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

📄 swsmactb.c

📁 vt6528芯片交换机API函数和文档运行程序
💻 C
📖 第 1 页 / 共 2 页
字号:

    bySlotId = BCAM_TO_SMAC_SLOTID(u32BcamAddr);
    s_vGetSmacField(pSEntry, (abyEntryBuf + bySlotId * 3));

    return TRUE;    
}


BOOL SWSMACTB_bInsEntry (SMacEntry* pSEntry, BOOL bIsOverWrite)
{
    UINT8   abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
    UINT8   bySlotId;
    UINT32  u32BcamAddr, u32SmacAddr;
    UINT16  u16Indx;

    
    STR_pvMemset(abyEntryBuf, 0, SRAM_ENTRY_SIZE_16Byte);
    u16Indx = SWSMACBCAM_wSearchEntry(pSEntry->abyMacAddr, pSEntry->u16Fid);
    u32BcamAddr = BCAM_INDEX_TO_SA(u16Indx);

    if (u16Indx == UINT16_MAX) {
        // If entry don't exist, find an empty
        u32BcamAddr = s_u32GetBcamEmpty();
        if (u32BcamAddr == UINT32_MAX) {
            // no space
            return FALSE;
        }            
    }
    else {
        // Entry exist
        if (FALSE == bIsOverWrite) {
            // don't overwrite
            return FALSE;
        }
    }

    // Write to BCAM fields
    s_vSetBcamField(pSEntry, abyEntryBuf);
    SWSRAM_bWriteEntry(u32BcamAddr, abyEntryBuf);
    
    // Write to  SMAC table 
    STR_pvMemset(abyEntryBuf, 0, SRAM_ENTRY_SIZE_16Byte);
    u32SmacAddr = s_u32BcamAddrToSmacAddr(u32BcamAddr);
    SWSRAM_bReadEntry(u32SmacAddr, abyEntryBuf);

    bySlotId = BCAM_TO_SMAC_SLOTID(u32BcamAddr);
    s_vSetSmacField(pSEntry, (abyEntryBuf + bySlotId * 3));
    SWSRAM_bWriteEntry(u32SmacAddr, abyEntryBuf);
    
    return TRUE;
}


BOOL SWSMACTB_bDelEntry(PUINT8 abyMacAddr, UINT16 u16Fid)
{
    UINT16  u16Indx;


    // Search entry
    u16Indx = SWSMACBCAM_wSearchEntry(abyMacAddr, u16Fid);
    // If search failed, return FALSE
    if (u16Indx == UINT16_MAX)
        return FALSE;

    // clear BCAM entry
    SWSMACTB_vDelEntryByIndx(u16Indx);
    
    return TRUE;
}


/*
 * Input : u16Indx: vaule between 0 and 255.
 */
void SWSMACTB_vDelEntryByIndx(UINT16 u16Indx)
{
    UINT8   au8EntryBuf[SRAM_ENTRY_SIZE_16Byte];
    UINT32  u32BcamAddr;
    
    
    u32BcamAddr = BCAM_INDEX_TO_SA(u16Indx);

    // Write sram data, we want to clear bit-64
    au8EntryBuf[8] = 0;
    // write entry
    SWSRAM_bWriteEntry(u32BcamAddr, au8EntryBuf);    
}




// static function
static UINT32 s_u32BcamAddrToSmacAddr (UINT32 u32BcamAddr)
{
    UINT8  byOffset;
    UINT32 u32ActAddr;
    
    
    byOffset = (u32BcamAddr - SRAM_SECOND_MAC_INDX_BASE_ADDR) >> SHIFT_NUM_SIZE_16Byte;
    u32ActAddr = SRAM_SECOND_MAC_TBL_BASE_ADDR + ((byOffset/2) << SHIFT_NUM_SIZE_8Byte);

    return u32ActAddr;
}


