From patchwork Tue Jul 28 06:34:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajit Khaparde X-Patchwork-Id: 74916 X-Patchwork-Delegate: ajit.khaparde@broadcom.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id F1A7EA0521; Tue, 28 Jul 2020 08:38:26 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6890D1C1CC; Tue, 28 Jul 2020 08:35:48 +0200 (CEST) Received: from mail-wm1-f98.google.com (mail-wm1-f98.google.com [209.85.128.98]) by dpdk.org (Postfix) with ESMTP id 599C71C128 for ; Tue, 28 Jul 2020 08:35:25 +0200 (CEST) Received: by mail-wm1-f98.google.com with SMTP id k8so6663835wma.2 for ; Mon, 27 Jul 2020 23:35:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fMVYaHnCIsjqHHAznENKaRSkgBC2pAWr0oklrowWeAI=; b=ZTopA/Gc6KdQlYq85NHbhKvXK8drfGnkiDI+rX1l/qLlnY3KU5an/lxZTkpGXC0OT/ Q9dN1nDSIwd7bucczAs+Ze1NqlJQlySYfr0evxYFwmNwgkpsHPw5IlEhf4bjTnhUpNAG hU3Gmds8DrNcCTTocZvCBNGeEvmzybUATGcSA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fMVYaHnCIsjqHHAznENKaRSkgBC2pAWr0oklrowWeAI=; b=it6L6qiEtaEuAzHEWlwyU4tx0aBXtoOUtDvBIN3KMVbzJ4/4zT8r3YmbvrC6ub1YOD mwsjX8eISx2Sfp8Yex5vYElBJe2JTez+/0XDMaVFCHvUwqqIT/IdiMd1X0smVD1z/M3n XZCjEi7Y5jKuOCGgps7UN75CuIFppZa9KuSp9HMbRA+45jKU1ZutBZWEAZLFDkfmVHDK AzUq0/TB9lVEoEFM4x98FRcqGPJmzt8FT/K0NQRYaOnFEov5/1Y+gd8H79EH5Hv1KvQX 4PrEreV8UmzqaykphqczLUpwnCFTtAsllbdZsBMuaihqhrTyOA0aea4NDqTcsn02HrS4 R48A== X-Gm-Message-State: AOAM532BSMzqcUIWyqE3zztXV5DnijpOiJ1M0GRLWxdbvce/6OV8H/Go bJrnYB16vQCtN9IoutL3diqOtlv/O2mlTZlronCzOrFwNTZ4U/1HGoHw4KG+hrimgPm0pOO3TbU Lc5L2RiRUlmjk2IDLVfJB0F2A9PZXn+kuTk+OMcukSM9j68qSZFwijy1Dsn78MN+FlazGj/gRpa sFKg== X-Google-Smtp-Source: ABdhPJyJi6gbESJ/ED2oMdvc7Lx+V2SC7USeWASFYSCFaOQjv5vti72FOOHJ00UcCoRg59nr4FU63bSLnqmM X-Received: by 2002:a1c:a757:: with SMTP id q84mr2414689wme.1.1595918124836; Mon, 27 Jul 2020 23:35:24 -0700 (PDT) Received: from localhost.localdomain ([192.19.223.252]) by smtp-relay.gmail.com with ESMTPS id r16sm30828wmh.29.2020.07.27.23.35.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Jul 2020 23:35:24 -0700 (PDT) X-Relaying-Domain: broadcom.com From: Ajit Khaparde To: dev@dpdk.org Cc: ferruh.yigit@intel.com, Kishore Padmanabha , Michael Baucom Date: Mon, 27 Jul 2020 23:34:34 -0700 Message-Id: <20200728063439.23114-18-ajit.khaparde@broadcom.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200728063439.23114-1-ajit.khaparde@broadcom.com> References: <20200728063439.23114-1-ajit.khaparde@broadcom.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v4 17/22] net/bnxt: add tcam table processing 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 ++++++++++++------ .../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 4dee65971..6ac4b0f83 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 ac651f63f..985591844 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 b9a25b064..6617ab9d4 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;