Linux Audio

Check our new training course

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