Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  Amiga Linux/m68k Ariadne Ethernet Driver
0003  *
0004  *  © Copyright 1995-2003 by Geert Uytterhoeven (geert@linux-m68k.org)
0005  *               Peter De Schrijver (p2@mind.be)
0006  *
0007  *  ---------------------------------------------------------------------------
0008  *
0009  *  This program is based on
0010  *
0011  *  lance.c:    An AMD LANCE ethernet driver for linux.
0012  *          Written 1993-94 by Donald Becker.
0013  *
0014  *  Am79C960:   PCnet(tm)-ISA Single-Chip Ethernet Controller
0015  *          Advanced Micro Devices
0016  *          Publication #16907, Rev. B, Amendment/0, May 1994
0017  *
0018  *  MC68230:    Parallel Interface/Timer (PI/T)
0019  *          Motorola Semiconductors, December, 1983
0020  *
0021  *  ---------------------------------------------------------------------------
0022  *
0023  *  This file is subject to the terms and conditions of the GNU General Public
0024  *  License.  See the file COPYING in the main directory of the Linux
0025  *  distribution for more details.
0026  *
0027  *  ---------------------------------------------------------------------------
0028  *
0029  *  The Ariadne is a Zorro-II board made by Village Tronic. It contains:
0030  *
0031  *  - an Am79C960 PCnet-ISA Single-Chip Ethernet Controller with both
0032  *    10BASE-2 (thin coax) and 10BASE-T (UTP) connectors
0033  *
0034  *  - an MC68230 Parallel Interface/Timer configured as 2 parallel ports
0035  */
0036 
0037 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0038 /*#define DEBUG*/
0039 
0040 #include <linux/module.h>
0041 #include <linux/stddef.h>
0042 #include <linux/kernel.h>
0043 #include <linux/string.h>
0044 #include <linux/errno.h>
0045 #include <linux/ioport.h>
0046 #include <linux/netdevice.h>
0047 #include <linux/etherdevice.h>
0048 #include <linux/interrupt.h>
0049 #include <linux/skbuff.h>
0050 #include <linux/init.h>
0051 #include <linux/zorro.h>
0052 #include <linux/bitops.h>
0053 
0054 #include <asm/byteorder.h>
0055 #include <asm/amigaints.h>
0056 #include <asm/amigahw.h>
0057 #include <asm/irq.h>
0058 
0059 #include "ariadne.h"
0060 
0061 #ifdef ARIADNE_DEBUG
0062 int ariadne_debug = ARIADNE_DEBUG;
0063 #else
0064 int ariadne_debug = 1;
0065 #endif
0066 
0067 /* Macros to Fix Endianness problems */
0068 
0069 /* Swap the Bytes in a WORD */
0070 #define swapw(x)    (((x >> 8) & 0x00ff) | ((x << 8) & 0xff00))
0071 /* Get the Low BYTE in a WORD */
0072 #define lowb(x)     (x & 0xff)
0073 /* Get the Swapped High WORD in a LONG */
0074 #define swhighw(x)  ((((x) >> 8) & 0xff00) | (((x) >> 24) & 0x00ff))
0075 /* Get the Swapped Low WORD in a LONG */
0076 #define swloww(x)   ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
0077 
0078 /* Transmit/Receive Ring Definitions */
0079 
0080 #define TX_RING_SIZE    5
0081 #define RX_RING_SIZE    16
0082 
0083 #define PKT_BUF_SIZE    1520
0084 
0085 /* Private Device Data */
0086 
0087 struct ariadne_private {
0088     volatile struct TDRE *tx_ring[TX_RING_SIZE];
0089     volatile struct RDRE *rx_ring[RX_RING_SIZE];
0090     volatile u_short *tx_buff[TX_RING_SIZE];
0091     volatile u_short *rx_buff[RX_RING_SIZE];
0092     int cur_tx, cur_rx;     /* The next free ring entry */
0093     int dirty_tx;           /* The ring entries to be free()ed */
0094     char tx_full;
0095 };
0096 
0097 /* Structure Created in the Ariadne's RAM Buffer */
0098 
0099 struct lancedata {
0100     struct TDRE tx_ring[TX_RING_SIZE];
0101     struct RDRE rx_ring[RX_RING_SIZE];
0102     u_short tx_buff[TX_RING_SIZE][PKT_BUF_SIZE / sizeof(u_short)];
0103     u_short rx_buff[RX_RING_SIZE][PKT_BUF_SIZE / sizeof(u_short)];
0104 };
0105 
0106 static void memcpyw(volatile u_short *dest, u_short *src, int len)
0107 {
0108     while (len >= 2) {
0109         *(dest++) = *(src++);
0110         len -= 2;
0111     }
0112     if (len == 1)
0113         *dest = (*(u_char *)src) << 8;
0114 }
0115 
0116 static void ariadne_init_ring(struct net_device *dev)
0117 {
0118     struct ariadne_private *priv = netdev_priv(dev);
0119     volatile struct lancedata *lancedata = (struct lancedata *)dev->mem_start;
0120     int i;
0121 
0122     netif_stop_queue(dev);
0123 
0124     priv->tx_full = 0;
0125     priv->cur_rx = priv->cur_tx = 0;
0126     priv->dirty_tx = 0;
0127 
0128     /* Set up TX Ring */
0129     for (i = 0; i < TX_RING_SIZE; i++) {
0130         volatile struct TDRE *t = &lancedata->tx_ring[i];
0131         t->TMD0 = swloww(ARIADNE_RAM +
0132                  offsetof(struct lancedata, tx_buff[i]));
0133         t->TMD1 = swhighw(ARIADNE_RAM +
0134                   offsetof(struct lancedata, tx_buff[i])) |
0135             TF_STP | TF_ENP;
0136         t->TMD2 = swapw((u_short)-PKT_BUF_SIZE);
0137         t->TMD3 = 0;
0138         priv->tx_ring[i] = &lancedata->tx_ring[i];
0139         priv->tx_buff[i] = lancedata->tx_buff[i];
0140         netdev_dbg(dev, "TX Entry %2d at %p, Buf at %p\n",
0141                i, &lancedata->tx_ring[i], lancedata->tx_buff[i]);
0142     }
0143 
0144     /* Set up RX Ring */
0145     for (i = 0; i < RX_RING_SIZE; i++) {
0146         volatile struct RDRE *r = &lancedata->rx_ring[i];
0147         r->RMD0 = swloww(ARIADNE_RAM +
0148                  offsetof(struct lancedata, rx_buff[i]));
0149         r->RMD1 = swhighw(ARIADNE_RAM +
0150                   offsetof(struct lancedata, rx_buff[i])) |
0151             RF_OWN;
0152         r->RMD2 = swapw((u_short)-PKT_BUF_SIZE);
0153         r->RMD3 = 0x0000;
0154         priv->rx_ring[i] = &lancedata->rx_ring[i];
0155         priv->rx_buff[i] = lancedata->rx_buff[i];
0156         netdev_dbg(dev, "RX Entry %2d at %p, Buf at %p\n",
0157                i, &lancedata->rx_ring[i], lancedata->rx_buff[i]);
0158     }
0159 }
0160 
0161 static int ariadne_rx(struct net_device *dev)
0162 {
0163     struct ariadne_private *priv = netdev_priv(dev);
0164     int entry = priv->cur_rx % RX_RING_SIZE;
0165     int i;
0166 
0167     /* If we own the next entry, it's a new packet. Send it up */
0168     while (!(lowb(priv->rx_ring[entry]->RMD1) & RF_OWN)) {
0169         int status = lowb(priv->rx_ring[entry]->RMD1);
0170 
0171         if (status != (RF_STP | RF_ENP)) {  /* There was an error */
0172             /* There is a tricky error noted by
0173              * John Murphy <murf@perftech.com> to Russ Nelson:
0174              * Even with full-sized buffers it's possible for a
0175              * jabber packet to use two buffers, with only the
0176              * last correctly noting the error
0177              */
0178             /* Only count a general error at the end of a packet */
0179             if (status & RF_ENP)
0180                 dev->stats.rx_errors++;
0181             if (status & RF_FRAM)
0182                 dev->stats.rx_frame_errors++;
0183             if (status & RF_OFLO)
0184                 dev->stats.rx_over_errors++;
0185             if (status & RF_CRC)
0186                 dev->stats.rx_crc_errors++;
0187             if (status & RF_BUFF)
0188                 dev->stats.rx_fifo_errors++;
0189             priv->rx_ring[entry]->RMD1 &= 0xff00 | RF_STP | RF_ENP;
0190         } else {
0191             /* Malloc up new buffer, compatible with net-3 */
0192             short pkt_len = swapw(priv->rx_ring[entry]->RMD3);
0193             struct sk_buff *skb;
0194 
0195             skb = netdev_alloc_skb(dev, pkt_len + 2);
0196             if (skb == NULL) {
0197                 for (i = 0; i < RX_RING_SIZE; i++)
0198                     if (lowb(priv->rx_ring[(entry + i) % RX_RING_SIZE]->RMD1) & RF_OWN)
0199                         break;
0200 
0201                 if (i > RX_RING_SIZE - 2) {
0202                     dev->stats.rx_dropped++;
0203                     priv->rx_ring[entry]->RMD1 |= RF_OWN;
0204                     priv->cur_rx++;
0205                 }
0206                 break;
0207             }
0208 
0209 
0210             skb_reserve(skb, 2);    /* 16 byte align */
0211             skb_put(skb, pkt_len);  /* Make room */
0212             skb_copy_to_linear_data(skb,
0213                         (const void *)priv->rx_buff[entry],
0214                         pkt_len);
0215             skb->protocol = eth_type_trans(skb, dev);
0216             netdev_dbg(dev, "RX pkt type 0x%04x from %pM to %pM data %p len %u\n",
0217                    ((u_short *)skb->data)[6],
0218                    skb->data + 6, skb->data,
0219                    skb->data, skb->len);
0220 
0221             netif_rx(skb);
0222             dev->stats.rx_packets++;
0223             dev->stats.rx_bytes += pkt_len;
0224         }
0225 
0226         priv->rx_ring[entry]->RMD1 |= RF_OWN;
0227         entry = (++priv->cur_rx) % RX_RING_SIZE;
0228     }
0229 
0230     priv->cur_rx = priv->cur_rx % RX_RING_SIZE;
0231 
0232     /* We should check that at least two ring entries are free.
0233      * If not, we should free one and mark stats->rx_dropped++
0234      */
0235 
0236     return 0;
0237 }
0238 
0239 static irqreturn_t ariadne_interrupt(int irq, void *data)
0240 {
0241     struct net_device *dev = (struct net_device *)data;
0242     volatile struct Am79C960 *lance = (struct Am79C960 *)dev->base_addr;
0243     struct ariadne_private *priv;
0244     int csr0, boguscnt;
0245     int handled = 0;
0246 
0247     lance->RAP = CSR0;      /* PCnet-ISA Controller Status */
0248 
0249     if (!(lance->RDP & INTR))   /* Check if any interrupt has been */
0250         return IRQ_NONE;    /* generated by the board */
0251 
0252     priv = netdev_priv(dev);
0253 
0254     boguscnt = 10;
0255     while ((csr0 = lance->RDP) & (ERR | RINT | TINT) && --boguscnt >= 0) {
0256         /* Acknowledge all of the current interrupt sources ASAP */
0257         lance->RDP = csr0 & ~(INEA | TDMD | STOP | STRT | INIT);
0258 
0259 #ifdef DEBUG
0260         if (ariadne_debug > 5) {
0261             netdev_dbg(dev, "interrupt  csr0=%#02x new csr=%#02x [",
0262                    csr0, lance->RDP);
0263             if (csr0 & INTR)
0264                 pr_cont(" INTR");
0265             if (csr0 & INEA)
0266                 pr_cont(" INEA");
0267             if (csr0 & RXON)
0268                 pr_cont(" RXON");
0269             if (csr0 & TXON)
0270                 pr_cont(" TXON");
0271             if (csr0 & TDMD)
0272                 pr_cont(" TDMD");
0273             if (csr0 & STOP)
0274                 pr_cont(" STOP");
0275             if (csr0 & STRT)
0276                 pr_cont(" STRT");
0277             if (csr0 & INIT)
0278                 pr_cont(" INIT");
0279             if (csr0 & ERR)
0280                 pr_cont(" ERR");
0281             if (csr0 & BABL)
0282                 pr_cont(" BABL");
0283             if (csr0 & CERR)
0284                 pr_cont(" CERR");
0285             if (csr0 & MISS)
0286                 pr_cont(" MISS");
0287             if (csr0 & MERR)
0288                 pr_cont(" MERR");
0289             if (csr0 & RINT)
0290                 pr_cont(" RINT");
0291             if (csr0 & TINT)
0292                 pr_cont(" TINT");
0293             if (csr0 & IDON)
0294                 pr_cont(" IDON");
0295             pr_cont(" ]\n");
0296         }
0297 #endif
0298 
0299         if (csr0 & RINT) {  /* Rx interrupt */
0300             handled = 1;
0301             ariadne_rx(dev);
0302         }
0303 
0304         if (csr0 & TINT) {  /* Tx-done interrupt */
0305             int dirty_tx = priv->dirty_tx;
0306 
0307             handled = 1;
0308             while (dirty_tx < priv->cur_tx) {
0309                 int entry = dirty_tx % TX_RING_SIZE;
0310                 int status = lowb(priv->tx_ring[entry]->TMD1);
0311 
0312                 if (status & TF_OWN)
0313                     break;  /* It still hasn't been Txed */
0314 
0315                 priv->tx_ring[entry]->TMD1 &= 0xff00;
0316 
0317                 if (status & TF_ERR) {
0318                     /* There was an major error, log it */
0319                     int err_status = priv->tx_ring[entry]->TMD3;
0320                     dev->stats.tx_errors++;
0321                     if (err_status & EF_RTRY)
0322                         dev->stats.tx_aborted_errors++;
0323                     if (err_status & EF_LCAR)
0324                         dev->stats.tx_carrier_errors++;
0325                     if (err_status & EF_LCOL)
0326                         dev->stats.tx_window_errors++;
0327                     if (err_status & EF_UFLO) {
0328                         /* Ackk!  On FIFO errors the Tx unit is turned off! */
0329                         dev->stats.tx_fifo_errors++;
0330                         /* Remove this verbosity later! */
0331                         netdev_err(dev, "Tx FIFO error! Status %04x\n",
0332                                csr0);
0333                         /* Restart the chip */
0334                         lance->RDP = STRT;
0335                     }
0336                 } else {
0337                     if (status & (TF_MORE | TF_ONE))
0338                         dev->stats.collisions++;
0339                     dev->stats.tx_packets++;
0340                 }
0341                 dirty_tx++;
0342             }
0343 
0344 #ifndef final_version
0345             if (priv->cur_tx - dirty_tx >= TX_RING_SIZE) {
0346                 netdev_err(dev, "out-of-sync dirty pointer, %d vs. %d, full=%d\n",
0347                        dirty_tx, priv->cur_tx,
0348                        priv->tx_full);
0349                 dirty_tx += TX_RING_SIZE;
0350             }
0351 #endif
0352 
0353             if (priv->tx_full && netif_queue_stopped(dev) &&
0354                 dirty_tx > priv->cur_tx - TX_RING_SIZE + 2) {
0355                 /* The ring is no longer full */
0356                 priv->tx_full = 0;
0357                 netif_wake_queue(dev);
0358             }
0359 
0360             priv->dirty_tx = dirty_tx;
0361         }
0362 
0363         /* Log misc errors */
0364         if (csr0 & BABL) {
0365             handled = 1;
0366             dev->stats.tx_errors++; /* Tx babble */
0367         }
0368         if (csr0 & MISS) {
0369             handled = 1;
0370             dev->stats.rx_errors++; /* Missed a Rx frame */
0371         }
0372         if (csr0 & MERR) {
0373             handled = 1;
0374             netdev_err(dev, "Bus master arbitration failure, status %04x\n",
0375                    csr0);
0376             /* Restart the chip */
0377             lance->RDP = STRT;
0378         }
0379     }
0380 
0381     /* Clear any other interrupt, and set interrupt enable */
0382     lance->RAP = CSR0;      /* PCnet-ISA Controller Status */
0383     lance->RDP = INEA | BABL | CERR | MISS | MERR | IDON;
0384 
0385     if (ariadne_debug > 4)
0386         netdev_dbg(dev, "exiting interrupt, csr%d=%#04x\n",
0387                lance->RAP, lance->RDP);
0388 
0389     return IRQ_RETVAL(handled);
0390 }
0391 
0392 static int ariadne_open(struct net_device *dev)
0393 {
0394     volatile struct Am79C960 *lance = (struct Am79C960 *)dev->base_addr;
0395     u_short in;
0396     u_long version;
0397     int i;
0398 
0399     /* Reset the LANCE */
0400     in = lance->Reset;
0401 
0402     /* Stop the LANCE */
0403     lance->RAP = CSR0;      /* PCnet-ISA Controller Status */
0404     lance->RDP = STOP;
0405 
0406     /* Check the LANCE version */
0407     lance->RAP = CSR88;     /* Chip ID */
0408     version = swapw(lance->RDP);
0409     lance->RAP = CSR89;     /* Chip ID */
0410     version |= swapw(lance->RDP) << 16;
0411     if ((version & 0x00000fff) != 0x00000003) {
0412         pr_warn("Couldn't find AMD Ethernet Chip\n");
0413         return -EAGAIN;
0414     }
0415     if ((version & 0x0ffff000) != 0x00003000) {
0416         pr_warn("Couldn't find Am79C960 (Wrong part number = %ld)\n",
0417                (version & 0x0ffff000) >> 12);
0418         return -EAGAIN;
0419     }
0420 
0421     netdev_dbg(dev, "Am79C960 (PCnet-ISA) Revision %ld\n",
0422            (version & 0xf0000000) >> 28);
0423 
0424     ariadne_init_ring(dev);
0425 
0426     /* Miscellaneous Stuff */
0427     lance->RAP = CSR3;      /* Interrupt Masks and Deferral Control */
0428     lance->RDP = 0x0000;
0429     lance->RAP = CSR4;      /* Test and Features Control */
0430     lance->RDP = DPOLL | APAD_XMT | MFCOM | RCVCCOM | TXSTRTM | JABM;
0431 
0432     /* Set the Multicast Table */
0433     lance->RAP = CSR8;      /* Logical Address Filter, LADRF[15:0] */
0434     lance->RDP = 0x0000;
0435     lance->RAP = CSR9;      /* Logical Address Filter, LADRF[31:16] */
0436     lance->RDP = 0x0000;
0437     lance->RAP = CSR10;     /* Logical Address Filter, LADRF[47:32] */
0438     lance->RDP = 0x0000;
0439     lance->RAP = CSR11;     /* Logical Address Filter, LADRF[63:48] */
0440     lance->RDP = 0x0000;
0441 
0442     /* Set the Ethernet Hardware Address */
0443     lance->RAP = CSR12;     /* Physical Address Register, PADR[15:0] */
0444     lance->RDP = ((const u_short *)&dev->dev_addr[0])[0];
0445     lance->RAP = CSR13;     /* Physical Address Register, PADR[31:16] */
0446     lance->RDP = ((const u_short *)&dev->dev_addr[0])[1];
0447     lance->RAP = CSR14;     /* Physical Address Register, PADR[47:32] */
0448     lance->RDP = ((const u_short *)&dev->dev_addr[0])[2];
0449 
0450     /* Set the Init Block Mode */
0451     lance->RAP = CSR15;     /* Mode Register */
0452     lance->RDP = 0x0000;
0453 
0454     /* Set the Transmit Descriptor Ring Pointer */
0455     lance->RAP = CSR30;     /* Base Address of Transmit Ring */
0456     lance->RDP = swloww(ARIADNE_RAM + offsetof(struct lancedata, tx_ring));
0457     lance->RAP = CSR31;     /* Base Address of transmit Ring */
0458     lance->RDP = swhighw(ARIADNE_RAM + offsetof(struct lancedata, tx_ring));
0459 
0460     /* Set the Receive Descriptor Ring Pointer */
0461     lance->RAP = CSR24;     /* Base Address of Receive Ring */
0462     lance->RDP = swloww(ARIADNE_RAM + offsetof(struct lancedata, rx_ring));
0463     lance->RAP = CSR25;     /* Base Address of Receive Ring */
0464     lance->RDP = swhighw(ARIADNE_RAM + offsetof(struct lancedata, rx_ring));
0465 
0466     /* Set the Number of RX and TX Ring Entries */
0467     lance->RAP = CSR76;     /* Receive Ring Length */
0468     lance->RDP = swapw(((u_short)-RX_RING_SIZE));
0469     lance->RAP = CSR78;     /* Transmit Ring Length */
0470     lance->RDP = swapw(((u_short)-TX_RING_SIZE));
0471 
0472     /* Enable Media Interface Port Auto Select (10BASE-2/10BASE-T) */
0473     lance->RAP = ISACSR2;       /* Miscellaneous Configuration */
0474     lance->IDP = ASEL;
0475 
0476     /* LED Control */
0477     lance->RAP = ISACSR5;       /* LED1 Status */
0478     lance->IDP = PSE|XMTE;
0479     lance->RAP = ISACSR6;   /* LED2 Status */
0480     lance->IDP = PSE|COLE;
0481     lance->RAP = ISACSR7;   /* LED3 Status */
0482     lance->IDP = PSE|RCVE;
0483 
0484     netif_start_queue(dev);
0485 
0486     i = request_irq(IRQ_AMIGA_PORTS, ariadne_interrupt, IRQF_SHARED,
0487             dev->name, dev);
0488     if (i)
0489         return i;
0490 
0491     lance->RAP = CSR0;      /* PCnet-ISA Controller Status */
0492     lance->RDP = INEA | STRT;
0493 
0494     return 0;
0495 }
0496 
0497 static int ariadne_close(struct net_device *dev)
0498 {
0499     volatile struct Am79C960 *lance = (struct Am79C960 *)dev->base_addr;
0500 
0501     netif_stop_queue(dev);
0502 
0503     lance->RAP = CSR112;        /* Missed Frame Count */
0504     dev->stats.rx_missed_errors = swapw(lance->RDP);
0505     lance->RAP = CSR0;      /* PCnet-ISA Controller Status */
0506 
0507     if (ariadne_debug > 1) {
0508         netdev_dbg(dev, "Shutting down ethercard, status was %02x\n",
0509                lance->RDP);
0510         netdev_dbg(dev, "%lu packets missed\n",
0511                dev->stats.rx_missed_errors);
0512     }
0513 
0514     /* We stop the LANCE here -- it occasionally polls memory if we don't */
0515     lance->RDP = STOP;
0516 
0517     free_irq(IRQ_AMIGA_PORTS, dev);
0518 
0519     return 0;
0520 }
0521 
0522 static inline void ariadne_reset(struct net_device *dev)
0523 {
0524     volatile struct Am79C960 *lance = (struct Am79C960 *)dev->base_addr;
0525 
0526     lance->RAP = CSR0;  /* PCnet-ISA Controller Status */
0527     lance->RDP = STOP;
0528     ariadne_init_ring(dev);
0529     lance->RDP = INEA | STRT;
0530     netif_start_queue(dev);
0531 }
0532 
0533 static void ariadne_tx_timeout(struct net_device *dev, unsigned int txqueue)
0534 {
0535     volatile struct Am79C960 *lance = (struct Am79C960 *)dev->base_addr;
0536 
0537     netdev_err(dev, "transmit timed out, status %04x, resetting\n",
0538            lance->RDP);
0539     ariadne_reset(dev);
0540     netif_wake_queue(dev);
0541 }
0542 
0543 static netdev_tx_t ariadne_start_xmit(struct sk_buff *skb,
0544                       struct net_device *dev)
0545 {
0546     struct ariadne_private *priv = netdev_priv(dev);
0547     volatile struct Am79C960 *lance = (struct Am79C960 *)dev->base_addr;
0548     int entry;
0549     unsigned long flags;
0550     int len = skb->len;
0551 
0552 #if 0
0553     if (ariadne_debug > 3) {
0554         lance->RAP = CSR0;  /* PCnet-ISA Controller Status */
0555         netdev_dbg(dev, "%s: csr0 %04x\n", __func__, lance->RDP);
0556         lance->RDP = 0x0000;
0557     }
0558 #endif
0559 
0560     /* FIXME: is the 79C960 new enough to do its own padding right ? */
0561     if (skb->len < ETH_ZLEN) {
0562         if (skb_padto(skb, ETH_ZLEN))
0563             return NETDEV_TX_OK;
0564         len = ETH_ZLEN;
0565     }
0566 
0567     /* Fill in a Tx ring entry */
0568 
0569     netdev_dbg(dev, "TX pkt type 0x%04x from %pM to %pM data %p len %u\n",
0570            ((u_short *)skb->data)[6],
0571            skb->data + 6, skb->data,
0572            skb->data, skb->len);
0573 
0574     local_irq_save(flags);
0575 
0576     entry = priv->cur_tx % TX_RING_SIZE;
0577 
0578     /* Caution: the write order is important here, set the base address with
0579        the "ownership" bits last */
0580 
0581     priv->tx_ring[entry]->TMD2 = swapw((u_short)-skb->len);
0582     priv->tx_ring[entry]->TMD3 = 0x0000;
0583     memcpyw(priv->tx_buff[entry], (u_short *)skb->data, len);
0584 
0585 #ifdef DEBUG
0586     print_hex_dump(KERN_DEBUG, "tx_buff: ", DUMP_PREFIX_OFFSET, 16, 1,
0587                (void *)priv->tx_buff[entry],
0588                skb->len > 64 ? 64 : skb->len, true);
0589 #endif
0590 
0591     priv->tx_ring[entry]->TMD1 = (priv->tx_ring[entry]->TMD1 & 0xff00)
0592         | TF_OWN | TF_STP | TF_ENP;
0593 
0594     dev_kfree_skb(skb);
0595 
0596     priv->cur_tx++;
0597     if ((priv->cur_tx >= TX_RING_SIZE) &&
0598         (priv->dirty_tx >= TX_RING_SIZE)) {
0599 
0600         netdev_dbg(dev, "*** Subtracting TX_RING_SIZE from cur_tx (%d) and dirty_tx (%d)\n",
0601                priv->cur_tx, priv->dirty_tx);
0602 
0603         priv->cur_tx -= TX_RING_SIZE;
0604         priv->dirty_tx -= TX_RING_SIZE;
0605     }
0606     dev->stats.tx_bytes += len;
0607 
0608     /* Trigger an immediate send poll */
0609     lance->RAP = CSR0;      /* PCnet-ISA Controller Status */
0610     lance->RDP = INEA | TDMD;
0611 
0612     if (lowb(priv->tx_ring[(entry + 1) % TX_RING_SIZE]->TMD1) != 0) {
0613         netif_stop_queue(dev);
0614         priv->tx_full = 1;
0615     }
0616     local_irq_restore(flags);
0617 
0618     return NETDEV_TX_OK;
0619 }
0620 
0621 static struct net_device_stats *ariadne_get_stats(struct net_device *dev)
0622 {
0623     volatile struct Am79C960 *lance = (struct Am79C960 *)dev->base_addr;
0624     short saved_addr;
0625     unsigned long flags;
0626 
0627     local_irq_save(flags);
0628     saved_addr = lance->RAP;
0629     lance->RAP = CSR112;        /* Missed Frame Count */
0630     dev->stats.rx_missed_errors = swapw(lance->RDP);
0631     lance->RAP = saved_addr;
0632     local_irq_restore(flags);
0633 
0634     return &dev->stats;
0635 }
0636 
0637 /* Set or clear the multicast filter for this adaptor.
0638  * num_addrs == -1  Promiscuous mode, receive all packets
0639  * num_addrs == 0   Normal mode, clear multicast list
0640  * num_addrs > 0    Multicast mode, receive normal and MC packets,
0641  *          and do best-effort filtering.
0642  */
0643 static void set_multicast_list(struct net_device *dev)
0644 {
0645     volatile struct Am79C960 *lance = (struct Am79C960 *)dev->base_addr;
0646 
0647     if (!netif_running(dev))
0648         return;
0649 
0650     netif_stop_queue(dev);
0651 
0652     /* We take the simple way out and always enable promiscuous mode */
0653     lance->RAP = CSR0;      /* PCnet-ISA Controller Status */
0654     lance->RDP = STOP;      /* Temporarily stop the lance */
0655     ariadne_init_ring(dev);
0656 
0657     if (dev->flags & IFF_PROMISC) {
0658         lance->RAP = CSR15; /* Mode Register */
0659         lance->RDP = PROM;  /* Set promiscuous mode */
0660     } else {
0661         short multicast_table[4];
0662         int num_addrs = netdev_mc_count(dev);
0663         int i;
0664         /* We don't use the multicast table,
0665          * but rely on upper-layer filtering
0666          */
0667         memset(multicast_table, (num_addrs == 0) ? 0 : -1,
0668                sizeof(multicast_table));
0669         for (i = 0; i < 4; i++) {
0670             lance->RAP = CSR8 + (i << 8);
0671                     /* Logical Address Filter */
0672             lance->RDP = swapw(multicast_table[i]);
0673         }
0674         lance->RAP = CSR15; /* Mode Register */
0675         lance->RDP = 0x0000;    /* Unset promiscuous mode */
0676     }
0677 
0678     lance->RAP = CSR0;      /* PCnet-ISA Controller Status */
0679     lance->RDP = INEA | STRT | IDON;/* Resume normal operation */
0680 
0681     netif_wake_queue(dev);
0682 }
0683 
0684 
0685 static void ariadne_remove_one(struct zorro_dev *z)
0686 {
0687     struct net_device *dev = zorro_get_drvdata(z);
0688 
0689     unregister_netdev(dev);
0690     release_mem_region(ZTWO_PADDR(dev->base_addr), sizeof(struct Am79C960));
0691     release_mem_region(ZTWO_PADDR(dev->mem_start), ARIADNE_RAM_SIZE);
0692     free_netdev(dev);
0693 }
0694 
0695 static const struct zorro_device_id ariadne_zorro_tbl[] = {
0696     { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE },
0697     { 0 }
0698 };
0699 MODULE_DEVICE_TABLE(zorro, ariadne_zorro_tbl);
0700 
0701 static const struct net_device_ops ariadne_netdev_ops = {
0702     .ndo_open       = ariadne_open,
0703     .ndo_stop       = ariadne_close,
0704     .ndo_start_xmit     = ariadne_start_xmit,
0705     .ndo_tx_timeout     = ariadne_tx_timeout,
0706     .ndo_get_stats      = ariadne_get_stats,
0707     .ndo_set_rx_mode    = set_multicast_list,
0708     .ndo_validate_addr  = eth_validate_addr,
0709     .ndo_set_mac_address    = eth_mac_addr,
0710 };
0711 
0712 static int ariadne_init_one(struct zorro_dev *z,
0713                 const struct zorro_device_id *ent)
0714 {
0715     unsigned long board = z->resource.start;
0716     unsigned long base_addr = board + ARIADNE_LANCE;
0717     unsigned long mem_start = board + ARIADNE_RAM;
0718     struct resource *r1, *r2;
0719     struct net_device *dev;
0720     u8 addr[ETH_ALEN];
0721     u32 serial;
0722     int err;
0723 
0724     r1 = request_mem_region(base_addr, sizeof(struct Am79C960), "Am79C960");
0725     if (!r1)
0726         return -EBUSY;
0727     r2 = request_mem_region(mem_start, ARIADNE_RAM_SIZE, "RAM");
0728     if (!r2) {
0729         release_mem_region(base_addr, sizeof(struct Am79C960));
0730         return -EBUSY;
0731     }
0732 
0733     dev = alloc_etherdev(sizeof(struct ariadne_private));
0734     if (dev == NULL) {
0735         release_mem_region(base_addr, sizeof(struct Am79C960));
0736         release_mem_region(mem_start, ARIADNE_RAM_SIZE);
0737         return -ENOMEM;
0738     }
0739 
0740     r1->name = dev->name;
0741     r2->name = dev->name;
0742 
0743     serial = be32_to_cpu(z->rom.er_SerialNumber);
0744     addr[0] = 0x00;
0745     addr[1] = 0x60;
0746     addr[2] = 0x30;
0747     addr[3] = (serial >> 16) & 0xff;
0748     addr[4] = (serial >> 8) & 0xff;
0749     addr[5] = serial & 0xff;
0750     eth_hw_addr_set(dev, addr);
0751     dev->base_addr = (unsigned long)ZTWO_VADDR(base_addr);
0752     dev->mem_start = (unsigned long)ZTWO_VADDR(mem_start);
0753     dev->mem_end = dev->mem_start + ARIADNE_RAM_SIZE;
0754 
0755     dev->netdev_ops = &ariadne_netdev_ops;
0756     dev->watchdog_timeo = 5 * HZ;
0757 
0758     err = register_netdev(dev);
0759     if (err) {
0760         release_mem_region(base_addr, sizeof(struct Am79C960));
0761         release_mem_region(mem_start, ARIADNE_RAM_SIZE);
0762         free_netdev(dev);
0763         return err;
0764     }
0765     zorro_set_drvdata(z, dev);
0766 
0767     netdev_info(dev, "Ariadne at 0x%08lx, Ethernet Address %pM\n",
0768             board, dev->dev_addr);
0769 
0770     return 0;
0771 }
0772 
0773 static struct zorro_driver ariadne_driver = {
0774     .name       = "ariadne",
0775     .id_table   = ariadne_zorro_tbl,
0776     .probe      = ariadne_init_one,
0777     .remove     = ariadne_remove_one,
0778 };
0779 
0780 static int __init ariadne_init_module(void)
0781 {
0782     return zorro_register_driver(&ariadne_driver);
0783 }
0784 
0785 static void __exit ariadne_cleanup_module(void)
0786 {
0787     zorro_unregister_driver(&ariadne_driver);
0788 }
0789 
0790 module_init(ariadne_init_module);
0791 module_exit(ariadne_cleanup_module);
0792 
0793 MODULE_LICENSE("GPL");