1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
10 #include "tf_identifier.h"
13 #include "tf_if_tbl.h"
14 #include "tf_global_cfg.h"
20 * The Device module provides a general device template. A supported
21 * device type should implement one or more of the listed function
22 * pointers according to its capabilities.
24 * If a device function pointer is NULL the device capability is not
29 * TF device information
32 enum tf_device_type type;
33 const struct tf_dev_ops *ops;
45 * Device bind handles the initialization of the specified device
49 * Pointer to TF handle
55 * Pointer to resource allocation information
61 * - (0) if successful.
62 * - (-EINVAL) parameter failure.
63 * - (-ENODEV) no such device supported.
65 int tf_dev_bind(struct tf *tfp,
66 enum tf_device_type type,
68 struct tf_session_resources *resources,
69 struct tf_dev_info *dev_handle);
72 * Device release handles cleanup of the device specific information.
75 * Pointer to TF handle
81 * - (0) if successful.
82 * - (-EINVAL) parameter failure.
83 * - (-ENODEV) no such device supported.
85 int tf_dev_unbind(struct tf *tfp,
86 struct tf_dev_info *dev_handle);
89 tf_dev_bind_ops(enum tf_device_type type,
90 struct tf_dev_info *dev_handle);
93 * Truflow device specific function hooks structure
95 * The following device hooks can be defined; unless noted otherwise,
96 * they are optional and can be filled with a null pointer. The
97 * purpose of these hooks is to support Truflow device operations for
98 * different device variants.
102 * Retrieves the MAX number of resource types that the device
106 * Pointer to TF handle
109 * Pointer to MAX number of types the device supports
112 * - (0) if successful.
113 * - (-EINVAL) on failure.
115 int (*tf_dev_get_max_types)(struct tf *tfp,
116 uint16_t *max_types);
119 * Retrieves the string description for the CFA resource
123 * Pointer to TF handle
126 * HCAPI cfa resource type id
129 * Pointer to a string
132 * - (0) if successful.
133 * - (-EINVAL) on failure.
135 int (*tf_dev_get_resource_str)(struct tf *tfp,
136 uint16_t resource_id,
137 const char **resource_str);
141 * Retrieves the WC TCAM slice information that the device
145 * Pointer to TF handle
153 * [out] num_slices_per_row
154 * Pointer to number of slices per row the device supports
157 * - (0) if successful.
158 * - (-EINVAL) on failure.
160 int (*tf_dev_get_tcam_slice_info)(struct tf *tfp,
161 enum tf_tcam_tbl_type type,
163 uint16_t *num_slices_per_row);
166 * Allocation of an identifier element.
168 * This API allocates the specified identifier element from a
169 * device specific identifier DB. The allocated element is
173 * Pointer to TF handle
176 * Pointer to identifier allocation parameters
179 * - (0) if successful.
180 * - (-EINVAL) on failure.
182 int (*tf_dev_alloc_ident)(struct tf *tfp,
183 struct tf_ident_alloc_parms *parms);
186 * Free of an identifier element.
188 * This API free's a previous allocated identifier element from a
189 * device specific identifier DB.
192 * Pointer to TF handle
195 * Pointer to identifier free parameters
198 * - (0) if successful.
199 * - (-EINVAL) on failure.
201 int (*tf_dev_free_ident)(struct tf *tfp,
202 struct tf_ident_free_parms *parms);
205 * Search of an identifier element.
207 * This API search the specified identifier element from a
208 * device specific identifier shadow DB. The allocated element
212 * Pointer to TF handle
215 * Pointer to identifier search parameters
218 * - (0) if successful.
219 * - (-EINVAL) on failure.
221 int (*tf_dev_search_ident)(struct tf *tfp,
222 struct tf_ident_search_parms *parms);
225 * Retrieves the identifier resource info.
227 * This API retrieves the identifier resource info from the rm db.
230 * Pointer to TF handle
233 * Pointer to identifier info
236 * - (0) if successful.
237 * - (-EINVAL) on failure.
239 int (*tf_dev_get_ident_resc_info)(struct tf *tfp,
240 struct tf_identifier_resource_info *parms);
243 * Get SRAM table information.
245 * Converts an internal RM allocated element offset to
246 * a user address and vice versa.
249 * Pointer to TF handle
252 * Truflow index table type, e.g. TF_TYPE_FULL_ACT_RECORD
255 * Pointer to the base address of the associated table type.
258 * Pointer to any shift required for the associated table type.
261 * - (0) if successful.
262 * - (-EINVAL) on failure.
264 int (*tf_dev_get_tbl_info)(struct tf *tfp,
266 enum tf_tbl_type type,
271 * Allocation of an index table type element.
273 * This API allocates the specified table type element from a
274 * device specific table type DB. The allocated element is
278 * Pointer to TF handle
281 * Pointer to table allocation parameters
284 * - (0) if successful.
285 * - (-EINVAL) on failure.
287 int (*tf_dev_alloc_tbl)(struct tf *tfp,
288 struct tf_tbl_alloc_parms *parms);
291 * Allocation of a external table type element.
293 * This API allocates the specified table type element from a
294 * device specific table type DB. The allocated element is
298 * Pointer to TF handle
301 * Pointer to table allocation parameters
304 * - (0) if successful.
305 * - (-EINVAL) on failure.
307 int (*tf_dev_alloc_ext_tbl)(struct tf *tfp,
308 struct tf_tbl_alloc_parms *parms);
311 * Free of a table type element.
313 * This API free's a previous allocated table type element from a
314 * device specific table type DB.
317 * Pointer to TF handle
320 * Pointer to table free parameters
323 * - (0) if successful.
324 * - (-EINVAL) on failure.
326 int (*tf_dev_free_tbl)(struct tf *tfp,
327 struct tf_tbl_free_parms *parms);
330 * Free of a external table type element.
332 * This API free's a previous allocated table type element from a
333 * device specific table type DB.
336 * Pointer to TF handle
339 * Pointer to table free parameters
342 * - (0) if successful.
343 * - (-EINVAL) on failure.
345 int (*tf_dev_free_ext_tbl)(struct tf *tfp,
346 struct tf_tbl_free_parms *parms);
349 * Searches for the specified table type element in a shadow DB.
351 * This API searches for the specified table type element in a
352 * device specific shadow DB. If the element is found the
353 * reference count for the element is updated. If the element
354 * is not found a new element is allocated from the table type
355 * DB and then inserted into the shadow DB.
358 * Pointer to TF handle
361 * Pointer to table allocation and search parameters
364 * - (0) if successful.
365 * - (-EINVAL) on failure.
367 int (*tf_dev_alloc_search_tbl)(struct tf *tfp,
368 struct tf_tbl_alloc_search_parms *parms);
371 * Sets the specified table type element.
373 * This API sets the specified element data by invoking the
377 * Pointer to TF handle
380 * Pointer to table set parameters
383 * - (0) if successful.
384 * - (-EINVAL) on failure.
386 int (*tf_dev_set_tbl)(struct tf *tfp,
387 struct tf_tbl_set_parms *parms);
390 * Sets the specified external table type element.
392 * This API sets the specified element data by invoking the
396 * Pointer to TF handle
399 * Pointer to table set parameters
402 * - (0) if successful.
403 * - (-EINVAL) on failure.
405 int (*tf_dev_set_ext_tbl)(struct tf *tfp,
406 struct tf_tbl_set_parms *parms);
409 * Retrieves the specified table type element.
411 * This API retrieves the specified element data by invoking the
415 * Pointer to TF handle
418 * Pointer to table get parameters
421 * - (0) if successful.
422 * - (-EINVAL) on failure.
424 int (*tf_dev_get_tbl)(struct tf *tfp,
425 struct tf_tbl_get_parms *parms);
428 * Retrieves the specified table type element using 'bulk'
431 * This API retrieves the specified element data by invoking the
435 * Pointer to TF handle
438 * Pointer to table get bulk parameters
441 * - (0) if successful.
442 * - (-EINVAL) on failure.
444 int (*tf_dev_get_bulk_tbl)(struct tf *tfp,
445 struct tf_tbl_get_bulk_parms *parms);
448 * Retrieves the table resource info.
450 * This API retrieves the table resource info from the rm db.
453 * Pointer to TF handle
456 * Pointer to tbl info
459 * - (0) if successful.
460 * - (-EINVAL) on failure.
462 int (*tf_dev_get_tbl_resc_info)(struct tf *tfp,
463 struct tf_tbl_resource_info *parms);
466 * Allocation of a tcam element.
468 * This API allocates the specified tcam element from a device
469 * specific tcam DB. The allocated element is returned.
472 * Pointer to TF handle
475 * Pointer to tcam allocation parameters
478 * - (0) if successful.
479 * - (-EINVAL) on failure.
481 int (*tf_dev_alloc_tcam)(struct tf *tfp,
482 struct tf_tcam_alloc_parms *parms);
485 * Free of a tcam element.
487 * This API free's a previous allocated tcam element from a
488 * device specific tcam DB.
491 * Pointer to TF handle
494 * Pointer to tcam free parameters
497 * - (0) if successful.
498 * - (-EINVAL) on failure.
500 int (*tf_dev_free_tcam)(struct tf *tfp,
501 struct tf_tcam_free_parms *parms);
504 * Searches for the specified tcam element in a shadow DB.
506 * This API searches for the specified tcam element in a
507 * device specific shadow DB. If the element is found the
508 * reference count for the element is updated. If the element
509 * is not found a new element is allocated from the tcam DB
510 * and then inserted into the shadow DB.
513 * Pointer to TF handle
516 * Pointer to tcam allocation and search parameters
519 * - (0) if successful.
520 * - (-EINVAL) on failure.
522 int (*tf_dev_alloc_search_tcam)
524 struct tf_tcam_alloc_search_parms *parms);
527 * Sets the specified tcam element.
529 * This API sets the specified element data by invoking the
533 * Pointer to TF handle
536 * Pointer to tcam set parameters
539 * - (0) if successful.
540 * - (-EINVAL) on failure.
542 int (*tf_dev_set_tcam)(struct tf *tfp,
543 struct tf_tcam_set_parms *parms);
546 * Retrieves the specified tcam element.
548 * This API retrieves the specified element data by invoking the
552 * Pointer to TF handle
555 * Pointer to tcam get parameters
558 * - (0) if successful.
559 * - (-EINVAL) on failure.
561 int (*tf_dev_get_tcam)(struct tf *tfp,
562 struct tf_tcam_get_parms *parms);
565 * Retrieves the tcam resource info.
567 * This API retrieves the tcam resource info from the rm db.
570 * Pointer to TF handle
573 * Pointer to tcam info
576 * - (0) if successful.
577 * - (-EINVAL) on failure.
579 int (*tf_dev_get_tcam_resc_info)(struct tf *tfp,
580 struct tf_tcam_resource_info *parms);
583 * Insert EM hash entry API
586 * Pointer to TF handle
589 * Pointer to E/EM insert parameters
595 int (*tf_dev_insert_int_em_entry)(struct tf *tfp,
596 struct tf_insert_em_entry_parms *parms);
599 * Delete EM hash entry API
602 * Pointer to TF handle
605 * Pointer to E/EM delete parameters
611 int (*tf_dev_delete_int_em_entry)(struct tf *tfp,
612 struct tf_delete_em_entry_parms *parms);
615 * Move EM hash entry API
618 * Pointer to TF handle
621 * Pointer to E/EM move parameters
627 int (*tf_dev_move_int_em_entry)(struct tf *tfp,
628 struct tf_move_em_entry_parms *parms);
631 * Insert EEM hash entry API
634 * Pointer to TF handle
637 * Pointer to E/EM insert parameters
643 int (*tf_dev_insert_ext_em_entry)(struct tf *tfp,
644 struct tf_insert_em_entry_parms *parms);
647 * Delete EEM hash entry API
650 * Pointer to TF handle
653 * Pointer to E/EM delete parameters
659 int (*tf_dev_delete_ext_em_entry)(struct tf *tfp,
660 struct tf_delete_em_entry_parms *parms);
663 * Retrieves the em resource info.
665 * This API retrieves the em resource info from the rm db.
668 * Pointer to TF handle
674 * - (0) if successful.
675 * - (-EINVAL) on failure.
677 int (*tf_dev_get_em_resc_info)(struct tf *tfp,
678 struct tf_em_resource_info *parms);
681 * Move EEM hash entry API
683 * Pointer to E/EM move parameters
686 * Pointer to TF handle
695 int (*tf_dev_move_ext_em_entry)(struct tf *tfp,
696 struct tf_move_em_entry_parms *parms);
699 * Allocate EEM table scope
702 * Pointer to TF handle
705 * Pointer to table scope alloc parameters
711 int (*tf_dev_alloc_tbl_scope)(struct tf *tfp,
712 struct tf_alloc_tbl_scope_parms *parms);
717 * Pointer to TF handle
720 * PF associated with the table scope
723 * Bitmask of PARIFs to enable
725 * [in/out] pointer to the parif_2_pf data to be updated
727 * [in/out] pointer to the parif_2_pf mask to be updated
729 * [in] sz_in_bytes - number of bytes to be written
735 int (*tf_dev_map_parif)(struct tf *tfp,
736 uint16_t parif_bitmask,
740 uint16_t sz_in_bytes);
742 * Map EEM table scope
745 * Pointer to TF handle
748 * Pointer to table scope map parameters
754 int (*tf_dev_map_tbl_scope)(struct tf *tfp,
755 struct tf_map_tbl_scope_parms *parms);
758 * Free EEM table scope
761 * Pointer to TF handle
764 * Pointer to table scope free parameters
770 int (*tf_dev_free_tbl_scope)(struct tf *tfp,
771 struct tf_free_tbl_scope_parms *parms);
774 * Sets the specified interface table type element.
776 * This API sets the specified element data by invoking the
780 * Pointer to TF handle
783 * Pointer to interface table set parameters
786 * - (0) if successful.
787 * - (-EINVAL) on failure.
789 int (*tf_dev_set_if_tbl)(struct tf *tfp,
790 struct tf_if_tbl_set_parms *parms);
793 * Retrieves the specified interface table type element.
795 * This API retrieves the specified element data by invoking the
799 * Pointer to TF handle
802 * Pointer to table get parameters
805 * - (0) if successful.
806 * - (-EINVAL) on failure.
808 int (*tf_dev_get_if_tbl)(struct tf *tfp,
809 struct tf_if_tbl_get_parms *parms);
815 * Pointer to TF handle
818 * Pointer to global cfg parameters
824 int (*tf_dev_set_global_cfg)(struct tf *tfp,
825 struct tf_global_cfg_parms *parms);
831 * Pointer to TF handle
834 * Pointer to global cfg parameters
840 int (*tf_dev_get_global_cfg)(struct tf *tfp,
841 struct tf_global_cfg_parms *parms);
849 int (*tf_dev_get_mailbox)(void);
852 * Convert length in bit to length in byte and align to word.
853 * The word length depends on device type.
861 int (*tf_dev_word_align)(uint16_t size);
864 * Hash key using crc32 and lookup3
875 uint64_t (*tf_dev_cfa_key_hash)(uint64_t *key_data,
880 * Supported device operation structures
882 extern const struct tf_dev_ops tf_dev_ops_p4_init;
883 extern const struct tf_dev_ops tf_dev_ops_p4;
884 extern const struct tf_dev_ops tf_dev_ops_p58_init;
885 extern const struct tf_dev_ops tf_dev_ops_p58;
887 #endif /* _TF_DEVICE_H_ */