File: /usr/src/linux/drivers/net/a2065.c
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/slab.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;
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 dev->last_rx = jiffies;
339 lp->stats.rx_packets++;
340 lp->stats.rx_bytes += len;
341 }
342
343 /* Return the packet to the pool */
344 rd->mblength = 0;
345 rd->rmd1_bits = LE_R1_OWN;
346 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
347 }
348 return 0;
349 }
350
351 static int lance_tx (struct net_device *dev)
352 {
353 struct lance_private *lp = (struct lance_private *) dev->priv;
354 volatile struct lance_init_block *ib = lp->init_block;
355 volatile struct lance_regs *ll = lp->ll;
356 volatile struct lance_tx_desc *td;
357 int i, j;
358 int status;
359
360 /* csr0 is 2f3 */
361 ll->rdp = LE_C0_TINT | LE_C0_INEA;
362 /* csr0 is 73 */
363
364 j = lp->tx_old;
365 for (i = j; i != lp->tx_new; i = j) {
366 td = &ib->btx_ring [i];
367
368 /* If we hit a packet not owned by us, stop */
369 if (td->tmd1_bits & LE_T1_OWN)
370 break;
371
372 if (td->tmd1_bits & LE_T1_ERR) {
373 status = td->misc;
374
375 lp->stats.tx_errors++;
376 if (status & LE_T3_RTY) lp->stats.tx_aborted_errors++;
377 if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
378
379 if (status & LE_T3_CLOS) {
380 lp->stats.tx_carrier_errors++;
381 if (lp->auto_select) {
382 lp->tpe = 1 - lp->tpe;
383 printk("%s: Carrier Lost, trying %s\n",
384 dev->name, lp->tpe?"TPE":"AUI");
385 /* Stop the lance */
386 ll->rap = LE_CSR0;
387 ll->rdp = LE_C0_STOP;
388 lance_init_ring (dev);
389 load_csrs (lp);
390 init_restart_lance (lp);
391 return 0;
392 }
393 }
394
395 /* buffer errors and underflows turn off the transmitter */
396 /* Restart the adapter */
397 if (status & (LE_T3_BUF|LE_T3_UFL)) {
398 lp->stats.tx_fifo_errors++;
399
400 printk ("%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
401 dev->name);
402 /* Stop the lance */
403 ll->rap = LE_CSR0;
404 ll->rdp = LE_C0_STOP;
405 lance_init_ring (dev);
406 load_csrs (lp);
407 init_restart_lance (lp);
408 return 0;
409 }
410 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
411 /*
412 * So we don't count the packet more than once.
413 */
414 td->tmd1_bits &= ~(LE_T1_POK);
415
416 /* One collision before packet was sent. */
417 if (td->tmd1_bits & LE_T1_EONE)
418 lp->stats.collisions++;
419
420 /* More than one collision, be optimistic. */
421 if (td->tmd1_bits & LE_T1_EMORE)
422 lp->stats.collisions += 2;
423
424 lp->stats.tx_packets++;
425 }
426
427 j = (j + 1) & lp->tx_ring_mod_mask;
428 }
429 lp->tx_old = j;
430 ll->rdp = LE_C0_TINT | LE_C0_INEA;
431 return 0;
432 }
433
434 static void lance_interrupt (int irq, void *dev_id, struct pt_regs *regs)
435 {
436 struct net_device *dev;
437 struct lance_private *lp;
438 volatile struct lance_regs *ll;
439 int csr0;
440
441 dev = (struct net_device *) dev_id;
442
443 lp = (struct lance_private *) dev->priv;
444 ll = lp->ll;
445
446 ll->rap = LE_CSR0; /* LANCE Controller Status */
447 csr0 = ll->rdp;
448
449 if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */
450 return; /* been generated by the Lance. */
451
452 /* Acknowledge all the interrupt sources ASAP */
453 ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|
454 LE_C0_INIT);
455
456 if ((csr0 & LE_C0_ERR)) {
457 /* Clear the error condition */
458 ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
459 }
460
461 if (csr0 & LE_C0_RINT)
462 lance_rx (dev);
463
464 if (csr0 & LE_C0_TINT)
465 lance_tx (dev);
466
467 /* Log misc errors. */
468 if (csr0 & LE_C0_BABL)
469 lp->stats.tx_errors++; /* Tx babble. */
470 if (csr0 & LE_C0_MISS)
471 lp->stats.rx_errors++; /* Missed a Rx frame. */
472 if (csr0 & LE_C0_MERR) {
473 printk("%s: Bus master arbitration failure, status %4.4x.\n", dev->name, csr0);
474 /* Restart the chip. */
475 ll->rdp = LE_C0_STRT;
476 }
477
478 if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
479 netif_wake_queue(dev);
480
481 ll->rap = LE_CSR0;
482 ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
483 LE_C0_IDON|LE_C0_INEA;
484
485 }
486
487 struct net_device *last_dev = 0;
488
489 static int lance_open (struct net_device *dev)
490 {
491 struct lance_private *lp = (struct lance_private *)dev->priv;
492 volatile struct lance_regs *ll = lp->ll;
493 int ret;
494
495 last_dev = dev;
496
497 /* Install the Interrupt handler */
498 ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, SA_SHIRQ,
499 dev->name, dev);
500 if (ret) return ret;
501
502 /* Stop the Lance */
503 ll->rap = LE_CSR0;
504 ll->rdp = LE_C0_STOP;
505
506 load_csrs (lp);
507 lance_init_ring (dev);
508
509 netif_start_queue(dev);
510
511 return init_restart_lance (lp);
512 }
513
514 static int lance_close (struct net_device *dev)
515 {
516 struct lance_private *lp = (struct lance_private *) dev->priv;
517 volatile struct lance_regs *ll = lp->ll;
518
519 netif_stop_queue(dev);
520 del_timer_sync(&lp->multicast_timer);
521
522 /* Stop the card */
523 ll->rap = LE_CSR0;
524 ll->rdp = LE_C0_STOP;
525
526 free_irq(IRQ_AMIGA_PORTS, dev);
527 return 0;
528 }
529
530 static inline int lance_reset (struct net_device *dev)
531 {
532 struct lance_private *lp = (struct lance_private *)dev->priv;
533 volatile struct lance_regs *ll = lp->ll;
534 int status;
535
536 /* Stop the lance */
537 ll->rap = LE_CSR0;
538 ll->rdp = LE_C0_STOP;
539
540 load_csrs (lp);
541
542 lance_init_ring (dev);
543 dev->trans_start = jiffies;
544 netif_start_queue(dev);
545
546 status = init_restart_lance (lp);
547 #ifdef DEBUG_DRIVER
548 printk ("Lance restart=%d\n", status);
549 #endif
550 return status;
551 }
552
553 static void lance_tx_timeout(struct net_device *dev)
554 {
555 struct lance_private *lp = (struct lance_private *) dev->priv;
556 volatile struct lance_regs *ll = lp->ll;
557
558 printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
559 dev->name, ll->rdp);
560 lance_reset(dev);
561 netif_wake_queue(dev);
562 }
563
564 static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
565 {
566 struct lance_private *lp = (struct lance_private *)dev->priv;
567 volatile struct lance_regs *ll = lp->ll;
568 volatile struct lance_init_block *ib = lp->init_block;
569 int entry, skblen, len;
570 int status = 0;
571 static int outs;
572 unsigned long flags;
573
574 skblen = skb->len;
575
576 save_flags(flags);
577 cli();
578
579 if (!TX_BUFFS_AVAIL){
580 restore_flags(flags);
581 return -1;
582 }
583
584 #ifdef DEBUG_DRIVER
585 /* dump the packet */
586 {
587 int i;
588
589 for (i = 0; i < 64; i++) {
590 if ((i % 16) == 0)
591 printk ("\n");
592 printk ("%2.2x ", skb->data [i]);
593 }
594 }
595 #endif
596 len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
597 entry = lp->tx_new & lp->tx_ring_mod_mask;
598 ib->btx_ring [entry].length = (-len) | 0xf000;
599 ib->btx_ring [entry].misc = 0;
600
601 memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
602
603 /* Clear the slack of the packet, do I need this? */
604 if (len != skblen)
605 memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen);
606
607 /* Now, give the packet to the lance */
608 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
609 lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
610
611 outs++;
612
613 if (TX_BUFFS_AVAIL <= 0)
614 netif_stop_queue(dev);
615
616 /* Kick the lance: transmit now */
617 ll->rdp = LE_C0_INEA | LE_C0_TDMD;
618 dev->trans_start = jiffies;
619 dev_kfree_skb (skb);
620
621 restore_flags(flags);
622
623 return status;
624 }
625
626 static struct net_device_stats *lance_get_stats (struct net_device *dev)
627 {
628 struct lance_private *lp = (struct lance_private *) dev->priv;
629
630 return &lp->stats;
631 }
632
633 /* taken from the depca driver */
634 static void lance_load_multicast (struct net_device *dev)
635 {
636 struct lance_private *lp = (struct lance_private *) dev->priv;
637 volatile struct lance_init_block *ib = lp->init_block;
638 volatile u16 *mcast_table = (u16 *)&ib->filter;
639 struct dev_mc_list *dmi=dev->mc_list;
640 char *addrs;
641 int i, j, bit, byte;
642 u32 crc, poly = CRC_POLYNOMIAL_LE;
643
644 /* set all multicast bits */
645 if (dev->flags & IFF_ALLMULTI){
646 ib->filter [0] = 0xffffffff;
647 ib->filter [1] = 0xffffffff;
648 return;
649 }
650 /* clear the multicast filter */
651 ib->filter [0] = 0;
652 ib->filter [1] = 0;
653
654 /* Add addresses */
655 for (i = 0; i < dev->mc_count; i++){
656 addrs = dmi->dmi_addr;
657 dmi = dmi->next;
658
659 /* multicast address? */
660 if (!(*addrs & 1))
661 continue;
662
663 crc = 0xffffffff;
664 for (byte = 0; byte < 6; byte++)
665 for (bit = *addrs++, j = 0; j < 8; j++, bit>>=1)
666 {
667 int test;
668
669 test = ((bit ^ crc) & 0x01);
670 crc >>= 1;
671
672 if (test)
673 {
674 crc = crc ^ poly;
675 }
676 }
677
678 crc = crc >> 26;
679 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
680 }
681 return;
682 }
683
684 static void lance_set_multicast (struct net_device *dev)
685 {
686 struct lance_private *lp = (struct lance_private *) dev->priv;
687 volatile struct lance_init_block *ib = lp->init_block;
688 volatile struct lance_regs *ll = lp->ll;
689
690 if (!netif_running(dev))
691 return;
692
693 if (lp->tx_old != lp->tx_new) {
694 mod_timer(&lp->multicast_timer, jiffies + 4);
695 netif_wake_queue(dev);
696 return;
697 }
698
699 netif_stop_queue(dev);
700
701 ll->rap = LE_CSR0;
702 ll->rdp = LE_C0_STOP;
703 lance_init_ring (dev);
704
705 if (dev->flags & IFF_PROMISC) {
706 ib->mode |= LE_MO_PROM;
707 } else {
708 ib->mode &= ~LE_MO_PROM;
709 lance_load_multicast (dev);
710 }
711 load_csrs (lp);
712 init_restart_lance (lp);
713 netif_wake_queue(dev);
714 }
715
716 static int __init a2065_probe(void)
717 {
718 struct zorro_dev *z = NULL;
719 struct net_device *dev;
720 struct lance_private *priv;
721 int res = -ENODEV;
722
723 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
724 unsigned long board, base_addr, mem_start;
725 struct resource *r1, *r2;
726 int is_cbm;
727
728 if (z->id == ZORRO_PROD_CBM_A2065_1 ||
729 z->id == ZORRO_PROD_CBM_A2065_2)
730 is_cbm = 1;
731 else if (z->id == ZORRO_PROD_AMERISTAR_A2065)
732 is_cbm = 0;
733 else
734 continue;
735
736 board = z->resource.start;
737 base_addr = board+A2065_LANCE;
738 mem_start = board+A2065_RAM;
739
740 r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
741 "Am7990");
742 if (!r1) continue;
743 r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
744 if (!r2) {
745 release_resource(r1);
746 continue;
747 }
748
749 dev = init_etherdev(NULL, sizeof(struct lance_private));
750
751 if (dev == NULL) {
752 release_resource(r1);
753 release_resource(r2);
754 return -ENOMEM;
755 }
756 SET_MODULE_OWNER(dev);
757 priv = dev->priv;
758
759 r1->name = dev->name;
760 r2->name = dev->name;
761
762 priv->dev = dev;
763 dev->dev_addr[0] = 0x00;
764 if (is_cbm) { /* Commodore */
765 dev->dev_addr[1] = 0x80;
766 dev->dev_addr[2] = 0x10;
767 } else { /* Ameristar */
768 dev->dev_addr[1] = 0x00;
769 dev->dev_addr[2] = 0x9f;
770 }
771 dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
772 dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
773 dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
774 printk("%s: A2065 at 0x%08lx, Ethernet Address "
775 "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board,
776 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
777 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
778
779 dev->base_addr = ZTWO_VADDR(base_addr);
780 dev->mem_start = ZTWO_VADDR(mem_start);
781 dev->mem_end = dev->mem_start+A2065_RAM_SIZE;
782
783 priv->ll = (volatile struct lance_regs *)dev->base_addr;
784 priv->init_block = (struct lance_init_block *)dev->mem_start;
785 priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
786 priv->auto_select = 0;
787 priv->busmaster_regval = LE_C3_BSWP;
788
789 priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
790 priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
791 priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
792 priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
793
794 dev->open = &lance_open;
795 dev->stop = &lance_close;
796 dev->hard_start_xmit = &lance_start_xmit;
797 dev->tx_timeout = &lance_tx_timeout;
798 dev->watchdog_timeo = 5*HZ;
799 dev->get_stats = &lance_get_stats;
800 dev->set_multicast_list = &lance_set_multicast;
801 dev->dma = 0;
802
803 #ifdef MODULE
804 priv->next_module = root_a2065_dev;
805 root_a2065_dev = priv;
806 #endif
807 ether_setup(dev);
808 init_timer(&priv->multicast_timer);
809 priv->multicast_timer.data = (unsigned long) dev;
810 priv->multicast_timer.function =
811 (void (*)(unsigned long)) &lance_set_multicast;
812
813 res = 0;
814 }
815 return res;
816 }
817
818
819 static void __exit a2065_cleanup(void)
820 {
821 #ifdef MODULE
822 struct lance_private *next;
823 struct net_device *dev;
824
825 while (root_a2065_dev) {
826 next = root_a2065_dev->next_module;
827 dev = root_a2065_dev->dev;
828 unregister_netdev(dev);
829 release_mem_region(ZTWO_PADDR(dev->base_addr),
830 sizeof(struct lance_regs));
831 release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
832 kfree(dev);
833 root_a2065_dev = next;
834 }
835 #endif
836 }
837
838 module_init(a2065_probe);
839 module_exit(a2065_cleanup);
840