Lines Matching +full:lock +full:- +full:latency +full:- +full:ns

3 	Written 1992-94 by Donald Becker.
17 This is the chip-specific code for many 8390-based ethernet adaptors.
18 This is not a complete driver, it must be combined with board-specific
24 you have found something that needs changing. -- PG
29 Paul Gortmaker : remove set_bit lock, other cleanups.
34 Paul Gortmaker : rewrite Rx overrun handling as per NS specs.
40 Paul Gortmaker : add kmod support for auto-loading of the 8390
80 /* These are the operational function interfaces to board-specific
89 "page" value uses the 8390's 256-byte pages.
98 #define ei_reset_8390 (ei_local->reset_8390)
99 #define ei_block_output (ei_local->block_output)
100 #define ei_block_input (ei_local->block_input)
101 #define ei_get_8390_hdr (ei_local->get_8390_hdr)
109 /* Routines generic to NS8390-based boards. */
127 * this with ei_local->page_lock. Nobody should assume or set the page other
128 * than zero when the lock is not held. Lock holders must restore page 0
129 * before unlocking. Even pure readers must take the lock to protect in
134 * sits on and hold the lock. We must hold the lock because there is a dual
139 * a latency on SMP irq delivery. So we can easily go "disable irq" "sync irqs"
140 * enter lock, take the queued irq. So we waddle instead of flying.
157 * - IRQ delivery is asynchronous to the PCI bus
158 * - Blocking the local CPU IRQ via spin locks was too slow
159 * - The chip has register windows needing locking work
166 * Take the page lock
168 * Disable the IRQ (but not mask locally- someone seems to have
169 * broken this with the lock validator stuff)
170 * [This must be _nosync as the page lock may otherwise
172 * Drop the page lock and turn IRQs back on
177 * Take the lock (so we know the IRQ has terminated) but don't mask
183 * re-enable the IRQ
197 * ei_open - Open/initialize the board.
200 * This routine goes all-out, setting everything
209 if (dev->watchdog_timeo <= 0) in __ei_open()
210 dev->watchdog_timeo = TX_TIMEOUT; in __ei_open()
213 * Grab the page lock so we own the register set, then call in __ei_open()
217 spin_lock_irqsave(&ei_local->page_lock, flags); in __ei_open()
219 /* Set the flag before we drop the lock, That way the IRQ arrives in __ei_open()
222 spin_unlock_irqrestore(&ei_local->page_lock, flags); in __ei_open()
223 ei_local->irqlock = 0; in __ei_open()
228 * ei_close - shut down network device
239 * Hold the page lock during close in __ei_close()
242 spin_lock_irqsave(&ei_local->page_lock, flags); in __ei_close()
244 spin_unlock_irqrestore(&ei_local->page_lock, flags); in __ei_close()
250 * ei_tx_timeout - handle transmit time out condition
254 * completed (or failed) - i.e. never posted a Tx related interrupt.
259 unsigned long e8390_base = dev->base_addr; in __ei_tx_timeout()
261 int txsr, isr, tickssofar = jiffies - dev_trans_start(dev); in __ei_tx_timeout()
264 dev->stats.tx_errors++; in __ei_tx_timeout()
266 spin_lock_irqsave(&ei_local->page_lock, flags); in __ei_tx_timeout()
269 spin_unlock_irqrestore(&ei_local->page_lock, flags); in __ei_tx_timeout()
276 if (!isr && !dev->stats.tx_packets) { in __ei_tx_timeout()
278 ei_local->interface_num ^= 1; /* Try a different xcvr. */ in __ei_tx_timeout()
283 disable_irq_nosync_lockdep(dev->irq); in __ei_tx_timeout()
284 spin_lock(&ei_local->page_lock); in __ei_tx_timeout()
290 spin_unlock(&ei_local->page_lock); in __ei_tx_timeout()
291 enable_irq_lockdep(dev->irq); in __ei_tx_timeout()
296 * ei_start_xmit - begin packet transmission
306 unsigned long e8390_base = dev->base_addr; in __ei_start_xmit()
308 int send_length = skb->len, output_page; in __ei_start_xmit()
311 char *data = skb->data; in __ei_start_xmit()
313 if (skb->len < ETH_ZLEN) { in __ei_start_xmit()
315 memcpy(buf, data, skb->len); in __ei_start_xmit()
321 SMP: We have to grab the lock here otherwise the IRQ handler in __ei_start_xmit()
323 up trashing the mcast filter not disabling irqs if we don't lock */ in __ei_start_xmit()
325 spin_lock_irqsave(&ei_local->page_lock, flags); in __ei_start_xmit()
327 spin_unlock_irqrestore(&ei_local->page_lock, flags); in __ei_start_xmit()
331 * Slow phase with lock held. in __ei_start_xmit()
334 disable_irq_nosync_lockdep_irqsave(dev->irq, &flags); in __ei_start_xmit()
336 spin_lock(&ei_local->page_lock); in __ei_start_xmit()
338 ei_local->irqlock = 1; in __ei_start_xmit()
343 * you get very close to transmitting back-to-back packets. With in __ei_start_xmit()
348 if (ei_local->tx1 == 0) { in __ei_start_xmit()
349 output_page = ei_local->tx_start_page; in __ei_start_xmit()
350 ei_local->tx1 = send_length; in __ei_start_xmit()
352 ei_local->tx2 > 0) in __ei_start_xmit()
355 ei_local->tx2, ei_local->lasttx, ei_local->txing); in __ei_start_xmit()
356 } else if (ei_local->tx2 == 0) { in __ei_start_xmit()
357 output_page = ei_local->tx_start_page + TX_PAGES/2; in __ei_start_xmit()
358 ei_local->tx2 = send_length; in __ei_start_xmit()
360 ei_local->tx1 > 0) in __ei_start_xmit()
363 ei_local->tx1, ei_local->lasttx, ei_local->txing); in __ei_start_xmit()
367 ei_local->tx1, ei_local->tx2, ei_local->lasttx); in __ei_start_xmit()
368 ei_local->irqlock = 0; in __ei_start_xmit()
371 spin_unlock(&ei_local->page_lock); in __ei_start_xmit()
372 enable_irq_lockdep_irqrestore(dev->irq, &flags); in __ei_start_xmit()
373 dev->stats.tx_errors++; in __ei_start_xmit()
385 if (!ei_local->txing) { in __ei_start_xmit()
386 ei_local->txing = 1; in __ei_start_xmit()
388 if (output_page == ei_local->tx_start_page) { in __ei_start_xmit()
389 ei_local->tx1 = -1; in __ei_start_xmit()
390 ei_local->lasttx = -1; in __ei_start_xmit()
392 ei_local->tx2 = -1; in __ei_start_xmit()
393 ei_local->lasttx = -2; in __ei_start_xmit()
396 ei_local->txqueue++; in __ei_start_xmit()
398 if (ei_local->tx1 && ei_local->tx2) in __ei_start_xmit()
404 ei_local->irqlock = 0; in __ei_start_xmit()
407 spin_unlock(&ei_local->page_lock); in __ei_start_xmit()
408 enable_irq_lockdep_irqrestore(dev->irq, &flags); in __ei_start_xmit()
411 dev->stats.tx_bytes += send_length; in __ei_start_xmit()
417 * ei_interrupt - handle the interrupts from an 8390
431 unsigned long e8390_base = dev->base_addr; in __ei_interrupt()
439 spin_lock(&ei_local->page_lock); in __ei_interrupt()
441 if (ei_local->irqlock) { in __ei_interrupt()
449 spin_unlock(&ei_local->page_lock); in __ei_interrupt()
458 /* !!Assumption!! -- we stay in page 0. Don't break this. */ in __ei_interrupt()
463 /* rmk - acknowledge the interrupts */ in __ei_interrupt()
474 /* Push the next to-transmit packet through. */ in __ei_interrupt()
481 dev->stats.rx_frame_errors += ei_inb_p(e8390_base + EN0_COUNTER0); in __ei_interrupt()
482 dev->stats.rx_crc_errors += ei_inb_p(e8390_base + EN0_COUNTER1); in __ei_interrupt()
483 dev->stats.rx_missed_errors += ei_inb_p(e8390_base + EN0_COUNTER2); in __ei_interrupt()
507 spin_unlock(&ei_local->page_lock); in __ei_interrupt()
514 disable_irq(dev->irq); in __ei_poll()
515 __ei_interrupt(dev->irq, dev); in __ei_poll()
516 enable_irq(dev->irq); in __ei_poll()
521 * ei_tx_err - handle transmitter error
531 * Called with lock held.
536 unsigned long e8390_base = dev->base_addr; in ei_tx_err()
545 pr_cont(" excess-collisions "); in ei_tx_err()
547 pr_cont(" non-deferral "); in ei_tx_err()
549 pr_cont(" lost-carrier "); in ei_tx_err()
551 pr_cont(" FIFO-underrun "); in ei_tx_err()
553 pr_cont(" lost-heartbeat "); in ei_tx_err()
562 dev->stats.tx_errors++; in ei_tx_err()
564 dev->stats.tx_carrier_errors++; in ei_tx_err()
566 dev->stats.tx_heartbeat_errors++; in ei_tx_err()
568 dev->stats.tx_window_errors++; in ei_tx_err()
573 * ei_tx_intr - transmit interrupt handler
577 * packet to be sent. Called with lock held.
582 unsigned long e8390_base = dev->base_addr; in ei_tx_intr()
592 ei_local->txqueue--; in ei_tx_intr()
594 if (ei_local->tx1 < 0) { in ei_tx_intr()
595 if (ei_local->lasttx != 1 && ei_local->lasttx != -1) in ei_tx_intr()
597 ei_local->name, ei_local->lasttx, ei_local->tx1); in ei_tx_intr()
598 ei_local->tx1 = 0; in ei_tx_intr()
599 if (ei_local->tx2 > 0) { in ei_tx_intr()
600 ei_local->txing = 1; in ei_tx_intr()
601 NS8390_trigger_send(dev, ei_local->tx2, ei_local->tx_start_page + 6); in ei_tx_intr()
603 ei_local->tx2 = -1; in ei_tx_intr()
604 ei_local->lasttx = 2; in ei_tx_intr()
606 ei_local->lasttx = 20; in ei_tx_intr()
607 ei_local->txing = 0; in ei_tx_intr()
609 } else if (ei_local->tx2 < 0) { in ei_tx_intr()
610 if (ei_local->lasttx != 2 && ei_local->lasttx != -2) in ei_tx_intr()
612 ei_local->name, ei_local->lasttx, ei_local->tx2); in ei_tx_intr()
613 ei_local->tx2 = 0; in ei_tx_intr()
614 if (ei_local->tx1 > 0) { in ei_tx_intr()
615 ei_local->txing = 1; in ei_tx_intr()
616 NS8390_trigger_send(dev, ei_local->tx1, ei_local->tx_start_page); in ei_tx_intr()
618 ei_local->tx1 = -1; in ei_tx_intr()
619 ei_local->lasttx = 1; in ei_tx_intr()
621 ei_local->lasttx = 10; in ei_tx_intr()
622 ei_local->txing = 0; in ei_tx_intr()
625 netdev_warn(dev, "unexpected TX-done interrupt, lasttx=%d\n", in ei_tx_intr()
626 ei_local->lasttx); in ei_tx_intr()
629 /* Minimize Tx latency: update the statistics after we restart TXing. */ in ei_tx_intr()
631 dev->stats.collisions++; in ei_tx_intr()
633 dev->stats.tx_packets++; in ei_tx_intr()
635 dev->stats.tx_errors++; in ei_tx_intr()
637 dev->stats.tx_aborted_errors++; in ei_tx_intr()
638 dev->stats.collisions += 16; in ei_tx_intr()
641 dev->stats.tx_carrier_errors++; in ei_tx_intr()
643 dev->stats.tx_fifo_errors++; in ei_tx_intr()
645 dev->stats.tx_heartbeat_errors++; in ei_tx_intr()
647 dev->stats.tx_window_errors++; in ei_tx_intr()
653 * ei_receive - receive some packets
657 * Called with lock held.
662 unsigned long e8390_base = dev->base_addr; in ei_receive()
668 int num_rx_pages = ei_local->stop_page-ei_local->rx_start_page; in ei_receive()
680 if (this_frame >= ei_local->stop_page) in ei_receive()
681 this_frame = ei_local->rx_start_page; in ei_receive()
690 this_frame != ei_local->current_page && in ei_receive()
694 this_frame, ei_local->current_page); in ei_receive()
702 pkt_len = rx_frame.count - sizeof(struct e8390_pkt_hdr); in ei_receive()
712 rx_frame.next != next_frame - num_rx_pages && in ei_receive()
713 rx_frame.next != next_frame + 1 - num_rx_pages) { in ei_receive()
714 ei_local->current_page = rxing_page; in ei_receive()
715 ei_outb(ei_local->current_page-1, e8390_base+EN0_BOUNDARY); in ei_receive()
716 dev->stats.rx_errors++; in ei_receive()
725 dev->stats.rx_errors++; in ei_receive()
726 dev->stats.rx_length_errors++; in ei_receive()
735 dev->stats.rx_dropped++; in ei_receive()
741 skb->protocol = eth_type_trans(skb, dev); in ei_receive()
744 dev->stats.rx_packets++; in ei_receive()
745 dev->stats.rx_bytes += pkt_len; in ei_receive()
747 dev->stats.multicast++; in ei_receive()
754 dev->stats.rx_errors++; in ei_receive()
757 dev->stats.rx_fifo_errors++; in ei_receive()
762 if (next_frame >= ei_local->stop_page) { in ei_receive()
765 next_frame = ei_local->rx_start_page; in ei_receive()
767 ei_local->current_page = next_frame; in ei_receive()
768 ei_outb_p(next_frame-1, e8390_base+EN0_BOUNDARY); in ei_receive()
777 * ei_rx_overrun - handle receiver overrun
781 * again. Problem is that you have to kick it exactly as NS prescribes in
785 * Called with lock held. Don't call this with the interrupts off or your
786 * computer will hate you - it takes 10ms or so.
791 unsigned long e8390_base = dev->base_addr; in ei_rx_overrun()
804 dev->stats.rx_over_errors++; in ei_rx_overrun()
807 * Wait a full Tx time (1.2ms) + some guard time, NS says 1.6ms total. in ei_rx_overrun()
822 * See if any Tx was interrupted or not. According to NS, this in ei_rx_overrun()
859 unsigned long ioaddr = dev->base_addr; in __ei_get_stats()
865 return &dev->stats; in __ei_get_stats()
867 spin_lock_irqsave(&ei_local->page_lock, flags); in __ei_get_stats()
869 dev->stats.rx_frame_errors += ei_inb_p(ioaddr + EN0_COUNTER0); in __ei_get_stats()
870 dev->stats.rx_crc_errors += ei_inb_p(ioaddr + EN0_COUNTER1); in __ei_get_stats()
871 dev->stats.rx_missed_errors += ei_inb_p(ioaddr + EN0_COUNTER2); in __ei_get_stats()
872 spin_unlock_irqrestore(&ei_local->page_lock, flags); in __ei_get_stats()
874 return &dev->stats; in __ei_get_stats()
887 u32 crc = ether_crc(ETH_ALEN, ha->addr); in make_mc_bits()
897 * do_set_multicast_list - set/clear multicast filter
901 * from a BH in 2.1.x. Must be called with lock held.
906 unsigned long e8390_base = dev->base_addr; in do_set_multicast_list()
910 if (!(dev->flags&(IFF_PROMISC|IFF_ALLMULTI))) { in do_set_multicast_list()
911 memset(ei_local->mcfilter, 0, 8); in do_set_multicast_list()
913 make_mc_bits(ei_local->mcfilter, dev); in do_set_multicast_list()
915 memset(ei_local->mcfilter, 0xFF, 8); /* mcast set to accept-all */ in do_set_multicast_list()
925 * Elite16) appear to be write-only. The NS 8390 data sheet lists in do_set_multicast_list()
934 ei_outb_p(ei_local->mcfilter[i], e8390_base + EN1_MULT_SHIFT(i)); in do_set_multicast_list()
936 if (ei_inb_p(e8390_base + EN1_MULT_SHIFT(i)) != ei_local->mcfilter[i]) in do_set_multicast_list()
943 if (dev->flags&IFF_PROMISC) in do_set_multicast_list()
945 else if (dev->flags & IFF_ALLMULTI || !netdev_mc_empty(dev)) in do_set_multicast_list()
952 * Called without lock held. This is invoked from user context and may
962 spin_lock_irqsave(&ei_local->page_lock, flags); in __ei_set_multicast_list()
964 spin_unlock_irqrestore(&ei_local->page_lock, flags); in __ei_set_multicast_list()
968 * ethdev_setup - init rest of 8390 device struct
981 spin_lock_init(&ei_local->page_lock); in ethdev_setup()
983 ei_local->msg_enable = netif_msg_init(msg_enable, default_msg_level); in ethdev_setup()
990 * alloc_ei_netdev - alloc_etherdev counterpart for 8390
993 * Allocate 8390-specific net_device.
1008 * NS8390_init - initialize 8390 hardware
1010 * @startp: boolean. non-zero value to initiate chip processing
1012 * Must be called with lock held.
1017 unsigned long e8390_base = dev->base_addr; in __NS8390_init()
1020 int endcfg = ei_local->word16 in __NS8390_init()
1021 ? (0x48 | ENDCFG_WTS | (ei_local->bigendian ? ENDCFG_BOS : 0)) in __NS8390_init()
1031 /* Set to monitor and loopback mode -- this is vital!. */ in __NS8390_init()
1035 ei_outb_p(ei_local->tx_start_page, e8390_base + EN0_TPSR); in __NS8390_init()
1036 ei_local->tx1 = ei_local->tx2 = 0; in __NS8390_init()
1037 ei_outb_p(ei_local->rx_start_page, e8390_base + EN0_STARTPG); in __NS8390_init()
1038 ei_outb_p(ei_local->stop_page-1, e8390_base + EN0_BOUNDARY); /* 3c503 says 0x3f,NS0x26*/ in __NS8390_init()
1039 ei_local->current_page = ei_local->rx_start_page; /* assert boundary+1 */ in __NS8390_init()
1040 ei_outb_p(ei_local->stop_page, e8390_base + EN0_STOPPG); in __NS8390_init()
1049 ei_outb_p(dev->dev_addr[i], e8390_base + EN1_PHYS_SHIFT(i)); in __NS8390_init()
1051 ei_inb_p(e8390_base + EN1_PHYS_SHIFT(i)) != dev->dev_addr[i]) in __NS8390_init()
1056 ei_outb_p(ei_local->rx_start_page, e8390_base + EN1_CURPAG); in __NS8390_init()
1059 ei_local->tx1 = ei_local->tx2 = 0; in __NS8390_init()
1060 ei_local->txing = 0; in __NS8390_init()
1074 Always called with the page lock held */
1079 unsigned long e8390_base = dev->base_addr; in NS8390_trigger_send()