⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3c59x.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 5 页
字号:
/* 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	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 issue_and_wait 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 Rekorajski)    - 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   LK1.1.12 1 Jan 2001 andrewm (2.4.0-pre1)    - Call pci_enable_device before we request our IRQ (Tobias Ringstrom)    - Add 3c590 PCI latency timer hack to vortex_probe1 (from 0.99Ra)    - Added extended issue_and_wait for the 3c905CX.    - Look for an MII on PHY index 24 first (3c905CX oddity).    - Add HAS_NWAY to 3cSOHO100-TX (Brett Frankenberger)    - Don't free skbs we don't own on oom path in vortex_open().   LK1.1.13 27 Jan 2001    - Added explicit `medialock' flag so we can truly      lock the media type down with `options'.    - "check ioremap return and some tidbits" (Arnaldo Carvalho de Melo <acme@conectiva.com.br>)    - Added and used EEPROM_NORESET for 3c556B PM resumes.    - Fixed leakage of vp->rx_ring.    - Break out separate HAS_HWCKSM device capability flag.    - Kill vp->tx_full (ANK)    - Merge zerocopy fragment handling (ANK?)   LK1.1.14 15 Feb 2001    - Enable WOL.  Can be turned on with `enable_wol' module option.    - EISA and PCI initialisation fixes (jgarzik, Manfred Spraul)    - If a device's internalconfig register reports it has NWAY,      use it, even if autoselect is enabled.   LK1.1.15 6 June 2001 akpm    - Prevent double counting of received bytes (Lars Christensen)    - Add ethtool support (jgarzik)    - Add module parm descriptions (Andrzej M. Krzysztofowicz)    - Implemented alloc_etherdev() API    - Special-case the 'Tx error 82' message.   LK1.1.16 18 July 2001 akpm    - Make NETIF_F_SG dependent upon nr_free_highpages(), not on CONFIG_HIGHMEM    - Lessen verbosity of bootup messages    - Fix WOL - use new PM API functions.    - Use netif_running() instead of vp->open in suspend/resume.    - Don't reset the interface logic on open/close/rmmod.  It upsets      autonegotiation, and hence DHCP (from 0.99T).    - Back out EEPROM_NORESET flag because of the above (we do it for all      NICs).    - Correct 3c982 identification string    - Rename wait_for_completion() to issue_and_wait() to avoid completion.h      clash.    - 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 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"#define DRV_VERSION	"LK1.1.16"#define DRV_RELDATE	"19 July 2001"/* 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 const int rx_copybreak = 200;#else/* ARM systems perform better by disregarding the bus-master   transfer capability of these cards. -- rmk */static const 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#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/config.h>#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/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 <asm/irq.h>			/* For NR_IRQS only. */#include <asm/bitops.h>#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. www.scyld.com/network/vortex.html\n";MODULE_AUTHOR("Donald Becker <becker@scyld.com>");MODULE_DESCRIPTION("3Com 3c59x/3c9xx ethernet driver "					DRV_VERSION " " DRV_RELDATE);MODULE_LICENSE("GPL");MODULE_PARM(debug, "i");MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");MODULE_PARM(hw_checksums, "1-" __MODULE_STRING(8) "i");MODULE_PARM(flow_ctrl, "1-" __MODULE_STRING(8) "i");MODULE_PARM(enable_wol, "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");MODULE_PARM_DESC(debug, "3c59x debug level (0-6)");MODULE_PARM_DESC(options, "3c59x: Bits 0-3: media type, bit 4: bus mastering, bit 9: full duplex");MODULE_PARM_DESC(full_duplex, "3c59x full duplex setting(s) (1)");MODULE_PARM_DESC(hw_checksums, "3c59x Hardware checksum checking by adapter(s) (0-1)");MODULE_PARM_DESC(flow_ctrl, "3c59x 802.3x flow control usage (PAUSE only) (0-1)");MODULE_PARM_DESC(enable_wol, "3c59x: Turn on Wake-on-LAN for adapter(s) (0-1)");MODULE_PARM_DESC(rx_copybreak, "3c59x copy breakpoint for copy-only-tiny-frames");MODULE_PARM_DESC(max_interrupt_work, "3c59x maximum events handled per interrupt");MODULE_PARM_DESC(compaq_ioaddr, "3c59x PCI I/O base address (Compaq BIOS problem workaround)");MODULE_PARM_DESC(compaq_irq, "3c59x PCI IRQ number (Compaq BIOS problem workaround)");MODULE_PARM_DESC(compaq_device_id, "3c59x PCI device ID (Compaq BIOS problem workaround)");MODULE_PARM_DESC(watchdog, "3c59x transmit timeout in milliseconds");/* 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.  One

⌨️ 快捷键说明

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