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

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