7ec4b8ae038aef04318c56feae9833591bc5c8a6
[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 for the flow database resource information. */
56 struct bnxt_ulp_flow_db {
57         struct bnxt_ulp_flow_tbl        flow_tbl;
58         uint16_t                        *func_id_tbl;
59         uint32_t                        func_id_tbl_size;
60 };
61
62 /* flow db resource params to add resources */
63 struct ulp_flow_db_res_params {
64         enum tf_dir                     direction;
65         enum bnxt_ulp_resource_func     resource_func;
66         uint8_t                         resource_type;
67         uint8_t                         resource_sub_type;
68         uint8_t                         reserved;
69         uint8_t                         critical_resource;
70         uint64_t                        resource_hndl;
71 };
72
73 /*
74  * Initialize the flow database. Memory is allocated in this
75  * call and assigned to the flow database.
76  *
77  * ulp_ctxt [in] Ptr to ulp context
78  *
79  * Returns 0 on success or negative number on failure.
80  */
81 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
82
83 /*
84  * Deinitialize the flow database. Memory is deallocated in
85  * this call and all flows should have been purged before this
86  * call.
87  *
88  * ulp_ctxt [in] Ptr to ulp context
89  *
90  * Returns 0 on success.
91  */
92 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
93
94 /*
95  * Allocate the flow database entry
96  *
97  * ulp_ctxt [in] Ptr to ulp_context
98  * tbl_idx [in] Specify it is regular or default flow
99  * func_id [in] The function id of the device.Valid only for regular flows.
100  * fid [out] The index to the flow entry
101  *
102  * returns 0 on success and negative on failure.
103  */
104 int32_t
105 ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
106                       enum bnxt_ulp_fdb_type flow_type,
107                       uint16_t func_id,
108                       uint32_t *fid);
109
110 /*
111  * Allocate the flow database entry.
112  * The params->critical_resource has to be set to 0 to allocate a new resource.
113  *
114  * ulp_ctxt [in] Ptr to ulp_context
115  * tbl_idx [in] Specify it is regular or default flow
116  * fid [in] The index to the flow entry
117  * params [in] The contents to be copied into resource
118  *
119  * returns 0 on success and negative on failure.
120  */
121 int32_t
122 ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
123                          enum bnxt_ulp_fdb_type flow_type,
124                          uint32_t fid,
125                          struct ulp_flow_db_res_params *params);
126
127 /*
128  * Free the flow database entry.
129  * The params->critical_resource has to be set to 1 to free the first resource.
130  *
131  * ulp_ctxt [in] Ptr to ulp_context
132  * tbl_idx [in] Specify it is regular or default flow
133  * fid [in] The index to the flow entry
134  * params [in/out] The contents to be copied into params.
135  * Only the critical_resource needs to be set by the caller.
136  *
137  * Returns 0 on success and negative on failure.
138  */
139 int32_t
140 ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
141                          enum bnxt_ulp_fdb_type flow_type,
142                          uint32_t fid,
143                          struct ulp_flow_db_res_params *params);
144
145 /*
146  * Free the flow database entry
147  *
148  * ulp_ctxt [in] Ptr to ulp_context
149  * tbl_idx [in] Specify it is regular or default flow
150  * fid [in] The index to the flow entry
151  *
152  * returns 0 on success and negative on failure.
153  */
154 int32_t
155 ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
156                      enum bnxt_ulp_fdb_type tbl_idx,
157                      uint32_t fid);
158
159 /*
160  *Get the flow database entry details
161  *
162  * ulp_ctxt [in] Ptr to ulp_context
163  * tbl_idx [in] Specify it is regular or default flow
164  * fid [in] The index to the flow entry
165  * nxt_idx [in/out] the index to the next entry
166  * params [out] The contents to be copied into params.
167  *
168  * returns 0 on success and negative on failure.
169  */
170 int32_t
171 ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
172                          enum bnxt_ulp_fdb_type flow_type,
173                          uint32_t fid,
174                          uint32_t *nxt_idx,
175                          struct ulp_flow_db_res_params *params);
176
177 /*
178  * Flush all flows in the flow database.
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_flush_flows(struct bnxt_ulp_context *ulp_ctx,
187                         uint32_t idx);
188
189 /*
190  * Flush all flows in the flow database that belong to a device function.
191  *
192  * ulp_ctxt [in] Ptr to ulp context
193  * tbl_idx [in] The index to table
194  *
195  * returns 0 on success or negative number on failure
196  */
197 int32_t
198 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
199                                 uint16_t func_id);
200
201 /*
202  * Flush all flows in the flow database that are associated with the session.
203  *
204  * ulp_ctxt [in] Ptr to ulp context
205  *
206  * returns 0 on success or negative number on failure
207  */
208 int32_t
209 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
210
211 /*
212  * Check that flow id matches the function id or not
213  *
214  * ulp_ctxt [in] Ptr to ulp context
215  * flow_id [in] flow id of the flow.
216  * func_id [in] The func_id to be set, for reset pass zero.
217  *
218  * returns true on success or false on failure
219  */
220 bool
221 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
222                                uint32_t flow_id,
223                                uint32_t func_id);
224
225 /*
226  * Api to get the cfa action pointer from a flow.
227  *
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
231  *
232  * returns 0 on success
233  */
234 int32_t
235 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx,
236                                    uint32_t flow_id,
237                                    uint16_t *cfa_action);
238
239 #endif /* _ULP_FLOW_DB_H_ */