a2a04cef42f601e51b1d04aa8979e9788e1ac6ab
[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         uint32_t        counter_acc;
60         uint64_t        pkt_count;
61         uint64_t        byte_count;
62         uint64_t        *child_fid_bitset;
63         uint32_t        f2_cnt;
64         uint8_t         tun_idx;
65 };
66
67 /* Structure to maintain parent-child flow relationships */
68 struct ulp_fdb_parent_child_db {
69         struct ulp_fdb_parent_info      *parent_flow_tbl;
70         uint32_t                        child_bitset_size;
71         uint32_t                        entries_count;
72         uint8_t                         *parent_flow_tbl_mem;
73 };
74
75 /* Structure for the flow database resource information. */
76 struct bnxt_ulp_flow_db {
77         struct bnxt_ulp_flow_tbl        flow_tbl;
78         uint16_t                        *func_id_tbl;
79         uint32_t                        func_id_tbl_size;
80         struct ulp_fdb_parent_child_db  parent_child_db;
81 };
82
83 /* flow db resource params to add resources */
84 struct ulp_flow_db_res_params {
85         enum tf_dir                     direction;
86         enum bnxt_ulp_resource_func     resource_func;
87         uint8_t                         resource_type;
88         uint8_t                         resource_sub_type;
89         uint8_t                         reserved;
90         uint8_t                         critical_resource;
91         uint64_t                        resource_hndl;
92 };
93
94 /*
95  * Initialize the flow database. Memory is allocated in this
96  * call and assigned to the flow database.
97  *
98  * ulp_ctxt [in] Ptr to ulp context
99  *
100  * Returns 0 on success or negative number on failure.
101  */
102 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
103
104 /*
105  * Deinitialize the flow database. Memory is deallocated in
106  * this call and all flows should have been purged before this
107  * call.
108  *
109  * ulp_ctxt [in] Ptr to ulp context
110  *
111  * Returns 0 on success.
112  */
113 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
114
115 /*
116  * Allocate the flow database entry
117  *
118  * ulp_ctxt [in] Ptr to ulp_context
119  * tbl_idx [in] Specify it is regular or default flow
120  * func_id [in] The function id of the device.Valid only for regular flows.
121  * fid [out] The index to the flow entry
122  *
123  * returns 0 on success and negative on failure.
124  */
125 int32_t
126 ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
127                       enum bnxt_ulp_fdb_type flow_type,
128                       uint16_t func_id,
129                       uint32_t *fid);
130
131 /*
132  * Allocate the flow database entry.
133  * The params->critical_resource has to be set to 0 to allocate a new resource.
134  *
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] The contents to be copied into resource
139  *
140  * returns 0 on success and negative on failure.
141  */
142 int32_t
143 ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
144                          enum bnxt_ulp_fdb_type flow_type,
145                          uint32_t fid,
146                          struct ulp_flow_db_res_params *params);
147
148 /*
149  * Free the flow database entry.
150  * The params->critical_resource has to be set to 1 to free the first resource.
151  *
152  * ulp_ctxt [in] Ptr to ulp_context
153  * tbl_idx [in] Specify it is regular or default flow
154  * fid [in] The index to the flow entry
155  * params [in/out] The contents to be copied into params.
156  * Only the critical_resource needs to be set by the caller.
157  *
158  * Returns 0 on success and negative on failure.
159  */
160 int32_t
161 ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
162                          enum bnxt_ulp_fdb_type flow_type,
163                          uint32_t fid,
164                          struct ulp_flow_db_res_params *params);
165
166 /*
167  * Free the flow database entry
168  *
169  * ulp_ctxt [in] Ptr to ulp_context
170  * tbl_idx [in] Specify it is regular or default flow
171  * fid [in] The index to the flow entry
172  *
173  * returns 0 on success and negative on failure.
174  */
175 int32_t
176 ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
177                      enum bnxt_ulp_fdb_type tbl_idx,
178                      uint32_t fid);
179
180 /*
181  *Get the flow database entry details
182  *
183  * ulp_ctxt [in] Ptr to ulp_context
184  * tbl_idx [in] Specify it is regular or default flow
185  * fid [in] The index to the flow entry
186  * nxt_idx [in/out] the index to the next entry
187  * params [out] The contents to be copied into params.
188  *
189  * returns 0 on success and negative on failure.
190  */
191 int32_t
192 ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
193                          enum bnxt_ulp_fdb_type flow_type,
194                          uint32_t fid,
195                          uint32_t *nxt_idx,
196                          struct ulp_flow_db_res_params *params);
197
198 /*
199  * Flush all flows in the flow database.
200  *
201  * ulp_ctxt [in] Ptr to ulp context
202  * tbl_idx [in] The index to table
203  *
204  * returns 0 on success or negative number on failure
205  */
206 int32_t
207 ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
208                         uint32_t idx);
209
210 /*
211  * Flush all flows in the flow database that belong to a device function.
212  *
213  * ulp_ctxt [in] Ptr to ulp context
214  * tbl_idx [in] The index to table
215  *
216  * returns 0 on success or negative number on failure
217  */
218 int32_t
219 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
220                                 uint16_t func_id);
221
222 /*
223  * Flush all flows in the flow database that are associated with the session.
224  *
225  * ulp_ctxt [in] Ptr to ulp context
226  *
227  * returns 0 on success or negative number on failure
228  */
229 int32_t
230 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
231
232 /*
233  * Check that flow id matches the function id or not
234  *
235  * ulp_ctxt [in] Ptr to ulp context
236  * flow_id [in] flow id of the flow.
237  * func_id [in] The func_id to be set, for reset pass zero.
238  *
239  * returns true on success or false on failure
240  */
241 bool
242 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
243                                uint32_t flow_id,
244                                uint32_t func_id);
245
246 /*
247  * Api to get the cfa action pointer from a flow.
248  *
249  * ulp_ctxt [in] Ptr to ulp context
250  * flow_id [in] flow id
251  * cfa_action [out] The resource handle stored in the flow database
252  *
253  * returns 0 on success
254  */
255 int32_t
256 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx,
257                                    uint32_t flow_id,
258                                    uint16_t *cfa_action);
259 /*
260  * Allocate the entry in the parent-child database
261  *
262  * ulp_ctxt [in] Ptr to ulp_context
263  * fid [in] The flow id to the flow entry
264  *
265  * returns index on success and negative on failure.
266  */
267 int32_t
268 ulp_flow_db_parent_flow_alloc(struct bnxt_ulp_context *ulp_ctxt,
269                               uint32_t fid);
270
271 /*
272  * Free the entry in the parent-child database
273  *
274  * ulp_ctxt [in] Ptr to ulp_context
275  * fid [in] The flow id to the flow entry
276  *
277  * returns 0 on success and negative on failure.
278  */
279 int32_t
280 ulp_flow_db_parent_flow_free(struct bnxt_ulp_context *ulp_ctxt,
281                              uint32_t fid);
282
283 /*
284  * Set or reset the child flow in the parent-child database
285  *
286  * ulp_ctxt [in] Ptr to ulp_context
287  * parent_fid [in] The flow id of the parent flow entry
288  * child_fid [in] The flow id of the child flow entry
289  * set_flag [in] Use 1 for setting child, 0 to reset
290  *
291  * returns zero on success and negative on failure.
292  */
293 int32_t
294 ulp_flow_db_parent_child_flow_set(struct bnxt_ulp_context *ulp_ctxt,
295                                   uint32_t parent_fid,
296                                   uint32_t child_fid,
297                                   uint32_t set_flag);
298
299 /*
300  * Get the parent index from the parent-child database
301  *
302  * ulp_ctxt [in] Ptr to ulp_context
303  * parent_fid [in] The flow id of the parent flow entry
304  * parent_idx [out] The parent index of parent flow entry
305  *
306  * returns zero on success and negative on failure.
307  */
308 int32_t
309 ulp_flow_db_parent_flow_idx_get(struct bnxt_ulp_context *ulp_ctxt,
310                                 uint32_t parent_fid,
311                                 uint32_t *parent_idx);
312
313 /*
314  * Get the next child flow in the parent-child database
315  *
316  * ulp_ctxt [in] Ptr to ulp_context
317  * parent_fid [in] The flow id of the parent flow entry
318  * child_fid [in/out] The flow id of the child flow entry
319  *
320  * returns zero on success and negative on failure.
321  * Pass child_fid as zero for first entry.
322  */
323 int32_t
324 ulp_flow_db_parent_child_flow_next_entry_get(struct bnxt_ulp_flow_db *flow_db,
325                                              uint32_t parent_idx,
326                                              uint32_t *child_fid);
327
328 /*
329  * Orphan the child flow entry
330  * This is called only for child flows that have
331  * BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW resource
332  *
333  * ulp_ctxt [in] Ptr to ulp_context
334  * flow_type [in] Specify it is regular or default flow
335  * fid [in] The index to the flow entry
336  *
337  * Returns 0 on success and negative on failure.
338  */
339 int32_t
340 ulp_flow_db_child_flow_reset(struct bnxt_ulp_context *ulp_ctxt,
341                              enum bnxt_ulp_fdb_type flow_type,
342                              uint32_t fid);
343
344 /*
345  * Create parent flow in the parent flow tbl
346  *
347  * parms [in] Ptr to mapper params
348  *
349  * Returns 0 on success and negative on failure.
350  */
351 int32_t
352 ulp_flow_db_parent_flow_create(struct bnxt_ulp_mapper_parms *parms);
353
354 /*
355  * Create child flow in the parent flow tbl
356  *
357  * parms [in] Ptr to mapper params
358  *
359  * Returns 0 on success and negative on failure.
360  */
361 int32_t
362 ulp_flow_db_child_flow_create(struct bnxt_ulp_mapper_parms *parms);
363
364 /*
365  * Update the parent counters
366  *
367  * ulp_ctxt [in] Ptr to ulp_context
368  * parent_fid [in] The flow id of the parent flow entry
369  * packet_count [in] - packet count
370  * byte_count [in] - byte count
371  *
372  * returns 0 on success
373  */
374 int32_t
375 ulp_flow_db_parent_flow_count_update(struct bnxt_ulp_context *ulp_ctxt,
376                                      uint32_t parent_fid,
377                                      uint64_t packet_count,
378                                      uint64_t byte_count);
379 /*
380  * Get the parent accumulation counters
381  *
382  * ulp_ctxt [in] Ptr to ulp_context
383  * parent_fid [in] The flow id of the parent flow entry
384  * packet_count [out] - packet count
385  * byte_count [out] - byte count
386  *
387  * returns 0 on success
388  */
389 int32_t
390 ulp_flow_db_parent_flow_count_get(struct bnxt_ulp_context *ulp_ctxt,
391                                   uint32_t parent_fid,
392                                   uint64_t *packet_count,
393                                   uint64_t *byte_count,
394                                   uint8_t count_reset);
395
396 /*
397  * reset the parent accumulation counters
398  *
399  * ulp_ctxt [in] Ptr to ulp_context
400  *
401  * returns none
402  */
403 void
404 ulp_flow_db_parent_flow_count_reset(struct bnxt_ulp_context *ulp_ctxt);
405
406 #endif /* _ULP_FLOW_DB_H_ */