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 {
65 uint64_t *child_fid_bitset;
70 /* Structure to maintain parent-child flow relationships */
71 struct ulp_fdb_parent_child_db {
72 struct ulp_fdb_parent_info *parent_flow_tbl;
73 uint32_t child_bitset_size;
74 uint32_t entries_count;
75 uint8_t *parent_flow_tbl_mem;
78 /* Structure for the flow database resource information. */
79 struct bnxt_ulp_flow_db {
80 struct bnxt_ulp_flow_tbl flow_tbl;
81 uint16_t *func_id_tbl;
82 uint32_t func_id_tbl_size;
83 struct ulp_fdb_parent_child_db parent_child_db;
86 /* flow db resource params to add resources */
87 struct ulp_flow_db_res_params {
88 enum tf_dir direction;
89 enum bnxt_ulp_resource_func resource_func;
90 uint8_t resource_type;
91 uint8_t resource_sub_type;
93 uint8_t critical_resource;
94 uint64_t resource_hndl;
98 * Initialize the flow database. Memory is allocated in this
99 * call and assigned to the flow database.
101 * ulp_ctxt [in] Ptr to ulp context
103 * Returns 0 on success or negative number on failure.
105 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
108 * Deinitialize the flow database. Memory is deallocated in
109 * this call and all flows should have been purged before this
112 * ulp_ctxt [in] Ptr to ulp context
114 * Returns 0 on success.
116 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
119 * Allocate the flow database entry
121 * ulp_ctxt [in] Ptr to ulp_context
122 * tbl_idx [in] Specify it is regular or default flow
123 * func_id [in] The function id of the device.Valid only for regular flows.
124 * fid [out] The index to the flow entry
126 * returns 0 on success and negative on failure.
129 ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
130 enum bnxt_ulp_fdb_type flow_type,
135 * Allocate the flow database entry.
136 * The params->critical_resource has to be set to 0 to allocate a new resource.
138 * ulp_ctxt [in] Ptr to ulp_context
139 * tbl_idx [in] Specify it is regular or default flow
140 * fid [in] The index to the flow entry
141 * params [in] The contents to be copied into resource
143 * returns 0 on success and negative on failure.
146 ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
147 enum bnxt_ulp_fdb_type flow_type,
149 struct ulp_flow_db_res_params *params);
152 * Free the flow database entry.
153 * The params->critical_resource has to be set to 1 to free the first resource.
155 * ulp_ctxt [in] Ptr to ulp_context
156 * tbl_idx [in] Specify it is regular or default flow
157 * fid [in] The index to the flow entry
158 * params [in/out] The contents to be copied into params.
159 * Only the critical_resource needs to be set by the caller.
161 * Returns 0 on success and negative on failure.
164 ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
165 enum bnxt_ulp_fdb_type flow_type,
167 struct ulp_flow_db_res_params *params);
170 * Free the flow database entry
172 * ulp_ctxt [in] Ptr to ulp_context
173 * tbl_idx [in] Specify it is regular or default flow
174 * fid [in] The index to the flow entry
176 * returns 0 on success and negative on failure.
179 ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
180 enum bnxt_ulp_fdb_type tbl_idx,
184 *Get the flow database entry details
186 * ulp_ctxt [in] Ptr to ulp_context
187 * tbl_idx [in] Specify it is regular or default flow
188 * fid [in] The index to the flow entry
189 * nxt_idx [in/out] the index to the next entry
190 * params [out] The contents to be copied into params.
192 * returns 0 on success and negative on failure.
195 ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
196 enum bnxt_ulp_fdb_type flow_type,
199 struct ulp_flow_db_res_params *params);
202 * Flush all flows in the flow database.
204 * ulp_ctxt [in] Ptr to ulp context
205 * tbl_idx [in] The index to table
207 * returns 0 on success or negative number on failure
210 ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
214 * Flush all flows in the flow database that belong to a device function.
216 * ulp_ctxt [in] Ptr to ulp context
217 * tbl_idx [in] The index to table
219 * returns 0 on success or negative number on failure
222 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
226 * Flush all flows in the flow database that are associated with the session.
228 * ulp_ctxt [in] Ptr to ulp context
230 * returns 0 on success or negative number on failure
233 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
236 * Check that flow id matches the function id or not
238 * ulp_ctxt [in] Ptr to ulp context
239 * flow_id [in] flow id of the flow.
240 * func_id [in] The func_id to be set, for reset pass zero.
242 * returns true on success or false on failure
245 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
250 * Api to get the cfa action pointer from a flow.
252 * ulp_ctxt [in] Ptr to ulp context
253 * flow_id [in] flow id
254 * cfa_action [out] The resource handle stored in the flow database
256 * returns 0 on success
259 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx,
261 uint16_t *cfa_action);
263 * Allocate the entry in the parent-child database
265 * ulp_ctxt [in] Ptr to ulp_context
266 * fid [in] The flow id to the flow entry
268 * returns index on success and negative on failure.
271 ulp_flow_db_parent_flow_alloc(struct bnxt_ulp_context *ulp_ctxt,
275 * Free the entry in the parent-child database
277 * ulp_ctxt [in] Ptr to ulp_context
278 * fid [in] The flow id to the flow entry
280 * returns 0 on success and negative on failure.
283 ulp_flow_db_parent_flow_free(struct bnxt_ulp_context *ulp_ctxt,
287 * Set or reset the child flow in the parent-child database
289 * ulp_ctxt [in] Ptr to ulp_context
290 * parent_fid [in] The flow id of the parent flow entry
291 * child_fid [in] The flow id of the child flow entry
292 * set_flag [in] Use 1 for setting child, 0 to reset
294 * returns zero on success and negative on failure.
297 ulp_flow_db_parent_child_flow_set(struct bnxt_ulp_context *ulp_ctxt,
303 * Get the parent index from the parent-child database
305 * ulp_ctxt [in] Ptr to ulp_context
306 * parent_fid [in] The flow id of the parent flow entry
307 * parent_idx [out] The parent index of parent flow entry
309 * returns zero on success and negative on failure.
312 ulp_flow_db_parent_flow_idx_get(struct bnxt_ulp_context *ulp_ctxt,
314 uint32_t *parent_idx);
317 * Get the next child flow in the parent-child database
319 * ulp_ctxt [in] Ptr to ulp_context
320 * parent_fid [in] The flow id of the parent flow entry
321 * child_fid [in/out] The flow id of the child flow entry
323 * returns zero on success and negative on failure.
324 * Pass child_fid as zero for first entry.
327 ulp_flow_db_parent_child_flow_next_entry_get(struct bnxt_ulp_flow_db *flow_db,
329 uint32_t *child_fid);
332 * Orphan the child flow entry
333 * This is called only for child flows that have
334 * BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW resource
336 * ulp_ctxt [in] Ptr to ulp_context
337 * flow_type [in] Specify it is regular or default flow
338 * fid [in] The index to the flow entry
340 * Returns 0 on success and negative on failure.
343 ulp_flow_db_child_flow_reset(struct bnxt_ulp_context *ulp_ctxt,
344 enum bnxt_ulp_fdb_type flow_type,
348 * Create parent flow in the parent flow tbl
350 * parms [in] Ptr to mapper params
352 * Returns 0 on success and negative on failure.
355 ulp_flow_db_parent_flow_create(struct bnxt_ulp_mapper_parms *parms);
358 * Create child flow in the parent flow tbl
360 * parms [in] Ptr to mapper params
362 * Returns 0 on success and negative on failure.
365 ulp_flow_db_child_flow_create(struct bnxt_ulp_mapper_parms *parms);
368 * Update the parent counters
370 * ulp_ctxt [in] Ptr to ulp_context
371 * parent_fid [in] The flow id of the parent flow entry
372 * packet_count [in] - packet count
373 * byte_count [in] - byte count
375 * returns 0 on success
378 ulp_flow_db_parent_flow_count_update(struct bnxt_ulp_context *ulp_ctxt,
380 uint64_t packet_count,
381 uint64_t byte_count);
383 * Get the parent accumulation counters
385 * ulp_ctxt [in] Ptr to ulp_context
386 * parent_fid [in] The flow id of the parent flow entry
387 * packet_count [out] - packet count
388 * byte_count [out] - byte count
390 * returns 0 on success
393 ulp_flow_db_parent_flow_count_get(struct bnxt_ulp_context *ulp_ctxt,
395 uint64_t *packet_count,
396 uint64_t *byte_count,
397 uint8_t count_reset);
400 * reset the parent accumulation counters
402 * ulp_ctxt [in] Ptr to ulp_context
407 ulp_flow_db_parent_flow_count_reset(struct bnxt_ulp_context *ulp_ctxt);
410 * Set the shared bit for the flow db entry
412 * res [in] Ptr to fdb entry
413 * shared [in] shared flag
417 void ulp_flow_db_shared_session_set(struct ulp_flow_db_res_params *res,
418 enum bnxt_ulp_shared_session shared);
420 #endif /* _ULP_FLOW_DB_H_ */