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
  12. init_module
  13. cleanup_module

   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   This is not a complete driver, it must be combined with board-specific
  12   code such as ne.c, wd.c, 3c503.c, etc.
  13   
  14   The Author may be reached as becker@super.org or
  15   C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715
  16   */
  17 
  18 static char *version =
  19     "8390.c:v0.99-15e 2/16/94 Donald Becker (becker@super.org)\n";
  20 #include <linux/config.h>
  21 
  22 /*
  23   Braindamage remaining:
  24   Much of this code should be cleaned up post-1.00, but it has been
  25   extensively beta tested in the current form.
  26   
  27   Sources:
  28   The National Semiconductor LAN Databook, and the 3Com 3c503 databook.
  29   The NE* programming info came from the Crynwr packet driver, and figuring
  30   out that the those boards are similar to the NatSemi evaluation board
  31   described in AN-729.  Thanks NS, no thanks to Novell/Eagle.
  32   */
  33 
  34 #include <linux/config.h>
  35 #include <linux/kernel.h>
  36 #include <linux/sched.h>
  37 #include <linux/fs.h>
  38 #include <linux/types.h>
  39 #include <linux/ptrace.h>
  40 #include <linux/string.h>
  41 #include <asm/system.h>
  42 #include <asm/segment.h>
  43 #include <asm/bitops.h>
  44 #include <asm/io.h>
  45 #include <errno.h>
  46 #include <linux/fcntl.h>
  47 #include <linux/in.h>
  48 #include <linux/interrupt.h>
  49 
  50 #include <linux/netdevice.h>
  51 #include <linux/etherdevice.h>
  52 #include <linux/skbuff.h>
  53 
  54 #include "8390.h"
  55 
  56 #ifdef MODULE
  57 #include <linux/module.h>
  58 #include "../../tools/version.h"
  59 #endif
  60 
  61 /* These are the operational function interfaces to board-specific
  62    routines.
  63         void reset_8390(struct device *dev)
  64                 Resets the board associated with DEV, including a hardware reset of
  65                 the 8390.  This is only called when there is a transmit timeout, and
  66                 it is always followed by 8390_init().
  67         void block_output(struct device *dev, int count, const unsigned char *buf,
  68                                           int start_page)
  69                 Write the COUNT bytes of BUF to the packet buffer at START_PAGE.  The
  70                 "page" value uses the 8390's 256-byte pages.
  71         int block_input(struct device *dev, int count, char *buf, int ring_offset)
  72                 Read COUNT bytes from the packet buffer into BUF.  Start reading from
  73                 RING_OFFSET, the address as the 8390 sees it.  The first read will
  74                 always be the 4 byte, page aligned 8390 header.  *If* there is a
  75                 subsequent read, it will be of the rest of the packet.
  76 */
  77 #define ei_reset_8390 (ei_local->reset_8390)
  78 #define ei_block_output (ei_local->block_output)
  79 #define ei_block_input (ei_local->block_input)
  80 
  81 /* use 0 for production, 1 for verification, >2 for debug */
  82 #ifdef EI_DEBUG
  83 int ei_debug = EI_DEBUG;
  84 #else
  85 int ei_debug = 1;
  86 #endif
  87 
  88 /* Max number of packets received at one Intr.
  89    Current this may only be examined by a kernel debugger. */
  90 static int high_water_mark = 0;
  91 
  92 /* Index to functions. */
  93 static void ei_tx_intr(struct device *dev);
  94 static void ei_receive(struct device *dev);
  95 static void ei_rx_overrun(struct device *dev);
  96 
  97 /* Routines generic to NS8390-based boards. */
  98 static void NS8390_trigger_send(struct device *dev, unsigned int length,
  99                                                                 int start_page);
 100 #ifdef HAVE_MULTICAST
 101 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
 102 #endif
 103 
 104 
 105 /* Open/initialize the board.  This routine goes all-out, setting everything
 106    up anew at each open, even though many of these registers should only
 107    need to be set once at boot.
 108    */
 109 int ei_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 110 {
 111     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 112     
 113     if ( ! ei_local) {
 114                 printk("%s: Opening a non-existent physical device\n", dev->name);
 115                 return ENXIO;
 116     }
 117     
 118     irq2dev_map[dev->irq] = dev;
 119     NS8390_init(dev, 1);
 120     dev->start = 1;
 121     ei_local->irqlock = 0;
 122     return 0;
 123 }
 124 
 125 static int ei_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 126 {
 127     int e8390_base = dev->base_addr;
 128     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 129     int length, send_length;
 130     
 131         /* We normally shouldn't be called if dev->tbusy is set, but the
 132            existing code does anyway.
 133            If it has been too long (> 100 or 150ms.) since the last Tx we assume
 134            the board has died and kick it. */
 135 
 136     if (dev->tbusy) {   /* Do timeouts, just like the 8003 driver. */
 137                 int txsr = inb(e8390_base+EN0_TSR), isr, cmd;
 138                 int tickssofar = jiffies - dev->trans_start;
 139                 if (tickssofar < 10     ||      (tickssofar < 15 && ! (txsr & ENTSR_PTX))) {
 140                         return 1;
 141                 }
 142                 isr = inb(e8390_base+EN0_ISR);
 143                 cmd = inb(e8390_base+E8390_CMD) & (E8390_STOP|E8390_START);
 144                 if ((cmd == 0) || (cmd == (E8390_STOP|E8390_START)))
 145                         return 1;
 146                 printk(KERN_DEBUG "%s: transmit timed out, TX status %#2x, ISR %#2x.\n",
 147                            dev->name, txsr, isr);
 148                 /* Does the 8390 thinks it has posted an interrupt? */
 149                 if (isr)
 150                         printk(KERN_DEBUG "%s: Possible IRQ conflict on IRQ%d?\n", dev->name, dev->irq);
 151                 else {
 152                         /* The 8390 probably hasn't gotten on the cable yet. */
 153                         printk(KERN_DEBUG "%s: Possible network cable problem?\n", dev->name);
 154                         if(ei_local->stat.tx_packets==0)
 155                                 ei_local->interface_num ^= 1;   /* Try a different xcvr.  */
 156                 }
 157                 /* Try to restart the card.  Perhaps the user has fixed something. */
 158                 ei_reset_8390(dev);
 159                 NS8390_init(dev, 1);
 160                 dev->trans_start = jiffies;
 161     }
 162     
 163     /* Sending a NULL skb means some higher layer thinks we've missed an
 164        tx-done interrupt. Caution: dev_tint() handles the cli()/sti()
 165        itself. */
 166     if (skb == NULL) {
 167                 dev_tint(dev);
 168                 return 0;
 169     }
 170     
 171     length = skb->len;
 172     if (skb->len <= 0)
 173                 return 0;
 174 
 175         /* Block a timer-based transmit from overlapping. */
 176         if (set_bit(0, (void*)&dev->tbusy) != 0) {
 177                 printk("%s: Transmitter access conflict.\n", dev->name);
 178                 return 1;
 179         }
 180 
 181     /* Mask interrupts from the ethercard. */
 182     outb(0x00,  e8390_base + EN0_IMR);
 183     ei_local->irqlock = 1;
 184 
 185     send_length = ETH_ZLEN < length ? length : ETH_ZLEN;
 186 
 187     if (ei_local->pingpong) {
 188                 int output_page;
 189                 if (ei_local->tx1 == 0) {
 190                         output_page = ei_local->tx_start_page;
 191                         ei_local->tx1 = send_length;
 192                         if (ei_debug  &&  ei_local->tx2 > 0)
 193                                 printk("%s: idle transmitter tx2=%d, lasttx=%d, txing=%d.\n",
 194                                            dev->name, ei_local->tx2, ei_local->lasttx,
 195                                            ei_local->txing);
 196                 } else if (ei_local->tx2 == 0) {
 197                         output_page = ei_local->tx_start_page + 6;
 198                         ei_local->tx2 = send_length;
 199                         if (ei_debug  &&  ei_local->tx1 > 0)
 200                                 printk("%s: idle transmitter, tx1=%d, lasttx=%d, txing=%d.\n",
 201                                            dev->name, ei_local->tx1, ei_local->lasttx,
 202                                            ei_local->txing);
 203                 } else {        /* We should never get here. */
 204                         if (ei_debug)
 205                                 printk("%s: No packet buffer space for ping-pong use.\n",
 206                                            dev->name);
 207                         ei_local->irqlock = 0;
 208                         dev->tbusy = 1;
 209                         outb_p(ENISR_ALL,  e8390_base + EN0_IMR);
 210                         return 1;
 211                 }
 212                 ei_block_output(dev, length, skb->data, output_page);
 213                 if (! ei_local->txing) {
 214                         NS8390_trigger_send(dev, send_length, output_page);
 215                         dev->trans_start = jiffies;
 216                         if (output_page == ei_local->tx_start_page)
 217                                 ei_local->tx1 = -1, ei_local->lasttx = -1;
 218                         else
 219                                 ei_local->tx2 = -1, ei_local->lasttx = -2;
 220                         ei_local->txing = 1;
 221                 } else
 222                         ei_local->txqueue++;
 223 
 224                 dev->tbusy = (ei_local->tx1  &&  ei_local->tx2);
 225     } else {  /* No pingpong, just a single Tx buffer. */
 226                 ei_block_output(dev, length, skb->data, ei_local->tx_start_page);
 227                 NS8390_trigger_send(dev, send_length, ei_local->tx_start_page);
 228                 dev->trans_start = jiffies;
 229                 dev->tbusy = 1;
 230     }
 231     
 232     /* Turn 8390 interrupts back on. */
 233     ei_local->irqlock = 0;
 234     outb_p(ENISR_ALL, e8390_base + EN0_IMR);
 235 
 236     dev_kfree_skb (skb, FREE_WRITE);
 237     
 238     return 0;
 239 }
 240 
 241 /* The typical workload of the driver:
 242    Handle the ether interface interrupts. */
 243 void ei_interrupt(int reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 244 {
 245     int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
 246     struct device *dev = (struct device *)(irq2dev_map[irq]);
 247     int e8390_base;
 248     int interrupts, cmd, boguscount = 0;
 249     struct ei_device *ei_local;
 250     
 251     if (dev == NULL) {
 252                 printk ("net_interrupt(): irq %d for unknown device.\n", irq);
 253                 return;
 254     }
 255     e8390_base = dev->base_addr;
 256     ei_local = (struct ei_device *) dev->priv;
 257     if (dev->interrupt || ei_local->irqlock) {
 258                 /* The "irqlock" check is only for testing. */
 259                 sti();
 260                 printk(ei_local->irqlock
 261                            ? "%s: Interrupted while interrupts are masked! isr=%#2x imr=%#2x.\n"
 262                            : "%s: Reentering the interrupt handler! isr=%#2x imr=%#2x.\n",
 263                            dev->name, inb_p(e8390_base + EN0_ISR),
 264                            inb_p(e8390_base + EN0_IMR));
 265                 return;
 266     }
 267     
 268     dev->interrupt = 1;
 269     sti(); /* Allow other interrupts. */
 270     
 271     /* Change to page 0 and read the intr status reg. */
 272     outb_p(E8390_NODMA+E8390_PAGE0, e8390_base + E8390_CMD);
 273     if (ei_debug > 3)
 274                 printk("%s: interrupt(isr=%#2.2x).\n", dev->name,
 275                            inb_p(e8390_base + EN0_ISR));
 276     
 277     /* !!Assumption!! -- we stay in page 0.      Don't break this. */
 278     while ((interrupts = inb_p(e8390_base + EN0_ISR)) != 0
 279                    && ++boguscount < 9) {
 280                 cmd = inb(e8390_base+E8390_CMD) & (E8390_STOP|E8390_START);
 281                 if ((cmd == 0) || (cmd == (E8390_STOP|E8390_START))) {
 282                         printk("%s: card not present\n", dev->name);
 283                         interrupts = 0;
 284                         break;
 285                         }
 286                 if (interrupts & ENISR_RDC) {
 287                         /* Ack meaningless DMA complete. */
 288                         outb_p(ENISR_RDC, e8390_base + EN0_ISR);
 289                 }
 290                 if (interrupts & ENISR_OVER) {
 291                         ei_rx_overrun(dev);
 292                 } else if (interrupts & (ENISR_RX+ENISR_RX_ERR)) {
 293                         /* Got a good (?) packet. */
 294                         ei_receive(dev);
 295                 }
 296                 /* Push the next to-transmit packet through. */
 297                 if (interrupts & ENISR_TX) {
 298                         ei_tx_intr(dev);
 299                 } else if (interrupts & ENISR_COUNTERS) {
 300                         ei_local->stat.rx_frame_errors += inb_p(e8390_base + EN0_COUNTER0);
 301                         ei_local->stat.rx_crc_errors   += inb_p(e8390_base + EN0_COUNTER1);
 302                         ei_local->stat.rx_missed_errors+= inb_p(e8390_base + EN0_COUNTER2);
 303                         outb_p(ENISR_COUNTERS, e8390_base + EN0_ISR); /* Ack intr. */
 304                 }
 305                 
 306                 /* Ignore the transmit errs and reset intr for now. */
 307                 if (interrupts & ENISR_TX_ERR) {
 308                         outb_p(ENISR_TX_ERR, e8390_base + EN0_ISR); /* Ack intr. */
 309                 }
 310                 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base + E8390_CMD);
 311     }
 312     
 313     if (interrupts && ei_debug) {
 314                 printk("%s: unknown interrupt %#2x\n", dev->name, interrupts);
 315                 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base + E8390_CMD);
 316                 outb_p(0xff, e8390_base + EN0_ISR); /* Ack. all intrs. */
 317     }
 318     dev->interrupt = 0;
 319     return;
 320 }
 321 
 322 /* We have finished a transmit: check for errors and then trigger the next
 323    packet to be sent. */
 324 static void 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     /* Minimize Tx latency: update the statistics after we restart TXing. */
 371         if (status & ENTSR_COL) ei_local->stat.collisions++;
 372     if (status & ENTSR_PTX)
 373                 ei_local->stat.tx_packets++;
 374     else {
 375                 ei_local->stat.tx_errors++;
 376                 if (status & ENTSR_ABT) ei_local->stat.tx_aborted_errors++;
 377                 if (status & ENTSR_CRS) ei_local->stat.tx_carrier_errors++;
 378                 if (status & ENTSR_FU)  ei_local->stat.tx_fifo_errors++;
 379                 if (status & ENTSR_CDH) ei_local->stat.tx_heartbeat_errors++;
 380                 if (status & ENTSR_OWC) ei_local->stat.tx_window_errors++;
 381         }
 382     
 383     mark_bh (NET_BH);
 384 }
 385 
 386 /* We have a good packet(s), get it/them out of the buffers. */
 387 
 388 static void ei_receive(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 389 {
 390     int e8390_base = dev->base_addr;
 391     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 392     int rxing_page, this_frame, next_frame, current_offset;
 393     int rx_pkt_count = 0;
 394     struct e8390_pkt_hdr rx_frame;
 395     int num_rx_pages = ei_local->stop_page-ei_local->rx_start_page;
 396     
 397     while (++rx_pkt_count < 10) {
 398                 int pkt_len;
 399                 
 400                 /* Get the rx page (incoming packet pointer). */
 401                 outb_p(E8390_NODMA+E8390_PAGE1, e8390_base + E8390_CMD);
 402                 rxing_page = inb_p(e8390_base + EN1_CURPAG);
 403                 outb_p(E8390_NODMA+E8390_PAGE0, e8390_base + E8390_CMD);
 404                 
 405                 /* Remove one frame from the ring.  Boundary is alway a page behind. */
 406                 this_frame = inb_p(e8390_base + EN0_BOUNDARY) + 1;
 407                 if (this_frame >= ei_local->stop_page)
 408                         this_frame = ei_local->rx_start_page;
 409                 
 410                 /* Someday we'll omit the previous, iff we never get this message.
 411                    (There is at least one clone claimed to have a problem.)  */
 412                 if (ei_debug > 0  &&  this_frame != ei_local->current_page)
 413                         printk("%s: mismatched read page pointers %2x vs %2x.\n",
 414                                    dev->name, this_frame, ei_local->current_page);
 415                 
 416                 if (this_frame == rxing_page)   /* Read all the frames? */
 417                         break;                          /* Done for now */
 418                 
 419                 current_offset = this_frame << 8;
 420                 ei_block_input(dev, sizeof(rx_frame), (char *)&rx_frame,
 421                                            current_offset);
 422                 
 423                 pkt_len = rx_frame.count - sizeof(rx_frame);
 424                 
 425                 next_frame = this_frame + 1 + ((pkt_len+4)>>8);
 426                 
 427                 /* Check for bogosity warned by 3c503 book: the status byte is never
 428                    written.  This happened a lot during testing! This code should be
 429                    cleaned up someday. */
 430                 if (rx_frame.next != next_frame
 431                         && rx_frame.next != next_frame + 1
 432                         && rx_frame.next != next_frame - num_rx_pages
 433                         && rx_frame.next != next_frame + 1 - num_rx_pages) {
 434                         ei_local->current_page = rxing_page;
 435                         outb(ei_local->current_page-1, e8390_base+EN0_BOUNDARY);
 436                         ei_local->stat.rx_errors++;
 437                         continue;
 438                 }
 439 
 440                 if (pkt_len < 60  ||  pkt_len > 1518) {
 441                         if (ei_debug)
 442                                 printk("%s: bogus packet size: %d, status=%#2x nxpg=%#2x.\n",
 443                                            dev->name, rx_frame.count, rx_frame.status,
 444                                            rx_frame.next);
 445                         ei_local->stat.rx_errors++;
 446                 } else if ((rx_frame.status & 0x0F) == ENRSR_RXOK) {
 447                         struct sk_buff *skb;
 448                         
 449                         skb = alloc_skb(pkt_len, GFP_ATOMIC);
 450                         if (skb == NULL) {
 451                                 if (ei_debug > 1)
 452                                         printk("%s: Couldn't allocate a sk_buff of size %d.\n",
 453                                                    dev->name, pkt_len);
 454                                 ei_local->stat.rx_dropped++;
 455                                 break;
 456                         } else {
 457                                 skb->len = pkt_len;
 458                                 skb->dev = dev;
 459                                 
 460                                 ei_block_input(dev, pkt_len, (char *) skb->data,
 461                                                            current_offset + sizeof(rx_frame));
 462                                 netif_rx(skb);
 463                                 ei_local->stat.rx_packets++;
 464                         }
 465                 } else {
 466                         int errs = rx_frame.status;
 467                         if (ei_debug)
 468                                 printk("%s: bogus packet: status=%#2x nxpg=%#2x size=%d\n",
 469                                            dev->name, rx_frame.status, rx_frame.next,
 470                                            rx_frame.count);
 471                         if (errs & ENRSR_FO)
 472                                 ei_local->stat.rx_fifo_errors++;
 473                 }
 474                 next_frame = rx_frame.next;
 475                 
 476                 /* This _should_ never happen: it's here for avoiding bad clones. */
 477                 if (next_frame >= ei_local->stop_page) {
 478                         printk("%s: next frame inconsistency, %#2x..", dev->name,
 479                                    next_frame);
 480                         next_frame = ei_local->rx_start_page;
 481                 }
 482                 ei_local->current_page = next_frame;
 483                 outb(next_frame-1, e8390_base+EN0_BOUNDARY);
 484     }
 485     /* If any worth-while packets have been received, dev_rint()
 486        has done a mark_bh(NET_BH) for us and will work on them
 487        when we get to the bottom-half routine. */
 488 
 489         /* Record the maximum Rx packet queue. */
 490         if (rx_pkt_count > high_water_mark)
 491                 high_water_mark = rx_pkt_count;
 492 
 493     /* Bug alert!  Reset ENISR_OVER to avoid spurious overruns! */
 494     outb_p(ENISR_RX+ENISR_RX_ERR+ENISR_OVER, e8390_base+EN0_ISR);
 495     return;
 496 }
 497 
 498 /* We have a receiver overrun: we have to kick the 8390 to get it started
 499    again.*/
 500 static void ei_rx_overrun(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 501 {
 502     int e8390_base = dev->base_addr;
 503     int reset_start_time = jiffies;
 504     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 505     
 506     /* We should already be stopped and in page0.  Remove after testing. */
 507     outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
 508     
 509     if (ei_debug > 1)
 510                 printk("%s: Receiver overrun.\n", dev->name);
 511     ei_local->stat.rx_over_errors++;
 512     
 513     /* The old Biro driver does dummy = inb_p( RBCR[01] ); at this point.
 514        It might mean something -- magic to speed up a reset?  A 8390 bug?*/
 515     
 516     /* Wait for the reset to complete.  This should happen almost instantly,
 517            but could take up to 1.5msec in certain rare instances.  There is no
 518            easy way of timing something in that range, so we use 'jiffies' as
 519            a sanity check. */
 520     while ((inb_p(e8390_base+EN0_ISR) & ENISR_RESET) == 0)
 521                 if (jiffies - reset_start_time > 1) {
 522                         printk("%s: reset did not complete at ei_rx_overrun.\n",
 523                                    dev->name);
 524                         NS8390_init(dev, 1);
 525                         return;
 526                 }
 527     
 528     /* Remove packets right away. */
 529     ei_receive(dev);
 530     
 531     outb_p(0xff, e8390_base+EN0_ISR);
 532     /* Generic 8390 insns to start up again, same as in open_8390(). */
 533     outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START, e8390_base + E8390_CMD);
 534     outb_p(E8390_TXCONFIG, e8390_base + EN0_TXCR); /* xmit on. */
 535 }
 536 
 537 static struct enet_statistics *get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 538 {
 539     short ioaddr = dev->base_addr;
 540     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 541     
 542     /* Read the counter registers, assuming we are in page 0. */
 543     ei_local->stat.rx_frame_errors += inb_p(ioaddr + EN0_COUNTER0);
 544     ei_local->stat.rx_crc_errors   += inb_p(ioaddr + EN0_COUNTER1);
 545     ei_local->stat.rx_missed_errors+= inb_p(ioaddr + EN0_COUNTER2);
 546     
 547     return &ei_local->stat;
 548 }
 549 
 550 #ifdef HAVE_MULTICAST
 551 /* Set or clear the multicast filter for this adaptor.
 552    num_addrs == -1      Promiscuous mode, receive all packets
 553    num_addrs == 0       Normal mode, clear multicast list
 554    num_addrs > 0        Multicast mode, receive normal and MC packets, and do
 555    .                            best-effort filtering.
 556    */
 557 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
 558 {
 559     short ioaddr = dev->base_addr;
 560     
 561     if (num_addrs > 0) {
 562                 /* The multicast-accept list is initialized to accept-all, and we
 563                    rely on higher-level filtering for now. */
 564                 outb_p(E8390_RXCONFIG | 0x08, ioaddr + EN0_RXCR);
 565     } else if (num_addrs < 0)
 566                 outb_p(E8390_RXCONFIG | 0x18, ioaddr + EN0_RXCR);
 567     else
 568                 outb_p(E8390_RXCONFIG, ioaddr + EN0_RXCR);
 569 }
 570 #endif
 571 
 572 /* Initialize the rest of the 8390 device structure. */
 573 int ethdev_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 574 {
 575     if (ei_debug > 1)
 576                 printk(version);
 577     
 578     if (dev->priv == NULL) {
 579                 struct ei_device *ei_local;
 580                 
 581                 dev->priv = kmalloc(sizeof(struct ei_device), GFP_KERNEL);
 582                 memset(dev->priv, 0, sizeof(struct ei_device));
 583                 ei_local = (struct ei_device *)dev->priv;
 584 #ifndef NO_PINGPONG
 585                 ei_local->pingpong = 1;
 586 #endif
 587     }
 588     
 589     /* The open call may be overridden by the card-specific code. */
 590     if (dev->open == NULL)
 591                 dev->open = &ei_open;
 592     /* We should have a dev->stop entry also. */
 593     dev->hard_start_xmit = &ei_start_xmit;
 594     dev->get_stats      = get_stats;
 595 #ifdef HAVE_MULTICAST
 596     dev->set_multicast_list = &set_multicast_list;
 597 #endif
 598 
 599     ether_setup(dev);
 600         
 601     return 0;
 602 }
 603 
 604 
 605 /* This page of functions should be 8390 generic */
 606 /* Follow National Semi's recommendations for initializing the "NIC". */
 607 void NS8390_init(struct device *dev, int startp)
     /* [previous][next][first][last][top][bottom][index][help] */
 608 {
 609     int e8390_base = dev->base_addr;
 610     struct ei_device *ei_local = (struct ei_device *) dev->priv;
 611     int i;
 612     int endcfg = ei_local->word16 ? (0x48 | ENDCFG_WTS) : 0x48;
 613     
 614     /* Follow National Semi's recommendations for initing the DP83902. */
 615     outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base); /* 0x21 */
 616     outb_p(endcfg, e8390_base + EN0_DCFG);      /* 0x48 or 0x49 */
 617     /* Clear the remote byte count registers. */
 618     outb_p(0x00,  e8390_base + EN0_RCNTLO);
 619     outb_p(0x00,  e8390_base + EN0_RCNTHI);
 620     /* Set to monitor and loopback mode -- this is vital!. */
 621     outb_p(E8390_RXOFF, e8390_base + EN0_RXCR); /* 0x20 */
 622     outb_p(E8390_TXOFF, e8390_base + EN0_TXCR); /* 0x02 */
 623     /* Set the transmit page and receive ring. */
 624     outb_p(ei_local->tx_start_page,      e8390_base + EN0_TPSR);
 625     ei_local->tx1 = ei_local->tx2 = 0;
 626     outb_p(ei_local->rx_start_page,      e8390_base + EN0_STARTPG);
 627     outb_p(ei_local->stop_page-1, e8390_base + EN0_BOUNDARY); /* 3c503 says 0x3f,NS0x26*/
 628     ei_local->current_page = ei_local->rx_start_page;           /* assert boundary+1 */
 629     outb_p(ei_local->stop_page,   e8390_base + EN0_STOPPG);
 630     /* Clear the pending interrupts and mask. */
 631     outb_p(0xFF, e8390_base + EN0_ISR);
 632     outb_p(0x00,  e8390_base + EN0_IMR);
 633     
 634     /* Copy the station address into the DS8390 registers,
 635        and set the multicast hash bitmap to receive all multicasts. */
 636     cli();
 637     outb_p(E8390_NODMA + E8390_PAGE1 + E8390_STOP, e8390_base); /* 0x61 */
 638     for(i = 0; i < 6; i++) {
 639                 outb_p(dev->dev_addr[i], e8390_base + EN1_PHYS + i);
 640     }
 641     /* Initialize the multicast list to accept-all.  If we enable multicast
 642        the higher levels can do the filtering. */
 643     for(i = 0; i < 8; i++)
 644                 outb_p(0xff, e8390_base + EN1_MULT + i);
 645     
 646     outb_p(ei_local->rx_start_page,      e8390_base + EN1_CURPAG);
 647     outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base);
 648     sti();
 649     dev->tbusy = 0;
 650     dev->interrupt = 0;
 651     ei_local->tx1 = ei_local->tx2 = 0;
 652     ei_local->txing = 0;
 653     if (startp) {
 654                 outb_p(0xff,  e8390_base + EN0_ISR);
 655                 outb_p(ENISR_ALL,  e8390_base + EN0_IMR);
 656                 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base);
 657                 outb_p(E8390_TXCONFIG, e8390_base + EN0_TXCR); /* xmit on. */
 658                 /* 3c503 TechMan says rxconfig only after the NIC is started. */
 659                 outb_p(E8390_RXCONFIG,  e8390_base + EN0_RXCR); /* rx on,  */
 660     }
 661     return;
 662 }
 663 
 664 /* Trigger a transmit start, assuming the length is valid. */
 665 static void NS8390_trigger_send(struct device *dev, unsigned int length,
     /* [previous][next][first][last][top][bottom][index][help] */
 666                                                                 int start_page)
 667 {
 668     int e8390_base = dev->base_addr;
 669     
 670     ei_status.txing = 1;
 671     outb_p(E8390_NODMA+E8390_PAGE0, e8390_base);
 672     
 673     if (inb_p(e8390_base) & E8390_TRANS) {
 674                 printk("%s: trigger_send() called with the transmitter busy.\n",
 675                            dev->name);
 676                 return;
 677     }
 678     outb_p(length & 0xff, e8390_base + EN0_TCNTLO);
 679     outb_p(length >> 8, e8390_base + EN0_TCNTHI);
 680     outb_p(start_page, e8390_base + EN0_TPSR);
 681     outb_p(E8390_NODMA+E8390_TRANS+E8390_START, e8390_base);
 682     return;
 683 }
 684 
 685 #ifdef MODULE
 686 char kernel_version[] = UTS_RELEASE;
 687 
 688 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 689 {
 690      return 0;
 691 }
 692 
 693 void
 694 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 695 {
 696 }
 697 #endif /* MODULE */
 698 
 699 /*
 700  * Local variables:
 701  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c 8390.c"
 702  *  version-control: t
 703  *  kept-new-versions: 5
 704  *  c-indent-level: 4
 705  *  tab-width: 4
 706  * End:
 707  */

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