+
+/*
+ * Allocate the entry in the parent-child database
+ *
+ * ulp_ctxt [in] Ptr to ulp_context
+ * fid [in] The flow id to the flow entry
+ *
+ * returns index on success and negative on failure.
+ */
+int32_t
+ulp_flow_db_parent_flow_alloc(struct bnxt_ulp_context *ulp_ctxt,
+ uint32_t fid)
+{
+ struct bnxt_ulp_flow_db *flow_db;
+ struct ulp_fdb_parent_child_db *p_pdb;
+ uint32_t idx, free_idx = 0;
+
+ flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp_ctxt);
+ if (!flow_db) {
+ BNXT_TF_DBG(ERR, "Invalid Arguments\n");
+ return -EINVAL;
+ }
+
+ /* check for max flows */
+ if (fid >= flow_db->flow_tbl.num_flows || !fid) {
+ BNXT_TF_DBG(ERR, "Invalid flow index\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) {
+ BNXT_TF_DBG(ERR, "fid is already allocated\n");
+ return -EINVAL;
+ }
+ if (!p_pdb->parent_flow_tbl[idx].parent_fid && !free_idx)
+ free_idx = idx + 1;
+ }
+ /* no free slots */
+ if (!free_idx) {
+ BNXT_TF_DBG(ERR, "parent child db is full\n");
+ return -ENOMEM;
+ }
+
+ free_idx -= 1;
+ /* set the Fid in the parent child */
+ p_pdb->parent_flow_tbl[free_idx].parent_fid = fid;
+ return free_idx;
+}
+
+/*
+ * Free the entry in the parent-child database
+ *
+ * ulp_ctxt [in] Ptr to ulp_context
+ * fid [in] The flow id to the flow entry
+ *
+ * returns 0 on success and negative on failure.
+ */
+int32_t
+ulp_flow_db_parent_flow_free(struct bnxt_ulp_context *ulp_ctxt,
+ uint32_t fid)
+{
+ struct bnxt_ulp_flow_db *flow_db;
+ struct ulp_fdb_parent_child_db *p_pdb;
+ uint32_t idx;
+
+ flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp_ctxt);
+ if (!flow_db) {
+ BNXT_TF_DBG(ERR, "Invalid Arguments\n");
+ return -EINVAL;
+ }
+
+ /* check for max flows */
+ if (fid >= flow_db->flow_tbl.num_flows || !fid) {
+ BNXT_TF_DBG(ERR, "Invalid flow index\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) {
+ /* free the contents */
+ p_pdb->parent_flow_tbl[idx].parent_fid = 0;
+ memset(p_pdb->parent_flow_tbl[idx].child_fid_bitset,
+ 0, p_pdb->child_bitset_size);
+ return 0;
+ }
+ }
+ BNXT_TF_DBG(ERR, "parent entry not found = %x\n", fid);
+ return -EINVAL;
+}
+
+/*
+ * Set or reset the child flow in the parent-child database
+ *
+ * ulp_ctxt [in] Ptr to ulp_context
+ * parent_fid [in] The flow id of the parent flow entry
+ * child_fid [in] The flow id of the child flow entry
+ * set_flag [in] Use 1 for setting child, 0 to reset
+ *
+ * returns zero on success and negative on failure.
+ */
+int32_t
+ulp_flow_db_parent_child_flow_set(struct bnxt_ulp_context *ulp_ctxt,
+ uint32_t parent_fid,
+ uint32_t child_fid,
+ uint32_t set_flag)
+{
+ struct bnxt_ulp_flow_db *flow_db;
+ struct ulp_fdb_parent_child_db *p_pdb;
+ uint32_t idx, a_idx;
+ uint64_t *t;
+
+ flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp_ctxt);
+ if (!flow_db) {
+ BNXT_TF_DBG(ERR, "Invalid Arguments\n");
+ return -EINVAL;
+ }
+
+ /* check for fid validity */
+ if (parent_fid >= flow_db->flow_tbl.num_flows || !parent_fid) {
+ BNXT_TF_DBG(ERR, "Invalid parent flow index %x\n", parent_fid);
+ return -EINVAL;
+ }
+
+ /* check for fid validity */
+ if (child_fid >= flow_db->flow_tbl.num_flows || !child_fid) {
+ BNXT_TF_DBG(ERR, "Invalid child flow index %x\n", child_fid);
+ 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++) {
+ if (p_pdb->parent_flow_tbl[idx].parent_fid == parent_fid) {
+ t = p_pdb->parent_flow_tbl[idx].child_fid_bitset;
+ if (set_flag)
+ ULP_INDEX_BITMAP_SET(t[a_idx], child_fid);
+ else
+ ULP_INDEX_BITMAP_RESET(t[a_idx], child_fid);
+ return 0;
+ }
+ }
+ BNXT_TF_DBG(ERR, "Unable to set the parent-child flow %x:%x\n",
+ parent_fid, child_fid);
+ return -1;
+}
+
+/*
+ * Get the parent index from the parent-child database
+ *
+ * ulp_ctxt [in] Ptr to ulp_context
+ * parent_fid [in] The flow id of the parent flow entry
+ * parent_idx [out] The parent index of parent flow entry
+ *
+ * returns zero on success and negative on failure.
+ */
+int32_t
+ulp_flow_db_parent_flow_idx_get(struct bnxt_ulp_context *ulp_ctxt,
+ uint32_t parent_fid,
+ uint32_t *parent_idx)
+{
+ struct bnxt_ulp_flow_db *flow_db;
+ struct ulp_fdb_parent_child_db *p_pdb;
+ uint32_t idx;
+
+ flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp_ctxt);
+ if (!flow_db) {
+ BNXT_TF_DBG(ERR, "Invalid Arguments\n");
+ return -EINVAL;
+ }
+
+ /* check for fid validity */
+ if (parent_fid >= flow_db->flow_tbl.num_flows || !parent_fid) {
+ BNXT_TF_DBG(ERR, "Invalid parent flow index %x\n", parent_fid);
+ 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) {
+ *parent_idx = idx;
+ return 0;
+ }
+ }
+ BNXT_TF_DBG(ERR, "Unable to get the parent flow %x\n", parent_fid);
+ return -1;
+}
+
+/*
+ * Get the next child flow in the parent-child database
+ *
+ * ulp_ctxt [in] Ptr to ulp_context
+ * parent_fid [in] The flow id of the parent flow entry
+ * child_fid [in/out] The flow id of the child flow entry
+ *
+ * returns zero on success and negative on failure.
+ * Pass child_fid as zero for first entry.
+ */
+int32_t
+ulp_flow_db_parent_child_flow_next_entry_get(struct bnxt_ulp_flow_db *flow_db,
+ uint32_t parent_idx,
+ uint32_t *child_fid)
+{
+ struct ulp_fdb_parent_child_db *p_pdb;
+ uint32_t idx, s_idx, mod_fid;
+ uint32_t next_fid = *child_fid;
+ uint64_t *child_bitset;
+ uint64_t bs;
+
+ /* check for fid validity */
+ p_pdb = &flow_db->parent_child_db;
+ if (parent_idx >= p_pdb->entries_count ||
+ !p_pdb->parent_flow_tbl[parent_idx].parent_fid) {
+ BNXT_TF_DBG(ERR, "Invalid parent flow index %x\n", parent_idx);
+ return -EINVAL;
+ }
+
+ child_bitset = p_pdb->parent_flow_tbl[parent_idx].child_fid_bitset;
+ do {
+ /* increment the flow id to find the next valid flow id */
+ next_fid++;
+ if (next_fid >= flow_db->flow_tbl.num_flows)
+ return -ENOENT;
+ idx = next_fid / ULP_INDEX_BITMAP_SIZE;
+ mod_fid = next_fid % ULP_INDEX_BITMAP_SIZE;
+ s_idx = idx;
+ while (!(bs = child_bitset[idx])) {
+ idx++;
+ if ((idx * ULP_INDEX_BITMAP_SIZE) >=
+ flow_db->flow_tbl.num_flows)
+ return -ENOENT;
+ }
+ /*
+ * remove the previous bits in the bitset bs to find the
+ * next non zero bit in the bitset. This needs to be done
+ * only if the idx is same as he one you started.
+ */
+ if (s_idx == idx)
+ bs &= (-1UL >> mod_fid);
+ next_fid = (idx * ULP_INDEX_BITMAP_SIZE) + __builtin_clzl(bs);
+ if (*child_fid >= next_fid) {
+ BNXT_TF_DBG(ERR, "Parent Child Database is corrupt\n");
+ return -ENOENT;
+ }
+ idx = next_fid / ULP_INDEX_BITMAP_SIZE;
+ } while (!ULP_INDEX_BITMAP_GET(child_bitset[idx], next_fid));
+ *child_fid = next_fid;
+ return 0;
+}