linux-bk/drivers/net/3c59x.c
<<
>>
Prefs
   1/* EtherLinkXL.c: A 3Com EtherLink PCI III/XL ethernet driver for linux. */
   2/*
   3        Written 1996-1999 by Donald Becker.
   4
   5        This software may be used and distributed according to the terms
   6        of the GNU General Public License, incorporated herein by reference.
   7
   8        This driver is for the 3Com "Vortex" and "Boomerang" series ethercards.
   9        Members of the series include Fast EtherLink 3c590/3c592/3c595/3c597
  10        and the EtherLink XL 3c900 and 3c905 cards.
  11
  12        Problem reports and questions should be directed to
  13        vortex@scyld.com
  14
  15        The author may be reached as becker@scyld.com, or C/O
  16        Scyld Computing Corporation
  17        410 Severn Ave., Suite 210
  18        Annapolis MD 21403
  19
  20        Linux Kernel Additions:
  21        
  22        0.99H+lk0.9 - David S. Miller - softnet, PCI DMA updates
  23        0.99H+lk1.0 - Jeff Garzik <jgarzik@mandrakesoft.com>
  24                Remove compatibility defines for kernel versions < 2.2.x.
  25                Update for new 2.3.x module interface
  26        LK1.1.2 (March 19, 2000)
  27        * New PCI interface (jgarzik)
  28
  29    LK1.1.3 25 April 2000, Andrew Morton <andrewm@uow.edu.au>
  30    - Merged with 3c575_cb.c
  31    - Don't set RxComplete in boomerang interrupt enable reg
  32    - spinlock in vortex_timer to protect mdio functions
  33    - disable local interrupts around call to vortex_interrupt in
  34      vortex_tx_timeout() (So vortex_interrupt can use spin_lock())
  35    - Select window 3 in vortex_timer()'s write to Wn3_MAC_Ctrl
  36    - In vortex_start_xmit(), move the lock to _after_ we've altered
  37      vp->cur_tx and vp->tx_full.  This defeats the race between
  38      vortex_start_xmit() and vortex_interrupt which was identified
  39      by Bogdan Costescu.
  40    - Merged back support for six new cards from various sources
  41    - Set vortex_have_pci if pci_module_init returns zero (fixes cardbus
  42      insertion oops)
  43    - Tell it that 3c905C has NWAY for 100bT autoneg
  44    - Fix handling of SetStatusEnd in 'Too much work..' code, as
  45      per 2.3.99's 3c575_cb (Dave Hinds).
  46    - Split ISR into two for vortex & boomerang
  47    - Fix MOD_INC/DEC races
  48    - Handle resource allocation failures.
  49    - Fix 3CCFE575CT LED polarity
  50    - Make tx_interrupt_mitigation the default
  51
  52    LK1.1.4 25 April 2000, Andrew Morton <andrewm@uow.edu.au>    
  53    - Add extra TxReset to vortex_up() to fix 575_cb hotplug initialisation probs.
  54    - Put vortex_info_tbl into __devinitdata
  55    - In the vortex_error StatsFull HACK, disable stats in vp->intr_enable as well
  56      as in the hardware.
  57    - Increased the loop counter in issue_and_wait from 2,000 to 4,000.
  58
  59    LK1.1.5 28 April 2000, andrewm
  60    - Added powerpc defines (John Daniel <jdaniel@etresoft.com> said these work...)
  61    - Some extra diagnostics
  62    - In vortex_error(), reset the Tx on maxCollisions.  Otherwise most
  63      chips usually get a Tx timeout.
  64    - Added extra_reset module parm
  65    - Replaced some inline timer manip with mod_timer
  66      (Franois romieu <Francois.Romieu@nic.fr>)
  67    - In vortex_up(), don't make Wn3_config initialisation dependent upon has_nway
  68      (this came across from 3c575_cb).
  69
  70    LK1.1.6 06 Jun 2000, andrewm
  71    - Backed out the PPC defines.
  72    - Use del_timer_sync(), mod_timer().
  73    - Fix wrapped ulong comparison in boomerang_rx()
  74    - Add IS_TORNADO, use it to suppress 3c905C checksum error msg
  75      (Donald Becker, I Lee Hetherington <ilh@sls.lcs.mit.edu>)
  76    - Replace union wn3_config with BFINS/BFEXT manipulation for
  77      sparc64 (Pete Zaitcev, Peter Jones)
  78    - In vortex_error, do_tx_reset and vortex_tx_timeout(Vortex):
  79      do a netif_wake_queue() to better recover from errors. (Anders Pedersen,
  80      Donald Becker)
  81    - Print a warning on out-of-memory (rate limited to 1 per 10 secs)
  82    - Added two more Cardbus 575 NICs: 5b57 and 6564 (Paul Wagland)
  83
  84    LK1.1.7 2 Jul 2000 andrewm
  85    - Better handling of shared IRQs
  86    - Reset the transmitter on a Tx reclaim error
  87    - Fixed crash under OOM during vortex_open() (Mark Hemment)
  88    - Fix Rx cessation problem during OOM (help from Mark Hemment)
  89    - The spinlocks around the mdio access were blocking interrupts for 300uS.
  90      Fix all this to use spin_lock_bh() within mdio_read/write
  91    - Only write to TxFreeThreshold if it's a boomerang - other NICs don't
  92      have one.
  93    - Added 802.3x MAC-layer flow control support
  94
  95   LK1.1.8 13 Aug 2000 andrewm
  96    - Ignore request_region() return value - already reserved if Cardbus.
  97    - Merged some additional Cardbus flags from Don's 0.99Qk
  98    - Some fixes for 3c556 (Fred Maciel)
  99    - Fix for EISA initialisation (Jan Rekorajski)
 100    - Renamed MII_XCVR_PWR and EEPROM_230 to align with 3c575_cb and D. Becker's drivers
 101    - Fixed MII_XCVR_PWR for 3CCFE575CT
 102    - Added INVERT_LED_PWR, used it.
 103    - Backed out the extra_reset stuff
 104
 105   LK1.1.9 12 Sep 2000 andrewm
 106    - Backed out the tx_reset_resume flags.  It was a no-op.
 107    - In vortex_error, don't reset the Tx on txReclaim errors
 108    - In vortex_error, don't reset the Tx on maxCollisions errors.
 109      Hence backed out all the DownListPtr logic here.
 110    - In vortex_error, give Tornado cards a partial TxReset on
 111      maxCollisions (David Hinds).  Defined MAX_COLLISION_RESET for this.
 112    - Redid some driver flags and device names based on pcmcia_cs-3.1.20.
 113    - Fixed a bug where, if vp->tx_full is set when the interface
 114      is downed, it remains set when the interface is upped.  Bad
 115      things happen.
 116
 117   LK1.1.10 17 Sep 2000 andrewm
 118    - Added EEPROM_8BIT for 3c555 (Fred Maciel)
 119    - Added experimental support for the 3c556B Laptop Hurricane (Louis Gerbarg)
 120    - Add HAS_NWAY to "3c900 Cyclone 10Mbps TPO"
 121
 122   LK1.1.11 13 Nov 2000 andrewm
 123    - Dump MOD_INC/DEC_USE_COUNT, use SET_MODULE_OWNER
 124
 125   LK1.1.12 1 Jan 2001 andrewm (2.4.0-pre1)
 126    - Call pci_enable_device before we request our IRQ (Tobias Ringstrom)
 127    - Add 3c590 PCI latency timer hack to vortex_probe1 (from 0.99Ra)
 128    - Added extended issue_and_wait for the 3c905CX.
 129    - Look for an MII on PHY index 24 first (3c905CX oddity).
 130    - Add HAS_NWAY to 3cSOHO100-TX (Brett Frankenberger)
 131    - Don't free skbs we don't own on oom path in vortex_open().
 132
 133   LK1.1.13 27 Jan 2001
 134    - Added explicit `medialock' flag so we can truly
 135      lock the media type down with `options'.
 136    - "check ioremap return and some tidbits" (Arnaldo Carvalho de Melo <acme@conectiva.com.br>)
 137    - Added and used EEPROM_NORESET for 3c556B PM resumes.
 138    - Fixed leakage of vp->rx_ring.
 139    - Break out separate HAS_HWCKSM device capability flag.
 140    - Kill vp->tx_full (ANK)
 141    - Merge zerocopy fragment handling (ANK?)
 142
 143   LK1.1.14 15 Feb 2001
 144    - Enable WOL.  Can be turned on with `enable_wol' module option.
 145    - EISA and PCI initialisation fixes (jgarzik, Manfred Spraul)
 146    - If a device's internalconfig register reports it has NWAY,
 147      use it, even if autoselect is enabled.
 148
 149   LK1.1.15 6 June 2001 akpm
 150    - Prevent double counting of received bytes (Lars Christensen)
 151    - Add ethtool support (jgarzik)
 152    - Add module parm descriptions (Andrzej M. Krzysztofowicz)
 153    - Implemented alloc_etherdev() API
 154    - Special-case the 'Tx error 82' message.
 155
 156   LK1.1.16 18 July 2001 akpm
 157    - Make NETIF_F_SG dependent upon nr_free_highpages(), not on CONFIG_HIGHMEM
 158    - Lessen verbosity of bootup messages
 159    - Fix WOL - use new PM API functions.
 160    - Use netif_running() instead of vp->open in suspend/resume.
 161    - Don't reset the interface logic on open/close/rmmod.  It upsets
 162      autonegotiation, and hence DHCP (from 0.99T).
 163    - Back out EEPROM_NORESET flag because of the above (we do it for all
 164      NICs).
 165    - Correct 3c982 identification string
 166    - Rename wait_for_completion() to issue_and_wait() to avoid completion.h
 167      clash.
 168
 169   LK1.1.17 18Dec01 akpm
 170    - PCI ID 9805 is a Python-T, not a dual-port Cyclone.  Apparently.
 171      And it has NWAY.
 172    - Mask our advertised modes (vp->advertising) with our capabilities
 173          (MII reg5) when deciding which duplex mode to use.
 174    - Add `global_options' as default for options[].  Ditto global_enable_wol,
 175      global_full_duplex.
 176
 177   LK1.1.18 01Jul02 akpm
 178    - Fix for undocumented transceiver power-up bit on some 3c566B's
 179      (Donald Becker, Rahul Karnik)
 180
 181    - See http://www.zip.com.au/~akpm/linux/#3c59x-2.3 for more details.
 182    - Also see Documentation/networking/vortex.txt
 183*/
 184
 185/*
 186 * FIXME: This driver _could_ support MTU changing, but doesn't.  See Don's hamachi.c implementation
 187 * as well as other drivers
 188 *
 189 * NOTE: If you make 'vortex_debug' a constant (#define vortex_debug 0) the driver shrinks by 2k
 190 * due to dead code elimination.  There will be some performance benefits from this due to
 191 * elimination of all the tests and reduced cache footprint.
 192 */
 193
 194
 195#define DRV_NAME        "3c59x"
 196#define DRV_VERSION     "LK1.1.18"
 197#define DRV_RELDATE     "1 Jul 2002"
 198
 199
 200
 201/* A few values that may be tweaked. */
 202/* Keep the ring sizes a power of two for efficiency. */
 203#define TX_RING_SIZE    16
 204#define RX_RING_SIZE    32
 205#define PKT_BUF_SZ              1536                    /* Size of each temporary Rx buffer.*/
 206
 207/* "Knobs" that adjust features and parameters. */
 208/* Set the copy breakpoint for the copy-only-tiny-frames scheme.
 209   Setting to > 1512 effectively disables this feature. */
 210#ifndef __arm__
 211static const int rx_copybreak = 200;
 212#else
 213/* ARM systems perform better by disregarding the bus-master
 214   transfer capability of these cards. -- rmk */
 215static const int rx_copybreak = 1513;
 216#endif
 217/* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
 218static const int mtu = 1500;
 219/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
 220static int max_interrupt_work = 32;
 221/* Tx timeout interval (millisecs) */
 222static int watchdog = 5000;
 223
 224/* Allow aggregation of Tx interrupts.  Saves CPU load at the cost
 225 * of possible Tx stalls if the system is blocking interrupts
 226 * somewhere else.  Undefine this to disable.
 227 */
 228#define tx_interrupt_mitigation 1
 229
 230/* Put out somewhat more debugging messages. (0: no msg, 1 minimal .. 6). */
 231#define vortex_debug debug
 232#ifdef VORTEX_DEBUG
 233static int vortex_debug = VORTEX_DEBUG;
 234#else
 235static int vortex_debug = 1;
 236#endif
 237
 238#ifndef __OPTIMIZE__
 239#error You must compile this file with the correct options!
 240#error See the last lines of the source file.
 241#error You must compile this driver with "-O".
 242#endif
 243
 244#include <linux/config.h>
 245#include <linux/module.h>
 246#include <linux/kernel.h>
 247#include <linux/sched.h>
 248#include <linux/string.h>
 249#include <linux/timer.h>
 250#include <linux/errno.h>
 251#include <linux/in.h>
 252#include <linux/ioport.h>
 253#include <linux/slab.h>
 254#include <linux/interrupt.h>
 255#include <linux/pci.h>
 256#include <linux/mii.h>
 257#include <linux/init.h>
 258#include <linux/netdevice.h>
 259#include <linux/etherdevice.h>
 260#include <linux/skbuff.h>
 261#include <linux/ethtool.h>
 262#include <linux/highmem.h>
 263#include <asm/irq.h>                    /* For NR_IRQS only. */
 264#include <asm/bitops.h>
 265#include <asm/io.h>
 266#include <asm/uaccess.h>
 267
 268/* Kernel compatibility defines, some common to David Hinds' PCMCIA package.
 269   This is only in the support-all-kernels source code. */
 270
 271#define RUN_AT(x) (jiffies + (x))
 272
 273#include <linux/delay.h>
 274
 275
 276static char version[] __devinitdata =
 277DRV_NAME ": Donald Becker and others. www.scyld.com/network/vortex.html\n";
 278
 279MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
 280MODULE_DESCRIPTION("3Com 3c59x/3c9xx ethernet driver "
 281                                        DRV_VERSION " " DRV_RELDATE);
 282MODULE_LICENSE("GPL");
 283
 284MODULE_PARM(debug, "i");
 285MODULE_PARM(global_options, "i");
 286MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");
 287MODULE_PARM(global_full_duplex, "i");
 288MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");
 289MODULE_PARM(hw_checksums, "1-" __MODULE_STRING(8) "i");
 290MODULE_PARM(flow_ctrl, "1-" __MODULE_STRING(8) "i");
 291MODULE_PARM(global_enable_wol, "i");
 292MODULE_PARM(enable_wol, "1-" __MODULE_STRING(8) "i");
 293MODULE_PARM(rx_copybreak, "i");
 294MODULE_PARM(max_interrupt_work, "i");
 295MODULE_PARM(compaq_ioaddr, "i");
 296MODULE_PARM(compaq_irq, "i");
 297MODULE_PARM(compaq_device_id, "i");
 298MODULE_PARM(watchdog, "i");
 299MODULE_PARM_DESC(debug, "3c59x debug level (0-6)");
 300MODULE_PARM_DESC(options, "3c59x: Bits 0-3: media type, bit 4: bus mastering, bit 9: full duplex");
 301MODULE_PARM_DESC(global_options, "3c59x: same as options, but applies to all NICs if options is unset");
 302MODULE_PARM_DESC(full_duplex, "3c59x full duplex setting(s) (1)");
 303MODULE_PARM_DESC(global_full_duplex, "3c59x: same as full_duplex, but applies to all NICs if options is unset");
 304MODULE_PARM_DESC(hw_checksums, "3c59x Hardware checksum checking by adapter(s) (0-1)");
 305MODULE_PARM_DESC(flow_ctrl, "3c59x 802.3x flow control usage (PAUSE only) (0-1)");
 306MODULE_PARM_DESC(enable_wol, "3c59x: Turn on Wake-on-LAN for adapter(s) (0-1)");
 307MODULE_PARM_DESC(global_enable_wol, "3c59x: same as enable_wol, but applies to all NICs if options is unset");
 308MODULE_PARM_DESC(rx_copybreak, "3c59x copy breakpoint for copy-only-tiny-frames");
 309MODULE_PARM_DESC(max_interrupt_work, "3c59x maximum events handled per interrupt");
 310MODULE_PARM_DESC(compaq_ioaddr, "3c59x PCI I/O base address (Compaq BIOS problem workaround)");
 311MODULE_PARM_DESC(compaq_irq, "3c59x PCI IRQ number (Compaq BIOS problem workaround)");
 312MODULE_PARM_DESC(compaq_device_id, "3c59x PCI device ID (Compaq BIOS problem workaround)");
 313MODULE_PARM_DESC(watchdog, "3c59x transmit timeout in milliseconds");
 314
 315/* Operational parameter that usually are not changed. */
 316
 317/* The Vortex size is twice that of the original EtherLinkIII series: the
 318   runtime register window, window 1, is now always mapped in.
 319   The Boomerang size is twice as large as the Vortex -- it has additional
 320   bus master control registers. */
 321#define VORTEX_TOTAL_SIZE 0x20
 322#define BOOMERANG_TOTAL_SIZE 0x40
 323
 324/* Set iff a MII transceiver on any interface requires mdio preamble.
 325   This only set with the original DP83840 on older 3c905 boards, so the extra
 326   code size of a per-interface flag is not worthwhile. */
 327static char mii_preamble_required;
 328
 329#define PFX DRV_NAME ": "
 330
 331
 332
 333/*
 334                                Theory of Operation
 335
 336I. Board Compatibility
 337
 338This device driver is designed for the 3Com FastEtherLink and FastEtherLink
 339XL, 3Com's PCI to 10/100baseT adapters.  It also works with the 10Mbs
 340versions of the FastEtherLink cards.  The supported product IDs are
 341  3c590, 3c592, 3c595, 3c597, 3c900, 3c905
 342
 343The related ISA 3c515 is supported with a separate driver, 3c515.c, included
 344with the kernel source or available from
 345    cesdis.gsfc.nasa.gov:/pub/linux/drivers/3c515.html
 346
 347II. Board-specific settings
 348
 349PCI bus devices are configured by the system at boot time, so no jumpers
 350need to be set on the board.  The system BIOS should be set to assign the
 351PCI INTA signal to an otherwise unused system IRQ line.
 352
 353The EEPROM settings for media type and forced-full-duplex are observed.
 354The EEPROM media type should be left at the default "autoselect" unless using
 35510base2 or AUI connections which cannot be reliably detected.
 356
 357III. Driver operation
 358
 359The 3c59x series use an interface that's very similar to the previous 3c5x9
 360series.  The primary interface is two programmed-I/O FIFOs, with an
 361alternate single-contiguous-region bus-master transfer (see next).
 362
 363The 3c900 "Boomerang" series uses a full-bus-master interface with separate
 364lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,
 365DEC Tulip and Intel Speedo3.  The first chip version retains a compatible
 366programmed-I/O interface that has been removed in 'B' and subsequent board
 367revisions.
 368
 369One extension that is advertised in a very large font is that the adapters
 370are capable of being bus masters.  On the Vortex chip this capability was
 371only for a single contiguous region making it far less useful than the full
 372bus master capability.  There is a significant performance impact of taking
 373an extra interrupt or polling for the completion of each transfer, as well
 374as difficulty sharing the single transfer engine between the transmit and
 375receive threads.  Using DMA transfers is a win only with large blocks or
 376with the flawed versions of the Intel Orion motherboard PCI controller.
 377
 378The Boomerang chip's full-bus-master interface is useful, and has the
 379currently-unused advantages over other similar chips that queued transmit
 380packets may be reordered and receive buffer groups are associated with a
 381single frame.
 382
 383With full-bus-master support, this driver uses a "RX_COPYBREAK" scheme.
 384Rather than a fixed intermediate receive buffer, this scheme allocates
 385full-sized skbuffs as receive buffers.  The value RX_COPYBREAK is used as
 386the copying breakpoint: it is chosen to trade-off the memory wasted by
 387passing the full-sized skbuff to the queue layer for all frames vs. the
 388copying cost of copying a frame to a correctly-sized skbuff.
 389
 390IIIC. Synchronization
 391The driver runs as two independent, single-threaded flows of control.  One
 392is the send-packet routine, which enforces single-threaded use by the
 393dev->tbusy flag.  The other thread is the interrupt handler, which is single
 394threaded by the hardware and other software.
 395
 396IV. Notes
 397
 398Thanks to Cameron Spitzer and Terry Murphy of 3Com for providing development
 3993c590, 3c595, and 3c900 boards.
 400The name "Vortex" is the internal 3Com project name for the PCI ASIC, and
 401the EISA version is called "Demon".  According to Terry these names come
 402from rides at the local amusement park.
 403
 404The new chips support both ethernet (1.5K) and FDDI (4.5K) packet sizes!
 405This driver only supports ethernet packets because of the skbuff allocation
 406limit of 4K.
 407*/
 408
 409/* This table drives the PCI probe routines.  It's mostly boilerplate in all
 410   of the drivers, and will likely be provided by some future kernel.
 411*/
 412enum pci_flags_bit {
 413        PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
 414        PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,
 415};
 416
 417enum {  IS_VORTEX=1, IS_BOOMERANG=2, IS_CYCLONE=4, IS_TORNADO=8,
 418        EEPROM_8BIT=0x10,       /* AKPM: Uses 0x230 as the base bitmaps for EEPROM reads */
 419        HAS_PWR_CTRL=0x20, HAS_MII=0x40, HAS_NWAY=0x80, HAS_CB_FNS=0x100,
 420        INVERT_MII_PWR=0x200, INVERT_LED_PWR=0x400, MAX_COLLISION_RESET=0x800,
 421        EEPROM_OFFSET=0x1000, HAS_HWCKSM=0x2000, WNO_XCVR_PWR=0x4000,
 422        EXTRA_PREAMBLE=0x8000, };
 423
 424enum vortex_chips {
 425        CH_3C590 = 0,
 426        CH_3C592,
 427        CH_3C597,
 428        CH_3C595_1,
 429        CH_3C595_2,
 430
 431        CH_3C595_3,
 432        CH_3C900_1,
 433        CH_3C900_2,
 434        CH_3C900_3,
 435        CH_3C900_4,
 436
 437        CH_3C900_5,
 438        CH_3C900B_FL,
 439        CH_3C905_1,
 440        CH_3C905_2,
 441        CH_3C905B_1,
 442
 443        CH_3C905B_2,
 444        CH_3C905B_FX,
 445        CH_3C905C,
 446        CH_3C980,
 447        CH_3C9805,
 448
 449        CH_3CSOHO100_TX,
 450        CH_3C555,
 451        CH_3C556,
 452        CH_3C556B,
 453        CH_3C575,
 454
 455        CH_3C575_1,
 456        CH_3CCFE575,
 457        CH_3CCFE575CT,
 458        CH_3CCFE656,
 459        CH_3CCFEM656,
 460
 461        CH_3CCFEM656_1,
 462        CH_3C450,
 463};
 464
 465
 466/* note: this array directly indexed by above enums, and MUST
 467 * be kept in sync with both the enums above, and the PCI device
 468 * table below
 469 */
 470static struct vortex_chip_info {
 471        const char *name;
 472        int flags;
 473        int drv_flags;
 474        int io_size;
 475} vortex_info_tbl[] __devinitdata = {
 476#define EISA_TBL_OFFSET 0               /* Offset of this entry for vortex_eisa_init */
 477        {"3c590 Vortex 10Mbps",
 478         PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
 479        {"3c592 EISA 10Mbps Demon/Vortex",                                      /* AKPM: from Don's 3c59x_cb.c 0.49H */
 480         PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
 481        {"3c597 EISA Fast Demon/Vortex",                                        /* AKPM: from Don's 3c59x_cb.c 0.49H */
 482         PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
 483        {"3c595 Vortex 100baseTx",
 484         PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
 485        {"3c595 Vortex 100baseT4",
 486         PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
 487
 488        {"3c595 Vortex 100base-MII",
 489         PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
 490        {"3c900 Boomerang 10baseT",
 491         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, },
 492        {"3c900 Boomerang 10Mbps Combo",
 493         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, },
 494        {"3c900 Cyclone 10Mbps TPO",                                            /* AKPM: from Don's 0.99M */
 495         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
 496        {"3c900 Cyclone 10Mbps Combo",
 497         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
 498
 499        {"3c900 Cyclone 10Mbps TPC",                                            /* AKPM: from Don's 0.99M */
 500         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
 501        {"3c900B-FL Cyclone 10base-FL",
 502         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
 503        {"3c905 Boomerang 100baseTx",
 504         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, },
 505        {"3c905 Boomerang 100baseT4",
 506         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, },
 507        {"3c905B Cyclone 100baseTx",
 508         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },
 509
 510        {"3c905B Cyclone 10/100/BNC",
 511         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
 512        {"3c905B-FX Cyclone 100baseFx",
 513         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
 514        {"3c905C Tornado",
 515         PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },
 516        {"3c980 Cyclone",
 517         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
 518        {"3c980C Python-T",
 519         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
 520
 521        {"3cSOHO100-TX Hurricane",
 522         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
 523        {"3c555 Laptop Hurricane",
 524         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|EEPROM_8BIT|HAS_HWCKSM, 128, },
 525        {"3c556 Laptop Tornado",
 526         PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|EEPROM_8BIT|HAS_CB_FNS|INVERT_MII_PWR|
 527                                                                        HAS_HWCKSM, 128, },
 528        {"3c556B Laptop Hurricane",
 529         PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|EEPROM_OFFSET|HAS_CB_FNS|INVERT_MII_PWR|
 530                                        WNO_XCVR_PWR|HAS_HWCKSM, 128, },
 531        {"3c575 [Megahertz] 10/100 LAN  CardBus",
 532        PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_8BIT, 128, },
 533
 534        {"3c575 Boomerang CardBus",
 535         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_8BIT, 128, },
 536        {"3CCFE575BT Cyclone CardBus",
 537         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|
 538                                                                        INVERT_LED_PWR|HAS_HWCKSM, 128, },
 539        {"3CCFE575CT Tornado CardBus",
 540         PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
 541                                                                        MAX_COLLISION_RESET|HAS_HWCKSM, 128, },
 542        {"3CCFE656 Cyclone CardBus",
 543         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
 544                                                                        INVERT_LED_PWR|HAS_HWCKSM, 128, },
 545        {"3CCFEM656B Cyclone+Winmodem CardBus",
 546         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
 547                                                                        INVERT_LED_PWR|HAS_HWCKSM, 128, },
 548
 549        {"3CXFEM656C Tornado+Winmodem CardBus",                 /* From pcmcia-cs-3.1.5 */
 550         PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
 551                                                                        MAX_COLLISION_RESET|HAS_HWCKSM, 128, },
 552        {"3c450 HomePNA Tornado",                                               /* AKPM: from Don's 0.99Q */
 553         PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },
 554        {0,}, /* 0 terminated list. */
 555};
 556
 557
 558static struct pci_device_id vortex_pci_tbl[] __devinitdata = {
 559        { 0x10B7, 0x5900, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C590 },
 560        { 0x10B7, 0x5920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C592 },
 561        { 0x10B7, 0x5970, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C597 },
 562        { 0x10B7, 0x5950, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_1 },
 563        { 0x10B7, 0x5951, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_2 },
 564
 565        { 0x10B7, 0x5952, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_3 },
 566        { 0x10B7, 0x9000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_1 },
 567        { 0x10B7, 0x9001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_2 },
 568        { 0x10B7, 0x9004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_3 },
 569        { 0x10B7, 0x9005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_4 },
 570
 571        { 0x10B7, 0x9006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_5 },
 572        { 0x10B7, 0x900A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900B_FL },
 573        { 0x10B7, 0x9050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905_1 },
 574        { 0x10B7, 0x9051, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905_2 },
 575        { 0x10B7, 0x9055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_1 },
 576
 577        { 0x10B7, 0x9058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_2 },
 578        { 0x10B7, 0x905A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_FX },
 579        { 0x10B7, 0x9200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905C },
 580        { 0x10B7, 0x9800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C980 },
 581        { 0x10B7, 0x9805, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C9805 },
 582
 583        { 0x10B7, 0x7646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CSOHO100_TX },
 584        { 0x10B7, 0x5055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C555 },
 585        { 0x10B7, 0x6055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C556 },
 586        { 0x10B7, 0x6056, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C556B },
 587        { 0x10B7, 0x5b57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C575 },
 588
 589        { 0x10B7, 0x5057, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C575_1 },
 590        { 0x10B7, 0x5157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE575 },
 591        { 0x10B7, 0x5257, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE575CT },
 592        { 0x10B7, 0x6560, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE656 },
 593        { 0x10B7, 0x6562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFEM656 },
 594
 595        { 0x10B7, 0x6564, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFEM656_1 },
 596        { 0x10B7, 0x4500, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C450 },
 597        {0,}                                            /* 0 terminated list. */
 598};
 599MODULE_DEVICE_TABLE(pci, vortex_pci_tbl);
 600
 601
 602/* Operational definitions.
 603   These are not used by other compilation units and thus are not
 604   exported in a ".h" file.
 605
 606   First the windows.  There are eight register windows, with the command
 607   and status registers available in each.
 608   */
 609#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
 610#define EL3_CMD 0x0e
 611#define EL3_STATUS 0x0e
 612
 613/* The top five bits written to EL3_CMD are a command, the lower
 614   11 bits are the parameter, if applicable.
 615   Note that 11 parameters bits was fine for ethernet, but the new chip
 616   can handle FDDI length frames (~4500 octets) and now parameters count
 617   32-bit 'Dwords' rather than octets. */
 618
 619enum vortex_cmd {
 620        TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
 621        RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11,
 622        UpStall = 6<<11, UpUnstall = (6<<11)+1,
 623        DownStall = (6<<11)+2, DownUnstall = (6<<11)+3,
 624        RxDiscard = 8<<11, TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
 625        FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
 626        SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
 627        SetTxThreshold = 18<<11, SetTxStart = 19<<11,
 628        StartDMAUp = 20<<11, StartDMADown = (20<<11)+1, StatsEnable = 21<<11,
 629        StatsDisable = 22<<11, StopCoax = 23<<11, SetFilterBit = 25<<11,};
 630
 631/* The SetRxFilter command accepts the following classes: */
 632enum RxFilter {
 633        RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
 634
 635/* Bits in the general status register. */
 636enum vortex_status {
 637        IntLatch = 0x0001, HostError = 0x0002, TxComplete = 0x0004,
 638        TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
 639        IntReq = 0x0040, StatsFull = 0x0080,
 640        DMADone = 1<<8, DownComplete = 1<<9, UpComplete = 1<<10,
 641        DMAInProgress = 1<<11,                  /* DMA controller is still busy.*/
 642        CmdInProgress = 1<<12,                  /* EL3_CMD is still busy.*/
 643};
 644
 645/* Register window 1 offsets, the window used in normal operation.
 646   On the Vortex this window is always mapped at offsets 0x10-0x1f. */
 647enum Window1 {
 648        TX_FIFO = 0x10,  RX_FIFO = 0x10,  RxErrors = 0x14,
 649        RxStatus = 0x18,  Timer=0x1A, TxStatus = 0x1B,
 650        TxFree = 0x1C, /* Remaining free bytes in Tx buffer. */
 651};
 652enum Window0 {
 653        Wn0EepromCmd = 10,              /* Window 0: EEPROM command register. */
 654        Wn0EepromData = 12,             /* Window 0: EEPROM results register. */
 655        IntrStatus=0x0E,                /* Valid in all windows. */
 656};
 657enum Win0_EEPROM_bits {
 658        EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0,
 659        EEPROM_EWENB = 0x30,            /* Enable erasing/writing for 10 msec. */
 660        EEPROM_EWDIS = 0x00,            /* Disable EWENB before 10 msec timeout. */
 661};
 662/* EEPROM locations. */
 663enum eeprom_offset {
 664        PhysAddr01=0, PhysAddr23=1, PhysAddr45=2, ModelID=3,
 665        EtherLink3ID=7, IFXcvrIO=8, IRQLine=9,
 666        NodeAddr01=10, NodeAddr23=11, NodeAddr45=12,
 667        DriverTune=13, Checksum=15};
 668
 669enum Window2 {                  /* Window 2. */
 670        Wn2_ResetOptions=12,
 671};
 672enum Window3 {                  /* Window 3: MAC/config bits. */
 673        Wn3_Config=0, Wn3_MAC_Ctrl=6, Wn3_Options=8,
 674};
 675
 676#define BFEXT(value, offset, bitcount)  \
 677    ((((unsigned long)(value)) >> (offset)) & ((1 << (bitcount)) - 1))
 678
 679#define BFINS(lhs, rhs, offset, bitcount)                                       \
 680        (((lhs) & ~((((1 << (bitcount)) - 1)) << (offset))) |   \
 681        (((rhs) & ((1 << (bitcount)) - 1)) << (offset)))
 682
 683#define RAM_SIZE(v)             BFEXT(v, 0, 3)
 684#define RAM_WIDTH(v)    BFEXT(v, 3, 1)
 685#define RAM_SPEED(v)    BFEXT(v, 4, 2)
 686#define ROM_SIZE(v)             BFEXT(v, 6, 2)
 687#define RAM_SPLIT(v)    BFEXT(v, 16, 2)
 688#define XCVR(v)                 BFEXT(v, 20, 4)
 689#define AUTOSELECT(v)   BFEXT(v, 24, 1)
 690
 691enum Window4 {          /* Window 4: Xcvr/media bits. */
 692        Wn4_FIFODiag = 4, Wn4_NetDiag = 6, Wn4_PhysicalMgmt=8, Wn4_Media = 10,
 693};
 694enum Win4_Media_bits {
 695        Media_SQE = 0x0008,             /* Enable SQE error counting for AUI. */
 696        Media_10TP = 0x00C0,    /* Enable link beat and jabber for 10baseT. */
 697        Media_Lnk = 0x0080,             /* Enable just link beat for 100TX/100FX. */
 698        Media_LnkBeat = 0x0800,
 699};
 700enum Window7 {                                  /* Window 7: Bus Master control. */
 701        Wn7_MasterAddr = 0, Wn7_MasterLen = 6, Wn7_MasterStatus = 12,
 702};
 703/* Boomerang bus master control registers. */
 704enum MasterCtrl {
 705        PktStatus = 0x20, DownListPtr = 0x24, FragAddr = 0x28, FragLen = 0x2c,
 706        TxFreeThreshold = 0x2f, UpPktStatus = 0x30, UpListPtr = 0x38,
 707};
 708
 709/* The Rx and Tx descriptor lists.
 710   Caution Alpha hackers: these types are 32 bits!  Note also the 8 byte
 711   alignment contraint on tx_ring[] and rx_ring[]. */
 712#define LAST_FRAG       0x80000000                      /* Last Addr/Len pair in descriptor. */
 713#define DN_COMPLETE     0x00010000                      /* This packet has been downloaded */
 714struct boom_rx_desc {
 715        u32 next;                                       /* Last entry points to 0.   */
 716        s32 status;
 717        u32 addr;                                       /* Up to 63 addr/len pairs possible. */
 718        s32 length;                                     /* Set LAST_FRAG to indicate last pair. */
 719};
 720/* Values for the Rx status entry. */
 721enum rx_desc_status {
 722        RxDComplete=0x00008000, RxDError=0x4000,
 723        /* See boomerang_rx() for actual error bits */
 724        IPChksumErr=1<<25, TCPChksumErr=1<<26, UDPChksumErr=1<<27,
 725        IPChksumValid=1<<29, TCPChksumValid=1<<30, UDPChksumValid=1<<31,
 726};
 727
 728#ifdef MAX_SKB_FRAGS
 729#define DO_ZEROCOPY 1
 730#else
 731#define DO_ZEROCOPY 0
 732#endif
 733
 734struct boom_tx_desc {
 735        u32 next;                                       /* Last entry points to 0.   */
 736        s32 status;                                     /* bits 0:12 length, others see below.  */
 737#if DO_ZEROCOPY
 738        struct {
 739                u32 addr;
 740                s32 length;
 741        } frag[1+MAX_SKB_FRAGS];
 742#else
 743                u32 addr;
 744                s32 length;
 745#endif
 746};
 747
 748/* Values for the Tx status entry. */
 749enum tx_desc_status {
 750        CRCDisable=0x2000, TxDComplete=0x8000,
 751        AddIPChksum=0x02000000, AddTCPChksum=0x04000000, AddUDPChksum=0x08000000,
 752        TxIntrUploaded=0x80000000,              /* IRQ when in FIFO, but maybe not sent. */
 753};
 754
 755/* Chip features we care about in vp->capabilities, read from the EEPROM. */
 756enum ChipCaps { CapBusMaster=0x20, CapPwrMgmt=0x2000 };
 757
 758struct vortex_private {
 759        /* The Rx and Tx rings should be quad-word-aligned. */
 760        struct boom_rx_desc* rx_ring;
 761        struct boom_tx_desc* tx_ring;
 762        dma_addr_t rx_ring_dma;
 763        dma_addr_t tx_ring_dma;
 764        /* The addresses of transmit- and receive-in-place skbuffs. */
 765        struct sk_buff* rx_skbuff[RX_RING_SIZE];
 766        struct sk_buff* tx_skbuff[TX_RING_SIZE];
 767        struct net_device *next_module;         /* NULL if PCI device */
 768        unsigned int cur_rx, cur_tx;            /* The next free ring entry */
 769        unsigned int dirty_rx, dirty_tx;        /* The ring entries to be free()ed. */
 770        struct net_device_stats stats;
 771        struct sk_buff *tx_skb;                         /* Packet being eaten by bus master ctrl.  */
 772        dma_addr_t tx_skb_dma;                          /* Allocated DMA address for bus master ctrl DMA.   */
 773
 774        /* PCI configuration space information. */
 775        struct pci_dev *pdev;
 776        char *cb_fn_base;                                       /* CardBus function status addr space. */
 777
 778        /* Some values here only for performance evaluation and path-coverage */
 779        int rx_nocopy, rx_copy, queued_packet, rx_csumhits;
 780        int card_idx;
 781
 782        /* The remainder are related to chip state, mostly media selection. */
 783        struct timer_list timer;                        /* Media selection timer. */
 784        struct timer_list rx_oom_timer;         /* Rx skb allocation retry timer */
 785        int options;                                            /* User-settable misc. driver options. */
 786        unsigned int media_override:4,          /* Passed-in media type. */
 787                default_media:4,                                /* Read from the EEPROM/Wn3_Config. */
 788                full_duplex:1, force_fd:1, autoselect:1,
 789                bus_master:1,                                   /* Vortex can only do a fragment bus-m. */
 790                full_bus_master_tx:1, full_bus_master_rx:2, /* Boomerang  */
 791                flow_ctrl:1,                                    /* Use 802.3x flow control (PAUSE only) */
 792                partner_flow_ctrl:1,                    /* Partner supports flow control */
 793                has_nway:1,
 794                enable_wol:1,                                   /* Wake-on-LAN is enabled */
 795                pm_state_valid:1,                               /* power_state[] has sane contents */
 796                open:1,
 797                medialock:1,
 798                must_free_region:1;                             /* Flag: if zero, Cardbus owns the I/O region */
 799        int drv_flags;
 800        u16 status_enable;
 801        u16 intr_enable;
 802        u16 available_media;                            /* From Wn3_Options. */
 803        u16 capabilities, info1, info2;         /* Various, from EEPROM. */
 804        u16 advertising;                                        /* NWay media advertisement */
 805        unsigned char phys[2];                          /* MII device addresses. */
 806        u16 deferred;                                           /* Resend these interrupts when we
 807                                                                                 * bale from the ISR */
 808        u16 io_size;                                            /* Size of PCI region (for release_region) */
 809        spinlock_t lock;                                        /* Serialise access to device & its vortex_private */
 810        spinlock_t mdio_lock;                           /* Serialise access to mdio hardware */
 811        u32 power_state[16];
 812};
 813
 814/* The action to take with a media selection timer tick.
 815   Note that we deviate from the 3Com order by checking 10base2 before AUI.
 816 */
 817enum xcvr_types {
 818        XCVR_10baseT=0, XCVR_AUI, XCVR_10baseTOnly, XCVR_10base2, XCVR_100baseTx,
 819        XCVR_100baseFx, XCVR_MII=6, XCVR_NWAY=8, XCVR_ExtMII=9, XCVR_Default=10,
 820};
 821
 822static struct media_table {
 823        char *name;
 824        unsigned int media_bits:16,             /* Bits to set in Wn4_Media register. */
 825                mask:8,                                         /* The transceiver-present bit in Wn3_Config.*/
 826                next:8;                                         /* The media type to try next. */
 827        int wait;                                               /* Time before we check media status. */
 828} media_tbl[] = {
 829  {     "10baseT",   Media_10TP,0x08, XCVR_10base2, (14*HZ)/10},
 830  { "10Mbs AUI", Media_SQE, 0x20, XCVR_Default, (1*HZ)/10},
 831  { "undefined", 0,                     0x80, XCVR_10baseT, 10000},
 832  { "10base2",   0,                     0x10, XCVR_AUI,         (1*HZ)/10},
 833  { "100baseTX", Media_Lnk, 0x02, XCVR_100baseFx, (14*HZ)/10},
 834  { "100baseFX", Media_Lnk, 0x04, XCVR_MII,             (14*HZ)/10},
 835  { "MII",               0,                     0x41, XCVR_10baseT, 3*HZ },
 836  { "undefined", 0,                     0x01, XCVR_10baseT, 10000},
 837  { "Autonegotiate", 0,         0x41, XCVR_10baseT, 3*HZ},
 838  { "MII-External",      0,             0x41, XCVR_10baseT, 3*HZ },
 839  { "Default",   0,                     0xFF, XCVR_10baseT, 10000},
 840};
 841
 842static int vortex_probe1(struct pci_dev *pdev, long ioaddr, int irq,
 843                                   int chip_idx, int card_idx);
 844static void vortex_up(struct net_device *dev);
 845static void vortex_down(struct net_device *dev);
 846static int vortex_open(struct net_device *dev);
 847static void mdio_sync(long ioaddr, int bits);
 848static int mdio_read(struct net_device *dev, int phy_id, int location);
 849static void mdio_write(struct net_device *vp, int phy_id, int location, int value);
 850static void vortex_timer(unsigned long arg);
 851static void rx_oom_timer(unsigned long arg);
 852static int vortex_start_xmit(struct sk_buff *skb, struct net_device *dev);
 853static int boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev);
 854static int vortex_rx(struct net_device *dev);
 855static int boomerang_rx(struct net_device *dev);
 856static void vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs);
 857static void boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs);
 858static int vortex_close(struct net_device *dev);
 859static void dump_tx_ring(struct net_device *dev);
 860static void update_stats(long ioaddr, struct net_device *dev);
 861static struct net_device_stats *vortex_get_stats(struct net_device *dev);
 862static void set_rx_mode(struct net_device *dev);
 863static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 864static void vortex_tx_timeout(struct net_device *dev);
 865static void acpi_set_WOL(struct net_device *dev);
 866
 867/* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
 868/* Option count limit only -- unlimited interfaces are supported. */
 869#define MAX_UNITS 8
 870static int options[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1,};
 871static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
 872static int hw_checksums[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
 873static int flow_ctrl[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
 874static int enable_wol[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
 875static int global_options = -1;
 876static int global_full_duplex = -1;
 877static int global_enable_wol = -1;
 878
 879/* #define dev_alloc_skb dev_alloc_skb_debug */
 880
 881/* A list of all installed Vortex EISA devices, for removing the driver module. */
 882static struct net_device *root_vortex_eisa_dev;
 883
 884/* Variables to work-around the Compaq PCI BIOS32 problem. */
 885static int compaq_ioaddr, compaq_irq, compaq_device_id = 0x5900;
 886
 887static int vortex_cards_found;
 888
 889#ifdef CONFIG_PM
 890
 891static int vortex_suspend (struct pci_dev *pdev, u32 state)
 892{
 893        struct net_device *dev = pci_get_drvdata(pdev);
 894
 895        if (dev && dev->priv) {
 896                if (netif_running(dev)) {
 897                        netif_device_detach(dev);
 898                        vortex_down(dev);
 899                }
 900        }
 901        return 0;
 902}
 903
 904static int vortex_resume (struct pci_dev *pdev)
 905{
 906        struct net_device *dev = pci_get_drvdata(pdev);
 907
 908        if (dev && dev->priv) {
 909                if (netif_running(dev)) {
 910                        vortex_up(dev);
 911                        netif_device_attach(dev);
 912                }
 913        }
 914        return 0;
 915}
 916
 917#endif /* CONFIG_PM */
 918
 919/* returns count found (>= 0), or negative on error */
 920static int __init vortex_eisa_init (void)
 921{
 922        long ioaddr;
 923        int rc;
 924        int orig_cards_found = vortex_cards_found;
 925
 926        /* Now check all slots of the EISA bus. */
 927        if (!EISA_bus)
 928                return 0;
 929
 930        for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
 931                int device_id;
 932
 933                if (request_region(ioaddr, VORTEX_TOTAL_SIZE, DRV_NAME) == NULL)
 934                        continue;
 935
 936                /* Check the standard EISA ID register for an encoded '3Com'. */
 937                if (inw(ioaddr + 0xC80) != 0x6d50) {
 938                        release_region (ioaddr, VORTEX_TOTAL_SIZE);
 939                        continue;
 940                }
 941
 942                /* Check for a product that we support, 3c59{2,7} any rev. */
 943                device_id = (inb(ioaddr + 0xC82)<<8) + inb(ioaddr + 0xC83);
 944                if ((device_id & 0xFF00) != 0x5900) {
 945                        release_region (ioaddr, VORTEX_TOTAL_SIZE);
 946                        continue;
 947                }
 948
 949                rc = vortex_probe1(NULL, ioaddr, inw(ioaddr + 0xC88) >> 12,
 950                                   EISA_TBL_OFFSET, vortex_cards_found);
 951                if (rc == 0)
 952                        vortex_cards_found++;
 953                else
 954                        release_region (ioaddr, VORTEX_TOTAL_SIZE);
 955        }
 956
 957        /* Special code to work-around the Compaq PCI BIOS32 problem. */
 958        if (compaq_ioaddr) {
 959                vortex_probe1(NULL, compaq_ioaddr, compaq_irq,
 960                                          compaq_device_id, vortex_cards_found++);
 961        }
 962
 963        return vortex_cards_found - orig_cards_found;
 964}
 965
 966/* returns count (>= 0), or negative on error */
 967static int __devinit vortex_init_one (struct pci_dev *pdev,
 968                                      const struct pci_device_id *ent)
 969{
 970        int rc;
 971
 972        /* wake up and enable device */         
 973        if (pci_enable_device (pdev)) {
 974                rc = -EIO;
 975        } else {
 976                rc = vortex_probe1 (pdev, pci_resource_start (pdev, 0), pdev->irq,
 977                                    ent->driver_data, vortex_cards_found);
 978                if (rc == 0)
 979                        vortex_cards_found++;
 980        }
 981        return rc;
 982}
 983
 984/*
 985 * Start up the PCI device which is described by *pdev.
 986 * Return 0 on success.
 987 *
 988 * NOTE: pdev can be NULL, for the case of an EISA driver
 989 */
 990static int __devinit vortex_probe1(struct pci_dev *pdev,
 991                                   long ioaddr, int irq,
 992                                   int chip_idx, int card_idx)
 993{
 994        struct vortex_private *vp;
 995        int option;
 996        unsigned int eeprom[0x40], checksum = 0;                /* EEPROM contents */
 997        int i, step;
 998        struct net_device *dev;
 999        static int printed_version;
1000        int retval, print_info;
1001        struct vortex_chip_info * const vci = &vortex_info_tbl[chip_idx];
1002        char *print_name;
1003
1004        if (!printed_version) {
1005                printk (version);
1006                printed_version = 1;
1007        }
1008
1009        print_name = pdev ? pdev->slot_name : "3c59x";
1010
1011        dev = alloc_etherdev(sizeof(*vp));
1012        retval = -ENOMEM;
1013        if (!dev) {
1014                printk (KERN_ERR PFX "unable to allocate etherdev, aborting\n");
1015                goto out;
1016        }
1017        SET_MODULE_OWNER(dev);
1018        vp = dev->priv;
1019
1020        option = global_options;
1021
1022        /* The lower four bits are the media type. */
1023        if (dev->mem_start) {
1024                /*
1025                 * The 'options' param is passed in as the third arg to the
1026                 * LILO 'ether=' argument for non-modular use
1027                 */
1028                option = dev->mem_start;
1029        }
1030        else if (card_idx < MAX_UNITS) {
1031                if (options[card_idx] >= 0)
1032                        option = options[card_idx];
1033        }
1034
1035        if (option > 0) {
1036                if (option & 0x8000)
1037                        vortex_debug = 7;
1038                if (option & 0x4000)
1039                        vortex_debug = 2;
1040                if (option & 0x0400)
1041                        vp->enable_wol = 1;
1042        }
1043
1044        print_info = (vortex_debug > 1);
1045        if (print_info)
1046                printk (KERN_INFO "See Documentation/networking/vortex.txt\n");
1047
1048        printk(KERN_INFO "%s: 3Com %s %s at 0x%lx. Vers " DRV_VERSION "\n",
1049               print_name,
1050               pdev ? "PCI" : "EISA",
1051               vci->name,
1052               ioaddr);
1053
1054        dev->base_addr = ioaddr;
1055        dev->irq = irq;
1056        dev->mtu = mtu;
1057        vp->drv_flags = vci->drv_flags;
1058        vp->has_nway = (vci->drv_flags & HAS_NWAY) ? 1 : 0;
1059        vp->io_size = vci->io_size;
1060        vp->card_idx = card_idx;
1061
1062        /* module list only for EISA devices */
1063        if (pdev == NULL) {
1064                vp->next_module = root_vortex_eisa_dev;
1065                root_vortex_eisa_dev = dev;
1066        }
1067
1068        /* PCI-only startup logic */
1069        if (pdev) {
1070                /* EISA resources already marked, so only PCI needs to do this here */
1071                /* Ignore return value, because Cardbus drivers already allocate for us */
1072                if (request_region(ioaddr, vci->io_size, print_name) != NULL)
1073                        vp->must_free_region = 1;
1074
1075                /* enable bus-mastering if necessary */         
1076                if (vci->flags & PCI_USES_MASTER)
1077                        pci_set_master (pdev);
1078
1079                if (vci->drv_flags & IS_VORTEX) {
1080                        u8 pci_latency;
1081                        u8 new_latency = 248;
1082
1083                        /* Check the PCI latency value.  On the 3c590 series the latency timer
1084                           must be set to the maximum value to avoid data corruption that occurs
1085                           when the timer expires during a transfer.  This bug exists the Vortex
1086                           chip only. */
1087                        pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
1088                        if (pci_latency < new_latency) {
1089                                printk(KERN_INFO "%s: Overriding PCI latency"
1090                                        " timer (CFLT) setting of %d, new value is %d.\n",
1091                                        print_name, pci_latency, new_latency);
1092                                        pci_write_config_byte(pdev, PCI_LATENCY_TIMER, new_latency);
1093                        }
1094                }
1095        }
1096
1097        spin_lock_init(&vp->lock);
1098        spin_lock_init(&vp->mdio_lock);
1099        vp->pdev = pdev;
1100
1101        /* Makes sure rings are at least 16 byte aligned. */
1102        vp->rx_ring = pci_alloc_consistent(pdev, sizeof(struct boom_rx_desc) * RX_RING_SIZE
1103                                           + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
1104                                           &vp->rx_ring_dma);
1105        retval = -ENOMEM;
1106        if (vp->rx_ring == 0)
1107                goto free_region;
1108
1109        vp->tx_ring = (struct boom_tx_desc *)(vp->rx_ring + RX_RING_SIZE);
1110        vp->tx_ring_dma = vp->rx_ring_dma + sizeof(struct boom_rx_desc) * RX_RING_SIZE;
1111
1112        /* if we are a PCI driver, we store info in pdev->driver_data
1113         * instead of a module list */  
1114        if (pdev)
1115                pci_set_drvdata(pdev, dev);
1116
1117        vp->media_override = 7;
1118        if (option >= 0) {
1119                vp->media_override = ((option & 7) == 2)  ?  0  :  option & 15;
1120                if (vp->media_override != 7)
1121                        vp->medialock = 1;
1122                vp->full_duplex = (option & 0x200) ? 1 : 0;
1123                vp->bus_master = (option & 16) ? 1 : 0;
1124        }
1125
1126        if (global_full_duplex > 0)
1127                vp->full_duplex = 1;
1128        if (global_enable_wol > 0)
1129                vp->enable_wol = 1;
1130
1131        if (card_idx < MAX_UNITS) {
1132                if (full_duplex[card_idx] > 0)
1133                        vp->full_duplex = 1;
1134                if (flow_ctrl[card_idx] > 0)
1135                        vp->flow_ctrl = 1;
1136                if (enable_wol[card_idx] > 0)
1137                        vp->enable_wol = 1;
1138        }
1139
1140        vp->force_fd = vp->full_duplex;
1141        vp->options = option;
1142        /* Read the station address from the EEPROM. */
1143        EL3WINDOW(0);
1144        {
1145                int base;
1146
1147                if (vci->drv_flags & EEPROM_8BIT)
1148                        base = 0x230;
1149                else if (vci->drv_flags & EEPROM_OFFSET)
1150                        base = EEPROM_Read + 0x30;
1151                else
1152                        base = EEPROM_Read;
1153
1154                for (i = 0; i < 0x40; i++) {
1155                        int timer;
1156                        outw(base + i, ioaddr + Wn0EepromCmd);
1157                        /* Pause for at least 162 us. for the read to take place. */
1158                        for (timer = 10; timer >= 0; timer--) {
1159                                udelay(162);
1160                                if ((inw(ioaddr + Wn0EepromCmd) & 0x8000) == 0)
1161                                        break;
1162                        }
1163                        eeprom[i] = inw(ioaddr + Wn0EepromData);
1164                }
1165        }
1166        for (i = 0; i < 0x18; i++)
1167                checksum ^= eeprom[i];
1168        checksum = (checksum ^ (checksum >> 8)) & 0xff;
1169        if (checksum != 0x00) {         /* Grrr, needless incompatible change 3Com. */
1170                while (i < 0x21)
1171                        checksum ^= eeprom[i++];
1172                checksum = (checksum ^ (checksum >> 8)) & 0xff;
1173        }
1174        if ((checksum != 0x00) && !(vci->drv_flags & IS_TORNADO))
1175                printk(" ***INVALID CHECKSUM %4.4x*** ", checksum);
1176        for (i = 0; i < 3; i++)
1177                ((u16 *)dev->dev_addr)[i] = htons(eeprom[i + 10]);
1178        if (print_info) {
1179                for (i = 0; i < 6; i++)
1180                        printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
1181        }
1182        EL3WINDOW(2);
1183        for (i = 0; i < 6; i++)
1184                outb(dev->dev_addr[i], ioaddr + i);
1185
1186#ifdef __sparc__
1187        if (print_info)
1188                printk(", IRQ %s\n", __irq_itoa(dev->irq));
1189#else
1190        if (print_info)
1191                printk(", IRQ %d\n", dev->irq);
1192        /* Tell them about an invalid IRQ. */
1193        if (dev->irq <= 0 || dev->irq >= NR_IRQS)
1194                printk(KERN_WARNING " *** Warning: IRQ %d is unlikely to work! ***\n",
1195                           dev->irq);
1196#endif
1197
1198        EL3WINDOW(4);
1199        step = (inb(ioaddr + Wn4_NetDiag) & 0x1e) >> 1;
1200        if (print_info) {
1201                printk(KERN_INFO "  product code %02x%02x rev %02x.%d date %02d-"
1202                        "%02d-%02d\n", eeprom[6]&0xff, eeprom[6]>>8, eeprom[0x14],
1203                        step, (eeprom[4]>>5) & 15, eeprom[4] & 31, eeprom[4]>>9);
1204        }
1205
1206
1207        if (pdev && vci->drv_flags & HAS_CB_FNS) {
1208                unsigned long fn_st_addr;                       /* Cardbus function status space */
1209                unsigned short n;
1210
1211                fn_st_addr = pci_resource_start (pdev, 2);
1212                if (fn_st_addr) {
1213                        vp->cb_fn_base = ioremap(fn_st_addr, 128);
1214                        retval = -ENOMEM;
1215                        if (!vp->cb_fn_base)
1216                                goto free_ring;
1217                }
1218                if (print_info) {
1219                        printk(KERN_INFO "%s: CardBus functions mapped %8.8lx->%p\n",
1220                                print_name, fn_st_addr, vp->cb_fn_base);
1221                }
1222                EL3WINDOW(2);
1223
1224                n = inw(ioaddr + Wn2_ResetOptions) & ~0x4010;
1225                if (vp->drv_flags & INVERT_LED_PWR)
1226                        n |= 0x10;
1227                if (vp->drv_flags & INVERT_MII_PWR)
1228                        n |= 0x4000;
1229                outw(n, ioaddr + Wn2_ResetOptions);
1230                if (vp->drv_flags & WNO_XCVR_PWR) {
1231                        EL3WINDOW(0);
1232                        outw(0x0800, ioaddr);
1233                }
1234        }
1235
1236        /* Extract our information from the EEPROM data. */
1237        vp->info1 = eeprom[13];
1238        vp->info2 = eeprom[15];
1239        vp->capabilities = eeprom[16];
1240
1241        if (vp->info1 & 0x8000) {
1242                vp->full_duplex = 1;
1243                if (print_info)
1244                        printk(KERN_INFO "Full duplex capable\n");
1245        }
1246
1247        {
1248                static const char * ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
1249                unsigned int config;
1250                EL3WINDOW(3);
1251                vp->available_media = inw(ioaddr + Wn3_Options);
1252                if ((vp->available_media & 0xff) == 0)          /* Broken 3c916 */
1253                        vp->available_media = 0x40;
1254                config = inl(ioaddr + Wn3_Config);
1255                if (print_info) {
1256                        printk(KERN_DEBUG "  Internal config register is %4.4x, "
1257                                   "transceivers %#x.\n", config, inw(ioaddr + Wn3_Options));
1258                        printk(KERN_INFO "  %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
1259                                   8 << RAM_SIZE(config),
1260                                   RAM_WIDTH(config) ? "word" : "byte",
1261                                   ram_split[RAM_SPLIT(config)],
1262                                   AUTOSELECT(config) ? "autoselect/" : "",
1263                                   XCVR(config) > XCVR_ExtMII ? "<invalid transceiver>" :
1264                                   media_tbl[XCVR(config)].name);
1265                }
1266                vp->default_media = XCVR(config);
1267                if (vp->default_media == XCVR_NWAY)
1268                        vp->has_nway = 1;
1269                vp->autoselect = AUTOSELECT(config);
1270        }
1271
1272        if (vp->media_override != 7) {
1273                printk(KERN_INFO "%s:  Media override to transceiver type %d (%s).\n",
1274                                print_name, vp->media_override,
1275                                media_tbl[vp->media_override].name);
1276                dev->if_port = vp->media_override;
1277        } else
1278                dev->if_port = vp->default_media;
1279
1280        if ((vp->available_media & 0x4b) || (vci->drv_flags & HAS_NWAY) ||
1281                dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
1282                int phy, phy_idx = 0;
1283                EL3WINDOW(4);
1284                mii_preamble_required++;
1285                if (vp->drv_flags & EXTRA_PREAMBLE)
1286                        mii_preamble_required++;
1287                mdio_sync(ioaddr, 32);
1288                mdio_read(dev, 24, 1);
1289                for (phy = 0; phy < 32 && phy_idx < 1; phy++) {
1290                        int mii_status, phyx;
1291
1292                        /*
1293                         * For the 3c905CX we look at index 24 first, because it bogusly
1294                         * reports an external PHY at all indices
1295                         */
1296                        if (phy == 0)
1297                                phyx = 24;
1298                        else if (phy <= 24)
1299                                phyx = phy - 1;
1300                        else
1301                                phyx = phy;
1302                        mii_status = mdio_read(dev, phyx, 1);
1303                        printk("phy=%d, phyx=%d, mii_status=0x%04x\n",
1304                                phy, phyx, mii_status);
1305                        if (mii_status  &&  mii_status != 0xffff) {
1306                                vp->phys[phy_idx++] = phyx;
1307                                if (print_info) {
1308                                        printk(KERN_INFO "  MII transceiver found at address %d,"
1309                                                " status %4x.\n", phyx, mii_status);
1310                                }
1311                                if ((mii_status & 0x0040) == 0)
1312                                        mii_preamble_required++;
1313                        }
1314                }
1315                mii_preamble_required--;
1316                if (phy_idx == 0) {
1317                        printk(KERN_WARNING"  ***WARNING*** No MII transceivers found!\n");
1318                        vp->phys[0] = 24;
1319                } else {
1320                        vp->advertising = mdio_read(dev, vp->phys[0], 4);
1321                        if (vp->full_duplex) {
1322                                /* Only advertise the FD media types. */
1323                                vp->advertising &= ~0x02A0;
1324                                mdio_write(dev, vp->phys[0], 4, vp->advertising);
1325                        }
1326                }
1327        }
1328
1329        if (vp->capabilities & CapBusMaster) {
1330                vp->full_bus_master_tx = 1;
1331                if (print_info) {
1332                        printk(KERN_INFO "  Enabling bus-master transmits and %s receives.\n",
1333                        (vp->info2 & 1) ? "early" : "whole-frame" );
1334                }
1335                vp->full_bus_master_rx = (vp->info2 & 1) ? 1 : 2;
1336                vp->bus_master = 0;             /* AKPM: vortex only */
1337        }
1338
1339        /* The 3c59x-specific entries in the device structure. */
1340        dev->open = vortex_open;
1341        if (vp->full_bus_master_tx) {
1342                dev->hard_start_xmit = boomerang_start_xmit;
1343                /* Actually, it still should work with iommu. */
1344                dev->features |= NETIF_F_SG;
1345                if (((hw_checksums[card_idx] == -1) && (vp->drv_flags & HAS_HWCKSM)) ||
1346                                        (hw_checksums[card_idx] == 1)) {
1347                                dev->features |= NETIF_F_IP_CSUM;
1348                }
1349        } else {
1350                dev->hard_start_xmit = vortex_start_xmit;
1351        }
1352
1353        if (print_info) {
1354                printk(KERN_INFO "%s: scatter/gather %sabled. h/w checksums %sabled\n",
1355                                print_name,
1356                                (dev->features & NETIF_F_SG) ? "en":"dis",
1357                                (dev->features & NETIF_F_IP_CSUM) ? "en":"dis");
1358        }
1359
1360        dev->stop = vortex_close;
1361        dev->get_stats = vortex_get_stats;
1362        dev->do_ioctl = vortex_ioctl;
1363        dev->set_multicast_list = set_rx_mode;
1364        dev->tx_timeout = vortex_tx_timeout;
1365        dev->watchdog_timeo = (watchdog * HZ) / 1000;
1366        if (pdev && vp->enable_wol) {
1367                vp->pm_state_valid = 1;
1368                pci_save_state(vp->pdev, vp->power_state);
1369                acpi_set_WOL(dev);
1370        }
1371        retval = register_netdev(dev);
1372        if (retval == 0)
1373                return 0;
1374
1375free_ring:
1376        pci_free_consistent(pdev,
1377                                                sizeof(struct boom_rx_desc) * RX_RING_SIZE
1378                                                        + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
1379                                                vp->rx_ring,
1380                                                vp->rx_ring_dma);
1381free_region:
1382        if (vp->must_free_region)
1383                release_region(ioaddr, vci->io_size);
1384        kfree (dev);
1385        printk(KERN_ERR PFX "vortex_probe1 fails.  Returns %d\n", retval);
1386out:
1387        return retval;
1388}
1389
1390static void
1391issue_and_wait(struct net_device *dev, int cmd)
1392{
1393        int i;
1394
1395        outw(cmd, dev->base_addr + EL3_CMD);
1396        for (i = 0; i < 2000; i++) {
1397                if (!(inw(dev->base_addr + EL3_STATUS) & CmdInProgress))
1398                        return;
1399        }
1400
1401        /* OK, that didn't work.  Do it the slow way.  One second */
1402        for (i = 0; i < 100000; i++) {
1403                if (!(inw(dev->base_addr + EL3_STATUS) & CmdInProgress)) {
1404                        if (vortex_debug > 1)
1405                                printk(KERN_INFO "%s: command 0x%04x took %d usecs\n",
1406                                           dev->name, cmd, i * 10);
1407                        return;
1408                }
1409                udelay(10);
1410        }
1411        printk(KERN_ERR "%s: command 0x%04x did not complete! Status=0x%x\n",
1412                           dev->name, cmd, inw(dev->base_addr + EL3_STATUS));
1413}
1414
1415static void
1416vortex_up(struct net_device *dev)
1417{
1418        long ioaddr = dev->base_addr;
1419        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1420        unsigned int config;
1421        int i;
1422
1423        if (vp->pdev && vp->enable_wol) {
1424                pci_set_power_state(vp->pdev, 0);       /* Go active */
1425                pci_restore_state(vp->pdev, vp->power_state);
1426        }
1427
1428        /* Before initializing select the active media port. */
1429        EL3WINDOW(3);
1430        config = inl(ioaddr + Wn3_Config);
1431
1432        if (vp->media_override != 7) {
1433                printk(KERN_INFO "%s: Media override to transceiver %d (%s).\n",
1434                           dev->name, vp->media_override,
1435                           media_tbl[vp->media_override].name);
1436                dev->if_port = vp->media_override;
1437        } else if (vp->autoselect) {
1438                if (vp->has_nway) {
1439                        if (vortex_debug > 1)
1440                                printk(KERN_INFO "%s: using NWAY device table, not %d\n",
1441                                                                dev->name, dev->if_port);
1442                        dev->if_port = XCVR_NWAY;
1443                } else {
1444                        /* Find first available media type, starting with 100baseTx. */
1445                        dev->if_port = XCVR_100baseTx;
1446                        while (! (vp->available_media & media_tbl[dev->if_port].mask))
1447                                dev->if_port = media_tbl[dev->if_port].next;
1448                        if (vortex_debug > 1)
1449                                printk(KERN_INFO "%s: first available media type: %s\n",
1450                                        dev->name, media_tbl[dev->if_port].name);
1451                }
1452        } else {
1453                dev->if_port = vp->default_media;
1454                if (vortex_debug > 1)
1455                        printk(KERN_INFO "%s: using default media %s\n",
1456                                dev->name, media_tbl[dev->if_port].name);
1457        }
1458
1459        init_timer(&vp->timer);
1460        vp->timer.expires = RUN_AT(media_tbl[dev->if_port].wait);
1461        vp->timer.data = (unsigned long)dev;
1462        vp->timer.function = vortex_timer;              /* timer handler */
1463        add_timer(&vp->timer);
1464
1465        init_timer(&vp->rx_oom_timer);
1466        vp->rx_oom_timer.data = (unsigned long)dev;
1467        vp->rx_oom_timer.function = rx_oom_timer;
1468
1469        if (vortex_debug > 1)
1470                printk(KERN_DEBUG "%s: Initial media type %s.\n",
1471                           dev->name, media_tbl[dev->if_port].name);
1472
1473        vp->full_duplex = vp->force_fd;
1474        config = BFINS(config, dev->if_port, 20, 4);
1475        if (vortex_debug > 6)
1476                printk(KERN_DEBUG "vortex_up(): writing 0x%x to InternalConfig\n", config);
1477        outl(config, ioaddr + Wn3_Config);
1478
1479        if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
1480                int mii_reg1, mii_reg5;
1481                EL3WINDOW(4);
1482                /* Read BMSR (reg1) only to clear old status. */
1483                mii_reg1 = mdio_read(dev, vp->phys[0], 1);
1484                mii_reg5 = mdio_read(dev, vp->phys[0], 5);
1485                if (mii_reg5 == 0xffff  ||  mii_reg5 == 0x0000) {
1486                        netif_carrier_off(dev); /* No MII device or no link partner report */
1487                } else {
1488                        mii_reg5 &= vp->advertising;
1489                        if ((mii_reg5 & 0x0100) != 0    /* 100baseTx-FD */
1490                                 || (mii_reg5 & 0x00C0) == 0x0040) /* 10T-FD, but not 100-HD */
1491                        vp->full_duplex = 1;
1492                        netif_carrier_on(dev);
1493                }
1494                vp->partner_flow_ctrl = ((mii_reg5 & 0x0400) != 0);
1495                if (vortex_debug > 1)
1496                        printk(KERN_INFO "%s: MII #%d status %4.4x, link partner capability %4.4x,"
1497                                   " info1 %04x, setting %s-duplex.\n",
1498                                        dev->name, vp->phys[0],
1499                                        mii_reg1, mii_reg5,
1500                                        vp->info1, ((vp->info1 & 0x8000) || vp->full_duplex) ? "full" : "half");
1501                EL3WINDOW(3);
1502        }
1503
1504        /* Set the full-duplex bit. */
1505        outw(   ((vp->info1 & 0x8000) || vp->full_duplex ? 0x20 : 0) |
1506                        (dev->mtu > 1500 ? 0x40 : 0) |
1507                        ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 0x100 : 0),
1508                        ioaddr + Wn3_MAC_Ctrl);
1509
1510        if (vortex_debug > 1) {
1511                printk(KERN_DEBUG "%s: vortex_up() InternalConfig %8.8x.\n",
1512                        dev->name, config);
1513        }
1514
1515        issue_and_wait(dev, TxReset);
1516        /*
1517         * Don't reset the PHY - that upsets autonegotiation during DHCP operations.
1518         */
1519        issue_and_wait(dev, RxReset|0x04);
1520
1521        outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
1522
1523        if (vortex_debug > 1) {
1524                EL3WINDOW(4);
1525                printk(KERN_DEBUG "%s: vortex_up() irq %d media status %4.4x.\n",
1526                           dev->name, dev->irq, inw(ioaddr + Wn4_Media));
1527        }
1528
1529        /* Set the station address and mask in window 2 each time opened. */
1530        EL3WINDOW(2);
1531        for (i = 0; i < 6; i++)
1532                outb(dev->dev_addr[i], ioaddr + i);
1533        for (; i < 12; i+=2)
1534                outw(0, ioaddr + i);
1535
1536        if (vp->cb_fn_base) {
1537                unsigned short n = inw(ioaddr + Wn2_ResetOptions) & ~0x4010;
1538                if (vp->drv_flags & INVERT_LED_PWR)
1539                        n |= 0x10;
1540                if (vp->drv_flags & INVERT_MII_PWR)
1541                        n |= 0x4000;
1542                outw(n, ioaddr + Wn2_ResetOptions);
1543        }
1544
1545        if (dev->if_port == XCVR_10base2)
1546                /* Start the thinnet transceiver. We should really wait 50ms...*/
1547                outw(StartCoax, ioaddr + EL3_CMD);
1548        if (dev->if_port != XCVR_NWAY) {
1549                EL3WINDOW(4);
1550                outw((inw(ioaddr + Wn4_Media) & ~(Media_10TP|Media_SQE)) |
1551                         media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
1552        }
1553
1554        /* Switch to the stats window, and clear all stats by reading. */
1555        outw(StatsDisable, ioaddr + EL3_CMD);
1556        EL3WINDOW(6);
1557        for (i = 0; i < 10; i++)
1558                inb(ioaddr + i);
1559        inw(ioaddr + 10);
1560        inw(ioaddr + 12);
1561        /* New: On the Vortex we must also clear the BadSSD counter. */
1562        EL3WINDOW(4);
1563        inb(ioaddr + 12);
1564        /* ..and on the Boomerang we enable the extra statistics bits. */
1565        outw(0x0040, ioaddr + Wn4_NetDiag);
1566
1567        /* Switch to register set 7 for normal use. */
1568        EL3WINDOW(7);
1569
1570        if (vp->full_bus_master_rx) { /* Boomerang bus master. */
1571                vp->cur_rx = vp->dirty_rx = 0;
1572                /* Initialize the RxEarly register as recommended. */
1573                outw(SetRxThreshold + (1536>>2), ioaddr + EL3_CMD);
1574                outl(0x0020, ioaddr + PktStatus);
1575                outl(vp->rx_ring_dma, ioaddr + UpListPtr);
1576        }
1577        if (vp->full_bus_master_tx) {           /* Boomerang bus master Tx. */
1578                vp->cur_tx = vp->dirty_tx = 0;
1579                if (vp->drv_flags & IS_BOOMERANG)
1580                        outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold); /* Room for a packet. */
1581                /* Clear the Rx, Tx rings. */
1582                for (i = 0; i < RX_RING_SIZE; i++)      /* AKPM: this is done in vortex_open, too */
1583                        vp->rx_ring[i].status = 0;
1584                for (i = 0; i < TX_RING_SIZE; i++)
1585                        vp->tx_skbuff[i] = 0;
1586                outl(0, ioaddr + DownListPtr);
1587        }
1588        /* Set receiver mode: presumably accept b-case and phys addr only. */
1589        set_rx_mode(dev);
1590        outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
1591
1592//      issue_and_wait(dev, SetTxStart|0x07ff);
1593        outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
1594        outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
1595        /* Allow status bits to be seen. */
1596        vp->status_enable = SetStatusEnb | HostError|IntReq|StatsFull|TxComplete|
1597                (vp->full_bus_master_tx ? DownComplete : TxAvailable) |
1598                (vp->full_bus_master_rx ? UpComplete : RxComplete) |
1599                (vp->bus_master ? DMADone : 0);
1600        vp->intr_enable = SetIntrEnb | IntLatch | TxAvailable |
1601                (vp->full_bus_master_rx ? 0 : RxComplete) |
1602                StatsFull | HostError | TxComplete | IntReq
1603                | (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete;
1604        outw(vp->status_enable, ioaddr + EL3_CMD);
1605        /* Ack all pending events, and set active indicator mask. */
1606        outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
1607                 ioaddr + EL3_CMD);
1608        outw(vp->intr_enable, ioaddr + EL3_CMD);
1609        if (vp->cb_fn_base)                     /* The PCMCIA people are idiots.  */
1610                writel(0x8000, vp->cb_fn_base + 4);
1611        netif_start_queue (dev);
1612}
1613
1614static int
1615vortex_open(struct net_device *dev)
1616{
1617        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1618        int i;
1619        int retval;
1620
1621        /* Use the now-standard shared IRQ implementation. */
1622        if ((retval = request_irq(dev->irq, vp->full_bus_master_rx ?
1623                                &boomerang_interrupt : &vortex_interrupt, SA_SHIRQ, dev->name, dev))) {
1624                printk(KERN_ERR "%s: Could not reserve IRQ %d\n", dev->name, dev->irq);
1625                goto out;
1626        }
1627
1628        if (vp->full_bus_master_rx) { /* Boomerang bus master. */
1629                if (vortex_debug > 2)
1630                        printk(KERN_DEBUG "%s:  Filling in the Rx ring.\n", dev->name);
1631                for (i = 0; i < RX_RING_SIZE; i++) {
1632                        struct sk_buff *skb;
1633                        vp->rx_ring[i].next = cpu_to_le32(vp->rx_ring_dma + sizeof(struct boom_rx_desc) * (i+1));
1634                        vp->rx_ring[i].status = 0;      /* Clear complete bit. */
1635                        vp->rx_ring[i].length = cpu_to_le32(PKT_BUF_SZ | LAST_FRAG);
1636                        skb = dev_alloc_skb(PKT_BUF_SZ);
1637                        vp->rx_skbuff[i] = skb;
1638                        if (skb == NULL)
1639                                break;                  /* Bad news!  */
1640                        skb->dev = dev;                 /* Mark as being used by this device. */
1641                        skb_reserve(skb, 2);    /* Align IP on 16 byte boundaries */
1642                        vp->rx_ring[i].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->tail, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
1643                }
1644                if (i != RX_RING_SIZE) {
1645                        int j;
1646                        printk(KERN_EMERG "%s: no memory for rx ring\n", dev->name);
1647                        for (j = 0; j < i; j++) {
1648                                if (vp->rx_skbuff[j]) {
1649                                        dev_kfree_skb(vp->rx_skbuff[j]);
1650                                        vp->rx_skbuff[j] = 0;
1651                                }
1652                        }
1653                        retval = -ENOMEM;
1654                        goto out_free_irq;
1655                }
1656                /* Wrap the ring. */
1657                vp->rx_ring[i-1].next = cpu_to_le32(vp->rx_ring_dma);
1658        }
1659
1660        vortex_up(dev);
1661        return 0;
1662
1663out_free_irq:
1664        free_irq(dev->irq, dev);
1665out:
1666        if (vortex_debug > 1)
1667                printk(KERN_ERR "%s: vortex_open() fails: returning %d\n", dev->name, retval);
1668        return retval;
1669}
1670
1671static void
1672vortex_timer(unsigned long data)
1673{
1674        struct net_device *dev = (struct net_device *)data;
1675        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1676        long ioaddr = dev->base_addr;
1677        int next_tick = 60*HZ;
1678        int ok = 0;
1679        int media_status, mii_status, old_window;
1680
1681        if (vortex_debug > 2) {
1682                printk(KERN_DEBUG "%s: Media selection timer tick happened, %s.\n",
1683                           dev->name, media_tbl[dev->if_port].name);
1684                printk(KERN_DEBUG "dev->watchdog_timeo=%d\n", dev->watchdog_timeo);
1685        }
1686
1687        if (vp->medialock)
1688                goto leave_media_alone;
1689        disable_irq(dev->irq);
1690        old_window = inw(ioaddr + EL3_CMD) >> 13;
1691        EL3WINDOW(4);
1692        media_status = inw(ioaddr + Wn4_Media);
1693        switch (dev->if_port) {
1694        case XCVR_10baseT:  case XCVR_100baseTx:  case XCVR_100baseFx:
1695                if (media_status & Media_LnkBeat) {
1696                        netif_carrier_on(dev);
1697                        ok = 1;
1698                        if (vortex_debug > 1)
1699                                printk(KERN_DEBUG "%s: Media %s has link beat, %x.\n",
1700                                           dev->name, media_tbl[dev->if_port].name, media_status);
1701                } else if (vortex_debug > 1) {
1702                        netif_carrier_off(dev);
1703                        printk(KERN_DEBUG "%s: Media %s has no link beat, %x.\n",
1704                                   dev->name, media_tbl[dev->if_port].name, media_status);
1705                }
1706                break;
1707        case XCVR_MII: case XCVR_NWAY:
1708                {
1709                        mii_status = mdio_read(dev, vp->phys[0], 1);
1710                        ok = 1;
1711                        if (vortex_debug > 2)
1712                                printk(KERN_DEBUG "%s: MII transceiver has status %4.4x.\n",
1713                                        dev->name, mii_status);
1714                        if (mii_status & BMSR_LSTATUS) {
1715                                int mii_reg5 = mdio_read(dev, vp->phys[0], 5);
1716                                if (! vp->force_fd  &&  mii_reg5 != 0xffff) {
1717                                        int duplex;
1718
1719                                        mii_reg5 &= vp->advertising;
1720                                        duplex = (mii_reg5&0x0100) || (mii_reg5 & 0x01C0) == 0x0040;
1721                                        if (vp->full_duplex != duplex) {
1722                                                vp->full_duplex = duplex;
1723                                                printk(KERN_INFO "%s: Setting %s-duplex based on MII "
1724                                                        "#%d link partner capability of %4.4x.\n",
1725                                                        dev->name, vp->full_duplex ? "full" : "half",
1726                                                        vp->phys[0], mii_reg5);
1727                                                /* Set the full-duplex bit. */
1728                                                EL3WINDOW(3);
1729                                                outw(   (vp->full_duplex ? 0x20 : 0) |
1730                                                                (dev->mtu > 1500 ? 0x40 : 0) |
1731                                                                ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 0x100 : 0),
1732                                                                ioaddr + Wn3_MAC_Ctrl);
1733                                                if (vortex_debug > 1)
1734                                                        printk(KERN_DEBUG "Setting duplex in Wn3_MAC_Ctrl\n");
1735                                                /* AKPM: bug: should reset Tx and Rx after setting Duplex.  Page 180 */
1736                                        }
1737                                }
1738                                netif_carrier_on(dev);
1739                        } else {
1740                                netif_carrier_off(dev);
1741                        }
1742                }
1743                break;
1744          default:                                      /* Other media types handled by Tx timeouts. */
1745                if (vortex_debug > 1)
1746                  printk(KERN_DEBUG "%s: Media %s has no indication, %x.\n",
1747                                 dev->name, media_tbl[dev->if_port].name, media_status);
1748                ok = 1;
1749        }
1750        if ( ! ok) {
1751                unsigned int config;
1752
1753                do {
1754                        dev->if_port = media_tbl[dev->if_port].next;
1755                } while ( ! (vp->available_media & media_tbl[dev->if_port].mask));
1756                if (dev->if_port == XCVR_Default) { /* Go back to default. */
1757                  dev->if_port = vp->default_media;
1758                  if (vortex_debug > 1)
1759                        printk(KERN_DEBUG "%s: Media selection failing, using default "
1760                                   "%s port.\n",
1761                                   dev->name, media_tbl[dev->if_port].name);
1762                } else {
1763                        if (vortex_debug > 1)
1764                                printk(KERN_DEBUG "%s: Media selection failed, now trying "
1765                                           "%s port.\n",
1766                                           dev->name, media_tbl[dev->if_port].name);
1767                        next_tick = media_tbl[dev->if_port].wait;
1768                }
1769                outw((media_status & ~(Media_10TP|Media_SQE)) |
1770                         media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
1771
1772                EL3WINDOW(3);
1773                config = inl(ioaddr + Wn3_Config);
1774                config = BFINS(config, dev->if_port, 20, 4);
1775                outl(config, ioaddr + Wn3_Config);
1776
1777                outw(dev->if_port == XCVR_10base2 ? StartCoax : StopCoax,
1778                         ioaddr + EL3_CMD);
1779                if (vortex_debug > 1)
1780                        printk(KERN_DEBUG "wrote 0x%08x to Wn3_Config\n", config);
1781                /* AKPM: FIXME: Should reset Rx & Tx here.  P60 of 3c90xc.pdf */
1782        }
1783        EL3WINDOW(old_window);
1784        enable_irq(dev->irq);
1785
1786leave_media_alone:
1787        if (vortex_debug > 2)
1788          printk(KERN_DEBUG "%s: Media selection timer finished, %s.\n",
1789                         dev->name, media_tbl[dev->if_port].name);
1790
1791        mod_timer(&vp->timer, RUN_AT(next_tick));
1792        if (vp->deferred)
1793                outw(FakeIntr, ioaddr + EL3_CMD);
1794        return;
1795}
1796
1797static void vortex_tx_timeout(struct net_device *dev)
1798{
1799        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1800        long ioaddr = dev->base_addr;
1801
1802        printk(KERN_ERR "%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
1803                   dev->name, inb(ioaddr + TxStatus),
1804                   inw(ioaddr + EL3_STATUS));
1805        EL3WINDOW(4);
1806        printk(KERN_ERR "  diagnostics: net %04x media %04x dma %08x fifo %04x\n",
1807                        inw(ioaddr + Wn4_NetDiag),
1808                        inw(ioaddr + Wn4_Media),
1809                        inl(ioaddr + PktStatus),
1810                        inw(ioaddr + Wn4_FIFODiag));
1811        /* Slight code bloat to be user friendly. */
1812        if ((inb(ioaddr + TxStatus) & 0x88) == 0x88)
1813                printk(KERN_ERR "%s: Transmitter encountered 16 collisions --"
1814                           " network cable problem?\n", dev->name);
1815        if (inw(ioaddr + EL3_STATUS) & IntLatch) {
1816                printk(KERN_ERR "%s: Interrupt posted but not delivered --"
1817                           " IRQ blocked by another device?\n", dev->name);
1818                /* Bad idea here.. but we might as well handle a few events. */
1819                {
1820                        /*
1821                         * Block interrupts because vortex_interrupt does a bare spin_lock()
1822                         */
1823                        unsigned long flags;
1824                        local_irq_save(flags);
1825                        if (vp->full_bus_master_tx)
1826                                boomerang_interrupt(dev->irq, dev, 0);
1827                        else
1828                                vortex_interrupt(dev->irq, dev, 0);
1829                        local_irq_restore(flags);
1830                }
1831        }
1832
1833        if (vortex_debug > 0)
1834                dump_tx_ring(dev);
1835
1836        issue_and_wait(dev, TxReset);
1837
1838        vp->stats.tx_errors++;
1839        if (vp->full_bus_master_tx) {
1840                printk(KERN_DEBUG "%s: Resetting the Tx ring pointer.\n", dev->name);
1841                if (vp->cur_tx - vp->dirty_tx > 0  &&  inl(ioaddr + DownListPtr) == 0)
1842                        outl(vp->tx_ring_dma + (vp->dirty_tx % TX_RING_SIZE) * sizeof(struct boom_tx_desc),
1843                                 ioaddr + DownListPtr);
1844                if (vp->cur_tx - vp->dirty_tx < TX_RING_SIZE)
1845                        netif_wake_queue (dev);
1846                if (vp->drv_flags & IS_BOOMERANG)
1847                        outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold);
1848                outw(DownUnstall, ioaddr + EL3_CMD);
1849        } else {
1850                vp->stats.tx_dropped++;
1851                netif_wake_queue(dev);
1852        }
1853        
1854        /* Issue Tx Enable */
1855        outw(TxEnable, ioaddr + EL3_CMD);
1856        dev->trans_start = jiffies;
1857        
1858        /* Switch to register set 7 for normal use. */
1859        EL3WINDOW(7);
1860}
1861
1862/*
1863 * Handle uncommon interrupt sources.  This is a separate routine to minimize
1864 * the cache impact.
1865 */
1866static void
1867vortex_error(struct net_device *dev, int status)
1868{
1869        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1870        long ioaddr = dev->base_addr;
1871        int do_tx_reset = 0, reset_mask = 0;
1872        unsigned char tx_status = 0;
1873
1874        if (vortex_debug > 2) {
1875                printk(KERN_ERR "%s: vortex_error(), status=0x%x\n", dev->name, status);
1876        }
1877
1878        if (status & TxComplete) {                      /* Really "TxError" for us. */
1879                tx_status = inb(ioaddr + TxStatus);
1880                /* Presumably a tx-timeout. We must merely re-enable. */
1881                if (vortex_debug > 2
1882                        || (tx_status != 0x88 && vortex_debug > 0)) {
1883                        printk(KERN_ERR "%s: Transmit error, Tx status register %2.2x.\n",
1884                                   dev->name, tx_status);
1885                        if (tx_status == 0x82) {
1886                                printk(KERN_ERR "Probably a duplex mismatch.  See "
1887                                                "Documentation/networking/vortex.txt\n");
1888                        }
1889                        dump_tx_ring(dev);
1890                }
1891                if (tx_status & 0x14)  vp->stats.tx_fifo_errors++;
1892                if (tx_status & 0x38)  vp->stats.tx_aborted_errors++;
1893                outb(0, ioaddr + TxStatus);
1894                if (tx_status & 0x30) {                 /* txJabber or txUnderrun */
1895                        do_tx_reset = 1;
1896                } else if ((tx_status & 0x08) && (vp->drv_flags & MAX_COLLISION_RESET)) {       /* maxCollisions */
1897                        do_tx_reset = 1;
1898                        reset_mask = 0x0108;            /* Reset interface logic, but not download logic */
1899                } else {                                                /* Merely re-enable the transmitter. */
1900                        outw(TxEnable, ioaddr + EL3_CMD);
1901                }
1902        }
1903
1904        if (status & RxEarly) {                         /* Rx early is unused. */
1905                vortex_rx(dev);
1906                outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
1907        }
1908        if (status & StatsFull) {                       /* Empty statistics. */
1909                static int DoneDidThat;
1910                if (vortex_debug > 4)
1911                        printk(KERN_DEBUG "%s: Updating stats.\n", dev->name);
1912                update_stats(ioaddr, dev);
1913                /* HACK: Disable statistics as an interrupt source. */
1914                /* This occurs when we have the wrong media type! */
1915                if (DoneDidThat == 0  &&
1916                        inw(ioaddr + EL3_STATUS) & StatsFull) {
1917                        printk(KERN_WARNING "%s: Updating statistics failed, disabling "
1918                                   "stats as an interrupt source.\n", dev->name);
1919                        EL3WINDOW(5);
1920                        outw(SetIntrEnb | (inw(ioaddr + 10) & ~StatsFull), ioaddr + EL3_CMD);
1921                        vp->intr_enable &= ~StatsFull;
1922                        EL3WINDOW(7);
1923                        DoneDidThat++;
1924                }
1925        }
1926        if (status & IntReq) {          /* Restore all interrupt sources.  */
1927                outw(vp->status_enable, ioaddr + EL3_CMD);
1928                outw(vp->intr_enable, ioaddr + EL3_CMD);
1929        }
1930        if (status & HostError) {
1931                u16 fifo_diag;
1932                EL3WINDOW(4);
1933                fifo_diag = inw(ioaddr + Wn4_FIFODiag);
1934                printk(KERN_ERR "%s: Host error, FIFO diagnostic register %4.4x.\n",
1935                           dev->name, fifo_diag);
1936                /* Adapter failure requires Tx/Rx reset and reinit. */
1937                if (vp->full_bus_master_tx) {
1938                        int bus_status = inl(ioaddr + PktStatus);
1939                        /* 0x80000000 PCI master abort. */
1940                        /* 0x40000000 PCI target abort. */
1941                        if (vortex_debug)
1942                                printk(KERN_ERR "%s: PCI bus error, bus status %8.8x\n", dev->name, bus_status);
1943
1944                        /* In this case, blow the card away */
1945                        vortex_down(dev);
1946                        issue_and_wait(dev, TotalReset | 0xff);
1947                        vortex_up(dev);         /* AKPM: bug.  vortex_up() assumes that the rx ring is full. It may not be. */
1948                } else if (fifo_diag & 0x0400)
1949                        do_tx_reset = 1;
1950                if (fifo_diag & 0x3000) {
1951                        /* Reset Rx fifo and upload logic */
1952                        issue_and_wait(dev, RxReset|0x07);
1953                        /* Set the Rx filter to the current state. */
1954                        set_rx_mode(dev);
1955                        outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
1956                        outw(AckIntr | HostError, ioaddr + EL3_CMD);
1957                }
1958        }
1959
1960        if (do_tx_reset) {
1961                issue_and_wait(dev, TxReset|reset_mask);
1962                outw(TxEnable, ioaddr + EL3_CMD);
1963                if (!vp->full_bus_master_tx)
1964                        netif_wake_queue(dev);
1965        }
1966}
1967
1968static int
1969vortex_start_xmit(struct sk_buff *skb, struct net_device *dev)
1970{
1971        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1972        long ioaddr = dev->base_addr;
1973
1974        /* Put out the doubleword header... */
1975        outl(skb->len, ioaddr + TX_FIFO);
1976        if (vp->bus_master) {
1977                /* Set the bus-master controller to transfer the packet. */
1978                int len = (skb->len + 3) & ~3;
1979                outl(   vp->tx_skb_dma = pci_map_single(vp->pdev, skb->data, len, PCI_DMA_TODEVICE),
1980                                ioaddr + Wn7_MasterAddr);
1981                outw(len, ioaddr + Wn7_MasterLen);
1982                vp->tx_skb = skb;
1983                outw(StartDMADown, ioaddr + EL3_CMD);
1984                /* netif_wake_queue() will be called at the DMADone interrupt. */
1985        } else {
1986                /* ... and the packet rounded to a doubleword. */
1987                outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
1988                dev_kfree_skb (skb);
1989                if (inw(ioaddr + TxFree) > 1536) {
1990                        netif_start_queue (dev);        /* AKPM: redundant? */
1991                } else {
1992                        /* Interrupt us when the FIFO has room for max-sized packet. */
1993                        netif_stop_queue(dev);
1994                        outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
1995                }
1996        }
1997
1998        dev->trans_start = jiffies;
1999
2000        /* Clear the Tx status stack. */
2001        {
2002                int tx_status;
2003                int i = 32;
2004
2005                while (--i > 0  &&      (tx_status = inb(ioaddr + TxStatus)) > 0) {
2006                        if (tx_status & 0x3C) {         /* A Tx-disabling error occurred.  */
2007                                if (vortex_debug > 2)
2008                                  printk(KERN_DEBUG "%s: Tx error, status %2.2x.\n",
2009                                                 dev->name, tx_status);
2010                                if (tx_status & 0x04) vp->stats.tx_fifo_errors++;
2011                                if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
2012                                if (tx_status & 0x30) {
2013                                        issue_and_wait(dev, TxReset);
2014                                }
2015                                outw(TxEnable, ioaddr + EL3_CMD);
2016                        }
2017                        outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */
2018                }
2019        }
2020        return 0;
2021}
2022
2023static int
2024boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
2025{
2026        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2027        long ioaddr = dev->base_addr;
2028        /* Calculate the next Tx descriptor entry. */
2029        int entry = vp->cur_tx % TX_RING_SIZE;
2030        struct boom_tx_desc *prev_entry = &vp->tx_ring[(vp->cur_tx-1) % TX_RING_SIZE];
2031        unsigned long flags;
2032
2033        if (vortex_debug > 6) {
2034                printk(KERN_DEBUG "boomerang_start_xmit()\n");
2035                if (vortex_debug > 3)
2036                        printk(KERN_DEBUG "%s: Trying to send a packet, Tx index %d.\n",
2037                                   dev->name, vp->cur_tx);
2038        }
2039
2040        if (vp->cur_tx - vp->dirty_tx >= TX_RING_SIZE) {
2041                if (vortex_debug > 0)
2042                        printk(KERN_WARNING "%s: BUG! Tx Ring full, refusing to send buffer.\n",
2043                                   dev->name);
2044                netif_stop_queue(dev);
2045                return 1;
2046        }
2047
2048        vp->tx_skbuff[entry] = skb;
2049
2050        vp->tx_ring[entry].next = 0;
2051#if DO_ZEROCOPY
2052        if (skb->ip_summed != CHECKSUM_HW)
2053                        vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded);
2054        else
2055                        vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded | AddTCPChksum);
2056
2057        if (!skb_shinfo(skb)->nr_frags) {
2058                vp->tx_ring[entry].frag[0].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->data,
2059                                                                                skb->len, PCI_DMA_TODEVICE));
2060                vp->tx_ring[entry].frag[0].length = cpu_to_le32(skb->len | LAST_FRAG);
2061        } else {
2062                int i;
2063
2064                vp->tx_ring[entry].frag[0].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->data,
2065                                                                                skb->len-skb->data_len, PCI_DMA_TODEVICE));
2066                vp->tx_ring[entry].frag[0].length = cpu_to_le32(skb->len-skb->data_len);
2067
2068                for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2069                        skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2070
2071                        vp->tx_ring[entry].frag[i+1].addr =
2072                                        cpu_to_le32(pci_map_single(vp->pdev,
2073                                                                                           (void*)page_address(frag->page) + frag->page_offset,
2074                                                                                           frag->size, PCI_DMA_TODEVICE));
2075
2076                        if (i == skb_shinfo(skb)->nr_frags-1)
2077                                        vp->tx_ring[entry].frag[i+1].length = cpu_to_le32(frag->size|LAST_FRAG);
2078                        else
2079                                        vp->tx_ring[entry].frag[i+1].length = cpu_to_le32(frag->size);
2080                }
2081        }
2082#else
2083        vp->tx_ring[entry].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->data, skb->len, PCI_DMA_TODEVICE));
2084        vp->tx_ring[entry].length = cpu_to_le32(skb->len | LAST_FRAG);
2085        vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded);
2086#endif
2087
2088        spin_lock_irqsave(&vp->lock, flags);
2089        /* Wait for the stall to complete. */
2090        issue_and_wait(dev, DownStall);
2091        prev_entry->next = cpu_to_le32(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc));
2092        if (inl(ioaddr + DownListPtr) == 0) {
2093                outl(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc), ioaddr + DownListPtr);
2094                vp->queued_packet++;
2095        }
2096
2097        vp->cur_tx++;
2098        if (vp->cur_tx - vp->dirty_tx > TX_RING_SIZE - 1) {
2099                netif_stop_queue (dev);
2100        } else {                                        /* Clear previous interrupt enable. */
2101#if defined(tx_interrupt_mitigation)
2102                /* Dubious. If in boomeang_interrupt "faster" cyclone ifdef
2103                 * were selected, this would corrupt DN_COMPLETE. No?
2104                 */
2105                prev_entry->status &= cpu_to_le32(~TxIntrUploaded);
2106#endif
2107        }
2108        outw(DownUnstall, ioaddr + EL3_CMD);
2109        spin_unlock_irqrestore(&vp->lock, flags);
2110        dev->trans_start = jiffies;
2111        return 0;
2112}
2113
2114/* The interrupt handler does all of the Rx thread work and cleans up
2115   after the Tx thread. */
2116
2117/*
2118 * This is the ISR for the vortex series chips.
2119 * full_bus_master_tx == 0 && full_bus_master_rx == 0
2120 */
2121
2122static void vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2123{
2124        struct net_device *dev = dev_id;
2125        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2126        long ioaddr;
2127        int status;
2128        int work_done = max_interrupt_work;
2129        
2130        ioaddr = dev->base_addr;
2131        spin_lock(&vp->lock);
2132
2133        status = inw(ioaddr + EL3_STATUS);
2134
2135        if (vortex_debug > 6)
2136                printk("vortex_interrupt(). status=0x%4x\n", status);
2137
2138        if ((status & IntLatch) == 0)
2139                goto handler_exit;              /* No interrupt: shared IRQs cause this */
2140
2141        if (status & IntReq) {
2142                status |= vp->deferred;
2143                vp->deferred = 0;
2144        }
2145
2146        if (status == 0xffff)           /* h/w no longer present (hotplug)? */
2147                goto handler_exit;
2148
2149        if (vortex_debug > 4)
2150                printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n",
2151                           dev->name, status, inb(ioaddr + Timer));
2152
2153        do {
2154                if (vortex_debug > 5)
2155                                printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n",
2156                                           dev->name, status);
2157                if (status & RxComplete)
2158                        vortex_rx(dev);
2159
2160                if (status & TxAvailable) {
2161                        if (vortex_debug > 5)
2162                                printk(KERN_DEBUG "     TX room bit was handled.\n");
2163                        /* There's room in the FIFO for a full-sized packet. */
2164                        outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
2165                        netif_wake_queue (dev);
2166                }
2167
2168                if (status & DMADone) {
2169                        if (inw(ioaddr + Wn7_MasterStatus) & 0x1000) {
2170                                outw(0x1000, ioaddr + Wn7_MasterStatus); /* Ack the event. */
2171                                pci_unmap_single(vp->pdev, vp->tx_skb_dma, (vp->tx_skb->len + 3) & ~3, PCI_DMA_TODEVICE);
2172                                dev_kfree_skb_irq(vp->tx_skb); /* Release the transferred buffer */
2173                                if (inw(ioaddr + TxFree) > 1536) {
2174                                        /*
2175                                         * AKPM: FIXME: I don't think we need this.  If the queue was stopped due to
2176                                         * insufficient FIFO room, the TxAvailable test will succeed and call
2177                                         * netif_wake_queue()
2178                                         */
2179                                        netif_wake_queue(dev);
2180                                } else { /* Interrupt when FIFO has room for max-sized packet. */
2181                                        outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
2182                                        netif_stop_queue(dev);
2183                                }
2184                        }
2185                }
2186                /* Check for all uncommon interrupts at once. */
2187                if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq)) {
2188                        if (status == 0xffff)
2189                                break;
2190                        vortex_error(dev, status);
2191                }
2192
2193                if (--work_done < 0) {
2194                        printk(KERN_WARNING "%s: Too much work in interrupt, status "
2195                                   "%4.4x.\n", dev->name, status);
2196                        /* Disable all pending interrupts. */
2197                        do {
2198                                vp->deferred |= status;
2199                                outw(SetStatusEnb | (~vp->deferred & vp->status_enable),
2200                                         ioaddr + EL3_CMD);
2201                                outw(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
2202                        } while ((status = inw(ioaddr + EL3_CMD)) & IntLatch);
2203                        /* The timer will reenable interrupts. */
2204                        mod_timer(&vp->timer, jiffies + 1*HZ);
2205                        break;
2206                }
2207                /* Acknowledge the IRQ. */
2208                outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
2209        } while ((status = inw(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete));
2210
2211        if (vortex_debug > 4)
2212                printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
2213                           dev->name, status);
2214handler_exit:
2215        spin_unlock(&vp->lock);
2216}
2217
2218/*
2219 * This is the ISR for the boomerang series chips.
2220 * full_bus_master_tx == 1 && full_bus_master_rx == 1
2221 */
2222
2223static void boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2224{
2225        struct net_device *dev = dev_id;
2226        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2227        long ioaddr;
2228        int status;
2229        int work_done = max_interrupt_work;
2230
2231        ioaddr = dev->base_addr;
2232
2233        /*
2234         * It seems dopey to put the spinlock this early, but we could race against vortex_tx_timeout
2235         * and boomerang_start_xmit
2236         */
2237        spin_lock(&vp->lock);
2238
2239        status = inw(ioaddr + EL3_STATUS);
2240
2241        if (vortex_debug > 6)
2242                printk(KERN_DEBUG "boomerang_interrupt. status=0x%4x\n", status);
2243
2244        if ((status & IntLatch) == 0)
2245                goto handler_exit;              /* No interrupt: shared IRQs can cause this */
2246
2247        if (status == 0xffff) {         /* h/w no longer present (hotplug)? */
2248                if (vortex_debug > 1)
2249                        printk(KERN_DEBUG "boomerang_interrupt(1): status = 0xffff\n");
2250                goto handler_exit;
2251        }
2252
2253        if (status & IntReq) {
2254                status |= vp->deferred;
2255                vp->deferred = 0;
2256        }
2257
2258        if (vortex_debug > 4)
2259                printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n",
2260                           dev->name, status, inb(ioaddr + Timer));
2261        do {
2262                if (vortex_debug > 5)
2263                                printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n",
2264                                           dev->name, status);
2265                if (status & UpComplete) {
2266                        outw(AckIntr | UpComplete, ioaddr + EL3_CMD);
2267                        if (vortex_debug > 5)
2268                                printk(KERN_DEBUG "boomerang_interrupt->boomerang_rx\n");
2269                        boomerang_rx(dev);
2270                }
2271
2272                if (status & DownComplete) {
2273                        unsigned int dirty_tx = vp->dirty_tx;
2274
2275                        outw(AckIntr | DownComplete, ioaddr + EL3_CMD);
2276                        while (vp->cur_tx - dirty_tx > 0) {
2277                                int entry = dirty_tx % TX_RING_SIZE;
2278#if 1   /* AKPM: the latter is faster, but cyclone-only */
2279                                if (inl(ioaddr + DownListPtr) ==
2280                                        vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc))
2281                                        break;                  /* It still hasn't been processed. */
2282#else
2283                                if ((vp->tx_ring[entry].status & DN_COMPLETE) == 0)
2284                                        break;                  /* It still hasn't been processed. */
2285#endif
2286                                        
2287                                if (vp->tx_skbuff[entry]) {
2288                                        struct sk_buff *skb = vp->tx_skbuff[entry];
2289#if DO_ZEROCOPY                                 
2290                                        int i;
2291                                        for (i=0; i<=skb_shinfo(skb)->nr_frags; i++)
2292                                                        pci_unmap_single(vp->pdev,
2293                                                                                         le32_to_cpu(vp->tx_ring[entry].frag[i].addr),
2294                                                                                         le32_to_cpu(vp->tx_ring[entry].frag[i].length)&0xFFF,
2295                                                                                         PCI_DMA_TODEVICE);
2296#else
2297                                        pci_unmap_single(vp->pdev,
2298                                                le32_to_cpu(vp->tx_ring[entry].addr), skb->len, PCI_DMA_TODEVICE);
2299#endif
2300                                        dev_kfree_skb_irq(skb);
2301                                        vp->tx_skbuff[entry] = 0;
2302                                } else {
2303                                        printk(KERN_DEBUG "boomerang_interrupt: no skb!\n");
2304                                }
2305                                /* vp->stats.tx_packets++;  Counted below. */
2306                                dirty_tx++;
2307                        }
2308                        vp->dirty_tx = dirty_tx;
2309                        if (vp->cur_tx - dirty_tx <= TX_RING_SIZE - 1) {
2310                                if (vortex_debug > 6)
2311                                        printk(KERN_DEBUG "boomerang_interrupt: wake queue\n");
2312                                netif_wake_queue (dev);
2313                        }
2314                }
2315
2316                /* Check for all uncommon interrupts at once. */
2317                if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq))
2318                        vortex_error(dev, status);
2319
2320                if (--work_done < 0) {
2321                        printk(KERN_WARNING "%s: Too much work in interrupt, status "
2322                                   "%4.4x.\n", dev->name, status);
2323                        /* Disable all pending interrupts. */
2324                        do {
2325                                vp->deferred |= status;
2326                                outw(SetStatusEnb | (~vp->deferred & vp->status_enable),
2327                                         ioaddr + EL3_CMD);
2328                                outw(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
2329                        } while ((status = inw(ioaddr + EL3_CMD)) & IntLatch);
2330                        /* The timer will reenable interrupts. */
2331                        mod_timer(&vp->timer, jiffies + 1*HZ);
2332                        break;
2333                }
2334                /* Acknowledge the IRQ. */
2335                outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
2336                if (vp->cb_fn_base)                     /* The PCMCIA people are idiots.  */
2337                        writel(0x8000, vp->cb_fn_base + 4);
2338
2339        } while ((status = inw(ioaddr + EL3_STATUS)) & IntLatch);
2340
2341        if (vortex_debug > 4)
2342                printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
2343                           dev->name, status);
2344handler_exit:
2345        spin_unlock(&vp->lock);
2346}
2347
2348static int vortex_rx(struct net_device *dev)
2349{
2350        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2351        long ioaddr = dev->base_addr;
2352        int i;
2353        short rx_status;
2354
2355        if (vortex_debug > 5)
2356                printk(KERN_DEBUG "vortex_rx(): status %4.4x, rx_status %4.4x.\n",
2357                           inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
2358        while ((rx_status = inw(ioaddr + RxStatus)) > 0) {
2359                if (rx_status & 0x4000) { /* Error, update stats. */
2360                        unsigned char rx_error = inb(ioaddr + RxErrors);
2361                        if (vortex_debug > 2)
2362                                printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
2363                        vp->stats.rx_errors++;
2364                        if (rx_error & 0x01)  vp->stats.rx_over_errors++;
2365                        if (rx_error & 0x02)  vp->stats.rx_length_errors++;
2366                        if (rx_error & 0x04)  vp->stats.rx_frame_errors++;
2367                        if (rx_error & 0x08)  vp->stats.rx_crc_errors++;
2368                        if (rx_error & 0x10)  vp->stats.rx_length_errors++;
2369                } else {
2370                        /* The packet length: up to 4.5K!. */
2371                        int pkt_len = rx_status & 0x1fff;
2372                        struct sk_buff *skb;
2373
2374                        skb = dev_alloc_skb(pkt_len + 5);
2375                        if (vortex_debug > 4)
2376                                printk(KERN_DEBUG "Receiving packet size %d status %4.4x.\n",
2377                                           pkt_len, rx_status);
2378                        if (skb != NULL) {
2379                                skb->dev = dev;
2380                                skb_reserve(skb, 2);    /* Align IP on 16 byte boundaries */
2381                                /* 'skb_put()' points to the start of sk_buff data area. */
2382                                if (vp->bus_master &&
2383                                        ! (inw(ioaddr + Wn7_MasterStatus) & 0x8000)) {
2384                                        dma_addr_t dma = pci_map_single(vp->pdev, skb_put(skb, pkt_len),
2385                                                                           pkt_len, PCI_DMA_FROMDEVICE);
2386                                        outl(dma, ioaddr + Wn7_MasterAddr);
2387                                        outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
2388                                        outw(StartDMAUp, ioaddr + EL3_CMD);
2389                                        while (inw(ioaddr + Wn7_MasterStatus) & 0x8000)
2390                                                ;
2391                                        pci_unmap_single(vp->pdev, dma, pkt_len, PCI_DMA_FROMDEVICE);
2392                                } else {
2393                                        insl(ioaddr + RX_FIFO, skb_put(skb, pkt_len),
2394                                                 (pkt_len + 3) >> 2);
2395                                }
2396                                outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
2397                                skb->protocol = eth_type_trans(skb, dev);
2398                                netif_rx(skb);
2399                                dev->last_rx = jiffies;
2400                                vp->stats.rx_packets++;
2401                                /* Wait a limited time to go to next packet. */
2402                                for (i = 200; i >= 0; i--)
2403                                        if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
2404                                                break;
2405                                continue;
2406                        } else if (vortex_debug > 0)
2407                                printk(KERN_NOTICE "%s: No memory to allocate a sk_buff of "
2408                                           "size %d.\n", dev->name, pkt_len);
2409                }
2410                vp->stats.rx_dropped++;
2411                issue_and_wait(dev, RxDiscard);
2412        }
2413
2414        return 0;
2415}
2416
2417static int
2418boomerang_rx(struct net_device *dev)
2419{
2420        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2421        int entry = vp->cur_rx % RX_RING_SIZE;
2422        long ioaddr = dev->base_addr;
2423        int rx_status;
2424        int rx_work_limit = vp->dirty_rx + RX_RING_SIZE - vp->cur_rx;
2425
2426        if (vortex_debug > 5)
2427                printk(KERN_DEBUG "boomerang_rx(): status %4.4x\n", inw(ioaddr+EL3_STATUS));
2428
2429        while ((rx_status = le32_to_cpu(vp->rx_ring[entry].status)) & RxDComplete){
2430                if (--rx_work_limit < 0)
2431                        break;
2432                if (rx_status & RxDError) { /* Error, update stats. */
2433                        unsigned char rx_error = rx_status >> 16;
2434                        if (vortex_debug > 2)
2435                                printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
2436                        vp->stats.rx_errors++;
2437                        if (rx_error & 0x01)  vp->stats.rx_over_errors++;
2438                        if (rx_error & 0x02)  vp->stats.rx_length_errors++;
2439                        if (rx_error & 0x04)  vp->stats.rx_frame_errors++;
2440                        if (rx_error & 0x08)  vp->stats.rx_crc_errors++;
2441                        if (rx_error & 0x10)  vp->stats.rx_length_errors++;
2442                } else {
2443                        /* The packet length: up to 4.5K!. */
2444                        int pkt_len = rx_status & 0x1fff;
2445                        struct sk_buff *skb;
2446                        dma_addr_t dma = le32_to_cpu(vp->rx_ring[entry].addr);
2447
2448                        if (vortex_debug > 4)
2449                                printk(KERN_DEBUG "Receiving packet size %d status %4.4x.\n",
2450                                           pkt_len, rx_status);
2451
2452                        /* Check if the packet is long enough to just accept without
2453                           copying to a properly sized skbuff. */
2454                        if (pkt_len < rx_copybreak && (skb = dev_alloc_skb(pkt_len + 2)) != 0) {
2455                                skb->dev = dev;
2456                                skb_reserve(skb, 2);    /* Align IP on 16 byte boundaries */
2457                                pci_dma_sync_single(vp->pdev, dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2458                                /* 'skb_put()' points to the start of sk_buff data area. */
2459                                memcpy(skb_put(skb, pkt_len),
2460                                           vp->rx_skbuff[entry]->tail,
2461                                           pkt_len);
2462                                vp->rx_copy++;
2463                        } else {
2464                                /* Pass up the skbuff already on the Rx ring. */
2465                                skb = vp->rx_skbuff[entry];
2466                                vp->rx_skbuff[entry] = NULL;
2467                                skb_put(skb, pkt_len);
2468                                pci_unmap_single(vp->pdev, dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2469                                vp->rx_nocopy++;
2470                        }
2471                        skb->protocol = eth_type_trans(skb, dev);
2472                        {                                       /* Use hardware checksum info. */
2473                                int csum_bits = rx_status & 0xee000000;
2474                                if (csum_bits &&
2475                                        (csum_bits == (IPChksumValid | TCPChksumValid) ||
2476                                         csum_bits == (IPChksumValid | UDPChksumValid))) {
2477                                        skb->ip_summed = CHECKSUM_UNNECESSARY;
2478                                        vp->rx_csumhits++;
2479                                }
2480                        }
2481                        netif_rx(skb);
2482                        dev->last_rx = jiffies;
2483                        vp->stats.rx_packets++;
2484                }
2485                entry = (++vp->cur_rx) % RX_RING_SIZE;
2486        }
2487        /* Refill the Rx ring buffers. */
2488        for (; vp->cur_rx - vp->dirty_rx > 0; vp->dirty_rx++) {
2489                struct sk_buff *skb;
2490                entry = vp->dirty_rx % RX_RING_SIZE;
2491                if (vp->rx_skbuff[entry] == NULL) {
2492                        skb = dev_alloc_skb(PKT_BUF_SZ);
2493                        if (skb == NULL) {
2494                                static unsigned long last_jif;
2495                                if ((jiffies - last_jif) > 10 * HZ) {
2496                                        printk(KERN_WARNING "%s: memory shortage\n", dev->name);
2497                                        last_jif = jiffies;
2498                                }
2499                                if ((vp->cur_rx - vp->dirty_rx) == RX_RING_SIZE)
2500                                        mod_timer(&vp->rx_oom_timer, RUN_AT(HZ * 1));
2501                                break;                  /* Bad news!  */
2502                        }
2503                        skb->dev = dev;                 /* Mark as being used by this device. */
2504                        skb_reserve(skb, 2);    /* Align IP on 16 byte boundaries */
2505                        vp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->tail, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
2506                        vp->rx_skbuff[entry] = skb;
2507                }
2508                vp->rx_ring[entry].status = 0;  /* Clear complete bit. */
2509                outw(UpUnstall, ioaddr + EL3_CMD);
2510        }
2511        return 0;
2512}
2513
2514/*
2515 * If we've hit a total OOM refilling the Rx ring we poll once a second
2516 * for some memory.  Otherwise there is no way to restart the rx process.
2517 */
2518static void
2519rx_oom_timer(unsigned long arg)
2520{
2521        struct net_device *dev = (struct net_device *)arg;
2522        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2523
2524        spin_lock_irq(&vp->lock);
2525        if ((vp->cur_rx - vp->dirty_rx) == RX_RING_SIZE)        /* This test is redundant, but makes me feel good */
2526                boomerang_rx(dev);
2527        if (vortex_debug > 1) {
2528                printk(KERN_DEBUG "%s: rx_oom_timer %s\n", dev->name,
2529                        ((vp->cur_rx - vp->dirty_rx) != RX_RING_SIZE) ? "succeeded" : "retrying");
2530        }
2531        spin_unlock_irq(&vp->lock);
2532}
2533
2534static void
2535vortex_down(struct net_device *dev)
2536{
2537        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2538        long ioaddr = dev->base_addr;
2539
2540        netif_stop_queue (dev);
2541
2542        del_timer_sync(&vp->rx_oom_timer);
2543        del_timer_sync(&vp->timer);
2544
2545        /* Turn off statistics ASAP.  We update vp->stats below. */
2546        outw(StatsDisable, ioaddr + EL3_CMD);
2547
2548        /* Disable the receiver and transmitter. */
2549        outw(RxDisable, ioaddr + EL3_CMD);
2550        outw(TxDisable, ioaddr + EL3_CMD);
2551
2552        if (dev->if_port == XCVR_10base2)
2553                /* Turn off thinnet power.  Green! */
2554                outw(StopCoax, ioaddr + EL3_CMD);
2555
2556        outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
2557
2558        update_stats(ioaddr, dev);
2559        if (vp->full_bus_master_rx)
2560                outl(0, ioaddr + UpListPtr);
2561        if (vp->full_bus_master_tx)
2562                outl(0, ioaddr + DownListPtr);
2563
2564        if (vp->pdev && vp->enable_wol) {
2565                pci_save_state(vp->pdev, vp->power_state);
2566                acpi_set_WOL(dev);
2567        }
2568}
2569
2570static int
2571vortex_close(struct net_device *dev)
2572{
2573        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2574        long ioaddr = dev->base_addr;
2575        int i;
2576
2577        if (netif_device_present(dev))
2578                vortex_down(dev);
2579
2580        if (vortex_debug > 1) {
2581                printk(KERN_DEBUG"%s: vortex_close() status %4.4x, Tx status %2.2x.\n",
2582                           dev->name, inw(ioaddr + EL3_STATUS), inb(ioaddr + TxStatus));
2583                printk(KERN_DEBUG "%s: vortex close stats: rx_nocopy %d rx_copy %d"
2584                           " tx_queued %d Rx pre-checksummed %d.\n",
2585                           dev->name, vp->rx_nocopy, vp->rx_copy, vp->queued_packet, vp->rx_csumhits);
2586        }
2587
2588#if DO_ZEROCOPY
2589        if (    vp->rx_csumhits &&
2590                        ((vp->drv_flags & HAS_HWCKSM) == 0) &&
2591                        (hw_checksums[vp->card_idx] == -1)) {
2592                printk(KERN_WARNING "%s supports hardware checksums, and we're not using them!\n", dev->name);
2593        }
2594#endif
2595                
2596        free_irq(dev->irq, dev);
2597
2598        if (vp->full_bus_master_rx) { /* Free Boomerang bus master Rx buffers. */
2599                for (i = 0; i < RX_RING_SIZE; i++)
2600                        if (vp->rx_skbuff[i]) {
2601                                pci_unmap_single(       vp->pdev, le32_to_cpu(vp->rx_ring[i].addr),
2602                                                                        PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2603                                dev_kfree_skb(vp->rx_skbuff[i]);
2604                                vp->rx_skbuff[i] = 0;
2605                        }
2606        }
2607        if (vp->full_bus_master_tx) { /* Free Boomerang bus master Tx buffers. */
2608                for (i = 0; i < TX_RING_SIZE; i++) {
2609                        if (vp->tx_skbuff[i]) {
2610                                struct sk_buff *skb = vp->tx_skbuff[i];
2611#if DO_ZEROCOPY
2612                                int k;
2613
2614                                for (k=0; k<=skb_shinfo(skb)->nr_frags; k++)
2615                                                pci_unmap_single(vp->pdev,
2616                                                                                 le32_to_cpu(vp->tx_ring[i].frag[k].addr),
2617                                                                                 le32_to_cpu(vp->tx_ring[i].frag[k].length)&0xFFF,
2618                                                                                 PCI_DMA_TODEVICE);
2619#else
2620                                pci_unmap_single(vp->pdev, le32_to_cpu(vp->tx_ring[i].addr), skb->len, PCI_DMA_TODEVICE);
2621#endif
2622                                dev_kfree_skb(skb);
2623                                vp->tx_skbuff[i] = 0;
2624                        }
2625                }
2626        }
2627
2628        return 0;
2629}
2630
2631static void
2632dump_tx_ring(struct net_device *dev)
2633{
2634        if (vortex_debug > 0) {
2635                struct vortex_private *vp = (struct vortex_private *)dev->priv;
2636                long ioaddr = dev->base_addr;
2637                
2638                if (vp->full_bus_master_tx) {
2639                        int i;
2640                        int stalled = inl(ioaddr + PktStatus) & 0x04;   /* Possible racy. But it's only debug stuff */
2641
2642                        printk(KERN_ERR "  Flags; bus-master %d, dirty %d(%d) current %d(%d)\n",
2643                                        vp->full_bus_master_tx,
2644                                        vp->dirty_tx, vp->dirty_tx % TX_RING_SIZE,
2645                                        vp->cur_tx, vp->cur_tx % TX_RING_SIZE);
2646                        printk(KERN_ERR "  Transmit list %8.8x vs. %p.\n",
2647                                   inl(ioaddr + DownListPtr),
2648                                   &vp->tx_ring[vp->dirty_tx % TX_RING_SIZE]);
2649                        issue_and_wait(dev, DownStall);
2650                        for (i = 0; i < TX_RING_SIZE; i++) {
2651                                printk(KERN_ERR "  %d: @%p  length %8.8x status %8.8x\n", i,
2652                                           &vp->tx_ring[i],
2653#if DO_ZEROCOPY
2654                                           le32_to_cpu(vp->tx_ring[i].frag[0].length),
2655#else
2656                                           le32_to_cpu(vp->tx_ring[i].length),
2657#endif
2658                                           le32_to_cpu(vp->tx_ring[i].status));
2659                        }
2660                        if (!stalled)
2661                                outw(DownUnstall, ioaddr + EL3_CMD);
2662                }
2663        }
2664}
2665
2666static struct net_device_stats *vortex_get_stats(struct net_device *dev)
2667{
2668        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2669        unsigned long flags;
2670
2671        if (netif_device_present(dev)) {        /* AKPM: Used to be netif_running */
2672                spin_lock_irqsave (&vp->lock, flags);
2673                update_stats(dev->base_addr, dev);
2674                spin_unlock_irqrestore (&vp->lock, flags);
2675        }
2676        return &vp->stats;
2677}
2678
2679/*  Update statistics.
2680        Unlike with the EL3 we need not worry about interrupts changing
2681        the window setting from underneath us, but we must still guard
2682        against a race condition with a StatsUpdate interrupt updating the
2683        table.  This is done by checking that the ASM (!) code generated uses
2684        atomic updates with '+='.
2685        */
2686static void update_stats(long ioaddr, struct net_device *dev)
2687{
2688        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2689        int old_window = inw(ioaddr + EL3_CMD);
2690
2691        if (old_window == 0xffff)       /* Chip suspended or ejected. */
2692                return;
2693        /* Unlike the 3c5x9 we need not turn off stats updates while reading. */
2694        /* Switch to the stats window, and read everything. */
2695        EL3WINDOW(6);
2696        vp->stats.tx_carrier_errors             += inb(ioaddr + 0);
2697        vp->stats.tx_heartbeat_errors   += inb(ioaddr + 1);
2698        /* Multiple collisions. */              inb(ioaddr + 2);
2699        vp->stats.collisions                    += inb(ioaddr + 3);
2700        vp->stats.tx_window_errors              += inb(ioaddr + 4);
2701        vp->stats.rx_fifo_errors                += inb(ioaddr + 5);
2702        vp->stats.tx_packets                    += inb(ioaddr + 6);
2703        vp->stats.tx_packets                    += (inb(ioaddr + 9)&0x30) << 4;
2704        /* Rx packets   */                              inb(ioaddr + 7);   /* Must read to clear */
2705        /* Tx deferrals */                              inb(ioaddr + 8);
2706        /* Don't bother with register 9, an extension of registers 6&7.
2707           If we do use the 6&7 values the atomic update assumption above
2708           is invalid. */
2709        vp->stats.rx_bytes += inw(ioaddr + 10);
2710        vp->stats.tx_bytes += inw(ioaddr + 12);
2711        /* New: On the Vortex we must also clear the BadSSD counter. */
2712        EL3WINDOW(4);
2713        inb(ioaddr + 12);
2714
2715        {
2716                u8 up = inb(ioaddr + 13);
2717                vp->stats.rx_bytes += (up & 0x0f) << 16;
2718                vp->stats.tx_bytes += (up & 0xf0) << 12;
2719        }
2720
2721        EL3WINDOW(old_window >> 13);
2722        return;
2723}
2724
2725
2726static int netdev_ethtool_ioctl(struct net_device *dev, void *useraddr)
2727{
2728        struct vortex_private *vp = dev->priv;
2729        u32 ethcmd;
2730                
2731        if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
2732                return -EFAULT;
2733
2734        switch (ethcmd) {
2735        case ETHTOOL_GDRVINFO: {
2736                struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
2737                strcpy(info.driver, DRV_NAME);
2738                strcpy(info.version, DRV_VERSION);
2739                if (vp->pdev)
2740                        strcpy(info.bus_info, vp->pdev->slot_name);
2741                else
2742                        sprintf(info.bus_info, "EISA 0x%lx %d",
2743                                dev->base_addr, dev->irq);
2744                if (copy_to_user(useraddr, &info, sizeof(info)))
2745                        return -EFAULT;
2746                return 0;
2747        }
2748
2749        }
2750        
2751        return -EOPNOTSUPP;
2752}
2753
2754static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2755{
2756        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2757        long ioaddr = dev->base_addr;
2758        struct mii_ioctl_data *data = (struct mii_ioctl_data *)&rq->ifr_data;
2759        int phy = vp->phys[0] & 0x1f;
2760        int retval;
2761
2762        switch(cmd) {
2763        case SIOCETHTOOL:
2764                return netdev_ethtool_ioctl(dev, (void *) rq->ifr_data);
2765
2766        case SIOCGMIIPHY:               /* Get address of MII PHY in use. */
2767                data->phy_id = phy;
2768
2769        case SIOCGMIIREG:               /* Read MII PHY register. */
2770                EL3WINDOW(4);
2771                data->val_out = mdio_read(dev, data->phy_id & 0x1f, data->reg_num & 0x1f);
2772                retval = 0;
2773                break;
2774
2775        case SIOCSMIIREG:               /* Write MII PHY register. */
2776                if (!capable(CAP_NET_ADMIN)) {
2777                        retval = -EPERM;
2778                } else {
2779                        EL3WINDOW(4);
2780                        mdio_write(dev, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in);
2781                        retval = 0;
2782                }
2783                break;
2784        default:
2785                retval = -EOPNOTSUPP;
2786                break;
2787        }
2788
2789        return retval;
2790}
2791
2792/* Pre-Cyclone chips have no documented multicast filter, so the only
2793   multicast setting is to receive all multicast frames.  At least
2794   the chip has a very clean way to set the mode, unlike many others. */
2795static void set_rx_mode(struct net_device *dev)
2796{
2797        long ioaddr = dev->base_addr;
2798        int new_mode;
2799
2800        if (dev->flags & IFF_PROMISC) {
2801                if (vortex_debug > 0)
2802                        printk(KERN_NOTICE "%s: Setting promiscuous mode.\n", dev->name);
2803                new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast|RxProm;
2804        } else  if ((dev->mc_list)  ||  (dev->flags & IFF_ALLMULTI)) {
2805                new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast;
2806        } else
2807                new_mode = SetRxFilter | RxStation | RxBroadcast;
2808
2809        outw(new_mode, ioaddr + EL3_CMD);
2810}
2811
2812/* MII transceiver control section.
2813   Read and write the MII registers using software-generated serial
2814   MDIO protocol.  See the MII specifications or DP83840A data sheet
2815   for details. */
2816
2817/* The maximum data clock rate is 2.5 Mhz.  The minimum timing is usually
2818   met by back-to-back PCI I/O cycles, but we insert a delay to avoid
2819   "overclocking" issues. */
2820#define mdio_delay() inl(mdio_addr)
2821
2822#define MDIO_SHIFT_CLK  0x01
2823#define MDIO_DIR_WRITE  0x04
2824#define MDIO_DATA_WRITE0 (0x00 | MDIO_DIR_WRITE)
2825#define MDIO_DATA_WRITE1 (0x02 | MDIO_DIR_WRITE)
2826#define MDIO_DATA_READ  0x02
2827#define MDIO_ENB_IN             0x00
2828
2829/* Generate the preamble required for initial synchronization and
2830   a few older transceivers. */
2831static void mdio_sync(long ioaddr, int bits)
2832{
2833        long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
2834
2835        /* Establish sync by sending at least 32 logic ones. */
2836        while (-- bits >= 0) {
2837                outw(MDIO_DATA_WRITE1, mdio_addr);
2838                mdio_delay();
2839                outw(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
2840                mdio_delay();
2841        }
2842}
2843
2844static int mdio_read(struct net_device *dev, int phy_id, int location)
2845{
2846        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2847        int i;
2848        long ioaddr = dev->base_addr;
2849        int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
2850        unsigned int retval = 0;
2851        long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
2852
2853        spin_lock_bh(&vp->mdio_lock);
2854
2855        if (mii_preamble_required)
2856                mdio_sync(ioaddr, 32);
2857
2858        /* Shift the read command bits out. */
2859        for (i = 14; i >= 0; i--) {
2860                int dataval = (read_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
2861                outw(dataval, mdio_addr);
2862                mdio_delay();
2863                outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
2864                mdio_delay();
2865        }
2866        /* Read the two transition, 16 data, and wire-idle bits. */
2867        for (i = 19; i > 0; i--) {
2868                outw(MDIO_ENB_IN, mdio_addr);
2869                mdio_delay();
2870                retval = (retval << 1) | ((inw(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
2871                outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
2872                mdio_delay();
2873        }
2874        spin_unlock_bh(&vp->mdio_lock);
2875        return retval & 0x20000 ? 0xffff : retval>>1 & 0xffff;
2876}
2877
2878static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
2879{
2880        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2881        long ioaddr = dev->base_addr;
2882        int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value;
2883        long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
2884        int i;
2885
2886        spin_lock_bh(&vp->mdio_lock);
2887
2888        if (mii_preamble_required)
2889                mdio_sync(ioaddr, 32);
2890
2891        /* Shift the command bits out. */
2892        for (i = 31; i >= 0; i--) {
2893                int dataval = (write_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
2894                outw(dataval, mdio_addr);
2895                mdio_delay();
2896                outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
2897                mdio_delay();
2898        }
2899        /* Leave the interface idle. */
2900        for (i = 1; i >= 0; i--) {
2901                outw(MDIO_ENB_IN, mdio_addr);
2902                mdio_delay();
2903                outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
2904                mdio_delay();
2905        }
2906        spin_unlock_bh(&vp->mdio_lock);
2907        return;
2908}
2909
2910/* ACPI: Advanced Configuration and Power Interface. */
2911/* Set Wake-On-LAN mode and put the board into D3 (power-down) state. */
2912static void acpi_set_WOL(struct net_device *dev)
2913{
2914        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2915        long ioaddr = dev->base_addr;
2916
2917        /* Power up on: 1==Downloaded Filter, 2==Magic Packets, 4==Link Status. */
2918        EL3WINDOW(7);
2919        outw(2, ioaddr + 0x0c);
2920        /* The RxFilter must accept the WOL frames. */
2921        outw(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
2922        outw(RxEnable, ioaddr + EL3_CMD);
2923
2924        /* Change the power state to D3; RxEnable doesn't take effect. */
2925        pci_enable_wake(vp->pdev, 0, 1);
2926        pci_set_power_state(vp->pdev, 3);
2927}
2928
2929
2930static void __devexit vortex_remove_one (struct pci_dev *pdev)
2931{
2932        struct net_device *dev = pci_get_drvdata(pdev);
2933        struct vortex_private *vp;
2934
2935        if (!dev) {
2936                printk("vortex_remove_one called for EISA device!\n");
2937                BUG();
2938        }
2939
2940        vp = dev->priv;
2941
2942        /* AKPM: FIXME: we should have
2943         *      if (vp->cb_fn_base) iounmap(vp->cb_fn_base);
2944         * here
2945         */
2946        unregister_netdev(dev);
2947        /* Should really use issue_and_wait() here */
2948        outw(TotalReset|0x14, dev->base_addr + EL3_CMD);
2949
2950        if (vp->pdev && vp->enable_wol) {
2951                pci_set_power_state(vp->pdev, 0);       /* Go active */
2952                if (vp->pm_state_valid)
2953                        pci_restore_state(vp->pdev, vp->power_state);
2954        }
2955
2956        pci_free_consistent(pdev,
2957                                                sizeof(struct boom_rx_desc) * RX_RING_SIZE
2958                                                        + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
2959                                                vp->rx_ring,
2960                                                vp->rx_ring_dma);
2961        if (vp->must_free_region)
2962                release_region(dev->base_addr, vp->io_size);
2963        kfree(dev);
2964}
2965
2966
2967static struct pci_driver vortex_driver = {
2968        .name           = "3c59x",
2969        .probe          = vortex_init_one,
2970        .remove         = __devexit_p(vortex_remove_one),
2971        .id_table       = vortex_pci_tbl,
2972#ifdef CONFIG_PM
2973        .suspend        = vortex_suspend,
2974        .resume         = vortex_resume,
2975#endif
2976};
2977
2978
2979static int vortex_have_pci;
2980static int vortex_have_eisa;
2981
2982
2983static int __init vortex_init (void)
2984{
2985        int pci_rc, eisa_rc;
2986
2987        pci_rc = pci_module_init(&vortex_driver);
2988        eisa_rc = vortex_eisa_init();
2989
2990        if (pci_rc == 0)
2991                vortex_have_pci = 1;
2992        if (eisa_rc > 0)
2993                vortex_have_eisa = 1;
2994
2995        return (vortex_have_pci + vortex_have_eisa) ? 0 : -ENODEV;
2996}
2997
2998
2999static void __exit vortex_eisa_cleanup (void)
3000{
3001        struct net_device *dev, *tmp;
3002        struct vortex_private *vp;
3003        long ioaddr;
3004
3005        dev = root_vortex_eisa_dev;
3006
3007        while (dev) {
3008                vp = dev->priv;
3009                ioaddr = dev->base_addr;
3010
3011                unregister_netdev (dev);
3012                outw (TotalReset, ioaddr + EL3_CMD);
3013                release_region (ioaddr, VORTEX_TOTAL_SIZE);
3014
3015                tmp = dev;
3016                dev = vp->next_module;
3017
3018                kfree (tmp);
3019        }
3020}
3021
3022
3023static void __exit vortex_cleanup (void)
3024{
3025        if (vortex_have_pci)
3026                pci_unregister_driver (&vortex_driver);
3027        if (vortex_have_eisa)
3028                vortex_eisa_cleanup ();
3029}
3030
3031
3032module_init(vortex_init);
3033module_exit(vortex_cleanup);
3034
3035
3036/*
3037 * Local variables:
3038 *  c-indent-level: 4
3039 *  c-basic-offset: 4
3040 *  tab-width: 4
3041 * End:
3042 */
3043
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.