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

📄 swfwd.c

📁 VIA VT6524 8口网管交换机源码
💻 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:    swfwd.c
 *
 * Purpose: Switch hardware accessing functions related to forwarding operation
 *
 * Author:  Tevin Chen
 *
 * Date:    Jan 08, 2002
 *
 * Functions:
 *
 * Revision History:
 *
 */


#if !defined(__SWITCH_H__)
#include "switch.h"
#endif
#if !defined(__PLATFORM_H__)
#include "platform.h"
#endif
#if !defined(__SWREG_H__)
#include "swreg.h"
#endif
#include "swfwd.h"




/*---------------------  Static Definitions  ------------------------*/
// for clear mac table
#define PTN_SPEEDUP_AGING               0x03
#define PTN_SPEEDUP_AGING_CYCLE         100
#define PTN_SPEEDUP_INTER_AGE_TIME      1
#define PTN_SPEEDUP_CLR_MACTBL_TIME     50      // msec

// auto ageing
#define PTN_AGE_OUT_BIT                 0x01

// s_abyAgeCycTimePtn is a lookup table for g_aszAutoAging, and beware array size
static DIRECT_MEMTYPE_CODE BYTE s_abyAgeCycTimePtn[] = {
    0,              // aging off
    50,             // 150 sec
    100,            // 300 sec
    200             // 600 sec
};


// Broadcast Storm Control Registers Setting
#define PTN_FUNC_CFG_BSF_EN             0x10

// Broadcast Storm Filter Percentage Setting
#ifdef __ASIC_VT6526
    #define SYS_FREE_MEM_CNT                3072
#else   // __ASIC_VT6524 or __ASIC_VT6526D
    #define SYS_FREE_MEM_CNT                1536
#endif

// lookup table for g_aszBSFMode
static DIRECT_MEMTYPE_CODE UINT16 s_awBsfXoffVal[] = {
    SYS_FREE_MEM_CNT,           // never used
    (SYS_FREE_MEM_CNT*0.05),
    (SYS_FREE_MEM_CNT*0.10),
    (SYS_FREE_MEM_CNT*0.20)
};

static DIRECT_MEMTYPE_CODE UINT16 s_awBsfXonVal[] = {
    SYS_FREE_MEM_CNT,           // never used
    (SYS_FREE_MEM_CNT*0.05/3),
    (SYS_FREE_MEM_CNT*0.10/3),
    (SYS_FREE_MEM_CNT*0.20/3)
};

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

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

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

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

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

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




void SWFWD_vClearMacTable (void) DIRECT_FUNTYPE_REENT
{
    BYTE    byOrgAgeCfg, byOrgAgeCycle, byOrgInterAgeTime;


    // Disable MAC learing
    SWREG_vWriteDW(FWD_SECURITY_CFG, PTN_BIT_MASK_ALL_PORT);

    // Log original config
    SWREG_vReadB(FWD_AUTO_AGE, &byOrgAgeCfg);
    SWREG_vReadB(FWD_AGE_CYC_TIME, &byOrgAgeCycle);
    SWREG_vReadB(FWD_INTER_AGE_TIME, &byOrgInterAgeTime);

    // Speed-up aging to clear mac table
    SWREG_vWriteB(FWD_AUTO_AGE, PTN_SPEEDUP_AGING);
    SWREG_vWriteB(FWD_AGE_CYC_TIME, PTN_SPEEDUP_AGING_CYCLE);
    SWREG_vWriteB(FWD_INTER_AGE_TIME, PTN_SPEEDUP_INTER_AGE_TIME);

    // Wait until table cleared
    PLATvDelay(PTN_SPEEDUP_CLR_MACTBL_TIME);

    // Restore original config
    SWREG_vWriteB(FWD_AUTO_AGE, byOrgAgeCfg);
    SWREG_vWriteB(FWD_AGE_CYC_TIME, byOrgAgeCycle);
    SWREG_vWriteB(FWD_INTER_AGE_TIME, byOrgInterAgeTime);

    // Enable MAC learing
    SWREG_vWriteDW(FWD_SECURITY_CFG, 0);
}


void SWFWD_vSetAutoAgingCfg(BYTE byOpt) DIRECT_FUNTYPE_REENT
{
    if (byOpt == AUTO_AGING_OFF) {
        SWREG_vBitsOff(FWD_AUTO_AGE, PTN_AGE_OUT_BIT);
    }
    else {
        SWREG_vBitsOn(FWD_AUTO_AGE, PTN_AGE_OUT_BIT);
        SWREG_vWriteB(FWD_AGE_CYC_TIME, s_abyAgeCycTimePtn[byOpt]);
    }
}


void SWFWD_vSetBsfCfg(UINT8 byBSFMode) DIRECT_FUNTYPE_REENT
{
    if (byBSFMode == BSF_MODE_OFF) {
        SWREG_vBitsOff(GLOBAL_FUNC_CFG, PTN_FUNC_CFG_BSF_EN);
    }
    else {
        SWREG_vBitsOn(GLOBAL_FUNC_CFG, PTN_FUNC_CFG_BSF_EN);
        SWREG_vWriteW(BSF_XOFF_THRED, s_awBsfXoffVal[byBSFMode]);
        SWREG_vWriteW(BSF_XON_THRED, s_awBsfXonVal[byBSFMode]);
    }
}

⌨️ 快捷键说明

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