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,
296 enum tf_search_status {
297 /** The entry was not found, but an idx was allocated if requested. */
299 /** The entry was found, and the result/idx are valid */
301 /** The entry was not found and the table is full */
307 * These defines are provisioned during
310 enum tf_em_tbl_type {
311 /** The number of internal EM records for the session */
312 TF_EM_TBL_TYPE_EM_RECORD,
313 /** The number of table scopes reequested */
314 TF_EM_TBL_TYPE_TBL_SCOPE,
319 * TruFlow Session Information
321 * Structure defining a TruFlow Session, also known as a Management
322 * session. This structure is initialized at time of
323 * tf_open_session(). It is passed to all of the TruFlow APIs as way
324 * to prescribe and isolate resources between different TruFlow ULP
327 * Ownership of the elements is split between ULP and TruFlow. Please
328 * see the individual elements.
330 struct tf_session_info {
332 * TrueFlow Version. Used to control the structure layout when
333 * sharing sessions. No guarantee that a secondary process
334 * would come from the same version of an executable.
335 * TruFlow initializes this variable on tf_open_session().
340 struct tf_session_version ver;
342 * will be STAILQ_ENTRY(tf_session_info) next
349 * Session ID is a unique identifier for the session. TruFlow
350 * initializes this variable during tf_open_session()
354 * Access: Truflow & ULP
356 union tf_session_id session_id;
358 * Protects access to core_data. Lock is initialized and owned
359 * by ULP. TruFlow can access the core_data without checking
367 * The core_data holds the TruFlow tf_session data
368 * structure. This memory is allocated and owned by TruFlow on
371 * TruFlow uses this memory for session management control
372 * until the session is closed by ULP. Access control is done
373 * by the spin_lock which ULP controls ahead of TruFlow API
376 * Please see tf_open_session_parms for specification details
384 * The core_data_sz_bytes specifies the size of core_data in
387 * The size is set by TruFlow on tf_open_session().
389 * Please see tf_open_session_parms for specification details
395 uint32_t core_data_sz_bytes;
401 * Contains a pointer to the session info. Allocated by ULP and passed
402 * to TruFlow using tf_open_session(). TruFlow will populate the
403 * session info at that time. A TruFlow Session can be used by more
404 * than one PF/VF by using the tf_open_session().
406 * It is expected that ULP allocates this memory as shared memory.
408 * NOTE: This struct must be within the BNXT PMD struct bnxt
409 * (bp). This allows use of container_of() to get access to the PMD.
412 struct tf_session_info *session;
416 * Identifier resource definition
418 struct tf_identifier_resources {
420 * Array of TF Identifiers where each entry is expected to be
421 * set to the requested resource number of that specific type.
422 * The index used is tf_identifier_type.
424 uint16_t cnt[TF_IDENT_TYPE_MAX];
428 * Table type resource definition
430 struct tf_tbl_resources {
432 * Array of TF Table types where each entry is expected to be
433 * set to the requeste resource number of that specific
434 * type. The index used is tf_tbl_type.
436 uint16_t cnt[TF_TBL_TYPE_MAX];
440 * TCAM type resource definition
442 struct tf_tcam_resources {
444 * Array of TF TCAM types where each entry is expected to be
445 * set to the requested resource number of that specific
446 * type. The index used is tf_tcam_tbl_type.
448 uint16_t cnt[TF_TCAM_TBL_TYPE_MAX];
452 * EM type resource definition
454 struct tf_em_resources {
456 * Array of TF EM table types where each entry is expected to
457 * be set to the requested resource number of that specific
458 * type. The index used is tf_em_tbl_type.
460 uint16_t cnt[TF_EM_TBL_TYPE_MAX];
464 * tf_session_resources parameter definition.
466 struct tf_session_resources {
468 * [in] Requested Identifier Resources
470 * Number of identifier resources requested for the
473 struct tf_identifier_resources ident_cnt[TF_DIR_MAX];
475 * [in] Requested Index Table resource counts
477 * The number of index table resources requested for the
480 struct tf_tbl_resources tbl_cnt[TF_DIR_MAX];
482 * [in] Requested TCAM Table resource counts
484 * The number of TCAM table resources requested for the
488 struct tf_tcam_resources tcam_cnt[TF_DIR_MAX];
490 * [in] Requested EM resource counts
492 * The number of internal EM table resources requested for the
495 struct tf_em_resources em_cnt[TF_DIR_MAX];
499 * tf_open_session parameters definition.
501 struct tf_open_session_parms {
503 * [in] ctrl_chan_name
505 * String containing name of control channel interface to be
506 * used for this session to communicate with firmware.
508 * The ctrl_chan_name can be looked up by using
509 * rte_eth_dev_get_name_by_port() within the ULP.
511 * ctrl_chan_name will be used as part of a name for any
512 * shared memory allocation.
514 char ctrl_chan_name[TF_SESSION_NAME_MAX];
518 * Boolean controlling the use and availability of shadow
519 * copy. Shadow copy will allow the TruFlow to keep track of
520 * resource content on the firmware side without having to
521 * query firmware. Additional private session core_data will
522 * be allocated if this boolean is set to 'true', default
525 * Size of memory depends on the NVM Resource settings for the
530 * [in/out] session_id
532 * Session_id is unique per session.
534 * Session_id is composed of domain, bus, device and
535 * fw_session_id. The construction is done by parsing the
536 * ctrl_chan_name together with allocation of a fw_session_id.
538 * The session_id allows a session to be shared between devices.
540 union tf_session_id session_id;
542 * [in/out] session_client_id
544 * Session_client_id is unique per client.
546 * Session_client_id is composed of session_id and the
547 * fw_session_client_id fw_session_id. The construction is
548 * done by parsing the ctrl_chan_name together with allocation
549 * of a fw_session_client_id during tf_open_session().
551 * A reference count will be incremented in the session on
552 * which a client is created.
554 * A session can first be closed if there is one Session
555 * Client left. Session Clients should closed using
556 * tf_close_session().
558 union tf_session_client_id session_client_id;
562 * Device type for the session.
564 enum tf_device_type device_type;
568 * Resource allocation for the session.
570 struct tf_session_resources resources;
574 * Opens a new TruFlow Session or session client.
576 * What gets created depends on the passed in tfp content. If the tfp
577 * does not have prior session data a new session with associated
578 * session client. If tfp has a session already a session client will
579 * be created. In both cases the session client is created using the
580 * provided ctrl_chan_name.
582 * In case of session creation TruFlow will allocate session specific
583 * memory, shared memory, to hold its session data. This data is
584 * private to TruFlow.
586 * No other TruFlow APIs will succeed unless this API is first called
589 * tf_open_session() returns a session id and session client id that
590 * is used on all other TF APIs.
592 * A Session or session client can be closed using tf_close_session().
595 * Pointer to TF handle
598 * Pointer to open parameters
601 * - (0) if successful.
602 * - (-EINVAL) on failure.
604 int tf_open_session(struct tf *tfp,
605 struct tf_open_session_parms *parms);
610 * tf_attach_session parameters definition.
612 struct tf_attach_session_parms {
614 * [in] ctrl_chan_name
616 * String containing name of control channel interface to be
617 * used for this session to communicate with firmware.
619 * The ctrl_chan_name can be looked up by using
620 * rte_eth_dev_get_name_by_port() within the ULP.
622 * ctrl_chan_name will be used as part of a name for any
623 * shared memory allocation.
625 char ctrl_chan_name[TF_SESSION_NAME_MAX];
628 * [in] attach_chan_name
630 * String containing name of attach channel interface to be
631 * used for this session.
633 * The attach_chan_name must be given to a 2nd process after
634 * the primary process has been created. This is the
635 * ctrl_chan_name of the primary process and is used to find
636 * the shared memory for the session that the attach is going
639 char attach_chan_name[TF_SESSION_NAME_MAX];
644 * Session_id is unique per session. For Attach the session_id
645 * should be the session_id that was returned on the first
648 * Session_id is composed of domain, bus, device and
649 * fw_session_id. The construction is done by parsing the
650 * ctrl_chan_name together with allocation of a fw_session_id
651 * during tf_open_session().
653 * A reference count will be incremented on attach. A session
654 * is first fully closed when reference count is zero by
655 * calling tf_close_session().
657 union tf_session_id session_id;
663 * Allows a 2nd application instance to attach to an existing
664 * session. Used when a session is to be shared between two processes.
666 * Attach will increment a ref count as to manage the shared session data.
669 * Pointer to TF handle
672 * Pointer to attach parameters
675 * - (0) if successful.
676 * - (-EINVAL) on failure.
678 int tf_attach_session(struct tf *tfp,
679 struct tf_attach_session_parms *parms);
682 * Closes an existing session client or the session it self. The
683 * session client is default closed and if the session reference count
684 * is 0 then the session is closed as well.
686 * On session close all hardware and firmware state associated with
687 * the TruFlow application is cleaned up.
689 * The session client is extracted from the tfp. Thus tf_close_session()
690 * cannot close a session client on behalf of another function.
692 * Returns success or failure code.
694 int tf_close_session(struct tf *tfp);
697 * @page ident Identity Management
699 * @ref tf_alloc_identifier
701 * @ref tf_free_identifier
704 * tf_alloc_identifier parameter definition
706 struct tf_alloc_identifier_parms {
708 * [in] receive or transmit direction
712 * [in] Identifier type
714 enum tf_identifier_type ident_type;
716 * [out] Allocated identifier
722 * tf_free_identifier parameter definition
724 struct tf_free_identifier_parms {
726 * [in] receive or transmit direction
730 * [in] Identifier type
732 enum tf_identifier_type ident_type;
739 * [out] Current refcnt after free
745 * tf_search_identifier parameter definition (experimental)
747 struct tf_search_identifier_parms {
749 * [in] receive or transmit direction
753 * [in] Identifier type
755 enum tf_identifier_type ident_type;
757 * [in] Identifier data to search for
761 * [out] Set if matching identifier found
765 * [out] Current ref count after allocation
771 * allocate identifier resource
773 * TruFlow core will allocate a free id from the per identifier resource type
774 * pool reserved for the session during tf_open(). No firmware is involved.
776 * If shadow copy is enabled, the internal ref_cnt is set to 1 in the
777 * shadow table for a newly allocated resource.
779 * Returns success or failure code.
781 int tf_alloc_identifier(struct tf *tfp,
782 struct tf_alloc_identifier_parms *parms);
785 * free identifier resource
787 * TruFlow core will return an id back to the per identifier resource type pool
788 * reserved for the session. No firmware is involved. During tf_close, the
789 * complete pool is returned to the firmware.
791 * additional operation (experimental)
792 * Decrement reference count. Only release resource once refcnt goes to 0 if
793 * shadow copy is enabled.
795 * Returns success or failure code.
797 int tf_free_identifier(struct tf *tfp,
798 struct tf_free_identifier_parms *parms);
801 * Search identifier resource (experimental)
803 * If the shadow copy is enabled search_id is used to search for a matching
804 * entry in the shadow table. The shadow table consists of an array of
805 * reference counts indexed by identifier. If a matching entry is found hit is
806 * set to TRUE, refcnt is increased by 1 and returned. Otherwise, hit is
807 * set to false and refcnt is set to 0.
809 * TODO: we may need a per table internal shadow copy enable flag to stage
810 * the shadow table implementation. We do not need the shadow table for other
811 * tables at this time so we may only want to enable the identifier shadow.
813 * TODO: remove this pseudocode below added to show that if search fails
814 * we shouldn't allocate a new entry but return.
816 * identifier alloc (search_en=1)
817 * if (ident is allocated and ref_cnt >=1)
818 * return ident - hit is set, incr refcnt
823 int tf_search_identifier(struct tf *tfp,
824 struct tf_search_identifier_parms *parms);
827 * @page dram_table DRAM Table Scope Interface
829 * @ref tf_alloc_tbl_scope
831 * @ref tf_free_tbl_scope
833 * If we allocate the EEM memory from the core, we need to store it in
834 * the shared session data structure to make sure it can be freed later.
835 * (for example if the PF goes away)
837 * Current thought is that memory is allocated within core.
842 * tf_alloc_tbl_scope_parms definition
844 struct tf_alloc_tbl_scope_parms {
846 * [in] All Maximum key size required.
848 uint16_t rx_max_key_sz_in_bits;
850 * [in] Maximum Action size required (includes inlined items)
852 uint16_t rx_max_action_entry_sz_in_bits;
854 * [in] Memory size in Megabytes
855 * Total memory size allocated by user to be divided
856 * up for actions, hash, counters. Only inline external actions.
857 * Use this variable or the number of flows, do not set both.
859 uint32_t rx_mem_size_in_mb;
861 * [in] Number of flows * 1000. If set, rx_mem_size_in_mb must equal 0.
863 uint32_t rx_num_flows_in_k;
865 * [in] SR2 only receive table access interface id
867 uint32_t rx_tbl_if_id;
869 * [in] All Maximum key size required.
871 uint16_t tx_max_key_sz_in_bits;
873 * [in] Maximum Action size required (includes inlined items)
875 uint16_t tx_max_action_entry_sz_in_bits;
877 * [in] Memory size in Megabytes
878 * Total memory size allocated by user to be divided
879 * up for actions, hash, counters. Only inline external actions.
881 uint32_t tx_mem_size_in_mb;
883 * [in] Number of flows * 1000
885 uint32_t tx_num_flows_in_k;
887 * [in] SR2 only receive table access interface id
889 uint32_t tx_tbl_if_id;
891 * [in] Flush pending HW cached flows every 1/10th of value
892 * set in seconds, both idle and active flows are flushed
893 * from the HW cache. If set to 0, this feature will be disabled.
895 uint8_t hw_flow_cache_flush_timer;
897 * [out] table scope identifier
899 uint32_t tbl_scope_id;
902 struct tf_free_tbl_scope_parms {
904 * [in] table scope identifier
906 uint32_t tbl_scope_id;
910 * allocate a table scope
912 * On SR2 Firmware will allocate a scope ID. On other devices, the scope
913 * is a software construct to identify an EEM table. This function will
914 * divide the hash memory/buckets and records according to the device
915 * device constraints based upon calculations using either the number of flows
916 * requested or the size of memory indicated. Other parameters passed in
917 * determine the configuration (maximum key size, maximum external action record
920 * This API will allocate the table region in
921 * DRAM, program the PTU page table entries, and program the number of static
922 * buckets (if SR2) in the RX and TX CFAs. Buckets are assumed to start at
923 * 0 in the EM memory for the scope. Upon successful completion of this API,
924 * hash tables are fully initialized and ready for entries to be inserted.
926 * A single API is used to allocate a common table scope identifier in both
927 * receive and transmit CFA. The scope identifier is common due to nature of
928 * connection tracking sending notifications between RX and TX direction.
930 * The receive and transmit table access identifiers specify which rings will
931 * be used to initialize table DRAM. The application must ensure mutual
932 * exclusivity of ring usage for table scope allocation and any table update
935 * The hash table buckets, EM keys, and EM lookup results are stored in the
936 * memory allocated based on the rx_em_hash_mb/tx_em_hash_mb parameters. The
937 * hash table buckets are stored at the beginning of that memory.
939 * NOTE: No EM internal setup is done here. On chip EM records are managed
940 * internally by TruFlow core.
942 * Returns success or failure code.
944 int tf_alloc_tbl_scope(struct tf *tfp,
945 struct tf_alloc_tbl_scope_parms *parms);
951 * Firmware checks that the table scope ID is owned by the TruFlow
952 * session, verifies that no references to this table scope remains
953 * (SR2 ILT) or Profile TCAM entries for either CFA (RX/TX) direction,
954 * then frees the table scope ID.
956 * Returns success or failure code.
958 int tf_free_tbl_scope(struct tf *tfp,
959 struct tf_free_tbl_scope_parms *parms);
962 * @page tcam TCAM Access
964 * @ref tf_search_tcam_entry
966 * @ref tf_alloc_tcam_entry
968 * @ref tf_set_tcam_entry
970 * @ref tf_get_tcam_entry
972 * @ref tf_free_tcam_entry
976 * tf_search_tcam_entry parameter definition (experimental)
978 struct tf_search_tcam_entry_parms {
980 * [in] receive or transmit direction
984 * [in] TCAM table type
986 enum tf_tcam_tbl_type tcam_tbl_type;
988 * [in] Key data to match on
992 * [in] key size in bits
994 uint16_t key_sz_in_bits;
996 * [in] Mask data to match on
1000 * [in] Priority of entry requested (definition TBD)
1004 * [in] Allocate on miss.
1008 * [out] Set if matching entry found
1012 * [out] Search result status (hit, miss, reject)
1014 enum tf_search_status search_status;
1016 * [out] Current refcnt after allocation
1020 * [in out] The result data from the search is copied here
1024 * [in out] result size in bits for the result data
1026 uint16_t result_sz_in_bits;
1034 * search TCAM entry (experimental)
1036 * Search for a TCAM entry
1038 * This function searches the shadow copy of the TCAM table for a matching
1039 * entry. Key and mask must match for hit to be set. Only TruFlow core data
1040 * is accessed. If shadow_copy is not enabled, an error is returned.
1044 * A hash is performed on the key/mask data and mapped to a shadow copy entry
1045 * where the full key/mask is populated. If the full key/mask matches the
1046 * entry, hit is set, ref_cnt is incremented, and search_status indicates what
1047 * action the caller can take regarding setting the entry.
1049 * search_status should be used as follows:
1050 * - On Miss, the caller should create a result and call tf_set_tcam_entry with
1053 * - On Reject, the hash table is full and the entry cannot be added.
1055 * - On Hit, the result data is returned to the caller. Additionally, the
1056 * ref_cnt is updated.
1058 * Also returns success or failure code.
1060 int tf_search_tcam_entry(struct tf *tfp,
1061 struct tf_search_tcam_entry_parms *parms);
1064 * tf_alloc_tcam_entry parameter definition
1066 struct tf_alloc_tcam_entry_parms {
1068 * [in] receive or transmit direction
1072 * [in] TCAM table type
1074 enum tf_tcam_tbl_type tcam_tbl_type;
1076 * [in] Enable search for matching entry
1078 uint8_t search_enable;
1080 * [in] Key data to match on (if search)
1084 * [in] key size in bits (if search)
1086 uint16_t key_sz_in_bits;
1088 * [in] Mask data to match on (if search)
1092 * [in] Priority of entry requested (definition TBD)
1096 * [out] If search, set if matching entry found
1100 * [out] Current refcnt after allocation
1104 * [out] Idx allocated
1111 * allocate TCAM entry
1113 * Allocate a TCAM entry - one of these types:
1120 * This function allocates a TCAM table record. This function
1121 * will attempt to allocate a TCAM table entry from the session
1122 * owned TCAM entries or search a shadow copy of the TCAM table for a
1123 * matching entry if search is enabled. Key, mask and result must match for
1124 * hit to be set. Only TruFlow core data is accessed.
1125 * A hash table to entry mapping is maintained for search purposes. If
1126 * search is not enabled, the first available free entry is returned based
1127 * on priority and alloc_cnt is set to 1. If search is enabled and a matching
1128 * entry to entry_data is found, hit is set to TRUE and alloc_cnt is set to 1.
1129 * RefCnt is also returned.
1131 * Also returns success or failure code.
1133 int tf_alloc_tcam_entry(struct tf *tfp,
1134 struct tf_alloc_tcam_entry_parms *parms);
1137 * tf_set_tcam_entry parameter definition
1139 struct tf_set_tcam_entry_parms {
1141 * [in] receive or transmit direction
1145 * [in] TCAM table type
1147 enum tf_tcam_tbl_type tcam_tbl_type;
1149 * [in] base index of the entry to program
1153 * [in] struct containing key
1157 * [in] struct containing mask fields
1161 * [in] key size in bits (if search)
1163 uint16_t key_sz_in_bits;
1165 * [in] struct containing result
1169 * [in] struct containing result size in bits
1171 uint16_t result_sz_in_bits;
1177 * Program a TCAM table entry for a TruFlow session.
1179 * If the entry has not been allocated, an error will be returned.
1181 * Returns success or failure code.
1183 int tf_set_tcam_entry(struct tf *tfp,
1184 struct tf_set_tcam_entry_parms *parms);
1187 * tf_get_tcam_entry parameter definition
1189 struct tf_get_tcam_entry_parms {
1191 * [in] receive or transmit direction
1195 * [in] TCAM table type
1197 enum tf_tcam_tbl_type tcam_tbl_type;
1199 * [in] index of the entry to get
1203 * [out] struct containing key
1207 * [out] struct containing mask fields
1211 * [out] key size in bits
1213 uint16_t key_sz_in_bits;
1215 * [out] struct containing result
1219 * [out] struct containing result size in bits
1221 uint16_t result_sz_in_bits;
1227 * Program a TCAM table entry for a TruFlow session.
1229 * If the entry has not been allocated, an error will be returned.
1231 * Returns success or failure code.
1233 int tf_get_tcam_entry(struct tf *tfp,
1234 struct tf_get_tcam_entry_parms *parms);
1237 * tf_free_tcam_entry parameter definition
1239 struct tf_free_tcam_entry_parms {
1241 * [in] receive or transmit direction
1245 * [in] TCAM table type
1247 enum tf_tcam_tbl_type tcam_tbl_type;
1249 * [in] Index to free
1253 * [out] reference count after free
1263 * Firmware checks to ensure the TCAM entries are owned by the TruFlow
1264 * session. TCAM entry will be invalidated. All-ones mask.
1267 * WCTCAM profile id of 0 must be used to invalidate an entry.
1269 * Returns success or failure code.
1271 int tf_free_tcam_entry(struct tf *tfp,
1272 struct tf_free_tcam_entry_parms *parms);
1275 * @page table Table Access
1277 * @ref tf_alloc_tbl_entry
1279 * @ref tf_free_tbl_entry
1281 * @ref tf_set_tbl_entry
1283 * @ref tf_get_tbl_entry
1285 * @ref tf_bulk_get_tbl_entry
1289 * tf_alloc_tbl_entry parameter definition
1291 struct tf_search_tbl_entry_parms {
1293 * [in] Receive or transmit direction
1297 * [in] Type of the allocation
1299 enum tf_tbl_type type;
1301 * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1303 uint32_t tbl_scope_id;
1305 * [in] Result data to search for
1309 * [in] Result data size in bytes
1311 uint16_t result_sz_in_bytes;
1313 * [in] Allocate on miss.
1317 * [out] Set if matching entry found
1321 * [out] Search result status (hit, miss, reject)
1323 enum tf_search_status search_status;
1325 * [out] Current ref count after allocation
1329 * [out] Idx of allocated entry or found entry
1335 * search Table Entry (experimental)
1337 * This function searches the shadow copy of an index table for a matching
1338 * entry. The result data must match for hit to be set. Only TruFlow core
1339 * data is accessed. If shadow_copy is not enabled, an error is returned.
1343 * A hash is performed on the result data and mappe3d to a shadow copy entry
1344 * where the result is populated. If the result matches the entry, hit is set,
1345 * ref_cnt is incremented (if alloc), and the search status indicates what
1346 * action the caller can take regarding setting the entry.
1348 * search status should be used as follows:
1349 * - On MISS, the caller should set the result into the returned index.
1351 * - On REJECT, the caller should reject the flow since there are no resources.
1353 * - On Hit, the matching index is returned to the caller. Additionally, the
1354 * ref_cnt is updated.
1356 * Also returns success or failure code.
1358 int tf_search_tbl_entry(struct tf *tfp,
1359 struct tf_search_tbl_entry_parms *parms);
1362 * tf_alloc_tbl_entry parameter definition
1364 struct tf_alloc_tbl_entry_parms {
1366 * [in] Receive or transmit direction
1370 * [in] Type of the allocation
1372 enum tf_tbl_type type;
1374 * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1376 uint32_t tbl_scope_id;
1378 * [in] Enable search for matching entry. If the table type is
1379 * internal the shadow copy will be searched before
1380 * alloc. Session must be configured with shadow copy enabled.
1382 uint8_t search_enable;
1384 * [in] Result data to search for (if search_enable)
1388 * [in] Result data size in bytes (if search_enable)
1390 uint16_t result_sz_in_bytes;
1392 * [out] If search_enable, set if matching entry found
1396 * [out] Current ref count after allocation (if search_enable)
1400 * [out] Idx of allocated entry or found entry (if search_enable)
1406 * allocate index table entries
1410 * Allocate an on chip index table entry or search for a matching
1411 * entry of the indicated type for this TruFlow session.
1413 * Allocates an index table record. This function will attempt to
1414 * allocate an entry or search an index table for a matching entry if
1415 * search is enabled (only the shadow copy of the table is accessed).
1417 * If search is not enabled, the first available free entry is
1418 * returned. If search is enabled and a matching entry to entry_data
1419 * is found hit is set to TRUE and success is returned.
1423 * These are used to allocate inlined action record memory.
1425 * Allocates an external index table action record.
1428 * Implementation of the internals of this function will be a stack with push
1431 * Returns success or failure code.
1433 int tf_alloc_tbl_entry(struct tf *tfp,
1434 struct tf_alloc_tbl_entry_parms *parms);
1437 * tf_free_tbl_entry parameter definition
1439 struct tf_free_tbl_entry_parms {
1441 * [in] Receive or transmit direction
1445 * [in] Type of the allocation type
1447 enum tf_tbl_type type;
1449 * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1451 uint32_t tbl_scope_id;
1453 * [in] Index to free
1457 * [out] Reference count after free, only valid if session has been
1458 * created with shadow_copy.
1464 * free index table entry
1466 * Used to free a previously allocated table entry.
1470 * If session has shadow_copy enabled the shadow DB is searched and if
1471 * found the element ref_cnt is decremented. If ref_cnt goes to
1472 * zero then the element is returned to the session pool.
1474 * If the session does not have a shadow DB the element is free'ed and
1475 * given back to the session pool.
1479 * Free's an external index table action record.
1482 * Implementation of the internals of this function will be a stack with push
1485 * Returns success or failure code.
1487 int tf_free_tbl_entry(struct tf *tfp,
1488 struct tf_free_tbl_entry_parms *parms);
1491 * tf_set_tbl_entry parameter definition
1493 struct tf_set_tbl_entry_parms {
1495 * [in] Table scope identifier
1497 uint32_t tbl_scope_id;
1499 * [in] Receive or transmit direction
1503 * [in] Type of object to set
1505 enum tf_tbl_type type;
1513 uint16_t data_sz_in_bytes;
1515 * [in] Entry index to write to
1521 * set index table entry
1523 * Used to insert an application programmed index table entry into a
1524 * previous allocated table location. A shadow copy of the table
1525 * is maintained (if enabled) (only for internal objects)
1527 * Returns success or failure code.
1529 int tf_set_tbl_entry(struct tf *tfp,
1530 struct tf_set_tbl_entry_parms *parms);
1533 * tf_get_tbl_entry parameter definition
1535 struct tf_get_tbl_entry_parms {
1537 * [in] Receive or transmit direction
1541 * [in] Type of object to get
1543 enum tf_tbl_type type;
1551 uint16_t data_sz_in_bytes;
1553 * [in] Entry index to read
1559 * get index table entry
1561 * Used to retrieve a previous set index table entry.
1563 * Reads and compares with the shadow table copy (if enabled) (only
1564 * for internal objects).
1566 * Returns success or failure code. Failure will be returned if the
1567 * provided data buffer is too small for the data type requested.
1569 int tf_get_tbl_entry(struct tf *tfp,
1570 struct tf_get_tbl_entry_parms *parms);
1573 * tf_bulk_get_tbl_entry parameter definition
1575 struct tf_bulk_get_tbl_entry_parms {
1577 * [in] Receive or transmit direction
1581 * [in] Type of object to get
1583 enum tf_tbl_type type;
1585 * [in] Starting index to read from
1587 uint32_t starting_idx;
1589 * [in] Number of sequential entries
1591 uint16_t num_entries;
1593 * [in] Size of the single entry
1595 uint16_t entry_sz_in_bytes;
1597 * [out] Host physical address, where the data
1598 * will be copied to by the firmware.
1599 * Use tfp_calloc() API and mem_pa
1600 * variable of the tfp_calloc_parms
1601 * structure for the physical address.
1603 uint64_t physical_mem_addr;
1607 * Bulk get index table entry
1609 * Used to retrieve a set of index table entries.
1611 * Entries within the range may not have been allocated using
1612 * tf_alloc_tbl_entry() at the time of access. But the range must
1613 * be within the bounds determined from tf_open_session() for the
1614 * given table type. Currently, this is only used for collecting statistics.
1616 * Returns success or failure code. Failure will be returned if the
1617 * provided data buffer is too small for the data type requested.
1619 int tf_bulk_get_tbl_entry(struct tf *tfp,
1620 struct tf_bulk_get_tbl_entry_parms *parms);
1623 * @page exact_match Exact Match Table
1625 * @ref tf_insert_em_entry
1627 * @ref tf_delete_em_entry
1629 * @ref tf_search_em_entry
1633 * tf_insert_em_entry parameter definition
1635 struct tf_insert_em_entry_parms {
1637 * [in] receive or transmit direction
1641 * [in] internal or external
1645 * [in] ID of table scope to use (external only)
1647 uint32_t tbl_scope_id;
1649 * [in] ID of table interface to use (SR2 only)
1653 * [in] ptr to structure containing key fields
1657 * [in] key bit length
1659 uint16_t key_sz_in_bits;
1661 * [in] ptr to structure containing result field
1665 * [out] result size in bits
1667 uint16_t em_record_sz_in_bits;
1669 * [in] duplicate check flag
1673 * [out] Flow handle value for the inserted entry. This is encoded
1674 * as the entries[4]:bucket[2]:hashId[1]:hash[14]
1676 uint64_t flow_handle;
1678 * [out] Flow id is returned as null (internal)
1679 * Flow id is the GFID value for the inserted entry (external)
1680 * This is the value written to the BD and useful information for mark.
1685 * tf_delete_em_entry parameter definition
1687 struct tf_delete_em_entry_parms {
1689 * [in] receive or transmit direction
1693 * [in] internal or external
1697 * [in] ID of table scope to use (external only)
1699 uint32_t tbl_scope_id;
1701 * [in] ID of table interface to use (SR2 only)
1705 * [in] epoch group IDs of entry to delete
1706 * 2 element array with 2 ids. (SR2 only)
1710 * [out] The index of the entry
1714 * [in] structure containing flow delete handle information
1716 uint64_t flow_handle;
1719 * tf_search_em_entry parameter definition
1721 struct tf_search_em_entry_parms {
1723 * [in] receive or transmit direction
1727 * [in] internal or external
1731 * [in] ID of table scope to use (external only)
1733 uint32_t tbl_scope_id;
1735 * [in] ID of table interface to use (SR2 only)
1739 * [in] ptr to structure containing key fields
1743 * [in] key bit length
1745 uint16_t key_sz_in_bits;
1747 * [in/out] ptr to structure containing EM record fields
1751 * [out] result size in bits
1753 uint16_t em_record_sz_in_bits;
1755 * [in] epoch group IDs of entry to lookup
1756 * 2 element array with 2 ids. (SR2 only)
1760 * [in] ptr to structure containing flow delete handle
1762 uint64_t flow_handle;
1766 * insert em hash entry in internal table memory
1770 * This API inserts an exact match entry into internal EM table memory
1771 * of the specified direction.
1773 * Note: The EM record is managed within the TruFlow core and not the
1776 * Shadow copy of internal record table an association with hash and 1,2, or 4
1777 * associated buckets
1780 * This API inserts an exact match entry into DRAM EM table memory of the
1781 * specified direction and table scope.
1783 * When inserting an entry into an exact match table, the TruFlow library may
1784 * need to allocate a dynamic bucket for the entry (SR2 only).
1786 * The insertion of duplicate entries in an EM table is not permitted. If a
1787 * TruFlow application can guarantee that it will never insert duplicates, it
1788 * can disable duplicate checking by passing a zero value in the dup_check
1789 * parameter to this API. This will optimize performance. Otherwise, the
1790 * TruFlow library will enforce protection against inserting duplicate entries.
1792 * Flow handle is defined in this document:
1794 * https://docs.google.com
1795 * /document/d/1NESu7RpTN3jwxbokaPfYORQyChYRmJgs40wMIRe8_-Q/edit
1797 * Returns success or busy code.
1800 int tf_insert_em_entry(struct tf *tfp,
1801 struct tf_insert_em_entry_parms *parms);
1804 * delete em hash entry table memory
1808 * This API deletes an exact match entry from internal EM table memory of the
1809 * specified direction. If a valid flow ptr is passed in then that takes
1810 * precedence over the pointer to the complete key passed in.
1815 * This API deletes an exact match entry from EM table memory of the specified
1816 * direction and table scope. If a valid flow handle is passed in then that
1817 * takes precedence over the pointer to the complete key passed in.
1819 * The TruFlow library may release a dynamic bucket when an entry is deleted.
1822 * Returns success or not found code
1826 int tf_delete_em_entry(struct tf *tfp,
1827 struct tf_delete_em_entry_parms *parms);
1830 * search em hash entry table memory
1834 * This API looks up an EM entry in table memory with the specified EM
1835 * key or flow (flow takes precedence) and direction.
1837 * The status will be one of: success or entry not found. If the lookup
1838 * succeeds, a pointer to the matching entry and the result record associated
1839 * with the matching entry will be provided.
1841 * If flow_handle is set, search shadow copy.
1843 * Otherwise, query the fw with key to get result.
1847 * This API looks up an EM entry in table memory with the specified EM
1848 * key or flow_handle (flow takes precedence), direction and table scope.
1850 * The status will be one of: success or entry not found. If the lookup
1851 * succeeds, a pointer to the matching entry and the result record associated
1852 * with the matching entry will be provided.
1854 * Returns success or not found code
1857 int tf_search_em_entry(struct tf *tfp,
1858 struct tf_search_em_entry_parms *parms);
1861 * @page global Global Configuration
1863 * @ref tf_set_global_cfg
1865 * @ref tf_get_global_cfg
1868 * Tunnel Encapsulation Offsets
1870 enum tf_tunnel_encap_offsets {
1872 TF_TUNNEL_ENCAP_NAT,
1873 TF_TUNNEL_ENCAP_MPLS,
1874 TF_TUNNEL_ENCAP_VXLAN,
1875 TF_TUNNEL_ENCAP_GENEVE,
1876 TF_TUNNEL_ENCAP_NVGRE,
1877 TF_TUNNEL_ENCAP_GRE,
1878 TF_TUNNEL_ENCAP_FULL_GENERIC
1881 * Global Configuration Table Types
1883 enum tf_global_config_type {
1884 TF_TUNNEL_ENCAP, /**< Tunnel Encap Config(TECT) */
1885 TF_ACTION_BLOCK, /**< Action Block Config(ABCR) */
1886 TF_GLOBAL_CFG_TYPE_MAX
1890 * tf_global_cfg parameter definition
1892 struct tf_global_cfg_parms {
1894 * [in] receive or transmit direction
1898 * [in] Global config type
1900 enum tf_global_config_type type;
1902 * [in] Offset @ the type
1906 * [in/out] Value of the configuration
1907 * set - Read, Modify and Write
1908 * get - Read the full configuration
1912 * [in] struct containing size
1914 uint16_t config_sz_in_bytes;
1918 * Get global configuration
1920 * Retrieve the configuration
1922 * Returns success or failure code.
1924 int tf_get_global_cfg(struct tf *tfp,
1925 struct tf_global_cfg_parms *parms);
1928 * Update the global configuration table
1930 * Read, modify write the value.
1932 * Returns success or failure code.
1934 int tf_set_global_cfg(struct tf *tfp,
1935 struct tf_global_cfg_parms *parms);
1938 * @page if_tbl Interface Table Access
1940 * @ref tf_set_if_tbl_entry
1942 * @ref tf_get_if_tbl_entry
1944 * @ref tf_restore_if_tbl_entry
1947 * Enumeration of TruFlow interface table types.
1949 enum tf_if_tbl_type {
1950 /** Default Profile L2 Context Entry */
1951 TF_IF_TBL_TYPE_PROF_SPIF_DFLT_L2_CTXT,
1952 /** Default Profile TCAM/Lookup Action Record Pointer Table */
1953 TF_IF_TBL_TYPE_PROF_PARIF_DFLT_ACT_REC_PTR,
1954 /** Error Profile TCAM Miss Action Record Pointer Table */
1955 TF_IF_TBL_TYPE_PROF_PARIF_ERR_ACT_REC_PTR,
1956 /** Default Error Profile TCAM Miss Action Record Pointer Table */
1957 TF_IF_TBL_TYPE_LKUP_PARIF_DFLT_ACT_REC_PTR,
1958 /** SR2 Ingress lookup table */
1960 /** SR2 VNIC/SVIF Table */
1961 TF_IF_TBL_TYPE_VNIC_SVIF,
1966 * tf_set_if_tbl_entry parameter definition
1968 struct tf_set_if_tbl_entry_parms {
1970 * [in] Receive or transmit direction
1974 * [in] Type of object to set
1976 enum tf_if_tbl_type type;
1984 uint16_t data_sz_in_bytes;
1986 * [in] Interface to write
1992 * set interface table entry
1994 * Used to set an interface table. This API is used for managing tables indexed
1995 * by SVIF/SPIF/PARIF interfaces. In current implementation only the value is
1997 * Returns success or failure code.
1999 int tf_set_if_tbl_entry(struct tf *tfp,
2000 struct tf_set_if_tbl_entry_parms *parms);
2003 * tf_get_if_tbl_entry parameter definition
2005 struct tf_get_if_tbl_entry_parms {
2007 * [in] Receive or transmit direction
2011 * [in] Type of table to get
2013 enum tf_if_tbl_type type;
2021 uint16_t data_sz_in_bytes;
2023 * [in] Entry index to read
2029 * get interface table entry
2031 * Used to retrieve an interface table entry.
2033 * Reads the interface table entry value
2035 * Returns success or failure code. Failure will be returned if the
2036 * provided data buffer is too small for the data type requested.
2038 int tf_get_if_tbl_entry(struct tf *tfp,
2039 struct tf_get_if_tbl_entry_parms *parms);
2041 #endif /* _TF_CORE_H_ */