net/bnxt: fix allocation of ULP context
authorMike Baucom <michael.baucom@broadcom.com>
Tue, 12 May 2020 20:25:28 +0000 (16:25 -0400)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 18 May 2020 18:35:57 +0000 (20:35 +0200)
Fix to allocate bnxt ulp context when TRUFLOW is enabled.
This patch reduces the size of struct bnxt.

Fixes: 313ac35ac701 ("net/bnxt: support ULP session manager init")

Signed-off-by: Mike Baucom <michael.baucom@broadcom.com>
Reviewed-by: Venkat Duvvuru <venkatkumar.duvvuru@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
drivers/net/bnxt/bnxt.h
drivers/net/bnxt/bnxt_ethdev.c
drivers/net/bnxt/bnxt_rxr.c
drivers/net/bnxt/tf_ulp/bnxt_ulp.c

index 403b23f..446764c 100644 (file)
@@ -561,6 +561,7 @@ struct bnxt {
 #define BNXT_FLAG_RX_VECTOR_PKT_MODE           BIT(24)
 #define BNXT_FLAG_FLOW_XSTATS_EN               BIT(25)
 #define BNXT_FLAG_DFLT_MAC_SET                 BIT(26)
+#define BNXT_FLAG_TRUFLOW_EN                   BIT(27)
 #define BNXT_PF(bp)            (!((bp)->flags & BNXT_FLAG_VF))
 #define BNXT_VF(bp)            ((bp)->flags & BNXT_FLAG_VF)
 #define BNXT_NPAR(bp)          ((bp)->flags & BNXT_FLAG_NPAR_PF)
@@ -575,6 +576,7 @@ struct bnxt {
 #define BNXT_HAS_RING_GRPS(bp) (!BNXT_CHIP_THOR(bp))
 #define BNXT_FLOW_XSTATS_EN(bp)        ((bp)->flags & BNXT_FLAG_FLOW_XSTATS_EN)
 #define BNXT_HAS_DFLT_MAC_SET(bp)      ((bp)->flags & BNXT_FLAG_DFLT_MAC_SET)
+#define BNXT_TRUFLOW_EN(bp)    ((bp)->flags & BNXT_FLAG_TRUFLOW_EN)
 
        uint32_t                fw_cap;
 #define BNXT_FW_CAP_HOT_RESET          BIT(0)
@@ -720,8 +722,7 @@ struct bnxt {
        uint16_t                port_svif;
 
        struct tf               tfp;
-       struct bnxt_ulp_context ulp_ctx;
-       uint8_t                 truflow;
+       struct bnxt_ulp_context *ulp_ctx;
        struct bnxt_flow_stat_info *flow_stat;
        uint8_t                 flow_xstat;
 };
index 77492f8..ae495da 100644 (file)
@@ -1095,7 +1095,7 @@ bnxt_receive_function(struct rte_eth_dev *eth_dev)
                DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
                DEV_RX_OFFLOAD_RSS_HASH |
                DEV_RX_OFFLOAD_VLAN_FILTER)) &&
