📄 swmibtb.c
字号:
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* This software is copyrighted by and is the sole property of
* VIA Networking Technologies, Inc. This software may only be used
* in accordance with the corresponding license agreement. Any unauthorized
* use, duplication, transmission, distribution, or disclosure of this
* software is expressly forbidden.
*
* This software is provided by VIA Networking Technologies, Inc. "as is"
* and any express or implied warranties, including, but not limited to, the
* implied warranties of merchantability and fitness for a particular purpose
* are disclaimed. In no event shall VIA Networking Technologies, Inc.
* be liable for any direct, indirect, incidental, special, exemplary, or
* consequential damages.
*
*
* File: swmibtb.c
*
* Purpose: Mib table operation functions
*
* Author: Tevin Chen
*
* Date: Jan 08, 2002
*
* Functions:
*
* Revision History:
*
*/
#if !defined(__STR_H__)
#include "str.h"
#endif
#if !defined(__SWITCH_H__)
#include "switch.h"
#endif
#if !defined(__SWSRAM_H__)
#include "swsram.h"
#endif
#if !defined(__SWMIBTB_H__)
#include "swmibtb.h"
#endif
/*--------------------- Static Definitions ------------------------*/
#define MIB_TBL_PORT_OFFSET 0x0008
#define MIB_TBL_ENTRY_SIZE 16 // 1 mib table entry == 16 bytes == 128 bits
#define SLOT_ENTRY_NUM 4 // 32bits slot, 128/32 = 4
/*--------------------- Static Types ------------------------------*/
/*--------------------- Static Macros -----------------------------*/
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Variables --------------------------*/
/*--------------------- Static Functions --------------------------*/
/*--------------------- Export Variables --------------------------*/
void SWMIBTB_vGetCntr(UINT8 byPortId, UINT8 byCntrId, UINT32 *pdwCntr)
{
UINT32 u32Addr;
u32Addr = SRAM_MIB_TBL_BASE_ADDR + ((byPortId * MIB_TBL_PORT_OFFSET) + (byCntrId / SLOT_ENTRY_NUM)) * MIB_TBL_ENTRY_SIZE;
// Get content of each field
SWSRAM_vReadBlock(u32Addr, SLOT_ENTRY_NUM, byCntrId % SLOT_ENTRY_NUM, (PUINT8)pdwCntr);
}
void SWMIBTB_vClearCntr(UINT8 byPortId, UINT8 byCntrId)
{
UINT32 u32Addr;
u32Addr = SRAM_MIB_TBL_BASE_ADDR + ((byPortId * MIB_TBL_PORT_OFFSET) + (byCntrId / SLOT_ENTRY_NUM)) * MIB_TBL_ENTRY_SIZE;
SWSRAM_vSetBlockEmpty(u32Addr, SLOT_ENTRY_NUM, byCntrId % SLOT_ENTRY_NUM);
}
void SWMIBTB_vGetAllCntr(UINT8 byPortId, SMibCntr *pSMibCntr)
{
PUINT32 pdwTmp;
UINT8 uu;
for (uu = 0; uu < MIBTB_CNTR_NUM; uu++) {
pdwTmp = (PUINT32)( (PUINT8)&(pSMibCntr->dwRxBcastPkt) + uu * sizeof(UINT32) );
SWMIBTB_vGetCntr(byPortId, uu, pdwTmp);
}
}
void SWMIBTB_vClearAllCntr(UINT8 byPortId)
{
UINT8 abySlotBuf[SRAM_ENTRY_SIZE_16Byte];
UINT8 uu, byCnt;
byCnt = ((MIBTB_CNTR_NUM % SLOT_ENTRY_NUM) != 0 ) ? 1 : 0;
byCnt += MIBTB_CNTR_NUM / SLOT_ENTRY_NUM;
STR_pvMemset(abySlotBuf, 0, SRAM_ENTRY_MAX_SIZE);
for (uu = 0; uu < byCnt; uu++)
SWSRAM_bWriteEntry(SRAM_MIB_TBL_BASE_ADDR + ((byPortId * MIB_TBL_PORT_OFFSET) + uu) * MIB_TBL_ENTRY_SIZE, abySlotBuf);
}
void SWMIBTB_vGetPortStatistic(UINT8 byPortId, SPortStatistic *pSPortStatistic)
{
SMibCntr SPortMibCntr;
// Read content of all port-counters
SWMIBTB_vGetAllCntr(byPortId, &SPortMibCntr);
// Calculate amount of good packet received
pSPortStatistic->dwRxGoodPkt = SPortMibCntr.dwRxPkt64 +
SPortMibCntr.dwRxPkt65to127 +
SPortMibCntr.dwRxPkt128to255 +
SPortMibCntr.dwRxPkt256to511 +
SPortMibCntr.dwRxPkt512to1023 +
SPortMibCntr.dwRxPkt1024to1522 +
SPortMibCntr.dwRxPause -
SPortMibCntr.dwRxFCSErr -
SPortMibCntr.dwRxAlignErr;
// Calculate amount of bad packet received
pSPortStatistic->dwRxBadPkt = SPortMibCntr.dwRxOverSizePkt +
SPortMibCntr.dwRxUnderSizePkt +
SPortMibCntr.dwRxFCSErr +
SPortMibCntr.dwRxAlignErr +
SPortMibCntr.dwRxJabber +
SPortMibCntr.dwRxFragment;
// Calculate amount of good packet transmitted
pSPortStatistic->dwTxGoodPkt = SPortMibCntr.dwTxUcastPkt +
SPortMibCntr.dwTxBcastPkt +
SPortMibCntr.dwTxPause +
SPortMibCntr.dwTxMcst;
// Read amount of bad packet transmitted
pSPortStatistic->dwTxBadPkt = SPortMibCntr.dwTxUnderrun;
// Read amount of packet transmitted abort
pSPortStatistic->dwTxAbort = SPortMibCntr.dwTxExcesCollisn;
// Read amount of collision
pSPortStatistic->dwCollision = SPortMibCntr.dwTxCollisn;
// Calculate amount of packet droped
pSPortStatistic->dwDropPkt = SPortMibCntr.dwDropFwdLkup +
SPortMibCntr.dwDropIn;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -