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"
11 #include "ulp_mapper.h"
13 #define BNXT_FLOW_DB_DEFAULT_NUM_FLOWS 512
14 #define BNXT_FLOW_DB_DEFAULT_NUM_RESOURCES 8
17 * Structure for the flow database resource information
18 * The below structure is based on the below paritions
19 * nxt_resource_idx = dir[31],resource_func_upper[30:28],nxt_resource_idx[27:0]
20 * If resource_func is EM_TBL then use resource_em_handle.
21 * Else the other part of the union is used and
22 * resource_func is resource_func_upper[30:28] << 5 | resource_func_lower
24 struct ulp_fdb_resource_info {
25 /* Points to next resource in the chained list. */
26 uint32_t nxt_resource_idx;
28 uint64_t resource_em_handle;
30 uint8_t resource_func_lower;
31 uint8_t resource_type;
32 uint8_t resource_sub_type;
34 uint32_t resource_hndl;
39 /* Structure for the flow database resource information. */
40 struct bnxt_ulp_flow_tbl {
41 /* Flow tbl is the resource object list for each flow id. */
42 struct ulp_fdb_resource_info *flow_resources;
44 /* Flow table stack to track free list of resources. */
45 uint32_t *flow_tbl_stack;
49 /* Table to track the active flows. */
50 uint64_t *active_reg_flows;
51 uint64_t *active_dflt_flows;
53 uint32_t num_resources;
56 /* Structure to maintain parent-child flow relationships */
57 struct ulp_fdb_parent_info {
59 uint64_t *child_fid_bitset;
62 /* Structure to maintain parent-child flow relationships */
63 struct ulp_fdb_parent_child_db {
64 struct ulp_fdb_parent_info *parent_flow_tbl;
65 uint32_t child_bitset_size;
66 uint32_t entries_count;
67 uint8_t *parent_flow_tbl_mem;
70 /* Structure for the flow database resource information. */
71 struct bnxt_ulp_flow_db {
72 struct bnxt_ulp_flow_tbl flow_tbl;
73 uint16_t *func_id_tbl;
74 uint32_t func_id_tbl_size;
75 struct ulp_fdb_parent_child_db parent_child_db;
78 /* flow db resource params to add resources */
79 struct ulp_flow_db_res_params {
80 enum tf_dir direction;
81 enum bnxt_ulp_resource_func resource_func;
82 uint8_t resource_type;
83 uint8_t resource_sub_type;
85 uint8_t critical_resource;
86 uint64_t resource_hndl;
90 * Initialize the flow database. Memory is allocated in this
91 * call and assigned to the flow database.
93 * ulp_ctxt [in] Ptr to ulp context
95 * Returns 0 on success or negative number on failure.
97 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
100 * Deinitialize the flow database. Memory is deallocated in
101 * this call and all flows should have been purged before this
104 * ulp_ctxt [in] Ptr to ulp context
106 * Returns 0 on success.
108 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
111 * Allocate the flow database entry
113 * ulp_ctxt [in] Ptr to ulp_context
114 * tbl_idx [in] Specify it is regular or default flow
115 * func_id [in] The function id of the device.Valid only for regular flows.
116 * fid [out] The index to the flow entry
118 * returns 0 on success and negative on failure.
121 ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
122 enum bnxt_ulp_fdb_type flow_type,
127 * Allocate the flow database entry.
128 * The params->critical_resource has to be set to 0 to allocate a new resource.
130 * ulp_ctxt [in] Ptr to ulp_context
131 * tbl_idx [in] Specify it is regular or default flow
132 * fid [in] The index to the flow entry
133 * params [in] The contents to be copied into resource
135 * returns 0 on success and negative on failure.
138 ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
139 enum bnxt_ulp_fdb_type flow_type,
141 struct ulp_flow_db_res_params *params);
144 * Free the flow database entry.
145 * The params->critical_resource has to be set to 1 to free the first resource.
147 * ulp_ctxt [in] Ptr to ulp_context
148 * tbl_idx [in] Specify it is regular or default flow
149 * fid [in] The index to the flow entry
150 * params [in/out] The contents to be copied into params.
151 * Only the critical_resource needs to be set by the caller.
153 * Returns 0 on success and negative on failure.
156 ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
157 enum bnxt_ulp_fdb_type flow_type,
159 struct ulp_flow_db_res_params *params);
162 * Free the flow database entry
164 * ulp_ctxt [in] Ptr to ulp_context
165 * tbl_idx [in] Specify it is regular or default flow
166 * fid [in] The index to the flow entry
168 * returns 0 on success and negative on failure.
171 ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
172 enum bnxt_ulp_fdb_type tbl_idx,
176 *Get the flow database entry details
178 * ulp_ctxt [in] Ptr to ulp_context
179 * tbl_idx [in] Specify it is regular or default flow
180 * fid [in] The index to the flow entry
181 * nxt_idx [in/out] the index to the next entry
182 * params [out] The contents to be copied into params.
184 * returns 0 on success and negative on failure.
187 ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
188 enum bnxt_ulp_fdb_type flow_type,
191 struct ulp_flow_db_res_params *params);
194 * Flush all flows in the flow database.
196 * ulp_ctxt [in] Ptr to ulp context
197 * tbl_idx [in] The index to table
199 * returns 0 on success or negative number on failure
202 ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
206 * Flush all flows in the flow database that belong to a device function.
208 * ulp_ctxt [in] Ptr to ulp context
209 * tbl_idx [in] The index to table
211 * returns 0 on success or negative number on failure
214 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
218 * Flush all flows in the flow database that are associated with the session.
220 * ulp_ctxt [in] Ptr to ulp context
222 * returns 0 on success or negative number on failure
225 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
228 * Check that flow id matches the function id or not
230 * ulp_ctxt [in] Ptr to ulp context
231 * flow_id [in] flow id of the flow.
232 * func_id [in] The func_id to be set, for reset pass zero.
234 * returns true on success or false on failure
237 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
242 * Api to get the cfa action pointer from a flow.
244 * ulp_ctxt [in] Ptr to ulp context
245 * flow_id [in] flow id
246 * cfa_action [out] The resource handle stored in the flow database
248 * returns 0 on success
251 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx,
253 uint16_t *cfa_action);
255 * Allocate the entry in the parent-child database
257 * ulp_ctxt [in] Ptr to ulp_context
258 * fid [in] The flow id to the flow entry
260 * returns index on success and negative on failure.
263 ulp_flow_db_parent_flow_alloc(struct bnxt_ulp_context *ulp_ctxt,
267 * Free the entry in the parent-child database
269 * ulp_ctxt [in] Ptr to ulp_context
270 * fid [in] The flow id to the flow entry
272 * returns 0 on success and negative on failure.
275 ulp_flow_db_parent_flow_free(struct bnxt_ulp_context *ulp_ctxt,
279 * Set or reset the child flow in the parent-child database
281 * ulp_ctxt [in] Ptr to ulp_context
282 * parent_fid [in] The flow id of the parent flow entry
283 * child_fid [in] The flow id of the child flow entry
284 * set_flag [in] Use 1 for setting child, 0 to reset
286 * returns zero on success and negative on failure.
289 ulp_flow_db_parent_child_flow_set(struct bnxt_ulp_context *ulp_ctxt,
295 * Get the parent index from the parent-child database
297 * ulp_ctxt [in] Ptr to ulp_context
298 * parent_fid [in] The flow id of the parent flow entry
299 * parent_idx [out] The parent index of parent flow entry
301 * returns zero on success and negative on failure.
304 ulp_flow_db_parent_flow_idx_get(struct bnxt_ulp_context *ulp_ctxt,
306 uint32_t *parent_idx);
309 * Get the next child flow in the parent-child database
311 * ulp_ctxt [in] Ptr to ulp_context
312 * parent_fid [in] The flow id of the parent flow entry
313 * child_fid [in/out] The flow id of the child flow entry
315 * returns zero on success and negative on failure.
316 * Pass child_fid as zero for first entry.
319 ulp_flow_db_parent_child_flow_next_entry_get(struct bnxt_ulp_flow_db *flow_db,
321 uint32_t *child_fid);
324 * Orphan the child flow entry
325 * This is called only for child flows that have
326 * BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW resource
328 * ulp_ctxt [in] Ptr to ulp_context
329 * flow_type [in] Specify it is regular or default flow
330 * fid [in] The index to the flow entry
332 * Returns 0 on success and negative on failure.
335 ulp_flow_db_child_flow_reset(struct bnxt_ulp_context *ulp_ctxt,
336 enum bnxt_ulp_fdb_type flow_type,
340 * Create parent flow in the parent flow tbl
342 * parms [in] Ptr to mapper params
344 * Returns 0 on success and negative on failure.
347 ulp_flow_db_parent_flow_create(struct bnxt_ulp_mapper_parms *parms);
350 * Create child flow in the parent flow tbl
352 * parms [in] Ptr to mapper params
354 * Returns 0 on success and negative on failure.
357 ulp_flow_db_child_flow_create(struct bnxt_ulp_mapper_parms *parms);
359 #endif /* _ULP_FLOW_DB_H_ */