blob: cd2475683027703d588727ecfbd481ad877040c0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* eepro.c: Intel EtherExpress Pro/10 device driver for Linux. */
2/*
3 Written 1994, 1995,1996 by Bao C. Ha.
4
5 Copyright (C) 1994, 1995,1996 by Bao C. Ha.
6
7 This software may be used and distributed
8 according to the terms of the GNU General Public License,
9 incorporated herein by reference.
10
11 The author may be reached at bao.ha@srs.gov
12 or 418 Hastings Place, Martinez, GA 30907.
13
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!
18
19 Bugs:
20
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.
24
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.
51
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)
65
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)
71
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)
78
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)
82
83 0.07a Fix a stat report which counts every packet as a
84 heart-beat failure. (BCH, 6/3/95)
85
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)
91
92 0.06a,b Interim released. Minor changes in the comments and
93 print out format. (BCH, 3/9/95 and 3/14/95)
94
95 0.06 First stable release that I am comfortable with. (BCH,
96 3/2/95)
97
98 0.05 Complete testing of multicast. (BCH, 2/23/95)
99
100 0.04 Adding multicast support. (BCH, 2/14/95)
101
102 0.03 First widely alpha release for public testing.
103 (BCH, 2/14/95)
104
105*/
106
107static const char version[] =
108 "eepro.c: v0.13b 09/13/2004 aris@cathedrallabs.org\n";
109
110#include <linux/module.h>
111
112/*
113 Sources:
114
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.
120
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.
124
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.
128
129 The User Manual for the 82595. It provides a lot of the missing
130 information.
131
132*/
133
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>
151
152#include <asm/system.h>
153#include <asm/io.h>
154#include <asm/dma.h>
155
156#define DRV_NAME "eepro"
157#define DRV_VERSION "0.13b"
158
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
164enum iftype { AUI=0, BNC=1, TPE=2 };
165
166/* First, a few definitions that the brave might change. */
167/* A zero-terminated list of I/O addresses to be probed. */
168static 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 */
172
173/* To try the (not-really PnP Wakeup: */
174/*
175#define PnPWakeup
176*/
177
178/* use 0 for production, 1 for verification, >2 for debug */
179#ifndef NET_DEBUG
180#define NET_DEBUG 0
181#endif
182static unsigned int net_debug = NET_DEBUG;
183
184/* The number of low I/O ports used by the ethercard. */
185#define EEPRO_IO_EXTENT 16
186
187/* Different 82595 chips */
188#define LAN595 0
189#define LAN595TX 1
190#define LAN595FX 2
191#define LAN595FX_10ISA 3
192
193/* Information that need to be kept for each board. */
194struct eepro_local {
195 struct net_device_stats stats;
196 unsigned rx_start;
197 unsigned tx_start; /* start of the transmit chain */
198 int tx_last; /* pointer to last packet in the transmit chain */
199 unsigned tx_end; /* end of the transmit chain (plus 1) */
200 int eepro; /* 1 for the EtherExpress Pro/10,
201 2 for the EtherExpress Pro/10+,
202 3 for the EtherExpress 10 (blue cards),
203 0 for other 82595-based lan cards. */
204 int version; /* a flag to indicate if this is a TX or FX
205 version of the 82595 chip. */
206 int stepping;
207
208 spinlock_t lock; /* Serializing lock */
209
210 unsigned rcv_ram; /* pre-calculated space for rx */
211 unsigned xmt_ram; /* pre-calculated space for tx */
212 unsigned char xmt_bar;
213 unsigned char xmt_lower_limit_reg;
214 unsigned char xmt_upper_limit_reg;
215 short xmt_lower_limit;
216 short xmt_upper_limit;
217 short rcv_lower_limit;
218 short rcv_upper_limit;
219 unsigned char eeprom_reg;
220 unsigned short word[8];
221};
222
223/* The station (ethernet) address prefix, used for IDing the board. */
224#define SA_ADDR0 0x00 /* Etherexpress Pro/10 */
225#define SA_ADDR1 0xaa
226#define SA_ADDR2 0x00
227
228#define GetBit(x,y) ((x & (1<<y))>>y)
229
230/* EEPROM Word 0: */
231#define ee_PnP 0 /* Plug 'n Play enable bit */
232#define ee_Word1 1 /* Word 1? */
233#define ee_BusWidth 2 /* 8/16 bit */
234#define ee_FlashAddr 3 /* Flash Address */
235#define ee_FlashMask 0x7 /* Mask */
236#define ee_AutoIO 6 /* */
237#define ee_reserved0 7 /* =0! */
238#define ee_Flash 8 /* Flash there? */
239#define ee_AutoNeg 9 /* Auto Negotiation enabled? */
240#define ee_IO0 10 /* IO Address LSB */
241#define ee_IO0Mask 0x /*...*/
242#define ee_IO1 15 /* IO MSB */
243
244/* EEPROM Word 1: */
245#define ee_IntSel 0 /* Interrupt */
246#define ee_IntMask 0x7
247#define ee_LI 3 /* Link Integrity 0= enabled */
248#define ee_PC 4 /* Polarity Correction 0= enabled */
249#define ee_TPE_AUI 5 /* PortSelection 1=TPE */
250#define ee_Jabber 6 /* Jabber prevention 0= enabled */
251#define ee_AutoPort 7 /* Auto Port Selection 1= Disabled */
252#define ee_SMOUT 8 /* SMout Pin Control 0= Input */
253#define ee_PROM 9 /* Flash EPROM / PROM 0=Flash */
254#define ee_reserved1 10 /* .. 12 =0! */
255#define ee_AltReady 13 /* Alternate Ready, 0=normal */
256#define ee_reserved2 14 /* =0! */
257#define ee_Duplex 15
258
259/* Word2,3,4: */
260#define ee_IA5 0 /*bit start for individual Addr Byte 5 */
261#define ee_IA4 8 /*bit start for individual Addr Byte 5 */
262#define ee_IA3 0 /*bit start for individual Addr Byte 5 */
263#define ee_IA2 8 /*bit start for individual Addr Byte 5 */
264#define ee_IA1 0 /*bit start for individual Addr Byte 5 */
265#define ee_IA0 8 /*bit start for individual Addr Byte 5 */
266
267/* Word 5: */
268#define ee_BNC_TPE 0 /* 0=TPE */
269#define ee_BootType 1 /* 00=None, 01=IPX, 10=ODI, 11=NDIS */
270#define ee_BootTypeMask 0x3
271#define ee_NumConn 3 /* Number of Connections 0= One or Two */
272#define ee_FlashSock 4 /* Presence of Flash Socket 0= Present */
273#define ee_PortTPE 5
274#define ee_PortBNC 6
275#define ee_PortAUI 7
276#define ee_PowerMgt 10 /* 0= disabled */
277#define ee_CP 13 /* Concurrent Processing */
278#define ee_CPMask 0x7
279
280/* Word 6: */
281#define ee_Stepping 0 /* Stepping info */
282#define ee_StepMask 0x0F
283#define ee_BoardID 4 /* Manucaturer Board ID, reserved */
284#define ee_BoardMask 0x0FFF
285
286/* Word 7: */
287#define ee_INT_TO_IRQ 0 /* int to IRQ Mapping = 0x1EB8 for Pro/10+ */
288#define ee_FX_INT2IRQ 0x1EB8 /* the _only_ mapping allowed for FX chips */
289
290/*..*/
291#define ee_SIZE 0x40 /* total EEprom Size */
292#define ee_Checksum 0xBABA /* initial and final value for adding checksum */
293
294
295/* Card identification via EEprom: */
296#define ee_addr_vendor 0x10 /* Word offset for EISA Vendor ID */
297#define ee_addr_id 0x11 /* Word offset for Card ID */
298#define ee_addr_SN 0x12 /* Serial Number */
299#define ee_addr_CRC_8 0x14 /* CRC over last thee Bytes */
300
301
302#define ee_vendor_intel0 0x25 /* Vendor ID Intel */
303#define ee_vendor_intel1 0xD4
304#define ee_id_eepro10p0 0x10 /* ID for eepro/10+ */
305#define ee_id_eepro10p1 0x31
306
307#define TX_TIMEOUT 40
308
309/* Index to functions, as function prototypes. */
310
311static int eepro_probe1(struct net_device *dev, int autoprobe);
312static int eepro_open(struct net_device *dev);
313static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev);
314static irqreturn_t eepro_interrupt(int irq, void *dev_id, struct pt_regs *regs);
315static void eepro_rx(struct net_device *dev);
316static void eepro_transmit_interrupt(struct net_device *dev);
317static int eepro_close(struct net_device *dev);
318static struct net_device_stats *eepro_get_stats(struct net_device *dev);
319static void set_multicast_list(struct net_device *dev);
320static void eepro_tx_timeout (struct net_device *dev);
321
322static int read_eeprom(int ioaddr, int location, struct net_device *dev);
323static int hardware_send_packet(struct net_device *dev, void *buf, short length);
324static int eepro_grab_irq(struct net_device *dev);
325
326/*
327 Details of the i82595.
328
329You will need either the datasheet or the user manual to understand what
330is going on here. The 82595 is very different from the 82586, 82593.
331
332The receive algorithm in eepro_rx() is just an implementation of the
333RCV ring structure that the Intel 82595 imposes at the hardware level.
334The receive buffer is set at 24K, and the transmit buffer is 8K. I
335am assuming that the total buffer memory is 32K, which is true for the
336Intel EtherExpress Pro/10. If it is less than that on a generic card,
337the driver will be broken.
338
339The transmit algorithm in the hardware_send_packet() is similar to the
340one in the eepro_rx(). The transmit buffer is a ring linked list.
341I just queue the next available packet to the end of the list. In my
342system, the 82595 is so fast that the list seems to always contain a
343single packet. In other systems with faster computers and more congested
344network traffics, the ring linked list should improve performance by
345allowing up to 8K worth of packets to be queued.
346
347The sizes of the receive and transmit buffers can now be changed via lilo
348or insmod. Lilo uses the appended line "ether=io,irq,debug,rx-buffer,eth0"
349where rx-buffer is in KB unit. Modules uses the parameter mem which is
350also in KB unit, for example "insmod io=io-address irq=0 mem=rx-buffer."
351The receive buffer has to be more than 3K or less than 29K. Otherwise,
352it is reset to the default of 24K, and, hence, 8K for the trasnmit
353buffer (transmit-buffer = 32K - receive-buffer).
354
355*/
356#define RAM_SIZE 0x8000
357
358#define RCV_HEADER 8
359#define RCV_DEFAULT_RAM 0x6000
360
361#define XMT_HEADER 8
362#define XMT_DEFAULT_RAM (RAM_SIZE - RCV_DEFAULT_RAM)
363
364#define XMT_START_PRO RCV_DEFAULT_RAM
365#define XMT_START_10 0x0000
366#define RCV_START_PRO 0x0000
367#define RCV_START_10 XMT_DEFAULT_RAM
368
369#define RCV_DONE 0x0008
370#define RX_OK 0x2000
371#define RX_ERROR 0x0d81
372
373#define TX_DONE_BIT 0x0080
374#define TX_OK 0x2000
375#define CHAIN_BIT 0x8000
376#define XMT_STATUS 0x02
377#define XMT_CHAIN 0x04
378#define XMT_COUNT 0x06
379
380#define BANK0_SELECT 0x00
381#define BANK1_SELECT 0x40
382#define BANK2_SELECT 0x80
383
384/* Bank 0 registers */
385#define COMMAND_REG 0x00 /* Register 0 */
386#define MC_SETUP 0x03
387#define XMT_CMD 0x04
388#define DIAGNOSE_CMD 0x07
389#define RCV_ENABLE_CMD 0x08
390#define RCV_DISABLE_CMD 0x0a
391#define STOP_RCV_CMD 0x0b
392#define RESET_CMD 0x0e
393#define POWER_DOWN_CMD 0x18
394#define RESUME_XMT_CMD 0x1c
395#define SEL_RESET_CMD 0x1e
396#define STATUS_REG 0x01 /* Register 1 */
397#define RX_INT 0x02
398#define TX_INT 0x04
399#define EXEC_STATUS 0x30
400#define ID_REG 0x02 /* Register 2 */
401#define R_ROBIN_BITS 0xc0 /* round robin counter */
402#define ID_REG_MASK 0x2c
403#define ID_REG_SIG 0x24
404#define AUTO_ENABLE 0x10
405#define INT_MASK_REG 0x03 /* Register 3 */
406#define RX_STOP_MASK 0x01
407#define RX_MASK 0x02
408#define TX_MASK 0x04
409#define EXEC_MASK 0x08
410#define ALL_MASK 0x0f
411#define IO_32_BIT 0x10
412#define RCV_BAR 0x04 /* The following are word (16-bit) registers */
413#define RCV_STOP 0x06
414
415#define XMT_BAR_PRO 0x0a
416#define XMT_BAR_10 0x0b
417
418#define HOST_ADDRESS_REG 0x0c
419#define IO_PORT 0x0e
420#define IO_PORT_32_BIT 0x0c
421
422/* Bank 1 registers */
423#define REG1 0x01
424#define WORD_WIDTH 0x02
425#define INT_ENABLE 0x80
426#define INT_NO_REG 0x02
427#define RCV_LOWER_LIMIT_REG 0x08
428#define RCV_UPPER_LIMIT_REG 0x09
429
430#define XMT_LOWER_LIMIT_REG_PRO 0x0a
431#define XMT_UPPER_LIMIT_REG_PRO 0x0b
432#define XMT_LOWER_LIMIT_REG_10 0x0b
433#define XMT_UPPER_LIMIT_REG_10 0x0a
434
435/* Bank 2 registers */
436#define XMT_Chain_Int 0x20 /* Interrupt at the end of the transmit chain */
437#define XMT_Chain_ErrStop 0x40 /* Interrupt at the end of the chain even if there are errors */
438#define RCV_Discard_BadFrame 0x80 /* Throw bad frames away, and continue to receive others */
439#define REG2 0x02
440#define PRMSC_Mode 0x01
441#define Multi_IA 0x20
442#define REG3 0x03
443#define TPE_BIT 0x04
444#define BNC_BIT 0x20
445#define REG13 0x0d
446#define FDX 0x00
447#define A_N_ENABLE 0x02
448
449#define I_ADD_REG0 0x04
450#define I_ADD_REG1 0x05
451#define I_ADD_REG2 0x06
452#define I_ADD_REG3 0x07
453#define I_ADD_REG4 0x08
454#define I_ADD_REG5 0x09
455
456#define EEPROM_REG_PRO 0x0a
457#define EEPROM_REG_10 0x0b
458
459#define EESK 0x01
460#define EECS 0x02
461#define EEDI 0x04
462#define EEDO 0x08
463
464/* do a full reset */
465#define eepro_reset(ioaddr) outb(RESET_CMD, ioaddr)
466
467/* do a nice reset */
468#define eepro_sel_reset(ioaddr) { \
469 outb(SEL_RESET_CMD, ioaddr); \
470 SLOW_DOWN; \
471 SLOW_DOWN; \
472 }
473
474/* disable all interrupts */
475#define eepro_dis_int(ioaddr) outb(ALL_MASK, ioaddr + INT_MASK_REG)
476
477/* clear all interrupts */
478#define eepro_clear_int(ioaddr) outb(ALL_MASK, ioaddr + STATUS_REG)
479
480/* enable tx/rx */
481#define eepro_en_int(ioaddr) outb(ALL_MASK & ~(RX_MASK | TX_MASK), \
482 ioaddr + INT_MASK_REG)
483
484/* enable exec event interrupt */
485#define eepro_en_intexec(ioaddr) outb(ALL_MASK & ~(EXEC_MASK), ioaddr + INT_MASK_REG)
486
487/* enable rx */
488#define eepro_en_rx(ioaddr) outb(RCV_ENABLE_CMD, ioaddr)
489
490/* disable rx */
491#define eepro_dis_rx(ioaddr) outb(RCV_DISABLE_CMD, ioaddr)
492
493/* switch bank */
494#define eepro_sw2bank0(ioaddr) outb(BANK0_SELECT, ioaddr)
495#define eepro_sw2bank1(ioaddr) outb(BANK1_SELECT, ioaddr)
496#define eepro_sw2bank2(ioaddr) outb(BANK2_SELECT, ioaddr)
497
498/* enable interrupt line */
499#define eepro_en_intline(ioaddr) outb(inb(ioaddr + REG1) | INT_ENABLE,\
500 ioaddr + REG1)
501
502/* disable interrupt line */
503#define eepro_dis_intline(ioaddr) outb(inb(ioaddr + REG1) & 0x7f, \
504 ioaddr + REG1);
505
506/* set diagnose flag */
507#define eepro_diag(ioaddr) outb(DIAGNOSE_CMD, ioaddr)
508
509/* ack for rx int */
510#define eepro_ack_rx(ioaddr) outb (RX_INT, ioaddr + STATUS_REG)
511
512/* ack for tx int */
513#define eepro_ack_tx(ioaddr) outb (TX_INT, ioaddr + STATUS_REG)
514
515/* a complete sel reset */
516#define eepro_complete_selreset(ioaddr) { \
517 lp->stats.tx_errors++;\
518 eepro_sel_reset(ioaddr);\
519 lp->tx_end = \
520 lp->xmt_lower_limit;\
521 lp->tx_start = lp->tx_end;\
522 lp->tx_last = 0;\
523 dev->trans_start = jiffies;\
524 netif_wake_queue(dev);\
525 eepro_en_rx(ioaddr);\
526 }
527
528/* Check for a network adaptor of this type, and return '0' if one exists.
529 If dev->base_addr == 0, probe all likely locations.
530 If dev->base_addr == 1, always return failure.
531 If dev->base_addr == 2, allocate space for the device and return success
532 (detachable devices only).
533 */
534static int __init do_eepro_probe(struct net_device *dev)
535{
536 int i;
537 int base_addr = dev->base_addr;
538 int irq = dev->irq;
539
540 SET_MODULE_OWNER(dev);
541
542#ifdef PnPWakeup
543 /* XXXX for multiple cards should this only be run once? */
544
545 /* Wakeup: */
546 #define WakeupPort 0x279
547 #define WakeupSeq {0x6A, 0xB5, 0xDA, 0xED, 0xF6, 0xFB, 0x7D, 0xBE,\
548 0xDF, 0x6F, 0x37, 0x1B, 0x0D, 0x86, 0xC3, 0x61,\
549 0xB0, 0x58, 0x2C, 0x16, 0x8B, 0x45, 0xA2, 0xD1,\
550 0xE8, 0x74, 0x3A, 0x9D, 0xCE, 0xE7, 0x73, 0x43}
551
552 {
553 unsigned short int WS[32]=WakeupSeq;
554
555 if (check_region(WakeupPort, 2)==0) {
556
557 if (net_debug>5)
558 printk(KERN_DEBUG "Waking UP\n");
559
560 outb_p(0,WakeupPort);
561 outb_p(0,WakeupPort);
562 for (i=0; i<32; i++) {
563 outb_p(WS[i],WakeupPort);
564 if (net_debug>5) printk(KERN_DEBUG ": %#x ",WS[i]);
565 }
566 } else printk(KERN_WARNING "Checkregion Failed!\n");
567 }
568#endif
569
570 if (base_addr > 0x1ff) /* Check a single specified location. */
571 return eepro_probe1(dev, 0);
572
573 else if (base_addr != 0) /* Don't probe at all. */
574 return -ENXIO;
575
576 for (i = 0; eepro_portlist[i]; i++) {
577 dev->base_addr = eepro_portlist[i];
578 dev->irq = irq;
579 if (eepro_probe1(dev, 1) == 0)
580 return 0;
581 }
582
583 return -ENODEV;
584}
585
586#ifndef MODULE
587struct net_device * __init eepro_probe(int unit)
588{
589 struct net_device *dev = alloc_etherdev(sizeof(struct eepro_local));
590 int err;
591
592 if (!dev)
593 return ERR_PTR(-ENODEV);
594
595 SET_MODULE_OWNER(dev);
596
597 sprintf(dev->name, "eth%d", unit);
598 netdev_boot_setup_check(dev);
599
600 err = do_eepro_probe(dev);
601 if (err)
602 goto out;
603 err = register_netdev(dev);
604 if (err)
605 goto out1;
606 return dev;
607out1:
608 release_region(dev->base_addr, EEPRO_IO_EXTENT);
609out:
610 free_netdev(dev);
611 return ERR_PTR(err);
612}
613#endif
614
615static void __init printEEPROMInfo(struct net_device *dev)
616{
617 struct eepro_local *lp = (struct eepro_local *)dev->priv;
618 int ioaddr = dev->base_addr;
619 unsigned short Word;
620 int i,j;
621
622 j = ee_Checksum;
623 for (i = 0; i < 8; i++)
624 j += lp->word[i];
625 for ( ; i < ee_SIZE; i++)
626 j += read_eeprom(ioaddr, i, dev);
627
628 printk(KERN_DEBUG "Checksum: %#x\n",j&0xffff);
629
630 Word = lp->word[0];
631 printk(KERN_DEBUG "Word0:\n");
632 printk(KERN_DEBUG " Plug 'n Pray: %d\n",GetBit(Word,ee_PnP));
633 printk(KERN_DEBUG " Buswidth: %d\n",(GetBit(Word,ee_BusWidth)+1)*8 );
634 printk(KERN_DEBUG " AutoNegotiation: %d\n",GetBit(Word,ee_AutoNeg));
635 printk(KERN_DEBUG " IO Address: %#x\n", (Word>>ee_IO0)<<4);
636
637 if (net_debug>4) {
638 Word = lp->word[1];
639 printk(KERN_DEBUG "Word1:\n");
640 printk(KERN_DEBUG " INT: %d\n", Word & ee_IntMask);
641 printk(KERN_DEBUG " LI: %d\n", GetBit(Word,ee_LI));
642 printk(KERN_DEBUG " PC: %d\n", GetBit(Word,ee_PC));
643 printk(KERN_DEBUG " TPE/AUI: %d\n", GetBit(Word,ee_TPE_AUI));
644 printk(KERN_DEBUG " Jabber: %d\n", GetBit(Word,ee_Jabber));
645 printk(KERN_DEBUG " AutoPort: %d\n", GetBit(!Word,ee_Jabber));
646 printk(KERN_DEBUG " Duplex: %d\n", GetBit(Word,ee_Duplex));
647 }
648
649 Word = lp->word[5];
650 printk(KERN_DEBUG "Word5:\n");
651 printk(KERN_DEBUG " BNC: %d\n",GetBit(Word,ee_BNC_TPE));
652 printk(KERN_DEBUG " NumConnectors: %d\n",GetBit(Word,ee_NumConn));
653 printk(KERN_DEBUG " Has ");
654 if (GetBit(Word,ee_PortTPE)) printk(KERN_DEBUG "TPE ");
655 if (GetBit(Word,ee_PortBNC)) printk(KERN_DEBUG "BNC ");
656 if (GetBit(Word,ee_PortAUI)) printk(KERN_DEBUG "AUI ");
657 printk(KERN_DEBUG "port(s) \n");
658
659 Word = lp->word[6];
660 printk(KERN_DEBUG "Word6:\n");
661 printk(KERN_DEBUG " Stepping: %d\n",Word & ee_StepMask);
662 printk(KERN_DEBUG " BoardID: %d\n",Word>>ee_BoardID);
663
664 Word = lp->word[7];
665 printk(KERN_DEBUG "Word7:\n");
666 printk(KERN_DEBUG " INT to IRQ:\n");
667
668 for (i=0, j=0; i<15; i++)
669 if (GetBit(Word,i)) printk(KERN_DEBUG " INT%d -> IRQ %d;",j++,i);
670
671 printk(KERN_DEBUG "\n");
672}
673
674/* function to recalculate the limits of buffer based on rcv_ram */
675static void eepro_recalc (struct net_device *dev)
676{
677 struct eepro_local * lp;
678
679 lp = netdev_priv(dev);
680 lp->xmt_ram = RAM_SIZE - lp->rcv_ram;
681
682 if (lp->eepro == LAN595FX_10ISA) {
683 lp->xmt_lower_limit = XMT_START_10;
684 lp->xmt_upper_limit = (lp->xmt_ram - 2);
685 lp->rcv_lower_limit = lp->xmt_ram;
686 lp->rcv_upper_limit = (RAM_SIZE - 2);
687 }
688 else {
689 lp->rcv_lower_limit = RCV_START_PRO;
690 lp->rcv_upper_limit = (lp->rcv_ram - 2);
691 lp->xmt_lower_limit = lp->rcv_ram;
692 lp->xmt_upper_limit = (RAM_SIZE - 2);
693 }
694}
695
696/* prints boot-time info */
697static void __init eepro_print_info (struct net_device *dev)
698{
699 struct eepro_local * lp = netdev_priv(dev);
700 int i;
701 const char * ifmap[] = {"AUI", "10Base2", "10BaseT"};
702
703 i = inb(dev->base_addr + ID_REG);
704 printk(KERN_DEBUG " id: %#x ",i);
705 printk(" io: %#x ", (unsigned)dev->base_addr);
706
707 switch (lp->eepro) {
708 case LAN595FX_10ISA:
709 printk("%s: Intel EtherExpress 10 ISA\n at %#x,",
710 dev->name, (unsigned)dev->base_addr);
711 break;
712 case LAN595FX:
713 printk("%s: Intel EtherExpress Pro/10+ ISA\n at %#x,",
714 dev->name, (unsigned)dev->base_addr);
715 break;
716 case LAN595TX:
717 printk("%s: Intel EtherExpress Pro/10 ISA at %#x,",
718 dev->name, (unsigned)dev->base_addr);
719 break;
720 case LAN595:
721 printk("%s: Intel 82595-based lan card at %#x,",
722 dev->name, (unsigned)dev->base_addr);
723 }
724
725 for (i=0; i < 6; i++)
726 printk("%c%02x", i ? ':' : ' ', dev->dev_addr[i]);
727
728 if (net_debug > 3)
729 printk(KERN_DEBUG ", %dK RCV buffer",
730 (int)(lp->rcv_ram)/1024);
731
732 if (dev->irq > 2)
733 printk(", IRQ %d, %s.\n", dev->irq, ifmap[dev->if_port]);
734 else
735 printk(", %s.\n", ifmap[dev->if_port]);
736
737 if (net_debug > 3) {
738 i = lp->word[5];
739 if (i & 0x2000) /* bit 13 of EEPROM word 5 */
740 printk(KERN_DEBUG "%s: Concurrent Processing is "
741 "enabled but not used!\n", dev->name);
742 }
743
744 /* Check the station address for the manufacturer's code */
745 if (net_debug>3)
746 printEEPROMInfo(dev);
747}
748
749static struct ethtool_ops eepro_ethtool_ops;
750
751/* This is the real probe routine. Linux has a history of friendly device
752 probes on the ISA bus. A good device probe avoids doing writes, and
753 verifies that the correct device exists and functions. */
754
755static int __init eepro_probe1(struct net_device *dev, int autoprobe)
756{
757 unsigned short station_addr[3], id, counter;
758 int i;
759 struct eepro_local *lp;
760 int ioaddr = dev->base_addr;
761
762 /* Grab the region so we can find another board if autoIRQ fails. */
763 if (!request_region(ioaddr, EEPRO_IO_EXTENT, DRV_NAME)) {
764 if (!autoprobe)
765 printk(KERN_WARNING "EEPRO: io-port 0x%04x in use \n",
766 ioaddr);
767 return -EBUSY;
768 }
769
770 /* Now, we are going to check for the signature of the
771 ID_REG (register 2 of bank 0) */
772
773 id = inb(ioaddr + ID_REG);
774
775 if ((id & ID_REG_MASK) != ID_REG_SIG)
776 goto exit;
777
778 /* We seem to have the 82595 signature, let's
779 play with its counter (last 2 bits of
780 register 2 of bank 0) to be sure. */
781
782 counter = id & R_ROBIN_BITS;
783
784 if ((inb(ioaddr + ID_REG) & R_ROBIN_BITS) != (counter + 0x40))
785 goto exit;
786
787 lp = netdev_priv(dev);
788 memset(lp, 0, sizeof(struct eepro_local));
789 lp->xmt_bar = XMT_BAR_PRO;
790 lp->xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_PRO;
791 lp->xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_PRO;
792 lp->eeprom_reg = EEPROM_REG_PRO;
793 spin_lock_init(&lp->lock);
794
795 /* Now, get the ethernet hardware address from
796 the EEPROM */
797 station_addr[0] = read_eeprom(ioaddr, 2, dev);
798
799 /* FIXME - find another way to know that we've found
800 * an Etherexpress 10
801 */
802 if (station_addr[0] == 0x0000 || station_addr[0] == 0xffff) {
803 lp->eepro = LAN595FX_10ISA;
804 lp->eeprom_reg = EEPROM_REG_10;
805 lp->xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_10;
806 lp->xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_10;
807 lp->xmt_bar = XMT_BAR_10;
808 station_addr[0] = read_eeprom(ioaddr, 2, dev);
809 }
810
811 /* get all words at once. will be used here and for ethtool */
812 for (i = 0; i < 8; i++) {
813 lp->word[i] = read_eeprom(ioaddr, i, dev);
814 }
815 station_addr[1] = lp->word[3];
816 station_addr[2] = lp->word[4];
817
818 if (!lp->eepro) {
819 if (lp->word[7] == ee_FX_INT2IRQ)
820 lp->eepro = 2;
821 else if (station_addr[2] == SA_ADDR1)
822 lp->eepro = 1;
823 }
824
825 /* Fill in the 'dev' fields. */
826 for (i=0; i < 6; i++)
827 dev->dev_addr[i] = ((unsigned char *) station_addr)[5-i];
828
829 /* RX buffer must be more than 3K and less than 29K */
830 if (dev->mem_end < 3072 || dev->mem_end > 29696)
831 lp->rcv_ram = RCV_DEFAULT_RAM;
832
833 /* calculate {xmt,rcv}_{lower,upper}_limit */
834 eepro_recalc(dev);
835
836 if (GetBit(lp->word[5], ee_BNC_TPE))
837 dev->if_port = BNC;
838 else
839 dev->if_port = TPE;
840
841 if (dev->irq < 2 && lp->eepro != 0) {
842 /* Mask off INT number */
843 int count = lp->word[1] & 7;
844 unsigned irqMask = lp->word[7];
845
846 while (count--)
847 irqMask &= irqMask - 1;
848
849 count = ffs(irqMask);
850
851 if (count)
852 dev->irq = count - 1;
853
854 if (dev->irq < 2) {
855 printk(KERN_ERR " Duh! illegal interrupt vector stored in EEPROM.\n");
856 goto exit;
857 } else if (dev->irq == 2) {
858 dev->irq = 9;
859 }
860 }
861
862 dev->open = eepro_open;
863 dev->stop = eepro_close;
864 dev->hard_start_xmit = eepro_send_packet;
865 dev->get_stats = eepro_get_stats;
866 dev->set_multicast_list = &set_multicast_list;
867 dev->tx_timeout = eepro_tx_timeout;
868 dev->watchdog_timeo = TX_TIMEOUT;
869 dev->ethtool_ops = &eepro_ethtool_ops;
870
871 /* print boot time info */
872 eepro_print_info(dev);
873
874 /* reset 82595 */
875 eepro_reset(ioaddr);
876 return 0;
877exit:
878 release_region(dev->base_addr, EEPRO_IO_EXTENT);
879 return -ENODEV;
880}
881
882/* Open/initialize the board. This is called (in the current kernel)
883 sometime after booting when the 'ifconfig' program is run.
884
885 This routine should set everything up anew at each open, even
886 registers that "should" only need to be set once at boot, so that
887 there is non-reboot way to recover if something goes wrong.
888 */
889
890static char irqrmap[] = {-1,-1,0,1,-1,2,-1,-1,-1,0,3,4,-1,-1,-1,-1};
891static char irqrmap2[] = {-1,-1,4,0,1,2,-1,3,-1,4,5,6,7,-1,-1,-1};
892static int eepro_grab_irq(struct net_device *dev)
893{
894 int irqlist[] = { 3, 4, 5, 7, 9, 10, 11, 12, 0 };
895 int *irqp = irqlist, temp_reg, ioaddr = dev->base_addr;
896
897 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
898
899 /* Enable the interrupt line. */
900 eepro_en_intline(ioaddr);
901
902 /* be CAREFUL, BANK 0 now */
903 eepro_sw2bank0(ioaddr);
904
905 /* clear all interrupts */
906 eepro_clear_int(ioaddr);
907
908 /* Let EXEC event to interrupt */
909 eepro_en_intexec(ioaddr);
910
911 do {
912 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
913
914 temp_reg = inb(ioaddr + INT_NO_REG);
915 outb((temp_reg & 0xf8) | irqrmap[*irqp], ioaddr + INT_NO_REG);
916
917 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
918
919 if (request_irq (*irqp, NULL, SA_SHIRQ, "bogus", dev) != EBUSY) {
920 unsigned long irq_mask;
921 /* Twinkle the interrupt, and check if it's seen */
922 irq_mask = probe_irq_on();
923
924 eepro_diag(ioaddr); /* RESET the 82595 */
925 mdelay(20);
926
927 if (*irqp == probe_irq_off(irq_mask)) /* It's a good IRQ line */
928 break;
929
930 /* clear all interrupts */
931 eepro_clear_int(ioaddr);
932 }
933 } while (*++irqp);
934
935 eepro_sw2bank1(ioaddr); /* Switch back to Bank 1 */
936
937 /* Disable the physical interrupt line. */
938 eepro_dis_intline(ioaddr);
939
940 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
941
942 /* Mask all the interrupts. */
943 eepro_dis_int(ioaddr);
944
945 /* clear all interrupts */
946 eepro_clear_int(ioaddr);
947
948 return dev->irq;
949}
950
951static int eepro_open(struct net_device *dev)
952{
953 unsigned short temp_reg, old8, old9;
954 int irqMask;
955 int i, ioaddr = dev->base_addr;
956 struct eepro_local *lp = netdev_priv(dev);
957
958 if (net_debug > 3)
959 printk(KERN_DEBUG "%s: entering eepro_open routine.\n", dev->name);
960
961 irqMask = lp->word[7];
962
963 if (lp->eepro == LAN595FX_10ISA) {
964 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 3;\n");
965 }
966 else if (irqMask == ee_FX_INT2IRQ) /* INT to IRQ Mask */
967 {
968 lp->eepro = 2; /* Yes, an Intel EtherExpress Pro/10+ */
969 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 2;\n");
970 }
971
972 else if ((dev->dev_addr[0] == SA_ADDR0 &&
973 dev->dev_addr[1] == SA_ADDR1 &&
974 dev->dev_addr[2] == SA_ADDR2))
975 {
976 lp->eepro = 1;
977 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 1;\n");
978 } /* Yes, an Intel EtherExpress Pro/10 */
979
980 else lp->eepro = 0; /* No, it is a generic 82585 lan card */
981
982 /* Get the interrupt vector for the 82595 */
983 if (dev->irq < 2 && eepro_grab_irq(dev) == 0) {
984 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
985 return -EAGAIN;
986 }
987
988 if (request_irq(dev->irq , &eepro_interrupt, 0, dev->name, dev)) {
989 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
990 return -EAGAIN;
991 }
992
993#ifdef irq2dev_map
994 if (((irq2dev_map[dev->irq] != 0)
995 || (irq2dev_map[dev->irq] = dev) == 0) &&
996 (irq2dev_map[dev->irq]!=dev)) {
997 /* printk("%s: IRQ map wrong\n", dev->name); */
998 free_irq(dev->irq, dev);
999 return -EAGAIN;
1000 }
1001#endif
1002
1003 /* Initialize the 82595. */
1004
1005 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1006 temp_reg = inb(ioaddr + lp->eeprom_reg);
1007
1008 lp->stepping = temp_reg >> 5; /* Get the stepping number of the 595 */
1009
1010 if (net_debug > 3)
1011 printk(KERN_DEBUG "The stepping of the 82595 is %d\n", lp->stepping);
1012
1013 if (temp_reg & 0x10) /* Check the TurnOff Enable bit */
1014 outb(temp_reg & 0xef, ioaddr + lp->eeprom_reg);
1015 for (i=0; i < 6; i++)
1016 outb(dev->dev_addr[i] , ioaddr + I_ADD_REG0 + i);
1017
1018 temp_reg = inb(ioaddr + REG1); /* Setup Transmit Chaining */
1019 outb(temp_reg | XMT_Chain_Int | XMT_Chain_ErrStop /* and discard bad RCV frames */
1020 | RCV_Discard_BadFrame, ioaddr + REG1);
1021
1022 temp_reg = inb(ioaddr + REG2); /* Match broadcast */
1023 outb(temp_reg | 0x14, ioaddr + REG2);
1024
1025 temp_reg = inb(ioaddr + REG3);
1026 outb(temp_reg & 0x3f, ioaddr + REG3); /* clear test mode */
1027
1028 /* Set the receiving mode */
1029 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
1030
1031 /* Set the interrupt vector */
1032 temp_reg = inb(ioaddr + INT_NO_REG);
1033 if (lp->eepro == LAN595FX || lp->eepro == LAN595FX_10ISA)
1034 outb((temp_reg & 0xf8) | irqrmap2[dev->irq], ioaddr + INT_NO_REG);
1035 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
1036
1037
1038 temp_reg = inb(ioaddr + INT_NO_REG);
1039 if (lp->eepro == LAN595FX || lp->eepro == LAN595FX_10ISA)
1040 outb((temp_reg & 0xf0) | irqrmap2[dev->irq] | 0x08,ioaddr+INT_NO_REG);
1041 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
1042
1043 if (net_debug > 3)
1044 printk(KERN_DEBUG "eepro_open: content of INT Reg is %x\n", temp_reg);
1045
1046
1047 /* Initialize the RCV and XMT upper and lower limits */
1048 outb(lp->rcv_lower_limit >> 8, ioaddr + RCV_LOWER_LIMIT_REG);
1049 outb(lp->rcv_upper_limit >> 8, ioaddr + RCV_UPPER_LIMIT_REG);
1050 outb(lp->xmt_lower_limit >> 8, ioaddr + lp->xmt_lower_limit_reg);
1051 outb(lp->xmt_upper_limit >> 8, ioaddr + lp->xmt_upper_limit_reg);
1052
1053 /* Enable the interrupt line. */
1054 eepro_en_intline(ioaddr);
1055
1056 /* Switch back to Bank 0 */
1057 eepro_sw2bank0(ioaddr);
1058
1059 /* Let RX and TX events to interrupt */
1060 eepro_en_int(ioaddr);
1061
1062 /* clear all interrupts */
1063 eepro_clear_int(ioaddr);
1064
1065 /* Initialize RCV */
1066 outw(lp->rcv_lower_limit, ioaddr + RCV_BAR);
1067 lp->rx_start = lp->rcv_lower_limit;
1068 outw(lp->rcv_upper_limit | 0xfe, ioaddr + RCV_STOP);
1069
1070 /* Initialize XMT */
1071 outw(lp->xmt_lower_limit, ioaddr + lp->xmt_bar);
1072 lp->tx_start = lp->tx_end = lp->xmt_lower_limit;
1073 lp->tx_last = 0;
1074
1075 /* Check for the i82595TX and i82595FX */
1076 old8 = inb(ioaddr + 8);
1077 outb(~old8, ioaddr + 8);
1078
1079 if ((temp_reg = inb(ioaddr + 8)) == old8) {
1080 if (net_debug > 3)
1081 printk(KERN_DEBUG "i82595 detected!\n");
1082 lp->version = LAN595;
1083 }
1084 else {
1085 lp->version = LAN595TX;
1086 outb(old8, ioaddr + 8);
1087 old9 = inb(ioaddr + 9);
1088
1089 if (irqMask==ee_FX_INT2IRQ) {
1090 if (net_debug > 3) {
1091 printk(KERN_DEBUG "IrqMask: %#x\n",irqMask);
1092 printk(KERN_DEBUG "i82595FX detected!\n");
1093 }
1094 lp->version = LAN595FX;
1095 outb(old9, ioaddr + 9);
1096 if (dev->if_port != TPE) { /* Hopefully, this will fix the
1097 problem of using Pentiums and
1098 pro/10 w/ BNC. */
1099 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1100 temp_reg = inb(ioaddr + REG13);
1101 /* disable the full duplex mode since it is not
1102 applicable with the 10Base2 cable. */
1103 outb(temp_reg & ~(FDX | A_N_ENABLE), REG13);
1104 eepro_sw2bank0(ioaddr); /* be CAREFUL, BANK 0 now */
1105 }
1106 }
1107 else if (net_debug > 3) {
1108 printk(KERN_DEBUG "temp_reg: %#x ~old9: %#x\n",temp_reg,((~old9)&0xff));
1109 printk(KERN_DEBUG "i82595TX detected!\n");
1110 }
1111 }
1112
1113 eepro_sel_reset(ioaddr);
1114
1115 netif_start_queue(dev);
1116
1117 if (net_debug > 3)
1118 printk(KERN_DEBUG "%s: exiting eepro_open routine.\n", dev->name);
1119
1120 /* enabling rx */
1121 eepro_en_rx(ioaddr);
1122
1123 return 0;
1124}
1125
1126static void eepro_tx_timeout (struct net_device *dev)
1127{
1128 struct eepro_local *lp = netdev_priv(dev);
1129 int ioaddr = dev->base_addr;
1130
1131 /* if (net_debug > 1) */
1132 printk (KERN_ERR "%s: transmit timed out, %s?\n", dev->name,
1133 "network cable problem");
1134 /* This is not a duplicate. One message for the console,
1135 one for the the log file */
1136 printk (KERN_DEBUG "%s: transmit timed out, %s?\n", dev->name,
1137 "network cable problem");
1138 eepro_complete_selreset(ioaddr);
1139}
1140
1141
1142static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev)
1143{
1144 struct eepro_local *lp = netdev_priv(dev);
1145 unsigned long flags;
1146 int ioaddr = dev->base_addr;
1147 short length = skb->len;
1148
1149 if (net_debug > 5)
1150 printk(KERN_DEBUG "%s: entering eepro_send_packet routine.\n", dev->name);
1151
1152 if (length < ETH_ZLEN) {
1153 skb = skb_padto(skb, ETH_ZLEN);
1154 if (skb == NULL)
1155 return 0;
1156 length = ETH_ZLEN;
1157 }
1158 netif_stop_queue (dev);
1159
1160 eepro_dis_int(ioaddr);
1161 spin_lock_irqsave(&lp->lock, flags);
1162
1163 {
1164 unsigned char *buf = skb->data;
1165
1166 if (hardware_send_packet(dev, buf, length))
1167 /* we won't wake queue here because we're out of space */
1168 lp->stats.tx_dropped++;
1169 else {
1170 lp->stats.tx_bytes+=skb->len;
1171 dev->trans_start = jiffies;
1172 netif_wake_queue(dev);
1173 }
1174
1175 }
1176
1177 dev_kfree_skb (skb);
1178
1179 /* You might need to clean up and record Tx statistics here. */
1180 /* lp->stats.tx_aborted_errors++; */
1181
1182 if (net_debug > 5)
1183 printk(KERN_DEBUG "%s: exiting eepro_send_packet routine.\n", dev->name);
1184
1185 eepro_en_int(ioaddr);
1186 spin_unlock_irqrestore(&lp->lock, flags);
1187
1188 return 0;
1189}
1190
1191
1192/* The typical workload of the driver:
1193 Handle the network interface interrupts. */
1194
1195static irqreturn_t
1196eepro_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1197{
1198 struct net_device *dev = (struct net_device *)dev_id;
1199 /* (struct net_device *)(irq2dev_map[irq]);*/
1200 struct eepro_local *lp;
1201 int ioaddr, status, boguscount = 20;
1202 int handled = 0;
1203
1204 if (dev == NULL) {
1205 printk (KERN_ERR "eepro_interrupt(): irq %d for unknown device.\\n", irq);
1206 return IRQ_NONE;
1207 }
1208
1209 lp = netdev_priv(dev);
1210
1211 spin_lock(&lp->lock);
1212
1213 if (net_debug > 5)
1214 printk(KERN_DEBUG "%s: entering eepro_interrupt routine.\n", dev->name);
1215
1216 ioaddr = dev->base_addr;
1217
1218 while (((status = inb(ioaddr + STATUS_REG)) & (RX_INT|TX_INT)) && (boguscount--))
1219 {
1220 handled = 1;
1221 if (status & RX_INT) {
1222 if (net_debug > 4)
1223 printk(KERN_DEBUG "%s: packet received interrupt.\n", dev->name);
1224
1225 eepro_dis_int(ioaddr);
1226
1227 /* Get the received packets */
1228 eepro_ack_rx(ioaddr);
1229 eepro_rx(dev);
1230
1231 eepro_en_int(ioaddr);
1232 }
1233 if (status & TX_INT) {
1234 if (net_debug > 4)
1235 printk(KERN_DEBUG "%s: packet transmit interrupt.\n", dev->name);
1236
1237
1238 eepro_dis_int(ioaddr);
1239
1240 /* Process the status of transmitted packets */
1241 eepro_ack_tx(ioaddr);
1242 eepro_transmit_interrupt(dev);
1243
1244 eepro_en_int(ioaddr);
1245 }
1246 }
1247
1248 if (net_debug > 5)
1249 printk(KERN_DEBUG "%s: exiting eepro_interrupt routine.\n", dev->name);
1250
1251 spin_unlock(&lp->lock);
1252 return IRQ_RETVAL(handled);
1253}
1254
1255static int eepro_close(struct net_device *dev)
1256{
1257 struct eepro_local *lp = netdev_priv(dev);
1258 int ioaddr = dev->base_addr;
1259 short temp_reg;
1260
1261 netif_stop_queue(dev);
1262
1263 eepro_sw2bank1(ioaddr); /* Switch back to Bank 1 */
1264
1265 /* Disable the physical interrupt line. */
1266 temp_reg = inb(ioaddr + REG1);
1267 outb(temp_reg & 0x7f, ioaddr + REG1);
1268
1269 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
1270
1271 /* Flush the Tx and disable Rx. */
1272 outb(STOP_RCV_CMD, ioaddr);
1273 lp->tx_start = lp->tx_end = lp->xmt_lower_limit;
1274 lp->tx_last = 0;
1275
1276 /* Mask all the interrupts. */
1277 eepro_dis_int(ioaddr);
1278
1279 /* clear all interrupts */
1280 eepro_clear_int(ioaddr);
1281
1282 /* Reset the 82595 */
1283 eepro_reset(ioaddr);
1284
1285 /* release the interrupt */
1286 free_irq(dev->irq, dev);
1287
1288#ifdef irq2dev_map
1289 irq2dev_map[dev->irq] = 0;
1290#endif
1291
1292 /* Update the statistics here. What statistics? */
1293
1294 return 0;
1295}
1296
1297/* Get the current statistics. This may be called with the card open or
1298 closed. */
1299static struct net_device_stats *
1300eepro_get_stats(struct net_device *dev)
1301{
1302 struct eepro_local *lp = netdev_priv(dev);
1303
1304 return &lp->stats;
1305}
1306
1307/* Set or clear the multicast filter for this adaptor.
1308 */
1309static void
1310set_multicast_list(struct net_device *dev)
1311{
1312 struct eepro_local *lp = netdev_priv(dev);
1313 short ioaddr = dev->base_addr;
1314 unsigned short mode;
1315 struct dev_mc_list *dmi=dev->mc_list;
1316
1317 if (dev->flags&(IFF_ALLMULTI|IFF_PROMISC) || dev->mc_count > 63)
1318 {
1319 /*
1320 * We must make the kernel realise we had to move
1321 * into promisc mode or we start all out war on
1322 * the cable. If it was a promisc request the
1323 * flag is already set. If not we assert it.
1324 */
1325 dev->flags|=IFF_PROMISC;
1326
1327 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1328 mode = inb(ioaddr + REG2);
1329 outb(mode | PRMSC_Mode, ioaddr + REG2);
1330 mode = inb(ioaddr + REG3);
1331 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1332 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1333 printk(KERN_INFO "%s: promiscuous mode enabled.\n", dev->name);
1334 }
1335
1336 else if (dev->mc_count==0 )
1337 {
1338 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1339 mode = inb(ioaddr + REG2);
1340 outb(mode & 0xd6, ioaddr + REG2); /* Turn off Multi-IA and PRMSC_Mode bits */
1341 mode = inb(ioaddr + REG3);
1342 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1343 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1344 }
1345
1346 else
1347 {
1348 unsigned short status, *eaddrs;
1349 int i, boguscount = 0;
1350
1351 /* Disable RX and TX interrupts. Necessary to avoid
1352 corruption of the HOST_ADDRESS_REG by interrupt
1353 service routines. */
1354 eepro_dis_int(ioaddr);
1355
1356 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1357 mode = inb(ioaddr + REG2);
1358 outb(mode | Multi_IA, ioaddr + REG2);
1359 mode = inb(ioaddr + REG3);
1360 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1361 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1362 outw(lp->tx_end, ioaddr + HOST_ADDRESS_REG);
1363 outw(MC_SETUP, ioaddr + IO_PORT);
1364 outw(0, ioaddr + IO_PORT);
1365 outw(0, ioaddr + IO_PORT);
1366 outw(6*(dev->mc_count + 1), ioaddr + IO_PORT);
1367
1368 for (i = 0; i < dev->mc_count; i++)
1369 {
1370 eaddrs=(unsigned short *)dmi->dmi_addr;
1371 dmi=dmi->next;
1372 outw(*eaddrs++, ioaddr + IO_PORT);
1373 outw(*eaddrs++, ioaddr + IO_PORT);
1374 outw(*eaddrs++, ioaddr + IO_PORT);
1375 }
1376
1377 eaddrs = (unsigned short *) dev->dev_addr;
1378 outw(eaddrs[0], ioaddr + IO_PORT);
1379 outw(eaddrs[1], ioaddr + IO_PORT);
1380 outw(eaddrs[2], ioaddr + IO_PORT);
1381 outw(lp->tx_end, ioaddr + lp->xmt_bar);
1382 outb(MC_SETUP, ioaddr);
1383
1384 /* Update the transmit queue */
1385 i = lp->tx_end + XMT_HEADER + 6*(dev->mc_count + 1);
1386
1387 if (lp->tx_start != lp->tx_end)
1388 {
1389 /* update the next address and the chain bit in the
1390 last packet */
1391 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1392 outw(i, ioaddr + IO_PORT);
1393 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1394 status = inw(ioaddr + IO_PORT);
1395 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1396 lp->tx_end = i ;
1397 }
1398 else {
1399 lp->tx_start = lp->tx_end = i ;
1400 }
1401
1402 /* Acknowledge that the MC setup is done */
1403 do { /* We should be doing this in the eepro_interrupt()! */
1404 SLOW_DOWN;
1405 SLOW_DOWN;
1406 if (inb(ioaddr + STATUS_REG) & 0x08)
1407 {
1408 i = inb(ioaddr);
1409 outb(0x08, ioaddr + STATUS_REG);
1410
1411 if (i & 0x20) { /* command ABORTed */
1412 printk(KERN_NOTICE "%s: multicast setup failed.\n",
1413 dev->name);
1414 break;
1415 } else if ((i & 0x0f) == 0x03) { /* MC-Done */
1416 printk(KERN_DEBUG "%s: set Rx mode to %d address%s.\n",
1417 dev->name, dev->mc_count,
1418 dev->mc_count > 1 ? "es":"");
1419 break;
1420 }
1421 }
1422 } while (++boguscount < 100);
1423
1424 /* Re-enable RX and TX interrupts */
1425 eepro_en_int(ioaddr);
1426 }
1427 if (lp->eepro == LAN595FX_10ISA) {
1428 eepro_complete_selreset(ioaddr);
1429 }
1430 else
1431 eepro_en_rx(ioaddr);
1432}
1433
1434/* The horrible routine to read a word from the serial EEPROM. */
1435/* IMPORTANT - the 82595 will be set to Bank 0 after the eeprom is read */
1436
1437/* The delay between EEPROM clock transitions. */
1438#define eeprom_delay() { udelay(40); }
1439#define EE_READ_CMD (6 << 6)
1440
1441int
1442read_eeprom(int ioaddr, int location, struct net_device *dev)
1443{
1444 int i;
1445 unsigned short retval = 0;
1446 struct eepro_local *lp = netdev_priv(dev);
1447 short ee_addr = ioaddr + lp->eeprom_reg;
1448 int read_cmd = location | EE_READ_CMD;
1449 short ctrl_val = EECS ;
1450
1451 /* XXXX - black magic */
1452 eepro_sw2bank1(ioaddr);
1453 outb(0x00, ioaddr + STATUS_REG);
1454 /* XXXX - black magic */
1455
1456 eepro_sw2bank2(ioaddr);
1457 outb(ctrl_val, ee_addr);
1458
1459 /* Shift the read command bits out. */
1460 for (i = 8; i >= 0; i--) {
1461 short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI
1462 : ctrl_val;
1463 outb(outval, ee_addr);
1464 outb(outval | EESK, ee_addr); /* EEPROM clock tick. */
1465 eeprom_delay();
1466 outb(outval, ee_addr); /* Finish EEPROM a clock tick. */
1467 eeprom_delay();
1468 }
1469 outb(ctrl_val, ee_addr);
1470
1471 for (i = 16; i > 0; i--) {
1472 outb(ctrl_val | EESK, ee_addr); eeprom_delay();
1473 retval = (retval << 1) | ((inb(ee_addr) & EEDO) ? 1 : 0);
1474 outb(ctrl_val, ee_addr); eeprom_delay();
1475 }
1476
1477 /* Terminate the EEPROM access. */
1478 ctrl_val &= ~EECS;
1479 outb(ctrl_val | EESK, ee_addr);
1480 eeprom_delay();
1481 outb(ctrl_val, ee_addr);
1482 eeprom_delay();
1483 eepro_sw2bank0(ioaddr);
1484 return retval;
1485}
1486
1487static int
1488hardware_send_packet(struct net_device *dev, void *buf, short length)
1489{
1490 struct eepro_local *lp = netdev_priv(dev);
1491 short ioaddr = dev->base_addr;
1492 unsigned status, tx_available, last, end;
1493
1494 if (net_debug > 5)
1495 printk(KERN_DEBUG "%s: entering hardware_send_packet routine.\n", dev->name);
1496
1497 /* determine how much of the transmit buffer space is available */
1498 if (lp->tx_end > lp->tx_start)
1499 tx_available = lp->xmt_ram - (lp->tx_end - lp->tx_start);
1500 else if (lp->tx_end < lp->tx_start)
1501 tx_available = lp->tx_start - lp->tx_end;
1502 else tx_available = lp->xmt_ram;
1503
1504 if (((((length + 3) >> 1) << 1) + 2*XMT_HEADER) >= tx_available) {
1505 /* No space available ??? */
1506 return 1;
1507 }
1508
1509 last = lp->tx_end;
1510 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1511
1512 if (end >= lp->xmt_upper_limit + 2) { /* the transmit buffer is wrapped around */
1513 if ((lp->xmt_upper_limit + 2 - last) <= XMT_HEADER) {
1514 /* Arrrr!!!, must keep the xmt header together,
1515 several days were lost to chase this one down. */
1516 last = lp->xmt_lower_limit;
1517 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1518 }
1519 else end = lp->xmt_lower_limit + (end -
1520 lp->xmt_upper_limit + 2);
1521 }
1522
1523 outw(last, ioaddr + HOST_ADDRESS_REG);
1524 outw(XMT_CMD, ioaddr + IO_PORT);
1525 outw(0, ioaddr + IO_PORT);
1526 outw(end, ioaddr + IO_PORT);
1527 outw(length, ioaddr + IO_PORT);
1528
1529 if (lp->version == LAN595)
1530 outsw(ioaddr + IO_PORT, buf, (length + 3) >> 1);
1531 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1532 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1533 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1534 outsl(ioaddr + IO_PORT_32_BIT, buf, (length + 3) >> 2);
1535 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1536 }
1537
1538 /* A dummy read to flush the DRAM write pipeline */
1539 status = inw(ioaddr + IO_PORT);
1540
1541 if (lp->tx_start == lp->tx_end) {
1542 outw(last, ioaddr + lp->xmt_bar);
1543 outb(XMT_CMD, ioaddr);
1544 lp->tx_start = last; /* I don't like to change tx_start here */
1545 }
1546 else {
1547 /* update the next address and the chain bit in the
1548 last packet */
1549
1550 if (lp->tx_end != last) {
1551 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1552 outw(last, ioaddr + IO_PORT);
1553 }
1554
1555 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1556 status = inw(ioaddr + IO_PORT);
1557 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1558
1559 /* Continue the transmit command */
1560 outb(RESUME_XMT_CMD, ioaddr);
1561 }
1562
1563 lp->tx_last = last;
1564 lp->tx_end = end;
1565
1566 if (net_debug > 5)
1567 printk(KERN_DEBUG "%s: exiting hardware_send_packet routine.\n", dev->name);
1568
1569 return 0;
1570}
1571
1572static void
1573eepro_rx(struct net_device *dev)
1574{
1575 struct eepro_local *lp = netdev_priv(dev);
1576 short ioaddr = dev->base_addr;
1577 short boguscount = 20;
1578 short rcv_car = lp->rx_start;
1579 unsigned rcv_event, rcv_status, rcv_next_frame, rcv_size;
1580
1581 if (net_debug > 5)
1582 printk(KERN_DEBUG "%s: entering eepro_rx routine.\n", dev->name);
1583
1584 /* Set the read pointer to the start of the RCV */
1585 outw(rcv_car, ioaddr + HOST_ADDRESS_REG);
1586
1587 rcv_event = inw(ioaddr + IO_PORT);
1588
1589 while (rcv_event == RCV_DONE) {
1590
1591 rcv_status = inw(ioaddr + IO_PORT);
1592 rcv_next_frame = inw(ioaddr + IO_PORT);
1593 rcv_size = inw(ioaddr + IO_PORT);
1594
1595 if ((rcv_status & (RX_OK | RX_ERROR)) == RX_OK) {
1596
1597 /* Malloc up new buffer. */
1598 struct sk_buff *skb;
1599
1600 lp->stats.rx_bytes+=rcv_size;
1601 rcv_size &= 0x3fff;
1602 skb = dev_alloc_skb(rcv_size+5);
1603 if (skb == NULL) {
1604 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
1605 lp->stats.rx_dropped++;
1606 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1607 lp->rx_start = rcv_next_frame;
1608 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1609
1610 break;
1611 }
1612 skb->dev = dev;
1613 skb_reserve(skb,2);
1614
1615 if (lp->version == LAN595)
1616 insw(ioaddr+IO_PORT, skb_put(skb,rcv_size), (rcv_size + 3) >> 1);
1617 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1618 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1619 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1620 insl(ioaddr+IO_PORT_32_BIT, skb_put(skb,rcv_size),
1621 (rcv_size + 3) >> 2);
1622 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1623 }
1624
1625 skb->protocol = eth_type_trans(skb,dev);
1626 netif_rx(skb);
1627 dev->last_rx = jiffies;
1628 lp->stats.rx_packets++;
1629 }
1630
1631 else { /* Not sure will ever reach here,
1632 I set the 595 to discard bad received frames */
1633 lp->stats.rx_errors++;
1634
1635 if (rcv_status & 0x0100)
1636 lp->stats.rx_over_errors++;
1637
1638 else if (rcv_status & 0x0400)
1639 lp->stats.rx_frame_errors++;
1640
1641 else if (rcv_status & 0x0800)
1642 lp->stats.rx_crc_errors++;
1643
1644 printk(KERN_DEBUG "%s: event = %#x, status = %#x, next = %#x, size = %#x\n",
1645 dev->name, rcv_event, rcv_status, rcv_next_frame, rcv_size);
1646 }
1647
1648 if (rcv_status & 0x1000)
1649 lp->stats.rx_length_errors++;
1650
1651 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1652 lp->rx_start = rcv_next_frame;
1653
1654 if (--boguscount == 0)
1655 break;
1656
1657 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1658 rcv_event = inw(ioaddr + IO_PORT);
1659
1660 }
1661 if (rcv_car == 0)
1662 rcv_car = lp->rcv_upper_limit | 0xff;
1663
1664 outw(rcv_car - 1, ioaddr + RCV_STOP);
1665
1666 if (net_debug > 5)
1667 printk(KERN_DEBUG "%s: exiting eepro_rx routine.\n", dev->name);
1668}
1669
1670static void
1671eepro_transmit_interrupt(struct net_device *dev)
1672{
1673 struct eepro_local *lp = netdev_priv(dev);
1674 short ioaddr = dev->base_addr;
1675 short boguscount = 25;
1676 short xmt_status;
1677
1678 while ((lp->tx_start != lp->tx_end) && boguscount--) {
1679
1680 outw(lp->tx_start, ioaddr + HOST_ADDRESS_REG);
1681 xmt_status = inw(ioaddr+IO_PORT);
1682
1683 if (!(xmt_status & TX_DONE_BIT))
1684 break;
1685
1686 xmt_status = inw(ioaddr+IO_PORT);
1687 lp->tx_start = inw(ioaddr+IO_PORT);
1688
1689 netif_wake_queue (dev);
1690
1691 if (xmt_status & TX_OK)
1692 lp->stats.tx_packets++;
1693 else {
1694 lp->stats.tx_errors++;
1695 if (xmt_status & 0x0400) {
1696 lp->stats.tx_carrier_errors++;
1697 printk(KERN_DEBUG "%s: carrier error\n",
1698 dev->name);
1699 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1700 dev->name, xmt_status);
1701 }
1702 else {
1703 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1704 dev->name, xmt_status);
1705 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1706 dev->name, xmt_status);
1707 }
1708 }
1709 if (xmt_status & 0x000f) {
1710 lp->stats.collisions += (xmt_status & 0x000f);
1711 }
1712
1713 if ((xmt_status & 0x0040) == 0x0) {
1714 lp->stats.tx_heartbeat_errors++;
1715 }
1716 }
1717}
1718
1719static int eepro_ethtool_get_settings(struct net_device *dev,
1720 struct ethtool_cmd *cmd)
1721{
1722 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1723
1724 cmd->supported = SUPPORTED_10baseT_Half |
1725 SUPPORTED_10baseT_Full |
1726 SUPPORTED_Autoneg;
1727 cmd->advertising = ADVERTISED_10baseT_Half |
1728 ADVERTISED_10baseT_Full |
1729 ADVERTISED_Autoneg;
1730
1731 if (GetBit(lp->word[5], ee_PortTPE)) {
1732 cmd->supported |= SUPPORTED_TP;
1733 cmd->advertising |= ADVERTISED_TP;
1734 }
1735 if (GetBit(lp->word[5], ee_PortBNC)) {
1736 cmd->supported |= SUPPORTED_BNC;
1737 cmd->advertising |= ADVERTISED_BNC;
1738 }
1739 if (GetBit(lp->word[5], ee_PortAUI)) {
1740 cmd->supported |= SUPPORTED_AUI;
1741 cmd->advertising |= ADVERTISED_AUI;
1742 }
1743
1744 cmd->speed = SPEED_10;
1745
1746 if (dev->if_port == TPE && lp->word[1] & ee_Duplex) {
1747 cmd->duplex = DUPLEX_FULL;
1748 }
1749 else {
1750 cmd->duplex = DUPLEX_HALF;
1751 }
1752
1753 cmd->port = dev->if_port;
1754 cmd->phy_address = dev->base_addr;
1755 cmd->transceiver = XCVR_INTERNAL;
1756
1757 if (lp->word[0] & ee_AutoNeg) {
1758 cmd->autoneg = 1;
1759 }
1760
1761 return 0;
1762}
1763
1764static void eepro_ethtool_get_drvinfo(struct net_device *dev,
1765 struct ethtool_drvinfo *drvinfo)
1766{
1767 strcpy(drvinfo->driver, DRV_NAME);
1768 strcpy(drvinfo->version, DRV_VERSION);
1769 sprintf(drvinfo->bus_info, "ISA 0x%lx", dev->base_addr);
1770}
1771
1772static struct ethtool_ops eepro_ethtool_ops = {
1773 .get_settings = eepro_ethtool_get_settings,
1774 .get_drvinfo = eepro_ethtool_get_drvinfo,
1775};
1776
1777#ifdef MODULE
1778
1779#define MAX_EEPRO 8
1780static struct net_device *dev_eepro[MAX_EEPRO];
1781
1782static int io[MAX_EEPRO] = {
1783 [0 ... MAX_EEPRO-1] = -1
1784};
1785static int irq[MAX_EEPRO];
1786static int mem[MAX_EEPRO] = { /* Size of the rx buffer in KB */
1787 [0 ... MAX_EEPRO-1] = RCV_DEFAULT_RAM/1024
1788};
1789static int autodetect;
1790
1791static int n_eepro;
1792/* For linux 2.1.xx */
1793
1794MODULE_AUTHOR("Pascal Dupuis and others");
1795MODULE_DESCRIPTION("Intel i82595 ISA EtherExpressPro10/10+ driver");
1796MODULE_LICENSE("GPL");
1797
1798static int num_params;
1799module_param_array(io, int, &num_params, 0);
1800module_param_array(irq, int, &num_params, 0);
1801module_param_array(mem, int, &num_params, 0);
1802module_param(autodetect, int, 0);
1803MODULE_PARM_DESC(io, "EtherExpress Pro/10 I/O base addres(es)");
1804MODULE_PARM_DESC(irq, "EtherExpress Pro/10 IRQ number(s)");
1805MODULE_PARM_DESC(mem, "EtherExpress Pro/10 Rx buffer size(es) in kB (3-29)");
1806MODULE_PARM_DESC(autodetect, "EtherExpress Pro/10 force board(s) detection (0-1)");
1807
1808int
1809init_module(void)
1810{
1811 struct net_device *dev;
1812 int i;
1813 if (io[0] == -1 && autodetect == 0) {
1814 printk(KERN_WARNING "eepro_init_module: Probe is very dangerous in ISA boards!\n");
1815 printk(KERN_WARNING "eepro_init_module: Please add \"autodetect=1\" to force probe\n");
1816 return -ENODEV;
1817 }
1818 else if (autodetect) {
1819 /* if autodetect is set then we must force detection */
1820 for (i = 0; i < MAX_EEPRO; i++) {
1821 io[i] = 0;
1822 }
1823
1824 printk(KERN_INFO "eepro_init_module: Auto-detecting boards (May God protect us...)\n");
1825 }
1826
1827 for (i = 0; io[i] != -1 && i < MAX_EEPRO; i++) {
1828 dev = alloc_etherdev(sizeof(struct eepro_local));
1829 if (!dev)
1830 break;
1831
1832 dev->mem_end = mem[i];
1833 dev->base_addr = io[i];
1834 dev->irq = irq[i];
1835
1836 if (do_eepro_probe(dev) == 0) {
1837 if (register_netdev(dev) == 0) {
1838 dev_eepro[n_eepro++] = dev;
1839 continue;
1840 }
1841 release_region(dev->base_addr, EEPRO_IO_EXTENT);
1842 }
1843 free_netdev(dev);
1844 break;
1845 }
1846
1847 if (n_eepro)
1848 printk(KERN_INFO "%s", version);
1849
1850 return n_eepro ? 0 : -ENODEV;
1851}
1852
1853void
1854cleanup_module(void)
1855{
1856 int i;
1857
1858 for (i=0; i<n_eepro; i++) {
1859 struct net_device *dev = dev_eepro[i];
1860 unregister_netdev(dev);
1861 release_region(dev->base_addr, EEPRO_IO_EXTENT);
1862 free_netdev(dev);
1863 }
1864}
1865#endif /* MODULE */