4 * Copyright 2015 6WIND S.A.
5 * Copyright 2015 Mellanox.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of 6WIND S.A. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
45 #pragma GCC diagnostic ignored "-Wpedantic"
47 #include <infiniband/verbs.h>
49 #pragma GCC diagnostic error "-Wpedantic"
53 #include <rte_malloc.h>
54 #include <rte_ethdev.h>
55 #include <rte_common.h>
57 #include "mlx5_utils.h"
58 #include "mlx5_defs.h"
60 #include "mlx5_rxtx.h"
61 #include "mlx5_autoconf.h"
64 * Allocate TX queue elements.
67 * Pointer to TX queue structure.
70 txq_alloc_elts(struct mlx5_txq_ctrl *txq_ctrl)
72 const unsigned int elts_n = 1 << txq_ctrl->txq.elts_n;
75 for (i = 0; (i != elts_n); ++i)
76 (*txq_ctrl->txq.elts)[i] = NULL;
77 DRV_LOG(DEBUG, "port %u Tx queue %u allocated and configured %u WRs",
78 PORT_ID(txq_ctrl->priv), txq_ctrl->idx, elts_n);
79 txq_ctrl->txq.elts_head = 0;
80 txq_ctrl->txq.elts_tail = 0;
81 txq_ctrl->txq.elts_comp = 0;
85 * Free TX queue elements.
88 * Pointer to TX queue structure.
91 txq_free_elts(struct mlx5_txq_ctrl *txq_ctrl)
93 const uint16_t elts_n = 1 << txq_ctrl->txq.elts_n;
94 const uint16_t elts_m = elts_n - 1;
95 uint16_t elts_head = txq_ctrl->txq.elts_head;
96 uint16_t elts_tail = txq_ctrl->txq.elts_tail;
97 struct rte_mbuf *(*elts)[elts_n] = txq_ctrl->txq.elts;
99 DRV_LOG(DEBUG, "port %u Tx queue %u freeing WRs",
100 PORT_ID(txq_ctrl->priv), txq_ctrl->idx);
101 txq_ctrl->txq.elts_head = 0;
102 txq_ctrl->txq.elts_tail = 0;
103 txq_ctrl->txq.elts_comp = 0;
105 while (elts_tail != elts_head) {
106 struct rte_mbuf *elt = (*elts)[elts_tail & elts_m];
109 rte_pktmbuf_free_seg(elt);
112 memset(&(*elts)[elts_tail & elts_m],
114 sizeof((*elts)[elts_tail & elts_m]));
121 * DPDK callback to configure a TX queue.
124 * Pointer to Ethernet device structure.
128 * Number of descriptors to configure in queue.
130 * NUMA socket on which memory must be allocated.
132 * Thresholds parameters.
135 * 0 on success, a negative errno value otherwise and rte_errno is set.
138 mlx5_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
139 unsigned int socket, const struct rte_eth_txconf *conf)
141 struct priv *priv = dev->data->dev_private;
142 struct mlx5_txq_data *txq = (*priv->txqs)[idx];
143 struct mlx5_txq_ctrl *txq_ctrl =
144 container_of(txq, struct mlx5_txq_ctrl, txq);
146 if (desc <= MLX5_TX_COMP_THRESH) {
148 "port %u number of descriptors requested for Tx queue"
149 " %u must be higher than MLX5_TX_COMP_THRESH, using %u"
151 dev->data->port_id, idx, MLX5_TX_COMP_THRESH + 1, desc);
152 desc = MLX5_TX_COMP_THRESH + 1;
154 if (!rte_is_power_of_2(desc)) {
155 desc = 1 << log2above(desc);
157 "port %u increased number of descriptors in Tx queue"
158 " %u to the next power of two (%d)",
159 dev->data->port_id, idx, desc);
161 DRV_LOG(DEBUG, "port %u configuring queue %u for %u descriptors",
162 dev->data->port_id, idx, desc);
163 if (idx >= priv->txqs_n) {
164 DRV_LOG(ERR, "port %u Tx queue index out of range (%u >= %u)",
165 dev->data->port_id, idx, priv->txqs_n);
166 rte_errno = EOVERFLOW;
169 if (!mlx5_txq_releasable(dev, idx)) {
171 DRV_LOG(ERR, "port %u unable to release queue index %u",
172 dev->data->port_id, idx);
175 mlx5_txq_release(dev, idx);
176 txq_ctrl = mlx5_txq_new(dev, idx, desc, socket, conf);
178 DRV_LOG(ERR, "port %u unable to allocate queue index %u",
179 dev->data->port_id, idx);
182 DRV_LOG(DEBUG, "port %u adding Tx queue %u to list",
183 dev->data->port_id, idx);
184 (*priv->txqs)[idx] = &txq_ctrl->txq;
189 * DPDK callback to release a TX queue.
192 * Generic TX queue pointer.
195 mlx5_tx_queue_release(void *dpdk_txq)
197 struct mlx5_txq_data *txq = (struct mlx5_txq_data *)dpdk_txq;
198 struct mlx5_txq_ctrl *txq_ctrl;
204 txq_ctrl = container_of(txq, struct mlx5_txq_ctrl, txq);
205 priv = txq_ctrl->priv;
206 for (i = 0; (i != priv->txqs_n); ++i)
207 if ((*priv->txqs)[i] == txq) {
208 mlx5_txq_release(ETH_DEV(priv), i);
209 DRV_LOG(DEBUG, "port %u removing Tx queue %u from list",
210 PORT_ID(priv), txq_ctrl->idx);
217 * Mmap TX UAR(HW doorbell) pages into reserved UAR address space.
218 * Both primary and secondary process do mmap to make UAR address
222 * Pointer to Ethernet device.
224 * Verbs file descriptor to map UAR pages.
227 * 0 on success, a negative errno value otherwise and rte_errno is set.
230 mlx5_tx_uar_remap(struct rte_eth_dev *dev, int fd)
232 struct priv *priv = dev->data->dev_private;
234 uintptr_t pages[priv->txqs_n];
235 unsigned int pages_n = 0;
240 struct mlx5_txq_data *txq;
241 struct mlx5_txq_ctrl *txq_ctrl;
243 size_t page_size = sysconf(_SC_PAGESIZE);
245 memset(pages, 0, priv->txqs_n * sizeof(uintptr_t));
247 * As rdma-core, UARs are mapped in size of OS page size.
248 * Use aligned address to avoid duplicate mmap.
249 * Ref to libmlx5 function: mlx5_init_context()
251 for (i = 0; i != priv->txqs_n; ++i) {
252 if (!(*priv->txqs)[i])
254 txq = (*priv->txqs)[i];
255 txq_ctrl = container_of(txq, struct mlx5_txq_ctrl, txq);
256 assert(txq_ctrl->idx == (uint16_t)i);
257 /* UAR addr form verbs used to find dup and offset in page. */
258 uar_va = (uintptr_t)txq_ctrl->bf_reg_orig;
259 off = uar_va & (page_size - 1); /* offset in page. */
260 uar_va = RTE_ALIGN_FLOOR(uar_va, page_size); /* page addr. */
262 for (j = 0; j != pages_n; ++j) {
263 if (pages[j] == uar_va) {
268 /* new address in reserved UAR address space. */
269 addr = RTE_PTR_ADD(priv->uar_base,
270 uar_va & (MLX5_UAR_SIZE - 1));
271 if (!already_mapped) {
272 pages[pages_n++] = uar_va;
273 /* fixed mmap to specified address in reserved
276 ret = mmap(addr, page_size,
277 PROT_WRITE, MAP_FIXED | MAP_SHARED, fd,
278 txq_ctrl->uar_mmap_offset);
280 /* fixed mmap have to return same address */
282 "port %u call to mmap failed on UAR"
284 dev->data->port_id, txq_ctrl->idx);
289 if (rte_eal_process_type() == RTE_PROC_PRIMARY) /* save once */
290 txq_ctrl->txq.bf_reg = RTE_PTR_ADD((void *)addr, off);
292 assert(txq_ctrl->txq.bf_reg ==
293 RTE_PTR_ADD((void *)addr, off));
299 * Create the Tx queue Verbs object.
302 * Pointer to Ethernet device.
304 * Queue index in DPDK Rx queue array
307 * The Verbs object initialised, NULL otherwise and rte_errno is set.
309 struct mlx5_txq_ibv *
310 mlx5_txq_ibv_new(struct rte_eth_dev *dev, uint16_t idx)
312 struct priv *priv = dev->data->dev_private;
313 struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
314 struct mlx5_txq_ctrl *txq_ctrl =
315 container_of(txq_data, struct mlx5_txq_ctrl, txq);
316 struct mlx5_txq_ibv tmpl;
317 struct mlx5_txq_ibv *txq_ibv;
319 struct ibv_qp_init_attr_ex init;
320 struct ibv_cq_init_attr_ex cq;
321 struct ibv_qp_attr mod;
322 struct ibv_cq_ex cq_attr;
325 struct mlx5dv_qp qp = { .comp_mask = MLX5DV_QP_MASK_UAR_MMAP_OFFSET };
326 struct mlx5dv_cq cq_info;
327 struct mlx5dv_obj obj;
328 const int desc = 1 << txq_data->elts_n;
332 priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_TX_QUEUE;
333 priv->verbs_alloc_ctx.obj = txq_ctrl;
334 if (mlx5_getenv_int("MLX5_ENABLE_CQE_COMPRESSION")) {
336 "port %u MLX5_ENABLE_CQE_COMPRESSION must never be set",
341 memset(&tmpl, 0, sizeof(struct mlx5_txq_ibv));
342 /* MRs will be registered in mp2mr[] later. */
343 attr.cq = (struct ibv_cq_init_attr_ex){
346 cqe_n = ((desc / MLX5_TX_COMP_THRESH) - 1) ?
347 ((desc / MLX5_TX_COMP_THRESH) - 1) : 1;
348 if (priv->mps == MLX5_MPW_ENHANCED)
349 cqe_n += MLX5_TX_COMP_THRESH_INLINE_DIV;
350 tmpl.cq = ibv_create_cq(priv->ctx, cqe_n, NULL, NULL, 0);
351 if (tmpl.cq == NULL) {
352 DRV_LOG(ERR, "port %u Tx queue %u CQ creation failure",
353 dev->data->port_id, idx);
357 attr.init = (struct ibv_qp_init_attr_ex){
358 /* CQ to be associated with the send queue. */
360 /* CQ to be associated with the receive queue. */
363 /* Max number of outstanding WRs. */
365 ((priv->device_attr.orig_attr.max_qp_wr <
367 priv->device_attr.orig_attr.max_qp_wr :
370 * Max number of scatter/gather elements in a WR,
371 * must be 1 to prevent libmlx5 from trying to affect
372 * too much memory. TX gather is not impacted by the
373 * priv->device_attr.max_sge limit and will still work
378 .qp_type = IBV_QPT_RAW_PACKET,
380 * Do *NOT* enable this, completions events are managed per
385 .comp_mask = IBV_QP_INIT_ATTR_PD,
387 if (txq_data->inline_en)
388 attr.init.cap.max_inline_data = txq_ctrl->max_inline_data;
389 if (txq_data->tso_en) {
390 attr.init.max_tso_header = txq_ctrl->max_tso_header;
391 attr.init.comp_mask |= IBV_QP_INIT_ATTR_MAX_TSO_HEADER;
393 tmpl.qp = ibv_create_qp_ex(priv->ctx, &attr.init);
394 if (tmpl.qp == NULL) {
395 DRV_LOG(ERR, "port %u Tx queue %u QP creation failure",
396 dev->data->port_id, idx);
400 attr.mod = (struct ibv_qp_attr){
401 /* Move the QP to this state. */
402 .qp_state = IBV_QPS_INIT,
403 /* Primary port number. */
404 .port_num = priv->port
406 ret = ibv_modify_qp(tmpl.qp, &attr.mod, (IBV_QP_STATE | IBV_QP_PORT));
409 "port %u Tx queue %u QP state to IBV_QPS_INIT failed",
410 dev->data->port_id, idx);
414 attr.mod = (struct ibv_qp_attr){
415 .qp_state = IBV_QPS_RTR
417 ret = ibv_modify_qp(tmpl.qp, &attr.mod, IBV_QP_STATE);
420 "port %u Tx queue %u QP state to IBV_QPS_RTR failed",
421 dev->data->port_id, idx);
425 attr.mod.qp_state = IBV_QPS_RTS;
426 ret = ibv_modify_qp(tmpl.qp, &attr.mod, IBV_QP_STATE);
429 "port %u Tx queue %u QP state to IBV_QPS_RTS failed",
430 dev->data->port_id, idx);
434 txq_ibv = rte_calloc_socket(__func__, 1, sizeof(struct mlx5_txq_ibv), 0,
437 DRV_LOG(ERR, "port %u Tx queue %u cannot allocate memory",
438 dev->data->port_id, idx);
443 obj.cq.out = &cq_info;
446 ret = mlx5dv_init_obj(&obj, MLX5DV_OBJ_CQ | MLX5DV_OBJ_QP);
451 if (cq_info.cqe_size != RTE_CACHE_LINE_SIZE) {
453 "port %u wrong MLX5_CQE_SIZE environment variable"
454 " value: it should be set to %u",
455 dev->data->port_id, RTE_CACHE_LINE_SIZE);
459 txq_data->cqe_n = log2above(cq_info.cqe_cnt);
460 txq_data->qp_num_8s = tmpl.qp->qp_num << 8;
461 txq_data->wqes = qp.sq.buf;
462 txq_data->wqe_n = log2above(qp.sq.wqe_cnt);
463 txq_data->qp_db = &qp.dbrec[MLX5_SND_DBR];
464 txq_ctrl->bf_reg_orig = qp.bf.reg;
465 txq_data->cq_db = cq_info.dbrec;
467 (volatile struct mlx5_cqe (*)[])
468 (uintptr_t)cq_info.buf;
471 txq_data->wqe_ci = 0;
472 txq_data->wqe_pi = 0;
473 txq_ibv->qp = tmpl.qp;
474 txq_ibv->cq = tmpl.cq;
475 rte_atomic32_inc(&txq_ibv->refcnt);
476 if (qp.comp_mask & MLX5DV_QP_MASK_UAR_MMAP_OFFSET) {
477 txq_ctrl->uar_mmap_offset = qp.uar_mmap_offset;
480 "port %u failed to retrieve UAR info, invalid"
486 DRV_LOG(DEBUG, "port %u Verbs Tx queue %u: refcnt %d",
487 dev->data->port_id, idx, rte_atomic32_read(&txq_ibv->refcnt));
488 LIST_INSERT_HEAD(&priv->txqsibv, txq_ibv, next);
489 txq_ibv->txq_ctrl = txq_ctrl;
490 priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_NONE;
493 ret = rte_errno; /* Save rte_errno before cleanup. */
495 claim_zero(ibv_destroy_cq(tmpl.cq));
497 claim_zero(ibv_destroy_qp(tmpl.qp));
498 priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_NONE;
499 rte_errno = ret; /* Restore rte_errno. */
504 * Get an Tx queue Verbs object.
507 * Pointer to Ethernet device.
509 * Queue index in DPDK Rx queue array
512 * The Verbs object if it exists.
514 struct mlx5_txq_ibv *
515 mlx5_txq_ibv_get(struct rte_eth_dev *dev, uint16_t idx)
517 struct priv *priv = dev->data->dev_private;
518 struct mlx5_txq_ctrl *txq_ctrl;
520 if (idx >= priv->txqs_n)
522 if (!(*priv->txqs)[idx])
524 txq_ctrl = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq);
526 rte_atomic32_inc(&txq_ctrl->ibv->refcnt);
527 DRV_LOG(DEBUG, "port %u Verbs Tx queue %u: refcnt %d",
528 dev->data->port_id, txq_ctrl->idx,
529 rte_atomic32_read(&txq_ctrl->ibv->refcnt));
531 return txq_ctrl->ibv;
535 * Release an Tx verbs queue object.
538 * Verbs Tx queue object.
541 * 1 while a reference on it exists, 0 when freed.
544 mlx5_txq_ibv_release(struct mlx5_txq_ibv *txq_ibv)
547 DRV_LOG(DEBUG, "port %u Verbs Tx queue %u: refcnt %d",
548 PORT_ID(txq_ibv->txq_ctrl->priv),
549 txq_ibv->txq_ctrl->idx, rte_atomic32_read(&txq_ibv->refcnt));
550 if (rte_atomic32_dec_and_test(&txq_ibv->refcnt)) {
551 claim_zero(ibv_destroy_qp(txq_ibv->qp));
552 claim_zero(ibv_destroy_cq(txq_ibv->cq));
553 LIST_REMOVE(txq_ibv, next);
561 * Return true if a single reference exists on the object.
564 * Verbs Tx queue object.
567 mlx5_txq_ibv_releasable(struct mlx5_txq_ibv *txq_ibv)
570 return (rte_atomic32_read(&txq_ibv->refcnt) == 1);
574 * Verify the Verbs Tx queue list is empty
577 * Pointer to Ethernet device.
580 * The number of object not released.
583 mlx5_txq_ibv_verify(struct rte_eth_dev *dev)
585 struct priv *priv = dev->data->dev_private;
587 struct mlx5_txq_ibv *txq_ibv;
589 LIST_FOREACH(txq_ibv, &priv->txqsibv, next) {
590 DRV_LOG(DEBUG, "port %u Verbs Tx queue %u still referenced",
591 dev->data->port_id, txq_ibv->txq_ctrl->idx);
598 * Create a DPDK Tx queue.
601 * Pointer to Ethernet device.
605 * Number of descriptors to configure in queue.
607 * NUMA socket on which memory must be allocated.
609 * Thresholds parameters.
612 * A DPDK queue object on success, NULL otherwise and rte_errno is set.
614 struct mlx5_txq_ctrl *
615 mlx5_txq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
616 unsigned int socket, const struct rte_eth_txconf *conf)
618 struct priv *priv = dev->data->dev_private;
619 const unsigned int max_tso_inline =
620 ((MLX5_MAX_TSO_HEADER + (RTE_CACHE_LINE_SIZE - 1)) /
621 RTE_CACHE_LINE_SIZE);
622 struct mlx5_txq_ctrl *tmpl;
624 tmpl = rte_calloc_socket("TXQ", 1,
626 desc * sizeof(struct rte_mbuf *),
632 assert(desc > MLX5_TX_COMP_THRESH);
633 tmpl->txq.flags = conf->txq_flags;
635 tmpl->socket = socket;
636 tmpl->txq.elts_n = log2above(desc);
638 if (priv->mps == MLX5_MPW_ENHANCED)
639 tmpl->txq.mpw_hdr_dseg = priv->mpw_hdr_dseg;
640 /* MRs will be registered in mp2mr[] later. */
641 DRV_LOG(DEBUG, "port %u priv->device_attr.max_qp_wr is %d",
642 dev->data->port_id, priv->device_attr.orig_attr.max_qp_wr);
643 DRV_LOG(DEBUG, "port %u priv->device_attr.max_sge is %d",
644 dev->data->port_id, priv->device_attr.orig_attr.max_sge);
645 if (priv->txq_inline && (priv->txqs_n >= priv->txqs_inline)) {
648 tmpl->txq.max_inline =
649 ((priv->txq_inline + (RTE_CACHE_LINE_SIZE - 1)) /
650 RTE_CACHE_LINE_SIZE);
651 tmpl->txq.inline_en = 1;
652 /* TSO and MPS can't be enabled concurrently. */
653 assert(!priv->tso || !priv->mps);
654 if (priv->mps == MLX5_MPW_ENHANCED) {
655 tmpl->txq.inline_max_packet_sz =
656 priv->inline_max_packet_sz;
657 /* To minimize the size of data set, avoid requesting
660 tmpl->max_inline_data =
661 ((RTE_MIN(priv->txq_inline,
662 priv->inline_max_packet_sz) +
663 (RTE_CACHE_LINE_SIZE - 1)) /
664 RTE_CACHE_LINE_SIZE) * RTE_CACHE_LINE_SIZE;
666 tmpl->max_inline_data =
667 tmpl->txq.max_inline * RTE_CACHE_LINE_SIZE;
670 * Check if the inline size is too large in a way which
671 * can make the WQE DS to overflow.
672 * Considering in calculation:
677 ds_cnt = 2 + (tmpl->txq.max_inline / MLX5_WQE_DWORD_SIZE);
678 if (ds_cnt > MLX5_DSEG_MAX) {
679 unsigned int max_inline = (MLX5_DSEG_MAX - 2) *
682 max_inline = max_inline - (max_inline %
683 RTE_CACHE_LINE_SIZE);
685 "port %u txq inline is too large (%d) setting it"
686 " to the maximum possible: %d\n",
687 PORT_ID(priv), priv->txq_inline, max_inline);
688 tmpl->txq.max_inline = max_inline / RTE_CACHE_LINE_SIZE;
692 tmpl->max_tso_header = max_tso_inline * RTE_CACHE_LINE_SIZE;
693 tmpl->txq.max_inline = RTE_MAX(tmpl->txq.max_inline,
695 tmpl->txq.tso_en = 1;
698 tmpl->txq.tunnel_en = 1;
700 (struct rte_mbuf *(*)[1 << tmpl->txq.elts_n])(tmpl + 1);
701 tmpl->txq.stats.idx = idx;
702 rte_atomic32_inc(&tmpl->refcnt);
703 DRV_LOG(DEBUG, "port %u Tx queue %u: refcnt %d", dev->data->port_id,
704 idx, rte_atomic32_read(&tmpl->refcnt));
705 LIST_INSERT_HEAD(&priv->txqsctrl, tmpl, next);
713 * Pointer to Ethernet device.
718 * A pointer to the queue if it exists.
720 struct mlx5_txq_ctrl *
721 mlx5_txq_get(struct rte_eth_dev *dev, uint16_t idx)
723 struct priv *priv = dev->data->dev_private;
724 struct mlx5_txq_ctrl *ctrl = NULL;
726 if ((*priv->txqs)[idx]) {
727 ctrl = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl,
731 mlx5_txq_ibv_get(dev, idx);
732 for (i = 0; i != MLX5_PMD_TX_MP_CACHE; ++i) {
733 if (ctrl->txq.mp2mr[i])
736 ctrl->txq.mp2mr[i]->mp));
738 rte_atomic32_inc(&ctrl->refcnt);
739 DRV_LOG(DEBUG, "port %u Tx queue %u refcnt %d",
741 ctrl->idx, rte_atomic32_read(&ctrl->refcnt));
747 * Release a Tx queue.
750 * Pointer to Ethernet device.
755 * 1 while a reference on it exists, 0 when freed.
758 mlx5_txq_release(struct rte_eth_dev *dev, uint16_t idx)
760 struct priv *priv = dev->data->dev_private;
762 struct mlx5_txq_ctrl *txq;
763 size_t page_size = sysconf(_SC_PAGESIZE);
765 if (!(*priv->txqs)[idx])
767 txq = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq);
768 DRV_LOG(DEBUG, "port %u Tx queue %u: refcnt %d", dev->data->port_id,
769 txq->idx, rte_atomic32_read(&txq->refcnt));
770 if (txq->ibv && !mlx5_txq_ibv_release(txq->ibv))
772 for (i = 0; i != MLX5_PMD_TX_MP_CACHE; ++i) {
773 if (txq->txq.mp2mr[i]) {
774 mlx5_mr_release(txq->txq.mp2mr[i]);
775 txq->txq.mp2mr[i] = NULL;
779 munmap((void *)RTE_ALIGN_FLOOR((uintptr_t)txq->txq.bf_reg,
780 page_size), page_size);
781 if (rte_atomic32_dec_and_test(&txq->refcnt)) {
783 LIST_REMOVE(txq, next);
785 (*priv->txqs)[idx] = NULL;
792 * Verify if the queue can be released.
795 * Pointer to Ethernet device.
800 * 1 if the queue can be released.
803 mlx5_txq_releasable(struct rte_eth_dev *dev, uint16_t idx)
805 struct priv *priv = dev->data->dev_private;
806 struct mlx5_txq_ctrl *txq;
808 if (!(*priv->txqs)[idx])
810 txq = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq);
811 return (rte_atomic32_read(&txq->refcnt) == 1);
815 * Verify the Tx Queue list is empty
818 * Pointer to Ethernet device.
821 * The number of object not released.
824 mlx5_txq_verify(struct rte_eth_dev *dev)
826 struct priv *priv = dev->data->dev_private;
827 struct mlx5_txq_ctrl *txq;
830 LIST_FOREACH(txq, &priv->txqsctrl, next) {
831 DRV_LOG(DEBUG, "port %u Tx queue %u still referenced",
832 dev->data->port_id, txq->idx);