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

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