3c59x.c

来自「linux 内核源代码」· C语言 代码 · 共 1,988 行 · 第 1/5 页

C
1,988
字号
/* EtherLinkXL.c: A 3Com EtherLink PCI III/XL ethernet driver for linux. *//*	Written 1996-1999 by Donald Becker.	This software may be used and distributed according to the terms	of the GNU General Public License, incorporated herein by reference.	This driver is for the 3Com "Vortex" and "Boomerang" series ethercards.	Members of the series include Fast EtherLink 3c590/3c592/3c595/3c597	and the EtherLink XL 3c900 and 3c905 cards.	Problem reports and questions should be directed to	vortex@scyld.com	The author may be reached as becker@scyld.com, or C/O	Scyld Computing Corporation	410 Severn Ave., Suite 210	Annapolis MD 21403*//* * FIXME: This driver _could_ support MTU changing, but doesn't.  See Don's hamachi.c implementation * as well as other drivers * * NOTE: If you make 'vortex_debug' a constant (#define vortex_debug 0) the driver shrinks by 2k * due to dead code elimination.  There will be some performance benefits from this due to * elimination of all the tests and reduced cache footprint. */#define DRV_NAME	"3c59x"/* A few values that may be tweaked. *//* Keep the ring sizes a power of two for efficiency. */#define TX_RING_SIZE	16#define RX_RING_SIZE	32#define PKT_BUF_SZ		1536			/* Size of each temporary Rx buffer.*//* "Knobs" that adjust features and parameters. *//* Set the copy breakpoint for the copy-only-tiny-frames scheme.   Setting to > 1512 effectively disables this feature. */#ifndef __arm__static int rx_copybreak = 200;#else/* ARM systems perform better by disregarding the bus-master   transfer capability of these cards. -- rmk */static int rx_copybreak = 1513;#endif/* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */static const int mtu = 1500;/* Maximum events (Rx packets, etc.) to handle at each interrupt. */static int max_interrupt_work = 32;/* Tx timeout interval (millisecs) */static int watchdog = 5000;/* Allow aggregation of Tx interrupts.  Saves CPU load at the cost * of possible Tx stalls if the system is blocking interrupts * somewhere else.  Undefine this to disable. */#define tx_interrupt_mitigation 1/* Put out somewhat more debugging messages. (0: no msg, 1 minimal .. 6). */#define vortex_debug debug#ifdef VORTEX_DEBUGstatic int vortex_debug = VORTEX_DEBUG;#elsestatic int vortex_debug = 1;#endif#include <linux/module.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/errno.h>#include <linux/in.h>#include <linux/ioport.h>#include <linux/slab.h>#include <linux/interrupt.h>#include <linux/pci.h>#include <linux/mii.h>#include <linux/init.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/ethtool.h>#include <linux/highmem.h>#include <linux/eisa.h>#include <linux/bitops.h>#include <linux/jiffies.h>#include <asm/irq.h>			/* For NR_IRQS only. */#include <asm/io.h>#include <asm/uaccess.h>/* Kernel compatibility defines, some common to David Hinds' PCMCIA package.   This is only in the support-all-kernels source code. */#define RUN_AT(x) (jiffies + (x))#include <linux/delay.h>static char version[] __devinitdata =DRV_NAME ": Donald Becker and others.\n";MODULE_AUTHOR("Donald Becker <becker@scyld.com>");MODULE_DESCRIPTION("3Com 3c59x/3c9xx ethernet driver ");MODULE_LICENSE("GPL");/* Operational parameter that usually are not changed. *//* The Vortex size is twice that of the original EtherLinkIII series: the   runtime register window, window 1, is now always mapped in.   The Boomerang size is twice as large as the Vortex -- it has additional   bus master control registers. */#define VORTEX_TOTAL_SIZE 0x20#define BOOMERANG_TOTAL_SIZE 0x40/* Set iff a MII transceiver on any interface requires mdio preamble.   This only set with the original DP83840 on older 3c905 boards, so the extra   code size of a per-interface flag is not worthwhile. */static char mii_preamble_required;#define PFX DRV_NAME ": "/*				Theory of OperationI. Board CompatibilityThis device driver is designed for the 3Com FastEtherLink and FastEtherLinkXL, 3Com's PCI to 10/100baseT adapters.  It also works with the 10Mbsversions of the FastEtherLink cards.  The supported product IDs are  3c590, 3c592, 3c595, 3c597, 3c900, 3c905The related ISA 3c515 is supported with a separate driver, 3c515.c, includedwith the kernel source or available from    cesdis.gsfc.nasa.gov:/pub/linux/drivers/3c515.htmlII. Board-specific settingsPCI bus devices are configured by the system at boot time, so no jumpersneed to be set on the board.  The system BIOS should be set to assign thePCI INTA signal to an otherwise unused system IRQ line.The EEPROM settings for media type and forced-full-duplex are observed.The EEPROM media type should be left at the default "autoselect" unless using10base2 or AUI connections which cannot be reliably detected.III. Driver operationThe 3c59x series use an interface that's very similar to the previous 3c5x9series.  The primary interface is two programmed-I/O FIFOs, with analternate single-contiguous-region bus-master transfer (see next).The 3c900 "Boomerang" series uses a full-bus-master interface with separatelists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,DEC Tulip and Intel Speedo3.  The first chip version retains a compatibleprogrammed-I/O interface that has been removed in 'B' and subsequent boardrevisions.One extension that is advertised in a very large font is that the adaptersare capable of being bus masters.  On the Vortex chip this capability wasonly for a single contiguous region making it far less useful than the fullbus master capability.  There is a significant performance impact of takingan extra interrupt or polling for the completion of each transfer, as wellas difficulty sharing the single transfer engine between the transmit andreceive threads.  Using DMA transfers is a win only with large blocks orwith the flawed versions of the Intel Orion motherboard PCI controller.The Boomerang chip's full-bus-master interface is useful, and has thecurrently-unused advantages over other similar chips that queued transmitpackets may be reordered and receive buffer groups are associated with asingle frame.With full-bus-master support, this driver uses a "RX_COPYBREAK" scheme.Rather than a fixed intermediate receive buffer, this scheme allocatesfull-sized skbuffs as receive buffers.  The value RX_COPYBREAK is used asthe copying breakpoint: it is chosen to trade-off the memory wasted bypassing the full-sized skbuff to the queue layer for all frames vs. thecopying cost of copying a frame to a correctly-sized skbuff.IIIC. SynchronizationThe driver runs as two independent, single-threaded flows of control.  Oneis the send-packet routine, which enforces single-threaded use by thedev->tbusy flag.  The other thread is the interrupt handler, which is singlethreaded by the hardware and other software.IV. NotesThanks to Cameron Spitzer and Terry Murphy of 3Com for providing development3c590, 3c595, and 3c900 boards.The name "Vortex" is the internal 3Com project name for the PCI ASIC, andthe EISA version is called "Demon".  According to Terry these names comefrom rides at the local amusement park.The new chips support both ethernet (1.5K) and FDDI (4.5K) packet sizes!This driver only supports ethernet packets because of the skbuff allocationlimit of 4K.*//* This table drives the PCI probe routines.  It's mostly boilerplate in all   of the drivers, and will likely be provided by some future kernel.*/enum pci_flags_bit {	PCI_USES_MASTER=4,};enum {	IS_VORTEX=1, IS_BOOMERANG=2, IS_CYCLONE=4, IS_TORNADO=8,	EEPROM_8BIT=0x10,	/* AKPM: Uses 0x230 as the base bitmaps for EEPROM reads */	HAS_PWR_CTRL=0x20, HAS_MII=0x40, HAS_NWAY=0x80, HAS_CB_FNS=0x100,	INVERT_MII_PWR=0x200, INVERT_LED_PWR=0x400, MAX_COLLISION_RESET=0x800,	EEPROM_OFFSET=0x1000, HAS_HWCKSM=0x2000, WNO_XCVR_PWR=0x4000,	EXTRA_PREAMBLE=0x8000, EEPROM_RESET=0x10000, };enum vortex_chips {	CH_3C590 = 0,	CH_3C592,	CH_3C597,	CH_3C595_1,	CH_3C595_2,	CH_3C595_3,	CH_3C900_1,	CH_3C900_2,	CH_3C900_3,	CH_3C900_4,	CH_3C900_5,	CH_3C900B_FL,	CH_3C905_1,	CH_3C905_2,	CH_3C905B_1,	CH_3C905B_2,	CH_3C905B_FX,	CH_3C905C,	CH_3C9202,	CH_3C980,	CH_3C9805,	CH_3CSOHO100_TX,	CH_3C555,	CH_3C556,	CH_3C556B,	CH_3C575,	CH_3C575_1,	CH_3CCFE575,	CH_3CCFE575CT,	CH_3CCFE656,	CH_3CCFEM656,	CH_3CCFEM656_1,	CH_3C450,	CH_3C920,	CH_3C982A,	CH_3C982B,	CH_905BT4,	CH_920B_EMB_WNM,};/* note: this array directly indexed by above enums, and MUST * be kept in sync with both the enums above, and the PCI device * table below */static struct vortex_chip_info {	const char *name;	int flags;	int drv_flags;	int io_size;} vortex_info_tbl[] __devinitdata = {	{"3c590 Vortex 10Mbps",	 PCI_USES_MASTER, IS_VORTEX, 32, },	{"3c592 EISA 10Mbps Demon/Vortex",					/* AKPM: from Don's 3c59x_cb.c 0.49H */	 PCI_USES_MASTER, IS_VORTEX, 32, },	{"3c597 EISA Fast Demon/Vortex",					/* AKPM: from Don's 3c59x_cb.c 0.49H */	 PCI_USES_MASTER, IS_VORTEX, 32, },	{"3c595 Vortex 100baseTx",	 PCI_USES_MASTER, IS_VORTEX, 32, },	{"3c595 Vortex 100baseT4",	 PCI_USES_MASTER, IS_VORTEX, 32, },	{"3c595 Vortex 100base-MII",	 PCI_USES_MASTER, IS_VORTEX, 32, },	{"3c900 Boomerang 10baseT",	 PCI_USES_MASTER, IS_BOOMERANG|EEPROM_RESET, 64, },	{"3c900 Boomerang 10Mbps Combo",	 PCI_USES_MASTER, IS_BOOMERANG|EEPROM_RESET, 64, },	{"3c900 Cyclone 10Mbps TPO",						/* AKPM: from Don's 0.99M */	 PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },	{"3c900 Cyclone 10Mbps Combo",	 PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },	{"3c900 Cyclone 10Mbps TPC",						/* AKPM: from Don's 0.99M */	 PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },	{"3c900B-FL Cyclone 10base-FL",	 PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },	{"3c905 Boomerang 100baseTx",	 PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_RESET, 64, },	{"3c905 Boomerang 100baseT4",	 PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_RESET, 64, },	{"3c905B Cyclone 100baseTx",	 PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },	{"3c905B Cyclone 10/100/BNC",	 PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },	{"3c905B-FX Cyclone 100baseFx",	 PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },	{"3c905C Tornado",	PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },	{"3c920B-EMB-WNM (ATI Radeon 9100 IGP)",	 PCI_USES_MASTER, IS_TORNADO|HAS_MII|HAS_HWCKSM, 128, },	{"3c980 Cyclone",	 PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },	{"3c980C Python-T",	 PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },	{"3cSOHO100-TX Hurricane",	 PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },	{"3c555 Laptop Hurricane",	 PCI_USES_MASTER, IS_CYCLONE|EEPROM_8BIT|HAS_HWCKSM, 128, },	{"3c556 Laptop Tornado",	 PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|EEPROM_8BIT|HAS_CB_FNS|INVERT_MII_PWR|									HAS_HWCKSM, 128, },	{"3c556B Laptop Hurricane",	 PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|EEPROM_OFFSET|HAS_CB_FNS|INVERT_MII_PWR|	                                WNO_XCVR_PWR|HAS_HWCKSM, 128, },	{"3c575 [Megahertz] 10/100 LAN 	CardBus",	PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_8BIT, 128, },	{"3c575 Boomerang CardBus",	 PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_8BIT, 128, },	{"3CCFE575BT Cyclone CardBus",	 PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|									INVERT_LED_PWR|HAS_HWCKSM, 128, },	{"3CCFE575CT Tornado CardBus",	 PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|									MAX_COLLISION_RESET|HAS_HWCKSM, 128, },	{"3CCFE656 Cyclone CardBus",	 PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|									INVERT_LED_PWR|HAS_HWCKSM, 128, },	{"3CCFEM656B Cyclone+Winmodem CardBus",	 PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|									INVERT_LED_PWR|HAS_HWCKSM, 128, },	{"3CXFEM656C Tornado+Winmodem CardBus",			/* From pcmcia-cs-3.1.5 */	 PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|									MAX_COLLISION_RESET|HAS_HWCKSM, 128, },	{"3c450 HomePNA Tornado",						/* AKPM: from Don's 0.99Q */	 PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },	{"3c920 Tornado",	 PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },	{"3c982 Hydra Dual Port A",	 PCI_USES_MASTER, IS_TORNADO|HAS_HWCKSM|HAS_NWAY, 128, },	{"3c982 Hydra Dual Port B",	 PCI_USES_MASTER, IS_TORNADO|HAS_HWCKSM|HAS_NWAY, 128, },	{"3c905B-T4",	 PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },	{"3c920B-EMB-WNM Tornado",	 PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },	{NULL,}, /* NULL terminated list. */};static struct pci_device_id vortex_pci_tbl[] = {	{ 0x10B7, 0x5900, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C590 },	{ 0x10B7, 0x5920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C592 },	{ 0x10B7, 0x5970, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C597 },	{ 0x10B7, 0x5950, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_1 },	{ 0x10B7, 0x5951, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_2 },	{ 0x10B7, 0x5952, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_3 },	{ 0x10B7, 0x9000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_1 },	{ 0x10B7, 0x9001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_2 },	{ 0x10B7, 0x9004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_3 },	{ 0x10B7, 0x9005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_4 },	{ 0x10B7, 0x9006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_5 },	{ 0x10B7, 0x900A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900B_FL },	{ 0x10B7, 0x9050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905_1 },	{ 0x10B7, 0x9051, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905_2 },	{ 0x10B7, 0x9055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_1 },	{ 0x10B7, 0x9058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_2 },	{ 0x10B7, 0x905A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_FX },	{ 0x10B7, 0x9200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905C },	{ 0x10B7, 0x9202, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C9202 },	{ 0x10B7, 0x9800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C980 },

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?