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

📄 zl5011xpkcpreprocess.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
字号:
/*******************************************************************************
*
*  File name:              zl5011xPkcPreProcess.c
*
*  Version:                11
*
*  Author:                 LCW
*
*  Date created:           16/05/2002
*
*  Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
*  All rights reserved.
*
*  Module Description:
*  This file contains all the functions that will initialise and control
*  the PKC Pre-Process block.
*
*  Revision History:
*
*  Rev:  Date:       Author:  Comments:
*  1     16/05/2002  LCW      Creation.
*  2     16/05/2002  LCW      Minor mods.
*  3     17/05/2002  LCW      Minor mods.
*  4     17/05/2002  LCW      Minor mods.
*  5     17/05/2002  LCW      Minor mods.
*  6     24/05/2002  LCW      Minor mods.
*  7     27/06/2002  LCW      Review actions.
*  8     06/08/2002  MRC      Rewrote filtering fns
*  9     27/09/2002  DJA      File header updated
*  10    31/10/2002  MRC      Added variants + minor fixes
*  11    23/07/2004  MRC      Fixed some compiler warnings
*
*******************************************************************************/

/*****************   INCLUDE FILES   ******************************************/

#include "zl5011x.h"
#include "zl5011xPkc.h"
#include "zl5011xPkcMap.h"
#include "zl5011xUtilLib.h"
#include "zl5011xRdWr.h"

/*******************************************************************************

 Function:
    zl5011xPkcFilterGetFreeEntry

 Description:
   This function can reserve an entry in the filter if a valid match
   number is provided, or will allocate one if possible.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   matchNum       the number of a free entry or ZL5011X_INVALID to allocate a
                  match number

 Outputs:
   matchNum       the number of a free entry if at input it was ZL5011X_INVALID

 Returns:
   zlStatusE

 Remarks:
   None

*******************************************************************************/

zlStatusE zl5011xPkcFilterGetFreeEntry(zl5011xParamsS *zl5011xParams,
      Uint32T *matchNum)
{
   Uint32T loop;
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
         "zl5011xPkcFilterGetFreeEntry: match in %d",
         *matchNum, 0, 0, 0, 0, 0);

   /* if the match number was set to a special value of invalid,
      then one will be automatically found */
   if (*matchNum == (Uint32T)ZL5011X_INVALID)
   {
      for (loop = 0; loop < ZL5011X_PKC_NUM_FILTER_ENTRIES; loop++)
      {
         if (zl5011xParams->packetIf.packetRx.pkcFilter[loop].filterReserved == ZL5011X_FALSE)
            break;
      }

      if (loop >= ZL5011X_PKC_NUM_FILTER_ENTRIES)
      {
         /* no free matches in the classifier, so return error */
         status = ZL5011X_NO_AVAIL_FILTER_MATCH;
      }
      else
      {
         *matchNum = loop;
      }
   }
   else
   {
      /* if the number was specified, but was not valid, then throw an error */
      if (*matchNum >= ZL5011X_PKC_NUM_FILTER_ENTRIES)
      {
         status = ZL5011X_PARAMETER_INVALID;
      }
      else
      {
         /* check that the match is not already in use */
         if (zl5011xParams->packetIf.packetRx.pkcFilter[*matchNum].filterReserved == ZL5011X_TRUE)
         {
            status = ZL5011X_FILTER_MATCH_IN_USE;
         }
      }
   }

   /* reserve the match if there has not been an error */
   if (status == ZL5011X_OK)
   {
      zl5011xParams->packetIf.packetRx.pkcFilter[*matchNum].filterReserved = ZL5011X_TRUE;

      ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
            "zl5011xPkcFilterGetFreeEntry: match out %d",
            *matchNum, 0, 0, 0, 0, 0);
   }

   return(status);
}

/*******************************************************************************

 Function:
    zl5011xPkcFilterEnableEntry

 Description:
   Enables a filter entry. The entry should be configured before it is
   enabled.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   matchNum       the number of the entry to enable

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

*******************************************************************************/

