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

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