net/bnxt: add functions to clear TCAM regions
authorFarah Smith <farah.smith@broadcom.com>
Sun, 30 May 2021 08:58:56 +0000 (14:28 +0530)
committerAjit Khaparde <ajit.khaparde@broadcom.com>
Thu, 8 Jul 2021 00:01:55 +0000 (02:01 +0200)
Add TRUFLOW API to clear either the hi or the low regions
in WildCard TCAM for ungraceful exit cleanup.

Signed-off-by: Farah Smith <farah.smith@broadcom.com>
Signed-off-by: Randy Schacher <stuart.schacher@broadcom.com>
Signed-off-by: Venkat Duvvuru <venkatkumar.duvvuru@broadcom.com>
Reviewed-by: Jay Ding <jay.ding@broadcom.com>
Reviewed-by: Peter Spreadborough <peter.spreadborough@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_device.h
drivers/net/bnxt/tf_core/tf_device_p4.c
drivers/net/bnxt/tf_core/tf_device_p58.c
drivers/net/bnxt/tf_core/tf_tcam_shared.c
drivers/net/bnxt/tf_core/tf_tcam_shared.h
drivers/net/bnxt/tf_core/tf_util.h

index 0fbbd40..97e6165 100644 (file)
@@ -968,6 +968,57 @@ tf_move_tcam_shared_entries(struct tf *tfp,
 
        return 0;
 }
+
+int
+tf_clear_tcam_shared_entries(struct tf *tfp,
+                            struct tf_clear_tcam_shared_entries_parms *parms)
+{
+       int rc;
+       struct tf_session *tfs;
+       struct tf_dev_info *dev;
+
+       TF_CHECK_PARMS2(tfp, parms);
+
+       /* Retrieve the session information */
+       rc = tf_session_get_session(tfp, &tfs);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "%s: Failed to lookup session, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           strerror(-rc));
+               return rc;
+       }
+
+       /* Retrieve the device information */
+       rc = tf_session_get_device(tfs, &dev);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "%s: Failed to lookup device, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           strerror(-rc));
+               return rc;
+       }
+
+       if (dev->ops->tf_dev_clear_tcam == NULL) {
+               rc = -EOPNOTSUPP;
+               TFP_DRV_LOG(ERR,
+                           "%s: Operation not supported, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           strerror(-rc));
+               return rc;
+       }
+
+       rc = dev->ops->tf_dev_clear_tcam(tfp, parms);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "%s: TCAM shared entries clear failed, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           strerror(-rc));
+               return rc;
+       }
+
+       return 0;
+}
 #endif /* TF_TCAM_SHARED */
 
 int
