1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
11 #include <sys/queue.h>
14 #include <rte_malloc.h>
15 #include <ethdev_driver.h>
16 #include <rte_common.h>
17 #include <rte_interrupts.h>
18 #include <rte_debug.h>
20 #include <rte_eal_paging.h>
22 #include <mlx5_glue.h>
23 #include <mlx5_malloc.h>
24 #include <mlx5_common.h>
25 #include <mlx5_common_mr.h>
27 #include "mlx5_defs.h"
30 #include "mlx5_utils.h"
31 #include "mlx5_autoconf.h"
32 #include "mlx5_devx.h"
35 /* Default RSS hash key also used for ConnectX-3. */
36 uint8_t rss_hash_default_key[] = {
37 0x2c, 0xc6, 0x81, 0xd1,
38 0x5b, 0xdb, 0xf4, 0xf7,
39 0xfc, 0xa2, 0x83, 0x19,
40 0xdb, 0x1a, 0x3e, 0x94,
41 0x6b, 0x9e, 0x38, 0xd9,
42 0x2c, 0x9c, 0x03, 0xd1,
43 0xad, 0x99, 0x44, 0xa7,
44 0xd9, 0x56, 0x3d, 0x59,
45 0x06, 0x3c, 0x25, 0xf3,
46 0xfc, 0x1f, 0xdc, 0x2a,
49 /* Length of the default RSS hash key. */
50 static_assert(MLX5_RSS_HASH_KEY_LEN ==
51 (unsigned int)sizeof(rss_hash_default_key),
52 "wrong RSS default key size.");
55 * Calculate the number of CQEs in CQ for the Rx queue.
58 * Pointer to receive queue structure.
61 * Number of CQEs in CQ.
64 mlx5_rxq_cqe_num(struct mlx5_rxq_data *rxq_data)
67 unsigned int wqe_n = 1 << rxq_data->elts_n;
69 if (mlx5_rxq_mprq_enabled(rxq_data))
70 cqe_n = wqe_n * RTE_BIT32(rxq_data->log_strd_num) - 1;
77 * Allocate RX queue elements for Multi-Packet RQ.
80 * Pointer to RX queue structure.
83 * 0 on success, a negative errno value otherwise and rte_errno is set.
86 rxq_alloc_elts_mprq(struct mlx5_rxq_ctrl *rxq_ctrl)
88 struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
89 unsigned int wqe_n = 1 << rxq->elts_n;
93 /* Iterate on segments. */
94 for (i = 0; i <= wqe_n; ++i) {
95 struct mlx5_mprq_buf *buf;
97 if (rte_mempool_get(rxq->mprq_mp, (void **)&buf) < 0) {
98 DRV_LOG(ERR, "port %u empty mbuf pool", rxq->port_id);
103 (*rxq->mprq_bufs)[i] = buf;
105 rxq->mprq_repl = buf;
108 "port %u MPRQ queue %u allocated and configured %u segments",
109 rxq->port_id, rxq->idx, wqe_n);
112 err = rte_errno; /* Save rte_errno before cleanup. */
114 for (i = 0; (i != wqe_n); ++i) {
115 if ((*rxq->mprq_bufs)[i] != NULL)
116 rte_mempool_put(rxq->mprq_mp,
117 (*rxq->mprq_bufs)[i]);
118 (*rxq->mprq_bufs)[i] = NULL;
120 DRV_LOG(DEBUG, "port %u MPRQ queue %u failed, freed everything",
121 rxq->port_id, rxq->idx);
122 rte_errno = err; /* Restore rte_errno. */
127 * Allocate RX queue elements for Single-Packet RQ.
130 * Pointer to RX queue structure.
133 * 0 on success, negative errno value on failure.
136 rxq_alloc_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
138 const unsigned int sges_n = 1 << rxq_ctrl->rxq.sges_n;
139 unsigned int elts_n = mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq) ?
140 RTE_BIT32(rxq_ctrl->rxq.elts_n) *
141 RTE_BIT32(rxq_ctrl->rxq.log_strd_num) :
142 RTE_BIT32(rxq_ctrl->rxq.elts_n);
143 bool has_vec_support = mlx5_rxq_check_vec_support(&rxq_ctrl->rxq) > 0;
147 /* Iterate on segments. */
148 for (i = 0; (i != elts_n); ++i) {
149 struct mlx5_eth_rxseg *seg = &rxq_ctrl->rxq.rxseg[i % sges_n];
150 struct rte_mbuf *buf;
152 buf = rte_pktmbuf_alloc(seg->mp);
154 if (rxq_ctrl->share_group == 0)
155 DRV_LOG(ERR, "port %u queue %u empty mbuf pool",
156 RXQ_PORT_ID(rxq_ctrl),
159 DRV_LOG(ERR, "share group %u queue %u empty mbuf pool",
160 rxq_ctrl->share_group,
161 rxq_ctrl->share_qid);
165 /* Only vectored Rx routines rely on headroom size. */
166 MLX5_ASSERT(!has_vec_support ||
167 DATA_OFF(buf) >= RTE_PKTMBUF_HEADROOM);
168 /* Buffer is supposed to be empty. */
169 MLX5_ASSERT(rte_pktmbuf_data_len(buf) == 0);
170 MLX5_ASSERT(rte_pktmbuf_pkt_len(buf) == 0);
171 MLX5_ASSERT(!buf->next);
172 SET_DATA_OFF(buf, seg->offset);
173 PORT(buf) = rxq_ctrl->rxq.port_id;
174 DATA_LEN(buf) = seg->length;
175 PKT_LEN(buf) = seg->length;
177 (*rxq_ctrl->rxq.elts)[i] = buf;
179 /* If Rx vector is activated. */
180 if (has_vec_support) {
181 struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
182 struct rte_mbuf *mbuf_init = &rxq->fake_mbuf;
183 struct rte_pktmbuf_pool_private *priv =
184 (struct rte_pktmbuf_pool_private *)
185 rte_mempool_get_priv(rxq_ctrl->rxq.mp);
188 /* Initialize default rearm_data for vPMD. */
189 mbuf_init->data_off = RTE_PKTMBUF_HEADROOM;
190 rte_mbuf_refcnt_set(mbuf_init, 1);
191 mbuf_init->nb_segs = 1;
192 /* For shared queues port is provided in CQE */
193 mbuf_init->port = rxq->shared ? 0 : rxq->port_id;
194 if (priv->flags & RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF)
195 mbuf_init->ol_flags = RTE_MBUF_F_EXTERNAL;
197 * prevent compiler reordering:
198 * rearm_data covers previous fields.
200 rte_compiler_barrier();
201 rxq->mbuf_initializer =
202 *(rte_xmm_t *)&mbuf_init->rearm_data;
203 /* Padding with a fake mbuf for vectorized Rx. */
204 for (j = 0; j < MLX5_VPMD_DESCS_PER_LOOP; ++j)
205 (*rxq->elts)[elts_n + j] = &rxq->fake_mbuf;
207 if (rxq_ctrl->share_group == 0)
209 "port %u SPRQ queue %u allocated and configured %u segments (max %u packets)",
210 RXQ_PORT_ID(rxq_ctrl), rxq_ctrl->rxq.idx, elts_n,
211 elts_n / (1 << rxq_ctrl->rxq.sges_n));
214 "share group %u SPRQ queue %u allocated and configured %u segments (max %u packets)",
215 rxq_ctrl->share_group, rxq_ctrl->share_qid, elts_n,
216 elts_n / (1 << rxq_ctrl->rxq.sges_n));
219 err = rte_errno; /* Save rte_errno before cleanup. */
221 for (i = 0; (i != elts_n); ++i) {
222 if ((*rxq_ctrl->rxq.elts)[i] != NULL)
223 rte_pktmbuf_free_seg((*rxq_ctrl->rxq.elts)[i]);
224 (*rxq_ctrl->rxq.elts)[i] = NULL;
226 if (rxq_ctrl->share_group == 0)
227 DRV_LOG(DEBUG, "port %u SPRQ queue %u failed, freed everything",
228 RXQ_PORT_ID(rxq_ctrl), rxq_ctrl->rxq.idx);
230 DRV_LOG(DEBUG, "share group %u SPRQ queue %u failed, freed everything",
231 rxq_ctrl->share_group, rxq_ctrl->share_qid);
232 rte_errno = err; /* Restore rte_errno. */
237 * Allocate RX queue elements.
240 * Pointer to RX queue structure.
243 * 0 on success, negative errno value on failure.
246 rxq_alloc_elts(struct mlx5_rxq_ctrl *rxq_ctrl)
251 * For MPRQ we need to allocate both MPRQ buffers
252 * for WQEs and simple mbufs for vector processing.
254 if (mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq))
255 ret = rxq_alloc_elts_mprq(rxq_ctrl);
257 ret = rxq_alloc_elts_sprq(rxq_ctrl);
262 * Free RX queue elements for Multi-Packet RQ.
265 * Pointer to RX queue structure.
268 rxq_free_elts_mprq(struct mlx5_rxq_ctrl *rxq_ctrl)
270 struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
273 DRV_LOG(DEBUG, "port %u Multi-Packet Rx queue %u freeing %d WRs",
274 rxq->port_id, rxq->idx, (1u << rxq->elts_n));
275 if (rxq->mprq_bufs == NULL)
277 for (i = 0; (i != (1u << rxq->elts_n)); ++i) {
278 if ((*rxq->mprq_bufs)[i] != NULL)
279 mlx5_mprq_buf_free((*rxq->mprq_bufs)[i]);
280 (*rxq->mprq_bufs)[i] = NULL;
282 if (rxq->mprq_repl != NULL) {
283 mlx5_mprq_buf_free(rxq->mprq_repl);
284 rxq->mprq_repl = NULL;
289 * Free RX queue elements for Single-Packet RQ.
292 * Pointer to RX queue structure.
295 rxq_free_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
297 struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
298 const uint16_t q_n = mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq) ?
299 RTE_BIT32(rxq->elts_n) * RTE_BIT32(rxq->log_strd_num) :
300 RTE_BIT32(rxq->elts_n);
301 const uint16_t q_mask = q_n - 1;
302 uint16_t elts_ci = mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq) ?
303 rxq->elts_ci : rxq->rq_ci;
304 uint16_t used = q_n - (elts_ci - rxq->rq_pi);
307 if (rxq_ctrl->share_group == 0)
308 DRV_LOG(DEBUG, "port %u Rx queue %u freeing %d WRs",
309 RXQ_PORT_ID(rxq_ctrl), rxq->idx, q_n);
311 DRV_LOG(DEBUG, "share group %u Rx queue %u freeing %d WRs",
312 rxq_ctrl->share_group, rxq_ctrl->share_qid, q_n);
313 if (rxq->elts == NULL)
316 * Some mbuf in the Ring belongs to the application.
317 * They cannot be freed.
319 if (mlx5_rxq_check_vec_support(rxq) > 0) {
320 for (i = 0; i < used; ++i)
321 (*rxq->elts)[(elts_ci + i) & q_mask] = NULL;
322 rxq->rq_pi = elts_ci;
324 for (i = 0; i != q_n; ++i) {
325 if ((*rxq->elts)[i] != NULL)
326 rte_pktmbuf_free_seg((*rxq->elts)[i]);
327 (*rxq->elts)[i] = NULL;
332 * Free RX queue elements.
335 * Pointer to RX queue structure.
338 rxq_free_elts(struct mlx5_rxq_ctrl *rxq_ctrl)
341 * For MPRQ we need to allocate both MPRQ buffers
342 * for WQEs and simple mbufs for vector processing.
344 if (mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq))
345 rxq_free_elts_mprq(rxq_ctrl);
346 rxq_free_elts_sprq(rxq_ctrl);
350 * Returns the per-queue supported offloads.
353 * Pointer to Ethernet device.
356 * Supported Rx offloads.
359 mlx5_get_rx_queue_offloads(struct rte_eth_dev *dev)
361 struct mlx5_priv *priv = dev->data->dev_private;
362 uint64_t offloads = (RTE_ETH_RX_OFFLOAD_SCATTER |
363 RTE_ETH_RX_OFFLOAD_TIMESTAMP |
364 RTE_ETH_RX_OFFLOAD_RSS_HASH);
366 if (!priv->config.mprq.enabled)
367 offloads |= RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT;
368 if (priv->sh->config.hw_fcs_strip)
369 offloads |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
370 if (priv->sh->dev_cap.hw_csum)
371 offloads |= (RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
372 RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
373 RTE_ETH_RX_OFFLOAD_TCP_CKSUM);
374 if (priv->sh->dev_cap.hw_vlan_strip)
375 offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
376 if (priv->sh->dev_cap.lro_supported)
377 offloads |= RTE_ETH_RX_OFFLOAD_TCP_LRO;
383 * Returns the per-port supported offloads.
386 * Supported Rx offloads.
389 mlx5_get_rx_port_offloads(void)
391 uint64_t offloads = RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
397 * Verify if the queue can be released.
400 * Pointer to Ethernet device.
405 * 1 if the queue can be released
406 * 0 if the queue can not be released, there are references to it.
407 * Negative errno and rte_errno is set if queue doesn't exist.
410 mlx5_rxq_releasable(struct rte_eth_dev *dev, uint16_t idx)
412 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
418 return (__atomic_load_n(&rxq->refcnt, __ATOMIC_RELAXED) == 1);
421 /* Fetches and drops all SW-owned and error CQEs to synchronize CQ. */
423 rxq_sync_cq(struct mlx5_rxq_data *rxq)
425 const uint16_t cqe_n = 1 << rxq->cqe_n;
426 const uint16_t cqe_mask = cqe_n - 1;
427 volatile struct mlx5_cqe *cqe;
432 cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_mask];
433 ret = check_cqe(cqe, cqe_n, rxq->cq_ci);
434 if (ret == MLX5_CQE_STATUS_HW_OWN)
436 if (ret == MLX5_CQE_STATUS_ERR) {
440 MLX5_ASSERT(ret == MLX5_CQE_STATUS_SW_OWN);
441 if (MLX5_CQE_FORMAT(cqe->op_own) != MLX5_COMPRESSED) {
445 /* Compute the next non compressed CQE. */
446 rxq->cq_ci += rte_be_to_cpu_32(cqe->byte_cnt);
449 /* Move all CQEs to HW ownership, including possible MiniCQEs. */
450 for (i = 0; i < cqe_n; i++) {
451 cqe = &(*rxq->cqes)[i];
452 cqe->op_own = MLX5_CQE_INVALIDATE;
454 /* Resync CQE and WQE (WQ in RESET state). */
456 *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
458 *rxq->rq_db = rte_cpu_to_be_32(0);
463 * Rx queue stop. Device queue goes to the RESET state,
464 * all involved mbufs are freed from WQ.
467 * Pointer to Ethernet device structure.
472 * 0 on success, a negative errno value otherwise and rte_errno is set.
475 mlx5_rx_queue_stop_primary(struct rte_eth_dev *dev, uint16_t idx)
477 struct mlx5_priv *priv = dev->data->dev_private;
478 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
479 struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl;
482 MLX5_ASSERT(rxq != NULL && rxq_ctrl != NULL);
483 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
484 ret = priv->obj_ops.rxq_obj_modify(rxq, MLX5_RXQ_MOD_RDY2RST);
486 DRV_LOG(ERR, "Cannot change Rx WQ state to RESET: %s",
491 /* Remove all processes CQEs. */
492 rxq_sync_cq(&rxq_ctrl->rxq);
493 /* Free all involved mbufs. */
494 rxq_free_elts(rxq_ctrl);
495 /* Set the actual queue state. */
496 dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STOPPED;
501 * Rx queue stop. Device queue goes to the RESET state,
502 * all involved mbufs are freed from WQ.
505 * Pointer to Ethernet device structure.
510 * 0 on success, a negative errno value otherwise and rte_errno is set.
513 mlx5_rx_queue_stop(struct rte_eth_dev *dev, uint16_t idx)
515 eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
518 if (rte_eth_dev_is_rx_hairpin_queue(dev, idx)) {
519 DRV_LOG(ERR, "Hairpin queue can't be stopped");
523 if (dev->data->rx_queue_state[idx] == RTE_ETH_QUEUE_STATE_STOPPED)
526 * Vectorized Rx burst requires the CQ and RQ indices
527 * synchronized, that might be broken on RQ restart
528 * and cause Rx malfunction, so queue stopping is
529 * not supported if vectorized Rx burst is engaged.
530 * The routine pointer depends on the process
531 * type, should perform check there.
533 if (pkt_burst == mlx5_rx_burst_vec) {
534 DRV_LOG(ERR, "Rx queue stop is not supported "
535 "for vectorized Rx");
539 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
540 ret = mlx5_mp_os_req_queue_control(dev, idx,
541 MLX5_MP_REQ_QUEUE_RX_STOP);
543 ret = mlx5_rx_queue_stop_primary(dev, idx);
549 * Rx queue start. Device queue goes to the ready state,
550 * all required mbufs are allocated and WQ is replenished.
553 * Pointer to Ethernet device structure.
558 * 0 on success, a negative errno value otherwise and rte_errno is set.
561 mlx5_rx_queue_start_primary(struct rte_eth_dev *dev, uint16_t idx)
563 struct mlx5_priv *priv = dev->data->dev_private;
564 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
565 struct mlx5_rxq_data *rxq_data = &rxq->ctrl->rxq;
568 MLX5_ASSERT(rxq != NULL && rxq->ctrl != NULL);
569 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
570 /* Allocate needed buffers. */
571 ret = rxq_alloc_elts(rxq->ctrl);
573 DRV_LOG(ERR, "Cannot reallocate buffers for Rx WQ");
578 *rxq_data->cq_db = rte_cpu_to_be_32(rxq_data->cq_ci);
580 /* Reset RQ consumer before moving queue to READY state. */
581 *rxq_data->rq_db = rte_cpu_to_be_32(0);
583 ret = priv->obj_ops.rxq_obj_modify(rxq, MLX5_RXQ_MOD_RST2RDY);
585 DRV_LOG(ERR, "Cannot change Rx WQ state to READY: %s",
590 /* Reinitialize RQ - set WQEs. */
591 mlx5_rxq_initialize(rxq_data);
592 rxq_data->err_state = MLX5_RXQ_ERR_STATE_NO_ERROR;
593 /* Set actual queue state. */
594 dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED;
599 * Rx queue start. Device queue goes to the ready state,
600 * all required mbufs are allocated and WQ is replenished.
603 * Pointer to Ethernet device structure.
608 * 0 on success, a negative errno value otherwise and rte_errno is set.
611 mlx5_rx_queue_start(struct rte_eth_dev *dev, uint16_t idx)
615 if (rte_eth_dev_is_rx_hairpin_queue(dev, idx)) {
616 DRV_LOG(ERR, "Hairpin queue can't be started");
620 if (dev->data->rx_queue_state[idx] == RTE_ETH_QUEUE_STATE_STARTED)
622 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
623 ret = mlx5_mp_os_req_queue_control(dev, idx,
624 MLX5_MP_REQ_QUEUE_RX_START);
626 ret = mlx5_rx_queue_start_primary(dev, idx);
632 * Rx queue presetup checks.
635 * Pointer to Ethernet device structure.
639 * Number of descriptors to configure in queue.
640 * @param[out] rxq_ctrl
641 * Address of pointer to shared Rx queue control.
644 * 0 on success, a negative errno value otherwise and rte_errno is set.
647 mlx5_rx_queue_pre_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t *desc,
648 struct mlx5_rxq_ctrl **rxq_ctrl)
650 struct mlx5_priv *priv = dev->data->dev_private;
651 struct mlx5_rxq_priv *rxq;
654 if (!rte_is_power_of_2(*desc)) {
655 *desc = 1 << log2above(*desc);
657 "port %u increased number of descriptors in Rx queue %u"
658 " to the next power of two (%d)",
659 dev->data->port_id, idx, *desc);
661 DRV_LOG(DEBUG, "port %u configuring Rx queue %u for %u descriptors",
662 dev->data->port_id, idx, *desc);
663 if (idx >= priv->rxqs_n) {
664 DRV_LOG(ERR, "port %u Rx queue index out of range (%u >= %u)",
665 dev->data->port_id, idx, priv->rxqs_n);
666 rte_errno = EOVERFLOW;
669 if (rxq_ctrl == NULL || *rxq_ctrl == NULL)
671 if (!(*rxq_ctrl)->rxq.shared) {
672 if (!mlx5_rxq_releasable(dev, idx)) {
673 DRV_LOG(ERR, "port %u unable to release queue index %u",
674 dev->data->port_id, idx);
678 mlx5_rxq_release(dev, idx);
680 if ((*rxq_ctrl)->obj != NULL)
681 /* Some port using shared Rx queue has been started. */
683 /* Release all owner RxQ to reconfigure Shared RxQ. */
685 rxq = LIST_FIRST(&(*rxq_ctrl)->owners);
686 LIST_REMOVE(rxq, owner_entry);
687 empty = LIST_EMPTY(&(*rxq_ctrl)->owners);
688 mlx5_rxq_release(ETH_DEV(rxq->priv), rxq->idx);
696 * Get the shared Rx queue object that matches group and queue index.
699 * Pointer to Ethernet device structure.
703 * Shared RX queue index.
706 * Shared RXQ object that matching, or NULL if not found.
708 static struct mlx5_rxq_ctrl *
709 mlx5_shared_rxq_get(struct rte_eth_dev *dev, uint32_t group, uint16_t share_qid)
711 struct mlx5_rxq_ctrl *rxq_ctrl;
712 struct mlx5_priv *priv = dev->data->dev_private;
714 LIST_FOREACH(rxq_ctrl, &priv->sh->shared_rxqs, share_entry) {
715 if (rxq_ctrl->share_group == group &&
716 rxq_ctrl->share_qid == share_qid)
723 * Check whether requested Rx queue configuration matches shared RXQ.
726 * Pointer to shared RXQ.
728 * Pointer to Ethernet device structure.
732 * Number of descriptors to configure in queue.
734 * NUMA socket on which memory must be allocated.
736 * Thresholds parameters.
738 * Memory pool for buffer allocations.
741 * 0 on success, a negative errno value otherwise and rte_errno is set.
744 mlx5_shared_rxq_match(struct mlx5_rxq_ctrl *rxq_ctrl, struct rte_eth_dev *dev,
745 uint16_t idx, uint16_t desc, unsigned int socket,
746 const struct rte_eth_rxconf *conf,
747 struct rte_mempool *mp)
749 struct mlx5_priv *spriv = LIST_FIRST(&rxq_ctrl->owners)->priv;
750 struct mlx5_priv *priv = dev->data->dev_private;
754 if (rxq_ctrl->socket != socket) {
755 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: socket mismatch",
756 dev->data->port_id, idx);
759 if (rxq_ctrl->rxq.elts_n != log2above(desc)) {
760 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: descriptor number mismatch",
761 dev->data->port_id, idx);
764 if (priv->mtu != spriv->mtu) {
765 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: mtu mismatch",
766 dev->data->port_id, idx);
769 if (priv->dev_data->dev_conf.intr_conf.rxq !=
770 spriv->dev_data->dev_conf.intr_conf.rxq) {
771 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: interrupt mismatch",
772 dev->data->port_id, idx);
775 if (mp != NULL && rxq_ctrl->rxq.mp != mp) {
776 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: mempool mismatch",
777 dev->data->port_id, idx);
779 } else if (mp == NULL) {
780 if (conf->rx_nseg != rxq_ctrl->rxseg_n) {
781 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: segment number mismatch",
782 dev->data->port_id, idx);
785 for (i = 0; i < conf->rx_nseg; i++) {
786 if (memcmp(&conf->rx_seg[i].split, &rxq_ctrl->rxseg[i],
787 sizeof(struct rte_eth_rxseg_split))) {
788 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: segment %u configuration mismatch",
789 dev->data->port_id, idx, i);
794 if (priv->config.hw_padding != spriv->config.hw_padding) {
795 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: padding mismatch",
796 dev->data->port_id, idx);
799 if (priv->config.cqe_comp != spriv->config.cqe_comp ||
800 (priv->config.cqe_comp &&
801 priv->config.cqe_comp_fmt != spriv->config.cqe_comp_fmt)) {
802 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: CQE compression mismatch",
803 dev->data->port_id, idx);
812 * Pointer to Ethernet device structure.
816 * Number of descriptors to configure in queue.
818 * NUMA socket on which memory must be allocated.
820 * Thresholds parameters.
822 * Memory pool for buffer allocations.
825 * 0 on success, a negative errno value otherwise and rte_errno is set.
828 mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
829 unsigned int socket, const struct rte_eth_rxconf *conf,
830 struct rte_mempool *mp)
832 struct mlx5_priv *priv = dev->data->dev_private;
833 struct mlx5_rxq_priv *rxq;
834 struct mlx5_rxq_ctrl *rxq_ctrl = NULL;
835 struct rte_eth_rxseg_split *rx_seg =
836 (struct rte_eth_rxseg_split *)conf->rx_seg;
837 struct rte_eth_rxseg_split rx_single = {.mp = mp};
838 uint16_t n_seg = conf->rx_nseg;
840 uint64_t offloads = conf->offloads |
841 dev->data->dev_conf.rxmode.offloads;
845 * The parameters should be checked on rte_eth_dev layer.
846 * If mp is specified it means the compatible configuration
847 * without buffer split feature tuning.
853 /* The offloads should be checked on rte_eth_dev layer. */
854 MLX5_ASSERT(offloads & RTE_ETH_RX_OFFLOAD_SCATTER);
855 if (!(offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)) {
856 DRV_LOG(ERR, "port %u queue index %u split "
857 "offload not configured",
858 dev->data->port_id, idx);
862 MLX5_ASSERT(n_seg < MLX5_MAX_RXQ_NSEG);
864 if (conf->share_group > 0) {
865 if (!priv->sh->cdev->config.hca_attr.mem_rq_rmp) {
866 DRV_LOG(ERR, "port %u queue index %u shared Rx queue not supported by fw",
867 dev->data->port_id, idx);
871 if (priv->obj_ops.rxq_obj_new != devx_obj_ops.rxq_obj_new) {
872 DRV_LOG(ERR, "port %u queue index %u shared Rx queue needs DevX api",
873 dev->data->port_id, idx);
877 if (conf->share_qid >= priv->rxqs_n) {
878 DRV_LOG(ERR, "port %u shared Rx queue index %u > number of Rx queues %u",
879 dev->data->port_id, conf->share_qid,
884 if (priv->config.mprq.enabled) {
885 DRV_LOG(ERR, "port %u shared Rx queue index %u: not supported when MPRQ enabled",
886 dev->data->port_id, conf->share_qid);
890 /* Try to reuse shared RXQ. */
891 rxq_ctrl = mlx5_shared_rxq_get(dev, conf->share_group,
893 if (rxq_ctrl != NULL &&
894 !mlx5_shared_rxq_match(rxq_ctrl, dev, idx, desc, socket,
900 res = mlx5_rx_queue_pre_setup(dev, idx, &desc, &rxq_ctrl);
904 rxq = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, sizeof(*rxq), 0,
907 DRV_LOG(ERR, "port %u unable to allocate rx queue index %u private data",
908 dev->data->port_id, idx);
912 if (rxq_ctrl == NULL) {
913 rxq_ctrl = mlx5_rxq_new(dev, idx, desc, socket, conf, rx_seg,
915 if (rxq_ctrl == NULL) {
916 DRV_LOG(ERR, "port %u unable to allocate rx queue index %u",
917 dev->data->port_id, idx);
925 (*priv->rxq_privs)[idx] = rxq;
926 /* Join owner list. */
927 LIST_INSERT_HEAD(&rxq_ctrl->owners, rxq, owner_entry);
928 rxq->ctrl = rxq_ctrl;
929 mlx5_rxq_ref(dev, idx);
930 DRV_LOG(DEBUG, "port %u adding Rx queue %u to list",
931 dev->data->port_id, idx);
932 dev->data->rx_queues[idx] = &rxq_ctrl->rxq;
939 * Pointer to Ethernet device structure.
943 * Number of descriptors to configure in queue.
944 * @param hairpin_conf
945 * Hairpin configuration parameters.
948 * 0 on success, a negative errno value otherwise and rte_errno is set.
951 mlx5_rx_hairpin_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
953 const struct rte_eth_hairpin_conf *hairpin_conf)
955 struct mlx5_priv *priv = dev->data->dev_private;
956 struct mlx5_rxq_priv *rxq;
957 struct mlx5_rxq_ctrl *rxq_ctrl;
960 res = mlx5_rx_queue_pre_setup(dev, idx, &desc, NULL);
963 if (hairpin_conf->peer_count != 1) {
965 DRV_LOG(ERR, "port %u unable to setup Rx hairpin queue index %u"
966 " peer count is %u", dev->data->port_id,
967 idx, hairpin_conf->peer_count);
970 if (hairpin_conf->peers[0].port == dev->data->port_id) {
971 if (hairpin_conf->peers[0].queue >= priv->txqs_n) {
973 DRV_LOG(ERR, "port %u unable to setup Rx hairpin queue"
974 " index %u, Tx %u is larger than %u",
975 dev->data->port_id, idx,
976 hairpin_conf->peers[0].queue, priv->txqs_n);
980 if (hairpin_conf->manual_bind == 0 ||
981 hairpin_conf->tx_explicit == 0) {
983 DRV_LOG(ERR, "port %u unable to setup Rx hairpin queue"
984 " index %u peer port %u with attributes %u %u",
985 dev->data->port_id, idx,
986 hairpin_conf->peers[0].port,
987 hairpin_conf->manual_bind,
988 hairpin_conf->tx_explicit);
992 rxq = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, sizeof(*rxq), 0,
995 DRV_LOG(ERR, "port %u unable to allocate hairpin rx queue index %u private data",
996 dev->data->port_id, idx);
1002 (*priv->rxq_privs)[idx] = rxq;
1003 rxq_ctrl = mlx5_rxq_hairpin_new(dev, rxq, desc, hairpin_conf);
1005 DRV_LOG(ERR, "port %u unable to allocate hairpin queue index %u",
1006 dev->data->port_id, idx);
1008 (*priv->rxq_privs)[idx] = NULL;
1012 DRV_LOG(DEBUG, "port %u adding hairpin Rx queue %u to list",
1013 dev->data->port_id, idx);
1014 dev->data->rx_queues[idx] = &rxq_ctrl->rxq;
1019 * DPDK callback to release a RX queue.
1022 * Pointer to Ethernet device structure.
1024 * Receive queue index.
1027 mlx5_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1029 struct mlx5_rxq_data *rxq = dev->data->rx_queues[qid];
1033 if (!mlx5_rxq_releasable(dev, qid))
1034 rte_panic("port %u Rx queue %u is still used by a flow and"
1035 " cannot be removed\n", dev->data->port_id, qid);
1036 mlx5_rxq_release(dev, qid);
1040 * Allocate queue vector and fill epoll fd list for Rx interrupts.
1043 * Pointer to Ethernet device.
1046 * 0 on success, a negative errno value otherwise and rte_errno is set.
1049 mlx5_rx_intr_vec_enable(struct rte_eth_dev *dev)
1051 struct mlx5_priv *priv = dev->data->dev_private;
1053 unsigned int rxqs_n = priv->rxqs_n;
1054 unsigned int n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
1055 unsigned int count = 0;
1056 struct rte_intr_handle *intr_handle = dev->intr_handle;
1058 if (!dev->data->dev_conf.intr_conf.rxq)
1060 mlx5_rx_intr_vec_disable(dev);
1061 if (rte_intr_vec_list_alloc(intr_handle, NULL, n)) {
1063 "port %u failed to allocate memory for interrupt"
1064 " vector, Rx interrupts will not be supported",
1065 dev->data->port_id);
1070 if (rte_intr_type_set(intr_handle, RTE_INTR_HANDLE_EXT))
1073 for (i = 0; i != n; ++i) {
1074 /* This rxq obj must not be released in this function. */
1075 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1076 struct mlx5_rxq_obj *rxq_obj = rxq ? rxq->ctrl->obj : NULL;
1079 /* Skip queues that cannot request interrupts. */
1080 if (!rxq_obj || (!rxq_obj->ibv_channel &&
1081 !rxq_obj->devx_channel)) {
1082 /* Use invalid intr_vec[] index to disable entry. */
1083 if (rte_intr_vec_list_index_set(intr_handle, i,
1084 RTE_INTR_VEC_RXTX_OFFSET + RTE_MAX_RXTX_INTR_VEC_ID))
1088 mlx5_rxq_ref(dev, i);
1089 if (count >= RTE_MAX_RXTX_INTR_VEC_ID) {
1091 "port %u too many Rx queues for interrupt"
1092 " vector size (%d), Rx interrupts cannot be"
1094 dev->data->port_id, RTE_MAX_RXTX_INTR_VEC_ID);
1095 mlx5_rx_intr_vec_disable(dev);
1099 rc = mlx5_os_set_nonblock_channel_fd(rxq_obj->fd);
1103 "port %u failed to make Rx interrupt file"
1104 " descriptor %d non-blocking for queue index"
1106 dev->data->port_id, rxq_obj->fd, i);
1107 mlx5_rx_intr_vec_disable(dev);
1111 if (rte_intr_vec_list_index_set(intr_handle, i,
1112 RTE_INTR_VEC_RXTX_OFFSET + count))
1114 if (rte_intr_efds_index_set(intr_handle, count,
1120 mlx5_rx_intr_vec_disable(dev);
1121 else if (rte_intr_nb_efd_set(intr_handle, count))
1127 * Clean up Rx interrupts handler.
1130 * Pointer to Ethernet device.
1133 mlx5_rx_intr_vec_disable(struct rte_eth_dev *dev)
1135 struct mlx5_priv *priv = dev->data->dev_private;
1136 struct rte_intr_handle *intr_handle = dev->intr_handle;
1138 unsigned int rxqs_n = priv->rxqs_n;
1139 unsigned int n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
1141 if (!dev->data->dev_conf.intr_conf.rxq)
1143 if (rte_intr_vec_list_index_get(intr_handle, 0) < 0)
1145 for (i = 0; i != n; ++i) {
1146 if (rte_intr_vec_list_index_get(intr_handle, i) ==
1147 RTE_INTR_VEC_RXTX_OFFSET + RTE_MAX_RXTX_INTR_VEC_ID)
1150 * Need to access directly the queue to release the reference
1151 * kept in mlx5_rx_intr_vec_enable().
1153 mlx5_rxq_deref(dev, i);
1156 rte_intr_free_epoll_fd(intr_handle);
1158 rte_intr_vec_list_free(intr_handle);
1160 rte_intr_nb_efd_set(intr_handle, 0);
1164 * MLX5 CQ notification .
1167 * Pointer to receive queue structure.
1169 * Sequence number per receive queue .
1172 mlx5_arm_cq(struct mlx5_rxq_data *rxq, int sq_n_rxq)
1175 uint32_t doorbell_hi;
1178 sq_n = sq_n_rxq & MLX5_CQ_SQN_MASK;
1179 doorbell_hi = sq_n << MLX5_CQ_SQN_OFFSET | (rxq->cq_ci & MLX5_CI_MASK);
1180 doorbell = (uint64_t)doorbell_hi << 32;
1181 doorbell |= rxq->cqn;
1182 mlx5_doorbell_ring(&rxq->uar_data, rte_cpu_to_be_64(doorbell),
1183 doorbell_hi, &rxq->cq_db[MLX5_CQ_ARM_DB], 0);
1187 * DPDK callback for Rx queue interrupt enable.
1190 * Pointer to Ethernet device structure.
1191 * @param rx_queue_id
1195 * 0 on success, a negative errno value otherwise and rte_errno is set.
1198 mlx5_rx_intr_enable(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1200 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, rx_queue_id);
1203 if (rxq->ctrl->irq) {
1204 if (!rxq->ctrl->obj)
1206 mlx5_arm_cq(&rxq->ctrl->rxq, rxq->ctrl->rxq.cq_arm_sn);
1215 * DPDK callback for Rx queue interrupt disable.
1218 * Pointer to Ethernet device structure.
1219 * @param rx_queue_id
1223 * 0 on success, a negative errno value otherwise and rte_errno is set.
1226 mlx5_rx_intr_disable(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1228 struct mlx5_priv *priv = dev->data->dev_private;
1229 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, rx_queue_id);
1236 if (!rxq->ctrl->obj)
1238 if (rxq->ctrl->irq) {
1239 ret = priv->obj_ops.rxq_event_get(rxq->ctrl->obj);
1242 rxq->ctrl->rxq.cq_arm_sn++;
1247 * The ret variable may be EAGAIN which means the get_event function was
1248 * called before receiving one.
1254 if (rte_errno != EAGAIN)
1255 DRV_LOG(WARNING, "port %u unable to disable interrupt on Rx queue %d",
1256 dev->data->port_id, rx_queue_id);
1261 * Verify the Rx queue objects list is empty
1264 * Pointer to Ethernet device.
1267 * The number of objects not released.
1270 mlx5_rxq_obj_verify(struct rte_eth_dev *dev)
1272 struct mlx5_priv *priv = dev->data->dev_private;
1274 struct mlx5_rxq_obj *rxq_obj;
1276 LIST_FOREACH(rxq_obj, &priv->rxqsobj, next) {
1277 if (rxq_obj->rxq_ctrl == NULL)
1279 if (rxq_obj->rxq_ctrl->rxq.shared &&
1280 !LIST_EMPTY(&rxq_obj->rxq_ctrl->owners))
1282 DRV_LOG(DEBUG, "port %u Rx queue %u still referenced",
1283 dev->data->port_id, rxq_obj->rxq_ctrl->rxq.idx);
1290 * Callback function to initialize mbufs for Multi-Packet RQ.
1293 mlx5_mprq_buf_init(struct rte_mempool *mp, void *opaque_arg,
1294 void *_m, unsigned int i __rte_unused)
1296 struct mlx5_mprq_buf *buf = _m;
1297 struct rte_mbuf_ext_shared_info *shinfo;
1298 unsigned int strd_n = (unsigned int)(uintptr_t)opaque_arg;
1301 memset(_m, 0, sizeof(*buf));
1303 __atomic_store_n(&buf->refcnt, 1, __ATOMIC_RELAXED);
1304 for (j = 0; j != strd_n; ++j) {
1305 shinfo = &buf->shinfos[j];
1306 shinfo->free_cb = mlx5_mprq_buf_free_cb;
1307 shinfo->fcb_opaque = buf;
1312 * Free mempool of Multi-Packet RQ.
1315 * Pointer to Ethernet device.
1318 * 0 on success, negative errno value on failure.
1321 mlx5_mprq_free_mp(struct rte_eth_dev *dev)
1323 struct mlx5_priv *priv = dev->data->dev_private;
1324 struct rte_mempool *mp = priv->mprq_mp;
1329 DRV_LOG(DEBUG, "port %u freeing mempool (%s) for Multi-Packet RQ",
1330 dev->data->port_id, mp->name);
1332 * If a buffer in the pool has been externally attached to a mbuf and it
1333 * is still in use by application, destroying the Rx queue can spoil
1334 * the packet. It is unlikely to happen but if application dynamically
1335 * creates and destroys with holding Rx packets, this can happen.
1337 * TODO: It is unavoidable for now because the mempool for Multi-Packet
1338 * RQ isn't provided by application but managed by PMD.
1340 if (!rte_mempool_full(mp)) {
1342 "port %u mempool for Multi-Packet RQ is still in use",
1343 dev->data->port_id);
1347 rte_mempool_free(mp);
1348 /* Unset mempool for each Rx queue. */
1349 for (i = 0; i != priv->rxqs_n; ++i) {
1350 struct mlx5_rxq_data *rxq = mlx5_rxq_data_get(dev, i);
1354 rxq->mprq_mp = NULL;
1356 priv->mprq_mp = NULL;
1361 * Allocate a mempool for Multi-Packet RQ. All configured Rx queues share the
1362 * mempool. If already allocated, reuse it if there're enough elements.
1363 * Otherwise, resize it.
1366 * Pointer to Ethernet device.
1369 * 0 on success, negative errno value on failure.
1372 mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)
1374 struct mlx5_priv *priv = dev->data->dev_private;
1375 struct rte_mempool *mp = priv->mprq_mp;
1376 char name[RTE_MEMPOOL_NAMESIZE];
1377 unsigned int desc = 0;
1378 unsigned int buf_len;
1379 unsigned int obj_num;
1380 unsigned int obj_size;
1381 unsigned int log_strd_num = 0;
1382 unsigned int log_strd_sz = 0;
1384 unsigned int n_ibv = 0;
1387 if (!mlx5_mprq_enabled(dev))
1389 /* Count the total number of descriptors configured. */
1390 for (i = 0; i != priv->rxqs_n; ++i) {
1391 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
1392 struct mlx5_rxq_data *rxq;
1394 if (rxq_ctrl == NULL ||
1395 rxq_ctrl->type != MLX5_RXQ_TYPE_STANDARD)
1397 rxq = &rxq_ctrl->rxq;
1399 desc += 1 << rxq->elts_n;
1400 /* Get the max number of strides. */
1401 if (log_strd_num < rxq->log_strd_num)
1402 log_strd_num = rxq->log_strd_num;
1403 /* Get the max size of a stride. */
1404 if (log_strd_sz < rxq->log_strd_sz)
1405 log_strd_sz = rxq->log_strd_sz;
1407 MLX5_ASSERT(log_strd_num && log_strd_sz);
1408 buf_len = RTE_BIT32(log_strd_num) * RTE_BIT32(log_strd_sz);
1409 obj_size = sizeof(struct mlx5_mprq_buf) + buf_len +
1410 RTE_BIT32(log_strd_num) *
1411 sizeof(struct rte_mbuf_ext_shared_info) +
1412 RTE_PKTMBUF_HEADROOM;
1414 * Received packets can be either memcpy'd or externally referenced. In
1415 * case that the packet is attached to an mbuf as an external buffer, as
1416 * it isn't possible to predict how the buffers will be queued by
1417 * application, there's no option to exactly pre-allocate needed buffers
1418 * in advance but to speculatively prepares enough buffers.
1420 * In the data path, if this Mempool is depleted, PMD will try to memcpy
1421 * received packets to buffers provided by application (rxq->mp) until
1422 * this Mempool gets available again.
1425 obj_num = desc + MLX5_MPRQ_MP_CACHE_SZ * n_ibv;
1427 * rte_mempool_create_empty() has sanity check to refuse large cache
1428 * size compared to the number of elements.
1429 * CACHE_FLUSHTHRESH_MULTIPLIER is defined in a C file, so using a
1430 * constant number 2 instead.
1432 obj_num = RTE_MAX(obj_num, MLX5_MPRQ_MP_CACHE_SZ * 2);
1433 /* Check a mempool is already allocated and if it can be resued. */
1434 if (mp != NULL && mp->elt_size >= obj_size && mp->size >= obj_num) {
1435 DRV_LOG(DEBUG, "port %u mempool %s is being reused",
1436 dev->data->port_id, mp->name);
1439 } else if (mp != NULL) {
1440 DRV_LOG(DEBUG, "port %u mempool %s should be resized, freeing it",
1441 dev->data->port_id, mp->name);
1443 * If failed to free, which means it may be still in use, no way
1444 * but to keep using the existing one. On buffer underrun,
1445 * packets will be memcpy'd instead of external buffer
1448 if (mlx5_mprq_free_mp(dev)) {
1449 if (mp->elt_size >= obj_size)
1455 snprintf(name, sizeof(name), "port-%u-mprq", dev->data->port_id);
1456 mp = rte_mempool_create(name, obj_num, obj_size, MLX5_MPRQ_MP_CACHE_SZ,
1457 0, NULL, NULL, mlx5_mprq_buf_init,
1458 (void *)((uintptr_t)1 << log_strd_num),
1459 dev->device->numa_node, 0);
1462 "port %u failed to allocate a mempool for"
1463 " Multi-Packet RQ, count=%u, size=%u",
1464 dev->data->port_id, obj_num, obj_size);
1468 ret = mlx5_mr_mempool_register(priv->sh->cdev, mp, false);
1469 if (ret < 0 && rte_errno != EEXIST) {
1471 DRV_LOG(ERR, "port %u failed to register a mempool for Multi-Packet RQ",
1472 dev->data->port_id);
1473 rte_mempool_free(mp);
1479 /* Set mempool for each Rx queue. */
1480 for (i = 0; i != priv->rxqs_n; ++i) {
1481 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
1483 if (rxq_ctrl == NULL ||
1484 rxq_ctrl->type != MLX5_RXQ_TYPE_STANDARD)
1486 rxq_ctrl->rxq.mprq_mp = mp;
1488 DRV_LOG(INFO, "port %u Multi-Packet RQ is configured",
1489 dev->data->port_id);
1493 #define MLX5_MAX_TCP_HDR_OFFSET ((unsigned int)(sizeof(struct rte_ether_hdr) + \
1494 sizeof(struct rte_vlan_hdr) * 2 + \
1495 sizeof(struct rte_ipv6_hdr)))
1496 #define MAX_TCP_OPTION_SIZE 40u
1497 #define MLX5_MAX_LRO_HEADER_FIX ((unsigned int)(MLX5_MAX_TCP_HDR_OFFSET + \
1498 sizeof(struct rte_tcp_hdr) + \
1499 MAX_TCP_OPTION_SIZE))
1502 * Adjust the maximum LRO massage size.
1505 * Pointer to Ethernet device.
1508 * @param max_lro_size
1509 * The maximum size for LRO packet.
1512 mlx5_max_lro_msg_size_adjust(struct rte_eth_dev *dev, uint16_t idx,
1513 uint32_t max_lro_size)
1515 struct mlx5_priv *priv = dev->data->dev_private;
1517 if (priv->sh->cdev->config.hca_attr.lro_max_msg_sz_mode ==
1518 MLX5_LRO_MAX_MSG_SIZE_START_FROM_L4 && max_lro_size >
1519 MLX5_MAX_TCP_HDR_OFFSET)
1520 max_lro_size -= MLX5_MAX_TCP_HDR_OFFSET;
1521 max_lro_size = RTE_MIN(max_lro_size, MLX5_MAX_LRO_SIZE);
1522 MLX5_ASSERT(max_lro_size >= MLX5_LRO_SEG_CHUNK_SIZE);
1523 max_lro_size /= MLX5_LRO_SEG_CHUNK_SIZE;
1524 if (priv->max_lro_msg_size)
1525 priv->max_lro_msg_size =
1526 RTE_MIN((uint32_t)priv->max_lro_msg_size, max_lro_size);
1528 priv->max_lro_msg_size = max_lro_size;
1530 "port %u Rx Queue %u max LRO message size adjusted to %u bytes",
1531 dev->data->port_id, idx,
1532 priv->max_lro_msg_size * MLX5_LRO_SEG_CHUNK_SIZE);
1536 * Prepare both size and number of stride for Multi-Packet RQ.
1539 * Pointer to Ethernet device.
1543 * Number of descriptors to configure in queue.
1545 * Indicator if Rx segment enables, if so Multi-Packet RQ doesn't enable.
1546 * @param min_mbuf_size
1547 * Non scatter min mbuf size, max_rx_pktlen plus overhead.
1548 * @param actual_log_stride_num
1549 * Log number of strides to configure for this queue.
1550 * @param actual_log_stride_size
1551 * Log stride size to configure for this queue.
1554 * 0 if Multi-Packet RQ is supported, otherwise -1.
1557 mlx5_mprq_prepare(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1558 bool rx_seg_en, uint32_t min_mbuf_size,
1559 uint32_t *actual_log_stride_num,
1560 uint32_t *actual_log_stride_size)
1562 struct mlx5_priv *priv = dev->data->dev_private;
1563 struct mlx5_port_config *config = &priv->config;
1564 struct mlx5_dev_cap *dev_cap = &priv->sh->dev_cap;
1565 uint32_t log_min_stride_num = dev_cap->mprq.log_min_stride_num;
1566 uint32_t log_max_stride_num = dev_cap->mprq.log_max_stride_num;
1567 uint32_t log_def_stride_num =
1568 RTE_MIN(RTE_MAX(MLX5_MPRQ_DEFAULT_LOG_STRIDE_NUM,
1569 log_min_stride_num),
1570 log_max_stride_num);
1571 uint32_t log_min_stride_size = dev_cap->mprq.log_min_stride_size;
1572 uint32_t log_max_stride_size = dev_cap->mprq.log_max_stride_size;
1573 uint32_t log_def_stride_size =
1574 RTE_MIN(RTE_MAX(MLX5_MPRQ_DEFAULT_LOG_STRIDE_SIZE,
1575 log_min_stride_size),
1576 log_max_stride_size);
1577 uint32_t log_stride_wqe_size;
1579 if (mlx5_check_mprq_support(dev) != 1 || rx_seg_en)
1581 /* Checks if chosen number of strides is in supported range. */
1582 if (config->mprq.log_stride_num > log_max_stride_num ||
1583 config->mprq.log_stride_num < log_min_stride_num) {
1584 *actual_log_stride_num = log_def_stride_num;
1586 "Port %u Rx queue %u number of strides for Multi-Packet RQ is out of range, setting default value (%u)",
1587 dev->data->port_id, idx, RTE_BIT32(log_def_stride_num));
1589 *actual_log_stride_num = config->mprq.log_stride_num;
1591 if (config->mprq.log_stride_size) {
1592 /* Checks if chosen size of stride is in supported range. */
1593 if (config->mprq.log_stride_size > log_max_stride_size ||
1594 config->mprq.log_stride_size < log_min_stride_size) {
1595 *actual_log_stride_size = log_def_stride_size;
1597 "Port %u Rx queue %u size of a stride for Multi-Packet RQ is out of range, setting default value (%u)",
1598 dev->data->port_id, idx,
1599 RTE_BIT32(log_def_stride_size));
1601 *actual_log_stride_size = config->mprq.log_stride_size;
1604 if (min_mbuf_size <= RTE_BIT32(log_max_stride_size))
1605 *actual_log_stride_size = log2above(min_mbuf_size);
1609 log_stride_wqe_size = *actual_log_stride_num + *actual_log_stride_size;
1610 /* Check if WQE buffer size is supported by hardware. */
1611 if (log_stride_wqe_size < dev_cap->mprq.log_min_stride_wqe_size) {
1612 *actual_log_stride_num = log_def_stride_num;
1613 *actual_log_stride_size = log_def_stride_size;
1615 "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)",
1616 dev->data->port_id, idx, RTE_BIT32(log_def_stride_num),
1617 RTE_BIT32(log_def_stride_size));
1618 log_stride_wqe_size = log_def_stride_num + log_def_stride_size;
1620 MLX5_ASSERT(log_stride_wqe_size >=
1621 dev_cap->mprq.log_min_stride_wqe_size);
1622 if (desc <= RTE_BIT32(*actual_log_stride_num))
1624 if (min_mbuf_size > RTE_BIT32(log_stride_wqe_size)) {
1625 DRV_LOG(WARNING, "Port %u Rx queue %u "
1626 "Multi-Packet RQ is unsupported, WQE buffer size (%u) "
1627 "is smaller than min mbuf size (%u)",
1628 dev->data->port_id, idx, RTE_BIT32(log_stride_wqe_size),
1632 DRV_LOG(DEBUG, "Port %u Rx queue %u "
1633 "Multi-Packet RQ is enabled strd_num_n = %u, strd_sz_n = %u",
1634 dev->data->port_id, idx, RTE_BIT32(*actual_log_stride_num),
1635 RTE_BIT32(*actual_log_stride_size));
1638 if (config->mprq.enabled)
1640 "Port %u MPRQ is requested but cannot be enabled\n"
1641 " (requested: pkt_sz = %u, desc_num = %u,"
1642 " rxq_num = %u, stride_sz = %u, stride_num = %u\n"
1643 " supported: min_rxqs_num = %u, min_buf_wqe_sz = %u"
1644 " min_stride_sz = %u, max_stride_sz = %u).\n"
1645 "Rx segment is %senable.",
1646 dev->data->port_id, min_mbuf_size, desc, priv->rxqs_n,
1647 RTE_BIT32(config->mprq.log_stride_size),
1648 RTE_BIT32(config->mprq.log_stride_num),
1649 config->mprq.min_rxqs_num,
1650 RTE_BIT32(dev_cap->mprq.log_min_stride_wqe_size),
1651 RTE_BIT32(dev_cap->mprq.log_min_stride_size),
1652 RTE_BIT32(dev_cap->mprq.log_max_stride_size),
1653 rx_seg_en ? "" : "not ");
1658 * Create a DPDK Rx queue.
1661 * Pointer to Ethernet device.
1665 * Number of descriptors to configure in queue.
1667 * NUMA socket on which memory must be allocated.
1670 * A DPDK queue object on success, NULL otherwise and rte_errno is set.
1672 struct mlx5_rxq_ctrl *
1673 mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1674 unsigned int socket, const struct rte_eth_rxconf *conf,
1675 const struct rte_eth_rxseg_split *rx_seg, uint16_t n_seg)
1677 struct mlx5_priv *priv = dev->data->dev_private;
1678 struct mlx5_rxq_ctrl *tmpl;
1679 unsigned int mb_len = rte_pktmbuf_data_room_size(rx_seg[0].mp);
1680 struct mlx5_port_config *config = &priv->config;
1681 uint64_t offloads = conf->offloads |
1682 dev->data->dev_conf.rxmode.offloads;
1683 unsigned int lro_on_queue = !!(offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO);
1684 unsigned int max_rx_pktlen = lro_on_queue ?
1685 dev->data->dev_conf.rxmode.max_lro_pkt_size :
1686 dev->data->mtu + (unsigned int)RTE_ETHER_HDR_LEN +
1688 unsigned int non_scatter_min_mbuf_size = max_rx_pktlen +
1689 RTE_PKTMBUF_HEADROOM;
1690 unsigned int max_lro_size = 0;
1691 unsigned int first_mb_free_size = mb_len - RTE_PKTMBUF_HEADROOM;
1692 uint32_t mprq_log_actual_stride_num = 0;
1693 uint32_t mprq_log_actual_stride_size = 0;
1694 bool rx_seg_en = n_seg != 1 || rx_seg[0].offset || rx_seg[0].length;
1695 const int mprq_en = !mlx5_mprq_prepare(dev, idx, desc, rx_seg_en,
1696 non_scatter_min_mbuf_size,
1697 &mprq_log_actual_stride_num,
1698 &mprq_log_actual_stride_size);
1700 * Always allocate extra slots, even if eventually
1701 * the vector Rx will not be used.
1703 uint16_t desc_n = desc + config->rx_vec_en * MLX5_VPMD_DESCS_PER_LOOP;
1704 size_t alloc_size = sizeof(*tmpl) + desc_n * sizeof(struct rte_mbuf *);
1705 const struct rte_eth_rxseg_split *qs_seg = rx_seg;
1706 unsigned int tail_len;
1709 /* Trim the number of descs needed. */
1710 desc >>= mprq_log_actual_stride_num;
1711 alloc_size += desc * sizeof(struct mlx5_mprq_buf *);
1713 tmpl = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, alloc_size, 0, socket);
1718 LIST_INIT(&tmpl->owners);
1719 MLX5_ASSERT(n_seg && n_seg <= MLX5_MAX_RXQ_NSEG);
1721 * Save the original segment configuration in the shared queue
1722 * descriptor for the later check on the sibling queue creation.
1724 tmpl->rxseg_n = n_seg;
1725 rte_memcpy(tmpl->rxseg, qs_seg,
1726 sizeof(struct rte_eth_rxseg_split) * n_seg);
1728 * Build the array of actual buffer offsets and lengths.
1729 * Pad with the buffers from the last memory pool if
1730 * needed to handle max size packets, replace zero length
1731 * with the buffer length from the pool.
1733 tail_len = max_rx_pktlen;
1735 struct mlx5_eth_rxseg *hw_seg =
1736 &tmpl->rxq.rxseg[tmpl->rxq.rxseg_n];
1737 uint32_t buf_len, offset, seg_len;
1740 * For the buffers beyond descriptions offset is zero,
1741 * the first buffer contains head room.
1743 buf_len = rte_pktmbuf_data_room_size(qs_seg->mp);
1744 offset = (tmpl->rxq.rxseg_n >= n_seg ? 0 : qs_seg->offset) +
1745 (tmpl->rxq.rxseg_n ? 0 : RTE_PKTMBUF_HEADROOM);
1747 * For the buffers beyond descriptions the length is
1748 * pool buffer length, zero lengths are replaced with
1749 * pool buffer length either.
1751 seg_len = tmpl->rxq.rxseg_n >= n_seg ? buf_len :
1755 /* Check is done in long int, now overflows. */
1756 if (buf_len < seg_len + offset) {
1757 DRV_LOG(ERR, "port %u Rx queue %u: Split offset/length "
1758 "%u/%u can't be satisfied",
1759 dev->data->port_id, idx,
1760 qs_seg->length, qs_seg->offset);
1764 if (seg_len > tail_len)
1765 seg_len = buf_len - offset;
1766 if (++tmpl->rxq.rxseg_n > MLX5_MAX_RXQ_NSEG) {
1768 "port %u too many SGEs (%u) needed to handle"
1769 " requested maximum packet size %u, the maximum"
1770 " supported are %u", dev->data->port_id,
1771 tmpl->rxq.rxseg_n, max_rx_pktlen,
1773 rte_errno = ENOTSUP;
1776 /* Build the actual scattering element in the queue object. */
1777 hw_seg->mp = qs_seg->mp;
1778 MLX5_ASSERT(offset <= UINT16_MAX);
1779 MLX5_ASSERT(seg_len <= UINT16_MAX);
1780 hw_seg->offset = (uint16_t)offset;
1781 hw_seg->length = (uint16_t)seg_len;
1783 * Advance the segment descriptor, the padding is the based
1784 * on the attributes of the last descriptor.
1786 if (tmpl->rxq.rxseg_n < n_seg)
1788 tail_len -= RTE_MIN(tail_len, seg_len);
1789 } while (tail_len || !rte_is_power_of_2(tmpl->rxq.rxseg_n));
1790 MLX5_ASSERT(tmpl->rxq.rxseg_n &&
1791 tmpl->rxq.rxseg_n <= MLX5_MAX_RXQ_NSEG);
1792 if (tmpl->rxq.rxseg_n > 1 && !(offloads & RTE_ETH_RX_OFFLOAD_SCATTER)) {
1793 DRV_LOG(ERR, "port %u Rx queue %u: Scatter offload is not"
1794 " configured and no enough mbuf space(%u) to contain "
1795 "the maximum RX packet length(%u) with head-room(%u)",
1796 dev->data->port_id, idx, mb_len, max_rx_pktlen,
1797 RTE_PKTMBUF_HEADROOM);
1801 tmpl->type = MLX5_RXQ_TYPE_STANDARD;
1802 if (mlx5_mr_ctrl_init(&tmpl->rxq.mr_ctrl,
1803 &priv->sh->cdev->mr_scache.dev_gen, socket)) {
1804 /* rte_errno is already set. */
1807 tmpl->socket = socket;
1808 if (dev->data->dev_conf.intr_conf.rxq)
1811 /* TODO: Rx scatter isn't supported yet. */
1812 tmpl->rxq.sges_n = 0;
1813 tmpl->rxq.log_strd_num = mprq_log_actual_stride_num;
1814 tmpl->rxq.log_strd_sz = mprq_log_actual_stride_size;
1815 tmpl->rxq.strd_shift_en = MLX5_MPRQ_TWO_BYTE_SHIFT;
1816 tmpl->rxq.strd_scatter_en =
1817 !!(offloads & RTE_ETH_RX_OFFLOAD_SCATTER);
1818 tmpl->rxq.mprq_max_memcpy_len = RTE_MIN(first_mb_free_size,
1819 config->mprq.max_memcpy_len);
1820 max_lro_size = RTE_MIN(max_rx_pktlen,
1821 RTE_BIT32(tmpl->rxq.log_strd_num) *
1822 RTE_BIT32(tmpl->rxq.log_strd_sz));
1823 } else if (tmpl->rxq.rxseg_n == 1) {
1824 MLX5_ASSERT(max_rx_pktlen <= first_mb_free_size);
1825 tmpl->rxq.sges_n = 0;
1826 max_lro_size = max_rx_pktlen;
1827 } else if (offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
1828 unsigned int sges_n;
1830 if (lro_on_queue && first_mb_free_size <
1831 MLX5_MAX_LRO_HEADER_FIX) {
1832 DRV_LOG(ERR, "Not enough space in the first segment(%u)"
1833 " to include the max header size(%u) for LRO",
1834 first_mb_free_size, MLX5_MAX_LRO_HEADER_FIX);
1835 rte_errno = ENOTSUP;
1839 * Determine the number of SGEs needed for a full packet
1840 * and round it to the next power of two.
1842 sges_n = log2above(tmpl->rxq.rxseg_n);
1843 if (sges_n > MLX5_MAX_LOG_RQ_SEGS) {
1845 "port %u too many SGEs (%u) needed to handle"
1846 " requested maximum packet size %u, the maximum"
1847 " supported are %u", dev->data->port_id,
1848 1 << sges_n, max_rx_pktlen,
1849 1u << MLX5_MAX_LOG_RQ_SEGS);
1850 rte_errno = ENOTSUP;
1853 tmpl->rxq.sges_n = sges_n;
1854 max_lro_size = max_rx_pktlen;
1856 DRV_LOG(DEBUG, "port %u maximum number of segments per packet: %u",
1857 dev->data->port_id, 1 << tmpl->rxq.sges_n);
1858 if (desc % (1 << tmpl->rxq.sges_n)) {
1860 "port %u number of Rx queue descriptors (%u) is not a"
1861 " multiple of SGEs per packet (%u)",
1864 1 << tmpl->rxq.sges_n);
1868 mlx5_max_lro_msg_size_adjust(dev, idx, max_lro_size);
1869 /* Toggle RX checksum offload if hardware supports it. */
1870 tmpl->rxq.csum = !!(offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM);
1871 /* Configure Rx timestamp. */
1872 tmpl->rxq.hw_timestamp = !!(offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP);
1873 tmpl->rxq.timestamp_rx_flag = 0;
1874 if (tmpl->rxq.hw_timestamp && rte_mbuf_dyn_rx_timestamp_register(
1875 &tmpl->rxq.timestamp_offset,
1876 &tmpl->rxq.timestamp_rx_flag) != 0) {
1877 DRV_LOG(ERR, "Cannot register Rx timestamp field/flag");
1880 /* Configure VLAN stripping. */
1881 tmpl->rxq.vlan_strip = !!(offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
1882 /* By default, FCS (CRC) is stripped by hardware. */
1883 tmpl->rxq.crc_present = 0;
1884 tmpl->rxq.lro = lro_on_queue;
1885 if (offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
1886 if (priv->sh->config.hw_fcs_strip) {
1888 * RQs used for LRO-enabled TIRs should not be
1889 * configured to scatter the FCS.
1893 "port %u CRC stripping has been "
1894 "disabled but will still be performed "
1895 "by hardware, because LRO is enabled",
1896 dev->data->port_id);
1898 tmpl->rxq.crc_present = 1;
1901 "port %u CRC stripping has been disabled but will"
1902 " still be performed by hardware, make sure MLNX_OFED"
1903 " and firmware are up to date",
1904 dev->data->port_id);
1908 "port %u CRC stripping is %s, %u bytes will be subtracted from"
1909 " incoming frames to hide it",
1911 tmpl->rxq.crc_present ? "disabled" : "enabled",
1912 tmpl->rxq.crc_present << 2);
1913 tmpl->rxq.rss_hash = !!priv->rss_conf.rss_hf &&
1914 (!!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS));
1916 tmpl->rxq.port_id = dev->data->port_id;
1917 tmpl->sh = priv->sh;
1918 tmpl->rxq.mp = rx_seg[0].mp;
1919 tmpl->rxq.elts_n = log2above(desc);
1920 tmpl->rxq.rq_repl_thresh = MLX5_VPMD_RXQ_RPLNSH_THRESH(desc_n);
1921 tmpl->rxq.elts = (struct rte_mbuf *(*)[desc_n])(tmpl + 1);
1922 tmpl->rxq.mprq_bufs =
1923 (struct mlx5_mprq_buf *(*)[desc])(*tmpl->rxq.elts + desc_n);
1924 tmpl->rxq.idx = idx;
1925 if (conf->share_group > 0) {
1926 tmpl->rxq.shared = 1;
1927 tmpl->share_group = conf->share_group;
1928 tmpl->share_qid = conf->share_qid;
1929 LIST_INSERT_HEAD(&priv->sh->shared_rxqs, tmpl, share_entry);
1931 LIST_INSERT_HEAD(&priv->rxqsctrl, tmpl, next);
1934 mlx5_mr_btree_free(&tmpl->rxq.mr_ctrl.cache_bh);
1940 * Create a DPDK Rx hairpin queue.
1943 * Pointer to Ethernet device.
1947 * Number of descriptors to configure in queue.
1948 * @param hairpin_conf
1949 * The hairpin binding configuration.
1952 * A DPDK queue object on success, NULL otherwise and rte_errno is set.
1954 struct mlx5_rxq_ctrl *
1955 mlx5_rxq_hairpin_new(struct rte_eth_dev *dev, struct mlx5_rxq_priv *rxq,
1957 const struct rte_eth_hairpin_conf *hairpin_conf)
1959 uint16_t idx = rxq->idx;
1960 struct mlx5_priv *priv = dev->data->dev_private;
1961 struct mlx5_rxq_ctrl *tmpl;
1963 tmpl = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, sizeof(*tmpl), 0,
1969 LIST_INIT(&tmpl->owners);
1971 LIST_INSERT_HEAD(&tmpl->owners, rxq, owner_entry);
1972 tmpl->type = MLX5_RXQ_TYPE_HAIRPIN;
1973 tmpl->socket = SOCKET_ID_ANY;
1974 tmpl->rxq.rss_hash = 0;
1975 tmpl->rxq.port_id = dev->data->port_id;
1976 tmpl->sh = priv->sh;
1977 tmpl->rxq.mp = NULL;
1978 tmpl->rxq.elts_n = log2above(desc);
1979 tmpl->rxq.elts = NULL;
1980 tmpl->rxq.mr_ctrl.cache_bh = (struct mlx5_mr_btree) { 0 };
1981 tmpl->rxq.idx = idx;
1982 rxq->hairpin_conf = *hairpin_conf;
1983 mlx5_rxq_ref(dev, idx);
1984 LIST_INSERT_HEAD(&priv->rxqsctrl, tmpl, next);
1989 * Increase Rx queue reference count.
1992 * Pointer to Ethernet device.
1997 * A pointer to the queue if it exists, NULL otherwise.
1999 struct mlx5_rxq_priv *
2000 mlx5_rxq_ref(struct rte_eth_dev *dev, uint16_t idx)
2002 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
2005 __atomic_fetch_add(&rxq->refcnt, 1, __ATOMIC_RELAXED);
2010 * Dereference a Rx queue.
2013 * Pointer to Ethernet device.
2018 * Updated reference count.
2021 mlx5_rxq_deref(struct rte_eth_dev *dev, uint16_t idx)
2023 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
2027 return __atomic_sub_fetch(&rxq->refcnt, 1, __ATOMIC_RELAXED);
2034 * Pointer to Ethernet device.
2039 * A pointer to the queue if it exists, NULL otherwise.
2041 struct mlx5_rxq_priv *
2042 mlx5_rxq_get(struct rte_eth_dev *dev, uint16_t idx)
2044 struct mlx5_priv *priv = dev->data->dev_private;
2046 MLX5_ASSERT(priv->rxq_privs != NULL);
2047 return (*priv->rxq_privs)[idx];
2051 * Get Rx queue shareable control.
2054 * Pointer to Ethernet device.
2059 * A pointer to the queue control if it exists, NULL otherwise.
2061 struct mlx5_rxq_ctrl *
2062 mlx5_rxq_ctrl_get(struct rte_eth_dev *dev, uint16_t idx)
2064 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
2066 return rxq == NULL ? NULL : rxq->ctrl;
2070 * Get Rx queue shareable data.
2073 * Pointer to Ethernet device.
2078 * A pointer to the queue data if it exists, NULL otherwise.
2080 struct mlx5_rxq_data *
2081 mlx5_rxq_data_get(struct rte_eth_dev *dev, uint16_t idx)
2083 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
2085 return rxq == NULL ? NULL : &rxq->ctrl->rxq;
2089 * Release a Rx queue.
2092 * Pointer to Ethernet device.
2097 * 1 while a reference on it exists, 0 when freed.
2100 mlx5_rxq_release(struct rte_eth_dev *dev, uint16_t idx)
2102 struct mlx5_priv *priv = dev->data->dev_private;
2103 struct mlx5_rxq_priv *rxq;
2104 struct mlx5_rxq_ctrl *rxq_ctrl;
2107 if (priv->rxq_privs == NULL)
2109 rxq = mlx5_rxq_get(dev, idx);
2110 if (rxq == NULL || rxq->refcnt == 0)
2112 rxq_ctrl = rxq->ctrl;
2113 refcnt = mlx5_rxq_deref(dev, idx);
2116 } else if (refcnt == 1) { /* RxQ stopped. */
2117 priv->obj_ops.rxq_obj_release(rxq);
2118 if (!rxq_ctrl->started && rxq_ctrl->obj != NULL) {
2119 LIST_REMOVE(rxq_ctrl->obj, next);
2120 mlx5_free(rxq_ctrl->obj);
2121 rxq_ctrl->obj = NULL;
2123 if (rxq_ctrl->type == MLX5_RXQ_TYPE_STANDARD) {
2124 if (!rxq_ctrl->started)
2125 rxq_free_elts(rxq_ctrl);
2126 dev->data->rx_queue_state[idx] =
2127 RTE_ETH_QUEUE_STATE_STOPPED;
2129 } else { /* Refcnt zero, closing device. */
2130 LIST_REMOVE(rxq, owner_entry);
2131 if (LIST_EMPTY(&rxq_ctrl->owners)) {
2132 if (rxq_ctrl->type == MLX5_RXQ_TYPE_STANDARD)
2134 (&rxq_ctrl->rxq.mr_ctrl.cache_bh);
2135 if (rxq_ctrl->rxq.shared)
2136 LIST_REMOVE(rxq_ctrl, share_entry);
2137 LIST_REMOVE(rxq_ctrl, next);
2138 mlx5_free(rxq_ctrl);
2140 dev->data->rx_queues[idx] = NULL;
2142 (*priv->rxq_privs)[idx] = NULL;
2148 * Verify the Rx Queue list is empty
2151 * Pointer to Ethernet device.
2154 * The number of object not released.
2157 mlx5_rxq_verify(struct rte_eth_dev *dev)
2159 struct mlx5_priv *priv = dev->data->dev_private;
2160 struct mlx5_rxq_ctrl *rxq_ctrl;
2163 LIST_FOREACH(rxq_ctrl, &priv->rxqsctrl, next) {
2164 DRV_LOG(DEBUG, "port %u Rx Queue %u still referenced",
2165 dev->data->port_id, rxq_ctrl->rxq.idx);
2172 * Get a Rx queue type.
2175 * Pointer to Ethernet device.
2180 * The Rx queue type.
2183 mlx5_rxq_get_type(struct rte_eth_dev *dev, uint16_t idx)
2185 struct mlx5_priv *priv = dev->data->dev_private;
2186 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
2188 if (idx < priv->rxqs_n && rxq_ctrl != NULL)
2189 return rxq_ctrl->type;
2190 return MLX5_RXQ_TYPE_UNDEFINED;
2194 * Get a Rx hairpin queue configuration.
2197 * Pointer to Ethernet device.
2202 * Pointer to the configuration if a hairpin RX queue, otherwise NULL.
2204 const struct rte_eth_hairpin_conf *
2205 mlx5_rxq_get_hairpin_conf(struct rte_eth_dev *dev, uint16_t idx)
2207 struct mlx5_priv *priv = dev->data->dev_private;
2208 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
2210 if (idx < priv->rxqs_n && rxq != NULL) {
2211 if (rxq->ctrl->type == MLX5_RXQ_TYPE_HAIRPIN)
2212 return &rxq->hairpin_conf;
2218 * Match queues listed in arguments to queues contained in indirection table
2222 * Pointer to indirection table to match.
2224 * Queues to match to ques in indirection table.
2226 * Number of queues in the array.
2229 * 1 if all queues in indirection table match 0 otherwise.
2232 mlx5_ind_table_obj_match_queues(const struct mlx5_ind_table_obj *ind_tbl,
2233 const uint16_t *queues, uint32_t queues_n)
2235 return (ind_tbl->queues_n == queues_n) &&
2236 (!memcmp(ind_tbl->queues, queues,
2237 ind_tbl->queues_n * sizeof(ind_tbl->queues[0])));
2241 * Get an indirection table.
2244 * Pointer to Ethernet device.
2246 * Queues entering in the indirection table.
2248 * Number of queues in the array.
2251 * An indirection table if found.
2253 struct mlx5_ind_table_obj *
2254 mlx5_ind_table_obj_get(struct rte_eth_dev *dev, const uint16_t *queues,
2257 struct mlx5_priv *priv = dev->data->dev_private;
2258 struct mlx5_ind_table_obj *ind_tbl;
2260 rte_rwlock_read_lock(&priv->ind_tbls_lock);
2261 LIST_FOREACH(ind_tbl, &priv->ind_tbls, next) {
2262 if ((ind_tbl->queues_n == queues_n) &&
2263 (memcmp(ind_tbl->queues, queues,
2264 ind_tbl->queues_n * sizeof(ind_tbl->queues[0]))
2266 __atomic_fetch_add(&ind_tbl->refcnt, 1,
2271 rte_rwlock_read_unlock(&priv->ind_tbls_lock);
2276 * Release an indirection table.
2279 * Pointer to Ethernet device.
2281 * Indirection table to release.
2283 * Indirection table for Standalone queue.
2285 * If true, then dereference RX queues related to indirection table.
2286 * Otherwise, no additional action will be taken.
2289 * 1 while a reference on it exists, 0 when freed.
2292 mlx5_ind_table_obj_release(struct rte_eth_dev *dev,
2293 struct mlx5_ind_table_obj *ind_tbl,
2297 struct mlx5_priv *priv = dev->data->dev_private;
2298 unsigned int i, ret;
2300 rte_rwlock_write_lock(&priv->ind_tbls_lock);
2301 ret = __atomic_sub_fetch(&ind_tbl->refcnt, 1, __ATOMIC_RELAXED);
2302 if (!ret && !standalone)
2303 LIST_REMOVE(ind_tbl, next);
2304 rte_rwlock_write_unlock(&priv->ind_tbls_lock);
2307 priv->obj_ops.ind_table_destroy(ind_tbl);
2309 for (i = 0; i != ind_tbl->queues_n; ++i)
2310 claim_nonzero(mlx5_rxq_deref(dev, ind_tbl->queues[i]));
2317 * Verify the Rx Queue list is empty
2320 * Pointer to Ethernet device.
2323 * The number of object not released.
2326 mlx5_ind_table_obj_verify(struct rte_eth_dev *dev)
2328 struct mlx5_priv *priv = dev->data->dev_private;
2329 struct mlx5_ind_table_obj *ind_tbl;
2332 rte_rwlock_read_lock(&priv->ind_tbls_lock);
2333 LIST_FOREACH(ind_tbl, &priv->ind_tbls, next) {
2335 "port %u indirection table obj %p still referenced",
2336 dev->data->port_id, (void *)ind_tbl);
2339 rte_rwlock_read_unlock(&priv->ind_tbls_lock);
2344 * Setup an indirection table structure fields.
2347 * Pointer to Ethernet device.
2349 * Indirection table to modify.
2351 * Whether to increment RxQ reference counters.
2354 * 0 on success, a negative errno value otherwise and rte_errno is set.
2357 mlx5_ind_table_obj_setup(struct rte_eth_dev *dev,
2358 struct mlx5_ind_table_obj *ind_tbl,
2361 struct mlx5_priv *priv = dev->data->dev_private;
2362 uint32_t queues_n = ind_tbl->queues_n;
2363 uint16_t *queues = ind_tbl->queues;
2364 unsigned int i = 0, j;
2366 const unsigned int n = rte_is_power_of_2(queues_n) ?
2367 log2above(queues_n) :
2368 log2above(priv->sh->dev_cap.ind_table_max_size);
2371 for (i = 0; i != queues_n; ++i) {
2372 if (mlx5_rxq_ref(dev, queues[i]) == NULL) {
2377 ret = priv->obj_ops.ind_table_new(dev, n, ind_tbl);
2380 __atomic_fetch_add(&ind_tbl->refcnt, 1, __ATOMIC_RELAXED);
2385 for (j = 0; j < i; j++)
2386 mlx5_rxq_deref(dev, queues[j]);
2389 DRV_LOG(DEBUG, "Port %u cannot setup indirection table.",
2390 dev->data->port_id);
2395 * Create an indirection table.
2398 * Pointer to Ethernet device.
2400 * Queues entering in the indirection table.
2402 * Number of queues in the array.
2404 * Indirection table for Standalone queue.
2406 * Whether to increment RxQ reference counters.
2409 * The Verbs/DevX object initialized, NULL otherwise and rte_errno is set.
2411 static struct mlx5_ind_table_obj *
2412 mlx5_ind_table_obj_new(struct rte_eth_dev *dev, const uint16_t *queues,
2413 uint32_t queues_n, bool standalone, bool ref_qs)
2415 struct mlx5_priv *priv = dev->data->dev_private;
2416 struct mlx5_ind_table_obj *ind_tbl;
2419 ind_tbl = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*ind_tbl) +
2420 queues_n * sizeof(uint16_t), 0, SOCKET_ID_ANY);
2425 ind_tbl->queues_n = queues_n;
2426 ind_tbl->queues = (uint16_t *)(ind_tbl + 1);
2427 memcpy(ind_tbl->queues, queues, queues_n * sizeof(*queues));
2428 ret = mlx5_ind_table_obj_setup(dev, ind_tbl, ref_qs);
2434 rte_rwlock_write_lock(&priv->ind_tbls_lock);
2435 LIST_INSERT_HEAD(&priv->ind_tbls, ind_tbl, next);
2436 rte_rwlock_write_unlock(&priv->ind_tbls_lock);
2442 mlx5_ind_table_obj_check_standalone(struct rte_eth_dev *dev __rte_unused,
2443 struct mlx5_ind_table_obj *ind_tbl)
2447 refcnt = __atomic_load_n(&ind_tbl->refcnt, __ATOMIC_RELAXED);
2451 * Modification of indirection tables having more than 1
2452 * reference is unsupported.
2455 "Port %u cannot modify indirection table %p (refcnt %u > 1).",
2456 dev->data->port_id, (void *)ind_tbl, refcnt);
2462 * Modify an indirection table.
2465 * Pointer to Ethernet device.
2467 * Indirection table to modify.
2469 * Queues replacement for the indirection table.
2471 * Number of queues in the array.
2473 * Indirection table for Standalone queue.
2475 * Whether to increment new RxQ set reference counters.
2476 * @param deref_old_qs
2477 * Whether to decrement old RxQ set reference counters.
2480 * 0 on success, a negative errno value otherwise and rte_errno is set.
2483 mlx5_ind_table_obj_modify(struct rte_eth_dev *dev,
2484 struct mlx5_ind_table_obj *ind_tbl,
2485 uint16_t *queues, const uint32_t queues_n,
2486 bool standalone, bool ref_new_qs, bool deref_old_qs)
2488 struct mlx5_priv *priv = dev->data->dev_private;
2489 unsigned int i = 0, j;
2491 const unsigned int n = rte_is_power_of_2(queues_n) ?
2492 log2above(queues_n) :
2493 log2above(priv->sh->dev_cap.ind_table_max_size);
2495 MLX5_ASSERT(standalone);
2496 RTE_SET_USED(standalone);
2497 if (mlx5_ind_table_obj_check_standalone(dev, ind_tbl) < 0)
2500 for (i = 0; i != queues_n; ++i) {
2501 if (!mlx5_rxq_ref(dev, queues[i])) {
2506 MLX5_ASSERT(priv->obj_ops.ind_table_modify);
2507 ret = priv->obj_ops.ind_table_modify(dev, n, queues, queues_n, ind_tbl);
2511 for (i = 0; i < ind_tbl->queues_n; i++)
2512 claim_nonzero(mlx5_rxq_deref(dev, ind_tbl->queues[i]));
2513 ind_tbl->queues_n = queues_n;
2514 ind_tbl->queues = queues;
2519 for (j = 0; j < i; j++)
2520 mlx5_rxq_deref(dev, queues[j]);
2523 DRV_LOG(DEBUG, "Port %u cannot setup indirection table.",
2524 dev->data->port_id);
2529 * Attach an indirection table to its queues.
2532 * Pointer to Ethernet device.
2534 * Indirection table to attach.
2537 * 0 on success, a negative errno value otherwise and rte_errno is set.
2540 mlx5_ind_table_obj_attach(struct rte_eth_dev *dev,
2541 struct mlx5_ind_table_obj *ind_tbl)
2545 ret = mlx5_ind_table_obj_modify(dev, ind_tbl, ind_tbl->queues,
2547 true /* standalone */,
2548 true /* ref_new_qs */,
2549 false /* deref_old_qs */);
2551 DRV_LOG(ERR, "Port %u could not modify indirect table obj %p",
2552 dev->data->port_id, (void *)ind_tbl);
2557 * Detach an indirection table from its queues.
2560 * Pointer to Ethernet device.
2562 * Indirection table to detach.
2565 * 0 on success, a negative errno value otherwise and rte_errno is set.
2568 mlx5_ind_table_obj_detach(struct rte_eth_dev *dev,
2569 struct mlx5_ind_table_obj *ind_tbl)
2571 struct mlx5_priv *priv = dev->data->dev_private;
2572 const unsigned int n = rte_is_power_of_2(ind_tbl->queues_n) ?
2573 log2above(ind_tbl->queues_n) :
2574 log2above(priv->sh->dev_cap.ind_table_max_size);
2578 ret = mlx5_ind_table_obj_check_standalone(dev, ind_tbl);
2581 MLX5_ASSERT(priv->obj_ops.ind_table_modify);
2582 ret = priv->obj_ops.ind_table_modify(dev, n, NULL, 0, ind_tbl);
2584 DRV_LOG(ERR, "Port %u could not modify indirect table obj %p",
2585 dev->data->port_id, (void *)ind_tbl);
2588 for (i = 0; i < ind_tbl->queues_n; i++)
2589 mlx5_rxq_release(dev, ind_tbl->queues[i]);
2594 mlx5_hrxq_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
2597 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
2598 struct mlx5_flow_rss_desc *rss_desc = ctx->data;
2599 struct mlx5_hrxq *hrxq = container_of(entry, typeof(*hrxq), entry);
2601 return (hrxq->rss_key_len != rss_desc->key_len ||
2602 memcmp(hrxq->rss_key, rss_desc->key, rss_desc->key_len) ||
2603 hrxq->hash_fields != rss_desc->hash_fields ||
2604 hrxq->ind_table->queues_n != rss_desc->queue_num ||
2605 memcmp(hrxq->ind_table->queues, rss_desc->queue,
2606 rss_desc->queue_num * sizeof(rss_desc->queue[0])));
2610 * Modify an Rx Hash queue configuration.
2613 * Pointer to Ethernet device.
2615 * Index to Hash Rx queue to modify.
2617 * RSS key for the Rx hash queue.
2618 * @param rss_key_len
2620 * @param hash_fields
2621 * Verbs protocol hash field to make the RSS on.
2623 * Queues entering in hash queue. In case of empty hash_fields only the
2624 * first queue index will be taken for the indirection table.
2629 * 0 on success, a negative errno value otherwise and rte_errno is set.
2632 mlx5_hrxq_modify(struct rte_eth_dev *dev, uint32_t hrxq_idx,
2633 const uint8_t *rss_key, uint32_t rss_key_len,
2634 uint64_t hash_fields,
2635 const uint16_t *queues, uint32_t queues_n)
2638 struct mlx5_ind_table_obj *ind_tbl = NULL;
2639 struct mlx5_priv *priv = dev->data->dev_private;
2640 struct mlx5_hrxq *hrxq =
2641 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
2642 bool dev_started = !!dev->data->dev_started;
2650 if (hrxq->rss_key_len != rss_key_len) {
2651 /* rss_key_len is fixed size 40 byte & not supposed to change */
2655 queues_n = hash_fields ? queues_n : 1;
2656 if (mlx5_ind_table_obj_match_queues(hrxq->ind_table,
2657 queues, queues_n)) {
2658 ind_tbl = hrxq->ind_table;
2660 if (hrxq->standalone) {
2662 * Replacement of indirection table unsupported for
2663 * standalone hrxq objects (used by shared RSS).
2665 rte_errno = ENOTSUP;
2668 ind_tbl = mlx5_ind_table_obj_get(dev, queues, queues_n);
2670 ind_tbl = mlx5_ind_table_obj_new(dev, queues, queues_n,
2678 MLX5_ASSERT(priv->obj_ops.hrxq_modify);
2679 ret = priv->obj_ops.hrxq_modify(dev, hrxq, rss_key,
2680 hash_fields, ind_tbl);
2685 if (ind_tbl != hrxq->ind_table) {
2686 MLX5_ASSERT(!hrxq->standalone);
2687 mlx5_ind_table_obj_release(dev, hrxq->ind_table,
2688 hrxq->standalone, true);
2689 hrxq->ind_table = ind_tbl;
2691 hrxq->hash_fields = hash_fields;
2692 memcpy(hrxq->rss_key, rss_key, rss_key_len);
2696 if (ind_tbl != hrxq->ind_table) {
2697 MLX5_ASSERT(!hrxq->standalone);
2698 mlx5_ind_table_obj_release(dev, ind_tbl, hrxq->standalone,
2706 __mlx5_hrxq_remove(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq)
2708 struct mlx5_priv *priv = dev->data->dev_private;
2710 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
2711 mlx5_glue->destroy_flow_action(hrxq->action);
2713 priv->obj_ops.hrxq_destroy(hrxq);
2714 if (!hrxq->standalone) {
2715 mlx5_ind_table_obj_release(dev, hrxq->ind_table,
2716 hrxq->standalone, true);
2718 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq->idx);
2722 * Release the hash Rx queue.
2725 * Pointer to Ethernet device.
2727 * Index to Hash Rx queue to release.
2730 * mlx5 list pointer.
2732 * Hash queue entry pointer.
2735 mlx5_hrxq_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
2737 struct rte_eth_dev *dev = tool_ctx;
2738 struct mlx5_hrxq *hrxq = container_of(entry, typeof(*hrxq), entry);
2740 __mlx5_hrxq_remove(dev, hrxq);
2743 static struct mlx5_hrxq *
2744 __mlx5_hrxq_create(struct rte_eth_dev *dev,
2745 struct mlx5_flow_rss_desc *rss_desc)
2747 struct mlx5_priv *priv = dev->data->dev_private;
2748 const uint8_t *rss_key = rss_desc->key;
2749 uint32_t rss_key_len = rss_desc->key_len;
2750 bool standalone = !!rss_desc->shared_rss;
2751 const uint16_t *queues =
2752 standalone ? rss_desc->const_q : rss_desc->queue;
2753 uint32_t queues_n = rss_desc->queue_num;
2754 struct mlx5_hrxq *hrxq = NULL;
2755 uint32_t hrxq_idx = 0;
2756 struct mlx5_ind_table_obj *ind_tbl = rss_desc->ind_tbl;
2759 queues_n = rss_desc->hash_fields ? queues_n : 1;
2761 ind_tbl = mlx5_ind_table_obj_get(dev, queues, queues_n);
2763 ind_tbl = mlx5_ind_table_obj_new(dev, queues, queues_n,
2765 !!dev->data->dev_started);
2768 hrxq = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_HRXQ], &hrxq_idx);
2771 hrxq->standalone = standalone;
2772 hrxq->idx = hrxq_idx;
2773 hrxq->ind_table = ind_tbl;
2774 hrxq->rss_key_len = rss_key_len;
2775 hrxq->hash_fields = rss_desc->hash_fields;
2776 memcpy(hrxq->rss_key, rss_key, rss_key_len);
2777 ret = priv->obj_ops.hrxq_new(dev, hrxq, rss_desc->tunnel);
2782 if (!rss_desc->ind_tbl)
2783 mlx5_ind_table_obj_release(dev, ind_tbl, standalone, true);
2785 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
2789 struct mlx5_list_entry *
2790 mlx5_hrxq_create_cb(void *tool_ctx, void *cb_ctx)
2792 struct rte_eth_dev *dev = tool_ctx;
2793 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
2794 struct mlx5_flow_rss_desc *rss_desc = ctx->data;
2795 struct mlx5_hrxq *hrxq;
2797 hrxq = __mlx5_hrxq_create(dev, rss_desc);
2798 return hrxq ? &hrxq->entry : NULL;
2801 struct mlx5_list_entry *
2802 mlx5_hrxq_clone_cb(void *tool_ctx, struct mlx5_list_entry *entry,
2803 void *cb_ctx __rte_unused)
2805 struct rte_eth_dev *dev = tool_ctx;
2806 struct mlx5_priv *priv = dev->data->dev_private;
2807 struct mlx5_hrxq *hrxq;
2808 uint32_t hrxq_idx = 0;
2810 hrxq = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_HRXQ], &hrxq_idx);
2813 memcpy(hrxq, entry, sizeof(*hrxq) + MLX5_RSS_HASH_KEY_LEN);
2814 hrxq->idx = hrxq_idx;
2815 return &hrxq->entry;
2819 mlx5_hrxq_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
2821 struct rte_eth_dev *dev = tool_ctx;
2822 struct mlx5_priv *priv = dev->data->dev_private;
2823 struct mlx5_hrxq *hrxq = container_of(entry, typeof(*hrxq), entry);
2825 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq->idx);
2829 * Get an Rx Hash queue.
2832 * Pointer to Ethernet device.
2834 * RSS configuration for the Rx hash queue.
2837 * An hash Rx queue index on success.
2839 uint32_t mlx5_hrxq_get(struct rte_eth_dev *dev,
2840 struct mlx5_flow_rss_desc *rss_desc)
2842 struct mlx5_priv *priv = dev->data->dev_private;
2843 struct mlx5_hrxq *hrxq;
2844 struct mlx5_list_entry *entry;
2845 struct mlx5_flow_cb_ctx ctx = {
2849 if (rss_desc->shared_rss) {
2850 hrxq = __mlx5_hrxq_create(dev, rss_desc);
2852 entry = mlx5_list_register(priv->hrxqs, &ctx);
2855 hrxq = container_of(entry, typeof(*hrxq), entry);
2863 * Release the hash Rx queue.
2866 * Pointer to Ethernet device.
2868 * Index to Hash Rx queue to release.
2871 * 1 while a reference on it exists, 0 when freed.
2873 int mlx5_hrxq_release(struct rte_eth_dev *dev, uint32_t hrxq_idx)
2875 struct mlx5_priv *priv = dev->data->dev_private;
2876 struct mlx5_hrxq *hrxq;
2878 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
2881 if (!hrxq->standalone)
2882 return mlx5_list_unregister(priv->hrxqs, &hrxq->entry);
2883 __mlx5_hrxq_remove(dev, hrxq);
2888 * Create a drop Rx Hash queue.
2891 * Pointer to Ethernet device.
2894 * The Verbs/DevX object initialized, NULL otherwise and rte_errno is set.
2897 mlx5_drop_action_create(struct rte_eth_dev *dev)
2899 struct mlx5_priv *priv = dev->data->dev_private;
2900 struct mlx5_hrxq *hrxq = NULL;
2903 if (priv->drop_queue.hrxq)
2904 return priv->drop_queue.hrxq;
2905 hrxq = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*hrxq), 0, SOCKET_ID_ANY);
2908 "Port %u cannot allocate memory for drop queue.",
2909 dev->data->port_id);
2913 priv->drop_queue.hrxq = hrxq;
2914 hrxq->ind_table = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*hrxq->ind_table),
2916 if (!hrxq->ind_table) {
2920 ret = priv->obj_ops.drop_action_create(dev);
2926 if (hrxq->ind_table)
2927 mlx5_free(hrxq->ind_table);
2928 priv->drop_queue.hrxq = NULL;
2935 * Release a drop hash Rx queue.
2938 * Pointer to Ethernet device.
2941 mlx5_drop_action_destroy(struct rte_eth_dev *dev)
2943 struct mlx5_priv *priv = dev->data->dev_private;
2944 struct mlx5_hrxq *hrxq = priv->drop_queue.hrxq;
2946 if (!priv->drop_queue.hrxq)
2948 priv->obj_ops.drop_action_destroy(dev);
2949 mlx5_free(priv->drop_queue.rxq);
2950 mlx5_free(hrxq->ind_table);
2952 priv->drop_queue.rxq = NULL;
2953 priv->drop_queue.hrxq = NULL;
2957 * Verify the Rx Queue list is empty
2960 * Pointer to Ethernet device.
2963 * The number of object not released.
2966 mlx5_hrxq_verify(struct rte_eth_dev *dev)
2968 struct mlx5_priv *priv = dev->data->dev_private;
2970 return mlx5_list_get_entry_num(priv->hrxqs);
2974 * Set the Rx queue timestamp conversion parameters
2977 * Pointer to the Ethernet device structure.
2980 mlx5_rxq_timestamp_set(struct rte_eth_dev *dev)
2982 struct mlx5_priv *priv = dev->data->dev_private;
2983 struct mlx5_dev_ctx_shared *sh = priv->sh;
2986 for (i = 0; i != priv->rxqs_n; ++i) {
2987 struct mlx5_rxq_data *data = mlx5_rxq_data_get(dev, i);
2992 data->rt_timestamp = sh->dev_cap.rt_timestamp;