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