1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
13 #include "hcapi/hcapi_cfa.h"
14 #include "tf_project.h"
19 * Truflow Core API Header File
22 /********** BEGIN Truflow Core DEFINITIONS **********/
25 #define TF_KILOBYTE 1024
26 #define TF_MEGABYTE (1024 * 1024)
32 TF_DIR_RX, /**< Receive */
33 TF_DIR_TX, /**< Transmit */
41 TF_MEM_INTERNAL, /**< Internal */
42 TF_MEM_EXTERNAL, /**< External */
47 * EEM record AR helper
49 * Helper to handle the Action Record Pointer in the EEM Record Entry.
51 * Convert absolute offset to action record pointer in EEM record entry
52 * Convert action record pointer in EEM record entry to absolute offset
54 #define TF_ACT_REC_OFFSET_2_PTR(offset) ((offset) >> 4)
55 #define TF_ACT_REC_PTR_2_OFFSET(offset) ((offset) << 4)
61 #define TF_BITS_2_BYTES(num_bits) (((num_bits) + 7) / 8)
63 /********** BEGIN API FUNCTION PROTOTYPES/PARAMETERS **********/
66 * @page general General
68 * @ref tf_open_session
70 * @ref tf_attach_session
72 * @ref tf_close_session
76 * Session Version defines
78 * The version controls the format of the tf_session and
79 * tf_session_info structure. This is to assure upgrade between
80 * versions can be supported.
82 #define TF_SESSION_VER_MAJOR 1 /**< Major Version */
83 #define TF_SESSION_VER_MINOR 0 /**< Minor Version */
84 #define TF_SESSION_VER_UPDATE 0 /**< Update Version */
89 * Name of the TruFlow control channel interface. Expects
90 * format to be RTE Name specific, i.e. rte_eth_dev_get_name_by_port()
92 #define TF_SESSION_NAME_MAX 64
94 #define TF_FW_SESSION_ID_INVALID 0xFF /**< Invalid FW Session ID define */
99 * Unique session identifier which includes PCIe bus info to
100 * distinguish the PF and session info to identify the associated
101 * TruFlow session. Session ID is constructed from the passed in
102 * ctrl_chan_name in tf_open_session() together with an allocated
103 * fw_session_id. Done by TruFlow on tf_open_session().
105 union tf_session_id {
111 uint8_t fw_session_id;
116 * Session Client Identifier
118 * Unique identifier for a client within a session. Session Client ID
119 * is constructed from the passed in session and a firmware allocated
120 * fw_session_client_id. Done by TruFlow on tf_open_session().
122 union tf_session_client_id {
125 uint8_t fw_session_id;
126 uint8_t fw_session_client_id;
133 * The version controls the format of the tf_session and
134 * tf_session_info structure. This is to assure upgrade between
135 * versions can be supported.
137 * Please see the TF_VER_MAJOR/MINOR and UPDATE defines.
139 struct tf_session_version {
146 * Session supported device types
148 enum tf_device_type {
149 TF_DEVICE_TYPE_WH = 0, /**< Whitney+ */
150 TF_DEVICE_TYPE_SR, /**< Stingray */
151 TF_DEVICE_TYPE_THOR, /**< Thor */
152 TF_DEVICE_TYPE_SR2, /**< Stingray2 */
153 TF_DEVICE_TYPE_MAX /**< Maximum */
157 * Identifier resource types
159 enum tf_identifier_type {
161 * The L2 Context is returned from the L2 Ctxt TCAM lookup
162 * and can be used in WC TCAM or EM keys to virtualize further
165 TF_IDENT_TYPE_L2_CTXT_HIGH,
167 * The L2 Context is returned from the L2 Ctxt TCAM lookup
168 * and can be used in WC TCAM or EM keys to virtualize further
171 TF_IDENT_TYPE_L2_CTXT_LOW,
173 * The WC profile func is returned from the L2 Ctxt TCAM lookup
174 * to enable virtualization of the profile TCAM.
176 TF_IDENT_TYPE_PROF_FUNC,
178 * The WC profile ID is included in the WC lookup key
179 * to enable virtualization of the WC TCAM hardware.
181 TF_IDENT_TYPE_WC_PROF,
183 * The EM profile ID is included in the EM lookup key
184 * to enable virtualization of the EM hardware. (not required for SR2
185 * as it has table scope)
187 TF_IDENT_TYPE_EM_PROF,
189 * The L2 func is included in the ILT result and from recycling to
190 * enable virtualization of further lookups.
192 TF_IDENT_TYPE_L2_FUNC,
197 * Enumeration of TruFlow table types. A table type is used to identify a
200 * NOTE: The table type TF_TBL_TYPE_EXT is unique in that it is
201 * the only table type that is connected with a table scope.
206 /** Wh+/SR Action Record */
207 TF_TBL_TYPE_FULL_ACT_RECORD,
208 /** Wh+/SR/Th Multicast Groups */
209 TF_TBL_TYPE_MCAST_GROUPS,
210 /** Wh+/SR Action Encap 8 Bytes */
211 TF_TBL_TYPE_ACT_ENCAP_8B,
212 /** Wh+/SR Action Encap 16 Bytes */
213 TF_TBL_TYPE_ACT_ENCAP_16B,
214 /** Action Encap 32 Bytes */
215 TF_TBL_TYPE_ACT_ENCAP_32B,
216 /** Wh+/SR Action Encap 64 Bytes */
217 TF_TBL_TYPE_ACT_ENCAP_64B,
218 /** Action Source Properties SMAC */
219 TF_TBL_TYPE_ACT_SP_SMAC,
220 /** Wh+/SR Action Source Properties SMAC IPv4 */
221 TF_TBL_TYPE_ACT_SP_SMAC_IPV4,
222 /** Action Source Properties SMAC IPv6 */
223 TF_TBL_TYPE_ACT_SP_SMAC_IPV6,
224 /** Wh+/SR Action Statistics 64 Bits */
225 TF_TBL_TYPE_ACT_STATS_64,
226 /** Wh+/SR Action Modify L4 Src Port */
227 TF_TBL_TYPE_ACT_MODIFY_SPORT,
228 /** Wh+/SR Action Modify L4 Dest Port */
229 TF_TBL_TYPE_ACT_MODIFY_DPORT,
230 /** Wh+/SR Action Modify IPv4 Source */
231 TF_TBL_TYPE_ACT_MODIFY_IPV4,
232 /** Meter Profiles */
233 TF_TBL_TYPE_METER_PROF,
234 /** Meter Instance */
235 TF_TBL_TYPE_METER_INST,
237 TF_TBL_TYPE_MIRROR_CONFIG,
240 /** SR2 Epoch 0 table */
242 /** SR2 Epoch 1 table */
245 TF_TBL_TYPE_METADATA,
247 TF_TBL_TYPE_CT_STATE,
248 /** SR2 Range Profile */
249 TF_TBL_TYPE_RANGE_PROF,
250 /** SR2 Range Entry */
251 TF_TBL_TYPE_RANGE_ENTRY,
254 /** SR2 VNIC/SVIF Table */
255 TF_TBL_TYPE_VNIC_SVIF,
256 /** Th/SR2 EM Flexible Key builder */
258 /** Th/SR2 WC Flexible Key builder */
264 * External table type - initially 1 poolsize entries.
265 * All External table types are associated with a table
266 * scope. Internal types are not.
275 enum tf_tcam_tbl_type {
276 /** L2 Context TCAM */
277 TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_HIGH,
278 /** L2 Context TCAM */
279 TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_LOW,
281 TF_TCAM_TBL_TYPE_PROF_TCAM,
283 TF_TCAM_TBL_TYPE_WC_TCAM,
284 /** Source Properties TCAM */
285 TF_TCAM_TBL_TYPE_SP_TCAM,
286 /** Connection Tracking Rule TCAM */
287 TF_TCAM_TBL_TYPE_CT_RULE_TCAM,
288 /** Virtual Edge Bridge TCAM */
289 TF_TCAM_TBL_TYPE_VEB_TCAM,
295 * These defines are provisioned during
298 enum tf_em_tbl_type {
299 /** The number of internal EM records for the session */
300 TF_EM_TBL_TYPE_EM_RECORD,
301 /** The number of table scopes reequested */
302 TF_EM_TBL_TYPE_TBL_SCOPE,
307 * TruFlow Session Information
309 * Structure defining a TruFlow Session, also known as a Management
310 * session. This structure is initialized at time of
311 * tf_open_session(). It is passed to all of the TruFlow APIs as way
312 * to prescribe and isolate resources between different TruFlow ULP
315 * Ownership of the elements is split between ULP and TruFlow. Please
316 * see the individual elements.
318 struct tf_session_info {
320 * TrueFlow Version. Used to control the structure layout when
321 * sharing sessions. No guarantee that a secondary process
322 * would come from the same version of an executable.
323 * TruFlow initializes this variable on tf_open_session().
328 struct tf_session_version ver;
330 * will be STAILQ_ENTRY(tf_session_info) next
337 * Session ID is a unique identifier for the session. TruFlow
338 * initializes this variable during tf_open_session()
342 * Access: Truflow & ULP
344 union tf_session_id session_id;
346 * Protects access to core_data. Lock is initialized and owned
347 * by ULP. TruFlow can access the core_data without checking
355 * The core_data holds the TruFlow tf_session data
356 * structure. This memory is allocated and owned by TruFlow on
359 * TruFlow uses this memory for session management control
360 * until the session is closed by ULP. Access control is done
361 * by the spin_lock which ULP controls ahead of TruFlow API
364 * Please see tf_open_session_parms for specification details
372 * The core_data_sz_bytes specifies the size of core_data in
375 * The size is set by TruFlow on tf_open_session().
377 * Please see tf_open_session_parms for specification details
383 uint32_t core_data_sz_bytes;
389 * Contains a pointer to the session info. Allocated by ULP and passed
390 * to TruFlow using tf_open_session(). TruFlow will populate the
391 * session info at that time. A TruFlow Session can be used by more
392 * than one PF/VF by using the tf_open_session().
394 * It is expected that ULP allocates this memory as shared memory.
396 * NOTE: This struct must be within the BNXT PMD struct bnxt
397 * (bp). This allows use of container_of() to get access to the PMD.
400 struct tf_session_info *session;
404 * Identifier resource definition
406 struct tf_identifier_resources {
408 * Array of TF Identifiers where each entry is expected to be
409 * set to the requested resource number of that specific type.
410 * The index used is tf_identifier_type.
412 uint16_t cnt[TF_IDENT_TYPE_MAX];
416 * Table type resource definition
418 struct tf_tbl_resources {
420 * Array of TF Table types where each entry is expected to be
421 * set to the requeste resource number of that specific
422 * type. The index used is tf_tbl_type.
424 uint16_t cnt[TF_TBL_TYPE_MAX];
428 * TCAM type resource definition
430 struct tf_tcam_resources {
432 * Array of TF TCAM types where each entry is expected to be
433 * set to the requested resource number of that specific
434 * type. The index used is tf_tcam_tbl_type.
436 uint16_t cnt[TF_TCAM_TBL_TYPE_MAX];
440 * EM type resource definition
442 struct tf_em_resources {
444 * Array of TF EM table types where each entry is expected to
445 * be set to the requested resource number of that specific
446 * type. The index used is tf_em_tbl_type.
448 uint16_t cnt[TF_EM_TBL_TYPE_MAX];
452 * tf_session_resources parameter definition.
454 struct tf_session_resources {
456 * [in] Requested Identifier Resources
458 * Number of identifier resources requested for the
461 struct tf_identifier_resources ident_cnt[TF_DIR_MAX];
463 * [in] Requested Index Table resource counts
465 * The number of index table resources requested for the
468 struct tf_tbl_resources tbl_cnt[TF_DIR_MAX];
470 * [in] Requested TCAM Table resource counts
472 * The number of TCAM table resources requested for the
476 struct tf_tcam_resources tcam_cnt[TF_DIR_MAX];
478 * [in] Requested EM resource counts
480 * The number of internal EM table resources requested for the
483 struct tf_em_resources em_cnt[TF_DIR_MAX];
487 * tf_open_session parameters definition.
489 struct tf_open_session_parms {
491 * [in] ctrl_chan_name
493 * String containing name of control channel interface to be
494 * used for this session to communicate with firmware.
496 * The ctrl_chan_name can be looked up by using
497 * rte_eth_dev_get_name_by_port() within the ULP.
499 * ctrl_chan_name will be used as part of a name for any
500 * shared memory allocation.
502 char ctrl_chan_name[TF_SESSION_NAME_MAX];
506 * Boolean controlling the use and availability of shadow
507 * copy. Shadow copy will allow the TruFlow to keep track of
508 * resource content on the firmware side without having to
509 * query firmware. Additional private session core_data will
510 * be allocated if this boolean is set to 'true', default
513 * Size of memory depends on the NVM Resource settings for the
518 * [in/out] session_id
520 * Session_id is unique per session.
522 * Session_id is composed of domain, bus, device and
523 * fw_session_id. The construction is done by parsing the
524 * ctrl_chan_name together with allocation of a fw_session_id.
526 * The session_id allows a session to be shared between devices.
528 union tf_session_id session_id;
530 * [in/out] session_client_id
532 * Session_client_id is unique per client.
534 * Session_client_id is composed of session_id and the
535 * fw_session_client_id fw_session_id. The construction is
536 * done by parsing the ctrl_chan_name together with allocation
537 * of a fw_session_client_id during tf_open_session().
539 * A reference count will be incremented in the session on
540 * which a client is created.
542 * A session can first be closed if there is one Session
543 * Client left. Session Clients should closed using
544 * tf_close_session().
546 union tf_session_client_id session_client_id;
550 * Device type for the session.
552 enum tf_device_type device_type;
556 * Resource allocation for the session.
558 struct tf_session_resources resources;
562 * Opens a new TruFlow Session or session client.
564 * What gets created depends on the passed in tfp content. If the tfp
565 * does not have prior session data a new session with associated
566 * session client. If tfp has a session already a session client will
567 * be created. In both cases the session client is created using the
568 * provided ctrl_chan_name.
570 * In case of session creation TruFlow will allocate session specific
571 * memory, shared memory, to hold its session data. This data is
572 * private to TruFlow.
574 * No other TruFlow APIs will succeed unless this API is first called
577 * tf_open_session() returns a session id and session client id that
578 * is used on all other TF APIs.
580 * A Session or session client can be closed using tf_close_session().
583 * Pointer to TF handle
586 * Pointer to open parameters
589 * - (0) if successful.
590 * - (-EINVAL) on failure.
592 int tf_open_session(struct tf *tfp,
593 struct tf_open_session_parms *parms);
598 * tf_attach_session parameters definition.
600 struct tf_attach_session_parms {
602 * [in] ctrl_chan_name
604 * String containing name of control channel interface to be
605 * used for this session to communicate with firmware.
607 * The ctrl_chan_name can be looked up by using
608 * rte_eth_dev_get_name_by_port() within the ULP.
610 * ctrl_chan_name will be used as part of a name for any
611 * shared memory allocation.
613 char ctrl_chan_name[TF_SESSION_NAME_MAX];
616 * [in] attach_chan_name
618 * String containing name of attach channel interface to be
619 * used for this session.
621 * The attach_chan_name must be given to a 2nd process after
622 * the primary process has been created. This is the
623 * ctrl_chan_name of the primary process and is used to find
624 * the shared memory for the session that the attach is going
627 char attach_chan_name[TF_SESSION_NAME_MAX];
632 * Session_id is unique per session. For Attach the session_id
633 * should be the session_id that was returned on the first
636 * Session_id is composed of domain, bus, device and
637 * fw_session_id. The construction is done by parsing the
638 * ctrl_chan_name together with allocation of a fw_session_id
639 * during tf_open_session().
641 * A reference count will be incremented on attach. A session
642 * is first fully closed when reference count is zero by
643 * calling tf_close_session().
645 union tf_session_id session_id;
651 * Allows a 2nd application instance to attach to an existing
652 * session. Used when a session is to be shared between two processes.
654 * Attach will increment a ref count as to manage the shared session data.
657 * Pointer to TF handle
660 * Pointer to attach parameters
663 * - (0) if successful.
664 * - (-EINVAL) on failure.
666 int tf_attach_session(struct tf *tfp,
667 struct tf_attach_session_parms *parms);
670 * Closes an existing session client or the session it self. The
671 * session client is default closed and if the session reference count
672 * is 0 then the session is closed as well.
674 * On session close all hardware and firmware state associated with
675 * the TruFlow application is cleaned up.
677 * The session client is extracted from the tfp. Thus tf_close_session()
678 * cannot close a session client on behalf of another function.
680 * Returns success or failure code.
682 int tf_close_session(struct tf *tfp);
685 * @page ident Identity Management
687 * @ref tf_alloc_identifier
689 * @ref tf_free_identifier
692 * tf_alloc_identifier parameter definition
694 struct tf_alloc_identifier_parms {
696 * [in] receive or transmit direction
700 * [in] Identifier type
702 enum tf_identifier_type ident_type;
704 * [out] Allocated identifier
710 * tf_free_identifier parameter definition
712 struct tf_free_identifier_parms {
714 * [in] receive or transmit direction
718 * [in] Identifier type
720 enum tf_identifier_type ident_type;
727 * [out] Current refcnt after free
733 * tf_search_identifier parameter definition (experimental)
735 struct tf_search_identifier_parms {
737 * [in] receive or transmit direction
741 * [in] Identifier type
743 enum tf_identifier_type ident_type;
745 * [in] Identifier data to search for
749 * [out] Set if matching identifier found
753 * [out] Current ref count after allocation
759 * allocate identifier resource
761 * TruFlow core will allocate a free id from the per identifier resource type
762 * pool reserved for the session during tf_open(). No firmware is involved.
764 * If shadow copy is enabled, the internal ref_cnt is set to 1 in the
765 * shadow table for a newly allocated resource.
767 * Returns success or failure code.
769 int tf_alloc_identifier(struct tf *tfp,
770 struct tf_alloc_identifier_parms *parms);
773 * free identifier resource
775 * TruFlow core will return an id back to the per identifier resource type pool
776 * reserved for the session. No firmware is involved. During tf_close, the
777 * complete pool is returned to the firmware.
779 * additional operation (experimental)
780 * Decrement reference count. Only release resource once refcnt goes to 0 if
781 * shadow copy is enabled.
783 * Returns success or failure code.
785 int tf_free_identifier(struct tf *tfp,
786 struct tf_free_identifier_parms *parms);
789 * Search identifier resource (experimental)
791 * If the shadow copy is enabled search_id is used to search for a matching
792 * entry in the shadow table. The shadow table consists of an array of
793 * reference counts indexed by identifier. If a matching entry is found hit is
794 * set to TRUE, refcnt is increased by 1 and returned. Otherwise, hit is
795 * set to false and refcnt is set to 0.
797 * TODO: we may need a per table internal shadow copy enable flag to stage
798 * the shadow table implementation. We do not need the shadow table for other
799 * tables at this time so we may only want to enable the identifier shadow.
801 * TODO: remove this pseudocode below added to show that if search fails
802 * we shouldn't allocate a new entry but return.
804 * identifier alloc (search_en=1)
805 * if (ident is allocated and ref_cnt >=1)
806 * return ident - hit is set, incr refcnt
811 int tf_search_identifier(struct tf *tfp,
812 struct tf_search_identifier_parms *parms);
815 * @page dram_table DRAM Table Scope Interface
817 * @ref tf_alloc_tbl_scope
819 * @ref tf_free_tbl_scope
821 * If we allocate the EEM memory from the core, we need to store it in
822 * the shared session data structure to make sure it can be freed later.
823 * (for example if the PF goes away)
825 * Current thought is that memory is allocated within core.
830 * tf_alloc_tbl_scope_parms definition
832 struct tf_alloc_tbl_scope_parms {
834 * [in] All Maximum key size required.
836 uint16_t rx_max_key_sz_in_bits;
838 * [in] Maximum Action size required (includes inlined items)
840 uint16_t rx_max_action_entry_sz_in_bits;
842 * [in] Memory size in Megabytes
843 * Total memory size allocated by user to be divided
844 * up for actions, hash, counters. Only inline external actions.
845 * Use this variable or the number of flows, do not set both.
847 uint32_t rx_mem_size_in_mb;
849 * [in] Number of flows * 1000. If set, rx_mem_size_in_mb must equal 0.
851 uint32_t rx_num_flows_in_k;
853 * [in] SR2 only receive table access interface id
855 uint32_t rx_tbl_if_id;
857 * [in] All Maximum key size required.
859 uint16_t tx_max_key_sz_in_bits;
861 * [in] Maximum Action size required (includes inlined items)
863 uint16_t tx_max_action_entry_sz_in_bits;
865 * [in] Memory size in Megabytes
866 * Total memory size allocated by user to be divided
867 * up for actions, hash, counters. Only inline external actions.
869 uint32_t tx_mem_size_in_mb;
871 * [in] Number of flows * 1000
873 uint32_t tx_num_flows_in_k;
875 * [in] SR2 only receive table access interface id
877 uint32_t tx_tbl_if_id;
879 * [in] Flush pending HW cached flows every 1/10th of value
880 * set in seconds, both idle and active flows are flushed
881 * from the HW cache. If set to 0, this feature will be disabled.
883 uint8_t hw_flow_cache_flush_timer;
885 * [out] table scope identifier
887 uint32_t tbl_scope_id;
890 struct tf_free_tbl_scope_parms {
892 * [in] table scope identifier
894 uint32_t tbl_scope_id;
898 * allocate a table scope
900 * On SR2 Firmware will allocate a scope ID. On other devices, the scope
901 * is a software construct to identify an EEM table. This function will
902 * divide the hash memory/buckets and records according to the device
903 * device constraints based upon calculations using either the number of flows
904 * requested or the size of memory indicated. Other parameters passed in
905 * determine the configuration (maximum key size, maximum external action record
908 * This API will allocate the table region in
909 * DRAM, program the PTU page table entries, and program the number of static
910 * buckets (if SR2) in the RX and TX CFAs. Buckets are assumed to start at
911 * 0 in the EM memory for the scope. Upon successful completion of this API,
912 * hash tables are fully initialized and ready for entries to be inserted.
914 * A single API is used to allocate a common table scope identifier in both
915 * receive and transmit CFA. The scope identifier is common due to nature of
916 * connection tracking sending notifications between RX and TX direction.
918 * The receive and transmit table access identifiers specify which rings will
919 * be used to initialize table DRAM. The application must ensure mutual
920 * exclusivity of ring usage for table scope allocation and any table update
923 * The hash table buckets, EM keys, and EM lookup results are stored in the
924 * memory allocated based on the rx_em_hash_mb/tx_em_hash_mb parameters. The
925 * hash table buckets are stored at the beginning of that memory.
927 * NOTE: No EM internal setup is done here. On chip EM records are managed
928 * internally by TruFlow core.
930 * Returns success or failure code.
932 int tf_alloc_tbl_scope(struct tf *tfp,
933 struct tf_alloc_tbl_scope_parms *parms);
939 * Firmware checks that the table scope ID is owned by the TruFlow
940 * session, verifies that no references to this table scope remains
941 * (SR2 ILT) or Profile TCAM entries for either CFA (RX/TX) direction,
942 * then frees the table scope ID.
944 * Returns success or failure code.
946 int tf_free_tbl_scope(struct tf *tfp,
947 struct tf_free_tbl_scope_parms *parms);
950 * @page tcam TCAM Access
952 * @ref tf_alloc_tcam_entry
954 * @ref tf_set_tcam_entry
956 * @ref tf_get_tcam_entry
958 * @ref tf_free_tcam_entry
963 * tf_alloc_tcam_entry parameter definition
965 struct tf_alloc_tcam_entry_parms {
967 * [in] receive or transmit direction
971 * [in] TCAM table type
973 enum tf_tcam_tbl_type tcam_tbl_type;
975 * [in] Enable search for matching entry
977 uint8_t search_enable;
979 * [in] Key data to match on (if search)
983 * [in] key size in bits (if search)
985 uint16_t key_sz_in_bits;
987 * [in] Mask data to match on (if search)
991 * [in] Priority of entry requested (definition TBD)
995 * [out] If search, set if matching entry found
999 * [out] Current refcnt after allocation
1003 * [out] Idx allocated
1010 * allocate TCAM entry
1012 * Allocate a TCAM entry - one of these types:
1019 * This function allocates a TCAM table record. This function
1020 * will attempt to allocate a TCAM table entry from the session
1021 * owned TCAM entries or search a shadow copy of the TCAM table for a
1022 * matching entry if search is enabled. Key, mask and result must match for
1023 * hit to be set. Only TruFlow core data is accessed.
1024 * A hash table to entry mapping is maintained for search purposes. If
1025 * search is not enabled, the first available free entry is returned based
1026 * on priority and alloc_cnt is set to 1. If search is enabled and a matching
1027 * entry to entry_data is found, hit is set to TRUE and alloc_cnt is set to 1.
1028 * RefCnt is also returned.
1030 * Also returns success or failure code.
1032 int tf_alloc_tcam_entry(struct tf *tfp,
1033 struct tf_alloc_tcam_entry_parms *parms);
1036 * tf_set_tcam_entry parameter definition
1038 struct tf_set_tcam_entry_parms {
1040 * [in] receive or transmit direction
1044 * [in] TCAM table type
1046 enum tf_tcam_tbl_type tcam_tbl_type;
1048 * [in] base index of the entry to program
1052 * [in] struct containing key
1056 * [in] struct containing mask fields
1060 * [in] key size in bits (if search)
1062 uint16_t key_sz_in_bits;
1064 * [in] struct containing result
1068 * [in] struct containing result size in bits
1070 uint16_t result_sz_in_bits;
1076 * Program a TCAM table entry for a TruFlow session.
1078 * If the entry has not been allocated, an error will be returned.
1080 * Returns success or failure code.
1082 int tf_set_tcam_entry(struct tf *tfp,
1083 struct tf_set_tcam_entry_parms *parms);
1086 * tf_get_tcam_entry parameter definition
1088 struct tf_get_tcam_entry_parms {
1090 * [in] receive or transmit direction
1094 * [in] TCAM table type
1096 enum tf_tcam_tbl_type tcam_tbl_type;
1098 * [in] index of the entry to get
1102 * [out] struct containing key
1106 * [out] struct containing mask fields
1110 * [out] key size in bits
1112 uint16_t key_sz_in_bits;
1114 * [out] struct containing result
1118 * [out] struct containing result size in bits
1120 uint16_t result_sz_in_bits;
1126 * Program a TCAM table entry for a TruFlow session.
1128 * If the entry has not been allocated, an error will be returned.
1130 * Returns success or failure code.
1132 int tf_get_tcam_entry(struct tf *tfp,
1133 struct tf_get_tcam_entry_parms *parms);
1136 * tf_free_tcam_entry parameter definition
1138 struct tf_free_tcam_entry_parms {
1140 * [in] receive or transmit direction
1144 * [in] TCAM table type
1146 enum tf_tcam_tbl_type tcam_tbl_type;
1148 * [in] Index to free
1152 * [out] reference count after free
1162 * Firmware checks to ensure the TCAM entries are owned by the TruFlow
1163 * session. TCAM entry will be invalidated. All-ones mask.
1166 * WCTCAM profile id of 0 must be used to invalidate an entry.
1168 * Returns success or failure code.
1170 int tf_free_tcam_entry(struct tf *tfp,
1171 struct tf_free_tcam_entry_parms *parms);
1174 * @page table Table Access
1176 * @ref tf_alloc_tbl_entry
1178 * @ref tf_free_tbl_entry
1180 * @ref tf_set_tbl_entry
1182 * @ref tf_get_tbl_entry
1184 * @ref tf_bulk_get_tbl_entry
1188 * tf_alloc_tbl_entry parameter definition
1190 struct tf_alloc_tbl_entry_parms {
1192 * [in] Receive or transmit direction
1196 * [in] Type of the allocation
1198 enum tf_tbl_type type;
1200 * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1202 uint32_t tbl_scope_id;
1204 * [in] Enable search for matching entry. If the table type is
1205 * internal the shadow copy will be searched before
1206 * alloc. Session must be configured with shadow copy enabled.
1208 uint8_t search_enable;
1210 * [in] Result data to search for (if search_enable)
1214 * [in] Result data size in bytes (if search_enable)
1216 uint16_t result_sz_in_bytes;
1218 * [out] If search_enable, set if matching entry found
1222 * [out] Current ref count after allocation (if search_enable)
1226 * [out] Idx of allocated entry or found entry (if search_enable)
1232 * allocate index table entries
1236 * Allocate an on chip index table entry or search for a matching
1237 * entry of the indicated type for this TruFlow session.
1239 * Allocates an index table record. This function will attempt to
1240 * allocate an entry or search an index table for a matching entry if
1241 * search is enabled (only the shadow copy of the table is accessed).
1243 * If search is not enabled, the first available free entry is
1244 * returned. If search is enabled and a matching entry to entry_data
1245 * is found hit is set to TRUE and success is returned.
1249 * These are used to allocate inlined action record memory.
1251 * Allocates an external index table action record.
1254 * Implementation of the internals of this function will be a stack with push
1257 * Returns success or failure code.
1259 int tf_alloc_tbl_entry(struct tf *tfp,
1260 struct tf_alloc_tbl_entry_parms *parms);
1263 * tf_free_tbl_entry parameter definition
1265 struct tf_free_tbl_entry_parms {
1267 * [in] Receive or transmit direction
1271 * [in] Type of the allocation type
1273 enum tf_tbl_type type;
1275 * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1277 uint32_t tbl_scope_id;
1279 * [in] Index to free
1283 * [out] Reference count after free, only valid if session has been
1284 * created with shadow_copy.
1290 * free index table entry
1292 * Used to free a previously allocated table entry.
1296 * If session has shadow_copy enabled the shadow DB is searched and if
1297 * found the element ref_cnt is decremented. If ref_cnt goes to
1298 * zero then the element is returned to the session pool.
1300 * If the session does not have a shadow DB the element is free'ed and
1301 * given back to the session pool.
1305 * Free's an external index table action record.
1308 * Implementation of the internals of this function will be a stack with push
1311 * Returns success or failure code.
1313 int tf_free_tbl_entry(struct tf *tfp,
1314 struct tf_free_tbl_entry_parms *parms);
1317 * tf_set_tbl_entry parameter definition
1319 struct tf_set_tbl_entry_parms {
1321 * [in] Table scope identifier
1323 uint32_t tbl_scope_id;
1325 * [in] Receive or transmit direction
1329 * [in] Type of object to set
1331 enum tf_tbl_type type;
1339 uint16_t data_sz_in_bytes;
1341 * [in] Entry index to write to
1347 * set index table entry
1349 * Used to insert an application programmed index table entry into a
1350 * previous allocated table location. A shadow copy of the table
1351 * is maintained (if enabled) (only for internal objects)
1353 * Returns success or failure code.
1355 int tf_set_tbl_entry(struct tf *tfp,
1356 struct tf_set_tbl_entry_parms *parms);
1359 * tf_get_tbl_entry parameter definition
1361 struct tf_get_tbl_entry_parms {
1363 * [in] Receive or transmit direction
1367 * [in] Type of object to get
1369 enum tf_tbl_type type;
1377 uint16_t data_sz_in_bytes;
1379 * [in] Entry index to read
1385 * get index table entry
1387 * Used to retrieve a previous set index table entry.
1389 * Reads and compares with the shadow table copy (if enabled) (only
1390 * for internal objects).
1392 * Returns success or failure code. Failure will be returned if the
1393 * provided data buffer is too small for the data type requested.
1395 int tf_get_tbl_entry(struct tf *tfp,
1396 struct tf_get_tbl_entry_parms *parms);
1399 * tf_bulk_get_tbl_entry parameter definition
1401 struct tf_bulk_get_tbl_entry_parms {
1403 * [in] Receive or transmit direction
1407 * [in] Type of object to get
1409 enum tf_tbl_type type;
1411 * [in] Starting index to read from
1413 uint32_t starting_idx;
1415 * [in] Number of sequential entries
1417 uint16_t num_entries;
1419 * [in] Size of the single entry
1421 uint16_t entry_sz_in_bytes;
1423 * [out] Host physical address, where the data
1424 * will be copied to by the firmware.
1425 * Use tfp_calloc() API and mem_pa
1426 * variable of the tfp_calloc_parms
1427 * structure for the physical address.
1429 uint64_t physical_mem_addr;
1433 * Bulk get index table entry
1435 * Used to retrieve a set of index table entries.
1437 * Entries within the range may not have been allocated using
1438 * tf_alloc_tbl_entry() at the time of access. But the range must
1439 * be within the bounds determined from tf_open_session() for the
1440 * given table type. Currently, this is only used for collecting statistics.
1442 * Returns success or failure code. Failure will be returned if the
1443 * provided data buffer is too small for the data type requested.
1445 int tf_bulk_get_tbl_entry(struct tf *tfp,
1446 struct tf_bulk_get_tbl_entry_parms *parms);
1449 * @page exact_match Exact Match Table
1451 * @ref tf_insert_em_entry
1453 * @ref tf_delete_em_entry
1455 * @ref tf_search_em_entry
1459 * tf_insert_em_entry parameter definition
1461 struct tf_insert_em_entry_parms {
1463 * [in] receive or transmit direction
1467 * [in] internal or external
1471 * [in] ID of table scope to use (external only)
1473 uint32_t tbl_scope_id;
1475 * [in] ID of table interface to use (SR2 only)
1479 * [in] ptr to structure containing key fields
1483 * [in] key bit length
1485 uint16_t key_sz_in_bits;
1487 * [in] ptr to structure containing result field
1491 * [out] result size in bits
1493 uint16_t em_record_sz_in_bits;
1495 * [in] duplicate check flag
1499 * [out] Flow handle value for the inserted entry. This is encoded
1500 * as the entries[4]:bucket[2]:hashId[1]:hash[14]
1502 uint64_t flow_handle;
1504 * [out] Flow id is returned as null (internal)
1505 * Flow id is the GFID value for the inserted entry (external)
1506 * This is the value written to the BD and useful information for mark.
1511 * tf_delete_em_entry parameter definition
1513 struct tf_delete_em_entry_parms {
1515 * [in] receive or transmit direction
1519 * [in] internal or external
1523 * [in] ID of table scope to use (external only)
1525 uint32_t tbl_scope_id;
1527 * [in] ID of table interface to use (SR2 only)
1531 * [in] epoch group IDs of entry to delete
1532 * 2 element array with 2 ids. (SR2 only)
1536 * [out] The index of the entry
1540 * [in] structure containing flow delete handle information
1542 uint64_t flow_handle;
1545 * tf_search_em_entry parameter definition
1547 struct tf_search_em_entry_parms {
1549 * [in] receive or transmit direction
1553 * [in] internal or external
1557 * [in] ID of table scope to use (external only)
1559 uint32_t tbl_scope_id;
1561 * [in] ID of table interface to use (SR2 only)
1565 * [in] ptr to structure containing key fields
1569 * [in] key bit length
1571 uint16_t key_sz_in_bits;
1573 * [in/out] ptr to structure containing EM record fields
1577 * [out] result size in bits
1579 uint16_t em_record_sz_in_bits;
1581 * [in] epoch group IDs of entry to lookup
1582 * 2 element array with 2 ids. (SR2 only)
1586 * [in] ptr to structure containing flow delete handle
1588 uint64_t flow_handle;
1592 * insert em hash entry in internal table memory
1596 * This API inserts an exact match entry into internal EM table memory
1597 * of the specified direction.
1599 * Note: The EM record is managed within the TruFlow core and not the
1602 * Shadow copy of internal record table an association with hash and 1,2, or 4
1603 * associated buckets
1606 * This API inserts an exact match entry into DRAM EM table memory of the
1607 * specified direction and table scope.
1609 * When inserting an entry into an exact match table, the TruFlow library may
1610 * need to allocate a dynamic bucket for the entry (SR2 only).
1612 * The insertion of duplicate entries in an EM table is not permitted. If a
1613 * TruFlow application can guarantee that it will never insert duplicates, it
1614 * can disable duplicate checking by passing a zero value in the dup_check
1615 * parameter to this API. This will optimize performance. Otherwise, the
1616 * TruFlow library will enforce protection against inserting duplicate entries.
1618 * Flow handle is defined in this document:
1620 * https://docs.google.com
1621 * /document/d/1NESu7RpTN3jwxbokaPfYORQyChYRmJgs40wMIRe8_-Q/edit
1623 * Returns success or busy code.
1626 int tf_insert_em_entry(struct tf *tfp,
1627 struct tf_insert_em_entry_parms *parms);
1630 * delete em hash entry table memory
1634 * This API deletes an exact match entry from internal EM table memory of the
1635 * specified direction. If a valid flow ptr is passed in then that takes
1636 * precedence over the pointer to the complete key passed in.
1641 * This API deletes an exact match entry from EM table memory of the specified
1642 * direction and table scope. If a valid flow handle is passed in then that
1643 * takes precedence over the pointer to the complete key passed in.
1645 * The TruFlow library may release a dynamic bucket when an entry is deleted.
1648 * Returns success or not found code
1652 int tf_delete_em_entry(struct tf *tfp,
1653 struct tf_delete_em_entry_parms *parms);
1656 * search em hash entry table memory
1660 * This API looks up an EM entry in table memory with the specified EM
1661 * key or flow (flow takes precedence) and direction.
1663 * The status will be one of: success or entry not found. If the lookup
1664 * succeeds, a pointer to the matching entry and the result record associated
1665 * with the matching entry will be provided.
1667 * If flow_handle is set, search shadow copy.
1669 * Otherwise, query the fw with key to get result.
1673 * This API looks up an EM entry in table memory with the specified EM
1674 * key or flow_handle (flow takes precedence), direction and table scope.
1676 * The status will be one of: success or entry not found. If the lookup
1677 * succeeds, a pointer to the matching entry and the result record associated
1678 * with the matching entry will be provided.
1680 * Returns success or not found code
1683 int tf_search_em_entry(struct tf *tfp,
1684 struct tf_search_em_entry_parms *parms);
1687 * @page global Global Configuration
1689 * @ref tf_set_global_cfg
1691 * @ref tf_get_global_cfg
1694 * Tunnel Encapsulation Offsets
1696 enum tf_tunnel_encap_offsets {
1698 TF_TUNNEL_ENCAP_NAT,
1699 TF_TUNNEL_ENCAP_MPLS,
1700 TF_TUNNEL_ENCAP_VXLAN,
1701 TF_TUNNEL_ENCAP_GENEVE,
1702 TF_TUNNEL_ENCAP_NVGRE,
1703 TF_TUNNEL_ENCAP_GRE,
1704 TF_TUNNEL_ENCAP_FULL_GENERIC
1707 * Global Configuration Table Types
1709 enum tf_global_config_type {
1710 TF_TUNNEL_ENCAP, /**< Tunnel Encap Config(TECT) */
1711 TF_ACTION_BLOCK, /**< Action Block Config(ABCR) */
1712 TF_GLOBAL_CFG_TYPE_MAX
1716 * tf_global_cfg parameter definition
1718 struct tf_global_cfg_parms {
1720 * [in] receive or transmit direction
1724 * [in] Global config type
1726 enum tf_global_config_type type;
1728 * [in] Offset @ the type
1732 * [in/out] Value of the configuration
1733 * set - Read, Modify and Write
1734 * get - Read the full configuration
1738 * [in] struct containing size
1740 uint16_t config_sz_in_bytes;
1744 * Get global configuration
1746 * Retrieve the configuration
1748 * Returns success or failure code.
1750 int tf_get_global_cfg(struct tf *tfp,
1751 struct tf_global_cfg_parms *parms);
1754 * Update the global configuration table
1756 * Read, modify write the value.
1758 * Returns success or failure code.
1760 int tf_set_global_cfg(struct tf *tfp,
1761 struct tf_global_cfg_parms *parms);
1764 * @page if_tbl Interface Table Access
1766 * @ref tf_set_if_tbl_entry
1768 * @ref tf_get_if_tbl_entry
1770 * @ref tf_restore_if_tbl_entry
1773 * Enumeration of TruFlow interface table types.
1775 enum tf_if_tbl_type {
1776 /** Default Profile L2 Context Entry */
1777 TF_IF_TBL_TYPE_PROF_SPIF_DFLT_L2_CTXT,
1778 /** Default Profile TCAM/Lookup Action Record Pointer Table */
1779 TF_IF_TBL_TYPE_PROF_PARIF_DFLT_ACT_REC_PTR,
1780 /** Error Profile TCAM Miss Action Record Pointer Table */
1781 TF_IF_TBL_TYPE_PROF_PARIF_ERR_ACT_REC_PTR,
1782 /** Default Error Profile TCAM Miss Action Record Pointer Table */
1783 TF_IF_TBL_TYPE_LKUP_PARIF_DFLT_ACT_REC_PTR,
1784 /** SR2 Ingress lookup table */
1786 /** SR2 VNIC/SVIF Table */
1787 TF_IF_TBL_TYPE_VNIC_SVIF,
1792 * tf_set_if_tbl_entry parameter definition
1794 struct tf_set_if_tbl_entry_parms {
1796 * [in] Receive or transmit direction
1800 * [in] Type of object to set
1802 enum tf_if_tbl_type type;
1810 uint16_t data_sz_in_bytes;
1812 * [in] Interface to write
1818 * set interface table entry
1820 * Used to set an interface table. This API is used for managing tables indexed
1821 * by SVIF/SPIF/PARIF interfaces. In current implementation only the value is
1823 * Returns success or failure code.
1825 int tf_set_if_tbl_entry(struct tf *tfp,
1826 struct tf_set_if_tbl_entry_parms *parms);
1829 * tf_get_if_tbl_entry parameter definition
1831 struct tf_get_if_tbl_entry_parms {
1833 * [in] Receive or transmit direction
1837 * [in] Type of table to get
1839 enum tf_if_tbl_type type;
1847 uint16_t data_sz_in_bytes;
1849 * [in] Entry index to read
1855 * get interface table entry
1857 * Used to retrieve an interface table entry.
1859 * Reads the interface table entry value
1861 * Returns success or failure code. Failure will be returned if the
1862 * provided data buffer is too small for the data type requested.
1864 int tf_get_if_tbl_entry(struct tf *tfp,
1865 struct tf_get_if_tbl_entry_parms *parms);
1867 #endif /* _TF_CORE_H_ */