blob: 18f7f815f66e2166cf4d12af0927cc85a7ec6cd3 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 int tpe; /* cable-selection is TPE */
123 int auto_select; /* cable-selection by carrier */
124 unsigned short busmaster_regval;
125
126#ifdef CONFIG_SUNLANCE
127 struct Linux_SBus_DMA *ledma; /* if set this points to ledma and arch=4m */
128 int burst_sizes; /* ledma SBus burst sizes */
129#endif
130 struct timer_list multicast_timer;
131};
132
133#define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
134 lp->tx_old+lp->tx_ring_mod_mask-lp->tx_new:\
135 lp->tx_old - lp->tx_new-1)
136
137
138#define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
139
140/* Load the CSR registers */
141static void load_csrs (struct lance_private *lp)
142{
143 volatile struct lance_regs *ll = lp->ll;
144 volatile struct lance_init_block *aib = lp->lance_init_block;
145 int leptr;
146
147 leptr = LANCE_ADDR (aib);
148
149 ll->rap = LE_CSR1;
150 ll->rdp = (leptr & 0xFFFF);
151 ll->rap = LE_CSR2;
152 ll->rdp = leptr >> 16;
153 ll->rap = LE_CSR3;
154 ll->rdp = lp->busmaster_regval;
155
156 /* Point back to csr0 */
157 ll->rap = LE_CSR0;
158}
159
160#define ZERO 0
161
162/* Setup the Lance Rx and Tx rings */
163static void lance_init_ring (struct net_device *dev)
164{
165 struct lance_private *lp = netdev_priv(dev);
166 volatile struct lance_init_block *ib = lp->init_block;
167 volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */
168 int leptr;
169 int i;
170
171 aib = lp->lance_init_block;
172
173 /* Lock out other processes while setting up hardware */
174 netif_stop_queue(dev);
175 lp->rx_new = lp->tx_new = 0;
176 lp->rx_old = lp->tx_old = 0;
177
178 ib->mode = 0;
179
180 /* Copy the ethernet address to the lance init block
181 * Note that on the sparc you need to swap the ethernet address.
182 */
183 ib->phys_addr [0] = dev->dev_addr [1];
184 ib->phys_addr [1] = dev->dev_addr [0];
185 ib->phys_addr [2] = dev->dev_addr [3];
186 ib->phys_addr [3] = dev->dev_addr [2];
187 ib->phys_addr [4] = dev->dev_addr [5];
188 ib->phys_addr [5] = dev->dev_addr [4];
189
190 if (ZERO)
191 printk(KERN_DEBUG "TX rings:\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 /* Setup the Tx ring entries */
194 for (i = 0; i <= (1<<lp->lance_log_tx_bufs); i++) {
195 leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
196 ib->btx_ring [i].tmd0 = leptr;
197 ib->btx_ring [i].tmd1_hadr = leptr >> 16;
198 ib->btx_ring [i].tmd1_bits = 0;
199 ib->btx_ring [i].length = 0xf000; /* The ones required by tmd2 */
200 ib->btx_ring [i].misc = 0;
201 if (i < 3 && ZERO)
202 printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr);
203 }
204
205 /* Setup the Rx ring entries */
206 if (ZERO)
207 printk(KERN_DEBUG "RX rings:\n");
208 for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) {
209 leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
210
211 ib->brx_ring [i].rmd0 = leptr;
212 ib->brx_ring [i].rmd1_hadr = leptr >> 16;
213 ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
214 ib->brx_ring [i].length = -RX_BUFF_SIZE | 0xf000;
215 ib->brx_ring [i].mblength = 0;
216 if (i < 3 && ZERO)
217 printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr);
218 }
219
220 /* Setup the initialization block */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 /* Setup rx descriptor pointer */
223 leptr = LANCE_ADDR(&aib->brx_ring);
224 ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
225 ib->rx_ptr = leptr;
226 if (ZERO)
227 printk(KERN_DEBUG "RX ptr: %8.8x\n", leptr);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 /* Setup tx descriptor pointer */
230 leptr = LANCE_ADDR(&aib->btx_ring);
231 ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
232 ib->tx_ptr = leptr;
233 if (ZERO)
234 printk(KERN_DEBUG "TX ptr: %8.8x\n", leptr);
235
236 /* Clear the multicast filter */
237 ib->filter [0] = 0;
238 ib->filter [1] = 0;
239}
240
241static int init_restart_lance (struct lance_private *lp)
242{
243 volatile struct lance_regs *ll = lp->ll;
244 int i;
245
246 ll->rap = LE_CSR0;
247 ll->rdp = LE_C0_INIT;
248
249 /* Wait for the lance to complete initialization */
250 for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++)
251 barrier();
252 if ((i == 100) || (ll->rdp & LE_C0_ERR)) {
253 printk(KERN_ERR "LANCE unopened after %d ticks, csr0=%4.4x.\n",
254 i, ll->rdp);
255 return -EIO;
256 }
257
258 /* Clear IDON by writing a "1", enable interrupts and start lance */
259 ll->rdp = LE_C0_IDON;
260 ll->rdp = LE_C0_INEA | LE_C0_STRT;
261
262 return 0;
263}
264
265static int lance_rx (struct net_device *dev)
266{
267 struct lance_private *lp = netdev_priv(dev);
268 volatile struct lance_init_block *ib = lp->init_block;
269 volatile struct lance_regs *ll = lp->ll;
270 volatile struct lance_rx_desc *rd;
271 unsigned char bits;
272 int len = 0; /* XXX shut up gcc warnings */
273 struct sk_buff *skb = 0; /* XXX shut up gcc warnings */
274
275#ifdef TEST_HITS
276 int i;
277 printk(KERN_DEBUG "[");
278 for (i = 0; i < RX_RING_SIZE; i++) {
279 if (i == lp->rx_new)
280 printk ("%s",
281 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X");
282 else
283 printk ("%s",
284 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1");
285 }
286 printk ("]\n");
287#endif
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 ll->rdp = LE_C0_RINT|LE_C0_INEA;
290 for (rd = &ib->brx_ring [lp->rx_new];
291 !((bits = rd->rmd1_bits) & LE_R1_OWN);
292 rd = &ib->brx_ring [lp->rx_new]) {
293
294 /* We got an incomplete frame? */
295 if ((bits & LE_R1_POK) != LE_R1_POK) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700296 dev->stats.rx_over_errors++;
297 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 continue;
299 } else if (bits & LE_R1_ERR) {
300 /* Count only the end frame as a rx error,
301 * not the beginning
302 */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700303 if (bits & LE_R1_BUF) dev->stats.rx_fifo_errors++;
304 if (bits & LE_R1_CRC) dev->stats.rx_crc_errors++;
305 if (bits & LE_R1_OFL) dev->stats.rx_over_errors++;
306 if (bits & LE_R1_FRA) dev->stats.rx_frame_errors++;
307 if (bits & LE_R1_EOP) dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 } else {
309 len = (rd->mblength & 0xfff) - 4;
310 skb = dev_alloc_skb (len+2);
311
312 if (skb == 0) {
313 printk(KERN_WARNING "%s: Memory squeeze, "
314 "deferring packet.\n", dev->name);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700315 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 rd->mblength = 0;
317 rd->rmd1_bits = LE_R1_OWN;
318 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
319 return 0;
320 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 skb_reserve (skb, 2); /* 16 byte align */
323 skb_put (skb, len); /* make room */
David S. Miller8c7b7fa2007-07-10 22:08:12 -0700324 skb_copy_to_linear_data(skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
David S. Miller8c7b7fa2007-07-10 22:08:12 -0700326 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 skb->protocol = eth_type_trans (skb, dev);
328 netif_rx (skb);
329 dev->last_rx = jiffies;
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700330 dev->stats.rx_packets++;
331 dev->stats.rx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
333
334 /* Return the packet to the pool */
335 rd->mblength = 0;
336 rd->rmd1_bits = LE_R1_OWN;
337 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
338 }
339 return 0;
340}
341
342static int lance_tx (struct net_device *dev)
343{
344 struct lance_private *lp = netdev_priv(dev);
345 volatile struct lance_init_block *ib = lp->init_block;
346 volatile struct lance_regs *ll = lp->ll;
347 volatile struct lance_tx_desc *td;
348 int i, j;
349 int status;
350
351 /* csr0 is 2f3 */
352 ll->rdp = LE_C0_TINT | LE_C0_INEA;
353 /* csr0 is 73 */
354
355 j = lp->tx_old;
356 for (i = j; i != lp->tx_new; i = j) {
357 td = &ib->btx_ring [i];
358
359 /* If we hit a packet not owned by us, stop */
360 if (td->tmd1_bits & LE_T1_OWN)
361 break;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 if (td->tmd1_bits & LE_T1_ERR) {
364 status = td->misc;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400365
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700366 dev->stats.tx_errors++;
367 if (status & LE_T3_RTY) dev->stats.tx_aborted_errors++;
368 if (status & LE_T3_LCOL) dev->stats.tx_window_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370 if (status & LE_T3_CLOS) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700371 dev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 if (lp->auto_select) {
373 lp->tpe = 1 - lp->tpe;
374 printk(KERN_ERR "%s: Carrier Lost, "
375 "trying %s\n", dev->name,
376 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;
384 }
385 }
386
387 /* buffer errors and underflows turn off the transmitter */
388 /* Restart the adapter */
389 if (status & (LE_T3_BUF|LE_T3_UFL)) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700390 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 printk(KERN_ERR "%s: Tx: ERR_BUF|ERR_UFL, "
393 "restarting\n", 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;
401 }
402 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
403 /*
404 * So we don't count the packet more than once.
405 */
406 td->tmd1_bits &= ~(LE_T1_POK);
407
408 /* One collision before packet was sent. */
409 if (td->tmd1_bits & LE_T1_EONE)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700410 dev->stats.collisions++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 /* More than one collision, be optimistic. */
413 if (td->tmd1_bits & LE_T1_EMORE)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700414 dev->stats.collisions += 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700416 dev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 j = (j + 1) & lp->tx_ring_mod_mask;
420 }
421 lp->tx_old = j;
422 ll->rdp = LE_C0_TINT | LE_C0_INEA;
423 return 0;
424}
425
David Howells7d12e782006-10-05 14:55:46 +0100426static irqreturn_t lance_interrupt (int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
428 struct net_device *dev;
429 struct lance_private *lp;
430 volatile struct lance_regs *ll;
431 int csr0;
432
433 dev = (struct net_device *) dev_id;
434
435 lp = netdev_priv(dev);
436 ll = lp->ll;
437
438 ll->rap = LE_CSR0; /* LANCE Controller Status */
439 csr0 = ll->rdp;
440
441 if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */
442 return IRQ_NONE; /* been generated by the Lance. */
443
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);
447
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;
451 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if (csr0 & LE_C0_RINT)
454 lance_rx (dev);
455
456 if (csr0 & LE_C0_TINT)
457 lance_tx (dev);
458
459 /* Log misc errors. */
460 if (csr0 & LE_C0_BABL)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700461 dev->stats.tx_errors++; /* Tx babble. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 if (csr0 & LE_C0_MISS)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700463 dev->stats.rx_errors++; /* Missed a Rx frame. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 if (csr0 & LE_C0_MERR) {
465 printk(KERN_ERR "%s: Bus master arbitration failure, status "
466 "%4.4x.\n", dev->name, csr0);
467 /* Restart the chip. */
468 ll->rdp = LE_C0_STRT;
469 }
470
471 if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
472 netif_wake_queue(dev);
473
474 ll->rap = LE_CSR0;
475 ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
476 LE_C0_IDON|LE_C0_INEA;
477 return IRQ_HANDLED;
478}
479
480struct net_device *last_dev = 0;
481
482static int lance_open (struct net_device *dev)
483{
484 struct lance_private *lp = netdev_priv(dev);
485 volatile struct lance_regs *ll = lp->ll;
486 int ret;
487
488 last_dev = dev;
489
490 /* Stop the Lance */
491 ll->rap = LE_CSR0;
492 ll->rdp = LE_C0_STOP;
493
494 /* Install the Interrupt handler */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700495 ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, IRQF_SHARED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 dev->name, dev);
497 if (ret) return ret;
498
499 load_csrs (lp);
500 lance_init_ring (dev);
501
502 netif_start_queue(dev);
503
504 return init_restart_lance (lp);
505}
506
507static int lance_close (struct net_device *dev)
508{
509 struct lance_private *lp = netdev_priv(dev);
510 volatile struct lance_regs *ll = lp->ll;
511
512 netif_stop_queue(dev);
513 del_timer_sync(&lp->multicast_timer);
514
515 /* Stop the card */
516 ll->rap = LE_CSR0;
517 ll->rdp = LE_C0_STOP;
518
519 free_irq(IRQ_AMIGA_PORTS, dev);
520 return 0;
521}
522
523static inline int lance_reset (struct net_device *dev)
524{
525 struct lance_private *lp = netdev_priv(dev);
526 volatile struct lance_regs *ll = lp->ll;
527 int status;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400528
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 /* Stop the lance */
530 ll->rap = LE_CSR0;
531 ll->rdp = LE_C0_STOP;
532
533 load_csrs (lp);
534
535 lance_init_ring (dev);
536 dev->trans_start = jiffies;
537 netif_start_queue(dev);
538
539 status = init_restart_lance (lp);
540#ifdef DEBUG_DRIVER
541 printk(KERN_DEBUG "Lance restart=%d\n", status);
542#endif
543 return status;
544}
545
546static void lance_tx_timeout(struct net_device *dev)
547{
548 struct lance_private *lp = netdev_priv(dev);
549 volatile struct lance_regs *ll = lp->ll;
550
551 printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
552 dev->name, ll->rdp);
553 lance_reset(dev);
554 netif_wake_queue(dev);
555}
556
557static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
558{
559 struct lance_private *lp = netdev_priv(dev);
560 volatile struct lance_regs *ll = lp->ll;
561 volatile struct lance_init_block *ib = lp->init_block;
562 int entry, skblen, len;
563 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 unsigned long flags;
565
566 skblen = skb->len;
567 len = skblen;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 if (len < ETH_ZLEN) {
570 len = ETH_ZLEN;
Herbert Xu5b057c62006-06-23 02:06:41 -0700571 if (skb_padto(skb, ETH_ZLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 return 0;
573 }
574
575 local_irq_save(flags);
576
577 if (!TX_BUFFS_AVAIL){
578 local_irq_restore(flags);
579 return -1;
580 }
581
582#ifdef DEBUG_DRIVER
583 /* dump the packet */
584 {
585 int i;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 for (i = 0; i < 64; i++) {
588 if ((i % 16) == 0)
589 printk("\n" KERN_DEBUG);
590 printk ("%2.2x ", skb->data [i]);
591 }
592 printk("\n");
593 }
594#endif
595 entry = lp->tx_new & lp->tx_ring_mod_mask;
596 ib->btx_ring [entry].length = (-len) | 0xf000;
597 ib->btx_ring [entry].misc = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400598
Geert Uytterhoevencfa08bb2007-05-01 22:33:05 +0200599 skb_copy_from_linear_data(skb, (void *)&ib->tx_buf [entry][0], skblen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 /* Clear the slack of the packet, do I need this? */
602 if (len != skblen)
Geert Uytterhoevencfa08bb2007-05-01 22:33:05 +0200603 memset ((void *) &ib->tx_buf [entry][skblen], 0, len - skblen);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 /* Now, give the packet to the lance */
606 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
607 lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700608 dev->stats.tx_bytes += skblen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 if (TX_BUFFS_AVAIL <= 0)
611 netif_stop_queue(dev);
612
613 /* Kick the lance: transmit now */
614 ll->rdp = LE_C0_INEA | LE_C0_TDMD;
615 dev->trans_start = jiffies;
616 dev_kfree_skb (skb);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 local_irq_restore(flags);
619
620 return status;
621}
622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623/* taken from the depca driver */
624static void lance_load_multicast (struct net_device *dev)
625{
626 struct lance_private *lp = netdev_priv(dev);
627 volatile struct lance_init_block *ib = lp->init_block;
628 volatile u16 *mcast_table = (u16 *)&ib->filter;
629 struct dev_mc_list *dmi=dev->mc_list;
630 char *addrs;
631 int i;
632 u32 crc;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 /* set all multicast bits */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400635 if (dev->flags & IFF_ALLMULTI){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 ib->filter [0] = 0xffffffff;
637 ib->filter [1] = 0xffffffff;
638 return;
639 }
640 /* clear the multicast filter */
641 ib->filter [0] = 0;
642 ib->filter [1] = 0;
643
644 /* Add addresses */
645 for (i = 0; i < dev->mc_count; i++){
646 addrs = dmi->dmi_addr;
647 dmi = dmi->next;
648
649 /* multicast address? */
650 if (!(*addrs & 1))
651 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 crc = ether_crc_le(6, addrs);
654 crc = crc >> 26;
655 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
656 }
657 return;
658}
659
660static void lance_set_multicast (struct net_device *dev)
661{
662 struct lance_private *lp = netdev_priv(dev);
663 volatile struct lance_init_block *ib = lp->init_block;
664 volatile struct lance_regs *ll = lp->ll;
665
666 if (!netif_running(dev))
667 return;
668
669 if (lp->tx_old != lp->tx_new) {
670 mod_timer(&lp->multicast_timer, jiffies + 4);
671 netif_wake_queue(dev);
672 return;
673 }
674
675 netif_stop_queue(dev);
676
677 ll->rap = LE_CSR0;
678 ll->rdp = LE_C0_STOP;
679 lance_init_ring (dev);
680
681 if (dev->flags & IFF_PROMISC) {
682 ib->mode |= LE_MO_PROM;
683 } else {
684 ib->mode &= ~LE_MO_PROM;
685 lance_load_multicast (dev);
686 }
687 load_csrs (lp);
688 init_restart_lance (lp);
689 netif_wake_queue(dev);
690}
691
692static int __devinit a2065_init_one(struct zorro_dev *z,
693 const struct zorro_device_id *ent);
694static void __devexit a2065_remove_one(struct zorro_dev *z);
695
696
697static struct zorro_device_id a2065_zorro_tbl[] __devinitdata = {
698 { ZORRO_PROD_CBM_A2065_1 },
699 { ZORRO_PROD_CBM_A2065_2 },
700 { ZORRO_PROD_AMERISTAR_A2065 },
701 { 0 }
702};
703
704static struct zorro_driver a2065_driver = {
705 .name = "a2065",
706 .id_table = a2065_zorro_tbl,
707 .probe = a2065_init_one,
708 .remove = __devexit_p(a2065_remove_one),
709};
710
711static int __devinit a2065_init_one(struct zorro_dev *z,
712 const struct zorro_device_id *ent)
713{
714 struct net_device *dev;
715 struct lance_private *priv;
716 unsigned long board, base_addr, mem_start;
717 struct resource *r1, *r2;
718 int err;
Joe Perches0795af52007-10-03 17:59:30 -0700719 DECLARE_MAC_BUF(mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
721 board = z->resource.start;
722 base_addr = board+A2065_LANCE;
723 mem_start = board+A2065_RAM;
724
725 r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
726 "Am7990");
727 if (!r1)
728 return -EBUSY;
729 r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
730 if (!r2) {
731 release_resource(r1);
732 return -EBUSY;
733 }
734
735 dev = alloc_etherdev(sizeof(struct lance_private));
736 if (dev == NULL) {
737 release_resource(r1);
738 release_resource(r2);
739 return -ENOMEM;
740 }
741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 priv = netdev_priv(dev);
743
744 r1->name = dev->name;
745 r2->name = dev->name;
746
747 dev->dev_addr[0] = 0x00;
748 if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* Commodore */
749 dev->dev_addr[1] = 0x80;
750 dev->dev_addr[2] = 0x10;
751 } else { /* Ameristar */
752 dev->dev_addr[1] = 0x00;
753 dev->dev_addr[2] = 0x9f;
754 }
755 dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
756 dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
757 dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
758 dev->base_addr = ZTWO_VADDR(base_addr);
759 dev->mem_start = ZTWO_VADDR(mem_start);
760 dev->mem_end = dev->mem_start+A2065_RAM_SIZE;
761
762 priv->ll = (volatile struct lance_regs *)dev->base_addr;
763 priv->init_block = (struct lance_init_block *)dev->mem_start;
764 priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
765 priv->auto_select = 0;
766 priv->busmaster_regval = LE_C3_BSWP;
767
768 priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
769 priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
770 priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
771 priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
772
773 dev->open = &lance_open;
774 dev->stop = &lance_close;
775 dev->hard_start_xmit = &lance_start_xmit;
776 dev->tx_timeout = &lance_tx_timeout;
777 dev->watchdog_timeo = 5*HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 dev->set_multicast_list = &lance_set_multicast;
779 dev->dma = 0;
780
781 init_timer(&priv->multicast_timer);
782 priv->multicast_timer.data = (unsigned long) dev;
783 priv->multicast_timer.function =
784 (void (*)(unsigned long)) &lance_set_multicast;
785
786 err = register_netdev(dev);
787 if (err) {
788 release_resource(r1);
789 release_resource(r2);
790 free_netdev(dev);
791 return err;
792 }
793 zorro_set_drvdata(z, dev);
794
795 printk(KERN_INFO "%s: A2065 at 0x%08lx, Ethernet Address "
Joe Perches0795af52007-10-03 17:59:30 -0700796 "%s\n", dev->name, board,
797 print_mac(mac, dev->dev_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799 return 0;
800}
801
802
803static void __devexit a2065_remove_one(struct zorro_dev *z)
804{
805 struct net_device *dev = zorro_get_drvdata(z);
806
807 unregister_netdev(dev);
808 release_mem_region(ZTWO_PADDR(dev->base_addr),
809 sizeof(struct lance_regs));
810 release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
811 free_netdev(dev);
812}
813
814static int __init a2065_init_module(void)
815{
Bjorn Helgaas33d86752006-03-25 03:07:20 -0800816 return zorro_register_driver(&a2065_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817}
818
819static void __exit a2065_cleanup_module(void)
820{
821 zorro_unregister_driver(&a2065_driver);
822}
823
824module_init(a2065_init_module);
825module_exit(a2065_cleanup_module);
826
827MODULE_LICENSE("GPL");