📄 if_fcc.c
字号:
os_printf("/***NO LINK***\n");#ifdef CYGPKG_REDBOOT return false;#endif } os_printf("\n"); // Initialize upper level driver for ecos (sc->funs->eth_drv->init)(sc, (unsigned char *)&qi->enaddr); return true;} //// This function is called to "start up" the interface. It may be called// multiple times, even when the hardware is already running. It will be// called whenever something "hardware oriented" changes and should leave// the hardware ready to send/receive packets.//static voidfcc_eth_start(struct eth_drv_sc *sc, unsigned char *enaddr, int flags){ struct fcc_eth_info *qi = (struct fcc_eth_info *)sc->driver_private; // Enable the device : // Set the ENT/ENR bits in the GFMR -- Enable Transmit/Receive qi->fcc_reg->fcc_gfmr |= (FCC_GFMR_EN_Rx | FCC_GFMR_EN_Tx); }//// This function is called to shut down the interface.//static voidfcc_eth_stop(struct eth_drv_sc *sc){ struct fcc_eth_info *qi = (struct fcc_eth_info *)sc->driver_private; // Disable the device : // Clear the ENT/ENR bits in the GFMR -- Disable Transmit/Receive qi->fcc_reg->fcc_gfmr &= ~(FCC_GFMR_EN_Rx | FCC_GFMR_EN_Tx);}//// This function is called for low level "control" operations//static intfcc_eth_control(struct eth_drv_sc *sc, unsigned long key, void *data, int length){ switch (key) { case ETH_DRV_SET_MAC_ADDRESS: return 0; break; default: return 1; break; }}//// This function is called to see if another packet can be sent.// It should return the number of packets which can be handled.// Zero should be returned if the interface is busy and can not send any more.//static intfcc_eth_can_send(struct eth_drv_sc *sc){ struct fcc_eth_info *qi = (struct fcc_eth_info *)sc->driver_private; volatile struct fcc_bd *txbd = qi->txbd;#ifndef FCC_BDs_NONCACHED int cache_state;#endif#ifndef FCC_BDs_NONCACHED HAL_DCACHE_IS_ENABLED(cache_state); if (cache_state) { HAL_DCACHE_INVALIDATE(fcc_eth_txring, 8*CYGNUM_DEVS_ETH_POWERPC_FCC_TxNUM); }#endif return ((txbd->ctrl & (FCC_BD_Tx_TC | FCC_BD_Tx_Ready)) == 0);}//// This routine is called to send data to the hardware.static void fcc_eth_send(struct eth_drv_sc *sc, struct eth_drv_sg *sg_list, int sg_len, int total_len, unsigned long key){ struct fcc_eth_info *qi = (struct fcc_eth_info *)sc->driver_private; struct fcc_bd *txbd, *txfirst; volatile char *bp; int i, txindex; int cache_state; HAL_DCACHE_IS_ENABLED(cache_state);#ifndef FCC_BDs_NONCACHED if (cache_state) { HAL_DCACHE_INVALIDATE(fcc_eth_txring, 8*CYGNUM_DEVS_ETH_POWERPC_FCC_TxNUM); }#endif // Find a free buffer txbd = txfirst = qi->txbd; while (txbd->ctrl & FCC_BD_Tx_Ready) { // This buffer is busy, move to next one if (txbd->ctrl & FCC_BD_Tx_Wrap) { txbd = qi->tbase; } else { txbd++; } if (txbd == txfirst) {#ifdef CYGPKG_NET panic ("No free xmit buffers");#else os_printf("FCC Ethernet: No free xmit buffers\n");#endif } } // Remember the next buffer to try if (txbd->ctrl & FCC_BD_Tx_Wrap) { qi->txbd = qi->tbase; } else { qi->txbd = txbd+1; } txindex = ((unsigned long)txbd - (unsigned long)qi->tbase) / sizeof(*txbd); qi->txkey[txindex] = key; // Set up buffer txbd->length = total_len; bp = txbd->buffer; for (i = 0; i < sg_len; i++) { memcpy((void *)bp, (void *)sg_list[i].buf, sg_list[i].len); bp += sg_list[i].len; } // Make sure no stale data buffer ... if (cache_state) { HAL_DCACHE_FLUSH(txbd->buffer, txbd->length); } // Send it on it's way txbd->ctrl |= FCC_BD_Tx_Ready | FCC_BD_Tx_Last | FCC_BD_Tx_TC;#ifndef FCC_BDs_NONCACHED if (cache_state) { HAL_DCACHE_FLUSH(fcc_eth_txring, 8*CYGNUM_DEVS_ETH_POWERPC_FCC_TxNUM); }#endif }//// This function is called when a packet has been received. It's job is// to prepare to unload the packet from the hardware. Once the length of// the packet is known, the upper layer of the driver can be told. When// the upper layer is ready to unload the packet, the internal function// 'fcc_eth_recv' will be called to actually fetch it from the hardware.//static voidfcc_eth_RxEvent(struct eth_drv_sc *sc){ struct fcc_eth_info *qi = (struct fcc_eth_info *)sc->driver_private; struct fcc_bd *rxbd; int cache_state; HAL_DCACHE_IS_ENABLED(cache_state);#ifndef FCC_BDs_NONCACHED if (cache_state) { HAL_DCACHE_INVALIDATE(fcc_eth_rxring, 8*CYGNUM_DEVS_ETH_POWERPC_FCC_RxNUM); }#endif rxbd = qi->rnext; while ((rxbd->ctrl & FCC_BD_Rx_Empty) == 0) { qi->rxbd = rxbd; // Save for callback // This is the right way of doing it, but dcbi has a bug ... // if (cache_state) { // HAL_DCACHE_INVALIDATE(rxbd->buffer, rxbd->length); // } if ((rxbd->ctrl & FCC_BD_Rx_ERRORS) == 0) { (sc->funs->eth_drv->recv)(sc, rxbd->length);#if 1 // Coherent caches? if (cache_state) { HAL_DCACHE_FLUSH(rxbd->buffer, rxbd->length); }#endif } // Reset control flags to known [empty] state, clearing error bits if (rxbd->ctrl & FCC_BD_Rx_Wrap) { rxbd->ctrl = FCC_BD_Rx_Empty | FCC_BD_Rx_Int | FCC_BD_Rx_Wrap; rxbd = qi->rbase; } else { rxbd->ctrl = FCC_BD_Rx_Empty | FCC_BD_Rx_Int; rxbd++; } } // Remember where we left off qi->rnext = (struct fcc_bd *)rxbd; // Make sure no stale data#ifndef FCC_BDs_NONCACHED if (cache_state) { HAL_DCACHE_FLUSH(fcc_eth_rxring, 8*CYGNUM_DEVS_ETH_POWERPC_FCC_RxNUM); }#endif}//// This function is called as a result of the "eth_drv_recv()" call above.// It's job is to actually fetch data for a packet from the hardware once// memory buffers have been allocated for the packet. Note that the buffers// may come in pieces, using a scatter-gather list. This allows for more// efficient processing in the upper layers of the stack.//static voidfcc_eth_recv(struct eth_drv_sc *sc, struct eth_drv_sg *sg_list, int sg_len){ struct fcc_eth_info *qi = (struct fcc_eth_info *)sc->driver_private; unsigned char *bp; int i; bp = (unsigned char *)qi->rxbd->buffer; for (i = 0; i < sg_len; i++) { if (sg_list[i].buf != 0) { memcpy((void *)sg_list[i].buf, bp, sg_list[i].len); bp += sg_list[i].len; } }}static voidfcc_eth_TxEvent(struct eth_drv_sc *sc, int stat){ struct fcc_eth_info *qi = (struct fcc_eth_info *)sc->driver_private; struct fcc_bd *txbd; int txindex;#ifndef FCC_BDs_NONCACHED int cache_state;#endif#ifndef FCC_BDs_NONCACHED // Make sure no stale data HAL_DCACHE_IS_ENABLED(cache_state); if (cache_state) { HAL_DCACHE_INVALIDATE(fcc_eth_txring, 8*CYGNUM_DEVS_ETH_POWERPC_FCC_TxNUM); }#endif txbd = qi->tnext; // Note: TC field is used to indicate the buffer has/had data in it while ( (txbd->ctrl & (FCC_BD_Tx_TC | FCC_BD_Tx_Ready)) == FCC_BD_Tx_TC ) { if ((txbd->ctrl & FCC_BD_Tx_ERRORS) != 0) {#if 0 diag_printf("FCC Tx error BD: %x/%x- ", txbd, txbd->ctrl); if ((txbd->ctrl & FCC_BD_Tx_LC) != 0) diag_printf("Late Collision/"); if ((txbd->ctrl & FCC_BD_Tx_RL) != 0) diag_printf("Retry limit/");// if ((txbd->ctrl & FCC_BD_Tx_RC) != 0) diag_printf("Late Collision/"); if ((txbd->ctrl & FCC_BD_Tx_UN) != 0) diag_printf("Underrun/"); if ((txbd->ctrl & FCC_BD_Tx_CSL) != 0) diag_printf("Carrier Lost/"); diag_printf("\n");#endif } txindex = ((unsigned long)txbd - (unsigned long)qi->tbase) / sizeof(*txbd); (sc->funs->eth_drv->tx_done)(sc, qi->txkey[txindex], 0); txbd->ctrl &= ~FCC_BD_Tx_TC; if (txbd->ctrl & FCC_BD_Tx_Wrap) { txbd = qi->tbase; } else { txbd++; } } // Remember where we left off qi->tnext = (struct fcc_bd *)txbd; // Make sure no stale data #ifndef FCC_BDs_NONCACHED if (cache_state) { HAL_DCACHE_FLUSH(fcc_eth_txring, 8*CYGNUM_DEVS_ETH_POWERPC_FCC_TxNUM); }#endif}//// Interrupt processing//static void fcc_eth_int(struct eth_drv_sc *sc){ struct fcc_eth_info *qi = (struct fcc_eth_info *)sc->driver_private; unsigned short iEvent; while ((iEvent = qi->fcc_reg->fcc_fcce) != 0){ // Clear pending interrupts (writing 1's to this register) qi->fcc_reg->fcc_fcce = iEvent; // Tx Done or Tx Error if ( iEvent & (FCC_EV_TXB | FCC_EV_TXE) ) { fcc_eth_TxEvent(sc, iEvent); } // Complete or non-complete frame receive if (iEvent & (FCC_EV_RXF | FCC_EV_RXB) ) { fcc_eth_RxEvent(sc); } }}//// Interrupt vector//static int fcc_eth_int_vector(struct eth_drv_sc *sc){ struct fcc_eth_info *qi = (struct fcc_eth_info *)sc->driver_private; return (qi->int_vector);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -