From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E9747A0521; Thu, 23 Jul 2020 14:05:34 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 07E731C126; Thu, 23 Jul 2020 14:02:44 +0200 (CEST) Received: from relay.smtp.broadcom.com (unknown [192.19.211.62]) by dpdk.org (Postfix) with ESMTP id 13AEA1BFD7 for ; Thu, 23 Jul 2020 14:02:07 +0200 (CEST) Received: from dhcp-10-123-153-55.dhcp.broadcom.net (bgccx-dev-host-lnx35.bec.broadcom.net [10.123.153.55]) by relay.smtp.broadcom.com (Postfix) with ESMTP id A044329AD66; Thu, 23 Jul 2020 05:02:06 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 relay.smtp.broadcom.com A044329AD66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1595505726; bh=6mOBqC3peAlL+fa2J5Ew1Rbo2a95jBbqGiX9KJJkm48=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YoWFEOIXdDC6F8Im8Qmw8ef+EUEpc0+QX53L6hjrYEYrM31UcraSB+F8S7dkogY2o bA6VRbbJF2gApfFQswLSPdkt2gLU1BtW+D7651ucvCvUMbh6efB3kbW2oeXWwXTnnY gc7VO4CFJOMS1nlRs8SQCH65lNs7sr8pCKnT04pQ= From: Somnath Kotur To: dev@dpdk.org Cc: ferruh.yigit@intel.com Date: Thu, 23 Jul 2020 17:26:36 +0530 Message-Id: <20200723115639.22357-18-somnath.kotur@broadcom.com> X-Mailer: git-send-email 2.10.1.613.g2cc2e70 In-Reply-To: <20200723115639.22357-1-somnath.kotur@broadcom.com> References: <20200723111329.21855-1-somnath.kotur@broadcom.com> <20200723115639.22357-1-somnath.kotur@broadcom.com> Subject: [dpdk-dev] [PATCH v2 17/20] net/bnxt: tcam table processing support for search and alloc X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Kishore Padmanabha Added support for tcam table processing to enable the search and allocate support. This also includes the tcam entry update support. Signed-off-by: Kishore Padmanabha Reviewed-by: Michael Baucom --- drivers/net/bnxt/tf_ulp/ulp_mapper.c | 317 ++++++++++++++++--------- drivers/net/bnxt/tf_ulp/ulp_template_db_enum.h | 5 +- drivers/net/bnxt/tf_ulp/ulp_template_struct.h | 8 +- 3 files changed, 213 insertions(+), 117 deletions(-) diff --git a/drivers/net/bnxt/tf_ulp/ulp_mapper.c b/drivers/net/bnxt/tf_ulp/ulp_mapper.c index 4dee659..6ac4b0f 100644 --- a/drivers/net/bnxt/tf_ulp/ulp_mapper.c +++ b/drivers/net/bnxt/tf_ulp/ulp_mapper.c @@ -1317,20 +1317,177 @@ ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms, return rc; } +/* + * Tcam table - create the result blob. + * data [out] - the result blob data + */ +static int32_t +ulp_mapper_tcam_tbl_result_create(struct bnxt_ulp_mapper_parms *parms, + struct bnxt_ulp_mapper_tbl_info *tbl, + struct ulp_blob *data) +{ + struct bnxt_ulp_mapper_result_field_info *dflds; + uint32_t num_dflds; + uint32_t encap_flds = 0; + uint32_t i; + int32_t rc = 0; + + /* Create the result data blob */ + dflds = ulp_mapper_result_fields_get(tbl, &num_dflds, + &encap_flds); + if (!dflds || !num_dflds || encap_flds) { + BNXT_TF_DBG(ERR, "Failed to get data fields.\n"); + return -EINVAL; + } + + for (i = 0; i < num_dflds; i++) { + rc = ulp_mapper_result_field_process(parms, + tbl->direction, + &dflds[i], + data, + "TCAM Result"); + if (rc) { + BNXT_TF_DBG(ERR, "Failed to set data fields\n"); + return -EINVAL; + } + } + return rc; +} + +/* Tcam table scan the identifier list and allocate each identifier */ +static int32_t +ulp_mapper_tcam_tbl_scan_ident_alloc(struct bnxt_ulp_mapper_parms *parms, + struct bnxt_ulp_mapper_tbl_info *tbl) +{ + struct bnxt_ulp_mapper_ident_info *idents; + uint32_t num_idents; + uint32_t i; + + /* + * Since the cache entry is responsible for allocating + * identifiers when in use, allocate the identifiers only + * during normal processing. + */ + if (parms->tcam_tbl_opc == + BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) { + idents = ulp_mapper_ident_fields_get(tbl, &num_idents); + + for (i = 0; i < num_idents; i++) { + if (ulp_mapper_ident_process(parms, tbl, + &idents[i], NULL)) + return -EINVAL; + } + } + return 0; +} + +/* + * Tcam table scan the identifier list and extract the identifier from + * the result blob. + */ +static int32_t +ulp_mapper_tcam_tbl_scan_ident_extract(struct bnxt_ulp_mapper_parms *parms, + struct bnxt_ulp_mapper_tbl_info *tbl, + struct ulp_blob *data) +{ + struct bnxt_ulp_mapper_ident_info *idents; + uint32_t num_idents = 0, i; + int32_t rc = 0; + + /* + * Extract the listed identifiers from the result field, + * no need to allocate them. + */ + idents = ulp_mapper_ident_fields_get(tbl, &num_idents); + for (i = 0; i < num_idents; i++) { + rc = ulp_mapper_ident_extract(parms, tbl, &idents[i], data); + if (rc) { + BNXT_TF_DBG(ERR, "Error in identifier extraction\n"); + return rc; + } + } + return rc; +} + +/* Internal function to write the tcam entry */ +static int32_t +ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms, + struct bnxt_ulp_mapper_tbl_info *tbl, + struct ulp_blob *key, + struct ulp_blob *mask, + struct ulp_blob *data, + uint16_t idx) +{ + struct tf_set_tcam_entry_parms sparms = { 0 }; + struct tf *tfp; + uint16_t tmplen; + int32_t rc; + + tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx); + if (!tfp) { + BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n"); + return -EINVAL; + } + + sparms.dir = tbl->direction; + sparms.tcam_tbl_type = tbl->resource_type; + sparms.idx = idx; + /* Already verified the key/mask lengths */ + sparms.key = ulp_blob_data_get(key, &tmplen); + sparms.mask = ulp_blob_data_get(mask, &tmplen); + sparms.key_sz_in_bits = tbl->key_bit_size; + sparms.result = ulp_blob_data_get(data, &tmplen); + + if (tbl->result_bit_size != tmplen) { + BNXT_TF_DBG(ERR, "Result len (%d) != Expected (%d)\n", + tmplen, tbl->result_bit_size); + return -EINVAL; + } + sparms.result_sz_in_bits = tbl->result_bit_size; + if (tf_set_tcam_entry(tfp, &sparms)) { + BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n", + tf_tcam_tbl_2_str(sparms.tcam_tbl_type), + tf_dir_2_str(sparms.dir), sparms.idx); + return -EIO; + } + BNXT_TF_DBG(INFO, "tcam[%s][%s][%x] write success.\n", + tf_tcam_tbl_2_str(sparms.tcam_tbl_type), + tf_dir_2_str(sparms.dir), sparms.idx); + + /* Update cache with TCAM index if the was cache allocated. */ + if (parms->tcam_tbl_opc == + BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC) { + if (!parms->cache_ptr) { + BNXT_TF_DBG(ERR, "Unable to update cache"); + return -EINVAL; + } + parms->cache_ptr->tcam_idx = idx; + } + + /* Mark action */ + rc = ulp_mapper_mark_act_ptr_process(parms, tbl); + if (rc) { + BNXT_TF_DBG(ERR, "failed mark action processing\n"); + return rc; + } + + return rc; +} + static int32_t ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms, struct bnxt_ulp_mapper_tbl_info *tbl) { struct bnxt_ulp_mapper_class_key_field_info *kflds; - struct ulp_blob key, mask, data; + struct ulp_blob key, mask, data, update_data; uint32_t i, num_kflds; struct tf *tfp; int32_t rc, trc; struct tf_alloc_tcam_entry_parms aparms = { 0 }; struct tf_search_tcam_entry_parms searchparms = { 0 }; - struct tf_set_tcam_entry_parms sparms = { 0 }; struct ulp_flow_db_res_params fid_parms = { 0 }; struct tf_free_tcam_entry_parms free_parms = { 0 }; + enum bnxt_ulp_search_before_alloc search_flag; uint32_t hit = 0; uint16_t tmplen = 0; uint16_t idx; @@ -1358,6 +1515,8 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms, !ulp_blob_init(&mask, tbl->key_bit_size, parms->device_params->byte_order) || !ulp_blob_init(&data, tbl->result_bit_size, + parms->device_params->byte_order) || + !ulp_blob_init(&update_data, tbl->result_bit_size, parms->device_params->byte_order)) { BNXT_TF_DBG(ERR, "blob inits failed.\n"); return -EINVAL; @@ -1388,7 +1547,7 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms, } } - if (!tbl->srch_b4_alloc) { + if (tbl->srch_b4_alloc == BNXT_ULP_SEARCH_BEFORE_ALLOC_NO) { /* * No search for re-use is requested, so simply allocate the * tcam index. @@ -1455,113 +1614,49 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms, hit = searchparms.hit; } - /* Build the result */ - if (!tbl->srch_b4_alloc || !hit) { - struct bnxt_ulp_mapper_result_field_info *dflds; - struct bnxt_ulp_mapper_ident_info *idents; - uint32_t num_dflds, num_idents; - uint32_t encap_flds = 0; - - /* - * Since the cache entry is responsible for allocating - * identifiers when in use, allocate the identifiers only - * during normal processing. - */ - if (parms->tcam_tbl_opc == - BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) { - idents = ulp_mapper_ident_fields_get(tbl, &num_idents); - - for (i = 0; i < num_idents; i++) { - rc = ulp_mapper_ident_process(parms, tbl, - &idents[i], NULL); - /* Already logged the error, just return */ - if (rc) - goto error; - } - } - - /* Create the result data blob */ - dflds = ulp_mapper_result_fields_get(tbl, &num_dflds, - &encap_flds); - if (!dflds || !num_dflds || encap_flds) { - BNXT_TF_DBG(ERR, "Failed to get data fields.\n"); - rc = -EINVAL; - goto error; - } - - for (i = 0; i < num_dflds; i++) { - rc = ulp_mapper_result_field_process(parms, - tbl->direction, - &dflds[i], - &data, - "TCAM Result"); - if (rc) { - BNXT_TF_DBG(ERR, "Failed to set data fields\n"); - goto error; - } - } - - sparms.dir = tbl->direction; - sparms.tcam_tbl_type = tbl->resource_type; - sparms.idx = idx; - /* Already verified the key/mask lengths */ - sparms.key = ulp_blob_data_get(&key, &tmplen); - sparms.mask = ulp_blob_data_get(&mask, &tmplen); - sparms.key_sz_in_bits = tbl->key_bit_size; - sparms.result = ulp_blob_data_get(&data, &tmplen); - - if (tbl->result_bit_size != tmplen) { - BNXT_TF_DBG(ERR, "Result len (%d) != Expected (%d)\n", - tmplen, tbl->result_bit_size); - rc = -EINVAL; - goto error; - } - sparms.result_sz_in_bits = tbl->result_bit_size; - - rc = tf_set_tcam_entry(tfp, &sparms); - if (rc) { - BNXT_TF_DBG(ERR, "tcam[%d][%s][%d] write failed.\n", - sparms.tcam_tbl_type, - (sparms.dir == TF_DIR_RX) ? "RX" : "TX", - sparms.idx); - goto error; - } - - /* Update cache with TCAM index if the was cache allocated. */ - if (parms->tcam_tbl_opc == - BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC) { - if (!parms->cache_ptr) { - BNXT_TF_DBG(ERR, "Unable to update cache"); - rc = -EINVAL; - goto error; - } - parms->cache_ptr->tcam_idx = idx; - } - - /* Mark action */ - rc = ulp_mapper_mark_act_ptr_process(parms, tbl); - if (rc) - goto error; - - } else { - struct bnxt_ulp_mapper_ident_info *idents; - uint32_t num_idents; - - /* - * Extract the listed identifiers from the result field, - * no need to allocate them. - */ - idents = ulp_mapper_ident_fields_get(tbl, &num_idents); - for (i = 0; i < num_idents; i++) { - rc = ulp_mapper_ident_extract(parms, tbl, - &idents[i], &data); - if (rc) { - BNXT_TF_DBG(ERR, - "Error in ident extraction\n"); - goto error; - } - } + /* if it is miss then it is same as no search before alloc */ + if (!hit) + search_flag = BNXT_ULP_SEARCH_BEFORE_ALLOC_NO; + else + search_flag = tbl->srch_b4_alloc; + + switch (search_flag) { + case BNXT_ULP_SEARCH_BEFORE_ALLOC_NO: + /*Scan identifier list, allocate identifier and update regfile*/ + rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl); + /* Create the result blob */ + if (!rc) + rc = ulp_mapper_tcam_tbl_result_create(parms, tbl, + &data); + /* write the tcam entry */ + if (!rc) + rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, &key, + &mask, &data, idx); + break; + case BNXT_ULP_SEARCH_BEFORE_ALLOC_SEARCH_IF_HIT_SKIP: + /*Scan identifier list, extract identifier and update regfile*/ + rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data); + break; + case BNXT_ULP_SEARCH_BEFORE_ALLOC_SEARCH_IF_HIT_UPDATE: + /*Scan identifier list, extract identifier and update regfile*/ + rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data); + /* Create the result blob */ + if (!rc) + rc = ulp_mapper_tcam_tbl_result_create(parms, tbl, + &update_data); + /* Update/overwrite the tcam entry */ + if (!rc) + rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, &key, + &mask, + &update_data, idx); + break; + default: + BNXT_TF_DBG(ERR, "invalid search opcode\n"); + rc = -EINVAL; + break; } + if (rc) + goto error; /* * Only link the entry to the flow db in the event that cache was not @@ -1598,11 +1693,11 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms, parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL; free_parms.dir = tbl->direction; free_parms.tcam_tbl_type = tbl->resource_type; - free_parms.idx = aparms.idx; + free_parms.idx = idx; trc = tf_free_tcam_entry(tfp, &free_parms); if (trc) BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n", - tbl->resource_type, tbl->direction, aparms.idx); + tbl->resource_type, tbl->direction, idx); return rc; } diff --git a/drivers/net/bnxt/tf_ulp/ulp_template_db_enum.h b/drivers/net/bnxt/tf_ulp/ulp_template_db_enum.h index ac651f6..9855918 100644 --- a/drivers/net/bnxt/tf_ulp/ulp_template_db_enum.h +++ b/drivers/net/bnxt/tf_ulp/ulp_template_db_enum.h @@ -271,8 +271,9 @@ enum bnxt_ulp_regfile_index { enum bnxt_ulp_search_before_alloc { BNXT_ULP_SEARCH_BEFORE_ALLOC_NO = 0, - BNXT_ULP_SEARCH_BEFORE_ALLOC_YES = 1, - BNXT_ULP_SEARCH_BEFORE_ALLOC_LAST = 2 + BNXT_ULP_SEARCH_BEFORE_ALLOC_SEARCH_IF_HIT_SKIP = 1, + BNXT_ULP_SEARCH_BEFORE_ALLOC_SEARCH_IF_HIT_UPDATE = 2, + BNXT_ULP_SEARCH_BEFORE_ALLOC_LAST = 3 }; enum bnxt_ulp_fdb_resource_flags { diff --git a/drivers/net/bnxt/tf_ulp/ulp_template_struct.h b/drivers/net/bnxt/tf_ulp/ulp_template_struct.h index b9a25b0..6617ab9 100644 --- a/drivers/net/bnxt/tf_ulp/ulp_template_struct.h +++ b/drivers/net/bnxt/tf_ulp/ulp_template_struct.h @@ -173,10 +173,10 @@ struct bnxt_ulp_mapper_tbl_info { enum bnxt_ulp_resource_sub_type resource_sub_type; enum bnxt_ulp_cond_opcode cond_opcode; uint32_t cond_operand; - uint8_t direction; - uint32_t priority; - uint8_t srch_b4_alloc; - enum bnxt_ulp_critical_resource critical_resource; + uint8_t direction; + uint32_t priority; + enum bnxt_ulp_search_before_alloc srch_b4_alloc; + enum bnxt_ulp_critical_resource critical_resource; /* Information for accessing the ulp_key_field_list */ uint32_t key_start_idx; -- 2.7.4