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