xref: /dpdk/drivers/net/bnxt/tf_ulp/ulp_flow_db.h (revision cf21c2d3)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2021 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 /* Defines for the fdb flag */
17 #define ULP_FDB_FLAG_SHARED_SESSION	0x1
18 
19 /*
20  * Structure for the flow database resource information
21  * The below structure is based on the below partitions
22  * nxt_resource_idx = dir[31],resource_func_upper[30:28],nxt_resource_idx[27:0]
23  * If resource_func is EM_TBL then use resource_em_handle.
24  * Else the other part of the union is used and
25  * resource_func is resource_func_upper[30:28] << 5 | resource_func_lower
26  */
27 struct ulp_fdb_resource_info {
28 	/* Points to next resource in the chained list. */
29 	uint32_t			nxt_resource_idx;
30 	union {
31 		uint64_t		resource_em_handle;
32 		struct {
33 			uint8_t		resource_func_lower;
34 			uint8_t		resource_type;
35 			uint8_t		resource_sub_type;
36 			uint8_t		fdb_flags;
37 			uint32_t	resource_hndl;
38 		};
39 	};
40 };
41 
42 /* Structure for the flow database resource information. */
43 struct bnxt_ulp_flow_tbl {
44 	/* Flow tbl is the resource object list for each flow id. */
45 	struct ulp_fdb_resource_info	*flow_resources;
46 
47 	/* Flow table stack to track free list of resources. */
48 	uint32_t	*flow_tbl_stack;
49 	uint32_t	head_index;
50 	uint32_t	tail_index;
51 
52 	/* Table to track the active flows. */
53 	uint64_t	*active_reg_flows;
54 	uint64_t	*active_dflt_flows;
55 	uint32_t	num_flows;
56 	uint32_t	num_resources;
57 };
58 
59 /* Structure to maintain parent-child flow relationships */
60 struct ulp_fdb_parent_info {
61 	uint32_t	valid;
62 	uint32_t	parent_fid;
63 	uint32_t	counter_acc;
64 	uint64_t	pkt_count;
65 	uint64_t	byte_count;
66 	uint64_t	*child_fid_bitset;
67 	uint32_t	f2_cnt;
68 	uint8_t		tun_idx;
69 };
70 
71 /* Structure to maintain parent-child flow relationships */
72 struct ulp_fdb_parent_child_db {
73 	struct ulp_fdb_parent_info	*parent_flow_tbl;
74 	uint32_t			child_bitset_size;
75 	uint32_t			entries_count;
76 	uint8_t				*parent_flow_tbl_mem;
77 };
78 
79 /* Structure for the flow database resource information. */
80 struct bnxt_ulp_flow_db {
81 	struct bnxt_ulp_flow_tbl	flow_tbl;
82 	uint16_t			*func_id_tbl;
83 	uint32_t			func_id_tbl_size;
84 	struct ulp_fdb_parent_child_db	parent_child_db;
85 };
86 
87 /* flow db resource params to add resources */
88 struct ulp_flow_db_res_params {
89 	enum tf_dir			direction;
90 	enum bnxt_ulp_resource_func	resource_func;
91 	uint8_t				resource_type;
92 	uint8_t				resource_sub_type;
93 	uint8_t				fdb_flags;
94 	uint8_t				critical_resource;
95 	uint64_t			resource_hndl;
96 };
97 
98 /*
99  * Initialize the flow database. Memory is allocated in this
100  * call and assigned to the flow database.
101  *
102  * ulp_ctxt [in] Ptr to ulp context
103  *
104  * Returns 0 on success or negative number on failure.
105  */
106 int32_t	ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
107 
108 /*
109  * Deinitialize the flow database. Memory is deallocated in
110  * this call and all flows should have been purged before this
111  * call.
112  *
113  * ulp_ctxt [in] Ptr to ulp context
114  *
115  * Returns 0 on success.
116  */
117 int32_t	ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
118 
119 /*
120  * Allocate the flow database entry
121  *
122  * ulp_ctxt [in] Ptr to ulp_context
123  * tbl_idx [in] Specify it is regular or default flow
124  * func_id [in] The function id of the device.Valid only for regular flows.
125  * fid [out] The index to the flow entry
126  *
127  * returns 0 on success and negative on failure.
128  */
129 int32_t
130 ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
131 		      enum bnxt_ulp_fdb_type flow_type,
132 		      uint16_t func_id,
133 		      uint32_t *fid);
134 
135 /*
136  * Allocate the flow database entry.
137  * The params->critical_resource has to be set to 0 to allocate a new resource.
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  * params [in] The contents to be copied into resource
143  *
144  * returns 0 on success and negative on failure.
145  */
146 int32_t
147 ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
148 			 enum bnxt_ulp_fdb_type flow_type,
149 			 uint32_t fid,
150 			 struct ulp_flow_db_res_params *params);
151 
152 /*
153  * Free the flow database entry.
154  * The params->critical_resource has to be set to 1 to free the first resource.
155  *
156  * ulp_ctxt [in] Ptr to ulp_context
157  * tbl_idx [in] Specify it is regular or default flow
158  * fid [in] The index to the flow entry
159  * params [in/out] The contents to be copied into params.
160  * Only the critical_resource needs to be set by the caller.
161  *
162  * Returns 0 on success and negative on failure.
163  */
164 int32_t
165 ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
166 			 enum bnxt_ulp_fdb_type flow_type,
167 			 uint32_t fid,
168 			 struct ulp_flow_db_res_params *params);
169 
170 /*
171  * Free the flow database entry
172  *
173  * ulp_ctxt [in] Ptr to ulp_context
174  * tbl_idx [in] Specify it is regular or default flow
175  * fid [in] The index to the flow entry
176  *
177  * returns 0 on success and negative on failure.
178  */
179 int32_t
180 ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
181 		     enum bnxt_ulp_fdb_type tbl_idx,
182 		     uint32_t fid);
183 
184 /*
185  *Get the flow database entry details
186  *
187  * ulp_ctxt [in] Ptr to ulp_context
188  * tbl_idx [in] Specify it is regular or default flow
189  * fid [in] The index to the flow entry
190  * nxt_idx [in/out] the index to the next entry
191  * params [out] The contents to be copied into params.
192  *
193  * returns 0 on success and negative on failure.
194  */
195 int32_t
196 ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
197 			 enum bnxt_ulp_fdb_type flow_type,
198 			 uint32_t fid,
199 			 uint32_t *nxt_idx,
200 			 struct ulp_flow_db_res_params *params);
201 
202 /*
203  * Flush all flows in the flow database.
204  *
205  * ulp_ctxt [in] Ptr to ulp context
206  * tbl_idx [in] The index to table
207  *
208  * returns 0 on success or negative number on failure
209  */
210 int32_t
211 ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
212 			uint32_t idx);
213 
214 /*
215  * Flush all flows in the flow database that belong to a device function.
216  *
217  * ulp_ctxt [in] Ptr to ulp context
218  * tbl_idx [in] The index to table
219  *
220  * returns 0 on success or negative number on failure
221  */
222 int32_t
223 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
224 				uint16_t func_id);
225 
226 /*
227  * Flush all flows in the flow database that are associated with the session.
228  *
229  * ulp_ctxt [in] Ptr to ulp context
230  *
231  * returns 0 on success or negative number on failure
232  */
233 int32_t
234 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx);
235 
236 /*
237  * Check that flow id matches the function id or not
238  *
239  * ulp_ctxt [in] Ptr to ulp context
240  * flow_id [in] flow id of the flow.
241  * func_id [in] The func_id to be set, for reset pass zero.
242  *
243  * returns true on success or false on failure
244  */
245 bool
246 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx,
247 			       uint32_t flow_id,
248 			       uint32_t func_id);
249 
250 /*
251  * Api to get the cfa action pointer from a flow.
252  *
253  * ulp_ctxt [in] Ptr to ulp context
254  * flow_id [in] flow id
255  * cfa_action [out] The resource handle stored in the flow database
256  *
257  * returns 0 on success
258  */
259 int32_t
260 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx,
261 				   uint32_t flow_id,
262 				   uint16_t *cfa_action);
263 
264 /*
265  * Set or reset the parent flow in the parent-child database
266  *
267  * ulp_ctxt [in] Ptr to ulp_context
268  * pc_idx [in] The index to parent child db
269  * parent_fid [in] The flow id of the parent flow entry
270  * set_flag [in] Use 1 for setting child, 0 to reset
271  *
272  * returns zero on success and negative on failure.
273  */
274 int32_t
275 ulp_flow_db_pc_db_parent_flow_set(struct bnxt_ulp_context *ulp_ctxt,
276 				  uint32_t pc_idx,
277 				  uint32_t parent_fid,
278 				  uint32_t set_flag);
279 
280 /*
281  * Set or reset the child flow in the parent-child database
282  *
283  * ulp_ctxt [in] Ptr to ulp_context
284  * pc_idx [in] The index to parent child db
285  * child_fid [in] The flow id of the child flow entry
286  * set_flag [in] Use 1 for setting child, 0 to reset
287  *
288  * returns zero on success and negative on failure.
289  */
290 int32_t
291 ulp_flow_db_pc_db_child_flow_set(struct bnxt_ulp_context *ulp_ctxt,
292 				 uint32_t pc_idx,
293 				 uint32_t child_fid,
294 				 uint32_t set_flag);
295 
296 /*
297  * Get the parent index from the parent-child database
298  *
299  * ulp_ctxt [in] Ptr to ulp_context
300  * parent_fid [in] The flow id of the parent flow entry
301  * parent_idx [out] The parent index of parent flow entry
302  *
303  * returns zero on success and negative on failure.
304  */
305 int32_t
306 ulp_flow_db_parent_flow_idx_get(struct bnxt_ulp_context *ulp_ctxt,
307 				uint32_t parent_fid,
308 				uint32_t *parent_idx);
309 
310 /*
311  * Get the next child flow in the parent-child database
312  *
313  * ulp_ctxt [in] Ptr to ulp_context
314  * parent_fid [in] The flow id of the parent flow entry
315  * child_fid [in/out] The flow id of the child flow entry
316  *
317  * returns zero on success and negative on failure.
318  * Pass child_fid as zero for first entry.
319  */
320 int32_t
321 ulp_flow_db_parent_child_flow_next_entry_get(struct bnxt_ulp_flow_db *flow_db,
322 					     uint32_t parent_idx,
323 					     uint32_t *child_fid);
324 
325 /*
326  * Orphan the child flow entry
327  * This is called only for child flows that have
328  * BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW resource
329  *
330  * ulp_ctxt [in] Ptr to ulp_context
331  * flow_type [in] Specify it is regular or default flow
332  * fid [in] The index to the flow entry
333  *
334  * Returns 0 on success and negative on failure.
335  */
336 int32_t
337 ulp_flow_db_child_flow_reset(struct bnxt_ulp_context *ulp_ctxt,
338 			     enum bnxt_ulp_fdb_type flow_type,
339 			     uint32_t fid);
340 
341 /*
342  * Create parent flow in the parent flow tbl
343  *
344  * parms [in] Ptr to mapper params
345  *
346  * Returns 0 on success and negative on failure.
347  */
348 int32_t
349 ulp_flow_db_parent_flow_create(struct bnxt_ulp_mapper_parms *parms);
350 
351 /*
352  * Create child flow in the parent flow tbl
353  *
354  * parms [in] Ptr to mapper params
355  *
356  * Returns 0 on success and negative on failure.
357  */
358 int32_t
359 ulp_flow_db_child_flow_create(struct bnxt_ulp_mapper_parms *parms);
360 
361 /*
362  * Update the parent counters
363  *
364  * ulp_ctxt [in] Ptr to ulp_context
365  * pc_idx [in] The parent flow entry idx
366  * packet_count [in] - packet count
367  * byte_count [in] - byte count
368  *
369  * returns 0 on success
370  */
371 int32_t
372 ulp_flow_db_parent_flow_count_update(struct bnxt_ulp_context *ulp_ctxt,
373 				     uint32_t pc_idx,
374 				     uint64_t packet_count,
375 				     uint64_t byte_count);
376 /*
377  * Get the parent accumulation counters
378  *
379  * ulp_ctxt [in] Ptr to ulp_context
380  * pc_idx [in] The parent flow entry idx
381  * packet_count [out] - packet count
382  * byte_count [out] - byte count
383  *
384  * returns 0 on success
385  */
386 int32_t
387 ulp_flow_db_parent_flow_count_get(struct bnxt_ulp_context *ulp_ctxt,
388 				  uint32_t pc_idx,
389 				  uint64_t *packet_count,
390 				  uint64_t *byte_count,
391 				  uint8_t count_reset);
392 
393 /*
394  * reset the parent accumulation counters
395  *
396  * ulp_ctxt [in] Ptr to ulp_context
397  *
398  * returns none
399  */
400 void
401 ulp_flow_db_parent_flow_count_reset(struct bnxt_ulp_context *ulp_ctxt);
402 
403 /*
404  * Set the shared bit for the flow db entry
405  *
406  * res [in] Ptr to fdb entry
407  * shared [in] shared flag
408  *
409  * returns none
410  */
411 void ulp_flow_db_shared_session_set(struct ulp_flow_db_res_params *res,
412 				    enum bnxt_ulp_shared_session shared);
413 
414 #endif /* _ULP_FLOW_DB_H_ */
415