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

📄 swvlantb.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:    swvlantb.c
 *
 * Purpose: VLAN hardware accessing functions
 *
 * Author:  Tevin Chen
 *          Henry Lin
 *
 * Date:    Jan 08, 2002
 *          May 16, 2005
 *
 * Functions:
 *
 * Revision History:
 *
 */


#if !defined(__STR_H__)
#include "str.h"
#endif
#if !defined(__SWCFG_H__)
#include "swcfg.h"
#endif
#if !defined(__SWITCH_H__)
#include "switch.h"
#endif
#if !defined(__SWREG_H__)
#include "swreg.h"
#endif
#if !defined(__SWVLANTB_H__)
#include "swvlantb.h"
#endif




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

// lookup table for g_aszIngrsFiltCfg
static UINT8 sg_au8IngrsFilterPtn[] = {
    INGRS_FLTR_DISABLE,
    INGRS_FLTR_NOTMBR,
    INGRS_FLTR_UNTAG,
    INGRS_FLTR_NOTMBR_UNTAG
};

// VLAN Classification Configuration
static UINT16 sg_au16ClassCfgPtn[] = {
    VLAN_CFG_CLASS_METHOD0,
    VLAN_CFG_CLASS_METHOD1,
    VLAN_CFG_CLASS_METHOD2,
    VLAN_CFG_CLASS_METHOD3,
    VLAN_CFG_CLASS_METHOD4
};


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

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

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

/*---------------------  Static Variables  --------------------------*/
static UINT8    sg_u8VlanMode = VLAN_MODE_DISABLE;

/*---------------------  Static Functions  --------------------------*/

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




UINT8 SWVLANTB_u8GetVlanMode (void)
{
    return sg_u8VlanMode;
}


void SWVLANTB_vSetVlanMode (UINT8 u8VlanMode)
{
    UINT8   uu;

    sg_u8VlanMode = u8VlanMode;
    switch (u8VlanMode) {

    case VLAN_MODE_PORTBASE:
        SWREG_vBitsOnU8(FWDCTL_VLAN_CFG, VLAN_CFG_VLAN_EN);
        
        // VLAN classification method4 (Defalut VLAN), used PVID.
        SWVLANTB_vSetClassMethod(sg_au16ClassCfgPtn[4]);
        for (uu = 0; uu < SWITCH_PORT_NUM; uu++)
            SWVLANTB_vSetVerbatimMode(uu, TRUE);

        return;

    case VLAN_MODE_8021Q:
        SWREG_vBitsOnU8(FWDCTL_VLAN_CFG, VLAN_CFG_VLAN_EN);

        // VLAN classification method0 (VLAN-tag VLAN > L2+ VLAN > Default VLAN).
        SWVLANTB_vSetClassMethod(sg_au16ClassCfgPtn[0]);
        for (uu = 0; uu < SWITCH_PORT_NUM; uu++)
            SWVLANTB_vSetVerbatimMode(uu, FALSE);
        return;

    case VLAN_MODE_PROTOBASE:
        SWREG_vBitsOnU8(FWDCTL_VLAN_CFG, VLAN_CFG_VLAN_EN);
        
        // VLAN classification method2 (L2+ VLAN > VLAN-tag VLAN > Default VLAN).
        SWVLANTB_vSetClassMethod(sg_au16ClassCfgPtn[2]);
        for (uu = 0; uu < SWITCH_PORT_NUM; uu++)
            SWVLANTB_vSetVerbatimMode(uu, TRUE);
        return;

    case VLAN_MODE_DISABLE:
    default:
        SWREG_vBitsOffU8(FWDCTL_VLAN_CFG, VLAN_CFG_VLAN_EN);
        return;
    }
}


