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