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 DF316A0519; Fri, 3 Jul 2020 01:32:33 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5A4CD1DA4E; Fri, 3 Jul 2020 01:29:19 +0200 (CEST) Received: from rnd-relay.smtp.broadcom.com (rnd-relay.smtp.broadcom.com [192.19.229.170]) by dpdk.org (Postfix) with ESMTP id 8FB731D681 for ; Fri, 3 Jul 2020 01:28:48 +0200 (CEST) Received: from mail-irv-17.broadcom.com (mail-irv-17.lvn.broadcom.net [10.75.242.48]) by rnd-relay.smtp.broadcom.com (Postfix) with ESMTP id 7011230C1AD; Thu, 2 Jul 2020 16:28:47 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 rnd-relay.smtp.broadcom.com 7011230C1AD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1593732527; bh=jliSqYY5DZHKT/FF6yUx2K9W+5ZL3swfO0Me3i9BE1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YuSY4VkmeCkDbuRgUVY7DR63rpS0uQ4PwQHZrna8ReA1+yOcWhAOmfv8L6TeZ2Cqg rBXacgfT134uKTo1+BratqLncsh+7GRf05FAnIrDXjWUR1i38r39X7ajprbS4hlJgm /ClRriGU7Yi7IRkHCCBcpbJCip51XWMojPbI3Dcc= Received: from localhost.localdomain (unknown [10.230.185.215]) by mail-irv-17.broadcom.com (Postfix) with ESMTP id 493B614008B; Thu, 2 Jul 2020 16:28:47 -0700 (PDT) From: Ajit Khaparde To: dev@dpdk.org Cc: Jay Ding , Venkat Duvvuru , Randy Schacher Date: Thu, 2 Jul 2020 16:28:08 -0700 Message-Id: <20200702232838.92817-22-ajit.khaparde@broadcom.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200702232838.92817-1-ajit.khaparde@broadcom.com> References: <1f5421dc-0453-6dc8-09c2-ddfff6eb4888@intel.com> <20200702232838.92817-1-ajit.khaparde@broadcom.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v4 21/51] 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 Signed-off-by: Venkat Duvvuru Reviewed-by: Randy Schacher Reviewed-by: Ajit Khaparde --- 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 fb4df9a19..918cabf19 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 563c8531a..2825bb37e 100644 --- a/drivers/net/bnxt/tf_core/bitalloc.h +++ b/drivers/net/bnxt/tf_core/bitalloc.h @@ -72,6 +72,11 @@ int ba_init(struct bitalloc *pool, int size); 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. * diff --git a/drivers/net/bnxt/tf_core/tf_rm_new.c b/drivers/net/bnxt/tf_core/tf_rm_new.c index 02b4b5c8f..de8f11955 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 a40296ed2..5cb68892a 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 2f4441de8..260fb15a6 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) { -- 2.21.1 (Apple Git-122.3)