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         if (skb->free)
 392                 kfree_skb (skb, FREE_WRITE);
 393 
 394         /* Clear the Tx status stack. */
 395         {
 396                 short tx_status;
 397                 int i = 4;
 398 
 399                 while (--i > 0  &&      (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
 400                         if (el3_debug > 5)
 401                                 printk("                Tx status %4.4x.\n", tx_status);
 402                         if (tx_status & 0x38) lp->stats.tx_aborted_errors++;
 403                         if (tx_status & 0x30) outw(0x5800, ioaddr + EL3_CMD);
 404                         if (tx_status & 0x3C) outw(0x4800, ioaddr + EL3_CMD);
 405                         outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
 406                 }
 407         }
 408         return 0;
 409 }
 410 
 411 /* The EL3 interrupt handler. */
 412 static void
 413 el3_interrupt(int reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 414 {
 415         int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
 416         struct device *dev = (struct device *)(irq2dev_map[irq]);
 417         int ioaddr, status;
 418         int i = 0;
 419 
 420         if (dev == NULL) {
 421                 printk ("el3_interrupt(): irq %d for unknown device.\n", irq);
 422                 return;
 423         }
 424 
 425         if (dev->interrupt)
 426                 printk("%s: Re-entering the interrupt handler.\n", dev->name);
 427         dev->interrupt = 1;
 428 
 429         ioaddr = dev->base_addr;
 430         status = inw(ioaddr + EL3_STATUS);
 431 
 432         if (el3_debug > 4)
 433                 printk("%s: interrupt, status %4.4x.\n", dev->name, status);
 434         
 435         while ((status = inw(ioaddr + EL3_STATUS)) & 0x01) {
 436 
 437                 if (status & 0x10)
 438                         el3_rx(dev);
 439 
 440                 if (status & 0x08) {
 441                         if (el3_debug > 5)
 442                                 printk("        TX room bit was handled.\n");
 443                         /* There's room in the FIFO for a full-sized packet. */
 444                         outw(0x6808, ioaddr + EL3_CMD); /* Ack IRQ */
 445                         dev->tbusy = 0;
 446                         mark_bh(NET_BH);
 447                 }
 448                 if (status & 0x80)                              /* Statistics full. */
 449                         update_stats(ioaddr, dev);
 450                 
 451                 if (++i > 10) {
 452                         printk("%s: Infinite loop in interrupt, status %4.4x.\n",
 453                                    dev->name, status);
 454                         /* Clear all interrupts we have handled */
 455                         outw(0x68FF, ioaddr + EL3_CMD);
 456                         break;
 457                 }
 458                 /* Acknowledge the IRQ. */
 459                 outw(0x6891, ioaddr + EL3_CMD); /* Ack IRQ */
 460         }
 461 
 462         if (el3_debug > 4) {
 463                 printk("%s: exiting interrupt, status %4.4x.\n", dev->name,
 464                            inw(ioaddr + EL3_STATUS));
 465         }
 466         
 467         dev->interrupt = 0;
 468         return;
 469 }
 470 
 471 
 472 static struct enet_statistics *
 473 el3_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 474 {
 475         struct el3_private *lp = (struct el3_private *)dev->priv;
 476 
 477         sti();
 478         update_stats(dev->base_addr, dev);
 479         cli();
 480         return &lp->stats;
 481 }
 482 
 483 /*  Update statistics.  We change to register window 6, so this should be run
 484         single-threaded if the device is active. This is expected to be a rare
 485         operation, and it's simpler for the rest of the driver to assume that
 486         window 1 is always valid rather than use a special window-state variable.
 487         */
 488 static void update_stats(int ioaddr, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 489 {
 490         struct el3_private *lp = (struct el3_private *)dev->priv;
 491 
 492         if (el3_debug > 5)
 493                 printk("   Updating the statistics.\n");
 494         /* Turn off statistics updates while reading. */
 495         outw(0xB000, ioaddr + EL3_CMD);
 496         /* Switch to the stats window, and read everything. */
 497         EL3WINDOW(6);
 498         lp->stats.tx_carrier_errors     += inb(ioaddr + 0);
 499         lp->stats.tx_heartbeat_errors   += inb(ioaddr + 1);
 500         /* Multiple collisions. */              inb(ioaddr + 2);
 501         lp->stats.collisions                    += inb(ioaddr + 3);
 502         lp->stats.tx_window_errors              += inb(ioaddr + 4);
 503         lp->stats.rx_fifo_errors                += inb(ioaddr + 5);
 504         lp->stats.tx_packets                    += inb(ioaddr + 6);
 505         lp->stats.rx_packets                    += inb(ioaddr + 7);
 506         /* Tx deferrals */                              inb(ioaddr + 8);
 507         inw(ioaddr + 10);       /* Total Rx and Tx octets. */
 508         inw(ioaddr + 12);
 509 
 510         /* Back to window 1, and turn statistics back on. */
 511         EL3WINDOW(1);
 512         outw(0xA800, ioaddr + EL3_CMD);
 513         return;
 514 }
 515 
 516 static int
 517 el3_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 518 {
 519         struct el3_private *lp = (struct el3_private *)dev->priv;
 520         int ioaddr = dev->base_addr;
 521         short rx_status;
 522 
 523         if (el3_debug > 5)
 524                 printk("           In rx_packet(), status %4.4x, rx_status %4.4x.\n",
 525                            inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
 526         while ((rx_status = inw(ioaddr + RX_STATUS)) > 0) {
 527                 if (rx_status & 0x4000) { /* Error, update stats. */
 528                         short error = rx_status & 0x3800;
 529                         lp->stats.rx_errors++;
 530                         switch (error) {
 531                         case 0x0000:            lp->stats.rx_over_errors++; break;
 532                         case 0x0800:            lp->stats.rx_length_errors++; break;
 533                         case 0x1000:            lp->stats.rx_frame_errors++; break;
 534                         case 0x1800:            lp->stats.rx_length_errors++; break;
 535                         case 0x2000:            lp->stats.rx_frame_errors++; break;
 536                         case 0x2800:            lp->stats.rx_crc_errors++; break;
 537                         }
 538                 }
 539                 if ( (! (rx_status & 0x4000))
 540                         || ! (rx_status & 0x1000)) { /* Dribble bits are OK. */
 541                         short pkt_len = rx_status & 0x7ff;
 542                         struct sk_buff *skb;
 543 
 544                         skb = alloc_skb(pkt_len+3, GFP_ATOMIC);
 545                         if (el3_debug > 4)
 546                                 printk("Receiving packet size %d status %4.4x.\n",
 547                                            pkt_len, rx_status);
 548                         if (skb != NULL) {
 549                                 skb->len = pkt_len;
 550                                 skb->dev = dev;
 551 
 552                                 /* 'skb->data' points to the start of sk_buff data area. */
 553                                 insl(ioaddr+RX_FIFO, skb->data,
 554                                                         (pkt_len + 3) >> 2);
 555 
 556 #ifdef HAVE_NETIF_RX
 557                                 netif_rx(skb);
 558                                 outw(0x4000, ioaddr + EL3_CMD); /* Rx discard */
 559                                 continue;
 560 #else
 561                                 skb->lock = 0;
 562                                 if (dev_rint((unsigned char *)skb, pkt_len,
 563                                                          IN_SKBUFF,dev)== 0){
 564                                         if (el3_debug > 6)
 565                                                 printk("         dev_rint() happy, status %4.4x.\n",
 566                                                 inb(ioaddr + EL3_STATUS));
 567                                         outw(0x4000, ioaddr + EL3_CMD); /* Rx discard */
 568                                         while (inw(ioaddr + EL3_STATUS) & 0x1000)
 569                                           printk("      Waiting for 3c509 to discard packet, status %x.\n",
 570                                                          inw(ioaddr + EL3_STATUS) );
 571                                         if (el3_debug > 6)
 572                                                 printk("         discarded packet, status %4.4x.\n",
 573                                                 inb(ioaddr + EL3_STATUS));
 574                                         continue;
 575                                 } else {
 576                                         printk("%s: receive buffers full.\n", dev->name);
 577                                         kfree_s(skb, FREE_READ);
 578                                 }
 579 #endif
 580                         } else if (el3_debug)
 581                                 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
 582                                            dev->name, pkt_len);
 583                 }
 584                 lp->stats.rx_dropped++;
 585                 outw(0x4000, ioaddr + EL3_CMD); /* Rx discard */
 586                 while (inw(ioaddr + EL3_STATUS) & 0x1000)
 587                   printk("      Waiting for 3c509 to discard packet, status %x.\n",
 588                                  inw(ioaddr + EL3_STATUS) );
 589         }
 590 
 591         if (el3_debug > 5)
 592                 printk("           Exiting rx_packet(), status %4.4x, rx_status %4.4x.\n",
 593                            inw(ioaddr+EL3_STATUS), inw(ioaddr+8));
 594 
 595         return 0;
 596 }
 597 
 598 #ifdef HAVE_MULTICAST
 599 /* Set or clear the multicast filter for this adaptor.
 600    num_addrs == -1              Promiscuous mode, receive all packets
 601    num_addrs == 0               Normal mode, clear multicast list
 602    num_addrs > 0                Multicast mode, receive normal and MC packets, and do
 603                                                 best-effort filtering.
 604  */
 605 static void
 606 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
 607 {
 608         short ioaddr = dev->base_addr;
 609         if (num_addrs > 0) {
 610                 outw(0x8007, ioaddr + EL3_CMD);
 611         } else if (num_addrs < 0) {
 612                 outw(0x8008, ioaddr + EL3_CMD);
 613         } else
 614                 outw(0x8005, ioaddr + EL3_CMD);
 615 }
 616 #endif
 617 
 618 static int
 619 el3_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 620 {
 621         int ioaddr = dev->base_addr;
 622 
 623         if (el3_debug > 2)
 624                 printk("%s: Shutting down ethercard.\n", dev->name);
 625 
 626         dev->tbusy = 1;
 627         dev->start = 0;
 628 
 629         /* Turn off statistics.  We update lp->stats below. */
 630         outw(0xB000, ioaddr + EL3_CMD);
 631 
 632         /* Disable the receiver and transmitter. */
 633         outw(0x1800, ioaddr + EL3_CMD);
 634         outw(0x5000, ioaddr + EL3_CMD);
 635 
 636         if (dev->if_port == 3)
 637                 /* Turn off thinnet power. */
 638                 outw(0xb800, ioaddr + EL3_CMD);
 639         else if (dev->if_port == 0) {
 640                 /* Disable link beat and jabber, if_port may change ere next open(). */
 641                 EL3WINDOW(4);
 642                 outw(inw(ioaddr + WN4_MEDIA) & ~MEDIA_TP, ioaddr + WN4_MEDIA);
 643         }
 644 
 645         free_irq(dev->irq);
 646         /* Switching back to window 0 disables the IRQ. */
 647         EL3WINDOW(0);
 648         /* But we explicitly zero the IRQ line select anyway. */
 649         outw(0x0f00, ioaddr + 8);
 650 
 651 
 652         irq2dev_map[dev->irq] = 0;
 653 
 654         update_stats(ioaddr, dev);
 655 #ifdef MODULE
 656         MOD_DEC_USE_COUNT;
 657 #endif
 658         return 0;
 659 }
 660 
 661 /*
 662  * Local variables:
 663  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c 3c509.c"
 664  *  version-control: t
 665  *  kept-new-versions: 5
 666  *  tab-width: 4
 667  * End:
 668  */
 669 #ifdef MODULE
 670 char kernel_version[] = UTS_RELEASE;
 671 static struct device dev_3c509 = {
 672         "" /*"3c509"*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, el3_probe };
 673 
 674 int
 675 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 676 {
 677         if (register_netdev(&dev_3c509) != 0)
 678                 return -EIO;
 679         return 0;
 680 }
 681 
 682 void
 683 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 684 {
 685         if (MOD_IN_USE)
 686                 printk("3c509: device busy, remove delayed\n");
 687         else
 688         {
 689                 unregister_netdev(&dev_3c509);
 690                 kfree_s(dev_3c509.priv,sizeof(struct el3_private));
 691                 dev_3c509.priv=NULL;
 692         }
 693 }
 694 #endif /* MODULE */

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