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.h"
12 #define BNXT_FLOW_DB_DEFAULT_NUM_FLOWS 128
13 #define BNXT_FLOW_DB_DEFAULT_NUM_RESOURCES 5
16 * Structure for the flow database resource information
17 * The below structure is based on the below paritions
18 * nxt_resource_idx = dir[31],resource_func_upper[30:28],nxt_resource_idx[27:0]
19 * If resource_func is EM_TBL then use resource_em_handle.
20 * Else the other part of the union is used and
21 * resource_func is resource_func_upper[30:28] << 5 | resource_func_lower
23 struct ulp_fdb_resource_info {
24 /* Points to next resource in the chained list. */
25 uint32_t nxt_resource_idx;
27 uint64_t resource_em_handle;
29 uint8_t resource_func_lower;
30 uint8_t resource_type;
31 uint8_t resource_sub_type;
33 uint32_t resource_hndl;
38 /* Structure for the flow database resource information. */
39 struct bnxt_ulp_flow_tbl {
40 /* Flow tbl is the resource object list for each flow id. */
41 struct ulp_fdb_resource_info *flow_resources;
43 /* Flow table stack to track free list of resources. */
44 uint32_t *flow_tbl_stack;
48 /* Table to track the active flows. */
49 uint64_t *active_flow_tbl;
51 uint32_t num_resources;
54 /* Flow database supports two tables. */
55 enum bnxt_ulp_flow_db_tables {
56 BNXT_ULP_REGULAR_FLOW_TABLE,
57 BNXT_ULP_DEFAULT_FLOW_TABLE,
58 BNXT_ULP_FLOW_TABLE_MAX
61 /* Structure for the flow database resource information. */
62 struct bnxt_ulp_flow_db {
63 struct bnxt_ulp_flow_tbl flow_tbl[BNXT_ULP_FLOW_TABLE_MAX];
64 uint16_t *func_id_tbl;
65 uint32_t func_id_tbl_size;
68 /* flow db resource params to add resources */
69 struct ulp_flow_db_res_params {
70 enum tf_dir direction;
71 enum bnxt_ulp_resource_func resource_func;
72 uint8_t resource_type;
73 uint8_t resource_sub_type;
75 uint8_t critical_resource;
76 uint64_t resource_hndl;
80 * Initialize the flow database. Memory is allocated in this
81 * call and assigned to the flow database.
83 * ulp_ctxt [in] Ptr to ulp context
85 * Returns 0 on success or negative number on failure.
87 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
90 * Deinitialize the flow database. Memory is deallocated in
91 * this call and all flows should have been purged before this
94 * ulp_ctxt [in] Ptr to ulp context
96 * Returns 0 on success.
98 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
101 * Allocate the flow database entry
103 * ulp_ctxt [in] Ptr to ulp_context
104 * tbl_idx [in] Specify it is regular or default flow
105 * func_id [in] The function id of the device.Valid only for regular flows.
106 * fid [out] The index to the flow entry
108 * returns 0 on success and negative on failure.
110 int32_t ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
111 enum bnxt_ulp_flow_db_tables tbl_idx,
116 * Allocate the flow database entry.
117 * The params->critical_resource has to be set to 0 to allocate a new resource.
119 * ulp_ctxt [in] Ptr to ulp_context
120 * tbl_idx [in] Specify it is regular or default flow
121 * fid [in] The index to the flow entry
122 * params [in] The contents to be copied into resource
124 * returns 0 on success and negative on failure.
126 int32_t ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
127 enum bnxt_ulp_flow_db_tables tbl_idx,
129 struct ulp_flow_db_res_params *params);
132 * Free the flow database entry.
133 * The params->critical_resource has to be set to 1 to free the first 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/out] The contents to be copied into params.
139 * Only the critical_resource needs to be set by the caller.
141 * Returns 0 on success and negative on failure.
143 int32_t ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
144 enum bnxt_ulp_flow_db_tables tbl_idx,
146 struct ulp_flow_db_res_params *params);
149 * Free the flow database entry
151 * ulp_ctxt [in] Ptr to ulp_context
152 * tbl_idx [in] Specify it is regular or default flow
153 * fid [in] The index to the flow entry
155 * returns 0 on success and negative on failure.
157 int32_t ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
158 enum bnxt_ulp_flow_db_tables tbl_idx,
162 *Get the flow database entry details
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
167 * nxt_idx [in/out] the index to the next entry
168 * params [out] The contents to be copied into params.
170 * returns 0 on success and negative on failure.
172 int32_t ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
173 enum bnxt_ulp_flow_db_tables tbl_idx,
176 struct ulp_flow_db_res_params *params);
179 * Flush all flows in the flow database.
181 * ulp_ctxt [in] Ptr to ulp context
182 * tbl_idx [in] The index to table
184 * returns 0 on success or negative number on failure
186 int32_t ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
190 * Flush all flows in the flow database that belong to a device function.
192 * ulp_ctxt [in] Ptr to ulp context
193 * tbl_idx [in] The index to table
195 * returns 0 on success or negative number on failure
198 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
202 * Flush all flows in the flow database that are associated with the session.
204 * ulp_ctxt [in] Ptr to ulp context
206 * returns 0 on success or negative number on failure
209 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
212 * Check that flow id matches the function id or not
214 * ulp_ctxt [in] Ptr to ulp context
215 * flow_db [in] Ptr to flow table
216 * func_id [in] The func_id to be set, for reset pass zero.
218 * returns true on success or false on failure
221 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
226 * Api to get the cfa action pointer from a flow.
228 * ulp_ctxt [in] Ptr to ulp context
229 * flow_id [in] flow id
230 * cfa_action [out] The resource handle stored in the flow database
232 * returns 0 on success
235 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx,
237 uint32_t *cfa_action);
239 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
241 * Dump the flow database entry details
243 * ulp_ctxt [in] Ptr to ulp_context
247 int32_t ulp_flow_db_debug_dump(struct bnxt_ulp_context *ulp_ctxt);
250 #endif /* _ULP_FLOW_DB_H_ */