root/net/inet/lance.c

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

DEFINITIONS

This source file includes following definitions.
  1. at1500_probe
  2. at1500_probe1
  3. lance_open
  4. lance_init_ring
  5. lance_start_xmit
  6. lance_interrupt
  7. lance_rx
  8. lance_close
  9. lance_get_stats

   1 /* lance.c: An AMD LANCE 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 Allied Telesis AT1500, and should work with
  11     NE2100 clones.
  12 
  13     The author may be reached as becker@super.org or
  14     C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715
  15 */
  16 
  17 static char *version = "lance.c:v0.12 9/3/93 becker@super.org\n";
  18 
  19 #include <linux/config.h>
  20 #include <linux/kernel.h>
  21 #include <linux/sched.h>
  22 #include <linux/string.h>
  23 /*#include <linux/interrupt.h>*/
  24 #include <linux/ptrace.h>
  25 #include <linux/errno.h>
  26 #include <linux/ioport.h>
  27 #include <asm/io.h>
  28 #include <asm/dma.h>
  29 /*#include <asm/system.h>*/
  30 
  31 #include "dev.h"
  32 #include "iow.h"
  33 #include "eth.h"
  34 #include "skbuff.h"
  35 #include "arp.h"
  36 
  37 #ifndef HAVE_AUTOIRQ
  38 /* From auto_irq.c, should be in a *.h file. */
  39 extern void autoirq_setup(int waittime);
  40 extern int autoirq_report(int waittime);
  41 extern struct device *irq2dev_map[16];
  42 #endif
  43 
  44 #ifdef LANCE_DEBUG
  45 int lance_debug = LANCE_DEBUG;
  46 #else
  47 int lance_debug = 1;
  48 #endif
  49 
  50 #ifndef DEFAULT_DMA
  51 #define DEFAULT_DMA     5
  52 #endif
  53 
  54 /* Bitfield in the high bits of init block ring buffer. */
  55 #define RING_LEN_BITS   0x80000000
  56 #define RING_MOD_MASK   0x0f
  57 #define RING_SIZE       16
  58 
  59 
  60 /* Offsets from base I/O address. */
  61 #define LANCE_DATA 0x10
  62 #define LANCE_ADDR 0x12
  63 #define LANCE_RESET 0x14
  64 #define LANCE_BUS_IF 0x16
  65 #define LANCE_TOTAL_SIZE 0x18
  66 
  67 /* The LANCE Rx and Tx ring descriptors. */
  68 struct lance_rx_head {
  69     int base;
  70     short buf_length;           /* This length is 2's complement (negative)! */
  71     short msg_length;           /* This length is "normal". */
  72 };
  73 
  74 struct lance_tx_head {
  75     int   base;
  76     short length;               /* Length is 2's complement (negative)! */
  77     short misc;
  78 };
  79 
  80 /* The LANCE initialization block, described in databook. */
  81 struct lance_init {
  82     unsigned short mode;        /* Pre-set mode (reg. 15) */
  83     unsigned char phys_addr[6]; /* Physical ethernet address */
  84     unsigned filter[2];         /* Multicast filter (unused). */
  85     /* Receive and transmit ring base, along with extra bits. */
  86     unsigned rx_ring;           /* Tx and Rx ring base pointers */
  87     unsigned tx_ring;
  88 };
  89 
  90 struct lance_private {
  91     /* These must aligned on 8-byte boundaries. */
  92     struct lance_rx_head rx_ring[RING_SIZE];
  93     struct lance_tx_head tx_ring[RING_SIZE];
  94     struct lance_init   init_block;
  95     int cur_rx, cur_tx;         /* The next free ring entry */
  96     int dirty_rx, dirty_tx;     /* The ring entries to be free()ed. */
  97     int dma;
  98     struct enet_statistics stats;
  99     int pad0, pad1;             /* Used for alignment */
 100 };
 101 
 102 /* We need a ethercard low-memory allocation scheme for for bus-master or
 103    DMA ethercards if they are to work >16M memory systems. This is a
 104    temporary solution to the lack of one, but it limits us to a single
 105    AT1500 and <16M. Bummer. */
 106 
 107 #define PKT_BUF_SZ      1550
 108 static char rx_buffs[PKT_BUF_SZ][RING_SIZE];
 109 
 110 int at1500_probe1(struct device *dev);
 111 static int lance_open(struct device *dev);
 112 static void lance_init_ring(struct device *dev);
 113 static int lance_start_xmit(struct sk_buff *skb, struct device *dev);
 114 static int lance_rx(struct device *dev);
 115 static void lance_interrupt(int reg_ptr);
 116 static int lance_close(struct device *dev);
 117 static struct enet_statistics *lance_get_stats(struct device *dev);
 118 
 119 #ifdef notdef
 120 static struct sigaction lance_sigaction = { &lance_interrupt, 0, 0, NULL, };
 121 #endif
 122 
 123 
 124 
 125 int at1500_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 126 {
 127     int *port, ports[] = {0x300, 0x320, 0x340, 0x360, 0};
 128     int base_addr = dev->base_addr;
 129 
 130     if (base_addr < 0)
 131         return ENXIO;           /* Don't probe at all. */
 132     if (base_addr > 0x100)      /* Check a single specified location. */
 133         return at1500_probe1(dev);
 134 
 135     /* First probe for the ethercard ID, 0x57, and then look for a LANCE
 136        chip. */
 137     
 138     for (port = &ports[0]; *port; port++) {
 139         int probe_addr = *port;
 140         short temp;
 141 
 142 #ifdef HAVE_PORTRESERVE
 143         if (check_region(probe_addr, LANCE_TOTAL_SIZE))
 144             continue;
 145 #endif
 146         if (inb(probe_addr + 14) != 0x57
 147             || inb(probe_addr + 15) != 0x57)
 148             continue;
 149 
 150         /* Reset the LANCE. Un-Reset needed only for the real NE2100. */
 151         temp = inw(probe_addr+LANCE_RESET); /* Reset the LANCE */
 152         outw(temp, probe_addr+LANCE_RESET);     /* "Un-reset" */
 153         
 154         outw(0x0000, probe_addr+LANCE_ADDR); /* Switch to window 0 */
 155         if (inw(probe_addr+LANCE_DATA) != 0x0004)
 156             continue;
 157         dev->base_addr = probe_addr;
 158         if (at1500_probe1(dev) == 0)
 159             return 0;
 160     }
 161 
 162     dev->base_addr = base_addr;
 163     return ENODEV;                      /* ENODEV would be more accurate. */
 164 }
 165 
 166 int
 167 at1500_probe1(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 168 {
 169     struct lance_private *lp;
 170     short ioaddr = dev->base_addr;
 171 
 172     int i;
 173 
 174     printk("%s: LANCE at %#3x, address", dev->name, ioaddr);
 175 
 176     /* There is a 16 byte station address PROM at the base address.
 177        The first six bytes are the station address. */
 178     for (i = 0; i < 6; i++)
 179         printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i));
 180 
 181     /* Reset the LANCE */
 182     inw(ioaddr+LANCE_RESET);
 183 
 184     /* Make up a LANCE-specific-data structure. */
 185     dev->priv = kmalloc(sizeof(struct lance_private), GFP_KERNEL);
 186     /* Align on 8-byte boundary. */
 187     dev->priv = (void *)(((int)dev->priv + 7) & ~0x07);
 188 
 189     if ((int)dev->priv & 0xff000000  ||  (int) rx_buffs & 0xff000000) {
 190         printk(" disabled (buff %#x > 16M).\n", (int)rx_buffs);
 191         return -ENOMEM;
 192     }
 193 
 194     memset(dev->priv, 0, sizeof(struct lance_private));
 195     lp = (struct lance_private *)dev->priv;
 196 
 197     if ((int)(lp->rx_ring) & 0x07)
 198         printk("%s: LANCE Rx and Tx rings not on even boundary.\n",
 199                dev->name);
 200 
 201     /* Un-Reset the LANCE, needed only for the NE2100. */
 202     outw(0, ioaddr+LANCE_RESET);
 203 
 204     lp->init_block.mode = 0x0003;       /* Disable Rx and Tx. */
 205     for (i = 0; i < 6; i++)
 206         lp->init_block.phys_addr[i] = dev->dev_addr[i];
 207     lp->init_block.filter[0] = 0x00000000;
 208     lp->init_block.filter[1] = 0x00000000;
 209     lp->init_block.rx_ring = (int)lp->rx_ring | RING_LEN_BITS;
 210     lp->init_block.tx_ring = (int)lp->tx_ring | RING_LEN_BITS;
 211 
 212     outw(0x0001, ioaddr+LANCE_ADDR);
 213     outw((short) (int) &lp->init_block, ioaddr+LANCE_DATA);
 214     outw(0x0002, ioaddr+LANCE_ADDR);
 215     outw(((int)&lp->init_block) >> 16, ioaddr+LANCE_DATA);
 216     outw(0x0000, ioaddr+LANCE_ADDR);
 217 
 218     /* To auto-IRQ we enable the initialization-done and DMA err,
 219        interrupts. For now we will always get a DMA error. */
 220     if (dev->irq < 2) {
 221         autoirq_setup(0);
 222 
 223         /* Trigger an initialization just for the interrupt. */
 224         outw(0x0041, ioaddr+LANCE_DATA);
 225 
 226         dev->irq = autoirq_report(1);
 227         if (dev->irq)
 228             printk(", using IRQ %d.\n", dev->irq);
 229         else {
 230             printk(", failed to detect IRQ line.\n");
 231             return -EAGAIN;
 232         }
 233     } else
 234         printk(" assigned IRQ %d.\n", dev->irq);
 235 
 236     /* The DMA channel may be passed in on this parameter. */
 237     dev->dma = dev->mem_start & 0x07;
 238 
 239 #ifndef NE2100                  /* The NE2100 might not understand */
 240     /* Turn on auto-select of media (10baseT or BNC) so that the user
 241        can watch the LEDs even if the board isn't opened. */
 242     outw(0x0002, ioaddr+LANCE_ADDR);
 243     outw(0x0002, ioaddr+LANCE_BUS_IF);
 244 #endif
 245 
 246 #ifdef HAVE_PORTRESERVE
 247     snarf_region(ioaddr, LANCE_TOTAL_SIZE);
 248 #endif
 249 
 250     if (lance_debug > 0)
 251         printk(version);
 252 
 253     /* The LANCE-specific entries in the device structure. */
 254     dev->open = &lance_open;
 255     dev->hard_start_xmit = &lance_start_xmit;
 256     dev->stop = &lance_close;
 257     dev->get_stats = &lance_get_stats;
 258 
 259     dev->mem_start = 0;
 260 
 261     /* Fill in the generic field of the device structure. */
 262     for (i = 0; i < DEV_NUMBUFFS; i++)
 263         dev->buffs[i] = NULL;
 264 
 265     dev->hard_header    = eth_header;
 266     dev->add_arp        = eth_add_arp;
 267     dev->queue_xmit     = dev_queue_xmit;
 268     dev->rebuild_header = eth_rebuild_header;
 269     dev->type_trans     = eth_type_trans;
 270 
 271     dev->type           = ARPHRD_ETHER;
 272     dev->hard_header_len = ETH_HLEN;
 273     dev->mtu            = 1500; /* eth_mtu */
 274     dev->addr_len       = ETH_ALEN;
 275     for (i = 0; i < dev->addr_len; i++) {
 276         dev->broadcast[i]=0xff;
 277     }
 278 
 279     /* New-style flags. */
 280     dev->flags          = IFF_BROADCAST;
 281     dev->family         = AF_INET;
 282     dev->pa_addr        = 0;
 283     dev->pa_brdaddr     = 0;
 284     dev->pa_mask        = 0;
 285     dev->pa_alen        = sizeof(unsigned long);
 286 
 287     return 0;
 288 }
 289 
 290 
 291 static int
 292 lance_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 293 {
 294     struct lance_private *lp = (struct lance_private *)dev->priv;
 295     int ioaddr = dev->base_addr;
 296     int i;
 297 
 298     if (request_irq(dev->irq, &lance_interrupt)) {
 299         return -EAGAIN;
 300     }
 301 
 302     lp->dma = dev->dma ? dev->dma : DEFAULT_DMA;
 303 
 304     if (request_dma(lp->dma)) {
 305         free_irq(dev->irq);
 306         return -EAGAIN;
 307     }
 308     irq2dev_map[dev->irq] = dev;
 309 
 310     /* Reset the LANCE */
 311     inw(ioaddr+LANCE_RESET);
 312 
 313     /* The DMA controller is used as a no-operation slave, "cascade mode". */
 314     enable_dma(lp->dma);
 315     set_dma_mode(lp->dma, DMA_MODE_CASCADE);
 316 
 317     /* Un-Reset the LANCE, needed only for the NE2100. */
 318     outw(0, ioaddr+LANCE_RESET);
 319 
 320 #ifndef NE2100
 321     /* This is really 79C960-specific, NE2100 might not understand */
 322     /* Turn on auto-select of media (10baseT or BNC). */
 323     outw(0x0002, ioaddr+LANCE_ADDR);
 324     outw(0x0002, ioaddr+LANCE_BUS_IF);
 325 #endif
 326 
 327     if (lance_debug > 1)
 328         printk("%s: lance_open() irq %d dma %d tx/rx rings %#x/%#x init %#x.\n",
 329                dev->name, dev->irq, lp->dma, (int) lp->tx_ring, (int) lp->rx_ring,
 330                (int) &lp->init_block);
 331 
 332     lance_init_ring(dev);
 333     /* Re-initialize the LANCE, and start it when done. */
 334     outw(0x0001, ioaddr+LANCE_ADDR);
 335     outw((short) (int) &lp->init_block, ioaddr+LANCE_DATA);
 336     outw(0x0002, ioaddr+LANCE_ADDR);
 337     outw(((int)&lp->init_block) >> 16, ioaddr+LANCE_DATA);
 338 
 339     outw(0x0004, ioaddr+LANCE_ADDR);
 340     outw(0x0d15, ioaddr+LANCE_DATA);
 341 
 342     outw(0x0000, ioaddr+LANCE_ADDR);
 343     outw(0x0001, ioaddr+LANCE_DATA);
 344 
 345     dev->tbusy = 0;
 346     dev->interrupt = 0;
 347     dev->start = 1;
 348     i = 0;
 349     while (i++ < 100)
 350         if (inw(ioaddr+LANCE_DATA) & 0x0100)
 351             break;
 352     outw(0x0142, ioaddr+LANCE_DATA);
 353 
 354     if (lance_debug > 2)
 355         printk("%s: LANCE open after %d ticks, init block %#x csr0 %4.4x.\n",
 356                dev->name, i, (int) &lp->init_block, inw(ioaddr+LANCE_DATA));
 357 
 358     return 0;                   /* Always succeed */
 359 }
 360 
 361 /* Initialize the LANCE Rx and Tx rings. */
 362 static void
 363 lance_init_ring(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 364 {
 365     struct lance_private *lp = (struct lance_private *)dev->priv;
 366     int i;
 367 
 368     lp->cur_rx = lp->cur_tx = 0;
 369     lp->dirty_rx = lp->dirty_tx = 0;
 370 
 371     for (i = 0; i < RING_SIZE; i++) {
 372         lp->rx_ring[i].base = (int) rx_buffs | (0x80000000 + i*PKT_BUF_SZ);
 373         lp->rx_ring[i].buf_length = -PKT_BUF_SZ;
 374         lp->tx_ring[i].base = 0;
 375     }
 376 
 377     lp->init_block.mode = 0x0000;
 378     for (i = 0; i < 6; i++)
 379         lp->init_block.phys_addr[i] = dev->dev_addr[i];
 380     lp->init_block.filter[0] = 0x00000000;
 381     lp->init_block.filter[1] = 0x00000000;
 382     lp->init_block.rx_ring = (int)lp->rx_ring | RING_LEN_BITS;
 383     lp->init_block.tx_ring = (int)lp->tx_ring | RING_LEN_BITS;
 384 }
 385 
 386 static int
 387 lance_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 388 {
 389     struct lance_private *lp = (struct lance_private *)dev->priv;
 390     int ioaddr = dev->base_addr;
 391 
 392     /* Transmitter timeout, serious problems. */
 393     if (dev->tbusy) {
 394         int tickssofar = jiffies - dev->trans_start;
 395         if (tickssofar < 5)
 396             return 1;
 397         outw(0, ioaddr+LANCE_ADDR);
 398         printk("%s: transmit timed out, status %4.4x, resetting.\n",
 399                dev->name, inw(ioaddr+LANCE_DATA));
 400 
 401         lance_init_ring(dev);
 402         outw(0x43, ioaddr+LANCE_DATA);
 403 
 404         dev->tbusy=0;
 405         dev->trans_start = jiffies;
 406 
 407         return 0;
 408     }
 409 
 410     if (skb == NULL) {
 411         dev_tint(dev);
 412         return 0;
 413     }
 414 
 415     /* Fill in the ethernet header. */
 416     if (!skb->arp  &&  dev->rebuild_header(skb+1, dev)) {
 417         skb->dev = dev;
 418         arp_queue (skb);
 419         return 0;
 420     }
 421 
 422     if (skb->len <= 0)
 423         return 0;
 424 
 425     if (lance_debug > 3) {
 426         outw(0x0000, ioaddr+LANCE_ADDR);
 427         printk("%s: lance_start_xmit() called, csr0 %4.4x.\n", dev->name,
 428                inw(ioaddr+LANCE_DATA));
 429         outw(0x0000, ioaddr+LANCE_DATA);
 430     }
 431 
 432     /* Avoid timer-based retransmission conflicts. */
 433     dev->tbusy=1;
 434 
 435     /* This code is broken for >16M RAM systems.
 436        There are two ways to fix it:
 437            Keep around several static low-memory buffers, and deal with
 438            the book-keeping (bad for small systems).
 439            Make static Tx buffers that are optionally used.
 440            (Even worse.)
 441      */
 442     {                           /* Fill in a Tx ring entry */
 443         int entry = lp->cur_tx++;
 444 
 445         entry &= RING_MOD_MASK;         /* Ring buffer. */
 446         /* Caution: the write order is important here. */
 447         lp->tx_ring[entry].length = -skb->len;
 448 
 449         /* This shouldn't be necessary... */
 450         lp->tx_ring[entry].length =
 451             -(ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN);
 452 
 453         lp->tx_ring[entry].misc = 0x0000;
 454         lp->tx_ring[entry].base = (int)(skb+1) | 0x83000000;
 455 
 456         /* Trigger an immediate send poll. */
 457         outw(0x0000, ioaddr+LANCE_ADDR);
 458         outw(0x0048, ioaddr+LANCE_DATA);
 459 
 460         if (lance_debug > 4) {
 461             unsigned char *pkt =
 462                 (unsigned char *)(lp->tx_ring[entry].base & 0x00ffffff);
 463 
 464             printk("%s: tx ring[%d], %#x, sk_buf %#x len %d.\n",
 465                    dev->name, entry, (int) &lp->tx_ring[entry],
 466                    lp->tx_ring[entry].base, -lp->tx_ring[entry].length);
 467             printk("%s:  Tx %2.2x %2.2x %2.2x ... %2.2x  %2.2x %2.2x %2.2x...%2.2x len %2.2x %2.2x  %2.2x %2.2x.\n",
 468                    dev->name, pkt[0], pkt[1], pkt[2], pkt[5], pkt[6],
 469                    pkt[7], pkt[8], pkt[11], pkt[12], pkt[13],
 470                    pkt[14], pkt[15]);
 471         }
 472 
 473         dev->trans_start = jiffies;
 474 
 475         if (lp->tx_ring[(entry+1) & RING_MOD_MASK].base >= 0)
 476             dev->tbusy=0;
 477     }
 478 
 479     return 0;
 480 }
 481 
 482 /* The LANCE interrupt handler. */
 483 static void
 484 lance_interrupt(int reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 485 {
 486     int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
 487     struct device *dev = (struct device *)(irq2dev_map[irq]);
 488     struct lance_private *lp;
 489     int csr0, ioaddr;
 490 
 491     if (dev == NULL) {
 492         printk ("lance_interrupt(): irq %d for unknown device.\n", irq);
 493         return;
 494     }
 495 
 496     ioaddr = dev->base_addr;
 497     lp = (struct lance_private *)dev->priv;
 498     if (dev->interrupt)
 499         printk("%s: Re-entering the interrupt handler.\n", dev->name);
 500 
 501     dev->interrupt = 1;
 502 
 503     outw(0x00, dev->base_addr + LANCE_ADDR);
 504     csr0 = inw(dev->base_addr + LANCE_DATA);
 505 
 506     /* Acknowledge all of the current interrupt sources ASAP. */
 507     outw(csr0 & ~0x004f, dev->base_addr + LANCE_DATA);
 508 
 509     if (lance_debug > 5)
 510         printk("%s: interrupt  csr0=%#2.2x new csr=%#2.2x.\n",
 511                dev->name, csr0, inw(dev->base_addr + LANCE_DATA));
 512 
 513     if (csr0 & 0x0400)          /* Rx interrupt */
 514         lance_rx(dev);
 515 
 516     if (csr0 & 0x0200) {        /* Tx-done interrupt */
 517         int dirty_tx = lp->dirty_tx & RING_MOD_MASK;
 518 
 519         if (lance_debug > 5)
 520             printk("%s: Cleaning tx ring, dirty %d clean %d.\n",
 521                    dev->name, dirty_tx, (lp->cur_tx & RING_MOD_MASK));
 522 
 523         /* This code is broken for >16M RAM systems. */
 524         while (dirty_tx != (lp->cur_tx & RING_MOD_MASK)
 525                && lp->tx_ring[dirty_tx].base > 0) {
 526             struct sk_buff *skb =
 527                 (struct sk_buff *)(lp->tx_ring[dirty_tx].base & 0x00ffffff);
 528             unsigned short *tmdp = (unsigned short *)(&lp->tx_ring[dirty_tx]);
 529             int status = lp->tx_ring[dirty_tx].base >> 24;
 530 
 531             if (status & 0x40) { /* There was an major error, log it. */
 532                 int err_status = lp->tx_ring[dirty_tx].misc;
 533                 lp->stats.tx_errors++;
 534                 if (err_status & 0x0400) lp->stats.tx_aborted_errors++;
 535                 if (err_status & 0x0800) lp->stats.tx_carrier_errors++;
 536                 if (err_status & 0x1000) lp->stats.tx_window_errors++;
 537                 if (err_status & 0x4000) lp->stats.tx_fifo_errors++;
 538                 /* We should re-init() after the FIFO error. */
 539             } else if (status & 0x18)
 540                 lp->stats.collisions++;
 541             else
 542                 lp->stats.tx_packets++;
 543             if (lance_debug > 5)
 544                 printk("%s: Tx done entry %d, %4.4x %4.4x %4.4x %4.4x.\n",
 545                        dev->name, dirty_tx,
 546                        tmdp[0], tmdp[1], tmdp[2], tmdp[3]);
 547             if ((skb-1)->free)
 548                 kfree_skb (skb-1, FREE_WRITE);
 549             dirty_tx = ++lp->dirty_tx & RING_MOD_MASK;
 550         }
 551         /* mark_bh(INET_BH); */
 552     }
 553 
 554     /* Clear the interrupts we've handled. */
 555     outw(0x0000, dev->base_addr + LANCE_ADDR);
 556     outw(0x7f40, dev->base_addr + LANCE_DATA);
 557 
 558     if (lance_debug > 4)
 559         printk("%s: exiting interrupt, csr%d=%#4.4x.\n",
 560                dev->name, inw(ioaddr + LANCE_ADDR),
 561                inw(dev->base_addr + LANCE_DATA));
 562 
 563     dev->interrupt = 0;
 564     return;
 565 }
 566 
 567 static int
 568 lance_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 569 {
 570     struct lance_private *lp = (struct lance_private *)dev->priv;
 571     int entry = lp->cur_rx & RING_MOD_MASK;
 572         
 573     /* If we own the next entry, it's a new packet. Send it up. */
 574     while (lp->rx_ring[entry].base >= 0) {
 575         int status = lp->rx_ring[entry].base >> 24;
 576 
 577         if (status & 0x40) {    /* There was an error. */
 578             lp->stats.rx_errors++;
 579             if (status & 0x20) lp->stats.rx_frame_errors++;
 580             if (status & 0x10) lp->stats.rx_over_errors++;
 581             if (status & 0x08) lp->stats.rx_crc_errors++;
 582             if (status & 0x04) lp->stats.rx_fifo_errors++;
 583         } else {
 584             /* Malloc up new buffer, compatible with net-2e. */
 585             short pkt_len = lp->rx_ring[entry].msg_length;
 586             int sksize = sizeof(struct sk_buff) + pkt_len;
 587             struct sk_buff *skb;
 588             skb = (struct sk_buff *) kmalloc(sksize, GFP_ATOMIC);
 589             if (skb == NULL) {
 590                 printk("%s: Memory squeeze, deferring packet.\n", dev->name);
 591                 lp->stats.rx_dropped++; /* Really, deferred. */
 592                 break;
 593             }
 594             skb->mem_len = sksize;
 595             skb->mem_addr = skb;
 596             skb->len = pkt_len;
 597             skb->dev = dev;
 598             memcpy((unsigned char *) (skb + 1),
 599                    (unsigned char *)(lp->rx_ring[entry].base & 0x00ffffff),
 600                    pkt_len);
 601 #ifdef HAVE_NETIF_RX
 602             netif_rx(skb);
 603 #else
 604             skb->lock = 0;
 605             if (dev_rint((unsigned char*)skb, pkt_len, IN_SKBUFF, dev) != 0) {
 606                 kfree_s(skb, sksize);
 607                 lp->stats.rx_dropped++;
 608                 break;
 609             }
 610 #endif
 611             lp->stats.rx_packets++;
 612         }
 613 
 614         lp->rx_ring[entry].base |= 0x80000000;
 615         entry = (entry+1) & RING_MOD_MASK;
 616     }
 617 
 618     /* We should check that at least two ring entries are free.  If not,
 619        we should free one and mark stats->rx_dropped++. */
 620 
 621     lp->cur_rx = entry;
 622 
 623     return 0;
 624 }
 625 
 626 static int
 627 lance_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 628 {
 629     int ioaddr = dev->base_addr;
 630     struct lance_private *lp = (struct lance_private *)dev->priv;
 631 
 632     dev->start = 0;
 633     dev->tbusy = 1;
 634 
 635     outw(112, ioaddr+LANCE_ADDR);
 636     lp->stats.rx_missed_errors = inw(ioaddr+LANCE_DATA);
 637 
 638     outw(0, ioaddr+LANCE_ADDR);
 639 
 640     if (lance_debug > 1)
 641         printk("%s: Shutting down ethercard, status was %2.2x.\n",
 642                dev->name, inw(ioaddr+LANCE_DATA));
 643 
 644     /* We stop the LANCE here -- it occasionally polls
 645        memory if we don't. */
 646     outw(0x0004, ioaddr+LANCE_DATA);
 647 
 648     disable_dma(lp->dma);
 649 
 650     free_irq(dev->irq);
 651     free_dma(lp->dma);
 652 
 653     irq2dev_map[dev->irq] = 0;
 654 
 655     return 0;
 656 }
 657 
 658 static struct enet_statistics *
 659 lance_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 660 {
 661     struct lance_private *lp = (struct lance_private *)dev->priv;
 662     short ioaddr = dev->base_addr;
 663     short saved_addr;
 664 
 665     cli();
 666     saved_addr = inw(ioaddr+LANCE_ADDR);
 667     outw(112, ioaddr+LANCE_ADDR);
 668     lp->stats.rx_missed_errors = inw(ioaddr+LANCE_DATA);
 669     outw(saved_addr, ioaddr+LANCE_ADDR);
 670     sti();
 671 
 672     return &lp->stats;
 673 }
 674 
 675 /*
 676  * Local variables:
 677  *  compile-command: "gcc -D__KERNEL__ -Wall -O6 -x c++ -c lance.c"
 678  * End:
 679  */

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