zlStatusE zl5011xPkcFilterEnableEntry(zl5011xParamsS *zl5011xParams,
      Uint32T matchNum)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
         "zl5011xPkcFilterEnableEntry: match %3d",
         matchNum, 0, 0, 0, 0, 0);

   /* check pre classifier entry number is in range */
   if (matchNum >= ZL5011X_PKC_NUM_FILTER_ENTRIES)
   {
      status = ZL5011X_PARAMETER_INVALID;
   }

   if (status == ZL5011X_OK)
   {
      zl5011xParams->packetIf.packetRx.pkcFilter[matchNum].filterInUse = ZL5011X_TRUE;

      /* set the bit to enable the filter entry */
      status = zl5011xReadModWrite(zl5011xParams, ZL5011X_PKC_FILTER_ENABLE,
            ZL5011X_1BIT_MASK << matchNum,
            ZL5011X_1BIT_MASK << matchNum);
   }

   return status;
}

/*******************************************************************************

 Function:
    zl5011xPkcFilterDisableEntry

 Description:
   Disables a filter entry. The entry is still reserved, but is disabled
   in the device.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   matchNum       the number of the entry to disable

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

*******************************************************************************/

zlStatusE zl5011xPkcFilterDisableEntry(zl5011xParamsS *zl5011xParams,
      Uint32T matchNum)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
         "zl5011xPkcFilterDisableEntry: match %3d",
         matchNum, 0, 0, 0, 0, 0);

   /* check the filter entry number is in range */
   if (matchNum >= ZL5011X_PKC_NUM_FILTER_ENTRIES)
   {
      status = ZL5011X_PARAMETER_INVALID;
   }

   if (status == ZL5011X_OK)
   {
      zl5011xParams->packetIf.packetRx.pkcFilter[matchNum].filterInUse = ZL5011X_FALSE;

      /* set the bit to disable the pre classifier entry */
      status = zl5011xReadModWrite(zl5011xParams, ZL5011X_PKC_FILTER_ENABLE,
            0,
            ZL5011X_1BIT_MASK << matchNum);
   }

   return status;
}

/*******************************************************************************

 Function:
    zl5011xPkcFilterDeleteEntry

 Description:
   Deletes a filter entry. The entry is marked as free, to allow it to
   be allocated again.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   matchNum       the number of the entry to delete

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

*******************************************************************************/

zlStatusE zl5011xPkcFilterDeleteEntry(zl5011xParamsS *zl5011xParams,
      Uint32T matchNum)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
         "zl5011xPkcFilterDeleteEntry: match %3d",
         matchNum, 0, 0, 0, 0, 0);

   status = zl5011xPkcFilterDisableEntry(zl5011xParams, matchNum);

   /* if the disable was okay, then free the filter by clearing
      the reserved flag */
   if (status == ZL5011X_OK)
   {
      zl5011xParams->packetIf.packetRx.pkcFilter[matchNum].filterReserved = ZL5011X_FALSE;
   }

   return status;
}

/*******************************************************************************

 Function:
   zl5011xPkcFilterSetMatch

 Description:
   A filter can be setup to match on a destination MAC address or ethertype
   and then forward the packet to the CPU.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance.
   matchNum       the number of the entry to configure
   match          structure containing the pre processor match settings

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

*******************************************************************************/

