• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/drivers/net/
1/*
2 *  Amiga Linux/m68k Ariadne Ethernet Driver
3 *
4 *  �� Copyright 1995-2003 by Geert Uytterhoeven (geert@linux-m68k.org)
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/netdevice.h>
44#include <linux/etherdevice.h>
45#include <linux/interrupt.h>
46#include <linux/skbuff.h>
47#include <linux/init.h>
48#include <linux/zorro.h>
49#include <linux/bitops.h>
50
51#include <asm/amigaints.h>
52#include <asm/amigahw.h>
53#include <asm/irq.h>
54
55#include "ariadne.h"
56
57
58#ifdef ARIADNE_DEBUG
59int ariadne_debug = ARIADNE_DEBUG;
60#else
61int ariadne_debug = 1;
62#endif
63
64
65    /*
66     *	Macros to Fix Endianness problems
67     */
68
69				/* Swap the Bytes in a WORD */
70#define swapw(x)	(((x>>8)&0x00ff)|((x<<8)&0xff00))
71				/* Get the Low BYTE in a WORD */
72#define lowb(x)		(x&0xff)
73				/* Get the Swapped High WORD in a LONG */
74#define swhighw(x)	((((x)>>8)&0xff00)|(((x)>>24)&0x00ff))
75				/* Get the Swapped Low WORD in a LONG */
76#define swloww(x)	((((x)<<8)&0xff00)|(((x)>>8)&0x00ff))
77
78
79    /*
80     *	Transmit/Receive Ring Definitions
81     */
82
83#define TX_RING_SIZE	5
84#define RX_RING_SIZE	16
85
86#define PKT_BUF_SIZE	1520
87
88
89    /*
90     *	Private Device Data
91     */
92
93struct ariadne_private {
94    volatile struct TDRE *tx_ring[TX_RING_SIZE];
95    volatile struct RDRE *rx_ring[RX_RING_SIZE];
96    volatile u_short *tx_buff[TX_RING_SIZE];
97    volatile u_short *rx_buff[RX_RING_SIZE];
98    int cur_tx, cur_rx;			/* The next free ring entry */
99    int dirty_tx;			/* The ring entries to be free()ed. */
100    char tx_full;
101};
102
103
104    /*
105     *	Structure Created in the Ariadne's RAM Buffer
106     */
107
108struct lancedata {
109    struct TDRE tx_ring[TX_RING_SIZE];
110    struct RDRE rx_ring[RX_RING_SIZE];
111    u_short tx_buff[TX_RING_SIZE][PKT_BUF_SIZE/sizeof(u_short)];
112    u_short rx_buff[RX_RING_SIZE][PKT_BUF_SIZE/sizeof(u_short)];
113};
114
115static int ariadne_open(struct net_device *dev);
116static void ariadne_init_ring(struct net_device *dev);
117static netdev_tx_t ariadne_start_xmit(struct sk_buff *skb,
118				      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);
122static irqreturn_t ariadne_interrupt(int irq, void *data);
123static int ariadne_close(struct net_device *dev);
124static struct net_device_stats *ariadne_get_stats(struct net_device *dev);
125static void set_multicast_list(struct net_device *dev);
126
127
128static void memcpyw(volatile u_short *dest, u_short *src, int len)
129{
130    while (len >= 2) {
131	*(dest++) = *(src++);
132	len -= 2;
133    }
134    if (len == 1)
135	*dest = (*(u_char *)src)<<8;
136}
137
138
139static int __devinit ariadne_init_one(struct zorro_dev *z,
140				      const struct zorro_device_id *ent);
141static void __devexit ariadne_remove_one(struct zorro_dev *z);
142
143
144static struct zorro_device_id ariadne_zorro_tbl[] __devinitdata = {
145    { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE },
146    { 0 }
147};
148MODULE_DEVICE_TABLE(zorro, ariadne_zorro_tbl);
149
150static struct zorro_driver ariadne_driver = {
151    .name	= "ariadne",
152    .id_table	= ariadne_zorro_tbl,
153    .probe	= ariadne_init_one,
154    .remove	= __devexit_p(ariadne_remove_one),
155};
156
157static const struct net_device_ops ariadne_netdev_ops = {
158	.ndo_open		= ariadne_open,
159	.ndo_stop		= ariadne_close,
160	.ndo_start_xmit		= ariadne_start_xmit,
161	.ndo_tx_timeout		= ariadne_tx_timeout,
162	.ndo_get_stats		= ariadne_get_stats,
163	.ndo_set_multicast_list	= set_multicast_list,
164	.ndo_validate_addr	= eth_validate_addr,
165	.ndo_change_mtu		= eth_change_mtu,
166	.ndo_set_mac_address	= eth_mac_addr,
167};
168
169static int __devinit ariadne_init_one(struct zorro_dev *z,
170				      const struct zorro_device_id *ent)
171{
172    unsigned long board = z->resource.start;
173    unsigned long base_addr = board+ARIADNE_LANCE;
174    unsigned long mem_start = board+ARIADNE_RAM;
175    struct resource *r1, *r2;
176    struct net_device *dev;
177    struct ariadne_private *priv;
178    int err;
179
180    r1 = request_mem_region(base_addr, sizeof(struct Am79C960), "Am79C960");
181    if (!r1)
182	return -EBUSY;
183    r2 = request_mem_region(mem_start, ARIADNE_RAM_SIZE, "RAM");
184    if (!r2) {
185	release_resource(r1);
186	return -EBUSY;
187    }
188
189    dev = alloc_etherdev(sizeof(struct ariadne_private));
190    if (dev == NULL) {
191	release_resource(r1);
192	release_resource(r2);
193	return -ENOMEM;
194    }
195
196    priv = netdev_priv(dev);
197
198    r1->name = dev->name;
199    r2->name = dev->name;
200
201    dev->dev_addr[0] = 0x00;
202    dev->dev_addr[1] = 0x60;
203    dev->dev_addr[2] = 0x30;
204    dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
205    dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
206    dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
207    dev->base_addr = ZTWO_VADDR(base_addr);
208    dev->mem_start = ZTWO_VADDR(mem_start);
209    dev->mem_end = dev->mem_start+ARIADNE_RAM_SIZE;
210
211    dev->netdev_ops = &ariadne_netdev_ops;
212    dev->watchdog_timeo = 5*HZ;
213
214    err = register_netdev(dev);
215    if (err) {
216	release_resource(r1);
217	release_resource(r2);
218	free_netdev(dev);
219	return err;
220    }
221    zorro_set_drvdata(z, dev);
222
223    printk(KERN_INFO "%s: Ariadne at 0x%08lx, Ethernet Address %pM\n",
224           dev->name, board, dev->dev_addr);
225
226    return 0;
227}
228
229
230static int ariadne_open(struct net_device *dev)
231{
232    volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
233    u_short in;
234    u_long version;
235    int i;
236
237    /* Reset the LANCE */
238    in = lance->Reset;
239
240    /* Stop the LANCE */
241    lance->RAP = CSR0;		/* PCnet-ISA Controller Status */
242    lance->RDP = STOP;
243
244    /* Check the LANCE version */
245    lance->RAP = CSR88;		/* Chip ID */
246    version = swapw(lance->RDP);
247    lance->RAP = CSR89;		/* Chip ID */
248    version |= swapw(lance->RDP)<<16;
249    if ((version & 0x00000fff) != 0x00000003) {
250	printk(KERN_WARNING "ariadne_open: Couldn't find AMD Ethernet Chip\n");
251	return -EAGAIN;
252    }
253    if ((version & 0x0ffff000) != 0x00003000) {
254	printk(KERN_WARNING "ariadne_open: Couldn't find Am79C960 (Wrong part "
255	       "number = %ld)\n", (version & 0x0ffff000)>>12);
256	return -EAGAIN;
257    }
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
321    i = request_irq(IRQ_AMIGA_PORTS, ariadne_interrupt, IRQF_SHARED,
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    }
355
356    /* Set up RX Ring */
357    for (i = 0; i < RX_RING_SIZE; i++) {
358	volatile struct RDRE *r = &lancedata->rx_ring[i];
359	r->RMD0 = swloww(ARIADNE_RAM+offsetof(struct lancedata, rx_buff[i]));
360	r->RMD1 = swhighw(ARIADNE_RAM+offsetof(struct lancedata, rx_buff[i])) |
361		  RF_OWN;
362	r->RMD2 = swapw((u_short)-PKT_BUF_SIZE);
363	r->RMD3 = 0x0000;
364	priv->rx_ring[i] = &lancedata->rx_ring[i];
365	priv->rx_buff[i] = lancedata->rx_buff[i];
366    }
367}
368
369
370static int ariadne_close(struct net_device *dev)
371{
372    volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
373
374    netif_stop_queue(dev);
375
376    lance->RAP = CSR112;	/* Missed Frame Count */
377    dev->stats.rx_missed_errors = swapw(lance->RDP);
378    lance->RAP = CSR0;		/* PCnet-ISA Controller Status */
379
380    if (ariadne_debug > 1) {
381	printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n",
382	       dev->name, lance->RDP);
383	printk(KERN_DEBUG "%s: %lu packets missed\n", dev->name,
384	       dev->stats.rx_missed_errors);
385    }
386
387    /* We stop the LANCE here -- it occasionally polls memory if we don't. */
388    lance->RDP = STOP;
389
390    free_irq(IRQ_AMIGA_PORTS, dev);
391
392    return 0;
393}
394
395
396static inline void ariadne_reset(struct net_device *dev)
397{
398    volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
399
400    lance->RAP = CSR0;	/* PCnet-ISA Controller Status */
401    lance->RDP = STOP;
402    ariadne_init_ring(dev);
403    lance->RDP = INEA|STRT;
404    netif_start_queue(dev);
405}
406
407
408static irqreturn_t ariadne_interrupt(int irq, void *data)
409{
410    struct net_device *dev = (struct net_device *)data;
411    volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
412    struct ariadne_private *priv;
413    int csr0, boguscnt;
414    int handled = 0;
415
416    if (dev == NULL) {
417	printk(KERN_WARNING "ariadne_interrupt(): irq for unknown device.\n");
418	return IRQ_NONE;
419    }
420
421    lance->RAP = CSR0;			/* PCnet-ISA Controller Status */
422
423    if (!(lance->RDP & INTR))		/* Check if any interrupt has been */
424	return IRQ_NONE;		/* generated by the board. */
425
426    priv = netdev_priv(dev);
427
428    boguscnt = 10;
429    while ((csr0 = lance->RDP) & (ERR|RINT|TINT) && --boguscnt >= 0) {
430	/* Acknowledge all of the current interrupt sources ASAP. */
431	lance->RDP = csr0 & ~(INEA|TDMD|STOP|STRT|INIT);
432
433
434	if (csr0 & RINT) {	/* Rx interrupt */
435	    handled = 1;
436	    ariadne_rx(dev);
437	}
438
439	if (csr0 & TINT) {	/* Tx-done interrupt */
440	    int dirty_tx = priv->dirty_tx;
441
442	    handled = 1;
443	    while (dirty_tx < priv->cur_tx) {
444		int entry = dirty_tx % TX_RING_SIZE;
445		int status = lowb(priv->tx_ring[entry]->TMD1);
446
447		if (status & TF_OWN)
448		    break;	/* It still hasn't been Txed */
449
450		priv->tx_ring[entry]->TMD1 &= 0xff00;
451
452		if (status & TF_ERR) {
453		    /* There was an major error, log it. */
454		    int err_status = priv->tx_ring[entry]->TMD3;
455		    dev->stats.tx_errors++;
456		    if (err_status & EF_RTRY)
457			dev->stats.tx_aborted_errors++;
458		    if (err_status & EF_LCAR)
459			dev->stats.tx_carrier_errors++;
460		    if (err_status & EF_LCOL)
461			dev->stats.tx_window_errors++;
462		    if (err_status & EF_UFLO) {
463			/* Ackk!  On FIFO errors the Tx unit is turned off! */
464			dev->stats.tx_fifo_errors++;
465			/* Remove this verbosity later! */
466			printk(KERN_ERR "%s: Tx FIFO error! Status %4.4x.\n",
467			       dev->name, csr0);
468			/* Restart the chip. */
469			lance->RDP = STRT;
470		    }
471		} else {
472		    if (status & (TF_MORE|TF_ONE))
473			dev->stats.collisions++;
474		    dev->stats.tx_packets++;
475		}
476		dirty_tx++;
477	    }
478
479#ifndef final_version
480	    if (priv->cur_tx - dirty_tx >= TX_RING_SIZE) {
481		printk(KERN_ERR "out-of-sync dirty pointer, %d vs. %d, "
482		       "full=%d.\n", dirty_tx, priv->cur_tx, priv->tx_full);
483		dirty_tx += TX_RING_SIZE;
484	    }
485#endif
486
487	    if (priv->tx_full && netif_queue_stopped(dev) &&
488		dirty_tx > priv->cur_tx - TX_RING_SIZE + 2) {
489		/* The ring is no longer full. */
490		priv->tx_full = 0;
491		netif_wake_queue(dev);
492	    }
493
494	    priv->dirty_tx = dirty_tx;
495	}
496
497	/* Log misc errors. */
498	if (csr0 & BABL) {
499	    handled = 1;
500	    dev->stats.tx_errors++;	/* Tx babble. */
501	}
502	if (csr0 & MISS) {
503	    handled = 1;
504	    dev->stats.rx_errors++;	/* Missed a Rx frame. */
505	}
506	if (csr0 & MERR) {
507	    handled = 1;
508	    printk(KERN_ERR "%s: Bus master arbitration failure, status "
509		   "%4.4x.\n", dev->name, csr0);
510	    /* Restart the chip. */
511	    lance->RDP = STRT;
512	}
513    }
514
515    /* Clear any other interrupt, and set interrupt enable. */
516    lance->RAP = CSR0;		/* PCnet-ISA Controller Status */
517    lance->RDP = INEA|BABL|CERR|MISS|MERR|IDON;
518
519    return IRQ_RETVAL(handled);
520}
521
522
523static void ariadne_tx_timeout(struct net_device *dev)
524{
525    volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
526
527    printk(KERN_ERR "%s: transmit timed out, status %4.4x, resetting.\n",
528	   dev->name, lance->RDP);
529    ariadne_reset(dev);
530    netif_wake_queue(dev);
531}
532
533
534static netdev_tx_t ariadne_start_xmit(struct sk_buff *skb,
535				      struct net_device *dev)
536{
537    struct ariadne_private *priv = netdev_priv(dev);
538    volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
539    int entry;
540    unsigned long flags;
541    int len = skb->len;
542
543
544    if (skb->len < ETH_ZLEN)
545    {
546    	if (skb_padto(skb, ETH_ZLEN))
547    	    return NETDEV_TX_OK;
548    	len = ETH_ZLEN;
549    }
550
551    /* Fill in a Tx ring entry */
552
553
554    local_irq_save(flags);
555
556    entry = priv->cur_tx % TX_RING_SIZE;
557
558    /* Caution: the write order is important here, set the base address with
559		the "ownership" bits last. */
560
561    priv->tx_ring[entry]->TMD2 = swapw((u_short)-skb->len);
562    priv->tx_ring[entry]->TMD3 = 0x0000;
563    memcpyw(priv->tx_buff[entry], (u_short *)skb->data, len);
564
565
566    priv->tx_ring[entry]->TMD1 = (priv->tx_ring[entry]->TMD1&0xff00)|TF_OWN|TF_STP|TF_ENP;
567
568    dev_kfree_skb(skb);
569
570    priv->cur_tx++;
571    if ((priv->cur_tx >= TX_RING_SIZE) && (priv->dirty_tx >= TX_RING_SIZE)) {
572
573
574	priv->cur_tx -= TX_RING_SIZE;
575	priv->dirty_tx -= TX_RING_SIZE;
576    }
577    dev->stats.tx_bytes += len;
578
579    /* Trigger an immediate send poll. */
580    lance->RAP = CSR0;		/* PCnet-ISA Controller Status */
581    lance->RDP = INEA|TDMD;
582
583    if (lowb(priv->tx_ring[(entry+1) % TX_RING_SIZE]->TMD1) != 0) {
584	netif_stop_queue(dev);
585	priv->tx_full = 1;
586    }
587    local_irq_restore(flags);
588
589    return NETDEV_TX_OK;
590}
591
592
593static int ariadne_rx(struct net_device *dev)
594{
595    struct ariadne_private *priv = netdev_priv(dev);
596    int entry = priv->cur_rx % RX_RING_SIZE;
597    int i;
598
599    /* If we own the next entry, it's a new packet. Send it up. */
600    while (!(lowb(priv->rx_ring[entry]->RMD1) & RF_OWN)) {
601	int status = lowb(priv->rx_ring[entry]->RMD1);
602
603	if (status != (RF_STP|RF_ENP)) {	/* There was an error. */
604	    /* There is a tricky error noted by John Murphy,
605		<murf@perftech.com> to Russ Nelson: Even with full-sized
606		buffers it's possible for a jabber packet to use two
607		buffers, with only the last correctly noting the error. */
608	    if (status & RF_ENP)
609		/* Only count a general error at the end of a packet.*/
610		dev->stats.rx_errors++;
611	    if (status & RF_FRAM)
612		dev->stats.rx_frame_errors++;
613	    if (status & RF_OFLO)
614		dev->stats.rx_over_errors++;
615	    if (status & RF_CRC)
616		dev->stats.rx_crc_errors++;
617	    if (status & RF_BUFF)
618		dev->stats.rx_fifo_errors++;
619	    priv->rx_ring[entry]->RMD1 &= 0xff00|RF_STP|RF_ENP;
620	} else {
621	    /* Malloc up new buffer, compatible with net-3. */
622	    short pkt_len = swapw(priv->rx_ring[entry]->RMD3);
623	    struct sk_buff *skb;
624
625	    skb = dev_alloc_skb(pkt_len+2);
626	    if (skb == NULL) {
627		printk(KERN_WARNING "%s: Memory squeeze, deferring packet.\n",
628		       dev->name);
629		for (i = 0; i < RX_RING_SIZE; i++)
630		    if (lowb(priv->rx_ring[(entry+i) % RX_RING_SIZE]->RMD1) & RF_OWN)
631			break;
632
633		if (i > RX_RING_SIZE-2) {
634		    dev->stats.rx_dropped++;
635		    priv->rx_ring[entry]->RMD1 |= RF_OWN;
636		    priv->cur_rx++;
637		}
638		break;
639	    }
640
641
642	    skb_reserve(skb,2);		/* 16 byte align */
643	    skb_put(skb,pkt_len);	/* Make room */
644	    skb_copy_to_linear_data(skb, (char *)priv->rx_buff[entry], pkt_len);
645	    skb->protocol=eth_type_trans(skb,dev);
646
647	    netif_rx(skb);
648	    dev->stats.rx_packets++;
649	    dev->stats.rx_bytes += pkt_len;
650	}
651
652	priv->rx_ring[entry]->RMD1 |= RF_OWN;
653	entry = (++priv->cur_rx) % RX_RING_SIZE;
654    }
655
656    priv->cur_rx = priv->cur_rx % RX_RING_SIZE;
657
658    /* We should check that at least two ring entries are free.	 If not,
659       we should free one and mark stats->rx_dropped++. */
660
661    return 0;
662}
663
664
665static struct net_device_stats *ariadne_get_stats(struct net_device *dev)
666{
667    volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
668    short saved_addr;
669    unsigned long flags;
670
671    local_irq_save(flags);
672    saved_addr = lance->RAP;
673    lance->RAP = CSR112;		/* Missed Frame Count */
674    dev->stats.rx_missed_errors = swapw(lance->RDP);
675    lance->RAP = saved_addr;
676    local_irq_restore(flags);
677
678    return &dev->stats;
679}
680
681
682/* Set or clear the multicast filter for this adaptor.
683    num_addrs == -1	Promiscuous mode, receive all packets
684    num_addrs == 0	Normal mode, clear multicast list
685    num_addrs > 0	Multicast mode, receive normal and MC packets, and do
686			best-effort filtering.
687 */
688static void set_multicast_list(struct net_device *dev)
689{
690    volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
691
692    if (!netif_running(dev))
693	return;
694
695    netif_stop_queue(dev);
696
697    /* We take the simple way out and always enable promiscuous mode. */
698    lance->RAP = CSR0;			/* PCnet-ISA Controller Status */
699    lance->RDP = STOP;			/* Temporarily stop the lance. */
700    ariadne_init_ring(dev);
701
702    if (dev->flags & IFF_PROMISC) {
703	lance->RAP = CSR15;		/* Mode Register */
704	lance->RDP = PROM;		/* Set promiscuous mode */
705    } else {
706	short multicast_table[4];
707	int num_addrs = netdev_mc_count(dev);
708	int i;
709	/* We don't use the multicast table, but rely on upper-layer filtering. */
710	memset(multicast_table, (num_addrs == 0) ? 0 : -1,
711	       sizeof(multicast_table));
712	for (i = 0; i < 4; i++) {
713	    lance->RAP = CSR8+(i<<8);	/* Logical Address Filter */
714	    lance->RDP = swapw(multicast_table[i]);
715	}
716	lance->RAP = CSR15;		/* Mode Register */
717	lance->RDP = 0x0000;		/* Unset promiscuous mode */
718    }
719
720    lance->RAP = CSR0;			/* PCnet-ISA Controller Status */
721    lance->RDP = INEA|STRT|IDON;	/* Resume normal operation. */
722
723    netif_wake_queue(dev);
724}
725
726
727static void __devexit ariadne_remove_one(struct zorro_dev *z)
728{
729    struct net_device *dev = zorro_get_drvdata(z);
730
731    unregister_netdev(dev);
732    release_mem_region(ZTWO_PADDR(dev->base_addr), sizeof(struct Am79C960));
733    release_mem_region(ZTWO_PADDR(dev->mem_start), ARIADNE_RAM_SIZE);
734    free_netdev(dev);
735}
736
737static int __init ariadne_init_module(void)
738{
739    return zorro_register_driver(&ariadne_driver);
740}
741
742static void __exit ariadne_cleanup_module(void)
743{
744    zorro_unregister_driver(&ariadne_driver);
745}
746
747module_init(ariadne_init_module);
748module_exit(ariadne_cleanup_module);
749
750MODULE_LICENSE("GPL");
751