⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpltaskrxfilter.c

📁 NATIONAL公司DP83816芯片Linux下驱动
💻 C
📖 第 1 页 / 共 2 页
字号:

//******************************************************************************
//
//  MPLTASKRXFILTER.C
//
//  Copyright (c) 2004 National Semiconductor Corporation.
//  All Rights Reserved
//
//  MPL receive filtering Offload Task Module.
//
//  This file contains the API implementations for
//     o Filtering of Receive packets based on
//       - Multicast Address
//       - Unicast   Address
//       - TBD
//
//******************************************************************************
#include <mplinternal.h>

#ifdef MPL_TASK_RECEIVE_FILTER
// 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_RX_FILTER, fn)
#define EXIT(fn) MPL_CEXIT(DZONE_MPL_TASK_RX_FILTER, fn)
#define ASSERT(le) MPL_CASSERT(DZONE_MPL_TASK_RX_FILTER, le)
#define PRINT(fmt) MPL_CTRACE(DZONE_MPL_TASK_RX_FILTER, fmt)
#define PRINTI(v) MPL_CTRACE(DZONE_MPL_TASK_RX_FILTER, \
                            (" "#v": %x \n",(NS_UINT)(v)))
#define PRINTS(v) MPL_CTRACE(DZONE_MPL_TASK_RX_FILTER, (" "#v": %s \n", v))
#define TBREAK(fmt) MPL_CTRACEBREAK(DZONE_MPL_TASK_RX_FILTER, fmt)

// Locals
static MPL_STATUS listenAdd(MPL_CONTEXT *pMplCtx,MPL_MAC_ADDR pCurrentAddress,
                                MPL_LISTEN_LIST pListen[][MAX_FILTER_COLS]);
static MPL_STATUS listenCheck(MPL_CONTEXT *pMplCtx,MPL_MAC_ADDR pCurrentAddress,
                                MPL_LISTEN_LIST pListen[][MAX_FILTER_COLS]);
static MPL_STATUS listenDel(MPL_CONTEXT *pMplCtx,MPL_MAC_ADDR pCurrentAddress,
                                MPL_LISTEN_LIST pListen[][MAX_FILTER_COLS]);
static MPL_STATUS listenClear(MPL_CONTEXT *pMplCtx,
                                MPL_LISTEN_LIST pListen[][MAX_FILTER_COLS]);
static MPL_STATUS updateHashTable(MPL_CONTEXT *pMplCtx,NS_UINT16 rowIndex, 
                                   NS_UINT16 colIndex);
static NS_VOID   getHashIndex(MPL_MAC_ADDR  pCurrentAddress, 
                                   NS_UINT16 *rowIndex, NS_UINT16 *colIndex);


//*****************************************************************************
//   MplTaskFilterCfg
//      Configure the receive filtering module 
//      (Currently Multicast and Unicast Destination Address Filtering)
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//      enableFlag
//         Set to NS_TRUE to enable the reception of multicast frames and 
//         filtering, NS_FALSE to disable.
//
//   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.
//      NS_STATUS_INVALID_PARM
//         An invalid parameter was detected.
//
//*****************************************************************************
MPL_STATUS
   MplTaskFilterCfg(
      IN NS_VOID         *pMplHandle,
      IN NS_BOOLEAN       enableFlag
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   MPL_STATUS status = NS_STATUS_SUCCESS;

   ENTER(MplTaskFilterCfg);

   pMplCtx->taskRxFilter.enable = enableFlag;
   
   EXIT(MplTaskFilterCfg);
   return status;
}

//*****************************************************************************
//   MplTaskFilterReload
//      Reload receive hash filters from previous defined listen list
//      Useful for if a Mac Reset is done and the listen lists are to be
//      restored to their previous saved values
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The listen list was successfully reloaded
//      NS_STATUS_FAILURE
//         This offload feature is disabled
//
//*****************************************************************************
MPL_STATUS
   MplTaskFilterReload(
      IN NS_VOID         *pMplHandle
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   NS_UINT16 rowIndex, colIndex;

   ENTER(MplTaskFilterReload);

   // Check if this feature is enabled
   if (pMplCtx->taskRxFilter.enable != NS_TRUE)
   {
      return NS_STATUS_FAILURE;
   }

   for (rowIndex = 0x0; rowIndex < MAX_FILTER_ROWS; rowIndex++)
   {
      for (colIndex = 0x0; colIndex < MAX_FILTER_COLS; colIndex++)
      {
         // Update the Hw's hash table if required
         if (pMplCtx->taskRxFilter.mcTable[rowIndex][colIndex].refCnt ||
                  pMplCtx->taskRxFilter.ucTable[rowIndex][colIndex].refCnt)
         {
            updateHashTable(pMplCtx, rowIndex, colIndex);
         }
      }
   }

   EXIT(MplTaskFilterReload);
   return NS_STATUS_SUCCESS;
}

//*****************************************************************************
//   MplTaskFilterMcastAddAddr
//      Add a new multicast address to the receive accept list
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//      pAddr
//         Multicast addr to be added to the filter list.
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The address was successfully added
//      NS_STATUS_RESOURCES
//         Unable to allocate required resources
//      NS_STATUS_INVALID_PARM
//         An invalid parameter was detected.
//      NS_STATUS_FAILURE
//         This offload feature is disabled
//
//*****************************************************************************
MPL_STATUS
   MplTaskFilterMcastAddAddr(
      IN NS_VOID         *pMplHandle,
      IN MPL_MAC_ADDR     pAddr
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   MPL_STATUS status = NS_STATUS_SUCCESS;

   ENTER(MplTaskFilterMcastAddAddr);

   // Check if this feature is enabled
   if (pMplCtx->taskRxFilter.enable != NS_TRUE)
   {
      return NS_STATUS_FAILURE;
   }
 
   // Add to the listen list
   status = listenAdd(pMplCtx, pAddr, pMplCtx->taskRxFilter.mcTable);

   EXIT(MplTaskFilterMcastAddAddr);
   return status;
}

//*****************************************************************************
//   MplTaskFilterMcastDeleteAddr
//      Delete a multicast address from the receive accept list
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//      pAddr
//         Multicast addr to be deleted from the filter list.
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The address was successfully deleted
//      NS_STATUS_FAILURE
//         Could not find the address to delete or feature not enabled
//
//*****************************************************************************
MPL_STATUS
   MplTaskFilterMcastDeleteAddr(
      IN NS_VOID         *pMplHandle,
      IN MPL_MAC_ADDR     pAddr
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   MPL_STATUS status = NS_STATUS_SUCCESS;

   ENTER(MplTaskFilterMcastDeleteAddr);

   // Check if this feature is enabled
   if (pMplCtx->taskRxFilter.enable != NS_TRUE)
   {
      return NS_STATUS_FAILURE;
   }

   // Remove from the listen list
   status = listenDel(pMplCtx, pAddr, pMplCtx->taskRxFilter.mcTable);

   EXIT(MplTaskFilterMcastDeleteAddr);
   return status;
}

//*****************************************************************************
//   MplTaskFilterMcastCheckAddr
//      Check if a multicast address is present in the receive accept list
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//      pAddr
//         Multicast addr to be checked in the filter list.
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The address was found in the receive accept list
//      NS_STATUS_FAILURE
//         Could not find the address or feature not enabled
//
//*****************************************************************************
MPL_STATUS
   MplTaskFilterMcastCheckAddr(
      IN NS_VOID         *pMplHandle,
      IN MPL_MAC_ADDR     pAddr
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   MPL_STATUS status = NS_STATUS_SUCCESS;

   ENTER(MplTaskFilterMcastCheckAddr);

   // Check if this feature is enabled
   if (pMplCtx->taskRxFilter.enable != NS_TRUE)
   {
      return NS_STATUS_FAILURE;
   }

   // Check in the listen list
   status = listenCheck(pMplCtx, pAddr, pMplCtx->taskRxFilter.mcTable);

   EXIT(MplTaskFilterMcastCheckAddr);
   return status;
}

//*****************************************************************************
//   MplTaskFilterMcastClearList
//      Clear the multicast clear list
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The list was successfully cleared
//      NS_STATUS_FAILURE
//         This offload feature is disabled
//
//*****************************************************************************
MPL_STATUS
   MplTaskFilterMcastClearList(
      IN NS_VOID         *pMplHandle
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   MPL_STATUS status = NS_STATUS_SUCCESS;

   ENTER(MplTaskFilterMcastClearList);

   // Check if this feature is enabled
   if (pMplCtx->taskRxFilter.enable != NS_TRUE)
   {
      return NS_STATUS_FAILURE;
   }

   // Clear multicast listen list
   status = listenClear(pMplCtx, pMplCtx->taskRxFilter.mcTable);

   EXIT(MplTaskFilterMcastClearList);
   return status;
}

//*****************************************************************************
//   MplTaskFilterUcastAddAddr
//      Add a new unicast address to the receive accept list
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//      pAddr
//         Unicast addr to be added to the filter list.
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The address was successfully added
//      NS_STATUS_RESOURCES
//         Unable to allocate required resources
//      NS_STATUS_FAILURE
//         This offload feature is disabled
//      NS_STATUS_INVALID_PARM
//         An invalid parameter was detected.
//
//*****************************************************************************
MPL_STATUS
   MplTaskFilterUcastAddAddr(
      IN NS_VOID         *pMplHandle,
      IN MPL_MAC_ADDR     pAddr
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   MPL_STATUS status = NS_STATUS_SUCCESS;

   ENTER(MplTaskFilterUcastAddAddr);

   // Check if this feature is enabled
   if (pMplCtx->taskRxFilter.enable != NS_TRUE)
   {
      return NS_STATUS_FAILURE;
   }

   // Add to the listen list
   status = listenAdd(pMplCtx, pAddr, pMplCtx->taskRxFilter.ucTable);
                                
   EXIT(MplTaskFilterUcastAddAddr);

   return status;
}

//*****************************************************************************
//   MplTaskFilterUcastDeleteAddr
//      Delete a unicast address from the receive accept list
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//      pAddr
//         Unicast addr to be deleted from the filter list.
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The address was successfully deleted
//      NS_STATUS_FAILURE
//         Could not find the address to delete or feature not enabled
//
//*****************************************************************************
MPL_STATUS
   MplTaskFilterUcastDeleteAddr(
      IN NS_VOID         *pMplHandle,
      IN MPL_MAC_ADDR     pAddr
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   MPL_STATUS status = NS_STATUS_SUCCESS;

   ENTER(MplTaskFilterUcastDeleteAddr);

   // Check if this feature is enabled
   if (pMplCtx->taskRxFilter.enable != NS_TRUE)
   {
      return NS_STATUS_FAILURE;
   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -