net/bnxt: update RM with residual checker
[dpdk.git] / drivers / net / bnxt / tf_core / tf_device.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _TF_DEVICE_H_
7 #define _TF_DEVICE_H_
8
9 #include "tf_core.h"
10 #include "tf_identifier.h"
11 #include "tf_tbl_type.h"
12 #include "tf_tcam.h"
13
14 struct tf;
15 struct tf_session;
16
17 /**
18  *
19  */
20 enum tf_device_module_type {
21         TF_DEVICE_MODULE_TYPE_IDENTIFIER,
22         TF_DEVICE_MODULE_TYPE_TABLE,
23         TF_DEVICE_MODULE_TYPE_TCAM,
24         TF_DEVICE_MODULE_TYPE_EM,
25         TF_DEVICE_MODULE_TYPE_MAX
26 };
27
28 /**
29  * The Device module provides a general device template. A supported
30  * device type should implement one or more of the listed function
31  * pointers according to its capabilities.
32  *
33  * If a device function pointer is NULL the device capability is not
34  * supported.
35  */
36
37 /**
38  * TF device information
39  */
40 struct tf_dev_info {
41         enum tf_device_type type;
42         const struct tf_dev_ops *ops;
43 };
44
45 /**
46  * @page device Device
47  *
48  * @ref tf_dev_bind
49  *
50  * @ref tf_dev_unbind
51  */
52
53 /**
54  * Device bind handles the initialization of the specified device
55  * type.
56  *
57  * [in] tfp
58  *   Pointer to TF handle
59  *
60  * [in] type
61  *   Device type
62  *
63  * [in] resources
64  *   Pointer to resource allocation information
65  *
66  * [out] dev_handle
67  *   Device handle
68  *
69  * Returns
70  *   - (0) if successful.
71  *   - (-EINVAL) parameter failure.
72  *   - (-ENODEV) no such device supported.
73  */
74 int tf_dev_bind(struct tf *tfp,
75                 enum tf_device_type type,
76                 bool shadow_copy,
77                 struct tf_session_resources *resources,
78                 struct tf_dev_info *dev_handle);
79
80 /**
81  * Device release handles cleanup of the device specific information.
82  *
83  * [in] tfp
84  *   Pointer to TF handle
85  *
86  * [in] dev_handle
87  *   Device handle
88  *
89  * Returns
90  *   - (0) if successful.
91  *   - (-EINVAL) parameter failure.
92  *   - (-ENODEV) no such device supported.
93  */
94 int tf_dev_unbind(struct tf *tfp,
95                   struct tf_dev_info *dev_handle);
96
97 /**
98  * Truflow device specific function hooks structure
99  *
100  * The following device hooks can be defined; unless noted otherwise,
101  * they are optional and can be filled with a null pointer. The
102  * purpose of these hooks is to support Truflow device operations for
103  * different device variants.
104  */
105 struct tf_dev_ops {
106         /**
107          * Retrieves the MAX number of resource types that the device
108          * supports.
109          *
110          * [in] tfp
111          *   Pointer to TF handle
112          *
113          * [out] max_types
114          *   Pointer to MAX number of types the device supports
115          *
116          * Returns
117          *   - (0) if successful.
118          *   - (-EINVAL) on failure.
119          */
120         int (*tf_dev_get_max_types)(struct tf *tfp,
121                                     uint16_t *max_types);
122
123         /**
124          * Retrieves the WC TCAM slice information that the device
125          * supports.
126          *
127          * [in] tfp
128          *   Pointer to TF handle
129          *
130          * [in] type
131          *   TCAM table type
132          *
133          * [in] key_sz
134          *   Key size
135          *
136          * [out] num_slices_per_row
137          *   Pointer to number of slices per row the device supports
138          *
139          * Returns
140          *   - (0) if successful.
141          *   - (-EINVAL) on failure.
142          */
143         int (*tf_dev_get_tcam_slice_info)(struct tf *tfp,
144                                           enum tf_tcam_tbl_type type,
145                                           uint16_t key_sz,
146                                           uint16_t *num_slices_per_row);
147
148         /**
149          * Allocation of an identifier element.
150          *
151          * This API allocates the specified identifier element from a
152          * device specific identifier DB. The allocated element is
153          * returned.
154          *
155          * [in] tfp
156          *   Pointer to TF handle
157          *
158          * [in] parms
159          *   Pointer to identifier allocation parameters
160          *
161          * Returns
162          *   - (0) if successful.
163          *   - (-EINVAL) on failure.
164          */
165         int (*tf_dev_alloc_ident)(struct tf *tfp,
166                                   struct tf_ident_alloc_parms *parms);
167
168         /**
169          * Free of an identifier element.
170          *
171          * This API free's a previous allocated identifier element from a
172          * device specific identifier DB.
173          *
174          * [in] tfp
175          *   Pointer to TF handle
176          *
177          * [in] parms
178          *   Pointer to identifier free parameters
179          *
180          * Returns
181          *   - (0) if successful.
182          *   - (-EINVAL) on failure.
183          */
184         int (*tf_dev_free_ident)(struct tf *tfp,
185                                  struct tf_ident_free_parms *parms);
186
187         /**
188          * Allocation of a table type element.
189          *
190          * This API allocates the specified table type element from a
191          * device specific table type DB. The allocated element is
192          * returned.
193          *
194          * [in] tfp
195          *   Pointer to TF handle
196          *
197          * [in] parms
198          *   Pointer to table allocation parameters
199          *
200          * Returns
201          *   - (0) if successful.
202          *   - (-EINVAL) on failure.
203          */
204         int (*tf_dev_alloc_tbl)(struct tf *tfp,
205                                 struct tf_tbl_alloc_parms *parms);
206
207         /**
208          * Free of a table type element.
209          *
210          * This API free's a previous allocated table type element from a
211          * device specific table type DB.
212          *
213          * [in] tfp
214          *   Pointer to TF handle
215          *
216          * [in] parms
217          *   Pointer to table free parameters
218          *
219          * Returns
220          *   - (0) if successful.
221          *   - (-EINVAL) on failure.
222          */
223         int (*tf_dev_free_tbl)(struct tf *tfp,
224                                struct tf_tbl_free_parms *parms);
225
226         /**
227          * Searches for the specified table type element in a shadow DB.
228          *
229          * This API searches for the specified table type element in a
230          * device specific shadow DB. If the element is found the
231          * reference count for the element is updated. If the element
232          * is not found a new element is allocated from the table type
233          * DB and then inserted into the shadow DB.
234          *
235          * [in] tfp
236          *   Pointer to TF handle
237          *
238          * [in] parms
239          *   Pointer to table allocation and search parameters
240          *
241          * Returns
242          *   - (0) if successful.
243          *   - (-EINVAL) on failure.
244          */
245         int (*tf_dev_alloc_search_tbl)(struct tf *tfp,
246                                        struct tf_tbl_alloc_search_parms *parms);
247
248         /**
249          * Sets the specified table type element.
250          *
251          * This API sets the specified element data by invoking the
252          * firmware.
253          *
254          * [in] tfp
255          *   Pointer to TF handle
256          *
257          * [in] parms
258          *   Pointer to table set parameters
259          *
260          * Returns
261          *   - (0) if successful.
262          *   - (-EINVAL) on failure.
263          */
264         int (*tf_dev_set_tbl)(struct tf *tfp,
265                               struct tf_tbl_set_parms *parms);
266
267         /**
268          * Retrieves the specified table type element.
269          *
270          * This API retrieves the specified element data by invoking the
271          * firmware.
272          *
273          * [in] tfp
274          *   Pointer to TF handle
275          *
276          * [in] parms
277          *   Pointer to table get parameters
278          *
279          * Returns
280          *   - (0) if successful.
281          *   - (-EINVAL) on failure.
282          */
283         int (*tf_dev_get_tbl)(struct tf *tfp,
284                                struct tf_tbl_get_parms *parms);
285
286         /**
287          * Allocation of a tcam element.
288          *
289          * This API allocates the specified tcam element from a device
290          * specific tcam DB. The allocated element is returned.
291          *
292          * [in] tfp
293          *   Pointer to TF handle
294          *
295          * [in] parms
296          *   Pointer to tcam allocation parameters
297          *
298          * Returns
299          *   - (0) if successful.
300          *   - (-EINVAL) on failure.
301          */
302         int (*tf_dev_alloc_tcam)(struct tf *tfp,
303                                  struct tf_tcam_alloc_parms *parms);
304
305         /**
306          * Free of a tcam element.
307          *
308          * This API free's a previous allocated tcam element from a
309          * device specific tcam DB.
310          *
311          * [in] tfp
312          *   Pointer to TF handle
313          *
314          * [in] parms
315          *   Pointer to tcam free parameters
316          *
317          * Returns
318          *   - (0) if successful.
319          *   - (-EINVAL) on failure.
320          */
321         int (*tf_dev_free_tcam)(struct tf *tfp,
322                                 struct tf_tcam_free_parms *parms);
323
324         /**
325          * Searches for the specified tcam element in a shadow DB.
326          *
327          * This API searches for the specified tcam element in a
328          * device specific shadow DB. If the element is found the
329          * reference count for the element is updated. If the element
330          * is not found a new element is allocated from the tcam DB
331          * and then inserted into the shadow DB.
332          *
333          * [in] tfp
334          *   Pointer to TF handle
335          *
336          * [in] parms
337          *   Pointer to tcam allocation and search parameters
338          *
339          * Returns
340          *   - (0) if successful.
341          *   - (-EINVAL) on failure.
342          */
343         int (*tf_dev_alloc_search_tcam)
344                         (struct tf *tfp,
345                         struct tf_tcam_alloc_search_parms *parms);
346
347         /**
348          * Sets the specified tcam element.
349          *
350          * This API sets the specified element data by invoking the
351          * firmware.
352          *
353          * [in] tfp
354          *   Pointer to TF handle
355          *
356          * [in] parms
357          *   Pointer to tcam set parameters
358          *
359          * Returns
360          *   - (0) if successful.
361          *   - (-EINVAL) on failure.
362          */
363         int (*tf_dev_set_tcam)(struct tf *tfp,
364                                struct tf_tcam_set_parms *parms);
365
366         /**
367          * Retrieves the specified tcam element.
368          *
369          * This API retrieves the specified element data by invoking the
370          * firmware.
371          *
372          * [in] tfp
373          *   Pointer to TF handle
374          *
375          * [in] parms
376          *   Pointer to tcam get parameters
377          *
378          * Returns
379          *   - (0) if successful.
380          *   - (-EINVAL) on failure.
381          */
382         int (*tf_dev_get_tcam)(struct tf *tfp,
383                                struct tf_tcam_get_parms *parms);
384
385         /**
386          * Insert EM hash entry API
387          *
388          * [in] tfp
389          *   Pointer to TF handle
390          *
391          * [in] parms
392          *   Pointer to E/EM insert parameters
393          *
394          *  Returns:
395          *    0       - Success
396          *    -EINVAL - Error
397          */
398         int (*tf_dev_insert_em_entry)(struct tf *tfp,
399                                       struct tf_insert_em_entry_parms *parms);
400
401         /**
402          * Delete EM hash entry API
403          *
404          * [in] tfp
405          *   Pointer to TF handle
406          *
407          * [in] parms
408          *   Pointer to E/EM delete parameters
409          *
410          *    returns:
411          *    0       - Success
412          *    -EINVAL - Error
413          */
414         int (*tf_dev_delete_em_entry)(struct tf *tfp,
415                                       struct tf_delete_em_entry_parms *parms);
416 };
417
418 /**
419  * Supported device operation structures
420  */
421 extern const struct tf_dev_ops tf_dev_ops_p4_init;
422 extern const struct tf_dev_ops tf_dev_ops_p4;
423
424 #endif /* _TF_DEVICE_H_ */