+/*
+ * 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 = { 0 };
+
+ /* 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;
+}
+
+/* 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;
+
+ /* it is assumed that port is either TVF or PF */
+ if (ulp_port_db_port_func_id_get(bp->ulp_ctx,
+ bp->eth_dev->data->port_id,
+ &func_id)) {
+ BNXT_TF_DBG(ERR, "Invalid argument\n");
+ return;
+ }
+ (void)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;
+ uint16_t port_id;
+ struct rte_eth_dev *vfr_eth_dev;
+ struct bnxt_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->vfr_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 deinit'ed by dpdk. This function is called
+ * and this function clears the ULP context and rest of the
+ * infrastructure associated with it.
+ */
+static void
+bnxt_ulp_deinit(struct bnxt *bp,
+ struct bnxt_ulp_session_state *session)
+{
+ bool ha_enabled;
+
+ if (!bp->ulp_ctx || !bp->ulp_ctx->cfg_data)
+ return;
+
+ ha_enabled = bnxt_ulp_cntxt_ha_enabled(bp->ulp_ctx);
+ if (ha_enabled && session->session_opened) {
+ int32_t rc = ulp_ha_mgr_close(bp->ulp_ctx);
+ if (rc)
+ BNXT_TF_DBG(ERR, "Failed to close HA (%d)\n", rc);
+ }
+
+ /* clean up default flows */
+ bnxt_ulp_destroy_df_rules(bp, true);
+
+ /* clean up default VFR flows */
+ bnxt_ulp_destroy_vfr_default_rules(bp, true);
+
+ /* clean up regular flows */
+ ulp_flow_db_flush_flows(bp->ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR);
+
+ /* 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_OUTER_MOST_FLAGS, 0);
+
+ (void)bnxt_ulp_global_cfg_update(bp, TF_DIR_TX, TF_TUNNEL_ENCAP,
+ TF_TUNNEL_ENCAP_NAT,
+ BNXT_ULP_NAT_OUTER_MOST_FLAGS, 0);
+
+ /* free the flow db lock */
+ pthread_mutex_destroy(&bp->ulp_ctx->cfg_data->flow_db_lock);
+
+ if (ha_enabled)
+ ulp_ha_mgr_deinit(bp->ulp_ctx);
+
+ /* 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");
+}
+