From: Oleksandr Kolomeiets <okl-plv@napatech.com>
To: dev@dpdk.org
Cc: mko-plv@napatech.com, sil-plv@napatech.com, ckm@napatech.com,
stephen@networkplumber.org
Subject: [PATCH v1 3/4] net/ntnic: unmap DMA during queue release
Date: Fri, 20 Jun 2025 13:27:06 +0200 [thread overview]
Message-ID: <20250620112707.294596-4-okl-plv@napatech.com> (raw)
In-Reply-To: <20250620112707.294596-1-okl-plv@napatech.com>
Perform unmapping in a default container, which is used by queues.
Handle multiple mappings when IOMMU is unoptimized.
Signed-off-by: Oleksandr Kolomeiets <okl-plv@napatech.com>
---
drivers/net/ntnic/include/ntos_drv.h | 1 +
drivers/net/ntnic/ntnic_ethdev.c | 26 ++++++++++++++++++++++++--
drivers/net/ntnic/ntnic_vfio.c | 3 ---
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ntnic/include/ntos_drv.h b/drivers/net/ntnic/include/ntos_drv.h
index cef3c5c277..047c077057 100644
--- a/drivers/net/ntnic/include/ntos_drv.h
+++ b/drivers/net/ntnic/include/ntos_drv.h
@@ -51,6 +51,7 @@ struct nthw_memory_descriptor {
struct hwq_s {
int vf_num;
struct nthw_memory_descriptor virt_queues_ctrl;
+ struct nthw_memory_descriptor pkt_buffers_ctrl;
struct nthw_memory_descriptor *pkt_buffers;
};
diff --git a/drivers/net/ntnic/ntnic_ethdev.c b/drivers/net/ntnic/ntnic_ethdev.c
index d875e7c236..79ef9e7e7c 100644
--- a/drivers/net/ntnic/ntnic_ethdev.c
+++ b/drivers/net/ntnic/ntnic_ethdev.c
@@ -879,6 +879,10 @@ static int allocate_hw_virtio_queues(struct rte_eth_dev *eth_dev, int vf_num, st
if (res != 0)
return -1;
+ hwq->pkt_buffers_ctrl.virt_addr = virt_addr;
+ hwq->pkt_buffers_ctrl.phys_addr = (void *)iova_addr;
+ hwq->pkt_buffers_ctrl.len = size;
+
for (i = 0; i < num_descr; i++) {
hwq->pkt_buffers[i].virt_addr =
(void *)((char *)virt_addr + ((uint64_t)(i) * buf_size));
@@ -900,9 +904,13 @@ static int allocate_hw_virtio_queues(struct rte_eth_dev *eth_dev, int vf_num, st
hwq->vf_num = vf_num;
hwq->virt_queues_ctrl.virt_addr = virt;
hwq->virt_queues_ctrl.phys_addr = (void *)(iova_addr);
- hwq->virt_queues_ctrl.len = 0x100000;
+ hwq->virt_queues_ctrl.len = ONE_G_SIZE;
iova_addr += 0x100000;
+ hwq->pkt_buffers_ctrl.virt_addr = NULL;
+ hwq->pkt_buffers_ctrl.phys_addr = NULL;
+ hwq->pkt_buffers_ctrl.len = 0;
+
NT_LOG(DBG, NTNIC,
"VFIO MMAP: virt_addr=%p phys_addr=%p size=%" PRIX32 " hpa=%" PRIX64 "",
hwq->virt_queues_ctrl.virt_addr, hwq->virt_queues_ctrl.phys_addr,
@@ -948,13 +956,27 @@ static int deallocate_hw_virtio_queues(struct hwq_s *hwq)
void *virt = hwq->virt_queues_ctrl.virt_addr;
int res = nt_vfio_dma_unmap(vf_num, hwq->virt_queues_ctrl.virt_addr,
- (uint64_t)hwq->virt_queues_ctrl.phys_addr, ONE_G_SIZE);
+ (uint64_t)hwq->virt_queues_ctrl.phys_addr, hwq->virt_queues_ctrl.len);
if (res != 0) {
NT_LOG(ERR, NTNIC, "VFIO UNMMAP FAILED! res %i, vf_num %i", res, vf_num);
return -1;
}
+ if (hwq->pkt_buffers_ctrl.virt_addr != NULL &&
+ hwq->pkt_buffers_ctrl.phys_addr != NULL &&
+ hwq->pkt_buffers_ctrl.len > 0) {
+ int res = nt_vfio_dma_unmap(vf_num,
+ hwq->pkt_buffers_ctrl.virt_addr,
+ (uint64_t)hwq->pkt_buffers_ctrl.phys_addr,
+ hwq->pkt_buffers_ctrl.len);
+
+ if (res != 0) {
+ NT_LOG(ERR, NTNIC, "VFIO UNMMAP FAILED! res %i, vf_num %i", res, vf_num);
+ return -1;
+ }
+ }
+
release_hw_virtio_queues(hwq);
rte_free(hwq->pkt_buffers);
rte_free(virt);
diff --git a/drivers/net/ntnic/ntnic_vfio.c b/drivers/net/ntnic/ntnic_vfio.c
index 8d955e8342..1031b3cf67 100644
--- a/drivers/net/ntnic/ntnic_vfio.c
+++ b/drivers/net/ntnic/ntnic_vfio.c
@@ -211,9 +211,6 @@ nt_vfio_dma_unmap(int vf_num, void *virt_addr, uint64_t iova_addr, uint64_t size
return -1;
}
- if (vfio->container_fd == -1)
- return 0;
-
int res = rte_vfio_container_dma_unmap(vfio->container_fd, gp_virt_base, iova_addr, size);
if (res != 0) {
--
2.47.1
next prev parent reply other threads:[~2025-06-20 11:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-20 11:27 [PATCH v1 0/4] net/ntnic: implement start, stop and deferred start for Rx/Tx queues Oleksandr Kolomeiets
2025-06-20 11:27 ` [PATCH v1 1/4] net/ntnic: implement start/stop " Oleksandr Kolomeiets
2025-06-20 11:27 ` [PATCH v1 2/4] net/ntnic: implement deferred start " Oleksandr Kolomeiets
2025-06-20 11:27 ` Oleksandr Kolomeiets [this message]
2025-06-20 11:27 ` [PATCH v1 4/4] net/ntnic: add warning when sending on a stopped queue Oleksandr Kolomeiets
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250620112707.294596-4-okl-plv@napatech.com \
--to=okl-plv@napatech.com \
--cc=ckm@napatech.com \
--cc=dev@dpdk.org \
--cc=mko-plv@napatech.com \
--cc=sil-plv@napatech.com \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).