From: Jay Ding Date: Sun, 30 May 2021 08:58:53 +0000 (+0530) Subject: net/bnxt: refactor host session failure cleanup X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=b08e34cd402538272a77b49d7daf9a9e4ce700c8;p=dpdk.git net/bnxt: refactor host session failure cleanup - Close FW session if session open fails after Fw session open. - Additional WC TCAM debug info to help in future debug - Reduce key/mask buffer sizes for performance - When a 64b counter is freed, clear the entry Signed-off-by: Jay Ding Signed-off-by: Farah Smith Signed-off-by: Venkat Duvvuru Reviewed-by: Randy Schacher Reviewed-by: Ajit Khaparde --- diff --git a/drivers/net/bnxt/tf_core/tf_em_internal.c b/drivers/net/bnxt/tf_core/tf_em_internal.c index 28ffbd5876..0720bb905d 100644 --- a/drivers/net/bnxt/tf_core/tf_em_internal.c +++ b/drivers/net/bnxt/tf_core/tf_em_internal.c @@ -543,18 +543,21 @@ tf_em_get_resc_info(struct tf *tfp, TF_CHECK_PARMS2(tfp, em); rc = tf_session_get_db(tfp, TF_MODULE_TYPE_EM, &em_db_ptr); - if (rc) { - TFP_DRV_LOG(INFO, - "No resource allocated for em from session\n"); - return 0; - } + if (rc == -ENOMEM) + return 0; /* db does not exist */ + else if (rc) + return rc; /* db error */ + em_db = (struct em_rm_db *)em_db_ptr; - /* check if reserved resource for WC is multiple of num_slices */ + /* check if reserved resource for EM is multiple of num_slices */ for (d = 0; d < TF_DIR_MAX; d++) { ainfo.rm_db = em_db->em_db[d]; dinfo = em[d].info; + if (!ainfo.rm_db) + continue; + ainfo.info = (struct tf_rm_alloc_info *)dinfo; ainfo.subtype = 0; rc = tf_rm_get_all_info(&ainfo, TF_EM_TBL_TYPE_MAX); diff --git a/drivers/net/bnxt/tf_core/tf_identifier.c b/drivers/net/bnxt/tf_core/tf_identifier.c index 9f27a41fcf..c491f77a2b 100644 --- a/drivers/net/bnxt/tf_core/tf_identifier.c +++ b/drivers/net/bnxt/tf_core/tf_identifier.c @@ -369,16 +369,20 @@ tf_ident_get_resc_info(struct tf *tfp, TF_CHECK_PARMS2(tfp, ident); rc = tf_session_get_db(tfp, TF_MODULE_TYPE_IDENTIFIER, &ident_db_ptr); - if (rc) { - TFP_DRV_LOG(INFO, - "No resource allocated for ident from session\n"); - return 0; - } + if (rc == -ENOMEM) + return 0; /* db doesn't exist */ + else if (rc) + return rc; /* error getting db */ + ident_db = (struct ident_rm_db *)ident_db_ptr; /* check if reserved resource for WC is multiple of num_slices */ for (d = 0; d < TF_DIR_MAX; d++) { ainfo.rm_db = ident_db->ident_db[d]; + + if (!ainfo.rm_db) + continue; + dinfo = ident[d].info; ainfo.info = (struct tf_rm_alloc_info *)dinfo; diff --git a/drivers/net/bnxt/tf_core/tf_msg.c b/drivers/net/bnxt/tf_core/tf_msg.c index 18eea8338a..fbd4b1d910 100644 --- a/drivers/net/bnxt/tf_core/tf_msg.c +++ b/drivers/net/bnxt/tf_core/tf_msg.c @@ -267,31 +267,13 @@ tf_msg_session_client_unregister(struct tf *tfp, int tf_msg_session_close(struct tf *tfp, - struct tf_session *tfs) + uint8_t fw_session_id, + int mailbox) { int rc; struct hwrm_tf_session_close_input req = { 0 }; struct hwrm_tf_session_close_output resp = { 0 }; struct tfp_send_msg_parms parms = { 0 }; - uint8_t fw_session_id; - struct tf_dev_info *dev; - - /* Retrieve the device information */ - rc = tf_session_get_device(tfs, &dev); - if (rc) { - TFP_DRV_LOG(ERR, - "Failed to lookup device, rc:%s\n", - strerror(-rc)); - return rc; - } - - rc = tf_session_get_fw_session_id(tfp, &fw_session_id); - if (rc) { - TFP_DRV_LOG(ERR, - "Unable to lookup FW id, rc:%s\n", - strerror(-rc)); - return rc; - } /* Populate the request */ req.fw_session_id = tfp_cpu_to_le_32(fw_session_id); @@ -301,7 +283,7 @@ tf_msg_session_close(struct tf *tfp, parms.req_size = sizeof(req); parms.resp_data = (uint32_t *)&resp; parms.resp_size = sizeof(resp); - parms.mailbox = dev->ops->tf_dev_get_mailbox(); + parms.mailbox = mailbox; rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms); diff --git a/drivers/net/bnxt/tf_core/tf_msg.h b/drivers/net/bnxt/tf_core/tf_msg.h index e8662fef0e..b26b15bfa3 100644 --- a/drivers/net/bnxt/tf_core/tf_msg.h +++ b/drivers/net/bnxt/tf_core/tf_msg.h @@ -115,11 +115,18 @@ int tf_msg_session_client_unregister(struct tf *tfp, * [in] session * Pointer to session handle * + * [in] fw_session_id + * fw session id + * + * [in] mailbox + * mailbox + * * Returns: * 0 on Success else internal Truflow error */ int tf_msg_session_close(struct tf *tfp, - struct tf_session *tfs); + uint8_t fw_session_id, + int mailbox); /** * Sends session query config request to TF Firmware diff --git a/drivers/net/bnxt/tf_core/tf_rm.c b/drivers/net/bnxt/tf_core/tf_rm.c index f44b5b1ab6..dcfba24b2c 100644 --- a/drivers/net/bnxt/tf_core/tf_rm.c +++ b/drivers/net/bnxt/tf_core/tf_rm.c @@ -18,9 +18,6 @@ #include "tfp.h" #include "tf_msg.h" -/* Logging defines */ -#define TF_RM_DEBUG 0 - /** * Generic RM Element data type that an RM DB is build upon. */ @@ -204,44 +201,6 @@ tf_rm_adjust_index(struct tf_rm_element *db, return rc; } -/** - * Logs an array of found residual entries to the console. - * - * [in] dir - * Receive or transmit direction - * - * [in] module - * Type of Device Module - * - * [in] count - * Number of entries in the residual array - * - * [in] residuals - * Pointer to an array of residual entries. Array is index same as - * the DB in which this function is used. Each entry holds residual - * value for that entry. - */ -static void -tf_rm_log_residuals(enum tf_dir dir, - enum tf_module_type module, - uint16_t count, - uint16_t *residuals) -{ - int i; - - /* Walk the residual array and log the types that wasn't - * cleaned up to the console. - */ - for (i = 0; i < count; i++) { - if (residuals[i] != 0) - TFP_DRV_LOG(ERR, - "%s, %s was not cleaned up, %d outstanding\n", - tf_dir_2_str(dir), - tf_module_subtype_2_str(module, i), - residuals[i]); - } -} - /** * Performs a check of the passed in DB for any lingering elements. If * a resource type was found to not have been cleaned up by the caller @@ -357,11 +316,6 @@ tf_rm_check_residuals(struct tf_rm_new_db *rm_db, *resv_size = found; } - tf_rm_log_residuals(rm_db->dir, - rm_db->module, - rm_db->num_entries, - residuals); - tfp_free((void *)residuals); *resv = local_resv; @@ -544,11 +498,6 @@ tf_rm_create_db(struct tf *tfp, &hcapi_items); if (hcapi_items == 0) { - TFP_DRV_LOG(ERR, - "%s: module:%s Empty RM DB create request\n", - tf_dir_2_str(parms->dir), - tf_module_2_str(parms->module)); - parms->rm_db = NULL; return -ENOMEM; } @@ -1296,7 +1245,13 @@ tf_rm_get_all_info(struct tf_rm_get_alloc_info_parms *parms, int size) struct tf_rm_alloc_info *info = parms->info; int i; - TF_CHECK_PARMS2(parms, parms->rm_db); + TF_CHECK_PARMS1(parms); + + /* No rm info available for this module type + */ + if (!parms->rm_db) + return -ENOMEM; + rm_db = (struct tf_rm_new_db *)parms->rm_db; TF_CHECK_PARMS1(rm_db->db); diff --git a/drivers/net/bnxt/tf_core/tf_session.c b/drivers/net/bnxt/tf_core/tf_session.c index 70844edb50..71ccb2e3e7 100644 --- a/drivers/net/bnxt/tf_core/tf_session.c +++ b/drivers/net/bnxt/tf_core/tf_session.c @@ -215,6 +215,16 @@ tf_session_create(struct tf *tfp, return 0; cleanup: + rc = tf_msg_session_close(tfp, + fw_session_id, + dev.ops->tf_dev_get_mailbox()); + if (rc) { + /* Log error */ + TFP_DRV_LOG(ERR, + "FW Session close failed, rc:%s\n", + strerror(-rc)); + } + tfp_free(tfp->session->core_data); tfp_free(tfp->session); tfp->session = NULL; @@ -479,6 +489,8 @@ tf_session_close_session(struct tf *tfp, struct tf_dev_info *tfd = NULL; struct tf_session_client_destroy_parms scdparms; uint16_t fid; + uint8_t fw_session_id = 1; + int mailbox = 0; TF_CHECK_PARMS2(tfp, parms); @@ -563,6 +575,16 @@ tf_session_close_session(struct tf *tfp, return rc; } + mailbox = tfd->ops->tf_dev_get_mailbox(); + + rc = tf_session_get_fw_session_id(tfp, &fw_session_id); + if (rc) { + TFP_DRV_LOG(ERR, + "Unable to lookup FW id, rc:%s\n", + strerror(-rc)); + return rc; + } + /* Unbind the device */ rc = tf_dev_unbind(tfp, tfd); if (rc) { @@ -572,7 +594,7 @@ tf_session_close_session(struct tf *tfp, strerror(-rc)); } - rc = tf_msg_session_close(tfp, tfs); + rc = tf_msg_session_close(tfp, fw_session_id, mailbox); if (rc) { /* Log error */ TFP_DRV_LOG(ERR, @@ -881,26 +903,26 @@ tf_session_get_db(struct tf *tfp, if (tfs->id_db_handle) *db_handle = tfs->id_db_handle; else - rc = -EINVAL; + rc = -ENOMEM; break; case TF_MODULE_TYPE_TABLE: if (tfs->tbl_db_handle) *db_handle = tfs->tbl_db_handle; else - rc = -EINVAL; + rc = -ENOMEM; break; case TF_MODULE_TYPE_TCAM: if (tfs->tcam_db_handle) *db_handle = tfs->tcam_db_handle; else - rc = -EINVAL; + rc = -ENOMEM; break; case TF_MODULE_TYPE_EM: if (tfs->em_db_handle) *db_handle = tfs->em_db_handle; else - rc = -EINVAL; + rc = -ENOMEM; break; default: rc = -EINVAL; diff --git a/drivers/net/bnxt/tf_core/tf_tbl.c b/drivers/net/bnxt/tf_core/tf_tbl.c index 6842291adf..ced59130b2 100644 --- a/drivers/net/bnxt/tf_core/tf_tbl.c +++ b/drivers/net/bnxt/tf_core/tf_tbl.c @@ -270,6 +270,44 @@ tf_tbl_free(struct tf *tfp __rte_unused, parms->idx); return -EINVAL; } + + /* If this is counter table, clear the entry on free */ + if (parms->type == TF_TBL_TYPE_ACT_STATS_64) { + uint8_t data[8] = { 0 }; + uint16_t hcapi_type = 0; + struct tf_rm_get_hcapi_parms hparms = { 0 }; + + /* Get the hcapi type */ + hparms.rm_db = tbl_db->tbl_db[parms->dir]; + hparms.subtype = parms->type; + hparms.hcapi_type = &hcapi_type; + rc = tf_rm_get_hcapi_type(&hparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s, Failed type lookup, type:%d, rc:%s\n", + tf_dir_2_str(parms->dir), + parms->type, + strerror(-rc)); + return rc; + } + /* Clear the counter + */ + rc = tf_msg_set_tbl_entry(tfp, + parms->dir, + hcapi_type, + sizeof(data), + data, + parms->idx); + if (rc) { + TFP_DRV_LOG(ERR, + "%s, Set failed, type:%d, rc:%s\n", + tf_dir_2_str(parms->dir), + parms->type, + strerror(-rc)); + return rc; + } + } + /* Free requested element */ fparms.rm_db = tbl_db->tbl_db[parms->dir]; fparms.subtype = parms->type; @@ -643,11 +681,11 @@ tf_tbl_get_resc_info(struct tf *tfp, return rc; rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr); - if (rc) { - TFP_DRV_LOG(INFO, - "No resource allocated for table from session\n"); - return 0; - } + if (rc == -ENOMEM) + return 0; /* db doesn't exist */ + else if (rc) + return rc; /* error getting db */ + tbl_db = (struct tbl_rm_db *)tbl_db_ptr; /* check if reserved resource for WC is multiple of num_slices */ @@ -655,6 +693,9 @@ tf_tbl_get_resc_info(struct tf *tfp, ainfo.rm_db = tbl_db->tbl_db[d]; dinfo = tbl[d].info; + if (!ainfo.rm_db) + continue; + ainfo.info = (struct tf_rm_alloc_info *)dinfo; ainfo.subtype = 0; rc = tf_rm_get_all_info(&ainfo, TF_TBL_TYPE_MAX); diff --git a/drivers/net/bnxt/tf_core/tf_tcam.c b/drivers/net/bnxt/tf_core/tf_tcam.c index d7e12e00ef..45206c5992 100644 --- a/drivers/net/bnxt/tf_core/tf_tcam.c +++ b/drivers/net/bnxt/tf_core/tf_tcam.c @@ -818,16 +818,20 @@ tf_tcam_get_resc_info(struct tf *tfp, TF_CHECK_PARMS2(tfp, tcam); rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr); - if (rc) { - TFP_DRV_LOG(INFO, - "No resource allocated for tcam from session\n"); - return 0; - } + if (rc == -ENOMEM) + return 0; /* db doesn't exist */ + else if (rc) + return rc; /* error getting db */ + tcam_db = (struct tcam_rm_db *)tcam_db_ptr; /* check if reserved resource for WC is multiple of num_slices */ for (d = 0; d < TF_DIR_MAX; d++) { ainfo.rm_db = tcam_db->tcam_db[d]; + + if (!ainfo.rm_db) + continue; + dinfo = tcam[d].info; ainfo.info = (struct tf_rm_alloc_info *)dinfo; diff --git a/drivers/net/bnxt/tf_core/tf_tcam_shared.c b/drivers/net/bnxt/tf_core/tf_tcam_shared.c index 9e283f6082..06d5c1d2ac 100644 --- a/drivers/net/bnxt/tf_core/tf_tcam_shared.c +++ b/drivers/net/bnxt/tf_core/tf_tcam_shared.c @@ -841,20 +841,28 @@ tf_tcam_shared_get(struct tf *tfp __rte_unused, return 0; } -/* Temporary builder defines pulled in here and renamed +/* Normally, device specific code wouldn't reside here, it belongs + * in a separate device specific function in tf_device_pxx.c. + * But this code is placed here as it is not a long term solution + * and we would like to have this code centrally located for easy + * removal */ -#define TF_TMP_MAX_FIELD_BITLEN 512 +#define TF_TCAM_SHARED_KEY_SLICE_SZ_BYTES_P4 12 +#define TF_TCAM_SHARED_REMAP_SZ_BYTES_P4 4 +#define TF_TCAM_SHARED_KEY_SLICE_SZ_BYTES_P58 24 +#define TF_TCAM_SHARED_REMAP_SZ_BYTES_P58 8 +/* Temporary builder defines pulled in here and adjusted + * for max WC TCAM values + */ union tf_tmp_field_obj { - uint8_t bytes[(TF_TMP_MAX_FIELD_BITLEN + 7) / 8]; + uint32_t words[(TF_TCAM_SHARED_REMAP_SZ_BYTES_P58 + 3) / 4]; + uint8_t bytes[TF_TCAM_SHARED_REMAP_SZ_BYTES_P58]; }; -#define TF_TMP_MAX_KEY_BITLEN 768 -#define TF_TMP_MAX_KEY_WORDLEN ((TF_TMP_MAX_KEY_BITLEN + 63) / 64) - union tf_tmp_key { - uint32_t words[(TF_TMP_MAX_KEY_BITLEN + 31) / 32]; - uint8_t bytes[(TF_TMP_MAX_KEY_BITLEN + 7) / 8]; + uint32_t words[(TF_TCAM_SHARED_KEY_SLICE_SZ_BYTES_P58 + 3) / 4]; + uint8_t bytes[TF_TCAM_SHARED_KEY_SLICE_SZ_BYTES_P58]; }; /** p58 has an enable bit, p4 does not @@ -933,9 +941,10 @@ tf_tcam_shared_move_entry(struct tf *tfp, if (rc) { /* Log error */ TFP_DRV_LOG(ERR, - "%s: WC_TCAM_LOW phyid(%d) set failed, rc:%s", + "%s: WC_TCAM_LOW phyid(%d/0x%x) set failed, rc:%s", tf_dir_2_str(dir), sparms.idx, + sparms.idx, strerror(-rc)); return rc; } @@ -950,10 +959,11 @@ tf_tcam_shared_move_entry(struct tf *tfp, if (rc) { /* Log error */ TFP_DRV_LOG(ERR, - "%s: %s: phyid(%d) free failed, rc:%s\n", + "%s: %s: phyid(%d/0x%x) free failed, rc:%s\n", tf_dir_2_str(dir), tf_tcam_tbl_2_str(fparms.type), sphy_idx, + sphy_idx, strerror(-rc)); return rc; } @@ -1118,15 +1128,6 @@ done: return rc; } -/* Normally, device specific code wouldn't reside here, it belongs - * in a separate device specific function in tf_device_pxx.c. - * But this code is placed here as it is not a long term solution - * and we would like to have this code centrally located for easy - * removal - */ -#define TF_TCAM_SHARED_KEY_SLICE_SZ_BYTES_P4 12 -#define TF_TCAM_SHARED_REMAP_SZ_BYTES_P4 4 - int tf_tcam_shared_move_p4(struct tf *tfp, struct tf_move_tcam_shared_entries_parms *parms) { @@ -1139,8 +1140,6 @@ int tf_tcam_shared_move_p4(struct tf *tfp, return rc; } -#define TF_TCAM_SHARED_KEY_SLICE_SZ_BYTES_P58 24 -#define TF_TCAM_SHARED_REMAP_SZ_BYTES_P58 8 int tf_tcam_shared_move_p58(struct tf *tfp, struct tf_move_tcam_shared_entries_parms *parms)