ARM: PL08x: ensure loops use cpu_relax()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / a2065.c
blobf142cc21e453dfddceabee7bd669171977622ed2
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/string.h>
50 #include <linux/init.h>
51 #include <linux/crc32.h>
52 #include <linux/zorro.h>
53 #include <linux/bitops.h>
55 #include <asm/irq.h>
56 #include <asm/amigaints.h>
57 #include <asm/amigahw.h>
59 #include "a2065.h"
63 * Transmit/Receive Ring Definitions
66 #define LANCE_LOG_TX_BUFFERS (2)
67 #define LANCE_LOG_RX_BUFFERS (4)
69 #define TX_RING_SIZE (1<<LANCE_LOG_TX_BUFFERS)
70 #define RX_RING_SIZE (1<<LANCE_LOG_RX_BUFFERS)
72 #define TX_RING_MOD_MASK (TX_RING_SIZE-1)
73 #define RX_RING_MOD_MASK (RX_RING_SIZE-1)
75 #define PKT_BUF_SIZE (1544)
76 #define RX_BUFF_SIZE PKT_BUF_SIZE
77 #define TX_BUFF_SIZE PKT_BUF_SIZE
81 * Layout of the Lance's RAM Buffer
85 struct lance_init_block {
86 unsigned short mode; /* Pre-set mode (reg. 15) */
87 unsigned char phys_addr[6]; /* Physical ethernet address */
88 unsigned filter[2]; /* Multicast filter. */
90 /* Receive and transmit ring base, along with extra bits. */
91 unsigned short rx_ptr; /* receive descriptor addr */
92 unsigned short rx_len; /* receive len and high addr */
93 unsigned short tx_ptr; /* transmit descriptor addr */
94 unsigned short tx_len; /* transmit len and high addr */
96 /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */
97 struct lance_rx_desc brx_ring[RX_RING_SIZE];
98 struct lance_tx_desc btx_ring[TX_RING_SIZE];
100 char rx_buf [RX_RING_SIZE][RX_BUFF_SIZE];
101 char tx_buf [TX_RING_SIZE][TX_BUFF_SIZE];
106 * Private Device Data
109 struct lance_private {
110 char *name;
111 volatile struct lance_regs *ll;
112 volatile struct lance_init_block *init_block; /* Hosts view */
113 volatile struct lance_init_block *lance_init_block; /* Lance view */
115 int rx_new, tx_new;
116 int rx_old, tx_old;
118 int lance_log_rx_bufs, lance_log_tx_bufs;
119 int rx_ring_mod_mask, tx_ring_mod_mask;
121 int tpe; /* cable-selection is TPE */
122 int auto_select; /* cable-selection by carrier */
123 unsigned short busmaster_regval;
125 #ifdef CONFIG_SUNLANCE
126 struct Linux_SBus_DMA *ledma; /* if set this points to ledma and arch=4m */
127 int burst_sizes; /* ledma SBus burst sizes */
128 #endif
129 struct timer_list multicast_timer;
132 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
133 lp->tx_old+lp->tx_ring_mod_mask-lp->tx_new:\
134 lp->tx_old - lp->tx_new-1)
137 #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
139 /* Load the CSR registers */
140 static void load_csrs (struct lance_private *lp)
142 volatile struct lance_regs *ll = lp->ll;
143 volatile struct lance_init_block *aib = lp->lance_init_block;
144 int leptr;
146 leptr = LANCE_ADDR (aib);
148 ll->rap = LE_CSR1;
149 ll->rdp = (leptr & 0xFFFF);
150 ll->rap = LE_CSR2;
151 ll->rdp = leptr >> 16;
152 ll->rap = LE_CSR3;
153 ll->rdp = lp->busmaster_regval;
155 /* Point back to csr0 */
156 ll->rap = LE_CSR0;
159 #define ZERO 0
161 /* Setup the Lance Rx and Tx rings */
162 static void lance_init_ring (struct net_device *dev)
164 struct lance_private *lp = netdev_priv(dev);
165 volatile struct lance_init_block *ib = lp->init_block;
166 volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */
167 int leptr;
168 int i;
170 aib = lp->lance_init_block;
172 /* Lock out other processes while setting up hardware */
173 netif_stop_queue(dev);
174 lp->rx_new = lp->tx_new = 0;
175 lp->rx_old = lp->tx_old = 0;
177 ib->mode = 0;
179 /* Copy the ethernet address to the lance init block
180 * Note that on the sparc you need to swap the ethernet address.
182 ib->phys_addr [0] = dev->dev_addr [1];
183 ib->phys_addr [1] = dev->dev_addr [0];
184 ib->phys_addr [2] = dev->dev_addr [3];
185 ib->phys_addr [3] = dev->dev_addr [2];
186 ib->phys_addr [4] = dev->dev_addr [5];
187 ib->phys_addr [5] = dev->dev_addr [4];
189 if (ZERO)
190 printk(KERN_DEBUG "TX rings:\n");
192 /* Setup the Tx ring entries */
193 for (i = 0; i <= (1<<lp->lance_log_tx_bufs); i++) {
194 leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
195 ib->btx_ring [i].tmd0 = leptr;
196 ib->btx_ring [i].tmd1_hadr = leptr >> 16;
197 ib->btx_ring [i].tmd1_bits = 0;
198 ib->btx_ring [i].length = 0xf000; /* The ones required by tmd2 */
199 ib->btx_ring [i].misc = 0;
200 if (i < 3 && ZERO)
201 printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr);
204 /* Setup the Rx ring entries */
205 if (ZERO)
206 printk(KERN_DEBUG "RX rings:\n");
207 for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) {
208 leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
210 ib->brx_ring [i].rmd0 = leptr;
211 ib->brx_ring [i].rmd1_hadr = leptr >> 16;
212 ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
213 ib->brx_ring [i].length = -RX_BUFF_SIZE | 0xf000;
214 ib->brx_ring [i].mblength = 0;
215 if (i < 3 && ZERO)
216 printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr);
219 /* Setup the initialization block */
221 /* Setup rx descriptor pointer */
222 leptr = LANCE_ADDR(&aib->brx_ring);
223 ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
224 ib->rx_ptr = leptr;
225 if (ZERO)
226 printk(KERN_DEBUG "RX ptr: %8.8x\n", leptr);
228 /* Setup tx descriptor pointer */
229 leptr = LANCE_ADDR(&aib->btx_ring);
230 ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
231 ib->tx_ptr = leptr;
232 if (ZERO)
233 printk(KERN_DEBUG "TX ptr: %8.8x\n", leptr);
235 /* Clear the multicast filter */
236 ib->filter [0] = 0;
237 ib->filter [1] = 0;
240 static int init_restart_lance (struct lance_private *lp)
242 volatile struct lance_regs *ll = lp->ll;
243 int i;
245 ll->rap = LE_CSR0;
246 ll->rdp = LE_C0_INIT;
248 /* Wait for the lance to complete initialization */
249 for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++)
250 barrier();
251 if ((i == 100) || (ll->rdp & LE_C0_ERR)) {
252 printk(KERN_ERR "LANCE unopened after %d ticks, csr0=%4.4x.\n",
253 i, ll->rdp);
254 return -EIO;
257 /* Clear IDON by writing a "1", enable interrupts and start lance */
258 ll->rdp = LE_C0_IDON;
259 ll->rdp = LE_C0_INEA | LE_C0_STRT;
261 return 0;
264 static int lance_rx (struct net_device *dev)
266 struct lance_private *lp = netdev_priv(dev);
267 volatile struct lance_init_block *ib = lp->init_block;
268 volatile struct lance_regs *ll = lp->ll;
269 volatile struct lance_rx_desc *rd;
270 unsigned char bits;
272 #ifdef TEST_HITS
273 int i;
274 printk(KERN_DEBUG "[");
275 for (i = 0; i < RX_RING_SIZE; i++) {
276 if (i == lp->rx_new)
277 printk ("%s",
278 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X");
279 else
280 printk ("%s",
281 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1");
283 printk ("]\n");
284 #endif
286 ll->rdp = LE_C0_RINT|LE_C0_INEA;
287 for (rd = &ib->brx_ring [lp->rx_new];
288 !((bits = rd->rmd1_bits) & LE_R1_OWN);
289 rd = &ib->brx_ring [lp->rx_new]) {
291 /* We got an incomplete frame? */
292 if ((bits & LE_R1_POK) != LE_R1_POK) {
293 dev->stats.rx_over_errors++;
294 dev->stats.rx_errors++;
295 continue;
296 } else if (bits & LE_R1_ERR) {
297 /* Count only the end frame as a rx error,
298 * not the beginning
300 if (bits & LE_R1_BUF) dev->stats.rx_fifo_errors++;
301 if (bits & LE_R1_CRC) dev->stats.rx_crc_errors++;
302 if (bits & LE_R1_OFL) dev->stats.rx_over_errors++;
303 if (bits & LE_R1_FRA) dev->stats.rx_frame_errors++;
304 if (bits & LE_R1_EOP) dev->stats.rx_errors++;
305 } else {
306 int len = (rd->mblength & 0xfff) - 4;
307 struct sk_buff *skb = dev_alloc_skb (len+2);
309 if (!skb) {
310 printk(KERN_WARNING "%s: Memory squeeze, "
311 "deferring packet.\n", dev->name);
312 dev->stats.rx_dropped++;
313 rd->mblength = 0;
314 rd->rmd1_bits = LE_R1_OWN;
315 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
316 return 0;
319 skb_reserve (skb, 2); /* 16 byte align */
320 skb_put (skb, len); /* make room */
321 skb_copy_to_linear_data(skb,
322 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
323 len);
324 skb->protocol = eth_type_trans (skb, dev);
325 netif_rx (skb);
326 dev->stats.rx_packets++;
327 dev->stats.rx_bytes += len;
330 /* Return the packet to the pool */
331 rd->mblength = 0;
332 rd->rmd1_bits = LE_R1_OWN;
333 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
335 return 0;
338 static int lance_tx (struct net_device *dev)
340 struct lance_private *lp = netdev_priv(dev);
341 volatile struct lance_init_block *ib = lp->init_block;
342 volatile struct lance_regs *ll = lp->ll;
343 volatile struct lance_tx_desc *td;
344 int i, j;
345 int status;
347 /* csr0 is 2f3 */
348 ll->rdp = LE_C0_TINT | LE_C0_INEA;
349 /* csr0 is 73 */
351 j = lp->tx_old;
352 for (i = j; i != lp->tx_new; i = j) {
353 td = &ib->btx_ring [i];
355 /* If we hit a packet not owned by us, stop */
356 if (td->tmd1_bits & LE_T1_OWN)
357 break;
359 if (td->tmd1_bits & LE_T1_ERR) {
360 status = td->misc;
362 dev->stats.tx_errors++;
363 if (status & LE_T3_RTY) dev->stats.tx_aborted_errors++;
364 if (status & LE_T3_LCOL) dev->stats.tx_window_errors++;
366 if (status & LE_T3_CLOS) {
367 dev->stats.tx_carrier_errors++;
368 if (lp->auto_select) {
369 lp->tpe = 1 - lp->tpe;
370 printk(KERN_ERR "%s: Carrier Lost, "
371 "trying %s\n", dev->name,
372 lp->tpe?"TPE":"AUI");
373 /* Stop the lance */
374 ll->rap = LE_CSR0;
375 ll->rdp = LE_C0_STOP;
376 lance_init_ring (dev);
377 load_csrs (lp);
378 init_restart_lance (lp);
379 return 0;
383 /* buffer errors and underflows turn off the transmitter */
384 /* Restart the adapter */
385 if (status & (LE_T3_BUF|LE_T3_UFL)) {
386 dev->stats.tx_fifo_errors++;
388 printk(KERN_ERR "%s: Tx: ERR_BUF|ERR_UFL, "
389 "restarting\n", dev->name);
390 /* Stop the lance */
391 ll->rap = LE_CSR0;
392 ll->rdp = LE_C0_STOP;
393 lance_init_ring (dev);
394 load_csrs (lp);
395 init_restart_lance (lp);
396 return 0;
398 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
400 * So we don't count the packet more than once.
402 td->tmd1_bits &= ~(LE_T1_POK);
404 /* One collision before packet was sent. */
405 if (td->tmd1_bits & LE_T1_EONE)
406 dev->stats.collisions++;
408 /* More than one collision, be optimistic. */
409 if (td->tmd1_bits & LE_T1_EMORE)
410 dev->stats.collisions += 2;
412 dev->stats.tx_packets++;
415 j = (j + 1) & lp->tx_ring_mod_mask;
417 lp->tx_old = j;
418 ll->rdp = LE_C0_TINT | LE_C0_INEA;
419 return 0;
422 static irqreturn_t lance_interrupt (int irq, void *dev_id)
424 struct net_device *dev;
425 struct lance_private *lp;
426 volatile struct lance_regs *ll;
427 int csr0;
429 dev = (struct net_device *) dev_id;
431 lp = netdev_priv(dev);
432 ll = lp->ll;
434 ll->rap = LE_CSR0; /* LANCE Controller Status */
435 csr0 = ll->rdp;
437 if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */
438 return IRQ_NONE; /* been generated by the Lance. */
440 /* Acknowledge all the interrupt sources ASAP */
441 ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|
442 LE_C0_INIT);
444 if ((csr0 & LE_C0_ERR)) {
445 /* Clear the error condition */
446 ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
449 if (csr0 & LE_C0_RINT)
450 lance_rx (dev);
452 if (csr0 & LE_C0_TINT)
453 lance_tx (dev);
455 /* Log misc errors. */
456 if (csr0 & LE_C0_BABL)
457 dev->stats.tx_errors++; /* Tx babble. */
458 if (csr0 & LE_C0_MISS)
459 dev->stats.rx_errors++; /* Missed a Rx frame. */
460 if (csr0 & LE_C0_MERR) {
461 printk(KERN_ERR "%s: Bus master arbitration failure, status "
462 "%4.4x.\n", dev->name, csr0);
463 /* Restart the chip. */
464 ll->rdp = LE_C0_STRT;
467 if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
468 netif_wake_queue(dev);
470 ll->rap = LE_CSR0;
471 ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
472 LE_C0_IDON|LE_C0_INEA;
473 return IRQ_HANDLED;
476 static int lance_open (struct net_device *dev)
478 struct lance_private *lp = netdev_priv(dev);
479 volatile struct lance_regs *ll = lp->ll;
480 int ret;
482 /* Stop the Lance */
483 ll->rap = LE_CSR0;
484 ll->rdp = LE_C0_STOP;
486 /* Install the Interrupt handler */
487 ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, IRQF_SHARED,
488 dev->name, dev);
489 if (ret) return ret;
491 load_csrs (lp);
492 lance_init_ring (dev);
494 netif_start_queue(dev);
496 return init_restart_lance (lp);
499 static int lance_close (struct net_device *dev)
501 struct lance_private *lp = netdev_priv(dev);
502 volatile struct lance_regs *ll = lp->ll;
504 netif_stop_queue(dev);
505 del_timer_sync(&lp->multicast_timer);
507 /* Stop the card */
508 ll->rap = LE_CSR0;
509 ll->rdp = LE_C0_STOP;
511 free_irq(IRQ_AMIGA_PORTS, dev);
512 return 0;
515 static inline int lance_reset (struct net_device *dev)
517 struct lance_private *lp = netdev_priv(dev);
518 volatile struct lance_regs *ll = lp->ll;
519 int status;
521 /* Stop the lance */
522 ll->rap = LE_CSR0;
523 ll->rdp = LE_C0_STOP;
525 load_csrs (lp);
527 lance_init_ring (dev);
528 dev->trans_start = jiffies; /* prevent tx timeout */
529 netif_start_queue(dev);
531 status = init_restart_lance (lp);
532 #ifdef DEBUG_DRIVER
533 printk(KERN_DEBUG "Lance restart=%d\n", status);
534 #endif
535 return status;
538 static void lance_tx_timeout(struct net_device *dev)
540 struct lance_private *lp = netdev_priv(dev);
541 volatile struct lance_regs *ll = lp->ll;
543 printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
544 dev->name, ll->rdp);
545 lance_reset(dev);
546 netif_wake_queue(dev);
549 static netdev_tx_t lance_start_xmit (struct sk_buff *skb,
550 struct net_device *dev)
552 struct lance_private *lp = netdev_priv(dev);
553 volatile struct lance_regs *ll = lp->ll;
554 volatile struct lance_init_block *ib = lp->init_block;
555 int entry, skblen;
556 int status = NETDEV_TX_OK;
557 unsigned long flags;
559 if (skb_padto(skb, ETH_ZLEN))
560 return NETDEV_TX_OK;
561 skblen = max_t(unsigned, skb->len, ETH_ZLEN);
563 local_irq_save(flags);
565 if (!TX_BUFFS_AVAIL){
566 local_irq_restore(flags);
567 return NETDEV_TX_LOCKED;
570 #ifdef DEBUG_DRIVER
571 /* dump the packet */
572 print_hex_dump(KERN_DEBUG, "skb->data: ", DUMP_PREFIX_NONE,
573 16, 1, skb->data, 64, true);
574 #endif
575 entry = lp->tx_new & lp->tx_ring_mod_mask;
576 ib->btx_ring [entry].length = (-skblen) | 0xf000;
577 ib->btx_ring [entry].misc = 0;
579 skb_copy_from_linear_data(skb, (void *)&ib->tx_buf [entry][0], skblen);
581 /* Now, give the packet to the lance */
582 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
583 lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
584 dev->stats.tx_bytes += skblen;
586 if (TX_BUFFS_AVAIL <= 0)
587 netif_stop_queue(dev);
589 /* Kick the lance: transmit now */
590 ll->rdp = LE_C0_INEA | LE_C0_TDMD;
591 dev_kfree_skb (skb);
593 local_irq_restore(flags);
595 return status;
598 /* taken from the depca driver */
599 static void lance_load_multicast (struct net_device *dev)
601 struct lance_private *lp = netdev_priv(dev);
602 volatile struct lance_init_block *ib = lp->init_block;
603 volatile u16 *mcast_table = (u16 *)&ib->filter;
604 struct netdev_hw_addr *ha;
605 char *addrs;
606 u32 crc;
608 /* set all multicast bits */
609 if (dev->flags & IFF_ALLMULTI){
610 ib->filter [0] = 0xffffffff;
611 ib->filter [1] = 0xffffffff;
612 return;
614 /* clear the multicast filter */
615 ib->filter [0] = 0;
616 ib->filter [1] = 0;
618 /* Add addresses */
619 netdev_for_each_mc_addr(ha, dev) {
620 addrs = ha->addr;
622 /* multicast address? */
623 if (!(*addrs & 1))
624 continue;
626 crc = ether_crc_le(6, addrs);
627 crc = crc >> 26;
628 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
632 static void lance_set_multicast (struct net_device *dev)
634 struct lance_private *lp = netdev_priv(dev);
635 volatile struct lance_init_block *ib = lp->init_block;
636 volatile struct lance_regs *ll = lp->ll;
638 if (!netif_running(dev))
639 return;
641 if (lp->tx_old != lp->tx_new) {
642 mod_timer(&lp->multicast_timer, jiffies + 4);
643 netif_wake_queue(dev);
644 return;
647 netif_stop_queue(dev);
649 ll->rap = LE_CSR0;
650 ll->rdp = LE_C0_STOP;
651 lance_init_ring (dev);
653 if (dev->flags & IFF_PROMISC) {
654 ib->mode |= LE_MO_PROM;
655 } else {
656 ib->mode &= ~LE_MO_PROM;
657 lance_load_multicast (dev);
659 load_csrs (lp);
660 init_restart_lance (lp);
661 netif_wake_queue(dev);
664 static int __devinit a2065_init_one(struct zorro_dev *z,
665 const struct zorro_device_id *ent);
666 static void __devexit a2065_remove_one(struct zorro_dev *z);
669 static struct zorro_device_id a2065_zorro_tbl[] __devinitdata = {
670 { ZORRO_PROD_CBM_A2065_1 },
671 { ZORRO_PROD_CBM_A2065_2 },
672 { ZORRO_PROD_AMERISTAR_A2065 },
673 { 0 }
675 MODULE_DEVICE_TABLE(zorro, a2065_zorro_tbl);
677 static struct zorro_driver a2065_driver = {
678 .name = "a2065",
679 .id_table = a2065_zorro_tbl,
680 .probe = a2065_init_one,
681 .remove = __devexit_p(a2065_remove_one),
684 static const struct net_device_ops lance_netdev_ops = {
685 .ndo_open = lance_open,
686 .ndo_stop = lance_close,
687 .ndo_start_xmit = lance_start_xmit,
688 .ndo_tx_timeout = lance_tx_timeout,
689 .ndo_set_multicast_list = lance_set_multicast,
690 .ndo_validate_addr = eth_validate_addr,
691 .ndo_change_mtu = eth_change_mtu,
692 .ndo_set_mac_address = eth_mac_addr,
695 static int __devinit a2065_init_one(struct zorro_dev *z,
696 const struct zorro_device_id *ent)
698 struct net_device *dev;
699 struct lance_private *priv;
700 unsigned long board, base_addr, mem_start;
701 struct resource *r1, *r2;
702 int err;
704 board = z->resource.start;
705 base_addr = board+A2065_LANCE;
706 mem_start = board+A2065_RAM;
708 r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
709 "Am7990");
710 if (!r1)
711 return -EBUSY;
712 r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
713 if (!r2) {
714 release_resource(r1);
715 return -EBUSY;
718 dev = alloc_etherdev(sizeof(struct lance_private));
719 if (dev == NULL) {
720 release_resource(r1);
721 release_resource(r2);
722 return -ENOMEM;
725 priv = netdev_priv(dev);
727 r1->name = dev->name;
728 r2->name = dev->name;
730 dev->dev_addr[0] = 0x00;
731 if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* Commodore */
732 dev->dev_addr[1] = 0x80;
733 dev->dev_addr[2] = 0x10;
734 } else { /* Ameristar */
735 dev->dev_addr[1] = 0x00;
736 dev->dev_addr[2] = 0x9f;
738 dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
739 dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
740 dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
741 dev->base_addr = ZTWO_VADDR(base_addr);
742 dev->mem_start = ZTWO_VADDR(mem_start);
743 dev->mem_end = dev->mem_start+A2065_RAM_SIZE;
745 priv->ll = (volatile struct lance_regs *)dev->base_addr;
746 priv->init_block = (struct lance_init_block *)dev->mem_start;
747 priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
748 priv->auto_select = 0;
749 priv->busmaster_regval = LE_C3_BSWP;
751 priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
752 priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
753 priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
754 priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
756 dev->netdev_ops = &lance_netdev_ops;
757 dev->watchdog_timeo = 5*HZ;
758 dev->dma = 0;
760 init_timer(&priv->multicast_timer);
761 priv->multicast_timer.data = (unsigned long) dev;
762 priv->multicast_timer.function =
763 (void (*)(unsigned long)) &lance_set_multicast;
765 err = register_netdev(dev);
766 if (err) {
767 release_resource(r1);
768 release_resource(r2);
769 free_netdev(dev);
770 return err;
772 zorro_set_drvdata(z, dev);
774 printk(KERN_INFO "%s: A2065 at 0x%08lx, Ethernet Address "
775 "%pM\n", dev->name, board, dev->dev_addr);
777 return 0;
781 static void __devexit a2065_remove_one(struct zorro_dev *z)
783 struct net_device *dev = zorro_get_drvdata(z);
785 unregister_netdev(dev);
786 release_mem_region(ZTWO_PADDR(dev->base_addr),
787 sizeof(struct lance_regs));
788 release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
789 free_netdev(dev);
792 static int __init a2065_init_module(void)
794 return zorro_register_driver(&a2065_driver);
797 static void __exit a2065_cleanup_module(void)
799 zorro_unregister_driver(&a2065_driver);
802 module_init(a2065_init_module);
803 module_exit(a2065_cleanup_module);
805 MODULE_LICENSE("GPL");