zlStatusE zl5011xPkcFilterSetMatch(zl5011xParamsS *zl5011xParams,
      Uint32T matchNum, zl5011xPacketFilterMatchS *match)
{
   Uint32T tempWord[(ZL5011X_PKC_FILTER_MATCH_SIZE / sizeof(Uint32T)) + 1];
   Uint8T tempPos = 0;
   Uint8T index = 0;
   Uint32T address = 0;
   Uint32T loop, bits;
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
         "zl5011xPkcFilterSetMatch: match %3d",
         matchNum, 0, 0, 0, 0, 0);

   /* check that the parameters are okay */
   if ((matchNum >= ZL5011X_PKC_NUM_FILTER_ENTRIES) ||
      (match == NULL))
   {
      status = ZL5011X_PARAMETER_INVALID;
   }

   if (status == ZL5011X_OK)
   {
      address = ZL5011X_PKC_FILTER_MATCH + (matchNum * ZL5011X_PKC_FILTER_MATCH_SIZE);

      /* if the filter is not enabled, then the CPU queue is not required
         so force to a valid value */
      if (match->ethertypeFilterEnable != ZL5011X_TRUE)
      {
         match->ethertypeCpuQueue = ZL5011X_QUEUE_0;
      }

      if (match->macAddressFilterEnable != ZL5011X_TRUE)
      {
         match->macAddressCpuQueue = ZL5011X_QUEUE_0;
      }
   }

   /* check that the output parameters are okay */
   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_QUEUE_NUMBER(match->macAddressCpuQueue);
   }

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_QUEUE_NUMBER(match->ethertypeCpuQueue);
   }

   if (status == ZL5011X_OK)
   {
      if (match->macAddressNumMaskBits >= (ZL5011X_1BIT_MASK << ZL5011X_PKC_FILTER_MAC_RANGE_FIELD))
      {
         status = ZL5011X_PARAMETER_INVALID;
      }
   }

   /* destination MAC address */
   for (loop = 0; loop < ZL5011X_MAC_SIZE; loop++)
   {
      if (status != ZL5011X_OK)
         break;

      status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
            match->macAddress[loop],
            ZL5011X_PKC_FILTER_MAC_ADDRESS_FIELD);
   }

   /* destination MAC address range */
   if(status == ZL5011X_OK)
   {
      status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
            match->macAddressNumMaskBits,
            ZL5011X_PKC_FILTER_MAC_RANGE_FIELD);
   }

   /* CPU queue to forward Mac address matches to */
   if(status == ZL5011X_OK)
   {
      status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
            match->macAddressCpuQueue,
            ZL5011X_PKC_FILTER_MAC_CPU_QUEUE_FIELD);
   }

   /* forward the Mac address matched packets to the CPU */
   if(status == ZL5011X_OK)
   {
      if (match->macAddressFilterEnable == ZL5011X_TRUE)
      {
         bits = 0x0;
      }
      else
      {
         bits = 0x1;
      }

      status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
            bits,
            ZL5011X_PKC_FILTER_MAC_ENABLE_FIELD);
   }

   /* ethertype to match */
   if(status == ZL5011X_OK)
   {
      status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
            match->ethertype,
            ZL5011X_PKC_FILTER_TYPE_ETHERTYPE_FIELD);
   }

   /* CPU queue to forward ethertype matches to */
   if(status == ZL5011X_OK)
   {
      status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
            match->ethertypeCpuQueue,
            ZL5011X_PKC_FILTER_TYPE_CPU_QUEUE_FIELD);
   }

   /* forward the ethertype matched packets to the CPU */
   if(status == ZL5011X_OK)
   {
      if (match->ethertypeFilterEnable == ZL5011X_TRUE)
      {
         bits = 0x0;
      }
      else
      {
         bits = 0x1;
      }

      status = zl5011xAssembleBitFields(tempWord, &index, &tempPos,
            bits,
            ZL5011X_PKC_FILTER_TYPE_ENABLE_FIELD);
   }

   /* Write assembled bits to device */
   if (status == ZL5011X_OK)
   {
      status = zl5011xWriteAssembledBitFields(zl5011xParams, tempWord,
            index, tempPos, address);
   }

   /* need to store all of these settings into the device structure */
   if (status == ZL5011X_OK)
   {
      (void)memcpy(&zl5011xParams->packetIf.packetRx.pkcFilter[matchNum].filterMatch,
            match, sizeof(zl5011xPacketFilterMatchS));
   }

   return status;
}

⌨️ 快捷键说明

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