-           !bp->truflow) {
+           !BNXT_TRUFLOW_EN(bp)) {
                PMD_DRV_LOG(INFO, "Using vector mode receive for port %d\n",
                            eth_dev->data->port_id);
                bp->flags |= BNXT_FLAG_RX_VECTOR_PKT_MODE;
@@ -1221,7 +1221,7 @@ static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
        bnxt_schedule_fw_health_check(bp);
        pthread_mutex_unlock(&bp->def_cp_lock);
 
-       if (bp->truflow)
+       if (BNXT_TRUFLOW_EN(bp))
                bnxt_ulp_init(bp);
 
        return 0;
@@ -1267,7 +1267,7 @@ static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
        struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
-       if (bp->truflow)
+       if (BNXT_TRUFLOW_EN(bp))
                bnxt_ulp_deinit(bp);
 
        eth_dev->data->dev_started = 0;
@@ -3647,7 +3647,7 @@ bnxt_filter_ctrl_op(struct rte_eth_dev *dev,
        case RTE_ETH_FILTER_GENERIC:
                if (filter_op != RTE_ETH_FILTER_GET)
                        return -EINVAL;
-               if (bp->truflow)
+               if (BNXT_TRUFLOW_EN(bp))
                        *(const void **)arg = &bnxt_ulp_rte_flow_ops;
                else
                        *(const void **)arg = &bnxt_flow_ops;
@@ -5350,8 +5350,8 @@ bnxt_parse_devarg_truflow(__rte_unused const char *key,
                return -EINVAL;
        }
 
-       bp->truflow = truflow;
-       if (bp->truflow)
+       bp->flags |= BNXT_FLAG_TRUFLOW_EN;
+       if (BNXT_TRUFLOW_EN(bp))
                PMD_DRV_LOG(INFO, "Host-based truflow feature enabled.\n");
 
        return 0;
index 9ecdf5e..d2955ba 100644 (file)
@@ -466,7 +466,7 @@ bnxt_ulp_set_mark_in_mbuf(struct bnxt *bp, struct rx_pkt_cmpl_hi *rxcmp1,
        }
 
        if (cfa_code) {
-               rc = ulp_mark_db_mark_get(&bp->ulp_ctx, gfid,
+               rc = ulp_mark_db_mark_get(bp->ulp_ctx, gfid,
                                          cfa_code, &mark_id);
                if (!rc) {
                        /* Got the mark, write it to the mbuf and return */
@@ -614,7 +614,7 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt,
                mbuf->ol_flags |= PKT_RX_RSS_HASH;
        }
 
-       if (bp->truflow)
+       if (BNXT_TRUFLOW_EN(bp))
                bnxt_ulp_set_mark_in_mbuf(rxq->bp, rxcmp1, mbuf);
        else
                bnxt_set_mark_in_mbuf(rxq->bp, rxcmp1, mbuf);
index a9cc92d..872c1ab 100644 (file)
@@ -44,7 +44,7 @@ ulp_ctx_deinit_allowed(void *ptr)
        if (!bp)
                return 0;
 
-       if (&bp->tfp == bp->ulp_ctx.g_tfp)
+       if (&bp->tfp == bp->ulp_ctx->g_tfp)
                return 1;
 
        return 0;
@@ -103,7 +103,7 @@ ulp_ctx_session_close(struct bnxt *bp,
                tf_close_session(&bp->tfp);
        session->session_opened = 0;
        session->g_tfp = NULL;
-       bp->ulp_ctx.g_tfp = NULL;
+       bp->ulp_ctx->g_tfp = NULL;
 }
 
 static void
@@ -114,7 +114,7 @@ bnxt_init_tbl_scope_parms(struct bnxt *bp,
        uint32_t dev_id;
        int rc;
 
-       rc = bnxt_ulp_cntxt_dev_id_get(&bp->ulp_ctx, &dev_id);
+       rc = bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id);
        if (rc)
                /* TBD: For now, just use default. */
                dparms = 0;
@@ -174,7 +174,7 @@ ulp_eem_tbl_scope_init(struct bnxt *bp)
                return rc;
        }
 
-       rc = bnxt_ulp_cntxt_tbl_scope_id_set(&bp->ulp_ctx, params.tbl_scope_id);
+       rc = bnxt_ulp_cntxt_tbl_scope_id_set(bp->ulp_ctx, params.tbl_scope_id);
        if (rc) {
                BNXT_TF_DBG(ERR, "Unable to set table scope id\n");
                return rc;
@@ -234,7 +234,7 @@ ulp_ctx_deinit(struct bnxt *bp,
        /* Free the contents */
        if (session->cfg_data) {
                rte_free(session->cfg_data);
-               bp->ulp_ctx.cfg_data = NULL;
+               bp->ulp_ctx->cfg_data = NULL;
                session->cfg_data = NULL;
        }
        return 0;
@@ -262,7 +262,7 @@ ulp_ctx_init(struct bnxt *bp,
        }
 
        /* Increment the ulp context data reference count usage. */
-       bp->ulp_ctx.cfg_data = ulp_data;
+       bp->ulp_ctx->cfg_data = ulp_data;
        session->cfg_data = ulp_data;
        ulp_data->ref_cnt++;
 
@@ -272,7 +272,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);
+       bnxt_ulp_cntxt_tfp_set(bp->ulp_ctx, session->g_tfp);
        return rc;
 }
 
@@ -304,7 +304,7 @@ ulp_ctx_detach(struct bnxt *bp,
                BNXT_TF_DBG(ERR, "Invalid Arguments\n");
                return -EINVAL;
        }
-       ulp_ctx = &bp->ulp_ctx;
+       ulp_ctx = bp->ulp_ctx;
 
        if (!ulp_ctx->cfg_data)
                return 0;
@@ -441,6 +441,11 @@ bnxt_ulp_init(struct bnxt *bp)
        bool init;
        int rc;
 
+       if (bp->ulp_ctx) {
+               BNXT_TF_DBG(ERR, "ulp ctx already allocated\n");
+               return -EINVAL;
+       }
+
        /*
         * Multiple uplink ports can be associated with a single vswitch.
         * Make sure only the port that is started first will initialize
@@ -452,22 +457,35 @@ bnxt_ulp_init(struct bnxt *bp)
                return -EINVAL;
        }
 
+       bp->ulp_ctx = rte_zmalloc("bnxt_ulp_ctx",
+                                 sizeof(struct bnxt_ulp_context), 0);
+       if (!bp->ulp_ctx) {
+               BNXT_TF_DBG(ERR, "Failed to allocate ulp ctx\n");
+               ulp_session_deinit(session);
+               return -ENOMEM;
+       }
+
        /*
         * If ULP is already initialized for a specific domain then simply
         * assign the ulp context to this rte_eth_dev.
         */
        if (init) {
-               rc = ulp_ctx_attach(&bp->ulp_ctx, session);
+               rc = ulp_ctx_attach(bp->ulp_ctx, session);
                if (rc) {
                        BNXT_TF_DBG(ERR,
                                    "Failed to attach the ulp context\n");
+                       ulp_session_deinit(session);
+                       rte_free(bp->ulp_ctx);
                        return rc;
                }
                /* update the port database */
-               rc = ulp_port_db_dev_port_intf_update(&bp->ulp_ctx, bp);
+               rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp);
                if (rc) {
                        BNXT_TF_DBG(ERR,
                                    "Failed to update port database\n");
+                       ulp_ctx_detach(bp, session);
+                       ulp_session_deinit(session);
+                       rte_free(bp->ulp_ctx);
                }
                return rc;
        }
@@ -480,28 +498,28 @@ bnxt_ulp_init(struct bnxt *bp)
        }
 
        /* create the port database */
-       rc = ulp_port_db_init(&bp->ulp_ctx);
+       rc = ulp_port_db_init(bp->ulp_ctx);
        if (rc) {
                BNXT_TF_DBG(ERR, "Failed to create the port database\n");
                goto jump_to_error;
        }
 
        /* update the port database */
-       rc = ulp_port_db_dev_port_intf_update(&bp->ulp_ctx, bp);
+       rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp);
        if (rc) {
                BNXT_TF_DBG(ERR, "Failed to update port database\n");
                goto jump_to_error;
        }
 
        /* Create the Mark database. */
