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

📄 dot3ah_api.c

📁 在freescale 的ne64上开发的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "datatypes.h"
#include "System.h"
#include "debug.h"
#include "ethernet.h"
#include "dot3ah.h"
#include "timers.h"
#include "mBuf.h"
#include "ne64debug.h" 
#include "hw_api.h"

#define debugDOT3AH 0

extern UINT8 localDTEType;
extern UINT8 locAutoCfg[2];
extern UINT8 locDuplexCfg[2];
extern UINT16 locSpeedCfg[2];
extern UINT8 locLink[2];
extern UINT8 locDuplexStat[2];
extern UINT16 locSpeedStat[2];
extern UINT8 locPwrUpFlag;
extern UINT8 localOAMPort;
extern UINT8 hard_addr [6];

UINT8 rmtCfgFlag=0;
UINT8 rmtRateCfgFlag=0;

extern UINT8 get_port_info(UINT8 port,UINT8 *singleFx, UINT8 *fxMode, UINT8 *fxCnctr, UINT16 *fxDistance);
extern UINT8 get_wave_info(UINT8 port,UINT16 *txWaveLen, UINT16 *rxWaveLen);	

void spec_tlv_cfg_set_req(UINT8 *data_ptr)
{
	tSPEC_CFG_SET_REQ_TLV *tlv_ptr	= (tSPEC_CFG_SET_REQ_TLV *)data_ptr;
	UINT8 autoTmp=0, dplxTmp=0, temp;
	UINT16 spdTmp=0;
#if debugDOT3AH
	DOT3AH_API_DEBUGOUT("Dot3ahApi spec_tlv_cfg_set_req\n\r");
	DOT3AH_API_DEBUGOUT("%02x %02x %02x %02x ",*data_ptr,*(data_ptr+1),*(data_ptr+2),*(data_ptr+3));
	DOT3AH_API_DEBUGOUT("%02x %02x %02x %02x\n\r",*(data_ptr+4),*(data_ptr+5),*(data_ptr+6),*(data_ptr+7));
#endif
	if((tlv_ptr->rmtGlbCfg.rmtGlbCfgVal & 0xFF7F) != 0x0)
		rmtCfgFlag = 1;
	if(tlv_ptr->rmtTpCfg.rmtTpCfgVal!= 0x0)
		rmtCfgFlag = 1;
	if(tlv_ptr->rmtFxCfg.rmtFxCfgVal!= 0x0)
		rmtCfgFlag = 1;
							
	/*globle config*/
	if(tlv_ptr->rmtGlbCfg.Bits.rmtCloseEn)
	{
		if(localOAMPort==8)
			hwSetPortStat(1, 0);
		else
			hwSetPortStat(2, 0);
#if debugDOT3AH
		DOT3AH_API_DEBUGOUT("Dot3ahApi rmtCloseEn\n\r");
#endif
	}
	if(tlv_ptr->rmtGlbCfg.Bits.rmtCloseDis)
	{
		if(localOAMPort==8)
			hwSetPortStat(1, 1);
		else
			hwSetPortStat(2, 1);
#if debugDOT3AH
		DOT3AH_API_DEBUGOUT("Dot3ahApi rmtCloseDis\n\r");
#endif
	}
	if(tlv_ptr->rmtGlbCfg.Bits.rmtReset)
	{
		hwReboot();
#if debugDOT3AH
		DOT3AH_API_DEBUGOUT("Dot3ahApi rmtReset\n\r");
#endif
	}
	if(tlv_ptr->rmtGlbCfg.Bits.rmtCOSEn)
	{
		hwSetCos(1);
#if debugDOT3AH
		DOT3AH_API_DEBUGOUT("Dot3ahApi rmtCOSEn\n\r");
#endif
	}
	if(tlv_ptr->rmtGlbCfg.Bits.rmtCOSDis)
	{
		hwSetCos(0);
#if debugDOT3AH
		DOT3AH_API_DEBUGOUT("Dot3ahApi rmtCOSDis\n\r");
#endif
	}
	if(tlv_ptr->rmtGlbCfg.Bits.rmtLFPEn)
	{
		hwSetLfp(1);
#if debugDOT3AH
		DOT3AH_API_DEBUGOUT("Dot3ahApi rmtLFPEn\n\r");
#endif
	}
	if(tlv_ptr->rmtGlbCfg.Bits.rmtLFPDis)
	{
		hwSetLfp(0);
#if debugDOT3AH
		DOT3AH_API_DEBUGOUT("Dot3ahApi rmtLFPDis\n\r");
#endif
	}
	if(tlv_ptr->rmtGlbCfg.Bits.rmtPwrUpFlgRst)
	{
		locPwrUpFlag = 0;
#if debugDOT3AH
		DOT3AH_API_DEBUGOUT("Dot3ahApi rmtPwrUpFlgRst\n\r");
#endif
	}
	/*TP port config*/
	autoTmp = locAutoCfg[0];
	dplxTmp = locDuplexCfg[0];
	spdTmp = locSpeedCfg[0];
	temp = 0;
	if(tlv_ptr->rmtTpCfg.Bits.tpAutoEn==1)
	{
		autoTmp = 1;
		temp = 1;
#if debugDOT3AH
		DOT3AH_API_DEBUGOUT("Dot3ahApi tpAutoEn\n\r");
#endif
	}
	if(tlv_ptr->rmtTpCfg.Bits.tpAutoDis==1)
	{
		autoTmp = 0;
		temp = 1;
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi tpAutoDis\n\r");
#endif	
	}
	if(tlv_ptr->rmtTpCfg.Bits.tpFull==1)
	{
		dplxTmp = 1;
		temp = 1;
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi tpFull\n\r");
#endif		
	}
	if(tlv_ptr->rmtTpCfg.Bits.tpHalf==1)
	{
		dplxTmp = 0;
		temp = 1;
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi tpHalf\n\r");
#endif		
	}
	if(tlv_ptr->rmtTpCfg.Bits.tp10M)
	{
		spdTmp = 10;
		temp = 1;
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi tp10M\n\r");
#endif		
	}
	if(tlv_ptr->rmtTpCfg.Bits.tp100M)
	{
		spdTmp = 100;
		temp = 1;
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi tp100M\n\r");
#endif		
	}
	if(tlv_ptr->rmtTpCfg.Bits.tp1000M)
	{
		spdTmp = 1000;
		temp = 1;
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi tp1000M\n\r");
#endif		
	}
		
	if(temp == 1)
		hwSetPortCfg(1, autoTmp, dplxTmp, spdTmp);
		
	if(tlv_ptr->rmtTpCfg.Bits.tpFlowCtrlEn)
	{
		hwSetPortFlowCtrl(1, 1);
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi tpFlowCtrlEn\n\r");
#endif		
	}
	if(tlv_ptr->rmtTpCfg.Bits.tpFlowCtrlDis)
	{
		hwSetPortFlowCtrl(1, 0);
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi tpFlowCtrlDis\n\r");
#endif		
	}
#if 0
	if(tlv_ptr->rmtTpCfg.Bits.tpLoopChkEn)
	{
	}
	if(tlv_ptr->rmtTpCfg.Bits.tpLoopChkDis)
	{
	}
#endif
	/*FX port config*/
	if(tlv_ptr->rmtFxCfg.Bits.fxAutoEn)
	{
		hwSetPortCfg(2, 1, 1, 1000);
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi fxAutoEn\n\r");
#endif		
	}
	if(tlv_ptr->rmtFxCfg.Bits.fxAutoDis)
	{
		hwSetPortCfg(2, 0, 1, 1000);
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi fxAutoDis\n\r");
#endif		
	}
	if(tlv_ptr->rmtFxCfg.Bits.fxFEFEn)
	{
		hwSetFef(1);
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi fxFEFEn\n\r");
#endif		
	}
	if(tlv_ptr->rmtFxCfg.Bits.fxFEFDis)
	{
		hwSetFef(0);
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi fxFEFDis\n\r");
#endif		
	}
	if(tlv_ptr->rmtFxCfg.Bits.fxFlowCtrlEn)
	{
		hwSetPortFlowCtrl(2, 1);
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi fxFlowCtrlEn\n\r");
#endif		
	}
	if(tlv_ptr->rmtFxCfg.Bits.fxFlowCtrlDis)
	{
		hwSetPortFlowCtrl(2, 0);
#if debugDOT3AH		
		DOT3AH_API_DEBUGOUT("Dot3ahApi fxFlowCtrlDis\n\r");
#endif		
	}
#if 0
	if(tlv_ptr->rmtFxCfg.Bits.fxLoopChkEn)
	{
	}
	if(tlv_ptr->rmtFxCfg.Bits.fxLoopChkDis)
	{
	}
#endif
}				

