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

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