blob: d76548e7535078d9715263a08e10f430a120196f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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/slab.h>
50#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/init.h>
52#include <linux/crc32.h>
53#include <linux/zorro.h>
54#include <linux/bitops.h>
55
56#include <asm/irq.h>
57#include <asm/amigaints.h>
58#include <asm/amigahw.h>
59
60#include "a2065.h"
61
62
63 /*
64 * Transmit/Receive Ring Definitions
65 */
66
67#define LANCE_LOG_TX_BUFFERS (2)
68#define LANCE_LOG_RX_BUFFERS (4)
69
70#define TX_RING_SIZE (1<<LANCE_LOG_TX_BUFFERS)
71#define RX_RING_SIZE (1<<LANCE_LOG_RX_BUFFERS)
72
73#define TX_RING_MOD_MASK (TX_RING_SIZE-1)
74#define RX_RING_MOD_MASK (RX_RING_SIZE-1)
75
76#define PKT_BUF_SIZE (1544)
77#define RX_BUFF_SIZE PKT_BUF_SIZE
78#define TX_BUFF_SIZE PKT_BUF_SIZE
79
80
81 /*
82 * Layout of the Lance's RAM Buffer
83 */
84
85
86struct lance_init_block {
87 unsigned short mode; /* Pre-set mode (reg. 15) */
88 unsigned char phys_addr[6]; /* Physical ethernet address */
89 unsigned filter[2]; /* Multicast filter. */
90
91 /* Receive and transmit ring base, along with extra bits. */
92 unsigned short rx_ptr; /* receive descriptor addr */
93 unsigned short rx_len; /* receive len and high addr */
94 unsigned short tx_ptr; /* transmit descriptor addr */
95 unsigned short tx_len; /* transmit len and high addr */
Jeff Garzik6aa20a22006-09-13 13:24:59 -040096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */
98 struct lance_rx_desc brx_ring[RX_RING_SIZE];
99 struct lance_tx_desc btx_ring[TX_RING_SIZE];
100
101 char rx_buf [RX_RING_SIZE][RX_BUFF_SIZE];
102 char tx_buf [TX_RING_SIZE][TX_BUFF_SIZE];
103};
104
105
106 /*
107 * Private Device Data
108 */
109
110struct lance_private {
111 char *name;
112 volatile struct lance_regs *ll;
113 volatile struct lance_init_block *init_block; /* Hosts view */
114 volatile struct lance_init_block *lance_init_block; /* Lance view */
115
116 int rx_new, tx_new;
117 int rx_old, tx_old;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 int lance_log_rx_bufs, lance_log_tx_bufs;
120 int rx_ring_mod_mask, tx_ring_mod_mask;
121
122 struct net_device_stats stats;
123 int tpe; /* cable-selection is TPE */
124 int auto_select; /* cable-selection by carrier */
125 unsigned short busmaster_regval;
126
127#ifdef CONFIG_SUNLANCE
128 struct Linux_SBus_DMA *ledma; /* if set this points to ledma and arch=4m */
129 int burst_sizes; /* ledma SBus burst sizes */
130#endif
131 struct timer_list multicast_timer;
132};
133
134#define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
135 lp->tx_old+lp->tx_ring_mod_mask-lp->tx_new:\
136 lp->tx_old - lp->tx_new-1)
137
138
139#define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
140
141/* Load the CSR registers */
142static void load_csrs (struct lance_private *lp)
143{
144 volatile struct lance_regs *ll = lp->ll;
145 volatile struct lance_init_block *aib = lp->lance_init_block;
146 int leptr;
147
148 leptr = LANCE_ADDR (aib);
149
150 ll->rap = LE_CSR1;
151 ll->rdp = (leptr & 0xFFFF);
152 ll->rap = LE_CSR2;
153 ll->rdp = leptr >> 16;
154 ll->rap = LE_CSR3;
155 ll->rdp = lp->busmaster_regval;
156
157 /* Point back to csr0 */
158 ll->rap = LE_CSR0;
159}
160
161#define ZERO 0
162
163/* Setup the Lance Rx and Tx rings */
164static void lance_init_ring (struct net_device *dev)
165{
166 struct lance_private *lp = netdev_priv(dev);
167 volatile struct lance_init_block *ib = lp->init_block;
168 volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */
169 int leptr;
170 int i;
171
172 aib = lp->lance_init_block;
173
174 /* Lock out other processes while setting up hardware */
175 netif_stop_queue(dev);
176 lp->rx_new = lp->tx_new = 0;
177 lp->rx_old = lp->tx_old = 0;
178
179 ib->mode = 0;
180
181 /* Copy the ethernet address to the lance init block
182 * Note that on the sparc you need to swap the ethernet address.
183 */
184 ib->phys_addr [0] = dev->dev_addr [1];
185 ib->phys_addr [1] = dev->dev_addr [0];
186 ib->phys_addr [2] = dev->dev_addr [3];
187 ib->phys_addr [3] = dev->dev_addr [2];
188 ib->phys_addr [4] = dev->dev_addr [5];
189 ib->phys_addr [5] = dev->dev_addr [4];
190
191 if (ZERO)
192 printk(KERN_DEBUG "TX rings:\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 /* Setup the Tx ring entries */
195 for (i = 0; i <= (1<<lp->lance_log_tx_bufs); i++) {
196 leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
197 ib->btx_ring [i].tmd0 = leptr;
198 ib->btx_ring [i].tmd1_hadr = leptr >> 16;
199 ib->btx_ring [i].tmd1_bits = 0;
200 ib->btx_ring [i].length = 0xf000; /* The ones required by tmd2 */
201 ib->btx_ring [i].misc = 0;
202 if (i < 3 && ZERO)
203 printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr);
204 }
205
206 /* Setup the Rx ring entries */
207 if (ZERO)
208 printk(KERN_DEBUG "RX rings:\n");
209 for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) {
210 leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
211
212 ib->brx_ring [i].rmd0 = leptr;
213 ib->brx_ring [i].rmd1_hadr = leptr >> 16;
214 ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
215 ib->brx_ring [i].length = -RX_BUFF_SIZE | 0xf000;
216 ib->brx_ring [i].mblength = 0;
217 if (i < 3 && ZERO)
218 printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr);
219 }
220
221 /* Setup the initialization block */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 /* Setup rx descriptor pointer */
224 leptr = LANCE_ADDR(&aib->brx_ring);
225 ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
226 ib->rx_ptr = leptr;
227 if (ZERO)
228 printk(KERN_DEBUG "RX ptr: %8.8x\n", leptr);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 /* Setup tx descriptor pointer */
231 leptr = LANCE_ADDR(&aib->btx_ring);
232 ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
233 ib->tx_ptr = leptr;
234 if (ZERO)
235 printk(KERN_DEBUG "TX ptr: %8.8x\n", leptr);
236
237 /* Clear the multicast filter */
238 ib->filter [0] = 0;
239 ib->filter [1] = 0;
240}
241
242static int init_restart_lance (struct lance_private *lp)
243{
244 volatile struct lance_regs *ll = lp->ll;
245 int i;
246
247 ll->rap = LE_CSR0;
248 ll->rdp = LE_C0_INIT;
249
250 /* Wait for the lance to complete initialization */
251 for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++)
252 barrier();
253 if ((i == 100) || (ll->rdp & LE_C0_ERR)) {
254 printk(KERN_ERR "LANCE unopened after %d ticks, csr0=%4.4x.\n",
255 i, ll->rdp);
256 return -EIO;
257 }
258
259 /* Clear IDON by writing a "1", enable interrupts and start lance */
260 ll->rdp = LE_C0_IDON;
261 ll->rdp = LE_C0_INEA | LE_C0_STRT;
262
263 return 0;
264}
265
266static int lance_rx (struct net_device *dev)
267{
268 struct lance_private *lp = netdev_priv(dev);
269 volatile struct lance_init_block *ib = lp->init_block;
270 volatile struct lance_regs *ll = lp->ll;
271 volatile struct lance_rx_desc *rd;
272 unsigned char bits;
273 int len = 0; /* XXX shut up gcc warnings */
274 struct sk_buff *skb = 0; /* XXX shut up gcc warnings */
275
276#ifdef TEST_HITS
277 int i;
278 printk(KERN_DEBUG "[");
279 for (i = 0; i < RX_RING_SIZE; i++) {
280 if (i == lp->rx_new)
281 printk ("%s",
282 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X");
283 else
284 printk ("%s",
285 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1");
286 }
287 printk ("]\n");
288#endif
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 ll->rdp = LE_C0_RINT|LE_C0_INEA;
291 for (rd = &ib->brx_ring [lp->rx_new];
292 !((bits = rd->rmd1_bits) & LE_R1_OWN);
293 rd = &ib->brx_ring [lp->rx_new]) {
294
295 /* We got an incomplete frame? */
296 if ((bits & LE_R1_POK) != LE_R1_POK) {
297 lp->stats.rx_over_errors++;
298 lp->stats.rx_errors++;
299 continue;
300 } else if (bits & LE_R1_ERR) {
301 /* Count only the end frame as a rx error,
302 * not the beginning
303 */
304 if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++;
305 if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++;
306 if (bits & LE_R1_OFL) lp->stats.rx_over_errors++;
307 if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++;
308 if (bits & LE_R1_EOP) lp->stats.rx_errors++;
309 } else {
310 len = (rd->mblength & 0xfff) - 4;
311 skb = dev_alloc_skb (len+2);
312
313 if (skb == 0) {
314 printk(KERN_WARNING "%s: Memory squeeze, "
315 "deferring packet.\n", dev->name);
316 lp->stats.rx_dropped++;
317 rd->mblength = 0;
318 rd->rmd1_bits = LE_R1_OWN;
319 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
320 return 0;
321 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 skb->dev = dev;
324 skb_reserve (skb, 2); /* 16 byte align */
325 skb_put (skb, len); /* make room */
326 eth_copy_and_sum(skb,
327 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
328 len, 0);
329 skb->protocol = eth_type_trans (skb, dev);
330 netif_rx (skb);
331 dev->last_rx = jiffies;
332 lp->stats.rx_packets++;
333 lp->stats.rx_bytes += len;
334 }
335
336 /* Return the packet to the pool */
337 rd->mblength = 0;
338 rd->rmd1_bits = LE_R1_OWN;
339 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
340 }
341 return 0;
342}
343
344static int lance_tx (struct net_device *dev)
345{
346 struct lance_private *lp = netdev_priv(dev);
347 volatile struct lance_init_block *ib = lp->init_block;
348 volatile struct lance_regs *ll = lp->ll;
349 volatile struct lance_tx_desc *td;
350 int i, j;
351 int status;
352
353 /* csr0 is 2f3 */
354 ll->rdp = LE_C0_TINT | LE_C0_INEA;
355 /* csr0 is 73 */
356
357 j = lp->tx_old;
358 for (i = j; i != lp->tx_new; i = j) {
359 td = &ib->btx_ring [i];
360
361 /* If we hit a packet not owned by us, stop */
362 if (td->tmd1_bits & LE_T1_OWN)
363 break;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 if (td->tmd1_bits & LE_T1_ERR) {
366 status = td->misc;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 lp->stats.tx_errors++;
369 if (status & LE_T3_RTY) lp->stats.tx_aborted_errors++;
370 if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
371
372 if (status & LE_T3_CLOS) {
373 lp->stats.tx_carrier_errors++;
374 if (lp->auto_select) {
375 lp->tpe = 1 - lp->tpe;
376 printk(KERN_ERR "%s: Carrier Lost, "
377 "trying %s\n", dev->name,
378 lp->tpe?"TPE":"AUI");
379 /* Stop the lance */
380 ll->rap = LE_CSR0;
381 ll->rdp = LE_C0_STOP;
382 lance_init_ring (dev);
383 load_csrs (lp);
384 init_restart_lance (lp);
385 return 0;
386 }
387 }
388
389 /* buffer errors and underflows turn off the transmitter */
390 /* Restart the adapter */
391 if (status & (LE_T3_BUF|LE_T3_UFL)) {
392 lp->stats.tx_fifo_errors++;
393
394 printk(KERN_ERR "%s: Tx: ERR_BUF|ERR_UFL, "
395 "restarting\n", dev->name);
396 /* Stop the lance */
397 ll->rap = LE_CSR0;
398 ll->rdp = LE_C0_STOP;
399 lance_init_ring (dev);
400 load_csrs (lp);
401 init_restart_lance (lp);
402 return 0;
403 }
404 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
405 /*
406 * So we don't count the packet more than once.
407 */
408 td->tmd1_bits &= ~(LE_T1_POK);
409
410 /* One collision before packet was sent. */
411 if (td->tmd1_bits & LE_T1_EONE)
412 lp->stats.collisions++;
413
414 /* More than one collision, be optimistic. */
415 if (td->tmd1_bits & LE_T1_EMORE)
416 lp->stats.collisions += 2;
417
418 lp->stats.tx_packets++;
419 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 j = (j + 1) & lp->tx_ring_mod_mask;
422 }
423 lp->tx_old = j;
424 ll->rdp = LE_C0_TINT | LE_C0_INEA;
425 return 0;
426}
427
David Howells7d12e782006-10-05 14:55:46 +0100428static irqreturn_t lance_interrupt (int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
430 struct net_device *dev;
431 struct lance_private *lp;
432 volatile struct lance_regs *ll;
433 int csr0;
434
435 dev = (struct net_device *) dev_id;
436
437 lp = netdev_priv(dev);
438 ll = lp->ll;
439
440 ll->rap = LE_CSR0; /* LANCE Controller Status */
441 csr0 = ll->rdp;
442
443 if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */
444 return IRQ_NONE; /* been generated by the Lance. */
445
446 /* Acknowledge all the interrupt sources ASAP */
447 ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|
448 LE_C0_INIT);
449
450 if ((csr0 & LE_C0_ERR)) {
451 /* Clear the error condition */
452 ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
453 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 if (csr0 & LE_C0_RINT)
456 lance_rx (dev);
457
458 if (csr0 & LE_C0_TINT)
459 lance_tx (dev);
460
461 /* Log misc errors. */
462 if (csr0 & LE_C0_BABL)
463 lp->stats.tx_errors++; /* Tx babble. */
464 if (csr0 & LE_C0_MISS)
465 lp->stats.rx_errors++; /* Missed a Rx frame. */
466 if (csr0 & LE_C0_MERR) {
467 printk(KERN_ERR "%s: Bus master arbitration failure, status "
468 "%4.4x.\n", dev->name, csr0);
469 /* Restart the chip. */
470 ll->rdp = LE_C0_STRT;
471 }
472
473 if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
474 netif_wake_queue(dev);
475
476 ll->rap = LE_CSR0;
477 ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
478 LE_C0_IDON|LE_C0_INEA;
479 return IRQ_HANDLED;
480}
481
482struct net_device *last_dev = 0;
483
484static int lance_open (struct net_device *dev)
485{
486 struct lance_private *lp = netdev_priv(dev);
487 volatile struct lance_regs *ll = lp->ll;
488 int ret;
489
490 last_dev = dev;
491
492 /* Stop the Lance */
493 ll->rap = LE_CSR0;
494 ll->rdp = LE_C0_STOP;
495
496 /* Install the Interrupt handler */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700497 ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, IRQF_SHARED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 dev->name, dev);
499 if (ret) return ret;
500
501 load_csrs (lp);
502 lance_init_ring (dev);
503
504 netif_start_queue(dev);
505
506 return init_restart_lance (lp);
507}
508
509static int lance_close (struct net_device *dev)
510{
511 struct lance_private *lp = netdev_priv(dev);
512 volatile struct lance_regs *ll = lp->ll;
513
514 netif_stop_queue(dev);
515 del_timer_sync(&lp->multicast_timer);
516
517 /* Stop the card */
518 ll->rap = LE_CSR0;
519 ll->rdp = LE_C0_STOP;
520
521 free_irq(IRQ_AMIGA_PORTS, dev);
522 return 0;
523}
524
525static inline int lance_reset (struct net_device *dev)
526{
527 struct lance_private *lp = netdev_priv(dev);
528 volatile struct lance_regs *ll = lp->ll;
529 int status;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 /* Stop the lance */
532 ll->rap = LE_CSR0;
533 ll->rdp = LE_C0_STOP;
534
535 load_csrs (lp);
536
537 lance_init_ring (dev);
538 dev->trans_start = jiffies;
539 netif_start_queue(dev);
540
541 status = init_restart_lance (lp);
542#ifdef DEBUG_DRIVER
543 printk(KERN_DEBUG "Lance restart=%d\n", status);
544#endif
545 return status;
546}
547
548static void lance_tx_timeout(struct net_device *dev)
549{
550 struct lance_private *lp = netdev_priv(dev);
551 volatile struct lance_regs *ll = lp->ll;
552
553 printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
554 dev->name, ll->rdp);
555 lance_reset(dev);
556 netif_wake_queue(dev);
557}
558
559static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
560{
561 struct lance_private *lp = netdev_priv(dev);
562 volatile struct lance_regs *ll = lp->ll;
563 volatile struct lance_init_block *ib = lp->init_block;
564 int entry, skblen, len;
565 int status = 0;
566 static int outs;
567 unsigned long flags;
568
569 skblen = skb->len;
570 len = skblen;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 if (len < ETH_ZLEN) {
573 len = ETH_ZLEN;
Herbert Xu5b057c62006-06-23 02:06:41 -0700574 if (skb_padto(skb, ETH_ZLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 return 0;
576 }
577
578 local_irq_save(flags);
579
580 if (!TX_BUFFS_AVAIL){
581 local_irq_restore(flags);
582 return -1;
583 }
584
585#ifdef DEBUG_DRIVER
586 /* dump the packet */
587 {
588 int i;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 for (i = 0; i < 64; i++) {
591 if ((i % 16) == 0)
592 printk("\n" KERN_DEBUG);
593 printk ("%2.2x ", skb->data [i]);
594 }
595 printk("\n");
596 }
597#endif
598 entry = lp->tx_new & lp->tx_ring_mod_mask;
599 ib->btx_ring [entry].length = (-len) | 0xf000;
600 ib->btx_ring [entry].misc = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
603
604 /* Clear the slack of the packet, do I need this? */
605 if (len != skblen)
606 memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 /* Now, give the packet to the lance */
609 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
610 lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
611
612 outs++;
613
614 if (TX_BUFFS_AVAIL <= 0)
615 netif_stop_queue(dev);
616
617 /* Kick the lance: transmit now */
618 ll->rdp = LE_C0_INEA | LE_C0_TDMD;
619 dev->trans_start = jiffies;
620 dev_kfree_skb (skb);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 local_irq_restore(flags);
623
624 return status;
625}
626
627static struct net_device_stats *lance_get_stats (struct net_device *dev)
628{
629 struct lance_private *lp = netdev_priv(dev);
630
631 return &lp->stats;
632}
633
634/* taken from the depca driver */
635static void lance_load_multicast (struct net_device *dev)
636{
637 struct lance_private *lp = netdev_priv(dev);
638 volatile struct lance_init_block *ib = lp->init_block;
639 volatile u16 *mcast_table = (u16 *)&ib->filter;
640 struct dev_mc_list *dmi=dev->mc_list;
641 char *addrs;
642 int i;
643 u32 crc;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 /* set all multicast bits */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400646 if (dev->flags & IFF_ALLMULTI){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 ib->filter [0] = 0xffffffff;
648 ib->filter [1] = 0xffffffff;
649 return;
650 }
651 /* clear the multicast filter */
652 ib->filter [0] = 0;
653 ib->filter [1] = 0;
654
655 /* Add addresses */
656 for (i = 0; i < dev->mc_count; i++){
657 addrs = dmi->dmi_addr;
658 dmi = dmi->next;
659
660 /* multicast address? */
661 if (!(*addrs & 1))
662 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 crc = ether_crc_le(6, addrs);
665 crc = crc >> 26;
666 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
667 }
668 return;
669}
670
671static void lance_set_multicast (struct net_device *dev)
672{
673 struct lance_private *lp = netdev_priv(dev);
674 volatile struct lance_init_block *ib = lp->init_block;
675 volatile struct lance_regs *ll = lp->ll;
676
677 if (!netif_running(dev))
678 return;
679
680 if (lp->tx_old != lp->tx_new) {
681 mod_timer(&lp->multicast_timer, jiffies + 4);
682 netif_wake_queue(dev);
683 return;
684 }
685
686 netif_stop_queue(dev);
687
688 ll->rap = LE_CSR0;
689 ll->rdp = LE_C0_STOP;
690 lance_init_ring (dev);
691
692 if (dev->flags & IFF_PROMISC) {
693 ib->mode |= LE_MO_PROM;
694 } else {
695 ib->mode &= ~LE_MO_PROM;
696 lance_load_multicast (dev);
697 }
698 load_csrs (lp);
699 init_restart_lance (lp);
700 netif_wake_queue(dev);
701}
702
703static int __devinit a2065_init_one(struct zorro_dev *z,
704 const struct zorro_device_id *ent);
705static void __devexit a2065_remove_one(struct zorro_dev *z);
706
707
708static struct zorro_device_id a2065_zorro_tbl[] __devinitdata = {
709 { ZORRO_PROD_CBM_A2065_1 },
710 { ZORRO_PROD_CBM_A2065_2 },
711 { ZORRO_PROD_AMERISTAR_A2065 },
712 { 0 }
713};
714
715static struct zorro_driver a2065_driver = {
716 .name = "a2065",
717 .id_table = a2065_zorro_tbl,
718 .probe = a2065_init_one,
719 .remove = __devexit_p(a2065_remove_one),
720};
721
722static int __devinit a2065_init_one(struct zorro_dev *z,
723 const struct zorro_device_id *ent)
724{
725 struct net_device *dev;
726 struct lance_private *priv;
727 unsigned long board, base_addr, mem_start;
728 struct resource *r1, *r2;
729 int err;
730
731 board = z->resource.start;
732 base_addr = board+A2065_LANCE;
733 mem_start = board+A2065_RAM;
734
735 r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
736 "Am7990");
737 if (!r1)
738 return -EBUSY;
739 r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
740 if (!r2) {
741 release_resource(r1);
742 return -EBUSY;
743 }
744
745 dev = alloc_etherdev(sizeof(struct lance_private));
746 if (dev == NULL) {
747 release_resource(r1);
748 release_resource(r2);
749 return -ENOMEM;
750 }
751
752 SET_MODULE_OWNER(dev);
753 priv = netdev_priv(dev);
754
755 r1->name = dev->name;
756 r2->name = dev->name;
757
758 dev->dev_addr[0] = 0x00;
759 if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* Commodore */
760 dev->dev_addr[1] = 0x80;
761 dev->dev_addr[2] = 0x10;
762 } else { /* Ameristar */
763 dev->dev_addr[1] = 0x00;
764 dev->dev_addr[2] = 0x9f;
765 }
766 dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
767 dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
768 dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
769 dev->base_addr = ZTWO_VADDR(base_addr);
770 dev->mem_start = ZTWO_VADDR(mem_start);
771 dev->mem_end = dev->mem_start+A2065_RAM_SIZE;
772
773 priv->ll = (volatile struct lance_regs *)dev->base_addr;
774 priv->init_block = (struct lance_init_block *)dev->mem_start;
775 priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
776 priv->auto_select = 0;
777 priv->busmaster_regval = LE_C3_BSWP;
778
779 priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
780 priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
781 priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
782 priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
783
784 dev->open = &lance_open;
785 dev->stop = &lance_close;
786 dev->hard_start_xmit = &lance_start_xmit;
787 dev->tx_timeout = &lance_tx_timeout;
788 dev->watchdog_timeo = 5*HZ;
789 dev->get_stats = &lance_get_stats;
790 dev->set_multicast_list = &lance_set_multicast;
791 dev->dma = 0;
792
793 init_timer(&priv->multicast_timer);
794 priv->multicast_timer.data = (unsigned long) dev;
795 priv->multicast_timer.function =
796 (void (*)(unsigned long)) &lance_set_multicast;
797
798 err = register_netdev(dev);
799 if (err) {
800 release_resource(r1);
801 release_resource(r2);
802 free_netdev(dev);
803 return err;
804 }
805 zorro_set_drvdata(z, dev);
806
807 printk(KERN_INFO "%s: A2065 at 0x%08lx, Ethernet Address "
808 "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board,
809 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
810 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
811
812 return 0;
813}
814
815
816static void __devexit a2065_remove_one(struct zorro_dev *z)
817{
818 struct net_device *dev = zorro_get_drvdata(z);
819
820 unregister_netdev(dev);
821 release_mem_region(ZTWO_PADDR(dev->base_addr),
822 sizeof(struct lance_regs));
823 release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
824 free_netdev(dev);
825}
826
827static int __init a2065_init_module(void)
828{
Bjorn Helgaas33d86752006-03-25 03:07:20 -0800829 return zorro_register_driver(&a2065_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830}
831
832static void __exit a2065_cleanup_module(void)
833{
834 zorro_unregister_driver(&a2065_driver);
835}
836
837module_init(a2065_init_module);
838module_exit(a2065_cleanup_module);
839
840MODULE_LICENSE("GPL");