📄 swstp.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: swstp.c
*
* Purpose: STP functions
*
* Author: Tevin Chen
* Henry Lin
*
* Date: Jan 08, 2002
* Apr 29, 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(__SWSRAM_H__)
#include "swsram.h"
#endif
#if !defined(__SWSTP_H__)
#include "swstp.h"
#endif
#if !defined(__SWMSTTB_H__)
#include "swmsttb.h"
#endif
/*--------------------- Static Definitions ------------------------*/
#define STP_STATE_MSK_PER_PORT 0x03
#define STP_STATE_BIT_NUM_PER_PORT 2
#define BPDU_FWD_MSK 0x03
#define PORT_NUM_ONE_OFFSET 4
/*--------------------- Static Types ------------------------------*/
/*--------------------- Static Macros -----------------------------*/
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Variables --------------------------*/
UINT8 au8PortState[SWITCH_PORT_NUM] = {
STP_STATE_FORWARDING, STP_STATE_FORWARDING, STP_STATE_FORWARDING, STP_STATE_FORWARDING,
STP_STATE_FORWARDING, STP_STATE_FORWARDING, STP_STATE_FORWARDING, STP_STATE_FORWARDING,
STP_STATE_FORWARDING, STP_STATE_FORWARDING, STP_STATE_FORWARDING, STP_STATE_FORWARDING,
STP_STATE_FORWARDING, STP_STATE_FORWARDING, STP_STATE_FORWARDING, STP_STATE_FORWARDING,
STP_STATE_FORWARDING, STP_STATE_FORWARDING, STP_STATE_FORWARDING, STP_STATE_FORWARDING,
STP_STATE_FORWARDING, STP_STATE_FORWARDING, STP_STATE_FORWARDING, STP_STATE_FORWARDING,
STP_STATE_FORWARDING, STP_STATE_FORWARDING
};
UINT32 u32PortStateMsk = BIT_MASK_PORT_ALL;
/*--------------------- Static Functions --------------------------*/
static void s_vSetBPDUOnlytoCpuEn(BOOL bEnable);
static BOOL s_bSetStpState(UINT8 byPortId, UINT8 byStpState);
static void s_vMstpSetStpState(UINT8 byPortId, UINT8 byStpState, UINT8 *abySramEntryBuf);
/*--------------------- Export Variables --------------------------*/
BOOL SWPROTO_vSetStpMode(UINT8 u8StpMode)
{
if (u8StpMode != STP_MODE_DISABLE)
{
//STP or MSTP
//if VLAN disable, MSTP can't use.
if (u8StpMode == STP_MODE_MSTP && !SWPROTO_bIsMstpModeValid())
return FALSE;
s_vSetBPDUOnlytoCpuEn(TRUE);
}
else
//Disable
s_vSetBPDUOnlytoCpuEn(FALSE);
return TRUE;
}
static void s_vSetBPDUOnlytoCpuEn(BOOL bEnable)
{
UINT8 u8Temp;
UINT8 u8Msk = BPDU_FWD_MSK;
SWREG_vReadU8(FWDCTL_CTRL_PKT_FWD_CFG, &u8Temp);
u8Temp &= ~u8Msk;
if (bEnable)
u8Temp |= FWD_CFG_BPDU_TO_ONLY_CPU ;
else
u8Temp |= FWD_CFG_BPDU_TO_ALL_NOT_CPU ;
SWREG_vWriteU8(FWDCTL_CTRL_PKT_FWD_CFG, u8Temp);
}
static BOOL s_bSetStpState(UINT8 byPortId, UINT8 byStpState)
{
UINT8 u8Temp;
UINT8 u8Msk = STP_STATE_MSK_PER_PORT;
SWREG_vReadU8(FWDCTL_STP_STATE_PORT0_15 + (byPortId/PORT_NUM_ONE_OFFSET), &u8Temp);
//reset the port STP state
u8Temp &= ~(u8Msk << ((byPortId%PORT_NUM_ONE_OFFSET)*STP_STATE_BIT_NUM_PER_PORT));
//set the port STP state
if (byStpState == STP_STATE_LISTENING)
u8Temp |= (STP_STATE_BLOCKING << ((byPortId%PORT_NUM_ONE_OFFSET)*STP_STATE_BIT_NUM_PER_PORT) );
else
u8Temp |= (byStpState << ((byPortId%PORT_NUM_ONE_OFFSET)*STP_STATE_BIT_NUM_PER_PORT) );
SWREG_vWriteU8(FWDCTL_STP_STATE_PORT0_15 + (byPortId/PORT_NUM_ONE_OFFSET), u8Temp);
return TRUE;
}
void SWPROTO_vStpSetPortState(UINT8 u8Port, UINT8 u8State)
{
UINT32 u32Msk = 0x00000001;
au8PortState[u8Port] = u8State;
switch (u8State) {
case STP_STATE_DISABLED:
s_bSetStpState(u8Port, u8State);
u32PortStateMsk &= ~(u32Msk<<u8Port) ;
break;
case STP_STATE_BLOCKING:
s_bSetStpState(u8Port, u8State);
u32PortStateMsk &= ~(u32Msk<<u8Port) ;
break;
case STP_STATE_LISTENING:
s_bSetStpState(u8Port, u8State);
u32PortStateMsk &= ~(u32Msk<<u8Port) ;
break;
case STP_STATE_LEARNING:
s_bSetStpState(u8Port, u8State);
u32PortStateMsk &= ~(u32Msk<<u8Port) ;
break;
case STP_STATE_FORWARDING:
s_bSetStpState(u8Port, u8State);
u32PortStateMsk |= (u32Msk<<u8Port) ;
break;
default:
break;
}
}
/*
* In/Out : abySramEntryBuf : is 8 bytes Multiple Spanning Tree entry.
* port0-12 store in abySramEntryBuf[0-3]
* port13-25 store in abySramEntryBuf[4-7]
*/
static void s_vMstpSetStpState(UINT8 byPortId, UINT8 byStpState, UINT8 *abySramEntryBuf)
{
UINT8 byStpStateTmp;
if (byStpState == STP_STATE_LISTENING)
byStpStateTmp = STP_STATE_BLOCKING;
else
byStpStateTmp = byStpState;
if (byPortId >= 13)
SWSRAM_vModifyBitsByByte(&abySramEntryBuf[4],
HWPerPortStpStateVlanBitS( (byPortId-13) ),
HWPerPortStpStateVlanBitE( (byPortId-13) ),
(PUINT8)&byStpStateTmp);
else
SWSRAM_vModifyBitsByByte(abySramEntryBuf,
HWPerPortStpStateVlanBitS(byPortId),
HWPerPortStpStateVlanBitE(byPortId),
(PUINT8)&byStpStateTmp);
}
/*
* Description : The function use to read STP state that store in Flash
* Input : u8MstId : vaule between 0 and 63
* abyMSTPState[] : per port new stp state : P0P0P0, P1P1P1...
*/
void SWPROTO_vMstpSetStpState(UINT8 u8MstId, UINT8 *abyMSTPState)
{
UINT8 byPortId, byStpState = 0;
UINT8 au8EntryBuf[SRAM_ENTRY_SIZE_8Byte];
UINT32 u32MskHigh, u32MskLow;
STR_pvMemset(au8EntryBuf, 0, SRAM_ENTRY_SIZE_8Byte);
for (byPortId = 0; byPortId < SWITCH_PORT_NUM; byPortId++) {
byStpState = 0;
SWSRAM_vExtractBitsByByte(abyMSTPState, EepPerPortStpStateVlanBitS(byPortId), EepPerPortStpStateVlanBitE(byPortId), &byStpState);
s_vMstpSetStpState(byPortId, byStpState, au8EntryBuf);
}
u32MskLow = *((UINT32 *)au8EntryBuf);
u32MskHigh = *((UINT32 *)&au8EntryBuf[4]);
//set into HW
SWMSTTB_bInsEntry(u8MstId, u32MskHigh, u32MskLow);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -