Subversion Repositories shark

Rev

Rev 3 | Rev 388 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/* EtherLinkXL.c: A 3Com EtherLink PCI III/XL ethernet driver for linux. */
2
/*
3
        Written 1996-1998 by Donald Becker.
4
 
5
        This software may be used and distributed according to the terms
6
        of the GNU 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
        The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
13
        Center of Excellence in Space Data and Information Sciences
14
           Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
15
*/
16
 
218 giacomo 17
/*
18
    15Apr00, Andrew Morton <andrewm@uow.edu.au>
19
    - Don't set RxComplete in boomerang interrupt enable reg
20
    - Added standard spinlocking.
21
    - Removed setting/clearing of dev->interrupt
22
    - Removed vp->in_interrupt
23
    - spinlock in vortex_timer to protect mdio functions
24
    - disable local interrupts around call to vortex_interrupt in
25
      vortex_tx_timeout() (So vortex_interrupt can use spin_lock())
26
    - Removed global save/restore_flags() and cli() from get_stats
27
      and vortex_start_xmit()
28
    - Select window 3 in vortex_timer()'s write to Wn3_MAC_Ctrl
29
    - In vortex_start_xmit(), move the lock to _after_ we've altered
30
      vp->cur_tx and vp->tx_full.  This defeats the race between
31
      vortex_start_xmit() and vortex_interrupt which was identified
32
      by Bogdan Costescu.
33
    - Merged back support for six new cards from various sources
34
    - Tell it that 3c905C has NWAY
35
    - Fix handling of SetStatusEnd in 'Too much work..' code, as
36
      per 2.3.99's 3c575_cb (Dave Hinds).  Added vp->deferred for this.
2 pj 37
 
218 giacomo 38
    24May00 <2.2.16-pre4> andrewm
39
    - Replace union wn3_config with BFINS/BFEXT manipulation for
40
      sparc64 (Pete Zaitcev, Peter Jones)
41
    - Use insl_ns/outsl_ns for __powerpc__ (Andreas Tobler)
42
    - In vortex_error, do_tx_reset and vortex_tx_timeout(Vortex): clear
43
      tbusy and force a BH rerun to better recover from errors.
44
 
45
    24Jun00 <2.2.16> andrewm
46
    - Better handling of shared interrupts
47
    - Reset the transmitter in vortex_error() on both maxcollisions and Tx reclaim error
48
    - Split the ISR into vortex_interrupt and boomerang_interrupt.  This is
49
      to fix once-and-for-all the dubious testing of vortex status bits on
50
      boomerang/hurricane/cyclone/tornado NICs.
51
    - Fixed crash under OOM during vortex_open() (Mark Hemment)
52
    - Fix Rx cessation problem during OOM (help from Mark Hemment)
53
 
54
    01Aug00 <2.2.17-pre14> andrewm
55
    - Added 3c556 support (Fred Maciel)
56
 
57
    16Aug00 <2.2.17-pre17> andrem
58
    - In vortex_error: don't reset the Tx after txReclaim or maxCollisions errors
59
    - In vortex_error(do_tx_reset): only reset dev->tbusy for vortex-style NICs.
60
    - In vortex_open(), set vp->tx_full to zero (else we get errors if the device was
61
      closed with a full Tx ring).
62
 
63
        17Oct00 <2.2.18-pre16> andrewm
64
        - Added support for the 3c556B Laptop Hurricane (Louis Gerbarg)
65
    - Backported transceiver options handling from 2.4.  This changes the semantics
66
      of forcing full duplex in the `options' parm!  (It's better to use
67
      `full_duplex' anyway).  See Documentation/vortex.txt (Maciej Rozycki).
68
    - Set PCI latency timer to maximum for the 3c590 (From Donald's driver)
69
    - Removed all the CARDBUS code (it's never used).
70
    - Added INVERT_MII_PWR, EEPROM_8BIT, EEPROM_OFFSET.  Use them.
71
    - Use EEPROM_8BIT for the 3c555
72
    - Merged ACPI WOL support from Donald's drivers.
73
    - Sort-of backported Donald's new medialock code. Called it duplexlock
74
      and we now prefer to use `full_duplex=[-1,0,1]' to force duplex mode.
75
    - Merged the rx_oom_timer from 2.4.  This gives better handling of OOM
76
      conditions.  Backed out the previous way of handling this.
77
    - Replace suser() with capable(CAP_NET_ADMIN) in ioctl().
78
 
79
    07Jan01 <2.2.19-pre6> andrewm
80
    - Add HAS_NWAY to "3c900 Cyclone 10Mbps TPO"
81
    - Added and used wait_for_completion().  3c905CX problems.
82
    - Removed the code for older kernel versions.
83
    - Add HAS_NWAY to 3cSOHO100-TX (Brett Frankenberger)
84
    - Search for phy 24 first for 3c905CX. (D Becker)
85
    - Don't free skbs we don't own on oom path in vortex_open().
86
    - Added explicit `medialock' flag so we can truly
87
      lock the media type down with `options'.
88
    - In vortex_error(), only reset the up/down load engine, not all the
89
      interface stuff.
90
    - Added and used EEPROM_NORESET for 3c556B PM resumes.
91
    - Enable WOL with the `enable_wol' module parm
92
    - Give the 3c980 HAS_NWAY
93
 
94
    - See http://www.uow.edu.au/~andrewm/linux/#3c59x-2.2 for more details.
95
*/
96
 
97
static char version[] =
98
"3c59x.c 18Feb01 Donald Becker and others http://www.scyld.com/network/vortex.html\n";
99
 
2 pj 100
/* "Knobs" that adjust features and parameters. */
101
/* Set the copy breakpoint for the copy-only-tiny-frames scheme.
102
   Setting to > 1512 effectively disables this feature. */
103
static const int rx_copybreak = 200;
104
/* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
105
static const int mtu = 1500;
106
/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
107
static int max_interrupt_work = 20;
108
 
109
/* Put out somewhat more debugging messages. (0: no msg, 1 minimal .. 6). */
110
#define vortex_debug debug
111
#ifdef VORTEX_DEBUG
112
static int vortex_debug = VORTEX_DEBUG;
113
#else
218 giacomo 114
static int vortex_debug = 0;
2 pj 115
#endif
116
 
117
/* Some values here only for performance evaluation and path-coverage
118
   debugging. */
119
static int rx_nocopy = 0, rx_copy = 0, queued_packet = 0, rx_csumhits;
120
 
121
/* A few values that may be tweaked. */
122
/* Time in jiffies before concluding the transmitter is hung. */
123
#define TX_TIMEOUT  ((400*HZ)/1000)
124
 
125
/* Keep the ring sizes a power of two for efficiency. */
126
#define TX_RING_SIZE    16
127
#define RX_RING_SIZE    32
128
#define PKT_BUF_SZ              1536                    /* Size of each temporary Rx buffer.*/
129
 
130
#include <linux/config.h>
131
#include <linux/version.h>
132
#include <linux/kernel.h>
133
#include <linux/sched.h>
134
#include <linux/string.h>
135
#include <linux/timer.h>
136
#include <linux/errno.h>
137
#include <linux/in.h>
138
#include <linux/ioport.h>
139
#include <linux/malloc.h>
140
#include <linux/interrupt.h>
141
#include <linux/pci.h>
142
#include <linux/netdevice.h>
143
#include <linux/etherdevice.h>
144
#include <linux/skbuff.h>
218 giacomo 145
#include <linux/delay.h>
146
#include <linux/module.h>
2 pj 147
#include <asm/irq.h>                    /* For NR_IRQS only. */
148
#include <asm/bitops.h>
149
#include <asm/io.h>
150
 
151
/* Kernel compatibility defines, some common to David Hinds' PCMCIA package.
152
   This is only in the support-all-kernels source code. */
153
 
154
#define RUN_AT(x) (jiffies + (x))
155
 
156
 
218 giacomo 157
MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
2 pj 158
MODULE_DESCRIPTION("3Com 3c590/3c900 series Vortex/Boomerang driver");
159
MODULE_PARM(debug, "i");
160
MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");
161
MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");
218 giacomo 162
MODULE_PARM(enable_wol, "1-" __MODULE_STRING(8) "i");
2 pj 163
MODULE_PARM(rx_copybreak, "i");
164
MODULE_PARM(max_interrupt_work, "i");
165
MODULE_PARM(compaq_ioaddr, "i");
166
MODULE_PARM(compaq_irq, "i");
167
MODULE_PARM(compaq_device_id, "i");
168
 
169
/* Operational parameter that usually are not changed. */
170
 
171
/* The Vortex size is twice that of the original EtherLinkIII series: the
172
   runtime register window, window 1, is now always mapped in.
173
   The Boomerang size is twice as large as the Vortex -- it has additional
174
   bus master control registers. */
175
#define VORTEX_TOTAL_SIZE 0x20
176
#define BOOMERANG_TOTAL_SIZE 0x40
177
 
178
/* Set iff a MII transceiver on any interface requires mdio preamble.
179
   This only set with the original DP83840 on older 3c905 boards, so the extra
180
   code size of a per-interface flag is not worthwhile. */
181
static char mii_preamble_required = 0;
182
 
183
/*
184
                                Theory of Operation
185
 
186
I. Board Compatibility
187
 
188
This device driver is designed for the 3Com FastEtherLink and FastEtherLink
189
XL, 3Com's PCI to 10/100baseT adapters.  It also works with the 10Mbs
190
versions of the FastEtherLink cards.  The supported product IDs are
191
  3c590, 3c592, 3c595, 3c597, 3c900, 3c905
192
 
193
The related ISA 3c515 is supported with a separate driver, 3c515.c, included
194
with the kernel source or available from
195
    cesdis.gsfc.nasa.gov:/pub/linux/drivers/3c515.html
196
 
197
II. Board-specific settings
198
 
199
PCI bus devices are configured by the system at boot time, so no jumpers
200
need to be set on the board.  The system BIOS should be set to assign the
201
PCI INTA signal to an otherwise unused system IRQ line.
202
 
203
The EEPROM settings for media type and forced-full-duplex are observed.
204
The EEPROM media type should be left at the default "autoselect" unless using
205
10base2 or AUI connections which cannot be reliably detected.
206
 
207
III. Driver operation
208
 
209
The 3c59x series use an interface that's very similar to the previous 3c5x9
210
series.  The primary interface is two programmed-I/O FIFOs, with an
211
alternate single-contiguous-region bus-master transfer (see next).
212
 
213
The 3c900 "Boomerang" series uses a full-bus-master interface with separate
214
lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,
215
DEC Tulip and Intel Speedo3.  The first chip version retains a compatible
216
programmed-I/O interface that has been removed in 'B' and subsequent board
217
revisions.
218
 
219
One extension that is advertised in a very large font is that the adapters
220
are capable of being bus masters.  On the Vortex chip this capability was
221
only for a single contiguous region making it far less useful than the full
222
bus master capability.  There is a significant performance impact of taking
223
an extra interrupt or polling for the completion of each transfer, as well
224
as difficulty sharing the single transfer engine between the transmit and
225
receive threads.  Using DMA transfers is a win only with large blocks or
226
with the flawed versions of the Intel Orion motherboard PCI controller.
227
 
228
The Boomerang chip's full-bus-master interface is useful, and has the
229
currently-unused advantages over other similar chips that queued transmit
230
packets may be reordered and receive buffer groups are associated with a
231
single frame.
232
 
233
With full-bus-master support, this driver uses a "RX_COPYBREAK" scheme.
234
Rather than a fixed intermediate receive buffer, this scheme allocates
235
full-sized skbuffs as receive buffers.  The value RX_COPYBREAK is used as
236
the copying breakpoint: it is chosen to trade-off the memory wasted by
237
passing the full-sized skbuff to the queue layer for all frames vs. the
238
copying cost of copying a frame to a correctly-sized skbuff.
239
 
240
 
241
IIIC. Synchronization
242
The driver runs as two independent, single-threaded flows of control.  One
243
is the send-packet routine, which enforces single-threaded use by the
244
dev->tbusy flag.  The other thread is the interrupt handler, which is single
245
threaded by the hardware and other software.
246
 
247
IV. Notes
248
 
249
Thanks to Cameron Spitzer and Terry Murphy of 3Com for providing development
250
3c590, 3c595, and 3c900 boards.
251
The name "Vortex" is the internal 3Com project name for the PCI ASIC, and
252
the EISA version is called "Demon".  According to Terry these names come
253
from rides at the local amusement park.
254
 
255
The new chips support both ethernet (1.5K) and FDDI (4.5K) packet sizes!
256
This driver only supports ethernet packets because of the skbuff allocation
257
limit of 4K.
258
*/
259
 
260
/* This table drives the PCI probe routines.  It's mostly boilerplate in all
261
   of the drivers, and will likely be provided by some future kernel.
262
*/
263
enum pci_flags_bit {
264
        PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
265
        PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,
266
};
267
struct pci_id_info {
268
        const char *name;
269
        u16     vendor_id, device_id, device_id_mask, flags;
270
        int drv_flags, io_size;
271
        struct device *(*probe1)(int pci_bus, int pci_devfn, struct device *dev,
272
                                                         long ioaddr, int irq, int chip_idx, int fnd_cnt);
273
};
274
 
218 giacomo 275
enum { IS_VORTEX=1, IS_BOOMERANG=2, IS_CYCLONE=4, IS_TORNADO=8,
276
           HAS_PWR_CTRL=0x10, HAS_MII=0x20, HAS_NWAY=0x40, HAS_CB_FNS=0x80,
277
           INVERT_MII_PWR=0x100, EEPROM_8BIT=0x200, EEPROM_OFFSET=0x400,
278
           EEPROM_NORESET=0x800};
2 pj 279
static struct device *vortex_probe1(int pci_bus, int pci_devfn,
280
                                                                        struct device *dev, long ioaddr,
281
                                                                        int irq, int dev_id, int card_idx);
282
static struct pci_id_info pci_tbl[] = {
283
        {"3c590 Vortex 10Mbps",                 0x10B7, 0x5900, 0xffff,
284
         PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},
218 giacomo 285
        {"3c592 EISA 10mbps Demon/Vortex", 0x10B7, 0x5920, 0xffff,              /* AKPM: from Don's 3c59x_cb.c 0.49H */
286
         PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},
287
        {"3c597 EISA Fast Demon/Vortex", 0x10B7, 0x5970, 0xffff,                /* AKPM: from Don's 3c59x_cb.c 0.49H */
288
         PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},
2 pj 289
        {"3c595 Vortex 100baseTx",              0x10B7, 0x5950, 0xffff,
290
         PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},
291
        {"3c595 Vortex 100baseT4",              0x10B7, 0x5951, 0xffff,
292
         PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},
293
        {"3c595 Vortex 100base-MII",    0x10B7, 0x5952, 0xffff,
294
         PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},
218 giacomo 295
 
296
#define EISA_TBL_OFFSET 6                       /* AKPM: the offset of this entry */
2 pj 297
        {"3Com Vortex",                                 0x10B7, 0x5900, 0xff00,
298
         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, vortex_probe1},
299
        {"3c900 Boomerang 10baseT",             0x10B7, 0x9000, 0xffff,
300
         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, vortex_probe1},
301
        {"3c900 Boomerang 10Mbps Combo", 0x10B7, 0x9001, 0xffff,
302
         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, vortex_probe1},
303
        {"3c900 Cyclone 10Mbps Combo", 0x10B7, 0x9005, 0xffff,
304
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},
305
        {"3c900B-FL Cyclone 10base-FL", 0x10B7, 0x900A, 0xffff,
306
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},
218 giacomo 307
        {"3c900 Cyclone 10Mbps TPO",    0x10B7, 0x9004, 0xffff,                 /* AKPM: from Don's 0.99M */
308
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY, 128, vortex_probe1},
309
        {"3c900 Cyclone 10Mbps TPC",    0x10B7, 0x9006, 0xffff,                 /* AKPM: from Don's 0.99M */
310
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},
2 pj 311
        {"3c905 Boomerang 100baseTx",   0x10B7, 0x9050, 0xffff,
312
         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, vortex_probe1},
313
        {"3c905 Boomerang 100baseT4",   0x10B7, 0x9051, 0xffff,
314
         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, vortex_probe1},
315
        {"3c905B Cyclone 100baseTx",    0x10B7, 0x9055, 0xffff,
316
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY, 128, vortex_probe1},
317
        {"3c905B Cyclone 10/100/BNC",   0x10B7, 0x9058, 0xffff,
318
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY, 128, vortex_probe1},
319
        {"3c905B-FX Cyclone 100baseFx", 0x10B7, 0x905A, 0xffff,
320
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},
321
        {"3c905C Tornado",      0x10B7, 0x9200, 0xffff,
218 giacomo 322
         PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY, 128, vortex_probe1},
2 pj 323
        {"3c980 Cyclone",       0x10B7, 0x9800, 0xfff0,
218 giacomo 324
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY, 128, vortex_probe1},
2 pj 325
        {"3cSOHO100-TX Hurricane",      0x10B7, 0x7646, 0xffff,
218 giacomo 326
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY, 128, vortex_probe1},
2 pj 327
        {"3c555 Laptop Hurricane",      0x10B7, 0x5055, 0xffff,
218 giacomo 328
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|EEPROM_8BIT, 128, vortex_probe1},
329
        {"3c556 10/100 Mini PCI Adapter",       0x10B7, 0x6055, 0xffff,
330
         PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|EEPROM_8BIT|HAS_CB_FNS|INVERT_MII_PWR, 128, vortex_probe1},
331
        {"3c556B Laptop Hurricane",     0x10B7, 0x6056, 0xffff,
332
         PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|EEPROM_OFFSET|HAS_CB_FNS|INVERT_MII_PWR|EEPROM_NORESET, 128, vortex_probe1},
2 pj 333
        {"3c575 Boomerang CardBus",             0x10B7, 0x5057, 0xffff,
334
         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, vortex_probe1},
335
        {"3CCFE575 Cyclone CardBus",    0x10B7, 0x5157, 0xffff,
336
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS,
337
         128, vortex_probe1},
338
        {"3CCFE656 Cyclone CardBus",    0x10B7, 0x6560, 0xffff,
339
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS,
340
         128, vortex_probe1},
218 giacomo 341
        {"3CCFEM656 Cyclone CardBus",   0x10B7, 0x6562, 0xffff,                 /* AKPM: From the 2.3 driver ? */
342
         PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS,
343
         128, vortex_probe1},
2 pj 344
        {"3c575 series CardBus (unknown version)", 0x10B7, 0x5057, 0xf0ff,
345
         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, vortex_probe1},
218 giacomo 346
        {"3c450 HomePNA Tornado", 0x10B7, 0x4500, 0xffff,                               /* AKPM: from Don's 0.99P */
347
         PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY, 128, vortex_probe1},
2 pj 348
        {"3Com Boomerang (unknown version)",    0x10B7, 0x9000, 0xff00,
349
         PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, vortex_probe1},
350
        {0,},                                           /* 0 terminated list. */
351
};
352
 
353
/* Operational definitions.
354
   These are not used by other compilation units and thus are not
355
   exported in a ".h" file.
356
 
357
   First the windows.  There are eight register windows, with the command
358
   and status registers available in each.
359
   */
360
#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
361
#define EL3_CMD 0x0e
362
#define EL3_STATUS 0x0e
363
 
364
/* The top five bits written to EL3_CMD are a command, the lower
365
   11 bits are the parameter, if applicable.
366
   Note that 11 parameters bits was fine for ethernet, but the new chip
367
   can handle FDDI length frames (~4500 octets) and now parameters count
368
   32-bit 'Dwords' rather than octets. */
369
 
370
enum vortex_cmd {
371
        TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
372
        RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11,
373
        UpStall = 6<<11, UpUnstall = (6<<11)+1,
374
        DownStall = (6<<11)+2, DownUnstall = (6<<11)+3,
375
        RxDiscard = 8<<11, TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
376
        FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
377
        SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
378
        SetTxThreshold = 18<<11, SetTxStart = 19<<11,
379
        StartDMAUp = 20<<11, StartDMADown = (20<<11)+1, StatsEnable = 21<<11,
380
        StatsDisable = 22<<11, StopCoax = 23<<11, SetFilterBit = 25<<11,};
381
 
382
/* The SetRxFilter command accepts the following classes: */
383
enum RxFilter {
384
        RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
385
 
386
/* Bits in the general status register. */
387
enum vortex_status {
388
        IntLatch = 0x0001, HostError = 0x0002, TxComplete = 0x0004,
389
        TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
390
        IntReq = 0x0040, StatsFull = 0x0080,
391
        DMADone = 1<<8, DownComplete = 1<<9, UpComplete = 1<<10,
392
        DMAInProgress = 1<<11,                  /* DMA controller is still busy.*/
393
        CmdInProgress = 1<<12,                  /* EL3_CMD is still busy.*/
394
};
395
 
396
/* Register window 1 offsets, the window used in normal operation.
397
   On the Vortex this window is always mapped at offsets 0x10-0x1f. */
398
enum Window1 {
399
        TX_FIFO = 0x10,  RX_FIFO = 0x10,  RxErrors = 0x14,
400
        RxStatus = 0x18,  Timer=0x1A, TxStatus = 0x1B,
401
        TxFree = 0x1C, /* Remaining free bytes in Tx buffer. */
402
};
403
enum Window0 {
404
        Wn0EepromCmd = 10,              /* Window 0: EEPROM command register. */
405
        Wn0EepromData = 12,             /* Window 0: EEPROM results register. */
406
        IntrStatus=0x0E,                /* Valid in all windows. */
407
};
408
enum Win0_EEPROM_bits {
409
        EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0,
410
        EEPROM_EWENB = 0x30,            /* Enable erasing/writing for 10 msec. */
411
        EEPROM_EWDIS = 0x00,            /* Disable EWENB before 10 msec timeout. */
412
};
413
/* EEPROM locations. */
414
enum eeprom_offset {
415
        PhysAddr01=0, PhysAddr23=1, PhysAddr45=2, ModelID=3,
416
        EtherLink3ID=7, IFXcvrIO=8, IRQLine=9,
417
        NodeAddr01=10, NodeAddr23=11, NodeAddr45=12,
418
        DriverTune=13, Checksum=15};
419
 
420
enum Window2 {                  /* Window 2. */
421
        Wn2_ResetOptions=12,
422
};
423
enum Window3 {                  /* Window 3: MAC/config bits. */
424
        Wn3_Config=0, Wn3_MAC_Ctrl=6, Wn3_Options=8,
425
};
426
 
218 giacomo 427
#define BFEXT(value, offset, bitcount)  \
428
    ((((unsigned long)(value)) >> (offset)) & ((1 << (bitcount)) - 1))
429
 
430
#define BFINS(lhs, rhs, offset, bitcount)                       \
431
    (((lhs) & ~((((1 << (bitcount)) - 1)) << (offset))) |       \
432
        (((rhs) & ((1 << (bitcount)) - 1)) << (offset)))
433
 
434
#define RAM_SIZE(v)             BFEXT(v, 0, 3)
435
#define RAM_WIDTH(v)    BFEXT(v, 3, 1)
436
#define RAM_SPEED(v)    BFEXT(v, 4, 2)
437
#define ROM_SIZE(v)             BFEXT(v, 6, 2)
438
#define RAM_SPLIT(v)    BFEXT(v, 16, 2)
439
#define XCVR(v)                 BFEXT(v, 20, 4)
440
#define AUTOSELECT(v)   BFEXT(v, 24, 1)
441
 
2 pj 442
enum Window4 {          /* Window 4: Xcvr/media bits. */
443
        Wn4_FIFODiag = 4, Wn4_NetDiag = 6, Wn4_PhysicalMgmt=8, Wn4_Media = 10,
444
};
445
enum Win4_Media_bits {
446
        Media_SQE = 0x0008,             /* Enable SQE error counting for AUI. */
447
        Media_10TP = 0x00C0,    /* Enable link beat and jabber for 10baseT. */
448
        Media_Lnk = 0x0080,             /* Enable just link beat for 100TX/100FX. */
449
        Media_LnkBeat = 0x0800,
450
};
451
enum Window7 {                                  /* Window 7: Bus Master control. */
452
        Wn7_MasterAddr = 0, Wn7_MasterLen = 6, Wn7_MasterStatus = 12,
453
};
454
/* Boomerang bus master control registers. */
455
enum MasterCtrl {
456
        PktStatus = 0x20, DownListPtr = 0x24, FragAddr = 0x28, FragLen = 0x2c,
457
        TxFreeThreshold = 0x2f, UpPktStatus = 0x30, UpListPtr = 0x38,
458
};
459
 
460
/* The Rx and Tx descriptor lists.
461
   Caution Alpha hackers: these types are 32 bits!  Note also the 8 byte
462
   alignment contraint on tx_ring[] and rx_ring[]. */
463
#define LAST_FRAG  0x80000000                   /* Last Addr/Len pair in descriptor. */
464
struct boom_rx_desc {
465
        u32 next;                                       /* Last entry points to 0.   */
466
        s32 status;
467
        u32 addr;                                       /* Up to 63 addr/len pairs possible. */
468
        s32 length;                                     /* Set LAST_FRAG to indicate last pair. */
469
};
470
/* Values for the Rx status entry. */
471
enum rx_desc_status {
472
        RxDComplete=0x00008000, RxDError=0x4000,
473
        /* See boomerang_rx() for actual error bits */
474
        IPChksumErr=1<<25, TCPChksumErr=1<<26, UDPChksumErr=1<<27,
475
        IPChksumValid=1<<29, TCPChksumValid=1<<30, UDPChksumValid=1<<31,
476
};
477
 
478
struct boom_tx_desc {
479
        u32 next;                                       /* Last entry points to 0.   */
480
        s32 status;                                     /* bits 0:12 length, others see below.  */
481
        u32 addr;
482
        s32 length;
483
};
484
 
485
/* Values for the Tx status entry. */
486
enum tx_desc_status {
487
        CRCDisable=0x2000, TxDComplete=0x8000,
488
        AddIPChksum=0x02000000, AddTCPChksum=0x04000000, AddUDPChksum=0x08000000,
489
        TxIntrUploaded=0x80000000,              /* IRQ when in FIFO, but maybe not sent. */
490
};
491
 
492
/* Chip features we care about in vp->capabilities, read from the EEPROM. */
218 giacomo 493
enum ChipCaps { CapBusMaster=0x20, CapPwrMgmt=0x2000 };
2 pj 494
 
495
struct vortex_private {
496
        /* The Rx and Tx rings should be quad-word-aligned. */
497
        struct boom_rx_desc rx_ring[RX_RING_SIZE];
498
        struct boom_tx_desc tx_ring[TX_RING_SIZE];
499
        /* The addresses of transmit- and receive-in-place skbuffs. */
500
        struct sk_buff* rx_skbuff[RX_RING_SIZE];
501
        struct sk_buff* tx_skbuff[TX_RING_SIZE];
502
        struct device *next_module;
503
        void *priv_addr;
504
        unsigned int cur_rx, cur_tx;            /* The next free ring entry */
505
        unsigned int dirty_rx, dirty_tx;        /* The ring entries to be free()ed. */
506
        struct net_device_stats stats;
507
        struct sk_buff *tx_skb;         /* Packet being eaten by bus master ctrl.  */
508
 
509
        /* PCI configuration space information. */
510
        u8 pci_bus, pci_devfn;          /* PCI bus location, for power management. */
511
        char *cb_fn_base;                       /* CardBus function status addr space. */
512
        int chip_id;
513
 
514
        /* The remainder are related to chip state, mostly media selection. */
515
        struct timer_list timer;        /* Media selection timer. */
218 giacomo 516
        struct timer_list rx_oom_timer;         /* Rx skb allocation retry timer */
2 pj 517
        int options;                            /* User-settable misc. driver options. */
218 giacomo 518
        unsigned int media_override:4,          /* Passed-in media type. */
2 pj 519
                default_media:4,                                /* Read from the EEPROM/Wn3_Config. */
218 giacomo 520
                full_duplex:1,                                  /* User wants FD (or we're running at FD) */
521
                duplexlock:1,                                   /* User has forced duplex */
522
                autoselect:1,                                   /* Can use NWAY negotiation */
2 pj 523
                bus_master:1,                           /* Vortex can only do a fragment bus-m. */
524
                full_bus_master_tx:1, full_bus_master_rx:2, /* Boomerang  */
218 giacomo 525
                tx_full:1,
526
                enable_wol:1,
527
                medialock:1;
2 pj 528
        u16 status_enable;
529
        u16 intr_enable;
530
        u16 available_media;                            /* From Wn3_Options. */
531
        u16 capabilities, info1, info2;         /* Various, from EEPROM. */
532
        u16 advertising;                                        /* NWay media advertisement */
533
        unsigned char phys[2];                          /* MII device addresses. */
218 giacomo 534
        u16 deferred;                                           /* Resend these interrupts when we
535
                                                                                 * bale from the ISR */
536
        spinlock_t lock;
2 pj 537
};
538
 
539
/* The action to take with a media selection timer tick.
540
   Note that we deviate from the 3Com order by checking 10base2 before AUI.
541
 */
542
enum xcvr_types {
543
        XCVR_10baseT=0, XCVR_AUI, XCVR_10baseTOnly, XCVR_10base2, XCVR_100baseTx,
544
        XCVR_100baseFx, XCVR_MII=6, XCVR_NWAY=8, XCVR_ExtMII=9, XCVR_Default=10,
545
};
546
 
547
static struct media_table {
548
        char *name;
549
        unsigned int media_bits:16,             /* Bits to set in Wn4_Media register. */
550
                mask:8,                         /* The transceiver-present bit in Wn3_Config.*/
551
                next:8;                         /* The media type to try next. */
552
        int wait;                       /* Time before we check media status. */
553
} media_tbl[] = {
554
  {     "10baseT",   Media_10TP,0x08, XCVR_10base2, (14*HZ)/10},
555
  { "10Mbs AUI", Media_SQE, 0x20, XCVR_Default, (1*HZ)/10},
556
  { "undefined", 0,                     0x80, XCVR_10baseT, 10000},
557
  { "10base2",   0,                     0x10, XCVR_AUI,         (1*HZ)/10},
558
  { "100baseTX", Media_Lnk, 0x02, XCVR_100baseFx, (14*HZ)/10},
559
  { "100baseFX", Media_Lnk, 0x04, XCVR_MII,             (14*HZ)/10},
560
  { "MII",               0,                     0x41, XCVR_10baseT, 3*HZ },
561
  { "undefined", 0,                     0x01, XCVR_10baseT, 10000},
562
  { "Autonegotiate", 0,         0x41, XCVR_10baseT, 3*HZ},
563
  { "MII-External",      0,             0x41, XCVR_10baseT, 3*HZ },
564
  { "Default",   0,                     0xFF, XCVR_10baseT, 10000},
565
};
566
 
567
static int vortex_scan(struct device *dev, struct pci_id_info pci_tbl[]);
568
static int vortex_open(struct device *dev);
569
static void mdio_sync(long ioaddr, int bits);
570
static int mdio_read(long ioaddr, int phy_id, int location);
571
static void mdio_write(long ioaddr, int phy_id, int location, int value);
572
static void vortex_timer(unsigned long arg);
218 giacomo 573
static void rx_oom_timer(unsigned long arg);
2 pj 574
static int vortex_start_xmit(struct sk_buff *skb, struct device *dev);
575
static int boomerang_start_xmit(struct sk_buff *skb, struct device *dev);
576
static int vortex_rx(struct device *dev);
577
static int boomerang_rx(struct device *dev);
578
static void vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs);
218 giacomo 579
static void boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs);
2 pj 580
static int vortex_close(struct device *dev);
581
static void update_stats(long ioaddr, struct device *dev);
582
static struct net_device_stats *vortex_get_stats(struct device *dev);
583
static void set_rx_mode(struct device *dev);
584
static int vortex_ioctl(struct device *dev, struct ifreq *rq, int cmd);
218 giacomo 585
static void acpi_wake(int pci_bus, int pci_devfn);
586
static void acpi_set_WOL(struct device *dev);
2 pj 587
 
588
 
218 giacomo 589
#if 0
590
#warning dev_alloc_skb_debug is defined!
591
#define dev_alloc_skb dev_alloc_skb_debug
592
#endif
593
 
2 pj 594
/* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
595
/* Option count limit only -- unlimited interfaces are supported. */
596
#define MAX_UNITS 8
218 giacomo 597
static int options[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1};
2 pj 598
static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
218 giacomo 599
static int enable_wol[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
2 pj 600
/* A list of all installed Vortex devices, for removing the driver module. */
601
static struct device *root_vortex_dev = NULL;
602
 
603
#ifdef MODULE
604
/* Variables to work-around the Compaq PCI BIOS32 problem. */
605
static int compaq_ioaddr = 0, compaq_irq = 0, compaq_device_id = 0x5900;
606
 
607
int init_module(void)
608
{
609
        if (vortex_debug)
610
                printk(KERN_INFO "%s", version);
611
        return vortex_scan(0, pci_tbl);
612
}
613
 
614
#else
615
int tc59x_probe(struct device *dev)
616
{
617
        static int scanned=0;
618
        if(scanned++)
619
                return -ENODEV;
620
        printk(KERN_INFO "%s", version);
621
        return vortex_scan(dev, pci_tbl);
622
}
623
#endif  /* not MODULE */
624
 
218 giacomo 625
static void wait_for_completion(struct device *dev, int cmd)
626
{
627
        int i;
628
 
629
        outw(cmd, dev->base_addr + EL3_CMD);
630
        for (i = 0; i < 2000; i++) {
631
                if (!(inw(dev->base_addr + EL3_STATUS) & CmdInProgress))
632
                        return;
633
        }
634
 
635
        /* OK, that didn't work.  Do it the slow way.  One second */
636
        for (i = 0; i < 100000; i++) {
637
                if (!(inw(dev->base_addr + EL3_STATUS) & CmdInProgress)) {
638
                        if (vortex_debug > 1)
639
                                printk(KERN_INFO "%s: command 0x%04x took %d usecs!\n",
640
                                           dev->name, cmd, i * 10);
641
                        return;
642
                }
643
                udelay(10);
644
        }
645
        printk(KERN_ERR "%s: command 0x%04x did not complete! Status=0x%x\n",
646
                           dev->name, cmd, inw(dev->base_addr + EL3_STATUS));
647
}
648
 
2 pj 649
static int vortex_scan(struct device *dev, struct pci_id_info pci_tbl[])
650
{
651
        int cards_found = 0;
652
 
653
        /* Allow an EISA-only driver. */
654
#if defined(CONFIG_PCI) || (defined(MODULE) && !defined(NO_PCI))
655
        /* Ideally we would detect all cards in slot order.  That would
656
           be best done a central PCI probe dispatch, which wouldn't work
657
           well with the current structure.  So instead we detect 3Com cards
658
           in slot order. */
659
        if (pcibios_present()) {
660
                static int pci_index = 0;
661
                unsigned char pci_bus, pci_device_fn;
662
 
663
                for (;pci_index < 0xff; pci_index++) {
664
                        u16 vendor, device, pci_command, new_command, pwr_cmd;
665
                        int chip_idx, irq;
666
                        long ioaddr;
667
 
668
                        if (pcibios_find_class (PCI_CLASS_NETWORK_ETHERNET << 8, pci_index,
218 giacomo 669
                                                                        &pci_bus, &pci_device_fn) != PCIBIOS_SUCCESSFUL)
2 pj 670
                                break;
671
                        pcibios_read_config_word(pci_bus, pci_device_fn,
672
                                                                         PCI_VENDOR_ID, &vendor);
673
                        pcibios_read_config_word(pci_bus, pci_device_fn,
674
                                                                         PCI_DEVICE_ID, &device);
675
                        for (chip_idx = 0; pci_tbl[chip_idx].vendor_id; chip_idx++)
676
                                if (vendor == pci_tbl[chip_idx].vendor_id
677
                                        && (device & pci_tbl[chip_idx].device_id_mask) ==
678
                                        pci_tbl[chip_idx].device_id)
679
                                        break;
680
                        if (pci_tbl[chip_idx].vendor_id == 0)           /* Compiled out! */
681
                                continue;
682
 
218 giacomo 683
                        /* The Cyclone requires config space re-write if powered down. */
684
                        acpi_wake(pci_bus, pci_device_fn);
685
 
2 pj 686
                        {
687
                                struct pci_dev *pdev = pci_find_slot(pci_bus, pci_device_fn);
688
                                ioaddr = pdev->base_address[0] & ~3;
689
                                irq = pdev->irq;
690
                        }
691
 
692
                        /* Power-up the card. */
693
                        pcibios_read_config_word(pci_bus, pci_device_fn,
694
                                                                                 0xe0, &pwr_cmd);
695
                        if (pwr_cmd & 0x3) {
696
                                /* Save the ioaddr and IRQ info! */
697
                                printk(KERN_INFO "  A 3Com network adapter is powered down!"
698
                                           "  Setting the power state %4.4x->%4.4x.\n",
699
                                           pwr_cmd, pwr_cmd & ~3);
700
                                pcibios_write_config_word(pci_bus, pci_device_fn,
701
                                                                                  0xe0, pwr_cmd & ~3);
702
                                printk(KERN_INFO "  Setting the IRQ to %d, IOADDR to %#lx.\n",
703
                                           irq, ioaddr);
704
                                pcibios_write_config_byte(pci_bus, pci_device_fn,
705
                                                                                 PCI_INTERRUPT_LINE, irq);
706
                                pcibios_write_config_dword(pci_bus, pci_device_fn,
707
                                                                                  PCI_BASE_ADDRESS_0, ioaddr);
708
                        }
709
 
710
                        if (ioaddr == 0) {
711
                                printk(KERN_WARNING "  A 3Com network adapter has been found, "
712
                                           "however it has not been assigned an I/O address.\n"
713
                                           "  You may need to power-cycle the machine for this "
714
                                           "device to work!\n");
715
                                continue;
716
                        }
717
 
718
                        if (check_region(ioaddr, pci_tbl[chip_idx].io_size))
719
                                continue;
720
 
721
                        /* Activate the card. */
722
                        pcibios_read_config_word(pci_bus, pci_device_fn,
723
                                                                         PCI_COMMAND, &pci_command);
724
                        new_command = pci_command | PCI_COMMAND_MASTER|PCI_COMMAND_IO;
725
                        if (pci_command != new_command) {
726
                                printk(KERN_INFO "  The PCI BIOS has not enabled the device "
727
                                           "at %d/%d. Updating PCI command %4.4x->%4.4x.\n",
728
                                           pci_bus, pci_device_fn, pci_command, new_command);
729
                                pcibios_write_config_word(pci_bus, pci_device_fn,
730
                                                                                  PCI_COMMAND, new_command);
731
                        }
732
 
733
                        dev = vortex_probe1(pci_bus, pci_device_fn, dev, ioaddr, irq,
734
                                                                chip_idx, cards_found);
735
 
736
                        if (dev) {
218 giacomo 737
                                if ((device & 0xff00) == 0x5900) {
2 pj 738
                                /* Get and check the latency values.  On the 3c590 series
739
                                   the latency timer must be set to the maximum value to avoid
740
                                   data corruption that occurs when the timer expires during
741
                                   a transfer -- a bug in the Vortex chip only. */
742
                                u8 pci_latency;
218 giacomo 743
                                        u8 new_latency = 248;
2 pj 744
 
218 giacomo 745
                                        pcibios_read_config_byte(pci_bus, pci_device_fn, PCI_LATENCY_TIMER, &pci_latency);
2 pj 746
                                if (pci_latency < new_latency) {
747
                                        printk(KERN_INFO "%s: Overriding PCI latency"
748
                                                   " timer (CFLT) setting of %d, new value is %d.\n",
749
                                                   dev->name, pci_latency, new_latency);
218 giacomo 750
                                                pcibios_write_config_byte(pci_bus, pci_device_fn, PCI_LATENCY_TIMER, new_latency);
751
                                        }
2 pj 752
                                }
753
                                dev = 0;
754
                                cards_found++;
755
                        }
756
                }
757
        }
758
#endif /* NO_PCI */
759
 
760
        /* Now check all slots of the EISA bus. */
761
        if (EISA_bus) {
762
                static long ioaddr = 0x1000;
763
                for ( ; ioaddr < 0x9000; ioaddr += 0x1000) {
764
                        int device_id;
765
                        if (check_region(ioaddr, VORTEX_TOTAL_SIZE))
766
                                continue;
767
                        /* Check the standard EISA ID register for an encoded '3Com'. */
768
                        if (inw(ioaddr + 0xC80) != 0x6d50)
769
                                continue;
770
                        /* Check for a product that we support, 3c59{2,7} any rev. */
771
                        device_id = (inb(ioaddr + 0xC82)<<8) + inb(ioaddr + 0xC83);
772
                        if ((device_id & 0xFF00) != 0x5900)
773
                                continue;
774
                        vortex_probe1(0, 0, dev, ioaddr, inw(ioaddr + 0xC88) >> 12,
218 giacomo 775
                                                  EISA_TBL_OFFSET, cards_found);
2 pj 776
                        dev = 0;
777
                        cards_found++;
778
                }
779
        }
780
 
781
#ifdef MODULE
782
        /* Special code to work-around the Compaq PCI BIOS32 problem. */
783
        if (compaq_ioaddr) {
784
                vortex_probe1(0, 0, dev, compaq_ioaddr, compaq_irq,
785
                                          compaq_device_id, cards_found++);
786
                dev = 0;
787
        }
788
#endif
789
 
790
        return cards_found ? 0 : -ENODEV;
791
}
792
 
793
static struct device *vortex_probe1(int pci_bus, int pci_devfn,
794
                                                                        struct device *dev, long ioaddr,
795
                                                                        int irq, int chip_idx, int card_idx)
796
{
797
        struct vortex_private *vp;
798
        int option;
799
        unsigned int eeprom[0x40], checksum = 0;                /* EEPROM contents */
800
        int i;
801
 
802
        dev = init_etherdev(dev, 0);
218 giacomo 803
        if (dev == NULL) {
804
                printk(KERN_EMERG "3c59x: init_etherdev failed\n");
805
                return NULL;
806
        }
2 pj 807
 
808
        printk(KERN_INFO "%s: 3Com %s at 0x%lx, ",
809
                   dev->name, pci_tbl[chip_idx].name, ioaddr);
810
 
811
        dev->base_addr = ioaddr;
812
        dev->irq = irq;
813
        dev->mtu = mtu;
814
 
815
        /* Make certain the descriptor lists are aligned. */
816
        {
817
                void *mem = kmalloc(sizeof(*vp) + 15, GFP_KERNEL);
218 giacomo 818
                if (!mem) {
819
                        printk(KERN_EMERG "3c59x: out of memory for dev->priv\n");
820
                        unregister_netdev(dev);
821
                        kfree(dev);
822
                        return NULL;
823
                }
2 pj 824
                vp =  (void *)(((long)mem + 15) & ~15);
218 giacomo 825
                memset(vp, 0, sizeof(*vp));
2 pj 826
                vp->priv_addr = mem;
827
        }
828
        dev->priv = vp;
829
 
830
        vp->next_module = root_vortex_dev;
831
        root_vortex_dev = dev;
832
 
218 giacomo 833
        spin_lock_init(&vp->lock);
2 pj 834
        vp->chip_id = chip_idx;
835
        vp->pci_bus = pci_bus;
836
        vp->pci_devfn = pci_devfn;
837
 
838
        /* The lower four bits are the media type. */
218 giacomo 839
        option = -1;
2 pj 840
        if (dev->mem_start)
841
                option = dev->mem_start;
842
        else if (card_idx < MAX_UNITS)
843
                option = options[card_idx];
844
 
845
        if (option >= 0) {
218 giacomo 846
                vp->media_override = ((option & 7) == 2)  ?  0  :  option & 15;
847
                if (vp->media_override != 7)
848
                        vp->medialock = 1;
849
                if (option & 0x200) {
850
                        vp->full_duplex = 1;
851
                        vp->duplexlock = 1;
852
                        printk( "\n" KERN_WARNING
853
                                        "%s: forcing duplex via options is deprecated - use `full_duplex'.\n",
854
                                        dev->name);
855
                }
2 pj 856
                vp->bus_master = (option & 16) ? 1 : 0;
857
        } else {
858
                vp->media_override = 7;
859
                vp->full_duplex = 0;
860
                vp->bus_master = 0;
861
        }
218 giacomo 862
        if (card_idx < MAX_UNITS) {
863
                if (enable_wol[card_idx] > 0)
864
                        vp->enable_wol = 1;
865
                if (full_duplex[card_idx] == 0) {       /* full_duplex=0 : force half duplex */
866
                        vp->duplexlock = 1;
867
                }
868
                if (full_duplex[card_idx] > 0) {        /* full_duplex=1: force full duplex */
869
                        vp->duplexlock = 1;
2 pj 870
                vp->full_duplex = 1;
218 giacomo 871
                }
872
                /* full_duplex=-1: duplex is not forced */
873
        }
2 pj 874
        vp->options = option;
875
 
876
        /* Read the station address from the EEPROM. */
877
        EL3WINDOW(0);
218 giacomo 878
        {
879
                int base;
880
 
881
                if (pci_tbl[chip_idx].drv_flags & EEPROM_8BIT)
882
                        base = 0x230;
883
                else if (pci_tbl[chip_idx].drv_flags & EEPROM_OFFSET)
884
                        base = EEPROM_Read + 0x30;
885
                else
886
                        base = EEPROM_Read;
887
 
2 pj 888
        for (i = 0; i < 0x40; i++) {
889
                int timer;
218 giacomo 890
                        outw(base + i, ioaddr + Wn0EepromCmd);
2 pj 891
                /* Pause for at least 162 us. for the read to take place. */
892
                for (timer = 10; timer >= 0; timer--) {
893
                        udelay(162);
894
                        if ((inw(ioaddr + Wn0EepromCmd) & 0x8000) == 0)
895
                                break;
896
                }
897
                eeprom[i] = inw(ioaddr + Wn0EepromData);
898
        }
218 giacomo 899
        }
900
 
2 pj 901
        for (i = 0; i < 0x18; i++)
902
                checksum ^= eeprom[i];
903
        checksum = (checksum ^ (checksum >> 8)) & 0xff;
904
        if (checksum != 0x00) {         /* Grrr, needless incompatible change 3Com. */
905
                while (i < 0x21)
906
                        checksum ^= eeprom[i++];
907
                checksum = (checksum ^ (checksum >> 8)) & 0xff;
908
        }
218 giacomo 909
        if (checksum != 0x00 && !(pci_tbl[chip_idx].drv_flags & IS_TORNADO))
2 pj 910
                printk(" ***INVALID CHECKSUM %4.4x*** ", checksum);
911
 
912
        for (i = 0; i < 3; i++)
913
                ((u16 *)dev->dev_addr)[i] = htons(eeprom[i + 10]);
914
        for (i = 0; i < 6; i++)
915
                printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
916
#ifdef __sparc__
917
        printk(", IRQ %s\n", __irq_itoa(dev->irq));
918
#else
919
        printk(", IRQ %d\n", dev->irq);
920
        /* Tell them about an invalid IRQ. */
921
        if (vortex_debug && (dev->irq <= 0 || dev->irq >= NR_IRQS))
922
                printk(KERN_WARNING " *** Warning: IRQ %d is unlikely to work! ***\n",
923
                           dev->irq);
924
#endif
925
 
926
        if (pci_tbl[vp->chip_id].drv_flags & HAS_CB_FNS) {
927
                u32 fn_st_addr;                 /* Cardbus function status space */
218 giacomo 928
                u16 n;
2 pj 929
                pcibios_read_config_dword(pci_bus, pci_devfn, PCI_BASE_ADDRESS_2,
930
                                                                  &fn_st_addr);
931
                if (fn_st_addr)
932
                        vp->cb_fn_base = ioremap(fn_st_addr & ~3, 128);
933
                printk("%s: CardBus functions mapped %8.8x->%p (PCMCIA committee"
934
                           " brain-damage).\n", dev->name, fn_st_addr, vp->cb_fn_base);
935
                EL3WINDOW(2);
218 giacomo 936
 
937
                n = inw(ioaddr + Wn2_ResetOptions) & ~0x4010;
938
                n |= 0x10;
939
                if (pci_tbl[chip_idx].drv_flags & INVERT_MII_PWR)
940
                        n |= 0x4000;
941
                outw(n, ioaddr + Wn2_ResetOptions);
2 pj 942
        }
943
 
944
        /* Extract our information from the EEPROM data. */
945
        vp->info1 = eeprom[13];
946
        vp->info2 = eeprom[15];
947
        vp->capabilities = eeprom[16];
948
 
218 giacomo 949
        if (!vp->duplexlock && (vp->info1 & 0x8000))
2 pj 950
                vp->full_duplex = 1;
951
 
952
        {
953
                char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
218 giacomo 954
                unsigned int config;
2 pj 955
                EL3WINDOW(3);
956
                vp->available_media = inw(ioaddr + Wn3_Options);
957
                if ((vp->available_media & 0xff) == 0)          /* Broken 3c916 */
958
                        vp->available_media = 0x40;
218 giacomo 959
                config = inl(ioaddr + Wn3_Config);
2 pj 960
                if (vortex_debug > 1)
961
                        printk(KERN_DEBUG "  Internal config register is %4.4x, "
218 giacomo 962
                                   "transceivers %#x.\n", config, inw(ioaddr + Wn3_Options));
2 pj 963
                printk(KERN_INFO "  %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
218 giacomo 964
                           8 << RAM_SIZE(config),
965
                           RAM_WIDTH(config) ? "word" : "byte",
966
                           ram_split[RAM_SPLIT(config)],
967
                           AUTOSELECT(config) ? "autoselect/" : "",
968
                           XCVR(config) > XCVR_ExtMII ? "<invalid transceiver>" :
969
                           media_tbl[XCVR(config)].name);
970
                vp->default_media = XCVR(config);
971
                vp->autoselect = AUTOSELECT(config);
2 pj 972
        }
973
 
974
        if (vp->media_override != 7) {
975
                printk(KERN_INFO "  Media override to transceiver type %d (%s).\n",
976
                           vp->media_override, media_tbl[vp->media_override].name);
977
                dev->if_port = vp->media_override;
978
        } else
979
                dev->if_port = vp->default_media;
980
 
981
        if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
982
                int phy, phy_idx = 0;
983
                EL3WINDOW(4);
984
                mii_preamble_required++;
985
                mii_preamble_required++;
986
                mdio_read(ioaddr, 24, 1);
218 giacomo 987
                for (phy = 0; phy < 32 && phy_idx < 1; phy++) {
988
                        int mii_status, phyx;
989
 
990
                        /*
991
                         * For the 3c905CX we look at index 24 first, because it bogusly
992
                         * reports an external PHY at all indices
993
                         */
994
                        if (phy == 0)
995
                                phyx = 24;
996
                        else if (phy <= 24)
997
                                phyx = phy - 1;
998
                        else
999
                                phyx = phy;
2 pj 1000
                        mii_status = mdio_read(ioaddr, phyx, 1);
1001
                        if (mii_status  &&  mii_status != 0xffff) {
1002
                                vp->phys[phy_idx++] = phyx;
1003
                                printk(KERN_INFO "  MII transceiver found at address %d,"
1004
                                           " status %4x.\n", phyx, mii_status);
1005
                                if ((mii_status & 0x0040) == 0)
1006
                                        mii_preamble_required++;
1007
                        }
1008
                }
1009
                mii_preamble_required--;
1010
                if (phy_idx == 0) {
1011
                        printk(KERN_WARNING"  ***WARNING*** No MII transceivers found!\n");
1012
                        vp->phys[0] = 24;
1013
                } else {
1014
                        vp->advertising = mdio_read(ioaddr, vp->phys[0], 4);
1015
                        if (vp->full_duplex) {
1016
                                /* Only advertise the FD media types. */
1017
                                vp->advertising &= ~0x02A0;
1018
                                mdio_write(ioaddr, vp->phys[0], 4, vp->advertising);
1019
                        }
1020
                }
1021
        }
1022
 
218 giacomo 1023
        if (vp->enable_wol && (vp->capabilities & CapPwrMgmt))
1024
                acpi_set_WOL(dev);
1025
 
2 pj 1026
        if (vp->capabilities & CapBusMaster) {
1027
                vp->full_bus_master_tx = 1;
1028
                printk(KERN_INFO"  Enabling bus-master transmits and %s receives.\n",
1029
                           (vp->info2 & 1) ? "early" : "whole-frame" );
1030
                vp->full_bus_master_rx = (vp->info2 & 1) ? 1 : 2;
1031
        }
1032
 
1033
        /* We do a request_region() to register /proc/ioports info. */
1034
        request_region(ioaddr, pci_tbl[chip_idx].io_size, dev->name);
1035
 
1036
        /* The 3c59x-specific entries in the device structure. */
218 giacomo 1037
        dev->open = vortex_open;
1038
        dev->hard_start_xmit = vp->full_bus_master_tx ?
1039
                                boomerang_start_xmit : vortex_start_xmit;
1040
        dev->stop = vortex_close;
1041
        dev->get_stats = vortex_get_stats;
1042
        dev->do_ioctl = vortex_ioctl;
1043
        dev->set_multicast_list = set_rx_mode;
2 pj 1044
 
1045
        return dev;
1046
}
1047
 
1048
 
1049
static int
1050
vortex_open(struct device *dev)
1051
{
1052
        long ioaddr = dev->base_addr;
1053
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
218 giacomo 1054
        unsigned int config;
1055
        int i, retval;
2 pj 1056
 
218 giacomo 1057
        MOD_INC_USE_COUNT;
1058
 
1059
        if (vp->enable_wol)
1060
                acpi_wake(vp->pci_bus, vp->pci_devfn);
1061
 
2 pj 1062
        /* Before initializing select the active media port. */
1063
        EL3WINDOW(3);
218 giacomo 1064
        config = inl(ioaddr + Wn3_Config);
2 pj 1065
 
1066
        if (vp->media_override != 7) {
1067
                if (vortex_debug > 1)
1068
                        printk(KERN_INFO "%s: Media override to transceiver %d (%s).\n",
1069
                                   dev->name, vp->media_override,
1070
                                   media_tbl[vp->media_override].name);
1071
                dev->if_port = vp->media_override;
1072
        } else if (vp->autoselect && pci_tbl[vp->chip_id].drv_flags & HAS_NWAY) {
218 giacomo 1073
                if (vortex_debug > 1)
1074
                        printk(KERN_INFO "%s: using NWAY from config\n", dev->name);
2 pj 1075
                        dev->if_port = XCVR_NWAY;
1076
        } else if (vp->autoselect) {
1077
                /* Find first available media type, starting with 100baseTx. */
1078
                dev->if_port = XCVR_100baseTx;
1079
                while (! (vp->available_media & media_tbl[dev->if_port].mask))
1080
                        dev->if_port = media_tbl[dev->if_port].next;
1081
        } else
1082
                dev->if_port = vp->default_media;
1083
 
218 giacomo 1084
        printk(KERN_INFO "%s: Initial media type %s.\n", dev->name, media_tbl[dev->if_port].name);
2 pj 1085
 
218 giacomo 1086
        if (!vp->duplexlock && (vp->info1 & 0x8000))
1087
                vp->full_duplex = 1;
2 pj 1088
 
218 giacomo 1089
        config = BFINS(config, dev->if_port, 20, 4);
1090
        outl(config, ioaddr + Wn3_Config);
2 pj 1091
 
1092
        if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
1093
                int mii_reg1, mii_reg5;
1094
                EL3WINDOW(4);
1095
                /* Read BMSR (reg1) only to clear old status. */
1096
                mii_reg1 = mdio_read(ioaddr, vp->phys[0], 1);
1097
                mii_reg5 = mdio_read(ioaddr, vp->phys[0], 5);
1098
                if (mii_reg5 == 0xffff  ||  mii_reg5 == 0x0000)
1099
                        ;                                       /* No MII device or no link partner report */
218 giacomo 1100
                else if (!vp->duplexlock &&
1101
                                ((mii_reg5 & 0x0100) != 0                       /* 100baseTx-FD */
1102
                                || (mii_reg5 & 0x00C0) == 0x0040))              /* 10T-FD, but not 100-HD */
2 pj 1103
                        vp->full_duplex = 1;
1104
                        printk(KERN_INFO "%s: MII #%d status %4.4x, link partner capability %4.4x,"
1105
                                   " setting %s-duplex.\n", dev->name, vp->phys[0],
1106
                                   mii_reg1, mii_reg5, vp->full_duplex ? "full" : "half");
1107
                EL3WINDOW(3);
1108
        }
1109
 
1110
        /* Set the full-duplex bit. */
218 giacomo 1111
        outb((vp->full_duplex ? 0x20 : 0) | (dev->mtu > 1500 ? 0x40 : 0), ioaddr + Wn3_MAC_Ctrl);
2 pj 1112
 
1113
        if (vortex_debug > 1) {
218 giacomo 1114
                printk(KERN_DEBUG "%s: vortex_open() InternalConfig %8.8x.\n", dev->name, config);
2 pj 1115
        }
1116
 
218 giacomo 1117
        wait_for_completion(dev, TxReset);
1118
        wait_for_completion(dev, RxReset);
2 pj 1119
 
1120
        outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
1121
 
1122
        /* Use the now-standard shared IRQ implementation. */
218 giacomo 1123
        if ((retval = request_irq(dev->irq, vp->full_bus_master_tx ?
1124
                                        &boomerang_interrupt : &vortex_interrupt,
1125
                                        SA_SHIRQ, dev->name, dev))) {
1126
                printk(KERN_ERR "%s: Cannot allocate IRQ #%d\n", dev->name, dev->irq);
1127
                goto out;
2 pj 1128
        }
1129
 
1130
        if (vortex_debug > 1) {
1131
                EL3WINDOW(4);
1132
                printk(KERN_DEBUG "%s: vortex_open() irq %d media status %4.4x.\n",
1133
                           dev->name, dev->irq, inw(ioaddr + Wn4_Media));
1134
        }
1135
 
1136
        /* Set the station address and mask in window 2 each time opened. */
1137
        EL3WINDOW(2);
1138
        for (i = 0; i < 6; i++)
1139
                outb(dev->dev_addr[i], ioaddr + i);
1140
        for (; i < 12; i+=2)
1141
                outw(0, ioaddr + i);
1142
 
1143
        if (dev->if_port == XCVR_10base2)
1144
                /* Start the thinnet transceiver. We should really wait 50ms...*/
1145
                outw(StartCoax, ioaddr + EL3_CMD);
1146
        if (dev->if_port != XCVR_NWAY) {
1147
                EL3WINDOW(4);
1148
                outw((inw(ioaddr + Wn4_Media) & ~(Media_10TP|Media_SQE)) |
1149
                         media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
1150
        }
1151
 
1152
        /* Switch to the stats window, and clear all stats by reading. */
1153
        outw(StatsDisable, ioaddr + EL3_CMD);
1154
        EL3WINDOW(6);
1155
        for (i = 0; i < 10; i++)
1156
                inb(ioaddr + i);
1157
        inw(ioaddr + 10);
1158
        inw(ioaddr + 12);
1159
        /* New: On the Vortex we must also clear the BadSSD counter. */
1160
        EL3WINDOW(4);
1161
        inb(ioaddr + 12);
1162
        /* ..and on the Boomerang we enable the extra statistics bits. */
1163
        outw(0x0040, ioaddr + Wn4_NetDiag);
1164
 
1165
        /* Switch to register set 7 for normal use. */
1166
        EL3WINDOW(7);
1167
 
1168
        if (vp->full_bus_master_rx) { /* Boomerang bus master. */
1169
                vp->cur_rx = vp->dirty_rx = 0;
1170
                /* Initialize the RxEarly register as recommended. */
1171
                outw(SetRxThreshold + (1536>>2), ioaddr + EL3_CMD);
1172
                outl(0x0020, ioaddr + PktStatus);
1173
                if (vortex_debug > 2)
1174
                        printk(KERN_DEBUG "%s:  Filling in the Rx ring.\n", dev->name);
1175
                for (i = 0; i < RX_RING_SIZE; i++) {
1176
                        struct sk_buff *skb;
1177
                        vp->rx_ring[i].next = cpu_to_le32(virt_to_bus(&vp->rx_ring[i+1]));
1178
                        vp->rx_ring[i].status = 0;      /* Clear complete bit. */
1179
                        vp->rx_ring[i].length = cpu_to_le32(PKT_BUF_SZ | LAST_FRAG);
1180
                        skb = dev_alloc_skb(PKT_BUF_SZ);
1181
                        vp->rx_skbuff[i] = skb;
1182
                        if (skb == NULL)
1183
                                break;                  /* Bad news!  */
1184
                        skb->dev = dev;                 /* Mark as being used by this device. */
1185
                        skb_reserve(skb, 2);    /* Align IP on 16 byte boundaries */
1186
                        vp->rx_ring[i].addr = cpu_to_le32(virt_to_bus(skb->tail));
1187
                }
218 giacomo 1188
                if (i != RX_RING_SIZE) {
1189
                        int j;
1190
                        printk(KERN_EMERG "%s: no memory for rx ring\n", dev->name);
1191
                        for (j = 0; j < i; j++) {
1192
                                if (vp->rx_skbuff[j])
1193
                                        dev_kfree_skb(vp->rx_skbuff[j]);
1194
                        }
1195
                        retval = -ENOMEM;
1196
                        goto out_free_irq;
1197
                }
2 pj 1198
                /* Wrap the ring. */
1199
                vp->rx_ring[i-1].next = cpu_to_le32(virt_to_bus(&vp->rx_ring[0]));
1200
                outl(virt_to_bus(&vp->rx_ring[0]), ioaddr + UpListPtr);
1201
        }
1202
        if (vp->full_bus_master_tx) {           /* Boomerang bus master Tx. */
1203
                vp->cur_tx = vp->dirty_tx = 0;
1204
                outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold); /* Room for a packet. */
1205
                /* Clear the Tx ring. */
1206
                for (i = 0; i < TX_RING_SIZE; i++)
1207
                        vp->tx_skbuff[i] = 0;
1208
                outl(0, ioaddr + DownListPtr);
1209
        }
218 giacomo 1210
        /* Set receiver mode: presumably accept b-case and phys addr only. */
2 pj 1211
        set_rx_mode(dev);
1212
        outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
1213
 
1214
        dev->tbusy = 0;
1215
        dev->start = 1;
218 giacomo 1216
        vp->tx_full = 0;
2 pj 1217
 
1218
        outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
1219
        outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
1220
        /* Allow status bits to be seen. */
1221
        vp->status_enable = SetStatusEnb | HostError|IntReq|StatsFull|TxComplete|
1222
                (vp->full_bus_master_tx ? DownComplete : TxAvailable) |
1223
                (vp->full_bus_master_rx ? UpComplete : RxComplete) |
1224
                (vp->bus_master ? DMADone : 0);
218 giacomo 1225
        vp->intr_enable = SetIntrEnb | IntLatch | TxAvailable |
1226
                (vp->full_bus_master_rx ? 0 : RxComplete) |
2 pj 1227
                StatsFull | HostError | TxComplete | IntReq
1228
                | (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete;
1229
        outw(vp->status_enable, ioaddr + EL3_CMD);
1230
        /* Ack all pending events, and set active indicator mask. */
1231
        outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
1232
                 ioaddr + EL3_CMD);
1233
        outw(vp->intr_enable, ioaddr + EL3_CMD);
1234
        if (vp->cb_fn_base)                     /* The PCMCIA people are idiots.  */
1235
                writel(0x8000, vp->cb_fn_base + 4);
1236
 
218 giacomo 1237
        init_timer(&vp->timer);
1238
        vp->timer.expires = RUN_AT(media_tbl[dev->if_port].wait);
1239
        vp->timer.data = (unsigned long)dev;
1240
        vp->timer.function = &vortex_timer;             /* timer handler */
1241
        add_timer(&vp->timer);
2 pj 1242
 
218 giacomo 1243
        init_timer(&vp->rx_oom_timer);
1244
        vp->rx_oom_timer.data = (unsigned long)dev;
1245
        vp->rx_oom_timer.function = rx_oom_timer;
1246
 
2 pj 1247
        return 0;
218 giacomo 1248
 
1249
out_free_irq:
1250
        free_irq(dev->irq, dev);
1251
out:
1252
        return retval;
2 pj 1253
}
1254
 
1255
static void vortex_timer(unsigned long data)
1256
{
1257
        struct device *dev = (struct device *)data;
1258
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1259
        long ioaddr = dev->base_addr;
218 giacomo 1260
        int next_tick = 60 * HZ;
2 pj 1261
        int ok = 0;
1262
        int media_status, mii_status, old_window;
1263
 
1264
        if (vortex_debug > 1)
1265
                printk(KERN_DEBUG "%s: Media selection timer tick happened, %s.\n",
1266
                           dev->name, media_tbl[dev->if_port].name);
1267
 
218 giacomo 1268
        if (vp->medialock)
1269
                goto leave_media_alone;
2 pj 1270
        disable_irq(dev->irq);
1271
        old_window = inw(ioaddr + EL3_CMD) >> 13;
1272
        EL3WINDOW(4);
1273
        media_status = inw(ioaddr + Wn4_Media);
1274
        switch (dev->if_port) {
1275
        case XCVR_10baseT:  case XCVR_100baseTx:  case XCVR_100baseFx:
1276
                if (media_status & Media_LnkBeat) {
1277
                  ok = 1;
1278
                  if (vortex_debug > 1)
1279
                        printk(KERN_DEBUG "%s: Media %s has link beat, %x.\n",
1280
                                   dev->name, media_tbl[dev->if_port].name, media_status);
1281
                } else if (vortex_debug > 1)
1282
                  printk(KERN_DEBUG "%s: Media %s is has no link beat, %x.\n",
1283
                                   dev->name, media_tbl[dev->if_port].name, media_status);
1284
                break;
1285
          case XCVR_MII: case XCVR_NWAY:
218 giacomo 1286
                {
1287
                  unsigned long flags;
1288
                  spin_lock_irqsave(&vp->lock, flags);
2 pj 1289
                  mii_status = mdio_read(ioaddr, vp->phys[0], 1);
1290
                  ok = 1;
1291
                  if (debug > 1)
1292
                          printk(KERN_DEBUG "%s: MII transceiver has status %4.4x.\n",
1293
                                         dev->name, mii_status);
1294
                  if (mii_status & 0x0004) {
1295
                          int mii_reg5 = mdio_read(ioaddr, vp->phys[0], 5);
218 giacomo 1296
                          if (!vp->duplexlock && mii_reg5 != 0xffff) {
2 pj 1297
                                  int duplex = (mii_reg5&0x0100) ||
1298
                                          (mii_reg5 & 0x01C0) == 0x0040;
1299
                                  if (vp->full_duplex != duplex) {
1300
                                          vp->full_duplex = duplex;
1301
                                          printk(KERN_INFO "%s: Setting %s-duplex based on MII "
1302
                                                         "#%d link partner capability of %4.4x.\n",
1303
                                                         dev->name, vp->full_duplex ? "full" : "half",
1304
                                                         vp->phys[0], mii_reg5);
1305
                                          /* Set the full-duplex bit. */
218 giacomo 1306
                                          EL3WINDOW(3);
2 pj 1307
                                          outb((vp->full_duplex ? 0x20 : 0) |
1308
                                                   (dev->mtu > 1500 ? 0x40 : 0),
1309
                                                   ioaddr + Wn3_MAC_Ctrl);
1310
                                  }
1311
                                  next_tick = 60*HZ;
1312
                          }
1313
                  }
218 giacomo 1314
                  spin_unlock_irqrestore(&vp->lock, flags);
1315
                }
2 pj 1316
                  break;
1317
          default:                                      /* Other media types handled by Tx timeouts. */
1318
                if (vortex_debug > 1)
218 giacomo 1319
                  printk(KERN_DEBUG "%s: Media %s has no indication, %x.\n",
2 pj 1320
                                 dev->name, media_tbl[dev->if_port].name, media_status);
1321
                ok = 1;
1322
        }
1323
        if ( ! ok) {
218 giacomo 1324
                unsigned int config;
2 pj 1325
 
1326
                do {
1327
                        dev->if_port = media_tbl[dev->if_port].next;
1328
                } while ( ! (vp->available_media & media_tbl[dev->if_port].mask));
1329
                if (dev->if_port == XCVR_Default) { /* Go back to default. */
1330
                  dev->if_port = vp->default_media;
1331
                  if (vortex_debug > 1)
1332
                        printk(KERN_DEBUG "%s: Media selection failing, using default "
1333
                                   "%s port.\n",
1334
                                   dev->name, media_tbl[dev->if_port].name);
1335
                } else {
1336
                  if (vortex_debug > 1)
1337
                        printk(KERN_DEBUG "%s: Media selection failed, now trying "
1338
                                   "%s port.\n",
1339
                                   dev->name, media_tbl[dev->if_port].name);
1340
                  next_tick = media_tbl[dev->if_port].wait;
1341
                }
1342
                outw((media_status & ~(Media_10TP|Media_SQE)) |
1343
                         media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
1344
 
1345
                EL3WINDOW(3);
218 giacomo 1346
                config = inl(ioaddr + Wn3_Config);
1347
                config = BFINS(config, dev->if_port, 20, 4);
1348
                outl(config, ioaddr + Wn3_Config);
2 pj 1349
 
1350
                outw(dev->if_port == XCVR_10base2 ? StartCoax : StopCoax,
1351
                         ioaddr + EL3_CMD);
1352
        }
1353
        EL3WINDOW(old_window);
1354
        enable_irq(dev->irq);
1355
 
218 giacomo 1356
leave_media_alone:
2 pj 1357
        if (vortex_debug > 2)
1358
          printk(KERN_DEBUG "%s: Media selection timer finished, %s.\n",
1359
                         dev->name, media_tbl[dev->if_port].name);
1360
 
1361
                vp->timer.expires = RUN_AT(next_tick);
1362
                add_timer(&vp->timer);
218 giacomo 1363
        if (vp->deferred)
1364
                outw(FakeIntr, ioaddr + EL3_CMD);
2 pj 1365
        return;
1366
}
1367
 
1368
static void vortex_tx_timeout(struct device *dev)
1369
{
1370
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1371
        long ioaddr = dev->base_addr;
1372
 
1373
        printk(KERN_ERR "%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
1374
                   dev->name, inb(ioaddr + TxStatus),
1375
                   inw(ioaddr + EL3_STATUS));
1376
        /* Slight code bloat to be user friendly. */
1377
        if ((inb(ioaddr + TxStatus) & 0x88) == 0x88)
1378
                printk(KERN_ERR "%s: Transmitter encountered 16 collisions --"
1379
                           " network cable problem?\n", dev->name);
1380
        if (inw(ioaddr + EL3_STATUS) & IntLatch) {
1381
                printk(KERN_ERR "%s: Interrupt posted but not delivered --"
1382
                           " IRQ blocked by another device?\n", dev->name);
1383
                /* Bad idea here.. but we might as well handle a few events. */
218 giacomo 1384
                {
1385
                        /*
1386
                         * AKPM: block interrupts because vortex_interrupt
1387
                         * does a bare spin_lock()
1388
                         */
1389
                        unsigned long flags;
1390
                        __save_flags(flags);
1391
                        __cli();
1392
                        if (vp->full_bus_master_tx)
1393
                                boomerang_interrupt(dev->irq, dev, 0);
1394
                        else
2 pj 1395
                vortex_interrupt(dev->irq, dev, 0);
218 giacomo 1396
                        __restore_flags(flags);
1397
                }
2 pj 1398
        }
1399
 
1400
        if (vp->full_bus_master_tx) {
1401
                int i;
1402
                printk(KERN_DEBUG "  Flags; bus-master %d, full %d; dirty %d "
1403
                           "current %d.\n",
1404
                           vp->full_bus_master_tx, vp->tx_full, vp->dirty_tx, vp->cur_tx);
1405
                printk(KERN_DEBUG "  Transmit list %8.8x vs. %p.\n",
1406
                           inl(ioaddr + DownListPtr),
1407
                           &vp->tx_ring[vp->dirty_tx % TX_RING_SIZE]);
1408
                for (i = 0; i < TX_RING_SIZE; i++) {
1409
                        printk(KERN_DEBUG "  %d: @%p  length %8.8x status %8.8x\n", i,
1410
                                   &vp->tx_ring[i],
1411
                                   le32_to_cpu(vp->tx_ring[i].length),
1412
                                   le32_to_cpu(vp->tx_ring[i].status));
1413
                }
1414
        }
218 giacomo 1415
        wait_for_completion(dev, TxReset);
2 pj 1416
        vp->stats.tx_errors++;
1417
        if (vp->full_bus_master_tx) {
1418
                if (vortex_debug > 0)
1419
                        printk(KERN_DEBUG "%s: Resetting the Tx ring pointer.\n",
1420
                                   dev->name);
1421
                if (vp->cur_tx - vp->dirty_tx > 0  &&  inl(ioaddr + DownListPtr) == 0)
1422
                        outl(virt_to_bus(&vp->tx_ring[vp->dirty_tx % TX_RING_SIZE]),
1423
                                 ioaddr + DownListPtr);
1424
                if (vp->tx_full && (vp->cur_tx - vp->dirty_tx <= TX_RING_SIZE - 1)) {
1425
                        vp->tx_full = 0;
1426
                        clear_bit(0, (void*)&dev->tbusy);
1427
                }
1428
                outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold);
1429
                outw(DownUnstall, ioaddr + EL3_CMD);
218 giacomo 1430
        } else {
2 pj 1431
                vp->stats.tx_dropped++;
218 giacomo 1432
                clear_bit(0, (void*)&dev->tbusy);
1433
        }
2 pj 1434
 
1435
        /* Issue Tx Enable */
1436
        outw(TxEnable, ioaddr + EL3_CMD);
1437
        dev->trans_start = jiffies;
1438
 
1439
        /* Switch to register set 7 for normal use. */
1440
        EL3WINDOW(7);
1441
}
1442
 
1443
/*
1444
 * Handle uncommon interrupt sources.  This is a separate routine to minimize
1445
 * the cache impact.
1446
 */
1447
static void
1448
vortex_error(struct device *dev, int status)
1449
{
1450
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1451
        long ioaddr = dev->base_addr;
1452
        int do_tx_reset = 0;
1453
 
1454
        if (status & TxComplete) {                      /* Really "TxError" for us. */
1455
                unsigned char tx_status = inb(ioaddr + TxStatus);
1456
                /* Presumably a tx-timeout. We must merely re-enable. */
1457
                if (vortex_debug > 2
1458
                        || (tx_status != 0x88 && vortex_debug > 0))
1459
                        printk(KERN_DEBUG"%s: Transmit error, Tx status register %2.2x.\n",
1460
                                   dev->name, tx_status);
1461
                if (tx_status & 0x14)  vp->stats.tx_fifo_errors++;
1462
                if (tx_status & 0x38)  vp->stats.tx_aborted_errors++;
1463
                outb(0, ioaddr + TxStatus);
218 giacomo 1464
                if (tx_status & 0x30)   /* txJabber or txUnderrun */
2 pj 1465
                        do_tx_reset = 1;
1466
                else                                    /* Merely re-enable the transmitter. */
1467
                        outw(TxEnable, ioaddr + EL3_CMD);
1468
        }
1469
        if (status & RxEarly) {                         /* Rx early is unused. */
1470
                vortex_rx(dev);
1471
                outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
1472
        }
1473
        if (status & StatsFull) {                       /* Empty statistics. */
1474
                static int DoneDidThat = 0;
1475
                if (vortex_debug > 4)
1476
                        printk(KERN_DEBUG "%s: Updating stats.\n", dev->name);
1477
                update_stats(ioaddr, dev);
1478
                /* HACK: Disable statistics as an interrupt source. */
1479
                /* This occurs when we have the wrong media type! */
1480
                if (DoneDidThat == 0  &&
1481
                        inw(ioaddr + EL3_STATUS) & StatsFull) {
1482
                        printk(KERN_WARNING "%s: Updating statistics failed, disabling "
1483
                                   "stats as an interrupt source.\n", dev->name);
1484
                        EL3WINDOW(5);
1485
                        outw(SetIntrEnb | (inw(ioaddr + 10) & ~StatsFull), ioaddr + EL3_CMD);
1486
                        EL3WINDOW(7);
1487
                        DoneDidThat++;
1488
                }
1489
        }
1490
        if (status & IntReq) {          /* Restore all interrupt sources.  */
1491
                outw(vp->status_enable, ioaddr + EL3_CMD);
1492
                outw(vp->intr_enable, ioaddr + EL3_CMD);
1493
        }
1494
        if (status & HostError) {
1495
                u16 fifo_diag;
1496
                EL3WINDOW(4);
1497
                fifo_diag = inw(ioaddr + Wn4_FIFODiag);
1498
                if (vortex_debug > 0)
1499
                        printk(KERN_ERR "%s: Host error, FIFO diagnostic register %4.4x.\n",
1500
                                   dev->name, fifo_diag);
1501
                /* Adapter failure requires Tx/Rx reset and reinit. */
1502
                if (vp->full_bus_master_tx) {
218 giacomo 1503
                        wait_for_completion(dev, TotalReset|0xff);
2 pj 1504
                        /* Re-enable the receiver. */
1505
                        outw(RxEnable, ioaddr + EL3_CMD);
1506
                        outw(TxEnable, ioaddr + EL3_CMD);
1507
                } else if (fifo_diag & 0x0400)
1508
                        do_tx_reset = 1;
1509
                if (fifo_diag & 0x3000) {
218 giacomo 1510
                        wait_for_completion(dev, RxReset);
2 pj 1511
                        /* Set the Rx filter to the current state. */
1512
                        set_rx_mode(dev);
1513
                        outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
1514
                        outw(AckIntr | HostError, ioaddr + EL3_CMD);
1515
                }
1516
        }
1517
        if (do_tx_reset) {
218 giacomo 1518
                wait_for_completion(dev, TxReset);
2 pj 1519
                outw(TxEnable, ioaddr + EL3_CMD);
218 giacomo 1520
                if (!vp->full_bus_master_tx) {
1521
                        clear_bit(0, (void*)&dev->tbusy);
1522
                        mark_bh(NET_BH);
1523
                }
2 pj 1524
        }
1525
 
1526
}
1527
 
1528
static int
1529
vortex_start_xmit(struct sk_buff *skb, struct device *dev)
1530
{
1531
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1532
        long ioaddr = dev->base_addr;
1533
 
1534
        if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
1535
                if (jiffies - dev->trans_start >= TX_TIMEOUT)
1536
                        vortex_tx_timeout(dev);
1537
                return 1;
1538
        }
218 giacomo 1539
                if (vortex_debug > 3)
1540
                        printk(KERN_DEBUG "%s: Trying to send a boomerang packet, Tx index %d.\n",
1541
                                   dev->name, vp->cur_tx);
2 pj 1542
 
1543
        /* Put out the doubleword header... */
1544
        outl(skb->len, ioaddr + TX_FIFO);
1545
        if (vp->bus_master) {
1546
                /* Set the bus-master controller to transfer the packet. */
1547
                outl(virt_to_bus(skb->data), ioaddr + Wn7_MasterAddr);
1548
                outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
1549
                vp->tx_skb = skb;
1550
                outw(StartDMADown, ioaddr + EL3_CMD);
1551
                /* dev->tbusy will be cleared at the DMADone interrupt. */
1552
        } else {
1553
                /* ... and the packet rounded to a doubleword. */
218 giacomo 1554
#ifdef __powerpc__
1555
                outsl_ns(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
1556
#else
2 pj 1557
                outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
218 giacomo 1558
#endif
1559
                dev_kfree_skb(skb);
2 pj 1560
                if (inw(ioaddr + TxFree) > 1536) {
1561
                        clear_bit(0, (void*)&dev->tbusy);
1562
                } else
1563
                        /* Interrupt us when the FIFO has room for max-sized packet. */
1564
                        outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
1565
        }
1566
 
1567
        dev->trans_start = jiffies;
1568
 
1569
        /* Clear the Tx status stack. */
1570
        {
1571
                int tx_status;
1572
                int i = 32;
1573
 
1574
                while (--i > 0  &&      (tx_status = inb(ioaddr + TxStatus)) > 0) {
1575
                        if (tx_status & 0x3C) {         /* A Tx-disabling error occurred.  */
1576
                                if (vortex_debug > 2)
1577
                                  printk(KERN_DEBUG "%s: Tx error, status %2.2x.\n",
1578
                                                 dev->name, tx_status);
1579
                                if (tx_status & 0x04) vp->stats.tx_fifo_errors++;
1580
                                if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
218 giacomo 1581
                                if (tx_status & 0x30)
1582
                                        wait_for_completion(dev, TxReset);
2 pj 1583
                                outw(TxEnable, ioaddr + EL3_CMD);
1584
                        }
1585
                        outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */
1586
                }
1587
        }
1588
        vp->stats.tx_bytes += skb->len;
1589
        return 0;
1590
}
1591
 
1592
static int
1593
boomerang_start_xmit(struct sk_buff *skb, struct device *dev)
1594
{
1595
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1596
        long ioaddr = dev->base_addr;
1597
 
1598
        if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
1599
                if (jiffies - dev->trans_start >= TX_TIMEOUT)
1600
                        vortex_tx_timeout(dev);
1601
                return 1;
1602
        } else {
1603
                /* Calculate the next Tx descriptor entry. */
1604
                int entry = vp->cur_tx % TX_RING_SIZE;
1605
                struct boom_tx_desc *prev_entry =
1606
                        &vp->tx_ring[(vp->cur_tx-1) % TX_RING_SIZE];
1607
                unsigned long flags;
1608
 
1609
                if (vortex_debug > 3)
218 giacomo 1610
                        printk(KERN_DEBUG "%s: Trying to send a boomerang packet, Tx index %d.\n",
2 pj 1611
                                   dev->name, vp->cur_tx);
1612
                if (vp->tx_full) {
218 giacomo 1613
                        if (vortex_debug > 0)
2 pj 1614
                                printk(KERN_WARNING "%s: Tx Ring full, refusing to send buffer.\n",
1615
                                           dev->name);
1616
                        return 1;
1617
                }
1618
                vp->tx_skbuff[entry] = skb;
1619
                vp->tx_ring[entry].next = 0;
1620
                vp->tx_ring[entry].addr = cpu_to_le32(virt_to_bus(skb->data));
1621
                vp->tx_ring[entry].length = cpu_to_le32(skb->len | LAST_FRAG);
1622
                vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded);
1623
 
218 giacomo 1624
                spin_lock_irqsave(&vp->lock, flags);
1625
                wait_for_completion(dev, DownStall);
2 pj 1626
                prev_entry->next = cpu_to_le32(virt_to_bus(&vp->tx_ring[entry]));
1627
                if (inl(ioaddr + DownListPtr) == 0) {
1628
                        outl(virt_to_bus(&vp->tx_ring[entry]), ioaddr + DownListPtr);
1629
                        queued_packet++;
1630
                }
1631
 
1632
                vp->cur_tx++;
1633
                if (vp->cur_tx - vp->dirty_tx > TX_RING_SIZE - 1)
1634
                        vp->tx_full = 1;
1635
                else {                                  /* Clear previous interrupt enable. */
1636
                        prev_entry->status &= cpu_to_le32(~TxIntrUploaded);
1637
                        clear_bit(0, (void*)&dev->tbusy);
1638
                }
218 giacomo 1639
                outw(DownUnstall, ioaddr + EL3_CMD);
1640
                spin_unlock_irqrestore(&vp->lock, flags);
2 pj 1641
                dev->trans_start = jiffies;
1642
                vp->stats.tx_bytes += skb->len;
1643
                return 0;
1644
        }
1645
}
1646
 
1647
/* The interrupt handler does all of the Rx thread work and cleans up
1648
   after the Tx thread. */
218 giacomo 1649
 
1650
/*
1651
 * This is the ISR for the vortex series chips.
1652
 * full_bus_master_tx == 0 && full_bus_master_rx == 0
1653
 */
1654
 
2 pj 1655
static void vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1656
{
1657
        struct device *dev = dev_id;
1658
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1659
        long ioaddr;
218 giacomo 1660
        int status;
2 pj 1661
        int work_done = max_interrupt_work;
1662
 
218 giacomo 1663
        ioaddr = dev->base_addr;
1664
        spin_lock(&vp->lock);
1665
        status = inw(ioaddr + EL3_STATUS);
1666
        if ((status & IntLatch) == 0) {
1667
                if (vortex_debug > 5)
1668
                        printk(KERN_DEBUG "%s: no vortex interrupt pending\n", dev->name);
1669
                goto no_int;    /* Happens during shared interrupts */
2 pj 1670
        }
218 giacomo 1671
 
1672
        if (status & IntReq) {
1673
                status |= vp->deferred;
1674
                vp->deferred = 0;
2 pj 1675
        }
1676
 
218 giacomo 1677
        if (vortex_debug > 4)
1678
                printk(KERN_DEBUG "%s: vortex_interrupt, status %4.4x, latency %d ticks.\n",
1679
                           dev->name, status, inb(ioaddr + Timer));
2 pj 1680
 
1681
        do {
1682
                if (vortex_debug > 5)
1683
                                printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n",
1684
                                           dev->name, status);
218 giacomo 1685
 
2 pj 1686
                if (status & RxComplete)
1687
                        vortex_rx(dev);
1688
 
1689
                if (status & TxAvailable) {
1690
                        if (vortex_debug > 5)
1691
                                printk(KERN_DEBUG "     TX room bit was handled.\n");
1692
                        /* There's room in the FIFO for a full-sized packet. */
1693
                        outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
1694
                        clear_bit(0, (void*)&dev->tbusy);
1695
                        mark_bh(NET_BH);
1696
                }
1697
 
218 giacomo 1698
                if (status & DMADone) {
1699
                        if (inw(ioaddr + Wn7_MasterStatus) & 0x1000) {
1700
                                outw(0x1000, ioaddr + Wn7_MasterStatus); /* Ack the event. */
1701
                                dev_kfree_skb(vp->tx_skb); /* Release the transfered buffer */
1702
                                if (inw(ioaddr + TxFree) > 1536) {
1703
                                        clear_bit(0, (void*)&dev->tbusy);
1704
                                        mark_bh(NET_BH);
1705
                                } else /* Interrupt when FIFO has room for max-sized packet. */
1706
                                        outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
1707
                        }
1708
                }
1709
 
1710
                /* Check for all uncommon interrupts at once. */
1711
                if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq)) {
1712
                        if (status == 0xffff)
1713
                                break;
1714
                        vortex_error(dev, status);
1715
                }
1716
 
1717
                if (--work_done < 0) {
1718
                        printk(KERN_WARNING "%s: Too much work in interrupt, status "
1719
                                   "%4.4x.\n", dev->name, status);
1720
                        /* Disable all pending interrupts. */
1721
                        do {
1722
                                vp->deferred |= status;
1723
                                outw(SetStatusEnb | (~vp->deferred & vp->status_enable),
1724
                                         ioaddr + EL3_CMD);
1725
                                outw(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
1726
                        } while ((status = inw(ioaddr + EL3_CMD)) & IntLatch);
1727
                        /* The timer will reenable interrupts. */
1728
                        mod_timer(&vp->timer, RUN_AT(1));
1729
                        break;
1730
                }
1731
 
1732
                /* Acknowledge the IRQ. */
1733
                outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
1734
        } while ((status = inw(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete));
1735
 
1736
        if (vortex_debug > 4)
1737
                printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
1738
                           dev->name, status);
1739
 
1740
no_int:
1741
        spin_unlock(&vp->lock);
1742
}
1743
 
1744
/*
1745
 * This is the ISR for the boomerang/cyclone/hurricane/tornado series chips.
1746
 * full_bus_master_tx == 1 && full_bus_master_rx == 1
1747
 */
1748
 
1749
static void boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1750
{
1751
        struct device *dev = dev_id;
1752
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1753
        long ioaddr;
1754
        int status;
1755
        int work_done = max_interrupt_work;
1756
 
1757
        ioaddr = dev->base_addr;
1758
        spin_lock(&vp->lock);
1759
        status = inw(ioaddr + EL3_STATUS);
1760
        if ((status & IntLatch) == 0) {
1761
                if (vortex_debug > 5)
1762
                        printk(KERN_DEBUG "%s: no boomerang interrupt pending\n", dev->name);
1763
                goto no_int;    /* Happens during shared interrupts */
1764
        }
1765
 
1766
        if (status & IntReq) {
1767
                status |= vp->deferred;
1768
                vp->deferred = 0;
1769
        }
1770
 
1771
        if (vortex_debug > 4)
1772
                printk(KERN_DEBUG "%s: boomerang interrupt, status %04x, latency %d, cur_rx %d, dirty_rx %d\n",
1773
                           dev->name, status, inb(ioaddr + Timer), vp->cur_rx, vp->dirty_rx);
1774
 
1775
        do {
1776
                if (vortex_debug > 5)
1777
                                printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n",
1778
                                           dev->name, status);
1779
 
1780
                if (status & UpComplete) {
1781
                        outw(AckIntr | UpComplete, ioaddr + EL3_CMD);
1782
                        boomerang_rx(dev);
1783
                }
1784
 
2 pj 1785
                if (status & DownComplete) {
1786
                        unsigned int dirty_tx = vp->dirty_tx;
1787
 
1788
                        while (vp->cur_tx - dirty_tx > 0) {
1789
                                int entry = dirty_tx % TX_RING_SIZE;
1790
                                if (inl(ioaddr + DownListPtr) ==
1791
                                        virt_to_bus(&vp->tx_ring[entry]))
1792
                                        break;                  /* It still hasn't been processed. */
1793
                                if (vp->tx_skbuff[entry]) {
218 giacomo 1794
                                        dev_kfree_skb(vp->tx_skbuff[entry]);
2 pj 1795
                                        vp->tx_skbuff[entry] = 0;
1796
                                }
1797
                                /* vp->stats.tx_packets++;  Counted below. */
1798
                                dirty_tx++;
1799
                        }
1800
                        vp->dirty_tx = dirty_tx;
1801
                        outw(AckIntr | DownComplete, ioaddr + EL3_CMD);
1802
                        if (vp->tx_full && (vp->cur_tx - dirty_tx <= TX_RING_SIZE - 1)) {
218 giacomo 1803
                                vp->tx_full = 0;
2 pj 1804
                                        clear_bit(0, (void*)&dev->tbusy);
1805
                                        mark_bh(NET_BH);
1806
                        }
1807
                }
218 giacomo 1808
 
2 pj 1809
                /* Check for all uncommon interrupts at once. */
1810
                if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq)) {
1811
                        if (status == 0xffff)
1812
                                break;
1813
                        vortex_error(dev, status);
1814
                }
1815
 
1816
                if (--work_done < 0) {
1817
                                printk(KERN_WARNING "%s: Too much work in interrupt, status "
218 giacomo 1818
                                   "%4.4x.\n", dev->name, status);
2 pj 1819
                                /* Disable all pending interrupts. */
218 giacomo 1820
                        do {
1821
                                vp->deferred |= status;
1822
                                outw(SetStatusEnb | (~vp->deferred & vp->status_enable),
1823
                                         ioaddr + EL3_CMD);
1824
                                outw(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
1825
                        } while ((status = inw(ioaddr + EL3_CMD)) & IntLatch);
2 pj 1826
                                /* The timer will reenable interrupts. */
218 giacomo 1827
                        mod_timer(&vp->timer, RUN_AT(1));
2 pj 1828
                                break;
1829
                        }
218 giacomo 1830
 
2 pj 1831
                /* Acknowledge the IRQ. */
1832
                outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
1833
                if (vp->cb_fn_base)                     /* The PCMCIA people are idiots.  */
1834
                        writel(0x8000, vp->cb_fn_base + 4);
1835
 
218 giacomo 1836
        } while ((status = inw(ioaddr + EL3_STATUS)) & IntLatch);
2 pj 1837
 
1838
        if (vortex_debug > 4)
1839
                printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
1840
                           dev->name, status);
1841
 
218 giacomo 1842
no_int:
1843
        spin_unlock(&vp->lock);
2 pj 1844
}
1845
 
1846
static int vortex_rx(struct device *dev)
1847
{
1848
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1849
        long ioaddr = dev->base_addr;
1850
        int i;
1851
        short rx_status;
1852
 
1853
        if (vortex_debug > 5)
218 giacomo 1854
                printk(KERN_DEBUG"   In vortex_rx(), status %4.4x, rx_status %4.4x.\n",
2 pj 1855
                           inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
1856
        while ((rx_status = inw(ioaddr + RxStatus)) > 0) {
1857
                if (rx_status & 0x4000) { /* Error, update stats. */
1858
                        unsigned char rx_error = inb(ioaddr + RxErrors);
1859
                        if (vortex_debug > 2)
1860
                                printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
1861
                        vp->stats.rx_errors++;
1862
                        if (rx_error & 0x01)  vp->stats.rx_over_errors++;
1863
                        if (rx_error & 0x02)  vp->stats.rx_length_errors++;
1864
                        if (rx_error & 0x04)  vp->stats.rx_frame_errors++;
1865
                        if (rx_error & 0x08)  vp->stats.rx_crc_errors++;
1866
                        if (rx_error & 0x10)  vp->stats.rx_length_errors++;
1867
                } else {
1868
                        /* The packet length: up to 4.5K!. */
1869
                        int pkt_len = rx_status & 0x1fff;
1870
                        struct sk_buff *skb;
1871
 
1872
                        skb = dev_alloc_skb(pkt_len + 5);
1873
                        if (vortex_debug > 4)
1874
                                printk(KERN_DEBUG "Receiving packet size %d status %4.4x.\n",
1875
                                           pkt_len, rx_status);
1876
                        if (skb != NULL) {
1877
                                skb->dev = dev;
1878
                                skb_reserve(skb, 2);    /* Align IP on 16 byte boundaries */
1879
                                /* 'skb_put()' points to the start of sk_buff data area. */
1880
                                if (vp->bus_master &&
1881
                                        ! (inw(ioaddr + Wn7_MasterStatus) & 0x8000)) {
1882
                                        outl(virt_to_bus(skb_put(skb, pkt_len)),
1883
                                                 ioaddr + Wn7_MasterAddr);
1884
                                        outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
1885
                                        outw(StartDMAUp, ioaddr + EL3_CMD);
1886
                                        while (inw(ioaddr + Wn7_MasterStatus) & 0x8000)
1887
                                                ;
1888
                                } else {
218 giacomo 1889
#ifdef __powerpc__
1890
                                        insl_ns(ioaddr + RX_FIFO, skb_put(skb, pkt_len),
1891
                                                 (pkt_len + 3) >> 2);
1892
#else
2 pj 1893
                                        insl(ioaddr + RX_FIFO, skb_put(skb, pkt_len),
1894
                                                 (pkt_len + 3) >> 2);
218 giacomo 1895
#endif
2 pj 1896
                                }
1897
                                outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
1898
                                skb->protocol = eth_type_trans(skb, dev);
1899
                                netif_rx(skb);
1900
                                dev->last_rx = jiffies;
1901
                                vp->stats.rx_packets++;
1902
                                vp->stats.rx_bytes += skb->len;
1903
                                /* Wait a limited time to go to next packet. */
1904
                                for (i = 200; i >= 0; i--)
1905
                                        if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
1906
                                                break;
1907
                                continue;
1908
                        } else if (vortex_debug)
1909
                                printk(KERN_NOTICE "%s: No memory to allocate a sk_buff of "
1910
                                           "size %d.\n", dev->name, pkt_len);
1911
                }
1912
                vp->stats.rx_dropped++;
218 giacomo 1913
                wait_for_completion(dev, RxDiscard);
2 pj 1914
        }
1915
 
1916
        return 0;
1917
}
1918
 
1919
static int
1920
boomerang_rx(struct device *dev)
1921
{
1922
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
1923
        int entry = vp->cur_rx % RX_RING_SIZE;
1924
        long ioaddr = dev->base_addr;
1925
        int rx_status;
1926
        int rx_work_limit = vp->dirty_rx + RX_RING_SIZE - vp->cur_rx;
1927
 
1928
        if (vortex_debug > 5)
1929
                printk(KERN_DEBUG "  In boomerang_rx(), status %4.4x, rx_status "
1930
                           "%4.4x.\n",
1931
                           inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
1932
        while ((rx_status = le32_to_cpu(vp->rx_ring[entry].status)) & RxDComplete){
1933
                if (--rx_work_limit < 0)
1934
                        break;
1935
                if (rx_status & RxDError) { /* Error, update stats. */
1936
                        unsigned char rx_error = rx_status >> 16;
1937
                        if (vortex_debug > 2)
1938
                                printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
1939
                        vp->stats.rx_errors++;
1940
                        if (rx_error & 0x01)  vp->stats.rx_over_errors++;
1941
                        if (rx_error & 0x02)  vp->stats.rx_length_errors++;
1942
                        if (rx_error & 0x04)  vp->stats.rx_frame_errors++;
1943
                        if (rx_error & 0x08)  vp->stats.rx_crc_errors++;
1944
                        if (rx_error & 0x10)  vp->stats.rx_length_errors++;
1945
                } else {
1946
                        /* The packet length: up to 4.5K!. */
1947
                        int pkt_len = rx_status & 0x1fff;
1948
                        struct sk_buff *skb;
1949
 
1950
                        vp->stats.rx_bytes += pkt_len;
1951
                        if (vortex_debug > 4)
1952
                                printk(KERN_DEBUG "Receiving packet size %d status %4.4x.\n",
1953
                                           pkt_len, rx_status);
1954
 
1955
                        /* Check if the packet is long enough to just accept without
1956
                           copying to a properly sized skbuff. */
1957
                        if (pkt_len < rx_copybreak
1958
                                && (skb = dev_alloc_skb(pkt_len + 2)) != 0) {
1959
                                skb->dev = dev;
1960
                                skb_reserve(skb, 2);    /* Align IP on 16 byte boundaries */
1961
                                /* 'skb_put()' points to the start of sk_buff data area. */
1962
                                memcpy(skb_put(skb, pkt_len),
1963
                                           bus_to_virt(le32_to_cpu(vp->rx_ring[entry].addr)),
1964
                                           pkt_len);
1965
                                rx_copy++;
1966
                        } else {
1967
                                void *temp;
1968
                                /* Pass up the skbuff already on the Rx ring. */
1969
                                skb = vp->rx_skbuff[entry];
1970
                                vp->rx_skbuff[entry] = NULL;
1971
                                temp = skb_put(skb, pkt_len);
1972
                                /* Remove this checking code for final release. */
1973
                                if (bus_to_virt(le32_to_cpu(vp->rx_ring[entry].addr)) != temp)
1974
                                        printk(KERN_ERR "%s: Warning -- the skbuff addresses do not match"
1975
                                                   " in boomerang_rx: %p vs. %p.\n", dev->name,
1976
                                                   bus_to_virt(le32_to_cpu(vp->rx_ring[entry].addr)),
1977
                                                   temp);
1978
                                rx_nocopy++;
1979
                        }
1980
                        skb->protocol = eth_type_trans(skb, dev);
1981
                        {                                       /* Use hardware checksum info. */
1982
                                int csum_bits = rx_status & 0xee000000;
1983
                                if (csum_bits &&
1984
                                        (csum_bits == (IPChksumValid | TCPChksumValid) ||
1985
                                         csum_bits == (IPChksumValid | UDPChksumValid))) {
1986
                                        skb->ip_summed = CHECKSUM_UNNECESSARY;
1987
                                        rx_csumhits++;
1988
                                }
1989
                        }
1990
                        netif_rx(skb);
1991
                        dev->last_rx = jiffies;
1992
                        vp->stats.rx_packets++;
1993
                }
1994
                entry = (++vp->cur_rx) % RX_RING_SIZE;
1995
        }
1996
        /* Refill the Rx ring buffers. */
218 giacomo 1997
        for (; vp->cur_rx - vp->dirty_rx > 0; vp->dirty_rx++) {
2 pj 1998
                struct sk_buff *skb;
1999
                entry = vp->dirty_rx % RX_RING_SIZE;
2000
                if (vp->rx_skbuff[entry] == NULL) {
2001
                        skb = dev_alloc_skb(PKT_BUF_SZ);
218 giacomo 2002
                        if (skb == NULL) {
2003
                                static unsigned long last_jif;
2004
                                if ((jiffies - last_jif) > 10 * HZ) {
2005
                                        printk(KERN_WARNING "%s: memory shortage\n", dev->name);
2006
                                        last_jif = jiffies;
2007
                                }
2008
                                if ((vp->cur_rx - vp->dirty_rx) == RX_RING_SIZE)
2009
                                        mod_timer(&vp->rx_oom_timer, RUN_AT(HZ * 1));
2 pj 2010
                                break;                  /* Bad news!  */
218 giacomo 2011
                        }
2 pj 2012
                        skb->dev = dev;                 /* Mark as being used by this device. */
2013
                        skb_reserve(skb, 2);    /* Align IP on 16 byte boundaries */
2014
                        vp->rx_ring[entry].addr = cpu_to_le32(virt_to_bus(skb->tail));
2015
                        vp->rx_skbuff[entry] = skb;
2016
                }
2017
                vp->rx_ring[entry].status = 0;  /* Clear complete bit. */
2018
                outw(UpUnstall, ioaddr + EL3_CMD);
2019
        }
2020
        return 0;
2021
}
2022
 
218 giacomo 2023
/*
2024
 * If we've hit a total OOM refilling the Rx ring we poll once a second
2025
 * for some memory.  Otherwise there is no way to restart the rx process.
2026
 */
2027
static void
2028
rx_oom_timer(unsigned long arg)
2029
{
2030
        struct device *dev = (struct device *)arg;
2031
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2032
 
2033
        spin_lock_irq(&vp->lock);
2034
        if ((vp->cur_rx - vp->dirty_rx) == RX_RING_SIZE)        /* This test is redundant, but makes me feel good */
2035
                boomerang_rx(dev);
2036
        if (vortex_debug > 1) {
2037
                printk(KERN_DEBUG "%s: rx_oom_timer %s\n", dev->name,
2038
                        ((vp->cur_rx - vp->dirty_rx) != RX_RING_SIZE) ? "succeeded" : "retrying");
2039
        }
2040
        spin_unlock_irq(&vp->lock);
2041
}
2042
 
2 pj 2043
static int
2044
vortex_close(struct device *dev)
2045
{
2046
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2047
        long ioaddr = dev->base_addr;
2048
        int i;
2049
 
2050
        dev->start = 0;
2051
        dev->tbusy = 1;
2052
 
2053
        if (vortex_debug > 1) {
2054
                printk(KERN_DEBUG"%s: vortex_close() status %4.4x, Tx status %2.2x.\n",
2055
                           dev->name, inw(ioaddr + EL3_STATUS), inb(ioaddr + TxStatus));
2056
                printk(KERN_DEBUG "%s: vortex close stats: rx_nocopy %d rx_copy %d"
2057
                           " tx_queued %d Rx pre-checksummed %d.\n",
2058
                           dev->name, rx_nocopy, rx_copy, queued_packet, rx_csumhits);
2059
        }
2060
 
2061
        del_timer(&vp->timer);
218 giacomo 2062
        del_timer(&vp->rx_oom_timer);
2 pj 2063
 
2064
        /* Turn off statistics ASAP.  We update vp->stats below. */
2065
        outw(StatsDisable, ioaddr + EL3_CMD);
2066
 
2067
        /* Disable the receiver and transmitter. */
2068
        outw(RxDisable, ioaddr + EL3_CMD);
2069
        outw(TxDisable, ioaddr + EL3_CMD);
2070
 
2071
        if (dev->if_port == XCVR_10base2)
2072
                /* Turn off thinnet power.  Green! */
2073
                outw(StopCoax, ioaddr + EL3_CMD);
2074
 
2075
        free_irq(dev->irq, dev);
2076
 
2077
        outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
2078
 
2079
        update_stats(ioaddr, dev);
2080
        if (vp->full_bus_master_rx) { /* Free Boomerang bus master Rx buffers. */
2081
                outl(0, ioaddr + UpListPtr);
2082
                for (i = 0; i < RX_RING_SIZE; i++)
2083
                        if (vp->rx_skbuff[i]) {
218 giacomo 2084
                                dev_kfree_skb(vp->rx_skbuff[i]);
2 pj 2085
                                vp->rx_skbuff[i] = 0;
2086
                        }
2087
        }
2088
        if (vp->full_bus_master_tx) { /* Free Boomerang bus master Tx buffers. */
2089
                outl(0, ioaddr + DownListPtr);
2090
                for (i = 0; i < TX_RING_SIZE; i++)
2091
                        if (vp->tx_skbuff[i]) {
218 giacomo 2092
                                dev_kfree_skb(vp->tx_skbuff[i]);
2 pj 2093
                                vp->tx_skbuff[i] = 0;
2094
                        }
2095
        }
2096
 
218 giacomo 2097
        if (vp->enable_wol && (vp->capabilities & CapPwrMgmt))
2098
                acpi_set_WOL(dev);
2 pj 2099
        MOD_DEC_USE_COUNT;
2100
 
2101
        return 0;
2102
}
2103
 
2104
static struct net_device_stats *vortex_get_stats(struct device *dev)
2105
{
2106
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2107
        unsigned long flags;
2108
 
2109
        if (dev->start) {
218 giacomo 2110
                spin_lock_irqsave(&vp->lock, flags);
2 pj 2111
                update_stats(dev->base_addr, dev);
218 giacomo 2112
                spin_unlock_irqrestore(&vp->lock, flags);
2 pj 2113
        }
2114
        return &vp->stats;
2115
}
2116
 
2117
/*  Update statistics.
2118
        Unlike with the EL3 we need not worry about interrupts changing
2119
        the window setting from underneath us, but we must still guard
2120
        against a race condition with a StatsUpdate interrupt updating the
2121
        table.  This is done by checking that the ASM (!) code generated uses
2122
        atomic updates with '+='.
2123
        */
2124
static void update_stats(long ioaddr, struct device *dev)
2125
{
2126
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2127
 
2128
        /* Unlike the 3c5x9 we need not turn off stats updates while reading. */
2129
        /* Switch to the stats window, and read everything. */
2130
        EL3WINDOW(6);
2131
        vp->stats.tx_carrier_errors             += inb(ioaddr + 0);
2132
        vp->stats.tx_heartbeat_errors   += inb(ioaddr + 1);
2133
        /* Multiple collisions. */              inb(ioaddr + 2);
2134
        vp->stats.collisions                    += inb(ioaddr + 3);
2135
        vp->stats.tx_window_errors              += inb(ioaddr + 4);
2136
        vp->stats.rx_fifo_errors                += inb(ioaddr + 5);
2137
        vp->stats.tx_packets                    += inb(ioaddr + 6);
2138
        vp->stats.tx_packets                    += (inb(ioaddr + 9)&0x30) << 4;
2139
        /* Rx packets   */                              inb(ioaddr + 7);   /* Must read to clear */
2140
        /* Tx deferrals */                              inb(ioaddr + 8);
2141
        /* Don't bother with register 9, an extension of registers 6&7.
2142
           If we do use the 6&7 values the atomic update assumption above
2143
           is invalid. */
2144
        inw(ioaddr + 10);       /* Total Rx and Tx octets. */
2145
        inw(ioaddr + 12);
2146
        /* New: On the Vortex we must also clear the BadSSD counter. */
2147
        EL3WINDOW(4);
2148
        inb(ioaddr + 12);
2149
 
2150
        /* We change back to window 7 (not 1) with the Vortex. */
2151
        EL3WINDOW(7);
2152
        return;
2153
}
2154
 
2155
static int vortex_ioctl(struct device *dev, struct ifreq *rq, int cmd)
2156
{
2157
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2158
        long ioaddr = dev->base_addr;
2159
        u16 *data = (u16 *)&rq->ifr_data;
2160
        int phy = vp->phys[0] & 0x1f;
218 giacomo 2161
        int retval;
2162
        unsigned long flags;
2 pj 2163
 
218 giacomo 2164
        spin_lock_irqsave(&vp->lock, flags);
2165
 
2 pj 2166
        switch(cmd) {
2167
        case SIOCDEVPRIVATE:            /* Get the address of the PHY in use. */
2168
                data[0] = phy;
2169
        case SIOCDEVPRIVATE+1:          /* Read the specified MII register. */
2170
                EL3WINDOW(4);
2171
                data[3] = mdio_read(ioaddr, data[0] & 0x1f, data[1] & 0x1f);
218 giacomo 2172
                retval = 0;
2173
                break;
2 pj 2174
        case SIOCDEVPRIVATE+2:          /* Write the specified MII register */
218 giacomo 2175
                if (!capable(CAP_NET_ADMIN)) {
2176
                        retval = -EPERM;
2177
                } else {
2 pj 2178
                EL3WINDOW(4);
2179
                mdio_write(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2]);
218 giacomo 2180
                        retval = 0;
2181
                }
2182
                break;
2 pj 2183
        default:
218 giacomo 2184
                retval = -EOPNOTSUPP;
2 pj 2185
        }
218 giacomo 2186
 
2187
        spin_unlock_irqrestore(&vp->lock, flags);
2188
        return retval;
2 pj 2189
}
2190
 
2191
/* Pre-Cyclone chips have no documented multicast filter, so the only
2192
   multicast setting is to receive all multicast frames.  At least
2193
   the chip has a very clean way to set the mode, unlike many others. */
2194
static void set_rx_mode(struct device *dev)
2195
{
2196
        long ioaddr = dev->base_addr;
2197
        int new_mode;
2198
 
2199
        if (dev->flags & IFF_PROMISC) {
2200
                if (vortex_debug > 0)
2201
                        printk(KERN_NOTICE "%s: Setting promiscuous mode.\n", dev->name);
2202
                new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast|RxProm;
2203
        } else  if ((dev->mc_list)  ||  (dev->flags & IFF_ALLMULTI)) {
2204
                new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast;
2205
        } else
2206
                new_mode = SetRxFilter | RxStation | RxBroadcast;
2207
 
2208
        outw(new_mode, ioaddr + EL3_CMD);
2209
}
2210
 
2211
 
2212
/* MII transceiver control section.
2213
   Read and write the MII registers using software-generated serial
2214
   MDIO protocol.  See the MII specifications or DP83840A data sheet
2215
   for details. */
2216
 
2217
/* The maximum data clock rate is 2.5 Mhz.  The minimum timing is usually
2218
   met by back-to-back PCI I/O cycles, but we insert a delay to avoid
2219
   "overclocking" issues. */
2220
#define mdio_delay() inl(mdio_addr)
2221
 
2222
#define MDIO_SHIFT_CLK  0x01
2223
#define MDIO_DIR_WRITE  0x04
2224
#define MDIO_DATA_WRITE0 (0x00 | MDIO_DIR_WRITE)
2225
#define MDIO_DATA_WRITE1 (0x02 | MDIO_DIR_WRITE)
2226
#define MDIO_DATA_READ  0x02
2227
#define MDIO_ENB_IN             0x00
2228
 
2229
/* Generate the preamble required for initial synchronization and
2230
   a few older transceivers. */
2231
static void mdio_sync(long ioaddr, int bits)
2232
{
2233
        long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
2234
 
2235
        /* Establish sync by sending at least 32 logic ones. */
2236
        while (-- bits >= 0) {
2237
                outw(MDIO_DATA_WRITE1, mdio_addr);
2238
                mdio_delay();
2239
                outw(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
2240
                mdio_delay();
2241
        }
2242
}
2243
 
2244
static int mdio_read(long ioaddr, int phy_id, int location)
2245
{
2246
        int i;
2247
        int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
2248
        unsigned int retval = 0;
2249
        long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
2250
 
2251
        if (mii_preamble_required)
2252
                mdio_sync(ioaddr, 32);
2253
 
2254
        /* Shift the read command bits out. */
2255
        for (i = 14; i >= 0; i--) {
2256
                int dataval = (read_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
2257
                outw(dataval, mdio_addr);
2258
                mdio_delay();
2259
                outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
2260
                mdio_delay();
2261
        }
2262
        /* Read the two transition, 16 data, and wire-idle bits. */
2263
        for (i = 19; i > 0; i--) {
2264
                outw(MDIO_ENB_IN, mdio_addr);
2265
                mdio_delay();
2266
                retval = (retval << 1) | ((inw(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
2267
                outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
2268
                mdio_delay();
2269
        }
2270
#if 0
2271
        return (retval>>1) & 0x1ffff;
2272
#else
2273
        return retval & 0x20000 ? 0xffff : retval>>1 & 0xffff;
2274
#endif
2275
}
2276
 
2277
static void mdio_write(long ioaddr, int phy_id, int location, int value)
2278
{
2279
        int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value;
2280
        long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
2281
        int i;
2282
 
2283
        if (mii_preamble_required)
2284
                mdio_sync(ioaddr, 32);
2285
 
2286
        /* Shift the command bits out. */
2287
        for (i = 31; i >= 0; i--) {
2288
                int dataval = (write_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
2289
                outw(dataval, mdio_addr);
2290
                mdio_delay();
2291
                outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
2292
                mdio_delay();
2293
        }
2294
        /* Leave the interface idle. */
2295
        for (i = 1; i >= 0; i--) {
2296
                outw(MDIO_ENB_IN, mdio_addr);
2297
                mdio_delay();
2298
                outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
2299
                mdio_delay();
2300
        }
2301
 
2302
        return;
2303
}
2304
 
218 giacomo 2305
/* ACPI: Advanced Configuration and Power Interface. */
2306
/* Set Wake-On-LAN mode and put the board into D3 (power-down) state. */
2307
static void acpi_set_WOL(struct device *dev)
2308
{
2309
        struct vortex_private *vp = (struct vortex_private *)dev->priv;
2310
        long ioaddr = dev->base_addr;
2311
 
2312
        /* Power up on: 1==Downloaded Filter, 2==Magic Packets, 4==Link Status. */
2313
        EL3WINDOW(7);
2314
        outw(2, ioaddr + 0x0c);
2315
        /* The RxFilter must accept the WOL frames. */
2316
        outw(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
2317
        outw(RxEnable, ioaddr + EL3_CMD);
2318
        /* Change the power state to D3; RxEnable doesn't take effect. */
2319
        pcibios_write_config_word(vp->pci_bus, vp->pci_devfn, 0xe0, 0x8103);
2320
}
2321
 
2322
/* Change from D3 (sleep) to D0 (active).
2323
   Problem: The Cyclone forgets all PCI config info during the transition! */
2324
static void acpi_wake(int bus, int devfn)
2325
{
2326
        u32 base0, base1, romaddr;
2327
        u16 pci_command, pwr_command;
2328
        u8  pci_latency, pci_cacheline, irq;
2329
 
2330
        pcibios_read_config_word(bus, devfn, 0xe0, &pwr_command);
2331
        if ((pwr_command & 3) == 0)
2332
                return;
2333
        pcibios_read_config_word( bus, devfn, PCI_COMMAND, &pci_command);
2334
        pcibios_read_config_dword(bus, devfn, PCI_BASE_ADDRESS_0, &base0);
2335
        pcibios_read_config_dword(bus, devfn, PCI_BASE_ADDRESS_1, &base1);
2336
        pcibios_read_config_dword(bus, devfn, PCI_ROM_ADDRESS, &romaddr);
2337
        pcibios_read_config_byte( bus, devfn, PCI_LATENCY_TIMER, &pci_latency);
2338
        pcibios_read_config_byte( bus, devfn, PCI_CACHE_LINE_SIZE, &pci_cacheline);
2339
        pcibios_read_config_byte( bus, devfn, PCI_INTERRUPT_LINE, &irq);
2340
 
2341
        pcibios_write_config_word( bus, devfn, 0xe0, 0x0000);
2342
        pcibios_write_config_dword(bus, devfn, PCI_BASE_ADDRESS_0, base0);
2343
        pcibios_write_config_dword(bus, devfn, PCI_BASE_ADDRESS_1, base1);
2344
        pcibios_write_config_dword(bus, devfn, PCI_ROM_ADDRESS, romaddr);
2345
        pcibios_write_config_byte( bus, devfn, PCI_INTERRUPT_LINE, irq);
2346
        pcibios_write_config_byte( bus, devfn, PCI_LATENCY_TIMER, pci_latency);
2347
        pcibios_write_config_byte( bus, devfn, PCI_CACHE_LINE_SIZE, pci_cacheline);
2348
        pcibios_write_config_word( bus, devfn, PCI_COMMAND, pci_command | 5);
2349
}
2350
 
2 pj 2351
 
2352
#ifdef MODULE
2353
void cleanup_module(void)
2354
{
2355
        struct device *next_dev;
2356
 
2357
        /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
2358
        while (root_vortex_dev) {
2359
                struct vortex_private *vp=(void *)(root_vortex_dev->priv);
218 giacomo 2360
                int drv_flags = pci_tbl[vp->chip_id].drv_flags;
2 pj 2361
                next_dev = vp->next_module;
2362
                unregister_netdev(root_vortex_dev);
218 giacomo 2363
                outw((drv_flags & EEPROM_NORESET) ? (TotalReset|0x10) : TotalReset,
2364
                                root_vortex_dev->base_addr + EL3_CMD);
2 pj 2365
                release_region(root_vortex_dev->base_addr,
2366
                                           pci_tbl[vp->chip_id].io_size);
2367
                kfree(root_vortex_dev);
2368
                kfree(vp->priv_addr);
2369
                root_vortex_dev = next_dev;
2370
        }
2371
}
2372
 
2373
#endif  /* MODULE */
2374
 
2375
/*
2376
 * Local variables:
2377
 *  c-indent-level: 4
2378
 *  c-basic-offset: 4
2379
 *  tab-width: 4
2380
 * End:
2381
 */