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

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