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