net/bnxt: add shadow and search capability to TCAM
[dpdk.git] / drivers / net / bnxt / tf_core / tf_shadow_tcam.h
index e2c4e06..ea9f38e 100644 (file)
 
 #include "tf_core.h"
 
-struct tf;
-
-/**
- * The Shadow tcam module provides shadow DB handling for tcam based
- * TF types. A shadow DB provides the capability that allows for reuse
- * of TF resources.
- *
- * A Shadow tcam DB is intended to be used by the Tcam module only.
- */
-
 /**
- * Shadow DB configuration information for a single tcam type.
- *
- * During Device initialization the HCAPI device specifics are learned
- * and as well as the RM DB creation. From that those initial steps
- * this structure can be populated.
+ * Shadow DB configuration information
  *
- * NOTE:
- * If used in an array of tcam types then such array must be ordered
- * by the TF type is represents.
+ * The shadow configuration is for all tcam table types for a direction
  */
 struct tf_shadow_tcam_cfg_parms {
        /**
-        * TF tcam type
+        * [in] The number of elements in the alloc_cnt and base_addr
+        * For now, it should always be equal to TF_TCAM_TBL_TYPE_MAX
         */
-       enum tf_tcam_tbl_type type;
-
+       int num_entries;
        /**
-        * Number of entries the Shadow DB needs to hold
+        * [in] Resource allocation count array
+        * This array content originates from the tf_session_resources
+        * that is passed in on session open
+        * Array size is TF_TCAM_TBL_TYPE_MAX
         */
-       int num_entries;
-
+       uint16_t *alloc_cnt;
        /**
-        * Element width for this table type
+        * [in] The base index for each tcam table
         */
-       int element_width;
+       uint16_t base_addr[TF_TCAM_TBL_TYPE_MAX];
 };
 
 /**
- * Shadow tcam DB creation parameters
+ * Shadow TCAM  DB creation parameters.  The shadow db for this direction
+ * is returned
  */
 struct tf_shadow_tcam_create_db_parms {
        /**
-        * [in] Configuration information for the shadow db
+        * [in] Receive or transmit direction
         */
-       struct tf_shadow_tcam_cfg_parms *cfg;
+       enum tf_dir dir;
        /**
-        * [in] Number of elements in the parms structure
+        * [in] Configuration information for the shadow db
         */
-       uint16_t num_elements;
+       struct tf_shadow_tcam_cfg_parms *cfg;
        /**
         * [out] Shadow tcam DB handle
         */
-       void *tf_shadow_tcam_db;
+       void **shadow_db;
 };
 
 /**
- * Shadow tcam DB free parameters
+ * Create the shadow db for a single direction
+ *
+ * The returned shadow db must be free using the free db API when no longer
+ * needed
  */
-struct tf_shadow_tcam_free_db_parms {
-       /**
-        * Shadow tcam DB handle
-        */
-       void *tf_shadow_tcam_db;
-};
+int
+tf_shadow_tcam_create_db(struct tf_shadow_tcam_create_db_parms *parms);
 
 /**
- * Shadow tcam search parameters
+ * Shadow TCAM free parameters
  */
