]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* e2100.c: A Cabletron E2100 series ethernet driver for linux. */ |
2 | /* | |
3 | Written 1993-1994 by Donald Becker. | |
4 | ||
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 General Public License, | |
9 | incorporated herein by reference. | |
10 | ||
11 | This is a driver for the Cabletron E2100 series ethercards. | |
12 | ||
13 | The Author may be reached as [email protected], or C/O | |
14 | Scyld Computing Corporation | |
15 | 410 Severn Ave., Suite 210 | |
16 | Annapolis MD 21403 | |
17 | ||
18 | The E2100 series ethercard is a fairly generic shared memory 8390 | |
19 | implementation. The only unusual aspect is the way the shared memory | |
20 | registers are set: first you do an inb() in what is normally the | |
21 | station address region, and the low three bits of next outb() *address* | |
22 | is used as the write value for that register. Either someone wasn't | |
23 | too used to dem bit en bites, or they were trying to obfuscate the | |
24 | programming interface. | |
25 | ||
26 | There is an additional complication when setting the window on the packet | |
27 | buffer. You must first do a read into the packet buffer region with the | |
28 | low 8 address bits the address setting the page for the start of the packet | |
29 | buffer window, and then do the above operation. See mem_on() for details. | |
30 | ||
31 | One bug on the chip is that even a hard reset won't disable the memory | |
32 | window, usually resulting in a hung machine if mem_off() isn't called. | |
33 | If this happens, you must power down the machine for about 30 seconds. | |
34 | */ | |
35 | ||
36 | static const char version[] = | |
37 | "e2100.c:v1.01 7/21/94 Donald Becker ([email protected])\n"; | |
38 | ||
39 | #include <linux/module.h> | |
40 | #include <linux/kernel.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> | |
48 | ||
49 | #include <asm/io.h> | |
50 | #include <asm/system.h> | |
51 | ||
52 | #include "8390.h" | |
53 | ||
54 | #define DRV_NAME "e2100" | |
55 | ||
56 | static int e21_probe_list[] = {0x300, 0x280, 0x380, 0x220, 0}; | |
57 | ||
58 | /* Offsets from the base_addr. | |
59 | Read from the ASIC register, and the low three bits of the next outb() | |
60 | address is used to set the corresponding register. */ | |
61 | #define E21_NIC_OFFSET 0 /* Offset to the 8390 NIC. */ | |
62 | #define E21_ASIC 0x10 | |
63 | #define E21_MEM_ENABLE 0x10 | |
64 | #define E21_MEM_ON 0x05 /* Enable memory in 16 bit mode. */ | |
65 | #define E21_MEM_ON_8 0x07 /* Enable memory in 8 bit mode. */ | |
66 | #define E21_MEM_BASE 0x11 | |
67 | #define E21_IRQ_LOW 0x12 /* The low three bits of the IRQ number. */ | |
68 | #define E21_IRQ_HIGH 0x14 /* The high IRQ bit and media select ... */ | |
69 | #define E21_MEDIA 0x14 /* (alias). */ | |
70 | #define E21_ALT_IFPORT 0x02 /* Set to use the other (BNC,AUI) port. */ | |
71 | #define E21_BIG_MEM 0x04 /* Use a bigger (64K) buffer (we don't) */ | |
72 | #define E21_SAPROM 0x10 /* Offset to station address data. */ | |
73 | #define E21_IO_EXTENT 0x20 | |
74 | ||
75 | static inline void mem_on(short port, volatile char __iomem *mem_base, | |
76 | unsigned char start_page ) | |
77 | { | |
78 | /* This is a little weird: set the shared memory window by doing a | |
79 | read. The low address bits specify the starting page. */ | |
80 | readb(mem_base+start_page); | |
81 | inb(port + E21_MEM_ENABLE); | |
82 | outb(E21_MEM_ON, port + E21_MEM_ENABLE + E21_MEM_ON); | |
83 | } | |
84 | ||
85 | static inline void mem_off(short port) | |
86 | { | |
87 | inb(port + E21_MEM_ENABLE); | |
88 | outb(0x00, port + E21_MEM_ENABLE); | |
89 | } | |
90 | ||
91 | /* In other drivers I put the TX pages first, but the E2100 window circuitry | |
92 | is designed to have a 4K Tx region last. The windowing circuitry wraps the | |
93 | window at 0x2fff->0x0000 so that the packets at e.g. 0x2f00 in the RX ring | |
94 | appear contiguously in the window. */ | |
95 | #define E21_RX_START_PG 0x00 /* First page of RX buffer */ | |
96 | #define E21_RX_STOP_PG 0x30 /* Last page +1 of RX ring */ | |
97 | #define E21_BIG_RX_STOP_PG 0xF0 /* Last page +1 of RX ring */ | |
98 | #define E21_TX_START_PG E21_RX_STOP_PG /* First page of TX buffer */ | |
99 | ||
100 | static int e21_probe1(struct net_device *dev, int ioaddr); | |
101 | ||
102 | static int e21_open(struct net_device *dev); | |
103 | static void e21_reset_8390(struct net_device *dev); | |
104 | static void e21_block_input(struct net_device *dev, int count, | |
105 | struct sk_buff *skb, int ring_offset); | |
106 | static void e21_block_output(struct net_device *dev, int count, | |
107 | const unsigned char *buf, int start_page); | |
108 | static void e21_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, | |
109 | int ring_page); | |
8284abea | 110 | static int e21_open(struct net_device *dev); |
1da177e4 LT |
111 | static int e21_close(struct net_device *dev); |
112 | ||
6aa20a22 | 113 | |
1da177e4 LT |
114 | /* Probe for the E2100 series ethercards. These cards have an 8390 at the |
115 | base address and the station address at both offset 0x10 and 0x18. I read | |
116 | the station address from offset 0x18 to avoid the dataport of NE2000 | |
117 | ethercards, and look for Ctron's unique ID (first three octets of the | |
118 | station address). | |
119 | */ | |
120 | ||
121 | static int __init do_e2100_probe(struct net_device *dev) | |
122 | { | |
123 | int *port; | |
124 | int base_addr = dev->base_addr; | |
125 | int irq = dev->irq; | |
126 | ||
1da177e4 LT |
127 | if (base_addr > 0x1ff) /* Check a single specified location. */ |
128 | return e21_probe1(dev, base_addr); | |
129 | else if (base_addr != 0) /* Don't probe at all. */ | |
130 | return -ENXIO; | |
131 | ||
132 | for (port = e21_probe_list; *port; port++) { | |
133 | dev->irq = irq; | |
134 | if (e21_probe1(dev, *port) == 0) | |
135 | return 0; | |
136 | } | |
137 | ||
138 | return -ENODEV; | |
139 | } | |
140 | ||
1da177e4 LT |
141 | #ifndef MODULE |
142 | struct net_device * __init e2100_probe(int unit) | |
143 | { | |
144 | struct net_device *dev = alloc_ei_netdev(); | |
145 | int err; | |
146 | ||
147 | if (!dev) | |
148 | return ERR_PTR(-ENOMEM); | |
149 | ||
150 | sprintf(dev->name, "eth%d", unit); | |
151 | netdev_boot_setup_check(dev); | |
152 | ||
153 | err = do_e2100_probe(dev); | |
154 | if (err) | |
155 | goto out; | |
1da177e4 | 156 | return dev; |
1da177e4 LT |
157 | out: |
158 | free_netdev(dev); | |
159 | return ERR_PTR(err); | |
160 | } | |
161 | #endif | |
162 | ||
8284abea SH |
163 | static const struct net_device_ops e21_netdev_ops = { |
164 | .ndo_open = e21_open, | |
165 | .ndo_stop = e21_close, | |
166 | ||
167 | .ndo_start_xmit = ei_start_xmit, | |
168 | .ndo_tx_timeout = ei_tx_timeout, | |
169 | .ndo_get_stats = ei_get_stats, | |
170 | .ndo_set_multicast_list = ei_set_multicast_list, | |
171 | .ndo_validate_addr = eth_validate_addr, | |
172 | .ndo_change_mtu = eth_change_mtu, | |
173 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
174 | .ndo_poll_controller = ei_poll, | |
175 | #endif | |
176 | }; | |
177 | ||
1da177e4 LT |
178 | static int __init e21_probe1(struct net_device *dev, int ioaddr) |
179 | { | |
180 | int i, status, retval; | |
181 | unsigned char *station_addr = dev->dev_addr; | |
182 | static unsigned version_printed; | |
183 | ||
184 | if (!request_region(ioaddr, E21_IO_EXTENT, DRV_NAME)) | |
185 | return -EBUSY; | |
186 | ||
187 | /* First check the station address for the Ctron prefix. */ | |
188 | if (inb(ioaddr + E21_SAPROM + 0) != 0x00 | |
189 | || inb(ioaddr + E21_SAPROM + 1) != 0x00 | |
190 | || inb(ioaddr + E21_SAPROM + 2) != 0x1d) { | |
191 | retval = -ENODEV; | |
192 | goto out; | |
193 | } | |
194 | ||
195 | /* Verify by making certain that there is a 8390 at there. */ | |
196 | outb(E8390_NODMA + E8390_STOP, ioaddr); | |
197 | udelay(1); /* we want to delay one I/O cycle - which is 2MHz */ | |
198 | status = inb(ioaddr); | |
199 | if (status != 0x21 && status != 0x23) { | |
200 | retval = -ENODEV; | |
201 | goto out; | |
202 | } | |
203 | ||
204 | /* Read the station address PROM. */ | |
205 | for (i = 0; i < 6; i++) | |
206 | station_addr[i] = inb(ioaddr + E21_SAPROM + i); | |
207 | ||
208 | inb(ioaddr + E21_MEDIA); /* Point to media selection. */ | |
209 | outb(0, ioaddr + E21_ASIC); /* and disable the secondary interface. */ | |
210 | ||
211 | if (ei_debug && version_printed++ == 0) | |
212 | printk(version); | |
213 | ||
214 | for (i = 0; i < 6; i++) | |
215 | printk(" %02X", station_addr[i]); | |
216 | ||
217 | if (dev->irq < 2) { | |
218 | int irqlist[] = {15,11,10,12,5,9,3,4}, i; | |
219 | for (i = 0; i < 8; i++) | |
220 | if (request_irq (irqlist[i], NULL, 0, "bogus", NULL) != -EBUSY) { | |
221 | dev->irq = irqlist[i]; | |
222 | break; | |
223 | } | |
224 | if (i >= 8) { | |
225 | printk(" unable to get IRQ %d.\n", dev->irq); | |
226 | retval = -EAGAIN; | |
227 | goto out; | |
228 | } | |
229 | } else if (dev->irq == 2) /* Fixup luser bogosity: IRQ2 is really IRQ9 */ | |
230 | dev->irq = 9; | |
231 | ||
232 | /* The 8390 is at the base address. */ | |
233 | dev->base_addr = ioaddr; | |
234 | ||
235 | ei_status.name = "E2100"; | |
236 | ei_status.word16 = 1; | |
237 | ei_status.tx_start_page = E21_TX_START_PG; | |
238 | ei_status.rx_start_page = E21_RX_START_PG; | |
239 | ei_status.stop_page = E21_RX_STOP_PG; | |
240 | ei_status.saved_irq = dev->irq; | |
241 | ||
242 | /* Check the media port used. The port can be passed in on the | |
243 | low mem_end bits. */ | |
244 | if (dev->mem_end & 15) | |
245 | dev->if_port = dev->mem_end & 7; | |
246 | else { | |
247 | dev->if_port = 0; | |
248 | inb(ioaddr + E21_MEDIA); /* Turn automatic media detection on. */ | |
249 | for(i = 0; i < 6; i++) | |
250 | if (station_addr[i] != inb(ioaddr + E21_SAPROM + 8 + i)) { | |
251 | dev->if_port = 1; | |
252 | break; | |
253 | } | |
254 | } | |
255 | ||
256 | /* Never map in the E21 shared memory unless you are actively using it. | |
257 | Also, the shared memory has effective only one setting -- spread all | |
258 | over the 128K region! */ | |
259 | if (dev->mem_start == 0) | |
260 | dev->mem_start = 0xd0000; | |
261 | ||
262 | ei_status.mem = ioremap(dev->mem_start, 2*1024); | |
263 | if (!ei_status.mem) { | |
264 | printk("unable to remap memory\n"); | |
265 | retval = -EAGAIN; | |
266 | goto out; | |
267 | } | |
268 | ||
269 | #ifdef notdef | |
270 | /* These values are unused. The E2100 has a 2K window into the packet | |
271 | buffer. The window can be set to start on any page boundary. */ | |
272 | ei_status.rmem_start = dev->mem_start + TX_PAGES*256; | |
273 | dev->mem_end = ei_status.rmem_end = dev->mem_start + 2*1024; | |
274 | #endif | |
275 | ||
276 | printk(", IRQ %d, %s media, memory @ %#lx.\n", dev->irq, | |
277 | dev->if_port ? "secondary" : "primary", dev->mem_start); | |
278 | ||
279 | ei_status.reset_8390 = &e21_reset_8390; | |
280 | ei_status.block_input = &e21_block_input; | |
281 | ei_status.block_output = &e21_block_output; | |
282 | ei_status.get_8390_hdr = &e21_get_8390_hdr; | |
8284abea SH |
283 | |
284 | dev->netdev_ops = &e21_netdev_ops; | |
1da177e4 LT |
285 | NS8390_init(dev, 0); |
286 | ||
b1fc5505 HX |
287 | retval = register_netdev(dev); |
288 | if (retval) | |
289 | goto out; | |
1da177e4 LT |
290 | return 0; |
291 | out: | |
292 | release_region(ioaddr, E21_IO_EXTENT); | |
293 | return retval; | |
294 | } | |
295 | ||
296 | static int | |
297 | e21_open(struct net_device *dev) | |
298 | { | |
299 | short ioaddr = dev->base_addr; | |
300 | int retval; | |
301 | ||
302 | if ((retval = request_irq(dev->irq, ei_interrupt, 0, dev->name, dev))) | |
303 | return retval; | |
304 | ||
305 | /* Set the interrupt line and memory base on the hardware. */ | |
306 | inb(ioaddr + E21_IRQ_LOW); | |
307 | outb(0, ioaddr + E21_ASIC + (dev->irq & 7)); | |
308 | inb(ioaddr + E21_IRQ_HIGH); /* High IRQ bit, and if_port. */ | |
309 | outb(0, ioaddr + E21_ASIC + (dev->irq > 7 ? 1:0) | |
310 | + (dev->if_port ? E21_ALT_IFPORT : 0)); | |
311 | inb(ioaddr + E21_MEM_BASE); | |
312 | outb(0, ioaddr + E21_ASIC + ((dev->mem_start >> 17) & 7)); | |
313 | ||
314 | ei_open(dev); | |
315 | return 0; | |
316 | } | |
317 | ||
318 | static void | |
319 | e21_reset_8390(struct net_device *dev) | |
320 | { | |
321 | short ioaddr = dev->base_addr; | |
322 | ||
323 | outb(0x01, ioaddr); | |
324 | if (ei_debug > 1) printk("resetting the E2180x3 t=%ld...", jiffies); | |
325 | ei_status.txing = 0; | |
326 | ||
327 | /* Set up the ASIC registers, just in case something changed them. */ | |
328 | ||
329 | if (ei_debug > 1) printk("reset done\n"); | |
330 | return; | |
331 | } | |
332 | ||
333 | /* Grab the 8390 specific header. We put the 2k window so the header page | |
334 | appears at the start of the shared memory. */ | |
335 | ||
336 | static void | |
337 | e21_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page) | |
338 | { | |
339 | ||
340 | short ioaddr = dev->base_addr; | |
341 | char __iomem *shared_mem = ei_status.mem; | |
342 | ||
343 | mem_on(ioaddr, shared_mem, ring_page); | |
344 | ||
345 | #ifdef notdef | |
346 | /* Officially this is what we are doing, but the readl() is faster */ | |
347 | memcpy_fromio(hdr, shared_mem, sizeof(struct e8390_pkt_hdr)); | |
348 | #else | |
349 | ((unsigned int*)hdr)[0] = readl(shared_mem); | |
350 | #endif | |
351 | ||
352 | /* Turn off memory access: we would need to reprogram the window anyway. */ | |
353 | mem_off(ioaddr); | |
354 | ||
355 | } | |
356 | ||
357 | /* Block input and output are easy on shared memory ethercards. | |
358 | The E21xx makes block_input() especially easy by wrapping the top | |
359 | ring buffer to the bottom automatically. */ | |
360 | static void | |
361 | e21_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset) | |
362 | { | |
363 | short ioaddr = dev->base_addr; | |
364 | char __iomem *shared_mem = ei_status.mem; | |
365 | ||
366 | mem_on(ioaddr, shared_mem, (ring_offset>>8)); | |
367 | ||
4ec03116 | 368 | memcpy_fromio(skb->data, ei_status.mem + (ring_offset & 0xff), count); |
1da177e4 LT |
369 | |
370 | mem_off(ioaddr); | |
371 | } | |
372 | ||
373 | static void | |
374 | e21_block_output(struct net_device *dev, int count, const unsigned char *buf, | |
375 | int start_page) | |
376 | { | |
377 | short ioaddr = dev->base_addr; | |
378 | volatile char __iomem *shared_mem = ei_status.mem; | |
379 | ||
380 | /* Set the shared memory window start by doing a read, with the low address | |
381 | bits specifying the starting page. */ | |
382 | readb(shared_mem + start_page); | |
383 | mem_on(ioaddr, shared_mem, start_page); | |
384 | ||
385 | memcpy_toio(shared_mem, buf, count); | |
386 | mem_off(ioaddr); | |
387 | } | |
388 | ||
389 | static int | |
390 | e21_close(struct net_device *dev) | |
391 | { | |
392 | short ioaddr = dev->base_addr; | |
393 | ||
394 | if (ei_debug > 1) | |
395 | printk("%s: Shutting down ethercard.\n", dev->name); | |
396 | ||
397 | free_irq(dev->irq, dev); | |
398 | dev->irq = ei_status.saved_irq; | |
399 | ||
400 | /* Shut off the interrupt line and secondary interface. */ | |
401 | inb(ioaddr + E21_IRQ_LOW); | |
402 | outb(0, ioaddr + E21_ASIC); | |
403 | inb(ioaddr + E21_IRQ_HIGH); /* High IRQ bit, and if_port. */ | |
404 | outb(0, ioaddr + E21_ASIC); | |
405 | ||
406 | ei_close(dev); | |
407 | ||
408 | /* Double-check that the memory has been turned off, because really | |
409 | really bad things happen if it isn't. */ | |
410 | mem_off(ioaddr); | |
411 | ||
412 | return 0; | |
413 | } | |
414 | ||
6aa20a22 | 415 | |
1da177e4 LT |
416 | #ifdef MODULE |
417 | #define MAX_E21_CARDS 4 /* Max number of E21 cards per module */ | |
418 | static struct net_device *dev_e21[MAX_E21_CARDS]; | |
419 | static int io[MAX_E21_CARDS]; | |
420 | static int irq[MAX_E21_CARDS]; | |
421 | static int mem[MAX_E21_CARDS]; | |
422 | static int xcvr[MAX_E21_CARDS]; /* choose int. or ext. xcvr */ | |
423 | ||
424 | module_param_array(io, int, NULL, 0); | |
425 | module_param_array(irq, int, NULL, 0); | |
426 | module_param_array(mem, int, NULL, 0); | |
427 | module_param_array(xcvr, int, NULL, 0); | |
428 | MODULE_PARM_DESC(io, "I/O base address(es)"); | |
429 | MODULE_PARM_DESC(irq, "IRQ number(s)"); | |
430 | MODULE_PARM_DESC(mem, " memory base address(es)"); | |
431 | MODULE_PARM_DESC(xcvr, "transceiver(s) (0=internal, 1=external)"); | |
432 | MODULE_DESCRIPTION("Cabletron E2100 ISA ethernet driver"); | |
433 | MODULE_LICENSE("GPL"); | |
434 | ||
435 | /* This is set up so that only a single autoprobe takes place per call. | |
436 | ISA device autoprobes on a running machine are not recommended. */ | |
d543cbb6 AM |
437 | |
438 | int __init init_module(void) | |
1da177e4 LT |
439 | { |
440 | struct net_device *dev; | |
441 | int this_dev, found = 0; | |
442 | ||
443 | for (this_dev = 0; this_dev < MAX_E21_CARDS; this_dev++) { | |
444 | if (io[this_dev] == 0) { | |
445 | if (this_dev != 0) break; /* only autoprobe 1st one */ | |
446 | printk(KERN_NOTICE "e2100.c: Presently autoprobing (not recommended) for a single card.\n"); | |
447 | } | |
448 | dev = alloc_ei_netdev(); | |
449 | if (!dev) | |
450 | break; | |
451 | dev->irq = irq[this_dev]; | |
452 | dev->base_addr = io[this_dev]; | |
453 | dev->mem_start = mem[this_dev]; | |
454 | dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */ | |
455 | if (do_e2100_probe(dev) == 0) { | |
b1fc5505 HX |
456 | dev_e21[found++] = dev; |
457 | continue; | |
1da177e4 LT |
458 | } |
459 | free_netdev(dev); | |
460 | printk(KERN_WARNING "e2100.c: No E2100 card found (i/o = 0x%x).\n", io[this_dev]); | |
461 | break; | |
462 | } | |
463 | if (found) | |
464 | return 0; | |
465 | return -ENXIO; | |
466 | } | |
467 | ||
64916f1e DV |
468 | static void cleanup_card(struct net_device *dev) |
469 | { | |
470 | /* NB: e21_close() handles free_irq */ | |
471 | iounmap(ei_status.mem); | |
472 | release_region(dev->base_addr, E21_IO_EXTENT); | |
473 | } | |
474 | ||
afc8eb46 | 475 | void __exit |
1da177e4 LT |
476 | cleanup_module(void) |
477 | { | |
478 | int this_dev; | |
479 | ||
480 | for (this_dev = 0; this_dev < MAX_E21_CARDS; this_dev++) { | |
481 | struct net_device *dev = dev_e21[this_dev]; | |
482 | if (dev) { | |
483 | unregister_netdev(dev); | |
484 | cleanup_card(dev); | |
485 | free_netdev(dev); | |
486 | } | |
487 | } | |
488 | } | |
489 | #endif /* MODULE */ |