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