BOOL SWVLANTB_bGetEntry(UINT16 u16Indx, SVlanEntry* pSEntry)
{
    UINT8   au8EntryBuf[VLAN_ENTRY_SIZE];
    UINT32  u32Addr;


    // Convert index to SRAM acture address
    u32Addr = SWVLANTB_dwVidToSramAddr(u16Indx);
    
    SWSRAM_bReadEntry(u32Addr, au8EntryBuf);

    // Check if the entry valid == [127] is 1
    if (!((au8EntryBuf[15] & VLAN_BPTN_VALID_VLAN) != 0))
        return FALSE;

    // Get vid value
    pSEntry->u16Vid = SWVLANTB_wSramAddrToVid(u32Addr);
    // Get fid field
    SWSRAM_vExtractBits(au8EntryBuf, VLAN_BIT_FID_S, VLAN_BIT_FID_E, (PUINT8)&pSEntry->u16Fid);
    // Get egress member field
    SWSRAM_vExtractBits(au8EntryBuf, VLAN_BIT_EGRS_MEMBER_S, VLAN_BIT_EGRS_MEMBER_E, (PUINT8)&pSEntry->u32EgrsMbrPortMsk);
    // Get ingress member field
    SWSRAM_vExtractBits(au8EntryBuf, VLAN_BIT_INGRS_MEMBER_S, VLAN_BIT_INGRS_MEMBER_E, (PUINT8)&pSEntry->u32IngrsMbrPortMsk);
    // Get tag-rule field
    SWSRAM_vExtractBits(au8EntryBuf, VLAN_BIT_TAG_S, VLAN_BIT_TAG_E, (PUINT8)&pSEntry->u32TagPortMsk);

    // Get jumbo field
    SWSRAM_vExtractBitsByBool(au8EntryBuf, VLAN_BIT_JUMBO_PASS_S, VLAN_BIT_JUMBO_PASS_E, &pSEntry->bJumboPass);
    // Get priority adjustment field
    SWSRAM_vExtractBitsByBool(au8EntryBuf, VLAN_BIT_PRI_ADJ_S, VLAN_BIT_PRI_ADJ_E, &pSEntry->bPriAdj);
    // Get ToS/DSCP-to-802.1p field
    SWSRAM_vExtractBitsByBool(au8EntryBuf, VLAN_BIT_TOS_MAP_1P_S, VLAN_BIT_TOS_MAP_1P_E, &pSEntry->bTosTo8021p);
    // Get cpu forward cfg field
    SWSRAM_vExtractBitsByByte(au8EntryBuf, VLAN_BIT_CPU_FWD_S, VLAN_BIT_CPU_FWD_E,  &pSEntry->u8CpuFwd);
    // Get per-VLAN priority field
    SWSRAM_vExtractBitsByByte(au8EntryBuf, VLAN_BIT_PER_VLAN_PRI_S, VLAN_BIT_PER_VLAN_PRI_E,  &pSEntry->u8PerVlanPri);
    // Get per-VLAN priority valid field
    SWSRAM_vExtractBitsByBool(au8EntryBuf, VLAN_BIT_PER_VLAN_VALID_S, VLAN_BIT_PER_VLAN_VALID_E, &pSEntry->bPerVlanPriVld);

    // Get verbatim mode field
    SWSRAM_vExtractBitsByBool(au8EntryBuf, VLAN_BIT_VERBATIM_MODE_S, VLAN_BIT_VERBATIM_MODE_E, &pSEntry->bVerbMode);
    // Get local tag rule field
    SWSRAM_vExtractBitsByBool(au8EntryBuf, VLAN_BIT_LOCAL_TAG_S, VLAN_BIT_LOCAL_TAG_E, &pSEntry->bLocTagRule);
    // Get MSTID field
    SWSRAM_vExtractBitsByByte(au8EntryBuf, VLAN_BIT_MSTID_S, VLAN_BIT_MSTID_E,  &pSEntry->u8MstId);
    // Get MSTID valid field
    SWSRAM_vExtractBitsByBool(au8EntryBuf, VLAN_BIT_MSTID_VALID_S, VLAN_BIT_MSTID_VALID_E, &pSEntry->bMstIdVld);

    return TRUE;
}


