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

📄 pitrunk.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:    pitrunk.c
 *
 * Purpose: Trunk module UI callback functions
 *
 * Author:  Tevin Chen
 *
 * Date:    Nov 01, 2005
 *
 * Functions:
 *
 * Revision History:
 *
 */


#include "str.h"
#if !defined(__SWCFG_H__)
#include "swcfg.h"
#endif
#if !defined(__SWSRAM_H__)
#include "swsram.h"
#endif
#include "swsnf.h"
#include "swtrk.h"
#include "swvlantb.h"
#include "swmsg.h"
#include "pieeprom.h"
#include "piportmp.h"
#include "pitrunk.h"
#include "pivlan.h"
#include "pivlnmod.h"
#include "pigencfg.h"
#include "swrate.h"

#if !defined(__SWSECU_H__)
#include "swsecu.h"
#endif

#include "pimacfltmd.h"
/*---------------------  EEPROM Content Statement  ------------------*/
/*
 * NOTE: EEPROM content of all trunk APIs are of config mask format.
 * i.e. The format of UI config buffer. Thus initializing hardware config
 * from EEPROM needs to transfer from config mask into physcial port mask;
 * on the other hand, saving current config into EEPROM doesn't need any
 * format transferring.
 */

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

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

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

/*---------------------  Static Functions  --------------------------*/
static void s_vTransPortCfgToGrpCfg (STrkPageCfg *pSPageBuf, PUINT32 adwTrkGrpMbr);
static UINT8 s_byCheckIfCfgValid     (PUINT32 adwTrkGrpMbr, PUINT16 pwFailGrpId);

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

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

/*---------------------  Export Functions  --------------------------*/




// Get config from EEPROM and set into page buf
void PITRK_vInitPage (STrkPageCfg *pSPageBuf)
{
    // We use function here because using macro would cause several *.h files including each other
    PIEEP_vGetCfgFromEep( EEP_ADDR_TRUNK_CFG, EEP_SIZE_TRUNK_CFG, (PUINT8)pSPageBuf );
}


// Get config from EEPROM and set into hardware
void PITRK_vSetHwFromEep (STrkPageCfg *pSPageBuf)
{
    PUINT32 adwTrkGrpMbr = pSPageBuf->adwTrkGrpMbr;
    UINT8   si;


    // Get trunk port config
    PITRK_vInitPage(pSPageBuf);

    // Transfer port-oriented config to group-oriented and set into HW
    s_vTransPortCfgToGrpCfg(pSPageBuf, adwTrkGrpMbr);
    for (si = 0; si < SWITCH_TRUNK_GRP_NUM; si++) {
        if (adwTrkGrpMbr[si])
            SWTRK_byInsGrp((UINT8)(MIN_TRK_GRP_ID+si), adwTrkGrpMbr[si]);
    }

    // Update logical port id list
    PIPORTMP_vUpdateLogIdList();
}


// Set trunk block EEPROM into default value
void  PITRK_vSetEepDefault (STrkPageCfg *pSPageBuf, BOOL bWriteDefault)
{
    // Clear all group set in EEPROM
    STR_pvMemset(pSPageBuf, 0, EEP_SIZE_TRUNK_CFG);
    if (bWriteDefault) {
        // Set value to nvram software cache
        STR_pvMemcpy(g_pu8NVRSwCache + (EEP_ADDR_TRUNK_CFG - NVR_ADDR_DATA_AREA_START), (PUINT8)pSPageBuf, EEP_SIZE_TRUNK_CFG);    
    }
    else {
        PIEEP_vSetCfgIntoEep( (PUINT8)pSPageBuf, EEP_ADDR_TRUNK_CFG, EEP_SIZE_TRUNK_CFG );
        NVRAM_vUpdateChecksum(EEP_SIZE_DATA_AREA);
    }
    
    // Clear all group in register
    // NOTE this should put in "PITRK_vSetHwFromEep",
    // but that function may also be called by "PITRK_vFailOverForLnkChg".
    // To increase performance we put it here.
    SWTRK_vDelGrp(BIT_MASK_PORT_ALL);
}

