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

📄 swqos.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:    swqos.c
 *
 * Purpose: QoS hardware accessing functions
 *
 * Author:  Henry Lin
 *
 * Date:    Apr 07, 2005
 *
 * Functions:
 *
 * Revision History:
 *
 */


#if !defined(__SWITCH_H__)
#include "switch.h"
#endif
#if !defined(__SWREG_H__)
#include "swreg.h"
#endif
#if !defined(__SWQOS_H__)
#include "swqos.h"
#endif
#if !defined(__SWPRIMTB_H__)
#include "swprimtb.h"
#endif




/*---------------------  Static Definitions  ------------------------*/
// lookup table for g_aszQosMode
static UINT8 s_abyQosModePtn[] = {
    SCHE_SEL_FCFS,
    SCHE_SEL_SP,
    SCHE_SEL_WRR
};

static UINT16 s_abyQosWghtPtn[] = {
    OUT_WEIGHT_8_4_2_1,
    OUT_WEIGHT_15_7_3_1,
    OUT_WEIGHT_15_10_5_1
};

// lookup table for g_aszStaticPortPriorCfg
static UINT8 sg_abyStaticPortPriorPtn[] = {
    PRIO_PORT_DIS,
    PRIO_PORT_LOW,
    PRIO_PORT_HIGH
};


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

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

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

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

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

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

void SWQOS_vSetQosCfg(UINT8 byOpt)
{
    SWREG_vWriteU8(QUECTL_OUT_SCHE_MODE, s_abyQosModePtn[byOpt]);
}


void SWQOS_vSetOutQueWght (UINT8 byOpt)
{
    SWREG_vWriteU16(QUECTL_OUT_WEIGHT, s_abyQosWghtPtn[byOpt]);
}


void SWQOS_vSetOutQueWghtTkn (UINT8 byQue3, UINT8 byQue2, UINT8 byQue1, UINT8 byQue0)
{
    UINT16  u16Wght;

    
    u16Wght = byQue0 | (byQue1 << 4) | (byQue2 << 8) | (byQue3 << 12);
    SWREG_vWriteU16(QUECTL_OUT_WEIGHT, u16Wght);
}


void SWQOS_vSetPortPrior (UINT8 byPortId, BOOL bSelected, UINT8 byPri)
{
    UINT8 u8Data;


    SWREG_vReadU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, &u8Data);
    u8Data &= ~PRIO_PORT_MSK;
    if (bSelected)
        u8Data |= (byPri | PRIO_PORT_SEL);
    else
        u8Data |= byPri;
    SWREG_vWriteU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, u8Data);
}


void SWQOS_vSetVlanTag (UINT8 byPortId, BOOL bSelected)
{

    if (bSelected)
        SWREG_vBitsOnU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, PRIO_VLAN_TAG_SEL);
    else
        SWREG_vBitsOffU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, PRIO_VLAN_TAG_SEL);
}


void SWQOS_vSetVlan (UINT8 byPortId, BOOL bSelected)
{

    if (bSelected)
        SWREG_vBitsOnU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, PRIO_VLAN_SEL);
    else
        SWREG_vBitsOffU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, PRIO_VLAN_SEL);
}


void SWQOS_vSetTos (UINT8 byPortId, BOOL bSelected)
{

    if (bSelected)
        SWREG_vBitsOnU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, PRIO_TOS_DSCP_SEL);
    else
        SWREG_vBitsOffU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, PRIO_TOS_DSCP_SEL);
}


void SWQOS_vSetL2p (UINT8 byPortId, BOOL bSelected)
{

    if (bSelected)
        SWREG_vBitsOnU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, PRIO_L2P_ACT_SEL);
    else
        SWREG_vBitsOffU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, PRIO_L2P_ACT_SEL);
}


void SWQOS_vSetPriorAdj (UINT8 byPortId, BOOL bEnable, UINT8 byProfileId)
{

    if (bEnable)
        SWREG_vBitsOnU8(PORTCFG_PRIO_ADJ_BASE + byPortId * PORTCFG_PORT_OFFSET, (PRIO_ADJ_EN | (byProfileId << 2)));
    else
        SWREG_vBitsOffU8(PORTCFG_PRIO_ADJ_BASE + byPortId * PORTCFG_PORT_OFFSET, PRIO_ADJ_EN);
}


