net/bnxt: add functions to get shared table increments
[dpdk.git] / drivers / net / bnxt / tf_core / tf_identifier.c
index 41ab13c..9f27a41 100644 (file)
 #include "tf_rm.h"
 #include "tf_util.h"
 #include "tfp.h"
+#include "tf_session.h"
 
 struct tf;
 
-/**
- * Identifier DBs.
- */
-static void *ident_db[TF_DIR_MAX];
-
-/**
- * Init flag, set on bind and cleared on unbind
- */
-static uint8_t init;
-
 /**
  * Identifier shadow DBs.
  */
@@ -39,35 +30,50 @@ tf_ident_bind(struct tf *tfp,
              struct tf_ident_cfg_parms *parms)
 {
        int rc;
+       int db_rc[TF_DIR_MAX] = { 0 };
        int i;
        struct tf_rm_create_db_parms db_cfg = { 0 };
        struct tf_shadow_ident_cfg_parms shadow_cfg = { 0 };
        struct tf_shadow_ident_create_db_parms shadow_cdb = { 0 };
+       struct ident_rm_db *ident_db;
+       struct tfp_calloc_parms cparms;
+       struct tf_session *tfs;
 
        TF_CHECK_PARMS2(tfp, parms);
 
-       if (init) {
-               TFP_DRV_LOG(ERR,
-                           "Identifier DB already initialized\n");
-               return -EINVAL;
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
+
+       memset(&db_cfg, 0, sizeof(db_cfg));
+       cparms.nitems = 1;
+       cparms.size = sizeof(struct ident_rm_db);
+       cparms.alignment = 0;
+       if (tfp_calloc(&cparms) != 0) {
+               TFP_DRV_LOG(ERR, "ident_rm_db alloc error %s\n",
+                           strerror(ENOMEM));
+               return -ENOMEM;
        }
 
-       db_cfg.type = TF_DEVICE_MODULE_TYPE_IDENTIFIER;
+       ident_db = cparms.mem_va;
+       for (i = 0; i < TF_DIR_MAX; i++)
+               ident_db->ident_db[i] = NULL;
+       tf_session_set_db(tfp, TF_MODULE_TYPE_IDENTIFIER, ident_db);
+
+       db_cfg.module = TF_MODULE_TYPE_IDENTIFIER;
        db_cfg.num_elements = parms->num_elements;
        db_cfg.cfg = parms->cfg;
 
        for (i = 0; i < TF_DIR_MAX; i++) {
+               db_cfg.rm_db = (void *)&ident_db->ident_db[i];
                db_cfg.dir = i;
                db_cfg.alloc_cnt = parms->resources->ident_cnt[i].cnt;
-               db_cfg.rm_db = &ident_db[i];
-               rc = tf_rm_create_db(tfp, &db_cfg);
-               if (rc) {
-                       TFP_DRV_LOG(ERR,
-                                   "%s: Identifier DB creation failed\n",
-                                   tf_dir_2_str(i));
-
-                       return rc;
-               }
+               if (tf_session_is_shared_session(tfs) &&
+                       (!tf_session_is_shared_session_creator(tfs)))
+                       db_rc[i] = tf_rm_create_db_no_reservation(tfp, &db_cfg);
+               else
+                       db_rc[i] = tf_rm_create_db(tfp, &db_cfg);
 
                if (parms->shadow_copy) {
                        shadow_cfg.alloc_cnt =
@@ -87,7 +93,11 @@ tf_ident_bind(struct tf *tfp,
                }
        }
 
-       init = 1;
+       /* No db created */
+       if (db_rc[TF_DIR_RX] && db_rc[TF_DIR_TX]) {
+               TFP_DRV_LOG(ERR, "No Identifier DB created\n");
+               return db_rc[TF_DIR_RX];
+       }
 
        TFP_DRV_LOG(INFO,
                    "Identifier - initialized\n");
@@ -102,19 +112,21 @@ tf_ident_unbind(struct tf *tfp)
        int i;
        struct tf_rm_free_db_parms fparms = { 0 };
        struct tf_shadow_ident_free_db_parms sparms = { 0 };
+       struct ident_rm_db *ident_db;
+       void *ident_db_ptr = NULL;
 
        TF_CHECK_PARMS1(tfp);
 
-       /* Bail if nothing has been initialized */
-       if (!init) {
-               TFP_DRV_LOG(INFO,
-                           "No Identifier DBs created\n");
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_IDENTIFIER, &ident_db_ptr);
+       if (rc)
                return 0;
-       }
+       ident_db = (struct ident_rm_db *)ident_db_ptr;
 
        for (i = 0; i < TF_DIR_MAX; i++) {
+               if (ident_db->ident_db[i] == NULL)
+                       continue;
+               fparms.rm_db = ident_db->ident_db[i];
                fparms.dir = i;
-               fparms.rm_db = ident_db[i];
                rc = tf_rm_free_db(tfp, &fparms);
                if (rc) {
                        TFP_DRV_LOG(ERR,
@@ -131,10 +143,9 @@ tf_ident_unbind(struct tf *tfp)
                        }
                        ident_shadow_db[i] = NULL;
                }
-               ident_db[i] = NULL;
+               ident_db->ident_db[i] = NULL;
        }
 
-       init = 0;
        shadow_init = 0;
 
        return 0;
@@ -149,19 +160,22 @@ tf_ident_alloc(struct tf *tfp __rte_unused,
        uint32_t base_id;
        struct tf_rm_allocate_parms aparms = { 0 };
        struct tf_shadow_ident_insert_parms iparms = { 0 };
+       struct ident_rm_db *ident_db;
+       void *ident_db_ptr = NULL;
 
        TF_CHECK_PARMS2(tfp, parms);
 
-       if (!init) {
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_IDENTIFIER, &ident_db_ptr);
+       if (rc) {
                TFP_DRV_LOG(ERR,
-                           "%s: No Identifier DBs created\n",
-                           tf_dir_2_str(parms->dir));
-               return -EINVAL;
+                           "Failed to get ident_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
        }
+       ident_db = (struct ident_rm_db *)ident_db_ptr;
 
-       /* Allocate requested element */
-       aparms.rm_db = ident_db[parms->dir];
-       aparms.db_index = parms->type;
+       aparms.rm_db = ident_db->ident_db[parms->dir];
+       aparms.subtype = parms->type;
        aparms.index = &id;
        aparms.base_index = &base_id;
        rc = tf_rm_allocate(&aparms);
@@ -203,19 +217,23 @@ tf_ident_free(struct tf *tfp __rte_unused,
        struct tf_shadow_ident_remove_parms rparms = { 0 };
        int allocated = 0;
        uint32_t base_id;
+       struct ident_rm_db *ident_db;
+       void *ident_db_ptr = NULL;
 
        TF_CHECK_PARMS2(tfp, parms);
 
-       if (!init) {
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_IDENTIFIER, &ident_db_ptr);
+       if (rc) {
                TFP_DRV_LOG(ERR,
-                           "%s: No Identifier DBs created\n",
-                           tf_dir_2_str(parms->dir));
-               return -EINVAL;
+                           "Failed to get ident_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
        }
+       ident_db = (struct ident_rm_db *)ident_db_ptr;
 
        /* Check if element is in use */
-       aparms.rm_db = ident_db[parms->dir];
-       aparms.db_index = parms->type;
+       aparms.rm_db = ident_db->ident_db[parms->dir];
+       aparms.subtype = parms->type;
        aparms.index = parms->id;
        aparms.base_index = &base_id;
        aparms.allocated = &allocated;
@@ -254,8 +272,8 @@ tf_ident_free(struct tf *tfp __rte_unused,
        }
 
        /* Free requested element */
-       fparms.rm_db = ident_db[parms->dir];
-       fparms.db_index = parms->type;
+       fparms.rm_db = ident_db->ident_db[parms->dir];
+       fparms.subtype = parms->type;
        fparms.index = parms->id;
        rc = tf_rm_free(&fparms);
        if (rc) {
@@ -279,26 +297,30 @@ tf_ident_search(struct tf *tfp __rte_unused,
        struct tf_shadow_ident_search_parms sparms = { 0 };
        int allocated = 0;
        uint32_t base_id;
+       struct ident_rm_db *ident_db;
+       void *ident_db_ptr = NULL;
 
        TF_CHECK_PARMS2(tfp, parms);
 
-       if (!init) {
+       if (!shadow_init) {
                TFP_DRV_LOG(ERR,
-                           "%s: No Identifier DBs created\n",
+                           "%s: Identifier Shadow copy is not enabled\n",
                            tf_dir_2_str(parms->dir));
                return -EINVAL;
        }
 
-       if (!shadow_init) {
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_IDENTIFIER, &ident_db_ptr);
+       if (rc) {
                TFP_DRV_LOG(ERR,
-                           "%s: Identifier Shadow copy is not enabled\n",
-                           tf_dir_2_str(parms->dir));
-               return -EINVAL;
+                           "Failed to get ident_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
        }
+       ident_db = (struct ident_rm_db *)ident_db_ptr;
 
        /* Check if element is in use */
-       aparms.rm_db = ident_db[parms->dir];
-       aparms.db_index = parms->type;
+       aparms.rm_db = ident_db->ident_db[parms->dir];
+       aparms.subtype = parms->type;
        aparms.index = parms->search_id;
        aparms.base_index = &base_id;
        aparms.allocated = &allocated;
@@ -332,3 +354,39 @@ tf_ident_search(struct tf *tfp __rte_unused,
 
        return 0;
 }
+
+int
+tf_ident_get_resc_info(struct tf *tfp,
+                      struct tf_identifier_resource_info *ident)
+{
+       int rc;
+       int d;
+       struct tf_resource_info *dinfo;
+       struct tf_rm_get_alloc_info_parms ainfo;
+       void *ident_db_ptr = NULL;
+       struct ident_rm_db *ident_db;
+
+       TF_CHECK_PARMS2(tfp, ident);
+
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_IDENTIFIER, &ident_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(INFO,
+                           "No resource allocated for ident from session\n");
+               return 0;
+       }
+       ident_db = (struct ident_rm_db *)ident_db_ptr;
+
+       /* check if reserved resource for WC is multiple of num_slices */
+       for (d = 0; d < TF_DIR_MAX; d++) {
+               ainfo.rm_db = ident_db->ident_db[d];
+               dinfo = ident[d].info;
+
+               ainfo.info = (struct tf_rm_alloc_info *)dinfo;
+               ainfo.subtype = 0;
+               rc = tf_rm_get_all_info(&ainfo, TF_IDENT_TYPE_MAX);
+               if (rc)
+                       return rc;
+       }
+
+       return 0;
+}