[dpdk-dev] [PATCH v2 09/34] net/bnxt: add tf core identifier support

Venkat Duvvuru venkatkumar.duvvuru at broadcom.com
Mon Apr 13 21:39:46 CEST 2020


From: Farah Smith <farah.smith at broadcom.com>

- Add TruFlow Identifier resource support
- Add TruFlow public API for Identifier resources.
- Add support code and stack for Identifier resource allocation control.

Signed-off-by: Farah Smith <farah.smith at broadcom.com>
Reviewed-by: Randy Schacher <stuart.schacher at broadcom.com>
Reviewed-by: Ajit Kumar Khaparde <ajit.khaparde at broadcom.com>
---
 drivers/net/bnxt/tf_core/tf_core.c | 156 +++++++++++++++++++++++++++++++++++++
 drivers/net/bnxt/tf_core/tf_core.h |  55 +++++++++++++
 drivers/net/bnxt/tf_core/tf_msg.c  |  13 ++++
 3 files changed, 224 insertions(+)

diff --git a/drivers/net/bnxt/tf_core/tf_core.c b/drivers/net/bnxt/tf_core/tf_core.c
index 259ffa2..037f7d1 100644
--- a/drivers/net/bnxt/tf_core/tf_core.c
+++ b/drivers/net/bnxt/tf_core/tf_core.c
@@ -283,3 +283,159 @@ tf_close_session(struct tf *tfp)
 
 	return rc_close;
 }
+
+/** allocate identifier resource
+ *
+ * Returns success or failure code.
+ */
+int tf_alloc_identifier(struct tf *tfp,
+			struct tf_alloc_identifier_parms *parms)
+{
+	struct bitalloc *session_pool;
+	struct tf_session *tfs;
+	int id;
+	int rc;
+
+	if (parms == NULL || tfp == NULL)
+		return -EINVAL;
+
+	if (tfp->session == NULL || tfp->session->core_data == NULL) {
+		PMD_DRV_LOG(ERR, "%s: session error\n",
+			    tf_dir_2_str(parms->dir));
+		return -EINVAL;
+	}
+
+	tfs = (struct tf_session *)(tfp->session->core_data);
+
+	switch (parms->ident_type) {
+	case TF_IDENT_TYPE_L2_CTXT:
+		TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
+				TF_L2_CTXT_REMAP_POOL_NAME,
+				rc);
+		break;
+	case TF_IDENT_TYPE_PROF_FUNC:
+		TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
+				TF_PROF_FUNC_POOL_NAME,
+				rc);
+		break;
+	case TF_IDENT_TYPE_EM_PROF:
+		TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
+				TF_EM_PROF_ID_POOL_NAME,
+				rc);
+		break;
+	case TF_IDENT_TYPE_WC_PROF:
+		TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
+				TF_WC_TCAM_PROF_ID_POOL_NAME,
+				rc);
+		break;
+	case TF_IDENT_TYPE_L2_FUNC:
+		PMD_DRV_LOG(ERR, "%s: unsupported %s\n",
+			    tf_dir_2_str(parms->dir),
+			    tf_ident_2_str(parms->ident_type));
+		rc = -EOPNOTSUPP;
+		break;
+	default:
+		PMD_DRV_LOG(ERR, "%s: %s\n",
+			    tf_dir_2_str(parms->dir),
+			    tf_ident_2_str(parms->ident_type));
+		rc = -EINVAL;
+		break;
+	}
+
+	if (rc) {
+		PMD_DRV_LOG(ERR, "%s: identifier pool %s failure\n",
+			    tf_dir_2_str(parms->dir),
+			    tf_ident_2_str(parms->ident_type));
+		return rc;
+	}
+
+	id = ba_alloc(session_pool);
+
+	if (id == BA_FAIL) {
+		PMD_DRV_LOG(ERR, "%s: %s: No resource available\n",
+			    tf_dir_2_str(parms->dir),
+			    tf_ident_2_str(parms->ident_type));
+		return -ENOMEM;
+	}
+	parms->id = id;
+	return 0;
+}
+
+/** free identifier resource
+ *
+ * Returns success or failure code.
+ */
+int tf_free_identifier(struct tf *tfp,
+		       struct tf_free_identifier_parms *parms)
+{
+	struct bitalloc *session_pool;
+	int rc;
+	int ba_rc;
+	struct tf_session *tfs;
+
+	if (parms == NULL || tfp == NULL)
+		return -EINVAL;
+
+	if (tfp->session == NULL || tfp->session->core_data == NULL) {
+		PMD_DRV_LOG(ERR, "%s: Session error\n",
+			    tf_dir_2_str(parms->dir));
+		return -EINVAL;
+	}
+
+	tfs = (struct tf_session *)(tfp->session->core_data);
+
+	switch (parms->ident_type) {
+	case TF_IDENT_TYPE_L2_CTXT:
+		TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
+				TF_L2_CTXT_REMAP_POOL_NAME,
+				rc);
+		break;
+	case TF_IDENT_TYPE_PROF_FUNC:
+		TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
+				TF_PROF_FUNC_POOL_NAME,
+				rc);
+		break;
+	case TF_IDENT_TYPE_EM_PROF:
+		TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
+				TF_EM_PROF_ID_POOL_NAME,
+				rc);
+		break;
+	case TF_IDENT_TYPE_WC_PROF:
+		TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
+				TF_WC_TCAM_PROF_ID_POOL_NAME,
+				rc);
+		break;
+	case TF_IDENT_TYPE_L2_FUNC:
+		PMD_DRV_LOG(ERR, "%s: unsupported %s\n",
+			    tf_dir_2_str(parms->dir),
+			    tf_ident_2_str(parms->ident_type));
+		rc = -EOPNOTSUPP;
+		break;
+	default:
+		PMD_DRV_LOG(ERR, "%s: invalid %s\n",
+			    tf_dir_2_str(parms->dir),
+			    tf_ident_2_str(parms->ident_type));
+		rc = -EINVAL;
+		break;
+	}
+	if (rc) {
+		PMD_DRV_LOG(ERR, "%s: %s Identifier pool access failed\n",
+			    tf_dir_2_str(parms->dir),
+			    tf_ident_2_str(parms->ident_type));
+		return rc;
+	}
+
+	ba_rc = ba_inuse(session_pool, (int)parms->id);
+
+	if (ba_rc == BA_FAIL || ba_rc == BA_ENTRY_FREE) {
+		PMD_DRV_LOG(ERR, "%s: %s: Entry %d already free",
+			    tf_dir_2_str(parms->dir),
+			    tf_ident_2_str(parms->ident_type),
+			    parms->id);
+		return -EINVAL;
+	}
+
+	ba_free(session_pool, (int)parms->id);
+
+	return 0;
+}
diff --git a/drivers/net/bnxt/tf_core/tf_core.h b/drivers/net/bnxt/tf_core/tf_core.h
index 16c8251..afad9ea 100644
--- a/drivers/net/bnxt/tf_core/tf_core.h
+++ b/drivers/net/bnxt/tf_core/tf_core.h
@@ -402,6 +402,61 @@ enum tf_identifier_type {
 	TF_IDENT_TYPE_L2_FUNC
 };
 
