File: /usr/src/linux/drivers/net/3c503.c
1 /* 3c503.c: A shared-memory NS8390 ethernet driver for linux. */
2 /*
3 Written 1992-94 by Donald Becker.
4
5 Copyright 1993 United States Government as represented by the
6 Director, National Security Agency. This software may be used and
7 distributed according to the terms of the GNU General Public License,
8 incorporated herein by reference.
9
10 The author may be reached as becker@scyld.com, or C/O
11 Scyld Computing Corporation
12 410 Severn Ave., Suite 210
13 Annapolis MD 21403
14
15
16 This driver should work with the 3c503 and 3c503/16. It should be used
17 in shared memory mode for best performance, although it may also work
18 in programmed-I/O mode.
19
20 Sources:
21 EtherLink II Technical Reference Manual,
22 EtherLink II/16 Technical Reference Manual Supplement,
23 3Com Corporation, 5400 Bayfront Plaza, Santa Clara CA 95052-8145
24
25 The Crynwr 3c503 packet driver.
26
27 Changelog:
28
29 Paul Gortmaker : add support for the 2nd 8kB of RAM on 16 bit cards.
30 Paul Gortmaker : multiple card support for module users.
31 rjohnson@analogic.com : Fix up PIO interface for efficient operation.
32
33 */
34
35 static const char version[] =
36 "3c503.c:v1.10 9/23/93 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
37
38 #include <linux/module.h>
39
40 #include <linux/kernel.h>
41 #include <linux/sched.h>
42 #include <linux/errno.h>
43 #include <linux/string.h>
44 #include <linux/delay.h>
45 #include <linux/netdevice.h>
46 #include <linux/etherdevice.h>
47 #include <linux/init.h>
48
49 #include <asm/io.h>
50 #include <asm/system.h>
51 #include <asm/byteorder.h>
52
53 #include "8390.h"
54 #include "3c503.h"
55 #define WRD_COUNT 4
56
57 int el2_probe(struct net_device *dev);
58 static int el2_pio_probe(struct net_device *dev);
59 static int el2_probe1(struct net_device *dev, int ioaddr);
60
61 /* A zero-terminated list of I/O addresses to be probed in PIO mode. */
62 static unsigned int netcard_portlist[] __initdata =
63 { 0x300,0x310,0x330,0x350,0x250,0x280,0x2a0,0x2e0,0};
64
65 #define EL2_IO_EXTENT 16
66
67 static int el2_open(struct net_device *dev);
68 static int el2_close(struct net_device *dev);
69 static void el2_reset_8390(struct net_device *dev);
70 static void el2_init_card(struct net_device *dev);
71 static void el2_block_output(struct net_device *dev, int count,
72 const unsigned char *buf, int start_page);
73 static void el2_block_input(struct net_device *dev, int count, struct sk_buff *skb,
74 int ring_offset);
75 static void el2_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
76 int ring_page);
77
78
79 /* This routine probes for a memory-mapped 3c503 board by looking for
80 the "location register" at the end of the jumpered boot PROM space.
81 This works even if a PROM isn't there.
82
83 If the ethercard isn't found there is an optional probe for
84 ethercard jumpered to programmed-I/O mode.
85 */
86 int __init
87 el2_probe(struct net_device *dev)
88 {
89 int *addr, addrs[] = { 0xddffe, 0xd9ffe, 0xcdffe, 0xc9ffe, 0};
90 int base_addr = dev->base_addr;
91
92 SET_MODULE_OWNER(dev);
93
94 if (base_addr > 0x1ff) /* Check a single specified location. */
95 return el2_probe1(dev, base_addr);
96 else if (base_addr != 0) /* Don't probe at all. */
97 return -ENXIO;
98
99 for (addr = addrs; *addr; addr++) {
100 int i;
101 unsigned int base_bits = isa_readb(*addr);
102 /* Find first set bit. */
103 for(i = 7; i >= 0; i--, base_bits >>= 1)
104 if (base_bits & 0x1)
105 break;
106 if (base_bits != 1)
107 continue;
108 if (el2_probe1(dev, netcard_portlist[i]) == 0)
109 return 0;
110 }
111 #if ! defined(no_probe_nonshared_memory)
112 return el2_pio_probe(dev);
113 #else
114 return -ENODEV;
115 #endif
116 }
117
118 /* Try all of the locations that aren't obviously empty. This touches
119 a lot of locations, and is much riskier than the code above. */
120 static int __init
121 el2_pio_probe(struct net_device *dev)
122 {
123 int i;
124 int base_addr = dev ? dev->base_addr : 0;
125
126 if (base_addr > 0x1ff) /* Check a single specified location. */
127 return el2_probe1(dev, base_addr);
128 else if (base_addr != 0) /* Don't probe at all. */
129 return -ENXIO;
130
131 for (i = 0; netcard_portlist[i]; i++)
132 if (el2_probe1(dev, netcard_portlist[i]) == 0)
133 return 0;
134
135 return -ENODEV;
136 }
137
138 /* Probe for the Etherlink II card at I/O port base IOADDR,
139 returning non-zero on success. If found, set the station
140 address and memory parameters in DEVICE. */
141 static int __init
142 el2_probe1(struct net_device *dev, int ioaddr)
143 {
144 int i, iobase_reg, membase_reg, saved_406, wordlength, retval;
145 static unsigned version_printed;
146 unsigned long vendor_id;
147
148 /* FIXME: code reads ioaddr + 0x400, we request ioaddr + 16 */
149 if (!request_region(ioaddr, EL2_IO_EXTENT, dev->name))
150 return -EBUSY;
151
152 /* Reset and/or avoid any lurking NE2000 */
153 if (inb(ioaddr + 0x408) == 0xff) {
154 mdelay(1);
155 retval = -ENODEV;
156 goto out;
157 }
158
159 /* We verify that it's a 3C503 board by checking the first three octets
160 of its ethernet address. */
161 iobase_reg = inb(ioaddr+0x403);
162 membase_reg = inb(ioaddr+0x404);
163 /* ASIC location registers should be 0 or have only a single bit set. */
164 if ( (iobase_reg & (iobase_reg - 1))
165 || (membase_reg & (membase_reg - 1))) {
166 retval = -ENODEV;
167 goto out;
168 }
169 saved_406 = inb_p(ioaddr + 0x406);
170 outb_p(ECNTRL_RESET|ECNTRL_THIN, ioaddr + 0x406); /* Reset it... */
171 outb_p(ECNTRL_THIN, ioaddr + 0x406);
172 /* Map the station addr PROM into the lower I/O ports. We now check
173 for both the old and new 3Com prefix */
174 outb(ECNTRL_SAPROM|ECNTRL_THIN, ioaddr + 0x406);
175 vendor_id = inb(ioaddr)*0x10000 + inb(ioaddr + 1)*0x100 + inb(ioaddr + 2);
176 if ((vendor_id != OLD_3COM_ID) && (vendor_id != NEW_3COM_ID)) {
177 /* Restore the register we frobbed. */
178 outb(saved_406, ioaddr + 0x406);
179 retval = -ENODEV;
180 goto out;
181 }
182
183 if (ei_debug && version_printed++ == 0)
184 printk(version);
185
186 dev->base_addr = ioaddr;
187 /* Allocate dev->priv and fill in 8390 specific dev fields. */
188 if (ethdev_init(dev)) {
189 printk ("3c503: unable to allocate memory for dev->priv.\n");
190 retval = -ENOMEM;
191 goto out;
192 }
193
194 printk("%s: 3c503 at i/o base %#3x, node ", dev->name, ioaddr);
195
196 /* Retrieve and print the ethernet address. */
197 for (i = 0; i < 6; i++)
198 printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i));
199
200 /* Map the 8390 back into the window. */
201 outb(ECNTRL_THIN, ioaddr + 0x406);
202
203 /* Check for EL2/16 as described in tech. man. */
204 outb_p(E8390_PAGE0, ioaddr + E8390_CMD);
205 outb_p(0, ioaddr + EN0_DCFG);
206 outb_p(E8390_PAGE2, ioaddr + E8390_CMD);
207 wordlength = inb_p(ioaddr + EN0_DCFG) & ENDCFG_WTS;
208 outb_p(E8390_PAGE0, ioaddr + E8390_CMD);
209
210 /* Probe for, turn on and clear the board's shared memory. */
211 if (ei_debug > 2) printk(" memory jumpers %2.2x ", membase_reg);
212 outb(EGACFR_NORM, ioaddr + 0x405); /* Enable RAM */
213
214 /* This should be probed for (or set via an ioctl()) at run-time.
215 Right now we use a sleazy hack to pass in the interface number
216 at boot-time via the low bits of the mem_end field. That value is
217 unused, and the low bits would be discarded even if it was used. */
218 #if defined(EI8390_THICK) || defined(EL2_AUI)
219 ei_status.interface_num = 1;
220 #else
221 ei_status.interface_num = dev->mem_end & 0xf;
222 #endif
223 printk(", using %sternal xcvr.\n", ei_status.interface_num == 0 ? "in" : "ex");
224
225 if ((membase_reg & 0xf0) == 0) {
226 dev->mem_start = 0;
227 ei_status.name = "3c503-PIO";
228 } else {
229 dev->mem_start = ((membase_reg & 0xc0) ? 0xD8000 : 0xC8000) +
230 ((membase_reg & 0xA0) ? 0x4000 : 0);
231
232 #define EL2_MEMSIZE (EL2_MB1_STOP_PG - EL2_MB1_START_PG)*256
233 #ifdef EL2MEMTEST
234 /* This has never found an error, but someone might care.
235 Note that it only tests the 2nd 8kB on 16kB 3c503/16
236 cards between card addr. 0x2000 and 0x3fff. */
237 { /* Check the card's memory. */
238 unsigned long mem_base = dev->mem_start;
239 unsigned int test_val = 0xbbadf00d;
240 isa_writel(0xba5eba5e, mem_base);
241 for (i = sizeof(test_val); i < EL2_MEMSIZE; i+=sizeof(test_val)) {
242 isa_writel(test_val, mem_base + i);
243 if (isa_readl(mem_base) != 0xba5eba5e
244 || isa_readl(mem_base + i) != test_val) {
245 printk("3c503: memory failure or memory address conflict.\n");
246 dev->mem_start = 0;
247 ei_status.name = "3c503-PIO";
248 break;
249 }
250 test_val += 0x55555555;
251 isa_writel(0, mem_base + i);
252 }
253 }
254 #endif /* EL2MEMTEST */
255
256 if (dev->mem_start)
257 dev->mem_end = dev->rmem_end = dev->mem_start + EL2_MEMSIZE;
258
259 if (wordlength) { /* No Tx pages to skip over to get to Rx */
260 dev->rmem_start = dev->mem_start;
261 ei_status.name = "3c503/16";
262 } else {
263 dev->rmem_start = TX_PAGES*256 + dev->mem_start;
264 ei_status.name = "3c503";
265 }
266 }
267
268 /*
269 Divide up the memory on the card. This is the same regardless of
270 whether shared-mem or PIO is used. For 16 bit cards (16kB RAM),
271 we use the entire 8k of bank1 for an Rx ring. We only use 3k
272 of the bank0 for 2 full size Tx packet slots. For 8 bit cards,
273 (8kB RAM) we use 3kB of bank1 for two Tx slots, and the remaining
274 5kB for an Rx ring. */
275
276 if (wordlength) {
277 ei_status.tx_start_page = EL2_MB0_START_PG;
278 ei_status.rx_start_page = EL2_MB1_START_PG;
279 } else {
280 ei_status.tx_start_page = EL2_MB1_START_PG;
281 ei_status.rx_start_page = EL2_MB1_START_PG + TX_PAGES;
282 }
283
284 /* Finish setting the board's parameters. */
285 ei_status.stop_page = EL2_MB1_STOP_PG;
286 ei_status.word16 = wordlength;
287 ei_status.reset_8390 = &el2_reset_8390;
288 ei_status.get_8390_hdr = &el2_get_8390_hdr;
289 ei_status.block_input = &el2_block_input;
290 ei_status.block_output = &el2_block_output;
291
292 if (dev->irq == 2)
293 dev->irq = 9;
294 else if (dev->irq > 5 && dev->irq != 9) {
295 printk("3c503: configured interrupt %d invalid, will use autoIRQ.\n",
296 dev->irq);
297 dev->irq = 0;
298 }
299
300 ei_status.saved_irq = dev->irq;
301
302 dev->open = &el2_open;
303 dev->stop = &el2_close;
304
305 if (dev->mem_start)
306 printk("%s: %s - %dkB RAM, 8kB shared mem window at %#6lx-%#6lx.\n",
307 dev->name, ei_status.name, (wordlength+1)<<3,
308 dev->mem_start, dev->mem_end-1);
309
310 else
311 {
312 ei_status.tx_start_page = EL2_MB1_START_PG;
313 ei_status.rx_start_page = EL2_MB1_START_PG + TX_PAGES;
314 printk("\n%s: %s, %dkB RAM, using programmed I/O (REJUMPER for SHARED MEMORY).\n",
315 dev->name, ei_status.name, (wordlength+1)<<3);
316 }
317 return 0;
318 out:
319 release_region(ioaddr, EL2_IO_EXTENT);
320 return retval;
321 }
322
323 static int
324 el2_open(struct net_device *dev)
325 {
326 int retval = -EAGAIN;
327
328 if (dev->irq < 2) {
329 int irqlist[] = {5, 9, 3, 4, 0};
330 int *irqp = irqlist;
331
332 outb(EGACFR_NORM, E33G_GACFR); /* Enable RAM and interrupts. */
333 do {
334 if (request_irq (*irqp, NULL, 0, "bogus", dev) != -EBUSY) {
335 /* Twinkle the interrupt, and check if it's seen. */
336 unsigned long cookie = probe_irq_on();
337 outb_p(0x04 << ((*irqp == 9) ? 2 : *irqp), E33G_IDCFR);
338 outb_p(0x00, E33G_IDCFR);
339 if (*irqp == probe_irq_off(cookie) /* It's a good IRQ line! */
340 && ((retval = request_irq(dev->irq = *irqp,
341 ei_interrupt, 0, dev->name, dev)) == 0))
342 break;
343 }
344 } while (*++irqp);
345 if (*irqp == 0) {
346 outb(EGACFR_IRQOFF, E33G_GACFR); /* disable interrupts. */
347 return retval;
348 }
349 } else {
350 if ((retval = request_irq(dev->irq, ei_interrupt, 0, dev->name, dev))) {
351 return retval;
352 }
353 }
354
355 el2_init_card(dev);
356 ei_open(dev);
357 return 0;
358 }
359
360 static int
361 el2_close(struct net_device *dev)
362 {
363 free_irq(dev->irq, dev);
364 dev->irq = ei_status.saved_irq;
365 outb(EGACFR_IRQOFF, E33G_GACFR); /* disable interrupts. */
366
367 ei_close(dev);
368 return 0;
369 }
370
371 /* This is called whenever we have a unrecoverable failure:
372 transmit timeout
373 Bad ring buffer packet header
374 */
375 static void
376 el2_reset_8390(struct net_device *dev)
377 {
378 if (ei_debug > 1) {
379 printk("%s: Resetting the 3c503 board...", dev->name);
380 printk("%#lx=%#02x %#lx=%#02x %#lx=%#02x...", E33G_IDCFR, inb(E33G_IDCFR),
381 E33G_CNTRL, inb(E33G_CNTRL), E33G_GACFR, inb(E33G_GACFR));
382 }
383 outb_p(ECNTRL_RESET|ECNTRL_THIN, E33G_CNTRL);
384 ei_status.txing = 0;
385 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
386 el2_init_card(dev);
387 if (ei_debug > 1) printk("done\n");
388 }
389
390 /* Initialize the 3c503 GA registers after a reset. */
391 static void
392 el2_init_card(struct net_device *dev)
393 {
394 /* Unmap the station PROM and select the DIX or BNC connector. */
395 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
396
397 /* Set ASIC copy of rx's first and last+1 buffer pages */
398 /* These must be the same as in the 8390. */
399 outb(ei_status.rx_start_page, E33G_STARTPG);
400 outb(ei_status.stop_page, E33G_STOPPG);
401
402 /* Point the vector pointer registers somewhere ?harmless?. */
403 outb(0xff, E33G_VP2); /* Point at the ROM restart location 0xffff0 */
404 outb(0xff, E33G_VP1);
405 outb(0x00, E33G_VP0);
406 /* Turn off all interrupts until we're opened. */
407 outb_p(0x00, dev->base_addr + EN0_IMR);
408 /* Enable IRQs iff started. */
409 outb(EGACFR_NORM, E33G_GACFR);
410
411 /* Set the interrupt line. */
412 outb_p((0x04 << (dev->irq == 9 ? 2 : dev->irq)), E33G_IDCFR);
413 outb_p((WRD_COUNT << 1), E33G_DRQCNT); /* Set burst size to 8 */
414 outb_p(0x20, E33G_DMAAH); /* Put a valid addr in the GA DMA */
415 outb_p(0x00, E33G_DMAAL);
416 return; /* We always succeed */
417 }
418
419 /*
420 * Either use the shared memory (if enabled on the board) or put the packet
421 * out through the ASIC FIFO.
422 */
423 static void
424 el2_block_output(struct net_device *dev, int count,
425 const unsigned char *buf, int start_page)
426 {
427 unsigned short int *wrd;
428 int boguscount; /* timeout counter */
429 unsigned short word; /* temporary for better machine code */
430
431 if (ei_status.word16) /* Tx packets go into bank 0 on EL2/16 card */
432 outb(EGACFR_RSEL|EGACFR_TCM, E33G_GACFR);
433 else
434 outb(EGACFR_NORM, E33G_GACFR);
435
436 if (dev->mem_start) { /* Shared memory transfer */
437 unsigned long dest_addr = dev->mem_start +
438 ((start_page - ei_status.tx_start_page) << 8);
439 isa_memcpy_toio(dest_addr, buf, count);
440 outb(EGACFR_NORM, E33G_GACFR); /* Back to bank1 in case on bank0 */
441 return;
442 }
443
444 /*
445 * No shared memory, put the packet out the other way.
446 * Set up then start the internal memory transfer to Tx Start Page
447 */
448
449 word = (unsigned short)start_page;
450 outb(word&0xFF, E33G_DMAAH);
451 outb(word>>8, E33G_DMAAL);
452
453 outb_p((ei_status.interface_num ? ECNTRL_AUI : ECNTRL_THIN ) | ECNTRL_OUTPUT
454 | ECNTRL_START, E33G_CNTRL);
455
456 /*
457 * Here I am going to write data to the FIFO as quickly as possible.
458 * Note that E33G_FIFOH is defined incorrectly. It is really
459 * E33G_FIFOL, the lowest port address for both the byte and
460 * word write. Variable 'count' is NOT checked. Caller must supply a
461 * valid count. Note that I may write a harmless extra byte to the
462 * 8390 if the byte-count was not even.
463 */
464 wrd = (unsigned short int *) buf;
465 count = (count + 1) >> 1;
466 for(;;)
467 {
468 boguscount = 0x1000;
469 while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
470 {
471 if(!boguscount--)
472 {
473 printk("%s: FIFO blocked in el2_block_output.\n", dev->name);
474 el2_reset_8390(dev);
475 goto blocked;
476 }
477 }
478 if(count > WRD_COUNT)
479 {
480 outsw(E33G_FIFOH, wrd, WRD_COUNT);
481 wrd += WRD_COUNT;
482 count -= WRD_COUNT;
483 }
484 else
485 {
486 outsw(E33G_FIFOH, wrd, count);
487 break;
488 }
489 }
490 blocked:;
491 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
492 return;
493 }
494
495 /* Read the 4 byte, page aligned 8390 specific header. */
496 static void
497 el2_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
498 {
499 int boguscount;
500 unsigned long hdr_start = dev->mem_start + ((ring_page - EL2_MB1_START_PG)<<8);
501 unsigned short word;
502
503 if (dev->mem_start) { /* Use the shared memory. */
504 isa_memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
505 return;
506 }
507
508 /*
509 * No shared memory, use programmed I/O.
510 */
511
512 word = (unsigned short)ring_page;
513 outb(word&0xFF, E33G_DMAAH);
514 outb(word>>8, E33G_DMAAL);
515
516 outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
517 | ECNTRL_START, E33G_CNTRL);
518 boguscount = 0x1000;
519 while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
520 {
521 if(!boguscount--)
522 {
523 printk("%s: FIFO blocked in el2_get_8390_hdr.\n", dev->name);
524 memset(hdr, 0x00, sizeof(struct e8390_pkt_hdr));
525 el2_reset_8390(dev);
526 goto blocked;
527 }
528 }
529 insw(E33G_FIFOH, hdr, (sizeof(struct e8390_pkt_hdr))>> 1);
530 blocked:;
531 outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
532 }
533
534
535 static void
536 el2_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
537 {
538 int boguscount = 0;
539 unsigned short int *buf;
540 unsigned short word;
541
542 int end_of_ring = dev->rmem_end;
543
544 /* Maybe enable shared memory just be to be safe... nahh.*/
545 if (dev->mem_start) { /* Use the shared memory. */
546 ring_offset -= (EL2_MB1_START_PG<<8);
547 if (dev->mem_start + ring_offset + count > end_of_ring) {
548 /* We must wrap the input move. */
549 int semi_count = end_of_ring - (dev->mem_start + ring_offset);
550 isa_memcpy_fromio(skb->data, dev->mem_start + ring_offset, semi_count);
551 count -= semi_count;
552 isa_memcpy_fromio(skb->data + semi_count, dev->rmem_start, count);
553 } else {
554 /* Packet is in one chunk -- we can copy + cksum. */
555 isa_eth_io_copy_and_sum(skb, dev->mem_start + ring_offset, count, 0);
556 }
557 return;
558 }
559
560 /*
561 * No shared memory, use programmed I/O.
562 */
563 word = (unsigned short) ring_offset;
564 outb(word>>8, E33G_DMAAH);
565 outb(word&0xFF, E33G_DMAAL);
566
567 outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
568 | ECNTRL_START, E33G_CNTRL);
569
570 /*
571 * Here I also try to get data as fast as possible. I am betting that I
572 * can read one extra byte without clobbering anything in the kernel because
573 * this would only occur on an odd byte-count and allocation of skb->data
574 * is word-aligned. Variable 'count' is NOT checked. Caller must check
575 * for a valid count.
576 * [This is currently quite safe.... but if one day the 3c503 explodes
577 * you know where to come looking ;)]
578 */
579
580 buf = (unsigned short int *) skb->data;
581 count = (count + 1) >> 1;
582 for(;;)
583 {
584 boguscount = 0x1000;
585 while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
586 {
587 if(!boguscount--)
588 {
589 printk("%s: FIFO blocked in el2_block_input.\n", dev->name);
590 el2_reset_8390(dev);
591 goto blocked;
592 }
593 }
594 if(count > WRD_COUNT)
595 {
596 insw(E33G_FIFOH, buf, WRD_COUNT);
597 buf += WRD_COUNT;
598 count -= WRD_COUNT;
599 }
600 else
601 {
602 insw(E33G_FIFOH, buf, count);
603 break;
604 }
605 }
606 blocked:;
607 outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
608 return;
609 }
610 #ifdef MODULE
611 #define MAX_EL2_CARDS 4 /* Max number of EL2 cards per module */
612
613 static struct net_device dev_el2[MAX_EL2_CARDS];
614 static int io[MAX_EL2_CARDS];
615 static int irq[MAX_EL2_CARDS];
616 static int xcvr[MAX_EL2_CARDS]; /* choose int. or ext. xcvr */
617 MODULE_PARM(io, "1-" __MODULE_STRING(MAX_EL2_CARDS) "i");
618 MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_EL2_CARDS) "i");
619 MODULE_PARM(xcvr, "1-" __MODULE_STRING(MAX_EL2_CARDS) "i");
620 MODULE_PARM_DESC(io, "EtherLink II I/O base address(es)");
621 MODULE_PARM_DESC(irq, "EtherLink II IRQ number(s) (assigned)");
622 MODULE_PARM_DESC(xcvr, "EtherLink II tranceiver(s) (0=internal, 1=external)");
623
624 /* This is set up so that only a single autoprobe takes place per call.
625 ISA device autoprobes on a running machine are not recommended. */
626 int
627 init_module(void)
628 {
629 int this_dev, found = 0;
630
631 for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) {
632 struct net_device *dev = &dev_el2[this_dev];
633 dev->irq = irq[this_dev];
634 dev->base_addr = io[this_dev];
635 dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */
636 dev->init = el2_probe;
637 if (io[this_dev] == 0) {
638 if (this_dev != 0) break; /* only autoprobe 1st one */
639 printk(KERN_NOTICE "3c503.c: Presently autoprobing (not recommended) for a single card.\n");
640 }
641 if (register_netdev(dev) != 0) {
642 printk(KERN_WARNING "3c503.c: No 3c503 card found (i/o = 0x%x).\n", io[this_dev]);
643 if (found != 0) { /* Got at least one. */
644 return 0;
645 }
646 return -ENXIO;
647 }
648 found++;
649 }
650 return 0;
651 }
652
653 void
654 cleanup_module(void)
655 {
656 int this_dev;
657
658 for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) {
659 struct net_device *dev = &dev_el2[this_dev];
660 if (dev->priv != NULL) {
661 void *priv = dev->priv;
662 /* NB: el2_close() handles free_irq */
663 release_region(dev->base_addr, EL2_IO_EXTENT);
664 unregister_netdev(dev);
665 kfree(priv);
666 }
667 }
668 }
669 #endif /* MODULE */
670
671 /*
672 * Local variables:
673 * version-control: t
674 * kept-new-versions: 5
675 * c-indent-level: 4
676 * End:
677 */
678