1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
10 #include "tf_identifier.h"
14 #include "tf_tcam_shared.h"
16 #include "tf_if_tbl.h"
17 #include "tf_global_cfg.h"
23 * The Device module provides a general device template. A supported
24 * device type should implement one or more of the listed function
25 * pointers according to its capabilities.
27 * If a device function pointer is NULL the device capability is not
32 * TF device information
35 enum tf_device_type type;
36 const struct tf_dev_ops *ops;
48 * Device bind handles the initialization of the specified device
52 * Pointer to TF handle
58 * Pointer to resource allocation information
61 * Number of slices per row for WC
67 * - (0) if successful.
68 * - (-EINVAL) parameter failure.
69 * - (-ENODEV) no such device supported.
71 int tf_dev_bind(struct tf *tfp,
72 enum tf_device_type type,
74 struct tf_session_resources *resources,
75 uint16_t wc_num_slices,
76 struct tf_dev_info *dev_handle);
79 * Device release handles cleanup of the device specific information.
82 * Pointer to TF handle
88 * - (0) if successful.
89 * - (-EINVAL) parameter failure.
90 * - (-ENODEV) no such device supported.
92 int tf_dev_unbind(struct tf *tfp,
93 struct tf_dev_info *dev_handle);
96 tf_dev_bind_ops(enum tf_device_type type,
97 struct tf_dev_info *dev_handle);
100 * Truflow device specific function hooks structure
102 * The following device hooks can be defined; unless noted otherwise,
103 * they are optional and can be filled with a null pointer. The
104 * purpose of these hooks is to support Truflow device operations for
105 * different device variants.
109 * Retrieves the MAX number of resource types that the device
113 * Pointer to TF handle
116 * Pointer to MAX number of types the device supports
119 * - (0) if successful.
120 * - (-EINVAL) on failure.
122 int (*tf_dev_get_max_types)(struct tf *tfp,
123 uint16_t *max_types);
126 * Retrieves the string description for the CFA resource
130 * Pointer to TF handle
133 * HCAPI cfa resource type id
136 * Pointer to a string
139 * - (0) if successful.
140 * - (-EINVAL) on failure.
142 int (*tf_dev_get_resource_str)(struct tf *tfp,
143 uint16_t resource_id,
144 const char **resource_str);
147 * Set the WC TCAM slice information that the device
151 * Pointer to TF handle
153 * [in] num_slices_per_row
154 * Number of slices per row the device supports
157 * - (0) if successful.
158 * - (-EINVAL) on failure.
160 int (*tf_dev_set_tcam_slice_info)(struct tf *tfp,
161 enum tf_wc_num_slice num_slices_per_row);
164 * Retrieves the WC TCAM slice information that the device
168 * Pointer to TF handle
176 * [out] num_slices_per_row
177 * Pointer to number of slices per row the device supports
180 * - (0) if successful.
181 * - (-EINVAL) on failure.
183 int (*tf_dev_get_tcam_slice_info)(struct tf *tfp,
184 enum tf_tcam_tbl_type type,
186 uint16_t *num_slices_per_row);
189 * Allocation of an identifier element.
191 * This API allocates the specified identifier element from a
192 * device specific identifier DB. The allocated element is
196 * Pointer to TF handle
199 * Pointer to identifier allocation parameters
202 * - (0) if successful.
203 * - (-EINVAL) on failure.
205 int (*tf_dev_alloc_ident)(struct tf *tfp,
206 struct tf_ident_alloc_parms *parms);
209 * Free of an identifier element.
211 * This API free's a previous allocated identifier element from a
212 * device specific identifier DB.
215 * Pointer to TF handle
218 * Pointer to identifier free parameters
221 * - (0) if successful.
222 * - (-EINVAL) on failure.
224 int (*tf_dev_free_ident)(struct tf *tfp,
225 struct tf_ident_free_parms *parms);
228 * Search of an identifier element.
230 * This API search the specified identifier element from a
231 * device specific identifier shadow DB. The allocated element
235 * Pointer to TF handle
238 * Pointer to identifier search parameters
241 * - (0) if successful.
242 * - (-EINVAL) on failure.
244 int (*tf_dev_search_ident)(struct tf *tfp,
245 struct tf_ident_search_parms *parms);
248 * Retrieves the identifier resource info.
250 * This API retrieves the identifier resource info from the rm db.
253 * Pointer to TF handle
256 * Pointer to identifier info
259 * - (0) if successful.
260 * - (-EINVAL) on failure.
262 int (*tf_dev_get_ident_resc_info)(struct tf *tfp,
263 struct tf_identifier_resource_info *parms);
266 * Indicates whether the index table type is SRAM managed
269 * Pointer to TF handle
272 * Truflow index table type, e.g. TF_TYPE_FULL_ACT_RECORD
275 * - (0) if the table is not managed by the SRAM manager
276 * - (1) if the table is managed by the SRAM manager
278 bool (*tf_dev_is_sram_managed)(struct tf *tfp,
279 enum tf_tbl_type tbl_type);
282 * Get SRAM table information.
284 * Converts an internal RM allocated element offset to
285 * a user address and vice versa.
288 * Pointer to TF handle
291 * Truflow index table type, e.g. TF_TYPE_FULL_ACT_RECORD
294 * Pointer to the base address of the associated table type.
297 * Pointer to any shift required for the associated table type.
300 * - (0) if successful.
301 * - (-EINVAL) on failure.
303 int (*tf_dev_get_tbl_info)(struct tf *tfp,
305 enum tf_tbl_type type,
310 * Allocation of an index table type element.
312 * This API allocates the specified table type element from a
313 * device specific table type DB. The allocated element is
317 * Pointer to TF handle
320 * Pointer to table allocation parameters
323 * - (0) if successful.
324 * - (-EINVAL) on failure.
326 int (*tf_dev_alloc_tbl)(struct tf *tfp,
327 struct tf_tbl_alloc_parms *parms);
330 * Allocation of an SRAM index table type element.
332 * This API allocates the specified table type element from a
333 * device specific table type DB. The allocated element is
337 * Pointer to TF handle
340 * Pointer to table allocation parameters
343 * - (0) if successful.
344 * - (-EINVAL) on failure.
346 int (*tf_dev_alloc_sram_tbl)(struct tf *tfp,
347 struct tf_tbl_alloc_parms *parms);
349 * Allocation of a external table type element.
351 * This API allocates the specified table type element from a
352 * device specific table type DB. The allocated element is
356 * Pointer to TF handle
359 * Pointer to table allocation parameters
362 * - (0) if successful.
363 * - (-EINVAL) on failure.
365 int (*tf_dev_alloc_ext_tbl)(struct tf *tfp,
366 struct tf_tbl_alloc_parms *parms);
369 * Free of a table type element.
371 * This API free's a previous allocated table type element from a
372 * device specific table type DB.
375 * Pointer to TF handle
378 * Pointer to table free parameters
381 * - (0) if successful.
382 * - (-EINVAL) on failure.
384 int (*tf_dev_free_tbl)(struct tf *tfp,
385 struct tf_tbl_free_parms *parms);
387 * Free of an SRAM table type element.
389 * This API free's a previous allocated table type element from a
390 * device specific table type DB.
393 * Pointer to TF handle
396 * Pointer to table free parameters
399 * - (0) if successful.
400 * - (-EINVAL) on failure.
402 int (*tf_dev_free_sram_tbl)(struct tf *tfp,
403 struct tf_tbl_free_parms *parms);
405 * Free of a external table type element.
407 * This API free's a previous allocated table type element from a
408 * device specific table type DB.
411 * Pointer to TF handle
414 * Pointer to table free parameters
417 * - (0) if successful.
418 * - (-EINVAL) on failure.
420 int (*tf_dev_free_ext_tbl)(struct tf *tfp,
421 struct tf_tbl_free_parms *parms);
424 * Sets the specified table type element.
426 * This API sets the specified element data by invoking the
430 * Pointer to TF handle
433 * Pointer to table set parameters
436 * - (0) if successful.
437 * - (-EINVAL) on failure.
439 int (*tf_dev_set_tbl)(struct tf *tfp,
440 struct tf_tbl_set_parms *parms);
443 * Sets the specified external table type element.
445 * This API sets the specified element data by invoking the
449 * Pointer to TF handle
452 * Pointer to table set parameters
455 * - (0) if successful.
456 * - (-EINVAL) on failure.
458 int (*tf_dev_set_ext_tbl)(struct tf *tfp,
459 struct tf_tbl_set_parms *parms);
462 * Sets the specified SRAM table type element.
464 * This API sets the specified element data by invoking the
468 * Pointer to TF handle
471 * Pointer to table set parameters
474 * - (0) if successful.
475 * - (-EINVAL) on failure.
477 int (*tf_dev_set_sram_tbl)(struct tf *tfp,
478 struct tf_tbl_set_parms *parms);
481 * Retrieves the specified table type element.
483 * This API retrieves the specified element data by invoking the
487 * Pointer to TF handle
490 * Pointer to table get parameters
493 * - (0) if successful.
494 * - (-EINVAL) on failure.
496 int (*tf_dev_get_tbl)(struct tf *tfp,
497 struct tf_tbl_get_parms *parms);
500 * Retrieves the specified SRAM table type element.
502 * This API retrieves the specified element data by invoking the
506 * Pointer to TF handle
509 * Pointer to table get parameters
512 * - (0) if successful.
513 * - (-EINVAL) on failure.
515 int (*tf_dev_get_sram_tbl)(struct tf *tfp,
516 struct tf_tbl_get_parms *parms);
519 * Retrieves the specified table type element using 'bulk'
522 * This API retrieves the specified element data by invoking the
526 * Pointer to TF handle
529 * Pointer to table get bulk parameters
532 * - (0) if successful.
533 * - (-EINVAL) on failure.
535 int (*tf_dev_get_bulk_tbl)(struct tf *tfp,
536 struct tf_tbl_get_bulk_parms *parms);
539 * Retrieves the specified SRAM table type element using 'bulk'
542 * This API retrieves the specified element data by invoking the
546 * Pointer to TF handle
549 * Pointer to table get bulk parameters
552 * - (0) if successful.
553 * - (-EINVAL) on failure.
555 int (*tf_dev_get_bulk_sram_tbl)(struct tf *tfp,
556 struct tf_tbl_get_bulk_parms *parms);
559 * Gets the increment value to add to the shared session resource
560 * start offset by for each count in the "stride"
563 * Pointer to TF handle
566 * Pointer to get shared tbl increment parameters
569 * - (0) if successful.
570 * - (-EINVAL) on failure.
572 int (*tf_dev_get_shared_tbl_increment)(struct tf *tfp,
573 struct tf_get_shared_tbl_increment_parms *parms);
576 * Retrieves the table resource info.
578 * This API retrieves the table resource info from the rm db.
581 * Pointer to TF handle
584 * Pointer to tbl info
587 * - (0) if successful.
588 * - (-EINVAL) on failure.
590 int (*tf_dev_get_tbl_resc_info)(struct tf *tfp,
591 struct tf_tbl_resource_info *parms);
594 * Allocation of a tcam element.
596 * This API allocates the specified tcam element from a device
597 * specific tcam DB. The allocated element is returned.
600 * Pointer to TF handle
603 * Pointer to tcam allocation parameters
606 * - (0) if successful.
607 * - (-EINVAL) on failure.
609 int (*tf_dev_alloc_tcam)(struct tf *tfp,
610 struct tf_tcam_alloc_parms *parms);
613 * Free of a tcam element.
615 * This API free's a previous allocated tcam element from a
616 * device specific tcam DB.
619 * Pointer to TF handle
622 * Pointer to tcam free parameters
625 * - (0) if successful.
626 * - (-EINVAL) on failure.
628 int (*tf_dev_free_tcam)(struct tf *tfp,
629 struct tf_tcam_free_parms *parms);
632 * Searches for the specified tcam element in a shadow DB.
634 * This API searches for the specified tcam element in a
635 * device specific shadow DB. If the element is found the
636 * reference count for the element is updated. If the element
637 * is not found a new element is allocated from the tcam DB
638 * and then inserted into the shadow DB.
641 * Pointer to TF handle
644 * Pointer to tcam allocation and search parameters
647 * - (0) if successful.
648 * - (-EINVAL) on failure.
650 int (*tf_dev_alloc_search_tcam)
652 struct tf_tcam_alloc_search_parms *parms);
655 * Sets the specified tcam element.
657 * This API sets the specified element data by invoking the
661 * Pointer to TF handle
664 * Pointer to tcam set parameters
667 * - (0) if successful.
668 * - (-EINVAL) on failure.
670 int (*tf_dev_set_tcam)(struct tf *tfp,
671 struct tf_tcam_set_parms *parms);
674 * Retrieves the specified tcam element.
676 * This API retrieves the specified element data by invoking the
680 * Pointer to TF handle
683 * Pointer to tcam get parameters
686 * - (0) if successful.
687 * - (-EINVAL) on failure.
689 int (*tf_dev_get_tcam)(struct tf *tfp,
690 struct tf_tcam_get_parms *parms);
692 #ifdef TF_TCAM_SHARED
694 * Move TCAM shared entries
697 * Pointer to TF handle
700 * Pointer to parameters
706 int (*tf_dev_move_tcam)(struct tf *tfp,
707 struct tf_move_tcam_shared_entries_parms *parms);
710 * Move TCAM shared entries
713 * Pointer to TF handle
716 * Pointer to parameters
722 int (*tf_dev_clear_tcam)(struct tf *tfp,
723 struct tf_clear_tcam_shared_entries_parms *parms);
725 #endif /* TF_TCAM_SHARED */
728 * Retrieves the tcam resource info.
730 * This API retrieves the tcam resource info from the rm db.
733 * Pointer to TF handle
736 * Pointer to tcam info
739 * - (0) if successful.
740 * - (-EINVAL) on failure.
742 int (*tf_dev_get_tcam_resc_info)(struct tf *tfp,
743 struct tf_tcam_resource_info *parms);
746 * Insert EM hash entry API
749 * Pointer to TF handle
752 * Pointer to E/EM insert parameters
758 int (*tf_dev_insert_int_em_entry)(struct tf *tfp,
759 struct tf_insert_em_entry_parms *parms);
762 * Delete EM hash entry API
765 * Pointer to TF handle
768 * Pointer to E/EM delete parameters
774 int (*tf_dev_delete_int_em_entry)(struct tf *tfp,
775 struct tf_delete_em_entry_parms *parms);
778 * Move EM hash entry API
781 * Pointer to TF handle
784 * Pointer to E/EM move parameters
790 int (*tf_dev_move_int_em_entry)(struct tf *tfp,
791 struct tf_move_em_entry_parms *parms);
794 * Insert EEM hash entry API
797 * Pointer to TF handle
800 * Pointer to E/EM insert parameters
806 int (*tf_dev_insert_ext_em_entry)(struct tf *tfp,
807 struct tf_insert_em_entry_parms *parms);
810 * Delete EEM hash entry API
813 * Pointer to TF handle
816 * Pointer to E/EM delete parameters
822 int (*tf_dev_delete_ext_em_entry)(struct tf *tfp,
823 struct tf_delete_em_entry_parms *parms);
826 * Retrieves the em resource info.
828 * This API retrieves the em resource info from the rm db.
831 * Pointer to TF handle
837 * - (0) if successful.
838 * - (-EINVAL) on failure.
840 int (*tf_dev_get_em_resc_info)(struct tf *tfp,
841 struct tf_em_resource_info *parms);
844 * Move EEM hash entry API
846 * Pointer to E/EM move parameters
849 * Pointer to TF handle
858 int (*tf_dev_move_ext_em_entry)(struct tf *tfp,
859 struct tf_move_em_entry_parms *parms);
862 * Allocate EEM table scope
865 * Pointer to TF handle
868 * Pointer to table scope alloc parameters
874 int (*tf_dev_alloc_tbl_scope)(struct tf *tfp,
875 struct tf_alloc_tbl_scope_parms *parms);
880 * Pointer to TF handle
883 * PF associated with the table scope
886 * Bitmask of PARIFs to enable
888 * [in/out] pointer to the parif_2_pf data to be updated
890 * [in/out] pointer to the parif_2_pf mask to be updated
892 * [in] sz_in_bytes - number of bytes to be written
898 int (*tf_dev_map_parif)(struct tf *tfp,
899 uint16_t parif_bitmask,
903 uint16_t sz_in_bytes);
905 * Map EEM table scope
908 * Pointer to TF handle
911 * Pointer to table scope map parameters
917 int (*tf_dev_map_tbl_scope)(struct tf *tfp,
918 struct tf_map_tbl_scope_parms *parms);
921 * Free EEM table scope
924 * Pointer to TF handle
927 * Pointer to table scope free parameters
933 int (*tf_dev_free_tbl_scope)(struct tf *tfp,
934 struct tf_free_tbl_scope_parms *parms);
937 * Sets the specified interface table type element.
939 * This API sets the specified element data by invoking the
943 * Pointer to TF handle
946 * Pointer to interface table set parameters
949 * - (0) if successful.
950 * - (-EINVAL) on failure.
952 int (*tf_dev_set_if_tbl)(struct tf *tfp,
953 struct tf_if_tbl_set_parms *parms);
956 * Retrieves the specified interface table type element.
958 * This API retrieves the specified element data by invoking the
962 * Pointer to TF handle
965 * Pointer to table get parameters
968 * - (0) if successful.
969 * - (-EINVAL) on failure.
971 int (*tf_dev_get_if_tbl)(struct tf *tfp,
972 struct tf_if_tbl_get_parms *parms);
978 * Pointer to TF handle
981 * Pointer to global cfg parameters
987 int (*tf_dev_set_global_cfg)(struct tf *tfp,
988 struct tf_global_cfg_parms *parms);
994 * Pointer to TF handle
997 * Pointer to global cfg parameters
1003 int (*tf_dev_get_global_cfg)(struct tf *tfp,
1004 struct tf_global_cfg_parms *parms);
1012 int (*tf_dev_get_mailbox)(void);
1015 * Convert length in bit to length in byte and align to word.
1016 * The word length depends on device type.
1024 int (*tf_dev_word_align)(uint16_t size);
1027 * Hash key using crc32 and lookup3
1033 * Number of key bits
1038 uint64_t (*tf_dev_cfa_key_hash)(uint64_t *key_data,
1043 * Supported device operation structures
1045 extern const struct tf_dev_ops tf_dev_ops_p4_init;
1046 extern const struct tf_dev_ops tf_dev_ops_p4;
1047 extern const struct tf_dev_ops tf_dev_ops_p58_init;
1048 extern const struct tf_dev_ops tf_dev_ops_p58;
1050 #endif /* _TF_DEVICE_H_ */