bc92cc0bc126644e42d4849995d43f01549be1b5
[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          * [in] type
120          *   TCAM table type
121          *
122          * [in] key_sz
123          *   Key size
124          *
125          * [out] num_slices_per_row
126          *   Pointer to number of slices per row the device supports
127          *
128          * Returns
129          *   - (0) if successful.
130          *   - (-EINVAL) on failure.
131          */
132         int (*tf_dev_get_tcam_slice_info)(struct tf *tfp,
133                                           enum tf_tcam_tbl_type type,
134                                           uint16_t key_sz,
135                                           uint16_t *num_slices_per_row);
136
137         /**
138          * Allocation of an identifier element.
139          *
140          * This API allocates the specified identifier element from a
141          * device specific identifier DB. The allocated element is
142          * returned.
143          *
144          * [in] tfp
145          *   Pointer to TF handle
146          *
147          * [in] parms
148          *   Pointer to identifier allocation parameters
149          *
150          * Returns
151          *   - (0) if successful.
152          *   - (-EINVAL) on failure.
153          */
154         int (*tf_dev_alloc_ident)(struct tf *tfp,
155                                   struct tf_ident_alloc_parms *parms);
156
157         /**
158          * Free of an identifier element.
159          *
160          * This API free's a previous allocated identifier element from a
161          * device specific identifier DB.
162          *
163          * [in] tfp
164          *   Pointer to TF handle
165          *
166          * [in] parms
167          *   Pointer to identifier free parameters
168          *
169          * Returns
170          *   - (0) if successful.
171          *   - (-EINVAL) on failure.
172          */
173         int (*tf_dev_free_ident)(struct tf *tfp,
174                                  struct tf_ident_free_parms *parms);
175
176         /**
177          * Allocation of a table type element.
178          *
179          * This API allocates the specified table type element from a
180          * device specific table type DB. The allocated element is
181          * returned.
182          *
183          * [in] tfp
184          *   Pointer to TF handle
185          *
186          * [in] parms
187          *   Pointer to table allocation parameters
188          *
189          * Returns
190          *   - (0) if successful.
191          *   - (-EINVAL) on failure.
192          */
193         int (*tf_dev_alloc_tbl)(struct tf *tfp,
194                                 struct tf_tbl_alloc_parms *parms);
195
196         /**
197          * Free of a table type element.
198          *
199          * This API free's a previous allocated table type element from a
200          * device specific table type DB.
201          *
202          * [in] tfp
203          *   Pointer to TF handle
204          *
205          * [in] parms
206          *   Pointer to table free parameters
207          *
208          * Returns
209          *   - (0) if successful.
210          *   - (-EINVAL) on failure.
211          */
212         int (*tf_dev_free_tbl)(struct tf *tfp,
213                                struct tf_tbl_free_parms *parms);
214
215         /**
216          * Searches for the specified table type element in a shadow DB.
217          *
218          * This API searches for the specified table type element in a
219          * device specific shadow DB. If the element is found the
220          * reference count for the element is updated. If the element
221          * is not found a new element is allocated from the table type
222          * DB and then inserted into the shadow DB.
223          *
224          * [in] tfp
225          *   Pointer to TF handle
226          *
227          * [in] parms
228          *   Pointer to table allocation and search parameters
229          *
230          * Returns
231          *   - (0) if successful.
232          *   - (-EINVAL) on failure.
233          */
234         int (*tf_dev_alloc_search_tbl)(struct tf *tfp,
235                                        struct tf_tbl_alloc_search_parms *parms);
236
237         /**
238          * Sets the specified table type element.
239          *
240          * This API sets the specified element data by invoking the
241          * firmware.
242          *
243          * [in] tfp
244          *   Pointer to TF handle
245          *
246          * [in] parms
247          *   Pointer to table set parameters
248          *
249          * Returns
250          *   - (0) if successful.
251          *   - (-EINVAL) on failure.
252          */
253         int (*tf_dev_set_tbl)(struct tf *tfp,
254                               struct tf_tbl_set_parms *parms);
255
256         /**
257          * Retrieves the specified table type element.
258          *
259          * This API retrieves the specified element data by invoking the
260          * firmware.
261          *
262          * [in] tfp
263          *   Pointer to TF handle
264          *
265          * [in] parms
266          *   Pointer to table get parameters
267          *
268          * Returns
269          *   - (0) if successful.
270          *   - (-EINVAL) on failure.
271          */
272         int (*tf_dev_get_tbl)(struct tf *tfp,
273                                struct tf_tbl_get_parms *parms);
274
275         /**
276          * Allocation of a tcam element.
277          *
278          * This API allocates the specified tcam element from a device
279          * specific tcam DB. The allocated element is returned.
280          *
281          * [in] tfp
282          *   Pointer to TF handle
283          *
284          * [in] parms
285          *   Pointer to tcam allocation parameters
286          *
287          * Returns
288          *   - (0) if successful.
289          *   - (-EINVAL) on failure.
290          */
291         int (*tf_dev_alloc_tcam)(struct tf *tfp,
292                                  struct tf_tcam_alloc_parms *parms);
293
294         /**
295          * Free of a tcam element.
296          *
297          * This API free's a previous allocated tcam element from a
298          * device specific tcam DB.
299          *
300          * [in] tfp
301          *   Pointer to TF handle
302          *
303          * [in] parms
304          *   Pointer to tcam free parameters
305          *
306          * Returns
307          *   - (0) if successful.
308          *   - (-EINVAL) on failure.
309          */
310         int (*tf_dev_free_tcam)(struct tf *tfp,
311                                 struct tf_tcam_free_parms *parms);
312
313         /**
314          * Searches for the specified tcam element in a shadow DB.
315          *
316          * This API searches for the specified tcam element in a
317          * device specific shadow DB. If the element is found the
318          * reference count for the element is updated. If the element
319          * is not found a new element is allocated from the tcam DB
320          * and then inserted into the shadow DB.
321          *
322          * [in] tfp
323          *   Pointer to TF handle
324          *
325          * [in] parms
326          *   Pointer to tcam allocation and search parameters
327          *
328          * Returns
329          *   - (0) if successful.
330          *   - (-EINVAL) on failure.
331          */
332         int (*tf_dev_alloc_search_tcam)
333                         (struct tf *tfp,
334                         struct tf_tcam_alloc_search_parms *parms);
335
336         /**
337          * Sets the specified tcam element.
338          *
339          * This API sets the specified element data by invoking the
340          * firmware.
341          *
342          * [in] tfp
343          *   Pointer to TF handle
344          *
345          * [in] parms
346          *   Pointer to tcam set parameters
347          *
348          * Returns
349          *   - (0) if successful.
350          *   - (-EINVAL) on failure.
351          */
352         int (*tf_dev_set_tcam)(struct tf *tfp,
353                                struct tf_tcam_set_parms *parms);
354
355         /**
356          * Retrieves the specified tcam element.
357          *
358          * This API retrieves the specified element data by invoking the
359          * firmware.
360          *
361          * [in] tfp
362          *   Pointer to TF handle
363          *
364          * [in] parms
365          *   Pointer to tcam get parameters
366          *
367          * Returns
368          *   - (0) if successful.
369          *   - (-EINVAL) on failure.
370          */
371         int (*tf_dev_get_tcam)(struct tf *tfp,
372                                struct tf_tcam_get_parms *parms);
373
374         /**
375          * Insert EM hash entry API
376          *
377          * [in] tfp
378          *   Pointer to TF handle
379          *
380          * [in] parms
381          *   Pointer to E/EM insert parameters
382          *
383          *  Returns:
384          *    0       - Success
385          *    -EINVAL - Error
386          */
387         int (*tf_dev_insert_em_entry)(struct tf *tfp,
388                                       struct tf_insert_em_entry_parms *parms);
389
390         /**
391          * Delete EM hash entry API
392          *
393          * [in] tfp
394          *   Pointer to TF handle
395          *
396          * [in] parms
397          *   Pointer to E/EM delete parameters
398          *
399          *    returns:
400          *    0       - Success
401          *    -EINVAL - Error
402          */
403         int (*tf_dev_delete_em_entry)(struct tf *tfp,
404                                       struct tf_delete_em_entry_parms *parms);
405 };
406
407 /**
408  * Supported device operation structures
409  */
410 extern const struct tf_dev_ops tf_dev_ops_p4_init;
411 extern const struct tf_dev_ops tf_dev_ops_p4;
412
413 #endif /* _TF_DEVICE_H_ */