static UINT32 s_u32SmacAddrToBcamAddr (UINT32 u32SmacAddr, UINT8 bySlotId)
{
    UINT8  byOffset;
    UINT32 u32BcamAddr;
    
    
    byOffset    = (((u32SmacAddr - SRAM_SECOND_MAC_TBL_BASE_ADDR) >> SHIFT_NUM_SIZE_8Byte) * 2) + bySlotId;
    u32BcamAddr = SRAM_SECOND_MAC_INDX_BASE_ADDR + (byOffset << SHIFT_NUM_SIZE_16Byte);

    return u32BcamAddr;
}


static void s_vGetSmacField (SMacEntry* pSEntry, PUINT8 pbySlot)
{    
    SWSRAM_vExtractBits(pbySlot, SMAC_BIT_BIND_ID_S, SMAC_BIT_BIND_ID_E, (PUINT8)&pSEntry->byBindId);
    SWSRAM_vExtractBitsByBool(pbySlot, SMAC_BIT_STATIC_S, SMAC_BIT_STATIC_E, &pSEntry->bStatic);
    SWSRAM_vExtractBitsByBool(pbySlot, SMAC_BIT_CAST_TYPE_S, SMAC_BIT_CAST_TYPE_E, &pSEntry->bTypeMcst);         

    if (TRUE == pSEntry->bStatic) { 
        // static, option fields
        SWSRAM_vExtractBitsByBool(pbySlot, SMAC_BIT_SEC_DRP_S, SMAC_BIT_SEC_DRP_E, &pSEntry->bSecDropExcp);   
        SWSRAM_vExtractBitsByBool(pbySlot, SMAC_BIT_DMAC_PRI_S, SMAC_BIT_DMAC_PRI_E, &pSEntry->bPriDmac);   
        SWSRAM_vExtractBitsByBool(pbySlot, SMAC_BIT_DMAC_REDIR_S, SMAC_BIT_DMAC_REDIR_E, &pSEntry->bNotRedirDmac);   
    }
    else {
        // dynamic, age count
        SWSRAM_vExtractBitsByByte(pbySlot, SMAC_BIT_AGE_COUNT_S, SMAC_BIT_AGE_COUNT_E, &pSEntry->u8AgeCnt);
    }
    
    if (FALSE == pSEntry->bTypeMcst) {
        // unicast, port index fields            
        SWSRAM_vExtractBitsByBool(pbySlot, SMAC_BIT_SMAC_FLT_S, SMAC_BIT_SMAC_FLT_E, &pSEntry->bFltrSmac);    
        SWSRAM_vExtractBitsByBool(pbySlot, SMAC_BIT_SMAC_REDIR_S, SMAC_BIT_SMAC_REDIR_E, &pSEntry->bNotRedirSmac);
        SWSRAM_vExtractBitsByBool(pbySlot, SMAC_BIT_SMAC_PRI_S, SMAC_BIT_SMAC_PRI_E, &pSEntry->bPriSmac);
        SWSRAM_vExtractBitsByBool(pbySlot, SMAC_BIT_SMAC_CPU_S, SMAC_BIT_SMAC_CPU_E, &pSEntry->bCpuInv);
        SWSRAM_vExtractBitsByBool(pbySlot, SMAC_BIT_TRK_TYPE_S, SMAC_BIT_TRK_TYPE_E, &pSEntry->bTrkGrp);
        SWSRAM_vExtractBitsByByte(pbySlot, SMAC_BIT_SRC_ID_S, SMAC_BIT_SRC_ID_E, &pSEntry->u8SrcId);
    }
    else {
        // multicast, port mask table index
        SWSRAM_vExtractBits(pbySlot, SMAC_BIT_MCST_INDEX_S, SMAC_BIT_MCST_INDEX_E, (PUINT8)(&pSEntry->u16McstIdx));            
    }                    
}


