?? winbond-840.c
字號:
/* winbond-840.c: A Linux PCI network adapter device driver. *//* Written 1998-2001 by Donald Becker. This software may be used and distributed according to the terms of the GNU General Public License (GPL), incorporated herein by reference. Drivers based on or derived from this code fall under the GPL and must retain the authorship, copyright and license notice. This file is not a complete program and may only be used when the entire operating system is licensed under the GPL. The author may be reached as becker@scyld.com, or C/O Scyld Computing Corporation 410 Severn Ave., Suite 210 Annapolis MD 21403 Support and updates available at http://www.scyld.com/network/drivers.html Do not remove the copyright information. Do not change the version information unless an improvement has been made. Merely removing my name, as Compex has done in the past, does not count as an improvement. Changelog: * ported to 2.4 ??? * spin lock update, memory barriers, new style dma mappings limit each tx buffer to < 1024 bytes remove DescIntr from Rx descriptors (that's an Tx flag) remove next pointer from Tx descriptors synchronize tx_q_bytes software reset in tx_timeout Copyright (C) 2000 Manfred Spraul * further cleanups power management. support for big endian descriptors Copyright (C) 2001 Manfred Spraul * ethtool support (jgarzik) * Replace some MII-related magic numbers with constants (jgarzik) TODO: * enable pci_power_off * Wake-On-LAN*/ #define DRV_NAME "winbond-840"#define DRV_VERSION "1.01-d"#define DRV_RELDATE "Nov-17-2001"/* Automatically extracted configuration info:probe-func: winbond840_probeconfig-in: tristate 'Winbond W89c840 Ethernet support' CONFIG_WINBOND_840c-help-name: Winbond W89c840 PCI Ethernet supportc-help-symbol: CONFIG_WINBOND_840c-help: This driver is for the Winbond W89c840 chip. It also works withc-help: the TX9882 chip on the Compex RL100-ATX board.c-help: More specific information and updates are available from c-help: http://www.scyld.com/network/drivers.html*//* The user-configurable values. These may be modified when a driver module is loaded.*/static int debug = 1; /* 1 normal messages, 0 quiet .. 7 verbose. */static int max_interrupt_work = 20;/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). The '840 uses a 64 element hash table based on the Ethernet CRC. */static int multicast_filter_limit = 32;/* Set the copy breakpoint for the copy-only-tiny-frames scheme. Setting to > 1518 effectively disables this feature. */static int rx_copybreak;/* Used to pass the media type, etc. Both 'options[]' and 'full_duplex[]' should exist for driver interoperability. The media type is usually passed in 'options[]'.*/#define MAX_UNITS 8 /* More are supported, limit only on options */static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};/* Operational parameters that are set at compile time. *//* Keep the ring sizes a power of two for compile efficiency. The compiler will convert <unsigned>'%'<2^N> into a bit mask. Making the Tx ring too large decreases the effectiveness of channel bonding and packet priority. There are no ill effects from too-large receive rings. */#define TX_RING_SIZE 16#define TX_QUEUE_LEN 10 /* Limit ring entries actually used. */#define TX_QUEUE_LEN_RESTART 5#define RX_RING_SIZE 32#define TX_BUFLIMIT (1024-128)/* The presumed FIFO size for working around the Tx-FIFO-overflow bug. To avoid overflowing we don't queue again until we have room for a full-size packet. */#define TX_FIFO_SIZE (2048)#define TX_BUG_FIFO_LIMIT (TX_FIFO_SIZE-1514-16)/* Operational parameters that usually are not changed. *//* Time in jiffies before concluding the transmitter is hung. */#define TX_TIMEOUT (2*HZ)#define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*//* Include files, designed to support most kernel versions 2.0.0 and later. */#include <linux/module.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/errno.h>#include <linux/ioport.h>#include <linux/slab.h>#include <linux/interrupt.h>#include <linux/pci.h>#include <linux/dma-mapping.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/init.h>#include <linux/delay.h>#include <linux/ethtool.h>#include <linux/mii.h>#include <linux/rtnetlink.h>#include <linux/crc32.h>#include <linux/bitops.h>#include <asm/uaccess.h>#include <asm/processor.h> /* Processor type for cache alignment. */#include <asm/io.h>#include <asm/irq.h>/* These identify the driver base version and may not be removed. */static char version[] __devinitdata =KERN_INFO DRV_NAME ".c:v" DRV_VERSION " (2.4 port) " DRV_RELDATE " Donald Becker <becker@scyld.com>\n"KERN_INFO " http://www.scyld.com/network/drivers.html\n";MODULE_AUTHOR("Donald Becker <becker@scyld.com>");MODULE_DESCRIPTION("Winbond W89c840 Ethernet driver");MODULE_LICENSE("GPL");MODULE_VERSION(DRV_VERSION);module_param(max_interrupt_work, int, 0);module_param(debug, int, 0);module_param(rx_copybreak, int, 0);module_param(multicast_filter_limit, int, 0);module_param_array(options, int, NULL, 0);module_param_array(full_duplex, int, NULL, 0);MODULE_PARM_DESC(max_interrupt_work, "winbond-840 maximum events handled per interrupt");MODULE_PARM_DESC(debug, "winbond-840 debug level (0-6)");MODULE_PARM_DESC(rx_copybreak, "winbond-840 copy breakpoint for copy-only-tiny-frames");MODULE_PARM_DESC(multicast_filter_limit, "winbond-840 maximum number of filtered multicast addresses");MODULE_PARM_DESC(options, "winbond-840: Bits 0-3: media type, bit 17: full duplex");MODULE_PARM_DESC(full_duplex, "winbond-840 full duplex setting(s) (1)");/* Theory of OperationI. Board CompatibilityThis driver is for the Winbond w89c840 chip.II. Board-specific settingsNone.III. Driver operationThis chip is very similar to the Digital 21*4* "Tulip" family. The firsttwelve registers and the descriptor format are nearly identical. Read aTulip manual for operational details.A significant difference is that the multicast filter and station address arestored in registers rather than loaded through a pseudo-transmit packet.Unlike the Tulip, transmit buffers are limited to 1KB. To transmit afull-sized packet we must use both data buffers in a descriptor. Thus thedriver uses ring mode where descriptors are implicitly sequential in memory,rather than using the second descriptor address as a chain pointer tosubsequent descriptors.IV. NotesIf you are going to almost clone a Tulip, why not go all the way and avoidthe need for a new driver?IVb. Referenceshttp://www.scyld.com/expert/100mbps.htmlhttp://www.scyld.com/expert/NWay.htmlhttp://www.winbond.com.tw/IVc. ErrataA horrible bug exists in the transmit FIFO. Apparently the chip doesn'tcorrectly detect a full FIFO, and queuing more than 2048 bytes may result insilent data corruption.Test with 'ping -s 10000' on a fast computer.*//* PCI probe table.*/enum pci_id_flags_bits { /* Set PCI command register bits before calling probe1(). */ PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4, /* Read and map the single following PCI BAR. */ PCI_ADDR0=0<<4, PCI_ADDR1=1<<4, PCI_ADDR2=2<<4, PCI_ADDR3=3<<4, PCI_ADDR_64BITS=0x100, PCI_NO_ACPI_WAKE=0x200, PCI_NO_MIN_LATENCY=0x400,};enum chip_capability_flags { CanHaveMII=1, HasBrokenTx=2, AlwaysFDX=4, FDXOnNoMII=8,};#ifdef USE_IO_OPS#define W840_FLAGS (PCI_USES_IO | PCI_ADDR0 | PCI_USES_MASTER)#else#define W840_FLAGS (PCI_USES_MEM | PCI_ADDR1 | PCI_USES_MASTER)#endifstatic struct pci_device_id w840_pci_tbl[] = { { 0x1050, 0x0840, PCI_ANY_ID, 0x8153, 0, 0, 0 }, { 0x1050, 0x0840, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, { 0x11f6, 0x2011, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 }, { 0, }};MODULE_DEVICE_TABLE(pci, w840_pci_tbl);struct pci_id_info { const char *name; struct match_info { int pci, pci_mask, subsystem, subsystem_mask; int revision, revision_mask; /* Only 8 bits. */ } id; enum pci_id_flags_bits pci_flags; int io_size; /* Needed for I/O region check or ioremap(). */ int drv_flags; /* Driver use, intended as capability flags. */};static struct pci_id_info pci_id_tbl[] = { {"Winbond W89c840", /* Sometime a Level-One switch card. */ { 0x08401050, 0xffffffff, 0x81530000, 0xffff0000 }, W840_FLAGS, 128, CanHaveMII | HasBrokenTx | FDXOnNoMII}, {"Winbond W89c840", { 0x08401050, 0xffffffff, }, W840_FLAGS, 128, CanHaveMII | HasBrokenTx}, {"Compex RL100-ATX", { 0x201111F6, 0xffffffff,}, W840_FLAGS, 128, CanHaveMII | HasBrokenTx}, {NULL,}, /* 0 terminated list. */};/* This driver was written to use PCI memory space, however some x86 systems work only with I/O space accesses. Pass -DUSE_IO_OPS to use PCI I/O space accesses instead of memory space. *//* Offsets to the Command and Status Registers, "CSRs". While similar to the Tulip, these registers are longword aligned. Note: It's not useful to define symbolic names for every register bit in the device. The name can only partially document the semantics and make the driver longer and more difficult to read.*/enum w840_offsets { PCIBusCfg=0x00, TxStartDemand=0x04, RxStartDemand=0x08, RxRingPtr=0x0C, TxRingPtr=0x10, IntrStatus=0x14, NetworkConfig=0x18, IntrEnable=0x1C, RxMissed=0x20, EECtrl=0x24, MIICtrl=0x24, BootRom=0x28, GPTimer=0x2C, CurRxDescAddr=0x30, CurRxBufAddr=0x34, /* Debug use */ MulticastFilter0=0x38, MulticastFilter1=0x3C, StationAddr=0x40, CurTxDescAddr=0x4C, CurTxBufAddr=0x50,};/* Bits in the interrupt status/enable registers. *//* The bits in the Intr Status/Enable registers, mostly interrupt sources. */enum intr_status_bits { NormalIntr=0x10000, AbnormalIntr=0x8000, IntrPCIErr=0x2000, TimerInt=0x800, IntrRxDied=0x100, RxNoBuf=0x80, IntrRxDone=0x40, TxFIFOUnderflow=0x20, RxErrIntr=0x10, TxIdle=0x04, IntrTxStopped=0x02, IntrTxDone=0x01,};/* Bits in the NetworkConfig register. */enum rx_mode_bits { AcceptErr=0x80, AcceptRunt=0x40, AcceptBroadcast=0x20, AcceptMulticast=0x10, AcceptAllPhys=0x08, AcceptMyPhys=0x02,};enum mii_reg_bits { MDIO_ShiftClk=0x10000, MDIO_DataIn=0x80000, MDIO_DataOut=0x20000, MDIO_EnbOutput=0x40000, MDIO_EnbIn = 0x00000,};/* The Tulip Rx and Tx buffer descriptors. */struct w840_rx_desc { s32 status; s32 length; u32 buffer1; u32 buffer2;};struct w840_tx_desc { s32 status; s32 length; u32 buffer1, buffer2;};/* Bits in network_desc.status */enum desc_status_bits { DescOwn=0x80000000, DescEndRing=0x02000000, DescUseLink=0x01000000, DescWholePkt=0x60000000, DescStartPkt=0x20000000, DescEndPkt=0x40000000, DescIntr=0x80000000,};#define MII_CNT 1 /* winbond only supports one MII */struct netdev_private { struct w840_rx_desc *rx_ring; dma_addr_t rx_addr[RX_RING_SIZE]; struct w840_tx_desc *tx_ring; dma_addr_t tx_addr[TX_RING_SIZE]; dma_addr_t ring_dma_addr; /* The addresses of receive-in-place skbuffs. */ struct sk_buff* rx_skbuff[RX_RING_SIZE]; /* The saved address of a sent-in-place packet/buffer, for later free(). */ struct sk_buff* tx_skbuff[TX_RING_SIZE]; struct net_device_stats stats; struct timer_list timer; /* Media monitoring timer. */ /* Frequently used values: keep some adjacent for cache effect. */ spinlock_t lock; int chip_id, drv_flags; struct pci_dev *pci_dev; int csr6; struct w840_rx_desc *rx_head_desc; unsigned int cur_rx, dirty_rx; /* Producer/consumer ring indices */ unsigned int rx_buf_sz; /* Based on MTU+slack. */ unsigned int cur_tx, dirty_tx; unsigned int tx_q_bytes; unsigned int tx_full; /* The Tx queue is full. */ /* MII transceiver section. */ int mii_cnt; /* MII device addresses. */ unsigned char phys[MII_CNT]; /* MII device addresses, but only the first is used */ u32 mii; struct mii_if_info mii_if; void __iomem *base_addr;};static int eeprom_read(void __iomem *ioaddr, int location);static int mdio_read(struct net_device *dev, int phy_id, int location);static void mdio_write(struct net_device *dev, int phy_id, int location, int value);static int netdev_open(struct net_device *dev);static int update_link(struct net_device *dev);static void netdev_timer(unsigned long data);static void init_rxtx_rings(struct net_device *dev);static void free_rxtx_rings(struct netdev_private *np);static void init_registers(struct net_device *dev);static void tx_timeout(struct net_device *dev);static int alloc_ringdesc(struct net_device *dev);static void free_ringdesc(struct netdev_private *np);static int start_tx(struct sk_buff *skb, struct net_device *dev);static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *regs);static void netdev_error(struct net_device *dev, int intr_status);static int netdev_rx(struct net_device *dev);static u32 __set_rx_mode(struct net_device *dev);static void set_rx_mode(struct net_device *dev);static struct net_device_stats *get_stats(struct net_device *dev);static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);static struct ethtool_ops netdev_ethtool_ops;static int netdev_close(struct net_device *dev);static int __devinit w840_probe1 (struct pci_dev *pdev, const struct pci_device_id *ent){ struct net_device *dev; struct netdev_private *np; static int find_cnt; int chip_idx = ent->driver_data; int irq; int i, option = find_cnt < MAX_UNITS ? options[find_cnt] : 0; void __iomem *ioaddr; int bar = 1; i = pci_enable_device(pdev); if (i) return i; pci_set_master(pdev); irq = pdev->irq; if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) { printk(KERN_WARNING "Winbond-840: Device %s disabled due to DMA limitations.\n", pci_name(pdev)); return -EIO; } dev = alloc_etherdev(sizeof(*np)); if (!dev) return -ENOMEM; SET_MODULE_OWNER(dev); SET_NETDEV_DEV(dev, &pdev->dev); if (pci_request_regions(pdev, DRV_NAME)) goto err_out_netdev;#ifdef USE_IO_OPS bar = 0;#endif ioaddr = pci_iomap(pdev, bar, pci_id_tbl[chip_idx].io_size); if (!ioaddr) goto err_out_free_res; for (i = 0; i < 3; i++) ((u16 *)dev->dev_addr)[i] = le16_to_cpu(eeprom_read(ioaddr, i)); /* Reset the chip to erase previous misconfiguration. No hold time required! */ iowrite32(0x00000001, ioaddr + PCIBusCfg); dev->base_addr = (unsigned long)ioaddr; dev->irq = irq; np = netdev_priv(dev); np->pci_dev = pdev; np->chip_id = chip_idx;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -