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. */
  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+1, 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 = %d) 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, (void *)(skb+1), (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                         break;
 481                 }
 482                 /* Clear the other interrupts we have handled. */
 483                 outw(0x6899, ioaddr + EL3_CMD); /* Ack IRQ */
 484         }
 485 
 486         if (el3_debug > 4) {
 487                 printk("%s: exiting interrupt, status %4.4x.\n", dev->name,
 488                            inw(ioaddr + EL3_STATUS));
 489         }
 490         
 491         dev->interrupt = 0;
 492         return;
 493 }
 494 
 495 
 496 static struct enet_statistics *
 497 el3_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 498 {
 499         struct el3_private *lp = (struct el3_private *)dev->priv;
 500 
 501         sti();
 502         update_stats(dev->base_addr, dev);
 503         cli();
 504         return &lp->stats;
 505 }
 506 
 507 /*  Update statistics.  We change to register window 6, so this should be run
 508         single-threaded if the device is active. This is expected to be a rare
 509         operation, and it's simpler for the rest of the driver to assume that
 510         window 1 is always valid rather than use a special window-state variable.
 511         */
 512 static void update_stats(int ioaddr, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 513 {
 514         struct el3_private *lp = (struct el3_private *)dev->priv;
 515 
 516         if (el3_debug > 5)
 517                 printk("   Updating the statistics.\n");
 518         /* Turn off statistics updates while reading. */
 519         outw(0xB000, ioaddr + EL3_CMD);
 520         /* Switch to the stats window, and read everything. */
 521         EL3WINDOW(6);
 522         lp->stats.tx_carrier_errors     += inb(ioaddr + 0);
 523         lp->stats.tx_heartbeat_errors   += inb(ioaddr + 1);
 524         /* Multiple collisions. */              inb(ioaddr + 2);
 525         lp->stats.collisions                    += inb(ioaddr + 3);
 526         lp->stats.tx_window_errors              += inb(ioaddr + 4);
 527         lp->stats.rx_fifo_errors                += inb(ioaddr + 5);
 528         lp->stats.tx_packets                    += inb(ioaddr + 6);
 529         lp->stats.rx_packets                    += inb(ioaddr + 7);
 530         /* Tx deferrals */                              inb(ioaddr + 8);
 531         inw(ioaddr + 10);       /* Total Rx and Tx octets. */
 532         inw(ioaddr + 12);
 533 
 534         /* Back to window 1, and turn statistics back on. */
 535         EL3WINDOW(1);
 536         outw(0xA800, ioaddr + EL3_CMD);
 537         return;
 538 }
 539 
 540 static int
 541 el3_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 542 {
 543         struct el3_private *lp = (struct el3_private *)dev->priv;
 544         int ioaddr = dev->base_addr;
 545         short rx_status;
 546 
 547         if (el3_debug > 5)
 548                 printk("           In rx_packet(), status %4.4x, rx_status %4.4x.\n",
 549                            inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
 550         while ((rx_status = inw(ioaddr + RX_STATUS)) > 0) {
 551                 if (rx_status & 0x4000) { /* Error, update stats. */
 552                         short error = rx_status & 0x3C00;
 553                         lp->stats.rx_errors++;
 554                         switch (error) {
 555                         case 0x2000:            lp->stats.rx_over_errors++; break;
 556                         case 0x2C00:            lp->stats.rx_length_errors++; break;
 557                         case 0x3400:            lp->stats.rx_crc_errors++; break;
 558                         case 0x2400:            lp->stats.rx_length_errors++; break;
 559                         case 0x3000:            lp->stats.rx_frame_errors++; break;
 560                         case 0x0800:            lp->stats.rx_frame_errors++; break;
 561                         }
 562                 }
 563                 if ( (! (rx_status & 0x4000))
 564                         || ! (rx_status & 0x2000)) { /* Dribble bits are OK. */
 565                         short pkt_len = rx_status & 0x7ff;
 566                         int sksize = sizeof(struct sk_buff) + pkt_len + 3;
 567                         struct sk_buff *skb;
 568 
 569                         skb = alloc_skb(sksize, GFP_ATOMIC);
 570                         if (el3_debug > 4)
 571                                 printk("           Receiving packet size %d status %4.4x.\n",
 572                                            pkt_len, rx_status);
 573                         if (skb != NULL) {
 574                                 skb->mem_len = sksize;
 575                                 skb->mem_addr = skb;
 576                                 skb->len = pkt_len;
 577                                 skb->dev = dev;
 578 
 579                                 /* 'skb+1' points to the start of sk_buff data area. */
 580                                 insl(ioaddr+RX_FIFO, (void *)(skb+1),
 581                                                         (pkt_len + 3) >> 2);
 582 
 583 #ifdef HAVE_NETIF_RX
 584                                 netif_rx(skb);
 585                                 outw(0x4000, ioaddr + EL3_CMD); /* Rx discard */
 586                                 continue;
 587 #else
 588                                 skb->lock = 0;
 589                                 if (dev_rint((unsigned char *)skb, pkt_len,
 590                                                          IN_SKBUFF,dev)== 0){
 591                                         if (el3_debug > 6)
 592                                                 printk("         dev_rint() happy, status %4.4x.\n",
 593                                                 inb(ioaddr + EL3_STATUS));
 594                                         outw(0x4000, ioaddr + EL3_CMD); /* Rx discard */
 595                                         while (inw(ioaddr + EL3_STATUS) & 0x1000)
 596                                           printk("      Waiting for 3c509 to discard packet, status %x.\n",
 597                                                          inw(ioaddr + EL3_STATUS) );
 598                                         if (el3_debug > 6)
 599                                                 printk("         discarded packet, status %4.4x.\n",
 600                                                 inb(ioaddr + EL3_STATUS));
 601                                         continue;
 602                                 } else {
 603                                         printk("%s: receive buffers full.\n", dev->name);
 604                                         kfree_s(skb, sksize);
 605                                 }
 606 #endif
 607                         } else if (el3_debug)
 608                                 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
 609                                            dev->name, sksize);
 610                 }
 611                 lp->stats.rx_dropped++;
 612                 outw(0x4000, ioaddr + EL3_CMD); /* Rx discard */
 613                 while (inw(ioaddr + EL3_STATUS) & 0x1000)
 614                   printk("      Waiting for 3c509 to discard packet, status %x.\n",
 615                                  inw(ioaddr + EL3_STATUS) );
 616         }
 617 
 618         if (el3_debug > 5)
 619                 printk("           Exiting rx_packet(), status %4.4x, rx_status %4.4x.\n",
 620                            inw(ioaddr+EL3_STATUS), inw(ioaddr+8));
 621 
 622         return 0;
 623 }
 624 
 625 #ifdef HAVE_MULTICAST
 626 /* Set or clear the multicast filter for this adaptor.
 627    num_addrs == -1              Promiscuous mode, receive all packets
 628    num_addrs == 0               Normal mode, clear multicast list
 629    num_addrs > 0                Multicast mode, receive normal and MC packets, and do
 630                                                 best-effort filtering.
 631  */
 632 static void
 633 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
 634 {
 635         short ioaddr = dev->base_addr;
 636         if (num_addrs > 0) {
 637                 outw(0x8007, ioaddr + EL3_CMD);
 638         } else if (num_addrs < 0) {
 639                 outw(0x8008, ioaddr + EL3_CMD);
 640         } else
 641                 outw(0x8005, ioaddr + EL3_CMD);
 642 }
 643 #endif
 644 
 645 static int
 646 el3_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 647 {
 648         int ioaddr = dev->base_addr;
 649 
 650         if (el3_debug > 2)
 651                 printk("%s: Shutting down ethercard.\n", dev->name);
 652 
 653         dev->tbusy = 1;
 654         dev->start = 0;
 655 
 656         /* Turn off statistics.  We update lp->stats below. */
 657         outw(0xB000, ioaddr + EL3_CMD);
 658 
 659         /* Disable the receiver and transmitter. */
 660         outw(0x1800, ioaddr + EL3_CMD);
 661         outw(0x5000, ioaddr + EL3_CMD);
 662 
 663         if (dev->if_port == 3)
 664                 /* Turn off thinnet power. */
 665                 outw(0xb800, ioaddr + EL3_CMD);
 666         else if (dev->if_port == 0) {
 667                 /* Disable link beat and jabber, if_port may change ere next open(). */
 668                 EL3WINDOW(4);
 669                 outw(inw(ioaddr + WN4_MEDIA) & ~MEDIA_TP, ioaddr + WN4_MEDIA);
 670         }
 671 
 672         free_irq(dev->irq);
 673         /* Switching back to window 0 disables the IRQ. */
 674         EL3WINDOW(0);
 675         /* But we explicitly zero the IRQ line select anyway. */
 676         outw(0x0f00, ioaddr + 8);
 677 
 678 
 679         irq2dev_map[dev->irq] = 0;
 680 
 681         update_stats(ioaddr, dev);
 682         return 0;
 683 }
 684 
 685 /*
 686  * Local variables:
 687  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c 3c509.c"
 688  *  version-control: t
 689  *  kept-new-versions: 5
 690  *  tab-width: 4
 691  * End:
 692  */

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