📄 ge_protosend.c
字号:
/**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-
* GE_ProtoSend.c - Ethernet 1000M code. .
*
* Copyright 2001-12 by GDT, Inc
*
* modification history
* --------------------
* 2001-12-14,yxy created.
*
*/
#include <msgQlib.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include "GE_Arp.h"
#include "GE_Global.h"
#include "GE_GlobalP.h"
#include "GE_ProtoSend.h"
#include "SBSL_MemManage.h"
#include "SBSL_Monitor.h"
#include "bdcom_860.h"
#include "GE_Utility.h"
unsigned int GE_PRO_SEND_DEBUG=0;
MSG_Q_ID GE_ProtoSendMsgQId;
/********************************************************************************************
* ProtoGroupInit: initlize the ProtoGroup
*/
STATUS GE_ProtoSendInit(void)
{
if (SBSL_TaskFlagGet(GE_PROTO_SEND_TASK_CODE)!= SBSL_TASK_UNREGISTER)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSendInit:the task has REGISTER!\n");
return ERROR;
}
if ((GE_ProtoSendMsgQId = msgQCreate(MAX_MSG_NUM,sizeof(TASK_MSG),MSG_Q_PRIORITY)) == NULL)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSendInit:creat MSGQ failed!\n");
return ERROR;
}
if(SBSL_TaskRegister( GE_PROTO_SEND_TASK_CODE,
GE_ProtoSendMsgQId,
GE_ProtoSendReinit,
GE_ProtoSendDel)==ERROR)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSendInit:task REGISTER failed!\n");
return ERROR;
}
if(taskSpawn ( TASK_NAME[GE_PROTO_SEND_TASK_CODE],
GE_PROTOSEND_TASK_PRI,
0,
100000,
(FUNCPTR)GE_ProtoSend,
0,0,0,0,0,0,0,0,0,0)==ERROR)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSendInit:reating task failed!\n");
return ERROR;
}
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_ProtoSendInit:the tProtoSend init succeed!\n");
return OK;
}
/********************************************************************************************
* ProtoGroup_DEL: DEL the GE_ProtoSendTask
*/
STATUS GE_ProtoSendDel (void)
{
if(SBSL_TaskFlagGet(GE_PROTO_SEND_TASK_CODE)!= SBSL_TASK_STARTED)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSendTaskDel:task not start!\n");
return ERROR;
}
if(taskDelete (SBSL_TaskIdGet(GE_PROTO_SEND_TASK_CODE))==ERROR )
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSendTaskDel:Delete GE_ProtoSendTask failed!\n");
return ERROR;
}
if (SBSL_TaskMemClear(GE_PROTO_SEND_TASK_CODE) == ERROR)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSendDel:Mem clear failed!\n");
}/*continue run and may cause mem block lost*/
if (SBSL_TaskStop(GE_PROTO_SEND_TASK_CODE) == ERROR)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSendDel:task stop failed!\n");
}
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_ProtoSendDel:task delete success!\n");
return OK;
}
/********************************************************************************************
* GE_ProtoSendReinit: reinit the GE_ProtoSendTask
*/
STATUS GE_ProtoSendReinit (void)
{
if (SBSL_TaskFlagGet(GE_PROTO_SEND_TASK_CODE)== SBSL_TASK_STARTED)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSendReinit:the task has started!\n");
return OK;
}
if (taskSpawn ( TASK_NAME[GE_PROTO_SEND_TASK_CODE],
GE_PROTOSEND_TASK_PRI,
0,
100000,
(FUNCPTR)GE_ProtoSend,
0,0,0,0,0,0,0,0,0,0)== ERROR)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSendReinit:Creating task failed!\n");
return ERROR;
}
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_ProtoSendReinit:Creating task success!\n");
return OK;
}
/********************************************************************************************
* ProtoGroup: Implement GE_ProtoSendTask
*/
STATUS GE_ProtoSend()
{
TASK_MSG ProtoSendMsg;
IP_MAC_BAND* pEntry;
ULONG bufLen,nextIp,ICMP_COUNT;
unsigned char* p;
unsigned char ICMP_BUF[100];
unsigned char unit,i;
while(BOARD_STATE != BOARD_STATE_NORMAL)
{
taskDelay(30);
}
if(SBSL_TaskStart(GE_PROTO_SEND_TASK_CODE,taskIdSelf()))
{
return ERROR;
}
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_ProtoSend:Task is running...\n");
while(1)
{
if(SBSL_TaskMsgIdGet(GE_PROTO_SEND_TASK_CODE)==NULL)
{
return ERROR;
}
if ((msgQReceive(GE_ProtoSendMsgQId,
(char *) &ProtoSendMsg,
MSG_LENGTH,
WAIT_FOREVER)) == ERROR)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSend: cannot receive any message !\n" );
return ERROR;
}
switch (ProtoSendMsg.type)
{
case MONITOR_MSG:
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_ProtoSend:received the MONITOR_MSG .\n");
ProtoSendMsg.taskCode = GE_PROTO_SEND_TASK_CODE;
ProtoSendMsg.type = MONITOR_MSG_ACK;
ProtoSendMsg.length = 0;
memset((void*)ProtoSendMsg.msgBuf, 0, 128);
if (msgQSend( SBSL_TaskMsgIdGet( MONITOR_TASK_CODE),
(char *)&ProtoSendMsg,
140,
NO_WAIT,
MSG_PRI_URGENT) == ERROR)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSend: send MONITOR_MSG_ACK to tBoardMonitor failed!\n");
break;
}
else
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_ProtoSend: send MONITOR_MSG_ACK to tBoardMonitor succeed!\n");
}
break;
case IP_PKT_DOWNRECEIVE:
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_ProtoSend:received IP_PROTO packet!\n");
p = (char*)(*(ULONG*)&ProtoSendMsg.msgBuf[4]);
bufLen = *(ULONG*)(p-4);
unit=*(p+1);
nextIp=*(ULONG*)(p+2);
GE_WriteIpToOutFpga(unit,nextIp,p+6,bufLen);
break;
case MPLS_PKT_DOWNRECEIVE:
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_ProtoSend:received MPLS_PROTO packet!\n");
p = (char*)(*(ULONG*)&ProtoSendMsg.msgBuf[4]);
bufLen = ProtoSendMsg.length-6;
unit=*(p+1);
nextIp=*(ULONG*)(p+2);
GE_WriteMplsToOutFpga(unit,nextIp,p+6,bufLen);
break;
case ARP_PROTO:
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_ProtoSend:received ARP packet!\n");
bufLen=ProtoSendMsg.length-4;
unit=(unsigned char)(*(ULONG*)&ProtoSendMsg.msgBuf[0]);
GE_WritePktToOutfpga((ULONG*)&ProtoSendMsg.msgBuf[4], bufLen, unit);
break;
case ROUTED_ICMP_IP_MSG:
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_ProtoSend:received ICMP packet from FWD!\n");
unit = ProtoSendMsg.msgBuf[0] & 0x0F;
bufLen =(*(unsigned short*)&ProtoSendMsg.msgBuf[2])+14;
nextIp = (ULONG)(*(ULONG*)&ProtoSendMsg.msgBuf[4]);
pEntry = GE_Arp_entry_lookup(unit, nextIp);
if(pEntry == NULL)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSend:this IPADDRESS is not in the IP_MAC table!\n");
GE_Arp_request_packet_generation(unit,nextIp);
break;
}
else
{
bcopy(&pEntry->PhyAddr[0],&ICMP_BUF[0],MAC_ADD_SIZ);
GE_GetPortMac (&ICMP_BUF[6],unit);
*(USHORT*)&ICMP_BUF[12]=0x800;
bcopy(&ProtoSendMsg.msgBuf[8],&ICMP_BUF[14],56);
GE_WritePktToOutfpga((ULONG*)&ICMP_BUF[0],bufLen,unit);
}
ICMP_COUNT+=1;
default:
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ProtoSend:received msg type %d invalid!\n",ProtoSendMsg.type);
break;
}
}
return OK;
}
/********************************************************************************************
* write all kind proto packet to outfpga in order to send to ethernet
*/
void GE_WritePktToOutfpga(ULONG *Buf, ULONG bufLen,unsigned char unit)
{
int i;
ULONG flag;
ULONG exPort;
ULONG port;
ULONG padNum;
ULONG cData;
for(i=0;i<10;i++)
{
taskLock();
flag=outfpgaRead(0x2A);
taskUnlock();
if ((flag&0x80000000)==0x80000000)
{
break;
}
}
if(i==10)
{
outfpgaWrite(0x10,0x0);/*reset in_chip pro fifo.*/
return ;
}
padNum = (2+ bufLen%4)<<8; /*BUFLEN is dmac ,sman protoType and data*/
port=(ULONG)(unit);
exPort=(ULONG)GE_swiport<<24;
cData=port|exPort|padNum;
outfpgaWrite(0x18,0xE25C4B89);
outfpgaWrite(0x18,cData);
for(i = 0; i<( (bufLen % 4 == 0)? bufLen / 4 : (bufLen / 4 + 1) ); i++)
{
outfpgaWrite(0x18,*Buf);
Buf+= 1;
}
outfpgaWrite(0x18,0x1da3b476);
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_WritePktToOutfpga:a packet send OK!\n");/*memfree is delete!*/
return;
}
/*******************************************************************************************
*
*/
STATUS GE_WriteIpToOutFpga(unsigned char unit,ULONG nextIp,char* pBuf,ULONG bufLen)
{
int i;
ULONG flag;
ULONG exPort;
ULONG padNum;
ULONG cData,data;
char buf[2000];
char DMAC[MAC_ADD_SIZ];
char SMAC[MAC_ADD_SIZ];
IP_MAC_BAND* pEntry;
pEntry=(IP_MAC_BAND*)GE_Arp_entry_lookup(unit, nextIp);
if(pEntry==NULL)
{
GE_Arp_request_packet_generation (unit,nextIp);
free(pBuf-26);
return OK;
}
else
{
GE_GetPortMac(&buf[6],unit);
bcopy((char*)&(pEntry->PhyAddr[0]),&buf[0],MAC_ADD_SIZ);
buf[12]=0x08;
buf[13]=0x00;
bcopy(pBuf,&buf[14],bufLen);
free(pBuf-26);
}
for(i=0;i<10;i++)
{
taskLock();
flag=outfpgaRead(0x2A);
taskUnlock();
if ((flag&0x80000000)==0x80000000)
{
break;
}
}
if(i==10)
{
outfpgaWrite(0x10,0x0);/*reset in_chip pro fifo.*/
return ERROR;
}
padNum = (2+ bufLen%4)<<8; /*BUFLEN is dmac ,sman protoType and data*/
exPort=(ULONG)GE_swiport<<24;
cData=unit|(exPort)|padNum;
outfpgaWrite(0x18,0xE25C4B89);
outfpgaWrite(0x18,cData);
for(i = 0; i<( ((bufLen+14) % 4 == 0)? (bufLen+14) / 4 : ((bufLen+14) / 4 + 1) ); i++)
{
data=*(ULONG*)&buf[0+i*4];
outfpgaWrite(0x18,data);
}
outfpgaWrite(0x18,0x1da3b476);
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_WritePktToOutfpga:a packet send OK!\n");/*memfree is delete!*/
return OK;
}
/*******************************************************************************************
*
*/
STATUS GE_WriteMplsToOutFpga(unsigned char unit,ULONG nextIp,char*pBuf,ULONG bufLen)
{
int i;
ULONG flag;
ULONG exPort;
ULONG padNum;
ULONG cData,data;
char buf[2000];
char DMAC[MAC_ADD_SIZ];
char SMAC[MAC_ADD_SIZ];
IP_MAC_BAND* pEntry;
pEntry=(IP_MAC_BAND*)GE_Arp_entry_lookup(unit, nextIp);
if(pEntry==NULL)
{
GE_Arp_request_packet_generation (unit,nextIp);
free(pBuf-26);
return OK;
}
else
{
GE_GetPortMac(&buf[6],unit);
bcopy((char*)&(pEntry->PhyAddr[0]),&buf[0],MAC_ADD_SIZ);
buf[12]=0x88;
buf[13]=0x47;
bcopy(pBuf,&buf[14],bufLen);
free(pBuf-26);
}
for(i=0;i<10;i++)
{
taskLock();
flag=outfpgaRead(0x2A);
taskUnlock();
if ((flag&0x80000000)==0x80000000)
{
break;
}
}
if(i==10)
{
outfpgaWrite(0x10,0x0);/*reset in_chip pro fifo.*/
return ERROR;
}
padNum = (2+ bufLen%4)<<8; /*BUFLEN is dmac ,sman protoType and data*/
exPort=(ULONG)GE_swiport<<24;
cData=unit|(exPort)|padNum;
outfpgaWrite(0x18,0xE25C4B89);
outfpgaWrite(0x18,cData);
for(i = 0; i<( ((bufLen+14) % 4 == 0)? (bufLen+14) / 4 : ((bufLen+14) / 4 + 1) ); i++)
{
data=*(ULONG*)&buf[0+i*4];
outfpgaWrite(0x18,data);
}
outfpgaWrite(0x18,0x1da3b476);
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_EVENT,"GE_WritePktToOutfpga:a packet send OK!\n");/*memfree is delete!*/
return OK;
}
/*******************************************************************************************
*
*/
STATUS GE_SuspendProtoSend()
{
if(taskSuspend((SBSL_TaskIdGet(GE_PROTO_SEND_TASK_CODE)))==ERROR)
{
return ERROR;
}
if(SBSL_TaskStop(GE_PROTO_SEND_TASK_CODE)==ERROR)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_SuspendProtoSend:suspendTask failed!\n");
return ERROR;
}
return OK;
}
/*******************************************************************************************
*
*/
STATUS GE_ResumeProtoSend()
{
if(taskResume((SBSL_TaskIdGet(GE_PROTO_SEND_TASK_CODE)))==ERROR)
{
return ERROR;
}
if((SBSL_TaskStart(GE_PROTO_SEND_TASK_CODE,SBSL_TaskIdGet(GE_PROTO_SEND_TASK_CODE)))==ERROR)
{
if(GE_PRO_SEND_DEBUG)
GE_printf(GE_ALARM,"GE_ResumeProtoSend:ResumeTask failed!\n");
return ERROR;
}
return OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -