2 * linux/drivers/acorn/net/ether1.c
4 * Copyright (C) 1996-2000 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Acorn ether1 driver (82586 chip) for Acorn machines
12 * We basically keep two queues in the cards memory - one for transmit
13 * and one for receive. Each has a head and a tail. The head is where
14 * we/the chip adds packets to be transmitted/received, and the tail
15 * is where the transmitter has got to/where the receiver will stop.
16 * Both of these queues are circular, and since the chip is running
17 * all the time, we have to be careful when we modify the pointers etc
18 * so that the buffer memory contents is valid all the time.
22 * 1.01 RMK 19/03/1996 Transfers the last odd byte onto/off of the card now.
23 * 1.02 RMK 25/05/1997 Added code to restart RU if it goes not ready
24 * 1.03 RMK 14/09/1997 Cleaned up the handling of a reset during the TX interrupt.
25 * Should prevent lockup.
26 * 1.04 RMK 17/09/1997 Added more info when initialsation of chip goes wrong.
27 * TDR now only reports failure when chip reports non-zero
29 * 1.05 RMK 31/12/1997 Removed calls to dev_tint for 2.1
30 * 1.06 RMK 10/02/2000 Updated for 2.3.43
31 * 1.07 RMK 13/05/2000 Updated for 2.3.99-pre8
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/types.h>
37 #include <linux/fcntl.h>
38 #include <linux/interrupt.h>
39 #include <linux/ptrace.h>
40 #include <linux/ioport.h>
42 #include <linux/slab.h>
43 #include <linux/string.h>
44 #include <linux/errno.h>
45 #include <linux/device.h>
46 #include <linux/init.h>
47 #include <linux/netdevice.h>
48 #include <linux/etherdevice.h>
49 #include <linux/skbuff.h>
50 #include <linux/bitops.h>
52 #include <asm/system.h>
55 #include <asm/ecard.h>
60 static unsigned int net_debug = NET_DEBUG;
62 #define BUFFER_SIZE 0x10000
63 #define TX_AREA_START 0x00100
64 #define TX_AREA_END 0x05000
65 #define RX_AREA_START 0x05000
66 #define RX_AREA_END 0x0fc00
68 static int ether1_open(struct net_device *dev);
69 static int ether1_sendpacket(struct sk_buff *skb, struct net_device *dev);
70 static irqreturn_t ether1_interrupt(int irq, void *dev_id);
71 static int ether1_close(struct net_device *dev);
72 static struct net_device_stats *ether1_getstats(struct net_device *dev);
73 static void ether1_setmulticastlist(struct net_device *dev);
74 static void ether1_timeout(struct net_device *dev);
76 /* ------------------------------------------------------------------------- */
78 static char version[] __initdata = "ether1 ethernet driver (c) 2000 Russell King v1.07\n";
83 /* ------------------------------------------------------------------------- */
88 #define ether1_readw(dev, addr, type, offset, svflgs) ether1_inw_p (dev, addr + (int)(&((type *)0)->offset), svflgs)
89 #define ether1_writew(dev, val, addr, type, offset, svflgs) ether1_outw_p (dev, val, addr + (int)(&((type *)0)->offset), svflgs)
91 static inline unsigned short
92 ether1_inw_p (struct net_device *dev, int addr, int svflgs)
98 local_irq_save (flags);
100 writeb(addr >> 12, REG_PAGE);
101 ret = readw(ETHER1_RAM + ((addr & 4095) << 1));
103 local_irq_restore (flags);
108 ether1_outw_p (struct net_device *dev, unsigned short val, int addr, int svflgs)
113 local_irq_save (flags);
115 writeb(addr >> 12, REG_PAGE);
116 writew(val, ETHER1_RAM + ((addr & 4095) << 1));
118 local_irq_restore (flags);
122 * Some inline assembler to allow fast transfers on to/off of the card.
123 * Since this driver depends on some features presented by the ARM
124 * specific architecture, and that you can't configure this driver
125 * without specifiing ARM mode, this is not a problem.
127 * This routine is essentially an optimised memcpy from the card's
128 * onboard RAM to kernel memory.
131 ether1_writebuffer (struct net_device *dev, void *data, unsigned int start, unsigned int length)
133 unsigned int page, thislen, offset;
136 offset = start & 4095;
138 addr = ETHER1_RAM + (offset << 1);
140 if (offset + length > 4096)
141 thislen = 4096 - offset;
148 writeb(page, REG_PAGE);
151 __asm__ __volatile__(
154 1: ldr %0, [%1], #2\n\
155 mov %0, %0, lsl #16\n\
156 orr %0, %0, %0, lsr #16\n\
161 mov %0, %0, lsl #16\n\
162 orr %0, %0, %0, lsr #16\n\
167 mov %0, %0, lsl #16\n\
168 orr %0, %0, %0, lsr #16\n\
173 mov %0, %0, lsl #16\n\
174 orr %0, %0, %0, lsr #16\n\
178 2: adds %3, %3, #1\n\
181 : "=&r" (used), "=&r" (data)
182 : "r" (addr), "r" (thislen), "1" (data));
194 ether1_readbuffer (struct net_device *dev, void *data, unsigned int start, unsigned int length)
196 unsigned int page, thislen, offset;
199 offset = start & 4095;
201 addr = ETHER1_RAM + (offset << 1);
203 if (offset + length > 4096)
204 thislen = 4096 - offset;
211 writeb(page, REG_PAGE);
214 __asm__ __volatile__(
217 1: ldr %0, [%2], #4\n\
219 mov %0, %0, lsr #8\n\
225 mov %0, %0, lsr #8\n\
231 mov %0, %0, lsr #8\n\
237 mov %0, %0, lsr #8\n\
241 2: adds %3, %3, #1\n\
244 : "=&r" (used), "=&r" (data)
245 : "r" (addr), "r" (thislen), "1" (data));
257 ether1_ramtest(struct net_device *dev, unsigned char byte)
259 unsigned char *buffer = kmalloc (BUFFER_SIZE, GFP_KERNEL);
260 int i, ret = BUFFER_SIZE;
268 memset (buffer, byte, BUFFER_SIZE);
269 ether1_writebuffer (dev, buffer, 0, BUFFER_SIZE);
270 memset (buffer, byte ^ 0xff, BUFFER_SIZE);
271 ether1_readbuffer (dev, buffer, 0, BUFFER_SIZE);
273 for (i = 0; i < BUFFER_SIZE; i++) {
274 if (buffer[i] != byte) {
275 if (max_errors >= 0 && bad != buffer[i]) {
278 printk (KERN_CRIT "%s: RAM failed with (%02X instead of %02X) at 0x%04X",
279 dev->name, buffer[i], byte, i);
287 if (bad_start == i - 1)
290 printk (" - 0x%04X\n", i - 1);
297 printk (" - 0x%04X\n", BUFFER_SIZE);
304 ether1_reset (struct net_device *dev)
306 writeb(CTRL_RST|CTRL_ACK, REG_CONTROL);
311 ether1_init_2(struct net_device *dev)
316 i = ether1_ramtest (dev, 0x5a);
319 i = ether1_ramtest (dev, 0x1e);
329 * These are the structures that are loaded into the ether RAM card to
330 * initialise the 82586
334 #define NOP_ADDR (TX_AREA_START)
335 #define NOP_SIZE (0x06)
336 static nop_t init_nop = {
343 #define TDR_ADDR (0x003a)
344 #define TDR_SIZE (0x08)
345 static tdr_t init_tdr = {
353 #define MC_ADDR (0x002e)
354 #define MC_SIZE (0x0c)
355 static mc_t init_mc = {
364 #define SA_ADDR (0x0022)
365 #define SA_SIZE (0x0c)
366 static sa_t init_sa = {
374 #define CFG_ADDR (0x0010)
375 #define CFG_SIZE (0x12)
376 static cfg_t init_cfg = {
383 CFG9_PREAMB8 | CFG9_ADDRLENBUF | CFG9_ADDRLEN(6),
387 CFG13_RETRY(15) | CFG13_SLOTH(2),
392 #define SCB_ADDR (0x0000)
393 #define SCB_SIZE (0x10)
394 static scb_t init_scb = {
396 SCB_CMDACKRNR | SCB_CMDACKCNA | SCB_CMDACKFR | SCB_CMDACKCX,
406 #define ISCP_ADDR (0xffee)
407 #define ISCP_SIZE (0x08)
408 static iscp_t init_iscp = {
416 #define SCP_ADDR (0xfff6)
417 #define SCP_SIZE (0x0a)
418 static scp_t init_scp = {
425 #define RFD_SIZE (0x16)
426 static rfd_t init_rfd = {
436 #define RBD_SIZE (0x0a)
437 static rbd_t init_rbd = {
445 #define TX_SIZE (0x08)
446 #define TBD_SIZE (0x08)
449 ether1_init_for_open (struct net_device *dev)
451 int i, status, addr, next, next2;
453 unsigned long timeout;
455 writeb(CTRL_RST|CTRL_ACK, REG_CONTROL);
457 for (i = 0; i < 6; i++)
458 init_sa.sa_addr[i] = dev->dev_addr[i];
460 /* load data structures into ether1 RAM */
461 ether1_writebuffer (dev, &init_scp, SCP_ADDR, SCP_SIZE);
462 ether1_writebuffer (dev, &init_iscp, ISCP_ADDR, ISCP_SIZE);
463 ether1_writebuffer (dev, &init_scb, SCB_ADDR, SCB_SIZE);
464 ether1_writebuffer (dev, &init_cfg, CFG_ADDR, CFG_SIZE);
465 ether1_writebuffer (dev, &init_sa, SA_ADDR, SA_SIZE);
466 ether1_writebuffer (dev, &init_mc, MC_ADDR, MC_SIZE);
467 ether1_writebuffer (dev, &init_tdr, TDR_ADDR, TDR_SIZE);
468 ether1_writebuffer (dev, &init_nop, NOP_ADDR, NOP_SIZE);
470 if (ether1_readw(dev, CFG_ADDR, cfg_t, cfg_command, NORMALIRQS) != CMD_CONFIG) {
471 printk (KERN_ERR "%s: detected either RAM fault or compiler bug\n",
477 * setup circularly linked list of { rfd, rbd, buffer }, with
478 * all rfds circularly linked, rbds circularly linked.
479 * First rfd is linked to scp, first rbd is linked to first
480 * rfd. Last rbd has a suspend command.
482 addr = RX_AREA_START;
484 next = addr + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;
485 next2 = next + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;
487 if (next2 >= RX_AREA_END) {
488 next = RX_AREA_START;
489 init_rfd.rfd_command = RFD_CMDEL | RFD_CMDSUSPEND;
490 priv(dev)->rx_tail = addr;
492 init_rfd.rfd_command = 0;
493 if (addr == RX_AREA_START)
494 init_rfd.rfd_rbdoffset = addr + RFD_SIZE;
496 init_rfd.rfd_rbdoffset = 0;
497 init_rfd.rfd_link = next;
498 init_rbd.rbd_link = next + RFD_SIZE;
499 init_rbd.rbd_bufl = addr + RFD_SIZE + RBD_SIZE;
501 ether1_writebuffer (dev, &init_rfd, addr, RFD_SIZE);
502 ether1_writebuffer (dev, &init_rbd, addr + RFD_SIZE, RBD_SIZE);
504 } while (next2 < RX_AREA_END);
506 priv(dev)->tx_link = NOP_ADDR;
507 priv(dev)->tx_head = NOP_ADDR + NOP_SIZE;
508 priv(dev)->tx_tail = TDR_ADDR;
509 priv(dev)->rx_head = RX_AREA_START;
511 /* release reset & give 586 a prod */
512 priv(dev)->resetting = 1;
513 priv(dev)->initialising = 1;
514 writeb(CTRL_RST, REG_CONTROL);
515 writeb(0, REG_CONTROL);
516 writeb(CTRL_CA, REG_CONTROL);
518 /* 586 should now unset iscp.busy */
519 timeout = jiffies + HZ/2;
520 while (ether1_readw(dev, ISCP_ADDR, iscp_t, iscp_busy, DISABLEIRQS) == 1) {
521 if (time_after(jiffies, timeout)) {
522 printk (KERN_WARNING "%s: can't initialise 82586: iscp is busy\n", dev->name);
527 /* check status of commands that we issued */
529 while (((status = ether1_readw(dev, CFG_ADDR, cfg_t, cfg_status, DISABLEIRQS))
530 & STAT_COMPLETE) == 0) {
531 if (time_after(jiffies, timeout))
535 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
536 printk (KERN_WARNING "%s: can't initialise 82586: config status %04X\n", dev->name, status);
537 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
538 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
539 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
540 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
541 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
546 while (((status = ether1_readw(dev, SA_ADDR, sa_t, sa_status, DISABLEIRQS))
547 & STAT_COMPLETE) == 0) {
548 if (time_after(jiffies, timeout))
552 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
553 printk (KERN_WARNING "%s: can't initialise 82586: set address status %04X\n", dev->name, status);
554 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
555 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
556 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
557 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
558 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
563 while (((status = ether1_readw(dev, MC_ADDR, mc_t, mc_status, DISABLEIRQS))
564 & STAT_COMPLETE) == 0) {
565 if (time_after(jiffies, timeout))
569 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
570 printk (KERN_WARNING "%s: can't initialise 82586: set multicast status %04X\n", dev->name, status);
571 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
572 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
573 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
574 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
575 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
580 while (((status = ether1_readw(dev, TDR_ADDR, tdr_t, tdr_status, DISABLEIRQS))
581 & STAT_COMPLETE) == 0) {
582 if (time_after(jiffies, timeout))
586 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
587 printk (KERN_WARNING "%s: can't tdr (ignored)\n", dev->name);
588 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
589 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
590 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
591 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
592 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
594 status = ether1_readw(dev, TDR_ADDR, tdr_t, tdr_result, DISABLEIRQS);
595 if (status & TDR_XCVRPROB)
596 printk (KERN_WARNING "%s: i/f failed tdr: transceiver problem\n", dev->name);
597 else if ((status & (TDR_SHORT|TDR_OPEN)) && (status & TDR_TIME)) {
599 printk (KERN_WARNING "%s: i/f failed tdr: cable %s %d.%d us away\n", dev->name,
600 status & TDR_SHORT ? "short" : "open", (status & TDR_TIME) / 10,
601 (status & TDR_TIME) % 10);
603 printk (KERN_WARNING "%s: i/f failed tdr: cable %s %d clks away\n", dev->name,
604 status & TDR_SHORT ? "short" : "open", (status & TDR_TIME));
611 return failures ? 1 : 0;
614 /* ------------------------------------------------------------------------- */
617 ether1_txalloc (struct net_device *dev, int size)
621 size = (size + 1) & ~1;
622 tail = priv(dev)->tx_tail;
624 if (priv(dev)->tx_head + size > TX_AREA_END) {
625 if (tail > priv(dev)->tx_head)
627 start = TX_AREA_START;
628 if (start + size > tail)
630 priv(dev)->tx_head = start + size;
632 if (priv(dev)->tx_head < tail && (priv(dev)->tx_head + size) > tail)
634 start = priv(dev)->tx_head;
635 priv(dev)->tx_head += size;
642 ether1_open (struct net_device *dev)
644 if (!is_valid_ether_addr(dev->dev_addr)) {
645 printk(KERN_WARNING "%s: invalid ethernet MAC address\n",
650 if (request_irq(dev->irq, ether1_interrupt, 0, "ether1", dev))
653 memset (&priv(dev)->stats, 0, sizeof (struct net_device_stats));
655 if (ether1_init_for_open (dev)) {
656 free_irq (dev->irq, dev);
660 netif_start_queue(dev);
666 ether1_timeout(struct net_device *dev)
668 printk(KERN_WARNING "%s: transmit timeout, network cable problem?\n",
670 printk(KERN_WARNING "%s: resetting device\n", dev->name);
674 if (ether1_init_for_open (dev))
675 printk (KERN_ERR "%s: unable to restart interface\n", dev->name);
677 priv(dev)->stats.tx_errors++;
678 netif_wake_queue(dev);
682 ether1_sendpacket (struct sk_buff *skb, struct net_device *dev)
684 int tmp, tst, nopaddr, txaddr, tbdaddr, dataddr;
690 if (priv(dev)->restart) {
691 printk(KERN_WARNING "%s: resetting device\n", dev->name);
695 if (ether1_init_for_open(dev))
696 printk(KERN_ERR "%s: unable to restart interface\n", dev->name);
698 priv(dev)->restart = 0;
701 if (skb->len < ETH_ZLEN) {
702 if (skb_padto(skb, ETH_ZLEN))
707 * insert packet followed by a nop
709 txaddr = ether1_txalloc (dev, TX_SIZE);
710 tbdaddr = ether1_txalloc (dev, TBD_SIZE);
711 dataddr = ether1_txalloc (dev, skb->len);
712 nopaddr = ether1_txalloc (dev, NOP_SIZE);
715 tx.tx_command = CMD_TX | CMD_INTR;
716 tx.tx_link = nopaddr;
717 tx.tx_tbdoffset = tbdaddr;
718 tbd.tbd_opts = TBD_EOL | skb->len;
719 tbd.tbd_link = I82586_NULL;
720 tbd.tbd_bufl = dataddr;
723 nop.nop_command = CMD_NOP;
724 nop.nop_link = nopaddr;
726 local_irq_save(flags);
727 ether1_writebuffer (dev, &tx, txaddr, TX_SIZE);
728 ether1_writebuffer (dev, &tbd, tbdaddr, TBD_SIZE);
729 ether1_writebuffer (dev, skb->data, dataddr, skb->len);
730 ether1_writebuffer (dev, &nop, nopaddr, NOP_SIZE);
731 tmp = priv(dev)->tx_link;
732 priv(dev)->tx_link = nopaddr;
734 /* now reset the previous nop pointer */
735 ether1_writew(dev, txaddr, tmp, nop_t, nop_link, NORMALIRQS);
737 local_irq_restore(flags);
739 /* handle transmit */
740 dev->trans_start = jiffies;
742 /* check to see if we have room for a full sized ether frame */
743 tmp = priv(dev)->tx_head;
744 tst = ether1_txalloc (dev, TX_SIZE + TBD_SIZE + NOP_SIZE + ETH_FRAME_LEN);
745 priv(dev)->tx_head = tmp;
749 netif_stop_queue(dev);
756 ether1_xmit_done (struct net_device *dev)
761 caddr = priv(dev)->tx_tail;
764 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
766 switch (nop.nop_command & CMD_MASK) {
769 if (ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS)
770 != (unsigned short)I82586_NULL) {
771 ether1_writew(dev, SCB_CMDCUCSTART | SCB_CMDRXSTART, SCB_ADDR, scb_t,
772 scb_command, NORMALIRQS);
773 writeb(CTRL_CA, REG_CONTROL);
775 priv(dev)->tx_tail = NOP_ADDR;
779 if (nop.nop_link == caddr) {
780 if (priv(dev)->initialising == 0)
781 printk (KERN_WARNING "%s: strange command complete with no tx command!\n", dev->name);
783 priv(dev)->initialising = 0;
786 if (caddr == nop.nop_link)
788 caddr = nop.nop_link;
792 if (nop.nop_status & STAT_COMPLETE)
794 printk (KERN_ERR "%s: strange command complete without completed command\n", dev->name);
795 priv(dev)->restart = 1;
799 printk (KERN_WARNING "%s: strange command %d complete! (offset %04X)", dev->name,
800 nop.nop_command & CMD_MASK, caddr);
801 priv(dev)->restart = 1;
805 while (nop.nop_status & STAT_COMPLETE) {
806 if (nop.nop_status & STAT_OK) {
807 priv(dev)->stats.tx_packets ++;
808 priv(dev)->stats.collisions += (nop.nop_status & STAT_COLLISIONS);
810 priv(dev)->stats.tx_errors ++;
812 if (nop.nop_status & STAT_COLLAFTERTX)
813 priv(dev)->stats.collisions ++;
814 if (nop.nop_status & STAT_NOCARRIER)
815 priv(dev)->stats.tx_carrier_errors ++;
816 if (nop.nop_status & STAT_TXLOSTCTS)
817 printk (KERN_WARNING "%s: cts lost\n", dev->name);
818 if (nop.nop_status & STAT_TXSLOWDMA)
819 priv(dev)->stats.tx_fifo_errors ++;
820 if (nop.nop_status & STAT_COLLEXCESSIVE)
821 priv(dev)->stats.collisions += 16;
824 if (nop.nop_link == caddr) {
825 printk (KERN_ERR "%s: tx buffer chaining error: tx command points to itself\n", dev->name);
829 caddr = nop.nop_link;
830 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
831 if ((nop.nop_command & CMD_MASK) != CMD_NOP) {
832 printk (KERN_ERR "%s: tx buffer chaining error: no nop after tx command\n", dev->name);
836 if (caddr == nop.nop_link)
839 caddr = nop.nop_link;
840 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
841 if ((nop.nop_command & CMD_MASK) != CMD_TX) {
842 printk (KERN_ERR "%s: tx buffer chaining error: no tx command after nop\n", dev->name);
846 priv(dev)->tx_tail = caddr;
848 caddr = priv(dev)->tx_head;
849 tst = ether1_txalloc (dev, TX_SIZE + TBD_SIZE + NOP_SIZE + ETH_FRAME_LEN);
850 priv(dev)->tx_head = caddr;
852 netif_wake_queue(dev);
856 ether1_recv_done (struct net_device *dev)
859 int nexttail, rbdaddr;
863 status = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_status, NORMALIRQS);
864 if ((status & RFD_COMPLETE) == 0)
867 rbdaddr = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_rbdoffset, NORMALIRQS);
868 ether1_readbuffer (dev, &rbd, rbdaddr, RBD_SIZE);
870 if ((rbd.rbd_status & (RBD_EOF | RBD_ACNTVALID)) == (RBD_EOF | RBD_ACNTVALID)) {
871 int length = rbd.rbd_status & RBD_ACNT;
874 length = (length + 1) & ~1;
875 skb = dev_alloc_skb (length + 2);
878 skb_reserve (skb, 2);
880 ether1_readbuffer (dev, skb_put (skb, length), rbd.rbd_bufl, length);
882 skb->protocol = eth_type_trans (skb, dev);
884 priv(dev)->stats.rx_packets ++;
886 priv(dev)->stats.rx_dropped ++;
888 printk(KERN_WARNING "%s: %s\n", dev->name,
889 (rbd.rbd_status & RBD_EOF) ? "oversized packet" : "acnt not valid");
890 priv(dev)->stats.rx_dropped ++;
893 nexttail = ether1_readw(dev, priv(dev)->rx_tail, rfd_t, rfd_link, NORMALIRQS);
894 /* nexttail should be rx_head */
895 if (nexttail != priv(dev)->rx_head)
896 printk(KERN_ERR "%s: receiver buffer chaining error (%04X != %04X)\n",
897 dev->name, nexttail, priv(dev)->rx_head);
898 ether1_writew(dev, RFD_CMDEL | RFD_CMDSUSPEND, nexttail, rfd_t, rfd_command, NORMALIRQS);
899 ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_command, NORMALIRQS);
900 ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_status, NORMALIRQS);
901 ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_rbdoffset, NORMALIRQS);
903 priv(dev)->rx_tail = nexttail;
904 priv(dev)->rx_head = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_link, NORMALIRQS);
909 ether1_interrupt (int irq, void *dev_id)
911 struct net_device *dev = (struct net_device *)dev_id;
914 status = ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS);
917 ether1_writew(dev, status & (SCB_STRNR | SCB_STCNA | SCB_STFR | SCB_STCX),
918 SCB_ADDR, scb_t, scb_command, NORMALIRQS);
919 writeb(CTRL_CA | CTRL_ACK, REG_CONTROL);
920 if (status & SCB_STCX) {
921 ether1_xmit_done (dev);
923 if (status & SCB_STCNA) {
924 if (priv(dev)->resetting == 0)
925 printk (KERN_WARNING "%s: CU went not ready ???\n", dev->name);
927 priv(dev)->resetting += 1;
928 if (ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS)
929 != (unsigned short)I82586_NULL) {
930 ether1_writew(dev, SCB_CMDCUCSTART, SCB_ADDR, scb_t, scb_command, NORMALIRQS);
931 writeb(CTRL_CA, REG_CONTROL);
933 if (priv(dev)->resetting == 2)
934 priv(dev)->resetting = 0;
936 if (status & SCB_STFR) {
937 ether1_recv_done (dev);
939 if (status & SCB_STRNR) {
940 if (ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS) & SCB_STRXSUSP) {
941 printk (KERN_WARNING "%s: RU went not ready: RU suspended\n", dev->name);
942 ether1_writew(dev, SCB_CMDRXRESUME, SCB_ADDR, scb_t, scb_command, NORMALIRQS);
943 writeb(CTRL_CA, REG_CONTROL);
944 priv(dev)->stats.rx_dropped ++; /* we suspended due to lack of buffer space */
946 printk(KERN_WARNING "%s: RU went not ready: %04X\n", dev->name,
947 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS));
948 printk (KERN_WARNING "RU ptr = %04X\n", ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset,
952 writeb(CTRL_ACK, REG_CONTROL);
958 ether1_close (struct net_device *dev)
962 free_irq(dev->irq, dev);
967 static struct net_device_stats *
968 ether1_getstats (struct net_device *dev)
970 return &priv(dev)->stats;
974 * Set or clear the multicast filter for this adaptor.
975 * num_addrs == -1 Promiscuous mode, receive all packets.
976 * num_addrs == 0 Normal mode, clear multicast list.
977 * num_addrs > 0 Multicast mode, receive normal and MC packets, and do
978 * best-effort filtering.
981 ether1_setmulticastlist (struct net_device *dev)
985 /* ------------------------------------------------------------------------- */
987 static void __devinit ether1_banner(void)
989 static unsigned int version_printed = 0;
991 if (net_debug && version_printed++ == 0)
992 printk(KERN_INFO "%s", version);
996 ether1_probe(struct expansion_card *ec, const struct ecard_id *id)
998 struct net_device *dev;
1003 ret = ecard_request_resources(ec);
1007 dev = alloc_etherdev(sizeof(struct ether1_priv));
1013 SET_MODULE_OWNER(dev);
1014 SET_NETDEV_DEV(dev, &ec->dev);
1017 priv(dev)->base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST),
1018 ecard_resource_len(ec, ECARD_RES_IOCFAST));
1019 if (!priv(dev)->base) {
1024 if ((priv(dev)->bus_type = ether1_reset(dev)) == 0) {
1029 for (i = 0; i < 6; i++)
1030 dev->dev_addr[i] = readb(IDPROM_ADDRESS + (i << 2));
1032 if (ether1_init_2(dev)) {
1037 dev->open = ether1_open;
1038 dev->stop = ether1_close;
1039 dev->hard_start_xmit = ether1_sendpacket;
1040 dev->get_stats = ether1_getstats;
1041 dev->set_multicast_list = ether1_setmulticastlist;
1042 dev->tx_timeout = ether1_timeout;
1043 dev->watchdog_timeo = 5 * HZ / 100;
1045 ret = register_netdev(dev);
1049 printk(KERN_INFO "%s: ether1 in slot %d, ",
1050 dev->name, ec->slot_no);
1052 for (i = 0; i < 6; i++)
1053 printk ("%2.2x%c", dev->dev_addr[i], i == 5 ? '\n' : ':');
1055 ecard_set_drvdata(ec, dev);
1059 if (priv(dev)->base)
1060 iounmap(priv(dev)->base);
1063 ecard_release_resources(ec);
1068 static void __devexit ether1_remove(struct expansion_card *ec)
1070 struct net_device *dev = ecard_get_drvdata(ec);
1072 ecard_set_drvdata(ec, NULL);
1074 unregister_netdev(dev);
1075 iounmap(priv(dev)->base);
1077 ecard_release_resources(ec);
1080 static const struct ecard_id ether1_ids[] = {
1081 { MANU_ACORN, PROD_ACORN_ETHER1 },
1085 static struct ecard_driver ether1_driver = {
1086 .probe = ether1_probe,
1087 .remove = __devexit_p(ether1_remove),
1088 .id_table = ether1_ids,
1094 static int __init ether1_init(void)
1096 return ecard_register_driver(ðer1_driver);
1099 static void __exit ether1_exit(void)
1101 ecard_remove_driver(ðer1_driver);
1104 module_init(ether1_init);
1105 module_exit(ether1_exit);
1107 MODULE_LICENSE("GPL");