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

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