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