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/ioport.h>
41 #include <linux/slab.h>
42 #include <linux/string.h>
43 #include <linux/errno.h>
44 #include <linux/device.h>
45 #include <linux/init.h>
46 #include <linux/netdevice.h>
47 #include <linux/etherdevice.h>
48 #include <linux/skbuff.h>
49 #include <linux/bitops.h>
53 #include <asm/ecard.h>
58 static unsigned int net_debug = NET_DEBUG;
60 #define BUFFER_SIZE 0x10000
61 #define TX_AREA_START 0x00100
62 #define TX_AREA_END 0x05000
63 #define RX_AREA_START 0x05000
64 #define RX_AREA_END 0x0fc00
66 static int ether1_open(struct net_device *dev);
67 static netdev_tx_t ether1_sendpacket(struct sk_buff *skb,
68 struct net_device *dev);
69 static irqreturn_t ether1_interrupt(int irq, void *dev_id);
70 static int ether1_close(struct net_device *dev);
71 static void ether1_setmulticastlist(struct net_device *dev);
72 static void ether1_timeout(struct net_device *dev);
74 /* ------------------------------------------------------------------------- */
76 static char version[] = "ether1 ethernet driver (c) 2000 Russell King v1.07\n";
81 /* ------------------------------------------------------------------------- */
86 #define ether1_readw(dev, addr, type, offset, svflgs) ether1_inw_p (dev, addr + (int)(&((type *)0)->offset), svflgs)
87 #define ether1_writew(dev, val, addr, type, offset, svflgs) ether1_outw_p (dev, val, addr + (int)(&((type *)0)->offset), svflgs)
89 static inline unsigned short
90 ether1_inw_p (struct net_device *dev, int addr, int svflgs)
96 local_irq_save (flags);
98 writeb(addr >> 12, REG_PAGE);
99 ret = readw(ETHER1_RAM + ((addr & 4095) << 1));
101 local_irq_restore (flags);
106 ether1_outw_p (struct net_device *dev, unsigned short val, int addr, int svflgs)
111 local_irq_save (flags);
113 writeb(addr >> 12, REG_PAGE);
114 writew(val, ETHER1_RAM + ((addr & 4095) << 1));
116 local_irq_restore (flags);
120 * Some inline assembler to allow fast transfers on to/off of the card.
121 * Since this driver depends on some features presented by the ARM
122 * specific architecture, and that you can't configure this driver
123 * without specifiing ARM mode, this is not a problem.
125 * This routine is essentially an optimised memcpy from the card's
126 * onboard RAM to kernel memory.
129 ether1_writebuffer (struct net_device *dev, void *data, unsigned int start, unsigned int length)
131 unsigned int page, thislen, offset;
134 offset = start & 4095;
136 addr = ETHER1_RAM + (offset << 1);
138 if (offset + length > 4096)
139 thislen = 4096 - offset;
146 writeb(page, REG_PAGE);
149 __asm__ __volatile__(
152 1: ldr %0, [%1], #2\n\
153 mov %0, %0, lsl #16\n\
154 orr %0, %0, %0, lsr #16\n\
159 mov %0, %0, lsl #16\n\
160 orr %0, %0, %0, lsr #16\n\
165 mov %0, %0, lsl #16\n\
166 orr %0, %0, %0, lsr #16\n\
171 mov %0, %0, lsl #16\n\
172 orr %0, %0, %0, lsr #16\n\
176 2: adds %3, %3, #1\n\
179 : "=&r" (used), "=&r" (data)
180 : "r" (addr), "r" (thislen), "1" (data));
192 ether1_readbuffer (struct net_device *dev, void *data, unsigned int start, unsigned int length)
194 unsigned int page, thislen, offset;
197 offset = start & 4095;
199 addr = ETHER1_RAM + (offset << 1);
201 if (offset + length > 4096)
202 thislen = 4096 - offset;
209 writeb(page, REG_PAGE);
212 __asm__ __volatile__(
215 1: ldr %0, [%2], #4\n\
217 mov %0, %0, lsr #8\n\
223 mov %0, %0, lsr #8\n\
229 mov %0, %0, lsr #8\n\
235 mov %0, %0, lsr #8\n\
239 2: adds %3, %3, #1\n\
242 : "=&r" (used), "=&r" (data)
243 : "r" (addr), "r" (thislen), "1" (data));
255 ether1_ramtest(struct net_device *dev, unsigned char byte)
257 unsigned char *buffer = kmalloc (BUFFER_SIZE, GFP_KERNEL);
258 int i, ret = BUFFER_SIZE;
266 memset (buffer, byte, BUFFER_SIZE);
267 ether1_writebuffer (dev, buffer, 0, BUFFER_SIZE);
268 memset (buffer, byte ^ 0xff, BUFFER_SIZE);
269 ether1_readbuffer (dev, buffer, 0, BUFFER_SIZE);
271 for (i = 0; i < BUFFER_SIZE; i++) {
272 if (buffer[i] != byte) {
273 if (max_errors >= 0 && bad != buffer[i]) {
276 printk (KERN_CRIT "%s: RAM failed with (%02X instead of %02X) at 0x%04X",
277 dev->name, buffer[i], byte, i);
285 if (bad_start == i - 1)
288 printk (" - 0x%04X\n", i - 1);
295 printk (" - 0x%04X\n", BUFFER_SIZE);
302 ether1_reset (struct net_device *dev)
304 writeb(CTRL_RST|CTRL_ACK, REG_CONTROL);
309 ether1_init_2(struct net_device *dev)
314 i = ether1_ramtest (dev, 0x5a);
317 i = ether1_ramtest (dev, 0x1e);
327 * These are the structures that are loaded into the ether RAM card to
328 * initialise the 82586
332 #define NOP_ADDR (TX_AREA_START)
333 #define NOP_SIZE (0x06)
334 static nop_t init_nop = {
341 #define TDR_ADDR (0x003a)
342 #define TDR_SIZE (0x08)
343 static tdr_t init_tdr = {
351 #define MC_ADDR (0x002e)
352 #define MC_SIZE (0x0c)
353 static mc_t init_mc = {
362 #define SA_ADDR (0x0022)
363 #define SA_SIZE (0x0c)
364 static sa_t init_sa = {
372 #define CFG_ADDR (0x0010)
373 #define CFG_SIZE (0x12)
374 static cfg_t init_cfg = {
381 CFG9_PREAMB8 | CFG9_ADDRLENBUF | CFG9_ADDRLEN(6),
385 CFG13_RETRY(15) | CFG13_SLOTH(2),
390 #define SCB_ADDR (0x0000)
391 #define SCB_SIZE (0x10)
392 static scb_t init_scb = {
394 SCB_CMDACKRNR | SCB_CMDACKCNA | SCB_CMDACKFR | SCB_CMDACKCX,
404 #define ISCP_ADDR (0xffee)
405 #define ISCP_SIZE (0x08)
406 static iscp_t init_iscp = {
414 #define SCP_ADDR (0xfff6)
415 #define SCP_SIZE (0x0a)
416 static scp_t init_scp = {
423 #define RFD_SIZE (0x16)
424 static rfd_t init_rfd = {
434 #define RBD_SIZE (0x0a)
435 static rbd_t init_rbd = {
443 #define TX_SIZE (0x08)
444 #define TBD_SIZE (0x08)
447 ether1_init_for_open (struct net_device *dev)
449 int i, status, addr, next, next2;
451 unsigned long timeout;
453 writeb(CTRL_RST|CTRL_ACK, REG_CONTROL);
455 for (i = 0; i < 6; i++)
456 init_sa.sa_addr[i] = dev->dev_addr[i];
458 /* load data structures into ether1 RAM */
459 ether1_writebuffer (dev, &init_scp, SCP_ADDR, SCP_SIZE);
460 ether1_writebuffer (dev, &init_iscp, ISCP_ADDR, ISCP_SIZE);
461 ether1_writebuffer (dev, &init_scb, SCB_ADDR, SCB_SIZE);
462 ether1_writebuffer (dev, &init_cfg, CFG_ADDR, CFG_SIZE);
463 ether1_writebuffer (dev, &init_sa, SA_ADDR, SA_SIZE);
464 ether1_writebuffer (dev, &init_mc, MC_ADDR, MC_SIZE);
465 ether1_writebuffer (dev, &init_tdr, TDR_ADDR, TDR_SIZE);
466 ether1_writebuffer (dev, &init_nop, NOP_ADDR, NOP_SIZE);
468 if (ether1_readw(dev, CFG_ADDR, cfg_t, cfg_command, NORMALIRQS) != CMD_CONFIG) {
469 printk (KERN_ERR "%s: detected either RAM fault or compiler bug\n",
475 * setup circularly linked list of { rfd, rbd, buffer }, with
476 * all rfds circularly linked, rbds circularly linked.
477 * First rfd is linked to scp, first rbd is linked to first
478 * rfd. Last rbd has a suspend command.
480 addr = RX_AREA_START;
482 next = addr + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;
483 next2 = next + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;
485 if (next2 >= RX_AREA_END) {
486 next = RX_AREA_START;
487 init_rfd.rfd_command = RFD_CMDEL | RFD_CMDSUSPEND;
488 priv(dev)->rx_tail = addr;
490 init_rfd.rfd_command = 0;
491 if (addr == RX_AREA_START)
492 init_rfd.rfd_rbdoffset = addr + RFD_SIZE;
494 init_rfd.rfd_rbdoffset = 0;
495 init_rfd.rfd_link = next;
496 init_rbd.rbd_link = next + RFD_SIZE;
497 init_rbd.rbd_bufl = addr + RFD_SIZE + RBD_SIZE;
499 ether1_writebuffer (dev, &init_rfd, addr, RFD_SIZE);
500 ether1_writebuffer (dev, &init_rbd, addr + RFD_SIZE, RBD_SIZE);
502 } while (next2 < RX_AREA_END);
504 priv(dev)->tx_link = NOP_ADDR;
505 priv(dev)->tx_head = NOP_ADDR + NOP_SIZE;
506 priv(dev)->tx_tail = TDR_ADDR;
507 priv(dev)->rx_head = RX_AREA_START;
509 /* release reset & give 586 a prod */
510 priv(dev)->resetting = 1;
511 priv(dev)->initialising = 1;
512 writeb(CTRL_RST, REG_CONTROL);
513 writeb(0, REG_CONTROL);
514 writeb(CTRL_CA, REG_CONTROL);
516 /* 586 should now unset iscp.busy */
517 timeout = jiffies + HZ/2;
518 while (ether1_readw(dev, ISCP_ADDR, iscp_t, iscp_busy, DISABLEIRQS) == 1) {
519 if (time_after(jiffies, timeout)) {
520 printk (KERN_WARNING "%s: can't initialise 82586: iscp is busy\n", dev->name);
525 /* check status of commands that we issued */
527 while (((status = ether1_readw(dev, CFG_ADDR, cfg_t, cfg_status, DISABLEIRQS))
528 & STAT_COMPLETE) == 0) {
529 if (time_after(jiffies, timeout))
533 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
534 printk (KERN_WARNING "%s: can't initialise 82586: config status %04X\n", dev->name, status);
535 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
536 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
537 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
538 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
539 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
544 while (((status = ether1_readw(dev, SA_ADDR, sa_t, sa_status, DISABLEIRQS))
545 & STAT_COMPLETE) == 0) {
546 if (time_after(jiffies, timeout))
550 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
551 printk (KERN_WARNING "%s: can't initialise 82586: set address status %04X\n", dev->name, status);
552 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
553 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
554 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
555 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
556 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
561 while (((status = ether1_readw(dev, MC_ADDR, mc_t, mc_status, DISABLEIRQS))
562 & STAT_COMPLETE) == 0) {
563 if (time_after(jiffies, timeout))
567 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
568 printk (KERN_WARNING "%s: can't initialise 82586: set multicast status %04X\n", dev->name, status);
569 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
570 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
571 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
572 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
573 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
578 while (((status = ether1_readw(dev, TDR_ADDR, tdr_t, tdr_status, DISABLEIRQS))
579 & STAT_COMPLETE) == 0) {
580 if (time_after(jiffies, timeout))
584 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
585 printk (KERN_WARNING "%s: can't tdr (ignored)\n", dev->name);
586 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
587 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
588 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
589 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
590 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
592 status = ether1_readw(dev, TDR_ADDR, tdr_t, tdr_result, DISABLEIRQS);
593 if (status & TDR_XCVRPROB)
594 printk (KERN_WARNING "%s: i/f failed tdr: transceiver problem\n", dev->name);
595 else if ((status & (TDR_SHORT|TDR_OPEN)) && (status & TDR_TIME)) {
597 printk (KERN_WARNING "%s: i/f failed tdr: cable %s %d.%d us away\n", dev->name,
598 status & TDR_SHORT ? "short" : "open", (status & TDR_TIME) / 10,
599 (status & TDR_TIME) % 10);
601 printk (KERN_WARNING "%s: i/f failed tdr: cable %s %d clks away\n", dev->name,
602 status & TDR_SHORT ? "short" : "open", (status & TDR_TIME));
609 return failures ? 1 : 0;
612 /* ------------------------------------------------------------------------- */
615 ether1_txalloc (struct net_device *dev, int size)
619 size = (size + 1) & ~1;
620 tail = priv(dev)->tx_tail;
622 if (priv(dev)->tx_head + size > TX_AREA_END) {
623 if (tail > priv(dev)->tx_head)
625 start = TX_AREA_START;
626 if (start + size > tail)
628 priv(dev)->tx_head = start + size;
630 if (priv(dev)->tx_head < tail && (priv(dev)->tx_head + size) > tail)
632 start = priv(dev)->tx_head;
633 priv(dev)->tx_head += size;
640 ether1_open (struct net_device *dev)
642 if (request_irq(dev->irq, ether1_interrupt, 0, "ether1", dev))
645 if (ether1_init_for_open (dev)) {
646 free_irq (dev->irq, dev);
650 netif_start_queue(dev);
656 ether1_timeout(struct net_device *dev)
658 printk(KERN_WARNING "%s: transmit timeout, network cable problem?\n",
660 printk(KERN_WARNING "%s: resetting device\n", dev->name);
664 if (ether1_init_for_open (dev))
665 printk (KERN_ERR "%s: unable to restart interface\n", dev->name);
667 dev->stats.tx_errors++;
668 netif_wake_queue(dev);
672 ether1_sendpacket (struct sk_buff *skb, struct net_device *dev)
674 int tmp, tst, nopaddr, txaddr, tbdaddr, dataddr;
680 if (priv(dev)->restart) {
681 printk(KERN_WARNING "%s: resetting device\n", dev->name);
685 if (ether1_init_for_open(dev))
686 printk(KERN_ERR "%s: unable to restart interface\n", dev->name);
688 priv(dev)->restart = 0;
691 if (skb->len < ETH_ZLEN) {
692 if (skb_padto(skb, ETH_ZLEN))
697 * insert packet followed by a nop
699 txaddr = ether1_txalloc (dev, TX_SIZE);
700 tbdaddr = ether1_txalloc (dev, TBD_SIZE);
701 dataddr = ether1_txalloc (dev, skb->len);
702 nopaddr = ether1_txalloc (dev, NOP_SIZE);
705 tx.tx_command = CMD_TX | CMD_INTR;
706 tx.tx_link = nopaddr;
707 tx.tx_tbdoffset = tbdaddr;
708 tbd.tbd_opts = TBD_EOL | skb->len;
709 tbd.tbd_link = I82586_NULL;
710 tbd.tbd_bufl = dataddr;
713 nop.nop_command = CMD_NOP;
714 nop.nop_link = nopaddr;
716 local_irq_save(flags);
717 ether1_writebuffer (dev, &tx, txaddr, TX_SIZE);
718 ether1_writebuffer (dev, &tbd, tbdaddr, TBD_SIZE);
719 ether1_writebuffer (dev, skb->data, dataddr, skb->len);
720 ether1_writebuffer (dev, &nop, nopaddr, NOP_SIZE);
721 tmp = priv(dev)->tx_link;
722 priv(dev)->tx_link = nopaddr;
724 /* now reset the previous nop pointer */
725 ether1_writew(dev, txaddr, tmp, nop_t, nop_link, NORMALIRQS);
727 local_irq_restore(flags);
729 /* handle transmit */
731 /* check to see if we have room for a full sized ether frame */
732 tmp = priv(dev)->tx_head;
733 tst = ether1_txalloc (dev, TX_SIZE + TBD_SIZE + NOP_SIZE + ETH_FRAME_LEN);
734 priv(dev)->tx_head = tmp;
738 netif_stop_queue(dev);
745 ether1_xmit_done (struct net_device *dev)
750 caddr = priv(dev)->tx_tail;
753 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
755 switch (nop.nop_command & CMD_MASK) {
758 if (ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS)
759 != (unsigned short)I82586_NULL) {
760 ether1_writew(dev, SCB_CMDCUCSTART | SCB_CMDRXSTART, SCB_ADDR, scb_t,
761 scb_command, NORMALIRQS);
762 writeb(CTRL_CA, REG_CONTROL);
764 priv(dev)->tx_tail = NOP_ADDR;
768 if (nop.nop_link == caddr) {
769 if (priv(dev)->initialising == 0)
770 printk (KERN_WARNING "%s: strange command complete with no tx command!\n", dev->name);
772 priv(dev)->initialising = 0;
775 if (caddr == nop.nop_link)
777 caddr = nop.nop_link;
781 if (nop.nop_status & STAT_COMPLETE)
783 printk (KERN_ERR "%s: strange command complete without completed command\n", dev->name);
784 priv(dev)->restart = 1;
788 printk (KERN_WARNING "%s: strange command %d complete! (offset %04X)", dev->name,
789 nop.nop_command & CMD_MASK, caddr);
790 priv(dev)->restart = 1;
794 while (nop.nop_status & STAT_COMPLETE) {
795 if (nop.nop_status & STAT_OK) {
796 dev->stats.tx_packets++;
797 dev->stats.collisions += (nop.nop_status & STAT_COLLISIONS);
799 dev->stats.tx_errors++;
801 if (nop.nop_status & STAT_COLLAFTERTX)
802 dev->stats.collisions++;
803 if (nop.nop_status & STAT_NOCARRIER)
804 dev->stats.tx_carrier_errors++;
805 if (nop.nop_status & STAT_TXLOSTCTS)
806 printk (KERN_WARNING "%s: cts lost\n", dev->name);
807 if (nop.nop_status & STAT_TXSLOWDMA)
808 dev->stats.tx_fifo_errors++;
809 if (nop.nop_status & STAT_COLLEXCESSIVE)
810 dev->stats.collisions += 16;
813 if (nop.nop_link == caddr) {
814 printk (KERN_ERR "%s: tx buffer chaining error: tx command points to itself\n", dev->name);
818 caddr = nop.nop_link;
819 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
820 if ((nop.nop_command & CMD_MASK) != CMD_NOP) {
821 printk (KERN_ERR "%s: tx buffer chaining error: no nop after tx command\n", dev->name);
825 if (caddr == nop.nop_link)
828 caddr = nop.nop_link;
829 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
830 if ((nop.nop_command & CMD_MASK) != CMD_TX) {
831 printk (KERN_ERR "%s: tx buffer chaining error: no tx command after nop\n", dev->name);
835 priv(dev)->tx_tail = caddr;
837 caddr = priv(dev)->tx_head;
838 tst = ether1_txalloc (dev, TX_SIZE + TBD_SIZE + NOP_SIZE + ETH_FRAME_LEN);
839 priv(dev)->tx_head = caddr;
841 netif_wake_queue(dev);
845 ether1_recv_done (struct net_device *dev)
848 int nexttail, rbdaddr;
852 status = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_status, NORMALIRQS);
853 if ((status & RFD_COMPLETE) == 0)
856 rbdaddr = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_rbdoffset, NORMALIRQS);
857 ether1_readbuffer (dev, &rbd, rbdaddr, RBD_SIZE);
859 if ((rbd.rbd_status & (RBD_EOF | RBD_ACNTVALID)) == (RBD_EOF | RBD_ACNTVALID)) {
860 int length = rbd.rbd_status & RBD_ACNT;
863 length = (length + 1) & ~1;
864 skb = netdev_alloc_skb(dev, length + 2);
867 skb_reserve (skb, 2);
869 ether1_readbuffer (dev, skb_put (skb, length), rbd.rbd_bufl, length);
871 skb->protocol = eth_type_trans (skb, dev);
873 dev->stats.rx_packets++;
875 dev->stats.rx_dropped++;
877 printk(KERN_WARNING "%s: %s\n", dev->name,
878 (rbd.rbd_status & RBD_EOF) ? "oversized packet" : "acnt not valid");
879 dev->stats.rx_dropped++;
882 nexttail = ether1_readw(dev, priv(dev)->rx_tail, rfd_t, rfd_link, NORMALIRQS);
883 /* nexttail should be rx_head */
884 if (nexttail != priv(dev)->rx_head)
885 printk(KERN_ERR "%s: receiver buffer chaining error (%04X != %04X)\n",
886 dev->name, nexttail, priv(dev)->rx_head);
887 ether1_writew(dev, RFD_CMDEL | RFD_CMDSUSPEND, nexttail, rfd_t, rfd_command, NORMALIRQS);
888 ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_command, NORMALIRQS);
889 ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_status, NORMALIRQS);
890 ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_rbdoffset, NORMALIRQS);
892 priv(dev)->rx_tail = nexttail;
893 priv(dev)->rx_head = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_link, NORMALIRQS);
898 ether1_interrupt (int irq, void *dev_id)
900 struct net_device *dev = (struct net_device *)dev_id;
903 status = ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS);
906 ether1_writew(dev, status & (SCB_STRNR | SCB_STCNA | SCB_STFR | SCB_STCX),
907 SCB_ADDR, scb_t, scb_command, NORMALIRQS);
908 writeb(CTRL_CA | CTRL_ACK, REG_CONTROL);
909 if (status & SCB_STCX) {
910 ether1_xmit_done (dev);
912 if (status & SCB_STCNA) {
913 if (priv(dev)->resetting == 0)
914 printk (KERN_WARNING "%s: CU went not ready ???\n", dev->name);
916 priv(dev)->resetting += 1;
917 if (ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS)
918 != (unsigned short)I82586_NULL) {
919 ether1_writew(dev, SCB_CMDCUCSTART, SCB_ADDR, scb_t, scb_command, NORMALIRQS);
920 writeb(CTRL_CA, REG_CONTROL);
922 if (priv(dev)->resetting == 2)
923 priv(dev)->resetting = 0;
925 if (status & SCB_STFR) {
926 ether1_recv_done (dev);
928 if (status & SCB_STRNR) {
929 if (ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS) & SCB_STRXSUSP) {
930 printk (KERN_WARNING "%s: RU went not ready: RU suspended\n", dev->name);
931 ether1_writew(dev, SCB_CMDRXRESUME, SCB_ADDR, scb_t, scb_command, NORMALIRQS);
932 writeb(CTRL_CA, REG_CONTROL);
933 dev->stats.rx_dropped++; /* we suspended due to lack of buffer space */
935 printk(KERN_WARNING "%s: RU went not ready: %04X\n", dev->name,
936 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS));
937 printk (KERN_WARNING "RU ptr = %04X\n", ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset,
941 writeb(CTRL_ACK, REG_CONTROL);
947 ether1_close (struct net_device *dev)
951 free_irq(dev->irq, dev);
957 * Set or clear the multicast filter for this adaptor.
958 * num_addrs == -1 Promiscuous mode, receive all packets.
959 * num_addrs == 0 Normal mode, clear multicast list.
960 * num_addrs > 0 Multicast mode, receive normal and MC packets, and do
961 * best-effort filtering.
964 ether1_setmulticastlist (struct net_device *dev)
968 /* ------------------------------------------------------------------------- */
970 static void ether1_banner(void)
972 static unsigned int version_printed = 0;
974 if (net_debug && version_printed++ == 0)
975 printk(KERN_INFO "%s", version);
978 static const struct net_device_ops ether1_netdev_ops = {
979 .ndo_open = ether1_open,
980 .ndo_stop = ether1_close,
981 .ndo_start_xmit = ether1_sendpacket,
982 .ndo_set_rx_mode = ether1_setmulticastlist,
983 .ndo_tx_timeout = ether1_timeout,
984 .ndo_validate_addr = eth_validate_addr,
985 .ndo_set_mac_address = eth_mac_addr,
989 ether1_probe(struct expansion_card *ec, const struct ecard_id *id)
991 struct net_device *dev;
996 ret = ecard_request_resources(ec);
1000 dev = alloc_etherdev(sizeof(struct ether1_priv));
1006 SET_NETDEV_DEV(dev, &ec->dev);
1009 priv(dev)->base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
1010 if (!priv(dev)->base) {
1015 if ((priv(dev)->bus_type = ether1_reset(dev)) == 0) {
1020 for (i = 0; i < 6; i++)
1021 dev->dev_addr[i] = readb(IDPROM_ADDRESS + (i << 2));
1023 if (ether1_init_2(dev)) {
1028 dev->netdev_ops = ðer1_netdev_ops;
1029 dev->watchdog_timeo = 5 * HZ / 100;
1031 ret = register_netdev(dev);
1035 printk(KERN_INFO "%s: ether1 in slot %d, %pM\n",
1036 dev->name, ec->slot_no, dev->dev_addr);
1038 ecard_set_drvdata(ec, dev);
1044 ecard_release_resources(ec);
1049 static void ether1_remove(struct expansion_card *ec)
1051 struct net_device *dev = ecard_get_drvdata(ec);
1053 ecard_set_drvdata(ec, NULL);
1055 unregister_netdev(dev);
1057 ecard_release_resources(ec);
1060 static const struct ecard_id ether1_ids[] = {
1061 { MANU_ACORN, PROD_ACORN_ETHER1 },
1065 static struct ecard_driver ether1_driver = {
1066 .probe = ether1_probe,
1067 .remove = ether1_remove,
1068 .id_table = ether1_ids,
1074 static int __init ether1_init(void)
1076 return ecard_register_driver(ðer1_driver);
1079 static void __exit ether1_exit(void)
1081 ecard_remove_driver(ðer1_driver);
1084 module_init(ether1_init);
1085 module_exit(ether1_exit);
1087 MODULE_LICENSE("GPL");