blob: 8d97f168f018734bcaeb1af1372b77ba9fca2eef [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#include <linux/string.h>
141#include <linux/errno.h>
142#include <linux/netdevice.h>
143#include <linux/etherdevice.h>
144#include <linux/skbuff.h>
145#include <linux/spinlock.h>
146#include <linux/init.h>
147#include <linux/delay.h>
148#include <linux/bitops.h>
149#include <linux/ethtool.h>
150
151#include <asm/system.h>
152#include <asm/io.h>
153#include <asm/dma.h>
154
155#define DRV_NAME "eepro"
Andy Gospodarekd5b20692006-09-11 17:39:18 -0400156#define DRV_VERSION "0.13c"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158#define compat_dev_kfree_skb( skb, mode ) dev_kfree_skb( (skb) )
159/* I had reports of looong delays with SLOW_DOWN defined as udelay(2) */
160#define SLOW_DOWN inb(0x80)
161/* udelay(2) */
162#define compat_init_data __initdata
163enum iftype { AUI=0, BNC=1, TPE=2 };
164
165/* First, a few definitions that the brave might change. */
166/* A zero-terminated list of I/O addresses to be probed. */
167static unsigned int eepro_portlist[] compat_init_data =
168 { 0x300, 0x210, 0x240, 0x280, 0x2C0, 0x200, 0x320, 0x340, 0x360, 0};
169/* note: 0x300 is default, the 595FX supports ALL IO Ports
170 from 0x000 to 0x3F0, some of which are reserved in PCs */
171
172/* To try the (not-really PnP Wakeup: */
173/*
174#define PnPWakeup
175*/
176
177/* use 0 for production, 1 for verification, >2 for debug */
178#ifndef NET_DEBUG
179#define NET_DEBUG 0
180#endif
181static unsigned int net_debug = NET_DEBUG;
182
183/* The number of low I/O ports used by the ethercard. */
184#define EEPRO_IO_EXTENT 16
185
186/* Different 82595 chips */
187#define LAN595 0
188#define LAN595TX 1
189#define LAN595FX 2
190#define LAN595FX_10ISA 3
191
192/* Information that need to be kept for each board. */
193struct eepro_local {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 unsigned rx_start;
195 unsigned tx_start; /* start of the transmit chain */
196 int tx_last; /* pointer to last packet in the transmit chain */
197 unsigned tx_end; /* end of the transmit chain (plus 1) */
198 int eepro; /* 1 for the EtherExpress Pro/10,
199 2 for the EtherExpress Pro/10+,
200 3 for the EtherExpress 10 (blue cards),
201 0 for other 82595-based lan cards. */
202 int version; /* a flag to indicate if this is a TX or FX
203 version of the 82595 chip. */
204 int stepping;
205
206 spinlock_t lock; /* Serializing lock */
207
208 unsigned rcv_ram; /* pre-calculated space for rx */
209 unsigned xmt_ram; /* pre-calculated space for tx */
210 unsigned char xmt_bar;
211 unsigned char xmt_lower_limit_reg;
212 unsigned char xmt_upper_limit_reg;
213 short xmt_lower_limit;
214 short xmt_upper_limit;
215 short rcv_lower_limit;
216 short rcv_upper_limit;
217 unsigned char eeprom_reg;
218 unsigned short word[8];
219};
220
221/* The station (ethernet) address prefix, used for IDing the board. */
222#define SA_ADDR0 0x00 /* Etherexpress Pro/10 */
223#define SA_ADDR1 0xaa
224#define SA_ADDR2 0x00
225
226#define GetBit(x,y) ((x & (1<<y))>>y)
227
228/* EEPROM Word 0: */
229#define ee_PnP 0 /* Plug 'n Play enable bit */
230#define ee_Word1 1 /* Word 1? */
231#define ee_BusWidth 2 /* 8/16 bit */
232#define ee_FlashAddr 3 /* Flash Address */
233#define ee_FlashMask 0x7 /* Mask */
234#define ee_AutoIO 6 /* */
235#define ee_reserved0 7 /* =0! */
236#define ee_Flash 8 /* Flash there? */
237#define ee_AutoNeg 9 /* Auto Negotiation enabled? */
238#define ee_IO0 10 /* IO Address LSB */
239#define ee_IO0Mask 0x /*...*/
240#define ee_IO1 15 /* IO MSB */
241
242/* EEPROM Word 1: */
243#define ee_IntSel 0 /* Interrupt */
244#define ee_IntMask 0x7
245#define ee_LI 3 /* Link Integrity 0= enabled */
246#define ee_PC 4 /* Polarity Correction 0= enabled */
247#define ee_TPE_AUI 5 /* PortSelection 1=TPE */
248#define ee_Jabber 6 /* Jabber prevention 0= enabled */
249#define ee_AutoPort 7 /* Auto Port Selection 1= Disabled */
250#define ee_SMOUT 8 /* SMout Pin Control 0= Input */
251#define ee_PROM 9 /* Flash EPROM / PROM 0=Flash */
252#define ee_reserved1 10 /* .. 12 =0! */
253#define ee_AltReady 13 /* Alternate Ready, 0=normal */
254#define ee_reserved2 14 /* =0! */
255#define ee_Duplex 15
256
257/* Word2,3,4: */
258#define ee_IA5 0 /*bit start for individual Addr Byte 5 */
259#define ee_IA4 8 /*bit start for individual Addr Byte 5 */
260#define ee_IA3 0 /*bit start for individual Addr Byte 5 */
261#define ee_IA2 8 /*bit start for individual Addr Byte 5 */
262#define ee_IA1 0 /*bit start for individual Addr Byte 5 */
263#define ee_IA0 8 /*bit start for individual Addr Byte 5 */
264
265/* Word 5: */
266#define ee_BNC_TPE 0 /* 0=TPE */
267#define ee_BootType 1 /* 00=None, 01=IPX, 10=ODI, 11=NDIS */
268#define ee_BootTypeMask 0x3
269#define ee_NumConn 3 /* Number of Connections 0= One or Two */
270#define ee_FlashSock 4 /* Presence of Flash Socket 0= Present */
271#define ee_PortTPE 5
272#define ee_PortBNC 6
273#define ee_PortAUI 7
274#define ee_PowerMgt 10 /* 0= disabled */
275#define ee_CP 13 /* Concurrent Processing */
276#define ee_CPMask 0x7
277
278/* Word 6: */
279#define ee_Stepping 0 /* Stepping info */
280#define ee_StepMask 0x0F
281#define ee_BoardID 4 /* Manucaturer Board ID, reserved */
282#define ee_BoardMask 0x0FFF
283
284/* Word 7: */
285#define ee_INT_TO_IRQ 0 /* int to IRQ Mapping = 0x1EB8 for Pro/10+ */
286#define ee_FX_INT2IRQ 0x1EB8 /* the _only_ mapping allowed for FX chips */
287
288/*..*/
289#define ee_SIZE 0x40 /* total EEprom Size */
290#define ee_Checksum 0xBABA /* initial and final value for adding checksum */
291
292
293/* Card identification via EEprom: */
294#define ee_addr_vendor 0x10 /* Word offset for EISA Vendor ID */
295#define ee_addr_id 0x11 /* Word offset for Card ID */
296#define ee_addr_SN 0x12 /* Serial Number */
297#define ee_addr_CRC_8 0x14 /* CRC over last thee Bytes */
298
299
300#define ee_vendor_intel0 0x25 /* Vendor ID Intel */
301#define ee_vendor_intel1 0xD4
302#define ee_id_eepro10p0 0x10 /* ID for eepro/10+ */
303#define ee_id_eepro10p1 0x31
304
305#define TX_TIMEOUT 40
306
307/* Index to functions, as function prototypes. */
308
309static int eepro_probe1(struct net_device *dev, int autoprobe);
310static int eepro_open(struct net_device *dev);
Stephen Hemminger613573252009-08-31 19:50:58 +0000311static netdev_tx_t eepro_send_packet(struct sk_buff *skb,
312 struct net_device *dev);
David Howells7d12e782006-10-05 14:55:46 +0100313static irqreturn_t eepro_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314static void eepro_rx(struct net_device *dev);
315static void eepro_transmit_interrupt(struct net_device *dev);
316static int eepro_close(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317static 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) { \
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700515 dev->stats.tx_errors++;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 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 */
532static int __init do_eepro_probe(struct net_device *dev)
533{
534 int i;
535 int base_addr = dev->base_addr;
536 int irq = dev->irq;
537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538#ifdef PnPWakeup
539 /* XXXX for multiple cards should this only be run once? */
540
541 /* Wakeup: */
542 #define WakeupPort 0x279
543 #define WakeupSeq {0x6A, 0xB5, 0xDA, 0xED, 0xF6, 0xFB, 0x7D, 0xBE,\
544 0xDF, 0x6F, 0x37, 0x1B, 0x0D, 0x86, 0xC3, 0x61,\
545 0xB0, 0x58, 0x2C, 0x16, 0x8B, 0x45, 0xA2, 0xD1,\
546 0xE8, 0x74, 0x3A, 0x9D, 0xCE, 0xE7, 0x73, 0x43}
547
548 {
549 unsigned short int WS[32]=WakeupSeq;
550
Jeff Garzikd61780c2005-10-30 15:01:51 -0800551 if (request_region(WakeupPort, 2, "eepro wakeup")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (net_debug>5)
553 printk(KERN_DEBUG "Waking UP\n");
554
555 outb_p(0,WakeupPort);
556 outb_p(0,WakeupPort);
557 for (i=0; i<32; i++) {
558 outb_p(WS[i],WakeupPort);
559 if (net_debug>5) printk(KERN_DEBUG ": %#x ",WS[i]);
560 }
Jeff Garzikd61780c2005-10-30 15:01:51 -0800561
562 release_region(WakeupPort, 2);
563 } else
564 printk(KERN_WARNING "PnP wakeup region busy!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 }
566#endif
567
568 if (base_addr > 0x1ff) /* Check a single specified location. */
569 return eepro_probe1(dev, 0);
570
571 else if (base_addr != 0) /* Don't probe at all. */
572 return -ENXIO;
573
574 for (i = 0; eepro_portlist[i]; i++) {
575 dev->base_addr = eepro_portlist[i];
576 dev->irq = irq;
577 if (eepro_probe1(dev, 1) == 0)
578 return 0;
579 }
580
581 return -ENODEV;
582}
583
584#ifndef MODULE
585struct net_device * __init eepro_probe(int unit)
586{
587 struct net_device *dev = alloc_etherdev(sizeof(struct eepro_local));
588 int err;
589
590 if (!dev)
591 return ERR_PTR(-ENODEV);
592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 sprintf(dev->name, "eth%d", unit);
594 netdev_boot_setup_check(dev);
595
596 err = do_eepro_probe(dev);
597 if (err)
598 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 return dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600out:
601 free_netdev(dev);
602 return ERR_PTR(err);
603}
604#endif
605
606static void __init printEEPROMInfo(struct net_device *dev)
607{
Wang Chen4cf16532008-11-12 23:38:14 -0800608 struct eepro_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 int ioaddr = dev->base_addr;
610 unsigned short Word;
611 int i,j;
612
613 j = ee_Checksum;
614 for (i = 0; i < 8; i++)
615 j += lp->word[i];
616 for ( ; i < ee_SIZE; i++)
617 j += read_eeprom(ioaddr, i, dev);
618
619 printk(KERN_DEBUG "Checksum: %#x\n",j&0xffff);
620
621 Word = lp->word[0];
622 printk(KERN_DEBUG "Word0:\n");
623 printk(KERN_DEBUG " Plug 'n Pray: %d\n",GetBit(Word,ee_PnP));
624 printk(KERN_DEBUG " Buswidth: %d\n",(GetBit(Word,ee_BusWidth)+1)*8 );
625 printk(KERN_DEBUG " AutoNegotiation: %d\n",GetBit(Word,ee_AutoNeg));
626 printk(KERN_DEBUG " IO Address: %#x\n", (Word>>ee_IO0)<<4);
627
628 if (net_debug>4) {
629 Word = lp->word[1];
630 printk(KERN_DEBUG "Word1:\n");
631 printk(KERN_DEBUG " INT: %d\n", Word & ee_IntMask);
632 printk(KERN_DEBUG " LI: %d\n", GetBit(Word,ee_LI));
633 printk(KERN_DEBUG " PC: %d\n", GetBit(Word,ee_PC));
634 printk(KERN_DEBUG " TPE/AUI: %d\n", GetBit(Word,ee_TPE_AUI));
635 printk(KERN_DEBUG " Jabber: %d\n", GetBit(Word,ee_Jabber));
Harvey Harrison4e5b8642008-04-26 23:44:03 -0700636 printk(KERN_DEBUG " AutoPort: %d\n", !GetBit(Word,ee_AutoPort));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 printk(KERN_DEBUG " Duplex: %d\n", GetBit(Word,ee_Duplex));
638 }
639
640 Word = lp->word[5];
641 printk(KERN_DEBUG "Word5:\n");
642 printk(KERN_DEBUG " BNC: %d\n",GetBit(Word,ee_BNC_TPE));
643 printk(KERN_DEBUG " NumConnectors: %d\n",GetBit(Word,ee_NumConn));
644 printk(KERN_DEBUG " Has ");
645 if (GetBit(Word,ee_PortTPE)) printk(KERN_DEBUG "TPE ");
646 if (GetBit(Word,ee_PortBNC)) printk(KERN_DEBUG "BNC ");
647 if (GetBit(Word,ee_PortAUI)) printk(KERN_DEBUG "AUI ");
Frans Popd6dbee82010-03-24 07:57:35 +0000648 printk(KERN_DEBUG "port(s)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
650 Word = lp->word[6];
651 printk(KERN_DEBUG "Word6:\n");
652 printk(KERN_DEBUG " Stepping: %d\n",Word & ee_StepMask);
653 printk(KERN_DEBUG " BoardID: %d\n",Word>>ee_BoardID);
654
655 Word = lp->word[7];
656 printk(KERN_DEBUG "Word7:\n");
657 printk(KERN_DEBUG " INT to IRQ:\n");
658
659 for (i=0, j=0; i<15; i++)
660 if (GetBit(Word,i)) printk(KERN_DEBUG " INT%d -> IRQ %d;",j++,i);
661
662 printk(KERN_DEBUG "\n");
663}
664
665/* function to recalculate the limits of buffer based on rcv_ram */
666static void eepro_recalc (struct net_device *dev)
667{
668 struct eepro_local * lp;
669
670 lp = netdev_priv(dev);
671 lp->xmt_ram = RAM_SIZE - lp->rcv_ram;
672
673 if (lp->eepro == LAN595FX_10ISA) {
674 lp->xmt_lower_limit = XMT_START_10;
675 lp->xmt_upper_limit = (lp->xmt_ram - 2);
676 lp->rcv_lower_limit = lp->xmt_ram;
677 lp->rcv_upper_limit = (RAM_SIZE - 2);
678 }
679 else {
680 lp->rcv_lower_limit = RCV_START_PRO;
681 lp->rcv_upper_limit = (lp->rcv_ram - 2);
682 lp->xmt_lower_limit = lp->rcv_ram;
683 lp->xmt_upper_limit = (RAM_SIZE - 2);
684 }
685}
686
687/* prints boot-time info */
688static void __init eepro_print_info (struct net_device *dev)
689{
690 struct eepro_local * lp = netdev_priv(dev);
691 int i;
692 const char * ifmap[] = {"AUI", "10Base2", "10BaseT"};
693
694 i = inb(dev->base_addr + ID_REG);
695 printk(KERN_DEBUG " id: %#x ",i);
696 printk(" io: %#x ", (unsigned)dev->base_addr);
697
698 switch (lp->eepro) {
699 case LAN595FX_10ISA:
700 printk("%s: Intel EtherExpress 10 ISA\n at %#x,",
701 dev->name, (unsigned)dev->base_addr);
702 break;
703 case LAN595FX:
Jeff Garzikd61780c2005-10-30 15:01:51 -0800704 printk("%s: Intel EtherExpress Pro/10+ ISA\n at %#x,",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 dev->name, (unsigned)dev->base_addr);
706 break;
707 case LAN595TX:
708 printk("%s: Intel EtherExpress Pro/10 ISA at %#x,",
709 dev->name, (unsigned)dev->base_addr);
710 break;
711 case LAN595:
Jeff Garzikd61780c2005-10-30 15:01:51 -0800712 printk("%s: Intel 82595-based lan card at %#x,",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 dev->name, (unsigned)dev->base_addr);
Joe Perches0795af52007-10-03 17:59:30 -0700714 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 }
716
Johannes Berge1749612008-10-27 15:59:26 -0700717 printk(" %pM", dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
719 if (net_debug > 3)
720 printk(KERN_DEBUG ", %dK RCV buffer",
721 (int)(lp->rcv_ram)/1024);
722
723 if (dev->irq > 2)
724 printk(", IRQ %d, %s.\n", dev->irq, ifmap[dev->if_port]);
Jeff Garzikd61780c2005-10-30 15:01:51 -0800725 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 printk(", %s.\n", ifmap[dev->if_port]);
727
728 if (net_debug > 3) {
729 i = lp->word[5];
730 if (i & 0x2000) /* bit 13 of EEPROM word 5 */
731 printk(KERN_DEBUG "%s: Concurrent Processing is "
732 "enabled but not used!\n", dev->name);
733 }
734
735 /* Check the station address for the manufacturer's code */
736 if (net_debug>3)
737 printEEPROMInfo(dev);
738}
739
Jeff Garzik7282d492006-09-13 14:30:00 -0400740static const struct ethtool_ops eepro_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Stephen Hemminger8afb1ce2009-03-26 15:11:35 +0000742static const struct net_device_ops eepro_netdev_ops = {
743 .ndo_open = eepro_open,
744 .ndo_stop = eepro_close,
745 .ndo_start_xmit = eepro_send_packet,
746 .ndo_set_multicast_list = set_multicast_list,
747 .ndo_tx_timeout = eepro_tx_timeout,
748 .ndo_change_mtu = eth_change_mtu,
749 .ndo_set_mac_address = eth_mac_addr,
750 .ndo_validate_addr = eth_validate_addr,
751};
752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753/* This is the real probe routine. Linux has a history of friendly device
754 probes on the ISA bus. A good device probe avoids doing writes, and
755 verifies that the correct device exists and functions. */
756
757static int __init eepro_probe1(struct net_device *dev, int autoprobe)
758{
759 unsigned short station_addr[3], id, counter;
760 int i;
761 struct eepro_local *lp;
762 int ioaddr = dev->base_addr;
b1fc5502005-05-12 20:11:55 -0400763 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 /* Grab the region so we can find another board if autoIRQ fails. */
Jeff Garzikd61780c2005-10-30 15:01:51 -0800766 if (!request_region(ioaddr, EEPRO_IO_EXTENT, DRV_NAME)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 if (!autoprobe)
Frans Popd6dbee82010-03-24 07:57:35 +0000768 printk(KERN_WARNING "EEPRO: io-port 0x%04x in use\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 ioaddr);
770 return -EBUSY;
771 }
772
773 /* Now, we are going to check for the signature of the
774 ID_REG (register 2 of bank 0) */
775
776 id = inb(ioaddr + ID_REG);
777
778 if ((id & ID_REG_MASK) != ID_REG_SIG)
779 goto exit;
780
781 /* We seem to have the 82595 signature, let's
782 play with its counter (last 2 bits of
783 register 2 of bank 0) to be sure. */
784
785 counter = id & R_ROBIN_BITS;
786
787 if ((inb(ioaddr + ID_REG) & R_ROBIN_BITS) != (counter + 0x40))
788 goto exit;
789
790 lp = netdev_priv(dev);
791 memset(lp, 0, sizeof(struct eepro_local));
792 lp->xmt_bar = XMT_BAR_PRO;
793 lp->xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_PRO;
794 lp->xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_PRO;
795 lp->eeprom_reg = EEPROM_REG_PRO;
796 spin_lock_init(&lp->lock);
797
798 /* Now, get the ethernet hardware address from
799 the EEPROM */
800 station_addr[0] = read_eeprom(ioaddr, 2, dev);
801
802 /* FIXME - find another way to know that we've found
803 * an Etherexpress 10
804 */
805 if (station_addr[0] == 0x0000 || station_addr[0] == 0xffff) {
806 lp->eepro = LAN595FX_10ISA;
807 lp->eeprom_reg = EEPROM_REG_10;
808 lp->xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_10;
809 lp->xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_10;
810 lp->xmt_bar = XMT_BAR_10;
811 station_addr[0] = read_eeprom(ioaddr, 2, dev);
812 }
813
814 /* get all words at once. will be used here and for ethtool */
815 for (i = 0; i < 8; i++) {
816 lp->word[i] = read_eeprom(ioaddr, i, dev);
817 }
818 station_addr[1] = lp->word[3];
819 station_addr[2] = lp->word[4];
820
821 if (!lp->eepro) {
822 if (lp->word[7] == ee_FX_INT2IRQ)
823 lp->eepro = 2;
824 else if (station_addr[2] == SA_ADDR1)
825 lp->eepro = 1;
826 }
827
828 /* Fill in the 'dev' fields. */
829 for (i=0; i < 6; i++)
830 dev->dev_addr[i] = ((unsigned char *) station_addr)[5-i];
831
832 /* RX buffer must be more than 3K and less than 29K */
833 if (dev->mem_end < 3072 || dev->mem_end > 29696)
834 lp->rcv_ram = RCV_DEFAULT_RAM;
835
836 /* calculate {xmt,rcv}_{lower,upper}_limit */
837 eepro_recalc(dev);
838
839 if (GetBit(lp->word[5], ee_BNC_TPE))
840 dev->if_port = BNC;
841 else
842 dev->if_port = TPE;
843
844 if (dev->irq < 2 && lp->eepro != 0) {
845 /* Mask off INT number */
846 int count = lp->word[1] & 7;
847 unsigned irqMask = lp->word[7];
Jeff Garzikd61780c2005-10-30 15:01:51 -0800848
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 while (count--)
850 irqMask &= irqMask - 1;
Jeff Garzikd61780c2005-10-30 15:01:51 -0800851
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 count = ffs(irqMask);
Jeff Garzikd61780c2005-10-30 15:01:51 -0800853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 if (count)
855 dev->irq = count - 1;
Jeff Garzikd61780c2005-10-30 15:01:51 -0800856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 if (dev->irq < 2) {
858 printk(KERN_ERR " Duh! illegal interrupt vector stored in EEPROM.\n");
859 goto exit;
860 } else if (dev->irq == 2) {
861 dev->irq = 9;
862 }
863 }
Jeff Garzikd61780c2005-10-30 15:01:51 -0800864
Stephen Hemminger8afb1ce2009-03-26 15:11:35 +0000865 dev->netdev_ops = &eepro_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 dev->watchdog_timeo = TX_TIMEOUT;
867 dev->ethtool_ops = &eepro_ethtool_ops;
Jeff Garzikd61780c2005-10-30 15:01:51 -0800868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 /* print boot time info */
870 eepro_print_info(dev);
871
872 /* reset 82595 */
873 eepro_reset(ioaddr);
b1fc5502005-05-12 20:11:55 -0400874
875 err = register_netdev(dev);
876 if (err)
877 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 return 0;
879exit:
b1fc5502005-05-12 20:11:55 -0400880 err = -ENODEV;
881err:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 release_region(dev->base_addr, EEPRO_IO_EXTENT);
b1fc5502005-05-12 20:11:55 -0400883 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884}
885
886/* Open/initialize the board. This is called (in the current kernel)
887 sometime after booting when the 'ifconfig' program is run.
888
889 This routine should set everything up anew at each open, even
890 registers that "should" only need to be set once at boot, so that
891 there is non-reboot way to recover if something goes wrong.
892 */
893
894static char irqrmap[] = {-1,-1,0,1,-1,2,-1,-1,-1,0,3,4,-1,-1,-1,-1};
895static char irqrmap2[] = {-1,-1,4,0,1,2,-1,3,-1,4,5,6,7,-1,-1,-1};
896static int eepro_grab_irq(struct net_device *dev)
897{
898 int irqlist[] = { 3, 4, 5, 7, 9, 10, 11, 12, 0 };
899 int *irqp = irqlist, temp_reg, ioaddr = dev->base_addr;
900
901 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
902
903 /* Enable the interrupt line. */
904 eepro_en_intline(ioaddr);
905
906 /* be CAREFUL, BANK 0 now */
907 eepro_sw2bank0(ioaddr);
908
909 /* clear all interrupts */
910 eepro_clear_int(ioaddr);
911
912 /* Let EXEC event to interrupt */
913 eepro_en_intexec(ioaddr);
914
915 do {
916 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
917
918 temp_reg = inb(ioaddr + INT_NO_REG);
919 outb((temp_reg & 0xf8) | irqrmap[*irqp], ioaddr + INT_NO_REG);
920
921 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
922
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700923 if (request_irq (*irqp, NULL, IRQF_SHARED, "bogus", dev) != EBUSY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 unsigned long irq_mask;
925 /* Twinkle the interrupt, and check if it's seen */
926 irq_mask = probe_irq_on();
927
928 eepro_diag(ioaddr); /* RESET the 82595 */
929 mdelay(20);
930
931 if (*irqp == probe_irq_off(irq_mask)) /* It's a good IRQ line */
932 break;
933
934 /* clear all interrupts */
935 eepro_clear_int(ioaddr);
936 }
937 } while (*++irqp);
938
939 eepro_sw2bank1(ioaddr); /* Switch back to Bank 1 */
940
941 /* Disable the physical interrupt line. */
942 eepro_dis_intline(ioaddr);
943
944 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
945
946 /* Mask all the interrupts. */
947 eepro_dis_int(ioaddr);
948
949 /* clear all interrupts */
950 eepro_clear_int(ioaddr);
951
952 return dev->irq;
953}
954
955static int eepro_open(struct net_device *dev)
956{
957 unsigned short temp_reg, old8, old9;
958 int irqMask;
959 int i, ioaddr = dev->base_addr;
960 struct eepro_local *lp = netdev_priv(dev);
961
962 if (net_debug > 3)
963 printk(KERN_DEBUG "%s: entering eepro_open routine.\n", dev->name);
964
965 irqMask = lp->word[7];
966
967 if (lp->eepro == LAN595FX_10ISA) {
968 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 3;\n");
969 }
970 else if (irqMask == ee_FX_INT2IRQ) /* INT to IRQ Mask */
971 {
972 lp->eepro = 2; /* Yes, an Intel EtherExpress Pro/10+ */
973 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 2;\n");
974 }
975
976 else if ((dev->dev_addr[0] == SA_ADDR0 &&
977 dev->dev_addr[1] == SA_ADDR1 &&
978 dev->dev_addr[2] == SA_ADDR2))
979 {
980 lp->eepro = 1;
981 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 1;\n");
982 } /* Yes, an Intel EtherExpress Pro/10 */
983
984 else lp->eepro = 0; /* No, it is a generic 82585 lan card */
985
986 /* Get the interrupt vector for the 82595 */
987 if (dev->irq < 2 && eepro_grab_irq(dev) == 0) {
988 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
989 return -EAGAIN;
990 }
991
Joe Perchesa0607fd2009-11-18 23:29:17 -0800992 if (request_irq(dev->irq , eepro_interrupt, 0, dev->name, dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
994 return -EAGAIN;
995 }
996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 /* Initialize the 82595. */
998
999 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1000 temp_reg = inb(ioaddr + lp->eeprom_reg);
1001
1002 lp->stepping = temp_reg >> 5; /* Get the stepping number of the 595 */
1003
1004 if (net_debug > 3)
1005 printk(KERN_DEBUG "The stepping of the 82595 is %d\n", lp->stepping);
1006
1007 if (temp_reg & 0x10) /* Check the TurnOff Enable bit */
1008 outb(temp_reg & 0xef, ioaddr + lp->eeprom_reg);
1009 for (i=0; i < 6; i++)
1010 outb(dev->dev_addr[i] , ioaddr + I_ADD_REG0 + i);
1011
1012 temp_reg = inb(ioaddr + REG1); /* Setup Transmit Chaining */
1013 outb(temp_reg | XMT_Chain_Int | XMT_Chain_ErrStop /* and discard bad RCV frames */
1014 | RCV_Discard_BadFrame, ioaddr + REG1);
1015
1016 temp_reg = inb(ioaddr + REG2); /* Match broadcast */
1017 outb(temp_reg | 0x14, ioaddr + REG2);
1018
1019 temp_reg = inb(ioaddr + REG3);
1020 outb(temp_reg & 0x3f, ioaddr + REG3); /* clear test mode */
1021
1022 /* Set the receiving mode */
1023 eepro_sw2bank1(ioaddr); /* be CAREFUL, BANK 1 now */
1024
1025 /* Set the interrupt vector */
1026 temp_reg = inb(ioaddr + INT_NO_REG);
1027 if (lp->eepro == LAN595FX || lp->eepro == LAN595FX_10ISA)
1028 outb((temp_reg & 0xf8) | irqrmap2[dev->irq], ioaddr + INT_NO_REG);
1029 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
1030
1031
1032 temp_reg = inb(ioaddr + INT_NO_REG);
1033 if (lp->eepro == LAN595FX || lp->eepro == LAN595FX_10ISA)
1034 outb((temp_reg & 0xf0) | irqrmap2[dev->irq] | 0x08,ioaddr+INT_NO_REG);
1035 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
1036
1037 if (net_debug > 3)
1038 printk(KERN_DEBUG "eepro_open: content of INT Reg is %x\n", temp_reg);
1039
1040
1041 /* Initialize the RCV and XMT upper and lower limits */
Jeff Garzikd61780c2005-10-30 15:01:51 -08001042 outb(lp->rcv_lower_limit >> 8, ioaddr + RCV_LOWER_LIMIT_REG);
1043 outb(lp->rcv_upper_limit >> 8, ioaddr + RCV_UPPER_LIMIT_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 outb(lp->xmt_lower_limit >> 8, ioaddr + lp->xmt_lower_limit_reg);
1045 outb(lp->xmt_upper_limit >> 8, ioaddr + lp->xmt_upper_limit_reg);
1046
1047 /* Enable the interrupt line. */
1048 eepro_en_intline(ioaddr);
1049
1050 /* Switch back to Bank 0 */
1051 eepro_sw2bank0(ioaddr);
1052
1053 /* Let RX and TX events to interrupt */
1054 eepro_en_int(ioaddr);
1055
1056 /* clear all interrupts */
1057 eepro_clear_int(ioaddr);
1058
1059 /* Initialize RCV */
Jeff Garzikd61780c2005-10-30 15:01:51 -08001060 outw(lp->rcv_lower_limit, ioaddr + RCV_BAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 lp->rx_start = lp->rcv_lower_limit;
Jeff Garzikd61780c2005-10-30 15:01:51 -08001062 outw(lp->rcv_upper_limit | 0xfe, ioaddr + RCV_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
1064 /* Initialize XMT */
Jeff Garzikd61780c2005-10-30 15:01:51 -08001065 outw(lp->xmt_lower_limit, ioaddr + lp->xmt_bar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 lp->tx_start = lp->tx_end = lp->xmt_lower_limit;
1067 lp->tx_last = 0;
1068
1069 /* Check for the i82595TX and i82595FX */
1070 old8 = inb(ioaddr + 8);
1071 outb(~old8, ioaddr + 8);
1072
1073 if ((temp_reg = inb(ioaddr + 8)) == old8) {
1074 if (net_debug > 3)
1075 printk(KERN_DEBUG "i82595 detected!\n");
1076 lp->version = LAN595;
1077 }
1078 else {
1079 lp->version = LAN595TX;
1080 outb(old8, ioaddr + 8);
1081 old9 = inb(ioaddr + 9);
1082
1083 if (irqMask==ee_FX_INT2IRQ) {
1084 if (net_debug > 3) {
1085 printk(KERN_DEBUG "IrqMask: %#x\n",irqMask);
1086 printk(KERN_DEBUG "i82595FX detected!\n");
1087 }
1088 lp->version = LAN595FX;
1089 outb(old9, ioaddr + 9);
1090 if (dev->if_port != TPE) { /* Hopefully, this will fix the
1091 problem of using Pentiums and
1092 pro/10 w/ BNC. */
1093 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1094 temp_reg = inb(ioaddr + REG13);
1095 /* disable the full duplex mode since it is not
1096 applicable with the 10Base2 cable. */
1097 outb(temp_reg & ~(FDX | A_N_ENABLE), REG13);
1098 eepro_sw2bank0(ioaddr); /* be CAREFUL, BANK 0 now */
1099 }
1100 }
1101 else if (net_debug > 3) {
1102 printk(KERN_DEBUG "temp_reg: %#x ~old9: %#x\n",temp_reg,((~old9)&0xff));
1103 printk(KERN_DEBUG "i82595TX detected!\n");
1104 }
1105 }
1106
1107 eepro_sel_reset(ioaddr);
1108
1109 netif_start_queue(dev);
1110
1111 if (net_debug > 3)
1112 printk(KERN_DEBUG "%s: exiting eepro_open routine.\n", dev->name);
1113
1114 /* enabling rx */
1115 eepro_en_rx(ioaddr);
1116
1117 return 0;
1118}
1119
1120static void eepro_tx_timeout (struct net_device *dev)
1121{
1122 struct eepro_local *lp = netdev_priv(dev);
1123 int ioaddr = dev->base_addr;
1124
1125 /* if (net_debug > 1) */
1126 printk (KERN_ERR "%s: transmit timed out, %s?\n", dev->name,
1127 "network cable problem");
1128 /* This is not a duplicate. One message for the console,
Michael Opdenacker59c51592007-05-09 08:57:56 +02001129 one for the log file */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 printk (KERN_DEBUG "%s: transmit timed out, %s?\n", dev->name,
1131 "network cable problem");
1132 eepro_complete_selreset(ioaddr);
1133}
1134
1135
Stephen Hemminger613573252009-08-31 19:50:58 +00001136static netdev_tx_t eepro_send_packet(struct sk_buff *skb,
1137 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138{
1139 struct eepro_local *lp = netdev_priv(dev);
1140 unsigned long flags;
1141 int ioaddr = dev->base_addr;
1142 short length = skb->len;
1143
1144 if (net_debug > 5)
1145 printk(KERN_DEBUG "%s: entering eepro_send_packet routine.\n", dev->name);
1146
1147 if (length < ETH_ZLEN) {
Herbert Xu5b057c62006-06-23 02:06:41 -07001148 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +00001149 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 length = ETH_ZLEN;
1151 }
1152 netif_stop_queue (dev);
1153
1154 eepro_dis_int(ioaddr);
1155 spin_lock_irqsave(&lp->lock, flags);
1156
1157 {
1158 unsigned char *buf = skb->data;
1159
1160 if (hardware_send_packet(dev, buf, length))
1161 /* we won't wake queue here because we're out of space */
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001162 dev->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 else {
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07001164 dev->stats.tx_bytes+=skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 netif_wake_queue(dev);
1166 }
1167
1168 }
1169
1170 dev_kfree_skb (skb);
1171
1172 /* You might need to clean up and record Tx statistics here. */
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001173 /* dev->stats.tx_aborted_errors++; */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
1175 if (net_debug > 5)
1176 printk(KERN_DEBUG "%s: exiting eepro_send_packet routine.\n", dev->name);
1177
1178 eepro_en_int(ioaddr);
1179 spin_unlock_irqrestore(&lp->lock, flags);
1180
Patrick McHardy6ed10652009-06-23 06:03:08 +00001181 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182}
1183
1184
1185/* The typical workload of the driver:
1186 Handle the network interface interrupts. */
1187
1188static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001189eepro_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190{
Jeff Garzikc31f28e2006-10-06 14:56:04 -04001191 struct net_device *dev = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 struct eepro_local *lp;
1193 int ioaddr, status, boguscount = 20;
1194 int handled = 0;
1195
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 lp = netdev_priv(dev);
1197
1198 spin_lock(&lp->lock);
1199
1200 if (net_debug > 5)
1201 printk(KERN_DEBUG "%s: entering eepro_interrupt routine.\n", dev->name);
1202
1203 ioaddr = dev->base_addr;
1204
1205 while (((status = inb(ioaddr + STATUS_REG)) & (RX_INT|TX_INT)) && (boguscount--))
1206 {
1207 handled = 1;
1208 if (status & RX_INT) {
1209 if (net_debug > 4)
1210 printk(KERN_DEBUG "%s: packet received interrupt.\n", dev->name);
1211
1212 eepro_dis_int(ioaddr);
1213
1214 /* Get the received packets */
1215 eepro_ack_rx(ioaddr);
1216 eepro_rx(dev);
1217
1218 eepro_en_int(ioaddr);
1219 }
1220 if (status & TX_INT) {
1221 if (net_debug > 4)
1222 printk(KERN_DEBUG "%s: packet transmit interrupt.\n", dev->name);
1223
1224
1225 eepro_dis_int(ioaddr);
1226
1227 /* Process the status of transmitted packets */
1228 eepro_ack_tx(ioaddr);
1229 eepro_transmit_interrupt(dev);
1230
1231 eepro_en_int(ioaddr);
1232 }
1233 }
1234
1235 if (net_debug > 5)
1236 printk(KERN_DEBUG "%s: exiting eepro_interrupt routine.\n", dev->name);
1237
1238 spin_unlock(&lp->lock);
1239 return IRQ_RETVAL(handled);
1240}
1241
1242static int eepro_close(struct net_device *dev)
1243{
1244 struct eepro_local *lp = netdev_priv(dev);
1245 int ioaddr = dev->base_addr;
1246 short temp_reg;
1247
1248 netif_stop_queue(dev);
1249
1250 eepro_sw2bank1(ioaddr); /* Switch back to Bank 1 */
1251
1252 /* Disable the physical interrupt line. */
1253 temp_reg = inb(ioaddr + REG1);
1254 outb(temp_reg & 0x7f, ioaddr + REG1);
1255
1256 eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
1257
1258 /* Flush the Tx and disable Rx. */
1259 outb(STOP_RCV_CMD, ioaddr);
1260 lp->tx_start = lp->tx_end = lp->xmt_lower_limit;
1261 lp->tx_last = 0;
1262
1263 /* Mask all the interrupts. */
1264 eepro_dis_int(ioaddr);
1265
1266 /* clear all interrupts */
1267 eepro_clear_int(ioaddr);
1268
1269 /* Reset the 82595 */
1270 eepro_reset(ioaddr);
1271
1272 /* release the interrupt */
1273 free_irq(dev->irq, dev);
1274
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 /* Update the statistics here. What statistics? */
1276
1277 return 0;
1278}
1279
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280/* Set or clear the multicast filter for this adaptor.
1281 */
1282static void
1283set_multicast_list(struct net_device *dev)
1284{
1285 struct eepro_local *lp = netdev_priv(dev);
1286 short ioaddr = dev->base_addr;
1287 unsigned short mode;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001288 struct netdev_hw_addr *ha;
Alexander Beregalov06c92ee2010-02-20 18:48:25 -08001289 int mc_count = netdev_mc_count(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001291 if (dev->flags&(IFF_ALLMULTI|IFF_PROMISC) || mc_count > 63)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1294 mode = inb(ioaddr + REG2);
1295 outb(mode | PRMSC_Mode, ioaddr + REG2);
1296 mode = inb(ioaddr + REG3);
1297 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1298 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 }
1300
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001301 else if (mc_count == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 {
1303 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1304 mode = inb(ioaddr + REG2);
1305 outb(mode & 0xd6, ioaddr + REG2); /* Turn off Multi-IA and PRMSC_Mode bits */
1306 mode = inb(ioaddr + REG3);
1307 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1308 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1309 }
1310
1311 else
1312 {
1313 unsigned short status, *eaddrs;
1314 int i, boguscount = 0;
1315
1316 /* Disable RX and TX interrupts. Necessary to avoid
1317 corruption of the HOST_ADDRESS_REG by interrupt
1318 service routines. */
1319 eepro_dis_int(ioaddr);
1320
1321 eepro_sw2bank2(ioaddr); /* be CAREFUL, BANK 2 now */
1322 mode = inb(ioaddr + REG2);
1323 outb(mode | Multi_IA, ioaddr + REG2);
1324 mode = inb(ioaddr + REG3);
1325 outb(mode, ioaddr + REG3); /* writing reg. 3 to complete the update */
1326 eepro_sw2bank0(ioaddr); /* Return to BANK 0 now */
1327 outw(lp->tx_end, ioaddr + HOST_ADDRESS_REG);
1328 outw(MC_SETUP, ioaddr + IO_PORT);
1329 outw(0, ioaddr + IO_PORT);
1330 outw(0, ioaddr + IO_PORT);
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001331 outw(6 * (mc_count + 1), ioaddr + IO_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Jiri Pirko22bedad32010-04-01 21:22:57 +00001333 netdev_for_each_mc_addr(ha, dev) {
1334 eaddrs = (unsigned short *) ha->addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 outw(*eaddrs++, ioaddr + IO_PORT);
1336 outw(*eaddrs++, ioaddr + IO_PORT);
1337 outw(*eaddrs++, ioaddr + IO_PORT);
1338 }
1339
1340 eaddrs = (unsigned short *) dev->dev_addr;
1341 outw(eaddrs[0], ioaddr + IO_PORT);
1342 outw(eaddrs[1], ioaddr + IO_PORT);
1343 outw(eaddrs[2], ioaddr + IO_PORT);
1344 outw(lp->tx_end, ioaddr + lp->xmt_bar);
1345 outb(MC_SETUP, ioaddr);
1346
1347 /* Update the transmit queue */
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001348 i = lp->tx_end + XMT_HEADER + 6 * (mc_count + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
1350 if (lp->tx_start != lp->tx_end)
1351 {
1352 /* update the next address and the chain bit in the
1353 last packet */
1354 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1355 outw(i, ioaddr + IO_PORT);
1356 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1357 status = inw(ioaddr + IO_PORT);
1358 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1359 lp->tx_end = i ;
1360 }
1361 else {
1362 lp->tx_start = lp->tx_end = i ;
1363 }
1364
1365 /* Acknowledge that the MC setup is done */
1366 do { /* We should be doing this in the eepro_interrupt()! */
1367 SLOW_DOWN;
1368 SLOW_DOWN;
1369 if (inb(ioaddr + STATUS_REG) & 0x08)
1370 {
1371 i = inb(ioaddr);
1372 outb(0x08, ioaddr + STATUS_REG);
1373
1374 if (i & 0x20) { /* command ABORTed */
Jeff Garzikd61780c2005-10-30 15:01:51 -08001375 printk(KERN_NOTICE "%s: multicast setup failed.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 dev->name);
1377 break;
1378 } else if ((i & 0x0f) == 0x03) { /* MC-Done */
1379 printk(KERN_DEBUG "%s: set Rx mode to %d address%s.\n",
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001380 dev->name, mc_count,
1381 mc_count > 1 ? "es":"");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 break;
1383 }
1384 }
1385 } while (++boguscount < 100);
1386
1387 /* Re-enable RX and TX interrupts */
1388 eepro_en_int(ioaddr);
1389 }
1390 if (lp->eepro == LAN595FX_10ISA) {
1391 eepro_complete_selreset(ioaddr);
1392 }
1393 else
1394 eepro_en_rx(ioaddr);
1395}
1396
1397/* The horrible routine to read a word from the serial EEPROM. */
1398/* IMPORTANT - the 82595 will be set to Bank 0 after the eeprom is read */
1399
1400/* The delay between EEPROM clock transitions. */
1401#define eeprom_delay() { udelay(40); }
1402#define EE_READ_CMD (6 << 6)
1403
Hannes Ederdac499f2008-12-25 23:56:45 -08001404static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405read_eeprom(int ioaddr, int location, struct net_device *dev)
1406{
1407 int i;
1408 unsigned short retval = 0;
1409 struct eepro_local *lp = netdev_priv(dev);
1410 short ee_addr = ioaddr + lp->eeprom_reg;
1411 int read_cmd = location | EE_READ_CMD;
1412 short ctrl_val = EECS ;
1413
1414 /* XXXX - black magic */
1415 eepro_sw2bank1(ioaddr);
1416 outb(0x00, ioaddr + STATUS_REG);
1417 /* XXXX - black magic */
1418
1419 eepro_sw2bank2(ioaddr);
1420 outb(ctrl_val, ee_addr);
1421
1422 /* Shift the read command bits out. */
1423 for (i = 8; i >= 0; i--) {
1424 short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI
1425 : ctrl_val;
1426 outb(outval, ee_addr);
1427 outb(outval | EESK, ee_addr); /* EEPROM clock tick. */
1428 eeprom_delay();
1429 outb(outval, ee_addr); /* Finish EEPROM a clock tick. */
1430 eeprom_delay();
1431 }
1432 outb(ctrl_val, ee_addr);
1433
1434 for (i = 16; i > 0; i--) {
1435 outb(ctrl_val | EESK, ee_addr); eeprom_delay();
1436 retval = (retval << 1) | ((inb(ee_addr) & EEDO) ? 1 : 0);
1437 outb(ctrl_val, ee_addr); eeprom_delay();
1438 }
1439
1440 /* Terminate the EEPROM access. */
1441 ctrl_val &= ~EECS;
1442 outb(ctrl_val | EESK, ee_addr);
1443 eeprom_delay();
1444 outb(ctrl_val, ee_addr);
1445 eeprom_delay();
1446 eepro_sw2bank0(ioaddr);
1447 return retval;
1448}
1449
1450static int
1451hardware_send_packet(struct net_device *dev, void *buf, short length)
1452{
1453 struct eepro_local *lp = netdev_priv(dev);
1454 short ioaddr = dev->base_addr;
1455 unsigned status, tx_available, last, end;
1456
1457 if (net_debug > 5)
1458 printk(KERN_DEBUG "%s: entering hardware_send_packet routine.\n", dev->name);
1459
1460 /* determine how much of the transmit buffer space is available */
1461 if (lp->tx_end > lp->tx_start)
1462 tx_available = lp->xmt_ram - (lp->tx_end - lp->tx_start);
1463 else if (lp->tx_end < lp->tx_start)
1464 tx_available = lp->tx_start - lp->tx_end;
1465 else tx_available = lp->xmt_ram;
1466
1467 if (((((length + 3) >> 1) << 1) + 2*XMT_HEADER) >= tx_available) {
1468 /* No space available ??? */
1469 return 1;
1470 }
1471
1472 last = lp->tx_end;
1473 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1474
1475 if (end >= lp->xmt_upper_limit + 2) { /* the transmit buffer is wrapped around */
Jeff Garzikd61780c2005-10-30 15:01:51 -08001476 if ((lp->xmt_upper_limit + 2 - last) <= XMT_HEADER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 /* Arrrr!!!, must keep the xmt header together,
1478 several days were lost to chase this one down. */
1479 last = lp->xmt_lower_limit;
1480 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1481 }
1482 else end = lp->xmt_lower_limit + (end -
1483 lp->xmt_upper_limit + 2);
1484 }
1485
1486 outw(last, ioaddr + HOST_ADDRESS_REG);
1487 outw(XMT_CMD, ioaddr + IO_PORT);
1488 outw(0, ioaddr + IO_PORT);
1489 outw(end, ioaddr + IO_PORT);
1490 outw(length, ioaddr + IO_PORT);
1491
1492 if (lp->version == LAN595)
1493 outsw(ioaddr + IO_PORT, buf, (length + 3) >> 1);
1494 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1495 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1496 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1497 outsl(ioaddr + IO_PORT_32_BIT, buf, (length + 3) >> 2);
1498 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1499 }
1500
1501 /* A dummy read to flush the DRAM write pipeline */
1502 status = inw(ioaddr + IO_PORT);
1503
1504 if (lp->tx_start == lp->tx_end) {
1505 outw(last, ioaddr + lp->xmt_bar);
1506 outb(XMT_CMD, ioaddr);
1507 lp->tx_start = last; /* I don't like to change tx_start here */
1508 }
1509 else {
1510 /* update the next address and the chain bit in the
1511 last packet */
1512
1513 if (lp->tx_end != last) {
1514 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1515 outw(last, ioaddr + IO_PORT);
1516 }
1517
1518 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1519 status = inw(ioaddr + IO_PORT);
1520 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1521
1522 /* Continue the transmit command */
1523 outb(RESUME_XMT_CMD, ioaddr);
1524 }
1525
1526 lp->tx_last = last;
1527 lp->tx_end = end;
1528
1529 if (net_debug > 5)
1530 printk(KERN_DEBUG "%s: exiting hardware_send_packet routine.\n", dev->name);
1531
1532 return 0;
1533}
1534
1535static void
1536eepro_rx(struct net_device *dev)
1537{
1538 struct eepro_local *lp = netdev_priv(dev);
1539 short ioaddr = dev->base_addr;
1540 short boguscount = 20;
1541 short rcv_car = lp->rx_start;
1542 unsigned rcv_event, rcv_status, rcv_next_frame, rcv_size;
1543
1544 if (net_debug > 5)
1545 printk(KERN_DEBUG "%s: entering eepro_rx routine.\n", dev->name);
1546
1547 /* Set the read pointer to the start of the RCV */
1548 outw(rcv_car, ioaddr + HOST_ADDRESS_REG);
1549
1550 rcv_event = inw(ioaddr + IO_PORT);
1551
1552 while (rcv_event == RCV_DONE) {
1553
1554 rcv_status = inw(ioaddr + IO_PORT);
1555 rcv_next_frame = inw(ioaddr + IO_PORT);
1556 rcv_size = inw(ioaddr + IO_PORT);
1557
1558 if ((rcv_status & (RX_OK | RX_ERROR)) == RX_OK) {
1559
1560 /* Malloc up new buffer. */
1561 struct sk_buff *skb;
1562
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001563 dev->stats.rx_bytes+=rcv_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 rcv_size &= 0x3fff;
1565 skb = dev_alloc_skb(rcv_size+5);
1566 if (skb == NULL) {
1567 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001568 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1570 lp->rx_start = rcv_next_frame;
1571 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1572
1573 break;
1574 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 skb_reserve(skb,2);
1576
1577 if (lp->version == LAN595)
1578 insw(ioaddr+IO_PORT, skb_put(skb,rcv_size), (rcv_size + 3) >> 1);
1579 else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */
1580 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1581 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1582 insl(ioaddr+IO_PORT_32_BIT, skb_put(skb,rcv_size),
1583 (rcv_size + 3) >> 2);
1584 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1585 }
1586
1587 skb->protocol = eth_type_trans(skb,dev);
1588 netif_rx(skb);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001589 dev->stats.rx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 }
1591
1592 else { /* Not sure will ever reach here,
1593 I set the 595 to discard bad received frames */
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001594 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
1596 if (rcv_status & 0x0100)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001597 dev->stats.rx_over_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
1599 else if (rcv_status & 0x0400)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001600 dev->stats.rx_frame_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
1602 else if (rcv_status & 0x0800)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001603 dev->stats.rx_crc_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
Jeff Garzikd61780c2005-10-30 15:01:51 -08001605 printk(KERN_DEBUG "%s: event = %#x, status = %#x, next = %#x, size = %#x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 dev->name, rcv_event, rcv_status, rcv_next_frame, rcv_size);
1607 }
1608
1609 if (rcv_status & 0x1000)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001610 dev->stats.rx_length_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1613 lp->rx_start = rcv_next_frame;
1614
1615 if (--boguscount == 0)
1616 break;
1617
1618 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1619 rcv_event = inw(ioaddr + IO_PORT);
1620
1621 }
1622 if (rcv_car == 0)
1623 rcv_car = lp->rcv_upper_limit | 0xff;
1624
1625 outw(rcv_car - 1, ioaddr + RCV_STOP);
1626
1627 if (net_debug > 5)
1628 printk(KERN_DEBUG "%s: exiting eepro_rx routine.\n", dev->name);
1629}
1630
1631static void
1632eepro_transmit_interrupt(struct net_device *dev)
1633{
1634 struct eepro_local *lp = netdev_priv(dev);
1635 short ioaddr = dev->base_addr;
Jeff Garzikd61780c2005-10-30 15:01:51 -08001636 short boguscount = 25;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 short xmt_status;
1638
Jeff Garzikd61780c2005-10-30 15:01:51 -08001639 while ((lp->tx_start != lp->tx_end) && boguscount--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
1641 outw(lp->tx_start, ioaddr + HOST_ADDRESS_REG);
1642 xmt_status = inw(ioaddr+IO_PORT);
1643
1644 if (!(xmt_status & TX_DONE_BIT))
1645 break;
1646
1647 xmt_status = inw(ioaddr+IO_PORT);
1648 lp->tx_start = inw(ioaddr+IO_PORT);
1649
1650 netif_wake_queue (dev);
1651
1652 if (xmt_status & TX_OK)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001653 dev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001655 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 if (xmt_status & 0x0400) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001657 dev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 printk(KERN_DEBUG "%s: carrier error\n",
1659 dev->name);
1660 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1661 dev->name, xmt_status);
1662 }
1663 else {
1664 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1665 dev->name, xmt_status);
1666 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1667 dev->name, xmt_status);
1668 }
1669 }
1670 if (xmt_status & 0x000f) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001671 dev->stats.collisions += (xmt_status & 0x000f);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 }
1673
1674 if ((xmt_status & 0x0040) == 0x0) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001675 dev->stats.tx_heartbeat_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 }
1677 }
1678}
1679
1680static int eepro_ethtool_get_settings(struct net_device *dev,
1681 struct ethtool_cmd *cmd)
1682{
Wang Chen4cf16532008-11-12 23:38:14 -08001683 struct eepro_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Jeff Garzikd61780c2005-10-30 15:01:51 -08001685 cmd->supported = SUPPORTED_10baseT_Half |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 SUPPORTED_10baseT_Full |
1687 SUPPORTED_Autoneg;
1688 cmd->advertising = ADVERTISED_10baseT_Half |
1689 ADVERTISED_10baseT_Full |
1690 ADVERTISED_Autoneg;
1691
1692 if (GetBit(lp->word[5], ee_PortTPE)) {
1693 cmd->supported |= SUPPORTED_TP;
1694 cmd->advertising |= ADVERTISED_TP;
1695 }
1696 if (GetBit(lp->word[5], ee_PortBNC)) {
1697 cmd->supported |= SUPPORTED_BNC;
1698 cmd->advertising |= ADVERTISED_BNC;
1699 }
1700 if (GetBit(lp->word[5], ee_PortAUI)) {
1701 cmd->supported |= SUPPORTED_AUI;
1702 cmd->advertising |= ADVERTISED_AUI;
1703 }
1704
1705 cmd->speed = SPEED_10;
1706
1707 if (dev->if_port == TPE && lp->word[1] & ee_Duplex) {
1708 cmd->duplex = DUPLEX_FULL;
1709 }
1710 else {
1711 cmd->duplex = DUPLEX_HALF;
1712 }
1713
1714 cmd->port = dev->if_port;
1715 cmd->phy_address = dev->base_addr;
1716 cmd->transceiver = XCVR_INTERNAL;
1717
1718 if (lp->word[0] & ee_AutoNeg) {
1719 cmd->autoneg = 1;
1720 }
1721
1722 return 0;
1723}
1724
1725static void eepro_ethtool_get_drvinfo(struct net_device *dev,
1726 struct ethtool_drvinfo *drvinfo)
1727{
1728 strcpy(drvinfo->driver, DRV_NAME);
1729 strcpy(drvinfo->version, DRV_VERSION);
1730 sprintf(drvinfo->bus_info, "ISA 0x%lx", dev->base_addr);
1731}
1732
Jeff Garzik7282d492006-09-13 14:30:00 -04001733static const struct ethtool_ops eepro_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 .get_settings = eepro_ethtool_get_settings,
1735 .get_drvinfo = eepro_ethtool_get_drvinfo,
1736};
1737
1738#ifdef MODULE
1739
1740#define MAX_EEPRO 8
1741static struct net_device *dev_eepro[MAX_EEPRO];
1742
1743static int io[MAX_EEPRO] = {
1744 [0 ... MAX_EEPRO-1] = -1
1745};
1746static int irq[MAX_EEPRO];
1747static int mem[MAX_EEPRO] = { /* Size of the rx buffer in KB */
1748 [0 ... MAX_EEPRO-1] = RCV_DEFAULT_RAM/1024
1749};
1750static int autodetect;
1751
1752static int n_eepro;
1753/* For linux 2.1.xx */
1754
1755MODULE_AUTHOR("Pascal Dupuis and others");
1756MODULE_DESCRIPTION("Intel i82595 ISA EtherExpressPro10/10+ driver");
1757MODULE_LICENSE("GPL");
1758
Florin Malitaa1bfcd92005-10-28 15:14:46 -07001759module_param_array(io, int, NULL, 0);
1760module_param_array(irq, int, NULL, 0);
1761module_param_array(mem, int, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762module_param(autodetect, int, 0);
1763MODULE_PARM_DESC(io, "EtherExpress Pro/10 I/O base addres(es)");
1764MODULE_PARM_DESC(irq, "EtherExpress Pro/10 IRQ number(s)");
1765MODULE_PARM_DESC(mem, "EtherExpress Pro/10 Rx buffer size(es) in kB (3-29)");
1766MODULE_PARM_DESC(autodetect, "EtherExpress Pro/10 force board(s) detection (0-1)");
1767
Andrew Morton02a32452006-08-14 23:00:01 -07001768int __init init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769{
1770 struct net_device *dev;
1771 int i;
1772 if (io[0] == -1 && autodetect == 0) {
1773 printk(KERN_WARNING "eepro_init_module: Probe is very dangerous in ISA boards!\n");
1774 printk(KERN_WARNING "eepro_init_module: Please add \"autodetect=1\" to force probe\n");
1775 return -ENODEV;
1776 }
1777 else if (autodetect) {
1778 /* if autodetect is set then we must force detection */
1779 for (i = 0; i < MAX_EEPRO; i++) {
1780 io[i] = 0;
1781 }
1782
1783 printk(KERN_INFO "eepro_init_module: Auto-detecting boards (May God protect us...)\n");
1784 }
1785
Roel Kluind513d012009-07-26 18:53:17 -07001786 for (i = 0; i < MAX_EEPRO && io[i] != -1; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 dev = alloc_etherdev(sizeof(struct eepro_local));
1788 if (!dev)
1789 break;
1790
1791 dev->mem_end = mem[i];
1792 dev->base_addr = io[i];
1793 dev->irq = irq[i];
1794
1795 if (do_eepro_probe(dev) == 0) {
b1fc5502005-05-12 20:11:55 -04001796 dev_eepro[n_eepro++] = dev;
1797 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 }
1799 free_netdev(dev);
1800 break;
1801 }
1802
1803 if (n_eepro)
1804 printk(KERN_INFO "%s", version);
1805
1806 return n_eepro ? 0 : -ENODEV;
1807}
1808
Al Viroafc8eb42006-06-14 18:50:53 -04001809void __exit
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810cleanup_module(void)
1811{
1812 int i;
1813
1814 for (i=0; i<n_eepro; i++) {
1815 struct net_device *dev = dev_eepro[i];
1816 unregister_netdev(dev);
1817 release_region(dev->base_addr, EEPRO_IO_EXTENT);
1818 free_netdev(dev);
1819 }
1820}
1821#endif /* MODULE */