diff mbox series

[v5,22/22] net/bnxt: use enum for bank ID

Message ID 20211104215846.58672-23-ajit.khaparde@broadcom.com (mailing list archive)
State Accepted, archived
Delegated to: Ajit Khaparde
Headers show
Series fixes and enhancements to Truflow | expand

Checks

Context Check Description
ci/iol-x86_64-unit-testing fail Testing issues
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/checkpatch success coding style OK

Commit Message

Ajit Khaparde Nov. 4, 2021, 9:58 p.m. UTC
From: Jay Ding <jay.ding@broadcom.com>

Instead of integer, using enum tf_sram_bank_id for bank
id in tf_set_sram_policy_parms.

Add index check against the allocation of the meter
instance for meter drop count because there is no
reason to access it if the corresponding meter
entry is not allocated.

Signed-off-by: Jay Ding <jay.ding@broadcom.com>
Reviewed-by: Steve Rempe <steve.rempe@broadcom.com>
Reviewed-by: Farah Smith <farah.smith@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/tf_core/tf_core.h       |  4 +-
 drivers/net/bnxt/tf_core/tf_device.h     |  4 +-
 drivers/net/bnxt/tf_core/tf_device_p58.c | 10 ++--
 drivers/net/bnxt/tf_core/tf_tbl.c        | 75 ++++++++++++------------
 4 files changed, 47 insertions(+), 46 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/bnxt/tf_core/tf_core.h b/drivers/net/bnxt/tf_core/tf_core.h
index b2886355fa..f891d7a48f 100644
--- a/drivers/net/bnxt/tf_core/tf_core.h
+++ b/drivers/net/bnxt/tf_core/tf_core.h
@@ -2520,7 +2520,7 @@  struct tf_set_sram_policy_parms {
 	/**
 	 * [in] Array of Bank id for each truflow tbl type
 	 */
-	uint8_t *bank_id;
+	enum tf_sram_bank_id bank_id[TF_TBL_TYPE_ACT_MODIFY_64B + 1];
 };
 
 /**
@@ -2552,7 +2552,7 @@  struct tf_get_sram_policy_parms {
 	/**
 	 * [out] Array of Bank id for each truflow tbl type
 	 */
