drivers/net: Remove casts of void *
[deliverable/linux.git] / drivers / net / a2065.c
1 /*
2 * Amiga Linux/68k A2065 Ethernet Driver
3 *
4 * (C) Copyright 1995-2003 by Geert Uytterhoeven <geert@linux-m68k.org>
5 *
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)
10 *
11 * ----------------------------------------------------------------------------
12 *
13 * This program is based on
14 *
15 * ariadne.?: Amiga Linux/68k Ariadne Ethernet Driver
16 * (C) Copyright 1995 by Geert Uytterhoeven,
17 * Peter De Schrijver
18 *
19 * lance.c: An AMD LANCE ethernet driver for linux.
20 * Written 1993-94 by Donald Becker.
21 *
22 * Am79C960: PCnet(tm)-ISA Single-Chip Ethernet Controller
23 * Advanced Micro Devices
24 * Publication #16907, Rev. B, Amendment/0, May 1994
25 *
26 * ----------------------------------------------------------------------------
27 *
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.
31 *
32 * ----------------------------------------------------------------------------
33 *
34 * The A2065 is a Zorro-II board made by Commodore/Ameristar. It contains:
35 *
36 * - an Am7990 Local Area Network Controller for Ethernet (LANCE) with
37 * both 10BASE-2 (thin coax) and AUI (DB-15) connectors
38 */
39
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>
54
55 #include <asm/irq.h>
56 #include <asm/amigaints.h>
57 #include <asm/amigahw.h>
58
59 #include "a2065.h"
60
61
62 /*
63 * Transmit/Receive Ring Definitions
64 */
65
66 #define LANCE_LOG_TX_BUFFERS (2)
67 #define LANCE_LOG_RX_BUFFERS (4)
68
69 #define TX_RING_SIZE (1<<LANCE_LOG_TX_BUFFERS)
70 #define RX_RING_SIZE (1<<LANCE_LOG_RX_BUFFERS)
71
72 #define TX_RING_MOD_MASK (TX_RING_SIZE-1)
73 #define RX_RING_MOD_MASK (RX_RING_SIZE-1)
74
75 #define PKT_BUF_SIZE (1544)
76 #define RX_BUFF_SIZE PKT_BUF_SIZE
77 #define TX_BUFF_SIZE PKT_BUF_SIZE
78
79
80 /*
81 * Layout of the Lance's RAM Buffer
82 */
83
84
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. */
89
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 */
95
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];
99
100 char rx_buf [RX_RING_SIZE][RX_BUFF_SIZE];
101 char tx_buf [TX_RING_SIZE][TX_BUFF_SIZE];
102 };
103
104
105 /*
106 * Private Device Data
107 */
108
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 */
114
115 int rx_new, tx_new;
116 int rx_old, tx_old;
117
118 int lance_log_rx_bufs, lance_log_tx_bufs;
119 int rx_ring_mod_mask, tx_ring_mod_mask;
120
121 int tpe; /* cable-selection is TPE */
122 int auto_select; /* cable-selection by carrier */
123 unsigned short busmaster_regval;
124
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;
130 };
131
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)
135
136
137 #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
138
139 /* Load the CSR registers */
140 static void load_csrs (struct lance_private *lp)
141 {
142 volatile struct lance_regs *ll = lp->ll;
143 volatile struct lance_init_block *aib = lp->lance_init_block;
144 int leptr;
145
146 leptr = LANCE_ADDR (aib);
147
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;
154
155 /* Point back to csr0 */
156 ll->rap = LE_CSR0;
157 }
158
159 #define ZERO 0
160
161 /* Setup the Lance Rx and Tx rings */
162 static void lance_init_ring (struct net_device *dev)
163 {
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;
169
170 aib = lp->lance_init_block;
171
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;
176
177 ib->mode = 0;
178
179 /* Copy the ethernet address to the lance init block
180 * Note that on the sparc you need to swap the ethernet address.
181 */
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];
188
189 if (ZERO)
190 printk(KERN_DEBUG "TX rings:\n");
191
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);
202 }
203
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]);
209
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);
217 }
218
219 /* Setup the initialization block */
220
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);
227
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);
234
235 /* Clear the multicast filter */
236 ib->filter [0] = 0;
237 ib->filter [1] = 0;
238 }
239
240 static int init_restart_lance (struct lance_private *lp)
241 {
242 volatile struct lance_regs *ll = lp->ll;
243 int i;
244
245 ll->rap = LE_CSR0;
246 ll->rdp = LE_C0_INIT;
247
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;
255 }
256
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;
260
261 return 0;
262 }
263
264 static int lance_rx (struct net_device *dev)
265 {
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;
271
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");
282 }
283 printk ("]\n");
284 #endif
285
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]) {
290
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
299 */
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);
308
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;
317 }
318
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;
328 }
329
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;
334 }
335 return 0;
336 }
337
338 static int lance_tx (struct net_device *dev)
339 {
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;
346
347 /* csr0 is 2f3 */
348 ll->rdp = LE_C0_TINT | LE_C0_INEA;
349 /* csr0 is 73 */
350
351 j = lp->tx_old;
352 for (i = j; i != lp->tx_new; i = j) {
353 td = &ib->btx_ring [i];
354
355 /* If we hit a packet not owned by us, stop */
356 if (td->tmd1_bits & LE_T1_OWN)
357 break;
358
359 if (td->tmd1_bits & LE_T1_ERR) {
360 status = td->misc;
361
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++;
365
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;
380 }
381 }
382
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++;
387
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;
397 }
398 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
399 /*
400 * So we don't count the packet more than once.
401 */
402 td->tmd1_bits &= ~(LE_T1_POK);
403
404 /* One collision before packet was sent. */
405 if (td->tmd1_bits & LE_T1_EONE)
406 dev->stats.collisions++;
407
408 /* More than one collision, be optimistic. */
409 if (td->tmd1_bits & LE_T1_EMORE)
410 dev->stats.collisions += 2;
411
412 dev->stats.tx_packets++;
413 }
414
415 j = (j + 1) & lp->tx_ring_mod_mask;
416 }
417 lp->tx_old = j;
418 ll->rdp = LE_C0_TINT | LE_C0_INEA;
419 return 0;
420 }
421
422 static irqreturn_t lance_interrupt (int irq, void *dev_id)
423 {
424 struct net_device *dev = dev_id;
425 struct lance_private *lp = netdev_priv(dev);
426 volatile struct lance_regs *ll = lp->ll;
427 int csr0;
428
429 ll->rap = LE_CSR0; /* LANCE Controller Status */
430 csr0 = ll->rdp;
431
432 if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */
433 return IRQ_NONE; /* been generated by the Lance. */
434
435 /* Acknowledge all the interrupt sources ASAP */
436 ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|
437 LE_C0_INIT);
438
439 if ((csr0 & LE_C0_ERR)) {
440 /* Clear the error condition */
441 ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
442 }
443
444 if (csr0 & LE_C0_RINT)
445 lance_rx (dev);
446
447 if (csr0 & LE_C0_TINT)
448 lance_tx (dev);
449
450 /* Log misc errors. */
451 if (csr0 & LE_C0_BABL)
452 dev->stats.tx_errors++; /* Tx babble. */
453 if (csr0 & LE_C0_MISS)
454 dev->stats.rx_errors++; /* Missed a Rx frame. */
455 if (csr0 & LE_C0_MERR) {
456 printk(KERN_ERR "%s: Bus master arbitration failure, status "
457 "%4.4x.\n", dev->name, csr0);
458 /* Restart the chip. */
459 ll->rdp = LE_C0_STRT;
460 }
461
462 if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
463 netif_wake_queue(dev);
464
465 ll->rap = LE_CSR0;
466 ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
467 LE_C0_IDON|LE_C0_INEA;
468 return IRQ_HANDLED;
469 }
470
471 static int lance_open (struct net_device *dev)
472 {
473 struct lance_private *lp = netdev_priv(dev);
474 volatile struct lance_regs *ll = lp->ll;
475 int ret;
476
477 /* Stop the Lance */
478 ll->rap = LE_CSR0;
479 ll->rdp = LE_C0_STOP;
480
481 /* Install the Interrupt handler */
482 ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, IRQF_SHARED,
483 dev->name, dev);
484 if (ret) return ret;
485
486 load_csrs (lp);
487 lance_init_ring (dev);
488
489 netif_start_queue(dev);
490
491 return init_restart_lance (lp);
492 }
493
494 static int lance_close (struct net_device *dev)
495 {
496 struct lance_private *lp = netdev_priv(dev);
497 volatile struct lance_regs *ll = lp->ll;
498
499 netif_stop_queue(dev);
500 del_timer_sync(&lp->multicast_timer);
501
502 /* Stop the card */
503 ll->rap = LE_CSR0;
504 ll->rdp = LE_C0_STOP;
505
506 free_irq(IRQ_AMIGA_PORTS, dev);
507 return 0;
508 }
509
510 static inline int lance_reset (struct net_device *dev)
511 {
512 struct lance_private *lp = netdev_priv(dev);
513 volatile struct lance_regs *ll = lp->ll;
514 int status;
515
516 /* Stop the lance */
517 ll->rap = LE_CSR0;
518 ll->rdp = LE_C0_STOP;
519
520 load_csrs (lp);
521
522 lance_init_ring (dev);
523 dev->trans_start = jiffies; /* prevent tx timeout */
524 netif_start_queue(dev);
525
526 status = init_restart_lance (lp);
527 #ifdef DEBUG_DRIVER
528 printk(KERN_DEBUG "Lance restart=%d\n", status);
529 #endif
530 return status;
531 }
532
533 static void lance_tx_timeout(struct net_device *dev)
534 {
535 struct lance_private *lp = netdev_priv(dev);
536 volatile struct lance_regs *ll = lp->ll;
537
538 printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
539 dev->name, ll->rdp);
540 lance_reset(dev);
541 netif_wake_queue(dev);
542 }
543
544 static netdev_tx_t lance_start_xmit (struct sk_buff *skb,
545 struct net_device *dev)
546 {
547 struct lance_private *lp = netdev_priv(dev);
548 volatile struct lance_regs *ll = lp->ll;
549 volatile struct lance_init_block *ib = lp->init_block;
550 int entry, skblen;
551 int status = NETDEV_TX_OK;
552 unsigned long flags;
553
554 if (skb_padto(skb, ETH_ZLEN))
555 return NETDEV_TX_OK;
556 skblen = max_t(unsigned, skb->len, ETH_ZLEN);
557
558 local_irq_save(flags);
559
560 if (!TX_BUFFS_AVAIL){
561 local_irq_restore(flags);
562 return NETDEV_TX_LOCKED;
563 }
564
565 #ifdef DEBUG_DRIVER
566 /* dump the packet */
567 print_hex_dump(KERN_DEBUG, "skb->data: ", DUMP_PREFIX_NONE,
568 16, 1, skb->data, 64, true);
569 #endif
570 entry = lp->tx_new & lp->tx_ring_mod_mask;
571 ib->btx_ring [entry].length = (-skblen) | 0xf000;
572 ib->btx_ring [entry].misc = 0;
573
574 skb_copy_from_linear_data(skb, (void *)&ib->tx_buf [entry][0], skblen);
575
576 /* Now, give the packet to the lance */
577 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
578 lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
579 dev->stats.tx_bytes += skblen;
580
581 if (TX_BUFFS_AVAIL <= 0)
582 netif_stop_queue(dev);
583
584 /* Kick the lance: transmit now */
585 ll->rdp = LE_C0_INEA | LE_C0_TDMD;
586 dev_kfree_skb (skb);
587
588 local_irq_restore(flags);
589
590 return status;
591 }
592
593 /* taken from the depca driver */
594 static void lance_load_multicast (struct net_device *dev)
595 {
596 struct lance_private *lp = netdev_priv(dev);
597 volatile struct lance_init_block *ib = lp->init_block;
598 volatile u16 *mcast_table = (u16 *)&ib->filter;
599 struct netdev_hw_addr *ha;
600 char *addrs;
601 u32 crc;
602
603 /* set all multicast bits */
604 if (dev->flags & IFF_ALLMULTI){
605 ib->filter [0] = 0xffffffff;
606 ib->filter [1] = 0xffffffff;
607 return;
608 }
609 /* clear the multicast filter */
610 ib->filter [0] = 0;
611 ib->filter [1] = 0;
612
613 /* Add addresses */
614 netdev_for_each_mc_addr(ha, dev) {
615 addrs = ha->addr;
616
617 /* multicast address? */
618 if (!(*addrs & 1))
619 continue;
620
621 crc = ether_crc_le(6, addrs);
622 crc = crc >> 26;
623 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
624 }
625 }
626
627 static void lance_set_multicast (struct net_device *dev)
628 {
629 struct lance_private *lp = netdev_priv(dev);
630 volatile struct lance_init_block *ib = lp->init_block;
631 volatile struct lance_regs *ll = lp->ll;
632
633 if (!netif_running(dev))
634 return;
635
636 if (lp->tx_old != lp->tx_new) {
637 mod_timer(&lp->multicast_timer, jiffies + 4);
638 netif_wake_queue(dev);
639 return;
640 }
641
642 netif_stop_queue(dev);
643
644 ll->rap = LE_CSR0;
645 ll->rdp = LE_C0_STOP;
646 lance_init_ring (dev);
647
648 if (dev->flags & IFF_PROMISC) {
649 ib->mode |= LE_MO_PROM;
650 } else {
651 ib->mode &= ~LE_MO_PROM;
652 lance_load_multicast (dev);
653 }
654 load_csrs (lp);
655 init_restart_lance (lp);
656 netif_wake_queue(dev);
657 }
658
659 static int __devinit a2065_init_one(struct zorro_dev *z,
660 const struct zorro_device_id *ent);
661 static void __devexit a2065_remove_one(struct zorro_dev *z);
662
663
664 static struct zorro_device_id a2065_zorro_tbl[] __devinitdata = {
665 { ZORRO_PROD_CBM_A2065_1 },
666 { ZORRO_PROD_CBM_A2065_2 },
667 { ZORRO_PROD_AMERISTAR_A2065 },
668 { 0 }
669 };
670 MODULE_DEVICE_TABLE(zorro, a2065_zorro_tbl);
671
672 static struct zorro_driver a2065_driver = {
673 .name = "a2065",
674 .id_table = a2065_zorro_tbl,
675 .probe = a2065_init_one,
676 .remove = __devexit_p(a2065_remove_one),
677 };
678
679 static const struct net_device_ops lance_netdev_ops = {
680 .ndo_open = lance_open,
681 .ndo_stop = lance_close,
682 .ndo_start_xmit = lance_start_xmit,
683 .ndo_tx_timeout = lance_tx_timeout,
684 .ndo_set_multicast_list = lance_set_multicast,
685 .ndo_validate_addr = eth_validate_addr,
686 .ndo_change_mtu = eth_change_mtu,
687 .ndo_set_mac_address = eth_mac_addr,
688 };
689
690 static int __devinit a2065_init_one(struct zorro_dev *z,
691 const struct zorro_device_id *ent)
692 {
693 struct net_device *dev;
694 struct lance_private *priv;
695 unsigned long board, base_addr, mem_start;
696 struct resource *r1, *r2;
697 int err;
698
699 board = z->resource.start;
700 base_addr = board+A2065_LANCE;
701 mem_start = board+A2065_RAM;
702
703 r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
704 "Am7990");
705 if (!r1)
706 return -EBUSY;
707 r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
708 if (!r2) {
709 release_mem_region(base_addr, sizeof(struct lance_regs));
710 return -EBUSY;
711 }
712
713 dev = alloc_etherdev(sizeof(struct lance_private));
714 if (dev == NULL) {
715 release_mem_region(base_addr, sizeof(struct lance_regs));
716 release_mem_region(mem_start, A2065_RAM_SIZE);
717 return -ENOMEM;
718 }
719
720 priv = netdev_priv(dev);
721
722 r1->name = dev->name;
723 r2->name = dev->name;
724
725 dev->dev_addr[0] = 0x00;
726 if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* Commodore */
727 dev->dev_addr[1] = 0x80;
728 dev->dev_addr[2] = 0x10;
729 } else { /* Ameristar */
730 dev->dev_addr[1] = 0x00;
731 dev->dev_addr[2] = 0x9f;
732 }
733 dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
734 dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
735 dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
736 dev->base_addr = ZTWO_VADDR(base_addr);
737 dev->mem_start = ZTWO_VADDR(mem_start);
738 dev->mem_end = dev->mem_start+A2065_RAM_SIZE;
739
740 priv->ll = (volatile struct lance_regs *)dev->base_addr;
741 priv->init_block = (struct lance_init_block *)dev->mem_start;
742 priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
743 priv->auto_select = 0;
744 priv->busmaster_regval = LE_C3_BSWP;
745
746 priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
747 priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
748 priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
749 priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
750
751 dev->netdev_ops = &lance_netdev_ops;
752 dev->watchdog_timeo = 5*HZ;
753 dev->dma = 0;
754
755 init_timer(&priv->multicast_timer);
756 priv->multicast_timer.data = (unsigned long) dev;
757 priv->multicast_timer.function =
758 (void (*)(unsigned long)) &lance_set_multicast;
759
760 err = register_netdev(dev);
761 if (err) {
762 release_mem_region(base_addr, sizeof(struct lance_regs));
763 release_mem_region(mem_start, A2065_RAM_SIZE);
764 free_netdev(dev);
765 return err;
766 }
767 zorro_set_drvdata(z, dev);
768
769 printk(KERN_INFO "%s: A2065 at 0x%08lx, Ethernet Address "
770 "%pM\n", dev->name, board, dev->dev_addr);
771
772 return 0;
773 }
774
775
776 static void __devexit a2065_remove_one(struct zorro_dev *z)
777 {
778 struct net_device *dev = zorro_get_drvdata(z);
779
780 unregister_netdev(dev);
781 release_mem_region(ZTWO_PADDR(dev->base_addr),
782 sizeof(struct lance_regs));
783 release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
784 free_netdev(dev);
785 }
786
787 static int __init a2065_init_module(void)
788 {
789 return zorro_register_driver(&a2065_driver);
790 }
791
792 static void __exit a2065_cleanup_module(void)
793 {
794 zorro_unregister_driver(&a2065_driver);
795 }
796
797 module_init(a2065_init_module);
798 module_exit(a2065_cleanup_module);
799
800 MODULE_LICENSE("GPL");
This page took 0.059418 seconds and 6 git commands to generate.