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);
+
/* 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");
goto jump_to_error;
}
+ rc = pthread_mutex_init(&bp->ulp_ctx->cfg_data->flow_db_lock, NULL);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Unable to initialize flow db lock\n");
+ goto jump_to_error;
+ }
+
/* Initialize ulp dparms with values devargs passed */
rc = ulp_dparms_init(bp, bp->ulp_ctx);
if (rc) {
return &ulp_ctx->cfg_data->vfr_rule_info[port_id];
}
+
+/* Function to acquire the flow database lock from the ulp context. */
+int32_t
+bnxt_ulp_cntxt_acquire_fdb_lock(struct bnxt_ulp_context *ulp_ctx)
+{
+ if (!ulp_ctx || !ulp_ctx->cfg_data)
+ return -1;
+
+ if (pthread_mutex_lock(&ulp_ctx->cfg_data->flow_db_lock)) {
+ BNXT_TF_DBG(ERR, "unable to acquire fdb lock\n");
+ return -1;
+ }
+ return 0;
+}
+
+/* Function to release the flow database lock from the ulp context. */
+void
+bnxt_ulp_cntxt_release_fdb_lock(struct bnxt_ulp_context *ulp_ctx)
+{
+ if (!ulp_ctx || !ulp_ctx->cfg_data)
+ return;
+
+ pthread_mutex_unlock(&ulp_ctx->cfg_data->flow_db_lock);
+}
uint32_t dev_id; /* Hardware device id */
uint32_t ref_cnt;
struct bnxt_ulp_flow_db *flow_db;
+ pthread_mutex_t flow_db_lock;
void *mapper_data;
struct bnxt_ulp_port_db *port_db;
struct bnxt_ulp_fc_info *fc_info;
bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx,
uint32_t port_id);
+int32_t
+bnxt_ulp_cntxt_acquire_fdb_lock(struct bnxt_ulp_context *ulp_ctx);
+
+void
+bnxt_ulp_cntxt_release_fdb_lock(struct bnxt_ulp_context *ulp_ctx);
+
#endif /* _BNXT_ULP_H_ */
BNXT_TF_DBG(ERR, "Flow database not found\n");
return -EINVAL;
}
+ if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
+ BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n");
+ return -EINVAL;
+ }
+
flow_tbl = &flow_db->flow_tbl[idx];
while (!ulp_flow_db_next_entry_get(flow_tbl, &fid))
ulp_mapper_resources_free(ulp_ctx, fid, idx);
+ bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
+
return 0;
}
BNXT_TF_DBG(ERR, "Flow database not found\n");
return -EINVAL;
}
+ if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
+ BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n");
+ return -EINVAL;
+ }
flow_tbl = &flow_db->flow_tbl[BNXT_ULP_REGULAR_FLOW_TABLE];
while (!ulp_flow_db_next_entry_get(flow_tbl, &flow_id)) {
if (flow_db->func_id_tbl[flow_id] == func_id)
ulp_mapper_resources_free(ulp_ctx, flow_id,
BNXT_ULP_REGULAR_FLOW_TABLE);
}
-
+ bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
return 0;
}
ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx, uint32_t fid,
enum bnxt_ulp_flow_db_tables flow_tbl_type)
{
+ int32_t rc;
+
if (!ulp_ctx) {
BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
return -EINVAL;
}
+ if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
+ BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n");
+ return -EINVAL;
+ }
+
+ rc = ulp_mapper_resources_free(ulp_ctx, fid, flow_tbl_type);
+ bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
+ return rc;
- return ulp_mapper_resources_free(ulp_ctx, fid, flow_tbl_type);
}
/* Function to handle the default global templates that are allocated during
return -EINVAL;
}
+ /* Protect flow creation */
+ if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
+ BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n");
+ return -EINVAL;
+ }
+
/* Allocate a Flow ID for attaching all resources for the flow to.
* Once allocated, all errors have to walk the list of resources and
* free each of them.
&parms.fid);
if (rc) {
BNXT_TF_DBG(ERR, "Unable to allocate flow table entry\n");
+ bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
return rc;
}
}
*flowid = parms.fid;
+ bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
return rc;
flow_error:
+ bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
/* Free all resources that were allocated during flow creation */
trc = ulp_mapper_flow_destroy(ulp_ctx, parms.fid,
BNXT_ULP_REGULAR_FLOW_TABLE);