Merge with Linux 2.4.0-test3-pre2.
[linux-2.6/linux-mips.git] / drivers / net / 3c59x.c
blob3f74c653761d66600965bdcdef36a7c7d895e87c
1 /* EtherLinkXL.c: A 3Com EtherLink PCI III/XL ethernet driver for linux. */
2 /*
3 Written 1996-1999 by Donald Becker.
5 This software may be used and distributed according to the terms
6 of the GNU Public License, incorporated herein by reference.
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.
12 The author may be reached as becker@scyld.com, or C/O
13 Center of Excellence in Space Data and Information Sciences
14 Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
16 Linux Kernel Additions:
18 0.99H+lk0.9 - David S. Miller - softnet, PCI DMA updates
19 0.99H+lk1.0 - Jeff Garzik <jgarzik@mandrakesoft.com>
20 Remove compatibility defines for kernel versions < 2.2.x.
21 Update for new 2.3.x module interface
22 LK1.1.2 (March 19, 2000)
23 * New PCI interface (jgarzik)
25 LK1.1.3 25 April 2000, Andrew Morton <andrewm@uow.edu.au>
26 - Merged with 3c575_cb.c
27 - Don't set RxComplete in boomerang interrupt enable reg
28 - spinlock in vortex_timer to protect mdio functions
29 - disable local interrupts around call to vortex_interrupt in
30 vortex_tx_timeout() (So vortex_interrupt can use spin_lock())
31 - Select window 3 in vortex_timer()'s write to Wn3_MAC_Ctrl
32 - In vortex_start_xmit(), move the lock to _after_ we've altered
33 vp->cur_tx and vp->tx_full. This defeats the race between
34 vortex_start_xmit() and vortex_interrupt which was identified
35 by Bogdan Costescu.
36 - Merged back support for six new cards from various sources
37 - Set vortex_have_pci if pci_module_init returns zero (fixes cardbus
38 insertion oops)
39 - Tell it that 3c905C has NWAY for 100bT autoneg
40 - Fix handling of SetStatusEnd in 'Too much work..' code, as
41 per 2.3.99's 3c575_cb (Dave Hinds).
42 - Split ISR into two for vortex & boomerang
43 - Fix MOD_INC/DEC races
44 - Handle resource allocation failures.
45 - Fix 3CCFE575CT LED polarity
46 - Make tx_interrupt_mitigation the default
48 LK1.1.4 25 April 2000, Andrew Morton <andrewm@uow.edu.au>
49 - Add extra TxReset to vortex_up() to fix 575_cb hotplug initialisation probs.
50 - Put vortex_info_tbl into __devinitdata
51 - In the vortex_error StatsFull HACK, disable stats in vp->intr_enable as well
52 as in the hardware.
53 - Increased the loop counter in wait_for_completion from 2,000 to 4,000.
55 LK1.1.5 28 April 2000, andrewm
56 - Added powerpc defines (John Daniel <jdaniel@etresoft.com> said these work...)
57 - Some extra diagnostics
58 - In vortex_error(), reset the Tx on maxCollisions. Otherwise most
59 chips usually get a Tx timeout.
60 - Added extra_reset module parm
61 - Replaced some inline timer manip with mod_timer
62 (Franois romieu <Francois.Romieu@nic.fr>)
63 - In vortex_up(), don't make Wn3_config initialisation dependent upon has_nway
64 (this came across from 3c575_cb).
66 LK1.1.6 06 Jun 2000, andrewm
67 - Backed out the PPC defines.
68 - Use del_timer_sync(), mod_timer().
69 - Fix wrapped ulong comparison in boomerang_rx()
70 - Add IS_TORNADO, use it to suppress 3c905C checksum error msg
71 (Donald Becker, I Lee Hetherington <ilh@sls.lcs.mit.edu>)
72 - Replace union wn3_config with BFINS/BFEXT manipulation for
73 sparc64 (Pete Zaitcev, Peter Jones)
74 - In vortex_error, do_tx_reset and vortex_tx_timeout(Vortex):
75 do a netif_wake_queue() to better recover from errors. (Anders Pedersen,
76 Donald Becker)
77 - Print a warning on out-of-memory (rate limited to 1 per 10 secs)
78 - Added two more Cardbus 575 NICs: 5b57 and 6564 (Paul Wagland)
80 - See http://www.uow.edu.au/~andrewm/linux/#3c59x-2.3 for more details.
84 * FIXME: This driver _could_ support MTU changing, but doesn't. See Don's hamaci.c implementation
85 * as well as other drivers
87 * NOTE: If you make 'vortex_debug' a constant (#define vortex_debug 0) the driver shrinks by 2k
88 * due to dead code elimination. There will be some performance benefits from this due to
89 * elimination of all the tests and reduced cache footprint.
92 /* A few values that may be tweaked. */
93 /* Keep the ring sizes a power of two for efficiency. */
94 #define TX_RING_SIZE 16
95 #define RX_RING_SIZE 32
96 #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
98 /* "Knobs" that adjust features and parameters. */
99 /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
100 Setting to > 1512 effectively disables this feature. */
101 static const int rx_copybreak = 200;
102 /* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
103 static const int mtu = 1500;
104 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
105 static int max_interrupt_work = 32;
106 /* Give the NIC an extra reset at the end of vortex_up() */
107 static int extra_reset = 0;
108 /* Tx timeout interval (millisecs) */
109 static int watchdog = 400;
111 /* Allow aggregation of Tx interrupts. Saves CPU load at the cost
112 * of possible Tx stalls if the system is blocking interrupts
113 * somewhere else. Undefine this to disable.
114 * AKPM 26 April 2000: enabling this still gets vestigial Tx timeouts
115 * in a heavily loaded (collision-prone) 10BaseT LAN. Should be OK with
116 * switched Ethernet.
117 * AKPM 24May00: vestigial timeouts have been removed by later fixes.
119 #define tx_interrupt_mitigation 1
121 /* Put out somewhat more debugging messages. (0: no msg, 1 minimal .. 6). */
122 #define vortex_debug debug
123 #ifdef VORTEX_DEBUG
124 static int vortex_debug = VORTEX_DEBUG;
125 #else
126 static int vortex_debug = 1;
127 #endif
129 /* Some values here only for performance evaluation and path-coverage
130 debugging. */
131 static int rx_nocopy = 0, rx_copy = 0, queued_packet = 0, rx_csumhits;
133 #ifndef __OPTIMIZE__
134 #error You must compile this file with the correct options!
135 #error See the last lines of the source file.
136 #error You must compile this driver with "-O".
137 #endif
139 #include <linux/module.h>
140 #include <linux/kernel.h>
141 #include <linux/sched.h>
142 #include <linux/string.h>
143 #include <linux/timer.h>
144 #include <linux/errno.h>
145 #include <linux/in.h>
146 #include <linux/ioport.h>
147 #include <linux/malloc.h>
148 #include <linux/interrupt.h>
149 #include <linux/pci.h>
150 #include <linux/init.h>
151 #include <linux/netdevice.h>
152 #include <linux/etherdevice.h>
153 #include <linux/skbuff.h>
154 #include <asm/irq.h> /* For NR_IRQS only. */
155 #include <asm/bitops.h>
156 #include <asm/io.h>
158 /* Kernel compatibility defines, some common to David Hinds' PCMCIA package.
159 This is only in the support-all-kernels source code. */
161 #define RUN_AT(x) (jiffies + (x))
163 #include <linux/delay.h>
165 static char version[] __devinitdata =
166 "3c59x.c:v0.99L+LK1.1.6 28 May 2000 Donald Becker and others. http://www.scyld.com/network/vortex.html " "$Revision: 1.97 $\n";
168 MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
169 MODULE_DESCRIPTION("3Com 3c59x/3c90x/3c575 series Vortex/Boomerang/Cyclone driver");
170 MODULE_PARM(debug, "i");
171 MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");
172 MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");
173 MODULE_PARM(rx_copybreak, "i");
174 MODULE_PARM(max_interrupt_work, "i");
175 MODULE_PARM(extra_reset, "i");
176 MODULE_PARM(compaq_ioaddr, "i");
177 MODULE_PARM(compaq_irq, "i");
178 MODULE_PARM(compaq_device_id, "i");
179 MODULE_PARM(watchdog, "i");
181 /* Operational parameter that usually are not changed. */
183 /* The Vortex size is twice that of the original EtherLinkIII series: the
184 runtime register window, window 1, is now always mapped in.
185 The Boomerang size is twice as large as the Vortex -- it has additional
186 bus master control registers. */
187 #define VORTEX_TOTAL_SIZE 0x20
188 #define BOOMERANG_TOTAL_SIZE 0x40
190 /* Set iff a MII transceiver on any interface requires mdio preamble.
191 This only set with the original DP83840 on older 3c905 boards, so the extra
192 code size of a per-interface flag is not worthwhile. */
193 static char mii_preamble_required = 0;
195 #define PFX "3c59x: "
200 Theory of Operation
202 I. Board Compatibility
204 This device driver is designed for the 3Com FastEtherLink and FastEtherLink
205 XL, 3Com's PCI to 10/100baseT adapters. It also works with the 10Mbs
206 versions of the FastEtherLink cards. The supported product IDs are
207 3c590, 3c592, 3c595, 3c597, 3c900, 3c905
209 The related ISA 3c515 is supported with a separate driver, 3c515.c, included
210 with the kernel source or available from
211 cesdis.gsfc.nasa.gov:/pub/linux/drivers/3c515.html
213 II. Board-specific settings
215 PCI bus devices are configured by the system at boot time, so no jumpers
216 need to be set on the board. The system BIOS should be set to assign the
217 PCI INTA signal to an otherwise unused system IRQ line.
219 The EEPROM settings for media type and forced-full-duplex are observed.
220 The EEPROM media type should be left at the default "autoselect" unless using
221 10base2 or AUI connections which cannot be reliably detected.
223 III. Driver operation
225 The 3c59x series use an interface that's very similar to the previous 3c5x9
226 series. The primary interface is two programmed-I/O FIFOs, with an
227 alternate single-contiguous-region bus-master transfer (see next).
229 The 3c900 "Boomerang" series uses a full-bus-master interface with separate
230 lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,
231 DEC Tulip and Intel Speedo3. The first chip version retains a compatible
232 programmed-I/O interface that has been removed in 'B' and subsequent board
233 revisions.
235 One extension that is advertised in a very large font is that the adapters
236 are capable of being bus masters. On the Vortex chip this capability was
237 only for a single contiguous region making it far less useful than the full
238 bus master capability. There is a significant performance impact of taking
239 an extra interrupt or polling for the completion of each transfer, as well
240 as difficulty sharing the single transfer engine between the transmit and
241 receive threads. Using DMA transfers is a win only with large blocks or
242 with the flawed versions of the Intel Orion motherboard PCI controller.
244 The Boomerang chip's full-bus-master interface is useful, and has the
245 currently-unused advantages over other similar chips that queued transmit
246 packets may be reordered and receive buffer groups are associated with a
247 single frame.
249 With full-bus-master support, this driver uses a "RX_COPYBREAK" scheme.
250 Rather than a fixed intermediate receive buffer, this scheme allocates
251 full-sized skbuffs as receive buffers. The value RX_COPYBREAK is used as
252 the copying breakpoint: it is chosen to trade-off the memory wasted by
253 passing the full-sized skbuff to the queue layer for all frames vs. the
254 copying cost of copying a frame to a correctly-sized skbuff.
256 IIIC. Synchronization
257 The driver runs as two independent, single-threaded flows of control. One
258 is the send-packet routine, which enforces single-threaded use by the
259 dev->tbusy flag. The other thread is the interrupt handler, which is single
260 threaded by the hardware and other software.
262 IV. Notes
264 Thanks to Cameron Spitzer and Terry Murphy of 3Com for providing development
265 3c590, 3c595, and 3c900 boards.
266 The name "Vortex" is the internal 3Com project name for the PCI ASIC, and
267 the EISA version is called "Demon". According to Terry these names come
268 from rides at the local amusement park.
270 The new chips support both ethernet (1.5K) and FDDI (4.5K) packet sizes!
271 This driver only supports ethernet packets because of the skbuff allocation
272 limit of 4K.
275 /* This table drives the PCI probe routines. It's mostly boilerplate in all
276 of the drivers, and will likely be provided by some future kernel.
278 enum pci_flags_bit {
279 PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
280 PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,
283 enum { IS_VORTEX=1, IS_BOOMERANG=2, IS_CYCLONE=4, IS_TORNADO=8,
284 EEPROM_230=0x10, /* AKPM: Uses 0x230 as the base bitmaps for EEPROM reads */
285 HAS_PWR_CTRL=0x20, HAS_MII=0x40, HAS_NWAY=0x80, HAS_CB_FNS=0x100, };
288 enum vortex_chips {
289 CH_3C590 = 0,
290 CH_3C592,
291 CH_3C597,
292 CH_3C595_1,
293 CH_3C595_2,
295 CH_3C595_3,
296 CH_3C900_1,
297 CH_3C900_2,
298 CH_3C900_3,
299 CH_3C900_4,
301 CH_3C900_5,
302 CH_3C900B_FL,
303 CH_3C905_1,
304 CH_3C905_2,
305 CH_3C905B_1,
307 CH_3C905B_2,
308 CH_3C905B_FX,
309 CH_3C905C,
310 CH_3C980,
311 CH_3C9805,
313 CH_3CSOHO100_TX,
314 CH_3C555,
315 CH_3C575,
316 CH_3C575_1,
317 CH_3CCFE575,
319 CH_3CCFE575CT,
320 CH_3CCFE656,
321 CH_3CCFEM656,
322 CH_3CCFEM656_1,
323 CH_3C450,
327 /* note: this array directly indexed by above enums, and MUST
328 * be kept in sync with both the enums above, and the PCI device
329 * table below
331 static struct vortex_chip_info {
332 const char *name;
333 int flags;
334 int drv_flags;
335 int io_size;
336 } vortex_info_tbl[] __devinitdata = {
337 #define EISA_TBL_OFFSET 0 /* Offset of this entry for vortex_eisa_init */
338 {"3c590 Vortex 10Mbps",
339 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
340 {"3c592 EISA 10mbps Demon/Vortex", /* AKPM: from Don's 3c59x_cb.c 0.49H */
341 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
342 {"3c597 EISA Fast Demon/Vortex", /* AKPM: from Don's 3c59x_cb.c 0.49H */
343 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
344 {"3c595 Vortex 100baseTx",
345 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
346 {"3c595 Vortex 100baseT4",
347 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
349 {"3c595 Vortex 100base-MII",
350 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
351 {"3c900 Boomerang 10baseT",
352 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, },
353 {"3c900 Boomerang 10Mbps Combo",
354 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, },
355 {"3c900 Cyclone 10Mbps TPO", /* AKPM: from Don's 0.99M */
356 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, },
357 {"3c900 Cyclone 10Mbps Combo",
358 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, },
360 {"3c900 Cyclone 10Mbps TPC", /* AKPM: from Don's 0.99M */
361 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, },
362 {"3c900B-FL Cyclone 10base-FL",
363 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, },
364 {"3c905 Boomerang 100baseTx",
365 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, },
366 {"3c905 Boomerang 100baseT4",
367 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, },
368 {"3c905B Cyclone 100baseTx",
369 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY, 128, },
371 {"3c905B Cyclone 10/100/BNC",
372 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY, 128, },
373 {"3c905B-FX Cyclone 100baseFx",
374 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, },
375 {"3c905C Tornado",
376 PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY, 128, },
377 {"3c980 Cyclone",
378 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, },
379 {"3c980 10/100 Base-TX NIC(Python-T)",
380 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, },
382 {"3cSOHO100-TX Hurricane",
383 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, },
384 {"3c555 Laptop Hurricane",
385 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, },
386 {"3c575 [Megahertz] 10/100 LAN CardBus",
387 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_230, 128, },
388 {"3c575 Boomerang CardBus",
389 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_230, 128, },
390 {"3CCFE575 Cyclone CardBus",
391 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_230, 128, },
393 {"3CCFE575CT Cyclone CardBus",
394 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_230, 128, },
395 {"3CCFE656 Cyclone CardBus",
396 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_230, 128, },
397 {"3CCFEM656 Cyclone CardBus",
398 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_230, 128, },
399 {"3CCFEM656 Cyclone CardBus(0x6564)", /* From pcmcia-cs-3.1.5 */
400 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_230, 128, },
401 {"3c450 HomePNA Tornado", /* AKPM: from Don's 0.99Q */
402 PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY, 128, },
404 {0,}, /* 0 terminated list. */
408 static struct pci_device_id vortex_pci_tbl[] __devinitdata = {
409 { 0x10B7, 0x5900, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C590 },
410 { 0x10B7, 0x5920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C592 },
411 { 0x10B7, 0x5970, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C597 },
412 { 0x10B7, 0x5950, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_1 },
413 { 0x10B7, 0x5951, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_2 },
415 { 0x10B7, 0x5952, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_3 },
416 { 0x10B7, 0x9000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_1 },
417 { 0x10B7, 0x9001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_2 },
418 { 0x10B7, 0x9004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_3 },
419 { 0x10B7, 0x9005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_4 },
421 { 0x10B7, 0x9006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_5 },
422 { 0x10B7, 0x900A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900B_FL },
423 { 0x10B7, 0x9050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905_1 },
424 { 0x10B7, 0x9051, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905_2 },
425 { 0x10B7, 0x9055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_1 },
427 { 0x10B7, 0x9058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_2 },
428 { 0x10B7, 0x905A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_FX },
429 { 0x10B7, 0x9200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905C },
430 { 0x10B7, 0x9800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C980 },
431 { 0x10B7, 0x9805, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C9805 },
433 { 0x10B7, 0x7646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CSOHO100_TX },
434 { 0x10B7, 0x5055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C555 },
435 { 0x10B7, 0x5b57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C575 },
436 { 0x10B7, 0x5057, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C575_1 },
437 { 0x10B7, 0x5157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE575 },
439 { 0x10B7, 0x5257, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE575CT },
440 { 0x10B7, 0x6560, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE656 },
441 { 0x10B7, 0x6562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFEM656 },
442 { 0x10B7, 0x6564, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFEM656_1 },
443 { 0x10B7, 0x4500, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C450 },
445 {0,} /* 0 terminated list. */
447 MODULE_DEVICE_TABLE(pci, vortex_pci_tbl);
450 /* Operational definitions.
451 These are not used by other compilation units and thus are not
452 exported in a ".h" file.
454 First the windows. There are eight register windows, with the command
455 and status registers available in each.
457 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
458 #define EL3_CMD 0x0e
459 #define EL3_STATUS 0x0e
461 /* The top five bits written to EL3_CMD are a command, the lower
462 11 bits are the parameter, if applicable.
463 Note that 11 parameters bits was fine for ethernet, but the new chip
464 can handle FDDI length frames (~4500 octets) and now parameters count
465 32-bit 'Dwords' rather than octets. */
467 enum vortex_cmd {
468 TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
469 RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11,
470 UpStall = 6<<11, UpUnstall = (6<<11)+1,
471 DownStall = (6<<11)+2, DownUnstall = (6<<11)+3,
472 RxDiscard = 8<<11, TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
473 FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
474 SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
475 SetTxThreshold = 18<<11, SetTxStart = 19<<11,
476 StartDMAUp = 20<<11, StartDMADown = (20<<11)+1, StatsEnable = 21<<11,
477 StatsDisable = 22<<11, StopCoax = 23<<11, SetFilterBit = 25<<11,};
479 /* The SetRxFilter command accepts the following classes: */
480 enum RxFilter {
481 RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
483 /* Bits in the general status register. */
484 enum vortex_status {
485 IntLatch = 0x0001, HostError = 0x0002, TxComplete = 0x0004,
486 TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
487 IntReq = 0x0040, StatsFull = 0x0080,
488 DMADone = 1<<8, DownComplete = 1<<9, UpComplete = 1<<10,
489 DMAInProgress = 1<<11, /* DMA controller is still busy.*/
490 CmdInProgress = 1<<12, /* EL3_CMD is still busy.*/
493 /* Register window 1 offsets, the window used in normal operation.
494 On the Vortex this window is always mapped at offsets 0x10-0x1f. */
495 enum Window1 {
496 TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14,
497 RxStatus = 0x18, Timer=0x1A, TxStatus = 0x1B,
498 TxFree = 0x1C, /* Remaining free bytes in Tx buffer. */
500 enum Window0 {
501 Wn0EepromCmd = 10, /* Window 0: EEPROM command register. */
502 Wn0EepromData = 12, /* Window 0: EEPROM results register. */
503 IntrStatus=0x0E, /* Valid in all windows. */
505 enum Win0_EEPROM_bits {
506 EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0,
507 EEPROM_EWENB = 0x30, /* Enable erasing/writing for 10 msec. */
508 EEPROM_EWDIS = 0x00, /* Disable EWENB before 10 msec timeout. */
510 /* EEPROM locations. */
511 enum eeprom_offset {
512 PhysAddr01=0, PhysAddr23=1, PhysAddr45=2, ModelID=3,
513 EtherLink3ID=7, IFXcvrIO=8, IRQLine=9,
514 NodeAddr01=10, NodeAddr23=11, NodeAddr45=12,
515 DriverTune=13, Checksum=15};
517 enum Window2 { /* Window 2. */
518 Wn2_ResetOptions=12,
520 enum Window3 { /* Window 3: MAC/config bits. */
521 Wn3_Config=0, Wn3_MAC_Ctrl=6, Wn3_Options=8,
524 #define BFEXT(value, offset, bitcount) \
525 ((((unsigned long)(value)) >> (offset)) & ((1 << (bitcount)) - 1))
527 #define BFINS(lhs, rhs, offset, bitcount) \
528 (((lhs) & ~((((1 << (bitcount)) - 1)) << (offset))) | \
529 (((rhs) & ((1 << (bitcount)) - 1)) << (offset)))
531 #define RAM_SIZE(v) BFEXT(v, 0, 3)
532 #define RAM_WIDTH(v) BFEXT(v, 3, 1)
533 #define RAM_SPEED(v) BFEXT(v, 4, 2)
534 #define ROM_SIZE(v) BFEXT(v, 6, 2)
535 #define RAM_SPLIT(v) BFEXT(v, 16, 2)
536 #define XCVR(v) BFEXT(v, 20, 4)
537 #define AUTOSELECT(v) BFEXT(v, 24, 1)
539 enum Window4 { /* Window 4: Xcvr/media bits. */
540 Wn4_FIFODiag = 4, Wn4_NetDiag = 6, Wn4_PhysicalMgmt=8, Wn4_Media = 10,
542 enum Win4_Media_bits {
543 Media_SQE = 0x0008, /* Enable SQE error counting for AUI. */
544 Media_10TP = 0x00C0, /* Enable link beat and jabber for 10baseT. */
545 Media_Lnk = 0x0080, /* Enable just link beat for 100TX/100FX. */
546 Media_LnkBeat = 0x0800,
548 enum Window7 { /* Window 7: Bus Master control. */
549 Wn7_MasterAddr = 0, Wn7_MasterLen = 6, Wn7_MasterStatus = 12,
551 /* Boomerang bus master control registers. */
552 enum MasterCtrl {
553 PktStatus = 0x20, DownListPtr = 0x24, FragAddr = 0x28, FragLen = 0x2c,
554 TxFreeThreshold = 0x2f, UpPktStatus = 0x30, UpListPtr = 0x38,
557 /* The Rx and Tx descriptor lists.
558 Caution Alpha hackers: these types are 32 bits! Note also the 8 byte
559 alignment contraint on tx_ring[] and rx_ring[]. */
560 #define LAST_FRAG 0x80000000 /* Last Addr/Len pair in descriptor. */
561 #define DN_COMPLETE 0x00010000 /* This packet has been downloaded */
562 struct boom_rx_desc {
563 u32 next; /* Last entry points to 0. */
564 s32 status;
565 u32 addr; /* Up to 63 addr/len pairs possible. */
566 s32 length; /* Set LAST_FRAG to indicate last pair. */
568 /* Values for the Rx status entry. */
569 enum rx_desc_status {
570 RxDComplete=0x00008000, RxDError=0x4000,
571 /* See boomerang_rx() for actual error bits */
572 IPChksumErr=1<<25, TCPChksumErr=1<<26, UDPChksumErr=1<<27,
573 IPChksumValid=1<<29, TCPChksumValid=1<<30, UDPChksumValid=1<<31,
576 struct boom_tx_desc {
577 u32 next; /* Last entry points to 0. */
578 s32 status; /* bits 0:12 length, others see below. */
579 u32 addr;
580 s32 length;
583 /* Values for the Tx status entry. */
584 enum tx_desc_status {
585 CRCDisable=0x2000, TxDComplete=0x8000,
586 AddIPChksum=0x02000000, AddTCPChksum=0x04000000, AddUDPChksum=0x08000000,
587 TxIntrUploaded=0x80000000, /* IRQ when in FIFO, but maybe not sent. */
590 /* Chip features we care about in vp->capabilities, read from the EEPROM. */
591 enum ChipCaps { CapBusMaster=0x20, CapPwrMgmt=0x2000 };
593 struct vortex_private {
594 /* The Rx and Tx rings should be quad-word-aligned. */
595 struct boom_rx_desc* rx_ring;
596 struct boom_tx_desc* tx_ring;
597 dma_addr_t rx_ring_dma;
598 dma_addr_t tx_ring_dma;
599 /* The addresses of transmit- and receive-in-place skbuffs. */
600 struct sk_buff* rx_skbuff[RX_RING_SIZE];
601 struct sk_buff* tx_skbuff[TX_RING_SIZE];
602 struct net_device *next_module; /* NULL if PCI device */
603 unsigned int cur_rx, cur_tx; /* The next free ring entry */
604 unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */
605 struct net_device_stats stats;
606 struct sk_buff *tx_skb; /* Packet being eaten by bus master ctrl. */
607 dma_addr_t tx_skb_dma; /* Allocated DMA address for bus master ctrl DMA. */
609 /* PCI configuration space information. */
610 struct pci_dev *pdev;
611 char *cb_fn_base; /* CardBus function status addr space. */
613 /* The remainder are related to chip state, mostly media selection. */
614 struct timer_list timer; /* Media selection timer. */
615 int options; /* User-settable misc. driver options. */
616 unsigned int media_override:4, /* Passed-in media type. */
617 default_media:4, /* Read from the EEPROM/Wn3_Config. */
618 full_duplex:1, force_fd:1, autoselect:1,
619 bus_master:1, /* Vortex can only do a fragment bus-m. */
620 full_bus_master_tx:1, full_bus_master_rx:2, /* Boomerang */
621 hw_csums:1, /* Has hardware checksums. */
622 tx_full:1,
623 has_nway:1,
624 open:1;
625 int tx_reset_resume; /* Flag to retart timer after vortex_error handling */
626 u16 status_enable;
627 u16 intr_enable;
628 u16 available_media; /* From Wn3_Options. */
629 u16 capabilities, info1, info2; /* Various, from EEPROM. */
630 u16 advertising; /* NWay media advertisement */
631 unsigned char phys[2]; /* MII device addresses. */
632 u16 deferred; /* Resend these interrupts when we
633 * bale from the ISR */
634 u16 io_size; /* Size of PCI region (for release_region) */
635 spinlock_t lock;
638 /* The action to take with a media selection timer tick.
639 Note that we deviate from the 3Com order by checking 10base2 before AUI.
641 enum xcvr_types {
642 XCVR_10baseT=0, XCVR_AUI, XCVR_10baseTOnly, XCVR_10base2, XCVR_100baseTx,
643 XCVR_100baseFx, XCVR_MII=6, XCVR_NWAY=8, XCVR_ExtMII=9, XCVR_Default=10,
646 static struct media_table {
647 char *name;
648 unsigned int media_bits:16, /* Bits to set in Wn4_Media register. */
649 mask:8, /* The transceiver-present bit in Wn3_Config.*/
650 next:8; /* The media type to try next. */
651 int wait; /* Time before we check media status. */
652 } media_tbl[] = {
653 { "10baseT", Media_10TP,0x08, XCVR_10base2, (14*HZ)/10},
654 { "10Mbs AUI", Media_SQE, 0x20, XCVR_Default, (1*HZ)/10},
655 { "undefined", 0, 0x80, XCVR_10baseT, 10000},
656 { "10base2", 0, 0x10, XCVR_AUI, (1*HZ)/10},
657 { "100baseTX", Media_Lnk, 0x02, XCVR_100baseFx, (14*HZ)/10},
658 { "100baseFX", Media_Lnk, 0x04, XCVR_MII, (14*HZ)/10},
659 { "MII", 0, 0x41, XCVR_10baseT, 3*HZ },
660 { "undefined", 0, 0x01, XCVR_10baseT, 10000},
661 { "Autonegotiate", 0, 0x41, XCVR_10baseT, 3*HZ},
662 { "MII-External", 0, 0x41, XCVR_10baseT, 3*HZ },
663 { "Default", 0, 0xFF, XCVR_10baseT, 10000},
666 static int vortex_probe1(struct pci_dev *pdev, long ioaddr, int irq,
667 int chip_idx, int card_idx);
668 static void vortex_up(struct net_device *dev);
669 static void vortex_down(struct net_device *dev);
670 static int vortex_open(struct net_device *dev);
671 static void mdio_sync(long ioaddr, int bits);
672 static int mdio_read(long ioaddr, int phy_id, int location);
673 static void mdio_write(long ioaddr, int phy_id, int location, int value);
674 static void vortex_timer(unsigned long arg);
675 static int vortex_start_xmit(struct sk_buff *skb, struct net_device *dev);
676 static int boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev);
677 static int vortex_rx(struct net_device *dev);
678 static int boomerang_rx(struct net_device *dev);
679 static void vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs);
680 static void boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs);
681 static int vortex_close(struct net_device *dev);
682 static void dump_tx_ring(struct net_device *dev);
683 static void update_stats(long ioaddr, struct net_device *dev);
684 static struct net_device_stats *vortex_get_stats(struct net_device *dev);
685 static void set_rx_mode(struct net_device *dev);
686 static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
687 static void vortex_tx_timeout(struct net_device *dev);
688 static void acpi_set_WOL(struct net_device *dev);
690 /* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
691 /* Option count limit only -- unlimited interfaces are supported. */
692 #define MAX_UNITS 8
693 static int options[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1,};
694 static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
697 /* A list of all installed Vortex EISA devices, for removing the driver module. */
698 static struct net_device *root_vortex_eisa_dev = NULL;
700 /* Variables to work-around the Compaq PCI BIOS32 problem. */
701 static int compaq_ioaddr = 0, compaq_irq = 0, compaq_device_id = 0x5900;
703 static int vortex_cards_found = 0;
705 static void vortex_suspend (struct pci_dev *pdev)
707 struct net_device *dev = pdev->driver_data;
709 printk(KERN_DEBUG "vortex_suspend(%s)\n", dev->name);
711 if (dev && dev->priv) {
712 struct vortex_private *vp = (struct vortex_private *)dev->priv;
713 if (vp->open) {
714 netif_device_detach(dev);
715 vortex_down(dev);
720 static void vortex_resume (struct pci_dev *pdev)
722 struct net_device *dev = pdev->driver_data;
724 printk(KERN_DEBUG "vortex_resume(%s)\n", dev->name);
726 if (dev && dev->priv) {
727 struct vortex_private *vp = (struct vortex_private *)dev->priv;
728 if (vp->open) {
729 vortex_up(dev);
730 netif_device_attach(dev);
735 /* returns count found (>= 0), or negative on error */
736 static int __init vortex_eisa_init (void)
738 long ioaddr;
739 int rc;
740 int orig_cards_found = vortex_cards_found;
742 /* Now check all slots of the EISA bus. */
743 if (!EISA_bus)
744 return 0;
746 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
747 int device_id;
749 if (request_region(ioaddr, VORTEX_TOTAL_SIZE, "vortex") == NULL)
750 continue;
752 /* Check the standard EISA ID register for an encoded '3Com'. */
753 if (inw(ioaddr + 0xC80) != 0x6d50) {
754 release_region (ioaddr, VORTEX_TOTAL_SIZE);
755 continue;
758 /* Check for a product that we support, 3c59{2,7} any rev. */
759 device_id = (inb(ioaddr + 0xC82)<<8) + inb(ioaddr + 0xC83);
760 if ((device_id & 0xFF00) != 0x5900) {
761 release_region (ioaddr, VORTEX_TOTAL_SIZE);
762 continue;
765 rc = vortex_probe1(NULL, ioaddr, inw(ioaddr + 0xC88) >> 12,
766 EISA_TBL_OFFSET,
767 vortex_cards_found);
768 if (rc == 0)
769 vortex_cards_found++;
770 else
771 release_region (ioaddr, VORTEX_TOTAL_SIZE);
774 /* Special code to work-around the Compaq PCI BIOS32 problem. */
775 if (compaq_ioaddr) {
776 vortex_probe1(NULL, compaq_ioaddr, compaq_irq,
777 compaq_device_id, vortex_cards_found++);
780 return vortex_cards_found - orig_cards_found;
784 /* returns count (>= 0), or negative on error */
785 static int __devinit vortex_init_one (struct pci_dev *pdev,
786 const struct pci_device_id *ent)
788 int rc;
790 rc = vortex_probe1 (pdev, pci_resource_start (pdev, 0), pdev->irq,
791 ent->driver_data, vortex_cards_found);
792 if (rc == 0)
793 vortex_cards_found++;
794 return rc;
798 * Start up the PCI device which is described by *pdev.
799 * Return 0 on success.
801 * NOTE: pdev can be NULL, for the case of an EISA driver
803 static int __devinit vortex_probe1(struct pci_dev *pdev,
804 long ioaddr, int irq,
805 int chip_idx, int card_idx)
807 struct vortex_private *vp;
808 int option;
809 unsigned int eeprom[0x40], checksum = 0; /* EEPROM contents */
810 int i;
811 struct net_device *dev;
812 static int printed_version = 0;
813 int retval;
814 struct vortex_chip_info * const vci = &vortex_info_tbl[chip_idx];
816 if (!printed_version) {
817 printk (KERN_INFO "%s", version);
818 printed_version = 1;
821 dev = init_etherdev(NULL, sizeof(*vp));
822 if (!dev) {
823 printk (KERN_ERR PFX "unable to allocate etherdev, aborting\n");
824 retval = -ENOMEM;
825 goto out;
828 printk(KERN_INFO "%s: 3Com %s %s at 0x%lx, ",
829 dev->name,
830 pdev ? "PCI" : "EISA",
831 vci->name,
832 ioaddr);
834 /* private struct aligned and zeroed by init_etherdev */
835 vp = dev->priv;
836 dev->base_addr = ioaddr;
837 dev->irq = irq;
838 dev->mtu = mtu;
839 vp->has_nway = (vci->drv_flags & HAS_NWAY) ? 1 : 0;
840 vp->io_size = vci->io_size;
842 /* module list only for EISA devices */
843 if (pdev == NULL) {
844 vp->next_module = root_vortex_eisa_dev;
845 root_vortex_eisa_dev = dev;
848 /* PCI-only startup logic */
849 if (pdev) {
850 /* EISA resources already marked, so only PCI needs to do this here */
851 if (!request_region (ioaddr, vci->io_size, dev->name)) {
852 printk (KERN_ERR "%s: Cannot reserve I/O resource 0x%x @ 0x%lx, aborting\n",
853 dev->name, vci->io_size, ioaddr);
854 retval = -EBUSY;
855 goto free_dev;
858 /* wake up and enable device */
859 if (pci_enable_device (pdev)) {
860 retval = -EIO;
861 goto free_region;
864 /* enable bus-mastering if necessary */
865 if (vci->flags & PCI_USES_MASTER)
866 pci_set_master (pdev);
869 vp->lock = SPIN_LOCK_UNLOCKED;
870 vp->pdev = pdev;
872 /* Makes sure rings are at least 16 byte aligned. */
873 vp->rx_ring = pci_alloc_consistent(pdev, sizeof(struct boom_rx_desc) * RX_RING_SIZE
874 + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
875 &vp->rx_ring_dma);
876 if (vp->rx_ring == 0)
878 retval = -ENOMEM;
879 goto free_region;
882 vp->tx_ring = (struct boom_tx_desc *)(vp->rx_ring + RX_RING_SIZE);
883 vp->tx_ring_dma = vp->rx_ring_dma + sizeof(struct boom_rx_desc) * RX_RING_SIZE;
885 /* if we are a PCI driver, we store info in pdev->driver_data
886 * instead of a module list */
887 if (pdev)
888 pdev->driver_data = dev;
890 /* The lower four bits are the media type. */
891 if (dev->mem_start)
892 { /*
893 * AKPM: ewww.. The 'options' param is passed in as the third arg to the
894 * LILO 'ether=' argument for non-modular use
896 option = dev->mem_start;
898 else if (card_idx < MAX_UNITS)
899 option = options[card_idx];
900 else
901 option = -1;
903 if (option >= 0) {
904 vp->media_override = ((option & 7) == 2) ? 0 : option & 15;
905 vp->full_duplex = (option & 0x200) ? 1 : 0;
906 vp->bus_master = (option & 16) ? 1 : 0;
907 } else {
908 vp->media_override = 7;
909 vp->full_duplex = 0;
910 vp->bus_master = 0;
912 if (card_idx < MAX_UNITS && full_duplex[card_idx] > 0)
913 vp->full_duplex = 1;
915 vp->force_fd = vp->full_duplex;
916 vp->options = option;
917 /* Read the station address from the EEPROM. */
918 EL3WINDOW(0);
920 int base = (vci->drv_flags & EEPROM_230) ? 0x230 : EEPROM_Read;
921 for (i = 0; i < 0x40; i++) {
922 int timer;
923 outw(base + i, ioaddr + Wn0EepromCmd);
924 /* Pause for at least 162 us. for the read to take place. */
925 for (timer = 10; timer >= 0; timer--) {
926 udelay(162);
927 if ((inw(ioaddr + Wn0EepromCmd) & 0x8000) == 0)
928 break;
930 eeprom[i] = inw(ioaddr + Wn0EepromData);
933 for (i = 0; i < 0x18; i++)
934 checksum ^= eeprom[i];
935 checksum = (checksum ^ (checksum >> 8)) & 0xff;
936 if (checksum != 0x00) { /* Grrr, needless incompatible change 3Com. */
937 while (i < 0x21)
938 checksum ^= eeprom[i++];
939 checksum = (checksum ^ (checksum >> 8)) & 0xff;
941 if ((checksum != 0x00) && !(vci->drv_flags & IS_TORNADO))
942 printk(" ***INVALID CHECKSUM %4.4x*** ", checksum);
943 for (i = 0; i < 3; i++)
944 ((u16 *)dev->dev_addr)[i] = htons(eeprom[i + 10]);
945 for (i = 0; i < 6; i++)
946 printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
947 EL3WINDOW(2);
948 for (i = 0; i < 6; i++)
949 outb(dev->dev_addr[i], ioaddr + i);
951 #ifdef __sparc__
952 printk(", IRQ %s\n", __irq_itoa(dev->irq));
953 #else
954 printk(", IRQ %d\n", dev->irq);
955 /* Tell them about an invalid IRQ. */
956 if (vortex_debug && (dev->irq <= 0 || dev->irq >= NR_IRQS))
957 printk(KERN_WARNING " *** Warning: IRQ %d is unlikely to work! ***\n",
958 dev->irq);
959 #endif
961 if (pdev && vci->drv_flags & HAS_CB_FNS) {
962 u32 fn_st_addr; /* Cardbus function status space */
963 fn_st_addr = pci_resource_start (pdev, 2);
964 if (fn_st_addr)
965 vp->cb_fn_base = ioremap(fn_st_addr, 128);
966 printk(KERN_INFO "%s: CardBus functions mapped %8.8x->%p\n",
967 dev->name, fn_st_addr, vp->cb_fn_base);
968 #if 1 /* AKPM: the 575_cb and 905B LEDs seem OK without this */
969 if (vortex_pci_tbl[chip_idx].device != 0x5257) {
970 EL3WINDOW(2);
971 outw(0x10 | inw(ioaddr + Wn2_ResetOptions), ioaddr + Wn2_ResetOptions);
973 #endif
976 /* Extract our information from the EEPROM data. */
977 vp->info1 = eeprom[13];
978 vp->info2 = eeprom[15];
979 vp->capabilities = eeprom[16];
981 if (vp->info1 & 0x8000)
983 vp->full_duplex = 1;
984 printk(KERN_INFO "Full duplex capable\n");
988 static const char * ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
989 unsigned int config;
990 EL3WINDOW(3);
991 vp->available_media = inw(ioaddr + Wn3_Options);
992 if ((vp->available_media & 0xff) == 0) /* Broken 3c916 */
993 vp->available_media = 0x40;
994 config = inl(ioaddr + Wn3_Config);
995 if (vortex_debug > 1)
996 printk(KERN_DEBUG " Internal config register is %4.4x, "
997 "transceivers %#x.\n", config, inw(ioaddr + Wn3_Options));
998 printk(KERN_INFO " %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
999 8 << RAM_SIZE(config),
1000 RAM_WIDTH(config) ? "word" : "byte",
1001 ram_split[RAM_SPLIT(config)],
1002 AUTOSELECT(config) ? "autoselect/" : "",
1003 XCVR(config) > XCVR_ExtMII ? "<invalid transceiver>" :
1004 media_tbl[XCVR(config)].name);
1005 vp->default_media = XCVR(config);
1006 vp->autoselect = AUTOSELECT(config);
1009 if (vp->media_override != 7) {
1010 printk(KERN_INFO " Media override to transceiver type %d (%s).\n",
1011 vp->media_override, media_tbl[vp->media_override].name);
1012 dev->if_port = vp->media_override;
1013 } else
1014 dev->if_port = vp->default_media;
1016 if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
1017 int phy, phy_idx = 0;
1018 EL3WINDOW(4);
1019 mii_preamble_required++;
1020 mii_preamble_required++;
1021 mdio_read(ioaddr, 24, 1);
1022 for (phy = 1; phy <= 32 && phy_idx < sizeof(vp->phys); phy++) {
1023 int mii_status, phyx = phy & 0x1f;
1024 mii_status = mdio_read(ioaddr, phyx, 1);
1025 if (mii_status && mii_status != 0xffff) {
1026 vp->phys[phy_idx++] = phyx;
1027 printk(KERN_INFO " MII transceiver found at address %d,"
1028 " status %4x.\n", phyx, mii_status);
1029 if ((mii_status & 0x0040) == 0)
1030 mii_preamble_required++;
1033 mii_preamble_required--;
1034 if (phy_idx == 0) {
1035 printk(KERN_WARNING" ***WARNING*** No MII transceivers found!\n");
1036 vp->phys[0] = 24;
1037 } else {
1038 vp->advertising = mdio_read(ioaddr, vp->phys[0], 4);
1039 if (vp->full_duplex) {
1040 /* Only advertise the FD media types. */
1041 vp->advertising &= ~0x02A0;
1042 mdio_write(ioaddr, vp->phys[0], 4, vp->advertising);
1047 if (vp->capabilities & CapPwrMgmt)
1048 acpi_set_WOL(dev);
1050 if (vp->capabilities & CapBusMaster) {
1051 vp->full_bus_master_tx = 1;
1052 printk(KERN_INFO" Enabling bus-master transmits and %s receives.\n",
1053 (vp->info2 & 1) ? "early" : "whole-frame" );
1054 vp->full_bus_master_rx = (vp->info2 & 1) ? 1 : 2;
1055 vp->bus_master = 0; /* AKPM: vortex only */
1058 /* The 3c59x-specific entries in the device structure. */
1059 dev->open = &vortex_open;
1060 dev->hard_start_xmit = &vortex_start_xmit;
1061 dev->stop = &vortex_close;
1062 dev->get_stats = &vortex_get_stats;
1063 dev->do_ioctl = &vortex_ioctl;
1064 dev->set_multicast_list = &set_rx_mode;
1065 dev->tx_timeout = &vortex_tx_timeout;
1066 dev->watchdog_timeo = (watchdog * HZ) / 1000;
1068 return 0;
1070 free_region:
1071 release_region (ioaddr, vci->io_size);
1072 free_dev:
1073 unregister_netdev(dev);
1074 kfree (dev);
1075 printk(KERN_ERR PFX "vortex_probe1 fails. Returns %d\n", retval);
1076 out:
1077 return retval;
1080 static void wait_for_completion(struct net_device *dev, int cmd)
1082 int i = 4000;
1084 outw(cmd, dev->base_addr + EL3_CMD);
1085 while (--i > 0)
1087 if (!(inw(dev->base_addr + EL3_STATUS) & CmdInProgress))
1088 return;
1090 printk(KERN_ERR "%s: command 0x%04x did not complete! Status=0x%x\n",
1091 dev->name, cmd, inw(dev->base_addr + EL3_STATUS));
1094 static void
1095 vortex_up(struct net_device *dev)
1097 long ioaddr = dev->base_addr;
1098 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1099 unsigned int config;
1100 int i, device_id;
1102 if (vp->pdev)
1103 device_id = vp->pdev->device;
1104 else
1105 device_id = 0x5900; /* EISA */
1107 /* Before initializing select the active media port. */
1108 EL3WINDOW(3);
1109 config = inl(ioaddr + Wn3_Config);
1111 if (vp->media_override != 7) {
1112 if (vortex_debug > 1)
1113 printk(KERN_INFO "%s: Media override to transceiver %d (%s).\n",
1114 dev->name, vp->media_override,
1115 media_tbl[vp->media_override].name);
1116 dev->if_port = vp->media_override;
1117 } else if (vp->autoselect) {
1118 if (vp->has_nway) {
1119 printk(KERN_INFO "%s: using NWAY autonegotiation\n", dev->name);
1120 dev->if_port = XCVR_NWAY;
1121 } else {
1122 /* Find first available media type, starting with 100baseTx. */
1123 dev->if_port = XCVR_100baseTx;
1124 while (! (vp->available_media & media_tbl[dev->if_port].mask))
1125 dev->if_port = media_tbl[dev->if_port].next;
1126 printk(KERN_INFO "%s: first available media type: %s\n",
1127 dev->name,
1128 media_tbl[dev->if_port].name);
1130 } else {
1131 dev->if_port = vp->default_media;
1132 printk(KERN_INFO "%s: using default media %s\n",
1133 dev->name, media_tbl[dev->if_port].name);
1136 init_timer(&vp->timer);
1137 vp->timer.expires = RUN_AT(media_tbl[dev->if_port].wait);
1138 vp->timer.data = (unsigned long)dev;
1139 vp->timer.function = &vortex_timer; /* timer handler */
1140 add_timer(&vp->timer);
1142 if (vortex_debug > 1)
1143 printk(KERN_DEBUG "%s: Initial media type %s.\n",
1144 dev->name, media_tbl[dev->if_port].name);
1146 vp->full_duplex = vp->force_fd;
1147 config = BFINS(config, dev->if_port, 20, 4);
1148 //AKPM if (!vp->has_nway)
1150 if (vortex_debug > 6)
1151 printk(KERN_DEBUG "vortex_up(): writing 0x%x to InternalConfig\n",
1152 config);
1153 outl(config, ioaddr + Wn3_Config);
1156 if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
1157 int mii_reg1, mii_reg5;
1158 EL3WINDOW(4);
1159 /* Read BMSR (reg1) only to clear old status. */
1160 mii_reg1 = mdio_read(ioaddr, vp->phys[0], 1);
1161 mii_reg5 = mdio_read(ioaddr, vp->phys[0], 5);
1162 if (mii_reg5 == 0xffff || mii_reg5 == 0x0000)
1163 ; /* No MII device or no link partner report */
1164 else if ((mii_reg5 & 0x0100) != 0 /* 100baseTx-FD */
1165 || (mii_reg5 & 0x00C0) == 0x0040) /* 10T-FD, but not 100-HD */
1166 vp->full_duplex = 1;
1167 if (vortex_debug > 1)
1168 printk(KERN_INFO "%s: MII #%d status %4.4x, link partner capability %4.4x,"
1169 " setting %s-duplex.\n", dev->name, vp->phys[0],
1170 mii_reg1, mii_reg5, vp->full_duplex ? "full" : "half");
1171 EL3WINDOW(3);
1174 /* Set the full-duplex bit. */
1175 outb(((vp->info1 & 0x8000) || vp->full_duplex ? 0x20 : 0) |
1176 (dev->mtu > 1500 ? 0x40 : 0), ioaddr + Wn3_MAC_Ctrl);
1178 if (vortex_debug > 1) {
1179 printk(KERN_DEBUG "%s: vortex_up() InternalConfig %8.8x.\n",
1180 dev->name, config);
1183 wait_for_completion(dev, TxReset);
1184 wait_for_completion(dev, RxReset);
1186 outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
1188 if (vortex_debug > 1) {
1189 EL3WINDOW(4);
1190 printk(KERN_DEBUG "%s: vortex_up() irq %d media status %4.4x.\n",
1191 dev->name, dev->irq, inw(ioaddr + Wn4_Media));
1194 /* Set the station address and mask in window 2 each time opened. */
1195 EL3WINDOW(2);
1196 for (i = 0; i < 6; i++)
1197 outb(dev->dev_addr[i], ioaddr + i);
1198 for (; i < 12; i+=2)
1199 outw(0, ioaddr + i);
1201 if (vp->cb_fn_base) {
1202 u_short n = inw(ioaddr + Wn2_ResetOptions);
1203 #if 0 /* AKPM: This is done in vortex_probe1, and seems to be wrong anyway... */
1204 /* Inverted LED polarity */
1205 if (device_id != 0x5257)
1206 n |= 0x0010;
1207 #endif
1208 /* Inverted polarity of MII power bit */
1209 if ((device_id == 0x6560) || (device_id == 0x6562) ||
1210 (device_id == 0x5257))
1211 n |= 0x4000;
1212 outw(n, ioaddr + Wn2_ResetOptions);
1215 if (dev->if_port == XCVR_10base2)
1216 /* Start the thinnet transceiver. We should really wait 50ms...*/
1217 outw(StartCoax, ioaddr + EL3_CMD);
1218 if (dev->if_port != XCVR_NWAY) {
1219 EL3WINDOW(4);
1220 outw((inw(ioaddr + Wn4_Media) & ~(Media_10TP|Media_SQE)) |
1221 media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
1224 /* Switch to the stats window, and clear all stats by reading. */
1225 outw(StatsDisable, ioaddr + EL3_CMD);
1226 EL3WINDOW(6);
1227 for (i = 0; i < 10; i++)
1228 inb(ioaddr + i);
1229 inw(ioaddr + 10);
1230 inw(ioaddr + 12);
1231 /* New: On the Vortex we must also clear the BadSSD counter. */
1232 EL3WINDOW(4);
1233 inb(ioaddr + 12);
1234 /* ..and on the Boomerang we enable the extra statistics bits. */
1235 outw(0x0040, ioaddr + Wn4_NetDiag);
1237 /* Switch to register set 7 for normal use. */
1238 EL3WINDOW(7);
1240 if (vp->full_bus_master_rx) { /* Boomerang bus master. */
1241 vp->cur_rx = vp->dirty_rx = 0;
1242 /* Initialize the RxEarly register as recommended. */
1243 outw(SetRxThreshold + (1536>>2), ioaddr + EL3_CMD);
1244 outl(0x0020, ioaddr + PktStatus);
1245 outl(vp->rx_ring_dma, ioaddr + UpListPtr);
1247 if (vp->full_bus_master_tx) { /* Boomerang bus master Tx. */
1248 dev->hard_start_xmit = &boomerang_start_xmit;
1249 vp->cur_tx = vp->dirty_tx = 0;
1250 outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold); /* Room for a packet. */
1251 /* Clear the Rx, Tx rings. */
1252 for (i = 0; i < RX_RING_SIZE; i++) /* AKPM: this is done in vortex_open, too */
1253 vp->rx_ring[i].status = 0;
1254 for (i = 0; i < TX_RING_SIZE; i++)
1255 vp->tx_skbuff[i] = 0;
1256 outl(0, ioaddr + DownListPtr);
1258 /* Set receiver mode: presumably accept b-case and phys addr only. */
1259 set_rx_mode(dev);
1260 outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
1262 outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
1263 outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
1264 /* Allow status bits to be seen. */
1265 vp->status_enable = SetStatusEnb | HostError|IntReq|StatsFull|TxComplete|
1266 (vp->full_bus_master_tx ? DownComplete : TxAvailable) |
1267 (vp->full_bus_master_rx ? UpComplete : RxComplete) |
1268 (vp->bus_master ? DMADone : 0);
1269 vp->intr_enable = SetIntrEnb | IntLatch | TxAvailable |
1270 (vp->full_bus_master_rx ? 0 : RxComplete) |
1271 StatsFull | HostError | TxComplete | IntReq
1272 | (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete;
1273 outw(vp->status_enable, ioaddr + EL3_CMD);
1274 /* Ack all pending events, and set active indicator mask. */
1275 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
1276 ioaddr + EL3_CMD);
1277 outw(vp->intr_enable, ioaddr + EL3_CMD);
1278 if (vp->cb_fn_base) /* The PCMCIA people are idiots. */
1279 writel(0x8000, vp->cb_fn_base + 4);
1281 if (extra_reset)
1283 /* AKPM: unjam the 3CCFE575CT */
1284 wait_for_completion(dev, TxReset);
1285 if (vp->full_bus_master_tx) {
1286 outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold);
1287 outw(DownUnstall, ioaddr + EL3_CMD);
1289 outw(TxEnable, ioaddr + EL3_CMD);
1291 netif_start_queue (dev);
1294 static int
1295 vortex_open(struct net_device *dev)
1297 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1298 int i;
1299 int retval;
1301 MOD_INC_USE_COUNT;
1303 /* Use the now-standard shared IRQ implementation. */
1304 if (request_irq(dev->irq, vp->full_bus_master_rx ? &boomerang_interrupt : &vortex_interrupt,
1305 SA_SHIRQ, dev->name, dev)) {
1306 retval = -EAGAIN;
1307 goto out;
1310 if (vp->full_bus_master_rx) { /* Boomerang bus master. */
1311 if (vortex_debug > 2)
1312 printk(KERN_DEBUG "%s: Filling in the Rx ring.\n", dev->name);
1313 for (i = 0; i < RX_RING_SIZE; i++) {
1314 struct sk_buff *skb;
1315 vp->rx_ring[i].next = cpu_to_le32(vp->rx_ring_dma + sizeof(struct boom_rx_desc) * (i+1));
1316 vp->rx_ring[i].status = 0; /* Clear complete bit. */
1317 vp->rx_ring[i].length = cpu_to_le32(PKT_BUF_SZ | LAST_FRAG);
1318 skb = dev_alloc_skb(PKT_BUF_SZ);
1319 vp->rx_skbuff[i] = skb;
1320 if (skb == NULL)
1321 break; /* Bad news! */
1322 skb->dev = dev; /* Mark as being used by this device. */
1323 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1324 vp->rx_ring[i].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->tail, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
1326 /* Wrap the ring. */
1327 vp->rx_ring[i-1].next = cpu_to_le32(vp->rx_ring_dma);
1330 vortex_up(dev);
1331 vp->open = 1;
1332 return 0;
1333 out:
1334 MOD_DEC_USE_COUNT;
1335 if (vortex_debug > 1)
1336 printk(KERN_ERR PFX "vortex_open() fails: returning %d\n", retval);
1337 return retval;
1340 static void vortex_timer(unsigned long data)
1342 struct net_device *dev = (struct net_device *)data;
1343 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1344 long ioaddr = dev->base_addr;
1345 int next_tick = 60*HZ;
1346 int ok = 0;
1347 int media_status, mii_status, old_window;
1349 if (vortex_debug > 1) {
1350 printk(KERN_DEBUG "%s: Media selection timer tick happened, %s.\n",
1351 dev->name, media_tbl[dev->if_port].name);
1352 printk(KERN_DEBUG "dev->watchdog_timeo=%d\n", dev->watchdog_timeo);
1355 disable_irq(dev->irq);
1356 old_window = inw(ioaddr + EL3_CMD) >> 13;
1357 EL3WINDOW(4);
1358 media_status = inw(ioaddr + Wn4_Media);
1359 switch (dev->if_port) {
1360 case XCVR_10baseT: case XCVR_100baseTx: case XCVR_100baseFx:
1361 if (media_status & Media_LnkBeat) {
1362 ok = 1;
1363 if (vortex_debug > 1)
1364 printk(KERN_DEBUG "%s: Media %s has link beat, %x.\n",
1365 dev->name, media_tbl[dev->if_port].name, media_status);
1366 } else if (vortex_debug > 1)
1367 printk(KERN_DEBUG "%s: Media %s has no link beat, %x.\n",
1368 dev->name, media_tbl[dev->if_port].name, media_status);
1369 break;
1370 case XCVR_MII: case XCVR_NWAY:
1372 unsigned long flags;
1373 spin_lock_irqsave(&vp->lock, flags); /* AKPM: protect mdio state */
1375 mii_status = mdio_read(ioaddr, vp->phys[0], 1);
1376 ok = 1;
1377 if (vortex_debug > 1)
1378 printk(KERN_DEBUG "%s: MII transceiver has status %4.4x.\n",
1379 dev->name, mii_status);
1380 if (mii_status & 0x0004) {
1381 int mii_reg5 = mdio_read(ioaddr, vp->phys[0], 5);
1382 if (! vp->force_fd && mii_reg5 != 0xffff) {
1383 int duplex = (mii_reg5&0x0100) ||
1384 (mii_reg5 & 0x01C0) == 0x0040;
1385 if (vp->full_duplex != duplex) {
1386 vp->full_duplex = duplex;
1387 printk(KERN_INFO "%s: Setting %s-duplex based on MII "
1388 "#%d link partner capability of %4.4x.\n",
1389 dev->name, vp->full_duplex ? "full" : "half",
1390 vp->phys[0], mii_reg5);
1391 /* Set the full-duplex bit. */
1392 EL3WINDOW(3); /* AKPM: this was missing from 2.3.99 3c59x.c! */
1393 outb((vp->full_duplex ? 0x20 : 0) |
1394 (dev->mtu > 1500 ? 0x40 : 0),
1395 ioaddr + Wn3_MAC_Ctrl);
1396 if (vortex_debug > 1)
1397 printk(KERN_DEBUG "Setting duplex in Wn3_MAC_Ctrl\n");
1398 /* AKPM: bug: should reset Tx and Rx after setting Duplex. Page 180 */
1400 next_tick = 60*HZ;
1403 spin_unlock_irqrestore(&vp->lock, flags);
1405 break;
1406 default: /* Other media types handled by Tx timeouts. */
1407 if (vortex_debug > 1)
1408 printk(KERN_DEBUG "%s: Media %s has no indication, %x.\n",
1409 dev->name, media_tbl[dev->if_port].name, media_status);
1410 ok = 1;
1412 if ( ! ok) {
1413 unsigned int config;
1415 do {
1416 dev->if_port = media_tbl[dev->if_port].next;
1417 } while ( ! (vp->available_media & media_tbl[dev->if_port].mask));
1418 if (dev->if_port == XCVR_Default) { /* Go back to default. */
1419 dev->if_port = vp->default_media;
1420 if (vortex_debug > 1)
1421 printk(KERN_DEBUG "%s: Media selection failing, using default "
1422 "%s port.\n",
1423 dev->name, media_tbl[dev->if_port].name);
1424 } else {
1425 if (vortex_debug > 1)
1426 printk(KERN_DEBUG "%s: Media selection failed, now trying "
1427 "%s port.\n",
1428 dev->name, media_tbl[dev->if_port].name);
1429 next_tick = media_tbl[dev->if_port].wait;
1431 outw((media_status & ~(Media_10TP|Media_SQE)) |
1432 media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
1434 EL3WINDOW(3);
1435 config = inl(ioaddr + Wn3_Config);
1436 config = BFINS(config, dev->if_port, 20, 4);
1437 outl(config, ioaddr + Wn3_Config);
1439 outw(dev->if_port == XCVR_10base2 ? StartCoax : StopCoax,
1440 ioaddr + EL3_CMD);
1441 if (vortex_debug > 1)
1442 printk(KERN_DEBUG "wrote 0x%08x to Wn3_Config\n", config);
1443 /* AKPM: FIXME: Should reset Rx & Tx here. P60 of 3c90xc.pdf */
1445 EL3WINDOW(old_window);
1446 enable_irq(dev->irq);
1448 if (vortex_debug > 1)
1449 printk(KERN_DEBUG "%s: Media selection timer finished, %s.\n",
1450 dev->name, media_tbl[dev->if_port].name);
1452 mod_timer(&vp->timer, RUN_AT(next_tick));
1453 if (vp->deferred)
1454 outw(FakeIntr, ioaddr + EL3_CMD);
1455 return;
1458 static void vortex_tx_timeout(struct net_device *dev)
1460 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1461 long ioaddr = dev->base_addr;
1463 printk(KERN_ERR "%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
1464 dev->name, inb(ioaddr + TxStatus),
1465 inw(ioaddr + EL3_STATUS));
1467 /* Slight code bloat to be user friendly. */
1468 if ((inb(ioaddr + TxStatus) & 0x88) == 0x88)
1469 printk(KERN_ERR "%s: Transmitter encountered 16 collisions --"
1470 " network cable problem?\n", dev->name);
1471 if (inw(ioaddr + EL3_STATUS) & IntLatch) {
1472 printk(KERN_ERR "%s: Interrupt posted but not delivered --"
1473 " IRQ blocked by another device?\n", dev->name);
1474 /* Bad idea here.. but we might as well handle a few events. */
1477 * AKPM: block interrupts because vortex_interrupt
1478 * does a bare spin_lock()
1480 unsigned long flags;
1481 local_irq_save(flags);
1482 if (vp->full_bus_master_tx)
1483 boomerang_interrupt(dev->irq, dev, 0);
1484 else
1485 vortex_interrupt(dev->irq, dev, 0);
1486 local_irq_restore(flags);
1490 if (vortex_debug > 0)
1491 dump_tx_ring(dev);
1493 wait_for_completion(dev, TxReset);
1495 vp->stats.tx_errors++;
1496 if (vp->full_bus_master_tx) {
1497 if (vortex_debug > 0)
1498 printk(KERN_DEBUG "%s: Resetting the Tx ring pointer.\n",
1499 dev->name);
1500 if (vp->cur_tx - vp->dirty_tx > 0 && inl(ioaddr + DownListPtr) == 0)
1501 outl(vp->tx_ring_dma + (vp->dirty_tx % TX_RING_SIZE) * sizeof(struct boom_tx_desc),
1502 ioaddr + DownListPtr);
1503 if (vp->tx_full && (vp->cur_tx - vp->dirty_tx <= TX_RING_SIZE - 1)) {
1504 vp->tx_full = 0;
1505 netif_wake_queue (dev);
1507 if (vp->tx_full)
1508 netif_stop_queue (dev);
1509 outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold);
1510 outw(DownUnstall, ioaddr + EL3_CMD);
1511 } else {
1512 vp->stats.tx_dropped++;
1513 netif_wake_queue(dev);
1516 /* Issue Tx Enable */
1517 outw(TxEnable, ioaddr + EL3_CMD);
1518 dev->trans_start = jiffies;
1520 /* Switch to register set 7 for normal use. */
1521 EL3WINDOW(7);
1525 * Handle uncommon interrupt sources. This is a separate routine to minimize
1526 * the cache impact.
1528 static void
1529 vortex_error(struct net_device *dev, int status)
1531 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1532 long ioaddr = dev->base_addr;
1533 int do_tx_reset = 0;
1534 unsigned char tx_status = 0;
1536 if (vortex_debug > 2) {
1537 printk(KERN_DEBUG "%s: vortex_error(), status=0x%x\n", dev->name, status);
1540 if (status & TxComplete) { /* Really "TxError" for us. */
1541 tx_status = inb(ioaddr + TxStatus);
1542 /* Presumably a tx-timeout. We must merely re-enable. */
1543 if (vortex_debug > 2
1544 || (tx_status != 0x88 && vortex_debug > 0)) {
1545 printk(KERN_DEBUG"%s: Transmit error, Tx status register %2.2x.\n",
1546 dev->name, tx_status);
1547 dump_tx_ring(dev);
1549 if (tx_status & 0x14) vp->stats.tx_fifo_errors++;
1550 if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
1551 outb(0, ioaddr + TxStatus);
1552 if (tx_status & 0x38) /* AKPM: tx reset after 16 collisions, despite what the manual says */
1553 do_tx_reset = 1;
1554 else /* Merely re-enable the transmitter. */
1555 outw(TxEnable, ioaddr + EL3_CMD);
1558 if (status & RxEarly) { /* Rx early is unused. */
1559 vortex_rx(dev);
1560 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
1562 if (status & StatsFull) { /* Empty statistics. */
1563 static int DoneDidThat = 0;
1564 if (vortex_debug > 4)
1565 printk(KERN_DEBUG "%s: Updating stats.\n", dev->name);
1566 update_stats(ioaddr, dev);
1567 /* HACK: Disable statistics as an interrupt source. */
1568 /* This occurs when we have the wrong media type! */
1569 if (DoneDidThat == 0 &&
1570 inw(ioaddr + EL3_STATUS) & StatsFull) {
1571 printk(KERN_WARNING "%s: Updating statistics failed, disabling "
1572 "stats as an interrupt source.\n", dev->name);
1573 EL3WINDOW(5);
1574 outw(SetIntrEnb | (inw(ioaddr + 10) & ~StatsFull), ioaddr + EL3_CMD);
1575 vp->intr_enable &= ~StatsFull;
1576 EL3WINDOW(7);
1577 DoneDidThat++;
1580 if (status & IntReq) { /* Restore all interrupt sources. */
1581 outw(vp->status_enable, ioaddr + EL3_CMD);
1582 outw(vp->intr_enable, ioaddr + EL3_CMD);
1584 if (status & HostError) {
1585 u16 fifo_diag;
1586 EL3WINDOW(4);
1587 fifo_diag = inw(ioaddr + Wn4_FIFODiag);
1588 printk(KERN_ERR "%s: Host error, FIFO diagnostic register %4.4x.\n",
1589 dev->name, fifo_diag);
1590 /* Adapter failure requires Tx/Rx reset and reinit. */
1591 if (vp->full_bus_master_tx) {
1592 /* In this case, blow the card away */
1593 vortex_down(dev);
1594 wait_for_completion(dev, TotalReset | 0xff);
1595 vortex_up(dev);
1596 } else if (fifo_diag & 0x0400)
1597 do_tx_reset = 1;
1598 if (fifo_diag & 0x3000) {
1599 wait_for_completion(dev, RxReset);
1600 /* Set the Rx filter to the current state. */
1601 set_rx_mode(dev);
1602 outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
1603 outw(AckIntr | HostError, ioaddr + EL3_CMD);
1608 * Black magic. If we're resetting the transmitter, remember the current downlist
1609 * pointer and restore it afterwards. We can't usr cur_tx because that could
1610 * lag the actual hardware index.
1612 if (do_tx_reset) {
1613 if (vp->full_bus_master_tx) {
1614 unsigned long old_down_list_ptr;
1616 wait_for_completion(dev, DownStall);
1617 old_down_list_ptr = inl(ioaddr + DownListPtr);
1618 wait_for_completion(dev, TxReset);
1619 outw(TxEnable, ioaddr + EL3_CMD);
1621 /* Restart DMA if necessary */
1622 outl(old_down_list_ptr, ioaddr + DownListPtr);
1623 if (vortex_debug > 2)
1624 printk(KERN_DEBUG "reset DMA to 0x%08x\n", inl(ioaddr + DownListPtr));
1625 outw(DownUnstall, ioaddr + EL3_CMD);
1628 * Here we make a single attempt to prevent a timeout by
1629 * restarting the timer if we think that the ISR has a good
1630 * chance of unjamming things.
1632 if (vp->tx_reset_resume == 0 && vp->tx_full) {
1633 vp->tx_reset_resume = 1;
1634 dev->trans_start = jiffies;
1636 } else {
1637 wait_for_completion(dev, TxReset);
1638 outw(TxEnable, ioaddr + EL3_CMD);
1639 netif_wake_queue(dev);
1644 static int
1645 vortex_start_xmit(struct sk_buff *skb, struct net_device *dev)
1647 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1648 long ioaddr = dev->base_addr;
1650 /* Put out the doubleword header... */
1651 outl(skb->len, ioaddr + TX_FIFO);
1652 if (vp->bus_master) {
1653 /* Set the bus-master controller to transfer the packet. */
1654 int len = (skb->len + 3) & ~3;
1655 outl( vp->tx_skb_dma = pci_map_single(vp->pdev, skb->data, len, PCI_DMA_TODEVICE),
1656 ioaddr + Wn7_MasterAddr);
1657 outw(len, ioaddr + Wn7_MasterLen);
1658 vp->tx_skb = skb;
1659 outw(StartDMADown, ioaddr + EL3_CMD);
1660 /* netif_wake_queue() will be called at the DMADone interrupt. */
1661 } else {
1662 /* ... and the packet rounded to a doubleword. */
1663 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
1664 dev_kfree_skb (skb);
1665 if (inw(ioaddr + TxFree) > 1536) {
1666 netif_start_queue (dev); /* AKPM: redundant? */
1667 } else {
1668 /* Interrupt us when the FIFO has room for max-sized packet. */
1669 netif_stop_queue(dev);
1670 outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
1674 dev->trans_start = jiffies;
1676 /* Clear the Tx status stack. */
1678 int tx_status;
1679 int i = 32;
1681 while (--i > 0 && (tx_status = inb(ioaddr + TxStatus)) > 0) {
1682 if (tx_status & 0x3C) { /* A Tx-disabling error occurred. */
1683 if (vortex_debug > 2)
1684 printk(KERN_DEBUG "%s: Tx error, status %2.2x.\n",
1685 dev->name, tx_status);
1686 if (tx_status & 0x04) vp->stats.tx_fifo_errors++;
1687 if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
1688 if (tx_status & 0x30) {
1689 wait_for_completion(dev, TxReset);
1691 outw(TxEnable, ioaddr + EL3_CMD);
1693 outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */
1696 return 0;
1699 static int
1700 boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
1702 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1703 long ioaddr = dev->base_addr;
1704 /* Calculate the next Tx descriptor entry. */
1705 int entry = vp->cur_tx % TX_RING_SIZE;
1706 struct boom_tx_desc *prev_entry = &vp->tx_ring[(vp->cur_tx-1) % TX_RING_SIZE];
1707 unsigned long flags;
1709 if (vortex_debug > 6)
1710 printk(KERN_DEBUG "boomerang_start_xmit()\n");
1712 if (vortex_debug > 3)
1713 printk(KERN_DEBUG "%s: Trying to send a packet, Tx index %d.\n",
1714 dev->name, vp->cur_tx);
1715 if (vp->tx_full) {
1716 if (vortex_debug > 0)
1717 printk(KERN_WARNING "%s: Tx Ring full, refusing to send buffer.\n",
1718 dev->name);
1719 return 1;
1721 vp->tx_skbuff[entry] = skb;
1722 vp->tx_ring[entry].next = 0;
1723 vp->tx_ring[entry].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->data, skb->len, PCI_DMA_TODEVICE));
1724 vp->tx_ring[entry].length = cpu_to_le32(skb->len | LAST_FRAG);
1725 vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded);
1727 spin_lock_irqsave(&vp->lock, flags);
1728 /* Wait for the stall to complete. */
1729 wait_for_completion(dev, DownStall);
1730 prev_entry->next = cpu_to_le32(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc));
1731 if (inl(ioaddr + DownListPtr) == 0) {
1732 outl(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc), ioaddr + DownListPtr);
1733 queued_packet++;
1736 vp->cur_tx++;
1737 if (vp->cur_tx - vp->dirty_tx > TX_RING_SIZE - 1) {
1738 vp->tx_full = 1;
1739 netif_stop_queue (dev);
1740 } else { /* Clear previous interrupt enable. */
1741 #if defined(tx_interrupt_mitigation)
1742 prev_entry->status &= cpu_to_le32(~TxIntrUploaded);
1743 #endif
1744 /* netif_start_queue (dev); */ /* AKPM: redundant? */
1746 outw(DownUnstall, ioaddr + EL3_CMD);
1747 vp->tx_reset_resume = 0;
1748 spin_unlock_irqrestore(&vp->lock, flags);
1749 dev->trans_start = jiffies;
1750 return 0;
1753 /* The interrupt handler does all of the Rx thread work and cleans up
1754 after the Tx thread. */
1757 * This is the ISR for the vortex series chips.
1758 * full_bus_master_tx == 0 && full_bus_master_rx == 0
1761 static void vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1763 struct net_device *dev = dev_id;
1764 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1765 long ioaddr;
1766 int status;
1767 int work_done = max_interrupt_work;
1769 spin_lock(&vp->lock);
1771 ioaddr = dev->base_addr;
1772 status = inw(ioaddr + EL3_STATUS);
1774 if (vortex_debug > 6)
1775 printk("vortex_interrupt(). status=0x%4x\n", status);
1777 if (status & IntReq) {
1778 status |= vp->deferred;
1779 vp->deferred = 0;
1782 if (status == 0xffff) /* AKPM: h/w no longer present (hotplug)? */
1783 goto handler_exit;
1785 if (vortex_debug > 4)
1786 printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n",
1787 dev->name, status, inb(ioaddr + Timer));
1788 do {
1789 if (vortex_debug > 5)
1790 printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n",
1791 dev->name, status);
1792 if (status & RxComplete)
1793 vortex_rx(dev);
1795 if (status & TxAvailable) {
1796 if (vortex_debug > 5)
1797 printk(KERN_DEBUG " TX room bit was handled.\n");
1798 /* There's room in the FIFO for a full-sized packet. */
1799 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
1800 netif_wake_queue (dev);
1803 if (status & DMADone) {
1804 if (inw(ioaddr + Wn7_MasterStatus) & 0x1000) {
1805 outw(0x1000, ioaddr + Wn7_MasterStatus); /* Ack the event. */
1806 pci_unmap_single(vp->pdev, vp->tx_skb_dma, (vp->tx_skb->len + 3) & ~3, PCI_DMA_TODEVICE);
1807 dev_kfree_skb_irq(vp->tx_skb); /* Release the transferred buffer */
1808 if (inw(ioaddr + TxFree) > 1536) {
1810 * AKPM: FIXME: I don't think we need this. If the queue was stopped due to
1811 * insufficient FIFO room, the TxAvailable test will succeed and call
1812 * netif_wake_queue()
1814 netif_wake_queue(dev);
1815 } else { /* Interrupt when FIFO has room for max-sized packet. */
1816 outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
1817 netif_stop_queue(dev); /* AKPM: This is new */
1821 /* Check for all uncommon interrupts at once. */
1822 if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq)) {
1823 if (status == 0xffff)
1824 break;
1825 vortex_error(dev, status);
1828 if (--work_done < 0) {
1829 printk(KERN_WARNING "%s: Too much work in interrupt, status "
1830 "%4.4x.\n", dev->name, status);
1831 /* Disable all pending interrupts. */
1832 do {
1833 vp->deferred |= status;
1834 outw(SetStatusEnb | (~vp->deferred & vp->status_enable),
1835 ioaddr + EL3_CMD);
1836 outw(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
1837 } while ((status = inw(ioaddr + EL3_CMD)) & IntLatch);
1838 /* The timer will reenable interrupts. */
1839 mod_timer(&vp->timer, jiffies + 1*HZ);
1840 break;
1842 /* Acknowledge the IRQ. */
1843 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
1844 if (vp->cb_fn_base) /* The PCMCIA people are idiots. */
1845 writel(0x8000, vp->cb_fn_base + 4);
1847 } while ((status = inw(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete));
1849 if (vortex_debug > 4)
1850 printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
1851 dev->name, status);
1852 handler_exit:
1853 spin_unlock(&vp->lock);
1857 * This is the ISR for the boomerang series chips.
1858 * full_bus_master_tx == 1 && full_bus_master_rx == 1
1861 static void boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1863 struct net_device *dev = dev_id;
1864 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1865 long ioaddr;
1866 int status;
1867 int work_done = max_interrupt_work;
1869 spin_lock(&vp->lock);
1871 ioaddr = dev->base_addr;
1872 status = inw(ioaddr + EL3_STATUS);
1874 if (vortex_debug > 6)
1875 printk(KERN_DEBUG "boomerang_interrupt. status=0x%4x\n", status);
1877 if (status == 0xffff) { /* AKPM: h/w no longer present (hotplug)? */
1878 if (vortex_debug > 1)
1879 printk(KERN_DEBUG "boomerang_interrupt(1): status = 0xffff\n");
1880 goto handler_exit;
1883 if (status & IntReq) {
1884 status |= vp->deferred;
1885 vp->deferred = 0;
1888 if (vortex_debug > 4)
1889 printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n",
1890 dev->name, status, inb(ioaddr + Timer));
1891 do {
1892 if (vortex_debug > 5)
1893 printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n",
1894 dev->name, status);
1895 if (status & UpComplete) {
1896 outw(AckIntr | UpComplete, ioaddr + EL3_CMD);
1897 if (vortex_debug > 5)
1898 printk(KERN_DEBUG "boomerang_interrupt->boomerang_rx\n");
1899 boomerang_rx(dev);
1902 if (status & DownComplete) {
1903 unsigned int dirty_tx = vp->dirty_tx;
1905 outw(AckIntr | DownComplete, ioaddr + EL3_CMD);
1906 while (vp->cur_tx - dirty_tx > 0) {
1907 int entry = dirty_tx % TX_RING_SIZE;
1908 #if 1 /* AKPM: the latter is faster, but cyclone-only */
1909 if (inl(ioaddr + DownListPtr) ==
1910 vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc))
1911 break; /* It still hasn't been processed. */
1912 #else
1913 if ((vp->tx_ring[entry].status & DN_COMPLETE) == 0)
1914 break; /* It still hasn't been processed. */
1915 #endif
1917 if (vp->tx_skbuff[entry]) {
1918 struct sk_buff *skb = vp->tx_skbuff[entry];
1920 pci_unmap_single(vp->pdev,
1921 le32_to_cpu(vp->tx_ring[entry].addr), skb->len, PCI_DMA_TODEVICE);
1922 dev_kfree_skb_irq(skb);
1923 vp->tx_skbuff[entry] = 0;
1924 } else {
1925 printk(KERN_DEBUG "boomerang_interrupt: no skb!\n");
1927 /* vp->stats.tx_packets++; Counted below. */
1928 dirty_tx++;
1930 vp->dirty_tx = dirty_tx;
1931 if (vp->tx_full && (vp->cur_tx - dirty_tx <= TX_RING_SIZE - 1)) {
1932 if (vortex_debug > 6)
1933 printk(KERN_DEBUG "boomerang_interrupt: clearing tx_full\n");
1934 vp->tx_full = 0;
1935 netif_wake_queue (dev);
1939 /* Check for all uncommon interrupts at once. */
1940 if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq))
1941 vortex_error(dev, status);
1943 if (--work_done < 0) {
1944 printk(KERN_WARNING "%s: Too much work in interrupt, status "
1945 "%4.4x.\n", dev->name, status);
1946 /* Disable all pending interrupts. */
1947 do {
1948 vp->deferred |= status;
1949 outw(SetStatusEnb | (~vp->deferred & vp->status_enable),
1950 ioaddr + EL3_CMD);
1951 outw(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
1952 } while ((status = inw(ioaddr + EL3_CMD)) & IntLatch);
1953 /* The timer will reenable interrupts. */
1954 mod_timer(&vp->timer, jiffies + 1*HZ);
1955 break;
1957 /* Acknowledge the IRQ. */
1958 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
1959 if (vp->cb_fn_base) /* The PCMCIA people are idiots. */
1960 writel(0x8000, vp->cb_fn_base + 4);
1962 } while ((status = inw(ioaddr + EL3_STATUS)) & IntLatch);
1964 if (vortex_debug > 4)
1965 printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
1966 dev->name, status);
1967 handler_exit:
1968 spin_unlock(&vp->lock);
1971 static int vortex_rx(struct net_device *dev)
1973 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1974 long ioaddr = dev->base_addr;
1975 int i;
1976 short rx_status;
1978 if (vortex_debug > 5)
1979 printk(KERN_DEBUG "vortex_rx(): status %4.4x, rx_status %4.4x.\n",
1980 inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
1981 while ((rx_status = inw(ioaddr + RxStatus)) > 0) {
1982 if (rx_status & 0x4000) { /* Error, update stats. */
1983 unsigned char rx_error = inb(ioaddr + RxErrors);
1984 if (vortex_debug > 2)
1985 printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
1986 vp->stats.rx_errors++;
1987 if (rx_error & 0x01) vp->stats.rx_over_errors++;
1988 if (rx_error & 0x02) vp->stats.rx_length_errors++;
1989 if (rx_error & 0x04) vp->stats.rx_frame_errors++;
1990 if (rx_error & 0x08) vp->stats.rx_crc_errors++;
1991 if (rx_error & 0x10) vp->stats.rx_length_errors++;
1992 } else {
1993 /* The packet length: up to 4.5K!. */
1994 int pkt_len = rx_status & 0x1fff;
1995 struct sk_buff *skb;
1997 skb = dev_alloc_skb(pkt_len + 5);
1998 if (vortex_debug > 4)
1999 printk(KERN_DEBUG "Receiving packet size %d status %4.4x.\n",
2000 pkt_len, rx_status);
2001 if (skb != NULL) {
2002 skb->dev = dev;
2003 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
2004 /* 'skb_put()' points to the start of sk_buff data area. */
2005 if (vp->bus_master &&
2006 ! (inw(ioaddr + Wn7_MasterStatus) & 0x8000)) {
2007 dma_addr_t dma = pci_map_single(vp->pdev, skb_put(skb, pkt_len),
2008 pkt_len, PCI_DMA_FROMDEVICE);
2009 outl(dma, ioaddr + Wn7_MasterAddr);
2010 outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
2011 outw(StartDMAUp, ioaddr + EL3_CMD);
2012 while (inw(ioaddr + Wn7_MasterStatus) & 0x8000)
2014 pci_unmap_single(vp->pdev, dma, pkt_len, PCI_DMA_FROMDEVICE);
2015 } else {
2016 insl(ioaddr + RX_FIFO, skb_put(skb, pkt_len),
2017 (pkt_len + 3) >> 2);
2019 outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
2020 skb->protocol = eth_type_trans(skb, dev);
2021 netif_rx(skb);
2022 dev->last_rx = jiffies;
2023 vp->stats.rx_packets++;
2024 /* Wait a limited time to go to next packet. */
2025 for (i = 200; i >= 0; i--)
2026 if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
2027 break;
2028 continue;
2029 } else if (vortex_debug > 0)
2030 printk(KERN_NOTICE "%s: No memory to allocate a sk_buff of "
2031 "size %d.\n", dev->name, pkt_len);
2033 vp->stats.rx_dropped++;
2034 wait_for_completion(dev, RxDiscard);
2037 return 0;
2040 static int
2041 boomerang_rx(struct net_device *dev)
2043 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2044 int entry = vp->cur_rx % RX_RING_SIZE;
2045 long ioaddr = dev->base_addr;
2046 int rx_status;
2047 int rx_work_limit = vp->dirty_rx + RX_RING_SIZE - vp->cur_rx;
2049 if (vortex_debug > 5)
2050 printk(KERN_DEBUG "boomerang_rx(): status %4.4x\n", inw(ioaddr+EL3_STATUS));
2052 while ((rx_status = le32_to_cpu(vp->rx_ring[entry].status)) & RxDComplete){
2053 if (--rx_work_limit < 0)
2054 break;
2055 if (rx_status & RxDError) { /* Error, update stats. */
2056 unsigned char rx_error = rx_status >> 16;
2057 if (vortex_debug > 2)
2058 printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
2059 vp->stats.rx_errors++;
2060 if (rx_error & 0x01) vp->stats.rx_over_errors++;
2061 if (rx_error & 0x02) vp->stats.rx_length_errors++;
2062 if (rx_error & 0x04) vp->stats.rx_frame_errors++;
2063 if (rx_error & 0x08) vp->stats.rx_crc_errors++;
2064 if (rx_error & 0x10) vp->stats.rx_length_errors++;
2065 } else {
2066 /* The packet length: up to 4.5K!. */
2067 int pkt_len = rx_status & 0x1fff;
2068 struct sk_buff *skb;
2069 dma_addr_t dma = le32_to_cpu(vp->rx_ring[entry].addr);
2071 vp->stats.rx_bytes += pkt_len;
2072 if (vortex_debug > 4)
2073 printk(KERN_DEBUG "Receiving packet size %d status %4.4x.\n",
2074 pkt_len, rx_status);
2076 /* Check if the packet is long enough to just accept without
2077 copying to a properly sized skbuff. */
2078 if (pkt_len < rx_copybreak && (skb = dev_alloc_skb(pkt_len + 2)) != 0) {
2079 skb->dev = dev;
2080 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
2081 pci_dma_sync_single(vp->pdev, dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2082 /* 'skb_put()' points to the start of sk_buff data area. */
2083 memcpy(skb_put(skb, pkt_len),
2084 vp->rx_skbuff[entry]->tail,
2085 pkt_len);
2086 rx_copy++;
2087 } else {
2088 /* Pass up the skbuff already on the Rx ring. */
2089 skb = vp->rx_skbuff[entry];
2090 vp->rx_skbuff[entry] = NULL;
2091 skb_put(skb, pkt_len);
2092 pci_unmap_single(vp->pdev, dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2093 rx_nocopy++;
2095 skb->protocol = eth_type_trans(skb, dev);
2096 { /* Use hardware checksum info. */
2097 int csum_bits = rx_status & 0xee000000;
2098 if (csum_bits &&
2099 (csum_bits == (IPChksumValid | TCPChksumValid) ||
2100 csum_bits == (IPChksumValid | UDPChksumValid))) {
2101 skb->ip_summed = CHECKSUM_UNNECESSARY;
2102 rx_csumhits++;
2105 netif_rx(skb);
2106 dev->last_rx = jiffies;
2107 vp->stats.rx_packets++;
2109 entry = (++vp->cur_rx) % RX_RING_SIZE;
2111 /* Refill the Rx ring buffers. */
2112 for (; vp->cur_rx - vp->dirty_rx > 0; vp->dirty_rx++) {
2113 struct sk_buff *skb;
2114 entry = vp->dirty_rx % RX_RING_SIZE;
2115 if (vp->rx_skbuff[entry] == NULL) {
2116 skb = dev_alloc_skb(PKT_BUF_SZ);
2117 if (skb == NULL) {
2118 static unsigned long last_jif;
2119 if ((jiffies - last_jif) > 10 * HZ) {
2120 printk(KERN_WARNING "%s: memory shortage\n", dev->name);
2121 last_jif = jiffies;
2123 break; /* Bad news! */
2125 skb->dev = dev; /* Mark as being used by this device. */
2126 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
2127 vp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->tail, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
2128 vp->rx_skbuff[entry] = skb;
2130 vp->rx_ring[entry].status = 0; /* Clear complete bit. */
2131 outw(UpUnstall, ioaddr + EL3_CMD);
2133 return 0;
2136 static void
2137 vortex_down(struct net_device *dev)
2139 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2140 long ioaddr = dev->base_addr;
2142 netif_stop_queue (dev);
2144 del_timer_sync(&vp->timer);
2146 /* Turn off statistics ASAP. We update vp->stats below. */
2147 outw(StatsDisable, ioaddr + EL3_CMD);
2149 /* Disable the receiver and transmitter. */
2150 outw(RxDisable, ioaddr + EL3_CMD);
2151 outw(TxDisable, ioaddr + EL3_CMD);
2153 if (dev->if_port == XCVR_10base2)
2154 /* Turn off thinnet power. Green! */
2155 outw(StopCoax, ioaddr + EL3_CMD);
2157 outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
2159 update_stats(ioaddr, dev);
2160 if (vp->full_bus_master_rx)
2161 outl(0, ioaddr + UpListPtr);
2162 if (vp->full_bus_master_tx)
2163 outl(0, ioaddr + DownListPtr);
2165 if (vp->capabilities & CapPwrMgmt)
2166 acpi_set_WOL(dev);
2169 static int
2170 vortex_close(struct net_device *dev)
2172 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2173 long ioaddr = dev->base_addr;
2174 int i;
2176 if (netif_device_present(dev))
2177 vortex_down(dev);
2179 if (vortex_debug > 1) {
2180 printk(KERN_DEBUG"%s: vortex_close() status %4.4x, Tx status %2.2x.\n",
2181 dev->name, inw(ioaddr + EL3_STATUS), inb(ioaddr + TxStatus));
2182 printk(KERN_DEBUG "%s: vortex close stats: rx_nocopy %d rx_copy %d"
2183 " tx_queued %d Rx pre-checksummed %d.\n",
2184 dev->name, rx_nocopy, rx_copy, queued_packet, rx_csumhits);
2187 free_irq(dev->irq, dev);
2189 if (vp->full_bus_master_rx) { /* Free Boomerang bus master Rx buffers. */
2190 for (i = 0; i < RX_RING_SIZE; i++)
2191 if (vp->rx_skbuff[i]) {
2192 pci_unmap_single( vp->pdev, le32_to_cpu(vp->rx_ring[i].addr),
2193 PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2194 dev_kfree_skb(vp->rx_skbuff[i]);
2195 vp->rx_skbuff[i] = 0;
2198 if (vp->full_bus_master_tx) { /* Free Boomerang bus master Tx buffers. */
2199 for (i = 0; i < TX_RING_SIZE; i++)
2200 if (vp->tx_skbuff[i]) {
2201 struct sk_buff *skb = vp->tx_skbuff[i];
2203 pci_unmap_single(vp->pdev, le32_to_cpu(vp->tx_ring[i].addr), skb->len, PCI_DMA_TODEVICE);
2204 dev_kfree_skb(skb);
2205 vp->tx_skbuff[i] = 0;
2209 MOD_DEC_USE_COUNT;
2210 vp->open = 0;
2211 return 0;
2214 static void
2215 dump_tx_ring(struct net_device *dev)
2217 if (vortex_debug > 0) {
2218 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2219 long ioaddr = dev->base_addr;
2221 if (vp->full_bus_master_tx) {
2222 int i;
2223 int stalled = inl(ioaddr + PktStatus) & 0x04; /* Possible racy. But it's only debug stuff */
2225 wait_for_completion(dev, DownStall);
2226 printk(KERN_ERR " Flags; bus-master %d, full %d; dirty %d(%d) "
2227 "current %d(%d).\n",
2228 vp->full_bus_master_tx, vp->tx_full,
2229 vp->dirty_tx, vp->dirty_tx % TX_RING_SIZE,
2230 vp->cur_tx, vp->cur_tx % TX_RING_SIZE);
2231 printk(KERN_ERR " Transmit list %8.8x vs. %p.\n",
2232 inl(ioaddr + DownListPtr),
2233 &vp->tx_ring[vp->dirty_tx % TX_RING_SIZE]);
2234 for (i = 0; i < TX_RING_SIZE; i++) {
2235 printk(KERN_ERR " %d: @%p length %8.8x status %8.8x\n", i,
2236 &vp->tx_ring[i],
2237 le32_to_cpu(vp->tx_ring[i].length),
2238 le32_to_cpu(vp->tx_ring[i].status));
2240 if (!stalled)
2241 outw(DownUnstall, ioaddr + EL3_CMD);
2246 static struct net_device_stats *vortex_get_stats(struct net_device *dev)
2248 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2249 unsigned long flags;
2251 if (netif_device_present(dev)) { /* AKPM: Used to be netif_running */
2252 spin_lock_irqsave (&vp->lock, flags);
2253 update_stats(dev->base_addr, dev);
2254 spin_unlock_irqrestore (&vp->lock, flags);
2256 return &vp->stats;
2259 /* Update statistics.
2260 Unlike with the EL3 we need not worry about interrupts changing
2261 the window setting from underneath us, but we must still guard
2262 against a race condition with a StatsUpdate interrupt updating the
2263 table. This is done by checking that the ASM (!) code generated uses
2264 atomic updates with '+='.
2266 static void update_stats(long ioaddr, struct net_device *dev)
2268 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2269 int old_window = inw(ioaddr + EL3_CMD);
2271 if (old_window == 0xffff) /* Chip suspended or ejected. */
2272 return;
2273 /* Unlike the 3c5x9 we need not turn off stats updates while reading. */
2274 /* Switch to the stats window, and read everything. */
2275 EL3WINDOW(6);
2276 vp->stats.tx_carrier_errors += inb(ioaddr + 0);
2277 vp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
2278 /* Multiple collisions. */ inb(ioaddr + 2);
2279 vp->stats.collisions += inb(ioaddr + 3);
2280 vp->stats.tx_window_errors += inb(ioaddr + 4);
2281 vp->stats.rx_fifo_errors += inb(ioaddr + 5);
2282 vp->stats.tx_packets += inb(ioaddr + 6);
2283 vp->stats.tx_packets += (inb(ioaddr + 9)&0x30) << 4;
2284 /* Rx packets */ inb(ioaddr + 7); /* Must read to clear */
2285 /* Tx deferrals */ inb(ioaddr + 8);
2286 /* Don't bother with register 9, an extension of registers 6&7.
2287 If we do use the 6&7 values the atomic update assumption above
2288 is invalid. */
2289 vp->stats.rx_bytes += inw(ioaddr + 10);
2290 vp->stats.tx_bytes += inw(ioaddr + 12);
2291 /* New: On the Vortex we must also clear the BadSSD counter. */
2292 EL3WINDOW(4);
2293 inb(ioaddr + 12);
2296 u8 up = inb(ioaddr + 13);
2297 vp->stats.rx_bytes += (up & 0x0f) << 16;
2298 vp->stats.tx_bytes += (up & 0xf0) << 12;
2301 /* We change back to window 7 (not 1) with the Vortex. */
2302 /* AKPM: the previous comment is obsolete - we switch back to the old window */
2303 EL3WINDOW(old_window >> 13);
2304 return;
2307 static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2309 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2310 long ioaddr = dev->base_addr;
2311 u16 *data = (u16 *)&rq->ifr_data;
2312 int phy = vp->phys[0] & 0x1f;
2313 int retval;
2314 unsigned long flags;
2316 spin_lock_irqsave(&vp->lock, flags);
2318 switch(cmd) {
2319 case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */
2320 data[0] = phy;
2321 case SIOCDEVPRIVATE+1: /* Read the specified MII register. */
2322 EL3WINDOW(4);
2323 data[3] = mdio_read(ioaddr, data[0] & 0x1f, data[1] & 0x1f);
2324 retval = 0;
2325 break;
2326 case SIOCDEVPRIVATE+2: /* Write the specified MII register */
2327 if (!capable(CAP_NET_ADMIN)) {
2328 retval = -EPERM;
2329 } else {
2330 EL3WINDOW(4);
2331 mdio_write(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2]);
2332 retval = 0;
2334 break;
2335 default:
2336 retval = -EOPNOTSUPP;
2337 break;
2340 spin_unlock_irqrestore(&vp->lock, flags);
2341 return retval;
2344 /* Pre-Cyclone chips have no documented multicast filter, so the only
2345 multicast setting is to receive all multicast frames. At least
2346 the chip has a very clean way to set the mode, unlike many others. */
2347 static void set_rx_mode(struct net_device *dev)
2349 long ioaddr = dev->base_addr;
2350 int new_mode;
2352 if (dev->flags & IFF_PROMISC) {
2353 if (vortex_debug > 0)
2354 printk(KERN_NOTICE "%s: Setting promiscuous mode.\n", dev->name);
2355 new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast|RxProm;
2356 } else if ((dev->mc_list) || (dev->flags & IFF_ALLMULTI)) {
2357 new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast;
2358 } else
2359 new_mode = SetRxFilter | RxStation | RxBroadcast;
2361 outw(new_mode, ioaddr + EL3_CMD);
2364 /* MII transceiver control section.
2365 Read and write the MII registers using software-generated serial
2366 MDIO protocol. See the MII specifications or DP83840A data sheet
2367 for details. */
2369 /* The maximum data clock rate is 2.5 Mhz. The minimum timing is usually
2370 met by back-to-back PCI I/O cycles, but we insert a delay to avoid
2371 "overclocking" issues. */
2372 #define mdio_delay() inl(mdio_addr)
2374 #define MDIO_SHIFT_CLK 0x01
2375 #define MDIO_DIR_WRITE 0x04
2376 #define MDIO_DATA_WRITE0 (0x00 | MDIO_DIR_WRITE)
2377 #define MDIO_DATA_WRITE1 (0x02 | MDIO_DIR_WRITE)
2378 #define MDIO_DATA_READ 0x02
2379 #define MDIO_ENB_IN 0x00
2381 /* Generate the preamble required for initial synchronization and
2382 a few older transceivers. */
2383 static void mdio_sync(long ioaddr, int bits)
2385 long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
2387 /* Establish sync by sending at least 32 logic ones. */
2388 while (-- bits >= 0) {
2389 outw(MDIO_DATA_WRITE1, mdio_addr);
2390 mdio_delay();
2391 outw(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
2392 mdio_delay();
2396 static int mdio_read(long ioaddr, int phy_id, int location)
2398 int i;
2399 int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
2400 unsigned int retval = 0;
2401 long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
2403 if (mii_preamble_required)
2404 mdio_sync(ioaddr, 32);
2406 /* Shift the read command bits out. */
2407 for (i = 14; i >= 0; i--) {
2408 int dataval = (read_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
2409 outw(dataval, mdio_addr);
2410 mdio_delay();
2411 outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
2412 mdio_delay();
2414 /* Read the two transition, 16 data, and wire-idle bits. */
2415 for (i = 19; i > 0; i--) {
2416 outw(MDIO_ENB_IN, mdio_addr);
2417 mdio_delay();
2418 retval = (retval << 1) | ((inw(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
2419 outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
2420 mdio_delay();
2422 return retval & 0x20000 ? 0xffff : retval>>1 & 0xffff;
2425 static void mdio_write(long ioaddr, int phy_id, int location, int value)
2427 int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value;
2428 long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
2429 int i;
2431 if (mii_preamble_required)
2432 mdio_sync(ioaddr, 32);
2434 /* Shift the command bits out. */
2435 for (i = 31; i >= 0; i--) {
2436 int dataval = (write_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
2437 outw(dataval, mdio_addr);
2438 mdio_delay();
2439 outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
2440 mdio_delay();
2442 /* Leave the interface idle. */
2443 for (i = 1; i >= 0; i--) {
2444 outw(MDIO_ENB_IN, mdio_addr);
2445 mdio_delay();
2446 outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
2447 mdio_delay();
2450 return;
2453 /* ACPI: Advanced Configuration and Power Interface. */
2454 /* Set Wake-On-LAN mode and put the board into D3 (power-down) state. */
2455 static void acpi_set_WOL(struct net_device *dev)
2457 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2458 long ioaddr = dev->base_addr;
2460 /* AKPM: This kills the 905 */
2461 if (vortex_debug > 0) {
2462 printk(KERN_INFO PFX "Wake-on-LAN functions disabled\n");
2464 return;
2466 /* Power up on: 1==Downloaded Filter, 2==Magic Packets, 4==Link Status. */
2467 EL3WINDOW(7);
2468 outw(2, ioaddr + 0x0c);
2469 /* The RxFilter must accept the WOL frames. */
2470 outw(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
2471 outw(RxEnable, ioaddr + EL3_CMD);
2472 /* Change the power state to D3; RxEnable doesn't take effect. */
2473 pci_write_config_word(vp->pdev, 0xe0, 0x8103);
2477 static void __devexit vortex_remove_one (struct pci_dev *pdev)
2479 struct net_device *dev = pdev->driver_data;
2480 struct vortex_private *vp;
2482 if (!dev) {
2483 printk("vortex_remove_one called for EISA device!\n");
2484 BUG();
2487 vp = (void *)(dev->priv);
2489 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
2490 /* AKPM: FIXME: we should have
2491 * if (vp->cb_fn_base) iounmap(vp->cb_fn_base);
2492 * here
2494 unregister_netdev(dev);
2495 outw(TotalReset, dev->base_addr + EL3_CMD);
2496 release_region(dev->base_addr, vp->io_size);
2497 kfree(dev);
2501 static struct pci_driver vortex_driver = {
2502 name: "3c575_cb",
2503 probe: vortex_init_one,
2504 remove: vortex_remove_one,
2505 suspend: vortex_suspend,
2506 resume: vortex_resume,
2507 id_table: vortex_pci_tbl,
2511 static int vortex_have_pci = 0;
2512 static int vortex_have_eisa = 0;
2515 static int __init vortex_init (void)
2517 int rc;
2519 rc = pci_module_init (&vortex_driver);
2520 if (rc < 0)
2521 goto out;
2523 if (rc >= 0) /* AKPM: had "> 0" */
2524 vortex_have_pci = 1;
2526 rc = vortex_eisa_init ();
2527 if (rc < 0)
2528 goto out;
2530 if (rc > 0)
2531 vortex_have_eisa = 1;
2533 out:
2534 return rc;
2538 static void __exit vortex_eisa_cleanup (void)
2540 struct net_device *dev, *tmp;
2541 struct vortex_private *vp;
2542 long ioaddr;
2544 dev = root_vortex_eisa_dev;
2546 while (dev) {
2547 vp = dev->priv;
2548 ioaddr = dev->base_addr;
2550 unregister_netdev (dev);
2551 outw (TotalReset, ioaddr + EL3_CMD);
2552 release_region (ioaddr, VORTEX_TOTAL_SIZE);
2554 tmp = dev;
2555 dev = vp->next_module;
2557 kfree (tmp);
2562 static void __exit vortex_cleanup (void)
2564 if (vortex_have_pci)
2565 pci_unregister_driver (&vortex_driver);
2566 if (vortex_have_eisa)
2567 vortex_eisa_cleanup ();
2571 module_init(vortex_init);
2572 module_exit(vortex_cleanup);
2577 * Local variables:
2578 * compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c59x.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`"
2579 * cardbus-compile-command: "gcc -DCONFIG_HOTPLUG -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c59x.c -o 3c575_cb.o -I/usr/src/linux/pcmcia-cs-3.0.9/include/"
2580 * c-indent-level: 4
2581 * c-basic-offset: 4
2582 * tab-width: 4
2583 * End: