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

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