Import 2.3.18pre1
[davej-history.git] / drivers / net / eepro.c
blobf436802eb65a58261fe46af0d2a329fa5462f9db
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.11e some tweaks about multiple cards support (PdP, jul/aug 1999)
27 0.11d added __initdata, __init stuff; call spin_lock_init
28 in eepro_probe1. Replaced "eepro" by dev->name. Augmented
29 the code protected by spin_lock in interrupt routine
30 (PdP, 12/12/1998)
31 0.11c minor cleanup (PdP, RMC, 09/12/1998)
32 0.11b Pascal Dupuis (dupuis@lei.ucl.ac.be): works as a module
33 under 2.1.xx. Debug messages are flagged as KERN_DEBUG to
34 avoid console flooding. Added locking at critical parts. Now
35 the dawn thing is SMP safe.
36 0.11a Attempt to get 2.1.xx support up (RMC)
37 0.11 Brian Candler added support for multiple cards. Tested as
38 a module, no idea if it works when compiled into kernel.
40 0.10e Rick Bressler notified me that ifconfig up;ifconfig down fails
41 because the irq is lost somewhere. Fixed that by moving
42 request_irq and free_irq to eepro_open and eepro_close respectively.
43 0.10d Ugh! Now Wakeup works. Was seriously broken in my first attempt.
44 I'll need to find a way to specify an ioport other than
45 the default one in the PnP case. PnP definitively sucks.
46 And, yes, this is not the only reason.
47 0.10c PnP Wakeup Test for 595FX. uncomment #define PnPWakeup;
48 to use.
49 0.10b Should work now with (some) Pro/10+. At least for
50 me (and my two cards) it does. _No_ guarantee for
51 function with non-Pro/10+ cards! (don't have any)
52 (RMC, 9/11/96)
54 0.10 Added support for the Etherexpress Pro/10+. The
55 IRQ map was changed significantly from the old
56 pro/10. The new interrupt map was provided by
57 Rainer M. Canavan (Canavan@Zeus.cs.bonn.edu).
58 (BCH, 9/3/96)
60 0.09 Fixed a race condition in the transmit algorithm,
61 which causes crashes under heavy load with fast
62 pentium computers. The performance should also
63 improve a bit. The size of RX buffer, and hence
64 TX buffer, can also be changed via lilo or insmod.
65 (BCH, 7/31/96)
67 0.08 Implement 32-bit I/O for the 82595TX and 82595FX
68 based lan cards. Disable full-duplex mode if TPE
69 is not used. (BCH, 4/8/96)
71 0.07a Fix a stat report which counts every packet as a
72 heart-beat failure. (BCH, 6/3/95)
74 0.07 Modified to support all other 82595-based lan cards.
75 The IRQ vector of the EtherExpress Pro will be set
76 according to the value saved in the EEPROM. For other
77 cards, I will do autoirq_request() to grab the next
78 available interrupt vector. (BCH, 3/17/95)
80 0.06a,b Interim released. Minor changes in the comments and
81 print out format. (BCH, 3/9/95 and 3/14/95)
83 0.06 First stable release that I am comfortable with. (BCH,
84 3/2/95)
86 0.05 Complete testing of multicast. (BCH, 2/23/95)
88 0.04 Adding multicast support. (BCH, 2/14/95)
90 0.03 First widely alpha release for public testing.
91 (BCH, 2/14/95)
95 static const char *version =
96 "eepro.c: v0.11d 08/12/1998 dupuis@lei.ucl.ac.be\n";
98 #include <linux/module.h>
101 Sources:
103 This driver wouldn't have been written without the availability
104 of the Crynwr's Lan595 driver source code. It helps me to
105 familiarize with the 82595 chipset while waiting for the Intel
106 documentation. I also learned how to detect the 82595 using
107 the packet driver's technique.
109 This driver is written by cutting and pasting the skeleton.c driver
110 provided by Donald Becker. I also borrowed the EEPROM routine from
111 Donald Becker's 82586 driver.
113 Datasheet for the Intel 82595 (including the TX and FX version). It
114 provides just enough info that the casual reader might think that it
115 documents the i82595.
117 The User Manual for the 82595. It provides a lot of the missing
118 information.
122 #include <linux/kernel.h>
123 #include <linux/sched.h>
124 #include <linux/types.h>
125 #include <linux/fcntl.h>
126 #include <linux/interrupt.h>
127 #include <linux/ptrace.h>
128 #include <linux/ioport.h>
129 #include <linux/in.h>
130 #include <linux/malloc.h>
131 #include <linux/string.h>
132 #include <asm/system.h>
133 #include <asm/bitops.h>
134 #include <asm/io.h>
135 #include <asm/dma.h>
136 #include <linux/errno.h>
138 #include <linux/netdevice.h>
139 #include <linux/etherdevice.h>
140 #include <linux/skbuff.h>
143 /* need to remove these asap */
144 /* 2.1.xx compatibility macros... */
145 /* */
148 #include <linux/version.h>
150 /* For linux 2.1.xx */
151 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
153 #include <linux/spinlock.h>
154 #include <linux/init.h>
155 #include <linux/delay.h>
157 #define compat_dev_kfree_skb( skb, mode ) dev_kfree_skb( (skb) )
158 /* I had reports of looong delays with SLOW_DOWN defined as udelay(2) */
159 #define SLOW_DOWN inb(0x80)
160 /* udelay(2) */
161 #define compat_init_data __initdata
163 #else
164 /* for 2.x */
166 #define compat_dev_kfree_skb( skb, mode ) dev_kfree_skb( (skb), (mode) )
167 #define test_and_set_bit(a,b) set_bit((a),(b))
168 #define SLOW_DOWN SLOW_DOWN_IO
169 #define compat_init_data
171 #endif
174 /* First, a few definitions that the brave might change. */
175 /* A zero-terminated list of I/O addresses to be probed. */
176 static unsigned int eepro_portlist[] compat_init_data =
177 { 0x300, 0x210, 0x240, 0x280, 0x2C0, 0x200, 0x320, 0x340, 0x360, 0};
178 /* note: 0x300 is default, the 595FX supports ALL IO Ports
179 from 0x000 to 0x3F0, some of which are reserved in PCs */
181 /* To try the (not-really PnP Wakeup: */
183 #define PnPWakeup
186 /* use 0 for production, 1 for verification, >2 for debug */
187 #ifndef NET_DEBUG
188 #define NET_DEBUG 0
189 #endif
190 static unsigned int net_debug = NET_DEBUG;
192 /* The number of low I/O ports used by the ethercard. */
193 #define EEPRO_IO_EXTENT 16
195 /* Different 82595 chips */
196 #define LAN595 0
197 #define LAN595TX 1
198 #define LAN595FX 2
200 /* Information that need to be kept for each board. */
201 struct eepro_local {
202 struct enet_statistics stats;
203 unsigned rx_start;
204 unsigned tx_start; /* start of the transmit chain */
205 int tx_last; /* pointer to last packet in the transmit chain */
206 unsigned tx_end; /* end of the transmit chain (plus 1) */
207 int eepro; /* 1 for the EtherExpress Pro/10,
208 2 for the EtherExpress Pro/10+,
209 0 for other 82595-based lan cards. */
210 int version; /* a flag to indicate if this is a TX or FX
211 version of the 82595 chip. */
212 int stepping;
213 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
214 spinlock_t lock; /* Serializing lock */
215 #endif
218 /* The station (ethernet) address prefix, used for IDing the board. */
219 #define SA_ADDR0 0x00 /* Etherexpress Pro/10 */
220 #define SA_ADDR1 0xaa
221 #define SA_ADDR2 0x00
223 #define GetBit(x,y) ((x & (1<<y))>>y)
225 /* EEPROM Word 0: */
226 #define ee_PnP 0 /* Plug 'n Play enable bit */
227 #define ee_Word1 1 /* Word 1? */
228 #define ee_BusWidth 2 /* 8/16 bit */
229 #define ee_FlashAddr 3 /* Flash Address */
230 #define ee_FlashMask 0x7 /* Mask */
231 #define ee_AutoIO 6 /* */
232 #define ee_reserved0 7 /* =0! */
233 #define ee_Flash 8 /* Flash there? */
234 #define ee_AutoNeg 9 /* Auto Negotiation enabled? */
235 #define ee_IO0 10 /* IO Address LSB */
236 #define ee_IO0Mask 0x /*...*/
237 #define ee_IO1 15 /* IO MSB */
239 /* EEPROM Word 1: */
240 #define ee_IntSel 0 /* Interrupt */
241 #define ee_IntMask 0x7
242 #define ee_LI 3 /* Link Integrity 0= enabled */
243 #define ee_PC 4 /* Polarity Correction 0= enabled */
244 #define ee_TPE_AUI 5 /* PortSelection 1=TPE */
245 #define ee_Jabber 6 /* Jabber prevention 0= enabled */
246 #define ee_AutoPort 7 /* Auto Port Selection 1= Disabled */
247 #define ee_SMOUT 8 /* SMout Pin Control 0= Input */
248 #define ee_PROM 9 /* Flash EPROM / PROM 0=Flash */
249 #define ee_reserved1 10 /* .. 12 =0! */
250 #define ee_AltReady 13 /* Alternate Ready, 0=normal */
251 #define ee_reserved2 14 /* =0! */
252 #define ee_Duplex 15
254 /* Word2,3,4: */
255 #define ee_IA5 0 /*bit start for individual Addr Byte 5 */
256 #define ee_IA4 8 /*bit start for individual Addr Byte 5 */
257 #define ee_IA3 0 /*bit start for individual Addr Byte 5 */
258 #define ee_IA2 8 /*bit start for individual Addr Byte 5 */
259 #define ee_IA1 0 /*bit start for individual Addr Byte 5 */
260 #define ee_IA0 8 /*bit start for individual Addr Byte 5 */
262 /* Word 5: */
263 #define ee_BNC_TPE 0 /* 0=TPE */
264 #define ee_BootType 1 /* 00=None, 01=IPX, 10=ODI, 11=NDIS */
265 #define ee_BootTypeMask 0x3
266 #define ee_NumConn 3 /* Number of Connections 0= One or Two */
267 #define ee_FlashSock 4 /* Presence of Flash Socket 0= Present */
268 #define ee_PortTPE 5
269 #define ee_PortBNC 6
270 #define ee_PortAUI 7
271 #define ee_PowerMgt 10 /* 0= disabled */
272 #define ee_CP 13 /* Concurrent Processing */
273 #define ee_CPMask 0x7
275 /* Word 6: */
276 #define ee_Stepping 0 /* Stepping info */
277 #define ee_StepMask 0x0F
278 #define ee_BoardID 4 /* Manucaturer Board ID, reserved */
279 #define ee_BoardMask 0x0FFF
281 /* Word 7: */
282 #define ee_INT_TO_IRQ 0 /* int to IRQ Mapping = 0x1EB8 for Pro/10+ */
283 #define ee_FX_INT2IRQ 0x1EB8 /* the _only_ mapping allowed for FX chips */
285 /*..*/
286 #define ee_SIZE 0x40 /* total EEprom Size */
287 #define ee_Checksum 0xBABA /* initial and final value for adding checksum */
290 /* Card identification via EEprom: */
291 #define ee_addr_vendor 0x10 /* Word offset for EISA Vendor ID */
292 #define ee_addr_id 0x11 /* Word offset for Card ID */
293 #define ee_addr_SN 0x12 /* Serial Number */
294 #define ee_addr_CRC_8 0x14 /* CRC over last thee Bytes */
297 #define ee_vendor_intel0 0x25 /* Vendor ID Intel */
298 #define ee_vendor_intel1 0xD4
299 #define ee_id_eepro10p0 0x10 /* ID for eepro/10+ */
300 #define ee_id_eepro10p1 0x31
303 /* Index to functions, as function prototypes. */
305 extern int eepro_probe(struct net_device *dev);
307 static int eepro_probe1(struct net_device *dev, short ioaddr);
308 static int eepro_open(struct net_device *dev);
309 static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev);
310 static void eepro_interrupt(int irq, void *dev_id, struct pt_regs *regs);
311 static void eepro_rx(struct net_device *dev);
312 static void eepro_transmit_interrupt(struct net_device *dev);
313 static int eepro_close(struct net_device *dev);
314 static struct enet_statistics *eepro_get_stats(struct net_device *dev);
315 static void set_multicast_list(struct net_device *dev);
317 static int read_eeprom(int ioaddr, int location);
318 static void hardware_send_packet(struct net_device *dev, void *buf, short length);
319 static int eepro_grab_irq(struct net_device *dev);
322 Details of the i82595.
324 You will need either the datasheet or the user manual to understand what
325 is going on here. The 82595 is very different from the 82586, 82593.
327 The receive algorithm in eepro_rx() is just an implementation of the
328 RCV ring structure that the Intel 82595 imposes at the hardware level.
329 The receive buffer is set at 24K, and the transmit buffer is 8K. I
330 am assuming that the total buffer memory is 32K, which is true for the
331 Intel EtherExpress Pro/10. If it is less than that on a generic card,
332 the driver will be broken.
334 The transmit algorithm in the hardware_send_packet() is similar to the
335 one in the eepro_rx(). The transmit buffer is a ring linked list.
336 I just queue the next available packet to the end of the list. In my
337 system, the 82595 is so fast that the list seems to always contain a
338 single packet. In other systems with faster computers and more congested
339 network traffics, the ring linked list should improve performance by
340 allowing up to 8K worth of packets to be queued.
342 The sizes of the receive and transmit buffers can now be changed via lilo
343 or insmod. Lilo uses the appended line "ether=io,irq,debug,rx-buffer,eth0"
344 where rx-buffer is in KB unit. Modules uses the parameter mem which is
345 also in KB unit, for example "insmod io=io-address irq=0 mem=rx-buffer."
346 The receive buffer has to be more than 3K or less than 29K. Otherwise,
347 it is reset to the default of 24K, and, hence, 8K for the trasnmit
348 buffer (transmit-buffer = 32K - receive-buffer).
351 #define RAM_SIZE 0x8000
352 #define RCV_HEADER 8
353 #define RCV_RAM 0x6000 /* 24KB default for RCV buffer */
354 #define RCV_LOWER_LIMIT 0x00 /* 0x0000 */
355 /* #define RCV_UPPER_LIMIT ((RCV_RAM - 2) >> 8) */ /* 0x5ffe */
356 #define RCV_UPPER_LIMIT (((rcv_ram) - 2) >> 8)
357 /* #define XMT_RAM (RAM_SIZE - RCV_RAM) */ /* 8KB for XMT buffer */
358 #define XMT_RAM (RAM_SIZE - (rcv_ram)) /* 8KB for XMT buffer */
359 /* #define XMT_LOWER_LIMIT (RCV_RAM >> 8) */ /* 0x6000 */
360 #define XMT_LOWER_LIMIT ((rcv_ram) >> 8)
361 #define XMT_UPPER_LIMIT ((RAM_SIZE - 2) >> 8) /* 0x7ffe */
362 #define XMT_HEADER 8
364 #define RCV_DONE 0x0008
365 #define RX_OK 0x2000
366 #define RX_ERROR 0x0d81
368 #define TX_DONE_BIT 0x0080
369 #define CHAIN_BIT 0x8000
370 #define XMT_STATUS 0x02
371 #define XMT_CHAIN 0x04
372 #define XMT_COUNT 0x06
374 #define BANK0_SELECT 0x00
375 #define BANK1_SELECT 0x40
376 #define BANK2_SELECT 0x80
378 /* Bank 0 registers */
379 #define COMMAND_REG 0x00 /* Register 0 */
380 #define MC_SETUP 0x03
381 #define XMT_CMD 0x04
382 #define DIAGNOSE_CMD 0x07
383 #define RCV_ENABLE_CMD 0x08
384 #define RCV_DISABLE_CMD 0x0a
385 #define STOP_RCV_CMD 0x0b
386 #define RESET_CMD 0x0e
387 #define POWER_DOWN_CMD 0x18
388 #define RESUME_XMT_CMD 0x1c
389 #define SEL_RESET_CMD 0x1e
390 #define STATUS_REG 0x01 /* Register 1 */
391 #define RX_INT 0x02
392 #define TX_INT 0x04
393 #define EXEC_STATUS 0x30
394 #define ID_REG 0x02 /* Register 2 */
395 #define R_ROBIN_BITS 0xc0 /* round robin counter */
396 #define ID_REG_MASK 0x2c
397 #define ID_REG_SIG 0x24
398 #define AUTO_ENABLE 0x10
399 #define INT_MASK_REG 0x03 /* Register 3 */
400 #define RX_STOP_MASK 0x01
401 #define RX_MASK 0x02
402 #define TX_MASK 0x04
403 #define EXEC_MASK 0x08
404 #define ALL_MASK 0x0f
405 #define IO_32_BIT 0x10
406 #define RCV_BAR 0x04 /* The following are word (16-bit) registers */
407 #define RCV_STOP 0x06
408 #define XMT_BAR 0x0a
409 #define HOST_ADDRESS_REG 0x0c
410 #define IO_PORT 0x0e
411 #define IO_PORT_32_BIT 0x0c
413 /* Bank 1 registers */
414 #define REG1 0x01
415 #define WORD_WIDTH 0x02
416 #define INT_ENABLE 0x80
417 #define INT_NO_REG 0x02
418 #define RCV_LOWER_LIMIT_REG 0x08
419 #define RCV_UPPER_LIMIT_REG 0x09
420 #define XMT_LOWER_LIMIT_REG 0x0a
421 #define XMT_UPPER_LIMIT_REG 0x0b
423 /* Bank 2 registers */
424 #define XMT_Chain_Int 0x20 /* Interrupt at the end of the transmit chain */
425 #define XMT_Chain_ErrStop 0x40 /* Interrupt at the end of the chain even if there are errors */
426 #define RCV_Discard_BadFrame 0x80 /* Throw bad frames away, and continue to receive others */
427 #define REG2 0x02
428 #define PRMSC_Mode 0x01
429 #define Multi_IA 0x20
430 #define REG3 0x03
431 #define TPE_BIT 0x04
432 #define BNC_BIT 0x20
433 #define REG13 0x0d
434 #define FDX 0x00
435 #define A_N_ENABLE 0x02
437 #define I_ADD_REG0 0x04
438 #define I_ADD_REG1 0x05
439 #define I_ADD_REG2 0x06
440 #define I_ADD_REG3 0x07
441 #define I_ADD_REG4 0x08
442 #define I_ADD_REG5 0x09
444 #define EEPROM_REG 0x0a
445 #define EESK 0x01
446 #define EECS 0x02
447 #define EEDI 0x04
448 #define EEDO 0x08
451 /* Check for a network adaptor of this type, and return '0' if one exists.
452 If dev->base_addr == 0, probe all likely locations.
453 If dev->base_addr == 1, always return failure.
454 If dev->base_addr == 2, allocate space for the device and return success
455 (detachable devices only).
457 #ifdef HAVE_DEVLIST
458 /* Support for an alternate probe manager, which will eliminate the
459 boilerplate below. */
460 struct netdev_entry netcard_drv =
461 {"eepro", eepro_probe1, EEPRO_IO_EXTENT, eepro_portlist};
462 #else
463 int __init eepro_probe(struct net_device *dev)
465 int i;
466 int base_addr = dev ? dev->base_addr : 0;
469 #ifdef PnPWakeup
470 /* XXXX for multiple cards should this only be run once? */
472 /* Wakeup: */
473 #define WakeupPort 0x279
474 #define WakeupSeq {0x6A, 0xB5, 0xDA, 0xED, 0xF6, 0xFB, 0x7D, 0xBE,\
475 0xDF, 0x6F, 0x37, 0x1B, 0x0D, 0x86, 0xC3, 0x61,\
476 0xB0, 0x58, 0x2C, 0x16, 0x8B, 0x45, 0xA2, 0xD1,\
477 0xE8, 0x74, 0x3A, 0x9D, 0xCE, 0xE7, 0x73, 0x43}
480 unsigned short int WS[32]=WakeupSeq;
482 if (check_region(WakeupPort, 2)==0) {
484 if (net_debug>5)
485 printk(KERN_DEBUG "Waking UP\n");
487 outb_p(0,WakeupPort);
488 outb_p(0,WakeupPort);
489 for (i=0; i<32; i++) {
490 outb_p(WS[i],WakeupPort);
491 if (net_debug>5) printk(KERN_DEBUG ": %#x ",WS[i]);
493 } else printk(KERN_WARNING "Checkregion Failed!\n");
495 #endif
498 if (base_addr > 0x1ff) /* Check a single specified location. */
499 return eepro_probe1(dev, base_addr);
501 else if (base_addr != 0) /* Don't probe at all. */
502 return ENXIO;
505 for (i = 0; eepro_portlist[i]; i++) {
506 int ioaddr = eepro_portlist[i];
508 if (check_region(ioaddr, EEPRO_IO_EXTENT))
509 continue;
510 if (eepro_probe1(dev, ioaddr) == 0)
511 return 0;
514 return ENODEV;
516 #endif
518 void printEEPROMInfo(short ioaddr)
520 unsigned short Word;
521 int i,j;
523 for (i=0, j=ee_Checksum; i<ee_SIZE; i++)
524 j+=read_eeprom(ioaddr,i);
525 printk("Checksum: %#x\n",j&0xffff);
527 Word=read_eeprom(ioaddr, 0);
528 printk(KERN_DEBUG "Word0:\n");
529 printk(KERN_DEBUG " Plug 'n Pray: %d\n",GetBit(Word,ee_PnP));
530 printk(KERN_DEBUG " Buswidth: %d\n",(GetBit(Word,ee_BusWidth)+1)*8 );
531 printk(KERN_DEBUG " AutoNegotiation: %d\n",GetBit(Word,ee_AutoNeg));
532 printk(KERN_DEBUG " IO Address: %#x\n", (Word>>ee_IO0)<<4);
534 if (net_debug>4) {
535 Word=read_eeprom(ioaddr, 1);
536 printk(KERN_DEBUG "Word1:\n");
537 printk(KERN_DEBUG " INT: %d\n", Word & ee_IntMask);
538 printk(KERN_DEBUG " LI: %d\n", GetBit(Word,ee_LI));
539 printk(KERN_DEBUG " PC: %d\n", GetBit(Word,ee_PC));
540 printk(KERN_DEBUG " TPE/AUI: %d\n", GetBit(Word,ee_TPE_AUI));
541 printk(KERN_DEBUG " Jabber: %d\n", GetBit(Word,ee_Jabber));
542 printk(KERN_DEBUG " AutoPort: %d\n", GetBit(!Word,ee_Jabber));
543 printk(KERN_DEBUG " Duplex: %d\n", GetBit(Word,ee_Duplex));
546 Word=read_eeprom(ioaddr, 5);
547 printk(KERN_DEBUG "Word5:\n");
548 printk(KERN_DEBUG " BNC: %d\n",GetBit(Word,ee_BNC_TPE));
549 printk(KERN_DEBUG " NumConnectors: %d\n",GetBit(Word,ee_NumConn));
550 printk(KERN_DEBUG " Has ");
551 if (GetBit(Word,ee_PortTPE)) printk("TPE ");
552 if (GetBit(Word,ee_PortBNC)) printk("BNC ");
553 if (GetBit(Word,ee_PortAUI)) printk("AUI ");
554 printk("port(s) \n");
556 Word=read_eeprom(ioaddr, 6);
557 printk(KERN_DEBUG "Word6:\n");
558 printk(KERN_DEBUG " Stepping: %d\n",Word & ee_StepMask);
559 printk(KERN_DEBUG " BoardID: %d\n",Word>>ee_BoardID);
561 Word=read_eeprom(ioaddr, 7);
562 printk(KERN_DEBUG "Word7:\n");
563 printk(KERN_DEBUG " INT to IRQ:\n");
565 printk(KERN_DEBUG);
567 for (i=0, j=0; i<15; i++)
568 if (GetBit(Word,i)) printk(" INT%d -> IRQ %d;",j++,i);
570 printk("\n");
573 /* This is the real probe routine. Linux has a history of friendly device
574 probes on the ISA bus. A good device probe avoids doing writes, and
575 verifies that the correct device exists and functions. */
577 int eepro_probe1(struct net_device *dev, short ioaddr)
579 unsigned short station_addr[6], id, counter;
580 int i,j, irqMask;
581 int eepro;
582 const char *ifmap[] = {"AUI", "10Base2", "10BaseT"};
583 enum iftype { AUI=0, BNC=1, TPE=2 };
585 /* Now, we are going to check for the signature of the
586 ID_REG (register 2 of bank 0) */
588 id=inb(ioaddr + ID_REG);
590 printk(KERN_DEBUG " id: %#x ",id);
591 printk(" io: %#x ",ioaddr);
593 if (((id) & ID_REG_MASK) == ID_REG_SIG) {
595 /* We seem to have the 82595 signature, let's
596 play with its counter (last 2 bits of
597 register 2 of bank 0) to be sure. */
599 counter = (id & R_ROBIN_BITS);
600 if (((id=inb(ioaddr+ID_REG)) & R_ROBIN_BITS) ==
601 (counter + 0x40)) {
603 /* Yes, the 82595 has been found */
605 /* Now, get the ethernet hardware address from
606 the EEPROM */
608 station_addr[0] = read_eeprom(ioaddr, 2);
609 station_addr[1] = read_eeprom(ioaddr, 3);
610 station_addr[2] = read_eeprom(ioaddr, 4);
612 /* Check the station address for the manufacturer's code */
613 if (net_debug>3)
614 printEEPROMInfo(ioaddr);
616 if (read_eeprom(ioaddr,7)== ee_FX_INT2IRQ) { /* int to IRQ Mask */
617 eepro = 2;
618 printk("%s: Intel EtherExpress Pro/10+ ISA\n at %#x,",
619 dev->name, ioaddr);
620 } else
621 if (station_addr[2] == 0x00aa) {
622 eepro = 1;
623 printk("%s: Intel EtherExpress Pro/10 ISA at %#x,",
624 dev->name, ioaddr);
626 else {
627 eepro = 0;
628 printk("%s: Intel 82595-based lan card at %#x,",
629 dev->name, ioaddr);
632 /* Fill in the 'dev' fields. */
633 dev->base_addr = ioaddr;
635 for (i=0; i < 6; i++) {
636 dev->dev_addr[i] = ((unsigned char *) station_addr)[5-i];
637 printk("%c%02x", i ? ':' : ' ', dev->dev_addr[i]);
640 if ((dev->mem_end & 0x3f) < 3 || /* RX buffer must be more than 3K */
641 (dev->mem_end & 0x3f) > 29) /* and less than 29K */
642 dev->mem_end = RCV_RAM; /* or it will be set to 24K */
643 else dev->mem_end = 1024*dev->mem_end; /* Maybe I should shift << 10 */
645 /* From now on, dev->mem_end contains the actual size of rx buffer */
647 if (net_debug > 3)
648 printk(", %dK RCV buffer", (int)(dev->mem_end)/1024);
651 /* ............... */
653 if (GetBit( read_eeprom(ioaddr, 5),ee_BNC_TPE))
654 dev->if_port = BNC;
655 else dev->if_port = TPE;
657 /* ............... */
660 if ((dev->irq < 2) && (eepro!=0)) {
661 i = read_eeprom(ioaddr, 1);
662 irqMask = read_eeprom(ioaddr, 7);
663 i &= 0x07; /* Mask off INT number */
665 for (j=0; ((j<16) && (i>=0)); j++) {
666 if ((irqMask & (1<<j))!=0) {
667 if (i==0) {
668 dev->irq = j;
669 break; /* found bit corresponding to irq */
671 i--; /* count bits set in irqMask */
674 if (dev -> irq<2) {
675 printk(" Duh! illegal interrupt vector stored in EEPROM.\n");
676 return ENODEV;
677 } else
679 if (dev->irq==2) dev->irq = 9;
681 else if (dev->irq == 2)
682 dev->irq = 9;
685 if (dev->irq > 2) {
686 printk(", IRQ %d, %s.\n", dev->irq,
687 ifmap[dev->if_port]);
689 else printk(", %s.\n", ifmap[dev->if_port]);
691 if ((dev->mem_start & 0xf) > 0) /* I don't know if this is */
692 net_debug = dev->mem_start & 7; /* still useful or not */
694 if (net_debug > 3) {
695 i = read_eeprom(ioaddr, 5);
696 if (i & 0x2000) /* bit 13 of EEPROM word 5 */
697 printk(KERN_DEBUG "%s: Concurrent Processing is enabled but not used!\n",
698 dev->name);
701 if (net_debug)
702 printk(version);
704 /* Grab the region so we can find another board if autoIRQ fails. */
705 request_region(ioaddr, EEPRO_IO_EXTENT, dev->name);
707 /* Initialize the device structure */
708 dev->priv = kmalloc(sizeof(struct eepro_local), GFP_KERNEL);
709 if (dev->priv == NULL)
710 return -ENOMEM;
711 memset(dev->priv, 0, sizeof(struct eepro_local));
713 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
714 spin_lock_init(&(((struct eepro_local *)dev->priv)->lock));
715 #endif
716 dev->open = eepro_open;
717 dev->stop = eepro_close;
718 dev->hard_start_xmit = eepro_send_packet;
719 dev->get_stats = eepro_get_stats;
720 dev->set_multicast_list = &set_multicast_list;
722 /* Fill in the fields of the device structure with
723 ethernet generic values */
725 ether_setup(dev);
727 outb(RESET_CMD, ioaddr); /* RESET the 82595 */
729 return 0;
731 else return ENODEV;
733 else if (net_debug > 3)
734 printk ("EtherExpress Pro probed failed!\n");
735 return ENODEV;
738 /* Open/initialize the board. This is called (in the current kernel)
739 sometime after booting when the 'ifconfig' program is run.
741 This routine should set everything up anew at each open, even
742 registers that "should" only need to be set once at boot, so that
743 there is non-reboot way to recover if something goes wrong.
746 static char irqrmap[] = {-1,-1,0,1,-1,2,-1,-1,-1,0,3,4,-1,-1,-1,-1};
747 static char irqrmap2[] = {-1,-1,4,0,1,2,-1,3,-1,4,5,6,7,-1,-1,-1};
748 static int eepro_grab_irq(struct net_device *dev)
750 int irqlist[] = { 3, 4, 5, 7, 9, 10, 11, 12 };
751 int *irqp = irqlist, temp_reg, ioaddr = dev->base_addr;
753 outb(BANK1_SELECT, ioaddr); /* be CAREFUL, BANK 1 now */
755 /* Enable the interrupt line. */
756 temp_reg = inb(ioaddr + REG1);
757 outb(temp_reg | INT_ENABLE, ioaddr + REG1);
759 outb(BANK0_SELECT, ioaddr); /* be CAREFUL, BANK 0 now */
761 /* clear all interrupts */
762 outb(ALL_MASK, ioaddr + STATUS_REG);
764 /* Let EXEC event to interrupt */
765 outb(ALL_MASK & ~(EXEC_MASK), ioaddr + INT_MASK_REG);
767 do {
768 outb(BANK1_SELECT, ioaddr); /* be CAREFUL, BANK 1 now */
770 temp_reg = inb(ioaddr + INT_NO_REG);
771 outb((temp_reg & 0xf8) | irqrmap[*irqp], ioaddr + INT_NO_REG);
773 outb(BANK0_SELECT, ioaddr); /* Switch back to Bank 0 */
775 if (request_irq (*irqp, NULL, 0, "bogus", dev) != EBUSY) {
776 /* Twinkle the interrupt, and check if it's seen */
777 autoirq_setup(0);
779 outb(DIAGNOSE_CMD, ioaddr); /* RESET the 82595 */
781 if (*irqp == autoirq_report(2)) /* It's a good IRQ line */
782 break;
784 /* clear all interrupts */
785 outb(ALL_MASK, ioaddr + STATUS_REG);
787 } while (*++irqp);
789 outb(BANK1_SELECT, ioaddr); /* Switch back to Bank 1 */
791 /* Disable the physical interrupt line. */
792 temp_reg = inb(ioaddr + REG1);
793 outb(temp_reg & 0x7f, ioaddr + REG1);
795 outb(BANK0_SELECT, ioaddr); /* Switch back to Bank 0 */
797 /* Mask all the interrupts. */
798 outb(ALL_MASK, ioaddr + INT_MASK_REG);
800 /* clear all interrupts */
801 outb(ALL_MASK, ioaddr + STATUS_REG);
803 return dev->irq;
806 static int eepro_open(struct net_device *dev)
808 unsigned short temp_reg, old8, old9;
809 int irqMask;
810 int i, ioaddr = dev->base_addr, rcv_ram = dev->mem_end;
811 struct eepro_local *lp = (struct eepro_local *)dev->priv;
813 if (net_debug > 3)
814 printk(KERN_DEBUG "%s: entering eepro_open routine.\n", dev->name);
816 if ((irqMask=read_eeprom(ioaddr,7))== ee_FX_INT2IRQ) /* INT to IRQ Mask */
818 lp->eepro = 2; /* Yes, an Intel EtherExpress Pro/10+ */
819 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 2;\n");
822 else if ((dev->dev_addr[0] == SA_ADDR0 &&
823 dev->dev_addr[1] == SA_ADDR1 &&
824 dev->dev_addr[2] == SA_ADDR2))
826 lp->eepro = 1;
827 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 1;\n");
828 } /* Yes, an Intel EtherExpress Pro/10 */
830 else lp->eepro = 0; /* No, it is a generic 82585 lan card */
832 /* Get the interrupt vector for the 82595 */
833 if (dev->irq < 2 && eepro_grab_irq(dev) == 0) {
834 printk("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
835 return -EAGAIN;
838 if (request_irq(dev->irq , &eepro_interrupt, 0, dev->name, dev)) {
839 printk("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
840 return -EAGAIN;
843 #ifdef irq2dev_map
844 if (((irq2dev_map[dev->irq] != 0)
845 || (irq2dev_map[dev->irq] = dev) == 0) &&
846 (irq2dev_map[dev->irq]!=dev)) {
847 /* printk("%s: IRQ map wrong\n", dev->name); */
848 return -EAGAIN;
850 #endif
852 /* Initialize the 82595. */
854 outb(BANK2_SELECT, ioaddr); /* be CAREFUL, BANK 2 now */
855 temp_reg = inb(ioaddr + EEPROM_REG);
857 lp->stepping = temp_reg >> 5; /* Get the stepping number of the 595 */
859 if (net_debug > 3)
860 printk(KERN_DEBUG "The stepping of the 82595 is %d\n", lp->stepping);
862 if (temp_reg & 0x10) /* Check the TurnOff Enable bit */
863 outb(temp_reg & 0xef, ioaddr + EEPROM_REG);
864 for (i=0; i < 6; i++)
865 outb(dev->dev_addr[i] , ioaddr + I_ADD_REG0 + i);
867 temp_reg = inb(ioaddr + REG1); /* Setup Transmit Chaining */
868 outb(temp_reg | XMT_Chain_Int | XMT_Chain_ErrStop /* and discard bad RCV frames */
869 | RCV_Discard_BadFrame, ioaddr + REG1);
871 temp_reg = inb(ioaddr + REG2); /* Match broadcast */
872 outb(temp_reg | 0x14, ioaddr + REG2);
874 temp_reg = inb(ioaddr + REG3);
875 outb(temp_reg & 0x3f, ioaddr + REG3); /* clear test mode */
877 /* Set the receiving mode */
878 outb(BANK1_SELECT, ioaddr); /* be CAREFUL, BANK 1 now */
880 /* Set the interrupt vector */
881 temp_reg = inb(ioaddr + INT_NO_REG);
882 if (lp->eepro == 2)
883 outb((temp_reg & 0xf8) | irqrmap2[dev->irq], ioaddr + INT_NO_REG);
884 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
887 temp_reg = inb(ioaddr + INT_NO_REG);
888 if (lp->eepro == 2)
889 outb((temp_reg & 0xf0) | irqrmap2[dev->irq] | 0x08,ioaddr+INT_NO_REG);
890 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
892 if (net_debug > 3)
893 printk(KERN_DEBUG "eepro_open: content of INT Reg is %x\n", temp_reg);
896 /* Initialize the RCV and XMT upper and lower limits */
897 outb(RCV_LOWER_LIMIT, ioaddr + RCV_LOWER_LIMIT_REG);
898 outb(RCV_UPPER_LIMIT, ioaddr + RCV_UPPER_LIMIT_REG);
899 outb(XMT_LOWER_LIMIT, ioaddr + XMT_LOWER_LIMIT_REG);
900 outb(XMT_UPPER_LIMIT, ioaddr + XMT_UPPER_LIMIT_REG);
902 /* Enable the interrupt line. */
903 temp_reg = inb(ioaddr + REG1);
904 outb(temp_reg | INT_ENABLE, ioaddr + REG1);
906 outb(BANK0_SELECT, ioaddr); /* Switch back to Bank 0 */
908 /* Let RX and TX events to interrupt */
909 outb(ALL_MASK & ~(RX_MASK | TX_MASK), ioaddr + INT_MASK_REG);
911 /* clear all interrupts */
912 outb(ALL_MASK, ioaddr + STATUS_REG);
914 /* Initialize RCV */
915 outw(RCV_LOWER_LIMIT << 8, ioaddr + RCV_BAR);
916 lp->rx_start = (RCV_LOWER_LIMIT << 8) ;
917 outw((RCV_UPPER_LIMIT << 8) | 0xfe, ioaddr + RCV_STOP);
919 /* Initialize XMT */
920 outw(XMT_LOWER_LIMIT << 8, ioaddr + XMT_BAR);
922 /* Check for the i82595TX and i82595FX */
923 old8 = inb(ioaddr + 8);
924 outb(~old8, ioaddr + 8);
926 if ((temp_reg = inb(ioaddr + 8)) == old8) {
927 if (net_debug > 3)
928 printk(KERN_DEBUG "i82595 detected!\n");
929 lp->version = LAN595;
931 else {
932 lp->version = LAN595TX;
933 outb(old8, ioaddr + 8);
934 old9 = inb(ioaddr + 9);
935 /*outb(~old9, ioaddr + 9);
936 if (((temp_reg = inb(ioaddr + 9)) == ( (~old9)&0xff) )) {*/
938 if (irqMask==ee_FX_INT2IRQ) {
939 enum iftype { AUI=0, BNC=1, TPE=2 };
941 if (net_debug > 3) {
942 printk(KERN_DEBUG "IrqMask: %#x\n",irqMask);
943 printk(KERN_DEBUG "i82595FX detected!\n");
945 lp->version = LAN595FX;
946 outb(old9, ioaddr + 9);
947 if (dev->if_port != TPE) { /* Hopefully, this will fix the
948 problem of using Pentiums and
949 pro/10 w/ BNC. */
950 outb(BANK2_SELECT, ioaddr); /* be CAREFUL, BANK 2 now */
951 temp_reg = inb(ioaddr + REG13);
952 /* disable the full duplex mode since it is not
953 applicable with the 10Base2 cable. */
954 outb(temp_reg & ~(FDX | A_N_ENABLE), REG13);
955 outb(BANK0_SELECT, ioaddr); /* be CAREFUL, BANK 0 now */
958 else if (net_debug > 3) {
959 printk(KERN_DEBUG "temp_reg: %#x ~old9: %#x\n",temp_reg,((~old9)&0xff));
960 printk(KERN_DEBUG "i82595TX detected!\n");
964 outb(SEL_RESET_CMD, ioaddr);
966 /* We are supposed to wait for 2 us after a SEL_RESET */
967 SLOW_DOWN;
968 SLOW_DOWN;
970 lp->tx_start = lp->tx_end = XMT_LOWER_LIMIT << 8; /* or = RCV_RAM */
971 lp->tx_last = 0;
973 dev->tbusy = 0;
974 dev->interrupt = 0;
975 dev->start = 1;
977 if (net_debug > 3)
978 printk(KERN_DEBUG "%s: exiting eepro_open routine.\n", dev->name);
980 outb(RCV_ENABLE_CMD, ioaddr);
982 MOD_INC_USE_COUNT;
983 return 0;
986 static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev)
988 struct eepro_local *lp = (struct eepro_local *)dev->priv;
989 int ioaddr = dev->base_addr;
990 int rcv_ram = dev->mem_end;
992 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
993 unsigned long flags;
994 #endif
996 if (net_debug > 5)
997 printk(KERN_DEBUG "%s: entering eepro_send_packet routine.\n", dev->name);
999 if (dev->tbusy) {
1000 /* If we get here, some higher level has decided we are broken.
1001 There should really be a "kick me" function call instead. */
1002 int tickssofar = jiffies - dev->trans_start;
1003 if (tickssofar < 40)
1004 return 1;
1006 /* if (net_debug > 1) */
1007 printk(KERN_ERR "%s: transmit timed out, %s?\n", dev->name,
1008 "network cable problem");
1009 /* This is not a duplicate. One message for the console,
1010 one for the the log file */
1011 printk(KERN_DEBUG "%s: transmit timed out, %s?\n", dev->name,
1012 "network cable problem");
1013 lp->stats.tx_errors++;
1015 /* Try to restart the adaptor. */
1016 outb(SEL_RESET_CMD, ioaddr);
1017 /* We are supposed to wait for 2 us after a SEL_RESET */
1018 SLOW_DOWN;
1019 SLOW_DOWN;
1021 /* Do I also need to flush the transmit buffers here? YES? */
1022 lp->tx_start = lp->tx_end = rcv_ram;
1023 lp->tx_last = 0;
1025 dev->tbusy=0;
1026 dev->trans_start = jiffies;
1028 outb(RCV_ENABLE_CMD, ioaddr);
1032 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE < 0x20155
1033 /* If some higher layer thinks we've missed an tx-done interrupt
1034 we are passed NULL. Caution: dev_tint() handles the cli()/sti()
1035 itself. */
1036 /* if (skb == NULL) {
1037 dev_tint(dev);
1038 return 0;
1040 /* according to A. Cox, this is obsolete since 1.0 */
1041 #endif
1043 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
1044 spin_lock_irqsave(&lp->lock, flags);
1045 #endif
1047 /* Block a timer-based transmit from overlapping. */
1048 if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
1049 printk(KERN_WARNING "%s: Transmitter access conflict.\n", dev->name);
1051 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
1052 spin_unlock_irqrestore(&lp->lock, flags);
1053 #endif
1054 } else {
1055 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1056 unsigned char *buf = skb->data;
1058 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
1059 lp->stats.tx_bytes+=skb->len;
1060 #endif
1062 hardware_send_packet(dev, buf, length);
1063 dev->trans_start = jiffies;
1067 compat_dev_kfree_skb (skb, FREE_WRITE);
1069 /* You might need to clean up and record Tx statistics here. */
1070 /* lp->stats.tx_aborted_errors++; */
1072 if (net_debug > 5)
1073 printk(KERN_DEBUG "%s: exiting eepro_send_packet routine.\n", dev->name);
1075 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
1076 spin_unlock_irqrestore(&lp->lock, flags);
1077 #endif
1079 return 0;
1083 /* The typical workload of the driver:
1084 Handle the network interface interrupts. */
1086 static void
1087 eepro_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1089 struct net_device *dev = (struct net_device *)dev_id;
1090 /* (struct net_device *)(irq2dev_map[irq]);*/
1091 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1092 int ioaddr, status, boguscount = 20;
1094 if (dev == NULL) {
1095 printk (KERN_ERR "eepro_interrupt(): irq %d for unknown device.\\n", irq);
1096 return;
1099 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
1100 spin_lock(&lp->lock);
1101 #endif
1103 if (dev->interrupt) {
1104 printk(KERN_ERR "%s: Re-entering the interrupt handler.\n", dev->name);
1106 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
1107 spin_unlock(&lp->lock);
1108 /* FIXME : with the lock, could this ever happen ? */
1109 #endif
1111 return;
1113 dev->interrupt = 1;
1115 if (net_debug > 5)
1116 printk(KERN_DEBUG "%s: entering eepro_interrupt routine.\n", dev->name);
1118 ioaddr = dev->base_addr;
1120 do {
1121 status = inb(ioaddr + STATUS_REG);
1123 if (status & RX_INT) {
1124 if (net_debug > 4)
1125 printk(KERN_DEBUG "%s: packet received interrupt.\n", dev->name);
1127 /* Acknowledge the RX_INT */
1128 outb(RX_INT, ioaddr + STATUS_REG);
1129 /* Get the received packets */
1130 eepro_rx(dev);
1133 else if (status & TX_INT) {
1134 if (net_debug > 4)
1135 printk(KERN_DEBUG "%s: packet transmit interrupt.\n", dev->name);
1137 /* Acknowledge the TX_INT */
1138 outb(TX_INT, ioaddr + STATUS_REG);
1140 /* Process the status of transmitted packets */
1141 eepro_transmit_interrupt(dev);
1144 } while ((boguscount-- > 0) && (status & 0x06));
1146 dev->interrupt = 0;
1148 if (net_debug > 5)
1149 printk(KERN_DEBUG "%s: exiting eepro_interrupt routine.\n", dev->name);
1151 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
1152 spin_unlock(&lp->lock);
1153 #endif
1154 return;
1157 static int eepro_close(struct net_device *dev)
1159 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1160 int ioaddr = dev->base_addr;
1161 int rcv_ram = dev->mem_end;
1162 short temp_reg;
1164 dev->tbusy = 1;
1165 dev->start = 0;
1167 outb(BANK1_SELECT, ioaddr); /* Switch back to Bank 1 */
1169 /* Disable the physical interrupt line. */
1170 temp_reg = inb(ioaddr + REG1);
1171 outb(temp_reg & 0x7f, ioaddr + REG1);
1173 outb(BANK0_SELECT, ioaddr); /* Switch back to Bank 0 */
1175 /* Flush the Tx and disable Rx. */
1176 outb(STOP_RCV_CMD, ioaddr);
1177 lp->tx_start = lp->tx_end = rcv_ram ;
1178 lp->tx_last = 0;
1180 /* Mask all the interrupts. */
1181 outb(ALL_MASK, ioaddr + INT_MASK_REG);
1183 /* clear all interrupts */
1184 outb(ALL_MASK, ioaddr + STATUS_REG);
1186 /* Reset the 82595 */
1187 outb(RESET_CMD, ioaddr);
1189 /* release the interrupt */
1190 free_irq(dev->irq, dev);
1192 #ifdef irq2dev_map
1193 irq2dev_map[dev->irq] = 0;
1194 #endif
1196 /* Update the statistics here. What statistics? */
1198 /* We are supposed to wait for 200 us after a RESET */
1199 SLOW_DOWN;
1200 SLOW_DOWN; /* May not be enough? */
1202 MOD_DEC_USE_COUNT;
1203 return 0;
1206 /* Get the current statistics. This may be called with the card open or
1207 closed. */
1208 static struct enet_statistics *
1209 eepro_get_stats(struct net_device *dev)
1211 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1213 return &lp->stats;
1216 /* Set or clear the multicast filter for this adaptor.
1218 static void
1219 set_multicast_list(struct net_device *dev)
1221 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1222 short ioaddr = dev->base_addr;
1223 unsigned short mode;
1224 struct dev_mc_list *dmi=dev->mc_list;
1226 if (dev->flags&(IFF_ALLMULTI|IFF_PROMISC) || dev->mc_count > 63)
1229 * We must make the kernel realise we had to move
1230 * into promisc mode or we start all out war on
1231 * the cable. If it was a promisc request the
1232 * flag is already set. If not we assert it.
1234 dev->flags|=IFF_PROMISC;
1236 outb(BANK2_SELECT, ioaddr); /* be CAREFUL, BANK 2 now */
1237 mode = inb(ioaddr + REG2);
1238 outb(mode | PRMSC_Mode, ioaddr + REG2);
1239 mode = inb(ioaddr + REG3);
1240 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1241 outb(BANK0_SELECT, ioaddr); /* Return to BANK 0 now */
1242 printk("%s: promiscuous mode enabled.\n", dev->name);
1245 else if (dev->mc_count==0 )
1247 outb(BANK2_SELECT, ioaddr); /* be CAREFUL, BANK 2 now */
1248 mode = inb(ioaddr + REG2);
1249 outb(mode & 0xd6, ioaddr + REG2); /* Turn off Multi-IA and PRMSC_Mode bits */
1250 mode = inb(ioaddr + REG3);
1251 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1252 outb(BANK0_SELECT, ioaddr); /* Return to BANK 0 now */
1255 else
1257 unsigned short status, *eaddrs;
1258 int i, boguscount = 0;
1260 /* Disable RX and TX interrupts. Necessary to avoid
1261 corruption of the HOST_ADDRESS_REG by interrupt
1262 service routines. */
1263 outb(ALL_MASK, ioaddr + INT_MASK_REG);
1265 outb(BANK2_SELECT, ioaddr); /* be CAREFUL, BANK 2 now */
1266 mode = inb(ioaddr + REG2);
1267 outb(mode | Multi_IA, ioaddr + REG2);
1268 mode = inb(ioaddr + REG3);
1269 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1270 outb(BANK0_SELECT, ioaddr); /* Return to BANK 0 now */
1271 outw(lp->tx_end, ioaddr + HOST_ADDRESS_REG);
1272 outw(MC_SETUP, ioaddr + IO_PORT);
1273 outw(0, ioaddr + IO_PORT);
1274 outw(0, ioaddr + IO_PORT);
1275 outw(6*(dev->mc_count + 1), ioaddr + IO_PORT);
1277 for (i = 0; i < dev->mc_count; i++)
1279 eaddrs=(unsigned short *)dmi->dmi_addr;
1280 dmi=dmi->next;
1281 outw(*eaddrs++, ioaddr + IO_PORT);
1282 outw(*eaddrs++, ioaddr + IO_PORT);
1283 outw(*eaddrs++, ioaddr + IO_PORT);
1286 eaddrs = (unsigned short *) dev->dev_addr;
1287 outw(eaddrs[0], ioaddr + IO_PORT);
1288 outw(eaddrs[1], ioaddr + IO_PORT);
1289 outw(eaddrs[2], ioaddr + IO_PORT);
1290 outw(lp->tx_end, ioaddr + XMT_BAR);
1291 outb(MC_SETUP, ioaddr);
1293 /* Update the transmit queue */
1294 i = lp->tx_end + XMT_HEADER + 6*(dev->mc_count + 1);
1296 if (lp->tx_start != lp->tx_end)
1298 /* update the next address and the chain bit in the
1299 last packet */
1300 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1301 outw(i, ioaddr + IO_PORT);
1302 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1303 status = inw(ioaddr + IO_PORT);
1304 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1305 lp->tx_end = i ;
1307 else {
1308 lp->tx_start = lp->tx_end = i ;
1311 /* Acknowledge that the MC setup is done */
1312 do { /* We should be doing this in the eepro_interrupt()! */
1313 SLOW_DOWN;
1314 SLOW_DOWN;
1315 if (inb(ioaddr + STATUS_REG) & 0x08)
1317 i = inb(ioaddr);
1318 outb(0x08, ioaddr + STATUS_REG);
1320 if (i & 0x20) { /* command ABORTed */
1321 printk("%s: multicast setup failed.\n",
1322 dev->name);
1323 break;
1324 } else if ((i & 0x0f) == 0x03) { /* MC-Done */
1325 printk("%s: set Rx mode to %d address%s.\n",
1326 dev->name, dev->mc_count,
1327 dev->mc_count > 1 ? "es":"");
1328 break;
1331 } while (++boguscount < 100);
1333 /* Re-enable RX and TX interrupts */
1334 outb(ALL_MASK & ~(RX_MASK | TX_MASK), ioaddr + INT_MASK_REG);
1337 outb(RCV_ENABLE_CMD, ioaddr);
1340 /* The horrible routine to read a word from the serial EEPROM. */
1341 /* IMPORTANT - the 82595 will be set to Bank 0 after the eeprom is read */
1343 /* The delay between EEPROM clock transitions. */
1344 #define eeprom_delay() { udelay(40); }
1345 #define EE_READ_CMD (6 << 6)
1348 read_eeprom(int ioaddr, int location)
1350 int i;
1351 unsigned short retval = 0;
1352 short ee_addr = ioaddr + EEPROM_REG;
1353 int read_cmd = location | EE_READ_CMD;
1354 short ctrl_val = EECS ;
1356 outb(BANK2_SELECT, ioaddr);
1357 outb(ctrl_val, ee_addr);
1359 /* Shift the read command bits out. */
1360 for (i = 8; i >= 0; i--) {
1361 short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI
1362 : ctrl_val;
1363 outb(outval, ee_addr);
1364 outb(outval | EESK, ee_addr); /* EEPROM clock tick. */
1365 eeprom_delay();
1366 outb(outval, ee_addr); /* Finish EEPROM a clock tick. */
1367 eeprom_delay();
1369 outb(ctrl_val, ee_addr);
1371 for (i = 16; i > 0; i--) {
1372 outb(ctrl_val | EESK, ee_addr); eeprom_delay();
1373 retval = (retval << 1) | ((inb(ee_addr) & EEDO) ? 1 : 0);
1374 outb(ctrl_val, ee_addr); eeprom_delay();
1377 /* Terminate the EEPROM access. */
1378 ctrl_val &= ~EECS;
1379 outb(ctrl_val | EESK, ee_addr);
1380 eeprom_delay();
1381 outb(ctrl_val, ee_addr);
1382 eeprom_delay();
1383 outb(BANK0_SELECT, ioaddr);
1384 return retval;
1387 static void
1388 hardware_send_packet(struct net_device *dev, void *buf, short length)
1390 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1391 short ioaddr = dev->base_addr;
1392 int rcv_ram = dev->mem_end;
1393 unsigned status, tx_available, last, end, boguscount = 100;
1395 if (net_debug > 5)
1396 printk(KERN_DEBUG "%s: entering hardware_send_packet routine.\n", dev->name);
1398 while (boguscount-- > 0) {
1400 /* Disable RX and TX interrupts. Necessary to avoid
1401 corruption of the HOST_ADDRESS_REG by interrupt
1402 service routines. */
1403 outb(ALL_MASK, ioaddr + INT_MASK_REG);
1405 if (dev->interrupt == 1) {
1406 /* Enable RX and TX interrupts */
1407 outb(ALL_MASK & ~(RX_MASK | TX_MASK), ioaddr + INT_MASK_REG);
1408 continue;
1411 /* determine how much of the transmit buffer space is available */
1412 if (lp->tx_end > lp->tx_start)
1413 tx_available = XMT_RAM - (lp->tx_end - lp->tx_start);
1414 else if (lp->tx_end < lp->tx_start)
1415 tx_available = lp->tx_start - lp->tx_end;
1416 else tx_available = XMT_RAM;
1418 if (((((length + 3) >> 1) << 1) + 2*XMT_HEADER)
1419 >= tx_available) /* No space available ??? */
1421 eepro_transmit_interrupt(dev); /* Clean up the transmiting queue */
1423 /* Enable RX and TX interrupts */
1424 outb(ALL_MASK & ~(RX_MASK | TX_MASK), ioaddr + INT_MASK_REG);
1425 continue;
1428 last = lp->tx_end;
1429 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1431 if (end >= RAM_SIZE) { /* the transmit buffer is wrapped around */
1433 if ((RAM_SIZE - last) <= XMT_HEADER) {
1434 /* Arrrr!!!, must keep the xmt header together,
1435 several days were lost to chase this one down. */
1437 last = rcv_ram;
1438 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1441 else end = rcv_ram + (end - RAM_SIZE);
1444 outw(last, ioaddr + HOST_ADDRESS_REG);
1445 outw(XMT_CMD, ioaddr + IO_PORT);
1446 outw(0, ioaddr + IO_PORT);
1447 outw(end, ioaddr + IO_PORT);
1448 outw(length, ioaddr + IO_PORT);
1450 if (lp->version == LAN595)
1451 outsw(ioaddr + IO_PORT, buf, (length + 3) >> 1);
1452 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1453 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1454 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1455 outsl(ioaddr + IO_PORT_32_BIT, buf, (length + 3) >> 2);
1456 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1459 /* A dummy read to flush the DRAM write pipeline */
1460 status = inw(ioaddr + IO_PORT);
1462 if (lp->tx_start == lp->tx_end) {
1463 outw(last, ioaddr + XMT_BAR);
1464 outb(XMT_CMD, ioaddr);
1465 lp->tx_start = last; /* I don't like to change tx_start here */
1467 else {
1468 /* update the next address and the chain bit in the
1469 last packet */
1471 if (lp->tx_end != last) {
1472 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1473 outw(last, ioaddr + IO_PORT);
1476 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1477 status = inw(ioaddr + IO_PORT);
1478 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1480 /* Continue the transmit command */
1481 outb(RESUME_XMT_CMD, ioaddr);
1484 lp->tx_last = last;
1485 lp->tx_end = end;
1487 if (dev->tbusy) {
1488 dev->tbusy = 0;
1491 /* Enable RX and TX interrupts */
1492 outb(ALL_MASK & ~(RX_MASK | TX_MASK), ioaddr + INT_MASK_REG);
1494 if (net_debug > 5)
1495 printk(KERN_DEBUG "%s: exiting hardware_send_packet routine.\n", dev->name);
1496 return;
1499 dev->tbusy = 1;
1500 if (net_debug > 5)
1501 printk(KERN_DEBUG "%s: exiting hardware_send_packet routine.\n", dev->name);
1504 static void
1505 eepro_rx(struct net_device *dev)
1507 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1508 short ioaddr = dev->base_addr, rcv_ram = dev->mem_end;
1509 short boguscount = 20;
1510 short rcv_car = lp->rx_start;
1511 unsigned rcv_event, rcv_status, rcv_next_frame, rcv_size;
1513 if (net_debug > 5)
1514 printk(KERN_DEBUG "%s: entering eepro_rx routine.\n", dev->name);
1516 /* Set the read pointer to the start of the RCV */
1517 outw(rcv_car, ioaddr + HOST_ADDRESS_REG);
1519 rcv_event = inw(ioaddr + IO_PORT);
1521 while (rcv_event == RCV_DONE) {
1523 rcv_status = inw(ioaddr + IO_PORT);
1524 rcv_next_frame = inw(ioaddr + IO_PORT);
1525 rcv_size = inw(ioaddr + IO_PORT);
1527 if ((rcv_status & (RX_OK | RX_ERROR)) == RX_OK) {
1529 /* Malloc up new buffer. */
1530 struct sk_buff *skb;
1532 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
1533 lp->stats.rx_bytes+=rcv_size;
1534 #endif
1535 rcv_size &= 0x3fff;
1536 skb = dev_alloc_skb(rcv_size+5);
1537 if (skb == NULL) {
1538 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
1539 lp->stats.rx_dropped++;
1540 break;
1542 skb->dev = dev;
1543 skb_reserve(skb,2);
1545 if (lp->version == LAN595)
1546 insw(ioaddr+IO_PORT, skb_put(skb,rcv_size), (rcv_size + 3) >> 1);
1547 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1548 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1549 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1550 insl(ioaddr+IO_PORT_32_BIT, skb_put(skb,rcv_size),
1551 (rcv_size + 3) >> 2);
1552 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1555 skb->protocol = eth_type_trans(skb,dev);
1556 netif_rx(skb);
1557 lp->stats.rx_packets++;
1560 else { /* Not sure will ever reach here,
1561 I set the 595 to discard bad received frames */
1562 lp->stats.rx_errors++;
1564 if (rcv_status & 0x0100)
1565 lp->stats.rx_over_errors++;
1567 else if (rcv_status & 0x0400)
1568 lp->stats.rx_frame_errors++;
1570 else if (rcv_status & 0x0800)
1571 lp->stats.rx_crc_errors++;
1573 printk("%s: event = %#x, status = %#x, next = %#x, size = %#x\n",
1574 dev->name, rcv_event, rcv_status, rcv_next_frame, rcv_size);
1577 if (rcv_status & 0x1000)
1578 lp->stats.rx_length_errors++;
1580 if (--boguscount == 0)
1581 break;
1583 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1584 lp->rx_start = rcv_next_frame;
1585 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1586 rcv_event = inw(ioaddr + IO_PORT);
1589 if (rcv_car == 0)
1590 rcv_car = (RCV_UPPER_LIMIT << 8) | 0xff;
1592 outw(rcv_car - 1, ioaddr + RCV_STOP);
1594 if (net_debug > 5)
1595 printk(KERN_DEBUG "%s: exiting eepro_rx routine.\n", dev->name);
1598 static void
1599 eepro_transmit_interrupt(struct net_device *dev)
1601 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1602 short ioaddr = dev->base_addr;
1603 short boguscount = 20;
1604 short xmt_status;
1607 if (dev->tbusy == 0) {
1608 printk("%s: transmit_interrupt called with tbusy = 0 ??\n",
1609 dev->name);
1610 printk(KERN_DEBUG "%s: transmit_interrupt called with tbusy = 0 ??\n",
1611 dev->name);
1615 while (lp->tx_start != lp->tx_end) {
1617 outw(lp->tx_start, ioaddr + HOST_ADDRESS_REG);
1618 xmt_status = inw(ioaddr+IO_PORT);
1620 if ((xmt_status & TX_DONE_BIT) == 0) break;
1622 xmt_status = inw(ioaddr+IO_PORT);
1623 lp->tx_start = inw(ioaddr+IO_PORT);
1625 dev->tbusy = 0;
1626 mark_bh(NET_BH);
1628 if (xmt_status & 0x2000)
1629 lp->stats.tx_packets++;
1630 else {
1631 lp->stats.tx_errors++;
1632 if (xmt_status & 0x0400)
1633 lp->stats.tx_carrier_errors++;
1634 printk("%s: XMT status = %#x\n",
1635 dev->name, xmt_status);
1636 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1637 dev->name, xmt_status);
1640 if (xmt_status & 0x000f) {
1641 lp->stats.collisions += (xmt_status & 0x000f);
1644 if ((xmt_status & 0x0040) == 0x0) {
1645 lp->stats.tx_heartbeat_errors++;
1648 if (--boguscount == 0)
1649 break;
1653 #ifdef MODULE
1655 #define MAX_EEPRO 8
1656 static char devicename[MAX_EEPRO][9];
1657 static struct net_device dev_eepro[MAX_EEPRO];
1659 static int io[MAX_EEPRO] = {
1660 #ifdef PnPWakeup
1661 0x210, /*: default for PnP enabled FX chips */
1662 #else
1663 0x200, /* Why? */
1664 #endif
1665 [1 ... MAX_EEPRO - 1] = -1 };
1666 static int irq[MAX_EEPRO] = { [0 ... MAX_EEPRO-1] = 0 };
1667 static int mem[MAX_EEPRO] = { /* Size of the rx buffer in KB */
1668 [0 ... MAX_EEPRO-1] = RCV_RAM/1024
1671 static int n_eepro = 0;
1672 /* For linux 2.1.xx */
1673 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20155
1674 MODULE_AUTHOR("Pascal Dupuis <dupuis@lei.ucl.ac.be> for the 2.1 stuff (locking,...)");
1675 MODULE_DESCRIPTION("Intel i82595 ISA EtherExpressPro10/10+ driver");
1676 MODULE_PARM(io, "1-" __MODULE_STRING(MAX_EEPRO) "i");
1677 MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_EEPRO) "i");
1678 MODULE_PARM(mem, "1-" __MODULE_STRING(MAX_EEPRO) "i");
1679 #endif
1681 int
1682 init_module(void)
1684 if (io[0] == 0)
1685 printk("eepro_init_module: You should not use auto-probing with insmod!\n");
1687 while (n_eepro < MAX_EEPRO && io[n_eepro] >= 0) {
1688 struct net_device *d = &dev_eepro[n_eepro];
1689 d->name = devicename[n_eepro]; /* inserted by drivers/net/net_init.c */
1690 d->mem_end = mem[n_eepro];
1691 d->base_addr = io[n_eepro];
1692 d->irq = irq[n_eepro];
1693 d->init = eepro_probe;
1695 if (register_netdev(d) == 0)
1696 n_eepro++;
1699 return n_eepro ? 0 : -ENODEV;
1702 void
1703 cleanup_module(void)
1705 int i;
1707 for (i=0; i<n_eepro; i++) {
1708 struct net_device *d = &dev_eepro[i];
1709 unregister_netdev(d);
1711 kfree_s(d->priv,sizeof(struct eepro_local));
1712 d->priv=NULL;
1714 /* If we don't do this, we can't re-insmod it later. */
1715 release_region(d->base_addr, EEPRO_IO_EXTENT);
1719 #endif /* MODULE */