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/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>
51 #include <asm/amigaints.h>
52 #include <asm/amigahw.h>
59 int ariadne_debug
= ARIADNE_DEBUG
;
61 int ariadne_debug
= 1;
66 * Macros to Fix Endianness problems
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))
80 * Transmit/Receive Ring Definitions
83 #define TX_RING_SIZE 5
84 #define RX_RING_SIZE 16
86 #define PKT_BUF_SIZE 1520
93 struct 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. */
105 * Structure Created in the Ariadne's RAM Buffer
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
)];
115 static int ariadne_open(struct net_device
*dev
);
116 static void ariadne_init_ring(struct net_device
*dev
);
117 static netdev_tx_t
ariadne_start_xmit(struct sk_buff
*skb
,
118 struct net_device
*dev
);
119 static void ariadne_tx_timeout(struct net_device
*dev
);
120 static int ariadne_rx(struct net_device
*dev
);
121 static void ariadne_reset(struct net_device
*dev
);
122 static irqreturn_t
ariadne_interrupt(int irq
, void *data
);
123 static int ariadne_close(struct net_device
*dev
);
124 static struct net_device_stats
*ariadne_get_stats(struct net_device
*dev
);
125 static void set_multicast_list(struct net_device
*dev
);
128 static void memcpyw(volatile u_short
*dest
, u_short
*src
, int len
)
131 *(dest
++) = *(src
++);
135 *dest
= (*(u_char
*)src
)<<8;
139 static int __devinit
ariadne_init_one(struct zorro_dev
*z
,
140 const struct zorro_device_id
*ent
);
141 static void __devexit
ariadne_remove_one(struct zorro_dev
*z
);
144 static struct zorro_device_id ariadne_zorro_tbl
[] __devinitdata
= {
145 { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE
},
148 MODULE_DEVICE_TABLE(zorro
, ariadne_zorro_tbl
);
150 static struct zorro_driver ariadne_driver
= {
152 .id_table
= ariadne_zorro_tbl
,
153 .probe
= ariadne_init_one
,
154 .remove
= __devexit_p(ariadne_remove_one
),
157 static 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
,
169 static int __devinit
ariadne_init_one(struct zorro_dev
*z
,
170 const struct zorro_device_id
*ent
)
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
;
180 r1
= request_mem_region(base_addr
, sizeof(struct Am79C960
), "Am79C960");
183 r2
= request_mem_region(mem_start
, ARIADNE_RAM_SIZE
, "RAM");
185 release_resource(r1
);
189 dev
= alloc_etherdev(sizeof(struct ariadne_private
));
191 release_resource(r1
);
192 release_resource(r2
);
196 priv
= netdev_priv(dev
);
198 r1
->name
= dev
->name
;
199 r2
->name
= dev
->name
;
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
;
211 dev
->netdev_ops
= &ariadne_netdev_ops
;
212 dev
->watchdog_timeo
= 5*HZ
;
214 err
= register_netdev(dev
);
216 release_resource(r1
);
217 release_resource(r2
);
221 zorro_set_drvdata(z
, dev
);
223 printk(KERN_INFO
"%s: Ariadne at 0x%08lx, Ethernet Address %pM\n",
224 dev
->name
, board
, dev
->dev_addr
);
230 static int ariadne_open(struct net_device
*dev
)
232 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
237 /* Reset the LANCE */
241 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
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");
253 if ((version
& 0x0ffff000) != 0x00003000) {
254 printk(KERN_WARNING
"ariadne_open: Couldn't find Am79C960 (Wrong part "
255 "number = %ld)\n", (version
& 0x0ffff000)>>12);
259 printk(KERN_DEBUG
"ariadne_open: Am79C960 (PCnet-ISA) Revision %ld\n",
260 (version
& 0xf0000000)>>28);
263 ariadne_init_ring(dev
);
265 /* Miscellaneous Stuff */
266 lance
->RAP
= CSR3
; /* Interrupt Masks and Deferral Control */
268 lance
->RAP
= CSR4
; /* Test and Features Control */
269 lance
->RDP
= DPOLL
|APAD_XMT
|MFCOM
|RCVCCOM
|TXSTRTM
|JABM
;
271 /* Set the Multicast Table */
272 lance
->RAP
= CSR8
; /* Logical Address Filter, LADRF[15:0] */
274 lance
->RAP
= CSR9
; /* Logical Address Filter, LADRF[31:16] */
276 lance
->RAP
= CSR10
; /* Logical Address Filter, LADRF[47:32] */
278 lance
->RAP
= CSR11
; /* Logical Address Filter, LADRF[63:48] */
281 /* Set the Ethernet Hardware Address */
282 lance
->RAP
= CSR12
; /* Physical Address Register, PADR[15:0] */
283 lance
->RDP
= ((u_short
*)&dev
->dev_addr
[0])[0];
284 lance
->RAP
= CSR13
; /* Physical Address Register, PADR[31:16] */
285 lance
->RDP
= ((u_short
*)&dev
->dev_addr
[0])[1];
286 lance
->RAP
= CSR14
; /* Physical Address Register, PADR[47:32] */
287 lance
->RDP
= ((u_short
*)&dev
->dev_addr
[0])[2];
289 /* Set the Init Block Mode */
290 lance
->RAP
= CSR15
; /* Mode Register */
293 /* Set the Transmit Descriptor Ring Pointer */
294 lance
->RAP
= CSR30
; /* Base Address of Transmit Ring */
295 lance
->RDP
= swloww(ARIADNE_RAM
+offsetof(struct lancedata
, tx_ring
));
296 lance
->RAP
= CSR31
; /* Base Address of transmit Ring */
297 lance
->RDP
= swhighw(ARIADNE_RAM
+offsetof(struct lancedata
, tx_ring
));
299 /* Set the Receive Descriptor Ring Pointer */
300 lance
->RAP
= CSR24
; /* Base Address of Receive Ring */
301 lance
->RDP
= swloww(ARIADNE_RAM
+offsetof(struct lancedata
, rx_ring
));
302 lance
->RAP
= CSR25
; /* Base Address of Receive Ring */
303 lance
->RDP
= swhighw(ARIADNE_RAM
+offsetof(struct lancedata
, rx_ring
));
305 /* Set the Number of RX and TX Ring Entries */
306 lance
->RAP
= CSR76
; /* Receive Ring Length */
307 lance
->RDP
= swapw(((u_short
)-RX_RING_SIZE
));
308 lance
->RAP
= CSR78
; /* Transmit Ring Length */
309 lance
->RDP
= swapw(((u_short
)-TX_RING_SIZE
));
311 /* Enable Media Interface Port Auto Select (10BASE-2/10BASE-T) */
312 lance
->RAP
= ISACSR2
; /* Miscellaneous Configuration */
316 lance
->RAP
= ISACSR5
; /* LED1 Status */
317 lance
->IDP
= PSE
|XMTE
;
318 lance
->RAP
= ISACSR6
; /* LED2 Status */
319 lance
->IDP
= PSE
|COLE
;
320 lance
->RAP
= ISACSR7
; /* LED3 Status */
321 lance
->IDP
= PSE
|RCVE
;
323 netif_start_queue(dev
);
325 i
= request_irq(IRQ_AMIGA_PORTS
, ariadne_interrupt
, IRQF_SHARED
,
329 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
330 lance
->RDP
= INEA
|STRT
;
336 static void ariadne_init_ring(struct net_device
*dev
)
338 struct ariadne_private
*priv
= netdev_priv(dev
);
339 volatile struct lancedata
*lancedata
= (struct lancedata
*)dev
->mem_start
;
342 netif_stop_queue(dev
);
345 priv
->cur_rx
= priv
->cur_tx
= 0;
349 for (i
= 0; i
< TX_RING_SIZE
; i
++) {
350 volatile struct TDRE
*t
= &lancedata
->tx_ring
[i
];
351 t
->TMD0
= swloww(ARIADNE_RAM
+offsetof(struct lancedata
, tx_buff
[i
]));
352 t
->TMD1
= swhighw(ARIADNE_RAM
+offsetof(struct lancedata
, tx_buff
[i
])) |
354 t
->TMD2
= swapw((u_short
)-PKT_BUF_SIZE
);
356 priv
->tx_ring
[i
] = &lancedata
->tx_ring
[i
];
357 priv
->tx_buff
[i
] = lancedata
->tx_buff
[i
];
359 printk(KERN_DEBUG
"TX Entry %2d at %p, Buf at %p\n", i
,
360 &lancedata
->tx_ring
[i
], lancedata
->tx_buff
[i
]);
365 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
366 volatile struct RDRE
*r
= &lancedata
->rx_ring
[i
];
367 r
->RMD0
= swloww(ARIADNE_RAM
+offsetof(struct lancedata
, rx_buff
[i
]));
368 r
->RMD1
= swhighw(ARIADNE_RAM
+offsetof(struct lancedata
, rx_buff
[i
])) |
370 r
->RMD2
= swapw((u_short
)-PKT_BUF_SIZE
);
372 priv
->rx_ring
[i
] = &lancedata
->rx_ring
[i
];
373 priv
->rx_buff
[i
] = lancedata
->rx_buff
[i
];
375 printk(KERN_DEBUG
"RX Entry %2d at %p, Buf at %p\n", i
,
376 &lancedata
->rx_ring
[i
], lancedata
->rx_buff
[i
]);
382 static int ariadne_close(struct net_device
*dev
)
384 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
386 netif_stop_queue(dev
);
388 lance
->RAP
= CSR112
; /* Missed Frame Count */
389 dev
->stats
.rx_missed_errors
= swapw(lance
->RDP
);
390 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
392 if (ariadne_debug
> 1) {
393 printk(KERN_DEBUG
"%s: Shutting down ethercard, status was %2.2x.\n",
394 dev
->name
, lance
->RDP
);
395 printk(KERN_DEBUG
"%s: %lu packets missed\n", dev
->name
,
396 dev
->stats
.rx_missed_errors
);
399 /* We stop the LANCE here -- it occasionally polls memory if we don't. */
402 free_irq(IRQ_AMIGA_PORTS
, dev
);
408 static inline void ariadne_reset(struct net_device
*dev
)
410 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
412 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
414 ariadne_init_ring(dev
);
415 lance
->RDP
= INEA
|STRT
;
416 netif_start_queue(dev
);
420 static irqreturn_t
ariadne_interrupt(int irq
, void *data
)
422 struct net_device
*dev
= (struct net_device
*)data
;
423 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
424 struct ariadne_private
*priv
;
429 printk(KERN_WARNING
"ariadne_interrupt(): irq for unknown device.\n");
433 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
435 if (!(lance
->RDP
& INTR
)) /* Check if any interrupt has been */
436 return IRQ_NONE
; /* generated by the board. */
438 priv
= netdev_priv(dev
);
441 while ((csr0
= lance
->RDP
) & (ERR
|RINT
|TINT
) && --boguscnt
>= 0) {
442 /* Acknowledge all of the current interrupt sources ASAP. */
443 lance
->RDP
= csr0
& ~(INEA
|TDMD
|STOP
|STRT
|INIT
);
446 if (ariadne_debug
> 5) {
447 printk(KERN_DEBUG
"%s: interrupt csr0=%#2.2x new csr=%#2.2x.",
448 dev
->name
, csr0
, lance
->RDP
);
486 if (csr0
& RINT
) { /* Rx interrupt */
491 if (csr0
& TINT
) { /* Tx-done interrupt */
492 int dirty_tx
= priv
->dirty_tx
;
495 while (dirty_tx
< priv
->cur_tx
) {
496 int entry
= dirty_tx
% TX_RING_SIZE
;
497 int status
= lowb(priv
->tx_ring
[entry
]->TMD1
);
500 break; /* It still hasn't been Txed */
502 priv
->tx_ring
[entry
]->TMD1
&= 0xff00;
504 if (status
& TF_ERR
) {
505 /* There was an major error, log it. */
506 int err_status
= priv
->tx_ring
[entry
]->TMD3
;
507 dev
->stats
.tx_errors
++;
508 if (err_status
& EF_RTRY
)
509 dev
->stats
.tx_aborted_errors
++;
510 if (err_status
& EF_LCAR
)
511 dev
->stats
.tx_carrier_errors
++;
512 if (err_status
& EF_LCOL
)
513 dev
->stats
.tx_window_errors
++;
514 if (err_status
& EF_UFLO
) {
515 /* Ackk! On FIFO errors the Tx unit is turned off! */
516 dev
->stats
.tx_fifo_errors
++;
517 /* Remove this verbosity later! */
518 printk(KERN_ERR
"%s: Tx FIFO error! Status %4.4x.\n",
520 /* Restart the chip. */
524 if (status
& (TF_MORE
|TF_ONE
))
525 dev
->stats
.collisions
++;
526 dev
->stats
.tx_packets
++;
531 #ifndef final_version
532 if (priv
->cur_tx
- dirty_tx
>= TX_RING_SIZE
) {
533 printk(KERN_ERR
"out-of-sync dirty pointer, %d vs. %d, "
534 "full=%d.\n", dirty_tx
, priv
->cur_tx
, priv
->tx_full
);
535 dirty_tx
+= TX_RING_SIZE
;
539 if (priv
->tx_full
&& netif_queue_stopped(dev
) &&
540 dirty_tx
> priv
->cur_tx
- TX_RING_SIZE
+ 2) {
541 /* The ring is no longer full. */
543 netif_wake_queue(dev
);
546 priv
->dirty_tx
= dirty_tx
;
549 /* Log misc errors. */
552 dev
->stats
.tx_errors
++; /* Tx babble. */
556 dev
->stats
.rx_errors
++; /* Missed a Rx frame. */
560 printk(KERN_ERR
"%s: Bus master arbitration failure, status "
561 "%4.4x.\n", dev
->name
, csr0
);
562 /* Restart the chip. */
567 /* Clear any other interrupt, and set interrupt enable. */
568 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
569 lance
->RDP
= INEA
|BABL
|CERR
|MISS
|MERR
|IDON
;
572 if (ariadne_debug
> 4)
573 printk(KERN_DEBUG
"%s: exiting interrupt, csr%d=%#4.4x.\n", dev
->name
,
574 lance
->RAP
, lance
->RDP
);
576 return IRQ_RETVAL(handled
);
580 static void ariadne_tx_timeout(struct net_device
*dev
)
582 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
584 printk(KERN_ERR
"%s: transmit timed out, status %4.4x, resetting.\n",
585 dev
->name
, lance
->RDP
);
587 netif_wake_queue(dev
);
591 static netdev_tx_t
ariadne_start_xmit(struct sk_buff
*skb
,
592 struct net_device
*dev
)
594 struct ariadne_private
*priv
= netdev_priv(dev
);
595 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
601 if (ariadne_debug
> 3) {
602 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
603 printk(KERN_DEBUG
"%s: ariadne_start_xmit() called, csr0 %4.4x.\n",
604 dev
->name
, lance
->RDP
);
609 /* FIXME: is the 79C960 new enough to do its own padding right ? */
610 if (skb
->len
< ETH_ZLEN
)
612 if (skb_padto(skb
, ETH_ZLEN
))
617 /* Fill in a Tx ring entry */
621 printk(KERN_DEBUG
"TX pkt type 0x%04x from %pM to %pM "
622 " data 0x%08x len %d\n",
623 ((u_short
*)skb
->data
)[6],
624 skb
->data
+ 6, skb
->data
,
625 (int)skb
->data
, (int)skb
->len
);
629 local_irq_save(flags
);
631 entry
= priv
->cur_tx
% TX_RING_SIZE
;
633 /* Caution: the write order is important here, set the base address with
634 the "ownership" bits last. */
636 priv
->tx_ring
[entry
]->TMD2
= swapw((u_short
)-skb
->len
);
637 priv
->tx_ring
[entry
]->TMD3
= 0x0000;
638 memcpyw(priv
->tx_buff
[entry
], (u_short
*)skb
->data
, len
);
644 len
= skb
->len
> 64 ? 64 : skb
->len
;
646 for (i
= 0; i
< len
; i
+= 8) {
648 printk(KERN_DEBUG
"%04x:", i
);
649 for (j
= 0; (j
< 8) && ((i
+j
) < len
); j
++) {
652 printk("%04x", priv
->tx_buff
[entry
][i
+j
]);
659 priv
->tx_ring
[entry
]->TMD1
= (priv
->tx_ring
[entry
]->TMD1
&0xff00)|TF_OWN
|TF_STP
|TF_ENP
;
664 if ((priv
->cur_tx
>= TX_RING_SIZE
) && (priv
->dirty_tx
>= TX_RING_SIZE
)) {
667 printk(KERN_DEBUG
"*** Subtracting TX_RING_SIZE from cur_tx (%d) and "
668 "dirty_tx (%d)\n", priv
->cur_tx
, priv
->dirty_tx
);
671 priv
->cur_tx
-= TX_RING_SIZE
;
672 priv
->dirty_tx
-= TX_RING_SIZE
;
674 dev
->stats
.tx_bytes
+= len
;
676 /* Trigger an immediate send poll. */
677 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
678 lance
->RDP
= INEA
|TDMD
;
680 if (lowb(priv
->tx_ring
[(entry
+1) % TX_RING_SIZE
]->TMD1
) != 0) {
681 netif_stop_queue(dev
);
684 local_irq_restore(flags
);
690 static int ariadne_rx(struct net_device
*dev
)
692 struct ariadne_private
*priv
= netdev_priv(dev
);
693 int entry
= priv
->cur_rx
% RX_RING_SIZE
;
696 /* If we own the next entry, it's a new packet. Send it up. */
697 while (!(lowb(priv
->rx_ring
[entry
]->RMD1
) & RF_OWN
)) {
698 int status
= lowb(priv
->rx_ring
[entry
]->RMD1
);
700 if (status
!= (RF_STP
|RF_ENP
)) { /* There was an error. */
701 /* There is a tricky error noted by John Murphy,
702 <murf@perftech.com> to Russ Nelson: Even with full-sized
703 buffers it's possible for a jabber packet to use two
704 buffers, with only the last correctly noting the error. */
706 /* Only count a general error at the end of a packet.*/
707 dev
->stats
.rx_errors
++;
708 if (status
& RF_FRAM
)
709 dev
->stats
.rx_frame_errors
++;
710 if (status
& RF_OFLO
)
711 dev
->stats
.rx_over_errors
++;
713 dev
->stats
.rx_crc_errors
++;
714 if (status
& RF_BUFF
)
715 dev
->stats
.rx_fifo_errors
++;
716 priv
->rx_ring
[entry
]->RMD1
&= 0xff00|RF_STP
|RF_ENP
;
718 /* Malloc up new buffer, compatible with net-3. */
719 short pkt_len
= swapw(priv
->rx_ring
[entry
]->RMD3
);
722 skb
= dev_alloc_skb(pkt_len
+2);
724 printk(KERN_WARNING
"%s: Memory squeeze, deferring packet.\n",
726 for (i
= 0; i
< RX_RING_SIZE
; i
++)
727 if (lowb(priv
->rx_ring
[(entry
+i
) % RX_RING_SIZE
]->RMD1
) & RF_OWN
)
730 if (i
> RX_RING_SIZE
-2) {
731 dev
->stats
.rx_dropped
++;
732 priv
->rx_ring
[entry
]->RMD1
|= RF_OWN
;
739 skb_reserve(skb
,2); /* 16 byte align */
740 skb_put(skb
,pkt_len
); /* Make room */
741 skb_copy_to_linear_data(skb
, (char *)priv
->rx_buff
[entry
], pkt_len
);
742 skb
->protocol
=eth_type_trans(skb
,dev
);
745 printk(KERN_DEBUG
"RX pkt type 0x%04x from ",
746 ((u_short
*)skb
->data
)[6]);
748 u_char
*ptr
= &((u_char
*)skb
->data
)[6];
753 u_char
*ptr
= (u_char
*)skb
->data
;
756 printk(" data 0x%08x len %d\n", (int)skb
->data
, (int)skb
->len
);
761 dev
->stats
.rx_packets
++;
762 dev
->stats
.rx_bytes
+= pkt_len
;
765 priv
->rx_ring
[entry
]->RMD1
|= RF_OWN
;
766 entry
= (++priv
->cur_rx
) % RX_RING_SIZE
;
769 priv
->cur_rx
= priv
->cur_rx
% RX_RING_SIZE
;
771 /* We should check that at least two ring entries are free. If not,
772 we should free one and mark stats->rx_dropped++. */
778 static struct net_device_stats
*ariadne_get_stats(struct net_device
*dev
)
780 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
784 local_irq_save(flags
);
785 saved_addr
= lance
->RAP
;
786 lance
->RAP
= CSR112
; /* Missed Frame Count */
787 dev
->stats
.rx_missed_errors
= swapw(lance
->RDP
);
788 lance
->RAP
= saved_addr
;
789 local_irq_restore(flags
);
795 /* Set or clear the multicast filter for this adaptor.
796 num_addrs == -1 Promiscuous mode, receive all packets
797 num_addrs == 0 Normal mode, clear multicast list
798 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
799 best-effort filtering.
801 static void set_multicast_list(struct net_device
*dev
)
803 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
805 if (!netif_running(dev
))
808 netif_stop_queue(dev
);
810 /* We take the simple way out and always enable promiscuous mode. */
811 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
812 lance
->RDP
= STOP
; /* Temporarily stop the lance. */
813 ariadne_init_ring(dev
);
815 if (dev
->flags
& IFF_PROMISC
) {
816 lance
->RAP
= CSR15
; /* Mode Register */
817 lance
->RDP
= PROM
; /* Set promiscuous mode */
819 short multicast_table
[4];
820 int num_addrs
= netdev_mc_count(dev
);
822 /* We don't use the multicast table, but rely on upper-layer filtering. */
823 memset(multicast_table
, (num_addrs
== 0) ? 0 : -1,
824 sizeof(multicast_table
));
825 for (i
= 0; i
< 4; i
++) {
826 lance
->RAP
= CSR8
+(i
<<8); /* Logical Address Filter */
827 lance
->RDP
= swapw(multicast_table
[i
]);
829 lance
->RAP
= CSR15
; /* Mode Register */
830 lance
->RDP
= 0x0000; /* Unset promiscuous mode */
833 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
834 lance
->RDP
= INEA
|STRT
|IDON
; /* Resume normal operation. */
836 netif_wake_queue(dev
);
840 static void __devexit
ariadne_remove_one(struct zorro_dev
*z
)
842 struct net_device
*dev
= zorro_get_drvdata(z
);
844 unregister_netdev(dev
);
845 release_mem_region(ZTWO_PADDR(dev
->base_addr
), sizeof(struct Am79C960
));
846 release_mem_region(ZTWO_PADDR(dev
->mem_start
), ARIADNE_RAM_SIZE
);
850 static int __init
ariadne_init_module(void)
852 return zorro_register_driver(&ariadne_driver
);
855 static void __exit
ariadne_cleanup_module(void)
857 zorro_unregister_driver(&ariadne_driver
);
860 module_init(ariadne_init_module
);
861 module_exit(ariadne_cleanup_module
);
863 MODULE_LICENSE("GPL");