compress/qat: enable compression on GEN3
[dpdk.git] / drivers / net / bnxt / tf_core / tf_core.h
index 9e80426..a47edff 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/hcapi_cfa_defs.h"
 #include "tf_project.h"
 
 /**
@@ -162,7 +162,13 @@ enum tf_identifier_type {
         *  and can be used in WC TCAM or EM keys to virtualize further
         *  lookups.
         */
-       TF_IDENT_TYPE_L2_CTXT,
+       TF_IDENT_TYPE_L2_CTXT_HIGH,
+       /**
+        *  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_LOW,
        /**
         *  The WC profile func is returned from the L2 Ctxt TCAM lookup
         *  to enable virtualization of the profile TCAM.
@@ -222,9 +228,7 @@ enum tf_tbl_type {
        /** 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,
+       TF_TBL_TYPE_ACT_MODIFY_IPV4,
        /** Meter Profiles */
        TF_TBL_TYPE_METER_PROF,
        /** Meter Instance */
@@ -270,7 +274,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 */
@@ -284,6 +290,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
@@ -695,9 +713,9 @@ struct tf_alloc_identifier_parms {
         */
        enum tf_identifier_type ident_type;
        /**
-        * [out] Identifier allocated
+        * [out] Allocated identifier
         */
-       uint16_t id;
+       uint32_t id;
 };
 
 /**
@@ -715,7 +733,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;
 };
 
 /**
@@ -724,6 +773,9 @@ 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,
@@ -736,11 +788,41 @@ int tf_alloc_identifier(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);
 
+/**
+ * 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
  *
@@ -816,7 +898,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
@@ -824,6 +908,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
  *
@@ -833,13 +932,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
@@ -862,7 +961,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
  *
@@ -879,6 +996,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
@@ -888,6 +1007,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
@@ -1114,6 +1320,79 @@ int tf_free_tcam_entry(struct tf *tfp,
  * @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
  */
@@ -1362,10 +1641,12 @@ 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.
@@ -1662,6 +1943,12 @@ struct tf_global_cfg_parms {
         * 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
         */