📄 dm9kend.c
字号:
/* Just want the 6 most significant bits. */ crc = DM9K_CRC_TO_LAF_IX (crc); pCurr = END_MULTI_LST_NEXT(pCurr); } /* Write the hash table to MAC MD table */ for (i = 0, oft = DM9KS_MAR0; i < 4; i++) { regWriteByte(oft++, hash_table[i] & 0xff); regWriteByte(oft++, (hash_table[i] >> 8) & 0xff); } return; }/********************************************************************************* dm9kPollReceive - routine to receive a packet in polled mode.** This routine is called by a user to try and get a packet from the* device. This routine return OK if it is successful in getting the packet** RETURNS: OK or EAGAIN.*/LOCAL STATUS dm9kPollReceive ( DM9K_DRV_CTRL * pDrvCtrl, /* device to be initialized */ M_BLK_ID pMblk ) { int len; char * pBuf; int rmdIndex; int i;#if 0 DM9KPS_EMAC pEmac = (DM9KPS_EMAC)(pDrvCtrl->devAdrs); DRV_LOG (DRV_DEBUG_POLL_RX, "PRX b\n", 1, 2, 3, 4, 5, 6); /* * Handle zero or more newly received frames */ while (!(pEmac->EMAC_RSR & DM9KC_EMAC_REC)); for (i = 0; i < DM9K_N_RX_BUF; i++) { if(tableList[i].addr & 0x1) { rmdIndex = i; len = tableList[rmdIndex].size & 0x3fff; /* get packet length */ pBuf = (char *)(tableList[rmdIndex].addr & 0xFFFFFFFC); 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; } } (*DM9KC_EMAC_RSR) |= DM9KC_EMAC_REC; return (OK); cleanRx: (*DM9KC_EMAC_RSR)|=DM9KC_EMAC_OVR; (*DM9KC_EMAC_RSR)|=DM9KC_EMAC_BNA; (*DM9KC_EMAC_RSR)|= DM9KC_EMAC_REC; DRV_LOG (DRV_DEBUG_RX, "dm9kPollReceive clean index %d %08x\n", rmdIndex, tableList[rmdIndex].addr, 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);#endif return (OK); }/********************************************************************************* dm9kPollSend - 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 dm9kPollSend ( DM9K_DRV_CTRL * pDrvCtrl, /* device to be initialized */ M_BLK_ID pMblk ) { char * pBuf; int index; int len = 0; printf("poll send\n");#if 0 DM9KPS_EMAC pEmac = (DM9KPS_EMAC)(pDrvCtrl->devAdrs); pEmac->EMAC_TSR |= DM9KC_EMAC_COMP; /* * Obtain exclusive access to transmitter. This is necessary becDM9Kse * we might have more than one stack transmitting at once. */ END_TX_SEM_TAKE (&pDrvCtrl->endObj, WAIT_FOREVER); DRV_LOG (DRV_DEBUG_POLL_TX, "PTX b\n", 1, 2, 3, 4, 5, 6); /* Advance our management index (first) */ index = pDrvCtrl->tmdIndex; pBuf = pDrvCtrl->pTxMem[index]; if (pBuf == NULL) return (EAGAIN); /* copy and release the packet */ len = netMblkToBufCopy (pMblk, pBuf, NULL); netMblkClChainFree (pMblk); /* flush the cache, if necessary */ CACHE_DMA_FLUSH(pBuf, len); if (len < ETHERSMALL) { /* Pad to ETHERSMALL with zeros, required by H/W */ bzero (&pBuf[len], ETHERSMALL - len); len = ETHERSMALL; } while (!(pEmac->EMAC_TSR & DM9KC_EMAC_BNQ)); /* pEmac->EMAC_TSR |= DM9KC_EMAC_COMP; */ pEmac->EMAC_TAR = (long) pBuf; pEmac->EMAC_TCR = len; /* Bump the statistic counter. */ END_ERR_ADD (&pDrvCtrl->endObj, MIB2_OUT_UCAST, +1); 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); END_TX_SEM_GIVE (&pDrvCtrl->endObj);#endif return (OK); }/******************************************************************************* dm9kMCastAddrAdd - 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 dm9kMCastAddrAdd ( DM9K_DRV_CTRL * pDrvCtrl, /* device to be initialized */ char * pAddress ) {#ifdef DM9K_END_MULTICAST int error; if ((error = etherMultiAdd (&pDrvCtrl->endObj.multiList, pAddress)) == ENETRESET) dm9kConfig (pDrvCtrl);#endif return (OK); }/******************************************************************************* dm9kMCastAddrDel - 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 dm9kMCastAddrDel ( DM9K_DRV_CTRL * pDrvCtrl, /* device to be initialized */ char * pAddress ) {#if DM9K_END_MULTICAST int error; if ((error = etherMultiDel (&pDrvCtrl->endObj.multiList, (char *)pAddress)) == ENETRESET) dm9kConfig (pDrvCtrl);#endif return (OK); }/******************************************************************************* dm9kMCastAddrGet - 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 dm9kMCastAddrGet ( DM9K_DRV_CTRL * pDrvCtrl, /* device to be initialized */ MULTI_TABLE * pTable ) { int error; error = etherMultiGet (&pDrvCtrl->endObj.multiList, pTable); return (error); }/********************************************************************************* dm9kStop - 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 dm9kStop ( DM9K_DRV_CTRL * pDrvCtrl /* device to be initialized */ ) { STATUS result = OK; /* Stop the device. */ dm9kReset (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,NULL,0,&result); if (result == ERROR) { DRV_LOG (DRV_DEBUG_LOAD, "Could not disconnect interrupt!\n", 1, 2, 3, 4, 5, 6); } return (result); }/******************************************************************************** dm9kUnload - 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 dm9kUnload ( DM9K_DRV_CTRL * pDrvCtrl /* device to be initialized */ ) { END_OBJECT_UNLOAD (&pDrvCtrl->endObj); /* Free the shared DMA memory. */ /* Free the shared DMA memory allocated for clusters */ if (pDrvCtrl->clDesc.memArea != NULL) free (pDrvCtrl->clDesc.memArea); /* Free the memory allocated for mBlks and clBlks */ if (pDrvCtrl->mClCfg.memArea != NULL) free (pDrvCtrl->mClCfg.memArea); /*free rx list*/ if (tableList != NULL) cacheDmaFree (tableList); if (pDrvCtrl->pRxMemBase != NULL) free(pDrvCtrl->pRxMemBase); /*free Tx list*/ if (pDrvCtrl->pTxMemBase != NULL) free(pDrvCtrl->pTxMemBase); /* Free the memory allocated for driver pool structure */ if (pDrvCtrl->endObj.pNetPool != NULL) free (pDrvCtrl->endObj.pNetPool); return (OK); }/********************************************************************************* dm9kPollStart - start polled mode operations** RETURNS: OK or ERROR.*/LOCAL STATUS dm9kPollStart ( DM9K_DRV_CTRL * pDrvCtrl /* device to be initialized */ ) { SYS_INT_DISABLE(pDrvCtrl); pDrvCtrl->flags |= DM9K_POLLING; DRV_LOG (DRV_DEBUG_POLL, "POLL STARTED\n", 1, 2, 3, 4, 5, 6); return (OK); }/********************************************************************************* dm9kPollStop - stop polled mode operations** RETURNS: OK or ERROR.*/LOCAL STATUS dm9kPollStop ( DM9K_DRV_CTRL * pDrvCtrl /* device to be initialized */ ) { SYS_INT_ENABLE(pDrvCtrl); pDrvCtrl->flags &= ~DM9K_POLLING; DRV_LOG (DRV_DEBUG_POLL, "STOPPED\n", 1, 2, 3, 4, 5, 6); return (OK); }/***************************************************************************below added by Horace_Lu*//* read a byte from DM9000 register */static UINT8 regReadByte(UINT8 reg){ OUT_BYTE(DM9KS_ADDR_PORT, reg);// udelay(0); return IN_BYTE(DM9KS_DATA_PORT);}/* read a word from DM9000 internel RAM */static UINT16 readWord(void){ OUT_WORD(DM9KS_ADDR_PORT, DM9KS_MRCMDX);// udelay(0); return IN_WORD(DM9KS_DATA_PORT);}/* write a byte to DM9000 register */static void regWriteByte(UINT8 reg, UINT8 data){ OUT_BYTE(DM9KS_ADDR_PORT, reg);// udelay(0); OUT_BYTE(DM9KS_DATA_PORT, data);// udelay(0);}/* write a WORD to DM9000 internel RAM */static void writeWord(UINT16 data){ OUT_WORD(DM9KS_ADDR_PORT, DM9KS_MWCMDX);// udelay(0); OUT_WORD(DM9KS_DATA_PORT, data);// udelay(0);}/* Read a Word from PHY register */static UINT16 phy_read(int reg){ /* Fill the phyxcer register into REG_0C */ regWriteByte(DM9KS_EPAR, DM9KS_PHY | reg); regWriteByte(DM9KS_EPCR, 0x0C); /* Issue phyxcer read command */ while (regReadByte(DM9KS_EPCR)&0x01) {;} /* Detect PHY read ready */ regWriteByte(DM9KS_EPCR, 0x08); /* Clear phyxcer read command */ /* The read data keeps on REG_0D & REG_0E */ return (((UINT16)(regReadByte(DM9KS_EPDRH) ) << 8 ) | regReadByte(DM9KS_EPDRL));}/* * Write a word to PHY register */static void phy_write(UINT8 reg, UINT16 value){ /* Fill the phyxcer register into REG_0C */ regWriteByte(DM9KS_EPAR, DM9KS_PHY | reg); /* Fill the written data into REG_0D & REG_0E */ regWriteByte(DM9KS_EPDRL, (value & 0xff)); regWriteByte(DM9KS_EPDRH, ((value >> 8) & 0xff)); regWriteByte(DM9KS_EPCR, 0x0A); /* Issue phyxcer write command */ while (regReadByte(DM9KS_EPCR)&0x01) {;} /* Detect PHY write ready */ regWriteByte(DM9KS_EPCR, 0x08); /* Clear phyxcer write command */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -