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

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