From patchwork Sun Jun 13 00:06:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajit Khaparde X-Patchwork-Id: 94118 X-Patchwork-Delegate: ajit.khaparde@broadcom.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E2206A0C41; Sun, 13 Jun 2021 02:10:39 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 927BB411CB; Sun, 13 Jun 2021 02:07:35 +0200 (CEST) Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by mails.dpdk.org (Postfix) with ESMTP id 61C09411BA for ; Sun, 13 Jun 2021 02:07:30 +0200 (CEST) Received: by mail-pj1-f49.google.com with SMTP id fy24-20020a17090b0218b029016c5a59021fso7966148pjb.0 for ; Sat, 12 Jun 2021 17:07:30 -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; bh=aANXTyRpe1oBY7CA1byhrwLaoLzGDl34wlN4DX5MNio=; b=YicP2Uhl+L46p7vPH4HvKE/bSFyCQjKGja/J8aZYbUAyhErcARKihPlqtKhvBTYknt udkJGob7MS8W+vVX97dF966Yod//uk8TT5VUGDKh7sXw6vVT4cGtZgn/dv2xfMiokBXK 7SNAyfxVIsWnI3JA84iczWgWQJaz2nxc4NZA8= 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; bh=aANXTyRpe1oBY7CA1byhrwLaoLzGDl34wlN4DX5MNio=; b=GTZjLuPjgO1QL+nOIlrJrTjgf/KQTEKFL9R3DgKW/fF9P3spdI0hjnZZgbQr+8DPbl XwYHLCLQRF2NpQswVJZKey20IKkBYd4s1O/zthqyBNjJpdGOhOxNo6eMyYjonlWKOI8j hOyySsuh0VhjpQhKWh1jD4UgQzRGfSOPq0QOnJ4Nax8aaiXRmXl81P6rGGdBCEXb3Mwb j10+dzML0Lnif8LSvCWgOkDvgQQgKqAdEqlU7pda6IH/3K7OXSH7xYtu3fZoP03xXivr Df+Pv15+4jN3yF7nCtMeGbWoUEBEgBCM5Quz/QEfed4YkFlw9KGkXVtrlqYSZftxI9vK qCmQ== X-Gm-Message-State: AOAM5319mAgLawWh5n+o/eoLBJQc+wJsWhVNI96gbk6GHlwSZp2ELOIj N1dn68+Iz+tZ4TwIOWmof8THzGip09bV8i2P1iqy3LcfoRlrActbILCrBx4Z9eQUh/uf3auzXBe C2FBMikdhwnGZOxz0KT1v5IOKo/vgRf2n/5AQkgtB9dcH7MmCZj/YhsCgDe9UP5s= X-Google-Smtp-Source: ABdhPJzXjMro4WvRU36n7xJS2i+nyYeZqvkV6e+/BEto1pqXP+3/s21OFOn/D7IRg96ouAptDYtG2w== X-Received: by 2002:a17:90a:694d:: with SMTP id j13mr11558636pjm.99.1623542848962; Sat, 12 Jun 2021 17:07:28 -0700 (PDT) Received: from localhost.localdomain ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id gg22sm12774609pjb.17.2021.06.12.17.07.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Jun 2021 17:07:28 -0700 (PDT) From: Ajit Khaparde To: dev@dpdk.org Cc: Farah Smith , Venkat Duvvuru , Randy Schacher Date: Sat, 12 Jun 2021 17:06:17 -0700 Message-Id: <20210613000652.28191-24-ajit.khaparde@broadcom.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20210613000652.28191-1-ajit.khaparde@broadcom.com> References: <20210530085929.29695-1-venkatkumar.duvvuru@broadcom.com> <20210613000652.28191-1-ajit.khaparde@broadcom.com> MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [dpdk-dev] [PATCH v2 23/58] net/bnxt: cleanup WC TCAM shared pool 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 Sender: "dev" From: Farah Smith Clean up all allocated hi or lo pool TCAM regions on close. Along with message cleanup and remove unnecessary multi-slice options Also make sure that find next free entry should start from 0 first time. Signed-off-by: Farah Smith Signed-off-by: Venkat Duvvuru Reviewed-by: Randy Schacher Reviewed-by: Ajit Khaparde --- drivers/net/bnxt/tf_core/tf_tcam_shared.c | 333 ++++++++++++---------- 1 file changed, 179 insertions(+), 154 deletions(-) diff --git a/drivers/net/bnxt/tf_core/tf_tcam_shared.c b/drivers/net/bnxt/tf_core/tf_tcam_shared.c index 5139b28537..b96d9ca9dd 100644 --- a/drivers/net/bnxt/tf_core/tf_tcam_shared.c +++ b/drivers/net/bnxt/tf_core/tf_tcam_shared.c @@ -19,8 +19,6 @@ #include "tf_core.h" #include "tf_rm.h" -struct tf; - /** Shared WC TCAM pool identifiers */ enum tf_tcam_shared_wc_pool_id { @@ -288,6 +286,12 @@ tf_tcam_shared_bind(struct tf *tfp, if (rc) return rc; + if (num_slices > 1) { + TFP_DRV_LOG(ERR, + "Only single slice supported\n"); + return -EOPNOTSUPP; + } + tf_tcam_shared_create_db(&tcam_shared_wc); @@ -338,49 +342,135 @@ int tf_tcam_shared_unbind(struct tf *tfp) { int rc, dir; + struct tf_dev_info *dev; struct tf_session *tfs; void *tcam_shared_db_ptr = NULL; struct tf_tcam_shared_wc_pools *tcam_shared_wc; + enum tf_tcam_shared_wc_pool_id pool_id; + struct tf_tcam_free_parms parms; + struct bitalloc *pool; + uint16_t start; + int log_idx, phy_idx; + uint16_t hcapi_type; + struct tf_rm_alloc_info info; + int i, pool_cnt; TF_CHECK_PARMS1(tfp); - /* Perform normal unbind, this will write all the - * allocated TCAM entries in the shared session. - */ - rc = tf_tcam_unbind(tfp); - if (rc) - return rc; - /* Retrieve the session information */ rc = tf_session_get_session_internal(tfp, &tfs); if (rc) return rc; - rc = tf_session_get_tcam_shared_db(tfp, (void *)&tcam_shared_db_ptr); + /* If not the shared session, call the normal + * tcam unbind and exit + */ + if (!tf_session_is_shared_session(tfs)) { + rc = tf_tcam_unbind(tfp); + return rc; + } + + /* We must be a shared session, get the database + */ + rc = tf_session_get_tcam_shared_db(tfp, + (void *)&tcam_shared_db_ptr); if (rc) { TFP_DRV_LOG(ERR, - "Failed to get tcam_shared_db from session, rc:%s\n", + "Failed to get tcam_shared_db, rc:%s\n", strerror(-rc)); return rc; } - tcam_shared_wc = (struct tf_tcam_shared_wc_pools *)tcam_shared_db_ptr; - /* If we are the shared session + tcam_shared_wc = + (struct tf_tcam_shared_wc_pools *)tcam_shared_db_ptr; + + + /* Get the device */ - if (tf_session_is_shared_session(tfs)) { - /* If there are WC TCAM entries allocated, free them + rc = tf_session_get_device(tfs, &dev); + if (rc) + return rc; + + + /* If there are WC TCAM entries allocated, free them + */ + for (dir = 0; dir < TF_DIR_MAX; dir++) { + /* If the database is invalid, skip */ - for (dir = 0; dir < TF_DIR_MAX; dir++) { - tf_tcam_shared_free_wc_pool(dir, - TF_TCAM_SHARED_WC_POOL_HI, - tcam_shared_wc); + if (!tf_tcam_db_valid(tfp, dir)) + continue; + + rc = tf_tcam_shared_get_rm_info(tfp, + dir, + &hcapi_type, + &info); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: TCAM shared rm info get failed\n", + tf_dir_2_str(dir)); + return rc; + } + + for (pool_id = TF_TCAM_SHARED_WC_POOL_HI; + pool_id < TF_TCAM_SHARED_WC_POOL_MAX; + pool_id++) { + pool = tcam_shared_wc->db[dir][pool_id].pool; + start = tcam_shared_wc->db[dir][pool_id].info.start; + pool_cnt = ba_inuse_count(pool); + + if (pool_cnt) { + TFP_DRV_LOG(INFO, + "%s: %s: %d residuals found, freeing\n", + tf_dir_2_str(dir), + tf_pool_2_str(pool_id), + pool_cnt); + } + + log_idx = 0; + + for (i = 0; i < pool_cnt; i++) { + log_idx = ba_find_next_inuse(pool, log_idx); + + if (log_idx < 0) { + TFP_DRV_LOG(ERR, + "Expected a found %s entry %d\n", + tf_pool_2_str(pool_id), + i); + /* attempt normal unbind + */ + goto done; + } + phy_idx = start + log_idx; + + parms.type = TF_TCAM_TBL_TYPE_WC_TCAM; + parms.hcapi_type = hcapi_type; + parms.idx = phy_idx; + parms.dir = dir; + rc = tf_msg_tcam_entry_free(tfp, dev, &parms); + if (rc) { + /* Log error */ + TFP_DRV_LOG(ERR, + "%s: %s: %d free failed, rc:%s\n", + tf_dir_2_str(parms.dir), + tf_tcam_tbl_2_str(parms.type), + phy_idx, + strerror(-rc)); + return rc; + } + } + /* Free the pool once all the entries + * have been cleared + */ tf_tcam_shared_free_wc_pool(dir, - TF_TCAM_SHARED_WC_POOL_LO, + pool_id, tcam_shared_wc); } } - return 0; +done: + rc = tf_tcam_unbind(tfp); + return rc; } + /** * tf_tcam_shared_alloc */ @@ -388,13 +478,12 @@ int tf_tcam_shared_alloc(struct tf *tfp, struct tf_tcam_alloc_parms *parms) { - int rc, i; + int rc; struct tf_session *tfs; struct tf_dev_info *dev; int log_idx; struct bitalloc *pool; enum tf_tcam_shared_wc_pool_id id; - uint16_t num_slices; struct tf_tcam_shared_wc_pools *tcam_shared_wc; void *tcam_shared_db_ptr = NULL; @@ -444,32 +533,24 @@ tf_tcam_shared_alloc(struct tf *tfp, if (rc) return rc; - rc = tf_tcam_shared_get_slices(tfp, dev, &num_slices); - if (rc) - return rc; - pool = tcam_shared_wc->db[parms->dir][id].pool; - for (i = 0; i < num_slices; i++) { - /* - * priority 0: allocate from top of the tcam i.e. high - * priority !0: allocate index from bottom i.e lowest - */ - if (parms->priority) - log_idx = ba_alloc_reverse(pool); - else - log_idx = ba_alloc(pool); - if (log_idx == BA_FAIL) { - TFP_DRV_LOG(ERR, - "%s: Allocation failed, rc:%s\n", - tf_dir_2_str(parms->dir), - strerror(ENOMEM)); - return -ENOMEM; - } - /* return the index without the start of each row */ - if (i == 0) - parms->idx = log_idx; + /* + * priority 0: allocate from top of the tcam i.e. high + * priority !0: allocate index from bottom i.e lowest + */ + if (parms->priority) + log_idx = ba_alloc_reverse(pool); + else + log_idx = ba_alloc(pool); + if (log_idx == BA_FAIL) { + TFP_DRV_LOG(ERR, + "%s: Allocation failed, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(ENOMEM)); + return -ENOMEM; } + parms->idx = log_idx; return 0; } @@ -481,13 +562,11 @@ tf_tcam_shared_free(struct tf *tfp, struct tf_session *tfs; struct tf_dev_info *dev; int allocated = 0; - int i; uint16_t start; int phy_idx; struct bitalloc *pool; enum tf_tcam_shared_wc_pool_id id; struct tf_tcam_free_parms nparms; - uint16_t num_slices; uint16_t hcapi_type; struct tf_rm_alloc_info info; void *tcam_shared_db_ptr = NULL; @@ -540,10 +619,6 @@ tf_tcam_shared_free(struct tf *tfp, if (rc) return rc; - rc = tf_tcam_shared_get_slices(tfp, dev, &num_slices); - if (rc) - return rc; - rc = tf_tcam_shared_get_rm_info(tfp, parms->dir, &hcapi_type, @@ -558,13 +633,6 @@ tf_tcam_shared_free(struct tf *tfp, pool = tcam_shared_wc->db[parms->dir][id].pool; start = tcam_shared_wc->db[parms->dir][id].info.start; - if (parms->idx % num_slices) { - TFP_DRV_LOG(ERR, - "%s: TCAM reserved resource is not multiple of %d\n", - tf_dir_2_str(parms->dir), num_slices); - return -EINVAL; - } - phy_idx = parms->idx + start; allocated = ba_inuse(pool, parms->idx); @@ -575,16 +643,14 @@ tf_tcam_shared_free(struct tf *tfp, return -EINVAL; } - for (i = 0; i < num_slices; i++) { - rc = ba_free(pool, parms->idx + i); - if (rc) { - TFP_DRV_LOG(ERR, - "%s: Free failed, type:%s, idx:%d\n", - tf_dir_2_str(parms->dir), - tf_tcam_tbl_2_str(parms->type), - parms->idx); - return rc; - } + rc = ba_free(pool, parms->idx); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Free failed, type:%s, idx:%d\n", + tf_dir_2_str(parms->dir), + tf_tcam_tbl_2_str(parms->type), + parms->idx); + return rc; } /* Override HI/LO type with parent WC TCAM type */ @@ -616,7 +682,6 @@ tf_tcam_shared_set(struct tf *tfp __rte_unused, struct tf_dev_info *dev; int allocated = 0; int phy_idx, log_idx; - uint16_t num_slices; struct tf_tcam_set_parms nparms; struct bitalloc *pool; uint16_t start; @@ -685,16 +750,7 @@ tf_tcam_shared_set(struct tf *tfp __rte_unused, tf_dir_2_str(parms->dir), parms->type, log_idx); return -EINVAL; } - rc = tf_tcam_shared_get_slices(tfp, dev, &num_slices); - if (rc) - return rc; - if (parms->idx % num_slices) { - TFP_DRV_LOG(ERR, - "%s: TCAM reserved resource is not multiple of %d\n", - tf_dir_2_str(parms->dir), num_slices); - return -EINVAL; - } rc = tf_tcam_shared_get_rm_info(tfp, parms->dir, &hcapi_type, @@ -736,7 +792,6 @@ tf_tcam_shared_get(struct tf *tfp __rte_unused, struct tf_dev_info *dev; int allocated = 0; int phy_idx, log_idx; - uint16_t num_slices; struct tf_tcam_get_parms nparms; struct bitalloc *pool; uint16_t start; @@ -794,16 +849,6 @@ tf_tcam_shared_get(struct tf *tfp __rte_unused, pool = tcam_shared_wc->db[parms->dir][id].pool; start = tcam_shared_wc->db[parms->dir][id].info.start; - rc = tf_tcam_shared_get_slices(tfp, dev, &num_slices); - if (rc) - return rc; - - if (parms->idx % num_slices) { - TFP_DRV_LOG(ERR, - "%s: TCAM reserved resource is not multiple of %d\n", - tf_dir_2_str(parms->dir), num_slices); - return -EINVAL; - } log_idx = parms->idx; phy_idx = parms->idx + start; allocated = ba_inuse(pool, parms->idx); @@ -881,7 +926,6 @@ tf_tcam_shared_move_entry(struct tf *tfp, int dphy_idx, int key_sz_bytes, int remap_sz_bytes, - uint16_t num_slices, bool set_enable_bit) { int rc = 0; @@ -897,12 +941,6 @@ tf_tcam_shared_move_entry(struct tf *tfp, memset(&tcam_remap_obj, 0, sizeof(tcam_remap_obj)); memset(&gparms, 0, sizeof(gparms)); - if (num_slices > 1) { - TFP_DRV_LOG(ERR, - "Only single slice supported"); - return -EOPNOTSUPP; - } - gparms.hcapi_type = hcapi_type; gparms.dir = dir; gparms.type = TF_TCAM_TBL_TYPE_WC_TCAM; @@ -917,7 +955,8 @@ tf_tcam_shared_move_entry(struct tf *tfp, if (rc) { /* Log error */ TFP_DRV_LOG(ERR, - "%s: WC_TCAM_HIGH: phyid(%d) get failed, rc:%s", + "%s: %s: phyid(%d) get failed, rc:%s\n", + tf_tcam_tbl_2_str(gparms.type), tf_dir_2_str(dir), gparms.idx, strerror(-rc)); @@ -942,7 +981,8 @@ tf_tcam_shared_move_entry(struct tf *tfp, if (rc) { /* Log error */ TFP_DRV_LOG(ERR, - "%s: WC_TCAM_LOW phyid(%d/0x%x) set failed, rc:%s", + "%s: %s phyid(%d/0x%x) set failed, rc:%s\n", + tf_tcam_tbl_2_str(sparms.type), tf_dir_2_str(dir), sparms.idx, sparms.idx, @@ -985,13 +1025,12 @@ int tf_tcam_shared_move(struct tf *tfp, struct tf_session *tfs; struct tf_dev_info *dev; int log_idx; - uint16_t num_slices; struct bitalloc *hi_pool, *lo_pool; uint16_t hi_start, lo_start; enum tf_tcam_shared_wc_pool_id hi_id, lo_id; uint16_t hcapi_type; struct tf_rm_alloc_info info; - int hi_cnt, i, j; + int hi_cnt, i; struct tf_tcam_shared_wc_pools *tcam_shared_wc; void *tcam_shared_db_ptr = NULL; @@ -1027,9 +1066,6 @@ int tf_tcam_shared_move(struct tf *tfp, /* TODO print amazing error */ return rc; } - rc = tf_tcam_shared_get_slices(tfp, dev, &num_slices); - if (rc) - return rc; rc = tf_tcam_shared_get_rm_info(tfp, parms->dir, @@ -1068,62 +1104,51 @@ int tf_tcam_shared_move(struct tf *tfp, /* Copy each valid entry to the same low pool logical offset */ + log_idx = 0; + for (i = 0; i < hi_cnt; i++) { - /* Go through all the slices + /* Find next free index starting from where we left off */ - for (j = 0; j < num_slices; j++) { - /* Find next free starting from where we left off - */ - log_idx = ba_find_next_inuse(hi_pool, i); + log_idx = ba_find_next_inuse(hi_pool, log_idx); + if (log_idx < 0) { + TFP_DRV_LOG(ERR, + "Expected a found %s entry %d\n", + tf_pool_2_str(hi_id), + i); + goto done; + } + /* The user should have never allocated from the low + * pool because the move only happens when switching + * from the high to the low pool + */ + if (ba_alloc_index(lo_pool, log_idx) < 0) { + TFP_DRV_LOG(ERR, + "Warning %s index %d already allocated\n", + tf_pool_2_str(lo_id), + i); - if (log_idx < 0) { - TFP_DRV_LOG(ERR, - "Expected a found %s entry %d\n", - tf_pool_2_str(hi_id), - i); - goto done; - } - /* The user should have never allocated from the low - * pool because the move only happens when switching - * from the high to the low pool + /* Since already allocated, continue with move */ - if (ba_alloc_index(lo_pool, log_idx) < 0) { - TFP_DRV_LOG(ERR, - "Cannot allocate %s index %d\n", - tf_pool_2_str(lo_id), - i); - goto done; - } + } - if (j == 0) { - rc = tf_tcam_shared_move_entry(tfp, dev, - hcapi_type, - parms->dir, - hi_start + log_idx, - lo_start + log_idx, - key_sz_bytes, - remap_sz_bytes, - num_slices, - set_enable_bit); - if (rc) { - TFP_DRV_LOG(ERR, - "Cannot allocate %s index %d\n", - tf_pool_2_str(hi_id), - i); - goto done; - } - ba_free(hi_pool, log_idx); - TFP_DRV_LOG(DEBUG, - "%s: TCAM shared move pool(%s) phyid(%d)\n", - tf_dir_2_str(parms->dir), - tf_pool_2_str(hi_id), - hi_start + log_idx); - TFP_DRV_LOG(DEBUG, - "to pool(%s) phyid(%d)\n", - tf_pool_2_str(lo_id), - lo_start + log_idx); - } + rc = tf_tcam_shared_move_entry(tfp, dev, + hcapi_type, + parms->dir, + hi_start + log_idx, + lo_start + log_idx, + key_sz_bytes, + remap_sz_bytes, + set_enable_bit); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Move error %s to %s index %d\n", + tf_dir_2_str(parms->dir), + tf_pool_2_str(hi_id), + tf_pool_2_str(lo_id), + i); + goto done; } + ba_free(hi_pool, log_idx); } done: return rc;