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
16 /* Defines for the fdb flag */
17 #define ULP_FDB_FLAG_SHARED_SESSION 0x1
20 * Structure for the flow database resource information
21 * The below structure is based on the below partitions
22 * nxt_resource_idx = dir[31],resource_func_upper[30:28],nxt_resource_idx[27:0]
23 * If resource_func is EM_TBL then use resource_em_handle.
24 * Else the other part of the union is used and
25 * resource_func is resource_func_upper[30:28] << 5 | resource_func_lower
27 struct ulp_fdb_resource_info {
28 /* Points to next resource in the chained list. */
29 uint32_t nxt_resource_idx;
31 uint64_t resource_em_handle;
33 uint8_t resource_func_lower;
34 uint8_t resource_type;
35 uint8_t resource_sub_type;
37 uint32_t resource_hndl;
42 /* Structure for the flow database resource information. */
43 struct bnxt_ulp_flow_tbl {
44 /* Flow tbl is the resource object list for each flow id. */
45 struct ulp_fdb_resource_info *flow_resources;
47 /* Flow table stack to track free list of resources. */
48 uint32_t *flow_tbl_stack;
52 /* Table to track the active flows. */
53 uint64_t *active_reg_flows;
54 uint64_t *active_dflt_flows;
56 uint32_t num_resources;
59 /* Structure to maintain parent-child flow relationships */
60 struct ulp_fdb_parent_info {
66 uint64_t *child_fid_bitset;
71 /* Structure to maintain parent-child flow relationships */
72 struct ulp_fdb_parent_child_db {
73 struct ulp_fdb_parent_info *parent_flow_tbl;
74 uint32_t child_bitset_size;
75 uint32_t entries_count;
76 uint8_t *parent_flow_tbl_mem;
79 /* Structure for the flow database resource information. */
80 struct bnxt_ulp_flow_db {
81 struct bnxt_ulp_flow_tbl flow_tbl;
82 uint16_t *func_id_tbl;
83 uint32_t func_id_tbl_size;
84 struct ulp_fdb_parent_child_db parent_child_db;
87 /* flow db resource params to add resources */
88 struct ulp_flow_db_res_params {
89 enum tf_dir direction;
90 enum bnxt_ulp_resource_func resource_func;
91 uint8_t resource_type;
92 uint8_t resource_sub_type;
94 uint8_t critical_resource;
95 uint64_t resource_hndl;
99 * Initialize the flow database. Memory is allocated in this
100 * call and assigned to the flow database.
102 * ulp_ctxt [in] Ptr to ulp context
104 * Returns 0 on success or negative number on failure.
106 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
109 * Deinitialize the flow database. Memory is deallocated in
110 * this call and all flows should have been purged before this
113 * ulp_ctxt [in] Ptr to ulp context
115 * Returns 0 on success.
117 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
120 * Allocate the flow database entry
122 * ulp_ctxt [in] Ptr to ulp_context
123 * tbl_idx [in] Specify it is regular or default flow
124 * func_id [in] The function id of the device.Valid only for regular flows.
125 * fid [out] The index to the flow entry
127 * returns 0 on success and negative on failure.
130 ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
131 enum bnxt_ulp_fdb_type flow_type,
136 * Allocate the flow database entry.
137 * The params->critical_resource has to be set to 0 to allocate a new resource.
139 * ulp_ctxt [in] Ptr to ulp_context
140 * tbl_idx [in] Specify it is regular or default flow
141 * fid [in] The index to the flow entry
142 * params [in] The contents to be copied into resource
144 * returns 0 on success and negative on failure.
147 ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
148 enum bnxt_ulp_fdb_type flow_type,
150 struct ulp_flow_db_res_params *params);
153 * Free the flow database entry.
154 * The params->critical_resource has to be set to 1 to free the first resource.
156 * ulp_ctxt [in] Ptr to ulp_context
157 * tbl_idx [in] Specify it is regular or default flow
158 * fid [in] The index to the flow entry
159 * params [in/out] The contents to be copied into params.
160 * Only the critical_resource needs to be set by the caller.
162 * Returns 0 on success and negative on failure.
165 ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
166 enum bnxt_ulp_fdb_type flow_type,
168 struct ulp_flow_db_res_params *params);
171 * Free the flow database entry
173 * ulp_ctxt [in] Ptr to ulp_context
174 * tbl_idx [in] Specify it is regular or default flow
175 * fid [in] The index to the flow entry
177 * returns 0 on success and negative on failure.
180 ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
181 enum bnxt_ulp_fdb_type tbl_idx,
185 *Get the flow database entry details
187 * ulp_ctxt [in] Ptr to ulp_context
188 * tbl_idx [in] Specify it is regular or default flow
189 * fid [in] The index to the flow entry
190 * nxt_idx [in/out] the index to the next entry
191 * params [out] The contents to be copied into params.
193 * returns 0 on success and negative on failure.
196 ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
197 enum bnxt_ulp_fdb_type flow_type,
200 struct ulp_flow_db_res_params *params);
203 * Flush all flows in the flow database.
205 * ulp_ctxt [in] Ptr to ulp context
206 * tbl_idx [in] The index to table
208 * returns 0 on success or negative number on failure
211 ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
215 * Flush all flows in the flow database that belong to a device function.
217 * ulp_ctxt [in] Ptr to ulp context
218 * tbl_idx [in] The index to table
220 * returns 0 on success or negative number on failure
223 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
227 * Flush all flows in the flow database that are associated with the session.
229 * ulp_ctxt [in] Ptr to ulp context
231 * returns 0 on success or negative number on failure
234 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
237 * Check that flow id matches the function id or not
239 * ulp_ctxt [in] Ptr to ulp context
240 * flow_id [in] flow id of the flow.
241 * func_id [in] The func_id to be set, for reset pass zero.
243 * returns true on success or false on failure
246 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
251 * Api to get the cfa action pointer from a flow.
253 * ulp_ctxt [in] Ptr to ulp context
254 * flow_id [in] flow id
255 * cfa_action [out] The resource handle stored in the flow database
257 * returns 0 on success
260 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx,
262 uint16_t *cfa_action);
265 * Set or reset the parent flow in the parent-child database
267 * ulp_ctxt [in] Ptr to ulp_context
268 * pc_idx [in] The index to parent child db
269 * parent_fid [in] The flow id of the parent flow entry
270 * set_flag [in] Use 1 for setting child, 0 to reset
272 * returns zero on success and negative on failure.
275 ulp_flow_db_pc_db_parent_flow_set(struct bnxt_ulp_context *ulp_ctxt,
281 * Set or reset the child flow in the parent-child database
283 * ulp_ctxt [in] Ptr to ulp_context
284 * pc_idx [in] The index to parent child db
285 * child_fid [in] The flow id of the child flow entry
286 * set_flag [in] Use 1 for setting child, 0 to reset
288 * returns zero on success and negative on failure.
291 ulp_flow_db_pc_db_child_flow_set(struct bnxt_ulp_context *ulp_ctxt,
297 * Get the parent index from the parent-child database
299 * ulp_ctxt [in] Ptr to ulp_context
300 * parent_fid [in] The flow id of the parent flow entry
301 * parent_idx [out] The parent index of parent flow entry
303 * returns zero on success and negative on failure.
306 ulp_flow_db_parent_flow_idx_get(struct bnxt_ulp_context *ulp_ctxt,
308 uint32_t *parent_idx);
311 * Get the next child flow in the parent-child database
313 * ulp_ctxt [in] Ptr to ulp_context
314 * parent_fid [in] The flow id of the parent flow entry
315 * child_fid [in/out] The flow id of the child flow entry
317 * returns zero on success and negative on failure.
318 * Pass child_fid as zero for first entry.
321 ulp_flow_db_parent_child_flow_next_entry_get(struct bnxt_ulp_flow_db *flow_db,
323 uint32_t *child_fid);
326 * Orphan the child flow entry
327 * This is called only for child flows that have
328 * BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW resource
330 * ulp_ctxt [in] Ptr to ulp_context
331 * flow_type [in] Specify it is regular or default flow
332 * fid [in] The index to the flow entry
334 * Returns 0 on success and negative on failure.
337 ulp_flow_db_child_flow_reset(struct bnxt_ulp_context *ulp_ctxt,
338 enum bnxt_ulp_fdb_type flow_type,
342 * Create parent flow in the parent flow tbl
344 * parms [in] Ptr to mapper params
346 * Returns 0 on success and negative on failure.
349 ulp_flow_db_parent_flow_create(struct bnxt_ulp_mapper_parms *parms);
352 * Create child flow in the parent flow tbl
354 * parms [in] Ptr to mapper params
356 * Returns 0 on success and negative on failure.
359 ulp_flow_db_child_flow_create(struct bnxt_ulp_mapper_parms *parms);
362 * Update the parent counters
364 * ulp_ctxt [in] Ptr to ulp_context
365 * pc_idx [in] The parent flow entry idx
366 * packet_count [in] - packet count
367 * byte_count [in] - byte count
369 * returns 0 on success
372 ulp_flow_db_parent_flow_count_update(struct bnxt_ulp_context *ulp_ctxt,
374 uint64_t packet_count,
375 uint64_t byte_count);
377 * Get the parent accumulation counters
379 * ulp_ctxt [in] Ptr to ulp_context
380 * pc_idx [in] The parent flow entry idx
381 * packet_count [out] - packet count
382 * byte_count [out] - byte count
384 * returns 0 on success
387 ulp_flow_db_parent_flow_count_get(struct bnxt_ulp_context *ulp_ctxt,
389 uint64_t *packet_count,
390 uint64_t *byte_count,
391 uint8_t count_reset);
394 * reset the parent accumulation counters
396 * ulp_ctxt [in] Ptr to ulp_context
401 ulp_flow_db_parent_flow_count_reset(struct bnxt_ulp_context *ulp_ctxt);
404 * Set the shared bit for the flow db entry
406 * res [in] Ptr to fdb entry
407 * shared [in] shared flag
411 void ulp_flow_db_shared_session_set(struct ulp_flow_db_res_params *res,
412 enum bnxt_ulp_shared_session shared);
414 #endif /* _ULP_FLOW_DB_H_ */