Import 2.3.15pre1
[davej-history.git] / drivers / net / a2065.c
blobead77eb9eedd9fce84821e4cad7aebb9d3044108
1 /*
2 * Amiga Linux/68k A2065 Ethernet Driver
4 * (C) Copyright 1995 by Geert Uytterhoeven <geert@linux-m68k.org>
6 * Fixes and tips by:
7 * - Janos Farkas (CHEXUM@sparta.banki.hu)
8 * - Jes Degn Soerensen (jds@kom.auc.dk)
10 * ----------------------------------------------------------------------------
12 * This program is based on
14 * ariadne.?: Amiga Linux/68k Ariadne Ethernet Driver
15 * (C) Copyright 1995 by Geert Uytterhoeven,
16 * Peter De Schrijver
18 * lance.c: An AMD LANCE ethernet driver for linux.
19 * Written 1993-94 by Donald Becker.
21 * Am79C960: PCnet(tm)-ISA Single-Chip Ethernet Controller
22 * Advanced Micro Devices
23 * Publication #16907, Rev. B, Amendment/0, May 1994
25 * ----------------------------------------------------------------------------
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.
31 * ----------------------------------------------------------------------------
33 * The A2065 is a Zorro-II board made by Commodore/Ameristar. It contains:
35 * - an Am7990 Local Area Network Controller for Ethernet (LANCE) with
36 * both 10BASE-2 (thin coax) and AUI (DB-15) connectors
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>
51 #include <asm/bitops.h>
52 #include <asm/io.h>
53 #include <asm/irq.h>
54 #include <linux/errno.h>
56 #include <asm/amigaints.h>
57 #include <asm/amigahw.h>
58 #include <linux/zorro.h>
60 #include <linux/netdevice.h>
61 #include <linux/etherdevice.h>
62 #include <linux/skbuff.h>
63 #include "a2065.h"
67 * Transmit/Receive Ring Definitions
70 #define LANCE_LOG_TX_BUFFERS (2)
71 #define LANCE_LOG_RX_BUFFERS (4)
73 #define TX_RING_SIZE (1<<LANCE_LOG_TX_BUFFERS)
74 #define RX_RING_SIZE (1<<LANCE_LOG_RX_BUFFERS)
76 #define TX_RING_MOD_MASK (TX_RING_SIZE-1)
77 #define RX_RING_MOD_MASK (RX_RING_SIZE-1)
79 #define PKT_BUF_SIZE (1544)
80 #define RX_BUFF_SIZE PKT_BUF_SIZE
81 #define TX_BUFF_SIZE PKT_BUF_SIZE
85 * Layout of the Lance's RAM Buffer
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. */
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 */
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];
104 char rx_buf [RX_RING_SIZE][RX_BUFF_SIZE];
105 char tx_buf [TX_RING_SIZE][TX_BUFF_SIZE];
110 * Private Device Data
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 */
119 int rx_new, tx_new;
120 int rx_old, tx_old;
122 int lance_log_rx_bufs, lance_log_tx_bufs;
123 int rx_ring_mod_mask, tx_ring_mod_mask;
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;
130 #ifdef CONFIG_AMIGA
131 unsigned int key;
132 #endif
133 #ifdef CONFIG_SUNLANCE
134 struct Linux_SBus_DMA *ledma; /* if set this points to ledma and arch=4m */
135 int burst_sizes; /* ledma SBus burst sizes */
136 #endif
137 struct timer_list multicast_timer;
140 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
141 lp->tx_old+lp->tx_ring_mod_mask-lp->tx_new:\
142 lp->tx_old - lp->tx_new-1)
145 #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
147 /* Load the CSR registers */
148 static void load_csrs (struct lance_private *lp)
150 volatile struct lance_regs *ll = lp->ll;
151 volatile struct lance_init_block *aib = lp->lance_init_block;
152 int leptr;
154 leptr = LANCE_ADDR (aib);
156 ll->rap = LE_CSR1;
157 ll->rdp = (leptr & 0xFFFF);
158 ll->rap = LE_CSR2;
159 ll->rdp = leptr >> 16;
160 ll->rap = LE_CSR3;
161 ll->rdp = lp->busmaster_regval;
163 /* Point back to csr0 */
164 ll->rap = LE_CSR0;
167 #define ZERO 0
169 /* Setup the Lance Rx and Tx rings */
170 /* Sets dev->tbusy */
171 static void lance_init_ring (struct net_device *dev)
173 struct lance_private *lp = (struct lance_private *) dev->priv;
174 volatile struct lance_init_block *ib = lp->init_block;
175 volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */
176 int leptr;
177 int i;
179 aib = lp->lance_init_block;
181 /* Lock out other processes while setting up hardware */
182 dev->tbusy = 1;
183 lp->rx_new = lp->tx_new = 0;
184 lp->rx_old = lp->tx_old = 0;
186 ib->mode = 0;
188 /* Copy the ethernet address to the lance init block
189 * Note that on the sparc you need to swap the ethernet address.
191 ib->phys_addr [0] = dev->dev_addr [1];
192 ib->phys_addr [1] = dev->dev_addr [0];
193 ib->phys_addr [2] = dev->dev_addr [3];
194 ib->phys_addr [3] = dev->dev_addr [2];
195 ib->phys_addr [4] = dev->dev_addr [5];
196 ib->phys_addr [5] = dev->dev_addr [4];
198 if (ZERO)
199 printk ("TX rings:\n");
201 /* Setup the Tx ring entries */
202 for (i = 0; i <= (1<<lp->lance_log_tx_bufs); i++) {
203 leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
204 ib->btx_ring [i].tmd0 = leptr;
205 ib->btx_ring [i].tmd1_hadr = leptr >> 16;
206 ib->btx_ring [i].tmd1_bits = 0;
207 ib->btx_ring [i].length = 0xf000; /* The ones required by tmd2 */
208 ib->btx_ring [i].misc = 0;
209 if (i < 3)
210 if (ZERO) printk ("%d: 0x%8.8x\n", i, leptr);
213 /* Setup the Rx ring entries */
214 if (ZERO)
215 printk ("RX rings:\n");
216 for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) {
217 leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
219 ib->brx_ring [i].rmd0 = leptr;
220 ib->brx_ring [i].rmd1_hadr = leptr >> 16;
221 ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
222 ib->brx_ring [i].length = -RX_BUFF_SIZE | 0xf000;
223 ib->brx_ring [i].mblength = 0;
224 if (i < 3 && ZERO)
225 printk ("%d: 0x%8.8x\n", i, leptr);
228 /* Setup the initialization block */
230 /* Setup rx descriptor pointer */
231 leptr = LANCE_ADDR(&aib->brx_ring);
232 ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
233 ib->rx_ptr = leptr;
234 if (ZERO)
235 printk ("RX ptr: %8.8x\n", leptr);
237 /* Setup tx descriptor pointer */
238 leptr = LANCE_ADDR(&aib->btx_ring);
239 ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
240 ib->tx_ptr = leptr;
241 if (ZERO)
242 printk ("TX ptr: %8.8x\n", leptr);
244 /* Clear the multicast filter */
245 ib->filter [0] = 0;
246 ib->filter [1] = 0;
249 static int init_restart_lance (struct lance_private *lp)
251 volatile struct lance_regs *ll = lp->ll;
252 int i;
254 ll->rap = LE_CSR0;
255 ll->rdp = LE_C0_INIT;
257 /* Wait for the lance to complete initialization */
258 for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++)
259 barrier();
260 if ((i == 100) || (ll->rdp & LE_C0_ERR)) {
261 printk ("LANCE unopened after %d ticks, csr0=%4.4x.\n", i, ll->rdp);
262 return -1;
265 /* Clear IDON by writing a "1", enable interrupts and start lance */
266 ll->rdp = LE_C0_IDON;
267 ll->rdp = LE_C0_INEA | LE_C0_STRT;
269 return 0;
272 static int lance_rx (struct net_device *dev)
274 struct lance_private *lp = (struct lance_private *) dev->priv;
275 volatile struct lance_init_block *ib = lp->init_block;
276 volatile struct lance_regs *ll = lp->ll;
277 volatile struct lance_rx_desc *rd;
278 unsigned char bits;
279 int len = 0; /* XXX shut up gcc warnings */
280 struct sk_buff *skb = 0; /* XXX shut up gcc warnings */
282 #ifdef TEST_HITS
283 printk ("[");
284 for (i = 0; i < RX_RING_SIZE; i++) {
285 if (i == lp->rx_new)
286 printk ("%s",
287 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X");
288 else
289 printk ("%s",
290 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1");
292 printk ("]");
293 #endif
295 ll->rdp = LE_C0_RINT|LE_C0_INEA;
296 for (rd = &ib->brx_ring [lp->rx_new];
297 !((bits = rd->rmd1_bits) & LE_R1_OWN);
298 rd = &ib->brx_ring [lp->rx_new]) {
300 /* We got an incomplete frame? */
301 if ((bits & LE_R1_POK) != LE_R1_POK) {
302 lp->stats.rx_over_errors++;
303 lp->stats.rx_errors++;
304 continue;
305 } else if (bits & LE_R1_ERR) {
306 /* Count only the end frame as a rx error,
307 * not the beginning
309 if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++;
310 if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++;
311 if (bits & LE_R1_OFL) lp->stats.rx_over_errors++;
312 if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++;
313 if (bits & LE_R1_EOP) lp->stats.rx_errors++;
314 } else {
315 len = (rd->mblength & 0xfff) - 4;
316 skb = dev_alloc_skb (len+2);
318 if (skb == 0) {
319 printk ("%s: Memory squeeze, deferring packet.\n",
320 dev->name);
321 lp->stats.rx_dropped++;
322 rd->mblength = 0;
323 rd->rmd1_bits = LE_R1_OWN;
324 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
325 return 0;
328 skb->dev = dev;
329 skb_reserve (skb, 2); /* 16 byte align */
330 skb_put (skb, len); /* make room */
331 eth_copy_and_sum(skb,
332 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
333 len, 0);
334 skb->protocol = eth_type_trans (skb, dev);
335 netif_rx (skb);
336 lp->stats.rx_packets++;
339 /* Return the packet to the pool */
340 rd->mblength = 0;
341 rd->rmd1_bits = LE_R1_OWN;
342 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
344 return 0;
347 static int lance_tx (struct net_device *dev)
349 struct lance_private *lp = (struct lance_private *) dev->priv;
350 volatile struct lance_init_block *ib = lp->init_block;
351 volatile struct lance_regs *ll = lp->ll;
352 volatile struct lance_tx_desc *td;
353 int i, j;
354 int status;
356 /* csr0 is 2f3 */
357 ll->rdp = LE_C0_TINT | LE_C0_INEA;
358 /* csr0 is 73 */
360 j = lp->tx_old;
361 for (i = j; i != lp->tx_new; i = j) {
362 td = &ib->btx_ring [i];
364 /* If we hit a packet not owned by us, stop */
365 if (td->tmd1_bits & LE_T1_OWN)
366 break;
368 if (td->tmd1_bits & LE_T1_ERR) {
369 status = td->misc;
371 lp->stats.tx_errors++;
372 if (status & LE_T3_RTY) lp->stats.tx_aborted_errors++;
373 if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
375 if (status & LE_T3_CLOS) {
376 lp->stats.tx_carrier_errors++;
377 if (lp->auto_select) {
378 lp->tpe = 1 - lp->tpe;
379 printk("%s: Carrier Lost, trying %s\n",
380 dev->name, lp->tpe?"TPE":"AUI");
381 /* Stop the lance */
382 ll->rap = LE_CSR0;
383 ll->rdp = LE_C0_STOP;
384 lance_init_ring (dev);
385 load_csrs (lp);
386 init_restart_lance (lp);
387 return 0;
391 /* buffer errors and underflows turn off the transmitter */
392 /* Restart the adapter */
393 if (status & (LE_T3_BUF|LE_T3_UFL)) {
394 lp->stats.tx_fifo_errors++;
396 printk ("%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
397 dev->name);
398 /* Stop the lance */
399 ll->rap = LE_CSR0;
400 ll->rdp = LE_C0_STOP;
401 lance_init_ring (dev);
402 load_csrs (lp);
403 init_restart_lance (lp);
404 return 0;
406 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
408 * So we don't count the packet more than once.
410 td->tmd1_bits &= ~(LE_T1_POK);
412 /* One collision before packet was sent. */
413 if (td->tmd1_bits & LE_T1_EONE)
414 lp->stats.collisions++;
416 /* More than one collision, be optimistic. */
417 if (td->tmd1_bits & LE_T1_EMORE)
418 lp->stats.collisions += 2;
420 lp->stats.tx_packets++;
423 j = (j + 1) & lp->tx_ring_mod_mask;
425 lp->tx_old = j;
426 ll->rdp = LE_C0_TINT | LE_C0_INEA;
427 return 0;
430 static void lance_interrupt (int irq, void *dev_id, struct pt_regs *regs)
432 struct net_device *dev;
433 struct lance_private *lp;
434 volatile struct lance_regs *ll;
435 int csr0;
437 dev = (struct net_device *) dev_id;
439 lp = (struct lance_private *) dev->priv;
440 ll = lp->ll;
442 ll->rap = LE_CSR0; /* LANCE Controller Status */
443 csr0 = ll->rdp;
445 if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */
446 return; /* been generated by the Lance. */
448 if (dev->interrupt)
449 printk ("%s: again", dev->name);
451 dev->interrupt = 1;
453 /* Acknowledge all the interrupt sources ASAP */
454 ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|
455 LE_C0_INIT);
457 if ((csr0 & LE_C0_ERR)) {
458 /* Clear the error condition */
459 ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
462 if (csr0 & LE_C0_RINT)
463 lance_rx (dev);
465 if (csr0 & LE_C0_TINT)
466 lance_tx (dev);
468 /* Log misc errors. */
469 if (csr0 & LE_C0_BABL)
470 lp->stats.tx_errors++; /* Tx babble. */
471 if (csr0 & LE_C0_MISS)
472 lp->stats.rx_errors++; /* Missed a Rx frame. */
473 if (csr0 & LE_C0_MERR) {
474 printk("%s: Bus master arbitration failure, status %4.4x.\n", dev->name, csr0);
475 /* Restart the chip. */
476 ll->rdp = LE_C0_STRT;
479 if ((TX_BUFFS_AVAIL >= 0) && dev->tbusy) {
480 dev->tbusy = 0;
481 mark_bh (NET_BH);
483 ll->rap = LE_CSR0;
484 ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
485 LE_C0_IDON|LE_C0_INEA;
487 dev->interrupt = 0;
490 struct net_device *last_dev = 0;
492 static int lance_open (struct net_device *dev)
494 struct lance_private *lp = (struct lance_private *)dev->priv;
495 volatile struct lance_regs *ll = lp->ll;
496 int status = 0;
498 last_dev = dev;
500 /* Install the Interrupt handler */
501 if (request_irq(IRQ_AMIGA_PORTS, lance_interrupt, SA_SHIRQ,
502 "a2065 Ethernet", dev))
503 return -EAGAIN;
505 /* Stop the Lance */
506 ll->rap = LE_CSR0;
507 ll->rdp = LE_C0_STOP;
509 load_csrs (lp);
510 lance_init_ring (dev);
512 dev->tbusy = 0;
513 dev->interrupt = 0;
514 dev->start = 1;
516 status = init_restart_lance (lp);
518 MOD_INC_USE_COUNT;
520 return status;
523 static int lance_close (struct net_device *dev)
525 struct lance_private *lp = (struct lance_private *) dev->priv;
526 volatile struct lance_regs *ll = lp->ll;
528 dev->start = 0;
529 dev->tbusy = 1;
530 del_timer(&lp->multicast_timer);
532 /* Stop the card */
533 ll->rap = LE_CSR0;
534 ll->rdp = LE_C0_STOP;
536 free_irq(IRQ_AMIGA_PORTS, dev);
538 MOD_DEC_USE_COUNT;
540 return 0;
543 static inline int lance_reset (struct net_device *dev)
545 struct lance_private *lp = (struct lance_private *)dev->priv;
546 volatile struct lance_regs *ll = lp->ll;
547 int status;
549 /* Stop the lance */
550 ll->rap = LE_CSR0;
551 ll->rdp = LE_C0_STOP;
553 load_csrs (lp);
554 lance_init_ring (dev);
555 dev->trans_start = jiffies;
556 dev->interrupt = 0;
557 dev->start = 1;
558 dev->tbusy = 0;
559 status = init_restart_lance (lp);
560 #ifdef DEBUG_DRIVER
561 printk ("Lance restart=%d\n", status);
562 #endif
563 return status;
566 static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
568 struct lance_private *lp = (struct lance_private *)dev->priv;
569 volatile struct lance_regs *ll = lp->ll;
570 volatile struct lance_init_block *ib = lp->init_block;
571 int entry, skblen, len;
572 int status = 0;
573 static int outs;
574 unsigned long flags;
576 /* Transmitter timeout, serious problems */
577 if (dev->tbusy) {
578 int tickssofar = jiffies - dev->trans_start;
580 if (tickssofar < 100) {
581 status = -1;
582 } else {
583 printk ("%s: transmit timed out, status %04x, resetting\n",
584 dev->name, ll->rdp);
585 lance_reset (dev);
587 return status;
590 /* Block a timer-based transmit from overlapping. */
591 if (test_and_set_bit (0, (void *) &dev->tbusy) != 0) {
592 printk ("Transmitter access conflict.\n");
593 return -1;
596 skblen = skb->len;
598 save_flags(flags);
599 cli();
601 if (!TX_BUFFS_AVAIL){
602 restore_flags(flags);
603 return -1;
606 #ifdef DEBUG_DRIVER
607 /* dump the packet */
609 int i;
611 for (i = 0; i < 64; i++) {
612 if ((i % 16) == 0)
613 printk ("\n");
614 printk ("%2.2x ", skb->data [i]);
617 #endif
618 len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
619 entry = lp->tx_new & lp->tx_ring_mod_mask;
620 ib->btx_ring [entry].length = (-len) | 0xf000;
621 ib->btx_ring [entry].misc = 0;
623 memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
625 /* Clear the slack of the packet, do I need this? */
626 if (len != skblen)
627 memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen);
629 /* Now, give the packet to the lance */
630 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
631 lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
633 outs++;
634 /* Kick the lance: transmit now */
635 ll->rdp = LE_C0_INEA | LE_C0_TDMD;
636 dev->trans_start = jiffies;
637 dev_kfree_skb (skb);
639 if (TX_BUFFS_AVAIL)
640 dev->tbusy = 0;
641 restore_flags(flags);
643 return status;
646 static struct net_device_stats *lance_get_stats (struct net_device *dev)
648 struct lance_private *lp = (struct lance_private *) dev->priv;
650 return &lp->stats;
653 /* taken from the depca driver */
654 static void lance_load_multicast (struct net_device *dev)
656 struct lance_private *lp = (struct lance_private *) dev->priv;
657 volatile struct lance_init_block *ib = lp->init_block;
658 volatile u16 *mcast_table = (u16 *)&ib->filter;
659 struct dev_mc_list *dmi=dev->mc_list;
660 char *addrs;
661 int i, j, bit, byte;
662 u32 crc, poly = CRC_POLYNOMIAL_LE;
664 /* set all multicast bits */
665 if (dev->flags & IFF_ALLMULTI){
666 ib->filter [0] = 0xffffffff;
667 ib->filter [1] = 0xffffffff;
668 return;
670 /* clear the multicast filter */
671 ib->filter [0] = 0;
672 ib->filter [1] = 0;
674 /* Add addresses */
675 for (i = 0; i < dev->mc_count; i++){
676 addrs = dmi->dmi_addr;
677 dmi = dmi->next;
679 /* multicast address? */
680 if (!(*addrs & 1))
681 continue;
683 crc = 0xffffffff;
684 for (byte = 0; byte < 6; byte++)
685 for (bit = *addrs++, j = 0; j < 8; j++, bit>>=1)
687 int test;
689 test = ((bit ^ crc) & 0x01);
690 crc >>= 1;
692 if (test)
694 crc = crc ^ poly;
698 crc = crc >> 26;
699 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
701 return;
704 static void lance_set_multicast (struct net_device *dev)
706 struct lance_private *lp = (struct lance_private *) dev->priv;
707 volatile struct lance_init_block *ib = lp->init_block;
708 volatile struct lance_regs *ll = lp->ll;
710 if (!dev->start)
711 return;
713 if (dev->tbusy) {
714 mod_timer(&lp->multicast_timer, jiffies + 2);
715 return;
717 set_bit (0, (void *) &dev->tbusy);
719 if (lp->tx_old != lp->tx_new) {
720 mod_timer(&lp->multicast_timer, jiffies + 4);
721 dev->tbusy = 0;
722 return;
725 ll->rap = LE_CSR0;
726 ll->rdp = LE_C0_STOP;
727 lance_init_ring (dev);
729 if (dev->flags & IFF_PROMISC) {
730 ib->mode |= LE_MO_PROM;
731 } else {
732 ib->mode &= ~LE_MO_PROM;
733 lance_load_multicast (dev);
735 load_csrs (lp);
736 init_restart_lance (lp);
737 dev->tbusy = 0;
738 mark_bh(NET_BH);
741 int __init a2065_probe(struct net_device *dev)
743 unsigned int key, is_cbm;
744 const struct ConfigDev *cd;
745 u_long board;
746 u_long sn;
747 struct lance_private *priv;
748 struct A2065Board *a2065;
750 if ((key = is_cbm = zorro_find(ZORRO_PROD_CBM_A2065_1, 0, 0)) ||
751 (key = is_cbm = zorro_find(ZORRO_PROD_CBM_A2065_2, 0, 0)) ||
752 (key = zorro_find(ZORRO_PROD_AMERISTAR_A2065, 0, 0))) {
753 cd = zorro_get_board(key);
754 if ((board = (u_long)cd->cd_BoardAddr)) {
755 sn = cd->cd_Rom.er_SerialNumber;
756 if (is_cbm) { /* Commodore */
757 dev->dev_addr[0] = 0x00;
758 dev->dev_addr[1] = 0x80;
759 dev->dev_addr[2] = 0x10;
760 } else { /* Ameristar */
761 dev->dev_addr[0] = 0x00;
762 dev->dev_addr[1] = 0x00;
763 dev->dev_addr[2] = 0x9f;
765 dev->dev_addr[3] = (sn>>16) & 0xff;
766 dev->dev_addr[4] = (sn>>8) & 0xff;
767 dev->dev_addr[5] = sn & 0xff;
768 printk("%s: A2065 at 0x%08lx, Ethernet Address %02x:%02x:%02x:%02x:%02x:%02x\n",
769 dev->name, board, dev->dev_addr[0],
770 dev->dev_addr[1], dev->dev_addr[2],
771 dev->dev_addr[3], dev->dev_addr[4],
772 dev->dev_addr[5]);
774 init_etherdev(dev, 0);
776 dev->priv = kmalloc(sizeof(struct
777 lance_private),
778 GFP_KERNEL);
779 if (dev->priv == NULL)
780 return -ENOMEM;
781 priv = (struct lance_private *)dev->priv;
782 memset(priv, 0, sizeof(struct lance_private));
784 a2065 = (struct A2065Board *)ZTWO_VADDR(board);
785 priv->ll = &a2065->Lance;
786 priv->init_block =
787 (struct lance_init_block *)&a2065->RAM;
788 priv->lance_init_block = (struct lance_init_block *)
789 offsetof(struct A2065Board, RAM);
790 priv->auto_select = 0;
791 priv->key = key;
792 priv->busmaster_regval = LE_C3_BSWP;
794 priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
795 priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
796 priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
797 priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
799 dev->open = &lance_open;
800 dev->stop = &lance_close;
801 dev->hard_start_xmit = &lance_start_xmit;
802 dev->get_stats = &lance_get_stats;
803 dev->set_multicast_list = &lance_set_multicast;
804 dev->dma = 0;
806 ether_setup(dev);
807 init_timer(&priv->multicast_timer);
808 priv->multicast_timer.data = (unsigned long) dev;
809 priv->multicast_timer.function =
810 (void (*)(unsigned long)) &lance_set_multicast;
812 zorro_config_board(key, 0);
813 return(0);
816 return(-ENODEV);
820 #ifdef MODULE
821 static char devicename[9] = { 0, };
823 static struct net_device a2065_dev =
825 devicename, /* filled in by register_netdev() */
826 0, 0, 0, 0, /* memory */
827 0, 0, /* base, irq */
828 0, 0, 0, NULL, a2065_probe,
831 int init_module(void)
833 int err;
835 if ((err = register_netdev(&a2065_dev))) {
836 if (err == -EIO)
837 printk("No A2065 board found. Module not loaded.\n");
838 return(err);
840 return(0);
843 void cleanup_module(void)
845 struct lance_private *priv = (struct lance_private *)a2065_dev.priv;
847 unregister_netdev(&a2065_dev);
848 zorro_unconfig_board(priv->key, 0);
849 kfree(priv);
852 #endif /* MODULE */