Linux 2.4.0-test10pre4
[davej-history.git] / drivers / net / a2065.c
blob498bd523f9e86640bf08b45492eeeec957e4c7de
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_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;
139 #ifdef MODULE
140 static struct lance_private *root_a2065_dev = NULL;
141 #endif
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)
148 #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
150 /* Load the CSR registers */
151 static void load_csrs (struct lance_private *lp)
153 volatile struct lance_regs *ll = lp->ll;
154 volatile struct lance_init_block *aib = lp->lance_init_block;
155 int leptr;
157 leptr = LANCE_ADDR (aib);
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;
166 /* Point back to csr0 */
167 ll->rap = LE_CSR0;
170 #define ZERO 0
172 /* Setup the Lance Rx and Tx rings */
173 static void lance_init_ring (struct net_device *dev)
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;
181 aib = lp->lance_init_block;
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;
188 ib->mode = 0;
190 /* Copy the ethernet address to the lance init block
191 * Note that on the sparc you need to swap the ethernet address.
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];
200 if (ZERO)
201 printk ("TX rings:\n");
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);
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]);
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);
230 /* Setup the initialization block */
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);
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);
246 /* Clear the multicast filter */
247 ib->filter [0] = 0;
248 ib->filter [1] = 0;
251 static int init_restart_lance (struct lance_private *lp)
253 volatile struct lance_regs *ll = lp->ll;
254 int i;
256 ll->rap = LE_CSR0;
257 ll->rdp = LE_C0_INIT;
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 -1;
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;
271 return 0;
274 static int lance_rx (struct net_device *dev)
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 */
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");
294 printk ("]");
295 #endif
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]) {
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
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);
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;
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++;
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;
346 return 0;
349 static int lance_tx (struct net_device *dev)
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;
358 /* csr0 is 2f3 */
359 ll->rdp = LE_C0_TINT | LE_C0_INEA;
360 /* csr0 is 73 */
362 j = lp->tx_old;
363 for (i = j; i != lp->tx_new; i = j) {
364 td = &ib->btx_ring [i];
366 /* If we hit a packet not owned by us, stop */
367 if (td->tmd1_bits & LE_T1_OWN)
368 break;
370 if (td->tmd1_bits & LE_T1_ERR) {
371 status = td->misc;
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++;
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;
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++;
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;
408 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
410 * So we don't count the packet more than once.
412 td->tmd1_bits &= ~(LE_T1_POK);
414 /* One collision before packet was sent. */
415 if (td->tmd1_bits & LE_T1_EONE)
416 lp->stats.collisions++;
418 /* More than one collision, be optimistic. */
419 if (td->tmd1_bits & LE_T1_EMORE)
420 lp->stats.collisions += 2;
422 lp->stats.tx_packets++;
425 j = (j + 1) & lp->tx_ring_mod_mask;
427 lp->tx_old = j;
428 ll->rdp = LE_C0_TINT | LE_C0_INEA;
429 return 0;
432 static void lance_interrupt (int irq, void *dev_id, struct pt_regs *regs)
434 struct net_device *dev;
435 struct lance_private *lp;
436 volatile struct lance_regs *ll;
437 int csr0;
439 dev = (struct net_device *) dev_id;
441 lp = (struct lance_private *) dev->priv;
442 ll = lp->ll;
444 ll->rap = LE_CSR0; /* LANCE Controller Status */
445 csr0 = ll->rdp;
447 if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */
448 return; /* been generated by the Lance. */
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);
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;
459 if (csr0 & LE_C0_RINT)
460 lance_rx (dev);
462 if (csr0 & LE_C0_TINT)
463 lance_tx (dev);
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;
476 if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
477 netif_wake_queue(dev);
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;
485 struct net_device *last_dev = 0;
487 static int lance_open (struct net_device *dev)
489 struct lance_private *lp = (struct lance_private *)dev->priv;
490 volatile struct lance_regs *ll = lp->ll;
491 int status = 0;
493 last_dev = dev;
495 /* Install the Interrupt handler */
496 if (request_irq(IRQ_AMIGA_PORTS, lance_interrupt, SA_SHIRQ,
497 "a2065 Ethernet", dev))
498 return -EAGAIN;
500 /* Stop the Lance */
501 ll->rap = LE_CSR0;
502 ll->rdp = LE_C0_STOP;
504 load_csrs (lp);
505 lance_init_ring (dev);
507 netif_start_queue(dev);
509 status = init_restart_lance (lp);
511 MOD_INC_USE_COUNT;
513 return status;
516 static int lance_close (struct net_device *dev)
518 struct lance_private *lp = (struct lance_private *) dev->priv;
519 volatile struct lance_regs *ll = lp->ll;
521 netif_stop_queue(dev);
522 del_timer_sync(&lp->multicast_timer);
524 /* Stop the card */
525 ll->rap = LE_CSR0;
526 ll->rdp = LE_C0_STOP;
528 free_irq(IRQ_AMIGA_PORTS, dev);
530 MOD_DEC_USE_COUNT;
532 return 0;
535 static inline int lance_reset (struct net_device *dev)
537 struct lance_private *lp = (struct lance_private *)dev->priv;
538 volatile struct lance_regs *ll = lp->ll;
539 int status;
541 /* Stop the lance */
542 ll->rap = LE_CSR0;
543 ll->rdp = LE_C0_STOP;
545 load_csrs (lp);
547 lance_init_ring (dev);
548 dev->trans_start = jiffies;
549 netif_start_queue(dev);
551 status = init_restart_lance (lp);
552 #ifdef DEBUG_DRIVER
553 printk ("Lance restart=%d\n", status);
554 #endif
555 return status;
558 static void lance_tx_timeout(struct net_device *dev)
560 struct lance_private *lp = (struct lance_private *) dev->priv;
561 volatile struct lance_regs *ll = lp->ll;
563 printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
564 dev->name, ll->rdp);
565 lance_reset(dev);
566 netif_wake_queue(dev);
569 static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
571 struct lance_private *lp = (struct lance_private *)dev->priv;
572 volatile struct lance_regs *ll = lp->ll;
573 volatile struct lance_init_block *ib = lp->init_block;
574 int entry, skblen, len;
575 int status = 0;
576 static int outs;
577 unsigned long flags;
579 skblen = skb->len;
581 save_flags(flags);
582 cli();
584 if (!TX_BUFFS_AVAIL){
585 restore_flags(flags);
586 return -1;
589 #ifdef DEBUG_DRIVER
590 /* dump the packet */
592 int i;
594 for (i = 0; i < 64; i++) {
595 if ((i % 16) == 0)
596 printk ("\n");
597 printk ("%2.2x ", skb->data [i]);
600 #endif
601 len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
602 entry = lp->tx_new & lp->tx_ring_mod_mask;
603 ib->btx_ring [entry].length = (-len) | 0xf000;
604 ib->btx_ring [entry].misc = 0;
606 memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
608 /* Clear the slack of the packet, do I need this? */
609 if (len != skblen)
610 memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen);
612 /* Now, give the packet to the lance */
613 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
614 lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
616 outs++;
618 if (TX_BUFFS_AVAIL <= 0)
619 netif_stop_queue(dev);
621 /* Kick the lance: transmit now */
622 ll->rdp = LE_C0_INEA | LE_C0_TDMD;
623 dev->trans_start = jiffies;
624 dev_kfree_skb (skb);
626 restore_flags(flags);
628 return status;
631 static struct net_device_stats *lance_get_stats (struct net_device *dev)
633 struct lance_private *lp = (struct lance_private *) dev->priv;
635 return &lp->stats;
638 /* taken from the depca driver */
639 static void lance_load_multicast (struct net_device *dev)
641 struct lance_private *lp = (struct lance_private *) dev->priv;
642 volatile struct lance_init_block *ib = lp->init_block;
643 volatile u16 *mcast_table = (u16 *)&ib->filter;
644 struct dev_mc_list *dmi=dev->mc_list;
645 char *addrs;
646 int i, j, bit, byte;
647 u32 crc, poly = CRC_POLYNOMIAL_LE;
649 /* set all multicast bits */
650 if (dev->flags & IFF_ALLMULTI){
651 ib->filter [0] = 0xffffffff;
652 ib->filter [1] = 0xffffffff;
653 return;
655 /* clear the multicast filter */
656 ib->filter [0] = 0;
657 ib->filter [1] = 0;
659 /* Add addresses */
660 for (i = 0; i < dev->mc_count; i++){
661 addrs = dmi->dmi_addr;
662 dmi = dmi->next;
664 /* multicast address? */
665 if (!(*addrs & 1))
666 continue;
668 crc = 0xffffffff;
669 for (byte = 0; byte < 6; byte++)
670 for (bit = *addrs++, j = 0; j < 8; j++, bit>>=1)
672 int test;
674 test = ((bit ^ crc) & 0x01);
675 crc >>= 1;
677 if (test)
679 crc = crc ^ poly;
683 crc = crc >> 26;
684 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
686 return;
689 static void lance_set_multicast (struct net_device *dev)
691 struct lance_private *lp = (struct lance_private *) dev->priv;
692 volatile struct lance_init_block *ib = lp->init_block;
693 volatile struct lance_regs *ll = lp->ll;
695 if (!netif_running(dev))
696 return;
698 if (lp->tx_old != lp->tx_new) {
699 mod_timer(&lp->multicast_timer, jiffies + 4);
700 netif_wake_queue(dev);
701 return;
704 netif_stop_queue(dev);
706 ll->rap = LE_CSR0;
707 ll->rdp = LE_C0_STOP;
708 lance_init_ring (dev);
710 if (dev->flags & IFF_PROMISC) {
711 ib->mode |= LE_MO_PROM;
712 } else {
713 ib->mode &= ~LE_MO_PROM;
714 lance_load_multicast (dev);
716 load_csrs (lp);
717 init_restart_lance (lp);
718 netif_wake_queue(dev);
721 static int __init a2065_probe(void)
723 struct zorro_dev *z = NULL;
724 struct net_device *dev;
725 struct lance_private *priv;
726 int res = -ENODEV;
728 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
729 unsigned long board, base_addr, mem_start;
730 int is_cbm;
732 if (z->id == ZORRO_PROD_CBM_A2065_1 ||
733 z->id == ZORRO_PROD_CBM_A2065_2)
734 is_cbm = 1;
735 else if (z->id == ZORRO_PROD_AMERISTAR_A2065)
736 is_cbm = 0;
737 else
738 continue;
740 board = z->resource.start;
741 base_addr = board+A2065_LANCE;
742 mem_start = board+A2065_RAM;
744 if (!request_mem_region(base_addr, sizeof(struct lance_regs),
745 "Am7990"))
746 continue;
747 if (!request_mem_region(mem_start, A2065_RAM_SIZE, "RAM")) {
748 release_mem_region(base_addr,
749 sizeof(struct lance_regs));
750 continue;
753 dev = init_etherdev(NULL, sizeof(struct lance_private));
755 if (dev == NULL) {
756 release_mem_region(base_addr,
757 sizeof(struct lance_regs));
758 release_mem_region(mem_start, A2065_RAM_SIZE);
759 return -ENOMEM;
761 priv = (struct lance_private *)dev->priv;
762 memset(priv, 0, sizeof(struct lance_private));
764 priv->dev = dev;
765 dev->dev_addr[0] = 0x00;
766 if (is_cbm) { /* Commodore */
767 dev->dev_addr[1] = 0x80;
768 dev->dev_addr[2] = 0x10;
769 } else { /* Ameristar */
770 dev->dev_addr[1] = 0x00;
771 dev->dev_addr[2] = 0x9f;
773 dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
774 dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
775 dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
776 printk("%s: A2065 at 0x%08lx, Ethernet Address "
777 "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board,
778 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
779 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
781 dev->base_addr = ZTWO_VADDR(base_addr);
782 dev->mem_start = ZTWO_VADDR(mem_start);
783 dev->mem_end = dev->mem_start+A2065_RAM_SIZE;
785 priv->ll = (volatile struct lance_regs *)dev->base_addr;
786 priv->init_block = (struct lance_init_block *)dev->mem_start;
787 priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
788 priv->auto_select = 0;
789 priv->busmaster_regval = LE_C3_BSWP;
791 priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
792 priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
793 priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
794 priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
796 dev->open = &lance_open;
797 dev->stop = &lance_close;
798 dev->hard_start_xmit = &lance_start_xmit;
799 dev->tx_timeout = &lance_tx_timeout;
800 dev->watchdog_timeo = 5*HZ;
801 dev->get_stats = &lance_get_stats;
802 dev->set_multicast_list = &lance_set_multicast;
803 dev->dma = 0;
805 #ifdef MODULE
806 priv->next_module = root_a2065_dev;
807 root_a2065_dev = priv;
808 #endif
809 ether_setup(dev);
810 init_timer(&priv->multicast_timer);
811 priv->multicast_timer.data = (unsigned long) dev;
812 priv->multicast_timer.function =
813 (void (*)(unsigned long)) &lance_set_multicast;
815 res = 0;
817 return res;
821 static void __exit a2065_cleanup(void)
823 #ifdef MODULE
824 struct lance_private *next;
825 struct net_device *dev;
827 while (root_a2065_dev) {
828 next = root_a2065_dev->next_module;
829 dev = root_a2065_dev->dev;
830 unregister_netdev(dev);
831 release_mem_region(ZTWO_PADDR(dev->base_addr),
832 sizeof(struct lance_regs));
833 release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
834 kfree(dev);
835 root_a2065_dev = next;
837 #endif
840 module_init(a2065_probe);
841 module_exit(a2065_cleanup);