+
+/*
+ * Free the flow database entry.
+ * The params->critical_resource has to be set to 1 to free the first resource.
+ *
+ * ulp_ctxt [in] Ptr to ulp_context
+ * tbl_idx [in] Specify it is regular or default flow
+ * fid [in] The index to the flow entry
+ * params [in/out] The contents to be copied into params.
+ * Onlythe critical_resource needs to be set by the caller.
+ *
+ * Returns 0 on success and negative on failure.
+ */
+int32_t ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
+ enum bnxt_ulp_flow_db_tables tbl_idx,
+ uint32_t fid,
+ struct ulp_flow_db_res_params *params)
+{
+ struct bnxt_ulp_flow_db *flow_db;
+ struct bnxt_ulp_flow_tbl *flow_tbl;
+ struct ulp_fdb_resource_info *nxt_resource, *fid_resource;
+ uint32_t nxt_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;
+ }
+
+ if (tbl_idx >= BNXT_ULP_FLOW_TABLE_MAX) {
+ BNXT_TF_DBG(ERR, "Invalid table index\n");
+ return -EINVAL;
+ }
+ flow_tbl = &flow_db->flow_tbl[tbl_idx];
+
+ /* check for max flows */
+ if (fid >= flow_tbl->num_flows || !fid) {
+ BNXT_TF_DBG(ERR, "Invalid flow index\n");
+ return -EINVAL;
+ }
+
+ /* check if the flow is active or not */
+ if (!ulp_flow_db_active_flow_is_set(flow_tbl, fid)) {
+ BNXT_TF_DBG(ERR, "flow does not exist\n");
+ return -EINVAL;
+ }
+
+ fid_resource = &flow_tbl->flow_resources[fid];
+ if (!params->critical_resource) {
+ /* Not the critical resource so free the resource */
+ ULP_FLOW_DB_RES_NXT_SET(nxt_idx,
+ fid_resource->nxt_resource_idx);
+ if (!nxt_idx) {
+ /* reached end of resources */
+ return -ENOENT;
+ }
+ nxt_resource = &flow_tbl->flow_resources[nxt_idx];
+
+ /* connect the fid resource to the next resource */
+ ULP_FLOW_DB_RES_NXT_RESET(fid_resource->nxt_resource_idx);
+ ULP_FLOW_DB_RES_NXT_SET(fid_resource->nxt_resource_idx,
+ nxt_resource->nxt_resource_idx);
+
+ /* update the contents to be given to caller */
+ ulp_flow_db_res_info_to_params(nxt_resource, params);
+
+ /* Delete the nxt_resource */
+ memset(nxt_resource, 0, sizeof(struct ulp_fdb_resource_info));
+
+ /* add it to the free list */
+ flow_tbl->tail_index++;
+ if (flow_tbl->tail_index >= flow_tbl->num_resources) {
+ BNXT_TF_DBG(ERR, "FlowDB:Tail reached max\n");
+ return -ENOENT;
+ }
+ flow_tbl->flow_tbl_stack[flow_tbl->tail_index] = nxt_idx;
+
+ } else {
+ /* Critical resource. copy the contents and exit */
+ ulp_flow_db_res_info_to_params(fid_resource, params);
+ ULP_FLOW_DB_RES_NXT_SET(nxt_idx,
+ fid_resource->nxt_resource_idx);
+ memset(fid_resource, 0, sizeof(struct ulp_fdb_resource_info));
+ ULP_FLOW_DB_RES_NXT_SET(fid_resource->nxt_resource_idx,
+ nxt_idx);
+ }
+
+ /* all good, return success */
+ return 0;
+}
+
+/*
+ * Free the flow database entry
+ *
+ * ulp_ctxt [in] Ptr to ulp_context
+ * tbl_idx [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_fid_free(struct bnxt_ulp_context *ulp_ctxt,
+ enum bnxt_ulp_flow_db_tables tbl_idx,
+ uint32_t fid)
+{
+ struct bnxt_ulp_flow_db *flow_db;
+ struct bnxt_ulp_flow_tbl *flow_tbl;
+
+ flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp_ctxt);
+ if (!flow_db) {
+ BNXT_TF_DBG(ERR, "Invalid Arguments\n");
+ return -EINVAL;
+ }
+
+ if (tbl_idx >= BNXT_ULP_FLOW_TABLE_MAX) {
+ BNXT_TF_DBG(ERR, "Invalid table index\n");
+ return -EINVAL;
+ }
+
+ flow_tbl = &flow_db->flow_tbl[tbl_idx];
+
+ /* check for limits of fid */
+ if (fid >= flow_tbl->num_flows || !fid) {
+ BNXT_TF_DBG(ERR, "Invalid flow index\n");
+ return -EINVAL;
+ }
+
+ /* check if the flow is active or not */
+ if (!ulp_flow_db_active_flow_is_set(flow_tbl, fid)) {
+ BNXT_TF_DBG(ERR, "flow does not exist\n");
+ return -EINVAL;
+ }
+ flow_tbl->head_index--;
+ if (!flow_tbl->head_index) {
+ BNXT_TF_DBG(ERR, "FlowDB: Head Ptr is zero\n");
+ return -ENOENT;
+ }
+ flow_tbl->flow_tbl_stack[flow_tbl->head_index] = fid;
+ ulp_flow_db_active_flow_set(flow_tbl, fid, 0);
+
+ /* all good, return success */
+ return 0;
+}