📄 winbond-840.c
字号:
/* winbond-840.c: A Linux network device driver for the Winbond W89c840. *//* Written 1998-2003 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 914 Bay Ridge Road, Suite 220 Annapolis MD 21403 Support information and updates available at http://www.scyld.com/network/drivers.html The information and support mailing lists are based at http://www.scyld.com/mailman/listinfo/ Do not remove the copyright infomation. 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.*//* These identify the driver base version and may not be removed. */static const char version1[] ="winbond-840.c:v1.10 7/22/2003 Donald Becker <becker@scyld.com>\n";static const char version2[] =" http://www.scyld.com/network/drivers.html\n";/* 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: The winbond-840.c driver is for the Winbond W89c840 chip.c-help: This chip is named TX9882 on the Compex RL100-ATX board.c-help: More specific information and updates are available fromc-help: http://www.scyld.com/network/drivers.html*//* The user-configurable values. These may be modified when a driver module is loaded.*//* Message enable level: 0..31 = no..all messages. See NETIF_MSG docs. */static int debug = 2;/* Maximum events (Rx packets, etc.) to handle at each interrupt. */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 = 0;/* Used to pass the media type, etc. Both 'options[]' and 'full_duplex[]' should exist for driver interoperability, however setting full_duplex[] is deprecated. The media type is usually passed in 'options[]'. The default is autonegotation for speed and duplex. This should rarely be overridden. Use option values 0x10/0x20 for 10Mbps, 0x100,0x200 for 100Mbps. Use option values 0x10 and 0x100 for forcing half duplex fixed speed. Use option values 0x20 and 0x200 for forcing full duplex operation.*/#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, confuses the system network buffer limits, and wastes memory. Larger receive rings merely waste memory.*/#define TX_RING_SIZE 16#define TX_QUEUE_LEN 10 /* Limit ring entries actually used, min 4. */#define RX_RING_SIZE 32/* 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. Re-autonegotiation may take up to 3 seconds. */#define TX_TIMEOUT (6*HZ)/* Allocation size of Rx buffers with normal sized Ethernet frames. Do not change this value without good reason. This is not a limit, but a way to keep a consistent allocation size among drivers. */#define PKT_BUF_SZ 1536#ifndef __KERNEL__#define __KERNEL__#endif#if !defined(__OPTIMIZE__)#warning You must compile this file with the correct options!#warning See the last lines of the source file.#error You must compile this driver with "-O".#endif/* Include files, designed to support most kernel versions 2.0.0 and later. */#include <linux/config.h>#if defined(CONFIG_SMP) && ! defined(__SMP__)#define __SMP__#endif#if defined(MODULE) && defined(CONFIG_MODVERSIONS) && ! defined(MODVERSIONS)#define MODVERSIONS#endif#include <linux/version.h>#if defined(MODVERSIONS)#include <linux/modversions.h>#endif#include <linux/module.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/errno.h>#include <linux/ioport.h>#if LINUX_VERSION_CODE >= 0x20400#include <linux/slab.h>#else#include <linux/malloc.h>#endif#include <linux/interrupt.h>#include <linux/pci.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <asm/processor.h> /* Processor type for cache alignment. */#include <asm/bitops.h>#include <asm/io.h>#ifdef INLINE_PCISCAN#include "k_compat.h"#else#include "pci-scan.h"#include "kern_compat.h"#endif/* Configure the PCI bus bursts and FIFO thresholds. 486: Set 8 longword cache alignment, 8 longword burst. 586: Set 16 longword cache alignment, no burst limit. Cache alignment bits 15:14 Burst length 13:8 0000 <not allowed> 0000 align to cache 0800 8 longwords 4000 8 longwords 0100 1 longword 1000 16 longwords 8000 16 longwords 0200 2 longwords 2000 32 longwords C000 32 longwords 0400 4 longwords Wait the specified 50 PCI cycles after a reset by initializing Tx and Rx queues and the address filter list. */#define TX_DESC_SIZE 16#if defined(__powerpc__) || defined(__sparc__) /* Big endian */static int csr0 = 0x00100000 | 0xE000 | TX_DESC_SIZE;#elif defined(__alpha__) || defined(__x86_64) || defined(__ia64)static int csr0 = 0xE000 | TX_DESC_SIZE;#elif defined(__i386__)static int csr0 = 0xE000 | TX_DESC_SIZE;#elsestatic int csr0 = 0xE000 | TX_DESC_SIZE;#warning Processor architecture unknown!#endif#if (LINUX_VERSION_CODE >= 0x20100) && defined(MODULE)char kernel_version[] = UTS_RELEASE;#endifMODULE_AUTHOR("Donald Becker <becker@scyld.com>");MODULE_DESCRIPTION("Winbond W89c840 Ethernet driver");MODULE_LICENSE("GPL");MODULE_PARM(max_interrupt_work, "i");MODULE_PARM(debug, "i");MODULE_PARM(rx_copybreak, "i");MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");MODULE_PARM(multicast_filter_limit, "i");MODULE_PARM_DESC(debug, "Driver message level (0-31)");MODULE_PARM_DESC(options, "Force transceiver type or fixed speed+duplex");MODULE_PARM_DESC(max_interrupt_work, "Driver maximum events handled per interrupt");MODULE_PARM_DESC(full_duplex, "Non-zero to set forced full duplex.");MODULE_PARM_DESC(rx_copybreak, "Breakpoint in bytes for copy-only-tiny-frames");MODULE_PARM_DESC(multicast_filter_limit, "Multicast addresses before switching to Rx-all-multicast");/* 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.*//* PCI probe table.*/static void *w840_probe1(struct pci_dev *pdev, void *init_dev, long ioaddr, int irq, int chip_idx, int find_cnt);static int winbond_pwr_event(void *dev_instance, int event);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_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}, {0,}, /* 0 terminated list. */};struct drv_id_info winbond840_drv_id = { "winbond-840", PCI_HOTSWAP, PCI_CLASS_NETWORK_ETHERNET<<8, pci_id_tbl, w840_probe1, winbond_pwr_event };/* 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. */#ifdef USE_IO_OPS#undef readb#undef readw#undef readl#undef writeb#undef writew#undef writel#define readb inb#define readw inw#define readl inl#define writeb outb#define writew outw#define writel outl#endif/* 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 { TxOn=0x2000, RxOn=0x0002, FullDuplex=0x0200, AcceptErr=0x80, AcceptRunt=0x40, /* Not used */ AcceptBroadcast=0x20, AcceptMulticast=0x10, AcceptAllPhys=0x08,};enum mii_reg_bits { MDIO_ShiftClk=0x10000, MDIO_DataIn=0x80000, MDIO_DataOut=0x20000, MDIO_EnbOutput=0x40000, MDIO_EnbIn = 0x00000,};/* The Tulip-like Rx and Tx buffer descriptors. */struct w840_rx_desc { s32 status; s32 length; u32 buffer1; u32 next_desc;};struct w840_tx_desc { s32 status; s32 length; u32 buffer1, buffer2; /* We use only buffer 1. */ char pad[TX_DESC_SIZE - 16];};/* Bits in network_desc.status */enum desc_status_bits { DescOwn=0x80000000, DescEndRing=0x02000000, DescUseLink=0x01000000, DescWholePkt=0x60000000, DescStartPkt=0x20000000, DescEndPkt=0x40000000, DescIntr=0x80000000,};#define PRIV_ALIGN 15 /* Required alignment mask */struct netdev_private { /* Descriptor rings first for alignment. */ struct w840_rx_desc rx_ring[RX_RING_SIZE]; struct w840_tx_desc tx_ring[TX_RING_SIZE]; struct net_device *next_module; /* Link for devices of this type. */ void *priv_addr; /* Unaligned address for kfree */ const char *product_name; /* 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. */ int msg_level; int chip_id, drv_flags; struct pci_dev *pci_dev; int csr0, csr6; unsigned int polling; /* Switched to polling mode. */ int max_interrupt_work; struct w840_rx_desc *rx_head_desc; unsigned int rx_ring_size; unsigned int cur_rx, dirty_rx; /* Producer/consumer ring indices */ unsigned int rx_buf_sz; /* Based on MTU+slack. */ int rx_copybreak; unsigned int tx_ring_size; unsigned int cur_tx, dirty_tx;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -