Merge Btrfs into fs/btrfs
[pandora-kernel.git] / drivers / net / 7990.c
1 /*
2  * 7990.c -- LANCE ethernet IC generic routines.
3  * This is an attempt to separate out the bits of various ethernet
4  * drivers that are common because they all use the AMD 7990 LANCE
5  * (Local Area Network Controller for Ethernet) chip.
6  *
7  * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk>
8  *
9  * Most of this stuff was obtained by looking at other LANCE drivers,
10  * in particular a2065.[ch]. The AMD C-LANCE datasheet was also helpful.
11  * NB: this was made easy by the fact that Jes Sorensen had cleaned up
12  * most of a2025 and sunlance with the aim of merging them, so the
13  * common code was pretty obvious.
14  */
15 #include <linux/crc32.h>
16 #include <linux/delay.h>
17 #include <linux/errno.h>
18 #include <linux/netdevice.h>
19 #include <linux/etherdevice.h>
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/types.h>
24 #include <linux/fcntl.h>
25 #include <linux/interrupt.h>
26 #include <linux/ioport.h>
27 #include <linux/in.h>
28 #include <linux/route.h>
29 #include <linux/slab.h>
30 #include <linux/string.h>
31 #include <linux/skbuff.h>
32 #include <asm/irq.h>
33 /* Used for the temporal inet entries and routing */
34 #include <linux/socket.h>
35 #include <linux/bitops.h>
36
37 #include <asm/system.h>
38 #include <asm/io.h>
39 #include <asm/dma.h>
40 #include <asm/pgtable.h>
41 #ifdef CONFIG_HP300
42 #include <asm/blinken.h>
43 #endif
44
45 #include "7990.h"
46
47 #define WRITERAP(lp,x) out_be16(lp->base + LANCE_RAP, (x))
48 #define WRITERDP(lp,x) out_be16(lp->base + LANCE_RDP, (x))
49 #define READRDP(lp) in_be16(lp->base + LANCE_RDP)
50
51 #if defined(CONFIG_HPLANCE) || defined(CONFIG_HPLANCE_MODULE)
52 #include "hplance.h"
53
54 #undef WRITERAP
55 #undef WRITERDP
56 #undef READRDP
57
58 #if defined(CONFIG_MVME147_NET) || defined(CONFIG_MVME147_NET_MODULE)
59
60 /* Lossage Factor Nine, Mr Sulu. */
61 #define WRITERAP(lp,x) (lp->writerap(lp,x))
62 #define WRITERDP(lp,x) (lp->writerdp(lp,x))
63 #define READRDP(lp) (lp->readrdp(lp))
64
65 #else
66
67 /* These inlines can be used if only CONFIG_HPLANCE is defined */
68 static inline void WRITERAP(struct lance_private *lp, __u16 value)
69 {
70         do {
71                 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
72         } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
73 }
74
75 static inline void WRITERDP(struct lance_private *lp, __u16 value)
76 {
77         do {
78                 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP, value);
79         } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
80 }
81
82 static inline __u16 READRDP(struct lance_private *lp)
83 {
84         __u16 value;
85         do {
86                 value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
87         } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
88         return value;
89 }
90
91 #endif
92 #endif /* CONFIG_HPLANCE || CONFIG_HPLANCE_MODULE */
93
94 /* debugging output macros, various flavours */
95 /* #define TEST_HITS */
96 #ifdef UNDEF
97 #define PRINT_RINGS() \
98 do { \
99         int t; \
100         for (t=0; t < RX_RING_SIZE; t++) { \
101                 printk("R%d: @(%02X %04X) len %04X, mblen %04X, bits %02X\n",\
102                        t, ib->brx_ring[t].rmd1_hadr, ib->brx_ring[t].rmd0,\
103                        ib->brx_ring[t].length,\
104                        ib->brx_ring[t].mblength, ib->brx_ring[t].rmd1_bits);\
105         }\
106         for (t=0; t < TX_RING_SIZE; t++) { \
107                 printk("T%d: @(%02X %04X) len %04X, misc %04X, bits %02X\n",\
108                        t, ib->btx_ring[t].tmd1_hadr, ib->btx_ring[t].tmd0,\
109                        ib->btx_ring[t].length,\
110                        ib->btx_ring[t].misc, ib->btx_ring[t].tmd1_bits);\
111         }\
112 } while (0)
113 #else
114 #define PRINT_RINGS()
115 #endif
116
117 /* Load the CSR registers. The LANCE has to be STOPped when we do this! */
118 static void load_csrs (struct lance_private *lp)
119 {
120         volatile struct lance_init_block *aib = lp->lance_init_block;
121         int leptr;
122
123         leptr = LANCE_ADDR (aib);
124
125         WRITERAP(lp, LE_CSR1);                    /* load address of init block */
126         WRITERDP(lp, leptr & 0xFFFF);
127         WRITERAP(lp, LE_CSR2);
128         WRITERDP(lp, leptr >> 16);
129         WRITERAP(lp, LE_CSR3);
130         WRITERDP(lp, lp->busmaster_regval);       /* set byteswap/ALEctrl/byte ctrl */
131
132         /* Point back to csr0 */
133         WRITERAP(lp, LE_CSR0);
134 }
135
136 /* #define to 0 or 1 appropriately */
137 #define DEBUG_IRING 0
138 /* Set up the Lance Rx and Tx rings and the init block */
139 static void lance_init_ring (struct net_device *dev)
140 {
141         struct lance_private *lp = netdev_priv(dev);
142         volatile struct lance_init_block *ib = lp->init_block;
143         volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */
144         int leptr;
145         int i;
146
147         aib = lp->lance_init_block;
148
149         lp->rx_new = lp->tx_new = 0;
150         lp->rx_old = lp->tx_old = 0;
151
152         ib->mode = LE_MO_PROM;                             /* normal, enable Tx & Rx */
153
154         /* Copy the ethernet address to the lance init block
155          * Notice that we do a byteswap if we're big endian.
156          * [I think this is the right criterion; at least, sunlance,
157          * a2065 and atarilance do the byteswap and lance.c (PC) doesn't.
158          * However, the datasheet says that the BSWAP bit doesn't affect
159          * the init block, so surely it should be low byte first for
160          * everybody? Um.]
161          * We could define the ib->physaddr as three 16bit values and
162          * use (addr[1] << 8) | addr[0] & co, but this is more efficient.
163          */
164 #ifdef __BIG_ENDIAN
165         ib->phys_addr [0] = dev->dev_addr [1];
166         ib->phys_addr [1] = dev->dev_addr [0];
167         ib->phys_addr [2] = dev->dev_addr [3];
168         ib->phys_addr [3] = dev->dev_addr [2];
169         ib->phys_addr [4] = dev->dev_addr [5];
170         ib->phys_addr [5] = dev->dev_addr [4];
171 #else
172         for (i=0; i<6; i++)
173            ib->phys_addr[i] = dev->dev_addr[i];
174 #endif
175
176         if (DEBUG_IRING)
177                 printk ("TX rings:\n");
178
179         lp->tx_full = 0;
180         /* Setup the Tx ring entries */
181         for (i = 0; i < (1<<lp->lance_log_tx_bufs); i++) {
182                 leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
183                 ib->btx_ring [i].tmd0      = leptr;
184                 ib->btx_ring [i].tmd1_hadr = leptr >> 16;
185                 ib->btx_ring [i].tmd1_bits = 0;
186                 ib->btx_ring [i].length    = 0xf000; /* The ones required by tmd2 */
187                 ib->btx_ring [i].misc      = 0;
188                 if (DEBUG_IRING)
189                    printk ("%d: 0x%8.8x\n", i, leptr);
190         }
191
192         /* Setup the Rx ring entries */
193         if (DEBUG_IRING)
194                 printk ("RX rings:\n");
195         for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) {
196                 leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
197
198                 ib->brx_ring [i].rmd0      = leptr;
199                 ib->brx_ring [i].rmd1_hadr = leptr >> 16;
200                 ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
201                 /* 0xf000 == bits that must be one (reserved, presumably) */
202                 ib->brx_ring [i].length    = -RX_BUFF_SIZE | 0xf000;
203                 ib->brx_ring [i].mblength  = 0;
204                 if (DEBUG_IRING)
205                         printk ("%d: 0x%8.8x\n", i, leptr);
206         }
207
208         /* Setup the initialization block */
209
210         /* Setup rx descriptor pointer */
211         leptr = LANCE_ADDR(&aib->brx_ring);
212         ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
213         ib->rx_ptr = leptr;
214         if (DEBUG_IRING)
215                 printk ("RX ptr: %8.8x\n", leptr);
216
217         /* Setup tx descriptor pointer */
218         leptr = LANCE_ADDR(&aib->btx_ring);
219         ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
220         ib->tx_ptr = leptr;
221         if (DEBUG_IRING)
222                 printk ("TX ptr: %8.8x\n", leptr);
223
224         /* Clear the multicast filter */
225         ib->filter [0] = 0;
226         ib->filter [1] = 0;
227         PRINT_RINGS();
228 }
229
230 /* LANCE must be STOPped before we do this, too... */
231 static int init_restart_lance (struct lance_private *lp)
232 {
233         int i;
234
235         WRITERAP(lp, LE_CSR0);
236         WRITERDP(lp, LE_C0_INIT);
237
238         /* Need a hook here for sunlance ledma stuff */
239
240         /* Wait for the lance to complete initialization */
241         for (i = 0; (i < 100) && !(READRDP(lp) & (LE_C0_ERR | LE_C0_IDON)); i++)
242                 barrier();
243         if ((i == 100) || (READRDP(lp) & LE_C0_ERR)) {
244                 printk ("LANCE unopened after %d ticks, csr0=%4.4x.\n", i, READRDP(lp));
245                 return -1;
246         }
247
248         /* Clear IDON by writing a "1", enable interrupts and start lance */
249         WRITERDP(lp, LE_C0_IDON);
250         WRITERDP(lp, LE_C0_INEA | LE_C0_STRT);
251
252         return 0;
253 }
254
255 static int lance_reset (struct net_device *dev)
256 {
257         struct lance_private *lp = netdev_priv(dev);
258         int status;
259
260         /* Stop the lance */
261         WRITERAP(lp, LE_CSR0);
262         WRITERDP(lp, LE_C0_STOP);
263
264         load_csrs (lp);
265         lance_init_ring (dev);
266         dev->trans_start = jiffies;
267         status = init_restart_lance (lp);
268 #ifdef DEBUG_DRIVER
269         printk ("Lance restart=%d\n", status);
270 #endif
271         return status;
272 }
273
274 static int lance_rx (struct net_device *dev)
275 {
276         struct lance_private *lp = netdev_priv(dev);
277         volatile struct lance_init_block *ib = lp->init_block;
278         volatile struct lance_rx_desc *rd;
279         unsigned char bits;
280 #ifdef TEST_HITS
281         int i;
282 #endif
283
284 #ifdef TEST_HITS
285         printk ("[");
286         for (i = 0; i < RX_RING_SIZE; i++) {
287                 if (i == lp->rx_new)
288                         printk ("%s",
289                                 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X");
290                 else
291                         printk ("%s",
292                                 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1");
293         }
294         printk ("]");
295 #endif
296 #ifdef CONFIG_HP300
297         blinken_leds(0x40, 0);
298 #endif
299         WRITERDP(lp, LE_C0_RINT | LE_C0_INEA);     /* ack Rx int, reenable ints */
300         for (rd = &ib->brx_ring [lp->rx_new];     /* For each Rx ring we own... */
301              !((bits = rd->rmd1_bits) & LE_R1_OWN);
302              rd = &ib->brx_ring [lp->rx_new]) {
303
304                 /* We got an incomplete frame? */
305                 if ((bits & LE_R1_POK) != LE_R1_POK) {
306                         dev->stats.rx_over_errors++;
307                         dev->stats.rx_errors++;
308                         continue;
309                 } else if (bits & LE_R1_ERR) {
310                         /* Count only the end frame as a rx error,
311                          * not the beginning
312                          */
313                         if (bits & LE_R1_BUF) dev->stats.rx_fifo_errors++;
314                         if (bits & LE_R1_CRC) dev->stats.rx_crc_errors++;
315                         if (bits & LE_R1_OFL) dev->stats.rx_over_errors++;
316                         if (bits & LE_R1_FRA) dev->stats.rx_frame_errors++;
317                         if (bits & LE_R1_EOP) dev->stats.rx_errors++;
318                 } else {
319                         int len = (rd->mblength & 0xfff) - 4;
320                         struct sk_buff *skb = dev_alloc_skb (len+2);
321
322                         if (!skb) {
323                                 printk ("%s: Memory squeeze, deferring packet.\n",
324                                         dev->name);
325                                 dev->stats.rx_dropped++;
326                                 rd->mblength = 0;
327                                 rd->rmd1_bits = LE_R1_OWN;
328                                 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
329                                 return 0;
330                         }
331
332                         skb_reserve (skb, 2);           /* 16 byte align */
333                         skb_put (skb, len);             /* make room */
334                         skb_copy_to_linear_data(skb,
335                                          (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
336                                          len);
337                         skb->protocol = eth_type_trans (skb, dev);
338                         netif_rx (skb);
339                         dev->last_rx = jiffies;
340                         dev->stats.rx_packets++;
341                         dev->stats.rx_bytes += len;
342                 }
343
344                 /* Return the packet to the pool */
345                 rd->mblength = 0;
346                 rd->rmd1_bits = LE_R1_OWN;
347                 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
348         }
349         return 0;
350 }
351
352 static int lance_tx (struct net_device *dev)
353 {
354         struct lance_private *lp = netdev_priv(dev);
355         volatile struct lance_init_block *ib = lp->init_block;
356         volatile struct lance_tx_desc *td;
357         int i, j;
358         int status;
359
360 #ifdef CONFIG_HP300
361         blinken_leds(0x80, 0);
362 #endif
363         /* csr0 is 2f3 */
364         WRITERDP(lp, LE_C0_TINT | LE_C0_INEA);
365         /* csr0 is 73 */
366
367         j = lp->tx_old;
368         for (i = j; i != lp->tx_new; i = j) {
369                 td = &ib->btx_ring [i];
370
371                 /* If we hit a packet not owned by us, stop */
372                 if (td->tmd1_bits & LE_T1_OWN)
373                         break;
374
375                 if (td->tmd1_bits & LE_T1_ERR) {
376                         status = td->misc;
377
378                         dev->stats.tx_errors++;
379                         if (status & LE_T3_RTY)  dev->stats.tx_aborted_errors++;
380                         if (status & LE_T3_LCOL) dev->stats.tx_window_errors++;
381
382                         if (status & LE_T3_CLOS) {
383                                 dev->stats.tx_carrier_errors++;
384                                 if (lp->auto_select) {
385                                         lp->tpe = 1 - lp->tpe;
386                                         printk("%s: Carrier Lost, trying %s\n",
387                                                dev->name, lp->tpe?"TPE":"AUI");
388                                         /* Stop the lance */
389                                         WRITERAP(lp, LE_CSR0);
390                                         WRITERDP(lp, LE_C0_STOP);
391                                         lance_init_ring (dev);
392                                         load_csrs (lp);
393                                         init_restart_lance (lp);
394                                         return 0;
395                                 }
396                         }
397
398                         /* buffer errors and underflows turn off the transmitter */
399                         /* Restart the adapter */
400                         if (status & (LE_T3_BUF|LE_T3_UFL)) {
401                                 dev->stats.tx_fifo_errors++;
402
403                                 printk ("%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
404                                         dev->name);
405                                 /* Stop the lance */
406                                 WRITERAP(lp, LE_CSR0);
407                                 WRITERDP(lp, LE_C0_STOP);
408                                 lance_init_ring (dev);
409                                 load_csrs (lp);
410                                 init_restart_lance (lp);
411                                 return 0;
412                         }
413                 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
414                         /*
415                          * So we don't count the packet more than once.
416                          */
417                         td->tmd1_bits &= ~(LE_T1_POK);
418
419                         /* One collision before packet was sent. */
420                         if (td->tmd1_bits & LE_T1_EONE)
421                                 dev->stats.collisions++;
422
423                         /* More than one collision, be optimistic. */
424                         if (td->tmd1_bits & LE_T1_EMORE)
425                                 dev->stats.collisions += 2;
426
427                         dev->stats.tx_packets++;
428                 }
429
430                 j = (j + 1) & lp->tx_ring_mod_mask;
431         }
432         lp->tx_old = j;
433         WRITERDP(lp, LE_C0_TINT | LE_C0_INEA);
434         return 0;
435 }
436
437 static irqreturn_t
438 lance_interrupt (int irq, void *dev_id)
439 {
440         struct net_device *dev = (struct net_device *)dev_id;
441         struct lance_private *lp = netdev_priv(dev);
442         int csr0;
443
444         spin_lock (&lp->devlock);
445
446         WRITERAP(lp, LE_CSR0);              /* LANCE Controller Status */
447         csr0 = READRDP(lp);
448
449         PRINT_RINGS();
450
451         if (!(csr0 & LE_C0_INTR)) {     /* Check if any interrupt has */
452                 spin_unlock (&lp->devlock);
453                 return IRQ_NONE;        /* been generated by the Lance. */
454         }
455
456         /* Acknowledge all the interrupt sources ASAP */
457         WRITERDP(lp, csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|LE_C0_INIT));
458
459         if ((csr0 & LE_C0_ERR)) {
460                 /* Clear the error condition */
461                 WRITERDP(lp, LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA);
462         }
463
464         if (csr0 & LE_C0_RINT)
465                 lance_rx (dev);
466
467         if (csr0 & LE_C0_TINT)
468                 lance_tx (dev);
469
470         /* Log misc errors. */
471         if (csr0 & LE_C0_BABL)
472                 dev->stats.tx_errors++;       /* Tx babble. */
473         if (csr0 & LE_C0_MISS)
474                 dev->stats.rx_errors++;       /* Missed a Rx frame. */
475         if (csr0 & LE_C0_MERR) {
476                 printk("%s: Bus master arbitration failure, status %4.4x.\n",
477                        dev->name, csr0);
478                 /* Restart the chip. */
479                 WRITERDP(lp, LE_C0_STRT);
480         }
481
482         if (lp->tx_full && netif_queue_stopped(dev) && (TX_BUFFS_AVAIL >= 0)) {
483                 lp->tx_full = 0;
484                 netif_wake_queue (dev);
485         }
486
487         WRITERAP(lp, LE_CSR0);
488         WRITERDP(lp, LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|LE_C0_IDON|LE_C0_INEA);
489
490         spin_unlock (&lp->devlock);
491         return IRQ_HANDLED;
492 }
493
494 int lance_open (struct net_device *dev)
495 {
496         struct lance_private *lp = netdev_priv(dev);
497         int res;
498
499         /* Install the Interrupt handler. Or we could shunt this out to specific drivers? */
500         if (request_irq(lp->irq, lance_interrupt, IRQF_SHARED, lp->name, dev))
501                 return -EAGAIN;
502
503         res = lance_reset(dev);
504         spin_lock_init(&lp->devlock);
505         netif_start_queue (dev);
506
507         return res;
508 }
509 EXPORT_SYMBOL_GPL(lance_open);
510
511 int lance_close (struct net_device *dev)
512 {
513         struct lance_private *lp = netdev_priv(dev);
514
515         netif_stop_queue (dev);
516
517         /* Stop the LANCE */
518         WRITERAP(lp, LE_CSR0);
519         WRITERDP(lp, LE_C0_STOP);
520
521         free_irq(lp->irq, dev);
522
523         return 0;
524 }
525 EXPORT_SYMBOL_GPL(lance_close);
526
527 void lance_tx_timeout(struct net_device *dev)
528 {
529         printk("lance_tx_timeout\n");
530         lance_reset(dev);
531         dev->trans_start = jiffies;
532         netif_wake_queue (dev);
533 }
534 EXPORT_SYMBOL_GPL(lance_tx_timeout);
535
536 int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
537 {
538         struct lance_private *lp = netdev_priv(dev);
539         volatile struct lance_init_block *ib = lp->init_block;
540         int entry, skblen, len;
541         static int outs;
542         unsigned long flags;
543
544         if (!TX_BUFFS_AVAIL)
545                 return -1;
546
547         netif_stop_queue (dev);
548
549         skblen = skb->len;
550
551 #ifdef DEBUG_DRIVER
552         /* dump the packet */
553         {
554                 int i;
555
556                 for (i = 0; i < 64; i++) {
557                         if ((i % 16) == 0)
558                                 printk ("\n");
559                         printk ("%2.2x ", skb->data [i]);
560                 }
561         }
562 #endif
563         len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
564         entry = lp->tx_new & lp->tx_ring_mod_mask;
565         ib->btx_ring [entry].length = (-len) | 0xf000;
566         ib->btx_ring [entry].misc = 0;
567
568         if (skb->len < ETH_ZLEN)
569                 memset((void *)&ib->tx_buf[entry][0], 0, ETH_ZLEN);
570         skb_copy_from_linear_data(skb, (void *)&ib->tx_buf[entry][0], skblen);
571
572         /* Now, give the packet to the lance */
573         ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
574         lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
575
576         outs++;
577         /* Kick the lance: transmit now */
578         WRITERDP(lp, LE_C0_INEA | LE_C0_TDMD);
579         dev->trans_start = jiffies;
580         dev_kfree_skb (skb);
581
582         spin_lock_irqsave (&lp->devlock, flags);
583         if (TX_BUFFS_AVAIL)
584                 netif_start_queue (dev);
585         else
586                 lp->tx_full = 1;
587         spin_unlock_irqrestore (&lp->devlock, flags);
588
589         return 0;
590 }
591 EXPORT_SYMBOL_GPL(lance_start_xmit);
592
593 /* taken from the depca driver via a2065.c */
594 static void lance_load_multicast (struct net_device *dev)
595 {
596         struct lance_private *lp = netdev_priv(dev);
597         volatile struct lance_init_block *ib = lp->init_block;
598         volatile u16 *mcast_table = (u16 *)&ib->filter;
599         struct dev_mc_list *dmi=dev->mc_list;
600         char *addrs;
601         int i;
602         u32 crc;
603
604         /* set all multicast bits */
605         if (dev->flags & IFF_ALLMULTI){
606                 ib->filter [0] = 0xffffffff;
607                 ib->filter [1] = 0xffffffff;
608                 return;
609         }
610         /* clear the multicast filter */
611         ib->filter [0] = 0;
612         ib->filter [1] = 0;
613
614         /* Add addresses */
615         for (i = 0; i < dev->mc_count; i++){
616                 addrs = dmi->dmi_addr;
617                 dmi   = dmi->next;
618
619                 /* multicast address? */
620                 if (!(*addrs & 1))
621                         continue;
622
623                 crc = ether_crc_le(6, addrs);
624                 crc = crc >> 26;
625                 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
626         }
627         return;
628 }
629
630
631 void lance_set_multicast (struct net_device *dev)
632 {
633         struct lance_private *lp = netdev_priv(dev);
634         volatile struct lance_init_block *ib = lp->init_block;
635         int stopped;
636
637         stopped = netif_queue_stopped(dev);
638         if (!stopped)
639                 netif_stop_queue (dev);
640
641         while (lp->tx_old != lp->tx_new)
642                 schedule();
643
644         WRITERAP(lp, LE_CSR0);
645         WRITERDP(lp, LE_C0_STOP);
646         lance_init_ring (dev);
647
648         if (dev->flags & IFF_PROMISC) {
649                 ib->mode |= LE_MO_PROM;
650         } else {
651                 ib->mode &= ~LE_MO_PROM;
652                 lance_load_multicast (dev);
653         }
654         load_csrs (lp);
655         init_restart_lance (lp);
656
657         if (!stopped)
658                 netif_start_queue (dev);
659 }
660 EXPORT_SYMBOL_GPL(lance_set_multicast);
661
662 #ifdef CONFIG_NET_POLL_CONTROLLER
663 void lance_poll(struct net_device *dev)
664 {
665         struct lance_private *lp = netdev_priv(dev);
666
667         spin_lock (&lp->devlock);
668         WRITERAP(lp, LE_CSR0);
669         WRITERDP(lp, LE_C0_STRT);
670         spin_unlock (&lp->devlock);
671         lance_interrupt(dev->irq, dev);
672 }
673 #endif
674
675 MODULE_LICENSE("GPL");