net/bnxt: add conditional processing of templates
[dpdk.git] / drivers / net / bnxt / tf_core / tf_device.c
index d072b98..498e668 100644 (file)
@@ -8,6 +8,10 @@
 #include "tf_device_p58.h"
 #include "tfp.h"
 #include "tf_em.h"
+#include "tf_rm.h"
+#ifdef TF_TCAM_SHARED
+#include "tf_tcam_shared.h"
+#endif /* TF_TCAM_SHARED */
 
 struct tf;
 
@@ -18,8 +22,8 @@ static int tf_dev_unbind_p58(struct tf *tfp);
 /**
  * Resource Reservation Check function
  *
- * [in] tfp
- *   Pointer to TF handle
+ * [in] count
+ *   Number of module subtypes
  *
  * [in] cfg
  *   Pointer to rm element config
@@ -28,11 +32,10 @@ static int tf_dev_unbind_p58(struct tf *tfp);
  *   Pointer to resource reservation array
  *
  * Returns
- *   - (n) number of tables that have non-zero reservation count.
+ *   - (n) number of tables in module that have non-zero reservation count.
  */
 static int
-tf_dev_reservation_check(struct tf *tfp __rte_unused,
-                        uint16_t count,
+tf_dev_reservation_check(uint16_t count,
                         struct tf_rm_element_cfg *cfg,
                         uint16_t *reservations)
 {
@@ -44,7 +47,11 @@ tf_dev_reservation_check(struct tf *tfp __rte_unused,
                rm_num = (uint16_t *)reservations + i * count;
                for (j = 0; j < count; j++) {
                        if ((cfg[j].cfg_type == TF_RM_ELEM_CFG_HCAPI ||
-                            cfg[j].cfg_type == TF_RM_ELEM_CFG_HCAPI_BA) &&
+                            cfg[j].cfg_type == TF_RM_ELEM_CFG_HCAPI_BA ||
+                            cfg[j].cfg_type ==
+                               TF_RM_ELEM_CFG_HCAPI_BA_PARENT ||
+                            cfg[j].cfg_type ==
+                               TF_RM_ELEM_CFG_HCAPI_BA_CHILD) &&
                             rm_num[j] > 0)
                                cnt++;
                }
@@ -88,14 +95,19 @@ tf_dev_bind_p4(struct tf *tfp,
        struct tf_em_cfg_parms em_cfg;
        struct tf_if_tbl_cfg_parms if_tbl_cfg;
        struct tf_global_cfg_cfg_parms global_cfg;
+       struct tf_session *tfs;
+
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
 
        /* Initial function initialization */
        dev_handle->ops = &tf_dev_ops_p4_init;
 
        /* Initialize the modules */
 
-       rsv_cnt = tf_dev_reservation_check(tfp,
-                                          TF_IDENT_TYPE_MAX,
+       rsv_cnt = tf_dev_reservation_check(TF_IDENT_TYPE_MAX,
                                           tf_ident_p4,
                                           (uint16_t *)resources->ident_cnt);
        if (rsv_cnt) {
@@ -113,8 +125,7 @@ tf_dev_bind_p4(struct tf *tfp,
                no_rsv_flag = false;
        }
 
-       rsv_cnt = tf_dev_reservation_check(tfp,
-                                          TF_TBL_TYPE_MAX,
+       rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
                                           tf_tbl_p4,
                                           (uint16_t *)resources->tbl_cnt);
        if (rsv_cnt) {
@@ -132,8 +143,7 @@ tf_dev_bind_p4(struct tf *tfp,
                no_rsv_flag = false;
        }
 
-       rsv_cnt = tf_dev_reservation_check(tfp,
-                                          TF_TCAM_TBL_TYPE_MAX,
+       rsv_cnt = tf_dev_reservation_check(TF_TCAM_TBL_TYPE_MAX,
                                           tf_tcam_p4,
                                           (uint16_t *)resources->tcam_cnt);
        if (rsv_cnt) {
@@ -141,7 +151,11 @@ tf_dev_bind_p4(struct tf *tfp,
                tcam_cfg.cfg = tf_tcam_p4;
                tcam_cfg.shadow_copy = shadow_copy;
                tcam_cfg.resources = resources;
+#ifdef TF_TCAM_SHARED
+               rc = tf_tcam_shared_bind(tfp, &tcam_cfg);
+#else /* !TF_TCAM_SHARED */
                rc = tf_tcam_bind(tfp, &tcam_cfg);
+#endif
                if (rc) {
                        TFP_DRV_LOG(ERR,
                                    "TCAM initialization failure\n");
@@ -155,8 +169,7 @@ tf_dev_bind_p4(struct tf *tfp,
         */
 
        em_cfg.cfg = tf_em_ext_p4;
-       rsv_cnt = tf_dev_reservation_check(tfp,
-                                          TF_EM_TBL_TYPE_MAX,
+       rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
                                           em_cfg.cfg,
                                           (uint16_t *)resources->em_cnt);
        if (rsv_cnt) {
@@ -175,8 +188,7 @@ tf_dev_bind_p4(struct tf *tfp,
        /*
         * EM
         */
-       rsv_cnt = tf_dev_reservation_check(tfp,
-                                          TF_EM_TBL_TYPE_MAX,
+       rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
                                           tf_em_int_p4,
                                           (uint16_t *)resources->em_cnt);
        if (rsv_cnt) {
@@ -217,18 +229,19 @@ tf_dev_bind_p4(struct tf *tfp,
                goto fail;
        }
 
-       /*
-        * GLOBAL_CFG
-        */
-       global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
-       global_cfg.cfg = tf_global_cfg_p4;
-       rc = tf_global_cfg_bind(tfp, &global_cfg);
-       if (rc) {
-               TFP_DRV_LOG(ERR,
-                           "Global Cfg initialization failure\n");
-               goto fail;
+       if (!tf_session_is_shared_session(tfs)) {
+               /*
+                * GLOBAL_CFG
+                */
+               global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
+               global_cfg.cfg = tf_global_cfg_p4;
+               rc = tf_global_cfg_bind(tfp, &global_cfg);
+               if (rc) {
+                       TFP_DRV_LOG(ERR,
+                                   "Global Cfg initialization failure\n");
+                       goto fail;
+               }
        }
-
        /* Final function initialization */
        dev_handle->ops = &tf_dev_ops_p4;
 
@@ -258,6 +271,12 @@ tf_dev_unbind_p4(struct tf *tfp)
 {
        int rc = 0;
        bool fail = false;
+       struct tf_session *tfs;
+
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
 
        /* Unbind all the support modules. As this is only done on
         * close we only report errors as everything has to be cleaned
@@ -266,53 +285,59 @@ tf_dev_unbind_p4(struct tf *tfp)
         * In case of residuals TCAMs are cleaned up first as to
         * invalidate the pipeline in a clean manner.
         */
+#ifdef TF_TCAM_SHARED
+       rc = tf_tcam_shared_unbind(tfp);
+#else /* !TF_TCAM_SHARED */
        rc = tf_tcam_unbind(tfp);
+#endif /* TF_TCAM_SHARED */
        if (rc) {
-               TFP_DRV_LOG(ERR,
+               TFP_DRV_LOG(INFO,
                            "Device unbind failed, TCAM\n");
                fail = true;
        }
 
        rc = tf_ident_unbind(tfp);
        if (rc) {
-               TFP_DRV_LOG(ERR,
+               TFP_DRV_LOG(INFO,
                            "Device unbind failed, Identifier\n");
                fail = true;
        }
 
        rc = tf_tbl_unbind(tfp);
        if (rc) {
-               TFP_DRV_LOG(ERR,
+               TFP_DRV_LOG(INFO,
                            "Device unbind failed, Table Type\n");
                fail = true;
        }
 
        rc = tf_em_ext_common_unbind(tfp);
        if (rc) {
-               TFP_DRV_LOG(ERR,
+               TFP_DRV_LOG(INFO,
                            "Device unbind failed, EEM\n");
                fail = true;
        }
 
        rc = tf_em_int_unbind(tfp);
        if (rc) {
-               TFP_DRV_LOG(ERR,
+               TFP_DRV_LOG(INFO,
                            "Device unbind failed, EM\n");
                fail = true;
        }
 
-       rc = tf_if_tbl_unbind(tfp);
-       if (rc) {
-               TFP_DRV_LOG(ERR,
-                           "Device unbind failed, IF Table Type\n");
-               fail = true;
-       }
+       if (!tf_session_is_shared_session(tfs)) {
+               rc = tf_if_tbl_unbind(tfp);
+               if (rc) {
+                       TFP_DRV_LOG(INFO,
+                                   "Device unbind failed, IF Table Type\n");
+                       fail = true;
+               }
 
-       rc = tf_global_cfg_unbind(tfp);
-       if (rc) {
-               TFP_DRV_LOG(ERR,
-                           "Device unbind failed, Global Cfg Type\n");
-               fail = true;
+               rc = tf_global_cfg_unbind(tfp);
+               if (rc) {
+                       TFP_DRV_LOG(INFO,
+                                   "Device unbind failed, Global Cfg Type\n");
+                       fail = true;
+               }
        }
 
        if (fail)
@@ -356,14 +381,17 @@ tf_dev_bind_p58(struct tf *tfp,
        struct tf_em_cfg_parms em_cfg;
        struct tf_if_tbl_cfg_parms if_tbl_cfg;
        struct tf_global_cfg_cfg_parms global_cfg;
+       struct tf_session *tfs;
 
        /* Initial function initialization */
        dev_handle->ops = &tf_dev_ops_p58_init;
 
-       /* Initialize the modules */
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
 
-       rsv_cnt = tf_dev_reservation_check(tfp,
-                                          TF_IDENT_TYPE_MAX,
+       rsv_cnt = tf_dev_reservation_check(TF_IDENT_TYPE_MAX,
                                           tf_ident_p58,
                                           (uint16_t *)resources->ident_cnt);
        if (rsv_cnt) {
@@ -380,8 +408,7 @@ tf_dev_bind_p58(struct tf *tfp,
                no_rsv_flag = false;
        }
 
-       rsv_cnt = tf_dev_reservation_check(tfp,
-                                          TF_TBL_TYPE_MAX,
+       rsv_cnt = tf_dev_reservation_check(TF_TBL_TYPE_MAX,
                                           tf_tbl_p58,
                                           (uint16_t *)resources->tbl_cnt);
        if (rsv_cnt) {
@@ -398,8 +425,7 @@ tf_dev_bind_p58(struct tf *tfp,
                no_rsv_flag = false;
        }
 
-       rsv_cnt = tf_dev_reservation_check(tfp,
-                                          TF_TCAM_TBL_TYPE_MAX,
+       rsv_cnt = tf_dev_reservation_check(TF_TCAM_TBL_TYPE_MAX,
                                           tf_tcam_p58,
                                           (uint16_t *)resources->tcam_cnt);
        if (rsv_cnt) {
@@ -407,7 +433,11 @@ tf_dev_bind_p58(struct tf *tfp,
                tcam_cfg.cfg = tf_tcam_p58;
                tcam_cfg.shadow_copy = shadow_copy;
                tcam_cfg.resources = resources;
+#ifdef TF_TCAM_SHARED
+               rc = tf_tcam_shared_bind(tfp, &tcam_cfg);
+#else /* !TF_TCAM_SHARED */
                rc = tf_tcam_bind(tfp, &tcam_cfg);
+#endif
                if (rc) {
                        TFP_DRV_LOG(ERR,
                                    "TCAM initialization failure\n");
@@ -419,8 +449,7 @@ tf_dev_bind_p58(struct tf *tfp,
        /*
         * EM
         */
-       rsv_cnt = tf_dev_reservation_check(tfp,
-                                          TF_EM_TBL_TYPE_MAX,
+       rsv_cnt = tf_dev_reservation_check(TF_EM_TBL_TYPE_MAX,
                                           tf_em_int_p58,
                                           (uint16_t *)resources->em_cnt);
        if (rsv_cnt) {
@@ -461,16 +490,18 @@ tf_dev_bind_p58(struct tf *tfp,
                goto fail;
        }
 
-       /*
-        * GLOBAL_CFG
-        */
-       global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
-       global_cfg.cfg = tf_global_cfg_p58;
-       rc = tf_global_cfg_bind(tfp, &global_cfg);
-       if (rc) {
-               TFP_DRV_LOG(ERR,
-                           "Global Cfg initialization failure\n");
-               goto fail;
+       if (!tf_session_is_shared_session(tfs)) {
+               /*
+                * GLOBAL_CFG
+                */
+               global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX;
+               global_cfg.cfg = tf_global_cfg_p58;
+               rc = tf_global_cfg_bind(tfp, &global_cfg);
+               if (rc) {
+                       TFP_DRV_LOG(ERR,
+                                   "Global Cfg initialization failure\n");
+                       goto fail;
+               }
        }
 
        /* Final function initialization */
@@ -498,10 +529,16 @@ tf_dev_bind_p58(struct tf *tfp,
  *   - (-EINVAL) on failure.
  */
 static int
-       tf_dev_unbind_p58(struct tf *tfp)
+tf_dev_unbind_p58(struct tf *tfp)
 {
        int rc = 0;
        bool fail = false;
+       struct tf_session *tfs;
+
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
 
        /* Unbind all the support modules. As this is only done on
         * close we only report errors as everything has to be cleaned
@@ -510,30 +547,34 @@ static int
         * In case of residuals TCAMs are cleaned up first as to
         * invalidate the pipeline in a clean manner.
         */
+#ifdef TF_TCAM_SHARED
+       rc = tf_tcam_shared_unbind(tfp);
+#else /* !TF_TCAM_SHARED */
        rc = tf_tcam_unbind(tfp);
+#endif /* TF_TCAM_SHARED */
        if (rc) {
-               TFP_DRV_LOG(ERR,
+               TFP_DRV_LOG(INFO,
                            "Device unbind failed, TCAM\n");
                fail = true;
        }
 
        rc = tf_ident_unbind(tfp);
        if (rc) {
-               TFP_DRV_LOG(ERR,
+               TFP_DRV_LOG(INFO,
                            "Device unbind failed, Identifier\n");
                fail = true;
        }
 
        rc = tf_tbl_unbind(tfp);
        if (rc) {
-               TFP_DRV_LOG(ERR,
+               TFP_DRV_LOG(INFO,
                            "Device unbind failed, Table Type\n");
                fail = true;
        }
 
        rc = tf_em_int_unbind(tfp);
        if (rc) {
-               TFP_DRV_LOG(ERR,
+               TFP_DRV_LOG(INFO,
                            "Device unbind failed, EM\n");
                fail = true;
        }
@@ -545,11 +586,13 @@ static int
                fail = true;
        }
 
-       rc = tf_global_cfg_unbind(tfp);
-       if (rc) {
-               TFP_DRV_LOG(ERR,
-                           "Device unbind failed, Global Cfg Type\n");
-               fail = true;
+       if (!tf_session_is_shared_session(tfs)) {
+               rc = tf_global_cfg_unbind(tfp);
+               if (rc) {
+                       TFP_DRV_LOG(ERR,
+                                   "Device unbind failed, Global Cfg Type\n");
+                       fail = true;
+               }
        }
 
        if (fail)
@@ -593,10 +636,10 @@ tf_dev_bind_ops(enum tf_device_type type,
        switch (type) {
        case TF_DEVICE_TYPE_WH:
        case TF_DEVICE_TYPE_SR:
-               dev_handle->ops = &tf_dev_ops_p4;
+               dev_handle->ops = &tf_dev_ops_p4_init;
                break;
        case TF_DEVICE_TYPE_THOR:
-               dev_handle->ops = &tf_dev_ops_p58;
+               dev_handle->ops = &tf_dev_ops_p58_init;
                break;
        default:
                TFP_DRV_LOG(ERR,