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

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