static void s_vSetSmacField (SMacEntry* pSEntry, PUINT8 pbySlot)
{
    UINT32  u32McstAddr, u32PortMsk = 0;
    UINT16  u16McstIdx;

    // Set SMAC/SIP Binding ID
    SWSRAM_vModifyBits(pbySlot, SMAC_BIT_BIND_ID_S, SMAC_BIT_BIND_ID_E, (PUINT8)&(pSEntry->byBindId));  
    SWSRAM_vModifyBitsByBool(pbySlot, SMAC_BIT_STATIC_S, SMAC_BIT_STATIC_E, &(pSEntry->bStatic));
    SWSRAM_vModifyBitsByBool(pbySlot, SMAC_BIT_CAST_TYPE_S, SMAC_BIT_CAST_TYPE_E, &(pSEntry->bTypeMcst));

    if (TRUE == pSEntry->bStatic) {
        // static, option fields
        SWSRAM_vModifyBitsByBool(pbySlot, SMAC_BIT_SEC_DRP_S, SMAC_BIT_SEC_DRP_E, &pSEntry->bSecDropExcp);
        SWSRAM_vModifyBitsByBool(pbySlot, SMAC_BIT_DMAC_PRI_S, SMAC_BIT_DMAC_PRI_E, &pSEntry->bPriDmac);
        SWSRAM_vModifyBitsByBool(pbySlot, SMAC_BIT_DMAC_REDIR_S, SMAC_BIT_DMAC_REDIR_E, &pSEntry->bNotRedirDmac);
    }
    else {
        // dynamic, age count
        SWSRAM_vModifyBitsByByte(pbySlot, SMAC_BIT_AGE_COUNT_S, SMAC_BIT_AGE_COUNT_E, &(pSEntry->u8AgeCnt));        
    }
    
    if (FALSE == pSEntry->bTypeMcst) {
        // unicast, port index fields
        SWSRAM_vModifyBitsByBool(pbySlot, SMAC_BIT_SMAC_FLT_S, SMAC_BIT_SMAC_FLT_E, &(pSEntry->bFltrSmac));
        SWSRAM_vModifyBitsByBool(pbySlot, SMAC_BIT_SMAC_REDIR_S, SMAC_BIT_SMAC_REDIR_E, &(pSEntry->bNotRedirSmac));
        SWSRAM_vModifyBitsByBool(pbySlot, SMAC_BIT_SMAC_PRI_S, SMAC_BIT_SMAC_PRI_E, &(pSEntry->bPriSmac));
        SWSRAM_vModifyBitsByBool(pbySlot, SMAC_BIT_SMAC_CPU_S, SMAC_BIT_SMAC_CPU_E, &(pSEntry->bCpuInv));            
        SWSRAM_vModifyBitsByBool(pbySlot, SMAC_BIT_TRK_TYPE_S, SMAC_BIT_TRK_TYPE_E, &(pSEntry->bTrkGrp));
        SWSRAM_vModifyBitsByByte(pbySlot, SMAC_BIT_SRC_ID_S, SMAC_BIT_SRC_ID_E, &(pSEntry->u8SrcId));
    }
    else {
        // reset original port mask entry
        SWSRAM_vExtractBits(pbySlot, SMAC_BIT_MCST_INDEX_S, SMAC_BIT_MCST_INDEX_E, (PUINT8)&u16McstIdx);            
        u32McstAddr = SRAM_PTMSK_TBL_BASE_ADDR + (u16McstIdx << 2);
        {
            UINT8   abyBuf[4];
            SWSRAM_vModifyBits(abyBuf, 0, 31, (PUINT8)&u32PortMsk);
            SWSRAM_bWriteEntry(u32McstAddr, abyBuf);        
        }

        // multicast, port mask table index
        SWSRAM_vModifyBits(pbySlot, SMAC_BIT_MCST_INDEX_S, SMAC_BIT_MCST_INDEX_E, (PUINT8)&(pSEntry->u16McstIdx));           
    }
}


static void s_vGetBcamField(SMacEntry* pSEntry, PUINT8 abyEntryBuf)
{
    // Get mac address
    SWSRAM_vExtractBitsLtl(abyEntryBuf, BCAM_BIT_MAC_ADDR_S, BCAM_BIT_MAC_ADDR_E, pSEntry->abyMacAddr);        
    // Get match address type
    SWSRAM_vExtractBitsByBool(abyEntryBuf, BCAM_BIT_ADDR_TYPE_S, BCAM_BIT_ADDR_TYPE_E, &pSEntry->bIpMcst);
    // Get fid field
    SWSRAM_vExtractBits(abyEntryBuf, BCAM_BIT_FID_S, BCAM_BIT_FID_E, (PUINT8)&pSEntry->u16Fid);    
}


