2 * Amiga Linux/m68k Ariadne Ethernet Driver
4 * © Copyright 1995 by Geert Uytterhoeven (geert@linux-m68k.org)
6 * (Peter.DeSchrijver@linux.cc.kuleuven.ac.be)
8 * ---------------------------------------------------------------------------
10 * This program is based on
12 * lance.c: An AMD LANCE ethernet driver for linux.
13 * Written 1993-94 by Donald Becker.
15 * Am79C960: PCnet(tm)-ISA Single-Chip Ethernet Controller
16 * Advanced Micro Devices
17 * Publication #16907, Rev. B, Amendment/0, May 1994
19 * MC68230: Parallel Interface/Timer (PI/T)
20 * Motorola Semiconductors, December, 1983
22 * ---------------------------------------------------------------------------
24 * This file is subject to the terms and conditions of the GNU General Public
25 * License. See the file COPYING in the main directory of the Linux
26 * distribution for more details.
28 * ---------------------------------------------------------------------------
30 * The Ariadne is a Zorro-II board made by Village Tronic. It contains:
32 * - an Am79C960 PCnet-ISA Single-Chip Ethernet Controller with both
33 * 10BASE-2 (thin coax) and 10BASE-T (UTP) connectors
35 * - an MC68230 Parallel Interface/Timer configured as 2 parallel ports
38 #include <linux/module.h>
39 #include <linux/stddef.h>
40 #include <linux/kernel.h>
41 #include <linux/string.h>
42 #include <linux/errno.h>
43 #include <linux/ioport.h>
44 #include <linux/slab.h>
45 #include <linux/netdevice.h>
46 #include <linux/etherdevice.h>
47 #include <linux/interrupt.h>
48 #include <linux/skbuff.h>
49 #include <linux/init.h>
50 #include <linux/zorro.h>
52 #include <asm/bitops.h>
53 #include <asm/amigaints.h>
54 #include <asm/amigahw.h>
61 int ariadne_debug
= ARIADNE_DEBUG
;
63 int ariadne_debug
= 1;
68 * Macros to Fix Endianness problems
71 /* Swap the Bytes in a WORD */
72 #define swapw(x) (((x>>8)&0x00ff)|((x<<8)&0xff00))
73 /* Get the Low BYTE in a WORD */
74 #define lowb(x) (x&0xff)
75 /* Get the Swapped High WORD in a LONG */
76 #define swhighw(x) ((((x)>>8)&0xff00)|(((x)>>24)&0x00ff))
77 /* Get the Swapped Low WORD in a LONG */
78 #define swloww(x) ((((x)<<8)&0xff00)|(((x)>>8)&0x00ff))
82 * Transmit/Receive Ring Definitions
85 #define TX_RING_SIZE 5
86 #define RX_RING_SIZE 16
88 #define PKT_BUF_SIZE 1520
95 struct ariadne_private
{
96 volatile struct TDRE
*tx_ring
[TX_RING_SIZE
];
97 volatile struct RDRE
*rx_ring
[RX_RING_SIZE
];
98 volatile u_short
*tx_buff
[TX_RING_SIZE
];
99 volatile u_short
*rx_buff
[RX_RING_SIZE
];
100 int cur_tx
, cur_rx
; /* The next free ring entry */
101 int dirty_tx
; /* The ring entries to be free()ed. */
102 struct net_device_stats stats
;
104 struct net_device
*dev
; /* Backpointer */
105 struct ariadne_private
*next_module
;
110 * Structure Created in the Ariadne's RAM Buffer
114 struct TDRE tx_ring
[TX_RING_SIZE
];
115 struct RDRE rx_ring
[RX_RING_SIZE
];
116 u_short tx_buff
[TX_RING_SIZE
][PKT_BUF_SIZE
/sizeof(u_short
)];
117 u_short rx_buff
[RX_RING_SIZE
][PKT_BUF_SIZE
/sizeof(u_short
)];
121 static struct ariadne_private
*root_ariadne_dev
;
124 static int ariadne_open(struct net_device
*dev
);
125 static void ariadne_init_ring(struct net_device
*dev
);
126 static int ariadne_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
127 static void ariadne_tx_timeout(struct net_device
*dev
);
128 static int ariadne_rx(struct net_device
*dev
);
129 static void ariadne_reset(struct net_device
*dev
);
130 static irqreturn_t
ariadne_interrupt(int irq
, void *data
, struct pt_regs
*fp
);
131 static int ariadne_close(struct net_device
*dev
);
132 static struct net_device_stats
*ariadne_get_stats(struct net_device
*dev
);
133 #ifdef HAVE_MULTICAST
134 static void set_multicast_list(struct net_device
*dev
);
138 static void memcpyw(volatile u_short
*dest
, u_short
*src
, int len
)
141 *(dest
++) = *(src
++);
145 *dest
= (*(u_char
*)src
)<<8;
149 static int __init
ariadne_probe(void)
151 struct zorro_dev
*z
= NULL
;
152 struct net_device
*dev
;
153 struct ariadne_private
*priv
;
156 while ((z
= zorro_find_device(ZORRO_PROD_VILLAGE_TRONIC_ARIADNE
, z
))) {
157 unsigned long board
= z
->resource
.start
;
158 unsigned long base_addr
= board
+ARIADNE_LANCE
;
159 unsigned long mem_start
= board
+ARIADNE_RAM
;
160 struct resource
*r1
, *r2
;
162 r1
= request_mem_region(base_addr
, sizeof(struct Am79C960
),
165 r2
= request_mem_region(mem_start
, ARIADNE_RAM_SIZE
, "RAM");
167 release_resource(r1
);
171 dev
= init_etherdev(NULL
, sizeof(struct ariadne_private
));
174 release_resource(r1
);
175 release_resource(r2
);
178 SET_MODULE_OWNER(dev
);
181 r1
->name
= dev
->name
;
182 r2
->name
= dev
->name
;
185 dev
->dev_addr
[0] = 0x00;
186 dev
->dev_addr
[1] = 0x60;
187 dev
->dev_addr
[2] = 0x30;
188 dev
->dev_addr
[3] = (z
->rom
.er_SerialNumber
>>16) & 0xff;
189 dev
->dev_addr
[4] = (z
->rom
.er_SerialNumber
>>8) & 0xff;
190 dev
->dev_addr
[5] = z
->rom
.er_SerialNumber
& 0xff;
191 printk("%s: Ariadne at 0x%08lx, Ethernet Address "
192 "%02x:%02x:%02x:%02x:%02x:%02x\n", dev
->name
, board
,
193 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
194 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
196 dev
->base_addr
= ZTWO_VADDR(base_addr
);
197 dev
->mem_start
= ZTWO_VADDR(mem_start
);
198 dev
->mem_end
= dev
->mem_start
+ARIADNE_RAM_SIZE
;
200 dev
->open
= &ariadne_open
;
201 dev
->stop
= &ariadne_close
;
202 dev
->hard_start_xmit
= &ariadne_start_xmit
;
203 dev
->tx_timeout
= &ariadne_tx_timeout
;
204 dev
->watchdog_timeo
= 5*HZ
;
205 dev
->get_stats
= &ariadne_get_stats
;
206 dev
->set_multicast_list
= &set_multicast_list
;
209 priv
->next_module
= root_ariadne_dev
;
210 root_ariadne_dev
= priv
;
218 static int ariadne_open(struct net_device
*dev
)
220 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
225 /* Reset the LANCE */
229 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
232 /* Check the LANCE version */
233 lance
->RAP
= CSR88
; /* Chip ID */
234 version
= swapw(lance
->RDP
);
235 lance
->RAP
= CSR89
; /* Chip ID */
236 version
|= swapw(lance
->RDP
)<<16;
237 if ((version
& 0x00000fff) != 0x00000003) {
238 printk("ariadne_open: Couldn't find AMD Ethernet Chip\n");
241 if ((version
& 0x0ffff000) != 0x00003000) {
242 printk("ariadne_open: Couldn't find Am79C960 (Wrong part number = %ld)\n",
243 (version
& 0x0ffff000)>>12);
247 printk("ariadne_open: Am79C960 (PCnet-ISA) Revision %ld\n",
248 (version
& 0xf0000000)>>28);
251 ariadne_init_ring(dev
);
253 /* Miscellaneous Stuff */
254 lance
->RAP
= CSR3
; /* Interrupt Masks and Deferral Control */
256 lance
->RAP
= CSR4
; /* Test and Features Control */
257 lance
->RDP
= DPOLL
|APAD_XMT
|MFCOM
|RCVCCOM
|TXSTRTM
|JABM
;
259 /* Set the Multicast Table */
260 lance
->RAP
= CSR8
; /* Logical Address Filter, LADRF[15:0] */
262 lance
->RAP
= CSR9
; /* Logical Address Filter, LADRF[31:16] */
264 lance
->RAP
= CSR10
; /* Logical Address Filter, LADRF[47:32] */
266 lance
->RAP
= CSR11
; /* Logical Address Filter, LADRF[63:48] */
269 /* Set the Ethernet Hardware Address */
270 lance
->RAP
= CSR12
; /* Physical Address Register, PADR[15:0] */
271 lance
->RDP
= ((u_short
*)&dev
->dev_addr
[0])[0];
272 lance
->RAP
= CSR13
; /* Physical Address Register, PADR[31:16] */
273 lance
->RDP
= ((u_short
*)&dev
->dev_addr
[0])[1];
274 lance
->RAP
= CSR14
; /* Physical Address Register, PADR[47:32] */
275 lance
->RDP
= ((u_short
*)&dev
->dev_addr
[0])[2];
277 /* Set the Init Block Mode */
278 lance
->RAP
= CSR15
; /* Mode Register */
281 /* Set the Transmit Descriptor Ring Pointer */
282 lance
->RAP
= CSR30
; /* Base Address of Transmit Ring */
283 lance
->RDP
= swloww(ARIADNE_RAM
+offsetof(struct lancedata
, tx_ring
));
284 lance
->RAP
= CSR31
; /* Base Address of transmit Ring */
285 lance
->RDP
= swhighw(ARIADNE_RAM
+offsetof(struct lancedata
, tx_ring
));
287 /* Set the Receive Descriptor Ring Pointer */
288 lance
->RAP
= CSR24
; /* Base Address of Receive Ring */
289 lance
->RDP
= swloww(ARIADNE_RAM
+offsetof(struct lancedata
, rx_ring
));
290 lance
->RAP
= CSR25
; /* Base Address of Receive Ring */
291 lance
->RDP
= swhighw(ARIADNE_RAM
+offsetof(struct lancedata
, rx_ring
));
293 /* Set the Number of RX and TX Ring Entries */
294 lance
->RAP
= CSR76
; /* Receive Ring Length */
295 lance
->RDP
= swapw(((u_short
)-RX_RING_SIZE
));
296 lance
->RAP
= CSR78
; /* Transmit Ring Length */
297 lance
->RDP
= swapw(((u_short
)-TX_RING_SIZE
));
299 /* Enable Media Interface Port Auto Select (10BASE-2/10BASE-T) */
300 lance
->RAP
= ISACSR2
; /* Miscellaneous Configuration */
304 lance
->RAP
= ISACSR5
; /* LED1 Status */
305 lance
->IDP
= PSE
|XMTE
;
306 lance
->RAP
= ISACSR6
; /* LED2 Status */
307 lance
->IDP
= PSE
|COLE
;
308 lance
->RAP
= ISACSR7
; /* LED3 Status */
309 lance
->IDP
= PSE
|RCVE
;
311 netif_start_queue(dev
);
313 i
= request_irq(IRQ_AMIGA_PORTS
, ariadne_interrupt
, SA_SHIRQ
,
317 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
318 lance
->RDP
= INEA
|STRT
;
324 static void ariadne_init_ring(struct net_device
*dev
)
326 struct ariadne_private
*priv
= (struct ariadne_private
*)dev
->priv
;
327 volatile struct lancedata
*lancedata
= (struct lancedata
*)dev
->mem_start
;
330 netif_stop_queue(dev
);
333 priv
->cur_rx
= priv
->cur_tx
= 0;
337 for (i
= 0; i
< TX_RING_SIZE
; i
++) {
338 volatile struct TDRE
*t
= &lancedata
->tx_ring
[i
];
339 t
->TMD0
= swloww(ARIADNE_RAM
+offsetof(struct lancedata
, tx_buff
[i
]));
340 t
->TMD1
= swhighw(ARIADNE_RAM
+offsetof(struct lancedata
, tx_buff
[i
])) |
342 t
->TMD2
= swapw((u_short
)-PKT_BUF_SIZE
);
344 priv
->tx_ring
[i
] = &lancedata
->tx_ring
[i
];
345 priv
->tx_buff
[i
] = lancedata
->tx_buff
[i
];
347 printk("TX Entry %2d at %p, Buf at %p\n", i
, &lancedata
->tx_ring
[i
],
348 lancedata
->tx_buff
[i
]);
353 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
354 volatile struct RDRE
*r
= &lancedata
->rx_ring
[i
];
355 r
->RMD0
= swloww(ARIADNE_RAM
+offsetof(struct lancedata
, rx_buff
[i
]));
356 r
->RMD1
= swhighw(ARIADNE_RAM
+offsetof(struct lancedata
, rx_buff
[i
])) |
358 r
->RMD2
= swapw((u_short
)-PKT_BUF_SIZE
);
360 priv
->rx_ring
[i
] = &lancedata
->rx_ring
[i
];
361 priv
->rx_buff
[i
] = lancedata
->rx_buff
[i
];
363 printk("RX Entry %2d at %p, Buf at %p\n", i
, &lancedata
->rx_ring
[i
],
364 lancedata
->rx_buff
[i
]);
370 static int ariadne_close(struct net_device
*dev
)
372 struct ariadne_private
*priv
= (struct ariadne_private
*)dev
->priv
;
373 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
375 netif_stop_queue(dev
);
377 lance
->RAP
= CSR112
; /* Missed Frame Count */
378 priv
->stats
.rx_missed_errors
= swapw(lance
->RDP
);
379 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
381 if (ariadne_debug
> 1) {
382 printk("%s: Shutting down ethercard, status was %2.2x.\n", dev
->name
,
384 printk("%s: %lu packets missed\n", dev
->name
,
385 priv
->stats
.rx_missed_errors
);
388 /* We stop the LANCE here -- it occasionally polls memory if we don't. */
391 free_irq(IRQ_AMIGA_PORTS
, dev
);
397 static inline void ariadne_reset(struct net_device
*dev
)
399 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
401 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
403 ariadne_init_ring(dev
);
404 lance
->RDP
= INEA
|STRT
;
405 netif_start_queue(dev
);
409 static irqreturn_t
ariadne_interrupt(int irq
, void *data
, struct pt_regs
*fp
)
411 struct net_device
*dev
= (struct net_device
*)data
;
412 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
413 struct ariadne_private
*priv
;
418 printk("ariadne_interrupt(): irq for unknown device.\n");
422 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
424 if (!(lance
->RDP
& INTR
)) /* Check if any interrupt has been */
425 return IRQ_NONE
; /* generated by the board. */
427 priv
= (struct ariadne_private
*)dev
->priv
;
430 while ((csr0
= lance
->RDP
) & (ERR
|RINT
|TINT
) && --boguscnt
>= 0) {
431 /* Acknowledge all of the current interrupt sources ASAP. */
432 lance
->RDP
= csr0
& ~(INEA
|TDMD
|STOP
|STRT
|INIT
);
435 if (ariadne_debug
> 5) {
436 printk("%s: interrupt csr0=%#2.2x new csr=%#2.2x.", dev
->name
,
475 if (csr0
& RINT
) { /* Rx interrupt */
480 if (csr0
& TINT
) { /* Tx-done interrupt */
481 int dirty_tx
= priv
->dirty_tx
;
484 while (dirty_tx
< priv
->cur_tx
) {
485 int entry
= dirty_tx
% TX_RING_SIZE
;
486 int status
= lowb(priv
->tx_ring
[entry
]->TMD1
);
489 break; /* It still hasn't been Txed */
491 priv
->tx_ring
[entry
]->TMD1
&= 0xff00;
493 if (status
& TF_ERR
) {
494 /* There was an major error, log it. */
495 int err_status
= priv
->tx_ring
[entry
]->TMD3
;
496 priv
->stats
.tx_errors
++;
497 if (err_status
& EF_RTRY
)
498 priv
->stats
.tx_aborted_errors
++;
499 if (err_status
& EF_LCAR
)
500 priv
->stats
.tx_carrier_errors
++;
501 if (err_status
& EF_LCOL
)
502 priv
->stats
.tx_window_errors
++;
503 if (err_status
& EF_UFLO
) {
504 /* Ackk! On FIFO errors the Tx unit is turned off! */
505 priv
->stats
.tx_fifo_errors
++;
506 /* Remove this verbosity later! */
507 printk("%s: Tx FIFO error! Status %4.4x.\n", dev
->name
,
509 /* Restart the chip. */
513 if (status
& (TF_MORE
|TF_ONE
))
514 priv
->stats
.collisions
++;
515 priv
->stats
.tx_packets
++;
520 #ifndef final_version
521 if (priv
->cur_tx
- dirty_tx
>= TX_RING_SIZE
) {
522 printk("out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
523 dirty_tx
, priv
->cur_tx
, priv
->tx_full
);
524 dirty_tx
+= TX_RING_SIZE
;
528 if (priv
->tx_full
&& netif_queue_stopped(dev
) &&
529 dirty_tx
> priv
->cur_tx
- TX_RING_SIZE
+ 2) {
530 /* The ring is no longer full. */
532 netif_wake_queue(dev
);
535 priv
->dirty_tx
= dirty_tx
;
538 /* Log misc errors. */
541 priv
->stats
.tx_errors
++; /* Tx babble. */
545 priv
->stats
.rx_errors
++; /* Missed a Rx frame. */
549 printk("%s: Bus master arbitration failure, status %4.4x.\n",
551 /* Restart the chip. */
556 /* Clear any other interrupt, and set interrupt enable. */
557 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
558 lance
->RDP
= INEA
|BABL
|CERR
|MISS
|MERR
|IDON
;
561 if (ariadne_debug
> 4)
562 printk("%s: exiting interrupt, csr%d=%#4.4x.\n", dev
->name
, lance
->RAP
,
565 return IRQ_RETVAL(handled
);
569 static void ariadne_tx_timeout(struct net_device
*dev
)
571 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
573 printk(KERN_ERR
"%s: transmit timed out, status %4.4x, resetting.\n",
574 dev
->name
, lance
->RDP
);
576 netif_wake_queue(dev
);
580 static int ariadne_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
582 struct ariadne_private
*priv
= (struct ariadne_private
*)dev
->priv
;
583 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
589 if (ariadne_debug
> 3) {
590 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
591 printk("%s: ariadne_start_xmit() called, csr0 %4.4x.\n", dev
->name
,
597 /* FIXME: is the 79C960 new enough to do its own padding right ? */
598 if (skb
->len
< ETH_ZLEN
)
600 skb
= skb_padto(skb
, ETH_ZLEN
);
606 /* Fill in a Tx ring entry */
609 printk("TX pkt type 0x%04x from ", ((u_short
*)skb
->data
)[6]);
612 u_char
*ptr
= &((u_char
*)skb
->data
)[6];
613 for (i
= 0; i
< 6; i
++)
614 printk("%02x", ptr
[i
]);
619 u_char
*ptr
= (u_char
*)skb
->data
;
620 for (i
= 0; i
< 6; i
++)
621 printk("%02x", ptr
[i
]);
623 printk(" data 0x%08x len %d\n", (int)skb
->data
, (int)skb
->len
);
626 local_irq_save(flags
);
628 entry
= priv
->cur_tx
% TX_RING_SIZE
;
630 /* Caution: the write order is important here, set the base address with
631 the "ownership" bits last. */
633 priv
->tx_ring
[entry
]->TMD2
= swapw((u_short
)-skb
->len
);
634 priv
->tx_ring
[entry
]->TMD3
= 0x0000;
635 memcpyw(priv
->tx_buff
[entry
], (u_short
*)skb
->data
, len
);
641 len
= skb
->len
> 64 ? 64 : skb
->len
;
643 for (i
= 0; i
< len
; i
+= 8) {
646 for (j
= 0; (j
< 8) && ((i
+j
) < len
); j
++) {
649 printk("%04x", priv
->tx_buff
[entry
][i
+j
]);
656 priv
->tx_ring
[entry
]->TMD1
= (priv
->tx_ring
[entry
]->TMD1
&0xff00)|TF_OWN
|TF_STP
|TF_ENP
;
661 if ((priv
->cur_tx
>= TX_RING_SIZE
) && (priv
->dirty_tx
>= TX_RING_SIZE
)) {
664 printk("*** Subtracting TX_RING_SIZE from cur_tx (%d) and dirty_tx (%d)\n",
665 priv
->cur_tx
, priv
->dirty_tx
);
668 priv
->cur_tx
-= TX_RING_SIZE
;
669 priv
->dirty_tx
-= TX_RING_SIZE
;
672 /* Trigger an immediate send poll. */
673 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
674 lance
->RDP
= INEA
|TDMD
;
676 dev
->trans_start
= jiffies
;
678 if (lowb(priv
->tx_ring
[(entry
+1) % TX_RING_SIZE
]->TMD1
) != 0) {
679 netif_stop_queue(dev
);
682 local_irq_restore(flags
);
688 static int ariadne_rx(struct net_device
*dev
)
690 struct ariadne_private
*priv
= (struct ariadne_private
*)dev
->priv
;
691 int entry
= priv
->cur_rx
% RX_RING_SIZE
;
694 /* If we own the next entry, it's a new packet. Send it up. */
695 while (!(lowb(priv
->rx_ring
[entry
]->RMD1
) & RF_OWN
)) {
696 int status
= lowb(priv
->rx_ring
[entry
]->RMD1
);
698 if (status
!= (RF_STP
|RF_ENP
)) { /* There was an error. */
699 /* There is a tricky error noted by John Murphy,
700 <murf@perftech.com> to Russ Nelson: Even with full-sized
701 buffers it's possible for a jabber packet to use two
702 buffers, with only the last correctly noting the error. */
704 /* Only count a general error at the end of a packet.*/
705 priv
->stats
.rx_errors
++;
706 if (status
& RF_FRAM
)
707 priv
->stats
.rx_frame_errors
++;
708 if (status
& RF_OFLO
)
709 priv
->stats
.rx_over_errors
++;
711 priv
->stats
.rx_crc_errors
++;
712 if (status
& RF_BUFF
)
713 priv
->stats
.rx_fifo_errors
++;
714 priv
->rx_ring
[entry
]->RMD1
&= 0xff00|RF_STP
|RF_ENP
;
716 /* Malloc up new buffer, compatible with net-3. */
717 short pkt_len
= swapw(priv
->rx_ring
[entry
]->RMD3
);
720 skb
= dev_alloc_skb(pkt_len
+2);
722 printk("%s: Memory squeeze, deferring packet.\n", dev
->name
);
723 for (i
= 0; i
< RX_RING_SIZE
; i
++)
724 if (lowb(priv
->rx_ring
[(entry
+i
) % RX_RING_SIZE
]->RMD1
) & RF_OWN
)
727 if (i
> RX_RING_SIZE
-2) {
728 priv
->stats
.rx_dropped
++;
729 priv
->rx_ring
[entry
]->RMD1
|= RF_OWN
;
737 skb_reserve(skb
,2); /* 16 byte align */
738 skb_put(skb
,pkt_len
); /* Make room */
739 eth_copy_and_sum(skb
, (char *)priv
->rx_buff
[entry
], pkt_len
,0);
740 skb
->protocol
=eth_type_trans(skb
,dev
);
742 printk("RX pkt type 0x%04x from ", ((u_short
*)skb
->data
)[6]);
745 u_char
*ptr
= &((u_char
*)skb
->data
)[6];
746 for (i
= 0; i
< 6; i
++)
747 printk("%02x", ptr
[i
]);
752 u_char
*ptr
= (u_char
*)skb
->data
;
753 for (i
= 0; i
< 6; i
++)
754 printk("%02x", ptr
[i
]);
756 printk(" data 0x%08x len %d\n", (int)skb
->data
, (int)skb
->len
);
760 dev
->last_rx
= jiffies
;
761 priv
->stats
.rx_packets
++;
762 priv
->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 struct ariadne_private
*priv
= (struct ariadne_private
*)dev
->priv
;
781 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
785 local_irq_save(flags
);
786 saved_addr
= lance
->RAP
;
787 lance
->RAP
= CSR112
; /* Missed Frame Count */
788 priv
->stats
.rx_missed_errors
= swapw(lance
->RDP
);
789 lance
->RAP
= saved_addr
;
790 local_irq_restore(flags
);
796 /* Set or clear the multicast filter for this adaptor.
797 num_addrs == -1 Promiscuous mode, receive all packets
798 num_addrs == 0 Normal mode, clear multicast list
799 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
800 best-effort filtering.
802 static void set_multicast_list(struct net_device
*dev
)
804 volatile struct Am79C960
*lance
= (struct Am79C960
*)dev
->base_addr
;
806 if (!netif_running(dev
))
809 netif_stop_queue(dev
);
811 /* We take the simple way out and always enable promiscuous mode. */
812 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
813 lance
->RDP
= STOP
; /* Temporarily stop the lance. */
814 ariadne_init_ring(dev
);
816 if (dev
->flags
& IFF_PROMISC
) {
817 /* Log any net taps. */
818 printk("%s: Promiscuous mode enabled.\n", dev
->name
);
819 lance
->RAP
= CSR15
; /* Mode Register */
820 lance
->RDP
= PROM
; /* Set promiscuous mode */
822 short multicast_table
[4];
823 int num_addrs
= dev
->mc_count
;
825 /* We don't use the multicast table, but rely on upper-layer filtering. */
826 memset(multicast_table
, (num_addrs
== 0) ? 0 : -1,
827 sizeof(multicast_table
));
828 for (i
= 0; i
< 4; i
++) {
829 lance
->RAP
= CSR8
+(i
<<8); /* Logical Address Filter */
830 lance
->RDP
= swapw(multicast_table
[i
]);
832 lance
->RAP
= CSR15
; /* Mode Register */
833 lance
->RDP
= 0x0000; /* Unset promiscuous mode */
836 lance
->RAP
= CSR0
; /* PCnet-ISA Controller Status */
837 lance
->RDP
= INEA
|STRT
|IDON
; /* Resume normal operation. */
839 netif_wake_queue(dev
);
843 static void __exit
ariadne_cleanup(void)
846 struct ariadne_private
*next
;
847 struct net_device
*dev
;
849 while (root_ariadne_dev
) {
850 next
= root_ariadne_dev
->next_module
;
851 dev
= root_ariadne_dev
->dev
;
852 unregister_netdev(dev
);
853 release_mem_region(ZTWO_PADDR(dev
->base_addr
), sizeof(struct Am79C960
));
854 release_mem_region(ZTWO_PADDR(dev
->mem_start
), ARIADNE_RAM_SIZE
);
856 root_ariadne_dev
= next
;
861 module_init(ariadne_probe
);
862 module_exit(ariadne_cleanup
);
864 MODULE_LICENSE("GPL");