linux-old/drivers/net/3c523.c
<<
>>
Prefs
   1/*
   2   net-3-driver for the 3c523 Etherlink/MC card (i82586 Ethernet chip)
   3
   4
   5   This is an extension to the Linux operating system, and is covered by the
   6   same GNU General Public License that covers that work.
   7
   8   Copyright 1995, 1996 by Chris Beauregard (cpbeaure@undergrad.math.uwaterloo.ca)
   9
  10   This is basically Michael Hipp's ni52 driver, with a new probing
  11   algorithm and some minor changes to the 82586 CA and reset routines.
  12   Thanks a lot Michael for a really clean i82586 implementation!  Unless
  13   otherwise documented in ni52.c, any bugs are mine.
  14
  15   Contrary to the Ethernet-HOWTO, this isn't based on the 3c507 driver in
  16   any way.  The ni52 is a lot easier to modify.
  17
  18   sources:
  19   ni52.c
  20
  21   Crynwr packet driver collection was a great reference for my first
  22   attempt at this sucker.  The 3c507 driver also helped, until I noticed
  23   that ni52.c was a lot nicer.
  24
  25   EtherLink/MC: Micro Channel Ethernet Adapter Technical Reference
  26   Manual, courtesy of 3Com CardFacts, documents the 3c523-specific
  27   stuff.  Information on CardFacts is found in the Ethernet HOWTO.
  28   Also see <a href="http://www.3com.com/">
  29
  30   Microprocessor Communications Support Chips, T.J. Byers, ISBN
  31   0-444-01224-9, has a section on the i82586.  It tells you just enough
  32   to know that you really don't want to learn how to program the chip.
  33
  34   The original device probe code was stolen from ps2esdi.c
  35
  36   Known Problems:
  37   Since most of the code was stolen from ni52.c, you'll run across the
  38   same bugs in the 0.62 version of ni52.c, plus maybe a few because of
  39   the 3c523 idiosynchacies.  The 3c523 has 16K of RAM though, so there
  40   shouldn't be the overrun problem that the 8K ni52 has.
  41
  42   This driver is for a 16K adapter.  It should work fine on the 64K
  43   adapters, but it will only use one of the 4 banks of RAM.  Modifying
  44   this for the 64K version would require a lot of heinous bank
  45   switching, which I'm sure not interested in doing.  If you try to
  46   implement a bank switching version, you'll basically have to remember
  47   what bank is enabled and do a switch everytime you access a memory
  48   location that's not current.  You'll also have to remap pointers on
  49   the driver side, because it only knows about 16K of the memory.
  50   Anyone desperate or masochistic enough to try?
  51
  52   It seems to be stable now when multiple transmit buffers are used.  I
  53   can't see any performance difference, but then I'm working on a 386SX.
  54
  55   Multicast doesn't work.  It doesn't even pretend to work.  Don't use
  56   it.  Don't compile your kernel with multicast support.  I don't know
  57   why.
  58
  59   Features:
  60   This driver is useable as a loadable module.  If you try to specify an
  61   IRQ or a IO address (via insmod 3c523.o irq=xx io=0xyyy), it will
  62   search the MCA slots until it finds a 3c523 with the specified
  63   parameters.
  64
  65   This driver does support multiple ethernet cards when used as a module
  66   (up to MAX_3C523_CARDS, the default being 4)
  67
  68   This has been tested with both BNC and TP versions, internal and
  69   external transceivers.  Haven't tested with the 64K version (that I
  70   know of).
  71
  72   History:
  73   Jan 1st, 1996
  74   first public release
  75   Feb 4th, 1996
  76   update to 1.3.59, incorporated multicast diffs from ni52.c
  77   Feb 15th, 1996
  78   added shared irq support
  79   Apr 1999
  80   added support for multiple cards when used as a module
  81   added option to disable multicast as is causes problems
  82       Ganesh Sittampalam <ganesh.sittampalam@magdalen.oxford.ac.uk>
  83       Stuart Adamson <stuart.adamson@compsoc.net>
  84   Nov 2001
  85   added support for ethtool (jgarzik)
  86        
  87   $Header: /fsys2/home/chrisb/linux-1.3.59-MCA/drivers/net/RCS/3c523.c,v 1.1 1996/02/05 01:53:46 chrisb Exp chrisb $
  88 */
  89
  90#define DRV_NAME                "3c523"
  91#define DRV_VERSION             "17-Nov-2001"
  92
  93#include <linux/module.h>
  94#include <linux/kernel.h>
  95#include <linux/sched.h>
  96#include <linux/string.h>
  97#include <linux/errno.h>
  98#include <linux/ioport.h>
  99#include <linux/slab.h>
 100#include <linux/interrupt.h>
 101#include <linux/delay.h>
 102#include <linux/mca.h>
 103#include <linux/ethtool.h>
 104
 105#include <asm/uaccess.h>
 106#include <asm/processor.h>
 107#include <asm/bitops.h>
 108#include <asm/io.h>
 109
 110#include <linux/netdevice.h>
 111#include <linux/etherdevice.h>
 112#include <linux/skbuff.h>
 113#include <linux/init.h>
 114
 115#include "3c523.h"
 116
 117/*************************************************************************/
 118#define DEBUG                   /* debug on */
 119#define SYSBUSVAL 0             /* 1 = 8 Bit, 0 = 16 bit - 3c523 only does 16 bit */
 120#undef ELMC_MULTICAST           /* Disable multicast support as it is somewhat seriously broken at the moment */
 121
 122#define make32(ptr16) (p->memtop + (short) (ptr16) )
 123#define make24(ptr32) ((char *) (ptr32) - p->base)
 124#define make16(ptr32) ((unsigned short) ((unsigned long) (ptr32) - (unsigned long) p->memtop ))
 125
 126/*************************************************************************/
 127/*
 128   Tables to which we can map values in the configuration registers.
 129 */
 130static int irq_table[] __initdata = {
 131        12, 7, 3, 9
 132};
 133
 134static int csr_table[] __initdata = {
 135        0x300, 0x1300, 0x2300, 0x3300
 136};
 137
 138static int shm_table[] __initdata = {
 139        0x0c0000, 0x0c8000, 0x0d0000, 0x0d8000
 140};
 141
 142/******************* how to calculate the buffers *****************************
 143
 144
 145  * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
 146  * --------------- in a different (more stable?) mode. Only in this mode it's
 147  *                 possible to configure the driver with 'NO_NOPCOMMANDS'
 148
 149sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
 150sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
 151sizeof(rfd) = 24; sizeof(rbd) = 12;
 152sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
 153sizeof(nop_cmd) = 8;
 154
 155  * if you don't know the driver, better do not change this values: */
 156
 157#define RECV_BUFF_SIZE 1524     /* slightly oversized */
 158#define XMIT_BUFF_SIZE 1524     /* slightly oversized */
 159#define NUM_XMIT_BUFFS 1        /* config for both, 8K and 16K shmem */
 160#define NUM_RECV_BUFFS_8  4     /* config for 8K shared mem */
 161#define NUM_RECV_BUFFS_16 9     /* config for 16K shared mem */
 162
 163#if (NUM_XMIT_BUFFS == 1)
 164#define NO_NOPCOMMANDS          /* only possible with NUM_XMIT_BUFFS=1 */
 165#endif
 166
 167/**************************************************************************/
 168
 169#define DELAY(x) { mdelay(32 * x); }
 170
 171/* a much shorter delay: */
 172#define DELAY_16(); { udelay(16) ; }
 173
 174/* wait for command with timeout: */
 175#define WAIT_4_SCB_CMD() { int i; \
 176  for(i=0;i<1024;i++) { \
 177    if(!p->scb->cmd) break; \
 178    DELAY_16(); \
 179    if(i == 1023) { \
 180      printk(KERN_WARNING "%s:%d: scb_cmd timed out .. resetting i82586\n",\
 181        dev->name,__LINE__); \
 182      elmc_id_reset586(); } } }
 183
 184static void elmc_interrupt(int irq, void *dev_id, struct pt_regs *reg_ptr);
 185static int elmc_open(struct net_device *dev);
 186static int elmc_close(struct net_device *dev);
 187static int elmc_send_packet(struct sk_buff *, struct net_device *);
 188static struct net_device_stats *elmc_get_stats(struct net_device *dev);
 189static void elmc_timeout(struct net_device *dev);
 190#ifdef ELMC_MULTICAST
 191static void set_multicast_list(struct net_device *dev);
 192#endif
 193static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd);
 194
 195/* helper-functions */
 196static int init586(struct net_device *dev);
 197static int check586(struct net_device *dev, unsigned long where, unsigned size);
 198static void alloc586(struct net_device *dev);
 199static void startrecv586(struct net_device *dev);
 200static void *alloc_rfa(struct net_device *dev, void *ptr);
 201static void elmc_rcv_int(struct net_device *dev);
 202static void elmc_xmt_int(struct net_device *dev);
 203static void elmc_rnr_int(struct net_device *dev);
 204
 205struct priv {
 206        struct net_device_stats stats;
 207        unsigned long base;
 208        char *memtop;
 209        unsigned long mapped_start;             /* Start of ioremap */
 210        volatile struct rfd_struct *rfd_last, *rfd_top, *rfd_first;
 211        volatile struct scp_struct *scp;        /* volatile is important */
 212        volatile struct iscp_struct *iscp;      /* volatile is important */
 213        volatile struct scb_struct *scb;        /* volatile is important */
 214        volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];
 215        volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
 216#if (NUM_XMIT_BUFFS == 1)
 217        volatile struct nop_cmd_struct *nop_cmds[2];
 218#else
 219        volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
 220#endif
 221        volatile int nop_point, num_recv_buffs;
 222        volatile char *xmit_cbuffs[NUM_XMIT_BUFFS];
 223        volatile int xmit_count, xmit_last;
 224        volatile int slot;
 225};
 226
 227#define elmc_attn586()  {elmc_do_attn586(dev->base_addr,ELMC_CTRL_INTE);}
 228#define elmc_reset586() {elmc_do_reset586(dev->base_addr,ELMC_CTRL_INTE);}
 229
 230/* with interrupts disabled - this will clear the interrupt bit in the
 231   3c523 control register, and won't put it back.  This effectively
 232   disables interrupts on the card. */
 233#define elmc_id_attn586()  {elmc_do_attn586(dev->base_addr,0);}
 234#define elmc_id_reset586() {elmc_do_reset586(dev->base_addr,0);}
 235
 236/*************************************************************************/
 237/*
 238   Do a Channel Attention on the 3c523.  This is extremely board dependent.
 239 */
 240static void elmc_do_attn586(int ioaddr, int ints)
 241{
 242        /* the 3c523 requires a minimum of 500 ns.  The delays here might be
 243           a little too large, and hence they may cut the performance of the
 244           card slightly.  If someone who knows a little more about Linux
 245           timing would care to play with these, I'd appreciate it. */
 246
 247        /* this bit masking stuff is crap.  I'd rather have separate
 248           registers with strobe triggers for each of these functions.  <sigh>
 249           Ya take what ya got. */
 250
 251        outb(ELMC_CTRL_RST | 0x3 | ELMC_CTRL_CA | ints, ioaddr + ELMC_CTRL);
 252        DELAY_16();             /* > 500 ns */
 253        outb(ELMC_CTRL_RST | 0x3 | ints, ioaddr + ELMC_CTRL);
 254}
 255
 256/*************************************************************************/
 257/*
 258   Reset the 82586 on the 3c523.  Also very board dependent.
 259 */
 260static void elmc_do_reset586(int ioaddr, int ints)
 261{
 262        /* toggle the RST bit low then high */
 263        outb(0x3 | ELMC_CTRL_LBK, ioaddr + ELMC_CTRL);
 264        DELAY_16();             /* > 500 ns */
 265        outb(ELMC_CTRL_RST | ELMC_CTRL_LBK | 0x3, ioaddr + ELMC_CTRL);
 266
 267        elmc_do_attn586(ioaddr, ints);
 268}
 269
 270/**********************************************
 271 * close device
 272 */
 273
 274static int elmc_close(struct net_device *dev)
 275{
 276        netif_stop_queue(dev);
 277        elmc_id_reset586();     /* the hard way to stop the receiver */
 278        free_irq(dev->irq, dev);
 279        return 0;
 280}
 281
 282/**********************************************
 283 * open device
 284 */
 285
 286static int elmc_open(struct net_device *dev)
 287{
 288        int ret;
 289
 290        elmc_id_attn586();      /* disable interrupts */
 291
 292        ret = request_irq(dev->irq, &elmc_interrupt, SA_SHIRQ | SA_SAMPLE_RANDOM,
 293                          dev->name, dev);
 294        if (ret) {
 295                printk(KERN_ERR "%s: couldn't get irq %d\n", dev->name, dev->irq);
 296                elmc_id_reset586();
 297                return ret;
 298        }
 299        alloc586(dev);
 300        init586(dev);
 301        startrecv586(dev);
 302        netif_start_queue(dev);
 303        return 0;               /* most done by init */
 304}
 305
 306/**********************************************
 307 * Check to see if there's an 82586 out there.
 308 */
 309
 310static int __init check586(struct net_device *dev, unsigned long where, unsigned size)
 311{
 312        struct priv *p = (struct priv *) dev->priv;
 313        char *iscp_addrs[2];
 314        int i = 0;
 315
 316        p->base = (unsigned long) bus_to_virt((unsigned long)where) + size - 0x01000000;
 317        p->memtop = bus_to_virt((unsigned long)where) + size;
 318        p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
 319        memset((char *) p->scp, 0, sizeof(struct scp_struct));
 320        p->scp->sysbus = SYSBUSVAL;     /* 1 = 8Bit-Bus, 0 = 16 Bit */
 321
 322        iscp_addrs[0] = bus_to_virt((unsigned long)where);
 323        iscp_addrs[1] = (char *) p->scp - sizeof(struct iscp_struct);
 324
 325        for (i = 0; i < 2; i++) {
 326                p->iscp = (struct iscp_struct *) iscp_addrs[i];
 327                memset((char *) p->iscp, 0, sizeof(struct iscp_struct));
 328
 329                p->scp->iscp = make24(p->iscp);
 330                p->iscp->busy = 1;
 331
 332                elmc_id_reset586();
 333
 334                /* reset586 does an implicit CA */
 335
 336                /* apparently, you sometimes have to kick the 82586 twice... */
 337                elmc_id_attn586();
 338                DELAY(1);
 339
 340                if (p->iscp->busy) {    /* i82586 clears 'busy' after successful init */
 341                        return 0;
 342                }
 343        }
 344        return 1;
 345}
 346
 347/******************************************************************
 348 * set iscp at the right place, called by elmc_probe and open586.
 349 */
 350
 351void alloc586(struct net_device *dev)
 352{
 353        struct priv *p = (struct priv *) dev->priv;
 354
 355        elmc_id_reset586();
 356        DELAY(2);
 357
 358        p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
 359        p->scb = (struct scb_struct *) bus_to_virt(dev->mem_start);
 360        p->iscp = (struct iscp_struct *) ((char *) p->scp - sizeof(struct iscp_struct));
 361
 362        memset((char *) p->iscp, 0, sizeof(struct iscp_struct));
 363        memset((char *) p->scp, 0, sizeof(struct scp_struct));
 364
 365        p->scp->iscp = make24(p->iscp);
 366        p->scp->sysbus = SYSBUSVAL;
 367        p->iscp->scb_offset = make16(p->scb);
 368
 369        p->iscp->busy = 1;
 370        elmc_id_reset586();
 371        elmc_id_attn586();
 372
 373        DELAY(2);
 374
 375        if (p->iscp->busy) {
 376                printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name);
 377        }
 378        memset((char *) p->scb, 0, sizeof(struct scb_struct));
 379}
 380
 381/*****************************************************************/
 382
 383static int elmc_getinfo(char *buf, int slot, void *d)
 384{
 385        int len = 0;
 386        struct net_device *dev = (struct net_device *) d;
 387        int i;
 388
 389        if (dev == NULL)
 390                return len;
 391
 392        len += sprintf(buf + len, "Revision: 0x%x\n",
 393                       inb(dev->base_addr + ELMC_REVISION) & 0xf);
 394        len += sprintf(buf + len, "IRQ: %d\n", dev->irq);
 395        len += sprintf(buf + len, "IO Address: %#lx-%#lx\n", dev->base_addr,
 396                       dev->base_addr + ELMC_IO_EXTENT);
 397        len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start,
 398                       dev->mem_end - 1);
 399        len += sprintf(buf + len, "Transceiver: %s\n", dev->if_port ?
 400                       "External" : "Internal");
 401        len += sprintf(buf + len, "Device: %s\n", dev->name);
 402        len += sprintf(buf + len, "Hardware Address:");
 403        for (i = 0; i < 6; i++) {
 404                len += sprintf(buf + len, " %02x", dev->dev_addr[i]);
 405        }
 406        buf[len++] = '\n';
 407        buf[len] = 0;
 408
 409        return len;
 410}                               /* elmc_getinfo() */
 411
 412/*****************************************************************/
 413
 414int __init elmc_probe(struct net_device *dev)
 415{
 416        static int slot;
 417        int base_addr = dev->base_addr;
 418        int irq = dev->irq;
 419        u_char status = 0;
 420        u_char revision = 0;
 421        int i = 0;
 422        unsigned int size = 0;
 423        int retval;
 424        struct priv *pr;
 425
 426        SET_MODULE_OWNER(dev);
 427        if (MCA_bus == 0) {
 428                return -ENODEV;
 429        }
 430        /* search through the slots for the 3c523. */
 431        slot = mca_find_adapter(ELMC_MCA_ID, 0);
 432        while (slot != -1) {
 433                status = mca_read_stored_pos(slot, 2);
 434
 435                dev->irq=irq_table[(status & ELMC_STATUS_IRQ_SELECT) >> 6];
 436                dev->base_addr=csr_table[(status & ELMC_STATUS_CSR_SELECT) >> 1];
 437                
 438                /*
 439                   If we're trying to match a specified irq or IO address,
 440                   we'll reject a match unless it's what we're looking for.
 441                   Also reject it if the card is already in use.
 442                 */
 443
 444                if ((irq && irq != dev->irq) || 
 445                    (base_addr && base_addr != dev->base_addr)) {
 446                        slot = mca_find_adapter(ELMC_MCA_ID, slot + 1);
 447                        continue;
 448                }
 449                if (!request_region(dev->base_addr, ELMC_IO_EXTENT, dev->name)) {
 450                        slot = mca_find_adapter(ELMC_MCA_ID, slot + 1);
 451                        continue;
 452                }
 453
 454                /* found what we're looking for... */
 455                break;
 456        }
 457
 458        /* we didn't find any 3c523 in the slots we checked for */
 459        if (slot == MCA_NOTFOUND) {
 460                retval = ((base_addr || irq) ? -ENXIO : -ENODEV);
 461                goto err_out;
 462        }
 463        mca_set_adapter_name(slot, "3Com 3c523 Etherlink/MC");
 464        mca_set_adapter_procfn(slot, (MCA_ProcFn) elmc_getinfo, dev);
 465
 466        /* if we get this far, adapter has been found - carry on */
 467        printk(KERN_INFO "%s: 3c523 adapter found in slot %d\n", dev->name, slot + 1);
 468
 469        /* Now we extract configuration info from the card.
 470           The 3c523 provides information in two of the POS registers, but
 471           the second one is only needed if we want to tell the card what IRQ
 472           to use.  I suspect that whoever sets the thing up initially would
 473           prefer we don't screw with those things.
 474
 475           Note that we read the status info when we found the card...
 476
 477           See 3c523.h for more details.
 478         */
 479
 480        /* revision is stored in the first 4 bits of the revision register */
 481        revision = inb(dev->base_addr + ELMC_REVISION) & 0xf;
 482
 483        /* according to docs, we read the interrupt and write it back to
 484           the IRQ select register, since the POST might not configure the IRQ
 485           properly. */
 486        switch (dev->irq) {
 487        case 3:
 488                mca_write_pos(slot, 3, 0x04);
 489                break;
 490        case 7:
 491                mca_write_pos(slot, 3, 0x02);
 492                break;
 493        case 9:
 494                mca_write_pos(slot, 3, 0x08);
 495                break;
 496        case 12:
 497                mca_write_pos(slot, 3, 0x01);
 498                break;
 499        }
 500
 501        pr = dev->priv = kmalloc(sizeof(struct priv), GFP_KERNEL);
 502        if (dev->priv == NULL) {
 503                retval = -ENOMEM;
 504                goto err_out;
 505        }
 506        memset(pr, 0, sizeof(struct priv));
 507
 508        pr->slot = slot;
 509
 510        printk(KERN_INFO "%s: 3Com 3c523 Rev 0x%x at %#lx\n", dev->name, (int) revision,
 511               dev->base_addr);
 512
 513        /* Determine if we're using the on-board transceiver (i.e. coax) or
 514           an external one.  The information is pretty much useless, but I
 515           guess it's worth brownie points. */
 516        dev->if_port = (status & ELMC_STATUS_DISABLE_THIN);
 517
 518        /* The 3c523 has a 24K chunk of memory.  The first 16K is the
 519           shared memory, while the last 8K is for the EtherStart BIOS ROM.
 520           Which we don't care much about here.  We'll just tell Linux that
 521           we're using 16K.  MCA won't permit address space conflicts caused
 522           by not mapping the other 8K. */
 523        dev->mem_start = shm_table[(status & ELMC_STATUS_MEMORY_SELECT) >> 3];
 524
 525        /* We're using MCA, so it's a given that the information about memory
 526           size is correct.  The Crynwr drivers do something like this. */
 527
 528        elmc_id_reset586();     /* seems like a good idea before checking it... */
 529
 530        size = 0x4000;          /* check for 16K mem */
 531        if (!check586(dev, dev->mem_start, size)) {
 532                printk(KERN_ERR "%s: memprobe, Can't find memory at 0x%lx!\n", dev->name,
 533                       dev->mem_start);
 534                kfree(dev->priv);
 535                dev->priv = NULL;
 536                retval = -ENODEV;
 537                goto err_out;
 538        }
 539        dev->mem_end = dev->mem_start + size;   /* set mem_end showed by 'ifconfig' */
 540
 541        pr->memtop = bus_to_virt(dev->mem_start) + size;
 542        pr->base = (unsigned long) bus_to_virt(dev->mem_start) + size - 0x01000000;
 543        alloc586(dev);
 544
 545        elmc_id_reset586();     /* make sure it doesn't generate spurious ints */
 546
 547        /* set number of receive-buffs according to memsize */
 548        pr->num_recv_buffs = NUM_RECV_BUFFS_16;
 549
 550        /* dump all the assorted information */
 551        printk(KERN_INFO "%s: IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev->name,
 552               dev->irq, dev->if_port ? "ex" : "in", 
 553               dev->mem_start, dev->mem_end - 1);
 554
 555        /* The hardware address for the 3c523 is stored in the first six
 556           bytes of the IO address. */
 557        printk(KERN_INFO "%s: hardware address ", dev->name);
 558        for (i = 0; i < 6; i++) {
 559                dev->dev_addr[i] = inb(dev->base_addr + i);
 560                printk(" %02x", dev->dev_addr[i]);
 561        }
 562        printk("\n");
 563
 564        dev->open = &elmc_open;
 565        dev->stop = &elmc_close;
 566        dev->get_stats = &elmc_get_stats;
 567        dev->hard_start_xmit = &elmc_send_packet;
 568        dev->tx_timeout = &elmc_timeout;
 569        dev->watchdog_timeo = HZ;
 570#ifdef ELMC_MULTICAST
 571        dev->set_multicast_list = &set_multicast_list;
 572#else
 573        dev->set_multicast_list = NULL;
 574#endif
 575        dev->do_ioctl = netdev_ioctl;
 576        
 577        ether_setup(dev);
 578
 579        /* note that we haven't actually requested the IRQ from the kernel.
 580           That gets done in elmc_open().  I'm not sure that's such a good idea,
 581           but it works, so I'll go with it. */
 582
 583#ifndef ELMC_MULTICAST
 584        dev->flags&=~IFF_MULTICAST;     /* Multicast doesn't work */
 585#endif
 586
 587        return 0;
 588err_out:
 589        release_region(dev->base_addr, ELMC_IO_EXTENT);
 590        return retval;
 591}
 592
 593/**********************************************
 594 * init the chip (elmc-interrupt should be disabled?!)
 595 * needs a correct 'allocated' memory
 596 */
 597
 598static int init586(struct net_device *dev)
 599{
 600        void *ptr;
 601        unsigned long s;
 602        int i, result = 0;
 603        struct priv *p = (struct priv *) dev->priv;
 604        volatile struct configure_cmd_struct *cfg_cmd;
 605        volatile struct iasetup_cmd_struct *ias_cmd;
 606        volatile struct tdr_cmd_struct *tdr_cmd;
 607        volatile struct mcsetup_cmd_struct *mc_cmd;
 608        struct dev_mc_list *dmi = dev->mc_list;
 609        int num_addrs = dev->mc_count;
 610
 611        ptr = (void *) ((char *) p->scb + sizeof(struct scb_struct));
 612
 613        cfg_cmd = (struct configure_cmd_struct *) ptr;  /* configure-command */
 614        cfg_cmd->cmd_status = 0;
 615        cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST;
 616        cfg_cmd->cmd_link = 0xffff;
 617
 618        cfg_cmd->byte_cnt = 0x0a;       /* number of cfg bytes */
 619        cfg_cmd->fifo = 0x08;   /* fifo-limit (8=tx:32/rx:64) */
 620        cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */
 621        cfg_cmd->adr_len = 0x2e;        /* addr_len |!src_insert |pre-len |loopback */
 622        cfg_cmd->priority = 0x00;
 623        cfg_cmd->ifs = 0x60;
 624        cfg_cmd->time_low = 0x00;
 625        cfg_cmd->time_high = 0xf2;
 626        cfg_cmd->promisc = 0;
 627        if (dev->flags & (IFF_ALLMULTI | IFF_PROMISC)) {
 628                cfg_cmd->promisc = 1;
 629                dev->flags |= IFF_PROMISC;
 630        }
 631        cfg_cmd->carr_coll = 0x00;
 632
 633        p->scb->cbl_offset = make16(cfg_cmd);
 634
 635        p->scb->cmd = CUC_START;        /* cmd.-unit start */
 636        elmc_id_attn586();
 637
 638        s = jiffies;            /* warning: only active with interrupts on !! */
 639        while (!(cfg_cmd->cmd_status & STAT_COMPL)) {
 640                if (jiffies - s > 30*HZ/100)
 641                        break;
 642        }
 643
 644        if ((cfg_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_COMPL | STAT_OK)) {
 645                printk(KERN_WARNING "%s (elmc): configure command failed: %x\n", dev->name, cfg_cmd->cmd_status);
 646                return 1;
 647        }
 648        /*
 649         * individual address setup
 650         */
 651        ias_cmd = (struct iasetup_cmd_struct *) ptr;
 652
 653        ias_cmd->cmd_status = 0;
 654        ias_cmd->cmd_cmd = CMD_IASETUP | CMD_LAST;
 655        ias_cmd->cmd_link = 0xffff;
 656
 657        memcpy((char *) &ias_cmd->iaddr, (char *) dev->dev_addr, ETH_ALEN);
 658
 659        p->scb->cbl_offset = make16(ias_cmd);
 660
 661        p->scb->cmd = CUC_START;        /* cmd.-unit start */
 662        elmc_id_attn586();
 663
 664        s = jiffies;
 665        while (!(ias_cmd->cmd_status & STAT_COMPL)) {
 666                if (jiffies - s > 30*HZ/100)
 667                        break;
 668        }
 669
 670        if ((ias_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_OK | STAT_COMPL)) {
 671                printk(KERN_WARNING "%s (elmc): individual address setup command failed: %04x\n", dev->name, ias_cmd->cmd_status);
 672                return 1;
 673        }
 674        /*
 675         * TDR, wire check .. e.g. no resistor e.t.c
 676         */
 677        tdr_cmd = (struct tdr_cmd_struct *) ptr;
 678
 679        tdr_cmd->cmd_status = 0;
 680        tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST;
 681        tdr_cmd->cmd_link = 0xffff;
 682        tdr_cmd->status = 0;
 683
 684        p->scb->cbl_offset = make16(tdr_cmd);
 685
 686        p->scb->cmd = CUC_START;        /* cmd.-unit start */
 687        elmc_attn586();
 688
 689        s = jiffies;
 690        while (!(tdr_cmd->cmd_status & STAT_COMPL)) {
 691                if (jiffies - s > 30*HZ/100) {
 692                        printk(KERN_WARNING "%s: %d Problems while running the TDR.\n", dev->name, __LINE__);
 693                        result = 1;
 694                        break;
 695                }
 696        }
 697
 698        if (!result) {
 699                DELAY(2);       /* wait for result */
 700                result = tdr_cmd->status;
 701
 702                p->scb->cmd = p->scb->status & STAT_MASK;
 703                elmc_id_attn586();      /* ack the interrupts */
 704
 705                if (result & TDR_LNK_OK) {
 706                        /* empty */
 707                } else if (result & TDR_XCVR_PRB) {
 708                        printk(KERN_WARNING "%s: TDR: Transceiver problem!\n", dev->name);
 709                } else if (result & TDR_ET_OPN) {
 710                        printk(KERN_WARNING "%s: TDR: No correct termination %d clocks away.\n", dev->name, result & TDR_TIMEMASK);
 711                } else if (result & TDR_ET_SRT) {
 712                        if (result & TDR_TIMEMASK)      /* time == 0 -> strange :-) */
 713                                printk(KERN_WARNING "%s: TDR: Detected a short circuit %d clocks away.\n", dev->name, result & TDR_TIMEMASK);
 714                } else {
 715                        printk(KERN_WARNING "%s: TDR: Unknown status %04x\n", dev->name, result);
 716                }
 717        }
 718        /*
 719         * ack interrupts
 720         */
 721        p->scb->cmd = p->scb->status & STAT_MASK;
 722        elmc_id_attn586();
 723
 724        /*
 725         * alloc nop/xmit-cmds
 726         */
 727#if (NUM_XMIT_BUFFS == 1)
 728        for (i = 0; i < 2; i++) {
 729                p->nop_cmds[i] = (struct nop_cmd_struct *) ptr;
 730                p->nop_cmds[i]->cmd_cmd = CMD_NOP;
 731                p->nop_cmds[i]->cmd_status = 0;
 732                p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
 733                ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
 734        }
 735        p->xmit_cmds[0] = (struct transmit_cmd_struct *) ptr;   /* transmit cmd/buff 0 */
 736        ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
 737#else
 738        for (i = 0; i < NUM_XMIT_BUFFS; i++) {
 739                p->nop_cmds[i] = (struct nop_cmd_struct *) ptr;
 740                p->nop_cmds[i]->cmd_cmd = CMD_NOP;
 741                p->nop_cmds[i]->cmd_status = 0;
 742                p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
 743                ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
 744                p->xmit_cmds[i] = (struct transmit_cmd_struct *) ptr;   /*transmit cmd/buff 0 */
 745                ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
 746        }
 747#endif
 748
 749        ptr = alloc_rfa(dev, (void *) ptr);     /* init receive-frame-area */
 750
 751        /*
 752         * Multicast setup
 753         */
 754
 755        if (dev->mc_count) {
 756                /* I don't understand this: do we really need memory after the init? */
 757                int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
 758                if (len <= 0) {
 759                        printk(KERN_ERR "%s: Ooooops, no memory for MC-Setup!\n", dev->name);
 760                } else {
 761                        if (len < num_addrs) {
 762                                num_addrs = len;
 763                                printk(KERN_WARNING "%s: Sorry, can only apply %d MC-Address(es).\n",
 764                                       dev->name, num_addrs);
 765                        }
 766                        mc_cmd = (struct mcsetup_cmd_struct *) ptr;
 767                        mc_cmd->cmd_status = 0;
 768                        mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST;
 769                        mc_cmd->cmd_link = 0xffff;
 770                        mc_cmd->mc_cnt = num_addrs * 6;
 771                        for (i = 0; i < num_addrs; i++) {
 772                                memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr, 6);
 773                                dmi = dmi->next;
 774                        }
 775                        p->scb->cbl_offset = make16(mc_cmd);
 776                        p->scb->cmd = CUC_START;
 777                        elmc_id_attn586();
 778                        s = jiffies;
 779                        while (!(mc_cmd->cmd_status & STAT_COMPL)) {
 780                                if (jiffies - s > 30*HZ/100)
 781                                        break;
 782                        }
 783                        if (!(mc_cmd->cmd_status & STAT_COMPL)) {
 784                                printk(KERN_WARNING "%s: Can't apply multicast-address-list.\n", dev->name);
 785                        }
 786                }
 787        }
 788        /*
 789         * alloc xmit-buffs / init xmit_cmds
 790         */
 791        for (i = 0; i < NUM_XMIT_BUFFS; i++) {
 792                p->xmit_cbuffs[i] = (char *) ptr;       /* char-buffs */
 793                ptr = (char *) ptr + XMIT_BUFF_SIZE;
 794                p->xmit_buffs[i] = (struct tbd_struct *) ptr;   /* TBD */
 795                ptr = (char *) ptr + sizeof(struct tbd_struct);
 796                if ((void *) ptr > (void *) p->iscp) {
 797                        printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n", dev->name);
 798                        return 1;
 799                }
 800                memset((char *) (p->xmit_cmds[i]), 0, sizeof(struct transmit_cmd_struct));
 801                memset((char *) (p->xmit_buffs[i]), 0, sizeof(struct tbd_struct));
 802                p->xmit_cmds[i]->cmd_status = STAT_COMPL;
 803                p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT;
 804                p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i]));
 805                p->xmit_buffs[i]->next = 0xffff;
 806                p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i]));
 807        }
 808
 809        p->xmit_count = 0;
 810        p->xmit_last = 0;
 811#ifndef NO_NOPCOMMANDS
 812        p->nop_point = 0;
 813#endif
 814
 815        /*
 816         * 'start transmitter' (nop-loop)
 817         */
 818#ifndef NO_NOPCOMMANDS
 819        p->scb->cbl_offset = make16(p->nop_cmds[0]);
 820        p->scb->cmd = CUC_START;
 821        elmc_id_attn586();
 822        WAIT_4_SCB_CMD();
 823#else
 824        p->xmit_cmds[0]->cmd_link = 0xffff;
 825        p->xmit_cmds[0]->cmd_cmd = CMD_XMIT | CMD_LAST | CMD_INT;
 826#endif
 827
 828        return 0;
 829}
 830
 831/******************************************************
 832 * This is a helper routine for elmc_rnr_int() and init586().
 833 * It sets up the Receive Frame Area (RFA).
 834 */
 835
 836static void *alloc_rfa(struct net_device *dev, void *ptr)
 837{
 838        volatile struct rfd_struct *rfd = (struct rfd_struct *) ptr;
 839        volatile struct rbd_struct *rbd;
 840        int i;
 841        struct priv *p = (struct priv *) dev->priv;
 842
 843        memset((char *) rfd, 0, sizeof(struct rfd_struct) * p->num_recv_buffs);
 844        p->rfd_first = rfd;
 845
 846        for (i = 0; i < p->num_recv_buffs; i++) {
 847                rfd[i].next = make16(rfd + (i + 1) % p->num_recv_buffs);
 848        }
 849        rfd[p->num_recv_buffs - 1].last = RFD_SUSP;     /* RU suspend */
 850
 851        ptr = (void *) (rfd + p->num_recv_buffs);
 852
 853        rbd = (struct rbd_struct *) ptr;
 854        ptr = (void *) (rbd + p->num_recv_buffs);
 855
 856        /* clr descriptors */
 857        memset((char *) rbd, 0, sizeof(struct rbd_struct) * p->num_recv_buffs);
 858
 859        for (i = 0; i < p->num_recv_buffs; i++) {
 860                rbd[i].next = make16((rbd + (i + 1) % p->num_recv_buffs));
 861                rbd[i].size = RECV_BUFF_SIZE;
 862                rbd[i].buffer = make24(ptr);
 863                ptr = (char *) ptr + RECV_BUFF_SIZE;
 864        }
 865
 866        p->rfd_top = p->rfd_first;
 867        p->rfd_last = p->rfd_first + p->num_recv_buffs - 1;
 868
 869        p->scb->rfa_offset = make16(p->rfd_first);
 870        p->rfd_first->rbd_offset = make16(rbd);
 871
 872        return ptr;
 873}
 874
 875
 876/**************************************************
 877 * Interrupt Handler ...
 878 */
 879
 880static void elmc_interrupt(int irq, void *dev_id, struct pt_regs *reg_ptr)
 881{
 882        struct net_device *dev = (struct net_device *) dev_id;
 883        unsigned short stat;
 884        struct priv *p;
 885
 886        if (dev == NULL) {
 887                printk(KERN_ERR "elmc-interrupt: irq %d for unknown device.\n", (int) -(((struct pt_regs *) reg_ptr)->orig_eax + 2));
 888                return;
 889        } else if (!netif_running(dev)) {
 890                /* The 3c523 has this habit of generating interrupts during the
 891                   reset.  I'm not sure if the ni52 has this same problem, but it's
 892                   really annoying if we haven't finished initializing it.  I was
 893                   hoping all the elmc_id_* commands would disable this, but I
 894                   might have missed a few. */
 895
 896                elmc_id_attn586();      /* ack inter. and disable any more */
 897                return;
 898        } else if (!(ELMC_CTRL_INT & inb(dev->base_addr + ELMC_CTRL))) {
 899                /* wasn't this device */
 900                return;
 901        }
 902        /* reading ELMC_CTRL also clears the INT bit. */
 903
 904        p = (struct priv *) dev->priv;
 905
 906        while ((stat = p->scb->status & STAT_MASK)) 
 907        {
 908                p->scb->cmd = stat;
 909                elmc_attn586(); /* ack inter. */
 910
 911                if (stat & STAT_CX) {
 912                        /* command with I-bit set complete */
 913                        elmc_xmt_int(dev);
 914                }
 915                if (stat & STAT_FR) {
 916                        /* received a frame */
 917                        elmc_rcv_int(dev);
 918                }
 919#ifndef NO_NOPCOMMANDS
 920                if (stat & STAT_CNA) {
 921                        /* CU went 'not ready' */
 922                        if (netif_running(dev)) {
 923                                printk(KERN_WARNING "%s: oops! CU has left active state. stat: %04x/%04x.\n", dev->name, (int) stat, (int) p->scb->status);
 924                        }
 925                }
 926#endif
 927
 928                if (stat & STAT_RNR) {
 929                        /* RU went 'not ready' */
 930
 931                        if (p->scb->status & RU_SUSPEND) {
 932                                /* special case: RU_SUSPEND */
 933
 934                                WAIT_4_SCB_CMD();
 935                                p->scb->cmd = RUC_RESUME;
 936                                elmc_attn586();
 937                        } else {
 938                                printk(KERN_WARNING "%s: Receiver-Unit went 'NOT READY': %04x/%04x.\n", dev->name, (int) stat, (int) p->scb->status);
 939                                elmc_rnr_int(dev);
 940                        }
 941                }
 942                WAIT_4_SCB_CMD();       /* wait for ack. (elmc_xmt_int can be faster than ack!!) */
 943                if (p->scb->cmd) {      /* timed out? */
 944                        break;
 945                }
 946        }
 947}
 948
 949/*******************************************************
 950 * receive-interrupt
 951 */
 952
 953static void elmc_rcv_int(struct net_device *dev)
 954{
 955        int status;
 956        unsigned short totlen;
 957        struct sk_buff *skb;
 958        struct rbd_struct *rbd;
 959        struct priv *p = (struct priv *) dev->priv;
 960
 961        for (; (status = p->rfd_top->status) & STAT_COMPL;) {
 962                rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
 963
 964                if (status & STAT_OK) {         /* frame received without error? */
 965                        if ((totlen = rbd->status) & RBD_LAST) {        /* the first and the last buffer? */
 966                                totlen &= RBD_MASK;     /* length of this frame */
 967                                rbd->status = 0;
 968                                skb = (struct sk_buff *) dev_alloc_skb(totlen + 2);
 969                                if (skb != NULL) {
 970                                        skb->dev = dev;
 971                                        skb_reserve(skb, 2);    /* 16 byte alignment */
 972                                        skb_put(skb,totlen);
 973                                        eth_copy_and_sum(skb, (char *) p->base+(unsigned long) rbd->buffer,totlen,0);
 974                                        skb->protocol = eth_type_trans(skb, dev);
 975                                        netif_rx(skb);
 976                                        dev->last_rx = jiffies;
 977                                        p->stats.rx_packets++;
 978                                        p->stats.rx_bytes += totlen;
 979                                } else {
 980                                        p->stats.rx_dropped++;
 981                                }
 982                        } else {
 983                                printk(KERN_WARNING "%s: received oversized frame.\n", dev->name);
 984                                p->stats.rx_dropped++;
 985                        }
 986                } else {        /* frame !(ok), only with 'save-bad-frames' */
 987                        printk(KERN_WARNING "%s: oops! rfd-error-status: %04x\n", dev->name, status);
 988                        p->stats.rx_errors++;
 989                }
 990                p->rfd_top->status = 0;
 991                p->rfd_top->last = RFD_SUSP;
 992                p->rfd_last->last = 0;  /* delete RU_SUSP  */
 993                p->rfd_last = p->rfd_top;
 994                p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next);    /* step to next RFD */
 995        }
 996}
 997
 998/**********************************************************
 999 * handle 'Receiver went not ready'.
1000 */
1001
1002static void elmc_rnr_int(struct net_device *dev)
1003{
1004        struct priv *p = (struct priv *) dev->priv;
1005
1006        p->stats.rx_errors++;
1007
1008        WAIT_4_SCB_CMD();       /* wait for the last cmd */
1009        p->scb->cmd = RUC_ABORT;        /* usually the RU is in the 'no resource'-state .. abort it now. */
1010        elmc_attn586();
1011        WAIT_4_SCB_CMD();       /* wait for accept cmd. */
1012
1013        alloc_rfa(dev, (char *) p->rfd_first);
1014        startrecv586(dev);      /* restart RU */
1015
1016        printk(KERN_WARNING "%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->status);
1017
1018}
1019
1020/**********************************************************
1021 * handle xmit - interrupt
1022 */
1023
1024static void elmc_xmt_int(struct net_device *dev)
1025{
1026        int status;
1027        struct priv *p = (struct priv *) dev->priv;
1028
1029        status = p->xmit_cmds[p->xmit_last]->cmd_status;
1030        if (!(status & STAT_COMPL)) {
1031                printk(KERN_WARNING "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
1032        }
1033        if (status & STAT_OK) {
1034                p->stats.tx_packets++;
1035                p->stats.collisions += (status & TCMD_MAXCOLLMASK);
1036        } else {
1037                p->stats.tx_errors++;
1038                if (status & TCMD_LATECOLL) {
1039                        printk(KERN_WARNING "%s: late collision detected.\n", dev->name);
1040                        p->stats.collisions++;
1041                } else if (status & TCMD_NOCARRIER) {
1042                        p->stats.tx_carrier_errors++;
1043                        printk(KERN_WARNING "%s: no carrier detected.\n", dev->name);
1044                } else if (status & TCMD_LOSTCTS) {
1045                        printk(KERN_WARNING "%s: loss of CTS detected.\n", dev->name);
1046                } else if (status & TCMD_UNDERRUN) {
1047                        p->stats.tx_fifo_errors++;
1048                        printk(KERN_WARNING "%s: DMA underrun detected.\n", dev->name);
1049                } else if (status & TCMD_MAXCOLL) {
1050                        printk(KERN_WARNING "%s: Max. collisions exceeded.\n", dev->name);
1051                        p->stats.collisions += 16;
1052                }
1053        }
1054
1055#if (NUM_XMIT_BUFFS != 1)
1056        if ((++p->xmit_last) == NUM_XMIT_BUFFS) {
1057                p->xmit_last = 0;
1058        }
1059#endif
1060
1061        netif_wake_queue(dev);
1062}
1063
1064/***********************************************************
1065 * (re)start the receiver
1066 */
1067
1068static void startrecv586(struct net_device *dev)
1069{
1070        struct priv *p = (struct priv *) dev->priv;
1071
1072        p->scb->rfa_offset = make16(p->rfd_first);
1073        p->scb->cmd = RUC_START;
1074        elmc_attn586();         /* start cmd. */
1075        WAIT_4_SCB_CMD();       /* wait for accept cmd. (no timeout!!) */
1076}
1077
1078/******************************************************
1079 * timeout
1080 */
1081 
1082static void elmc_timeout(struct net_device *dev)
1083{
1084        struct priv *p = (struct priv *) dev->priv;
1085        /* COMMAND-UNIT active? */
1086        if (p->scb->status & CU_ACTIVE) {
1087#ifdef DEBUG
1088                printk("%s: strange ... timeout with CU active?!?\n", dev->name);
1089                printk("%s: X0: %04x N0: %04x N1: %04x %d\n", dev->name, (int) p->xmit_cmds[0]->cmd_status, (int) p->nop_cmds[0]->cmd_status, (int) p->nop_cmds[1]->cmd_status, (int) p->nop_point);
1090#endif
1091                p->scb->cmd = CUC_ABORT;
1092                elmc_attn586();
1093                WAIT_4_SCB_CMD();
1094                p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
1095                p->scb->cmd = CUC_START;
1096                elmc_attn586();
1097                WAIT_4_SCB_CMD();
1098                netif_wake_queue(dev);
1099        } else {
1100#ifdef DEBUG
1101                printk("%s: xmitter timed out, try to restart! stat: %04x\n", dev->name, p->scb->status);
1102                printk("%s: command-stats: %04x %04x\n", dev->name, p->xmit_cmds[0]->cmd_status, p->xmit_cmds[1]->cmd_status);
1103#endif
1104                elmc_close(dev);
1105                elmc_open(dev);
1106        }
1107}
1108 
1109/******************************************************
1110 * send frame
1111 */
1112
1113static int elmc_send_packet(struct sk_buff *skb, struct net_device *dev)
1114{
1115        int len;
1116        int i;
1117#ifndef NO_NOPCOMMANDS
1118        int next_nop;
1119#endif
1120        struct priv *p = (struct priv *) dev->priv;
1121
1122        netif_stop_queue(dev);
1123
1124        memcpy((char *) p->xmit_cbuffs[p->xmit_count], (char *) (skb->data), skb->len);
1125        len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
1126
1127#if (NUM_XMIT_BUFFS == 1)
1128#ifdef NO_NOPCOMMANDS
1129        p->xmit_buffs[0]->size = TBD_LAST | len;
1130        for (i = 0; i < 16; i++) {
1131                p->scb->cbl_offset = make16(p->xmit_cmds[0]);
1132                p->scb->cmd = CUC_START;
1133                p->xmit_cmds[0]->cmd_status = 0;
1134                        elmc_attn586();
1135                dev->trans_start = jiffies;
1136                if (!i) {
1137                        dev_kfree_skb(skb);
1138                }
1139                WAIT_4_SCB_CMD();
1140                if ((p->scb->status & CU_ACTIVE)) {     /* test it, because CU sometimes doesn't start immediately */
1141                        break;
1142                }
1143                if (p->xmit_cmds[0]->cmd_status) {
1144                        break;
1145                }
1146                if (i == 15) {
1147                        printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name);
1148                }
1149        }
1150#else
1151        next_nop = (p->nop_point + 1) & 0x1;
1152        p->xmit_buffs[0]->size = TBD_LAST | len;
1153        
1154        p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1155            = make16((p->nop_cmds[next_nop]));
1156        p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
1157
1158        p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
1159        dev->trans_start = jiffies;
1160        p->nop_point = next_nop;
1161        dev_kfree_skb(skb);
1162#endif
1163#else
1164        p->xmit_buffs[p->xmit_count]->size = TBD_LAST | len;
1165        if ((next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS) {
1166                next_nop = 0;
1167        }
1168        p->xmit_cmds[p->xmit_count]->cmd_status = 0;
1169        p->xmit_cmds[p->xmit_count]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1170            = make16((p->nop_cmds[next_nop]));
1171        p->nop_cmds[next_nop]->cmd_status = 0;
1172                p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count]));
1173        dev->trans_start = jiffies;
1174        p->xmit_count = next_nop;
1175        if (p->xmit_count != p->xmit_last)
1176                netif_wake_queue(dev);
1177        dev_kfree_skb(skb);
1178#endif
1179        return 0;
1180}
1181
1182/*******************************************
1183 * Someone wanna have the statistics
1184 */
1185
1186static struct net_device_stats *elmc_get_stats(struct net_device *dev)
1187{
1188        struct priv *p = (struct priv *) dev->priv;
1189        unsigned short crc, aln, rsc, ovrn;
1190
1191        crc = p->scb->crc_errs; /* get error-statistic from the ni82586 */
1192        p->scb->crc_errs -= crc;
1193        aln = p->scb->aln_errs;
1194        p->scb->aln_errs -= aln;
1195        rsc = p->scb->rsc_errs;
1196        p->scb->rsc_errs -= rsc;
1197        ovrn = p->scb->ovrn_errs;
1198        p->scb->ovrn_errs -= ovrn;
1199
1200        p->stats.rx_crc_errors += crc;
1201        p->stats.rx_fifo_errors += ovrn;
1202        p->stats.rx_frame_errors += aln;
1203        p->stats.rx_dropped += rsc;
1204
1205        return &p->stats;
1206}
1207
1208/********************************************************
1209 * Set MC list ..
1210 */
1211
1212#ifdef ELMC_MULTICAST
1213static void set_multicast_list(struct net_device *dev)
1214{
1215        if (!dev->start) {
1216                /* without a running interface, promiscuous doesn't work */
1217                return;
1218        }
1219        dev->start = 0;
1220        alloc586(dev);
1221        init586(dev);
1222        startrecv586(dev);
1223        dev->start = 1;
1224}
1225#endif
1226
1227/**
1228 * netdev_ethtool_ioctl: Handle network interface SIOCETHTOOL ioctls
1229 * @dev: network interface on which out-of-band action is to be performed
1230 * @useraddr: userspace address to which data is to be read and returned
1231 *
1232 * Process the various commands of the SIOCETHTOOL interface.
1233 */
1234
1235static int netdev_ethtool_ioctl (struct net_device *dev, void *useraddr)
1236{
1237        u32 ethcmd;
1238
1239        /* dev_ioctl() in ../../net/core/dev.c has already checked
1240           capable(CAP_NET_ADMIN), so don't bother with that here.  */
1241
1242        if (get_user(ethcmd, (u32 *)useraddr))
1243                return -EFAULT;
1244
1245        switch (ethcmd) {
1246
1247        case ETHTOOL_GDRVINFO: {
1248                struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
1249                strcpy (info.driver, DRV_NAME);
1250                strcpy (info.version, DRV_VERSION);
1251                sprintf(info.bus_info, "MCA 0x%lx", dev->base_addr);
1252                if (copy_to_user (useraddr, &info, sizeof (info)))
1253                        return -EFAULT;
1254                return 0;
1255        }
1256
1257        default:
1258                break;
1259        }
1260
1261        return -EOPNOTSUPP;
1262}
1263
1264/**
1265 * netdev_ioctl: Handle network interface ioctls
1266 * @dev: network interface on which out-of-band action is to be performed
1267 * @rq: user request data
1268 * @cmd: command issued by user
1269 *
1270 * Process the various out-of-band ioctls passed to this driver.
1271 */
1272
1273static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
1274{
1275        int rc = 0;
1276
1277        switch (cmd) {
1278        case SIOCETHTOOL:
1279                rc = netdev_ethtool_ioctl(dev, (void *) rq->ifr_data);
1280                break;
1281
1282        default:
1283                rc = -EOPNOTSUPP;
1284                break;
1285        }
1286
1287        return rc;
1288}
1289 
1290/*************************************************************************/
1291
1292#ifdef MODULE
1293
1294/* Increase if needed ;) */
1295#define MAX_3C523_CARDS 4
1296
1297static struct net_device dev_elmc[MAX_3C523_CARDS];
1298static int irq[MAX_3C523_CARDS];
1299static int io[MAX_3C523_CARDS];
1300MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_3C523_CARDS) "i");
1301MODULE_PARM(io, "1-" __MODULE_STRING(MAX_3C523_CARDS) "i");
1302MODULE_PARM_DESC(io, "EtherLink/MC I/O base address(es)");
1303MODULE_PARM_DESC(irq, "EtherLink/MC IRQ number(s)");
1304
1305int init_module(void)
1306{
1307        int this_dev,found = 0;
1308
1309        /* Loop until we either can't find any more cards, or we have MAX_3C523_CARDS */        
1310        for(this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) 
1311                {
1312                struct net_device *dev = &dev_elmc[this_dev];
1313                dev->irq=irq[this_dev];
1314                dev->base_addr=io[this_dev];
1315                dev->init=elmc_probe;
1316                if(register_netdev(dev)!=0) {
1317                        if(io[this_dev]==0) break;
1318                        printk(KERN_WARNING "3c523.c: No 3c523 card found at io=%#x\n",io[this_dev]);
1319                } else found++;
1320        }
1321
1322        if(found==0) {
1323                if(io[0]==0) printk(KERN_NOTICE "3c523.c: No 3c523 cards found\n");
1324                return -ENXIO;
1325        } else return 0;
1326}
1327
1328void cleanup_module(void)
1329{
1330        int this_dev;
1331        for(this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) {
1332
1333                struct net_device *dev = &dev_elmc[this_dev];
1334                if(dev->priv) {
1335                        /* shutdown interrupts on the card */
1336                        elmc_id_reset586();
1337                        if (dev->irq != 0) {
1338                                /* this should be done by close, but if we failed to
1339                                   initialize properly something may have gotten hosed. */
1340                                free_irq(dev->irq, dev);
1341                                dev->irq = 0;
1342                        }
1343                        if (dev->base_addr != 0) {
1344                                release_region(dev->base_addr, ELMC_IO_EXTENT);
1345                                dev->base_addr = 0;
1346                        }
1347                        irq[this_dev] = 0;
1348                        io[this_dev] = 0;
1349                        unregister_netdev(dev);
1350
1351                        mca_set_adapter_procfn(((struct priv *) (dev->priv))->slot,
1352                               NULL, NULL);
1353
1354                        kfree(dev->priv);
1355                        dev->priv = NULL;
1356                }
1357        }
1358}
1359
1360#endif                          /* MODULE */
1361
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.