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