void spec_tlv_stat_get_req(tSPEC_STAT_GET_RES_TLV *tlv_ptr)
{
	UINT8 u8Tmp;
	UINT16 u16Tmp;
#if debugDOT3AH
	DOT3AH_API_DEBUGOUT("Dot3ahApi spec_tlv_stat_get_req\n\r");
#endif		
	tlv_ptr->specTlvType = SPEC_TYPE_STAT_GET_RES;
	tlv_ptr->specTlvDataLen = SPEC_STAT_GET_RES_LEN;

	tlv_ptr->rmtGlbStat.rmtGlbStatVal = 0;
	tlv_ptr->rmtTpStat.rmtTpStatVal = 0;
	tlv_ptr->rmtFxStat.rmtFxStatVal = 0;

	if(localOAMPort==8)
		hwGetPortStat(1, &u8Tmp);
	else
		hwGetPortStat(2, &u8Tmp);
	if(u8Tmp)
		tlv_ptr->rmtGlbStat.Bits.rmtCfgClose = 0;
	else
		tlv_ptr->rmtGlbStat.Bits.rmtCfgClose = 1;
	hwGetCos(&u8Tmp);
	if(u8Tmp)
		tlv_ptr->rmtGlbStat.Bits.rmtCfgCOS = 1;
	else
		tlv_ptr->rmtGlbStat.Bits.rmtCfgCOS = 0;
	hwGetLfp(&u8Tmp);
	if(u8Tmp)
		tlv_ptr->rmtGlbStat.Bits.rmtCfgLFP = 1;
	else
		tlv_ptr->rmtGlbStat.Bits.rmtCfgLFP = 0;			

	tlv_ptr->rmtTpStat.Bits.tpCfgAuto = locAutoCfg[0];
	tlv_ptr->rmtTpStat.Bits.tpCfgDuplex = locDuplexCfg[0];
	if(locSpeedCfg[0] == 10)
		tlv_ptr->rmtTpStat.Bits.tpCfgSpeed = 0;
	else if(locSpeedCfg[0] == 100)
		tlv_ptr->rmtTpStat.Bits.tpCfgSpeed = 1;
	else
		tlv_ptr->rmtTpStat.Bits.tpCfgSpeed = 2;
	hwGetPortFlowCtrl(1, &u8Tmp);
	if(u8Tmp)
		tlv_ptr->rmtTpStat.Bits.tpCfgFlowCtrl = 1;
	else
		tlv_ptr->rmtTpStat.Bits.tpCfgFlowCtrl = 0;				
	tlv_ptr->rmtTpStat.Bits.tpCfgLoopChk = 0;
	tlv_ptr->rmtTpStat.Bits.tpStatLink = locLink[0];
	tlv_ptr->rmtTpStat.Bits.tpStatDuplex = locDuplexStat[0];
	if(locSpeedStat[0] == 10)
		tlv_ptr->rmtTpStat.Bits.tpStatSpeed = 0;
	else if(locSpeedStat[0] == 100)
		tlv_ptr->rmtTpStat.Bits.tpStatSpeed = 1;
	else
		tlv_ptr->rmtTpStat.Bits.tpStatSpeed = 2;
	tlv_ptr->rmtTpStat.Bits.tpStatLoop = 0;
	tlv_ptr->rmtFxStat.Bits.fxCfgAuto = locAutoCfg[1];
	hwGetFef(&u8Tmp);
	if(u8Tmp)
		tlv_ptr->rmtFxStat.Bits.fxCfgFEF = 1;
	else
		tlv_ptr->rmtFxStat.Bits.fxCfgFEF = 0;
	hwGetPortFlowCtrl(2, &u8Tmp);
	if(u8Tmp)
		tlv_ptr->rmtFxStat.Bits.fxCfgFlowCtrl = 1;
	else
		tlv_ptr->rmtFxStat.Bits.fxCfgFlowCtrl = 0;				
	tlv_ptr->rmtFxStat.Bits.fxCfgLoopChk = 0;
	tlv_ptr->rmtFxStat.Bits.fxStatLink = locLink[1];
	tlv_ptr->rmtFxStat.Bits.fxStatLoop = 0;	
	hwGetPortRate(2, 1, &tlv_ptr->rmtTpFxSpdLmt);
	tlv_ptr->rmtTpFxSpdLmt <<= 1;
	hwGetPortRate(1, 1, &tlv_ptr->rmtFxTpSpdLmt);
	tlv_ptr->rmtFxTpSpdLmt <<= 1;
	hwGetPortStorm(1, &u8Tmp, &u16Tmp);
	if(u8Tmp == 0) /*bcast*/
	{
		if(u16Tmp == 0)
			tlv_ptr->rmtTpFxBcastLmt = 0;
		else
		{
			if(u16Tmp >= 8/*512k*/)
			{
				u16Tmp >>= 3;
				if(u16Tmp > 0xff)
					tlv_ptr->rmtTpFxBcastLmt = 0xff;
				else
					tlv_ptr->rmtTpFxBcastLmt = u16Tmp;
			}
			else
				tlv_ptr->rmtTpFxBcastLmt = 1;
		}					
		tlv_ptr->rmtTpFxMcastLmt=0;
	}
	else if(u8Tmp == 1)/*m-bcast*/
	{
		if(u16Tmp == 0)
		{
			tlv_ptr->rmtTpFxBcastLmt = 0;
			tlv_ptr->rmtTpFxMcastLmt = 0;
		}
		else
		{
			if(u16Tmp >= 8/*512k*/)
			{
				u16Tmp >>= 3;
				if(u16Tmp > 0xff)
				{
					tlv_ptr->rmtTpFxBcastLmt = 0xff;
					tlv_ptr->rmtTpFxMcastLmt = 0xff;
				}
				else
				{
					tlv_ptr->rmtTpFxBcastLmt = u16Tmp;
					tlv_ptr->rmtTpFxMcastLmt = u16Tmp;
				}
			}
			else
			{
				tlv_ptr->rmtTpFxBcastLmt = 1;
				tlv_ptr->rmtTpFxMcastLmt = 1;
			}
		}	
	}
	else
	{
		tlv_ptr->rmtTpFxBcastLmt = 0;
		tlv_ptr->rmtTpFxMcastLmt = 0;
	}
	
	hwGetPortStorm(2, &u8Tmp, &u16Tmp);
	if(u8Tmp == 0)
	{
		if(u16Tmp == 0)
			tlv_ptr->rmtFxTpBcastLmt = 0;
		else
		{
			if(u16Tmp >= 8/*512k*/)
			{
				u16Tmp >>= 3;
				if(u16Tmp > 0xff)
					tlv_ptr->rmtFxTpBcastLmt = 0xff;
				else
					tlv_ptr->rmtFxTpBcastLmt = u16Tmp;
			}
			else
				tlv_ptr->rmtFxTpBcastLmt = 1;
		}					
		tlv_ptr->rmtFxTpMcastLmt=0;
	}
	else if(u8Tmp == 1)
	{
		if(u16Tmp == 0)
		{
			tlv_ptr->rmtFxTpBcastLmt = 0;
			tlv_ptr->rmtFxTpMcastLmt = 0;
		}
		else
		{
			if(u16Tmp >= 8/*512k*/)
			{
				u16Tmp >>= 3;
				if(u16Tmp > 0xff)
				{
					tlv_ptr->rmtFxTpBcastLmt = 0xff;
					tlv_ptr->rmtFxTpMcastLmt = 0xff;
				}
				else
				{
					tlv_ptr->rmtFxTpBcastLmt = u16Tmp;
					tlv_ptr->rmtFxTpMcastLmt = u16Tmp;
				}
			}
			else
			{
				tlv_ptr->rmtFxTpBcastLmt = 1;
				tlv_ptr->rmtFxTpMcastLmt = 1;
			}
		}	
	}
	else
	{
		tlv_ptr->rmtFxTpBcastLmt = 0;
		tlv_ptr->rmtFxTpMcastLmt = 0;
	}
}

