Import 2.3.47pre1
[davej-history.git] / drivers / net / a2065.c
blob25364d9207fa35f950e858a92bab85092ee024cd
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;
137 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
138 lp->tx_old+lp->tx_ring_mod_mask-lp->tx_new:\
139 lp->tx_old - lp->tx_new-1)
142 #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
144 /* Load the CSR registers */
145 static void load_csrs (struct lance_private *lp)
147 volatile struct lance_regs *ll = lp->ll;
148 volatile struct lance_init_block *aib = lp->lance_init_block;
149 int leptr;
151 leptr = LANCE_ADDR (aib);
153 ll->rap = LE_CSR1;
154 ll->rdp = (leptr & 0xFFFF);
155 ll->rap = LE_CSR2;
156 ll->rdp = leptr >> 16;
157 ll->rap = LE_CSR3;
158 ll->rdp = lp->busmaster_regval;
160 /* Point back to csr0 */
161 ll->rap = LE_CSR0;
164 #define ZERO 0
166 /* Setup the Lance Rx and Tx rings */
167 static void lance_init_ring (struct net_device *dev)
169 struct lance_private *lp = (struct lance_private *) dev->priv;
170 volatile struct lance_init_block *ib = lp->init_block;
171 volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */
172 int leptr;
173 int i;
175 aib = lp->lance_init_block;
177 /* Lock out other processes while setting up hardware */
178 netif_stop_queue(dev);
179 lp->rx_new = lp->tx_new = 0;
180 lp->rx_old = lp->tx_old = 0;
182 ib->mode = 0;
184 /* Copy the ethernet address to the lance init block
185 * Note that on the sparc you need to swap the ethernet address.
187 ib->phys_addr [0] = dev->dev_addr [1];
188 ib->phys_addr [1] = dev->dev_addr [0];
189 ib->phys_addr [2] = dev->dev_addr [3];
190 ib->phys_addr [3] = dev->dev_addr [2];
191 ib->phys_addr [4] = dev->dev_addr [5];
192 ib->phys_addr [5] = dev->dev_addr [4];
194 if (ZERO)
195 printk ("TX rings:\n");
197 /* Setup the Tx ring entries */
198 for (i = 0; i <= (1<<lp->lance_log_tx_bufs); i++) {
199 leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
200 ib->btx_ring [i].tmd0 = leptr;
201 ib->btx_ring [i].tmd1_hadr = leptr >> 16;
202 ib->btx_ring [i].tmd1_bits = 0;
203 ib->btx_ring [i].length = 0xf000; /* The ones required by tmd2 */
204 ib->btx_ring [i].misc = 0;
205 if (i < 3)
206 if (ZERO) printk ("%d: 0x%8.8x\n", i, leptr);
209 /* Setup the Rx ring entries */
210 if (ZERO)
211 printk ("RX rings:\n");
212 for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) {
213 leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
215 ib->brx_ring [i].rmd0 = leptr;
216 ib->brx_ring [i].rmd1_hadr = leptr >> 16;
217 ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
218 ib->brx_ring [i].length = -RX_BUFF_SIZE | 0xf000;
219 ib->brx_ring [i].mblength = 0;
220 if (i < 3 && ZERO)
221 printk ("%d: 0x%8.8x\n", i, leptr);
224 /* Setup the initialization block */
226 /* Setup rx descriptor pointer */
227 leptr = LANCE_ADDR(&aib->brx_ring);
228 ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
229 ib->rx_ptr = leptr;
230 if (ZERO)
231 printk ("RX ptr: %8.8x\n", leptr);
233 /* Setup tx descriptor pointer */
234 leptr = LANCE_ADDR(&aib->btx_ring);
235 ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
236 ib->tx_ptr = leptr;
237 if (ZERO)
238 printk ("TX ptr: %8.8x\n", leptr);
240 /* Clear the multicast filter */
241 ib->filter [0] = 0;
242 ib->filter [1] = 0;
245 static int init_restart_lance (struct lance_private *lp)
247 volatile struct lance_regs *ll = lp->ll;
248 int i;
250 ll->rap = LE_CSR0;
251 ll->rdp = LE_C0_INIT;
253 /* Wait for the lance to complete initialization */
254 for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++)
255 barrier();
256 if ((i == 100) || (ll->rdp & LE_C0_ERR)) {
257 printk ("LANCE unopened after %d ticks, csr0=%4.4x.\n", i, ll->rdp);
258 return -1;
261 /* Clear IDON by writing a "1", enable interrupts and start lance */
262 ll->rdp = LE_C0_IDON;
263 ll->rdp = LE_C0_INEA | LE_C0_STRT;
265 return 0;
268 static int lance_rx (struct net_device *dev)
270 struct lance_private *lp = (struct lance_private *) dev->priv;
271 volatile struct lance_init_block *ib = lp->init_block;
272 volatile struct lance_regs *ll = lp->ll;
273 volatile struct lance_rx_desc *rd;
274 unsigned char bits;
275 int len = 0; /* XXX shut up gcc warnings */
276 struct sk_buff *skb = 0; /* XXX shut up gcc warnings */
278 #ifdef TEST_HITS
279 printk ("[");
280 for (i = 0; i < RX_RING_SIZE; i++) {
281 if (i == lp->rx_new)
282 printk ("%s",
283 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X");
284 else
285 printk ("%s",
286 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1");
288 printk ("]");
289 #endif
291 ll->rdp = LE_C0_RINT|LE_C0_INEA;
292 for (rd = &ib->brx_ring [lp->rx_new];
293 !((bits = rd->rmd1_bits) & LE_R1_OWN);
294 rd = &ib->brx_ring [lp->rx_new]) {
296 /* We got an incomplete frame? */
297 if ((bits & LE_R1_POK) != LE_R1_POK) {
298 lp->stats.rx_over_errors++;
299 lp->stats.rx_errors++;
300 continue;
301 } else if (bits & LE_R1_ERR) {
302 /* Count only the end frame as a rx error,
303 * not the beginning
305 if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++;
306 if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++;
307 if (bits & LE_R1_OFL) lp->stats.rx_over_errors++;
308 if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++;
309 if (bits & LE_R1_EOP) lp->stats.rx_errors++;
310 } else {
311 len = (rd->mblength & 0xfff) - 4;
312 skb = dev_alloc_skb (len+2);
314 if (skb == 0) {
315 printk ("%s: Memory squeeze, deferring packet.\n",
316 dev->name);
317 lp->stats.rx_dropped++;
318 rd->mblength = 0;
319 rd->rmd1_bits = LE_R1_OWN;
320 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
321 return 0;
324 skb->dev = dev;
325 skb_reserve (skb, 2); /* 16 byte align */
326 skb_put (skb, len); /* make room */
327 eth_copy_and_sum(skb,
328 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
329 len, 0);
330 skb->protocol = eth_type_trans (skb, dev);
331 netif_rx (skb);
332 lp->stats.rx_packets++;
335 /* Return the packet to the pool */
336 rd->mblength = 0;
337 rd->rmd1_bits = LE_R1_OWN;
338 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
340 return 0;
343 static int lance_tx (struct net_device *dev)
345 struct lance_private *lp = (struct lance_private *) dev->priv;
346 volatile struct lance_init_block *ib = lp->init_block;
347 volatile struct lance_regs *ll = lp->ll;
348 volatile struct lance_tx_desc *td;
349 int i, j;
350 int status;
352 /* csr0 is 2f3 */
353 ll->rdp = LE_C0_TINT | LE_C0_INEA;
354 /* csr0 is 73 */
356 j = lp->tx_old;
357 for (i = j; i != lp->tx_new; i = j) {
358 td = &ib->btx_ring [i];
360 /* If we hit a packet not owned by us, stop */
361 if (td->tmd1_bits & LE_T1_OWN)
362 break;
364 if (td->tmd1_bits & LE_T1_ERR) {
365 status = td->misc;
367 lp->stats.tx_errors++;
368 if (status & LE_T3_RTY) lp->stats.tx_aborted_errors++;
369 if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
371 if (status & LE_T3_CLOS) {
372 lp->stats.tx_carrier_errors++;
373 if (lp->auto_select) {
374 lp->tpe = 1 - lp->tpe;
375 printk("%s: Carrier Lost, trying %s\n",
376 dev->name, lp->tpe?"TPE":"AUI");
377 /* Stop the lance */
378 ll->rap = LE_CSR0;
379 ll->rdp = LE_C0_STOP;
380 lance_init_ring (dev);
381 load_csrs (lp);
382 init_restart_lance (lp);
383 return 0;
387 /* buffer errors and underflows turn off the transmitter */
388 /* Restart the adapter */
389 if (status & (LE_T3_BUF|LE_T3_UFL)) {
390 lp->stats.tx_fifo_errors++;
392 printk ("%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
393 dev->name);
394 /* Stop the lance */
395 ll->rap = LE_CSR0;
396 ll->rdp = LE_C0_STOP;
397 lance_init_ring (dev);
398 load_csrs (lp);
399 init_restart_lance (lp);
400 return 0;
402 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
404 * So we don't count the packet more than once.
406 td->tmd1_bits &= ~(LE_T1_POK);
408 /* One collision before packet was sent. */
409 if (td->tmd1_bits & LE_T1_EONE)
410 lp->stats.collisions++;
412 /* More than one collision, be optimistic. */
413 if (td->tmd1_bits & LE_T1_EMORE)
414 lp->stats.collisions += 2;
416 lp->stats.tx_packets++;
419 j = (j + 1) & lp->tx_ring_mod_mask;
421 lp->tx_old = j;
422 ll->rdp = LE_C0_TINT | LE_C0_INEA;
423 return 0;
426 static void lance_interrupt (int irq, void *dev_id, struct pt_regs *regs)
428 struct net_device *dev;
429 struct lance_private *lp;
430 volatile struct lance_regs *ll;
431 int csr0;
433 dev = (struct net_device *) dev_id;
435 lp = (struct lance_private *) dev->priv;
436 ll = lp->ll;
438 ll->rap = LE_CSR0; /* LANCE Controller Status */
439 csr0 = ll->rdp;
441 if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */
442 return; /* been generated by the Lance. */
444 /* Acknowledge all the interrupt sources ASAP */
445 ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|
446 LE_C0_INIT);
448 if ((csr0 & LE_C0_ERR)) {
449 /* Clear the error condition */
450 ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
453 if (csr0 & LE_C0_RINT)
454 lance_rx (dev);
456 if (csr0 & LE_C0_TINT)
457 lance_tx (dev);
459 /* Log misc errors. */
460 if (csr0 & LE_C0_BABL)
461 lp->stats.tx_errors++; /* Tx babble. */
462 if (csr0 & LE_C0_MISS)
463 lp->stats.rx_errors++; /* Missed a Rx frame. */
464 if (csr0 & LE_C0_MERR) {
465 printk("%s: Bus master arbitration failure, status %4.4x.\n", dev->name, csr0);
466 /* Restart the chip. */
467 ll->rdp = LE_C0_STRT;
470 if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
471 netif_wake_queue(dev);
473 ll->rap = LE_CSR0;
474 ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
475 LE_C0_IDON|LE_C0_INEA;
479 struct net_device *last_dev = 0;
481 static int lance_open (struct net_device *dev)
483 struct lance_private *lp = (struct lance_private *)dev->priv;
484 volatile struct lance_regs *ll = lp->ll;
485 int status = 0;
487 last_dev = dev;
489 /* Install the Interrupt handler */
490 if (request_irq(IRQ_AMIGA_PORTS, lance_interrupt, SA_SHIRQ,
491 "a2065 Ethernet", dev))
492 return -EAGAIN;
494 /* Stop the Lance */
495 ll->rap = LE_CSR0;
496 ll->rdp = LE_C0_STOP;
498 load_csrs (lp);
499 lance_init_ring (dev);
501 netif_start_queue(dev);
503 status = init_restart_lance (lp);
505 MOD_INC_USE_COUNT;
507 return status;
510 static int lance_close (struct net_device *dev)
512 struct lance_private *lp = (struct lance_private *) dev->priv;
513 volatile struct lance_regs *ll = lp->ll;
515 netif_stop_queue(dev);
516 del_timer_sync(&lp->multicast_timer);
518 /* Stop the card */
519 ll->rap = LE_CSR0;
520 ll->rdp = LE_C0_STOP;
522 free_irq(IRQ_AMIGA_PORTS, dev);
524 MOD_DEC_USE_COUNT;
526 return 0;
529 static inline int lance_reset (struct net_device *dev)
531 struct lance_private *lp = (struct lance_private *)dev->priv;
532 volatile struct lance_regs *ll = lp->ll;
533 int status;
535 /* Stop the lance */
536 ll->rap = LE_CSR0;
537 ll->rdp = LE_C0_STOP;
539 load_csrs (lp);
541 lance_init_ring (dev);
542 dev->trans_start = jiffies;
543 netif_start_queue(dev);
545 status = init_restart_lance (lp);
546 #ifdef DEBUG_DRIVER
547 printk ("Lance restart=%d\n", status);
548 #endif
549 return status;
552 static void lance_tx_timeout(struct net_device *dev)
554 struct lance_private *lp = (struct lance_private *) dev->priv;
555 volatile struct lance_regs *ll = lp->ll;
557 printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
558 dev->name, ll->rdp);
559 lance_reset(dev);
560 netif_wake_queue(dev);
563 static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
565 struct lance_private *lp = (struct lance_private *)dev->priv;
566 volatile struct lance_regs *ll = lp->ll;
567 volatile struct lance_init_block *ib = lp->init_block;
568 int entry, skblen, len;
569 int status = 0;
570 static int outs;
571 unsigned long flags;
573 skblen = skb->len;
575 save_flags(flags);
576 cli();
578 if (!TX_BUFFS_AVAIL){
579 restore_flags(flags);
580 return -1;
583 #ifdef DEBUG_DRIVER
584 /* dump the packet */
586 int i;
588 for (i = 0; i < 64; i++) {
589 if ((i % 16) == 0)
590 printk ("\n");
591 printk ("%2.2x ", skb->data [i]);
594 #endif
595 len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
596 entry = lp->tx_new & lp->tx_ring_mod_mask;
597 ib->btx_ring [entry].length = (-len) | 0xf000;
598 ib->btx_ring [entry].misc = 0;
600 memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
602 /* Clear the slack of the packet, do I need this? */
603 if (len != skblen)
604 memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen);
606 /* Now, give the packet to the lance */
607 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
608 lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
610 outs++;
612 if (TX_BUFFS_AVAIL <= 0)
613 netif_stop_queue(dev);
615 /* Kick the lance: transmit now */
616 ll->rdp = LE_C0_INEA | LE_C0_TDMD;
617 dev->trans_start = jiffies;
618 dev_kfree_skb (skb);
620 restore_flags(flags);
622 return status;
625 static struct net_device_stats *lance_get_stats (struct net_device *dev)
627 struct lance_private *lp = (struct lance_private *) dev->priv;
629 return &lp->stats;
632 /* taken from the depca driver */
633 static void lance_load_multicast (struct net_device *dev)
635 struct lance_private *lp = (struct lance_private *) dev->priv;
636 volatile struct lance_init_block *ib = lp->init_block;
637 volatile u16 *mcast_table = (u16 *)&ib->filter;
638 struct dev_mc_list *dmi=dev->mc_list;
639 char *addrs;
640 int i, j, bit, byte;
641 u32 crc, poly = CRC_POLYNOMIAL_LE;
643 /* set all multicast bits */
644 if (dev->flags & IFF_ALLMULTI){
645 ib->filter [0] = 0xffffffff;
646 ib->filter [1] = 0xffffffff;
647 return;
649 /* clear the multicast filter */
650 ib->filter [0] = 0;
651 ib->filter [1] = 0;
653 /* Add addresses */
654 for (i = 0; i < dev->mc_count; i++){
655 addrs = dmi->dmi_addr;
656 dmi = dmi->next;
658 /* multicast address? */
659 if (!(*addrs & 1))
660 continue;
662 crc = 0xffffffff;
663 for (byte = 0; byte < 6; byte++)
664 for (bit = *addrs++, j = 0; j < 8; j++, bit>>=1)
666 int test;
668 test = ((bit ^ crc) & 0x01);
669 crc >>= 1;
671 if (test)
673 crc = crc ^ poly;
677 crc = crc >> 26;
678 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
680 return;
683 static void lance_set_multicast (struct net_device *dev)
685 struct lance_private *lp = (struct lance_private *) dev->priv;
686 volatile struct lance_init_block *ib = lp->init_block;
687 volatile struct lance_regs *ll = lp->ll;
689 if (!netif_running(dev))
690 return;
692 if (lp->tx_old != lp->tx_new) {
693 mod_timer(&lp->multicast_timer, jiffies + 4);
694 netif_wake_queue(dev);
695 return;
698 netif_stop_queue(dev);
700 ll->rap = LE_CSR0;
701 ll->rdp = LE_C0_STOP;
702 lance_init_ring (dev);
704 if (dev->flags & IFF_PROMISC) {
705 ib->mode |= LE_MO_PROM;
706 } else {
707 ib->mode &= ~LE_MO_PROM;
708 lance_load_multicast (dev);
710 load_csrs (lp);
711 init_restart_lance (lp);
712 netif_wake_queue(dev);
715 static int __init a2065_probe(void)
717 struct net_device *dev = NULL;
718 static int called = 0;
719 struct zorro_dev *z = NULL;
721 if (called)
722 return -ENODEV;
723 called++;
725 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
726 unsigned long board, base_addr, ram_start;
727 int is_cbm;
728 struct lance_private *priv;
730 if (z->id == ZORRO_PROD_CBM_A2065_1 ||
731 z->id == ZORRO_PROD_CBM_A2065_2)
732 is_cbm = 1;
733 else if (z->id == ZORRO_PROD_AMERISTAR_A2065)
734 is_cbm = 0;
735 else
736 continue;
738 board = z->resource.start;
739 base_addr = board+A2065_LANCE;
740 ram_start = board+A2065_RAM;
742 if (!request_mem_region(base_addr, sizeof(struct lance_regs),
743 "Am7990"))
744 continue;
745 if (!request_mem_region(ram_start, A2065_RAM_SIZE, "RAM")) {
746 release_mem_region(base_addr,
747 sizeof(struct lance_regs));
748 continue;
750 strcpy(z->name, "A2065 Ethernet Card");
752 dev = init_etherdev(NULL, sizeof(struct lance_private));
754 if (dev == NULL) {
755 release_mem_region(base_addr,
756 sizeof(struct lance_regs));
757 release_mem_region(ram_start, A2065_RAM_SIZE);
758 return -ENOMEM;
760 priv = (struct lance_private *)dev->priv;
761 memset(priv, 0, sizeof(struct lance_private));
763 if (is_cbm) { /* Commodore */
764 dev->dev_addr[0] = 0x00;
765 dev->dev_addr[1] = 0x80;
766 dev->dev_addr[2] = 0x10;
767 } else { /* Ameristar */
768 dev->dev_addr[0] = 0x00;
769 dev->dev_addr[1] = 0x00;
770 dev->dev_addr[2] = 0x9f;
772 dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
773 dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
774 dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
775 printk("%s: A2065 at 0x%08lx, Ethernet Address "
776 "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board,
777 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
778 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
780 dev->base_addr = ZTWO_VADDR(base_addr);
781 dev->mem_start = ZTWO_VADDR(ram_start);
782 dev->mem_end = dev->mem_start+A2065_RAM_SIZE;
784 priv->ll = (volatile struct lance_regs *)dev->base_addr;
785 priv->init_block = (struct lance_init_block *)dev->mem_start;
786 priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
787 priv->auto_select = 0;
788 priv->busmaster_regval = LE_C3_BSWP;
790 priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
791 priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
792 priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
793 priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
795 dev->open = &lance_open;
796 dev->stop = &lance_close;
797 dev->hard_start_xmit = &lance_start_xmit;
798 dev->tx_timeout = &lance_tx_timeout;
799 dev->watchdog_timeo = 5*HZ;
800 dev->get_stats = &lance_get_stats;
801 dev->set_multicast_list = &lance_set_multicast;
802 dev->dma = 0;
804 ether_setup(dev);
805 init_timer(&priv->multicast_timer);
806 priv->multicast_timer.data = (unsigned long) dev;
807 priv->multicast_timer.function =
808 (void (*)(unsigned long)) &lance_set_multicast;
810 return(0);
812 return(-ENODEV);
816 static void __exit a2065_cleanup(void)
818 #ifdef MODULE
819 struct lance_private *priv = (struct lance_private *)a2065_dev.priv;
821 unregister_netdev(&a2065_dev);
822 release_mem_region(ZTWO_PADDR(a2065_dev.base_addr),
823 sizeof(struct lance_regs));
824 release_mem_region(ZTWO_PADDR(a2065_dev.mem_start), A2065_RAM_SIZE);
825 kfree(priv);
826 #endif
829 module_init(a2065_probe);
830 module_exit(a2065_cleanup);