📄 swsmactb.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: swsmactb.c
*
* Purpose: Secondary Mac table operation functions
*
* Author: Henry Lin
*
* Date: Dec 06, 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(__SWPMACTB_H__)
#include "swpmactb.h"
#endif
#if !defined(__SWSMACTB_H__)
#include "swsmactb.h"
#endif
/*--------------------- Static Definitions ------------------------*/
#define ENTRY_NUM_OF_RESERVED_PAGE 16 //16 MAC entry
#define TOTAL_NUM_OF_BCAM_PAGE 16
/*--------------------- Static Types ------------------------------*/
/*--------------------- Static Macros -----------------------------*/
#define BCAM_TO_SMAC_SLOTID(x) ((x & 0x00000010) ? 1 : 0) //x is BCAM entry address,ex: x=0xD8010, so relative SMAC entry is in slot1
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Variables --------------------------*/
/*--------------------- Static Functions --------------------------*/
static UINT32 s_u32BcamAddrToSmacAddr(UINT32 u32BcamAddr);
static UINT32 s_u32SmacAddrToBcamAddr(UINT32 u32SmacAddr, UINT8 bySlotId);
static void s_vGetSmacField(SMacEntry* pSEntry, PUINT8 pbySlot);
static void s_vSetSmacField(SMacEntry* pSEntry, PUINT8 pbySlot);
static void s_vGetBcamField(SMacEntry* pSEntry, PUINT8 abyEntryBuf);
static void s_vSetBcamField(SMacEntry* pSEntry, PUINT8 abyEntryBuf);
static UINT32 s_u32GetBcamEmpty(void);
/*--------------------- Export Variables --------------------------*/
/*
* Description : If want to insert B-CAM entry, should reserve page first.
* Once reserve 1 page, can create 16 entries. And reserve 2 pages, can create 32 entries.
* And so on.
* Input : byResvPg: value between 1 and 15.
*/
BOOL SWSMACTB_bReservePage (UINT8 byResvPg)
{
UINT8 abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
UINT8 uu, ii, byAge, byLog;
UINT32 u32BaseAddr, u32Learn;
//Step 1,
//Wait until MAC Address Table Scan Command is finished before changing the setting.
if (!SWREG_bWaitStatus(FWDCTL_SCAN_STATUS, SCAN_STATUS_BUSY, FALSE))
return FALSE;
//Step 2,Disable Auto-aging.
SWREG_vReadU8(FWDCTL_AUTO_AGE_CFG, &byAge);
SWREG_vBitsOffU8(FWDCTL_AUTO_AGE_CFG, AUTO_AGE_EN);
//Step 3,Pause log table and disable auto-learning.
SWREG_vReadU8(FWDCTL_LOG_CTRL, &byLog);
SWREG_vBitsOnU8(FWDCTL_LOG_CTRL, LOG_CTRL_PAUSE);
SWREG_vReadU32(FWDCTL_LEARN_EN, &u32Learn);
SWREG_vWriteU32(FWDCTL_LEARN_EN, 0);
//Step 4,Changing the number of reserved pages.
SWREG_vWriteU8(FWDCTL_SEC_MAC_OWNER_CMD, byResvPg);
//Step 5,After changing the setting, handle log table's entry.
//MACREC_vMain(SWMAC_UPDATE); //TOCHECK
//Step 6,Write 0 to all entries in reserved pages.
// After writing an entry, read back again to make sure the entry is indeed cleared.
//Start Address of reserved area
u32BaseAddr = (SRAM_SECOND_MAC_INDX_BASE_ADDR + SRAM_SECOND_MAC_INDX_SIZE) -
((byResvPg * ENTRY_NUM_OF_RESERVED_PAGE)*SRAM_ENTRY_SIZE_16Byte);
STR_pvMemset(abyEntryBuf, 0, SRAM_ENTRY_SIZE_16Byte);
for (uu = 0; uu < (byResvPg * ENTRY_NUM_OF_RESERVED_PAGE); uu++)
SWSRAM_bWriteEntry(u32BaseAddr + (uu * SRAM_ENTRY_SIZE_16Byte), abyEntryBuf);
for (uu = 0; uu < (byResvPg * ENTRY_NUM_OF_RESERVED_PAGE); uu++) {
SWSRAM_bReadEntry(u32BaseAddr + (uu * SRAM_ENTRY_SIZE_16Byte), abyEntryBuf);
for (ii = 0; ii < SRAM_ENTRY_SIZE_16Byte; ii++) {
if (abyEntryBuf[ii] != 0)
return FALSE;
}
}
//Step 7 Restore Auto-aging , log table and auto-learning setting.
SWREG_vWriteU8(FWDCTL_AUTO_AGE_CFG, byAge);
SWREG_vWriteU8(FWDCTL_LOG_CTRL, byLog);
SWREG_vWriteU32(FWDCTL_LEARN_EN, u32Learn);
return TRUE;
}
/*
* Description : Determine Secondary MAC entry if valid.
* Input : u16Indx: memory entry index for Seconday MAC table.(value between 0 and 127)
* bySlotId: Secondary MAC table one memory entry has two slot(0 or 1).
*/
BOOL SWSMACTB_bIsEntryEmpty (UINT16 u16Indx, UINT8 bySlotId)
{
UINT8 abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
UINT32 u32BcamAddr, u32SmacAddr;
// Convert index to SRAM address
u32SmacAddr = SMAC_INDEX_TO_SA(u16Indx);
u32BcamAddr = s_u32SmacAddrToBcamAddr(u32SmacAddr, bySlotId);
SWSRAM_bReadEntry(u32BcamAddr, abyEntryBuf);
// Check if bit-64 is not 0
if (!((abyEntryBuf[8] & 0x01) == 0))
return FALSE;
return TRUE;
}
//
// Only search entry in reserved page
//
UINT16 SWSMACBCAM_wSearchEntry(PUINT8 abyMacAddr, UINT16 u16Fid)
{
UINT8 abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
UINT8 byResvPg, uu;
UINT16 u16FIDBuf;
UINT32 u32BaseAddr;
#ifdef __TEST_SECMACINDEX
byResvPg = 1;
#else
//the number of reserved pages.
SWREG_vReadU8(FWDCTL_SEC_MAC_OWNER_CMD, &byResvPg);
if (byResvPg == 0)
return UINT16_MAX;
#endif
//Start Address of reserved area
u32BaseAddr = (SRAM_SECOND_MAC_INDX_BASE_ADDR + SRAM_SECOND_MAC_INDX_SIZE) -
((byResvPg * ENTRY_NUM_OF_RESERVED_PAGE) * SRAM_ENTRY_SIZE_16Byte);
STR_pvMemset(abyEntryBuf, 0, SRAM_ENTRY_SIZE_16Byte);
for (uu = 0; uu < (byResvPg * ENTRY_NUM_OF_RESERVED_PAGE); uu++) {
SWSRAM_bReadEntry(u32BaseAddr + (uu * SRAM_ENTRY_SIZE_16Byte), abyEntryBuf);
// Check if [64] is on, bit[64]==0 means the entry invalid
if ((abyEntryBuf[8] & 0x01) == 0)
continue;
// Check FID
SWSRAM_vExtractBits(abyEntryBuf, BCAM_BIT_FID_S, BCAM_BIT_FID_E, (PUINT8)&u16FIDBuf);
if (u16FIDBuf != u16Fid)
continue;
else {
// Check MAC Addr
if (STR_iMemcmp(&abyEntryBuf[2], abyMacAddr, MAC_ADDR_SIZE) != 0 )
continue;
else
return (((u32BaseAddr - SRAM_SECOND_MAC_INDX_BASE_ADDR)/SRAM_ENTRY_SIZE_16Byte) + uu);
}
}
// Return search failed
return UINT16_MAX;
}
//
// Only search entry in none reserved page
//
UINT16 SWSMACBCAM_wSearchEntryInHw(PUINT8 abyMacAddr, UINT16 u16Fid)
{
UINT8 abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
UINT8 byResvPg;
UINT16 u16FIDBuf;
UINT32 u32BaseAddr;
UINT16 u16Cnt;
UINT8 u8LeftPageNum;
//the number of reserved pages.
SWREG_vReadU8(FWDCTL_SEC_MAC_OWNER_CMD, &byResvPg);
//Start Address of none reserved area
u32BaseAddr = SRAM_SECOND_MAC_INDX_BASE_ADDR;
u8LeftPageNum = TOTAL_NUM_OF_BCAM_PAGE - byResvPg;
STR_pvMemset(abyEntryBuf, 0, SRAM_ENTRY_SIZE_16Byte);
for(u16Cnt = 0; u16Cnt < (u8LeftPageNum * ENTRY_NUM_OF_RESERVED_PAGE); u16Cnt++) {
SWSRAM_bReadEntry(u32BaseAddr + (u16Cnt * SRAM_ENTRY_SIZE_16Byte), abyEntryBuf);
// Check if [64] is on, bit[64]==0 means the entry invalid
if ((abyEntryBuf[8] & 0x01) == 0)
continue;
// Check FID
SWSRAM_vExtractBits(abyEntryBuf, BCAM_BIT_FID_S, BCAM_BIT_FID_E, (PUINT8)&u16FIDBuf);
if (u16FIDBuf != u16Fid)
continue;
else {
// Check MAC Addr
if(STR_iMemcmp(&abyEntryBuf[2], abyMacAddr, MAC_ADDR_SIZE) != 0 )
continue;
else
return u16Cnt;
}
}
// Return search failed
return UINT16_MAX;
}
/*
* Input : u16Indx: vaule between 0 and 255.
*/
BOOL SWSMACBCAM_bIsEntryEmpty (UINT16 u16Indx)
{
UINT8 abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
UINT32 u32BcamAddr;
u32BcamAddr = BCAM_INDEX_TO_SA(u16Indx);
// read entry
SWSRAM_bReadEntry(u32BcamAddr, abyEntryBuf);
// Check if bit-64 is not 0
if (!((abyEntryBuf[8] & 0x01) == 0))
return FALSE;
return TRUE;
}
/*
* Input : u16Indx: vaule between 0 and 255.
*/
BOOL SWSMACTB_bGetEntry(UINT16 u16Indx, SMacEntry* pSEntry)
{
UINT8 abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
UINT8 bySlotId;
UINT32 u32BcamAddr;
if (SWSMACBCAM_bIsEntryEmpty(u16Indx) )
return FALSE;
u32BcamAddr = BCAM_INDEX_TO_SA(u16Indx);
// Read matched BCAM entry
STR_pvMemset(abyEntryBuf, 0, SRAM_ENTRY_SIZE_16Byte);
SWSRAM_bReadEntry(u32BcamAddr, abyEntryBuf);
s_vGetBcamField(pSEntry, abyEntryBuf);
// Read SMAC entry
STR_pvMemset(abyEntryBuf, 0, SRAM_ENTRY_SIZE_16Byte);
SWSRAM_bReadEntry(s_u32BcamAddrToSmacAddr(u32BcamAddr), abyEntryBuf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -