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

📄 zl5011xpkc.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************
*
*  File name:              zl5011xPkc.c
*
*  Version:                23
*
*  Author:                 MRC
*
*  Date created:           13/05/2002
*
*  Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
*  All rights reserved.
*
*  Module Description:
*
*  This file contains the initialisation functions and bit handling
*  functions that are used in programming the PKC.
*
*  Revision History:
*
*  Rev:  Date:       Author:  Comments:
*  1     13/05/2002  MRC      Creation
*  2     21/05/2002  MRC      PKC Rams have to be written in reverse order, so
*                             modified the bit field construction routines.
*  3     11/06/2002  LCW      Added function: PkcGetStats
*  4     13/06/2002  MRC      Updated the init function
*  5     21/06/2002  MRC      Updated the init function
*  6     06/08/2002  MRC      Added initialisation for filtering fns
*  7     25/09/2002  JFE      Added initialisation for protocol stacks structure
*                             Fixed overwriting status bug in zl5011xPkcInit
*  8     27/09/2002  JFE      Removed extra init in rev 7.
*  9     03/10/2002  JFE      Added two functions: zl5011xPkcSetPWInterrupt and
*                             zl5011xPkcGetPWInterrupt.
*  10    08/10/2002  PJE      Added three intr functions
*  11    31/10/2002  MRC      Added variants + minor fixes
*  12    06/01/2003  MRC      Added PKC statistics function
*  13    25/03/2003  MRC      Added fn zl5011xPkcChecksumConfig
*  14    07/05/2003  MRC      Disable UDP checksum checking
*  15    22/05/2003  MRC      Added PW interrupt status fn
*  16    05/06/2003  MRC      Fixed protocol match count for PKC stats fn
*  17    09/06/2003  DJA      Performed pre-audit actions
*  18    30/07/2003  APL      Update
*  19    23/07/2004  MRC      Fixed some compiler warnings
*  20    29/07/2004  MRC      Fixed some compiler warnings
*  21    25/08/2004  MRC      Modified PW queue functions
*  22    26/08/2004  MRC      Updated PW status byte handling
*  23    02/03/2005  APL      Used zl5011xQueueE values where appropriate
*  24    07/07/2005  APL      Corrected TRACE control flag in zl5011xPkcGetPwStatus
*
*******************************************************************************/

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

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

/*****************   EXPORTED GLOBAL VARIABLES    *****************************/

/*****************   STATIC GLOBAL VARIABLES      *****************************/

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

 Function:
    zl5011xPkcInit

 Description:
    This function initialises the Pkc block and data structure.

 Inputs:
    zl5011xParams      Pointer to the structure for this device instance

 Outputs:
    None

 Returns:
   zlStatusE

 Remarks:
    None

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

