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 * Searches for the specified table type element in a shadow DB.
353 * This API searches for the specified table type element in a
354 * device specific shadow DB. If the element is found the
355 * reference count for the element is updated. If the element
356 * is not found a new element is allocated from the table type
357 * DB and then inserted into the shadow DB.
360 * Pointer to TF handle
363 * Pointer to table allocation and search parameters
366 * - (0) if successful.
367 * - (-EINVAL) on failure.
369 int (*tf_dev_alloc_search_tbl)(struct tf *tfp,
370 struct tf_tbl_alloc_search_parms *parms);
373 * Sets the specified table type element.
375 * This API sets the specified element data by invoking the
379 * Pointer to TF handle
382 * Pointer to table set parameters
385 * - (0) if successful.
386 * - (-EINVAL) on failure.
388 int (*tf_dev_set_tbl)(struct tf *tfp,
389 struct tf_tbl_set_parms *parms);
392 * Sets the specified external table type element.
394 * This API sets the specified element data by invoking the
398 * Pointer to TF handle
401 * Pointer to table set parameters
404 * - (0) if successful.
405 * - (-EINVAL) on failure.
407 int (*tf_dev_set_ext_tbl)(struct tf *tfp,
408 struct tf_tbl_set_parms *parms);
411 * Retrieves the specified table type element.
413 * This API retrieves the specified element data by invoking the
417 * Pointer to TF handle
420 * Pointer to table get parameters
423 * - (0) if successful.
424 * - (-EINVAL) on failure.
426 int (*tf_dev_get_tbl)(struct tf *tfp,
427 struct tf_tbl_get_parms *parms);
430 * Retrieves the specified table type element using 'bulk'
433 * This API retrieves the specified element data by invoking the
437 * Pointer to TF handle
440 * Pointer to table get bulk parameters
443 * - (0) if successful.
444 * - (-EINVAL) on failure.
446 int (*tf_dev_get_bulk_tbl)(struct tf *tfp,
447 struct tf_tbl_get_bulk_parms *parms);
450 * Gets the increment value to add to the shared session resource
451 * start offset by for each count in the "stride"
454 * Pointer to TF handle
457 * Pointer to get shared tbl increment parameters
460 * - (0) if successful.
461 * - (-EINVAL) on failure.
463 int (*tf_dev_get_shared_tbl_increment)(struct tf *tfp,
464 struct tf_get_shared_tbl_increment_parms *parms);
467 * Retrieves the table resource info.
469 * This API retrieves the table resource info from the rm db.
472 * Pointer to TF handle
475 * Pointer to tbl info
478 * - (0) if successful.
479 * - (-EINVAL) on failure.
481 int (*tf_dev_get_tbl_resc_info)(struct tf *tfp,
482 struct tf_tbl_resource_info *parms);
485 * Allocation of a tcam element.
487 * This API allocates the specified tcam element from a device
488 * specific tcam DB. The allocated element is returned.
491 * Pointer to TF handle
494 * Pointer to tcam allocation parameters
497 * - (0) if successful.
498 * - (-EINVAL) on failure.
500 int (*tf_dev_alloc_tcam)(struct tf *tfp,
501 struct tf_tcam_alloc_parms *parms);
504 * Free of a tcam element.
506 * This API free's a previous allocated tcam element from a
507 * device specific tcam DB.
510 * Pointer to TF handle
513 * Pointer to tcam free parameters
516 * - (0) if successful.
517 * - (-EINVAL) on failure.
519 int (*tf_dev_free_tcam)(struct tf *tfp,
520 struct tf_tcam_free_parms *parms);
523 * Searches for the specified tcam element in a shadow DB.
525 * This API searches for the specified tcam element in a
526 * device specific shadow DB. If the element is found the
527 * reference count for the element is updated. If the element
528 * is not found a new element is allocated from the tcam DB
529 * and then inserted into the shadow DB.
532 * Pointer to TF handle
535 * Pointer to tcam allocation and search parameters
538 * - (0) if successful.
539 * - (-EINVAL) on failure.
541 int (*tf_dev_alloc_search_tcam)
543 struct tf_tcam_alloc_search_parms *parms);
546 * Sets the specified tcam element.
548 * This API sets the specified element data by invoking the
552 * Pointer to TF handle
555 * Pointer to tcam set parameters
558 * - (0) if successful.
559 * - (-EINVAL) on failure.
561 int (*tf_dev_set_tcam)(struct tf *tfp,
562 struct tf_tcam_set_parms *parms);
565 * Retrieves the specified tcam element.
567 * This API retrieves the specified element data by invoking the
571 * Pointer to TF handle
574 * Pointer to tcam get parameters
577 * - (0) if successful.
578 * - (-EINVAL) on failure.
580 int (*tf_dev_get_tcam)(struct tf *tfp,
581 struct tf_tcam_get_parms *parms);
583 #ifdef TF_TCAM_SHARED
585 * Move TCAM shared entries
588 * Pointer to TF handle
591 * Pointer to parameters
597 int (*tf_dev_move_tcam)(struct tf *tfp,
598 struct tf_move_tcam_shared_entries_parms *parms);
599 #endif /* TF_TCAM_SHARED */
602 * Retrieves the tcam resource info.
604 * This API retrieves the tcam resource info from the rm db.
607 * Pointer to TF handle
610 * Pointer to tcam info
613 * - (0) if successful.
614 * - (-EINVAL) on failure.
616 int (*tf_dev_get_tcam_resc_info)(struct tf *tfp,
617 struct tf_tcam_resource_info *parms);
620 * Insert EM hash entry API
623 * Pointer to TF handle
626 * Pointer to E/EM insert parameters
632 int (*tf_dev_insert_int_em_entry)(struct tf *tfp,
633 struct tf_insert_em_entry_parms *parms);
636 * Delete EM hash entry API
639 * Pointer to TF handle
642 * Pointer to E/EM delete parameters
648 int (*tf_dev_delete_int_em_entry)(struct tf *tfp,
649 struct tf_delete_em_entry_parms *parms);
652 * Move EM hash entry API
655 * Pointer to TF handle
658 * Pointer to E/EM move parameters
664 int (*tf_dev_move_int_em_entry)(struct tf *tfp,
665 struct tf_move_em_entry_parms *parms);
668 * Insert EEM hash entry API
671 * Pointer to TF handle
674 * Pointer to E/EM insert parameters
680 int (*tf_dev_insert_ext_em_entry)(struct tf *tfp,
681 struct tf_insert_em_entry_parms *parms);
684 * Delete EEM hash entry API
687 * Pointer to TF handle
690 * Pointer to E/EM delete parameters
696 int (*tf_dev_delete_ext_em_entry)(struct tf *tfp,
697 struct tf_delete_em_entry_parms *parms);
700 * Retrieves the em resource info.
702 * This API retrieves the em resource info from the rm db.
705 * Pointer to TF handle
711 * - (0) if successful.
712 * - (-EINVAL) on failure.
714 int (*tf_dev_get_em_resc_info)(struct tf *tfp,
715 struct tf_em_resource_info *parms);
718 * Move EEM hash entry API
720 * Pointer to E/EM move parameters
723 * Pointer to TF handle
732 int (*tf_dev_move_ext_em_entry)(struct tf *tfp,
733 struct tf_move_em_entry_parms *parms);
736 * Allocate EEM table scope
739 * Pointer to TF handle
742 * Pointer to table scope alloc parameters
748 int (*tf_dev_alloc_tbl_scope)(struct tf *tfp,
749 struct tf_alloc_tbl_scope_parms *parms);
754 * Pointer to TF handle
757 * PF associated with the table scope
760 * Bitmask of PARIFs to enable
762 * [in/out] pointer to the parif_2_pf data to be updated
764 * [in/out] pointer to the parif_2_pf mask to be updated
766 * [in] sz_in_bytes - number of bytes to be written
772 int (*tf_dev_map_parif)(struct tf *tfp,
773 uint16_t parif_bitmask,
777 uint16_t sz_in_bytes);
779 * Map EEM table scope
782 * Pointer to TF handle
785 * Pointer to table scope map parameters
791 int (*tf_dev_map_tbl_scope)(struct tf *tfp,
792 struct tf_map_tbl_scope_parms *parms);
795 * Free EEM table scope
798 * Pointer to TF handle
801 * Pointer to table scope free parameters
807 int (*tf_dev_free_tbl_scope)(struct tf *tfp,
808 struct tf_free_tbl_scope_parms *parms);
811 * Sets the specified interface table type element.
813 * This API sets the specified element data by invoking the
817 * Pointer to TF handle
820 * Pointer to interface table set parameters
823 * - (0) if successful.
824 * - (-EINVAL) on failure.
826 int (*tf_dev_set_if_tbl)(struct tf *tfp,
827 struct tf_if_tbl_set_parms *parms);
830 * Retrieves the specified interface table type element.
832 * This API retrieves the specified element data by invoking the
836 * Pointer to TF handle
839 * Pointer to table get parameters
842 * - (0) if successful.
843 * - (-EINVAL) on failure.
845 int (*tf_dev_get_if_tbl)(struct tf *tfp,
846 struct tf_if_tbl_get_parms *parms);
852 * Pointer to TF handle
855 * Pointer to global cfg parameters
861 int (*tf_dev_set_global_cfg)(struct tf *tfp,
862 struct tf_global_cfg_parms *parms);
868 * Pointer to TF handle
871 * Pointer to global cfg parameters
877 int (*tf_dev_get_global_cfg)(struct tf *tfp,
878 struct tf_global_cfg_parms *parms);
886 int (*tf_dev_get_mailbox)(void);
889 * Convert length in bit to length in byte and align to word.
890 * The word length depends on device type.
898 int (*tf_dev_word_align)(uint16_t size);
901 * Hash key using crc32 and lookup3
912 uint64_t (*tf_dev_cfa_key_hash)(uint64_t *key_data,
917 * Supported device operation structures
919 extern const struct tf_dev_ops tf_dev_ops_p4_init;
920 extern const struct tf_dev_ops tf_dev_ops_p4;
921 extern const struct tf_dev_ops tf_dev_ops_p58_init;
922 extern const struct tf_dev_ops tf_dev_ops_p58;
924 #endif /* _TF_DEVICE_H_ */