net/qede: free packets in bulk
[dpdk.git] / drivers / net / qede / qede_rxtx.c
index 9878ba5..f439ee0 100644 (file)
@@ -393,6 +393,7 @@ qede_alloc_tx_queue_mem(struct rte_eth_dev *dev,
        struct ecore_dev *edev = &qdev->edev;
        struct qede_tx_queue *txq;
        int rc;
+       size_t sw_tx_ring_size;
 
        txq = rte_zmalloc_socket("qede_tx_queue", sizeof(struct qede_tx_queue),
                                 RTE_CACHE_LINE_SIZE, socket_id);
@@ -425,9 +426,9 @@ qede_alloc_tx_queue_mem(struct rte_eth_dev *dev,
        }
 
        /* Allocate software ring */
+       sw_tx_ring_size = sizeof(txq->sw_tx_ring) * txq->nb_tx_desc;
        txq->sw_tx_ring = rte_zmalloc_socket("txq->sw_tx_ring",
-                                            (sizeof(struct qede_tx_entry) *
-                                             txq->nb_tx_desc),
+                                            sw_tx_ring_size,
                                             RTE_CACHE_LINE_SIZE, socket_id);
 
        if (!txq->sw_tx_ring) {
@@ -523,9 +524,9 @@ static void qede_tx_queue_release_mbufs(struct qede_tx_queue *txq)
 
        if (txq->sw_tx_ring) {
                for (i = 0; i < txq->nb_tx_desc; i++) {
-                       if (txq->sw_tx_ring[i].mbuf) {
-                               rte_pktmbuf_free(txq->sw_tx_ring[i].mbuf);
-                               txq->sw_tx_ring[i].mbuf = NULL;
+                       if (txq->sw_tx_ring[i]) {
+                               rte_pktmbuf_free(txq->sw_tx_ring[i]);
+                               txq->sw_tx_ring[i] = NULL;
                        }
                }
        }
@@ -647,8 +648,6 @@ int qede_alloc_fp_resc(struct qede_dev *qdev)
 
        for (sb_idx = 0; sb_idx < QEDE_RXTX_MAX(qdev); sb_idx++) {
                fp = &qdev->fp_array[sb_idx];
-               if (!fp)
-                       continue;
                fp->sb_info = rte_calloc("sb", 1, sizeof(struct ecore_sb_info),
                                RTE_CACHE_LINE_SIZE);
                if (!fp->sb_info) {
@@ -678,11 +677,9 @@ void qede_dealloc_fp_resc(struct rte_eth_dev *eth_dev)
 
        for (sb_idx = 0; sb_idx < QEDE_RXTX_MAX(qdev); sb_idx++) {
                fp = &qdev->fp_array[sb_idx];
-               if (!fp)
-                       continue;
-               DP_INFO(edev, "Free sb_info index 0x%x\n",
-                               fp->sb_info->igu_sb_id);
                if (fp->sb_info) {
+                       DP_INFO(edev, "Free sb_info index 0x%x\n",
+                                       fp->sb_info->igu_sb_id);
                        OSAL_DMA_FREE_COHERENT(edev, fp->sb_info->sb_virt,
                                fp->sb_info->sb_phys,
                                sizeof(struct status_block));
@@ -886,51 +883,59 @@ qede_tx_queue_start(struct rte_eth_dev *eth_dev, uint16_t tx_queue_id)
 }
 
 static inline void
-qede_free_tx_pkt(struct qede_tx_queue *txq)
+qede_process_tx_compl(__rte_unused struct ecore_dev *edev,
+                     struct qede_tx_queue *txq)
 {
+       uint16_t hw_bd_cons;
+       uint16_t sw_tx_cons;
+       uint16_t remaining;
+       uint16_t mask;
        struct rte_mbuf *mbuf;
        uint16_t nb_segs;
        uint16_t idx;
+       uint16_t first_idx;
 
-       idx = TX_CONS(txq);
-       mbuf = txq->sw_tx_ring[idx].mbuf;
-       if (mbuf) {
+       rte_compiler_barrier();
+       sw_tx_cons = ecore_chain_get_cons_idx(&txq->tx_pbl);
+       hw_bd_cons = rte_le_to_cpu_16(*txq->hw_cons_ptr);
+#ifdef RTE_LIBRTE_QEDE_DEBUG_TX
+       PMD_TX_LOG(DEBUG, txq, "Tx Completions = %u\n",
+                  abs(hw_bd_cons - sw_tx_cons));
+#endif
+
+       mask = NUM_TX_BDS(txq);
+       idx = txq->sw_tx_cons & mask;
+
+       remaining = hw_bd_cons - sw_tx_cons;
+       txq->nb_tx_avail += remaining;
+       first_idx = idx;
+
+       while (remaining) {
+               mbuf = txq->sw_tx_ring[idx];
+               RTE_ASSERT(mbuf);
                nb_segs = mbuf->nb_segs;
+               remaining -= nb_segs;
+
                PMD_TX_LOG(DEBUG, txq, "nb_segs to free %u\n", nb_segs);
+
                while (nb_segs) {
-                       /* It's like consuming rxbuf in recv() */
                        ecore_chain_consume(&txq->tx_pbl);
-                       txq->nb_tx_avail++;
                        nb_segs--;
                }
-               rte_pktmbuf_free(mbuf);
-               txq->sw_tx_ring[idx].mbuf = NULL;
-               txq->sw_tx_cons++;
+
+               idx = (idx + 1) & mask;
                PMD_TX_LOG(DEBUG, txq, "Freed tx packet\n");
-       } else {
-               ecore_chain_consume(&txq->tx_pbl);
-               txq->nb_tx_avail++;
        }
-}
-
-static inline void
-qede_process_tx_compl(__rte_unused struct ecore_dev *edev,
-                     struct qede_tx_queue *txq)
-{
-       uint16_t hw_bd_cons;
-#ifdef RTE_LIBRTE_QEDE_DEBUG_TX
-       uint16_t sw_tx_cons;
-#endif
+       txq->sw_tx_cons = idx;
 
-       rte_compiler_barrier();
-       hw_bd_cons = rte_le_to_cpu_16(*txq->hw_cons_ptr);
-#ifdef RTE_LIBRTE_QEDE_DEBUG_TX
-       sw_tx_cons = ecore_chain_get_cons_idx(&txq->tx_pbl);
-       PMD_TX_LOG(DEBUG, txq, "Tx Completions = %u\n",
-                  abs(hw_bd_cons - sw_tx_cons));
-#endif
-       while (hw_bd_cons !=  ecore_chain_get_cons_idx(&txq->tx_pbl))
-               qede_free_tx_pkt(txq);
+       if (first_idx > idx) {
+               rte_pktmbuf_free_bulk(&txq->sw_tx_ring[first_idx],
+                                                         mask - first_idx + 1);
+               rte_pktmbuf_free_bulk(&txq->sw_tx_ring[0], idx);
+       } else {
+               rte_pktmbuf_free_bulk(&txq->sw_tx_ring[first_idx],
+                                                         idx - first_idx);
+       }
 }
 
 static int qede_drain_txq(struct qede_dev *qdev,
@@ -1636,7 +1641,7 @@ qede_recv_pkts_regular(void *p_rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                                        "Outer L3 csum failed, flags = 0x%x\n",
                                        parse_flag);
                                rxq->rx_hw_errors++;
-                               ol_flags |= PKT_RX_EIP_CKSUM_BAD;
+                               ol_flags |= PKT_RX_OUTER_IP_CKSUM_BAD;
                        } else {
                                ol_flags |= PKT_RX_IP_CKSUM_GOOD;
                        }
@@ -1905,7 +1910,7 @@ qede_recv_pkts(void *p_rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                                        "Outer L3 csum failed, flags = 0x%x\n",
                                        parse_flag);
                                  rxq->rx_hw_errors++;
-                                 ol_flags |= PKT_RX_EIP_CKSUM_BAD;
+                                 ol_flags |= PKT_RX_OUTER_IP_CKSUM_BAD;
                        } else {
                                  ol_flags |= PKT_RX_IP_CKSUM_GOOD;
                        }
@@ -2247,7 +2252,7 @@ qede_xmit_pkts_regular(void *p_txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
        struct eth_tx_3rd_bd *bd3;
        struct rte_mbuf *m_seg = NULL;
        struct rte_mbuf *mbuf;
-       struct qede_tx_entry *sw_tx_ring;
+       struct rte_mbuf **sw_tx_ring;
        uint16_t nb_tx_pkts;
        uint16_t bd_prod;
        uint16_t idx;
@@ -2310,7 +2315,7 @@ qede_xmit_pkts_regular(void *p_txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 
                /* Fill the entry in the SW ring and the BDs in the FW ring */
                idx = TX_PROD(txq);
-               sw_tx_ring[idx].mbuf = mbuf;
+               sw_tx_ring[idx] = mbuf;
 
                /* BD1 */
                bd1 = (struct eth_tx_1st_bd *)ecore_chain_produce(&txq->tx_pbl);
@@ -2616,7 +2621,7 @@ qede_xmit_pkts(void *p_txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 
                /* Fill the entry in the SW ring and the BDs in the FW ring */
                idx = TX_PROD(txq);
-               txq->sw_tx_ring[idx].mbuf = mbuf;
+               txq->sw_tx_ring[idx] = mbuf;
 
                /* BD1 */
                bd1 = (struct eth_tx_1st_bd *)ecore_chain_produce(&txq->tx_pbl);