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

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