net/bnxt: enable shadow tables during session open
[dpdk.git] / drivers / net / bnxt / tf_ulp / bnxt_ulp.c
index 6b0a403..077527f 100644 (file)
@@ -9,9 +9,9 @@
 #include <rte_flow_driver.h>
 #include <rte_tailq.h>
 
+#include "bnxt.h"
 #include "bnxt_ulp.h"
 #include "bnxt_tf_common.h"
-#include "bnxt.h"
 #include "tf_core.h"
 #include "tf_ext_flow_handle.h"
 
@@ -81,12 +81,13 @@ ulp_ctx_session_open(struct bnxt *bp,
                return rc;
        }
 
-       params.shadow_copy = false;
+       params.shadow_copy = true;
        params.device_type = TF_DEVICE_TYPE_WH;
        resources = &params.resources;
        /** RX **/
        /* Identifiers */
-       resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_L2_CTXT] = 16;
+       resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_L2_CTXT_HIGH] = 200;
+       resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_L2_CTXT_LOW] = 20;
        resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_WC_PROF] = 8;
        resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_PROF_FUNC] = 8;
        resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_EM_PROF] = 8;
@@ -94,9 +95,17 @@ ulp_ctx_session_open(struct bnxt *bp,
        /* Table Types */
        resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_FULL_ACT_RECORD] = 720;
        resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_STATS_64] = 720;
+       resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_MODIFY_IPV4] = 8;
+
+       /* ENCAP */
+       resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_ENCAP_8B] = 16;
+       resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_ENCAP_16B] = 16;
 
        /* TCAMs */
-       resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM] = 16;
+       resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_HIGH] =
+               200;
+       resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_LOW] =
+               20;
        resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_PROF_TCAM] = 8;
        resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] = 416;
 
@@ -108,7 +117,8 @@ ulp_ctx_session_open(struct bnxt *bp,
 
        /** TX **/
        /* Identifiers */
-       resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_L2_CTXT] = 8;
+       resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_L2_CTXT_HIGH] = 200;
+       resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_L2_CTXT_LOW] = 20;
        resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_WC_PROF] = 8;
        resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_PROF_FUNC] = 8;
        resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_EM_PROF] = 8;
@@ -116,13 +126,17 @@ ulp_ctx_session_open(struct bnxt *bp,
        /* Table Types */
        resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_FULL_ACT_RECORD] = 16;
        resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_STATS_64] = 16;
+       resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_MODIFY_IPV4] = 8;
 
        /* ENCAP */
        resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_64B] = 16;
        resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_16B] = 16;
 
        /* TCAMs */
-       resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM] = 8;
+       resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_HIGH] =
+               200;
+       resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_LOW] =
+               20;
        resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_PROF_TCAM] = 8;
        resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] = 8;
 
@@ -359,6 +373,7 @@ ulp_ctx_init(struct bnxt *bp,
        bp->ulp_ctx->cfg_data = ulp_data;
        session->cfg_data = ulp_data;
        ulp_data->ref_cnt++;
+       ulp_data->ulp_flags |= BNXT_ULP_VF_REP_ENABLED;
 
        /* Open the ulp session. */
        rc = ulp_ctx_session_open(bp, session);
@@ -366,6 +381,7 @@ ulp_ctx_init(struct bnxt *bp,
                (void)ulp_ctx_deinit(bp, session);
                return rc;
        }
+
        bnxt_ulp_cntxt_tfp_set(bp->ulp_ctx, session->g_tfp);
        return rc;
 }
@@ -581,6 +597,52 @@ ulp_session_deinit(struct bnxt_ulp_session_state *session)
        }
 }
 
