net/bnxt: enable filter ctrl ops for port representor
[dpdk.git] / drivers / net / bnxt / tf_ulp / bnxt_ulp.c
index 4835b95..397d0a9 100644 (file)
@@ -18,6 +18,7 @@
 #include "ulp_template_db_enum.h"
 #include "ulp_template_struct.h"
 #include "ulp_mark_mgr.h"
+#include "ulp_fc_mgr.h"
 #include "ulp_flow_db.h"
 #include "ulp_mapper.h"
 #include "ulp_port_db.h"
@@ -102,6 +103,9 @@ ulp_ctx_session_open(struct bnxt *bp,
        /* EM */
        resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_EM_RECORD] = 2048;
 
+       /* EEM */
+       resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
+
        /** TX **/
        /* Identifiers */
        resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_L2_CTXT] = 8;
@@ -126,9 +130,11 @@ ulp_ctx_session_open(struct bnxt *bp,
        resources->em_cnt[TF_DIR_TX].cnt[TF_EM_TBL_TYPE_EM_RECORD] = 8;
 
        /* EEM */
-       resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
        resources->em_cnt[TF_DIR_TX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
 
+       /* SP */
+       resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_SP_SMAC_IPV4] = 128;
+
        rc = tf_open_session(&bp->tfp, &params);
        if (rc) {
                BNXT_TF_DBG(ERR, "Failed to open TF session - %s, rc = %d\n",
@@ -213,8 +219,27 @@ static int32_t
 ulp_eem_tbl_scope_init(struct bnxt *bp)
 {
        struct tf_alloc_tbl_scope_parms params = {0};
+       uint32_t dev_id;
+       struct bnxt_ulp_device_params *dparms;
        int rc;
 
+       /* Get the dev specific number of flows that needed to be supported. */
+       if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
+               BNXT_TF_DBG(ERR, "Invalid device id\n");
+               return -EINVAL;
+       }
+
+       dparms = bnxt_ulp_device_params_get(dev_id);
+       if (!dparms) {
+               BNXT_TF_DBG(ERR, "could not fetch the device params\n");
+               return -ENODEV;
+       }
+
+       if (dparms->flow_mem_type != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
+               BNXT_TF_DBG(INFO, "Table Scope alloc is not required\n");
+               return 0;
+       }
+
        bnxt_init_tbl_scope_parms(bp, &params);
 
        rc = tf_alloc_tbl_scope(&bp->tfp, &params);
@@ -240,6 +265,8 @@ ulp_eem_tbl_scope_deinit(struct bnxt *bp, struct bnxt_ulp_context *ulp_ctx)
        struct tf_free_tbl_scope_parms  params = {0};
        struct tf                       *tfp;
        int32_t                         rc = 0;
+       struct bnxt_ulp_device_params *dparms;
+       uint32_t dev_id;
 
        if (!ulp_ctx || !ulp_ctx->cfg_data)
                return -EINVAL;
@@ -254,6 +281,23 @@ ulp_eem_tbl_scope_deinit(struct bnxt *bp, struct bnxt_ulp_context *ulp_ctx)
                return -EINVAL;
        }
 
+       /* Get the dev specific number of flows that needed to be supported. */
+       if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
+               BNXT_TF_DBG(ERR, "Invalid device id\n");
+               return -EINVAL;
+       }
+
+       dparms = bnxt_ulp_device_params_get(dev_id);
+       if (!dparms) {
+               BNXT_TF_DBG(ERR, "could not fetch the device params\n");
+               return -ENODEV;
+       }
+
+       if (dparms->flow_mem_type != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
+               BNXT_TF_DBG(INFO, "Table Scope free is not required\n");
+               return 0;
+       }
+
        rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, &params.tbl_scope_id);
        if (rc) {
                BNXT_TF_DBG(ERR, "Failed to get the table scope id\n");
@@ -550,7 +594,7 @@ bnxt_ulp_init(struct bnxt *bp)
        int rc;
 
        if (bp->ulp_ctx) {
-               BNXT_TF_DBG(ERR, "ulp ctx already allocated\n");
+               BNXT_TF_DBG(DEBUG, "ulp ctx already allocated\n");
                return -EINVAL;
        }
 
@@ -620,7 +664,7 @@ bnxt_ulp_init(struct bnxt *bp)
        rc = ulp_dparms_init(bp, bp->ulp_ctx);
 
        /* create the port database */
-       rc = ulp_port_db_init(bp->ulp_ctx);
+       rc = ulp_port_db_init(bp->ulp_ctx, bp->port_cnt);
        if (rc) {
                BNXT_TF_DBG(ERR, "Failed to create the port database\n");
                goto jump_to_error;
@@ -667,6 +711,12 @@ bnxt_ulp_init(struct bnxt *bp)
                goto jump_to_error;
        }
 
+       rc = ulp_fc_mgr_init(bp->ulp_ctx);
+       if (rc) {
+               BNXT_TF_DBG(ERR, "Failed to initialize ulp flow counter mgr\n");
+               goto jump_to_error;
+       }
+
        return rc;
 
 jump_to_error:
@@ -714,6 +764,9 @@ bnxt_ulp_deinit(struct bnxt *bp)
        /* cleanup the ulp mapper */
        ulp_mapper_deinit(bp->ulp_ctx);
 
+       /* Delete the Flow Counter Manager */
+       ulp_fc_mgr_deinit(bp->ulp_ctx);
+
        /* Delete the Port database */
        ulp_port_db_deinit(bp->ulp_ctx);
 
@@ -870,9 +923,13 @@ bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context    *ulp_ctx)
 struct bnxt_ulp_context        *
 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev     *dev)
 {
-       struct bnxt     *bp;
+       struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
+
+       if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) {
+               struct bnxt_vf_representor *vfr = dev->data->dev_private;
+               bp = vfr->parent_dev->data->dev_private;
+       }
 
-       bp = (struct bnxt *)dev->data->dev_private;
        if (!bp) {
                BNXT_TF_DBG(ERR, "Bnxt private data is not initialized\n");
                return NULL;
@@ -925,3 +982,28 @@ bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context    *ulp_ctx)
 
        return ulp_ctx->cfg_data->port_db;
 }
+
+/* Function to set the flow counter info into the context */
+int32_t
+bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx,
+                               struct bnxt_ulp_fc_info *ulp_fc_info)
+{
+       if (!ulp_ctx || !ulp_ctx->cfg_data) {
+               BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
+               return -EINVAL;
+       }
+
+       ulp_ctx->cfg_data->fc_info = ulp_fc_info;
+
+       return 0;
+}
+
+/* Function to retrieve the flow counter info from the context. */
+struct bnxt_ulp_fc_info *
+bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx)
+{
+       if (!ulp_ctx || !ulp_ctx->cfg_data)
+               return NULL;
+
+       return ulp_ctx->cfg_data->fc_info;
+}