void spec_tlv_stat_get_res(UINT8 *data_ptr)
{
#if debugDOT3AH
	DOT3AH_API_DEBUGOUT("Dot3ahApi spec_tlv_stat_get_res\n\r");
#endif	
}

void spec_tlv_rate_set_req(UINT8 *data_ptr)
{
	tSPEC_RATELMT_SET_REQ_TLV *tlv_ptr=(tSPEC_RATELMT_SET_REQ_TLV*)data_ptr;
	UINT16 u16Tmp;
#if debugDOT3AH
	DOT3AH_API_DEBUGOUT("Dot3ahApi spec_tlv_rate_set_req\n\r");
#endif	
	rmtRateCfgFlag = 1;
	
	if(tlv_ptr->rmtTpFxSpdLmt.Bits.rmtSpdLmtEn)
	{
		hwSetPortRate(2, 1, (tlv_ptr->rmtTpFxSpdLmt.Bits.rmtSpdLmt>>1));					
	}
	if(tlv_ptr->rmtFxTpSpdLmt.Bits.rmtSpdLmtEn)
	{
		hwSetPortRate(1, 1, (tlv_ptr->rmtFxTpSpdLmt.Bits.rmtSpdLmt>>1));
	}
	if(tlv_ptr->rmtPktLmt.rmtPktLmtCtrl.rmtPktLmtCtrlVal)
	{
		if(tlv_ptr->rmtPktLmt.rmtPktLmtCtrl.Bits.rmtTpFxBcastLmtEn)
		{
			u16Tmp = tlv_ptr->rmtPktLmt.rmtTpFxBcastLmt;
			hwSetPortStorm(1, 0, (u16Tmp<<3));
		}
		if(tlv_ptr->rmtPktLmt.rmtPktLmtCtrl.Bits.rmtTpFxBcastLmtdis)
		{
			hwSetPortStorm(1, 0, 0);

⌨️ 快捷键说明

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