// Save all trunk groups
UINT8 PITRK_bySavePage (STrkPageCfg *pSPageBuf, PUINT16 pwFailGrpId)
{
    PUINT32 adwTrkGrpMbr = pSPageBuf->adwTrkGrpMbr;
    UINT8   byRes, si;



    // Transfer port-oriented config to group-oriented
    s_vTransPortCfgToGrpCfg(pSPageBuf, adwTrkGrpMbr);

    // If trunk config invalid, return error code
    byRes = s_byCheckIfCfgValid(adwTrkGrpMbr, pwFailGrpId);
    if (byRes != OP_OK)
        return byRes;

    // Clear orginal trunk config of hardware
    SWTRK_vDelGrp(BIT_MASK_PORT_ALL);

    // Insert groups into hardware. If failed, recover to original and return
    for (si = 0; si < SWITCH_TRUNK_GRP_NUM; si++) {
        if (adwTrkGrpMbr[si] ) {
            byRes = SWTRK_byInsGrp( (UINT8)(MIN_TRK_GRP_ID+si), adwTrkGrpMbr[si] );
            if (byRes != OP_OK) {
                SWTRK_vDelGrp(BIT_MASK_PORT_ALL);

                // In order to keep original user config, PITRK_vSetHwFromEep needs a new
                // memory buffer. Unfortunately, the RAM is not enough. However, the union
                // of config buffer, g_UCfgBuf, is much larger than STrkPageCfg. Therefore,
                // the unused memory of g_UCfgBuf is passed to as a new config buffer.
                PITRK_vSetHwFromEep((STrkPageCfg*)(((PUINT8)pSPageBuf)+EEP_SIZE_TRUNK_CFG));

                (*pwFailGrpId) = PORTMAP_BASE_TRKGRP_LOG_ID + si;

                //return byRes;
                return TRK_OP_MBR_NUM_INVALID;
            }
        }
    }

    // Set trunk page config in EEPROM
    PIEEP_vSetCfgIntoEep( (PUINT8)pSPageBuf, EEP_ADDR_TRUNK_CFG, EEP_SIZE_TRUNK_CFG );
    NVRAM_vUpdateChecksum(EEP_SIZE_DATA_AREA);

    // Update logical port id list if config changed
    PIPORTMP_vUpdateLogIdList();

    // Clear MAC table to prevent table lookup problems and return
    //SWFWD_vClearMacTable(); //TOCHECK
    return OP_OK;
}


// Adjust admin criteria for link change fail over
void PITRK_vFailOverForLnkChg (void)
{
    // NOTE: Trunk config buffer here must be local buffer
    //       since this function may be executed anytime by
    //       software fail-over polling.
    union   // For reducing stack usage
    {
        SRatePageCfg    SRate;
        STrkPageCfg     STrk;
    } SPageBuf;
    UINT8 u8PhyPID;
    UINT32 dwLnkChgMsk = 0, dwPhyPortMask = 0x01;


    // Polling for link change => if so, execute trunk failover function
    SWREG_vReadU32(PHYCTL_LINK_STATUS_CHANGE, &dwLnkChgMsk);
    if (dwLnkChgMsk){
        PITRK_vSetHwFromEep(&(SPageBuf.STrk));

        //Egress rate setting depend on link speed
        PIRATE_byOp(&SPageBuf.SRate, RATE_OP_EEP_TO_BUF);
        for (u8PhyPID = 0; u8PhyPID < SWITCH_PORT_NUM; u8PhyPID++)
        {
            if ((dwPhyPortMask & dwLnkChgMsk) )
                SWRATE_vSetRateCtrlExt(u8PhyPID, *( (PUINT16)((PUINT8)SPageBuf.SRate.au16Rate + (u8PhyPID * EEP_SIZE_RATE_PORT_BYTE_OFFSET)) ), 
                    (*( (PUINT16)((PUINT8)SPageBuf.SRate.au16Rate + (u8PhyPID * EEP_SIZE_RATE_PORT_BYTE_OFFSET) + DATA_SIZE_IN_RATE)))*1000 );
            dwPhyPortMask <<= 1;
        }
    }
}

⌨️ 快捷键说明

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