+/*
+ * Internal api to enable NAT feature.
+ * Set set_flag to 1 to set the value or zero to reset the value.
+ * returns 0 on success.
+ */
+static int32_t
+bnxt_ulp_global_cfg_update(struct bnxt *bp,
+                          enum tf_dir dir,
+                          enum tf_global_config_type type,
+                          uint32_t offset,
+                          uint32_t value,
+                          uint32_t set_flag)
+{
+       uint32_t global_cfg = 0;
+       int rc;
+       struct tf_global_cfg_parms parms;
+
+       /* Initialize the params */
+       parms.dir = dir,
+       parms.type = type,
+       parms.offset = offset,
+       parms.config = (uint8_t *)&global_cfg,
+       parms.config_sz_in_bytes = sizeof(global_cfg);
+
+       rc = tf_get_global_cfg(&bp->tfp, &parms);
+       if (rc) {
+               BNXT_TF_DBG(ERR, "Failed to get global cfg 0x%x rc:%d\n",
+                           type, rc);
+               return rc;
+       }
+
+       if (set_flag)
+               global_cfg |= value;
+       else
+               global_cfg &= ~value;
+
+       /* SET the register RE_CFA_REG_ACT_TECT */
+       rc = tf_set_global_cfg(&bp->tfp, &parms);
+       if (rc) {
+               BNXT_TF_DBG(ERR, "Failed to set global cfg 0x%x rc:%d\n",
+                           type, rc);
+               return rc;
+       }
+       return rc;
+}
+
 /*
  * When a port is initialized by dpdk. This functions is called
  * and this function initializes the ULP context and rest of the
@@ -593,6 +655,9 @@ bnxt_ulp_init(struct bnxt *bp)
        bool init;
        int rc;
 
+       if (!BNXT_TRUFLOW_EN(bp))
+               return 0;
+
        if (bp->ulp_ctx) {
                BNXT_TF_DBG(DEBUG, "ulp ctx already allocated\n");
                return -EINVAL;
@@ -717,6 +782,29 @@ bnxt_ulp_init(struct bnxt *bp)
                goto jump_to_error;
        }
 
+       /*
+        * Enable NAT feature. Set the global configuration register
+        * Tunnel encap to enable NAT with the reuse of existing inner
+        * L2 header smac and dmac
+        */
+       rc = bnxt_ulp_global_cfg_update(bp, TF_DIR_RX, TF_TUNNEL_ENCAP,
+                                       TF_TUNNEL_ENCAP_NAT,
+                                       (BNXT_ULP_NAT_INNER_L2_HEADER_SMAC |
+                                       BNXT_ULP_NAT_INNER_L2_HEADER_DMAC), 1);
+       if (rc) {
+               BNXT_TF_DBG(ERR, "Failed to set rx global configuration\n");
+               goto jump_to_error;
+       }
+
+       rc = bnxt_ulp_global_cfg_update(bp, TF_DIR_TX, TF_TUNNEL_ENCAP,
+                                       TF_TUNNEL_ENCAP_NAT,
+                                       (BNXT_ULP_NAT_INNER_L2_HEADER_SMAC |
+                                       BNXT_ULP_NAT_INNER_L2_HEADER_DMAC), 1);
+       if (rc) {
+               BNXT_TF_DBG(ERR, "Failed to set tx global configuration\n");
+               goto jump_to_error;
+       }
+
        return rc;
 
 jump_to_error:
@@ -738,6 +826,9 @@ bnxt_ulp_deinit(struct bnxt *bp)
        struct rte_pci_device           *pci_dev;
        struct rte_pci_addr             *pci_addr;
 
+       if (!BNXT_TRUFLOW_EN(bp))
+               return;
+
        /* Get the session first */
        pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
        pci_addr = &pci_dev->addr;
@@ -749,6 +840,9 @@ bnxt_ulp_deinit(struct bnxt *bp)
        if (!session)
                return;
 
+       /* clean up default flows */
+       bnxt_ulp_destroy_df_rules(bp, true);
+
        /* clean up regular flows */
        ulp_flow_db_flush_flows(bp->ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
 
@@ -770,6 +864,19 @@ bnxt_ulp_deinit(struct bnxt *bp)
        /* Delete the Port database */
        ulp_port_db_deinit(bp->ulp_ctx);
 
+       /* Disable NAT feature */
+       (void)bnxt_ulp_global_cfg_update(bp, TF_DIR_RX, TF_TUNNEL_ENCAP,
+                                        TF_TUNNEL_ENCAP_NAT,
+                                        (BNXT_ULP_NAT_INNER_L2_HEADER_SMAC |
+                                         BNXT_ULP_NAT_INNER_L2_HEADER_DMAC),
+                                        0);
+
+       (void)bnxt_ulp_global_cfg_update(bp, TF_DIR_TX, TF_TUNNEL_ENCAP,
+                                        TF_TUNNEL_ENCAP_NAT,
+                                        (BNXT_ULP_NAT_INNER_L2_HEADER_SMAC |
+                                         BNXT_ULP_NAT_INNER_L2_HEADER_DMAC),
+                                        0);
+
        /* Delete the ulp context and tf session */
        ulp_ctx_detach(bp, session);
 
@@ -927,6 +1034,7 @@ bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev)
 
        if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) {
                struct bnxt_vf_representor *vfr = dev->data->dev_private;
+
                bp = vfr->parent_dev->data->dev_private;
        }
 
@@ -1007,3 +1115,15 @@ bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx)
 
        return ulp_ctx->cfg_data->fc_info;
 }
+
+/* Function to get the ulp flags from the ulp context. */
+int32_t
+bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx,
+                                 uint32_t *flags)
+{
+       if (!ulp_ctx || !ulp_ctx->cfg_data)
+               return -1;
+
+       *flags =  ulp_ctx->cfg_data->ulp_flags;
+       return 0;
+}