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

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