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

📄 zl5011xlan.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*******************************************************************************
*
*  File name:              zl5011xLan.c
*
*  Version:                58
*
*  Author:                 MRC
*
*  Date created:           11/06/2002
*
*  Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
*  All rights reserved.
*
*  Module Description:
*
*  This file contains the functions required to setup the Lan ports and
*  packet configuration
*
*  Revision History:
*
*  Rev:  Date:       Author:  Comments:
*  1     11/06/2002  MRC      Creation
*  2     14/06/2002  MRC      Added some packet fns
*  3     21/06/2002  MRC      Added more packet fns
*  4     28/06/2002  MRC      Added packet Rx functions
*  5     03/07/2002  MRC      Changed the protocol match structure names
*  6     09/07/2002  MRC      Added an enable to the Lan configure fn
*  7     12/07/2002  MRC      Added bodge RTP function for packet Tx headers
*  8     18/07/2002  MRC      Allow layer 4 and 5 header output MPID to be
*                             specified, rather than default to the context no.
*  9     22/07/2002  MRC      Removed temp fns
*  10    06/08/2002  MRC      Added packet Rx filtering fns
*  11    16/08/2002  MRC      Added control to allow the Tx RTP timestamp to be
*                             derived from the WAN interface.
*  12    02/09/2002  MRC      Allows the flow to be set for Rx contexts
*  13    04/09/2002  MRC      Changed the name of a structure entry from
*                             protocolLength16Bits to protocolTwoByteSeq
*  14    05/09/2002  MRC      Determine the Wan Tx switch bit during context
*                             changes
*  15    12/09/2002  MRC      Updated following review
*  16    13/09/2002  MRC      Added in PHY and stats functions
*  17    18/09/2002  MRC      Increased the number of granules for the Lan
*                             queues
*  18    02/10/2002  DJA      ZL5011X_TRACE messages fixed up
*  19    17/10/2002  MRC      Improved default packet size for lan configure
*  20    25/10/2002  MRC      Added parameter checking
*  21    30/10/2002  MRC      Fixed context check in Layer 4 and 5 header fn
*  22    31/10/2002  MRC      Added variants + minor fixes
*  23    04/11/2002  MRC      LanRxSetContextMatch allows the calling function
*                             to specify the mpid
*  24    07/11/2002  MRC      Added control for LanRxSetContextMatch to use the
*                             raw Rx packet length
*  25    19/11/2002  MRC      Fixed gotDevice checks
*  26    07/01/2003  MRC      Added zl5011xLanGetPacketStats function
*  27    22/05/2003  MRC      Added Lan port redirection functions
*  28    29/07/2003  APL      Added support for devices with no TDM interface
*                             Renamed global wanLimits structure to devLimits
*  29    30/07/2003  APL      Renamed packetToTdmMapping
*  30    30/07/2003  APL      Fixed problem identifying free header
*                             (from previous change)
*  31    04/08/2003  APL      Removed unused variable for some device variants
*  32    11/08/2003  MRC      Now allow port to be disabled by configure fn
*  33    26/08/2003  MRC      Added check for the Lan port
*  34    09/09/2003  MRC      Fixed a couple of context checks that were
*                             checking for modification rather than active
*  35    12/09/2003  APL      Minor change to a comment from audit follow up
*  36    06/11/2003  AMS      Update
*  37    10/11/2003  AMS      Update
*  38    06/01/2004  MRC      Reverted to revision 35
*  39    14/01/2004  APL      Minor function header update for LanTxPortRedirect
*  40    23/03/2004  APL      Corrected file version history
*  41    15/04/2004  APL      Improved comments in zl5011xLanRxFilter
*  42    05/05/2004  MRC      Revised the port combination rule
*  43    23/06/2004  APL      Corrected a comment so it matched the code
*  44    26/07/2004  MRC      Fixed some compiler warnings
*  45    29/07/2004  MRC      Fixed some compiler warnings
*  46    25/08/2004  MRC      Added PW functions
*  47    06/09/2004  APL      Map ports appropriately for different device variants
*  48    13/09/2004  APL      Delay enabling lan-to-lan context matches until context
*                                is updated.
*                             Extra variable added to zl5011xParamsS to avoid referencing
*                                low level PKI port numbers.
*                             Added port validity rule 4 to zl5011xLanConfigure.
*                             Lan-to-lan contexts restricted to only one header match.
*  49    14/09/2004  APL      Minor tidying following review
*  50    24/01/2005  APL      Mac type variable set correctly in zl5011xLanConfigure
*                             Allow special test mode build
*  51    04/02/2005  MRC      Added read counters call to Lan stats function
*  52    14/02/2005  APL      Ensure RTP stats are read from the current header.
*                             Corrected range check in zl5011xLanGetRtpStats.
*  53    28/02/2005  APL      Added additional debug (internal use only)
*  54    07/03/2005  APL      Fixed compiler warnings (internal code only)
*  55    06/05/2005  APL      Added function zl5011xLanGetTxSeqNum
*  56    17/05/2005  MRC      Update protocol type when deleting headers
*  57    05/07/2005  APL      zl5011xLanGetTxSeqNum now returns a sensible value
*                             when a context has just been created.
*  58    21/07/2005  MRC      Added functions to read/write a 32 bit value to the
*                             Packet Tx header and provided support for a packet
*                             discard Lan port
*
*******************************************************************************/

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

