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