root/net/inet/8390.c

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

DEFINITIONS

This source file includes following definitions.
  1. ei_open
  2. ei_start_xmit
  3. ei_interrupt
  4. ei_tx_intr
  5. ei_receive
  6. ei_rx_overrun
  7. get_stats
  8. ethif_init
  9. ethdev_init
  10. NS8390_init
  11. NS8390_trigger_send

   1 /* 8390.c: A general NS8390 ethernet driver core for linux. */
   2 /*
   3     Written 1992,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 is the chip-specific code for many 8390-based ethernet adaptors.
  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 =
  17     "8390.c:v0.99-12 8/9/93 for 0.99.12+ Donald Becker (becker@super.org)\n";
  18 #include <linux/config.h>
  19 #if !defined(EL2) && !defined(NE2000) && !defined(WD80x3) && !defined(HPLAN)
  20 /* They don't know what they want -- give it all to them! */
  21 #define EL2
  22 #define NE2000
  23 #define WD80x3
  24 #define HPLAN
  25 #endif
  26 
  27 /*
  28   Braindamage remaining:
  29 
  30   Ethernet devices should use a chr_drv device interface, with ioctl()s to
  31   configure the card, bring the interface up or down, allow access to
  32   statistics, and maybe read() and write() access to raw packets.
  33   This won't be done until after Linux 1.00.
  34 
  35 Sources:
  36   The National Semiconductor LAN Databook, and the 3Com 3c503 databook.
  37   The NE* programming info came from the Crynwr packet driver, and figuring
  38   out that the those boards are similar to the NatSemi evaluation board
  39   described in AN-729.  Thanks NS, no thanks to Novell/Eagle.
  40   */
  41 
  42 #include <linux/config.h>
  43 #include <linux/kernel.h>
  44 #include <linux/sched.h>
  45 #include <linux/fs.h>
  46 #include <linux/tty.h>
  47 #include <linux/types.h>
  48 #include <linux/ptrace.h>
  49 #include <linux/string.h>
  50 #include <asm/system.h>
  51 #include <asm/segment.h>
  52 #include <asm/io.h>
  53 #include <errno.h>
  54 #include <linux/fcntl.h>
  55 #include <linux/in.h>
  56 #include <linux/interrupt.h>
  57 
  58 #include "dev.h"
  59 #include "eth.h"
  60 #include "ip.h"
  61 #include "protocol.h"
  62 #include "tcp.h"
  63 #include "skbuff.h"
  64 #include "sock.h"
  65 #include "arp.h"
  66 
  67 #include "8390.h"
  68 
  69 #define ei_reset_8390 (ei_local->reset_8390)
  70 #define ei_block_output (ei_local->block_output)
  71 #define ei_block_input (ei_local->block_input)
  72 
  73 /* use 0 for production, 1 for verification, >2 for debug */
  74 #ifdef EI_DEBUG
  75 int ei_debug = EI_DEBUG;
  76 #else
  77 int ei_debug = 1;
  78 #endif
  79 
  80 /* Max number of packets received at one Intr. */
  81 /*static int high_water_mark = 0;*/
  82 
  83 /* Index to functions. */
  84 /* Put in the device structure. */
  85 int ei_open(struct device *dev);
  86 /* Dispatch from interrupts. */
  87 void ei_interrupt(int reg_ptr);
  88 static void ei_tx_intr(struct device *dev);
  89 static void ei_receive(struct device *dev);
  90 static void ei_rx_overrun(struct device *dev);
  91 
  92 /* Routines generic to NS8390-based boards. */
  93 void NS8390_init(struct device *dev, int startp);
  94 static void NS8390_trigger_send(struct device *dev, unsigned int length,
  95                                 int start_page);
  96 
  97 extern int el2autoprobe(int ioaddr, struct device *dev);
  98 extern int el2probe(int ioaddr, struct device *dev);
  99 extern int neprobe(int ioaddr, struct device *dev);
 100 extern int wdprobe(int ioaddr, struct device *dev);
 101 extern int hpprobe(int ioaddr, struct device *dev);
 102 
 103 struct sigaction ei_sigaction = { ei_interrupt, 0, 0, NULL, };
 104 
 105 /* Open/initialize the board.  This routine goes all-out, setting everything
 106    up anew at each open, even though many of these registers should only
 107    need to be set once at boot.
 108    */
 109 int
 110 ei_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 111 {
 112     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 113 
 114     if ( ! ei_local) {
 115         printk("%s: Opening a non-existent physical device\n", dev->name);
 116         return 1;               /* ENXIO would be more accurate. */
 117     }
 118 
 119   irq2dev_map[dev->irq] = dev;
 120   NS8390_init(dev, 1);
 121   ei_local->tx1 = ei_local->tx2 = 0;
 122   /* The old local flags... */
 123   ei_local->txing = 0;
 124   /* ... are now global. */
 125   dev->tbusy = 0;
 126   dev->interrupt = 0;
 127   dev->start = 1;
 128   ei_local->irqlock = 0;
 129   return 0;
 130 }
 131 
 132 static int
 133 ei_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 134 {
 135     int e8390_base = dev->base_addr;
 136     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 137     int length, send_length;
 138     int tmp_tbusy;    /* we must lock dev_tint in dev.c with dev->t_busy =1 */
 139                     /* because on a slow pc a quasi endless loop can appear */
 140 
 141     if (dev->tbusy) {   /* Do timeouts, just like the 8003 driver. */
 142         int txsr = inb(e8390_base+EN0_TSR), isr;
 143         int tickssofar = jiffies - dev->trans_start;
 144         if (tickssofar < 5  ||  (tickssofar < 15 && ! (txsr & ENTSR_PTX))) {
 145             return 1;
 146         }
 147         isr = inb(e8390_base+EN0_ISR);
 148         printk("%s: transmit timed out, TX status %#2x, ISR %#2x.\n",
 149                 dev->name, txsr, isr);
 150         /* It's possible to check for an IRQ conflict here.
 151            I may have to do that someday. */
 152         if (isr)
 153             printk("%s: Possible IRQ conflict on IRQ%d?", dev->name, dev->irq);
 154         else
 155             printk("%s: Possible network cable problem?\n", dev->name);
 156         /* It futile, but try to restart it anyway. */
 157         ei_reset_8390(dev);
 158         NS8390_init(dev, 1);
 159         printk("\n");
 160     }
 161 
 162     /* This is new: it means some higher layer thinks we've missed an
 163        tx-done interrupt. Caution: dev_tint() handles the cli()/sti()
 164        itself. */
 165     if (skb == NULL) {
 166         dev_tint(dev);
 167         return 0;
 168     }
 169     /* Fill in the ethernet header. */
 170     if (!skb->arp  &&  dev->rebuild_header(skb+1, dev)) {
 171         skb->dev = dev;
 172         arp_queue (skb);
 173         return 0;
 174     }
 175 
 176     if (skb->len <= 0)
 177         return 0;
 178     length = skb->len;
 179     send_length = ETH_ZLEN < length ? length : ETH_ZLEN;
 180     /* Turn off interrupts so that we can put the packet out safely. */
 181     cli();
 182     if (dev->interrupt || ei_local->irqlock) {
 183         /* We should never get here during an interrupt after 0.99.4. */
 184         sti();
 185         if (ei_debug > 2)
 186             printk("%s: Attempt to reenter critical zone%s.\n",
 187                    dev->name, ei_local->irqlock ? " during interrupt" : "");
 188         return 1;
 189     }
 190     outb(0x00,  e8390_base + EN0_IMR);
 191     tmp_tbusy=dev->tbusy;
 192     dev->tbusy = 1;                   /* lock dev_tint() in dev.c */
 193     ei_local->irqlock = 1;
 194     sti();
 195     if (ei_local->pingpong) {
 196         int output_page;
 197         if (ei_local->tx1 == 0) {
 198             output_page = ei_local->tx_start_page;
 199             ei_local->tx1 = send_length;
 200             if (ei_debug  &&  ei_local->tx2 > 0)
 201                 printk("%s: idle transmitter tx2=%d, lasttx=%d, txing=%d.\n",
 202                        dev->name, ei_local->tx2, ei_local->lasttx,
 203                        ei_local->txing);
 204         } else if (ei_local->tx2 == 0) {
 205             output_page = ei_local->tx_start_page + 6;
 206             ei_local->tx2 = send_length;
 207             if (ei_debug  &&  ei_local->tx1 > 0)
 208                 printk("%s: idle transmitter, tx1=%d, lasttx=%d, txing=%d.\n",
 209                        dev->name, ei_local->tx1, ei_local->lasttx,
 210                        ei_local->txing);
 211         } else {
 212             /* We can get to here if we get an rx interrupt and queued
 213                a tx packet just before masking 8390 irqs above. */
 214             if (ei_debug > 2)
 215                 printk("%s: No packet buffer space for ping-pong use.\n",
 216                        dev->name);
 217             cli();
 218             ei_local->irqlock = 0;
 219             dev->tbusy = tmp_tbusy;
 220             outb_p(ENISR_ALL,  e8390_base + EN0_IMR);
 221             sti();
 222             return 1;
 223         }
 224         dev->trans_start = jiffies;
 225         ei_block_output(dev, length, (unsigned char *)(skb+1), output_page);
 226         if (! ei_local->txing) {
 227             NS8390_trigger_send(dev, send_length, output_page);
 228             if (output_page == ei_local->tx_start_page)
 229                 ei_local->tx1 = -1, ei_local->lasttx = -1;
 230             else
 231                 ei_local->tx2 = -1, ei_local->lasttx = -2;
 232             ei_local->txing = 1;
 233         } else
 234             ei_local->txqueue++;
 235         if (ei_local->tx1  &&  ei_local->tx2)
 236             tmp_tbusy = 1;
 237     } else {
 238         dev->trans_start = jiffies;
 239         ei_block_output(dev, length, (unsigned char *)(skb+1),
 240                         ei_local->tx_start_page);
 241         NS8390_trigger_send(dev, send_length, ei_local->tx_start_page);
 242         tmp_tbusy = 1;
 243     }  /* PINGPONG */
 244 
 245     if (skb->free)
 246         kfree_skb (skb, FREE_WRITE);
 247 
 248     /* Turn 8390 interrupts back on. */
 249     cli();
 250     outb_p(ENISR_ALL,  e8390_base + EN0_IMR);
 251     ei_local->irqlock = 0;
 252     dev->tbusy=tmp_tbusy;
 253     sti();
 254     return 0;
 255 }
 256 
 257 /* The typical workload of the driver:
 258    Handle the ether interface interrupts. */
 259 void
 260 ei_interrupt(int reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 261 {
 262     int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
 263     struct device *dev = irq2dev_map[irq];
 264     int e8390_base;
 265     int interrupts, boguscount = 0;
 266     struct ei_device *ei_local;
 267 
 268     if (dev == NULL) {
 269         printk ("net_interrupt(): irq %d for unknown device.\n", irq);
 270         return;
 271     }
 272     e8390_base = dev->base_addr;
 273     ei_local = (struct ei_device *) dev->priv;
 274     if (dev->interrupt || ei_local->irqlock) {
 275         /* The "irqlock" check is only for testing. */
 276         sti();
 277         printk(ei_local->irqlock
 278                ? "%s: Interrupted while interrupts are masked! isr=%#2x imr=%#2x.\n"
 279                : "%s: Reentering the interrupt handler! isr=%#2x imr=%#2x.\n",
 280                dev->name, inb_p(e8390_base + EN0_ISR),
 281                inb_p(e8390_base + EN0_IMR));
 282         return;
 283     }
 284 
 285     dev->interrupt = 1;
 286     sti(); /* Allow other interrupts. */
 287 
 288     /* Change to page 0 and read the intr status reg. */
 289     outb_p(E8390_NODMA+E8390_PAGE0, e8390_base + E8390_CMD);
 290     if (ei_debug > 3)
 291         printk("%s: interrupt(isr=%#2.2x).\n", dev->name,
 292                inb_p(e8390_base + EN0_ISR));
 293 
 294     /* !!Assumption!! -- we stay in page 0.  Don't break this. */
 295     while ((interrupts = inb_p(e8390_base + EN0_ISR)) != 0
 296            && ++boguscount < 20) {
 297         if (interrupts & ENISR_RDC) {
 298             /* Ack meaningless DMA complete. */
 299             outb_p(ENISR_RDC, e8390_base + EN0_ISR);
 300         }
 301         if (interrupts & ENISR_OVER) {
 302             ei_rx_overrun(dev);
 303         } else if (interrupts & (ENISR_RX+ENISR_RX_ERR)) {
 304             /* Got a good (?) packet. */
 305             ei_receive(dev);
 306         }
 307         /* Push the next to-transmit packet through. */
 308         if (interrupts & ENISR_TX) {
 309             ei_tx_intr(dev);
 310         } else if (interrupts & ENISR_COUNTERS) {
 311             struct ei_device *ei_local = (struct ei_device *) dev->priv;
 312             ei_local->stat.rx_frame_errors += inb_p(e8390_base + EN0_COUNTER0);
 313             ei_local->stat.rx_crc_errors   += inb_p(e8390_base + EN0_COUNTER1);
 314             ei_local->stat.rx_missed_errors+= inb_p(e8390_base + EN0_COUNTER2);
 315             outb_p(ENISR_COUNTERS, e8390_base + EN0_ISR); /* Ack intr. */
 316         }
 317 
 318         /* Ignore the transmit errs and reset intr for now. */
 319         if (interrupts & ENISR_TX_ERR) {
 320             outb_p(ENISR_TX_ERR, e8390_base + EN0_ISR); /* Ack intr. */
 321         }
 322         outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base + E8390_CMD);
 323     }
 324 
 325     if (interrupts && ei_debug) {
 326       printk("%s: unknown interrupt %#2x\n", dev->name, interrupts);
 327       outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base + E8390_CMD);
 328       outb_p(0xff, e8390_base + EN0_ISR); /* Ack. all intrs. */
 329     }
 330     dev->interrupt = 0;
 331     return;
 332 }
 333 
 334 /* We have finished a transmit: check for errors and then trigger the next
 335    packet to be sent. */
 336 static void
 337 ei_tx_intr(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 338 {
 339     int e8390_base = dev->base_addr;
 340     int status = inb(e8390_base + EN0_TSR);
 341     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 342 
 343     outb_p(ENISR_TX, e8390_base + EN0_ISR); /* Ack intr. */
 344 
 345     if (ei_local->pingpong) {
 346         ei_local->txqueue--;
 347         if (ei_local->tx1 < 0) {
 348             if (ei_local->lasttx != 1 && ei_local->lasttx != -1)
 349                 printk("%s: bogus last_tx_buffer %d, tx1=%d.\n",
 350                        ei_local->name, ei_local->lasttx, ei_local->tx1);
 351             ei_local->tx1 = 0;
 352             dev->tbusy = 0;
 353             if (ei_local->tx2 > 0) {
 354                 NS8390_trigger_send(dev, ei_local->tx2, ei_local->tx_start_page + 6);
 355                 dev->trans_start = jiffies;
 356                 ei_local->txing = 1;
 357                 ei_local->tx2 = -1,
 358                 ei_local->lasttx = 2;
 359             } else
 360                 ei_local->lasttx = 20, ei_local->txing = 0;
 361         } else if (ei_local->tx2 < 0) {
 362             if (ei_local->lasttx != 2  &&  ei_local->lasttx != -2)
 363                 printk("%s: bogus last_tx_buffer %d, tx2=%d.\n",
 364                        ei_local->name, ei_local->lasttx, ei_local->tx2);
 365             ei_local->tx2 = 0;
 366             dev->tbusy = 0;
 367             if (ei_local->tx1 > 0) {
 368                 NS8390_trigger_send(dev, ei_local->tx1, ei_local->tx_start_page);
 369                 dev->trans_start = jiffies;
 370                 ei_local->txing = 1;
 371                 ei_local->tx1 = -1;
 372                 ei_local->lasttx = 1;
 373             } else
 374                 ei_local->lasttx = 10, ei_local->txing = 0;
 375         } else
 376             printk("%s: unexpected TX-done interrupt, lasttx=%d.\n",
 377                    dev->name, ei_local->lasttx);
 378     } else {
 379         ei_local->txing = 0;
 380         dev->tbusy = 0;
 381     }
 382 
 383     /* Do the statistics _after_ we start the next TX. */
 384     if (status & ENTSR_PTX)
 385         ei_local->stat.tx_packets++;
 386     else
 387         ei_local->stat.tx_errors++;
 388     if (status & ENTSR_COL)
 389         ei_local->stat.collisions++;
 390     if (status & ENTSR_ABT)
 391         ei_local->stat.tx_aborted_errors++;
 392     if (status & ENTSR_CRS)
 393         ei_local->stat.tx_carrier_errors++;
 394     if (status & ENTSR_FU)
 395         ei_local->stat.tx_fifo_errors++;
 396     if (status & ENTSR_CDH)
 397         ei_local->stat.tx_heartbeat_errors++;
 398     if (status & ENTSR_OWC)
 399         ei_local->stat.tx_window_errors++;
 400 
 401     mark_bh (INET_BH);
 402 }
 403 
 404 /* We have a good packet(s), get it/them out of the buffers. */
 405 
 406 static void
 407 ei_receive(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 408 {
 409     int e8390_base = dev->base_addr;
 410     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 411     int rxing_page, this_frame, next_frame, current_offset;
 412     int boguscount = 0;
 413     struct e8390_pkt_hdr rx_frame;
 414     int num_rx_pages = ei_local->stop_page-ei_local->rx_start_page;
 415 
 416     while (++boguscount < 10) {
 417       int size;
 418 
 419       /* Get the rx page (incoming packet pointer). */
 420       outb_p(E8390_NODMA+E8390_PAGE1, e8390_base + E8390_CMD);
 421       rxing_page = inb_p(e8390_base + EN1_CURPAG);
 422       outb_p(E8390_NODMA+E8390_PAGE0, e8390_base + E8390_CMD);
 423 
 424       /* Remove one frame from the ring.  Boundary is alway a page behind. */
 425       this_frame = inb_p(e8390_base + EN0_BOUNDARY) + 1;
 426       if (this_frame >= ei_local->stop_page)
 427         this_frame = ei_local->rx_start_page;
 428 
 429       /* Someday we'll omit the previous step, iff we never get this message.*/
 430       if (ei_debug > 0  &&  this_frame != ei_local->current_page)
 431         printk("%s: mismatched read page pointers %2x vs %2x.\n",
 432                dev->name, this_frame, ei_local->current_page);
 433 
 434       if (this_frame == rxing_page)     /* Read all the frames? */
 435         break;                          /* Done for now */
 436 
 437       current_offset = this_frame << 8;
 438       ei_block_input(dev, sizeof(rx_frame), (char *)&rx_frame,
 439                      current_offset);
 440 
 441       size = rx_frame.count - sizeof(rx_frame);
 442 
 443       next_frame = this_frame + 1 + ((size+4)>>8);
 444 
 445       /* Check for bogosity warned by 3c503 book: the status byte is never
 446          written.  This happened a lot during testing! This code should be
 447          cleaned up someday, and the printk()s should be PRINTK()s. */
 448       if (   rx_frame.next != next_frame
 449           && rx_frame.next != next_frame + 1
 450           && rx_frame.next != next_frame - num_rx_pages
 451           && rx_frame.next != next_frame + 1 - num_rx_pages) {
 452 #ifndef EI_DEBUG
 453           ei_local->current_page = rxing_page;
 454           outb(ei_local->current_page-1, e8390_base+EN0_BOUNDARY);
 455           continue;
 456 #else
 457         static int last_rx_bogosity = -1;
 458         printk("%s: bogus packet header, status=%#2x nxpg=%#2x sz=%#x (at %#4x)\n",
 459                dev->name, rx_frame.status, rx_frame.next, rx_frame.count,
 460                current_offset);
 461 
 462         if (ei_local->stat.rx_packets != last_rx_bogosity) {
 463           /* Maybe we can avoid resetting the chip... empty the packet ring. */
 464           ei_local->current_page = rxing_page;
 465           printk("%s:   setting next frame to %#2x (nxt=%#2x, rx_frm.nx=%#2x rx_frm.stat=%#2x).\n",
 466                  dev->name, ei_local->current_page, next_frame,
 467                  rx_frame.next, rx_frame.status);
 468           last_rx_bogosity = ei_local->stat.rx_packets;
 469           outb(ei_local->current_page-1, e8390_base+EN0_BOUNDARY);
 470           continue;
 471         } else {
 472           /* Oh no Mr Bill! Last ditch error recovery. */
 473           printk("%s: recovery failed, resetting at packet #%d..",
 474                  dev->name, ei_local->stat.rx_packets);
 475           sti();
 476           ei_reset_8390(dev);
 477           NS8390_init(dev, 1);
 478           printk("restarting.\n");
 479           return;
 480         }
 481 #endif  /* EI8390_NOCHECK */
 482       }
 483 
 484       if ((size < 32  ||  size > 1535) && ei_debug)
 485         printk("%s: bogus packet size, status=%#2x nxpg=%#2x size=%#x\n",
 486                dev->name, rx_frame.status, rx_frame.next, rx_frame.count);
 487       if ((rx_frame.status & 0x0F) == ENRSR_RXOK) {
 488         int sksize = sizeof(struct sk_buff) + size;
 489         struct sk_buff *skb;
 490         skb = (struct sk_buff *) kmalloc(sksize, GFP_ATOMIC);
 491         if (skb != NULL) {
 492           skb->lock = 0;
 493           skb->mem_len = sksize;
 494           skb->mem_addr = skb;
 495           /* 'skb+1' points to the start of sk_buff data area. */
 496           ei_block_input(dev, size, (char *)(skb+1),
 497                          current_offset + sizeof(rx_frame));
 498           if (dev_rint((unsigned char *)skb, size, IN_SKBUFF, dev)) {
 499               printk("%s: receive buffers full.\n", dev->name);
 500               kfree_s(skb, sksize);
 501               break;
 502           }
 503         } else if (ei_debug) {
 504           printk("%s: Couldn't allocate a sk_buff of size %d.\n",
 505                  dev->name, sksize);
 506           break;
 507         }
 508         ei_local->stat.rx_packets++;
 509       } else {
 510         int errs = rx_frame.status;
 511         if (ei_debug)
 512           printk("%s: bogus packet, status=%#2x nxpg=%#2x size=%d\n",
 513                  dev->name, rx_frame.status, rx_frame.next, rx_frame.count);
 514         if (errs & ENRSR_FO)
 515             ei_local->stat.rx_fifo_errors++;
 516       }
 517       next_frame = rx_frame.next;
 518 
 519          /* This should never happen, it's here for debugging. */
 520       if (next_frame >= ei_local->stop_page) {
 521         printk("%s: next frame inconsistency, %#2x..", dev->name, next_frame);
 522         next_frame = ei_local->rx_start_page;
 523       }
 524       ei_local->current_page += 1 + ((size+4)>>8);
 525       ei_local->current_page = next_frame;
 526       outb(next_frame-1, e8390_base+EN0_BOUNDARY);
 527     }
 528     /* If any worth-while packets have been received, dev_rint()
 529        has done a mark_bh(INET_BH) for us and will work on them
 530        when we get to the bottom-half routine. */
 531 
 532     /* Bug alert!  Reset ENISR_OVER to avoid spurious overruns! */
 533     outb_p(ENISR_RX+ENISR_RX_ERR+ENISR_OVER, e8390_base+EN0_ISR);
 534     return;
 535 }
 536 
 537 /* We have a receiver overrun: we have to kick the 8390 to get it started
 538    again.*/
 539 static void
 540 ei_rx_overrun(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 541 {
 542     int e8390_base = dev->base_addr;
 543     int reset_start_time = jiffies;
 544     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 545 
 546     /* We should already be stopped and in page0.  Remove after testing. */
 547     outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
 548 
 549     if (ei_debug)
 550         printk("%s: Receiver overrun.\n", dev->name);
 551     ei_local->stat.rx_over_errors++;
 552 
 553     /* The we.c driver does dummy = inb_p( RBCR[01] ); at this point.
 554        It might mean something -- magic to speed up a reset?  A 8390 bug?*/
 555 
 556     /* Wait for reset in case the NIC is doing a tx or rx.  This could take up to
 557        1.5msec, but we have no way of timing something in that range.  The 'jiffies'
 558        are just a sanity check. */
 559     while ((inb_p(e8390_base+EN0_ISR) & ENISR_RESET) == 0)
 560         if (jiffies - reset_start_time > 1) {
 561             printk("%s: reset did not complete at ei_rx_overrun.\n",
 562                    dev->name);
 563             NS8390_init(dev, 1);
 564             return;
 565         };
 566 
 567     /* Remove packets right away. */
 568     ei_receive(dev);
 569 
 570     outb_p(0xff, e8390_base+EN0_ISR);
 571     /* Generic 8390 insns to start up again, same as in open_8390(). */
 572     outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START, e8390_base + E8390_CMD);
 573     outb_p(E8390_TXCONFIG, e8390_base + EN0_TXCR); /* xmit on. */
 574 }
 575 
 576 static struct enet_statistics *
 577 get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 578 {
 579     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 580     return &ei_local->stat;
 581 }
 582 
 583 int
 584 ethif_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 585 {
 586     if (1
 587 #ifdef WD80x3
 588         && ! wdprobe(dev->base_addr, dev)
 589 #endif
 590 #ifdef EL2
 591         && ! el2autoprobe(dev->base_addr, dev)
 592 #endif
 593 #ifdef NE2000
 594         && ! neprobe(dev->base_addr, dev)
 595 #endif
 596 #ifdef HPLAN
 597         && ! hpprobe(dev->base_addr, dev)
 598 #endif
 599         && 1 ) {
 600         return 1;       /* -ENODEV or -EAGAIN would be more accurate. */
 601     }
 602     if (ei_debug > 1)
 603         printk(version);
 604     return 0;
 605 }
 606 
 607 /* Initialize the rest of the device structure. */
 608 int
 609 ethdev_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 610 {
 611     int i;
 612 
 613     for (i = 0; i < DEV_NUMBUFFS; i++)
 614         dev->buffs[i] = NULL;
 615 
 616     /* The open call may be overridden by the card-specific code. */
 617     if (dev->open == NULL)
 618         dev->open = &ei_open;
 619 
 620     dev->get_stats      = get_stats;
 621     dev->hard_header    = eth_header;
 622     dev->add_arp        = eth_add_arp;
 623     dev->queue_xmit     = dev_queue_xmit;
 624     dev->rebuild_header = eth_rebuild_header;
 625     dev->type_trans     = eth_type_trans;
 626 
 627     if (dev->priv == NULL) {
 628         struct ei_device *ei_local;
 629 
 630         dev->priv = kmalloc(sizeof(struct ei_device), GFP_KERNEL);
 631         memset(dev->priv, 0, sizeof(struct ei_device));
 632         ei_local = (struct ei_device *)dev->priv;
 633 #ifndef NO_PINGPONG
 634         ei_local->pingpong = 1;
 635 #endif
 636     }
 637 
 638     dev->hard_start_xmit = &ei_start_xmit;
 639 
 640     dev->type           = ARPHRD_ETHER;
 641     dev->hard_header_len = ETH_HLEN;
 642     dev->mtu            = 1500; /* eth_mtu */
 643     dev->addr_len       = ETH_ALEN;
 644     for (i = 0; i < dev->addr_len; i++) {
 645         dev->broadcast[i]=0xff;
 646     }
 647 
 648     /* New-style flags. */
 649     dev->flags          = IFF_BROADCAST;
 650     dev->family         = AF_INET;
 651     dev->pa_addr        = 0;
 652     dev->pa_brdaddr     = 0;
 653     dev->pa_mask        = 0;
 654     dev->pa_alen        = sizeof(unsigned long);
 655 
 656     return 0;
 657 }
 658 
 659 
 660 /* This page of functions should be 8390 generic */
 661 /* Follow National Semi's recommendations for initializing the "NIC". */
 662 void NS8390_init(struct device *dev, int startp)
     /* [previous][next][first][last][top][bottom][index][help] */
 663 {
 664     int e8390_base = dev->base_addr;
 665     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 666     int i;
 667     int endcfg = ei_local->word16 ? (0x48 | ENDCFG_WTS) : 0x48;
 668 
 669     /* Follow National Semi's recommendations for initing the DP83902. */
 670     outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base); /* 0x21 */
 671     outb_p(endcfg, e8390_base + EN0_DCFG);      /* 0x48 or 0x49 */
 672     /* Clear the remote byte count registers. */
 673     outb_p(0x00,  e8390_base + EN0_RCNTLO);
 674     outb_p(0x00,  e8390_base + EN0_RCNTHI);
 675     /* Set to monitor and loopback mode -- this is vital!. */
 676     outb_p(E8390_RXOFF, e8390_base + EN0_RXCR); /* 0x20 */
 677     outb_p(E8390_TXOFF, e8390_base + EN0_TXCR); /* 0x02 */
 678     /* Set the transmit page and receive ring. */
 679     outb_p(ei_local->tx_start_page,  e8390_base + EN0_TPSR);
 680     ei_local->tx1 = ei_local->tx2 = 0;
 681     outb_p(ei_local->rx_start_page,  e8390_base + EN0_STARTPG);
 682     outb_p(ei_local->stop_page-1, e8390_base + EN0_BOUNDARY); /* 3c503 says 0x3f,NS0x26*/
 683     ei_local->current_page = ei_local->rx_start_page;       /* assert boundary+1 */
 684     outb_p(ei_local->stop_page,   e8390_base + EN0_STOPPG);
 685     /* Clear the pending interrupts and mask. */
 686     outb_p(0xFF, e8390_base + EN0_ISR);
 687     outb_p(0x00,  e8390_base + EN0_IMR);
 688 
 689     /* Copy the station address into the DS8390 registers,
 690        and set the multicast hash bitmap to receive all multicasts. */
 691     cli();
 692     outb_p(E8390_NODMA + E8390_PAGE1 + E8390_STOP, e8390_base); /* 0x61 */
 693     for(i = 0; i < 6; i++) {
 694         outb_p(dev->dev_addr[i], e8390_base + EN1_PHYS + i);
 695     }
 696     for(i = 0; i < 8; i++)
 697         outb_p(0xff, e8390_base + EN1_MULT + i);
 698 
 699     outb_p(ei_local->rx_start_page,  e8390_base + EN1_CURPAG);
 700     outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base);
 701     sti();
 702     if (startp) {
 703         outb_p(0xff,  e8390_base + EN0_ISR);
 704         outb_p(ENISR_ALL,  e8390_base + EN0_IMR);
 705         outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base);
 706         outb_p(E8390_TXCONFIG, e8390_base + EN0_TXCR); /* xmit on. */
 707         /* 3c503 TechMan says rxconfig only after the NIC is started. */
 708         outb_p(E8390_RXCONFIG,  e8390_base + EN0_RXCR); /* rx on,  */
 709     }
 710     return;
 711 }
 712 
 713 /* Trigger a transmit start, assuming the length is valid. */
 714 static void NS8390_trigger_send(struct device *dev, unsigned int length,
     /* [previous][next][first][last][top][bottom][index][help] */
 715                                 int start_page)
 716 {
 717     int e8390_base = dev->base_addr;
 718 
 719     ei_status.txing = 1;
 720     outb_p(E8390_NODMA+E8390_PAGE0, e8390_base);
 721 
 722     if (inb_p(e8390_base) & E8390_TRANS) {
 723       printk("%s: trigger_send() called with the transmitter busy.\n",
 724              dev->name);
 725       return;
 726     }
 727     outb_p(length & 0xff, e8390_base + EN0_TCNTLO);
 728     outb_p(length >> 8, e8390_base + EN0_TCNTHI);
 729     outb_p(start_page, e8390_base + EN0_TPSR);
 730     outb_p(E8390_NODMA+E8390_TRANS+E8390_START, e8390_base);
 731     return;
 732 }
 733 
 734 
 735 /*
 736  * Local variables:
 737  *  compile-command: "gcc -D__KERNEL__ -Wall -O6 -x c++ -c 8390.c"
 738  *  version-control: t
 739  *  kept-new-versions: 5
 740  * End:
 741  */

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