1 /* e2100.c: A Cabletron E2100 series ethernet driver for linux. */
3 Written 1993-1994 by Donald Becker.
5 Copyright 1994 by Donald Becker.
6 Copyright 1993 United States Government as represented by the
7 Director, National Security Agency. This software may be used and
8 distributed according to the terms of the GNU Public License,
9 incorporated herein by reference.
11 This is a driver for the Cabletron E2100 series ethercards.
13 The Author may be reached as becker@cesdis.gsfc.nasa.gov, or
14 C/O Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
16 The E2100 series ethercard is a fairly generic shared memory 8390
17 implementation. The only unusual aspect is the way the shared memory
18 registers are set: first you do an inb() in what is normally the
19 station address region, and the low three bits of next outb() *address*
20 is used as the write value for that register. Either someone wasn't
21 too used to dem bit en bites, or they were trying to obfuscate the
22 programming interface.
24 There is an additional complication when setting the window on the packet
25 buffer. You must first do a read into the packet buffer region with the
26 low 8 address bits the address setting the page for the start of the packet
27 buffer window, and then do the above operation. See mem_on() for details.
29 One bug on the chip is that even a hard reset won't disable the memory
30 window, usually resulting in a hung machine if mem_off() isn't called.
31 If this happens, you must power down the machine for about 30 seconds.
34 static const char *version
=
35 "e2100.c:v1.01 7/21/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
37 #include <linux/module.h>
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
43 #include <linux/ioport.h>
44 #include <linux/netdevice.h>
45 #include <linux/etherdevice.h>
46 #include <linux/init.h>
47 #include <linux/delay.h>
50 #include <asm/system.h>
54 static int e21_probe_list
[] = {0x300, 0x280, 0x380, 0x220, 0};
56 /* Offsets from the base_addr.
57 Read from the ASIC register, and the low three bits of the next outb()
58 address is used to set the corresponding register. */
59 #define E21_NIC_OFFSET 0 /* Offset to the 8390 NIC. */
61 #define E21_MEM_ENABLE 0x10
62 #define E21_MEM_ON 0x05 /* Enable memory in 16 bit mode. */
63 #define E21_MEM_ON_8 0x07 /* Enable memory in 8 bit mode. */
64 #define E21_MEM_BASE 0x11
65 #define E21_IRQ_LOW 0x12 /* The low three bits of the IRQ number. */
66 #define E21_IRQ_HIGH 0x14 /* The high IRQ bit and media select ... */
67 #define E21_MEDIA 0x14 /* (alias). */
68 #define E21_ALT_IFPORT 0x02 /* Set to use the other (BNC,AUI) port. */
69 #define E21_BIG_MEM 0x04 /* Use a bigger (64K) buffer (we don't) */
70 #define E21_SAPROM 0x10 /* Offset to station address data. */
71 #define E21_IO_EXTENT 0x20
73 extern inline void mem_on(short port
, volatile char *mem_base
,
74 unsigned char start_page
)
76 /* This is a little weird: set the shared memory window by doing a
77 read. The low address bits specify the starting page. */
78 readb(mem_base
+start_page
);
79 inb(port
+ E21_MEM_ENABLE
);
80 outb(E21_MEM_ON
, port
+ E21_MEM_ENABLE
+ E21_MEM_ON
);
83 extern inline void mem_off(short port
)
85 inb(port
+ E21_MEM_ENABLE
);
86 outb(0x00, port
+ E21_MEM_ENABLE
);
89 /* In other drivers I put the TX pages first, but the E2100 window circuitry
90 is designed to have a 4K Tx region last. The windowing circuitry wraps the
91 window at 0x2fff->0x0000 so that the packets at e.g. 0x2f00 in the RX ring
92 appear contiguously in the window. */
93 #define E21_RX_START_PG 0x00 /* First page of RX buffer */
94 #define E21_RX_STOP_PG 0x30 /* Last page +1 of RX ring */
95 #define E21_BIG_RX_STOP_PG 0xF0 /* Last page +1 of RX ring */
96 #define E21_TX_START_PG E21_RX_STOP_PG /* First page of TX buffer */
98 int e2100_probe(struct net_device
*dev
);
99 int e21_probe1(struct net_device
*dev
, int ioaddr
);
101 static int e21_open(struct net_device
*dev
);
102 static void e21_reset_8390(struct net_device
*dev
);
103 static void e21_block_input(struct net_device
*dev
, int count
,
104 struct sk_buff
*skb
, int ring_offset
);
105 static void e21_block_output(struct net_device
*dev
, int count
,
106 const unsigned char *buf
, int start_page
);
107 static void e21_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
,
110 static int e21_close(struct net_device
*dev
);
113 /* Probe for the E2100 series ethercards. These cards have an 8390 at the
114 base address and the station address at both offset 0x10 and 0x18. I read
115 the station address from offset 0x18 to avoid the dataport of NE2000
116 ethercards, and look for Ctron's unique ID (first three octets of the
120 int __init
e2100_probe(struct net_device
*dev
)
123 int base_addr
= dev
->base_addr
;
125 if (base_addr
> 0x1ff) /* Check a single specified location. */
126 return e21_probe1(dev
, base_addr
);
127 else if (base_addr
!= 0) /* Don't probe at all. */
130 for (port
= e21_probe_list
; *port
; port
++) {
131 if (check_region(*port
, E21_IO_EXTENT
))
133 if (e21_probe1(dev
, *port
) == 0)
140 int __init
e21_probe1(struct net_device
*dev
, int ioaddr
)
143 unsigned char *station_addr
= dev
->dev_addr
;
144 static unsigned version_printed
= 0;
146 /* First check the station address for the Ctron prefix. */
147 if (inb(ioaddr
+ E21_SAPROM
+ 0) != 0x00
148 || inb(ioaddr
+ E21_SAPROM
+ 1) != 0x00
149 || inb(ioaddr
+ E21_SAPROM
+ 2) != 0x1d)
152 /* Verify by making certain that there is a 8390 at there. */
153 outb(E8390_NODMA
+ E8390_STOP
, ioaddr
);
154 udelay(1); /* we want to delay one I/O cycle - which is 2MHz */
155 status
= inb(ioaddr
);
156 if (status
!= 0x21 && status
!= 0x23)
159 /* Read the station address PROM. */
160 for (i
= 0; i
< 6; i
++)
161 station_addr
[i
] = inb(ioaddr
+ E21_SAPROM
+ i
);
163 inb(ioaddr
+ E21_MEDIA
); /* Point to media selection. */
164 outb(0, ioaddr
+ E21_ASIC
); /* and disable the secondary interface. */
166 if (load_8390_module("e2100.c"))
169 if (ei_debug
&& version_printed
++ == 0)
172 /* We should have a "dev" from Space.c or the static module table. */
174 printk("e2100.c: Passed a NULL device.\n");
175 dev
= init_etherdev(0, 0);
178 printk("%s: E21** at %#3x,", dev
->name
, ioaddr
);
179 for (i
= 0; i
< 6; i
++)
180 printk(" %02X", station_addr
[i
]);
182 /* Allocate dev->priv and fill in 8390 specific dev fields. */
183 if (ethdev_init(dev
)) {
184 printk (" unable to get memory for dev->priv.\n");
189 int irqlist
[] = {15,11,10,12,5,9,3,4}, i
;
190 for (i
= 0; i
< 8; i
++)
191 if (request_irq (irqlist
[i
], NULL
, 0, "bogus", NULL
) != -EBUSY
) {
192 dev
->irq
= irqlist
[i
];
196 printk(" unable to get IRQ %d.\n", dev
->irq
);
199 } else if (dev
->irq
== 2) /* Fixup luser bogosity: IRQ2 is really IRQ9 */
202 /* Grab the region so we can find a different board if IRQ select fails. */
203 request_region(ioaddr
, E21_IO_EXTENT
, "e2100");
205 /* The 8390 is at the base address. */
206 dev
->base_addr
= ioaddr
;
208 ei_status
.name
= "E2100";
209 ei_status
.word16
= 1;
210 ei_status
.tx_start_page
= E21_TX_START_PG
;
211 ei_status
.rx_start_page
= E21_RX_START_PG
;
212 ei_status
.stop_page
= E21_RX_STOP_PG
;
213 ei_status
.saved_irq
= dev
->irq
;
215 /* Check the media port used. The port can be passed in on the
217 if (dev
->mem_end
& 15)
218 dev
->if_port
= dev
->mem_end
& 7;
221 inb(ioaddr
+ E21_MEDIA
); /* Turn automatic media detection on. */
222 for(i
= 0; i
< 6; i
++)
223 if (station_addr
[i
] != inb(ioaddr
+ E21_SAPROM
+ 8 + i
)) {
229 /* Never map in the E21 shared memory unless you are actively using it.
230 Also, the shared memory has effective only one setting -- spread all
231 over the 128K region! */
232 if (dev
->mem_start
== 0)
233 dev
->mem_start
= 0xd0000;
236 /* These values are unused. The E2100 has a 2K window into the packet
237 buffer. The window can be set to start on any page boundary. */
238 dev
->rmem_start
= dev
->mem_start
+ TX_PAGES
*256;
239 dev
->mem_end
= dev
->rmem_end
= dev
->mem_start
+ 2*1024;
242 printk(", IRQ %d, %s media, memory @ %#lx.\n", dev
->irq
,
243 dev
->if_port
? "secondary" : "primary", dev
->mem_start
);
245 ei_status
.reset_8390
= &e21_reset_8390
;
246 ei_status
.block_input
= &e21_block_input
;
247 ei_status
.block_output
= &e21_block_output
;
248 ei_status
.get_8390_hdr
= &e21_get_8390_hdr
;
249 dev
->open
= &e21_open
;
250 dev
->stop
= &e21_close
;
257 e21_open(struct net_device
*dev
)
259 short ioaddr
= dev
->base_addr
;
261 if (request_irq(dev
->irq
, ei_interrupt
, 0, "e2100", dev
)) {
265 /* Set the interrupt line and memory base on the hardware. */
266 inb(ioaddr
+ E21_IRQ_LOW
);
267 outb(0, ioaddr
+ E21_ASIC
+ (dev
->irq
& 7));
268 inb(ioaddr
+ E21_IRQ_HIGH
); /* High IRQ bit, and if_port. */
269 outb(0, ioaddr
+ E21_ASIC
+ (dev
->irq
> 7 ? 1:0)
270 + (dev
->if_port
? E21_ALT_IFPORT
: 0));
271 inb(ioaddr
+ E21_MEM_BASE
);
272 outb(0, ioaddr
+ E21_ASIC
+ ((dev
->mem_start
>> 17) & 7));
280 e21_reset_8390(struct net_device
*dev
)
282 short ioaddr
= dev
->base_addr
;
285 if (ei_debug
> 1) printk("resetting the E2180x3 t=%ld...", jiffies
);
288 /* Set up the ASIC registers, just in case something changed them. */
290 if (ei_debug
> 1) printk("reset done\n");
294 /* Grab the 8390 specific header. We put the 2k window so the header page
295 appears at the start of the shared memory. */
298 e21_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
, int ring_page
)
301 short ioaddr
= dev
->base_addr
;
302 char *shared_mem
= (char *)dev
->mem_start
;
304 mem_on(ioaddr
, shared_mem
, ring_page
);
307 /* Officially this is what we are doing, but the readl() is faster */
308 memcpy_fromio(hdr
, shared_mem
, sizeof(struct e8390_pkt_hdr
));
310 ((unsigned int*)hdr
)[0] = readl(shared_mem
);
313 /* Turn off memory access: we would need to reprogram the window anyway. */
318 /* Block input and output are easy on shared memory ethercards.
319 The E21xx makes block_input() especially easy by wrapping the top
320 ring buffer to the bottom automatically. */
322 e21_block_input(struct net_device
*dev
, int count
, struct sk_buff
*skb
, int ring_offset
)
324 short ioaddr
= dev
->base_addr
;
325 char *shared_mem
= (char *)dev
->mem_start
;
327 mem_on(ioaddr
, shared_mem
, (ring_offset
>>8));
329 /* Packet is always in one chunk -- we can copy + cksum. */
330 eth_io_copy_and_sum(skb
, dev
->mem_start
+ (ring_offset
& 0xff), count
, 0);
336 e21_block_output(struct net_device
*dev
, int count
, const unsigned char *buf
,
339 short ioaddr
= dev
->base_addr
;
340 volatile char *shared_mem
= (char *)dev
->mem_start
;
342 /* Set the shared memory window start by doing a read, with the low address
343 bits specifying the starting page. */
344 readb(shared_mem
+ start_page
);
345 mem_on(ioaddr
, shared_mem
, start_page
);
347 memcpy_toio(shared_mem
, buf
, count
);
352 e21_close(struct net_device
*dev
)
354 short ioaddr
= dev
->base_addr
;
357 printk("%s: Shutting down ethercard.\n", dev
->name
);
359 free_irq(dev
->irq
, dev
);
360 dev
->irq
= ei_status
.saved_irq
;
362 /* Shut off the interrupt line and secondary interface. */
363 inb(ioaddr
+ E21_IRQ_LOW
);
364 outb(0, ioaddr
+ E21_ASIC
);
365 inb(ioaddr
+ E21_IRQ_HIGH
); /* High IRQ bit, and if_port. */
366 outb(0, ioaddr
+ E21_ASIC
);
370 /* Double-check that the memory has been turned off, because really
371 really bad things happen if it isn't. */
380 struct netdev_entry e21_drv
=
381 {"e21", e21_probe1
, E21_IO_EXTENT
, e21_probe_list
};
386 #define MAX_E21_CARDS 4 /* Max number of E21 cards per module */
387 #define NAMELEN 8 /* # of chars for storing dev->name */
388 static char namelist
[NAMELEN
* MAX_E21_CARDS
] = { 0, };
389 static struct net_device dev_e21
[MAX_E21_CARDS
] = {
391 NULL
, /* assign a chunk of namelist[] below */
398 static int io
[MAX_E21_CARDS
] = { 0, };
399 static int irq
[MAX_E21_CARDS
] = { 0, };
400 static int mem
[MAX_E21_CARDS
] = { 0, };
401 static int xcvr
[MAX_E21_CARDS
] = { 0, }; /* choose int. or ext. xcvr */
403 MODULE_PARM(io
, "1-" __MODULE_STRING(MAX_E21_CARDS
) "i");
404 MODULE_PARM(irq
, "1-" __MODULE_STRING(MAX_E21_CARDS
) "i");
405 MODULE_PARM(mem
, "1-" __MODULE_STRING(MAX_E21_CARDS
) "i");
406 MODULE_PARM(xcvr
, "1-" __MODULE_STRING(MAX_E21_CARDS
) "i");
408 /* This is set up so that only a single autoprobe takes place per call.
409 ISA device autoprobes on a running machine are not recommended. */
413 int this_dev
, found
= 0;
415 for (this_dev
= 0; this_dev
< MAX_E21_CARDS
; this_dev
++) {
416 struct net_device
*dev
= &dev_e21
[this_dev
];
417 dev
->name
= namelist
+(NAMELEN
*this_dev
);
418 dev
->irq
= irq
[this_dev
];
419 dev
->base_addr
= io
[this_dev
];
420 dev
->mem_start
= mem
[this_dev
];
421 dev
->mem_end
= xcvr
[this_dev
]; /* low 4bits = xcvr sel. */
422 dev
->init
= e2100_probe
;
423 if (io
[this_dev
] == 0) {
424 if (this_dev
!= 0) break; /* only autoprobe 1st one */
425 printk(KERN_NOTICE
"e2100.c: Presently autoprobing (not recommended) for a single card.\n");
427 if (register_netdev(dev
) != 0) {
428 printk(KERN_WARNING
"e2100.c: No E2100 card found (i/o = 0x%x).\n", io
[this_dev
]);
429 if (found
!= 0) { /* Got at least one. */
446 for (this_dev
= 0; this_dev
< MAX_E21_CARDS
; this_dev
++) {
447 struct net_device
*dev
= &dev_e21
[this_dev
];
448 if (dev
->priv
!= NULL
) {
449 void *priv
= dev
->priv
;
450 /* NB: e21_close() handles free_irq */
451 release_region(dev
->base_addr
, E21_IO_EXTENT
);
452 unregister_netdev(dev
);
456 unlock_8390_module();
462 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c e2100.c"
465 * kept-new-versions: 5