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 {
62 uint64_t *child_fid_bitset;
65 /* Structure to maintain parent-child flow relationships */
66 struct ulp_fdb_parent_child_db {
67 struct ulp_fdb_parent_info *parent_flow_tbl;
68 uint32_t child_bitset_size;
69 uint32_t entries_count;
70 uint8_t *parent_flow_tbl_mem;
73 /* Structure for the flow database resource information. */
74 struct bnxt_ulp_flow_db {
75 struct bnxt_ulp_flow_tbl flow_tbl;
76 uint16_t *func_id_tbl;
77 uint32_t func_id_tbl_size;
78 struct ulp_fdb_parent_child_db parent_child_db;
81 /* flow db resource params to add resources */
82 struct ulp_flow_db_res_params {
83 enum tf_dir direction;
84 enum bnxt_ulp_resource_func resource_func;
85 uint8_t resource_type;
86 uint8_t resource_sub_type;
88 uint8_t critical_resource;
89 uint64_t resource_hndl;
93 * Initialize the flow database. Memory is allocated in this
94 * call and assigned to the flow database.
96 * ulp_ctxt [in] Ptr to ulp context
98 * Returns 0 on success or negative number on failure.
100 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
103 * Deinitialize the flow database. Memory is deallocated in
104 * this call and all flows should have been purged before this
107 * ulp_ctxt [in] Ptr to ulp context
109 * Returns 0 on success.
111 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
114 * Allocate the flow database entry
116 * ulp_ctxt [in] Ptr to ulp_context
117 * tbl_idx [in] Specify it is regular or default flow
118 * func_id [in] The function id of the device.Valid only for regular flows.
119 * fid [out] The index to the flow entry
121 * returns 0 on success and negative on failure.
124 ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
125 enum bnxt_ulp_fdb_type flow_type,
130 * Allocate the flow database entry.
131 * The params->critical_resource has to be set to 0 to allocate a new resource.
133 * ulp_ctxt [in] Ptr to ulp_context
134 * tbl_idx [in] Specify it is regular or default flow
135 * fid [in] The index to the flow entry
136 * params [in] The contents to be copied into resource
138 * returns 0 on success and negative on failure.
141 ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
142 enum bnxt_ulp_fdb_type flow_type,
144 struct ulp_flow_db_res_params *params);
147 * Free the flow database entry.
148 * The params->critical_resource has to be set to 1 to free the first resource.
150 * ulp_ctxt [in] Ptr to ulp_context
151 * tbl_idx [in] Specify it is regular or default flow
152 * fid [in] The index to the flow entry
153 * params [in/out] The contents to be copied into params.
154 * Only the critical_resource needs to be set by the caller.
156 * Returns 0 on success and negative on failure.
159 ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
160 enum bnxt_ulp_fdb_type flow_type,
162 struct ulp_flow_db_res_params *params);
165 * Free the flow database entry
167 * ulp_ctxt [in] Ptr to ulp_context
168 * tbl_idx [in] Specify it is regular or default flow
169 * fid [in] The index to the flow entry
171 * returns 0 on success and negative on failure.
174 ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
175 enum bnxt_ulp_fdb_type tbl_idx,
179 *Get the flow database entry details
181 * ulp_ctxt [in] Ptr to ulp_context
182 * tbl_idx [in] Specify it is regular or default flow
183 * fid [in] The index to the flow entry
184 * nxt_idx [in/out] the index to the next entry
185 * params [out] The contents to be copied into params.
187 * returns 0 on success and negative on failure.
190 ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
191 enum bnxt_ulp_fdb_type flow_type,
194 struct ulp_flow_db_res_params *params);
197 * Flush all flows in the flow database.
199 * ulp_ctxt [in] Ptr to ulp context
200 * tbl_idx [in] The index to table
202 * returns 0 on success or negative number on failure
205 ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
209 * Flush all flows in the flow database that belong to a device function.
211 * ulp_ctxt [in] Ptr to ulp context
212 * tbl_idx [in] The index to table
214 * returns 0 on success or negative number on failure
217 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
221 * Flush all flows in the flow database that are associated with the session.
223 * ulp_ctxt [in] Ptr to ulp context
225 * returns 0 on success or negative number on failure
228 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
231 * Check that flow id matches the function id or not
233 * ulp_ctxt [in] Ptr to ulp context
234 * flow_id [in] flow id of the flow.
235 * func_id [in] The func_id to be set, for reset pass zero.
237 * returns true on success or false on failure
240 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
245 * Api to get the cfa action pointer from a flow.
247 * ulp_ctxt [in] Ptr to ulp context
248 * flow_id [in] flow id
249 * cfa_action [out] The resource handle stored in the flow database
251 * returns 0 on success
254 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx,
256 uint16_t *cfa_action);
258 * Allocate the entry in the parent-child database
260 * ulp_ctxt [in] Ptr to ulp_context
261 * fid [in] The flow id to the flow entry
263 * returns index on success and negative on failure.
266 ulp_flow_db_parent_flow_alloc(struct bnxt_ulp_context *ulp_ctxt,
270 * Free the entry in the parent-child database
272 * ulp_ctxt [in] Ptr to ulp_context
273 * fid [in] The flow id to the flow entry
275 * returns 0 on success and negative on failure.
278 ulp_flow_db_parent_flow_free(struct bnxt_ulp_context *ulp_ctxt,
282 * Set or reset the child flow in the parent-child database
284 * ulp_ctxt [in] Ptr to ulp_context
285 * parent_fid [in] The flow id of the parent flow entry
286 * child_fid [in] The flow id of the child flow entry
287 * set_flag [in] Use 1 for setting child, 0 to reset
289 * returns zero on success and negative on failure.
292 ulp_flow_db_parent_child_flow_set(struct bnxt_ulp_context *ulp_ctxt,
298 * Get the parent index from the parent-child database
300 * ulp_ctxt [in] Ptr to ulp_context
301 * parent_fid [in] The flow id of the parent flow entry
302 * parent_idx [out] The parent index of parent flow entry
304 * returns zero on success and negative on failure.
307 ulp_flow_db_parent_flow_idx_get(struct bnxt_ulp_context *ulp_ctxt,
309 uint32_t *parent_idx);
312 * Get the next child flow in the parent-child database
314 * ulp_ctxt [in] Ptr to ulp_context
315 * parent_fid [in] The flow id of the parent flow entry
316 * child_fid [in/out] The flow id of the child flow entry
318 * returns zero on success and negative on failure.
319 * Pass child_fid as zero for first entry.
322 ulp_flow_db_parent_child_flow_next_entry_get(struct bnxt_ulp_flow_db *flow_db,
324 uint32_t *child_fid);
327 * Orphan the child flow entry
328 * This is called only for child flows that have
329 * BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW resource
331 * ulp_ctxt [in] Ptr to ulp_context
332 * flow_type [in] Specify it is regular or default flow
333 * fid [in] The index to the flow entry
335 * Returns 0 on success and negative on failure.
338 ulp_flow_db_child_flow_reset(struct bnxt_ulp_context *ulp_ctxt,
339 enum bnxt_ulp_fdb_type flow_type,
343 * Create parent flow in the parent flow tbl
345 * parms [in] Ptr to mapper params
347 * Returns 0 on success and negative on failure.
350 ulp_flow_db_parent_flow_create(struct bnxt_ulp_mapper_parms *parms);
353 * Create child flow in the parent flow tbl
355 * parms [in] Ptr to mapper params
357 * Returns 0 on success and negative on failure.
360 ulp_flow_db_child_flow_create(struct bnxt_ulp_mapper_parms *parms);
363 * Update the parent counters
365 * ulp_ctxt [in] Ptr to ulp_context
366 * parent_fid [in] The flow id of the parent flow entry
367 * packet_count [in] - packet count
368 * byte_count [in] - byte count
370 * returns 0 on success
373 ulp_flow_db_parent_flow_count_update(struct bnxt_ulp_context *ulp_ctxt,
375 uint64_t packet_count,
376 uint64_t byte_count);
378 * Get the parent accumulation counters
380 * ulp_ctxt [in] Ptr to ulp_context
381 * parent_fid [in] The flow id of the parent flow entry
382 * packet_count [out] - packet count
383 * byte_count [out] - byte count
385 * returns 0 on success
388 ulp_flow_db_parent_flow_count_get(struct bnxt_ulp_context *ulp_ctxt,
390 uint64_t *packet_count,
391 uint64_t *byte_count);
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);
403 #endif /* _ULP_FLOW_DB_H_ */