1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017 6WIND S.A.
3 * Copyright 2017 Mellanox Technologies, Ltd
11 #include <rte_mempool.h>
12 #include <rte_prefetch.h>
15 #include <mlx5_glue.h>
18 #include "mlx5_defs.h"
20 #include "mlx5_utils.h"
21 #include "mlx5_rxtx.h"
22 #include "mlx5_rxtx_vec.h"
23 #include "mlx5_autoconf.h"
25 #if defined RTE_ARCH_X86_64
26 #include "mlx5_rxtx_vec_sse.h"
27 #elif defined RTE_ARCH_ARM64
28 #include "mlx5_rxtx_vec_neon.h"
29 #elif defined RTE_ARCH_PPC_64
30 #include "mlx5_rxtx_vec_altivec.h"
32 #error "This should not be compiled if SIMD instructions are not supported."
39 * Pointer to RX queue structure.
41 * Array to store received packets.
43 * Maximum number of packets in array.
46 * Number of packets successfully received (<= pkts_n).
49 rxq_handle_pending_error(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts,
54 #ifdef MLX5_PMD_SOFT_COUNTERS
55 uint32_t err_bytes = 0;
58 for (i = 0; i < pkts_n; ++i) {
59 struct rte_mbuf *pkt = pkts[i];
61 if (pkt->packet_type == RTE_PTYPE_ALL_MASK || rxq->err_state) {
62 #ifdef MLX5_PMD_SOFT_COUNTERS
63 err_bytes += PKT_LEN(pkt);
65 rte_pktmbuf_free_seg(pkt);
70 rxq->stats.idropped += (pkts_n - n);
71 #ifdef MLX5_PMD_SOFT_COUNTERS
72 /* Correct counters of errored completions. */
73 rxq->stats.ipackets -= (pkts_n - n);
74 rxq->stats.ibytes -= err_bytes;
76 mlx5_rx_err_handle(rxq, 1);
81 * Receive burst of packets. An errored completion also consumes a mbuf, but the
82 * packet_type is set to be RTE_PTYPE_ALL_MASK. Marked mbufs should be freed
83 * before returning to application.
86 * Pointer to RX queue structure.
88 * Array to store received packets.
90 * Maximum number of packets in array.
92 * Pointer to a flag. Set non-zero value if pkts array has at least one error
95 * Pointer to a boolean. Set true if no new CQE seen.
98 * Number of packets received including errors (<= pkts_n).
100 static inline uint16_t
101 rxq_burst_v(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts,
102 uint16_t pkts_n, uint64_t *err, bool *no_cq)
104 const uint16_t q_n = 1 << rxq->cqe_n;
105 const uint16_t q_mask = q_n - 1;
106 const uint16_t e_n = 1 << rxq->elts_n;
107 const uint16_t e_mask = e_n - 1;
108 volatile struct mlx5_cqe *cq;
109 struct rte_mbuf **elts;
110 uint64_t comp_idx = MLX5_VPMD_DESCS_PER_LOOP;
111 uint16_t nocmp_n = 0;
112 uint16_t rcvd_pkt = 0;
113 unsigned int cq_idx = rxq->cq_ci & q_mask;
114 unsigned int elts_idx;
116 MLX5_ASSERT(rxq->sges_n == 0);
117 MLX5_ASSERT(rxq->cqe_n == rxq->elts_n);
118 cq = &(*rxq->cqes)[cq_idx];
120 rte_prefetch0(cq + 1);
121 rte_prefetch0(cq + 2);
122 rte_prefetch0(cq + 3);
123 pkts_n = RTE_MIN(pkts_n, MLX5_VPMD_RX_MAX_BURST);
124 mlx5_rx_replenish_bulk_mbuf(rxq);
125 /* See if there're unreturned mbufs from compressed CQE. */
126 rcvd_pkt = rxq->decompressed;
128 rcvd_pkt = RTE_MIN(rcvd_pkt, pkts_n);
129 rxq_copy_mbuf_v(&(*rxq->elts)[rxq->rq_pi & e_mask],
131 rxq->rq_pi += rcvd_pkt;
132 rxq->decompressed -= rcvd_pkt;
135 elts_idx = rxq->rq_pi & e_mask;
136 elts = &(*rxq->elts)[elts_idx];
137 /* Not to overflow pkts array. */
138 pkts_n = RTE_ALIGN_FLOOR(pkts_n - rcvd_pkt, MLX5_VPMD_DESCS_PER_LOOP);
139 /* Not to cross queue end. */
140 pkts_n = RTE_MIN(pkts_n, q_n - elts_idx);
141 pkts_n = RTE_MIN(pkts_n, q_n - cq_idx);
146 /* At this point, there shouldn't be any remaining packets. */
147 MLX5_ASSERT(rxq->decompressed == 0);
148 /* Process all the CQEs */
149 nocmp_n = rxq_cq_process_v(rxq, cq, elts, pkts, pkts_n, err, &comp_idx);
150 /* If no new CQE seen, return without updating cq_db. */
151 if (unlikely(!nocmp_n && comp_idx == MLX5_VPMD_DESCS_PER_LOOP)) {
155 /* Update the consumer indexes for non-compressed CQEs. */
156 MLX5_ASSERT(nocmp_n <= pkts_n);
157 rxq->cq_ci += nocmp_n;
158 rxq->rq_pi += nocmp_n;
160 /* Decompress the last CQE if compressed. */
161 if (comp_idx < MLX5_VPMD_DESCS_PER_LOOP) {
162 MLX5_ASSERT(comp_idx == (nocmp_n % MLX5_VPMD_DESCS_PER_LOOP));
163 rxq->decompressed = rxq_cq_decompress_v(rxq, &cq[nocmp_n],
165 rxq->cq_ci += rxq->decompressed;
166 /* Return more packets if needed. */
167 if (nocmp_n < pkts_n) {
168 uint16_t n = rxq->decompressed;
170 n = RTE_MIN(n, pkts_n - nocmp_n);
171 rxq_copy_mbuf_v(&(*rxq->elts)[rxq->rq_pi & e_mask],
175 rxq->decompressed -= n;
179 *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
185 * DPDK callback for vectorized RX.
188 * Generic pointer to RX queue structure.
190 * Array to store received packets.
192 * Maximum number of packets in array.
195 * Number of packets successfully received (<= pkts_n).
198 mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
200 struct mlx5_rxq_data *rxq = dpdk_rxq;
207 nb_rx = rxq_burst_v(rxq, pkts + tn, pkts_n - tn, &err, &no_cq);
208 if (unlikely(err | rxq->err_state))
209 nb_rx = rxq_handle_pending_error(rxq, pkts + tn, nb_rx);
213 } while (tn != pkts_n);
218 * Check a RX queue can support vectorized RX.
221 * Pointer to RX queue.
224 * 1 if supported, negative errno value if not.
227 mlx5_rxq_check_vec_support(struct mlx5_rxq_data *rxq)
229 struct mlx5_rxq_ctrl *ctrl =
230 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
232 if (mlx5_mprq_enabled(ETH_DEV(ctrl->priv)))
234 if (!ctrl->priv->config.rx_vec_en || rxq->sges_n != 0)
242 * Check a device can support vectorized RX.
245 * Pointer to Ethernet device.
248 * 1 if supported, negative errno value if not.
251 mlx5_check_vec_rx_support(struct rte_eth_dev *dev)
253 struct mlx5_priv *priv = dev->data->dev_private;
256 if (rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128)
258 if (!priv->config.rx_vec_en)
260 if (mlx5_mprq_enabled(dev))
262 /* All the configured queues should support. */
263 for (i = 0; i < priv->rxqs_n; ++i) {
264 struct mlx5_rxq_data *rxq = (*priv->rxqs)[i];
268 if (mlx5_rxq_check_vec_support(rxq) < 0)
271 if (i != priv->rxqs_n)