mpltaskvlan.c

来自「NATIONAL公司DP83816芯片Linux下驱动」· C语言 代码 · 共 549 行 · 第 1/2 页

C
549
字号
      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(MplTaskVlanDeleteRxTag);

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

   // 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] = 0x0;

   EXIT(MplTaskVlanDeleteRxTag);
   return status;
}

//*****************************************************************************
//   MplTaskVlanClearRxTag
//      Clear the Rx VLAN  filter list
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The VLAN tags were successfully cleared.
//      NS_STATUS_FAILURE
//         This offload feature is disabled
//
//*****************************************************************************
MPL_STATUS
   MplTaskVlanClearRxTag (
      IN NS_VOID *pMplHandle
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   MPL_STATUS status = NS_STATUS_SUCCESS;
   NS_UINT16 rowIndex, colIndex;

   ENTER(MplTaskVlanClearRxTag);

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

   for (rowIndex = 0x0; rowIndex < MAX_VLAN_FILTER_ROWS; rowIndex++)
   {
      for (colIndex = 0x0; colIndex < MAX_VLAN_FILTER_COLS; colIndex++)
      {
         // Reset the reference count
         pMplCtx->taskVlan.filterTable[rowIndex][colIndex] = 0x0;
      }
   }

   EXIT(MplTaskVlanClearRxTag);
   return status;
}

//*****************************************************************************
//   MplTaskVlanCheckRxTag
//      Check if the VLAN tag is to be filtered out
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//      vlanId
//         The VLAN id (0 to 4095 inclusive)
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The VLAN tag was found
//      NS_STATUS_FAILURE
//         This offload feature is disabled
//      NS_STATUS_NOT_PRESENT
//         Could not find the VLAN tag
//
//*****************************************************************************
MPL_STATUS
   MplTaskVlanCheckRxTag (
      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(MplTaskVlanCheckRxTag);

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

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

   // Check in the filter table
   if (pMplCtx->taskVlan.filterTable[rowIndex][colIndex])
   {
      return NS_STATUS_SUCCESS;
   }
   else
      return NS_STATUS_NOT_PRESENT;

   EXIT(MplTaskVlanCheckRxTag);
   return status;
}

//*****************************************************************************
//   MplSetPacketVlanTag
//     Set a given VLAN tag to the outgoing pkt (per packet mode)     
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//      pPacket
//         Pointer to the MPL_PKT structure that describes the frame to be
//          transmitted
//      vlanId
//         The VLAN id (0 to 4095 inclusive) to be used to transmit this packet
//      vlanPriority
//         The VLAN priority (0 to 7 inclusive) to be used to transmit this
//          packet
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The VLAN id was successfully set for the packet.
//      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
   MplSetPacketVlanTag (
      IN NS_VOID *pMplHandle,
      IN MPL_PKT   *pPacket,
      IN NS_UINT16  vlanId,
      IN NS_UINT8   vlanPriority
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   MPL_STATUS status = NS_STATUS_SUCCESS;

   ENTER(MplSetPacketVlanTag);

   // 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
   pPacket->txOOB.extCtl = ECS_VPKT | VLAN_MAKE_TAG(vlanId, vlanPriority);

   EXIT(MplSetPacketVlanTag);
   return status;
}

//*****************************************************************************
//  MplQueryPacketVlanTag 
//      Retrieve the VLAN tag in a given Rx packet
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//      pPacket
//         Pointer to the MPL_PKT structure that describes the frame just
//          received
//      pVlanId
//         Pointer to a caller provided variable in which the VLAN id (0 to
//          4095 inclusive) is returned.
//      pVlanPriority
//         Caller allocated variable in which this function returns the VLAN
//          priority (0 to 7 inclusive) on the received frame.
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The VLAN tag was successfully retrieved for the packet.
//      NS_STATUS_INVALID_PARM
//         The packet is not a VLAN tagged packet.
//      NS_STATUS_FAILURE
//         This offload feature is disabled
//
//****************************************************************************
MPL_STATUS
   MplQueryPacketVlanId (
      IN NS_VOID *pMplHandle,
      IN MPL_PKT    *pPacket,
      IN NS_UINT16  *pVlanId,
      IN NS_UINT8   *pVlanPriority
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   MPL_STATUS status = NS_STATUS_SUCCESS;

   ENTER(MplQueryPacketVlanId);

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

   // Check if this packet has a VLAN tag
   if (pPacket->rxOOB.extSts & ECS_VPKT)
   {
      VLAN_BREAK_TAG(pPacket->rxOOB.extSts, pVlanId, pVlanPriority)
   }
   else
   {
      return NS_STATUS_INVALID_PARM;
   }

   EXIT(MplQueryPacketVlanId);
   return status;
}

//*****************************************************************************
//   getHashIndex
//      Gets the row and col index into the hash table based on a given VLAN
//      id
//
//   Parameters
//      vlanId
//         vlanId
//      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 NS_UINT16     vlanId,
      IN NS_UINT16    *rowIndex,
      IN NS_UINT16    *colIndex
      )
{
    *rowIndex = vlanId >> 3; // Bits 11:3
    *colIndex = vlanId & 0x007; // Bits 2:0
     return;
}

#endif

⌨️ 快捷键说明

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