mac80211: convert to %pM away from print_mac
[linux-2.6-block.git] / drivers / net / ariadne.c
CommitLineData
1da177e4
LT
1/*
2 * Amiga Linux/m68k Ariadne Ethernet Driver
3 *
96de0e25 4 * © Copyright 1995-2003 by Geert Uytterhoeven (geert@linux-m68k.org)
1da177e4
LT
5 * Peter De Schrijver (p2@mind.be)
6 *
7 * ---------------------------------------------------------------------------
8 *
9 * This program is based on
10 *
11 * lance.c: An AMD LANCE ethernet driver for linux.
12 * Written 1993-94 by Donald Becker.
13 *
14 * Am79C960: PCnet(tm)-ISA Single-Chip Ethernet Controller
15 * Advanced Micro Devices
16 * Publication #16907, Rev. B, Amendment/0, May 1994
17 *
18 * MC68230: Parallel Interface/Timer (PI/T)
19 * Motorola Semiconductors, December, 1983
20 *
21 * ---------------------------------------------------------------------------
22 *
23 * This file is subject to the terms and conditions of the GNU General Public
24 * License. See the file COPYING in the main directory of the Linux
25 * distribution for more details.
26 *
27 * ---------------------------------------------------------------------------
28 *
29 * The Ariadne is a Zorro-II board made by Village Tronic. It contains:
30 *
31 * - an Am79C960 PCnet-ISA Single-Chip Ethernet Controller with both
32 * 10BASE-2 (thin coax) and 10BASE-T (UTP) connectors
33 *
34 * - an MC68230 Parallel Interface/Timer configured as 2 parallel ports
35 */
36
37#include <linux/module.h>
38#include <linux/stddef.h>
39#include <linux/kernel.h>
40#include <linux/string.h>
41#include <linux/errno.h>
42#include <linux/ioport.h>
43#include <linux/slab.h>
44#include <linux/netdevice.h>
45#include <linux/etherdevice.h>
46#include <linux/interrupt.h>
47#include <linux/skbuff.h>
48#include <linux/init.h>
49#include <linux/zorro.h>
50#include <linux/bitops.h>
51
52#include <asm/amigaints.h>
53#include <asm/amigahw.h>
54#include <asm/irq.h>
55
56#include "ariadne.h"
57
58
59#ifdef ARIADNE_DEBUG
60int ariadne_debug = ARIADNE_DEBUG;
61#else
62int ariadne_debug = 1;
63#endif
64
65
66 /*
67 * Macros to Fix Endianness problems
68 */
69
70 /* Swap the Bytes in a WORD */
71#define swapw(x) (((x>>8)&0x00ff)|((x<<8)&0xff00))
72 /* Get the Low BYTE in a WORD */
73#define lowb(x) (x&0xff)
74 /* Get the Swapped High WORD in a LONG */
75#define swhighw(x) ((((x)>>8)&0xff00)|(((x)>>24)&0x00ff))
76 /* Get the Swapped Low WORD in a LONG */
77#define swloww(x) ((((x)<<8)&0xff00)|(((x)>>8)&0x00ff))
78
79
80 /*
81 * Transmit/Receive Ring Definitions
82 */
83
84#define TX_RING_SIZE 5
85#define RX_RING_SIZE 16
86
87#define PKT_BUF_SIZE 1520
88
89
90 /*
91 * Private Device Data
92 */
93
94struct ariadne_private {
95 volatile struct TDRE *tx_ring[TX_RING_SIZE];
96 volatile struct RDRE *rx_ring[RX_RING_SIZE];
97 volatile u_short *tx_buff[TX_RING_SIZE];
98 volatile u_short *rx_buff[RX_RING_SIZE];
99 int cur_tx, cur_rx; /* The next free ring entry */
100 int dirty_tx; /* The ring entries to be free()ed. */
1da177e4
LT
101 char tx_full;
102};
103
104
105 /*
106 * Structure Created in the Ariadne's RAM Buffer
107 */
108
109struct lancedata {
110 struct TDRE tx_ring[TX_RING_SIZE];
111 struct RDRE rx_ring[RX_RING_SIZE];
112 u_short tx_buff[TX_RING_SIZE][PKT_BUF_SIZE/sizeof(u_short)];
113 u_short rx_buff[RX_RING_SIZE][PKT_BUF_SIZE/sizeof(u_short)];
114};
115
116static int ariadne_open(struct net_device *dev);
117static void ariadne_init_ring(struct net_device *dev);
118static int ariadne_start_xmit(struct sk_buff *skb, struct net_device *dev);
119static void ariadne_tx_timeout(struct net_device *dev);
120static int ariadne_rx(struct net_device *dev);
121static void ariadne_reset(struct net_device *dev);
7d12e780 122static irqreturn_t ariadne_interrupt(int irq, void *data);
1da177e4
LT
123static int ariadne_close(struct net_device *dev);
124static struct net_device_stats *ariadne_get_stats(struct net_device *dev);
125#ifdef HAVE_MULTICAST
126static void set_multicast_list(struct net_device *dev);
127#endif
128
129
130static void memcpyw(volatile u_short *dest, u_short *src, int len)
131{
132 while (len >= 2) {
133 *(dest++) = *(src++);
134 len -= 2;
135 }
136 if (len == 1)
137 *dest = (*(u_char *)src)<<8;
138}
139
140
141static int __devinit ariadne_init_one(struct zorro_dev *z,
142 const struct zorro_device_id *ent);
143static void __devexit ariadne_remove_one(struct zorro_dev *z);
144
145
146static struct zorro_device_id ariadne_zorro_tbl[] __devinitdata = {
147 { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE },
148 { 0 }
149};
150
151static struct zorro_driver ariadne_driver = {
152 .name = "ariadne",
153 .id_table = ariadne_zorro_tbl,
154 .probe = ariadne_init_one,
155 .remove = __devexit_p(ariadne_remove_one),
156};
157
158static int __devinit ariadne_init_one(struct zorro_dev *z,
159 const struct zorro_device_id *ent)
160{
161 unsigned long board = z->resource.start;
162 unsigned long base_addr = board+ARIADNE_LANCE;
163 unsigned long mem_start = board+ARIADNE_RAM;
164 struct resource *r1, *r2;
165 struct net_device *dev;
166 struct ariadne_private *priv;
167 int err;
0795af57 168 DECLARE_MAC_BUF(mac);
1da177e4
LT
169
170 r1 = request_mem_region(base_addr, sizeof(struct Am79C960), "Am79C960");
171 if (!r1)
172 return -EBUSY;
173 r2 = request_mem_region(mem_start, ARIADNE_RAM_SIZE, "RAM");
174 if (!r2) {
175 release_resource(r1);
176 return -EBUSY;
177 }
178
179 dev = alloc_etherdev(sizeof(struct ariadne_private));
180 if (dev == NULL) {
181 release_resource(r1);
182 release_resource(r2);
183 return -ENOMEM;
184 }
185
1da177e4
LT
186 priv = netdev_priv(dev);
187
188 r1->name = dev->name;
189 r2->name = dev->name;
190
191 dev->dev_addr[0] = 0x00;
192 dev->dev_addr[1] = 0x60;
193 dev->dev_addr[2] = 0x30;
194 dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
195 dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
196 dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
197 dev->base_addr = ZTWO_VADDR(base_addr);
198 dev->mem_start = ZTWO_VADDR(mem_start);
199 dev->mem_end = dev->mem_start+ARIADNE_RAM_SIZE;
200
201 dev->open = &ariadne_open;
202 dev->stop = &ariadne_close;
203 dev->hard_start_xmit = &ariadne_start_xmit;
204 dev->tx_timeout = &ariadne_tx_timeout;
205 dev->watchdog_timeo = 5*HZ;
206 dev->get_stats = &ariadne_get_stats;
207 dev->set_multicast_list = &set_multicast_list;
208
209 err = register_netdev(dev);
210 if (err) {
211 release_resource(r1);
212 release_resource(r2);
213 free_netdev(dev);
214 return err;
215 }
216 zorro_set_drvdata(z, dev);
217
218 printk(KERN_INFO "%s: Ariadne at 0x%08lx, Ethernet Address "
0795af57
JP
219 "%s\n", dev->name, board,
220 print_mac(mac, dev->dev_addr));
1da177e4
LT
221
222 return 0;
223}
224
225
226static int ariadne_open(struct net_device *dev)
227{
228 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
229 u_short in;
230 u_long version;
231 int i;
232
233 /* Reset the LANCE */
234 in = lance->Reset;
235
236 /* Stop the LANCE */
237 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
238 lance->RDP = STOP;
239
240 /* Check the LANCE version */
241 lance->RAP = CSR88; /* Chip ID */
242 version = swapw(lance->RDP);
243 lance->RAP = CSR89; /* Chip ID */
244 version |= swapw(lance->RDP)<<16;
245 if ((version & 0x00000fff) != 0x00000003) {
246 printk(KERN_WARNING "ariadne_open: Couldn't find AMD Ethernet Chip\n");
247 return -EAGAIN;
248 }
249 if ((version & 0x0ffff000) != 0x00003000) {
250 printk(KERN_WARNING "ariadne_open: Couldn't find Am79C960 (Wrong part "
251 "number = %ld)\n", (version & 0x0ffff000)>>12);
252 return -EAGAIN;
253 }
254#if 0
255 printk(KERN_DEBUG "ariadne_open: Am79C960 (PCnet-ISA) Revision %ld\n",
256 (version & 0xf0000000)>>28);
257#endif
258
259 ariadne_init_ring(dev);
260
261 /* Miscellaneous Stuff */
262 lance->RAP = CSR3; /* Interrupt Masks and Deferral Control */
263 lance->RDP = 0x0000;
264 lance->RAP = CSR4; /* Test and Features Control */
265 lance->RDP = DPOLL|APAD_XMT|MFCOM|RCVCCOM|TXSTRTM|JABM;
266
267 /* Set the Multicast Table */
268 lance->RAP = CSR8; /* Logical Address Filter, LADRF[15:0] */
269 lance->RDP = 0x0000;
270 lance->RAP = CSR9; /* Logical Address Filter, LADRF[31:16] */
271 lance->RDP = 0x0000;
272 lance->RAP = CSR10; /* Logical Address Filter, LADRF[47:32] */
273 lance->RDP = 0x0000;
274 lance->RAP = CSR11; /* Logical Address Filter, LADRF[63:48] */
275 lance->RDP = 0x0000;
276
277 /* Set the Ethernet Hardware Address */
278 lance->RAP = CSR12; /* Physical Address Register, PADR[15:0] */
279 lance->RDP = ((u_short *)&dev->dev_addr[0])[0];
280 lance->RAP = CSR13; /* Physical Address Register, PADR[31:16] */
281 lance->RDP = ((u_short *)&dev->dev_addr[0])[1];
282 lance->RAP = CSR14; /* Physical Address Register, PADR[47:32] */
283 lance->RDP = ((u_short *)&dev->dev_addr[0])[2];
284
285 /* Set the Init Block Mode */
286 lance->RAP = CSR15; /* Mode Register */
287 lance->RDP = 0x0000;
288
289 /* Set the Transmit Descriptor Ring Pointer */
290 lance->RAP = CSR30; /* Base Address of Transmit Ring */
291 lance->RDP = swloww(ARIADNE_RAM+offsetof(struct lancedata, tx_ring));
292 lance->RAP = CSR31; /* Base Address of transmit Ring */
293 lance->RDP = swhighw(ARIADNE_RAM+offsetof(struct lancedata, tx_ring));
294
295 /* Set the Receive Descriptor Ring Pointer */
296 lance->RAP = CSR24; /* Base Address of Receive Ring */
297 lance->RDP = swloww(ARIADNE_RAM+offsetof(struct lancedata, rx_ring));
298 lance->RAP = CSR25; /* Base Address of Receive Ring */
299 lance->RDP = swhighw(ARIADNE_RAM+offsetof(struct lancedata, rx_ring));
300
301 /* Set the Number of RX and TX Ring Entries */
302 lance->RAP = CSR76; /* Receive Ring Length */
303 lance->RDP = swapw(((u_short)-RX_RING_SIZE));
304 lance->RAP = CSR78; /* Transmit Ring Length */
305 lance->RDP = swapw(((u_short)-TX_RING_SIZE));
306
307 /* Enable Media Interface Port Auto Select (10BASE-2/10BASE-T) */
308 lance->RAP = ISACSR2; /* Miscellaneous Configuration */
309 lance->IDP = ASEL;
310
311 /* LED Control */
312 lance->RAP = ISACSR5; /* LED1 Status */
313 lance->IDP = PSE|XMTE;
314 lance->RAP = ISACSR6; /* LED2 Status */
315 lance->IDP = PSE|COLE;
316 lance->RAP = ISACSR7; /* LED3 Status */
317 lance->IDP = PSE|RCVE;
318
319 netif_start_queue(dev);
320
1fb9df5d 321 i = request_irq(IRQ_AMIGA_PORTS, ariadne_interrupt, IRQF_SHARED,
1da177e4
LT
322 dev->name, dev);
323 if (i) return i;
324
325 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
326 lance->RDP = INEA|STRT;
327
328 return 0;
329}
330
331
332static void ariadne_init_ring(struct net_device *dev)
333{
334 struct ariadne_private *priv = netdev_priv(dev);
335 volatile struct lancedata *lancedata = (struct lancedata *)dev->mem_start;
336 int i;
337
338 netif_stop_queue(dev);
339
340 priv->tx_full = 0;
341 priv->cur_rx = priv->cur_tx = 0;
342 priv->dirty_tx = 0;
343
344 /* Set up TX Ring */
345 for (i = 0; i < TX_RING_SIZE; i++) {
346 volatile struct TDRE *t = &lancedata->tx_ring[i];
347 t->TMD0 = swloww(ARIADNE_RAM+offsetof(struct lancedata, tx_buff[i]));
348 t->TMD1 = swhighw(ARIADNE_RAM+offsetof(struct lancedata, tx_buff[i])) |
349 TF_STP | TF_ENP;
350 t->TMD2 = swapw((u_short)-PKT_BUF_SIZE);
351 t->TMD3 = 0;
352 priv->tx_ring[i] = &lancedata->tx_ring[i];
353 priv->tx_buff[i] = lancedata->tx_buff[i];
354#if 0
355 printk(KERN_DEBUG "TX Entry %2d at %p, Buf at %p\n", i,
356 &lancedata->tx_ring[i], lancedata->tx_buff[i]);
357#endif
358 }
359
360 /* Set up RX Ring */
361 for (i = 0; i < RX_RING_SIZE; i++) {
362 volatile struct RDRE *r = &lancedata->rx_ring[i];
363 r->RMD0 = swloww(ARIADNE_RAM+offsetof(struct lancedata, rx_buff[i]));
364 r->RMD1 = swhighw(ARIADNE_RAM+offsetof(struct lancedata, rx_buff[i])) |
365 RF_OWN;
366 r->RMD2 = swapw((u_short)-PKT_BUF_SIZE);
367 r->RMD3 = 0x0000;
368 priv->rx_ring[i] = &lancedata->rx_ring[i];
369 priv->rx_buff[i] = lancedata->rx_buff[i];
370#if 0
371 printk(KERN_DEBUG "RX Entry %2d at %p, Buf at %p\n", i,
372 &lancedata->rx_ring[i], lancedata->rx_buff[i]);
373#endif
374 }
375}
376
377
378static int ariadne_close(struct net_device *dev)
379{
1da177e4
LT
380 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
381
382 netif_stop_queue(dev);
383
384 lance->RAP = CSR112; /* Missed Frame Count */
038eddd9 385 dev->stats.rx_missed_errors = swapw(lance->RDP);
1da177e4
LT
386 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
387
388 if (ariadne_debug > 1) {
389 printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n",
390 dev->name, lance->RDP);
391 printk(KERN_DEBUG "%s: %lu packets missed\n", dev->name,
038eddd9 392 dev->stats.rx_missed_errors);
1da177e4
LT
393 }
394
395 /* We stop the LANCE here -- it occasionally polls memory if we don't. */
396 lance->RDP = STOP;
397
398 free_irq(IRQ_AMIGA_PORTS, dev);
399
400 return 0;
401}
402
403
404static inline void ariadne_reset(struct net_device *dev)
405{
406 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
407
408 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
409 lance->RDP = STOP;
410 ariadne_init_ring(dev);
411 lance->RDP = INEA|STRT;
412 netif_start_queue(dev);
413}
414
415
7d12e780 416static irqreturn_t ariadne_interrupt(int irq, void *data)
1da177e4
LT
417{
418 struct net_device *dev = (struct net_device *)data;
419 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
420 struct ariadne_private *priv;
421 int csr0, boguscnt;
422 int handled = 0;
423
424 if (dev == NULL) {
425 printk(KERN_WARNING "ariadne_interrupt(): irq for unknown device.\n");
426 return IRQ_NONE;
427 }
428
429 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
430
431 if (!(lance->RDP & INTR)) /* Check if any interrupt has been */
432 return IRQ_NONE; /* generated by the board. */
433
434 priv = netdev_priv(dev);
435
436 boguscnt = 10;
437 while ((csr0 = lance->RDP) & (ERR|RINT|TINT) && --boguscnt >= 0) {
438 /* Acknowledge all of the current interrupt sources ASAP. */
439 lance->RDP = csr0 & ~(INEA|TDMD|STOP|STRT|INIT);
440
441#if 0
442 if (ariadne_debug > 5) {
443 printk(KERN_DEBUG "%s: interrupt csr0=%#2.2x new csr=%#2.2x.",
444 dev->name, csr0, lance->RDP);
445 printk("[");
446 if (csr0 & INTR)
447 printk(" INTR");
448 if (csr0 & INEA)
449 printk(" INEA");
450 if (csr0 & RXON)
451 printk(" RXON");
452 if (csr0 & TXON)
453 printk(" TXON");
454 if (csr0 & TDMD)
455 printk(" TDMD");
456 if (csr0 & STOP)
457 printk(" STOP");
458 if (csr0 & STRT)
459 printk(" STRT");
460 if (csr0 & INIT)
461 printk(" INIT");
462 if (csr0 & ERR)
463 printk(" ERR");
464 if (csr0 & BABL)
465 printk(" BABL");
466 if (csr0 & CERR)
467 printk(" CERR");
468 if (csr0 & MISS)
469 printk(" MISS");
470 if (csr0 & MERR)
471 printk(" MERR");
472 if (csr0 & RINT)
473 printk(" RINT");
474 if (csr0 & TINT)
475 printk(" TINT");
476 if (csr0 & IDON)
477 printk(" IDON");
478 printk(" ]\n");
479 }
480#endif
481
482 if (csr0 & RINT) { /* Rx interrupt */
483 handled = 1;
484 ariadne_rx(dev);
485 }
486
487 if (csr0 & TINT) { /* Tx-done interrupt */
488 int dirty_tx = priv->dirty_tx;
489
490 handled = 1;
491 while (dirty_tx < priv->cur_tx) {
492 int entry = dirty_tx % TX_RING_SIZE;
493 int status = lowb(priv->tx_ring[entry]->TMD1);
494
495 if (status & TF_OWN)
496 break; /* It still hasn't been Txed */
497
498 priv->tx_ring[entry]->TMD1 &= 0xff00;
499
500 if (status & TF_ERR) {
501 /* There was an major error, log it. */
502 int err_status = priv->tx_ring[entry]->TMD3;
038eddd9 503 dev->stats.tx_errors++;
1da177e4 504 if (err_status & EF_RTRY)
038eddd9 505 dev->stats.tx_aborted_errors++;
1da177e4 506 if (err_status & EF_LCAR)
038eddd9 507 dev->stats.tx_carrier_errors++;
1da177e4 508 if (err_status & EF_LCOL)
038eddd9 509 dev->stats.tx_window_errors++;
1da177e4
LT
510 if (err_status & EF_UFLO) {
511 /* Ackk! On FIFO errors the Tx unit is turned off! */
038eddd9 512 dev->stats.tx_fifo_errors++;
1da177e4
LT
513 /* Remove this verbosity later! */
514 printk(KERN_ERR "%s: Tx FIFO error! Status %4.4x.\n",
515 dev->name, csr0);
516 /* Restart the chip. */
517 lance->RDP = STRT;
518 }
519 } else {
520 if (status & (TF_MORE|TF_ONE))
038eddd9
PZ
521 dev->stats.collisions++;
522 dev->stats.tx_packets++;
1da177e4
LT
523 }
524 dirty_tx++;
525 }
526
527#ifndef final_version
528 if (priv->cur_tx - dirty_tx >= TX_RING_SIZE) {
529 printk(KERN_ERR "out-of-sync dirty pointer, %d vs. %d, "
530 "full=%d.\n", dirty_tx, priv->cur_tx, priv->tx_full);
531 dirty_tx += TX_RING_SIZE;
532 }
533#endif
534
535 if (priv->tx_full && netif_queue_stopped(dev) &&
536 dirty_tx > priv->cur_tx - TX_RING_SIZE + 2) {
537 /* The ring is no longer full. */
538 priv->tx_full = 0;
539 netif_wake_queue(dev);
540 }
541
542 priv->dirty_tx = dirty_tx;
543 }
544
545 /* Log misc errors. */
546 if (csr0 & BABL) {
547 handled = 1;
038eddd9 548 dev->stats.tx_errors++; /* Tx babble. */
1da177e4
LT
549 }
550 if (csr0 & MISS) {
551 handled = 1;
038eddd9 552 dev->stats.rx_errors++; /* Missed a Rx frame. */
1da177e4
LT
553 }
554 if (csr0 & MERR) {
555 handled = 1;
556 printk(KERN_ERR "%s: Bus master arbitration failure, status "
557 "%4.4x.\n", dev->name, csr0);
558 /* Restart the chip. */
559 lance->RDP = STRT;
560 }
561 }
562
563 /* Clear any other interrupt, and set interrupt enable. */
564 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
565 lance->RDP = INEA|BABL|CERR|MISS|MERR|IDON;
566
567#if 0
568 if (ariadne_debug > 4)
569 printk(KERN_DEBUG "%s: exiting interrupt, csr%d=%#4.4x.\n", dev->name,
570 lance->RAP, lance->RDP);
571#endif
572 return IRQ_RETVAL(handled);
573}
574
575
576static void ariadne_tx_timeout(struct net_device *dev)
577{
578 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
579
580 printk(KERN_ERR "%s: transmit timed out, status %4.4x, resetting.\n",
581 dev->name, lance->RDP);
582 ariadne_reset(dev);
583 netif_wake_queue(dev);
584}
585
586
587static int ariadne_start_xmit(struct sk_buff *skb, struct net_device *dev)
588{
589 struct ariadne_private *priv = netdev_priv(dev);
590 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
591 int entry;
592 unsigned long flags;
593 int len = skb->len;
594
595#if 0
596 if (ariadne_debug > 3) {
597 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
598 printk(KERN_DEBUG "%s: ariadne_start_xmit() called, csr0 %4.4x.\n",
599 dev->name, lance->RDP);
600 lance->RDP = 0x0000;
601 }
602#endif
603
604 /* FIXME: is the 79C960 new enough to do its own padding right ? */
605 if (skb->len < ETH_ZLEN)
606 {
5b057c6b 607 if (skb_padto(skb, ETH_ZLEN))
1da177e4
LT
608 return 0;
609 len = ETH_ZLEN;
610 }
611
612 /* Fill in a Tx ring entry */
613
614#if 0
0795af57
JP
615{
616 DECLARE_MAC_BUF(mac);
617 DECLARE_MAC_BUF(mac2);
618
619 printk(KERN_DEBUG "TX pkt type 0x%04x from %s to %s "
620 " data 0x%08x len %d\n",
621 ((u_short *)skb->data)[6],
622 print_mac(mac, ((const u8 *)skb->data)+6),
623 print_mac(mac, (const u8 *)skb->data),
624 (int)skb->data, (int)skb->len);
625}
1da177e4
LT
626#endif
627
628 local_irq_save(flags);
629
630 entry = priv->cur_tx % TX_RING_SIZE;
631
632 /* Caution: the write order is important here, set the base address with
633 the "ownership" bits last. */
634
635 priv->tx_ring[entry]->TMD2 = swapw((u_short)-skb->len);
636 priv->tx_ring[entry]->TMD3 = 0x0000;
637 memcpyw(priv->tx_buff[entry], (u_short *)skb->data, len);
638
639#if 0
640 {
641 int i, len;
642
643 len = skb->len > 64 ? 64 : skb->len;
644 len >>= 1;
645 for (i = 0; i < len; i += 8) {
646 int j;
647 printk(KERN_DEBUG "%04x:", i);
648 for (j = 0; (j < 8) && ((i+j) < len); j++) {
649 if (!(j & 1))
650 printk(" ");
651 printk("%04x", priv->tx_buff[entry][i+j]);
652 }
653 printk("\n");
654 }
655 }
656#endif
657
658 priv->tx_ring[entry]->TMD1 = (priv->tx_ring[entry]->TMD1&0xff00)|TF_OWN|TF_STP|TF_ENP;
659
660 dev_kfree_skb(skb);
661
662 priv->cur_tx++;
663 if ((priv->cur_tx >= TX_RING_SIZE) && (priv->dirty_tx >= TX_RING_SIZE)) {
664
665#if 0
666 printk(KERN_DEBUG "*** Subtracting TX_RING_SIZE from cur_tx (%d) and "
667 "dirty_tx (%d)\n", priv->cur_tx, priv->dirty_tx);
668#endif
669
670 priv->cur_tx -= TX_RING_SIZE;
671 priv->dirty_tx -= TX_RING_SIZE;
672 }
038eddd9 673 dev->stats.tx_bytes += len;
1da177e4
LT
674
675 /* Trigger an immediate send poll. */
676 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
677 lance->RDP = INEA|TDMD;
678
679 dev->trans_start = jiffies;
680
681 if (lowb(priv->tx_ring[(entry+1) % TX_RING_SIZE]->TMD1) != 0) {
682 netif_stop_queue(dev);
683 priv->tx_full = 1;
684 }
685 local_irq_restore(flags);
686
687 return 0;
688}
689
690
691static int ariadne_rx(struct net_device *dev)
692{
693 struct ariadne_private *priv = netdev_priv(dev);
694 int entry = priv->cur_rx % RX_RING_SIZE;
695 int i;
696
697 /* If we own the next entry, it's a new packet. Send it up. */
698 while (!(lowb(priv->rx_ring[entry]->RMD1) & RF_OWN)) {
699 int status = lowb(priv->rx_ring[entry]->RMD1);
700
701 if (status != (RF_STP|RF_ENP)) { /* There was an error. */
702 /* There is a tricky error noted by John Murphy,
703 <murf@perftech.com> to Russ Nelson: Even with full-sized
704 buffers it's possible for a jabber packet to use two
705 buffers, with only the last correctly noting the error. */
706 if (status & RF_ENP)
707 /* Only count a general error at the end of a packet.*/
038eddd9 708 dev->stats.rx_errors++;
1da177e4 709 if (status & RF_FRAM)
038eddd9 710 dev->stats.rx_frame_errors++;
1da177e4 711 if (status & RF_OFLO)
038eddd9 712 dev->stats.rx_over_errors++;
1da177e4 713 if (status & RF_CRC)
038eddd9 714 dev->stats.rx_crc_errors++;
1da177e4 715 if (status & RF_BUFF)
038eddd9 716 dev->stats.rx_fifo_errors++;
1da177e4
LT
717 priv->rx_ring[entry]->RMD1 &= 0xff00|RF_STP|RF_ENP;
718 } else {
719 /* Malloc up new buffer, compatible with net-3. */
720 short pkt_len = swapw(priv->rx_ring[entry]->RMD3);
721 struct sk_buff *skb;
722
723 skb = dev_alloc_skb(pkt_len+2);
724 if (skb == NULL) {
725 printk(KERN_WARNING "%s: Memory squeeze, deferring packet.\n",
726 dev->name);
727 for (i = 0; i < RX_RING_SIZE; i++)
728 if (lowb(priv->rx_ring[(entry+i) % RX_RING_SIZE]->RMD1) & RF_OWN)
729 break;
730
731 if (i > RX_RING_SIZE-2) {
038eddd9 732 dev->stats.rx_dropped++;
1da177e4
LT
733 priv->rx_ring[entry]->RMD1 |= RF_OWN;
734 priv->cur_rx++;
735 }
736 break;
737 }
738
739
1da177e4
LT
740 skb_reserve(skb,2); /* 16 byte align */
741 skb_put(skb,pkt_len); /* Make room */
8c7b7faa 742 skb_copy_to_linear_data(skb, (char *)priv->rx_buff[entry], pkt_len);
1da177e4
LT
743 skb->protocol=eth_type_trans(skb,dev);
744#if 0
0795af57
JP
745{
746 DECLARE_MAC_BUF(mac);
747
1da177e4
LT
748 printk(KERN_DEBUG "RX pkt type 0x%04x from ",
749 ((u_short *)skb->data)[6]);
750 {
1da177e4 751 u_char *ptr = &((u_char *)skb->data)[6];
0795af57 752 printk("%s", print_mac(mac, ptr));
1da177e4
LT
753 }
754 printk(" to ");
755 {
1da177e4 756 u_char *ptr = (u_char *)skb->data;
0795af57 757 printk("%s", print_mac(mac, ptr));
1da177e4
LT
758 }
759 printk(" data 0x%08x len %d\n", (int)skb->data, (int)skb->len);
0795af57 760}
1da177e4
LT
761#endif
762
763 netif_rx(skb);
764 dev->last_rx = jiffies;
038eddd9
PZ
765 dev->stats.rx_packets++;
766 dev->stats.rx_bytes += pkt_len;
1da177e4
LT
767 }
768
769 priv->rx_ring[entry]->RMD1 |= RF_OWN;
770 entry = (++priv->cur_rx) % RX_RING_SIZE;
771 }
772
773 priv->cur_rx = priv->cur_rx % RX_RING_SIZE;
774
775 /* We should check that at least two ring entries are free. If not,
776 we should free one and mark stats->rx_dropped++. */
777
778 return 0;
779}
780
781
782static struct net_device_stats *ariadne_get_stats(struct net_device *dev)
783{
1da177e4
LT
784 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
785 short saved_addr;
786 unsigned long flags;
787
788 local_irq_save(flags);
789 saved_addr = lance->RAP;
790 lance->RAP = CSR112; /* Missed Frame Count */
038eddd9 791 dev->stats.rx_missed_errors = swapw(lance->RDP);
1da177e4
LT
792 lance->RAP = saved_addr;
793 local_irq_restore(flags);
794
038eddd9 795 return &dev->stats;
1da177e4
LT
796}
797
798
799/* Set or clear the multicast filter for this adaptor.
800 num_addrs == -1 Promiscuous mode, receive all packets
801 num_addrs == 0 Normal mode, clear multicast list
802 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
803 best-effort filtering.
804 */
805static void set_multicast_list(struct net_device *dev)
806{
807 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
808
809 if (!netif_running(dev))
810 return;
811
812 netif_stop_queue(dev);
813
814 /* We take the simple way out and always enable promiscuous mode. */
815 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
816 lance->RDP = STOP; /* Temporarily stop the lance. */
817 ariadne_init_ring(dev);
818
819 if (dev->flags & IFF_PROMISC) {
1da177e4
LT
820 lance->RAP = CSR15; /* Mode Register */
821 lance->RDP = PROM; /* Set promiscuous mode */
822 } else {
823 short multicast_table[4];
824 int num_addrs = dev->mc_count;
825 int i;
826 /* We don't use the multicast table, but rely on upper-layer filtering. */
827 memset(multicast_table, (num_addrs == 0) ? 0 : -1,
828 sizeof(multicast_table));
829 for (i = 0; i < 4; i++) {
830 lance->RAP = CSR8+(i<<8); /* Logical Address Filter */
831 lance->RDP = swapw(multicast_table[i]);
832 }
833 lance->RAP = CSR15; /* Mode Register */
834 lance->RDP = 0x0000; /* Unset promiscuous mode */
835 }
836
837 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
838 lance->RDP = INEA|STRT|IDON; /* Resume normal operation. */
839
840 netif_wake_queue(dev);
841}
842
843
844static void __devexit ariadne_remove_one(struct zorro_dev *z)
845{
846 struct net_device *dev = zorro_get_drvdata(z);
847
848 unregister_netdev(dev);
849 release_mem_region(ZTWO_PADDR(dev->base_addr), sizeof(struct Am79C960));
850 release_mem_region(ZTWO_PADDR(dev->mem_start), ARIADNE_RAM_SIZE);
851 free_netdev(dev);
852}
853
854static int __init ariadne_init_module(void)
855{
33d8675e 856 return zorro_register_driver(&ariadne_driver);
1da177e4
LT
857}
858
859static void __exit ariadne_cleanup_module(void)
860{
861 zorro_unregister_driver(&ariadne_driver);
862}
863
864module_init(ariadne_init_module);
865module_exit(ariadne_cleanup_module);
866
867MODULE_LICENSE("GPL");