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 * Retrieves the table resource info.
452 * This API retrieves the table resource info from the rm db.
455 * Pointer to TF handle
458 * Pointer to tbl info
461 * - (0) if successful.
462 * - (-EINVAL) on failure.
464 int (*tf_dev_get_tbl_resc_info)(struct tf *tfp,
465 struct tf_tbl_resource_info *parms);
468 * Allocation of a tcam element.
470 * This API allocates the specified tcam element from a device
471 * specific tcam DB. The allocated element is returned.
474 * Pointer to TF handle
477 * Pointer to tcam allocation parameters
480 * - (0) if successful.
481 * - (-EINVAL) on failure.
483 int (*tf_dev_alloc_tcam)(struct tf *tfp,
484 struct tf_tcam_alloc_parms *parms);
487 * Free of a tcam element.
489 * This API free's a previous allocated tcam element from a
490 * device specific tcam DB.
493 * Pointer to TF handle
496 * Pointer to tcam free parameters
499 * - (0) if successful.
500 * - (-EINVAL) on failure.
502 int (*tf_dev_free_tcam)(struct tf *tfp,
503 struct tf_tcam_free_parms *parms);
506 * Searches for the specified tcam element in a shadow DB.
508 * This API searches for the specified tcam element in a
509 * device specific shadow DB. If the element is found the
510 * reference count for the element is updated. If the element
511 * is not found a new element is allocated from the tcam DB
512 * and then inserted into the shadow DB.
515 * Pointer to TF handle
518 * Pointer to tcam allocation and search parameters
521 * - (0) if successful.
522 * - (-EINVAL) on failure.
524 int (*tf_dev_alloc_search_tcam)
526 struct tf_tcam_alloc_search_parms *parms);
529 * Sets the specified tcam element.
531 * This API sets the specified element data by invoking the
535 * Pointer to TF handle
538 * Pointer to tcam set parameters
541 * - (0) if successful.
542 * - (-EINVAL) on failure.
544 int (*tf_dev_set_tcam)(struct tf *tfp,
545 struct tf_tcam_set_parms *parms);
548 * Retrieves the specified tcam element.
550 * This API retrieves the specified element data by invoking the
554 * Pointer to TF handle
557 * Pointer to tcam get parameters
560 * - (0) if successful.
561 * - (-EINVAL) on failure.
563 int (*tf_dev_get_tcam)(struct tf *tfp,
564 struct tf_tcam_get_parms *parms);
567 * Retrieves the tcam resource info.
569 * This API retrieves the tcam resource info from the rm db.
572 * Pointer to TF handle
575 * Pointer to tcam info
578 * - (0) if successful.
579 * - (-EINVAL) on failure.
581 int (*tf_dev_get_tcam_resc_info)(struct tf *tfp,
582 struct tf_tcam_resource_info *parms);
585 * Insert EM hash entry API
588 * Pointer to TF handle
591 * Pointer to E/EM insert parameters
597 int (*tf_dev_insert_int_em_entry)(struct tf *tfp,
598 struct tf_insert_em_entry_parms *parms);
601 * Delete EM hash entry API
604 * Pointer to TF handle
607 * Pointer to E/EM delete parameters
613 int (*tf_dev_delete_int_em_entry)(struct tf *tfp,
614 struct tf_delete_em_entry_parms *parms);
617 * Move EM hash entry API
620 * Pointer to TF handle
623 * Pointer to E/EM move parameters
629 int (*tf_dev_move_int_em_entry)(struct tf *tfp,
630 struct tf_move_em_entry_parms *parms);
633 * Insert EEM hash entry API
636 * Pointer to TF handle
639 * Pointer to E/EM insert parameters
645 int (*tf_dev_insert_ext_em_entry)(struct tf *tfp,
646 struct tf_insert_em_entry_parms *parms);
649 * Delete EEM hash entry API
652 * Pointer to TF handle
655 * Pointer to E/EM delete parameters
661 int (*tf_dev_delete_ext_em_entry)(struct tf *tfp,
662 struct tf_delete_em_entry_parms *parms);
665 * Retrieves the em resource info.
667 * This API retrieves the em resource info from the rm db.
670 * Pointer to TF handle
676 * - (0) if successful.
677 * - (-EINVAL) on failure.
679 int (*tf_dev_get_em_resc_info)(struct tf *tfp,
680 struct tf_em_resource_info *parms);
683 * Move EEM hash entry API
685 * Pointer to E/EM move parameters
688 * Pointer to TF handle
697 int (*tf_dev_move_ext_em_entry)(struct tf *tfp,
698 struct tf_move_em_entry_parms *parms);
701 * Allocate EEM table scope
704 * Pointer to TF handle
707 * Pointer to table scope alloc parameters
713 int (*tf_dev_alloc_tbl_scope)(struct tf *tfp,
714 struct tf_alloc_tbl_scope_parms *parms);
719 * Pointer to TF handle
722 * PF associated with the table scope
725 * Bitmask of PARIFs to enable
727 * [in/out] pointer to the parif_2_pf data to be updated
729 * [in/out] pointer to the parif_2_pf mask to be updated
731 * [in] sz_in_bytes - number of bytes to be written
737 int (*tf_dev_map_parif)(struct tf *tfp,
738 uint16_t parif_bitmask,
742 uint16_t sz_in_bytes);
744 * Map EEM table scope
747 * Pointer to TF handle
750 * Pointer to table scope map parameters
756 int (*tf_dev_map_tbl_scope)(struct tf *tfp,
757 struct tf_map_tbl_scope_parms *parms);
760 * Free EEM table scope
763 * Pointer to TF handle
766 * Pointer to table scope free parameters
772 int (*tf_dev_free_tbl_scope)(struct tf *tfp,
773 struct tf_free_tbl_scope_parms *parms);
776 * Sets the specified interface table type element.
778 * This API sets the specified element data by invoking the
782 * Pointer to TF handle
785 * Pointer to interface table set parameters
788 * - (0) if successful.
789 * - (-EINVAL) on failure.
791 int (*tf_dev_set_if_tbl)(struct tf *tfp,
792 struct tf_if_tbl_set_parms *parms);
795 * Retrieves the specified interface table type element.
797 * This API retrieves the specified element data by invoking the
801 * Pointer to TF handle
804 * Pointer to table get parameters
807 * - (0) if successful.
808 * - (-EINVAL) on failure.
810 int (*tf_dev_get_if_tbl)(struct tf *tfp,
811 struct tf_if_tbl_get_parms *parms);
817 * Pointer to TF handle
820 * Pointer to global cfg parameters
826 int (*tf_dev_set_global_cfg)(struct tf *tfp,
827 struct tf_global_cfg_parms *parms);
833 * Pointer to TF handle
836 * Pointer to global cfg parameters
842 int (*tf_dev_get_global_cfg)(struct tf *tfp,
843 struct tf_global_cfg_parms *parms);
851 int (*tf_dev_get_mailbox)(void);
854 * Convert length in bit to length in byte and align to word.
855 * The word length depends on device type.
863 int (*tf_dev_word_align)(uint16_t size);
866 * Hash key using crc32 and lookup3
877 uint64_t (*tf_dev_cfa_key_hash)(uint64_t *key_data,
882 * Supported device operation structures
884 extern const struct tf_dev_ops tf_dev_ops_p4_init;
885 extern const struct tf_dev_ops tf_dev_ops_p4;
886 extern const struct tf_dev_ops tf_dev_ops_p58_init;
887 extern const struct tf_dev_ops tf_dev_ops_p58;
889 #endif /* _TF_DEVICE_H_ */