📄 3c59x.c
字号:
/* 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 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. The author may be reached as becker@scyld.com, or C/O Center of Excellence in Space Data and Information Sciences Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771 Linux Kernel Additions: 0.99H+lk0.9 - David S. Miller - softnet, PCI DMA updates 0.99H+lk1.0 - Jeff Garzik <jgarzik@mandrakesoft.com> Remove compatibility defines for kernel versions < 2.2.x. Update for new 2.3.x module interface LK1.1.2 (March 19, 2000) * New PCI interface (jgarzik) LK1.1.3 25 April 2000, Andrew Morton <andrewm@uow.edu.au> - Merged with 3c575_cb.c - Don't set RxComplete in boomerang interrupt enable reg - spinlock in vortex_timer to protect mdio functions - disable local interrupts around call to vortex_interrupt in vortex_tx_timeout() (So vortex_interrupt can use spin_lock()) - Select window 3 in vortex_timer()'s write to Wn3_MAC_Ctrl - In vortex_start_xmit(), move the lock to _after_ we've altered vp->cur_tx and vp->tx_full. This defeats the race between vortex_start_xmit() and vortex_interrupt which was identified by Bogdan Costescu. - Merged back support for six new cards from various sources - Set vortex_have_pci if pci_module_init returns zero (fixes cardbus insertion oops) - Tell it that 3c905C has NWAY for 100bT autoneg - Fix handling of SetStatusEnd in 'Too much work..' code, as per 2.3.99's 3c575_cb (Dave Hinds). - Split ISR into two for vortex & boomerang - Fix MOD_INC/DEC races - Handle resource allocation failures. - Fix 3CCFE575CT LED polarity - Make tx_interrupt_mitigation the default LK1.1.4 25 April 2000, Andrew Morton <andrewm@uow.edu.au> - Add extra TxReset to vortex_up() to fix 575_cb hotplug initialisation probs. - Put vortex_info_tbl into __devinitdata - In the vortex_error StatsFull HACK, disable stats in vp->intr_enable as well as in the hardware. - Increased the loop counter in wait_for_completion from 2,000 to 4,000. LK1.1.5 28 April 2000, andrewm - Added powerpc defines (John Daniel <jdaniel@etresoft.com> said these work...) - Some extra diagnostics - In vortex_error(), reset the Tx on maxCollisions. Otherwise most chips usually get a Tx timeout. - Added extra_reset module parm - Replaced some inline timer manip with mod_timer (Franois romieu <Francois.Romieu@nic.fr>) - In vortex_up(), don't make Wn3_config initialisation dependent upon has_nway (this came across from 3c575_cb). LK1.1.6 06 Jun 2000, andrewm - Backed out the PPC defines. - Use del_timer_sync(), mod_timer(). - Fix wrapped ulong comparison in boomerang_rx() - Add IS_TORNADO, use it to suppress 3c905C checksum error msg (Donald Becker, I Lee Hetherington <ilh@sls.lcs.mit.edu>) - Replace union wn3_config with BFINS/BFEXT manipulation for sparc64 (Pete Zaitcev, Peter Jones) - In vortex_error, do_tx_reset and vortex_tx_timeout(Vortex): do a netif_wake_queue() to better recover from errors. (Anders Pedersen, Donald Becker) - Print a warning on out-of-memory (rate limited to 1 per 10 secs) - Added two more Cardbus 575 NICs: 5b57 and 6564 (Paul Wagland) LK1.1.7 2 Jul 2000 andrewm - Better handling of shared IRQs - Reset the transmitter on a Tx reclaim error - Fixed crash under OOM during vortex_open() (Mark Hemment) - Fix Rx cessation problem during OOM (help from Mark Hemment) - The spinlocks around the mdio access were blocking interrupts for 300uS. Fix all this to use spin_lock_bh() within mdio_read/write - Only write to TxFreeThreshold if it's a boomerang - other NICs don't have one. - Added 802.3x MAC-layer flow control support LK1.1.8 13 Aug 2000 andrewm - Ignore request_region() return value - already reserved if Cardbus. - Merged some additional Cardbus flags from Don's 0.99Qk - Some fixes for 3c556 (Fred Maciel) - Fix for EISA initialisation (Jan Rkorajski) - Renamed MII_XCVR_PWR and EEPROM_230 to align with 3c575_cb and D. Becker's drivers - Fixed MII_XCVR_PWR for 3CCFE575CT - Added INVERT_LED_PWR, used it. - Backed out the extra_reset stuff LK1.1.9 12 Sep 2000 andrewm - Backed out the tx_reset_resume flags. It was a no-op. - In vortex_error, don't reset the Tx on txReclaim errors - In vortex_error, don't reset the Tx on maxCollisions errors. Hence backed out all the DownListPtr logic here. - In vortex_error, give Tornado cards a partial TxReset on maxCollisions (David Hinds). Defined MAX_COLLISION_RESET for this. - Redid some driver flags and device names based on pcmcia_cs-3.1.20. - Fixed a bug where, if vp->tx_full is set when the interface is downed, it remains set when the interface is upped. Bad things happen. LK1.1.10 17 Sep 2000 andrewm - Added EEPROM_8BIT for 3c555 (Fred Maciel) - Added experimental support for the 3c556B Laptop Hurricane (Louis Gerbarg) - Add HAS_NWAY to "3c900 Cyclone 10Mbps TPO" LK1.1.11 13 Nov 2000 andrewm - Dump MOD_INC/DEC_USE_COUNT, use SET_MODULE_OWNER - See http://www.uow.edu.au/~andrewm/linux/#3c59x-2.3 for more details. - Also see Documentation/networking/vortex.txt*//* * FIXME: This driver _could_ support MTU changing, but doesn't. See Don's hamaci.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. *//* 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. */static const int rx_copybreak = 200;/* 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 = 400;/* 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. * AKPM 26 April 2000: enabling this still gets vestigial Tx timeouts * in a heavily loaded (collision-prone) 10BaseT LAN. Should be OK with * switched Ethernet. * AKPM 24May00: vestigial timeouts have been removed by later fixes. */#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/* Some values here only for performance evaluation and path-coverage debugging. */static int rx_nocopy = 0, rx_copy = 0, queued_packet = 0, rx_csumhits;#ifndef __OPTIMIZE__#error You must compile this file with the correct options!#error See the last lines of the source file.#error You must compile this driver with "-O".#endif#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/errno.h>#include <linux/in.h>#include <linux/ioport.h>#include <linux/malloc.h>#include <linux/interrupt.h>#include <linux/pci.h>#include <linux/init.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <asm/irq.h> /* For NR_IRQS only. */#include <asm/bitops.h>#include <asm/io.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 ="3c59x.c:LK1.1.11 13 Nov 2000 Donald Becker and others. http://www.scyld.com/network/vortex.html " "$Revision: 1.102.2.46 $\n";MODULE_AUTHOR("Donald Becker <becker@scyld.com>");MODULE_DESCRIPTION("3Com 3c59x/3c90x/3c575 series Vortex/Boomerang/Cyclone driver");MODULE_PARM(debug, "i");MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");MODULE_PARM(flow_ctrl, "1-" __MODULE_STRING(8) "i");MODULE_PARM(rx_copybreak, "i");MODULE_PARM(max_interrupt_work, "i");MODULE_PARM(compaq_ioaddr, "i");MODULE_PARM(compaq_irq, "i");MODULE_PARM(compaq_device_id, "i");MODULE_PARM(watchdog, "i");/* 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 "3c59x: "/* 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_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4, PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,};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 };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_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,};/* 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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -