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