vserver 1.9.3
[linux-2.6.git] / drivers / net / 8139too.c
index 58290c5..2a94719 100644 (file)
@@ -593,6 +593,7 @@ struct rtl8139_private {
        int time_to_die;
        struct mii_if_info mii;
        unsigned int regs_len;
+       unsigned long fifo_copy_timeout;
 };
 
 MODULE_AUTHOR ("Jeff Garzik <jgarzik@pobox.com>");
@@ -613,7 +614,7 @@ static int rtl8139_open (struct net_device *dev);
 static int mdio_read (struct net_device *dev, int phy_id, int location);
 static void mdio_write (struct net_device *dev, int phy_id, int location,
                        int val);
-static inline void rtl8139_start_thread(struct net_device *dev);
+static void rtl8139_start_thread(struct net_device *dev);
 static void rtl8139_tx_timeout (struct net_device *dev);
 static void rtl8139_init_ring (struct net_device *dev);
 static int rtl8139_start_xmit (struct sk_buff *skb,
@@ -1643,7 +1644,7 @@ static int rtl8139_thread (void *data)
        complete_and_exit (&tp->thr_exited, 0);
 }
 
-static inline void rtl8139_start_thread(struct net_device *dev)
+static void rtl8139_start_thread(struct net_device *dev)
 {
        struct rtl8139_private *tp = dev->priv;
 
@@ -1927,6 +1928,24 @@ static __inline__ void wrap_copy(struct sk_buff *skb, const unsigned char *ring,
 }
 #endif
 
+static void rtl8139_isr_ack(struct rtl8139_private *tp)
+{
+       void *ioaddr = tp->mmio_addr;
+       u16 status;
+
+       status = RTL_R16 (IntrStatus) & RxAckBits;
+
+       /* Clear out errors and receive interrupts */
+       if (likely(status != 0)) {
+               if (unlikely(status & (RxFIFOOver | RxOverflow))) {
+                       tp->stats.rx_errors++;
+                       if (status & RxFIFOOver)
+                               tp->stats.rx_fifo_errors++;
+               }
+               RTL_W16_F (IntrStatus, RxAckBits);
+       }
+}
+
 static int rtl8139_rx(struct net_device *dev, struct rtl8139_private *tp,
                      int budget)
 {
@@ -1934,9 +1953,10 @@ static int rtl8139_rx(struct net_device *dev, struct rtl8139_private *tp,
        int received = 0;
        unsigned char *rx_ring = tp->rx_ring;
        unsigned int cur_rx = tp->cur_rx;
+       unsigned int rx_size = 0;
 
        DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x,"
-                " free to %4.4x, Cmd %2.2x.\n", dev->name, cur_rx,
+                " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx,
                 RTL_R16 (RxBufAddr),
                 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
 
@@ -1944,10 +1964,8 @@ static int rtl8139_rx(struct net_device *dev, struct rtl8139_private *tp,
               && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) {
                u32 ring_offset = cur_rx % RX_BUF_LEN;
                u32 rx_status;
-               unsigned int rx_size;
                unsigned int pkt_size;
                struct sk_buff *skb;
-               u16 status;
 
                rmb();
 
@@ -1976,10 +1994,24 @@ static int rtl8139_rx(struct net_device *dev, struct rtl8139_private *tp,
                 * since EarlyRx is disabled.
                 */
                if (unlikely(rx_size == 0xfff0)) {
+                       if (!tp->fifo_copy_timeout)
+                               tp->fifo_copy_timeout = jiffies + 2;
+                       else if (time_after(jiffies, tp->fifo_copy_timeout)) {
+                               DPRINTK ("%s: hung FIFO. Reset.", dev->name);
+                               rx_size = 0;
+                               goto no_early_rx;
+                       }
+                       if (netif_msg_intr(tp)) {
+                               printk(KERN_DEBUG "%s: fifo copy in progress.",
+                                      dev->name);
+                       }
                        tp->xstats.early_rx++;
-                       goto done;
+                       break;
                }
 
+no_early_rx:
+               tp->fifo_copy_timeout = 0;
+
                /* If Rx err or invalid rx_size/rx_status received
                 * (which happens if we get lost in the ring),
                 * Rx process gets reset, so we abort any further
@@ -1989,7 +2021,8 @@ static int rtl8139_rx(struct net_device *dev, struct rtl8139_private *tp,
                             (rx_size < 8) ||
                             (!(rx_status & RxStatusOK)))) {
                        rtl8139_rx_err (rx_status, dev, tp, ioaddr);
-                       return -1;
+                       received = -1;
+                       goto out;
                }
 
                /* Malloc up new buffer, compatible with net-2e. */
@@ -2025,19 +2058,11 @@ static int rtl8139_rx(struct net_device *dev, struct rtl8139_private *tp,
                cur_rx = (cur_rx + rx_size + 4 + 3) & ~3;
                RTL_W16 (RxBufPtr, (u16) (cur_rx - 16));
 
-               /* Clear out errors and receive interrupts */
-               status = RTL_R16 (IntrStatus) & RxAckBits;
-               if (likely(status != 0)) {
-                       if (unlikely(status & (RxFIFOOver | RxOverflow))) {
-                               tp->stats.rx_errors++;
-                               if (status & RxFIFOOver)
-                                       tp->stats.rx_fifo_errors++;
-                       }
-                       RTL_W16_F (IntrStatus, RxAckBits);
-               }
+               rtl8139_isr_ack(tp);
        }
 
- done:
+       if (unlikely(!received || rx_size == 0xfff0))
+               rtl8139_isr_ack(tp);
 
 #if RTL8139_DEBUG > 1
        DPRINTK ("%s: Done rtl8139_rx(), current %4.4x BufAddr %4.4x,"
@@ -2047,6 +2072,15 @@ static int rtl8139_rx(struct net_device *dev, struct rtl8139_private *tp,
 #endif
 
        tp->cur_rx = cur_rx;
+
+       /*
+        * The receive buffer should be mostly empty.
+        * Tell NAPI to reenable the Rx irq.
+        */
+       if (tp->fifo_copy_timeout)
+               received = budget;
+
+out:
        return received;
 }