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

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