f0d8e94f7e598713d8b106da52c004e44521eb83
[dpdk.git] / drivers / net / bnxt / tf_core / tf_tbl.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef TF_TBL_TYPE_H_
7 #define TF_TBL_TYPE_H_
8
9 #include "tf_core.h"
10 #include "stack.h"
11
12 struct tf;
13
14 /**
15  * The Table module provides processing of Internal TF table types.
16  */
17
18 /**
19  * Table scope control block content
20  */
21 struct tf_em_caps {
22         uint32_t flags;
23         uint32_t supported;
24         uint32_t max_entries_supported;
25         uint16_t key_entry_size;
26         uint16_t record_entry_size;
27         uint16_t efc_entry_size;
28 };
29
30 /** Invalid table scope id */
31 #define TF_TBL_SCOPE_INVALID 0xffffffff
32
33 /**
34  * Table Scope Control Block
35  *
36  * Holds private data for a table scope. Only one instance of a table
37  * scope with Internal EM is supported.
38  */
39 struct tf_tbl_scope_cb {
40         uint32_t tbl_scope_id;
41        /** The pf or parent pf of the vf used for table scope creation
42         */
43         uint16_t pf;
44         int index;
45         struct hcapi_cfa_em_ctx_mem_info em_ctx_info[TF_DIR_MAX];
46         struct tf_em_caps em_caps[TF_DIR_MAX];
47         struct stack ext_act_pool[TF_DIR_MAX];
48         uint32_t *ext_act_pool_mem[TF_DIR_MAX];
49 };
50
51 /**
52  * Table configuration parameters
53  */
54 struct tf_tbl_cfg_parms {
55         /**
56          * Number of table types in each of the configuration arrays
57          */
58         uint16_t num_elements;
59         /**
60          * Table Type element configuration array
61          */
62         struct tf_rm_element_cfg *cfg;
63         /**
64          * Shadow table type configuration array
65          */
66         struct tf_shadow_tbl_cfg *shadow_cfg;
67         /**
68          * Boolean controlling the request shadow copy.
69          */
70         bool shadow_copy;
71         /**
72          * Session resource allocations
73          */
74         struct tf_session_resources *resources;
75 };
76
77 /**
78  * Table allocation parameters
79  */
80 struct tf_tbl_alloc_parms {
81         /**
82          * [in] Receive or transmit direction
83          */
84         enum tf_dir dir;
85         /**
86          * [in] Type of the allocation
87          */
88         enum tf_tbl_type type;
89         /**
90          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
91          */
92         uint32_t tbl_scope_id;
93         /**
94          * [out] Idx of allocated entry or found entry (if search_enable)
95          */
96         uint32_t *idx;
97 };
98
99 /**
100  * Table free parameters
101  */
102 struct tf_tbl_free_parms {
103         /**
104          * [in] Receive or transmit direction
105          */
106         enum tf_dir dir;
107         /**
108          * [in] Type of the allocation type
109          */
110         enum tf_tbl_type type;
111         /**
112          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
113          */
114         uint32_t tbl_scope_id;
115         /**
116          * [in] Index to free
117          */
118         uint32_t idx;
119         /**
120          * [out] Reference count after free, only valid if session has been
121          * created with shadow_copy.
122          */
123         uint16_t ref_cnt;
124 };
125
126 /**
127  * Table allocate search parameters
128  */
129 struct tf_tbl_alloc_search_parms {
130         /**
131          * [in] Receive or transmit direction
132          */
133         enum tf_dir dir;
134         /**
135          * [in] Type of the allocation
136          */
137         enum tf_tbl_type type;
138         /**
139          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
140          */
141         uint32_t tbl_scope_id;
142         /**
143          * [in] Result data to search for
144          */
145         uint8_t *result;
146         /**
147          * [in] Result data size in bytes
148          */
149         uint16_t result_sz_in_bytes;
150         /**
151          * [in] Whether or not to allocate on MISS, 1 is allocate.
152          */
153         uint8_t alloc;
154         /**
155          * [out] If search_enable, set if matching entry found
156          */
157         uint8_t hit;
158         /**
159          * [out] The status of the search (REJECT, MISS, HIT)
160          */
161         enum tf_search_status search_status;
162         /**
163          * [out] Current ref count after allocation
164          */
165         uint16_t ref_cnt;
166         /**
167          * [out] Idx of allocated entry or found entry
168          */
169         uint32_t idx;
170 };
171
172 /**
173  * Table set parameters
174  */
175 struct tf_tbl_set_parms {
176         /**
177          * [in] Receive or transmit direction
178          */
179         enum tf_dir dir;
180         /**
181          * [in] Type of object to set
182          */
183         enum tf_tbl_type type;
184         /**
185          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
186          */
187         uint32_t tbl_scope_id;
188         /**
189          * [in] Entry data
190          */
191         uint8_t *data;
192         /**
193          * [in] Entry size
194          */
195         uint16_t data_sz_in_bytes;
196         /**
197          * [in] Entry index to write to
198          */
199         uint32_t idx;
200 };
201
202 /**
203  * Table get parameters
204  */
205 struct tf_tbl_get_parms {
206         /**
207          * [in] Receive or transmit direction
208          */
209         enum tf_dir dir;
210         /**
211          * [in] Type of object to get
212          */
213         enum tf_tbl_type type;
214         /**
215          * [out] Entry data
216          */
217         uint8_t *data;
218         /**
219          * [out] Entry size
220          */
221         uint16_t data_sz_in_bytes;
222         /**
223          * [in] Entry index to read
224          */
225         uint32_t idx;
226 };
227
228 /**
229  * Table get bulk parameters
230  */
231 struct tf_tbl_get_bulk_parms {
232         /**
233          * [in] Receive or transmit direction
234          */
235         enum tf_dir dir;
236         /**
237          * [in] Type of object to get
238          */
239         enum tf_tbl_type type;
240         /**
241          * [in] Starting index to read from
242          */
243         uint32_t starting_idx;
244         /**
245          * [in] Number of sequential entries
246          */
247         uint16_t num_entries;
248         /**
249          * [in] Size of the single entry
250          */
251         uint16_t entry_sz_in_bytes;
252         /**
253          * [out] Host physical address, where the data
254          * will be copied to by the firmware.
255          * Use tfp_calloc() API and mem_pa
256          * variable of the tfp_calloc_parms
257          * structure for the physical address.
258          */
259         uint64_t physical_mem_addr;
260 };
261
262 /**
263  * @page tbl Table
264  *
265  * @ref tf_tbl_bind
266  *
267  * @ref tf_tbl_unbind
268  *
269  * @ref tf_tbl_alloc
270  *
271  * @ref tf_tbl_free
272  *
273  * @ref tf_tbl_alloc_search
274  *
275  * @ref tf_tbl_set
276  *
277  * @ref tf_tbl_get
278  *
279  * @ref tf_tbl_bulk_get
280  */
281
282 /**
283  * Initializes the Table module with the requested DBs. Must be
284  * invoked as the first thing before any of the access functions.
285  *
286  * [in] tfp
287  *   Pointer to TF handle, used for HCAPI communication
288  *
289  * [in] parms
290  *   Pointer to Table configuration parameters
291  *
292  * Returns
293  *   - (0) if successful.
294  *   - (-EINVAL) on failure.
295  */
296 int tf_tbl_bind(struct tf *tfp,
297                 struct tf_tbl_cfg_parms *parms);
298
299 /**
300  * Cleans up the private DBs and releases all the data.
301  *
302  * [in] tfp
303  *   Pointer to TF handle, used for HCAPI communication
304  *
305  * [in] parms
306  *   Pointer to parameters
307  *
308  * Returns
309  *   - (0) if successful.
310  *   - (-EINVAL) on failure.
311  */
312 int tf_tbl_unbind(struct tf *tfp);
313
314 /**
315  * Allocates the requested table type from the internal RM DB.
316  *
317  * [in] tfp
318  *   Pointer to TF handle, used for HCAPI communication
319  *
320  * [in] parms
321  *   Pointer to Table allocation parameters
322  *
323  * Returns
324  *   - (0) if successful.
325  *   - (-EINVAL) on failure.
326  */
327 int tf_tbl_alloc(struct tf *tfp,
328                  struct tf_tbl_alloc_parms *parms);
329
330 /**
331  * Free's the requested table type and returns it to the DB. If shadow
332  * DB is enabled its searched first and if found the element refcount
333  * is decremented. If refcount goes to 0 then its returned to the
334  * table type DB.
335  *
336  * [in] tfp
337  *   Pointer to TF handle, used for HCAPI communication
338  *
339  * [in] parms
340  *   Pointer to Table free parameters
341  *
342  * Returns
343  *   - (0) if successful.
344  *   - (-EINVAL) on failure.
345  */
346 int tf_tbl_free(struct tf *tfp,
347                 struct tf_tbl_free_parms *parms);
348
349 /**
350  * Supported if Shadow DB is configured. Searches the Shadow DB for
351  * any matching element. If found the refcount in the shadow DB is
352  * updated accordingly. If not found a new element is allocated and
353  * installed into the shadow DB.
354  *
355  * [in] tfp
356  *   Pointer to TF handle, used for HCAPI communication
357  *
358  * [in] parms
359  *   Pointer to parameters
360  *
361  * Returns
362  *   - (0) if successful.
363  *   - (-EINVAL) on failure.
364  */
365 int tf_tbl_alloc_search(struct tf *tfp,
366                         struct tf_tbl_alloc_search_parms *parms);
367
368 /**
369  * Configures the requested element by sending a firmware request which
370  * then installs it into the device internal structures.
371  *
372  * [in] tfp
373  *   Pointer to TF handle, used for HCAPI communication
374  *
375  * [in] parms
376  *   Pointer to Table set parameters
377  *
378  * Returns
379  *   - (0) if successful.
380  *   - (-EINVAL) on failure.
381  */
382 int tf_tbl_set(struct tf *tfp,
383                struct tf_tbl_set_parms *parms);
384
385 /**
386  * Retrieves the requested element by sending a firmware request to get
387  * the element.
388  *
389  * [in] tfp
390  *   Pointer to TF handle, used for HCAPI communication
391  *
392  * [in] parms
393  *   Pointer to Table get parameters
394  *
395  * Returns
396  *   - (0) if successful.
397  *   - (-EINVAL) on failure.
398  */
399 int tf_tbl_get(struct tf *tfp,
400                struct tf_tbl_get_parms *parms);
401
402 /**
403  * Retrieves bulk block of elements by sending a firmware request to
404  * get the elements.
405  *
406  * [in] tfp
407  *   Pointer to TF handle, used for HCAPI communication
408  *
409  * [in] parms
410  *   Pointer to Table get bulk parameters
411  *
412  * Returns
413  *   - (0) if successful.
414  *   - (-EINVAL) on failure.
415  */
416 int tf_tbl_bulk_get(struct tf *tfp,
417                     struct tf_tbl_get_bulk_parms *parms);
418
419 #endif /* TF_TBL_TYPE_H */