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 <rte_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_devx_cmds.h>
24 #include <mlx5_malloc.h>
26 #include "mlx5_defs.h"
28 #include "mlx5_common_os.h"
29 #include "mlx5_rxtx.h"
30 #include "mlx5_utils.h"
31 #include "mlx5_autoconf.h"
32 #include "mlx5_flow.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 * Check whether Multi-Packet RQ can be enabled for the device.
58 * Pointer to Ethernet device.
61 * 1 if supported, negative errno value if not.
64 mlx5_check_mprq_support(struct rte_eth_dev *dev)
66 struct mlx5_priv *priv = dev->data->dev_private;
68 if (priv->config.mprq.enabled &&
69 priv->rxqs_n >= priv->config.mprq.min_rxqs_num)
75 * Check whether Multi-Packet RQ is enabled for the Rx queue.
78 * Pointer to receive queue structure.
81 * 0 if disabled, otherwise enabled.
84 mlx5_rxq_mprq_enabled(struct mlx5_rxq_data *rxq)
86 return rxq->strd_num_n > 0;
90 * Check whether Multi-Packet RQ is enabled for the device.
93 * Pointer to Ethernet device.
96 * 0 if disabled, otherwise enabled.
99 mlx5_mprq_enabled(struct rte_eth_dev *dev)
101 struct mlx5_priv *priv = dev->data->dev_private;
106 if (mlx5_check_mprq_support(dev) < 0)
108 /* All the configured queues should be enabled. */
109 for (i = 0; i < priv->rxqs_n; ++i) {
110 struct mlx5_rxq_data *rxq = (*priv->rxqs)[i];
111 struct mlx5_rxq_ctrl *rxq_ctrl = container_of
112 (rxq, struct mlx5_rxq_ctrl, rxq);
114 if (rxq == NULL || rxq_ctrl->type != MLX5_RXQ_TYPE_STANDARD)
117 if (mlx5_rxq_mprq_enabled(rxq))
120 /* Multi-Packet RQ can't be partially configured. */
121 MLX5_ASSERT(n == 0 || n == n_ibv);
126 * Allocate RX queue elements for Multi-Packet RQ.
129 * Pointer to RX queue structure.
132 * 0 on success, a negative errno value otherwise and rte_errno is set.
135 rxq_alloc_elts_mprq(struct mlx5_rxq_ctrl *rxq_ctrl)
137 struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
138 unsigned int wqe_n = 1 << rxq->elts_n;
142 /* Iterate on segments. */
143 for (i = 0; i <= wqe_n; ++i) {
144 struct mlx5_mprq_buf *buf;
146 if (rte_mempool_get(rxq->mprq_mp, (void **)&buf) < 0) {
147 DRV_LOG(ERR, "port %u empty mbuf pool", rxq->port_id);
152 (*rxq->mprq_bufs)[i] = buf;
154 rxq->mprq_repl = buf;
157 "port %u Rx queue %u allocated and configured %u segments",
158 rxq->port_id, rxq->idx, wqe_n);
161 err = rte_errno; /* Save rte_errno before cleanup. */
163 for (i = 0; (i != wqe_n); ++i) {
164 if ((*rxq->mprq_bufs)[i] != NULL)
165 rte_mempool_put(rxq->mprq_mp,
166 (*rxq->mprq_bufs)[i]);
167 (*rxq->mprq_bufs)[i] = NULL;
169 DRV_LOG(DEBUG, "port %u Rx queue %u failed, freed everything",
170 rxq->port_id, rxq->idx);
171 rte_errno = err; /* Restore rte_errno. */
176 * Allocate RX queue elements for Single-Packet RQ.
179 * Pointer to RX queue structure.
182 * 0 on success, errno value on failure.
185 rxq_alloc_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
187 const unsigned int sges_n = 1 << rxq_ctrl->rxq.sges_n;
188 unsigned int elts_n = 1 << rxq_ctrl->rxq.elts_n;
192 /* Iterate on segments. */
193 for (i = 0; (i != elts_n); ++i) {
194 struct rte_mbuf *buf;
196 buf = rte_pktmbuf_alloc(rxq_ctrl->rxq.mp);
198 DRV_LOG(ERR, "port %u empty mbuf pool",
199 PORT_ID(rxq_ctrl->priv));
203 /* Headroom is reserved by rte_pktmbuf_alloc(). */
204 MLX5_ASSERT(DATA_OFF(buf) == RTE_PKTMBUF_HEADROOM);
205 /* Buffer is supposed to be empty. */
206 MLX5_ASSERT(rte_pktmbuf_data_len(buf) == 0);
207 MLX5_ASSERT(rte_pktmbuf_pkt_len(buf) == 0);
208 MLX5_ASSERT(!buf->next);
209 /* Only the first segment keeps headroom. */
211 SET_DATA_OFF(buf, 0);
212 PORT(buf) = rxq_ctrl->rxq.port_id;
213 DATA_LEN(buf) = rte_pktmbuf_tailroom(buf);
214 PKT_LEN(buf) = DATA_LEN(buf);
216 (*rxq_ctrl->rxq.elts)[i] = buf;
218 /* If Rx vector is activated. */
219 if (mlx5_rxq_check_vec_support(&rxq_ctrl->rxq) > 0) {
220 struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
221 struct rte_mbuf *mbuf_init = &rxq->fake_mbuf;
222 struct rte_pktmbuf_pool_private *priv =
223 (struct rte_pktmbuf_pool_private *)
224 rte_mempool_get_priv(rxq_ctrl->rxq.mp);
227 /* Initialize default rearm_data for vPMD. */
228 mbuf_init->data_off = RTE_PKTMBUF_HEADROOM;
229 rte_mbuf_refcnt_set(mbuf_init, 1);
230 mbuf_init->nb_segs = 1;
231 mbuf_init->port = rxq->port_id;
232 if (priv->flags & RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF)
233 mbuf_init->ol_flags = EXT_ATTACHED_MBUF;
235 * prevent compiler reordering:
236 * rearm_data covers previous fields.
238 rte_compiler_barrier();
239 rxq->mbuf_initializer =
240 *(rte_xmm_t *)&mbuf_init->rearm_data;
241 /* Padding with a fake mbuf for vectorized Rx. */
242 for (j = 0; j < MLX5_VPMD_DESCS_PER_LOOP; ++j)
243 (*rxq->elts)[elts_n + j] = &rxq->fake_mbuf;
246 "port %u Rx queue %u allocated and configured %u segments"
248 PORT_ID(rxq_ctrl->priv), rxq_ctrl->rxq.idx, elts_n,
249 elts_n / (1 << rxq_ctrl->rxq.sges_n));
252 err = rte_errno; /* Save rte_errno before cleanup. */
254 for (i = 0; (i != elts_n); ++i) {
255 if ((*rxq_ctrl->rxq.elts)[i] != NULL)
256 rte_pktmbuf_free_seg((*rxq_ctrl->rxq.elts)[i]);
257 (*rxq_ctrl->rxq.elts)[i] = NULL;
259 DRV_LOG(DEBUG, "port %u Rx queue %u failed, freed everything",
260 PORT_ID(rxq_ctrl->priv), rxq_ctrl->rxq.idx);
261 rte_errno = err; /* Restore rte_errno. */
266 * Allocate RX queue elements.
269 * Pointer to RX queue structure.
272 * 0 on success, errno value on failure.
275 rxq_alloc_elts(struct mlx5_rxq_ctrl *rxq_ctrl)
277 return mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq) ?
278 rxq_alloc_elts_mprq(rxq_ctrl) : rxq_alloc_elts_sprq(rxq_ctrl);
282 * Free RX queue elements for Multi-Packet RQ.
285 * Pointer to RX queue structure.
288 rxq_free_elts_mprq(struct mlx5_rxq_ctrl *rxq_ctrl)
290 struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
293 DRV_LOG(DEBUG, "port %u Multi-Packet Rx queue %u freeing WRs",
294 rxq->port_id, rxq->idx);
295 if (rxq->mprq_bufs == NULL)
297 MLX5_ASSERT(mlx5_rxq_check_vec_support(rxq) < 0);
298 for (i = 0; (i != (1u << rxq->elts_n)); ++i) {
299 if ((*rxq->mprq_bufs)[i] != NULL)
300 mlx5_mprq_buf_free((*rxq->mprq_bufs)[i]);
301 (*rxq->mprq_bufs)[i] = NULL;
303 if (rxq->mprq_repl != NULL) {
304 mlx5_mprq_buf_free(rxq->mprq_repl);
305 rxq->mprq_repl = NULL;
310 * Free RX queue elements for Single-Packet RQ.
313 * Pointer to RX queue structure.
316 rxq_free_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
318 struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
319 const uint16_t q_n = (1 << rxq->elts_n);
320 const uint16_t q_mask = q_n - 1;
321 uint16_t used = q_n - (rxq->rq_ci - rxq->rq_pi);
324 DRV_LOG(DEBUG, "port %u Rx queue %u freeing WRs",
325 PORT_ID(rxq_ctrl->priv), rxq->idx);
326 if (rxq->elts == NULL)
329 * Some mbuf in the Ring belongs to the application. They cannot be
332 if (mlx5_rxq_check_vec_support(rxq) > 0) {
333 for (i = 0; i < used; ++i)
334 (*rxq->elts)[(rxq->rq_ci + i) & q_mask] = NULL;
335 rxq->rq_pi = rxq->rq_ci;
337 for (i = 0; (i != (1u << rxq->elts_n)); ++i) {
338 if ((*rxq->elts)[i] != NULL)
339 rte_pktmbuf_free_seg((*rxq->elts)[i]);
340 (*rxq->elts)[i] = NULL;
345 * Free RX queue elements.
348 * Pointer to RX queue structure.
351 rxq_free_elts(struct mlx5_rxq_ctrl *rxq_ctrl)
353 if (mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq))
354 rxq_free_elts_mprq(rxq_ctrl);
356 rxq_free_elts_sprq(rxq_ctrl);
360 * Returns the per-queue supported offloads.
363 * Pointer to Ethernet device.
366 * Supported Rx offloads.
369 mlx5_get_rx_queue_offloads(struct rte_eth_dev *dev)
371 struct mlx5_priv *priv = dev->data->dev_private;
372 struct mlx5_dev_config *config = &priv->config;
373 uint64_t offloads = (DEV_RX_OFFLOAD_SCATTER |
374 DEV_RX_OFFLOAD_TIMESTAMP |
375 DEV_RX_OFFLOAD_JUMBO_FRAME |
376 DEV_RX_OFFLOAD_RSS_HASH);
378 if (config->hw_fcs_strip)
379 offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
382 offloads |= (DEV_RX_OFFLOAD_IPV4_CKSUM |
383 DEV_RX_OFFLOAD_UDP_CKSUM |
384 DEV_RX_OFFLOAD_TCP_CKSUM);
385 if (config->hw_vlan_strip)
386 offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
387 if (MLX5_LRO_SUPPORTED(dev))
388 offloads |= DEV_RX_OFFLOAD_TCP_LRO;
394 * Returns the per-port supported offloads.
397 * Supported Rx offloads.
400 mlx5_get_rx_port_offloads(void)
402 uint64_t offloads = DEV_RX_OFFLOAD_VLAN_FILTER;
408 * Verify if the queue can be released.
411 * Pointer to Ethernet device.
416 * 1 if the queue can be released
417 * 0 if the queue can not be released, there are references to it.
418 * Negative errno and rte_errno is set if queue doesn't exist.
421 mlx5_rxq_releasable(struct rte_eth_dev *dev, uint16_t idx)
423 struct mlx5_priv *priv = dev->data->dev_private;
424 struct mlx5_rxq_ctrl *rxq_ctrl;
426 if (!(*priv->rxqs)[idx]) {
430 rxq_ctrl = container_of((*priv->rxqs)[idx], struct mlx5_rxq_ctrl, rxq);
431 return (rte_atomic32_read(&rxq_ctrl->refcnt) == 1);
434 /* Fetches and drops all SW-owned and error CQEs to synchronize CQ. */
436 rxq_sync_cq(struct mlx5_rxq_data *rxq)
438 const uint16_t cqe_n = 1 << rxq->cqe_n;
439 const uint16_t cqe_mask = cqe_n - 1;
440 volatile struct mlx5_cqe *cqe;
445 cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_mask];
446 ret = check_cqe(cqe, cqe_n, rxq->cq_ci);
447 if (ret == MLX5_CQE_STATUS_HW_OWN)
449 if (ret == MLX5_CQE_STATUS_ERR) {
453 MLX5_ASSERT(ret == MLX5_CQE_STATUS_SW_OWN);
454 if (MLX5_CQE_FORMAT(cqe->op_own) != MLX5_COMPRESSED) {
458 /* Compute the next non compressed CQE. */
459 rxq->cq_ci += rte_be_to_cpu_32(cqe->byte_cnt);
462 /* Move all CQEs to HW ownership, including possible MiniCQEs. */
463 for (i = 0; i < cqe_n; i++) {
464 cqe = &(*rxq->cqes)[i];
465 cqe->op_own = MLX5_CQE_INVALIDATE;
467 /* Resync CQE and WQE (WQ in RESET state). */
469 *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
471 *rxq->rq_db = rte_cpu_to_be_32(0);
476 * Rx queue stop. Device queue goes to the RESET state,
477 * all involved mbufs are freed from WQ.
480 * Pointer to Ethernet device structure.
485 * 0 on success, a negative errno value otherwise and rte_errno is set.
488 mlx5_rx_queue_stop_primary(struct rte_eth_dev *dev, uint16_t idx)
490 struct mlx5_priv *priv = dev->data->dev_private;
491 struct mlx5_rxq_data *rxq = (*priv->rxqs)[idx];
492 struct mlx5_rxq_ctrl *rxq_ctrl =
493 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
496 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
497 if (rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_IBV) {
498 struct ibv_wq_attr mod = {
499 .attr_mask = IBV_WQ_ATTR_STATE,
500 .wq_state = IBV_WQS_RESET,
503 ret = mlx5_glue->modify_wq(rxq_ctrl->obj->wq, &mod);
504 } else { /* rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_DEVX_RQ. */
505 struct mlx5_devx_modify_rq_attr rq_attr;
507 memset(&rq_attr, 0, sizeof(rq_attr));
508 rq_attr.rq_state = MLX5_RQC_STATE_RDY;
509 rq_attr.state = MLX5_RQC_STATE_RST;
510 ret = mlx5_devx_cmd_modify_rq(rxq_ctrl->obj->rq, &rq_attr);
513 DRV_LOG(ERR, "Cannot change Rx WQ state to RESET: %s",
518 /* Remove all processes CQEs. */
520 /* Free all involved mbufs. */
521 rxq_free_elts(rxq_ctrl);
522 /* Set the actual queue state. */
523 dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STOPPED;
528 * Rx queue stop. Device queue goes to the RESET state,
529 * all involved mbufs are freed from WQ.
532 * Pointer to Ethernet device structure.
537 * 0 on success, a negative errno value otherwise and rte_errno is set.
540 mlx5_rx_queue_stop(struct rte_eth_dev *dev, uint16_t idx)
542 eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
545 if (dev->data->rx_queue_state[idx] == RTE_ETH_QUEUE_STATE_HAIRPIN) {
546 DRV_LOG(ERR, "Hairpin queue can't be stopped");
550 if (dev->data->rx_queue_state[idx] == RTE_ETH_QUEUE_STATE_STOPPED)
553 * Vectorized Rx burst requires the CQ and RQ indices
554 * synchronized, that might be broken on RQ restart
555 * and cause Rx malfunction, so queue stopping is
556 * not supported if vectorized Rx burst is engaged.
557 * The routine pointer depends on the process
558 * type, should perform check there.
560 if (pkt_burst == mlx5_rx_burst) {
561 DRV_LOG(ERR, "Rx queue stop is not supported "
562 "for vectorized Rx");
566 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
567 ret = mlx5_mp_os_req_queue_control(dev, idx,
568 MLX5_MP_REQ_QUEUE_RX_STOP);
570 ret = mlx5_rx_queue_stop_primary(dev, idx);
576 * Rx queue start. Device queue goes to the ready state,
577 * all required mbufs are allocated and WQ is replenished.
580 * Pointer to Ethernet device structure.
585 * 0 on success, a negative errno value otherwise and rte_errno is set.
588 mlx5_rx_queue_start_primary(struct rte_eth_dev *dev, uint16_t idx)
590 struct mlx5_priv *priv = dev->data->dev_private;
591 struct mlx5_rxq_data *rxq = (*priv->rxqs)[idx];
592 struct mlx5_rxq_ctrl *rxq_ctrl =
593 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
596 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
597 /* Allocate needed buffers. */
598 ret = rxq_alloc_elts(rxq_ctrl);
600 DRV_LOG(ERR, "Cannot reallocate buffers for Rx WQ");
605 *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
607 /* Reset RQ consumer before moving queue to READY state. */
608 *rxq->rq_db = rte_cpu_to_be_32(0);
610 if (rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_IBV) {
611 struct ibv_wq_attr mod = {
612 .attr_mask = IBV_WQ_ATTR_STATE,
613 .wq_state = IBV_WQS_RDY,
616 ret = mlx5_glue->modify_wq(rxq_ctrl->obj->wq, &mod);
617 } else { /* rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_DEVX_RQ. */
618 struct mlx5_devx_modify_rq_attr rq_attr;
620 memset(&rq_attr, 0, sizeof(rq_attr));
621 rq_attr.rq_state = MLX5_RQC_STATE_RST;
622 rq_attr.state = MLX5_RQC_STATE_RDY;
623 ret = mlx5_devx_cmd_modify_rq(rxq_ctrl->obj->rq, &rq_attr);
626 DRV_LOG(ERR, "Cannot change Rx WQ state to READY: %s",
631 /* Reinitialize RQ - set WQEs. */
632 mlx5_rxq_initialize(rxq);
633 rxq->err_state = MLX5_RXQ_ERR_STATE_NO_ERROR;
634 /* Set actual queue state. */
635 dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED;
640 * Rx queue start. Device queue goes to the ready state,
641 * all required mbufs are allocated and WQ is replenished.
644 * Pointer to Ethernet device structure.
649 * 0 on success, a negative errno value otherwise and rte_errno is set.
652 mlx5_rx_queue_start(struct rte_eth_dev *dev, uint16_t idx)
656 if (dev->data->rx_queue_state[idx] == RTE_ETH_QUEUE_STATE_HAIRPIN) {
657 DRV_LOG(ERR, "Hairpin queue can't be started");
661 if (dev->data->rx_queue_state[idx] == RTE_ETH_QUEUE_STATE_STARTED)
663 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
664 ret = mlx5_mp_os_req_queue_control(dev, idx,
665 MLX5_MP_REQ_QUEUE_RX_START);
667 ret = mlx5_rx_queue_start_primary(dev, idx);
673 * Rx queue presetup checks.
676 * Pointer to Ethernet device structure.
680 * Number of descriptors to configure in queue.
683 * 0 on success, a negative errno value otherwise and rte_errno is set.
686 mlx5_rx_queue_pre_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t *desc)
688 struct mlx5_priv *priv = dev->data->dev_private;
690 if (!rte_is_power_of_2(*desc)) {
691 *desc = 1 << log2above(*desc);
693 "port %u increased number of descriptors in Rx queue %u"
694 " to the next power of two (%d)",
695 dev->data->port_id, idx, *desc);
697 DRV_LOG(DEBUG, "port %u configuring Rx queue %u for %u descriptors",
698 dev->data->port_id, idx, *desc);
699 if (idx >= priv->rxqs_n) {
700 DRV_LOG(ERR, "port %u Rx queue index out of range (%u >= %u)",
701 dev->data->port_id, idx, priv->rxqs_n);
702 rte_errno = EOVERFLOW;
705 if (!mlx5_rxq_releasable(dev, idx)) {
706 DRV_LOG(ERR, "port %u unable to release queue index %u",
707 dev->data->port_id, idx);
711 mlx5_rxq_release(dev, idx);
718 * Pointer to Ethernet device structure.
722 * Number of descriptors to configure in queue.
724 * NUMA socket on which memory must be allocated.
726 * Thresholds parameters.
728 * Memory pool for buffer allocations.
731 * 0 on success, a negative errno value otherwise and rte_errno is set.
734 mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
735 unsigned int socket, const struct rte_eth_rxconf *conf,
736 struct rte_mempool *mp)
738 struct mlx5_priv *priv = dev->data->dev_private;
739 struct mlx5_rxq_data *rxq = (*priv->rxqs)[idx];
740 struct mlx5_rxq_ctrl *rxq_ctrl =
741 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
744 res = mlx5_rx_queue_pre_setup(dev, idx, &desc);
747 rxq_ctrl = mlx5_rxq_new(dev, idx, desc, socket, conf, mp);
749 DRV_LOG(ERR, "port %u unable to allocate queue index %u",
750 dev->data->port_id, idx);
754 DRV_LOG(DEBUG, "port %u adding Rx queue %u to list",
755 dev->data->port_id, idx);
756 (*priv->rxqs)[idx] = &rxq_ctrl->rxq;
763 * Pointer to Ethernet device structure.
767 * Number of descriptors to configure in queue.
768 * @param hairpin_conf
769 * Hairpin configuration parameters.
772 * 0 on success, a negative errno value otherwise and rte_errno is set.
775 mlx5_rx_hairpin_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
777 const struct rte_eth_hairpin_conf *hairpin_conf)
779 struct mlx5_priv *priv = dev->data->dev_private;
780 struct mlx5_rxq_data *rxq = (*priv->rxqs)[idx];
781 struct mlx5_rxq_ctrl *rxq_ctrl =
782 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
785 res = mlx5_rx_queue_pre_setup(dev, idx, &desc);
788 if (hairpin_conf->peer_count != 1 ||
789 hairpin_conf->peers[0].port != dev->data->port_id ||
790 hairpin_conf->peers[0].queue >= priv->txqs_n) {
791 DRV_LOG(ERR, "port %u unable to setup hairpin queue index %u "
792 " invalid hairpind configuration", dev->data->port_id,
797 rxq_ctrl = mlx5_rxq_hairpin_new(dev, idx, desc, hairpin_conf);
799 DRV_LOG(ERR, "port %u unable to allocate queue index %u",
800 dev->data->port_id, idx);
804 DRV_LOG(DEBUG, "port %u adding Rx queue %u to list",
805 dev->data->port_id, idx);
806 (*priv->rxqs)[idx] = &rxq_ctrl->rxq;
811 * DPDK callback to release a RX queue.
814 * Generic RX queue pointer.
817 mlx5_rx_queue_release(void *dpdk_rxq)
819 struct mlx5_rxq_data *rxq = (struct mlx5_rxq_data *)dpdk_rxq;
820 struct mlx5_rxq_ctrl *rxq_ctrl;
821 struct mlx5_priv *priv;
825 rxq_ctrl = container_of(rxq, struct mlx5_rxq_ctrl, rxq);
826 priv = rxq_ctrl->priv;
827 if (!mlx5_rxq_releasable(ETH_DEV(priv), rxq_ctrl->rxq.idx))
828 rte_panic("port %u Rx queue %u is still used by a flow and"
829 " cannot be removed\n",
830 PORT_ID(priv), rxq->idx);
831 mlx5_rxq_release(ETH_DEV(priv), rxq_ctrl->rxq.idx);
835 * Allocate queue vector and fill epoll fd list for Rx interrupts.
838 * Pointer to Ethernet device.
841 * 0 on success, a negative errno value otherwise and rte_errno is set.
844 mlx5_rx_intr_vec_enable(struct rte_eth_dev *dev)
846 struct mlx5_priv *priv = dev->data->dev_private;
848 unsigned int rxqs_n = priv->rxqs_n;
849 unsigned int n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
850 unsigned int count = 0;
851 struct rte_intr_handle *intr_handle = dev->intr_handle;
853 if (!dev->data->dev_conf.intr_conf.rxq)
855 mlx5_rx_intr_vec_disable(dev);
856 intr_handle->intr_vec = mlx5_malloc(0,
857 n * sizeof(intr_handle->intr_vec[0]),
859 if (intr_handle->intr_vec == NULL) {
861 "port %u failed to allocate memory for interrupt"
862 " vector, Rx interrupts will not be supported",
867 intr_handle->type = RTE_INTR_HANDLE_EXT;
868 for (i = 0; i != n; ++i) {
869 /* This rxq obj must not be released in this function. */
870 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_get(dev, i);
871 struct mlx5_rxq_obj *rxq_obj = rxq_ctrl ? rxq_ctrl->obj : NULL;
874 /* Skip queues that cannot request interrupts. */
875 if (!rxq_obj || (!rxq_obj->ibv_channel &&
876 !rxq_obj->devx_channel)) {
877 /* Use invalid intr_vec[] index to disable entry. */
878 intr_handle->intr_vec[i] =
879 RTE_INTR_VEC_RXTX_OFFSET +
880 RTE_MAX_RXTX_INTR_VEC_ID;
881 /* Decrease the rxq_ctrl's refcnt */
883 mlx5_rxq_release(dev, i);
886 if (count >= RTE_MAX_RXTX_INTR_VEC_ID) {
888 "port %u too many Rx queues for interrupt"
889 " vector size (%d), Rx interrupts cannot be"
891 dev->data->port_id, RTE_MAX_RXTX_INTR_VEC_ID);
892 mlx5_rx_intr_vec_disable(dev);
896 rc = mlx5_os_set_nonblock_channel_fd(rxq_obj->fd);
900 "port %u failed to make Rx interrupt file"
901 " descriptor %d non-blocking for queue index"
903 dev->data->port_id, rxq_obj->fd, i);
904 mlx5_rx_intr_vec_disable(dev);
907 intr_handle->intr_vec[i] = RTE_INTR_VEC_RXTX_OFFSET + count;
908 intr_handle->efds[count] = rxq_obj->fd;
912 mlx5_rx_intr_vec_disable(dev);
914 intr_handle->nb_efd = count;
919 * Clean up Rx interrupts handler.
922 * Pointer to Ethernet device.
925 mlx5_rx_intr_vec_disable(struct rte_eth_dev *dev)
927 struct mlx5_priv *priv = dev->data->dev_private;
928 struct rte_intr_handle *intr_handle = dev->intr_handle;
930 unsigned int rxqs_n = priv->rxqs_n;
931 unsigned int n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
933 if (!dev->data->dev_conf.intr_conf.rxq)
935 if (!intr_handle->intr_vec)
937 for (i = 0; i != n; ++i) {
938 if (intr_handle->intr_vec[i] == RTE_INTR_VEC_RXTX_OFFSET +
939 RTE_MAX_RXTX_INTR_VEC_ID)
942 * Need to access directly the queue to release the reference
943 * kept in mlx5_rx_intr_vec_enable().
945 mlx5_rxq_release(dev, i);
948 rte_intr_free_epoll_fd(intr_handle);
949 if (intr_handle->intr_vec)
950 mlx5_free(intr_handle->intr_vec);
951 intr_handle->nb_efd = 0;
952 intr_handle->intr_vec = NULL;
956 * MLX5 CQ notification .
959 * Pointer to receive queue structure.
961 * Sequence number per receive queue .
964 mlx5_arm_cq(struct mlx5_rxq_data *rxq, int sq_n_rxq)
967 uint32_t doorbell_hi;
969 void *cq_db_reg = (char *)rxq->cq_uar + MLX5_CQ_DOORBELL;
971 sq_n = sq_n_rxq & MLX5_CQ_SQN_MASK;
972 doorbell_hi = sq_n << MLX5_CQ_SQN_OFFSET | (rxq->cq_ci & MLX5_CI_MASK);
973 doorbell = (uint64_t)doorbell_hi << 32;
974 doorbell |= rxq->cqn;
975 rxq->cq_db[MLX5_CQ_ARM_DB] = rte_cpu_to_be_32(doorbell_hi);
976 mlx5_uar_write64(rte_cpu_to_be_64(doorbell),
977 cq_db_reg, rxq->uar_lock_cq);
981 * DPDK callback for Rx queue interrupt enable.
984 * Pointer to Ethernet device structure.
989 * 0 on success, a negative errno value otherwise and rte_errno is set.
992 mlx5_rx_intr_enable(struct rte_eth_dev *dev, uint16_t rx_queue_id)
994 struct mlx5_rxq_ctrl *rxq_ctrl;
996 rxq_ctrl = mlx5_rxq_get(dev, rx_queue_id);
1000 if (!rxq_ctrl->obj) {
1001 mlx5_rxq_release(dev, rx_queue_id);
1004 mlx5_arm_cq(&rxq_ctrl->rxq, rxq_ctrl->rxq.cq_arm_sn);
1006 mlx5_rxq_release(dev, rx_queue_id);
1014 * DPDK callback for Rx queue interrupt disable.
1017 * Pointer to Ethernet device structure.
1018 * @param rx_queue_id
1022 * 0 on success, a negative errno value otherwise and rte_errno is set.
1025 mlx5_rx_intr_disable(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1027 struct mlx5_priv *priv = dev->data->dev_private;
1028 struct mlx5_rxq_ctrl *rxq_ctrl;
1031 rxq_ctrl = mlx5_rxq_get(dev, rx_queue_id);
1038 if (rxq_ctrl->irq) {
1039 ret = priv->obj_ops->rxq_event_get(rxq_ctrl->obj);
1042 rxq_ctrl->rxq.cq_arm_sn++;
1044 mlx5_rxq_release(dev, rx_queue_id);
1048 * The ret variable may be EAGAIN which means the get_event function was
1049 * called before receiving one.
1055 ret = rte_errno; /* Save rte_errno before cleanup. */
1056 mlx5_rxq_release(dev, rx_queue_id);
1058 DRV_LOG(WARNING, "port %u unable to disable interrupt on Rx queue %d",
1059 dev->data->port_id, rx_queue_id);
1060 rte_errno = ret; /* Restore rte_errno. */
1065 * Verify the Rx queue objects list is empty
1068 * Pointer to Ethernet device.
1071 * The number of objects not released.
1074 mlx5_rxq_obj_verify(struct rte_eth_dev *dev)
1076 struct mlx5_priv *priv = dev->data->dev_private;
1078 struct mlx5_rxq_obj *rxq_obj;
1080 LIST_FOREACH(rxq_obj, &priv->rxqsobj, next) {
1081 DRV_LOG(DEBUG, "port %u Rx queue %u still referenced",
1082 dev->data->port_id, rxq_obj->rxq_ctrl->rxq.idx);
1089 * Callback function to initialize mbufs for Multi-Packet RQ.
1092 mlx5_mprq_buf_init(struct rte_mempool *mp, void *opaque_arg,
1093 void *_m, unsigned int i __rte_unused)
1095 struct mlx5_mprq_buf *buf = _m;
1096 struct rte_mbuf_ext_shared_info *shinfo;
1097 unsigned int strd_n = (unsigned int)(uintptr_t)opaque_arg;
1100 memset(_m, 0, sizeof(*buf));
1102 rte_atomic16_set(&buf->refcnt, 1);
1103 for (j = 0; j != strd_n; ++j) {
1104 shinfo = &buf->shinfos[j];
1105 shinfo->free_cb = mlx5_mprq_buf_free_cb;
1106 shinfo->fcb_opaque = buf;
1111 * Free mempool of Multi-Packet RQ.
1114 * Pointer to Ethernet device.
1117 * 0 on success, negative errno value on failure.
1120 mlx5_mprq_free_mp(struct rte_eth_dev *dev)
1122 struct mlx5_priv *priv = dev->data->dev_private;
1123 struct rte_mempool *mp = priv->mprq_mp;
1128 DRV_LOG(DEBUG, "port %u freeing mempool (%s) for Multi-Packet RQ",
1129 dev->data->port_id, mp->name);
1131 * If a buffer in the pool has been externally attached to a mbuf and it
1132 * is still in use by application, destroying the Rx queue can spoil
1133 * the packet. It is unlikely to happen but if application dynamically
1134 * creates and destroys with holding Rx packets, this can happen.
1136 * TODO: It is unavoidable for now because the mempool for Multi-Packet
1137 * RQ isn't provided by application but managed by PMD.
1139 if (!rte_mempool_full(mp)) {
1141 "port %u mempool for Multi-Packet RQ is still in use",
1142 dev->data->port_id);
1146 rte_mempool_free(mp);
1147 /* Unset mempool for each Rx queue. */
1148 for (i = 0; i != priv->rxqs_n; ++i) {
1149 struct mlx5_rxq_data *rxq = (*priv->rxqs)[i];
1153 rxq->mprq_mp = NULL;
1155 priv->mprq_mp = NULL;
1160 * Allocate a mempool for Multi-Packet RQ. All configured Rx queues share the
1161 * mempool. If already allocated, reuse it if there're enough elements.
1162 * Otherwise, resize it.
1165 * Pointer to Ethernet device.
1168 * 0 on success, negative errno value on failure.
1171 mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)
1173 struct mlx5_priv *priv = dev->data->dev_private;
1174 struct rte_mempool *mp = priv->mprq_mp;
1175 char name[RTE_MEMPOOL_NAMESIZE];
1176 unsigned int desc = 0;
1177 unsigned int buf_len;
1178 unsigned int obj_num;
1179 unsigned int obj_size;
1180 unsigned int strd_num_n = 0;
1181 unsigned int strd_sz_n = 0;
1183 unsigned int n_ibv = 0;
1185 if (!mlx5_mprq_enabled(dev))
1187 /* Count the total number of descriptors configured. */
1188 for (i = 0; i != priv->rxqs_n; ++i) {
1189 struct mlx5_rxq_data *rxq = (*priv->rxqs)[i];
1190 struct mlx5_rxq_ctrl *rxq_ctrl = container_of
1191 (rxq, struct mlx5_rxq_ctrl, rxq);
1193 if (rxq == NULL || rxq_ctrl->type != MLX5_RXQ_TYPE_STANDARD)
1196 desc += 1 << rxq->elts_n;
1197 /* Get the max number of strides. */
1198 if (strd_num_n < rxq->strd_num_n)
1199 strd_num_n = rxq->strd_num_n;
1200 /* Get the max size of a stride. */
1201 if (strd_sz_n < rxq->strd_sz_n)
1202 strd_sz_n = rxq->strd_sz_n;
1204 MLX5_ASSERT(strd_num_n && strd_sz_n);
1205 buf_len = (1 << strd_num_n) * (1 << strd_sz_n);
1206 obj_size = sizeof(struct mlx5_mprq_buf) + buf_len + (1 << strd_num_n) *
1207 sizeof(struct rte_mbuf_ext_shared_info) + RTE_PKTMBUF_HEADROOM;
1209 * Received packets can be either memcpy'd or externally referenced. In
1210 * case that the packet is attached to an mbuf as an external buffer, as
1211 * it isn't possible to predict how the buffers will be queued by
1212 * application, there's no option to exactly pre-allocate needed buffers
1213 * in advance but to speculatively prepares enough buffers.
1215 * In the data path, if this Mempool is depleted, PMD will try to memcpy
1216 * received packets to buffers provided by application (rxq->mp) until
1217 * this Mempool gets available again.
1220 obj_num = desc + MLX5_MPRQ_MP_CACHE_SZ * n_ibv;
1222 * rte_mempool_create_empty() has sanity check to refuse large cache
1223 * size compared to the number of elements.
1224 * CACHE_FLUSHTHRESH_MULTIPLIER is defined in a C file, so using a
1225 * constant number 2 instead.
1227 obj_num = RTE_MAX(obj_num, MLX5_MPRQ_MP_CACHE_SZ * 2);
1228 /* Check a mempool is already allocated and if it can be resued. */
1229 if (mp != NULL && mp->elt_size >= obj_size && mp->size >= obj_num) {
1230 DRV_LOG(DEBUG, "port %u mempool %s is being reused",
1231 dev->data->port_id, mp->name);
1234 } else if (mp != NULL) {
1235 DRV_LOG(DEBUG, "port %u mempool %s should be resized, freeing it",
1236 dev->data->port_id, mp->name);
1238 * If failed to free, which means it may be still in use, no way
1239 * but to keep using the existing one. On buffer underrun,
1240 * packets will be memcpy'd instead of external buffer
1243 if (mlx5_mprq_free_mp(dev)) {
1244 if (mp->elt_size >= obj_size)
1250 snprintf(name, sizeof(name), "port-%u-mprq", dev->data->port_id);
1251 mp = rte_mempool_create(name, obj_num, obj_size, MLX5_MPRQ_MP_CACHE_SZ,
1252 0, NULL, NULL, mlx5_mprq_buf_init,
1253 (void *)(uintptr_t)(1 << strd_num_n),
1254 dev->device->numa_node, 0);
1257 "port %u failed to allocate a mempool for"
1258 " Multi-Packet RQ, count=%u, size=%u",
1259 dev->data->port_id, obj_num, obj_size);
1265 /* Set mempool for each Rx queue. */
1266 for (i = 0; i != priv->rxqs_n; ++i) {
1267 struct mlx5_rxq_data *rxq = (*priv->rxqs)[i];
1268 struct mlx5_rxq_ctrl *rxq_ctrl = container_of
1269 (rxq, struct mlx5_rxq_ctrl, rxq);
1271 if (rxq == NULL || rxq_ctrl->type != MLX5_RXQ_TYPE_STANDARD)
1275 DRV_LOG(INFO, "port %u Multi-Packet RQ is configured",
1276 dev->data->port_id);
1280 #define MLX5_MAX_TCP_HDR_OFFSET ((unsigned int)(sizeof(struct rte_ether_hdr) + \
1281 sizeof(struct rte_vlan_hdr) * 2 + \
1282 sizeof(struct rte_ipv6_hdr)))
1283 #define MAX_TCP_OPTION_SIZE 40u
1284 #define MLX5_MAX_LRO_HEADER_FIX ((unsigned int)(MLX5_MAX_TCP_HDR_OFFSET + \
1285 sizeof(struct rte_tcp_hdr) + \
1286 MAX_TCP_OPTION_SIZE))
1289 * Adjust the maximum LRO massage size.
1292 * Pointer to Ethernet device.
1295 * @param max_lro_size
1296 * The maximum size for LRO packet.
1299 mlx5_max_lro_msg_size_adjust(struct rte_eth_dev *dev, uint16_t idx,
1300 uint32_t max_lro_size)
1302 struct mlx5_priv *priv = dev->data->dev_private;
1304 if (priv->config.hca_attr.lro_max_msg_sz_mode ==
1305 MLX5_LRO_MAX_MSG_SIZE_START_FROM_L4 && max_lro_size >
1306 MLX5_MAX_TCP_HDR_OFFSET)
1307 max_lro_size -= MLX5_MAX_TCP_HDR_OFFSET;
1308 max_lro_size = RTE_MIN(max_lro_size, MLX5_MAX_LRO_SIZE);
1309 MLX5_ASSERT(max_lro_size >= MLX5_LRO_SEG_CHUNK_SIZE);
1310 max_lro_size /= MLX5_LRO_SEG_CHUNK_SIZE;
1311 if (priv->max_lro_msg_size)
1312 priv->max_lro_msg_size =
1313 RTE_MIN((uint32_t)priv->max_lro_msg_size, max_lro_size);
1315 priv->max_lro_msg_size = max_lro_size;
1317 "port %u Rx Queue %u max LRO message size adjusted to %u bytes",
1318 dev->data->port_id, idx,
1319 priv->max_lro_msg_size * MLX5_LRO_SEG_CHUNK_SIZE);
1323 * Create a DPDK Rx queue.
1326 * Pointer to Ethernet device.
1330 * Number of descriptors to configure in queue.
1332 * NUMA socket on which memory must be allocated.
1335 * A DPDK queue object on success, NULL otherwise and rte_errno is set.
1337 struct mlx5_rxq_ctrl *
1338 mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1339 unsigned int socket, const struct rte_eth_rxconf *conf,
1340 struct rte_mempool *mp)
1342 struct mlx5_priv *priv = dev->data->dev_private;
1343 struct mlx5_rxq_ctrl *tmpl;
1344 unsigned int mb_len = rte_pktmbuf_data_room_size(mp);
1345 unsigned int mprq_stride_nums;
1346 unsigned int mprq_stride_size;
1347 unsigned int mprq_stride_cap;
1348 struct mlx5_dev_config *config = &priv->config;
1350 * Always allocate extra slots, even if eventually
1351 * the vector Rx will not be used.
1354 desc + config->rx_vec_en * MLX5_VPMD_DESCS_PER_LOOP;
1355 uint64_t offloads = conf->offloads |
1356 dev->data->dev_conf.rxmode.offloads;
1357 unsigned int lro_on_queue = !!(offloads & DEV_RX_OFFLOAD_TCP_LRO);
1358 const int mprq_en = mlx5_check_mprq_support(dev) > 0;
1359 unsigned int max_rx_pkt_len = lro_on_queue ?
1360 dev->data->dev_conf.rxmode.max_lro_pkt_size :
1361 dev->data->dev_conf.rxmode.max_rx_pkt_len;
1362 unsigned int non_scatter_min_mbuf_size = max_rx_pkt_len +
1363 RTE_PKTMBUF_HEADROOM;
1364 unsigned int max_lro_size = 0;
1365 unsigned int first_mb_free_size = mb_len - RTE_PKTMBUF_HEADROOM;
1367 if (non_scatter_min_mbuf_size > mb_len && !(offloads &
1368 DEV_RX_OFFLOAD_SCATTER)) {
1369 DRV_LOG(ERR, "port %u Rx queue %u: Scatter offload is not"
1370 " configured and no enough mbuf space(%u) to contain "
1371 "the maximum RX packet length(%u) with head-room(%u)",
1372 dev->data->port_id, idx, mb_len, max_rx_pkt_len,
1373 RTE_PKTMBUF_HEADROOM);
1377 tmpl = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, sizeof(*tmpl) +
1378 desc_n * sizeof(struct rte_mbuf *), 0, socket);
1383 tmpl->type = MLX5_RXQ_TYPE_STANDARD;
1384 if (mlx5_mr_btree_init(&tmpl->rxq.mr_ctrl.cache_bh,
1385 MLX5_MR_BTREE_CACHE_N, socket)) {
1386 /* rte_errno is already set. */
1389 tmpl->socket = socket;
1390 if (dev->data->dev_conf.intr_conf.rxq)
1392 mprq_stride_nums = config->mprq.stride_num_n ?
1393 config->mprq.stride_num_n : MLX5_MPRQ_STRIDE_NUM_N;
1394 mprq_stride_size = non_scatter_min_mbuf_size <=
1395 (1U << config->mprq.max_stride_size_n) ?
1396 log2above(non_scatter_min_mbuf_size) : MLX5_MPRQ_STRIDE_SIZE_N;
1397 mprq_stride_cap = (config->mprq.stride_num_n ?
1398 (1U << config->mprq.stride_num_n) : (1U << mprq_stride_nums)) *
1399 (config->mprq.stride_size_n ?
1400 (1U << config->mprq.stride_size_n) : (1U << mprq_stride_size));
1402 * This Rx queue can be configured as a Multi-Packet RQ if all of the
1403 * following conditions are met:
1404 * - MPRQ is enabled.
1405 * - The number of descs is more than the number of strides.
1406 * - max_rx_pkt_len plus overhead is less than the max size
1407 * of a stride or mprq_stride_size is specified by a user.
1408 * Need to nake sure that there are enough stides to encap
1409 * the maximum packet size in case mprq_stride_size is set.
1410 * Otherwise, enable Rx scatter if necessary.
1412 if (mprq_en && desc > (1U << mprq_stride_nums) &&
1413 (non_scatter_min_mbuf_size <=
1414 (1U << config->mprq.max_stride_size_n) ||
1415 (config->mprq.stride_size_n &&
1416 non_scatter_min_mbuf_size <= mprq_stride_cap))) {
1417 /* TODO: Rx scatter isn't supported yet. */
1418 tmpl->rxq.sges_n = 0;
1419 /* Trim the number of descs needed. */
1420 desc >>= mprq_stride_nums;
1421 tmpl->rxq.strd_num_n = config->mprq.stride_num_n ?
1422 config->mprq.stride_num_n : mprq_stride_nums;
1423 tmpl->rxq.strd_sz_n = config->mprq.stride_size_n ?
1424 config->mprq.stride_size_n : mprq_stride_size;
1425 tmpl->rxq.strd_shift_en = MLX5_MPRQ_TWO_BYTE_SHIFT;
1426 tmpl->rxq.strd_scatter_en =
1427 !!(offloads & DEV_RX_OFFLOAD_SCATTER);
1428 tmpl->rxq.mprq_max_memcpy_len = RTE_MIN(first_mb_free_size,
1429 config->mprq.max_memcpy_len);
1430 max_lro_size = RTE_MIN(max_rx_pkt_len,
1431 (1u << tmpl->rxq.strd_num_n) *
1432 (1u << tmpl->rxq.strd_sz_n));
1434 "port %u Rx queue %u: Multi-Packet RQ is enabled"
1435 " strd_num_n = %u, strd_sz_n = %u",
1436 dev->data->port_id, idx,
1437 tmpl->rxq.strd_num_n, tmpl->rxq.strd_sz_n);
1438 } else if (max_rx_pkt_len <= first_mb_free_size) {
1439 tmpl->rxq.sges_n = 0;
1440 max_lro_size = max_rx_pkt_len;
1441 } else if (offloads & DEV_RX_OFFLOAD_SCATTER) {
1442 unsigned int size = non_scatter_min_mbuf_size;
1443 unsigned int sges_n;
1445 if (lro_on_queue && first_mb_free_size <
1446 MLX5_MAX_LRO_HEADER_FIX) {
1447 DRV_LOG(ERR, "Not enough space in the first segment(%u)"
1448 " to include the max header size(%u) for LRO",
1449 first_mb_free_size, MLX5_MAX_LRO_HEADER_FIX);
1450 rte_errno = ENOTSUP;
1454 * Determine the number of SGEs needed for a full packet
1455 * and round it to the next power of two.
1457 sges_n = log2above((size / mb_len) + !!(size % mb_len));
1458 if (sges_n > MLX5_MAX_LOG_RQ_SEGS) {
1460 "port %u too many SGEs (%u) needed to handle"
1461 " requested maximum packet size %u, the maximum"
1462 " supported are %u", dev->data->port_id,
1463 1 << sges_n, max_rx_pkt_len,
1464 1u << MLX5_MAX_LOG_RQ_SEGS);
1465 rte_errno = ENOTSUP;
1468 tmpl->rxq.sges_n = sges_n;
1469 max_lro_size = max_rx_pkt_len;
1471 if (config->mprq.enabled && !mlx5_rxq_mprq_enabled(&tmpl->rxq))
1473 "port %u MPRQ is requested but cannot be enabled\n"
1474 " (requested: pkt_sz = %u, desc_num = %u,"
1475 " rxq_num = %u, stride_sz = %u, stride_num = %u\n"
1476 " supported: min_rxqs_num = %u,"
1477 " min_stride_sz = %u, max_stride_sz = %u).",
1478 dev->data->port_id, non_scatter_min_mbuf_size,
1480 config->mprq.stride_size_n ?
1481 (1U << config->mprq.stride_size_n) :
1482 (1U << mprq_stride_size),
1483 config->mprq.stride_num_n ?
1484 (1U << config->mprq.stride_num_n) :
1485 (1U << mprq_stride_nums),
1486 config->mprq.min_rxqs_num,
1487 (1U << config->mprq.min_stride_size_n),
1488 (1U << config->mprq.max_stride_size_n));
1489 DRV_LOG(DEBUG, "port %u maximum number of segments per packet: %u",
1490 dev->data->port_id, 1 << tmpl->rxq.sges_n);
1491 if (desc % (1 << tmpl->rxq.sges_n)) {
1493 "port %u number of Rx queue descriptors (%u) is not a"
1494 " multiple of SGEs per packet (%u)",
1497 1 << tmpl->rxq.sges_n);
1501 mlx5_max_lro_msg_size_adjust(dev, idx, max_lro_size);
1502 /* Toggle RX checksum offload if hardware supports it. */
1503 tmpl->rxq.csum = !!(offloads & DEV_RX_OFFLOAD_CHECKSUM);
1504 tmpl->rxq.hw_timestamp = !!(offloads & DEV_RX_OFFLOAD_TIMESTAMP);
1505 /* Configure VLAN stripping. */
1506 tmpl->rxq.vlan_strip = !!(offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
1507 /* By default, FCS (CRC) is stripped by hardware. */
1508 tmpl->rxq.crc_present = 0;
1509 tmpl->rxq.lro = lro_on_queue;
1510 if (offloads & DEV_RX_OFFLOAD_KEEP_CRC) {
1511 if (config->hw_fcs_strip) {
1513 * RQs used for LRO-enabled TIRs should not be
1514 * configured to scatter the FCS.
1518 "port %u CRC stripping has been "
1519 "disabled but will still be performed "
1520 "by hardware, because LRO is enabled",
1521 dev->data->port_id);
1523 tmpl->rxq.crc_present = 1;
1526 "port %u CRC stripping has been disabled but will"
1527 " still be performed by hardware, make sure MLNX_OFED"
1528 " and firmware are up to date",
1529 dev->data->port_id);
1533 "port %u CRC stripping is %s, %u bytes will be subtracted from"
1534 " incoming frames to hide it",
1536 tmpl->rxq.crc_present ? "disabled" : "enabled",
1537 tmpl->rxq.crc_present << 2);
1539 tmpl->rxq.rss_hash = !!priv->rss_conf.rss_hf &&
1540 (!!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS));
1541 tmpl->rxq.port_id = dev->data->port_id;
1544 tmpl->rxq.elts_n = log2above(desc);
1545 tmpl->rxq.rq_repl_thresh =
1546 MLX5_VPMD_RXQ_RPLNSH_THRESH(1 << tmpl->rxq.elts_n);
1548 (struct rte_mbuf *(*)[1 << tmpl->rxq.elts_n])(tmpl + 1);
1550 tmpl->rxq.uar_lock_cq = &priv->sh->uar_lock_cq;
1552 tmpl->rxq.idx = idx;
1553 rte_atomic32_inc(&tmpl->refcnt);
1554 LIST_INSERT_HEAD(&priv->rxqsctrl, tmpl, next);
1562 * Create a DPDK Rx hairpin queue.
1565 * Pointer to Ethernet device.
1569 * Number of descriptors to configure in queue.
1570 * @param hairpin_conf
1571 * The hairpin binding configuration.
1574 * A DPDK queue object on success, NULL otherwise and rte_errno is set.
1576 struct mlx5_rxq_ctrl *
1577 mlx5_rxq_hairpin_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1578 const struct rte_eth_hairpin_conf *hairpin_conf)
1580 struct mlx5_priv *priv = dev->data->dev_private;
1581 struct mlx5_rxq_ctrl *tmpl;
1583 tmpl = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, sizeof(*tmpl), 0,
1589 tmpl->type = MLX5_RXQ_TYPE_HAIRPIN;
1590 tmpl->socket = SOCKET_ID_ANY;
1591 tmpl->rxq.rss_hash = 0;
1592 tmpl->rxq.port_id = dev->data->port_id;
1594 tmpl->rxq.mp = NULL;
1595 tmpl->rxq.elts_n = log2above(desc);
1596 tmpl->rxq.elts = NULL;
1597 tmpl->rxq.mr_ctrl.cache_bh = (struct mlx5_mr_btree) { 0 };
1598 tmpl->hairpin_conf = *hairpin_conf;
1599 tmpl->rxq.idx = idx;
1600 rte_atomic32_inc(&tmpl->refcnt);
1601 LIST_INSERT_HEAD(&priv->rxqsctrl, tmpl, next);
1609 * Pointer to Ethernet device.
1614 * A pointer to the queue if it exists, NULL otherwise.
1616 struct mlx5_rxq_ctrl *
1617 mlx5_rxq_get(struct rte_eth_dev *dev, uint16_t idx)
1619 struct mlx5_priv *priv = dev->data->dev_private;
1620 struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[idx];
1621 struct mlx5_rxq_ctrl *rxq_ctrl = NULL;
1624 rxq_ctrl = container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
1625 rte_atomic32_inc(&rxq_ctrl->refcnt);
1631 * Release a Rx queue.
1634 * Pointer to Ethernet device.
1639 * 1 while a reference on it exists, 0 when freed.
1642 mlx5_rxq_release(struct rte_eth_dev *dev, uint16_t idx)
1644 struct mlx5_priv *priv = dev->data->dev_private;
1645 struct mlx5_rxq_ctrl *rxq_ctrl;
1647 if (!(*priv->rxqs)[idx])
1649 rxq_ctrl = container_of((*priv->rxqs)[idx], struct mlx5_rxq_ctrl, rxq);
1650 if (!rte_atomic32_dec_and_test(&rxq_ctrl->refcnt))
1652 if (rxq_ctrl->obj) {
1653 priv->obj_ops->rxq_obj_release(rxq_ctrl->obj);
1654 rxq_ctrl->obj = NULL;
1656 if (rxq_ctrl->type == MLX5_RXQ_TYPE_STANDARD)
1657 mlx5_mr_btree_free(&rxq_ctrl->rxq.mr_ctrl.cache_bh);
1658 LIST_REMOVE(rxq_ctrl, next);
1659 mlx5_free(rxq_ctrl);
1660 (*priv->rxqs)[idx] = NULL;
1665 * Verify the Rx Queue list is empty
1668 * Pointer to Ethernet device.
1671 * The number of object not released.
1674 mlx5_rxq_verify(struct rte_eth_dev *dev)
1676 struct mlx5_priv *priv = dev->data->dev_private;
1677 struct mlx5_rxq_ctrl *rxq_ctrl;
1680 LIST_FOREACH(rxq_ctrl, &priv->rxqsctrl, next) {
1681 DRV_LOG(DEBUG, "port %u Rx Queue %u still referenced",
1682 dev->data->port_id, rxq_ctrl->rxq.idx);
1689 * Get a Rx queue type.
1692 * Pointer to Ethernet device.
1697 * The Rx queue type.
1700 mlx5_rxq_get_type(struct rte_eth_dev *dev, uint16_t idx)
1702 struct mlx5_priv *priv = dev->data->dev_private;
1703 struct mlx5_rxq_ctrl *rxq_ctrl = NULL;
1705 if (idx < priv->rxqs_n && (*priv->rxqs)[idx]) {
1706 rxq_ctrl = container_of((*priv->rxqs)[idx],
1707 struct mlx5_rxq_ctrl,
1709 return rxq_ctrl->type;
1711 return MLX5_RXQ_TYPE_UNDEFINED;
1715 * Create an indirection table.
1718 * Pointer to Ethernet device.
1720 * Queues entering in the indirection table.
1722 * Number of queues in the array.
1725 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
1727 static struct mlx5_ind_table_obj *
1728 mlx5_ind_table_obj_new(struct rte_eth_dev *dev, const uint16_t *queues,
1729 uint32_t queues_n, enum mlx5_ind_tbl_type type)
1731 struct mlx5_priv *priv = dev->data->dev_private;
1732 struct mlx5_ind_table_obj *ind_tbl;
1733 unsigned int i = 0, j = 0, k = 0;
1735 ind_tbl = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*ind_tbl) +
1736 queues_n * sizeof(uint16_t), 0, SOCKET_ID_ANY);
1741 ind_tbl->type = type;
1742 if (ind_tbl->type == MLX5_IND_TBL_TYPE_IBV) {
1743 const unsigned int wq_n = rte_is_power_of_2(queues_n) ?
1744 log2above(queues_n) :
1745 log2above(priv->config.ind_table_max_size);
1746 struct ibv_wq *wq[1 << wq_n];
1748 for (i = 0; i != queues_n; ++i) {
1749 struct mlx5_rxq_ctrl *rxq = mlx5_rxq_get(dev,
1753 wq[i] = rxq->obj->wq;
1754 ind_tbl->queues[i] = queues[i];
1756 ind_tbl->queues_n = queues_n;
1757 /* Finalise indirection table. */
1758 k = i; /* Retain value of i for use in error case. */
1759 for (j = 0; k != (unsigned int)(1 << wq_n); ++k, ++j)
1761 ind_tbl->ind_table = mlx5_glue->create_rwq_ind_table
1763 &(struct ibv_rwq_ind_table_init_attr){
1764 .log_ind_tbl_size = wq_n,
1768 if (!ind_tbl->ind_table) {
1772 } else { /* ind_tbl->type == MLX5_IND_TBL_TYPE_DEVX */
1773 struct mlx5_devx_rqt_attr *rqt_attr = NULL;
1774 const unsigned int rqt_n =
1775 1 << (rte_is_power_of_2(queues_n) ?
1776 log2above(queues_n) :
1777 log2above(priv->config.ind_table_max_size));
1779 rqt_attr = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rqt_attr) +
1780 rqt_n * sizeof(uint32_t), 0,
1783 DRV_LOG(ERR, "port %u cannot allocate RQT resources",
1784 dev->data->port_id);
1788 rqt_attr->rqt_max_size = priv->config.ind_table_max_size;
1789 rqt_attr->rqt_actual_size = rqt_n;
1790 for (i = 0; i != queues_n; ++i) {
1791 struct mlx5_rxq_ctrl *rxq = mlx5_rxq_get(dev,
1795 rqt_attr->rq_list[i] = rxq->obj->rq->id;
1796 ind_tbl->queues[i] = queues[i];
1798 k = i; /* Retain value of i for use in error case. */
1799 for (j = 0; k != rqt_n; ++k, ++j)
1800 rqt_attr->rq_list[k] = rqt_attr->rq_list[j];
1801 ind_tbl->rqt = mlx5_devx_cmd_create_rqt(priv->sh->ctx,
1803 mlx5_free(rqt_attr);
1804 if (!ind_tbl->rqt) {
1805 DRV_LOG(ERR, "port %u cannot create DevX RQT",
1806 dev->data->port_id);
1810 ind_tbl->queues_n = queues_n;
1812 rte_atomic32_inc(&ind_tbl->refcnt);
1813 LIST_INSERT_HEAD(&priv->ind_tbls, ind_tbl, next);
1816 for (j = 0; j < i; j++)
1817 mlx5_rxq_release(dev, ind_tbl->queues[j]);
1819 DEBUG("port %u cannot create indirection table", dev->data->port_id);
1824 * Get an indirection table.
1827 * Pointer to Ethernet device.
1829 * Queues entering in the indirection table.
1831 * Number of queues in the array.
1834 * An indirection table if found.
1836 static struct mlx5_ind_table_obj *
1837 mlx5_ind_table_obj_get(struct rte_eth_dev *dev, const uint16_t *queues,
1840 struct mlx5_priv *priv = dev->data->dev_private;
1841 struct mlx5_ind_table_obj *ind_tbl;
1843 LIST_FOREACH(ind_tbl, &priv->ind_tbls, next) {
1844 if ((ind_tbl->queues_n == queues_n) &&
1845 (memcmp(ind_tbl->queues, queues,
1846 ind_tbl->queues_n * sizeof(ind_tbl->queues[0]))
1853 rte_atomic32_inc(&ind_tbl->refcnt);
1854 for (i = 0; i != ind_tbl->queues_n; ++i)
1855 mlx5_rxq_get(dev, ind_tbl->queues[i]);
1861 * Release an indirection table.
1864 * Pointer to Ethernet device.
1866 * Indirection table to release.
1869 * 1 while a reference on it exists, 0 when freed.
1872 mlx5_ind_table_obj_release(struct rte_eth_dev *dev,
1873 struct mlx5_ind_table_obj *ind_tbl)
1877 if (rte_atomic32_dec_and_test(&ind_tbl->refcnt)) {
1878 if (ind_tbl->type == MLX5_IND_TBL_TYPE_IBV)
1879 claim_zero(mlx5_glue->destroy_rwq_ind_table
1880 (ind_tbl->ind_table));
1881 else if (ind_tbl->type == MLX5_IND_TBL_TYPE_DEVX)
1882 claim_zero(mlx5_devx_cmd_destroy(ind_tbl->rqt));
1884 for (i = 0; i != ind_tbl->queues_n; ++i)
1885 claim_nonzero(mlx5_rxq_release(dev, ind_tbl->queues[i]));
1886 if (!rte_atomic32_read(&ind_tbl->refcnt)) {
1887 LIST_REMOVE(ind_tbl, next);
1895 * Verify the Rx Queue list is empty
1898 * Pointer to Ethernet device.
1901 * The number of object not released.
1904 mlx5_ind_table_obj_verify(struct rte_eth_dev *dev)
1906 struct mlx5_priv *priv = dev->data->dev_private;
1907 struct mlx5_ind_table_obj *ind_tbl;
1910 LIST_FOREACH(ind_tbl, &priv->ind_tbls, next) {
1912 "port %u indirection table obj %p still referenced",
1913 dev->data->port_id, (void *)ind_tbl);
1920 * Create an Rx Hash queue.
1923 * Pointer to Ethernet device.
1925 * RSS key for the Rx hash queue.
1926 * @param rss_key_len
1928 * @param hash_fields
1929 * Verbs protocol hash field to make the RSS on.
1931 * Queues entering in hash queue. In case of empty hash_fields only the
1932 * first queue index will be taken for the indirection table.
1939 * The Verbs/DevX object initialised index, 0 otherwise and rte_errno is set.
1942 mlx5_hrxq_new(struct rte_eth_dev *dev,
1943 const uint8_t *rss_key, uint32_t rss_key_len,
1944 uint64_t hash_fields,
1945 const uint16_t *queues, uint32_t queues_n,
1946 int tunnel __rte_unused)
1948 struct mlx5_priv *priv = dev->data->dev_private;
1949 struct mlx5_hrxq *hrxq = NULL;
1950 uint32_t hrxq_idx = 0;
1951 struct ibv_qp *qp = NULL;
1952 struct mlx5_ind_table_obj *ind_tbl;
1954 struct mlx5_devx_obj *tir = NULL;
1955 struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[queues[0]];
1956 struct mlx5_rxq_ctrl *rxq_ctrl =
1957 container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
1959 queues_n = hash_fields ? queues_n : 1;
1960 ind_tbl = mlx5_ind_table_obj_get(dev, queues, queues_n);
1962 enum mlx5_ind_tbl_type type;
1964 type = rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_IBV ?
1965 MLX5_IND_TBL_TYPE_IBV : MLX5_IND_TBL_TYPE_DEVX;
1966 ind_tbl = mlx5_ind_table_obj_new(dev, queues, queues_n, type);
1972 if (ind_tbl->type == MLX5_IND_TBL_TYPE_IBV) {
1973 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1974 struct mlx5dv_qp_init_attr qp_init_attr;
1976 memset(&qp_init_attr, 0, sizeof(qp_init_attr));
1978 qp_init_attr.comp_mask =
1979 MLX5DV_QP_INIT_ATTR_MASK_QP_CREATE_FLAGS;
1980 qp_init_attr.create_flags =
1981 MLX5DV_QP_CREATE_TUNNEL_OFFLOADS;
1983 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
1984 if (dev->data->dev_conf.lpbk_mode) {
1986 * Allow packet sent from NIC loop back
1987 * w/o source MAC check.
1989 qp_init_attr.comp_mask |=
1990 MLX5DV_QP_INIT_ATTR_MASK_QP_CREATE_FLAGS;
1991 qp_init_attr.create_flags |=
1992 MLX5DV_QP_CREATE_TIR_ALLOW_SELF_LOOPBACK_UC;
1995 qp = mlx5_glue->dv_create_qp
1997 &(struct ibv_qp_init_attr_ex){
1998 .qp_type = IBV_QPT_RAW_PACKET,
2000 IBV_QP_INIT_ATTR_PD |
2001 IBV_QP_INIT_ATTR_IND_TABLE |
2002 IBV_QP_INIT_ATTR_RX_HASH,
2003 .rx_hash_conf = (struct ibv_rx_hash_conf){
2005 IBV_RX_HASH_FUNC_TOEPLITZ,
2006 .rx_hash_key_len = rss_key_len,
2008 (void *)(uintptr_t)rss_key,
2009 .rx_hash_fields_mask = hash_fields,
2011 .rwq_ind_tbl = ind_tbl->ind_table,
2016 qp = mlx5_glue->create_qp_ex
2018 &(struct ibv_qp_init_attr_ex){
2019 .qp_type = IBV_QPT_RAW_PACKET,
2021 IBV_QP_INIT_ATTR_PD |
2022 IBV_QP_INIT_ATTR_IND_TABLE |
2023 IBV_QP_INIT_ATTR_RX_HASH,
2024 .rx_hash_conf = (struct ibv_rx_hash_conf){
2026 IBV_RX_HASH_FUNC_TOEPLITZ,
2027 .rx_hash_key_len = rss_key_len,
2029 (void *)(uintptr_t)rss_key,
2030 .rx_hash_fields_mask = hash_fields,
2032 .rwq_ind_tbl = ind_tbl->ind_table,
2040 } else { /* ind_tbl->type == MLX5_IND_TBL_TYPE_DEVX */
2041 struct mlx5_devx_tir_attr tir_attr;
2045 /* Enable TIR LRO only if all the queues were configured for. */
2046 for (i = 0; i < queues_n; ++i) {
2047 if (!(*priv->rxqs)[queues[i]]->lro) {
2052 memset(&tir_attr, 0, sizeof(tir_attr));
2053 tir_attr.disp_type = MLX5_TIRC_DISP_TYPE_INDIRECT;
2054 tir_attr.rx_hash_fn = MLX5_RX_HASH_FN_TOEPLITZ;
2055 tir_attr.tunneled_offload_en = !!tunnel;
2056 /* If needed, translate hash_fields bitmap to PRM format. */
2058 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
2059 struct mlx5_rx_hash_field_select *rx_hash_field_select =
2060 hash_fields & IBV_RX_HASH_INNER ?
2061 &tir_attr.rx_hash_field_selector_inner :
2062 &tir_attr.rx_hash_field_selector_outer;
2064 struct mlx5_rx_hash_field_select *rx_hash_field_select =
2065 &tir_attr.rx_hash_field_selector_outer;
2068 /* 1 bit: 0: IPv4, 1: IPv6. */
2069 rx_hash_field_select->l3_prot_type =
2070 !!(hash_fields & MLX5_IPV6_IBV_RX_HASH);
2071 /* 1 bit: 0: TCP, 1: UDP. */
2072 rx_hash_field_select->l4_prot_type =
2073 !!(hash_fields & MLX5_UDP_IBV_RX_HASH);
2074 /* Bitmask which sets which fields to use in RX Hash. */
2075 rx_hash_field_select->selected_fields =
2076 ((!!(hash_fields & MLX5_L3_SRC_IBV_RX_HASH)) <<
2077 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_SRC_IP) |
2078 (!!(hash_fields & MLX5_L3_DST_IBV_RX_HASH)) <<
2079 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_DST_IP |
2080 (!!(hash_fields & MLX5_L4_SRC_IBV_RX_HASH)) <<
2081 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_L4_SPORT |
2082 (!!(hash_fields & MLX5_L4_DST_IBV_RX_HASH)) <<
2083 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_L4_DPORT;
2085 if (rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_DEVX_HAIRPIN)
2086 tir_attr.transport_domain = priv->sh->td->id;
2088 tir_attr.transport_domain = priv->sh->tdn;
2089 memcpy(tir_attr.rx_hash_toeplitz_key, rss_key,
2090 MLX5_RSS_HASH_KEY_LEN);
2091 tir_attr.indirect_table = ind_tbl->rqt->id;
2092 if (dev->data->dev_conf.lpbk_mode)
2093 tir_attr.self_lb_block =
2094 MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST;
2096 tir_attr.lro_timeout_period_usecs =
2097 priv->config.lro.timeout;
2098 tir_attr.lro_max_msg_sz = priv->max_lro_msg_size;
2099 tir_attr.lro_enable_mask =
2100 MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO |
2101 MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO;
2103 tir = mlx5_devx_cmd_create_tir(priv->sh->ctx, &tir_attr);
2105 DRV_LOG(ERR, "port %u cannot create DevX TIR",
2106 dev->data->port_id);
2111 hrxq = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_HRXQ], &hrxq_idx);
2114 hrxq->ind_table = ind_tbl;
2115 if (ind_tbl->type == MLX5_IND_TBL_TYPE_IBV) {
2117 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
2119 mlx5_glue->dv_create_flow_action_dest_ibv_qp(hrxq->qp);
2120 if (!hrxq->action) {
2125 } else { /* ind_tbl->type == MLX5_IND_TBL_TYPE_DEVX */
2127 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
2128 hrxq->action = mlx5_glue->dv_create_flow_action_dest_devx_tir
2130 if (!hrxq->action) {
2136 hrxq->rss_key_len = rss_key_len;
2137 hrxq->hash_fields = hash_fields;
2138 memcpy(hrxq->rss_key, rss_key, rss_key_len);
2139 rte_atomic32_inc(&hrxq->refcnt);
2140 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_HRXQ], &priv->hrxqs, hrxq_idx,
2144 err = rte_errno; /* Save rte_errno before cleanup. */
2145 mlx5_ind_table_obj_release(dev, ind_tbl);
2147 claim_zero(mlx5_glue->destroy_qp(qp));
2149 claim_zero(mlx5_devx_cmd_destroy(tir));
2151 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
2152 rte_errno = err; /* Restore rte_errno. */
2157 * Get an Rx Hash queue.
2160 * Pointer to Ethernet device.
2162 * RSS configuration for the Rx hash queue.
2164 * Queues entering in hash queue. In case of empty hash_fields only the
2165 * first queue index will be taken for the indirection table.
2170 * An hash Rx queue index on success.
2173 mlx5_hrxq_get(struct rte_eth_dev *dev,
2174 const uint8_t *rss_key, uint32_t rss_key_len,
2175 uint64_t hash_fields,
2176 const uint16_t *queues, uint32_t queues_n)
2178 struct mlx5_priv *priv = dev->data->dev_private;
2179 struct mlx5_hrxq *hrxq;
2182 queues_n = hash_fields ? queues_n : 1;
2183 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_HRXQ], priv->hrxqs, idx,
2185 struct mlx5_ind_table_obj *ind_tbl;
2187 if (hrxq->rss_key_len != rss_key_len)
2189 if (memcmp(hrxq->rss_key, rss_key, rss_key_len))
2191 if (hrxq->hash_fields != hash_fields)
2193 ind_tbl = mlx5_ind_table_obj_get(dev, queues, queues_n);
2196 if (ind_tbl != hrxq->ind_table) {
2197 mlx5_ind_table_obj_release(dev, ind_tbl);
2200 rte_atomic32_inc(&hrxq->refcnt);
2207 * Release the hash Rx queue.
2210 * Pointer to Ethernet device.
2212 * Index to Hash Rx queue to release.
2215 * 1 while a reference on it exists, 0 when freed.
2218 mlx5_hrxq_release(struct rte_eth_dev *dev, uint32_t hrxq_idx)
2220 struct mlx5_priv *priv = dev->data->dev_private;
2221 struct mlx5_hrxq *hrxq;
2223 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
2226 if (rte_atomic32_dec_and_test(&hrxq->refcnt)) {
2227 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
2228 mlx5_glue->destroy_flow_action(hrxq->action);
2230 if (hrxq->ind_table->type == MLX5_IND_TBL_TYPE_IBV)
2231 claim_zero(mlx5_glue->destroy_qp(hrxq->qp));
2232 else /* hrxq->ind_table->type == MLX5_IND_TBL_TYPE_DEVX */
2233 claim_zero(mlx5_devx_cmd_destroy(hrxq->tir));
2234 mlx5_ind_table_obj_release(dev, hrxq->ind_table);
2235 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_HRXQ], &priv->hrxqs,
2236 hrxq_idx, hrxq, next);
2237 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
2240 claim_nonzero(mlx5_ind_table_obj_release(dev, hrxq->ind_table));
2245 * Verify the Rx Queue list is empty
2248 * Pointer to Ethernet device.
2251 * The number of object not released.
2254 mlx5_hrxq_verify(struct rte_eth_dev *dev)
2256 struct mlx5_priv *priv = dev->data->dev_private;
2257 struct mlx5_hrxq *hrxq;
2261 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_HRXQ], priv->hrxqs, idx,
2264 "port %u hash Rx queue %p still referenced",
2265 dev->data->port_id, (void *)hrxq);
2272 * Create a drop Rx queue Verbs/DevX object.
2275 * Pointer to Ethernet device.
2278 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
2280 static struct mlx5_rxq_obj *
2281 mlx5_rxq_obj_drop_new(struct rte_eth_dev *dev)
2283 struct mlx5_priv *priv = dev->data->dev_private;
2284 struct ibv_context *ctx = priv->sh->ctx;
2286 struct ibv_wq *wq = NULL;
2287 struct mlx5_rxq_obj *rxq;
2289 if (priv->drop_queue.rxq)
2290 return priv->drop_queue.rxq;
2291 cq = mlx5_glue->create_cq(ctx, 1, NULL, NULL, 0);
2293 DEBUG("port %u cannot allocate CQ for drop queue",
2294 dev->data->port_id);
2298 wq = mlx5_glue->create_wq(ctx,
2299 &(struct ibv_wq_init_attr){
2300 .wq_type = IBV_WQT_RQ,
2307 DEBUG("port %u cannot allocate WQ for drop queue",
2308 dev->data->port_id);
2312 rxq = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rxq), 0, SOCKET_ID_ANY);
2314 DEBUG("port %u cannot allocate drop Rx queue memory",
2315 dev->data->port_id);
2321 priv->drop_queue.rxq = rxq;
2325 claim_zero(mlx5_glue->destroy_wq(wq));
2327 claim_zero(mlx5_glue->destroy_cq(cq));
2332 * Release a drop Rx queue Verbs/DevX object.
2335 * Pointer to Ethernet device.
2338 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
2341 mlx5_rxq_obj_drop_release(struct rte_eth_dev *dev)
2343 struct mlx5_priv *priv = dev->data->dev_private;
2344 struct mlx5_rxq_obj *rxq = priv->drop_queue.rxq;
2347 claim_zero(mlx5_glue->destroy_wq(rxq->wq));
2349 claim_zero(mlx5_glue->destroy_cq(rxq->ibv_cq));
2351 priv->drop_queue.rxq = NULL;
2355 * Create a drop indirection table.
2358 * Pointer to Ethernet device.
2361 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
2363 static struct mlx5_ind_table_obj *
2364 mlx5_ind_table_obj_drop_new(struct rte_eth_dev *dev)
2366 struct mlx5_priv *priv = dev->data->dev_private;
2367 struct mlx5_ind_table_obj *ind_tbl;
2368 struct mlx5_rxq_obj *rxq;
2369 struct mlx5_ind_table_obj tmpl;
2371 rxq = mlx5_rxq_obj_drop_new(dev);
2374 tmpl.ind_table = mlx5_glue->create_rwq_ind_table
2376 &(struct ibv_rwq_ind_table_init_attr){
2377 .log_ind_tbl_size = 0,
2378 .ind_tbl = (struct ibv_wq **)&rxq->wq,
2381 if (!tmpl.ind_table) {
2382 DEBUG("port %u cannot allocate indirection table for drop"
2384 dev->data->port_id);
2388 ind_tbl = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*ind_tbl), 0,
2394 ind_tbl->ind_table = tmpl.ind_table;
2397 mlx5_rxq_obj_drop_release(dev);
2402 * Release a drop indirection table.
2405 * Pointer to Ethernet device.
2408 mlx5_ind_table_obj_drop_release(struct rte_eth_dev *dev)
2410 struct mlx5_priv *priv = dev->data->dev_private;
2411 struct mlx5_ind_table_obj *ind_tbl = priv->drop_queue.hrxq->ind_table;
2413 claim_zero(mlx5_glue->destroy_rwq_ind_table(ind_tbl->ind_table));
2414 mlx5_rxq_obj_drop_release(dev);
2416 priv->drop_queue.hrxq->ind_table = NULL;
2420 * Create a drop Rx Hash queue.
2423 * Pointer to Ethernet device.
2426 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
2429 mlx5_hrxq_drop_new(struct rte_eth_dev *dev)
2431 struct mlx5_priv *priv = dev->data->dev_private;
2432 struct mlx5_ind_table_obj *ind_tbl = NULL;
2433 struct ibv_qp *qp = NULL;
2434 struct mlx5_hrxq *hrxq = NULL;
2436 if (priv->drop_queue.hrxq) {
2437 rte_atomic32_inc(&priv->drop_queue.hrxq->refcnt);
2438 return priv->drop_queue.hrxq;
2440 hrxq = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*hrxq), 0, SOCKET_ID_ANY);
2443 "port %u cannot allocate memory for drop queue",
2444 dev->data->port_id);
2448 priv->drop_queue.hrxq = hrxq;
2449 ind_tbl = mlx5_ind_table_obj_drop_new(dev);
2452 hrxq->ind_table = ind_tbl;
2453 qp = mlx5_glue->create_qp_ex(priv->sh->ctx,
2454 &(struct ibv_qp_init_attr_ex){
2455 .qp_type = IBV_QPT_RAW_PACKET,
2457 IBV_QP_INIT_ATTR_PD |
2458 IBV_QP_INIT_ATTR_IND_TABLE |
2459 IBV_QP_INIT_ATTR_RX_HASH,
2460 .rx_hash_conf = (struct ibv_rx_hash_conf){
2462 IBV_RX_HASH_FUNC_TOEPLITZ,
2463 .rx_hash_key_len = MLX5_RSS_HASH_KEY_LEN,
2464 .rx_hash_key = rss_hash_default_key,
2465 .rx_hash_fields_mask = 0,
2467 .rwq_ind_tbl = ind_tbl->ind_table,
2471 DEBUG("port %u cannot allocate QP for drop queue",
2472 dev->data->port_id);
2477 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
2478 hrxq->action = mlx5_glue->dv_create_flow_action_dest_ibv_qp(hrxq->qp);
2479 if (!hrxq->action) {
2484 rte_atomic32_set(&hrxq->refcnt, 1);
2487 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
2488 if (hrxq && hrxq->action)
2489 mlx5_glue->destroy_flow_action(hrxq->action);
2492 claim_zero(mlx5_glue->destroy_qp(hrxq->qp));
2494 mlx5_ind_table_obj_drop_release(dev);
2496 priv->drop_queue.hrxq = NULL;
2503 * Release a drop hash Rx queue.
2506 * Pointer to Ethernet device.
2509 mlx5_hrxq_drop_release(struct rte_eth_dev *dev)
2511 struct mlx5_priv *priv = dev->data->dev_private;
2512 struct mlx5_hrxq *hrxq = priv->drop_queue.hrxq;
2514 if (rte_atomic32_dec_and_test(&hrxq->refcnt)) {
2515 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
2516 mlx5_glue->destroy_flow_action(hrxq->action);
2518 claim_zero(mlx5_glue->destroy_qp(hrxq->qp));
2519 mlx5_ind_table_obj_drop_release(dev);
2521 priv->drop_queue.hrxq = NULL;
2527 * Set the Rx queue timestamp conversion parameters
2530 * Pointer to the Ethernet device structure.
2533 mlx5_rxq_timestamp_set(struct rte_eth_dev *dev)
2535 struct mlx5_priv *priv = dev->data->dev_private;
2536 struct mlx5_dev_ctx_shared *sh = priv->sh;
2537 struct mlx5_rxq_data *data;
2540 for (i = 0; i != priv->rxqs_n; ++i) {
2541 if (!(*priv->rxqs)[i])
2543 data = (*priv->rxqs)[i];
2545 data->rt_timestamp = priv->config.rt_timestamp;