index 44c30fa..0b06bb2 100644 (file)
@@ -233,7 +233,7 @@ enum tf_identifier_type {
         */
        TF_IDENT_TYPE_EM_PROF,
        /**
-        *  TH
+        *  (Future)
         *  The L2 func is included in the ILT result and from recycling to
         *  enable virtualization of further lookups.
         */
@@ -1244,6 +1244,8 @@ int tf_free_tbl_scope(struct tf *tfp,
  *
 #ifdef TF_TCAM_SHARED
  * @ref tf_move_tcam_shared_entries
+ *
+ * @ref tf_clear_tcam_shared_entries
 #endif
  */
 
@@ -1580,6 +1582,37 @@ struct tf_move_tcam_shared_entries_parms {
 int tf_move_tcam_shared_entries(struct tf *tfp,
                                struct tf_move_tcam_shared_entries_parms *parms);
 
+/**
+ * tf_clear_tcam_shared_entries parameter definition
+ */
+struct tf_clear_tcam_shared_entries_parms {
+       /**
+        * [in] receive or transmit direction
+        */
+       enum tf_dir dir;
+       /**
+        * [in] TCAM table type
+        */
+       enum tf_tcam_tbl_type tcam_tbl_type;
+};
+
+/**
+ * Clear TCAM shared entries pool
+ *
+ * This API only affects the following TCAM pools within a shared session:
+ *
+ * TF_TCAM_TBL_TYPE_WC_TCAM_HIGH
+ * TF_TCAM_TBL_TYPE_WC_TCAM_LOW
+ *
+ * When called, the indicated WC TCAM high or low pool will be cleared.
+ *
+ * This API is not supported on a non-shared session.
+ *
+ * Returns success or failure code.
+ */
+int tf_clear_tcam_shared_entries(struct tf *tfp,
+                             struct tf_clear_tcam_shared_entries_parms *parms);
+
 #endif /* TF_TCAM_SHARED */
 /**
  * @page table Table Access
@@ -2108,7 +2141,7 @@ struct tf_move_em_entry_parms {
        uint64_t flow_handle;
 };
 /**
- * tf_search_em_entry parameter definition
+ * tf_search_em_entry parameter definition (Future)
  */
 struct tf_search_em_entry_parms {
        /**
@@ -2211,7 +2244,7 @@ int tf_delete_em_entry(struct tf *tfp,
                       struct tf_delete_em_entry_parms *parms);
 
 /**
- * search em hash entry table memory
+ * search em hash entry table memory (Future)
  *
  * Internal:
 
index 1893f63..da3f541 100644 (file)
@@ -595,7 +595,24 @@ struct tf_dev_ops {
         *    -EINVAL - Error
         */
        int (*tf_dev_move_tcam)(struct tf *tfp,
-                               struct tf_move_tcam_shared_entries_parms *parms);
+                              struct tf_move_tcam_shared_entries_parms *parms);
+
+       /**
+        * Move TCAM shared entries
+        *
+        * [in] tfp
+        *   Pointer to TF handle
+        *
+        * [in] parms
+        *   Pointer to parameters
+        *
+        *    returns:
+        *    0       - Success
+        *    -EINVAL - Error
+        */
+       int (*tf_dev_clear_tcam)(struct tf *tfp,
+                             struct tf_clear_tcam_shared_entries_parms *parms);
+
 #endif /* TF_TCAM_SHARED */
 
        /**
index 2397848..971fab7 100644 (file)
@@ -248,9 +248,6 @@ const struct tf_dev_ops tf_dev_ops_p4_init = {
        .tf_dev_alloc_search_tcam = NULL,
        .tf_dev_set_tcam = NULL,
        .tf_dev_get_tcam = NULL,
-#ifdef TF_TCAM_SHARED
-       .tf_dev_move_tcam = NULL,
-#endif /* TF_TCAM_SHARED */
        .tf_dev_get_tcam_resc_info = NULL,
        .tf_dev_insert_int_em_entry = NULL,
        .tf_dev_delete_int_em_entry = NULL,
@@ -298,6 +295,7 @@ const struct tf_dev_ops tf_dev_ops_p4 = {
        .tf_dev_set_tcam = tf_tcam_shared_set,
        .tf_dev_get_tcam = tf_tcam_shared_get,
        .tf_dev_move_tcam = tf_tcam_shared_move_p4,
+       .tf_dev_clear_tcam = tf_tcam_shared_clear,
 #else /* !TF_TCAM_SHARED */
        .tf_dev_alloc_tcam = tf_tcam_alloc,
        .tf_dev_free_tcam = tf_tcam_free,
index 483f771..6bbc5e2 100644 (file)
@@ -339,6 +339,7 @@ const struct tf_dev_ops tf_dev_ops_p58 = {
        .tf_dev_set_tcam = tf_tcam_shared_set,
        .tf_dev_get_tcam = tf_tcam_shared_get,
        .tf_dev_move_tcam = tf_tcam_shared_move_p58,
+       .tf_dev_clear_tcam = tf_tcam_shared_clear,
 #else /* !TF_TCAM_SHARED */
        .tf_dev_alloc_tcam = tf_tcam_alloc,
        .tf_dev_free_tcam = tf_tcam_free,
index 9cd5533..83b6fbd 100644 (file)
@@ -1153,8 +1153,9 @@ done:
        return rc;
 }
 
-int tf_tcam_shared_move_p4(struct tf *tfp,
-                          struct tf_move_tcam_shared_entries_parms *parms)
+int
+tf_tcam_shared_move_p4(struct tf *tfp,
+                      struct tf_move_tcam_shared_entries_parms *parms)
 {
        int rc = 0;
        rc = tf_tcam_shared_move(tfp,
@@ -1166,8 +1167,9 @@ int tf_tcam_shared_move_p4(struct tf *tfp,
 }
 
 
-int tf_tcam_shared_move_p58(struct tf *tfp,
-                           struct tf_move_tcam_shared_entries_parms *parms)
+int
+tf_tcam_shared_move_p58(struct tf *tfp,
+                       struct tf_move_tcam_shared_entries_parms *parms)
 {
        int rc = 0;
        rc = tf_tcam_shared_move(tfp,
@@ -1177,3 +1179,104 @@ int tf_tcam_shared_move_p58(struct tf *tfp,
                                 true); /* set enable bit */
        return rc;
 }
+
+int
+tf_tcam_shared_clear(struct tf *tfp,
+                    struct tf_clear_tcam_shared_entries_parms *parms)
+{
+       int rc = 0;
+       struct tf_session *tfs;
+       struct tf_dev_info *dev;
+       uint16_t start;
+       int phy_idx;
+       enum tf_tcam_shared_wc_pool_id id;
+       struct tf_tcam_free_parms nparms;
+       uint16_t hcapi_type;
+       struct tf_rm_alloc_info info;
+       void *tcam_shared_db_ptr = NULL;
+       struct tf_tcam_shared_wc_pools *tcam_shared_wc;
+       int i, cnt;
+
+       TF_CHECK_PARMS2(tfp, parms);
+
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
+
+       if (!tf_session_is_shared_session(tfs) ||
+           (parms->tcam_tbl_type != TF_TCAM_TBL_TYPE_WC_TCAM_HIGH &&
+            parms->tcam_tbl_type != TF_TCAM_TBL_TYPE_WC_TCAM_LOW))
+               return -EOPNOTSUPP;
+
+       if (!tf_tcam_db_valid(tfp, parms->dir)) {
+               TFP_DRV_LOG(ERR,
+                           "%s: tcam shared pool doesn't exist\n",
+                           tf_dir_2_str(parms->dir));
+               return -ENOMEM;
+       }
+
+       rc = tf_session_get_tcam_shared_db(tfp, (void *)&tcam_shared_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get tcam_shared_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tcam_shared_wc = (struct tf_tcam_shared_wc_pools *)tcam_shared_db_ptr;
+
+
+       if (parms->tcam_tbl_type == TF_TCAM_TBL_TYPE_WC_TCAM_HIGH)
+               id = TF_TCAM_SHARED_WC_POOL_HI;
+       else
+               id = TF_TCAM_SHARED_WC_POOL_LO;
+
+
+       /* Retrieve the device information */
+       rc = tf_session_get_device(tfs, &dev);
+       if (rc)
+               return rc;
+
+       rc = tf_tcam_shared_get_rm_info(tfp,
+                                       parms->dir,
+                                       &hcapi_type,
+                                       &info);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "%s: TCAM rm info get failed\n",
+                           tf_dir_2_str(parms->dir));
+               return rc;
+       }
+
+       start = tcam_shared_wc->db[parms->dir][id].info.start;
+       cnt = tcam_shared_wc->db[parms->dir][id].info.stride;
+
+       /* Override HI/LO type with parent WC TCAM type */
+       nparms.dir = parms->dir;
+       nparms.type = TF_TCAM_TBL_TYPE_WC_TCAM;
+       nparms.hcapi_type = hcapi_type;
+
+       for (i = 0; i < cnt; i++) {
+               phy_idx = start + i;
+               nparms.idx = phy_idx;
+
+               /* Clear entry */
+               rc = tf_msg_tcam_entry_free(tfp, dev, &nparms);
+               if (rc) {
+                       /* Log error */
+                       TFP_DRV_LOG(ERR,
+                                   "%s: %s: log%d free failed, rc:%s\n",
+                                   tf_dir_2_str(nparms.dir),
+                                   tf_tcam_tbl_2_str(nparms.type),
+                                   phy_idx,
+                                   strerror(-rc));
+                       return rc;
+               }
+       }
+
+       TFP_DRV_LOG(DEBUG,
+                   "%s: TCAM shared clear pool(%s)\n",
+                   tf_dir_2_str(nparms.dir),
+                   tf_pool_2_str(id));
+       return 0;
+}
index 5588125..020763a 100644 (file)
  *
  * @ref tf_tcam_shared_get
  *
+ * @ref tf_tcam_shared_move_p4
+ *
+ * @ref tf_tcam_shared_move_p58
+ *
+ * @ref tf_tcam_shared_clear
  */
 
 /**
@@ -159,4 +164,20 @@ int tf_tcam_shared_move_p4(struct tf *tfp,
 int tf_tcam_shared_move_p58(struct tf *tfp,
                            struct tf_move_tcam_shared_entries_parms *parms);
 
+/**
+ * Allocates and clears the entire WC_TCAM_HI or WC_TCAM_LO shared pools
+ *
+ * [in] tfp
+ *   Pointer to the truflow handle
+ *
+ * [in] parms
+ *   Pointer to parameters
+ *
+ * Returns
+ *   - (0) if successful.
+ *   - (-EINVAL) on failure.
+ */
+int tf_tcam_shared_clear(struct tf *tfp,
+                        struct tf_clear_tcam_shared_entries_parms *parms);
+
 #endif /* _TF_TCAM_SHARED_H */
index 4caf503..854c519 100644 (file)
@@ -7,7 +7,6 @@
 #define _TF_UTIL_H_
 
 #include "tf_core.h"
-#include "tf_device.h"
 
 #define TF_BITS2BYTES(x) (((x) + 7) >> 3)
 #define TF_BITS2BYTES_WORD_ALIGN(x) ((((x) + 31) >> 5) * 4)