-struct tf_shadow_tcam_search_parms {
+struct tf_shadow_tcam_free_db_parms {
        /**
         * [in] Shadow tcam DB handle
         */
-       void *tf_shadow_tcam_db;
-       /**
-        * [in] TCAM tbl type
-        */
-       enum tf_tcam_tbl_type type;
-       /**
-        * [in] Pointer to entry blob value in remap table to match
-        */
-       uint8_t *entry;
-       /**
-        * [in] Size of the entry blob passed in bytes
-        */
-       uint16_t entry_sz;
-       /**
-        * [out] Index of the found element returned if hit
-        */
-       uint16_t *index;
-       /**
-        * [out] Reference count incremented if hit
-        */
-       uint16_t *ref_cnt;
+       void *shadow_db;
 };
 
 /**
- * Shadow tcam insert parameters
+ * Free all resources associated with the shadow db
+ */
+int
+tf_shadow_tcam_free_db(struct tf_shadow_tcam_free_db_parms *parms);
+
+/**
+ * Shadow TCAM bind index parameters
  */
-struct tf_shadow_tcam_insert_parms {
+struct tf_shadow_tcam_bind_index_parms {
        /**
         * [in] Shadow tcam DB handle
         */
-       void *tf_shadow_tcam_db;
+       void *shadow_db;
        /**
-        * [in] TCAM tbl type
+        * [in] receive or transmit direction
+        */
+       enum tf_dir dir;
+       /**
+        * [in] TCAM table type
         */
        enum tf_tcam_tbl_type type;
        /**
-        * [in] Pointer to entry blob value in remap table to match
+        * [in] index of the entry to program
         */
-       uint8_t *entry;
+       uint16_t idx;
        /**
-        * [in] Size of the entry blob passed in bytes
+        * [in] struct containing key
         */
-       uint16_t entry_sz;
+       uint8_t *key;
        /**
-        * [in] Entry to update
+        * [in] struct containing mask fields
         */
-       uint16_t index;
+       uint8_t *mask;
        /**
-        * [out] Reference count after insert
+        * [in] key size in bits (if search)
         */
-       uint16_t *ref_cnt;
+       uint16_t key_size;
+       /**
+        * [in] The hash bucket handled returned from the search
+        */
+       uint32_t hb_handle;
 };
 
 /**
- * Shadow tcam remove parameters
+ * Binds the allocated tcam index with the hash and shadow tables
  */
-struct tf_shadow_tcam_remove_parms {
+int
+tf_shadow_tcam_bind_index(struct tf_shadow_tcam_bind_index_parms *parms);
+
+/**
+ * Shadow TCAM insert parameters
+ */
+struct tf_shadow_tcam_insert_parms {
        /**
         * [in] Shadow tcam DB handle
         */
-       void *tf_shadow_tcam_db;
-       /**
-        * [in] TCAM tbl type
-        */
-       enum tf_tcam_tbl_type type;
-       /**
-        * [in] Entry to update
-        */
-       uint16_t index;
+       void *shadow_db;
        /**
-        * [out] Reference count after removal
+        * [in] The set parms from tf core
         */
-       uint16_t *ref_cnt;
+       struct tf_tcam_set_parms *sparms;
 };
 
 /**
- * @page shadow_tcam Shadow tcam DB
- *
- * @ref tf_shadow_tcam_create_db
- *
- * @ref tf_shadow_tcam_free_db
- *
- * @reg tf_shadow_tcam_search
- *
- * @reg tf_shadow_tcam_insert
- *
- * @reg tf_shadow_tcam_remove
- */
-
-/**
- * Creates and fills a Shadow tcam DB. The DB is indexed per the
- * parms structure.
- *
- * [in] parms
- *   Pointer to create db parameters
+ * Set the entry into the tcam manager hash and shadow tables
  *
- * Returns
- *   - (0) if successful.
- *   - (-EINVAL) on failure.
+ * The search must have been used prior to setting the entry so that the
+ * hash has been calculated and duplicate entries will not be added
  */
-int tf_shadow_tcam_create_db(struct tf_shadow_tcam_create_db_parms *parms);
+int
+tf_shadow_tcam_insert(struct tf_shadow_tcam_insert_parms *parms);
 
 /**
- * Closes the Shadow tcam DB and frees all allocated
- * resources per the associated database.
- *
- * [in] parms
- *   Pointer to the free DB parameters
- *
- * Returns
- *   - (0) if successful.
- *   - (-EINVAL) on failure.
+ * Shadow TCAM remove parameters
  */
-int tf_shadow_tcam_free_db(struct tf_shadow_tcam_free_db_parms *parms);
+struct tf_shadow_tcam_remove_parms {
+       /**
+        * [in] Shadow tcam DB handle
+        */
+       void *shadow_db;
+       /**
+        * [in,out] The set parms from tf core
+        */
+       struct tf_tcam_free_parms *fparms;
+};
 
 /**
- * Search Shadow tcam db for matching result
- *
- * [in] parms
- *   Pointer to the search parameters
+ * Remove the entry from the tcam hash and shadow tables
  *
- * Returns
- *   - (0) if successful, element was found.
- *   - (-EINVAL) on failure.
+ * The search must have been used prior to setting the entry so that the
+ * hash has been calculated and duplicate entries will not be added
  */
-int tf_shadow_tcam_search(struct tf_shadow_tcam_search_parms *parms);
+int
+tf_shadow_tcam_remove(struct tf_shadow_tcam_remove_parms *parms);
 
 /**
- * Inserts an element into the Shadow tcam DB. Will fail if the
- * elements ref_count is different from 0. Ref_count after insert will
- * be incremented.
- *
- * [in] parms
- *   Pointer to insert parameters
- *
- * Returns
- *   - (0) if successful.
- *   - (-EINVAL) on failure.
+ * Shadow TCAM search parameters
  */
-int tf_shadow_tcam_insert(struct tf_shadow_tcam_insert_parms *parms);
+struct tf_shadow_tcam_search_parms {
+       /**
+        * [in] Shadow tcam DB handle
+        */
+       void *shadow_db;
+       /**
+        * [in,out] The search parameters from tf core
+        */
+       struct tf_tcam_alloc_search_parms *sparms;
+       /**
+        * [out] The hash handle to use for the set
+        */
+       uint32_t hb_handle;
+};
 
 /**
- * Removes an element from the Shadow tcam DB. Will fail if the
- * elements ref_count is 0. Ref_count after removal will be
- * decremented.
+ * Search for an entry in the tcam hash/shadow tables
  *
- * [in] parms
- *   Pointer to remove parameter
- *
- * Returns
- *   - (0) if successful.
- *   - (-EINVAL) on failure.
+ * If there is a miss, but there is room for insertion, the hb_handle returned
+ * is used for insertion during the bind index API
  */
-int tf_shadow_tcam_remove(struct tf_shadow_tcam_remove_parms *parms);
-
-#endif /* _TF_SHADOW_TCAM_H_ */
+int
+tf_shadow_tcam_search(struct tf_shadow_tcam_search_parms *parms);
+#endif