[v1,03/14] net/ntnic: add scatter-gather HW deallocation

Message ID 20241004153551.267935-40-sil-plv@napatech.com (mailing list archive)
State Superseded
Delegated to: Ferruh Yigit
Headers
Series None |

Checks

Context Check Description
ci/Intel-compilation warning apply issues

Commit Message

Serhii Iliushyk Oct. 4, 2024, 3:34 p.m. UTC
From: Danylo Vodopianov <dvo-plv@napatech.com>

Deallocates memory for hardware Virtio queues and unmaps
VFIO resources.

Updated eth_tx_queue_release and eth_rx_queue_release. Released
hardware Virtio queues for TX and RX.

Signed-off-by: Danylo Vodopianov <dvo-plv@napatech.com>
---
 drivers/net/ntnic/include/ntos_drv.h |  1 +
 drivers/net/ntnic/ntnic_ethdev.c     | 32 ++++++++++++++++++++++++----
 2 files changed, 29 insertions(+), 4 deletions(-)
  

Patch

diff --git a/drivers/net/ntnic/include/ntos_drv.h b/drivers/net/ntnic/include/ntos_drv.h
index 191686a07a..233d585303 100644
--- a/drivers/net/ntnic/include/ntos_drv.h
+++ b/drivers/net/ntnic/include/ntos_drv.h
@@ -28,6 +28,7 @@ 
 
 /* Structs: */
 struct nthw_memory_descriptor {
+	void *phys_addr;
 	void *virt_addr;
 	uint32_t len;
 };
diff --git a/drivers/net/ntnic/ntnic_ethdev.c b/drivers/net/ntnic/ntnic_ethdev.c
index 79b5ae4d60..78a689d444 100644
--- a/drivers/net/ntnic/ntnic_ethdev.c
+++ b/drivers/net/ntnic/ntnic_ethdev.c
@@ -34,6 +34,8 @@ 
 /* Max RSS queues */
 #define MAX_QUEUES 125
 
+#define ONE_G_SIZE  0x40000000
+
 #define ETH_DEV_NTNIC_HELP_ARG "help"
 #define ETH_DEV_NTHW_RXQUEUES_ARG "rxqs"
 #define ETH_DEV_NTHW_TXQUEUES_ARG "txqs"
@@ -193,16 +195,38 @@  static void release_hw_virtio_queues(struct hwq_s *hwq)
 	hwq->vf_num = 0;
 }
 
+static int deallocate_hw_virtio_queues(struct hwq_s *hwq)
+{
+	int vf_num = hwq->vf_num;
+
+	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);
+
+	if (res != 0) {
+		NT_LOG(ERR, NTNIC, "VFIO UNMMAP FAILED! res %i, vf_num %i\n", res, vf_num);
+		return -1;
+	}
+
+	release_hw_virtio_queues(hwq);
+	rte_free(hwq->pkt_buffers);
+	rte_free(virt);
+	return 0;
+}
+
 static void eth_tx_queue_release(struct rte_eth_dev *eth_dev, uint16_t queue_id)
 {
-	(void)eth_dev;
-	(void)queue_id;
+	struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private;
+	struct ntnic_tx_queue *tx_q = &internals->txq_scg[queue_id];
+	deallocate_hw_virtio_queues(&tx_q->hwq);
 }
 
 static void eth_rx_queue_release(struct rte_eth_dev *eth_dev, uint16_t queue_id)
 {
-	(void)eth_dev;
-	(void)queue_id;
+	struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private;
+	struct ntnic_rx_queue *rx_q = &internals->rxq_scg[queue_id];
+	deallocate_hw_virtio_queues(&rx_q->hwq);
 }
 
 static int num_queues_alloced;