net/bnxt: use enum for bank ID

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>
This commit is contained in:
Jay Ding 2021-11-02 17:52:51 -07:00 committed by Ajit Khaparde
parent 62d8961f10
commit f2c730d423
4 changed files with 47 additions and 46 deletions

View 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];
};
/**

View 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);
};
/**

View 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;

View 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 */