zlStatusE zl5011xPkcInit(zl5011xParamsS *zl5011xParams)
{
   Uint32T loop;
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID, "zl5011xPkcInit:", 0, 0, 0, 0, 0, 0);

   /* mark all of the filter entries in the structure as unused */
   for (loop = 0; loop < ZL5011X_PKC_NUM_FILTER_ENTRIES; loop++)
   {
      zl5011xParams->packetIf.packetRx.pkcFilter[loop].filterInUse = ZL5011X_FALSE;
      zl5011xParams->packetIf.packetRx.pkcFilter[loop].filterReserved = ZL5011X_FALSE;
   }

   /* mark all of the classifier entries in the structure as unused */
   for (loop = 0; loop < ZL5011X_PKC_NUM_CLASSIFY_ENTRIES; loop++)
   {
      zl5011xParams->packetIf.packetRx.pkcClassify[loop].classifyInUse = ZL5011X_FALSE;
      zl5011xParams->packetIf.packetRx.pkcClassify[loop].classifyReserved = ZL5011X_FALSE;
      zl5011xParams->packetIf.packetRx.pkcClassify[loop].protocolType = ZL5011X_INVALID_PROTOCOL;

      /* disable each of the PW interrupts */
      status = zl5011xPkcSetPWInterrupt(zl5011xParams, (Uint32T)ZL5011X_INVALID_CONTEXT, loop,
            (ZL5011X_1BIT_MASK << ZL5011X_PKC_PW_INT_DISABLE_BIT) | ( 0xff << ZL5011X_PKC_PW_STATUS_MASK_BITS));
   }

   /* mark all of the protocol entries in the structure as unused */
   for (loop = 0; loop < ZL5011X_PKC_NUM_PROTOCOL_ENTRIES; loop++)
   {
      zl5011xParams->packetIf.packetRx.pkcProtocol[loop].protocolInUse = ZL5011X_FALSE;
      zl5011xParams->packetIf.packetRx.pkcProtocol[loop].protocolReserved = ZL5011X_FALSE;
      zl5011xParams->packetIf.packetRx.pkcProtocol[loop].protocolType = ZL5011X_INVALID_PROTOCOL;
   }

   /* initialise the PKC to TDM context mappings */
   for (loop = 0; loop < ZL5011X_MAX_NUMBER_CONTEXTS; loop++)
   {
      zl5011xParams->packetIf.packetRx.contextRxPacketMatch[loop].contextMatchState[0] = ZL5011X_PKC_STATE_MATCH_NOT_ALLOCATED;
      zl5011xParams->packetIf.packetRx.contextRxPacketMatch[loop].contextMatchState[1] = ZL5011X_PKC_STATE_MATCH_NOT_ALLOCATED;

      zl5011xParams->packetIf.packetRx.contextRxPacketMatch[loop].pkcClassifyMatchNum[0] = (Uint32T)ZL5011X_INVALID;
      zl5011xParams->packetIf.packetRx.contextRxPacketMatch[loop].pkcClassifyMatchNum[1] = (Uint32T)ZL5011X_INVALID;
   }

   /* initialise the classifer to discard unmatched / failing verification packets */
   status = zl5011xPkcClassifyConfigure(zl5011xParams, ZL5011X_TRUE, ZL5011X_QUEUE_0, ZL5011X_TRUE, ZL5011X_QUEUE_0);

   /* initialise the pre-classifer to discard unmatched packets */
   if (status == ZL5011X_OK)
   {
     status = zl5011xPkcProtocolConfigure(zl5011xParams, ZL5011X_TRUE, ZL5011X_QUEUE_0);
   }

   /* set the flow type for unmatched packets directed to the CPU */
   if (status == ZL5011X_OK)
   {
      status = zl5011xPkcSetHostFlowType(zl5011xParams, ZL5011X_FLOW_PKT_CPU);
   }

   /* enable IPv4 and disable UDP checksums */
   if (status == ZL5011X_OK)
   {
      status = zl5011xPkcChecksumConfig(zl5011xParams, ZL5011X_TRUE, ZL5011X_FALSE);
   }

   if (status == ZL5011X_OK)
   {
      /* disable all of the PKC interrupts */
      status = zl5011xPkcDisableInterrupts(zl5011xParams, ZL5011X_PKC_INT_ALL_MASK);
   }

   /* set the block ID. This is only used for debugging TM messages. */
   if (status == ZL5011X_OK)
   {
      status = zl5011xWrite(zl5011xParams, ZL5011X_PKC_BLOCK_ID,
            ZL5011X_PKC_SOURCE_BLOCK_ID);
   }

   return (status);
}

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

 Function:
    zl5011xPkcChecksumConfig

 Description:
    Controls whether packets with incorrect UDP / IPv4 checksums are accepted
    or rejected.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   enableIpv4Checksum   ZL5011X_TRUE to enable dropping of packets with incorrect
                        IPv4 checksum
   enableUdpChecksum    ZL5011X_TRUE to enable dropping of packets with incorrect
                        UDP checksum
                        ZL5011X_FALSE to allow dropping of packets with incorrect
                        UDP checksum to be determined on a per protocol basis

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xPkcChecksumConfig(zl5011xParamsS *zl5011xParams,
      zl5011xBooleanE enableIpv4Checksum, zl5011xBooleanE enableUdpChecksum)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T bits;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
         "zl5011xPkcChecksumConfig: IPv4 %d, UDP %d",
         enableIpv4Checksum, enableUdpChecksum, 0, 0, 0, 0);

   if (status == ZL5011X_OK)
   {
      bits = 0;

      if (enableIpv4Checksum == ZL5011X_TRUE)
      {
         bits |= ZL5011X_1BIT_MASK << ZL5011X_PKC_CHECKSUM_IPV4_ENABLE_BIT;
      }

      if (enableUdpChecksum == ZL5011X_TRUE)
      {
         bits |= ZL5011X_1BIT_MASK << ZL5011X_PKC_CHECKSUM_UDP_ENABLE_BIT;
      }

      status = zl5011xWrite(zl5011xParams, ZL5011X_PKC_CHECKSUM_CONFIG, bits);
   }

   return (status);
}

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

 Function:
    zl5011xPkcSetPWInterrupt

 Description:
    This function is called to set the PW Status register. There is one register
    for each of the matches in the classification engine.

 Inputs:
   zl5011xParams     Pointer to the structure for this device instance
   context          context number associated with this classifier match.
                    Used during interrupt function to return context number.
   matchNum         Match number in classification engine
   pwStatusRegister New value to write to register.

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xPkcSetPWInterrupt(zl5011xParamsS *zl5011xParams,
      Uint32T context, Uint32T matchNum, Uint32T pwStatusRegister)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T   registerAddress;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID,"zl5011xPkcSetPWInterrupt: match %ld",matchNum,0,0,0,0,0);

   if (matchNum >= ZL5011X_PKC_NUM_CLASSIFY_ENTRIES)
   {
      status = ZL5011X_PARAMETER_INVALID;
   }

   if (status == ZL5011X_OK)
   {
      registerAddress = ZL5011X_PKC_PW_STATUS_RAM + (matchNum * sizeof(Uint32T));
      zl5011xParams->packetIf.packetRx.pkcClassify[matchNum].context = context;
      zl5011xParams->packetIf.packetRx.pkcClassify[matchNum].pwInterruptMask = pwStatusRegister;
      zl5011xParams->packetIf.packetRx.pkcPrevPwValue[matchNum] = (Uint32T)ZL5011X_INVALID;

      status = zl5011xWrite(zl5011xParams, registerAddress, pwStatusRegister);
   }

   return (status);
}

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

 Function:
    zl5011xPkcGetPWInterrupt

 Description:
    This function is called to read the PW Status register. There is one register
    for each of the matches in the classification engine.

 Inputs:
   zl5011xParams     Pointer to the structure for this device instance
   matchNum         Match number in classification engine

 Outputs:
   pwStatusRegister return from PW status register

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xPkcGetPWInterrupt(zl5011xParamsS *zl5011xParams,
      Uint32T matchNum, Uint32T *pwStatusRegister)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T   registerAddress;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID,"zl5011xPkcGetPWInterrupt: match %ld",matchNum,0,0,0,0,0);

   if (matchNum >= ZL5011X_PKC_NUM_CLASSIFY_ENTRIES)
   {
      status = ZL5011X_PARAMETER_INVALID;
   }

   if (status == ZL5011X_OK)
   {
      registerAddress = ZL5011X_PKC_PW_STATUS_RAM + (matchNum * sizeof(Uint32T));

      status = zl5011xRead(zl5011xParams, registerAddress, pwStatusRegister);
   }

   return (status);
}

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

 Function:
    zl5011xPkcSetHostFlowType

 Description:
    This function sets the flow type that is used for messages sent to the
    host. The flow type is used in the message from the PKC, and is used by the

⌨️ 快捷键说明

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