V4L/DVB (10353): gspca - some subdrivers: Don't get the control values from the webcam.
[linux/fpc-iii.git] / drivers / net / 3c501.c
blob1c5344aa57cc32473a0b019d7ab1205e3df2b9e0
1 /* 3c501.c: A 3Com 3c501 Ethernet driver for Linux. */
2 /*
3 Written 1992,1993,1994 Donald Becker
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.
10 This is a device driver for the 3Com Etherlink 3c501.
11 Do not purchase this card, even as a joke. It's performance is horrible,
12 and it breaks in many ways.
14 The original author may be reached as becker@scyld.com, or C/O
15 Scyld Computing Corporation
16 410 Severn Ave., Suite 210
17 Annapolis MD 21403
19 Fixed (again!) the missing interrupt locking on TX/RX shifting.
20 Alan Cox <alan@lxorguk.ukuu.org.uk>
22 Removed calls to init_etherdev since they are no longer needed, and
23 cleaned up modularization just a bit. The driver still allows only
24 the default address for cards when loaded as a module, but that's
25 really less braindead than anyone using a 3c501 board. :)
26 19950208 (invid@msen.com)
28 Added traps for interrupts hitting the window as we clear and TX load
29 the board. Now getting 150K/second FTP with a 3c501 card. Still playing
30 with a TX-TX optimisation to see if we can touch 180-200K/second as seems
31 theoretically maximum.
32 19950402 Alan Cox <alan@lxorguk.ukuu.org.uk>
34 Cleaned up for 2.3.x because we broke SMP now.
35 20000208 Alan Cox <alan@lxorguk.ukuu.org.uk>
37 Check up pass for 2.5. Nothing significant changed
38 20021009 Alan Cox <alan@lxorguk.ukuu.org.uk>
40 Fixed zero fill corner case
41 20030104 Alan Cox <alan@lxorguk.ukuu.org.uk>
44 For the avoidance of doubt the "preferred form" of this code is one which
45 is in an open non patent encumbered format. Where cryptographic key signing
46 forms part of the process of creating an executable the information
47 including keys needed to generate an equivalently functional executable
48 are deemed to be part of the source code.
53 /**
54 * DOC: 3c501 Card Notes
56 * Some notes on this thing if you have to hack it. [Alan]
58 * Some documentation is available from 3Com. Due to the boards age
59 * standard responses when you ask for this will range from 'be serious'
60 * to 'give it to a museum'. The documentation is incomplete and mostly
61 * of historical interest anyway.
63 * The basic system is a single buffer which can be used to receive or
64 * transmit a packet. A third command mode exists when you are setting
65 * things up.
67 * If it's transmitting it's not receiving and vice versa. In fact the
68 * time to get the board back into useful state after an operation is
69 * quite large.
71 * The driver works by keeping the board in receive mode waiting for a
72 * packet to arrive. When one arrives it is copied out of the buffer
73 * and delivered to the kernel. The card is reloaded and off we go.
75 * When transmitting lp->txing is set and the card is reset (from
76 * receive mode) [possibly losing a packet just received] to command
77 * mode. A packet is loaded and transmit mode triggered. The interrupt
78 * handler runs different code for transmit interrupts and can handle
79 * returning to receive mode or retransmissions (yes you have to help
80 * out with those too).
82 * DOC: Problems
84 * There are a wide variety of undocumented error returns from the card
85 * and you basically have to kick the board and pray if they turn up. Most
86 * only occur under extreme load or if you do something the board doesn't
87 * like (eg touching a register at the wrong time).
89 * The driver is less efficient than it could be. It switches through
90 * receive mode even if more transmits are queued. If this worries you buy
91 * a real Ethernet card.
93 * The combination of slow receive restart and no real multicast
94 * filter makes the board unusable with a kernel compiled for IP
95 * multicasting in a real multicast environment. That's down to the board,
96 * but even with no multicast programs running a multicast IP kernel is
97 * in group 224.0.0.1 and you will therefore be listening to all multicasts.
98 * One nv conference running over that Ethernet and you can give up.
102 #define DRV_NAME "3c501"
103 #define DRV_VERSION "2002/10/09"
106 static const char version[] =
107 DRV_NAME ".c: " DRV_VERSION " Alan Cox (alan@lxorguk.ukuu.org.uk).\n";
110 * Braindamage remaining:
111 * The 3c501 board.
114 #include <linux/module.h>
116 #include <linux/kernel.h>
117 #include <linux/fcntl.h>
118 #include <linux/ioport.h>
119 #include <linux/interrupt.h>
120 #include <linux/slab.h>
121 #include <linux/string.h>
122 #include <linux/errno.h>
123 #include <linux/spinlock.h>
124 #include <linux/ethtool.h>
125 #include <linux/delay.h>
126 #include <linux/bitops.h>
128 #include <asm/uaccess.h>
129 #include <asm/io.h>
131 #include <linux/netdevice.h>
132 #include <linux/etherdevice.h>
133 #include <linux/skbuff.h>
134 #include <linux/init.h>
136 #include "3c501.h"
139 * The boilerplate probe code.
142 static int io = 0x280;
143 static int irq = 5;
144 static int mem_start;
147 * el1_probe: - probe for a 3c501
148 * @dev: The device structure passed in to probe.
150 * This can be called from two places. The network layer will probe using
151 * a device structure passed in with the probe information completed. For a
152 * modular driver we use #init_module to fill in our own structure and probe
153 * for it.
155 * Returns 0 on success. ENXIO if asked not to probe and ENODEV if asked to
156 * probe and failing to find anything.
159 struct net_device * __init el1_probe(int unit)
161 struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
162 static unsigned ports[] = { 0x280, 0x300, 0};
163 unsigned *port;
164 int err = 0;
166 if (!dev)
167 return ERR_PTR(-ENOMEM);
169 if (unit >= 0) {
170 sprintf(dev->name, "eth%d", unit);
171 netdev_boot_setup_check(dev);
172 io = dev->base_addr;
173 irq = dev->irq;
174 mem_start = dev->mem_start & 7;
177 if (io > 0x1ff) { /* Check a single specified location. */
178 err = el1_probe1(dev, io);
179 } else if (io != 0) {
180 err = -ENXIO; /* Don't probe at all. */
181 } else {
182 for (port = ports; *port && el1_probe1(dev, *port); port++)
184 if (!*port)
185 err = -ENODEV;
187 if (err)
188 goto out;
189 err = register_netdev(dev);
190 if (err)
191 goto out1;
192 return dev;
193 out1:
194 release_region(dev->base_addr, EL1_IO_EXTENT);
195 out:
196 free_netdev(dev);
197 return ERR_PTR(err);
200 static const struct net_device_ops el_netdev_ops = {
201 .ndo_open = el_open,
202 .ndo_stop = el1_close,
203 .ndo_start_xmit = el_start_xmit,
204 .ndo_tx_timeout = el_timeout,
205 .ndo_set_multicast_list = set_multicast_list,
206 .ndo_change_mtu = eth_change_mtu,
207 .ndo_set_mac_address = eth_mac_addr,
208 .ndo_validate_addr = eth_validate_addr,
212 * el1_probe1:
213 * @dev: The device structure to use
214 * @ioaddr: An I/O address to probe at.
216 * The actual probe. This is iterated over by #el1_probe in order to
217 * check all the applicable device locations.
219 * Returns 0 for a success, in which case the device is activated,
220 * EAGAIN if the IRQ is in use by another driver, and ENODEV if the
221 * board cannot be found.
224 static int __init el1_probe1(struct net_device *dev, int ioaddr)
226 struct net_local *lp;
227 const char *mname; /* Vendor name */
228 unsigned char station_addr[6];
229 int autoirq = 0;
230 int i;
233 * Reserve I/O resource for exclusive use by this driver
236 if (!request_region(ioaddr, EL1_IO_EXTENT, DRV_NAME))
237 return -ENODEV;
240 * Read the station address PROM data from the special port.
243 for (i = 0; i < 6; i++) {
244 outw(i, ioaddr + EL1_DATAPTR);
245 station_addr[i] = inb(ioaddr + EL1_SAPROM);
248 * Check the first three octets of the S.A. for 3Com's prefix, or
249 * for the Sager NP943 prefix.
252 if (station_addr[0] == 0x02 && station_addr[1] == 0x60
253 && station_addr[2] == 0x8c)
254 mname = "3c501";
255 else if (station_addr[0] == 0x00 && station_addr[1] == 0x80
256 && station_addr[2] == 0xC8)
257 mname = "NP943";
258 else {
259 release_region(ioaddr, EL1_IO_EXTENT);
260 return -ENODEV;
264 * We auto-IRQ by shutting off the interrupt line and letting it
265 * float high.
268 dev->irq = irq;
270 if (dev->irq < 2) {
271 unsigned long irq_mask;
273 irq_mask = probe_irq_on();
274 inb(RX_STATUS); /* Clear pending interrupts. */
275 inb(TX_STATUS);
276 outb(AX_LOOP + 1, AX_CMD);
278 outb(0x00, AX_CMD);
280 mdelay(20);
281 autoirq = probe_irq_off(irq_mask);
283 if (autoirq == 0) {
284 printk(KERN_WARNING "%s probe at %#x failed to detect IRQ line.\n",
285 mname, ioaddr);
286 release_region(ioaddr, EL1_IO_EXTENT);
287 return -EAGAIN;
291 outb(AX_RESET+AX_LOOP, AX_CMD); /* Loopback mode. */
292 dev->base_addr = ioaddr;
293 memcpy(dev->dev_addr, station_addr, ETH_ALEN);
295 if (mem_start & 0xf)
296 el_debug = mem_start & 0x7;
297 if (autoirq)
298 dev->irq = autoirq;
300 printk(KERN_INFO "%s: %s EtherLink at %#lx, using %sIRQ %d.\n",
301 dev->name, mname, dev->base_addr,
302 autoirq ? "auto":"assigned ", dev->irq);
304 #ifdef CONFIG_IP_MULTICAST
305 printk(KERN_WARNING "WARNING: Use of the 3c501 in a multicast kernel is NOT recommended.\n");
306 #endif
308 if (el_debug)
309 printk(KERN_DEBUG "%s", version);
311 lp = netdev_priv(dev);
312 memset(lp, 0, sizeof(struct net_local));
313 spin_lock_init(&lp->lock);
316 * The EL1-specific entries in the device structure.
319 dev->netdev_ops = &el_netdev_ops;
320 dev->watchdog_timeo = HZ;
321 dev->ethtool_ops = &netdev_ethtool_ops;
322 return 0;
326 * el1_open:
327 * @dev: device that is being opened
329 * When an ifconfig is issued which changes the device flags to include
330 * IFF_UP this function is called. It is only called when the change
331 * occurs, not when the interface remains up. #el1_close will be called
332 * when it goes down.
334 * Returns 0 for a successful open, or -EAGAIN if someone has run off
335 * with our interrupt line.
338 static int el_open(struct net_device *dev)
340 int retval;
341 int ioaddr = dev->base_addr;
342 struct net_local *lp = netdev_priv(dev);
343 unsigned long flags;
345 if (el_debug > 2)
346 printk(KERN_DEBUG "%s: Doing el_open()...", dev->name);
348 retval = request_irq(dev->irq, &el_interrupt, 0, dev->name, dev);
349 if (retval)
350 return retval;
352 spin_lock_irqsave(&lp->lock, flags);
353 el_reset(dev);
354 spin_unlock_irqrestore(&lp->lock, flags);
356 lp->txing = 0; /* Board in RX mode */
357 outb(AX_RX, AX_CMD); /* Aux control, irq and receive enabled */
358 netif_start_queue(dev);
359 return 0;
363 * el_timeout:
364 * @dev: The 3c501 card that has timed out
366 * Attempt to restart the board. This is basically a mixture of extreme
367 * violence and prayer
371 static void el_timeout(struct net_device *dev)
373 struct net_local *lp = netdev_priv(dev);
374 int ioaddr = dev->base_addr;
376 if (el_debug)
377 printk(KERN_DEBUG "%s: transmit timed out, txsr %#2x axsr=%02x rxsr=%02x.\n",
378 dev->name, inb(TX_STATUS),
379 inb(AX_STATUS), inb(RX_STATUS));
380 dev->stats.tx_errors++;
381 outb(TX_NORM, TX_CMD);
382 outb(RX_NORM, RX_CMD);
383 outb(AX_OFF, AX_CMD); /* Just trigger a false interrupt. */
384 outb(AX_RX, AX_CMD); /* Aux control, irq and receive enabled */
385 lp->txing = 0; /* Ripped back in to RX */
386 netif_wake_queue(dev);
391 * el_start_xmit:
392 * @skb: The packet that is queued to be sent
393 * @dev: The 3c501 card we want to throw it down
395 * Attempt to send a packet to a 3c501 card. There are some interesting
396 * catches here because the 3c501 is an extremely old and therefore
397 * stupid piece of technology.
399 * If we are handling an interrupt on the other CPU we cannot load a packet
400 * as we may still be attempting to retrieve the last RX packet buffer.
402 * When a transmit times out we dump the card into control mode and just
403 * start again. It happens enough that it isnt worth logging.
405 * We avoid holding the spin locks when doing the packet load to the board.
406 * The device is very slow, and its DMA mode is even slower. If we held the
407 * lock while loading 1500 bytes onto the controller we would drop a lot of
408 * serial port characters. This requires we do extra locking, but we have
409 * no real choice.
412 static int el_start_xmit(struct sk_buff *skb, struct net_device *dev)
414 struct net_local *lp = netdev_priv(dev);
415 int ioaddr = dev->base_addr;
416 unsigned long flags;
419 * Avoid incoming interrupts between us flipping txing and flipping
420 * mode as the driver assumes txing is a faithful indicator of card
421 * state
424 spin_lock_irqsave(&lp->lock, flags);
427 * Avoid timer-based retransmission conflicts.
430 netif_stop_queue(dev);
432 do {
433 int len = skb->len;
434 int pad = 0;
435 int gp_start;
436 unsigned char *buf = skb->data;
438 if (len < ETH_ZLEN)
439 pad = ETH_ZLEN - len;
441 gp_start = 0x800 - (len + pad);
443 lp->tx_pkt_start = gp_start;
444 lp->collisions = 0;
446 dev->stats.tx_bytes += skb->len;
449 * Command mode with status cleared should [in theory]
450 * mean no more interrupts can be pending on the card.
453 outb_p(AX_SYS, AX_CMD);
454 inb_p(RX_STATUS);
455 inb_p(TX_STATUS);
457 lp->loading = 1;
458 lp->txing = 1;
461 * Turn interrupts back on while we spend a pleasant
462 * afternoon loading bytes into the board
465 spin_unlock_irqrestore(&lp->lock, flags);
467 /* Set rx packet area to 0. */
468 outw(0x00, RX_BUF_CLR);
469 /* aim - packet will be loaded into buffer start */
470 outw(gp_start, GP_LOW);
471 /* load buffer (usual thing each byte increments the pointer) */
472 outsb(DATAPORT, buf, len);
473 if (pad) {
474 while (pad--) /* Zero fill buffer tail */
475 outb(0, DATAPORT);
477 /* the board reuses the same register */
478 outw(gp_start, GP_LOW);
480 if (lp->loading != 2) {
481 /* fire ... Trigger xmit. */
482 outb(AX_XMIT, AX_CMD);
483 lp->loading = 0;
484 dev->trans_start = jiffies;
485 if (el_debug > 2)
486 printk(KERN_DEBUG " queued xmit.\n");
487 dev_kfree_skb(skb);
488 return 0;
490 /* A receive upset our load, despite our best efforts */
491 if (el_debug > 2)
492 printk(KERN_DEBUG "%s: burped during tx load.\n",
493 dev->name);
494 spin_lock_irqsave(&lp->lock, flags);
495 } while (1);
499 * el_interrupt:
500 * @irq: Interrupt number
501 * @dev_id: The 3c501 that burped
503 * Handle the ether interface interrupts. The 3c501 needs a lot more
504 * hand holding than most cards. In particular we get a transmit interrupt
505 * with a collision error because the board firmware isnt capable of rewinding
506 * its own transmit buffer pointers. It can however count to 16 for us.
508 * On the receive side the card is also very dumb. It has no buffering to
509 * speak of. We simply pull the packet out of its PIO buffer (which is slow)
510 * and queue it for the kernel. Then we reset the card for the next packet.
512 * We sometimes get surprise interrupts late both because the SMP IRQ delivery
513 * is message passing and because the card sometimes seems to deliver late. I
514 * think if it is part way through a receive and the mode is changed it carries
515 * on receiving and sends us an interrupt. We have to band aid all these cases
516 * to get a sensible 150kBytes/second performance. Even then you want a small
517 * TCP window.
520 static irqreturn_t el_interrupt(int irq, void *dev_id)
522 struct net_device *dev = dev_id;
523 struct net_local *lp;
524 int ioaddr;
525 int axsr; /* Aux. status reg. */
527 ioaddr = dev->base_addr;
528 lp = netdev_priv(dev);
530 spin_lock(&lp->lock);
533 * What happened ?
536 axsr = inb(AX_STATUS);
539 * Log it
542 if (el_debug > 3)
543 printk(KERN_DEBUG "%s: el_interrupt() aux=%#02x",
544 dev->name, axsr);
546 if (lp->loading == 1 && !lp->txing)
547 printk(KERN_WARNING "%s: Inconsistent state loading while not in tx\n",
548 dev->name);
550 if (lp->txing) {
552 * Board in transmit mode. May be loading. If we are
553 * loading we shouldn't have got this.
555 int txsr = inb(TX_STATUS);
557 if (lp->loading == 1) {
558 if (el_debug > 2) {
559 printk(KERN_DEBUG "%s: Interrupt while loading [",
560 dev->name);
561 printk(" txsr=%02x gp=%04x rp=%04x]\n",
562 txsr, inw(GP_LOW), inw(RX_LOW));
564 /* Force a reload */
565 lp->loading = 2;
566 spin_unlock(&lp->lock);
567 goto out;
569 if (el_debug > 6)
570 printk(KERN_DEBUG " txsr=%02x gp=%04x rp=%04x",
571 txsr, inw(GP_LOW), inw(RX_LOW));
573 if ((axsr & 0x80) && (txsr & TX_READY) == 0) {
575 * FIXME: is there a logic to whether to keep
576 * on trying or reset immediately ?
578 if (el_debug > 1)
579 printk(KERN_DEBUG "%s: Unusual interrupt during Tx, txsr=%02x axsr=%02x gp=%03x rp=%03x.\n",
580 dev->name, txsr, axsr,
581 inw(ioaddr + EL1_DATAPTR),
582 inw(ioaddr + EL1_RXPTR));
583 lp->txing = 0;
584 netif_wake_queue(dev);
585 } else if (txsr & TX_16COLLISIONS) {
587 * Timed out
589 if (el_debug)
590 printk(KERN_DEBUG "%s: Transmit failed 16 times, Ethernet jammed?\n", dev->name);
591 outb(AX_SYS, AX_CMD);
592 lp->txing = 0;
593 dev->stats.tx_aborted_errors++;
594 netif_wake_queue(dev);
595 } else if (txsr & TX_COLLISION) {
597 * Retrigger xmit.
600 if (el_debug > 6)
601 printk(KERN_DEBUG " retransmitting after a collision.\n");
603 * Poor little chip can't reset its own start
604 * pointer
607 outb(AX_SYS, AX_CMD);
608 outw(lp->tx_pkt_start, GP_LOW);
609 outb(AX_XMIT, AX_CMD);
610 dev->stats.collisions++;
611 spin_unlock(&lp->lock);
612 goto out;
613 } else {
615 * It worked.. we will now fall through and receive
617 dev->stats.tx_packets++;
618 if (el_debug > 6)
619 printk(KERN_DEBUG " Tx succeeded %s\n",
620 (txsr & TX_RDY) ? "." :
621 "but tx is busy!");
623 * This is safe the interrupt is atomic WRT itself.
625 lp->txing = 0;
626 /* In case more to transmit */
627 netif_wake_queue(dev);
629 } else {
631 * In receive mode.
634 int rxsr = inb(RX_STATUS);
635 if (el_debug > 5)
636 printk(KERN_DEBUG " rxsr=%02x txsr=%02x rp=%04x", rxsr, inb(TX_STATUS), inw(RX_LOW));
638 * Just reading rx_status fixes most errors.
640 if (rxsr & RX_MISSED)
641 dev->stats.rx_missed_errors++;
642 else if (rxsr & RX_RUNT) {
643 /* Handled to avoid board lock-up. */
644 dev->stats.rx_length_errors++;
645 if (el_debug > 5)
646 printk(KERN_DEBUG " runt.\n");
647 } else if (rxsr & RX_GOOD) {
649 * Receive worked.
651 el_receive(dev);
652 } else {
654 * Nothing? Something is broken!
656 if (el_debug > 2)
657 printk(KERN_DEBUG "%s: No packet seen, rxsr=%02x **resetting 3c501***\n",
658 dev->name, rxsr);
659 el_reset(dev);
661 if (el_debug > 3)
662 printk(KERN_DEBUG ".\n");
666 * Move into receive mode
669 outb(AX_RX, AX_CMD);
670 outw(0x00, RX_BUF_CLR);
671 inb(RX_STATUS); /* Be certain that interrupts are cleared. */
672 inb(TX_STATUS);
673 spin_unlock(&lp->lock);
674 out:
675 return IRQ_HANDLED;
680 * el_receive:
681 * @dev: Device to pull the packets from
683 * We have a good packet. Well, not really "good", just mostly not broken.
684 * We must check everything to see if it is good. In particular we occasionally
685 * get wild packet sizes from the card. If the packet seems sane we PIO it
686 * off the card and queue it for the protocol layers.
689 static void el_receive(struct net_device *dev)
691 int ioaddr = dev->base_addr;
692 int pkt_len;
693 struct sk_buff *skb;
695 pkt_len = inw(RX_LOW);
697 if (el_debug > 4)
698 printk(KERN_DEBUG " el_receive %d.\n", pkt_len);
700 if (pkt_len < 60 || pkt_len > 1536) {
701 if (el_debug)
702 printk(KERN_DEBUG "%s: bogus packet, length=%d\n",
703 dev->name, pkt_len);
704 dev->stats.rx_over_errors++;
705 return;
709 * Command mode so we can empty the buffer
712 outb(AX_SYS, AX_CMD);
713 skb = dev_alloc_skb(pkt_len+2);
716 * Start of frame
719 outw(0x00, GP_LOW);
720 if (skb == NULL) {
721 printk(KERN_INFO "%s: Memory squeeze, dropping packet.\n",
722 dev->name);
723 dev->stats.rx_dropped++;
724 return;
725 } else {
726 skb_reserve(skb, 2); /* Force 16 byte alignment */
728 * The read increments through the bytes. The interrupt
729 * handler will fix the pointer when it returns to
730 * receive mode.
732 insb(DATAPORT, skb_put(skb, pkt_len), pkt_len);
733 skb->protocol = eth_type_trans(skb, dev);
734 netif_rx(skb);
735 dev->stats.rx_packets++;
736 dev->stats.rx_bytes += pkt_len;
738 return;
742 * el_reset: Reset a 3c501 card
743 * @dev: The 3c501 card about to get zapped
745 * Even resetting a 3c501 isnt simple. When you activate reset it loses all
746 * its configuration. You must hold the lock when doing this. The function
747 * cannot take the lock itself as it is callable from the irq handler.
750 static void el_reset(struct net_device *dev)
752 struct net_local *lp = netdev_priv(dev);
753 int ioaddr = dev->base_addr;
755 if (el_debug > 2)
756 printk(KERN_INFO "3c501 reset...");
757 outb(AX_RESET, AX_CMD); /* Reset the chip */
758 /* Aux control, irq and loopback enabled */
759 outb(AX_LOOP, AX_CMD);
761 int i;
762 for (i = 0; i < 6; i++) /* Set the station address. */
763 outb(dev->dev_addr[i], ioaddr + i);
766 outw(0, RX_BUF_CLR); /* Set rx packet area to 0. */
767 outb(TX_NORM, TX_CMD); /* tx irq on done, collision */
768 outb(RX_NORM, RX_CMD); /* Set Rx commands. */
769 inb(RX_STATUS); /* Clear status. */
770 inb(TX_STATUS);
771 lp->txing = 0;
775 * el1_close:
776 * @dev: 3c501 card to shut down
778 * Close a 3c501 card. The IFF_UP flag has been cleared by the user via
779 * the SIOCSIFFLAGS ioctl. We stop any further transmissions being queued,
780 * and then disable the interrupts. Finally we reset the chip. The effects
781 * of the rest will be cleaned up by #el1_open. Always returns 0 indicating
782 * a success.
785 static int el1_close(struct net_device *dev)
787 int ioaddr = dev->base_addr;
789 if (el_debug > 2)
790 printk(KERN_INFO "%s: Shutting down Ethernet card at %#x.\n",
791 dev->name, ioaddr);
793 netif_stop_queue(dev);
796 * Free and disable the IRQ.
799 free_irq(dev->irq, dev);
800 outb(AX_RESET, AX_CMD); /* Reset the chip */
802 return 0;
806 * set_multicast_list:
807 * @dev: The device to adjust
809 * Set or clear the multicast filter for this adaptor to use the best-effort
810 * filtering supported. The 3c501 supports only three modes of filtering.
811 * It always receives broadcasts and packets for itself. You can choose to
812 * optionally receive all packets, or all multicast packets on top of this.
815 static void set_multicast_list(struct net_device *dev)
817 int ioaddr = dev->base_addr;
819 if (dev->flags & IFF_PROMISC) {
820 outb(RX_PROM, RX_CMD);
821 inb(RX_STATUS);
822 } else if (dev->mc_list || dev->flags & IFF_ALLMULTI) {
823 /* Multicast or all multicast is the same */
824 outb(RX_MULT, RX_CMD);
825 inb(RX_STATUS); /* Clear status. */
826 } else {
827 outb(RX_NORM, RX_CMD);
828 inb(RX_STATUS);
833 static void netdev_get_drvinfo(struct net_device *dev,
834 struct ethtool_drvinfo *info)
836 strcpy(info->driver, DRV_NAME);
837 strcpy(info->version, DRV_VERSION);
838 sprintf(info->bus_info, "ISA 0x%lx", dev->base_addr);
841 static u32 netdev_get_msglevel(struct net_device *dev)
843 return debug;
846 static void netdev_set_msglevel(struct net_device *dev, u32 level)
848 debug = level;
851 static const struct ethtool_ops netdev_ethtool_ops = {
852 .get_drvinfo = netdev_get_drvinfo,
853 .get_msglevel = netdev_get_msglevel,
854 .set_msglevel = netdev_set_msglevel,
857 #ifdef MODULE
859 static struct net_device *dev_3c501;
861 module_param(io, int, 0);
862 module_param(irq, int, 0);
863 MODULE_PARM_DESC(io, "EtherLink I/O base address");
864 MODULE_PARM_DESC(irq, "EtherLink IRQ number");
867 * init_module:
869 * When the driver is loaded as a module this function is called. We fake up
870 * a device structure with the base I/O and interrupt set as if it were being
871 * called from Space.c. This minimises the extra code that would otherwise
872 * be required.
874 * Returns 0 for success or -EIO if a card is not found. Returning an error
875 * here also causes the module to be unloaded
878 int __init init_module(void)
880 dev_3c501 = el1_probe(-1);
881 if (IS_ERR(dev_3c501))
882 return PTR_ERR(dev_3c501);
883 return 0;
887 * cleanup_module:
889 * The module is being unloaded. We unhook our network device from the system
890 * and then free up the resources we took when the card was found.
893 void __exit cleanup_module(void)
895 struct net_device *dev = dev_3c501;
896 unregister_netdev(dev);
897 release_region(dev->base_addr, EL1_IO_EXTENT);
898 free_netdev(dev);
901 #endif /* MODULE */
903 MODULE_AUTHOR("Donald Becker, Alan Cox");
904 MODULE_DESCRIPTION("Support for the ancient 3Com 3c501 ethernet card");
905 MODULE_LICENSE("GPL");