ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / net / fmv18x.c
1 /* fmv18x.c: A network device driver for the Fujitsu FMV-181/182/183/184.
2
3         Original: at1700.c (1993-94 by Donald Becker).
4                 Copyright 1993 United States Government as represented by the
5                 Director, National Security Agency.
6                 The author may be reached as becker@scyld.com, or C/O
7                         Scyld Computing Corporation
8                         410 Severn Ave., Suite 210
9                         Annapolis MD 21403
10
11         Modified by Yutaka TAMIYA (tamy@flab.fujitsu.co.jp)
12                 Copyright 1994 Fujitsu Laboratories Ltd.
13         Special thanks to:
14                 Masayoshi UTAKA (utaka@ace.yk.fujitsu.co.jp)
15                         for testing this driver.
16                 H. NEGISHI (agy, negishi@sun45.psd.cs.fujitsu.co.jp)
17                         for suggestion of some program modification.
18                 Masahiro SEKIGUCHI <seki@sysrap.cs.fujitsu.co.jp>
19                         for suggestion of some program modification.
20                 Kazutoshi MORIOKA (morioka@aurora.oaks.cs.fujitsu.co.jp)
21                         for testing this driver.
22
23         This software may be used and distributed according to the terms
24         of the GNU General Public License, incorporated herein by reference.
25
26         This is a device driver for the Fujitsu FMV-181/182/183/184, which
27         is a straight-forward Fujitsu MB86965 implementation.
28
29   Sources:
30     at1700.c
31     The Fujitsu MB86965 datasheet.
32     The Fujitsu FMV-181/182 user's guide
33 */
34
35 static const char version[] =
36         "fmv18x.c:v2.2.0 09/24/98  Yutaka TAMIYA (tamy@flab.fujitsu.co.jp)\n";
37
38 #include <linux/module.h>
39 #include <linux/kernel.h>
40 #include <linux/types.h>
41 #include <linux/fcntl.h>
42 #include <linux/interrupt.h>
43 #include <linux/ioport.h>
44 #include <linux/in.h>
45 #include <linux/slab.h>
46 #include <linux/string.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/spinlock.h>
50 #include <linux/netdevice.h>
51 #include <linux/etherdevice.h>
52 #include <linux/skbuff.h>
53 #include <linux/delay.h>
54
55 #include <asm/system.h>
56 #include <asm/bitops.h>
57 #include <asm/io.h>
58 #include <asm/dma.h>
59
60 static unsigned fmv18x_probe_list[] __initdata = {
61         0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x300, 0x340, 0
62 };
63
64 /* use 0 for production, 1 for verification, >2 for debug */
65 #ifndef NET_DEBUG
66 #define NET_DEBUG 1
67 #endif
68 static unsigned int net_debug = NET_DEBUG;
69
70 typedef unsigned char uchar;
71
72 /* Information that need to be kept for each board. */
73 struct net_local {
74         struct net_device_stats stats;
75         long open_time;                         /* Useless example local info. */
76         uint tx_started:1;                      /* Number of packet on the Tx queue. */
77         uint tx_queue_ready:1;          /* Tx queue is ready to be sent. */
78         uint rx_started:1;                      /* Packets are Rxing. */
79         uchar tx_queue;                         /* Number of packet on the Tx queue. */
80         ushort tx_queue_len;            /* Current length of the Tx queue. */
81         spinlock_t lock;
82 };
83
84
85 /* Offsets from the base address. */
86 #define STATUS                  0
87 #define TX_STATUS               0
88 #define RX_STATUS               1
89 #define TX_INTR                 2               /* Bit-mapped interrupt enable registers. */
90 #define RX_INTR                 3
91 #define TX_MODE                 4
92 #define RX_MODE                 5
93 #define CONFIG_0                6               /* Misc. configuration settings. */
94 #define CONFIG_1                7
95 /* Run-time register bank 2 definitions. */
96 #define DATAPORT                8               /* Word-wide DMA or programmed-I/O dataport. */
97 #define TX_START                10
98 #define COL16CNTL               11              /* Controll Reg for 16 collisions */
99 #define MODE13                  13
100 /* Fujitsu FMV-18x Card Configuration */
101 #define FJ_STATUS0              0x10
102 #define FJ_STATUS1              0x11
103 #define FJ_CONFIG0              0x12
104 #define FJ_CONFIG1              0x13
105 #define FJ_MACADDR              0x14    /* 0x14 - 0x19 */
106 #define FJ_BUFCNTL              0x1A
107 #define FJ_BUFDATA              0x1C
108 #define FMV18X_IO_EXTENT        32
109
110 /* Index to functions, as function prototypes. */
111
112 static int fmv18x_probe1(struct net_device *dev, short ioaddr);
113 static int net_open(struct net_device *dev);
114 static int net_send_packet(struct sk_buff *skb, struct net_device *dev);
115 static irqreturn_t net_interrupt(int irq, void *dev_id, struct pt_regs *regs);
116 static void net_rx(struct net_device *dev);
117 static void net_timeout(struct net_device *dev);
118 static int net_close(struct net_device *dev);
119 static struct net_device_stats *net_get_stats(struct net_device *dev);
120 static void set_multicast_list(struct net_device *dev);
121
122 \f
123 /* Check for a network adaptor of this type, and return '0' iff one exists.
124    If dev->base_addr == 0, probe all likely locations.
125    If dev->base_addr == 1, always return failure.
126    If dev->base_addr == 2, allocate space for the device and return success
127    (detachable devices only).
128    */
129
130 static int io = 0x220;
131 static int irq;
132
133 struct net_device * __init fmv18x_probe(int unit)
134 {
135         struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
136         unsigned *port;
137         int err = 0;
138
139         if (!dev)
140                 return ERR_PTR(-ENODEV);
141
142         if (unit >= 0) {
143                 sprintf(dev->name, "eth%d", unit);
144                 netdev_boot_setup_check(dev);
145                 io = dev->base_addr;
146                 irq = dev->irq;
147         }
148
149         SET_MODULE_OWNER(dev);
150
151         if (io > 0x1ff) {       /* Check a single specified location. */
152                 err = fmv18x_probe1(dev, io);
153         } else if (io != 0) {   /* Don't probe at all. */
154                 err = -ENXIO;
155         } else {
156                 for (port = fmv18x_probe_list; *port; port++)
157                         if (fmv18x_probe1(dev, *port) == 0)
158                                 break;
159                 if (!*port)
160                         err = -ENODEV;
161         }
162         if (err)
163                 goto out;
164         err = register_netdev(dev);
165         if (err)
166                 goto out1;
167         return dev;
168 out1:
169         free_irq(dev->irq, dev);
170         release_region(dev->base_addr, FMV18X_IO_EXTENT);
171 out:
172         free_netdev(dev);
173         return ERR_PTR(err);
174 }
175
176 /* The Fujitsu datasheet suggests that the NIC be probed for by checking its
177    "signature", the default bit pattern after a reset.  This *doesn't* work --
178    there is no way to reset the bus interface without a complete power-cycle!
179
180    It turns out that ATI came to the same conclusion I did: the only thing
181    that can be done is checking a few bits and then diving right into MAC
182    address check. */
183
184 static int __init fmv18x_probe1(struct net_device *dev, short ioaddr)
185 {
186         char irqmap[4] = {3, 7, 10, 15};
187         char irqmap_pnp[8] = {3, 4, 5, 7, 9, 10, 11, 15};
188         unsigned int i, retval;
189         struct net_local *lp;
190
191         /* Resetting the chip doesn't reset the ISA interface, so don't bother.
192            That means we have to be careful with the register values we probe for.
193            */
194
195         if (!request_region(ioaddr, FMV18X_IO_EXTENT, dev->name))
196                 return -EBUSY;
197
198         dev->irq = irq;
199         dev->base_addr = ioaddr;
200
201         /* Check I/O address configuration and Fujitsu vendor code */
202         if (inb(ioaddr+FJ_MACADDR  ) != 0x00
203         ||  inb(ioaddr+FJ_MACADDR+1) != 0x00
204         ||  inb(ioaddr+FJ_MACADDR+2) != 0x0e) {
205                 retval = -ENODEV;
206                 goto out;
207         }
208
209         /* Check PnP mode for FMV-183/184/183A/184A. */
210         /* This PnP routine is very poor. IO and IRQ should be known. */
211         if (inb(ioaddr + FJ_STATUS1) & 0x20) {
212                 for (i = 0; i < 8; i++) {
213                         if (dev->irq == irqmap_pnp[i])
214                                 break;
215                 }
216                 if (i == 8) {
217                         retval = -ENODEV;
218                         goto out;
219                 }
220         } else {
221                 if (fmv18x_probe_list[inb(ioaddr + FJ_CONFIG0) & 0x07] != ioaddr)
222                         return -ENODEV;
223                 dev->irq = irqmap[(inb(ioaddr + FJ_CONFIG0)>>6) & 0x03];
224         }
225
226         /* Snarf the interrupt vector now. */
227         retval = request_irq(dev->irq, &net_interrupt, 0, dev->name, dev);
228         if (retval) {
229                 printk ("FMV-18x found at %#3x, but it's unusable due to a conflict on"
230                                 "IRQ %d.\n", ioaddr, dev->irq);
231                 goto out;
232         }
233
234         printk("%s: FMV-18x found at %#3x, IRQ %d, address ", dev->name,
235                    ioaddr, dev->irq);
236
237         for(i = 0; i < 6; i++) {
238                 unsigned char val = inb(ioaddr + FJ_MACADDR + i);
239                 printk("%02x", val);
240                 dev->dev_addr[i] = val;
241         }
242
243         /* "FJ_STATUS0" 12 bit 0x0400 means use regular 100 ohm 10baseT signals,
244            rather than 150 ohm shielded twisted pair compensation.
245            0x0000 == auto-sense the interface
246            0x0800 == use TP interface
247            0x1800 == use coax interface
248            */
249         {
250                 const char *porttype[] = {"auto-sense", "10baseT", "auto-sense", "10base2/5"};
251                 ushort setup_value = inb(ioaddr + FJ_STATUS0);
252
253                 switch( setup_value & 0x07 ){
254                 case 0x01 /* 10base5 */:
255                 case 0x02 /* 10base2 */: dev->if_port = 0x18; break;
256                 case 0x04 /* 10baseT */: dev->if_port = 0x08; break;
257                 default /* auto-sense*/: dev->if_port = 0x00; break;
258                 }
259                 printk(" %s interface.\n", porttype[(dev->if_port>>3) & 3]);
260         }
261
262         /* Initialize LAN Controller and LAN Card */
263         outb(0xda, ioaddr + CONFIG_0);   /* Initialize LAN Controller */
264         outb(0x00, ioaddr + CONFIG_1);   /* Stand by mode */
265         outb(0x00, ioaddr + FJ_CONFIG1); /* Disable IRQ of LAN Card */
266         outb(0x00, ioaddr + FJ_BUFCNTL); /* Reset ? I'm not sure (TAMIYA) */
267
268         /* wait for a while */
269         udelay(200);
270
271         /* Set the station address in bank zero. */
272         outb(0x00, ioaddr + CONFIG_1);
273         for (i = 0; i < 6; i++)
274                 outb(dev->dev_addr[i], ioaddr + 8 + i);
275
276         /* Switch to bank 1 and set the multicast table to accept none. */
277         outb(0x04, ioaddr + CONFIG_1);
278         for (i = 0; i < 8; i++)
279                 outb(0x00, ioaddr + 8 + i);
280
281         /* Switch to bank 2 and lock our I/O address. */
282         outb(0x08, ioaddr + CONFIG_1);
283         outb(dev->if_port, ioaddr + MODE13);
284         outb(0x00, ioaddr + COL16CNTL);
285
286         if (net_debug)
287                 printk(version);
288
289         /* Initialize the device structure. */
290         dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
291         if (!dev->priv) {
292                 retval = -ENOMEM;
293                 goto out_irq;
294         }
295         memset(dev->priv, 0, sizeof(struct net_local));
296         lp = dev->priv;
297         spin_lock_init(&lp->lock);
298
299         dev->open               = net_open;
300         dev->stop               = net_close;
301         dev->hard_start_xmit    = net_send_packet;
302         dev->tx_timeout         = net_timeout;
303         dev->watchdog_timeo     = HZ/10;
304         dev->get_stats          = net_get_stats;
305         dev->set_multicast_list = set_multicast_list;
306         return 0;
307
308 out_irq:
309         free_irq(dev->irq, dev);
310 out:
311         release_region(ioaddr, FMV18X_IO_EXTENT);
312         return retval;
313 }
314 \f
315
316 static int net_open(struct net_device *dev)
317 {
318         struct net_local *lp = dev->priv;
319         int ioaddr = dev->base_addr;
320
321         /* Set the configuration register 0 to 32K 100ns. byte-wide memory,
322            16 bit bus access, and two 4K Tx, enable the Rx and Tx. */
323         outb(0x5a, ioaddr + CONFIG_0);
324
325         /* Powerup and switch to register bank 2 for the run-time registers. */
326         outb(0xe8, ioaddr + CONFIG_1);
327
328         lp->tx_started = 0;
329         lp->tx_queue_ready = 1;
330         lp->rx_started = 0;
331         lp->tx_queue = 0;
332         lp->tx_queue_len = 0;
333
334         /* Clear Tx and Rx Status */
335         outb(0xff, ioaddr + TX_STATUS);
336         outb(0xff, ioaddr + RX_STATUS);
337         lp->open_time = jiffies;
338
339         netif_start_queue(dev);
340         
341         /* Enable the IRQ of the LAN Card */
342         outb(0x80, ioaddr + FJ_CONFIG1);
343
344         /* Enable both Tx and Rx interrupts */
345         outw(0x8182, ioaddr+TX_INTR);
346
347         return 0;
348 }
349
350 static void net_timeout(struct net_device *dev)
351 {
352         struct net_local *lp = dev->priv;
353         int ioaddr = dev->base_addr;
354         unsigned long flags;
355         
356         
357         printk(KERN_WARNING "%s: transmit timed out with status %04x, %s?\n", dev->name,
358                    htons(inw(ioaddr + TX_STATUS)),
359                    inb(ioaddr + TX_STATUS) & 0x80
360                    ? "IRQ conflict" : "network cable problem");
361         printk(KERN_WARNING "%s: timeout registers: %04x %04x %04x %04x %04x %04x %04x %04x.\n",
362                    dev->name, htons(inw(ioaddr + 0)),
363                    htons(inw(ioaddr + 2)), htons(inw(ioaddr + 4)),
364                    htons(inw(ioaddr + 6)), htons(inw(ioaddr + 8)),
365                    htons(inw(ioaddr +10)), htons(inw(ioaddr +12)),
366                    htons(inw(ioaddr +14)));
367         printk(KERN_WARNING "eth card: %04x %04x\n",
368                 htons(inw(ioaddr+FJ_STATUS0)),
369                 htons(inw(ioaddr+FJ_CONFIG0)));
370         lp->stats.tx_errors++;
371         /* ToDo: We should try to restart the adaptor... */
372         spin_lock_irqsave(&lp->lock, flags);
373
374         /* Initialize LAN Controller and LAN Card */
375         outb(0xda, ioaddr + CONFIG_0);   /* Initialize LAN Controller */
376         outb(0x00, ioaddr + CONFIG_1);   /* Stand by mode */
377         outb(0x00, ioaddr + FJ_CONFIG1); /* Disable IRQ of LAN Card */
378         outb(0x00, ioaddr + FJ_BUFCNTL); /* Reset ? I'm not sure */
379         net_open(dev);
380         spin_unlock_irqrestore(&lp->lock, flags);
381
382         netif_wake_queue(dev);
383 }
384
385 static int net_send_packet(struct sk_buff *skb, struct net_device *dev)
386 {
387         struct net_local *lp = dev->priv;
388         int ioaddr = dev->base_addr;
389         short length = skb->len;
390         unsigned char *buf;
391         unsigned long flags;
392
393         /* Block a transmit from overlapping.  */
394         
395         if (length > ETH_FRAME_LEN) {
396                 if (net_debug)
397                         printk("%s: Attempting to send a large packet (%d bytes).\n",
398                                 dev->name, length);
399                 return 1;
400         }
401         
402         if (length < ETH_ZLEN) {
403                 skb = skb_padto(skb, ETH_ZLEN);
404                 if (skb == NULL)
405                         return 0;
406                 length = ETH_ZLEN;
407         }
408         buf = skb->data;
409         
410         if (net_debug > 4)
411                 printk("%s: Transmitting a packet of length %lu.\n", dev->name,
412                            (unsigned long)skb->len);
413         /* We may not start transmitting unless we finish transferring
414            a packet into the Tx queue. During executing the following
415            codes we possibly catch a Tx interrupt. Thus we flag off
416            tx_queue_ready, so that we prevent the interrupt routine
417            (net_interrupt) to start transmitting. */
418         spin_lock_irqsave(&lp->lock, flags);
419         lp->tx_queue_ready = 0;
420         {
421                 outw(length, ioaddr + DATAPORT);
422                 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
423                 lp->tx_queue++;
424                 lp->tx_queue_len += length + 2;
425         }
426         lp->tx_queue_ready = 1;
427         spin_unlock_irqrestore(&lp->lock, flags);
428
429         if (lp->tx_started == 0) {
430                 /* If the Tx is idle, always trigger a transmit. */
431                 outb(0x80 | lp->tx_queue, ioaddr + TX_START);
432                 lp->tx_queue = 0;
433                 lp->tx_queue_len = 0;
434                 dev->trans_start = jiffies;
435                 lp->tx_started = 1;
436         } else if (lp->tx_queue_len >= 4096 - 1502) /* No room for a packet */
437                 netif_stop_queue(dev);
438
439         dev_kfree_skb(skb);
440         return 0;
441 }
442 \f
443 /* The typical workload of the driver:
444    Handle the network interface interrupts. */
445 static irqreturn_t
446 net_interrupt(int irq, void *dev_id, struct pt_regs *regs)
447 {
448         struct net_device *dev = dev_id;
449         struct net_local *lp;
450         int ioaddr, status;
451
452         ioaddr = dev->base_addr;
453         lp = dev->priv;
454         status = inw(ioaddr + TX_STATUS);
455         outw(status, ioaddr + TX_STATUS);
456
457         if (net_debug > 4)
458                 printk("%s: Interrupt with status %04x.\n", dev->name, status);
459         if (lp->rx_started == 0 &&
460                 (status & 0xff00 || (inb(ioaddr + RX_MODE) & 0x40) == 0)) {
461                 /* Got a packet(s).
462                    We cannot execute net_rx more than once at the same time for
463                    the same device. During executing net_rx, we possibly catch a
464                    Tx interrupt. Thus we flag on rx_started, so that we prevent
465                    the interrupt routine (net_interrupt) to dive into net_rx
466                    again. */
467                 lp->rx_started = 1;
468                 outb(0x00, ioaddr + RX_INTR);   /* Disable RX intr. */
469                 net_rx(dev);
470                 outb(0x81, ioaddr + RX_INTR);   /* Enable  RX intr. */
471                 lp->rx_started = 0;
472         }
473         if (status & 0x00ff) {
474                 if (status & 0x02) {
475                         /* More than 16 collisions occurred */
476                         if (net_debug > 4)
477                                 printk("%s: 16 Collision occur during Txing.\n", dev->name);
478                         /* Cancel sending a packet. */
479                         outb(0x03, ioaddr + COL16CNTL);
480                         lp->stats.collisions++;
481                 }
482                 if (status & 0x82) {
483                         spin_lock(&lp->lock);
484                         lp->stats.tx_packets++;
485                         if (lp->tx_queue && lp->tx_queue_ready) {
486                                 outb(0x80 | lp->tx_queue, ioaddr + TX_START);
487                                 lp->tx_queue = 0;
488                                 lp->tx_queue_len = 0;
489                                 dev->trans_start = jiffies;
490                                 netif_wake_queue(dev);  /* Inform upper layers. */
491                         } else {
492                                 lp->tx_started = 0;
493                                 netif_wake_queue(dev);  /* Inform upper layers. */
494                         }
495                         spin_unlock(&lp->lock);
496                 }
497         }
498         return IRQ_RETVAL(status);
499 }
500
501 /* We have a good packet(s), get it/them out of the buffers. */
502 static void net_rx(struct net_device *dev)
503 {
504         struct net_local *lp = dev->priv;
505         int ioaddr = dev->base_addr;
506         int boguscount = 5;
507
508         while ((inb(ioaddr + RX_MODE) & 0x40) == 0) {
509                 /* Clear PKT_RDY bit: by agy 19940922 */
510                 /* outb(0x80, ioaddr + RX_STATUS); */
511                 ushort status = inw(ioaddr + DATAPORT);
512
513                 if (net_debug > 4)
514                         printk("%s: Rxing packet mode %02x status %04x.\n",
515                                    dev->name, inb(ioaddr + RX_MODE), status);
516 #ifndef final_version
517                 if (status == 0) {
518                         outb(0x05, ioaddr + 14);
519                         break;
520                 }
521 #endif
522
523                 if ((status & 0xF0) != 0x20) {  /* There was an error. */
524                         lp->stats.rx_errors++;
525                         if (status & 0x08) lp->stats.rx_length_errors++;
526                         if (status & 0x04) lp->stats.rx_frame_errors++;
527                         if (status & 0x02) lp->stats.rx_crc_errors++;
528                         if (status & 0x01) lp->stats.rx_over_errors++;
529                 } else {
530                         ushort pkt_len = inw(ioaddr + DATAPORT);
531                         /* Malloc up new buffer. */
532                         struct sk_buff *skb;
533
534                         if (pkt_len > 1550) {
535                                 printk("%s: The FMV-18x claimed a very large packet, size %d.\n",
536                                            dev->name, pkt_len);
537                                 outb(0x05, ioaddr + 14);
538                                 lp->stats.rx_errors++;
539                                 break;
540                         }
541                         skb = dev_alloc_skb(pkt_len+3);
542                         if (skb == NULL) {
543                                 printk("%s: Memory squeeze, dropping packet (len %d).\n",
544                                            dev->name, pkt_len);
545                                 outb(0x05, ioaddr + 14);
546                                 lp->stats.rx_dropped++;
547                                 break;
548                         }
549                         skb->dev = dev;
550                         skb_reserve(skb,2);
551
552                         insw(ioaddr + DATAPORT, skb_put(skb,pkt_len), (pkt_len + 1) >> 1);
553
554                         if (net_debug > 5) {
555                                 int i;
556                                 printk("%s: Rxed packet of length %d: ", dev->name, pkt_len);
557                                 for (i = 0; i < 14; i++)
558                                         printk(" %02x", skb->data[i]);
559                                 printk(".\n");
560                         }
561
562                         skb->protocol=eth_type_trans(skb, dev);
563                         netif_rx(skb);
564                         dev->last_rx = jiffies;
565                         lp->stats.rx_packets++;
566                         lp->stats.rx_bytes += pkt_len;
567                 }
568                 if (--boguscount <= 0)
569                         break;
570         }
571
572         /* If any worth-while packets have been received, dev_rint()
573            has done a mark_bh(NET_BH) for us and will work on them
574            when we get to the bottom-half routine. */
575         {
576                 int i;
577                 for (i = 0; i < 20; i++) {
578                         if ((inb(ioaddr + RX_MODE) & 0x40) == 0x40)
579                                 break;
580                         (void)inw(ioaddr + DATAPORT);                           /* dummy status read */
581                         outb(0x05, ioaddr + 14);
582                 }
583
584                 if (net_debug > 5 && i > 0)
585                         printk("%s: Exint Rx packet with mode %02x after %d ticks.\n",
586                                    dev->name, inb(ioaddr + RX_MODE), i);
587         }
588
589         return;
590 }
591
592 /* The inverse routine to net_open(). */
593 static int net_close(struct net_device *dev)
594 {
595         int ioaddr = dev->base_addr;
596
597         ((struct net_local *)dev->priv)->open_time = 0;
598
599         netif_stop_queue(dev);
600         
601         /* Set configuration register 0 to disable Tx and Rx. */
602         outb(0xda, ioaddr + CONFIG_0);
603
604         /* Update the statistics -- ToDo. */
605
606         /* Power-down the chip.  Green, green, green! */
607         outb(0x00, ioaddr + CONFIG_1);
608
609         /* Set the ethernet adaptor disable IRQ */
610         outb(0x00, ioaddr + FJ_CONFIG1);
611
612         return 0;
613 }
614
615 /* Get the current statistics.  This may be called with the card open or
616    closed. */
617 static struct net_device_stats *net_get_stats(struct net_device *dev)
618 {
619         struct net_local *lp = dev->priv;
620         return &lp->stats;
621 }
622
623 /* Set or clear the multicast filter for this adaptor.
624    num_addrs == -1      Promiscuous mode, receive all packets
625    num_addrs == 0       Normal mode, clear multicast list
626    num_addrs > 0        Multicast mode, receive normal and MC packets, and do
627                         best-effort filtering.
628  */
629  
630 static void set_multicast_list(struct net_device *dev)
631 {
632         short ioaddr = dev->base_addr;
633         if (dev->mc_count || dev->flags&(IFF_PROMISC|IFF_ALLMULTI))
634         {
635                 /*
636                  *      We must make the kernel realise we had to move
637                  *      into promisc mode or we start all out war on
638                  *      the cable. - AC
639                  */
640                 dev->flags|=IFF_PROMISC;
641
642                 outb(3, ioaddr + RX_MODE);      /* Enable promiscuous mode */
643         }
644         else
645                 outb(2, ioaddr + RX_MODE);      /* Disable promiscuous, use normal mode */
646 }
647
648 #ifdef MODULE
649 static struct net_device *dev_fmv18x;
650
651 MODULE_PARM(io, "i");
652 MODULE_PARM(irq, "i");
653 MODULE_PARM(net_debug, "i");
654 MODULE_PARM_DESC(io, "FMV-18X I/O address");
655 MODULE_PARM_DESC(irq, "FMV-18X IRQ number");
656 MODULE_PARM_DESC(net_debug, "FMV-18X debug level (0-1,5-6)");
657 MODULE_LICENSE("GPL");
658
659 int init_module(void)
660 {
661         if (io == 0)
662                 printk("fmv18x: You should not use auto-probing with insmod!\n");
663         dev_fmv18x = fmv18x_probe(-1);
664         if (IS_ERR(dev_fmv18x))
665                 return PTR_ERR(dev_fmv18x);
666         return 0;
667 }
668
669 void
670 cleanup_module(void)
671 {
672         unregister_netdev(dev_fmv18x);
673         free_irq(dev_fmv18x->irq, dev_fmv18x);
674         release_region(dev_fmv18x->base_addr, FMV18X_IO_EXTENT);
675         free_netdev(dev_fmv18x);
676 }
677 #endif /* MODULE */
678 \f
679 /*
680  * Local variables:
681  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c fmv18x.c"
682  *  version-control: t
683  *  kept-new-versions: 5
684  *  tab-width: 4
685  *  c-indent-level: 4
686  * End:
687  */