static void s_vSetBcamField(SMacEntry* pSEntry, PUINT8 abyEntryBuf)
{
    BOOL    bValid = TRUE;
    

    // Set Valid field
    SWSRAM_vModifyBitsByBool(abyEntryBuf, BCAM_BIT_VALID_S, BCAM_BIT_VALID_E, &bValid);
    // Set MAC address
    STR_pvMemcpy(&abyEntryBuf[2], pSEntry->abyMacAddr, MAC_ADDR_SIZE);
    // Set Address type field
    SWSRAM_vModifyBitsByBool(abyEntryBuf, BCAM_BIT_ADDR_TYPE_S, BCAM_BIT_ADDR_TYPE_E, &pSEntry->bIpMcst);
    // Set FID field
    SWSRAM_vModifyBits(abyEntryBuf, BCAM_BIT_FID_S, BCAM_BIT_FID_E, (PUINT8)&pSEntry->u16Fid);
}


static UINT32 s_u32GetBcamEmpty (void)
{
    UINT8   abyEntryBuf[SRAM_ENTRY_SIZE_16Byte];
    UINT8   byResvPg, uu;
    UINT32  u32BaseAddr;


#ifdef __TEST_SECMACINDEX
    byResvPg = 1;
#else
    // Number of reserved pages.
    SWREG_vReadU8(FWDCTL_SEC_MAC_OWNER_CMD, &byResvPg);
    if (byResvPg == 0)
        return UINT32_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)
            return u32BaseAddr + (uu * SRAM_ENTRY_SIZE_16Byte);
    }

    // Return no space
    return UINT32_MAX;
}


BOOL ANLZSMACTB_bDelEntryByAddr(UINT32 u32BcamAddr)
{
    UINT32  u32ActAddr, u32McstAddr = 0;
    UINT8   abyEntryBuf[SRAM_ENTRY_SIZE_8Byte], bySlotId;


    //Check entry is unicast or multicast
    u32ActAddr = s_u32BcamAddrToSmacAddr(u32BcamAddr);
    bySlotId = BCAM_TO_SMAC_SLOTID(u32BcamAddr);

    if (!SWSMACTB_bIsEntryUcst(u32ActAddr, bySlotId) )
    {
        //multicast, also clear multicast port mask entry
        SWSRAM_bReadEntry(u32ActAddr, abyEntryBuf);
        SWSRAM_vExtractBits(abyEntryBuf+(bySlotId*3), SMAC_BIT_MCST_ADDR_S, SMAC_BIT_MCST_ADDR_E, (PUINT8)&u32McstAddr);
        u32McstAddr = (u32McstAddr << 2) + SRAM_PTMSK_TBL_BASE_ADDR;
        SWSRAM_vSetMemEntryEmpty(u32McstAddr);
    }
    SWSMACTB_vDelEntryByIndx( ((u32BcamAddr-SRAM_SECOND_MAC_INDX_BASE_ADDR)>>SHIFT_NUM_SIZE_16Byte));
    
    return TRUE;
}


/*
 * Description : Determine Secondary MAC entry if unicast or multicast.
 * Input : u32SmacAddr: Sram address for Seconday MAC table.
 *         bySlotId:    Secondary MAC table one memory entry has two slot(0 or 1).
 */
BOOL SWSMACTB_bIsEntryUcst(UINT32 u32SmacAddr, UINT8 bySlotId)
{
    UINT8   abyEntryBuf[SRAM_ENTRY_SIZE_8Byte];
    BOOL    bCast;


    // read entry
    SWSRAM_bReadEntry(u32SmacAddr, abyEntryBuf);

    // Check if unicast entry
    SWSRAM_vExtractBitsByBool(abyEntryBuf + (bySlotId*3),
        SMAC_BIT_CAST_TYPE_S,
        SMAC_BIT_CAST_TYPE_E, &bCast);

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

}

⌨️ 快捷键说明

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