+ bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
+
+ return rc;
+}
+
+void
+bnxt_ulp_destroy_df_rules(struct bnxt *bp, bool global)
+{
+ struct bnxt_ulp_df_rule_info *info;
+ uint8_t port_id;
+
+ 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 per port */
+ if (!global) {
+ port_id = bp->eth_dev->data->port_id;
+ info = &bp->ulp_ctx->cfg_data->df_rule_info[port_id];
+ if (!info->valid)
+ return;
+
+ ulp_default_flow_destroy(bp->eth_dev,
+ info->def_port_flow_id);
+ memset(info, 0, sizeof(struct bnxt_ulp_df_rule_info));
+ return;
+ }
+
+ /* Delete default rules for all ports */
+ for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) {
+ info = &bp->ulp_ctx->cfg_data->df_rule_info[port_id];
+ if (!info->valid)
+ continue;
+
+ ulp_default_flow_destroy(bp->eth_dev,
+ info->def_port_flow_id);
+ memset(info, 0, sizeof(struct bnxt_ulp_df_rule_info));
+ }
+}
+
+static int32_t
+bnxt_create_port_app_df_rule(struct bnxt *bp, uint8_t flow_type,
+ uint32_t *flow_id)
+{
+ uint16_t port_id = bp->eth_dev->data->port_id;
+ struct ulp_tlv_param param_list[] = {
+ {
+ .type = BNXT_ULP_DF_PARAM_TYPE_DEV_PORT_ID,
+ .length = 2,
+ .value = {(port_id >> 8) & 0xff, port_id & 0xff}
+ },
+ {
+ .type = BNXT_ULP_DF_PARAM_TYPE_LAST,
+ .length = 0,
+ .value = {0}
+ }
+ };
+
+ if (!flow_type) {
+ *flow_id = 0;
+ return 0;
+ }
+ return ulp_default_flow_create(bp->eth_dev, param_list, flow_type,
+ flow_id);
+}
+
+int32_t
+bnxt_ulp_create_df_rules(struct bnxt *bp)
+{
+ struct bnxt_ulp_df_rule_info *info;
+ uint8_t port_id;
+ int rc = 0;
+
+ if (!BNXT_TRUFLOW_EN(bp) ||
+ BNXT_ETH_DEV_IS_REPRESENTOR(bp->eth_dev) || !bp->ulp_ctx)
+ return 0;
+
+ port_id = bp->eth_dev->data->port_id;
+ info = &bp->ulp_ctx->cfg_data->df_rule_info[port_id];
+ rc = bnxt_create_port_app_df_rule(bp,
+ BNXT_ULP_DF_TPL_DEFAULT_UPLINK_PORT,
+ &info->def_port_flow_id);
+ if (rc) {
+ BNXT_TF_DBG(ERR,
+ "Failed to create port to app default rule\n");
+ return rc;
+ }
+
+ rc = ulp_default_flow_db_cfa_action_get(bp->ulp_ctx,
+ info->def_port_flow_id,
+ &bp->tx_cfa_action);
+ if (rc)
+ bp->tx_cfa_action = 0;
+ info->valid = true;
+ return 0;
+}
+
+static int32_t
+bnxt_create_port_vfr_default_rule(struct bnxt *bp,
+ uint8_t flow_type,
+ uint16_t vfr_port_id,
+ uint32_t *flow_id)
+{
+ struct ulp_tlv_param param_list[] = {
+ {
+ .type = BNXT_ULP_DF_PARAM_TYPE_DEV_PORT_ID,
+ .length = 2,
+ .value = {(vfr_port_id >> 8) & 0xff, vfr_port_id & 0xff}
+ },
+ {
+ .type = BNXT_ULP_DF_PARAM_TYPE_LAST,
+ .length = 0,
+ .value = {0}
+ }
+ };
+ return ulp_default_flow_create(bp->eth_dev, param_list, flow_type,
+ flow_id);
+}
+
+int32_t
+bnxt_ulp_create_vfr_default_rules(struct rte_eth_dev *vfr_ethdev)
+{
+ struct bnxt_ulp_vfr_rule_info *info;
+ struct bnxt_representor *vfr = vfr_ethdev->data->dev_private;
+ struct rte_eth_dev *parent_dev = vfr->parent_dev;
+ struct bnxt *bp = parent_dev->data->dev_private;
+ uint16_t vfr_port_id = vfr_ethdev->data->port_id;
+ uint8_t port_id;
+ int rc;
+
+ if (!bp || !BNXT_TRUFLOW_EN(bp))
+ return 0;
+
+ port_id = vfr_ethdev->data->port_id;
+ info = bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(bp->ulp_ctx, port_id);
+
+ if (!info) {
+ BNXT_TF_DBG(ERR, "Failed to get vfr ulp context\n");
+ return -EINVAL;
+ }
+
+ if (info->valid) {
+ BNXT_TF_DBG(ERR, "VFR already allocated\n");
+ return -EINVAL;
+ }
+
+ memset(info, 0, sizeof(struct bnxt_ulp_vfr_rule_info));
+ rc = bnxt_create_port_vfr_default_rule(bp, BNXT_ULP_DF_TPL_DEFAULT_VFR,
+ vfr_port_id,
+ &info->vfr_flow_id);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to create VFR default rule\n");
+ goto error;
+ }
+ rc = ulp_default_flow_db_cfa_action_get(bp->ulp_ctx,
+ info->vfr_flow_id,
+ &vfr->vfr_tx_cfa_action);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to get the tx cfa action\n");
+ goto error;
+ }
+
+ /* Update the other details */
+ info->valid = true;
+ info->parent_port_id = bp->eth_dev->data->port_id;
+ return 0;