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. ethif_init
  8. ethdev_init
  9. NS8390_init
  10. NS8390_trigger_send

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

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