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

📄 mpltaskrxfilter.c

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

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

   EXIT(MplTaskFilterUcastDeleteAddr);
   return status;
}

//*****************************************************************************
//   MplTaskFilterUcastCheckAddr
//      Check if a unicast address is present in the receive accept list
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//      pAddr
//         Unicast 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
   MplTaskFilterUcastCheckAddr(
      IN NS_VOID         *pMplHandle,
      IN MPL_MAC_ADDR     pAddr
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   MPL_STATUS status = NS_STATUS_SUCCESS;

   ENTER(MplTaskFilterUcastCheckAddr);

   // 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.ucTable);

   EXIT(MplTaskFilterUcastCheckAddr);
   return status;
}

//*****************************************************************************
//   MplTaskFilterUcastClearList
//      Clear the unicast 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
   MplTaskFilterUcastClearList(
      IN NS_VOID         *pMplHandle
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   MPL_STATUS status = NS_STATUS_SUCCESS;

   ENTER(MplTaskFilterUcastClearList);

   // 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.ucTable);

   EXIT(MplTaskFilterUcastClearList);
   return status;
}


//*****************************************************************************
//   listenAdd
//      Adds a new MAC address to the listen (i.e. accept) list
//
//   Parameters
//      pMplCtx
//         Pointer to MPL Context
//      pCurrentAddress
//         Pointer to MAC address to be added
//      pListen
//         Pointer to the listen list (multicast or unicast)
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The MAC address was succefully added to the listen list
//
//*****************************************************************************
static
MPL_STATUS
   listenAdd(
      IN MPL_CONTEXT  *pMplCtx,
      IN MPL_MAC_ADDR  pCurrentAddress,
      IN MPL_LISTEN_LIST pListen[][MAX_FILTER_COLS]
      )
{
   NS_UINT16 rowIndex, colIndex;

   // Get the Hash Value
   getHashIndex(pCurrentAddress, &rowIndex, &colIndex);

   // Increment the reference count
   pListen[rowIndex][colIndex].refCnt++; 

   // FM: Add to tracking list

   // Update the Hw's hash table if required
   if (pListen[rowIndex][colIndex].refCnt == 0x01)
   {
      updateHashTable(pMplCtx, rowIndex, colIndex);
   }

   return NS_STATUS_SUCCESS;
}

//*****************************************************************************
//   listenCheck
//      Checks if a  MAC address is listed in the listen (i.e. accept) list
//
//   Parameters
//      pMplCtx
//         Pointer to MPL Context
//      pCurrentAddress
//         Pointer to MAC address to be searched
//      pListen
//         Pointer to the listen list (multicast or unicast)
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The MAC address was found
//      NS_STATUS_FAILURE
//         Could not find the address
//
//*****************************************************************************
static
MPL_STATUS
   listenCheck (
      IN MPL_CONTEXT  *pMplCtx,
      IN MPL_MAC_ADDR  pCurrentAddress,
      IN MPL_LISTEN_LIST pListen[][MAX_FILTER_COLS]
      )
{
   NS_UINT16 rowIndex, colIndex;

   // Get the Hash Value
   getHashIndex(pCurrentAddress, &rowIndex, &colIndex);

   // Update the Hw's hash table if required
   if (pListen[rowIndex][colIndex].refCnt)
   {
      // TBD: Do a perfect match check - In tracking list
      return NS_STATUS_SUCCESS;
   }
   else
      return NS_STATUS_FAILURE;
}

//*****************************************************************************
//   listenDel
//      Deletes a MAC address from the listen (i.e. accept) list
//
//   Parameters
//      pMplCtx
//         Pointer to MPL Context
//      pCurrentAddress
//         Pointer to MAC address to be deleted
//      pListen
//         Pointer to the listen list (multicast or unicast)
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The MAC address was succefully deleted from the listen list
//
//*****************************************************************************
static
MPL_STATUS
   listenDel(
      IN MPL_CONTEXT  *pMplCtx,
      IN MPL_MAC_ADDR  pCurrentAddress,
      IN MPL_LISTEN_LIST pListen[][MAX_FILTER_COLS]
      )
{
   MPL_STATUS status = NS_STATUS_SUCCESS;
   NS_UINT16 rowIndex, colIndex;

   // Get the Hash Value
   getHashIndex(pCurrentAddress, &rowIndex, &colIndex);

   // Update the Hw's hash table if required
   if (pListen[rowIndex][colIndex].refCnt != 0x0)
   {
      // Decrement the reference count
      pListen[rowIndex][colIndex].refCnt--; 

      // FM: Del from tracking list
     
      // Update the Hw's hash table if required
      if (pListen[rowIndex][colIndex].refCnt == 0x0)
      {
         updateHashTable(pMplCtx, rowIndex, colIndex);
      }
   }
   else
   {
      status = NS_STATUS_FAILURE;
   }

   return status;
}


