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