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

📄 swpmactb.c

📁 vt6528芯片交换机API函数和文档运行程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * 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:    swpmactb.c
 *
 * Purpose: Mac table operation functions
 *
 * Author:  Tevin Chen
 *          Henry Lin
 *
 * Date:    Jan 08, 2002
 *          Apr 22, 2005
 *
 * 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




/*---------------------  Static Definitions  ------------------------*/

/*---------------------  Static Types  ------------------------------*/

/*---------------------  Static Macros  -----------------------------*/

/*---------------------  Static Classes  ----------------------------*/

/*---------------------  Static Variables  --------------------------*/

/*---------------------  Static Functions  --------------------------*/
static UINT16 s_wHash(PUINT8 abyMacAddr, UINT16 u16Fid);
static UINT16 s_wInvCRCHash(UINT16 u16Crc, UINT16 u16Fid, PUINT8 abyTag);

static void s_vGetCommonField(UINT16 u16Indx, PUINT8 pbySlot, SMacEntry *pSEntry);
static void s_vSetCommonField(SMacEntry* pSEntry, PUINT8 pbySlot);
static BOOL s_bCheckEmpty(PUINT8 pbySlot);
static BOOL s_bFindInsSlot(PUINT8 pbyEntryBuf, BOOL bIsOverWrite, UINT8 *pbySlotId);

/*---------------------  Export Variables  --------------------------*/


BOOL SWMACTB_bIsEntryStatic(UINT16 u16Indx)
{
    UINT8    abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
    UINT8    bySlotId;
    BOOL    bStatic;
    UINT32  u32Addr;


    // Convert index to SRAM acture address
    u32Addr = PMAC_INDEX_TO_SA(u16Indx);

    bySlotId = GET_PMAC_SLOTID(u32Addr);
    u32Addr  = GET_PMAC_MEMENTRY_ADDR(u32Addr);
    // Read the entry
    SWSRAM_bReadEntry(u32Addr, abyEntryBuf);
    // Check if static entry
    SWSRAM_vExtractBitsByBool(abyEntryBuf + (bySlotId * 8), MAC_BIT_STATIC_S, MAC_BIT_STATIC_E, &bStatic);
    
    return bStatic;
}


/*
 * Input : u16Indx: vaule between 0 and 8191.
 */
BOOL SWMACTB_bIsEntryEmpty(UINT16 u16Indx)
{
    UINT8   au8EntryBuf[SRAM_ENTRY_SIZE_16Byte];
    UINT8    *pbySlot, bySlotId;
    UINT32  u32Addr;


    // Convert index to SRAM address
    u32Addr = PMAC_INDEX_TO_SA(u16Indx);

    bySlotId = GET_PMAC_SLOTID(u32Addr);
    u32Addr  = GET_PMAC_MEMENTRY_ADDR(u32Addr);
    pbySlot = au8EntryBuf + (bySlotId * 8);
            
    // read entry
    SWSRAM_bReadEntry(u32Addr, au8EntryBuf);
    
    return s_bCheckEmpty(pbySlot);
}


BOOL SWMACTB_bIsEntryUcst(UINT16 u16Indx)
{
    UINT8   abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
    UINT8    *pbySlot, bySlotId;
    BOOL    bCast;
    UINT32  u32Addr;


    // Convert index to SRAM address
    u32Addr = PMAC_INDEX_TO_SA(u16Indx);

    bySlotId = GET_PMAC_SLOTID(u32Addr);
    u32Addr  = GET_PMAC_MEMENTRY_ADDR(u32Addr);    
    // read entry
    SWSRAM_bReadEntry(u32Addr, abyEntryBuf);
    pbySlot = abyEntryBuf + (bySlotId *8);
    
    // Check if unicast entry
    SWSRAM_vExtractBitsByBool(pbySlot, MAC_BIT_CAST_TYPE_S, MAC_BIT_CAST_TYPE_E, &bCast);

    //unicast => cast=0
    return !bCast;
}


/*
 * Output : UINT16_MAX:  entry not exist.
 *          entry index: entry exist, the entry index is slot index not memory entry's index
 */
UINT16 SWMACTB_wSearchEntry(PUINT8 abyMacAddr, UINT16 u16Fid)
{
    UINT8    abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
    UINT8    abyTagBuf[MAC_ADDR_SIZE], abyMacAddrBuf[MAC_ADDR_SIZE];
    UINT8    *pbySlot, bySlotId;
    UINT16  u16FIDBuf, u16Indx;
    UINT32  u32HashResult;
    

    // Get entry's sram address by hash(Mac,fid)
    // SramAddr[19:0] = SRAM_PMAC_TBL_BASE_ADDR + (bucket_addr[11:0] << 4)
    u16Indx = SWMACTB_wHash(abyMacAddr, u16Fid);
    u32HashResult = PMAC_MEM_INDEX_TO_SA(u16Indx);

    SWSRAM_bReadEntry(u32HashResult, abyEntryBuf);
    // Check if any of the 2 slots is the desired one
    for (bySlotId = 0; bySlotId < 2; bySlotId++) {

        pbySlot = abyEntryBuf + (bySlotId * 8);
        
        // If empty entry, search next entry
        if (s_bCheckEmpty(pbySlot))
            continue;
            
        // Check FID
        SWSRAM_vExtractBits(pbySlot, MAC_BIT_FID_S, MAC_BIT_FID_E, (PUINT8)&u16FIDBuf);
        if (u16FIDBuf != u16Fid)
            continue;

        // Check MAC Addr
        SWSRAM_vExtractBitsLtl(pbySlot, MAC_BIT_TAG_S, MAC_BIT_TAG_E, abyTagBuf);
        SWMACTB_vInvHash(u16Indx, u16FIDBuf, abyTagBuf, abyMacAddrBuf);
        if (STR_iMemcmp(abyMacAddrBuf, abyMacAddr, MAC_ADDR_SIZE) == 0)
        {
            u16Indx = ((u32HashResult + (bySlotId * 8) - SRAM_PMAC_TBL_BASE_ADDR) >> SHIFT_NUM_SIZE_8Byte);
            return (u16Indx);
        }
    }
    
    // Return hash failed
    return UINT16_MAX;
}