//*****************************************************************************
//   listenClear
//      Clears all MAC addresses from the listen (i.e. accept) list
//
//   Parameters
//      pMplCtx
//         Pointer to MPL Context
//      pListen
//         Pointer to the listen list (multicast or unicast)
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The MAC address was succefully deleted from the listen list
//
//*****************************************************************************
static
MPL_STATUS
   listenClear(
      IN MPL_CONTEXT  *pMplCtx,
      IN MPL_LISTEN_LIST pListen[][MAX_FILTER_COLS]
      )
{
   NS_UINT16 rowIndex, colIndex;

   // Update the Hw's hash table if required
   for (rowIndex = 0x0; rowIndex < MAX_FILTER_ROWS; rowIndex++)
   {
      for (colIndex = 0x0; colIndex < MAX_FILTER_COLS; colIndex++)
      {
         // FM: Del from tracking list

         // Reset the reference count and tell device about it
         pListen[rowIndex][colIndex].refCnt = 0x0; 
         updateHashTable(pMplCtx, rowIndex, colIndex);
      }
   }

   return NS_STATUS_SUCCESS;
}

//*****************************************************************************
//   updateHashTable
//      Updates the hash table entry on the device to match the one maintained
//       by this software module
//
//   Parameters
//      pMplCtx
//         Pointer to MPL Context
//      rowIndex
//         Row index for the hash table to be modified.
//      colIndex
//         Col index for the hash table to be modified.
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The hardware was successfully notified
//
//*****************************************************************************
static
MPL_STATUS
   updateHashTable(
      IN MPL_CONTEXT  *pMplCtx,
      IN NS_UINT16     rowIndex,
      IN NS_UINT16     colIndex
      )
{
   NS_UINT32 rfcrVal, hashVal;

   // Disable Rx filter
   rfcrVal = MPL_READ32(pMplCtx, RFCR);
   MPL_WRITE32(pMplCtx, RFCR, rfcrVal & ~RXFLTR_EN);

   // Set control bits to get to wordIndex
   MPL_WRITE32(pMplCtx, RFCR, HASH_TABLE_INDEX + (rowIndex * 2));

   // Read current hash setting at wordIndex -16bits
   hashVal = MPL_READ32(pMplCtx, RFDR);

   // Write the new hashValue
   if (pMplCtx->taskRxFilter.mcTable[rowIndex][colIndex].refCnt ||
                  pMplCtx->taskRxFilter.ucTable[rowIndex][colIndex].refCnt)
   {
      // Multicast or Unicast Address needs to be accepted
      MPL_WRITE32(pMplCtx, RFDR, hashVal | (1 << colIndex));
   }
   else
   {
      // Neither Multicast or Unicast Address needs to be accepted
      MPL_WRITE32(pMplCtx, RFDR, hashVal & ~(1 << colIndex));
   }

   // Reenable Rx filter
   MPL_WRITE32(pMplCtx, RFCR, rfcrVal);

   return NS_STATUS_SUCCESS;
}

//*****************************************************************************
//   getHashIndex
//      Gets the row and col index into the hash table based on a given MAC
//      address
//
//   Parameters
//      pCurrentAddress
//         Pointer to MAC address
//      rowIndex
//         Pointer to a caller supplier variable where the Row index into the
//          hash-table is returned
//      colIndex
//         Pointer to a caller supplier variable where the column index into the
//          hash-table is returned
//
//   Return Value
//      None
//
//*****************************************************************************
static
NS_VOID   
   getHashIndex(
      IN MPL_MAC_ADDR   pCurrentAddress,
      IN NS_UINT16     *rowIndex,
      IN NS_UINT16     *colIndex
      )
{
   NS_UINT32 crc, msb;
   NS_UINT8 i, j, currByte;

   // Get the CRC 
   crc = 0xffffffffL;
   for (i = 0; i < 0x6; i++) 
   {
      currByte = *pCurrentAddress++;
      for (j = 0; j < 0x8; j++) 
      {
         msb = crc >> 31;
         crc <<= 1;
         if ( msb ^ ( currByte & 1 ) ) 
         {
            crc ^= IEEE_802_3_FCS_HASH_FUNC;
            crc |= 1;
         }
         currByte >>= 1;
      }
   }

   // Compute the word and bit indexes 
   //   Word(Row) index is bits 31-27 of the crc
    //  Bit(Col)  index is bits 26-23 of the crc 
   crc >>= 23;
   *rowIndex = (NS_UINT16)((crc >> 4) & 0x1fL);
   *colIndex = (NS_UINT16)(crc & 0xfL);

   return;
}

#endif // MPL_TASK_RECEIVE_FILTER

⌨️ 快捷键说明

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