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