root/drivers/net/3c509.c

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

DEFINITIONS

This source file includes following definitions.
  1. el3_probe
  2. read_eeprom
  3. id_read_eeprom
  4. el3_open
  5. el3_start_xmit
  6. el3_interrupt
  7. el3_get_stats
  8. update_stats
  9. el3_rx
  10. set_multicast_list
  11. el3_close
  12. init_module
  13. cleanup_module

   1 /* 3c509.c: A 3c509 EtherLink3 ethernet driver for linux. */
   2 /*
   3         Written 1993,1994 by Donald Becker.
   4 
   5         Copyright 1994 by Donald Becker.
   6         Copyright 1993 United States Government as represented by the
   7         Director, National Security Agency.      This software may be used and
   8         distributed according to the terms of the GNU Public License,
   9         incorporated herein by reference.
  10 
  11         This driver is for the 3Com EtherLinkIII series.
  12 
  13         The author may be reached as becker@cesdis.gsfc.nasa.gov or
  14         C/O Center of Excellence in Space Data and Information Sciences
  15                 Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
  16 
  17         Known limitations:
  18         Because of the way 3c509 ISA detection works it's difficult to predict
  19         a priori which of several ISA-mode cards will be detected first.
  20 
  21         This driver does not use predictive interrupt mode, resulting in higher
  22         packet latency but lower overhead.  If interrupts are disabled for an
  23         unusually long time it could also result in missed packets, but in
  24         practice this rarely happens.
  25 */
  26 
  27 static const  char *version = "3c509.c:1.03 10/8/94 becker@cesdis.gsfc.nasa.gov\n";
  28 
  29 #include <linux/config.h>
  30 #ifdef MODULE
  31 #include <linux/module.h>
  32 #include <linux/version.h>
  33 #endif
  34 
  35 #include <linux/kernel.h>
  36 #include <linux/sched.h>
  37 #include <linux/string.h>
  38 #include <linux/interrupt.h>
  39 #include <linux/ptrace.h>
  40 #include <linux/errno.h>
  41 #include <linux/in.h>
  42 #include <linux/malloc.h>
  43 #include <linux/ioport.h>
  44 #include <asm/bitops.h>
  45 #include <asm/io.h>
  46 
  47 #include <linux/netdevice.h>
  48 #include <linux/etherdevice.h>
  49 #include <linux/skbuff.h>
  50 
  51 
  52 #ifdef EL3_DEBUG
  53 int el3_debug = EL3_DEBUG;
  54 #else
  55 int el3_debug = 2;
  56 #endif
  57 
  58 /* To minimize the size of the driver source I only define operating
  59    constants if they are used several times.  You'll need the manual
  60    if you want to understand driver details. */
  61 /* Offsets from base I/O address. */
  62 #define EL3_DATA 0x00
  63 #define EL3_CMD 0x0e
  64 #define EL3_STATUS 0x0e
  65 #define ID_PORT 0x100
  66 #define  EEPROM_READ 0x80
  67 
  68 #define EL3_IO_EXTENT   16
  69 
  70 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
  71 
  72 
  73 /* The top five bits written to EL3_CMD are a command, the lower
  74    11 bits are the parameter, if applicable. */
  75 enum c509cmd {
  76         TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
  77         RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, RxDiscard = 8<<11,
  78         TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
  79         FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrMask = 14<<11,
  80         SetReadZero = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
  81         SetTxThreshold = 18<<11, SetTxStart = 19<<11, StatsEnable = 21<<11,
  82         StatsDisable = 22<<11, StopCoax = 23<<11,};
  83 
  84 /* The SetRxFilter command accepts the following classes: */
  85 enum RxFilter {
  86         RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
  87 
  88 /* Register window 1 offsets, the window used in normal operation. */
  89 #define TX_FIFO         0x00
  90 #define RX_FIFO         0x00
  91 #define RX_STATUS       0x08
  92 #define TX_STATUS       0x0B
  93 #define TX_FREE         0x0C            /* Remaining free bytes in Tx buffer. */
  94 
  95 #define WN0_IRQ         0x08            /* Window 0: Set IRQ line in bits 12-15. */
  96 #define WN4_MEDIA       0x0A            /* Window 4: Various transcvr/media bits. */
  97 #define  MEDIA_TP       0x00C0          /* Enable link beat and jabber for 10baseT. */
  98 
  99 struct el3_private {
 100         struct enet_statistics stats;
 101 };
 102 
 103 static ushort id_read_eeprom(int index);
 104 static ushort read_eeprom(short ioaddr, int index);
 105 static int el3_open(struct device *dev);
 106 static int el3_start_xmit(struct sk_buff *skb, struct device *dev);
 107 static void el3_interrupt(int irq, struct pt_regs *regs);
 108 static void update_stats(int addr, struct device *dev);
 109 static struct enet_statistics *el3_get_stats(struct device *dev);
 110 static int el3_rx(struct device *dev);
 111 static int el3_close(struct device *dev);
 112 #ifdef HAVE_MULTICAST
 113 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
 114 #endif
 115 
 116 
 117 
 118 int el3_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 119 {
 120         short lrs_state = 0xff, i;
 121         ushort ioaddr, irq, if_port;
 122         short *phys_addr = (short *)dev->dev_addr;
 123         static int current_tag = 0;
 124 
 125         /* First check all slots of the EISA bus.  The next slot address to
 126            probe is kept in 'eisa_addr' to support multiple probe() calls. */
 127         if (EISA_bus) {
 128                 static int eisa_addr = 0x1000;
 129                 while (eisa_addr < 0x9000) {
 130                         ioaddr = eisa_addr;
 131                         eisa_addr += 0x1000;
 132 
 133                         /* Check the standard EISA ID register for an encoded '3Com'. */
 134                         if (inw(ioaddr + 0xC80) != 0x6d50)
 135                                 continue;
 136 
 137                         /* Change the register set to the configuration window 0. */
 138                         outw(SelectWindow | 0, ioaddr + 0xC80 + EL3_CMD);
 139 
 140                         irq = inw(ioaddr + WN0_IRQ) >> 12;
 141                         if_port = inw(ioaddr + 6)>>14;
 142                         for (i = 0; i < 3; i++)
 143                                 phys_addr[i] = htons(read_eeprom(ioaddr, i));
 144 
 145                         /* Restore the "Product ID" to the EEPROM read register. */
 146                         read_eeprom(ioaddr, 3);
 147 
 148                         /* Was the EISA code an add-on hack?  Nahhhhh... */
 149                         goto found;
 150                 }
 151         }
 152 
 153 #ifdef CONFIG_MCA
 154         if (MCA_bus) {
 155                 mca_adaptor_select_mode(1);
 156                 for (i = 0; i < 8; i++)
 157                         if ((mca_adaptor_id(i) | 1) == 0x627c) {
 158                                 ioaddr = mca_pos_base_addr(i);
 159                                 irq = inw(ioaddr + WN0_IRQ) >> 12;
 160                                 if_port = inw(ioaddr + 6)>>14;
 161                                 for (i = 0; i < 3; i++)
 162                                         phys_addr[i] = htons(read_eeprom(ioaddr, i));
 163 
 164                                 mca_adaptor_select_mode(0);
 165                                 goto found;
 166                         }
 167                 mca_adaptor_select_mode(0);
 168 
 169         }
 170 #endif
 171 
 172         /* Next check for all ISA bus boards by sending the ID sequence to the
 173            ID_PORT.  We find cards past the first by setting the 'current_tag'
 174            on cards as they are found.  Cards with their tag set will not
 175            respond to subsequent ID sequences. */
 176 
 177         if (check_region(ID_PORT,1)) {
 178           static int once = 1;
 179           if (once) printk("3c509: Somebody has reserved 0x%x, can't do ID_PORT lookup, nor card auto-probing\n",ID_PORT);
 180           once = 0;
 181           return -ENODEV;
 182         }
 183 
 184         outb(0x00, ID_PORT);
 185         outb(0x00, ID_PORT);
 186         for(i = 0; i < 255; i++) {
 187                 outb(lrs_state, ID_PORT);
 188                 lrs_state <<= 1;
 189                 lrs_state = lrs_state & 0x100 ? lrs_state ^ 0xcf : lrs_state;
 190         }
 191 
 192         /* For the first probe, clear all board's tag registers. */
 193         if (current_tag == 0)
 194                 outb(0xd0, ID_PORT);
 195         else                            /* Otherwise kill off already-found boards. */
 196                 outb(0xd8, ID_PORT);
 197 
 198         if (id_read_eeprom(7) != 0x6d50) {
 199                 return -ENODEV;
 200         }
 201 
 202         /* Read in EEPROM data, which does contention-select.
 203            Only the lowest address board will stay "on-line".
 204            3Com got the byte order backwards. */
 205         for (i = 0; i < 3; i++) {
 206                 phys_addr[i] = htons(id_read_eeprom(i));
 207         }
 208 
 209         {
 210                 unsigned short iobase = id_read_eeprom(8);
 211                 if_port = iobase >> 14;
 212                 ioaddr = 0x200 + ((iobase & 0x1f) << 4);
 213         }
 214         irq = id_read_eeprom(9) >> 12;
 215 
 216         if (dev->base_addr != 0
 217                 &&      dev->base_addr != (unsigned short)ioaddr) {
 218                 return -ENODEV;
 219         }
 220 
 221         /* Set the adaptor tag so that the next card can be found. */
 222         outb(0xd0 + ++current_tag, ID_PORT);
 223 
 224         /* Activate the adaptor at the EEPROM location. */
 225         outb(0xff, ID_PORT);
 226 
 227         EL3WINDOW(0);
 228         if (inw(ioaddr) != 0x6d50)
 229                 return -ENODEV;
 230 
 231         /* Free the interrupt so that some other card can use it. */
 232         outw(0x0f00, ioaddr + WN0_IRQ);
 233  found:
 234         dev->base_addr = ioaddr;
 235         dev->irq = irq;
 236         dev->if_port = if_port;
 237         request_region(dev->base_addr, EL3_IO_EXTENT, "3c509");
 238 
 239         {
 240                 const char *if_names[] = {"10baseT", "AUI", "undefined", "BNC"};
 241                 printk("%s: 3c509 at %#3.3lx tag %d, %s port, address ",
 242                            dev->name, dev->base_addr, current_tag, if_names[dev->if_port]);
 243         }
 244 
 245         /* Read in the station address. */
 246         for (i = 0; i < 6; i++)
 247                 printk(" %2.2x", dev->dev_addr[i]);
 248         printk(", IRQ %d.\n", dev->irq);
 249 
 250         /* Make up a EL3-specific-data structure. */
 251         dev->priv = kmalloc(sizeof(struct el3_private), GFP_KERNEL);
 252         if (dev->priv == NULL)
 253                 return -ENOMEM;
 254         memset(dev->priv, 0, sizeof(struct el3_private));
 255 
 256         if (el3_debug > 0)
 257                 printk(version);
 258 
 259         /* The EL3-specific entries in the device structure. */
 260         dev->open = &el3_open;
 261         dev->hard_start_xmit = &el3_start_xmit;
 262         dev->stop = &el3_close;
 263         dev->get_stats = &el3_get_stats;
 264 #ifdef HAVE_MULTICAST
 265                 dev->set_multicast_list = &set_multicast_list;
 266 #endif
 267 
 268         /* Fill in the generic fields of the device structure. */
 269         ether_setup(dev);
 270         return 0;
 271 }
 272 
 273 /* Read a word from the EEPROM using the regular EEPROM access register.
 274    Assume that we are in register window zero.
 275  */
 276 static ushort read_eeprom(short ioaddr, int index)
     /* [previous][next][first][last][top][bottom][index][help] */
 277 {
 278         int timer;
 279 
 280         outw(EEPROM_READ + index, ioaddr + 10);
 281         /* Pause for at least 162 us. for the read to take place. */
 282         for (timer = 0; timer < 162*4 + 400; timer++)
 283                 SLOW_DOWN_IO;
 284         return inw(ioaddr + 12);
 285 }
 286 
 287 /* Read a word from the EEPROM when in the ISA ID probe state. */
 288 static ushort id_read_eeprom(int index)
     /* [previous][next][first][last][top][bottom][index][help] */
 289 {
 290         int timer, bit, word = 0;
 291 
 292         /* Issue read command, and pause for at least 162 us. for it to complete.
 293            Assume extra-fast 16Mhz bus. */
 294         outb(EEPROM_READ + index, ID_PORT);
 295 
 296         /* This should really be done by looking at one of the timer channels. */
 297         for (timer = 0; timer < 162*4 + 400; timer++)
 298                 SLOW_DOWN_IO;
 299 
 300         for (bit = 15; bit >= 0; bit--)
 301                 word = (word << 1) + (inb(ID_PORT) & 0x01);
 302 
 303         if (el3_debug > 3)
 304                 printk("  3c509 EEPROM word %d %#4.4x.\n", index, word);
 305 
 306         return word;
 307 }
 308 
 309 
 310 
 311 static int
 312 el3_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 313 {
 314         int ioaddr = dev->base_addr;
 315         int i;
 316 
 317         outw(TxReset, ioaddr + EL3_CMD);
 318         outw(RxReset, ioaddr + EL3_CMD);
 319         outw(SetReadZero | 0x00, ioaddr + EL3_CMD);
 320 
 321         if (request_irq(dev->irq, &el3_interrupt, 0, "3c509")) {
 322                 return -EAGAIN;
 323         }
 324 
 325         EL3WINDOW(0);
 326         if (el3_debug > 3)
 327                 printk("%s: Opening, IRQ %d      status@%x %4.4x.\n", dev->name,
 328                            dev->irq, ioaddr + EL3_STATUS, inw(ioaddr + EL3_STATUS));
 329 
 330         /* Activate board: this is probably unnecessary. */
 331         outw(0x0001, ioaddr + 4);
 332 
 333         irq2dev_map[dev->irq] = dev;
 334 
 335         /* Set the IRQ line. */
 336         outw((dev->irq << 12) | 0x0f00, ioaddr + WN0_IRQ);
 337 
 338         /* Set the station address in window 2 each time opened. */
 339         EL3WINDOW(2);
 340 
 341         for (i = 0; i < 6; i++)
 342                 outb(dev->dev_addr[i], ioaddr + i);
 343 
 344         if (dev->if_port == 3)
 345                 /* Start the thinnet transceiver. We should really wait 50ms...*/
 346                 outw(StartCoax, ioaddr + EL3_CMD);
 347         else if (dev->if_port == 0) {
 348                 /* 10baseT interface, enabled link beat and jabber check. */
 349                 EL3WINDOW(4);
 350                 outw(inw(ioaddr + WN4_MEDIA) | MEDIA_TP, ioaddr + WN4_MEDIA);
 351         }
 352 
 353         /* Switch to the stats window, and clear all stats by reading. */
 354         outw(StatsDisable, ioaddr + EL3_CMD);
 355         EL3WINDOW(6);
 356         for (i = 0; i < 9; i++)
 357                 inb(ioaddr + i);
 358         inb(ioaddr + 10);
 359         inb(ioaddr + 12);
 360 
 361         /* Switch to register set 1 for normal use. */
 362         EL3WINDOW(1);
 363 
 364         /* Accept b-case and phys addr only. */
 365         outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
 366         outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
 367 
 368         dev->interrupt = 0;
 369         dev->tbusy = 0;
 370         dev->start = 1;
 371 
 372         outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
 373         outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
 374         /* Allow status bits to be seen. */
 375         outw(SetReadZero | 0xff, ioaddr + EL3_CMD);
 376         outw(AckIntr | 0x69, ioaddr + EL3_CMD); /* Ack IRQ */
 377         outw(SetIntrMask | 0x98, ioaddr + EL3_CMD); /* Set interrupt mask. */
 378 
 379         if (el3_debug > 3)
 380                 printk("%s: Opened 3c509  IRQ %d  status %4.4x.\n",
 381                            dev->name, dev->irq, inw(ioaddr + EL3_STATUS));
 382 
 383 #ifdef MODULE
 384         MOD_INC_USE_COUNT;
 385 #endif
 386         return 0;                                       /* Always succeed */
 387 }
 388 
 389 static int
 390 el3_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 391 {
 392         struct el3_private *lp = (struct el3_private *)dev->priv;
 393         int ioaddr = dev->base_addr;
 394 
 395         /* Transmitter timeout, serious problems. */
 396         if (dev->tbusy) {
 397                 int tickssofar = jiffies - dev->trans_start;
 398                 if (tickssofar < 10)
 399                         return 1;
 400                 printk("%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
 401                            dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS));
 402                 dev->trans_start = jiffies;
 403                 /* Issue TX_RESET and TX_START commands. */
 404                 outw(TxReset, ioaddr + EL3_CMD);
 405                 outw(TxEnable, ioaddr + EL3_CMD);
 406                 dev->tbusy = 0;
 407         }
 408 
 409         if (skb == NULL) {
 410                 dev_tint(dev);
 411                 return 0;
 412         }
 413 
 414         if (skb->len <= 0)
 415                 return 0;
 416 
 417         if (el3_debug > 4) {
 418                 printk("%s: el3_start_xmit(length = %ld) called, status %4.4x.\n",
 419                            dev->name, skb->len, inw(ioaddr + EL3_STATUS));
 420         }
 421 #ifndef final_version
 422         {       /* Error-checking code, delete for 1.30. */
 423                 ushort status = inw(ioaddr + EL3_STATUS);
 424                 if (status & 0x0001             /* IRQ line active, missed one. */
 425                         && inw(ioaddr + EL3_STATUS) & 1) {                      /* Make sure. */
 426                         printk("%s: Missed interrupt, status then %04x now %04x"
 427                                    "  Tx %2.2x Rx %4.4x.\n", dev->name, status,
 428                                    inw(ioaddr + EL3_STATUS), inb(ioaddr + TX_STATUS),
 429                                    inw(ioaddr + RX_STATUS));
 430                         /* Fake interrupt trigger by masking, acknowledge interrupts. */
 431                         outw(SetReadZero | 0x00, ioaddr + EL3_CMD);
 432                         outw(AckIntr | 0x69, ioaddr + EL3_CMD); /* Ack IRQ */
 433                         outw(SetReadZero | 0xff, ioaddr + EL3_CMD);
 434                 }
 435         }
 436 #endif
 437 
 438         /* Avoid timer-based retransmission conflicts. */
 439         if (set_bit(0, (void*)&dev->tbusy) != 0)
 440                 printk("%s: Transmitter access conflict.\n", dev->name);
 441         else {
 442                 /* Put out the doubleword header... */
 443                 outw(skb->len, ioaddr + TX_FIFO);
 444                 outw(0x00, ioaddr + TX_FIFO);
 445                 /* ... and the packet rounded to a doubleword. */
 446                 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
 447 
 448                 dev->trans_start = jiffies;
 449                 if (inw(ioaddr + TX_FREE) > 1536) {
 450                         dev->tbusy = 0;
 451                 } else
 452                         /* Interrupt us when the FIFO has room for max-sized packet. */
 453                         outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);
 454         }
 455 
 456         dev_kfree_skb (skb, FREE_WRITE);
 457 
 458         /* Clear the Tx status stack. */
 459         {
 460                 short tx_status;
 461                 int i = 4;
 462 
 463                 while (--i > 0  &&      (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
 464                         if (tx_status & 0x38) lp->stats.tx_aborted_errors++;
 465                         if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
 466                         if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
 467                         outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
 468                 }
 469         }
 470         return 0;
 471 }
 472 
 473 /* The EL3 interrupt handler. */
 474 static void
 475 el3_interrupt(int irq, struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 476 {
 477         struct device *dev = (struct device *)(irq2dev_map[irq]);
 478         int ioaddr, status;
 479         int i = 0;
 480 
 481         if (dev == NULL) {
 482                 printk ("el3_interrupt(): irq %d for unknown device.\n", irq);
 483                 return;
 484         }
 485 
 486         if (dev->interrupt)
 487                 printk("%s: Re-entering the interrupt handler.\n", dev->name);
 488         dev->interrupt = 1;
 489 
 490         ioaddr = dev->base_addr;
 491         status = inw(ioaddr + EL3_STATUS);
 492 
 493         if (el3_debug > 4)
 494                 printk("%s: interrupt, status %4.4x.\n", dev->name, status);
 495 
 496         while ((status = inw(ioaddr + EL3_STATUS)) & 0x91) {
 497 
 498                 if (status & 0x10)
 499                         el3_rx(dev);
 500 
 501                 if (status & 0x08) {
 502                         if (el3_debug > 5)
 503                                 printk("        TX room bit was handled.\n");
 504                         /* There's room in the FIFO for a full-sized packet. */
 505                         outw(AckIntr | 0x08, ioaddr + EL3_CMD);
 506                         dev->tbusy = 0;
 507                         mark_bh(NET_BH);
 508                 }
 509                 if (status & 0x80)                              /* Statistics full. */
 510                         update_stats(ioaddr, dev);
 511 
 512                 if (++i > 10) {
 513                         printk("%s: Infinite loop in interrupt, status %4.4x.\n",
 514                                    dev->name, status);
 515                         /* Clear all interrupts. */
 516                         outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
 517                         break;
 518                 }
 519                 /* Acknowledge the IRQ. */
 520                 outw(AckIntr | 0x41, ioaddr + EL3_CMD); /* Ack IRQ */
 521 
 522         }
 523 
 524         if (el3_debug > 4) {
 525                 printk("%s: exiting interrupt, status %4.4x.\n", dev->name,
 526                            inw(ioaddr + EL3_STATUS));
 527         }
 528 
 529         dev->interrupt = 0;
 530         return;
 531 }
 532 
 533 
 534 static struct enet_statistics *
 535 el3_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 536 {
 537         struct el3_private *lp = (struct el3_private *)dev->priv;
 538         unsigned long flags;
 539 
 540         save_flags(flags);
 541         cli();
 542         update_stats(dev->base_addr, dev);
 543         restore_flags(flags);
 544         return &lp->stats;
 545 }
 546 
 547 /*  Update statistics.  We change to register window 6, so this should be run
 548         single-threaded if the device is active. This is expected to be a rare
 549         operation, and it's simpler for the rest of the driver to assume that
 550         window 1 is always valid rather than use a special window-state variable.
 551         */
 552 static void update_stats(int ioaddr, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 553 {
 554         struct el3_private *lp = (struct el3_private *)dev->priv;
 555 
 556         if (el3_debug > 5)
 557                 printk("   Updating the statistics.\n");
 558         /* Turn off statistics updates while reading. */
 559         outw(StatsDisable, ioaddr + EL3_CMD);
 560         /* Switch to the stats window, and read everything. */
 561         EL3WINDOW(6);
 562         lp->stats.tx_carrier_errors     += inb(ioaddr + 0);
 563         lp->stats.tx_heartbeat_errors   += inb(ioaddr + 1);
 564         /* Multiple collisions. */              inb(ioaddr + 2);
 565         lp->stats.collisions                    += inb(ioaddr + 3);
 566         lp->stats.tx_window_errors              += inb(ioaddr + 4);
 567         lp->stats.rx_fifo_errors                += inb(ioaddr + 5);
 568         lp->stats.tx_packets                    += inb(ioaddr + 6);
 569         /* Rx packets   */                              inb(ioaddr + 7);
 570         /* Tx deferrals */                              inb(ioaddr + 8);
 571         inw(ioaddr + 10);       /* Total Rx and Tx octets. */
 572         inw(ioaddr + 12);
 573 
 574         /* Back to window 1, and turn statistics back on. */
 575         EL3WINDOW(1);
 576         outw(StatsEnable, ioaddr + EL3_CMD);
 577         return;
 578 }
 579 
 580 static int
 581 el3_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 582 {
 583         struct el3_private *lp = (struct el3_private *)dev->priv;
 584         int ioaddr = dev->base_addr;
 585         short rx_status;
 586 
 587         if (el3_debug > 5)
 588                 printk("   In rx_packet(), status %4.4x, rx_status %4.4x.\n",
 589                            inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
 590         while ((rx_status = inw(ioaddr + RX_STATUS)) > 0) {
 591                 if (rx_status & 0x4000) { /* Error, update stats. */
 592                         short error = rx_status & 0x3800;
 593                         lp->stats.rx_errors++;
 594                         switch (error) {
 595                         case 0x0000:            lp->stats.rx_over_errors++; break;
 596                         case 0x0800:            lp->stats.rx_length_errors++; break;
 597                         case 0x1000:            lp->stats.rx_frame_errors++; break;
 598                         case 0x1800:            lp->stats.rx_length_errors++; break;
 599                         case 0x2000:            lp->stats.rx_frame_errors++; break;
 600                         case 0x2800:            lp->stats.rx_crc_errors++; break;
 601                         }
 602                 } else {
 603                         short pkt_len = rx_status & 0x7ff;
 604                         struct sk_buff *skb;
 605 
 606                         skb = dev_alloc_skb(pkt_len+5);
 607                         if (el3_debug > 4)
 608                                 printk("Receiving packet size %d status %4.4x.\n",
 609                                            pkt_len, rx_status);
 610                         if (skb != NULL) {
 611                                 skb->dev = dev;
 612                                 skb_reserve(skb,2);     /* Align IP on 16 byte boundaries */
 613 
 614                                 /* 'skb->data' points to the start of sk_buff data area. */
 615                                 insl(ioaddr+RX_FIFO, skb_put(skb,pkt_len),
 616                                                         (pkt_len + 3) >> 2);
 617 
 618                                 skb->protocol=eth_type_trans(skb,dev);
 619                                 netif_rx(skb);
 620                                 outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
 621                                 lp->stats.rx_packets++;
 622                                 continue;
 623                         } else if (el3_debug)
 624                                 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
 625                                            dev->name, pkt_len);
 626                 }
 627                 lp->stats.rx_dropped++;
 628                 outw(RxDiscard, ioaddr + EL3_CMD);
 629                 while (inw(ioaddr + EL3_STATUS) & 0x1000)
 630                         printk("        Waiting for 3c509 to discard packet, status %x.\n",
 631                                    inw(ioaddr + EL3_STATUS) );
 632         }
 633 
 634         return 0;
 635 }
 636 
 637 #ifdef HAVE_MULTICAST
 638 /* Set or clear the multicast filter for this adaptor.
 639    num_addrs == -1              Promiscuous mode, receive all packets
 640    num_addrs == 0               Normal mode, clear multicast list
 641    num_addrs > 0                Multicast mode, receive normal and MC packets, and do
 642                                                 best-effort filtering.
 643  */
 644 static void
 645 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
 646 {
 647         short ioaddr = dev->base_addr;
 648         if (el3_debug > 1) {
 649                 static int old = 0;
 650                 if (old != num_addrs) {
 651                         old = num_addrs;
 652                         printk("%s: Setting Rx mode to %d addresses.\n", dev->name, num_addrs);
 653                 }
 654         }
 655         if (num_addrs > 0) {
 656                 outw(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
 657         } else if (num_addrs < 0) {
 658                 outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
 659                          ioaddr + EL3_CMD);
 660         } else
 661                 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
 662 }
 663 #endif
 664 
 665 static int
 666 el3_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 667 {
 668         int ioaddr = dev->base_addr;
 669 
 670         if (el3_debug > 2)
 671                 printk("%s: Shutting down ethercard.\n", dev->name);
 672 
 673         dev->tbusy = 1;
 674         dev->start = 0;
 675 
 676         /* Turn off statistics ASAP.  We update lp->stats below. */
 677         outw(StatsDisable, ioaddr + EL3_CMD);
 678 
 679         /* Disable the receiver and transmitter. */
 680         outw(RxDisable, ioaddr + EL3_CMD);
 681         outw(TxDisable, ioaddr + EL3_CMD);
 682 
 683         if (dev->if_port == 3)
 684                 /* Turn off thinnet power.  Green! */
 685                 outw(StopCoax, ioaddr + EL3_CMD);
 686         else if (dev->if_port == 0) {
 687                 /* Disable link beat and jabber, if_port may change ere next open(). */
 688                 EL3WINDOW(4);
 689                 outw(inw(ioaddr + WN4_MEDIA) & ~MEDIA_TP, ioaddr + WN4_MEDIA);
 690         }
 691 
 692         free_irq(dev->irq);
 693         /* Switching back to window 0 disables the IRQ. */
 694         EL3WINDOW(0);
 695         /* But we explicitly zero the IRQ line select anyway. */
 696         outw(0x0f00, ioaddr + WN0_IRQ);
 697 
 698 
 699         irq2dev_map[dev->irq] = 0;
 700 
 701         update_stats(ioaddr, dev);
 702 #ifdef MODULE
 703         MOD_DEC_USE_COUNT;
 704 #endif
 705         return 0;
 706 }
 707 
 708 #ifdef MODULE
 709 char kernel_version[] = UTS_RELEASE;
 710 static char devicename[9] = { 0, };
 711 static struct device dev_3c509 = {
 712         devicename, /* device name is inserted by linux/drivers/net/net_init.c */
 713         0, 0, 0, 0,
 714         0, 0,
 715         0, 0, 0, NULL, el3_probe };
 716 
 717 int io = 0;
 718 int irq = 0;
 719 
 720 int
 721 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 722 {
 723         dev_3c509.base_addr = io;
 724         dev_3c509.irq       = irq;
 725         if (!EISA_bus) {
 726                 printk("3c509: WARNING! Module load-time probing works reliably only for EISA-bus!\n");
 727         }
 728         if (register_netdev(&dev_3c509) != 0)
 729                 return -EIO;
 730         return 0;
 731 }
 732 
 733 void
 734 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 735 {
 736         if (MOD_IN_USE)
 737                 printk("3c509: device busy, remove delayed\n");
 738         else
 739         {
 740                 unregister_netdev(&dev_3c509);
 741                 kfree_s(dev_3c509.priv,sizeof(struct el3_private));
 742                 dev_3c509.priv=NULL;
 743                 /* If we don't do this, we can't re-insmod it later. */
 744                 release_region(dev_3c509.base_addr, EL3_IO_EXTENT);
 745         }
 746 }
 747 #endif /* MODULE */
 748 
 749 /*
 750  * Local variables:
 751  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c 3c509.c"
 752  *  version-control: t
 753  *  kept-new-versions: 5
 754  *  tab-width: 4
 755  * End:
 756  */

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