📄 auend.c
字号:
int len; char * pBuf; UINT32 status, ERROR_MASK=0x812bc000; int rmdIndex,oldLevel; DRV_LOG (DRV_DEBUG_POLL_RX, "PRX b\n", 1, 2, 3, 4, 5, 6); /* * Handle zero or more newly received frames */if (!(AU_RX_ADDRESS(pDrvCtrl->rmdIndex) & (1<<1))) { pDrvCtrl->rmdIndex = (pDrvCtrl->rmdIndex + 1) & (pDrvCtrl->rringSize - 1); /* goto cleanRx; */ return (EAGAIN); } /* Extract packet particulators */ rmdIndex = pDrvCtrl->rmdIndex; /* Read the device status register */ status = AU_RX_STATUS(rmdIndex); len = AU_RX_STATUS (rmdIndex) & 0x3fff; /* get packet length */ pBuf = pDrvCtrl->pRxMem[rmdIndex]; if (status & (ERROR_MASK & ~0x0)) { DRV_LOG (DRV_DEBUG_POLL_RX, "PRX bad error\n", 1, 2, 3, 4, 5, 6); END_ERR_ADD (&pDrvCtrl->endObj, MIB2_IN_ERRS, +1); /* restart chip on fatal error */ if (status & ERROR_MASK & 0x0) /* memory error */ { END_FLAGS_CLR (&pDrvCtrl->endObj, (IFF_UP | IFF_RUNNING)); DRV_LOG (DRV_DEBUG_POLL_RX, "PRX restart\n", 1, 2, 3, 4, 5, 6); auRestart (pDrvCtrl); return (EAGAIN); } /* goto cleanRx; */ goto cleanRx; } if (!len) { DRV_LOG (DRV_DEBUG_RX, "RMD error!\n", 1, 2, 3, 4, 5, 6); END_ERR_ADD (&pDrvCtrl->endObj, MIB2_IN_ERRS, +1); goto cleanRx; /* skip to clean up */ } END_ERR_ADD (&pDrvCtrl->endObj, MIB2_IN_UCAST, +1); /* Upper layer provides the buffer. */ if ((pMblk->mBlkHdr.mLen < len) || (!(pMblk->mBlkHdr.mFlags & M_EXT))) { DRV_LOG (DRV_DEBUG_POLL_RX, "PRX bad mblk len:%d flags:%d\n", pMblk->mBlkHdr.mLen, pMblk->mBlkHdr.mFlags, 3, 4, 5, 6); return (EAGAIN); } pMblk->mBlkHdr.mData += pDrvCtrl->offset; bcopy (pBuf, pMblk->mBlkHdr.mData, len); pMblk->mBlkHdr.mLen = len; pMblk->mBlkHdr.mFlags |= M_PKTHDR; pMblk->mBlkPktHdr.len = len;cleanRx: /* Restore the receiver buffer */ AU_RX_STATUS(rmdIndex) = 0; AU_RX_ADDRESS(rmdIndex) = ((UINT32) AU_CACHE_VIRT_TO_PHYS(pDrvCtrl->pRxMem[rmdIndex])) | 1; SYS_WB_FLUSH(); DRV_LOG (DRV_DEBUG_RX, "auPollReceive clean index %d %08x\n", rmdIndex, AU_RX_ADDRESS(rmdIndex) & 0x1f, 0, 0, 0, 0); /* Advance our management index */ pDrvCtrl->rmdIndex = (pDrvCtrl->rmdIndex + 1) & (pDrvCtrl->rringSize - 1); DRV_LOG (DRV_DEBUG_POLL_RX, "PRX ok\n", 1, 2, 3, 4, 5, 6); return (OK); }/********************************************************************************* auPollSend - routine to send a packet in polled mode.** This routine is called by a user to try and send a packet on the* device.** RETURNS: OK or EAGAIN.*/LOCAL STATUS auPollSend ( AU_DRV_CTRL * pDrvCtrl, /* device to be initialized */ M_BLK_ID pMblk ) { char * pBuf; int index; int len = 0; int oldLevel; UINT32 addr; DRV_LOG (DRV_DEBUG_POLL_TX, "PTX b\n", 1, 2, 3, 4, 5, 6); /* Advance our management index (first) */ index = pDrvCtrl->tmdIndex; if (AU_TX_ADDRESS(index) & 0x01) { DRV_LOG (DRV_DEBUG_POLL_TX, "Out of tmds.\n", 1, 2, 3, 4, 5, 6); if (!pDrvCtrl->txCleaning) auTRingScrub (pDrvCtrl); return (EAGAIN); } pBuf = pDrvCtrl->pTxMem[index]; if (pBuf == NULL) return (EAGAIN); /* copy and release the packet */ len = netMblkToBufCopy (pMblk, pBuf, NULL); if (len < ETHERSMALL) { /* Pad to ETHERSMALL with zeros, required by H/W */ bzero (&pBuf[len], ETHERSMALL - len); len = ETHERSMALL; } addr = ((UINT32)AU_CACHE_VIRT_TO_PHYS(pDrvCtrl->pTxMem[index]) | 1); AU_TX_LENGTH(index) = len; AU_TX_STATUS(index) = 0; AU_TX_ADDRESS(index) = addr; SYS_WB_FLUSH(); /* Bump the statistic counter. */ END_ERR_ADD (&pDrvCtrl->endObj, MIB2_OUT_UCAST, +1); /* Spin until we think we've sent it. */ while (!(AU_TX_ADDRESS(index) & (1<<1))); AU_TX_ADDRESS(index) = 0; AU_TX_STATUS(index) = 0; AU_TX_LENGTH(index) = 0; SYS_WB_FLUSH(); index = (pDrvCtrl->tmdIndex + 1) & (pDrvCtrl->tringSize - 1); pDrvCtrl->tmdIndex = index; pDrvCtrl->tmdLastIndex = (pDrvCtrl->tmdLastIndex + 1) & (pDrvCtrl->tringSize - 1); DRV_LOG (DRV_DEBUG_POLL_TX, "PTX e\n", 1, 2, 3, 4, 5, 6); return (OK); }/******************************************************************************* auMCastAddrAdd - add a multicast address for the device** This routine adds a multicast address to whatever the driver* is already listening for. It then resets the address filter.** RETURNS: OK*/LOCAL STATUS auMCastAddrAdd ( AU_DRV_CTRL * pDrvCtrl, /* device to be initialized */ char * pAddress ) {#ifdef AU_END_MULTICAST int error; if ((error = etherMultiAdd (&pDrvCtrl->endObj.multiList, pAddress)) == ENETRESET) auConfig (pDrvCtrl);#endif return (OK); }/******************************************************************************* auMCastAddrDel - delete a multicast address for the device** This routine removes a multicast address from whatever the driver* is listening for. It then resets the address filter.** RETURNS: OK.*/LOCAL STATUS auMCastAddrDel ( AU_DRV_CTRL * pDrvCtrl, /* device to be initialized */ char * pAddress ) {#if AU_END_MULTICAST int error; if ((error = etherMultiDel (&pDrvCtrl->endObj.multiList, (char *)pAddress)) == ENETRESET) auConfig (pDrvCtrl);#endif return (OK); }/******************************************************************************* auMCastAddrGet - get the multicast address list for the device** This routine gets the multicast list of whatever the driver* is already listening for.** RETURNS: OK/ERROR*/LOCAL STATUS auMCastAddrGet ( AU_DRV_CTRL * pDrvCtrl, /* device to be initialized */ MULTI_TABLE * pTable ) { int error; error = etherMultiGet (&pDrvCtrl->endObj.multiList, pTable); return (error); }/********************************************************************************* auStop - stop the device** This function calls BSP functions to disconnect interrupts and stop* the device from operating in interrupt mode.** RETURNS: OK or ERROR*/LOCAL STATUS auStop ( AU_DRV_CTRL * pDrvCtrl /* device to be initialized */ ) { STATUS result = OK; /* Stop the device. */ auReset (pDrvCtrl); SYS_INT_DISABLE (pDrvCtrl); /* mark the interface as down */ END_FLAGS_CLR (&pDrvCtrl->endObj, (IFF_UP | IFF_RUNNING)); /* disconnect the interrupt handler */ SYS_INT_DISCONNECT (pDrvCtrl, auInt, (int)pDrvCtrl, &result); if (result == ERROR) { DRV_LOG (DRV_DEBUG_LOAD, "Could not disconnect interrupt!\n", 1, 2, 3, 4, 5, 6); } return (result); }/******************************************************************************** auUnload - unload a driver from the system** This function first brings down the device, and then frees any* stuff that was allocated by the driver in the load function. The controller* structure should be free by who ever is calling this function.** RETURNS: OK*/LOCAL STATUS auUnload ( AU_DRV_CTRL * pDrvCtrl /* device to be initialized */ ) { END_OBJECT_UNLOAD (&pDrvCtrl->endObj); /* Free the shared DMA memory. */ if (pDrvCtrl->pRxMem) { cacheDmaFree (pDrvCtrl->pRxMemBase); pDrvCtrl->pRxMemBase = NULL; } if (pDrvCtrl->pTxMem) { cacheDmaFree (pDrvCtrl->pTxMemBase); pDrvCtrl->pTxMemBase = NULL; } /* Free the shared DMA memory allocated for clusters */ if (pDrvCtrl->flags & AU_MEM_ALLOC_FLAG) cacheDmaFree (pDrvCtrl->clDesc.memArea); /* Free the memory allocated for mBlks and clBlks */ if (pDrvCtrl->mClCfg.memArea != NULL) free (pDrvCtrl->mClCfg.memArea); /* Free the memory allocated for driver pool structure */ if (pDrvCtrl->endObj.pNetPool != NULL) free (pDrvCtrl->endObj.pNetPool); return (OK); }/********************************************************************************* auPollStart - start polled mode operations** RETURNS: OK or ERROR.*/LOCAL STATUS auPollStart ( AU_DRV_CTRL * pDrvCtrl /* device to be initialized */ ) { SYS_INT_DISABLE(pDrvCtrl); pDrvCtrl->flags |= AU_POLLING; DRV_LOG (DRV_DEBUG_POLL, "POLL STARTED\n", 1, 2, 3, 4, 5, 6); return (OK); }/********************************************************************************* auPollStop - stop polled mode operations** RETURNS: OK or ERROR.*/LOCAL STATUS auPollStop ( AU_DRV_CTRL * pDrvCtrl /* device to be initialized */ ) { SYS_INT_ENABLE(pDrvCtrl); pDrvCtrl->flags &= ~AU_POLLING; DRV_LOG (DRV_DEBUG_POLL, "STOPPED\n", 1, 2, 3, 4, 5, 6); return (OK); }/******************************************************************************** auTRingScrub - clean the transmit ring** RETURNS: N/A**/LOCAL void auTRingScrub ( AU_DRV_CTRL * pDrvCtrl /* device to be initialized */ ) { pDrvCtrl->txCleaning = TRUE; do { /* if the buffer is still owned by the MAC, don't touch it */ if (AU_TX_ADDRESS(pDrvCtrl->tmdLastIndex) & (1 << 1)) break; /* Clear the TX entry */ DRV_LOG (DRV_DEBUG_TX, "auTRingScrub %d\n", pDrvCtrl->tmdLastIndex, 0, 0, 0, 0, 0); AU_TX_STATUS(pDrvCtrl->tmdLastIndex) = 0; AU_TX_LENGTH(pDrvCtrl->tmdLastIndex) = 0; AU_TX_ADDRESS(pDrvCtrl->tmdLastIndex) = 0; /* Increment the tmd disposal index pointer around the ring */ pDrvCtrl->tmdLastIndex = (pDrvCtrl->tmdLastIndex + 1) & (pDrvCtrl->tringSize - 1); } while (pDrvCtrl->tmdLastIndex != pDrvCtrl->tmdIndex); pDrvCtrl->txCleaning = FALSE; }/******************************************************************************** auDump - display device status**/void auDump ( int unit ) {#ifdef DRV_DEBUG int i; AU_DRV_CTRL * pDrvCtrl = dbgDrvCtrl[unit]; /* Examine receive buffers */ printf ("Rx index %d (rmdIndex=%d)\n", (AU_RX_ADDRESS(0) >> 2) & 0x03, pDrvCtrl->rmdIndex); for (i = 0; i < pDrvCtrl->rringSize; ++i) { printf ("rx%d addr=%08x astat=%02x stat=%08x len=%d\n", i, AU_RX_ADDRESS(i) & ~0x1f, AU_RX_ADDRESS(i) & 0x1f, AU_RX_STATUS(i) & 0xffffc000, AU_RX_STATUS(i) & 0x00003fff); printf ("receive %d done\n", AU_RX_ADDRESS(i) & (1 << 1) ? 1 : 0); } /* Examine transmit buffers */ printf ("Tx index %d\n", (AU_TX_ADDRESS(0) >> 2) & 0x03); for (i = 0; i < pDrvCtrl->tringSize; ++i) { printf ("tx%d addr=%08x astat=%02x stat=%08x len=%d\n", i, AU_TX_ADDRESS(i) & ~0x1f, AU_TX_ADDRESS(i) & 0x1f, AU_TX_STATUS(i), AU_TX_LENGTH(i)); printf ("transmit %d done\n", AU_TX_ADDRESS(i) & (1 << 1) ? 1 : 0); }#endif }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -