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