+/** tf_alloc_identifier parameter definition
+ */
+struct tf_alloc_identifier_parms {
+	/**
+	 * [in]	 receive or transmit direction
+	 */
+	enum tf_dir dir;
+	/**
+	 * [in] Identifier type
+	 */
+	enum tf_identifier_type ident_type;
+	/**
+	 * [out] Identifier allocated
+	 */
+	uint16_t id;
+};
+
+/** tf_free_identifier parameter definition
+ */
+struct tf_free_identifier_parms {
+	/**
+	 * [in]	 receive or transmit direction
+	 */
+	enum tf_dir dir;
+	/**
+	 * [in] Identifier type
+	 */
+	enum tf_identifier_type ident_type;
+	/**
+	 * [in] ID to free
+	 */
+	uint16_t id;
+};
+
+/** allocate identifier resource
+ *
+ * TruFlow core will allocate a free id from the per identifier resource type
+ * pool reserved for the session during tf_open().  No firmware is involved.
+ *
+ * Returns success or failure code.
+ */
+int tf_alloc_identifier(struct tf *tfp,
+			struct tf_alloc_identifier_parms *parms);
+
+/** free identifier resource
+ *
+ * TruFlow core will return an id back to the per identifier resource type pool
+ * reserved for the session.  No firmware is involved.  During tf_close, the
+ * complete pool is returned to the firmware.
+ *
+ * Returns success or failure code.
+ */
+int tf_free_identifier(struct tf *tfp,
+		       struct tf_free_identifier_parms *parms);
+
 /**
  * TCAM table type
  */
diff --git a/drivers/net/bnxt/tf_core/tf_msg.c b/drivers/net/bnxt/tf_core/tf_msg.c
index 4ce2bc5..c44f96f 100644
--- a/drivers/net/bnxt/tf_core/tf_msg.c
+++ b/drivers/net/bnxt/tf_core/tf_msg.c
@@ -94,6 +94,19 @@
 } while (0)
 
 /**
+ * This is the MAX data we can transport across regular HWRM
+ */
+#define TF_PCI_BUF_SIZE_MAX 88
+
+/**
+ * If data bigger than TF_PCI_BUF_SIZE_MAX then use DMA method
+ */
+struct tf_msg_dma_buf {
+	void *va_addr;
+	uint64_t pa_addr;
+};
+
+/**
  * Sends session open request to TF Firmware
  */
 int
-- 
2.7.4



More information about the dev mailing list