sb1250-mac.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 2,624 行 · 第 1/5 页
C
2,624 行
/* * Set the receive filter for no packets, and write values * to the various config registers */ SBMAC_WRITECSR(s->sbm_rxfilter,0); SBMAC_WRITECSR(s->sbm_imr,0); SBMAC_WRITECSR(s->sbm_framecfg,framecfg); SBMAC_WRITECSR(s->sbm_fifocfg,fifo); SBMAC_WRITECSR(s->sbm_maccfg,cfg); /* * Initialize DMA channels (rings should be ok now) */ sbdma_channel_start(&(s->sbm_rxdma), DMA_RX); sbdma_channel_start(&(s->sbm_txdma), DMA_TX); /* * Configure the speed, duplex, and flow control */ sbmac_set_speed(s,s->sbm_speed); sbmac_set_duplex(s,s->sbm_duplex,s->sbm_fc); /* * Fill the receive ring */ sbdma_fillring(&(s->sbm_rxdma)); /* * Turn on the rest of the bits in the enable register */ SBMAC_WRITECSR(s->sbm_macenable, M_MAC_RXDMA_EN0 | M_MAC_TXDMA_EN0 | M_MAC_RX_ENABLE | M_MAC_TX_ENABLE); #ifdef CONFIG_SBMAC_COALESCE /* * Accept any TX interrupt and EOP count/timer RX interrupts on ch 0 */ SBMAC_WRITECSR(s->sbm_imr, ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) | ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0));#else /* * Accept any kind of interrupt on TX and RX DMA channel 0 */ SBMAC_WRITECSR(s->sbm_imr, (M_MAC_INT_CHANNEL << S_MAC_TX_CH0) | (M_MAC_INT_CHANNEL << S_MAC_RX_CH0));#endif /* * Enable receiving unicasts and broadcasts */ SBMAC_WRITECSR(s->sbm_rxfilter,M_MAC_UCAST_EN | M_MAC_BCAST_EN); /* * we're running now. */ s->sbm_state = sbmac_state_on; /* * Program multicast addresses */ sbmac_setmulti(s); /* * If channel was in promiscuous mode before, turn that on */ if (s->sbm_devflags & IFF_PROMISC) { sbmac_promiscuous_mode(s,1); } }/********************************************************************** * SBMAC_CHANNEL_STOP(s) * * Stop packet processing on this MAC. * * Input parameters: * s - sbmac structure * * Return value: * nothing ********************************************************************* */static void sbmac_channel_stop(struct sbmac_softc *s){ /* don't do this if already stopped */ if (s->sbm_state == sbmac_state_off) return; /* don't accept any packets, disable all interrupts */ SBMAC_WRITECSR(s->sbm_rxfilter,0); SBMAC_WRITECSR(s->sbm_imr,0); /* Turn off ticker */ /* XXX */ /* turn off receiver and transmitter */ SBMAC_WRITECSR(s->sbm_macenable,0); /* We're stopped now. */ s->sbm_state = sbmac_state_off; /* * Stop DMA channels (rings should be ok now) */ sbdma_channel_stop(&(s->sbm_rxdma)); sbdma_channel_stop(&(s->sbm_txdma)); /* Empty the receive and transmit rings */ sbdma_emptyring(&(s->sbm_rxdma)); sbdma_emptyring(&(s->sbm_txdma)); }/********************************************************************** * SBMAC_SET_CHANNEL_STATE(state) * * Set the channel's state ON or OFF * * Input parameters: * state - new state * * Return value: * old state ********************************************************************* */static sbmac_state_t sbmac_set_channel_state(struct sbmac_softc *sc, sbmac_state_t state){ sbmac_state_t oldstate = sc->sbm_state; /* * If same as previous state, return */ if (state == oldstate) { return oldstate; } /* * If new state is ON, turn channel on */ if (state == sbmac_state_on) { sbmac_channel_start(sc); } else { sbmac_channel_stop(sc); } /* * Return previous state */ return oldstate;}/********************************************************************** * SBMAC_PROMISCUOUS_MODE(sc,onoff) * * Turn on or off promiscuous mode * * Input parameters: * sc - softc * onoff - 1 to turn on, 0 to turn off * * Return value: * nothing ********************************************************************* */static void sbmac_promiscuous_mode(struct sbmac_softc *sc,int onoff){ uint64_t reg; if (sc->sbm_state != sbmac_state_on) return; if (onoff) { reg = SBMAC_READCSR(sc->sbm_rxfilter); reg |= M_MAC_ALLPKT_EN; SBMAC_WRITECSR(sc->sbm_rxfilter,reg); } else { reg = SBMAC_READCSR(sc->sbm_rxfilter); reg &= ~M_MAC_ALLPKT_EN; SBMAC_WRITECSR(sc->sbm_rxfilter,reg); }}/********************************************************************** * SBMAC_SETIPHDR_OFFSET(sc,onoff) * * Set the iphdr offset as 15 assuming ethernet encapsulation * * Input parameters: * sc - softc * * Return value: * nothing ********************************************************************* */static void sbmac_set_iphdr_offset(struct sbmac_softc *sc){ uint64_t reg; /* Hard code the off set to 15 for now */ reg = SBMAC_READCSR(sc->sbm_rxfilter); reg &= ~M_MAC_IPHDR_OFFSET | V_MAC_IPHDR_OFFSET(15); SBMAC_WRITECSR(sc->sbm_rxfilter,reg); /* read system identification to determine revision */ if (periph_rev >= 2) { printk(KERN_INFO "%s: enabling TCP rcv checksum\n", sc->sbm_dev->name); sc->rx_hw_checksum = ENABLE; } else { sc->rx_hw_checksum = DISABLE; }}/********************************************************************** * SBMAC_ADDR2REG(ptr) * * Convert six bytes into the 64-bit register value that * we typically write into the SBMAC's address/mcast registers * * Input parameters: * ptr - pointer to 6 bytes * * Return value: * register value ********************************************************************* */static uint64_t sbmac_addr2reg(unsigned char *ptr){ uint64_t reg = 0; ptr += 6; reg |= (uint64_t) *(--ptr); reg <<= 8; reg |= (uint64_t) *(--ptr); reg <<= 8; reg |= (uint64_t) *(--ptr); reg <<= 8; reg |= (uint64_t) *(--ptr); reg <<= 8; reg |= (uint64_t) *(--ptr); reg <<= 8; reg |= (uint64_t) *(--ptr); return reg;}/********************************************************************** * SBMAC_SET_SPEED(s,speed) * * Configure LAN speed for the specified MAC. * Warning: must be called when MAC is off! * * Input parameters: * s - sbmac structure * speed - speed to set MAC to (see sbmac_speed_t enum) * * Return value: * 1 if successful * 0 indicates invalid parameters ********************************************************************* */static int sbmac_set_speed(struct sbmac_softc *s,sbmac_speed_t speed){ uint64_t cfg; uint64_t framecfg; /* * Save new current values */ s->sbm_speed = speed; if (s->sbm_state == sbmac_state_on) return 0; /* save for next restart */ /* * Read current register values */ cfg = SBMAC_READCSR(s->sbm_maccfg); framecfg = SBMAC_READCSR(s->sbm_framecfg); /* * Mask out the stuff we want to change */ cfg &= ~(M_MAC_BURST_EN | M_MAC_SPEED_SEL); framecfg &= ~(M_MAC_IFG_RX | M_MAC_IFG_TX | M_MAC_IFG_THRSH | M_MAC_SLOT_SIZE); /* * Now add in the new bits */ switch (speed) { case sbmac_speed_10: framecfg |= V_MAC_IFG_RX_10 | V_MAC_IFG_TX_10 | K_MAC_IFG_THRSH_10 | V_MAC_SLOT_SIZE_10; cfg |= V_MAC_SPEED_SEL_10MBPS; break; case sbmac_speed_100: framecfg |= V_MAC_IFG_RX_100 | V_MAC_IFG_TX_100 | V_MAC_IFG_THRSH_100 | V_MAC_SLOT_SIZE_100; cfg |= V_MAC_SPEED_SEL_100MBPS ; break; case sbmac_speed_1000: framecfg |= V_MAC_IFG_RX_1000 | V_MAC_IFG_TX_1000 | V_MAC_IFG_THRSH_1000 | V_MAC_SLOT_SIZE_1000; cfg |= V_MAC_SPEED_SEL_1000MBPS | M_MAC_BURST_EN; break; case sbmac_speed_auto: /* XXX not implemented */ /* fall through */ default: return 0; } /* * Send the bits back to the hardware */ SBMAC_WRITECSR(s->sbm_framecfg,framecfg); SBMAC_WRITECSR(s->sbm_maccfg,cfg); return 1;}/********************************************************************** * SBMAC_SET_DUPLEX(s,duplex,fc) * * Set Ethernet duplex and flow control options for this MAC * Warning: must be called when MAC is off! * * Input parameters: * s - sbmac structure * duplex - duplex setting (see sbmac_duplex_t) * fc - flow control setting (see sbmac_fc_t) * * Return value: * 1 if ok * 0 if an invalid parameter combination was specified ********************************************************************* */static int sbmac_set_duplex(struct sbmac_softc *s,sbmac_duplex_t duplex,sbmac_fc_t fc){ uint64_t cfg; /* * Save new current values */ s->sbm_duplex = duplex; s->sbm_fc = fc; if (s->sbm_state == sbmac_state_on) return 0; /* save for next restart */ /* * Read current register values */ cfg = SBMAC_READCSR(s->sbm_maccfg); /* * Mask off the stuff we're about to change */ cfg &= ~(M_MAC_FC_SEL | M_MAC_FC_CMD | M_MAC_HDX_EN); switch (duplex) { case sbmac_duplex_half: switch (fc) { case sbmac_fc_disabled: cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_DISABLED; break; case sbmac_fc_collision: cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENABLED; break; case sbmac_fc_carrier: cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENAB_FALSECARR; break; case sbmac_fc_auto: /* XXX not implemented */ /* fall through */ case sbmac_fc_frame: /* not valid in half duplex */ default: /* invalid selection */ return 0; } break; case sbmac_duplex_full: switch (fc) { case sbmac_fc_disabled: cfg |= V_MAC_FC_CMD_DISABLED; break; case sbmac_fc_frame: cfg |= V_MAC_FC_CMD_ENABLED; break; case sbmac_fc_collision: /* not valid in full duplex */ case sbmac_fc_carrier: /* not valid in full duplex */ case sbmac_fc_auto: /* XXX not implemented */ /* fall through */ default: return 0; } break; case sbmac_duplex_auto: /* XXX not implemented */ break; } /* * Send the bits back to the hardware */ SBMAC_WRITECSR(s->sbm_maccfg,cfg); return 1;}/********************************************************************** * SBMAC_INTR() * * Interrupt handler for MAC interrupts * * Input parameters: * MAC structure * * Return value: * nothing ********************************************************************* */static irqreturn_t sbmac_intr(int irq,void *dev_instance,struct pt_regs *rgs){ struct net_device *dev = (struct net_device *) dev_instance; struct sbmac_softc *sc = netdev_priv(dev); uint64_t isr; int handled = 0; for (;;) { /* * Read the ISR (this clears the bits in the real * register, except for counter addr) */ isr = SBMAC_READCSR(sc->sbm_isr) & ~M_MAC_COUNTER_ADDR; if (isr == 0) break; handled = 1; /* * Transmits on channel 0 */ if (isr & (M_MAC_INT_CHANNEL << S_MAC_TX_CH0)) { sbdma_tx_process(sc,&(sc->sbm_txdma)); } /* * Receives on channel 0 */ /* * It's important to test all the bits (or at least the * EOP_SEEN bit) when deciding to do the RX process * particularly when coalescing, to make sure we * take care of the following: * * If you have some packets waiting (have been received * but no interrupt) and get a TX interrupt before * the RX timer or counter expires, reading the ISR
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?