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 to maintain parent-child flow relationships */
56 struct ulp_fdb_parent_info {
58 uint64_t *child_fid_bitset;
61 /* Structure to maintain parent-child flow relationships */
62 struct ulp_fdb_parent_child_db {
63 struct ulp_fdb_parent_info *parent_flow_tbl;
64 uint32_t child_bitset_size;
65 uint32_t entries_count;
66 uint8_t *parent_flow_tbl_mem;
69 /* Structure for the flow database resource information. */
70 struct bnxt_ulp_flow_db {
71 struct bnxt_ulp_flow_tbl flow_tbl;
72 uint16_t *func_id_tbl;
73 uint32_t func_id_tbl_size;
74 struct ulp_fdb_parent_child_db parent_child_db;
77 /* flow db resource params to add resources */
78 struct ulp_flow_db_res_params {
79 enum tf_dir direction;
80 enum bnxt_ulp_resource_func resource_func;
81 uint8_t resource_type;
82 uint8_t resource_sub_type;
84 uint8_t critical_resource;
85 uint64_t resource_hndl;
89 * Initialize the flow database. Memory is allocated in this
90 * call and assigned to the flow database.
92 * ulp_ctxt [in] Ptr to ulp context
94 * Returns 0 on success or negative number on failure.
96 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
99 * Deinitialize the flow database. Memory is deallocated in
100 * this call and all flows should have been purged before this
103 * ulp_ctxt [in] Ptr to ulp context
105 * Returns 0 on success.
107 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
110 * Allocate the flow database entry
112 * ulp_ctxt [in] Ptr to ulp_context
113 * tbl_idx [in] Specify it is regular or default flow
114 * func_id [in] The function id of the device.Valid only for regular flows.
115 * fid [out] The index to the flow entry
117 * returns 0 on success and negative on failure.
120 ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
121 enum bnxt_ulp_fdb_type flow_type,
126 * Allocate the flow database entry.
127 * The params->critical_resource has to be set to 0 to allocate a new resource.
129 * ulp_ctxt [in] Ptr to ulp_context
130 * tbl_idx [in] Specify it is regular or default flow
131 * fid [in] The index to the flow entry
132 * params [in] The contents to be copied into resource
134 * returns 0 on success and negative on failure.
137 ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
138 enum bnxt_ulp_fdb_type flow_type,
140 struct ulp_flow_db_res_params *params);
143 * Free the flow database entry.
144 * The params->critical_resource has to be set to 1 to free the first resource.
146 * ulp_ctxt [in] Ptr to ulp_context
147 * tbl_idx [in] Specify it is regular or default flow
148 * fid [in] The index to the flow entry
149 * params [in/out] The contents to be copied into params.
150 * Only the critical_resource needs to be set by the caller.
152 * Returns 0 on success and negative on failure.
155 ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
156 enum bnxt_ulp_fdb_type flow_type,
158 struct ulp_flow_db_res_params *params);
161 * Free the flow database entry
163 * ulp_ctxt [in] Ptr to ulp_context
164 * tbl_idx [in] Specify it is regular or default flow
165 * fid [in] The index to the flow entry
167 * returns 0 on success and negative on failure.
170 ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
171 enum bnxt_ulp_fdb_type tbl_idx,
175 *Get the flow database entry details
177 * ulp_ctxt [in] Ptr to ulp_context
178 * tbl_idx [in] Specify it is regular or default flow
179 * fid [in] The index to the flow entry
180 * nxt_idx [in/out] the index to the next entry
181 * params [out] The contents to be copied into params.
183 * returns 0 on success and negative on failure.
186 ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
187 enum bnxt_ulp_fdb_type flow_type,
190 struct ulp_flow_db_res_params *params);
193 * Flush all flows in the flow database.
195 * ulp_ctxt [in] Ptr to ulp context
196 * tbl_idx [in] The index to table
198 * returns 0 on success or negative number on failure
201 ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
205 * Flush all flows in the flow database that belong to a device function.
207 * ulp_ctxt [in] Ptr to ulp context
208 * tbl_idx [in] The index to table
210 * returns 0 on success or negative number on failure
213 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
217 * Flush all flows in the flow database that are associated with the session.
219 * ulp_ctxt [in] Ptr to ulp context
221 * returns 0 on success or negative number on failure
224 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
227 * Check that flow id matches the function id or not
229 * ulp_ctxt [in] Ptr to ulp context
230 * flow_id [in] flow id of the flow.
231 * func_id [in] The func_id to be set, for reset pass zero.
233 * returns true on success or false on failure
236 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
241 * Api to get the cfa action pointer from a flow.
243 * ulp_ctxt [in] Ptr to ulp context
244 * flow_id [in] flow id
245 * cfa_action [out] The resource handle stored in the flow database
247 * returns 0 on success
250 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx,
252 uint16_t *cfa_action);
254 * Allocate the entry in the parent-child database
256 * ulp_ctxt [in] Ptr to ulp_context
257 * fid [in] The flow id to the flow entry
259 * returns index on success and negative on failure.
262 ulp_flow_db_parent_flow_alloc(struct bnxt_ulp_context *ulp_ctxt,
266 * Free the entry in the parent-child database
268 * ulp_ctxt [in] Ptr to ulp_context
269 * fid [in] The flow id to the flow entry
271 * returns 0 on success and negative on failure.
274 ulp_flow_db_parent_flow_free(struct bnxt_ulp_context *ulp_ctxt,
278 * Set or reset the child flow in the parent-child database
280 * ulp_ctxt [in] Ptr to ulp_context
281 * parent_fid [in] The flow id of the parent flow entry
282 * child_fid [in] The flow id of the child flow entry
283 * set_flag [in] Use 1 for setting child, 0 to reset
285 * returns zero on success and negative on failure.
288 ulp_flow_db_parent_child_flow_set(struct bnxt_ulp_context *ulp_ctxt,
294 * Get the parent index from the parent-child database
296 * ulp_ctxt [in] Ptr to ulp_context
297 * parent_fid [in] The flow id of the parent flow entry
298 * parent_idx [out] The parent index of parent flow entry
300 * returns zero on success and negative on failure.
303 ulp_flow_db_parent_flow_idx_get(struct bnxt_ulp_context *ulp_ctxt,
305 uint32_t *parent_idx);
308 * Get the next child flow in the parent-child database
310 * ulp_ctxt [in] Ptr to ulp_context
311 * parent_fid [in] The flow id of the parent flow entry
312 * child_fid [in/out] The flow id of the child flow entry
314 * returns zero on success and negative on failure.
315 * Pass child_fid as zero for first entry.
318 ulp_flow_db_parent_child_flow_next_entry_get(struct bnxt_ulp_flow_db *flow_db,
320 uint32_t *child_fid);
323 #endif /* _ULP_FLOW_DB_H_ */