void SWQOS_vSetPriorPropagate (UINT8 byPortId, BOOL bEnable)
{

    if (bEnable)
        SWREG_vBitsOnU8(PORTCFG_PRIO_ADJ_BASE + byPortId * PORTCFG_PORT_OFFSET, PRIO_PROPAGATE_EN);
    else
        SWREG_vBitsOffU8(PORTCFG_PRIO_ADJ_BASE + byPortId * PORTCFG_PORT_OFFSET, PRIO_PROPAGATE_EN);
}


/*
 * Output : FALSE: precedence has duplication or value not between 0 and 4
 *          TRUE:  precedence no duplication and value between 0 and 4
 */
BOOL SWQOS_bSetPrecedence (SPriorPrec *psPrec)
{
    UINT16 u16Data = 0;
    UINT8  u8Chk = 0x01;

    
    // precedence must be between 0 and 4.
    if ((psPrec->byPort > PREC_HIGHEST) || (psPrec->byVlanTag > PREC_HIGHEST) ||
        (psPrec->byVlan > PREC_HIGHEST) || (psPrec->byTos > PREC_HIGHEST) ||
        (psPrec->byL2p > PREC_HIGHEST) )
        return FALSE;
    
    // precedence doesn't duplicate.
    if (((u8Chk << psPrec->byPort) | (u8Chk << psPrec->byVlanTag) | (u8Chk << psPrec->byVlan) |
         (u8Chk << psPrec->byTos)  | (u8Chk << psPrec->byL2p)) != 0x1F)
        return FALSE;
        
    u16Data = psPrec->byPort | (psPrec->byVlanTag << 3) | (psPrec->byVlan << 6) | 
              (psPrec->byTos << 9) | (psPrec->byL2p << 12);
    SWREG_vWriteU16(FWDCTL_PRIORITY_CFG, u16Data);
    return TRUE;
}


void SWQOS_vSetRaisedPrior (UINT8 byPri)
{
    UINT8 u8Data;


    SWREG_vReadU8(FWDCTL_PRIORITY_RAISED, &u8Data);
    u8Data &= 0x08;
    u8Data |= byPri;
    SWREG_vWriteU8(FWDCTL_PRIORITY_RAISED, u8Data);
}


void SWQOS_vSetBPDUPrior (BOOL bPri7)
{

    if (bPri7)
        SWREG_vBitsOnU8(FWDCTL_PRIORITY_RAISED, PRIORITY_BPDU);
    else
        SWREG_vBitsOffU8(FWDCTL_PRIORITY_RAISED, PRIORITY_BPDU);
}


void SWQOS_vSetAdjProfile (UINT8 byProfId, SAdjPrior *psAdjPri)
{
    UINT32 u32Data = 0;
    UINT8  byi;


    for (byi = 0; byi < PRIOR_NUM ; byi++)
        u32Data = u32Data | (psAdjPri->byPri[byi] << (byi*3));
    SWREG_vWriteU32(ADVFWD_PRIO_ADJ_PROF0 + (byProfId*PRIO_ADJ_PROF_OFFSET), u32Data);
}


BOOL SWQOS_bGetDSCPPrior (UINT8 byDSCP, PUINT8 pbyPri)
{
    
    return SWPRIM_bReadEntry(byDSCP, pbyPri);
}


BOOL SWQOS_bSetDSCPPrior (UINT8 byDSCP, UINT8 byPri)
{
    
    return SWPRIM_bWriteEntry(byDSCP, byPri);
}

void SWQOS_vSetStaticPrior (UINT8 byPortId, UINT8 byCfg)
{
    UINT8 u8Data;


    // if set low/high, then disable all priority select except port priority select
    if (sg_abyStaticPortPriorPtn[byCfg] == PRIO_PORT_DIS){
        SWREG_vReadU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, &u8Data);
        u8Data &= ~PRIO_PORT_MSK;
        SWREG_vWriteU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, u8Data);
    }
    else
        SWREG_vWriteU8(PORTCFG_PRIO_CFG_BASE + byPortId * PORTCFG_PORT_OFFSET, sg_abyStaticPortPriorPtn[byCfg]);
}

⌨️ 快捷键说明

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