[jme] Fix refill behavior
authorGuo-Fu Tseng <cooldavid@cooldavid.org>
Fri, 4 Jun 2010 05:02:34 +0000 (13:02 +0800)
committerGuo-Fu Tseng <cooldavid@cooldavid.org>
Fri, 4 Jun 2010 05:02:34 +0000 (13:02 +0800)
After changed driver behavior to refill after feed, if any error occurs
will introduce non-contiguous empty buffer in the ring. Due to my
reuse-buffer-when-error implementation.

src/drivers/net/jme.c

index 441eb8a..3f9174f 100644 (file)
@@ -590,20 +590,29 @@ jme_disable_rx_engine(struct jme_adapter *jme)
 }
 
 static void
-jme_refill_rx_ring(struct jme_adapter *jme)
+jme_refill_rx_ring(struct jme_adapter *jme, int idx)
 {
        struct jme_ring *rxring = &jme->rxring;
-       int i = rxring->next_to_fill;
+       int i = rxring->next_to_fill, lasthole;
        struct io_buffer **bufinf = rxring->bufinf;
        int mask = jme->rx_ring_mask;
+       int limit = jme->rx_ring_size;
 
-       while (!bufinf[i]) {
-               if (jme_make_new_rx_buf(bufinf + i))
+       lasthole = i;
+       while (limit--) {
+               if (!bufinf[i]) {
+                       lasthole = i;
+                       if (jme_make_new_rx_buf(bufinf + i))
+                               break;
+                       jme_set_clean_rxdesc(jme, i);
+               }
+               if (i == idx) {
+                       lasthole = (i + 1) & mask;
                        break;
-               jme_set_clean_rxdesc(jme, i);
+               }
                i = (i + 1) & mask;
        }
-       rxring->next_to_fill = i;
+       rxring->next_to_fill = lasthole;
 }
 
 static void
@@ -622,7 +631,7 @@ jme_alloc_and_feed_iob(struct jme_adapter *jme, int idx)
        netdev_rx(netdev, rxbi);
 
        rxring->bufinf[idx] = NULL;
-       jme_refill_rx_ring(jme);
+       jme_refill_rx_ring(jme, idx);
 }
 
 static void
@@ -636,7 +645,8 @@ jme_process_receive(struct jme_adapter *jme)
 
        i = rxring->next_to_clean;
        rxdesc += i;
-       while (!(rxdesc->descwb.flags & cpu_to_le16(RXWBFLAG_OWN)) &&
+       while (rxring->bufinf[i] &&
+               !(rxdesc->descwb.flags & cpu_to_le16(RXWBFLAG_OWN)) &&
                (rxdesc->descwb.desccnt & RXWBDCNT_WBCPL) &&
                limit--) {