net/bnxt: add session and function flow flush
[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.h"
11
12 #define BNXT_FLOW_DB_DEFAULT_NUM_FLOWS          128
13 #define BNXT_FLOW_DB_DEFAULT_NUM_RESOURCES      5
14
15 /* Structure for the flow database resource information. */
16 struct ulp_fdb_resource_info {
17         /* Points to next resource in the chained list. */
18         uint32_t        nxt_resource_idx;
19         union {
20                 uint64_t        resource_em_handle;
21                 struct {
22                         uint32_t        resource_type;
23                         uint32_t        resource_hndl;
24                 };
25         };
26 };
27
28 /* Structure for the flow database resource information. */
29 struct bnxt_ulp_flow_tbl {
30         /* Flow tbl is the resource object list for each flow id. */
31         struct ulp_fdb_resource_info    *flow_resources;
32
33         /* Flow table stack to track free list of resources. */
34         uint32_t        *flow_tbl_stack;
35         uint32_t        head_index;
36         uint32_t        tail_index;
37
38         /* Table to track the active flows. */
39         uint64_t        *active_flow_tbl;
40         uint32_t        num_flows;
41         uint32_t        num_resources;
42 };
43
44 /* Flow database supports two tables. */
45 enum bnxt_ulp_flow_db_tables {
46         BNXT_ULP_REGULAR_FLOW_TABLE,
47         BNXT_ULP_DEFAULT_FLOW_TABLE,
48         BNXT_ULP_FLOW_TABLE_MAX
49 };
50
51 /* Structure for the flow database resource information. */
52 struct bnxt_ulp_flow_db {
53         struct bnxt_ulp_flow_tbl        flow_tbl[BNXT_ULP_FLOW_TABLE_MAX];
54         uint16_t                        *func_id_tbl;
55         uint32_t                        func_id_tbl_size;
56 };
57
58 /* flow db resource params to add resources */
59 struct ulp_flow_db_res_params {
60         enum tf_dir                     direction;
61         enum bnxt_ulp_resource_func     resource_func;
62         uint64_t                        resource_hndl;
63         uint32_t                        resource_type;
64         uint32_t                        critical_resource;
65 };
66
67 /*
68  * Initialize the flow database. Memory is allocated in this
69  * call and assigned to the flow database.
70  *
71  * ulp_ctxt [in] Ptr to ulp context
72  *
73  * Returns 0 on success or negative number on failure.
74  */
75 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
76
77 /*
78  * Deinitialize the flow database. Memory is deallocated in
79  * this call and all flows should have been purged before this
80  * call.
81  *
82  * ulp_ctxt [in] Ptr to ulp context
83  *
84  * Returns 0 on success.
85  */
86 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
87
88 /*
89  * Allocate the flow database entry
90  *
91  * ulp_ctxt [in] Ptr to ulp_context
92  * tbl_idx [in] Specify it is regular or default flow
93  * func_id [in] The function id of the device.Valid only for regular flows.
94  * fid [out] The index to the flow entry
95  *
96  * returns 0 on success and negative on failure.
97  */
98 int32_t ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
99                               enum bnxt_ulp_flow_db_tables tbl_idx,
100                               uint16_t func_id,
101                               uint32_t *fid);
102
103 /*
104  * Allocate the flow database entry.
105  * The params->critical_resource has to be set to 0 to allocate a new resource.
106  *
107  * ulp_ctxt [in] Ptr to ulp_context
108  * tbl_idx [in] Specify it is regular or default flow
109  * fid [in] The index to the flow entry
110  * params [in] The contents to be copied into resource
111  *
112  * returns 0 on success and negative on failure.
113  */
114 int32_t ulp_flow_db_resource_add(struct bnxt_ulp_context        *ulp_ctxt,
115                                  enum bnxt_ulp_flow_db_tables   tbl_idx,
116                                  uint32_t                       fid,
117                                  struct ulp_flow_db_res_params  *params);
118
119 /*
120  * Free the flow database entry.
121  * The params->critical_resource has to be set to 1 to free the first resource.
122  *
123  * ulp_ctxt [in] Ptr to ulp_context
124  * tbl_idx [in] Specify it is regular or default flow
125  * fid [in] The index to the flow entry
126  * params [in/out] The contents to be copied into params.
127  * Only the critical_resource needs to be set by the caller.
128  *
129  * Returns 0 on success and negative on failure.
130  */
131 int32_t ulp_flow_db_resource_del(struct bnxt_ulp_context        *ulp_ctxt,
132                                  enum bnxt_ulp_flow_db_tables   tbl_idx,
133                                  uint32_t                       fid,
134                                  struct ulp_flow_db_res_params  *params);
135
136 /*
137  * Free the flow database entry
138  *
139  * ulp_ctxt [in] Ptr to ulp_context
140  * tbl_idx [in] Specify it is regular or default flow
141  * fid [in] The index to the flow entry
142  *
143  * returns 0 on success and negative on failure.
144  */
145 int32_t ulp_flow_db_fid_free(struct bnxt_ulp_context            *ulp_ctxt,
146                              enum bnxt_ulp_flow_db_tables       tbl_idx,
147                              uint32_t                           fid);
148
149 /*
150  *Get the flow database entry details
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  * nxt_idx [in/out] the index to the next entry
156  * params [out] The contents to be copied into params.
157  *
158  * returns 0 on success and negative on failure.
159  */
160 int32_t ulp_flow_db_resource_get(struct bnxt_ulp_context        *ulp_ctxt,
161                                  enum bnxt_ulp_flow_db_tables   tbl_idx,
162                                  uint32_t                       fid,
163                                  uint32_t                       *nxt_idx,
164                                  struct ulp_flow_db_res_params  *params);
165
166 /*
167  * Flush all flows in the flow database.
168  *
169  * ulp_ctxt [in] Ptr to ulp context
170  * tbl_idx [in] The index to table
171  *
172  * returns 0 on success or negative number on failure
173  */
174 int32_t ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
175                                 uint32_t                idx);
176
177 /*
178  * Flush all flows in the flow database that belong to a device function.
179  *
180  * ulp_ctxt [in] Ptr to ulp context
181  * tbl_idx [in] The index to table
182  *
183  * returns 0 on success or negative number on failure
184  */
185 int32_t
186 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
187                                 uint16_t func_id);
188
189 /*
190  * Flush all flows in the flow database that are associated with the session.
191  *
192  * ulp_ctxt [in] Ptr to ulp context
193  *
194  * returns 0 on success or negative number on failure
195  */
196 int32_t
197 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
198
199 /*
200  * Check that flow id matches the function id or not
201  *
202  * ulp_ctxt [in] Ptr to ulp context
203  * flow_db [in] Ptr to flow table
204  * func_id [in] The func_id to be set, for reset pass zero.
205  *
206  * returns true on success or false on failure
207  */
208 bool
209 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
210                                uint32_t flow_id,
211                                uint32_t func_id);
212
213 #endif /* _ULP_FLOW_DB_H_ */