[TG3]: Add tagged status support.
[linux-2.6/verdex.git] / drivers / net / a2065.c
blob8e538a6d7d9793565e3095c8daa3ad755ec630d5
1 /*
2 * Amiga Linux/68k A2065 Ethernet Driver
4 * (C) Copyright 1995-2003 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)
9 * - Matt Domsch (Matt_Domsch@dell.com)
11 * ----------------------------------------------------------------------------
13 * This program is based on
15 * ariadne.?: Amiga Linux/68k Ariadne Ethernet Driver
16 * (C) Copyright 1995 by Geert Uytterhoeven,
17 * Peter De Schrijver
19 * lance.c: An AMD LANCE ethernet driver for linux.
20 * Written 1993-94 by Donald Becker.
22 * Am79C960: PCnet(tm)-ISA Single-Chip Ethernet Controller
23 * Advanced Micro Devices
24 * Publication #16907, Rev. B, Amendment/0, May 1994
26 * ----------------------------------------------------------------------------
28 * This file is subject to the terms and conditions of the GNU General Public
29 * License. See the file COPYING in the main directory of the Linux
30 * distribution for more details.
32 * ----------------------------------------------------------------------------
34 * The A2065 is a Zorro-II board made by Commodore/Ameristar. It contains:
36 * - an Am7990 Local Area Network Controller for Ethernet (LANCE) with
37 * both 10BASE-2 (thin coax) and AUI (DB-15) connectors
40 #include <linux/errno.h>
41 #include <linux/netdevice.h>
42 #include <linux/etherdevice.h>
43 #include <linux/module.h>
44 #include <linux/stddef.h>
45 #include <linux/kernel.h>
46 #include <linux/interrupt.h>
47 #include <linux/ioport.h>
48 #include <linux/skbuff.h>
49 #include <linux/slab.h>
50 #include <linux/string.h>
51 #include <linux/config.h>
52 #include <linux/init.h>
53 #include <linux/crc32.h>
54 #include <linux/zorro.h>
55 #include <linux/bitops.h>
57 #include <asm/irq.h>
58 #include <asm/amigaints.h>
59 #include <asm/amigahw.h>
61 #include "a2065.h"
65 * Transmit/Receive Ring Definitions
68 #define LANCE_LOG_TX_BUFFERS (2)
69 #define LANCE_LOG_RX_BUFFERS (4)
71 #define TX_RING_SIZE (1<<LANCE_LOG_TX_BUFFERS)
72 #define RX_RING_SIZE (1<<LANCE_LOG_RX_BUFFERS)
74 #define TX_RING_MOD_MASK (TX_RING_SIZE-1)
75 #define RX_RING_MOD_MASK (RX_RING_SIZE-1)
77 #define PKT_BUF_SIZE (1544)
78 #define RX_BUFF_SIZE PKT_BUF_SIZE
79 #define TX_BUFF_SIZE PKT_BUF_SIZE
83 * Layout of the Lance's RAM Buffer
87 struct lance_init_block {
88 unsigned short mode; /* Pre-set mode (reg. 15) */
89 unsigned char phys_addr[6]; /* Physical ethernet address */
90 unsigned filter[2]; /* Multicast filter. */
92 /* Receive and transmit ring base, along with extra bits. */
93 unsigned short rx_ptr; /* receive descriptor addr */
94 unsigned short rx_len; /* receive len and high addr */
95 unsigned short tx_ptr; /* transmit descriptor addr */
96 unsigned short tx_len; /* transmit len and high addr */
98 /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */
99 struct lance_rx_desc brx_ring[RX_RING_SIZE];
100 struct lance_tx_desc btx_ring[TX_RING_SIZE];
102 char rx_buf [RX_RING_SIZE][RX_BUFF_SIZE];
103 char tx_buf [TX_RING_SIZE][TX_BUFF_SIZE];
108 * Private Device Data
111 struct lance_private {
112 char *name;
113 volatile struct lance_regs *ll;
114 volatile struct lance_init_block *init_block; /* Hosts view */
115 volatile struct lance_init_block *lance_init_block; /* Lance view */
117 int rx_new, tx_new;
118 int rx_old, tx_old;
120 int lance_log_rx_bufs, lance_log_tx_bufs;
121 int rx_ring_mod_mask, tx_ring_mod_mask;
123 struct net_device_stats stats;
124 int tpe; /* cable-selection is TPE */
125 int auto_select; /* cable-selection by carrier */
126 unsigned short busmaster_regval;
128 #ifdef CONFIG_SUNLANCE
129 struct Linux_SBus_DMA *ledma; /* if set this points to ledma and arch=4m */
130 int burst_sizes; /* ledma SBus burst sizes */
131 #endif
132 struct timer_list multicast_timer;
135 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
136 lp->tx_old+lp->tx_ring_mod_mask-lp->tx_new:\
137 lp->tx_old - lp->tx_new-1)
140 #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
142 /* Load the CSR registers */
143 static void load_csrs (struct lance_private *lp)
145 volatile struct lance_regs *ll = lp->ll;
146 volatile struct lance_init_block *aib = lp->lance_init_block;
147 int leptr;
149 leptr = LANCE_ADDR (aib);
151 ll->rap = LE_CSR1;
152 ll->rdp = (leptr & 0xFFFF);
153 ll->rap = LE_CSR2;
154 ll->rdp = leptr >> 16;
155 ll->rap = LE_CSR3;
156 ll->rdp = lp->busmaster_regval;
158 /* Point back to csr0 */
159 ll->rap = LE_CSR0;
162 #define ZERO 0
164 /* Setup the Lance Rx and Tx rings */
165 static void lance_init_ring (struct net_device *dev)
167 struct lance_private *lp = netdev_priv(dev);
168 volatile struct lance_init_block *ib = lp->init_block;
169 volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */
170 int leptr;
171 int i;
173 aib = lp->lance_init_block;
175 /* Lock out other processes while setting up hardware */
176 netif_stop_queue(dev);
177 lp->rx_new = lp->tx_new = 0;
178 lp->rx_old = lp->tx_old = 0;
180 ib->mode = 0;
182 /* Copy the ethernet address to the lance init block
183 * Note that on the sparc you need to swap the ethernet address.
185 ib->phys_addr [0] = dev->dev_addr [1];
186 ib->phys_addr [1] = dev->dev_addr [0];
187 ib->phys_addr [2] = dev->dev_addr [3];
188 ib->phys_addr [3] = dev->dev_addr [2];
189 ib->phys_addr [4] = dev->dev_addr [5];
190 ib->phys_addr [5] = dev->dev_addr [4];
192 if (ZERO)
193 printk(KERN_DEBUG "TX rings:\n");
195 /* Setup the Tx ring entries */
196 for (i = 0; i <= (1<<lp->lance_log_tx_bufs); i++) {
197 leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
198 ib->btx_ring [i].tmd0 = leptr;
199 ib->btx_ring [i].tmd1_hadr = leptr >> 16;
200 ib->btx_ring [i].tmd1_bits = 0;
201 ib->btx_ring [i].length = 0xf000; /* The ones required by tmd2 */
202 ib->btx_ring [i].misc = 0;
203 if (i < 3 && ZERO)
204 printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr);
207 /* Setup the Rx ring entries */
208 if (ZERO)
209 printk(KERN_DEBUG "RX rings:\n");
210 for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) {
211 leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
213 ib->brx_ring [i].rmd0 = leptr;
214 ib->brx_ring [i].rmd1_hadr = leptr >> 16;
215 ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
216 ib->brx_ring [i].length = -RX_BUFF_SIZE | 0xf000;
217 ib->brx_ring [i].mblength = 0;
218 if (i < 3 && ZERO)
219 printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr);
222 /* Setup the initialization block */
224 /* Setup rx descriptor pointer */
225 leptr = LANCE_ADDR(&aib->brx_ring);
226 ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
227 ib->rx_ptr = leptr;
228 if (ZERO)
229 printk(KERN_DEBUG "RX ptr: %8.8x\n", leptr);
231 /* Setup tx descriptor pointer */
232 leptr = LANCE_ADDR(&aib->btx_ring);
233 ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
234 ib->tx_ptr = leptr;
235 if (ZERO)
236 printk(KERN_DEBUG "TX ptr: %8.8x\n", leptr);
238 /* Clear the multicast filter */
239 ib->filter [0] = 0;
240 ib->filter [1] = 0;
243 static int init_restart_lance (struct lance_private *lp)
245 volatile struct lance_regs *ll = lp->ll;
246 int i;
248 ll->rap = LE_CSR0;
249 ll->rdp = LE_C0_INIT;
251 /* Wait for the lance to complete initialization */
252 for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++)
253 barrier();
254 if ((i == 100) || (ll->rdp & LE_C0_ERR)) {
255 printk(KERN_ERR "LANCE unopened after %d ticks, csr0=%4.4x.\n",
256 i, ll->rdp);
257 return -EIO;
260 /* Clear IDON by writing a "1", enable interrupts and start lance */
261 ll->rdp = LE_C0_IDON;
262 ll->rdp = LE_C0_INEA | LE_C0_STRT;
264 return 0;
267 static int lance_rx (struct net_device *dev)
269 struct lance_private *lp = netdev_priv(dev);
270 volatile struct lance_init_block *ib = lp->init_block;
271 volatile struct lance_regs *ll = lp->ll;
272 volatile struct lance_rx_desc *rd;
273 unsigned char bits;
274 int len = 0; /* XXX shut up gcc warnings */
275 struct sk_buff *skb = 0; /* XXX shut up gcc warnings */
277 #ifdef TEST_HITS
278 int i;
279 printk(KERN_DEBUG "[");
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 ("]\n");
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(KERN_WARNING "%s: Memory squeeze, "
316 "deferring packet.\n", 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 dev->last_rx = jiffies;
333 lp->stats.rx_packets++;
334 lp->stats.rx_bytes += len;
337 /* Return the packet to the pool */
338 rd->mblength = 0;
339 rd->rmd1_bits = LE_R1_OWN;
340 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
342 return 0;
345 static int lance_tx (struct net_device *dev)
347 struct lance_private *lp = netdev_priv(dev);
348 volatile struct lance_init_block *ib = lp->init_block;
349 volatile struct lance_regs *ll = lp->ll;
350 volatile struct lance_tx_desc *td;
351 int i, j;
352 int status;
354 /* csr0 is 2f3 */
355 ll->rdp = LE_C0_TINT | LE_C0_INEA;
356 /* csr0 is 73 */
358 j = lp->tx_old;
359 for (i = j; i != lp->tx_new; i = j) {
360 td = &ib->btx_ring [i];
362 /* If we hit a packet not owned by us, stop */
363 if (td->tmd1_bits & LE_T1_OWN)
364 break;
366 if (td->tmd1_bits & LE_T1_ERR) {
367 status = td->misc;
369 lp->stats.tx_errors++;
370 if (status & LE_T3_RTY) lp->stats.tx_aborted_errors++;
371 if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
373 if (status & LE_T3_CLOS) {
374 lp->stats.tx_carrier_errors++;
375 if (lp->auto_select) {
376 lp->tpe = 1 - lp->tpe;
377 printk(KERN_ERR "%s: Carrier Lost, "
378 "trying %s\n", dev->name,
379 lp->tpe?"TPE":"AUI");
380 /* Stop the lance */
381 ll->rap = LE_CSR0;
382 ll->rdp = LE_C0_STOP;
383 lance_init_ring (dev);
384 load_csrs (lp);
385 init_restart_lance (lp);
386 return 0;
390 /* buffer errors and underflows turn off the transmitter */
391 /* Restart the adapter */
392 if (status & (LE_T3_BUF|LE_T3_UFL)) {
393 lp->stats.tx_fifo_errors++;
395 printk(KERN_ERR "%s: Tx: ERR_BUF|ERR_UFL, "
396 "restarting\n", dev->name);
397 /* Stop the lance */
398 ll->rap = LE_CSR0;
399 ll->rdp = LE_C0_STOP;
400 lance_init_ring (dev);
401 load_csrs (lp);
402 init_restart_lance (lp);
403 return 0;
405 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
407 * So we don't count the packet more than once.
409 td->tmd1_bits &= ~(LE_T1_POK);
411 /* One collision before packet was sent. */
412 if (td->tmd1_bits & LE_T1_EONE)
413 lp->stats.collisions++;
415 /* More than one collision, be optimistic. */
416 if (td->tmd1_bits & LE_T1_EMORE)
417 lp->stats.collisions += 2;
419 lp->stats.tx_packets++;
422 j = (j + 1) & lp->tx_ring_mod_mask;
424 lp->tx_old = j;
425 ll->rdp = LE_C0_TINT | LE_C0_INEA;
426 return 0;
429 static irqreturn_t
430 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 = netdev_priv(dev);
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 IRQ_NONE; /* been generated by the Lance. */
448 /* Acknowledge all the interrupt sources ASAP */
449 ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|
450 LE_C0_INIT);
452 if ((csr0 & LE_C0_ERR)) {
453 /* Clear the error condition */
454 ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
457 if (csr0 & LE_C0_RINT)
458 lance_rx (dev);
460 if (csr0 & LE_C0_TINT)
461 lance_tx (dev);
463 /* Log misc errors. */
464 if (csr0 & LE_C0_BABL)
465 lp->stats.tx_errors++; /* Tx babble. */
466 if (csr0 & LE_C0_MISS)
467 lp->stats.rx_errors++; /* Missed a Rx frame. */
468 if (csr0 & LE_C0_MERR) {
469 printk(KERN_ERR "%s: Bus master arbitration failure, status "
470 "%4.4x.\n", dev->name, csr0);
471 /* Restart the chip. */
472 ll->rdp = LE_C0_STRT;
475 if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
476 netif_wake_queue(dev);
478 ll->rap = LE_CSR0;
479 ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
480 LE_C0_IDON|LE_C0_INEA;
481 return IRQ_HANDLED;
484 struct net_device *last_dev = 0;
486 static int lance_open (struct net_device *dev)
488 struct lance_private *lp = netdev_priv(dev);
489 volatile struct lance_regs *ll = lp->ll;
490 int ret;
492 last_dev = dev;
494 /* Stop the Lance */
495 ll->rap = LE_CSR0;
496 ll->rdp = LE_C0_STOP;
498 /* Install the Interrupt handler */
499 ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, SA_SHIRQ,
500 dev->name, dev);
501 if (ret) return ret;
503 load_csrs (lp);
504 lance_init_ring (dev);
506 netif_start_queue(dev);
508 return init_restart_lance (lp);
511 static int lance_close (struct net_device *dev)
513 struct lance_private *lp = netdev_priv(dev);
514 volatile struct lance_regs *ll = lp->ll;
516 netif_stop_queue(dev);
517 del_timer_sync(&lp->multicast_timer);
519 /* Stop the card */
520 ll->rap = LE_CSR0;
521 ll->rdp = LE_C0_STOP;
523 free_irq(IRQ_AMIGA_PORTS, dev);
524 return 0;
527 static inline int lance_reset (struct net_device *dev)
529 struct lance_private *lp = netdev_priv(dev);
530 volatile struct lance_regs *ll = lp->ll;
531 int status;
533 /* Stop the lance */
534 ll->rap = LE_CSR0;
535 ll->rdp = LE_C0_STOP;
537 load_csrs (lp);
539 lance_init_ring (dev);
540 dev->trans_start = jiffies;
541 netif_start_queue(dev);
543 status = init_restart_lance (lp);
544 #ifdef DEBUG_DRIVER
545 printk(KERN_DEBUG "Lance restart=%d\n", status);
546 #endif
547 return status;
550 static void lance_tx_timeout(struct net_device *dev)
552 struct lance_private *lp = netdev_priv(dev);
553 volatile struct lance_regs *ll = lp->ll;
555 printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
556 dev->name, ll->rdp);
557 lance_reset(dev);
558 netif_wake_queue(dev);
561 static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
563 struct lance_private *lp = netdev_priv(dev);
564 volatile struct lance_regs *ll = lp->ll;
565 volatile struct lance_init_block *ib = lp->init_block;
566 int entry, skblen, len;
567 int status = 0;
568 static int outs;
569 unsigned long flags;
571 skblen = skb->len;
572 len = skblen;
574 if (len < ETH_ZLEN) {
575 len = ETH_ZLEN;
576 skb = skb_padto(skb, ETH_ZLEN);
577 if (skb == NULL)
578 return 0;
581 local_irq_save(flags);
583 if (!TX_BUFFS_AVAIL){
584 local_irq_restore(flags);
585 return -1;
588 #ifdef DEBUG_DRIVER
589 /* dump the packet */
591 int i;
593 for (i = 0; i < 64; i++) {
594 if ((i % 16) == 0)
595 printk("\n" KERN_DEBUG);
596 printk ("%2.2x ", skb->data [i]);
598 printk("\n");
600 #endif
601 entry = lp->tx_new & lp->tx_ring_mod_mask;
602 ib->btx_ring [entry].length = (-len) | 0xf000;
603 ib->btx_ring [entry].misc = 0;
605 memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
607 /* Clear the slack of the packet, do I need this? */
608 if (len != skblen)
609 memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen);
611 /* Now, give the packet to the lance */
612 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
613 lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
615 outs++;
617 if (TX_BUFFS_AVAIL <= 0)
618 netif_stop_queue(dev);
620 /* Kick the lance: transmit now */
621 ll->rdp = LE_C0_INEA | LE_C0_TDMD;
622 dev->trans_start = jiffies;
623 dev_kfree_skb (skb);
625 local_irq_restore(flags);
627 return status;
630 static struct net_device_stats *lance_get_stats (struct net_device *dev)
632 struct lance_private *lp = netdev_priv(dev);
634 return &lp->stats;
637 /* taken from the depca driver */
638 static void lance_load_multicast (struct net_device *dev)
640 struct lance_private *lp = netdev_priv(dev);
641 volatile struct lance_init_block *ib = lp->init_block;
642 volatile u16 *mcast_table = (u16 *)&ib->filter;
643 struct dev_mc_list *dmi=dev->mc_list;
644 char *addrs;
645 int i;
646 u32 crc;
648 /* set all multicast bits */
649 if (dev->flags & IFF_ALLMULTI){
650 ib->filter [0] = 0xffffffff;
651 ib->filter [1] = 0xffffffff;
652 return;
654 /* clear the multicast filter */
655 ib->filter [0] = 0;
656 ib->filter [1] = 0;
658 /* Add addresses */
659 for (i = 0; i < dev->mc_count; i++){
660 addrs = dmi->dmi_addr;
661 dmi = dmi->next;
663 /* multicast address? */
664 if (!(*addrs & 1))
665 continue;
667 crc = ether_crc_le(6, addrs);
668 crc = crc >> 26;
669 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
671 return;
674 static void lance_set_multicast (struct net_device *dev)
676 struct lance_private *lp = netdev_priv(dev);
677 volatile struct lance_init_block *ib = lp->init_block;
678 volatile struct lance_regs *ll = lp->ll;
680 if (!netif_running(dev))
681 return;
683 if (lp->tx_old != lp->tx_new) {
684 mod_timer(&lp->multicast_timer, jiffies + 4);
685 netif_wake_queue(dev);
686 return;
689 netif_stop_queue(dev);
691 ll->rap = LE_CSR0;
692 ll->rdp = LE_C0_STOP;
693 lance_init_ring (dev);
695 if (dev->flags & IFF_PROMISC) {
696 ib->mode |= LE_MO_PROM;
697 } else {
698 ib->mode &= ~LE_MO_PROM;
699 lance_load_multicast (dev);
701 load_csrs (lp);
702 init_restart_lance (lp);
703 netif_wake_queue(dev);
706 static int __devinit a2065_init_one(struct zorro_dev *z,
707 const struct zorro_device_id *ent);
708 static void __devexit a2065_remove_one(struct zorro_dev *z);
711 static struct zorro_device_id a2065_zorro_tbl[] __devinitdata = {
712 { ZORRO_PROD_CBM_A2065_1 },
713 { ZORRO_PROD_CBM_A2065_2 },
714 { ZORRO_PROD_AMERISTAR_A2065 },
715 { 0 }
718 static struct zorro_driver a2065_driver = {
719 .name = "a2065",
720 .id_table = a2065_zorro_tbl,
721 .probe = a2065_init_one,
722 .remove = __devexit_p(a2065_remove_one),
725 static int __devinit a2065_init_one(struct zorro_dev *z,
726 const struct zorro_device_id *ent)
728 struct net_device *dev;
729 struct lance_private *priv;
730 unsigned long board, base_addr, mem_start;
731 struct resource *r1, *r2;
732 int err;
734 board = z->resource.start;
735 base_addr = board+A2065_LANCE;
736 mem_start = board+A2065_RAM;
738 r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
739 "Am7990");
740 if (!r1)
741 return -EBUSY;
742 r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
743 if (!r2) {
744 release_resource(r1);
745 return -EBUSY;
748 dev = alloc_etherdev(sizeof(struct lance_private));
749 if (dev == NULL) {
750 release_resource(r1);
751 release_resource(r2);
752 return -ENOMEM;
755 SET_MODULE_OWNER(dev);
756 priv = netdev_priv(dev);
758 r1->name = dev->name;
759 r2->name = dev->name;
761 dev->dev_addr[0] = 0x00;
762 if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* 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;
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 dev->base_addr = ZTWO_VADDR(base_addr);
773 dev->mem_start = ZTWO_VADDR(mem_start);
774 dev->mem_end = dev->mem_start+A2065_RAM_SIZE;
776 priv->ll = (volatile struct lance_regs *)dev->base_addr;
777 priv->init_block = (struct lance_init_block *)dev->mem_start;
778 priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
779 priv->auto_select = 0;
780 priv->busmaster_regval = LE_C3_BSWP;
782 priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
783 priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
784 priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
785 priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
787 dev->open = &lance_open;
788 dev->stop = &lance_close;
789 dev->hard_start_xmit = &lance_start_xmit;
790 dev->tx_timeout = &lance_tx_timeout;
791 dev->watchdog_timeo = 5*HZ;
792 dev->get_stats = &lance_get_stats;
793 dev->set_multicast_list = &lance_set_multicast;
794 dev->dma = 0;
796 init_timer(&priv->multicast_timer);
797 priv->multicast_timer.data = (unsigned long) dev;
798 priv->multicast_timer.function =
799 (void (*)(unsigned long)) &lance_set_multicast;
801 err = register_netdev(dev);
802 if (err) {
803 release_resource(r1);
804 release_resource(r2);
805 free_netdev(dev);
806 return err;
808 zorro_set_drvdata(z, dev);
810 printk(KERN_INFO "%s: A2065 at 0x%08lx, Ethernet Address "
811 "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board,
812 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
813 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
815 return 0;
819 static void __devexit a2065_remove_one(struct zorro_dev *z)
821 struct net_device *dev = zorro_get_drvdata(z);
823 unregister_netdev(dev);
824 release_mem_region(ZTWO_PADDR(dev->base_addr),
825 sizeof(struct lance_regs));
826 release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
827 free_netdev(dev);
830 static int __init a2065_init_module(void)
832 return zorro_module_init(&a2065_driver);
835 static void __exit a2065_cleanup_module(void)
837 zorro_unregister_driver(&a2065_driver);
840 module_init(a2065_init_module);
841 module_exit(a2065_cleanup_module);
843 MODULE_LICENSE("GPL");