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