net/mlx5: enforce Tx num of segments limitation
[dpdk.git] / drivers / net / mlx5 / mlx5_rxtx_vec_sse.c
index 67f63c6..39c7325 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"
@@ -119,8 +112,7 @@ txq_wr_dseg_v(struct txq *txq, __m128i *dseg,
 }
 
 /**
- * Count the number of continuous single segment packets. The first packet must
- * be a single segment packet.
+ * Count the number of continuous single segment packets.
  *
  * @param pkts
  *   Pointer to array of packets.
@@ -137,9 +129,8 @@ txq_check_multiseg(struct rte_mbuf **pkts, uint16_t pkts_n)
 
        if (!pkts_n)
                return 0;
-       assert(NB_SEGS(pkts[0]) == 1);
        /* Count the number of continuous single segment packets. */
-       for (pos = 1; pos < pkts_n; ++pos)
+       for (pos = 0; pos < pkts_n; ++pos)
                if (NB_SEGS(pkts[pos]) > 1)
                        break;
        return pos;
@@ -257,6 +248,10 @@ txq_scatter_v(struct txq *txq, struct rte_mbuf **pkts, uint16_t pkts_n)
                if (segs_n == 1 ||
                    max_elts < segs_n || max_wqe < 2)
                        break;
+               if (segs_n > MLX5_MPW_DSEG_MAX) {
+                       txq->stats.oerrors++;
+                       break;
+               }
                wqe = &((volatile struct mlx5_wqe64 *)
                         txq->wqes)[wqe_ci & wq_mask].hdr;
                if (buf->ol_flags &
@@ -374,6 +369,7 @@ txq_burst_v(struct txq *txq, struct rte_mbuf **pkts, uint16_t pkts_n,
        max_elts = (elts_n - (elts_head - txq->elts_tail));
        max_wqe = (1u << txq->wqe_n) - (txq->wqe_ci - txq->wqe_pi);
        pkts_n = RTE_MIN((unsigned int)RTE_MIN(pkts_n, max_wqe), max_elts);
+       assert(pkts_n <= MLX5_DSEG_MAX - nb_dword_in_hdr);
        if (unlikely(!pkts_n))
                return 0;
        elts = &(*txq->elts)[elts_head & elts_m];