-       rc = ulp_mark_db_init(&bp->ulp_ctx);
+       rc = ulp_mark_db_init(bp->ulp_ctx);
        if (rc) {
                BNXT_TF_DBG(ERR, "Failed to create the mark database\n");
                goto jump_to_error;
        }
 
        /* Create the flow database. */
-       rc = ulp_flow_db_init(&bp->ulp_ctx);
+       rc = ulp_flow_db_init(bp->ulp_ctx);
        if (rc) {
                BNXT_TF_DBG(ERR, "Failed to create the flow database\n");
                goto jump_to_error;
@@ -514,7 +532,7 @@ bnxt_ulp_init(struct bnxt *bp)
                goto jump_to_error;
        }
 
-       rc = ulp_mapper_init(&bp->ulp_ctx);
+       rc = ulp_mapper_init(bp->ulp_ctx);
        if (rc) {
                BNXT_TF_DBG(ERR, "Failed to initialize ulp mapper\n");
                goto jump_to_error;
@@ -553,28 +571,30 @@ bnxt_ulp_deinit(struct bnxt *bp)
                return;
 
        /* clean up regular flows */
-       ulp_flow_db_flush_flows(&bp->ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
+       ulp_flow_db_flush_flows(bp->ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
 
        /* cleanup the eem table scope */
-       ulp_eem_tbl_scope_deinit(bp, &bp->ulp_ctx);
+       ulp_eem_tbl_scope_deinit(bp, bp->ulp_ctx);
 
        /* cleanup the flow database */
-       ulp_flow_db_deinit(&bp->ulp_ctx);
+       ulp_flow_db_deinit(bp->ulp_ctx);
 
        /* Delete the Mark database */
-       ulp_mark_db_deinit(&bp->ulp_ctx);
+       ulp_mark_db_deinit(bp->ulp_ctx);
 
        /* cleanup the ulp mapper */
-       ulp_mapper_deinit(&bp->ulp_ctx);
+       ulp_mapper_deinit(bp->ulp_ctx);
 
        /* Delete the Port database */
-       ulp_port_db_deinit(&bp->ulp_ctx);
+       ulp_port_db_deinit(bp->ulp_ctx);
 
        /* Delete the ulp context and tf session */
        ulp_ctx_detach(bp, session);
 
        /* Finally delete the bnxt session*/
        ulp_session_deinit(session);
+
+       rte_free(bp->ulp_ctx);
 }
 
 /* Function to set the Mark DB into the context */
@@ -728,7 +748,7 @@ bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev  *dev)
                BNXT_TF_DBG(ERR, "Bnxt private data is not initialized\n");
                return NULL;
        }
-       return &bp->ulp_ctx;
+       return bp->ulp_ctx;
 }
 
 int32_t