/*
* Allow the deletion of context only for the bnxt device that
- * created the session
- * TBD - The implementation of the function should change to
- * using the reference count once tf_session_attach functionality
- * is fixed.
+ * created the session.
*/
bool
ulp_ctx_deinit_allowed(void *ptr)
{
struct bnxt *bp = (struct bnxt *)ptr;
- if (!bp)
- return 0;
+ if (!bp || !bp->ulp_ctx || !bp->ulp_ctx->cfg_data)
+ return false;
- if (&bp->tfp == bp->ulp_ctx->g_tfp)
- return 1;
+ if (!bp->ulp_ctx->cfg_data->ref_cnt) {
+ BNXT_TF_DBG(DEBUG, "ulp ctx shall initiate deinit\n");
+ return true;
+ }
- return 0;
+ return false;
}
/*
params.ctrl_chan_name, rc);
return -EINVAL;
}
- session->session_opened = 1;
- session->g_tfp = &bp->tfp;
+ if (!session->session_opened) {
+ session->session_opened = 1;
+ session->g_tfp = &bp->tfp;
+ }
return rc;
}
tf_close_session(&bp->tfp);
session->session_opened = 0;
session->g_tfp = NULL;
- bp->ulp_ctx->g_tfp = NULL;
}
static void
if (!ulp_ctx || !ulp_ctx->cfg_data)
return -EINVAL;
- /* Free the resources for the last device */
- if (!ulp_ctx_deinit_allowed(bp))
- return rc;
-
tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
if (!tfp) {
BNXT_TF_DBG(ERR, "Failed to get the truflow pointer\n");
ulp_ctx_deinit(struct bnxt *bp,
struct bnxt_ulp_session_state *session)
{
- if (!session || !bp) {
- BNXT_TF_DBG(ERR, "Invalid Arguments\n");
- return -EINVAL;
- }
-
/* close the tf session */
ulp_ctx_session_close(bp, session);
struct bnxt_ulp_data *ulp_data;
int32_t rc = 0;
- if (!session || !bp) {
- BNXT_TF_DBG(ERR, "Invalid Arguments\n");
- return -EINVAL;
- }
-
/* Allocate memory to hold ulp context data. */
ulp_data = rte_zmalloc("bnxt_ulp_data",
sizeof(struct bnxt_ulp_data), 0);
/* Open the ulp session. */
rc = ulp_ctx_session_open(bp, session);
if (rc) {
+ session->session_opened = 1;
(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, &bp->tfp);
return rc;
}
uint32_t dev_id;
if (!bp->max_num_kflows)
- return -EINVAL;
+ return 0;
if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
}
static int32_t
-ulp_ctx_attach(struct bnxt_ulp_context *ulp_ctx,
+ulp_ctx_attach(struct bnxt *bp,
struct bnxt_ulp_session_state *session)
{
- if (!ulp_ctx || !session) {
- BNXT_TF_DBG(ERR, "Invalid Arguments\n");
- return -EINVAL;
- }
+ int32_t rc = 0;
/* Increment the ulp context data reference count usage. */
- ulp_ctx->cfg_data = session->cfg_data;
- ulp_ctx->cfg_data->ref_cnt++;
+ bp->ulp_ctx->cfg_data = session->cfg_data;
+ bp->ulp_ctx->cfg_data->ref_cnt++;
- /* TBD call TF_session_attach. */
- ulp_ctx->g_tfp = session->g_tfp;
- return 0;
-}
-
-static int32_t
-ulp_ctx_detach(struct bnxt *bp,
- struct bnxt_ulp_session_state *session)
-{
- struct bnxt_ulp_context *ulp_ctx;
+ /* update the session details in bnxt tfp */
+ bp->tfp.session = session->g_tfp->session;
- if (!bp || !session) {
- BNXT_TF_DBG(ERR, "Invalid Arguments\n");
- return -EINVAL;
+ /* Create a TF Client */
+ rc = ulp_ctx_session_open(bp, session);
+ if (rc) {
+ PMD_DRV_LOG(ERR, "Failed to open ctxt session, rc:%d\n", rc);
+ bp->tfp.session = NULL;
+ return rc;
}
- ulp_ctx = bp->ulp_ctx;
- if (!ulp_ctx->cfg_data)
- return 0;
-
- /* TBD call TF_session_detach */
+ bnxt_ulp_cntxt_tfp_set(bp->ulp_ctx, &bp->tfp);
+ return rc;
+}
- /* Increment the ulp context data reference count usage. */
- if (ulp_ctx->cfg_data->ref_cnt >= 1) {
- ulp_ctx->cfg_data->ref_cnt--;
- if (ulp_ctx_deinit_allowed(bp))
- ulp_ctx_deinit(bp, session);
- ulp_ctx->cfg_data = NULL;
- ulp_ctx->g_tfp = NULL;
- return 0;
+static void
+ulp_ctx_detach(struct bnxt *bp)
+{
+ if (bp->tfp.session) {
+ tf_close_session(&bp->tfp);
+ bp->tfp.session = NULL;
}
- BNXT_TF_DBG(ERR, "context deatach on invalid data\n");
- return 0;
}
/*
struct rte_pci_device *pci_dev;
struct rte_pci_addr *pci_addr;
struct bnxt_ulp_session_state *session;
+ int rc = 0;
if (!bp)
return NULL;
/* Add it to the queue */
session->pci_info.domain = pci_addr->domain;
session->pci_info.bus = pci_addr->bus;
- pthread_mutex_init(&session->bnxt_ulp_mutex, NULL);
+ rc = pthread_mutex_init(&session->bnxt_ulp_mutex, NULL);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "mutex create failed\n");
+ pthread_mutex_unlock(&bnxt_ulp_global_mutex);
+ return NULL;
+ }
STAILQ_INSERT_TAIL(&bnxt_ulp_session_list,
session, next);
}
return rc;
}
+/* Internal function to delete all the flows belonging to the given port */
+static void
+bnxt_ulp_flush_port_flows(struct bnxt *bp)
+{
+ uint16_t func_id;
+
+ func_id = bnxt_get_fw_func_id(bp->eth_dev->data->port_id,
+ BNXT_ULP_INTF_TYPE_INVALID);
+ ulp_flow_db_function_flow_flush(bp->ulp_ctx, func_id);
+}
+
+/* Internal function to delete the VFR default flows */
+static void
+bnxt_ulp_destroy_vfr_default_rules(struct bnxt *bp, bool global)
+{
+ struct bnxt_ulp_vfr_rule_info *info;
+ uint8_t port_id;
+ struct rte_eth_dev *vfr_eth_dev;
+ struct bnxt_vf_representor *vfr_bp;
+
+ if (!BNXT_TRUFLOW_EN(bp) || BNXT_ETH_DEV_IS_REPRESENTOR(bp->eth_dev))
+ return;
+
+ if (!bp->ulp_ctx || !bp->ulp_ctx->cfg_data)
+ return;
+
+ /* Delete default rules for all ports */
+ for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) {
+ info = &bp->ulp_ctx->cfg_data->vfr_rule_info[port_id];
+ if (!info->valid)
+ continue;
+
+ if (!global && info->parent_port_id !=
+ bp->eth_dev->data->port_id)
+ continue;
+
+ /* Destroy the flows */
+ ulp_default_flow_destroy(bp->eth_dev, info->rep2vf_flow_id);
+ ulp_default_flow_destroy(bp->eth_dev, info->vf2rep_flow_id);
+ /* Clean up the tx action pointer */
+ vfr_eth_dev = &rte_eth_devices[port_id];
+ if (vfr_eth_dev) {
+ vfr_bp = vfr_eth_dev->data->dev_private;
+ vfr_bp->vfr_tx_cfa_action = 0;
+ }
+ memset(info, 0, sizeof(struct bnxt_ulp_vfr_rule_info));
+ }
+}
+
/*
- * When a port is initialized by dpdk. This functions is called
- * and this function initializes the ULP context and rest of the
+ * When a port is deinit'ed by dpdk. This function is called
+ * and this function clears the ULP context and rest of the
* infrastructure associated with it.
*/
-int32_t
-bnxt_ulp_init(struct bnxt *bp)
+static void
+bnxt_ulp_deinit(struct bnxt *bp,
+ struct bnxt_ulp_session_state *session)
{
- struct bnxt_ulp_session_state *session;
- bool init;
- int rc;
+ if (!bp->ulp_ctx || !bp->ulp_ctx->cfg_data)
+ return;
- if (!BNXT_TRUFLOW_EN(bp))
- return 0;
+ /* clean up default flows */
+ bnxt_ulp_destroy_df_rules(bp, true);
- if (bp->ulp_ctx) {
- BNXT_TF_DBG(DEBUG, "ulp ctx already allocated\n");
- return -EINVAL;
- }
+ /* clean up default VFR flows */
+ bnxt_ulp_destroy_vfr_default_rules(bp, true);
- /*
- * Multiple uplink ports can be associated with a single vswitch.
- * Make sure only the port that is started first will initialize
- * the TF session.
- */
- session = ulp_session_init(bp, &init);
- if (!session) {
- BNXT_TF_DBG(ERR, "Failed to initialize the tf session\n");
- return -EINVAL;
- }
+ /* clean up regular flows */
+ ulp_flow_db_flush_flows(bp->ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
- 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;
- }
+ /* cleanup the eem table scope */
+ ulp_eem_tbl_scope_deinit(bp, bp->ulp_ctx);
- /*
- * 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);
- if (rc) {
- BNXT_TF_DBG(ERR,
- "Failed to attach the ulp context\n");
- ulp_session_deinit(session);
- rte_free(bp->ulp_ctx);
- return rc;
- }
+ /* cleanup the flow database */
+ ulp_flow_db_deinit(bp->ulp_ctx);
- /* Update bnxt driver flags */
- rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
- if (rc) {
- BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
- ulp_ctx_detach(bp, session);
- ulp_session_deinit(session);
- rte_free(bp->ulp_ctx);
- return rc;
- }
+ /* Delete the Mark database */
+ ulp_mark_db_deinit(bp->ulp_ctx);
- /* update the port database */
- rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
- 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;
- }
+ /* 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);
+
+ /* 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 and free the ulp context */
+ ulp_ctx_deinit(bp, session);
+ BNXT_TF_DBG(DEBUG, "ulp ctx has been deinitialized\n");
+}
+
+/*
+ * When a port is initialized by dpdk. This functions is called
+ * and this function initializes the ULP context and rest of the
+ * infrastructure associated with it.
+ */
+static int32_t
+bnxt_ulp_init(struct bnxt *bp,
+ struct bnxt_ulp_session_state *session)
+{
+ int rc;
/* Allocate and Initialize the ulp context. */
rc = ulp_ctx_init(bp, session);
/* Initialize ulp dparms with values devargs passed */
rc = ulp_dparms_init(bp, bp->ulp_ctx);
-
- /* create the port database */
- 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;
- }
-
- /* Update bnxt driver flags */
- rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
if (rc) {
- BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
+ BNXT_TF_DBG(ERR, "Failed to initialize the dparms\n");
goto jump_to_error;
}
- /* update the port database */
- rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
+ /* create the port database */
+ rc = ulp_port_db_init(bp->ulp_ctx, bp->port_cnt);
if (rc) {
- BNXT_TF_DBG(ERR, "Failed to update port database\n");
+ BNXT_TF_DBG(ERR, "Failed to create the port database\n");
goto jump_to_error;
}
BNXT_TF_DBG(ERR, "Failed to set tx global configuration\n");
goto jump_to_error;
}
-
+ BNXT_TF_DBG(DEBUG, "ulp ctx has been initialized\n");
return rc;
jump_to_error:
- bnxt_ulp_deinit(bp);
- return -ENOMEM;
+ bnxt_ulp_deinit(bp, session);
+ return rc;
}
-/* Below are the access functions to access internal data of ulp context. */
+/*
+ * When a port is initialized by dpdk. This functions sets up
+ * the port specific details.
+ */
+int32_t
+bnxt_ulp_port_init(struct bnxt *bp)
+{
+ struct bnxt_ulp_session_state *session;
+ bool initialized;
+ int32_t rc = 0;
+
+ if (!bp || !BNXT_TRUFLOW_EN(bp))
+ return rc;
+
+ if (!BNXT_PF(bp) && !BNXT_VF_IS_TRUSTED(bp)) {
+ BNXT_TF_DBG(ERR,
+ "Skip ulp init for port: %d, not a TVF or PF\n",
+ bp->eth_dev->data->port_id);
+ return rc;
+ }
+
+ if (bp->ulp_ctx) {
+ BNXT_TF_DBG(DEBUG, "ulp ctx already allocated\n");
+ return rc;
+ }
+
+ 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");
+ return -ENOMEM;
+ }
+
+ /*
+ * Multiple uplink ports can be associated with a single vswitch.
+ * Make sure only the port that is started first will initialize
+ * the TF session.
+ */
+ session = ulp_session_init(bp, &initialized);
+ if (!session) {
+ BNXT_TF_DBG(ERR, "Failed to initialize the tf session\n");
+ rc = -EIO;
+ goto jump_to_error;
+ }
+
+ if (initialized) {
+ /*
+ * If ULP is already initialized for a specific domain then
+ * simply assign the ulp context to this rte_eth_dev.
+ */
+ rc = ulp_ctx_attach(bp, session);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to attach the ulp context\n");
+ goto jump_to_error;
+ }
+ } else {
+ rc = bnxt_ulp_init(bp, session);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to initialize the ulp init\n");
+ goto jump_to_error;
+ }
+ }
+
+ /* Update bnxt driver flags */
+ rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
+ goto jump_to_error;
+ }
+
+ /* update the port database for the given interface */
+ rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to update port database\n");
+ goto jump_to_error;
+ }
+ /* create the default rules */
+ bnxt_ulp_create_df_rules(bp);
+ BNXT_TF_DBG(DEBUG, "ULP Port:%d created and initialized\n",
+ bp->eth_dev->data->port_id);
+ return rc;
+
+jump_to_error:
+ bnxt_ulp_port_deinit(bp);
+ return rc;
+}
/*
- * When a port is deinit'ed by dpdk. This function is called
- * and this function clears the ULP context and rest of the
- * infrastructure associated with it.
+ * When a port is de-initialized by dpdk. This functions clears up
+ * the port specific details.
*/
void
-bnxt_ulp_deinit(struct bnxt *bp)
+bnxt_ulp_port_deinit(struct bnxt *bp)
{
- struct bnxt_ulp_session_state *session;
- struct rte_pci_device *pci_dev;
- struct rte_pci_addr *pci_addr;
+ struct bnxt_ulp_session_state *session;
+ struct rte_pci_device *pci_dev;
+ struct rte_pci_addr *pci_addr;
if (!BNXT_TRUFLOW_EN(bp))
return;
- /* Get the session first */
+ if (!BNXT_PF(bp) && !BNXT_VF_IS_TRUSTED(bp)) {
+ BNXT_TF_DBG(ERR,
+ "Skip ULP deinit port:%d, not a TVF or PF\n",
+ bp->eth_dev->data->port_id);
+ return;
+ }
+
+ if (!bp->ulp_ctx) {
+ BNXT_TF_DBG(DEBUG, "ulp ctx already de-allocated\n");
+ return;
+ }
+
+ BNXT_TF_DBG(DEBUG, "ULP Port:%d destroyed\n",
+ bp->eth_dev->data->port_id);
+
+ /* Get the session details */
pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
pci_addr = &pci_dev->addr;
pthread_mutex_lock(&bnxt_ulp_global_mutex);
pthread_mutex_unlock(&bnxt_ulp_global_mutex);
/* session not found then just exit */
- if (!session)
+ if (!session) {
+ /* Free the ulp context */
+ rte_free(bp->ulp_ctx);
+ bp->ulp_ctx = NULL;
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);
-
- /* cleanup the eem table scope */
- ulp_eem_tbl_scope_deinit(bp, bp->ulp_ctx);
-
- /* cleanup the flow database */
- ulp_flow_db_deinit(bp->ulp_ctx);
-
- /* Delete the Mark database */
- ulp_mark_db_deinit(bp->ulp_ctx);
-
- /* 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);
-
- /* 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);
+ /* Check the reference count to deinit or deattach*/
+ if (bp->ulp_ctx->cfg_data && bp->ulp_ctx->cfg_data->ref_cnt) {
+ bp->ulp_ctx->cfg_data->ref_cnt--;
+ if (bp->ulp_ctx->cfg_data->ref_cnt) {
+ /* free the port details */
+ /* Free the default flow rule associated to this port */
+ bnxt_ulp_destroy_df_rules(bp, false);
+ bnxt_ulp_destroy_vfr_default_rules(bp, false);
- (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);
+ /* free flows associated with this port */
+ bnxt_ulp_flush_port_flows(bp);
- /* Delete the ulp context and tf session */
- ulp_ctx_detach(bp, session);
+ /* close the session associated with this port */
+ ulp_ctx_detach(bp);
+ } else {
+ /* Perform ulp ctx deinit */
+ bnxt_ulp_deinit(bp, session);
+ }
+ }
- /* Finally delete the bnxt session*/
+ /* clean up the session */
ulp_session_deinit(session);
+ /* Free the ulp context */
rte_free(bp->ulp_ctx);
-
bp->ulp_ctx = NULL;
}
+/* Below are the access functions to access internal data of ulp context. */
/* Function to set the Mark DB into the context */
int32_t
bnxt_ulp_cntxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
return -EINVAL;
}
- /* TBD The tfp should be removed once tf_attach is implemented. */
ulp->g_tfp = tfp;
return 0;
}
BNXT_TF_DBG(ERR, "Invalid arguments\n");
return NULL;
}
- /* TBD The tfp should be removed once tf_attach is implemented. */
return ulp->g_tfp;
}
*flags = ulp_ctx->cfg_data->ulp_flags;
return 0;
}
+
+/* Function to get the ulp vfr info from the ulp context. */
+struct bnxt_ulp_vfr_rule_info*
+bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx,
+ uint32_t port_id)
+{
+ if (!ulp_ctx || !ulp_ctx->cfg_data || port_id >= RTE_MAX_ETHPORTS)
+ return NULL;
+
+ return &ulp_ctx->cfg_data->vfr_rule_info[port_id];
+}