[14/50] net/bnxt: support two-level priority for TCAMs

Message ID 20200612132934.16488-15-somnath.kotur@broadcom.com (mailing list archive)
State Superseded, archived
Delegated to: Ajit Khaparde
Headers
Series add features for host-based flow management |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

Somnath Kotur June 12, 2020, 1:28 p.m. UTC
  From: Shahaji Bhosle <sbhosle@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@broadcom.com>
Reviewed-by: Randy Schacher <stuart.schacher@broadcom.com>
Reviewed-by: Ajit Kumar Khaparde <ajit.khaparde@broadcom.com>
Signed-off-by: Venkat Duvvuru <venkatkumar.duvvuru@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(-)
  

Patch

diff --git a/drivers/net/bnxt/tf_core/tf_core.c b/drivers/net/bnxt/tf_core/tf_core.c
index 28a6bbd..7d9bca8 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 74ed24e..f1ef00b 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 fd1797e..91cbc62 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 0f2979e..f9bfae7 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"));