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,
167 * The WC profile func is returned from the L2 Ctxt TCAM lookup
168 * to enable virtualization of the profile TCAM.
170 TF_IDENT_TYPE_PROF_FUNC,
172 * The WC profile ID is included in the WC lookup key
173 * to enable virtualization of the WC TCAM hardware.
175 TF_IDENT_TYPE_WC_PROF,
177 * The EM profile ID is included in the EM lookup key
178 * to enable virtualization of the EM hardware. (not required for SR2
179 * as it has table scope)
181 TF_IDENT_TYPE_EM_PROF,
183 * The L2 func is included in the ILT result and from recycling to
184 * enable virtualization of further lookups.
186 TF_IDENT_TYPE_L2_FUNC,
191 * Enumeration of TruFlow table types. A table type is used to identify a
194 * NOTE: The table type TF_TBL_TYPE_EXT is unique in that it is
195 * the only table type that is connected with a table scope.
200 /** Wh+/SR Action Record */
201 TF_TBL_TYPE_FULL_ACT_RECORD,
202 /** Wh+/SR/Th Multicast Groups */
203 TF_TBL_TYPE_MCAST_GROUPS,
204 /** Wh+/SR Action Encap 8 Bytes */
205 TF_TBL_TYPE_ACT_ENCAP_8B,
206 /** Wh+/SR Action Encap 16 Bytes */
207 TF_TBL_TYPE_ACT_ENCAP_16B,
208 /** Action Encap 32 Bytes */
209 TF_TBL_TYPE_ACT_ENCAP_32B,
210 /** Wh+/SR Action Encap 64 Bytes */
211 TF_TBL_TYPE_ACT_ENCAP_64B,
212 /** Action Source Properties SMAC */
213 TF_TBL_TYPE_ACT_SP_SMAC,
214 /** Wh+/SR Action Source Properties SMAC IPv4 */
215 TF_TBL_TYPE_ACT_SP_SMAC_IPV4,
216 /** Action Source Properties SMAC IPv6 */
217 TF_TBL_TYPE_ACT_SP_SMAC_IPV6,
218 /** Wh+/SR Action Statistics 64 Bits */
219 TF_TBL_TYPE_ACT_STATS_64,
220 /** Wh+/SR Action Modify L4 Src Port */
221 TF_TBL_TYPE_ACT_MODIFY_SPORT,
222 /** Wh+/SR Action Modify L4 Dest Port */
223 TF_TBL_TYPE_ACT_MODIFY_DPORT,
224 /** Wh+/SR Action Modify IPv4 Source */
225 TF_TBL_TYPE_ACT_MODIFY_IPV4_SRC,
226 /** Wh+/SR Action _Modify L4 Dest Port */
227 TF_TBL_TYPE_ACT_MODIFY_IPV4_DEST,
228 /** Meter Profiles */
229 TF_TBL_TYPE_METER_PROF,
230 /** Meter Instance */
231 TF_TBL_TYPE_METER_INST,
233 TF_TBL_TYPE_MIRROR_CONFIG,
236 /** SR2 Epoch 0 table */
238 /** SR2 Epoch 1 table */
241 TF_TBL_TYPE_METADATA,
243 TF_TBL_TYPE_CT_STATE,
244 /** SR2 Range Profile */
245 TF_TBL_TYPE_RANGE_PROF,
246 /** SR2 Range Entry */
247 TF_TBL_TYPE_RANGE_ENTRY,
250 /** SR2 VNIC/SVIF Table */
251 TF_TBL_TYPE_VNIC_SVIF,
252 /** Th/SR2 EM Flexible Key builder */
254 /** Th/SR2 WC Flexible Key builder */
260 * External table type - initially 1 poolsize entries.
261 * All External table types are associated with a table
262 * scope. Internal types are not.
271 enum tf_tcam_tbl_type {
272 /** L2 Context TCAM */
273 TF_TCAM_TBL_TYPE_L2_CTXT_TCAM,
275 TF_TCAM_TBL_TYPE_PROF_TCAM,
277 TF_TCAM_TBL_TYPE_WC_TCAM,
278 /** Source Properties TCAM */
279 TF_TCAM_TBL_TYPE_SP_TCAM,
280 /** Connection Tracking Rule TCAM */
281 TF_TCAM_TBL_TYPE_CT_RULE_TCAM,
282 /** Virtual Edge Bridge TCAM */
283 TF_TCAM_TBL_TYPE_VEB_TCAM,
289 * These defines are provisioned during
292 enum tf_em_tbl_type {
293 /** The number of internal EM records for the session */
294 TF_EM_TBL_TYPE_EM_RECORD,
295 /** The number of table scopes reequested */
296 TF_EM_TBL_TYPE_TBL_SCOPE,
301 * TruFlow Session Information
303 * Structure defining a TruFlow Session, also known as a Management
304 * session. This structure is initialized at time of
305 * tf_open_session(). It is passed to all of the TruFlow APIs as way
306 * to prescribe and isolate resources between different TruFlow ULP
309 * Ownership of the elements is split between ULP and TruFlow. Please
310 * see the individual elements.
312 struct tf_session_info {
314 * TrueFlow Version. Used to control the structure layout when
315 * sharing sessions. No guarantee that a secondary process
316 * would come from the same version of an executable.
317 * TruFlow initializes this variable on tf_open_session().
322 struct tf_session_version ver;
324 * will be STAILQ_ENTRY(tf_session_info) next
331 * Session ID is a unique identifier for the session. TruFlow
332 * initializes this variable during tf_open_session()
336 * Access: Truflow & ULP
338 union tf_session_id session_id;
340 * Protects access to core_data. Lock is initialized and owned
341 * by ULP. TruFlow can access the core_data without checking
349 * The core_data holds the TruFlow tf_session data
350 * structure. This memory is allocated and owned by TruFlow on
353 * TruFlow uses this memory for session management control
354 * until the session is closed by ULP. Access control is done
355 * by the spin_lock which ULP controls ahead of TruFlow API
358 * Please see tf_open_session_parms for specification details
366 * The core_data_sz_bytes specifies the size of core_data in
369 * The size is set by TruFlow on tf_open_session().
371 * Please see tf_open_session_parms for specification details
377 uint32_t core_data_sz_bytes;
383 * Contains a pointer to the session info. Allocated by ULP and passed
384 * to TruFlow using tf_open_session(). TruFlow will populate the
385 * session info at that time. A TruFlow Session can be used by more
386 * than one PF/VF by using the tf_open_session().
388 * It is expected that ULP allocates this memory as shared memory.
390 * NOTE: This struct must be within the BNXT PMD struct bnxt
391 * (bp). This allows use of container_of() to get access to the PMD.
394 struct tf_session_info *session;
398 * Identifier resource definition
400 struct tf_identifier_resources {
402 * Array of TF Identifiers where each entry is expected to be
403 * set to the requested resource number of that specific type.
404 * The index used is tf_identifier_type.
406 uint16_t cnt[TF_IDENT_TYPE_MAX];
410 * Table type resource definition
412 struct tf_tbl_resources {
414 * Array of TF Table types where each entry is expected to be
415 * set to the requeste resource number of that specific
416 * type. The index used is tf_tbl_type.
418 uint16_t cnt[TF_TBL_TYPE_MAX];
422 * TCAM type resource definition
424 struct tf_tcam_resources {
426 * Array of TF TCAM types where each entry is expected to be
427 * set to the requested resource number of that specific
428 * type. The index used is tf_tcam_tbl_type.
430 uint16_t cnt[TF_TCAM_TBL_TYPE_MAX];
434 * EM type resource definition
436 struct tf_em_resources {
438 * Array of TF EM table types where each entry is expected to
439 * be set to the requested resource number of that specific
440 * type. The index used is tf_em_tbl_type.
442 uint16_t cnt[TF_EM_TBL_TYPE_MAX];
446 * tf_session_resources parameter definition.
448 struct tf_session_resources {
450 * [in] Requested Identifier Resources
452 * Number of identifier resources requested for the
455 struct tf_identifier_resources ident_cnt[TF_DIR_MAX];
457 * [in] Requested Index Table resource counts
459 * The number of index table resources requested for the
462 struct tf_tbl_resources tbl_cnt[TF_DIR_MAX];
464 * [in] Requested TCAM Table resource counts
466 * The number of TCAM table resources requested for the
470 struct tf_tcam_resources tcam_cnt[TF_DIR_MAX];
472 * [in] Requested EM resource counts
474 * The number of internal EM table resources requested for the
477 struct tf_em_resources em_cnt[TF_DIR_MAX];
481 * tf_open_session parameters definition.
483 struct tf_open_session_parms {
485 * [in] ctrl_chan_name
487 * String containing name of control channel interface to be
488 * used for this session to communicate with firmware.
490 * The ctrl_chan_name can be looked up by using
491 * rte_eth_dev_get_name_by_port() within the ULP.
493 * ctrl_chan_name will be used as part of a name for any
494 * shared memory allocation.
496 char ctrl_chan_name[TF_SESSION_NAME_MAX];
500 * Boolean controlling the use and availability of shadow
501 * copy. Shadow copy will allow the TruFlow to keep track of
502 * resource content on the firmware side without having to
503 * query firmware. Additional private session core_data will
504 * be allocated if this boolean is set to 'true', default
507 * Size of memory depends on the NVM Resource settings for the
512 * [in/out] session_id
514 * Session_id is unique per session.
516 * Session_id is composed of domain, bus, device and
517 * fw_session_id. The construction is done by parsing the
518 * ctrl_chan_name together with allocation of a fw_session_id.
520 * The session_id allows a session to be shared between devices.
522 union tf_session_id session_id;
524 * [in/out] session_client_id
526 * Session_client_id is unique per client.
528 * Session_client_id is composed of session_id and the
529 * fw_session_client_id fw_session_id. The construction is
530 * done by parsing the ctrl_chan_name together with allocation
531 * of a fw_session_client_id during tf_open_session().
533 * A reference count will be incremented in the session on
534 * which a client is created.
536 * A session can first be closed if there is one Session
537 * Client left. Session Clients should closed using
538 * tf_close_session().
540 union tf_session_client_id session_client_id;
544 * Device type for the session.
546 enum tf_device_type device_type;
550 * Resource allocation for the session.
552 struct tf_session_resources resources;
556 * Opens a new TruFlow Session or session client.
558 * What gets created depends on the passed in tfp content. If the tfp
559 * does not have prior session data a new session with associated
560 * session client. If tfp has a session already a session client will
561 * be created. In both cases the session client is created using the
562 * provided ctrl_chan_name.
564 * In case of session creation TruFlow will allocate session specific
565 * memory, shared memory, to hold its session data. This data is
566 * private to TruFlow.
568 * No other TruFlow APIs will succeed unless this API is first called
571 * tf_open_session() returns a session id and session client id that
572 * is used on all other TF APIs.
574 * A Session or session client can be closed using tf_close_session().
577 * Pointer to TF handle
580 * Pointer to open parameters
583 * - (0) if successful.
584 * - (-EINVAL) on failure.
586 int tf_open_session(struct tf *tfp,
587 struct tf_open_session_parms *parms);
592 * tf_attach_session parameters definition.
594 struct tf_attach_session_parms {
596 * [in] ctrl_chan_name
598 * String containing name of control channel interface to be
599 * used for this session to communicate with firmware.
601 * The ctrl_chan_name can be looked up by using
602 * rte_eth_dev_get_name_by_port() within the ULP.
604 * ctrl_chan_name will be used as part of a name for any
605 * shared memory allocation.
607 char ctrl_chan_name[TF_SESSION_NAME_MAX];
610 * [in] attach_chan_name
612 * String containing name of attach channel interface to be
613 * used for this session.
615 * The attach_chan_name must be given to a 2nd process after
616 * the primary process has been created. This is the
617 * ctrl_chan_name of the primary process and is used to find
618 * the shared memory for the session that the attach is going
621 char attach_chan_name[TF_SESSION_NAME_MAX];
626 * Session_id is unique per session. For Attach the session_id
627 * should be the session_id that was returned on the first
630 * Session_id is composed of domain, bus, device and
631 * fw_session_id. The construction is done by parsing the
632 * ctrl_chan_name together with allocation of a fw_session_id
633 * during tf_open_session().
635 * A reference count will be incremented on attach. A session
636 * is first fully closed when reference count is zero by
637 * calling tf_close_session().
639 union tf_session_id session_id;
645 * Allows a 2nd application instance to attach to an existing
646 * session. Used when a session is to be shared between two processes.
648 * Attach will increment a ref count as to manage the shared session data.
651 * Pointer to TF handle
654 * Pointer to attach parameters
657 * - (0) if successful.
658 * - (-EINVAL) on failure.
660 int tf_attach_session(struct tf *tfp,
661 struct tf_attach_session_parms *parms);
664 * Closes an existing session client or the session it self. The
665 * session client is default closed and if the session reference count
666 * is 0 then the session is closed as well.
668 * On session close all hardware and firmware state associated with
669 * the TruFlow application is cleaned up.
671 * The session client is extracted from the tfp. Thus tf_close_session()
672 * cannot close a session client on behalf of another function.
674 * Returns success or failure code.
676 int tf_close_session(struct tf *tfp);
679 * @page ident Identity Management
681 * @ref tf_alloc_identifier
683 * @ref tf_free_identifier
686 * tf_alloc_identifier parameter definition
688 struct tf_alloc_identifier_parms {
690 * [in] receive or transmit direction
694 * [in] Identifier type
696 enum tf_identifier_type ident_type;
698 * [out] Identifier allocated
704 * tf_free_identifier parameter definition
706 struct tf_free_identifier_parms {
708 * [in] receive or transmit direction
712 * [in] Identifier type
714 enum tf_identifier_type ident_type;
722 * allocate identifier resource
724 * TruFlow core will allocate a free id from the per identifier resource type
725 * pool reserved for the session during tf_open(). No firmware is involved.
727 * Returns success or failure code.
729 int tf_alloc_identifier(struct tf *tfp,
730 struct tf_alloc_identifier_parms *parms);
733 * free identifier resource
735 * TruFlow core will return an id back to the per identifier resource type pool
736 * reserved for the session. No firmware is involved. During tf_close, the
737 * complete pool is returned to the firmware.
739 * Returns success or failure code.
741 int tf_free_identifier(struct tf *tfp,
742 struct tf_free_identifier_parms *parms);
745 * @page dram_table DRAM Table Scope Interface
747 * @ref tf_alloc_tbl_scope
749 * @ref tf_free_tbl_scope
751 * If we allocate the EEM memory from the core, we need to store it in
752 * the shared session data structure to make sure it can be freed later.
753 * (for example if the PF goes away)
755 * Current thought is that memory is allocated within core.
760 * tf_alloc_tbl_scope_parms definition
762 struct tf_alloc_tbl_scope_parms {
764 * [in] All Maximum key size required.
766 uint16_t rx_max_key_sz_in_bits;
768 * [in] Maximum Action size required (includes inlined items)
770 uint16_t rx_max_action_entry_sz_in_bits;
772 * [in] Memory size in Megabytes
773 * Total memory size allocated by user to be divided
774 * up for actions, hash, counters. Only inline external actions.
775 * Use this variable or the number of flows, do not set both.
777 uint32_t rx_mem_size_in_mb;
779 * [in] Number of flows * 1000. If set, rx_mem_size_in_mb must equal 0.
781 uint32_t rx_num_flows_in_k;
783 * [in] SR2 only receive table access interface id
785 uint32_t rx_tbl_if_id;
787 * [in] All Maximum key size required.
789 uint16_t tx_max_key_sz_in_bits;
791 * [in] Maximum Action size required (includes inlined items)
793 uint16_t tx_max_action_entry_sz_in_bits;
795 * [in] Memory size in Megabytes
796 * Total memory size allocated by user to be divided
797 * up for actions, hash, counters. Only inline external actions.
799 uint32_t tx_mem_size_in_mb;
801 * [in] Number of flows * 1000
803 uint32_t tx_num_flows_in_k;
805 * [in] SR2 only receive table access interface id
807 uint32_t tx_tbl_if_id;
809 * [in] Flush pending HW cached flows every 1/10th of value
810 * set in seconds, both idle and active flows are flushed
811 * from the HW cache. If set to 0, this feature will be disabled.
813 uint8_t hw_flow_cache_flush_timer;
815 * [out] table scope identifier
817 uint32_t tbl_scope_id;
820 struct tf_free_tbl_scope_parms {
822 * [in] table scope identifier
824 uint32_t tbl_scope_id;
828 * allocate a table scope
830 * On SR2 Firmware will allocate a scope ID. On other devices, the scope
831 * is a software construct to identify an EEM table. This function will
832 * divide the hash memory/buckets and records according to the device
833 * device constraints based upon calculations using either the number of flows
834 * requested or the size of memory indicated. Other parameters passed in
835 * determine the configuration (maximum key size, maximum external action record
838 * This API will allocate the table region in
839 * DRAM, program the PTU page table entries, and program the number of static
840 * buckets (if SR2) in the RX and TX CFAs. Buckets are assumed to start at
841 * 0 in the EM memory for the scope. Upon successful completion of this API,
842 * hash tables are fully initialized and ready for entries to be inserted.
844 * A single API is used to allocate a common table scope identifier in both
845 * receive and transmit CFA. The scope identifier is common due to nature of
846 * connection tracking sending notifications between RX and TX direction.
848 * The receive and transmit table access identifiers specify which rings will
849 * be used to initialize table DRAM. The application must ensure mutual
850 * exclusivity of ring usage for table scope allocation and any table update
853 * The hash table buckets, EM keys, and EM lookup results are stored in the
854 * memory allocated based on the rx_em_hash_mb/tx_em_hash_mb parameters. The
855 * hash table buckets are stored at the beginning of that memory.
857 * NOTE: No EM internal setup is done here. On chip EM records are managed
858 * internally by TruFlow core.
860 * Returns success or failure code.
862 int tf_alloc_tbl_scope(struct tf *tfp,
863 struct tf_alloc_tbl_scope_parms *parms);
869 * Firmware checks that the table scope ID is owned by the TruFlow
870 * session, verifies that no references to this table scope remains
871 * (SR2 ILT) or Profile TCAM entries for either CFA (RX/TX) direction,
872 * then frees the table scope ID.
874 * Returns success or failure code.
876 int tf_free_tbl_scope(struct tf *tfp,
877 struct tf_free_tbl_scope_parms *parms);
880 * @page tcam TCAM Access
882 * @ref tf_alloc_tcam_entry
884 * @ref tf_set_tcam_entry
886 * @ref tf_get_tcam_entry
888 * @ref tf_free_tcam_entry
893 * tf_alloc_tcam_entry parameter definition
895 struct tf_alloc_tcam_entry_parms {
897 * [in] receive or transmit direction
901 * [in] TCAM table type
903 enum tf_tcam_tbl_type tcam_tbl_type;
905 * [in] Enable search for matching entry
907 uint8_t search_enable;
909 * [in] Key data to match on (if search)
913 * [in] key size in bits (if search)
915 uint16_t key_sz_in_bits;
917 * [in] Mask data to match on (if search)
921 * [in] Priority of entry requested (definition TBD)
925 * [out] If search, set if matching entry found
929 * [out] Current refcnt after allocation
933 * [out] Idx allocated
940 * allocate TCAM entry
942 * Allocate a TCAM entry - one of these types:
949 * This function allocates a TCAM table record. This function
950 * will attempt to allocate a TCAM table entry from the session
951 * owned TCAM entries or search a shadow copy of the TCAM table for a
952 * matching entry if search is enabled. Key, mask and result must match for
953 * hit to be set. Only TruFlow core data is accessed.
954 * A hash table to entry mapping is maintained for search purposes. If
955 * search is not enabled, the first available free entry is returned based
956 * on priority and alloc_cnt is set to 1. If search is enabled and a matching
957 * entry to entry_data is found, hit is set to TRUE and alloc_cnt is set to 1.
958 * RefCnt is also returned.
960 * Also returns success or failure code.
962 int tf_alloc_tcam_entry(struct tf *tfp,
963 struct tf_alloc_tcam_entry_parms *parms);
966 * tf_set_tcam_entry parameter definition
968 struct tf_set_tcam_entry_parms {
970 * [in] receive or transmit direction
974 * [in] TCAM table type
976 enum tf_tcam_tbl_type tcam_tbl_type;
978 * [in] base index of the entry to program
982 * [in] struct containing key
986 * [in] struct containing mask fields
990 * [in] key size in bits (if search)
992 uint16_t key_sz_in_bits;
994 * [in] struct containing result
998 * [in] struct containing result size in bits
1000 uint16_t result_sz_in_bits;
1006 * Program a TCAM table entry for a TruFlow session.
1008 * If the entry has not been allocated, an error will be returned.
1010 * Returns success or failure code.
1012 int tf_set_tcam_entry(struct tf *tfp,
1013 struct tf_set_tcam_entry_parms *parms);
1016 * tf_get_tcam_entry parameter definition
1018 struct tf_get_tcam_entry_parms {
1020 * [in] receive or transmit direction
1024 * [in] TCAM table type
1026 enum tf_tcam_tbl_type tcam_tbl_type;
1028 * [in] index of the entry to get
1032 * [out] struct containing key
1036 * [out] struct containing mask fields
1040 * [out] key size in bits
1042 uint16_t key_sz_in_bits;
1044 * [out] struct containing result
1048 * [out] struct containing result size in bits
1050 uint16_t result_sz_in_bits;
1056 * Program a TCAM table entry for a TruFlow session.
1058 * If the entry has not been allocated, an error will be returned.
1060 * Returns success or failure code.
1062 int tf_get_tcam_entry(struct tf *tfp,
1063 struct tf_get_tcam_entry_parms *parms);
1066 * tf_free_tcam_entry parameter definition
1068 struct tf_free_tcam_entry_parms {
1070 * [in] receive or transmit direction
1074 * [in] TCAM table type
1076 enum tf_tcam_tbl_type tcam_tbl_type;
1078 * [in] Index to free
1082 * [out] reference count after free
1092 * Firmware checks to ensure the TCAM entries are owned by the TruFlow
1093 * session. TCAM entry will be invalidated. All-ones mask.
1096 * WCTCAM profile id of 0 must be used to invalidate an entry.
1098 * Returns success or failure code.
1100 int tf_free_tcam_entry(struct tf *tfp,
1101 struct tf_free_tcam_entry_parms *parms);
1104 * @page table Table Access
1106 * @ref tf_alloc_tbl_entry
1108 * @ref tf_free_tbl_entry
1110 * @ref tf_set_tbl_entry
1112 * @ref tf_get_tbl_entry
1114 * @ref tf_bulk_get_tbl_entry
1118 * tf_alloc_tbl_entry parameter definition
1120 struct tf_alloc_tbl_entry_parms {
1122 * [in] Receive or transmit direction
1126 * [in] Type of the allocation
1128 enum tf_tbl_type type;
1130 * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1132 uint32_t tbl_scope_id;
1134 * [in] Enable search for matching entry. If the table type is
1135 * internal the shadow copy will be searched before
1136 * alloc. Session must be configured with shadow copy enabled.
1138 uint8_t search_enable;
1140 * [in] Result data to search for (if search_enable)
1144 * [in] Result data size in bytes (if search_enable)
1146 uint16_t result_sz_in_bytes;
1148 * [out] If search_enable, set if matching entry found
1152 * [out] Current ref count after allocation (if search_enable)
1156 * [out] Idx of allocated entry or found entry (if search_enable)
1162 * allocate index table entries
1166 * Allocate an on chip index table entry or search for a matching
1167 * entry of the indicated type for this TruFlow session.
1169 * Allocates an index table record. This function will attempt to
1170 * allocate an entry or search an index table for a matching entry if
1171 * search is enabled (only the shadow copy of the table is accessed).
1173 * If search is not enabled, the first available free entry is
1174 * returned. If search is enabled and a matching entry to entry_data
1175 * is found hit is set to TRUE and success is returned.
1179 * These are used to allocate inlined action record memory.
1181 * Allocates an external index table action record.
1184 * Implementation of the internals of this function will be a stack with push
1187 * Returns success or failure code.
1189 int tf_alloc_tbl_entry(struct tf *tfp,
1190 struct tf_alloc_tbl_entry_parms *parms);
1193 * tf_free_tbl_entry parameter definition
1195 struct tf_free_tbl_entry_parms {
1197 * [in] Receive or transmit direction
1201 * [in] Type of the allocation type
1203 enum tf_tbl_type type;
1205 * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1207 uint32_t tbl_scope_id;
1209 * [in] Index to free
1213 * [out] Reference count after free, only valid if session has been
1214 * created with shadow_copy.
1220 * free index table entry
1222 * Used to free a previously allocated table entry.
1226 * If session has shadow_copy enabled the shadow DB is searched and if
1227 * found the element ref_cnt is decremented. If ref_cnt goes to
1228 * zero then the element is returned to the session pool.
1230 * If the session does not have a shadow DB the element is free'ed and
1231 * given back to the session pool.
1235 * Free's an external index table action record.
1238 * Implementation of the internals of this function will be a stack with push
1241 * Returns success or failure code.
1243 int tf_free_tbl_entry(struct tf *tfp,
1244 struct tf_free_tbl_entry_parms *parms);
1247 * tf_set_tbl_entry parameter definition
1249 struct tf_set_tbl_entry_parms {
1251 * [in] Table scope identifier
1253 uint32_t tbl_scope_id;
1255 * [in] Receive or transmit direction
1259 * [in] Type of object to set
1261 enum tf_tbl_type type;
1269 uint16_t data_sz_in_bytes;
1271 * [in] Entry index to write to
1277 * set index table entry
1279 * Used to insert an application programmed index table entry into a
1280 * previous allocated table location. A shadow copy of the table
1281 * is maintained (if enabled) (only for internal objects)
1283 * Returns success or failure code.
1285 int tf_set_tbl_entry(struct tf *tfp,
1286 struct tf_set_tbl_entry_parms *parms);
1289 * tf_get_tbl_entry parameter definition
1291 struct tf_get_tbl_entry_parms {
1293 * [in] Receive or transmit direction
1297 * [in] Type of object to get
1299 enum tf_tbl_type type;
1307 uint16_t data_sz_in_bytes;
1309 * [in] Entry index to read
1315 * get index table entry
1317 * Used to retrieve a previous set index table entry.
1319 * Reads and compares with the shadow table copy (if enabled) (only
1320 * for internal objects).
1322 * Returns success or failure code. Failure will be returned if the
1323 * provided data buffer is too small for the data type requested.
1325 int tf_get_tbl_entry(struct tf *tfp,
1326 struct tf_get_tbl_entry_parms *parms);
1329 * tf_bulk_get_tbl_entry parameter definition
1331 struct tf_bulk_get_tbl_entry_parms {
1333 * [in] Receive or transmit direction
1337 * [in] Type of object to get
1339 enum tf_tbl_type type;
1341 * [in] Starting index to read from
1343 uint32_t starting_idx;
1345 * [in] Number of sequential entries
1347 uint16_t num_entries;
1349 * [in] Size of the single entry
1351 uint16_t entry_sz_in_bytes;
1353 * [out] Host physical address, where the data
1354 * will be copied to by the firmware.
1355 * Use tfp_calloc() API and mem_pa
1356 * variable of the tfp_calloc_parms
1357 * structure for the physical address.
1359 uint64_t physical_mem_addr;
1363 * Bulk get index table entry
1365 * Used to retrieve a previous set index table entry.
1367 * Reads and compares with the shadow table copy (if enabled) (only
1368 * for internal objects).
1370 * Returns success or failure code. Failure will be returned if the
1371 * provided data buffer is too small for the data type requested.
1373 int tf_bulk_get_tbl_entry(struct tf *tfp,
1374 struct tf_bulk_get_tbl_entry_parms *parms);
1377 * @page exact_match Exact Match Table
1379 * @ref tf_insert_em_entry
1381 * @ref tf_delete_em_entry
1383 * @ref tf_search_em_entry
1387 * tf_insert_em_entry parameter definition
1389 struct tf_insert_em_entry_parms {
1391 * [in] receive or transmit direction
1395 * [in] internal or external
1399 * [in] ID of table scope to use (external only)
1401 uint32_t tbl_scope_id;
1403 * [in] ID of table interface to use (SR2 only)
1407 * [in] ptr to structure containing key fields
1411 * [in] key bit length
1413 uint16_t key_sz_in_bits;
1415 * [in] ptr to structure containing result field
1419 * [out] result size in bits
1421 uint16_t em_record_sz_in_bits;
1423 * [in] duplicate check flag
1427 * [out] Flow handle value for the inserted entry. This is encoded
1428 * as the entries[4]:bucket[2]:hashId[1]:hash[14]
1430 uint64_t flow_handle;
1432 * [out] Flow id is returned as null (internal)
1433 * Flow id is the GFID value for the inserted entry (external)
1434 * This is the value written to the BD and useful information for mark.
1439 * tf_delete_em_entry parameter definition
1441 struct tf_delete_em_entry_parms {
1443 * [in] receive or transmit direction
1447 * [in] internal or external
1451 * [in] ID of table scope to use (external only)
1453 uint32_t tbl_scope_id;
1455 * [in] ID of table interface to use (SR2 only)
1459 * [in] epoch group IDs of entry to delete
1460 * 2 element array with 2 ids. (SR2 only)
1464 * [out] The index of the entry
1468 * [in] structure containing flow delete handle information
1470 uint64_t flow_handle;
1473 * tf_search_em_entry parameter definition
1475 struct tf_search_em_entry_parms {
1477 * [in] receive or transmit direction
1481 * [in] internal or external
1485 * [in] ID of table scope to use (external only)
1487 uint32_t tbl_scope_id;
1489 * [in] ID of table interface to use (SR2 only)
1493 * [in] ptr to structure containing key fields
1497 * [in] key bit length
1499 uint16_t key_sz_in_bits;
1501 * [in/out] ptr to structure containing EM record fields
1505 * [out] result size in bits
1507 uint16_t em_record_sz_in_bits;
1509 * [in] epoch group IDs of entry to lookup
1510 * 2 element array with 2 ids. (SR2 only)
1514 * [in] ptr to structure containing flow delete handle
1516 uint64_t flow_handle;
1520 * insert em hash entry in internal table memory
1524 * This API inserts an exact match entry into internal EM table memory
1525 * of the specified direction.
1527 * Note: The EM record is managed within the TruFlow core and not the
1530 * Shadow copy of internal record table an association with hash and 1,2, or 4
1531 * associated buckets
1534 * This API inserts an exact match entry into DRAM EM table memory of the
1535 * specified direction and table scope.
1537 * When inserting an entry into an exact match table, the TruFlow library may
1538 * need to allocate a dynamic bucket for the entry (SR2 only).
1540 * The insertion of duplicate entries in an EM table is not permitted. If a
1541 * TruFlow application can guarantee that it will never insert duplicates, it
1542 * can disable duplicate checking by passing a zero value in the dup_check
1543 * parameter to this API. This will optimize performance. Otherwise, the
1544 * TruFlow library will enforce protection against inserting duplicate entries.
1546 * Flow handle is defined in this document:
1548 * https://docs.google.com
1549 * /document/d/1NESu7RpTN3jwxbokaPfYORQyChYRmJgs40wMIRe8_-Q/edit
1551 * Returns success or busy code.
1554 int tf_insert_em_entry(struct tf *tfp,
1555 struct tf_insert_em_entry_parms *parms);
1558 * delete em hash entry table memory
1562 * This API deletes an exact match entry from internal EM table memory of the
1563 * specified direction. If a valid flow ptr is passed in then that takes
1564 * precedence over the pointer to the complete key passed in.
1569 * This API deletes an exact match entry from EM table memory of the specified
1570 * direction and table scope. If a valid flow handle is passed in then that
1571 * takes precedence over the pointer to the complete key passed in.
1573 * The TruFlow library may release a dynamic bucket when an entry is deleted.
1576 * Returns success or not found code
1580 int tf_delete_em_entry(struct tf *tfp,
1581 struct tf_delete_em_entry_parms *parms);
1584 * search em hash entry table memory
1588 * This API looks up an EM entry in table memory with the specified EM
1589 * key or flow (flow takes precedence) and direction.
1591 * The status will be one of: success or entry not found. If the lookup
1592 * succeeds, a pointer to the matching entry and the result record associated
1593 * with the matching entry will be provided.
1595 * If flow_handle is set, search shadow copy.
1597 * Otherwise, query the fw with key to get result.
1601 * This API looks up an EM entry in table memory with the specified EM
1602 * key or flow_handle (flow takes precedence), direction and table scope.
1604 * The status will be one of: success or entry not found. If the lookup
1605 * succeeds, a pointer to the matching entry and the result record associated
1606 * with the matching entry will be provided.
1608 * Returns success or not found code
1611 int tf_search_em_entry(struct tf *tfp,
1612 struct tf_search_em_entry_parms *parms);
1615 * @page global Global Configuration
1617 * @ref tf_set_global_cfg
1619 * @ref tf_get_global_cfg
1622 * Tunnel Encapsulation Offsets
1624 enum tf_tunnel_encap_offsets {
1626 TF_TUNNEL_ENCAP_NAT,
1627 TF_TUNNEL_ENCAP_MPLS,
1628 TF_TUNNEL_ENCAP_VXLAN,
1629 TF_TUNNEL_ENCAP_GENEVE,
1630 TF_TUNNEL_ENCAP_NVGRE,
1631 TF_TUNNEL_ENCAP_GRE,
1632 TF_TUNNEL_ENCAP_FULL_GENERIC
1635 * Global Configuration Table Types
1637 enum tf_global_config_type {
1638 TF_TUNNEL_ENCAP, /**< Tunnel Encap Config(TECT) */
1639 TF_ACTION_BLOCK, /**< Action Block Config(ABCR) */
1640 TF_GLOBAL_CFG_TYPE_MAX
1644 * tf_global_cfg parameter definition
1646 struct tf_global_cfg_parms {
1648 * [in] receive or transmit direction
1652 * [in] Global config type
1654 enum tf_global_config_type type;
1656 * [in] Offset @ the type
1660 * [in/out] Value of the configuration
1661 * set - Read, Modify and Write
1662 * get - Read the full configuration
1666 * [in] struct containing size
1668 uint16_t config_sz_in_bytes;
1672 * Get global configuration
1674 * Retrieve the configuration
1676 * Returns success or failure code.
1678 int tf_get_global_cfg(struct tf *tfp,
1679 struct tf_global_cfg_parms *parms);
1682 * Update the global configuration table
1684 * Read, modify write the value.
1686 * Returns success or failure code.
1688 int tf_set_global_cfg(struct tf *tfp,
1689 struct tf_global_cfg_parms *parms);
1692 * @page if_tbl Interface Table Access
1694 * @ref tf_set_if_tbl_entry
1696 * @ref tf_get_if_tbl_entry
1698 * @ref tf_restore_if_tbl_entry
1701 * Enumeration of TruFlow interface table types.
1703 enum tf_if_tbl_type {
1704 /** Default Profile L2 Context Entry */
1705 TF_IF_TBL_TYPE_PROF_SPIF_DFLT_L2_CTXT,
1706 /** Default Profile TCAM/Lookup Action Record Pointer Table */
1707 TF_IF_TBL_TYPE_PROF_PARIF_DFLT_ACT_REC_PTR,
1708 /** Error Profile TCAM Miss Action Record Pointer Table */
1709 TF_IF_TBL_TYPE_PROF_PARIF_ERR_ACT_REC_PTR,
1710 /** Default Error Profile TCAM Miss Action Record Pointer Table */
1711 TF_IF_TBL_TYPE_LKUP_PARIF_DFLT_ACT_REC_PTR,
1712 /** SR2 Ingress lookup table */
1714 /** SR2 VNIC/SVIF Table */
1715 TF_IF_TBL_TYPE_VNIC_SVIF,
1720 * tf_set_if_tbl_entry parameter definition
1722 struct tf_set_if_tbl_entry_parms {
1724 * [in] Receive or transmit direction
1728 * [in] Type of object to set
1730 enum tf_if_tbl_type type;
1738 uint16_t data_sz_in_bytes;
1740 * [in] Interface to write
1746 * set interface table entry
1748 * Used to set an interface table. This API is used for managing tables indexed
1749 * by SVIF/SPIF/PARIF interfaces. In current implementation only the value is
1751 * Returns success or failure code.
1753 int tf_set_if_tbl_entry(struct tf *tfp,
1754 struct tf_set_if_tbl_entry_parms *parms);
1757 * tf_get_if_tbl_entry parameter definition
1759 struct tf_get_if_tbl_entry_parms {
1761 * [in] Receive or transmit direction
1765 * [in] Type of table to get
1767 enum tf_if_tbl_type type;
1775 uint16_t data_sz_in_bytes;
1777 * [in] Entry index to read
1783 * get interface table entry
1785 * Used to retrieve an interface table entry.
1787 * Reads the interface table entry value
1789 * Returns success or failure code. Failure will be returned if the
1790 * provided data buffer is too small for the data type requested.
1792 int tf_get_if_tbl_entry(struct tf *tfp,
1793 struct tf_get_if_tbl_entry_parms *parms);
1795 #endif /* _TF_CORE_H_ */