xref: /dpdk/drivers/net/bnxt/tf_ulp/ulp_flow_db.h (revision 0d09cbc7)
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_flow_tbl;
50 	uint32_t	num_flows;
51 	uint32_t	num_resources;
52 };
53 
54 /* Flow database supports two tables. */
55 enum bnxt_ulp_flow_db_tables {
56 	BNXT_ULP_REGULAR_FLOW_TABLE,
57 	BNXT_ULP_DEFAULT_FLOW_TABLE,
58 	BNXT_ULP_FLOW_TABLE_MAX
59 };
60 
61 /* Structure for the flow database resource information. */
62 struct bnxt_ulp_flow_db {
63 	struct bnxt_ulp_flow_tbl	flow_tbl[BNXT_ULP_FLOW_TABLE_MAX];
64 	uint16_t			*func_id_tbl;
65 	uint32_t			func_id_tbl_size;
66 };
67 
68 /* flow db resource params to add resources */
69 struct ulp_flow_db_res_params {
70 	enum tf_dir			direction;
71 	enum bnxt_ulp_resource_func	resource_func;
72 	uint8_t				resource_type;
73 	uint8_t				resource_sub_type;
74 	uint8_t				reserved;
75 	uint8_t				critical_resource;
76 	uint64_t			resource_hndl;
77 };
78 
79 /*
80  * Initialize the flow database. Memory is allocated in this
81  * call and assigned to the flow database.
82  *
83  * ulp_ctxt [in] Ptr to ulp context
84  *
85  * Returns 0 on success or negative number on failure.
86  */
87 int32_t	ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
88 
89 /*
90  * Deinitialize the flow database. Memory is deallocated in
91  * this call and all flows should have been purged before this
92  * call.
93  *
94  * ulp_ctxt [in] Ptr to ulp context
95  *
96  * Returns 0 on success.
97  */
98 int32_t	ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
99 
100 /*
101  * Allocate the flow database entry
102  *
103  * ulp_ctxt [in] Ptr to ulp_context
104  * tbl_idx [in] Specify it is regular or default flow
105  * func_id [in] The function id of the device.Valid only for regular flows.
106  * fid [out] The index to the flow entry
107  *
108  * returns 0 on success and negative on failure.
109  */
110 int32_t ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
111 			      enum bnxt_ulp_flow_db_tables tbl_idx,
112 			      uint16_t func_id,
113 			      uint32_t *fid);
114 
115 /*
116  * Allocate the flow database entry.
117  * The params->critical_resource has to be set to 0 to allocate a new resource.
118  *
119  * ulp_ctxt [in] Ptr to ulp_context
120  * tbl_idx [in] Specify it is regular or default flow
121  * fid [in] The index to the flow entry
122  * params [in] The contents to be copied into resource
123  *
124  * returns 0 on success and negative on failure.
125  */
126 int32_t	ulp_flow_db_resource_add(struct bnxt_ulp_context	*ulp_ctxt,
127 				 enum bnxt_ulp_flow_db_tables	tbl_idx,
128 				 uint32_t			fid,
129 				 struct ulp_flow_db_res_params	*params);
130 
131 /*
132  * Free the flow database entry.
133  * The params->critical_resource has to be set to 1 to free the first 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/out] The contents to be copied into params.
139  * Only the critical_resource needs to be set by the caller.
140  *
141  * Returns 0 on success and negative on failure.
142  */
143 int32_t	ulp_flow_db_resource_del(struct bnxt_ulp_context	*ulp_ctxt,
144 				 enum bnxt_ulp_flow_db_tables	tbl_idx,
145 				 uint32_t			fid,
146 				 struct ulp_flow_db_res_params	*params);
147 
148 /*
149  * Free the flow database entry
150  *
151  * ulp_ctxt [in] Ptr to ulp_context
152  * tbl_idx [in] Specify it is regular or default flow
153  * fid [in] The index to the flow entry
154  *
155  * returns 0 on success and negative on failure.
156  */
157 int32_t	ulp_flow_db_fid_free(struct bnxt_ulp_context		*ulp_ctxt,
158 			     enum bnxt_ulp_flow_db_tables	tbl_idx,
159 			     uint32_t				fid);
160 
161 /*
162  *Get the flow database entry details
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  * nxt_idx [in/out] the index to the next entry
168  * params [out] The contents to be copied into params.
169  *
170  * returns 0 on success and negative on failure.
171  */
172 int32_t	ulp_flow_db_resource_get(struct bnxt_ulp_context	*ulp_ctxt,
173 				 enum bnxt_ulp_flow_db_tables	tbl_idx,
174 				 uint32_t			fid,
175 				 uint32_t			*nxt_idx,
176 				 struct ulp_flow_db_res_params	*params);
177 
178 /*
179  * Flush all flows in the flow database.
180  *
181  * ulp_ctxt [in] Ptr to ulp context
182  * tbl_idx [in] The index to table
183  *
184  * returns 0 on success or negative number on failure
185  */
186 int32_t	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_db [in] Ptr to flow table
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 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
240 /*
241  * Dump the flow database entry details
242  *
243  * ulp_ctxt [in] Ptr to ulp_context
244  *
245  * returns none
246  */
247 int32_t	ulp_flow_db_debug_dump(struct bnxt_ulp_context	*ulp_ctxt);
248 #endif
249 
250 #endif /* _ULP_FLOW_DB_H_ */
251