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

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