root/drivers/net/3c501.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. el1_probe
  2. el1_probe1
  3. el_open
  4. el_start_xmit
  5. el_interrupt
  6. el_receive
  7. el_reset
  8. el1_close
  9. el1_get_stats
  10. set_multicast_list
  11. init_module
  12. cleanup_module

   1 /* 3c501.c: A 3Com 3c501 ethernet driver for linux. */
   2 /*
   3     Written 1992,1993,1994  Donald Becker
   4 
   5     Copyright 1993 United States Government as represented by the
   6     Director, National Security Agency.  This software may be used and
   7     distributed according to the terms of the GNU Public License,
   8     incorporated herein by reference.
   9 
  10     This is a device driver for the 3Com Etherlink 3c501.
  11     Do not purchase this card, even as a joke.  It's performance is horrible,
  12     and it breaks in many ways.  
  13 
  14     The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
  15     Center of Excellence in Space Data and Information Sciences
  16        Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
  17        
  18     Fixed (again!) the missing interrupt locking on TX/RX shifting.
  19                 Alan Cox <Alan.Cox@linux.org>
  20                 
  21     Removed calls to init_etherdev since they are no longer needed, and
  22     cleaned up modularization just a bit. The driver still allows only
  23     the default address for cards when loaded as a module, but that's
  24     really less braindead than anyone using a 3c501 board. :)
  25                     19950208 (invid@msen.com)
  26 
  27     Added traps for interrupts hitting the window as we clear and TX load
  28     the board. Now getting 150K/second FTP with a 3c501 card. Still playing
  29     with a TX-TX optimisation to see if we can touch 180-200K/second as seems
  30     theoretically maximum.
  31                 19950402 Alan Cox <Alan.Cox@linux.org>
  32                 
  33     Some notes on this thing if you have to hack it.  [Alan]
  34     
  35     1]  Some documentation is available from 3Com. Due to the boards age
  36         standard responses when you ask for this will range from 'be serious'
  37         to 'give it to a museum'. The documentation is incomplete and mostly
  38         of historical interest anyway.
  39         
  40     2]  The basic system is a single buffer which can be used to receive or
  41         transmit a packet. A third command mode exists when you are setting
  42         things up.
  43         
  44     3]  If it's transmitting it's not receiving and vice versa. In fact the 
  45         time to get the board back into useful state after an operation is
  46         quite large.
  47         
  48     4]  The driver works by keeping the board in receive mode waiting for a
  49         packet to arrive. When one arrives it is copied out of the buffer
  50         and delivered to the kernel. The card is reloaded and off we go.
  51         
  52     5]  When transmitting dev->tbusy is set and the card is reset (from
  53         receive mode) [possibly losing a packet just received] to command
  54         mode. A packet is loaded and transmit mode triggered. The interrupt
  55         handler runs different code for transmit interrupts and can handle
  56         returning to receive mode or retransmissions (yes you have to help
  57         out with those too).
  58         
  59     Problems:
  60         There are a wide variety of undocumented error returns from the card
  61     and you basically have to kick the board and pray if they turn up. Most 
  62     only occur under extreme load or if you do something the board doesn't
  63     like (eg touching a register at the wrong time).
  64     
  65         The driver is less efficient than it could be. It switches through
  66     receive mode even if more transmits are queued. If this worries you buy
  67     a real ethernet card.
  68     
  69         The combination of slow receive restart and no real multicast
  70     filter makes the board unusable with a kernel compiled for IP
  71     multicasting in a real multicast environment. Thats down to the board, 
  72     but even with no multicast programs running a multicast IP kernel is
  73     in group 224.0.0.1 and you will therefore be listening to all multicasts.
  74     One nv conference running over that ethernet and you can give up.
  75     
  76 */
  77 
  78 static const char *version =
  79     "3c501.c: 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov).\n";
  80 
  81 /*
  82   Braindamage remaining:
  83   The 3c501 board.
  84   */
  85 
  86 #include <linux/module.h>
  87 
  88 #include <linux/kernel.h>
  89 #include <linux/sched.h>
  90 #include <linux/ptrace.h>
  91 #include <linux/fcntl.h>
  92 #include <linux/ioport.h>
  93 #include <linux/interrupt.h>
  94 #include <linux/malloc.h>
  95 #include <linux/string.h>
  96 #include <linux/ioport.h>
  97 #include <linux/errno.h>
  98 #include <linux/config.h>       /* for CONFIG_IP_MULTICAST */
  99 
 100 #include <asm/bitops.h>
 101 #include <asm/io.h>
 102 
 103 #include <linux/netdevice.h>
 104 #include <linux/etherdevice.h>
 105 #include <linux/skbuff.h>
 106 
 107 /* A zero-terminated list of I/O addresses to be probed.
 108    The 3c501 can be at many locations, but here are the popular ones. */
 109 static unsigned int netcard_portlist[] =
 110    { 0x280, 0x300, 0};
 111 
 112 
 113 /* Index to functions. */
 114 int el1_probe(struct device *dev);
 115 static int  el1_probe1(struct device *dev, int ioaddr);
 116 static int  el_open(struct device *dev);
 117 static int  el_start_xmit(struct sk_buff *skb, struct device *dev);
 118 static void el_interrupt(int irq, struct pt_regs *regs);
 119 static void el_receive(struct device *dev);
 120 static void el_reset(struct device *dev);
 121 static int  el1_close(struct device *dev);
 122 static struct enet_statistics *el1_get_stats(struct device *dev);
 123 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
 124 
 125 #define EL1_IO_EXTENT   16
 126 
 127 #ifndef EL_DEBUG
 128 #define EL_DEBUG  2     /* use 0 for production, 1 for devel., >2 for debug */
 129 #endif                  /* Anything above 5 is wordy death! */
 130 static int el_debug = EL_DEBUG;
 131  
 132 /* Board-specific info in dev->priv. */
 133 struct net_local {
 134     struct enet_statistics stats;
 135     int tx_pkt_start;           /* The length of the current Tx packet. */
 136     int collisions;             /* Tx collisions this packet */
 137     int loading;                /* Spot buffer load collisions */
 138 };
 139 
 140 
 141 #define RX_STATUS (ioaddr + 0x06)
 142 #define RX_CMD    RX_STATUS
 143 #define TX_STATUS (ioaddr + 0x07)
 144 #define TX_CMD    TX_STATUS
 145 #define GP_LOW    (ioaddr + 0x08)
 146 #define GP_HIGH   (ioaddr + 0x09)
 147 #define RX_BUF_CLR (ioaddr + 0x0A)
 148 #define RX_LOW    (ioaddr + 0x0A)
 149 #define RX_HIGH   (ioaddr + 0x0B)
 150 #define SAPROM    (ioaddr + 0x0C)
 151 #define AX_STATUS (ioaddr + 0x0E)
 152 #define AX_CMD    AX_STATUS
 153 #define DATAPORT  (ioaddr + 0x0F)
 154 #define TX_RDY 0x08             /* In TX_STATUS */
 155 
 156 #define EL1_DATAPTR     0x08
 157 #define EL1_RXPTR       0x0A
 158 #define EL1_SAPROM      0x0C
 159 #define EL1_DATAPORT    0x0f
 160 
 161 /* Writes to the ax command register. */
 162 #define AX_OFF  0x00                    /* Irq off, buffer access on */
 163 #define AX_SYS  0x40                    /* Load the buffer */
 164 #define AX_XMIT 0x44                    /* Transmit a packet */
 165 #define AX_RX   0x48                    /* Receive a packet */
 166 #define AX_LOOP 0x0C                    /* Loopback mode */
 167 #define AX_RESET 0x80
 168 
 169 /* Normal receive mode written to RX_STATUS.  We must intr on short packets
 170    to avoid bogus rx lockups. */
 171 #define RX_NORM 0xA8            /* 0x68 == all addrs, 0xA8 only to me. */
 172 #define RX_PROM 0x68            /* Senior Prom, uhmm promiscuous mode. */
 173 #define RX_MULT 0xE8            /* Accept multicast packets. */
 174 #define TX_NORM 0x0A    /* Interrupt on everything that might hang the chip */
 175 
 176 /* TX_STATUS register. */
 177 #define TX_COLLISION 0x02
 178 #define TX_16COLLISIONS 0x04
 179 #define TX_READY 0x08
 180 
 181 #define RX_RUNT 0x08
 182 #define RX_MISSED 0x01          /* Missed a packet due to 3c501 braindamage. */
 183 #define RX_GOOD 0x30            /* Good packet 0x20, or simple overflow 0x10. */
 184 
 185 
 186 /* The boilerplate probe code. */
 187 #ifdef HAVE_DEVLIST
 188 struct netdev_entry el1_drv =
 189 {"3c501", el1_probe1, EL1_IO_EXTENT, netcard_portlist};
 190 #else
 191 int
 192 el1_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 193 {
 194     int i;
 195     int base_addr = dev ? dev->base_addr : 0;
 196 
 197     if (base_addr > 0x1ff)      /* Check a single specified location. */
 198         return el1_probe1(dev, base_addr);
 199     else if (base_addr != 0)    /* Don't probe at all. */
 200         return ENXIO;
 201 
 202     for (i = 0; netcard_portlist[i]; i++) {
 203         int ioaddr = netcard_portlist[i];
 204         if (check_region(ioaddr, EL1_IO_EXTENT))
 205             continue;
 206         if (el1_probe1(dev, ioaddr) == 0)
 207             return 0;
 208     }
 209 
 210     return ENODEV;
 211 }
 212 #endif
 213 
 214 /* The actual probe. */ 
 215 static int
 216 el1_probe1(struct device *dev, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 217 {
 218     #ifndef MODULE
 219 
 220     const char *mname;          /* Vendor name */
 221     unsigned char station_addr[6];
 222     int autoirq = 0;
 223     int i;
 224 
 225     /* Read the station address PROM data from the special port.  */
 226     for (i = 0; i < 6; i++) {
 227         outw(i, ioaddr + EL1_DATAPTR);
 228         station_addr[i] = inb(ioaddr + EL1_SAPROM);
 229     }
 230     /* Check the first three octets of the S.A. for 3Com's prefix, or
 231        for the Sager NP943 prefix. */ 
 232     if (station_addr[0] == 0x02  &&  station_addr[1] == 0x60
 233         && station_addr[2] == 0x8c) {
 234         mname = "3c501";
 235     } else if (station_addr[0] == 0x00  &&  station_addr[1] == 0x80
 236         && station_addr[2] == 0xC8) {
 237         mname = "NP943";
 238     } else
 239         return ENODEV;
 240 
 241     /* Grab the region so we can find the another board if autoIRQ fails. */
 242     request_region(ioaddr, EL1_IO_EXTENT,"3c501");
 243 
 244     /* We auto-IRQ by shutting off the interrupt line and letting it float
 245        high. */
 246     if (dev->irq < 2) {
 247 
 248         autoirq_setup(2);
 249 
 250         inb(RX_STATUS);         /* Clear pending interrupts. */
 251         inb(TX_STATUS);
 252         outb(AX_LOOP + 1, AX_CMD);
 253 
 254         outb(0x00, AX_CMD);
 255 
 256         autoirq = autoirq_report(1);
 257 
 258         if (autoirq == 0) {
 259             printk("%s probe at %#x failed to detect IRQ line.\n",
 260                    mname, ioaddr);
 261             return EAGAIN;
 262         }
 263     }
 264 
 265     outb(AX_RESET+AX_LOOP, AX_CMD);                     /* Loopback mode. */
 266 
 267     dev->base_addr = ioaddr;
 268     memcpy(dev->dev_addr, station_addr, ETH_ALEN);
 269     if (dev->mem_start & 0xf)
 270         el_debug = dev->mem_start & 0x7;
 271     if (autoirq)
 272         dev->irq = autoirq;
 273 
 274     printk("%s: %s EtherLink at %#lx, using %sIRQ %d.\n",
 275            dev->name, mname, dev->base_addr,
 276            autoirq ? "auto":"assigned ", dev->irq);
 277            
 278 #ifdef CONFIG_IP_MULTICAST
 279     printk("WARNING: Use of the 3c501 in a multicast kernel is NOT recommended.\n");
 280 #endif    
 281 
 282     if (el_debug)
 283         printk("%s", version);
 284 
 285     /* Initialize the device structure. */
 286     dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
 287     if (dev->priv == NULL)
 288         return -ENOMEM;
 289     memset(dev->priv, 0, sizeof(struct net_local));
 290 
 291     /* The EL1-specific entries in the device structure. */
 292     dev->open = &el_open;
 293     dev->hard_start_xmit = &el_start_xmit;
 294     dev->stop = &el1_close;
 295     dev->get_stats = &el1_get_stats;
 296     dev->set_multicast_list = &set_multicast_list;
 297     /* Setup the generic properties */
 298     ether_setup(dev);
 299 
 300 #endif /* !MODULE */
 301     return 0;
 302 }
 303 
 304 /* Open/initialize the board. */
 305 static int
 306 el_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 307 {
 308     int ioaddr = dev->base_addr;
 309 
 310     if (el_debug > 2)
 311         printk("%s: Doing el_open()...", dev->name);
 312 
 313     if (request_irq(dev->irq, &el_interrupt, 0, "3c501")) {
 314         return -EAGAIN;
 315     }
 316     irq2dev_map[dev->irq] = dev;
 317 
 318     el_reset(dev);
 319 
 320     dev->start = 1;
 321 
 322     outb(AX_RX, AX_CMD);        /* Aux control, irq and receive enabled */
 323     MOD_INC_USE_COUNT;
 324     return 0;
 325 }
 326 
 327 static int
 328 el_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 329 {
 330     struct net_local *lp = (struct net_local *)dev->priv;
 331     int ioaddr = dev->base_addr;
 332     unsigned long flags;
 333 
 334     if (dev->tbusy) {
 335         if (jiffies - dev->trans_start < 20) {
 336             if (el_debug > 2)
 337                 printk(" transmitter busy, deferred.\n");
 338             return 1;
 339         }
 340         if (el_debug)
 341             printk ("%s: transmit timed out, txsr %#2x axsr=%02x rxsr=%02x.\n",
 342                     dev->name, inb(TX_STATUS), inb(AX_STATUS), inb(RX_STATUS));
 343         lp->stats.tx_errors++;
 344         outb(TX_NORM, TX_CMD);
 345         outb(RX_NORM, RX_CMD);
 346         outb(AX_OFF, AX_CMD);   /* Just trigger a false interrupt. */
 347         outb(AX_RX, AX_CMD);    /* Aux control, irq and receive enabled */
 348         dev->tbusy = 0;
 349         dev->trans_start = jiffies;
 350     }
 351 
 352     if (skb == NULL) {
 353         dev_tint(dev);
 354         return 0;
 355     }
 356 
 357     save_flags(flags);
 358     /* Avoid incoming interrupts between us flipping tbusy and flipping
 359        mode as the driver assumes tbusy is a faithful indicator of card
 360        state */
 361     cli();
 362     /* Avoid timer-based retransmission conflicts. */
 363     if (set_bit(0, (void*)&dev->tbusy) != 0)
 364     {
 365         restore_flags(flags);
 366         printk("%s: Transmitter access conflict.\n", dev->name);
 367     }
 368     else {
 369         int gp_start = 0x800 - (ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN);
 370         unsigned char *buf = skb->data;
 371 
 372 load_it_again_sam:
 373         lp->tx_pkt_start = gp_start;
 374         lp->collisions = 0;
 375 
 376         /*
 377          *      Command mode with status cleared should [in theory]
 378          *      mean no more interrupts can be pending on the card.
 379          */
 380         outb(AX_SYS, AX_CMD);
 381         inb(RX_STATUS);
 382         inb(TX_STATUS);
 383         
 384         lp->loading=1;
 385         
 386         /* 
 387          *      Turn interrupts back on while we spend a pleasant afternoon
 388          *      loading bytes into the board 
 389          */
 390         restore_flags(flags);
 391         outw(0x00, RX_BUF_CLR);         /* Set rx packet area to 0. */
 392         outw(gp_start, GP_LOW);         /* aim - packet will be loaded into buffer start */
 393         outsb(DATAPORT,buf,skb->len);   /* load buffer (usual thing each byte increments the pointer) */
 394         outw(gp_start, GP_LOW);         /* the board reuses the same register */
 395         if(lp->loading==2)              /* A receive upset our load, despite our best efforts */
 396         {
 397                 if(el_debug>2)
 398                         printk("%s: burped during tx load.\n", dev->name);
 399                 goto load_it_again_sam; /* Sigh... */
 400         }
 401         outb(AX_XMIT, AX_CMD);          /* fire ... Trigger xmit.  */
 402         dev->trans_start = jiffies;
 403     }
 404 
 405     if (el_debug > 2)
 406         printk(" queued xmit.\n");
 407     dev_kfree_skb (skb, FREE_WRITE);
 408     return 0;
 409 }
 410 
 411 
 412 /* The typical workload of the driver:
 413    Handle the ether interface interrupts. */
 414 static void
 415 el_interrupt(int irq, struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 416 {
 417     struct device *dev = (struct device *)(irq2dev_map[irq]);
 418     struct net_local *lp;
 419     int ioaddr;
 420     int axsr;                   /* Aux. status reg. */
 421 
 422     if (dev == NULL  ||  dev->irq != irq) {
 423         printk ("3c501 driver: irq %d for unknown device.\n", irq);
 424         return;
 425     }
 426 
 427     ioaddr = dev->base_addr;
 428     lp = (struct net_local *)dev->priv;
 429     axsr = inb(AX_STATUS);
 430 
 431     if (el_debug > 3)
 432       printk("%s: el_interrupt() aux=%#02x", dev->name, axsr);
 433     if (dev->interrupt)
 434         printk("%s: Reentering the interrupt driver!\n", dev->name);
 435     dev->interrupt = 1;
 436     
 437     lp->loading=2;              /* So we can spot loading interruptions */
 438 
 439     if (dev->tbusy) {
 440     
 441         /*
 442          *      Board in transmit mode.
 443          */
 444          
 445         int txsr = inb(TX_STATUS);
 446 
 447         if (el_debug > 6)
 448             printk(" txsr=%02x gp=%04x rp=%04x", txsr, inw(GP_LOW),
 449                    inw(RX_LOW));
 450 
 451         if ((axsr & 0x80) && (txsr & TX_READY) == 0) {
 452         /*
 453          *      FIXME: is there a logic to whether to keep on trying or
 454          *      reset immediately ?
 455          */
 456             printk("%s: Unusual interrupt during Tx, txsr=%02x axsr=%02x"
 457                    " gp=%03x rp=%03x.\n", dev->name, txsr, axsr,
 458                    inw(ioaddr + EL1_DATAPTR), inw(ioaddr + EL1_RXPTR));
 459             dev->tbusy = 0;
 460             mark_bh(NET_BH);
 461         } else if (txsr & TX_16COLLISIONS) {
 462         /*
 463          *      Timed out
 464          */
 465             if (el_debug)
 466                 printk("%s: Transmit failed 16 times, ethernet jammed?\n",
 467                        dev->name);
 468             outb(AX_SYS, AX_CMD);
 469             lp->stats.tx_aborted_errors++;
 470         } else if (txsr & TX_COLLISION) {       /* Retrigger xmit. */
 471             if (el_debug > 6)
 472                 printk(" retransmitting after a collision.\n");
 473         /*
 474          *      Poor little chip can't reset its own start pointer
 475          */
 476             outb(AX_SYS, AX_CMD);
 477             outw(lp->tx_pkt_start, GP_LOW);
 478             outb(AX_XMIT, AX_CMD);
 479             lp->stats.collisions++;
 480             dev->interrupt = 0;
 481             return;
 482         } else {
 483         /*
 484          *      It worked.. we will now fall through and receive
 485          */
 486             lp->stats.tx_packets++;
 487             if (el_debug > 6)
 488                 printk(" Tx succeeded %s\n",
 489                        (txsr & TX_RDY) ? "." : "but tx is busy!");
 490         /*
 491          *      This is safe the interrupt is atomic WRT itself.
 492          */
 493             dev->tbusy = 0;
 494             mark_bh(NET_BH);    /* In case more to transmit */
 495         }
 496     } else {
 497     
 498         /*
 499          *      In receive mode.
 500          */
 501          
 502         int rxsr = inb(RX_STATUS);
 503         if (el_debug > 5)
 504             printk(" rxsr=%02x txsr=%02x rp=%04x", rxsr, inb(TX_STATUS),
 505                    inw(RX_LOW));
 506 
 507         /*
 508          *      Just reading rx_status fixes most errors. 
 509          */
 510         if (rxsr & RX_MISSED)
 511             lp->stats.rx_missed_errors++;
 512         if (rxsr & RX_RUNT) {   /* Handled to avoid board lock-up. */
 513             lp->stats.rx_length_errors++;
 514             if (el_debug > 5) printk(" runt.\n");
 515         } else if (rxsr & RX_GOOD) {
 516         /*
 517          *      Receive worked.
 518          */
 519             el_receive(dev);
 520         } else {                        /* Nothing?  Something is broken! */
 521             if (el_debug > 2)
 522                 printk("%s: No packet seen, rxsr=%02x **resetting 3c501***\n",
 523                        dev->name, rxsr);
 524             el_reset(dev);
 525         }
 526         if (el_debug > 3)
 527             printk(".\n");
 528     }
 529 
 530     /*
 531      *  Move into receive mode 
 532      */
 533     outb(AX_RX, AX_CMD);
 534     outw(0x00, RX_BUF_CLR);
 535     inb(RX_STATUS);             /* Be certain that interrupts are cleared. */
 536     inb(TX_STATUS);
 537     dev->interrupt = 0;
 538     return;
 539 }
 540 
 541 
 542 /* We have a good packet. Well, not really "good", just mostly not broken.
 543    We must check everything to see if it is good. */
 544 static void
 545 el_receive(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 546 {
 547     struct net_local *lp = (struct net_local *)dev->priv;
 548     int ioaddr = dev->base_addr;
 549     int pkt_len;
 550     struct sk_buff *skb;
 551 
 552     pkt_len = inw(RX_LOW);
 553 
 554     if (el_debug > 4)
 555       printk(" el_receive %d.\n", pkt_len);
 556 
 557     if ((pkt_len < 60)  ||  (pkt_len > 1536)) {
 558         if (el_debug)
 559           printk("%s: bogus packet, length=%d\n", dev->name, pkt_len);
 560         lp->stats.rx_over_errors++;
 561         return;
 562     }
 563     
 564     /*
 565      *  Command mode so we can empty the buffer
 566      */
 567      
 568     outb(AX_SYS, AX_CMD);
 569 
 570     skb = dev_alloc_skb(pkt_len+2);
 571     /*
 572      *  Start of frame
 573      */
 574     outw(0x00, GP_LOW);
 575     if (skb == NULL) {
 576         printk("%s: Memory squeeze, dropping packet.\n", dev->name);
 577         lp->stats.rx_dropped++;
 578         return;
 579     } else {
 580         skb_reserve(skb,2);     /* Force 16 byte alignment */
 581         skb->dev = dev;
 582 
 583         /*
 584          *      The read increments through the bytes. The interrupt
 585          *      handler will fix the pointer when it returns to 
 586          *      receive mode.
 587          */
 588          
 589         insb(DATAPORT, skb_put(skb,pkt_len), pkt_len);
 590         skb->protocol=eth_type_trans(skb,dev);
 591         netif_rx(skb);
 592         lp->stats.rx_packets++;
 593     }
 594     return;
 595 }
 596 
 597 static void 
 598 el_reset(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 599 {
 600     int ioaddr = dev->base_addr;
 601 
 602     if (el_debug> 2)
 603         printk("3c501 reset...");
 604     outb(AX_RESET, AX_CMD);     /* Reset the chip */
 605     outb(AX_LOOP, AX_CMD);      /* Aux control, irq and loopback enabled */
 606     {
 607         int i;
 608         for (i = 0; i < 6; i++) /* Set the station address. */
 609             outb(dev->dev_addr[i], ioaddr + i);
 610     }
 611     
 612     outw(0, RX_BUF_CLR);                /* Set rx packet area to 0. */
 613     cli();                      /* Avoid glitch on writes to CMD regs */
 614     outb(TX_NORM, TX_CMD);              /* tx irq on done, collision */
 615     outb(RX_NORM, RX_CMD);      /* Set Rx commands. */
 616     inb(RX_STATUS);             /* Clear status. */
 617     inb(TX_STATUS);
 618     dev->interrupt = 0;
 619     dev->tbusy = 0;
 620     sti();
 621 }
 622 
 623 static int
 624 el1_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 625 {
 626     int ioaddr = dev->base_addr;
 627 
 628     if (el_debug > 2)
 629         printk("%s: Shutting down ethercard at %#x.\n", dev->name, ioaddr);
 630 
 631     dev->tbusy = 1;
 632     dev->start = 0;
 633 
 634     /* Free and disable the IRQ. */
 635     free_irq(dev->irq);
 636     outb(AX_RESET, AX_CMD);     /* Reset the chip */
 637     irq2dev_map[dev->irq] = 0;
 638 
 639     MOD_DEC_USE_COUNT;
 640     return 0;
 641 }
 642 
 643 static struct enet_statistics *
 644 el1_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 645 {
 646     struct net_local *lp = (struct net_local *)dev->priv;
 647     return &lp->stats;
 648 }
 649 
 650 /* Set or clear the multicast filter for this adaptor.
 651    num_addrs == -2      All multicast hosts
 652    num_addrs == -1      Promiscuous mode, receive all packets
 653    num_addrs == 0       Normal mode, clear multicast list
 654    num_addrs > 0        Multicast mode, receive normal and MC packets, and do
 655                         best-effort filtering.
 656  */
 657 static void
 658 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
 659 {
 660     int ioaddr = dev->base_addr;
 661 
 662     if (num_addrs > 0 || num_addrs==-2) {
 663         outb(RX_MULT, RX_CMD);  /* Multicast or all multicast is the same */
 664         inb(RX_STATUS);         /* Clear status. */
 665     } else if (num_addrs < 0) {
 666         outb(RX_PROM, RX_CMD);
 667         inb(RX_STATUS);
 668     } else {
 669         outb(RX_NORM, RX_CMD);
 670         inb(RX_STATUS);
 671     }
 672 }
 673 #ifdef MODULE
 674 static char devicename[9] = { 0, };
 675 static struct device dev_3c501 = {
 676         devicename, /* device name is inserted by linux/drivers/net/net_init.c */
 677         0, 0, 0, 0,
 678         0x280, 5,
 679         0, 0, 0, NULL, el1_probe };
 680 
 681 static int io=0x280;
 682 static int irq=5;
 683         
 684 int
 685 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 686 {
 687         dev_3c501.irq=irq;
 688         dev_3c501.base_addr=io;
 689         if (register_netdev(&dev_3c501) != 0)
 690                 return -EIO;
 691         return 0;
 692 }
 693 
 694 void
 695 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 696 {
 697         /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
 698         unregister_netdev(&dev_3c501);
 699 
 700         /* Free up the private structure, or leak memory :-)  */
 701         kfree(dev_3c501.priv);
 702         dev_3c501.priv = NULL;  /* gets re-allocated by el1_probe1 */
 703 
 704         /* If we don't do this, we can't re-insmod it later. */
 705         release_region(dev_3c501.base_addr, EL1_IO_EXTENT);
 706 }
 707 #endif /* MODULE */
 708 
 709 /*
 710  * Local variables:
 711  *  compile-command: "gcc -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer  -m486 -c -o 3c501.o 3c501.c"
 712  *  kept-new-versions: 5
 713  * End:
 714  */

/* [previous][next][first][last][top][bottom][index][help] */