📄 cs89x0.c
字号:
#endif ); netif_start_queue(dev); if (net_debug > 1) printk("cs89x0: net_open() succeeded\n"); return 0;bad_out: return ret;}static void net_timeout(struct net_device *dev){ /* If we get here, some higher level has decided we are broken. There should really be a "kick me" function call instead. */ if (net_debug > 0) printk("%s: transmit timed out, %s?\n", dev->name, tx_done(dev) ? "IRQ conflict ?" : "network cable problem"); /* Try to restart the adaptor. */ netif_wake_queue(dev);}static int net_send_packet(struct sk_buff *skb, struct net_device *dev){ struct net_local *lp = netdev_priv(dev); if (net_debug > 3) { printk("%s: sent %d byte packet of type %x\n", dev->name, skb->len, (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]); } /* keep the upload from being interrupted, since we ask the chip to start transmitting before the whole packet has been completely uploaded. */ spin_lock_irq(&lp->lock); netif_stop_queue(dev); /* initiate a transmit sequence */ writeword(dev->base_addr, TX_CMD_PORT, lp->send_cmd); writeword(dev->base_addr, TX_LEN_PORT, skb->len); /* Test to see if the chip has allocated memory for the packet */ if ((readreg(dev, PP_BusST) & READY_FOR_TX_NOW) == 0) { /* * Gasp! It hasn't. But that shouldn't happen since * we're waiting for TxOk, so return 1 and requeue this packet. */ spin_unlock_irq(&lp->lock); if (net_debug) printk("cs89x0: Tx buffer not free!\n"); return 1; } /* Write the contents of the packet */ writewords(dev->base_addr, TX_FRAME_PORT,skb->data,(skb->len+1) >>1); spin_unlock_irq(&lp->lock); lp->stats.tx_bytes += skb->len; dev->trans_start = jiffies; dev_kfree_skb (skb); /* * We DO NOT call netif_wake_queue() here. * We also DO NOT call netif_start_queue(). * * Either of these would cause another bottom half run through * net_send_packet() before this packet has fully gone out. That causes * us to hit the "Gasp!" above and the send is rescheduled. it runs like * a dog. We just return and wait for the Tx completion interrupt handler * to restart the netdevice layer */ return 0;}/* The typical workload of the driver: Handle the network interface interrupts. */ static irqreturn_t net_interrupt(int irq, void *dev_id, struct pt_regs * regs){ struct net_device *dev = dev_id; struct net_local *lp; int ioaddr, status; int handled = 0; ioaddr = dev->base_addr; lp = netdev_priv(dev); /* we MUST read all the events out of the ISQ, otherwise we'll never get interrupted again. As a consequence, we can't have any limit on the number of times we loop in the interrupt handler. The hardware guarantees that eventually we'll run out of events. Of course, if you're on a slow machine, and packets are arriving faster than you can read them off, you're screwed. Hasta la vista, baby! */ while ((status = readword(dev->base_addr, ISQ_PORT))) { if (net_debug > 4)printk("%s: event=%04x\n", dev->name, status); handled = 1; switch(status & ISQ_EVENT_MASK) { case ISQ_RECEIVER_EVENT: /* Got a packet(s). */ net_rx(dev); break; case ISQ_TRANSMITTER_EVENT: lp->stats.tx_packets++; netif_wake_queue(dev); /* Inform upper layers. */ if ((status & ( TX_OK | TX_LOST_CRS | TX_SQE_ERROR | TX_LATE_COL | TX_16_COL)) != TX_OK) { if ((status & TX_OK) == 0) lp->stats.tx_errors++; if (status & TX_LOST_CRS) lp->stats.tx_carrier_errors++; if (status & TX_SQE_ERROR) lp->stats.tx_heartbeat_errors++; if (status & TX_LATE_COL) lp->stats.tx_window_errors++; if (status & TX_16_COL) lp->stats.tx_aborted_errors++; } break; case ISQ_BUFFER_EVENT: if (status & READY_FOR_TX) { /* we tried to transmit a packet earlier, but inexplicably ran out of buffers. That shouldn't happen since we only ever load one packet. Shrug. Do the right thing anyway. */ netif_wake_queue(dev); /* Inform upper layers. */ } if (status & TX_UNDERRUN) { if (net_debug > 0) printk("%s: transmit underrun\n", dev->name); lp->send_underrun++; if (lp->send_underrun == 3) lp->send_cmd = TX_AFTER_381; else if (lp->send_underrun == 6) lp->send_cmd = TX_AFTER_ALL; /* transmit cycle is done, although frame wasn't transmitted - this avoids having to wait for the upper layers to timeout on us, in the event of a tx underrun */ netif_wake_queue(dev); /* Inform upper layers. */ }#if ALLOW_DMA if (lp->use_dma && (status & RX_DMA)) { int count = readreg(dev, PP_DmaFrameCnt); while(count) { if (net_debug > 5) printk("%s: receiving %d DMA frames\n", dev->name, count); if (net_debug > 2 && count >1) printk("%s: receiving %d DMA frames\n", dev->name, count); dma_rx(dev); if (--count == 0) count = readreg(dev, PP_DmaFrameCnt); if (net_debug > 2 && count > 0) printk("%s: continuing with %d DMA frames\n", dev->name, count); } }#endif break; case ISQ_RX_MISS_EVENT: lp->stats.rx_missed_errors += (status >>6); break; case ISQ_TX_COL_EVENT: lp->stats.collisions += (status >>6); break; } } return IRQ_RETVAL(handled);}static voidcount_rx_errors(int status, struct net_local *lp){ lp->stats.rx_errors++; if (status & RX_RUNT) lp->stats.rx_length_errors++; if (status & RX_EXTRA_DATA) lp->stats.rx_length_errors++; if (status & RX_CRC_ERROR) if (!(status & (RX_EXTRA_DATA|RX_RUNT))) /* per str 172 */ lp->stats.rx_crc_errors++; if (status & RX_DRIBBLE) lp->stats.rx_frame_errors++; return;}/* We have a good packet(s), get it/them out of the buffers. */static voidnet_rx(struct net_device *dev){ struct net_local *lp = netdev_priv(dev); struct sk_buff *skb; int status, length; int ioaddr = dev->base_addr; status = readword(ioaddr, RX_FRAME_PORT); length = readword(ioaddr, RX_FRAME_PORT); if ((status & RX_OK) == 0) { count_rx_errors(status, lp); return; } /* Malloc up new buffer. */ skb = dev_alloc_skb(length + 2); if (skb == NULL) {#if 0 /* Again, this seems a cruel thing to do */ printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);#endif lp->stats.rx_dropped++; return; } skb_reserve(skb, 2); /* longword align L3 header */ skb->dev = dev; readwords(ioaddr, RX_FRAME_PORT, skb_put(skb, length), length >> 1); if (length & 1) skb->data[length-1] = readword(ioaddr, RX_FRAME_PORT); if (net_debug > 3) { printk( "%s: received %d byte packet of type %x\n", dev->name, length, (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]); } skb->protocol=eth_type_trans(skb,dev); netif_rx(skb); dev->last_rx = jiffies; lp->stats.rx_packets++; lp->stats.rx_bytes += length;}#if ALLOW_DMAstatic void release_dma_buff(struct net_local *lp){ if (lp->dma_buff) { free_pages((unsigned long)(lp->dma_buff), get_order(lp->dmasize * 1024)); lp->dma_buff = NULL; }}#endif/* The inverse routine to net_open(). */static intnet_close(struct net_device *dev){#if ALLOW_DMA struct net_local *lp = netdev_priv(dev);#endif netif_stop_queue(dev); writereg(dev, PP_RxCFG, 0); writereg(dev, PP_TxCFG, 0); writereg(dev, PP_BufCFG, 0); writereg(dev, PP_BusCTL, 0); free_irq(dev->irq, dev);#if ALLOW_DMA if (lp->use_dma && lp->dma) { free_dma(dev->dma); release_dma_buff(lp); }#endif /* Update the statistics here. */ return 0;}/* Get the current statistics. This may be called with the card open or closed. */static struct net_device_stats *net_get_stats(struct net_device *dev){ struct net_local *lp = netdev_priv(dev); unsigned long flags; spin_lock_irqsave(&lp->lock, flags); /* Update the statistics from the device registers. */ lp->stats.rx_missed_errors += (readreg(dev, PP_RxMiss) >> 6); lp->stats.collisions += (readreg(dev, PP_TxCol) >> 6); spin_unlock_irqrestore(&lp->lock, flags); return &lp->stats;}static void set_multicast_list(struct net_device *dev){ struct net_local *lp = netdev_priv(dev); unsigned long flags; spin_lock_irqsave(&lp->lock, flags); if(dev->flags&IFF_PROMISC) { lp->rx_mode = RX_ALL_ACCEPT; } else if((dev->flags&IFF_ALLMULTI)||dev->mc_list) { /* The multicast-accept list is initialized to accept-all, and we rely on higher-level filtering for now. */ lp->rx_mode = RX_MULTCAST_ACCEPT; } else lp->rx_mode = 0; writereg(dev, PP_RxCTL, DEF_RX_ACCEPT | lp->rx_mode); /* in promiscuous mode, we accept errored packets, so we have to enable interrupts on them also */ writereg(dev, PP_RxCFG, lp->curr_rx_cfg | (lp->rx_mode == RX_ALL_ACCEPT? (RX_CRC_ERROR_ENBL|RX_RUNT_ENBL|RX_EXTRA_DATA_ENBL) : 0)); spin_unlock_irqrestore(&lp->lock, flags);}static int set_mac_address(struct net_device *dev, void *p){ int i; struct sockaddr *addr = p; if (netif_running(dev)) return -EBUSY; memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); if (net_debug) { printk("%s: Setting MAC address to ", dev->name); for (i = 0; i < dev->addr_len; i++) printk(" %2.2x", dev->dev_addr[i]); printk(".\n"); } /* set the Ethernet address */ for (i=0; i < ETH_ALEN/2; i++) writereg(dev, PP_IA+i*2, dev->dev_addr[i*2] | (dev->dev_addr[i*2+1] << 8)); return 0;}#ifdef MODULEstatic struct net_device *dev_cs89x0;/* * Support the 'debug' module parm even if we're compiled for non-debug to * avoid breaking someone's startup scripts */static int io;static int irq;static int debug;static char media[8];static int duplex=-1;static int use_dma; /* These generate unused var warnings if ALLOW_DMA = 0 */static int dma;static int dmasize=16; /* or 64 */module_param(io, int, 0);module_param(irq, int, 0);module_param(debug, int, 0);module_param_string(media, media, sizeof(media), 0);module_param(duplex, int, 0);module_param(dma , int, 0);module_param(dmasize , int, 0);module_param(use_dma , int, 0);MODULE_PARM_DESC(io, "cs89x0 I/O base address");MODULE_PARM_DESC(irq, "cs89x0 IRQ number");#if DEBUGGINGMODULE_PARM_DESC(debug, "cs89x0 debug level (0-6)");#elseMODULE_PARM_DESC(debug, "(ignored)");#endifMODULE_PARM_DESC(media, "Set cs89x0 adapter(s) media type(s) (rj45,bnc,aui)");/* No other value than -1 for duplex seems to be currently interpreted */MODULE_PARM_DESC(duplex, "(ignored)");#if ALLOW_DMAMODULE_PARM_DESC(dma , "cs89x0 ISA DMA channel; ignored if use_dma=0");MODULE_PARM_DESC(dmasize , "cs89x0 DMA size in kB (16,64); ignored if use_dma=0");MODULE_PARM_DESC(use_dma , "cs89x0 using DMA (0-1)");#elseMODULE_PARM_DESC(dma , "(ignored)");MODULE_PARM_DESC(dmasize , "(ignored)");MODULE_PARM_DESC(use_dma , "(ignored)");#endifMODULE_AUTHOR("Mike Cruse, Russwll Nelson <nelson@crynwr.com>, Andrew Morton <andrewm@uow.edu.au>");MODULE_LICENSE("GPL");/** media=t - specify media type or media=2 or media=aui or medai=auto* duplex=0 - specify forced half/full/autonegotiate duplex* debug=# - debug level* Default Chip Configuration: * DMA Burst = enabled * IOCHRDY Enabled = enabled * UseSA = enabled * CS8900 defaults to half-duplex if not specified on command-line * CS8920 defaults to autoneg if not specified on command-line * Use reset defaults for other config parameters* Assumptions: * media type specified is supported (circuitry is present) * if memory address is > 1MB, then required mem decode hw is present * if 10B-2, then agent other than driver will enable DC/DC converter (hw or software util)*/intinit_module(void){ struct net_device *dev = alloc_etherdev(sizeof(struct net_local)); struct net_local *lp; int ret = 0;#if DEBUGGING net_debug = debug;#else debug = 0;#endif if (!dev) return -ENOMEM; dev->irq = irq; dev->base_addr = io; lp = netdev_priv(dev);#if ALLOW_DMA if (use_dma) { lp->use_dma = use_dma; lp->dma = dma; lp->dmasize = dmasize; }#endif spin_lock_init(&lp->lock); /* boy, they'd better get these right */ if (!strcmp(media, "rj45")) lp->adapter_cnf = A_CNF_MEDIA_10B_T | A_CNF_10B_T; else if (!strcmp(media, "aui")) lp->adapter_cnf = A_CNF_MEDIA_AUI | A_CNF_AUI; else if (!strcmp(media, "bnc")) lp->adapter_cnf = A_CNF_MEDIA_10B_2 | A_CNF_10B_2; else lp->adapter_cnf = A_CNF_MEDIA_10B_T | A_CNF_10B_T; if (duplex==-1) lp->auto_neg_cnf = AUTO_NEG_ENABLE; if (io == 0) { printk(KERN_ERR "cs89x0.c: Module autoprobing not allowed.\n"); printk(KERN_ERR "cs89x0.c: Append io=0xNNN\n"); ret = -EPERM; goto out; } else if (io <= 0x1ff) { ret = -ENXIO; goto out; }#if ALLOW_DMA if (use_dma && dmasize != 16 && dmasize != 64) { printk(KERN_ERR "cs89x0.c: dma size must be either 16K or 64K, not %dK\n", dmasize); ret = -EPERM; goto out; }#endif ret = cs89x0_probe1(dev, io, 1); if (ret) goto out; dev_cs89x0 = dev; return 0;out: free_netdev(dev); return ret;}voidcleanup_module(void){ unregister_netdev(dev_cs89x0); writeword(dev_cs89x0->base_addr, ADD_PORT, PP_ChipID); release_region(dev_cs89x0->base_addr, NETCARD_IO_EXTENT); free_netdev(dev_cs89x0);}#endif /* MODULE *//* * Local variables: * version-control: t * kept-new-versions: 5 * c-indent-level: 8 * tab-width: 8 * End: * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -