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

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