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

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

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