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

📄 zl5011xpki.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 4 页
字号:
     zl5011xPkiReadCounters() should be called before this fn.
*******************************************************************************/
extern zlStatusE zl5011xPkiGetEtherStats(zl5011xParamsS *zl5011xParams,
                                        Uint8T      portNum,
                                        zl5011xEtherStatsS * pEtherStats)
{
   zlStatusE status = ZL5011X_OK;
   zl5011xMacStatsS *pMacStats;

   ZL5011X_TRACE(ZL5011X_PKI_FN_ID,
         "zl5011xPkiGetEtherStats: port %d ",
         portNum, 0, 0, 0, 0, 0);

   if( status== ZL5011X_OK)
   {
      if( pEtherStats== NULL)
      {
         status= ZL5011X_PARAMETER_INVALID;
      }
   }

   if( status== ZL5011X_OK)
   {
      /* zero the EtherStats structure contents */
      (void)memset( pEtherStats, 0, sizeof(zl5011xEtherStatsS));

      /* pointer just saves typing */
      pMacStats= &(zl5011xParams->pki.lanPort[ portNum].macStats);

      pEtherStats->etherStatsIndex= portNum;

      /* fill EtherStats from Mac Stats data */
      pEtherStats->etherStatsDropEvents  = pMacStats->dropEvent;
      pEtherStats->etherStatsOctets = pMacStats->totalOctetsReceived;
      pEtherStats->etherStatsPkts = pMacStats->totalPktsReceived;
      pEtherStats->etherStatsBroadcastPkts = pMacStats->broadcastPktsReceived;
      pEtherStats->etherStatsMulticastPkts = pMacStats->multicastPktsReceived;
      pEtherStats->etherStatsCRCAlignErrors= pMacStats->alignmentError;
      status= zl5011xPkiAdd64bit( &(pEtherStats->etherStatsCRCAlignErrors),
                                                               &(pMacStats->crc));
   }
   if( status== ZL5011X_OK)
   {  /* continue */
      pEtherStats->etherStatsUndersizePkts = pMacStats->undersize;
      pEtherStats->etherStatsOversizePkts = pMacStats->oversize;
      pEtherStats->etherStatsFragments = pMacStats->fragment;
      pEtherStats->etherStatsJabbers = pMacStats->jabber;
      pEtherStats->etherStatsCollisions = pMacStats->collision;
      status= zl5011xPkiAdd64bit(&(pEtherStats->etherStatsCollisions),
                                                   &(pMacStats->lateCollision));
   }
   if( status== ZL5011X_OK)
   {  /* continue */
      pEtherStats->etherStatsPkts64Octets = pMacStats->pkts64Octets;
      pEtherStats->etherStatsPkts65to127Octets = pMacStats->pkts65To127Octets;
      pEtherStats->etherStatsPkts128to255Octets = pMacStats->pkts128To255Octets;
      pEtherStats->etherStatsPkts256to511Octets = pMacStats->pkts256To511Octets;
      pEtherStats->etherStatsPkts512to1023Octets = pMacStats->pkts512To1023Octets;
      pEtherStats->etherStatsPkts1024to1518Octets = pMacStats->pkts1024To1518Octets;
   }
   return(status);
}


