net/bnxt: support Thor WC TCAM
[dpdk.git] / drivers / net / bnxt / tf_core / tf_core.h
index bb456bb..fcba492 100644 (file)
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2019-2020 Broadcom
+ * Copyright(c) 2019-2021 Broadcom
  * All rights reserved.
  */
 
@@ -10,7 +10,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <stdio.h>
-#include "hcapi/hcapi_cfa.h"
+#include "hcapi/cfa/hcapi_cfa_defs.h"
 #include "tf_project.h"
 
 /**
@@ -72,7 +72,6 @@ enum tf_mem {
  * @ref tf_close_session
  */
 
-
 /**
  * Session Version defines
  *
@@ -113,6 +112,21 @@ union tf_session_id {
        } internal;
 };
 
+/**
+ * Session Client Identifier
+ *
+ * Unique identifier for a client within a session. Session Client ID
+ * is constructed from the passed in session and a firmware allocated
+ * fw_session_client_id. Done by TruFlow on tf_open_session().
+ */
+union tf_session_client_id {
+       uint16_t id;
+       struct {
+               uint8_t fw_session_id;
+               uint8_t fw_session_client_id;
+       } internal;
+};
+
 /**
  * Session Version
  *
@@ -139,33 +153,69 @@ enum tf_device_type {
        TF_DEVICE_TYPE_MAX     /**< Maximum   */
 };
 
