From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0DACD45A76; Tue, 1 Oct 2024 07:51:22 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F0CA140613; Tue, 1 Oct 2024 07:51:21 +0200 (CEST) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mails.dpdk.org (Postfix) with ESMTP id 2ED8B4029B for ; Tue, 1 Oct 2024 07:51:20 +0200 (CEST) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-7178df70f28so4014783b3a.2 for ; Mon, 30 Sep 2024 22:51:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1727761879; x=1728366679; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=59xhx9Df2aZlLcTZC5LRcX37/hGTC8A6TYeMdjGAAgo=; b=aIIpYHafrftv/nPDITVGxbf5dXii0VzisZZXvb55jqOYR+g+8mBqmSiW9nuxyaD5RU iD1Pd4pDj4wECTvzsR4meWrqpPkBYgsNolj1/AxFZXmFAz3peSOGRHJKKXlgIKp1QTv9 Fic2YGznyWqxgSrEe9TBsEBaXmYtHGjY5n7Mw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727761879; x=1728366679; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=59xhx9Df2aZlLcTZC5LRcX37/hGTC8A6TYeMdjGAAgo=; b=ikwBDz1dEwGziYNu3+nu/cbr6nqv8r1Z1NttYLi7vxttJa2/ZeSeb2YzLiWw8MTPFn Fo+1OX2nxsT/UMIf3WvmjVE8qW2J3vAlGetjF3eH5nW7o29TQ4FejM1OWGMY2B2nyExa /Ndpv6TvU81NmZd+I21+BDnH6zFtmzw2sQSBpoODFwl6Tvsj0nKPHCo4aIk5XEmOEKsA A5JTYwDXIIQ1i9yyCpW3d1zoHmXIFOjcuouARWbL2Fj0fzvhNdpS+HwhZ7KyEcqo2rMs jylFGvD/qawftR1EsJrIvdsjOS+5JgTzfLf0Qpcf7pHSOk3PHeV7MwNSHlDUlLBlnHLJ NMig== X-Gm-Message-State: AOJu0YwSl+VXNEXteh92RTK+HbFAdaiajNgTgT7x8Mzlsi06iYH2c0aA okz7GHXA1PSeCMxYglkJZS/8lT9uE3W7wvvD4/nGtoNlyuwBYFQl7TFqWwPK08GBz7GmPSL0lML n7zeSfW0t+WEgnwajenETXKMFJc0zmaMdmyc9Z4mjEcYpIsREYlsOzpw4c/BY2nm3JlXixljl2t 4T4+d+rhhz0DPBVLGIZgmE18KxlVQgEXjecCKA6Ie4xQ== X-Google-Smtp-Source: AGHT+IG64gjSrKMm73RuYeebnm3XuKLKWJVuIUL4NUoi2z61Qbj+B0zCi9Hlgb75txeZ2zONt3r1iA== X-Received: by 2002:a05:6a00:844:b0:717:85a4:c7a1 with SMTP id d2e1a72fcca58-71b2607eb68mr22384266b3a.27.1727761878618; Mon, 30 Sep 2024 22:51:18 -0700 (PDT) Received: from dhcp-10-123-154-23.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e6db2c8af2sm7513792a12.48.2024.09.30.22.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 22:51:18 -0700 (PDT) From: Sriharsha Basavapatna To: dev@dpdk.org Cc: Kishore Padmanabha , Sriharsha Basavapatna , Michael Baucom , Ajit Khaparde Subject: [PATCH v3 19/47] net/bnxt: tf_ulp: convert recipe table to dynamic memory Date: Tue, 1 Oct 2024 11:28:05 +0530 Message-Id: <20241001055833.757163-20-sriharsha.basavapatna@broadcom.com> X-Mailer: git-send-email 2.39.0.189.g4dbebc36b0 In-Reply-To: <20241001055833.757163-1-sriharsha.basavapatna@broadcom.com> References: <20241001055833.757163-1-sriharsha.basavapatna@broadcom.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Kishore Padmanabha Converted the recipe table allocation from static model to dynamic memory allocation model. Signed-off-by: Kishore Padmanabha Signed-off-by: Sriharsha Basavapatna Reviewed-by: Michael Baucom Reviewed-by: Ajit Khaparde --- drivers/net/bnxt/tf_ulp/ulp_mapper.c | 175 +++++++++++++++------------ drivers/net/bnxt/tf_ulp/ulp_mapper.h | 5 +- 2 files changed, 97 insertions(+), 83 deletions(-) diff --git a/drivers/net/bnxt/tf_ulp/ulp_mapper.c b/drivers/net/bnxt/tf_ulp/ulp_mapper.c index 7045efffad..a7b35bf292 100644 --- a/drivers/net/bnxt/tf_ulp/ulp_mapper.c +++ b/drivers/net/bnxt/tf_ulp/ulp_mapper.c @@ -1280,65 +1280,71 @@ ulp_mapper_field_opc_next(struct bnxt_ulp_mapper_parms *parms, static void ulp_mapper_key_recipe_tbl_deinit(struct bnxt_ulp_mapper_data *mdata) { + struct bnxt_ulp_key_recipe_entry **recipes; enum bnxt_ulp_direction dir; + uint32_t idx, ftype; + + /* If recipe table is not initialized then exit */ + if (!mdata->key_recipe_info.num_recipes) + return; for (dir = 0; dir < BNXT_ULP_DIRECTION_LAST; dir++) { - rte_free(mdata->key_recipe_info.em_recipes[dir]); - rte_free(mdata->key_recipe_info.wc_recipes[dir]); + for (ftype = 0; ftype < ULP_RECIPE_TYPE_MAX; ftype++) { + recipes = mdata->key_recipe_info.recipes[dir][ftype]; + for (idx = 0; idx < mdata->key_recipe_info.num_recipes; + idx++) { + if (recipes[idx]) + rte_free(recipes[idx]); + } + rte_free(mdata->key_recipe_info.recipes[dir][ftype]); + mdata->key_recipe_info.recipes[dir][ftype] = NULL; + } } + mdata->key_recipe_info.num_recipes = 0; } static int32_t ulp_mapper_key_recipe_tbl_init(struct bnxt_ulp_context *ulp_ctx, struct bnxt_ulp_mapper_data *mdata) { - struct bnxt_ulp_key_recipe_entry *recipes; + struct bnxt_ulp_key_recipe_entry **recipes; enum bnxt_ulp_direction dir; - uint32_t dev_id = 0; - uint32_t num_recipes; + uint32_t dev_id = 0, size_val; + uint32_t num_recipes, ftype; int32_t rc = 0; rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id); if (rc) { BNXT_DRV_DBG(ERR, "Unable to get device id from ulp.\n"); - return rc; + return -EINVAL; } num_recipes = bnxt_ulp_num_key_recipes_get(ulp_ctx); if (!num_recipes) - return 0; + return rc; + size_val = sizeof(struct bnxt_ulp_key_recipe_entry *); for (dir = 0; dir < BNXT_ULP_DIRECTION_LAST; dir++) { - recipes = rte_zmalloc("key_recipe_em", - sizeof(struct bnxt_ulp_key_recipe_entry) * - num_recipes, 0); - if (!recipes) - goto error; - mdata->key_recipe_info.em_recipes[dir] = recipes; - - recipes = rte_zmalloc("key_recipe_wc", - sizeof(struct bnxt_ulp_key_recipe_entry) * - num_recipes, 0); - if (!recipes) - goto error; - mdata->key_recipe_info.wc_recipes[dir] = recipes; + for (ftype = 0; ftype < ULP_RECIPE_TYPE_MAX; ftype++) { + recipes = rte_zmalloc("key_recipe_list", + size_val * num_recipes, 0); + if (!recipes) { + BNXT_DRV_DBG(ERR, "Uanable to alloc memory\n"); + return -ENOMEM; + } + mdata->key_recipe_info.recipes[dir][ftype] = recipes; + } } - mdata->key_recipe_info.num_recipes = num_recipes; mdata->key_recipe_info.max_fields = BNXT_ULP_KEY_RECIPE_MAX_FLDS; - - return 0; -error: - (void)ulp_mapper_key_recipe_tbl_deinit(mdata); - return -ENOMEM; + return rc; } -static struct bnxt_ulp_key_recipe_entry * -ulp_mapper_key_recipe_entry_get(struct bnxt_ulp_context *ulp_ctx, - enum bnxt_ulp_direction dir, - enum bnxt_ulp_resource_sub_type stype, - uint8_t recipe_id, uint8_t *max_fields) +static struct bnxt_ulp_mapper_data * +ulp_mapper_key_recipe_args_validate(struct bnxt_ulp_context *ulp_ctx, + enum bnxt_ulp_direction dir, + enum bnxt_ulp_resource_sub_type stype, + uint8_t recipe_id) { - struct bnxt_ulp_key_recipe_entry *recipes; struct bnxt_ulp_mapper_data *mdata; mdata = (struct bnxt_ulp_mapper_data *) @@ -1355,52 +1361,54 @@ ulp_mapper_key_recipe_entry_get(struct bnxt_ulp_context *ulp_ctx, BNXT_DRV_DBG(ERR, "Recipes are not supported\n"); return NULL; } - switch (stype) { - case BNXT_ULP_RESOURCE_SUB_TYPE_KEY_RECIPE_TABLE_WM: - recipes = mdata->key_recipe_info.wc_recipes[dir]; - break; - case BNXT_ULP_RESOURCE_SUB_TYPE_KEY_RECIPE_TABLE_EM: - recipes = mdata->key_recipe_info.em_recipes[dir]; - break; - default: - BNXT_DRV_DBG(ERR, "Invalid type (%d) for key recipe.\n", stype); + if (stype != BNXT_ULP_RESOURCE_SUB_TYPE_KEY_RECIPE_TABLE_WM && + stype != BNXT_ULP_RESOURCE_SUB_TYPE_KEY_RECIPE_TABLE_EM) { + BNXT_DRV_DBG(ERR, "Invalid type (%d) in key recipe\n", stype); return NULL; - }; - - if (recipe_id >= mdata->key_recipe_info.num_recipes) { - BNXT_DRV_DBG(ERR, "key recipe id out of range(%d >= %d)\n", + } + if (recipe_id >= mdata->key_recipe_info.num_recipes || + !mdata->key_recipe_info.num_recipes) { + BNXT_DRV_DBG(ERR, "Key recipe id out of range(%d >= %d)\n", recipe_id, mdata->key_recipe_info.num_recipes); return NULL; } - - if (max_fields) - *max_fields = mdata->key_recipe_info.max_fields; - return &recipes[recipe_id]; + return mdata; } -/* Not a strict alloc, it is allocating with the key id */ static struct bnxt_ulp_key_recipe_entry * ulp_mapper_key_recipe_alloc(struct bnxt_ulp_context *ulp_ctx, enum bnxt_ulp_direction dir, enum bnxt_ulp_resource_sub_type stype, uint8_t recipe_id, uint8_t *max_fields) { - struct bnxt_ulp_key_recipe_entry *recipe; + struct bnxt_ulp_key_recipe_entry **recipes; + struct bnxt_ulp_mapper_data *mdata = NULL; + uint32_t size_s = sizeof(struct bnxt_ulp_key_recipe_entry); - recipe = ulp_mapper_key_recipe_entry_get(ulp_ctx, dir, stype, - recipe_id, max_fields); - if (recipe) { - if (recipe->in_use) { - BNXT_DRV_INF("Recipe ID (%d) already allocated\n", - recipe_id); + mdata = ulp_mapper_key_recipe_args_validate(ulp_ctx, dir, + stype, recipe_id); + if (mdata == NULL) + return NULL; + + recipes = mdata->key_recipe_info.recipes[dir][stype]; + if (recipes[recipe_id] == NULL) { + recipes[recipe_id] = rte_zmalloc("key_recipe_entry", size_s, 0); + if (recipes[recipe_id] == NULL) { + BNXT_DRV_DBG(ERR, "Unable to alloc key recipe\n"); return NULL; } - recipe->in_use = true; - recipe->cnt = 0; +#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG +#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER + BNXT_DRV_INF("Alloc key recipe [%s]:[%s] = 0x%X\n", + (dir == BNXT_ULP_DIRECTION_INGRESS) ? "rx" : "tx", + ulp_mapper_key_recipe_type_to_str(stype), recipe_id); +#endif +#endif + *max_fields = mdata->key_recipe_info.max_fields; + return recipes[recipe_id]; } - - /* key will be null if it failed */ - return recipe; + BNXT_DRV_DBG(ERR, "Recipe ID (%d) already allocated\n", recipe_id); + return NULL; } /* The free just marks the entry as not in use and resets the number of entries @@ -1412,15 +1420,19 @@ ulp_mapper_key_recipe_free(struct bnxt_ulp_context *ulp_ctx, enum bnxt_ulp_resource_sub_type stype, uint32_t index) { - struct bnxt_ulp_key_recipe_entry *recipe; + struct bnxt_ulp_key_recipe_entry **recipes; + struct bnxt_ulp_mapper_data *mdata = NULL; - recipe = ulp_mapper_key_recipe_entry_get(ulp_ctx, dir, stype, - index, NULL); - if (recipe == NULL) + mdata = ulp_mapper_key_recipe_args_validate(ulp_ctx, dir, + stype, index); + if (mdata == NULL) return -EINVAL; - recipe->in_use = false; - recipe->cnt = 0; + recipes = mdata->key_recipe_info.recipes[dir][stype]; + if (recipes[index] == NULL) + return -EINVAL; + rte_free(recipes[index]); + recipes[index] = NULL; #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER BNXT_DRV_INF("Free key recipe [%s]:[%s] = 0x%X\n", @@ -1428,7 +1440,6 @@ ulp_mapper_key_recipe_free(struct bnxt_ulp_context *ulp_ctx, ulp_mapper_key_recipe_type_to_str(stype), index); #endif #endif - return 0; } @@ -1454,8 +1465,9 @@ ulp_mapper_key_recipe_fields_get(struct bnxt_ulp_mapper_parms *parms, struct bnxt_ulp_mapper_tbl_info *tbl, uint32_t *num_flds) { - struct bnxt_ulp_key_recipe_entry *recipe; + struct bnxt_ulp_key_recipe_entry **recipes; enum bnxt_ulp_resource_sub_type stype; + struct bnxt_ulp_mapper_data *mdata = NULL; uint64_t recipe_id = 0; /* Don't like this, but need to convert from a tbl resource func to the @@ -1475,22 +1487,25 @@ ulp_mapper_key_recipe_fields_get(struct bnxt_ulp_mapper_parms *parms, }; /* Get the recipe index from the registry file */ - if (!ulp_regfile_read(parms->regfile, - tbl->key_recipe_operand, + if (!ulp_regfile_read(parms->regfile, tbl->key_recipe_operand, &recipe_id)) { - BNXT_DRV_DBG(ERR, - "Failed to get tbl idx from regfile[%d].\n", + BNXT_DRV_DBG(ERR, "Failed to get tbl idx from regfile[%d].\n", tbl->tbl_operand); return NULL; } recipe_id = tfp_be_to_cpu_64(recipe_id); - recipe = ulp_mapper_key_recipe_entry_get(parms->ulp_ctx, tbl->direction, - stype, recipe_id, NULL); - if (recipe == NULL || !recipe->in_use) + mdata = ulp_mapper_key_recipe_args_validate(parms->ulp_ctx, + tbl->direction, + stype, recipe_id); + if (mdata == NULL) + return NULL; + + recipes = mdata->key_recipe_info.recipes[tbl->direction][stype]; + if (recipes[recipe_id] == NULL) return NULL; - *num_flds = recipe->cnt; - return &recipe->flds[0]; + *num_flds = recipes[recipe_id]->cnt; + return &recipes[recipe_id]->flds[0]; } static int32_t @@ -3552,7 +3567,7 @@ ulp_mapper_func_info_process(struct bnxt_ulp_mapper_parms *parms, } #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER - BNXT_DRV_DBG(DEBUG, "write the %" PRIu64 " into func_opc %u\n", res, + BNXT_DRV_DBG(DEBUG, "write the %" PRIX64 " into func_opc %u\n", res, func_info->func_dst_opr); #endif #endif diff --git a/drivers/net/bnxt/tf_ulp/ulp_mapper.h b/drivers/net/bnxt/tf_ulp/ulp_mapper.h index 9c7fb67891..53305670bf 100644 --- a/drivers/net/bnxt/tf_ulp/ulp_mapper.h +++ b/drivers/net/bnxt/tf_ulp/ulp_mapper.h @@ -31,16 +31,15 @@ struct bnxt_ulp_mapper_glb_resource_entry { #define BNXT_ULP_KEY_RECIPE_MAX_FLDS 128 struct bnxt_ulp_key_recipe_entry { - bool in_use; uint32_t cnt; struct bnxt_ulp_mapper_key_info flds[BNXT_ULP_KEY_RECIPE_MAX_FLDS]; }; +#define ULP_RECIPE_TYPE_MAX (BNXT_ULP_RESOURCE_SUB_TYPE_KEY_RECIPE_TABLE_WM + 1) struct bnxt_ulp_key_recipe_info { uint32_t num_recipes; uint8_t max_fields; - struct bnxt_ulp_key_recipe_entry *em_recipes[BNXT_ULP_DIRECTION_LAST]; - struct bnxt_ulp_key_recipe_entry *wc_recipes[BNXT_ULP_DIRECTION_LAST]; + struct bnxt_ulp_key_recipe_entry **recipes[BNXT_ULP_DIRECTION_LAST][ULP_RECIPE_TYPE_MAX]; }; struct ulp_mapper_core_ops; -- 2.39.3