#include <rte_malloc.h>
#include "bnxt.h"
#include "bnxt_tf_common.h"
-#include "ulp_flow_db.h"
#include "ulp_utils.h"
#include "ulp_template_struct.h"
#include "ulp_mapper.h"
+#include "ulp_flow_db.h"
#include "ulp_fc_mgr.h"
#define ULP_FLOW_DB_RES_DIR_BIT 31
} else {
if (flow_type == BNXT_ULP_FDB_TYPE_REGULAR)
ULP_INDEX_BITMAP_RESET(f_tbl->active_reg_flows[a_idx],
- idx);
+ idx);
else
ULP_INDEX_BITMAP_RESET(f_tbl->active_dflt_flows[a_idx],
- idx);
+ idx);
}
}
idx);
}
+static inline enum tf_dir
+ulp_flow_db_resource_dir_get(struct ulp_fdb_resource_info *res_info)
+{
+ return ((res_info->nxt_resource_idx & ULP_FLOW_DB_RES_DIR_MASK) >>
+ ULP_FLOW_DB_RES_DIR_BIT);
+}
+
static uint8_t
ulp_flow_db_resource_func_get(struct ulp_fdb_resource_info *res_info)
{
struct ulp_flow_db_res_params *params)
{
memset(params, 0, sizeof(struct ulp_flow_db_res_params));
- params->direction = ((resource_info->nxt_resource_idx &
- ULP_FLOW_DB_RES_DIR_MASK) >>
- ULP_FLOW_DB_RES_DIR_BIT);
/* use the helper function to get the resource func */
+ params->direction = ulp_flow_db_resource_dir_get(resource_info);
params->resource_func = ulp_flow_db_resource_func_get(resource_info);
if (params->resource_func == BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE ||
struct ulp_fdb_parent_child_db *p_db;
uint32_t size, idx;
+ if (!num_entries)
+ return 0;
+
/* update the sizes for the allocation */
p_db = &flow_db->parent_child_db;
p_db->child_bitset_size = (flow_db->flow_tbl.num_flows /
return -EINVAL;
}
+ /* No support for parent child db then just exit */
+ if (!flow_db->parent_child_db.entries_count) {
+ BNXT_TF_DBG(ERR, "parent child db not supported\n");
+ return -EINVAL;
+ }
+
p_pdb = &flow_db->parent_child_db;
for (idx = 0; idx <= p_pdb->entries_count; idx++) {
if (p_pdb->parent_flow_tbl[idx].parent_fid == fid) {
return -EINVAL;
}
+ /* No support for parent child db then just exit */
+ if (!flow_db->parent_child_db.entries_count) {
+ BNXT_TF_DBG(ERR, "parent child db not supported\n");
+ return -EINVAL;
+ }
+
p_pdb = &flow_db->parent_child_db;
for (idx = 0; idx <= p_pdb->entries_count; idx++) {
if (p_pdb->parent_flow_tbl[idx].parent_fid == fid) {
return -EINVAL;
}
+ /* No support for parent child db then just exit */
+ if (!flow_db->parent_child_db.entries_count) {
+ BNXT_TF_DBG(ERR, "parent child db not supported\n");
+ return -EINVAL;
+ }
+
p_pdb = &flow_db->parent_child_db;
a_idx = child_fid / ULP_INDEX_BITMAP_SIZE;
for (idx = 0; idx <= p_pdb->entries_count; idx++) {
return -EINVAL;
}
+ /* No support for parent child db then just exit */
+ if (!flow_db->parent_child_db.entries_count) {
+ BNXT_TF_DBG(ERR, "parent child db not supported\n");
+ return -EINVAL;
+ }
+
p_pdb = &flow_db->parent_child_db;
for (idx = 0; idx <= p_pdb->entries_count; idx++) {
if (p_pdb->parent_flow_tbl[idx].parent_fid == parent_fid) {
*child_fid = next_fid;
return 0;
}
+
+/*
+ * Orphan the child flow entry
+ * This is called only for child flows that have
+ * BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW resource
+ *
+ * ulp_ctxt [in] Ptr to ulp_context
+ * flow_type [in] Specify it is regular or default flow
+ * fid [in] The index to the flow entry
+ *
+ * Returns 0 on success and negative on failure.
+ */
+int32_t
+ulp_flow_db_child_flow_reset(struct bnxt_ulp_context *ulp_ctxt,
+ enum bnxt_ulp_fdb_type flow_type,
+ uint32_t fid)
+{
+ struct bnxt_ulp_flow_db *flow_db;
+ struct bnxt_ulp_flow_tbl *flow_tbl;
+ struct ulp_fdb_resource_info *fid_res;
+ uint32_t res_id = 0;
+
+ flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp_ctxt);
+ if (!flow_db) {
+ BNXT_TF_DBG(ERR, "Invalid Arguments\n");
+ return -EINVAL;
+ }
+
+ if (flow_type > BNXT_ULP_FDB_TYPE_DEFAULT) {
+ BNXT_TF_DBG(ERR, "Invalid flow type\n");
+ return -EINVAL;
+ }
+
+ flow_tbl = &flow_db->flow_tbl;
+ /* check for max flows */
+ if (fid >= flow_tbl->num_flows || !fid) {
+ BNXT_TF_DBG(ERR, "Invalid flow index %x\n", fid);
+ return -EINVAL;
+ }
+
+ /* check if the flow is active or not */
+ if (!ulp_flow_db_active_flows_bit_is_set(flow_db, flow_type, fid)) {
+ BNXT_TF_DBG(ERR, "flow does not exist\n");
+ return -EINVAL;
+ }
+
+ /* Iterate the resource to get the resource handle */
+ res_id = fid;
+ while (res_id) {
+ fid_res = &flow_tbl->flow_resources[res_id];
+ if (ulp_flow_db_resource_func_get(fid_res) ==
+ BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW) {
+ /* invalidate the resource details */
+ fid_res->resource_hndl = 0;
+ return 0;
+ }
+ res_id = 0;
+ ULP_FLOW_DB_RES_NXT_SET(res_id, fid_res->nxt_resource_idx);
+ }
+ /* failed */
+ return -1;
+}
+
+/*
+ * Create parent flow in the parent flow tbl
+ *
+ * parms [in] Ptr to mapper params
+ *
+ * Returns 0 on success and negative on failure.
+ */
+int32_t
+ulp_flow_db_parent_flow_create(struct bnxt_ulp_mapper_parms *parms)
+{
+ struct ulp_flow_db_res_params fid_parms;
+ int32_t fid_idx;
+
+ /* create the child flow entry in parent flow table */
+ fid_idx = ulp_flow_db_parent_flow_alloc(parms->ulp_ctx, parms->fid);
+ if (fid_idx < 0) {
+ BNXT_TF_DBG(ERR, "Error in creating parent flow fid %x\n",
+ parms->fid);
+ return -1;
+ }
+
+ /* Add the parent details in the resource list of the flow */
+ memset(&fid_parms, 0, sizeof(fid_parms));
+ fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW;
+ fid_parms.resource_hndl = fid_idx;
+ fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
+ if (ulp_flow_db_resource_add(parms->ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR,
+ parms->fid, &fid_parms)) {
+ BNXT_TF_DBG(ERR, "Error in adding flow res for fid %x\n",
+ parms->fid);
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * Create child flow in the parent flow tbl
+ *
+ * parms [in] Ptr to mapper params
+ *
+ * Returns 0 on success and negative on failure.
+ */
+int32_t
+ulp_flow_db_child_flow_create(struct bnxt_ulp_mapper_parms *parms)
+{
+ struct ulp_flow_db_res_params fid_parms;
+ int32_t rc;
+
+ /* create the parent flow entry in parent flow table */
+ rc = ulp_flow_db_parent_child_flow_set(parms->ulp_ctx,
+ parms->parent_fid,
+ parms->fid, 1);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Error in setting child fid %x\n", parms->fid);
+ return -1;
+ }
+
+ /* Add the parent details in the resource list of the flow */
+ memset(&fid_parms, 0, sizeof(fid_parms));
+ fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW;
+ fid_parms.resource_hndl = parms->parent_fid;
+ fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
+ if (ulp_flow_db_resource_add(parms->ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR,
+ parms->fid, &fid_parms)) {
+ BNXT_TF_DBG(ERR, "Error in adding flow res for fid %x\n",
+ parms->fid);
+ return -1;
+ }
+ return 0;
+}
#include "tfp.h"
#include "tf_ext_flow_handle.h"
#include "ulp_mark_mgr.h"
-#include "ulp_flow_db.h"
#include "ulp_mapper.h"
+#include "ulp_flow_db.h"
#include "tf_util.h"
static struct bnxt_ulp_glb_resource_info *
res->resource_hndl);
}
+
+static inline int32_t
+ulp_mapper_parent_flow_free(struct bnxt_ulp_context *ulp,
+ uint32_t parent_fid,
+ struct ulp_flow_db_res_params *res)
+{
+ uint32_t idx, child_fid = 0, parent_idx;
+ struct bnxt_ulp_flow_db *flow_db;
+
+ parent_idx = (uint32_t)res->resource_hndl;
+
+ /* check the validity of the parent fid */
+ if (ulp_flow_db_parent_flow_idx_get(ulp, parent_fid, &idx) ||
+ idx != parent_idx) {
+ BNXT_TF_DBG(ERR, "invalid parent flow id %x\n", parent_fid);
+ return -EINVAL;
+ }
+
+ /* Clear all the child flows parent index */
+ flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp);
+ while (!ulp_flow_db_parent_child_flow_next_entry_get(flow_db, idx,
+ &child_fid)) {
+ /* update the child flows resource handle */
+ if (ulp_flow_db_child_flow_reset(ulp, BNXT_ULP_FDB_TYPE_REGULAR,
+ child_fid)) {
+ BNXT_TF_DBG(ERR, "failed to reset child flow %x\n",
+ child_fid);
+ return -EINVAL;
+ }
+ }
+
+ /* free the parent entry in the parent table flow */
+ if (ulp_flow_db_parent_flow_free(ulp, parent_fid)) {
+ BNXT_TF_DBG(ERR, "failed to free parent flow %x\n", parent_fid);
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static inline int32_t
+ulp_mapper_child_flow_free(struct bnxt_ulp_context *ulp,
+ uint32_t child_fid,
+ struct ulp_flow_db_res_params *res)
+{
+ uint32_t parent_fid;
+
+ parent_fid = (uint32_t)res->resource_hndl;
+ if (!parent_fid)
+ return 0; /* Already freed - orphan child*/
+
+ /* reset the child flow bitset*/
+ if (ulp_flow_db_parent_child_flow_set(ulp, parent_fid, child_fid, 0)) {
+ BNXT_TF_DBG(ERR, "error in resetting child flow bitset %x:%x\n",
+ parent_fid, child_fid);
+ return -EINVAL;
+ }
+ return 0;
+}
+
/*
* Process the identifier instruction and either store it in the flow database
* or return it in the val (if not NULL) on success. If val is NULL, the
static int32_t
ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
+ uint32_t fid,
struct ulp_flow_db_res_params *res)
{
struct tf *tfp;
case BNXT_ULP_RESOURCE_FUNC_HW_FID:
rc = ulp_mapper_mark_free(ulp, res);
break;
+ case BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW:
+ rc = ulp_mapper_parent_flow_free(ulp, fid, res);
+ break;
+ case BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW:
+ rc = ulp_mapper_child_flow_free(ulp, fid, res);
+ break;
default:
break;
}
}
while (!rc) {
- trc = ulp_mapper_resource_free(ulp_ctx, &res_parms);
+ trc = ulp_mapper_resource_free(ulp_ctx, fid, &res_parms);
if (trc)
/*
* On fail, we still need to attempt to free the
/*convert it from BE to cpu */
res.resource_hndl =
tfp_be_to_cpu_64(ent->resource_hndl);
- ulp_mapper_resource_free(ulp_ctx, &res);
+ ulp_mapper_resource_free(ulp_ctx, 0, &res);
}
}
}
parms.act_tid = cparms->act_tid;
parms.class_tid = cparms->class_tid;
parms.flow_type = cparms->flow_type;
+ parms.parent_flow = cparms->parent_flow;
+ parms.parent_fid = cparms->parent_fid;
/* Get the device id from the ulp context */
if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
goto flow_error;
}
+ /* setup the parent-child details */
+ if (parms.parent_flow) {
+ /* create a parent flow details */
+ rc = ulp_flow_db_parent_flow_create(&parms);
+ if (rc)
+ goto flow_error;
+ } else if (parms.parent_fid) {
+ /* create a child flow details */
+ rc = ulp_flow_db_child_flow_create(&parms);
+ if (rc)
+ goto flow_error;
+ }
+
*flowid = parms.fid;
bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);