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