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
64 * - (0) if successful.
65 * - (-EINVAL) parameter failure.
66 * - (-ENODEV) no such device supported.
68 int tf_dev_bind(struct tf *tfp,
69 enum tf_device_type type,
71 struct tf_session_resources *resources,
72 struct tf_dev_info *dev_handle);
75 * Device release handles cleanup of the device specific information.
78 * Pointer to TF handle
84 * - (0) if successful.
85 * - (-EINVAL) parameter failure.
86 * - (-ENODEV) no such device supported.
88 int tf_dev_unbind(struct tf *tfp,
89 struct tf_dev_info *dev_handle);
92 tf_dev_bind_ops(enum tf_device_type type,
93 struct tf_dev_info *dev_handle);
96 * Truflow device specific function hooks structure
98 * The following device hooks can be defined; unless noted otherwise,
99 * they are optional and can be filled with a null pointer. The
100 * purpose of these hooks is to support Truflow device operations for
101 * different device variants.
105 * Retrieves the MAX number of resource types that the device
109 * Pointer to TF handle
112 * Pointer to MAX number of types the device supports
115 * - (0) if successful.
116 * - (-EINVAL) on failure.
118 int (*tf_dev_get_max_types)(struct tf *tfp,
119 uint16_t *max_types);
122 * Retrieves the string description for the CFA resource
126 * Pointer to TF handle
129 * HCAPI cfa resource type id
132 * Pointer to a string
135 * - (0) if successful.
136 * - (-EINVAL) on failure.
138 int (*tf_dev_get_resource_str)(struct tf *tfp,
139 uint16_t resource_id,
140 const char **resource_str);
143 * Retrieves the WC TCAM slice information that the device
147 * Pointer to TF handle
155 * [out] num_slices_per_row
156 * Pointer to number of slices per row the device supports
159 * - (0) if successful.
160 * - (-EINVAL) on failure.
162 int (*tf_dev_get_tcam_slice_info)(struct tf *tfp,
163 enum tf_tcam_tbl_type type,
165 uint16_t *num_slices_per_row);
168 * Allocation of an identifier element.
170 * This API allocates the specified identifier element from a
171 * device specific identifier DB. The allocated element is
175 * Pointer to TF handle
178 * Pointer to identifier allocation parameters
181 * - (0) if successful.
182 * - (-EINVAL) on failure.
184 int (*tf_dev_alloc_ident)(struct tf *tfp,
185 struct tf_ident_alloc_parms *parms);
188 * Free of an identifier element.
190 * This API free's a previous allocated identifier element from a
191 * device specific identifier DB.
194 * Pointer to TF handle
197 * Pointer to identifier free parameters
200 * - (0) if successful.
201 * - (-EINVAL) on failure.
203 int (*tf_dev_free_ident)(struct tf *tfp,
204 struct tf_ident_free_parms *parms);
207 * Search of an identifier element.
209 * This API search the specified identifier element from a
210 * device specific identifier shadow DB. The allocated element
214 * Pointer to TF handle
217 * Pointer to identifier search parameters
220 * - (0) if successful.
221 * - (-EINVAL) on failure.
223 int (*tf_dev_search_ident)(struct tf *tfp,
224 struct tf_ident_search_parms *parms);
227 * Retrieves the identifier resource info.
229 * This API retrieves the identifier resource info from the rm db.
232 * Pointer to TF handle
235 * Pointer to identifier info
238 * - (0) if successful.
239 * - (-EINVAL) on failure.
241 int (*tf_dev_get_ident_resc_info)(struct tf *tfp,
242 struct tf_identifier_resource_info *parms);
245 * Get SRAM table information.
247 * Converts an internal RM allocated element offset to
248 * a user address and vice versa.
251 * Pointer to TF handle
254 * Truflow index table type, e.g. TF_TYPE_FULL_ACT_RECORD
257 * Pointer to the base address of the associated table type.
260 * Pointer to any shift required for the associated table type.
263 * - (0) if successful.
264 * - (-EINVAL) on failure.
266 int (*tf_dev_get_tbl_info)(struct tf *tfp,
268 enum tf_tbl_type type,
273 * Allocation of an index table type element.
275 * This API allocates the specified table type element from a
276 * device specific table type DB. The allocated element is
280 * Pointer to TF handle
283 * Pointer to table allocation parameters
286 * - (0) if successful.
287 * - (-EINVAL) on failure.
289 int (*tf_dev_alloc_tbl)(struct tf *tfp,
290 struct tf_tbl_alloc_parms *parms);
293 * Allocation of a external table type element.
295 * This API allocates the specified table type element from a
296 * device specific table type DB. The allocated element is
300 * Pointer to TF handle
303 * Pointer to table allocation parameters
306 * - (0) if successful.
307 * - (-EINVAL) on failure.
309 int (*tf_dev_alloc_ext_tbl)(struct tf *tfp,
310 struct tf_tbl_alloc_parms *parms);
313 * Free of a table type element.
315 * This API free's a previous allocated table type element from a
316 * device specific table type DB.
319 * Pointer to TF handle
322 * Pointer to table free parameters
325 * - (0) if successful.
326 * - (-EINVAL) on failure.
328 int (*tf_dev_free_tbl)(struct tf *tfp,
329 struct tf_tbl_free_parms *parms);
332 * Free of a external table type element.
334 * This API free's a previous allocated table type element from a
335 * device specific table type DB.
338 * Pointer to TF handle
341 * Pointer to table free parameters
344 * - (0) if successful.
345 * - (-EINVAL) on failure.
347 int (*tf_dev_free_ext_tbl)(struct tf *tfp,
348 struct tf_tbl_free_parms *parms);
351 * Sets the specified table type element.
353 * This API sets the specified element data by invoking the
357 * Pointer to TF handle
360 * Pointer to table set parameters
363 * - (0) if successful.
364 * - (-EINVAL) on failure.
366 int (*tf_dev_set_tbl)(struct tf *tfp,
367 struct tf_tbl_set_parms *parms);
370 * Sets the specified external table type element.
372 * This API sets the specified element data by invoking the
376 * Pointer to TF handle
379 * Pointer to table set parameters
382 * - (0) if successful.
383 * - (-EINVAL) on failure.
385 int (*tf_dev_set_ext_tbl)(struct tf *tfp,
386 struct tf_tbl_set_parms *parms);
389 * Retrieves the specified table type element.
391 * This API retrieves the specified element data by invoking the
395 * Pointer to TF handle
398 * Pointer to table get parameters
401 * - (0) if successful.
402 * - (-EINVAL) on failure.
404 int (*tf_dev_get_tbl)(struct tf *tfp,
405 struct tf_tbl_get_parms *parms);
408 * Retrieves the specified table type element using 'bulk'
411 * This API retrieves the specified element data by invoking the
415 * Pointer to TF handle
418 * Pointer to table get bulk parameters
421 * - (0) if successful.
422 * - (-EINVAL) on failure.
424 int (*tf_dev_get_bulk_tbl)(struct tf *tfp,
425 struct tf_tbl_get_bulk_parms *parms);
428 * Gets the increment value to add to the shared session resource
429 * start offset by for each count in the "stride"
432 * Pointer to TF handle
435 * Pointer to get shared tbl increment parameters
438 * - (0) if successful.
439 * - (-EINVAL) on failure.
441 int (*tf_dev_get_shared_tbl_increment)(struct tf *tfp,
442 struct tf_get_shared_tbl_increment_parms *parms);
445 * Retrieves the table resource info.
447 * This API retrieves the table resource info from the rm db.
450 * Pointer to TF handle
453 * Pointer to tbl info
456 * - (0) if successful.
457 * - (-EINVAL) on failure.
459 int (*tf_dev_get_tbl_resc_info)(struct tf *tfp,
460 struct tf_tbl_resource_info *parms);
463 * Allocation of a tcam element.
465 * This API allocates the specified tcam element from a device
466 * specific tcam DB. The allocated element is returned.
469 * Pointer to TF handle
472 * Pointer to tcam allocation parameters
475 * - (0) if successful.
476 * - (-EINVAL) on failure.
478 int (*tf_dev_alloc_tcam)(struct tf *tfp,
479 struct tf_tcam_alloc_parms *parms);
482 * Free of a tcam element.
484 * This API free's a previous allocated tcam element from a
485 * device specific tcam DB.
488 * Pointer to TF handle
491 * Pointer to tcam free parameters
494 * - (0) if successful.
495 * - (-EINVAL) on failure.
497 int (*tf_dev_free_tcam)(struct tf *tfp,
498 struct tf_tcam_free_parms *parms);
501 * Searches for the specified tcam element in a shadow DB.
503 * This API searches for the specified tcam element in a
504 * device specific shadow DB. If the element is found the
505 * reference count for the element is updated. If the element
506 * is not found a new element is allocated from the tcam DB
507 * and then inserted into the shadow DB.
510 * Pointer to TF handle
513 * Pointer to tcam allocation and search parameters
516 * - (0) if successful.
517 * - (-EINVAL) on failure.
519 int (*tf_dev_alloc_search_tcam)
521 struct tf_tcam_alloc_search_parms *parms);
524 * Sets the specified tcam element.
526 * This API sets the specified element data by invoking the
530 * Pointer to TF handle
533 * Pointer to tcam set parameters
536 * - (0) if successful.
537 * - (-EINVAL) on failure.
539 int (*tf_dev_set_tcam)(struct tf *tfp,
540 struct tf_tcam_set_parms *parms);
543 * Retrieves the specified tcam element.
545 * This API retrieves the specified element data by invoking the
549 * Pointer to TF handle
552 * Pointer to tcam get parameters
555 * - (0) if successful.
556 * - (-EINVAL) on failure.
558 int (*tf_dev_get_tcam)(struct tf *tfp,
559 struct tf_tcam_get_parms *parms);
561 #ifdef TF_TCAM_SHARED
563 * Move TCAM shared entries
566 * Pointer to TF handle
569 * Pointer to parameters
575 int (*tf_dev_move_tcam)(struct tf *tfp,
576 struct tf_move_tcam_shared_entries_parms *parms);
579 * Move TCAM shared entries
582 * Pointer to TF handle
585 * Pointer to parameters
591 int (*tf_dev_clear_tcam)(struct tf *tfp,
592 struct tf_clear_tcam_shared_entries_parms *parms);
594 #endif /* TF_TCAM_SHARED */
597 * Retrieves the tcam resource info.
599 * This API retrieves the tcam resource info from the rm db.
602 * Pointer to TF handle
605 * Pointer to tcam info
608 * - (0) if successful.
609 * - (-EINVAL) on failure.
611 int (*tf_dev_get_tcam_resc_info)(struct tf *tfp,
612 struct tf_tcam_resource_info *parms);
615 * Insert EM hash entry API
618 * Pointer to TF handle
621 * Pointer to E/EM insert parameters
627 int (*tf_dev_insert_int_em_entry)(struct tf *tfp,
628 struct tf_insert_em_entry_parms *parms);
631 * Delete EM hash entry API
634 * Pointer to TF handle
637 * Pointer to E/EM delete parameters
643 int (*tf_dev_delete_int_em_entry)(struct tf *tfp,
644 struct tf_delete_em_entry_parms *parms);
647 * Move EM hash entry API
650 * Pointer to TF handle
653 * Pointer to E/EM move parameters
659 int (*tf_dev_move_int_em_entry)(struct tf *tfp,
660 struct tf_move_em_entry_parms *parms);
663 * Insert EEM hash entry API
666 * Pointer to TF handle
669 * Pointer to E/EM insert parameters
675 int (*tf_dev_insert_ext_em_entry)(struct tf *tfp,
676 struct tf_insert_em_entry_parms *parms);
679 * Delete EEM hash entry API
682 * Pointer to TF handle
685 * Pointer to E/EM delete parameters
691 int (*tf_dev_delete_ext_em_entry)(struct tf *tfp,
692 struct tf_delete_em_entry_parms *parms);
695 * Retrieves the em resource info.
697 * This API retrieves the em resource info from the rm db.
700 * Pointer to TF handle
706 * - (0) if successful.
707 * - (-EINVAL) on failure.
709 int (*tf_dev_get_em_resc_info)(struct tf *tfp,
710 struct tf_em_resource_info *parms);
713 * Move EEM hash entry API
715 * Pointer to E/EM move parameters
718 * Pointer to TF handle
727 int (*tf_dev_move_ext_em_entry)(struct tf *tfp,
728 struct tf_move_em_entry_parms *parms);
731 * Allocate EEM table scope
734 * Pointer to TF handle
737 * Pointer to table scope alloc parameters
743 int (*tf_dev_alloc_tbl_scope)(struct tf *tfp,
744 struct tf_alloc_tbl_scope_parms *parms);
749 * Pointer to TF handle
752 * PF associated with the table scope
755 * Bitmask of PARIFs to enable
757 * [in/out] pointer to the parif_2_pf data to be updated
759 * [in/out] pointer to the parif_2_pf mask to be updated
761 * [in] sz_in_bytes - number of bytes to be written
767 int (*tf_dev_map_parif)(struct tf *tfp,
768 uint16_t parif_bitmask,
772 uint16_t sz_in_bytes);
774 * Map EEM table scope
777 * Pointer to TF handle
780 * Pointer to table scope map parameters
786 int (*tf_dev_map_tbl_scope)(struct tf *tfp,
787 struct tf_map_tbl_scope_parms *parms);
790 * Free EEM table scope
793 * Pointer to TF handle
796 * Pointer to table scope free parameters
802 int (*tf_dev_free_tbl_scope)(struct tf *tfp,
803 struct tf_free_tbl_scope_parms *parms);
806 * Sets the specified interface table type element.
808 * This API sets the specified element data by invoking the
812 * Pointer to TF handle
815 * Pointer to interface table set parameters
818 * - (0) if successful.
819 * - (-EINVAL) on failure.
821 int (*tf_dev_set_if_tbl)(struct tf *tfp,
822 struct tf_if_tbl_set_parms *parms);
825 * Retrieves the specified interface table type element.
827 * This API retrieves the specified element data by invoking the
831 * Pointer to TF handle
834 * Pointer to table get parameters
837 * - (0) if successful.
838 * - (-EINVAL) on failure.
840 int (*tf_dev_get_if_tbl)(struct tf *tfp,
841 struct tf_if_tbl_get_parms *parms);
847 * Pointer to TF handle
850 * Pointer to global cfg parameters
856 int (*tf_dev_set_global_cfg)(struct tf *tfp,
857 struct tf_global_cfg_parms *parms);
863 * Pointer to TF handle
866 * Pointer to global cfg parameters
872 int (*tf_dev_get_global_cfg)(struct tf *tfp,
873 struct tf_global_cfg_parms *parms);
881 int (*tf_dev_get_mailbox)(void);
884 * Convert length in bit to length in byte and align to word.
885 * The word length depends on device type.
893 int (*tf_dev_word_align)(uint16_t size);
896 * Hash key using crc32 and lookup3
907 uint64_t (*tf_dev_cfa_key_hash)(uint64_t *key_data,
912 * Supported device operation structures
914 extern const struct tf_dev_ops tf_dev_ops_p4_init;
915 extern const struct tf_dev_ops tf_dev_ops_p4;
916 extern const struct tf_dev_ops tf_dev_ops_p58_init;
917 extern const struct tf_dev_ops tf_dev_ops_p58;
919 #endif /* _TF_DEVICE_H_ */