+/**
+ * Module types
+ */
+enum tf_module_type {
+       /**
+        * Identifier module
+        */
+       TF_MODULE_TYPE_IDENTIFIER,
+       /**
+        * Table type module
+        */
+       TF_MODULE_TYPE_TABLE,
+       /**
+        * TCAM module
+        */
+       TF_MODULE_TYPE_TCAM,
+       /**
+        * EM module
+        */
+       TF_MODULE_TYPE_EM,
+       TF_MODULE_TYPE_MAX
+};
+
+
 /**
  * Identifier resource types
  */
 enum tf_identifier_type {
        /**
+        *  WH/SR/TH/SR2
+        *  The L2 Context is returned from the L2 Ctxt TCAM lookup
+        *  and can be used in WC TCAM or EM keys to virtualize further
+        *  lookups.
+        */
+       TF_IDENT_TYPE_L2_CTXT_HIGH,
+       /**
+        *  WH/SR/TH/SR2
         *  The L2 Context is returned from the L2 Ctxt TCAM lookup
         *  and can be used in WC TCAM or EM keys to virtualize further
         *  lookups.
         */
-       TF_IDENT_TYPE_L2_CTXT,
+       TF_IDENT_TYPE_L2_CTXT_LOW,
        /**
+        *  WH/SR/TH/SR2
         *  The WC profile func is returned from the L2 Ctxt TCAM lookup
         *  to enable virtualization of the profile TCAM.
         */
        TF_IDENT_TYPE_PROF_FUNC,
        /**
+        *  WH/SR/TH/SR2
         *  The WC profile ID is included in the WC lookup key
         *  to enable virtualization of the WC TCAM hardware.
         */
        TF_IDENT_TYPE_WC_PROF,
        /**
+        *  WH/SR/TH/SR2
         *  The EM profile ID is included in the EM lookup key
         *  to enable virtualization of the EM hardware. (not required for SR2
         *  as it has table scope)
         */
        TF_IDENT_TYPE_EM_PROF,
        /**
+        *  TH/SR2
         *  The L2 func is included in the ILT result and from recycling to
         *  enable virtualization of further lookups.
         */
@@ -183,65 +233,63 @@ enum tf_identifier_type {
 enum tf_tbl_type {
        /* Internal */
 
-       /** Wh+/SR Action Record */
+       /** Wh+/SR/TH Action Record */
        TF_TBL_TYPE_FULL_ACT_RECORD,
-       /** Wh+/SR/Th Multicast Groups */
+       /** TH Compact Action Record */
+       TF_TBL_TYPE_COMPACT_ACT_RECORD,
+       /** (Future) Multicast Groups */
        TF_TBL_TYPE_MCAST_GROUPS,
-       /** Wh+/SR Action Encap 8 Bytes */
+       /** Wh+/SR/TH Action Encap 8 Bytes */
        TF_TBL_TYPE_ACT_ENCAP_8B,
-       /** Wh+/SR Action Encap 16 Bytes */
+       /** Wh+/SR/TH Action Encap 16 Bytes */
        TF_TBL_TYPE_ACT_ENCAP_16B,
-       /** Action Encap 32 Bytes */
+       /** WH+/SR/TH Action Encap 32 Bytes */
        TF_TBL_TYPE_ACT_ENCAP_32B,
-       /** Wh+/SR Action Encap 64 Bytes */
+       /** Wh+/SR/TH Action Encap 64 Bytes */
        TF_TBL_TYPE_ACT_ENCAP_64B,
-       /** Action Source Properties SMAC */
+       /** WH+/SR/TH Action Source Properties SMAC */
        TF_TBL_TYPE_ACT_SP_SMAC,
-       /** Wh+/SR Action Source Properties SMAC IPv4 */
+       /** Wh+/SR/TH Action Source Properties SMAC IPv4 */
        TF_TBL_TYPE_ACT_SP_SMAC_IPV4,
-       /** Action Source Properties SMAC IPv6 */
+       /** WH+/SR/TH Action Source Properties SMAC IPv6 */
        TF_TBL_TYPE_ACT_SP_SMAC_IPV6,
-       /** Wh+/SR Action Statistics 64 Bits */
+       /** Wh+/SR/TH Action Statistics 64 Bits */
        TF_TBL_TYPE_ACT_STATS_64,
-       /** Wh+/SR Action Modify L4 Src Port */
-       TF_TBL_TYPE_ACT_MODIFY_SPORT,
-       /** Wh+/SR Action Modify L4 Dest Port */
-       TF_TBL_TYPE_ACT_MODIFY_DPORT,
        /** Wh+/SR Action Modify IPv4 Source */
-       TF_TBL_TYPE_ACT_MODIFY_IPV4_SRC,
-       /** Wh+/SR Action _Modify L4 Dest Port */
-       TF_TBL_TYPE_ACT_MODIFY_IPV4_DEST,
-       /** Action Modify IPv6 Source */
-       TF_TBL_TYPE_ACT_MODIFY_IPV6_SRC,
-       /** Action Modify IPv6 Destination */
-       TF_TBL_TYPE_ACT_MODIFY_IPV6_DEST,
-       /** Meter Profiles */
+       TF_TBL_TYPE_ACT_MODIFY_IPV4,
+       /** TH 8B Modify Record */
+       TF_TBL_TYPE_ACT_MODIFY_8B,
+       /** TH 16B Modify Record */
+       TF_TBL_TYPE_ACT_MODIFY_16B,
+       /** TH 32B Modify Record */
+       TF_TBL_TYPE_ACT_MODIFY_32B,
+       /** TH 64B Modify Record */
+       TF_TBL_TYPE_ACT_MODIFY_64B,
+       /** (Future) Meter Profiles */
        TF_TBL_TYPE_METER_PROF,
-       /** Meter Instance */
+       /** (Future) Meter Instance */
        TF_TBL_TYPE_METER_INST,
-       /** Mirror Config */
+       /** Wh+/SR/Th Mirror Config */
        TF_TBL_TYPE_MIRROR_CONFIG,
-       /** UPAR */
+       /** (Future) UPAR */
        TF_TBL_TYPE_UPAR,
-       /** SR2 Epoch 0 table */
+       /** (Future) SR2 Epoch 0 table */
        TF_TBL_TYPE_EPOCH0,
-       /** SR2 Epoch 1 table  */
+       /** (Future) SR2 Epoch 1 table  */
        TF_TBL_TYPE_EPOCH1,
-       /** SR2 Metadata  */
+       /** (Future) TH/SR2 Metadata  */
        TF_TBL_TYPE_METADATA,
-       /** SR2 CT State  */
+       /** (Future) TH/SR2 CT State  */
        TF_TBL_TYPE_CT_STATE,
-       /** SR2 Range Profile  */
+       /** (Future) TH/SR2 Range Profile  */
        TF_TBL_TYPE_RANGE_PROF,
-       /** SR2 Range Entry  */
+       /** (Future) SR2 Range Entry  */
        TF_TBL_TYPE_RANGE_ENTRY,
-       /** SR2 LAG Entry  */
+       /** (Future) SR2 LAG Entry  */
        TF_TBL_TYPE_LAG,
-       /** SR2 VNIC/SVIF Table */
-       TF_TBL_TYPE_VNIC_SVIF,
-       /** Th/SR2 EM Flexible Key builder */
+       /** TH/SR2 EM Flexible Key builder */
        TF_TBL_TYPE_EM_FKB,
-       /** Th/SR2 WC Flexible Key builder */
+       /** TH/SR2 WC Flexible Key builder */
        TF_TBL_TYPE_WC_FKB,
 
        /* External */
@@ -249,9 +297,18 @@ enum tf_tbl_type {
        /**
         * External table type - initially 1 poolsize entries.
         * All External table types are associated with a table
-        * scope. Internal types are not.
+        * scope. Internal types are not.  Currently this is
+        * a pool of 64B entries.
         */
        TF_TBL_TYPE_EXT,
+       /* (Future) SR2 32B External EM Action 32B Pool */
+       TF_TBL_TYPE_EXT_32B,
+       /* (Future) SR2 64B External EM Action 64B Pool */
+       TF_TBL_TYPE_EXT_64B,
+       /* (Future) SR2 96B External EM Action 96B Pool */
+       TF_TBL_TYPE_EXT_96B,
+       /* (Future) SR2 128B External EM Action 128B Pool */
+       TF_TBL_TYPE_EXT_128B,
        TF_TBL_TYPE_MAX
 };
 
@@ -260,7 +317,9 @@ enum tf_tbl_type {
  */
 enum tf_tcam_tbl_type {
        /** L2 Context TCAM */
-       TF_TCAM_TBL_TYPE_L2_CTXT_TCAM,
+       TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_HIGH,
+       /** L2 Context TCAM */
+       TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_LOW,
        /** Profile TCAM */
        TF_TCAM_TBL_TYPE_PROF_TCAM,
        /** Wildcard TCAM */
@@ -274,6 +333,18 @@ enum tf_tcam_tbl_type {
        TF_TCAM_TBL_TYPE_MAX
 };
 
+/**
+ * SEARCH STATUS
+ */
+enum tf_search_status {
+       /** The entry was not found, but an idx was allocated if requested. */
+       MISS,
+       /** The entry was found, and the result/idx are valid */
+       HIT,
+       /** The entry was not found and the table is full */
+       REJECT
+};
+
 /**
  * EM Resources
  * These defines are provisioned during
@@ -372,8 +443,8 @@ struct tf_session_info {
  *
  * Contains a pointer to the session info. Allocated by ULP and passed
  * to TruFlow using tf_open_session(). TruFlow will populate the
- * session info at that time. Additional 'opens' can be done using
- * same session_info by using tf_attach_session().
+ * session info at that time. A TruFlow Session can be used by more
+ * than one PF/VF by using the tf_open_session().
  *
  * It is expected that ULP allocates this memory as shared memory.
  *
@@ -384,34 +455,87 @@ struct tf {
        struct tf_session_info *session;
 };
 
+/**
+ * Identifier resource definition
+ */
+struct tf_identifier_resources {
+       /**
+        * Array of TF Identifiers where each entry is expected to be
+        * set to the requested resource number of that specific type.
+        * The index used is tf_identifier_type.
+        */
+       uint16_t cnt[TF_IDENT_TYPE_MAX];
+};
+
+/**
+ * Table type resource definition
+ */
+struct tf_tbl_resources {
+       /**
+        * Array of TF Table types where each entry is expected to be
+        * set to the requeste resource number of that specific
+        * type. The index used is tf_tbl_type.
+        */
+       uint16_t cnt[TF_TBL_TYPE_MAX];
+};
+
+/**
+ * TCAM type resource definition
+ */
+struct tf_tcam_resources {
+       /**
+        * Array of TF TCAM types where each entry is expected to be
+        * set to the requested resource number of that specific
+        * type. The index used is tf_tcam_tbl_type.
+        */
+       uint16_t cnt[TF_TCAM_TBL_TYPE_MAX];
+};
+
+/**
+ * EM type resource definition
+ */
+struct tf_em_resources {
+       /**
+        * Array of TF EM table types where each entry is expected to
+        * be set to the requested resource number of that specific
+        * type. The index used is tf_em_tbl_type.
+        */
+       uint16_t cnt[TF_EM_TBL_TYPE_MAX];
+};
+
 /**
  * tf_session_resources parameter definition.
  */
 struct tf_session_resources {
-       /** [in] Requested Identifier Resources
+       /**
+        * [in] Requested Identifier Resources
         *
-        * The number of identifier resources requested for the session.
-        * The index used is tf_identifier_type.
+        * Number of identifier resources requested for the
+        * session.
         */
-       uint16_t identifier_cnt[TF_IDENT_TYPE_MAX][TF_DIR_MAX];
-       /** [in] Requested Index Table resource counts
+       struct tf_identifier_resources ident_cnt[TF_DIR_MAX];
+       /**
+        * [in] Requested Index Table resource counts
         *
-        * The number of index table resources requested for the session.
-        * The index used is tf_tbl_type.
+        * The number of index table resources requested for the
+        * session.
         */
-       uint16_t tbl_cnt[TF_TBL_TYPE_MAX][TF_DIR_MAX];
-       /** [in] Requested TCAM Table resource counts
+       struct tf_tbl_resources tbl_cnt[TF_DIR_MAX];
+       /**
+        * [in] Requested TCAM Table resource counts
         *
-        * The number of TCAM table resources requested for the session.
-        * The index used is tf_tcam_tbl_type.
+        * The number of TCAM table resources requested for the
+        * session.
         */
-       uint16_t tcam_tbl_cnt[TF_TCAM_TBL_TYPE_MAX][TF_DIR_MAX];
-       /** [in] Requested EM resource counts
+
+       struct tf_tcam_resources tcam_cnt[TF_DIR_MAX];
+       /**
+        * [in] Requested EM resource counts
         *
-        * The number of internal EM table resources requested for the session
-        * The index used is tf_em_tbl_type.
+        * The number of internal EM table resources requested for the
+        * session.
         */
-       uint16_t em_tbl_cnt[TF_EM_TBL_TYPE_MAX][TF_DIR_MAX];
+       struct tf_em_resources em_cnt[TF_DIR_MAX];
 };
 
 /**
@@ -457,36 +581,62 @@ struct tf_open_session_parms {
         * The session_id allows a session to be shared between devices.
         */
        union tf_session_id session_id;
+       /**
+        * [in/out] session_client_id
+        *
+        * Session_client_id is unique per client.
+        *
+        * Session_client_id is composed of session_id and the
+        * fw_session_client_id fw_session_id. The construction is
+        * done by parsing the ctrl_chan_name together with allocation
+        * of a fw_session_client_id during tf_open_session().
+        *
+        * A reference count will be incremented in the session on
+        * which a client is created.
+        *
+        * A session can first be closed if there is one Session
+        * Client left. Session Clients should closed using
+        * tf_close_session().
+        */
+       union tf_session_client_id session_client_id;
        /**
         * [in] device type
         *
-        * Device type is passed, one of Wh+, SR, Thor, SR2
+        * Device type for the session.
         */
        enum tf_device_type device_type;
-       /** [in] resources
+       /**
+        * [in] resources
         *
-        * Resource allocation
+        * Resource allocation for the session.
         */
        struct tf_session_resources resources;
 };
 
 /**
- * Opens a new TruFlow management session.
+ * Opens a new TruFlow Session or session client.
+ *
+ * What gets created depends on the passed in tfp content. If the tfp
+ * does not have prior session data a new session with associated
+ * session client. If tfp has a session already a session client will
+ * be created. In both cases the session client is created using the
+ * provided ctrl_chan_name.
  *
- * TruFlow will allocate session specific memory, shared memory, to
- * hold its session data. This data is private to TruFlow.
+ * In case of session creation TruFlow will allocate session specific
+ * memory, shared memory, to hold its session data. This data is
+ * private to TruFlow.
  *
- * Multiple PFs can share the same session. An association, refcount,
- * between session and PFs is maintained within TruFlow. Thus, a PF
- * can attach to an existing session, see tf_attach_session().
+ * No other TruFlow APIs will succeed unless this API is first called
+ * and succeeds.
  *
- * No other TruFlow APIs will succeed unless this API is first called and
- * succeeds.
+ * tf_open_session() returns a session id and session client id that
+ * is used on all other TF APIs.
  *
- * tf_open_session() returns a session id that can be used on attach.
+ * A Session or session client can be closed using tf_close_session().
  *
  * [in] tfp
  *   Pointer to TF handle
+ *
  * [in] parms
  *   Pointer to open parameters
  *
@@ -497,9 +647,11 @@ struct tf_open_session_parms {
 int tf_open_session(struct tf *tfp,
                    struct tf_open_session_parms *parms);
 
-int tf_open_session_new(struct tf *tfp,
-                       struct tf_open_session_parms *parms);
-
+/**
+ * Experimental
+ *
+ * tf_attach_session parameters definition.
+ */
 struct tf_attach_session_parms {
        /**
         * [in] ctrl_chan_name
@@ -549,15 +701,18 @@ struct tf_attach_session_parms {
 };
 
 /**
- * Attaches to an existing session. Used when more than one PF wants
- * to share a single session. In that case all TruFlow management
- * traffic will be sent to the TruFlow firmware using the 'PF' that
- * did the attach not the session ctrl channel.
+ * Experimental
+ *
+ * Allows a 2nd application instance to attach to an existing
+ * session. Used when a session is to be shared between two processes.
  *
  * Attach will increment a ref count as to manage the shared session data.
  *
- * [in] tfp, pointer to TF handle
- * [in] parms, pointer to attach parameters
+ * [in] tfp
+ *   Pointer to TF handle
+ *
+ * [in] parms
+ *   Pointer to attach parameters
  *
  * Returns
  *   - (0) if successful.
@@ -565,18 +720,21 @@ struct tf_attach_session_parms {
  */
 int tf_attach_session(struct tf *tfp,
                      struct tf_attach_session_parms *parms);
-int tf_attach_session_new(struct tf *tfp,
-                         struct tf_attach_session_parms *parms);
 
 /**
- * Closes an existing session. Cleans up all hardware and firmware
- * state associated with the TruFlow application session when the last
- * PF associated with the session results in refcount to be zero.
+ * Closes an existing session client or the session it self. The
+ * session client is default closed and if the session reference count
+ * is 0 then the session is closed as well.
+ *
+ * On session close all hardware and firmware state associated with
+ * the TruFlow application is cleaned up.
+ *
+ * The session client is extracted from the tfp. Thus tf_close_session()
+ * cannot close a session client on behalf of another function.
  *
  * Returns success or failure code.
  */
 int tf_close_session(struct tf *tfp);
-int tf_close_session_new(struct tf *tfp);
 
 /**
  * @page  ident Identity Management
@@ -598,9 +756,9 @@ struct tf_alloc_identifier_parms {
         */
        enum tf_identifier_type ident_type;
        /**
-        * [out] Identifier allocated
+        * [out] Allocated identifier
         */
-       uint16_t id;
+       uint32_t id;
 };
 
 /**
@@ -618,7 +776,38 @@ struct tf_free_identifier_parms {
        /**
         * [in] ID to free
         */
-       uint16_t id;
+       uint32_t id;
+       /**
+        * (experimental)
+        * [out] Current refcnt after free
+        */
+       uint32_t ref_cnt;
+};
+
+/**
+ * tf_search_identifier parameter definition (experimental)
+ */
+struct tf_search_identifier_parms {
+       /**
+        * [in]  receive or transmit direction
+        */
+       enum tf_dir dir;
+       /**
+        * [in] Identifier type
+        */
+       enum tf_identifier_type ident_type;
+       /**
+        * [in] Identifier data to search for
+        */
+       uint32_t search_id;
+       /**
+        * [out] Set if matching identifier found
+        */
+       bool hit;
+       /**
+        * [out] Current ref count after allocation
+        */
+       uint32_t ref_cnt;
 };
 
 /**
@@ -627,12 +816,13 @@ struct tf_free_identifier_parms {
  * TruFlow core will allocate a free id from the per identifier resource type
  * pool reserved for the session during tf_open().  No firmware is involved.
  *
+ * If shadow copy is enabled, the internal ref_cnt is set to 1 in the
+ * shadow table for a newly allocated resource.
+ *
  * Returns success or failure code.
  */
 int tf_alloc_identifier(struct tf *tfp,
                        struct tf_alloc_identifier_parms *parms);
-int tf_alloc_identifier_new(struct tf *tfp,
-                           struct tf_alloc_identifier_parms *parms);
 
 /**
  * free identifier resource
@@ -641,12 +831,40 @@ int tf_alloc_identifier_new(struct tf *tfp,
  * reserved for the session.  No firmware is involved.  During tf_close, the
  * complete pool is returned to the firmware.
  *
+ * additional operation (experimental)
+ * Decrement reference count.  Only release resource once refcnt goes to 0 if
+ * shadow copy is enabled.
+ *
  * Returns success or failure code.
  */
 int tf_free_identifier(struct tf *tfp,
                       struct tf_free_identifier_parms *parms);
-int tf_free_identifier_new(struct tf *tfp,
-                          struct tf_free_identifier_parms *parms);
+
+/**
+ * Search identifier resource (experimental)
+ *
+ * If the shadow copy is enabled search_id is used to search for a matching
+ * entry in the shadow table.  The shadow table consists of an array of
+ * reference counts indexed by identifier.  If a matching entry is found hit is
+ * set to TRUE, refcnt is increased by 1 and returned.  Otherwise, hit is
+ * set to false and refcnt is set to 0.
+ *
+ * TODO: we may need a per table internal shadow copy enable flag to stage
+ * the shadow table implementation.  We do not need the shadow table for other
+ * tables at this time so we may only want to enable the identifier shadow.
+ *
+ * TODO: remove this pseudocode below added to show that if search fails
+ * we shouldn't allocate a new entry but return.
+ *
+ * identifier alloc (search_en=1)
+ * if (ident is allocated and ref_cnt >=1)
+ *      return ident - hit is set, incr refcnt
+ * else (not found)
+ *      return
+ *
+ */
+int tf_search_identifier(struct tf *tfp,
+                        struct tf_search_identifier_parms *parms);
 
 /**
  * @page dram_table DRAM Table Scope Interface
@@ -723,7 +941,9 @@ struct tf_alloc_tbl_scope_parms {
         */
        uint32_t tbl_scope_id;
 };
-
+/**
+ * tf_free_tbl_scope_parms definition
+ */
 struct tf_free_tbl_scope_parms {
        /**
         * [in] table scope identifier
@@ -731,6 +951,21 @@ struct tf_free_tbl_scope_parms {
        uint32_t tbl_scope_id;
 };
 
+/**
+ * tf_map_tbl_scope_parms definition
+ */
+struct tf_map_tbl_scope_parms {
+       /**
+        * [in] table scope identifier
+        */
+       uint32_t tbl_scope_id;
+       /**
+        * [in] Which parifs are associated with this table scope.  Bit 0
+        *      indicates parif 0.
+        */
+       uint16_t parif_bitmask;
+};
+
 /**
  * allocate a table scope
  *
@@ -740,13 +975,13 @@ struct tf_free_tbl_scope_parms {
  * device constraints based upon calculations using either the number of flows
  * requested or the size of memory indicated.  Other parameters passed in
  * determine the configuration (maximum key size, maximum external action record
- * size.
+ * size).
  *
- * This API will allocate the table region in
- * DRAM, program the PTU page table entries, and program the number of static
- * buckets (if SR2) in the RX and TX CFAs.  Buckets are assumed to start at
- * 0 in the EM memory for the scope.  Upon successful completion of this API,
- * hash tables are fully initialized and ready for entries to be inserted.
+ * This API will allocate the table region in DRAM, program the PTU page table
+ * entries, and program the number of static buckets (if SR2) in the RX and TX
+ * CFAs.  Buckets are assumed to start at 0 in the EM memory for the scope.
+ * Upon successful completion of this API, hash tables are fully initialized and
+ * ready for entries to be inserted.
  *
  * A single API is used to allocate a common table scope identifier in both
  * receive and transmit CFA. The scope identifier is common due to nature of
@@ -769,7 +1004,25 @@ struct tf_free_tbl_scope_parms {
 int tf_alloc_tbl_scope(struct tf *tfp,
                       struct tf_alloc_tbl_scope_parms *parms);
 
+/**
+ * map a table scope (legacy device only Wh+/SR)
+ *
+ * Map a table scope to one or more partition interfaces (parifs).
+ * The parif can be remapped in the L2 context lookup for legacy devices.  This
+ * API allows a number of parifs to be mapped to the same table scope.  On
+ * legacy devices a table scope identifies one of 16 sets of EEM table base
+ * addresses and is associated with a PF communication channel.  The associated
+ * PF must be configured for the table scope to operate.
+ *
+ * An L2 context TCAM lookup returns a remapped parif value used to
+ * index into the set of 16 parif_to_pf registers which are used to map to one
+ * of the 16 table scopes.  This API allows the user to map the parifs in the
+ * mask to the previously allocated table scope (EEM table).
 
+ * Returns success or failure code.
+ */
+int tf_map_tbl_scope(struct tf *tfp,
+                     struct tf_map_tbl_scope_parms *parms);
 /**
  * free a table scope
  *
@@ -786,6 +1039,8 @@ int tf_free_tbl_scope(struct tf *tfp,
 /**
  * @page tcam TCAM Access
  *
+ * @ref tf_search_tcam_entry
+ *
  * @ref tf_alloc_tcam_entry
  *
  * @ref tf_set_tcam_entry
@@ -795,6 +1050,93 @@ int tf_free_tbl_scope(struct tf *tfp,
  * @ref tf_free_tcam_entry
  */
 
+/**
+ * tf_search_tcam_entry parameter definition (experimental)
+ */
+struct tf_search_tcam_entry_parms {
+       /**
+        * [in] receive or transmit direction
+        */
+       enum tf_dir dir;
+       /**
+        * [in] TCAM table type
+        */
+       enum tf_tcam_tbl_type tcam_tbl_type;
+       /**
+        * [in] Key data to match on
+        */
+       uint8_t *key;
+       /**
+        * [in] key size in bits
+        */
+       uint16_t key_sz_in_bits;
+       /**
+        * [in] Mask data to match on
+        */
+       uint8_t *mask;
+       /**
+        * [in] Priority of entry requested (definition TBD)
+        */
+       uint32_t priority;
+       /**
+        * [in] Allocate on miss.
+        */
+       uint8_t alloc;
+       /**
+        * [out] Set if matching entry found
+        */
+       uint8_t hit;
+       /**
+        * [out] Search result status (hit, miss, reject)
+        */
+       enum tf_search_status search_status;
+       /**
+        * [out] Current refcnt after allocation
+        */
+       uint16_t ref_cnt;
+       /**
+        * [in out] The result data from the search is copied here
+        */
+       uint8_t *result;
+       /**
+        * [in out] result size in bits for the result data
+        */
+       uint16_t result_sz_in_bits;
+       /**
+        * [out] Index found
+        */
+       uint16_t idx;
+};
+
+/**
+ * search TCAM entry (experimental)
+ *
+ * Search for a TCAM entry
+ *
+ * This function searches the shadow copy of the TCAM table for a matching
+ * entry.  Key and mask must match for hit to be set.  Only TruFlow core data
+ * is accessed.  If shadow_copy is not enabled, an error is returned.
+ *
+ * Implementation:
+ *
+ * A hash is performed on the key/mask data and mapped to a shadow copy entry
+ * where the full key/mask is populated.  If the full key/mask matches the
+ * entry, hit is set, ref_cnt is incremented, and search_status indicates what
+ * action the caller can take regarding setting the entry.
+ *
+ * search_status should be used as follows:
+ * - On Miss, the caller should create a result and call tf_set_tcam_entry with
+ * returned index.
+ *
+ * - On Reject, the hash table is full and the entry cannot be added.
+ *
+ * - On Hit, the result data is returned to the caller.  Additionally, the
+ * ref_cnt is updated.
+ *
+ * Also returns success or failure code.
+ */
+int tf_search_tcam_entry(struct tf *tfp,
+                        struct tf_search_tcam_entry_parms *parms);
 
 /**
  * tf_alloc_tcam_entry parameter definition
@@ -944,7 +1286,7 @@ struct tf_get_tcam_entry_parms {
         */
        uint8_t *mask;
        /**
-        * [out] key size in bits
+        * [in/out] key size in bits
         */
        uint16_t key_sz_in_bits;
        /**
@@ -952,7 +1294,7 @@ struct tf_get_tcam_entry_parms {
         */
        uint8_t *result;
        /**
-        * [out] struct containing result size in bits
+        * [in/out] struct containing result size in bits
         */
        uint16_t result_sz_in_bits;
 };
@@ -1017,8 +1359,82 @@ int tf_free_tcam_entry(struct tf *tfp,
  * @ref tf_set_tbl_entry
  *
  * @ref tf_get_tbl_entry
+ *
+ * @ref tf_bulk_get_tbl_entry
+ */
+
+/**
+ * tf_alloc_tbl_entry parameter definition
  */
+struct tf_search_tbl_entry_parms {
+       /**
+        * [in] Receive or transmit direction
+        */
+       enum tf_dir dir;
+       /**
+        * [in] Type of the allocation
+        */
+       enum tf_tbl_type type;
+       /**
+        * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
+        */
+       uint32_t tbl_scope_id;
+       /**
+        * [in] Result data to search for
+        */
+       uint8_t *result;
+       /**
+        * [in] Result data size in bytes
+        */
+       uint16_t result_sz_in_bytes;
+       /**
+        * [in] Allocate on miss.
+        */
+       uint8_t alloc;
+       /**
+        * [out] Set if matching entry found
+        */
+       uint8_t hit;
+       /**
+        * [out] Search result status (hit, miss, reject)
+        */
+       enum tf_search_status search_status;
+       /**
+        * [out] Current ref count after allocation
+        */
+       uint16_t ref_cnt;
+       /**
+        * [out] Idx of allocated entry or found entry
+        */
+       uint32_t idx;
+};
 
+/**
+ * search Table Entry (experimental)
+ *
+ * This function searches the shadow copy of an index table for a matching
+ * entry.  The result data must match for hit to be set.  Only TruFlow core
+ * data is accessed.  If shadow_copy is not enabled, an error is returned.
+ *
+ * Implementation:
+ *
+ * A hash is performed on the result data and mappe3d to a shadow copy entry
+ * where the result is populated.  If the result matches the entry, hit is set,
+ * ref_cnt is incremented (if alloc), and the search status indicates what
+ * action the caller can take regarding setting the entry.
+ *
+ * search status should be used as follows:
+ * - On MISS, the caller should set the result into the returned index.
+ *
+ * - On REJECT, the caller should reject the flow since there are no resources.
+ *
+ * - On Hit, the matching index is returned to the caller.  Additionally, the
+ *   ref_cnt is updated.
+ *
+ * Also returns success or failure code.
+ */
+int tf_search_tbl_entry(struct tf *tfp,
+                       struct tf_search_tbl_entry_parms *parms);
 
 /**
  * tf_alloc_tbl_entry parameter definition
@@ -1268,16 +1684,18 @@ struct tf_bulk_get_tbl_entry_parms {
 /**
  * Bulk get index table entry
  *
- * Used to retrieve a previous set index table entry.
+ * Used to retrieve a set of index table entries.
  *
- * Reads and compares with the shadow table copy (if enabled) (only
- * for internal objects).
+ * Entries within the range may not have been allocated using
+ * tf_alloc_tbl_entry() at the time of access. But the range must
+ * be within the bounds determined from tf_open_session() for the
+ * given table type.  Currently, this is only used for collecting statistics.
  *
  * Returns success or failure code. Failure will be returned if the
  * provided data buffer is too small for the data type requested.
  */
 int tf_bulk_get_tbl_entry(struct tf *tfp,
-                    struct tf_bulk_get_tbl_entry_parms *parms);
+                         struct tf_bulk_get_tbl_entry_parms *parms);
 
 /**
  * @page exact_match Exact Match Table
@@ -1517,4 +1935,192 @@ int tf_delete_em_entry(struct tf *tfp,
 int tf_search_em_entry(struct tf *tfp,
                       struct tf_search_em_entry_parms *parms);
 
+/**
+ * @page global Global Configuration
+ *
+ * @ref tf_set_global_cfg
+ *
+ * @ref tf_get_global_cfg
+ */
+/**
+ * Tunnel Encapsulation Offsets
+ */
+enum tf_tunnel_encap_offsets {
+       TF_TUNNEL_ENCAP_L2,
+       TF_TUNNEL_ENCAP_NAT,
+       TF_TUNNEL_ENCAP_MPLS,
+       TF_TUNNEL_ENCAP_VXLAN,
+       TF_TUNNEL_ENCAP_GENEVE,
+       TF_TUNNEL_ENCAP_NVGRE,
+       TF_TUNNEL_ENCAP_GRE,
+       TF_TUNNEL_ENCAP_FULL_GENERIC
+};
+/**
+ * Global Configuration Table Types
+ */
+enum tf_global_config_type {
+       TF_TUNNEL_ENCAP,  /**< Tunnel Encap Config(TECT) */
+       TF_ACTION_BLOCK,  /**< Action Block Config(ABCR) */
+       TF_COUNTER_CFG,   /**< Counter Configuration (CNTRS_CTRL) */
+       TF_GLOBAL_CFG_TYPE_MAX
+};
+
+/**
+ * tf_global_cfg parameter definition
+ */
+struct tf_global_cfg_parms {
+       /**
+        * [in] receive or transmit direction
+        */
+       enum tf_dir dir;
+       /**
+        * [in] Global config type
+        */
+       enum tf_global_config_type type;
+       /**
+        * [in] Offset @ the type
+        */
+       uint32_t offset;
+       /**
+        * [in/out] Value of the configuration
+        * set - Read, Modify and Write
+        * get - Read the full configuration
+        */
+       uint8_t *config;
+       /**
+        * [in] Configuration mask
+        * set - Read, Modify with mask and Write
+        * get - unused
+        */
+       uint8_t *config_mask;
+       /**
+        * [in] struct containing size
+        */
+       uint16_t config_sz_in_bytes;
+};
+
+/**
+ * Get global configuration
+ *
+ * Retrieve the configuration
+ *
+ * Returns success or failure code.
+ */
+int tf_get_global_cfg(struct tf *tfp,
+                     struct tf_global_cfg_parms *parms);
+
+/**
+ * Update the global configuration table
+ *
+ * Read, modify write the value.
+ *
+ * Returns success or failure code.
+ */
+int tf_set_global_cfg(struct tf *tfp,
+                     struct tf_global_cfg_parms *parms);
+
+/**
+ * @page if_tbl Interface Table Access
+ *
+ * @ref tf_set_if_tbl_entry
+ *
+ * @ref tf_get_if_tbl_entry
+ *
+ * @ref tf_restore_if_tbl_entry
+ */
+/**
+ * Enumeration of TruFlow interface table types.
+ */
+enum tf_if_tbl_type {
+       /** Default Profile L2 Context Entry */
+       TF_IF_TBL_TYPE_PROF_SPIF_DFLT_L2_CTXT,
+       /** Default Profile TCAM/Lookup Action Record Pointer Table */
+       TF_IF_TBL_TYPE_PROF_PARIF_DFLT_ACT_REC_PTR,
+       /** Error Profile TCAM Miss Action Record Pointer Table */
+       TF_IF_TBL_TYPE_PROF_PARIF_ERR_ACT_REC_PTR,
+       /** Default Error Profile TCAM Miss Action Record Pointer Table */
+       TF_IF_TBL_TYPE_LKUP_PARIF_DFLT_ACT_REC_PTR,
+       /** SR2 Ingress lookup table */
+       TF_IF_TBL_TYPE_ILT,
+       /** SR2 VNIC/SVIF Properties Table */
+       TF_IF_TBL_TYPE_VSPT,
+       TF_IF_TBL_TYPE_MAX
+};
+
+/**
+ * tf_set_if_tbl_entry parameter definition
+ */
+struct tf_set_if_tbl_entry_parms {
+       /**
+        * [in] Receive or transmit direction
+        */
+       enum tf_dir dir;
+       /**
+        * [in] Type of object to set
+        */
+       enum tf_if_tbl_type type;
+       /**
+        * [in] Entry data
+        */
+       uint8_t *data;
+       /**
+        * [in] Entry size
+        */
+       uint16_t data_sz_in_bytes;
+       /**
+        * [in] Interface to write
+        */
+       uint32_t idx;
+};
+
+/**
+ * set interface table entry
+ *
+ * Used to set an interface table. This API is used for managing tables indexed
+ * by SVIF/SPIF/PARIF interfaces. In current implementation only the value is
+ * set.
+ * Returns success or failure code.
+ */
+int tf_set_if_tbl_entry(struct tf *tfp,
+                       struct tf_set_if_tbl_entry_parms *parms);
+
+/**
+ * tf_get_if_tbl_entry parameter definition
+ */
+struct tf_get_if_tbl_entry_parms {
+       /**
+        * [in] Receive or transmit direction
+        */
+       enum tf_dir dir;
+       /**
+        * [in] Type of table to get
+        */
+       enum tf_if_tbl_type type;
+       /**
+        * [out] Entry data
+        */
+       uint8_t *data;
+       /**
+        * [in] Entry size
+        */
+       uint16_t data_sz_in_bytes;
+       /**
+        * [in] Entry index to read
+        */
+       uint32_t idx;
+};
+
+/**
+ * get interface table entry
+ *
+ * Used to retrieve an interface table entry.
+ *
+ * Reads the interface table entry value
+ *
+ * Returns success or failure code. Failure will be returned if the
+ * provided data buffer is too small for the data type requested.
+ */
+int tf_get_if_tbl_entry(struct tf *tfp,
+                       struct tf_get_if_tbl_entry_parms *parms);
+
 #endif /* _TF_CORE_H_ */