50 #define ECAT_RECV_FAILED 0x664
51 #define ECAT_RECV_OK 0x665
52 #define ECAT_RECV_RETRY_OK 0x666
53 #define ECAT_STACK_RECV 0x667
54 #define ECAT_SEND_START 0x675
55 #define ECAT_SEND_COMPLETE 0x676
56 #define ECAT_SEND_FAILED 0x677
60 #define NIC_LOGMSG(x,a,b,c,d,e,f) \
62 logMsg (x,a,b,c,d,e,f); \
64 #define NIC_WVEVENT(a,b,c) \
71 #define NIC_LOGMSG(x,a,b,c,d,e,f)
72 #define NIC_WVEVENT(a,b,c)
75 #define IF_NAME_SIZE 8
98 #define RX_PRIM priMAC[1]
100 #define RX_SEC secMAC[1]
103 #define USECS_PER_SEC 1000000
107 static int mux_rx_callback(
void* pCookie,
long type, M_BLK_ID pMblk, LL_HDR_INFO *llHdrInfo,
void *muxUserArg);
120 printf(
"Generic is used\n");
146 pPktDev = &(port->
redport->pktDev);
151 pPktDev = &(port->pktDev);
161 port->sem_get_index = semMCreate(SEM_Q_PRIORITY | SEM_INVERSION_SAFE);
166 memset(ifn,0x0,
sizeof(ifn));
168 for(i=0; i < strlen(ifname);i++)
170 if(isdigit(ifname[i]))
172 strncpy(ifn, ifname, i);
173 unit_no = atoi(&ifname[i]);
181 pPktDev->
port = port;
187 pPktDev->
pCookie = muxBind(ifn,
200 NIC_LOGMSG(
"ecx_setupnic: muxBind init for gei: %d failed\n",
201 unit_no, 2, 3, 4, 5, 6);
206 pPktDev->
endObj = endFindByName(ifn, unit_no);
208 if (port->pktDev.endObj == NULL)
211 NIC_LOGMSG(
"error_hook: endFindByName failed, device gei: %d not found\n",
212 unit_no, 2, 3, 4, 5, 6);
230 port->
redport->msgQId[i] = msgQCreate(1,
sizeof(M_BLK_ID), MSG_Q_FIFO);
231 if (port->
redport->msgQId[i] == MSG_Q_ID_NULL)
233 NIC_LOGMSG(
"ecx_setupnic: Failed to create redundant MsgQ[%d]",
243 NIC_LOGMSG(
"ecx_setupnic: Redundant port not allocated",
244 unit_no, 2, 3, 4, 5, 6);
260 port->msgQId[i] = msgQCreate(1,
sizeof(M_BLK_ID), MSG_Q_FIFO);
261 if (port->msgQId[i] == MSG_Q_ID_NULL)
263 NIC_LOGMSG(
"ecx_setupnic: Failed to create MsgQ[%d]",
297 pPktDev = &(port->pktDev);
301 if (port->msgQId[i] != MSG_Q_ID_NULL)
303 if (msgQReceive(port->msgQId[i],
308 NIC_LOGMSG(
"ecx_closenic: idx %d MsgQ close\n", i,
311 netMblkClChainFree(trash_can);
313 msgQDelete(port->msgQId[i]);
325 pPktDev = &(port->
redport->pktDev);
328 if (port->
redport->msgQId[i] != MSG_Q_ID_NULL)
330 if (msgQReceive(port->
redport->msgQId[i],
335 NIC_LOGMSG(
"ecx_closenic: idx %d MsgQ close\n", i,
338 netMblkClChainFree(trash_can);
340 msgQDelete(port->
redport->msgQId[i]);
361 bp->da0 = htons(0xffff);
362 bp->da1 = htons(0xffff);
363 bp->da2 = htons(0xffff);
364 bp->sa0 = htons(
priMAC[0]);
365 bp->sa1 = htons(
priMAC[1]);
366 bp->sa2 = htons(
priMAC[2]);
379 semTake(port->sem_get_index, WAIT_FOREVER);
401 semGive(port->sem_get_index);
429 M_BLK_ID pPacket = NULL;
431 END_OBJ *endObj = (END_OBJ *)pPktDev->
endObj;
436 if(msgQNumMsgs(msgQId) > 0)
439 NIC_LOGMSG(
"ec_outfram_send: idx %d MsgQ abandoned\n", idx,
441 if (msgQReceive(msgQId,
447 NIC_LOGMSG(
"ec_outfram_send: idx %d MsgQ mBlk handled by receiver\n", idx,
455 if ((pPacket = netTupleGet(endObj->pNetPool,
461 NIC_LOGMSG(
"ec_outfram_send: Could not allocate MBLK memory!\n", 1, 2, 3, 4, 5, 6);
466 pPacket->mBlkHdr.mLen = len;
467 pPacket->mBlkHdr.mFlags |= M_PKTHDR;
468 pPacket->mBlkHdr.mData = pPacket->pClBlk->clNode.pClBuf;
469 pPacket->mBlkPktHdr.len = pPacket->m_len;
471 netMblkFromBufCopy(pPacket, buf, 0, pPacket->mBlkHdr.mLen, M_DONTWAIT, NULL);
472 status = muxSend(endObj, pPacket);
481 netMblkClChainFree(pPacket);
483 static int print_once;
511 stack = &(port->
stack);
512 pPktDev = &(port->pktDev);
517 pPktDev = &(port->
redport->pktDev);
525 port->pktDev.tx_count++;
548 ehp->sa1 = htons(
priMAC[1]);
557 datagramP->index = idx;
559 ehp->sa1 = htons(
secMAC[1]);
581 static int mux_rx_callback(
void* pCookie,
long type, M_BLK_ID pMblk, LL_HDR_INFO *llHdrInfo,
void *muxUserArg)
596 length = pMblk->mBlkHdr.mLen;
597 tempbuf = (
ec_bufT *)pMblk->mBlkHdr.mData;
599 port = pPktDev->
port;
606 NIC_LOGMSG(
"mux_rx_callback: idx %d out of bounds\n", idxf,
615 msgQId = port->
redport->msgQId[idxf];
620 msgQId = port->msgQId[idxf];
628 status = msgQSend(msgQId, (
char *)&pMblk,
sizeof(M_BLK_ID),
629 NO_WAIT, MSG_PRI_NORMAL);
635 else if ((status == ERROR) && (errno == S_objLib_OBJ_UNAVAILABLE))
642 port->pktDev.overrun_count++;
643 NIC_LOGMSG(
"mux_rx_callback: idx %d MsgQ overrun\n", idxf,
646 if (msgQReceive(msgQId,
652 netMblkClChainFree(trash_can);
654 status = msgQSend(msgQId,
687 if (stacknumber == 1)
689 msgQId = port->
redport->msgQId[idx];
693 msgQId = port->msgQId[idx];
698 bytesrx = msgQReceive(msgQId, (
void *)pMblk,
699 sizeof(M_BLK_ID), NO_WAIT);
703 bytesrx = msgQReceive(msgQId, (
void *)pMblk,
704 sizeof(M_BLK_ID), tick_timeout);
709 bytesrx = (*pMblk)->mBlkHdr.mLen;
714 return (bytesrx > 0);
744 stack = &(port->
stack);
753 if (
ecx_recvpkt(port, idx, stacknumber, &pMblk, timeout))
758 tempinbuf = (
ec_bufT *)pMblk->mBlkHdr.mData;
763 l =
etohs(ecp->elength) & 0x0fff;
769 rval = ((*rxbuf)[l] + ((
uint16)((*
rxbuf)[l + 1]) << 8));
773 (*stack->
rxsa)[idx] = ntohs(ehp->sa1);
774 netMblkClChainFree(pMblk);
775 port->pktDev.rx_count++;
845 if ( ((primrx == 0) && (secrx ==
RX_SEC)) ||
966 int ec_inframe(
int idx,
int stacknumber,
int timeout)