From patchwork Fri Jun 12 13:29:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Somnath Kotur X-Patchwork-Id: 71413 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 A17B3A00BE; Fri, 12 Jun 2020 15:43:53 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F24221C0B6; Fri, 12 Jun 2020 15:34:36 +0200 (CEST) Received: from relay.smtp.broadcom.com (unknown [192.19.232.149]) by dpdk.org (Postfix) with ESMTP id 4A0B61C01E for ; Fri, 12 Jun 2020 15:34:33 +0200 (CEST) Received: from dhcp-10-123-153-55.dhcp.broadcom.net (dhcp-10-123-153-55.dhcp.broadcom.net [10.123.153.55]) by relay.smtp.broadcom.com (Postfix) with ESMTP id 208A11BD788; Fri, 12 Jun 2020 06:34:31 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 relay.smtp.broadcom.com 208A11BD788 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1591968872; bh=v4Ln8MWXQkBBn55zpouc3PlbyPjWZiasChxvvanpKYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZQsbC6Feqyc/+IdmCKFVB5Gu1D5aB4qDrtSV4Pd7vFiTdY9H0jysFAP58A6W4PI8c AixnD5oVcACQ1pq1LEkp10bGYBIwjrVHW7GltR3x2Ojsjs1bzdIGeAHfH24k518G+A rLZ4hZklEo+PHszu9qzJmiUa7rDfa0Jmgtdrk1gE= From: Somnath Kotur To: dev@dpdk.org Cc: ferruh.yigit@intel.com Date: Fri, 12 Jun 2020 18:59:05 +0530 Message-Id: <20200612132934.16488-22-somnath.kotur@broadcom.com> X-Mailer: git-send-email 2.10.1.613.g2cc2e70 In-Reply-To: <20200612132934.16488-1-somnath.kotur@broadcom.com> References: <20200612132934.16488-1-somnath.kotur@broadcom.com> Subject: [dpdk-dev] [PATCH 21/50] net/bnxt: support two level priority for TCAMs 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: Jay Ding Allow TCAM indexes to be allocated from top or bottom. If the priority is set to 0, allocate from the lowest tcam indexes i.e. from top. Any other value, allocate it from the highest tcam indexes i.e. from bottom. Signed-off-by: Jay Ding Reviewed-by: Randy Schacher Signed-off-by: Venkat Duvvuru --- drivers/net/bnxt/tf_core/bitalloc.c | 107 +++++++++++++++++++++++++++++++++++ drivers/net/bnxt/tf_core/bitalloc.h | 5 ++ drivers/net/bnxt/tf_core/tf_rm_new.c | 9 ++- drivers/net/bnxt/tf_core/tf_rm_new.h | 8 +++ drivers/net/bnxt/tf_core/tf_tcam.c | 1 + 5 files changed, 129 insertions(+), 1 deletion(-) diff --git a/drivers/net/bnxt/tf_core/bitalloc.c b/drivers/net/bnxt/tf_core/bitalloc.c index fb4df9a..918cabf 100644 --- a/drivers/net/bnxt/tf_core/bitalloc.c +++ b/drivers/net/bnxt/tf_core/bitalloc.c @@ -7,6 +7,40 @@ #define BITALLOC_MAX_LEVELS 6 + +/* Finds the last bit set plus 1, equivalent to gcc __builtin_fls */ +static int +ba_fls(bitalloc_word_t v) +{ + int c = 32; + + if (!v) + return 0; + + if (!(v & 0xFFFF0000u)) { + v <<= 16; + c -= 16; + } + if (!(v & 0xFF000000u)) { + v <<= 8; + c -= 8; + } + if (!(v & 0xF0000000u)) { + v <<= 4; + c -= 4; + } + if (!(v & 0xC0000000u)) { + v <<= 2; + c -= 2; + } + if (!(v & 0x80000000u)) { + v <<= 1; + c -= 1; + } + + return c; +} + /* Finds the first bit set plus 1, equivalent to gcc __builtin_ffs */ static int ba_ffs(bitalloc_word_t v) @@ -120,6 +154,79 @@ ba_alloc(struct bitalloc *pool) return ba_alloc_helper(pool, 0, 1, 32, 0, &clear); } +/** + * Help function to alloc entry from highest available index + * + * Searching the pool from highest index for the empty entry. + * + * [in] pool + * Pointer to the resource pool + * + * [in] offset + * Offset of the storage in the pool + * + * [in] words + * Number of words in this level + * + * [in] size + * Number of entries in this level + * + * [in] index + * Index of words that has the entry + * + * [in] clear + * Indicate if a bit needs to be clear due to the entry is allocated + * + * Returns: + * 0 - Success + * -1 - Failure + */ +static int +ba_alloc_reverse_helper(struct bitalloc *pool, + int offset, + int words, + unsigned int size, + int index, + int *clear) +{ + bitalloc_word_t *storage = &pool->storage[offset]; + int loc = ba_fls(storage[index]); + int r; + + if (loc == 0) + return -1; + + loc--; + + if (pool->size > size) { + r = ba_alloc_reverse_helper(pool, + offset + words + 1, + storage[words], + size * 32, + index * 32 + loc, + clear); + } else { + r = index * 32 + loc; + *clear = 1; + pool->free_count--; + } + + if (*clear) { + storage[index] &= ~(1 << loc); + *clear = (storage[index] == 0); + } + + return r; +} + +int +ba_alloc_reverse(struct bitalloc *pool) +{ + int clear = 0; + + return ba_alloc_reverse_helper(pool, 0, 1, 32, 0, &clear); +} + static int ba_alloc_index_helper(struct bitalloc *pool, int offset, diff --git a/drivers/net/bnxt/tf_core/bitalloc.h b/drivers/net/bnxt/tf_core/bitalloc.h index 563c853..2825bb3 100644 --- a/drivers/net/bnxt/tf_core/bitalloc.h +++ b/drivers/net/bnxt/tf_core/bitalloc.h @@ -73,6 +73,11 @@ int ba_alloc(struct bitalloc *pool); int ba_alloc_index(struct bitalloc *pool, int index); /** + * Returns -1 on failure, or index of allocated entry + */ +int ba_alloc_reverse(struct bitalloc *pool); + +/** * Query a particular index in a pool to check if its in use. * * Returns -1 on invalid index, 1 if the index is allocated, 0 if it diff --git a/drivers/net/bnxt/tf_core/tf_rm_new.c b/drivers/net/bnxt/tf_core/tf_rm_new.c index 02b4b5c..de8f119 100644 --- a/drivers/net/bnxt/tf_core/tf_rm_new.c +++ b/drivers/net/bnxt/tf_core/tf_rm_new.c @@ -671,7 +671,14 @@ tf_rm_allocate(struct tf_rm_allocate_parms *parms) return rc; } - id = ba_alloc(rm_db->db[parms->db_index].pool); + /* + * priority 0: allocate from top of the tcam i.e. high + * priority !0: allocate index from bottom i.e lowest + */ + if (parms->priority) + id = ba_alloc_reverse(rm_db->db[parms->db_index].pool); + else + id = ba_alloc(rm_db->db[parms->db_index].pool); if (id == BA_FAIL) { rc = -ENOMEM; TFP_DRV_LOG(ERR, diff --git a/drivers/net/bnxt/tf_core/tf_rm_new.h b/drivers/net/bnxt/tf_core/tf_rm_new.h index a40296e..5cb6889 100644 --- a/drivers/net/bnxt/tf_core/tf_rm_new.h +++ b/drivers/net/bnxt/tf_core/tf_rm_new.h @@ -185,6 +185,14 @@ struct tf_rm_allocate_parms { * i.e. Full Action Record offsets. */ uint32_t *index; + /** + * [in] Priority, indicates the prority of the entry + * priority 0: allocate from top of the tcam (from index 0 + * or lowest available index) + * priority !0: allocate from bottom of the tcam (from highest + * available index) + */ + uint32_t priority; }; /** diff --git a/drivers/net/bnxt/tf_core/tf_tcam.c b/drivers/net/bnxt/tf_core/tf_tcam.c index 2f4441d..260fb15 100644 --- a/drivers/net/bnxt/tf_core/tf_tcam.c +++ b/drivers/net/bnxt/tf_core/tf_tcam.c @@ -157,6 +157,7 @@ tf_tcam_alloc(struct tf *tfp, /* Allocate requested element */ aparms.rm_db = tcam_db[parms->dir]; aparms.db_index = parms->type; + aparms.priority = parms->priority; aparms.index = (uint32_t *)&parms->idx; rc = tf_rm_allocate(&aparms); if (rc) {