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

📄 swgmrptb.c

📁 vt6528芯片交换机API函数和文档运行程序
💻 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:    swgmrptb.c
 *
 * Purpose: Multicast entry in PMAC/SMAC Table & Multicast port mask Table functions
 *
 * Author:  Henry Lin
 *
 * Date:    May 3, 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(__SWGMRPTB_H__)
#include "swgmrptb.h"
#endif


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

#define MCST_HASH_BLOCK_ENTRY_NUM   512     //In hash block has 512 entry number.
#define MCST_HASH_BLOCK_SIZE        (MCST_HASH_BLOCK_ENTRY_NUM << 2)

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

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

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

/*---------------------  Static Functions  --------------------------*/
static void s_vSrchEmptyMcstEntry(PUINT8 abyMacAddr, PUINT32 pdwAddr);

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




BOOL SWGMRPTB_bGmrpSetEn(BOOL bEnable)
{

    if (bEnable)
        SWREG_vBitsOnU8(FWDCTL_CTRL_PKT_FWD_CFG + 1, (FWD_CFG_GMRP_TO_ONLY_CPU >> 8));
    else
        SWREG_vBitsOffU8(FWDCTL_CTRL_PKT_FWD_CFG + 1, (FWD_CFG_GMRP_TO_ONLY_CPU >> 8));

    return TRUE;
}


/*
 * Description : Search multicast mac and fid in PMAC/SMAC.
 * Output : UINT16_MAX: The entry not exist in PMAC and SMAC.
 *          u16Indx:    Entry index.
 */
UINT16 SWGMRPTB_wSearchEntry(PUINT8 abyMacAddr, UINT16 u16Fid)
{
    UINT16  u16Indx;


    // search primary mac table
    u16Indx = SWMACTB_wSearchEntry(abyMacAddr, u16Fid);
    if (UINT16_MAX == u16Indx) {
        // search secondary mac bcam index table
        u16Indx = SWSMACBCAM_wSearchEntry(abyMacAddr, u16Fid);
        if (UINT16_MAX == u16Indx)
            return UINT16_MAX;
        u16Indx += PMAC_SLOT_NUM;   //if in BCAM, index value between 8192 and 8447
    }
    
    return u16Indx;
}

/*
 * Input : u16Indx: if PMAC entry, vaule between 0 and 8191.
 *                  if BCAM entry, vaule between 8192 and 8447.
 */
BOOL SWGMRPTB_bGetEntry(UINT16 u16Indx, SGMRPEntry* pSEntry)
{
    UINT32  u32McstAddr;
    
    
    if (IS_PMAC_ENTRY(u16Indx) ){
        // this is a pmac index
        if (FALSE == SWMACTB_bGetEntry(u16Indx, &(pSEntry->sMacEntry)))
            return FALSE;
    }
    else{
        // this is a bcam index
        u16Indx -= PMAC_SLOT_NUM;
        if (FALSE == SWSMACTB_bGetEntry(u16Indx, &(pSEntry->sMacEntry)) )
            return FALSE;
    }
    
    u32McstAddr = SRAM_PTMSK_TBL_BASE_ADDR + ((pSEntry->sMacEntry.u16McstIdx) << 2);
        
    {
        UINT8       abyBuf[4];       
        
        SWSRAM_bReadEntry(u32McstAddr, abyBuf);
        SWSRAM_vExtractBits(abyBuf, 0, 31, (UINT8 * )&(pSEntry->u32PortMask));
    }

    return TRUE;
}


BOOL SWGMRPTB_bInsEntry (SGMRPEntry* pSEntry, BOOL bIsOverWrite)
{
    UINT32  u32McstAddr;


    // Search an empty entry for portmask table
    s_vSrchEmptyMcstEntry(pSEntry->sMacEntry.abyMacAddr, &u32McstAddr);
    // If no empty entry, return insert fail msg
    if (u32McstAddr == UINT32_MAX)
        return FALSE;

    // Set multicast address in mac table
    pSEntry->sMacEntry.u16McstIdx = (u32McstAddr - SRAM_PTMSK_TBL_BASE_ADDR) >> 2;

    // write into primary mac table
    // GMRP/IPM entry always static, multicast port mask index in PMAC/SMAC
    pSEntry->sMacEntry.bStatic  = TRUE;
    pSEntry->sMacEntry.bTypeMcst= TRUE;
    if (FALSE == SWMACTB_bInsEntry(&(pSEntry->sMacEntry), bIsOverWrite)) {
        // if fail, write into secondary mac table
        if (FALSE == SWSMACTB_bInsEntry(&(pSEntry->sMacEntry), bIsOverWrite))
            return FALSE;
    }

    // Set content of portmask table entry
    {
        UINT8   abyBuf[4];
        SWSRAM_vModifyBits(abyBuf, 0, 31, (PUINT8)&(pSEntry->u32PortMask));
        SWSRAM_bWriteEntry(u32McstAddr, abyBuf);        
    }

    return TRUE;
}