/*
 * Input : u16Indx: The index isn't a memory entry index, it is slot number.
 */
BOOL SWMACTB_bGetEntry(UINT16 u16Indx, SMacEntry* pSEntry)
{
    UINT8    abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
    UINT8    *pbySlot, bySlotId;
    UINT32  u32Addr;


    // Convert index to SRAM address
    u32Addr = PMAC_INDEX_TO_SA(u16Indx);

    bySlotId = GET_PMAC_SLOTID(u32Addr);
    u32Addr  = GET_PMAC_MEMENTRY_ADDR(u32Addr);
    pbySlot  = abyEntryBuf + (bySlotId * 8);

    // Get entry
    SWSRAM_bReadEntry(u32Addr, abyEntryBuf);
    
    // If empty entry or cast type incorrect, search next entry
    if (s_bCheckEmpty(pbySlot))
        return FALSE;

    // Get common fields
    s_vGetCommonField((u16Indx>>0x1), pbySlot, pSEntry);
    //
    if (FALSE == pSEntry->bTypeMcst) { // unicast, port index fields
        SWSRAM_vExtractBitsByBool(pbySlot, MAC_BIT_FLT_SMAC_S, MAC_BIT_FLT_SMAC_E, &(pSEntry->bFltrSmac));    
        SWSRAM_vExtractBitsByBool(pbySlot, MAC_BIT_SMAC_REDIR_S, MAC_BIT_SMAC_REDIR_E, &(pSEntry->bNotRedirSmac));
        SWSRAM_vExtractBitsByBool(pbySlot, MAC_BIT_SMAC_PRI_S, MAC_BIT_SMAC_PRI_E, &(pSEntry->bPriSmac));
        SWSRAM_vExtractBitsByBool(pbySlot, MAC_BIT_CPU_INV_S, MAC_BIT_CPU_INV_E, &(pSEntry->bCpuInv));
        SWSRAM_vExtractBitsByBool(pbySlot, MAC_BIT_TRK_TYPE_S, MAC_BIT_TRK_TYPE_E, &(pSEntry->bTrkGrp));
        SWSRAM_vExtractBitsByByte(pbySlot, MAC_BIT_SRC_ID_S, MAC_BIT_SRC_ID_E, &(pSEntry->u8SrcId));
    }
    else { // multicast, port mask table index
        SWSRAM_vExtractBits(pbySlot, MAC_BIT_MCST_IDX_S, MAC_BIT_MCST_IDX_E, (PUINT8)&pSEntry->u16McstIdx);
    }
          
    return TRUE;
}

/************************************************************************
 * Insert an Primary Mac Address Entry 
 *      Insert an PMAC entry
 ************************************************************************/
BOOL SWMACTB_bInsEntry (SMacEntry* pSEntry, BOOL bIsOverWrite)
{
    UINT8    abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
    UINT8    *pbySlot, bySlotId;
    UINT32  u32InsAddr;
    UINT16  u16Indx;


    // Mac address hash
    // SramAddr[19:0] = SRAM_PMAC_TBL_BASE_ADDR + (bucket_addr[11:0] << 4)
    u16Indx = SWMACTB_wHash(pSEntry->abyMacAddr, pSEntry->u16Fid);
    u32InsAddr = PMAC_MEM_INDEX_TO_SA(u16Indx);

    STR_pvMemset(abyEntryBuf, 0, SRAM_ENTRY_SIZE_16Byte);
    SWSRAM_bReadEntry(u32InsAddr, abyEntryBuf);
    // check slot 0 and slot 1
    if (FALSE == s_bFindInsSlot(abyEntryBuf, bIsOverWrite, &bySlotId))
        return FALSE;
        
    pbySlot = abyEntryBuf + (bySlotId * 8);
    // Set common fields
    s_vSetCommonField(pSEntry, pbySlot);

    if (FALSE == pSEntry->bTypeMcst) {
        // unicast, port index fields
        SWSRAM_vModifyBitsByBool(pbySlot, MAC_BIT_FLT_SMAC_S, MAC_BIT_FLT_SMAC_E, &pSEntry->bFltrSmac);    

⌨️ 快捷键说明

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