[v2,28/34] net/ntnic: fix group print

Message ID 20250205104548.1533554-29-sil-plv@napatech.com (mailing list archive)
State Accepted, archived
Delegated to: Stephen Hemminger
Headers
Series net/ntnic: bugfixes and refactoring |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Serhii Iliushyk Feb. 5, 2025, 10:45 a.m. UTC
From: Danylo Vodopianov <dvo-plv@napatech.com>

Flow dump output was fixed to show original group
number for `jumps` stored in action and match sets.

Fixes: 6f0fe142caed ("net/ntnic: add flow dump")

Signed-off-by: Danylo Vodopianov <dvo-plv@napatech.com>
---
 drivers/net/ntnic/include/flow_api_engine.h   |  2 ++
 drivers/net/ntnic/nthw/flow_api/flow_group.c  | 26 +++++++++++++++++++
 .../profile_inline/flow_api_hw_db_inline.c    | 24 ++++++++++++-----
 3 files changed, 45 insertions(+), 7 deletions(-)
  

Patch

diff --git a/drivers/net/ntnic/include/flow_api_engine.h b/drivers/net/ntnic/include/flow_api_engine.h
index 636c53b260..262317002f 100644
--- a/drivers/net/ntnic/include/flow_api_engine.h
+++ b/drivers/net/ntnic/include/flow_api_engine.h
@@ -425,5 +425,7 @@  int flow_group_handle_destroy(void **handle);
 
 int flow_group_translate_get(void *handle, uint8_t owner_id, uint8_t port_id, uint32_t group_in,
 	uint32_t *group_out);
+int flow_group_translate_get_orig_group(void *handle, uint32_t translated_group,
+	uint32_t *group_orig);
 
 #endif  /* _FLOW_API_ENGINE_H_ */
diff --git a/drivers/net/ntnic/nthw/flow_api/flow_group.c b/drivers/net/ntnic/nthw/flow_api/flow_group.c
index f76986b178..d1fa0193e1 100644
--- a/drivers/net/ntnic/nthw/flow_api/flow_group.c
+++ b/drivers/net/ntnic/nthw/flow_api/flow_group.c
@@ -14,6 +14,7 @@ 
 struct group_lookup_entry_s {
 	uint64_t ref_counter;
 	uint32_t *reverse_lookup;
+	uint32_t group_orig;
 };
 
 struct group_handle_s {
@@ -83,6 +84,7 @@  int flow_group_translate_get(void *handle, uint8_t owner_id, uint8_t port_id, ui
 		if (lookup < group_handle->group_count) {
 			group_handle->lookup_entries[lookup].reverse_lookup = table_ptr;
 			group_handle->lookup_entries[lookup].ref_counter += 1;
+			group_handle->lookup_entries[lookup].group_orig = group_in;
 
 			*table_ptr = lookup;
 
@@ -97,3 +99,27 @@  int flow_group_translate_get(void *handle, uint8_t owner_id, uint8_t port_id, ui
 	*group_out = lookup;
 	return 0;
 }
+
+int flow_group_translate_get_orig_group(void *handle, uint32_t translated_group,
+	uint32_t *group_orig)
+{
+	struct group_handle_s *group_handle = (struct group_handle_s *)handle;
+	struct group_lookup_entry_s *lookup;
+
+	if (group_handle == NULL || translated_group >= group_handle->group_count)
+		return -1;
+
+	/* Don't translate group 0 */
+	if (translated_group == 0) {
+		*group_orig = 0;
+		return 0;
+	}
+
+	lookup = &group_handle->lookup_entries[translated_group];
+
+	if (lookup->reverse_lookup && lookup->ref_counter > 0) {
+		*group_orig = lookup->group_orig;
+		return 0;
+	}
+	return -1;
+}
diff --git a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_hw_db_inline.c b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_hw_db_inline.c
index 22cbf61b60..278be8b180 100644
--- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_hw_db_inline.c
+++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_hw_db_inline.c
@@ -429,9 +429,14 @@  void hw_db_inline_dump(struct flow_nic_dev *ndev, void *db_handle, const struct
 				data->cat.ids, data->km.id1, data->km_ft.id1,
 				data->action_set.ids);
 
-			if (data->jump)
-				fprintf(file, "    Jumps to %d\n", data->jump);
-
+			if (data->jump) {
+				uint32_t group_orig = 0;
+				if (flow_group_translate_get_orig_group(ndev->group_handle,
+					data->jump, &group_orig) < 0)
+					fprintf(file, "    Jumps to %d (encoded)\n", data->jump);
+				else
+					fprintf(file, "    Jumps to %d\n", group_orig);
+			}
 			break;
 		}
 
@@ -440,15 +445,20 @@  void hw_db_inline_dump(struct flow_nic_dev *ndev, void *db_handle, const struct
 					&db->action_set[idxs[i].ids].data;
 			fprintf(file, "  ACTION_SET %d\n", idxs[i].ids);
 
-			if (data->contains_jump)
-				fprintf(file, "    Jumps to %d\n", data->jump);
+			if (data->contains_jump) {
+				uint32_t group_orig = 0;
+				if (flow_group_translate_get_orig_group(ndev->group_handle,
+					data->jump, &group_orig) < 0)
+					fprintf(file, "    Jumps to %d (encoded)\n", data->jump);
 
-			else
+				else
+					fprintf(file, "    Jumps to %d\n", group_orig);
+			} else {
 				fprintf(file,
 					"    COT id %d, QSL id %d, SLC_LR id %d, TPE id %d, HSH id %d, SCRUB id %d\n",
 					data->cot.ids, data->qsl.ids, data->slc_lr.ids,
 					data->tpe.ids, data->hsh.ids, data->scrub.ids);
-
+			}
 			break;
 		}