[v6,42/47] net/bnxt: tf_ulp: TFC support flow scale query for Thor2

Message ID 20241021082607.232829-43-sriharsha.basavapatna@broadcom.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ajit Khaparde
Headers
Series TruFlow update for Thor2 |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Sriharsha Basavapatna Oct. 21, 2024, 8:26 a.m. UTC
From: Shuanglin Wang <shuanglin.wang@broadcom.com>

TFC supports the flow scale query feature for OVS application.
The resource usage(WC-TCAM) is tracked inside Thor2 firmware.
This patch is to query the wc-tcam usage info when adding/
deleting a flow. It is just for debugging purpose and disabled by
default.

Using the build flag -DTF_FLOW_SCALE_QUERY to enable it.
And users should use niccli to query the resource usage.

Signed-off-by: Shuanglin Wang <shuanglin.wang@broadcom.com>
Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Reviewed-by: Kishore Padmanabha <kishore.padmanabha@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/tf_ulp/bnxt_ulp_tfc.c |  6 ++++++
 drivers/net/bnxt/tf_ulp/ulp_flow_db.c  |  9 +++++----
 drivers/net/bnxt/tf_ulp/ulp_mapper.c   | 26 ++++++++++++++++++++++++--
 drivers/net/bnxt/tf_ulp/ulp_mapper.h   |  5 +++++
 4 files changed, 40 insertions(+), 6 deletions(-)
  

Patch

diff --git a/drivers/net/bnxt/tf_ulp/bnxt_ulp_tfc.c b/drivers/net/bnxt/tf_ulp/bnxt_ulp_tfc.c
index d30339393e..ebbc5a85a9 100644
--- a/drivers/net/bnxt/tf_ulp/bnxt_ulp_tfc.c
+++ b/drivers/net/bnxt/tf_ulp/bnxt_ulp_tfc.c
@@ -34,6 +34,7 @@ 
 #include "ulp_ha_mgr.h"
 #include "bnxt_tf_pmd_shim.h"
 #include "ulp_template_db_tbl.h"
+#include "tfc_resources.h"
 
 /* define to enable shared table scope */
 #define TFC_SHARED_TBL_SCOPE_ENABLE 0
@@ -1053,6 +1054,11 @@  ulp_tfc_init(struct bnxt *bp,
 		}
 	}
 
+#ifdef TF_FLOW_SCALE_QUERY
+	/* Query resource statstics from firmware */
+	tfc_resc_usage_query_all(bp);
+#endif /* TF_FLOW_SCALE_QUERY */
+
 	BNXT_DRV_DBG(DEBUG, "ulp ctx has been initialized\n");
 	return rc;
 
diff --git a/drivers/net/bnxt/tf_ulp/ulp_flow_db.c b/drivers/net/bnxt/tf_ulp/ulp_flow_db.c
index 341c8c2dfe..8984808b67 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_flow_db.c
+++ b/drivers/net/bnxt/tf_ulp/ulp_flow_db.c
@@ -15,6 +15,7 @@ 
 #include "ulp_tun.h"
 #ifdef TF_FLOW_SCALE_QUERY
 #include "tf_resources.h"
+#include "tfc_resources.h"
 #endif /* TF_FLOW_SCALE_QUERY */
 
 #define ULP_FLOW_DB_RES_DIR_BIT		31
@@ -963,11 +964,12 @@  ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
 #ifdef TF_FLOW_SCALE_QUERY
 	tf_resc_pause_usage_update();
 #endif
+
 	while (!ulp_flow_db_next_entry_get(flow_db, flow_type, &fid))
 		ulp_mapper_resources_free(ulp_ctx, flow_type, fid, NULL);
+
 #ifdef TF_FLOW_SCALE_QUERY
-	tf_resc_resume_usage_update();
-	tf_resc_usage_update_all(ulp_ctx->bp);
+	ulp_resc_usage_sync(ulp_ctx);
 #endif
 
 	bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
@@ -1017,8 +1019,7 @@  ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
 						  NULL);
 	}
 #ifdef TF_FLOW_SCALE_QUERY
-	tf_resc_resume_usage_update();
-	tf_resc_usage_update_all(ulp_ctx->bp);
+	ulp_resc_usage_sync(ulp_ctx);
 #endif
 	bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
 	return 0;
diff --git a/drivers/net/bnxt/tf_ulp/ulp_mapper.c b/drivers/net/bnxt/tf_ulp/ulp_mapper.c
index 5dfe72df17..c595e7cfc3 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_mapper.c
+++ b/drivers/net/bnxt/tf_ulp/ulp_mapper.c
@@ -24,6 +24,7 @@ 
 #include "bnxt_tf_pmd_shim.h"
 #ifdef TF_FLOW_SCALE_QUERY
 #include "tf_resources.h"
+#include "tfc_resources.h"
 #endif /* TF_FLOW_SCALE_QUERY */
 
 static uint8_t mapper_fld_zeros[16] = { 0 };
@@ -4322,7 +4323,7 @@  ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
 #ifdef TF_FLOW_SCALE_QUERY
 	/* update for regular flows only */
 	if (flow_type == BNXT_ULP_FDB_TYPE_REGULAR)
-		tf_resc_usage_update_all(ulp_ctx->bp);
+		ulp_resc_usage_sync(ulp_ctx);
 #endif /* TF_FLOW_SCALE_QUERY */
 
 	return frc;
@@ -4475,7 +4476,7 @@  ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
 	}
 
 #ifdef TF_FLOW_SCALE_QUERY
-	tf_resc_usage_update_all(ulp_ctx->bp);
+	ulp_resc_usage_sync(ulp_ctx);
 #endif /* TF_FLOW_SCALE_QUERY */
 
 	return rc;
@@ -4514,6 +4515,27 @@  ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
 	return rc;
 }
 
+#ifdef TF_FLOW_SCALE_QUERY
+/* Sync resource usage state with firmware */
+int ulp_resc_usage_sync(struct bnxt_ulp_context *ulp_ctx)
+{
+	uint32_t dev_id;
+	if (unlikely(bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id))) {
+		BNXT_DRV_DBG(ERR, "Invalid ulp context\n");
+		return -EINVAL;
+	}
+
+	if (dev_id == BNXT_ULP_DEVICE_ID_THOR) {
+		tf_resc_resume_usage_update();
+		tf_resc_usage_update_all(ulp_ctx->bp);
+	} else if (dev_id == BNXT_ULP_DEVICE_ID_THOR2) {
+		tfc_resc_usage_query_all(ulp_ctx->bp);
+	}
+
+	return 0;
+}
+#endif /* TF_FLOW_SCALE_QUERY */
+
 int32_t
 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
 {
diff --git a/drivers/net/bnxt/tf_ulp/ulp_mapper.h b/drivers/net/bnxt/tf_ulp/ulp_mapper.h
index 0f43e2a8b5..d2fc716232 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_mapper.h
+++ b/drivers/net/bnxt/tf_ulp/ulp_mapper.h
@@ -302,4 +302,9 @@  ulp_mapper_init(struct bnxt_ulp_context	*ulp_ctx);
 void
 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx);
 
+#ifdef TF_FLOW_SCALE_QUERY
+int32_t
+ulp_resc_usage_sync(struct bnxt_ulp_context *ulp_ctx);
+#endif /* TF_FLOW_SCALE_QUERY */
+
 #endif /* _ULP_MAPPER_H_ */