Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2021 6WIND S.A.
3 : : * Copyright 2021 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #include <stdint.h>
7 : : #include <string.h>
8 : : #include <stdlib.h>
9 : :
10 : : #include <eal_export.h>
11 : : #include <rte_mbuf.h>
12 : : #include <rte_mempool.h>
13 : : #include <rte_prefetch.h>
14 : : #include <rte_common.h>
15 : : #include <rte_branch_prediction.h>
16 : : #include <rte_ether.h>
17 : : #include <rte_cycles.h>
18 : : #include <rte_flow.h>
19 : :
20 : : #include <mlx5_prm.h>
21 : : #include <mlx5_common.h>
22 : : #include <mlx5_common_mr.h>
23 : : #include <rte_pmd_mlx5.h>
24 : :
25 : : #include "mlx5_autoconf.h"
26 : : #include "mlx5_defs.h"
27 : : #include "mlx5.h"
28 : : #include "mlx5_utils.h"
29 : : #include "mlx5_rxtx.h"
30 : : #include "mlx5_devx.h"
31 : : #include "mlx5_rx.h"
32 : : #ifdef HAVE_MLX5_MSTFLINT
33 : : #include <mstflint/mtcr.h>
34 : : #endif
35 : :
36 : :
37 : : static __rte_always_inline uint32_t
38 : : rxq_cq_to_pkt_type(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe,
39 : : volatile struct mlx5_mini_cqe8 *mcqe);
40 : :
41 : : static __rte_always_inline int
42 : : mlx5_rx_poll_len(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe,
43 : : uint16_t cqe_n, uint16_t cqe_mask,
44 : : volatile struct mlx5_mini_cqe8 **mcqe,
45 : : uint16_t *skip_cnt, bool mprq, uint32_t *widx);
46 : :
47 : : static __rte_always_inline uint32_t
48 : : rxq_cq_to_ol_flags(volatile struct mlx5_cqe *cqe);
49 : :
50 : : static __rte_always_inline void
51 : : rxq_cq_to_mbuf(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt,
52 : : volatile struct mlx5_cqe *cqe,
53 : : volatile struct mlx5_mini_cqe8 *mcqe);
54 : :
55 : : static inline void
56 : : mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr *__rte_restrict tcp,
57 : : volatile struct mlx5_cqe *__rte_restrict cqe,
58 : : uint32_t phcsum, uint8_t l4_type);
59 : :
60 : : static inline void
61 : : mlx5_lro_update_hdr(uint8_t *__rte_restrict padd,
62 : : volatile struct mlx5_cqe *__rte_restrict cqe,
63 : : volatile struct mlx5_mini_cqe8 *mcqe,
64 : : struct mlx5_rxq_data *rxq, uint32_t len);
65 : :
66 : :
67 : : /**
68 : : * Internal function to compute the number of used descriptors in an RX queue.
69 : : *
70 : : * @param rxq
71 : : * The Rx queue.
72 : : *
73 : : * @return
74 : : * The number of used Rx descriptor.
75 : : */
76 : : static int
77 : 0 : rx_queue_count(struct mlx5_rxq_data *rxq)
78 : : {
79 : : struct rxq_zip *zip = &rxq->zip;
80 : : volatile struct mlx5_cqe *cqe;
81 : 0 : const unsigned int cqe_n = (1 << rxq->cqe_n);
82 : 0 : const unsigned int sges_n = (1 << rxq->sges_n);
83 : 0 : const unsigned int elts_n = (1 << rxq->elts_n);
84 : 0 : const unsigned int strd_n = RTE_BIT32(rxq->log_strd_num);
85 : 0 : const unsigned int cqe_cnt = cqe_n - 1;
86 : : unsigned int cq_ci, used;
87 : :
88 : : /* if we are processing a compressed cqe */
89 [ # # ]: 0 : if (zip->ai) {
90 : 0 : used = zip->cqe_cnt - zip->ai;
91 : 0 : cq_ci = zip->cq_ci;
92 : : } else {
93 : : used = 0;
94 : 0 : cq_ci = rxq->cq_ci;
95 : : }
96 : 0 : cqe = &(*rxq->cqes)[cq_ci & cqe_cnt];
97 [ # # ]: 0 : while (check_cqe(cqe, cqe_n, cq_ci) != MLX5_CQE_STATUS_HW_OWN) {
98 : : int8_t op_own;
99 : : unsigned int n;
100 : :
101 : 0 : op_own = cqe->op_own;
102 [ # # ]: 0 : if (MLX5_CQE_FORMAT(op_own) == MLX5_COMPRESSED)
103 : 0 : n = rte_be_to_cpu_32(cqe->byte_cnt);
104 : : else
105 : : n = 1;
106 : 0 : cq_ci += n;
107 : 0 : used += n;
108 : 0 : cqe = &(*rxq->cqes)[cq_ci & cqe_cnt];
109 : : }
110 : 0 : used = RTE_MIN(used * sges_n, elts_n * strd_n);
111 : 0 : return used;
112 : : }
113 : :
114 : : /**
115 : : * DPDK callback to check the status of a Rx descriptor.
116 : : *
117 : : * @param rx_queue
118 : : * The Rx queue.
119 : : * @param[in] offset
120 : : * The index of the descriptor in the ring.
121 : : *
122 : : * @return
123 : : * The status of the Rx descriptor.
124 : : */
125 : : int
126 : 0 : mlx5_rx_descriptor_status(void *rx_queue, uint16_t offset)
127 : : {
128 : : struct mlx5_rxq_data *rxq = rx_queue;
129 : :
130 [ # # ]: 0 : if (offset >= (1 << rxq->cqe_n)) {
131 : 0 : rte_errno = EINVAL;
132 : 0 : return -rte_errno;
133 : : }
134 [ # # ]: 0 : if (offset < rx_queue_count(rxq))
135 : 0 : return RTE_ETH_RX_DESC_DONE;
136 : : return RTE_ETH_RX_DESC_AVAIL;
137 : : }
138 : :
139 : : /* Get rxq lwm percentage according to lwm number. */
140 : : static uint8_t
141 : : mlx5_rxq_lwm_to_percentage(struct mlx5_rxq_priv *rxq)
142 : : {
143 : 0 : struct mlx5_rxq_data *rxq_data = &rxq->ctrl->rxq;
144 : 0 : uint32_t wqe_cnt = 1 << (rxq_data->elts_n - rxq_data->sges_n);
145 : :
146 : 0 : return rxq->lwm * 100 / wqe_cnt;
147 : : }
148 : :
149 : : /**
150 : : * DPDK callback to get the RX queue information.
151 : : *
152 : : * @param dev
153 : : * Pointer to the device structure.
154 : : *
155 : : * @param rx_queue_id
156 : : * Rx queue identificator.
157 : : *
158 : : * @param qinfo
159 : : * Pointer to the RX queue information structure.
160 : : *
161 : : * @return
162 : : * None.
163 : : */
164 : :
165 : : void
166 : 0 : mlx5_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
167 : : struct rte_eth_rxq_info *qinfo)
168 : : {
169 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, rx_queue_id);
170 : 0 : struct mlx5_rxq_data *rxq = mlx5_rxq_data_get(dev, rx_queue_id);
171 : 0 : struct mlx5_rxq_priv *rxq_priv = mlx5_rxq_get(dev, rx_queue_id);
172 : :
173 [ # # ]: 0 : if (!rxq)
174 : : return;
175 : 0 : qinfo->mp = mlx5_rxq_mprq_enabled(rxq) ?
176 [ # # ]: 0 : rxq->mprq_mp : rxq->mp;
177 : 0 : qinfo->conf.rx_thresh.pthresh = 0;
178 : 0 : qinfo->conf.rx_thresh.hthresh = 0;
179 : 0 : qinfo->conf.rx_thresh.wthresh = 0;
180 : 0 : qinfo->conf.rx_free_thresh = rxq->rq_repl_thresh;
181 : 0 : qinfo->conf.rx_drop_en = 1;
182 [ # # # # ]: 0 : if (rxq_ctrl == NULL || rxq_ctrl->obj == NULL)
183 : 0 : qinfo->conf.rx_deferred_start = 0;
184 : : else
185 : 0 : qinfo->conf.rx_deferred_start = 1;
186 : 0 : qinfo->conf.offloads = dev->data->dev_conf.rxmode.offloads;
187 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
188 [ # # ]: 0 : qinfo->nb_desc = mlx5_rxq_mprq_enabled(rxq) ?
189 : 0 : RTE_BIT32(rxq->elts_n) * RTE_BIT32(rxq->log_strd_num) :
190 : 0 : RTE_BIT32(rxq->elts_n);
191 [ # # ]: 0 : qinfo->avail_thresh = rxq_priv ?
192 : : mlx5_rxq_lwm_to_percentage(rxq_priv) : 0;
193 : : }
194 : :
195 : : /**
196 : : * DPDK callback to get the RX packet burst mode information.
197 : : *
198 : : * @param dev
199 : : * Pointer to the device structure.
200 : : *
201 : : * @param rx_queue_id
202 : : * Rx queue identification.
203 : : *
204 : : * @param mode
205 : : * Pointer to the burts mode information.
206 : : *
207 : : * @return
208 : : * 0 as success, -EINVAL as failure.
209 : : */
210 : : int
211 : 0 : mlx5_rx_burst_mode_get(struct rte_eth_dev *dev,
212 : : uint16_t rx_queue_id __rte_unused,
213 : : struct rte_eth_burst_mode *mode)
214 : : {
215 : 0 : eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
216 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, rx_queue_id);
217 : :
218 [ # # ]: 0 : if (!rxq) {
219 : 0 : rte_errno = EINVAL;
220 : 0 : return -rte_errno;
221 : : }
222 [ # # ]: 0 : if (pkt_burst == mlx5_rx_burst) {
223 : 0 : snprintf(mode->info, sizeof(mode->info), "%s", "Scalar");
224 [ # # ]: 0 : } else if (pkt_burst == mlx5_rx_burst_out_of_order) {
225 : 0 : snprintf(mode->info, sizeof(mode->info), "%s", "Scalar Out-of-Order");
226 [ # # ]: 0 : } else if (pkt_burst == mlx5_rx_burst_mprq) {
227 : 0 : snprintf(mode->info, sizeof(mode->info), "%s", "Multi-Packet RQ");
228 [ # # ]: 0 : } else if (pkt_burst == mlx5_rx_burst_vec) {
229 : : #if defined RTE_ARCH_X86_64
230 : 0 : snprintf(mode->info, sizeof(mode->info), "%s", "Vector SSE");
231 : : #elif defined RTE_ARCH_ARM64
232 : : snprintf(mode->info, sizeof(mode->info), "%s", "Vector Neon");
233 : : #elif defined RTE_ARCH_PPC_64
234 : : snprintf(mode->info, sizeof(mode->info), "%s", "Vector AltiVec");
235 : : #else
236 : : return -EINVAL;
237 : : #endif
238 [ # # ]: 0 : } else if (pkt_burst == mlx5_rx_burst_mprq_vec) {
239 : : #if defined RTE_ARCH_X86_64
240 : 0 : snprintf(mode->info, sizeof(mode->info), "%s", "MPRQ Vector SSE");
241 : : #elif defined RTE_ARCH_ARM64
242 : : snprintf(mode->info, sizeof(mode->info), "%s", "MPRQ Vector Neon");
243 : : #elif defined RTE_ARCH_PPC_64
244 : : snprintf(mode->info, sizeof(mode->info), "%s", "MPRQ Vector AltiVec");
245 : : #else
246 : : return -EINVAL;
247 : : #endif
248 : : } else {
249 : : return -EINVAL;
250 : : }
251 : : return 0;
252 : : }
253 : :
254 : : /**
255 : : * DPDK callback to get the number of used descriptors in a RX queue.
256 : : *
257 : : * @param rx_queue
258 : : * The Rx queue pointer.
259 : : *
260 : : * @return
261 : : * The number of used rx descriptor.
262 : : * -EINVAL if the queue is invalid
263 : : */
264 : : int
265 : 0 : mlx5_rx_queue_count(void *rx_queue)
266 : : {
267 : : struct mlx5_rxq_data *rxq = rx_queue;
268 : : struct rte_eth_dev *dev;
269 : :
270 [ # # ]: 0 : if (!rxq) {
271 : 0 : rte_errno = EINVAL;
272 : 0 : return -rte_errno;
273 : : }
274 : :
275 : 0 : dev = &rte_eth_devices[rxq->port_id];
276 : :
277 [ # # # # ]: 0 : if (dev->rx_pkt_burst == NULL ||
278 : : dev->rx_pkt_burst == rte_eth_pkt_burst_dummy) {
279 : 0 : rte_errno = ENOTSUP;
280 : 0 : return -rte_errno;
281 : : }
282 : :
283 : 0 : return rx_queue_count(rxq);
284 : : }
285 : :
286 : : #define CLB_VAL_IDX 0
287 : : #define CLB_MSK_IDX 1
288 : : static int
289 : 0 : mlx5_monitor_callback(const uint64_t value,
290 : : const uint64_t opaque[RTE_POWER_MONITOR_OPAQUE_SZ])
291 : : {
292 : 0 : const uint64_t m = opaque[CLB_MSK_IDX];
293 : 0 : const uint64_t v = opaque[CLB_VAL_IDX];
294 : :
295 [ # # ]: 0 : return (value & m) == v ? -1 : 0;
296 : : }
297 : :
298 : : static int
299 : 0 : mlx5_monitor_cqe_own_callback(const uint64_t value,
300 : : const uint64_t opaque[RTE_POWER_MONITOR_OPAQUE_SZ])
301 : : {
302 : 0 : const uint64_t m = opaque[CLB_MSK_IDX];
303 : 0 : const uint64_t v = opaque[CLB_VAL_IDX];
304 : 0 : const uint64_t sw_owned = ((value & m) == v);
305 : 0 : const uint64_t opcode = MLX5_CQE_OPCODE(value);
306 : 0 : const uint64_t valid_op = (opcode != MLX5_CQE_INVALID);
307 : :
308 : : /* ownership bit is not valid for invalid opcode; CQE is HW owned */
309 : 0 : return -(valid_op & sw_owned);
310 : : }
311 : :
312 : 0 : int mlx5_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc)
313 : : {
314 : : struct mlx5_rxq_data *rxq = rx_queue;
315 : 0 : const unsigned int cqe_num = 1 << rxq->cqe_n;
316 : 0 : const unsigned int cqe_mask = cqe_num - 1;
317 : 0 : const uint16_t idx = rxq->cq_ci & cqe_num;
318 : 0 : const uint8_t vic = rxq->cq_ci >> rxq->cqe_n;
319 : 0 : volatile struct mlx5_cqe *cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_mask];
320 : :
321 [ # # ]: 0 : if (unlikely(rxq->cqes == NULL)) {
322 : 0 : rte_errno = EINVAL;
323 : 0 : return -rte_errno;
324 : : }
325 [ # # ]: 0 : if (rxq->cqe_comp_layout) {
326 : 0 : pmc->addr = &cqe->validity_iteration_count;
327 : 0 : pmc->opaque[CLB_VAL_IDX] = vic;
328 : 0 : pmc->opaque[CLB_MSK_IDX] = MLX5_CQE_VIC_INIT;
329 : 0 : pmc->fn = mlx5_monitor_callback;
330 : : } else {
331 : 0 : pmc->addr = &cqe->op_own;
332 : 0 : pmc->opaque[CLB_VAL_IDX] = !!idx;
333 : 0 : pmc->opaque[CLB_MSK_IDX] = MLX5_CQE_OWNER_MASK;
334 : 0 : pmc->fn = mlx5_monitor_cqe_own_callback;
335 : : }
336 : 0 : pmc->size = sizeof(uint8_t);
337 : 0 : return 0;
338 : : }
339 : :
340 : : /**
341 : : * Translate RX completion flags to packet type.
342 : : *
343 : : * @param[in] rxq
344 : : * Pointer to RX queue structure.
345 : : * @param[in] cqe
346 : : * Pointer to CQE.
347 : : *
348 : : * @note: fix mlx5_dev_supported_ptypes_get() if any change here.
349 : : *
350 : : * @return
351 : : * Packet type for struct rte_mbuf.
352 : : */
353 : : static inline uint32_t
354 : : rxq_cq_to_pkt_type(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe,
355 : : volatile struct mlx5_mini_cqe8 *mcqe)
356 : : {
357 : : uint8_t idx;
358 : : uint8_t ptype;
359 : 0 : uint8_t pinfo = (cqe->pkt_info & 0x3) << 6;
360 : :
361 : : /* Get l3/l4 header from mini-CQE in case L3/L4 format*/
362 [ # # # # : 0 : if (mcqe == NULL ||
# # ]
363 [ # # # # : 0 : rxq->mcqe_format != MLX5_CQE_RESP_FORMAT_L34H_STRIDX)
# # ]
364 : 0 : ptype = (cqe->hdr_type_etc & 0xfc00) >> 10;
365 : : else
366 : 0 : ptype = mcqe->hdr_type >> 2;
367 : : /*
368 : : * The index to the array should have:
369 : : * bit[1:0] = l3_hdr_type
370 : : * bit[4:2] = l4_hdr_type
371 : : * bit[5] = ip_frag
372 : : * bit[6] = tunneled
373 : : * bit[7] = outer_l3_type
374 : : */
375 : 0 : idx = pinfo | ptype;
376 : 0 : return mlx5_ptype_table[idx] | rxq->tunnel * !!(idx & (1 << 6));
377 : : }
378 : :
379 : 0 : static inline void mlx5_rq_win_reset(struct mlx5_rxq_data *rxq)
380 : : {
381 : : static_assert(MLX5_WINOOO_BITS == (sizeof(*rxq->rq_win_data) * CHAR_BIT),
382 : : "Invalid out-of-order window bitwidth");
383 : 0 : rxq->rq_win_idx = 0;
384 : 0 : rxq->rq_win_cnt = 0;
385 [ # # # # ]: 0 : if (rxq->rq_win_data != NULL && rxq->rq_win_idx_mask != 0)
386 : 0 : memset(rxq->rq_win_data, 0, (rxq->rq_win_idx_mask + 1) * sizeof(*rxq->rq_win_data));
387 : 0 : }
388 : :
389 : 0 : static inline int mlx5_rq_win_init(struct mlx5_rxq_data *rxq)
390 : : {
391 : : struct mlx5_rxq_ctrl *ctrl = container_of(rxq, struct mlx5_rxq_ctrl, rxq);
392 : : uint32_t win_size, win_mask;
393 : :
394 : : /* Set queue size as window size */
395 : 0 : win_size = 1u << rxq->elts_n;
396 : 0 : win_size = RTE_MAX(win_size, MLX5_WINOOO_BITS);
397 : 0 : win_size = win_size / MLX5_WINOOO_BITS;
398 : 0 : win_mask = win_size - 1;
399 [ # # # # ]: 0 : if (win_mask != rxq->rq_win_idx_mask || rxq->rq_win_data == NULL) {
400 : 0 : mlx5_free(rxq->rq_win_data);
401 : 0 : rxq->rq_win_idx_mask = 0;
402 : 0 : rxq->rq_win_data = mlx5_malloc(MLX5_MEM_RTE,
403 : : win_size * sizeof(*rxq->rq_win_data),
404 : 0 : RTE_CACHE_LINE_SIZE, ctrl->socket);
405 [ # # ]: 0 : if (rxq->rq_win_data == NULL)
406 : : return -ENOMEM;
407 : 0 : rxq->rq_win_idx_mask = (uint16_t)win_mask;
408 : : }
409 : 0 : mlx5_rq_win_reset(rxq);
410 : 0 : return 0;
411 : : }
412 : :
413 : : static inline bool mlx5_rq_win_test(struct mlx5_rxq_data *rxq)
414 : : {
415 : 0 : return !!rxq->rq_win_cnt;
416 : : }
417 : :
418 : : static inline void mlx5_rq_win_update(struct mlx5_rxq_data *rxq, uint32_t delta)
419 : : {
420 : : uint32_t idx;
421 : :
422 : 0 : idx = (delta / MLX5_WINOOO_BITS) + rxq->rq_win_idx;
423 : 0 : idx &= rxq->rq_win_idx_mask;
424 : 0 : rxq->rq_win_cnt = 1;
425 : 0 : rxq->rq_win_data[idx] |= 1u << (delta % MLX5_WINOOO_BITS);
426 : 0 : }
427 : :
428 : 0 : static inline uint32_t mlx5_rq_win_advance(struct mlx5_rxq_data *rxq, uint32_t delta)
429 : : {
430 : : uint32_t idx;
431 : :
432 : 0 : idx = (delta / MLX5_WINOOO_BITS) + rxq->rq_win_idx;
433 : 0 : idx &= rxq->rq_win_idx_mask;
434 : 0 : rxq->rq_win_data[idx] |= 1u << (delta % MLX5_WINOOO_BITS);
435 : 0 : ++rxq->rq_win_cnt;
436 [ # # ]: 0 : if (delta >= MLX5_WINOOO_BITS)
437 : : return 0;
438 : : delta = 0;
439 [ # # ]: 0 : while (~rxq->rq_win_data[idx] == 0) {
440 : 0 : rxq->rq_win_data[idx] = 0;
441 : : MLX5_ASSERT(rxq->rq_win_cnt >= MLX5_WINOOO_BITS);
442 : 0 : rxq->rq_win_cnt -= MLX5_WINOOO_BITS;
443 : 0 : idx = (idx + 1) & rxq->rq_win_idx_mask;
444 : 0 : rxq->rq_win_idx = idx;
445 : 0 : delta += MLX5_WINOOO_BITS;
446 : : }
447 : : return delta;
448 : : }
449 : :
450 : : /**
451 : : * Initialize Rx WQ and indexes.
452 : : *
453 : : * @param[in] rxq
454 : : * Pointer to RX queue structure.
455 : : */
456 : : int
457 : 0 : mlx5_rxq_initialize(struct mlx5_rxq_data *rxq)
458 : : {
459 : 0 : const unsigned int wqe_n = 1 << rxq->elts_n;
460 : : unsigned int i;
461 : :
462 [ # # ]: 0 : for (i = 0; (i != wqe_n); ++i) {
463 : : volatile struct mlx5_wqe_data_seg *scat;
464 : : uintptr_t addr;
465 : : uint32_t byte_count;
466 : : uint32_t lkey;
467 : :
468 [ # # ]: 0 : if (mlx5_rxq_mprq_enabled(rxq)) {
469 : 0 : struct mlx5_mprq_buf *buf = (*rxq->mprq_bufs)[i];
470 : :
471 : 0 : scat = &((volatile struct mlx5_wqe_mprq *)
472 : 0 : rxq->wqes)[i].dseg;
473 : 0 : addr = (uintptr_t)mlx5_mprq_buf_addr
474 : : (buf, (uintptr_t)RTE_BIT32(rxq->log_strd_num));
475 [ # # ]: 0 : byte_count = RTE_BIT32(rxq->log_strd_sz) *
476 : : RTE_BIT32(rxq->log_strd_num);
477 : : lkey = mlx5_rx_addr2mr(rxq, addr);
478 : : } else {
479 : 0 : struct rte_mbuf *buf = (*rxq->elts)[i];
480 : :
481 : 0 : scat = &((volatile struct mlx5_wqe_data_seg *)
482 : 0 : rxq->wqes)[i];
483 : 0 : addr = rte_pktmbuf_mtod(buf, uintptr_t);
484 [ # # ]: 0 : byte_count = DATA_LEN(buf);
485 : : lkey = mlx5_rx_mb2mr(rxq, buf);
486 : : }
487 : : /* scat->addr must be able to store a pointer. */
488 : : MLX5_ASSERT(sizeof(scat->addr) >= sizeof(uintptr_t));
489 : 0 : *scat = (struct mlx5_wqe_data_seg){
490 [ # # ]: 0 : .addr = rte_cpu_to_be_64(addr),
491 [ # # ]: 0 : .byte_count = rte_cpu_to_be_32(byte_count),
492 : : .lkey = lkey,
493 : : };
494 : : }
495 : 0 : rxq->consumed_strd = 0;
496 : : rxq->decompressed = 0;
497 : 0 : rxq->rq_pi = 0;
498 [ # # ]: 0 : rxq->zip = (struct rxq_zip){
499 : : .ai = 0,
500 : : };
501 : 0 : rxq->elts_ci = mlx5_rxq_mprq_enabled(rxq) ?
502 [ # # ]: 0 : (wqe_n >> rxq->sges_n) * RTE_BIT32(rxq->log_strd_num) : 0;
503 : : /* Update doorbell counter. */
504 : 0 : rxq->rq_ci = wqe_n >> rxq->sges_n;
505 : 0 : rxq->rq_ci_ooo = rxq->rq_ci;
506 [ # # ]: 0 : if (mlx5_rq_win_init(rxq))
507 : : return -ENOMEM;
508 : 0 : rte_io_wmb();
509 [ # # ]: 0 : *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
510 : 0 : return 0;
511 : : }
512 : :
513 : : #define MLX5_ERROR_CQE_MASK 0x40000000
514 : : /* Must be negative. */
515 : : #define MLX5_REGULAR_ERROR_CQE_RET (-5)
516 : : #define MLX5_CRITICAL_ERROR_CQE_RET (-4)
517 : : /* Must not be negative. */
518 : : #define MLX5_RECOVERY_ERROR_RET 0
519 : : #define MLX5_RECOVERY_IGNORE_RET 1
520 : : #define MLX5_RECOVERY_COMPLETED_RET 2
521 : :
522 : : /**
523 : : * Handle a Rx error.
524 : : * The function inserts the RQ state to reset when the first error CQE is
525 : : * shown, then drains the CQ by the caller function loop. When the CQ is empty,
526 : : * it moves the RQ state to ready and initializes the RQ.
527 : : * Next CQE identification and error counting are in the caller responsibility.
528 : : *
529 : : * @param[in] rxq
530 : : * Pointer to RX queue structure.
531 : : * @param[in] vec
532 : : * 1 when called from vectorized Rx burst, need to prepare mbufs for the RQ.
533 : : * 0 when called from non-vectorized Rx burst.
534 : : * @param[in] err_n
535 : : * Number of CQEs to check for an error.
536 : : *
537 : : * @return
538 : : * MLX5_RECOVERY_ERROR_RET in case of recovery error,
539 : : * MLX5_RECOVERY_IGNORE_RET in case of non-critical error syndrome,
540 : : * MLX5_RECOVERY_COMPLETED_RET in case of recovery is completed,
541 : : * otherwise the CQE status after ignored error syndrome or queue reset.
542 : : */
543 : : int
544 : 0 : mlx5_rx_err_handle(struct mlx5_rxq_data *rxq, uint8_t vec,
545 : : uint16_t err_n, uint16_t *skip_cnt)
546 : : {
547 : 0 : const uint16_t cqe_n = 1 << rxq->cqe_n;
548 : 0 : const uint16_t cqe_mask = cqe_n - 1;
549 : 0 : const uint16_t wqe_n = 1 << rxq->elts_n;
550 : 0 : const uint16_t strd_n = RTE_BIT32(rxq->log_strd_num);
551 : : struct mlx5_rxq_ctrl *rxq_ctrl =
552 : : container_of(rxq, struct mlx5_rxq_ctrl, rxq);
553 : : union {
554 : : volatile struct mlx5_cqe *cqe;
555 : : volatile struct mlx5_error_cqe *err_cqe;
556 : : } u = {
557 : 0 : .cqe = &(*rxq->cqes)[(rxq->cq_ci - vec) & cqe_mask],
558 : : };
559 : : struct mlx5_mp_arg_queue_state_modify sm;
560 : : bool critical_syndrome = false;
561 : : int ret, i;
562 : :
563 [ # # # # : 0 : switch (rxq->err_state) {
# ]
564 : 0 : case MLX5_RXQ_ERR_STATE_IGNORE:
565 [ # # ]: 0 : ret = check_cqe(u.cqe, cqe_n, rxq->cq_ci - vec);
566 : : if (ret != MLX5_CQE_STATUS_ERR) {
567 : 0 : rxq->err_state = MLX5_RXQ_ERR_STATE_NO_ERROR;
568 : 0 : return ret;
569 : : }
570 : : /* Fall-through */
571 : : case MLX5_RXQ_ERR_STATE_NO_ERROR:
572 [ # # ]: 0 : for (i = 0; i < (int)err_n; i++) {
573 : 0 : u.cqe = &(*rxq->cqes)[(rxq->cq_ci - vec - i) & cqe_mask];
574 [ # # ]: 0 : if (MLX5_CQE_OPCODE(u.cqe->op_own) == MLX5_CQE_RESP_ERR) {
575 [ # # ]: 0 : if (u.err_cqe->syndrome == MLX5_CQE_SYNDROME_LOCAL_QP_OP_ERR ||
576 [ # # ]: 0 : u.err_cqe->syndrome == MLX5_CQE_SYNDROME_LOCAL_PROT_ERR ||
577 [ # # ]: 0 : u.err_cqe->syndrome == MLX5_CQE_SYNDROME_WR_FLUSH_ERR)
578 : : critical_syndrome = true;
579 : : break;
580 : : }
581 : : }
582 : : if (!critical_syndrome) {
583 [ # # ]: 0 : if (rxq->err_state == MLX5_RXQ_ERR_STATE_NO_ERROR) {
584 : 0 : *skip_cnt = 0;
585 [ # # ]: 0 : if (i == err_n)
586 : 0 : rxq->err_state = MLX5_RXQ_ERR_STATE_IGNORE;
587 : : }
588 : 0 : return MLX5_RECOVERY_IGNORE_RET;
589 : : }
590 : 0 : rxq->err_state = MLX5_RXQ_ERR_STATE_NEED_RESET;
591 : : /* Fall-through */
592 : 0 : case MLX5_RXQ_ERR_STATE_NEED_RESET:
593 : 0 : sm.is_wq = 1;
594 : 0 : sm.queue_id = rxq->idx;
595 : 0 : sm.state = IBV_WQS_RESET;
596 [ # # ]: 0 : if (mlx5_queue_state_modify(RXQ_DEV(rxq_ctrl), &sm))
597 : : return MLX5_RECOVERY_ERROR_RET;
598 : 0 : if (rxq_ctrl->dump_file_n <
599 [ # # ]: 0 : RXQ_PORT(rxq_ctrl)->config.max_dump_files_num) {
600 : 0 : MKSTR(err_str, "Unexpected CQE error syndrome "
601 : : "0x%02x CQN = %u RQN = %u wqe_counter = %u"
602 : : " rq_ci = %u cq_ci = %u", u.err_cqe->syndrome,
603 : : rxq->cqn, rxq_ctrl->wqn,
604 : : rte_be_to_cpu_16(u.err_cqe->wqe_counter),
605 : : rxq->rq_ci << rxq->sges_n, rxq->cq_ci);
606 : 0 : MKSTR(name, "dpdk_mlx5_port_%u_rxq_%u_%u",
607 : : rxq->port_id, rxq->idx, (uint32_t)rte_rdtsc());
608 : 0 : mlx5_dump_debug_information(name, NULL, err_str, 0);
609 : 0 : mlx5_dump_debug_information(name, "MLX5 Error CQ:",
610 : : (const void *)((uintptr_t)
611 : 0 : rxq->cqes),
612 : : sizeof(*u.cqe) * cqe_n);
613 : 0 : mlx5_dump_debug_information(name, "MLX5 Error RQ:",
614 : : (const void *)((uintptr_t)
615 : 0 : rxq->wqes),
616 : 0 : 16 * wqe_n);
617 : 0 : rxq_ctrl->dump_file_n++;
618 : : }
619 : : /* Try to find the actual cq_ci in hardware for shared queue. */
620 [ # # ]: 0 : if (rxq->shared)
621 : 0 : rxq_sync_cq(rxq);
622 : 0 : rxq->err_state = MLX5_RXQ_ERR_STATE_NEED_READY;
623 : : /* Fall-through */
624 : 0 : case MLX5_RXQ_ERR_STATE_NEED_READY:
625 [ # # ]: 0 : ret = check_cqe(u.cqe, cqe_n, rxq->cq_ci);
626 : : if (ret == MLX5_CQE_STATUS_HW_OWN) {
627 : 0 : rte_io_wmb();
628 [ # # ]: 0 : *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
629 : 0 : rte_io_wmb();
630 : : /*
631 : : * The RQ consumer index must be zeroed while moving
632 : : * from RESET state to RDY state.
633 : : */
634 : 0 : *rxq->rq_db = rte_cpu_to_be_32(0);
635 : 0 : rte_io_wmb();
636 : 0 : sm.is_wq = 1;
637 : 0 : sm.queue_id = rxq->idx;
638 : 0 : sm.state = IBV_WQS_RDY;
639 [ # # ]: 0 : if (mlx5_queue_state_modify(RXQ_DEV(rxq_ctrl), &sm))
640 : : return MLX5_RECOVERY_ERROR_RET;
641 [ # # ]: 0 : if (vec) {
642 : : const uint32_t elts_n =
643 : : mlx5_rxq_mprq_enabled(rxq) ?
644 [ # # ]: 0 : wqe_n * strd_n : wqe_n;
645 : 0 : const uint32_t e_mask = elts_n - 1;
646 : : uint32_t elts_ci =
647 : : mlx5_rxq_mprq_enabled(rxq) ?
648 [ # # ]: 0 : rxq->elts_ci : rxq->rq_ci;
649 : : uint32_t elt_idx;
650 : : struct rte_mbuf **elt;
651 : 0 : unsigned int n = elts_n - (elts_ci -
652 : 0 : rxq->rq_pi);
653 : :
654 [ # # ]: 0 : for (i = 0; i < (int)n; ++i) {
655 : 0 : elt_idx = (elts_ci + i) & e_mask;
656 : 0 : elt = &(*rxq->elts)[elt_idx];
657 : 0 : *elt = rte_mbuf_raw_alloc(rxq->mp);
658 [ # # ]: 0 : if (!*elt) {
659 [ # # ]: 0 : for (i--; i >= 0; --i) {
660 : 0 : elt_idx = (elts_ci +
661 : : i) & elts_n;
662 : 0 : elt = &(*rxq->elts)
663 : : [elt_idx];
664 [ # # ]: 0 : rte_pktmbuf_free_seg
665 : : (*elt);
666 : : }
667 : : return MLX5_RECOVERY_ERROR_RET;
668 : : }
669 : : }
670 [ # # ]: 0 : for (i = 0; i < (int)elts_n; ++i) {
671 : 0 : elt = &(*rxq->elts)[i];
672 : 0 : DATA_LEN(*elt) =
673 : 0 : (uint16_t)((*elt)->buf_len -
674 : : rte_pktmbuf_headroom(*elt));
675 : : }
676 : : /* Padding with a fake mbuf for vec Rx. */
677 [ # # ]: 0 : for (i = 0; i < MLX5_VPMD_DESCS_PER_LOOP; ++i)
678 : 0 : (*rxq->elts)[elts_n + i] =
679 : 0 : &rxq->fake_mbuf;
680 : : }
681 [ # # ]: 0 : if (mlx5_rxq_initialize(rxq))
682 : : return MLX5_RECOVERY_ERROR_RET;
683 : 0 : rxq->err_state = MLX5_RXQ_ERR_STATE_NO_ERROR;
684 : 0 : return MLX5_RECOVERY_COMPLETED_RET;
685 : : }
686 : : return ret;
687 : : default:
688 : : return MLX5_RECOVERY_ERROR_RET;
689 : : }
690 : : }
691 : :
692 : : /**
693 : : * Get size of the next packet for a given CQE. For compressed CQEs, the
694 : : * consumer index is updated only once all packets of the current one have
695 : : * been processed.
696 : : *
697 : : * @param rxq
698 : : * Pointer to RX queue.
699 : : * @param cqe
700 : : * CQE to process.
701 : : * @param cqe_n
702 : : * Completion queue count.
703 : : * @param cqe_mask
704 : : * Completion queue mask.
705 : : * @param[out] mcqe
706 : : * Store pointer to mini-CQE if compressed. Otherwise, the pointer is not
707 : : * written.
708 : : * @param[out] skip_cnt
709 : : * Number of packets skipped due to recoverable errors.
710 : : * @param mprq
711 : : * Indication if it is called from MPRQ.
712 : : * @param[out] widx
713 : : * Store WQE index from CQE to support out of order completions. NULL
714 : : * can be specified if index is not needed
715 : : *
716 : : * @return
717 : : * 0 in case of empty CQE,
718 : : * MLX5_REGULAR_ERROR_CQE_RET in case of error CQE,
719 : : * MLX5_CRITICAL_ERROR_CQE_RET in case of error CQE lead to Rx queue reset,
720 : : * otherwise the packet size in regular RxQ,
721 : : * and striding byte count format in mprq case.
722 : : */
723 : : static inline int
724 : : mlx5_rx_poll_len(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe,
725 : : uint16_t cqe_n, uint16_t cqe_mask,
726 : : volatile struct mlx5_mini_cqe8 **mcqe,
727 : : uint16_t *skip_cnt, bool mprq, uint32_t *widx)
728 : : {
729 : : struct rxq_zip *zip = &rxq->zip;
730 : : int len = 0, ret = 0;
731 : : uint32_t idx, end;
732 : :
733 : : do {
734 : 0 : len = 0;
735 : : /* Process compressed data in the CQE and mini arrays. */
736 [ # # # # : 0 : if (zip->ai) {
# # ]
737 : 0 : volatile struct mlx5_mini_cqe8 (*mc)[8] =
738 : : (volatile struct mlx5_mini_cqe8 (*)[8])
739 : 0 : (uintptr_t)(&(*rxq->cqes)[zip->ca &
740 : : cqe_mask].pkt_info);
741 : 0 : len = rte_be_to_cpu_32((*mc)[zip->ai & 7].byte_cnt &
742 : : rxq->byte_mask);
743 : : if (widx != NULL)
744 : 0 : *widx = zip->wqe_idx + zip->ai;
745 : 0 : *mcqe = &(*mc)[zip->ai & 7];
746 [ # # # # : 0 : if (rxq->cqe_comp_layout) {
# # ]
747 : 0 : zip->ai++;
748 [ # # # # : 0 : if (unlikely(rxq->zip.ai == rxq->zip.cqe_cnt)) {
# # ]
749 : 0 : rxq->cq_ci = zip->cq_ci;
750 : 0 : zip->ai = 0;
751 : : }
752 : : } else {
753 [ # # # # : 0 : if ((++zip->ai & 7) == 0) {
# # ]
754 : : /* Invalidate consumed CQEs */
755 : : idx = zip->ca;
756 : 0 : end = zip->na;
757 [ # # # # : 0 : while (idx != end) {
# # ]
758 : 0 : (*rxq->cqes)[idx & cqe_mask].op_own =
759 : : MLX5_CQE_INVALIDATE;
760 : 0 : ++idx;
761 : : }
762 : : /*
763 : : * Increment consumer index to skip the number
764 : : * of CQEs consumed. Hardware leaves holes in
765 : : * the CQ ring for software use.
766 : : */
767 : 0 : zip->ca = zip->na;
768 : 0 : zip->na += 8;
769 : : }
770 [ # # # # : 0 : if (unlikely(rxq->zip.ai == rxq->zip.cqe_cnt)) {
# # ]
771 : : /* Invalidate the rest */
772 : 0 : idx = zip->ca;
773 : 0 : end = zip->cq_ci;
774 : :
775 [ # # # # : 0 : while (idx != end) {
# # ]
776 : 0 : (*rxq->cqes)[idx & cqe_mask].op_own =
777 : : MLX5_CQE_INVALIDATE;
778 : 0 : ++idx;
779 : : }
780 : 0 : rxq->cq_ci = zip->cq_ci;
781 : 0 : zip->ai = 0;
782 : : }
783 : : }
784 : : /*
785 : : * No compressed data, get next CQE and verify if it is
786 : : * compressed.
787 : : */
788 : : } else {
789 : : int8_t op_own;
790 : : uint32_t cq_ci;
791 : :
792 : 0 : ret = (rxq->cqe_comp_layout) ?
793 [ # # # # : 0 : check_cqe_iteration(cqe, rxq->cqe_n, rxq->cq_ci) :
# # # # #
# # # ]
794 [ # # # # : 0 : check_cqe(cqe, cqe_n, rxq->cq_ci);
# # ]
795 [ # # # # : 0 : if (unlikely(ret != MLX5_CQE_STATUS_SW_OWN)) {
# # ]
796 [ # # # # : 0 : if (unlikely(ret == MLX5_CQE_STATUS_ERR ||
# # # # #
# # # ]
797 : : rxq->err_state)) {
798 : : /* We should try to track out-pf-order WQE */
799 : : if (widx != NULL)
800 : 0 : *widx = rte_be_to_cpu_16(cqe->wqe_counter);
801 : 0 : ret = mlx5_rx_err_handle(rxq, 0, 1, skip_cnt);
802 [ # # # # : 0 : if (ret == MLX5_CQE_STATUS_HW_OWN)
# # ]
803 : : return MLX5_ERROR_CQE_MASK;
804 : 0 : if (ret == MLX5_RECOVERY_ERROR_RET ||
805 [ # # # # : 0 : ret == MLX5_RECOVERY_COMPLETED_RET)
# # ]
806 : : return MLX5_CRITICAL_ERROR_CQE_RET;
807 [ # # # # ]: 0 : if (!mprq && ret == MLX5_RECOVERY_IGNORE_RET) {
808 : 0 : *skip_cnt = 1;
809 : 0 : ++rxq->cq_ci;
810 : 0 : return MLX5_ERROR_CQE_MASK;
811 : : }
812 : : } else {
813 : : return 0;
814 : : }
815 : : }
816 : : /*
817 : : * Introduce the local variable to have queue cq_ci
818 : : * index in queue structure always consistent with
819 : : * actual CQE boundary (not pointing to the middle
820 : : * of compressed CQE session).
821 : : */
822 : 0 : cq_ci = rxq->cq_ci + !rxq->cqe_comp_layout;
823 : 0 : op_own = cqe->op_own;
824 [ # # # # : 0 : if (MLX5_CQE_FORMAT(op_own) == MLX5_COMPRESSED) {
# # ]
825 : 0 : volatile struct mlx5_mini_cqe8 (*mc)[8] =
826 : : (volatile struct mlx5_mini_cqe8 (*)[8])
827 : 0 : (uintptr_t)(&(*rxq->cqes)
828 : 0 : [cq_ci & cqe_mask].pkt_info);
829 : :
830 : : /* Fix endianness. */
831 [ # # # # : 0 : zip->cqe_cnt = rxq->cqe_comp_layout ?
# # ]
832 : 0 : (MLX5_CQE_NUM_MINIS(op_own) + 1U) :
833 : 0 : rte_be_to_cpu_32(cqe->byte_cnt);
834 : : /*
835 : : * Current mini array position is the one
836 : : * returned by check_cqe64().
837 : : *
838 : : * If completion comprises several mini arrays,
839 : : * as a special case the second one is located
840 : : * 7 CQEs after the initial CQE instead of 8
841 : : * for subsequent ones.
842 : : */
843 : 0 : zip->ca = cq_ci;
844 : 0 : zip->na = zip->ca + 7;
845 : : if (widx != NULL) {
846 : 0 : zip->wqe_idx = rte_be_to_cpu_16(cqe->wqe_counter);
847 : 0 : *widx = zip->wqe_idx;
848 : : }
849 : : /* Compute the next non compressed CQE. */
850 : 0 : zip->cq_ci = rxq->cq_ci + zip->cqe_cnt;
851 : : /* Get packet size to return. */
852 : 0 : len = rte_be_to_cpu_32((*mc)[0].byte_cnt &
853 : : rxq->byte_mask);
854 : 0 : *mcqe = &(*mc)[0];
855 [ # # # # : 0 : if (rxq->cqe_comp_layout) {
# # ]
856 [ # # # # : 0 : if (MLX5_CQE_NUM_MINIS(op_own))
# # ]
857 : 0 : zip->ai = 1;
858 : : else
859 : 0 : rxq->cq_ci = zip->cq_ci;
860 : : } else {
861 : 0 : zip->ai = 1;
862 : : /* Prefetch all to be invalidated */
863 : : idx = zip->ca;
864 : : end = zip->cq_ci;
865 [ # # # # : 0 : while (idx != end) {
# # ]
866 : 0 : rte_prefetch0(&(*rxq->cqes)[(idx) & cqe_mask]);
867 : 0 : ++idx;
868 : : }
869 : : }
870 : : } else {
871 : 0 : ++rxq->cq_ci;
872 : 0 : len = rte_be_to_cpu_32(cqe->byte_cnt);
873 : : if (widx != NULL)
874 : 0 : *widx = rte_be_to_cpu_16(cqe->wqe_counter);
875 [ # # # # : 0 : if (rxq->cqe_comp_layout) {
# # ]
876 : : volatile struct mlx5_cqe *next;
877 : :
878 : 0 : next = &(*rxq->cqes)[rxq->cq_ci & cqe_mask];
879 [ # # # # : 0 : ret = check_cqe_iteration(next, rxq->cqe_n, rxq->cq_ci);
# # ]
880 : 0 : if (ret != MLX5_CQE_STATUS_SW_OWN ||
881 [ # # # # : 0 : MLX5_CQE_FORMAT(next->op_own) == MLX5_COMPRESSED)
# # ]
882 [ # # # # : 0 : rte_memcpy(&rxq->title_cqe,
# # ]
883 : : (const void *)(uintptr_t)cqe,
884 : : sizeof(struct mlx5_cqe));
885 : : }
886 : : }
887 : : }
888 [ # # # # : 0 : if (unlikely(rxq->err_state)) {
# # ]
889 [ # # # # : 0 : if (rxq->err_state == MLX5_RXQ_ERR_STATE_IGNORE &&
# # # # #
# # # ]
890 : : ret == MLX5_CQE_STATUS_SW_OWN) {
891 : 0 : rxq->err_state = MLX5_RXQ_ERR_STATE_NO_ERROR;
892 : 0 : return len & MLX5_ERROR_CQE_MASK;
893 : : }
894 : 0 : cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_mask];
895 : 0 : ++rxq->stats.idropped;
896 : 0 : (*skip_cnt) += mprq ? (len & MLX5_MPRQ_STRIDE_NUM_MASK) >>
897 : : MLX5_MPRQ_STRIDE_NUM_SHIFT : 1;
898 : : } else {
899 : : return len;
900 : : }
901 : : } while (1);
902 : : }
903 : :
904 : : /**
905 : : * Translate RX completion flags to offload flags.
906 : : *
907 : : * @param[in] cqe
908 : : * Pointer to CQE.
909 : : *
910 : : * @return
911 : : * Offload flags (ol_flags) for struct rte_mbuf.
912 : : */
913 : : static inline uint32_t
914 : : rxq_cq_to_ol_flags(volatile struct mlx5_cqe *cqe)
915 : : {
916 : : uint32_t ol_flags = 0;
917 : 0 : uint16_t flags = rte_be_to_cpu_16(cqe->hdr_type_etc);
918 : :
919 : 0 : ol_flags =
920 : 0 : TRANSPOSE(flags,
921 : : MLX5_CQE_RX_L3_HDR_VALID,
922 : 0 : RTE_MBUF_F_RX_IP_CKSUM_GOOD) |
923 : 0 : TRANSPOSE(flags,
924 : : MLX5_CQE_RX_L4_HDR_VALID,
925 : : RTE_MBUF_F_RX_L4_CKSUM_GOOD);
926 : : return ol_flags;
927 : : }
928 : :
929 : : /**
930 : : * Fill in mbuf fields from RX completion flags.
931 : : * Note that pkt->ol_flags should be initialized outside of this function.
932 : : *
933 : : * @param rxq
934 : : * Pointer to RX queue.
935 : : * @param pkt
936 : : * mbuf to fill.
937 : : * @param cqe
938 : : * CQE to process.
939 : : * @param rss_hash_res
940 : : * Packet RSS Hash result.
941 : : */
942 : : static inline void
943 : : rxq_cq_to_mbuf(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt,
944 : : volatile struct mlx5_cqe *cqe,
945 : : volatile struct mlx5_mini_cqe8 *mcqe)
946 : : {
947 : : /* Update packet information. */
948 : 0 : pkt->packet_type = rxq_cq_to_pkt_type(rxq, cqe, mcqe);
949 [ # # # # : 0 : pkt->port = unlikely(rxq->shared) ? cqe->user_index_low : rxq->port_id;
# # ]
950 : :
951 [ # # # # : 0 : if (rxq->rss_hash) {
# # ]
952 : : uint32_t rss_hash_res = 0;
953 : :
954 : : /* If compressed, take hash result from mini-CQE. */
955 [ # # # # : 0 : if (mcqe == NULL ||
# # ]
956 [ # # # # : 0 : rxq->mcqe_format != MLX5_CQE_RESP_FORMAT_HASH)
# # ]
957 : 0 : rss_hash_res = rte_be_to_cpu_32(cqe->rx_hash_res);
958 : : else
959 : 0 : rss_hash_res = rte_be_to_cpu_32(mcqe->rx_hash_result);
960 [ # # # # : 0 : if (rss_hash_res) {
# # ]
961 : 0 : pkt->hash.rss = rss_hash_res;
962 : 0 : pkt->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
963 : : }
964 : : }
965 [ # # # # : 0 : if (rxq->mark) {
# # ]
966 : : uint32_t mark = 0;
967 : :
968 : : /* If compressed, take flow tag from mini-CQE. */
969 [ # # # # : 0 : if (mcqe == NULL ||
# # ]
970 [ # # # # : 0 : rxq->mcqe_format != MLX5_CQE_RESP_FORMAT_FTAG_STRIDX)
# # ]
971 : 0 : mark = cqe->sop_drop_qpn;
972 : : else
973 : 0 : mark = ((mcqe->byte_cnt_flow & 0xff) << 8) |
974 : 0 : (mcqe->flow_tag_high << 16);
975 [ # # # # : 0 : if (MLX5_FLOW_MARK_IS_VALID(mark)) {
# # ]
976 : 0 : pkt->ol_flags |= RTE_MBUF_F_RX_FDIR;
977 [ # # # # : 0 : if (mark != RTE_BE32(MLX5_FLOW_MARK_DEFAULT)) {
# # ]
978 : 0 : pkt->ol_flags |= rxq->mark_flag;
979 : 0 : pkt->hash.fdir.hi = mlx5_flow_mark_get(mark);
980 : : }
981 : : }
982 : : }
983 [ # # # # : 0 : if (rxq->dynf_meta) {
# # ]
984 : 0 : uint32_t meta = rte_be_to_cpu_32(cqe->flow_table_metadata) &
985 : 0 : rxq->flow_meta_port_mask;
986 : :
987 [ # # # # : 0 : if (meta) {
# # ]
988 : 0 : pkt->ol_flags |= rxq->flow_meta_mask;
989 : 0 : *RTE_MBUF_DYNFIELD(pkt, rxq->flow_meta_offset,
990 : 0 : uint32_t *) = meta;
991 : : }
992 : : }
993 [ # # # # : 0 : if (rxq->csum)
# # ]
994 : 0 : pkt->ol_flags |= rxq_cq_to_ol_flags(cqe);
995 [ # # # # : 0 : if (rxq->vlan_strip) {
# # ]
996 : : bool vlan_strip;
997 : :
998 [ # # # # : 0 : if (mcqe == NULL ||
# # ]
999 [ # # # # : 0 : rxq->mcqe_format != MLX5_CQE_RESP_FORMAT_L34H_STRIDX)
# # ]
1000 : 0 : vlan_strip = cqe->hdr_type_etc &
1001 : : RTE_BE16(MLX5_CQE_VLAN_STRIPPED);
1002 : : else
1003 : 0 : vlan_strip = mcqe->hdr_type &
1004 : : RTE_BE16(MLX5_CQE_VLAN_STRIPPED);
1005 [ # # # # : 0 : if (vlan_strip) {
# # ]
1006 : 0 : pkt->ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
1007 : 0 : pkt->vlan_tci = rte_be_to_cpu_16(cqe->vlan_info);
1008 : : }
1009 : : }
1010 [ # # # # : 0 : if (rxq->hw_timestamp) {
# # ]
1011 : 0 : uint64_t ts = rte_be_to_cpu_64(cqe->timestamp);
1012 : :
1013 [ # # # # : 0 : if (rxq->rt_timestamp)
# # ]
1014 : : ts = mlx5_txpp_convert_rx_ts(rxq->sh, ts);
1015 : 0 : mlx5_timestamp_set(pkt, rxq->timestamp_offset, ts);
1016 : 0 : pkt->ol_flags |= rxq->timestamp_rx_flag;
1017 : : }
1018 : : }
1019 : :
1020 : : /**
1021 : : * DPDK callback for RX.
1022 : : *
1023 : : * @param dpdk_rxq
1024 : : * Generic pointer to RX queue structure.
1025 : : * @param[out] pkts
1026 : : * Array to store received packets.
1027 : : * @param pkts_n
1028 : : * Maximum number of packets in array.
1029 : : *
1030 : : * @return
1031 : : * Number of packets successfully received (<= pkts_n).
1032 : : */
1033 : : uint16_t
1034 : 0 : mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
1035 : : {
1036 : : struct mlx5_rxq_data *rxq = dpdk_rxq;
1037 : 0 : const uint32_t wqe_n = 1 << rxq->elts_n;
1038 : 0 : const uint32_t wqe_mask = wqe_n - 1;
1039 : 0 : const uint32_t cqe_n = 1 << rxq->cqe_n;
1040 : 0 : const uint32_t cqe_mask = cqe_n - 1;
1041 : 0 : const unsigned int sges_n = rxq->sges_n;
1042 : : struct rte_mbuf *pkt = NULL;
1043 : : struct rte_mbuf *seg = NULL;
1044 : 0 : volatile struct mlx5_cqe *cqe =
1045 : 0 : &(*rxq->cqes)[rxq->cq_ci & cqe_mask];
1046 : : unsigned int i = 0;
1047 : 0 : unsigned int rq_ci = rxq->rq_ci << sges_n;
1048 : : int len = 0; /* keep its value across iterations. */
1049 : :
1050 [ # # ]: 0 : while (pkts_n) {
1051 : : uint16_t skip_cnt;
1052 : 0 : unsigned int idx = rq_ci & wqe_mask;
1053 : 0 : volatile struct mlx5_wqe_data_seg *wqe =
1054 : 0 : &((volatile struct mlx5_wqe_data_seg *)rxq->wqes)[idx];
1055 : 0 : struct rte_mbuf *rep = (*rxq->elts)[idx];
1056 : : volatile struct mlx5_mini_cqe8 *mcqe = NULL;
1057 : :
1058 [ # # ]: 0 : if (pkt)
1059 : 0 : NEXT(seg) = rep;
1060 : : seg = rep;
1061 : : rte_prefetch0(seg);
1062 : : rte_prefetch0(cqe);
1063 : : rte_prefetch0(wqe);
1064 : : /* Allocate the buf from the same pool. */
1065 : 0 : rep = rte_mbuf_raw_alloc(seg->pool);
1066 [ # # ]: 0 : if (unlikely(rep == NULL)) {
1067 : 0 : ++rxq->stats.rx_nombuf;
1068 [ # # ]: 0 : if (!pkt) {
1069 : : /*
1070 : : * no buffers before we even started,
1071 : : * bail out silently.
1072 : : */
1073 : : break;
1074 : : }
1075 [ # # ]: 0 : while (pkt != seg) {
1076 : : MLX5_ASSERT(pkt != (*rxq->elts)[idx]);
1077 : 0 : rep = NEXT(pkt);
1078 : 0 : NEXT(pkt) = NULL;
1079 [ # # ]: 0 : NB_SEGS(pkt) = 1;
1080 : : rte_mbuf_raw_free(pkt);
1081 : : pkt = rep;
1082 : : }
1083 : 0 : rq_ci >>= sges_n;
1084 : 0 : ++rq_ci;
1085 : 0 : rq_ci <<= sges_n;
1086 : 0 : break;
1087 : : }
1088 [ # # ]: 0 : if (!pkt) {
1089 : 0 : cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_mask];
1090 : 0 : len = mlx5_rx_poll_len(rxq, cqe, cqe_n, cqe_mask,
1091 : : &mcqe, &skip_cnt, false, NULL);
1092 [ # # ]: 0 : if (unlikely(len & MLX5_ERROR_CQE_MASK)) {
1093 : : /* We drop packets with non-critical errors */
1094 : : rte_mbuf_raw_free(rep);
1095 [ # # ]: 0 : if (len == MLX5_CRITICAL_ERROR_CQE_RET) {
1096 : 0 : rq_ci = rxq->rq_ci << sges_n;
1097 : 0 : break;
1098 : : }
1099 : : /* Skip specified amount of error CQEs packets */
1100 : 0 : rq_ci >>= sges_n;
1101 : 0 : rq_ci += skip_cnt;
1102 : 0 : rq_ci <<= sges_n;
1103 : : MLX5_ASSERT(!pkt);
1104 : 0 : continue;
1105 : : }
1106 [ # # ]: 0 : if (len == 0) {
1107 : : rte_mbuf_raw_free(rep);
1108 : : break;
1109 : : }
1110 : : pkt = seg;
1111 : : MLX5_ASSERT(len >= (int)(rxq->crc_present << 2));
1112 : 0 : pkt->ol_flags &= RTE_MBUF_F_EXTERNAL;
1113 [ # # # # ]: 0 : if (rxq->cqe_comp_layout && mcqe)
1114 : 0 : cqe = &rxq->title_cqe;
1115 : : rxq_cq_to_mbuf(rxq, pkt, cqe, mcqe);
1116 [ # # ]: 0 : if (rxq->crc_present)
1117 : 0 : len -= RTE_ETHER_CRC_LEN;
1118 : 0 : PKT_LEN(pkt) = len;
1119 [ # # ]: 0 : if (cqe->lro_num_seg > 1) {
1120 : 0 : mlx5_lro_update_hdr
1121 : 0 : (rte_pktmbuf_mtod(pkt, uint8_t *), cqe,
1122 : : mcqe, rxq, len);
1123 : 0 : pkt->ol_flags |= RTE_MBUF_F_RX_LRO;
1124 : 0 : pkt->tso_segsz = len / cqe->lro_num_seg;
1125 : : }
1126 : : }
1127 : 0 : DATA_LEN(rep) = DATA_LEN(seg);
1128 : 0 : PKT_LEN(rep) = PKT_LEN(seg);
1129 : 0 : SET_DATA_OFF(rep, DATA_OFF(seg));
1130 : 0 : PORT(rep) = PORT(seg);
1131 : 0 : (*rxq->elts)[idx] = rep;
1132 : : /*
1133 : : * Fill NIC descriptor with the new buffer. The lkey and size
1134 : : * of the buffers are already known, only the buffer address
1135 : : * changes.
1136 : : */
1137 : 0 : wqe->addr = rte_cpu_to_be_64(rte_pktmbuf_mtod(rep, uintptr_t));
1138 : : /* If there's only one MR, no need to replace LKey in WQE. */
1139 [ # # ]: 0 : if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1))
1140 : 0 : wqe->lkey = mlx5_rx_mb2mr(rxq, rep);
1141 [ # # ]: 0 : if (len > DATA_LEN(seg)) {
1142 : 0 : len -= DATA_LEN(seg);
1143 : 0 : ++NB_SEGS(pkt);
1144 : 0 : ++rq_ci;
1145 : 0 : continue;
1146 : : }
1147 : 0 : DATA_LEN(seg) = len;
1148 : : #ifdef MLX5_PMD_SOFT_COUNTERS
1149 : : /* Increment bytes counter. */
1150 : 0 : rxq->stats.ibytes += PKT_LEN(pkt);
1151 : : #endif
1152 : : /* Return packet. */
1153 : 0 : *(pkts++) = pkt;
1154 : : pkt = NULL;
1155 : 0 : --pkts_n;
1156 : 0 : ++i;
1157 : : /* Align consumer index to the next stride. */
1158 : 0 : rq_ci >>= sges_n;
1159 : 0 : ++rq_ci;
1160 : 0 : rq_ci <<= sges_n;
1161 : : }
1162 [ # # # # ]: 0 : if (unlikely(i == 0 && ((rq_ci >> sges_n) == rxq->rq_ci)))
1163 : : return 0;
1164 : : /* Update the consumer index. */
1165 : 0 : rxq->rq_ci = rq_ci >> sges_n;
1166 : 0 : rte_io_wmb();
1167 [ # # ]: 0 : *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
1168 : 0 : rte_io_wmb();
1169 [ # # ]: 0 : *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
1170 : : #ifdef MLX5_PMD_SOFT_COUNTERS
1171 : : /* Increment packets counter. */
1172 : 0 : rxq->stats.ipackets += i;
1173 : : #endif
1174 : 0 : return i;
1175 : : }
1176 : :
1177 : : /**
1178 : : * DPDK callback for RX with Out-of-Order completions support.
1179 : : *
1180 : : * @param dpdk_rxq
1181 : : * Generic pointer to RX queue structure.
1182 : : * @param[out] pkts
1183 : : * Array to store received packets.
1184 : : * @param pkts_n
1185 : : * Maximum number of packets in array.
1186 : : *
1187 : : * @return
1188 : : * Number of packets successfully received (<= pkts_n).
1189 : : */
1190 : : uint16_t
1191 : 0 : mlx5_rx_burst_out_of_order(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
1192 : : {
1193 : : struct mlx5_rxq_data *rxq = dpdk_rxq;
1194 : 0 : const uint32_t wqe_n = 1 << rxq->elts_n;
1195 : 0 : const uint32_t wqe_mask = wqe_n - 1;
1196 : 0 : const uint32_t cqe_n = 1 << rxq->cqe_n;
1197 : 0 : const uint32_t cqe_mask = cqe_n - 1;
1198 : 0 : const unsigned int sges_n = rxq->sges_n;
1199 : 0 : const uint32_t pkt_mask = wqe_mask >> sges_n;
1200 : : struct rte_mbuf *pkt = NULL;
1201 : : struct rte_mbuf *seg = NULL;
1202 : 0 : volatile struct mlx5_cqe *cqe =
1203 : 0 : &(*rxq->cqes)[rxq->cq_ci & cqe_mask];
1204 : : unsigned int i = 0;
1205 : : int len = 0; /* keep its value across iterations. */
1206 : 0 : const uint32_t rq_ci = rxq->rq_ci;
1207 : : uint32_t idx = 0;
1208 : :
1209 : : do {
1210 : : volatile struct mlx5_wqe_data_seg *wqe;
1211 : : struct rte_mbuf *rep = NULL;
1212 : : volatile struct mlx5_mini_cqe8 *mcqe = NULL;
1213 : : uint32_t delta;
1214 : : uint16_t skip_cnt;
1215 : :
1216 [ # # ]: 0 : if (!pkt) {
1217 : 0 : cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_mask];
1218 : : rte_prefetch0(cqe);
1219 : : /* Allocate from the first packet mbuf pool */
1220 : 0 : rep = (*rxq->elts)[0];
1221 : : /* We must allocate before CQE consuming to allow retry */
1222 : 0 : rep = rte_mbuf_raw_alloc(rep->pool);
1223 [ # # ]: 0 : if (unlikely(rep == NULL)) {
1224 : 0 : ++rxq->stats.rx_nombuf;
1225 : 0 : break;
1226 : : }
1227 : 0 : len = mlx5_rx_poll_len(rxq, cqe, cqe_n, cqe_mask,
1228 : : &mcqe, &skip_cnt, false, &idx);
1229 [ # # ]: 0 : if (unlikely(len == MLX5_CRITICAL_ERROR_CQE_RET)) {
1230 : : rte_mbuf_raw_free(rep);
1231 : 0 : mlx5_rq_win_reset(rxq);
1232 : 0 : break;
1233 : : }
1234 [ # # ]: 0 : if (len == 0) {
1235 : : rte_mbuf_raw_free(rep);
1236 : : break;
1237 : : }
1238 : 0 : idx &= pkt_mask;
1239 : 0 : delta = (idx - rxq->rq_ci) & pkt_mask;
1240 : : MLX5_ASSERT(delta < ((rxq->rq_win_idx_mask + 1) * MLX5_WINOOO_BITS));
1241 [ # # ]: 0 : if (likely(!mlx5_rq_win_test(rxq))) {
1242 : : /* No out of order completions in sliding window */
1243 [ # # ]: 0 : if (likely(delta == 0))
1244 : 0 : rxq->rq_ci++;
1245 : : else
1246 : : mlx5_rq_win_update(rxq, delta);
1247 : : } else {
1248 : : /* We have out of order completions */
1249 : 0 : rxq->rq_ci += mlx5_rq_win_advance(rxq, delta);
1250 : : }
1251 [ # # ]: 0 : if (rxq->zip.ai == 0)
1252 : 0 : rxq->rq_ci_ooo = rxq->rq_ci;
1253 : 0 : idx <<= sges_n;
1254 : : /* We drop packets with non-critical errors */
1255 [ # # ]: 0 : if (unlikely(len & MLX5_ERROR_CQE_MASK)) {
1256 : : rte_mbuf_raw_free(rep);
1257 : 0 : continue;
1258 : : }
1259 : : }
1260 : 0 : wqe = &((volatile struct mlx5_wqe_data_seg *)rxq->wqes)[idx];
1261 [ # # ]: 0 : if (unlikely(pkt))
1262 : 0 : NEXT(seg) = (*rxq->elts)[idx];
1263 : 0 : seg = (*rxq->elts)[idx];
1264 : : rte_prefetch0(seg);
1265 : : rte_prefetch0(wqe);
1266 : : /* Allocate the buf from the same pool. */
1267 [ # # ]: 0 : if (unlikely(rep == NULL)) {
1268 : 0 : rep = rte_mbuf_raw_alloc(seg->pool);
1269 [ # # ]: 0 : if (unlikely(rep == NULL)) {
1270 : 0 : ++rxq->stats.rx_nombuf;
1271 [ # # ]: 0 : if (!pkt) {
1272 : : /*
1273 : : * no buffers before we even started,
1274 : : * bail out silently.
1275 : : */
1276 : : break;
1277 : : }
1278 [ # # ]: 0 : while (pkt != seg) {
1279 : : MLX5_ASSERT(pkt != (*rxq->elts)[idx]);
1280 : 0 : rep = NEXT(pkt);
1281 : 0 : NEXT(pkt) = NULL;
1282 [ # # ]: 0 : NB_SEGS(pkt) = 1;
1283 : : rte_mbuf_raw_free(pkt);
1284 : : pkt = rep;
1285 : : }
1286 : : break;
1287 : : }
1288 : : }
1289 [ # # ]: 0 : if (!pkt) {
1290 : : pkt = seg;
1291 : : MLX5_ASSERT(len >= (int)(rxq->crc_present << 2));
1292 : 0 : pkt->ol_flags &= RTE_MBUF_F_EXTERNAL;
1293 [ # # # # ]: 0 : if (rxq->cqe_comp_layout && mcqe)
1294 : 0 : cqe = &rxq->title_cqe;
1295 : : rxq_cq_to_mbuf(rxq, pkt, cqe, mcqe);
1296 [ # # ]: 0 : if (rxq->crc_present)
1297 : 0 : len -= RTE_ETHER_CRC_LEN;
1298 : 0 : PKT_LEN(pkt) = len;
1299 [ # # ]: 0 : if (cqe->lro_num_seg > 1) {
1300 : 0 : mlx5_lro_update_hdr
1301 : 0 : (rte_pktmbuf_mtod(pkt, uint8_t *), cqe,
1302 : : mcqe, rxq, len);
1303 : 0 : pkt->ol_flags |= RTE_MBUF_F_RX_LRO;
1304 : 0 : pkt->tso_segsz = len / cqe->lro_num_seg;
1305 : : }
1306 : : }
1307 : 0 : DATA_LEN(rep) = DATA_LEN(seg);
1308 : 0 : PKT_LEN(rep) = PKT_LEN(seg);
1309 : 0 : SET_DATA_OFF(rep, DATA_OFF(seg));
1310 : 0 : PORT(rep) = PORT(seg);
1311 : 0 : (*rxq->elts)[idx] = rep;
1312 : : /*
1313 : : * Fill NIC descriptor with the new buffer. The lkey and size
1314 : : * of the buffers are already known, only the buffer address
1315 : : * changes.
1316 : : */
1317 : 0 : wqe->addr = rte_cpu_to_be_64(rte_pktmbuf_mtod(rep, uintptr_t));
1318 : : /* If there's only one MR, no need to replace LKey in WQE. */
1319 [ # # ]: 0 : if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1))
1320 : 0 : wqe->lkey = mlx5_rx_mb2mr(rxq, rep);
1321 [ # # ]: 0 : if (len > DATA_LEN(seg)) {
1322 : 0 : len -= DATA_LEN(seg);
1323 : 0 : ++NB_SEGS(pkt);
1324 : 0 : ++idx;
1325 : 0 : idx &= wqe_mask;
1326 : 0 : continue;
1327 : : }
1328 : 0 : DATA_LEN(seg) = len;
1329 : : #ifdef MLX5_PMD_SOFT_COUNTERS
1330 : : /* Increment bytes counter. */
1331 : 0 : rxq->stats.ibytes += PKT_LEN(pkt);
1332 : : #endif
1333 : : /* Return packet. */
1334 : 0 : *(pkts++) = pkt;
1335 : : pkt = NULL;
1336 : 0 : ++i;
1337 [ # # ]: 0 : } while (i < pkts_n);
1338 [ # # # # ]: 0 : if (unlikely(i == 0 && rq_ci == rxq->rq_ci_ooo))
1339 : : return 0;
1340 : : /* Update the consumer index. */
1341 : 0 : rte_io_wmb();
1342 [ # # ]: 0 : *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
1343 : 0 : rte_io_wmb();
1344 [ # # ]: 0 : *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci_ooo);
1345 : : #ifdef MLX5_PMD_SOFT_COUNTERS
1346 : : /* Increment packets counter. */
1347 : 0 : rxq->stats.ipackets += i;
1348 : : #endif
1349 : 0 : return i;
1350 : : }
1351 : :
1352 : : /**
1353 : : * Update LRO packet TCP header.
1354 : : * The HW LRO feature doesn't update the TCP header after coalescing the
1355 : : * TCP segments but supplies information in CQE to fill it by SW.
1356 : : *
1357 : : * @param tcp
1358 : : * Pointer to the TCP header.
1359 : : * @param cqe
1360 : : * Pointer to the completion entry.
1361 : : * @param phcsum
1362 : : * The L3 pseudo-header checksum.
1363 : : */
1364 : : static inline void
1365 : 0 : mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr *__rte_restrict tcp,
1366 : : volatile struct mlx5_cqe *__rte_restrict cqe,
1367 : : uint32_t phcsum, uint8_t l4_type)
1368 : : {
1369 : : /*
1370 : : * The HW calculates only the TCP payload checksum, need to complete
1371 : : * the TCP header checksum and the L3 pseudo-header checksum.
1372 : : */
1373 : 0 : uint32_t csum = phcsum + cqe->csum;
1374 : :
1375 [ # # ]: 0 : if (l4_type == MLX5_L4_HDR_TYPE_TCP_EMPTY_ACK ||
1376 : : l4_type == MLX5_L4_HDR_TYPE_TCP_WITH_ACL) {
1377 : 0 : tcp->tcp_flags |= RTE_TCP_ACK_FLAG;
1378 : 0 : tcp->recv_ack = cqe->lro_ack_seq_num;
1379 : 0 : tcp->rx_win = cqe->lro_tcp_win;
1380 : : }
1381 [ # # ]: 0 : if (cqe->lro_tcppsh_abort_dupack & MLX5_CQE_LRO_PUSH_MASK)
1382 : 0 : tcp->tcp_flags |= RTE_TCP_PSH_FLAG;
1383 : 0 : tcp->cksum = 0;
1384 : 0 : csum += rte_raw_cksum(tcp, (tcp->data_off >> 4) * 4);
1385 : 0 : csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
1386 : 0 : csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
1387 : 0 : csum = (~csum) & 0xffff;
1388 [ # # ]: 0 : if (csum == 0)
1389 : : csum = 0xffff;
1390 : 0 : tcp->cksum = csum;
1391 : 0 : }
1392 : :
1393 : : /**
1394 : : * Update LRO packet headers.
1395 : : * The HW LRO feature doesn't update the L3/TCP headers after coalescing the
1396 : : * TCP segments but supply information in CQE to fill it by SW.
1397 : : *
1398 : : * @param padd
1399 : : * The packet address.
1400 : : * @param cqe
1401 : : * Pointer to the completion entry.
1402 : : * @param len
1403 : : * The packet length.
1404 : : */
1405 : : static inline void
1406 : 0 : mlx5_lro_update_hdr(uint8_t *__rte_restrict padd,
1407 : : volatile struct mlx5_cqe *__rte_restrict cqe,
1408 : : volatile struct mlx5_mini_cqe8 *mcqe,
1409 : : struct mlx5_rxq_data *rxq, uint32_t len)
1410 : : {
1411 : : union {
1412 : : struct rte_ether_hdr *eth;
1413 : : struct rte_vlan_hdr *vlan;
1414 : : struct rte_ipv4_hdr *ipv4;
1415 : : struct rte_ipv6_hdr *ipv6;
1416 : : struct rte_tcp_hdr *tcp;
1417 : : uint8_t *hdr;
1418 : : } h = {
1419 : : .hdr = padd,
1420 : : };
1421 : 0 : uint16_t proto = h.eth->ether_type;
1422 : : uint32_t phcsum;
1423 : : uint8_t l4_type;
1424 : :
1425 : 0 : h.eth++;
1426 : 0 : while (proto == RTE_BE16(RTE_ETHER_TYPE_VLAN) ||
1427 [ # # ]: 0 : proto == RTE_BE16(RTE_ETHER_TYPE_QINQ)) {
1428 : 0 : proto = h.vlan->eth_proto;
1429 : 0 : h.vlan++;
1430 : : }
1431 [ # # ]: 0 : if (proto == RTE_BE16(RTE_ETHER_TYPE_IPV4)) {
1432 : 0 : h.ipv4->time_to_live = cqe->lro_min_ttl;
1433 [ # # ]: 0 : h.ipv4->total_length = rte_cpu_to_be_16(len - (h.hdr - padd));
1434 : 0 : h.ipv4->hdr_checksum = 0;
1435 : 0 : h.ipv4->hdr_checksum = rte_ipv4_cksum(h.ipv4);
1436 : 0 : phcsum = rte_ipv4_phdr_cksum(h.ipv4, 0);
1437 : 0 : h.ipv4++;
1438 : : } else {
1439 : 0 : h.ipv6->hop_limits = cqe->lro_min_ttl;
1440 [ # # ]: 0 : h.ipv6->payload_len = rte_cpu_to_be_16(len - (h.hdr - padd) -
1441 : : sizeof(*h.ipv6));
1442 : 0 : phcsum = rte_ipv6_phdr_cksum(h.ipv6, 0);
1443 : 0 : h.ipv6++;
1444 : : }
1445 [ # # ]: 0 : if (mcqe == NULL ||
1446 [ # # ]: 0 : rxq->mcqe_format != MLX5_CQE_RESP_FORMAT_L34H_STRIDX)
1447 : 0 : l4_type = (rte_be_to_cpu_16(cqe->hdr_type_etc) &
1448 : 0 : MLX5_CQE_L4_TYPE_MASK) >> MLX5_CQE_L4_TYPE_SHIFT;
1449 : : else
1450 : 0 : l4_type = (rte_be_to_cpu_16(mcqe->hdr_type) &
1451 : 0 : MLX5_CQE_L4_TYPE_MASK) >> MLX5_CQE_L4_TYPE_SHIFT;
1452 : 0 : mlx5_lro_update_tcp_hdr(h.tcp, cqe, phcsum, l4_type);
1453 : 0 : }
1454 : :
1455 : : void
1456 : 0 : mlx5_mprq_buf_free(struct mlx5_mprq_buf *buf)
1457 : : {
1458 : 0 : mlx5_mprq_buf_free_cb(NULL, buf);
1459 : 0 : }
1460 : :
1461 : : /**
1462 : : * DPDK callback for RX with Multi-Packet RQ support.
1463 : : *
1464 : : * @param dpdk_rxq
1465 : : * Generic pointer to RX queue structure.
1466 : : * @param[out] pkts
1467 : : * Array to store received packets.
1468 : : * @param pkts_n
1469 : : * Maximum number of packets in array.
1470 : : *
1471 : : * @return
1472 : : * Number of packets successfully received (<= pkts_n).
1473 : : */
1474 : : uint16_t
1475 : 0 : mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
1476 : : {
1477 : : struct mlx5_rxq_data *rxq = dpdk_rxq;
1478 : 0 : const uint32_t strd_n = RTE_BIT32(rxq->log_strd_num);
1479 : 0 : const uint32_t strd_sz = RTE_BIT32(rxq->log_strd_sz);
1480 : 0 : const uint32_t cqe_n = 1 << rxq->cqe_n;
1481 : 0 : const uint32_t cq_mask = cqe_n - 1;
1482 : 0 : const uint32_t wqe_n = 1 << rxq->elts_n;
1483 : 0 : const uint32_t wq_mask = wqe_n - 1;
1484 : : volatile struct mlx5_cqe *cqe = &(*rxq->cqes)[rxq->cq_ci & cq_mask];
1485 : : unsigned int i = 0;
1486 : 0 : uint32_t rq_ci = rxq->rq_ci;
1487 : 0 : uint16_t consumed_strd = rxq->consumed_strd;
1488 : 0 : struct mlx5_mprq_buf *buf = (*rxq->mprq_bufs)[rq_ci & wq_mask];
1489 : :
1490 [ # # ]: 0 : while (i < pkts_n) {
1491 : : struct rte_mbuf *pkt;
1492 : : int ret;
1493 : : uint32_t len;
1494 : : uint16_t strd_cnt;
1495 : : uint16_t strd_idx;
1496 : : uint32_t byte_cnt;
1497 : : uint16_t skip_cnt;
1498 : : volatile struct mlx5_mini_cqe8 *mcqe = NULL;
1499 : : enum mlx5_rqx_code rxq_code;
1500 : :
1501 [ # # ]: 0 : if (consumed_strd == strd_n) {
1502 : : /* Replace WQE if the buffer is still in use. */
1503 [ # # ]: 0 : mprq_buf_replace(rxq, rq_ci & wq_mask);
1504 : : /* Advance to the next WQE. */
1505 : : consumed_strd = 0;
1506 : 0 : ++rq_ci;
1507 : 0 : buf = (*rxq->mprq_bufs)[rq_ci & wq_mask];
1508 : : }
1509 : 0 : cqe = &(*rxq->cqes)[rxq->cq_ci & cq_mask];
1510 : 0 : ret = mlx5_rx_poll_len(rxq, cqe, cqe_n, cq_mask, &mcqe, &skip_cnt, true, NULL);
1511 [ # # ]: 0 : if (unlikely(ret & MLX5_ERROR_CQE_MASK)) {
1512 [ # # ]: 0 : if (ret == MLX5_CRITICAL_ERROR_CQE_RET) {
1513 : 0 : rq_ci = rxq->rq_ci;
1514 : 0 : consumed_strd = rxq->consumed_strd;
1515 : 0 : break;
1516 : : }
1517 : 0 : consumed_strd += skip_cnt;
1518 [ # # ]: 0 : while (consumed_strd >= strd_n) {
1519 : : /* Replace WQE if the buffer is still in use. */
1520 [ # # ]: 0 : mprq_buf_replace(rxq, rq_ci & wq_mask);
1521 : : /* Advance to the next WQE. */
1522 : 0 : consumed_strd -= strd_n;
1523 : 0 : ++rq_ci;
1524 : 0 : buf = (*rxq->mprq_bufs)[rq_ci & wq_mask];
1525 : : }
1526 : 0 : cqe = &(*rxq->cqes)[rxq->cq_ci & cq_mask];
1527 : : }
1528 [ # # ]: 0 : if (ret == 0)
1529 : : break;
1530 : 0 : byte_cnt = ret;
1531 : 0 : len = (byte_cnt & MLX5_MPRQ_LEN_MASK) >> MLX5_MPRQ_LEN_SHIFT;
1532 : : MLX5_ASSERT((int)len >= (rxq->crc_present << 2));
1533 [ # # ]: 0 : if (rxq->crc_present)
1534 : 0 : len -= RTE_ETHER_CRC_LEN;
1535 [ # # ]: 0 : if (mcqe &&
1536 [ # # ]: 0 : rxq->mcqe_format == MLX5_CQE_RESP_FORMAT_FTAG_STRIDX)
1537 : 0 : strd_cnt = (len / strd_sz) + !!(len % strd_sz);
1538 : : else
1539 : 0 : strd_cnt = (byte_cnt & MLX5_MPRQ_STRIDE_NUM_MASK) >>
1540 : : MLX5_MPRQ_STRIDE_NUM_SHIFT;
1541 : : MLX5_ASSERT(strd_cnt);
1542 : 0 : consumed_strd += strd_cnt;
1543 [ # # ]: 0 : if (byte_cnt & MLX5_MPRQ_FILLER_MASK)
1544 : 0 : continue;
1545 [ # # # # ]: 0 : if (rxq->cqe_comp_layout && mcqe)
1546 : 0 : cqe = &rxq->title_cqe;
1547 [ # # ]: 0 : strd_idx = rte_be_to_cpu_16(mcqe == NULL ?
1548 : : cqe->wqe_counter :
1549 : : mcqe->stride_idx);
1550 : : MLX5_ASSERT(strd_idx < strd_n);
1551 : : MLX5_ASSERT(!((rte_be_to_cpu_16(cqe->wqe_id) ^ rq_ci) &
1552 : : wq_mask));
1553 : 0 : pkt = rte_pktmbuf_alloc(rxq->mp);
1554 [ # # ]: 0 : if (unlikely(pkt == NULL)) {
1555 : 0 : ++rxq->stats.rx_nombuf;
1556 : 0 : break;
1557 : : }
1558 : : len = (byte_cnt & MLX5_MPRQ_LEN_MASK) >> MLX5_MPRQ_LEN_SHIFT;
1559 : : MLX5_ASSERT((int)len >= (rxq->crc_present << 2));
1560 [ # # ]: 0 : if (rxq->crc_present)
1561 : 0 : len -= RTE_ETHER_CRC_LEN;
1562 [ # # ]: 0 : rxq_code = mprq_buf_to_pkt(rxq, pkt, len, buf,
1563 : : strd_idx, strd_cnt);
1564 [ # # ]: 0 : if (unlikely(rxq_code != MLX5_RXQ_CODE_EXIT)) {
1565 : : rte_pktmbuf_free_seg(pkt);
1566 [ # # ]: 0 : if (rxq_code == MLX5_RXQ_CODE_DROPPED) {
1567 : 0 : ++rxq->stats.idropped;
1568 : 0 : continue;
1569 : : }
1570 [ # # ]: 0 : if (rxq_code == MLX5_RXQ_CODE_NOMBUF) {
1571 : 0 : ++rxq->stats.rx_nombuf;
1572 : 0 : break;
1573 : : }
1574 : : }
1575 : : rxq_cq_to_mbuf(rxq, pkt, cqe, mcqe);
1576 [ # # ]: 0 : if (cqe->lro_num_seg > 1) {
1577 : 0 : mlx5_lro_update_hdr(rte_pktmbuf_mtod(pkt, uint8_t *),
1578 : : cqe, mcqe, rxq, len);
1579 : 0 : pkt->ol_flags |= RTE_MBUF_F_RX_LRO;
1580 : 0 : pkt->tso_segsz = len / cqe->lro_num_seg;
1581 : : }
1582 : 0 : PKT_LEN(pkt) = len;
1583 : 0 : PORT(pkt) = rxq->port_id;
1584 : : #ifdef MLX5_PMD_SOFT_COUNTERS
1585 : : /* Increment bytes counter. */
1586 : 0 : rxq->stats.ibytes += PKT_LEN(pkt);
1587 : : #endif
1588 : : /* Return packet. */
1589 : 0 : *(pkts++) = pkt;
1590 : 0 : ++i;
1591 : : }
1592 : : /* Update the consumer indexes. */
1593 : 0 : rxq->consumed_strd = consumed_strd;
1594 : 0 : rte_io_wmb();
1595 [ # # ]: 0 : *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
1596 [ # # ]: 0 : if (rq_ci != rxq->rq_ci) {
1597 : 0 : rxq->rq_ci = rq_ci;
1598 : 0 : rte_io_wmb();
1599 [ # # ]: 0 : *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
1600 : : }
1601 : : #ifdef MLX5_PMD_SOFT_COUNTERS
1602 : : /* Increment packets counter. */
1603 : 0 : rxq->stats.ipackets += i;
1604 : : #endif
1605 : 0 : return i;
1606 : : }
1607 : :
1608 : : int
1609 : 0 : mlx5_rx_queue_lwm_query(struct rte_eth_dev *dev,
1610 : : uint16_t *queue_id, uint8_t *lwm)
1611 : : {
1612 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1613 : : unsigned int rxq_id, found = 0, n;
1614 : : struct mlx5_rxq_priv *rxq;
1615 : :
1616 [ # # ]: 0 : if (!queue_id)
1617 : : return -EINVAL;
1618 : : /* Query all the Rx queues of the port in a circular way. */
1619 [ # # ]: 0 : for (rxq_id = *queue_id, n = 0; n < priv->rxqs_n; n++) {
1620 : 0 : rxq = mlx5_rxq_get(dev, rxq_id);
1621 [ # # # # ]: 0 : if (rxq && rxq->lwm_event_pending) {
1622 : 0 : pthread_mutex_lock(&priv->sh->lwm_config_lock);
1623 : 0 : rxq->lwm_event_pending = 0;
1624 : 0 : pthread_mutex_unlock(&priv->sh->lwm_config_lock);
1625 : 0 : *queue_id = rxq_id;
1626 : : found = 1;
1627 [ # # ]: 0 : if (lwm)
1628 : 0 : *lwm = mlx5_rxq_lwm_to_percentage(rxq);
1629 : : break;
1630 : : }
1631 : 0 : rxq_id = (rxq_id + 1) % priv->rxqs_n;
1632 : : }
1633 : 0 : return found;
1634 : : }
1635 : :
1636 : : /**
1637 : : * Rte interrupt handler for LWM event.
1638 : : * It first checks if the event arrives, if so process the callback for
1639 : : * RTE_ETH_EVENT_RX_LWM.
1640 : : *
1641 : : * @param args
1642 : : * Generic pointer to mlx5_priv.
1643 : : */
1644 : : void
1645 : 0 : mlx5_dev_interrupt_handler_lwm(void *args)
1646 : : {
1647 : : struct mlx5_priv *priv = args;
1648 : : struct mlx5_rxq_priv *rxq;
1649 : : struct rte_eth_dev *dev;
1650 : 0 : int ret, rxq_idx = 0, port_id = 0;
1651 : :
1652 : 0 : ret = priv->obj_ops.rxq_event_get_lwm(priv, &rxq_idx, &port_id);
1653 [ # # ]: 0 : if (unlikely(ret < 0)) {
1654 : 0 : DRV_LOG(WARNING, "Cannot get LWM event context.");
1655 : 0 : return;
1656 : : }
1657 : 0 : DRV_LOG(INFO, "%s get LWM event, port_id:%d rxq_id:%d.", __func__,
1658 : : port_id, rxq_idx);
1659 : 0 : dev = &rte_eth_devices[port_id];
1660 : 0 : rxq = mlx5_rxq_get(dev, rxq_idx);
1661 [ # # ]: 0 : if (rxq) {
1662 : 0 : pthread_mutex_lock(&priv->sh->lwm_config_lock);
1663 : 0 : rxq->lwm_event_pending = 1;
1664 : 0 : pthread_mutex_unlock(&priv->sh->lwm_config_lock);
1665 : : }
1666 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_RX_AVAIL_THRESH, NULL);
1667 : : }
1668 : :
1669 : : /**
1670 : : * DPDK callback to arm an Rx queue LWM(limit watermark) event.
1671 : : * While the Rx queue fullness reaches the LWM limit, the driver catches
1672 : : * an HW event and invokes the user event callback.
1673 : : * After the last event handling, the user needs to call this API again
1674 : : * to arm an additional event.
1675 : : *
1676 : : * @param dev
1677 : : * Pointer to the device structure.
1678 : : * @param[in] rx_queue_id
1679 : : * Rx queue identificator.
1680 : : * @param[in] lwm
1681 : : * The LWM value, is defined by a percentage of the Rx queue size.
1682 : : * [1-99] to set a new LWM (update the old value).
1683 : : * 0 to unarm the event.
1684 : : *
1685 : : * @return
1686 : : * 0 : operation success.
1687 : : * Otherwise:
1688 : : * - ENOMEM - not enough memory to create LWM event channel.
1689 : : * - EINVAL - the input Rxq is not created by devx.
1690 : : * - E2BIG - lwm is bigger than 99.
1691 : : */
1692 : : int
1693 : 0 : mlx5_rx_queue_lwm_set(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1694 : : uint8_t lwm)
1695 : : {
1696 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1697 : 0 : uint16_t port_id = PORT_ID(priv);
1698 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, rx_queue_id);
1699 : 0 : uint16_t event_nums[1] = {MLX5_EVENT_TYPE_SRQ_LIMIT_REACHED};
1700 : : struct mlx5_rxq_data *rxq_data;
1701 : : uint32_t wqe_cnt;
1702 : : uint64_t cookie;
1703 : : int ret = 0;
1704 : :
1705 [ # # ]: 0 : if (!rxq) {
1706 : 0 : rte_errno = EINVAL;
1707 : 0 : return -rte_errno;
1708 : : }
1709 : 0 : rxq_data = &rxq->ctrl->rxq;
1710 : : /* Ensure the Rq is created by devx. */
1711 [ # # ]: 0 : if (priv->obj_ops.rxq_obj_new != devx_obj_ops.rxq_obj_new) {
1712 : 0 : rte_errno = EINVAL;
1713 : 0 : return -rte_errno;
1714 : : }
1715 [ # # ]: 0 : if (lwm > 99) {
1716 : 0 : DRV_LOG(WARNING, "Too big LWM configuration.");
1717 : 0 : rte_errno = E2BIG;
1718 : 0 : return -rte_errno;
1719 : : }
1720 : : /* Start config LWM. */
1721 : 0 : pthread_mutex_lock(&priv->sh->lwm_config_lock);
1722 [ # # # # ]: 0 : if (rxq->lwm == 0 && lwm == 0) {
1723 : : /* Both old/new values are 0, do nothing. */
1724 : : ret = 0;
1725 : 0 : goto end;
1726 : : }
1727 : 0 : wqe_cnt = 1 << (rxq_data->elts_n - rxq_data->sges_n);
1728 [ # # ]: 0 : if (lwm) {
1729 [ # # ]: 0 : if (!priv->sh->devx_channel_lwm) {
1730 : 0 : ret = mlx5_lwm_setup(priv);
1731 [ # # ]: 0 : if (ret) {
1732 : 0 : DRV_LOG(WARNING,
1733 : : "Failed to create shared_lwm.");
1734 : 0 : rte_errno = ENOMEM;
1735 : : ret = -rte_errno;
1736 : 0 : goto end;
1737 : : }
1738 : : }
1739 [ # # ]: 0 : if (!rxq->lwm_devx_subscribed) {
1740 : 0 : cookie = ((uint32_t)
1741 : 0 : (port_id << LWM_COOKIE_PORTID_OFFSET)) |
1742 : 0 : (rx_queue_id << LWM_COOKIE_RXQID_OFFSET);
1743 : 0 : ret = mlx5_os_devx_subscribe_devx_event
1744 : 0 : (priv->sh->devx_channel_lwm,
1745 : 0 : rxq->devx_rq.rq->obj,
1746 : : sizeof(event_nums),
1747 : : event_nums,
1748 : : cookie);
1749 [ # # ]: 0 : if (ret) {
1750 [ # # ]: 0 : rte_errno = rte_errno ? rte_errno : EINVAL;
1751 : 0 : ret = -rte_errno;
1752 : 0 : goto end;
1753 : : }
1754 : 0 : rxq->lwm_devx_subscribed = 1;
1755 : : }
1756 : : }
1757 : : /* Save LWM to rxq and send modify_rq devx command. */
1758 : 0 : rxq->lwm = lwm * wqe_cnt / 100;
1759 : : /* Prevent integer division loss when switch lwm number to percentage. */
1760 [ # # # # ]: 0 : if (lwm && (lwm * wqe_cnt % 100)) {
1761 [ # # ]: 0 : rxq->lwm = ((uint32_t)(rxq->lwm + 1) >= wqe_cnt) ?
1762 : : rxq->lwm : (rxq->lwm + 1);
1763 : : }
1764 [ # # # # ]: 0 : if (lwm && !rxq->lwm) {
1765 : : /* With mprq, wqe_cnt may be < 100. */
1766 : 0 : DRV_LOG(WARNING, "Too small LWM configuration.");
1767 : 0 : rte_errno = EINVAL;
1768 : : ret = -rte_errno;
1769 : 0 : goto end;
1770 : : }
1771 : 0 : ret = mlx5_devx_modify_rq(rxq, MLX5_RXQ_MOD_RDY2RDY);
1772 : 0 : end:
1773 : 0 : pthread_mutex_unlock(&priv->sh->lwm_config_lock);
1774 : 0 : return ret;
1775 : : }
1776 : :
1777 : : /**
1778 : : * Mlx5 access register function to configure host shaper.
1779 : : * It calls API in libmtcr_ul to access QSHR(Qos Shaper Host Register)
1780 : : * in firmware.
1781 : : *
1782 : : * @param dev
1783 : : * Pointer to rte_eth_dev.
1784 : : * @param lwm_triggered
1785 : : * Flag to enable/disable lwm_triggered bit in QSHR.
1786 : : * @param rate
1787 : : * Host shaper rate, unit is 100Mbps, set to 0 means disable the shaper.
1788 : : * @return
1789 : : * 0 : operation success.
1790 : : * Otherwise:
1791 : : * - ENOENT - no ibdev interface.
1792 : : * - EBUSY - the register access unit is busy.
1793 : : * - EIO - the register access command meets IO error.
1794 : : */
1795 : : static int
1796 : : mlxreg_host_shaper_config(struct rte_eth_dev *dev,
1797 : : bool lwm_triggered, uint8_t rate)
1798 : : {
1799 : : #ifdef HAVE_MLX5_MSTFLINT
1800 : : struct mlx5_priv *priv = dev->data->dev_private;
1801 : : uint32_t data[MLX5_ST_SZ_DW(register_qshr)] = {0};
1802 : : int rc, retry_count = 3;
1803 : : mfile *mf = NULL;
1804 : : int status;
1805 : : void *ptr;
1806 : :
1807 : : mf = mopen(priv->sh->ibdev_name);
1808 : : if (!mf) {
1809 : : DRV_LOG(WARNING, "mopen failed\n");
1810 : : rte_errno = ENOENT;
1811 : : return -rte_errno;
1812 : : }
1813 : : MLX5_SET(register_qshr, data, connected_host, 1);
1814 : : MLX5_SET(register_qshr, data, fast_response, lwm_triggered ? 1 : 0);
1815 : : MLX5_SET(register_qshr, data, local_port, 1);
1816 : : ptr = MLX5_ADDR_OF(register_qshr, data, global_config);
1817 : : MLX5_SET(ets_global_config_register, ptr, rate_limit_update, 1);
1818 : : MLX5_SET(ets_global_config_register, ptr, max_bw_units,
1819 : : rate ? ETS_GLOBAL_CONFIG_BW_UNIT_HUNDREDS_MBPS :
1820 : : ETS_GLOBAL_CONFIG_BW_UNIT_DISABLED);
1821 : : MLX5_SET(ets_global_config_register, ptr, max_bw_value, rate);
1822 : : do {
1823 : : rc = maccess_reg(mf,
1824 : : MLX5_QSHR_REGISTER_ID,
1825 : : MACCESS_REG_METHOD_SET,
1826 : : (u_int32_t *)&data[0],
1827 : : sizeof(data),
1828 : : sizeof(data),
1829 : : sizeof(data),
1830 : : &status);
1831 : : if ((rc != ME_ICMD_STATUS_IFC_BUSY &&
1832 : : status != ME_REG_ACCESS_BAD_PARAM) ||
1833 : : !(mf->flags & MDEVS_REM)) {
1834 : : break;
1835 : : }
1836 : : DRV_LOG(WARNING, "%s retry.", __func__);
1837 : : usleep(10000);
1838 : : } while (retry_count-- > 0);
1839 : : mclose(mf);
1840 : : rte_errno = (rc == ME_REG_ACCESS_DEV_BUSY) ? EBUSY : EIO;
1841 : : return rc ? -rte_errno : 0;
1842 : : #else
1843 : : (void)dev;
1844 : : (void)lwm_triggered;
1845 : : (void)rate;
1846 : : return -1;
1847 : : #endif
1848 : : }
1849 : :
1850 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_host_shaper_config, 22.07)
1851 : 0 : int rte_pmd_mlx5_host_shaper_config(int port_id, uint8_t rate,
1852 : : uint32_t flags)
1853 : : {
1854 : : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1855 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1856 : : bool lwm_triggered =
1857 : 0 : !!(flags & RTE_BIT32(RTE_PMD_MLX5_HOST_SHAPER_FLAG_AVAIL_THRESH_TRIGGERED));
1858 : :
1859 [ # # ]: 0 : if (!lwm_triggered) {
1860 : 0 : priv->sh->host_shaper_rate = rate;
1861 : : } else {
1862 [ # # # ]: 0 : switch (rate) {
1863 : 0 : case 0:
1864 : : /* Rate 0 means disable lwm_triggered. */
1865 : 0 : priv->sh->lwm_triggered = 0;
1866 : 0 : break;
1867 : 0 : case 1:
1868 : : /* Rate 1 means enable lwm_triggered. */
1869 : 0 : priv->sh->lwm_triggered = 1;
1870 : 0 : break;
1871 : : default:
1872 : : return -ENOTSUP;
1873 : : }
1874 : : }
1875 : 0 : return mlxreg_host_shaper_config(dev, priv->sh->lwm_triggered,
1876 : : priv->sh->host_shaper_rate);
1877 : : }
1878 : :
1879 : : /**
1880 : : * Dump RQ/CQ Context to a file.
1881 : : *
1882 : : * @param[in] port_id
1883 : : * Port ID
1884 : : * @param[in] queue_id
1885 : : * Queue ID
1886 : : * @param[in] filename
1887 : : * Name of file to dump the Rx Queue Context
1888 : : *
1889 : : * @return
1890 : : * 0 for Success, non-zero value depending on failure type
1891 : : */
1892 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_rxq_dump_contexts, 24.07)
1893 : 0 : int rte_pmd_mlx5_rxq_dump_contexts(uint16_t port_id, uint16_t queue_id, const char *filename)
1894 : : {
1895 : : struct rte_eth_dev *dev;
1896 : : struct mlx5_rxq_priv *rxq;
1897 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1898 : : struct mlx5_rxq_obj *rxq_obj;
1899 : : struct mlx5_devx_rq *rq;
1900 : : struct mlx5_devx_cq *cq;
1901 : : struct mlx5_devx_obj *rq_devx_obj;
1902 : : struct mlx5_devx_obj *cq_devx_obj;
1903 : :
1904 : 0 : uint32_t rq_out[MLX5_ST_SZ_DW(query_rq_out)] = {0};
1905 : 0 : uint32_t cq_out[MLX5_ST_SZ_DW(query_cq_out)] = {0};
1906 : :
1907 : : int ret;
1908 : : FILE *fd;
1909 : 0 : MKSTR(path, "./%s", filename);
1910 : :
1911 [ # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id))
1912 : : return -ENODEV;
1913 : :
1914 [ # # ]: 0 : if (rte_eth_rx_queue_is_valid(port_id, queue_id))
1915 : : return -EINVAL;
1916 : :
1917 : 0 : fd = fopen(path, "w");
1918 [ # # ]: 0 : if (!fd) {
1919 : 0 : rte_errno = errno;
1920 : 0 : return -EIO;
1921 : : }
1922 : :
1923 : 0 : dev = &rte_eth_devices[port_id];
1924 : 0 : rxq = mlx5_rxq_ref(dev, queue_id);
1925 : 0 : rxq_ctrl = rxq->ctrl;
1926 : 0 : rxq_obj = rxq_ctrl->obj;
1927 : : rq = &rxq->devx_rq;
1928 : : cq = &rxq_obj->cq_obj;
1929 : 0 : rq_devx_obj = rq->rq;
1930 : 0 : cq_devx_obj = cq->cq;
1931 : :
1932 : : do {
1933 : 0 : ret = mlx5_devx_cmd_query_rq(rq_devx_obj, rq_out, sizeof(rq_out));
1934 [ # # ]: 0 : if (ret)
1935 : : break;
1936 : :
1937 : : /* Dump rq query output to file */
1938 : 0 : MKSTR(rq_headline, "RQ DevX ID = %u Port = %u Queue index = %u ",
1939 : : rq_devx_obj->id, port_id, queue_id);
1940 : 0 : mlx5_dump_to_file(fd, NULL, rq_headline, 0);
1941 : 0 : mlx5_dump_to_file(fd, "Query RQ Dump:",
1942 : : (const void *)((uintptr_t)rq_out),
1943 : : sizeof(rq_out));
1944 : :
1945 : 0 : ret = mlx5_devx_cmd_query_cq(cq_devx_obj, cq_out, sizeof(cq_out));
1946 [ # # ]: 0 : if (ret)
1947 : : break;
1948 : :
1949 : : /* Dump cq query output to file */
1950 : 0 : MKSTR(cq_headline, "CQ DevX ID = %u Port = %u Queue index = %u ",
1951 : : cq_devx_obj->id, port_id, queue_id);
1952 : 0 : mlx5_dump_to_file(fd, NULL, cq_headline, 0);
1953 : 0 : mlx5_dump_to_file(fd, "Query CQ Dump:",
1954 : : (const void *)((uintptr_t)cq_out),
1955 : : sizeof(cq_out));
1956 : : } while (false);
1957 : :
1958 : 0 : fclose(fd);
1959 : 0 : return ret;
1960 : : }
|