drivers/net/: all drivers/net/ cleanup with ARRAY_SIZE
[deliverable/linux.git] / drivers / net / 3c501.c
CommitLineData
1da177e4
LT
1/* 3c501.c: A 3Com 3c501 Ethernet driver for Linux. */
2/*
3 Written 1992,1993,1994 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 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.
13
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
18
19 Fixed (again!) the missing interrupt locking on TX/RX shifting.
20 Alan Cox <Alan.Cox@linux.org>
21
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)
27
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.Cox@linux.org>
6aa20a22
JG
33
34 Cleaned up for 2.3.x because we broke SMP now.
1da177e4
LT
35 20000208 Alan Cox <alan@redhat.com>
36
37 Check up pass for 2.5. Nothing significant changed
38 20021009 Alan Cox <alan@redhat.com>
39
6aa20a22 40 Fixed zero fill corner case
1da177e4 41 20030104 Alan Cox <alan@redhat.com>
6aa20a22
JG
42
43
1da177e4
LT
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.
49
50*/
51
52
53/**
54 * DOC: 3c501 Card Notes
55 *
56 * Some notes on this thing if you have to hack it. [Alan]
57 *
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
6aa20a22 61 * of historical interest anyway.
1da177e4
LT
62 *
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.
66 *
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.
70 *
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.
74 *
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).
81 *
82 * DOC: Problems
6aa20a22 83 *
1da177e4
LT
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).
88 *
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.
92 *
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.
99 *
100 */
101
102#define DRV_NAME "3c501"
103#define DRV_VERSION "2002/10/09"
104
105
106static const char version[] =
107 DRV_NAME ".c: " DRV_VERSION " Alan Cox (alan@redhat.com).\n";
108
109/*
110 * Braindamage remaining:
111 * The 3c501 board.
112 */
113
114#include <linux/module.h>
115
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>
1da177e4
LT
123#include <linux/spinlock.h>
124#include <linux/ethtool.h>
125#include <linux/delay.h>
126#include <linux/bitops.h>
127
128#include <asm/uaccess.h>
129#include <asm/io.h>
130
131#include <linux/netdevice.h>
132#include <linux/etherdevice.h>
133#include <linux/skbuff.h>
134#include <linux/init.h>
135
136#include "3c501.h"
137
138/*
139 * The boilerplate probe code.
140 */
141
142static int io=0x280;
143static int irq=5;
144static int mem_start;
145
146/**
147 * el1_probe: - probe for a 3c501
6aa20a22 148 * @dev: The device structure passed in to probe.
1da177e4
LT
149 *
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.
154 *
155 * Returns 0 on success. ENXIO if asked not to probe and ENODEV if asked to
156 * probe and failing to find anything.
157 */
6aa20a22 158
1da177e4
LT
159struct net_device * __init el1_probe(int unit)
160{
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;
165
166 if (!dev)
167 return ERR_PTR(-ENOMEM);
168
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;
175 }
176
1da177e4
LT
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++)
183 ;
184 if (!*port)
185 err = -ENODEV;
186 }
187 if (err)
188 goto out;
189 err = register_netdev(dev);
190 if (err)
191 goto out1;
192 return dev;
193out1:
194 release_region(dev->base_addr, EL1_IO_EXTENT);
195out:
196 free_netdev(dev);
197 return ERR_PTR(err);
198}
199
200/**
6aa20a22 201 * el1_probe1:
1da177e4
LT
202 * @dev: The device structure to use
203 * @ioaddr: An I/O address to probe at.
204 *
205 * The actual probe. This is iterated over by #el1_probe in order to
206 * check all the applicable device locations.
207 *
208 * Returns 0 for a success, in which case the device is activated,
209 * EAGAIN if the IRQ is in use by another driver, and ENODEV if the
210 * board cannot be found.
211 */
212
213static int __init el1_probe1(struct net_device *dev, int ioaddr)
214{
215 struct net_local *lp;
216 const char *mname; /* Vendor name */
217 unsigned char station_addr[6];
218 int autoirq = 0;
219 int i;
220
221 /*
222 * Reserve I/O resource for exclusive use by this driver
223 */
224
225 if (!request_region(ioaddr, EL1_IO_EXTENT, DRV_NAME))
226 return -ENODEV;
227
228 /*
229 * Read the station address PROM data from the special port.
230 */
231
232 for (i = 0; i < 6; i++)
233 {
234 outw(i, ioaddr + EL1_DATAPTR);
235 station_addr[i] = inb(ioaddr + EL1_SAPROM);
236 }
237 /*
238 * Check the first three octets of the S.A. for 3Com's prefix, or
239 * for the Sager NP943 prefix.
240 */
241
242 if (station_addr[0] == 0x02 && station_addr[1] == 0x60
243 && station_addr[2] == 0x8c)
244 {
245 mname = "3c501";
246 } else if (station_addr[0] == 0x00 && station_addr[1] == 0x80
247 && station_addr[2] == 0xC8)
248 {
249 mname = "NP943";
250 }
251 else {
252 release_region(ioaddr, EL1_IO_EXTENT);
253 return -ENODEV;
254 }
255
256 /*
257 * We auto-IRQ by shutting off the interrupt line and letting it float
258 * high.
259 */
260
261 dev->irq = irq;
262
263 if (dev->irq < 2)
264 {
265 unsigned long irq_mask;
266
267 irq_mask = probe_irq_on();
268 inb(RX_STATUS); /* Clear pending interrupts. */
269 inb(TX_STATUS);
270 outb(AX_LOOP + 1, AX_CMD);
271
272 outb(0x00, AX_CMD);
273
274 mdelay(20);
275 autoirq = probe_irq_off(irq_mask);
276
277 if (autoirq == 0)
278 {
279 printk(KERN_WARNING "%s probe at %#x failed to detect IRQ line.\n",
280 mname, ioaddr);
281 release_region(ioaddr, EL1_IO_EXTENT);
282 return -EAGAIN;
283 }
284 }
285
286 outb(AX_RESET+AX_LOOP, AX_CMD); /* Loopback mode. */
287 dev->base_addr = ioaddr;
288 memcpy(dev->dev_addr, station_addr, ETH_ALEN);
289
290 if (mem_start & 0xf)
291 el_debug = mem_start & 0x7;
292 if (autoirq)
293 dev->irq = autoirq;
294
295 printk(KERN_INFO "%s: %s EtherLink at %#lx, using %sIRQ %d.\n", dev->name, mname, dev->base_addr,
296 autoirq ? "auto":"assigned ", dev->irq);
297
298#ifdef CONFIG_IP_MULTICAST
299 printk(KERN_WARNING "WARNING: Use of the 3c501 in a multicast kernel is NOT recommended.\n");
300#endif
301
302 if (el_debug)
303 printk(KERN_DEBUG "%s", version);
304
305 memset(dev->priv, 0, sizeof(struct net_local));
306 lp = netdev_priv(dev);
307 spin_lock_init(&lp->lock);
6aa20a22 308
1da177e4
LT
309 /*
310 * The EL1-specific entries in the device structure.
311 */
312
313 dev->open = &el_open;
314 dev->hard_start_xmit = &el_start_xmit;
315 dev->tx_timeout = &el_timeout;
316 dev->watchdog_timeo = HZ;
317 dev->stop = &el1_close;
318 dev->get_stats = &el1_get_stats;
319 dev->set_multicast_list = &set_multicast_list;
320 dev->ethtool_ops = &netdev_ethtool_ops;
321 return 0;
322}
323
324/**
325 * el1_open:
326 * @dev: device that is being opened
327 *
328 * When an ifconfig is issued which changes the device flags to include
6aa20a22 329 * IFF_UP this function is called. It is only called when the change
1da177e4
LT
330 * occurs, not when the interface remains up. #el1_close will be called
331 * when it goes down.
332 *
333 * Returns 0 for a successful open, or -EAGAIN if someone has run off
334 * with our interrupt line.
335 */
336
337static int el_open(struct net_device *dev)
338{
339 int retval;
340 int ioaddr = dev->base_addr;
341 struct net_local *lp = netdev_priv(dev);
342 unsigned long flags;
343
344 if (el_debug > 2)
345 printk(KERN_DEBUG "%s: Doing el_open()...", dev->name);
346
347 if ((retval = request_irq(dev->irq, &el_interrupt, 0, dev->name, dev)))
348 return retval;
349
350 spin_lock_irqsave(&lp->lock, flags);
351 el_reset(dev);
352 spin_unlock_irqrestore(&lp->lock, flags);
353
354 lp->txing = 0; /* Board in RX mode */
355 outb(AX_RX, AX_CMD); /* Aux control, irq and receive enabled */
356 netif_start_queue(dev);
357 return 0;
358}
359
360/**
361 * el_timeout:
362 * @dev: The 3c501 card that has timed out
363 *
364 * Attempt to restart the board. This is basically a mixture of extreme
365 * violence and prayer
366 *
367 */
6aa20a22 368
1da177e4
LT
369static void el_timeout(struct net_device *dev)
370{
371 struct net_local *lp = netdev_priv(dev);
372 int ioaddr = dev->base_addr;
6aa20a22 373
1da177e4
LT
374 if (el_debug)
375 printk (KERN_DEBUG "%s: transmit timed out, txsr %#2x axsr=%02x rxsr=%02x.\n",
376 dev->name, inb(TX_STATUS), inb(AX_STATUS), inb(RX_STATUS));
377 lp->stats.tx_errors++;
378 outb(TX_NORM, TX_CMD);
379 outb(RX_NORM, RX_CMD);
380 outb(AX_OFF, AX_CMD); /* Just trigger a false interrupt. */
381 outb(AX_RX, AX_CMD); /* Aux control, irq and receive enabled */
382 lp->txing = 0; /* Ripped back in to RX */
383 netif_wake_queue(dev);
384}
385
6aa20a22 386
1da177e4
LT
387/**
388 * el_start_xmit:
389 * @skb: The packet that is queued to be sent
390 * @dev: The 3c501 card we want to throw it down
391 *
392 * Attempt to send a packet to a 3c501 card. There are some interesting
393 * catches here because the 3c501 is an extremely old and therefore
394 * stupid piece of technology.
395 *
396 * If we are handling an interrupt on the other CPU we cannot load a packet
397 * as we may still be attempting to retrieve the last RX packet buffer.
398 *
399 * When a transmit times out we dump the card into control mode and just
400 * start again. It happens enough that it isnt worth logging.
401 *
402 * We avoid holding the spin locks when doing the packet load to the board.
403 * The device is very slow, and its DMA mode is even slower. If we held the
404 * lock while loading 1500 bytes onto the controller we would drop a lot of
405 * serial port characters. This requires we do extra locking, but we have
406 * no real choice.
407 */
408
409static int el_start_xmit(struct sk_buff *skb, struct net_device *dev)
410{
411 struct net_local *lp = netdev_priv(dev);
412 int ioaddr = dev->base_addr;
413 unsigned long flags;
414
415 /*
416 * Avoid incoming interrupts between us flipping txing and flipping
417 * mode as the driver assumes txing is a faithful indicator of card
418 * state
419 */
420
421 spin_lock_irqsave(&lp->lock, flags);
6aa20a22 422
1da177e4
LT
423 /*
424 * Avoid timer-based retransmission conflicts.
425 */
426
427 netif_stop_queue(dev);
428
429 do
430 {
431 int len = skb->len;
432 int pad = 0;
433 int gp_start;
434 unsigned char *buf = skb->data;
6aa20a22 435
1da177e4
LT
436 if (len < ETH_ZLEN)
437 pad = ETH_ZLEN - len;
6aa20a22 438
1da177e4
LT
439 gp_start = 0x800 - ( len + pad );
440
441 lp->tx_pkt_start = gp_start;
442 lp->collisions = 0;
443
444 lp->stats.tx_bytes += skb->len;
445
446 /*
447 * Command mode with status cleared should [in theory]
448 * mean no more interrupts can be pending on the card.
449 */
450
451 outb_p(AX_SYS, AX_CMD);
452 inb_p(RX_STATUS);
453 inb_p(TX_STATUS);
454
455 lp->loading = 1;
456 lp->txing = 1;
457
458 /*
459 * Turn interrupts back on while we spend a pleasant afternoon
460 * loading bytes into the board
461 */
462
463 spin_unlock_irqrestore(&lp->lock, flags);
6aa20a22 464
1da177e4
LT
465 outw(0x00, RX_BUF_CLR); /* Set rx packet area to 0. */
466 outw(gp_start, GP_LOW); /* aim - packet will be loaded into buffer start */
467 outsb(DATAPORT,buf,len); /* load buffer (usual thing each byte increments the pointer) */
468 if (pad) {
469 while(pad--) /* Zero fill buffer tail */
470 outb(0, DATAPORT);
471 }
472 outw(gp_start, GP_LOW); /* the board reuses the same register */
6aa20a22 473
1da177e4
LT
474 if(lp->loading != 2)
475 {
476 outb(AX_XMIT, AX_CMD); /* fire ... Trigger xmit. */
477 lp->loading=0;
478 dev->trans_start = jiffies;
479 if (el_debug > 2)
480 printk(KERN_DEBUG " queued xmit.\n");
481 dev_kfree_skb (skb);
482 return 0;
483 }
484 /* A receive upset our load, despite our best efforts */
485 if(el_debug>2)
486 printk(KERN_DEBUG "%s: burped during tx load.\n", dev->name);
487 spin_lock_irqsave(&lp->lock, flags);
488 }
489 while(1);
490
491}
492
493/**
494 * el_interrupt:
495 * @irq: Interrupt number
496 * @dev_id: The 3c501 that burped
1da177e4 497 *
6aa20a22 498 * Handle the ether interface interrupts. The 3c501 needs a lot more
1da177e4
LT
499 * hand holding than most cards. In particular we get a transmit interrupt
500 * with a collision error because the board firmware isnt capable of rewinding
501 * its own transmit buffer pointers. It can however count to 16 for us.
502 *
503 * On the receive side the card is also very dumb. It has no buffering to
504 * speak of. We simply pull the packet out of its PIO buffer (which is slow)
505 * and queue it for the kernel. Then we reset the card for the next packet.
506 *
d6e05edc 507 * We sometimes get surprise interrupts late both because the SMP IRQ delivery
1da177e4
LT
508 * is message passing and because the card sometimes seems to deliver late. I
509 * think if it is part way through a receive and the mode is changed it carries
510 * on receiving and sends us an interrupt. We have to band aid all these cases
d6e05edc 511 * to get a sensible 150kBytes/second performance. Even then you want a small
1da177e4
LT
512 * TCP window.
513 */
514
7d12e780 515static irqreturn_t el_interrupt(int irq, void *dev_id)
1da177e4
LT
516{
517 struct net_device *dev = dev_id;
518 struct net_local *lp;
519 int ioaddr;
520 int axsr; /* Aux. status reg. */
521
522 ioaddr = dev->base_addr;
523 lp = netdev_priv(dev);
524
525 spin_lock(&lp->lock);
6aa20a22 526
1da177e4
LT
527 /*
528 * What happened ?
529 */
530
531 axsr = inb(AX_STATUS);
532
533 /*
534 * Log it
535 */
536
537 if (el_debug > 3)
538 printk(KERN_DEBUG "%s: el_interrupt() aux=%#02x", dev->name, axsr);
539
540 if(lp->loading==1 && !lp->txing)
541 printk(KERN_WARNING "%s: Inconsistent state loading while not in tx\n",
542 dev->name);
543
544 if (lp->txing)
545 {
546
547 /*
548 * Board in transmit mode. May be loading. If we are
549 * loading we shouldn't have got this.
550 */
551
552 int txsr = inb(TX_STATUS);
553
554 if(lp->loading==1)
555 {
556 if(el_debug > 2)
557 {
558 printk(KERN_DEBUG "%s: Interrupt while loading [", dev->name);
559 printk(KERN_DEBUG " txsr=%02x gp=%04x rp=%04x]\n", txsr, inw(GP_LOW),inw(RX_LOW));
560 }
561 lp->loading=2; /* Force a reload */
562 spin_unlock(&lp->lock);
563 goto out;
564 }
565
566 if (el_debug > 6)
567 printk(KERN_DEBUG " txsr=%02x gp=%04x rp=%04x", txsr, inw(GP_LOW),inw(RX_LOW));
568
569 if ((axsr & 0x80) && (txsr & TX_READY) == 0)
570 {
571 /*
572 * FIXME: is there a logic to whether to keep on trying or
573 * reset immediately ?
574 */
575 if(el_debug>1)
576 printk(KERN_DEBUG "%s: Unusual interrupt during Tx, txsr=%02x axsr=%02x"
577 " gp=%03x rp=%03x.\n", dev->name, txsr, axsr,
578 inw(ioaddr + EL1_DATAPTR), inw(ioaddr + EL1_RXPTR));
579 lp->txing = 0;
580 netif_wake_queue(dev);
581 }
582 else if (txsr & TX_16COLLISIONS)
583 {
584 /*
585 * Timed out
586 */
587 if (el_debug)
588 printk (KERN_DEBUG "%s: Transmit failed 16 times, Ethernet jammed?\n",dev->name);
589 outb(AX_SYS, AX_CMD);
590 lp->txing = 0;
591 lp->stats.tx_aborted_errors++;
592 netif_wake_queue(dev);
593 }
594 else if (txsr & TX_COLLISION)
595 {
596 /*
597 * Retrigger xmit.
598 */
599
600 if (el_debug > 6)
601 printk(KERN_DEBUG " retransmitting after a collision.\n");
602 /*
603 * Poor little chip can't reset its own start pointer
604 */
605
606 outb(AX_SYS, AX_CMD);
607 outw(lp->tx_pkt_start, GP_LOW);
608 outb(AX_XMIT, AX_CMD);
609 lp->stats.collisions++;
610 spin_unlock(&lp->lock);
611 goto out;
612 }
613 else
614 {
615 /*
616 * It worked.. we will now fall through and receive
617 */
618 lp->stats.tx_packets++;
619 if (el_debug > 6)
620 printk(KERN_DEBUG " Tx succeeded %s\n",
621 (txsr & TX_RDY) ? "." : "but tx is busy!");
622 /*
623 * This is safe the interrupt is atomic WRT itself.
624 */
625
626 lp->txing = 0;
627 netif_wake_queue(dev); /* In case more to transmit */
628 }
629 }
630 else
631 {
632 /*
633 * In receive mode.
634 */
635
636 int rxsr = inb(RX_STATUS);
637 if (el_debug > 5)
638 printk(KERN_DEBUG " rxsr=%02x txsr=%02x rp=%04x", rxsr, inb(TX_STATUS),inw(RX_LOW));
639 /*
640 * Just reading rx_status fixes most errors.
641 */
642 if (rxsr & RX_MISSED)
643 lp->stats.rx_missed_errors++;
644 else if (rxsr & RX_RUNT)
645 { /* Handled to avoid board lock-up. */
646 lp->stats.rx_length_errors++;
647 if (el_debug > 5)
648 printk(KERN_DEBUG " runt.\n");
649 }
650 else if (rxsr & RX_GOOD)
651 {
652 /*
653 * Receive worked.
654 */
655 el_receive(dev);
656 }
657 else
658 {
659 /*
660 * Nothing? Something is broken!
661 */
662 if (el_debug > 2)
663 printk(KERN_DEBUG "%s: No packet seen, rxsr=%02x **resetting 3c501***\n",
664 dev->name, rxsr);
665 el_reset(dev);
666 }
667 if (el_debug > 3)
668 printk(KERN_DEBUG ".\n");
669 }
670
671 /*
672 * Move into receive mode
673 */
674
675 outb(AX_RX, AX_CMD);
676 outw(0x00, RX_BUF_CLR);
677 inb(RX_STATUS); /* Be certain that interrupts are cleared. */
678 inb(TX_STATUS);
679 spin_unlock(&lp->lock);
680out:
681 return IRQ_HANDLED;
682}
683
684
685/**
686 * el_receive:
687 * @dev: Device to pull the packets from
688 *
689 * We have a good packet. Well, not really "good", just mostly not broken.
690 * We must check everything to see if it is good. In particular we occasionally
691 * get wild packet sizes from the card. If the packet seems sane we PIO it
692 * off the card and queue it for the protocol layers.
693 */
694
695static void el_receive(struct net_device *dev)
696{
697 struct net_local *lp = netdev_priv(dev);
698 int ioaddr = dev->base_addr;
699 int pkt_len;
700 struct sk_buff *skb;
701
702 pkt_len = inw(RX_LOW);
703
704 if (el_debug > 4)
705 printk(KERN_DEBUG " el_receive %d.\n", pkt_len);
706
707 if ((pkt_len < 60) || (pkt_len > 1536))
708 {
709 if (el_debug)
710 printk(KERN_DEBUG "%s: bogus packet, length=%d\n", dev->name, pkt_len);
711 lp->stats.rx_over_errors++;
712 return;
713 }
714
715 /*
716 * Command mode so we can empty the buffer
717 */
718
719 outb(AX_SYS, AX_CMD);
720 skb = dev_alloc_skb(pkt_len+2);
721
722 /*
723 * Start of frame
724 */
725
726 outw(0x00, GP_LOW);
727 if (skb == NULL)
728 {
729 printk(KERN_INFO "%s: Memory squeeze, dropping packet.\n", dev->name);
730 lp->stats.rx_dropped++;
731 return;
732 }
733 else
734 {
735 skb_reserve(skb,2); /* Force 16 byte alignment */
1da177e4
LT
736 /*
737 * The read increments through the bytes. The interrupt
738 * handler will fix the pointer when it returns to
739 * receive mode.
740 */
741 insb(DATAPORT, skb_put(skb,pkt_len), pkt_len);
742 skb->protocol=eth_type_trans(skb,dev);
743 netif_rx(skb);
744 dev->last_rx = jiffies;
745 lp->stats.rx_packets++;
746 lp->stats.rx_bytes+=pkt_len;
747 }
748 return;
749}
750
751/**
752 * el_reset: Reset a 3c501 card
753 * @dev: The 3c501 card about to get zapped
754 *
755 * Even resetting a 3c501 isnt simple. When you activate reset it loses all
756 * its configuration. You must hold the lock when doing this. The function
757 * cannot take the lock itself as it is callable from the irq handler.
758 */
759
760static void el_reset(struct net_device *dev)
761{
762 struct net_local *lp = netdev_priv(dev);
763 int ioaddr = dev->base_addr;
764
765 if (el_debug> 2)
766 printk(KERN_INFO "3c501 reset...");
767 outb(AX_RESET, AX_CMD); /* Reset the chip */
768 outb(AX_LOOP, AX_CMD); /* Aux control, irq and loopback enabled */
769 {
770 int i;
771 for (i = 0; i < 6; i++) /* Set the station address. */
772 outb(dev->dev_addr[i], ioaddr + i);
773 }
774
775 outw(0, RX_BUF_CLR); /* Set rx packet area to 0. */
776 outb(TX_NORM, TX_CMD); /* tx irq on done, collision */
777 outb(RX_NORM, RX_CMD); /* Set Rx commands. */
778 inb(RX_STATUS); /* Clear status. */
779 inb(TX_STATUS);
780 lp->txing = 0;
781}
782
783/**
784 * el1_close:
785 * @dev: 3c501 card to shut down
786 *
787 * Close a 3c501 card. The IFF_UP flag has been cleared by the user via
788 * the SIOCSIFFLAGS ioctl. We stop any further transmissions being queued,
789 * and then disable the interrupts. Finally we reset the chip. The effects
790 * of the rest will be cleaned up by #el1_open. Always returns 0 indicating
791 * a success.
792 */
6aa20a22 793
1da177e4
LT
794static int el1_close(struct net_device *dev)
795{
796 int ioaddr = dev->base_addr;
797
798 if (el_debug > 2)
799 printk(KERN_INFO "%s: Shutting down Ethernet card at %#x.\n", dev->name, ioaddr);
800
801 netif_stop_queue(dev);
6aa20a22 802
1da177e4
LT
803 /*
804 * Free and disable the IRQ.
805 */
806
807 free_irq(dev->irq, dev);
808 outb(AX_RESET, AX_CMD); /* Reset the chip */
809
810 return 0;
811}
812
813/**
814 * el1_get_stats:
815 * @dev: The card to get the statistics for
816 *
817 * In smarter devices this function is needed to pull statistics off the
818 * board itself. The 3c501 has no hardware statistics. We maintain them all
819 * so they are by definition always up to date.
820 *
821 * Returns the statistics for the card from the card private data
822 */
6aa20a22 823
1da177e4
LT
824static struct net_device_stats *el1_get_stats(struct net_device *dev)
825{
826 struct net_local *lp = netdev_priv(dev);
827 return &lp->stats;
828}
829
830/**
831 * set_multicast_list:
832 * @dev: The device to adjust
833 *
6aa20a22 834 * Set or clear the multicast filter for this adaptor to use the best-effort
1da177e4
LT
835 * filtering supported. The 3c501 supports only three modes of filtering.
836 * It always receives broadcasts and packets for itself. You can choose to
837 * optionally receive all packets, or all multicast packets on top of this.
838 */
839
840static void set_multicast_list(struct net_device *dev)
841{
842 int ioaddr = dev->base_addr;
843
844 if(dev->flags&IFF_PROMISC)
845 {
846 outb(RX_PROM, RX_CMD);
847 inb(RX_STATUS);
848 }
849 else if (dev->mc_list || dev->flags&IFF_ALLMULTI)
850 {
851 outb(RX_MULT, RX_CMD); /* Multicast or all multicast is the same */
852 inb(RX_STATUS); /* Clear status. */
853 }
854 else
855 {
856 outb(RX_NORM, RX_CMD);
857 inb(RX_STATUS);
858 }
859}
860
861
862static void netdev_get_drvinfo(struct net_device *dev,
863 struct ethtool_drvinfo *info)
864{
865 strcpy(info->driver, DRV_NAME);
866 strcpy(info->version, DRV_VERSION);
867 sprintf(info->bus_info, "ISA 0x%lx", dev->base_addr);
868}
869
870static u32 netdev_get_msglevel(struct net_device *dev)
871{
872 return debug;
873}
874
875static void netdev_set_msglevel(struct net_device *dev, u32 level)
876{
877 debug = level;
878}
879
7282d491 880static const struct ethtool_ops netdev_ethtool_ops = {
1da177e4
LT
881 .get_drvinfo = netdev_get_drvinfo,
882 .get_msglevel = netdev_get_msglevel,
883 .set_msglevel = netdev_set_msglevel,
884};
885
886#ifdef MODULE
887
888static struct net_device *dev_3c501;
889
890module_param(io, int, 0);
891module_param(irq, int, 0);
892MODULE_PARM_DESC(io, "EtherLink I/O base address");
893MODULE_PARM_DESC(irq, "EtherLink IRQ number");
894
895/**
896 * init_module:
897 *
898 * When the driver is loaded as a module this function is called. We fake up
899 * a device structure with the base I/O and interrupt set as if it were being
900 * called from Space.c. This minimises the extra code that would otherwise
901 * be required.
902 *
903 * Returns 0 for success or -EIO if a card is not found. Returning an error
904 * here also causes the module to be unloaded
905 */
6aa20a22 906
96e672c7 907int __init init_module(void)
1da177e4
LT
908{
909 dev_3c501 = el1_probe(-1);
910 if (IS_ERR(dev_3c501))
911 return PTR_ERR(dev_3c501);
912 return 0;
913}
914
915/**
916 * cleanup_module:
6aa20a22 917 *
1da177e4
LT
918 * The module is being unloaded. We unhook our network device from the system
919 * and then free up the resources we took when the card was found.
920 */
6aa20a22 921
afc8eb46 922void __exit cleanup_module(void)
1da177e4
LT
923{
924 struct net_device *dev = dev_3c501;
925 unregister_netdev(dev);
926 release_region(dev->base_addr, EL1_IO_EXTENT);
927 free_netdev(dev);
928}
929
930#endif /* MODULE */
931
932MODULE_AUTHOR("Donald Becker, Alan Cox");
933MODULE_DESCRIPTION("Support for the ancient 3Com 3c501 ethernet card");
934MODULE_LICENSE("GPL");
935
This page took 0.422963 seconds and 5 git commands to generate.