#include "zl5011xApi.h"
#include "zl5011xLan.h"
#include "zl5011xMisc.h"
#include "zl5011xPkcMap.h"
#include "zl5011xTdm.h"

/*****************   STATIC FUNCTION DECLARATIONS   ***************************/

/*****************   EXPORTED FUNCTION DEFINTIONS   ***************************/

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

 Function:
    zl5011xLanConfigureStructInit

 Description:
   Initialises structure used by zl5011xLanConfigure function.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   par            Pointer to the structure for configuration items.
                  See main function

 Returns:
   zlStatusE

 Remarks:
    None

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

zlStatusE zl5011xLanConfigureStructInit(zl5011xParamsS *zl5011xParams, zl5011xLanConfigureS *par)
{
   zlStatusE status = ZL5011X_OK;

   /* do some parameter checking */
   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
            "zl5011xLanConfigureStructInit:",
            0, 0, 0, 0, 0, 0);

      par->portNum = (Uint8T)ZL5011X_INVALID;
      par->macType = ZL5011X_MAC_TYPE_MII;
      (void)memset(par->macAddress, 0, sizeof(par->macAddress));
      par->enable64BitMacStats = ZL5011X_FALSE;

      par->vlanEnabled = ZL5011X_FALSE;
      par->maxPktLength = (Uint32T)ZL5011X_INVALID;
      par->osExclusionEnable = ZL5011X_TRUE;

      /* the following settings are for internal use only and should NOT be modified */
      par->filterBroadcastPkts = ZL5011X_FALSE;
      par->filterMulticastPkts = ZL5011X_FALSE;
      par->filterNonMatchingUnicastPkts = ZL5011X_FALSE;
   }

   return status;
}

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

 Function:
   zl5011xLanConfigure

 Description:
   Used to configure a Lan port - setting MAC address and  packet filtering.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   par            Pointer to the structure for configuration items. See below:

 Structure inputs:
   portNum        which port to configure
   macType        how should the MAC be configure - MII, GMII, PCS
   macAddress     address of the MAC (macAddress[0] = high byte - 1st transmitted)
   maxPktLength   how long is the longest packet to receive - will default to
                  the maximum for the VLAN type unless specified
   vlanEnabled    set to ZL5011X_TRUE to enable VLAN tagged packets
   enable64BitMacStats  set to ZL5011X_TRUE to enable 64 bit MAC statistics
                        collection - only required for GMII (uses interrupts)
   osExclusionEnable ZL5011X_TRUE to enable OS exclusion

 Structure outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xLanConfigure(zl5011xParamsS *zl5011xParams, zl5011xLanConfigureS *par)
{
   zlStatusE status = ZL5011X_OK;
   Uint8T internalPortNum;
   Uint32T loop;
   Uint32T countMII = 0, countGMII = 0;
   zl5011xBooleanE gotDevice = ZL5011X_FALSE;

   /* do some parameter checking */
   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_RUNNING(zl5011xParams);
   }

   if ((status == ZL5011X_OK) && (par->osExclusionEnable == ZL5011X_TRUE))
   {
      /* get access to the device */
      status = zl5011xGetDevice(zl5011xParams, ZL5011X_GET_DEVICE_TIMEOUT_MODE);

      if (status == ZL5011X_OK)
      {
         gotDevice = ZL5011X_TRUE;
      }
   }

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
            "zl5011xLanConfigure:",
            0, 0, 0, 0, 0, 0);

      /* check that a valid port has been provided */
      if (par->portNum >= zl5011xParams->devLimits.lanNumLanPorts)
      {
         status = ZL5011X_INVALID_PORT;
      }
      else
      {
         /* Map requested port to real internal one */
         status = zl5011xPkiExternalPortToInternal(zl5011xParams, &internalPortNum, par->portNum);
      }
   }
   if (par->macType == ZL5011X_MAC_TYPE_DISABLED)
   {
      if (status == ZL5011X_OK)
      {
      /* the MAC port is being disabled */
         status = zl5011xPkiEnablePort(zl5011xParams, internalPortNum, ZL5011X_FALSE);

         zl5011xParams->lanPortInitialised[par->portNum] = ZL5011X_FALSE;  /* Array reference is the external port number */
         zl5011xParams->pki.lanPort[internalPortNum].macControl.macType = par->macType;
      }
   }
   else
   { /* MAC port is being enabled */
      if (status == ZL5011X_OK)
      {
         /* If port is to be set to GMII speed then check that the port is GMII capable */
         if (((par->macType == ZL5011X_MAC_TYPE_GMII) || (par->macType == ZL5011X_MAC_TYPE_PCS)) &&
               (par->portNum > zl5011xParams->devLimits.lanNumGbitLanPorts-1))
         {
            /* This port is not GMII capable */
            status = ZL5011X_INVALID_PORT_CONFIG;
         }
      }

      /* Has passed the basic validity tests. Now check for valid combinations.
         Count how many ports of each speed (100 or 1000) would be configured if
         the current configuration went ahead  */
      for (loop = 0; (loop < zl5011xParams->devLimits.lanNumLanPorts) && (status == ZL5011X_OK); loop++)
      {
         if (par->portNum == loop)  /* Include the proposed setting for the current port in the count */
         {
            if (par->macType == ZL5011X_MAC_TYPE_MII)
            {
               countMII++;
            }
            else
            {
               countGMII++;
            }
         }
         else
         {
            if (zl5011xParams->lanPortInitialised[loop] == ZL5011X_TRUE)
            {
               /* port is initialised, how has it been configured? */
               if (status == ZL5011X_OK)
               {
                  if (zl5011xParams->packetIf.lanMacType[loop] == ZL5011X_MAC_TYPE_MII)
                  {
                     countMII++;
                  }
                  else
                  {
                     countGMII++;
                  }
               }
            }
         }
      }

      {
         /* Check that the resulting port combination will be valid */
#ifdef _ZARLINK_TEST_DISABLE_LAN_RULE1
         /* Special build to allow port 2 and 3 to be used together for internal testing.
            Do NOT use this in normal use as the ports are designed for redundancy purposes
            only and are not intended to be used simultaneously in normal use. */
#else
         /* Rule 1: ports 2 & 3 cannot both be configured together */
         if ((status == ZL5011X_OK) &&
             (((par->portNum == 2) && (zl5011xParams->lanPortInitialised[3] == ZL5011X_TRUE)) ||
              ((par->portNum == 3) && (zl5011xParams->lanPortInitialised[2] == ZL5011X_TRUE))))
         {
            status = ZL5011X_INVALID_PORT_CONFIG;
         }
#endif
         /* Rule 2: If all ports are MII then the total maximum number of ports is three */
         if ((status == ZL5011X_OK) && (countGMII == 0) && (countMII > 3))
         {
            status = ZL5011X_INVALID_PORT_CONFIG;
         }
         /* Rule 3: For devices that support more than one GMII-capable port, if either port 0
            or port 1 is configured then the other can only be configured to be the same type.
            The following combinations would be allowed:
               Port 0   Port 1
               MII      MII         Permitted, both ports can be active
               GMII     GMII        Only one port can be active. Second port provides redundancy
               PCS      PCS         Only one port can be active. Second port provides redundancy */
         if ((status == ZL5011X_OK) && (zl5011xParams->devLimits.lanNumGbitLanPorts > 1))
         {
            if (((par->portNum == 0) && (zl5011xParams->lanPortInitialised[1] == ZL5011X_TRUE) &&
                 (par->macType != zl5011xParams->packetIf.lanMacType[1])) ||
                ((par->portNum == 1) && (zl5011xParams->lanPortInitialised[0] == ZL5011X_TRUE) &&
                 (par->macType != zl5011xParams->packetIf.lanMacType[0])))
            {
               status = ZL5011X_INVALID_PORT_CONFIG;
            }
         }
      }

      if (status == ZL5011X_OK)
      {
         if (par->maxPktLength == (Uint32T)ZL5011X_INVALID)
         {
            /* if the calling function has not set a packet length, then
               set the maximum for the VLAN type */

            if (par->vlanEnabled == ZL5011X_FALSE)
            {
               /* maximum packet length for a NON vlan packet is 1518 */
               par->maxPktLength = 1518;
            }
            else
            {
               /* maximum packet length for a vlan packet is 1518 + 4 = 1522 */
               par->maxPktLength = 1522;
            }
         }

         status = zl5011xPkiConfigure(zl5011xParams,
               internalPortNum,
               par->macAddress,
               par->maxPktLength,
               par->macType,
               par->filterBroadcastPkts,
               par->filterMulticastPkts,
               par->filterNonMatchingUnicastPkts,
               par->vlanEnabled,
               par->enable64BitMacStats);
      }

      /* if the port was configured correctly, enable it */
      if (status == ZL5011X_OK)
      {
         /* Store the type of mac configured */
         zl5011xParams->packetIf.lanMacType[par->portNum] = par->macType;

         status = zl5011xPkiEnablePort(zl5011xParams, internalPortNum, ZL5011X_TRUE);

         zl5011xParams->lanPortInitialised[par->portNum] = ZL5011X_TRUE;   /* Array reference is external port num */
      }
   }

   if (gotDevice == ZL5011X_TRUE)
   {
      if (status == ZL5011X_OK)

⌨️ 快捷键说明

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