xref: /dpdk/drivers/net/bnxt/tf_core/tf_device.h (revision 68a03efeed657e6e05f281479b33b51102797e15)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 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.h"
12 #include "tf_tcam.h"
13 #include "tf_if_tbl.h"
14 #include "tf_global_cfg.h"
15 
16 struct tf;
17 struct tf_session;
18 
19 /**
20  * Device module types
21  */
22 enum tf_device_module_type {
23 	/**
24 	 * Identifier module
25 	 */
26 	TF_DEVICE_MODULE_TYPE_IDENTIFIER,
27 	/**
28 	 * Table type module
29 	 */
30 	TF_DEVICE_MODULE_TYPE_TABLE,
31 	/**
32 	 * TCAM module
33 	 */
34 	TF_DEVICE_MODULE_TYPE_TCAM,
35 	/**
36 	 * EM module
37 	 */
38 	TF_DEVICE_MODULE_TYPE_EM,
39 	TF_DEVICE_MODULE_TYPE_MAX
40 };
41 
42 /**
43  * The Device module provides a general device template. A supported
44  * device type should implement one or more of the listed function
45  * pointers according to its capabilities.
46  *
47  * If a device function pointer is NULL the device capability is not
48  * supported.
49  */
50 
51 /**
52  * TF device information
53  */
54 struct tf_dev_info {
55 	enum tf_device_type type;
56 	const struct tf_dev_ops *ops;
57 };
58 
59 /**
60  * @page device Device
61  *
62  * @ref tf_dev_bind
63  *
64  * @ref tf_dev_unbind
65  */
66 
67 /**
68  * Device bind handles the initialization of the specified device
69  * type.
70  *
71  * [in] tfp
72  *   Pointer to TF handle
73  *
74  * [in] type
75  *   Device type
76  *
77  * [in] resources
78  *   Pointer to resource allocation information
79  *
80  * [out] dev_handle
81  *   Device handle
82  *
83  * Returns
84  *   - (0) if successful.
85  *   - (-EINVAL) parameter failure.
86  *   - (-ENODEV) no such device supported.
87  */
88 int tf_dev_bind(struct tf *tfp,
89 		enum tf_device_type type,
90 		bool shadow_copy,
91 		struct tf_session_resources *resources,
92 		struct tf_dev_info *dev_handle);
93 
94 /**
95  * Device release handles cleanup of the device specific information.
96  *
97  * [in] tfp
98  *   Pointer to TF handle
99  *
100  * [in] dev_handle
101  *   Device handle
102  *
103  * Returns
104  *   - (0) if successful.
105  *   - (-EINVAL) parameter failure.
106  *   - (-ENODEV) no such device supported.
107  */
108 int tf_dev_unbind(struct tf *tfp,
109 		  struct tf_dev_info *dev_handle);
110 
111 /**
112  * Truflow device specific function hooks structure
113  *
114  * The following device hooks can be defined; unless noted otherwise,
115  * they are optional and can be filled with a null pointer. The
116  * purpose of these hooks is to support Truflow device operations for
117  * different device variants.
118  */
119 struct tf_dev_ops {
120 	/**
121 	 * Retrieves the MAX number of resource types that the device
122 	 * supports.
123 	 *
124 	 * [in] tfp
125 	 *   Pointer to TF handle
126 	 *
127 	 * [out] max_types
128 	 *   Pointer to MAX number of types the device supports
129 	 *
130 	 * Returns
131 	 *   - (0) if successful.
132 	 *   - (-EINVAL) on failure.
133 	 */
134 	int (*tf_dev_get_max_types)(struct tf *tfp,
135 				    uint16_t *max_types);
136 
137 	/**
138 	 * Retrieves the WC TCAM slice information that the device
139 	 * supports.
140 	 *
141 	 * [in] tfp
142 	 *   Pointer to TF handle
143 	 *
144 	 * [in] type
145 	 *   TCAM table type
146 	 *
147 	 * [in] key_sz
148 	 *   Key size
149 	 *
150 	 * [out] num_slices_per_row
151 	 *   Pointer to number of slices per row the device supports
152 	 *
153 	 * Returns
154 	 *   - (0) if successful.
155 	 *   - (-EINVAL) on failure.
156 	 */
157 	int (*tf_dev_get_tcam_slice_info)(struct tf *tfp,
158 					  enum tf_tcam_tbl_type type,
159 					  uint16_t key_sz,
160 					  uint16_t *num_slices_per_row);
161 
162 	/**
163 	 * Allocation of an identifier element.
164 	 *
165 	 * This API allocates the specified identifier element from a
166 	 * device specific identifier DB. The allocated element is
167 	 * returned.
168 	 *
169 	 * [in] tfp
170 	 *   Pointer to TF handle
171 	 *
172 	 * [in] parms
173 	 *   Pointer to identifier allocation parameters
174 	 *
175 	 * Returns
176 	 *   - (0) if successful.
177 	 *   - (-EINVAL) on failure.
178 	 */
179 	int (*tf_dev_alloc_ident)(struct tf *tfp,
180 				  struct tf_ident_alloc_parms *parms);
181 
182 	/**
183 	 * Free of an identifier element.
184 	 *
185 	 * This API free's a previous allocated identifier element from a
186 	 * device specific identifier DB.
187 	 *
188 	 * [in] tfp
189 	 *   Pointer to TF handle
190 	 *
191 	 * [in] parms
192 	 *   Pointer to identifier free parameters
193 	 *
194 	 * Returns
195 	 *   - (0) if successful.
196 	 *   - (-EINVAL) on failure.
197 	 */
198 	int (*tf_dev_free_ident)(struct tf *tfp,
199 				 struct tf_ident_free_parms *parms);
200 
201 	/**
202 	 * Search of an identifier element.
203 	 *
204 	 * This API search the specified identifier element from a
205 	 * device specific identifier shadow DB. The allocated element
206 	 * is returned.
207 	 *
208 	 * [in] tfp
209 	 *   Pointer to TF handle
210 	 *
211 	 * [in] parms
212 	 *   Pointer to identifier search parameters
213 	 *
214 	 * Returns
215 	 *   - (0) if successful.
216 	 *   - (-EINVAL) on failure.
217 	 */
218 	int (*tf_dev_search_ident)(struct tf *tfp,
219 				   struct tf_ident_search_parms *parms);
220 
221 	/**
222 	 * Allocation of a table type element.
223 	 *
224 	 * This API allocates the specified table type element from a
225 	 * device specific table type DB. The allocated element is
226 	 * returned.
227 	 *
228 	 * [in] tfp
229 	 *   Pointer to TF handle
230 	 *
231 	 * [in] parms
232 	 *   Pointer to table allocation parameters
233 	 *
234 	 * Returns
235 	 *   - (0) if successful.
236 	 *   - (-EINVAL) on failure.
237 	 */
238 	int (*tf_dev_alloc_tbl)(struct tf *tfp,
239 				struct tf_tbl_alloc_parms *parms);
240 
241 	/**
242 	 * Allocation of a external table type element.
243 	 *
244 	 * This API allocates the specified table type element from a
245 	 * device specific table type DB. The allocated element is
246 	 * returned.
247 	 *
248 	 * [in] tfp
249 	 *   Pointer to TF handle
250 	 *
251 	 * [in] parms
252 	 *   Pointer to table allocation parameters
253 	 *
254 	 * Returns
255 	 *   - (0) if successful.
256 	 *   - (-EINVAL) on failure.
257 	 */
258 	int (*tf_dev_alloc_ext_tbl)(struct tf *tfp,
259 				    struct tf_tbl_alloc_parms *parms);
260 
261 	/**
262 	 * Free of a table type element.
263 	 *
264 	 * This API free's a previous allocated table type element from a
265 	 * device specific table type DB.
266 	 *
267 	 * [in] tfp
268 	 *   Pointer to TF handle
269 	 *
270 	 * [in] parms
271 	 *   Pointer to table free parameters
272 	 *
273 	 * Returns
274 	 *   - (0) if successful.
275 	 *   - (-EINVAL) on failure.
276 	 */
277 	int (*tf_dev_free_tbl)(struct tf *tfp,
278 			       struct tf_tbl_free_parms *parms);
279 
280 	/**
281 	 * Free of a external table type element.
282 	 *
283 	 * This API free's a previous allocated table type element from a
284 	 * device specific table type DB.
285 	 *
286 	 * [in] tfp
287 	 *   Pointer to TF handle
288 	 *
289 	 * [in] parms
290 	 *   Pointer to table free parameters
291 	 *
292 	 * Returns
293 	 *   - (0) if successful.
294 	 *   - (-EINVAL) on failure.
295 	 */
296 	int (*tf_dev_free_ext_tbl)(struct tf *tfp,
297 				   struct tf_tbl_free_parms *parms);
298 
299 	/**
300 	 * Searches for the specified table type element in a shadow DB.
301 	 *
302 	 * This API searches for the specified table type element in a
303 	 * device specific shadow DB. If the element is found the
304 	 * reference count for the element is updated. If the element
305 	 * is not found a new element is allocated from the table type
306 	 * DB and then inserted into the shadow DB.
307 	 *
308 	 * [in] tfp
309 	 *   Pointer to TF handle
310 	 *
311 	 * [in] parms
312 	 *   Pointer to table allocation and search parameters
313 	 *
314 	 * Returns
315 	 *   - (0) if successful.
316 	 *   - (-EINVAL) on failure.
317 	 */
318 	int (*tf_dev_alloc_search_tbl)(struct tf *tfp,
319 				       struct tf_tbl_alloc_search_parms *parms);
320 
321 	/**
322 	 * Sets the specified table type element.
323 	 *
324 	 * This API sets the specified element data by invoking the
325 	 * firmware.
326 	 *
327 	 * [in] tfp
328 	 *   Pointer to TF handle
329 	 *
330 	 * [in] parms
331 	 *   Pointer to table set parameters
332 	 *
333 	 * Returns
334 	 *   - (0) if successful.
335 	 *   - (-EINVAL) on failure.
336 	 */
337 	int (*tf_dev_set_tbl)(struct tf *tfp,
338 			      struct tf_tbl_set_parms *parms);
339 
340 	/**
341 	 * Sets the specified external table type element.
342 	 *
343 	 * This API sets the specified element data by invoking the
344 	 * firmware.
345 	 *
346 	 * [in] tfp
347 	 *   Pointer to TF handle
348 	 *
349 	 * [in] parms
350 	 *   Pointer to table set parameters
351 	 *
352 	 * Returns
353 	 *   - (0) if successful.
354 	 *   - (-EINVAL) on failure.
355 	 */
356 	int (*tf_dev_set_ext_tbl)(struct tf *tfp,
357 				  struct tf_tbl_set_parms *parms);
358 
359 	/**
360 	 * Retrieves the specified table type element.
361 	 *
362 	 * This API retrieves the specified element data by invoking the
363 	 * firmware.
364 	 *
365 	 * [in] tfp
366 	 *   Pointer to TF handle
367 	 *
368 	 * [in] parms
369 	 *   Pointer to table get parameters
370 	 *
371 	 * Returns
372 	 *   - (0) if successful.
373 	 *   - (-EINVAL) on failure.
374 	 */
375 	int (*tf_dev_get_tbl)(struct tf *tfp,
376 			      struct tf_tbl_get_parms *parms);
377 
378 	/**
379 	 * Retrieves the specified table type element using 'bulk'
380 	 * mechanism.
381 	 *
382 	 * This API retrieves the specified element data by invoking the
383 	 * firmware.
384 	 *
385 	 * [in] tfp
386 	 *   Pointer to TF handle
387 	 *
388 	 * [in] parms
389 	 *   Pointer to table get bulk parameters
390 	 *
391 	 * Returns
392 	 *   - (0) if successful.
393 	 *   - (-EINVAL) on failure.
394 	 */
395 	int (*tf_dev_get_bulk_tbl)(struct tf *tfp,
396 				   struct tf_tbl_get_bulk_parms *parms);
397 
398 	/**
399 	 * Allocation of a tcam element.
400 	 *
401 	 * This API allocates the specified tcam element from a device
402 	 * specific tcam DB. The allocated element is returned.
403 	 *
404 	 * [in] tfp
405 	 *   Pointer to TF handle
406 	 *
407 	 * [in] parms
408 	 *   Pointer to tcam allocation parameters
409 	 *
410 	 * Returns
411 	 *   - (0) if successful.
412 	 *   - (-EINVAL) on failure.
413 	 */
414 	int (*tf_dev_alloc_tcam)(struct tf *tfp,
415 				 struct tf_tcam_alloc_parms *parms);
416 
417 	/**
418 	 * Free of a tcam element.
419 	 *
420 	 * This API free's a previous allocated tcam element from a
421 	 * device specific tcam DB.
422 	 *
423 	 * [in] tfp
424 	 *   Pointer to TF handle
425 	 *
426 	 * [in] parms
427 	 *   Pointer to tcam free parameters
428 	 *
429 	 * Returns
430 	 *   - (0) if successful.
431 	 *   - (-EINVAL) on failure.
432 	 */
433 	int (*tf_dev_free_tcam)(struct tf *tfp,
434 				struct tf_tcam_free_parms *parms);
435 
436 	/**
437 	 * Searches for the specified tcam element in a shadow DB.
438 	 *
439 	 * This API searches for the specified tcam element in a
440 	 * device specific shadow DB. If the element is found the
441 	 * reference count for the element is updated. If the element
442 	 * is not found a new element is allocated from the tcam DB
443 	 * and then inserted into the shadow DB.
444 	 *
445 	 * [in] tfp
446 	 *   Pointer to TF handle
447 	 *
448 	 * [in] parms
449 	 *   Pointer to tcam allocation and search parameters
450 	 *
451 	 * Returns
452 	 *   - (0) if successful.
453 	 *   - (-EINVAL) on failure.
454 	 */
455 	int (*tf_dev_alloc_search_tcam)
456 			(struct tf *tfp,
457 			struct tf_tcam_alloc_search_parms *parms);
458 
459 	/**
460 	 * Sets the specified tcam element.
461 	 *
462 	 * This API sets the specified element data by invoking the
463 	 * firmware.
464 	 *
465 	 * [in] tfp
466 	 *   Pointer to TF handle
467 	 *
468 	 * [in] parms
469 	 *   Pointer to tcam set parameters
470 	 *
471 	 * Returns
472 	 *   - (0) if successful.
473 	 *   - (-EINVAL) on failure.
474 	 */
475 	int (*tf_dev_set_tcam)(struct tf *tfp,
476 			       struct tf_tcam_set_parms *parms);
477 
478 	/**
479 	 * Retrieves the specified tcam element.
480 	 *
481 	 * This API retrieves the specified element data by invoking the
482 	 * firmware.
483 	 *
484 	 * [in] tfp
485 	 *   Pointer to TF handle
486 	 *
487 	 * [in] parms
488 	 *   Pointer to tcam get parameters
489 	 *
490 	 * Returns
491 	 *   - (0) if successful.
492 	 *   - (-EINVAL) on failure.
493 	 */
494 	int (*tf_dev_get_tcam)(struct tf *tfp,
495 			       struct tf_tcam_get_parms *parms);
496 
497 	/**
498 	 * Insert EM hash entry API
499 	 *
500 	 * [in] tfp
501 	 *   Pointer to TF handle
502 	 *
503 	 * [in] parms
504 	 *   Pointer to E/EM insert parameters
505 	 *
506 	 *  Returns:
507 	 *    0       - Success
508 	 *    -EINVAL - Error
509 	 */
510 	int (*tf_dev_insert_int_em_entry)(struct tf *tfp,
511 					  struct tf_insert_em_entry_parms *parms);
512 
513 	/**
514 	 * Delete EM hash entry API
515 	 *
516 	 * [in] tfp
517 	 *   Pointer to TF handle
518 	 *
519 	 * [in] parms
520 	 *   Pointer to E/EM delete parameters
521 	 *
522 	 *    returns:
523 	 *    0       - Success
524 	 *    -EINVAL - Error
525 	 */
526 	int (*tf_dev_delete_int_em_entry)(struct tf *tfp,
527 					  struct tf_delete_em_entry_parms *parms);
528 
529 	/**
530 	 * Insert EEM hash entry API
531 	 *
532 	 * [in] tfp
533 	 *   Pointer to TF handle
534 	 *
535 	 * [in] parms
536 	 *   Pointer to E/EM insert parameters
537 	 *
538 	 *  Returns:
539 	 *    0       - Success
540 	 *    -EINVAL - Error
541 	 */
542 	int (*tf_dev_insert_ext_em_entry)(struct tf *tfp,
543 					  struct tf_insert_em_entry_parms *parms);
544 
545 	/**
546 	 * Delete EEM hash entry API
547 	 *
548 	 * [in] tfp
549 	 *   Pointer to TF handle
550 	 *
551 	 * [in] parms
552 	 *   Pointer to E/EM delete parameters
553 	 *
554 	 *    returns:
555 	 *    0       - Success
556 	 *    -EINVAL - Error
557 	 */
558 	int (*tf_dev_delete_ext_em_entry)(struct tf *tfp,
559 					  struct tf_delete_em_entry_parms *parms);
560 
561 	/**
562 	 * Allocate EEM table scope
563 	 *
564 	 * [in] tfp
565 	 *   Pointer to TF handle
566 	 *
567 	 * [in] parms
568 	 *   Pointer to table scope alloc parameters
569 	 *
570 	 *    returns:
571 	 *    0       - Success
572 	 *    -EINVAL - Error
573 	 */
574 	int (*tf_dev_alloc_tbl_scope)(struct tf *tfp,
575 				      struct tf_alloc_tbl_scope_parms *parms);
576 	/**
577 	 * Map EEM parif
578 	 *
579 	 * [in] tfp
580 	 *   Pointer to TF handle
581 	 *
582 	 * [in] pf
583 	 * PF associated with the table scope
584 	 *
585 	 * [in] parif_bitmask
586 	 * Bitmask of PARIFs to enable
587 	 *
588 	 * [in/out] pointer to the parif_2_pf data to be updated
589 	 *
590 	 * [in/out] pointer to the parif_2_pf mask to be updated
591 	 *
592 	 * [in] sz_in_bytes - number of bytes to be written
593 	 *
594 	 *    returns:
595 	 *    0       - Success
596 	 *    -EINVAL - Error
597 	 */
598 	int (*tf_dev_map_parif)(struct tf *tfp,
599 				uint16_t parif_bitmask,
600 				uint16_t pf,
601 				uint8_t *data,
602 				uint8_t *mask,
603 				uint16_t sz_in_bytes);
604 	/**
605 	 * Map EEM table scope
606 	 *
607 	 * [in] tfp
608 	 *   Pointer to TF handle
609 	 *
610 	 * [in] parms
611 	 *   Pointer to table scope map parameters
612 	 *
613 	 *    returns:
614 	 *    0       - Success
615 	 *    -EINVAL - Error
616 	 */
617 	int (*tf_dev_map_tbl_scope)(struct tf *tfp,
618 				    struct tf_map_tbl_scope_parms *parms);
619 
620 	/**
621 	 * Free EEM table scope
622 	 *
623 	 * [in] tfp
624 	 *   Pointer to TF handle
625 	 *
626 	 * [in] parms
627 	 *   Pointer to table scope free parameters
628 	 *
629 	 *    returns:
630 	 *    0       - Success
631 	 *    -EINVAL - Error
632 	 */
633 	int (*tf_dev_free_tbl_scope)(struct tf *tfp,
634 				     struct tf_free_tbl_scope_parms *parms);
635 
636 	/**
637 	 * Sets the specified interface table type element.
638 	 *
639 	 * This API sets the specified element data by invoking the
640 	 * firmware.
641 	 *
642 	 * [in] tfp
643 	 *   Pointer to TF handle
644 	 *
645 	 * [in] parms
646 	 *   Pointer to interface table set parameters
647 	 *
648 	 * Returns
649 	 *   - (0) if successful.
650 	 *   - (-EINVAL) on failure.
651 	 */
652 	int (*tf_dev_set_if_tbl)(struct tf *tfp,
653 				 struct tf_if_tbl_set_parms *parms);
654 
655 	/**
656 	 * Retrieves the specified interface table type element.
657 	 *
658 	 * This API retrieves the specified element data by invoking the
659 	 * firmware.
660 	 *
661 	 * [in] tfp
662 	 *   Pointer to TF handle
663 	 *
664 	 * [in] parms
665 	 *   Pointer to table get parameters
666 	 *
667 	 * Returns
668 	 *   - (0) if successful.
669 	 *   - (-EINVAL) on failure.
670 	 */
671 	int (*tf_dev_get_if_tbl)(struct tf *tfp,
672 				 struct tf_if_tbl_get_parms *parms);
673 
674 	/**
675 	 * Update global cfg
676 	 *
677 	 * [in] tfp
678 	 *   Pointer to TF handle
679 	 *
680 	 * [in] parms
681 	 *   Pointer to global cfg parameters
682 	 *
683 	 *    returns:
684 	 *    0       - Success
685 	 *    -EINVAL - Error
686 	 */
687 	int (*tf_dev_set_global_cfg)(struct tf *tfp,
688 				     struct tf_global_cfg_parms *parms);
689 
690 	/**
691 	 * Get global cfg
692 	 *
693 	 * [in] tfp
694 	 *   Pointer to TF handle
695 	 *
696 	 * [in] parms
697 	 *   Pointer to global cfg parameters
698 	 *
699 	 *    returns:
700 	 *    0       - Success
701 	 *    -EINVAL - Error
702 	 */
703 	int (*tf_dev_get_global_cfg)(struct tf *tfp,
704 				     struct tf_global_cfg_parms *parms);
705 };
706 
707 /**
708  * Supported device operation structures
709  */
710 extern const struct tf_dev_ops tf_dev_ops_p4_init;
711 extern const struct tf_dev_ops tf_dev_ops_p4;
712 
713 #endif /* _TF_DEVICE_H_ */
714