Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2015 6WIND S.A.
3 : : * Copyright 2015 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #include <stddef.h>
7 : : #include <errno.h>
8 : : #include <string.h>
9 : : #include <stdint.h>
10 : : #include <fcntl.h>
11 : : #include <sys/queue.h>
12 : :
13 : : #include <eal_export.h>
14 : : #include <rte_mbuf.h>
15 : : #include <rte_malloc.h>
16 : : #include <ethdev_driver.h>
17 : : #include <rte_common.h>
18 : : #include <rte_interrupts.h>
19 : : #include <rte_debug.h>
20 : : #include <rte_io.h>
21 : : #include <rte_eal_paging.h>
22 : :
23 : : #include <mlx5_glue.h>
24 : : #include <mlx5_malloc.h>
25 : : #include <mlx5_common.h>
26 : : #include <mlx5_common_mr.h>
27 : :
28 : : #include "mlx5_defs.h"
29 : : #include "mlx5.h"
30 : : #include "mlx5_rx.h"
31 : : #include "mlx5_utils.h"
32 : : #include "mlx5_autoconf.h"
33 : : #include "mlx5_devx.h"
34 : : #include "rte_pmd_mlx5.h"
35 : :
36 : :
37 : : /* Default RSS hash key also used for ConnectX-3. */
38 : : uint8_t mlx5_rss_hash_default_key[] = {
39 : : 0x2c, 0xc6, 0x81, 0xd1,
40 : : 0x5b, 0xdb, 0xf4, 0xf7,
41 : : 0xfc, 0xa2, 0x83, 0x19,
42 : : 0xdb, 0x1a, 0x3e, 0x94,
43 : : 0x6b, 0x9e, 0x38, 0xd9,
44 : : 0x2c, 0x9c, 0x03, 0xd1,
45 : : 0xad, 0x99, 0x44, 0xa7,
46 : : 0xd9, 0x56, 0x3d, 0x59,
47 : : 0x06, 0x3c, 0x25, 0xf3,
48 : : 0xfc, 0x1f, 0xdc, 0x2a,
49 : : };
50 : :
51 : : /* Length of the default RSS hash key. */
52 : : static_assert(MLX5_RSS_HASH_KEY_LEN ==
53 : : (unsigned int)sizeof(mlx5_rss_hash_default_key),
54 : : "wrong RSS default key size.");
55 : :
56 : : /**
57 : : * Calculate the number of CQEs in CQ for the Rx queue.
58 : : *
59 : : * @param rxq_data
60 : : * Pointer to receive queue structure.
61 : : *
62 : : * @return
63 : : * Number of CQEs in CQ.
64 : : */
65 : : unsigned int
66 : 0 : mlx5_rxq_cqe_num(struct mlx5_rxq_data *rxq_data)
67 : : {
68 : : unsigned int cqe_n;
69 [ # # ]: 0 : unsigned int wqe_n = 1 << rxq_data->elts_n;
70 : :
71 [ # # ]: 0 : if (mlx5_rxq_mprq_enabled(rxq_data))
72 : 0 : cqe_n = wqe_n * RTE_BIT32(rxq_data->log_strd_num) - 1;
73 : : else
74 : 0 : cqe_n = wqe_n - 1;
75 : 0 : return cqe_n;
76 : : }
77 : :
78 : : /**
79 : : * Allocate RX queue elements for Multi-Packet RQ.
80 : : *
81 : : * @param rxq_ctrl
82 : : * Pointer to RX queue structure.
83 : : *
84 : : * @return
85 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
86 : : */
87 : : static int
88 : 0 : rxq_alloc_elts_mprq(struct mlx5_rxq_ctrl *rxq_ctrl)
89 : : {
90 : : struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
91 : 0 : unsigned int wqe_n = 1 << rxq->elts_n;
92 : : unsigned int i;
93 : : int err;
94 : :
95 : : /* Iterate on segments. */
96 [ # # ]: 0 : for (i = 0; i <= wqe_n; ++i) {
97 : : struct mlx5_mprq_buf *buf;
98 : :
99 [ # # # # ]: 0 : if (rte_mempool_get(rxq->mprq_mp, (void **)&buf) < 0) {
100 : 0 : DRV_LOG(ERR, "port %u empty mbuf pool", rxq->port_id);
101 : 0 : rte_errno = ENOMEM;
102 : 0 : goto error;
103 : : }
104 [ # # ]: 0 : if (i < wqe_n)
105 : 0 : (*rxq->mprq_bufs)[i] = buf;
106 : : else
107 : 0 : rxq->mprq_repl = buf;
108 : : }
109 : 0 : DRV_LOG(DEBUG,
110 : : "port %u MPRQ queue %u allocated and configured %u segments",
111 : : rxq->port_id, rxq->idx, wqe_n);
112 : 0 : return 0;
113 : : error:
114 : : err = rte_errno; /* Save rte_errno before cleanup. */
115 : : wqe_n = i;
116 [ # # ]: 0 : for (i = 0; (i != wqe_n); ++i) {
117 [ # # ]: 0 : if ((*rxq->mprq_bufs)[i] != NULL)
118 [ # # ]: 0 : rte_mempool_put(rxq->mprq_mp,
119 : : (*rxq->mprq_bufs)[i]);
120 : 0 : (*rxq->mprq_bufs)[i] = NULL;
121 : : }
122 : 0 : DRV_LOG(DEBUG, "port %u MPRQ queue %u failed, freed everything",
123 : : rxq->port_id, rxq->idx);
124 : 0 : rte_errno = err; /* Restore rte_errno. */
125 : 0 : return -rte_errno;
126 : : }
127 : :
128 : : /**
129 : : * Allocate RX queue elements for Single-Packet RQ.
130 : : *
131 : : * @param rxq_ctrl
132 : : * Pointer to RX queue structure.
133 : : *
134 : : * @return
135 : : * 0 on success, negative errno value on failure.
136 : : */
137 : : static int
138 : 0 : rxq_alloc_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
139 : : {
140 [ # # ]: 0 : const unsigned int sges_n = 1 << rxq_ctrl->rxq.sges_n;
141 : : unsigned int elts_n = mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq) ?
142 : 0 : RTE_BIT32(rxq_ctrl->rxq.elts_n) *
143 [ # # ]: 0 : RTE_BIT32(rxq_ctrl->rxq.log_strd_num) :
144 : 0 : RTE_BIT32(rxq_ctrl->rxq.elts_n);
145 : 0 : bool has_vec_support = mlx5_rxq_check_vec_support(&rxq_ctrl->rxq) > 0;
146 : : unsigned int i;
147 : : int err;
148 : :
149 : : /* Iterate on segments. */
150 [ # # ]: 0 : for (i = 0; (i != elts_n); ++i) {
151 : 0 : struct mlx5_eth_rxseg *seg = &rxq_ctrl->rxq.rxseg[i % sges_n];
152 : : struct rte_mbuf *buf;
153 : :
154 [ # # ]: 0 : if (seg->mp) {
155 : 0 : buf = rte_pktmbuf_alloc(seg->mp);
156 [ # # ]: 0 : if (buf == NULL) {
157 [ # # ]: 0 : if (rxq_ctrl->share_group == 0)
158 : 0 : DRV_LOG(ERR, "port %u queue %u empty mbuf pool",
159 : : RXQ_PORT_ID(rxq_ctrl),
160 : : rxq_ctrl->rxq.idx);
161 : : else
162 : 0 : DRV_LOG(ERR, "share group %u queue %u empty mbuf pool",
163 : : rxq_ctrl->share_group,
164 : : rxq_ctrl->share_qid);
165 : 0 : rte_errno = ENOMEM;
166 : 0 : goto error;
167 : : }
168 : : /* Only vectored Rx routines rely on headroom size. */
169 : : MLX5_ASSERT(!has_vec_support ||
170 : : DATA_OFF(buf) >= RTE_PKTMBUF_HEADROOM);
171 : : /* Buffer is supposed to be empty. */
172 : : MLX5_ASSERT(rte_pktmbuf_data_len(buf) == 0);
173 : : MLX5_ASSERT(rte_pktmbuf_pkt_len(buf) == 0);
174 : : MLX5_ASSERT(!buf->next);
175 : : } else {
176 : 0 : buf = seg->null_mbuf;
177 : : }
178 : 0 : SET_DATA_OFF(buf, seg->offset);
179 : 0 : PORT(buf) = rxq_ctrl->rxq.port_id;
180 : 0 : DATA_LEN(buf) = seg->length;
181 : 0 : PKT_LEN(buf) = seg->length;
182 : 0 : NB_SEGS(buf) = 1;
183 : 0 : (*rxq_ctrl->rxq.elts)[i] = buf;
184 : : }
185 : : /* If Rx vector is activated. */
186 [ # # ]: 0 : if (has_vec_support) {
187 : : struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
188 : 0 : struct rte_mbuf *mbuf_init = &rxq->fake_mbuf;
189 : : struct rte_pktmbuf_pool_private *priv =
190 : : (struct rte_pktmbuf_pool_private *)
191 [ # # ]: 0 : rte_mempool_get_priv(rxq_ctrl->rxq.mp);
192 : : int j;
193 : :
194 : : /* Initialize default rearm_data for vPMD. */
195 [ # # ]: 0 : mbuf_init->data_off = RTE_PKTMBUF_HEADROOM;
196 : : rte_mbuf_refcnt_set(mbuf_init, 1);
197 : 0 : mbuf_init->nb_segs = 1;
198 : : /* For shared queues port is provided in CQE */
199 [ # # ]: 0 : mbuf_init->port = rxq->shared ? 0 : rxq->port_id;
200 [ # # ]: 0 : if (priv->flags & RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF)
201 : 0 : mbuf_init->ol_flags = RTE_MBUF_F_EXTERNAL;
202 : : /*
203 : : * prevent compiler reordering:
204 : : * rearm_data covers previous fields.
205 : : */
206 : 0 : rte_compiler_barrier();
207 : 0 : rxq->mbuf_initializer =
208 : : *(rte_xmm_t *)&mbuf_init->rearm_data;
209 : : /* Padding with a fake mbuf for vectorized Rx. */
210 [ # # ]: 0 : for (j = 0; j < MLX5_VPMD_DESCS_PER_LOOP; ++j)
211 : 0 : (*rxq->elts)[elts_n + j] = &rxq->fake_mbuf;
212 : : }
213 [ # # ]: 0 : if (rxq_ctrl->share_group == 0)
214 : 0 : DRV_LOG(DEBUG,
215 : : "port %u SPRQ queue %u allocated and configured %u segments (max %u packets)",
216 : : RXQ_PORT_ID(rxq_ctrl), rxq_ctrl->rxq.idx, elts_n,
217 : : elts_n / (1 << rxq_ctrl->rxq.sges_n));
218 : : else
219 : 0 : DRV_LOG(DEBUG,
220 : : "share group %u SPRQ queue %u allocated and configured %u segments (max %u packets)",
221 : : rxq_ctrl->share_group, rxq_ctrl->share_qid, elts_n,
222 : : elts_n / (1 << rxq_ctrl->rxq.sges_n));
223 : : return 0;
224 : : error:
225 : : err = rte_errno; /* Save rte_errno before cleanup. */
226 : : elts_n = i;
227 [ # # ]: 0 : for (i = 0; (i != elts_n); ++i) {
228 [ # # ]: 0 : if ((*rxq_ctrl->rxq.elts)[i] != NULL)
229 : : rte_pktmbuf_free_seg((*rxq_ctrl->rxq.elts)[i]);
230 : 0 : (*rxq_ctrl->rxq.elts)[i] = NULL;
231 : : }
232 [ # # ]: 0 : if (rxq_ctrl->share_group == 0)
233 : 0 : DRV_LOG(DEBUG, "port %u SPRQ queue %u failed, freed everything",
234 : : RXQ_PORT_ID(rxq_ctrl), rxq_ctrl->rxq.idx);
235 : : else
236 : 0 : DRV_LOG(DEBUG, "share group %u SPRQ queue %u failed, freed everything",
237 : : rxq_ctrl->share_group, rxq_ctrl->share_qid);
238 : 0 : rte_errno = err; /* Restore rte_errno. */
239 : 0 : return -rte_errno;
240 : : }
241 : :
242 : : /**
243 : : * Allocate RX queue elements.
244 : : *
245 : : * @param rxq_ctrl
246 : : * Pointer to RX queue structure.
247 : : *
248 : : * @return
249 : : * 0 on success, negative errno value on failure.
250 : : */
251 : : int
252 [ # # ]: 0 : mlx5_rxq_alloc_elts(struct mlx5_rxq_ctrl *rxq_ctrl)
253 : : {
254 : : int ret = 0;
255 : :
256 : : /**
257 : : * For MPRQ we need to allocate both MPRQ buffers
258 : : * for WQEs and simple mbufs for vector processing.
259 : : */
260 [ # # ]: 0 : if (mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq))
261 : 0 : ret = rxq_alloc_elts_mprq(rxq_ctrl);
262 [ # # ]: 0 : if (ret == 0)
263 : 0 : ret = rxq_alloc_elts_sprq(rxq_ctrl);
264 : 0 : return ret;
265 : : }
266 : :
267 : : /**
268 : : * Free RX queue elements for Multi-Packet RQ.
269 : : *
270 : : * @param rxq_ctrl
271 : : * Pointer to RX queue structure.
272 : : */
273 : : static void
274 : 0 : rxq_free_elts_mprq(struct mlx5_rxq_ctrl *rxq_ctrl)
275 : : {
276 : : struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
277 : : uint16_t i;
278 : :
279 : 0 : DRV_LOG(DEBUG, "port %u Multi-Packet Rx queue %u freeing %d WRs",
280 : : rxq->port_id, rxq->idx, (1u << rxq->elts_n));
281 [ # # ]: 0 : if (rxq->mprq_bufs == NULL)
282 : : return;
283 [ # # ]: 0 : for (i = 0; (i != (1u << rxq->elts_n)); ++i) {
284 [ # # ]: 0 : if ((*rxq->mprq_bufs)[i] != NULL)
285 : 0 : mlx5_mprq_buf_free((*rxq->mprq_bufs)[i]);
286 : 0 : (*rxq->mprq_bufs)[i] = NULL;
287 : : }
288 [ # # ]: 0 : if (rxq->mprq_repl != NULL) {
289 : 0 : mlx5_mprq_buf_free(rxq->mprq_repl);
290 : 0 : rxq->mprq_repl = NULL;
291 : : }
292 : : }
293 : :
294 : : /**
295 : : * Free RX queue elements for Single-Packet RQ.
296 : : *
297 : : * @param rxq_ctrl
298 : : * Pointer to RX queue structure.
299 : : */
300 : : static void
301 : 0 : rxq_free_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
302 : : {
303 [ # # ]: 0 : struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
304 [ # # ]: 0 : const uint16_t q_n = mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq) ?
305 : 0 : RTE_BIT32(rxq->elts_n) * RTE_BIT32(rxq->log_strd_num) :
306 : 0 : RTE_BIT32(rxq->elts_n);
307 : 0 : const uint16_t q_mask = q_n - 1;
308 [ # # ]: 0 : uint16_t elts_ci = mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq) ?
309 : 0 : rxq->elts_ci : rxq->rq_ci;
310 : 0 : uint16_t used = q_n - (elts_ci - rxq->rq_pi);
311 : : uint16_t i;
312 : :
313 [ # # ]: 0 : if (rxq_ctrl->share_group == 0)
314 : 0 : DRV_LOG(DEBUG, "port %u Rx queue %u freeing %d WRs",
315 : : RXQ_PORT_ID(rxq_ctrl), rxq->idx, q_n);
316 : : else
317 : 0 : DRV_LOG(DEBUG, "share group %u Rx queue %u freeing %d WRs",
318 : : rxq_ctrl->share_group, rxq_ctrl->share_qid, q_n);
319 [ # # ]: 0 : if (rxq->elts == NULL)
320 : : return;
321 : : /**
322 : : * Some mbuf in the Ring belongs to the application.
323 : : * They cannot be freed.
324 : : */
325 [ # # ]: 0 : if (mlx5_rxq_check_vec_support(rxq) > 0) {
326 [ # # ]: 0 : for (i = 0; i < used; ++i)
327 : 0 : (*rxq->elts)[(elts_ci + i) & q_mask] = NULL;
328 : 0 : rxq->rq_pi = elts_ci;
329 : : }
330 [ # # ]: 0 : for (i = 0; i != q_n; ++i) {
331 [ # # # # ]: 0 : if ((*rxq->elts)[i] != NULL && (*rxq->elts)[i]->pool != NULL)
332 : : rte_pktmbuf_free_seg((*rxq->elts)[i]);
333 : 0 : (*rxq->elts)[i] = NULL;
334 : : }
335 [ # # ]: 0 : for (i = 0; i < rxq->rxseg_n; i++) {
336 : 0 : mlx5_free(rxq->rxseg[i].null_mbuf);
337 : 0 : rxq->rxseg[i].null_mbuf = NULL;
338 : : }
339 : : }
340 : :
341 : : /**
342 : : * Free RX queue elements.
343 : : *
344 : : * @param rxq_ctrl
345 : : * Pointer to RX queue structure.
346 : : */
347 : : static void
348 [ # # ]: 0 : rxq_free_elts(struct mlx5_rxq_ctrl *rxq_ctrl)
349 : : {
350 : : /*
351 : : * For MPRQ we need to allocate both MPRQ buffers
352 : : * for WQEs and simple mbufs for vector processing.
353 : : */
354 [ # # ]: 0 : if (mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq))
355 : 0 : rxq_free_elts_mprq(rxq_ctrl);
356 : 0 : rxq_free_elts_sprq(rxq_ctrl);
357 : 0 : }
358 : :
359 : : /**
360 : : * Returns the per-queue supported offloads.
361 : : *
362 : : * @param dev
363 : : * Pointer to Ethernet device.
364 : : *
365 : : * @return
366 : : * Supported Rx offloads.
367 : : */
368 : : uint64_t
369 : 0 : mlx5_get_rx_queue_offloads(struct rte_eth_dev *dev)
370 : : {
371 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
372 : : uint64_t offloads = (RTE_ETH_RX_OFFLOAD_SCATTER |
373 : : RTE_ETH_RX_OFFLOAD_TIMESTAMP |
374 : : RTE_ETH_RX_OFFLOAD_RSS_HASH);
375 : :
376 [ # # ]: 0 : if (!priv->config.mprq.enabled)
377 : : offloads |= RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT;
378 [ # # ]: 0 : if (priv->sh->config.hw_fcs_strip)
379 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
380 [ # # ]: 0 : if (priv->sh->dev_cap.hw_csum)
381 : 0 : offloads |= (RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
382 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
383 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM);
384 [ # # ]: 0 : if (priv->sh->dev_cap.hw_vlan_strip)
385 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
386 [ # # ]: 0 : if (priv->sh->config.lro_allowed)
387 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_TCP_LRO;
388 : 0 : return offloads;
389 : : }
390 : :
391 : :
392 : : /**
393 : : * Returns the per-port supported offloads.
394 : : *
395 : : * @return
396 : : * Supported Rx offloads.
397 : : */
398 : : uint64_t
399 : 0 : mlx5_get_rx_port_offloads(void)
400 : : {
401 : : uint64_t offloads = RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
402 : :
403 : 0 : return offloads;
404 : : }
405 : :
406 : : /**
407 : : * Verify if the queue can be released.
408 : : *
409 : : * @param dev
410 : : * Pointer to Ethernet device.
411 : : * @param idx
412 : : * RX queue index.
413 : : *
414 : : * @return
415 : : * 1 if the queue can be released
416 : : * 0 if the queue can not be released, there are references to it.
417 : : * Negative errno and rte_errno is set if queue doesn't exist.
418 : : */
419 : : static int
420 : 0 : mlx5_rxq_releasable(struct rte_eth_dev *dev, uint16_t idx)
421 : : {
422 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
423 : :
424 [ # # ]: 0 : if (rxq == NULL) {
425 : 0 : rte_errno = EINVAL;
426 : 0 : return -rte_errno;
427 : : }
428 : 0 : return (rte_atomic_load_explicit(&rxq->refcnt, rte_memory_order_relaxed) == 1);
429 : : }
430 : :
431 : : /* Fetches and drops all SW-owned and error CQEs to synchronize CQ. */
432 : : void
433 : 0 : mlx5_rxq_sync_cq(struct mlx5_rxq_data *rxq)
434 : : {
435 : 0 : const uint16_t cqe_n = 1 << rxq->cqe_n;
436 : 0 : const uint16_t cqe_mask = cqe_n - 1;
437 : : volatile struct mlx5_cqe *cqe;
438 : : int ret, i;
439 : :
440 : : i = cqe_n;
441 : : do {
442 : 0 : cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_mask];
443 [ # # ]: 0 : ret = check_cqe(cqe, cqe_n, rxq->cq_ci);
444 : : if (ret == MLX5_CQE_STATUS_HW_OWN)
445 : : break;
446 [ # # ]: 0 : if (ret == MLX5_CQE_STATUS_ERR) {
447 : 0 : rxq->cq_ci++;
448 : 0 : continue;
449 : : }
450 : : MLX5_ASSERT(ret == MLX5_CQE_STATUS_SW_OWN);
451 [ # # ]: 0 : if (MLX5_CQE_FORMAT(cqe->op_own) != MLX5_COMPRESSED) {
452 : 0 : rxq->cq_ci++;
453 : 0 : continue;
454 : : }
455 : : /* Compute the next non compressed CQE. */
456 : 0 : rxq->cq_ci += rxq->cqe_comp_layout ?
457 [ # # ]: 0 : (MLX5_CQE_NUM_MINIS(cqe->op_own) + 1U) :
458 : 0 : rte_be_to_cpu_32(cqe->byte_cnt);
459 : :
460 [ # # ]: 0 : } while (--i);
461 : : /* Move all CQEs to HW ownership, including possible MiniCQEs. */
462 [ # # ]: 0 : for (i = 0; i < cqe_n; i++) {
463 : 0 : cqe = &(*rxq->cqes)[i];
464 : 0 : cqe->validity_iteration_count = MLX5_CQE_VIC_INIT;
465 : 0 : cqe->op_own = MLX5_CQE_INVALIDATE;
466 : : }
467 : : /* Resync CQE and WQE (WQ in RESET state). */
468 : 0 : rte_io_wmb();
469 [ # # ]: 0 : *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
470 : 0 : rte_io_wmb();
471 : 0 : *rxq->rq_db = rte_cpu_to_be_32(0);
472 : 0 : rte_io_wmb();
473 : 0 : }
474 : :
475 : : /**
476 : : * Rx queue stop. Device queue goes to the RESET state,
477 : : * all involved mbufs are freed from WQ.
478 : : *
479 : : * @param dev
480 : : * Pointer to Ethernet device structure.
481 : : * @param idx
482 : : * RX queue index.
483 : : *
484 : : * @return
485 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
486 : : */
487 : : int
488 : 0 : mlx5_rx_queue_stop_primary(struct rte_eth_dev *dev, uint16_t idx)
489 : : {
490 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
491 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
492 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl;
493 : : int ret;
494 : :
495 : : MLX5_ASSERT(rxq != NULL && rxq_ctrl != NULL);
496 : : MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
497 : 0 : ret = priv->obj_ops.rxq_obj_modify(rxq, MLX5_RXQ_MOD_RDY2RST);
498 [ # # ]: 0 : if (ret) {
499 : 0 : DRV_LOG(ERR, "Cannot change Rx WQ state to RESET: %s",
500 : : strerror(errno));
501 : 0 : rte_errno = errno;
502 : 0 : return ret;
503 : : }
504 : : /* Remove all processes CQEs. */
505 : 0 : mlx5_rxq_sync_cq(&rxq_ctrl->rxq);
506 : : /* Free all involved mbufs. */
507 : 0 : rxq_free_elts(rxq_ctrl);
508 : : /* Set the actual queue state. */
509 : 0 : dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STOPPED;
510 : 0 : return 0;
511 : : }
512 : :
513 : : /**
514 : : * Rx queue stop. Device queue goes to the RESET state,
515 : : * all involved mbufs are freed from WQ.
516 : : *
517 : : * @param dev
518 : : * Pointer to Ethernet device structure.
519 : : * @param idx
520 : : * RX queue index.
521 : : *
522 : : * @return
523 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
524 : : */
525 : : int
526 : 0 : mlx5_rx_queue_stop(struct rte_eth_dev *dev, uint16_t idx)
527 : : {
528 : 0 : eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
529 : : int ret;
530 : :
531 [ # # ]: 0 : if (rte_eth_dev_is_rx_hairpin_queue(dev, idx)) {
532 : 0 : DRV_LOG(ERR, "Hairpin queue can't be stopped");
533 : 0 : rte_errno = EINVAL;
534 : 0 : return -EINVAL;
535 : : }
536 [ # # ]: 0 : if (dev->data->rx_queue_state[idx] == RTE_ETH_QUEUE_STATE_STOPPED)
537 : : return 0;
538 : : /*
539 : : * Vectorized Rx burst requires the CQ and RQ indices
540 : : * synchronized, that might be broken on RQ restart
541 : : * and cause Rx malfunction, so queue stopping is
542 : : * not supported if vectorized Rx burst is engaged.
543 : : * The routine pointer depends on the process type,
544 : : * should perform check there. MPRQ is not supported as well.
545 : : */
546 [ # # ]: 0 : if (pkt_burst != mlx5_rx_burst) {
547 : 0 : DRV_LOG(ERR, "Rx queue stop is only supported "
548 : : "for non-vectorized single-packet Rx");
549 : 0 : rte_errno = EINVAL;
550 : 0 : return -EINVAL;
551 : : }
552 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
553 : 0 : ret = mlx5_mp_os_req_queue_control(dev, idx,
554 : : MLX5_MP_REQ_QUEUE_RX_STOP);
555 : : } else {
556 : 0 : ret = mlx5_rx_queue_stop_primary(dev, idx);
557 : : }
558 : : return ret;
559 : : }
560 : :
561 : : /**
562 : : * Rx queue start. Device queue goes to the ready state,
563 : : * all required mbufs are allocated and WQ is replenished.
564 : : *
565 : : * @param dev
566 : : * Pointer to Ethernet device structure.
567 : : * @param idx
568 : : * RX queue index.
569 : : *
570 : : * @return
571 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
572 : : */
573 : : int
574 : 0 : mlx5_rx_queue_start_primary(struct rte_eth_dev *dev, uint16_t idx)
575 : : {
576 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
577 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
578 : 0 : struct mlx5_rxq_data *rxq_data = &rxq->ctrl->rxq;
579 : : int ret;
580 : :
581 : : MLX5_ASSERT(rxq != NULL && rxq->ctrl != NULL);
582 : : MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
583 : : /* Allocate needed buffers. */
584 : 0 : ret = mlx5_rxq_alloc_elts(rxq->ctrl);
585 [ # # ]: 0 : if (ret) {
586 : 0 : DRV_LOG(ERR, "Cannot reallocate buffers for Rx WQ");
587 : 0 : rte_errno = errno;
588 : 0 : return ret;
589 : : }
590 : 0 : rte_io_wmb();
591 [ # # ]: 0 : *rxq_data->cq_db = rte_cpu_to_be_32(rxq_data->cq_ci);
592 : 0 : rte_io_wmb();
593 : : /* Reset RQ consumer before moving queue to READY state. */
594 : 0 : *rxq_data->rq_db = rte_cpu_to_be_32(0);
595 : 0 : rte_io_wmb();
596 : 0 : ret = priv->obj_ops.rxq_obj_modify(rxq, MLX5_RXQ_MOD_RST2RDY);
597 [ # # ]: 0 : if (ret) {
598 : 0 : DRV_LOG(ERR, "Cannot change Rx WQ state to READY: %s",
599 : : strerror(errno));
600 : 0 : rte_errno = errno;
601 : 0 : return ret;
602 : : }
603 : : /* Reinitialize RQ - set WQEs. */
604 : 0 : ret = mlx5_rxq_initialize(rxq_data);
605 [ # # ]: 0 : if (ret) {
606 : 0 : DRV_LOG(ERR, "Port %u Rx queue %u RQ initialization failure.",
607 : : priv->dev_data->port_id, rxq->idx);
608 : 0 : rte_errno = ENOMEM;
609 : 0 : return ret;
610 : : }
611 : 0 : rxq_data->err_state = MLX5_RXQ_ERR_STATE_NO_ERROR;
612 : : /* Set actual queue state. */
613 : 0 : dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED;
614 : 0 : return 0;
615 : : }
616 : :
617 : : /**
618 : : * Rx queue start. Device queue goes to the ready state,
619 : : * all required mbufs are allocated and WQ is replenished.
620 : : *
621 : : * @param dev
622 : : * Pointer to Ethernet device structure.
623 : : * @param idx
624 : : * RX queue index.
625 : : *
626 : : * @return
627 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
628 : : */
629 : : int
630 : 0 : mlx5_rx_queue_start(struct rte_eth_dev *dev, uint16_t idx)
631 : : {
632 : : int ret;
633 : :
634 [ # # ]: 0 : if (rte_eth_dev_is_rx_hairpin_queue(dev, idx)) {
635 : 0 : DRV_LOG(ERR, "Hairpin queue can't be started");
636 : 0 : rte_errno = EINVAL;
637 : 0 : return -EINVAL;
638 : : }
639 [ # # ]: 0 : if (dev->data->rx_queue_state[idx] == RTE_ETH_QUEUE_STATE_STARTED)
640 : : return 0;
641 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
642 : 0 : ret = mlx5_mp_os_req_queue_control(dev, idx,
643 : : MLX5_MP_REQ_QUEUE_RX_START);
644 : : } else {
645 : 0 : ret = mlx5_rx_queue_start_primary(dev, idx);
646 : : }
647 : : return ret;
648 : : }
649 : :
650 : : /**
651 : : * Rx queue presetup checks.
652 : : *
653 : : * @param dev
654 : : * Pointer to Ethernet device structure.
655 : : * @param idx
656 : : * RX queue index.
657 : : * @param desc
658 : : * Number of descriptors to configure in queue.
659 : : * @param[out] rxq_ctrl
660 : : * Address of pointer to shared Rx queue control.
661 : : *
662 : : * @return
663 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
664 : : */
665 : : static int
666 : 0 : mlx5_rx_queue_pre_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t *desc,
667 : : struct mlx5_rxq_ctrl **rxq_ctrl)
668 : : {
669 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
670 : :
671 [ # # ]: 0 : if (*desc > mlx5_dev_get_max_wq_size(priv->sh)) {
672 : 0 : DRV_LOG(ERR,
673 : : "port %u number of descriptors requested for Rx queue"
674 : : " %u is more than supported",
675 : : dev->data->port_id, idx);
676 : 0 : rte_errno = EINVAL;
677 : 0 : return -EINVAL;
678 : : }
679 [ # # ]: 0 : if (!rte_is_power_of_2(*desc)) {
680 : 0 : *desc = 1 << log2above(*desc);
681 : 0 : DRV_LOG(WARNING,
682 : : "port %u increased number of descriptors in Rx queue %u"
683 : : " to the next power of two (%d)",
684 : : dev->data->port_id, idx, *desc);
685 : : }
686 : 0 : DRV_LOG(DEBUG, "port %u configuring Rx queue %u for %u descriptors",
687 : : dev->data->port_id, idx, *desc);
688 [ # # ]: 0 : if (idx >= priv->rxqs_n) {
689 : 0 : DRV_LOG(ERR, "port %u Rx queue index out of range (%u >= %u)",
690 : : dev->data->port_id, idx, priv->rxqs_n);
691 : 0 : rte_errno = EOVERFLOW;
692 : 0 : return -rte_errno;
693 : : }
694 [ # # # # ]: 0 : if (rxq_ctrl == NULL || *rxq_ctrl == NULL)
695 : : return 0;
696 [ # # ]: 0 : if (!(*rxq_ctrl)->rxq.shared) {
697 [ # # ]: 0 : if (!mlx5_rxq_releasable(dev, idx)) {
698 : 0 : DRV_LOG(ERR, "port %u unable to release queue index %u",
699 : : dev->data->port_id, idx);
700 : 0 : rte_errno = EBUSY;
701 : 0 : return -rte_errno;
702 : : }
703 : 0 : mlx5_rxq_release(dev, idx);
704 : : } else {
705 : 0 : if ((*rxq_ctrl)->obj != NULL)
706 : : /* Some port using shared Rx queue has been started. */
707 : : return 0;
708 : : }
709 : : return 0;
710 : : }
711 : :
712 : : /**
713 : : * Get the shared Rx queue object that matches group and queue index.
714 : : *
715 : : * @param dev
716 : : * Pointer to Ethernet device structure.
717 : : * @param group
718 : : * Shared RXQ group.
719 : : * @param share_qid
720 : : * Shared RX queue index.
721 : : *
722 : : * @return
723 : : * Shared RXQ object that matching, or NULL if not found.
724 : : */
725 : : static struct mlx5_rxq_ctrl *
726 : : mlx5_shared_rxq_get(struct rte_eth_dev *dev, uint32_t group, uint16_t share_qid)
727 : : {
728 : : struct mlx5_rxq_ctrl *rxq_ctrl;
729 : : struct mlx5_priv *priv = dev->data->dev_private;
730 : :
731 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &priv->sh->shared_rxqs, share_entry) {
732 [ # # ]: 0 : if (rxq_ctrl->share_group == group &&
733 [ # # ]: 0 : rxq_ctrl->share_qid == share_qid)
734 : : return rxq_ctrl;
735 : : }
736 : : return NULL;
737 : : }
738 : :
739 : : /**
740 : : * Check whether requested Rx queue configuration matches shared RXQ.
741 : : *
742 : : * @param rxq_ctrl
743 : : * Pointer to shared RXQ.
744 : : * @param dev
745 : : * Pointer to Ethernet device structure.
746 : : * @param idx
747 : : * Queue index.
748 : : * @param desc
749 : : * Number of descriptors to configure in queue.
750 : : * @param socket
751 : : * NUMA socket on which memory must be allocated.
752 : : * @param[in] conf
753 : : * Thresholds parameters.
754 : : * @param mp
755 : : * Memory pool for buffer allocations.
756 : : *
757 : : * @return
758 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
759 : : */
760 : : static bool
761 : 0 : mlx5_shared_rxq_match(struct mlx5_rxq_ctrl *rxq_ctrl, struct rte_eth_dev *dev,
762 : : uint16_t idx, uint16_t desc, unsigned int socket,
763 : : const struct rte_eth_rxconf *conf,
764 : : struct rte_mempool *mp)
765 : : {
766 : 0 : struct mlx5_priv *spriv = LIST_FIRST(&rxq_ctrl->owners)->priv;
767 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
768 : : unsigned int i;
769 : :
770 : : RTE_SET_USED(conf);
771 [ # # ]: 0 : if (rxq_ctrl->socket != socket) {
772 : 0 : DRV_LOG(ERR, "port %u queue index %u failed to join shared group: socket mismatch",
773 : : dev->data->port_id, idx);
774 : 0 : return false;
775 : : }
776 [ # # ]: 0 : if (rxq_ctrl->rxq.elts_n != log2above(desc)) {
777 : 0 : DRV_LOG(ERR, "port %u queue index %u failed to join shared group: descriptor number mismatch",
778 : : dev->data->port_id, idx);
779 : 0 : return false;
780 : : }
781 [ # # ]: 0 : if (dev->data->mtu != rxq_ctrl->mtu) {
782 : : /*
783 : : * MTU mismatch is only a problem when the queue hasn't been started yet.
784 : : * If rxq_ctrl->obj is NULL, the queue hardware objects haven't been created,
785 : : * meaning we're in the initial configuration phase where MTU must match.
786 : : * If obj != NULL, the queue is already running with its hardware configured,
787 : : * and runtime MTU changes are safe as they only update software bookkeeping
788 : : * without recreating hardware resources.
789 : : */
790 [ # # ]: 0 : if (rxq_ctrl->obj == NULL) {
791 : 0 : DRV_LOG(DEBUG, "port %u queue index %u: mtu mismatch with existing shared rxq_ctrl "
792 : : "(port mtu=%u rxq_ctrl mtu=%u), reconfiguration needed",
793 : : dev->data->port_id, idx, dev->data->mtu, rxq_ctrl->mtu);
794 : 0 : return false;
795 : : }
796 : : }
797 : 0 : if (priv->dev_data->dev_conf.intr_conf.rxq !=
798 [ # # ]: 0 : spriv->dev_data->dev_conf.intr_conf.rxq) {
799 : 0 : DRV_LOG(ERR, "port %u queue index %u failed to join shared group: interrupt mismatch",
800 : : dev->data->port_id, idx);
801 : 0 : return false;
802 : : }
803 [ # # # # ]: 0 : if (mp != NULL && rxq_ctrl->rxq.mp != mp) {
804 : 0 : DRV_LOG(ERR, "port %u queue index %u failed to join shared group: mempool mismatch",
805 : : dev->data->port_id, idx);
806 : 0 : return false;
807 [ # # ]: 0 : } else if (mp == NULL) {
808 [ # # ]: 0 : if (conf->rx_nseg != rxq_ctrl->rxseg_n) {
809 : 0 : DRV_LOG(ERR, "port %u queue index %u failed to join shared group: segment number mismatch",
810 : : dev->data->port_id, idx);
811 : 0 : return false;
812 : : }
813 [ # # ]: 0 : for (i = 0; i < conf->rx_nseg; i++) {
814 [ # # ]: 0 : if (memcmp(&conf->rx_seg[i].split, &rxq_ctrl->rxseg[i],
815 : : sizeof(struct rte_eth_rxseg_split))) {
816 : 0 : DRV_LOG(ERR, "port %u queue index %u failed to join shared group: segment %u configuration mismatch",
817 : : dev->data->port_id, idx, i);
818 : 0 : return false;
819 : : }
820 : : }
821 : : }
822 [ # # ]: 0 : if (priv->config.hw_padding != spriv->config.hw_padding) {
823 : 0 : DRV_LOG(ERR, "port %u queue index %u failed to join shared group: padding mismatch",
824 : : dev->data->port_id, idx);
825 : 0 : return false;
826 : : }
827 [ # # ]: 0 : if (priv->config.cqe_comp != spriv->config.cqe_comp ||
828 [ # # ]: 0 : (priv->config.cqe_comp &&
829 [ # # ]: 0 : priv->config.cqe_comp_fmt != spriv->config.cqe_comp_fmt)) {
830 : 0 : DRV_LOG(ERR, "port %u queue index %u failed to join shared group: CQE compression mismatch",
831 : : dev->data->port_id, idx);
832 : 0 : return false;
833 : : }
834 : : return true;
835 : : }
836 : :
837 : : /**
838 : : *
839 : : * @param dev
840 : : * Pointer to Ethernet device structure.
841 : : * @param idx
842 : : * RX queue index.
843 : : * @param desc
844 : : * Number of descriptors to configure in queue.
845 : : * @param socket
846 : : * NUMA socket on which memory must be allocated.
847 : : * @param[in] conf
848 : : * Thresholds parameters.
849 : : * @param mp
850 : : * Memory pool for buffer allocations.
851 : : *
852 : : * @return
853 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
854 : : */
855 : : int
856 : 0 : mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
857 : : unsigned int socket, const struct rte_eth_rxconf *conf,
858 : : struct rte_mempool *mp)
859 : : {
860 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
861 : : struct mlx5_rxq_priv *rxq;
862 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = NULL;
863 : 0 : struct rte_eth_rxseg_split *rx_seg =
864 : : (struct rte_eth_rxseg_split *)conf->rx_seg;
865 : 0 : struct rte_eth_rxseg_split rx_single = {.mp = mp};
866 : 0 : uint16_t n_seg = conf->rx_nseg;
867 : : int res;
868 : 0 : uint64_t offloads = conf->offloads |
869 : 0 : dev->data->dev_conf.rxmode.offloads;
870 : : bool is_extmem = false;
871 : :
872 [ # # ]: 0 : if ((offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) &&
873 [ # # ]: 0 : !priv->sh->config.lro_allowed) {
874 : 0 : DRV_LOG(ERR,
875 : : "Port %u queue %u LRO is configured but not allowed.",
876 : : dev->data->port_id, idx);
877 : 0 : rte_errno = EINVAL;
878 : 0 : return -rte_errno;
879 : : }
880 [ # # ]: 0 : if (mp) {
881 : : /*
882 : : * The parameters should be checked on rte_eth_dev layer.
883 : : * If mp is specified it means the compatible configuration
884 : : * without buffer split feature tuning.
885 : : */
886 : : rx_seg = &rx_single;
887 : : n_seg = 1;
888 : 0 : is_extmem = rte_pktmbuf_priv_flags(mp) &
889 : : RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF;
890 : : }
891 [ # # ]: 0 : if (n_seg > 1) {
892 : : /* The offloads should be checked on rte_eth_dev layer. */
893 : : MLX5_ASSERT(offloads & RTE_ETH_RX_OFFLOAD_SCATTER);
894 [ # # ]: 0 : if (!(offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)) {
895 : 0 : DRV_LOG(ERR, "port %u queue index %u split "
896 : : "offload not configured",
897 : : dev->data->port_id, idx);
898 : 0 : rte_errno = ENOSPC;
899 : 0 : return -rte_errno;
900 : : }
901 : : MLX5_ASSERT(n_seg < MLX5_MAX_RXQ_NSEG);
902 : : }
903 [ # # ]: 0 : if (conf->share_group > 0) {
904 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.mem_rq_rmp) {
905 : 0 : DRV_LOG(ERR, "port %u queue index %u shared Rx queue not supported by fw",
906 : : dev->data->port_id, idx);
907 : 0 : rte_errno = EINVAL;
908 : 0 : return -rte_errno;
909 : : }
910 [ # # ]: 0 : if (priv->obj_ops.rxq_obj_new != mlx5_devx_obj_ops.rxq_obj_new) {
911 : 0 : DRV_LOG(ERR, "port %u queue index %u shared Rx queue needs DevX api",
912 : : dev->data->port_id, idx);
913 : 0 : rte_errno = EINVAL;
914 : 0 : return -rte_errno;
915 : : }
916 [ # # ]: 0 : if (conf->share_qid >= priv->rxqs_n) {
917 : 0 : DRV_LOG(ERR, "port %u shared Rx queue index %u > number of Rx queues %u",
918 : : dev->data->port_id, conf->share_qid,
919 : : priv->rxqs_n);
920 : 0 : rte_errno = EINVAL;
921 : 0 : return -rte_errno;
922 : : }
923 [ # # ]: 0 : if (priv->config.mprq.enabled) {
924 : 0 : DRV_LOG(ERR, "port %u shared Rx queue index %u: not supported when MPRQ enabled",
925 : : dev->data->port_id, conf->share_qid);
926 : 0 : rte_errno = EINVAL;
927 : 0 : return -rte_errno;
928 : : }
929 : : /* Try to reuse shared RXQ. */
930 : 0 : rxq_ctrl = mlx5_shared_rxq_get(dev, conf->share_group,
931 : : conf->share_qid);
932 : 0 : res = mlx5_rx_queue_pre_setup(dev, idx, &desc, &rxq_ctrl);
933 [ # # ]: 0 : if (res)
934 : : return res;
935 [ # # # # ]: 0 : if (rxq_ctrl != NULL &&
936 : 0 : !mlx5_shared_rxq_match(rxq_ctrl, dev, idx, desc, socket,
937 : : conf, mp)) {
938 : : struct mlx5_rxq_priv *rxq_tmp;
939 : : bool empty;
940 : :
941 : : /*
942 : : * Configuration mismatch detected with existing shared RXQ.
943 : : * We need to reconfigure, but only if it's safe to do so.
944 : : *
945 : : * First check: If hardware objects are allocated, the shared queue has
946 : : * been started. Reconfiguration would require destroying and recreating
947 : : * hardware resources, which cannot be done while the queue is active.
948 : : * Return EBUSY to force caller to stop the queue first.
949 : : */
950 [ # # ]: 0 : if (rxq_ctrl->obj != NULL) {
951 : 0 : DRV_LOG(ERR, "port %u queue index %u: cannot reconfigure shared RXQ while started",
952 : : dev->data->port_id, idx);
953 : 0 : rte_errno = EBUSY;
954 : 0 : return -rte_errno;
955 : : }
956 : :
957 : : /*
958 : : * Second check: Even if hardware objects aren't allocated yet,
959 : : * verify that no owner port is actively using this queue.
960 : : * refcnt == 1 means the queue exists but is idle (only setup reference).
961 : : * refcnt > 1 means the queue is being used by flows or other components.
962 : : * This prevents releasing a queue that other ports depend on.
963 : : */
964 [ # # ]: 0 : LIST_FOREACH(rxq_tmp, &rxq_ctrl->owners, owner_entry) {
965 [ # # ]: 0 : if (rxq_tmp->refcnt > 1) {
966 : 0 : DRV_LOG(ERR, "port %u queue index %u: cannot reconfigure shared RXQ "
967 : : "while other ports are running",
968 : : dev->data->port_id, idx);
969 : 0 : rte_errno = EBUSY;
970 : 0 : return -rte_errno;
971 : : }
972 : : }
973 : :
974 : : /*
975 : : * Safe to reconfigure: hardware not started and no active users.
976 : : * Release all owner ports from the existing shared rxq_ctrl.
977 : : * This will decrement references and eventually free the old rxq_ctrl.
978 : : * Setting rxq_ctrl to NULL triggers creation of a new one below with
979 : : * the updated configuration.
980 : : */
981 : : do {
982 : 0 : rxq_tmp = LIST_FIRST(&rxq_ctrl->owners);
983 [ # # ]: 0 : LIST_REMOVE(rxq_tmp, owner_entry);
984 : 0 : empty = LIST_EMPTY(&rxq_ctrl->owners);
985 : 0 : mlx5_rxq_release(ETH_DEV(rxq_tmp->priv), rxq_tmp->idx);
986 [ # # ]: 0 : } while (!empty);
987 : :
988 : 0 : rxq_ctrl = NULL;
989 : : }
990 : : } else {
991 : 0 : res = mlx5_rx_queue_pre_setup(dev, idx, &desc, &rxq_ctrl);
992 [ # # ]: 0 : if (res)
993 : : return res;
994 : : }
995 : : /* Allocate RXQ. */
996 : 0 : rxq = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, sizeof(*rxq), 0,
997 : : SOCKET_ID_ANY);
998 [ # # ]: 0 : if (!rxq) {
999 : 0 : DRV_LOG(ERR, "port %u unable to allocate rx queue index %u private data",
1000 : : dev->data->port_id, idx);
1001 : 0 : rte_errno = ENOMEM;
1002 : 0 : return -rte_errno;
1003 : : }
1004 [ # # ]: 0 : if (rxq_ctrl == NULL) {
1005 : 0 : rxq_ctrl = mlx5_rxq_new(dev, idx, desc, socket, conf, rx_seg,
1006 : : n_seg, is_extmem);
1007 [ # # ]: 0 : if (rxq_ctrl == NULL) {
1008 : 0 : DRV_LOG(ERR, "port %u unable to allocate rx queue index %u",
1009 : : dev->data->port_id, idx);
1010 : 0 : mlx5_free(rxq);
1011 : 0 : rte_errno = ENOMEM;
1012 : 0 : return -rte_errno;
1013 : : }
1014 : : }
1015 : 0 : rxq->priv = priv;
1016 : 0 : rxq->idx = idx;
1017 : 0 : (*priv->rxq_privs)[idx] = rxq;
1018 : : /* Join owner list. */
1019 [ # # ]: 0 : LIST_INSERT_HEAD(&rxq_ctrl->owners, rxq, owner_entry);
1020 : 0 : rxq->ctrl = rxq_ctrl;
1021 : 0 : rte_atomic_fetch_add_explicit(&rxq_ctrl->ctrl_ref, 1, rte_memory_order_relaxed);
1022 : 0 : mlx5_rxq_ref(dev, idx);
1023 : 0 : DRV_LOG(DEBUG, "port %u adding Rx queue %u to list",
1024 : : dev->data->port_id, idx);
1025 : 0 : dev->data->rx_queues[idx] = &rxq_ctrl->rxq;
1026 : 0 : return 0;
1027 : : }
1028 : :
1029 : : /**
1030 : : *
1031 : : * @param dev
1032 : : * Pointer to Ethernet device structure.
1033 : : * @param idx
1034 : : * RX queue index.
1035 : : * @param desc
1036 : : * Number of descriptors to configure in queue.
1037 : : * @param hairpin_conf
1038 : : * Hairpin configuration parameters.
1039 : : *
1040 : : * @return
1041 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1042 : : */
1043 : : int
1044 : 0 : mlx5_rx_hairpin_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
1045 : : uint16_t desc,
1046 : : const struct rte_eth_hairpin_conf *hairpin_conf)
1047 : : {
1048 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1049 : : struct mlx5_rxq_priv *rxq;
1050 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1051 : : int res;
1052 : :
1053 : 0 : res = mlx5_rx_queue_pre_setup(dev, idx, &desc, NULL);
1054 [ # # ]: 0 : if (res)
1055 : : return res;
1056 [ # # ]: 0 : if (hairpin_conf->peer_count != 1) {
1057 : 0 : rte_errno = EINVAL;
1058 : 0 : DRV_LOG(ERR, "port %u unable to setup Rx hairpin queue index %u"
1059 : : " peer count is %u", dev->data->port_id,
1060 : : idx, hairpin_conf->peer_count);
1061 : 0 : return -rte_errno;
1062 : : }
1063 [ # # ]: 0 : if (hairpin_conf->peers[0].port == dev->data->port_id) {
1064 [ # # ]: 0 : if (hairpin_conf->peers[0].queue >= priv->txqs_n) {
1065 : 0 : rte_errno = EINVAL;
1066 : 0 : DRV_LOG(ERR, "port %u unable to setup Rx hairpin queue"
1067 : : " index %u, Tx %u is larger than %u",
1068 : : dev->data->port_id, idx,
1069 : : hairpin_conf->peers[0].queue, priv->txqs_n);
1070 : 0 : return -rte_errno;
1071 : : }
1072 : : } else {
1073 [ # # ]: 0 : if (hairpin_conf->manual_bind == 0 ||
1074 : : hairpin_conf->tx_explicit == 0) {
1075 : 0 : rte_errno = EINVAL;
1076 : 0 : DRV_LOG(ERR, "port %u unable to setup Rx hairpin queue"
1077 : : " index %u peer port %u with attributes %u %u",
1078 : : dev->data->port_id, idx,
1079 : : hairpin_conf->peers[0].port,
1080 : : hairpin_conf->manual_bind,
1081 : : hairpin_conf->tx_explicit);
1082 : 0 : return -rte_errno;
1083 : : }
1084 : : }
1085 : 0 : rxq = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, sizeof(*rxq), 0,
1086 : : SOCKET_ID_ANY);
1087 [ # # ]: 0 : if (!rxq) {
1088 : 0 : DRV_LOG(ERR, "port %u unable to allocate hairpin rx queue index %u private data",
1089 : : dev->data->port_id, idx);
1090 : 0 : rte_errno = ENOMEM;
1091 : 0 : return -rte_errno;
1092 : : }
1093 : 0 : rxq->priv = priv;
1094 : 0 : rxq->idx = idx;
1095 : 0 : (*priv->rxq_privs)[idx] = rxq;
1096 : 0 : rxq_ctrl = mlx5_rxq_hairpin_new(dev, rxq, desc, hairpin_conf);
1097 [ # # ]: 0 : if (!rxq_ctrl) {
1098 : 0 : DRV_LOG(ERR, "port %u unable to allocate hairpin queue index %u",
1099 : : dev->data->port_id, idx);
1100 : 0 : mlx5_free(rxq);
1101 : 0 : (*priv->rxq_privs)[idx] = NULL;
1102 : 0 : rte_errno = ENOMEM;
1103 : 0 : return -rte_errno;
1104 : : }
1105 : 0 : rte_atomic_fetch_add_explicit(&rxq_ctrl->ctrl_ref, 1, rte_memory_order_relaxed);
1106 : 0 : DRV_LOG(DEBUG, "port %u adding hairpin Rx queue %u to list",
1107 : : dev->data->port_id, idx);
1108 : 0 : dev->data->rx_queues[idx] = &rxq_ctrl->rxq;
1109 : 0 : return 0;
1110 : : }
1111 : :
1112 : : /**
1113 : : * DPDK callback to release a RX queue.
1114 : : *
1115 : : * @param dev
1116 : : * Pointer to Ethernet device structure.
1117 : : * @param qid
1118 : : * Receive queue index.
1119 : : */
1120 : : void
1121 : 0 : mlx5_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1122 : : {
1123 : 0 : struct mlx5_rxq_data *rxq = dev->data->rx_queues[qid];
1124 : :
1125 [ # # ]: 0 : if (rxq == NULL)
1126 : : return;
1127 [ # # ]: 0 : if (!mlx5_rxq_releasable(dev, qid))
1128 : 0 : rte_panic("port %u Rx queue %u is still used by a flow and"
1129 : : " cannot be removed\n", dev->data->port_id, qid);
1130 : 0 : mlx5_rxq_release(dev, qid);
1131 : : }
1132 : :
1133 : : /**
1134 : : * Allocate queue vector and fill epoll fd list for Rx interrupts.
1135 : : *
1136 : : * @param dev
1137 : : * Pointer to Ethernet device.
1138 : : *
1139 : : * @return
1140 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1141 : : */
1142 : : int
1143 : 0 : mlx5_rx_intr_vec_enable(struct rte_eth_dev *dev)
1144 : : {
1145 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1146 : : unsigned int i;
1147 : 0 : unsigned int rxqs_n = priv->rxqs_n;
1148 : 0 : unsigned int n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
1149 : : unsigned int count = 0;
1150 : 0 : struct rte_intr_handle *intr_handle = dev->intr_handle;
1151 : :
1152 [ # # ]: 0 : if (!dev->data->dev_conf.intr_conf.rxq)
1153 : : return 0;
1154 : 0 : mlx5_rx_intr_vec_disable(dev);
1155 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, NULL, n)) {
1156 : 0 : DRV_LOG(ERR,
1157 : : "port %u failed to allocate memory for interrupt"
1158 : : " vector, Rx interrupts will not be supported",
1159 : : dev->data->port_id);
1160 : 0 : rte_errno = ENOMEM;
1161 : 0 : return -rte_errno;
1162 : : }
1163 : :
1164 [ # # ]: 0 : if (rte_intr_type_set(intr_handle, RTE_INTR_HANDLE_EXT))
1165 : 0 : return -rte_errno;
1166 : :
1167 [ # # ]: 0 : for (i = 0; i != n; ++i) {
1168 : : /* This rxq obj must not be released in this function. */
1169 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1170 [ # # ]: 0 : struct mlx5_rxq_obj *rxq_obj = rxq ? rxq->ctrl->obj : NULL;
1171 : : int rc;
1172 : :
1173 : : /* Skip queues that cannot request interrupts. */
1174 [ # # # # ]: 0 : if (!rxq_obj || (!rxq_obj->ibv_channel &&
1175 [ # # ]: 0 : !rxq_obj->devx_channel)) {
1176 : : /* Use invalid intr_vec[] index to disable entry. */
1177 [ # # ]: 0 : if (rte_intr_vec_list_index_set(intr_handle, i,
1178 : : RTE_INTR_VEC_RXTX_OFFSET + RTE_MAX_RXTX_INTR_VEC_ID))
1179 : 0 : return -rte_errno;
1180 : 0 : continue;
1181 : : }
1182 : 0 : mlx5_rxq_ref(dev, i);
1183 [ # # ]: 0 : if (count >= RTE_MAX_RXTX_INTR_VEC_ID) {
1184 : 0 : DRV_LOG(ERR,
1185 : : "port %u too many Rx queues for interrupt"
1186 : : " vector size (%d), Rx interrupts cannot be"
1187 : : " enabled",
1188 : : dev->data->port_id, RTE_MAX_RXTX_INTR_VEC_ID);
1189 : 0 : mlx5_rx_intr_vec_disable(dev);
1190 : 0 : rte_errno = ENOMEM;
1191 : 0 : return -rte_errno;
1192 : : }
1193 : 0 : rc = mlx5_os_set_nonblock_channel_fd(rxq_obj->fd);
1194 [ # # ]: 0 : if (rc < 0) {
1195 : 0 : rte_errno = errno;
1196 : 0 : DRV_LOG(ERR,
1197 : : "port %u failed to make Rx interrupt file"
1198 : : " descriptor %d non-blocking for queue index"
1199 : : " %d",
1200 : : dev->data->port_id, rxq_obj->fd, i);
1201 : 0 : mlx5_rx_intr_vec_disable(dev);
1202 : 0 : return -rte_errno;
1203 : : }
1204 : :
1205 [ # # ]: 0 : if (rte_intr_vec_list_index_set(intr_handle, i,
1206 : 0 : RTE_INTR_VEC_RXTX_OFFSET + count))
1207 : 0 : return -rte_errno;
1208 [ # # ]: 0 : if (rte_intr_efds_index_set(intr_handle, count,
1209 : : rxq_obj->fd))
1210 : 0 : return -rte_errno;
1211 : : count++;
1212 : : }
1213 [ # # ]: 0 : if (!count)
1214 : 0 : mlx5_rx_intr_vec_disable(dev);
1215 [ # # ]: 0 : else if (rte_intr_nb_efd_set(intr_handle, count))
1216 : 0 : return -rte_errno;
1217 : : return 0;
1218 : : }
1219 : :
1220 : : /**
1221 : : * Clean up Rx interrupts handler.
1222 : : *
1223 : : * @param dev
1224 : : * Pointer to Ethernet device.
1225 : : */
1226 : : void
1227 : 0 : mlx5_rx_intr_vec_disable(struct rte_eth_dev *dev)
1228 : : {
1229 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1230 : 0 : struct rte_intr_handle *intr_handle = dev->intr_handle;
1231 : : unsigned int i;
1232 : 0 : unsigned int rxqs_n = priv->rxqs_n;
1233 : 0 : unsigned int n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
1234 : :
1235 [ # # ]: 0 : if (!dev->data->dev_conf.intr_conf.rxq)
1236 : : return;
1237 [ # # ]: 0 : if (rte_intr_vec_list_index_get(intr_handle, 0) < 0)
1238 : 0 : goto free;
1239 [ # # ]: 0 : for (i = 0; i != n; ++i) {
1240 [ # # ]: 0 : if (rte_intr_vec_list_index_get(intr_handle, i) ==
1241 : : RTE_INTR_VEC_RXTX_OFFSET + RTE_MAX_RXTX_INTR_VEC_ID)
1242 : 0 : continue;
1243 : : /**
1244 : : * Need to access directly the queue to release the reference
1245 : : * kept in mlx5_rx_intr_vec_enable().
1246 : : */
1247 : 0 : mlx5_rxq_deref(dev, i);
1248 : : }
1249 : 0 : free:
1250 : 0 : rte_intr_free_epoll_fd(intr_handle);
1251 : :
1252 : 0 : rte_intr_vec_list_free(intr_handle);
1253 : :
1254 : 0 : rte_intr_nb_efd_set(intr_handle, 0);
1255 : : }
1256 : :
1257 : : /**
1258 : : * MLX5 CQ notification .
1259 : : *
1260 : : * @param rxq
1261 : : * Pointer to receive queue structure.
1262 : : * @param sq_n_rxq
1263 : : * Sequence number per receive queue .
1264 : : */
1265 : : static inline void
1266 : 0 : mlx5_arm_cq(struct mlx5_rxq_data *rxq, int sq_n_rxq)
1267 : : {
1268 : : int sq_n = 0;
1269 : : uint32_t doorbell_hi;
1270 : : uint64_t doorbell;
1271 : :
1272 : : sq_n = sq_n_rxq & MLX5_CQ_SQN_MASK;
1273 : 0 : doorbell_hi = sq_n << MLX5_CQ_SQN_OFFSET | (rxq->cq_ci & MLX5_CI_MASK);
1274 : 0 : doorbell = (uint64_t)doorbell_hi << 32;
1275 : 0 : doorbell |= rxq->cqn;
1276 : 0 : mlx5_doorbell_ring(&rxq->uar_data, rte_cpu_to_be_64(doorbell),
1277 [ # # ]: 0 : doorbell_hi, &rxq->cq_db[MLX5_CQ_ARM_DB], 0);
1278 : 0 : }
1279 : :
1280 : : /**
1281 : : * DPDK callback for Rx queue interrupt enable.
1282 : : *
1283 : : * @param dev
1284 : : * Pointer to Ethernet device structure.
1285 : : * @param rx_queue_id
1286 : : * Rx queue number.
1287 : : *
1288 : : * @return
1289 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1290 : : */
1291 : : int
1292 : 0 : mlx5_rx_intr_enable(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1293 : : {
1294 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, rx_queue_id);
1295 [ # # ]: 0 : if (!rxq)
1296 : 0 : goto error;
1297 [ # # ]: 0 : if (rxq->ctrl->irq) {
1298 [ # # ]: 0 : if (!rxq->ctrl->obj)
1299 : 0 : goto error;
1300 : 0 : mlx5_arm_cq(&rxq->ctrl->rxq, rxq->ctrl->rxq.cq_arm_sn);
1301 : : }
1302 : : return 0;
1303 : 0 : error:
1304 : 0 : rte_errno = EINVAL;
1305 : 0 : return -rte_errno;
1306 : : }
1307 : :
1308 : : /**
1309 : : * DPDK callback for Rx queue interrupt disable.
1310 : : *
1311 : : * @param dev
1312 : : * Pointer to Ethernet device structure.
1313 : : * @param rx_queue_id
1314 : : * Rx queue number.
1315 : : *
1316 : : * @return
1317 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1318 : : */
1319 : : int
1320 : 0 : mlx5_rx_intr_disable(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1321 : : {
1322 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1323 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, rx_queue_id);
1324 : : int ret = 0;
1325 : :
1326 [ # # ]: 0 : if (!rxq) {
1327 : 0 : rte_errno = EINVAL;
1328 : 0 : return -rte_errno;
1329 : : }
1330 [ # # ]: 0 : if (!rxq->ctrl->obj)
1331 : 0 : goto error;
1332 [ # # ]: 0 : if (rxq->ctrl->irq) {
1333 : 0 : ret = priv->obj_ops.rxq_event_get(rxq->ctrl->obj);
1334 [ # # ]: 0 : if (ret < 0)
1335 : 0 : goto error;
1336 : 0 : rxq->ctrl->rxq.cq_arm_sn++;
1337 : : }
1338 : : return 0;
1339 : : error:
1340 : : /**
1341 : : * The ret variable may be EAGAIN which means the get_event function was
1342 : : * called before receiving one.
1343 : : */
1344 : : if (ret < 0)
1345 : 0 : rte_errno = errno;
1346 : : else
1347 : 0 : rte_errno = EINVAL;
1348 [ # # ]: 0 : if (rte_errno != EAGAIN)
1349 : 0 : DRV_LOG(WARNING, "port %u unable to disable interrupt on Rx queue %d",
1350 : : dev->data->port_id, rx_queue_id);
1351 : 0 : return -rte_errno;
1352 : : }
1353 : :
1354 : : /**
1355 : : * Verify the Rx queue objects list is empty
1356 : : *
1357 : : * @param dev
1358 : : * Pointer to Ethernet device.
1359 : : *
1360 : : * @return
1361 : : * The number of objects not released.
1362 : : */
1363 : : int
1364 : 0 : mlx5_rxq_obj_verify(struct rte_eth_dev *dev)
1365 : : {
1366 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1367 : : int ret = 0;
1368 : : struct mlx5_rxq_obj *rxq_obj;
1369 : :
1370 [ # # ]: 0 : LIST_FOREACH(rxq_obj, &priv->rxqsobj, next) {
1371 [ # # ]: 0 : if (rxq_obj->rxq_ctrl == NULL)
1372 : 0 : continue;
1373 [ # # ]: 0 : if (rxq_obj->rxq_ctrl->rxq.shared &&
1374 [ # # ]: 0 : !LIST_EMPTY(&rxq_obj->rxq_ctrl->owners))
1375 : 0 : continue;
1376 : 0 : DRV_LOG(DEBUG, "port %u Rx queue %u still referenced",
1377 : : dev->data->port_id, rxq_obj->rxq_ctrl->rxq.idx);
1378 : 0 : ++ret;
1379 : : }
1380 : 0 : return ret;
1381 : : }
1382 : :
1383 : : /**
1384 : : * Destroy all queue counters.
1385 : : *
1386 : : * @param dev
1387 : : * Pointer to Ethernet device.
1388 : : */
1389 : : void
1390 : 0 : mlx5_q_counters_destroy(struct rte_eth_dev *dev)
1391 : : {
1392 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1393 : : unsigned int i;
1394 : :
1395 : : /* Destroy port q counter */
1396 [ # # ]: 0 : if (priv->q_counters) {
1397 : 0 : mlx5_devx_cmd_destroy(priv->q_counters);
1398 : 0 : priv->q_counters = NULL;
1399 : : }
1400 : :
1401 : : /* Destroy port global hairpin q counter */
1402 [ # # ]: 0 : if (priv->q_counter_hairpin) {
1403 : 0 : mlx5_devx_cmd_destroy(priv->q_counter_hairpin);
1404 : 0 : priv->q_counter_hairpin = NULL;
1405 : : }
1406 : :
1407 : : /* Destroy per hairpin queue counter */
1408 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1409 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1410 : :
1411 [ # # # # ]: 0 : if (rxq == NULL || rxq->q_counter == NULL)
1412 : 0 : continue;
1413 : :
1414 : 0 : mlx5_devx_cmd_destroy(rxq->q_counter);
1415 : 0 : rxq->q_counter = NULL;
1416 : : }
1417 : 0 : }
1418 : :
1419 : : /**
1420 : : * Callback function to initialize mbufs for Multi-Packet RQ.
1421 : : */
1422 : : static inline void
1423 : 0 : mlx5_mprq_buf_init(struct rte_mempool *mp, void *opaque_arg,
1424 : : void *_m, unsigned int i __rte_unused)
1425 : : {
1426 : : struct mlx5_mprq_buf *buf = _m;
1427 : : struct rte_mbuf_ext_shared_info *shinfo;
1428 : 0 : unsigned int strd_n = (unsigned int)(uintptr_t)opaque_arg;
1429 : : unsigned int j;
1430 : :
1431 : : memset(_m, 0, sizeof(*buf));
1432 : 0 : buf->mp = mp;
1433 : 0 : rte_atomic_store_explicit(&buf->refcnt, 1, rte_memory_order_relaxed);
1434 [ # # ]: 0 : for (j = 0; j != strd_n; ++j) {
1435 : : shinfo = &buf->shinfos[j];
1436 : 0 : shinfo->free_cb = mlx5_mprq_buf_free_cb;
1437 : 0 : shinfo->fcb_opaque = buf;
1438 : : }
1439 : 0 : }
1440 : :
1441 : : /**
1442 : : * Free mempool of Multi-Packet RQ.
1443 : : *
1444 : : * @param dev
1445 : : * Pointer to Ethernet device.
1446 : : *
1447 : : * @return
1448 : : * 0 on success, negative errno value on failure.
1449 : : */
1450 : : int
1451 : 0 : mlx5_mprq_free_mp(struct rte_eth_dev *dev)
1452 : : {
1453 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1454 : 0 : struct rte_mempool *mp = priv->mprq_mp;
1455 : : unsigned int i;
1456 : :
1457 [ # # ]: 0 : if (mp == NULL)
1458 : : return 0;
1459 : 0 : DRV_LOG(DEBUG, "port %u freeing mempool (%s) for Multi-Packet RQ",
1460 : : dev->data->port_id, mp->name);
1461 : : /*
1462 : : * If a buffer in the pool has been externally attached to a mbuf and it
1463 : : * is still in use by application, destroying the Rx queue can spoil
1464 : : * the packet. It is unlikely to happen but if application dynamically
1465 : : * creates and destroys with holding Rx packets, this can happen.
1466 : : *
1467 : : * TODO: It is unavoidable for now because the mempool for Multi-Packet
1468 : : * RQ isn't provided by application but managed by PMD.
1469 : : */
1470 [ # # ]: 0 : if (!rte_mempool_full(mp)) {
1471 : 0 : DRV_LOG(ERR,
1472 : : "port %u mempool for Multi-Packet RQ is still in use",
1473 : : dev->data->port_id);
1474 : 0 : rte_errno = EBUSY;
1475 : 0 : return -rte_errno;
1476 : : }
1477 : 0 : rte_mempool_free(mp);
1478 : : /* Unset mempool for each Rx queue. */
1479 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1480 : 0 : struct mlx5_rxq_data *rxq = mlx5_rxq_data_get(dev, i);
1481 : :
1482 [ # # ]: 0 : if (rxq == NULL)
1483 : 0 : continue;
1484 : 0 : rxq->mprq_mp = NULL;
1485 : : }
1486 : 0 : priv->mprq_mp = NULL;
1487 : 0 : return 0;
1488 : : }
1489 : :
1490 : : /**
1491 : : * Allocate a mempool for Multi-Packet RQ. All configured Rx queues share the
1492 : : * mempool. If already allocated, reuse it if there're enough elements.
1493 : : * Otherwise, resize it.
1494 : : *
1495 : : * @param dev
1496 : : * Pointer to Ethernet device.
1497 : : *
1498 : : * @return
1499 : : * 0 on success, negative errno value on failure.
1500 : : */
1501 : : int
1502 : 0 : mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)
1503 : : {
1504 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1505 [ # # ]: 0 : struct rte_mempool *mp = priv->mprq_mp;
1506 : : char name[RTE_MEMPOOL_NAMESIZE];
1507 : : unsigned int desc = 0;
1508 : : unsigned int buf_len;
1509 : : unsigned int obj_num;
1510 : : unsigned int obj_size;
1511 : : unsigned int log_strd_num = 0;
1512 : : unsigned int log_strd_sz = 0;
1513 : : unsigned int i;
1514 : : unsigned int n_ibv = 0;
1515 : : int ret;
1516 : :
1517 [ # # ]: 0 : if (!mlx5_mprq_enabled(dev))
1518 : 0 : return 0;
1519 : : /* Count the total number of descriptors configured. */
1520 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1521 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
1522 : : struct mlx5_rxq_data *rxq;
1523 : :
1524 [ # # # # ]: 0 : if (rxq_ctrl == NULL || rxq_ctrl->is_hairpin)
1525 : 0 : continue;
1526 : : rxq = &rxq_ctrl->rxq;
1527 : 0 : n_ibv++;
1528 : 0 : desc += 1 << rxq->elts_n;
1529 : : /* Get the max number of strides. */
1530 : 0 : if (log_strd_num < rxq->log_strd_num)
1531 : : log_strd_num = rxq->log_strd_num;
1532 : : /* Get the max size of a stride. */
1533 : 0 : if (log_strd_sz < rxq->log_strd_sz)
1534 : : log_strd_sz = rxq->log_strd_sz;
1535 : : }
1536 : : MLX5_ASSERT(log_strd_num && log_strd_sz);
1537 : 0 : buf_len = RTE_BIT32(log_strd_num) * RTE_BIT32(log_strd_sz);
1538 : 0 : obj_size = sizeof(struct mlx5_mprq_buf) + buf_len +
1539 : 0 : (size_t)RTE_BIT32(log_strd_num) *
1540 : : sizeof(struct rte_mbuf_ext_shared_info) +
1541 : : RTE_PKTMBUF_HEADROOM;
1542 : : /*
1543 : : * Received packets can be either memcpy'd or externally referenced. In
1544 : : * case that the packet is attached to an mbuf as an external buffer, as
1545 : : * it isn't possible to predict how the buffers will be queued by
1546 : : * application, there's no option to exactly pre-allocate needed buffers
1547 : : * in advance but to speculatively prepares enough buffers.
1548 : : *
1549 : : * In the data path, if this Mempool is depleted, PMD will try to memcpy
1550 : : * received packets to buffers provided by application (rxq->mp) until
1551 : : * this Mempool gets available again.
1552 : : */
1553 : 0 : desc *= 4;
1554 : 0 : obj_num = desc + MLX5_MPRQ_MP_CACHE_SZ * n_ibv;
1555 : : /*
1556 : : * rte_mempool_create_empty() has sanity check to refuse large cache
1557 : : * size compared to the number of elements.
1558 : : * CALC_CACHE_FLUSHTHRESH() is defined in a C file, so using a
1559 : : * constant number 2 instead.
1560 : : */
1561 : 0 : obj_num = RTE_MAX(obj_num, MLX5_MPRQ_MP_CACHE_SZ * 2);
1562 : : /* Check a mempool is already allocated and if it can be resued. */
1563 [ # # # # : 0 : if (mp != NULL && mp->elt_size >= obj_size && mp->size >= obj_num) {
# # ]
1564 : 0 : DRV_LOG(DEBUG, "port %u mempool %s is being reused",
1565 : : dev->data->port_id, mp->name);
1566 : : /* Reuse. */
1567 : 0 : goto exit;
1568 [ # # ]: 0 : } else if (mp != NULL) {
1569 : 0 : DRV_LOG(DEBUG, "port %u mempool %s should be resized, freeing it",
1570 : : dev->data->port_id, mp->name);
1571 : : /*
1572 : : * If failed to free, which means it may be still in use, no way
1573 : : * but to keep using the existing one. On buffer underrun,
1574 : : * packets will be memcpy'd instead of external buffer
1575 : : * attachment.
1576 : : */
1577 [ # # ]: 0 : if (mlx5_mprq_free_mp(dev)) {
1578 [ # # ]: 0 : if (mp->elt_size >= obj_size)
1579 : 0 : goto exit;
1580 : : else
1581 : 0 : return -rte_errno;
1582 : : }
1583 : : }
1584 : 0 : snprintf(name, sizeof(name), "port-%u-mprq", dev->data->port_id);
1585 : 0 : mp = rte_mempool_create(name, obj_num, obj_size, MLX5_MPRQ_MP_CACHE_SZ,
1586 : : 0, NULL, NULL, mlx5_mprq_buf_init,
1587 : 0 : (void *)((uintptr_t)1 << log_strd_num),
1588 : 0 : dev->device->numa_node, 0);
1589 [ # # ]: 0 : if (mp == NULL) {
1590 : 0 : DRV_LOG(ERR,
1591 : : "port %u failed to allocate a mempool for"
1592 : : " Multi-Packet RQ, count=%u, size=%u",
1593 : : dev->data->port_id, obj_num, obj_size);
1594 : 0 : rte_errno = ENOMEM;
1595 : 0 : return -rte_errno;
1596 : : }
1597 : 0 : ret = mlx5_mr_mempool_register(priv->sh->cdev, mp, false);
1598 [ # # # # ]: 0 : if (ret < 0 && rte_errno != EEXIST) {
1599 : : ret = rte_errno;
1600 : 0 : DRV_LOG(ERR, "port %u failed to register a mempool for Multi-Packet RQ",
1601 : : dev->data->port_id);
1602 : 0 : rte_mempool_free(mp);
1603 : 0 : rte_errno = ret;
1604 : 0 : return -rte_errno;
1605 : : }
1606 : 0 : priv->mprq_mp = mp;
1607 : 0 : exit:
1608 : : /* Set mempool for each Rx queue. */
1609 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1610 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
1611 : :
1612 [ # # # # ]: 0 : if (rxq_ctrl == NULL || rxq_ctrl->is_hairpin)
1613 : 0 : continue;
1614 : 0 : rxq_ctrl->rxq.mprq_mp = mp;
1615 : : }
1616 : 0 : DRV_LOG(INFO, "port %u Multi-Packet RQ is configured",
1617 : : dev->data->port_id);
1618 : 0 : return 0;
1619 : : }
1620 : :
1621 : : #define MLX5_MAX_TCP_HDR_OFFSET ((unsigned int)(sizeof(struct rte_ether_hdr) + \
1622 : : sizeof(struct rte_vlan_hdr) * 2 + \
1623 : : sizeof(struct rte_ipv6_hdr)))
1624 : : #define MAX_TCP_OPTION_SIZE 40u
1625 : : #define MLX5_MAX_LRO_HEADER_FIX ((unsigned int)(MLX5_MAX_TCP_HDR_OFFSET + \
1626 : : sizeof(struct rte_tcp_hdr) + \
1627 : : MAX_TCP_OPTION_SIZE))
1628 : :
1629 : : /**
1630 : : * Adjust the maximum LRO massage size.
1631 : : *
1632 : : * @param dev
1633 : : * Pointer to Ethernet device.
1634 : : * @param idx
1635 : : * RX queue index.
1636 : : * @param max_lro_size
1637 : : * The maximum size for LRO packet.
1638 : : */
1639 : : static void
1640 : 0 : mlx5_max_lro_msg_size_adjust(struct rte_eth_dev *dev, uint16_t idx,
1641 : : uint32_t max_lro_size)
1642 : : {
1643 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1644 : :
1645 [ # # ]: 0 : if (priv->sh->cdev->config.hca_attr.lro_max_msg_sz_mode ==
1646 [ # # ]: 0 : MLX5_LRO_MAX_MSG_SIZE_START_FROM_L4 && max_lro_size >
1647 : : MLX5_MAX_TCP_HDR_OFFSET)
1648 : 0 : max_lro_size -= MLX5_MAX_TCP_HDR_OFFSET;
1649 : 0 : max_lro_size = RTE_MIN(max_lro_size, MLX5_MAX_LRO_SIZE);
1650 [ # # ]: 0 : if (priv->max_lro_msg_size)
1651 : 0 : priv->max_lro_msg_size =
1652 : 0 : RTE_MIN((uint32_t)priv->max_lro_msg_size, max_lro_size);
1653 : : else
1654 : 0 : priv->max_lro_msg_size = max_lro_size;
1655 : 0 : DRV_LOG(DEBUG,
1656 : : "port %u Rx Queue %u max LRO message size adjusted to %u bytes",
1657 : : dev->data->port_id, idx, priv->max_lro_msg_size);
1658 : 0 : }
1659 : :
1660 : : /**
1661 : : * Prepare both size and number of stride for Multi-Packet RQ.
1662 : : *
1663 : : * @param dev
1664 : : * Pointer to Ethernet device.
1665 : : * @param idx
1666 : : * RX queue index.
1667 : : * @param desc
1668 : : * Number of descriptors to configure in queue.
1669 : : * @param rx_seg_en
1670 : : * Indicator if Rx segment enables, if so Multi-Packet RQ doesn't enable.
1671 : : * @param min_mbuf_size
1672 : : * Non scatter min mbuf size, max_rx_pktlen plus overhead.
1673 : : * @param actual_log_stride_num
1674 : : * Log number of strides to configure for this queue.
1675 : : * @param actual_log_stride_size
1676 : : * Log stride size to configure for this queue.
1677 : : * @param is_extmem
1678 : : * Is external pinned memory pool used.
1679 : : * @return
1680 : : * 0 if Multi-Packet RQ is supported, otherwise -1.
1681 : : */
1682 : : static int
1683 : 0 : mlx5_mprq_prepare(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1684 : : bool rx_seg_en, uint32_t min_mbuf_size,
1685 : : uint32_t *actual_log_stride_num,
1686 : : uint32_t *actual_log_stride_size,
1687 : : bool is_extmem)
1688 : : {
1689 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1690 : : struct mlx5_port_config *config = &priv->config;
1691 : 0 : struct mlx5_dev_cap *dev_cap = &priv->sh->dev_cap;
1692 : 0 : uint32_t log_min_stride_num = dev_cap->mprq.log_min_stride_num;
1693 : 0 : uint32_t log_max_stride_num = dev_cap->mprq.log_max_stride_num;
1694 : : uint32_t log_def_stride_num =
1695 : 0 : RTE_MIN(RTE_MAX(MLX5_MPRQ_DEFAULT_LOG_STRIDE_NUM,
1696 : : log_min_stride_num),
1697 : : log_max_stride_num);
1698 : 0 : uint32_t log_min_stride_size = dev_cap->mprq.log_min_stride_size;
1699 : 0 : uint32_t log_max_stride_size = dev_cap->mprq.log_max_stride_size;
1700 : : uint32_t log_def_stride_size =
1701 [ # # ]: 0 : RTE_MIN(RTE_MAX(MLX5_MPRQ_DEFAULT_LOG_STRIDE_SIZE,
1702 : : log_min_stride_size),
1703 : : log_max_stride_size);
1704 : : uint32_t log_stride_wqe_size;
1705 : :
1706 [ # # ]: 0 : if (mlx5_check_mprq_support(dev) != 1 || rx_seg_en || is_extmem)
1707 : 0 : goto unsupport;
1708 : : /* Checks if chosen number of strides is in supported range. */
1709 [ # # # # ]: 0 : if (config->mprq.log_stride_num > log_max_stride_num ||
1710 : : config->mprq.log_stride_num < log_min_stride_num) {
1711 : 0 : *actual_log_stride_num = log_def_stride_num;
1712 : 0 : DRV_LOG(WARNING,
1713 : : "Port %u Rx queue %u number of strides for Multi-Packet RQ is out of range, setting default value (%u)",
1714 : : dev->data->port_id, idx, RTE_BIT32(log_def_stride_num));
1715 : : } else {
1716 : 0 : *actual_log_stride_num = config->mprq.log_stride_num;
1717 : : }
1718 : : /* Checks if chosen size of stride is in supported range. */
1719 [ # # ]: 0 : if (config->mprq.log_stride_size != (uint32_t)MLX5_ARG_UNSET) {
1720 [ # # # # ]: 0 : if (config->mprq.log_stride_size > log_max_stride_size ||
1721 : : config->mprq.log_stride_size < log_min_stride_size) {
1722 : 0 : *actual_log_stride_size = log_def_stride_size;
1723 : 0 : DRV_LOG(WARNING,
1724 : : "Port %u Rx queue %u size of a stride for Multi-Packet RQ is out of range, setting default value (%u)",
1725 : : dev->data->port_id, idx,
1726 : : RTE_BIT32(log_def_stride_size));
1727 : : } else {
1728 : 0 : *actual_log_stride_size = config->mprq.log_stride_size;
1729 : : }
1730 : : } else {
1731 : : /* Make the stride fit the mbuf size by default. */
1732 [ # # ]: 0 : if (min_mbuf_size <= RTE_BIT32(log_max_stride_size)) {
1733 : 0 : DRV_LOG(WARNING,
1734 : : "Port %u Rx queue %u size of a stride for Multi-Packet RQ is adjusted to match the mbuf size (%u)",
1735 : : dev->data->port_id, idx, min_mbuf_size);
1736 : 0 : *actual_log_stride_size = log2above(min_mbuf_size);
1737 : : } else {
1738 : 0 : goto unsupport;
1739 : : }
1740 : : }
1741 : : /* Make sure the stride size is greater than the headroom. */
1742 [ # # ]: 0 : if (RTE_BIT32(*actual_log_stride_size) < RTE_PKTMBUF_HEADROOM) {
1743 [ # # ]: 0 : if (RTE_BIT32(log_max_stride_size) > RTE_PKTMBUF_HEADROOM) {
1744 : 0 : DRV_LOG(WARNING,
1745 : : "Port %u Rx queue %u size of a stride for Multi-Packet RQ is adjusted to accommodate the headroom (%u)",
1746 : : dev->data->port_id, idx, RTE_PKTMBUF_HEADROOM);
1747 : 0 : *actual_log_stride_size = log2above(RTE_PKTMBUF_HEADROOM);
1748 : : } else {
1749 : 0 : goto unsupport;
1750 : : }
1751 : : }
1752 : 0 : log_stride_wqe_size = *actual_log_stride_num + *actual_log_stride_size;
1753 : : /* Check if WQE buffer size is supported by hardware. */
1754 [ # # ]: 0 : if (log_stride_wqe_size < dev_cap->mprq.log_min_stride_wqe_size) {
1755 : 0 : *actual_log_stride_num = log_def_stride_num;
1756 : 0 : *actual_log_stride_size = log_def_stride_size;
1757 : 0 : DRV_LOG(WARNING,
1758 : : "Port %u Rx queue %u size of WQE buffer for Multi-Packet RQ is too small, setting default values (stride_num_n=%u, stride_size_n=%u)",
1759 : : dev->data->port_id, idx, RTE_BIT32(log_def_stride_num),
1760 : : RTE_BIT32(log_def_stride_size));
1761 : 0 : log_stride_wqe_size = log_def_stride_num + log_def_stride_size;
1762 : : }
1763 : : MLX5_ASSERT(log_stride_wqe_size >=
1764 : : dev_cap->mprq.log_min_stride_wqe_size);
1765 [ # # ]: 0 : if (desc <= RTE_BIT32(*actual_log_stride_num))
1766 : 0 : goto unsupport;
1767 [ # # ]: 0 : if (min_mbuf_size > RTE_BIT32(log_stride_wqe_size)) {
1768 : 0 : DRV_LOG(WARNING, "Port %u Rx queue %u "
1769 : : "Multi-Packet RQ is unsupported, WQE buffer size (%u) "
1770 : : "is smaller than min mbuf size (%u)",
1771 : : dev->data->port_id, idx, RTE_BIT32(log_stride_wqe_size),
1772 : : min_mbuf_size);
1773 : 0 : goto unsupport;
1774 : : }
1775 : 0 : DRV_LOG(DEBUG, "Port %u Rx queue %u "
1776 : : "Multi-Packet RQ is enabled strd_num_n = %u, strd_sz_n = %u",
1777 : : dev->data->port_id, idx, RTE_BIT32(*actual_log_stride_num),
1778 : : RTE_BIT32(*actual_log_stride_size));
1779 : 0 : return 0;
1780 : 0 : unsupport:
1781 [ # # ]: 0 : if (config->mprq.enabled)
1782 [ # # # # : 0 : DRV_LOG(WARNING,
# # ]
1783 : : "Port %u MPRQ is requested but cannot be enabled\n"
1784 : : " (requested: pkt_sz = %u, desc_num = %u,"
1785 : : " rxq_num = %u, stride_sz = %u, stride_num = %u\n"
1786 : : " supported: min_rxqs_num = %u, min_buf_wqe_sz = %u"
1787 : : " min_stride_sz = %u, max_stride_sz = %u).\n"
1788 : : "Rx segment is %senabled. External mempool is %sused.",
1789 : : dev->data->port_id, min_mbuf_size, desc, priv->rxqs_n,
1790 : : config->mprq.log_stride_size == (uint32_t)MLX5_ARG_UNSET ?
1791 : : RTE_BIT32(MLX5_MPRQ_DEFAULT_LOG_STRIDE_SIZE) :
1792 : : RTE_BIT32(config->mprq.log_stride_size),
1793 : : RTE_BIT32(config->mprq.log_stride_num),
1794 : : config->mprq.min_rxqs_num,
1795 : : RTE_BIT32(dev_cap->mprq.log_min_stride_wqe_size),
1796 : : RTE_BIT32(dev_cap->mprq.log_min_stride_size),
1797 : : RTE_BIT32(dev_cap->mprq.log_max_stride_size),
1798 : : rx_seg_en ? "" : "not ", is_extmem ? "" : "not ");
1799 : : return -1;
1800 : : }
1801 : :
1802 : : /**
1803 : : * Create a DPDK Rx queue.
1804 : : *
1805 : : * @param dev
1806 : : * Pointer to Ethernet device.
1807 : : * @param idx
1808 : : * RX queue index.
1809 : : * @param desc
1810 : : * Number of descriptors to configure in queue.
1811 : : * @param socket
1812 : : * NUMA socket on which memory must be allocated.
1813 : : *
1814 : : * @return
1815 : : * A DPDK queue object on success, NULL otherwise and rte_errno is set.
1816 : : */
1817 : : struct mlx5_rxq_ctrl *
1818 : 0 : mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1819 : : unsigned int socket, const struct rte_eth_rxconf *conf,
1820 : : const struct rte_eth_rxseg_split *rx_seg, uint16_t n_seg,
1821 : : bool is_extmem)
1822 : : {
1823 : : int ret;
1824 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1825 : : struct mlx5_rxq_ctrl *tmpl;
1826 : : struct rte_mempool *first_mp = NULL;
1827 : : struct rte_mempool *last_mp = NULL;
1828 : : unsigned int mb_len;
1829 : : struct mlx5_port_config *config = &priv->config;
1830 : 0 : uint64_t offloads = conf->offloads |
1831 : 0 : dev->data->dev_conf.rxmode.offloads;
1832 : 0 : unsigned int lro_on_queue = !!(offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO);
1833 : : unsigned int max_rx_pktlen = lro_on_queue ?
1834 [ # # ]: 0 : dev->data->dev_conf.rxmode.max_lro_pkt_size :
1835 : 0 : dev->data->mtu + (unsigned int)RTE_ETHER_HDR_LEN +
1836 : : RTE_ETHER_CRC_LEN;
1837 : 0 : unsigned int non_scatter_min_mbuf_size = max_rx_pktlen +
1838 : : RTE_PKTMBUF_HEADROOM;
1839 : : unsigned int max_lro_size = 0;
1840 : : unsigned int first_mb_free_size;
1841 : 0 : uint32_t mprq_log_actual_stride_num = 0;
1842 : 0 : uint32_t mprq_log_actual_stride_size = 0;
1843 [ # # # # ]: 0 : bool rx_seg_en = n_seg != 1 || rx_seg[0].offset || rx_seg[0].length;
1844 : 0 : const int mprq_en = !mlx5_mprq_prepare(dev, idx, desc, rx_seg_en,
1845 : : non_scatter_min_mbuf_size,
1846 : : &mprq_log_actual_stride_num,
1847 : : &mprq_log_actual_stride_size,
1848 : : is_extmem);
1849 : : /*
1850 : : * Always allocate extra slots, even if eventually
1851 : : * the vector Rx will not be used.
1852 : : */
1853 : 0 : uint16_t desc_n = desc + config->rx_vec_en * MLX5_VPMD_DESCS_PER_LOOP;
1854 : 0 : size_t alloc_size = sizeof(*tmpl) + desc_n * sizeof(struct rte_mbuf *);
1855 : : const struct rte_eth_rxseg_split *qs_seg = rx_seg;
1856 : : unsigned int tail_len;
1857 : :
1858 : : /* Find first segment with a mempool. */
1859 [ # # ]: 0 : for (uint16_t seg = 0; seg < n_seg; seg++) {
1860 [ # # ]: 0 : if (rx_seg[seg].mp != NULL) {
1861 : : first_mp = rx_seg[seg].mp;
1862 : : break;
1863 : : }
1864 : : }
1865 [ # # ]: 0 : if (first_mp == NULL) {
1866 : 0 : DRV_LOG(ERR, "port %u Rx queue %u has no mempool", dev->data->port_id, idx);
1867 : 0 : rte_errno = EINVAL;
1868 : 0 : return NULL;
1869 : : }
1870 : 0 : mb_len = rte_pktmbuf_data_room_size(first_mp);
1871 : 0 : first_mb_free_size = mb_len - RTE_PKTMBUF_HEADROOM;
1872 : :
1873 [ # # ]: 0 : if (mprq_en) {
1874 : : /* Trim the number of descs needed. */
1875 : 0 : desc >>= mprq_log_actual_stride_num;
1876 : 0 : alloc_size += desc * sizeof(struct mlx5_mprq_buf *);
1877 : : }
1878 [ # # ]: 0 : if (socket != (unsigned int)SOCKET_ID_ANY) {
1879 : 0 : tmpl = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, alloc_size, 0, socket);
1880 : : } else {
1881 [ # # # # : 0 : tmpl = mlx5_malloc_numa_tolerant(MLX5_MEM_RTE | MLX5_MEM_ZERO, alloc_size, 0,
# # ]
1882 : : dev->device->numa_node);
1883 : : }
1884 [ # # ]: 0 : if (!tmpl) {
1885 : 0 : rte_errno = ENOMEM;
1886 : 0 : return NULL;
1887 : : }
1888 : 0 : LIST_INIT(&tmpl->owners);
1889 : : MLX5_ASSERT(n_seg && n_seg <= MLX5_MAX_RXQ_NSEG);
1890 : : /*
1891 : : * Save the current MTU to check against for shared rx queues.
1892 : : * Use dev->data->mtu which reflects the actual current MTU.
1893 : : */
1894 : 0 : tmpl->mtu = dev->data->mtu;
1895 : : /*
1896 : : * Save the original segment configuration in the shared queue
1897 : : * descriptor for the later check on the sibling queue creation.
1898 : : */
1899 : 0 : tmpl->rxseg_n = n_seg;
1900 [ # # ]: 0 : rte_memcpy(tmpl->rxseg, qs_seg,
1901 : : sizeof(struct rte_eth_rxseg_split) * n_seg);
1902 : : /*
1903 : : * Build the array of actual buffer offsets and lengths.
1904 : : * Pad with the buffers from the last memory pool if
1905 : : * needed to handle max size packets, replace zero length
1906 : : * with the buffer length from the pool.
1907 : : */
1908 : : tail_len = max_rx_pktlen;
1909 : : do {
1910 : : struct mlx5_eth_rxseg *hw_seg =
1911 : 0 : &tmpl->rxq.rxseg[tmpl->rxq.rxseg_n];
1912 : : uint32_t buf_len = 0, offset, seg_len;
1913 : :
1914 : : /*
1915 : : * For the buffers beyond descriptions offset is zero,
1916 : : * the first buffer contains head room.
1917 : : */
1918 [ # # ]: 0 : if (qs_seg->mp != NULL) {
1919 : : last_mp = qs_seg->mp;
1920 : 0 : buf_len = rte_pktmbuf_data_room_size(qs_seg->mp);
1921 [ # # ]: 0 : } else if (last_mp != NULL) {
1922 : 0 : buf_len = rte_pktmbuf_data_room_size(last_mp);
1923 : : } else {
1924 : : buf_len = mb_len;
1925 : : }
1926 [ # # ]: 0 : offset = (tmpl->rxq.rxseg_n >= n_seg ? 0 : qs_seg->offset) +
1927 [ # # ]: 0 : (tmpl->rxq.rxseg_n ? 0 : RTE_PKTMBUF_HEADROOM);
1928 : : /*
1929 : : * For the buffers beyond descriptions the length is
1930 : : * pool buffer length, zero lengths are replaced with
1931 : : * pool buffer length for real segments,
1932 : : * or remaining packet length for discard segments.
1933 : : */
1934 [ # # ]: 0 : seg_len = tmpl->rxq.rxseg_n >= n_seg ? buf_len :
1935 : 0 : qs_seg->length ?
1936 [ # # ]: 0 : qs_seg->length :
1937 : : qs_seg->mp != NULL ?
1938 [ # # ]: 0 : (buf_len - offset) : tail_len;
1939 : : /* Check is done in long int, now overflows. */
1940 [ # # # # ]: 0 : if (qs_seg->mp != NULL && buf_len < seg_len + offset) {
1941 : 0 : DRV_LOG(ERR, "port %u Rx queue %u: Split offset/length "
1942 : : "%u/%u can't be satisfied",
1943 : : dev->data->port_id, idx,
1944 : : qs_seg->offset, qs_seg->length);
1945 : 0 : rte_errno = EINVAL;
1946 : 0 : goto error;
1947 : : }
1948 [ # # ]: 0 : if (seg_len > tail_len)
1949 [ # # ]: 0 : seg_len = qs_seg->mp != NULL ? buf_len - offset : tail_len;
1950 [ # # ]: 0 : if (++tmpl->rxq.rxseg_n > MLX5_MAX_RXQ_NSEG) {
1951 : 0 : DRV_LOG(ERR,
1952 : : "port %u too many SGEs (%u) needed to handle"
1953 : : " requested maximum packet size %u, the maximum"
1954 : : " supported are %u", dev->data->port_id,
1955 : : tmpl->rxq.rxseg_n, max_rx_pktlen,
1956 : : MLX5_MAX_RXQ_NSEG);
1957 : 0 : rte_errno = ENOTSUP;
1958 : 0 : goto error;
1959 : : }
1960 : : /* Build the actual scattering element in the queue object. */
1961 : 0 : hw_seg->mp = qs_seg->mp;
1962 : : MLX5_ASSERT(offset <= UINT16_MAX);
1963 : : MLX5_ASSERT(seg_len <= UINT16_MAX);
1964 : 0 : hw_seg->offset = (uint16_t)offset;
1965 : 0 : hw_seg->length = (uint16_t)seg_len;
1966 : : /*
1967 : : * Advance the segment descriptor, the padding is the based
1968 : : * on the attributes of the last descriptor.
1969 : : */
1970 [ # # ]: 0 : if (tmpl->rxq.rxseg_n < n_seg)
1971 : 0 : qs_seg++;
1972 : 0 : tail_len -= RTE_MIN(tail_len, seg_len);
1973 [ # # # # ]: 0 : } while (tail_len || !rte_is_power_of_2(tmpl->rxq.rxseg_n));
1974 : : MLX5_ASSERT(tmpl->rxq.rxseg_n &&
1975 : : tmpl->rxq.rxseg_n <= MLX5_MAX_RXQ_NSEG);
1976 [ # # # # ]: 0 : if (tmpl->rxq.rxseg_n > 1 && !(offloads & RTE_ETH_RX_OFFLOAD_SCATTER)) {
1977 : 0 : DRV_LOG(ERR, "port %u Rx queue %u: Scatter offload is not"
1978 : : " configured and no enough mbuf space(%u) to contain "
1979 : : "the maximum RX packet length(%u) with head-room(%u)",
1980 : : dev->data->port_id, idx, mb_len, max_rx_pktlen,
1981 : : RTE_PKTMBUF_HEADROOM);
1982 : 0 : rte_errno = ENOSPC;
1983 : 0 : goto error;
1984 : : }
1985 : 0 : tmpl->is_hairpin = false;
1986 [ # # ]: 0 : if (socket != (unsigned int)SOCKET_ID_ANY) {
1987 [ # # ]: 0 : if (mlx5_mr_ctrl_init(&tmpl->rxq.mr_ctrl,
1988 : 0 : &priv->sh->cdev->mr_scache.dev_gen, socket))
1989 : : /* rte_errno is already set. */
1990 : 0 : goto error;
1991 : : } else {
1992 : 0 : ret = mlx5_mr_ctrl_init(&tmpl->rxq.mr_ctrl,
1993 : 0 : &priv->sh->cdev->mr_scache.dev_gen, dev->device->numa_node);
1994 [ # # ]: 0 : if (ret == -ENOMEM) {
1995 : 0 : ret = mlx5_mr_ctrl_init(&tmpl->rxq.mr_ctrl,
1996 : 0 : &priv->sh->cdev->mr_scache.dev_gen, SOCKET_ID_ANY);
1997 : : }
1998 [ # # ]: 0 : if (ret)
1999 : : /* rte_errno is already set. */
2000 : 0 : goto error;
2001 : : }
2002 : 0 : tmpl->socket = (socket == (unsigned int)SOCKET_ID_ANY ?
2003 [ # # ]: 0 : (unsigned int)dev->device->numa_node : socket);
2004 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq)
2005 : 0 : tmpl->irq = 1;
2006 [ # # ]: 0 : if (mprq_en) {
2007 : : /* TODO: Rx scatter isn't supported yet. */
2008 : 0 : tmpl->rxq.sges_n = 0;
2009 : 0 : tmpl->rxq.log_strd_num = mprq_log_actual_stride_num;
2010 : 0 : tmpl->rxq.log_strd_sz = mprq_log_actual_stride_size;
2011 : 0 : tmpl->rxq.strd_shift_en = MLX5_MPRQ_TWO_BYTE_SHIFT;
2012 : 0 : tmpl->rxq.strd_scatter_en =
2013 : 0 : !!(offloads & RTE_ETH_RX_OFFLOAD_SCATTER);
2014 : 0 : tmpl->rxq.mprq_max_memcpy_len = RTE_MIN(first_mb_free_size,
2015 : : config->mprq.max_memcpy_len);
2016 : 0 : max_lro_size = RTE_MIN(max_rx_pktlen,
2017 : : RTE_BIT32(tmpl->rxq.log_strd_num) *
2018 : : RTE_BIT32(tmpl->rxq.log_strd_sz));
2019 [ # # ]: 0 : } else if (tmpl->rxq.rxseg_n == 1) {
2020 : : MLX5_ASSERT(max_rx_pktlen <= first_mb_free_size);
2021 : 0 : tmpl->rxq.sges_n = 0;
2022 : : max_lro_size = max_rx_pktlen;
2023 [ # # ]: 0 : } else if (offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
2024 : : unsigned int sges_n;
2025 : :
2026 [ # # ]: 0 : if (lro_on_queue && first_mb_free_size <
2027 : : MLX5_MAX_LRO_HEADER_FIX) {
2028 : 0 : DRV_LOG(ERR, "Not enough space in the first segment(%u)"
2029 : : " to include the max header size(%u) for LRO",
2030 : : first_mb_free_size, MLX5_MAX_LRO_HEADER_FIX);
2031 : 0 : rte_errno = ENOTSUP;
2032 : 0 : goto error;
2033 : : }
2034 : : /*
2035 : : * Determine the number of SGEs needed for a full packet
2036 : : * and round it to the next power of two.
2037 : : */
2038 : 0 : sges_n = log2above(tmpl->rxq.rxseg_n);
2039 [ # # ]: 0 : if (sges_n > MLX5_MAX_LOG_RQ_SEGS) {
2040 : 0 : DRV_LOG(ERR,
2041 : : "port %u too many SGEs (%u) needed to handle"
2042 : : " requested maximum packet size %u, the maximum"
2043 : : " supported are %u", dev->data->port_id,
2044 : : 1 << sges_n, max_rx_pktlen,
2045 : : 1u << MLX5_MAX_LOG_RQ_SEGS);
2046 : 0 : rte_errno = ENOTSUP;
2047 : 0 : goto error;
2048 : : }
2049 : 0 : tmpl->rxq.sges_n = sges_n;
2050 : : max_lro_size = max_rx_pktlen;
2051 : : }
2052 : 0 : DRV_LOG(DEBUG, "port %u maximum number of segments per packet: %u",
2053 : : dev->data->port_id, 1 << tmpl->rxq.sges_n);
2054 [ # # ]: 0 : if (desc % (1 << tmpl->rxq.sges_n)) {
2055 : 0 : DRV_LOG(ERR,
2056 : : "port %u number of Rx queue descriptors (%u) is not a"
2057 : : " multiple of SGEs per packet (%u)",
2058 : : dev->data->port_id,
2059 : : desc,
2060 : : 1 << tmpl->rxq.sges_n);
2061 : 0 : rte_errno = EINVAL;
2062 : 0 : goto error;
2063 : : }
2064 : 0 : mlx5_max_lro_msg_size_adjust(dev, idx, max_lro_size);
2065 : : /* Toggle RX checksum offload if hardware supports it. */
2066 : 0 : tmpl->rxq.csum = !!(offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM);
2067 : : /* Configure Rx timestamp. */
2068 : 0 : tmpl->rxq.hw_timestamp = !!(offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP);
2069 : 0 : tmpl->rxq.timestamp_rx_flag = 0;
2070 [ # # # # ]: 0 : if (tmpl->rxq.hw_timestamp && rte_mbuf_dyn_rx_timestamp_register(
2071 : : &tmpl->rxq.timestamp_offset,
2072 : : &tmpl->rxq.timestamp_rx_flag) != 0) {
2073 : 0 : DRV_LOG(ERR, "Cannot register Rx timestamp field/flag");
2074 : 0 : goto error;
2075 : : }
2076 : : /* Configure VLAN stripping. */
2077 : 0 : tmpl->rxq.vlan_strip = !!(offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
2078 : : /* By default, FCS (CRC) is stripped by hardware. */
2079 : 0 : tmpl->rxq.crc_present = 0;
2080 : 0 : tmpl->rxq.lro = lro_on_queue;
2081 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
2082 [ # # ]: 0 : if (priv->sh->config.hw_fcs_strip) {
2083 : : /*
2084 : : * RQs used for LRO-enabled TIRs should not be
2085 : : * configured to scatter the FCS.
2086 : : */
2087 [ # # ]: 0 : if (lro_on_queue)
2088 : 0 : DRV_LOG(WARNING,
2089 : : "port %u CRC stripping has been "
2090 : : "disabled but will still be performed "
2091 : : "by hardware, because LRO is enabled",
2092 : : dev->data->port_id);
2093 : : else
2094 : 0 : tmpl->rxq.crc_present = 1;
2095 : : } else {
2096 : 0 : DRV_LOG(WARNING,
2097 : : "port %u CRC stripping has been disabled but will"
2098 : : " still be performed by hardware, make sure MLNX_OFED"
2099 : : " and firmware are up to date",
2100 : : dev->data->port_id);
2101 : : }
2102 : : }
2103 [ # # ]: 0 : DRV_LOG(DEBUG,
2104 : : "port %u CRC stripping is %s, %u bytes will be subtracted from"
2105 : : " incoming frames to hide it",
2106 : : dev->data->port_id,
2107 : : tmpl->rxq.crc_present ? "disabled" : "enabled",
2108 : : tmpl->rxq.crc_present << 2);
2109 [ # # ]: 0 : tmpl->rxq.rss_hash = !!priv->rss_conf.rss_hf &&
2110 [ # # ]: 0 : (!!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS));
2111 : : /* Save port ID. */
2112 : 0 : tmpl->rxq.port_id = dev->data->port_id;
2113 : 0 : tmpl->sh = priv->sh;
2114 : 0 : tmpl->rxq.sh = priv->sh;
2115 : 0 : tmpl->rxq.mp = first_mp;
2116 : 0 : tmpl->rxq.elts_n = log2above(desc);
2117 : 0 : tmpl->rxq.rq_repl_thresh = MLX5_VPMD_RXQ_RPLNSH_THRESH(desc_n);
2118 : 0 : tmpl->rxq.elts = (struct rte_mbuf *(*)[])(tmpl + 1);
2119 : 0 : tmpl->rxq.mprq_bufs = (struct mlx5_mprq_buf *(*)[])(*tmpl->rxq.elts + desc_n);
2120 : 0 : tmpl->rxq.idx = idx;
2121 [ # # ]: 0 : if (conf->share_group > 0) {
2122 : 0 : tmpl->rxq.shared = 1;
2123 : 0 : tmpl->share_group = conf->share_group;
2124 : 0 : tmpl->share_qid = conf->share_qid;
2125 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->sh->shared_rxqs, tmpl, share_entry);
2126 : : } else {
2127 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->rxqsctrl, tmpl, next);
2128 : : }
2129 : 0 : rte_atomic_store_explicit(&tmpl->ctrl_ref, 1, rte_memory_order_relaxed);
2130 : 0 : return tmpl;
2131 : 0 : error:
2132 : 0 : mlx5_mr_btree_free(&tmpl->rxq.mr_ctrl.cache_bh);
2133 : 0 : mlx5_free(tmpl);
2134 : 0 : return NULL;
2135 : : }
2136 : :
2137 : : /**
2138 : : * Create a DPDK Rx hairpin queue.
2139 : : *
2140 : : * @param dev
2141 : : * Pointer to Ethernet device.
2142 : : * @param rxq
2143 : : * RX queue.
2144 : : * @param desc
2145 : : * Number of descriptors to configure in queue.
2146 : : * @param hairpin_conf
2147 : : * The hairpin binding configuration.
2148 : : *
2149 : : * @return
2150 : : * A DPDK queue object on success, NULL otherwise and rte_errno is set.
2151 : : */
2152 : : struct mlx5_rxq_ctrl *
2153 : 0 : mlx5_rxq_hairpin_new(struct rte_eth_dev *dev, struct mlx5_rxq_priv *rxq,
2154 : : uint16_t desc,
2155 : : const struct rte_eth_hairpin_conf *hairpin_conf)
2156 : : {
2157 : 0 : uint16_t idx = rxq->idx;
2158 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2159 : : struct mlx5_rxq_ctrl *tmpl;
2160 : :
2161 : 0 : tmpl = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, sizeof(*tmpl), 0,
2162 : : SOCKET_ID_ANY);
2163 [ # # ]: 0 : if (!tmpl) {
2164 : 0 : rte_errno = ENOMEM;
2165 : 0 : return NULL;
2166 : : }
2167 : : LIST_INIT(&tmpl->owners);
2168 : 0 : rxq->ctrl = tmpl;
2169 : 0 : LIST_INSERT_HEAD(&tmpl->owners, rxq, owner_entry);
2170 : 0 : tmpl->is_hairpin = true;
2171 : 0 : tmpl->socket = SOCKET_ID_ANY;
2172 : 0 : tmpl->rxq.rss_hash = 0;
2173 : 0 : tmpl->rxq.port_id = dev->data->port_id;
2174 : 0 : tmpl->sh = priv->sh;
2175 : 0 : tmpl->rxq.mp = NULL;
2176 : 0 : tmpl->rxq.elts_n = log2above(desc);
2177 : 0 : tmpl->rxq.elts = NULL;
2178 : 0 : tmpl->rxq.mr_ctrl.cache_bh = (struct mlx5_mr_btree) { 0 };
2179 : 0 : tmpl->rxq.idx = idx;
2180 : 0 : rxq->hairpin_conf = *hairpin_conf;
2181 : 0 : mlx5_rxq_ref(dev, idx);
2182 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->rxqsctrl, tmpl, next);
2183 : 0 : rte_atomic_store_explicit(&tmpl->ctrl_ref, 1, rte_memory_order_relaxed);
2184 : 0 : return tmpl;
2185 : : }
2186 : :
2187 : : /**
2188 : : * Increase Rx queue reference count.
2189 : : *
2190 : : * @param dev
2191 : : * Pointer to Ethernet device.
2192 : : * @param idx
2193 : : * RX queue index.
2194 : : *
2195 : : * @return
2196 : : * A pointer to the queue if it exists, NULL otherwise.
2197 : : */
2198 : : struct mlx5_rxq_priv *
2199 : 0 : mlx5_rxq_ref(struct rte_eth_dev *dev, uint16_t idx)
2200 : : {
2201 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
2202 : :
2203 [ # # ]: 0 : if (rxq != NULL)
2204 : 0 : rte_atomic_fetch_add_explicit(&rxq->refcnt, 1, rte_memory_order_relaxed);
2205 : 0 : return rxq;
2206 : : }
2207 : :
2208 : : /**
2209 : : * Dereference a Rx queue.
2210 : : *
2211 : : * @param dev
2212 : : * Pointer to Ethernet device.
2213 : : * @param idx
2214 : : * RX queue index.
2215 : : *
2216 : : * @return
2217 : : * Updated reference count.
2218 : : */
2219 : : uint32_t
2220 : 0 : mlx5_rxq_deref(struct rte_eth_dev *dev, uint16_t idx)
2221 : : {
2222 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
2223 : :
2224 [ # # ]: 0 : if (rxq == NULL)
2225 : : return 0;
2226 : 0 : return rte_atomic_fetch_sub_explicit(&rxq->refcnt, 1, rte_memory_order_relaxed) - 1;
2227 : : }
2228 : :
2229 : : /**
2230 : : * Get a Rx queue.
2231 : : *
2232 : : * @param dev
2233 : : * Pointer to Ethernet device.
2234 : : * @param idx
2235 : : * RX queue index.
2236 : : *
2237 : : * @return
2238 : : * A pointer to the queue if it exists, NULL otherwise.
2239 : : */
2240 : : struct mlx5_rxq_priv *
2241 : 0 : mlx5_rxq_get(struct rte_eth_dev *dev, uint16_t idx)
2242 : : {
2243 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2244 : :
2245 [ # # ]: 0 : if (idx >= priv->rxqs_n)
2246 : : return NULL;
2247 : : MLX5_ASSERT(priv->rxq_privs != NULL);
2248 : 0 : return (*priv->rxq_privs)[idx];
2249 : : }
2250 : :
2251 : : /**
2252 : : * Get Rx queue shareable control.
2253 : : *
2254 : : * @param dev
2255 : : * Pointer to Ethernet device.
2256 : : * @param idx
2257 : : * RX queue index.
2258 : : *
2259 : : * @return
2260 : : * A pointer to the queue control if it exists, NULL otherwise.
2261 : : */
2262 : : struct mlx5_rxq_ctrl *
2263 : 0 : mlx5_rxq_ctrl_get(struct rte_eth_dev *dev, uint16_t idx)
2264 : : {
2265 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
2266 : :
2267 [ # # ]: 0 : return rxq == NULL ? NULL : rxq->ctrl;
2268 : : }
2269 : :
2270 : : /**
2271 : : * Get Rx queue shareable data.
2272 : : *
2273 : : * @param dev
2274 : : * Pointer to Ethernet device.
2275 : : * @param idx
2276 : : * RX queue index.
2277 : : *
2278 : : * @return
2279 : : * A pointer to the queue data if it exists, NULL otherwise.
2280 : : */
2281 : : struct mlx5_rxq_data *
2282 : 0 : mlx5_rxq_data_get(struct rte_eth_dev *dev, uint16_t idx)
2283 : : {
2284 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
2285 : :
2286 [ # # ]: 0 : return rxq == NULL ? NULL : &rxq->ctrl->rxq;
2287 : : }
2288 : :
2289 : : /**
2290 : : * Increase an external Rx queue reference count.
2291 : : *
2292 : : * @param dev
2293 : : * Pointer to Ethernet device.
2294 : : * @param idx
2295 : : * External RX queue index.
2296 : : *
2297 : : * @return
2298 : : * A pointer to the queue if it exists, NULL otherwise.
2299 : : */
2300 : : struct mlx5_external_q *
2301 : 0 : mlx5_ext_rxq_ref(struct rte_eth_dev *dev, uint16_t idx)
2302 : : {
2303 : 0 : struct mlx5_external_q *rxq = mlx5_ext_rxq_get(dev, idx);
2304 : :
2305 [ # # ]: 0 : if (rxq != NULL)
2306 : 0 : rte_atomic_fetch_add_explicit(&rxq->refcnt, 1, rte_memory_order_relaxed);
2307 : 0 : return rxq;
2308 : : }
2309 : :
2310 : : /**
2311 : : * Decrease an external Rx queue reference count.
2312 : : *
2313 : : * @param dev
2314 : : * Pointer to Ethernet device.
2315 : : * @param idx
2316 : : * External RX queue index.
2317 : : *
2318 : : * @return
2319 : : * Updated reference count.
2320 : : */
2321 : : uint32_t
2322 : 0 : mlx5_ext_rxq_deref(struct rte_eth_dev *dev, uint16_t idx)
2323 : : {
2324 : 0 : struct mlx5_external_q *rxq = mlx5_ext_rxq_get(dev, idx);
2325 : :
2326 : : return rxq != NULL ?
2327 [ # # ]: 0 : rte_atomic_fetch_sub_explicit(&rxq->refcnt, 1, rte_memory_order_relaxed) - 1 :
2328 : : UINT32_MAX;
2329 : : }
2330 : :
2331 : : /**
2332 : : * Get an external Rx queue.
2333 : : *
2334 : : * @param dev
2335 : : * Pointer to Ethernet device.
2336 : : * @param idx
2337 : : * External Rx queue index.
2338 : : *
2339 : : * @return
2340 : : * A pointer to the queue if it exists, NULL otherwise.
2341 : : */
2342 : : struct mlx5_external_q *
2343 : 0 : mlx5_ext_rxq_get(struct rte_eth_dev *dev, uint16_t idx)
2344 : : {
2345 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
2346 : :
2347 : : return mlx5_is_external_rxq(dev, idx) ?
2348 [ # # ]: 0 : &priv->ext_rxqs[idx - RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN] : NULL;
2349 : : }
2350 : :
2351 : : /**
2352 : : * Dereference a list of Rx queues.
2353 : : *
2354 : : * @param dev
2355 : : * Pointer to Ethernet device.
2356 : : * @param queues
2357 : : * List of Rx queues to deref.
2358 : : * @param queues_n
2359 : : * Number of queues in the array.
2360 : : */
2361 : : static void
2362 : 0 : mlx5_rxqs_deref(struct rte_eth_dev *dev, uint16_t *queues,
2363 : : const uint32_t queues_n)
2364 : : {
2365 : : uint32_t i;
2366 : :
2367 [ # # ]: 0 : for (i = 0; i < queues_n; i++) {
2368 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queues[i]))
2369 : 0 : claim_nonzero(mlx5_ext_rxq_deref(dev, queues[i]));
2370 : : else
2371 : 0 : claim_nonzero(mlx5_rxq_deref(dev, queues[i]));
2372 : : }
2373 : 0 : }
2374 : :
2375 : : /**
2376 : : * Increase reference count for list of Rx queues.
2377 : : *
2378 : : * @param dev
2379 : : * Pointer to Ethernet device.
2380 : : * @param queues
2381 : : * List of Rx queues to ref.
2382 : : * @param queues_n
2383 : : * Number of queues in the array.
2384 : : *
2385 : : * @return
2386 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2387 : : */
2388 : : static int
2389 : 0 : mlx5_rxqs_ref(struct rte_eth_dev *dev, uint16_t *queues,
2390 : : const uint32_t queues_n)
2391 : : {
2392 : : uint32_t i;
2393 : :
2394 [ # # ]: 0 : for (i = 0; i != queues_n; ++i) {
2395 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queues[i])) {
2396 [ # # ]: 0 : if (mlx5_ext_rxq_ref(dev, queues[i]) == NULL)
2397 : 0 : goto error;
2398 : : } else {
2399 [ # # ]: 0 : if (mlx5_rxq_ref(dev, queues[i]) == NULL)
2400 : 0 : goto error;
2401 : : }
2402 : : }
2403 : : return 0;
2404 : 0 : error:
2405 : 0 : mlx5_rxqs_deref(dev, queues, i);
2406 : 0 : rte_errno = EINVAL;
2407 : 0 : return -rte_errno;
2408 : : }
2409 : :
2410 : : /**
2411 : : * Release a Rx queue.
2412 : : *
2413 : : * @param dev
2414 : : * Pointer to Ethernet device.
2415 : : * @param idx
2416 : : * RX queue index.
2417 : : *
2418 : : * @return
2419 : : * 1 while a reference on it exists, 0 when freed.
2420 : : */
2421 : : int
2422 : 0 : mlx5_rxq_release(struct rte_eth_dev *dev, uint16_t idx)
2423 : : {
2424 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2425 : : struct mlx5_rxq_priv *rxq;
2426 : : struct mlx5_rxq_ctrl *rxq_ctrl;
2427 : : uint32_t refcnt;
2428 : : int32_t ctrl_ref;
2429 : :
2430 [ # # ]: 0 : if (priv->rxq_privs == NULL)
2431 : : return 0;
2432 : 0 : rxq = mlx5_rxq_get(dev, idx);
2433 [ # # # # ]: 0 : if (rxq == NULL || rxq->refcnt == 0)
2434 : : return 0;
2435 : 0 : rxq_ctrl = rxq->ctrl;
2436 : 0 : refcnt = mlx5_rxq_deref(dev, idx);
2437 [ # # ]: 0 : if (refcnt > 1) {
2438 : : return 1;
2439 [ # # ]: 0 : } else if (refcnt == 1) { /* RxQ stopped. */
2440 : 0 : priv->obj_ops.rxq_obj_release(rxq);
2441 [ # # # # ]: 0 : if (!rxq_ctrl->started && rxq_ctrl->obj != NULL) {
2442 [ # # ]: 0 : LIST_REMOVE(rxq_ctrl->obj, next);
2443 : 0 : mlx5_free(rxq_ctrl->obj);
2444 : 0 : rxq_ctrl->obj = NULL;
2445 : : }
2446 [ # # ]: 0 : if (!rxq_ctrl->is_hairpin) {
2447 [ # # ]: 0 : if (!rxq_ctrl->started)
2448 : 0 : rxq_free_elts(rxq_ctrl);
2449 : 0 : dev->data->rx_queue_state[idx] =
2450 : : RTE_ETH_QUEUE_STATE_STOPPED;
2451 : : }
2452 : : } else { /* Refcnt zero, closing device. */
2453 [ # # ]: 0 : LIST_REMOVE(rxq, owner_entry);
2454 : 0 : ctrl_ref = rte_atomic_fetch_sub_explicit(&rxq_ctrl->ctrl_ref, 1,
2455 : : rte_memory_order_relaxed) - 1;
2456 [ # # # # ]: 0 : if (ctrl_ref == 1 && LIST_EMPTY(&rxq_ctrl->owners)) {
2457 [ # # ]: 0 : if (!rxq_ctrl->is_hairpin)
2458 : 0 : mlx5_mr_btree_free
2459 : : (&rxq_ctrl->rxq.mr_ctrl.cache_bh);
2460 [ # # ]: 0 : if (rxq_ctrl->rxq.shared)
2461 [ # # ]: 0 : LIST_REMOVE(rxq_ctrl, share_entry);
2462 : : else
2463 [ # # ]: 0 : LIST_REMOVE(rxq_ctrl, next);
2464 : 0 : mlx5_free(rxq_ctrl->rxq.rq_win_data);
2465 : 0 : mlx5_free(rxq_ctrl);
2466 : : }
2467 : 0 : dev->data->rx_queues[idx] = NULL;
2468 : 0 : mlx5_free(rxq);
2469 : 0 : (*priv->rxq_privs)[idx] = NULL;
2470 : : }
2471 : : return 0;
2472 : : }
2473 : :
2474 : : /**
2475 : : * Verify the Rx Queue list is empty
2476 : : *
2477 : : * @param dev
2478 : : * Pointer to Ethernet device.
2479 : : *
2480 : : * @return
2481 : : * The number of object not released.
2482 : : */
2483 : : int
2484 : 0 : mlx5_rxq_verify(struct rte_eth_dev *dev)
2485 : : {
2486 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2487 : : struct mlx5_rxq_ctrl *rxq_ctrl;
2488 : : int ret = 0;
2489 : :
2490 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &priv->rxqsctrl, next) {
2491 : 0 : DRV_LOG(DEBUG, "port %u Rx Queue %u still referenced",
2492 : : dev->data->port_id, rxq_ctrl->rxq.idx);
2493 : 0 : ++ret;
2494 : : }
2495 : 0 : return ret;
2496 : : }
2497 : :
2498 : : /**
2499 : : * Verify the external Rx Queue list is empty.
2500 : : *
2501 : : * @param dev
2502 : : * Pointer to Ethernet device.
2503 : : *
2504 : : * @return
2505 : : * The number of object not released.
2506 : : */
2507 : : int
2508 : 0 : mlx5_ext_rxq_verify(struct rte_eth_dev *dev)
2509 : : {
2510 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2511 : : uint32_t i;
2512 : : int ret = 0;
2513 : :
2514 [ # # ]: 0 : if (priv->ext_rxqs == NULL)
2515 : : return 0;
2516 : :
2517 [ # # ]: 0 : for (i = RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN; i <= UINT16_MAX ; ++i) {
2518 : 0 : struct mlx5_external_q *rxq = mlx5_ext_rxq_get(dev, i);
2519 : :
2520 [ # # # # ]: 0 : if (rxq == NULL || rxq->refcnt < 2)
2521 : 0 : continue;
2522 : 0 : DRV_LOG(DEBUG, "Port %u external RxQ %u still referenced.",
2523 : : dev->data->port_id, i);
2524 : 0 : ++ret;
2525 : : }
2526 : : return ret;
2527 : : }
2528 : :
2529 : : /**
2530 : : * Check whether RxQ type is Hairpin.
2531 : : *
2532 : : * @param dev
2533 : : * Pointer to Ethernet device.
2534 : : * @param idx
2535 : : * Rx queue index.
2536 : : *
2537 : : * @return
2538 : : * True if Rx queue type is Hairpin, otherwise False.
2539 : : */
2540 : : bool
2541 : 0 : mlx5_rxq_is_hairpin(struct rte_eth_dev *dev, uint16_t idx)
2542 : : {
2543 : : struct mlx5_rxq_ctrl *rxq_ctrl;
2544 : :
2545 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, idx))
2546 : : return false;
2547 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
2548 [ # # # # ]: 0 : return (rxq_ctrl != NULL && rxq_ctrl->is_hairpin);
2549 : : }
2550 : :
2551 : : /*
2552 : : * Get a Rx hairpin queue configuration.
2553 : : *
2554 : : * @param dev
2555 : : * Pointer to Ethernet device.
2556 : : * @param idx
2557 : : * Rx queue index.
2558 : : *
2559 : : * @return
2560 : : * Pointer to the configuration if a hairpin RX queue, otherwise NULL.
2561 : : */
2562 : : const struct rte_eth_hairpin_conf *
2563 : 0 : mlx5_rxq_get_hairpin_conf(struct rte_eth_dev *dev, uint16_t idx)
2564 : : {
2565 [ # # ]: 0 : if (mlx5_rxq_is_hairpin(dev, idx)) {
2566 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
2567 : :
2568 [ # # ]: 0 : return rxq != NULL ? &rxq->hairpin_conf : NULL;
2569 : : }
2570 : : return NULL;
2571 : : }
2572 : :
2573 : : /**
2574 : : * Match queues listed in arguments to queues contained in indirection table
2575 : : * object.
2576 : : *
2577 : : * @param ind_tbl
2578 : : * Pointer to indirection table to match.
2579 : : * @param queues
2580 : : * Queues to match to queues in indirection table.
2581 : : * @param queues_n
2582 : : * Number of queues in the array.
2583 : : *
2584 : : * @return
2585 : : * 1 if all queues in indirection table match 0 otherwise.
2586 : : */
2587 : : static int
2588 : : mlx5_ind_table_obj_match_queues(const struct mlx5_ind_table_obj *ind_tbl,
2589 : : const uint16_t *queues, uint32_t queues_n)
2590 : : {
2591 : 0 : return (ind_tbl->queues_n == queues_n) &&
2592 : 0 : (!memcmp(ind_tbl->queues, queues,
2593 [ # # ]: 0 : ind_tbl->queues_n * sizeof(ind_tbl->queues[0])));
2594 : : }
2595 : :
2596 : : /**
2597 : : * Get an indirection table.
2598 : : *
2599 : : * @param dev
2600 : : * Pointer to Ethernet device.
2601 : : * @param queues
2602 : : * Queues entering in the indirection table.
2603 : : * @param queues_n
2604 : : * Number of queues in the array.
2605 : : *
2606 : : * @return
2607 : : * An indirection table if found.
2608 : : */
2609 : : struct mlx5_ind_table_obj *
2610 : 0 : mlx5_ind_table_obj_get(struct rte_eth_dev *dev, const uint16_t *queues,
2611 : : uint32_t queues_n)
2612 : : {
2613 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2614 : : struct mlx5_ind_table_obj *ind_tbl;
2615 : :
2616 : 0 : rte_rwlock_read_lock(&priv->ind_tbls_lock);
2617 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->ind_tbls, next) {
2618 [ # # ]: 0 : if ((ind_tbl->queues_n == queues_n) &&
2619 : 0 : (memcmp(ind_tbl->queues, queues,
2620 [ # # ]: 0 : ind_tbl->queues_n * sizeof(ind_tbl->queues[0]))
2621 : : == 0)) {
2622 : 0 : rte_atomic_fetch_add_explicit(&ind_tbl->refcnt, 1,
2623 : : rte_memory_order_relaxed);
2624 : 0 : break;
2625 : : }
2626 : : }
2627 : : rte_rwlock_read_unlock(&priv->ind_tbls_lock);
2628 : 0 : return ind_tbl;
2629 : : }
2630 : :
2631 : : /**
2632 : : * Release an indirection table.
2633 : : *
2634 : : * @param dev
2635 : : * Pointer to Ethernet device.
2636 : : * @param ind_table
2637 : : * Indirection table to release.
2638 : : * @param deref_rxqs
2639 : : * If true, then dereference RX queues related to indirection table.
2640 : : * Otherwise, no additional action will be taken.
2641 : : *
2642 : : * @return
2643 : : * 1 while a reference on it exists, 0 when freed.
2644 : : */
2645 : : int
2646 : 0 : mlx5_ind_table_obj_release(struct rte_eth_dev *dev,
2647 : : struct mlx5_ind_table_obj *ind_tbl,
2648 : : bool deref_rxqs)
2649 : : {
2650 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2651 : : unsigned int ret;
2652 : :
2653 : 0 : rte_rwlock_write_lock(&priv->ind_tbls_lock);
2654 : 0 : ret = rte_atomic_fetch_sub_explicit(&ind_tbl->refcnt, 1, rte_memory_order_relaxed) - 1;
2655 [ # # ]: 0 : if (!ret)
2656 [ # # ]: 0 : LIST_REMOVE(ind_tbl, next);
2657 : : rte_rwlock_write_unlock(&priv->ind_tbls_lock);
2658 [ # # ]: 0 : if (ret)
2659 : : return 1;
2660 : 0 : priv->obj_ops.ind_table_destroy(ind_tbl);
2661 [ # # ]: 0 : if (deref_rxqs)
2662 : 0 : mlx5_rxqs_deref(dev, ind_tbl->queues, ind_tbl->queues_n);
2663 : 0 : mlx5_free(ind_tbl);
2664 : 0 : return 0;
2665 : : }
2666 : :
2667 : : /**
2668 : : * Verify the Rx Queue list is empty
2669 : : *
2670 : : * @param dev
2671 : : * Pointer to Ethernet device.
2672 : : *
2673 : : * @return
2674 : : * The number of object not released.
2675 : : */
2676 : : int
2677 : 0 : mlx5_ind_table_obj_verify(struct rte_eth_dev *dev)
2678 : : {
2679 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2680 : : struct mlx5_ind_table_obj *ind_tbl;
2681 : : int ret = 0;
2682 : :
2683 : 0 : rte_rwlock_read_lock(&priv->ind_tbls_lock);
2684 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->ind_tbls, next) {
2685 : 0 : DRV_LOG(DEBUG,
2686 : : "port %u indirection table obj %p still referenced",
2687 : : dev->data->port_id, (void *)ind_tbl);
2688 : 0 : ++ret;
2689 : : }
2690 : : rte_rwlock_read_unlock(&priv->ind_tbls_lock);
2691 : 0 : return ret;
2692 : : }
2693 : :
2694 : : /**
2695 : : * Setup an indirection table structure fields.
2696 : : *
2697 : : * @param dev
2698 : : * Pointer to Ethernet device.
2699 : : * @param ind_table
2700 : : * Indirection table to modify.
2701 : : * @param ref_qs
2702 : : * Whether to increment RxQ reference counters.
2703 : : *
2704 : : * @return
2705 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2706 : : */
2707 : : int
2708 : 0 : mlx5_ind_table_obj_setup(struct rte_eth_dev *dev,
2709 : : struct mlx5_ind_table_obj *ind_tbl,
2710 : : bool ref_qs)
2711 : : {
2712 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2713 [ # # ]: 0 : uint32_t queues_n = ind_tbl->queues_n;
2714 : : int ret;
2715 : : const unsigned int n = rte_is_power_of_2(queues_n) ?
2716 : : log2above(queues_n) :
2717 : 0 : log2above(priv->sh->dev_cap.ind_table_max_size);
2718 : :
2719 [ # # # # ]: 0 : if (ref_qs && mlx5_rxqs_ref(dev, ind_tbl->queues, queues_n) < 0) {
2720 : 0 : DRV_LOG(DEBUG, "Port %u invalid indirection table queues.",
2721 : : dev->data->port_id);
2722 : 0 : return -rte_errno;
2723 : : }
2724 : 0 : ret = priv->obj_ops.ind_table_new(dev, n, ind_tbl);
2725 [ # # ]: 0 : if (ret) {
2726 : 0 : DRV_LOG(DEBUG, "Port %u cannot create a new indirection table.",
2727 : : dev->data->port_id);
2728 [ # # ]: 0 : if (ref_qs) {
2729 : 0 : int err = rte_errno;
2730 : :
2731 : 0 : mlx5_rxqs_deref(dev, ind_tbl->queues, queues_n);
2732 : 0 : rte_errno = err;
2733 : : }
2734 : 0 : return ret;
2735 : : }
2736 : 0 : rte_atomic_fetch_add_explicit(&ind_tbl->refcnt, 1, rte_memory_order_relaxed);
2737 : 0 : return 0;
2738 : : }
2739 : :
2740 : : /**
2741 : : * Create an indirection table.
2742 : : *
2743 : : * @param dev
2744 : : * Pointer to Ethernet device.
2745 : : * @param queues
2746 : : * Queues entering in the indirection table.
2747 : : * @param queues_n
2748 : : * Number of queues in the array.
2749 : : * @param standalone
2750 : : * Indirection table for Standalone queue.
2751 : : * @param ref_qs
2752 : : * Whether to increment RxQ reference counters.
2753 : : *
2754 : : * @return
2755 : : * The Verbs/DevX object initialized, NULL otherwise and rte_errno is set.
2756 : : */
2757 : : struct mlx5_ind_table_obj *
2758 : 0 : mlx5_ind_table_obj_new(struct rte_eth_dev *dev, const uint16_t *queues,
2759 : : uint32_t queues_n, bool standalone, bool ref_qs)
2760 : : {
2761 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2762 : : struct mlx5_ind_table_obj *ind_tbl;
2763 : : int ret;
2764 : 0 : uint32_t max_queues_n = priv->rxqs_n > queues_n ? priv->rxqs_n : queues_n;
2765 : :
2766 : : /*
2767 : : * Allocate maximum queues for shared action as queue number
2768 : : * maybe modified later.
2769 : : */
2770 [ # # ]: 0 : ind_tbl = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*ind_tbl) +
2771 : 0 : (standalone ? max_queues_n : queues_n) *
2772 : : sizeof(uint16_t), 0, SOCKET_ID_ANY);
2773 [ # # ]: 0 : if (!ind_tbl) {
2774 : 0 : rte_errno = ENOMEM;
2775 : 0 : return NULL;
2776 : : }
2777 : 0 : ind_tbl->queues_n = queues_n;
2778 : 0 : ind_tbl->queues = (uint16_t *)(ind_tbl + 1);
2779 : 0 : memcpy(ind_tbl->queues, queues, queues_n * sizeof(*queues));
2780 : 0 : ret = mlx5_ind_table_obj_setup(dev, ind_tbl, ref_qs);
2781 [ # # ]: 0 : if (ret < 0) {
2782 : 0 : mlx5_free(ind_tbl);
2783 : 0 : return NULL;
2784 : : }
2785 : 0 : rte_rwlock_write_lock(&priv->ind_tbls_lock);
2786 [ # # ]: 0 : if (!standalone)
2787 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->ind_tbls, ind_tbl, next);
2788 : : else
2789 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->standalone_ind_tbls, ind_tbl, next);
2790 : : rte_rwlock_write_unlock(&priv->ind_tbls_lock);
2791 : :
2792 : 0 : return ind_tbl;
2793 : : }
2794 : :
2795 : : static int
2796 : 0 : mlx5_ind_table_obj_check_standalone(struct rte_eth_dev *dev __rte_unused,
2797 : : struct mlx5_ind_table_obj *ind_tbl)
2798 : : {
2799 : : uint32_t refcnt;
2800 : :
2801 : 0 : refcnt = rte_atomic_load_explicit(&ind_tbl->refcnt, rte_memory_order_relaxed);
2802 [ # # ]: 0 : if (refcnt <= 1)
2803 : : return 0;
2804 : : /*
2805 : : * Modification of indirection tables having more than 1
2806 : : * reference is unsupported.
2807 : : */
2808 : 0 : DRV_LOG(DEBUG,
2809 : : "Port %u cannot modify indirection table %p (refcnt %u > 1).",
2810 : : dev->data->port_id, (void *)ind_tbl, refcnt);
2811 : 0 : rte_errno = EINVAL;
2812 : 0 : return -rte_errno;
2813 : : }
2814 : :
2815 : : /**
2816 : : * Modify an indirection table.
2817 : : *
2818 : : * @param dev
2819 : : * Pointer to Ethernet device.
2820 : : * @param ind_table
2821 : : * Indirection table to modify.
2822 : : * @param queues
2823 : : * Queues replacement for the indirection table.
2824 : : * @param queues_n
2825 : : * Number of queues in the array.
2826 : : * @param standalone
2827 : : * Indirection table for Standalone queue.
2828 : : * @param ref_new_qs
2829 : : * Whether to increment new RxQ set reference counters.
2830 : : * @param deref_old_qs
2831 : : * Whether to decrement old RxQ set reference counters.
2832 : : *
2833 : : * @return
2834 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2835 : : */
2836 : : int
2837 : 0 : mlx5_ind_table_obj_modify(struct rte_eth_dev *dev,
2838 : : struct mlx5_ind_table_obj *ind_tbl,
2839 : : uint16_t *queues, const uint32_t queues_n,
2840 : : bool standalone, bool ref_new_qs, bool deref_old_qs)
2841 : : {
2842 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
2843 : : int ret;
2844 : : const unsigned int n = rte_is_power_of_2(queues_n) ?
2845 : : log2above(queues_n) :
2846 : 0 : log2above(priv->sh->dev_cap.ind_table_max_size);
2847 : :
2848 : : MLX5_ASSERT(standalone);
2849 : : RTE_SET_USED(standalone);
2850 [ # # ]: 0 : if (mlx5_ind_table_obj_check_standalone(dev, ind_tbl) < 0)
2851 : 0 : return -rte_errno;
2852 [ # # # # ]: 0 : if (ref_new_qs && mlx5_rxqs_ref(dev, queues, queues_n) < 0) {
2853 : 0 : DRV_LOG(DEBUG, "Port %u invalid indirection table queues.",
2854 : : dev->data->port_id);
2855 : 0 : return -rte_errno;
2856 : : }
2857 : : MLX5_ASSERT(priv->obj_ops.ind_table_modify);
2858 : 0 : ret = priv->obj_ops.ind_table_modify(dev, n, queues, queues_n, ind_tbl);
2859 [ # # ]: 0 : if (ret) {
2860 : 0 : DRV_LOG(DEBUG, "Port %u cannot modify indirection table.",
2861 : : dev->data->port_id);
2862 [ # # ]: 0 : if (ref_new_qs) {
2863 : 0 : int err = rte_errno;
2864 : :
2865 : 0 : mlx5_rxqs_deref(dev, queues, queues_n);
2866 : 0 : rte_errno = err;
2867 : : }
2868 : 0 : return ret;
2869 : : }
2870 [ # # ]: 0 : if (deref_old_qs)
2871 : 0 : mlx5_rxqs_deref(dev, ind_tbl->queues, ind_tbl->queues_n);
2872 : 0 : ind_tbl->queues_n = queues_n;
2873 : 0 : ind_tbl->queues = queues;
2874 : 0 : return 0;
2875 : : }
2876 : :
2877 : : /**
2878 : : * Attach an indirection table to its queues.
2879 : : *
2880 : : * @param dev
2881 : : * Pointer to Ethernet device.
2882 : : * @param ind_table
2883 : : * Indirection table to attach.
2884 : : *
2885 : : * @return
2886 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2887 : : */
2888 : : int
2889 : 0 : mlx5_ind_table_obj_attach(struct rte_eth_dev *dev,
2890 : : struct mlx5_ind_table_obj *ind_tbl)
2891 : : {
2892 : : int ret;
2893 : :
2894 : 0 : ret = mlx5_ind_table_obj_modify(dev, ind_tbl, ind_tbl->queues,
2895 : : ind_tbl->queues_n,
2896 : : true /* standalone */,
2897 : : true /* ref_new_qs */,
2898 : : false /* deref_old_qs */);
2899 [ # # ]: 0 : if (ret != 0)
2900 : 0 : DRV_LOG(ERR, "Port %u could not modify indirect table obj %p",
2901 : : dev->data->port_id, (void *)ind_tbl);
2902 : 0 : return ret;
2903 : : }
2904 : :
2905 : : /**
2906 : : * Detach an indirection table from its queues.
2907 : : *
2908 : : * @param dev
2909 : : * Pointer to Ethernet device.
2910 : : * @param ind_table
2911 : : * Indirection table to detach.
2912 : : *
2913 : : * @return
2914 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2915 : : */
2916 : : int
2917 : 0 : mlx5_ind_table_obj_detach(struct rte_eth_dev *dev,
2918 : : struct mlx5_ind_table_obj *ind_tbl)
2919 : : {
2920 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2921 [ # # ]: 0 : const unsigned int n = rte_is_power_of_2(ind_tbl->queues_n) ?
2922 : : log2above(ind_tbl->queues_n) :
2923 : 0 : log2above(priv->sh->dev_cap.ind_table_max_size);
2924 : : unsigned int i;
2925 : : int ret;
2926 : :
2927 : 0 : ret = mlx5_ind_table_obj_check_standalone(dev, ind_tbl);
2928 [ # # ]: 0 : if (ret != 0)
2929 : : return ret;
2930 : : MLX5_ASSERT(priv->obj_ops.ind_table_modify);
2931 : 0 : ret = priv->obj_ops.ind_table_modify(dev, n, NULL, 0, ind_tbl);
2932 [ # # ]: 0 : if (ret != 0) {
2933 : 0 : DRV_LOG(ERR, "Port %u could not modify indirect table obj %p",
2934 : : dev->data->port_id, (void *)ind_tbl);
2935 : 0 : return ret;
2936 : : }
2937 [ # # ]: 0 : for (i = 0; i < ind_tbl->queues_n; i++)
2938 : 0 : mlx5_rxq_release(dev, ind_tbl->queues[i]);
2939 : : return ret;
2940 : : }
2941 : :
2942 : : int
2943 : 0 : mlx5_hrxq_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
2944 : : void *cb_ctx)
2945 : : {
2946 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
2947 : 0 : struct mlx5_flow_rss_desc *rss_desc = ctx->data;
2948 : : struct mlx5_hrxq *hrxq = container_of(entry, typeof(*hrxq), entry);
2949 : :
2950 : 0 : return (hrxq->rss_key_len != rss_desc->key_len ||
2951 [ # # ]: 0 : hrxq->symmetric_hash_function != rss_desc->symmetric_hash_function ||
2952 [ # # ]: 0 : memcmp(hrxq->rss_key, rss_desc->key, rss_desc->key_len) ||
2953 [ # # ]: 0 : hrxq->hws_flags != rss_desc->hws_flags ||
2954 [ # # ]: 0 : hrxq->hash_fields != rss_desc->hash_fields ||
2955 [ # # # # ]: 0 : hrxq->ind_table->queues_n != rss_desc->queue_num ||
2956 : 0 : memcmp(hrxq->ind_table->queues, rss_desc->queue,
2957 [ # # ]: 0 : rss_desc->queue_num * sizeof(rss_desc->queue[0])));
2958 : : }
2959 : :
2960 : : /**
2961 : : * Modify an Rx Hash queue configuration.
2962 : : *
2963 : : * @param dev
2964 : : * Pointer to Ethernet device.
2965 : : * @param hrxq
2966 : : * Index to Hash Rx queue to modify.
2967 : : * @param rss_key
2968 : : * RSS key for the Rx hash queue.
2969 : : * @param rss_key_len
2970 : : * RSS key length.
2971 : : * @param hash_fields
2972 : : * Verbs protocol hash field to make the RSS on.
2973 : : * @param queues
2974 : : * Queues entering in hash queue. In case of empty hash_fields only the
2975 : : * first queue index will be taken for the indirection table.
2976 : : * @param queues_n
2977 : : * Number of queues.
2978 : : *
2979 : : * @return
2980 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2981 : : */
2982 : : int
2983 : 0 : mlx5_hrxq_modify(struct rte_eth_dev *dev, uint32_t hrxq_idx,
2984 : : const uint8_t *rss_key, uint32_t rss_key_len,
2985 : : uint64_t hash_fields, bool symmetric_hash_function,
2986 : : const uint16_t *queues, uint32_t queues_n)
2987 : : {
2988 : : int err;
2989 : : struct mlx5_ind_table_obj *ind_tbl = NULL;
2990 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2991 : : struct mlx5_hrxq *hrxq =
2992 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
2993 : 0 : bool dev_started = !!dev->data->dev_started;
2994 : : int ret;
2995 : :
2996 [ # # ]: 0 : if (!hrxq) {
2997 : 0 : rte_errno = EINVAL;
2998 : 0 : return -rte_errno;
2999 : : }
3000 : : /* validations */
3001 [ # # ]: 0 : if (hrxq->rss_key_len != rss_key_len) {
3002 : : /* rss_key_len is fixed size 40 byte & not supposed to change */
3003 : 0 : rte_errno = EINVAL;
3004 : 0 : return -rte_errno;
3005 : : }
3006 [ # # ]: 0 : queues_n = hash_fields ? queues_n : 1;
3007 [ # # ]: 0 : if (mlx5_ind_table_obj_match_queues(hrxq->ind_table,
3008 : : queues, queues_n)) {
3009 : : ind_tbl = hrxq->ind_table;
3010 : : } else {
3011 [ # # ]: 0 : if (hrxq->standalone) {
3012 : : /*
3013 : : * Replacement of indirection table unsupported for
3014 : : * standalone hrxq objects (used by shared RSS).
3015 : : */
3016 : 0 : rte_errno = ENOTSUP;
3017 : 0 : return -rte_errno;
3018 : : }
3019 : 0 : ind_tbl = mlx5_ind_table_obj_get(dev, queues, queues_n);
3020 [ # # ]: 0 : if (!ind_tbl)
3021 : 0 : ind_tbl = mlx5_ind_table_obj_new(dev, queues, queues_n,
3022 : 0 : hrxq->standalone,
3023 : : dev_started);
3024 : : }
3025 [ # # ]: 0 : if (!ind_tbl) {
3026 : 0 : rte_errno = ENOMEM;
3027 : 0 : return -rte_errno;
3028 : : }
3029 : : MLX5_ASSERT(priv->obj_ops.hrxq_modify);
3030 : 0 : ret = priv->obj_ops.hrxq_modify(dev, hrxq, rss_key, hash_fields,
3031 : : symmetric_hash_function, ind_tbl);
3032 [ # # ]: 0 : if (ret) {
3033 : 0 : rte_errno = errno;
3034 : 0 : goto error;
3035 : : }
3036 [ # # ]: 0 : if (ind_tbl != hrxq->ind_table) {
3037 : : MLX5_ASSERT(!hrxq->standalone);
3038 : 0 : mlx5_ind_table_obj_release(dev, hrxq->ind_table, true);
3039 : 0 : hrxq->ind_table = ind_tbl;
3040 : : }
3041 : 0 : hrxq->hash_fields = hash_fields;
3042 : 0 : memcpy(hrxq->rss_key, rss_key, rss_key_len);
3043 : 0 : return 0;
3044 : : error:
3045 : : err = rte_errno;
3046 [ # # ]: 0 : if (ind_tbl != hrxq->ind_table) {
3047 : : MLX5_ASSERT(!hrxq->standalone);
3048 : 0 : mlx5_ind_table_obj_release(dev, ind_tbl, true);
3049 : : }
3050 : 0 : rte_errno = err;
3051 : 0 : return -rte_errno;
3052 : : }
3053 : :
3054 : : static void
3055 : 0 : __mlx5_hrxq_remove(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq)
3056 : : {
3057 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3058 : : bool deref_rxqs = true;
3059 : :
3060 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
3061 [ # # ]: 0 : if (hrxq->hws_flags)
3062 : 0 : mlx5dr_action_destroy(hrxq->action);
3063 : : else
3064 : 0 : mlx5_glue->destroy_flow_action(hrxq->action);
3065 : : #endif
3066 : 0 : priv->obj_ops.hrxq_destroy(hrxq);
3067 [ # # ]: 0 : if (!hrxq->standalone) {
3068 [ # # # # ]: 0 : if (!dev->data->dev_started && hrxq->hws_flags &&
3069 [ # # ]: 0 : !priv->hws_rule_flushing)
3070 : : deref_rxqs = false;
3071 : 0 : mlx5_ind_table_obj_release(dev, hrxq->ind_table, deref_rxqs);
3072 : : }
3073 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq->idx);
3074 : 0 : }
3075 : :
3076 : : /**
3077 : : * Release the hash Rx queue.
3078 : : *
3079 : : * @param dev
3080 : : * Pointer to Ethernet device.
3081 : : * @param hrxq
3082 : : * Index to Hash Rx queue to release.
3083 : : *
3084 : : * @param list
3085 : : * mlx5 list pointer.
3086 : : * @param entry
3087 : : * Hash queue entry pointer.
3088 : : */
3089 : : void
3090 : 0 : mlx5_hrxq_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3091 : : {
3092 : : struct rte_eth_dev *dev = tool_ctx;
3093 : : struct mlx5_hrxq *hrxq = container_of(entry, typeof(*hrxq), entry);
3094 : :
3095 : 0 : __mlx5_hrxq_remove(dev, hrxq);
3096 : 0 : }
3097 : :
3098 : : static struct mlx5_hrxq *
3099 : 0 : __mlx5_hrxq_create(struct rte_eth_dev *dev,
3100 : : struct mlx5_flow_rss_desc *rss_desc)
3101 : : {
3102 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3103 : 0 : const uint8_t *rss_key = rss_desc->key;
3104 : 0 : uint32_t rss_key_len = rss_desc->key_len;
3105 : 0 : bool standalone = !!rss_desc->shared_rss;
3106 : : const uint16_t *queues =
3107 [ # # ]: 0 : standalone ? rss_desc->const_q : rss_desc->queue;
3108 : 0 : uint32_t queues_n = rss_desc->queue_num;
3109 : : struct mlx5_hrxq *hrxq = NULL;
3110 : 0 : uint32_t hrxq_idx = 0;
3111 : 0 : struct mlx5_ind_table_obj *ind_tbl = rss_desc->ind_tbl;
3112 : : int ret;
3113 : :
3114 [ # # ]: 0 : queues_n = rss_desc->hash_fields ? queues_n : 1;
3115 [ # # # # ]: 0 : if (!ind_tbl && !rss_desc->hws_flags)
3116 : 0 : ind_tbl = mlx5_ind_table_obj_get(dev, queues, queues_n);
3117 [ # # ]: 0 : if (!ind_tbl)
3118 : 0 : ind_tbl = mlx5_ind_table_obj_new(dev, queues, queues_n,
3119 : 0 : standalone ||
3120 [ # # ]: 0 : rss_desc->hws_flags,
3121 [ # # ]: 0 : !!dev->data->dev_started);
3122 [ # # ]: 0 : if (!ind_tbl)
3123 : : return NULL;
3124 : 0 : hrxq = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_HRXQ], &hrxq_idx);
3125 [ # # ]: 0 : if (!hrxq)
3126 : 0 : goto error;
3127 : 0 : hrxq->standalone = standalone;
3128 : 0 : hrxq->idx = hrxq_idx;
3129 : 0 : hrxq->ind_table = ind_tbl;
3130 : 0 : hrxq->rss_key_len = rss_key_len;
3131 : 0 : hrxq->hash_fields = rss_desc->hash_fields;
3132 : 0 : hrxq->hws_flags = rss_desc->hws_flags;
3133 : 0 : hrxq->symmetric_hash_function = rss_desc->symmetric_hash_function;
3134 : 0 : memcpy(hrxq->rss_key, rss_key, rss_key_len);
3135 : 0 : ret = priv->obj_ops.hrxq_new(dev, hrxq, rss_desc->tunnel);
3136 [ # # ]: 0 : if (ret < 0)
3137 : 0 : goto error;
3138 : : return hrxq;
3139 : 0 : error:
3140 [ # # ]: 0 : if (!rss_desc->ind_tbl)
3141 : 0 : mlx5_ind_table_obj_release(dev, ind_tbl, true);
3142 [ # # ]: 0 : if (hrxq)
3143 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
3144 : : return NULL;
3145 : : }
3146 : :
3147 : : struct mlx5_list_entry *
3148 : 0 : mlx5_hrxq_create_cb(void *tool_ctx, void *cb_ctx)
3149 : : {
3150 : : struct rte_eth_dev *dev = tool_ctx;
3151 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3152 : 0 : struct mlx5_flow_rss_desc *rss_desc = ctx->data;
3153 : : struct mlx5_hrxq *hrxq;
3154 : :
3155 : 0 : hrxq = __mlx5_hrxq_create(dev, rss_desc);
3156 [ # # ]: 0 : return hrxq ? &hrxq->entry : NULL;
3157 : : }
3158 : :
3159 : : struct mlx5_list_entry *
3160 : 0 : mlx5_hrxq_clone_cb(void *tool_ctx, struct mlx5_list_entry *entry,
3161 : : void *cb_ctx __rte_unused)
3162 : : {
3163 : : struct rte_eth_dev *dev = tool_ctx;
3164 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3165 : : struct mlx5_hrxq *hrxq;
3166 : 0 : uint32_t hrxq_idx = 0;
3167 : :
3168 : 0 : hrxq = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_HRXQ], &hrxq_idx);
3169 [ # # ]: 0 : if (!hrxq)
3170 : : return NULL;
3171 : : memcpy(hrxq, entry, sizeof(*hrxq) + MLX5_RSS_HASH_KEY_LEN);
3172 : 0 : hrxq->idx = hrxq_idx;
3173 : 0 : return &hrxq->entry;
3174 : : }
3175 : :
3176 : : void
3177 : 0 : mlx5_hrxq_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3178 : : {
3179 : : struct rte_eth_dev *dev = tool_ctx;
3180 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3181 : : struct mlx5_hrxq *hrxq = container_of(entry, typeof(*hrxq), entry);
3182 : :
3183 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq->idx);
3184 : 0 : }
3185 : :
3186 : : /**
3187 : : * Get an Rx Hash queue.
3188 : : *
3189 : : * @param dev
3190 : : * Pointer to Ethernet device.
3191 : : * @param rss_desc
3192 : : * RSS configuration for the Rx hash queue.
3193 : : *
3194 : : * @return
3195 : : * An hash Rx queue on success.
3196 : : */
3197 : 0 : struct mlx5_hrxq *mlx5_hrxq_get(struct rte_eth_dev *dev,
3198 : : struct mlx5_flow_rss_desc *rss_desc)
3199 : : {
3200 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3201 : : struct mlx5_hrxq *hrxq = NULL;
3202 : : struct mlx5_list_entry *entry;
3203 : 0 : struct mlx5_flow_cb_ctx ctx = {
3204 : : .data = rss_desc,
3205 : : };
3206 : :
3207 [ # # ]: 0 : if (rss_desc->shared_rss) {
3208 : 0 : hrxq = __mlx5_hrxq_create(dev, rss_desc);
3209 : : } else {
3210 : 0 : entry = mlx5_list_register(priv->hrxqs, &ctx);
3211 [ # # ]: 0 : if (!entry)
3212 : 0 : return NULL;
3213 : : hrxq = container_of(entry, typeof(*hrxq), entry);
3214 : : }
3215 : : return hrxq;
3216 : : }
3217 : :
3218 : : /**
3219 : : * Release the hash Rx queue.
3220 : : *
3221 : : * @param dev
3222 : : * Pointer to Ethernet device.
3223 : : * @param hrxq_idx
3224 : : * Hash Rx queue to release.
3225 : : *
3226 : : * @return
3227 : : * 1 while a reference on it exists, 0 when freed.
3228 : : */
3229 : 0 : int mlx5_hrxq_obj_release(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq)
3230 : : {
3231 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3232 : :
3233 [ # # ]: 0 : if (!hrxq)
3234 : : return 0;
3235 [ # # ]: 0 : if (!hrxq->standalone)
3236 : 0 : return mlx5_list_unregister(priv->hrxqs, &hrxq->entry);
3237 : 0 : __mlx5_hrxq_remove(dev, hrxq);
3238 : 0 : return 0;
3239 : : }
3240 : :
3241 : : /**
3242 : : * Release the hash Rx queue with index.
3243 : : *
3244 : : * @param dev
3245 : : * Pointer to Ethernet device.
3246 : : * @param hrxq_idx
3247 : : * Index to Hash Rx queue to release.
3248 : : *
3249 : : * @return
3250 : : * 1 while a reference on it exists, 0 when freed.
3251 : : */
3252 : 0 : int mlx5_hrxq_release(struct rte_eth_dev *dev, uint32_t hrxq_idx)
3253 : : {
3254 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3255 : : struct mlx5_hrxq *hrxq;
3256 : :
3257 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
3258 : 0 : return mlx5_hrxq_obj_release(dev, hrxq);
3259 : : }
3260 : :
3261 : : /**
3262 : : * Create a drop Rx Hash queue.
3263 : : *
3264 : : * @param dev
3265 : : * Pointer to Ethernet device.
3266 : : *
3267 : : * @return
3268 : : * The Verbs/DevX object initialized, NULL otherwise and rte_errno is set.
3269 : : */
3270 : : struct mlx5_hrxq *
3271 : 0 : mlx5_drop_action_create(struct rte_eth_dev *dev)
3272 : : {
3273 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3274 : : struct mlx5_hrxq *hrxq = NULL;
3275 : : int ret;
3276 : :
3277 [ # # ]: 0 : if (priv->drop_queue.hrxq)
3278 : : return priv->drop_queue.hrxq;
3279 : 0 : hrxq = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*hrxq) + MLX5_RSS_HASH_KEY_LEN, 0, SOCKET_ID_ANY);
3280 [ # # ]: 0 : if (!hrxq) {
3281 : 0 : DRV_LOG(WARNING,
3282 : : "Port %u cannot allocate memory for drop queue.",
3283 : : dev->data->port_id);
3284 : 0 : rte_errno = ENOMEM;
3285 : 0 : goto error;
3286 : : }
3287 : 0 : priv->drop_queue.hrxq = hrxq;
3288 : 0 : hrxq->ind_table = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*hrxq->ind_table),
3289 : : 0, SOCKET_ID_ANY);
3290 [ # # ]: 0 : if (!hrxq->ind_table) {
3291 : 0 : rte_errno = ENOMEM;
3292 : 0 : goto error;
3293 : : }
3294 : 0 : ret = priv->obj_ops.drop_action_create(dev);
3295 [ # # ]: 0 : if (ret < 0)
3296 : 0 : goto error;
3297 : : return hrxq;
3298 : 0 : error:
3299 [ # # ]: 0 : if (hrxq) {
3300 [ # # ]: 0 : if (hrxq->ind_table)
3301 : 0 : mlx5_free(hrxq->ind_table);
3302 : 0 : priv->drop_queue.hrxq = NULL;
3303 : 0 : mlx5_free(hrxq);
3304 : : }
3305 : : return NULL;
3306 : : }
3307 : :
3308 : : /**
3309 : : * Release a drop hash Rx queue.
3310 : : *
3311 : : * @param dev
3312 : : * Pointer to Ethernet device.
3313 : : */
3314 : : void
3315 : 0 : mlx5_drop_action_destroy(struct rte_eth_dev *dev)
3316 : : {
3317 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3318 : 0 : struct mlx5_hrxq *hrxq = priv->drop_queue.hrxq;
3319 : :
3320 [ # # ]: 0 : if (!priv->drop_queue.hrxq)
3321 : : return;
3322 : 0 : priv->obj_ops.drop_action_destroy(dev);
3323 : 0 : mlx5_free(priv->drop_queue.rxq);
3324 : 0 : mlx5_free(hrxq->ind_table);
3325 : 0 : mlx5_free(hrxq);
3326 : 0 : priv->drop_queue.rxq = NULL;
3327 : 0 : priv->drop_queue.hrxq = NULL;
3328 : : }
3329 : :
3330 : : /**
3331 : : * Verify the Rx Queue list is empty
3332 : : *
3333 : : * @param dev
3334 : : * Pointer to Ethernet device.
3335 : : *
3336 : : * @return
3337 : : * The number of object not released.
3338 : : */
3339 : : uint32_t
3340 : 0 : mlx5_hrxq_verify(struct rte_eth_dev *dev)
3341 : : {
3342 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3343 : :
3344 : 0 : return mlx5_list_get_entry_num(priv->hrxqs);
3345 : : }
3346 : :
3347 : : /**
3348 : : * Set the Rx queue timestamp conversion parameters
3349 : : *
3350 : : * @param[in] dev
3351 : : * Pointer to the Ethernet device structure.
3352 : : */
3353 : : void
3354 : 0 : mlx5_rxq_timestamp_set(struct rte_eth_dev *dev)
3355 : : {
3356 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3357 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
3358 : : unsigned int i;
3359 : :
3360 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
3361 : 0 : struct mlx5_rxq_data *data = mlx5_rxq_data_get(dev, i);
3362 : :
3363 [ # # ]: 0 : if (data == NULL)
3364 : 0 : continue;
3365 : 0 : data->sh = sh;
3366 : 0 : data->rt_timestamp = sh->dev_cap.rt_timestamp;
3367 : : }
3368 : 0 : }
3369 : :
3370 : : /**
3371 : : * Validate given external RxQ rte_plow index, and get pointer to concurrent
3372 : : * external RxQ object to map/unmap.
3373 : : *
3374 : : * @param[in] port_id
3375 : : * The port identifier of the Ethernet device.
3376 : : * @param[in] dpdk_idx
3377 : : * Queue index in rte_flow.
3378 : : *
3379 : : * @return
3380 : : * Pointer to concurrent external RxQ on success,
3381 : : * NULL otherwise and rte_errno is set.
3382 : : */
3383 : : static struct mlx5_external_q *
3384 : 0 : mlx5_external_rx_queue_get_validate(uint16_t port_id, uint16_t dpdk_idx)
3385 : : {
3386 : : struct rte_eth_dev *dev;
3387 : : struct mlx5_priv *priv;
3388 : : int ret;
3389 : :
3390 [ # # ]: 0 : if (dpdk_idx < RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN) {
3391 : 0 : DRV_LOG(ERR, "Queue index %u should be in range: [%u, %u].",
3392 : : dpdk_idx, RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN, UINT16_MAX);
3393 : 0 : rte_errno = EINVAL;
3394 : 0 : return NULL;
3395 : : }
3396 : 0 : ret = mlx5_devx_extq_port_validate(port_id);
3397 [ # # ]: 0 : if (unlikely(ret))
3398 : : return NULL;
3399 : : dev = &rte_eth_devices[port_id];
3400 : 0 : priv = dev->data->dev_private;
3401 : : /*
3402 : : * When user configures remote PD and CTX and device creates RxQ by
3403 : : * DevX, external RxQs array is allocated.
3404 : : */
3405 : : MLX5_ASSERT(priv->ext_rxqs != NULL);
3406 : 0 : return &priv->ext_rxqs[dpdk_idx - RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN];
3407 : : }
3408 : :
3409 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_external_rx_queue_id_map, 22.03)
3410 : : int
3411 : 0 : rte_pmd_mlx5_external_rx_queue_id_map(uint16_t port_id, uint16_t dpdk_idx,
3412 : : uint32_t hw_idx)
3413 : : {
3414 : : struct mlx5_external_q *ext_rxq;
3415 : : uint32_t unmapped = 0;
3416 : :
3417 : 0 : ext_rxq = mlx5_external_rx_queue_get_validate(port_id, dpdk_idx);
3418 [ # # ]: 0 : if (ext_rxq == NULL)
3419 : 0 : return -rte_errno;
3420 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&ext_rxq->refcnt, &unmapped, 1,
3421 : : rte_memory_order_relaxed, rte_memory_order_relaxed)) {
3422 [ # # ]: 0 : if (ext_rxq->hw_id != hw_idx) {
3423 : 0 : DRV_LOG(ERR, "Port %u external RxQ index %u "
3424 : : "is already mapped to HW index (requesting is "
3425 : : "%u, existing is %u).",
3426 : : port_id, dpdk_idx, hw_idx, ext_rxq->hw_id);
3427 : 0 : rte_errno = EEXIST;
3428 : 0 : return -rte_errno;
3429 : : }
3430 : 0 : DRV_LOG(WARNING, "Port %u external RxQ index %u "
3431 : : "is already mapped to the requested HW index (%u)",
3432 : : port_id, dpdk_idx, hw_idx);
3433 : :
3434 : : } else {
3435 : 0 : ext_rxq->hw_id = hw_idx;
3436 : 0 : DRV_LOG(DEBUG, "Port %u external RxQ index %u "
3437 : : "is successfully mapped to the requested HW index (%u)",
3438 : : port_id, dpdk_idx, hw_idx);
3439 : : }
3440 : : return 0;
3441 : : }
3442 : :
3443 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_external_rx_queue_id_unmap, 22.03)
3444 : : int
3445 : 0 : rte_pmd_mlx5_external_rx_queue_id_unmap(uint16_t port_id, uint16_t dpdk_idx)
3446 : : {
3447 : : struct mlx5_external_q *ext_rxq;
3448 : : uint32_t mapped = 1;
3449 : :
3450 : 0 : ext_rxq = mlx5_external_rx_queue_get_validate(port_id, dpdk_idx);
3451 [ # # ]: 0 : if (ext_rxq == NULL)
3452 : 0 : return -rte_errno;
3453 [ # # ]: 0 : if (ext_rxq->refcnt > 1) {
3454 : 0 : DRV_LOG(ERR, "Port %u external RxQ index %u still referenced.",
3455 : : port_id, dpdk_idx);
3456 : 0 : rte_errno = EINVAL;
3457 : 0 : return -rte_errno;
3458 : : }
3459 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&ext_rxq->refcnt, &mapped, 0,
3460 : : rte_memory_order_relaxed, rte_memory_order_relaxed)) {
3461 : 0 : DRV_LOG(ERR, "Port %u external RxQ index %u doesn't exist.",
3462 : : port_id, dpdk_idx);
3463 : 0 : rte_errno = EINVAL;
3464 : 0 : return -rte_errno;
3465 : : }
3466 : 0 : DRV_LOG(DEBUG,
3467 : : "Port %u external RxQ index %u is successfully unmapped.",
3468 : : port_id, dpdk_idx);
3469 : 0 : return 0;
3470 : : }
|