]> git.droids-corp.org - dpdk.git/commitdiff
net/bnxt: use enum for bank ID
authorJay Ding <jay.ding@broadcom.com>
Wed, 3 Nov 2021 00:52:51 +0000 (17:52 -0700)
committerAjit Khaparde <ajit.khaparde@broadcom.com>
Thu, 4 Nov 2021 21:15:10 +0000 (22:15 +0100)
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
drivers/net/bnxt/tf_core/tf_device.h
drivers/net/bnxt/tf_core/tf_device_p58.c
drivers/net/bnxt/tf_core/tf_tbl.c

index b2886355faea231a0983a8a45b334827ea501a03..f891d7a48f0d6895be14606ee7f49e6b6a193c7c 100644 (file)
@@ -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];
 };
 
 /**
index 3d5de988c49365a5a846d7cb1ba7c5abf528ea51..bfb5de4370cc02e27f3d2ce99c1b783b0ff500f5 100644 (file)
@@ -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);
 };
 
 /**
index 3c1c3a2de1ccbefed292df5f73bd2941761b76b2..30c0af7eef7f39f10e6ecac5d0048f02e5a3f50b 100644 (file)
@@ -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;
index 3fb22b52ace885e6e86b047a1a27d39c3041d5d8..f18e4ba346e08ed3770f7d877cd82a863b6131a3 100644 (file)
@@ -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 */