1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/acorn/net/ether1.c
5 * Copyright (C) 1996-2000 Russell King
7 * Acorn ether1 driver (82586 chip) for Acorn machines
9 * We basically keep two queues in the cards memory - one for transmit
10 * and one for receive. Each has a head and a tail. The head is where
11 * we/the chip adds packets to be transmitted/received, and the tail
12 * is where the transmitter has got to/where the receiver will stop.
13 * Both of these queues are circular, and since the chip is running
14 * all the time, we have to be careful when we modify the pointers etc
15 * so that the buffer memory contents is valid all the time.
19 * 1.01 RMK 19/03/1996 Transfers the last odd byte onto/off of the card now.
20 * 1.02 RMK 25/05/1997 Added code to restart RU if it goes not ready
21 * 1.03 RMK 14/09/1997 Cleaned up the handling of a reset during the TX interrupt.
22 * Should prevent lockup.
23 * 1.04 RMK 17/09/1997 Added more info when initialsation of chip goes wrong.
24 * TDR now only reports failure when chip reports non-zero
26 * 1.05 RMK 31/12/1997 Removed calls to dev_tint for 2.1
27 * 1.06 RMK 10/02/2000 Updated for 2.3.43
28 * 1.07 RMK 13/05/2000 Updated for 2.3.99-pre8
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/fcntl.h>
35 #include <linux/interrupt.h>
36 #include <linux/ioport.h>
38 #include <linux/slab.h>
39 #include <linux/string.h>
40 #include <linux/errno.h>
41 #include <linux/device.h>
42 #include <linux/init.h>
43 #include <linux/netdevice.h>
44 #include <linux/etherdevice.h>
45 #include <linux/skbuff.h>
46 #include <linux/bitops.h>
50 #include <asm/ecard.h>
55 static unsigned int net_debug
= NET_DEBUG
;
57 #define BUFFER_SIZE 0x10000
58 #define TX_AREA_START 0x00100
59 #define TX_AREA_END 0x05000
60 #define RX_AREA_START 0x05000
61 #define RX_AREA_END 0x0fc00
63 static int ether1_open(struct net_device
*dev
);
64 static netdev_tx_t
ether1_sendpacket(struct sk_buff
*skb
,
65 struct net_device
*dev
);
66 static irqreturn_t
ether1_interrupt(int irq
, void *dev_id
);
67 static int ether1_close(struct net_device
*dev
);
68 static void ether1_setmulticastlist(struct net_device
*dev
);
69 static void ether1_timeout(struct net_device
*dev
, unsigned int txqueue
);
71 /* ------------------------------------------------------------------------- */
73 static char version
[] = "ether1 ethernet driver (c) 2000 Russell King v1.07\n";
78 /* ------------------------------------------------------------------------- */
83 #define ether1_readw(dev, addr, type, offset, svflgs) ether1_inw_p (dev, addr + (int)(&((type *)0)->offset), svflgs)
84 #define ether1_writew(dev, val, addr, type, offset, svflgs) ether1_outw_p (dev, val, addr + (int)(&((type *)0)->offset), svflgs)
86 static inline unsigned short
87 ether1_inw_p (struct net_device
*dev
, int addr
, int svflgs
)
93 local_irq_save (flags
);
95 writeb(addr
>> 12, REG_PAGE
);
96 ret
= readw(ETHER1_RAM
+ ((addr
& 4095) << 1));
98 local_irq_restore (flags
);
103 ether1_outw_p (struct net_device
*dev
, unsigned short val
, int addr
, int svflgs
)
108 local_irq_save (flags
);
110 writeb(addr
>> 12, REG_PAGE
);
111 writew(val
, ETHER1_RAM
+ ((addr
& 4095) << 1));
113 local_irq_restore (flags
);
117 * Some inline assembler to allow fast transfers on to/off of the card.
118 * Since this driver depends on some features presented by the ARM
119 * specific architecture, and that you can't configure this driver
120 * without specifiing ARM mode, this is not a problem.
122 * This routine is essentially an optimised memcpy from the card's
123 * onboard RAM to kernel memory.
126 ether1_writebuffer (struct net_device
*dev
, void *data
, unsigned int start
, unsigned int length
)
128 unsigned int page
, thislen
, offset
;
131 offset
= start
& 4095;
133 addr
= ETHER1_RAM
+ (offset
<< 1);
135 if (offset
+ length
> 4096)
136 thislen
= 4096 - offset
;
143 writeb(page
, REG_PAGE
);
146 __asm__
__volatile__(
149 1: ldr %0, [%1], #2\n\
150 mov %0, %0, lsl #16\n\
151 orr %0, %0, %0, lsr #16\n\
156 mov %0, %0, lsl #16\n\
157 orr %0, %0, %0, lsr #16\n\
162 mov %0, %0, lsl #16\n\
163 orr %0, %0, %0, lsr #16\n\
168 mov %0, %0, lsl #16\n\
169 orr %0, %0, %0, lsr #16\n\
173 2: adds %3, %3, #1\n\
176 : "=&r" (used
), "=&r" (data
)
177 : "r" (addr
), "r" (thislen
), "1" (data
));
189 ether1_readbuffer (struct net_device
*dev
, void *data
, unsigned int start
, unsigned int length
)
191 unsigned int page
, thislen
, offset
;
194 offset
= start
& 4095;
196 addr
= ETHER1_RAM
+ (offset
<< 1);
198 if (offset
+ length
> 4096)
199 thislen
= 4096 - offset
;
206 writeb(page
, REG_PAGE
);
209 __asm__
__volatile__(
212 1: ldr %0, [%2], #4\n\
214 mov %0, %0, lsr #8\n\
220 mov %0, %0, lsr #8\n\
226 mov %0, %0, lsr #8\n\
232 mov %0, %0, lsr #8\n\
236 2: adds %3, %3, #1\n\
239 : "=&r" (used
), "=&r" (data
)
240 : "r" (addr
), "r" (thislen
), "1" (data
));
252 ether1_ramtest(struct net_device
*dev
, unsigned char byte
)
254 unsigned char *buffer
= kmalloc (BUFFER_SIZE
, GFP_KERNEL
);
255 int i
, ret
= BUFFER_SIZE
;
263 memset (buffer
, byte
, BUFFER_SIZE
);
264 ether1_writebuffer (dev
, buffer
, 0, BUFFER_SIZE
);
265 memset (buffer
, byte
^ 0xff, BUFFER_SIZE
);
266 ether1_readbuffer (dev
, buffer
, 0, BUFFER_SIZE
);
268 for (i
= 0; i
< BUFFER_SIZE
; i
++) {
269 if (buffer
[i
] != byte
) {
270 if (max_errors
>= 0 && bad
!= buffer
[i
]) {
273 printk (KERN_CRIT
"%s: RAM failed with (%02X instead of %02X) at 0x%04X",
274 dev
->name
, buffer
[i
], byte
, i
);
282 if (bad_start
== i
- 1)
285 printk (" - 0x%04X\n", i
- 1);
292 printk (" - 0x%04X\n", BUFFER_SIZE
);
299 ether1_reset (struct net_device
*dev
)
301 writeb(CTRL_RST
|CTRL_ACK
, REG_CONTROL
);
306 ether1_init_2(struct net_device
*dev
)
311 i
= ether1_ramtest (dev
, 0x5a);
314 i
= ether1_ramtest (dev
, 0x1e);
324 * These are the structures that are loaded into the ether RAM card to
325 * initialise the 82586
329 #define NOP_ADDR (TX_AREA_START)
330 #define NOP_SIZE (0x06)
331 static nop_t init_nop
= {
338 #define TDR_ADDR (0x003a)
339 #define TDR_SIZE (0x08)
340 static tdr_t init_tdr
= {
348 #define MC_ADDR (0x002e)
349 #define MC_SIZE (0x0c)
350 static mc_t init_mc
= {
359 #define SA_ADDR (0x0022)
360 #define SA_SIZE (0x0c)
361 static sa_t init_sa
= {
369 #define CFG_ADDR (0x0010)
370 #define CFG_SIZE (0x12)
371 static cfg_t init_cfg
= {
378 CFG9_PREAMB8
| CFG9_ADDRLENBUF
| CFG9_ADDRLEN(6),
382 CFG13_RETRY(15) | CFG13_SLOTH(2),
387 #define SCB_ADDR (0x0000)
388 #define SCB_SIZE (0x10)
389 static scb_t init_scb
= {
391 SCB_CMDACKRNR
| SCB_CMDACKCNA
| SCB_CMDACKFR
| SCB_CMDACKCX
,
401 #define ISCP_ADDR (0xffee)
402 #define ISCP_SIZE (0x08)
403 static iscp_t init_iscp
= {
411 #define SCP_ADDR (0xfff6)
412 #define SCP_SIZE (0x0a)
413 static scp_t init_scp
= {
420 #define RFD_SIZE (0x16)
421 static rfd_t init_rfd
= {
431 #define RBD_SIZE (0x0a)
432 static rbd_t init_rbd
= {
440 #define TX_SIZE (0x08)
441 #define TBD_SIZE (0x08)
444 ether1_init_for_open (struct net_device
*dev
)
446 int i
, status
, addr
, next
, next2
;
448 unsigned long timeout
;
450 writeb(CTRL_RST
|CTRL_ACK
, REG_CONTROL
);
452 for (i
= 0; i
< 6; i
++)
453 init_sa
.sa_addr
[i
] = dev
->dev_addr
[i
];
455 /* load data structures into ether1 RAM */
456 ether1_writebuffer (dev
, &init_scp
, SCP_ADDR
, SCP_SIZE
);
457 ether1_writebuffer (dev
, &init_iscp
, ISCP_ADDR
, ISCP_SIZE
);
458 ether1_writebuffer (dev
, &init_scb
, SCB_ADDR
, SCB_SIZE
);
459 ether1_writebuffer (dev
, &init_cfg
, CFG_ADDR
, CFG_SIZE
);
460 ether1_writebuffer (dev
, &init_sa
, SA_ADDR
, SA_SIZE
);
461 ether1_writebuffer (dev
, &init_mc
, MC_ADDR
, MC_SIZE
);
462 ether1_writebuffer (dev
, &init_tdr
, TDR_ADDR
, TDR_SIZE
);
463 ether1_writebuffer (dev
, &init_nop
, NOP_ADDR
, NOP_SIZE
);
465 if (ether1_readw(dev
, CFG_ADDR
, cfg_t
, cfg_command
, NORMALIRQS
) != CMD_CONFIG
) {
466 printk (KERN_ERR
"%s: detected either RAM fault or compiler bug\n",
472 * setup circularly linked list of { rfd, rbd, buffer }, with
473 * all rfds circularly linked, rbds circularly linked.
474 * First rfd is linked to scp, first rbd is linked to first
475 * rfd. Last rbd has a suspend command.
477 addr
= RX_AREA_START
;
479 next
= addr
+ RFD_SIZE
+ RBD_SIZE
+ ETH_FRAME_LEN
+ 10;
480 next2
= next
+ RFD_SIZE
+ RBD_SIZE
+ ETH_FRAME_LEN
+ 10;
482 if (next2
>= RX_AREA_END
) {
483 next
= RX_AREA_START
;
484 init_rfd
.rfd_command
= RFD_CMDEL
| RFD_CMDSUSPEND
;
485 priv(dev
)->rx_tail
= addr
;
487 init_rfd
.rfd_command
= 0;
488 if (addr
== RX_AREA_START
)
489 init_rfd
.rfd_rbdoffset
= addr
+ RFD_SIZE
;
491 init_rfd
.rfd_rbdoffset
= 0;
492 init_rfd
.rfd_link
= next
;
493 init_rbd
.rbd_link
= next
+ RFD_SIZE
;
494 init_rbd
.rbd_bufl
= addr
+ RFD_SIZE
+ RBD_SIZE
;
496 ether1_writebuffer (dev
, &init_rfd
, addr
, RFD_SIZE
);
497 ether1_writebuffer (dev
, &init_rbd
, addr
+ RFD_SIZE
, RBD_SIZE
);
499 } while (next2
< RX_AREA_END
);
501 priv(dev
)->tx_link
= NOP_ADDR
;
502 priv(dev
)->tx_head
= NOP_ADDR
+ NOP_SIZE
;
503 priv(dev
)->tx_tail
= TDR_ADDR
;
504 priv(dev
)->rx_head
= RX_AREA_START
;
506 /* release reset & give 586 a prod */
507 priv(dev
)->resetting
= 1;
508 priv(dev
)->initialising
= 1;
509 writeb(CTRL_RST
, REG_CONTROL
);
510 writeb(0, REG_CONTROL
);
511 writeb(CTRL_CA
, REG_CONTROL
);
513 /* 586 should now unset iscp.busy */
514 timeout
= jiffies
+ HZ
/2;
515 while (ether1_readw(dev
, ISCP_ADDR
, iscp_t
, iscp_busy
, DISABLEIRQS
) == 1) {
516 if (time_after(jiffies
, timeout
)) {
517 printk (KERN_WARNING
"%s: can't initialise 82586: iscp is busy\n", dev
->name
);
522 /* check status of commands that we issued */
524 while (((status
= ether1_readw(dev
, CFG_ADDR
, cfg_t
, cfg_status
, DISABLEIRQS
))
525 & STAT_COMPLETE
) == 0) {
526 if (time_after(jiffies
, timeout
))
530 if ((status
& (STAT_COMPLETE
| STAT_OK
)) != (STAT_COMPLETE
| STAT_OK
)) {
531 printk (KERN_WARNING
"%s: can't initialise 82586: config status %04X\n", dev
->name
, status
);
532 printk (KERN_DEBUG
"%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev
->name
,
533 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_status
, NORMALIRQS
),
534 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_command
, NORMALIRQS
),
535 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_cbl_offset
, NORMALIRQS
),
536 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_rfa_offset
, NORMALIRQS
));
541 while (((status
= ether1_readw(dev
, SA_ADDR
, sa_t
, sa_status
, DISABLEIRQS
))
542 & STAT_COMPLETE
) == 0) {
543 if (time_after(jiffies
, timeout
))
547 if ((status
& (STAT_COMPLETE
| STAT_OK
)) != (STAT_COMPLETE
| STAT_OK
)) {
548 printk (KERN_WARNING
"%s: can't initialise 82586: set address status %04X\n", dev
->name
, status
);
549 printk (KERN_DEBUG
"%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev
->name
,
550 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_status
, NORMALIRQS
),
551 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_command
, NORMALIRQS
),
552 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_cbl_offset
, NORMALIRQS
),
553 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_rfa_offset
, NORMALIRQS
));
558 while (((status
= ether1_readw(dev
, MC_ADDR
, mc_t
, mc_status
, DISABLEIRQS
))
559 & STAT_COMPLETE
) == 0) {
560 if (time_after(jiffies
, timeout
))
564 if ((status
& (STAT_COMPLETE
| STAT_OK
)) != (STAT_COMPLETE
| STAT_OK
)) {
565 printk (KERN_WARNING
"%s: can't initialise 82586: set multicast status %04X\n", dev
->name
, status
);
566 printk (KERN_DEBUG
"%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev
->name
,
567 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_status
, NORMALIRQS
),
568 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_command
, NORMALIRQS
),
569 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_cbl_offset
, NORMALIRQS
),
570 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_rfa_offset
, NORMALIRQS
));
575 while (((status
= ether1_readw(dev
, TDR_ADDR
, tdr_t
, tdr_status
, DISABLEIRQS
))
576 & STAT_COMPLETE
) == 0) {
577 if (time_after(jiffies
, timeout
))
581 if ((status
& (STAT_COMPLETE
| STAT_OK
)) != (STAT_COMPLETE
| STAT_OK
)) {
582 printk (KERN_WARNING
"%s: can't tdr (ignored)\n", dev
->name
);
583 printk (KERN_DEBUG
"%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev
->name
,
584 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_status
, NORMALIRQS
),
585 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_command
, NORMALIRQS
),
586 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_cbl_offset
, NORMALIRQS
),
587 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_rfa_offset
, NORMALIRQS
));
589 status
= ether1_readw(dev
, TDR_ADDR
, tdr_t
, tdr_result
, DISABLEIRQS
);
590 if (status
& TDR_XCVRPROB
)
591 printk (KERN_WARNING
"%s: i/f failed tdr: transceiver problem\n", dev
->name
);
592 else if ((status
& (TDR_SHORT
|TDR_OPEN
)) && (status
& TDR_TIME
)) {
594 printk (KERN_WARNING
"%s: i/f failed tdr: cable %s %d.%d us away\n", dev
->name
,
595 status
& TDR_SHORT
? "short" : "open", (status
& TDR_TIME
) / 10,
596 (status
& TDR_TIME
) % 10);
598 printk (KERN_WARNING
"%s: i/f failed tdr: cable %s %d clks away\n", dev
->name
,
599 status
& TDR_SHORT
? "short" : "open", (status
& TDR_TIME
));
606 return failures
? 1 : 0;
609 /* ------------------------------------------------------------------------- */
612 ether1_txalloc (struct net_device
*dev
, int size
)
616 size
= (size
+ 1) & ~1;
617 tail
= priv(dev
)->tx_tail
;
619 if (priv(dev
)->tx_head
+ size
> TX_AREA_END
) {
620 if (tail
> priv(dev
)->tx_head
)
622 start
= TX_AREA_START
;
623 if (start
+ size
> tail
)
625 priv(dev
)->tx_head
= start
+ size
;
627 if (priv(dev
)->tx_head
< tail
&& (priv(dev
)->tx_head
+ size
) > tail
)
629 start
= priv(dev
)->tx_head
;
630 priv(dev
)->tx_head
+= size
;
637 ether1_open (struct net_device
*dev
)
639 if (request_irq(dev
->irq
, ether1_interrupt
, 0, "ether1", dev
))
642 if (ether1_init_for_open (dev
)) {
643 free_irq (dev
->irq
, dev
);
647 netif_start_queue(dev
);
653 ether1_timeout(struct net_device
*dev
, unsigned int txqueue
)
655 printk(KERN_WARNING
"%s: transmit timeout, network cable problem?\n",
657 printk(KERN_WARNING
"%s: resetting device\n", dev
->name
);
661 if (ether1_init_for_open (dev
))
662 printk (KERN_ERR
"%s: unable to restart interface\n", dev
->name
);
664 dev
->stats
.tx_errors
++;
665 netif_wake_queue(dev
);
669 ether1_sendpacket (struct sk_buff
*skb
, struct net_device
*dev
)
671 int tmp
, tst
, nopaddr
, txaddr
, tbdaddr
, dataddr
;
677 if (priv(dev
)->restart
) {
678 printk(KERN_WARNING
"%s: resetting device\n", dev
->name
);
682 if (ether1_init_for_open(dev
))
683 printk(KERN_ERR
"%s: unable to restart interface\n", dev
->name
);
685 priv(dev
)->restart
= 0;
688 if (skb
->len
< ETH_ZLEN
) {
689 if (skb_padto(skb
, ETH_ZLEN
))
694 * insert packet followed by a nop
696 txaddr
= ether1_txalloc (dev
, TX_SIZE
);
697 tbdaddr
= ether1_txalloc (dev
, TBD_SIZE
);
698 dataddr
= ether1_txalloc (dev
, skb
->len
);
699 nopaddr
= ether1_txalloc (dev
, NOP_SIZE
);
702 tx
.tx_command
= CMD_TX
| CMD_INTR
;
703 tx
.tx_link
= nopaddr
;
704 tx
.tx_tbdoffset
= tbdaddr
;
705 tbd
.tbd_opts
= TBD_EOL
| skb
->len
;
706 tbd
.tbd_link
= I82586_NULL
;
707 tbd
.tbd_bufl
= dataddr
;
710 nop
.nop_command
= CMD_NOP
;
711 nop
.nop_link
= nopaddr
;
713 local_irq_save(flags
);
714 ether1_writebuffer (dev
, &tx
, txaddr
, TX_SIZE
);
715 ether1_writebuffer (dev
, &tbd
, tbdaddr
, TBD_SIZE
);
716 ether1_writebuffer (dev
, skb
->data
, dataddr
, skb
->len
);
717 ether1_writebuffer (dev
, &nop
, nopaddr
, NOP_SIZE
);
718 tmp
= priv(dev
)->tx_link
;
719 priv(dev
)->tx_link
= nopaddr
;
721 /* now reset the previous nop pointer */
722 ether1_writew(dev
, txaddr
, tmp
, nop_t
, nop_link
, NORMALIRQS
);
724 local_irq_restore(flags
);
726 /* handle transmit */
728 /* check to see if we have room for a full sized ether frame */
729 tmp
= priv(dev
)->tx_head
;
730 tst
= ether1_txalloc (dev
, TX_SIZE
+ TBD_SIZE
+ NOP_SIZE
+ ETH_FRAME_LEN
);
731 priv(dev
)->tx_head
= tmp
;
735 netif_stop_queue(dev
);
742 ether1_xmit_done (struct net_device
*dev
)
747 caddr
= priv(dev
)->tx_tail
;
750 ether1_readbuffer (dev
, &nop
, caddr
, NOP_SIZE
);
752 switch (nop
.nop_command
& CMD_MASK
) {
755 if (ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_cbl_offset
, NORMALIRQS
)
756 != (unsigned short)I82586_NULL
) {
757 ether1_writew(dev
, SCB_CMDCUCSTART
| SCB_CMDRXSTART
, SCB_ADDR
, scb_t
,
758 scb_command
, NORMALIRQS
);
759 writeb(CTRL_CA
, REG_CONTROL
);
761 priv(dev
)->tx_tail
= NOP_ADDR
;
765 if (nop
.nop_link
== caddr
) {
766 if (priv(dev
)->initialising
== 0)
767 printk (KERN_WARNING
"%s: strange command complete with no tx command!\n", dev
->name
);
769 priv(dev
)->initialising
= 0;
772 if (caddr
== nop
.nop_link
)
774 caddr
= nop
.nop_link
;
778 if (nop
.nop_status
& STAT_COMPLETE
)
780 printk (KERN_ERR
"%s: strange command complete without completed command\n", dev
->name
);
781 priv(dev
)->restart
= 1;
785 printk (KERN_WARNING
"%s: strange command %d complete! (offset %04X)", dev
->name
,
786 nop
.nop_command
& CMD_MASK
, caddr
);
787 priv(dev
)->restart
= 1;
791 while (nop
.nop_status
& STAT_COMPLETE
) {
792 if (nop
.nop_status
& STAT_OK
) {
793 dev
->stats
.tx_packets
++;
794 dev
->stats
.collisions
+= (nop
.nop_status
& STAT_COLLISIONS
);
796 dev
->stats
.tx_errors
++;
798 if (nop
.nop_status
& STAT_COLLAFTERTX
)
799 dev
->stats
.collisions
++;
800 if (nop
.nop_status
& STAT_NOCARRIER
)
801 dev
->stats
.tx_carrier_errors
++;
802 if (nop
.nop_status
& STAT_TXLOSTCTS
)
803 printk (KERN_WARNING
"%s: cts lost\n", dev
->name
);
804 if (nop
.nop_status
& STAT_TXSLOWDMA
)
805 dev
->stats
.tx_fifo_errors
++;
806 if (nop
.nop_status
& STAT_COLLEXCESSIVE
)
807 dev
->stats
.collisions
+= 16;
810 if (nop
.nop_link
== caddr
) {
811 printk (KERN_ERR
"%s: tx buffer chaining error: tx command points to itself\n", dev
->name
);
815 caddr
= nop
.nop_link
;
816 ether1_readbuffer (dev
, &nop
, caddr
, NOP_SIZE
);
817 if ((nop
.nop_command
& CMD_MASK
) != CMD_NOP
) {
818 printk (KERN_ERR
"%s: tx buffer chaining error: no nop after tx command\n", dev
->name
);
822 if (caddr
== nop
.nop_link
)
825 caddr
= nop
.nop_link
;
826 ether1_readbuffer (dev
, &nop
, caddr
, NOP_SIZE
);
827 if ((nop
.nop_command
& CMD_MASK
) != CMD_TX
) {
828 printk (KERN_ERR
"%s: tx buffer chaining error: no tx command after nop\n", dev
->name
);
832 priv(dev
)->tx_tail
= caddr
;
834 caddr
= priv(dev
)->tx_head
;
835 tst
= ether1_txalloc (dev
, TX_SIZE
+ TBD_SIZE
+ NOP_SIZE
+ ETH_FRAME_LEN
);
836 priv(dev
)->tx_head
= caddr
;
838 netif_wake_queue(dev
);
842 ether1_recv_done (struct net_device
*dev
)
845 int nexttail
, rbdaddr
;
849 status
= ether1_readw(dev
, priv(dev
)->rx_head
, rfd_t
, rfd_status
, NORMALIRQS
);
850 if ((status
& RFD_COMPLETE
) == 0)
853 rbdaddr
= ether1_readw(dev
, priv(dev
)->rx_head
, rfd_t
, rfd_rbdoffset
, NORMALIRQS
);
854 ether1_readbuffer (dev
, &rbd
, rbdaddr
, RBD_SIZE
);
856 if ((rbd
.rbd_status
& (RBD_EOF
| RBD_ACNTVALID
)) == (RBD_EOF
| RBD_ACNTVALID
)) {
857 int length
= rbd
.rbd_status
& RBD_ACNT
;
860 length
= (length
+ 1) & ~1;
861 skb
= netdev_alloc_skb(dev
, length
+ 2);
864 skb_reserve (skb
, 2);
866 ether1_readbuffer (dev
, skb_put (skb
, length
), rbd
.rbd_bufl
, length
);
868 skb
->protocol
= eth_type_trans (skb
, dev
);
870 dev
->stats
.rx_packets
++;
872 dev
->stats
.rx_dropped
++;
874 printk(KERN_WARNING
"%s: %s\n", dev
->name
,
875 (rbd
.rbd_status
& RBD_EOF
) ? "oversized packet" : "acnt not valid");
876 dev
->stats
.rx_dropped
++;
879 nexttail
= ether1_readw(dev
, priv(dev
)->rx_tail
, rfd_t
, rfd_link
, NORMALIRQS
);
880 /* nexttail should be rx_head */
881 if (nexttail
!= priv(dev
)->rx_head
)
882 printk(KERN_ERR
"%s: receiver buffer chaining error (%04X != %04X)\n",
883 dev
->name
, nexttail
, priv(dev
)->rx_head
);
884 ether1_writew(dev
, RFD_CMDEL
| RFD_CMDSUSPEND
, nexttail
, rfd_t
, rfd_command
, NORMALIRQS
);
885 ether1_writew(dev
, 0, priv(dev
)->rx_tail
, rfd_t
, rfd_command
, NORMALIRQS
);
886 ether1_writew(dev
, 0, priv(dev
)->rx_tail
, rfd_t
, rfd_status
, NORMALIRQS
);
887 ether1_writew(dev
, 0, priv(dev
)->rx_tail
, rfd_t
, rfd_rbdoffset
, NORMALIRQS
);
889 priv(dev
)->rx_tail
= nexttail
;
890 priv(dev
)->rx_head
= ether1_readw(dev
, priv(dev
)->rx_head
, rfd_t
, rfd_link
, NORMALIRQS
);
895 ether1_interrupt (int irq
, void *dev_id
)
897 struct net_device
*dev
= (struct net_device
*)dev_id
;
900 status
= ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_status
, NORMALIRQS
);
903 ether1_writew(dev
, status
& (SCB_STRNR
| SCB_STCNA
| SCB_STFR
| SCB_STCX
),
904 SCB_ADDR
, scb_t
, scb_command
, NORMALIRQS
);
905 writeb(CTRL_CA
| CTRL_ACK
, REG_CONTROL
);
906 if (status
& SCB_STCX
) {
907 ether1_xmit_done (dev
);
909 if (status
& SCB_STCNA
) {
910 if (priv(dev
)->resetting
== 0)
911 printk (KERN_WARNING
"%s: CU went not ready ???\n", dev
->name
);
913 priv(dev
)->resetting
+= 1;
914 if (ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_cbl_offset
, NORMALIRQS
)
915 != (unsigned short)I82586_NULL
) {
916 ether1_writew(dev
, SCB_CMDCUCSTART
, SCB_ADDR
, scb_t
, scb_command
, NORMALIRQS
);
917 writeb(CTRL_CA
, REG_CONTROL
);
919 if (priv(dev
)->resetting
== 2)
920 priv(dev
)->resetting
= 0;
922 if (status
& SCB_STFR
) {
923 ether1_recv_done (dev
);
925 if (status
& SCB_STRNR
) {
926 if (ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_status
, NORMALIRQS
) & SCB_STRXSUSP
) {
927 printk (KERN_WARNING
"%s: RU went not ready: RU suspended\n", dev
->name
);
928 ether1_writew(dev
, SCB_CMDRXRESUME
, SCB_ADDR
, scb_t
, scb_command
, NORMALIRQS
);
929 writeb(CTRL_CA
, REG_CONTROL
);
930 dev
->stats
.rx_dropped
++; /* we suspended due to lack of buffer space */
932 printk(KERN_WARNING
"%s: RU went not ready: %04X\n", dev
->name
,
933 ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_status
, NORMALIRQS
));
934 printk (KERN_WARNING
"RU ptr = %04X\n", ether1_readw(dev
, SCB_ADDR
, scb_t
, scb_rfa_offset
,
938 writeb(CTRL_ACK
, REG_CONTROL
);
944 ether1_close (struct net_device
*dev
)
948 free_irq(dev
->irq
, dev
);
954 * Set or clear the multicast filter for this adaptor.
955 * num_addrs == -1 Promiscuous mode, receive all packets.
956 * num_addrs == 0 Normal mode, clear multicast list.
957 * num_addrs > 0 Multicast mode, receive normal and MC packets, and do
958 * best-effort filtering.
961 ether1_setmulticastlist (struct net_device
*dev
)
965 /* ------------------------------------------------------------------------- */
967 static void ether1_banner(void)
969 static unsigned int version_printed
= 0;
971 if (net_debug
&& version_printed
++ == 0)
972 printk(KERN_INFO
"%s", version
);
975 static const struct net_device_ops ether1_netdev_ops
= {
976 .ndo_open
= ether1_open
,
977 .ndo_stop
= ether1_close
,
978 .ndo_start_xmit
= ether1_sendpacket
,
979 .ndo_set_rx_mode
= ether1_setmulticastlist
,
980 .ndo_tx_timeout
= ether1_timeout
,
981 .ndo_validate_addr
= eth_validate_addr
,
982 .ndo_set_mac_address
= eth_mac_addr
,
986 ether1_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
988 struct net_device
*dev
;
993 ret
= ecard_request_resources(ec
);
997 dev
= alloc_etherdev(sizeof(struct ether1_priv
));
1003 SET_NETDEV_DEV(dev
, &ec
->dev
);
1006 priv(dev
)->base
= ecardm_iomap(ec
, ECARD_RES_IOCFAST
, 0, 0);
1007 if (!priv(dev
)->base
) {
1012 if ((priv(dev
)->bus_type
= ether1_reset(dev
)) == 0) {
1017 for (i
= 0; i
< 6; i
++)
1018 dev
->dev_addr
[i
] = readb(IDPROM_ADDRESS
+ (i
<< 2));
1020 if (ether1_init_2(dev
)) {
1025 dev
->netdev_ops
= ðer1_netdev_ops
;
1026 dev
->watchdog_timeo
= 5 * HZ
/ 100;
1028 ret
= register_netdev(dev
);
1032 printk(KERN_INFO
"%s: ether1 in slot %d, %pM\n",
1033 dev
->name
, ec
->slot_no
, dev
->dev_addr
);
1035 ecard_set_drvdata(ec
, dev
);
1041 ecard_release_resources(ec
);
1046 static void ether1_remove(struct expansion_card
*ec
)
1048 struct net_device
*dev
= ecard_get_drvdata(ec
);
1050 ecard_set_drvdata(ec
, NULL
);
1052 unregister_netdev(dev
);
1054 ecard_release_resources(ec
);
1057 static const struct ecard_id ether1_ids
[] = {
1058 { MANU_ACORN
, PROD_ACORN_ETHER1
},
1062 static struct ecard_driver ether1_driver
= {
1063 .probe
= ether1_probe
,
1064 .remove
= ether1_remove
,
1065 .id_table
= ether1_ids
,
1071 static int __init
ether1_init(void)
1073 return ecard_register_driver(ðer1_driver
);
1076 static void __exit
ether1_exit(void)
1078 ecard_remove_driver(ðer1_driver
);
1081 module_init(ether1_init
);
1082 module_exit(ether1_exit
);
1084 MODULE_LICENSE("GPL");