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

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