~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/net/a2065.c

Version: ~ [ 2.2.5 ] ~ [ 2.4.1 ] ~ [ 2.4.9 ] ~ [ 2.6.17.10 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Amiga Linux/68k A2065 Ethernet Driver
  3  *
  4  * (C) Copyright 1995 by Geert Uytterhoeven <geert@linux-m68k.org>
  5  *
  6  * Fixes and tips by:
  7  *      - Janos Farkas (CHEXUM@sparta.banki.hu)
  8  *      - Jes Degn Soerensen (jds@kom.auc.dk)
  9  *
 10  * ----------------------------------------------------------------------------
 11  *
 12  * This program is based on
 13  *
 14  *      ariadne.?:      Amiga Linux/68k Ariadne Ethernet Driver
 15  *                      (C) Copyright 1995 by Geert Uytterhoeven,
 16  *                                            Peter De Schrijver
 17  *
 18  *      lance.c:        An AMD LANCE ethernet driver for linux.
 19  *                      Written 1993-94 by Donald Becker.
 20  *
 21  *      Am79C960:       PCnet(tm)-ISA Single-Chip Ethernet Controller
 22  *                      Advanced Micro Devices
 23  *                      Publication #16907, Rev. B, Amendment/0, May 1994
 24  *
 25  * ----------------------------------------------------------------------------
 26  *
 27  * This file is subject to the terms and conditions of the GNU General Public
 28  * License.  See the file COPYING in the main directory of the Linux
 29  * distribution for more details.
 30  *
 31  * ----------------------------------------------------------------------------
 32  *
 33  * The A2065 is a Zorro-II board made by Commodore/Ameristar. It contains:
 34  *
 35  *      - an Am7990 Local Area Network Controller for Ethernet (LANCE) with
 36  *        both 10BASE-2 (thin coax) and AUI (DB-15) connectors
 37  */
 38 
 39 #include <linux/module.h>
 40 #include <linux/stddef.h>
 41 #include <linux/kernel.h>
 42 #include <linux/sched.h>
 43 #include <linux/interrupt.h>
 44 #include <linux/ptrace.h>
 45 #include <linux/ioport.h>
 46 #include <linux/malloc.h>
 47 #include <linux/string.h>
 48 #include <linux/config.h>
 49 #include <linux/init.h>
 50 
 51 #include <asm/bitops.h>
 52 #include <asm/io.h>
 53 #include <asm/irq.h>
 54 #include <linux/errno.h>
 55 
 56 #include <asm/amigaints.h>
 57 #include <asm/amigahw.h>
 58 #include <linux/zorro.h>
 59 
 60 #include <linux/netdevice.h>
 61 #include <linux/etherdevice.h>
 62 #include <linux/skbuff.h>
 63 #include "a2065.h"
 64 
 65 
 66         /*
 67          *              Transmit/Receive Ring Definitions
 68          */
 69 
 70 #define LANCE_LOG_TX_BUFFERS    (2)
 71 #define LANCE_LOG_RX_BUFFERS    (4)
 72 
 73 #define TX_RING_SIZE            (1<<LANCE_LOG_TX_BUFFERS)
 74 #define RX_RING_SIZE            (1<<LANCE_LOG_RX_BUFFERS)
 75 
 76 #define TX_RING_MOD_MASK        (TX_RING_SIZE-1)
 77 #define RX_RING_MOD_MASK        (RX_RING_SIZE-1)
 78 
 79 #define PKT_BUF_SIZE            (1544)
 80 #define RX_BUFF_SIZE            PKT_BUF_SIZE
 81 #define TX_BUFF_SIZE            PKT_BUF_SIZE
 82 
 83 
 84         /*
 85          *              Layout of the Lance's RAM Buffer
 86          */
 87 
 88 
 89 struct lance_init_block {
 90         unsigned short mode;            /* Pre-set mode (reg. 15) */
 91         unsigned char phys_addr[6];     /* Physical ethernet address */
 92         unsigned filter[2];             /* Multicast filter. */
 93 
 94         /* Receive and transmit ring base, along with extra bits. */
 95         unsigned short rx_ptr;          /* receive descriptor addr */
 96         unsigned short rx_len;          /* receive len and high addr */
 97         unsigned short tx_ptr;          /* transmit descriptor addr */
 98         unsigned short tx_len;          /* transmit len and high addr */
 99     
100         /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */
101         struct lance_rx_desc brx_ring[RX_RING_SIZE];
102         struct lance_tx_desc btx_ring[TX_RING_SIZE];
103 
104         char   rx_buf [RX_RING_SIZE][RX_BUFF_SIZE];
105         char   tx_buf [TX_RING_SIZE][TX_BUFF_SIZE];
106 };
107 
108 
109         /*
110          *              Private Device Data
111          */
112 
113 struct lance_private {
114         char *name;
115         volatile struct lance_regs *ll;
116         volatile struct lance_init_block *init_block;       /* Hosts view */
117         volatile struct lance_init_block *lance_init_block; /* Lance view */
118 
119         int rx_new, tx_new;
120         int rx_old, tx_old;
121     
122         int lance_log_rx_bufs, lance_log_tx_bufs;
123         int rx_ring_mod_mask, tx_ring_mod_mask;
124 
125         struct net_device_stats stats;
126         int tpe;                      /* cable-selection is TPE */
127         int auto_select;              /* cable-selection by carrier */
128         unsigned short busmaster_regval;
129 
130 #ifdef CONFIG_SUNLANCE
131         struct Linux_SBus_DMA *ledma; /* if set this points to ledma and arch=4m */
132         int burst_sizes;              /* ledma SBus burst sizes */
133 #endif
134         struct timer_list         multicast_timer;
135         struct net_device *dev;         /* Backpointer */
136         struct lance_private *next_module;
137 };
138 
139 #ifdef MODULE
140 static struct lance_private *root_a2065_dev = NULL;
141 #endif
142 
143 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
144                         lp->tx_old+lp->tx_ring_mod_mask-lp->tx_new:\
145                         lp->tx_old - lp->tx_new-1)
146 
147 
148 #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
149 
150 /* Load the CSR registers */
151 static void load_csrs (struct lance_private *lp)
152 {
153         volatile struct lance_regs *ll = lp->ll;
154         volatile struct lance_init_block *aib = lp->lance_init_block;
155         int leptr;
156 
157         leptr = LANCE_ADDR (aib);
158 
159         ll->rap = LE_CSR1;
160         ll->rdp = (leptr & 0xFFFF);
161         ll->rap = LE_CSR2;
162         ll->rdp = leptr >> 16;
163         ll->rap = LE_CSR3;
164         ll->rdp = lp->busmaster_regval;
165 
166         /* Point back to csr0 */
167         ll->rap = LE_CSR0;
168 }
169 
170 #define ZERO 0
171 
172 /* Setup the Lance Rx and Tx rings */
173 static void lance_init_ring (struct net_device *dev)
174 {
175         struct lance_private *lp = (struct lance_private *) dev->priv;
176         volatile struct lance_init_block *ib = lp->init_block;
177         volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */
178         int leptr;
179         int i;
180 
181         aib = lp->lance_init_block;
182 
183         /* Lock out other processes while setting up hardware */
184         netif_stop_queue(dev);
185         lp->rx_new = lp->tx_new = 0;
186         lp->rx_old = lp->tx_old = 0;
187 
188         ib->mode = 0;
189 
190         /* Copy the ethernet address to the lance init block
191          * Note that on the sparc you need to swap the ethernet address.
192          */
193         ib->phys_addr [0] = dev->dev_addr [1];
194         ib->phys_addr [1] = dev->dev_addr [0];
195         ib->phys_addr [2] = dev->dev_addr [3];
196         ib->phys_addr [3] = dev->dev_addr [2];
197         ib->phys_addr [4] = dev->dev_addr [5];
198         ib->phys_addr [5] = dev->dev_addr [4];
199 
200         if (ZERO)
201                 printk ("TX rings:\n");
202     
203         /* Setup the Tx ring entries */
204         for (i = 0; i <= (1<<lp->lance_log_tx_bufs); i++) {
205                 leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
206                 ib->btx_ring [i].tmd0      = leptr;
207                 ib->btx_ring [i].tmd1_hadr = leptr >> 16;
208                 ib->btx_ring [i].tmd1_bits = 0;
209                 ib->btx_ring [i].length    = 0xf000; /* The ones required by tmd2 */
210                 ib->btx_ring [i].misc      = 0;
211                 if (i < 3)
212                         if (ZERO) printk ("%d: 0x%8.8x\n", i, leptr);
213         }
214 
215         /* Setup the Rx ring entries */
216         if (ZERO)
217                 printk ("RX rings:\n");
218         for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) {
219                 leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
220 
221                 ib->brx_ring [i].rmd0      = leptr;
222                 ib->brx_ring [i].rmd1_hadr = leptr >> 16;
223                 ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
224                 ib->brx_ring [i].length    = -RX_BUFF_SIZE | 0xf000;
225                 ib->brx_ring [i].mblength  = 0;
226                 if (i < 3 && ZERO)
227                         printk ("%d: 0x%8.8x\n", i, leptr);
228         }
229 
230         /* Setup the initialization block */
231     
232         /* Setup rx descriptor pointer */
233         leptr = LANCE_ADDR(&aib->brx_ring);
234         ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
235         ib->rx_ptr = leptr;
236         if (ZERO)
237                 printk ("RX ptr: %8.8x\n", leptr);
238     
239         /* Setup tx descriptor pointer */
240         leptr = LANCE_ADDR(&aib->btx_ring);
241         ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
242         ib->tx_ptr = leptr;
243         if (ZERO)
244                 printk ("TX ptr: %8.8x\n", leptr);
245 
246         /* Clear the multicast filter */
247         ib->filter [0] = 0;
248         ib->filter [1] = 0;
249 }
250 
251 static int init_restart_lance (struct lance_private *lp)
252 {
253         volatile struct lance_regs *ll = lp->ll;
254         int i;
255 
256         ll->rap = LE_CSR0;
257         ll->rdp = LE_C0_INIT;
258 
259         /* Wait for the lance to complete initialization */
260         for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++)
261                 barrier();
262         if ((i == 100) || (ll->rdp & LE_C0_ERR)) {
263                 printk ("LANCE unopened after %d ticks, csr0=%4.4x.\n", i, ll->rdp);
264                 return -EIO;
265         }
266 
267         /* Clear IDON by writing a "1", enable interrupts and start lance */
268         ll->rdp = LE_C0_IDON;
269         ll->rdp = LE_C0_INEA | LE_C0_STRT;
270 
271         return 0;
272 }
273 
274 static int lance_rx (struct net_device *dev)
275 {
276         struct lance_private *lp = (struct lance_private *) dev->priv;
277         volatile struct lance_init_block *ib = lp->init_block;
278         volatile struct lance_regs *ll = lp->ll;
279         volatile struct lance_rx_desc *rd;
280         unsigned char bits;
281         int len = 0;                    /* XXX shut up gcc warnings */
282         struct sk_buff *skb = 0;        /* XXX shut up gcc warnings */
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     
297         ll->rdp = LE_C0_RINT|LE_C0_INEA;
298         for (rd = &ib->brx_ring [lp->rx_new];
299              !((bits = rd->rmd1_bits) & LE_R1_OWN);
300              rd = &ib->brx_ring [lp->rx_new]) {
301 
302                 /* We got an incomplete frame? */
303                 if ((bits & LE_R1_POK) != LE_R1_POK) {
304                         lp->stats.rx_over_errors++;
305                         lp->stats.rx_errors++;
306                         continue;
307                 } else if (bits & LE_R1_ERR) {
308                         /* Count only the end frame as a rx error,
309                          * not the beginning
310                          */
311                         if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++;
312                         if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++;
313                         if (bits & LE_R1_OFL) lp->stats.rx_over_errors++;
314                         if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++;
315                         if (bits & LE_R1_EOP) lp->stats.rx_errors++;
316                 } else {
317                         len = (rd->mblength & 0xfff) - 4;
318                         skb = dev_alloc_skb (len+2);
319 
320                         if (skb == 0) {
321                                 printk ("%s: Memory squeeze, deferring packet.\n",
322                                         dev->name);
323                                 lp->stats.rx_dropped++;
324                                 rd->mblength = 0;
325                                 rd->rmd1_bits = LE_R1_OWN;
326                                 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
327                                 return 0;
328                         }
329             
330                         skb->dev = dev;
331                         skb_reserve (skb, 2);           /* 16 byte align */
332                         skb_put (skb, len);             /* make room */
333                         eth_copy_and_sum(skb,
334                                          (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
335                                          len, 0);
336                         skb->protocol = eth_type_trans (skb, dev);
337                         netif_rx (skb);
338                         lp->stats.rx_packets++;
339                 }
340 
341                 /* Return the packet to the pool */
342                 rd->mblength = 0;
343                 rd->rmd1_bits = LE_R1_OWN;
344                 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
345         }
346         return 0;
347 }
348 
349 static int lance_tx (struct net_device *dev)
350 {
351         struct lance_private *lp = (struct lance_private *) dev->priv;
352         volatile struct lance_init_block *ib = lp->init_block;
353         volatile struct lance_regs *ll = lp->ll;
354         volatile struct lance_tx_desc *td;
355         int i, j;
356         int status;
357 
358         /* csr0 is 2f3 */
359         ll->rdp = LE_C0_TINT | LE_C0_INEA;
360         /* csr0 is 73 */
361 
362         j = lp->tx_old;
363         for (i = j; i != lp->tx_new; i = j) {
364                 td = &ib->btx_ring [i];
365 
366                 /* If we hit a packet not owned by us, stop */
367                 if (td->tmd1_bits & LE_T1_OWN)
368                         break;
369                 
370                 if (td->tmd1_bits & LE_T1_ERR) {
371                         status = td->misc;
372             
373                         lp->stats.tx_errors++;
374                         if (status & LE_T3_RTY)  lp->stats.tx_aborted_errors++;
375                         if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
376 
377                         if (status & LE_T3_CLOS) {
378                                 lp->stats.tx_carrier_errors++;
379                                 if (lp->auto_select) {
380                                         lp->tpe = 1 - lp->tpe;
381                                         printk("%s: Carrier Lost, trying %s\n",
382                                                dev->name, lp->tpe?"TPE":"AUI");
383                                         /* Stop the lance */
384                                         ll->rap = LE_CSR0;
385                                         ll->rdp = LE_C0_STOP;
386                                         lance_init_ring (dev);
387                                         load_csrs (lp);
388                                         init_restart_lance (lp);
389                                         return 0;
390                                 }
391                         }
392 
393                         /* buffer errors and underflows turn off the transmitter */
394                         /* Restart the adapter */
395                         if (status & (LE_T3_BUF|LE_T3_UFL)) {
396                                 lp->stats.tx_fifo_errors++;
397 
398                                 printk ("%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
399                                         dev->name);
400                                 /* Stop the lance */
401                                 ll->rap = LE_CSR0;
402                                 ll->rdp = LE_C0_STOP;
403                                 lance_init_ring (dev);
404                                 load_csrs (lp);
405                                 init_restart_lance (lp);
406                                 return 0;
407                         }
408                 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
409                         /*
410                          * So we don't count the packet more than once.
411                          */
412                         td->tmd1_bits &= ~(LE_T1_POK);
413 
414                         /* One collision before packet was sent. */
415                         if (td->tmd1_bits & LE_T1_EONE)
416                                 lp->stats.collisions++;
417 
418                         /* More than one collision, be optimistic. */
419                         if (td->tmd1_bits & LE_T1_EMORE)
420                                 lp->stats.collisions += 2;
421 
422                         lp->stats.tx_packets++;
423                 }
424         
425                 j = (j + 1) & lp->tx_ring_mod_mask;
426         }
427         lp->tx_old = j;
428         ll->rdp = LE_C0_TINT | LE_C0_INEA;
429         return 0;
430 }
431 
432 static void lance_interrupt (int irq, void *dev_id, struct pt_regs *regs)
433 {
434         struct net_device *dev;
435         struct lance_private *lp;
436         volatile struct lance_regs *ll;
437         int csr0;
438 
439         dev = (struct net_device *) dev_id;
440 
441         lp = (struct lance_private *) dev->priv;
442         ll = lp->ll;
443 
444         ll->rap = LE_CSR0;              /* LANCE Controller Status */
445         csr0 = ll->rdp;
446 
447         if (!(csr0 & LE_C0_INTR))       /* Check if any interrupt has */
448                 return;                 /* been generated by the Lance. */
449 
450         /* Acknowledge all the interrupt sources ASAP */
451         ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|
452                            LE_C0_INIT);
453 
454         if ((csr0 & LE_C0_ERR)) {
455                 /* Clear the error condition */
456                 ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
457         }
458     
459         if (csr0 & LE_C0_RINT)
460                 lance_rx (dev);
461 
462         if (csr0 & LE_C0_TINT)
463                 lance_tx (dev);
464 
465         /* Log misc errors. */
466         if (csr0 & LE_C0_BABL)
467                 lp->stats.tx_errors++;       /* Tx babble. */
468         if (csr0 & LE_C0_MISS)
469                 lp->stats.rx_errors++;       /* Missed a Rx frame. */
470         if (csr0 & LE_C0_MERR) {
471                 printk("%s: Bus master arbitration failure, status %4.4x.\n", dev->name, csr0);
472                 /* Restart the chip. */
473                 ll->rdp = LE_C0_STRT;
474         }
475 
476         if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
477                 netif_wake_queue(dev);
478 
479         ll->rap = LE_CSR0;
480         ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
481                                         LE_C0_IDON|LE_C0_INEA;
482 
483 }
484 
485 struct net_device *last_dev = 0;
486 
487 static int lance_open (struct net_device *dev)
488 {
489         struct lance_private *lp = (struct lance_private *)dev->priv;
490         volatile struct lance_regs *ll = lp->ll;
491         int ret;
492 
493         last_dev = dev;
494 
495         /* Install the Interrupt handler */
496         ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, SA_SHIRQ,
497                           dev->name, dev);
498         if (ret) return ret;
499 
500         /* Stop the Lance */
501         ll->rap = LE_CSR0;
502         ll->rdp = LE_C0_STOP;
503 
504         load_csrs (lp);
505         lance_init_ring (dev);
506 
507         netif_start_queue(dev);
508 
509         return init_restart_lance (lp);
510 }
511 
512 static int lance_close (struct net_device *dev)
513 {
514         struct lance_private *lp = (struct lance_private *) dev->priv;
515         volatile struct lance_regs *ll = lp->ll;
516 
517         netif_stop_queue(dev);
518         del_timer_sync(&lp->multicast_timer);
519 
520         /* Stop the card */
521         ll->rap = LE_CSR0;
522         ll->rdp = LE_C0_STOP;
523 
524         free_irq(IRQ_AMIGA_PORTS, dev);
525         return 0;
526 }
527 
528 static inline int lance_reset (struct net_device *dev)
529 {
530         struct lance_private *lp = (struct lance_private *)dev->priv;
531         volatile struct lance_regs *ll = lp->ll;
532         int status;
533     
534         /* Stop the lance */
535         ll->rap = LE_CSR0;
536         ll->rdp = LE_C0_STOP;
537 
538         load_csrs (lp);
539 
540         lance_init_ring (dev);
541         dev->trans_start = jiffies;
542         netif_start_queue(dev);
543 
544         status = init_restart_lance (lp);
545 #ifdef DEBUG_DRIVER
546         printk ("Lance restart=%d\n", status);
547 #endif
548         return status;
549 }
550 
551 static void lance_tx_timeout(struct net_device *dev)
552 {
553         struct lance_private *lp = (struct lance_private *) dev->priv;
554         volatile struct lance_regs *ll = lp->ll;
555 
556         printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
557                dev->name, ll->rdp);
558         lance_reset(dev);
559         netif_wake_queue(dev);
560 }
561 
562 static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
563 {
564         struct lance_private *lp = (struct lance_private *)dev->priv;
565         volatile struct lance_regs *ll = lp->ll;
566         volatile struct lance_init_block *ib = lp->init_block;
567         int entry, skblen, len;
568         int status = 0;
569         static int outs;
570         unsigned long flags;
571 
572         skblen = skb->len;
573 
574         save_flags(flags);
575         cli();
576 
577         if (!TX_BUFFS_AVAIL){
578                 restore_flags(flags);
579                 return -1;
580         }
581 
582 #ifdef DEBUG_DRIVER
583         /* dump the packet */
584         {
585                 int i;
586         
587                 for (i = 0; i < 64; i++) {
588                         if ((i % 16) == 0)
589                                 printk ("\n");
590                         printk ("%2.2x ", skb->data [i]);
591                 }
592         }
593 #endif
594         len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
595         entry = lp->tx_new & lp->tx_ring_mod_mask;
596         ib->btx_ring [entry].length = (-len) | 0xf000;
597         ib->btx_ring [entry].misc = 0;
598     
599         memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
600 
601         /* Clear the slack of the packet, do I need this? */
602         if (len != skblen)
603                 memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen);
604     
605         /* Now, give the packet to the lance */
606         ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
607         lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
608 
609         outs++;
610 
611         if (TX_BUFFS_AVAIL <= 0)
612                 netif_stop_queue(dev);
613 
614         /* Kick the lance: transmit now */
615         ll->rdp = LE_C0_INEA | LE_C0_TDMD;
616         dev->trans_start = jiffies;
617         dev_kfree_skb (skb);
618     
619         restore_flags(flags);
620 
621         return status;
622 }
623 
624 static struct net_device_stats *lance_get_stats (struct net_device *dev)
625 {
626         struct lance_private *lp = (struct lance_private *) dev->priv;
627 
628         return &lp->stats;
629 }
630 
631 /* taken from the depca driver */
632 static void lance_load_multicast (struct net_device *dev)
633 {
634         struct lance_private *lp = (struct lance_private *) dev->priv;
635         volatile struct lance_init_block *ib = lp->init_block;
636         volatile u16 *mcast_table = (u16 *)&ib->filter;
637         struct dev_mc_list *dmi=dev->mc_list;
638         char *addrs;
639         int i, j, bit, byte;
640         u32 crc, poly = CRC_POLYNOMIAL_LE;
641         
642         /* set all multicast bits */
643         if (dev->flags & IFF_ALLMULTI){ 
644                 ib->filter [0] = 0xffffffff;
645                 ib->filter [1] = 0xffffffff;
646                 return;
647         }
648         /* clear the multicast filter */
649         ib->filter [0] = 0;
650         ib->filter [1] = 0;
651 
652         /* Add addresses */
653         for (i = 0; i < dev->mc_count; i++){
654                 addrs = dmi->dmi_addr;
655                 dmi   = dmi->next;
656 
657                 /* multicast address? */
658                 if (!(*addrs & 1))
659                         continue;
660                 
661                 crc = 0xffffffff;
662                 for (byte = 0; byte < 6; byte++)
663                         for (bit = *addrs++, j = 0; j < 8; j++, bit>>=1)
664                         {
665                                 int test;
666 
667                                 test = ((bit ^ crc) & 0x01);
668                                 crc >>= 1;
669 
670                                 if (test)
671                                 {
672                                         crc = crc ^ poly;
673                                 }
674                         }
675                 
676                 crc = crc >> 26;
677                 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
678         }
679         return;
680 }
681 
682 static void lance_set_multicast (struct net_device *dev)
683 {
684         struct lance_private *lp = (struct lance_private *) dev->priv;
685         volatile struct lance_init_block *ib = lp->init_block;
686         volatile struct lance_regs *ll = lp->ll;
687 
688         if (!netif_running(dev))
689                 return;
690 
691         if (lp->tx_old != lp->tx_new) {
692                 mod_timer(&lp->multicast_timer, jiffies + 4);
693                 netif_wake_queue(dev);
694                 return;
695         }
696 
697         netif_stop_queue(dev);
698 
699         ll->rap = LE_CSR0;
700         ll->rdp = LE_C0_STOP;
701         lance_init_ring (dev);
702 
703         if (dev->flags & IFF_PROMISC) {
704                 ib->mode |= LE_MO_PROM;
705         } else {
706                 ib->mode &= ~LE_MO_PROM;
707                 lance_load_multicast (dev);
708         }
709         load_csrs (lp);
710         init_restart_lance (lp);
711         netif_wake_queue(dev);
712 }
713 
714 static int __init a2065_probe(void)
715 {
716         struct zorro_dev *z = NULL;
717         struct net_device *dev;
718         struct lance_private *priv;
719         int res = -ENODEV;
720 
721         while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
722                 unsigned long board, base_addr, mem_start;
723                 struct resource *r1, *r2;
724                 int is_cbm;
725 
726                 if (z->id == ZORRO_PROD_CBM_A2065_1 ||
727                     z->id == ZORRO_PROD_CBM_A2065_2)
728                         is_cbm = 1;
729                 else if (z->id == ZORRO_PROD_AMERISTAR_A2065)
730                         is_cbm = 0;
731                 else
732                         continue;
733 
734                 board = z->resource.start;
735                 base_addr = board+A2065_LANCE;
736                 mem_start = board+A2065_RAM;
737 
738                 r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
739                                         "Am7990");
740                 if (!r1) continue;
741                 r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
742                 if (!r2) {
743                         release_resource(r1);
744                         continue;
745                 }
746 
747                 dev = init_etherdev(NULL, sizeof(struct lance_private));
748 
749                 if (dev == NULL) {
750                         release_resource(r1);
751                         release_resource(r2);
752                         return -ENOMEM;
753                 }
754                 SET_MODULE_OWNER(dev);
755                 priv = dev->priv;
756 
757                 r1->name = dev->name;
758                 r2->name = dev->name;
759 
760                 priv->dev = dev;
761                 dev->dev_addr[0] = 0x00;
762                 if (is_cbm) {                           /* Commodore */
763                         dev->dev_addr[1] = 0x80;
764                         dev->dev_addr[2] = 0x10;
765                 } else {                                /* Ameristar */
766                         dev->dev_addr[1] = 0x00;
767                         dev->dev_addr[2] = 0x9f;
768                 }
769                 dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
770                 dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
771                 dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
772                 printk("%s: A2065 at 0x%08lx, Ethernet Address "
773                        "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board,
774                        dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
775                        dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
776 
777                 dev->base_addr = ZTWO_VADDR(base_addr);
778                 dev->mem_start = ZTWO_VADDR(mem_start);
779                 dev->mem_end = dev->mem_start+A2065_RAM_SIZE;
780 
781                 priv->ll = (volatile struct lance_regs *)dev->base_addr;
782                 priv->init_block = (struct lance_init_block *)dev->mem_start;
783                 priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
784                 priv->auto_select = 0;
785                 priv->busmaster_regval = LE_C3_BSWP;
786 
787                 priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
788                 priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
789                 priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
790                 priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
791 
792                 dev->open = &lance_open;
793                 dev->stop = &lance_close;
794                 dev->hard_start_xmit = &lance_start_xmit;
795                 dev->tx_timeout = &lance_tx_timeout;
796                 dev->watchdog_timeo = 5*HZ;
797                 dev->get_stats = &lance_get_stats;
798                 dev->set_multicast_list = &lance_set_multicast;
799                 dev->dma = 0;
800 
801 #ifdef MODULE
802                 priv->next_module = root_a2065_dev;
803                 root_a2065_dev = priv;
804 #endif
805                 ether_setup(dev);
806                 init_timer(&priv->multicast_timer);
807                 priv->multicast_timer.data = (unsigned long) dev;
808                 priv->multicast_timer.function =
809                         (void (*)(unsigned long)) &lance_set_multicast;
810 
811                 res = 0;
812         }
813         return res;
814 }
815 
816 
817 static void __exit a2065_cleanup(void)
818 {
819 #ifdef MODULE
820         struct lance_private *next;
821         struct net_device *dev;
822 
823         while (root_a2065_dev) {
824                 next = root_a2065_dev->next_module;
825                 dev = root_a2065_dev->dev;
826                 unregister_netdev(dev);
827                 release_mem_region(ZTWO_PADDR(dev->base_addr),
828                                    sizeof(struct lance_regs));
829                 release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
830                 kfree(dev);
831                 root_a2065_dev = next;
832         }
833 #endif
834 }
835 
836 module_init(a2065_probe);
837 module_exit(a2065_cleanup);
838 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.