1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2019 Broadcom
6 #ifndef _ULP_FLOW_DB_H_
7 #define _ULP_FLOW_DB_H_
10 #include "ulp_template_db_enum.h"
12 #define BNXT_FLOW_DB_DEFAULT_NUM_FLOWS 512
13 #define BNXT_FLOW_DB_DEFAULT_NUM_RESOURCES 8
16 * Structure for the flow database resource information
17 * The below structure is based on the below paritions
18 * nxt_resource_idx = dir[31],resource_func_upper[30:28],nxt_resource_idx[27:0]
19 * If resource_func is EM_TBL then use resource_em_handle.
20 * Else the other part of the union is used and
21 * resource_func is resource_func_upper[30:28] << 5 | resource_func_lower
23 struct ulp_fdb_resource_info {
24 /* Points to next resource in the chained list. */
25 uint32_t nxt_resource_idx;
27 uint64_t resource_em_handle;
29 uint8_t resource_func_lower;
30 uint8_t resource_type;
31 uint8_t resource_sub_type;
33 uint32_t resource_hndl;
38 /* Structure for the flow database resource information. */
39 struct bnxt_ulp_flow_tbl {
40 /* Flow tbl is the resource object list for each flow id. */
41 struct ulp_fdb_resource_info *flow_resources;
43 /* Flow table stack to track free list of resources. */
44 uint32_t *flow_tbl_stack;
48 /* Table to track the active flows. */
49 uint64_t *active_reg_flows;
50 uint64_t *active_dflt_flows;
52 uint32_t num_resources;
55 /* Structure for the flow database resource information. */
56 struct bnxt_ulp_flow_db {
57 struct bnxt_ulp_flow_tbl flow_tbl;
58 uint16_t *func_id_tbl;
59 uint32_t func_id_tbl_size;
62 /* flow db resource params to add resources */
63 struct ulp_flow_db_res_params {
64 enum tf_dir direction;
65 enum bnxt_ulp_resource_func resource_func;
66 uint8_t resource_type;
67 uint8_t resource_sub_type;
69 uint8_t critical_resource;
70 uint64_t resource_hndl;
74 * Initialize the flow database. Memory is allocated in this
75 * call and assigned to the flow database.
77 * ulp_ctxt [in] Ptr to ulp context
79 * Returns 0 on success or negative number on failure.
81 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
84 * Deinitialize the flow database. Memory is deallocated in
85 * this call and all flows should have been purged before this
88 * ulp_ctxt [in] Ptr to ulp context
90 * Returns 0 on success.
92 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
95 * Allocate the flow database entry
97 * ulp_ctxt [in] Ptr to ulp_context
98 * tbl_idx [in] Specify it is regular or default flow
99 * func_id [in] The function id of the device.Valid only for regular flows.
100 * fid [out] The index to the flow entry
102 * returns 0 on success and negative on failure.
105 ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
106 enum bnxt_ulp_fdb_type flow_type,
111 * Allocate the flow database entry.
112 * The params->critical_resource has to be set to 0 to allocate a new resource.
114 * ulp_ctxt [in] Ptr to ulp_context
115 * tbl_idx [in] Specify it is regular or default flow
116 * fid [in] The index to the flow entry
117 * params [in] The contents to be copied into resource
119 * returns 0 on success and negative on failure.
122 ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
123 enum bnxt_ulp_fdb_type flow_type,
125 struct ulp_flow_db_res_params *params);
128 * Free the flow database entry.
129 * The params->critical_resource has to be set to 1 to free the first resource.
131 * ulp_ctxt [in] Ptr to ulp_context
132 * tbl_idx [in] Specify it is regular or default flow
133 * fid [in] The index to the flow entry
134 * params [in/out] The contents to be copied into params.
135 * Only the critical_resource needs to be set by the caller.
137 * Returns 0 on success and negative on failure.
140 ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
141 enum bnxt_ulp_fdb_type flow_type,
143 struct ulp_flow_db_res_params *params);
146 * Free the flow database entry
148 * ulp_ctxt [in] Ptr to ulp_context
149 * tbl_idx [in] Specify it is regular or default flow
150 * fid [in] The index to the flow entry
152 * returns 0 on success and negative on failure.
155 ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
156 enum bnxt_ulp_fdb_type tbl_idx,
160 *Get the flow database entry details
162 * ulp_ctxt [in] Ptr to ulp_context
163 * tbl_idx [in] Specify it is regular or default flow
164 * fid [in] The index to the flow entry
165 * nxt_idx [in/out] the index to the next entry
166 * params [out] The contents to be copied into params.
168 * returns 0 on success and negative on failure.
171 ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
172 enum bnxt_ulp_fdb_type flow_type,
175 struct ulp_flow_db_res_params *params);
178 * Flush all flows in the flow database.
180 * ulp_ctxt [in] Ptr to ulp context
181 * tbl_idx [in] The index to table
183 * returns 0 on success or negative number on failure
186 ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
190 * Flush all flows in the flow database that belong to a device function.
192 * ulp_ctxt [in] Ptr to ulp context
193 * tbl_idx [in] The index to table
195 * returns 0 on success or negative number on failure
198 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
202 * Flush all flows in the flow database that are associated with the session.
204 * ulp_ctxt [in] Ptr to ulp context
206 * returns 0 on success or negative number on failure
209 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
212 * Check that flow id matches the function id or not
214 * ulp_ctxt [in] Ptr to ulp context
215 * flow_id [in] flow id of the flow.
216 * func_id [in] The func_id to be set, for reset pass zero.
218 * returns true on success or false on failure
221 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
226 * Api to get the cfa action pointer from a flow.
228 * ulp_ctxt [in] Ptr to ulp context
229 * flow_id [in] flow id
230 * cfa_action [out] The resource handle stored in the flow database
232 * returns 0 on success
235 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx,
237 uint16_t *cfa_action);
239 #endif /* _ULP_FLOW_DB_H_ */