File: /usr/src/linux/drivers/net/eepro.c
1 /* eepro.c: Intel EtherExpress Pro/10 device driver for Linux. */
2 /*
3 Written 1994, 1995,1996 by Bao C. Ha.
4
5 Copyright (C) 1994, 1995,1996 by Bao C. Ha.
6
7 This software may be used and distributed
8 according to the terms of the GNU General Public License,
9 incorporated herein by reference.
10
11 The author may be reached at bao.ha@srs.gov
12 or 418 Hastings Place, Martinez, GA 30907.
13
14 Things remaining to do:
15 Better record keeping of errors.
16 Eliminate transmit interrupt to reduce overhead.
17 Implement "concurrent processing". I won't be doing it!
18
19 Bugs:
20
21 If you have a problem of not detecting the 82595 during a
22 reboot (warm reset), disable the FLASH memory should fix it.
23 This is a compatibility hardware problem.
24
25 Versions:
26 0.12c fixing some problems with old cards (aris, 01/08/2001)
27 0.12b misc fixes (aris, 06/26/2000)
28 0.12a port of version 0.12a of 2.2.x kernels to 2.3.x
29 (aris (aris@conectiva.com.br), 05/19/2000)
30 0.11e some tweaks about multiple cards support (PdP, jul/aug 1999)
31 0.11d added __initdata, __init stuff; call spin_lock_init
32 in eepro_probe1. Replaced "eepro" by dev->name. Augmented
33 the code protected by spin_lock in interrupt routine
34 (PdP, 12/12/1998)
35 0.11c minor cleanup (PdP, RMC, 09/12/1998)
36 0.11b Pascal Dupuis (dupuis@lei.ucl.ac.be): works as a module
37 under 2.1.xx. Debug messages are flagged as KERN_DEBUG to
38 avoid console flooding. Added locking at critical parts. Now
39 the dawn thing is SMP safe.
40 0.11a Attempt to get 2.1.xx support up (RMC)
41 0.11 Brian Candler added support for multiple cards. Tested as
42 a module, no idea if it works when compiled into kernel.
43
44 0.10e Rick Bressler notified me that ifconfig up;ifconfig down fails
45 because the irq is lost somewhere. Fixed that by moving
46 request_irq and free_irq to eepro_open and eepro_close respectively.
47 0.10d Ugh! Now Wakeup works. Was seriously broken in my first attempt.
48 I'll need to find a way to specify an ioport other than
49 the default one in the PnP case. PnP definitively sucks.
50 And, yes, this is not the only reason.
51 0.10c PnP Wakeup Test for 595FX. uncomment #define PnPWakeup;
52 to use.
53 0.10b Should work now with (some) Pro/10+. At least for
54 me (and my two cards) it does. _No_ guarantee for
55 function with non-Pro/10+ cards! (don't have any)
56 (RMC, 9/11/96)
57
58 0.10 Added support for the Etherexpress Pro/10+. The
59 IRQ map was changed significantly from the old
60 pro/10. The new interrupt map was provided by
61 Rainer M. Canavan (Canavan@Zeus.cs.bonn.edu).
62 (BCH, 9/3/96)
63
64 0.09 Fixed a race condition in the transmit algorithm,
65 which causes crashes under heavy load with fast
66 pentium computers. The performance should also
67 improve a bit. The size of RX buffer, and hence
68 TX buffer, can also be changed via lilo or insmod.
69 (BCH, 7/31/96)
70
71 0.08 Implement 32-bit I/O for the 82595TX and 82595FX
72 based lan cards. Disable full-duplex mode if TPE
73 is not used. (BCH, 4/8/96)
74
75 0.07a Fix a stat report which counts every packet as a
76 heart-beat failure. (BCH, 6/3/95)
77
78 0.07 Modified to support all other 82595-based lan cards.
79 The IRQ vector of the EtherExpress Pro will be set
80 according to the value saved in the EEPROM. For other
81 cards, I will do autoirq_request() to grab the next
82 available interrupt vector. (BCH, 3/17/95)
83
84 0.06a,b Interim released. Minor changes in the comments and
85 print out format. (BCH, 3/9/95 and 3/14/95)
86
87 0.06 First stable release that I am comfortable with. (BCH,
88 3/2/95)
89
90 0.05 Complete testing of multicast. (BCH, 2/23/95)
91
92 0.04 Adding multicast support. (BCH, 2/14/95)
93
94 0.03 First widely alpha release for public testing.
95 (BCH, 2/14/95)
96
97 */
98
99 static const char version[] =
100 "eepro.c: v0.12c 01/08/2000 aris@conectiva.com.br\n";
101
102 #include <linux/module.h>
103
104 /*
105 Sources:
106
107 This driver wouldn't have been written without the availability
108 of the Crynwr's Lan595 driver source code. It helps me to
109 familiarize with the 82595 chipset while waiting for the Intel
110 documentation. I also learned how to detect the 82595 using
111 the packet driver's technique.
112
113 This driver is written by cutting and pasting the skeleton.c driver
114 provided by Donald Becker. I also borrowed the EEPROM routine from
115 Donald Becker's 82586 driver.
116
117 Datasheet for the Intel 82595 (including the TX and FX version). It
118 provides just enough info that the casual reader might think that it
119 documents the i82595.
120
121 The User Manual for the 82595. It provides a lot of the missing
122 information.
123
124 */
125
126 #include <linux/kernel.h>
127 #include <linux/sched.h>
128 #include <linux/types.h>
129 #include <linux/fcntl.h>
130 #include <linux/interrupt.h>
131 #include <linux/ptrace.h>
132 #include <linux/ioport.h>
133 #include <linux/in.h>
134 #include <linux/slab.h>
135 #include <linux/string.h>
136 #include <asm/system.h>
137 #include <asm/bitops.h>
138 #include <asm/io.h>
139 #include <asm/dma.h>
140 #include <linux/errno.h>
141
142 #include <linux/netdevice.h>
143 #include <linux/etherdevice.h>
144 #include <linux/skbuff.h>
145 #include <linux/spinlock.h>
146 #include <linux/init.h>
147 #include <linux/delay.h>
148
149 #define compat_dev_kfree_skb( skb, mode ) dev_kfree_skb( (skb) )
150 /* I had reports of looong delays with SLOW_DOWN defined as udelay(2) */
151 #define SLOW_DOWN inb(0x80)
152 /* udelay(2) */
153 #define compat_init_data __initdata
154
155
156 /* First, a few definitions that the brave might change. */
157 /* A zero-terminated list of I/O addresses to be probed. */
158 static unsigned int eepro_portlist[] compat_init_data =
159 { 0x300, 0x210, 0x240, 0x280, 0x2C0, 0x200, 0x320, 0x340, 0x360, 0};
160 /* note: 0x300 is default, the 595FX supports ALL IO Ports
161 from 0x000 to 0x3F0, some of which are reserved in PCs */
162
163 /* To try the (not-really PnP Wakeup: */
164 /*
165 #define PnPWakeup
166 */
167
168 /* use 0 for production, 1 for verification, >2 for debug */
169 #ifndef NET_DEBUG
170 #define NET_DEBUG 0
171 #endif
172 static unsigned int net_debug = NET_DEBUG;
173
174 /* The number of low I/O ports used by the ethercard. */
175 #define EEPRO_IO_EXTENT 16
176
177 /* Different 82595 chips */
178 #define LAN595 0
179 #define LAN595TX 1
180 #define LAN595FX 2
181 #define LAN595FX_10ISA 3
182
183 /* Information that need to be kept for each board. */
184 struct eepro_local {
185 struct net_device_stats stats;
186 unsigned rx_start;
187 unsigned tx_start; /* start of the transmit chain */
188 int tx_last; /* pointer to last packet in the transmit chain */
189 unsigned tx_end; /* end of the transmit chain (plus 1) */
190 int eepro; /* 1 for the EtherExpress Pro/10,
191 2 for the EtherExpress Pro/10+,
192 0 for other 82595-based lan cards. */
193 int version; /* a flag to indicate if this is a TX or FX
194 version of the 82595 chip. */
195 int stepping;
196
197 spinlock_t lock; /* Serializing lock */
198 };
199
200 /* The station (ethernet) address prefix, used for IDing the board. */
201 #define SA_ADDR0 0x00 /* Etherexpress Pro/10 */
202 #define SA_ADDR1 0xaa
203 #define SA_ADDR2 0x00
204
205 #define GetBit(x,y) ((x & (1<<y))>>y)
206
207 /* EEPROM Word 0: */
208 #define ee_PnP 0 /* Plug 'n Play enable bit */
209 #define ee_Word1 1 /* Word 1? */
210 #define ee_BusWidth 2 /* 8/16 bit */
211 #define ee_FlashAddr 3 /* Flash Address */
212 #define ee_FlashMask 0x7 /* Mask */
213 #define ee_AutoIO 6 /* */
214 #define ee_reserved0 7 /* =0! */
215 #define ee_Flash 8 /* Flash there? */
216 #define ee_AutoNeg 9 /* Auto Negotiation enabled? */
217 #define ee_IO0 10 /* IO Address LSB */
218 #define ee_IO0Mask 0x /*...*/
219 #define ee_IO1 15 /* IO MSB */
220
221 /* EEPROM Word 1: */
222 #define ee_IntSel 0 /* Interrupt */
223 #define ee_IntMask 0x7
224 #define ee_LI 3 /* Link Integrity 0= enabled */
225 #define ee_PC 4 /* Polarity Correction 0= enabled */
226 #define ee_TPE_AUI 5 /* PortSelection 1=TPE */
227 #define ee_Jabber 6 /* Jabber prevention 0= enabled */
228 #define ee_AutoPort 7 /* Auto Port Selection 1= Disabled */
229 #define ee_SMOUT 8 /* SMout Pin Control 0= Input */
230 #define ee_PROM 9 /* Flash EPROM / PROM 0=Flash */
231 #define ee_reserved1 10 /* .. 12 =0! */
232 #define ee_AltReady 13 /* Alternate Ready, 0=normal */
233 #define ee_reserved2 14 /* =0! */
234 #define ee_Duplex 15
235
236 /* Word2,3,4: */
237 #define ee_IA5 0 /*bit start for individual Addr Byte 5 */
238 #define ee_IA4 8 /*bit start for individual Addr Byte 5 */
239 #define ee_IA3 0 /*bit start for individual Addr Byte 5 */
240 #define ee_IA2 8 /*bit start for individual Addr Byte 5 */
241 #define ee_IA1 0 /*bit start for individual Addr Byte 5 */
242 #define ee_IA0 8 /*bit start for individual Addr Byte 5 */
243
244 /* Word 5: */
245 #define ee_BNC_TPE 0 /* 0=TPE */
246 #define ee_BootType 1 /* 00=None, 01=IPX, 10=ODI, 11=NDIS */
247 #define ee_BootTypeMask 0x3
248 #define ee_NumConn 3 /* Number of Connections 0= One or Two */
249 #define ee_FlashSock 4 /* Presence of Flash Socket 0= Present */
250 #define ee_PortTPE 5
251 #define ee_PortBNC 6
252 #define ee_PortAUI 7
253 #define ee_PowerMgt 10 /* 0= disabled */
254 #define ee_CP 13 /* Concurrent Processing */
255 #define ee_CPMask 0x7
256
257 /* Word 6: */
258 #define ee_Stepping 0 /* Stepping info */
259 #define ee_StepMask 0x0F
260 #define ee_BoardID 4 /* Manucaturer Board ID, reserved */
261 #define ee_BoardMask 0x0FFF
262
263 /* Word 7: */
264 #define ee_INT_TO_IRQ 0 /* int to IRQ Mapping = 0x1EB8 for Pro/10+ */
265 #define ee_FX_INT2IRQ 0x1EB8 /* the _only_ mapping allowed for FX chips */
266
267 /*..*/
268 #define ee_SIZE 0x40 /* total EEprom Size */
269 #define ee_Checksum 0xBABA /* initial and final value for adding checksum */
270
271
272 /* Card identification via EEprom: */
273 #define ee_addr_vendor 0x10 /* Word offset for EISA Vendor ID */
274 #define ee_addr_id 0x11 /* Word offset for Card ID */
275 #define ee_addr_SN 0x12 /* Serial Number */
276 #define ee_addr_CRC_8 0x14 /* CRC over last thee Bytes */
277
278
279 #define ee_vendor_intel0 0x25 /* Vendor ID Intel */
280 #define ee_vendor_intel1 0xD4
281 #define ee_id_eepro10p0 0x10 /* ID for eepro/10+ */
282 #define ee_id_eepro10p1 0x31
283
284 #define TX_TIMEOUT 40
285
286 /* Index to functions, as function prototypes. */
287
288 extern int eepro_probe(struct net_device *dev);
289
290 static int eepro_probe1(struct net_device *dev, short ioaddr);
291 static int eepro_open(struct net_device *dev);
292 static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev);
293 static void eepro_interrupt(int irq, void *dev_id, struct pt_regs *regs);
294 static void eepro_rx(struct net_device *dev);
295 static void eepro_transmit_interrupt(struct net_device *dev);
296 static int eepro_close(struct net_device *dev);
297 static struct net_device_stats *eepro_get_stats(struct net_device *dev);
298 static void set_multicast_list(struct net_device *dev);
299 static void eepro_tx_timeout (struct net_device *dev);
300
301 static int read_eeprom(int ioaddr, int location, struct net_device *dev);
302 static void hardware_send_packet(struct net_device *dev, void *buf, short length);
303 static int eepro_grab_irq(struct net_device *dev);
304
305 /*
306 Details of the i82595.
307
308 You will need either the datasheet or the user manual to understand what
309 is going on here. The 82595 is very different from the 82586, 82593.
310
311 The receive algorithm in eepro_rx() is just an implementation of the
312 RCV ring structure that the Intel 82595 imposes at the hardware level.
313 The receive buffer is set at 24K, and the transmit buffer is 8K. I
314 am assuming that the total buffer memory is 32K, which is true for the
315 Intel EtherExpress Pro/10. If it is less than that on a generic card,
316 the driver will be broken.
317
318 The transmit algorithm in the hardware_send_packet() is similar to the
319 one in the eepro_rx(). The transmit buffer is a ring linked list.
320 I just queue the next available packet to the end of the list. In my
321 system, the 82595 is so fast that the list seems to always contain a
322 single packet. In other systems with faster computers and more congested
323 network traffics, the ring linked list should improve performance by
324 allowing up to 8K worth of packets to be queued.
325
326 The sizes of the receive and transmit buffers can now be changed via lilo
327 or insmod. Lilo uses the appended line "ether=io,irq,debug,rx-buffer,eth0"
328 where rx-buffer is in KB unit. Modules uses the parameter mem which is
329 also in KB unit, for example "insmod io=io-address irq=0 mem=rx-buffer."
330 The receive buffer has to be more than 3K or less than 29K. Otherwise,
331 it is reset to the default of 24K, and, hence, 8K for the trasnmit
332 buffer (transmit-buffer = 32K - receive-buffer).
333
334 */
335 /* now this section could be used by both boards: the oldies and the ee10:
336 * ee10 uses tx buffer before of rx buffer and the oldies the inverse.
337 * (aris)
338 */
339 #define RAM_SIZE 0x8000
340
341 #define RCV_HEADER 8
342 #define RCV_DEFAULT_RAM 0x6000
343 #define RCV_RAM rcv_ram
344
345 static unsigned rcv_ram = RCV_DEFAULT_RAM;
346
347 #define XMT_HEADER 8
348 #define XMT_RAM (RAM_SIZE - RCV_RAM)
349
350 #define XMT_START ((rcv_start + RCV_RAM) % RAM_SIZE)
351
352 #define RCV_LOWER_LIMIT (rcv_start >> 8)
353 #define RCV_UPPER_LIMIT (((rcv_start + RCV_RAM) - 2) >> 8)
354 #define XMT_LOWER_LIMIT (XMT_START >> 8)
355 #define XMT_UPPER_LIMIT (((XMT_START + XMT_RAM) - 2) >> 8)
356
357 #define RCV_START_PRO 0x00
358 #define RCV_START_10 XMT_RAM
359 /* by default the old driver */
360 static unsigned rcv_start = RCV_START_PRO;
361
362 #define RCV_DONE 0x0008
363 #define RX_OK 0x2000
364 #define RX_ERROR 0x0d81
365
366 #define TX_DONE_BIT 0x0080
367 #define CHAIN_BIT 0x8000
368 #define XMT_STATUS 0x02
369 #define XMT_CHAIN 0x04
370 #define XMT_COUNT 0x06
371
372 #define BANK0_SELECT 0x00
373 #define BANK1_SELECT 0x40
374 #define BANK2_SELECT 0x80
375
376 /* Bank 0 registers */
377 #define COMMAND_REG 0x00 /* Register 0 */
378 #define MC_SETUP 0x03
379 #define XMT_CMD 0x04
380 #define DIAGNOSE_CMD 0x07
381 #define RCV_ENABLE_CMD 0x08
382 #define RCV_DISABLE_CMD 0x0a
383 #define STOP_RCV_CMD 0x0b
384 #define RESET_CMD 0x0e
385 #define POWER_DOWN_CMD 0x18
386 #define RESUME_XMT_CMD 0x1c
387 #define SEL_RESET_CMD 0x1e
388 #define STATUS_REG 0x01 /* Register 1 */
389 #define RX_INT 0x02
390 #define TX_INT 0x04
391 #define EXEC_STATUS 0x30
392 #define ID_REG 0x02 /* Register 2 */
393 #define R_ROBIN_BITS 0xc0 /* round robin counter */
394 #define ID_REG_MASK 0x2c
395 #define ID_REG_SIG 0x24
396 #define AUTO_ENABLE 0x10
397 #define INT_MASK_REG 0x03 /* Register 3 */
398 #define RX_STOP_MASK 0x01
399 #define RX_MASK 0x02
400 #define TX_MASK 0x04
401 #define EXEC_MASK 0x08
402 #define ALL_MASK 0x0f
403 #define IO_32_BIT 0x10
404 #define RCV_BAR 0x04 /* The following are word (16-bit) registers */
405 #define RCV_STOP 0x06
406
407 #define XMT_BAR_PRO 0x0a
408 #define XMT_BAR_10 0x0b
409 static unsigned xmt_bar = XMT_BAR_PRO;
410
411 #define HOST_ADDRESS_REG 0x0c
412 #define IO_PORT 0x0e
413 #define IO_PORT_32_BIT 0x0c
414
415 /* Bank 1 registers */
416 #define REG1 0x01
417 #define WORD_WIDTH 0x02
418 #define INT_ENABLE 0x80
419 #define INT_NO_REG 0x02
420 #define RCV_LOWER_LIMIT_REG 0x08
421 #define RCV_UPPER_LIMIT_REG 0x09
422
423 #define XMT_LOWER_LIMIT_REG_PRO 0x0a
424 #define XMT_UPPER_LIMIT_REG_PRO 0x0b
425 #define XMT_LOWER_LIMIT_REG_10 0x0b
426 #define XMT_UPPER_LIMIT_REG_10 0x0a
427 static unsigned xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_PRO;
428 static unsigned xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_PRO;
429
430 /* Bank 2 registers */
431 #define XMT_Chain_Int 0x20 /* Interrupt at the end of the transmit chain */
432 #define XMT_Chain_ErrStop 0x40 /* Interrupt at the end of the chain even if there are errors */
433 #define RCV_Discard_BadFrame 0x80 /* Throw bad frames away, and continue to receive others */
434 #define REG2 0x02
435 #define PRMSC_Mode 0x01
436 #define Multi_IA 0x20
437 #define REG3 0x03
438 #define TPE_BIT 0x04
439 #define BNC_BIT 0x20
440 #define REG13 0x0d
441 #define FDX 0x00
442 #define A_N_ENABLE 0x02
443
444 #define I_ADD_REG0 0x04
445 #define I_ADD_REG1 0x05
446 #define I_ADD_REG2 0x06
447 #define I_ADD_REG3 0x07
448 #define I_ADD_REG4 0x08
449 #define I_ADD_REG5 0x09
450
451 #define EEPROM_REG_PRO 0x0a
452 #define EEPROM_REG_10 0x0b
453 static unsigned eeprom_reg = EEPROM_REG_PRO;
454
455 #define EESK 0x01
456 #define EECS 0x02
457 #define EEDI 0x04
458 #define EEDO 0x08
459
460 /* do a full reset */
461 #define eepro_reset(ioaddr) outb(RESET_CMD, ioaddr)
462
463 /* do a nice reset */
464 #define eepro_sel_reset(ioaddr) { \
465 outb(SEL_RESET_CMD, ioaddr); \
466 SLOW_DOWN; \
467 SLOW_DOWN; \
468 }
469
470 /* disable all interrupts */
471 #define eepro_dis_int(ioaddr) outb(ALL_MASK, ioaddr + INT_MASK_REG)
472
473 /* clear all interrupts */
474 #define eepro_clear_int(ioaddr) outb(ALL_MASK, ioaddr + STATUS_REG)
475
476 /* enable tx/rx */
477 #define eepro_en_int(ioaddr) outb(ALL_MASK & ~(RX_MASK | TX_MASK), \
478 ioaddr + INT_MASK_REG)
479
480 /* enable exec event interrupt */
481 #define eepro_en_intexec(ioaddr) outb(ALL_MASK & ~(EXEC_MASK), ioaddr + INT_MASK_REG)
482
483 /* enable rx */
484 #define eepro_en_rx(ioaddr) outb(RCV_ENABLE_CMD, ioaddr)
485
486 /* disable rx */
487 #define eepro_dis_rx(ioaddr) outb(RCV_DISABLE_CMD, ioaddr)
488
489 /* switch bank */
490 #define eepro_sw2bank0(ioaddr) outb(BANK0_SELECT, ioaddr)
491 #define eepro_sw2bank1(ioaddr) outb(BANK1_SELECT, ioaddr)
492 #define eepro_sw2bank2(ioaddr) outb(BANK2_SELECT, ioaddr)
493
494 /* enable interrupt line */
495 #define eepro_en_intline(ioaddr) outb(inb(ioaddr + REG1) | INT_ENABLE,\
496 ioaddr + REG1)
497
498 /* disable interrupt line */
499 #define eepro_dis_intline(ioaddr) outb(inb(ioaddr + REG1) & 0x7f, \
500 ioaddr + REG1);
501
502 /* set diagnose flag */
503 #define eepro_diag(ioaddr) outb(DIAGNOSE_CMD, ioaddr)
504
505 #ifdef ANSWER_TX_AND_RX /* experimental way of handling interrupts */
506 /* ack for rx/tx int */
507 #define eepro_ack_rxtx(ioaddr) outb (RX_INT | TX_INT, ioaddr + STATUS_REG)
508 #endif
509
510 /* ack for rx int */
511 #define eepro_ack_rx(ioaddr) outb (RX_INT, ioaddr + STATUS_REG)
512
513 /* ack for tx int */
514 #define eepro_ack_tx(ioaddr) outb (TX_INT, ioaddr + STATUS_REG)
515
516 /* a complete sel reset */
517 #define eepro_complete_selreset(ioaddr) { eepro_dis_int(ioaddr);\
518 lp->stats.tx_errors++;\
519 eepro_sel_reset(ioaddr);\
520 lp->tx_end = \
521 (XMT_LOWER_LIMIT << 8);\
522 lp->tx_start = lp->tx_end;\
523 lp->tx_last = 0;\
524 dev->trans_start = jiffies;\
525 netif_wake_queue(dev);\
526 eepro_en_int(ioaddr);\
527 eepro_en_rx(ioaddr);\
528 }
529
530 /* Check for a network adaptor of this type, and return '0' if one exists.
531 If dev->base_addr == 0, probe all likely locations.
532 If dev->base_addr == 1, always return failure.
533 If dev->base_addr == 2, allocate space for the device and return success
534 (detachable devices only).
535 */
536 int __init eepro_probe(struct net_device *dev)
537 {
538 int i;
539 int base_addr = dev->base_addr;
540
541 SET_MODULE_OWNER(dev);
542
543 #ifdef PnPWakeup
544 /* XXXX for multiple cards should this only be run once? */
545
546 /* Wakeup: */
547 #define WakeupPort 0x279
548 #define WakeupSeq {0x6A, 0xB5, 0xDA, 0xED, 0xF6, 0xFB, 0x7D, 0xBE,\
549 0xDF, 0x6F, 0x37, 0x1B, 0x0D, 0x86, 0xC3, 0x61,\
550 0xB0, 0x58, 0x2C, 0x16, 0x8B, 0x45, 0xA2, 0xD1,\
551 0xE8, 0x74, 0x3A, 0x9D, 0xCE, 0xE7, 0x73, 0x43}
552
553 {
554 unsigned short int WS[32]=WakeupSeq;
555
556 if (check_region(WakeupPort, 2)==0) {
557
558 if (net_debug>5)
559 printk(KERN_DEBUG "Waking UP\n");
560
561 outb_p(0,WakeupPort);
562 outb_p(0,WakeupPort);
563 for (i=0; i<32; i++) {
564 outb_p(WS[i],WakeupPort);
565 if (net_debug>5) printk(KERN_DEBUG ": %#x ",WS[i]);
566 }
567 } else printk(KERN_WARNING "Checkregion Failed!\n");
568 }
569 #endif
570
571
572 if (base_addr > 0x1ff) /* Check a single specified location. */
573 return eepro_probe1(dev, base_addr);
574
575 else if (base_addr != 0) /* Don't probe at all. */
576 return -ENXIO;
577
578
579 for (i = 0; eepro_portlist[i]; i++) {
580 int ioaddr = eepro_portlist[i];
581
582 if (check_region(ioaddr, EEPRO_IO_EXTENT))
583 continue;
584 if (eepro_probe1(dev, ioaddr) == 0)
585 return 0;
586 }
587
588 return -ENODEV;
589 }
590
591 static void __init printEEPROMInfo(short ioaddr, struct net_device *dev)
592 {
593 unsigned short Word;
594 int i,j;
595
596 for (i=0, j=ee_Checksum; i<ee_SIZE; i++)
597 j+=read_eeprom(ioaddr,i,dev);
598 printk("Checksum: %#x\n",j&0xffff);
599
600 Word=read_eeprom(ioaddr, 0, dev);
601 printk(KERN_DEBUG "Word0:\n");
602 printk(KERN_DEBUG " Plug 'n Pray: %d\n",GetBit(Word,ee_PnP));
603 printk(KERN_DEBUG " Buswidth: %d\n",(GetBit(Word,ee_BusWidth)+1)*8 );
604 printk(KERN_DEBUG " AutoNegotiation: %d\n",GetBit(Word,ee_AutoNeg));
605 printk(KERN_DEBUG " IO Address: %#x\n", (Word>>ee_IO0)<<4);
606
607 if (net_debug>4) {
608 Word=read_eeprom(ioaddr, 1, dev);
609 printk(KERN_DEBUG "Word1:\n");
610 printk(KERN_DEBUG " INT: %d\n", Word & ee_IntMask);
611 printk(KERN_DEBUG " LI: %d\n", GetBit(Word,ee_LI));
612 printk(KERN_DEBUG " PC: %d\n", GetBit(Word,ee_PC));
613 printk(KERN_DEBUG " TPE/AUI: %d\n", GetBit(Word,ee_TPE_AUI));
614 printk(KERN_DEBUG " Jabber: %d\n", GetBit(Word,ee_Jabber));
615 printk(KERN_DEBUG " AutoPort: %d\n", GetBit(!Word,ee_Jabber));
616 printk(KERN_DEBUG " Duplex: %d\n", GetBit(Word,ee_Duplex));
617 }
618
619 Word=read_eeprom(ioaddr, 5, dev);
620 printk(KERN_DEBUG "Word5:\n");
621 printk(KERN_DEBUG " BNC: %d\n",GetBit(Word,ee_BNC_TPE));
622 printk(KERN_DEBUG " NumConnectors: %d\n",GetBit(Word,ee_NumConn));
623 printk(KERN_DEBUG " Has ");
624 if (GetBit(Word,ee_PortTPE)) printk("TPE ");
625 if (GetBit(Word,ee_PortBNC)) printk("BNC ");
626 if (GetBit(Word,ee_PortAUI)) printk("AUI ");
627 printk("port(s) \n");
628
629 Word=read_eeprom(ioaddr, 6, dev);
630 printk(KERN_DEBUG "Word6:\n");
631 printk(KERN_DEBUG " Stepping: %d\n",Word & ee_StepMask);
632 printk(KERN_DEBUG " BoardID: %d\n",Word>>ee_BoardID);
633
634 Word=read_eeprom(ioaddr, 7, dev);
635 printk(KERN_DEBUG "Word7:\n");
636 printk(KERN_DEBUG " INT to IRQ:\n");
637
638 printk(KERN_DEBUG);
639
640 for (i=0, j=0; i<15; i++)
641 if (GetBit(Word,i)) printk(" INT%d -> IRQ %d;",j++,i);
642
643 printk("\n");
644 }
645
646 /* This is the real probe routine. Linux has a history of friendly device
647 probes on the ISA bus. A good device probe avoids doing writes, and
648 verifies that the correct device exists and functions. */
649
650 static int __init eepro_probe1(struct net_device *dev, short ioaddr)
651 {
652 unsigned short station_addr[6], id, counter;
653 int i,j, irqMask;
654 int eepro = 0;
655 struct eepro_local *lp;
656 const char *ifmap[] = {"AUI", "10Base2", "10BaseT"};
657 enum iftype { AUI=0, BNC=1, TPE=2 };
658
659 /* Now, we are going to check for the signature of the
660 ID_REG (register 2 of bank 0) */
661
662 id=inb(ioaddr + ID_REG);
663
664 if (((id) & ID_REG_MASK) == ID_REG_SIG) {
665
666 /* We seem to have the 82595 signature, let's
667 play with its counter (last 2 bits of
668 register 2 of bank 0) to be sure. */
669
670 counter = (id & R_ROBIN_BITS);
671 if (((id=inb(ioaddr+ID_REG)) & R_ROBIN_BITS) ==
672 (counter + 0x40)) {
673
674 /* Yes, the 82595 has been found */
675 printk(KERN_DEBUG " id: %#x ",id);
676 printk(" io: %#x ",ioaddr);
677
678 /* Initialize the device structure */
679 dev->priv = kmalloc(sizeof(struct eepro_local), GFP_KERNEL);
680 if (dev->priv == NULL)
681 return -ENOMEM;
682 memset(dev->priv, 0, sizeof(struct eepro_local));
683
684 lp = (struct eepro_local *)dev->priv;
685
686 /* Now, get the ethernet hardware address from
687 the EEPROM */
688
689 station_addr[0] = read_eeprom(ioaddr, 2, dev);
690
691 /* FIXME - find another way to know that we've found
692 * an Etherexpress 10
693 */
694 if (station_addr[0] == 0x0000 ||
695 station_addr[0] == 0xffff) {
696 eepro = 3;
697 lp->eepro = LAN595FX_10ISA;
698 eeprom_reg = EEPROM_REG_10;
699 rcv_start = RCV_START_10;
700 xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_10;
701 xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_10;
702
703 station_addr[0] = read_eeprom(ioaddr, 2, dev);
704 }
705
706 station_addr[1] = read_eeprom(ioaddr, 3, dev);
707 station_addr[2] = read_eeprom(ioaddr, 4, dev);
708
709 if (eepro) {
710 printk("%s: Intel EtherExpress 10 ISA\n at %#x,",
711 dev->name, ioaddr);
712 } else if (read_eeprom(ioaddr,7,dev)== ee_FX_INT2IRQ) {
713 /* int to IRQ Mask */
714 eepro = 2;
715 printk("%s: Intel EtherExpress Pro/10+ ISA\n at %#x,",
716 dev->name, ioaddr);
717 } else
718 if (station_addr[2] == 0x00aa) {
719 eepro = 1;
720 printk("%s: Intel EtherExpress Pro/10 ISA at %#x,",
721 dev->name, ioaddr);
722 }
723 else {
724 eepro = 0;
725 printk("%s: Intel 82595-based lan card at %#x,",
726 dev->name, ioaddr);
727 }
728
729 /* Fill in the 'dev' fields. */
730 dev->base_addr = ioaddr;
731
732 for (i=0; i < 6; i++) {
733 dev->dev_addr[i] = ((unsigned char *) station_addr)[5-i];
734 printk("%c%02x", i ? ':' : ' ', dev->dev_addr[i]);
735 }
736
737 dev->mem_start = (RCV_LOWER_LIMIT << 8);
738
739 if ((dev->mem_end & 0x3f) < 3 || /* RX buffer must be more than 3K */
740 (dev->mem_end & 0x3f) > 29) /* and less than 29K */
741 dev->mem_end = (RCV_UPPER_LIMIT << 8);
742 else {
743 dev->mem_end = (dev->mem_end * 1024) +
744 (RCV_LOWER_LIMIT << 8);
745 rcv_ram = dev->mem_end - (RCV_LOWER_LIMIT << 8);
746 }
747
748 /* From now on, dev->mem_end - dev->mem_start contains
749 * the actual size of rx buffer
750 */
751
752 if (net_debug > 3)
753 printk(", %dK RCV buffer", (int)(dev->mem_end -
754 dev->mem_start)/1024);
755
756
757 /* ............... */
758
759 if (GetBit( read_eeprom(ioaddr, 5, dev),ee_BNC_TPE))
760 dev->if_port = BNC;
761 else dev->if_port = TPE;
762
763 /* ............... */
764
765
766 if ((dev->irq < 2) && (eepro!=0)) {
767 i = read_eeprom(ioaddr, 1, dev);
768 irqMask = read_eeprom(ioaddr, 7, dev);
769 i &= 0x07; /* Mask off INT number */
770
771 for (j=0; ((j<16) && (i>=0)); j++) {
772 if ((irqMask & (1<<j))!=0) {
773 if (i==0) {
774 dev->irq = j;
775 break; /* found bit corresponding to irq */
776 }
777 i--; /* count bits set in irqMask */
778 }
779 }
780 if (dev->irq < 2) {
781 printk(" Duh! illegal interrupt vector stored in EEPROM.\n");
782 kfree(dev->priv);
783 return -ENODEV;
784 } else
785
786 if (dev->irq==2)
787 dev->irq = 9;
788 }
789
790 if (dev->irq > 2) {
791 printk(", IRQ %d, %s.\n", dev->irq,
792 ifmap[dev->if_port]);
793 }
794 else printk(", %s.\n", ifmap[dev->if_port]);
795
796 if ((dev->mem_start & 0xf) > 0) /* I don't know if this is */
797 net_debug = dev->mem_start & 7; /* still useful or not */
798
799 if (net_debug > 3) {
800 i = read_eeprom(ioaddr, 5, dev);
801 if (i & 0x2000) /* bit 13 of EEPROM word 5 */
802 printk(KERN_DEBUG "%s: Concurrent Processing is enabled but not used!\n",
803 dev->name);
804 }
805
806 if (net_debug)
807 printk(version);
808
809 /* Grab the region so we can find another board if autoIRQ fails. */
810 request_region(ioaddr, EEPRO_IO_EXTENT, dev->name);
811
812 ((struct eepro_local *)dev->priv)->lock = SPIN_LOCK_UNLOCKED;
813
814 dev->open = eepro_open;
815 dev->stop = eepro_close;
816 dev->hard_start_xmit = eepro_send_packet;
817 dev->get_stats = eepro_get_stats;
818 dev->set_multicast_list = &set_multicast_list;
819 dev->tx_timeout = eepro_tx_timeout;
820 dev->watchdog_timeo = TX_TIMEOUT;
821
822 /* Fill in the fields of the device structure with
823 ethernet generic values */
824
825 ether_setup(dev);
826
827 /* Check the station address for the manufacturer's code */
828 if (net_debug>3)
829 printEEPROMInfo(ioaddr, dev);
830
831 /* RESET the 82595 */
832 eepro_reset(ioaddr);
833
834 return 0;
835 }
836 else return -ENODEV;
837 }
838 else if (net_debug > 3)
839 printk ("EtherExpress Pro probed failed!\n");
840 return -ENODEV;
841 }
842
843 /* Open/initialize the board. This is called (in the current kernel)
844 sometime after booting when the 'ifconfig' program is run.
845
846 This routine should set everything up anew at each open, even
847 registers that "should" only need to be set once at boot, so that
848 there is non-reboot way to recover if something goes wrong.
849 */
850
851 static char irqrmap[] = {-1,-1,0,1,-1,2,-1,-1,-1,0,3,4,-1,-1,-1,-1};
852 static char irqrmap2[] = {-1,-1,4,0,1,2,-1,3,-1,4,5,6,7,-1,-1,-1};
853 static int eepro_grab_irq(struct net_device *dev)
854 {
855 int irqlist[] = { 3, 4, 5, 7, 9, 10, 11, 12, 0 };
856 int *irqp = irqlist, temp_reg, ioaddr = dev->base_addr;
857
858 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
859
860 /* Enable the interrupt line. */
861 eepro_en_intline(ioaddr);
862
863 /* be CAREFUL, BANK 0 now */
864 eepro_sw2bank0(ioaddr);
865
866 /* clear all interrupts */
867 eepro_clear_int(ioaddr);
868
869 /* Let EXEC event to interrupt */
870 eepro_en_intexec(ioaddr);
871
872 do {
873 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
874
875 temp_reg = inb(ioaddr + INT_NO_REG);
876 outb((temp_reg & 0xf8) | irqrmap[*irqp], ioaddr + INT_NO_REG);
877
878 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
879
880 if (request_irq (*irqp, NULL, 0, "bogus", dev) != EBUSY) {
881 /* Twinkle the interrupt, and check if it's seen */
882 autoirq_setup(0);
883
884 eepro_diag(ioaddr); /* RESET the 82595 */
885
886 if (*irqp == autoirq_report(2)) /* It's a good IRQ line */
887 break;
888
889 /* clear all interrupts */
890 eepro_clear_int(ioaddr);
891 }
892 } while (*++irqp);
893
894 eepro_sw2bank1(ioaddr); /* Switch back to Bank 1 */
895
896 /* Disable the physical interrupt line. */
897 eepro_dis_intline(ioaddr);
898
899 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
900
901 /* Mask all the interrupts. */
902 eepro_dis_int(ioaddr);
903
904 /* clear all interrupts */
905 eepro_clear_int(ioaddr);
906
907 return dev->irq;
908 }
909
910 static int eepro_open(struct net_device *dev)
911 {
912 unsigned short temp_reg, old8, old9;
913 int irqMask;
914 int i, ioaddr = dev->base_addr;
915 struct eepro_local *lp = (struct eepro_local *)dev->priv;
916
917 if (net_debug > 3)
918 printk(KERN_DEBUG "%s: entering eepro_open routine.\n", dev->name);
919
920 irqMask = read_eeprom(ioaddr,7,dev);
921
922 if (lp->eepro == LAN595FX_10ISA) {
923 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 3;\n");
924 }
925 else if (irqMask == ee_FX_INT2IRQ) /* INT to IRQ Mask */
926 {
927 lp->eepro = 2; /* Yes, an Intel EtherExpress Pro/10+ */
928 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 2;\n");
929 }
930
931 else if ((dev->dev_addr[0] == SA_ADDR0 &&
932 dev->dev_addr[1] == SA_ADDR1 &&
933 dev->dev_addr[2] == SA_ADDR2))
934 {
935 lp->eepro = 1;
936 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 1;\n");
937 } /* Yes, an Intel EtherExpress Pro/10 */
938
939 else lp->eepro = 0; /* No, it is a generic 82585 lan card */
940
941 /* Get the interrupt vector for the 82595 */
942 if (dev->irq < 2 && eepro_grab_irq(dev) == 0) {
943 printk("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
944 return -EAGAIN;
945 }
946
947 if (request_irq(dev->irq , &eepro_interrupt, 0, dev->name, dev)) {
948 printk("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
949 return -EAGAIN;
950 }
951
952 #ifdef irq2dev_map
953 if (((irq2dev_map[dev->irq] != 0)
954 || (irq2dev_map[dev->irq] = dev) == 0) &&
955 (irq2dev_map[dev->irq]!=dev)) {
956 /* printk("%s: IRQ map wrong\n", dev->name); */
957 free_irq(dev->irq, dev);
958 return -EAGAIN;
959 }
960 #endif
961
962 /* Initialize the 82595. */
963
964 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
965 temp_reg = inb(ioaddr + eeprom_reg);
966
967 lp->stepping = temp_reg >> 5; /* Get the stepping number of the 595 */
968
969 if (net_debug > 3)
970 printk(KERN_DEBUG "The stepping of the 82595 is %d\n", lp->stepping);
971
972 if (temp_reg & 0x10) /* Check the TurnOff Enable bit */
973 outb(temp_reg & 0xef, ioaddr + eeprom_reg);
974 for (i=0; i < 6; i++)
975 outb(dev->dev_addr[i] , ioaddr + I_ADD_REG0 + i);
976
977 temp_reg = inb(ioaddr + REG1); /* Setup Transmit Chaining */
978 outb(temp_reg | XMT_Chain_Int | XMT_Chain_ErrStop /* and discard bad RCV frames */
979 | RCV_Discard_BadFrame, ioaddr + REG1);
980
981 temp_reg = inb(ioaddr + REG2); /* Match broadcast */
982 outb(temp_reg | 0x14, ioaddr + REG2);
983
984 temp_reg = inb(ioaddr + REG3);
985 outb(temp_reg & 0x3f, ioaddr + REG3); /* clear test mode */
986
987 /* Set the receiving mode */
988 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
989
990 /* Set the interrupt vector */
991 temp_reg = inb(ioaddr + INT_NO_REG);
992 if (lp->eepro == 2 || lp->eepro == LAN595FX_10ISA)
993 outb((temp_reg & 0xf8) | irqrmap2[dev->irq], ioaddr + INT_NO_REG);
994 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
995
996
997 temp_reg = inb(ioaddr + INT_NO_REG);
998 if (lp->eepro == 2 || lp->eepro == LAN595FX_10ISA)
999 outb((temp_reg & 0xf0) | irqrmap2[dev->irq] | 0x08,ioaddr+INT_NO_REG);
1000 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
1001
1002 if (net_debug > 3)
1003 printk(KERN_DEBUG "eepro_open: content of INT Reg is %x\n", temp_reg);
1004
1005
1006 /* Initialize the RCV and XMT upper and lower limits */
1007 outb(RCV_LOWER_LIMIT, ioaddr + RCV_LOWER_LIMIT_REG);
1008 outb(RCV_UPPER_LIMIT, ioaddr + RCV_UPPER_LIMIT_REG);
1009 outb(XMT_LOWER_LIMIT, ioaddr + xmt_lower_limit_reg);
1010 outb(XMT_UPPER_LIMIT, ioaddr + xmt_upper_limit_reg);
1011
1012 /* Enable the interrupt line. */
1013 eepro_en_intline(ioaddr);
1014
1015 /* Switch back to Bank 0 */
1016 eepro_sw2bank0(ioaddr);
1017
1018 /* Let RX and TX events to interrupt */
1019 eepro_en_int(ioaddr);
1020
1021 /* clear all interrupts */
1022 eepro_clear_int(ioaddr);
1023
1024 /* Initialize RCV */
1025 outw(RCV_LOWER_LIMIT << 8, ioaddr + RCV_BAR);
1026 lp->rx_start = (RCV_LOWER_LIMIT << 8) ;
1027 outw((RCV_UPPER_LIMIT << 8) | 0xfe, ioaddr + RCV_STOP);
1028
1029 /* Initialize XMT */
1030 outw(XMT_LOWER_LIMIT << 8, ioaddr + xmt_bar);
1031
1032 /* Check for the i82595TX and i82595FX */
1033 old8 = inb(ioaddr + 8);
1034 outb(~old8, ioaddr + 8);
1035
1036 if ((temp_reg = inb(ioaddr + 8)) == old8) {
1037 if (net_debug > 3)
1038 printk(KERN_DEBUG "i82595 detected!\n");
1039 lp->version = LAN595;
1040 }
1041 else {
1042 lp->version = LAN595TX;
1043 outb(old8, ioaddr + 8);
1044 old9 = inb(ioaddr + 9);
1045 /*outb(~old9, ioaddr + 9);
1046 if (((temp_reg = inb(ioaddr + 9)) == ( (~old9)&0xff) )) {*/
1047
1048 if (irqMask==ee_FX_INT2IRQ) {
1049 enum iftype { AUI=0, BNC=1, TPE=2 };
1050
1051 if (net_debug > 3) {
1052 printk(KERN_DEBUG "IrqMask: %#x\n",irqMask);
1053 printk(KERN_DEBUG "i82595FX detected!\n");
1054 }
1055 lp->version = LAN595FX;
1056 outb(old9, ioaddr + 9);
1057 if (dev->if_port != TPE) { /* Hopefully, this will fix the
1058 problem of using Pentiums and
1059 pro/10 w/ BNC. */
1060 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1061 temp_reg = inb(ioaddr + REG13);
1062 /* disable the full duplex mode since it is not
1063 applicable with the 10Base2 cable. */
1064 outb(temp_reg & ~(FDX | A_N_ENABLE), REG13);
1065 eepro_sw2bank0(ioaddr); /* be CAREFUL, BANK 0 now */
1066 }
1067 }
1068 else if (net_debug > 3) {
1069 printk(KERN_DEBUG "temp_reg: %#x ~old9: %#x\n",temp_reg,((~old9)&0xff));
1070 printk(KERN_DEBUG "i82595TX detected!\n");
1071 }
1072 }
1073
1074 eepro_sel_reset(ioaddr);
1075 SLOW_DOWN;
1076 SLOW_DOWN;
1077
1078 lp->tx_start = lp->tx_end = XMT_LOWER_LIMIT << 8;
1079 lp->tx_last = 0;
1080
1081 netif_start_queue(dev);
1082
1083 if (net_debug > 3)
1084 printk(KERN_DEBUG "%s: exiting eepro_open routine.\n", dev->name);
1085
1086 /* enabling rx */
1087 eepro_en_rx(ioaddr);
1088
1089 return 0;
1090 }
1091
1092 static void eepro_tx_timeout (struct net_device *dev)
1093 {
1094 struct eepro_local *lp = (struct eepro_local *) dev->priv;
1095 int ioaddr = dev->base_addr;
1096
1097 /* if (net_debug > 1) */
1098 printk (KERN_ERR "%s: transmit timed out, %s?\n", dev->name,
1099 "network cable problem");
1100 /* This is not a duplicate. One message for the console,
1101 one for the the log file */
1102 printk (KERN_DEBUG "%s: transmit timed out, %s?\n", dev->name,
1103 "network cable problem");
1104 eepro_complete_selreset(ioaddr);
1105 }
1106
1107
1108 static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev)
1109 {
1110 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1111 unsigned long flags;
1112
1113 if (net_debug > 5)
1114 printk(KERN_DEBUG "%s: entering eepro_send_packet routine.\n", dev->name);
1115
1116 netif_stop_queue (dev);
1117
1118 spin_lock_irqsave(&lp->lock, flags);
1119
1120 {
1121 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1122 unsigned char *buf = skb->data;
1123
1124 lp->stats.tx_bytes+=skb->len;
1125
1126 hardware_send_packet(dev, buf, length);
1127
1128 dev->trans_start = jiffies;
1129
1130 }
1131
1132 dev_kfree_skb (skb);
1133
1134 /* You might need to clean up and record Tx statistics here. */
1135 /* lp->stats.tx_aborted_errors++; */
1136
1137 if (net_debug > 5)
1138 printk(KERN_DEBUG "%s: exiting eepro_send_packet routine.\n", dev->name);
1139
1140 spin_unlock_irqrestore(&lp->lock, flags);
1141
1142 return 0;
1143 }
1144
1145
1146 /* The typical workload of the driver:
1147 Handle the network interface interrupts. */
1148
1149 static void
1150 eepro_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1151 {
1152 struct net_device *dev = (struct net_device *)dev_id;
1153 /* (struct net_device *)(irq2dev_map[irq]);*/
1154 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1155 int ioaddr, status, boguscount = 20;
1156
1157 if (dev == NULL) {
1158 printk (KERN_ERR "eepro_interrupt(): irq %d for unknown device.\\n", irq);
1159 return;
1160 }
1161
1162 spin_lock(&lp->lock);
1163
1164 if (net_debug > 5)
1165 printk(KERN_DEBUG "%s: entering eepro_interrupt routine.\n", dev->name);
1166
1167 ioaddr = dev->base_addr;
1168
1169 while (((status = inb(ioaddr + STATUS_REG)) & 0x06) && (boguscount--))
1170 {
1171 switch (status & (RX_INT | TX_INT)) {
1172 #ifdef ANSWER_TX_AND_RX
1173 case (RX_INT | TX_INT):
1174 eepro_ack_rxtx(ioaddr);
1175 break;
1176 #endif
1177 case RX_INT:
1178 eepro_ack_rx(ioaddr);
1179 break;
1180 case TX_INT:
1181 eepro_ack_tx(ioaddr);
1182 break;
1183 }
1184 if (status & RX_INT) {
1185 if (net_debug > 4)
1186 printk(KERN_DEBUG "%s: packet received interrupt.\n", dev->name);
1187
1188 /* Get the received packets */
1189 eepro_rx(dev);
1190 #ifndef ANSWER_TX_AND_RX
1191 continue;
1192 #endif
1193 }
1194 if (status & TX_INT) {
1195 if (net_debug > 4)
1196 printk(KERN_DEBUG "%s: packet transmit interrupt.\n", dev->name);
1197
1198 /* Process the status of transmitted packets */
1199 eepro_transmit_interrupt(dev);
1200 }
1201 }
1202
1203 if (net_debug > 5)
1204 printk(KERN_DEBUG "%s: exiting eepro_interrupt routine.\n", dev->name);
1205
1206 spin_unlock(&lp->lock);
1207 return;
1208 }
1209
1210 static int eepro_close(struct net_device *dev)
1211 {
1212 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1213 int ioaddr = dev->base_addr;
1214 short temp_reg;
1215
1216 netif_stop_queue(dev);
1217
1218 eepro_sw2bank1(ioaddr); /* Switch back to Bank 1 */
1219
1220 /* Disable the physical interrupt line. */
1221 temp_reg = inb(ioaddr + REG1);
1222 outb(temp_reg & 0x7f, ioaddr + REG1);
1223
1224 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
1225
1226 /* Flush the Tx and disable Rx. */
1227 outb(STOP_RCV_CMD, ioaddr);
1228 lp->tx_start = lp->tx_end = (XMT_LOWER_LIMIT << 8);
1229 lp->tx_last = 0;
1230
1231 /* Mask all the interrupts. */
1232 eepro_dis_int(ioaddr);
1233
1234 /* clear all interrupts */
1235 eepro_clear_int(ioaddr);
1236
1237 /* Reset the 82595 */
1238 eepro_reset(ioaddr);
1239
1240 /* release the interrupt */
1241 free_irq(dev->irq, dev);
1242
1243 #ifdef irq2dev_map
1244 irq2dev_map[dev->irq] = 0;
1245 #endif
1246
1247 /* Update the statistics here. What statistics? */
1248
1249 return 0;
1250 }
1251
1252 /* Get the current statistics. This may be called with the card open or
1253 closed. */
1254 static struct net_device_stats *
1255 eepro_get_stats(struct net_device *dev)
1256 {
1257 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1258
1259 return &lp->stats;
1260 }
1261
1262 /* Set or clear the multicast filter for this adaptor.
1263 */
1264 static void
1265 set_multicast_list(struct net_device *dev)
1266 {
1267 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1268 short ioaddr = dev->base_addr;
1269 unsigned short mode;
1270 struct dev_mc_list *dmi=dev->mc_list;
1271
1272 if (dev->flags&(IFF_ALLMULTI|IFF_PROMISC) || dev->mc_count > 63)
1273 {
1274 /*
1275 * We must make the kernel realise we had to move
1276 * into promisc mode or we start all out war on
1277 * the cable. If it was a promisc request the
1278 * flag is already set. If not we assert it.
1279 */
1280 dev->flags|=IFF_PROMISC;
1281
1282 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1283 mode = inb(ioaddr + REG2);
1284 outb(mode | PRMSC_Mode, ioaddr + REG2);
1285 mode = inb(ioaddr + REG3);
1286 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1287 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1288 printk("%s: promiscuous mode enabled.\n", dev->name);
1289 }
1290
1291 else if (dev->mc_count==0 )
1292 {
1293 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1294 mode = inb(ioaddr + REG2);
1295 outb(mode & 0xd6, ioaddr + REG2); /* Turn off Multi-IA and PRMSC_Mode bits */
1296 mode = inb(ioaddr + REG3);
1297 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1298 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1299 }
1300
1301 else
1302 {
1303 unsigned short status, *eaddrs;
1304 int i, boguscount = 0;
1305
1306 /* Disable RX and TX interrupts. Necessary to avoid
1307 corruption of the HOST_ADDRESS_REG by interrupt
1308 service routines. */
1309 eepro_dis_int(ioaddr);
1310
1311 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1312 mode = inb(ioaddr + REG2);
1313 outb(mode | Multi_IA, ioaddr + REG2);
1314 mode = inb(ioaddr + REG3);
1315 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1316 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1317 outw(lp->tx_end, ioaddr + HOST_ADDRESS_REG);
1318 outw(MC_SETUP, ioaddr + IO_PORT);
1319 outw(0, ioaddr + IO_PORT);
1320 outw(0, ioaddr + IO_PORT);
1321 outw(6*(dev->mc_count + 1), ioaddr + IO_PORT);
1322
1323 for (i = 0; i < dev->mc_count; i++)
1324 {
1325 eaddrs=(unsigned short *)dmi->dmi_addr;
1326 dmi=dmi->next;
1327 outw(*eaddrs++, ioaddr + IO_PORT);
1328 outw(*eaddrs++, ioaddr + IO_PORT);
1329 outw(*eaddrs++, ioaddr + IO_PORT);
1330 }
1331
1332 eaddrs = (unsigned short *) dev->dev_addr;
1333 outw(eaddrs[0], ioaddr + IO_PORT);
1334 outw(eaddrs[1], ioaddr + IO_PORT);
1335 outw(eaddrs[2], ioaddr + IO_PORT);
1336 outw(lp->tx_end, ioaddr + xmt_bar);
1337 outb(MC_SETUP, ioaddr);
1338
1339 /* Update the transmit queue */
1340 i = lp->tx_end + XMT_HEADER + 6*(dev->mc_count + 1);
1341
1342 if (lp->tx_start != lp->tx_end)
1343 {
1344 /* update the next address and the chain bit in the
1345 last packet */
1346 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1347 outw(i, ioaddr + IO_PORT);
1348 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1349 status = inw(ioaddr + IO_PORT);
1350 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1351 lp->tx_end = i ;
1352 }
1353 else {
1354 lp->tx_start = lp->tx_end = i ;
1355 }
1356
1357 /* Acknowledge that the MC setup is done */
1358 do { /* We should be doing this in the eepro_interrupt()! */
1359 SLOW_DOWN;
1360 SLOW_DOWN;
1361 if (inb(ioaddr + STATUS_REG) & 0x08)
1362 {
1363 i = inb(ioaddr);
1364 outb(0x08, ioaddr + STATUS_REG);
1365
1366 if (i & 0x20) { /* command ABORTed */
1367 printk("%s: multicast setup failed.\n",
1368 dev->name);
1369 break;
1370 } else if ((i & 0x0f) == 0x03) { /* MC-Done */
1371 printk("%s: set Rx mode to %d address%s.\n",
1372 dev->name, dev->mc_count,
1373 dev->mc_count > 1 ? "es":"");
1374 break;
1375 }
1376 }
1377 } while (++boguscount < 100);
1378
1379 /* Re-enable RX and TX interrupts */
1380 eepro_en_int(ioaddr);
1381 }
1382 if (lp->eepro == LAN595FX_10ISA) {
1383 eepro_complete_selreset(ioaddr);
1384 }
1385 else
1386 eepro_en_rx(ioaddr);
1387 }
1388
1389 /* The horrible routine to read a word from the serial EEPROM. */
1390 /* IMPORTANT - the 82595 will be set to Bank 0 after the eeprom is read */
1391
1392 /* The delay between EEPROM clock transitions. */
1393 #define eeprom_delay() { udelay(40); }
1394 #define EE_READ_CMD (6 << 6)
1395
1396 int
1397 read_eeprom(int ioaddr, int location, struct net_device *dev)
1398 {
1399 int i;
1400 unsigned short retval = 0;
1401 short ee_addr = ioaddr + eeprom_reg;
1402 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1403 int read_cmd = location | EE_READ_CMD;
1404 short ctrl_val = EECS ;
1405
1406 /* XXXX - this is not the final version. We must test this on other
1407 * boards other than eepro10. I think that it won't let other
1408 * boards to fail. (aris)
1409 */
1410 if (lp->eepro == LAN595FX_10ISA) {
1411 eepro_sw2bank1(ioaddr);
1412 outb(0x00, ioaddr + STATUS_REG);
1413 }
1414
1415 eepro_sw2bank2(ioaddr);
1416 outb(ctrl_val, ee_addr);
1417
1418 /* Shift the read command bits out. */
1419 for (i = 8; i >= 0; i--) {
1420 short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI
1421 : ctrl_val;
1422 outb(outval, ee_addr);
1423 outb(outval | EESK, ee_addr); /* EEPROM clock tick. */
1424 eeprom_delay();
1425 outb(outval, ee_addr); /* Finish EEPROM a clock tick. */
1426 eeprom_delay();
1427 }
1428 outb(ctrl_val, ee_addr);
1429
1430 for (i = 16; i > 0; i--) {
1431 outb(ctrl_val | EESK, ee_addr); eeprom_delay();
1432 retval = (retval << 1) | ((inb(ee_addr) & EEDO) ? 1 : 0);
1433 outb(ctrl_val, ee_addr); eeprom_delay();
1434 }
1435
1436 /* Terminate the EEPROM access. */
1437 ctrl_val &= ~EECS;
1438 outb(ctrl_val | EESK, ee_addr);
1439 eeprom_delay();
1440 outb(ctrl_val, ee_addr);
1441 eeprom_delay();
1442 eepro_sw2bank0(ioaddr);
1443 return retval;
1444 }
1445
1446 static void
1447 hardware_send_packet(struct net_device *dev, void *buf, short length)
1448 {
1449 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1450 short ioaddr = dev->base_addr;
1451 unsigned status, tx_available, last, end, boguscount = 100;
1452
1453 if (net_debug > 5)
1454 printk(KERN_DEBUG "%s: entering hardware_send_packet routine.\n", dev->name);
1455
1456 while (boguscount-- > 0) {
1457
1458 /* Disable RX and TX interrupts. Necessary to avoid
1459 corruption of the HOST_ADDRESS_REG by interrupt
1460 service routines. */
1461 eepro_dis_int(ioaddr);
1462
1463 /* determine how much of the transmit buffer space is available */
1464 if (lp->tx_end > lp->tx_start)
1465 tx_available = XMT_RAM - (lp->tx_end - lp->tx_start);
1466 else if (lp->tx_end < lp->tx_start)
1467 tx_available = lp->tx_start - lp->tx_end;
1468 else tx_available = XMT_RAM;
1469
1470 if (((((length + 3) >> 1) << 1) + 2*XMT_HEADER)
1471 >= tx_available) /* No space available ??? */
1472 {
1473 eepro_transmit_interrupt(dev); /* Clean up the transmiting queue */
1474
1475 /* Enable RX and TX interrupts */
1476 eepro_en_int(ioaddr);
1477 continue;
1478 }
1479
1480 last = lp->tx_end;
1481 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1482
1483 if (end >= (XMT_UPPER_LIMIT << 8)) { /* the transmit buffer is wrapped around */
1484 if (((XMT_UPPER_LIMIT << 8) - last) <= XMT_HEADER) {
1485 /* Arrrr!!!, must keep the xmt header together,
1486 several days were lost to chase this one down. */
1487
1488 last = (XMT_LOWER_LIMIT << 8);
1489 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1490 }
1491
1492 else end = (XMT_LOWER_LIMIT << 8) + (end -
1493 (XMT_UPPER_LIMIT <<8));
1494 }
1495 outw(last, ioaddr + HOST_ADDRESS_REG);
1496 outw(XMT_CMD, ioaddr + IO_PORT);
1497 outw(0, ioaddr + IO_PORT);
1498 outw(end, ioaddr + IO_PORT);
1499 outw(length, ioaddr + IO_PORT);
1500
1501 if (lp->version == LAN595)
1502 outsw(ioaddr + IO_PORT, buf, (length + 3) >> 1);
1503 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1504 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1505 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1506 outsl(ioaddr + IO_PORT_32_BIT, buf, (length + 3) >> 2);
1507 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1508 }
1509
1510 /* A dummy read to flush the DRAM write pipeline */
1511 status = inw(ioaddr + IO_PORT);
1512
1513 if (lp->tx_start == lp->tx_end) {
1514 outw(last, ioaddr + xmt_bar);
1515 outb(XMT_CMD, ioaddr);
1516 lp->tx_start = last; /* I don't like to change tx_start here */
1517 }
1518 else {
1519 /* update the next address and the chain bit in the
1520 last packet */
1521
1522 if (lp->tx_end != last) {
1523 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1524 outw(last, ioaddr + IO_PORT);
1525 }
1526
1527 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1528 status = inw(ioaddr + IO_PORT);
1529 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1530
1531 /* Continue the transmit command */
1532 outb(RESUME_XMT_CMD, ioaddr);
1533 }
1534
1535 lp->tx_last = last;
1536 lp->tx_end = end;
1537
1538 if (netif_queue_stopped(dev))
1539 netif_wake_queue(dev);
1540
1541 /* now we are serializing tx. queue won't come back until
1542 * the tx interrupt
1543 */
1544 if (lp->eepro == LAN595FX_10ISA)
1545 netif_stop_queue(dev);
1546
1547 /* Enable RX and TX interrupts */
1548 eepro_en_int(ioaddr);
1549
1550 if (net_debug > 5)
1551 printk(KERN_DEBUG "%s: exiting hardware_send_packet routine.\n", dev->name);
1552 return;
1553 }
1554 if (lp->eepro == LAN595FX_10ISA)
1555 netif_stop_queue(dev);
1556
1557 if (net_debug > 5)
1558 printk(KERN_DEBUG "%s: exiting hardware_send_packet routine.\n", dev->name);
1559 }
1560
1561 static void
1562 eepro_rx(struct net_device *dev)
1563 {
1564 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1565 short ioaddr = dev->base_addr;
1566 short boguscount = 20;
1567 unsigned rcv_car = lp->rx_start;
1568 unsigned rcv_event, rcv_status, rcv_next_frame, rcv_size;
1569
1570 if (net_debug > 5)
1571 printk(KERN_DEBUG "%s: entering eepro_rx routine.\n", dev->name);
1572
1573 /* Set the read pointer to the start of the RCV */
1574 outw(rcv_car, ioaddr + HOST_ADDRESS_REG);
1575
1576 rcv_event = inw(ioaddr + IO_PORT);
1577
1578 while (rcv_event == RCV_DONE) {
1579
1580 rcv_status = inw(ioaddr + IO_PORT);
1581 rcv_next_frame = inw(ioaddr + IO_PORT);
1582 rcv_size = inw(ioaddr + IO_PORT);
1583
1584 if ((rcv_status & (RX_OK | RX_ERROR)) == RX_OK) {
1585
1586 /* Malloc up new buffer. */
1587 struct sk_buff *skb;
1588
1589 lp->stats.rx_bytes+=rcv_size;
1590 rcv_size &= 0x3fff;
1591 skb = dev_alloc_skb(rcv_size+5);
1592 if (skb == NULL) {
1593 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
1594 lp->stats.rx_dropped++;
1595 break;
1596 }
1597 skb->dev = dev;
1598 skb_reserve(skb,2);
1599
1600 if (lp->version == LAN595)
1601 insw(ioaddr+IO_PORT, skb_put(skb,rcv_size), (rcv_size + 3) >> 1);
1602 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1603 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1604 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1605 insl(ioaddr+IO_PORT_32_BIT, skb_put(skb,rcv_size),
1606 (rcv_size + 3) >> 2);
1607 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1608 }
1609
1610 skb->protocol = eth_type_trans(skb,dev);
1611 netif_rx(skb);
1612 dev->last_rx = jiffies;
1613 lp->stats.rx_packets++;
1614 }
1615
1616 else { /* Not sure will ever reach here,
1617 I set the 595 to discard bad received frames */
1618 lp->stats.rx_errors++;
1619
1620 if (rcv_status & 0x0100)
1621 lp->stats.rx_over_errors++;
1622
1623 else if (rcv_status & 0x0400)
1624 lp->stats.rx_frame_errors++;
1625
1626 else if (rcv_status & 0x0800)
1627 lp->stats.rx_crc_errors++;
1628
1629 printk("%s: event = %#x, status = %#x, next = %#x, size = %#x\n",
1630 dev->name, rcv_event, rcv_status, rcv_next_frame, rcv_size);
1631 }
1632
1633 if (rcv_status & 0x1000)
1634 lp->stats.rx_length_errors++;
1635
1636 if (--boguscount == 0)
1637 break;
1638
1639 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1640 lp->rx_start = rcv_next_frame;
1641 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1642 rcv_event = inw(ioaddr + IO_PORT);
1643
1644 }
1645 if (rcv_car == 0)
1646 rcv_car = (RCV_UPPER_LIMIT << 8) | 0xff;
1647
1648 outw(rcv_car - 1, ioaddr + RCV_STOP);
1649
1650 if (net_debug > 5)
1651 printk(KERN_DEBUG "%s: exiting eepro_rx routine.\n", dev->name);
1652 }
1653
1654 static void
1655 eepro_transmit_interrupt(struct net_device *dev)
1656 {
1657 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1658 short ioaddr = dev->base_addr;
1659 short boguscount = 20;
1660 unsigned xmt_status;
1661
1662 /*
1663 if (dev->tbusy == 0) {
1664 printk("%s: transmit_interrupt called with tbusy = 0 ??\n",
1665 dev->name);
1666 printk(KERN_DEBUG "%s: transmit_interrupt called with tbusy = 0 ??\n",
1667 dev->name);
1668 }
1669 */
1670 while (lp->tx_start != lp->tx_end && boguscount) {
1671
1672 outw(lp->tx_start, ioaddr + HOST_ADDRESS_REG);
1673 xmt_status = inw(ioaddr+IO_PORT);
1674
1675 if ((xmt_status & TX_DONE_BIT) == 0) {
1676 if (lp->eepro == LAN595FX_10ISA) {
1677 udelay(40);
1678 boguscount--;
1679 continue;
1680 }
1681 else
1682 break;
1683 }
1684
1685 xmt_status = inw(ioaddr+IO_PORT);
1686 lp->tx_start = inw(ioaddr+IO_PORT);
1687
1688 if (lp->eepro == LAN595FX_10ISA) {
1689 lp->tx_start = (XMT_LOWER_LIMIT << 8);
1690 lp->tx_end = lp->tx_start;
1691
1692 /* yeah, black magic :( */
1693 eepro_sw2bank0(ioaddr);
1694 eepro_en_int(ioaddr);
1695
1696 /* disabling rx */
1697 eepro_dis_rx(ioaddr);
1698
1699 /* enabling rx */
1700 eepro_en_rx(ioaddr);
1701 }
1702
1703 netif_wake_queue (dev);
1704
1705 if (xmt_status & 0x2000)
1706 lp->stats.tx_packets++;
1707 else {
1708 lp->stats.tx_errors++;
1709 if (xmt_status & 0x0400) {
1710 lp->stats.tx_carrier_errors++;
1711 printk(KERN_DEBUG "%s: carrier error\n",
1712 dev->name);
1713 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1714 dev->name, xmt_status);
1715 }
1716 else {
1717 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1718 dev->name, xmt_status);
1719 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1720 dev->name, xmt_status);
1721 }
1722 if (lp->eepro == LAN595FX_10ISA) {
1723 /* Try to restart the adaptor. */
1724 /* We are supposed to wait for 2 us after a SEL_RESET */
1725 eepro_sel_reset(ioaddr);
1726
1727 /* first enable interrupts */
1728 eepro_sw2bank0(ioaddr);
1729 outb(ALL_MASK & ~(RX_INT | TX_INT), ioaddr + STATUS_REG);
1730
1731 /* enabling rx */
1732 eepro_en_rx(ioaddr);
1733 }
1734 }
1735 if (xmt_status & 0x000f) {
1736 lp->stats.collisions += (xmt_status & 0x000f);
1737 }
1738
1739 if ((xmt_status & 0x0040) == 0x0) {
1740 lp->stats.tx_heartbeat_errors++;
1741 }
1742
1743 boguscount--;
1744 }
1745 /* if it reached here then it's probable that the adapter won't
1746 * interrupt again for tx. in other words: tx timeout what will take
1747 * a lot of time to happen, so we'll do a complete selreset.
1748 */
1749 if (!boguscount && lp->eepro == LAN595FX_10ISA)
1750 eepro_complete_selreset(ioaddr);
1751 }
1752
1753 #ifdef MODULE
1754
1755 #define MAX_EEPRO 8
1756 static struct net_device dev_eepro[MAX_EEPRO];
1757
1758 static int io[MAX_EEPRO];
1759 static int irq[MAX_EEPRO];
1760 static int mem[MAX_EEPRO] = { /* Size of the rx buffer in KB */
1761 [0 ... MAX_EEPRO-1] = RCV_DEFAULT_RAM/1024
1762 };
1763 static int autodetect;
1764
1765 static int n_eepro;
1766 /* For linux 2.1.xx */
1767
1768 MODULE_AUTHOR("Pascal Dupuis <dupuis@lei.ucl.ac.be> for the 2.1 stuff (locking,...)");
1769 MODULE_DESCRIPTION("Intel i82595 ISA EtherExpressPro10/10+ driver");
1770 MODULE_PARM(io, "1-" __MODULE_STRING(MAX_EEPRO) "i");
1771 MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_EEPRO) "i");
1772 MODULE_PARM(mem, "1-" __MODULE_STRING(MAX_EEPRO) "i");
1773 MODULE_PARM(autodetect, "1-" __MODULE_STRING(1) "i");
1774 MODULE_PARM_DESC(io, "EtherExpress Pro/10 I/O base addres(es)");
1775 MODULE_PARM_DESC(irq, "EtherExpress Pro/10 IRQ number(s)");
1776 MODULE_PARM_DESC(mem, "EtherExpress Pro/10 Rx buffer size(es) in kB (3-29)");
1777 MODULE_PARM_DESC(autodetect, "EtherExpress Pro/10 force board(s) detection (0-1)");
1778
1779 int
1780 init_module(void)
1781 {
1782 int i;
1783 if (io[0] == 0 && autodetect == 0) {
1784 printk("eepro_init_module: Probe is very dangerous in ISA boards!\n");
1785 printk("eepro_init_module: Please add \"autodetect=1\" to force probe\n");
1786 return 1;
1787 }
1788 else if (autodetect) {
1789 /* if autodetect is set then we must force detection */
1790 io[0] = 0;
1791
1792 printk("eepro_init_module: Auto-detecting boards (May God protect us...)\n");
1793 }
1794
1795 for (i = 0; i < MAX_EEPRO; i++) {
1796 struct net_device *d = &dev_eepro[n_eepro];
1797 d->mem_end = mem[n_eepro];
1798 d->base_addr = io[0];
1799 d->irq = irq[n_eepro];
1800 d->init = eepro_probe;
1801
1802 if (register_netdev(d) == 0)
1803 n_eepro++;
1804 else
1805 break;
1806 }
1807
1808 return n_eepro ? 0 : -ENODEV;
1809 }
1810
1811 void
1812 cleanup_module(void)
1813 {
1814 int i;
1815
1816 for (i=0; i<n_eepro; i++) {
1817 struct net_device *d = &dev_eepro[i];
1818 unregister_netdev(d);
1819
1820 kfree(d->priv);
1821 d->priv=NULL;
1822
1823 /* If we don't do this, we can't re-insmod it later. */
1824 release_region(d->base_addr, EEPRO_IO_EXTENT);
1825
1826 }
1827 }
1828 #endif /* MODULE */
1829