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 extern int eepro_probe(struct net_device
*dev
);
307 static int eepro_probe1(struct net_device
*dev
, short ioaddr
);
308 static int eepro_open(struct net_device
*dev
);
309 static int eepro_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
310 static irqreturn_t
eepro_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
311 static void eepro_rx(struct net_device
*dev
);
312 static void eepro_transmit_interrupt(struct net_device
*dev
);
313 static int eepro_close(struct net_device
*dev
);
314 static struct net_device_stats
*eepro_get_stats(struct net_device
*dev
);
315 static void set_multicast_list(struct net_device
*dev
);
316 static void eepro_tx_timeout (struct net_device
*dev
);
318 static int read_eeprom(int ioaddr
, int location
, struct net_device
*dev
);
319 static int hardware_send_packet(struct net_device
*dev
, void *buf
, short length
);
320 static int eepro_grab_irq(struct net_device
*dev
);
323 Details of the i82595.
325 You will need either the datasheet or the user manual to understand what
326 is going on here. The 82595 is very different from the 82586, 82593.
328 The receive algorithm in eepro_rx() is just an implementation of the
329 RCV ring structure that the Intel 82595 imposes at the hardware level.
330 The receive buffer is set at 24K, and the transmit buffer is 8K. I
331 am assuming that the total buffer memory is 32K, which is true for the
332 Intel EtherExpress Pro/10. If it is less than that on a generic card,
333 the driver will be broken.
335 The transmit algorithm in the hardware_send_packet() is similar to the
336 one in the eepro_rx(). The transmit buffer is a ring linked list.
337 I just queue the next available packet to the end of the list. In my
338 system, the 82595 is so fast that the list seems to always contain a
339 single packet. In other systems with faster computers and more congested
340 network traffics, the ring linked list should improve performance by
341 allowing up to 8K worth of packets to be queued.
343 The sizes of the receive and transmit buffers can now be changed via lilo
344 or insmod. Lilo uses the appended line "ether=io,irq,debug,rx-buffer,eth0"
345 where rx-buffer is in KB unit. Modules uses the parameter mem which is
346 also in KB unit, for example "insmod io=io-address irq=0 mem=rx-buffer."
347 The receive buffer has to be more than 3K or less than 29K. Otherwise,
348 it is reset to the default of 24K, and, hence, 8K for the trasnmit
349 buffer (transmit-buffer = 32K - receive-buffer).
352 #define RAM_SIZE 0x8000
355 #define RCV_DEFAULT_RAM 0x6000
358 #define XMT_DEFAULT_RAM (RAM_SIZE - RCV_DEFAULT_RAM)
360 #define XMT_START_PRO RCV_DEFAULT_RAM
361 #define XMT_START_10 0x0000
362 #define RCV_START_PRO 0x0000
363 #define RCV_START_10 XMT_DEFAULT_RAM
365 #define RCV_DONE 0x0008
367 #define RX_ERROR 0x0d81
369 #define TX_DONE_BIT 0x0080
371 #define CHAIN_BIT 0x8000
372 #define XMT_STATUS 0x02
373 #define XMT_CHAIN 0x04
374 #define XMT_COUNT 0x06
376 #define BANK0_SELECT 0x00
377 #define BANK1_SELECT 0x40
378 #define BANK2_SELECT 0x80
380 /* Bank 0 registers */
381 #define COMMAND_REG 0x00 /* Register 0 */
382 #define MC_SETUP 0x03
384 #define DIAGNOSE_CMD 0x07
385 #define RCV_ENABLE_CMD 0x08
386 #define RCV_DISABLE_CMD 0x0a
387 #define STOP_RCV_CMD 0x0b
388 #define RESET_CMD 0x0e
389 #define POWER_DOWN_CMD 0x18
390 #define RESUME_XMT_CMD 0x1c
391 #define SEL_RESET_CMD 0x1e
392 #define STATUS_REG 0x01 /* Register 1 */
395 #define EXEC_STATUS 0x30
396 #define ID_REG 0x02 /* Register 2 */
397 #define R_ROBIN_BITS 0xc0 /* round robin counter */
398 #define ID_REG_MASK 0x2c
399 #define ID_REG_SIG 0x24
400 #define AUTO_ENABLE 0x10
401 #define INT_MASK_REG 0x03 /* Register 3 */
402 #define RX_STOP_MASK 0x01
405 #define EXEC_MASK 0x08
406 #define ALL_MASK 0x0f
407 #define IO_32_BIT 0x10
408 #define RCV_BAR 0x04 /* The following are word (16-bit) registers */
409 #define RCV_STOP 0x06
411 #define XMT_BAR_PRO 0x0a
412 #define XMT_BAR_10 0x0b
414 #define HOST_ADDRESS_REG 0x0c
416 #define IO_PORT_32_BIT 0x0c
418 /* Bank 1 registers */
420 #define WORD_WIDTH 0x02
421 #define INT_ENABLE 0x80
422 #define INT_NO_REG 0x02
423 #define RCV_LOWER_LIMIT_REG 0x08
424 #define RCV_UPPER_LIMIT_REG 0x09
426 #define XMT_LOWER_LIMIT_REG_PRO 0x0a
427 #define XMT_UPPER_LIMIT_REG_PRO 0x0b
428 #define XMT_LOWER_LIMIT_REG_10 0x0b
429 #define XMT_UPPER_LIMIT_REG_10 0x0a
431 /* Bank 2 registers */
432 #define XMT_Chain_Int 0x20 /* Interrupt at the end of the transmit chain */
433 #define XMT_Chain_ErrStop 0x40 /* Interrupt at the end of the chain even if there are errors */
434 #define RCV_Discard_BadFrame 0x80 /* Throw bad frames away, and continue to receive others */
436 #define PRMSC_Mode 0x01
437 #define Multi_IA 0x20
443 #define A_N_ENABLE 0x02
445 #define I_ADD_REG0 0x04
446 #define I_ADD_REG1 0x05
447 #define I_ADD_REG2 0x06
448 #define I_ADD_REG3 0x07
449 #define I_ADD_REG4 0x08
450 #define I_ADD_REG5 0x09
452 #define EEPROM_REG_PRO 0x0a
453 #define EEPROM_REG_10 0x0b
460 /* do a full reset */
461 #define eepro_reset(ioaddr) outb(RESET_CMD, ioaddr)
463 /* do a nice reset */
464 #define eepro_sel_reset(ioaddr) { \
465 outb(SEL_RESET_CMD, ioaddr); \
470 /* disable all interrupts */
471 #define eepro_dis_int(ioaddr) outb(ALL_MASK, ioaddr + INT_MASK_REG)
473 /* clear all interrupts */
474 #define eepro_clear_int(ioaddr) outb(ALL_MASK, ioaddr + STATUS_REG)
477 #define eepro_en_int(ioaddr) outb(ALL_MASK & ~(RX_MASK | TX_MASK), \
478 ioaddr + INT_MASK_REG)
480 /* enable exec event interrupt */
481 #define eepro_en_intexec(ioaddr) outb(ALL_MASK & ~(EXEC_MASK), ioaddr + INT_MASK_REG)
484 #define eepro_en_rx(ioaddr) outb(RCV_ENABLE_CMD, ioaddr)
487 #define eepro_dis_rx(ioaddr) outb(RCV_DISABLE_CMD, ioaddr)
490 #define eepro_sw2bank0(ioaddr) outb(BANK0_SELECT, ioaddr)
491 #define eepro_sw2bank1(ioaddr) outb(BANK1_SELECT, ioaddr)
492 #define eepro_sw2bank2(ioaddr) outb(BANK2_SELECT, ioaddr)
494 /* enable interrupt line */
495 #define eepro_en_intline(ioaddr) outb(inb(ioaddr + REG1) | INT_ENABLE,\
498 /* disable interrupt line */
499 #define eepro_dis_intline(ioaddr) outb(inb(ioaddr + REG1) & 0x7f, \
502 /* set diagnose flag */
503 #define eepro_diag(ioaddr) outb(DIAGNOSE_CMD, ioaddr)
506 #define eepro_ack_rx(ioaddr) outb (RX_INT, ioaddr + STATUS_REG)
509 #define eepro_ack_tx(ioaddr) outb (TX_INT, ioaddr + STATUS_REG)
511 /* a complete sel reset */
512 #define eepro_complete_selreset(ioaddr) { \
513 lp->stats.tx_errors++;\
514 eepro_sel_reset(ioaddr);\
516 lp->xmt_lower_limit;\
517 lp->tx_start = lp->tx_end;\
519 dev->trans_start = jiffies;\
520 netif_wake_queue(dev);\
521 eepro_en_rx(ioaddr);\
524 /* Check for a network adaptor of this type, and return '0' if one exists.
525 If dev->base_addr == 0, probe all likely locations.
526 If dev->base_addr == 1, always return failure.
527 If dev->base_addr == 2, allocate space for the device and return success
528 (detachable devices only).
530 int __init
eepro_probe(struct net_device
*dev
)
533 int base_addr
= dev
->base_addr
;
535 SET_MODULE_OWNER(dev
);
538 /* XXXX for multiple cards should this only be run once? */
541 #define WakeupPort 0x279
542 #define WakeupSeq {0x6A, 0xB5, 0xDA, 0xED, 0xF6, 0xFB, 0x7D, 0xBE,\
543 0xDF, 0x6F, 0x37, 0x1B, 0x0D, 0x86, 0xC3, 0x61,\
544 0xB0, 0x58, 0x2C, 0x16, 0x8B, 0x45, 0xA2, 0xD1,\
545 0xE8, 0x74, 0x3A, 0x9D, 0xCE, 0xE7, 0x73, 0x43}
548 unsigned short int WS
[32]=WakeupSeq
;
550 if (check_region(WakeupPort
, 2)==0) {
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
]);
561 } else printk(KERN_WARNING
"Checkregion Failed!\n");
565 if (base_addr
> 0x1ff) /* Check a single specified location. */
566 return eepro_probe1(dev
, base_addr
);
568 else if (base_addr
!= 0) /* Don't probe at all. */
572 for (i
= 0; eepro_portlist
[i
]; i
++) {
573 int ioaddr
= eepro_portlist
[i
];
575 if (check_region(ioaddr
, EEPRO_IO_EXTENT
))
577 if (eepro_probe1(dev
, ioaddr
) == 0)
584 static void __init
printEEPROMInfo(short ioaddr
, struct net_device
*dev
)
589 for (i
=0, j
=ee_Checksum
; i
<ee_SIZE
; i
++)
590 j
+=read_eeprom(ioaddr
,i
,dev
);
591 printk(KERN_DEBUG
"Checksum: %#x\n",j
&0xffff);
593 Word
=read_eeprom(ioaddr
, 0, dev
);
594 printk(KERN_DEBUG
"Word0:\n");
595 printk(KERN_DEBUG
" Plug 'n Pray: %d\n",GetBit(Word
,ee_PnP
));
596 printk(KERN_DEBUG
" Buswidth: %d\n",(GetBit(Word
,ee_BusWidth
)+1)*8 );
597 printk(KERN_DEBUG
" AutoNegotiation: %d\n",GetBit(Word
,ee_AutoNeg
));
598 printk(KERN_DEBUG
" IO Address: %#x\n", (Word
>>ee_IO0
)<<4);
601 Word
=read_eeprom(ioaddr
, 1, dev
);
602 printk(KERN_DEBUG
"Word1:\n");
603 printk(KERN_DEBUG
" INT: %d\n", Word
& ee_IntMask
);
604 printk(KERN_DEBUG
" LI: %d\n", GetBit(Word
,ee_LI
));
605 printk(KERN_DEBUG
" PC: %d\n", GetBit(Word
,ee_PC
));
606 printk(KERN_DEBUG
" TPE/AUI: %d\n", GetBit(Word
,ee_TPE_AUI
));
607 printk(KERN_DEBUG
" Jabber: %d\n", GetBit(Word
,ee_Jabber
));
608 printk(KERN_DEBUG
" AutoPort: %d\n", GetBit(!Word
,ee_Jabber
));
609 printk(KERN_DEBUG
" Duplex: %d\n", GetBit(Word
,ee_Duplex
));
612 Word
=read_eeprom(ioaddr
, 5, dev
);
613 printk(KERN_DEBUG
"Word5:\n");
614 printk(KERN_DEBUG
" BNC: %d\n",GetBit(Word
,ee_BNC_TPE
));
615 printk(KERN_DEBUG
" NumConnectors: %d\n",GetBit(Word
,ee_NumConn
));
616 printk(KERN_DEBUG
" Has ");
617 if (GetBit(Word
,ee_PortTPE
)) printk(KERN_DEBUG
"TPE ");
618 if (GetBit(Word
,ee_PortBNC
)) printk(KERN_DEBUG
"BNC ");
619 if (GetBit(Word
,ee_PortAUI
)) printk(KERN_DEBUG
"AUI ");
620 printk(KERN_DEBUG
"port(s) \n");
622 Word
=read_eeprom(ioaddr
, 6, dev
);
623 printk(KERN_DEBUG
"Word6:\n");
624 printk(KERN_DEBUG
" Stepping: %d\n",Word
& ee_StepMask
);
625 printk(KERN_DEBUG
" BoardID: %d\n",Word
>>ee_BoardID
);
627 Word
=read_eeprom(ioaddr
, 7, dev
);
628 printk(KERN_DEBUG
"Word7:\n");
629 printk(KERN_DEBUG
" INT to IRQ:\n");
631 for (i
=0, j
=0; i
<15; i
++)
632 if (GetBit(Word
,i
)) printk(KERN_DEBUG
" INT%d -> IRQ %d;",j
++,i
);
634 printk(KERN_DEBUG
"\n");
637 /* function to recalculate the limits of buffer based on rcv_ram */
638 static void eepro_recalc (struct net_device
*dev
)
640 struct eepro_local
* lp
;
643 lp
->xmt_ram
= RAM_SIZE
- lp
->rcv_ram
;
645 if (lp
->eepro
== LAN595FX_10ISA
) {
646 lp
->xmt_lower_limit
= XMT_START_10
;
647 lp
->xmt_upper_limit
= (lp
->xmt_ram
- 2);
648 lp
->rcv_lower_limit
= lp
->xmt_ram
;
649 lp
->rcv_upper_limit
= (RAM_SIZE
- 2);
652 lp
->rcv_lower_limit
= RCV_START_PRO
;
653 lp
->rcv_upper_limit
= (lp
->rcv_ram
- 2);
654 lp
->xmt_lower_limit
= lp
->rcv_ram
;
655 lp
->xmt_upper_limit
= (RAM_SIZE
- 2);
659 /* prints boot-time info */
660 static void eepro_print_info (struct net_device
*dev
)
662 struct eepro_local
* lp
= dev
->priv
;
664 const char * ifmap
[] = {"AUI", "10Base2", "10BaseT"};
666 i
= inb(dev
->base_addr
+ ID_REG
);
667 printk(KERN_DEBUG
" id: %#x ",i
);
668 printk(" io: %#x ", (unsigned)dev
->base_addr
);
672 printk("%s: Intel EtherExpress 10 ISA\n at %#x,",
673 dev
->name
, (unsigned)dev
->base_addr
);
676 printk("%s: Intel EtherExpress Pro/10+ ISA\n at %#x,",
677 dev
->name
, (unsigned)dev
->base_addr
);
680 printk("%s: Intel EtherExpress Pro/10 ISA at %#x,",
681 dev
->name
, (unsigned)dev
->base_addr
);
684 printk("%s: Intel 82595-based lan card at %#x,",
685 dev
->name
, (unsigned)dev
->base_addr
);
688 for (i
=0; i
< 6; i
++)
689 printk("%c%02x", i
? ':' : ' ', dev
->dev_addr
[i
]);
692 printk(KERN_DEBUG
", %dK RCV buffer",
693 (int)(lp
->rcv_ram
)/1024);
696 printk(", IRQ %d, %s.\n", dev
->irq
, ifmap
[dev
->if_port
]);
698 printk(", %s.\n", ifmap
[dev
->if_port
]);
701 i
= read_eeprom(dev
->base_addr
, 5, dev
);
702 if (i
& 0x2000) /* bit 13 of EEPROM word 5 */
703 printk(KERN_DEBUG
"%s: Concurrent Processing is "
704 "enabled but not used!\n", dev
->name
);
707 /* Check the station address for the manufacturer's code */
709 printEEPROMInfo(dev
->base_addr
, dev
);
712 /* This is the real probe routine. Linux has a history of friendly device
713 probes on the ISA bus. A good device probe avoids doing writes, and
714 verifies that the correct device exists and functions. */
716 static int __init
eepro_probe1(struct net_device
*dev
, short ioaddr
)
718 unsigned short station_addr
[6], id
, counter
;
719 int i
, j
, irqMask
, retval
= 0;
720 struct eepro_local
*lp
;
721 enum iftype
{ AUI
=0, BNC
=1, TPE
=2 };
723 /* Now, we are going to check for the signature of the
724 ID_REG (register 2 of bank 0) */
726 id
=inb(ioaddr
+ ID_REG
);
728 if (((id
) & ID_REG_MASK
) != ID_REG_SIG
) {
733 /* We seem to have the 82595 signature, let's
734 play with its counter (last 2 bits of
735 register 2 of bank 0) to be sure. */
737 counter
= (id
& R_ROBIN_BITS
);
739 if (((id
=inb(ioaddr
+ID_REG
)) & R_ROBIN_BITS
)!=(counter
+ 0x40)) {
744 /* Initialize the device structure */
745 dev
->priv
= kmalloc(sizeof(struct eepro_local
), GFP_KERNEL
);
751 memset(dev
->priv
, 0, sizeof(struct eepro_local
));
753 lp
= (struct eepro_local
*)dev
->priv
;
757 lp
->xmt_bar
= XMT_BAR_PRO
;
758 lp
->xmt_lower_limit_reg
= XMT_LOWER_LIMIT_REG_PRO
;
759 lp
->xmt_upper_limit_reg
= XMT_UPPER_LIMIT_REG_PRO
;
760 lp
->eeprom_reg
= EEPROM_REG_PRO
;
762 /* Now, get the ethernet hardware address from
764 station_addr
[0] = read_eeprom(ioaddr
, 2, dev
);
766 /* FIXME - find another way to know that we've found
769 if (station_addr
[0] == 0x0000 ||
770 station_addr
[0] == 0xffff) {
771 lp
->eepro
= LAN595FX_10ISA
;
772 lp
->eeprom_reg
= EEPROM_REG_10
;
773 lp
->xmt_lower_limit_reg
= XMT_LOWER_LIMIT_REG_10
;
774 lp
->xmt_upper_limit_reg
= XMT_UPPER_LIMIT_REG_10
;
775 lp
->xmt_bar
= XMT_BAR_10
;
776 station_addr
[0] = read_eeprom(ioaddr
, 2, dev
);
778 station_addr
[1] = read_eeprom(ioaddr
, 3, dev
);
779 station_addr
[2] = read_eeprom(ioaddr
, 4, dev
);
782 if (read_eeprom(ioaddr
,7,dev
)== ee_FX_INT2IRQ
)
784 else if (station_addr
[2] == SA_ADDR1
)
788 /* Fill in the 'dev' fields. */
789 dev
->base_addr
= ioaddr
;
791 for (i
=0; i
< 6; i
++)
792 dev
->dev_addr
[i
] = ((unsigned char *) station_addr
)[5-i
];
794 /* RX buffer must be more than 3K and less than 29K */
795 if (dev
->mem_end
< 3072 || dev
->mem_end
> 29696)
796 lp
->rcv_ram
= RCV_DEFAULT_RAM
;
798 /* calculate {xmt,rcv}_{lower,upper}_limit */
802 if (GetBit( read_eeprom(ioaddr
, 5, dev
),ee_BNC_TPE
))
807 if ((dev
->irq
< 2) && (lp
->eepro
!=0)) {
808 i
= read_eeprom(ioaddr
, 1, dev
);
809 irqMask
= read_eeprom(ioaddr
, 7, dev
);
810 i
&= 0x07; /* Mask off INT number */
812 for (j
=0; ((j
<16) && (i
>=0)); j
++) {
813 if ((irqMask
& (1<<j
))!=0) {
816 break; /* found bit corresponding to irq */
818 i
--; /* count bits set in irqMask */
822 printk(KERN_ERR
" Duh! illegal interrupt vector stored in EEPROM.\n");
826 if (dev
->irq
==2) dev
->irq
= 9;
829 /* Grab the region so we can find another board if autoIRQ fails. */
830 if (!request_region(ioaddr
, EEPRO_IO_EXTENT
, dev
->name
)) {
831 printk(KERN_WARNING
"EEPRO: io-port 0x%04x in use \n", ioaddr
);
834 ((struct eepro_local
*)dev
->priv
)->lock
= SPIN_LOCK_UNLOCKED
;
836 dev
->open
= eepro_open
;
837 dev
->stop
= eepro_close
;
838 dev
->hard_start_xmit
= eepro_send_packet
;
839 dev
->get_stats
= eepro_get_stats
;
840 dev
->set_multicast_list
= &set_multicast_list
;
841 dev
->tx_timeout
= eepro_tx_timeout
;
842 dev
->watchdog_timeo
= TX_TIMEOUT
;
844 /* Fill in the fields of the device structure with
845 ethernet generic values */
848 /* print boot time info */
849 eepro_print_info(dev
);
862 /* Open/initialize the board. This is called (in the current kernel)
863 sometime after booting when the 'ifconfig' program is run.
865 This routine should set everything up anew at each open, even
866 registers that "should" only need to be set once at boot, so that
867 there is non-reboot way to recover if something goes wrong.
870 static char irqrmap
[] = {-1,-1,0,1,-1,2,-1,-1,-1,0,3,4,-1,-1,-1,-1};
871 static char irqrmap2
[] = {-1,-1,4,0,1,2,-1,3,-1,4,5,6,7,-1,-1,-1};
872 static int eepro_grab_irq(struct net_device
*dev
)
874 int irqlist
[] = { 3, 4, 5, 7, 9, 10, 11, 12, 0 };
875 int *irqp
= irqlist
, temp_reg
, ioaddr
= dev
->base_addr
;
877 eepro_sw2bank1(ioaddr
); /* be CAREFUL, BANK 1 now */
879 /* Enable the interrupt line. */
880 eepro_en_intline(ioaddr
);
882 /* be CAREFUL, BANK 0 now */
883 eepro_sw2bank0(ioaddr
);
885 /* clear all interrupts */
886 eepro_clear_int(ioaddr
);
888 /* Let EXEC event to interrupt */
889 eepro_en_intexec(ioaddr
);
892 eepro_sw2bank1(ioaddr
); /* be CAREFUL, BANK 1 now */
894 temp_reg
= inb(ioaddr
+ INT_NO_REG
);
895 outb((temp_reg
& 0xf8) | irqrmap
[*irqp
], ioaddr
+ INT_NO_REG
);
897 eepro_sw2bank0(ioaddr
); /* Switch back to Bank 0 */
899 if (request_irq (*irqp
, NULL
, SA_SHIRQ
, "bogus", dev
) != EBUSY
) {
900 unsigned long irq_mask
, delay
;
901 /* Twinkle the interrupt, and check if it's seen */
902 irq_mask
= probe_irq_on();
904 eepro_diag(ioaddr
); /* RESET the 82595 */
906 delay
= jiffies
+ HZ
/50;
907 while (time_before(jiffies
, delay
)) ;
909 if (*irqp
== probe_irq_off(irq_mask
)) /* It's a good IRQ line */
912 /* clear all interrupts */
913 eepro_clear_int(ioaddr
);
917 eepro_sw2bank1(ioaddr
); /* Switch back to Bank 1 */
919 /* Disable the physical interrupt line. */
920 eepro_dis_intline(ioaddr
);
922 eepro_sw2bank0(ioaddr
); /* Switch back to Bank 0 */
924 /* Mask all the interrupts. */
925 eepro_dis_int(ioaddr
);
927 /* clear all interrupts */
928 eepro_clear_int(ioaddr
);
933 static int eepro_open(struct net_device
*dev
)
935 unsigned short temp_reg
, old8
, old9
;
937 int i
, ioaddr
= dev
->base_addr
;
938 struct eepro_local
*lp
= (struct eepro_local
*)dev
->priv
;
941 printk(KERN_DEBUG
"%s: entering eepro_open routine.\n", dev
->name
);
943 irqMask
= read_eeprom(ioaddr
,7,dev
);
945 if (lp
->eepro
== LAN595FX_10ISA
) {
946 if (net_debug
> 3) printk(KERN_DEBUG
"p->eepro = 3;\n");
948 else if (irqMask
== ee_FX_INT2IRQ
) /* INT to IRQ Mask */
950 lp
->eepro
= 2; /* Yes, an Intel EtherExpress Pro/10+ */
951 if (net_debug
> 3) printk(KERN_DEBUG
"p->eepro = 2;\n");
954 else if ((dev
->dev_addr
[0] == SA_ADDR0
&&
955 dev
->dev_addr
[1] == SA_ADDR1
&&
956 dev
->dev_addr
[2] == SA_ADDR2
))
959 if (net_debug
> 3) printk(KERN_DEBUG
"p->eepro = 1;\n");
960 } /* Yes, an Intel EtherExpress Pro/10 */
962 else lp
->eepro
= 0; /* No, it is a generic 82585 lan card */
964 /* Get the interrupt vector for the 82595 */
965 if (dev
->irq
< 2 && eepro_grab_irq(dev
) == 0) {
966 printk(KERN_ERR
"%s: unable to get IRQ %d.\n", dev
->name
, dev
->irq
);
970 if (request_irq(dev
->irq
, &eepro_interrupt
, 0, dev
->name
, dev
)) {
971 printk(KERN_ERR
"%s: unable to get IRQ %d.\n", dev
->name
, dev
->irq
);
976 if (((irq2dev_map
[dev
->irq
] != 0)
977 || (irq2dev_map
[dev
->irq
] = dev
) == 0) &&
978 (irq2dev_map
[dev
->irq
]!=dev
)) {
979 /* printk("%s: IRQ map wrong\n", dev->name); */
980 free_irq(dev
->irq
, dev
);
985 /* Initialize the 82595. */
987 eepro_sw2bank2(ioaddr
); /* be CAREFUL, BANK 2 now */
988 temp_reg
= inb(ioaddr
+ lp
->eeprom_reg
);
990 lp
->stepping
= temp_reg
>> 5; /* Get the stepping number of the 595 */
993 printk(KERN_DEBUG
"The stepping of the 82595 is %d\n", lp
->stepping
);
995 if (temp_reg
& 0x10) /* Check the TurnOff Enable bit */
996 outb(temp_reg
& 0xef, ioaddr
+ lp
->eeprom_reg
);
997 for (i
=0; i
< 6; i
++)
998 outb(dev
->dev_addr
[i
] , ioaddr
+ I_ADD_REG0
+ i
);
1000 temp_reg
= inb(ioaddr
+ REG1
); /* Setup Transmit Chaining */
1001 outb(temp_reg
| XMT_Chain_Int
| XMT_Chain_ErrStop
/* and discard bad RCV frames */
1002 | RCV_Discard_BadFrame
, ioaddr
+ REG1
);
1004 temp_reg
= inb(ioaddr
+ REG2
); /* Match broadcast */
1005 outb(temp_reg
| 0x14, ioaddr
+ REG2
);
1007 temp_reg
= inb(ioaddr
+ REG3
);
1008 outb(temp_reg
& 0x3f, ioaddr
+ REG3
); /* clear test mode */
1010 /* Set the receiving mode */
1011 eepro_sw2bank1(ioaddr
); /* be CAREFUL, BANK 1 now */
1013 /* Set the interrupt vector */
1014 temp_reg
= inb(ioaddr
+ INT_NO_REG
);
1015 if (lp
->eepro
== LAN595FX
|| lp
->eepro
== LAN595FX_10ISA
)
1016 outb((temp_reg
& 0xf8) | irqrmap2
[dev
->irq
], ioaddr
+ INT_NO_REG
);
1017 else outb((temp_reg
& 0xf8) | irqrmap
[dev
->irq
], ioaddr
+ INT_NO_REG
);
1020 temp_reg
= inb(ioaddr
+ INT_NO_REG
);
1021 if (lp
->eepro
== LAN595FX
|| lp
->eepro
== LAN595FX_10ISA
)
1022 outb((temp_reg
& 0xf0) | irqrmap2
[dev
->irq
] | 0x08,ioaddr
+INT_NO_REG
);
1023 else outb((temp_reg
& 0xf8) | irqrmap
[dev
->irq
], ioaddr
+ INT_NO_REG
);
1026 printk(KERN_DEBUG
"eepro_open: content of INT Reg is %x\n", temp_reg
);
1029 /* Initialize the RCV and XMT upper and lower limits */
1030 outb(lp
->rcv_lower_limit
>> 8, ioaddr
+ RCV_LOWER_LIMIT_REG
);
1031 outb(lp
->rcv_upper_limit
>> 8, ioaddr
+ RCV_UPPER_LIMIT_REG
);
1032 outb(lp
->xmt_lower_limit
>> 8, ioaddr
+ lp
->xmt_lower_limit_reg
);
1033 outb(lp
->xmt_upper_limit
>> 8, ioaddr
+ lp
->xmt_upper_limit_reg
);
1035 /* Enable the interrupt line. */
1036 eepro_en_intline(ioaddr
);
1038 /* Switch back to Bank 0 */
1039 eepro_sw2bank0(ioaddr
);
1041 /* Let RX and TX events to interrupt */
1042 eepro_en_int(ioaddr
);
1044 /* clear all interrupts */
1045 eepro_clear_int(ioaddr
);
1047 /* Initialize RCV */
1048 outw(lp
->rcv_lower_limit
, ioaddr
+ RCV_BAR
);
1049 lp
->rx_start
= lp
->rcv_lower_limit
;
1050 outw(lp
->rcv_upper_limit
| 0xfe, ioaddr
+ RCV_STOP
);
1052 /* Initialize XMT */
1053 outw(lp
->xmt_lower_limit
, ioaddr
+ lp
->xmt_bar
);
1054 lp
->tx_start
= lp
->tx_end
= lp
->xmt_lower_limit
;
1057 /* Check for the i82595TX and i82595FX */
1058 old8
= inb(ioaddr
+ 8);
1059 outb(~old8
, ioaddr
+ 8);
1061 if ((temp_reg
= inb(ioaddr
+ 8)) == old8
) {
1063 printk(KERN_DEBUG
"i82595 detected!\n");
1064 lp
->version
= LAN595
;
1067 lp
->version
= LAN595TX
;
1068 outb(old8
, ioaddr
+ 8);
1069 old9
= inb(ioaddr
+ 9);
1071 if (irqMask
==ee_FX_INT2IRQ
) {
1072 enum iftype
{ AUI
=0, BNC
=1, TPE
=2 };
1074 if (net_debug
> 3) {
1075 printk(KERN_DEBUG
"IrqMask: %#x\n",irqMask
);
1076 printk(KERN_DEBUG
"i82595FX detected!\n");
1078 lp
->version
= LAN595FX
;
1079 outb(old9
, ioaddr
+ 9);
1080 if (dev
->if_port
!= TPE
) { /* Hopefully, this will fix the
1081 problem of using Pentiums and
1083 eepro_sw2bank2(ioaddr
); /* be CAREFUL, BANK 2 now */
1084 temp_reg
= inb(ioaddr
+ REG13
);
1085 /* disable the full duplex mode since it is not
1086 applicable with the 10Base2 cable. */
1087 outb(temp_reg
& ~(FDX
| A_N_ENABLE
), REG13
);
1088 eepro_sw2bank0(ioaddr
); /* be CAREFUL, BANK 0 now */
1091 else if (net_debug
> 3) {
1092 printk(KERN_DEBUG
"temp_reg: %#x ~old9: %#x\n",temp_reg
,((~old9
)&0xff));
1093 printk(KERN_DEBUG
"i82595TX detected!\n");
1097 eepro_sel_reset(ioaddr
);
1099 netif_start_queue(dev
);
1102 printk(KERN_DEBUG
"%s: exiting eepro_open routine.\n", dev
->name
);
1105 eepro_en_rx(ioaddr
);
1110 static void eepro_tx_timeout (struct net_device
*dev
)
1112 struct eepro_local
*lp
= (struct eepro_local
*) dev
->priv
;
1113 int ioaddr
= dev
->base_addr
;
1115 /* if (net_debug > 1) */
1116 printk (KERN_ERR
"%s: transmit timed out, %s?\n", dev
->name
,
1117 "network cable problem");
1118 /* This is not a duplicate. One message for the console,
1119 one for the the log file */
1120 printk (KERN_DEBUG
"%s: transmit timed out, %s?\n", dev
->name
,
1121 "network cable problem");
1122 eepro_complete_selreset(ioaddr
);
1126 static int eepro_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
1128 struct eepro_local
*lp
= (struct eepro_local
*)dev
->priv
;
1129 unsigned long flags
;
1130 int ioaddr
= dev
->base_addr
;
1131 short length
= skb
->len
;
1134 printk(KERN_DEBUG
"%s: entering eepro_send_packet routine.\n", dev
->name
);
1136 if (length
< ETH_ZLEN
) {
1137 skb
= skb_padto(skb
, ETH_ZLEN
);
1142 netif_stop_queue (dev
);
1144 eepro_dis_int(ioaddr
);
1145 spin_lock_irqsave(&lp
->lock
, flags
);
1148 unsigned char *buf
= skb
->data
;
1150 if (hardware_send_packet(dev
, buf
, length
))
1151 /* we won't wake queue here because we're out of space */
1152 lp
->stats
.tx_dropped
++;
1154 lp
->stats
.tx_bytes
+=skb
->len
;
1155 dev
->trans_start
= jiffies
;
1156 netif_wake_queue(dev
);
1161 dev_kfree_skb (skb
);
1163 /* You might need to clean up and record Tx statistics here. */
1164 /* lp->stats.tx_aborted_errors++; */
1167 printk(KERN_DEBUG
"%s: exiting eepro_send_packet routine.\n", dev
->name
);
1169 eepro_en_int(ioaddr
);
1170 spin_unlock_irqrestore(&lp
->lock
, flags
);
1176 /* The typical workload of the driver:
1177 Handle the network interface interrupts. */
1180 eepro_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
1182 struct net_device
*dev
= (struct net_device
*)dev_id
;
1183 /* (struct net_device *)(irq2dev_map[irq]);*/
1184 struct eepro_local
*lp
;
1185 int ioaddr
, status
, boguscount
= 20;
1189 printk (KERN_ERR
"eepro_interrupt(): irq %d for unknown device.\\n", irq
);
1193 lp
= (struct eepro_local
*)dev
->priv
;
1195 spin_lock(&lp
->lock
);
1198 printk(KERN_DEBUG
"%s: entering eepro_interrupt routine.\n", dev
->name
);
1200 ioaddr
= dev
->base_addr
;
1202 while (((status
= inb(ioaddr
+ STATUS_REG
)) & (RX_INT
|TX_INT
)) && (boguscount
--))
1205 if (status
& RX_INT
) {
1207 printk(KERN_DEBUG
"%s: packet received interrupt.\n", dev
->name
);
1209 eepro_dis_int(ioaddr
);
1211 /* Get the received packets */
1212 eepro_ack_rx(ioaddr
);
1215 eepro_en_int(ioaddr
);
1217 if (status
& TX_INT
) {
1219 printk(KERN_DEBUG
"%s: packet transmit interrupt.\n", dev
->name
);
1222 eepro_dis_int(ioaddr
);
1224 /* Process the status of transmitted packets */
1225 eepro_ack_tx(ioaddr
);
1226 eepro_transmit_interrupt(dev
);
1228 eepro_en_int(ioaddr
);
1233 printk(KERN_DEBUG
"%s: exiting eepro_interrupt routine.\n", dev
->name
);
1235 spin_unlock(&lp
->lock
);
1236 return IRQ_RETVAL(handled
);
1239 static int eepro_close(struct net_device
*dev
)
1241 struct eepro_local
*lp
= (struct eepro_local
*)dev
->priv
;
1242 int ioaddr
= dev
->base_addr
;
1245 netif_stop_queue(dev
);
1247 eepro_sw2bank1(ioaddr
); /* Switch back to Bank 1 */
1249 /* Disable the physical interrupt line. */
1250 temp_reg
= inb(ioaddr
+ REG1
);
1251 outb(temp_reg
& 0x7f, ioaddr
+ REG1
);
1253 eepro_sw2bank0(ioaddr
); /* Switch back to Bank 0 */
1255 /* Flush the Tx and disable Rx. */
1256 outb(STOP_RCV_CMD
, ioaddr
);
1257 lp
->tx_start
= lp
->tx_end
= lp
->xmt_lower_limit
;
1260 /* Mask all the interrupts. */
1261 eepro_dis_int(ioaddr
);
1263 /* clear all interrupts */
1264 eepro_clear_int(ioaddr
);
1266 /* Reset the 82595 */
1267 eepro_reset(ioaddr
);
1269 /* release the interrupt */
1270 free_irq(dev
->irq
, dev
);
1273 irq2dev_map
[dev
->irq
] = 0;
1276 /* Update the statistics here. What statistics? */
1281 /* Get the current statistics. This may be called with the card open or
1283 static struct net_device_stats
*
1284 eepro_get_stats(struct net_device
*dev
)
1286 struct eepro_local
*lp
= (struct eepro_local
*)dev
->priv
;
1291 /* Set or clear the multicast filter for this adaptor.
1294 set_multicast_list(struct net_device
*dev
)
1296 struct eepro_local
*lp
= (struct eepro_local
*)dev
->priv
;
1297 short ioaddr
= dev
->base_addr
;
1298 unsigned short mode
;
1299 struct dev_mc_list
*dmi
=dev
->mc_list
;
1301 if (dev
->flags
&(IFF_ALLMULTI
|IFF_PROMISC
) || dev
->mc_count
> 63)
1304 * We must make the kernel realise we had to move
1305 * into promisc mode or we start all out war on
1306 * the cable. If it was a promisc request the
1307 * flag is already set. If not we assert it.
1309 dev
->flags
|=IFF_PROMISC
;
1311 eepro_sw2bank2(ioaddr
); /* be CAREFUL, BANK 2 now */
1312 mode
= inb(ioaddr
+ REG2
);
1313 outb(mode
| PRMSC_Mode
, ioaddr
+ REG2
);
1314 mode
= inb(ioaddr
+ REG3
);
1315 outb(mode
, ioaddr
+ REG3
); /* writing reg. 3 to complete the update */
1316 eepro_sw2bank0(ioaddr
); /* Return to BANK 0 now */
1317 printk(KERN_INFO
"%s: promiscuous mode enabled.\n", dev
->name
);
1320 else if (dev
->mc_count
==0 )
1322 eepro_sw2bank2(ioaddr
); /* be CAREFUL, BANK 2 now */
1323 mode
= inb(ioaddr
+ REG2
);
1324 outb(mode
& 0xd6, ioaddr
+ REG2
); /* Turn off Multi-IA and PRMSC_Mode bits */
1325 mode
= inb(ioaddr
+ REG3
);
1326 outb(mode
, ioaddr
+ REG3
); /* writing reg. 3 to complete the update */
1327 eepro_sw2bank0(ioaddr
); /* Return to BANK 0 now */
1332 unsigned short status
, *eaddrs
;
1333 int i
, boguscount
= 0;
1335 /* Disable RX and TX interrupts. Necessary to avoid
1336 corruption of the HOST_ADDRESS_REG by interrupt
1337 service routines. */
1338 eepro_dis_int(ioaddr
);
1340 eepro_sw2bank2(ioaddr
); /* be CAREFUL, BANK 2 now */
1341 mode
= inb(ioaddr
+ REG2
);
1342 outb(mode
| Multi_IA
, ioaddr
+ REG2
);
1343 mode
= inb(ioaddr
+ REG3
);
1344 outb(mode
, ioaddr
+ REG3
); /* writing reg. 3 to complete the update */
1345 eepro_sw2bank0(ioaddr
); /* Return to BANK 0 now */
1346 outw(lp
->tx_end
, ioaddr
+ HOST_ADDRESS_REG
);
1347 outw(MC_SETUP
, ioaddr
+ IO_PORT
);
1348 outw(0, ioaddr
+ IO_PORT
);
1349 outw(0, ioaddr
+ IO_PORT
);
1350 outw(6*(dev
->mc_count
+ 1), ioaddr
+ IO_PORT
);
1352 for (i
= 0; i
< dev
->mc_count
; i
++)
1354 eaddrs
=(unsigned short *)dmi
->dmi_addr
;
1356 outw(*eaddrs
++, ioaddr
+ IO_PORT
);
1357 outw(*eaddrs
++, ioaddr
+ IO_PORT
);
1358 outw(*eaddrs
++, ioaddr
+ IO_PORT
);
1361 eaddrs
= (unsigned short *) dev
->dev_addr
;
1362 outw(eaddrs
[0], ioaddr
+ IO_PORT
);
1363 outw(eaddrs
[1], ioaddr
+ IO_PORT
);
1364 outw(eaddrs
[2], ioaddr
+ IO_PORT
);
1365 outw(lp
->tx_end
, ioaddr
+ lp
->xmt_bar
);
1366 outb(MC_SETUP
, ioaddr
);
1368 /* Update the transmit queue */
1369 i
= lp
->tx_end
+ XMT_HEADER
+ 6*(dev
->mc_count
+ 1);
1371 if (lp
->tx_start
!= lp
->tx_end
)
1373 /* update the next address and the chain bit in the
1375 outw(lp
->tx_last
+ XMT_CHAIN
, ioaddr
+ HOST_ADDRESS_REG
);
1376 outw(i
, ioaddr
+ IO_PORT
);
1377 outw(lp
->tx_last
+ XMT_COUNT
, ioaddr
+ HOST_ADDRESS_REG
);
1378 status
= inw(ioaddr
+ IO_PORT
);
1379 outw(status
| CHAIN_BIT
, ioaddr
+ IO_PORT
);
1383 lp
->tx_start
= lp
->tx_end
= i
;
1386 /* Acknowledge that the MC setup is done */
1387 do { /* We should be doing this in the eepro_interrupt()! */
1390 if (inb(ioaddr
+ STATUS_REG
) & 0x08)
1393 outb(0x08, ioaddr
+ STATUS_REG
);
1395 if (i
& 0x20) { /* command ABORTed */
1396 printk(KERN_NOTICE
"%s: multicast setup failed.\n",
1399 } else if ((i
& 0x0f) == 0x03) { /* MC-Done */
1400 printk(KERN_DEBUG
"%s: set Rx mode to %d address%s.\n",
1401 dev
->name
, dev
->mc_count
,
1402 dev
->mc_count
> 1 ? "es":"");
1406 } while (++boguscount
< 100);
1408 /* Re-enable RX and TX interrupts */
1409 eepro_en_int(ioaddr
);
1411 if (lp
->eepro
== LAN595FX_10ISA
) {
1412 eepro_complete_selreset(ioaddr
);
1415 eepro_en_rx(ioaddr
);
1418 /* The horrible routine to read a word from the serial EEPROM. */
1419 /* IMPORTANT - the 82595 will be set to Bank 0 after the eeprom is read */
1421 /* The delay between EEPROM clock transitions. */
1422 #define eeprom_delay() { udelay(40); }
1423 #define EE_READ_CMD (6 << 6)
1426 read_eeprom(int ioaddr
, int location
, struct net_device
*dev
)
1429 unsigned short retval
= 0;
1430 struct eepro_local
*lp
= dev
->priv
;
1431 short ee_addr
= ioaddr
+ lp
->eeprom_reg
;
1432 int read_cmd
= location
| EE_READ_CMD
;
1433 short ctrl_val
= EECS
;
1435 /* XXXX - black magic */
1436 eepro_sw2bank1(ioaddr
);
1437 outb(0x00, ioaddr
+ STATUS_REG
);
1438 /* XXXX - black magic */
1440 eepro_sw2bank2(ioaddr
);
1441 outb(ctrl_val
, ee_addr
);
1443 /* Shift the read command bits out. */
1444 for (i
= 8; i
>= 0; i
--) {
1445 short outval
= (read_cmd
& (1 << i
)) ? ctrl_val
| EEDI
1447 outb(outval
, ee_addr
);
1448 outb(outval
| EESK
, ee_addr
); /* EEPROM clock tick. */
1450 outb(outval
, ee_addr
); /* Finish EEPROM a clock tick. */
1453 outb(ctrl_val
, ee_addr
);
1455 for (i
= 16; i
> 0; i
--) {
1456 outb(ctrl_val
| EESK
, ee_addr
); eeprom_delay();
1457 retval
= (retval
<< 1) | ((inb(ee_addr
) & EEDO
) ? 1 : 0);
1458 outb(ctrl_val
, ee_addr
); eeprom_delay();
1461 /* Terminate the EEPROM access. */
1463 outb(ctrl_val
| EESK
, ee_addr
);
1465 outb(ctrl_val
, ee_addr
);
1467 eepro_sw2bank0(ioaddr
);
1472 hardware_send_packet(struct net_device
*dev
, void *buf
, short length
)
1474 struct eepro_local
*lp
= (struct eepro_local
*)dev
->priv
;
1475 short ioaddr
= dev
->base_addr
;
1476 unsigned status
, tx_available
, last
, end
;
1479 printk(KERN_DEBUG
"%s: entering hardware_send_packet routine.\n", dev
->name
);
1481 /* determine how much of the transmit buffer space is available */
1482 if (lp
->tx_end
> lp
->tx_start
)
1483 tx_available
= lp
->xmt_ram
- (lp
->tx_end
- lp
->tx_start
);
1484 else if (lp
->tx_end
< lp
->tx_start
)
1485 tx_available
= lp
->tx_start
- lp
->tx_end
;
1486 else tx_available
= lp
->xmt_ram
;
1488 if (((((length
+ 3) >> 1) << 1) + 2*XMT_HEADER
) >= tx_available
) {
1489 /* No space available ??? */
1494 end
= last
+ (((length
+ 3) >> 1) << 1) + XMT_HEADER
;
1496 if (end
>= lp
->xmt_upper_limit
+ 2) { /* the transmit buffer is wrapped around */
1497 if ((lp
->xmt_upper_limit
+ 2 - last
) <= XMT_HEADER
) {
1498 /* Arrrr!!!, must keep the xmt header together,
1499 several days were lost to chase this one down. */
1500 last
= lp
->xmt_lower_limit
;
1501 end
= last
+ (((length
+ 3) >> 1) << 1) + XMT_HEADER
;
1503 else end
= lp
->xmt_lower_limit
+ (end
-
1504 lp
->xmt_upper_limit
+ 2);
1507 outw(last
, ioaddr
+ HOST_ADDRESS_REG
);
1508 outw(XMT_CMD
, ioaddr
+ IO_PORT
);
1509 outw(0, ioaddr
+ IO_PORT
);
1510 outw(end
, ioaddr
+ IO_PORT
);
1511 outw(length
, ioaddr
+ IO_PORT
);
1513 if (lp
->version
== LAN595
)
1514 outsw(ioaddr
+ IO_PORT
, buf
, (length
+ 3) >> 1);
1515 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1516 unsigned short temp
= inb(ioaddr
+ INT_MASK_REG
);
1517 outb(temp
| IO_32_BIT
, ioaddr
+ INT_MASK_REG
);
1518 outsl(ioaddr
+ IO_PORT_32_BIT
, buf
, (length
+ 3) >> 2);
1519 outb(temp
& ~(IO_32_BIT
), ioaddr
+ INT_MASK_REG
);
1522 /* A dummy read to flush the DRAM write pipeline */
1523 status
= inw(ioaddr
+ IO_PORT
);
1525 if (lp
->tx_start
== lp
->tx_end
) {
1526 outw(last
, ioaddr
+ lp
->xmt_bar
);
1527 outb(XMT_CMD
, ioaddr
);
1528 lp
->tx_start
= last
; /* I don't like to change tx_start here */
1531 /* update the next address and the chain bit in the
1534 if (lp
->tx_end
!= last
) {
1535 outw(lp
->tx_last
+ XMT_CHAIN
, ioaddr
+ HOST_ADDRESS_REG
);
1536 outw(last
, ioaddr
+ IO_PORT
);
1539 outw(lp
->tx_last
+ XMT_COUNT
, ioaddr
+ HOST_ADDRESS_REG
);
1540 status
= inw(ioaddr
+ IO_PORT
);
1541 outw(status
| CHAIN_BIT
, ioaddr
+ IO_PORT
);
1543 /* Continue the transmit command */
1544 outb(RESUME_XMT_CMD
, ioaddr
);
1551 printk(KERN_DEBUG
"%s: exiting hardware_send_packet routine.\n", dev
->name
);
1557 eepro_rx(struct net_device
*dev
)
1559 struct eepro_local
*lp
= (struct eepro_local
*)dev
->priv
;
1560 short ioaddr
= dev
->base_addr
;
1561 short boguscount
= 20;
1562 short rcv_car
= lp
->rx_start
;
1563 unsigned rcv_event
, rcv_status
, rcv_next_frame
, rcv_size
;
1566 printk(KERN_DEBUG
"%s: entering eepro_rx routine.\n", dev
->name
);
1568 /* Set the read pointer to the start of the RCV */
1569 outw(rcv_car
, ioaddr
+ HOST_ADDRESS_REG
);
1571 rcv_event
= inw(ioaddr
+ IO_PORT
);
1573 while (rcv_event
== RCV_DONE
) {
1575 rcv_status
= inw(ioaddr
+ IO_PORT
);
1576 rcv_next_frame
= inw(ioaddr
+ IO_PORT
);
1577 rcv_size
= inw(ioaddr
+ IO_PORT
);
1579 if ((rcv_status
& (RX_OK
| RX_ERROR
)) == RX_OK
) {
1581 /* Malloc up new buffer. */
1582 struct sk_buff
*skb
;
1584 lp
->stats
.rx_bytes
+=rcv_size
;
1586 skb
= dev_alloc_skb(rcv_size
+5);
1588 printk(KERN_NOTICE
"%s: Memory squeeze, dropping packet.\n", dev
->name
);
1589 lp
->stats
.rx_dropped
++;
1590 rcv_car
= lp
->rx_start
+ RCV_HEADER
+ rcv_size
;
1591 lp
->rx_start
= rcv_next_frame
;
1592 outw(rcv_next_frame
, ioaddr
+ HOST_ADDRESS_REG
);
1599 if (lp
->version
== LAN595
)
1600 insw(ioaddr
+IO_PORT
, skb_put(skb
,rcv_size
), (rcv_size
+ 3) >> 1);
1601 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1602 unsigned short temp
= inb(ioaddr
+ INT_MASK_REG
);
1603 outb(temp
| IO_32_BIT
, ioaddr
+ INT_MASK_REG
);
1604 insl(ioaddr
+IO_PORT_32_BIT
, skb_put(skb
,rcv_size
),
1605 (rcv_size
+ 3) >> 2);
1606 outb(temp
& ~(IO_32_BIT
), ioaddr
+ INT_MASK_REG
);
1609 skb
->protocol
= eth_type_trans(skb
,dev
);
1611 dev
->last_rx
= jiffies
;
1612 lp
->stats
.rx_packets
++;
1615 else { /* Not sure will ever reach here,
1616 I set the 595 to discard bad received frames */
1617 lp
->stats
.rx_errors
++;
1619 if (rcv_status
& 0x0100)
1620 lp
->stats
.rx_over_errors
++;
1622 else if (rcv_status
& 0x0400)
1623 lp
->stats
.rx_frame_errors
++;
1625 else if (rcv_status
& 0x0800)
1626 lp
->stats
.rx_crc_errors
++;
1628 printk(KERN_DEBUG
"%s: event = %#x, status = %#x, next = %#x, size = %#x\n",
1629 dev
->name
, rcv_event
, rcv_status
, rcv_next_frame
, rcv_size
);
1632 if (rcv_status
& 0x1000)
1633 lp
->stats
.rx_length_errors
++;
1635 rcv_car
= lp
->rx_start
+ RCV_HEADER
+ rcv_size
;
1636 lp
->rx_start
= rcv_next_frame
;
1638 if (--boguscount
== 0)
1641 outw(rcv_next_frame
, ioaddr
+ HOST_ADDRESS_REG
);
1642 rcv_event
= inw(ioaddr
+ IO_PORT
);
1646 rcv_car
= lp
->rcv_upper_limit
| 0xff;
1648 outw(rcv_car
- 1, ioaddr
+ RCV_STOP
);
1651 printk(KERN_DEBUG
"%s: exiting eepro_rx routine.\n", dev
->name
);
1655 eepro_transmit_interrupt(struct net_device
*dev
)
1657 struct eepro_local
*lp
= (struct eepro_local
*)dev
->priv
;
1658 short ioaddr
= dev
->base_addr
;
1659 short boguscount
= 25;
1662 while ((lp
->tx_start
!= lp
->tx_end
) && boguscount
--) {
1664 outw(lp
->tx_start
, ioaddr
+ HOST_ADDRESS_REG
);
1665 xmt_status
= inw(ioaddr
+IO_PORT
);
1667 if (!(xmt_status
& TX_DONE_BIT
))
1670 xmt_status
= inw(ioaddr
+IO_PORT
);
1671 lp
->tx_start
= inw(ioaddr
+IO_PORT
);
1673 netif_wake_queue (dev
);
1675 if (xmt_status
& TX_OK
)
1676 lp
->stats
.tx_packets
++;
1678 lp
->stats
.tx_errors
++;
1679 if (xmt_status
& 0x0400) {
1680 lp
->stats
.tx_carrier_errors
++;
1681 printk(KERN_DEBUG
"%s: carrier error\n",
1683 printk(KERN_DEBUG
"%s: XMT status = %#x\n",
1684 dev
->name
, xmt_status
);
1687 printk(KERN_DEBUG
"%s: XMT status = %#x\n",
1688 dev
->name
, xmt_status
);
1689 printk(KERN_DEBUG
"%s: XMT status = %#x\n",
1690 dev
->name
, xmt_status
);
1693 if (xmt_status
& 0x000f) {
1694 lp
->stats
.collisions
+= (xmt_status
& 0x000f);
1697 if ((xmt_status
& 0x0040) == 0x0) {
1698 lp
->stats
.tx_heartbeat_errors
++;
1706 static struct net_device dev_eepro
[MAX_EEPRO
];
1708 static int io
[MAX_EEPRO
];
1709 static int irq
[MAX_EEPRO
];
1710 static int mem
[MAX_EEPRO
] = { /* Size of the rx buffer in KB */
1711 [0 ... MAX_EEPRO
-1] = RCV_DEFAULT_RAM
/1024
1713 static int autodetect
;
1716 /* For linux 2.1.xx */
1718 MODULE_AUTHOR("Pascal Dupuis, and aris@cathedrallabs.org");
1719 MODULE_DESCRIPTION("Intel i82595 ISA EtherExpressPro10/10+ driver");
1720 MODULE_LICENSE("GPL");
1722 MODULE_PARM(io
, "1-" __MODULE_STRING(MAX_EEPRO
) "i");
1723 MODULE_PARM(irq
, "1-" __MODULE_STRING(MAX_EEPRO
) "i");
1724 MODULE_PARM(mem
, "1-" __MODULE_STRING(MAX_EEPRO
) "i");
1725 MODULE_PARM(autodetect
, "1-" __MODULE_STRING(1) "i");
1726 MODULE_PARM_DESC(io
, "EtherExpress Pro/10 I/O base addres(es)");
1727 MODULE_PARM_DESC(irq
, "EtherExpress Pro/10 IRQ number(s)");
1728 MODULE_PARM_DESC(mem
, "EtherExpress Pro/10 Rx buffer size(es) in kB (3-29)");
1729 MODULE_PARM_DESC(autodetect
, "EtherExpress Pro/10 force board(s) detection (0-1)");
1735 if (io
[0] == 0 && autodetect
== 0) {
1736 printk(KERN_WARNING
"eepro_init_module: Probe is very dangerous in ISA boards!\n");
1737 printk(KERN_WARNING
"eepro_init_module: Please add \"autodetect=1\" to force probe\n");
1740 else if (autodetect
) {
1741 /* if autodetect is set then we must force detection */
1744 printk(KERN_INFO
"eepro_init_module: Auto-detecting boards (May God protect us...)\n");
1747 for (i
= 0; i
< MAX_EEPRO
; i
++) {
1748 struct net_device
*d
= &dev_eepro
[n_eepro
];
1749 d
->mem_end
= mem
[i
];
1750 d
->base_addr
= io
[i
];
1752 d
->init
= eepro_probe
;
1754 if (register_netdev(d
) == 0)
1761 printk(KERN_INFO
"%s", version
);
1763 return n_eepro
? 0 : -ENODEV
;
1767 cleanup_module(void)
1771 for (i
=0; i
<n_eepro
; i
++) {
1772 struct net_device
*d
= &dev_eepro
[i
];
1773 unregister_netdev(d
);
1778 /* If we don't do this, we can't re-insmod it later. */
1779 release_region(d
->base_addr
, EEPRO_IO_EXTENT
);