1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2021 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 {
62 uint64_t *child_fid_bitset;
67 /* Structure to maintain parent-child flow relationships */
68 struct ulp_fdb_parent_child_db {
69 struct ulp_fdb_parent_info *parent_flow_tbl;
70 uint32_t child_bitset_size;
71 uint32_t entries_count;
72 uint8_t *parent_flow_tbl_mem;
75 /* Structure for the flow database resource information. */
76 struct bnxt_ulp_flow_db {
77 struct bnxt_ulp_flow_tbl flow_tbl;
78 uint16_t *func_id_tbl;
79 uint32_t func_id_tbl_size;
80 struct ulp_fdb_parent_child_db parent_child_db;
83 /* flow db resource params to add resources */
84 struct ulp_flow_db_res_params {
85 enum tf_dir direction;
86 enum bnxt_ulp_resource_func resource_func;
87 uint8_t resource_type;
88 uint8_t resource_sub_type;
90 uint8_t critical_resource;
91 uint64_t resource_hndl;
95 * Initialize the flow database. Memory is allocated in this
96 * call and assigned to the flow database.
98 * ulp_ctxt [in] Ptr to ulp context
100 * Returns 0 on success or negative number on failure.
102 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
105 * Deinitialize the flow database. Memory is deallocated in
106 * this call and all flows should have been purged before this
109 * ulp_ctxt [in] Ptr to ulp context
111 * Returns 0 on success.
113 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
116 * Allocate the flow database entry
118 * ulp_ctxt [in] Ptr to ulp_context
119 * tbl_idx [in] Specify it is regular or default flow
120 * func_id [in] The function id of the device.Valid only for regular flows.
121 * fid [out] The index to the flow entry
123 * returns 0 on success and negative on failure.
126 ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
127 enum bnxt_ulp_fdb_type flow_type,
132 * Allocate the flow database entry.
133 * The params->critical_resource has to be set to 0 to allocate a new resource.
135 * ulp_ctxt [in] Ptr to ulp_context
136 * tbl_idx [in] Specify it is regular or default flow
137 * fid [in] The index to the flow entry
138 * params [in] The contents to be copied into resource
140 * returns 0 on success and negative on failure.
143 ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
144 enum bnxt_ulp_fdb_type flow_type,
146 struct ulp_flow_db_res_params *params);
149 * Free the flow database entry.
150 * The params->critical_resource has to be set to 1 to free the first resource.
152 * ulp_ctxt [in] Ptr to ulp_context
153 * tbl_idx [in] Specify it is regular or default flow
154 * fid [in] The index to the flow entry
155 * params [in/out] The contents to be copied into params.
156 * Only the critical_resource needs to be set by the caller.
158 * Returns 0 on success and negative on failure.
161 ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
162 enum bnxt_ulp_fdb_type flow_type,
164 struct ulp_flow_db_res_params *params);
167 * Free the flow database entry
169 * ulp_ctxt [in] Ptr to ulp_context
170 * tbl_idx [in] Specify it is regular or default flow
171 * fid [in] The index to the flow entry
173 * returns 0 on success and negative on failure.
176 ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
177 enum bnxt_ulp_fdb_type tbl_idx,
181 *Get the flow database entry details
183 * ulp_ctxt [in] Ptr to ulp_context
184 * tbl_idx [in] Specify it is regular or default flow
185 * fid [in] The index to the flow entry
186 * nxt_idx [in/out] the index to the next entry
187 * params [out] The contents to be copied into params.
189 * returns 0 on success and negative on failure.
192 ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
193 enum bnxt_ulp_fdb_type flow_type,
196 struct ulp_flow_db_res_params *params);
199 * Flush all flows in the flow database.
201 * ulp_ctxt [in] Ptr to ulp context
202 * tbl_idx [in] The index to table
204 * returns 0 on success or negative number on failure
207 ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
211 * Flush all flows in the flow database that belong to a device function.
213 * ulp_ctxt [in] Ptr to ulp context
214 * tbl_idx [in] The index to table
216 * returns 0 on success or negative number on failure
219 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
223 * Flush all flows in the flow database that are associated with the session.
225 * ulp_ctxt [in] Ptr to ulp context
227 * returns 0 on success or negative number on failure
230 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
233 * Check that flow id matches the function id or not
235 * ulp_ctxt [in] Ptr to ulp context
236 * flow_id [in] flow id of the flow.
237 * func_id [in] The func_id to be set, for reset pass zero.
239 * returns true on success or false on failure
242 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
247 * Api to get the cfa action pointer from a flow.
249 * ulp_ctxt [in] Ptr to ulp context
250 * flow_id [in] flow id
251 * cfa_action [out] The resource handle stored in the flow database
253 * returns 0 on success
256 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx,
258 uint16_t *cfa_action);
260 * Allocate the entry in the parent-child database
262 * ulp_ctxt [in] Ptr to ulp_context
263 * fid [in] The flow id to the flow entry
265 * returns index on success and negative on failure.
268 ulp_flow_db_parent_flow_alloc(struct bnxt_ulp_context *ulp_ctxt,
272 * Free the entry in the parent-child database
274 * ulp_ctxt [in] Ptr to ulp_context
275 * fid [in] The flow id to the flow entry
277 * returns 0 on success and negative on failure.
280 ulp_flow_db_parent_flow_free(struct bnxt_ulp_context *ulp_ctxt,
284 * Set or reset the child flow in the parent-child database
286 * ulp_ctxt [in] Ptr to ulp_context
287 * parent_fid [in] The flow id of the parent flow entry
288 * child_fid [in] The flow id of the child flow entry
289 * set_flag [in] Use 1 for setting child, 0 to reset
291 * returns zero on success and negative on failure.
294 ulp_flow_db_parent_child_flow_set(struct bnxt_ulp_context *ulp_ctxt,
300 * Get the parent index from the parent-child database
302 * ulp_ctxt [in] Ptr to ulp_context
303 * parent_fid [in] The flow id of the parent flow entry
304 * parent_idx [out] The parent index of parent flow entry
306 * returns zero on success and negative on failure.
309 ulp_flow_db_parent_flow_idx_get(struct bnxt_ulp_context *ulp_ctxt,
311 uint32_t *parent_idx);
314 * Get the next child flow in the parent-child database
316 * ulp_ctxt [in] Ptr to ulp_context
317 * parent_fid [in] The flow id of the parent flow entry
318 * child_fid [in/out] The flow id of the child flow entry
320 * returns zero on success and negative on failure.
321 * Pass child_fid as zero for first entry.
324 ulp_flow_db_parent_child_flow_next_entry_get(struct bnxt_ulp_flow_db *flow_db,
326 uint32_t *child_fid);
329 * Orphan the child flow entry
330 * This is called only for child flows that have
331 * BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW resource
333 * ulp_ctxt [in] Ptr to ulp_context
334 * flow_type [in] Specify it is regular or default flow
335 * fid [in] The index to the flow entry
337 * Returns 0 on success and negative on failure.
340 ulp_flow_db_child_flow_reset(struct bnxt_ulp_context *ulp_ctxt,
341 enum bnxt_ulp_fdb_type flow_type,
345 * Create parent flow in the parent flow tbl
347 * parms [in] Ptr to mapper params
349 * Returns 0 on success and negative on failure.
352 ulp_flow_db_parent_flow_create(struct bnxt_ulp_mapper_parms *parms);
355 * Create child flow in the parent flow tbl
357 * parms [in] Ptr to mapper params
359 * Returns 0 on success and negative on failure.
362 ulp_flow_db_child_flow_create(struct bnxt_ulp_mapper_parms *parms);
365 * Update the parent counters
367 * ulp_ctxt [in] Ptr to ulp_context
368 * parent_fid [in] The flow id of the parent flow entry
369 * packet_count [in] - packet count
370 * byte_count [in] - byte count
372 * returns 0 on success
375 ulp_flow_db_parent_flow_count_update(struct bnxt_ulp_context *ulp_ctxt,
377 uint64_t packet_count,
378 uint64_t byte_count);
380 * Get the parent accumulation counters
382 * ulp_ctxt [in] Ptr to ulp_context
383 * parent_fid [in] The flow id of the parent flow entry
384 * packet_count [out] - packet count
385 * byte_count [out] - byte count
387 * returns 0 on success
390 ulp_flow_db_parent_flow_count_get(struct bnxt_ulp_context *ulp_ctxt,
392 uint64_t *packet_count,
393 uint64_t *byte_count,
394 uint8_t count_reset);
397 * reset the parent accumulation counters
399 * ulp_ctxt [in] Ptr to ulp_context
404 ulp_flow_db_parent_flow_count_reset(struct bnxt_ulp_context *ulp_ctxt);
406 #endif /* _ULP_FLOW_DB_H_ */