BOOL SWGMRPTB_bDelEntry (PUINT8 abyMacAddr, UINT16 u16Fid)
{
    UINT32  u32McstAddr = 0;
    SGMRPEntry sEntry;
    UINT16 u16Indx;


    // Search entry
    u16Indx = SWGMRPTB_wSearchEntry(abyMacAddr, u16Fid);
    // If search failed, return FALSE
    if (u16Indx == UINT16_MAX)
        return FALSE;
    
    if (IS_PMAC_ENTRY(u16Indx) ){
        // this is a pmac index

        // delete mac entry
        SWMACTB_vDelEntryByIndx(u16Indx);
    }
    else{
        // this is a bcam index
        u16Indx -= PMAC_SLOT_NUM;

        // delete mac entry
        SWSMACTB_vDelEntryByIndx(u16Indx);
    }

    SWGMRPTB_bGetEntry(u16Indx, &sEntry);    
    u32McstAddr = sEntry.sMacEntry.u16McstIdx;
    
    u32McstAddr = (u32McstAddr << 2) + SRAM_PTMSK_TBL_BASE_ADDR;

    // delete port mask table entry           
    SWSRAM_vSetMemEntryEmpty(u32McstAddr);

    return TRUE;
}


/*
 * Description : Insert multicast entry in SMAC.
 */
BOOL SWGMRPTB_bInsEntryInSMT (SGMRPEntry* pSEntry, BOOL bIsOverWrite)
{
    UINT32  u32PMTblAddr;

    
    //
    // Search an empty entry for portmask
    //
    s_vSrchEmptyMcstEntry(pSEntry->sMacEntry.abyMacAddr, &u32PMTblAddr);
    // If no empty entry, return insert fail msg
    if (u32PMTblAddr == UINT32_MAX)
        return FALSE;

    pSEntry->sMacEntry.u16McstIdx = ((u32PMTblAddr - SRAM_PTMSK_TBL_BASE_ADDR) >> 2);
    
    // write bcam and smac table
    if (FALSE == SWSMACTB_bInsEntry(&(pSEntry->sMacEntry), bIsOverWrite))
        return FALSE;
    
    // Set content of portmask table entry
    {
        UINT8   abyBuf[4];
        SWSRAM_vModifyBits(abyBuf, 0, 31, (PUINT8)&(pSEntry->u32PortMask));
        SWSRAM_bWriteEntry(u32PMTblAddr, abyBuf);        
    }

    return TRUE;
}


/*
 * Description : Delete multicast entry in SMAC.
 */
BOOL SWGMRPTB_bDelEntryInSMT (PUINT8 abyMacAddr, UINT16 u16Fid)
{
    SMacEntry pSEntry;
    UINT32  u32PMTblAddr;
    UINT16  u16Indx;


    // search entry
    u16Indx = SWSMACBCAM_wSearchEntry(abyMacAddr, u16Fid);
    if (UINT16_MAX == u16Indx)
        return FALSE;
    
    SWSMACTB_bGetEntry(u16Indx, &pSEntry);
    if (TRUE == pSEntry.bTypeMcst) {
        // multicast
        u32PMTblAddr = (pSEntry.u16McstIdx << 2) + SRAM_PTMSK_TBL_BASE_ADDR;

        // clear multicasr port mask entry
        SWSRAM_vSetMemEntryEmpty(u32PMTblAddr);
    }

    // delete smac and bcam entry
    SWSMACTB_vDelEntryByIndx(u16Indx);
    
    return TRUE;
}


static void s_vSrchEmptyMcstEntry(PUINT8 abyMacAddr, PUINT32 pdwAddr)
{
    // Use leaset bit of MAC[1] and MAC[0] address to hash 
    *pdwAddr = ((((abyMacAddr[1] & 0x01) << 8) + abyMacAddr[0]) << 2) + SRAM_PTMSK_TBL_BASE_ADDR;
    
    // If memory entry empty, return
    if (SWSRAM_bIsMemEntryEmpty(*pdwAddr))
        return;

    // If hash conflict, find an empty entry sequentially in PortMask Table
    for (*pdwAddr = SRAM_PTMSK_TBL_BASE_ADDR + MCST_HASH_BLOCK_SIZE; 
          *pdwAddr <= SRAM_PTMSK_TBL_END_ADDR; (*pdwAddr) += SRAM_ENTRY_SIZE_4Byte ) 
    {
        if (SWSRAM_bIsMemEntryEmpty(*pdwAddr))
            return;
    }

    // If still no empty entry, return search failed    
    *pdwAddr = UINT32_MAX;

    return;
}

⌨️ 快捷键说明

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