📄 mpltaskvlan.c
字号:
//******************************************************************************
//
// MPLTASKVLAN.C
//
// Copyright (c) 2004 National Semiconductor Corporation.
// All Rights Reserved
//
// MPL VLAN Offload Task Module.
//
// This file contains the API implementations for
// o Configuring the VLAN offload task module
// o Adding/Deleting VLAN tags (global, transmit, receive)
// o Set/Query of VLAN tags in packets
//
//******************************************************************************
#include <mplinternal.h>
#ifdef MPL_TASK_VLAN
// Local helful debug macros
#undef ENTER
#undef EXIT
#undef ASSERT
#undef PRINT
#undef PRINTI
#undef PRINTS
#undef TBREAK
#define ENTER(fn) MPL_CENTER(DZONE_MPL_TASK_VLAN, fn)
#define EXIT(fn) MPL_CEXIT(DZONE_MPL_TASK_VLAN, fn)
#define ASSERT(le) MPL_CASSERT(DZONE_MPL_TASK_VLAN, le)
#define PRINT(fmt) MPL_CTRACE(DZONE_MPL_TASK_VLAN, fmt)
#define PRINTI(v) MPL_CTRACE(DZONE_MPL_TASK_VLAN, \
(" "#v": %x \n",(NS_UINT)(v)))
#define PRINTS(v) MPL_CTRACE(DZONE_MPL_TASK_VLAN, (" "#v": %s \n", v))
#define TBREAK(fmt) MPL_CTRACEBREAK(DZONE_MPL_TASK_VLAN, fmt)
static NS_VOID getHashIndex(NS_UINT16 vlanId,
NS_UINT16 *rowIndex, NS_UINT16 *colIndex);
//*****************************************************************************
// MplTaskVlanCfg
// Enable/Disable and configure the VLAN module
//
// Parameters
// pMplHandle
// MPL device handle returned following a call to MplInitialize
// enableFlag
// Set to NS_TRUE to enable the VLAN tag insertion and removal process,
// NS_FALSE to disable.
// cfg
// Bit map of configuration options for the VLAN task offload module.
// MPL_TASK_VLAN_DETECT_TAGS - Detect VLAN tags in incoming pkts
// and include tag data in OOB field of MPL_PKT
// MPL_TASK_VLAN_REMOVE_TAGS - Specifies the MPL should remove VLAN
// tags from receive packets indicated to the NSM.
// MPL_TASK_VLAN_DISCARD_TAGGED – Enables discard of frames *with*
// a VLAN tag.
// MPL_TASK_VLAN_DISCARD_UNTAGGED – Enables discard of frames
// *without* a VLAN tag.
// MPL_TASK_VLAN_FILTER - Enables MPL’s VLAN ID receive filter.
// MPL_TASK_VLAN_PERPACKET - Include VLAN tag on a per pkt basis
// - For Tx only (See Global insertion in MplTaskVlanAddTxTag)
//
// Return Value
// NS_STATUS_SUCCESS
// The task offload was successfully enabled or disabled.
// NS_STATUS_NOT_SUPPORTED
// This offload task or selected configuration option is not supported
// by MPL.
//
//*****************************************************************************
MPL_STATUS
MplTaskVlanCfg (
IN NS_VOID *pMplHandle,
IN NS_BOOLEAN enableFlag,
IN NS_UINT cfg
)
{
MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
MPL_STATUS status = NS_STATUS_SUCCESS;
NS_UINT32 regVal;
ENTER(MplTaskVlanCfg);
// Note enable/disable mode
pMplCtx->taskVlan.enable = enableFlag;
if (pMplCtx->taskVlan.enable == NS_TRUE)
{
// Make sure that we support this offload and the required cfg options
if ((pMplCtx->caps.taskCaps.vlan.supported == NS_TRUE) &&
(pMplCtx->caps.taskCaps.vlan.vlanFlags & cfg))
{
// Note the cfg request
pMplCtx->taskVlan.cfg = cfg;
// Enable each Rx config request
regVal = MPL_READ32(pMplCtx, VRCR);;
if (cfg & MPL_TASK_VLAN_DETECT_TAGS)
regVal |= VTDEN; // Enable tag detection
if (cfg & MPL_TASK_VLAN_REMOVE_TAGS)
regVal |= VTREN;
if (cfg & MPL_TASK_VLAN_DISCARD_TAGGED)
regVal |= DVTF;
if (cfg & MPL_TASK_VLAN_DISCARD_UNTAGGED)
regVal |= DUTF;
// Notify H/w abt Rx VLAN cfg
MPL_WRITE32(pMplCtx, VRCR, regVal);
// Enable each Tx config request
regVal = MPL_READ32(pMplCtx, VTCR);;
if (cfg & MPL_TASK_VLAN_PERPACKET)
regVal |= VPPTI;
// Notify H/w abt Tx VLAN cfg
MPL_WRITE32(pMplCtx, VTCR, regVal);
// Need to enable extended status field on descriptors
regVal = MPL_READ32(pMplCtx, CFG);
MPL_WRITE32(pMplCtx, CFG, regVal | EXTENDEDDESC_EN);
}
else
{
pMplCtx->taskVlan.cfg = 0x0;
status = NS_STATUS_NOT_SUPPORTED;
}
}
EXIT(MplTaskVlanCfg);
return status;
}
//*****************************************************************************
// MplTaskVlanAddTxTag
// Add a new VLAN tag to used globally for all Tx pkts
//
// Parameters
// pMplHandle
// MPL device handle returned following a call to MplInitialize
// vlanId
// VLAN identifier to be inserted globally for all transmits packets.
// vlanPriority
// VLAN priority to be inserted globally for all transmits packets.
//
// Return Value
// NS_STATUS_SUCCESS
// The VLAN tag was successfully added.
// NS_STATUS_FAILURE
// This offload feature is disabled
// NS_STATUS_INVALID_PARM
// The VLAN id or priority value was not in the valid range.
//
//*****************************************************************************
MPL_STATUS
MplTaskVlanAddTxTag (
IN NS_VOID *pMplHandle,
IN NS_UINT16 vlanId,
IN NS_UINT8 vlanPriority
)
{
MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
MPL_STATUS status = NS_STATUS_SUCCESS;
NS_UINT32 regVal;
NS_UINT16 vlanTag;
ENTER(MplTaskVlanAddTxTag);
// Check if this feature is enabled
if (pMplCtx->taskVlan.enable != NS_TRUE)
{
return NS_STATUS_FAILURE;
}
// Check values
if ((vlanId > VLAN_MAX_ID) || (vlanPriority > VLAN_MAX_PRIORITY))
{
return NS_STATUS_INVALID_PARM;
}
// Build the VLAN tag
regVal = MPL_READ32(pMplCtx, VTCR);;
regVal = (regVal & ~VPPTI) | VGTI; // Global tag insertion now
vlanTag = VLAN_MAKE_TAG(vlanId, vlanPriority);
regVal = (regVal & VTCI_MASK) | (vlanTag << VTCI_SHIFT);
// Notify H/w
MPL_WRITE32(pMplCtx, VTCR, regVal);
EXIT(MplTaskVlanAddTxTag);
return status;
}
//*****************************************************************************
// MplTaskVlanAddRxTag
// Add a new VLAN tag to the Rx filter list
//
// Parameters
// pMplHandle
// MPL device handle returned following a call to MplInitialize
// vlanId
// VLAN identifier to be inserted in the receive filter for incoming
// receive packets.
//
// Return Value
// NS_STATUS_SUCCESS
// The VLAN tag was successfully added.
// NS_STATUS_FAILURE
// This offload feature is disabled
// NS_STATUS_INVALID_PARM
// The VLAN id or priority value was not in the valid range.
// NS_STATUS_RESOURCES
// The maximum filter list size was reached.
//
//*****************************************************************************
MPL_STATUS
MplTaskVlanAddRxTag (
IN NS_VOID *pMplHandle,
IN NS_UINT16 vlanId
)
{
MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
MPL_STATUS status = NS_STATUS_SUCCESS;
NS_UINT16 rowIndex, colIndex;
ENTER(MplTaskVlanAddRxTag);
// Check if this feature is enabled
if (pMplCtx->taskVlan.enable != NS_TRUE)
{
return NS_STATUS_FAILURE;
}
// Check values
if (vlanId > VLAN_MAX_ID)
{
return NS_STATUS_INVALID_PARM;
}
// Get the Hash Value
getHashIndex(vlanId, &rowIndex, &colIndex);
// Update the filter table - Should be a perfect match
// so force to absolute 1 and 0s.
pMplCtx->taskVlan.filterTable[rowIndex][colIndex] = 0x01;
EXIT(MplTaskVlanAddRxTag);
return status;
}
//*****************************************************************************
// MplTaskVlanDeleteRxTag
// Delete a VLAN tag from the Rx filter list
//
// Parameters
// pMplHandle
// MPL device handle returned following a call to MplInitialize
// vlanId
// VLAN identifier to be removed from the receive filter list.
//
// Return Value
// NS_STATUS_SUCCESS
// The VLAN tag was successfully deleted.
// NS_STATUS_FAILURE
// This offload feature is disabled
//
//*****************************************************************************
MPL_STATUS
MplTaskVlanDeleteRxTag (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -