[v5,68/80] net/ntnic: add termination thread

Message ID 20241030213940.3470062-69-sil-plv@napatech.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series Provide flow filter and statistics support |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Serhii Iliushyk Oct. 30, 2024, 9:39 p.m. UTC
From: Danylo Vodopianov <dvo-plv@napatech.com>

Introduce clear_pdrv to unregister driver
from global tracking.

Modify drv_deinit to call clear_pdirv and ensure
safe termination.

Add flm sta and age event free.

Signed-off-by: Danylo Vodopianov <dvo-plv@napatech.com>
---
 .../flow_api/profile_inline/flm_age_queue.c   | 10 +++
 .../flow_api/profile_inline/flm_age_queue.h   |  1 +
 .../flow_api/profile_inline/flm_evt_queue.c   | 76 +++++++++++++++++++
 .../flow_api/profile_inline/flm_evt_queue.h   |  1 +
 drivers/net/ntnic/ntnic_ethdev.c              |  6 ++
 5 files changed, 94 insertions(+)
  

Patch

diff --git a/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_age_queue.c b/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_age_queue.c
index 76bbd57f65..d916eccec7 100644
--- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_age_queue.c
+++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_age_queue.c
@@ -44,6 +44,16 @@  void flm_age_queue_free(uint8_t port, uint16_t caller_id)
 		rte_ring_free(q);
 }
 
+void flm_age_queue_free_all(void)
+{
+	int i;
+	int j;
+
+	for (i = 0; i < MAX_EVT_AGE_PORTS; i++)
+		for (j = 0; j < MAX_EVT_AGE_QUEUES; j++)
+			flm_age_queue_free(i, j);
+}
+
 struct rte_ring *flm_age_queue_create(uint8_t port, uint16_t caller_id, unsigned int count)
 {
 	char name[20];
diff --git a/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_age_queue.h b/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_age_queue.h
index 27154836c5..55c410ac86 100644
--- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_age_queue.h
+++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_age_queue.h
@@ -32,6 +32,7 @@  int flm_age_event_get(uint8_t port);
 void flm_age_event_set(uint8_t port);
 void flm_age_event_clear(uint8_t port);
 void flm_age_queue_free(uint8_t port, uint16_t caller_id);
+void flm_age_queue_free_all(void);
 struct rte_ring *flm_age_queue_create(uint8_t port, uint16_t caller_id, unsigned int count);
 void flm_age_queue_put(uint16_t caller_id, struct flm_age_event_s *obj);
 int flm_age_queue_get(uint16_t caller_id, struct flm_age_event_s *obj);
diff --git a/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.c b/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.c
index db9687714f..761609a0ea 100644
--- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.c
+++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.c
@@ -25,6 +25,82 @@  static struct rte_ring *stat_q_local[MAX_STAT_LCL_QUEUES];
 /* Remote queues for flm status records */
 static struct rte_ring *stat_q_remote[MAX_STAT_RMT_QUEUES];
 
+static void flm_inf_sta_queue_free(uint8_t port, uint8_t caller)
+{
+	struct rte_ring *q = NULL;
+
+	/* If queues is not created, then ignore and return */
+	switch (caller) {
+	case FLM_INFO_LOCAL:
+		if (port < MAX_INFO_LCL_QUEUES && info_q_local[port] != NULL) {
+			q = info_q_local[port];
+			info_q_local[port] = NULL;
+		}
+
+		break;
+
+	case FLM_INFO_REMOTE:
+		if (port < MAX_INFO_RMT_QUEUES && info_q_remote[port] != NULL) {
+			q = info_q_remote[port];
+			info_q_remote[port] = NULL;
+		}
+
+		break;
+
+	case FLM_STAT_LOCAL:
+		if (port < MAX_STAT_LCL_QUEUES && stat_q_local[port] != NULL) {
+			q = stat_q_local[port];
+			stat_q_local[port] = NULL;
+		}
+
+		break;
+
+	case FLM_STAT_REMOTE:
+		if (port < MAX_STAT_RMT_QUEUES && stat_q_remote[port] != NULL) {
+			q = stat_q_remote[port];
+			stat_q_remote[port] = NULL;
+		}
+
+		break;
+
+	default:
+		NT_LOG(ERR, FILTER, "FLM queue free illegal caller: %u", caller);
+		break;
+	}
+
+	if (q)
+		rte_ring_free(q);
+}
+
+void flm_inf_sta_queue_free_all(uint8_t caller)
+{
+	int count = 0;
+
+	switch (caller) {
+	case FLM_INFO_LOCAL:
+		count = MAX_INFO_LCL_QUEUES;
+		break;
+
+	case FLM_INFO_REMOTE:
+		count = MAX_INFO_RMT_QUEUES;
+		break;
+
+	case FLM_STAT_LOCAL:
+		count = MAX_STAT_LCL_QUEUES;
+		break;
+
+	case FLM_STAT_REMOTE:
+		count = MAX_STAT_RMT_QUEUES;
+		break;
+
+	default:
+		NT_LOG(ERR, FILTER, "FLM queue free illegal caller: %u", caller);
+		return;
+	}
+
+	for (int i = 0; i < count; i++)
+		flm_inf_sta_queue_free(i, caller);
+}
 
 static struct rte_ring *flm_evt_queue_create(uint8_t port, uint8_t caller)
 {
diff --git a/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.h b/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.h
index 3a61f844b6..d61b282472 100644
--- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.h
+++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.h
@@ -47,6 +47,7 @@  enum {
 #define FLM_EVT_ELEM_SIZE sizeof(struct flm_info_event_s)
 #define FLM_STAT_ELEM_SIZE sizeof(struct flm_status_event_s)
 
+void flm_inf_sta_queue_free_all(uint8_t caller);
 int flm_inf_queue_get(uint8_t port, bool remote, struct flm_info_event_s *obj);
 int flm_sta_queue_put(uint8_t port, bool remote, struct flm_status_event_s *obj);
 
diff --git a/drivers/net/ntnic/ntnic_ethdev.c b/drivers/net/ntnic/ntnic_ethdev.c
index e0f455dc1b..cdf5c346b7 100644
--- a/drivers/net/ntnic/ntnic_ethdev.c
+++ b/drivers/net/ntnic/ntnic_ethdev.c
@@ -1420,6 +1420,12 @@  drv_deinit(struct drv_s *p_drv)
 		THREAD_JOIN(p_nt_drv->flm_thread);
 		profile_inline_ops->flm_free_queues();
 		THREAD_JOIN(p_nt_drv->port_event_thread);
+		/* Free all local flm event queues */
+		flm_inf_sta_queue_free_all(FLM_INFO_LOCAL);
+		/* Free all remote flm event queues */
+		flm_inf_sta_queue_free_all(FLM_INFO_REMOTE);
+		/* Free all aged flow event queues */
+		flm_age_queue_free_all();
 	}
 
 	/* stop adapter */