net/mlx4: simplify Rx buffer handling
[dpdk.git] / drivers / net / mlx5 / mlx5_rxtx_vec_sse.c
index 9be48a0..37854a7 100644 (file)
 #pragma GCC diagnostic error "-Wpedantic"
 #endif
 
-/* DPDK headers don't like -pedantic. */
-#ifdef PEDANTIC
-#pragma GCC diagnostic ignored "-Wpedantic"
-#endif
 #include <rte_mbuf.h>
 #include <rte_mempool.h>
 #include <rte_prefetch.h>
-#ifdef PEDANTIC
-#pragma GCC diagnostic error "-Wpedantic"
-#endif
 
 #include "mlx5.h"
 #include "mlx5_utils.h"
@@ -829,8 +822,9 @@ rxq_cq_to_ptype_oflags_v(struct rxq *rxq, __m128i cqes[4], __m128i op_err,
        ptype = _mm_and_si128(ptype, ptype_mask);
        pinfo = _mm_and_si128(pinfo, pinfo_mask);
        pinfo = _mm_slli_epi32(pinfo, 16);
-       ptype = _mm_or_si128(ptype, pinfo);
-       ptype = _mm_srli_epi32(ptype, 10);
+       /* Make pinfo has merged fields for ol_flags calculation. */
+       pinfo = _mm_or_si128(ptype, pinfo);
+       ptype = _mm_srli_epi32(pinfo, 10);
        ptype = _mm_packs_epi32(ptype, zero);
        /* Errored packets will have RTE_PTYPE_ALL_MASK. */
        op_err = _mm_srli_epi16(op_err, 8);
@@ -886,16 +880,28 @@ rxq_handle_pending_error(struct rxq *rxq, struct rte_mbuf **pkts,
 {
        uint16_t n = 0;
        unsigned int i;
+#ifdef MLX5_PMD_SOFT_COUNTERS
+       uint32_t err_bytes = 0;
+#endif
 
        for (i = 0; i < pkts_n; ++i) {
                struct rte_mbuf *pkt = pkts[i];
 
-               if (pkt->packet_type == RTE_PTYPE_ALL_MASK)
+               if (pkt->packet_type == RTE_PTYPE_ALL_MASK) {
+#ifdef MLX5_PMD_SOFT_COUNTERS
+                       err_bytes += PKT_LEN(pkt);
+#endif
                        rte_pktmbuf_free_seg(pkt);
-               else
+               } else {
                        pkts[n++] = pkt;
+               }
        }
        rxq->stats.idropped += (pkts_n - n);
+#ifdef MLX5_PMD_SOFT_COUNTERS
+       /* Correct counters of errored completions. */
+       rxq->stats.ipackets -= (pkts_n - n);
+       rxq->stats.ibytes -= err_bytes;
+#endif
        rxq->pending_err = 0;
        return n;
 }
@@ -1310,7 +1316,8 @@ priv_check_raw_vec_tx_support(struct priv *priv)
 int __attribute__((cold))
 priv_check_vec_tx_support(struct priv *priv)
 {
-       if (priv->txqs_n > MLX5_VPMD_MIN_TXQS ||
+       if (!priv->tx_vec_en ||
+           priv->txqs_n > MLX5_VPMD_MIN_TXQS ||
            priv->mps != MLX5_MPW_ENHANCED ||
            priv->tso)
                return -ENOTSUP;
@@ -1329,7 +1336,9 @@ priv_check_vec_tx_support(struct priv *priv)
 int __attribute__((cold))
 rxq_check_vec_support(struct rxq *rxq)
 {
-       if (rxq->sges_n != 0)
+       struct rxq_ctrl *ctrl = container_of(rxq, struct rxq_ctrl, rxq);
+
+       if (!ctrl->priv->rx_vec_en || rxq->sges_n != 0)
                return -ENOTSUP;
        return 1;
 }
@@ -1348,6 +1357,8 @@ priv_check_vec_rx_support(struct priv *priv)
 {
        uint16_t i;
 
+       if (!priv->rx_vec_en)
+               return -ENOTSUP;
        /* All the configured queues should support. */
        for (i = 0; i < priv->rxqs_n; ++i) {
                struct rxq *rxq = (*priv->rxqs)[i];
@@ -1359,41 +1370,3 @@ priv_check_vec_rx_support(struct priv *priv)
                return -ENOTSUP;
        return 1;
 }
-
-/**
- * Prepare for vectorized RX.
- *
- * @param priv
- *   Pointer to private structure.
- */
-void
-priv_prep_vec_rx_function(struct priv *priv)
-{
-       uint16_t i;
-
-       for (i = 0; i < priv->rxqs_n; ++i) {
-               struct rxq *rxq = (*priv->rxqs)[i];
-               struct rte_mbuf *mbuf_init = &rxq->fake_mbuf;
-               const uint16_t desc = 1 << rxq->elts_n;
-               int j;
-
-               assert(rxq->elts_n == rxq->cqe_n);
-               /* Initialize default rearm_data for vPMD. */
-               mbuf_init->data_off = RTE_PKTMBUF_HEADROOM;
-               rte_mbuf_refcnt_set(mbuf_init, 1);
-               mbuf_init->nb_segs = 1;
-               mbuf_init->port = rxq->port_id;
-               /*
-                * prevent compiler reordering:
-                * rearm_data covers previous fields.
-                */
-               rte_compiler_barrier();
-               rxq->mbuf_initializer =
-                       *(uint64_t *)&mbuf_init->rearm_data;
-               /* Padding with a fake mbuf for vectorized Rx. */
-               for (j = 0; j < MLX5_VPMD_DESCS_PER_LOOP; ++j)
-                       (*rxq->elts)[desc + j] = &rxq->fake_mbuf;
-               /* Mark that it need to be cleaned up for rxq_alloc_elts(). */
-               rxq->trim_elts = 1;
-       }
-}