remove malta-mtd.c and fix MAINTAINERS
[linux-2.6/zen-sources.git] / drivers / net / eepro.c
blob1f11350e16cf24b6a1a25d44ab9f8c41d4481a79
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 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!
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.13b basic ethtool support (aris, 09/13/2004)
27 0.13a in memory shortage, drop packets also in board
28 (Michael Westermann <mw@microdata-pos.de>, 07/30/2002)
29 0.13 irq sharing, rewrote probe function, fixed a nasty bug in
30 hardware_send_packet and a major cleanup (aris, 11/08/2001)
31 0.12d fixing a problem with single card detected as eight eth devices
32 fixing a problem with sudden drop in card performance
33 (chris (asdn@go2.pl), 10/29/2001)
34 0.12c fixing some problems with old cards (aris, 01/08/2001)
35 0.12b misc fixes (aris, 06/26/2000)
36 0.12a port of version 0.12a of 2.2.x kernels to 2.3.x
37 (aris (aris@conectiva.com.br), 05/19/2000)
38 0.11e some tweaks about multiple cards support (PdP, jul/aug 1999)
39 0.11d added __initdata, __init stuff; call spin_lock_init
40 in eepro_probe1. Replaced "eepro" by dev->name. Augmented
41 the code protected by spin_lock in interrupt routine
42 (PdP, 12/12/1998)
43 0.11c minor cleanup (PdP, RMC, 09/12/1998)
44 0.11b Pascal Dupuis (dupuis@lei.ucl.ac.be): works as a module
45 under 2.1.xx. Debug messages are flagged as KERN_DEBUG to
46 avoid console flooding. Added locking at critical parts. Now
47 the dawn thing is SMP safe.
48 0.11a Attempt to get 2.1.xx support up (RMC)
49 0.11 Brian Candler added support for multiple cards. Tested as
50 a module, no idea if it works when compiled into kernel.
52 0.10e Rick Bressler notified me that ifconfig up;ifconfig down fails
53 because the irq is lost somewhere. Fixed that by moving
54 request_irq and free_irq to eepro_open and eepro_close respectively.
55 0.10d Ugh! Now Wakeup works. Was seriously broken in my first attempt.
56 I'll need to find a way to specify an ioport other than
57 the default one in the PnP case. PnP definitively sucks.
58 And, yes, this is not the only reason.
59 0.10c PnP Wakeup Test for 595FX. uncomment #define PnPWakeup;
60 to use.
61 0.10b Should work now with (some) Pro/10+. At least for
62 me (and my two cards) it does. _No_ guarantee for
63 function with non-Pro/10+ cards! (don't have any)
64 (RMC, 9/11/96)
66 0.10 Added support for the Etherexpress Pro/10+. The
67 IRQ map was changed significantly from the old
68 pro/10. The new interrupt map was provided by
69 Rainer M. Canavan (Canavan@Zeus.cs.bonn.edu).
70 (BCH, 9/3/96)
72 0.09 Fixed a race condition in the transmit algorithm,
73 which causes crashes under heavy load with fast
74 pentium computers. The performance should also
75 improve a bit. The size of RX buffer, and hence
76 TX buffer, can also be changed via lilo or insmod.
77 (BCH, 7/31/96)
79 0.08 Implement 32-bit I/O for the 82595TX and 82595FX
80 based lan cards. Disable full-duplex mode if TPE
81 is not used. (BCH, 4/8/96)
83 0.07a Fix a stat report which counts every packet as a
84 heart-beat failure. (BCH, 6/3/95)
86 0.07 Modified to support all other 82595-based lan cards.
87 The IRQ vector of the EtherExpress Pro will be set
88 according to the value saved in the EEPROM. For other
89 cards, I will do autoirq_request() to grab the next
90 available interrupt vector. (BCH, 3/17/95)
92 0.06a,b Interim released. Minor changes in the comments and
93 print out format. (BCH, 3/9/95 and 3/14/95)
95 0.06 First stable release that I am comfortable with. (BCH,
96 3/2/95)
98 0.05 Complete testing of multicast. (BCH, 2/23/95)
100 0.04 Adding multicast support. (BCH, 2/14/95)
102 0.03 First widely alpha release for public testing.
103 (BCH, 2/14/95)
107 static const char version[] =
108 "eepro.c: v0.13b 09/13/2004 aris@cathedrallabs.org\n";
110 #include <linux/module.h>
113 Sources:
115 This driver wouldn't have been written without the availability
116 of the Crynwr's Lan595 driver source code. It helps me to
117 familiarize with the 82595 chipset while waiting for the Intel
118 documentation. I also learned how to detect the 82595 using
119 the packet driver's technique.
121 This driver is written by cutting and pasting the skeleton.c driver
122 provided by Donald Becker. I also borrowed the EEPROM routine from
123 Donald Becker's 82586 driver.
125 Datasheet for the Intel 82595 (including the TX and FX version). It
126 provides just enough info that the casual reader might think that it
127 documents the i82595.
129 The User Manual for the 82595. It provides a lot of the missing
130 information.
134 #include <linux/kernel.h>
135 #include <linux/types.h>
136 #include <linux/fcntl.h>
137 #include <linux/interrupt.h>
138 #include <linux/ioport.h>
139 #include <linux/in.h>
140 #include <linux/slab.h>
141 #include <linux/string.h>
142 #include <linux/errno.h>
143 #include <linux/netdevice.h>
144 #include <linux/etherdevice.h>
145 #include <linux/skbuff.h>
146 #include <linux/spinlock.h>
147 #include <linux/init.h>
148 #include <linux/delay.h>
149 #include <linux/bitops.h>
150 #include <linux/ethtool.h>
152 #include <asm/system.h>
153 #include <asm/io.h>
154 #include <asm/dma.h>
156 #define DRV_NAME "eepro"
157 #define DRV_VERSION "0.13c"
159 #define compat_dev_kfree_skb( skb, mode ) dev_kfree_skb( (skb) )
160 /* I had reports of looong delays with SLOW_DOWN defined as udelay(2) */
161 #define SLOW_DOWN inb(0x80)
162 /* udelay(2) */
163 #define compat_init_data __initdata
164 enum iftype { AUI=0, BNC=1, TPE=2 };
166 /* First, a few definitions that the brave might change. */
167 /* A zero-terminated list of I/O addresses to be probed. */
168 static unsigned int eepro_portlist[] compat_init_data =
169 { 0x300, 0x210, 0x240, 0x280, 0x2C0, 0x200, 0x320, 0x340, 0x360, 0};
170 /* note: 0x300 is default, the 595FX supports ALL IO Ports
171 from 0x000 to 0x3F0, some of which are reserved in PCs */
173 /* To try the (not-really PnP Wakeup: */
175 #define PnPWakeup
178 /* use 0 for production, 1 for verification, >2 for debug */
179 #ifndef NET_DEBUG
180 #define NET_DEBUG 0
181 #endif
182 static unsigned int net_debug = NET_DEBUG;
184 /* The number of low I/O ports used by the ethercard. */
185 #define EEPRO_IO_EXTENT 16
187 /* Different 82595 chips */
188 #define LAN595 0
189 #define LAN595TX 1
190 #define LAN595FX 2
191 #define LAN595FX_10ISA 3
193 /* Information that need to be kept for each board. */
194 struct eepro_local {
195 unsigned rx_start;
196 unsigned tx_start; /* start of the transmit chain */
197 int tx_last; /* pointer to last packet in the transmit chain */
198 unsigned tx_end; /* end of the transmit chain (plus 1) */
199 int eepro; /* 1 for the EtherExpress Pro/10,
200 2 for the EtherExpress Pro/10+,
201 3 for the EtherExpress 10 (blue cards),
202 0 for other 82595-based lan cards. */
203 int version; /* a flag to indicate if this is a TX or FX
204 version of the 82595 chip. */
205 int stepping;
207 spinlock_t lock; /* Serializing lock */
209 unsigned rcv_ram; /* pre-calculated space for rx */
210 unsigned xmt_ram; /* pre-calculated space for tx */
211 unsigned char xmt_bar;
212 unsigned char xmt_lower_limit_reg;
213 unsigned char xmt_upper_limit_reg;
214 short xmt_lower_limit;
215 short xmt_upper_limit;
216 short rcv_lower_limit;
217 short rcv_upper_limit;
218 unsigned char eeprom_reg;
219 unsigned short word[8];
222 /* The station (ethernet) address prefix, used for IDing the board. */
223 #define SA_ADDR0 0x00 /* Etherexpress Pro/10 */
224 #define SA_ADDR1 0xaa
225 #define SA_ADDR2 0x00
227 #define GetBit(x,y) ((x & (1<<y))>>y)
229 /* EEPROM Word 0: */
230 #define ee_PnP 0 /* Plug 'n Play enable bit */
231 #define ee_Word1 1 /* Word 1? */
232 #define ee_BusWidth 2 /* 8/16 bit */
233 #define ee_FlashAddr 3 /* Flash Address */
234 #define ee_FlashMask 0x7 /* Mask */
235 #define ee_AutoIO 6 /* */
236 #define ee_reserved0 7 /* =0! */
237 #define ee_Flash 8 /* Flash there? */
238 #define ee_AutoNeg 9 /* Auto Negotiation enabled? */
239 #define ee_IO0 10 /* IO Address LSB */
240 #define ee_IO0Mask 0x /*...*/
241 #define ee_IO1 15 /* IO MSB */
243 /* EEPROM Word 1: */
244 #define ee_IntSel 0 /* Interrupt */
245 #define ee_IntMask 0x7
246 #define ee_LI 3 /* Link Integrity 0= enabled */
247 #define ee_PC 4 /* Polarity Correction 0= enabled */
248 #define ee_TPE_AUI 5 /* PortSelection 1=TPE */
249 #define ee_Jabber 6 /* Jabber prevention 0= enabled */
250 #define ee_AutoPort 7 /* Auto Port Selection 1= Disabled */
251 #define ee_SMOUT 8 /* SMout Pin Control 0= Input */
252 #define ee_PROM 9 /* Flash EPROM / PROM 0=Flash */
253 #define ee_reserved1 10 /* .. 12 =0! */
254 #define ee_AltReady 13 /* Alternate Ready, 0=normal */
255 #define ee_reserved2 14 /* =0! */
256 #define ee_Duplex 15
258 /* Word2,3,4: */
259 #define ee_IA5 0 /*bit start for individual Addr Byte 5 */
260 #define ee_IA4 8 /*bit start for individual Addr Byte 5 */
261 #define ee_IA3 0 /*bit start for individual Addr Byte 5 */
262 #define ee_IA2 8 /*bit start for individual Addr Byte 5 */
263 #define ee_IA1 0 /*bit start for individual Addr Byte 5 */
264 #define ee_IA0 8 /*bit start for individual Addr Byte 5 */
266 /* Word 5: */
267 #define ee_BNC_TPE 0 /* 0=TPE */
268 #define ee_BootType 1 /* 00=None, 01=IPX, 10=ODI, 11=NDIS */
269 #define ee_BootTypeMask 0x3
270 #define ee_NumConn 3 /* Number of Connections 0= One or Two */
271 #define ee_FlashSock 4 /* Presence of Flash Socket 0= Present */
272 #define ee_PortTPE 5
273 #define ee_PortBNC 6
274 #define ee_PortAUI 7
275 #define ee_PowerMgt 10 /* 0= disabled */
276 #define ee_CP 13 /* Concurrent Processing */
277 #define ee_CPMask 0x7
279 /* Word 6: */
280 #define ee_Stepping 0 /* Stepping info */
281 #define ee_StepMask 0x0F
282 #define ee_BoardID 4 /* Manucaturer Board ID, reserved */
283 #define ee_BoardMask 0x0FFF
285 /* Word 7: */
286 #define ee_INT_TO_IRQ 0 /* int to IRQ Mapping = 0x1EB8 for Pro/10+ */
287 #define ee_FX_INT2IRQ 0x1EB8 /* the _only_ mapping allowed for FX chips */
289 /*..*/
290 #define ee_SIZE 0x40 /* total EEprom Size */
291 #define ee_Checksum 0xBABA /* initial and final value for adding checksum */
294 /* Card identification via EEprom: */
295 #define ee_addr_vendor 0x10 /* Word offset for EISA Vendor ID */
296 #define ee_addr_id 0x11 /* Word offset for Card ID */
297 #define ee_addr_SN 0x12 /* Serial Number */
298 #define ee_addr_CRC_8 0x14 /* CRC over last thee Bytes */
301 #define ee_vendor_intel0 0x25 /* Vendor ID Intel */
302 #define ee_vendor_intel1 0xD4
303 #define ee_id_eepro10p0 0x10 /* ID for eepro/10+ */
304 #define ee_id_eepro10p1 0x31
306 #define TX_TIMEOUT 40
308 /* Index to functions, as function prototypes. */
310 static int eepro_probe1(struct net_device *dev, int autoprobe);
311 static int eepro_open(struct net_device *dev);
312 static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev);
313 static irqreturn_t eepro_interrupt(int irq, void *dev_id);
314 static void eepro_rx(struct net_device *dev);
315 static void eepro_transmit_interrupt(struct net_device *dev);
316 static int eepro_close(struct net_device *dev);
317 static void set_multicast_list(struct net_device *dev);
318 static void eepro_tx_timeout (struct net_device *dev);
320 static int read_eeprom(int ioaddr, int location, struct net_device *dev);
321 static int hardware_send_packet(struct net_device *dev, void *buf, short length);
322 static int eepro_grab_irq(struct net_device *dev);
325 Details of the i82595.
327 You will need either the datasheet or the user manual to understand what
328 is going on here. The 82595 is very different from the 82586, 82593.
330 The receive algorithm in eepro_rx() is just an implementation of the
331 RCV ring structure that the Intel 82595 imposes at the hardware level.
332 The receive buffer is set at 24K, and the transmit buffer is 8K. I
333 am assuming that the total buffer memory is 32K, which is true for the
334 Intel EtherExpress Pro/10. If it is less than that on a generic card,
335 the driver will be broken.
337 The transmit algorithm in the hardware_send_packet() is similar to the
338 one in the eepro_rx(). The transmit buffer is a ring linked list.
339 I just queue the next available packet to the end of the list. In my
340 system, the 82595 is so fast that the list seems to always contain a
341 single packet. In other systems with faster computers and more congested
342 network traffics, the ring linked list should improve performance by
343 allowing up to 8K worth of packets to be queued.
345 The sizes of the receive and transmit buffers can now be changed via lilo
346 or insmod. Lilo uses the appended line "ether=io,irq,debug,rx-buffer,eth0"
347 where rx-buffer is in KB unit. Modules uses the parameter mem which is
348 also in KB unit, for example "insmod io=io-address irq=0 mem=rx-buffer."
349 The receive buffer has to be more than 3K or less than 29K. Otherwise,
350 it is reset to the default of 24K, and, hence, 8K for the trasnmit
351 buffer (transmit-buffer = 32K - receive-buffer).
354 #define RAM_SIZE 0x8000
356 #define RCV_HEADER 8
357 #define RCV_DEFAULT_RAM 0x6000
359 #define XMT_HEADER 8
360 #define XMT_DEFAULT_RAM (RAM_SIZE - RCV_DEFAULT_RAM)
362 #define XMT_START_PRO RCV_DEFAULT_RAM
363 #define XMT_START_10 0x0000
364 #define RCV_START_PRO 0x0000
365 #define RCV_START_10 XMT_DEFAULT_RAM
367 #define RCV_DONE 0x0008
368 #define RX_OK 0x2000
369 #define RX_ERROR 0x0d81
371 #define TX_DONE_BIT 0x0080
372 #define TX_OK 0x2000
373 #define CHAIN_BIT 0x8000
374 #define XMT_STATUS 0x02
375 #define XMT_CHAIN 0x04
376 #define XMT_COUNT 0x06
378 #define BANK0_SELECT 0x00
379 #define BANK1_SELECT 0x40
380 #define BANK2_SELECT 0x80
382 /* Bank 0 registers */
383 #define COMMAND_REG 0x00 /* Register 0 */
384 #define MC_SETUP 0x03
385 #define XMT_CMD 0x04
386 #define DIAGNOSE_CMD 0x07
387 #define RCV_ENABLE_CMD 0x08
388 #define RCV_DISABLE_CMD 0x0a
389 #define STOP_RCV_CMD 0x0b
390 #define RESET_CMD 0x0e
391 #define POWER_DOWN_CMD 0x18
392 #define RESUME_XMT_CMD 0x1c
393 #define SEL_RESET_CMD 0x1e
394 #define STATUS_REG 0x01 /* Register 1 */
395 #define RX_INT 0x02
396 #define TX_INT 0x04
397 #define EXEC_STATUS 0x30
398 #define ID_REG 0x02 /* Register 2 */
399 #define R_ROBIN_BITS 0xc0 /* round robin counter */
400 #define ID_REG_MASK 0x2c
401 #define ID_REG_SIG 0x24
402 #define AUTO_ENABLE 0x10
403 #define INT_MASK_REG 0x03 /* Register 3 */
404 #define RX_STOP_MASK 0x01
405 #define RX_MASK 0x02
406 #define TX_MASK 0x04
407 #define EXEC_MASK 0x08
408 #define ALL_MASK 0x0f
409 #define IO_32_BIT 0x10
410 #define RCV_BAR 0x04 /* The following are word (16-bit) registers */
411 #define RCV_STOP 0x06
413 #define XMT_BAR_PRO 0x0a
414 #define XMT_BAR_10 0x0b
416 #define HOST_ADDRESS_REG 0x0c
417 #define IO_PORT 0x0e
418 #define IO_PORT_32_BIT 0x0c
420 /* Bank 1 registers */
421 #define REG1 0x01
422 #define WORD_WIDTH 0x02
423 #define INT_ENABLE 0x80
424 #define INT_NO_REG 0x02
425 #define RCV_LOWER_LIMIT_REG 0x08
426 #define RCV_UPPER_LIMIT_REG 0x09
428 #define XMT_LOWER_LIMIT_REG_PRO 0x0a
429 #define XMT_UPPER_LIMIT_REG_PRO 0x0b
430 #define XMT_LOWER_LIMIT_REG_10 0x0b
431 #define XMT_UPPER_LIMIT_REG_10 0x0a
433 /* Bank 2 registers */
434 #define XMT_Chain_Int 0x20 /* Interrupt at the end of the transmit chain */
435 #define XMT_Chain_ErrStop 0x40 /* Interrupt at the end of the chain even if there are errors */
436 #define RCV_Discard_BadFrame 0x80 /* Throw bad frames away, and continue to receive others */
437 #define REG2 0x02
438 #define PRMSC_Mode 0x01
439 #define Multi_IA 0x20
440 #define REG3 0x03
441 #define TPE_BIT 0x04
442 #define BNC_BIT 0x20
443 #define REG13 0x0d
444 #define FDX 0x00
445 #define A_N_ENABLE 0x02
447 #define I_ADD_REG0 0x04
448 #define I_ADD_REG1 0x05
449 #define I_ADD_REG2 0x06
450 #define I_ADD_REG3 0x07
451 #define I_ADD_REG4 0x08
452 #define I_ADD_REG5 0x09
454 #define EEPROM_REG_PRO 0x0a
455 #define EEPROM_REG_10 0x0b
457 #define EESK 0x01
458 #define EECS 0x02
459 #define EEDI 0x04
460 #define EEDO 0x08
462 /* do a full reset */
463 #define eepro_reset(ioaddr) outb(RESET_CMD, ioaddr)
465 /* do a nice reset */
466 #define eepro_sel_reset(ioaddr) { \
467 outb(SEL_RESET_CMD, ioaddr); \
468 SLOW_DOWN; \
469 SLOW_DOWN; \
472 /* disable all interrupts */
473 #define eepro_dis_int(ioaddr) outb(ALL_MASK, ioaddr + INT_MASK_REG)
475 /* clear all interrupts */
476 #define eepro_clear_int(ioaddr) outb(ALL_MASK, ioaddr + STATUS_REG)
478 /* enable tx/rx */
479 #define eepro_en_int(ioaddr) outb(ALL_MASK & ~(RX_MASK | TX_MASK), \
480 ioaddr + INT_MASK_REG)
482 /* enable exec event interrupt */
483 #define eepro_en_intexec(ioaddr) outb(ALL_MASK & ~(EXEC_MASK), ioaddr + INT_MASK_REG)
485 /* enable rx */
486 #define eepro_en_rx(ioaddr) outb(RCV_ENABLE_CMD, ioaddr)
488 /* disable rx */
489 #define eepro_dis_rx(ioaddr) outb(RCV_DISABLE_CMD, ioaddr)
491 /* switch bank */
492 #define eepro_sw2bank0(ioaddr) outb(BANK0_SELECT, ioaddr)
493 #define eepro_sw2bank1(ioaddr) outb(BANK1_SELECT, ioaddr)
494 #define eepro_sw2bank2(ioaddr) outb(BANK2_SELECT, ioaddr)
496 /* enable interrupt line */
497 #define eepro_en_intline(ioaddr) outb(inb(ioaddr + REG1) | INT_ENABLE,\
498 ioaddr + REG1)
500 /* disable interrupt line */
501 #define eepro_dis_intline(ioaddr) outb(inb(ioaddr + REG1) & 0x7f, \
502 ioaddr + REG1);
504 /* set diagnose flag */
505 #define eepro_diag(ioaddr) outb(DIAGNOSE_CMD, ioaddr)
507 /* ack for rx int */
508 #define eepro_ack_rx(ioaddr) outb (RX_INT, ioaddr + STATUS_REG)
510 /* ack for tx int */
511 #define eepro_ack_tx(ioaddr) outb (TX_INT, ioaddr + STATUS_REG)
513 /* a complete sel reset */
514 #define eepro_complete_selreset(ioaddr) { \
515 dev->stats.tx_errors++;\
516 eepro_sel_reset(ioaddr);\
517 lp->tx_end = \
518 lp->xmt_lower_limit;\
519 lp->tx_start = lp->tx_end;\
520 lp->tx_last = 0;\
521 dev->trans_start = jiffies;\
522 netif_wake_queue(dev);\
523 eepro_en_rx(ioaddr);\
526 /* Check for a network adaptor of this type, and return '0' if one exists.
527 If dev->base_addr == 0, probe all likely locations.
528 If dev->base_addr == 1, always return failure.
529 If dev->base_addr == 2, allocate space for the device and return success
530 (detachable devices only).
532 static int __init do_eepro_probe(struct net_device *dev)
534 int i;
535 int base_addr = dev->base_addr;
536 int irq = dev->irq;
538 #ifdef PnPWakeup
539 /* XXXX for multiple cards should this only be run once? */
541 /* Wakeup: */
542 #define WakeupPort 0x279
543 #define WakeupSeq {0x6A, 0xB5, 0xDA, 0xED, 0xF6, 0xFB, 0x7D, 0xBE,\
544 0xDF, 0x6F, 0x37, 0x1B, 0x0D, 0x86, 0xC3, 0x61,\
545 0xB0, 0x58, 0x2C, 0x16, 0x8B, 0x45, 0xA2, 0xD1,\
546 0xE8, 0x74, 0x3A, 0x9D, 0xCE, 0xE7, 0x73, 0x43}
549 unsigned short int WS[32]=WakeupSeq;
551 if (request_region(WakeupPort, 2, "eepro wakeup")) {
552 if (net_debug>5)
553 printk(KERN_DEBUG "Waking UP\n");
555 outb_p(0,WakeupPort);
556 outb_p(0,WakeupPort);
557 for (i=0; i<32; i++) {
558 outb_p(WS[i],WakeupPort);
559 if (net_debug>5) printk(KERN_DEBUG ": %#x ",WS[i]);
562 release_region(WakeupPort, 2);
563 } else
564 printk(KERN_WARNING "PnP wakeup region busy!\n");
566 #endif
568 if (base_addr > 0x1ff) /* Check a single specified location. */
569 return eepro_probe1(dev, 0);
571 else if (base_addr != 0) /* Don't probe at all. */
572 return -ENXIO;
574 for (i = 0; eepro_portlist[i]; i++) {
575 dev->base_addr = eepro_portlist[i];
576 dev->irq = irq;
577 if (eepro_probe1(dev, 1) == 0)
578 return 0;
581 return -ENODEV;
584 #ifndef MODULE
585 struct net_device * __init eepro_probe(int unit)
587 struct net_device *dev = alloc_etherdev(sizeof(struct eepro_local));
588 int err;
590 if (!dev)
591 return ERR_PTR(-ENODEV);
593 sprintf(dev->name, "eth%d", unit);
594 netdev_boot_setup_check(dev);
596 err = do_eepro_probe(dev);
597 if (err)
598 goto out;
599 return dev;
600 out:
601 free_netdev(dev);
602 return ERR_PTR(err);
604 #endif
606 static void __init printEEPROMInfo(struct net_device *dev)
608 struct eepro_local *lp = (struct eepro_local *)dev->priv;
609 int ioaddr = dev->base_addr;
610 unsigned short Word;
611 int i,j;
613 j = ee_Checksum;
614 for (i = 0; i < 8; i++)
615 j += lp->word[i];
616 for ( ; i < ee_SIZE; i++)
617 j += read_eeprom(ioaddr, i, dev);
619 printk(KERN_DEBUG "Checksum: %#x\n",j&0xffff);
621 Word = lp->word[0];
622 printk(KERN_DEBUG "Word0:\n");
623 printk(KERN_DEBUG " Plug 'n Pray: %d\n",GetBit(Word,ee_PnP));
624 printk(KERN_DEBUG " Buswidth: %d\n",(GetBit(Word,ee_BusWidth)+1)*8 );
625 printk(KERN_DEBUG " AutoNegotiation: %d\n",GetBit(Word,ee_AutoNeg));
626 printk(KERN_DEBUG " IO Address: %#x\n", (Word>>ee_IO0)<<4);
628 if (net_debug>4) {
629 Word = lp->word[1];
630 printk(KERN_DEBUG "Word1:\n");
631 printk(KERN_DEBUG " INT: %d\n", Word & ee_IntMask);
632 printk(KERN_DEBUG " LI: %d\n", GetBit(Word,ee_LI));
633 printk(KERN_DEBUG " PC: %d\n", GetBit(Word,ee_PC));
634 printk(KERN_DEBUG " TPE/AUI: %d\n", GetBit(Word,ee_TPE_AUI));
635 printk(KERN_DEBUG " Jabber: %d\n", GetBit(Word,ee_Jabber));
636 printk(KERN_DEBUG " AutoPort: %d\n", !GetBit(Word,ee_AutoPort));
637 printk(KERN_DEBUG " Duplex: %d\n", GetBit(Word,ee_Duplex));
640 Word = lp->word[5];
641 printk(KERN_DEBUG "Word5:\n");
642 printk(KERN_DEBUG " BNC: %d\n",GetBit(Word,ee_BNC_TPE));
643 printk(KERN_DEBUG " NumConnectors: %d\n",GetBit(Word,ee_NumConn));
644 printk(KERN_DEBUG " Has ");
645 if (GetBit(Word,ee_PortTPE)) printk(KERN_DEBUG "TPE ");
646 if (GetBit(Word,ee_PortBNC)) printk(KERN_DEBUG "BNC ");
647 if (GetBit(Word,ee_PortAUI)) printk(KERN_DEBUG "AUI ");
648 printk(KERN_DEBUG "port(s) \n");
650 Word = lp->word[6];
651 printk(KERN_DEBUG "Word6:\n");
652 printk(KERN_DEBUG " Stepping: %d\n",Word & ee_StepMask);
653 printk(KERN_DEBUG " BoardID: %d\n",Word>>ee_BoardID);
655 Word = lp->word[7];
656 printk(KERN_DEBUG "Word7:\n");
657 printk(KERN_DEBUG " INT to IRQ:\n");
659 for (i=0, j=0; i<15; i++)
660 if (GetBit(Word,i)) printk(KERN_DEBUG " INT%d -> IRQ %d;",j++,i);
662 printk(KERN_DEBUG "\n");
665 /* function to recalculate the limits of buffer based on rcv_ram */
666 static void eepro_recalc (struct net_device *dev)
668 struct eepro_local * lp;
670 lp = netdev_priv(dev);
671 lp->xmt_ram = RAM_SIZE - lp->rcv_ram;
673 if (lp->eepro == LAN595FX_10ISA) {
674 lp->xmt_lower_limit = XMT_START_10;
675 lp->xmt_upper_limit = (lp->xmt_ram - 2);
676 lp->rcv_lower_limit = lp->xmt_ram;
677 lp->rcv_upper_limit = (RAM_SIZE - 2);
679 else {
680 lp->rcv_lower_limit = RCV_START_PRO;
681 lp->rcv_upper_limit = (lp->rcv_ram - 2);
682 lp->xmt_lower_limit = lp->rcv_ram;
683 lp->xmt_upper_limit = (RAM_SIZE - 2);
687 /* prints boot-time info */
688 static void __init eepro_print_info (struct net_device *dev)
690 struct eepro_local * lp = netdev_priv(dev);
691 int i;
692 const char * ifmap[] = {"AUI", "10Base2", "10BaseT"};
693 DECLARE_MAC_BUF(mac);
695 i = inb(dev->base_addr + ID_REG);
696 printk(KERN_DEBUG " id: %#x ",i);
697 printk(" io: %#x ", (unsigned)dev->base_addr);
699 switch (lp->eepro) {
700 case LAN595FX_10ISA:
701 printk("%s: Intel EtherExpress 10 ISA\n at %#x,",
702 dev->name, (unsigned)dev->base_addr);
703 break;
704 case LAN595FX:
705 printk("%s: Intel EtherExpress Pro/10+ ISA\n at %#x,",
706 dev->name, (unsigned)dev->base_addr);
707 break;
708 case LAN595TX:
709 printk("%s: Intel EtherExpress Pro/10 ISA at %#x,",
710 dev->name, (unsigned)dev->base_addr);
711 break;
712 case LAN595:
713 printk("%s: Intel 82595-based lan card at %#x,",
714 dev->name, (unsigned)dev->base_addr);
715 break;
718 printk(" %s", print_mac(mac, dev->dev_addr));
720 if (net_debug > 3)
721 printk(KERN_DEBUG ", %dK RCV buffer",
722 (int)(lp->rcv_ram)/1024);
724 if (dev->irq > 2)
725 printk(", IRQ %d, %s.\n", dev->irq, ifmap[dev->if_port]);
726 else
727 printk(", %s.\n", ifmap[dev->if_port]);
729 if (net_debug > 3) {
730 i = lp->word[5];
731 if (i & 0x2000) /* bit 13 of EEPROM word 5 */
732 printk(KERN_DEBUG "%s: Concurrent Processing is "
733 "enabled but not used!\n", dev->name);
736 /* Check the station address for the manufacturer's code */
737 if (net_debug>3)
738 printEEPROMInfo(dev);
741 static const struct ethtool_ops eepro_ethtool_ops;
743 /* This is the real probe routine. Linux has a history of friendly device
744 probes on the ISA bus. A good device probe avoids doing writes, and
745 verifies that the correct device exists and functions. */
747 static int __init eepro_probe1(struct net_device *dev, int autoprobe)
749 unsigned short station_addr[3], id, counter;
750 int i;
751 struct eepro_local *lp;
752 int ioaddr = dev->base_addr;
753 int err;
755 /* Grab the region so we can find another board if autoIRQ fails. */
756 if (!request_region(ioaddr, EEPRO_IO_EXTENT, DRV_NAME)) {
757 if (!autoprobe)
758 printk(KERN_WARNING "EEPRO: io-port 0x%04x in use \n",
759 ioaddr);
760 return -EBUSY;
763 /* Now, we are going to check for the signature of the
764 ID_REG (register 2 of bank 0) */
766 id = inb(ioaddr + ID_REG);
768 if ((id & ID_REG_MASK) != ID_REG_SIG)
769 goto exit;
771 /* We seem to have the 82595 signature, let's
772 play with its counter (last 2 bits of
773 register 2 of bank 0) to be sure. */
775 counter = id & R_ROBIN_BITS;
777 if ((inb(ioaddr + ID_REG) & R_ROBIN_BITS) != (counter + 0x40))
778 goto exit;
780 lp = netdev_priv(dev);
781 memset(lp, 0, sizeof(struct eepro_local));
782 lp->xmt_bar = XMT_BAR_PRO;
783 lp->xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_PRO;
784 lp->xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_PRO;
785 lp->eeprom_reg = EEPROM_REG_PRO;
786 spin_lock_init(&lp->lock);
788 /* Now, get the ethernet hardware address from
789 the EEPROM */
790 station_addr[0] = read_eeprom(ioaddr, 2, dev);
792 /* FIXME - find another way to know that we've found
793 * an Etherexpress 10
795 if (station_addr[0] == 0x0000 || station_addr[0] == 0xffff) {
796 lp->eepro = LAN595FX_10ISA;
797 lp->eeprom_reg = EEPROM_REG_10;
798 lp->xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_10;
799 lp->xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_10;
800 lp->xmt_bar = XMT_BAR_10;
801 station_addr[0] = read_eeprom(ioaddr, 2, dev);
804 /* get all words at once. will be used here and for ethtool */
805 for (i = 0; i < 8; i++) {
806 lp->word[i] = read_eeprom(ioaddr, i, dev);
808 station_addr[1] = lp->word[3];
809 station_addr[2] = lp->word[4];
811 if (!lp->eepro) {
812 if (lp->word[7] == ee_FX_INT2IRQ)
813 lp->eepro = 2;
814 else if (station_addr[2] == SA_ADDR1)
815 lp->eepro = 1;
818 /* Fill in the 'dev' fields. */
819 for (i=0; i < 6; i++)
820 dev->dev_addr[i] = ((unsigned char *) station_addr)[5-i];
822 /* RX buffer must be more than 3K and less than 29K */
823 if (dev->mem_end < 3072 || dev->mem_end > 29696)
824 lp->rcv_ram = RCV_DEFAULT_RAM;
826 /* calculate {xmt,rcv}_{lower,upper}_limit */
827 eepro_recalc(dev);
829 if (GetBit(lp->word[5], ee_BNC_TPE))
830 dev->if_port = BNC;
831 else
832 dev->if_port = TPE;
834 if (dev->irq < 2 && lp->eepro != 0) {
835 /* Mask off INT number */
836 int count = lp->word[1] & 7;
837 unsigned irqMask = lp->word[7];
839 while (count--)
840 irqMask &= irqMask - 1;
842 count = ffs(irqMask);
844 if (count)
845 dev->irq = count - 1;
847 if (dev->irq < 2) {
848 printk(KERN_ERR " Duh! illegal interrupt vector stored in EEPROM.\n");
849 goto exit;
850 } else if (dev->irq == 2) {
851 dev->irq = 9;
855 dev->open = eepro_open;
856 dev->stop = eepro_close;
857 dev->hard_start_xmit = eepro_send_packet;
858 dev->set_multicast_list = &set_multicast_list;
859 dev->tx_timeout = eepro_tx_timeout;
860 dev->watchdog_timeo = TX_TIMEOUT;
861 dev->ethtool_ops = &eepro_ethtool_ops;
863 /* print boot time info */
864 eepro_print_info(dev);
866 /* reset 82595 */
867 eepro_reset(ioaddr);
869 err = register_netdev(dev);
870 if (err)
871 goto err;
872 return 0;
873 exit:
874 err = -ENODEV;
875 err:
876 release_region(dev->base_addr, EEPRO_IO_EXTENT);
877 return err;
880 /* Open/initialize the board. This is called (in the current kernel)
881 sometime after booting when the 'ifconfig' program is run.
883 This routine should set everything up anew at each open, even
884 registers that "should" only need to be set once at boot, so that
885 there is non-reboot way to recover if something goes wrong.
888 static char irqrmap[] = {-1,-1,0,1,-1,2,-1,-1,-1,0,3,4,-1,-1,-1,-1};
889 static char irqrmap2[] = {-1,-1,4,0,1,2,-1,3,-1,4,5,6,7,-1,-1,-1};
890 static int eepro_grab_irq(struct net_device *dev)
892 int irqlist[] = { 3, 4, 5, 7, 9, 10, 11, 12, 0 };
893 int *irqp = irqlist, temp_reg, ioaddr = dev->base_addr;
895 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
897 /* Enable the interrupt line. */
898 eepro_en_intline(ioaddr);
900 /* be CAREFUL, BANK 0 now */
901 eepro_sw2bank0(ioaddr);
903 /* clear all interrupts */
904 eepro_clear_int(ioaddr);
906 /* Let EXEC event to interrupt */
907 eepro_en_intexec(ioaddr);
909 do {
910 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
912 temp_reg = inb(ioaddr + INT_NO_REG);
913 outb((temp_reg & 0xf8) | irqrmap[*irqp], ioaddr + INT_NO_REG);
915 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
917 if (request_irq (*irqp, NULL, IRQF_SHARED, "bogus", dev) != EBUSY) {
918 unsigned long irq_mask;
919 /* Twinkle the interrupt, and check if it's seen */
920 irq_mask = probe_irq_on();
922 eepro_diag(ioaddr); /* RESET the 82595 */
923 mdelay(20);
925 if (*irqp == probe_irq_off(irq_mask)) /* It's a good IRQ line */
926 break;
928 /* clear all interrupts */
929 eepro_clear_int(ioaddr);
931 } while (*++irqp);
933 eepro_sw2bank1(ioaddr); /* Switch back to Bank 1 */
935 /* Disable the physical interrupt line. */
936 eepro_dis_intline(ioaddr);
938 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
940 /* Mask all the interrupts. */
941 eepro_dis_int(ioaddr);
943 /* clear all interrupts */
944 eepro_clear_int(ioaddr);
946 return dev->irq;
949 static int eepro_open(struct net_device *dev)
951 unsigned short temp_reg, old8, old9;
952 int irqMask;
953 int i, ioaddr = dev->base_addr;
954 struct eepro_local *lp = netdev_priv(dev);
956 if (net_debug > 3)
957 printk(KERN_DEBUG "%s: entering eepro_open routine.\n", dev->name);
959 irqMask = lp->word[7];
961 if (lp->eepro == LAN595FX_10ISA) {
962 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 3;\n");
964 else if (irqMask == ee_FX_INT2IRQ) /* INT to IRQ Mask */
966 lp->eepro = 2; /* Yes, an Intel EtherExpress Pro/10+ */
967 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 2;\n");
970 else if ((dev->dev_addr[0] == SA_ADDR0 &&
971 dev->dev_addr[1] == SA_ADDR1 &&
972 dev->dev_addr[2] == SA_ADDR2))
974 lp->eepro = 1;
975 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 1;\n");
976 } /* Yes, an Intel EtherExpress Pro/10 */
978 else lp->eepro = 0; /* No, it is a generic 82585 lan card */
980 /* Get the interrupt vector for the 82595 */
981 if (dev->irq < 2 && eepro_grab_irq(dev) == 0) {
982 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
983 return -EAGAIN;
986 if (request_irq(dev->irq , &eepro_interrupt, 0, dev->name, dev)) {
987 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
988 return -EAGAIN;
991 /* Initialize the 82595. */
993 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
994 temp_reg = inb(ioaddr + lp->eeprom_reg);
996 lp->stepping = temp_reg >> 5; /* Get the stepping number of the 595 */
998 if (net_debug > 3)
999 printk(KERN_DEBUG "The stepping of the 82595 is %d\n", lp->stepping);
1001 if (temp_reg & 0x10) /* Check the TurnOff Enable bit */
1002 outb(temp_reg & 0xef, ioaddr + lp->eeprom_reg);
1003 for (i=0; i < 6; i++)
1004 outb(dev->dev_addr[i] , ioaddr + I_ADD_REG0 + i);
1006 temp_reg = inb(ioaddr + REG1); /* Setup Transmit Chaining */
1007 outb(temp_reg | XMT_Chain_Int | XMT_Chain_ErrStop /* and discard bad RCV frames */
1008 | RCV_Discard_BadFrame, ioaddr + REG1);
1010 temp_reg = inb(ioaddr + REG2); /* Match broadcast */
1011 outb(temp_reg | 0x14, ioaddr + REG2);
1013 temp_reg = inb(ioaddr + REG3);
1014 outb(temp_reg & 0x3f, ioaddr + REG3); /* clear test mode */
1016 /* Set the receiving mode */
1017 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
1019 /* Set the interrupt vector */
1020 temp_reg = inb(ioaddr + INT_NO_REG);
1021 if (lp->eepro == LAN595FX || lp->eepro == LAN595FX_10ISA)
1022 outb((temp_reg & 0xf8) | irqrmap2[dev->irq], ioaddr + INT_NO_REG);
1023 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
1026 temp_reg = inb(ioaddr + INT_NO_REG);
1027 if (lp->eepro == LAN595FX || lp->eepro == LAN595FX_10ISA)
1028 outb((temp_reg & 0xf0) | irqrmap2[dev->irq] | 0x08,ioaddr+INT_NO_REG);
1029 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
1031 if (net_debug > 3)
1032 printk(KERN_DEBUG "eepro_open: content of INT Reg is %x\n", temp_reg);
1035 /* Initialize the RCV and XMT upper and lower limits */
1036 outb(lp->rcv_lower_limit >> 8, ioaddr + RCV_LOWER_LIMIT_REG);
1037 outb(lp->rcv_upper_limit >> 8, ioaddr + RCV_UPPER_LIMIT_REG);
1038 outb(lp->xmt_lower_limit >> 8, ioaddr + lp->xmt_lower_limit_reg);
1039 outb(lp->xmt_upper_limit >> 8, ioaddr + lp->xmt_upper_limit_reg);
1041 /* Enable the interrupt line. */
1042 eepro_en_intline(ioaddr);
1044 /* Switch back to Bank 0 */
1045 eepro_sw2bank0(ioaddr);
1047 /* Let RX and TX events to interrupt */
1048 eepro_en_int(ioaddr);
1050 /* clear all interrupts */
1051 eepro_clear_int(ioaddr);
1053 /* Initialize RCV */
1054 outw(lp->rcv_lower_limit, ioaddr + RCV_BAR);
1055 lp->rx_start = lp->rcv_lower_limit;
1056 outw(lp->rcv_upper_limit | 0xfe, ioaddr + RCV_STOP);
1058 /* Initialize XMT */
1059 outw(lp->xmt_lower_limit, ioaddr + lp->xmt_bar);
1060 lp->tx_start = lp->tx_end = lp->xmt_lower_limit;
1061 lp->tx_last = 0;
1063 /* Check for the i82595TX and i82595FX */
1064 old8 = inb(ioaddr + 8);
1065 outb(~old8, ioaddr + 8);
1067 if ((temp_reg = inb(ioaddr + 8)) == old8) {
1068 if (net_debug > 3)
1069 printk(KERN_DEBUG "i82595 detected!\n");
1070 lp->version = LAN595;
1072 else {
1073 lp->version = LAN595TX;
1074 outb(old8, ioaddr + 8);
1075 old9 = inb(ioaddr + 9);
1077 if (irqMask==ee_FX_INT2IRQ) {
1078 if (net_debug > 3) {
1079 printk(KERN_DEBUG "IrqMask: %#x\n",irqMask);
1080 printk(KERN_DEBUG "i82595FX detected!\n");
1082 lp->version = LAN595FX;
1083 outb(old9, ioaddr + 9);
1084 if (dev->if_port != TPE) { /* Hopefully, this will fix the
1085 problem of using Pentiums and
1086 pro/10 w/ BNC. */
1087 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1088 temp_reg = inb(ioaddr + REG13);
1089 /* disable the full duplex mode since it is not
1090 applicable with the 10Base2 cable. */
1091 outb(temp_reg & ~(FDX | A_N_ENABLE), REG13);
1092 eepro_sw2bank0(ioaddr); /* be CAREFUL, BANK 0 now */
1095 else if (net_debug > 3) {
1096 printk(KERN_DEBUG "temp_reg: %#x ~old9: %#x\n",temp_reg,((~old9)&0xff));
1097 printk(KERN_DEBUG "i82595TX detected!\n");
1101 eepro_sel_reset(ioaddr);
1103 netif_start_queue(dev);
1105 if (net_debug > 3)
1106 printk(KERN_DEBUG "%s: exiting eepro_open routine.\n", dev->name);
1108 /* enabling rx */
1109 eepro_en_rx(ioaddr);
1111 return 0;
1114 static void eepro_tx_timeout (struct net_device *dev)
1116 struct eepro_local *lp = netdev_priv(dev);
1117 int ioaddr = dev->base_addr;
1119 /* if (net_debug > 1) */
1120 printk (KERN_ERR "%s: transmit timed out, %s?\n", dev->name,
1121 "network cable problem");
1122 /* This is not a duplicate. One message for the console,
1123 one for the log file */
1124 printk (KERN_DEBUG "%s: transmit timed out, %s?\n", dev->name,
1125 "network cable problem");
1126 eepro_complete_selreset(ioaddr);
1130 static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev)
1132 struct eepro_local *lp = netdev_priv(dev);
1133 unsigned long flags;
1134 int ioaddr = dev->base_addr;
1135 short length = skb->len;
1137 if (net_debug > 5)
1138 printk(KERN_DEBUG "%s: entering eepro_send_packet routine.\n", dev->name);
1140 if (length < ETH_ZLEN) {
1141 if (skb_padto(skb, ETH_ZLEN))
1142 return 0;
1143 length = ETH_ZLEN;
1145 netif_stop_queue (dev);
1147 eepro_dis_int(ioaddr);
1148 spin_lock_irqsave(&lp->lock, flags);
1151 unsigned char *buf = skb->data;
1153 if (hardware_send_packet(dev, buf, length))
1154 /* we won't wake queue here because we're out of space */
1155 dev->stats.tx_dropped++;
1156 else {
1157 dev->stats.tx_bytes+=skb->len;
1158 dev->trans_start = jiffies;
1159 netif_wake_queue(dev);
1164 dev_kfree_skb (skb);
1166 /* You might need to clean up and record Tx statistics here. */
1167 /* dev->stats.tx_aborted_errors++; */
1169 if (net_debug > 5)
1170 printk(KERN_DEBUG "%s: exiting eepro_send_packet routine.\n", dev->name);
1172 eepro_en_int(ioaddr);
1173 spin_unlock_irqrestore(&lp->lock, flags);
1175 return 0;
1179 /* The typical workload of the driver:
1180 Handle the network interface interrupts. */
1182 static irqreturn_t
1183 eepro_interrupt(int irq, void *dev_id)
1185 struct net_device *dev = dev_id;
1186 struct eepro_local *lp;
1187 int ioaddr, status, boguscount = 20;
1188 int handled = 0;
1190 lp = netdev_priv(dev);
1192 spin_lock(&lp->lock);
1194 if (net_debug > 5)
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--))
1201 handled = 1;
1202 if (status & RX_INT) {
1203 if (net_debug > 4)
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);
1210 eepro_rx(dev);
1212 eepro_en_int(ioaddr);
1214 if (status & TX_INT) {
1215 if (net_debug > 4)
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);
1229 if (net_debug > 5)
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;
1240 short temp_reg;
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;
1255 lp->tx_last = 0;
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);
1269 /* Update the statistics here. What statistics? */
1271 return 0;
1274 /* Set or clear the multicast filter for this adaptor.
1276 static void
1277 set_multicast_list(struct net_device *dev)
1279 struct eepro_local *lp = netdev_priv(dev);
1280 short ioaddr = dev->base_addr;
1281 unsigned short mode;
1282 struct dev_mc_list *dmi=dev->mc_list;
1284 if (dev->flags&(IFF_ALLMULTI|IFF_PROMISC) || dev->mc_count > 63)
1286 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1287 mode = inb(ioaddr + REG2);
1288 outb(mode | PRMSC_Mode, ioaddr + REG2);
1289 mode = inb(ioaddr + REG3);
1290 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1291 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1294 else if (dev->mc_count==0 )
1296 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1297 mode = inb(ioaddr + REG2);
1298 outb(mode & 0xd6, ioaddr + REG2); /* Turn off Multi-IA and PRMSC_Mode bits */
1299 mode = inb(ioaddr + REG3);
1300 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1301 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1304 else
1306 unsigned short status, *eaddrs;
1307 int i, boguscount = 0;
1309 /* Disable RX and TX interrupts. Necessary to avoid
1310 corruption of the HOST_ADDRESS_REG by interrupt
1311 service routines. */
1312 eepro_dis_int(ioaddr);
1314 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1315 mode = inb(ioaddr + REG2);
1316 outb(mode | Multi_IA, ioaddr + REG2);
1317 mode = inb(ioaddr + REG3);
1318 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1319 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1320 outw(lp->tx_end, ioaddr + HOST_ADDRESS_REG);
1321 outw(MC_SETUP, ioaddr + IO_PORT);
1322 outw(0, ioaddr + IO_PORT);
1323 outw(0, ioaddr + IO_PORT);
1324 outw(6*(dev->mc_count + 1), ioaddr + IO_PORT);
1326 for (i = 0; i < dev->mc_count; i++)
1328 eaddrs=(unsigned short *)dmi->dmi_addr;
1329 dmi=dmi->next;
1330 outw(*eaddrs++, ioaddr + IO_PORT);
1331 outw(*eaddrs++, ioaddr + IO_PORT);
1332 outw(*eaddrs++, ioaddr + IO_PORT);
1335 eaddrs = (unsigned short *) dev->dev_addr;
1336 outw(eaddrs[0], ioaddr + IO_PORT);
1337 outw(eaddrs[1], ioaddr + IO_PORT);
1338 outw(eaddrs[2], ioaddr + IO_PORT);
1339 outw(lp->tx_end, ioaddr + lp->xmt_bar);
1340 outb(MC_SETUP, ioaddr);
1342 /* Update the transmit queue */
1343 i = lp->tx_end + XMT_HEADER + 6*(dev->mc_count + 1);
1345 if (lp->tx_start != lp->tx_end)
1347 /* update the next address and the chain bit in the
1348 last packet */
1349 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1350 outw(i, ioaddr + IO_PORT);
1351 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1352 status = inw(ioaddr + IO_PORT);
1353 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1354 lp->tx_end = i ;
1356 else {
1357 lp->tx_start = lp->tx_end = i ;
1360 /* Acknowledge that the MC setup is done */
1361 do { /* We should be doing this in the eepro_interrupt()! */
1362 SLOW_DOWN;
1363 SLOW_DOWN;
1364 if (inb(ioaddr + STATUS_REG) & 0x08)
1366 i = inb(ioaddr);
1367 outb(0x08, ioaddr + STATUS_REG);
1369 if (i & 0x20) { /* command ABORTed */
1370 printk(KERN_NOTICE "%s: multicast setup failed.\n",
1371 dev->name);
1372 break;
1373 } else if ((i & 0x0f) == 0x03) { /* MC-Done */
1374 printk(KERN_DEBUG "%s: set Rx mode to %d address%s.\n",
1375 dev->name, dev->mc_count,
1376 dev->mc_count > 1 ? "es":"");
1377 break;
1380 } while (++boguscount < 100);
1382 /* Re-enable RX and TX interrupts */
1383 eepro_en_int(ioaddr);
1385 if (lp->eepro == LAN595FX_10ISA) {
1386 eepro_complete_selreset(ioaddr);
1388 else
1389 eepro_en_rx(ioaddr);
1392 /* The horrible routine to read a word from the serial EEPROM. */
1393 /* IMPORTANT - the 82595 will be set to Bank 0 after the eeprom is read */
1395 /* The delay between EEPROM clock transitions. */
1396 #define eeprom_delay() { udelay(40); }
1397 #define EE_READ_CMD (6 << 6)
1400 read_eeprom(int ioaddr, int location, struct net_device *dev)
1402 int i;
1403 unsigned short retval = 0;
1404 struct eepro_local *lp = netdev_priv(dev);
1405 short ee_addr = ioaddr + lp->eeprom_reg;
1406 int read_cmd = location | EE_READ_CMD;
1407 short ctrl_val = EECS ;
1409 /* XXXX - black magic */
1410 eepro_sw2bank1(ioaddr);
1411 outb(0x00, ioaddr + STATUS_REG);
1412 /* XXXX - black magic */
1414 eepro_sw2bank2(ioaddr);
1415 outb(ctrl_val, ee_addr);
1417 /* Shift the read command bits out. */
1418 for (i = 8; i >= 0; i--) {
1419 short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI
1420 : ctrl_val;
1421 outb(outval, ee_addr);
1422 outb(outval | EESK, ee_addr); /* EEPROM clock tick. */
1423 eeprom_delay();
1424 outb(outval, ee_addr); /* Finish EEPROM a clock tick. */
1425 eeprom_delay();
1427 outb(ctrl_val, ee_addr);
1429 for (i = 16; i > 0; i--) {
1430 outb(ctrl_val | EESK, ee_addr); eeprom_delay();
1431 retval = (retval << 1) | ((inb(ee_addr) & EEDO) ? 1 : 0);
1432 outb(ctrl_val, ee_addr); eeprom_delay();
1435 /* Terminate the EEPROM access. */
1436 ctrl_val &= ~EECS;
1437 outb(ctrl_val | EESK, ee_addr);
1438 eeprom_delay();
1439 outb(ctrl_val, ee_addr);
1440 eeprom_delay();
1441 eepro_sw2bank0(ioaddr);
1442 return retval;
1445 static int
1446 hardware_send_packet(struct net_device *dev, void *buf, short length)
1448 struct eepro_local *lp = netdev_priv(dev);
1449 short ioaddr = dev->base_addr;
1450 unsigned status, tx_available, last, end;
1452 if (net_debug > 5)
1453 printk(KERN_DEBUG "%s: entering hardware_send_packet routine.\n", dev->name);
1455 /* determine how much of the transmit buffer space is available */
1456 if (lp->tx_end > lp->tx_start)
1457 tx_available = lp->xmt_ram - (lp->tx_end - lp->tx_start);
1458 else if (lp->tx_end < lp->tx_start)
1459 tx_available = lp->tx_start - lp->tx_end;
1460 else tx_available = lp->xmt_ram;
1462 if (((((length + 3) >> 1) << 1) + 2*XMT_HEADER) >= tx_available) {
1463 /* No space available ??? */
1464 return 1;
1467 last = lp->tx_end;
1468 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1470 if (end >= lp->xmt_upper_limit + 2) { /* the transmit buffer is wrapped around */
1471 if ((lp->xmt_upper_limit + 2 - last) <= XMT_HEADER) {
1472 /* Arrrr!!!, must keep the xmt header together,
1473 several days were lost to chase this one down. */
1474 last = lp->xmt_lower_limit;
1475 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1477 else end = lp->xmt_lower_limit + (end -
1478 lp->xmt_upper_limit + 2);
1481 outw(last, ioaddr + HOST_ADDRESS_REG);
1482 outw(XMT_CMD, ioaddr + IO_PORT);
1483 outw(0, ioaddr + IO_PORT);
1484 outw(end, ioaddr + IO_PORT);
1485 outw(length, ioaddr + IO_PORT);
1487 if (lp->version == LAN595)
1488 outsw(ioaddr + IO_PORT, buf, (length + 3) >> 1);
1489 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1490 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1491 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1492 outsl(ioaddr + IO_PORT_32_BIT, buf, (length + 3) >> 2);
1493 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1496 /* A dummy read to flush the DRAM write pipeline */
1497 status = inw(ioaddr + IO_PORT);
1499 if (lp->tx_start == lp->tx_end) {
1500 outw(last, ioaddr + lp->xmt_bar);
1501 outb(XMT_CMD, ioaddr);
1502 lp->tx_start = last; /* I don't like to change tx_start here */
1504 else {
1505 /* update the next address and the chain bit in the
1506 last packet */
1508 if (lp->tx_end != last) {
1509 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1510 outw(last, ioaddr + IO_PORT);
1513 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1514 status = inw(ioaddr + IO_PORT);
1515 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1517 /* Continue the transmit command */
1518 outb(RESUME_XMT_CMD, ioaddr);
1521 lp->tx_last = last;
1522 lp->tx_end = end;
1524 if (net_debug > 5)
1525 printk(KERN_DEBUG "%s: exiting hardware_send_packet routine.\n", dev->name);
1527 return 0;
1530 static void
1531 eepro_rx(struct net_device *dev)
1533 struct eepro_local *lp = netdev_priv(dev);
1534 short ioaddr = dev->base_addr;
1535 short boguscount = 20;
1536 short rcv_car = lp->rx_start;
1537 unsigned rcv_event, rcv_status, rcv_next_frame, rcv_size;
1539 if (net_debug > 5)
1540 printk(KERN_DEBUG "%s: entering eepro_rx routine.\n", dev->name);
1542 /* Set the read pointer to the start of the RCV */
1543 outw(rcv_car, ioaddr + HOST_ADDRESS_REG);
1545 rcv_event = inw(ioaddr + IO_PORT);
1547 while (rcv_event == RCV_DONE) {
1549 rcv_status = inw(ioaddr + IO_PORT);
1550 rcv_next_frame = inw(ioaddr + IO_PORT);
1551 rcv_size = inw(ioaddr + IO_PORT);
1553 if ((rcv_status & (RX_OK | RX_ERROR)) == RX_OK) {
1555 /* Malloc up new buffer. */
1556 struct sk_buff *skb;
1558 dev->stats.rx_bytes+=rcv_size;
1559 rcv_size &= 0x3fff;
1560 skb = dev_alloc_skb(rcv_size+5);
1561 if (skb == NULL) {
1562 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
1563 dev->stats.rx_dropped++;
1564 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1565 lp->rx_start = rcv_next_frame;
1566 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1568 break;
1570 skb_reserve(skb,2);
1572 if (lp->version == LAN595)
1573 insw(ioaddr+IO_PORT, skb_put(skb,rcv_size), (rcv_size + 3) >> 1);
1574 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1575 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1576 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1577 insl(ioaddr+IO_PORT_32_BIT, skb_put(skb,rcv_size),
1578 (rcv_size + 3) >> 2);
1579 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1582 skb->protocol = eth_type_trans(skb,dev);
1583 netif_rx(skb);
1584 dev->last_rx = jiffies;
1585 dev->stats.rx_packets++;
1588 else { /* Not sure will ever reach here,
1589 I set the 595 to discard bad received frames */
1590 dev->stats.rx_errors++;
1592 if (rcv_status & 0x0100)
1593 dev->stats.rx_over_errors++;
1595 else if (rcv_status & 0x0400)
1596 dev->stats.rx_frame_errors++;
1598 else if (rcv_status & 0x0800)
1599 dev->stats.rx_crc_errors++;
1601 printk(KERN_DEBUG "%s: event = %#x, status = %#x, next = %#x, size = %#x\n",
1602 dev->name, rcv_event, rcv_status, rcv_next_frame, rcv_size);
1605 if (rcv_status & 0x1000)
1606 dev->stats.rx_length_errors++;
1608 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1609 lp->rx_start = rcv_next_frame;
1611 if (--boguscount == 0)
1612 break;
1614 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1615 rcv_event = inw(ioaddr + IO_PORT);
1618 if (rcv_car == 0)
1619 rcv_car = lp->rcv_upper_limit | 0xff;
1621 outw(rcv_car - 1, ioaddr + RCV_STOP);
1623 if (net_debug > 5)
1624 printk(KERN_DEBUG "%s: exiting eepro_rx routine.\n", dev->name);
1627 static void
1628 eepro_transmit_interrupt(struct net_device *dev)
1630 struct eepro_local *lp = netdev_priv(dev);
1631 short ioaddr = dev->base_addr;
1632 short boguscount = 25;
1633 short xmt_status;
1635 while ((lp->tx_start != lp->tx_end) && boguscount--) {
1637 outw(lp->tx_start, ioaddr + HOST_ADDRESS_REG);
1638 xmt_status = inw(ioaddr+IO_PORT);
1640 if (!(xmt_status & TX_DONE_BIT))
1641 break;
1643 xmt_status = inw(ioaddr+IO_PORT);
1644 lp->tx_start = inw(ioaddr+IO_PORT);
1646 netif_wake_queue (dev);
1648 if (xmt_status & TX_OK)
1649 dev->stats.tx_packets++;
1650 else {
1651 dev->stats.tx_errors++;
1652 if (xmt_status & 0x0400) {
1653 dev->stats.tx_carrier_errors++;
1654 printk(KERN_DEBUG "%s: carrier error\n",
1655 dev->name);
1656 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1657 dev->name, xmt_status);
1659 else {
1660 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1661 dev->name, xmt_status);
1662 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1663 dev->name, xmt_status);
1666 if (xmt_status & 0x000f) {
1667 dev->stats.collisions += (xmt_status & 0x000f);
1670 if ((xmt_status & 0x0040) == 0x0) {
1671 dev->stats.tx_heartbeat_errors++;
1676 static int eepro_ethtool_get_settings(struct net_device *dev,
1677 struct ethtool_cmd *cmd)
1679 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1681 cmd->supported = SUPPORTED_10baseT_Half |
1682 SUPPORTED_10baseT_Full |
1683 SUPPORTED_Autoneg;
1684 cmd->advertising = ADVERTISED_10baseT_Half |
1685 ADVERTISED_10baseT_Full |
1686 ADVERTISED_Autoneg;
1688 if (GetBit(lp->word[5], ee_PortTPE)) {
1689 cmd->supported |= SUPPORTED_TP;
1690 cmd->advertising |= ADVERTISED_TP;
1692 if (GetBit(lp->word[5], ee_PortBNC)) {
1693 cmd->supported |= SUPPORTED_BNC;
1694 cmd->advertising |= ADVERTISED_BNC;
1696 if (GetBit(lp->word[5], ee_PortAUI)) {
1697 cmd->supported |= SUPPORTED_AUI;
1698 cmd->advertising |= ADVERTISED_AUI;
1701 cmd->speed = SPEED_10;
1703 if (dev->if_port == TPE && lp->word[1] & ee_Duplex) {
1704 cmd->duplex = DUPLEX_FULL;
1706 else {
1707 cmd->duplex = DUPLEX_HALF;
1710 cmd->port = dev->if_port;
1711 cmd->phy_address = dev->base_addr;
1712 cmd->transceiver = XCVR_INTERNAL;
1714 if (lp->word[0] & ee_AutoNeg) {
1715 cmd->autoneg = 1;
1718 return 0;
1721 static void eepro_ethtool_get_drvinfo(struct net_device *dev,
1722 struct ethtool_drvinfo *drvinfo)
1724 strcpy(drvinfo->driver, DRV_NAME);
1725 strcpy(drvinfo->version, DRV_VERSION);
1726 sprintf(drvinfo->bus_info, "ISA 0x%lx", dev->base_addr);
1729 static const struct ethtool_ops eepro_ethtool_ops = {
1730 .get_settings = eepro_ethtool_get_settings,
1731 .get_drvinfo = eepro_ethtool_get_drvinfo,
1734 #ifdef MODULE
1736 #define MAX_EEPRO 8
1737 static struct net_device *dev_eepro[MAX_EEPRO];
1739 static int io[MAX_EEPRO] = {
1740 [0 ... MAX_EEPRO-1] = -1
1742 static int irq[MAX_EEPRO];
1743 static int mem[MAX_EEPRO] = { /* Size of the rx buffer in KB */
1744 [0 ... MAX_EEPRO-1] = RCV_DEFAULT_RAM/1024
1746 static int autodetect;
1748 static int n_eepro;
1749 /* For linux 2.1.xx */
1751 MODULE_AUTHOR("Pascal Dupuis and others");
1752 MODULE_DESCRIPTION("Intel i82595 ISA EtherExpressPro10/10+ driver");
1753 MODULE_LICENSE("GPL");
1755 module_param_array(io, int, NULL, 0);
1756 module_param_array(irq, int, NULL, 0);
1757 module_param_array(mem, int, NULL, 0);
1758 module_param(autodetect, int, 0);
1759 MODULE_PARM_DESC(io, "EtherExpress Pro/10 I/O base addres(es)");
1760 MODULE_PARM_DESC(irq, "EtherExpress Pro/10 IRQ number(s)");
1761 MODULE_PARM_DESC(mem, "EtherExpress Pro/10 Rx buffer size(es) in kB (3-29)");
1762 MODULE_PARM_DESC(autodetect, "EtherExpress Pro/10 force board(s) detection (0-1)");
1764 int __init init_module(void)
1766 struct net_device *dev;
1767 int i;
1768 if (io[0] == -1 && autodetect == 0) {
1769 printk(KERN_WARNING "eepro_init_module: Probe is very dangerous in ISA boards!\n");
1770 printk(KERN_WARNING "eepro_init_module: Please add \"autodetect=1\" to force probe\n");
1771 return -ENODEV;
1773 else if (autodetect) {
1774 /* if autodetect is set then we must force detection */
1775 for (i = 0; i < MAX_EEPRO; i++) {
1776 io[i] = 0;
1779 printk(KERN_INFO "eepro_init_module: Auto-detecting boards (May God protect us...)\n");
1782 for (i = 0; io[i] != -1 && i < MAX_EEPRO; i++) {
1783 dev = alloc_etherdev(sizeof(struct eepro_local));
1784 if (!dev)
1785 break;
1787 dev->mem_end = mem[i];
1788 dev->base_addr = io[i];
1789 dev->irq = irq[i];
1791 if (do_eepro_probe(dev) == 0) {
1792 dev_eepro[n_eepro++] = dev;
1793 continue;
1795 free_netdev(dev);
1796 break;
1799 if (n_eepro)
1800 printk(KERN_INFO "%s", version);
1802 return n_eepro ? 0 : -ENODEV;
1805 void __exit
1806 cleanup_module(void)
1808 int i;
1810 for (i=0; i<n_eepro; i++) {
1811 struct net_device *dev = dev_eepro[i];
1812 unregister_netdev(dev);
1813 release_region(dev->base_addr, EEPRO_IO_EXTENT);
1814 free_netdev(dev);
1817 #endif /* MODULE */