net/enetc: use bulk alloc in Rx refill ring
[dpdk.git] / drivers / net / enetc / enetc_rxtx.c
index b7ecb75..8b85c53 100644 (file)
@@ -14,7 +14,7 @@
 #include "enetc.h"
 #include "enetc_logs.h"
 
-#define ENETC_RXBD_BUNDLE 8 /* Number of BDs to update at once */
+#define ENETC_RXBD_BUNDLE 16 /* Number of buffers to allocate at once */
 
 static int
 enetc_clean_tx_ring(struct enetc_bdr *tx_ring)
@@ -23,12 +23,15 @@ enetc_clean_tx_ring(struct enetc_bdr *tx_ring)
        struct enetc_swbd *tx_swbd;
        int i, hwci;
 
+       /* we don't need barriers here, we just want a relatively current value
+        * from HW.
+        */
+       hwci = (int)(rte_read32_relaxed(tx_ring->tcisr) &
+                    ENETC_TBCISR_IDX_MASK);
+
        i = tx_ring->next_to_clean;
        tx_swbd = &tx_ring->q_swbd[i];
 
-       hwci = (int)(enetc_rd_reg(tx_ring->tcisr) &
-                    ENETC_TBCISR_IDX_MASK);
-
        /* we're only reading the CI index once here, which means HW may update
         * it while we're doing clean-up.  We could read the register in a loop
         * but for now I assume it's OK to leave a few Tx frames for next call.
@@ -73,7 +76,6 @@ enetc_xmit_pkts(void *tx_queue,
 
        start = 0;
        while (nb_pkts--) {
-               enetc_clean_tx_ring(tx_ring);
                tx_ring->q_swbd[i].buffer_addr = tx_pkts[start];
                txbd = ENETC_TXBD(*tx_ring, i);
                tx_swbd = &tx_ring->q_swbd[i];
@@ -89,6 +91,14 @@ enetc_xmit_pkts(void *tx_queue,
                        i = 0;
        }
 
+       /* we're only cleaning up the Tx ring here, on the assumption that
+        * software is slower than hardware and hardware completed sending
+        * older frames out by now.
+        * We're also cleaning up the ring before kicking off Tx for the new
+        * batch to minimize chances of contention on the Tx ring
+        */
+       enetc_clean_tx_ring(tx_ring);
+
        tx_ring->next_to_use = i;
        enetc_wr_reg(tx_ring->tcir, i);
        return start;
@@ -99,15 +109,25 @@ enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt)
 {
        struct enetc_swbd *rx_swbd;
        union enetc_rx_bd *rxbd;
-       int i, j;
+       int i, j, k = ENETC_RXBD_BUNDLE;
+       struct rte_mbuf *m[ENETC_RXBD_BUNDLE];
+       struct rte_mempool *mb_pool;
 
        i = rx_ring->next_to_use;
+       mb_pool = rx_ring->mb_pool;
        rx_swbd = &rx_ring->q_swbd[i];
        rxbd = ENETC_RXBD(*rx_ring, i);
        for (j = 0; j < buff_cnt; j++) {
-               rx_swbd->buffer_addr = (void *)(uintptr_t)
-                       rte_cpu_to_le_64((uint64_t)(uintptr_t)
-                                       rte_pktmbuf_alloc(rx_ring->mb_pool));
+               /* bulk alloc for the next up to 8 BDs */
+               if (k == ENETC_RXBD_BUNDLE) {
+                       k = 0;
+                       int m_cnt = RTE_MIN(buff_cnt - j, ENETC_RXBD_BUNDLE);
+
+                       if (rte_pktmbuf_alloc_bulk(mb_pool, m, m_cnt))
+                               return -1;
+               }
+
+               rx_swbd->buffer_addr = m[k];
                rxbd->w.addr = (uint64_t)(uintptr_t)
                               rx_swbd->buffer_addr->buf_iova +
                               rx_swbd->buffer_addr->data_off;
@@ -116,6 +136,7 @@ enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt)
                rx_swbd++;
                rxbd++;
                i++;
+               k++;
                if (unlikely(i == rx_ring->bd_count)) {
                        i = 0;
                        rxbd = ENETC_RXBD(*rx_ring, 0);
@@ -295,12 +316,6 @@ enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
                union enetc_rx_bd *rxbd;
                uint32_t bd_status;
 
-               if (cleaned_cnt >= ENETC_RXBD_BUNDLE) {
-                       int count = enetc_refill_rx_ring(rx_ring, cleaned_cnt);
-
-                       cleaned_cnt -= count;
-               }
-
                rxbd = ENETC_RXBD(*rx_ring, i);
                bd_status = rte_le_to_cpu_32(rxbd->r.lstatus);
                if (!bd_status)
@@ -327,6 +342,8 @@ enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
                rx_frm_cnt++;
        }
 
+       enetc_refill_rx_ring(rx_ring, cleaned_cnt);
+
        return rx_frm_cnt;
 }