BOOL SWVLANTB_bSetEntry (SVlanEntry* pSEntry)
{
    UINT8   au8EntryBuf[VLAN_ENTRY_SIZE];
    UINT32  dwAddr;


    //Internal VLAN Enable?
    if (pSEntry->u16Vid >= VID_NUM_8021Q){
        if (!SWVLANTB_bIsIntEntryValid(pSEntry->u16Vid))
            return FALSE;
    }
    
    //insert entry to VLAN or PMAC table
    dwAddr = SWVLANTB_dwVidToSramAddr(pSEntry->u16Vid);
    if (dwAddr == UINT32_MAX)
        return FALSE;   //vid out of range

    // Set entry content and write into sram
    STR_pvMemset(au8EntryBuf, 0, VLAN_ENTRY_SIZE);
    // Set fid field
    SWSRAM_vModifyBits(au8EntryBuf, VLAN_BIT_FID_S, VLAN_BIT_FID_E, (PUINT8)&pSEntry->u16Fid);
    // Set egress membership field, CPU port MUST be all of the vlan member
    pSEntry->u32EgrsMbrPortMsk |= BIT_MASK_PORT_CPU;
    SWSRAM_vModifyBits(au8EntryBuf, VLAN_BIT_EGRS_MEMBER_S, VLAN_BIT_EGRS_MEMBER_E, (PUINT8)&pSEntry->u32EgrsMbrPortMsk);
    // Set ingress membership field
    SWSRAM_vModifyBits(au8EntryBuf, VLAN_BIT_INGRS_MEMBER_S, VLAN_BIT_INGRS_MEMBER_E, (PUINT8)&pSEntry->u32IngrsMbrPortMsk);
    // Set tag-rule field
    SWSRAM_vModifyBits(au8EntryBuf, VLAN_BIT_TAG_S, VLAN_BIT_TAG_E, (PUINT8)&pSEntry->u32TagPortMsk);

    // Set VLAN valid field
    au8EntryBuf[15] |= VLAN_BPTN_VALID_VLAN;

    // Set jumbo field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_JUMBO_PASS_S, VLAN_BIT_JUMBO_PASS_E, &pSEntry->bJumboPass);
    // Set priority adjustment field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_PRI_ADJ_S, VLAN_BIT_PRI_ADJ_E, &pSEntry->bPriAdj);
    // Set ToS/DSCP-to-802.1p field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_TOS_MAP_1P_S, VLAN_BIT_TOS_MAP_1P_E, &pSEntry->bTosTo8021p);
    // Set cpu forward cfg field
    SWSRAM_vModifyBitsByByte(au8EntryBuf, VLAN_BIT_CPU_FWD_S, VLAN_BIT_CPU_FWD_E,  &pSEntry->u8CpuFwd);
    // Set per-VLAN priority field
    SWSRAM_vModifyBitsByByte(au8EntryBuf, VLAN_BIT_PER_VLAN_PRI_S, VLAN_BIT_PER_VLAN_PRI_E,  &pSEntry->u8PerVlanPri);
    // Set per-VLAN priority valid field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_PER_VLAN_VALID_S, VLAN_BIT_PER_VLAN_VALID_E, &pSEntry->bPerVlanPriVld);

    // Set verbatim mode field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_VERBATIM_MODE_S, VLAN_BIT_VERBATIM_MODE_E, &pSEntry->bVerbMode);
    // Set local tag rule field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_LOCAL_TAG_S, VLAN_BIT_LOCAL_TAG_E, &pSEntry->bLocTagRule);
    // Set MSTID field
    SWSRAM_vModifyBitsByByte(au8EntryBuf, VLAN_BIT_MSTID_S, VLAN_BIT_MSTID_E,  &pSEntry->u8MstId);
    // Set MSTID valid field
    SWSRAM_vModifyBitsByBool(au8EntryBuf, VLAN_BIT_MSTID_VALID_S, VLAN_BIT_MSTID_VALID_E, &pSEntry->bMstIdVld);

    SWSRAM_bWriteEntry(dwAddr, au8EntryBuf);

    return TRUE;
}


BOOL SWVLANTB_bDelEntry(UINT16 u16Indx)
{
    UINT8   au8EntryBuf[VLAN_ENTRY_SIZE];

⌨️ 快捷键说明

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