V4L/DVB (7861): mt312: Prefix functions only with mt312_, Add zl10313 to kconfig...
[linux-2.6/verdex.git] / drivers / net / ariadne.c
blob10f3a196be32b729c5ddb075d72f39a0c82199ff
1 /*
2 * Amiga Linux/m68k Ariadne Ethernet Driver
4 * © Copyright 1995-2003 by Geert Uytterhoeven (geert@linux-m68k.org)
5 * Peter De Schrijver (p2@mind.be)
7 * ---------------------------------------------------------------------------
9 * This program is based on
11 * lance.c: An AMD LANCE ethernet driver for linux.
12 * Written 1993-94 by Donald Becker.
14 * Am79C960: PCnet(tm)-ISA Single-Chip Ethernet Controller
15 * Advanced Micro Devices
16 * Publication #16907, Rev. B, Amendment/0, May 1994
18 * MC68230: Parallel Interface/Timer (PI/T)
19 * Motorola Semiconductors, December, 1983
21 * ---------------------------------------------------------------------------
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.
27 * ---------------------------------------------------------------------------
29 * The Ariadne is a Zorro-II board made by Village Tronic. It contains:
31 * - an Am79C960 PCnet-ISA Single-Chip Ethernet Controller with both
32 * 10BASE-2 (thin coax) and 10BASE-T (UTP) connectors
34 * - an MC68230 Parallel Interface/Timer configured as 2 parallel ports
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>
52 #include <asm/amigaints.h>
53 #include <asm/amigahw.h>
54 #include <asm/irq.h>
56 #include "ariadne.h"
59 #ifdef ARIADNE_DEBUG
60 int ariadne_debug = ARIADNE_DEBUG;
61 #else
62 int ariadne_debug = 1;
63 #endif
67 * Macros to Fix Endianness problems
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))
81 * Transmit/Receive Ring Definitions
84 #define TX_RING_SIZE 5
85 #define RX_RING_SIZE 16
87 #define PKT_BUF_SIZE 1520
91 * Private Device Data
94 struct 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. */
101 struct net_device_stats stats;
102 char tx_full;
107 * Structure Created in the Ariadne's RAM Buffer
110 struct lancedata {
111 struct TDRE tx_ring[TX_RING_SIZE];
112 struct RDRE rx_ring[RX_RING_SIZE];
113 u_short tx_buff[TX_RING_SIZE][PKT_BUF_SIZE/sizeof(u_short)];
114 u_short rx_buff[RX_RING_SIZE][PKT_BUF_SIZE/sizeof(u_short)];
117 static int ariadne_open(struct net_device *dev);
118 static void ariadne_init_ring(struct net_device *dev);
119 static int ariadne_start_xmit(struct sk_buff *skb, struct net_device *dev);
120 static void ariadne_tx_timeout(struct net_device *dev);
121 static int ariadne_rx(struct net_device *dev);
122 static void ariadne_reset(struct net_device *dev);
123 static irqreturn_t ariadne_interrupt(int irq, void *data);
124 static int ariadne_close(struct net_device *dev);
125 static struct net_device_stats *ariadne_get_stats(struct net_device *dev);
126 #ifdef HAVE_MULTICAST
127 static void set_multicast_list(struct net_device *dev);
128 #endif
131 static void memcpyw(volatile u_short *dest, u_short *src, int len)
133 while (len >= 2) {
134 *(dest++) = *(src++);
135 len -= 2;
137 if (len == 1)
138 *dest = (*(u_char *)src)<<8;
142 static int __devinit ariadne_init_one(struct zorro_dev *z,
143 const struct zorro_device_id *ent);
144 static void __devexit ariadne_remove_one(struct zorro_dev *z);
147 static struct zorro_device_id ariadne_zorro_tbl[] __devinitdata = {
148 { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE },
149 { 0 }
152 static struct zorro_driver ariadne_driver = {
153 .name = "ariadne",
154 .id_table = ariadne_zorro_tbl,
155 .probe = ariadne_init_one,
156 .remove = __devexit_p(ariadne_remove_one),
159 static int __devinit ariadne_init_one(struct zorro_dev *z,
160 const struct zorro_device_id *ent)
162 unsigned long board = z->resource.start;
163 unsigned long base_addr = board+ARIADNE_LANCE;
164 unsigned long mem_start = board+ARIADNE_RAM;
165 struct resource *r1, *r2;
166 struct net_device *dev;
167 struct ariadne_private *priv;
168 int err;
169 DECLARE_MAC_BUF(mac);
171 r1 = request_mem_region(base_addr, sizeof(struct Am79C960), "Am79C960");
172 if (!r1)
173 return -EBUSY;
174 r2 = request_mem_region(mem_start, ARIADNE_RAM_SIZE, "RAM");
175 if (!r2) {
176 release_resource(r1);
177 return -EBUSY;
180 dev = alloc_etherdev(sizeof(struct ariadne_private));
181 if (dev == NULL) {
182 release_resource(r1);
183 release_resource(r2);
184 return -ENOMEM;
187 priv = netdev_priv(dev);
189 r1->name = dev->name;
190 r2->name = dev->name;
192 dev->dev_addr[0] = 0x00;
193 dev->dev_addr[1] = 0x60;
194 dev->dev_addr[2] = 0x30;
195 dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
196 dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
197 dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
198 dev->base_addr = ZTWO_VADDR(base_addr);
199 dev->mem_start = ZTWO_VADDR(mem_start);
200 dev->mem_end = dev->mem_start+ARIADNE_RAM_SIZE;
202 dev->open = &ariadne_open;
203 dev->stop = &ariadne_close;
204 dev->hard_start_xmit = &ariadne_start_xmit;
205 dev->tx_timeout = &ariadne_tx_timeout;
206 dev->watchdog_timeo = 5*HZ;
207 dev->get_stats = &ariadne_get_stats;
208 dev->set_multicast_list = &set_multicast_list;
210 err = register_netdev(dev);
211 if (err) {
212 release_resource(r1);
213 release_resource(r2);
214 free_netdev(dev);
215 return err;
217 zorro_set_drvdata(z, dev);
219 printk(KERN_INFO "%s: Ariadne at 0x%08lx, Ethernet Address "
220 "%s\n", dev->name, board,
221 print_mac(mac, dev->dev_addr));
223 return 0;
227 static int ariadne_open(struct net_device *dev)
229 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
230 u_short in;
231 u_long version;
232 int i;
234 /* Reset the LANCE */
235 in = lance->Reset;
237 /* Stop the LANCE */
238 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
239 lance->RDP = STOP;
241 /* Check the LANCE version */
242 lance->RAP = CSR88; /* Chip ID */
243 version = swapw(lance->RDP);
244 lance->RAP = CSR89; /* Chip ID */
245 version |= swapw(lance->RDP)<<16;
246 if ((version & 0x00000fff) != 0x00000003) {
247 printk(KERN_WARNING "ariadne_open: Couldn't find AMD Ethernet Chip\n");
248 return -EAGAIN;
250 if ((version & 0x0ffff000) != 0x00003000) {
251 printk(KERN_WARNING "ariadne_open: Couldn't find Am79C960 (Wrong part "
252 "number = %ld)\n", (version & 0x0ffff000)>>12);
253 return -EAGAIN;
255 #if 0
256 printk(KERN_DEBUG "ariadne_open: Am79C960 (PCnet-ISA) Revision %ld\n",
257 (version & 0xf0000000)>>28);
258 #endif
260 ariadne_init_ring(dev);
262 /* Miscellaneous Stuff */
263 lance->RAP = CSR3; /* Interrupt Masks and Deferral Control */
264 lance->RDP = 0x0000;
265 lance->RAP = CSR4; /* Test and Features Control */
266 lance->RDP = DPOLL|APAD_XMT|MFCOM|RCVCCOM|TXSTRTM|JABM;
268 /* Set the Multicast Table */
269 lance->RAP = CSR8; /* Logical Address Filter, LADRF[15:0] */
270 lance->RDP = 0x0000;
271 lance->RAP = CSR9; /* Logical Address Filter, LADRF[31:16] */
272 lance->RDP = 0x0000;
273 lance->RAP = CSR10; /* Logical Address Filter, LADRF[47:32] */
274 lance->RDP = 0x0000;
275 lance->RAP = CSR11; /* Logical Address Filter, LADRF[63:48] */
276 lance->RDP = 0x0000;
278 /* Set the Ethernet Hardware Address */
279 lance->RAP = CSR12; /* Physical Address Register, PADR[15:0] */
280 lance->RDP = ((u_short *)&dev->dev_addr[0])[0];
281 lance->RAP = CSR13; /* Physical Address Register, PADR[31:16] */
282 lance->RDP = ((u_short *)&dev->dev_addr[0])[1];
283 lance->RAP = CSR14; /* Physical Address Register, PADR[47:32] */
284 lance->RDP = ((u_short *)&dev->dev_addr[0])[2];
286 /* Set the Init Block Mode */
287 lance->RAP = CSR15; /* Mode Register */
288 lance->RDP = 0x0000;
290 /* Set the Transmit Descriptor Ring Pointer */
291 lance->RAP = CSR30; /* Base Address of Transmit Ring */
292 lance->RDP = swloww(ARIADNE_RAM+offsetof(struct lancedata, tx_ring));
293 lance->RAP = CSR31; /* Base Address of transmit Ring */
294 lance->RDP = swhighw(ARIADNE_RAM+offsetof(struct lancedata, tx_ring));
296 /* Set the Receive Descriptor Ring Pointer */
297 lance->RAP = CSR24; /* Base Address of Receive Ring */
298 lance->RDP = swloww(ARIADNE_RAM+offsetof(struct lancedata, rx_ring));
299 lance->RAP = CSR25; /* Base Address of Receive Ring */
300 lance->RDP = swhighw(ARIADNE_RAM+offsetof(struct lancedata, rx_ring));
302 /* Set the Number of RX and TX Ring Entries */
303 lance->RAP = CSR76; /* Receive Ring Length */
304 lance->RDP = swapw(((u_short)-RX_RING_SIZE));
305 lance->RAP = CSR78; /* Transmit Ring Length */
306 lance->RDP = swapw(((u_short)-TX_RING_SIZE));
308 /* Enable Media Interface Port Auto Select (10BASE-2/10BASE-T) */
309 lance->RAP = ISACSR2; /* Miscellaneous Configuration */
310 lance->IDP = ASEL;
312 /* LED Control */
313 lance->RAP = ISACSR5; /* LED1 Status */
314 lance->IDP = PSE|XMTE;
315 lance->RAP = ISACSR6; /* LED2 Status */
316 lance->IDP = PSE|COLE;
317 lance->RAP = ISACSR7; /* LED3 Status */
318 lance->IDP = PSE|RCVE;
320 netif_start_queue(dev);
322 i = request_irq(IRQ_AMIGA_PORTS, ariadne_interrupt, IRQF_SHARED,
323 dev->name, dev);
324 if (i) return i;
326 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
327 lance->RDP = INEA|STRT;
329 return 0;
333 static void ariadne_init_ring(struct net_device *dev)
335 struct ariadne_private *priv = netdev_priv(dev);
336 volatile struct lancedata *lancedata = (struct lancedata *)dev->mem_start;
337 int i;
339 netif_stop_queue(dev);
341 priv->tx_full = 0;
342 priv->cur_rx = priv->cur_tx = 0;
343 priv->dirty_tx = 0;
345 /* Set up TX Ring */
346 for (i = 0; i < TX_RING_SIZE; i++) {
347 volatile struct TDRE *t = &lancedata->tx_ring[i];
348 t->TMD0 = swloww(ARIADNE_RAM+offsetof(struct lancedata, tx_buff[i]));
349 t->TMD1 = swhighw(ARIADNE_RAM+offsetof(struct lancedata, tx_buff[i])) |
350 TF_STP | TF_ENP;
351 t->TMD2 = swapw((u_short)-PKT_BUF_SIZE);
352 t->TMD3 = 0;
353 priv->tx_ring[i] = &lancedata->tx_ring[i];
354 priv->tx_buff[i] = lancedata->tx_buff[i];
355 #if 0
356 printk(KERN_DEBUG "TX Entry %2d at %p, Buf at %p\n", i,
357 &lancedata->tx_ring[i], lancedata->tx_buff[i]);
358 #endif
361 /* Set up RX Ring */
362 for (i = 0; i < RX_RING_SIZE; i++) {
363 volatile struct RDRE *r = &lancedata->rx_ring[i];
364 r->RMD0 = swloww(ARIADNE_RAM+offsetof(struct lancedata, rx_buff[i]));
365 r->RMD1 = swhighw(ARIADNE_RAM+offsetof(struct lancedata, rx_buff[i])) |
366 RF_OWN;
367 r->RMD2 = swapw((u_short)-PKT_BUF_SIZE);
368 r->RMD3 = 0x0000;
369 priv->rx_ring[i] = &lancedata->rx_ring[i];
370 priv->rx_buff[i] = lancedata->rx_buff[i];
371 #if 0
372 printk(KERN_DEBUG "RX Entry %2d at %p, Buf at %p\n", i,
373 &lancedata->rx_ring[i], lancedata->rx_buff[i]);
374 #endif
379 static int ariadne_close(struct net_device *dev)
381 struct ariadne_private *priv = netdev_priv(dev);
382 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
384 netif_stop_queue(dev);
386 lance->RAP = CSR112; /* Missed Frame Count */
387 priv->stats.rx_missed_errors = swapw(lance->RDP);
388 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
390 if (ariadne_debug > 1) {
391 printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n",
392 dev->name, lance->RDP);
393 printk(KERN_DEBUG "%s: %lu packets missed\n", dev->name,
394 priv->stats.rx_missed_errors);
397 /* We stop the LANCE here -- it occasionally polls memory if we don't. */
398 lance->RDP = STOP;
400 free_irq(IRQ_AMIGA_PORTS, dev);
402 return 0;
406 static inline void ariadne_reset(struct net_device *dev)
408 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
410 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
411 lance->RDP = STOP;
412 ariadne_init_ring(dev);
413 lance->RDP = INEA|STRT;
414 netif_start_queue(dev);
418 static irqreturn_t ariadne_interrupt(int irq, void *data)
420 struct net_device *dev = (struct net_device *)data;
421 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
422 struct ariadne_private *priv;
423 int csr0, boguscnt;
424 int handled = 0;
426 if (dev == NULL) {
427 printk(KERN_WARNING "ariadne_interrupt(): irq for unknown device.\n");
428 return IRQ_NONE;
431 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
433 if (!(lance->RDP & INTR)) /* Check if any interrupt has been */
434 return IRQ_NONE; /* generated by the board. */
436 priv = netdev_priv(dev);
438 boguscnt = 10;
439 while ((csr0 = lance->RDP) & (ERR|RINT|TINT) && --boguscnt >= 0) {
440 /* Acknowledge all of the current interrupt sources ASAP. */
441 lance->RDP = csr0 & ~(INEA|TDMD|STOP|STRT|INIT);
443 #if 0
444 if (ariadne_debug > 5) {
445 printk(KERN_DEBUG "%s: interrupt csr0=%#2.2x new csr=%#2.2x.",
446 dev->name, csr0, lance->RDP);
447 printk("[");
448 if (csr0 & INTR)
449 printk(" INTR");
450 if (csr0 & INEA)
451 printk(" INEA");
452 if (csr0 & RXON)
453 printk(" RXON");
454 if (csr0 & TXON)
455 printk(" TXON");
456 if (csr0 & TDMD)
457 printk(" TDMD");
458 if (csr0 & STOP)
459 printk(" STOP");
460 if (csr0 & STRT)
461 printk(" STRT");
462 if (csr0 & INIT)
463 printk(" INIT");
464 if (csr0 & ERR)
465 printk(" ERR");
466 if (csr0 & BABL)
467 printk(" BABL");
468 if (csr0 & CERR)
469 printk(" CERR");
470 if (csr0 & MISS)
471 printk(" MISS");
472 if (csr0 & MERR)
473 printk(" MERR");
474 if (csr0 & RINT)
475 printk(" RINT");
476 if (csr0 & TINT)
477 printk(" TINT");
478 if (csr0 & IDON)
479 printk(" IDON");
480 printk(" ]\n");
482 #endif
484 if (csr0 & RINT) { /* Rx interrupt */
485 handled = 1;
486 ariadne_rx(dev);
489 if (csr0 & TINT) { /* Tx-done interrupt */
490 int dirty_tx = priv->dirty_tx;
492 handled = 1;
493 while (dirty_tx < priv->cur_tx) {
494 int entry = dirty_tx % TX_RING_SIZE;
495 int status = lowb(priv->tx_ring[entry]->TMD1);
497 if (status & TF_OWN)
498 break; /* It still hasn't been Txed */
500 priv->tx_ring[entry]->TMD1 &= 0xff00;
502 if (status & TF_ERR) {
503 /* There was an major error, log it. */
504 int err_status = priv->tx_ring[entry]->TMD3;
505 priv->stats.tx_errors++;
506 if (err_status & EF_RTRY)
507 priv->stats.tx_aborted_errors++;
508 if (err_status & EF_LCAR)
509 priv->stats.tx_carrier_errors++;
510 if (err_status & EF_LCOL)
511 priv->stats.tx_window_errors++;
512 if (err_status & EF_UFLO) {
513 /* Ackk! On FIFO errors the Tx unit is turned off! */
514 priv->stats.tx_fifo_errors++;
515 /* Remove this verbosity later! */
516 printk(KERN_ERR "%s: Tx FIFO error! Status %4.4x.\n",
517 dev->name, csr0);
518 /* Restart the chip. */
519 lance->RDP = STRT;
521 } else {
522 if (status & (TF_MORE|TF_ONE))
523 priv->stats.collisions++;
524 priv->stats.tx_packets++;
526 dirty_tx++;
529 #ifndef final_version
530 if (priv->cur_tx - dirty_tx >= TX_RING_SIZE) {
531 printk(KERN_ERR "out-of-sync dirty pointer, %d vs. %d, "
532 "full=%d.\n", dirty_tx, priv->cur_tx, priv->tx_full);
533 dirty_tx += TX_RING_SIZE;
535 #endif
537 if (priv->tx_full && netif_queue_stopped(dev) &&
538 dirty_tx > priv->cur_tx - TX_RING_SIZE + 2) {
539 /* The ring is no longer full. */
540 priv->tx_full = 0;
541 netif_wake_queue(dev);
544 priv->dirty_tx = dirty_tx;
547 /* Log misc errors. */
548 if (csr0 & BABL) {
549 handled = 1;
550 priv->stats.tx_errors++; /* Tx babble. */
552 if (csr0 & MISS) {
553 handled = 1;
554 priv->stats.rx_errors++; /* Missed a Rx frame. */
556 if (csr0 & MERR) {
557 handled = 1;
558 printk(KERN_ERR "%s: Bus master arbitration failure, status "
559 "%4.4x.\n", dev->name, csr0);
560 /* Restart the chip. */
561 lance->RDP = STRT;
565 /* Clear any other interrupt, and set interrupt enable. */
566 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
567 lance->RDP = INEA|BABL|CERR|MISS|MERR|IDON;
569 #if 0
570 if (ariadne_debug > 4)
571 printk(KERN_DEBUG "%s: exiting interrupt, csr%d=%#4.4x.\n", dev->name,
572 lance->RAP, lance->RDP);
573 #endif
574 return IRQ_RETVAL(handled);
578 static void ariadne_tx_timeout(struct net_device *dev)
580 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
582 printk(KERN_ERR "%s: transmit timed out, status %4.4x, resetting.\n",
583 dev->name, lance->RDP);
584 ariadne_reset(dev);
585 netif_wake_queue(dev);
589 static int ariadne_start_xmit(struct sk_buff *skb, struct net_device *dev)
591 struct ariadne_private *priv = netdev_priv(dev);
592 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
593 int entry;
594 unsigned long flags;
595 int len = skb->len;
597 #if 0
598 if (ariadne_debug > 3) {
599 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
600 printk(KERN_DEBUG "%s: ariadne_start_xmit() called, csr0 %4.4x.\n",
601 dev->name, lance->RDP);
602 lance->RDP = 0x0000;
604 #endif
606 /* FIXME: is the 79C960 new enough to do its own padding right ? */
607 if (skb->len < ETH_ZLEN)
609 if (skb_padto(skb, ETH_ZLEN))
610 return 0;
611 len = ETH_ZLEN;
614 /* Fill in a Tx ring entry */
616 #if 0
618 DECLARE_MAC_BUF(mac);
619 DECLARE_MAC_BUF(mac2);
621 printk(KERN_DEBUG "TX pkt type 0x%04x from %s to %s "
622 " data 0x%08x len %d\n",
623 ((u_short *)skb->data)[6],
624 print_mac(mac, ((const u8 *)skb->data)+6),
625 print_mac(mac, (const u8 *)skb->data),
626 (int)skb->data, (int)skb->len);
628 #endif
630 local_irq_save(flags);
632 entry = priv->cur_tx % TX_RING_SIZE;
634 /* Caution: the write order is important here, set the base address with
635 the "ownership" bits last. */
637 priv->tx_ring[entry]->TMD2 = swapw((u_short)-skb->len);
638 priv->tx_ring[entry]->TMD3 = 0x0000;
639 memcpyw(priv->tx_buff[entry], (u_short *)skb->data, len);
641 #if 0
643 int i, len;
645 len = skb->len > 64 ? 64 : skb->len;
646 len >>= 1;
647 for (i = 0; i < len; i += 8) {
648 int j;
649 printk(KERN_DEBUG "%04x:", i);
650 for (j = 0; (j < 8) && ((i+j) < len); j++) {
651 if (!(j & 1))
652 printk(" ");
653 printk("%04x", priv->tx_buff[entry][i+j]);
655 printk("\n");
658 #endif
660 priv->tx_ring[entry]->TMD1 = (priv->tx_ring[entry]->TMD1&0xff00)|TF_OWN|TF_STP|TF_ENP;
662 dev_kfree_skb(skb);
664 priv->cur_tx++;
665 if ((priv->cur_tx >= TX_RING_SIZE) && (priv->dirty_tx >= TX_RING_SIZE)) {
667 #if 0
668 printk(KERN_DEBUG "*** Subtracting TX_RING_SIZE from cur_tx (%d) and "
669 "dirty_tx (%d)\n", priv->cur_tx, priv->dirty_tx);
670 #endif
672 priv->cur_tx -= TX_RING_SIZE;
673 priv->dirty_tx -= TX_RING_SIZE;
675 priv->stats.tx_bytes += len;
677 /* Trigger an immediate send poll. */
678 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
679 lance->RDP = INEA|TDMD;
681 dev->trans_start = jiffies;
683 if (lowb(priv->tx_ring[(entry+1) % TX_RING_SIZE]->TMD1) != 0) {
684 netif_stop_queue(dev);
685 priv->tx_full = 1;
687 local_irq_restore(flags);
689 return 0;
693 static int ariadne_rx(struct net_device *dev)
695 struct ariadne_private *priv = netdev_priv(dev);
696 int entry = priv->cur_rx % RX_RING_SIZE;
697 int i;
699 /* If we own the next entry, it's a new packet. Send it up. */
700 while (!(lowb(priv->rx_ring[entry]->RMD1) & RF_OWN)) {
701 int status = lowb(priv->rx_ring[entry]->RMD1);
703 if (status != (RF_STP|RF_ENP)) { /* There was an error. */
704 /* There is a tricky error noted by John Murphy,
705 <murf@perftech.com> to Russ Nelson: Even with full-sized
706 buffers it's possible for a jabber packet to use two
707 buffers, with only the last correctly noting the error. */
708 if (status & RF_ENP)
709 /* Only count a general error at the end of a packet.*/
710 priv->stats.rx_errors++;
711 if (status & RF_FRAM)
712 priv->stats.rx_frame_errors++;
713 if (status & RF_OFLO)
714 priv->stats.rx_over_errors++;
715 if (status & RF_CRC)
716 priv->stats.rx_crc_errors++;
717 if (status & RF_BUFF)
718 priv->stats.rx_fifo_errors++;
719 priv->rx_ring[entry]->RMD1 &= 0xff00|RF_STP|RF_ENP;
720 } else {
721 /* Malloc up new buffer, compatible with net-3. */
722 short pkt_len = swapw(priv->rx_ring[entry]->RMD3);
723 struct sk_buff *skb;
725 skb = dev_alloc_skb(pkt_len+2);
726 if (skb == NULL) {
727 printk(KERN_WARNING "%s: Memory squeeze, deferring packet.\n",
728 dev->name);
729 for (i = 0; i < RX_RING_SIZE; i++)
730 if (lowb(priv->rx_ring[(entry+i) % RX_RING_SIZE]->RMD1) & RF_OWN)
731 break;
733 if (i > RX_RING_SIZE-2) {
734 priv->stats.rx_dropped++;
735 priv->rx_ring[entry]->RMD1 |= RF_OWN;
736 priv->cur_rx++;
738 break;
742 skb_reserve(skb,2); /* 16 byte align */
743 skb_put(skb,pkt_len); /* Make room */
744 skb_copy_to_linear_data(skb, (char *)priv->rx_buff[entry], pkt_len);
745 skb->protocol=eth_type_trans(skb,dev);
746 #if 0
748 DECLARE_MAC_BUF(mac);
750 printk(KERN_DEBUG "RX pkt type 0x%04x from ",
751 ((u_short *)skb->data)[6]);
753 u_char *ptr = &((u_char *)skb->data)[6];
754 printk("%s", print_mac(mac, ptr));
756 printk(" to ");
758 u_char *ptr = (u_char *)skb->data;
759 printk("%s", print_mac(mac, ptr));
761 printk(" data 0x%08x len %d\n", (int)skb->data, (int)skb->len);
763 #endif
765 netif_rx(skb);
766 dev->last_rx = jiffies;
767 priv->stats.rx_packets++;
768 priv->stats.rx_bytes += pkt_len;
771 priv->rx_ring[entry]->RMD1 |= RF_OWN;
772 entry = (++priv->cur_rx) % RX_RING_SIZE;
775 priv->cur_rx = priv->cur_rx % RX_RING_SIZE;
777 /* We should check that at least two ring entries are free. If not,
778 we should free one and mark stats->rx_dropped++. */
780 return 0;
784 static struct net_device_stats *ariadne_get_stats(struct net_device *dev)
786 struct ariadne_private *priv = netdev_priv(dev);
787 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
788 short saved_addr;
789 unsigned long flags;
791 local_irq_save(flags);
792 saved_addr = lance->RAP;
793 lance->RAP = CSR112; /* Missed Frame Count */
794 priv->stats.rx_missed_errors = swapw(lance->RDP);
795 lance->RAP = saved_addr;
796 local_irq_restore(flags);
798 return &priv->stats;
802 /* Set or clear the multicast filter for this adaptor.
803 num_addrs == -1 Promiscuous mode, receive all packets
804 num_addrs == 0 Normal mode, clear multicast list
805 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
806 best-effort filtering.
808 static void set_multicast_list(struct net_device *dev)
810 volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
812 if (!netif_running(dev))
813 return;
815 netif_stop_queue(dev);
817 /* We take the simple way out and always enable promiscuous mode. */
818 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
819 lance->RDP = STOP; /* Temporarily stop the lance. */
820 ariadne_init_ring(dev);
822 if (dev->flags & IFF_PROMISC) {
823 lance->RAP = CSR15; /* Mode Register */
824 lance->RDP = PROM; /* Set promiscuous mode */
825 } else {
826 short multicast_table[4];
827 int num_addrs = dev->mc_count;
828 int i;
829 /* We don't use the multicast table, but rely on upper-layer filtering. */
830 memset(multicast_table, (num_addrs == 0) ? 0 : -1,
831 sizeof(multicast_table));
832 for (i = 0; i < 4; i++) {
833 lance->RAP = CSR8+(i<<8); /* Logical Address Filter */
834 lance->RDP = swapw(multicast_table[i]);
836 lance->RAP = CSR15; /* Mode Register */
837 lance->RDP = 0x0000; /* Unset promiscuous mode */
840 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
841 lance->RDP = INEA|STRT|IDON; /* Resume normal operation. */
843 netif_wake_queue(dev);
847 static void __devexit ariadne_remove_one(struct zorro_dev *z)
849 struct net_device *dev = zorro_get_drvdata(z);
851 unregister_netdev(dev);
852 release_mem_region(ZTWO_PADDR(dev->base_addr), sizeof(struct Am79C960));
853 release_mem_region(ZTWO_PADDR(dev->mem_start), ARIADNE_RAM_SIZE);
854 free_netdev(dev);
857 static int __init ariadne_init_module(void)
859 return zorro_register_driver(&ariadne_driver);
862 static void __exit ariadne_cleanup_module(void)
864 zorro_unregister_driver(&ariadne_driver);
867 module_init(ariadne_init_module);
868 module_exit(ariadne_cleanup_module);
870 MODULE_LICENSE("GPL");