1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
9 #include "cfa_resource_types.h"
11 #include "tf_identifier.h"
15 #include "tf_tcam_shared.h"
17 #include "tf_if_tbl.h"
18 #include "tf_global_cfg.h"
24 * The Device module provides a general device template. A supported
25 * device type should implement one or more of the listed function
26 * pointers according to its capabilities.
28 * If a device function pointer is NULL the device capability is not
33 * TF device information
36 enum tf_device_type type;
37 const struct tf_dev_ops *ops;
41 * This structure can be used to translate the CFA resource type to TF type.
43 struct tf_hcapi_resource_map {
45 * Truflow module type associated with this resource type.
47 enum tf_module_type module_type;
50 * Bitmap of TF sub-type for the element.
64 * Device bind handles the initialization of the specified device
68 * Pointer to TF handle
74 * Pointer to resource allocation information
77 * Number of slices per row for WC
83 * - (0) if successful.
84 * - (-EINVAL) parameter failure.
85 * - (-ENODEV) no such device supported.
87 int tf_dev_bind(struct tf *tfp,
88 enum tf_device_type type,
90 struct tf_session_resources *resources,
91 uint16_t wc_num_slices,
92 struct tf_dev_info *dev_handle);
95 * Device release handles cleanup of the device specific information.
98 * Pointer to TF handle
104 * - (0) if successful.
105 * - (-EINVAL) parameter failure.
106 * - (-ENODEV) no such device supported.
108 int tf_dev_unbind(struct tf *tfp,
109 struct tf_dev_info *dev_handle);
112 tf_dev_bind_ops(enum tf_device_type type,
113 struct tf_dev_info *dev_handle);
116 * Truflow device specific function hooks structure
118 * The following device hooks can be defined; unless noted otherwise,
119 * they are optional and can be filled with a null pointer. The
120 * purpose of these hooks is to support Truflow device operations for
121 * different device variants.
125 * Retrieves the MAX number of resource types that the device
129 * Pointer to TF handle
132 * Pointer to MAX number of types the device supports
135 * - (0) if successful.
136 * - (-EINVAL) on failure.
138 int (*tf_dev_get_max_types)(struct tf *tfp,
139 uint16_t *max_types);
142 * Retrieves the string description for the CFA resource
146 * Pointer to TF handle
149 * HCAPI cfa resource type id
152 * Pointer to a string
155 * - (0) if successful.
156 * - (-EINVAL) on failure.
158 int (*tf_dev_get_resource_str)(struct tf *tfp,
159 uint16_t resource_id,
160 const char **resource_str);
163 * Set the WC TCAM slice information that the device
167 * Pointer to TF handle
169 * [in] num_slices_per_row
170 * Number of slices per row the device supports
173 * - (0) if successful.
174 * - (-EINVAL) on failure.
176 int (*tf_dev_set_tcam_slice_info)(struct tf *tfp,
177 enum tf_wc_num_slice num_slices_per_row);
180 * Retrieves the WC TCAM slice information that the device
184 * Pointer to TF handle
192 * [out] num_slices_per_row
193 * Pointer to number of slices per row the device supports
196 * - (0) if successful.
197 * - (-EINVAL) on failure.
199 int (*tf_dev_get_tcam_slice_info)(struct tf *tfp,
200 enum tf_tcam_tbl_type type,
202 uint16_t *num_slices_per_row);
205 * Allocation of an identifier element.
207 * This API allocates the specified identifier element from a
208 * device specific identifier DB. The allocated element is
212 * Pointer to TF handle
215 * Pointer to identifier allocation parameters
218 * - (0) if successful.
219 * - (-EINVAL) on failure.
221 int (*tf_dev_alloc_ident)(struct tf *tfp,
222 struct tf_ident_alloc_parms *parms);
225 * Free of an identifier element.
227 * This API free's a previous allocated identifier element from a
228 * device specific identifier DB.
231 * Pointer to TF handle
234 * Pointer to identifier free parameters
237 * - (0) if successful.
238 * - (-EINVAL) on failure.
240 int (*tf_dev_free_ident)(struct tf *tfp,
241 struct tf_ident_free_parms *parms);
244 * Search of an identifier element.
246 * This API search the specified identifier element from a
247 * device specific identifier shadow DB. The allocated element
251 * Pointer to TF handle
254 * Pointer to identifier search parameters
257 * - (0) if successful.
258 * - (-EINVAL) on failure.
260 int (*tf_dev_search_ident)(struct tf *tfp,
261 struct tf_ident_search_parms *parms);
264 * Retrieves the identifier resource info.
266 * This API retrieves the identifier resource info from the rm db.
269 * Pointer to TF handle
272 * Pointer to identifier info
275 * - (0) if successful.
276 * - (-EINVAL) on failure.
278 int (*tf_dev_get_ident_resc_info)(struct tf *tfp,
279 struct tf_identifier_resource_info *parms);
282 * Indicates whether the index table type is SRAM managed
285 * Pointer to TF handle
288 * Truflow index table type, e.g. TF_TYPE_FULL_ACT_RECORD
291 * - (0) if the table is not managed by the SRAM manager
292 * - (1) if the table is managed by the SRAM manager
294 bool (*tf_dev_is_sram_managed)(struct tf *tfp,
295 enum tf_tbl_type tbl_type);
298 * Get SRAM table information.
300 * Converts an internal RM allocated element offset to
301 * a user address and vice versa.
304 * Pointer to TF handle
307 * Truflow index table type, e.g. TF_TYPE_FULL_ACT_RECORD
310 * Pointer to the base address of the associated table type.
313 * Pointer to any shift required for the associated table type.
316 * - (0) if successful.
317 * - (-EINVAL) on failure.
319 int (*tf_dev_get_tbl_info)(struct tf *tfp,
321 enum tf_tbl_type type,
326 * Allocation of an index table type element.
328 * This API allocates the specified table type element from a
329 * device specific table type DB. The allocated element is
333 * Pointer to TF handle
336 * Pointer to table allocation parameters
339 * - (0) if successful.
340 * - (-EINVAL) on failure.
342 int (*tf_dev_alloc_tbl)(struct tf *tfp,
343 struct tf_tbl_alloc_parms *parms);
346 * Allocation of an SRAM index table type element.
348 * This API allocates the specified table type element from a
349 * device specific table type DB. The allocated element is
353 * Pointer to TF handle
356 * Pointer to table allocation parameters
359 * - (0) if successful.
360 * - (-EINVAL) on failure.
362 int (*tf_dev_alloc_sram_tbl)(struct tf *tfp,
363 struct tf_tbl_alloc_parms *parms);
365 * Allocation of a external table type element.
367 * This API allocates the specified table type element from a
368 * device specific table type DB. The allocated element is
372 * Pointer to TF handle
375 * Pointer to table allocation parameters
378 * - (0) if successful.
379 * - (-EINVAL) on failure.
381 int (*tf_dev_alloc_ext_tbl)(struct tf *tfp,
382 struct tf_tbl_alloc_parms *parms);
385 * Free of a table type element.
387 * This API free's a previous allocated table type element from a
388 * device specific table type DB.
391 * Pointer to TF handle
394 * Pointer to table free parameters
397 * - (0) if successful.
398 * - (-EINVAL) on failure.
400 int (*tf_dev_free_tbl)(struct tf *tfp,
401 struct tf_tbl_free_parms *parms);
403 * Free of an SRAM table type element.
405 * This API free's a previous allocated table type element from a
406 * device specific table type DB.
409 * Pointer to TF handle
412 * Pointer to table free parameters
415 * - (0) if successful.
416 * - (-EINVAL) on failure.
418 int (*tf_dev_free_sram_tbl)(struct tf *tfp,
419 struct tf_tbl_free_parms *parms);
421 * Free of a external table type element.
423 * This API free's a previous allocated table type element from a
424 * device specific table type DB.
427 * Pointer to TF handle
430 * Pointer to table free parameters
433 * - (0) if successful.
434 * - (-EINVAL) on failure.
436 int (*tf_dev_free_ext_tbl)(struct tf *tfp,
437 struct tf_tbl_free_parms *parms);
440 * Sets the specified table type element.
442 * This API sets the specified element data by invoking the
446 * Pointer to TF handle
449 * Pointer to table set parameters
452 * - (0) if successful.
453 * - (-EINVAL) on failure.
455 int (*tf_dev_set_tbl)(struct tf *tfp,
456 struct tf_tbl_set_parms *parms);
459 * Sets the specified external table type element.
461 * This API sets the specified element data by invoking the
465 * Pointer to TF handle
468 * Pointer to table set parameters
471 * - (0) if successful.
472 * - (-EINVAL) on failure.
474 int (*tf_dev_set_ext_tbl)(struct tf *tfp,
475 struct tf_tbl_set_parms *parms);
478 * Sets the specified SRAM table type element.
480 * This API sets the specified element data by invoking the
484 * Pointer to TF handle
487 * Pointer to table set parameters
490 * - (0) if successful.
491 * - (-EINVAL) on failure.
493 int (*tf_dev_set_sram_tbl)(struct tf *tfp,
494 struct tf_tbl_set_parms *parms);
497 * Retrieves the specified table type element.
499 * This API retrieves the specified element data by invoking the
503 * Pointer to TF handle
506 * Pointer to table get parameters
509 * - (0) if successful.
510 * - (-EINVAL) on failure.
512 int (*tf_dev_get_tbl)(struct tf *tfp,
513 struct tf_tbl_get_parms *parms);
516 * Retrieves the specified SRAM table type element.
518 * This API retrieves the specified element data by invoking the
522 * Pointer to TF handle
525 * Pointer to table get parameters
528 * - (0) if successful.
529 * - (-EINVAL) on failure.
531 int (*tf_dev_get_sram_tbl)(struct tf *tfp,
532 struct tf_tbl_get_parms *parms);
535 * Retrieves the specified table type element using 'bulk'
538 * This API retrieves the specified element data by invoking the
542 * Pointer to TF handle
545 * Pointer to table get bulk parameters
548 * - (0) if successful.
549 * - (-EINVAL) on failure.
551 int (*tf_dev_get_bulk_tbl)(struct tf *tfp,
552 struct tf_tbl_get_bulk_parms *parms);
555 * Retrieves the specified SRAM table type element using 'bulk'
558 * This API retrieves the specified element data by invoking the
562 * Pointer to TF handle
565 * Pointer to table get bulk parameters
568 * - (0) if successful.
569 * - (-EINVAL) on failure.
571 int (*tf_dev_get_bulk_sram_tbl)(struct tf *tfp,
572 struct tf_tbl_get_bulk_parms *parms);
575 * Gets the increment value to add to the shared session resource
576 * start offset by for each count in the "stride"
579 * Pointer to TF handle
582 * Pointer to get shared tbl increment parameters
585 * - (0) if successful.
586 * - (-EINVAL) on failure.
588 int (*tf_dev_get_shared_tbl_increment)(struct tf *tfp,
589 struct tf_get_shared_tbl_increment_parms *parms);
592 * Retrieves the table resource info.
594 * This API retrieves the table resource info from the rm db.
597 * Pointer to TF handle
600 * Pointer to tbl info
603 * - (0) if successful.
604 * - (-EINVAL) on failure.
606 int (*tf_dev_get_tbl_resc_info)(struct tf *tfp,
607 struct tf_tbl_resource_info *parms);
610 * Allocation of a tcam element.
612 * This API allocates the specified tcam element from a device
613 * specific tcam DB. The allocated element is returned.
616 * Pointer to TF handle
619 * Pointer to tcam allocation parameters
622 * - (0) if successful.
623 * - (-EINVAL) on failure.
625 int (*tf_dev_alloc_tcam)(struct tf *tfp,
626 struct tf_tcam_alloc_parms *parms);
629 * Free of a tcam element.
631 * This API free's a previous allocated tcam element from a
632 * device specific tcam DB.
635 * Pointer to TF handle
638 * Pointer to tcam free parameters
641 * - (0) if successful.
642 * - (-EINVAL) on failure.
644 int (*tf_dev_free_tcam)(struct tf *tfp,
645 struct tf_tcam_free_parms *parms);
648 * Searches for the specified tcam element in a shadow DB.
650 * This API searches for the specified tcam element in a
651 * device specific shadow DB. If the element is found the
652 * reference count for the element is updated. If the element
653 * is not found a new element is allocated from the tcam DB
654 * and then inserted into the shadow DB.
657 * Pointer to TF handle
660 * Pointer to tcam allocation and search parameters
663 * - (0) if successful.
664 * - (-EINVAL) on failure.
666 int (*tf_dev_alloc_search_tcam)
668 struct tf_tcam_alloc_search_parms *parms);
671 * Sets the specified tcam element.
673 * This API sets the specified element data by invoking the
677 * Pointer to TF handle
680 * Pointer to tcam set parameters
683 * - (0) if successful.
684 * - (-EINVAL) on failure.
686 int (*tf_dev_set_tcam)(struct tf *tfp,
687 struct tf_tcam_set_parms *parms);
690 * Retrieves the specified tcam element.
692 * This API retrieves the specified element data by invoking the
696 * Pointer to TF handle
699 * Pointer to tcam get parameters
702 * - (0) if successful.
703 * - (-EINVAL) on failure.
705 int (*tf_dev_get_tcam)(struct tf *tfp,
706 struct tf_tcam_get_parms *parms);
708 #ifdef TF_TCAM_SHARED
710 * Move TCAM shared entries
713 * Pointer to TF handle
716 * Pointer to parameters
722 int (*tf_dev_move_tcam)(struct tf *tfp,
723 struct tf_move_tcam_shared_entries_parms *parms);
726 * Move TCAM shared entries
729 * Pointer to TF handle
732 * Pointer to parameters
738 int (*tf_dev_clear_tcam)(struct tf *tfp,
739 struct tf_clear_tcam_shared_entries_parms *parms);
741 #endif /* TF_TCAM_SHARED */
744 * Retrieves the tcam resource info.
746 * This API retrieves the tcam resource info from the rm db.
749 * Pointer to TF handle
752 * Pointer to tcam info
755 * - (0) if successful.
756 * - (-EINVAL) on failure.
758 int (*tf_dev_get_tcam_resc_info)(struct tf *tfp,
759 struct tf_tcam_resource_info *parms);
762 * Insert EM hash entry API
765 * Pointer to TF handle
768 * Pointer to E/EM insert parameters
774 int (*tf_dev_insert_int_em_entry)(struct tf *tfp,
775 struct tf_insert_em_entry_parms *parms);
778 * Delete EM hash entry API
781 * Pointer to TF handle
784 * Pointer to E/EM delete parameters
790 int (*tf_dev_delete_int_em_entry)(struct tf *tfp,
791 struct tf_delete_em_entry_parms *parms);
794 * Move EM hash entry API
797 * Pointer to TF handle
800 * Pointer to E/EM move parameters
806 int (*tf_dev_move_int_em_entry)(struct tf *tfp,
807 struct tf_move_em_entry_parms *parms);
810 * Insert EEM hash entry API
813 * Pointer to TF handle
816 * Pointer to E/EM insert parameters
822 int (*tf_dev_insert_ext_em_entry)(struct tf *tfp,
823 struct tf_insert_em_entry_parms *parms);
826 * Delete EEM hash entry API
829 * Pointer to TF handle
832 * Pointer to E/EM delete parameters
838 int (*tf_dev_delete_ext_em_entry)(struct tf *tfp,
839 struct tf_delete_em_entry_parms *parms);
842 * Retrieves the em resource info.
844 * This API retrieves the em resource info from the rm db.
847 * Pointer to TF handle
853 * - (0) if successful.
854 * - (-EINVAL) on failure.
856 int (*tf_dev_get_em_resc_info)(struct tf *tfp,
857 struct tf_em_resource_info *parms);
860 * Move EEM hash entry API
862 * Pointer to E/EM move parameters
865 * Pointer to TF handle
874 int (*tf_dev_move_ext_em_entry)(struct tf *tfp,
875 struct tf_move_em_entry_parms *parms);
878 * Allocate EEM table scope
881 * Pointer to TF handle
884 * Pointer to table scope alloc parameters
890 int (*tf_dev_alloc_tbl_scope)(struct tf *tfp,
891 struct tf_alloc_tbl_scope_parms *parms);
896 * Pointer to TF handle
899 * PF associated with the table scope
902 * Bitmask of PARIFs to enable
904 * [in/out] pointer to the parif_2_pf data to be updated
906 * [in/out] pointer to the parif_2_pf mask to be updated
908 * [in] sz_in_bytes - number of bytes to be written
914 int (*tf_dev_map_parif)(struct tf *tfp,
915 uint16_t parif_bitmask,
919 uint16_t sz_in_bytes);
921 * Map EEM table scope
924 * Pointer to TF handle
927 * Pointer to table scope map parameters
933 int (*tf_dev_map_tbl_scope)(struct tf *tfp,
934 struct tf_map_tbl_scope_parms *parms);
937 * Free EEM table scope
940 * Pointer to TF handle
943 * Pointer to table scope free parameters
949 int (*tf_dev_free_tbl_scope)(struct tf *tfp,
950 struct tf_free_tbl_scope_parms *parms);
953 * Sets the specified interface table type element.
955 * This API sets the specified element data by invoking the
959 * Pointer to TF handle
962 * Pointer to interface table set parameters
965 * - (0) if successful.
966 * - (-EINVAL) on failure.
968 int (*tf_dev_set_if_tbl)(struct tf *tfp,
969 struct tf_if_tbl_set_parms *parms);
972 * Retrieves the specified interface table type element.
974 * This API retrieves the specified element data by invoking the
978 * Pointer to TF handle
981 * Pointer to table get parameters
984 * - (0) if successful.
985 * - (-EINVAL) on failure.
987 int (*tf_dev_get_if_tbl)(struct tf *tfp,
988 struct tf_if_tbl_get_parms *parms);
994 * Pointer to TF handle
997 * Pointer to global cfg parameters
1003 int (*tf_dev_set_global_cfg)(struct tf *tfp,
1004 struct tf_global_cfg_parms *parms);
1010 * Pointer to TF handle
1013 * Pointer to global cfg parameters
1019 int (*tf_dev_get_global_cfg)(struct tf *tfp,
1020 struct tf_global_cfg_parms *parms);
1028 int (*tf_dev_get_mailbox)(void);
1031 * Convert length in bit to length in byte and align to word.
1032 * The word length depends on device type.
1040 int (*tf_dev_word_align)(uint16_t size);
1043 * Hash key using crc32 and lookup3
1049 * Number of key bits
1054 uint64_t (*tf_dev_cfa_key_hash)(uint64_t *key_data,
1058 * Translate the CFA resource type to Truflow type
1061 * CFA resource type bitmap
1064 * Pointer to identifier type bitmap
1067 * Pointer to tcam type bitmap
1070 * Pointer to table type bitmap
1073 * Pointer to em type bitmap
1076 * - (0) if successful.
1077 * - (-EINVAL) on failure.
1079 int (*tf_dev_map_hcapi_caps)(uint64_t hcapi_caps,
1080 uint32_t *ident_caps,
1081 uint32_t *tcam_caps,
1086 * Device specific function that retrieves the sram resource
1089 * Point to resources query result
1091 * [out] sram_bank_caps
1092 * Pointer to SRAM bank capabilities
1094 * [out] dynamic_sram_capable
1095 * Pointer to dynamic sram capable
1098 * - (0) if successful.
1099 * - (-EINVAL) on failure.
1101 int (*tf_dev_get_sram_resources)(void *query,
1102 uint32_t *sram_bank_caps,
1103 bool *dynamic_sram_capable);
1106 * Device specific function that sets the sram policy
1109 * Receive or transmit direction
1115 * - (0) if successful.
1116 * - (-EINVAL) on failure.
1118 int (*tf_dev_set_sram_policy)(enum tf_dir dir,
1119 enum tf_sram_bank_id *bank_id);
1122 * Device specific function that gets the sram policy
1125 * Receive or transmit direction
1128 * pointer to SRAM bank id
1131 * - (0) if successful.
1132 * - (-EINVAL) on failure.
1134 int (*tf_dev_get_sram_policy)(enum tf_dir dir,
1135 enum tf_sram_bank_id *bank_id);
1139 * Supported device operation structures
1141 extern const struct tf_dev_ops tf_dev_ops_p4_init;
1142 extern const struct tf_dev_ops tf_dev_ops_p4;
1143 extern const struct tf_dev_ops tf_dev_ops_p58_init;
1144 extern const struct tf_dev_ops tf_dev_ops_p58;
1147 * Supported device resource type mapping structures
1149 extern const struct tf_hcapi_resource_map tf_hcapi_res_map_p4[CFA_RESOURCE_TYPE_P4_LAST + 1];
1150 extern const struct tf_hcapi_resource_map tf_hcapi_res_map_p58[CFA_RESOURCE_TYPE_P58_LAST + 1];
1152 #endif /* _TF_DEVICE_H_ */