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