Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2017 6WIND S.A.
3 : : * Copyright 2017 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #include <stdint.h>
7 : : #include <string.h>
8 : : #include <stdlib.h>
9 : :
10 : : #include <rte_mbuf.h>
11 : : #include <rte_mempool.h>
12 : : #include <rte_prefetch.h>
13 : : #include <rte_vect.h>
14 : :
15 : : #include <mlx5_glue.h>
16 : : #include <mlx5_prm.h>
17 : :
18 : : #include "mlx5_defs.h"
19 : : #include "mlx5.h"
20 : : #include "mlx5_utils.h"
21 : : #include "mlx5_rxtx.h"
22 : : #include "mlx5_rx.h"
23 : : #include "mlx5_rxtx_vec.h"
24 : : #include "mlx5_autoconf.h"
25 : :
26 : : #if defined RTE_ARCH_X86_64
27 : : #include "mlx5_rxtx_vec_sse.h"
28 : : #elif defined RTE_ARCH_ARM64
29 : : #include "mlx5_rxtx_vec_neon.h"
30 : : #elif defined RTE_ARCH_PPC_64
31 : : #include "mlx5_rxtx_vec_altivec.h"
32 : : #else
33 : : #error "This should not be compiled if SIMD instructions are not supported."
34 : : #endif
35 : :
36 : : /**
37 : : * Skip error packets.
38 : : *
39 : : * @param rxq
40 : : * Pointer to RX queue structure.
41 : : * @param[out] pkts
42 : : * Array to store received packets.
43 : : * @param pkts_n
44 : : * Maximum number of packets in array.
45 : : *
46 : : * @return
47 : : * Number of packets successfully received (<= pkts_n).
48 : : */
49 : : static uint16_t
50 : 0 : rxq_handle_pending_error(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts,
51 : : uint16_t pkts_n)
52 : : {
53 : : uint16_t n = 0;
54 : : uint16_t skip_cnt;
55 : : unsigned int i;
56 : : #ifdef MLX5_PMD_SOFT_COUNTERS
57 : : uint32_t err_bytes = 0;
58 : : #endif
59 : :
60 [ # # ]: 0 : for (i = 0; i < pkts_n; ++i) {
61 : 0 : struct rte_mbuf *pkt = pkts[i];
62 : :
63 [ # # # # ]: 0 : if (pkt->packet_type == RTE_PTYPE_ALL_MASK || rxq->err_state) {
64 : : #ifdef MLX5_PMD_SOFT_COUNTERS
65 : 0 : err_bytes += PKT_LEN(pkt);
66 : : #endif
67 : : rte_pktmbuf_free_seg(pkt);
68 : : } else {
69 : 0 : pkts[n++] = pkt;
70 : : }
71 : : }
72 : 0 : rxq->stats.idropped += (pkts_n - n);
73 : : #ifdef MLX5_PMD_SOFT_COUNTERS
74 : : /* Correct counters of errored completions. */
75 : 0 : rxq->stats.ipackets -= (pkts_n - n);
76 : 0 : rxq->stats.ibytes -= err_bytes;
77 : : #endif
78 : 0 : mlx5_rx_err_handle(rxq, 1, pkts_n, &skip_cnt);
79 : 0 : return n;
80 : : }
81 : :
82 : : /**
83 : : * Replenish buffers for RX in bulk.
84 : : *
85 : : * @param rxq
86 : : * Pointer to RX queue structure.
87 : : */
88 : : static inline void
89 : 0 : mlx5_rx_replenish_bulk_mbuf(struct mlx5_rxq_data *rxq)
90 : : {
91 : 0 : const uint16_t q_n = 1 << rxq->elts_n;
92 : 0 : const uint16_t q_mask = q_n - 1;
93 : 0 : uint16_t n = q_n - (rxq->rq_ci - rxq->rq_pi);
94 : 0 : uint16_t elts_idx = rxq->rq_ci & q_mask;
95 : 0 : struct rte_mbuf **elts = &(*rxq->elts)[elts_idx];
96 : 0 : volatile struct mlx5_wqe_data_seg *wq =
97 : 0 : &((volatile struct mlx5_wqe_data_seg *)rxq->wqes)[elts_idx];
98 : : unsigned int i;
99 : :
100 [ # # ]: 0 : if (n >= rxq->rq_repl_thresh) {
101 : : MLX5_ASSERT(n >= MLX5_VPMD_RXQ_RPLNSH_THRESH(q_n));
102 : : MLX5_ASSERT(MLX5_VPMD_RXQ_RPLNSH_THRESH(q_n) >
103 : : MLX5_VPMD_DESCS_PER_LOOP);
104 : : /* Not to cross queue end. */
105 : 0 : n = RTE_MIN(n - MLX5_VPMD_DESCS_PER_LOOP, q_n - elts_idx);
106 [ # # # # ]: 0 : if (rte_mempool_get_bulk(rxq->mp, (void *)elts, n) < 0) {
107 : 0 : rxq->stats.rx_nombuf += n;
108 : : /*
109 : : * A failed bulk get may have partially filled elts[]
110 : : * from the cache without dequeueing those objects.
111 : : * Restore the fake_mbuf guards so a following
112 : : * decompression does not write into mbufs that are
113 : : * still owned by the mempool (or by the application).
114 : : */
115 [ # # ]: 0 : for (i = 0; i < MLX5_VPMD_DESCS_PER_LOOP; ++i)
116 : 0 : elts[i] = &rxq->fake_mbuf;
117 : : return;
118 : : }
119 [ # # ]: 0 : if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1)) {
120 [ # # ]: 0 : for (i = 0; i < n; ++i) {
121 : : /*
122 : : * In order to support the mbufs with external attached
123 : : * data buffer we should use the buf_addr pointer
124 : : * instead of rte_mbuf_buf_addr(). It touches the mbuf
125 : : * itself and may impact the performance.
126 : : */
127 : 0 : void *buf_addr = elts[i]->buf_addr;
128 : :
129 [ # # # # ]: 0 : wq[i].addr = rte_cpu_to_be_64((uintptr_t)buf_addr +
130 : : RTE_PKTMBUF_HEADROOM);
131 : 0 : wq[i].lkey = mlx5_rx_mb2mr(rxq, elts[i]);
132 : : }
133 : : } else {
134 [ # # ]: 0 : for (i = 0; i < n; ++i) {
135 : 0 : void *buf_addr = elts[i]->buf_addr;
136 : :
137 [ # # ]: 0 : wq[i].addr = rte_cpu_to_be_64((uintptr_t)buf_addr +
138 : : RTE_PKTMBUF_HEADROOM);
139 : : }
140 : : }
141 : 0 : rxq->rq_ci += n;
142 : : /* Prevent overflowing into consumed mbufs. */
143 : 0 : elts_idx = rxq->rq_ci & q_mask;
144 [ # # ]: 0 : for (i = 0; i < MLX5_VPMD_DESCS_PER_LOOP; ++i)
145 : 0 : (*rxq->elts)[elts_idx + i] = &rxq->fake_mbuf;
146 : 0 : rte_io_wmb();
147 [ # # ]: 0 : *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
148 : : }
149 : : }
150 : :
151 : : /**
152 : : * Replenish buffers for MPRQ RX in bulk.
153 : : *
154 : : * @param rxq
155 : : * Pointer to RX queue structure.
156 : : */
157 : : static inline void
158 : 0 : mlx5_rx_mprq_replenish_bulk_mbuf(struct mlx5_rxq_data *rxq)
159 : : {
160 : 0 : const uint16_t wqe_n = 1 << rxq->elts_n;
161 : 0 : const uint32_t strd_n = RTE_BIT32(rxq->log_strd_num);
162 : 0 : const uint32_t elts_n = wqe_n * strd_n;
163 : 0 : const uint32_t wqe_mask = elts_n - 1;
164 : 0 : uint32_t n = elts_n - (rxq->elts_ci - rxq->rq_pi);
165 : 0 : uint32_t elts_idx = rxq->elts_ci & wqe_mask;
166 : 0 : struct rte_mbuf **elts = &(*rxq->elts)[elts_idx];
167 : : unsigned int i;
168 : :
169 [ # # ]: 0 : if (n >= rxq->rq_repl_thresh &&
170 : 0 : rxq->elts_ci - rxq->rq_pi <=
171 [ # # ]: 0 : rxq->rq_repl_thresh + MLX5_VPMD_RX_MAX_BURST) {
172 : : MLX5_ASSERT(n >= MLX5_VPMD_RXQ_RPLNSH_THRESH(elts_n));
173 : : MLX5_ASSERT(MLX5_VPMD_RXQ_RPLNSH_THRESH(elts_n) >
174 : : MLX5_VPMD_DESCS_PER_LOOP);
175 : : /* Not to cross queue end. */
176 : 0 : n = RTE_MIN(n - MLX5_VPMD_DESCS_PER_LOOP, elts_n - elts_idx);
177 : : /* Limit replenish number to threshold value. */
178 : 0 : n = RTE_MIN(n, rxq->rq_repl_thresh);
179 [ # # # # ]: 0 : if (rte_mempool_get_bulk(rxq->mp, (void *)elts, n) < 0) {
180 : 0 : rxq->stats.rx_nombuf += n;
181 : : /* See mlx5_rx_replenish_bulk_mbuf(). */
182 [ # # ]: 0 : for (i = 0; i < MLX5_VPMD_DESCS_PER_LOOP; ++i)
183 : 0 : elts[i] = &rxq->fake_mbuf;
184 : : return;
185 : : }
186 : 0 : rxq->elts_ci += n;
187 : : /* Prevent overflowing into consumed mbufs. */
188 : 0 : elts_idx = rxq->elts_ci & wqe_mask;
189 [ # # ]: 0 : for (i = 0; i < MLX5_VPMD_DESCS_PER_LOOP; ++i)
190 : 0 : (*rxq->elts)[elts_idx + i] = &rxq->fake_mbuf;
191 : : }
192 : : }
193 : :
194 : : /**
195 : : * Copy or attach MPRQ buffers to RX SW ring.
196 : : *
197 : : * @param rxq
198 : : * Pointer to RX queue structure.
199 : : * @param pkts
200 : : * Pointer to array of packets to be stored.
201 : : * @param pkts_n
202 : : * Number of packets to be stored.
203 : : *
204 : : * @return
205 : : * Number of packets successfully copied/attached (<= pkts_n).
206 : : */
207 : : static inline uint16_t
208 : 0 : rxq_copy_mprq_mbuf_v(struct mlx5_rxq_data *rxq,
209 : : struct rte_mbuf **pkts, uint16_t pkts_n)
210 : : {
211 : 0 : const uint16_t wqe_n = 1 << rxq->elts_n;
212 : 0 : const uint16_t wqe_mask = wqe_n - 1;
213 : 0 : const uint16_t strd_sz = RTE_BIT32(rxq->log_strd_sz);
214 : 0 : const uint32_t strd_n = RTE_BIT32(rxq->log_strd_num);
215 : 0 : const uint32_t elts_n = wqe_n * strd_n;
216 : 0 : const uint32_t elts_mask = elts_n - 1;
217 : 0 : uint32_t elts_idx = rxq->rq_pi & elts_mask;
218 : 0 : struct rte_mbuf **elts = &(*rxq->elts)[elts_idx];
219 : 0 : uint32_t rq_ci = rxq->rq_ci;
220 : 0 : struct mlx5_mprq_buf *buf = (*rxq->mprq_bufs)[rq_ci & wqe_mask];
221 : : uint16_t copied = 0;
222 : : uint16_t i = 0;
223 : :
224 [ # # ]: 0 : for (i = 0; i < pkts_n; ++i) {
225 : : uint16_t strd_cnt;
226 : : enum mlx5_rqx_code rxq_code;
227 : :
228 [ # # ]: 0 : if (rxq->consumed_strd == strd_n) {
229 : : /* Replace WQE if the buffer is still in use. */
230 [ # # ]: 0 : mprq_buf_replace(rxq, rq_ci & wqe_mask);
231 : : /* Advance to the next WQE. */
232 : 0 : rxq->consumed_strd = 0;
233 : 0 : rq_ci++;
234 : 0 : buf = (*rxq->mprq_bufs)[rq_ci & wqe_mask];
235 : : }
236 : :
237 [ # # ]: 0 : if (!elts[i]->pkt_len) {
238 : 0 : rxq->consumed_strd = strd_n;
239 : : rte_pktmbuf_free_seg(elts[i]);
240 : : #ifdef MLX5_PMD_SOFT_COUNTERS
241 : 0 : rxq->stats.ipackets -= 1;
242 : : #endif
243 : 0 : continue;
244 : : }
245 : 0 : strd_cnt = (elts[i]->pkt_len / strd_sz) +
246 [ # # ]: 0 : ((elts[i]->pkt_len % strd_sz) ? 1 : 0);
247 : : /* Drop and realign if the stride index drifted past the
248 : : * buffer, rather than letting mprq_buf_to_pkt() index
249 : : * past shinfos[] and the stride region (bug 1369).
250 : : */
251 [ # # ]: 0 : if (unlikely(rxq->consumed_strd + strd_cnt > strd_n)) {
252 : 0 : rxq->consumed_strd = strd_n;
253 : : rte_pktmbuf_free_seg(elts[i]);
254 : : #ifdef MLX5_PMD_SOFT_COUNTERS
255 : 0 : rxq->stats.ipackets -= 1;
256 : 0 : rxq->stats.ibytes -= elts[i]->pkt_len;
257 : : #endif
258 : 0 : ++rxq->stats.idropped;
259 : 0 : continue;
260 : : }
261 : : rxq_code = mprq_buf_to_pkt(rxq, elts[i], elts[i]->pkt_len,
262 : : buf, rxq->consumed_strd, strd_cnt);
263 : 0 : rxq->consumed_strd += strd_cnt;
264 [ # # ]: 0 : if (unlikely(rxq_code != MLX5_RXQ_CODE_EXIT)) {
265 : 0 : rte_pktmbuf_free_seg(elts[i]);
266 : : #ifdef MLX5_PMD_SOFT_COUNTERS
267 : 0 : rxq->stats.ipackets -= 1;
268 : 0 : rxq->stats.ibytes -= elts[i]->pkt_len;
269 : : #endif
270 [ # # ]: 0 : if (rxq_code == MLX5_RXQ_CODE_NOMBUF) {
271 : 0 : ++rxq->stats.rx_nombuf;
272 : 0 : break;
273 : : }
274 [ # # ]: 0 : if (rxq_code == MLX5_RXQ_CODE_DROPPED) {
275 : 0 : ++rxq->stats.idropped;
276 : 0 : continue;
277 : : }
278 : : }
279 : 0 : pkts[copied++] = elts[i];
280 : : }
281 : 0 : rxq->rq_pi += i;
282 : 0 : rxq->cq_ci += i;
283 [ # # ]: 0 : if (rq_ci != rxq->rq_ci) {
284 : 0 : rxq->rq_ci = rq_ci;
285 : 0 : rte_io_wmb();
286 [ # # ]: 0 : *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
287 : : }
288 : 0 : return copied;
289 : : }
290 : :
291 : : /**
292 : : * Receive burst of packets. An errored completion also consumes a mbuf, but the
293 : : * packet_type is set to be RTE_PTYPE_ALL_MASK. Marked mbufs should be freed
294 : : * before returning to application.
295 : : *
296 : : * @param rxq
297 : : * Pointer to RX queue structure.
298 : : * @param[out] pkts
299 : : * Array to store received packets.
300 : : * @param pkts_n
301 : : * Maximum number of packets in array.
302 : : * @param[out] err
303 : : * Pointer to a flag. Set non-zero value if pkts array has at least one error
304 : : * packet to handle.
305 : : * @param[out] no_cq
306 : : * Pointer to a boolean. Set true if no new CQE seen.
307 : : *
308 : : * @return
309 : : * Number of packets received including errors (<= pkts_n).
310 : : */
311 : : static inline uint16_t
312 : 0 : rxq_burst_v(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts,
313 : : uint16_t pkts_n, uint64_t *err, bool *no_cq)
314 : : {
315 : 0 : const uint16_t q_n = 1 << rxq->cqe_n;
316 : 0 : const uint16_t q_mask = q_n - 1;
317 : 0 : const uint16_t e_n = 1 << rxq->elts_n;
318 : 0 : const uint16_t e_mask = e_n - 1;
319 : : volatile struct mlx5_cqe *cq, *next;
320 : : struct rte_mbuf **elts;
321 : 0 : uint64_t comp_idx = MLX5_VPMD_DESCS_PER_LOOP;
322 : : uint16_t nocmp_n = 0;
323 : : uint16_t rcvd_pkt = 0;
324 : 0 : unsigned int cq_idx = rxq->cq_ci & q_mask;
325 : : unsigned int elts_idx;
326 : : int ret;
327 : :
328 : : MLX5_ASSERT(rxq->sges_n == 0);
329 : : MLX5_ASSERT(rxq->cqe_n == rxq->elts_n);
330 : 0 : cq = &(*rxq->cqes)[cq_idx];
331 : : rte_prefetch0(cq);
332 : 0 : rte_prefetch0(cq + 1);
333 : 0 : rte_prefetch0(cq + 2);
334 : 0 : rte_prefetch0(cq + 3);
335 : 0 : pkts_n = RTE_MIN(pkts_n, MLX5_VPMD_RX_MAX_BURST);
336 : 0 : mlx5_rx_replenish_bulk_mbuf(rxq);
337 : : /* See if there're unreturned mbufs from compressed CQE. */
338 : 0 : rcvd_pkt = rxq->decompressed;
339 [ # # ]: 0 : if (rcvd_pkt > 0) {
340 : 0 : rcvd_pkt = RTE_MIN(rcvd_pkt, pkts_n);
341 : 0 : rxq_copy_mbuf_v(&(*rxq->elts)[rxq->rq_pi & e_mask],
342 : : pkts, rcvd_pkt);
343 : 0 : rxq->rq_pi += rcvd_pkt;
344 : 0 : rxq->decompressed -= rcvd_pkt;
345 : 0 : pkts += rcvd_pkt;
346 : : }
347 : 0 : elts_idx = rxq->rq_pi & e_mask;
348 : 0 : elts = &(*rxq->elts)[elts_idx];
349 : : /* Not to overflow pkts array. */
350 : 0 : pkts_n = RTE_ALIGN_FLOOR(pkts_n - rcvd_pkt, MLX5_VPMD_DESCS_PER_LOOP);
351 : : /* Not to cross queue end. */
352 : 0 : pkts_n = RTE_MIN(pkts_n, q_n - elts_idx);
353 : 0 : pkts_n = RTE_MIN(pkts_n, q_n - cq_idx);
354 : : /* Not to move past the allocated mbufs. */
355 : 0 : pkts_n = RTE_MIN(pkts_n, RTE_ALIGN_FLOOR(rxq->rq_ci - rxq->rq_pi,
356 : : MLX5_VPMD_DESCS_PER_LOOP));
357 [ # # ]: 0 : if (!pkts_n) {
358 : 0 : *no_cq = !rcvd_pkt;
359 : 0 : return rcvd_pkt;
360 : : }
361 : : /* At this point, there shouldn't be any remaining packets. */
362 : : MLX5_ASSERT(rxq->decompressed == 0);
363 : : /* Go directly to unzipping in case the first CQE is compressed. */
364 [ # # ]: 0 : if (rxq->cqe_comp_layout) {
365 [ # # ]: 0 : ret = check_cqe_iteration(cq, rxq->cqe_n, rxq->cq_ci);
366 : 0 : if (ret == MLX5_CQE_STATUS_SW_OWN &&
367 [ # # ]: 0 : (MLX5_CQE_FORMAT(cq->op_own) == MLX5_COMPRESSED)) {
368 : 0 : comp_idx = 0;
369 : 0 : goto decompress;
370 : : }
371 : : }
372 : : /* Process all the CQEs */
373 : 0 : nocmp_n = rxq_cq_process_v(rxq, cq, elts, pkts, pkts_n, err, &comp_idx);
374 : : /* If no new CQE seen, return without updating cq_db. */
375 [ # # # # ]: 0 : if (unlikely(!nocmp_n && comp_idx == MLX5_VPMD_DESCS_PER_LOOP)) {
376 : 0 : *no_cq = true;
377 : 0 : return rcvd_pkt;
378 : : }
379 : : /* Update the consumer indexes for non-compressed CQEs. */
380 : : MLX5_ASSERT(nocmp_n <= pkts_n);
381 : 0 : rxq->cq_ci += nocmp_n;
382 : 0 : rxq->rq_pi += nocmp_n;
383 : 0 : rcvd_pkt += nocmp_n;
384 : : /* Copy title packet for future compressed sessions. */
385 [ # # ]: 0 : if (rxq->cqe_comp_layout) {
386 [ # # ]: 0 : ret = check_cqe_iteration(cq, rxq->cqe_n, rxq->cq_ci);
387 : 0 : if (ret == MLX5_CQE_STATUS_SW_OWN &&
388 [ # # ]: 0 : (MLX5_CQE_FORMAT(cq->op_own) != MLX5_COMPRESSED)) {
389 : 0 : next = &(*rxq->cqes)[rxq->cq_ci & q_mask];
390 [ # # ]: 0 : ret = check_cqe_iteration(next, rxq->cqe_n, rxq->cq_ci);
391 [ # # # # ]: 0 : if (MLX5_CQE_FORMAT(next->op_own) == MLX5_COMPRESSED ||
392 : : ret != MLX5_CQE_STATUS_SW_OWN)
393 [ # # ]: 0 : rte_memcpy(&rxq->title_pkt, elts[nocmp_n - 1],
394 : : sizeof(struct rte_mbuf));
395 : : }
396 : : }
397 : 0 : decompress:
398 : : /* Decompress the last CQE if compressed. */
399 [ # # ]: 0 : if (comp_idx < MLX5_VPMD_DESCS_PER_LOOP) {
400 : : MLX5_ASSERT(comp_idx == (nocmp_n % MLX5_VPMD_DESCS_PER_LOOP));
401 : 0 : rxq->decompressed = rxq_cq_decompress_v(rxq, &cq[nocmp_n],
402 : 0 : &elts[nocmp_n], true);
403 : 0 : rxq->cq_ci += rxq->decompressed;
404 : : /* Return more packets if needed. */
405 [ # # ]: 0 : if (nocmp_n < pkts_n) {
406 : : uint16_t n = rxq->decompressed;
407 : :
408 : 0 : n = RTE_MIN(n, pkts_n - nocmp_n);
409 : 0 : rxq_copy_mbuf_v(&(*rxq->elts)[rxq->rq_pi & e_mask],
410 : : &pkts[nocmp_n], n);
411 : 0 : rxq->rq_pi += n;
412 : 0 : rcvd_pkt += n;
413 : 0 : rxq->decompressed -= n;
414 : : }
415 : : }
416 : 0 : *no_cq = !rcvd_pkt;
417 : 0 : return rcvd_pkt;
418 : : }
419 : :
420 : : /**
421 : : * DPDK callback for vectorized RX.
422 : : *
423 : : * @param dpdk_rxq
424 : : * Generic pointer to RX queue structure.
425 : : * @param[out] pkts
426 : : * Array to store received packets.
427 : : * @param pkts_n
428 : : * Maximum number of packets in array.
429 : : *
430 : : * @return
431 : : * Number of packets successfully received (<= pkts_n).
432 : : */
433 : : uint16_t
434 : 0 : mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
435 : : {
436 : : struct mlx5_rxq_data *rxq = dpdk_rxq;
437 : : uint16_t nb_rx = 0;
438 : : uint16_t tn = 0;
439 : : uint64_t err = 0;
440 : 0 : bool no_cq = false;
441 : :
442 : : do {
443 : 0 : err = 0;
444 : 0 : nb_rx = rxq_burst_v(rxq, pkts + tn, pkts_n - tn,
445 : : &err, &no_cq);
446 [ # # ]: 0 : if (unlikely(err | rxq->err_state))
447 : 0 : nb_rx = rxq_handle_pending_error(rxq, pkts + tn, nb_rx);
448 : 0 : tn += nb_rx;
449 [ # # ]: 0 : if (unlikely(no_cq))
450 : : break;
451 : 0 : rte_io_wmb();
452 [ # # ]: 0 : *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
453 [ # # ]: 0 : } while (tn != pkts_n);
454 : 0 : return tn;
455 : : }
456 : :
457 : : /**
458 : : * Receive burst of packets. An errored completion also consumes a mbuf, but the
459 : : * packet_type is set to be RTE_PTYPE_ALL_MASK. Marked mbufs should be freed
460 : : * before returning to application.
461 : : *
462 : : * @param rxq
463 : : * Pointer to RX queue structure.
464 : : * @param[out] pkts
465 : : * Array to store received packets.
466 : : * @param pkts_n
467 : : * Maximum number of packets in array.
468 : : * @param[out] err
469 : : * Pointer to a flag. Set non-zero value if pkts array has at least one error
470 : : * packet to handle.
471 : : * @param[out] no_cq
472 : : * Pointer to a boolean. Set true if no new CQE seen.
473 : : *
474 : : * @return
475 : : * Number of packets received including errors (<= pkts_n).
476 : : */
477 : : static inline uint16_t
478 : 0 : rxq_burst_mprq_v(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts,
479 : : uint16_t pkts_n, uint64_t *err, bool *no_cq)
480 : : {
481 : 0 : const uint16_t q_n = 1 << rxq->cqe_n;
482 : 0 : const uint16_t q_mask = q_n - 1;
483 : 0 : const uint16_t wqe_n = 1 << rxq->elts_n;
484 : 0 : const uint32_t strd_n = RTE_BIT32(rxq->log_strd_num);
485 : 0 : const uint32_t elts_n = wqe_n * strd_n;
486 : 0 : const uint32_t elts_mask = elts_n - 1;
487 : : volatile struct mlx5_cqe *cq, *next;
488 : : struct rte_mbuf **elts;
489 : 0 : uint64_t comp_idx = MLX5_VPMD_DESCS_PER_LOOP;
490 : : uint16_t nocmp_n = 0;
491 : : uint16_t rcvd_pkt = 0;
492 : : uint16_t cp_pkt = 0;
493 : 0 : unsigned int cq_idx = rxq->cq_ci & q_mask;
494 : : unsigned int elts_idx;
495 : : int ret;
496 : :
497 : : MLX5_ASSERT(rxq->sges_n == 0);
498 : 0 : cq = &(*rxq->cqes)[cq_idx];
499 : : rte_prefetch0(cq);
500 : 0 : rte_prefetch0(cq + 1);
501 : 0 : rte_prefetch0(cq + 2);
502 : 0 : rte_prefetch0(cq + 3);
503 : 0 : pkts_n = RTE_MIN(pkts_n, MLX5_VPMD_RX_MAX_BURST);
504 : 0 : mlx5_rx_mprq_replenish_bulk_mbuf(rxq);
505 : : /* Not to move past the allocated mbufs. */
506 : 0 : pkts_n = RTE_MIN(pkts_n, rxq->elts_ci - rxq->rq_pi);
507 : : /* See if there're unreturned mbufs from compressed CQE. */
508 : 0 : rcvd_pkt = rxq->decompressed;
509 [ # # ]: 0 : if (rcvd_pkt > 0) {
510 : 0 : rcvd_pkt = RTE_MIN(rcvd_pkt, pkts_n);
511 : 0 : cp_pkt = rxq_copy_mprq_mbuf_v(rxq, pkts, rcvd_pkt);
512 : 0 : rxq->decompressed -= rcvd_pkt;
513 : 0 : pkts += cp_pkt;
514 : : }
515 : 0 : elts_idx = rxq->rq_pi & elts_mask;
516 : 0 : elts = &(*rxq->elts)[elts_idx];
517 : : /* Not to overflow pkts array. */
518 : 0 : pkts_n = RTE_ALIGN_FLOOR(pkts_n - cp_pkt, MLX5_VPMD_DESCS_PER_LOOP);
519 : : /* Not to cross queue end. */
520 : 0 : pkts_n = RTE_MIN(pkts_n, elts_n - elts_idx);
521 : 0 : pkts_n = RTE_MIN(pkts_n, q_n - cq_idx);
522 [ # # ]: 0 : if (!pkts_n) {
523 : 0 : *no_cq = !cp_pkt;
524 : 0 : return cp_pkt;
525 : : }
526 : : /* At this point, there shouldn't be any remaining packets. */
527 : : MLX5_ASSERT(rxq->decompressed == 0);
528 : : /* Go directly to unzipping in case the first CQE is compressed. */
529 [ # # ]: 0 : if (rxq->cqe_comp_layout) {
530 [ # # ]: 0 : ret = check_cqe_iteration(cq, rxq->cqe_n, rxq->cq_ci);
531 : 0 : if (ret == MLX5_CQE_STATUS_SW_OWN &&
532 [ # # ]: 0 : (MLX5_CQE_FORMAT(cq->op_own) == MLX5_COMPRESSED)) {
533 : 0 : comp_idx = 0;
534 : 0 : goto decompress;
535 : : }
536 : : }
537 : : /* Process all the CQEs */
538 : 0 : nocmp_n = rxq_cq_process_v(rxq, cq, elts, pkts, pkts_n, err, &comp_idx);
539 : : /* If no new CQE seen, return without updating cq_db. */
540 [ # # # # ]: 0 : if (unlikely(!nocmp_n && comp_idx == MLX5_VPMD_DESCS_PER_LOOP)) {
541 : 0 : *no_cq = true;
542 : 0 : return cp_pkt;
543 : : }
544 : : /* Update the consumer indexes for non-compressed CQEs. */
545 : : MLX5_ASSERT(nocmp_n <= pkts_n);
546 : 0 : cp_pkt = rxq_copy_mprq_mbuf_v(rxq, pkts, nocmp_n);
547 : 0 : rcvd_pkt += cp_pkt;
548 : : /* Copy title packet for future compressed sessions. */
549 [ # # ]: 0 : if (rxq->cqe_comp_layout) {
550 [ # # ]: 0 : ret = check_cqe_iteration(cq, rxq->cqe_n, rxq->cq_ci);
551 : 0 : if (ret == MLX5_CQE_STATUS_SW_OWN &&
552 [ # # ]: 0 : (MLX5_CQE_FORMAT(cq->op_own) != MLX5_COMPRESSED)) {
553 : 0 : next = &(*rxq->cqes)[rxq->cq_ci & q_mask];
554 [ # # ]: 0 : ret = check_cqe_iteration(next, rxq->cqe_n, rxq->cq_ci);
555 [ # # # # ]: 0 : if (MLX5_CQE_FORMAT(next->op_own) == MLX5_COMPRESSED ||
556 : : ret != MLX5_CQE_STATUS_SW_OWN)
557 [ # # ]: 0 : rte_memcpy(&rxq->title_pkt, elts[nocmp_n - 1],
558 : : sizeof(struct rte_mbuf));
559 : : }
560 : : }
561 : 0 : decompress:
562 : : /* Decompress the last CQE if compressed. */
563 [ # # ]: 0 : if (comp_idx < MLX5_VPMD_DESCS_PER_LOOP) {
564 : : MLX5_ASSERT(comp_idx == (nocmp_n % MLX5_VPMD_DESCS_PER_LOOP));
565 : 0 : rxq->decompressed = rxq_cq_decompress_v(rxq, &cq[nocmp_n],
566 : 0 : &elts[nocmp_n], false);
567 : : /* Return more packets if needed. */
568 [ # # ]: 0 : if (nocmp_n < pkts_n) {
569 : : uint16_t n = rxq->decompressed;
570 : :
571 : 0 : n = RTE_MIN(n, pkts_n - nocmp_n);
572 : 0 : cp_pkt = rxq_copy_mprq_mbuf_v(rxq, &pkts[cp_pkt], n);
573 : 0 : rcvd_pkt += cp_pkt;
574 : 0 : rxq->decompressed -= n;
575 : : }
576 : : }
577 : 0 : *no_cq = !rcvd_pkt;
578 : 0 : return rcvd_pkt;
579 : : }
580 : :
581 : : /**
582 : : * DPDK callback for vectorized MPRQ RX.
583 : : *
584 : : * @param dpdk_rxq
585 : : * Generic pointer to RX queue structure.
586 : : * @param[out] pkts
587 : : * Array to store received packets.
588 : : * @param pkts_n
589 : : * Maximum number of packets in array.
590 : : *
591 : : * @return
592 : : * Number of packets successfully received (<= pkts_n).
593 : : */
594 : : uint16_t
595 : 0 : mlx5_rx_burst_mprq_vec(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
596 : : {
597 : : struct mlx5_rxq_data *rxq = dpdk_rxq;
598 : : uint16_t nb_rx = 0;
599 : : uint16_t tn = 0;
600 : : uint64_t err = 0;
601 : 0 : bool no_cq = false;
602 : :
603 : : do {
604 : 0 : err = 0;
605 : 0 : nb_rx = rxq_burst_mprq_v(rxq, pkts + tn, pkts_n - tn,
606 : : &err, &no_cq);
607 [ # # ]: 0 : if (unlikely(err | rxq->err_state))
608 : 0 : nb_rx = rxq_handle_pending_error(rxq, pkts + tn, nb_rx);
609 : 0 : tn += nb_rx;
610 [ # # ]: 0 : if (unlikely(no_cq))
611 : : break;
612 : 0 : rte_io_wmb();
613 [ # # ]: 0 : *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
614 [ # # ]: 0 : } while (tn != pkts_n);
615 : 0 : return tn;
616 : : }
617 : :
618 : : /**
619 : : * Check a RX queue can support vectorized RX.
620 : : *
621 : : * @param rxq
622 : : * Pointer to RX queue.
623 : : *
624 : : * @return
625 : : * 1 if supported, negative errno value if not.
626 : : */
627 : : int __rte_cold
628 : 0 : mlx5_rxq_check_vec_support(struct mlx5_rxq_data *rxq)
629 : : {
630 : : struct mlx5_rxq_ctrl *ctrl =
631 : : container_of(rxq, struct mlx5_rxq_ctrl, rxq);
632 : :
633 [ # # # # ]: 0 : if (!RXQ_PORT(ctrl)->config.rx_vec_en || rxq->sges_n != 0)
634 : : return -ENOTSUP;
635 [ # # ]: 0 : if (mlx5_shared_rq_enabled(RXQ_DEV(ctrl)))
636 : : return -ENOTSUP;
637 [ # # ]: 0 : if (rxq->lro)
638 : 0 : return -ENOTSUP;
639 : : return 1;
640 : : }
641 : :
642 : : /**
643 : : * Check a device can support vectorized RX.
644 : : *
645 : : * @param dev
646 : : * Pointer to Ethernet device.
647 : : *
648 : : * @return
649 : : * 1 if supported, negative errno value if not.
650 : : */
651 : : int __rte_cold
652 : 0 : mlx5_check_vec_rx_support(struct rte_eth_dev *dev)
653 : : {
654 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
655 : : uint32_t i;
656 : :
657 [ # # ]: 0 : if (rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128)
658 : : return -ENOTSUP;
659 [ # # ]: 0 : if (!priv->config.rx_vec_en)
660 : : return -ENOTSUP;
661 : : /* All the configured queues should support. */
662 [ # # ]: 0 : for (i = 0; i < priv->rxqs_n; ++i) {
663 : 0 : struct mlx5_rxq_data *rxq_data = mlx5_rxq_data_get(dev, i);
664 : :
665 [ # # ]: 0 : if (!rxq_data)
666 : 0 : continue;
667 [ # # ]: 0 : if (mlx5_rxq_check_vec_support(rxq_data) < 0)
668 : : break;
669 : : }
670 [ # # ]: 0 : if (i != priv->rxqs_n)
671 : 0 : return -ENOTSUP;
672 : : return 1;
673 : : }
|