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

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