📄 swlogtb.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: swlogtb.c
*
* Purpose: MAC address table change log table operation functions
*
* Author: Henry Lin
*
* Date: Nov 08, 2004
*
* Functions:
*
* Revision History:
*
*/
#if !defined(__STR_H__)
#include "str.h"
#endif
#if !defined(__SWITCH_H__)
#include "switch.h"
#endif
#if !defined(__SWREG_H__)
#include "swreg.h"
#endif
#if !defined(__SWSRAM_H__)
#include "swsram.h"
#endif
#if !defined(__SWLOGTB_H__)
#include "swlogtb.h"
#endif
/*--------------------- Static Definitions ------------------------*/
#define LOGTBL_PTR_BASE 0x400
#define LOGTBL_ENTRY_NUMBER 0xC00
#define LOG_ENTRY_SIZE SRAM_ENTRY_SIZE_16Byte
/*--------------------- Static Types ------------------------------*/
/*--------------------- Static Macros -----------------------------*/
#define MACLOG_INDEX_TO_SA(indx) (SRAM_MAC_LOG_TBL_BASE_ADDR + (indx<<SHIFT_NUM_SIZE_16Byte))
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Variables --------------------------*/
/*--------------------- Static Functions --------------------------*/
static void s_vGetField (UINT16 u16Indx, SLogEntry *pSEntry);
/*--------------------- Export Variables --------------------------*/
BOOL SWLOGTB_bIsEntryEmpty(UINT16 u16Indx)
{
UINT8 au8EntryBuf[LOG_ENTRY_SIZE], uu;
UINT32 u32EntryAddr;
u32EntryAddr = MACLOG_INDEX_TO_SA(u16Indx);
// read memory entry
SWSRAM_bReadEntry(u32EntryAddr, au8EntryBuf);
for (uu = 0; uu < LOG_ENTRY_SIZE; uu++) {
if (au8EntryBuf[uu] != 0)
return FALSE;
}
return TRUE;
}
BOOL SWLOGTB_bGetEntry (SLogEntry *pSEntry)
{
UINT16 u16LogReadPtr, u16UnreadNum, u16Indx;
UINT32 u32EntryAddr;
// read unread pointer
SWREG_vReadU16(FWDCTL_UNRD_READ_PTR, &u16LogReadPtr);
// read unread number
SWREG_vReadU16(FWDCTL_NUM_UNRD_ENTRY, &u16UnreadNum);
if (0 == u16UnreadNum)
return FALSE;
// calculate address
u32EntryAddr = SRAM_MAC_LOG_TBL_BASE_ADDR + ((u16LogReadPtr - LOGTBL_PTR_BASE) % LOGTBL_ENTRY_NUMBER) * LOG_ENTRY_SIZE;
// calculate index
u16Indx = (u16LogReadPtr - LOGTBL_PTR_BASE) % LOGTBL_ENTRY_NUMBER;
s_vGetField(u16Indx, pSEntry);
// write processed number
SWREG_vWriteU16(FWDCTL_NUM_PROC_ENTRY, 1);
return TRUE;
}
BOOL SWLOGTB_bGetEntryByIndx(UINT16 u16Indx, SLogEntry *pSEntry)
{
s_vGetField(u16Indx, pSEntry);
return TRUE;
}
static void s_vGetField (UINT16 u16Indx, SLogEntry *pSEntry)
{
UINT8 au8EntryBuf[LOG_ENTRY_SIZE];
UINT32 u32EntryAddr;
u32EntryAddr = MACLOG_INDEX_TO_SA(u16Indx);
SWSRAM_bReadEntry(u32EntryAddr, au8EntryBuf);
// case type
SWSRAM_vExtractBitsByBool(au8EntryBuf, LOG_BIT_CAST_TYPE_S, LOG_BIT_CAST_TYPE_E, &pSEntry->bTypeMcst);
if (FALSE == pSEntry->bTypeMcst) { //unicast
SWSRAM_vExtractBitsByBool(au8EntryBuf, LOG_BIT_FLT_SMAC_S, LOG_BIT_FLT_SMAC_E, &(pSEntry->bFltrSmac));
SWSRAM_vExtractBitsByBool(au8EntryBuf, LOG_BIT_SMAC_REDIR_S, LOG_BIT_SMAC_REDIR_E, &(pSEntry->bNotRedirSmac));
// trunk group or not
SWSRAM_vExtractBitsByBool(au8EntryBuf, LOG_BIT_TRK_TYPE_S, LOG_BIT_TRK_TYPE_E, &(pSEntry->bTrkGrp));
// source port id
SWSRAM_vExtractBitsByByte(au8EntryBuf, LOG_BIT_SRC_ID_S, LOG_BIT_SRC_ID_E, &(pSEntry->u8SrcId));
}
else {
// multicast mask
SWSRAM_vExtractBits(au8EntryBuf, LOG_BIT_MCST_MASK_S, LOG_BIT_MCST_MASK_E, (PUINT8)&(pSEntry->u16McstIdx));
}
// log entry property
SWSRAM_vExtractBitsByByte(au8EntryBuf, LOG_BIT_SECU_VIO_S, LOG_BIT_SECU_VIO_E, &pSEntry->u8SecuVio);
SWSRAM_vExtractBitsByBool(au8EntryBuf, LOG_BIT_LEARNING_S, LOG_BIT_LEARNING_E, &pSEntry->bLearning);
SWSRAM_vExtractBitsByByte(au8EntryBuf, LOG_BIT_SCAN_S, LOG_BIT_SCAN_E, &pSEntry->u8Scan);
SWSRAM_vExtractBitsByBool(au8EntryBuf, LOG_BIT_AGEOUT_S, LOG_BIT_AGEOUT_E, &pSEntry->bAgeOut);
SWSRAM_vExtractBitsByBool(au8EntryBuf, LOG_BIT_LOCCHG_S, LOG_BIT_LOCCHG_E, &pSEntry->bLocChg);
// extra entry id
SWSRAM_vExtractBits(au8EntryBuf, LOG_BIT_EXTRA_ENTRYID_S, LOG_BIT_EXTRA_ENTRYID_E, (PUINT8)&pSEntry->u16ExtraEntryId);
// entry id
SWSRAM_vExtractBits(au8EntryBuf, LOG_BIT_ENTRYID_S, LOG_BIT_ENTRYID_E, (PUINT8)&pSEntry->u16EntryId);
// mac address
SWSRAM_vExtractBitsLtl(au8EntryBuf, LOG_BIT_MACADDR_S, LOG_BIT_MACADDR_E, pSEntry->abyMacAddr);
// fid
SWSRAM_vExtractBits(au8EntryBuf, LOG_BIT_FID_S, LOG_BIT_FID_E, (PUINT8)&pSEntry->u16Fid);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -