1 /* eepro.c: Intel EtherExpress Pro/10 device driver for Linux. */
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 General 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!
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.
26 0.13a in memory shortage, drop packets also in board
27 (Michael Westermann <mw@microdata-pos.de>, 07/30/2002)
28 0.13 irq sharing, rewrote probe function, fixed a nasty bug in
29 hardware_send_packet and a major cleanup (aris, 11/08/2001)
30 0.12d fixing a problem with single card detected as eight eth devices
31 fixing a problem with sudden drop in card performance
32 (chris (asdn@go2.pl), 10/29/2001)
33 0.12c fixing some problems with old cards (aris, 01/08/2001)
34 0.12b misc fixes (aris, 06/26/2000)
35 0.12a port of version 0.12a of 2.2.x kernels to 2.3.x
36 (aris (aris@conectiva.com.br), 05/19/2000)
37 0.11e some tweaks about multiple cards support (PdP, jul/aug 1999)
38 0.11d added __initdata, __init stuff; call spin_lock_init
39 in eepro_probe1. Replaced "eepro" by dev->name. Augmented
40 the code protected by spin_lock in interrupt routine
42 0.11c minor cleanup (PdP, RMC, 09/12/1998)
43 0.11b Pascal Dupuis (dupuis@lei.ucl.ac.be): works as a module
44 under 2.1.xx. Debug messages are flagged as KERN_DEBUG to
45 avoid console flooding. Added locking at critical parts. Now
46 the dawn thing is SMP safe.
47 0.11a Attempt to get 2.1.xx support up (RMC)
48 0.11 Brian Candler added support for multiple cards. Tested as
49 a module, no idea if it works when compiled into kernel.
51 0.10e Rick Bressler notified me that ifconfig up;ifconfig down fails
52 because the irq is lost somewhere. Fixed that by moving
53 request_irq and free_irq to eepro_open and eepro_close respectively.
54 0.10d Ugh! Now Wakeup works. Was seriously broken in my first attempt.
55 I'll need to find a way to specify an ioport other than
56 the default one in the PnP case. PnP definitively sucks.
57 And, yes, this is not the only reason.
58 0.10c PnP Wakeup Test for 595FX. uncomment #define PnPWakeup;
60 0.10b Should work now with (some) Pro/10+. At least for
61 me (and my two cards) it does. _No_ guarantee for
62 function with non-Pro/10+ cards! (don't have any)
65 0.10 Added support for the Etherexpress Pro/10+. The
66 IRQ map was changed significantly from the old
67 pro/10. The new interrupt map was provided by
68 Rainer M. Canavan (Canavan@Zeus.cs.bonn.edu).
71 0.09 Fixed a race condition in the transmit algorithm,
72 which causes crashes under heavy load with fast
73 pentium computers. The performance should also
74 improve a bit. The size of RX buffer, and hence
75 TX buffer, can also be changed via lilo or insmod.
78 0.08 Implement 32-bit I/O for the 82595TX and 82595FX
79 based lan cards. Disable full-duplex mode if TPE
80 is not used. (BCH, 4/8/96)
82 0.07a Fix a stat report which counts every packet as a
83 heart-beat failure. (BCH, 6/3/95)
85 0.07 Modified to support all other 82595-based lan cards.
86 The IRQ vector of the EtherExpress Pro will be set
87 according to the value saved in the EEPROM. For other
88 cards, I will do autoirq_request() to grab the next
89 available interrupt vector. (BCH, 3/17/95)
91 0.06a,b Interim released. Minor changes in the comments and
92 print out format. (BCH, 3/9/95 and 3/14/95)
94 0.06 First stable release that I am comfortable with. (BCH,
97 0.05 Complete testing of multicast. (BCH, 2/23/95)
99 0.04 Adding multicast support. (BCH, 2/14/95)
101 0.03 First widely alpha release for public testing.
106 static const char version[] =
107 "eepro.c: v0.13 11/08/2001 aris@cathedrallabs.org\n";
109 #include <linux/module.h>
114 This driver wouldn't have been written without the availability
115 of the Crynwr's Lan595 driver source code. It helps me to
116 familiarize with the 82595 chipset while waiting for the Intel
117 documentation. I also learned how to detect the 82595 using
118 the packet driver's technique.
120 This driver is written by cutting and pasting the skeleton.c driver
121 provided by Donald Becker. I also borrowed the EEPROM routine from
122 Donald Becker's 82586 driver.
124 Datasheet for the Intel 82595 (including the TX and FX version). It
125 provides just enough info that the casual reader might think that it
126 documents the i82595.
128 The User Manual for the 82595. It provides a lot of the missing
133 #include <linux/kernel.h>
134 #include <linux/types.h>
135 #include <linux/fcntl.h>
136 #include <linux/interrupt.h>
137 #include <linux/ioport.h>
138 #include <linux/in.h>
139 #include <linux/slab.h>
140 #include <linux/string.h>
141 #include <linux/errno.h>
142 #include <linux/netdevice.h>
143 #include <linux/etherdevice.h>
144 #include <linux/skbuff.h>
145 #include <linux/spinlock.h>
146 #include <linux/init.h>
147 #include <linux/delay.h>
149 #include <asm/system.h>
150 #include <asm/bitops.h>
154 #define compat_dev_kfree_skb( skb, mode ) dev_kfree_skb( (skb) )
155 /* I had reports of looong delays with SLOW_DOWN defined as udelay(2) */
156 #define SLOW_DOWN inb(0x80)
158 #define compat_init_data __initdata
161 /* First, a few definitions that the brave might change. */
162 /* A zero-terminated list of I/O addresses to be probed. */
163 static unsigned int eepro_portlist[] compat_init_data =
164 { 0x300, 0x210, 0x240, 0x280, 0x2C0, 0x200, 0x320, 0x340, 0x360, 0};
165 /* note: 0x300 is default, the 595FX supports ALL IO Ports
166 from 0x000 to 0x3F0, some of which are reserved in PCs */
168 /* To try the (not-really PnP Wakeup: */
173 /* use 0 for production, 1 for verification, >2 for debug */
177 static unsigned int net_debug = NET_DEBUG;
179 /* The number of low I/O ports used by the ethercard. */
180 #define EEPRO_IO_EXTENT 16
182 /* Different 82595 chips */
186 #define LAN595FX_10ISA 3
188 /* Information that need to be kept for each board. */
190 struct net_device_stats stats;
192 unsigned tx_start; /* start of the transmit chain */
193 int tx_last; /* pointer to last packet in the transmit chain */
194 unsigned tx_end; /* end of the transmit chain (plus 1) */
195 int eepro; /* 1 for the EtherExpress Pro/10,
196 2 for the EtherExpress Pro/10+,
197 3 for the EtherExpress 10 (blue cards),
198 0 for other 82595-based lan cards. */
199 int version; /* a flag to indicate if this is a TX or FX
200 version of the 82595 chip. */
203 spinlock_t lock; /* Serializing lock */
205 unsigned rcv_ram; /* pre-calculated space for rx */
206 unsigned xmt_ram; /* pre-calculated space for tx */
207 unsigned char xmt_bar;
208 unsigned char xmt_lower_limit_reg;
209 unsigned char xmt_upper_limit_reg;
210 short xmt_lower_limit;
211 short xmt_upper_limit;
212 short rcv_lower_limit;
213 short rcv_upper_limit;
214 unsigned char eeprom_reg;
217 /* The station (ethernet) address prefix, used for IDing the board. */
218 #define SA_ADDR0 0x00 /* Etherexpress Pro/10 */
219 #define SA_ADDR1 0xaa
220 #define SA_ADDR2 0x00
222 #define GetBit(x,y) ((x & (1<<y))>>y)
225 #define ee_PnP 0 /* Plug 'n Play enable bit */
226 #define ee_Word1 1 /* Word 1? */
227 #define ee_BusWidth 2 /* 8/16 bit */
228 #define ee_FlashAddr 3 /* Flash Address */
229 #define ee_FlashMask 0x7 /* Mask */
230 #define ee_AutoIO 6 /* */
231 #define ee_reserved0 7 /* =0! */
232 #define ee_Flash 8 /* Flash there? */
233 #define ee_AutoNeg 9 /* Auto Negotiation enabled? */
234 #define ee_IO0 10 /* IO Address LSB */
235 #define ee_IO0Mask 0x /*...*/
236 #define ee_IO1 15 /* IO MSB */
239 #define ee_IntSel 0 /* Interrupt */
240 #define ee_IntMask 0x7
241 #define ee_LI 3 /* Link Integrity 0= enabled */
242 #define ee_PC 4 /* Polarity Correction 0= enabled */
243 #define ee_TPE_AUI 5 /* PortSelection 1=TPE */
244 #define ee_Jabber 6 /* Jabber prevention 0= enabled */
245 #define ee_AutoPort 7 /* Auto Port Selection 1= Disabled */
246 #define ee_SMOUT 8 /* SMout Pin Control 0= Input */
247 #define ee_PROM 9 /* Flash EPROM / PROM 0=Flash */
248 #define ee_reserved1 10 /* .. 12 =0! */
249 #define ee_AltReady 13 /* Alternate Ready, 0=normal */
250 #define ee_reserved2 14 /* =0! */
254 #define ee_IA5 0 /*bit start for individual Addr Byte 5 */
255 #define ee_IA4 8 /*bit start for individual Addr Byte 5 */
256 #define ee_IA3 0 /*bit start for individual Addr Byte 5 */
257 #define ee_IA2 8 /*bit start for individual Addr Byte 5 */
258 #define ee_IA1 0 /*bit start for individual Addr Byte 5 */
259 #define ee_IA0 8 /*bit start for individual Addr Byte 5 */
262 #define ee_BNC_TPE 0 /* 0=TPE */
263 #define ee_BootType 1 /* 00=None, 01=IPX, 10=ODI, 11=NDIS */
264 #define ee_BootTypeMask 0x3
265 #define ee_NumConn 3 /* Number of Connections 0= One or Two */
266 #define ee_FlashSock 4 /* Presence of Flash Socket 0= Present */
270 #define ee_PowerMgt 10 /* 0= disabled */
271 #define ee_CP 13 /* Concurrent Processing */
272 #define ee_CPMask 0x7
275 #define ee_Stepping 0 /* Stepping info */
276 #define ee_StepMask 0x0F
277 #define ee_BoardID 4 /* Manucaturer Board ID, reserved */
278 #define ee_BoardMask 0x0FFF
281 #define ee_INT_TO_IRQ 0 /* int to IRQ Mapping = 0x1EB8 for Pro/10+ */
282 #define ee_FX_INT2IRQ 0x1EB8 /* the _only_ mapping allowed for FX chips */
285 #define ee_SIZE 0x40 /* total EEprom Size */
286 #define ee_Checksum 0xBABA /* initial and final value for adding checksum */
289 /* Card identification via EEprom: */
290 #define ee_addr_vendor 0x10 /* Word offset for EISA Vendor ID */
291 #define ee_addr_id 0x11 /* Word offset for Card ID */
292 #define ee_addr_SN 0x12 /* Serial Number */
293 #define ee_addr_CRC_8 0x14 /* CRC over last thee Bytes */
296 #define ee_vendor_intel0 0x25 /* Vendor ID Intel */
297 #define ee_vendor_intel1 0xD4
298 #define ee_id_eepro10p0 0x10 /* ID for eepro/10+ */
299 #define ee_id_eepro10p1 0x31
301 #define TX_TIMEOUT 40
303 /* Index to functions, as function prototypes. */
305 static int eepro_probe1(struct net_device *dev, int autoprobe);
306 static int eepro_open(struct net_device *dev);
307 static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev);
308 static irqreturn_t eepro_interrupt(int irq, void *dev_id, struct pt_regs *regs);
309 static void eepro_rx(struct net_device *dev);
310 static void eepro_transmit_interrupt(struct net_device *dev);
311 static int eepro_close(struct net_device *dev);
312 static struct net_device_stats *eepro_get_stats(struct net_device *dev);
313 static void set_multicast_list(struct net_device *dev);
314 static void eepro_tx_timeout (struct net_device *dev);
316 static int read_eeprom(int ioaddr, int location, struct net_device *dev);
317 static int hardware_send_packet(struct net_device *dev, void *buf, short length);
318 static int eepro_grab_irq(struct net_device *dev);
321 Details of the i82595.
323 You will need either the datasheet or the user manual to understand what
324 is going on here. The 82595 is very different from the 82586, 82593.
326 The receive algorithm in eepro_rx() is just an implementation of the
327 RCV ring structure that the Intel 82595 imposes at the hardware level.
328 The receive buffer is set at 24K, and the transmit buffer is 8K. I
329 am assuming that the total buffer memory is 32K, which is true for the
330 Intel EtherExpress Pro/10. If it is less than that on a generic card,
331 the driver will be broken.
333 The transmit algorithm in the hardware_send_packet() is similar to the
334 one in the eepro_rx(). The transmit buffer is a ring linked list.
335 I just queue the next available packet to the end of the list. In my
336 system, the 82595 is so fast that the list seems to always contain a
337 single packet. In other systems with faster computers and more congested
338 network traffics, the ring linked list should improve performance by
339 allowing up to 8K worth of packets to be queued.
341 The sizes of the receive and transmit buffers can now be changed via lilo
342 or insmod. Lilo uses the appended line "ether=io,irq,debug,rx-buffer,eth0"
343 where rx-buffer is in KB unit. Modules uses the parameter mem which is
344 also in KB unit, for example "insmod io=io-address irq=0 mem=rx-buffer."
345 The receive buffer has to be more than 3K or less than 29K. Otherwise,
346 it is reset to the default of 24K, and, hence, 8K for the trasnmit
347 buffer (transmit-buffer = 32K - receive-buffer).
350 #define RAM_SIZE 0x8000
353 #define RCV_DEFAULT_RAM 0x6000
356 #define XMT_DEFAULT_RAM (RAM_SIZE - RCV_DEFAULT_RAM)
358 #define XMT_START_PRO RCV_DEFAULT_RAM
359 #define XMT_START_10 0x0000
360 #define RCV_START_PRO 0x0000
361 #define RCV_START_10 XMT_DEFAULT_RAM
363 #define RCV_DONE 0x0008
365 #define RX_ERROR 0x0d81
367 #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
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 */
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
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
409 #define XMT_BAR_PRO 0x0a
410 #define XMT_BAR_10 0x0b
412 #define HOST_ADDRESS_REG 0x0c
414 #define IO_PORT_32_BIT 0x0c
416 /* Bank 1 registers */
418 #define WORD_WIDTH 0x02
419 #define INT_ENABLE 0x80
420 #define INT_NO_REG 0x02
421 #define RCV_LOWER_LIMIT_REG 0x08
422 #define RCV_UPPER_LIMIT_REG 0x09
424 #define XMT_LOWER_LIMIT_REG_PRO 0x0a
425 #define XMT_UPPER_LIMIT_REG_PRO 0x0b
426 #define XMT_LOWER_LIMIT_REG_10 0x0b
427 #define XMT_UPPER_LIMIT_REG_10 0x0a
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 */
434 #define PRMSC_Mode 0x01
435 #define Multi_IA 0x20
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
458 /* do a full reset */
459 #define eepro_reset(ioaddr) outb(RESET_CMD, ioaddr)
461 /* do a nice reset */
462 #define eepro_sel_reset(ioaddr) { \
463 outb(SEL_RESET_CMD, ioaddr); \
468 /* disable all interrupts */
469 #define eepro_dis_int(ioaddr) outb(ALL_MASK, ioaddr + INT_MASK_REG)
471 /* clear all interrupts */
472 #define eepro_clear_int(ioaddr) outb(ALL_MASK, ioaddr + STATUS_REG)
475 #define eepro_en_int(ioaddr) outb(ALL_MASK & ~(RX_MASK | TX_MASK), \
476 ioaddr + INT_MASK_REG)
478 /* enable exec event interrupt */
479 #define eepro_en_intexec(ioaddr) outb(ALL_MASK & ~(EXEC_MASK), ioaddr + INT_MASK_REG)
482 #define eepro_en_rx(ioaddr) outb(RCV_ENABLE_CMD, ioaddr)
485 #define eepro_dis_rx(ioaddr) outb(RCV_DISABLE_CMD, ioaddr)
488 #define eepro_sw2bank0(ioaddr) outb(BANK0_SELECT, ioaddr)
489 #define eepro_sw2bank1(ioaddr) outb(BANK1_SELECT, ioaddr)
490 #define eepro_sw2bank2(ioaddr) outb(BANK2_SELECT, ioaddr)
492 /* enable interrupt line */
493 #define eepro_en_intline(ioaddr) outb(inb(ioaddr + REG1) | INT_ENABLE,\
496 /* disable interrupt line */
497 #define eepro_dis_intline(ioaddr) outb(inb(ioaddr + REG1) & 0x7f, \
500 /* set diagnose flag */
501 #define eepro_diag(ioaddr) outb(DIAGNOSE_CMD, ioaddr)
504 #define eepro_ack_rx(ioaddr) outb (RX_INT, ioaddr + STATUS_REG)
507 #define eepro_ack_tx(ioaddr) outb (TX_INT, ioaddr + STATUS_REG)
509 /* a complete sel reset */
510 #define eepro_complete_selreset(ioaddr) { \
511 lp->stats.tx_errors++;\
512 eepro_sel_reset(ioaddr);\
514 lp->xmt_lower_limit;\
515 lp->tx_start = lp->tx_end;\
517 dev->trans_start = jiffies;\
518 netif_wake_queue(dev);\
519 eepro_en_rx(ioaddr);\
522 /* Check for a network adaptor of this type, and return '0' if one exists.
523 If dev->base_addr == 0, probe all likely locations.
524 If dev->base_addr == 1, always return failure.
525 If dev->base_addr == 2, allocate space for the device and return success
526 (detachable devices only).
528 static int __init do_eepro_probe(struct net_device *dev)
531 int base_addr = dev->base_addr;
534 SET_MODULE_OWNER(dev);
537 /* XXXX for multiple cards should this only be run once? */
540 #define WakeupPort 0x279
541 #define WakeupSeq {0x6A, 0xB5, 0xDA, 0xED, 0xF6, 0xFB, 0x7D, 0xBE,\
542 0xDF, 0x6F, 0x37, 0x1B, 0x0D, 0x86, 0xC3, 0x61,\
543 0xB0, 0x58, 0x2C, 0x16, 0x8B, 0x45, 0xA2, 0xD1,\
544 0xE8, 0x74, 0x3A, 0x9D, 0xCE, 0xE7, 0x73, 0x43}
547 unsigned short int WS[32]=WakeupSeq;
549 if (check_region(WakeupPort, 2)==0) {
552 printk(KERN_DEBUG "Waking UP\n");
554 outb_p(0,WakeupPort);
555 outb_p(0,WakeupPort);
556 for (i=0; i<32; i++) {
557 outb_p(WS[i],WakeupPort);
558 if (net_debug>5) printk(KERN_DEBUG ": %#x ",WS[i]);
560 } else printk(KERN_WARNING "Checkregion Failed!\n");
564 if (base_addr > 0x1ff) /* Check a single specified location. */
565 return eepro_probe1(dev, 0);
567 else if (base_addr != 0) /* Don't probe at all. */
570 for (i = 0; eepro_portlist[i]; i++) {
571 dev->base_addr = eepro_portlist[i];
573 if (eepro_probe1(dev, 1) == 0)
580 struct net_device * __init eepro_probe(int unit)
582 struct net_device *dev = alloc_etherdev(sizeof(struct eepro_local));
586 return ERR_PTR(-ENODEV);
588 SET_MODULE_OWNER(dev);
590 sprintf(dev->name, "eth%d", unit);
591 netdev_boot_setup_check(dev);
593 err = do_eepro_probe(dev);
596 err = register_netdev(dev);
601 release_region(dev->base_addr, EEPRO_IO_EXTENT);
607 static void __init printEEPROMInfo(short ioaddr, struct net_device *dev)
612 for (i=0, j=ee_Checksum; i<ee_SIZE; i++)
613 j+=read_eeprom(ioaddr,i,dev);
614 printk(KERN_DEBUG "Checksum: %#x\n",j&0xffff);
616 Word=read_eeprom(ioaddr, 0, dev);
617 printk(KERN_DEBUG "Word0:\n");
618 printk(KERN_DEBUG " Plug 'n Pray: %d\n",GetBit(Word,ee_PnP));
619 printk(KERN_DEBUG " Buswidth: %d\n",(GetBit(Word,ee_BusWidth)+1)*8 );
620 printk(KERN_DEBUG " AutoNegotiation: %d\n",GetBit(Word,ee_AutoNeg));
621 printk(KERN_DEBUG " IO Address: %#x\n", (Word>>ee_IO0)<<4);
624 Word=read_eeprom(ioaddr, 1, dev);
625 printk(KERN_DEBUG "Word1:\n");
626 printk(KERN_DEBUG " INT: %d\n", Word & ee_IntMask);
627 printk(KERN_DEBUG " LI: %d\n", GetBit(Word,ee_LI));
628 printk(KERN_DEBUG " PC: %d\n", GetBit(Word,ee_PC));
629 printk(KERN_DEBUG " TPE/AUI: %d\n", GetBit(Word,ee_TPE_AUI));
630 printk(KERN_DEBUG " Jabber: %d\n", GetBit(Word,ee_Jabber));
631 printk(KERN_DEBUG " AutoPort: %d\n", GetBit(!Word,ee_Jabber));
632 printk(KERN_DEBUG " Duplex: %d\n", GetBit(Word,ee_Duplex));
635 Word=read_eeprom(ioaddr, 5, dev);
636 printk(KERN_DEBUG "Word5:\n");
637 printk(KERN_DEBUG " BNC: %d\n",GetBit(Word,ee_BNC_TPE));
638 printk(KERN_DEBUG " NumConnectors: %d\n",GetBit(Word,ee_NumConn));
639 printk(KERN_DEBUG " Has ");
640 if (GetBit(Word,ee_PortTPE)) printk(KERN_DEBUG "TPE ");
641 if (GetBit(Word,ee_PortBNC)) printk(KERN_DEBUG "BNC ");
642 if (GetBit(Word,ee_PortAUI)) printk(KERN_DEBUG "AUI ");
643 printk(KERN_DEBUG "port(s) \n");
645 Word=read_eeprom(ioaddr, 6, dev);
646 printk(KERN_DEBUG "Word6:\n");
647 printk(KERN_DEBUG " Stepping: %d\n",Word & ee_StepMask);
648 printk(KERN_DEBUG " BoardID: %d\n",Word>>ee_BoardID);
650 Word=read_eeprom(ioaddr, 7, dev);
651 printk(KERN_DEBUG "Word7:\n");
652 printk(KERN_DEBUG " INT to IRQ:\n");
654 for (i=0, j=0; i<15; i++)
655 if (GetBit(Word,i)) printk(KERN_DEBUG " INT%d -> IRQ %d;",j++,i);
657 printk(KERN_DEBUG "\n");
660 /* function to recalculate the limits of buffer based on rcv_ram */
661 static void eepro_recalc (struct net_device *dev)
663 struct eepro_local * lp;
665 lp = netdev_priv(dev);
666 lp->xmt_ram = RAM_SIZE - lp->rcv_ram;
668 if (lp->eepro == LAN595FX_10ISA) {
669 lp->xmt_lower_limit = XMT_START_10;
670 lp->xmt_upper_limit = (lp->xmt_ram - 2);
671 lp->rcv_lower_limit = lp->xmt_ram;
672 lp->rcv_upper_limit = (RAM_SIZE - 2);
675 lp->rcv_lower_limit = RCV_START_PRO;
676 lp->rcv_upper_limit = (lp->rcv_ram - 2);
677 lp->xmt_lower_limit = lp->rcv_ram;
678 lp->xmt_upper_limit = (RAM_SIZE - 2);
682 /* prints boot-time info */
683 static void __init eepro_print_info (struct net_device *dev)
685 struct eepro_local * lp = netdev_priv(dev);
687 const char * ifmap[] = {"AUI", "10Base2", "10BaseT"};
689 i = inb(dev->base_addr + ID_REG);
690 printk(KERN_DEBUG " id: %#x ",i);
691 printk(" io: %#x ", (unsigned)dev->base_addr);
695 printk("%s: Intel EtherExpress 10 ISA\n at %#x,",
696 dev->name, (unsigned)dev->base_addr);
699 printk("%s: Intel EtherExpress Pro/10+ ISA\n at %#x,",
700 dev->name, (unsigned)dev->base_addr);
703 printk("%s: Intel EtherExpress Pro/10 ISA at %#x,",
704 dev->name, (unsigned)dev->base_addr);
707 printk("%s: Intel 82595-based lan card at %#x,",
708 dev->name, (unsigned)dev->base_addr);
711 for (i=0; i < 6; i++)
712 printk("%c%02x", i ? ':' : ' ', dev->dev_addr[i]);
715 printk(KERN_DEBUG ", %dK RCV buffer",
716 (int)(lp->rcv_ram)/1024);
719 printk(", IRQ %d, %s.\n", dev->irq, ifmap[dev->if_port]);
721 printk(", %s.\n", ifmap[dev->if_port]);
724 i = read_eeprom(dev->base_addr, 5, dev);
725 if (i & 0x2000) /* bit 13 of EEPROM word 5 */
726 printk(KERN_DEBUG "%s: Concurrent Processing is "
727 "enabled but not used!\n", dev->name);
730 /* Check the station address for the manufacturer's code */
732 printEEPROMInfo(dev->base_addr, dev);
735 /* This is the real probe routine. Linux has a history of friendly device
736 probes on the ISA bus. A good device probe avoids doing writes, and
737 verifies that the correct device exists and functions. */
739 static int __init eepro_probe1(struct net_device *dev, int autoprobe)
741 unsigned short station_addr[6], id, counter;
743 struct eepro_local *lp;
744 enum iftype { AUI=0, BNC=1, TPE=2 };
745 int ioaddr = dev->base_addr;
747 /* Grab the region so we can find another board if autoIRQ fails. */
748 if (!request_region(ioaddr, EEPRO_IO_EXTENT, dev->name)) {
750 printk(KERN_WARNING "EEPRO: io-port 0x%04x in use \n",
755 /* Now, we are going to check for the signature of the
756 ID_REG (register 2 of bank 0) */
758 id = inb(ioaddr + ID_REG);
760 if ((id & ID_REG_MASK) != ID_REG_SIG)
763 /* We seem to have the 82595 signature, let's
764 play with its counter (last 2 bits of
765 register 2 of bank 0) to be sure. */
767 counter = id & R_ROBIN_BITS;
769 if ((inb(ioaddr + ID_REG) & R_ROBIN_BITS) != (counter + 0x40))
772 lp = netdev_priv(dev);
773 memset(lp, 0, sizeof(struct eepro_local));
774 lp->xmt_bar = XMT_BAR_PRO;
775 lp->xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_PRO;
776 lp->xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_PRO;
777 lp->eeprom_reg = EEPROM_REG_PRO;
778 spin_lock_init(&lp->lock);
780 /* Now, get the ethernet hardware address from
782 station_addr[0] = read_eeprom(ioaddr, 2, dev);
784 /* FIXME - find another way to know that we've found
787 if (station_addr[0] == 0x0000 || station_addr[0] == 0xffff) {
788 lp->eepro = LAN595FX_10ISA;
789 lp->eeprom_reg = EEPROM_REG_10;
790 lp->xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_10;
791 lp->xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_10;
792 lp->xmt_bar = XMT_BAR_10;
793 station_addr[0] = read_eeprom(ioaddr, 2, dev);
795 station_addr[1] = read_eeprom(ioaddr, 3, dev);
796 station_addr[2] = read_eeprom(ioaddr, 4, dev);
799 if (read_eeprom(ioaddr,7,dev)== ee_FX_INT2IRQ)
801 else if (station_addr[2] == SA_ADDR1)
805 /* Fill in the 'dev' fields. */
806 for (i=0; i < 6; i++)
807 dev->dev_addr[i] = ((unsigned char *) station_addr)[5-i];
809 /* RX buffer must be more than 3K and less than 29K */
810 if (dev->mem_end < 3072 || dev->mem_end > 29696)
811 lp->rcv_ram = RCV_DEFAULT_RAM;
813 /* calculate {xmt,rcv}_{lower,upper}_limit */
816 if (GetBit( read_eeprom(ioaddr, 5, dev),ee_BNC_TPE))
821 if (dev->irq < 2 && lp->eepro != 0) {
822 /* Mask off INT number */
823 int count = read_eeprom(ioaddr, 1, dev) & 7;
824 unsigned irqMask = read_eeprom(ioaddr, 7, dev);
827 irqMask &= irqMask - 1;
829 count = ffs(irqMask);
832 dev->irq = count - 1;
835 printk(KERN_ERR " Duh! illegal interrupt vector stored in EEPROM.\n");
837 } else if (dev->irq == 2) {
842 dev->open = eepro_open;
843 dev->stop = eepro_close;
844 dev->hard_start_xmit = eepro_send_packet;
845 dev->get_stats = eepro_get_stats;
846 dev->set_multicast_list = &set_multicast_list;
847 dev->tx_timeout = eepro_tx_timeout;
848 dev->watchdog_timeo = TX_TIMEOUT;
850 /* print boot time info */
851 eepro_print_info(dev);
857 release_region(dev->base_addr, EEPRO_IO_EXTENT);
861 /* Open/initialize the board. This is called (in the current kernel)
862 sometime after booting when the 'ifconfig' program is run.
864 This routine should set everything up anew at each open, even
865 registers that "should" only need to be set once at boot, so that
866 there is non-reboot way to recover if something goes wrong.
869 static char irqrmap[] = {-1,-1,0,1,-1,2,-1,-1,-1,0,3,4,-1,-1,-1,-1};
870 static char irqrmap2[] = {-1,-1,4,0,1,2,-1,3,-1,4,5,6,7,-1,-1,-1};
871 static int eepro_grab_irq(struct net_device *dev)
873 int irqlist[] = { 3, 4, 5, 7, 9, 10, 11, 12, 0 };
874 int *irqp = irqlist, temp_reg, ioaddr = dev->base_addr;
876 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
878 /* Enable the interrupt line. */
879 eepro_en_intline(ioaddr);
881 /* be CAREFUL, BANK 0 now */
882 eepro_sw2bank0(ioaddr);
884 /* clear all interrupts */
885 eepro_clear_int(ioaddr);
887 /* Let EXEC event to interrupt */
888 eepro_en_intexec(ioaddr);
891 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
893 temp_reg = inb(ioaddr + INT_NO_REG);
894 outb((temp_reg & 0xf8) | irqrmap[*irqp], ioaddr + INT_NO_REG);
896 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
898 if (request_irq (*irqp, NULL, SA_SHIRQ, "bogus", dev) != EBUSY) {
899 unsigned long irq_mask;
900 /* Twinkle the interrupt, and check if it's seen */
901 irq_mask = probe_irq_on();
903 eepro_diag(ioaddr); /* RESET the 82595 */
906 if (*irqp == probe_irq_off(irq_mask)) /* It's a good IRQ line */
909 /* clear all interrupts */
910 eepro_clear_int(ioaddr);
914 eepro_sw2bank1(ioaddr); /* Switch back to Bank 1 */
916 /* Disable the physical interrupt line. */
917 eepro_dis_intline(ioaddr);
919 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
921 /* Mask all the interrupts. */
922 eepro_dis_int(ioaddr);
924 /* clear all interrupts */
925 eepro_clear_int(ioaddr);
930 static int eepro_open(struct net_device *dev)
932 unsigned short temp_reg, old8, old9;
934 int i, ioaddr = dev->base_addr;
935 struct eepro_local *lp = netdev_priv(dev);
938 printk(KERN_DEBUG "%s: entering eepro_open routine.\n", dev->name);
940 irqMask = read_eeprom(ioaddr,7,dev);
942 if (lp->eepro == LAN595FX_10ISA) {
943 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 3;\n");
945 else if (irqMask == ee_FX_INT2IRQ) /* INT to IRQ Mask */
947 lp->eepro = 2; /* Yes, an Intel EtherExpress Pro/10+ */
948 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 2;\n");
951 else if ((dev->dev_addr[0] == SA_ADDR0 &&
952 dev->dev_addr[1] == SA_ADDR1 &&
953 dev->dev_addr[2] == SA_ADDR2))
956 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 1;\n");
957 } /* Yes, an Intel EtherExpress Pro/10 */
959 else lp->eepro = 0; /* No, it is a generic 82585 lan card */
961 /* Get the interrupt vector for the 82595 */
962 if (dev->irq < 2 && eepro_grab_irq(dev) == 0) {
963 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
967 if (request_irq(dev->irq , &eepro_interrupt, 0, dev->name, dev)) {
968 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
973 if (((irq2dev_map[dev->irq] != 0)
974 || (irq2dev_map[dev->irq] = dev) == 0) &&
975 (irq2dev_map[dev->irq]!=dev)) {
976 /* printk("%s: IRQ map wrong\n", dev->name); */
977 free_irq(dev->irq, dev);
982 /* Initialize the 82595. */
984 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
985 temp_reg = inb(ioaddr + lp->eeprom_reg);
987 lp->stepping = temp_reg >> 5; /* Get the stepping number of the 595 */
990 printk(KERN_DEBUG "The stepping of the 82595 is %d\n", lp->stepping);
992 if (temp_reg & 0x10) /* Check the TurnOff Enable bit */
993 outb(temp_reg & 0xef, ioaddr + lp->eeprom_reg);
994 for (i=0; i < 6; i++)
995 outb(dev->dev_addr[i] , ioaddr + I_ADD_REG0 + i);
997 temp_reg = inb(ioaddr + REG1); /* Setup Transmit Chaining */
998 outb(temp_reg | XMT_Chain_Int | XMT_Chain_ErrStop /* and discard bad RCV frames */
999 | RCV_Discard_BadFrame, ioaddr + REG1);
1001 temp_reg = inb(ioaddr + REG2); /* Match broadcast */
1002 outb(temp_reg | 0x14, ioaddr + REG2);
1004 temp_reg = inb(ioaddr + REG3);
1005 outb(temp_reg & 0x3f, ioaddr + REG3); /* clear test mode */
1007 /* Set the receiving mode */
1008 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
1010 /* Set the interrupt vector */
1011 temp_reg = inb(ioaddr + INT_NO_REG);
1012 if (lp->eepro == LAN595FX || lp->eepro == LAN595FX_10ISA)
1013 outb((temp_reg & 0xf8) | irqrmap2[dev->irq], ioaddr + INT_NO_REG);
1014 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
1017 temp_reg = inb(ioaddr + INT_NO_REG);
1018 if (lp->eepro == LAN595FX || lp->eepro == LAN595FX_10ISA)
1019 outb((temp_reg & 0xf0) | irqrmap2[dev->irq] | 0x08,ioaddr+INT_NO_REG);
1020 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
1023 printk(KERN_DEBUG "eepro_open: content of INT Reg is %x\n", temp_reg);
1026 /* Initialize the RCV and XMT upper and lower limits */
1027 outb(lp->rcv_lower_limit >> 8, ioaddr + RCV_LOWER_LIMIT_REG);
1028 outb(lp->rcv_upper_limit >> 8, ioaddr + RCV_UPPER_LIMIT_REG);
1029 outb(lp->xmt_lower_limit >> 8, ioaddr + lp->xmt_lower_limit_reg);
1030 outb(lp->xmt_upper_limit >> 8, ioaddr + lp->xmt_upper_limit_reg);
1032 /* Enable the interrupt line. */
1033 eepro_en_intline(ioaddr);
1035 /* Switch back to Bank 0 */
1036 eepro_sw2bank0(ioaddr);
1038 /* Let RX and TX events to interrupt */
1039 eepro_en_int(ioaddr);
1041 /* clear all interrupts */
1042 eepro_clear_int(ioaddr);
1044 /* Initialize RCV */
1045 outw(lp->rcv_lower_limit, ioaddr + RCV_BAR);
1046 lp->rx_start = lp->rcv_lower_limit;
1047 outw(lp->rcv_upper_limit | 0xfe, ioaddr + RCV_STOP);
1049 /* Initialize XMT */
1050 outw(lp->xmt_lower_limit, ioaddr + lp->xmt_bar);
1051 lp->tx_start = lp->tx_end = lp->xmt_lower_limit;
1054 /* Check for the i82595TX and i82595FX */
1055 old8 = inb(ioaddr + 8);
1056 outb(~old8, ioaddr + 8);
1058 if ((temp_reg = inb(ioaddr + 8)) == old8) {
1060 printk(KERN_DEBUG "i82595 detected!\n");
1061 lp->version = LAN595;
1064 lp->version = LAN595TX;
1065 outb(old8, ioaddr + 8);
1066 old9 = inb(ioaddr + 9);
1068 if (irqMask==ee_FX_INT2IRQ) {
1069 enum iftype { AUI=0, BNC=1, TPE=2 };
1071 if (net_debug > 3) {
1072 printk(KERN_DEBUG "IrqMask: %#x\n",irqMask);
1073 printk(KERN_DEBUG "i82595FX detected!\n");
1075 lp->version = LAN595FX;
1076 outb(old9, ioaddr + 9);
1077 if (dev->if_port != TPE) { /* Hopefully, this will fix the
1078 problem of using Pentiums and
1080 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1081 temp_reg = inb(ioaddr + REG13);
1082 /* disable the full duplex mode since it is not
1083 applicable with the 10Base2 cable. */
1084 outb(temp_reg & ~(FDX | A_N_ENABLE), REG13);
1085 eepro_sw2bank0(ioaddr); /* be CAREFUL, BANK 0 now */
1088 else if (net_debug > 3) {
1089 printk(KERN_DEBUG "temp_reg: %#x ~old9: %#x\n",temp_reg,((~old9)&0xff));
1090 printk(KERN_DEBUG "i82595TX detected!\n");
1094 eepro_sel_reset(ioaddr);
1096 netif_start_queue(dev);
1099 printk(KERN_DEBUG "%s: exiting eepro_open routine.\n", dev->name);
1102 eepro_en_rx(ioaddr);
1107 static void eepro_tx_timeout (struct net_device *dev)
1109 struct eepro_local *lp = netdev_priv(dev);
1110 int ioaddr = dev->base_addr;
1112 /* if (net_debug > 1) */
1113 printk (KERN_ERR "%s: transmit timed out, %s?\n", dev->name,
1114 "network cable problem");
1115 /* This is not a duplicate. One message for the console,
1116 one for the the log file */
1117 printk (KERN_DEBUG "%s: transmit timed out, %s?\n", dev->name,
1118 "network cable problem");
1119 eepro_complete_selreset(ioaddr);
1123 static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev)
1125 struct eepro_local *lp = netdev_priv(dev);
1126 unsigned long flags;
1127 int ioaddr = dev->base_addr;
1128 short length = skb->len;
1131 printk(KERN_DEBUG "%s: entering eepro_send_packet routine.\n", dev->name);
1133 if (length < ETH_ZLEN) {
1134 skb = skb_padto(skb, ETH_ZLEN);
1139 netif_stop_queue (dev);
1141 eepro_dis_int(ioaddr);
1142 spin_lock_irqsave(&lp->lock, flags);
1145 unsigned char *buf = skb->data;
1147 if (hardware_send_packet(dev, buf, length))
1148 /* we won't wake queue here because we're out of space */
1149 lp->stats.tx_dropped++;
1151 lp->stats.tx_bytes+=skb->len;
1152 dev->trans_start = jiffies;
1153 netif_wake_queue(dev);
1158 dev_kfree_skb (skb);
1160 /* You might need to clean up and record Tx statistics here. */
1161 /* lp->stats.tx_aborted_errors++; */
1164 printk(KERN_DEBUG "%s: exiting eepro_send_packet routine.\n", dev->name);
1166 eepro_en_int(ioaddr);
1167 spin_unlock_irqrestore(&lp->lock, flags);
1173 /* The typical workload of the driver:
1174 Handle the network interface interrupts. */
1177 eepro_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1179 struct net_device *dev = (struct net_device *)dev_id;
1180 /* (struct net_device *)(irq2dev_map[irq]);*/
1181 struct eepro_local *lp;
1182 int ioaddr, status, boguscount = 20;
1186 printk (KERN_ERR "eepro_interrupt(): irq %d for unknown device.\\n", irq);
1190 lp = netdev_priv(dev);
1192 spin_lock(&lp->lock);
1195 printk(KERN_DEBUG "%s: entering eepro_interrupt routine.\n", dev->name);
1197 ioaddr = dev->base_addr;
1199 while (((status = inb(ioaddr + STATUS_REG)) & (RX_INT|TX_INT)) && (boguscount--))
1202 if (status & RX_INT) {
1204 printk(KERN_DEBUG "%s: packet received interrupt.\n", dev->name);
1206 eepro_dis_int(ioaddr);
1208 /* Get the received packets */
1209 eepro_ack_rx(ioaddr);
1212 eepro_en_int(ioaddr);
1214 if (status & TX_INT) {
1216 printk(KERN_DEBUG "%s: packet transmit interrupt.\n", dev->name);
1219 eepro_dis_int(ioaddr);
1221 /* Process the status of transmitted packets */
1222 eepro_ack_tx(ioaddr);
1223 eepro_transmit_interrupt(dev);
1225 eepro_en_int(ioaddr);
1230 printk(KERN_DEBUG "%s: exiting eepro_interrupt routine.\n", dev->name);
1232 spin_unlock(&lp->lock);
1233 return IRQ_RETVAL(handled);
1236 static int eepro_close(struct net_device *dev)
1238 struct eepro_local *lp = netdev_priv(dev);
1239 int ioaddr = dev->base_addr;
1242 netif_stop_queue(dev);
1244 eepro_sw2bank1(ioaddr); /* Switch back to Bank 1 */
1246 /* Disable the physical interrupt line. */
1247 temp_reg = inb(ioaddr + REG1);
1248 outb(temp_reg & 0x7f, ioaddr + REG1);
1250 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
1252 /* Flush the Tx and disable Rx. */
1253 outb(STOP_RCV_CMD, ioaddr);
1254 lp->tx_start = lp->tx_end = lp->xmt_lower_limit;
1257 /* Mask all the interrupts. */
1258 eepro_dis_int(ioaddr);
1260 /* clear all interrupts */
1261 eepro_clear_int(ioaddr);
1263 /* Reset the 82595 */
1264 eepro_reset(ioaddr);
1266 /* release the interrupt */
1267 free_irq(dev->irq, dev);
1270 irq2dev_map[dev->irq] = 0;
1273 /* Update the statistics here. What statistics? */
1278 /* Get the current statistics. This may be called with the card open or
1280 static struct net_device_stats *
1281 eepro_get_stats(struct net_device *dev)
1283 struct eepro_local *lp = netdev_priv(dev);
1288 /* Set or clear the multicast filter for this adaptor.
1291 set_multicast_list(struct net_device *dev)
1293 struct eepro_local *lp = netdev_priv(dev);
1294 short ioaddr = dev->base_addr;
1295 unsigned short mode;
1296 struct dev_mc_list *dmi=dev->mc_list;
1298 if (dev->flags&(IFF_ALLMULTI|IFF_PROMISC) || dev->mc_count > 63)
1301 * We must make the kernel realise we had to move
1302 * into promisc mode or we start all out war on
1303 * the cable. If it was a promisc request the
1304 * flag is already set. If not we assert it.
1306 dev->flags|=IFF_PROMISC;
1308 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1309 mode = inb(ioaddr + REG2);
1310 outb(mode | PRMSC_Mode, ioaddr + REG2);
1311 mode = inb(ioaddr + REG3);
1312 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1313 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1314 printk(KERN_INFO "%s: promiscuous mode enabled.\n", dev->name);
1317 else if (dev->mc_count==0 )
1319 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1320 mode = inb(ioaddr + REG2);
1321 outb(mode & 0xd6, ioaddr + REG2); /* Turn off Multi-IA and PRMSC_Mode bits */
1322 mode = inb(ioaddr + REG3);
1323 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1324 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1329 unsigned short status, *eaddrs;
1330 int i, boguscount = 0;
1332 /* Disable RX and TX interrupts. Necessary to avoid
1333 corruption of the HOST_ADDRESS_REG by interrupt
1334 service routines. */
1335 eepro_dis_int(ioaddr);
1337 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1338 mode = inb(ioaddr + REG2);
1339 outb(mode | Multi_IA, ioaddr + REG2);
1340 mode = inb(ioaddr + REG3);
1341 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1342 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1343 outw(lp->tx_end, ioaddr + HOST_ADDRESS_REG);
1344 outw(MC_SETUP, ioaddr + IO_PORT);
1345 outw(0, ioaddr + IO_PORT);
1346 outw(0, ioaddr + IO_PORT);
1347 outw(6*(dev->mc_count + 1), ioaddr + IO_PORT);
1349 for (i = 0; i < dev->mc_count; i++)
1351 eaddrs=(unsigned short *)dmi->dmi_addr;
1353 outw(*eaddrs++, ioaddr + IO_PORT);
1354 outw(*eaddrs++, ioaddr + IO_PORT);
1355 outw(*eaddrs++, ioaddr + IO_PORT);
1358 eaddrs = (unsigned short *) dev->dev_addr;
1359 outw(eaddrs[0], ioaddr + IO_PORT);
1360 outw(eaddrs[1], ioaddr + IO_PORT);
1361 outw(eaddrs[2], ioaddr + IO_PORT);
1362 outw(lp->tx_end, ioaddr + lp->xmt_bar);
1363 outb(MC_SETUP, ioaddr);
1365 /* Update the transmit queue */
1366 i = lp->tx_end + XMT_HEADER + 6*(dev->mc_count + 1);
1368 if (lp->tx_start != lp->tx_end)
1370 /* update the next address and the chain bit in the
1372 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1373 outw(i, ioaddr + IO_PORT);
1374 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1375 status = inw(ioaddr + IO_PORT);
1376 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1380 lp->tx_start = lp->tx_end = i ;
1383 /* Acknowledge that the MC setup is done */
1384 do { /* We should be doing this in the eepro_interrupt()! */
1387 if (inb(ioaddr + STATUS_REG) & 0x08)
1390 outb(0x08, ioaddr + STATUS_REG);
1392 if (i & 0x20) { /* command ABORTed */
1393 printk(KERN_NOTICE "%s: multicast setup failed.\n",
1396 } else if ((i & 0x0f) == 0x03) { /* MC-Done */
1397 printk(KERN_DEBUG "%s: set Rx mode to %d address%s.\n",
1398 dev->name, dev->mc_count,
1399 dev->mc_count > 1 ? "es":"");
1403 } while (++boguscount < 100);
1405 /* Re-enable RX and TX interrupts */
1406 eepro_en_int(ioaddr);
1408 if (lp->eepro == LAN595FX_10ISA) {
1409 eepro_complete_selreset(ioaddr);
1412 eepro_en_rx(ioaddr);
1415 /* The horrible routine to read a word from the serial EEPROM. */
1416 /* IMPORTANT - the 82595 will be set to Bank 0 after the eeprom is read */
1418 /* The delay between EEPROM clock transitions. */
1419 #define eeprom_delay() { udelay(40); }
1420 #define EE_READ_CMD (6 << 6)
1423 read_eeprom(int ioaddr, int location, struct net_device *dev)
1426 unsigned short retval = 0;
1427 struct eepro_local *lp = netdev_priv(dev);
1428 short ee_addr = ioaddr + lp->eeprom_reg;
1429 int read_cmd = location | EE_READ_CMD;
1430 short ctrl_val = EECS ;
1432 /* XXXX - black magic */
1433 eepro_sw2bank1(ioaddr);
1434 outb(0x00, ioaddr + STATUS_REG);
1435 /* XXXX - black magic */
1437 eepro_sw2bank2(ioaddr);
1438 outb(ctrl_val, ee_addr);
1440 /* Shift the read command bits out. */
1441 for (i = 8; i >= 0; i--) {
1442 short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI
1444 outb(outval, ee_addr);
1445 outb(outval | EESK, ee_addr); /* EEPROM clock tick. */
1447 outb(outval, ee_addr); /* Finish EEPROM a clock tick. */
1450 outb(ctrl_val, ee_addr);
1452 for (i = 16; i > 0; i--) {
1453 outb(ctrl_val | EESK, ee_addr); eeprom_delay();
1454 retval = (retval << 1) | ((inb(ee_addr) & EEDO) ? 1 : 0);
1455 outb(ctrl_val, ee_addr); eeprom_delay();
1458 /* Terminate the EEPROM access. */
1460 outb(ctrl_val | EESK, ee_addr);
1462 outb(ctrl_val, ee_addr);
1464 eepro_sw2bank0(ioaddr);
1469 hardware_send_packet(struct net_device *dev, void *buf, short length)
1471 struct eepro_local *lp = netdev_priv(dev);
1472 short ioaddr = dev->base_addr;
1473 unsigned status, tx_available, last, end;
1476 printk(KERN_DEBUG "%s: entering hardware_send_packet routine.\n", dev->name);
1478 /* determine how much of the transmit buffer space is available */
1479 if (lp->tx_end > lp->tx_start)
1480 tx_available = lp->xmt_ram - (lp->tx_end - lp->tx_start);
1481 else if (lp->tx_end < lp->tx_start)
1482 tx_available = lp->tx_start - lp->tx_end;
1483 else tx_available = lp->xmt_ram;
1485 if (((((length + 3) >> 1) << 1) + 2*XMT_HEADER) >= tx_available) {
1486 /* No space available ??? */
1491 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1493 if (end >= lp->xmt_upper_limit + 2) { /* the transmit buffer is wrapped around */
1494 if ((lp->xmt_upper_limit + 2 - last) <= XMT_HEADER) {
1495 /* Arrrr!!!, must keep the xmt header together,
1496 several days were lost to chase this one down. */
1497 last = lp->xmt_lower_limit;
1498 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1500 else end = lp->xmt_lower_limit + (end -
1501 lp->xmt_upper_limit + 2);
1504 outw(last, ioaddr + HOST_ADDRESS_REG);
1505 outw(XMT_CMD, ioaddr + IO_PORT);
1506 outw(0, ioaddr + IO_PORT);
1507 outw(end, ioaddr + IO_PORT);
1508 outw(length, ioaddr + IO_PORT);
1510 if (lp->version == LAN595)
1511 outsw(ioaddr + IO_PORT, buf, (length + 3) >> 1);
1512 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1513 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1514 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1515 outsl(ioaddr + IO_PORT_32_BIT, buf, (length + 3) >> 2);
1516 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1519 /* A dummy read to flush the DRAM write pipeline */
1520 status = inw(ioaddr + IO_PORT);
1522 if (lp->tx_start == lp->tx_end) {
1523 outw(last, ioaddr + lp->xmt_bar);
1524 outb(XMT_CMD, ioaddr);
1525 lp->tx_start = last; /* I don't like to change tx_start here */
1528 /* update the next address and the chain bit in the
1531 if (lp->tx_end != last) {
1532 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1533 outw(last, ioaddr + IO_PORT);
1536 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1537 status = inw(ioaddr + IO_PORT);
1538 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1540 /* Continue the transmit command */
1541 outb(RESUME_XMT_CMD, ioaddr);
1548 printk(KERN_DEBUG "%s: exiting hardware_send_packet routine.\n", dev->name);
1554 eepro_rx(struct net_device *dev)
1556 struct eepro_local *lp = netdev_priv(dev);
1557 short ioaddr = dev->base_addr;
1558 short boguscount = 20;
1559 short rcv_car = lp->rx_start;
1560 unsigned rcv_event, rcv_status, rcv_next_frame, rcv_size;
1563 printk(KERN_DEBUG "%s: entering eepro_rx routine.\n", dev->name);
1565 /* Set the read pointer to the start of the RCV */
1566 outw(rcv_car, ioaddr + HOST_ADDRESS_REG);
1568 rcv_event = inw(ioaddr + IO_PORT);
1570 while (rcv_event == RCV_DONE) {
1572 rcv_status = inw(ioaddr + IO_PORT);
1573 rcv_next_frame = inw(ioaddr + IO_PORT);
1574 rcv_size = inw(ioaddr + IO_PORT);
1576 if ((rcv_status & (RX_OK | RX_ERROR)) == RX_OK) {
1578 /* Malloc up new buffer. */
1579 struct sk_buff *skb;
1581 lp->stats.rx_bytes+=rcv_size;
1583 skb = dev_alloc_skb(rcv_size+5);
1585 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
1586 lp->stats.rx_dropped++;
1587 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1588 lp->rx_start = rcv_next_frame;
1589 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1596 if (lp->version == LAN595)
1597 insw(ioaddr+IO_PORT, skb_put(skb,rcv_size), (rcv_size + 3) >> 1);
1598 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1599 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1600 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1601 insl(ioaddr+IO_PORT_32_BIT, skb_put(skb,rcv_size),
1602 (rcv_size + 3) >> 2);
1603 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1606 skb->protocol = eth_type_trans(skb,dev);
1608 dev->last_rx = jiffies;
1609 lp->stats.rx_packets++;
1612 else { /* Not sure will ever reach here,
1613 I set the 595 to discard bad received frames */
1614 lp->stats.rx_errors++;
1616 if (rcv_status & 0x0100)
1617 lp->stats.rx_over_errors++;
1619 else if (rcv_status & 0x0400)
1620 lp->stats.rx_frame_errors++;
1622 else if (rcv_status & 0x0800)
1623 lp->stats.rx_crc_errors++;
1625 printk(KERN_DEBUG "%s: event = %#x, status = %#x, next = %#x, size = %#x\n",
1626 dev->name, rcv_event, rcv_status, rcv_next_frame, rcv_size);
1629 if (rcv_status & 0x1000)
1630 lp->stats.rx_length_errors++;
1632 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1633 lp->rx_start = rcv_next_frame;
1635 if (--boguscount == 0)
1638 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1639 rcv_event = inw(ioaddr + IO_PORT);
1643 rcv_car = lp->rcv_upper_limit | 0xff;
1645 outw(rcv_car - 1, ioaddr + RCV_STOP);
1648 printk(KERN_DEBUG "%s: exiting eepro_rx routine.\n", dev->name);
1652 eepro_transmit_interrupt(struct net_device *dev)
1654 struct eepro_local *lp = netdev_priv(dev);
1655 short ioaddr = dev->base_addr;
1656 short boguscount = 25;
1659 while ((lp->tx_start != lp->tx_end) && boguscount--) {
1661 outw(lp->tx_start, ioaddr + HOST_ADDRESS_REG);
1662 xmt_status = inw(ioaddr+IO_PORT);
1664 if (!(xmt_status & TX_DONE_BIT))
1667 xmt_status = inw(ioaddr+IO_PORT);
1668 lp->tx_start = inw(ioaddr+IO_PORT);
1670 netif_wake_queue (dev);
1672 if (xmt_status & TX_OK)
1673 lp->stats.tx_packets++;
1675 lp->stats.tx_errors++;
1676 if (xmt_status & 0x0400) {
1677 lp->stats.tx_carrier_errors++;
1678 printk(KERN_DEBUG "%s: carrier error\n",
1680 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1681 dev->name, xmt_status);
1684 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1685 dev->name, xmt_status);
1686 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1687 dev->name, xmt_status);
1690 if (xmt_status & 0x000f) {
1691 lp->stats.collisions += (xmt_status & 0x000f);
1694 if ((xmt_status & 0x0040) == 0x0) {
1695 lp->stats.tx_heartbeat_errors++;
1703 static struct net_device *dev_eepro[MAX_EEPRO];
1705 static int io[MAX_EEPRO];
1706 static int irq[MAX_EEPRO];
1707 static int mem[MAX_EEPRO] = { /* Size of the rx buffer in KB */
1708 [0 ... MAX_EEPRO-1] = RCV_DEFAULT_RAM/1024
1710 static int autodetect;
1713 /* For linux 2.1.xx */
1715 MODULE_AUTHOR("Pascal Dupuis, and aris@cathedrallabs.org");
1716 MODULE_DESCRIPTION("Intel i82595 ISA EtherExpressPro10/10+ driver");
1717 MODULE_LICENSE("GPL");
1719 MODULE_PARM(io, "1-" __MODULE_STRING(MAX_EEPRO) "i");
1720 MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_EEPRO) "i");
1721 MODULE_PARM(mem, "1-" __MODULE_STRING(MAX_EEPRO) "i");
1722 MODULE_PARM(autodetect, "1-" __MODULE_STRING(1) "i");
1723 MODULE_PARM_DESC(io, "EtherExpress Pro/10 I/O base addres(es)");
1724 MODULE_PARM_DESC(irq, "EtherExpress Pro/10 IRQ number(s)");
1725 MODULE_PARM_DESC(mem, "EtherExpress Pro/10 Rx buffer size(es) in kB (3-29)");
1726 MODULE_PARM_DESC(autodetect, "EtherExpress Pro/10 force board(s) detection (0-1)");
1731 struct net_device *dev;
1733 if (io[0] == 0 && autodetect == 0) {
1734 printk(KERN_WARNING "eepro_init_module: Probe is very dangerous in ISA boards!\n");
1735 printk(KERN_WARNING "eepro_init_module: Please add \"autodetect=1\" to force probe\n");
1738 else if (autodetect) {
1739 /* if autodetect is set then we must force detection */
1742 printk(KERN_INFO "eepro_init_module: Auto-detecting boards (May God protect us...)\n");
1745 for (i = 0; i < MAX_EEPRO; i++) {
1746 dev = alloc_etherdev(sizeof(struct eepro_local));
1750 dev->mem_end = mem[i];
1751 dev->base_addr = io[i];
1754 if (do_eepro_probe(dev) == 0) {
1755 if (register_netdev(dev) == 0) {
1756 dev_eepro[n_eepro++] = dev;
1759 release_region(dev->base_addr, EEPRO_IO_EXTENT);
1766 printk(KERN_INFO "%s", version);
1768 return n_eepro ? 0 : -ENODEV;
1772 cleanup_module(void)
1776 for (i=0; i<n_eepro; i++) {
1777 struct net_device *dev = dev_eepro[i];
1778 unregister_netdev(dev);
1779 release_region(dev->base_addr, EEPRO_IO_EXTENT);