1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
16 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
18 #pragma GCC diagnostic ignored "-Wpedantic"
20 #include <infiniband/verbs.h>
22 #pragma GCC diagnostic error "-Wpedantic"
26 #include <rte_malloc.h>
27 #include <rte_ethdev_driver.h>
28 #include <rte_common.h>
30 #include "mlx5_utils.h"
31 #include "mlx5_defs.h"
33 #include "mlx5_rxtx.h"
34 #include "mlx5_autoconf.h"
35 #include "mlx5_glue.h"
38 * Allocate TX queue elements.
41 * Pointer to TX queue structure.
44 txq_alloc_elts(struct mlx5_txq_ctrl *txq_ctrl)
46 const unsigned int elts_n = 1 << txq_ctrl->txq.elts_n;
49 for (i = 0; (i != elts_n); ++i)
50 txq_ctrl->txq.elts[i] = NULL;
51 DRV_LOG(DEBUG, "port %u Tx queue %u allocated and configured %u WRs",
52 PORT_ID(txq_ctrl->priv), txq_ctrl->txq.idx, elts_n);
53 txq_ctrl->txq.elts_head = 0;
54 txq_ctrl->txq.elts_tail = 0;
55 txq_ctrl->txq.elts_comp = 0;
59 * Free TX queue elements.
62 * Pointer to TX queue structure.
65 txq_free_elts(struct mlx5_txq_ctrl *txq_ctrl)
67 const uint16_t elts_n = 1 << txq_ctrl->txq.elts_n;
68 const uint16_t elts_m = elts_n - 1;
69 uint16_t elts_head = txq_ctrl->txq.elts_head;
70 uint16_t elts_tail = txq_ctrl->txq.elts_tail;
71 struct rte_mbuf *(*elts)[elts_n] = &txq_ctrl->txq.elts;
73 DRV_LOG(DEBUG, "port %u Tx queue %u freeing WRs",
74 PORT_ID(txq_ctrl->priv), txq_ctrl->txq.idx);
75 txq_ctrl->txq.elts_head = 0;
76 txq_ctrl->txq.elts_tail = 0;
77 txq_ctrl->txq.elts_comp = 0;
79 while (elts_tail != elts_head) {
80 struct rte_mbuf *elt = (*elts)[elts_tail & elts_m];
83 rte_pktmbuf_free_seg(elt);
86 memset(&(*elts)[elts_tail & elts_m],
88 sizeof((*elts)[elts_tail & elts_m]));
95 * Returns the per-port supported offloads.
98 * Pointer to Ethernet device.
101 * Supported Tx offloads.
104 mlx5_get_tx_port_offloads(struct rte_eth_dev *dev)
106 struct mlx5_priv *priv = dev->data->dev_private;
107 uint64_t offloads = (DEV_TX_OFFLOAD_MULTI_SEGS |
108 DEV_TX_OFFLOAD_VLAN_INSERT);
109 struct mlx5_dev_config *config = &priv->config;
112 offloads |= (DEV_TX_OFFLOAD_IPV4_CKSUM |
113 DEV_TX_OFFLOAD_UDP_CKSUM |
114 DEV_TX_OFFLOAD_TCP_CKSUM);
116 offloads |= DEV_TX_OFFLOAD_TCP_TSO;
119 offloads |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
121 offloads |= (DEV_TX_OFFLOAD_IP_TNL_TSO |
122 DEV_TX_OFFLOAD_UDP_TNL_TSO);
124 if (config->tunnel_en) {
126 offloads |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
128 offloads |= (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
129 DEV_TX_OFFLOAD_GRE_TNL_TSO);
131 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
132 if (config->dv_flow_en)
133 offloads |= DEV_TX_OFFLOAD_MATCH_METADATA;
139 * DPDK callback to configure a TX queue.
142 * Pointer to Ethernet device structure.
146 * Number of descriptors to configure in queue.
148 * NUMA socket on which memory must be allocated.
150 * Thresholds parameters.
153 * 0 on success, a negative errno value otherwise and rte_errno is set.
156 mlx5_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
157 unsigned int socket, const struct rte_eth_txconf *conf)
159 struct mlx5_priv *priv = dev->data->dev_private;
160 struct mlx5_txq_data *txq = (*priv->txqs)[idx];
161 struct mlx5_txq_ctrl *txq_ctrl =
162 container_of(txq, struct mlx5_txq_ctrl, txq);
164 if (desc <= MLX5_TX_COMP_THRESH) {
166 "port %u number of descriptors requested for Tx queue"
167 " %u must be higher than MLX5_TX_COMP_THRESH, using %u"
169 dev->data->port_id, idx, MLX5_TX_COMP_THRESH + 1, desc);
170 desc = MLX5_TX_COMP_THRESH + 1;
172 if (!rte_is_power_of_2(desc)) {
173 desc = 1 << log2above(desc);
175 "port %u increased number of descriptors in Tx queue"
176 " %u to the next power of two (%d)",
177 dev->data->port_id, idx, desc);
179 DRV_LOG(DEBUG, "port %u configuring queue %u for %u descriptors",
180 dev->data->port_id, idx, desc);
181 if (idx >= priv->txqs_n) {
182 DRV_LOG(ERR, "port %u Tx queue index out of range (%u >= %u)",
183 dev->data->port_id, idx, priv->txqs_n);
184 rte_errno = EOVERFLOW;
187 if (!mlx5_txq_releasable(dev, idx)) {
189 DRV_LOG(ERR, "port %u unable to release queue index %u",
190 dev->data->port_id, idx);
193 mlx5_txq_release(dev, idx);
194 txq_ctrl = mlx5_txq_new(dev, idx, desc, socket, conf);
196 DRV_LOG(ERR, "port %u unable to allocate queue index %u",
197 dev->data->port_id, idx);
200 DRV_LOG(DEBUG, "port %u adding Tx queue %u to list",
201 dev->data->port_id, idx);
202 (*priv->txqs)[idx] = &txq_ctrl->txq;
207 * DPDK callback to release a TX queue.
210 * Generic TX queue pointer.
213 mlx5_tx_queue_release(void *dpdk_txq)
215 struct mlx5_txq_data *txq = (struct mlx5_txq_data *)dpdk_txq;
216 struct mlx5_txq_ctrl *txq_ctrl;
217 struct mlx5_priv *priv;
222 txq_ctrl = container_of(txq, struct mlx5_txq_ctrl, txq);
223 priv = txq_ctrl->priv;
224 for (i = 0; (i != priv->txqs_n); ++i)
225 if ((*priv->txqs)[i] == txq) {
226 mlx5_txq_release(ETH_DEV(priv), i);
227 DRV_LOG(DEBUG, "port %u removing Tx queue %u from list",
228 PORT_ID(priv), txq->idx);
234 * Initialize Tx UAR registers for primary process.
237 * Pointer to Tx queue control structure.
240 txq_uar_init(struct mlx5_txq_ctrl *txq_ctrl)
242 struct mlx5_priv *priv = txq_ctrl->priv;
243 struct mlx5_proc_priv *ppriv = MLX5_PROC_PRIV(PORT_ID(priv));
245 unsigned int lock_idx;
246 const size_t page_size = sysconf(_SC_PAGESIZE);
249 assert(rte_eal_process_type() == RTE_PROC_PRIMARY);
251 ppriv->uar_table[txq_ctrl->txq.idx] = txq_ctrl->bf_reg;
253 /* Assign an UAR lock according to UAR page number */
254 lock_idx = (txq_ctrl->uar_mmap_offset / page_size) &
255 MLX5_UAR_PAGE_NUM_MASK;
256 txq_ctrl->txq.uar_lock = &priv->uar_lock[lock_idx];
261 * Remap UAR register of a Tx queue for secondary process.
263 * Remapped address is stored at the table in the process private structure of
264 * the device, indexed by queue index.
267 * Pointer to Tx queue control structure.
269 * Verbs file descriptor to map UAR pages.
272 * 0 on success, a negative errno value otherwise and rte_errno is set.
275 txq_uar_init_secondary(struct mlx5_txq_ctrl *txq_ctrl, int fd)
277 struct mlx5_priv *priv = txq_ctrl->priv;
278 struct mlx5_proc_priv *ppriv = MLX5_PROC_PRIV(PORT_ID(priv));
279 struct mlx5_txq_data *txq = &txq_ctrl->txq;
283 const size_t page_size = sysconf(_SC_PAGESIZE);
287 * As rdma-core, UARs are mapped in size of OS page
288 * size. Ref to libmlx5 function: mlx5_init_context()
290 uar_va = (uintptr_t)txq_ctrl->bf_reg;
291 offset = uar_va & (page_size - 1); /* Offset in page. */
292 addr = mmap(NULL, page_size, PROT_WRITE, MAP_SHARED, fd,
293 txq_ctrl->uar_mmap_offset);
294 if (addr == MAP_FAILED) {
296 "port %u mmap failed for BF reg of txq %u",
297 txq->port_id, txq->idx);
301 addr = RTE_PTR_ADD(addr, offset);
302 ppriv->uar_table[txq->idx] = addr;
307 * Unmap UAR register of a Tx queue for secondary process.
310 * Pointer to Tx queue control structure.
313 txq_uar_uninit_secondary(struct mlx5_txq_ctrl *txq_ctrl)
315 struct mlx5_proc_priv *ppriv = MLX5_PROC_PRIV(PORT_ID(txq_ctrl->priv));
316 const size_t page_size = sysconf(_SC_PAGESIZE);
319 addr = ppriv->uar_table[txq_ctrl->txq.idx];
320 munmap(RTE_PTR_ALIGN_FLOOR(addr, page_size), page_size);
324 * Initialize Tx UAR registers for secondary process.
327 * Pointer to Ethernet device.
329 * Verbs file descriptor to map UAR pages.
332 * 0 on success, a negative errno value otherwise and rte_errno is set.
335 mlx5_tx_uar_init_secondary(struct rte_eth_dev *dev, int fd)
337 struct mlx5_priv *priv = dev->data->dev_private;
338 struct mlx5_txq_data *txq;
339 struct mlx5_txq_ctrl *txq_ctrl;
343 assert(rte_eal_process_type() == RTE_PROC_SECONDARY);
344 for (i = 0; i != priv->txqs_n; ++i) {
345 if (!(*priv->txqs)[i])
347 txq = (*priv->txqs)[i];
348 txq_ctrl = container_of(txq, struct mlx5_txq_ctrl, txq);
349 assert(txq->idx == (uint16_t)i);
350 ret = txq_uar_init_secondary(txq_ctrl, fd);
358 if (!(*priv->txqs)[i])
360 txq = (*priv->txqs)[i];
361 txq_ctrl = container_of(txq, struct mlx5_txq_ctrl, txq);
362 txq_uar_uninit_secondary(txq_ctrl);
368 * Create the Tx queue Verbs object.
371 * Pointer to Ethernet device.
373 * Queue index in DPDK Tx queue array.
376 * The Verbs object initialised, NULL otherwise and rte_errno is set.
378 struct mlx5_txq_ibv *
379 mlx5_txq_ibv_new(struct rte_eth_dev *dev, uint16_t idx)
381 struct mlx5_priv *priv = dev->data->dev_private;
382 struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
383 struct mlx5_txq_ctrl *txq_ctrl =
384 container_of(txq_data, struct mlx5_txq_ctrl, txq);
385 struct mlx5_txq_ibv tmpl;
386 struct mlx5_txq_ibv *txq_ibv = NULL;
388 struct ibv_qp_init_attr_ex init;
389 struct ibv_cq_init_attr_ex cq;
390 struct ibv_qp_attr mod;
393 struct mlx5dv_qp qp = { .comp_mask = MLX5DV_QP_MASK_UAR_MMAP_OFFSET };
394 struct mlx5dv_cq cq_info;
395 struct mlx5dv_obj obj;
396 const int desc = 1 << txq_data->elts_n;
400 priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_TX_QUEUE;
401 priv->verbs_alloc_ctx.obj = txq_ctrl;
402 if (mlx5_getenv_int("MLX5_ENABLE_CQE_COMPRESSION")) {
404 "port %u MLX5_ENABLE_CQE_COMPRESSION must never be set",
409 memset(&tmpl, 0, sizeof(struct mlx5_txq_ibv));
410 attr.cq = (struct ibv_cq_init_attr_ex){
413 cqe_n = desc / MLX5_TX_COMP_THRESH +
414 1 + MLX5_TX_COMP_THRESH_INLINE_DIV;
415 tmpl.cq = mlx5_glue->create_cq(priv->sh->ctx, cqe_n, NULL, NULL, 0);
416 if (tmpl.cq == NULL) {
417 DRV_LOG(ERR, "port %u Tx queue %u CQ creation failure",
418 dev->data->port_id, idx);
422 attr.init = (struct ibv_qp_init_attr_ex){
423 /* CQ to be associated with the send queue. */
425 /* CQ to be associated with the receive queue. */
428 /* Max number of outstanding WRs. */
430 ((priv->sh->device_attr.orig_attr.max_qp_wr <
432 priv->sh->device_attr.orig_attr.max_qp_wr :
435 * Max number of scatter/gather elements in a WR,
436 * must be 1 to prevent libmlx5 from trying to affect
437 * too much memory. TX gather is not impacted by the
438 * device_attr.max_sge limit and will still work
443 .qp_type = IBV_QPT_RAW_PACKET,
445 * Do *NOT* enable this, completions events are managed per
450 .comp_mask = IBV_QP_INIT_ATTR_PD,
452 if (txq_data->inlen_send)
453 attr.init.cap.max_inline_data = txq_ctrl->max_inline_data;
454 if (txq_data->tso_en) {
455 attr.init.max_tso_header = txq_ctrl->max_tso_header;
456 attr.init.comp_mask |= IBV_QP_INIT_ATTR_MAX_TSO_HEADER;
458 tmpl.qp = mlx5_glue->create_qp_ex(priv->sh->ctx, &attr.init);
459 if (tmpl.qp == NULL) {
460 DRV_LOG(ERR, "port %u Tx queue %u QP creation failure",
461 dev->data->port_id, idx);
465 attr.mod = (struct ibv_qp_attr){
466 /* Move the QP to this state. */
467 .qp_state = IBV_QPS_INIT,
468 /* IB device port number. */
469 .port_num = (uint8_t)priv->ibv_port,
471 ret = mlx5_glue->modify_qp(tmpl.qp, &attr.mod,
472 (IBV_QP_STATE | IBV_QP_PORT));
475 "port %u Tx queue %u QP state to IBV_QPS_INIT failed",
476 dev->data->port_id, idx);
480 attr.mod = (struct ibv_qp_attr){
481 .qp_state = IBV_QPS_RTR
483 ret = mlx5_glue->modify_qp(tmpl.qp, &attr.mod, IBV_QP_STATE);
486 "port %u Tx queue %u QP state to IBV_QPS_RTR failed",
487 dev->data->port_id, idx);
491 attr.mod.qp_state = IBV_QPS_RTS;
492 ret = mlx5_glue->modify_qp(tmpl.qp, &attr.mod, IBV_QP_STATE);
495 "port %u Tx queue %u QP state to IBV_QPS_RTS failed",
496 dev->data->port_id, idx);
500 txq_ibv = rte_calloc_socket(__func__, 1, sizeof(struct mlx5_txq_ibv), 0,
503 DRV_LOG(ERR, "port %u Tx queue %u cannot allocate memory",
504 dev->data->port_id, idx);
509 obj.cq.out = &cq_info;
512 ret = mlx5_glue->dv_init_obj(&obj, MLX5DV_OBJ_CQ | MLX5DV_OBJ_QP);
517 if (cq_info.cqe_size != RTE_CACHE_LINE_SIZE) {
519 "port %u wrong MLX5_CQE_SIZE environment variable"
520 " value: it should be set to %u",
521 dev->data->port_id, RTE_CACHE_LINE_SIZE);
525 txq_data->cqe_n = log2above(cq_info.cqe_cnt);
526 txq_data->cqe_s = 1 << txq_data->cqe_n;
527 txq_data->cqe_m = txq_data->cqe_s - 1;
528 txq_data->qp_num_8s = tmpl.qp->qp_num << 8;
529 txq_data->wqes = qp.sq.buf;
530 txq_data->wqe_n = log2above(qp.sq.wqe_cnt);
531 txq_data->wqe_s = 1 << txq_data->wqe_n;
532 txq_data->wqe_m = txq_data->wqe_s - 1;
533 txq_data->wqes_end = txq_data->wqes + txq_data->wqe_s;
534 txq_data->qp_db = &qp.dbrec[MLX5_SND_DBR];
535 txq_data->cq_db = cq_info.dbrec;
536 txq_data->cqes = (volatile struct mlx5_cqe *)cq_info.buf;
541 txq_data->wqe_ci = 0;
542 txq_data->wqe_pi = 0;
543 txq_data->wqe_comp = 0;
544 txq_data->wqe_thres = txq_data->wqe_s / MLX5_TX_COMP_THRESH_INLINE_DIV;
545 txq_ibv->qp = tmpl.qp;
546 txq_ibv->cq = tmpl.cq;
547 rte_atomic32_inc(&txq_ibv->refcnt);
548 txq_ctrl->bf_reg = qp.bf.reg;
549 txq_uar_init(txq_ctrl);
550 if (qp.comp_mask & MLX5DV_QP_MASK_UAR_MMAP_OFFSET) {
551 txq_ctrl->uar_mmap_offset = qp.uar_mmap_offset;
552 DRV_LOG(DEBUG, "port %u: uar_mmap_offset 0x%"PRIx64,
553 dev->data->port_id, txq_ctrl->uar_mmap_offset);
556 "port %u failed to retrieve UAR info, invalid"
562 LIST_INSERT_HEAD(&priv->txqsibv, txq_ibv, next);
563 txq_ibv->txq_ctrl = txq_ctrl;
564 priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_NONE;
567 ret = rte_errno; /* Save rte_errno before cleanup. */
569 claim_zero(mlx5_glue->destroy_cq(tmpl.cq));
571 claim_zero(mlx5_glue->destroy_qp(tmpl.qp));
574 priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_NONE;
575 rte_errno = ret; /* Restore rte_errno. */
580 * Get an Tx queue Verbs object.
583 * Pointer to Ethernet device.
585 * Queue index in DPDK Tx queue array.
588 * The Verbs object if it exists.
590 struct mlx5_txq_ibv *
591 mlx5_txq_ibv_get(struct rte_eth_dev *dev, uint16_t idx)
593 struct mlx5_priv *priv = dev->data->dev_private;
594 struct mlx5_txq_ctrl *txq_ctrl;
596 if (idx >= priv->txqs_n)
598 if (!(*priv->txqs)[idx])
600 txq_ctrl = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq);
602 rte_atomic32_inc(&txq_ctrl->ibv->refcnt);
603 return txq_ctrl->ibv;
607 * Release an Tx verbs queue object.
610 * Verbs Tx queue object.
613 * 1 while a reference on it exists, 0 when freed.
616 mlx5_txq_ibv_release(struct mlx5_txq_ibv *txq_ibv)
619 if (rte_atomic32_dec_and_test(&txq_ibv->refcnt)) {
620 claim_zero(mlx5_glue->destroy_qp(txq_ibv->qp));
621 claim_zero(mlx5_glue->destroy_cq(txq_ibv->cq));
622 LIST_REMOVE(txq_ibv, next);
630 * Verify the Verbs Tx queue list is empty
633 * Pointer to Ethernet device.
636 * The number of object not released.
639 mlx5_txq_ibv_verify(struct rte_eth_dev *dev)
641 struct mlx5_priv *priv = dev->data->dev_private;
643 struct mlx5_txq_ibv *txq_ibv;
645 LIST_FOREACH(txq_ibv, &priv->txqsibv, next) {
646 DRV_LOG(DEBUG, "port %u Verbs Tx queue %u still referenced",
647 dev->data->port_id, txq_ibv->txq_ctrl->txq.idx);
654 * Calculate the total number of WQEBB for Tx queue.
656 * Simplified version of calc_sq_size() in rdma-core.
659 * Pointer to Tx queue control structure.
662 * The number of WQEBB.
665 txq_calc_wqebb_cnt(struct mlx5_txq_ctrl *txq_ctrl)
667 unsigned int wqe_size;
668 const unsigned int desc = 1 << txq_ctrl->txq.elts_n;
670 wqe_size = MLX5_WQE_CSEG_SIZE +
673 MLX5_ESEG_MIN_INLINE_SIZE +
674 txq_ctrl->max_inline_data;
675 return rte_align32pow2(wqe_size * desc) / MLX5_WQE_SIZE;
679 * Set Tx queue parameters from device configuration.
682 * Pointer to Tx queue control structure.
685 txq_set_params(struct mlx5_txq_ctrl *txq_ctrl)
687 struct mlx5_priv *priv = txq_ctrl->priv;
688 struct mlx5_dev_config *config = &priv->config;
689 unsigned int inlen_send; /* Inline data for ordinary SEND.*/
690 unsigned int inlen_empw; /* Inline data for enhanced MPW. */
691 unsigned int inlen_mode; /* Minimal required Inline data. */
692 unsigned int txqs_inline; /* Min Tx queues to enable inline. */
693 uint64_t dev_txoff = priv->dev_data->dev_conf.txmode.offloads;
694 bool tso = txq_ctrl->txq.offloads & (DEV_TX_OFFLOAD_TCP_TSO |
695 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
696 DEV_TX_OFFLOAD_GRE_TNL_TSO |
697 DEV_TX_OFFLOAD_IP_TNL_TSO |
698 DEV_TX_OFFLOAD_UDP_TNL_TSO);
702 if (config->txqs_inline == MLX5_ARG_UNSET)
704 #if defined(RTE_ARCH_ARM64)
705 (priv->sh->pci_dev->id.device_id ==
706 PCI_DEVICE_ID_MELLANOX_CONNECTX5BF) ?
707 MLX5_INLINE_MAX_TXQS_BLUEFIELD :
709 MLX5_INLINE_MAX_TXQS;
711 txqs_inline = (unsigned int)config->txqs_inline;
712 inlen_send = (config->txq_inline_max == MLX5_ARG_UNSET) ?
713 MLX5_SEND_DEF_INLINE_LEN :
714 (unsigned int)config->txq_inline_max;
715 inlen_empw = (config->txq_inline_mpw == MLX5_ARG_UNSET) ?
716 MLX5_EMPW_DEF_INLINE_LEN :
717 (unsigned int)config->txq_inline_mpw;
718 inlen_mode = (config->txq_inline_min == MLX5_ARG_UNSET) ?
719 0 : (unsigned int)config->txq_inline_min;
720 if (config->mps != MLX5_MPW_ENHANCED)
723 * If there is requested minimal amount of data to inline
724 * we MUST enable inlining. This is a case for ConnectX-4
725 * which usually requires L2 inlined for correct operating
726 * and ConnectX-4LX which requires L2-L4 inlined to
727 * support E-Switch Flows.
730 if (inlen_mode <= MLX5_ESEG_MIN_INLINE_SIZE) {
732 * Optimize minimal inlining for single
733 * segment packets to fill one WQEBB
736 temp = MLX5_ESEG_MIN_INLINE_SIZE;
738 temp = inlen_mode - MLX5_ESEG_MIN_INLINE_SIZE;
739 temp = RTE_ALIGN(temp, MLX5_WSEG_SIZE) +
740 MLX5_ESEG_MIN_INLINE_SIZE;
741 temp = RTE_MIN(temp, MLX5_SEND_MAX_INLINE_LEN);
743 if (temp != inlen_mode) {
745 "port %u minimal required inline setting"
746 " aligned from %u to %u",
747 PORT_ID(priv), inlen_mode, temp);
752 * If port is configured to support VLAN insertion and device
753 * does not support this feature by HW (for NICs before ConnectX-5
754 * or in case of wqe_vlan_insert flag is not set) we must enable
755 * data inline on all queues because it is supported by single
758 txq_ctrl->txq.vlan_en = config->hw_vlan_insert;
759 vlan_inline = (dev_txoff & DEV_TX_OFFLOAD_VLAN_INSERT) &&
760 !config->hw_vlan_insert;
762 inlen_send = RTE_MAX(inlen_send, MLX5_ESEG_MIN_INLINE_SIZE);
764 * If there are few Tx queues it is prioritized
765 * to save CPU cycles and disable data inlining at all.
767 if ((inlen_send && priv->txqs_n >= txqs_inline) || vlan_inline) {
769 * The data sent with ordinal MLX5_OPCODE_SEND
770 * may be inlined in Ethernet Segment, align the
771 * length accordingly to fit entire WQEBBs.
773 temp = (inlen_send / MLX5_WQE_SIZE) * MLX5_WQE_SIZE +
774 MLX5_ESEG_MIN_INLINE_SIZE + MLX5_WQE_DSEG_SIZE;
775 temp = RTE_MIN(temp, MLX5_WQE_SIZE_MAX +
776 MLX5_ESEG_MIN_INLINE_SIZE -
779 MLX5_WQE_DSEG_SIZE * 2);
780 temp = RTE_MIN(temp, MLX5_SEND_MAX_INLINE_LEN);
781 temp = RTE_MAX(temp, inlen_mode);
782 if (temp != inlen_send) {
784 "port %u ordinary send inline setting"
785 " aligned from %u to %u",
786 PORT_ID(priv), inlen_send, temp);
790 * Not aligned to cache lines, but to WQEs.
791 * First bytes of data (initial alignment)
792 * is going to be copied explicitly at the
793 * beginning of inlining buffer in Ethernet
796 assert(inlen_send >= MLX5_ESEG_MIN_INLINE_SIZE);
797 assert(inlen_send <= MLX5_WQE_SIZE_MAX +
798 MLX5_ESEG_MIN_INLINE_SIZE -
801 MLX5_WQE_DSEG_SIZE * 2);
802 txq_ctrl->txq.inlen_send = inlen_send;
803 txq_ctrl->txq.inlen_mode = inlen_mode;
804 txq_ctrl->txq.inlen_empw = 0;
807 * If minimal inlining is requested we must
808 * enable inlining in general, despite the
809 * number of configured queues.
811 inlen_send = inlen_mode;
814 * Extend space for inline data to allow
815 * optional alignment of data buffer
816 * start address, it may improve PCIe
819 inlen_send = RTE_MIN(inlen_send + MLX5_WQE_SIZE,
820 MLX5_SEND_MAX_INLINE_LEN);
822 txq_ctrl->txq.inlen_send = inlen_send;
823 txq_ctrl->txq.inlen_mode = inlen_mode;
824 txq_ctrl->txq.inlen_empw = 0;
828 if (inlen_send && inlen_empw && priv->txqs_n >= txqs_inline) {
830 * The data sent with MLX5_OPCODE_ENHANCED_MPSW
831 * may be inlined in Data Segment, align the
832 * length accordingly to fit entire WQEBBs.
834 temp = (inlen_empw + MLX5_WQE_SIZE - 1) / MLX5_WQE_SIZE;
835 temp = temp * MLX5_WQE_SIZE +
836 MLX5_DSEG_MIN_INLINE_SIZE - MLX5_WQE_DSEG_SIZE;
837 temp = RTE_MIN(temp, MLX5_WQE_SIZE_MAX +
838 MLX5_DSEG_MIN_INLINE_SIZE -
842 temp = RTE_MIN(temp, MLX5_EMPW_MAX_INLINE_LEN);
843 if (temp != inlen_empw) {
845 "port %u enhanced empw inline setting"
846 " aligned from %u to %u",
847 PORT_ID(priv), inlen_empw, temp);
850 assert(inlen_empw >= MLX5_ESEG_MIN_INLINE_SIZE);
851 assert(inlen_empw <= MLX5_WQE_SIZE_MAX +
852 MLX5_DSEG_MIN_INLINE_SIZE -
856 txq_ctrl->txq.inlen_empw = inlen_empw;
858 txq_ctrl->max_inline_data = RTE_MAX(inlen_send, inlen_empw);
860 txq_ctrl->max_tso_header = MLX5_MAX_TSO_HEADER;
861 txq_ctrl->max_inline_data = RTE_MAX(txq_ctrl->max_inline_data,
862 MLX5_MAX_TSO_HEADER);
863 txq_ctrl->txq.tso_en = 1;
865 txq_ctrl->txq.tunnel_en = config->tunnel_en | config->swp;
866 txq_ctrl->txq.swp_en = ((DEV_TX_OFFLOAD_IP_TNL_TSO |
867 DEV_TX_OFFLOAD_UDP_TNL_TSO |
868 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &
869 txq_ctrl->txq.offloads) && config->swp;
873 * Create a DPDK Tx queue.
876 * Pointer to Ethernet device.
880 * Number of descriptors to configure in queue.
882 * NUMA socket on which memory must be allocated.
884 * Thresholds parameters.
887 * A DPDK queue object on success, NULL otherwise and rte_errno is set.
889 struct mlx5_txq_ctrl *
890 mlx5_txq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
891 unsigned int socket, const struct rte_eth_txconf *conf)
893 struct mlx5_priv *priv = dev->data->dev_private;
894 struct mlx5_txq_ctrl *tmpl;
896 tmpl = rte_calloc_socket("TXQ", 1,
898 desc * sizeof(struct rte_mbuf *),
904 if (mlx5_mr_btree_init(&tmpl->txq.mr_ctrl.cache_bh,
905 MLX5_MR_BTREE_CACHE_N, socket)) {
906 /* rte_errno is already set. */
909 /* Save pointer of global generation number to check memory event. */
910 tmpl->txq.mr_ctrl.dev_gen_ptr = &priv->sh->mr.dev_gen;
911 assert(desc > MLX5_TX_COMP_THRESH);
912 tmpl->txq.offloads = conf->offloads |
913 dev->data->dev_conf.txmode.offloads;
915 tmpl->socket = socket;
916 tmpl->txq.elts_n = log2above(desc);
917 tmpl->txq.elts_s = desc;
918 tmpl->txq.elts_m = desc - 1;
919 tmpl->txq.port_id = dev->data->port_id;
921 txq_set_params(tmpl);
922 if (txq_calc_wqebb_cnt(tmpl) >
923 priv->sh->device_attr.orig_attr.max_qp_wr) {
925 "port %u Tx WQEBB count (%d) exceeds the limit (%d),"
926 " try smaller queue size",
927 dev->data->port_id, txq_calc_wqebb_cnt(tmpl),
928 priv->sh->device_attr.orig_attr.max_qp_wr);
932 rte_atomic32_inc(&tmpl->refcnt);
933 LIST_INSERT_HEAD(&priv->txqsctrl, tmpl, next);
944 * Pointer to Ethernet device.
949 * A pointer to the queue if it exists.
951 struct mlx5_txq_ctrl *
952 mlx5_txq_get(struct rte_eth_dev *dev, uint16_t idx)
954 struct mlx5_priv *priv = dev->data->dev_private;
955 struct mlx5_txq_ctrl *ctrl = NULL;
957 if ((*priv->txqs)[idx]) {
958 ctrl = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl,
960 mlx5_txq_ibv_get(dev, idx);
961 rte_atomic32_inc(&ctrl->refcnt);
967 * Release a Tx queue.
970 * Pointer to Ethernet device.
975 * 1 while a reference on it exists, 0 when freed.
978 mlx5_txq_release(struct rte_eth_dev *dev, uint16_t idx)
980 struct mlx5_priv *priv = dev->data->dev_private;
981 struct mlx5_txq_ctrl *txq;
983 if (!(*priv->txqs)[idx])
985 txq = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq);
986 if (txq->ibv && !mlx5_txq_ibv_release(txq->ibv))
988 if (rte_atomic32_dec_and_test(&txq->refcnt)) {
990 mlx5_mr_btree_free(&txq->txq.mr_ctrl.cache_bh);
991 LIST_REMOVE(txq, next);
993 (*priv->txqs)[idx] = NULL;
1000 * Verify if the queue can be released.
1003 * Pointer to Ethernet device.
1008 * 1 if the queue can be released.
1011 mlx5_txq_releasable(struct rte_eth_dev *dev, uint16_t idx)
1013 struct mlx5_priv *priv = dev->data->dev_private;
1014 struct mlx5_txq_ctrl *txq;
1016 if (!(*priv->txqs)[idx])
1018 txq = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq);
1019 return (rte_atomic32_read(&txq->refcnt) == 1);
1023 * Verify the Tx Queue list is empty
1026 * Pointer to Ethernet device.
1029 * The number of object not released.
1032 mlx5_txq_verify(struct rte_eth_dev *dev)
1034 struct mlx5_priv *priv = dev->data->dev_private;
1035 struct mlx5_txq_ctrl *txq_ctrl;
1038 LIST_FOREACH(txq_ctrl, &priv->txqsctrl, next) {
1039 DRV_LOG(DEBUG, "port %u Tx queue %u still referenced",
1040 dev->data->port_id, txq_ctrl->txq.idx);