[dpdk-dev] [PATCH v4 14/51] net/bnxt: support two-level priority for TCAMs

Ajit Khaparde ajit.khaparde at broadcom.com
Fri Jul 3 01:28:01 CEST 2020


From: Shahaji Bhosle <sbhosle at broadcom.com>

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: Shahaji Bhosle <sbhosle at broadcom.com>
Signed-off-by: Venkat Duvvuru <venkatkumar.duvvuru at broadcom.com>
Reviewed-by: Randy Schacher <stuart.schacher at broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde at broadcom.com>
---
 drivers/net/bnxt/tf_core/tf_core.c | 36 ++++++++++++++++++++++++------
 drivers/net/bnxt/tf_core/tf_core.h |  4 +++-
 drivers/net/bnxt/tf_core/tf_em.c   |  6 ++---
 drivers/net/bnxt/tf_core/tf_tbl.c  |  2 +-
 4 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/drivers/net/bnxt/tf_core/tf_core.c b/drivers/net/bnxt/tf_core/tf_core.c
index 81a88e211..eac57e7bd 100644
--- a/drivers/net/bnxt/tf_core/tf_core.c
+++ b/drivers/net/bnxt/tf_core/tf_core.c
@@ -893,7 +893,7 @@ tf_alloc_tcam_entry(struct tf *tfp,
 		    struct tf_alloc_tcam_entry_parms *parms)
 {
 	int rc;
-	int index;
+	int index = 0;
 	struct tf_session *tfs;
 	struct bitalloc *session_pool;
 
@@ -916,12 +916,34 @@ tf_alloc_tcam_entry(struct tf *tfp,
 	if (rc)
 		return rc;
 
-	index = ba_alloc(session_pool);
-	if (index == BA_FAIL) {
-		PMD_DRV_LOG(ERR, "%s: %s: No resource available\n",
-			    tf_dir_2_str(parms->dir),
-			    tf_tcam_tbl_2_str(parms->tcam_tbl_type));
-		return -ENOMEM;
+	/*
+	 * priority  0: allocate from top of the tcam i.e. high
+	 * priority !0: allocate index from bottom i.e lowest
+	 */
+	if (parms->priority) {
+		for (index = session_pool->size - 1; index >= 0; index--) {
+			if (ba_inuse(session_pool,
+					  index) == BA_ENTRY_FREE) {
+				break;
+			}
+		}
+		if (ba_alloc_index(session_pool,
+				   index) == BA_FAIL) {
+			TFP_DRV_LOG(ERR,
+				    "%s: %s: ba_alloc index %d failed\n",
+				    tf_dir_2_str(parms->dir),
+				    tf_tcam_tbl_2_str(parms->tcam_tbl_type),
+				    index);
+			return -ENOMEM;
+		}
+	} else {
+		index = ba_alloc(session_pool);
+		if (index == BA_FAIL) {
+			TFP_DRV_LOG(ERR, "%s: %s: Out of resource\n",
+				    tf_dir_2_str(parms->dir),
+				    tf_tcam_tbl_2_str(parms->tcam_tbl_type));
+			return -ENOMEM;
+		}
 	}
 
 	parms->idx = index;
diff --git a/drivers/net/bnxt/tf_core/tf_core.h b/drivers/net/bnxt/tf_core/tf_core.h
index 74ed24e5a..f1ef00b30 100644
--- a/drivers/net/bnxt/tf_core/tf_core.h
+++ b/drivers/net/bnxt/tf_core/tf_core.h
@@ -799,7 +799,9 @@ struct tf_alloc_tcam_entry_parms {
 	 */
 	uint8_t *mask;
 	/**
-	 * [in] Priority of entry requested (definition TBD)
+	 * [in] Priority of entry requested
+	 * 0: index from top i.e. highest priority first
+	 * !0: index from bottom i.e lowest priority first
 	 */
 	uint32_t priority;
 	/**
diff --git a/drivers/net/bnxt/tf_core/tf_em.c b/drivers/net/bnxt/tf_core/tf_em.c
index fd1797e39..91cbc6299 100644
--- a/drivers/net/bnxt/tf_core/tf_em.c
+++ b/drivers/net/bnxt/tf_core/tf_em.c
@@ -479,8 +479,7 @@ int tf_insert_em_internal_entry(struct tf *tfp,
 	rc = stack_pop(pool, &index);
 
 	if (rc != 0) {
-		PMD_DRV_LOG
-		   (ERR,
+		TFP_DRV_LOG(ERR,
 		   "dir:%d, EM entry index allocation failed\n",
 		   parms->dir);
 		return rc;
@@ -495,8 +494,7 @@ int tf_insert_em_internal_entry(struct tf *tfp,
 	if (rc != 0)
 		return -1;
 
-	PMD_DRV_LOG
-		   (ERR,
+	TFP_DRV_LOG(INFO,
 		   "Internal entry @ Index:%d rptr_index:0x%x rptr_entry:0x%x num_of_entries:%d\n",
 		   index * TF_SESSION_EM_ENTRY_SIZE,
 		   rptr_index,
diff --git a/drivers/net/bnxt/tf_core/tf_tbl.c b/drivers/net/bnxt/tf_core/tf_tbl.c
index 26313ed3c..4e236d56c 100644
--- a/drivers/net/bnxt/tf_core/tf_tbl.c
+++ b/drivers/net/bnxt/tf_core/tf_tbl.c
@@ -1967,7 +1967,7 @@ void tf_dump_dma(struct tf *tfp, uint32_t tbl_scope_id)
 	tbl_scope_cb = tbl_scope_cb_find(session,
 					 tbl_scope_id);
 	if (tbl_scope_cb == NULL)
-		PMD_DRV_LOG(ERR, "No table scope\n");
+		TFP_DRV_LOG(ERR, "No table scope\n");
 
 	for (dir = 0; dir < TF_DIR_MAX; dir++) {
 		printf("Direction %s:\n", (dir == TF_DIR_RX ? "Rx" : "Tx"));
-- 
2.21.1 (Apple Git-122.3)



More information about the dev mailing list