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