-	uint8_t bank_id[TF_TBL_TYPE_ACT_MODIFY_64B + 1];
+	enum tf_sram_bank_id bank_id[TF_TBL_TYPE_ACT_MODIFY_64B + 1];
 };
 
 /**
diff --git a/drivers/net/bnxt/tf_core/tf_device.h b/drivers/net/bnxt/tf_core/tf_device.h
index 3d5de988c4..bfb5de4370 100644
--- a/drivers/net/bnxt/tf_core/tf_device.h
+++ b/drivers/net/bnxt/tf_core/tf_device.h
@@ -1116,7 +1116,7 @@  struct tf_dev_ops {
 	 *   - (-EINVAL) on failure.
 	 */
 	int (*tf_dev_set_sram_policy)(enum tf_dir dir,
-				      uint8_t *bank_id);
+				      enum tf_sram_bank_id *bank_id);
 
 	/**
 	 * Device specific function that gets the sram policy
@@ -1132,7 +1132,7 @@  struct tf_dev_ops {
 	 *   - (-EINVAL) on failure.
 	 */
 	int (*tf_dev_get_sram_policy)(enum tf_dir dir,
-				      uint8_t *bank_id);
+				      enum tf_sram_bank_id *bank_id);
 };
 
 /**
diff --git a/drivers/net/bnxt/tf_core/tf_device_p58.c b/drivers/net/bnxt/tf_core/tf_device_p58.c
index 3c1c3a2de1..30c0af7eef 100644
--- a/drivers/net/bnxt/tf_core/tf_device_p58.c
+++ b/drivers/net/bnxt/tf_core/tf_device_p58.c
@@ -673,7 +673,7 @@  static int tf_dev_p58_get_sram_resources(void *q,
 	return 0;
 }
 
-int sram_bank_hcapi_type[] = {
+static int sram_bank_hcapi_type[] = {
 	CFA_RESOURCE_TYPE_P58_SRAM_BANK_0,
 	CFA_RESOURCE_TYPE_P58_SRAM_BANK_1,
 	CFA_RESOURCE_TYPE_P58_SRAM_BANK_2,
@@ -694,15 +694,15 @@  int sram_bank_hcapi_type[] = {
  *   - (-EINVAL) on failure.
  */
 static int tf_dev_p58_set_sram_policy(enum tf_dir dir,
-				      uint8_t *bank_id)
+				      enum tf_sram_bank_id *bank_id)
 {
 	struct tf_rm_element_cfg *rm_cfg = tf_tbl_p58[dir];
 	uint8_t type;
 	uint8_t parent[TF_SRAM_BANK_ID_MAX] = { 0xFF, 0xFF, 0xFF, 0xFF };
 
 	for (type = TF_TBL_TYPE_FULL_ACT_RECORD;
-			type < TF_TBL_TYPE_ACT_MODIFY_64B + 1; type++) {
-		if (bank_id[type] > 3)
+			type <= TF_TBL_TYPE_ACT_MODIFY_64B; type++) {
+		if (bank_id[type] >= TF_SRAM_BANK_ID_MAX)
 			return -EINVAL;
 
 		rm_cfg[type].hcapi_type = sram_bank_hcapi_type[bank_id[type]];
@@ -735,7 +735,7 @@  static int tf_dev_p58_set_sram_policy(enum tf_dir dir,
  *   - (-EINVAL) on failure.
  */
 static int tf_dev_p58_get_sram_policy(enum tf_dir dir,
-				      uint8_t *bank_id)
+				      enum tf_sram_bank_id *bank_id)
 {
 	struct tf_rm_element_cfg *rm_cfg = tf_tbl_p58[dir];
 	uint8_t type;
diff --git a/drivers/net/bnxt/tf_core/tf_tbl.c b/drivers/net/bnxt/tf_core/tf_tbl.c
index 3fb22b52ac..f18e4ba346 100644
--- a/drivers/net/bnxt/tf_core/tf_tbl.c
+++ b/drivers/net/bnxt/tf_core/tf_tbl.c
@@ -307,28 +307,28 @@  tf_tbl_set(struct tf *tfp,
 	}
 	tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
 
-
-	/* Do not check meter drop counter because it is not allocated
-	 * resources
+	/* Verify that the entry has been previously allocated.
+	 * for meter drop counter, check the corresponding meter
+	 * entry
 	 */
-	if (parms->type != TF_TBL_TYPE_METER_DROP_CNT) {
-		/* Verify that the entry has been previously allocated */
-		aparms.rm_db = tbl_db->tbl_db[parms->dir];
+	aparms.rm_db = tbl_db->tbl_db[parms->dir];
+	if (parms->type != TF_TBL_TYPE_METER_DROP_CNT)
 		aparms.subtype = parms->type;
-		aparms.allocated = &allocated;
-		aparms.index = parms->idx;
-		rc = tf_rm_is_allocated(&aparms);
-		if (rc)
-			return rc;
+	else
+		aparms.subtype = TF_TBL_TYPE_METER_INST;
+	aparms.allocated = &allocated;
+	aparms.index = parms->idx;
+	rc = tf_rm_is_allocated(&aparms);
+	if (rc)
+		return rc;
 
-		if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
-			TFP_DRV_LOG(ERR,
-			      "%s, Invalid or not allocated, type:%s, idx:%d\n",
-			      tf_dir_2_str(parms->dir),
-			      tf_tbl_type_2_str(parms->type),
-			      parms->idx);
-			return -EINVAL;
-		}
+	if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
+		TFP_DRV_LOG(ERR,
+		      "%s, Invalid or not allocated, type:%s, idx:%d\n",
+		      tf_dir_2_str(parms->dir),
+		      tf_tbl_type_2_str(parms->type),
+		      parms->idx);
+		return -EINVAL;
 	}
 
 	/* Set the entry */
@@ -398,27 +398,28 @@  tf_tbl_get(struct tf *tfp,
 	}
 	tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
 
-	/* Do not check meter drop counter because it is not allocated
-	 * resources.
+	/* Verify that the entry has been previously allocated.
+	 * for meter drop counter, check the corresponding meter
+	 * entry
 	 */
-	if (parms->type != TF_TBL_TYPE_METER_DROP_CNT) {
-		/* Verify that the entry has been previously allocated */
-		aparms.rm_db = tbl_db->tbl_db[parms->dir];
+	aparms.rm_db = tbl_db->tbl_db[parms->dir];
+	if (parms->type != TF_TBL_TYPE_METER_DROP_CNT)
 		aparms.subtype = parms->type;
-		aparms.index = parms->idx;
-		aparms.allocated = &allocated;
-		rc = tf_rm_is_allocated(&aparms);
-		if (rc)
-			return rc;
+	else
+		aparms.subtype = TF_TBL_TYPE_METER_INST;
+	aparms.index = parms->idx;
+	aparms.allocated = &allocated;
+	rc = tf_rm_is_allocated(&aparms);
+	if (rc)
+		return rc;
 
-		if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
-			TFP_DRV_LOG(ERR,
-			   "%s, Invalid or not allocated index, type:%s, idx:%d\n",
-			   tf_dir_2_str(parms->dir),
-			   tf_tbl_type_2_str(parms->type),
-			   parms->idx);
-			return -EINVAL;
-		}
+	if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
+		TFP_DRV_LOG(ERR,
+		   "%s, Invalid or not allocated index, type:%s, idx:%d\n",
+		   tf_dir_2_str(parms->dir),
+		   tf_tbl_type_2_str(parms->type),
+		   parms->idx);
+		return -EINVAL;
 	}
 
 	/* Set the entry */