net/bnxt: support parent child flow database
[dpdk.git] / drivers / net / bnxt / tf_ulp / ulp_flow_db.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2019 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _ULP_FLOW_DB_H_
7 #define _ULP_FLOW_DB_H_
8
9 #include "bnxt_ulp.h"
10 #include "ulp_template_db_enum.h"
11
12 #define BNXT_FLOW_DB_DEFAULT_NUM_FLOWS          512
13 #define BNXT_FLOW_DB_DEFAULT_NUM_RESOURCES      8
14
15 /*
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
22  */
23 struct ulp_fdb_resource_info {
24         /* Points to next resource in the chained list. */
25         uint32_t                        nxt_resource_idx;
26         union {
27                 uint64_t                resource_em_handle;
28                 struct {
29                         uint8_t         resource_func_lower;
30                         uint8_t         resource_type;
31                         uint8_t         resource_sub_type;
32                         uint8_t         reserved;
33                         uint32_t        resource_hndl;
34                 };
35         };
36 };
37
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;
42
43         /* Flow table stack to track free list of resources. */
44         uint32_t        *flow_tbl_stack;
45         uint32_t        head_index;
46         uint32_t        tail_index;
47
48         /* Table to track the active flows. */
49         uint64_t        *active_reg_flows;
50         uint64_t        *active_dflt_flows;
51         uint32_t        num_flows;
52         uint32_t        num_resources;
53 };
54
55 /* Structure to maintain parent-child flow relationships */
56 struct ulp_fdb_parent_info {
57         uint32_t        parent_fid;
58         uint64_t        *child_fid_bitset;
59 };
60
61 /* Structure to maintain parent-child flow relationships */
62 struct ulp_fdb_parent_child_db {
63         struct ulp_fdb_parent_info      *parent_flow_tbl;
64         uint32_t                        child_bitset_size;
65         uint32_t                        entries_count;
66         uint8_t                         *parent_flow_tbl_mem;
67 };
68
69 /* Structure for the flow database resource information. */
70 struct bnxt_ulp_flow_db {
71         struct bnxt_ulp_flow_tbl        flow_tbl;
72         uint16_t                        *func_id_tbl;
73         uint32_t                        func_id_tbl_size;
74         struct ulp_fdb_parent_child_db  parent_child_db;
75 };
76
77 /* flow db resource params to add resources */
78 struct ulp_flow_db_res_params {
79         enum tf_dir                     direction;
80         enum bnxt_ulp_resource_func     resource_func;
81         uint8_t                         resource_type;
82         uint8_t                         resource_sub_type;
83         uint8_t                         reserved;
84         uint8_t                         critical_resource;
85         uint64_t                        resource_hndl;
86 };
87
88 /*
89  * Initialize the flow database. Memory is allocated in this
90  * call and assigned to the flow database.
91  *
92  * ulp_ctxt [in] Ptr to ulp context
93  *
94  * Returns 0 on success or negative number on failure.
95  */
96 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
97
98 /*
99  * Deinitialize the flow database. Memory is deallocated in
100  * this call and all flows should have been purged before this
101  * call.
102  *
103  * ulp_ctxt [in] Ptr to ulp context
104  *
105  * Returns 0 on success.
106  */
107 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
108
109 /*
110  * Allocate the flow database entry
111  *
112  * ulp_ctxt [in] Ptr to ulp_context
113  * tbl_idx [in] Specify it is regular or default flow
114  * func_id [in] The function id of the device.Valid only for regular flows.
115  * fid [out] The index to the flow entry
116  *
117  * returns 0 on success and negative on failure.
118  */
119 int32_t
120 ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
121                       enum bnxt_ulp_fdb_type flow_type,
122                       uint16_t func_id,
123                       uint32_t *fid);
124
125 /*
126  * Allocate the flow database entry.
127  * The params->critical_resource has to be set to 0 to allocate a new resource.
128  *
129  * ulp_ctxt [in] Ptr to ulp_context
130  * tbl_idx [in] Specify it is regular or default flow
131  * fid [in] The index to the flow entry
132  * params [in] The contents to be copied into resource
133  *
134  * returns 0 on success and negative on failure.
135  */
136 int32_t
137 ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
138                          enum bnxt_ulp_fdb_type flow_type,
139                          uint32_t fid,
140                          struct ulp_flow_db_res_params *params);
141
142 /*
143  * Free the flow database entry.
144  * The params->critical_resource has to be set to 1 to free the first resource.
145  *
146  * ulp_ctxt [in] Ptr to ulp_context
147  * tbl_idx [in] Specify it is regular or default flow
148  * fid [in] The index to the flow entry
149  * params [in/out] The contents to be copied into params.
150  * Only the critical_resource needs to be set by the caller.
151  *
152  * Returns 0 on success and negative on failure.
153  */
154 int32_t
155 ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
156                          enum bnxt_ulp_fdb_type flow_type,
157                          uint32_t fid,
158                          struct ulp_flow_db_res_params *params);
159
160 /*
161  * Free the flow database entry
162  *
163  * ulp_ctxt [in] Ptr to ulp_context
164  * tbl_idx [in] Specify it is regular or default flow
165  * fid [in] The index to the flow entry
166  *
167  * returns 0 on success and negative on failure.
168  */
169 int32_t
170 ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
171                      enum bnxt_ulp_fdb_type tbl_idx,
172                      uint32_t fid);
173
174 /*
175  *Get the flow database entry details
176  *
177  * ulp_ctxt [in] Ptr to ulp_context
178  * tbl_idx [in] Specify it is regular or default flow
179  * fid [in] The index to the flow entry
180  * nxt_idx [in/out] the index to the next entry
181  * params [out] The contents to be copied into params.
182  *
183  * returns 0 on success and negative on failure.
184  */
185 int32_t
186 ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
187                          enum bnxt_ulp_fdb_type flow_type,
188                          uint32_t fid,
189                          uint32_t *nxt_idx,
190                          struct ulp_flow_db_res_params *params);
191
192 /*
193  * Flush all flows in the flow database.
194  *
195  * ulp_ctxt [in] Ptr to ulp context
196  * tbl_idx [in] The index to table
197  *
198  * returns 0 on success or negative number on failure
199  */
200 int32_t
201 ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
202                         uint32_t idx);
203
204 /*
205  * Flush all flows in the flow database that belong to a device function.
206  *
207  * ulp_ctxt [in] Ptr to ulp context
208  * tbl_idx [in] The index to table
209  *
210  * returns 0 on success or negative number on failure
211  */
212 int32_t
213 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
214                                 uint16_t func_id);
215
216 /*
217  * Flush all flows in the flow database that are associated with the session.
218  *
219  * ulp_ctxt [in] Ptr to ulp context
220  *
221  * returns 0 on success or negative number on failure
222  */
223 int32_t
224 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
225
226 /*
227  * Check that flow id matches the function id or not
228  *
229  * ulp_ctxt [in] Ptr to ulp context
230  * flow_id [in] flow id of the flow.
231  * func_id [in] The func_id to be set, for reset pass zero.
232  *
233  * returns true on success or false on failure
234  */
235 bool
236 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
237                                uint32_t flow_id,
238                                uint32_t func_id);
239
240 /*
241  * Api to get the cfa action pointer from a flow.
242  *
243  * ulp_ctxt [in] Ptr to ulp context
244  * flow_id [in] flow id
245  * cfa_action [out] The resource handle stored in the flow database
246  *
247  * returns 0 on success
248  */
249 int32_t
250 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx,
251                                    uint32_t flow_id,
252                                    uint16_t *cfa_action);
253 /*
254  * Allocate the entry in the parent-child database
255  *
256  * ulp_ctxt [in] Ptr to ulp_context
257  * fid [in] The flow id to the flow entry
258  *
259  * returns index on success and negative on failure.
260  */
261 int32_t
262 ulp_flow_db_parent_flow_alloc(struct bnxt_ulp_context *ulp_ctxt,
263                               uint32_t fid);
264
265 /*
266  * Free the entry in the parent-child database
267  *
268  * ulp_ctxt [in] Ptr to ulp_context
269  * fid [in] The flow id to the flow entry
270  *
271  * returns 0 on success and negative on failure.
272  */
273 int32_t
274 ulp_flow_db_parent_flow_free(struct bnxt_ulp_context *ulp_ctxt,
275                              uint32_t fid);
276
277 /*
278  * Set or reset the child flow in the parent-child database
279  *
280  * ulp_ctxt [in] Ptr to ulp_context
281  * parent_fid [in] The flow id of the parent flow entry
282  * child_fid [in] The flow id of the child flow entry
283  * set_flag [in] Use 1 for setting child, 0 to reset
284  *
285  * returns zero on success and negative on failure.
286  */
287 int32_t
288 ulp_flow_db_parent_child_flow_set(struct bnxt_ulp_context *ulp_ctxt,
289                                   uint32_t parent_fid,
290                                   uint32_t child_fid,
291                                   uint32_t set_flag);
292
293 /*
294  * Get the parent index from the parent-child database
295  *
296  * ulp_ctxt [in] Ptr to ulp_context
297  * parent_fid [in] The flow id of the parent flow entry
298  * parent_idx [out] The parent index of parent flow entry
299  *
300  * returns zero on success and negative on failure.
301  */
302 int32_t
303 ulp_flow_db_parent_flow_idx_get(struct bnxt_ulp_context *ulp_ctxt,
304                                 uint32_t parent_fid,
305                                 uint32_t *parent_idx);
306
307 /*
308  * Get the next child flow in the parent-child database
309  *
310  * ulp_ctxt [in] Ptr to ulp_context
311  * parent_fid [in] The flow id of the parent flow entry
312  * child_fid [in/out] The flow id of the child flow entry
313  *
314  * returns zero on success and negative on failure.
315  * Pass child_fid as zero for first entry.
316  */
317 int32_t
318 ulp_flow_db_parent_child_flow_next_entry_get(struct bnxt_ulp_flow_db *flow_db,
319                                              uint32_t parent_idx,
320                                              uint32_t *child_fid);
321
322
323 #endif /* _ULP_FLOW_DB_H_ */