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

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