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

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