linux-bk/drivers/net/a2065.c
<<
>>
Prefs
   1/*
   2 * Amiga Linux/68k A2065 Ethernet Driver
   3 *
   4 * (C) Copyright 1995 by Geert Uytterhoeven <geert@linux-m68k.org>
   5 *
   6 * Fixes and tips by:
   7 *      - Janos Farkas (CHEXUM@sparta.banki.hu)
   8 *      - Jes Degn Soerensen (jds@kom.auc.dk)
   9 *      - Matt Domsch (Matt_Domsch@dell.com)
  10 *
  11 * ----------------------------------------------------------------------------
  12 *
  13 * This program is based on
  14 *
  15 *      ariadne.?:      Amiga Linux/68k Ariadne Ethernet Driver
  16 *                      (C) Copyright 1995 by Geert Uytterhoeven,
  17 *                                            Peter De Schrijver
  18 *
  19 *      lance.c:        An AMD LANCE ethernet driver for linux.
  20 *                      Written 1993-94 by Donald Becker.
  21 *
  22 *      Am79C960:       PCnet(tm)-ISA Single-Chip Ethernet Controller
  23 *                      Advanced Micro Devices
  24 *                      Publication #16907, Rev. B, Amendment/0, May 1994
  25 *
  26 * ----------------------------------------------------------------------------
  27 *
  28 * This file is subject to the terms and conditions of the GNU General Public
  29 * License.  See the file COPYING in the main directory of the Linux
  30 * distribution for more details.
  31 *
  32 * ----------------------------------------------------------------------------
  33 *
  34 * The A2065 is a Zorro-II board made by Commodore/Ameristar. It contains:
  35 *
  36 *      - an Am7990 Local Area Network Controller for Ethernet (LANCE) with
  37 *        both 10BASE-2 (thin coax) and AUI (DB-15) connectors
  38 */
  39
  40#include <linux/errno.h>
  41#include <linux/netdevice.h>
  42#include <linux/etherdevice.h>
  43#include <linux/module.h>
  44#include <linux/stddef.h>
  45#include <linux/kernel.h>
  46#include <linux/interrupt.h>
  47#include <linux/ioport.h>
  48#include <linux/skbuff.h>
  49#include <linux/slab.h>
  50#include <linux/string.h>
  51#include <linux/config.h>
  52#include <linux/init.h>
  53#include <linux/crc32.h>
  54#include <linux/zorro.h>
  55
  56#include <asm/bitops.h>
  57#include <asm/irq.h>
  58#include <asm/amigaints.h>
  59#include <asm/amigahw.h>
  60
  61#include "a2065.h"
  62
  63
  64        /*
  65         *              Transmit/Receive Ring Definitions
  66         */
  67
  68#define LANCE_LOG_TX_BUFFERS    (2)
  69#define LANCE_LOG_RX_BUFFERS    (4)
  70
  71#define TX_RING_SIZE            (1<<LANCE_LOG_TX_BUFFERS)
  72#define RX_RING_SIZE            (1<<LANCE_LOG_RX_BUFFERS)
  73
  74#define TX_RING_MOD_MASK        (TX_RING_SIZE-1)
  75#define RX_RING_MOD_MASK        (RX_RING_SIZE-1)
  76
  77#define PKT_BUF_SIZE            (1544)
  78#define RX_BUFF_SIZE            PKT_BUF_SIZE
  79#define TX_BUFF_SIZE            PKT_BUF_SIZE
  80
  81
  82        /*
  83         *              Layout of the Lance's RAM Buffer
  84         */
  85
  86
  87struct lance_init_block {
  88        unsigned short mode;            /* Pre-set mode (reg. 15) */
  89        unsigned char phys_addr[6];     /* Physical ethernet address */
  90        unsigned filter[2];             /* Multicast filter. */
  91
  92        /* Receive and transmit ring base, along with extra bits. */
  93        unsigned short rx_ptr;          /* receive descriptor addr */
  94        unsigned short rx_len;          /* receive len and high addr */
  95        unsigned short tx_ptr;          /* transmit descriptor addr */
  96        unsigned short tx_len;          /* transmit len and high addr */
  97    
  98        /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */
  99        struct lance_rx_desc brx_ring[RX_RING_SIZE];
 100        struct lance_tx_desc btx_ring[TX_RING_SIZE];
 101
 102        char   rx_buf [RX_RING_SIZE][RX_BUFF_SIZE];
 103        char   tx_buf [TX_RING_SIZE][TX_BUFF_SIZE];
 104};
 105
 106
 107        /*
 108         *              Private Device Data
 109         */
 110
 111struct lance_private {
 112        char *name;
 113        volatile struct lance_regs *ll;
 114        volatile struct lance_init_block *init_block;       /* Hosts view */
 115        volatile struct lance_init_block *lance_init_block; /* Lance view */
 116
 117        int rx_new, tx_new;
 118        int rx_old, tx_old;
 119    
 120        int lance_log_rx_bufs, lance_log_tx_bufs;
 121        int rx_ring_mod_mask, tx_ring_mod_mask;
 122
 123        struct net_device_stats stats;
 124        int tpe;                      /* cable-selection is TPE */
 125        int auto_select;              /* cable-selection by carrier */
 126        unsigned short busmaster_regval;
 127
 128#ifdef CONFIG_SUNLANCE
 129        struct Linux_SBus_DMA *ledma; /* if set this points to ledma and arch=4m */
 130        int burst_sizes;              /* ledma SBus burst sizes */
 131#endif
 132        struct timer_list         multicast_timer;
 133        struct net_device *dev;         /* Backpointer */
 134        struct lance_private *next_module;
 135};
 136
 137#ifdef MODULE
 138static struct lance_private *root_a2065_dev;
 139#endif
 140
 141#define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
 142                        lp->tx_old+lp->tx_ring_mod_mask-lp->tx_new:\
 143                        lp->tx_old - lp->tx_new-1)
 144
 145
 146#define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
 147
 148/* Load the CSR registers */
 149static void load_csrs (struct lance_private *lp)
 150{
 151        volatile struct lance_regs *ll = lp->ll;
 152        volatile struct lance_init_block *aib = lp->lance_init_block;
 153        int leptr;
 154
 155        leptr = LANCE_ADDR (aib);
 156
 157        ll->rap = LE_CSR1;
 158        ll->rdp = (leptr & 0xFFFF);
 159        ll->rap = LE_CSR2;
 160        ll->rdp = leptr >> 16;
 161        ll->rap = LE_CSR3;
 162        ll->rdp = lp->busmaster_regval;
 163
 164        /* Point back to csr0 */
 165        ll->rap = LE_CSR0;
 166}
 167
 168#define ZERO 0
 169
 170/* Setup the Lance Rx and Tx rings */
 171static void lance_init_ring (struct net_device *dev)
 172{
 173        struct lance_private *lp = (struct lance_private *) dev->priv;
 174        volatile struct lance_init_block *ib = lp->init_block;
 175        volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */
 176        int leptr;
 177        int i;
 178
 179        aib = lp->lance_init_block;
 180
 181        /* Lock out other processes while setting up hardware */
 182        netif_stop_queue(dev);
 183        lp->rx_new = lp->tx_new = 0;
 184        lp->rx_old = lp->tx_old = 0;
 185
 186        ib->mode = 0;
 187
 188        /* Copy the ethernet address to the lance init block
 189         * Note that on the sparc you need to swap the ethernet address.
 190         */
 191        ib->phys_addr [0] = dev->dev_addr [1];
 192        ib->phys_addr [1] = dev->dev_addr [0];
 193        ib->phys_addr [2] = dev->dev_addr [3];
 194        ib->phys_addr [3] = dev->dev_addr [2];
 195        ib->phys_addr [4] = dev->dev_addr [5];
 196        ib->phys_addr [5] = dev->dev_addr [4];
 197
 198        if (ZERO)
 199                printk ("TX rings:\n");
 200    
 201        /* Setup the Tx ring entries */
 202        for (i = 0; i <= (1<<lp->lance_log_tx_bufs); i++) {
 203                leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
 204                ib->btx_ring [i].tmd0      = leptr;
 205                ib->btx_ring [i].tmd1_hadr = leptr >> 16;
 206                ib->btx_ring [i].tmd1_bits = 0;
 207                ib->btx_ring [i].length    = 0xf000; /* The ones required by tmd2 */
 208                ib->btx_ring [i].misc      = 0;
 209                if (i < 3)
 210                        if (ZERO) printk ("%d: 0x%8.8x\n", i, leptr);
 211        }
 212
 213        /* Setup the Rx ring entries */
 214        if (ZERO)
 215                printk ("RX rings:\n");
 216        for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) {
 217                leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
 218
 219                ib->brx_ring [i].rmd0      = leptr;
 220                ib->brx_ring [i].rmd1_hadr = leptr >> 16;
 221                ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
 222                ib->brx_ring [i].length    = -RX_BUFF_SIZE | 0xf000;
 223                ib->brx_ring [i].mblength  = 0;
 224                if (i < 3 && ZERO)
 225                        printk ("%d: 0x%8.8x\n", i, leptr);
 226        }
 227
 228        /* Setup the initialization block */
 229    
 230        /* Setup rx descriptor pointer */
 231        leptr = LANCE_ADDR(&aib->brx_ring);
 232        ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
 233        ib->rx_ptr = leptr;
 234        if (ZERO)
 235                printk ("RX ptr: %8.8x\n", leptr);
 236    
 237        /* Setup tx descriptor pointer */
 238        leptr = LANCE_ADDR(&aib->btx_ring);
 239        ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
 240        ib->tx_ptr = leptr;
 241        if (ZERO)
 242                printk ("TX ptr: %8.8x\n", leptr);
 243
 244        /* Clear the multicast filter */
 245        ib->filter [0] = 0;
 246        ib->filter [1] = 0;
 247}
 248
 249static int init_restart_lance (struct lance_private *lp)
 250{
 251        volatile struct lance_regs *ll = lp->ll;
 252        int i;
 253
 254        ll->rap = LE_CSR0;
 255        ll->rdp = LE_C0_INIT;
 256
 257        /* Wait for the lance to complete initialization */
 258        for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++)
 259                barrier();
 260        if ((i == 100) || (ll->rdp & LE_C0_ERR)) {
 261                printk ("LANCE unopened after %d ticks, csr0=%4.4x.\n", i, ll->rdp);
 262                return -EIO;
 263        }
 264
 265        /* Clear IDON by writing a "1", enable interrupts and start lance */
 266        ll->rdp = LE_C0_IDON;
 267        ll->rdp = LE_C0_INEA | LE_C0_STRT;
 268
 269        return 0;
 270}
 271
 272static int lance_rx (struct net_device *dev)
 273{
 274        struct lance_private *lp = (struct lance_private *) dev->priv;
 275        volatile struct lance_init_block *ib = lp->init_block;
 276        volatile struct lance_regs *ll = lp->ll;
 277        volatile struct lance_rx_desc *rd;
 278        unsigned char bits;
 279        int len = 0;                    /* XXX shut up gcc warnings */
 280        struct sk_buff *skb = 0;        /* XXX shut up gcc warnings */
 281
 282#ifdef TEST_HITS
 283        printk ("[");
 284        for (i = 0; i < RX_RING_SIZE; i++) {
 285                if (i == lp->rx_new)
 286                        printk ("%s",
 287                                ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X");
 288                else
 289                        printk ("%s",
 290                                ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1");
 291        }
 292        printk ("]");
 293#endif
 294    
 295        ll->rdp = LE_C0_RINT|LE_C0_INEA;
 296        for (rd = &ib->brx_ring [lp->rx_new];
 297             !((bits = rd->rmd1_bits) & LE_R1_OWN);
 298             rd = &ib->brx_ring [lp->rx_new]) {
 299
 300                /* We got an incomplete frame? */
 301                if ((bits & LE_R1_POK) != LE_R1_POK) {
 302                        lp->stats.rx_over_errors++;
 303                        lp->stats.rx_errors++;
 304                        continue;
 305                } else if (bits & LE_R1_ERR) {
 306                        /* Count only the end frame as a rx error,
 307                         * not the beginning
 308                         */
 309                        if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++;
 310                        if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++;
 311                        if (bits & LE_R1_OFL) lp->stats.rx_over_errors++;
 312                        if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++;
 313                        if (bits & LE_R1_EOP) lp->stats.rx_errors++;
 314                } else {
 315                        len = (rd->mblength & 0xfff) - 4;
 316                        skb = dev_alloc_skb (len+2);
 317
 318                        if (skb == 0) {
 319                                printk ("%s: Memory squeeze, deferring packet.\n",
 320                                        dev->name);
 321                                lp->stats.rx_dropped++;
 322                                rd->mblength = 0;
 323                                rd->rmd1_bits = LE_R1_OWN;
 324                                lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
 325                                return 0;
 326                        }
 327            
 328                        skb->dev = dev;
 329                        skb_reserve (skb, 2);           /* 16 byte align */
 330                        skb_put (skb, len);             /* make room */
 331                        eth_copy_and_sum(skb,
 332                                         (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
 333                                         len, 0);
 334                        skb->protocol = eth_type_trans (skb, dev);
 335                        netif_rx (skb);
 336                        dev->last_rx = jiffies;
 337                        lp->stats.rx_packets++;
 338                        lp->stats.rx_bytes += len;
 339                }
 340
 341                /* Return the packet to the pool */
 342                rd->mblength = 0;
 343                rd->rmd1_bits = LE_R1_OWN;
 344                lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
 345        }
 346        return 0;
 347}
 348
 349static int lance_tx (struct net_device *dev)
 350{
 351        struct lance_private *lp = (struct lance_private *) dev->priv;
 352        volatile struct lance_init_block *ib = lp->init_block;
 353        volatile struct lance_regs *ll = lp->ll;
 354        volatile struct lance_tx_desc *td;
 355        int i, j;
 356        int status;
 357
 358        /* csr0 is 2f3 */
 359        ll->rdp = LE_C0_TINT | LE_C0_INEA;
 360        /* csr0 is 73 */
 361
 362        j = lp->tx_old;
 363        for (i = j; i != lp->tx_new; i = j) {
 364                td = &ib->btx_ring [i];
 365
 366                /* If we hit a packet not owned by us, stop */
 367                if (td->tmd1_bits & LE_T1_OWN)
 368                        break;
 369                
 370                if (td->tmd1_bits & LE_T1_ERR) {
 371                        status = td->misc;
 372            
 373                        lp->stats.tx_errors++;
 374                        if (status & LE_T3_RTY)  lp->stats.tx_aborted_errors++;
 375                        if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
 376
 377                        if (status & LE_T3_CLOS) {
 378                                lp->stats.tx_carrier_errors++;
 379                                if (lp->auto_select) {
 380                                        lp->tpe = 1 - lp->tpe;
 381                                        printk("%s: Carrier Lost, trying %s\n",
 382                                               dev->name, lp->tpe?"TPE":"AUI");
 383                                        /* Stop the lance */
 384                                        ll->rap = LE_CSR0;
 385                                        ll->rdp = LE_C0_STOP;
 386                                        lance_init_ring (dev);
 387                                        load_csrs (lp);
 388                                        init_restart_lance (lp);
 389                                        return 0;
 390                                }
 391                        }
 392
 393                        /* buffer errors and underflows turn off the transmitter */
 394                        /* Restart the adapter */
 395                        if (status & (LE_T3_BUF|LE_T3_UFL)) {
 396                                lp->stats.tx_fifo_errors++;
 397
 398                                printk ("%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
 399                                        dev->name);
 400                                /* Stop the lance */
 401                                ll->rap = LE_CSR0;
 402                                ll->rdp = LE_C0_STOP;
 403                                lance_init_ring (dev);
 404                                load_csrs (lp);
 405                                init_restart_lance (lp);
 406                                return 0;
 407                        }
 408                } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
 409                        /*
 410                         * So we don't count the packet more than once.
 411                         */
 412                        td->tmd1_bits &= ~(LE_T1_POK);
 413
 414                        /* One collision before packet was sent. */
 415                        if (td->tmd1_bits & LE_T1_EONE)
 416                                lp->stats.collisions++;
 417
 418                        /* More than one collision, be optimistic. */
 419                        if (td->tmd1_bits & LE_T1_EMORE)
 420                                lp->stats.collisions += 2;
 421
 422                        lp->stats.tx_packets++;
 423                }
 424        
 425                j = (j + 1) & lp->tx_ring_mod_mask;
 426        }
 427        lp->tx_old = j;
 428        ll->rdp = LE_C0_TINT | LE_C0_INEA;
 429        return 0;
 430}
 431
 432static irqreturn_t
 433lance_interrupt (int irq, void *dev_id, struct pt_regs *regs)
 434{
 435        struct net_device *dev;
 436        struct lance_private *lp;
 437        volatile struct lance_regs *ll;
 438        int csr0;
 439
 440        dev = (struct net_device *) dev_id;
 441
 442        lp = (struct lance_private *) dev->priv;
 443        ll = lp->ll;
 444
 445        ll->rap = LE_CSR0;              /* LANCE Controller Status */
 446        csr0 = ll->rdp;
 447
 448        if (!(csr0 & LE_C0_INTR))       /* Check if any interrupt has */
 449                return IRQ_NONE;        /* been generated by the Lance. */
 450
 451        /* Acknowledge all the interrupt sources ASAP */
 452        ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|
 453                           LE_C0_INIT);
 454
 455        if ((csr0 & LE_C0_ERR)) {
 456                /* Clear the error condition */
 457                ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
 458        }
 459    
 460        if (csr0 & LE_C0_RINT)
 461                lance_rx (dev);
 462
 463        if (csr0 & LE_C0_TINT)
 464                lance_tx (dev);
 465
 466        /* Log misc errors. */
 467        if (csr0 & LE_C0_BABL)
 468                lp->stats.tx_errors++;       /* Tx babble. */
 469        if (csr0 & LE_C0_MISS)
 470                lp->stats.rx_errors++;       /* Missed a Rx frame. */
 471        if (csr0 & LE_C0_MERR) {
 472                printk("%s: Bus master arbitration failure, status %4.4x.\n", dev->name, csr0);
 473                /* Restart the chip. */
 474                ll->rdp = LE_C0_STRT;
 475        }
 476
 477        if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
 478                netif_wake_queue(dev);
 479
 480        ll->rap = LE_CSR0;
 481        ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
 482                                        LE_C0_IDON|LE_C0_INEA;
 483        return IRQ_HANDLED;
 484}
 485
 486struct net_device *last_dev = 0;
 487
 488static int lance_open (struct net_device *dev)
 489{
 490        struct lance_private *lp = (struct lance_private *)dev->priv;
 491        volatile struct lance_regs *ll = lp->ll;
 492        int ret;
 493
 494        last_dev = dev;
 495
 496        /* Stop the Lance */
 497        ll->rap = LE_CSR0;
 498        ll->rdp = LE_C0_STOP;
 499
 500        /* Install the Interrupt handler */
 501        ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, SA_SHIRQ,
 502                          dev->name, dev);
 503        if (ret) return ret;
 504
 505        load_csrs (lp);
 506        lance_init_ring (dev);
 507
 508        netif_start_queue(dev);
 509
 510        return init_restart_lance (lp);
 511}
 512
 513static int lance_close (struct net_device *dev)
 514{
 515        struct lance_private *lp = (struct lance_private *) dev->priv;
 516        volatile struct lance_regs *ll = lp->ll;
 517
 518        netif_stop_queue(dev);
 519        del_timer_sync(&lp->multicast_timer);
 520
 521        /* Stop the card */
 522        ll->rap = LE_CSR0;
 523        ll->rdp = LE_C0_STOP;
 524
 525        free_irq(IRQ_AMIGA_PORTS, dev);
 526        return 0;
 527}
 528
 529static inline int lance_reset (struct net_device *dev)
 530{
 531        struct lance_private *lp = (struct lance_private *)dev->priv;
 532        volatile struct lance_regs *ll = lp->ll;
 533        int status;
 534    
 535        /* Stop the lance */
 536        ll->rap = LE_CSR0;
 537        ll->rdp = LE_C0_STOP;
 538
 539        load_csrs (lp);
 540
 541        lance_init_ring (dev);
 542        dev->trans_start = jiffies;
 543        netif_start_queue(dev);
 544
 545        status = init_restart_lance (lp);
 546#ifdef DEBUG_DRIVER
 547        printk ("Lance restart=%d\n", status);
 548#endif
 549        return status;
 550}
 551
 552static void lance_tx_timeout(struct net_device *dev)
 553{
 554        struct lance_private *lp = (struct lance_private *) dev->priv;
 555        volatile struct lance_regs *ll = lp->ll;
 556
 557        printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
 558               dev->name, ll->rdp);
 559        lance_reset(dev);
 560        netif_wake_queue(dev);
 561}
 562
 563static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
 564{
 565        struct lance_private *lp = (struct lance_private *)dev->priv;
 566        volatile struct lance_regs *ll = lp->ll;
 567        volatile struct lance_init_block *ib = lp->init_block;
 568        int entry, skblen, len;
 569        int status = 0;
 570        static int outs;
 571        unsigned long flags;
 572
 573        skblen = skb->len;
 574        len = skblen;
 575        
 576        if (len < ETH_ZLEN) {
 577                len = ETH_ZLEN;
 578                skb = skb_padto(skb, ETH_ZLEN);
 579                if (skb == NULL)
 580                        return 0;
 581        }
 582
 583        local_irq_save(flags);
 584
 585        if (!TX_BUFFS_AVAIL){
 586                local_irq_restore(flags);
 587                return -1;
 588        }
 589
 590#ifdef DEBUG_DRIVER
 591        /* dump the packet */
 592        {
 593                int i;
 594        
 595                for (i = 0; i < 64; i++) {
 596                        if ((i % 16) == 0)
 597                                printk ("\n");
 598                        printk ("%2.2x ", skb->data [i]);
 599                }
 600        }
 601#endif
 602        entry = lp->tx_new & lp->tx_ring_mod_mask;
 603        ib->btx_ring [entry].length = (-len) | 0xf000;
 604        ib->btx_ring [entry].misc = 0;
 605    
 606        memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
 607
 608        /* Clear the slack of the packet, do I need this? */
 609        if (len != skblen)
 610                memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen);
 611    
 612        /* Now, give the packet to the lance */
 613        ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
 614        lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
 615
 616        outs++;
 617
 618        if (TX_BUFFS_AVAIL <= 0)
 619                netif_stop_queue(dev);
 620
 621        /* Kick the lance: transmit now */
 622        ll->rdp = LE_C0_INEA | LE_C0_TDMD;
 623        dev->trans_start = jiffies;
 624        dev_kfree_skb (skb);
 625    
 626        local_irq_restore(flags);
 627
 628        return status;
 629}
 630
 631static struct net_device_stats *lance_get_stats (struct net_device *dev)
 632{
 633        struct lance_private *lp = (struct lance_private *) dev->priv;
 634
 635        return &lp->stats;
 636}
 637
 638/* taken from the depca driver */
 639static void lance_load_multicast (struct net_device *dev)
 640{
 641        struct lance_private *lp = (struct lance_private *) dev->priv;
 642        volatile struct lance_init_block *ib = lp->init_block;
 643        volatile u16 *mcast_table = (u16 *)&ib->filter;
 644        struct dev_mc_list *dmi=dev->mc_list;
 645        char *addrs;
 646        int i;
 647        u32 crc;
 648        
 649        /* set all multicast bits */
 650        if (dev->flags & IFF_ALLMULTI){ 
 651                ib->filter [0] = 0xffffffff;
 652                ib->filter [1] = 0xffffffff;
 653                return;
 654        }
 655        /* clear the multicast filter */
 656        ib->filter [0] = 0;
 657        ib->filter [1] = 0;
 658
 659        /* Add addresses */
 660        for (i = 0; i < dev->mc_count; i++){
 661                addrs = dmi->dmi_addr;
 662                dmi   = dmi->next;
 663
 664                /* multicast address? */
 665                if (!(*addrs & 1))
 666                        continue;
 667                
 668                crc = ether_crc_le(6, addrs);
 669                crc = crc >> 26;
 670                mcast_table [crc >> 4] |= 1 << (crc & 0xf);
 671        }
 672        return;
 673}
 674
 675static void lance_set_multicast (struct net_device *dev)
 676{
 677        struct lance_private *lp = (struct lance_private *) dev->priv;
 678        volatile struct lance_init_block *ib = lp->init_block;
 679        volatile struct lance_regs *ll = lp->ll;
 680
 681        if (!netif_running(dev))
 682                return;
 683
 684        if (lp->tx_old != lp->tx_new) {
 685                mod_timer(&lp->multicast_timer, jiffies + 4);
 686                netif_wake_queue(dev);
 687                return;
 688        }
 689
 690        netif_stop_queue(dev);
 691
 692        ll->rap = LE_CSR0;
 693        ll->rdp = LE_C0_STOP;
 694        lance_init_ring (dev);
 695
 696        if (dev->flags & IFF_PROMISC) {
 697                ib->mode |= LE_MO_PROM;
 698        } else {
 699                ib->mode &= ~LE_MO_PROM;
 700                lance_load_multicast (dev);
 701        }
 702        load_csrs (lp);
 703        init_restart_lance (lp);
 704        netif_wake_queue(dev);
 705}
 706
 707static int __init a2065_probe(void)
 708{
 709        struct zorro_dev *z = NULL;
 710        struct net_device *dev;
 711        struct lance_private *priv;
 712        int res = -ENODEV;
 713
 714        while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
 715                unsigned long board, base_addr, mem_start;
 716                struct resource *r1, *r2;
 717                int is_cbm;
 718
 719                if (z->id == ZORRO_PROD_CBM_A2065_1 ||
 720                    z->id == ZORRO_PROD_CBM_A2065_2)
 721                        is_cbm = 1;
 722                else if (z->id == ZORRO_PROD_AMERISTAR_A2065)
 723                        is_cbm = 0;
 724                else
 725                        continue;
 726
 727                board = z->resource.start;
 728                base_addr = board+A2065_LANCE;
 729                mem_start = board+A2065_RAM;
 730
 731                r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
 732                                        "Am7990");
 733                if (!r1) continue;
 734                r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
 735                if (!r2) {
 736                        release_resource(r1);
 737                        continue;
 738                }
 739
 740                dev = init_etherdev(NULL, sizeof(struct lance_private));
 741
 742                if (dev == NULL) {
 743                        release_resource(r1);
 744                        release_resource(r2);
 745                        return -ENOMEM;
 746                }
 747                SET_MODULE_OWNER(dev);
 748                priv = dev->priv;
 749
 750                r1->name = dev->name;
 751                r2->name = dev->name;
 752
 753                priv->dev = dev;
 754                dev->dev_addr[0] = 0x00;
 755                if (is_cbm) {                           /* Commodore */
 756                        dev->dev_addr[1] = 0x80;
 757                        dev->dev_addr[2] = 0x10;
 758                } else {                                /* Ameristar */
 759                        dev->dev_addr[1] = 0x00;
 760                        dev->dev_addr[2] = 0x9f;
 761                }
 762                dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
 763                dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
 764                dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
 765                printk("%s: A2065 at 0x%08lx, Ethernet Address "
 766                       "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board,
 767                       dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
 768                       dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
 769
 770                dev->base_addr = ZTWO_VADDR(base_addr);
 771                dev->mem_start = ZTWO_VADDR(mem_start);
 772                dev->mem_end = dev->mem_start+A2065_RAM_SIZE;
 773
 774                priv->ll = (volatile struct lance_regs *)dev->base_addr;
 775                priv->init_block = (struct lance_init_block *)dev->mem_start;
 776                priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
 777                priv->auto_select = 0;
 778                priv->busmaster_regval = LE_C3_BSWP;
 779
 780                priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
 781                priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
 782                priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
 783                priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
 784
 785                dev->open = &lance_open;
 786                dev->stop = &lance_close;
 787                dev->hard_start_xmit = &lance_start_xmit;
 788                dev->tx_timeout = &lance_tx_timeout;
 789                dev->watchdog_timeo = 5*HZ;
 790                dev->get_stats = &lance_get_stats;
 791                dev->set_multicast_list = &lance_set_multicast;
 792                dev->dma = 0;
 793
 794#ifdef MODULE
 795                priv->next_module = root_a2065_dev;
 796                root_a2065_dev = priv;
 797#endif
 798                ether_setup(dev);
 799                init_timer(&priv->multicast_timer);
 800                priv->multicast_timer.data = (unsigned long) dev;
 801                priv->multicast_timer.function =
 802                        (void (*)(unsigned long)) &lance_set_multicast;
 803
 804                res = 0;
 805        }
 806        return res;
 807}
 808
 809
 810static void __exit a2065_cleanup(void)
 811{
 812#ifdef MODULE
 813        struct lance_private *next;
 814        struct net_device *dev;
 815
 816        while (root_a2065_dev) {
 817                next = root_a2065_dev->next_module;
 818                dev = root_a2065_dev->dev;
 819                unregister_netdev(dev);
 820                release_mem_region(ZTWO_PADDR(dev->base_addr),
 821                                   sizeof(struct lance_regs));
 822                release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
 823                free_netdev(dev);
 824                root_a2065_dev = next;
 825        }
 826#endif
 827}
 828
 829module_init(a2065_probe);
 830module_exit(a2065_cleanup);
 831MODULE_LICENSE("GPL");
 832
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.