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 "dev.h"
  32 #include "eth.h"
  33 #include "skbuff.h"
  34 #include "arp.h"
  35 
  36 #ifndef HAVE_ALLOC_SKB
  37 #define alloc_skb(size, priority) (struct sk_buff *) kmalloc(size,priority)
  38 #endif
  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         for (i = 0; i < DEV_NUMBUFFS; i++)
 223                 dev->buffs[i] = NULL;
 224 
 225         dev->hard_header        = eth_header;
 226         dev->add_arp            = eth_add_arp;
 227         dev->queue_xmit         = dev_queue_xmit;
 228         dev->rebuild_header = eth_rebuild_header;
 229         dev->type_trans         = eth_type_trans;
 230 
 231         dev->type                       = ARPHRD_ETHER;
 232         dev->hard_header_len = ETH_HLEN;
 233         dev->mtu                        = 1500; /* eth_mtu */
 234         dev->addr_len           = ETH_ALEN;
 235         for (i = 0; i < ETH_ALEN; i++) {
 236                 dev->broadcast[i]=0xff;
 237         }
 238 
 239         /* New-style flags. */
 240         dev->flags                      = IFF_BROADCAST;
 241         dev->family                     = AF_INET;
 242         dev->pa_addr            = 0;
 243         dev->pa_brdaddr         = 0;
 244         dev->pa_mask            = 0;
 245         dev->pa_alen            = sizeof(unsigned long);
 246 
 247         return 0;
 248 }
 249 
 250 /* Read a word from the EEPROM using the regular EEPROM access register.
 251    Assume that we are in register window zero.
 252  */
 253 static ushort read_eeprom(short ioaddr, int index)
     /* [previous][next][first][last][top][bottom][index][help] */
 254 {
 255         int timer;
 256 
 257         outw(EEPROM_READ + index, ioaddr + 10);
 258         /* Pause for at least 162 us. for the read to take place. */
 259         for (timer = 0; timer < 162*4 + 400; timer++)
 260                 SLOW_DOWN_IO;
 261         return inw(ioaddr + 12);
 262 }
 263 
 264 /* Read a word from the EEPROM when in the ISA ID probe state. */
 265 static ushort id_read_eeprom(int index)
     /* [previous][next][first][last][top][bottom][index][help] */
 266 {
 267         int timer, bit, word = 0;
 268         
 269         /* Issue read command, and pause for at least 162 us. for it to complete.
 270            Assume extra-fast 16Mhz bus. */
 271         outb(EEPROM_READ + index, ID_PORT);
 272 
 273         /* This should really be done by looking at one of the timer channels. */
 274         for (timer = 0; timer < 162*4 + 400; timer++)
 275                 SLOW_DOWN_IO;
 276 
 277         for (bit = 15; bit >= 0; bit--)
 278                 word = (word << 1) + (inb(ID_PORT) & 0x01);
 279                 
 280         if (el3_debug > 3)
 281                 printk("  3c509 EEPROM word %d %#4.4x.\n", index, word);
 282 
 283         return word;
 284 }
 285 
 286 
 287 
 288 static int
 289 el3_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 290 {
 291         int ioaddr = dev->base_addr;
 292         int i;
 293 
 294         if (request_irq(dev->irq, &el3_interrupt)) {
 295                 return -EAGAIN;
 296         }
 297 
 298         EL3WINDOW(0);
 299         if (el3_debug > 3)
 300                 printk("%s: Opening, IRQ %d      status@%x %4.4x.\n", dev->name,
 301                            dev->irq, ioaddr + EL3_STATUS, inw(ioaddr + EL3_STATUS));
 302 
 303         /* Activate board: this is probably unnecessary. */
 304         outw(0x0001, ioaddr + 4);
 305 
 306         irq2dev_map[dev->irq] = dev;
 307 
 308         /* Set the IRQ line. */
 309         outw((dev->irq << 12) | 0x0f00, ioaddr + 8);
 310 
 311         /* Set the station address in window 2 each time opened. */
 312         EL3WINDOW(2);
 313 
 314         for (i = 0; i < 6; i++)
 315                 outb(dev->dev_addr[i], ioaddr + i);
 316 
 317         if (dev->if_port == 3)
 318                 /* Start the thinnet transceiver. We should really wait 50ms...*/
 319                 outw(0x1000, ioaddr + EL3_CMD);
 320         else if (dev->if_port == 0) {
 321                 /* 10baseT interface, enabled link beat and jabber check. */
 322                 EL3WINDOW(4);
 323                 outw(inw(ioaddr + WN4_MEDIA) | MEDIA_TP, ioaddr + WN4_MEDIA);
 324         }
 325 
 326         /* Switch to register set 1 for normal use. */
 327         EL3WINDOW(1);
 328 
 329         outw(0x8005, ioaddr + EL3_CMD); /* Accept b-case and phys addr only. */
 330         outw(0xA800, ioaddr + EL3_CMD); /* Turn on statistics. */
 331         outw(0x2000, ioaddr + EL3_CMD); /* Enable the receiver. */
 332         outw(0x4800, ioaddr + EL3_CMD); /* Enable transmitter. */
 333         outw(0x78ff, ioaddr + EL3_CMD); /* Allow all status bits to be seen. */
 334         dev->interrupt = 0;
 335         dev->tbusy = 0;
 336         dev->start = 1;
 337         outw(0x7098, ioaddr + EL3_CMD); /* Set interrupt mask. */
 338 
 339         if (el3_debug > 3)
 340                 printk("%s: Opened 3c509  IRQ %d  status %4.4x.\n",
 341                            dev->name, dev->irq, inw(ioaddr + EL3_STATUS));
 342 
 343         return 0;                                       /* Always succeed */
 344 }
 345 
 346 static int
 347 el3_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 348 {
 349         struct el3_private *lp = (struct el3_private *)dev->priv;
 350         int ioaddr = dev->base_addr;
 351 
 352         /* Transmitter timeout, serious problems. */
 353         if (dev->tbusy) {
 354                 int tickssofar = jiffies - dev->trans_start;
 355                 if (tickssofar < 10)
 356                         return 1;
 357                 printk("%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
 358                            dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS));
 359                 dev->trans_start = jiffies;
 360                 /* Issue TX_RESET and TX_START commands. */
 361                 outw(0x5800, ioaddr + EL3_CMD); /* TX_RESET */
 362                 outw(0x4800, ioaddr + EL3_CMD); /* TX_START */
 363                 dev->tbusy = 0;
 364         }
 365 
 366         if (skb == NULL) {
 367                 dev_tint(dev);
 368                 return 0;
 369         }
 370 
 371         /* Fill in the ethernet header. */
 372         if (!skb->arp  &&  dev->rebuild_header(skb->data, dev)) {
 373                 skb->dev = dev;
 374                 arp_queue (skb);
 375                 return 0;
 376         }
 377         skb->arp=1;
 378 
 379         if (skb->len <= 0)
 380                 return 0;
 381 
 382         if (el3_debug > 4) {
 383                 printk("%s: el3_start_xmit(lenght = %ld) called, status %4.4x.\n",
 384                            dev->name, skb->len, inw(ioaddr + EL3_STATUS));
 385         }
 386 #ifndef final_version
 387         {       /* Error-checking code, delete for 1.00. */
 388                 ushort status = inw(ioaddr + EL3_STATUS);
 389                 if (status & 0x0001             /* IRQ line active, missed one. */
 390                         && inw(ioaddr + EL3_STATUS) & 1) {                      /* Make sure. */
 391                         printk("%s: Missed interrupt, status then %04x now %04x"
 392                                    "  Tx %2.2x Rx %4.4x.\n", dev->name, status,
 393                                    inw(ioaddr + EL3_STATUS), inb(ioaddr + TX_STATUS),
 394                                    inw(ioaddr + RX_STATUS));
 395                         outw(0x7800, ioaddr + EL3_CMD); /* Fake interrupt trigger. */
 396                         outw(0x6899, ioaddr + EL3_CMD); /* Ack IRQ */
 397                         outw(0x78ff, ioaddr + EL3_CMD); /* Set all status bits visible. */
 398                 }
 399         }
 400 #endif
 401 
 402         /* Avoid timer-based retransmission conflicts. */
 403         if (set_bit(0, (void*)&dev->tbusy) != 0)
 404                 printk("%s: Transmitter access conflict.\n", dev->name);
 405         else {
 406                 /* Put out the doubleword header... */
 407                 outw(skb->len, ioaddr + TX_FIFO);
 408                 outw(0x00, ioaddr + TX_FIFO);
 409                 /* ... and the packet rounded to a doubleword. */
 410                 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
 411         
 412                 dev->trans_start = jiffies;
 413                 if (inw(ioaddr + TX_FREE) > 1536) {
 414                         dev->tbusy=0;
 415                 } else
 416                         /* Interrupt us when the FIFO has room for max-sized packet. */
 417                         outw(0x9000 + 1536, ioaddr + EL3_CMD);
 418         }
 419 
 420         if (skb->free)
 421                 kfree_skb (skb, FREE_WRITE);
 422 
 423         /* Clear the Tx status stack. */
 424         {
 425                 short tx_status;
 426                 int i = 4;
 427 
 428                 while (--i > 0  &&      (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
 429                         if (el3_debug > 5)
 430                                 printk("                Tx status %4.4x.\n", tx_status);
 431                         if (tx_status & 0x38) lp->stats.tx_aborted_errors++;
 432                         if (tx_status & 0x30) outw(0x5800, ioaddr + EL3_CMD);
 433                         if (tx_status & 0x3C) outw(0x4800, ioaddr + EL3_CMD);
 434                         outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
 435                 }
 436         }
 437         return 0;
 438 }
 439 
 440 /* The EL3 interrupt handler. */
 441 static void
 442 el3_interrupt(int reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 443 {
 444         int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
 445         struct device *dev = (struct device *)(irq2dev_map[irq]);
 446         int ioaddr, status;
 447         int i = 0;
 448 
 449         if (dev == NULL) {
 450                 printk ("el3_interrupt(): irq %d for unknown device.\n", irq);
 451                 return;
 452         }
 453 
 454         if (dev->interrupt)
 455                 printk("%s: Re-entering the interrupt handler.\n", dev->name);
 456         dev->interrupt = 1;
 457 
 458         ioaddr = dev->base_addr;
 459         status = inw(ioaddr + EL3_STATUS);
 460 
 461         if (el3_debug > 4)
 462                 printk("%s: interrupt, status %4.4x.\n", dev->name, status);
 463         
 464         while ((status = inw(ioaddr + EL3_STATUS)) & 0x01) {
 465 
 466                 if (status & 0x10)
 467                         el3_rx(dev);
 468 
 469                 if (status & 0x08) {
 470                         if (el3_debug > 5)
 471                                 printk("        TX room bit was handled.\n");
 472                         /* There's room in the FIFO for a full-sized packet. */
 473                         outw(0x6808, ioaddr + EL3_CMD); /* Ack IRQ */
 474                         dev->tbusy = 0;
 475                         mark_bh(INET_BH);
 476                 }
 477                 if (status & 0x80)                              /* Statistics full. */
 478                         update_stats(ioaddr, dev);
 479                 
 480                 if (++i > 10) {
 481                         printk("%s: Infinite loop in interrupt, status %4.4x.\n",
 482                                    dev->name, status);
 483                         /* Clear all interrupts we have handled. */
 484                         outw(0x68FF, ioaddr + EL3_CMD);
 485                         break;
 486                 }
 487                 /* Acknowledge the IRQ. */
 488                 outw(0x6891, ioaddr + EL3_CMD); /* Ack IRQ */
 489         }
 490 
 491         if (el3_debug > 4) {
 492                 printk("%s: exiting interrupt, status %4.4x.\n", dev->name,
 493                            inw(ioaddr + EL3_STATUS));
 494         }
 495         
 496         dev->interrupt = 0;
 497         return;
 498 }
 499 
 500 
 501 static struct enet_statistics *
 502 el3_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 503 {
 504         struct el3_private *lp = (struct el3_private *)dev->priv;
 505 
 506         sti();
 507         update_stats(dev->base_addr, dev);
 508         cli();
 509         return &lp->stats;
 510 }
 511 
 512 /*  Update statistics.  We change to register window 6, so this should be run
 513         single-threaded if the device is active. This is expected to be a rare
 514         operation, and it's simpler for the rest of the driver to assume that
 515         window 1 is always valid rather than use a special window-state variable.
 516         */
 517 static void update_stats(int ioaddr, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 518 {
 519         struct el3_private *lp = (struct el3_private *)dev->priv;
 520 
 521         if (el3_debug > 5)
 522                 printk("   Updating the statistics.\n");
 523         /* Turn off statistics updates while reading. */
 524         outw(0xB000, ioaddr + EL3_CMD);
 525         /* Switch to the stats window, and read everything. */
 526         EL3WINDOW(6);
 527         lp->stats.tx_carrier_errors     += inb(ioaddr + 0);
 528         lp->stats.tx_heartbeat_errors   += inb(ioaddr + 1);
 529         /* Multiple collisions. */              inb(ioaddr + 2);
 530         lp->stats.collisions                    += inb(ioaddr + 3);
 531         lp->stats.tx_window_errors              += inb(ioaddr + 4);
 532         lp->stats.rx_fifo_errors                += inb(ioaddr + 5);
 533         lp->stats.tx_packets                    += inb(ioaddr + 6);
 534         lp->stats.rx_packets                    += inb(ioaddr + 7);
 535         /* Tx deferrals */                              inb(ioaddr + 8);
 536         inw(ioaddr + 10);       /* Total Rx and Tx octets. */
 537         inw(ioaddr + 12);
 538 
 539         /* Back to window 1, and turn statistics back on. */
 540         EL3WINDOW(1);
 541         outw(0xA800, ioaddr + EL3_CMD);
 542         return;
 543 }
 544 
 545 static int
 546 el3_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 547 {
 548         struct el3_private *lp = (struct el3_private *)dev->priv;
 549         int ioaddr = dev->base_addr;
 550         short rx_status;
 551 
 552         if (el3_debug > 5)
 553                 printk("           In rx_packet(), status %4.4x, rx_status %4.4x.\n",
 554                            inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
 555         while ((rx_status = inw(ioaddr + RX_STATUS)) > 0) {
 556                 if (rx_status & 0x4000) { /* Error, update stats. */
 557                         short error = rx_status & 0x3800;
 558                         lp->stats.rx_errors++;
 559                         switch (error) {
 560                         case 0x0000:            lp->stats.rx_over_errors++; break;
 561                         case 0x0800:            lp->stats.rx_length_errors++; break;
 562                         case 0x1000:            lp->stats.rx_frame_errors++; break;
 563                         case 0x1800:            lp->stats.rx_length_errors++; break;
 564                         case 0x2000:            lp->stats.rx_frame_errors++; break;
 565                         case 0x2800:            lp->stats.rx_crc_errors++; break;
 566                         }
 567                 }
 568                 if ( (! (rx_status & 0x4000))
 569                         || ! (rx_status & 0x1000)) { /* Dribble bits are OK. */
 570                         short pkt_len = rx_status & 0x7ff;
 571                         int sksize = sizeof(struct sk_buff) + pkt_len + 3;
 572                         struct sk_buff *skb;
 573 
 574                         skb = alloc_skb(sksize, GFP_ATOMIC);
 575                         if (el3_debug > 4)
 576                                 printk("           Receiving packet size %d status %4.4x.\n",
 577                                            pkt_len, rx_status);
 578                         if (skb != NULL) {
 579                                 skb->mem_len = sksize;
 580                                 skb->mem_addr = skb;
 581                                 skb->len = pkt_len;
 582                                 skb->dev = dev;
 583 
 584                                 /* 'skb->data' points to the start of sk_buff data area. */
 585                                 insl(ioaddr+RX_FIFO, skb->data,
 586                                                         (pkt_len + 3) >> 2);
 587 
 588 #ifdef HAVE_NETIF_RX
 589                                 netif_rx(skb);
 590                                 outw(0x4000, ioaddr + EL3_CMD); /* Rx discard */
 591                                 continue;
 592 #else
 593                                 skb->lock = 0;
 594                                 if (dev_rint((unsigned char *)skb, pkt_len,
 595                                                          IN_SKBUFF,dev)== 0){
 596                                         if (el3_debug > 6)
 597                                                 printk("         dev_rint() happy, status %4.4x.\n",
 598                                                 inb(ioaddr + EL3_STATUS));
 599                                         outw(0x4000, ioaddr + EL3_CMD); /* Rx discard */
 600                                         while (inw(ioaddr + EL3_STATUS) & 0x1000)
 601                                           printk("      Waiting for 3c509 to discard packet, status %x.\n",
 602                                                          inw(ioaddr + EL3_STATUS) );
 603                                         if (el3_debug > 6)
 604                                                 printk("         discarded packet, status %4.4x.\n",
 605                                                 inb(ioaddr + EL3_STATUS));
 606                                         continue;
 607                                 } else {
 608                                         printk("%s: receive buffers full.\n", dev->name);
 609                                         kfree_s(skb, sksize);
 610                                 }
 611 #endif
 612                         } else if (el3_debug)
 613                                 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
 614                                            dev->name, sksize);
 615                 }
 616                 lp->stats.rx_dropped++;
 617                 outw(0x4000, ioaddr + EL3_CMD); /* Rx discard */
 618                 while (inw(ioaddr + EL3_STATUS) & 0x1000)
 619                   printk("      Waiting for 3c509 to discard packet, status %x.\n",
 620                                  inw(ioaddr + EL3_STATUS) );
 621         }
 622 
 623         if (el3_debug > 5)
 624                 printk("           Exiting rx_packet(), status %4.4x, rx_status %4.4x.\n",
 625                            inw(ioaddr+EL3_STATUS), inw(ioaddr+8));
 626 
 627         return 0;
 628 }
 629 
 630 #ifdef HAVE_MULTICAST
 631 /* Set or clear the multicast filter for this adaptor.
 632    num_addrs == -1              Promiscuous mode, receive all packets
 633    num_addrs == 0               Normal mode, clear multicast list
 634    num_addrs > 0                Multicast mode, receive normal and MC packets, and do
 635                                                 best-effort filtering.
 636  */
 637 static void
 638 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
 639 {
 640         short ioaddr = dev->base_addr;
 641         if (num_addrs > 0) {
 642                 outw(0x8007, ioaddr + EL3_CMD);
 643         } else if (num_addrs < 0) {
 644                 outw(0x8008, ioaddr + EL3_CMD);
 645         } else
 646                 outw(0x8005, ioaddr + EL3_CMD);
 647 }
 648 #endif
 649 
 650 static int
 651 el3_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 652 {
 653         int ioaddr = dev->base_addr;
 654 
 655         if (el3_debug > 2)
 656                 printk("%s: Shutting down ethercard.\n", dev->name);
 657 
 658         dev->tbusy = 1;
 659         dev->start = 0;
 660 
 661         /* Turn off statistics.  We update lp->stats below. */
 662         outw(0xB000, ioaddr + EL3_CMD);
 663 
 664         /* Disable the receiver and transmitter. */
 665         outw(0x1800, ioaddr + EL3_CMD);
 666         outw(0x5000, ioaddr + EL3_CMD);
 667 
 668         if (dev->if_port == 3)
 669                 /* Turn off thinnet power. */
 670                 outw(0xb800, ioaddr + EL3_CMD);
 671         else if (dev->if_port == 0) {
 672                 /* Disable link beat and jabber, if_port may change ere next open(). */
 673                 EL3WINDOW(4);
 674                 outw(inw(ioaddr + WN4_MEDIA) & ~MEDIA_TP, ioaddr + WN4_MEDIA);
 675         }
 676 
 677         free_irq(dev->irq);
 678         /* Switching back to window 0 disables the IRQ. */
 679         EL3WINDOW(0);
 680         /* But we explicitly zero the IRQ line select anyway. */
 681         outw(0x0f00, ioaddr + 8);
 682 
 683 
 684         irq2dev_map[dev->irq] = 0;
 685 
 686         update_stats(ioaddr, dev);
 687         return 0;
 688 }
 689 
 690 /*
 691  * Local variables:
 692  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c 3c509.c"
 693  *  version-control: t
 694  *  kept-new-versions: 5
 695  *  tab-width: 4
 696  * End:
 697  */

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