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_close
  3. ei_start_xmit
  4. ei_interrupt
  5. ei_tx_intr
  6. ei_receive
  7. ei_rx_overrun
  8. get_stats
  9. set_multicast_list
  10. ethdev_init
  11. NS8390_init
  12. NS8390_trigger_send
  13. init_module
  14. cleanup_module

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

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