8b63ff178418546249d7a218eca0c01237f92102
[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         const struct tf_dev_ops *ops;
31 };
32
33 /**
34  * @page device Device
35  *
36  * @ref tf_dev_bind
37  *
38  * @ref tf_dev_unbind
39  */
40
41 /**
42  * Device bind handles the initialization of the specified device
43  * type.
44  *
45  * [in] tfp
46  *   Pointer to TF handle
47  *
48  * [in] type
49  *   Device type
50  *
51  * [in] resources
52  *   Pointer to resource allocation information
53  *
54  * [out] dev_handle
55  *   Device handle
56  *
57  * Returns
58  *   - (0) if successful.
59  *   - (-EINVAL) on failure.
60  */
61 int dev_bind(struct tf *tfp,
62              enum tf_device_type type,
63              struct tf_session_resources *resources,
64              struct tf_dev_info *dev_handle);
65
66 /**
67  * Device release handles cleanup of the device specific information.
68  *
69  * [in] tfp
70  *   Pointer to TF handle
71  *
72  * [in] dev_handle
73  *   Device handle
74  */
75 int dev_unbind(struct tf *tfp,
76                struct tf_dev_info *dev_handle);
77
78 /**
79  * Truflow device specific function hooks structure
80  *
81  * The following device hooks can be defined; unless noted otherwise,
82  * they are optional and can be filled with a null pointer. The
83  * purpose of these hooks is to support Truflow device operations for
84  * different device variants.
85  */
86 struct tf_dev_ops {
87         /**
88          * Allocation of an identifier element.
89          *
90          * This API allocates the specified identifier element from a
91          * device specific identifier DB. The allocated element is
92          * returned.
93          *
94          * [in] tfp
95          *   Pointer to TF handle
96          *
97          * [in] parms
98          *   Pointer to identifier allocation parameters
99          *
100          * Returns
101          *   - (0) if successful.
102          *   - (-EINVAL) on failure.
103          */
104         int (*tf_dev_alloc_ident)(struct tf *tfp,
105                                   struct tf_ident_alloc_parms *parms);
106
107         /**
108          * Free of an identifier element.
109          *
110          * This API free's a previous allocated identifier element from a
111          * device specific identifier DB.
112          *
113          * [in] tfp
114          *   Pointer to TF handle
115          *
116          * [in] parms
117          *   Pointer to identifier free parameters
118          *
119          * Returns
120          *   - (0) if successful.
121          *   - (-EINVAL) on failure.
122          */
123         int (*tf_dev_free_ident)(struct tf *tfp,
124                                  struct tf_ident_free_parms *parms);
125
126         /**
127          * Allocation of a table type element.
128          *
129          * This API allocates the specified table type element from a
130          * device specific table type DB. The allocated element is
131          * returned.
132          *
133          * [in] tfp
134          *   Pointer to TF handle
135          *
136          * [in] parms
137          *   Pointer to table type allocation parameters
138          *
139          * Returns
140          *   - (0) if successful.
141          *   - (-EINVAL) on failure.
142          */
143         int (*tf_dev_alloc_tbl_type)(struct tf *tfp,
144                                      struct tf_tbl_type_alloc_parms *parms);
145
146         /**
147          * Free of a table type element.
148          *
149          * This API free's a previous allocated table type element from a
150          * device specific table type DB.
151          *
152          * [in] tfp
153          *   Pointer to TF handle
154          *
155          * [in] parms
156          *   Pointer to table type free parameters
157          *
158          * Returns
159          *   - (0) if successful.
160          *   - (-EINVAL) on failure.
161          */
162         int (*tf_dev_free_tbl_type)(struct tf *tfp,
163                                     struct tf_tbl_type_free_parms *parms);
164
165         /**
166          * Searches for the specified table type element in a shadow DB.
167          *
168          * This API searches for the specified table type element in a
169          * device specific shadow DB. If the element is found the
170          * reference count for the element is updated. If the element
171          * is not found a new element is allocated from the table type
172          * DB and then inserted into the shadow DB.
173          *
174          * [in] tfp
175          *   Pointer to TF handle
176          *
177          * [in] parms
178          *   Pointer to table type allocation and search parameters
179          *
180          * Returns
181          *   - (0) if successful.
182          *   - (-EINVAL) on failure.
183          */
184         int (*tf_dev_alloc_search_tbl_type)
185                         (struct tf *tfp,
186                         struct tf_tbl_type_alloc_search_parms *parms);
187
188         /**
189          * Sets the specified table type element.
190          *
191          * This API sets the specified element data by invoking the
192          * firmware.
193          *
194          * [in] tfp
195          *   Pointer to TF handle
196          *
197          * [in] parms
198          *   Pointer to table type set parameters
199          *
200          * Returns
201          *   - (0) if successful.
202          *   - (-EINVAL) on failure.
203          */
204         int (*tf_dev_set_tbl_type)(struct tf *tfp,
205                                    struct tf_tbl_type_set_parms *parms);
206
207         /**
208          * Retrieves the specified table type element.
209          *
210          * This API retrieves the specified element data by invoking the
211          * firmware.
212          *
213          * [in] tfp
214          *   Pointer to TF handle
215          *
216          * [in] parms
217          *   Pointer to table type get parameters
218          *
219          * Returns
220          *   - (0) if successful.
221          *   - (-EINVAL) on failure.
222          */
223         int (*tf_dev_get_tbl_type)(struct tf *tfp,
224                                    struct tf_tbl_type_get_parms *parms);
225
226         /**
227          * Allocation of a tcam element.
228          *
229          * This API allocates the specified tcam element from a device
230          * specific tcam DB. The allocated element is returned.
231          *
232          * [in] tfp
233          *   Pointer to TF handle
234          *
235          * [in] parms
236          *   Pointer to tcam allocation parameters
237          *
238          * Returns
239          *   - (0) if successful.
240          *   - (-EINVAL) on failure.
241          */
242         int (*tf_dev_alloc_tcam)(struct tf *tfp,
243                                  struct tf_tcam_alloc_parms *parms);
244
245         /**
246          * Free of a tcam element.
247          *
248          * This API free's a previous allocated tcam element from a
249          * device specific tcam DB.
250          *
251          * [in] tfp
252          *   Pointer to TF handle
253          *
254          * [in] parms
255          *   Pointer to tcam free parameters
256          *
257          * Returns
258          *   - (0) if successful.
259          *   - (-EINVAL) on failure.
260          */
261         int (*tf_dev_free_tcam)(struct tf *tfp,
262                                 struct tf_tcam_free_parms *parms);
263
264         /**
265          * Searches for the specified tcam element in a shadow DB.
266          *
267          * This API searches for the specified tcam element in a
268          * device specific shadow DB. If the element is found the
269          * reference count for the element is updated. If the element
270          * is not found a new element is allocated from the tcam DB
271          * and then inserted into the shadow DB.
272          *
273          * [in] tfp
274          *   Pointer to TF handle
275          *
276          * [in] parms
277          *   Pointer to tcam allocation and search parameters
278          *
279          * Returns
280          *   - (0) if successful.
281          *   - (-EINVAL) on failure.
282          */
283         int (*tf_dev_alloc_search_tcam)
284                         (struct tf *tfp,
285                         struct tf_tcam_alloc_search_parms *parms);
286
287         /**
288          * Sets the specified tcam element.
289          *
290          * This API sets the specified element data by invoking the
291          * firmware.
292          *
293          * [in] tfp
294          *   Pointer to TF handle
295          *
296          * [in] parms
297          *   Pointer to tcam set parameters
298          *
299          * Returns
300          *   - (0) if successful.
301          *   - (-EINVAL) on failure.
302          */
303         int (*tf_dev_set_tcam)(struct tf *tfp,
304                                struct tf_tcam_set_parms *parms);
305
306         /**
307          * Retrieves the specified tcam element.
308          *
309          * This API retrieves the specified element data by invoking the
310          * firmware.
311          *
312          * [in] tfp
313          *   Pointer to TF handle
314          *
315          * [in] parms
316          *   Pointer to tcam get parameters
317          *
318          * Returns
319          *   - (0) if successful.
320          *   - (-EINVAL) on failure.
321          */
322         int (*tf_dev_get_tcam)(struct tf *tfp,
323                                struct tf_tcam_get_parms *parms);
324 };
325
326 /**
327  * Supported device operation structures
328  */
329 extern const struct tf_dev_ops tf_dev_ops_p4;
330
331 #endif /* _TF_DEVICE_H_ */