/*******************************************************************************
 Function:
    zl5011xPkiGetIfStats


 Description:
   Reads the port counters out of the device structure and formats the stats, using
   64 bit counters if they are enabled.
   Conforms with RFC 2863 for Remote Network Monitoring MIB.

 Inputs:
    zl5011xParams      Pointer to the structure for this device instance
    Uint8T  portNum        - port number 0 to 3
    zl5011xIfStatsS *     pIfStats  - pointer to the structure to receive the data

 Outputs:

 Returns:
    zlStatusE

 Remarks:
     zl5011xPkiReadCounters() should be called before this fn.
     pIfStats->ifStatsInUnknownProtos needs to be maintained by protocol stack
     Need to verify that OutOctets needs to include framing bytes
*******************************************************************************/
extern zlStatusE zl5011xPkiGetIfStats(zl5011xParamsS *zl5011xParams, Uint8T portNum,
                                     zl5011xIfStatsS * pIfStats)
{
   zlStatusE status = ZL5011X_OK;
   zl5011xMacStatsS *pMacStats;
   int n= 0;

   ZL5011X_TRACE(ZL5011X_PKI_FN_ID, "zl5011xPkiGetIfStats: port number %d ", portNum, 0, 0, 0, 0, 0);

   if( status== ZL5011X_OK)
   {
      /* zero the IfStats structure contents */
      (void)memset( pIfStats, 0, sizeof(zl5011xIfStatsS));

      /* pointer just saves typing */
      pMacStats= &(zl5011xParams->pki.lanPort[ portNum].macStats);

      /* copy from Mac Stats data to IF stats */
      pIfStats->ifInOctets = pMacStats->totalOctetsReceived;
      pIfStats->ifInUcastPkts = pMacStats->totalPktsReceived;
      status= zl5011xPkiSubtract64bit(&(pIfStats->ifInUcastPkts),
                                           &(pMacStats->broadcastPktsReceived));
      if( status== ZL5011X_OK)
      {
         status= zl5011xPkiSubtract64bit(&(pIfStats->ifInUcastPkts),
                                           &(pMacStats->multicastPktsReceived));
         if( status== ZL5011X_OK)
         {
            status= zl5011xPkiSubtract64bit(&(pIfStats->ifInUcastPkts),
                                                            &(pMacStats->crc));
            if( status== ZL5011X_OK)
            {
               status= zl5011xPkiSubtract64bit(&(pIfStats->ifInUcastPkts),
                                                   &(pMacStats->alignmentError));
               if( status== ZL5011X_OK)
               {
                  status= zl5011xPkiSubtract64bit(&(pIfStats->ifInUcastPkts),
                                                         &(pMacStats->fragment));

                  if( status== ZL5011X_OK)
                  {
                     status= zl5011xPkiSubtract64bit(&(pIfStats->ifInUcastPkts),
                                                         &(pMacStats->jabber));
                  }
               }
            }
         }
      }
   }
   if( status== ZL5011X_OK)
   {
      pIfStats->ifInNUcastPkts = pMacStats->broadcastPktsReceived;
      status= zl5011xPkiAdd64bit(&(pIfStats->ifInNUcastPkts),
                                             &(pMacStats->multicastPktsReceived));
   }
   if( status== ZL5011X_OK)
   {
      pIfStats->ifInDiscards = pMacStats->dropEvent;
      pIfStats->ifInErrors = pMacStats->crc;
      status= zl5011xPkiAdd64bit(&(pIfStats->ifInErrors), &(pMacStats->crc));
      if( status== ZL5011X_OK)
      {
         status= zl5011xPkiAdd64bit(&(pIfStats->ifInErrors),
                                                   &(pMacStats->alignmentError));
         if( status== ZL5011X_OK)
         {
            status= zl5011xPkiAdd64bit(&(pIfStats->ifInErrors),
                                                         &(pMacStats->fragment));
            if( status== ZL5011X_OK)
            {
               status= zl5011xPkiAdd64bit(&(pIfStats->ifInErrors),
                                                            &(pMacStats->jabber));
            }
         }
      }
   }
   if( status== ZL5011X_OK)
   {
      pIfStats->ifOutOctets = pMacStats->totalOctetsSent;
      pIfStats->ifOutUcastPkts = pMacStats->ucastPktsSent;
      pIfStats->ifOutNUcastPkts = pMacStats->nUcastPktsSent;
      pIfStats->ifOutDiscards = 0;
      pIfStats->ifOutErrors = pMacStats->pktSentFail;
      pIfStats->ifIndex = 0;
      pIfStats->ifType = 0;
      pIfStats->ifMtu = 0;
      pIfStats->ifSpeed = 0;
      for(n=0;n< ZL5011X_MAC_SIZE ;n++)
      {
        pIfStats->ifPhysAddress[n]=zl5011xParams->pki.lanPort[ portNum].macAddress[n];
      }
   }
   return(status);
}

