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/sched.h>
37 #include <linux/types.h>
38 #include <linux/fcntl.h>
39 #include <linux/interrupt.h>
40 #include <linux/ptrace.h>
41 #include <linux/ioport.h>
43 #include <linux/slab.h>
44 #include <linux/string.h>
45 #include <linux/errno.h>
46 #include <linux/init.h>
47 #include <linux/netdevice.h>
48 #include <linux/etherdevice.h>
49 #include <linux/skbuff.h>
51 #include <asm/system.h>
52 #include <asm/bitops.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 void ether1_interrupt(int irq, void *dev_id, struct pt_regs *regs);
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 static const card_ids __init ether1_cids[] = {
84 { MANU_ACORN, PROD_ACORN_ETHER1 },
88 /* ------------------------------------------------------------------------- */
93 #define ether1_inw(dev, addr, type, offset, svflgs) ether1_inw_p (dev, addr + (int)(&((type *)0)->offset), svflgs)
94 #define ether1_outw(dev, val, addr, type, offset, svflgs) ether1_outw_p (dev, val, addr + (int)(&((type *)0)->offset), svflgs)
96 static inline unsigned short
97 ether1_inw_p (struct net_device *dev, int addr, int svflgs)
103 save_flags_cli (flags);
105 outb (addr >> 12, REG_PAGE);
106 ret = inw (ETHER1_RAM + ((addr & 4095) >> 1));
108 restore_flags (flags);
113 ether1_outw_p (struct net_device *dev, unsigned short val, int addr, int svflgs)
118 save_flags_cli (flags);
120 outb (addr >> 12, REG_PAGE);
121 outw (val, ETHER1_RAM + ((addr & 4095) >> 1));
123 restore_flags (flags);
127 * Some inline assembler to allow fast transfers on to/off of the card.
128 * Since this driver depends on some features presented by the ARM
129 * specific architecture, and that you can't configure this driver
130 * without specifiing ARM mode, this is not a problem.
132 * This routine is essentially an optimised memcpy from the card's
133 * onboard RAM to kernel memory.
136 ether1_writebuffer (struct net_device *dev, void *data, unsigned int start, unsigned int length)
138 unsigned int page, thislen, offset, addr;
140 offset = start & 4095;
142 addr = ioaddr(ETHER1_RAM + (offset >> 1));
144 if (offset + length > 4096)
145 thislen = 4096 - offset;
152 outb(page, REG_PAGE);
155 __asm__ __volatile__(
160 orr %0, %0, %0, lsr #16
166 orr %0, %0, %0, lsr #16
172 orr %0, %0, %0, lsr #16
178 orr %0, %0, %0, lsr #16
185 : "=&r" (used), "=&r" (data)
186 : "r" (addr), "r" (thislen), "1" (data));
188 addr = ioaddr(ETHER1_RAM);
198 ether1_readbuffer (struct net_device *dev, void *data, unsigned int start, unsigned int length)
200 unsigned int page, thislen, offset, addr;
202 offset = start & 4095;
204 addr = ioaddr(ETHER1_RAM + (offset >> 1));
206 if (offset + length > 4096)
207 thislen = 4096 - offset;
214 outb(page, REG_PAGE);
217 __asm__ __volatile__(
247 : "=&r" (used), "=&r" (data)
248 : "r" (addr), "r" (thislen), "1" (data));
250 addr = ioaddr(ETHER1_RAM);
260 ether1_ramtest(struct net_device *dev, unsigned char byte)
262 unsigned char *buffer = kmalloc (BUFFER_SIZE, GFP_KERNEL);
263 int i, ret = BUFFER_SIZE;
271 memset (buffer, byte, BUFFER_SIZE);
272 ether1_writebuffer (dev, buffer, 0, BUFFER_SIZE);
273 memset (buffer, byte ^ 0xff, BUFFER_SIZE);
274 ether1_readbuffer (dev, buffer, 0, BUFFER_SIZE);
276 for (i = 0; i < BUFFER_SIZE; i++) {
277 if (buffer[i] != byte) {
278 if (max_errors >= 0 && bad != buffer[i]) {
281 printk (KERN_CRIT "%s: RAM failed with (%02X instead of %02X) at 0x%04X",
282 dev->name, buffer[i], byte, i);
290 if (bad_start == i - 1)
293 printk (" - 0x%04X\n", i - 1);
300 printk (" - 0x%04X\n", BUFFER_SIZE);
307 ether1_reset (struct net_device *dev)
309 outb (CTRL_RST|CTRL_ACK, REG_CONTROL);
314 ether1_init_2(struct net_device *dev)
319 i = ether1_ramtest (dev, 0x5a);
322 i = ether1_ramtest (dev, 0x1e);
332 * These are the structures that are loaded into the ether RAM card to
333 * initialise the 82586
337 #define NOP_ADDR (TX_AREA_START)
338 #define NOP_SIZE (0x06)
339 static nop_t init_nop = {
346 #define TDR_ADDR (0x003a)
347 #define TDR_SIZE (0x08)
348 static tdr_t init_tdr = {
356 #define MC_ADDR (0x002e)
357 #define MC_SIZE (0x0c)
358 static mc_t init_mc = {
367 #define SA_ADDR (0x0022)
368 #define SA_SIZE (0x0c)
369 static sa_t init_sa = {
377 #define CFG_ADDR (0x0010)
378 #define CFG_SIZE (0x12)
379 static cfg_t init_cfg = {
386 CFG9_PREAMB8 | CFG9_ADDRLENBUF | CFG9_ADDRLEN(6),
390 CFG13_RETRY(15) | CFG13_SLOTH(2),
395 #define SCB_ADDR (0x0000)
396 #define SCB_SIZE (0x10)
397 static scb_t init_scb = {
399 SCB_CMDACKRNR | SCB_CMDACKCNA | SCB_CMDACKFR | SCB_CMDACKCX,
409 #define ISCP_ADDR (0xffee)
410 #define ISCP_SIZE (0x08)
411 static iscp_t init_iscp = {
419 #define SCP_ADDR (0xfff6)
420 #define SCP_SIZE (0x0a)
421 static scp_t init_scp = {
428 #define RFD_SIZE (0x16)
429 static rfd_t init_rfd = {
439 #define RBD_SIZE (0x0a)
440 static rbd_t init_rbd = {
448 #define TX_SIZE (0x08)
449 #define TBD_SIZE (0x08)
452 ether1_init_for_open (struct net_device *dev)
454 struct ether1_priv *priv = (struct ether1_priv *)dev->priv;
455 int i, status, addr, next, next2;
458 outb (CTRL_RST|CTRL_ACK, REG_CONTROL);
460 for (i = 0; i < 6; i++)
461 init_sa.sa_addr[i] = dev->dev_addr[i];
463 /* load data structures into ether1 RAM */
464 ether1_writebuffer (dev, &init_scp, SCP_ADDR, SCP_SIZE);
465 ether1_writebuffer (dev, &init_iscp, ISCP_ADDR, ISCP_SIZE);
466 ether1_writebuffer (dev, &init_scb, SCB_ADDR, SCB_SIZE);
467 ether1_writebuffer (dev, &init_cfg, CFG_ADDR, CFG_SIZE);
468 ether1_writebuffer (dev, &init_sa, SA_ADDR, SA_SIZE);
469 ether1_writebuffer (dev, &init_mc, MC_ADDR, MC_SIZE);
470 ether1_writebuffer (dev, &init_tdr, TDR_ADDR, TDR_SIZE);
471 ether1_writebuffer (dev, &init_nop, NOP_ADDR, NOP_SIZE);
473 if (ether1_inw (dev, CFG_ADDR, cfg_t, cfg_command, NORMALIRQS) != CMD_CONFIG) {
474 printk (KERN_ERR "%s: detected either RAM fault or compiler bug\n",
480 * setup circularly linked list of { rfd, rbd, buffer }, with
481 * all rfds circularly linked, rbds circularly linked.
482 * First rfd is linked to scp, first rbd is linked to first
483 * rfd. Last rbd has a suspend command.
485 addr = RX_AREA_START;
487 next = addr + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;
488 next2 = next + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;
490 if (next2 >= RX_AREA_END) {
491 next = RX_AREA_START;
492 init_rfd.rfd_command = RFD_CMDEL | RFD_CMDSUSPEND;
493 priv->rx_tail = addr;
495 init_rfd.rfd_command = 0;
496 if (addr == RX_AREA_START)
497 init_rfd.rfd_rbdoffset = addr + RFD_SIZE;
499 init_rfd.rfd_rbdoffset = 0;
500 init_rfd.rfd_link = next;
501 init_rbd.rbd_link = next + RFD_SIZE;
502 init_rbd.rbd_bufl = addr + RFD_SIZE + RBD_SIZE;
504 ether1_writebuffer (dev, &init_rfd, addr, RFD_SIZE);
505 ether1_writebuffer (dev, &init_rbd, addr + RFD_SIZE, RBD_SIZE);
507 } while (next2 < RX_AREA_END);
509 priv->tx_link = NOP_ADDR;
510 priv->tx_head = NOP_ADDR + NOP_SIZE;
511 priv->tx_tail = TDR_ADDR;
512 priv->rx_head = RX_AREA_START;
514 /* release reset & give 586 a prod */
516 priv->initialising = 1;
517 outb (CTRL_RST, REG_CONTROL);
518 outb (0, REG_CONTROL);
519 outb (CTRL_CA, REG_CONTROL);
521 /* 586 should now unset iscp.busy */
523 while (ether1_inw (dev, ISCP_ADDR, iscp_t, iscp_busy, DISABLEIRQS) == 1) {
524 if (time_after(jiffies, i)) {
525 printk (KERN_WARNING "%s: can't initialise 82586: iscp is busy\n", dev->name);
530 /* check status of commands that we issued */
532 while (((status = ether1_inw (dev, CFG_ADDR, cfg_t, cfg_status, DISABLEIRQS))
533 & STAT_COMPLETE) == 0) {
534 if (time_after(jiffies, i))
538 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
539 printk (KERN_WARNING "%s: can't initialise 82586: config status %04X\n", dev->name, status);
540 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
541 ether1_inw (dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
542 ether1_inw (dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
543 ether1_inw (dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
544 ether1_inw (dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
549 while (((status = ether1_inw (dev, SA_ADDR, sa_t, sa_status, DISABLEIRQS))
550 & STAT_COMPLETE) == 0) {
551 if (time_after(jiffies, i))
555 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
556 printk (KERN_WARNING "%s: can't initialise 82586: set address status %04X\n", dev->name, status);
557 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
558 ether1_inw (dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
559 ether1_inw (dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
560 ether1_inw (dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
561 ether1_inw (dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
566 while (((status = ether1_inw (dev, MC_ADDR, mc_t, mc_status, DISABLEIRQS))
567 & STAT_COMPLETE) == 0) {
568 if (time_after(jiffies, i))
572 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
573 printk (KERN_WARNING "%s: can't initialise 82586: set multicast status %04X\n", dev->name, status);
574 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
575 ether1_inw (dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
576 ether1_inw (dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
577 ether1_inw (dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
578 ether1_inw (dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
583 while (((status = ether1_inw (dev, TDR_ADDR, tdr_t, tdr_status, DISABLEIRQS))
584 & STAT_COMPLETE) == 0) {
585 if (time_after(jiffies, i))
589 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
590 printk (KERN_WARNING "%s: can't tdr (ignored)\n", dev->name);
591 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
592 ether1_inw (dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
593 ether1_inw (dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
594 ether1_inw (dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
595 ether1_inw (dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
597 status = ether1_inw (dev, TDR_ADDR, tdr_t, tdr_result, DISABLEIRQS);
598 if (status & TDR_XCVRPROB)
599 printk (KERN_WARNING "%s: i/f failed tdr: transceiver problem\n", dev->name);
600 else if ((status & (TDR_SHORT|TDR_OPEN)) && (status & TDR_TIME)) {
602 printk (KERN_WARNING "%s: i/f failed tdr: cable %s %d.%d us away\n", dev->name,
603 status & TDR_SHORT ? "short" : "open", (status & TDR_TIME) / 10,
604 (status & TDR_TIME) % 10);
606 printk (KERN_WARNING "%s: i/f failed tdr: cable %s %d clks away\n", dev->name,
607 status & TDR_SHORT ? "short" : "open", (status & TDR_TIME));
614 return failures ? 1 : 0;
617 /* ------------------------------------------------------------------------- */
620 ether1_txalloc (struct net_device *dev, int size)
622 struct ether1_priv *priv = (struct ether1_priv *)dev->priv;
625 size = (size + 1) & ~1;
626 tail = priv->tx_tail;
628 if (priv->tx_head + size > TX_AREA_END) {
629 if (tail > priv->tx_head)
631 start = TX_AREA_START;
632 if (start + size > tail)
634 priv->tx_head = start + size;
636 if (priv->tx_head < tail && (priv->tx_head + size) > tail)
638 start = priv->tx_head;
639 priv->tx_head += size;
646 ether1_open (struct net_device *dev)
648 struct ether1_priv *priv = (struct ether1_priv *)dev->priv;
650 if (!is_valid_ether_addr(dev->dev_addr)) {
651 printk("%s: invalid ethernet MAC address\n", dev->name);
655 if (request_irq(dev->irq, ether1_interrupt, 0, "ether1", dev))
658 memset (&priv->stats, 0, sizeof (struct net_device_stats));
660 if (ether1_init_for_open (dev)) {
661 free_irq (dev->irq, dev);
665 netif_start_queue(dev);
671 ether1_timeout(struct net_device *dev)
673 struct ether1_priv *priv = (struct ether1_priv *)dev->priv;
675 printk(KERN_WARNING "%s: transmit timeout, network cable problem?\n",
677 printk(KERN_WARNING "%s: resetting device\n", dev->name);
681 if (ether1_init_for_open (dev))
682 printk (KERN_ERR "%s: unable to restart interface\n", dev->name);
684 priv->stats.tx_errors++;
685 netif_wake_queue(dev);
689 ether1_sendpacket (struct sk_buff *skb, struct net_device *dev)
691 struct ether1_priv *priv = (struct ether1_priv *)dev->priv;
692 int tmp, tst, nopaddr, txaddr, tbdaddr, dataddr;
699 printk(KERN_WARNING "%s: resetting device\n", dev->name);
703 if (ether1_init_for_open(dev))
704 printk(KERN_ERR "%s: unable to restart interface\n", dev->name);
709 if (skb->len < ETH_ZLEN) {
710 skb = skb_padto(skb, ETH_ZLEN);
716 * insert packet followed by a nop
718 txaddr = ether1_txalloc (dev, TX_SIZE);
719 tbdaddr = ether1_txalloc (dev, TBD_SIZE);
720 dataddr = ether1_txalloc (dev, skb->len);
721 nopaddr = ether1_txalloc (dev, NOP_SIZE);
724 tx.tx_command = CMD_TX | CMD_INTR;
725 tx.tx_link = nopaddr;
726 tx.tx_tbdoffset = tbdaddr;
727 tbd.tbd_opts = TBD_EOL | skb->len;
728 tbd.tbd_link = I82586_NULL;
729 tbd.tbd_bufl = dataddr;
732 nop.nop_command = CMD_NOP;
733 nop.nop_link = nopaddr;
735 save_flags_cli(flags);
736 ether1_writebuffer (dev, &tx, txaddr, TX_SIZE);
737 ether1_writebuffer (dev, &tbd, tbdaddr, TBD_SIZE);
738 ether1_writebuffer (dev, skb->data, dataddr, skb->len);
739 ether1_writebuffer (dev, &nop, nopaddr, NOP_SIZE);
741 priv->tx_link = nopaddr;
743 /* now reset the previous nop pointer */
744 ether1_outw (dev, txaddr, tmp, nop_t, nop_link, NORMALIRQS);
746 restore_flags(flags);
748 /* handle transmit */
749 dev->trans_start = jiffies;
751 /* check to see if we have room for a full sized ether frame */
753 tst = ether1_txalloc (dev, TX_SIZE + TBD_SIZE + NOP_SIZE + ETH_FRAME_LEN);
758 netif_stop_queue(dev);
765 ether1_xmit_done (struct net_device *dev)
767 struct ether1_priv *priv = (struct ether1_priv *)dev->priv;
771 caddr = priv->tx_tail;
774 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
776 switch (nop.nop_command & CMD_MASK) {
779 if (ether1_inw (dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS)
780 != (unsigned short)I82586_NULL) {
781 ether1_outw(dev, SCB_CMDCUCSTART | SCB_CMDRXSTART, SCB_ADDR, scb_t,
782 scb_command, NORMALIRQS);
783 outb (CTRL_CA, REG_CONTROL);
785 priv->tx_tail = NOP_ADDR;
789 if (nop.nop_link == caddr) {
790 if (priv->initialising == 0)
791 printk (KERN_WARNING "%s: strange command complete with no tx command!\n", dev->name);
793 priv->initialising = 0;
796 if (caddr == nop.nop_link)
798 caddr = nop.nop_link;
802 if (nop.nop_status & STAT_COMPLETE)
804 printk (KERN_ERR "%s: strange command complete without completed command\n", dev->name);
809 printk (KERN_WARNING "%s: strange command %d complete! (offset %04X)", dev->name,
810 nop.nop_command & CMD_MASK, caddr);
815 while (nop.nop_status & STAT_COMPLETE) {
816 if (nop.nop_status & STAT_OK) {
817 priv->stats.tx_packets ++;
818 priv->stats.collisions += (nop.nop_status & STAT_COLLISIONS);
820 priv->stats.tx_errors ++;
822 if (nop.nop_status & STAT_COLLAFTERTX)
823 priv->stats.collisions ++;
824 if (nop.nop_status & STAT_NOCARRIER)
825 priv->stats.tx_carrier_errors ++;
826 if (nop.nop_status & STAT_TXLOSTCTS)
827 printk (KERN_WARNING "%s: cts lost\n", dev->name);
828 if (nop.nop_status & STAT_TXSLOWDMA)
829 priv->stats.tx_fifo_errors ++;
830 if (nop.nop_status & STAT_COLLEXCESSIVE)
831 priv->stats.collisions += 16;
834 if (nop.nop_link == caddr) {
835 printk (KERN_ERR "%s: tx buffer chaining error: tx command points to itself\n", dev->name);
839 caddr = nop.nop_link;
840 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
841 if ((nop.nop_command & CMD_MASK) != CMD_NOP) {
842 printk (KERN_ERR "%s: tx buffer chaining error: no nop after tx command\n", dev->name);
846 if (caddr == nop.nop_link)
849 caddr = nop.nop_link;
850 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
851 if ((nop.nop_command & CMD_MASK) != CMD_TX) {
852 printk (KERN_ERR "%s: tx buffer chaining error: no tx command after nop\n", dev->name);
856 priv->tx_tail = caddr;
858 caddr = priv->tx_head;
859 tst = ether1_txalloc (dev, TX_SIZE + TBD_SIZE + NOP_SIZE + ETH_FRAME_LEN);
860 priv->tx_head = caddr;
862 netif_wake_queue(dev);
866 ether1_recv_done (struct net_device *dev)
868 struct ether1_priv *priv = (struct ether1_priv *)dev->priv;
870 int nexttail, rbdaddr;
874 status = ether1_inw (dev, priv->rx_head, rfd_t, rfd_status, NORMALIRQS);
875 if ((status & RFD_COMPLETE) == 0)
878 rbdaddr = ether1_inw (dev, priv->rx_head, rfd_t, rfd_rbdoffset, NORMALIRQS);
879 ether1_readbuffer (dev, &rbd, rbdaddr, RBD_SIZE);
881 if ((rbd.rbd_status & (RBD_EOF | RBD_ACNTVALID)) == (RBD_EOF | RBD_ACNTVALID)) {
882 int length = rbd.rbd_status & RBD_ACNT;
885 length = (length + 1) & ~1;
886 skb = dev_alloc_skb (length + 2);
890 skb_reserve (skb, 2);
892 ether1_readbuffer (dev, skb_put (skb, length), rbd.rbd_bufl, length);
894 skb->protocol = eth_type_trans (skb, dev);
896 priv->stats.rx_packets ++;
898 priv->stats.rx_dropped ++;
900 printk(KERN_WARNING "%s: %s\n", dev->name,
901 (rbd.rbd_status & RBD_EOF) ? "oversized packet" : "acnt not valid");
902 priv->stats.rx_dropped ++;
905 nexttail = ether1_inw (dev, priv->rx_tail, rfd_t, rfd_link, NORMALIRQS);
906 /* nexttail should be rx_head */
907 if (nexttail != priv->rx_head)
908 printk(KERN_ERR "%s: receiver buffer chaining error (%04X != %04X)\n",
909 dev->name, nexttail, priv->rx_head);
910 ether1_outw (dev, RFD_CMDEL | RFD_CMDSUSPEND, nexttail, rfd_t, rfd_command, NORMALIRQS);
911 ether1_outw (dev, 0, priv->rx_tail, rfd_t, rfd_command, NORMALIRQS);
912 ether1_outw (dev, 0, priv->rx_tail, rfd_t, rfd_status, NORMALIRQS);
913 ether1_outw (dev, 0, priv->rx_tail, rfd_t, rfd_rbdoffset, NORMALIRQS);
915 priv->rx_tail = nexttail;
916 priv->rx_head = ether1_inw (dev, priv->rx_head, rfd_t, rfd_link, NORMALIRQS);
921 ether1_interrupt (int irq, void *dev_id, struct pt_regs *regs)
923 struct net_device *dev = (struct net_device *)dev_id;
924 struct ether1_priv *priv = (struct ether1_priv *)dev->priv;
927 status = ether1_inw (dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS);
930 ether1_outw(dev, status & (SCB_STRNR | SCB_STCNA | SCB_STFR | SCB_STCX),
931 SCB_ADDR, scb_t, scb_command, NORMALIRQS);
932 outb (CTRL_CA | CTRL_ACK, REG_CONTROL);
933 if (status & SCB_STCX) {
934 ether1_xmit_done (dev);
936 if (status & SCB_STCNA) {
937 if (priv->resetting == 0)
938 printk (KERN_WARNING "%s: CU went not ready ???\n", dev->name);
940 priv->resetting += 1;
941 if (ether1_inw (dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS)
942 != (unsigned short)I82586_NULL) {
943 ether1_outw (dev, SCB_CMDCUCSTART, SCB_ADDR, scb_t, scb_command, NORMALIRQS);
944 outb (CTRL_CA, REG_CONTROL);
946 if (priv->resetting == 2)
949 if (status & SCB_STFR) {
950 ether1_recv_done (dev);
952 if (status & SCB_STRNR) {
953 if (ether1_inw (dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS) & SCB_STRXSUSP) {
954 printk (KERN_WARNING "%s: RU went not ready: RU suspended\n", dev->name);
955 ether1_outw (dev, SCB_CMDRXRESUME, SCB_ADDR, scb_t, scb_command, NORMALIRQS);
956 outb (CTRL_CA, REG_CONTROL);
957 priv->stats.rx_dropped ++; /* we suspended due to lack of buffer space */
959 printk(KERN_WARNING "%s: RU went not ready: %04X\n", dev->name,
960 ether1_inw (dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS));
961 printk (KERN_WARNING "RU ptr = %04X\n", ether1_inw (dev, SCB_ADDR, scb_t, scb_rfa_offset,
965 outb (CTRL_ACK, REG_CONTROL);
969 ether1_close (struct net_device *dev)
973 free_irq(dev->irq, dev);
978 static struct net_device_stats *
979 ether1_getstats (struct net_device *dev)
981 struct ether1_priv *priv = (struct ether1_priv *)dev->priv;
986 ether1_set_mac_address(struct net_device *dev, void *p)
988 struct sockaddr *addr = p;
990 if (netif_running(dev))
993 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
996 * We'll set the MAC address on the chip when we open it.
1003 * Set or clear the multicast filter for this adaptor.
1004 * num_addrs == -1 Promiscuous mode, receive all packets.
1005 * num_addrs == 0 Normal mode, clear multicast list.
1006 * num_addrs > 0 Multicast mode, receive normal and MC packets, and do
1007 * best-effort filtering.
1010 ether1_setmulticastlist (struct net_device *dev)
1014 /* ------------------------------------------------------------------------- */
1016 static void __init ether1_banner(void)
1018 static unsigned int version_printed = 0;
1020 if (net_debug && version_printed++ == 0)
1021 printk(KERN_INFO "%s", version);
1024 static struct net_device * __init ether1_init_one(struct expansion_card *ec)
1026 struct net_device *dev;
1027 struct ether1_priv *priv;
1034 dev = init_etherdev(NULL, sizeof(struct ether1_priv));
1038 SET_MODULE_OWNER(dev);
1040 dev->base_addr = ecard_address(ec, ECARD_IOC, ECARD_FAST);
1044 * these will not fail - the nature of the bus ensures this
1046 request_region(dev->base_addr, 16, dev->name);
1047 request_region(dev->base_addr + 0x800, 4096, dev->name);
1049 priv = (struct ether1_priv *)dev->priv;
1050 if ((priv->bus_type = ether1_reset(dev)) == 0)
1053 printk(KERN_INFO "%s: ether1 in slot %d, ",
1054 dev->name, ec->slot_no);
1056 for (i = 0; i < 6; i++) {
1057 dev->dev_addr[i] = inb(IDPROM_ADDRESS + i);
1058 printk ("%2.2x%c", dev->dev_addr[i], i == 5 ? '\n' : ':');
1061 if (ether1_init_2(dev))
1064 dev->open = ether1_open;
1065 dev->stop = ether1_close;
1066 dev->hard_start_xmit = ether1_sendpacket;
1067 dev->get_stats = ether1_getstats;
1068 dev->set_multicast_list = ether1_setmulticastlist;
1069 dev->set_mac_address = ether1_set_mac_address;
1070 dev->tx_timeout = ether1_timeout;
1071 dev->watchdog_timeo = 5 * HZ / 100;
1075 release_region(dev->base_addr, 16);
1076 release_region(dev->base_addr + 0x800, 4096);
1077 unregister_netdev(dev);
1084 static struct expansion_card *e_card[MAX_ECARDS];
1085 static struct net_device *e_dev[MAX_ECARDS];
1087 static int __init ether1_init(void)
1089 int i, ret = -ENODEV;
1093 for (i = 0; i < MAX_ECARDS; i++) {
1094 struct expansion_card *ec;
1095 struct net_device *dev;
1097 ec = ecard_find(0, ether1_cids);
1101 dev = ether1_init_one(ec);
1113 static void __exit ether1_exit(void)
1117 for (i = 0; i < MAX_ECARDS; i++) {
1119 unregister_netdev(e_dev[i]);
1120 release_region(e_dev[i]->base_addr, 16);
1121 release_region(e_dev[i]->base_addr + 0x800, 4096);
1126 ecard_release(e_card[i]);
1132 module_init(ether1_init);
1133 module_exit(ether1_exit);
1135 MODULE_LICENSE("GPL");