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

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