/*******************************************************************************
 Function:
    zl5011xPkiGetWrapStatus

 Description:
   This returns the state of the counter wrap bits for the port. This will be
   called by the counter update routine from the ISR.

 Inputs:
    zl5011xParams      Pointer to the structure for this device instance
    Uint8T  portNum        - port number 0 to 3
    Uint32T *pStatsWraps   - returns the counter wrap bits

 Outputs:

 Returns:
    zlStatusE

 Remarks:
   Interrupts will have been disabled by the calling function.
*******************************************************************************/
extern zlStatusE zl5011xPkiGetWrapStatus(zl5011xParamsS *zl5011xParams,
                                             Uint8T   portNum,
                                             Uint32T  *pStatsWraps)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T pkiAddress=0;

   ZL5011X_TRACE(ZL5011X_PKI_FN_ID, "zl5011xPkiGetWrapStatus: port number %d ",
                           portNum, 0, 0, 0, 0, 0);

   if( status== ZL5011X_OK)
   {
      if( pStatsWraps== NULL)
      {
         status= ZL5011X_PARAMETER_INVALID;
      }
   }

   /* check relevant Wrap Reg */
   if( status== ZL5011X_OK)
   {
      pkiAddress= ZL5011X_WAS0_CPU_RDATA+ (portNum* sizeof(Uint32T));
      status= zl5011xRead( zl5011xParams, pkiAddress, pStatsWraps);
      *pStatsWraps= (*pStatsWraps)& ZL5011X_WRAP_ALL;
   }

   ZL5011X_TRACE(ZL5011X_PKI_FN_ID, "zl5011xPkiGetWrapStatus: port number %d, value: 0x%.8lx",
                           portNum, *pStatsWraps, 0, 0, 0, 0);
   return(status);
}

/*******************************************************************************
 Function:
    zl5011xPkiUpdateCounters

 Description:
   Updates the s/w counters which have wrapped. All of the counts in the device
   are 32 bits, so only need this for the 64 bit counts.
   This function updates the top 32 bits of those counters held in the device structure
   which are identified in a bit mask for the port. The bitmask is also held in the
   device structure.

 Inputs:
    zl5011xParams      Pointer to the structure for this device instance
    Uint8T  portNum        - port number 0 to 3

 Outputs:

 Returns:
    zlStatusE

 Remarks:
This is called from the ISR.

*******************************************************************************/
extern zlStatusE zl5011xPkiUpdateCounters(zl5011xParamsS *zl5011xParams,
                                         Uint8T  portNum)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T rolloverReg= 0;
   Uint32T i;

   ZL5011X_TRACE(ZL5011X_PKI_FN_ID,
         "zl5011xPkiUpdateCounters: port %d",
         portNum, 0, 0, 0, 0, 0);

   /* if statistics mode 64 bit */
   if (zl5011xParams->pki.lanPort[portNum].macStats64bits == ZL5011X_TRUE)
   {
      /* read the rollover status & check against 64 bit requirement mask in structure */
      status = zl5011xPkiGetWrapStatus( zl5011xParams, portNum, &rolloverReg );
      rolloverReg &= zl5011xParams->interruptMasks.pkiLanPortMasks[portNum].mask32BitWrap;

      /* loop for all counters  */
      for( i= 0; i < ZL5011X_PKI_MAC_STATS_SIZE; i++)
      {
         /* if this counter rollover has occurred */
         if ((rolloverReg & (ZL5011X_1BIT_MASK << i)) != 0)
         {
            zl5011xParams->pki.lanPort[portNum].upper32Ctr[i]++;
         }
      }
   }

   return(status);
}

/*******************************************************************************
 Function:
    zl5011xPkiReadCounters

 Description:
   This reads the counters from the device into the device structure. This function
   would be called prior to calling PkiGetEtherStats or PkiGetIfStats, so as to get
   the current count values from the port. The device structure holds an array of
   count values, where each count is a 64 bit structure. For counts that are identified
   as 32 bit, the top 32 bits will not be maintained by the ISR, and are only present
   to give a simple data structure for manipulation.

   The mechanism for reading the counters is as follows:
   

⌨️ 快捷键说明

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