net/bnxt: add TruFlow core identifier
authorFarah Smith <farah.smith@broadcom.com>
Wed, 15 Apr 2020 08:18:46 +0000 (13:48 +0530)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 21 Apr 2020 11:57:08 +0000 (13:57 +0200)
- 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@broadcom.com>
Reviewed-by: Randy Schacher <stuart.schacher@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
drivers/net/bnxt/tf_core/tf_core.c
drivers/net/bnxt/tf_core/tf_core.h
drivers/net/bnxt/tf_core/tf_msg.c

index bb6d38b..7b027f7 100644 (file)
@@ -284,3 +284,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;
+}
index c225202..2f5bee2 100644 (file)
@@ -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
  */
index 4ce2bc5..c44f96f 100644 (file)
                tfp_le_to_cpu_16(response.element ## _stride);               \
 } 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
  */