net/bnxt: change RM database type
authorJay Ding <jay.ding@broadcom.com>
Sun, 30 May 2021 08:58:44 +0000 (14:28 +0530)
committerAjit Khaparde <ajit.khaparde@broadcom.com>
Thu, 8 Jul 2021 00:01:49 +0000 (02:01 +0200)
RM databases are statically defined in each module. New static
database needs to be defined in the code when multiple sessions
are added. Add dynamic alloc database and associate it to each
session.

Signed-off-by: Jay Ding <jay.ding@broadcom.com>
Signed-off-by: Randy Schacher <stuart.schacher@broadcom.com>
Signed-off-by: Venkat Duvvuru <venkatkumar.duvvuru@broadcom.com>
Reviewed-by: Farah Smith <farah.smith@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
drivers/net/bnxt/tf_core/tf_em.h
drivers/net/bnxt/tf_core/tf_em_internal.c
drivers/net/bnxt/tf_core/tf_identifier.c
drivers/net/bnxt/tf_core/tf_identifier.h
drivers/net/bnxt/tf_core/tf_tbl.c
drivers/net/bnxt/tf_core/tf_tbl.h
drivers/net/bnxt/tf_core/tf_tcam.c
drivers/net/bnxt/tf_core/tf_tcam.h

index 2de1862..19ad7f1 100644 (file)
@@ -133,6 +133,16 @@ struct tf_em_cfg_parms {
        enum tf_mem_type mem_type;
 };
 
+/**
+ * EM database
+ *
+ * EM rm database
+ *
+ */
+struct em_rm_db {
+       struct rm_db *em_db[TF_DIR_MAX];
+};
+
 /**
  * @page em EM
  *
index 043f9be..5a100ef 100644 (file)
 
 #include "bnxt.h"
 
-/**
- * EM DBs.
- */
-static void *em_db[TF_DIR_MAX];
-
 #define TF_EM_DB_EM_REC 0
 
 /**
@@ -242,6 +237,8 @@ tf_em_int_bind(struct tf *tfp,
        uint8_t db_exists = 0;
        struct tf_rm_get_alloc_info_parms iparms;
        struct tf_rm_alloc_info info;
+       struct em_rm_db *em_db;
+       struct tfp_calloc_parms cparms;
 
        TF_CHECK_PARMS2(tfp, parms);
 
@@ -251,6 +248,21 @@ tf_em_int_bind(struct tf *tfp,
                return -EINVAL;
        }
 
+       memset(&db_cfg, 0, sizeof(db_cfg));
+       cparms.nitems = 1;
+       cparms.size = sizeof(struct em_rm_db);
+       cparms.alignment = 0;
+       if (tfp_calloc(&cparms) != 0) {
+               TFP_DRV_LOG(ERR, "em_rm_db alloc error %s\n",
+                           strerror(ENOMEM));
+               return -ENOMEM;
+       }
+
+       em_db = cparms.mem_va;
+       for (i = 0; i < TF_DIR_MAX; i++)
+               em_db->em_db[i] = NULL;
+       tf_session_set_db(tfp, TF_MODULE_TYPE_EM, em_db);
+
        db_cfg.module = TF_MODULE_TYPE_EM;
        db_cfg.num_elements = parms->num_elements;
        db_cfg.cfg = parms->cfg;
@@ -277,7 +289,8 @@ tf_em_int_bind(struct tf *tfp,
                        return rc;
                }
 
-               db_cfg.rm_db = &em_db[i];
+               db_cfg.rm_db = (void *)&em_db->em_db[i];
+
                rc = tf_rm_create_db(tfp, &db_cfg);
                if (rc) {
                        TFP_DRV_LOG(ERR,
@@ -293,7 +306,7 @@ tf_em_int_bind(struct tf *tfp,
                init = 1;
 
        for (i = 0; i < TF_DIR_MAX; i++) {
-               iparms.rm_db = em_db[i];
+               iparms.rm_db = em_db->em_db[i];
                iparms.subtype = TF_EM_DB_EM_REC;
                iparms.info = &info;
 
@@ -323,6 +336,8 @@ tf_em_int_unbind(struct tf *tfp)
        int rc;
        int i;
        struct tf_rm_free_db_parms fparms = { 0 };
+       struct em_rm_db *em_db;
+       void *em_db_ptr = NULL;
 
        TF_CHECK_PARMS1(tfp);
 
@@ -336,16 +351,25 @@ tf_em_int_unbind(struct tf *tfp)
        for (i = 0; i < TF_DIR_MAX; i++)
                tf_free_em_pool(i);
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_EM, &em_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       em_db = (struct em_rm_db *)em_db_ptr;
+
        for (i = 0; i < TF_DIR_MAX; i++) {
                fparms.dir = i;
-               fparms.rm_db = em_db[i];
-               if (em_db[i] != NULL) {
+               fparms.rm_db = em_db->em_db[i];
+               if (em_db->em_db[i] != NULL) {
                        rc = tf_rm_free_db(tfp, &fparms);
                        if (rc)
                                return rc;
                }
 
-               em_db[i] = NULL;
+               em_db->em_db[i] = NULL;
        }
 
        init = 0;
index 9d0a578..ee68b6c 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
  */
@@ -43,6 +39,8 @@ tf_ident_bind(struct tf *tfp,
        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;
 
        TF_CHECK_PARMS2(tfp, parms);
 
@@ -52,14 +50,29 @@ tf_ident_bind(struct tf *tfp,
                return -EINVAL;
        }
 
+       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;
+       }
+
+       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,
@@ -102,6 +115,8 @@ 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);
 
@@ -112,9 +127,18 @@ tf_ident_unbind(struct tf *tfp)
                return 0;
        }
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_IDENTIFIER, &ident_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get ident_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       ident_db = (struct ident_rm_db *)ident_db_ptr;
+
        for (i = 0; i < TF_DIR_MAX; i++) {
+               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,7 +155,7 @@ tf_ident_unbind(struct tf *tfp)
                        }
                        ident_shadow_db[i] = NULL;
                }
-               ident_db[i] = NULL;
+               ident_db->ident_db[i] = NULL;
        }
 
        init = 0;
@@ -149,6 +173,8 @@ 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);
 
@@ -159,8 +185,16 @@ tf_ident_alloc(struct tf *tfp __rte_unused,
                return -EINVAL;
        }
 
-       /* Allocate requested element */
-       aparms.rm_db = ident_db[parms->dir];
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_IDENTIFIER, &ident_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get ident_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       ident_db = (struct ident_rm_db *)ident_db_ptr;
+
+       aparms.rm_db = ident_db->ident_db[parms->dir];
        aparms.subtype = parms->type;
        aparms.index = &id;
        aparms.base_index = &base_id;
@@ -203,6 +237,8 @@ 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);
 
@@ -213,8 +249,17 @@ tf_ident_free(struct tf *tfp __rte_unused,
                return -EINVAL;
        }
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_IDENTIFIER, &ident_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "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.rm_db = ident_db->ident_db[parms->dir];
        aparms.subtype = parms->type;
        aparms.index = parms->id;
        aparms.base_index = &base_id;
@@ -254,7 +299,7 @@ tf_ident_free(struct tf *tfp __rte_unused,
        }
 
        /* Free requested element */
-       fparms.rm_db = ident_db[parms->dir];
+       fparms.rm_db = ident_db->ident_db[parms->dir];
        fparms.subtype = parms->type;
        fparms.index = parms->id;
        rc = tf_rm_free(&fparms);
@@ -279,6 +324,8 @@ 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);
 
@@ -296,8 +343,17 @@ tf_ident_search(struct tf *tfp __rte_unused,
                return -EINVAL;
        }
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_IDENTIFIER, &ident_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "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.rm_db = ident_db->ident_db[parms->dir];
        aparms.subtype = parms->type;
        aparms.index = parms->search_id;
        aparms.base_index = &base_id;
index 2700416..54cecbf 100644 (file)
@@ -99,6 +99,16 @@ struct tf_ident_search_parms {
        uint32_t *ref_cnt;
 };
 
+/**
+ * Identifier database
+ *
+ * Identifier rm database
+ *
+ */
+struct ident_rm_db {
+       struct rm_db *ident_db[TF_DIR_MAX];
+};
+
 /**
  * @page ident Identity Management
  *
index 75dbe20..2d0dda1 100644 (file)
 
 struct tf;
 
-/**
- * Table DBs.
- */
-static void *tbl_db[TF_DIR_MAX];
-
 /**
  * Table Shadow DBs
  */
@@ -50,8 +45,10 @@ int
 tf_tbl_bind(struct tf *tfp,
            struct tf_tbl_cfg_parms *parms)
 {
-       int rc, d;
+       int rc, d, i;
        struct tf_rm_create_db_parms db_cfg = { 0 };
+       struct tbl_rm_db *tbl_db;
+       struct tfp_calloc_parms cparms;
 
        TF_CHECK_PARMS2(tfp, parms);
 
@@ -61,6 +58,21 @@ tf_tbl_bind(struct tf *tfp,
                return -EINVAL;
        }
 
+       memset(&db_cfg, 0, sizeof(db_cfg));
+       cparms.nitems = 1;
+       cparms.size = sizeof(struct tbl_rm_db);
+       cparms.alignment = 0;
+       if (tfp_calloc(&cparms) != 0) {
+               TFP_DRV_LOG(ERR, "tbl_rm_db alloc error %s\n",
+                           strerror(ENOMEM));
+               return -ENOMEM;
+       }
+
+       tbl_db = cparms.mem_va;
+       for (i = 0; i < TF_DIR_MAX; i++)
+               tbl_db->tbl_db[i] = NULL;
+       tf_session_set_db(tfp, TF_MODULE_TYPE_TABLE, tbl_db);
+
        db_cfg.num_elements = parms->num_elements;
        db_cfg.module = TF_MODULE_TYPE_TABLE;
        db_cfg.num_elements = parms->num_elements;
@@ -69,7 +81,8 @@ tf_tbl_bind(struct tf *tfp,
        for (d = 0; d < TF_DIR_MAX; d++) {
                db_cfg.dir = d;
                db_cfg.alloc_cnt = parms->resources->tbl_cnt[d].cnt;
-               db_cfg.rm_db = &tbl_db[d];
+               db_cfg.rm_db = (void *)&tbl_db->tbl_db[d];
+
                rc = tf_rm_create_db(tfp, &db_cfg);
                if (rc) {
                        TFP_DRV_LOG(ERR,
@@ -79,7 +92,6 @@ tf_tbl_bind(struct tf *tfp,
                        return rc;
                }
        }
-
        init = 1;
 
        TFP_DRV_LOG(INFO,
@@ -94,6 +106,8 @@ tf_tbl_unbind(struct tf *tfp)
        int rc;
        int i;
        struct tf_rm_free_db_parms fparms = { 0 };
+       struct tbl_rm_db *tbl_db;
+       void *tbl_db_ptr = NULL;
        TF_CHECK_PARMS1(tfp);
 
        /* Bail if nothing has been initialized */
@@ -103,14 +117,23 @@ tf_tbl_unbind(struct tf *tfp)
                return 0;
        }
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+
        for (i = 0; i < TF_DIR_MAX; i++) {
                fparms.dir = i;
-               fparms.rm_db = tbl_db[i];
+               fparms.rm_db = tbl_db->tbl_db[i];
                rc = tf_rm_free_db(tfp, &fparms);
                if (rc)
                        return rc;
 
-               tbl_db[i] = NULL;
+               tbl_db->tbl_db[i] = NULL;
        }
 
        init = 0;
@@ -129,6 +152,8 @@ tf_tbl_alloc(struct tf *tfp __rte_unused,
        struct tf_session *tfs;
        struct tf_dev_info *dev;
        uint16_t base = 0, shift = 0;
+       struct tbl_rm_db *tbl_db;
+       void *tbl_db_ptr = NULL;
 
        TF_CHECK_PARMS2(tfp, parms);
 
@@ -149,10 +174,22 @@ tf_tbl_alloc(struct tf *tfp __rte_unused,
        if (rc)
                return rc;
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+
        /* Only get table info if required for the device */
        if (dev->ops->tf_dev_get_tbl_info) {
-               rc = dev->ops->tf_dev_get_tbl_info(tfp, tbl_db[parms->dir],
-                                                  parms->type, &base, &shift);
+               rc = dev->ops->tf_dev_get_tbl_info(tfp,
+                                                  tbl_db->tbl_db[parms->dir],
+                                                  parms->type,
+                                                  &base,
+                                                  &shift);
                if (rc) {
                        TFP_DRV_LOG(ERR,
                                    "%s: Failed to get table info:%d\n",
@@ -163,7 +200,7 @@ tf_tbl_alloc(struct tf *tfp __rte_unused,
        }
 
        /* Allocate requested element */
-       aparms.rm_db = tbl_db[parms->dir];
+       aparms.rm_db = tbl_db->tbl_db[parms->dir];
        aparms.subtype = parms->type;
        aparms.index = &idx;
        rc = tf_rm_allocate(&aparms);
@@ -192,6 +229,8 @@ tf_tbl_free(struct tf *tfp __rte_unused,
        struct tf_session *tfs;
        struct tf_dev_info *dev;
        uint16_t base = 0, shift = 0;
+       struct tbl_rm_db *tbl_db;
+       void *tbl_db_ptr = NULL;
 
        TF_CHECK_PARMS2(tfp, parms);
 
@@ -211,10 +250,22 @@ tf_tbl_free(struct tf *tfp __rte_unused,
        if (rc)
                return rc;
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+
        /* Only get table info if required for the device */
        if (dev->ops->tf_dev_get_tbl_info) {
-               rc = dev->ops->tf_dev_get_tbl_info(tfp, tbl_db[parms->dir],
-                                                  parms->type, &base, &shift);
+               rc = dev->ops->tf_dev_get_tbl_info(tfp,
+                                                  tbl_db->tbl_db[parms->dir],
+                                                  parms->type,
+                                                  &base,
+                                                  &shift);
                if (rc) {
                        TFP_DRV_LOG(ERR,
                                    "%s: Failed to get table info:%d\n",
@@ -225,7 +276,7 @@ tf_tbl_free(struct tf *tfp __rte_unused,
        }
 
        /* Check if element is in use */
-       aparms.rm_db = tbl_db[parms->dir];
+       aparms.rm_db = tbl_db->tbl_db[parms->dir];
        aparms.subtype = parms->type;
 
        TF_TBL_PTR_TO_RM(&aparms.index, parms->idx, base, shift);
@@ -244,7 +295,7 @@ tf_tbl_free(struct tf *tfp __rte_unused,
                return -EINVAL;
        }
        /* Free requested element */
-       fparms.rm_db = tbl_db[parms->dir];
+       fparms.rm_db = tbl_db->tbl_db[parms->dir];
        fparms.subtype = parms->type;
 
        TF_TBL_PTR_TO_RM(&fparms.index, parms->idx, base, shift);
@@ -290,6 +341,8 @@ tf_tbl_set(struct tf *tfp,
        struct tf_session *tfs;
        struct tf_dev_info *dev;
        uint16_t base = 0, shift = 0;
+       struct tbl_rm_db *tbl_db;
+       void *tbl_db_ptr = NULL;
 
        TF_CHECK_PARMS3(tfp, parms, parms->data);
 
@@ -310,10 +363,22 @@ tf_tbl_set(struct tf *tfp,
        if (rc)
                return rc;
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+
        /* Only get table info if required for the device */
        if (dev->ops->tf_dev_get_tbl_info) {
-               rc = dev->ops->tf_dev_get_tbl_info(tfp, tbl_db[parms->dir],
-                                                  parms->type, &base, &shift);
+               rc = dev->ops->tf_dev_get_tbl_info(tfp,
+                                                  tbl_db->tbl_db[parms->dir],
+                                                  parms->type,
+                                                  &base,
+                                                  &shift);
                if (rc) {
                        TFP_DRV_LOG(ERR,
                                    "%s: Failed to get table info:%d\n",
@@ -324,7 +389,7 @@ tf_tbl_set(struct tf *tfp,
        }
 
        /* Verify that the entry has been previously allocated */
-       aparms.rm_db = tbl_db[parms->dir];
+       aparms.rm_db = tbl_db->tbl_db[parms->dir];
        aparms.subtype = parms->type;
        TF_TBL_PTR_TO_RM(&aparms.index, parms->idx, base, shift);
 
@@ -343,7 +408,7 @@ tf_tbl_set(struct tf *tfp,
        }
 
        /* Set the entry */
-       hparms.rm_db = tbl_db[parms->dir];
+       hparms.rm_db = tbl_db->tbl_db[parms->dir];
        hparms.subtype = parms->type;
        hparms.hcapi_type = &hcapi_type;
        rc = tf_rm_get_hcapi_type(&hparms);
@@ -386,6 +451,8 @@ tf_tbl_get(struct tf *tfp,
        struct tf_session *tfs;
        struct tf_dev_info *dev;
        uint16_t base = 0, shift = 0;
+       struct tbl_rm_db *tbl_db;
+       void *tbl_db_ptr = NULL;
 
        TF_CHECK_PARMS3(tfp, parms, parms->data);
 
@@ -407,10 +474,22 @@ tf_tbl_get(struct tf *tfp,
        if (rc)
                return rc;
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+
        /* Only get table info if required for the device */
        if (dev->ops->tf_dev_get_tbl_info) {
-               rc = dev->ops->tf_dev_get_tbl_info(tfp, tbl_db[parms->dir],
-                                                  parms->type, &base, &shift);
+               rc = dev->ops->tf_dev_get_tbl_info(tfp,
+                                                  tbl_db->tbl_db[parms->dir],
+                                                  parms->type,
+                                                  &base,
+                                                  &shift);
                if (rc) {
                        TFP_DRV_LOG(ERR,
                                    "%s: Failed to get table info:%d\n",
@@ -421,7 +500,7 @@ tf_tbl_get(struct tf *tfp,
        }
 
        /* Verify that the entry has been previously allocated */
-       aparms.rm_db = tbl_db[parms->dir];
+       aparms.rm_db = tbl_db->tbl_db[parms->dir];
        aparms.subtype = parms->type;
        TF_TBL_PTR_TO_RM(&aparms.index, parms->idx, base, shift);
 
@@ -440,7 +519,7 @@ tf_tbl_get(struct tf *tfp,
        }
 
        /* Set the entry */
-       hparms.rm_db = tbl_db[parms->dir];
+       hparms.rm_db = tbl_db->tbl_db[parms->dir];
        hparms.subtype = parms->type;
        hparms.hcapi_type = &hcapi_type;
        rc = tf_rm_get_hcapi_type(&hparms);
@@ -483,6 +562,8 @@ tf_tbl_bulk_get(struct tf *tfp,
        struct tf_session *tfs;
        struct tf_dev_info *dev;
        uint16_t base = 0, shift = 0;
+       struct tbl_rm_db *tbl_db;
+       void *tbl_db_ptr = NULL;
 
        TF_CHECK_PARMS2(tfp, parms);
 
@@ -504,10 +585,22 @@ tf_tbl_bulk_get(struct tf *tfp,
        if (rc)
                return rc;
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+
        /* Only get table info if required for the device */
        if (dev->ops->tf_dev_get_tbl_info) {
-               rc = dev->ops->tf_dev_get_tbl_info(tfp, tbl_db[parms->dir],
-                                                  parms->type, &base, &shift);
+               rc = dev->ops->tf_dev_get_tbl_info(tfp,
+                                                  tbl_db->tbl_db[parms->dir],
+                                                  parms->type,
+                                                  &base,
+                                                  &shift);
                if (rc) {
                        TFP_DRV_LOG(ERR,
                                    "%s: Failed to get table info:%d\n",
@@ -518,7 +611,7 @@ tf_tbl_bulk_get(struct tf *tfp,
        }
 
        /* Verify that the entries are in the range of reserved resources. */
-       cparms.rm_db = tbl_db[parms->dir];
+       cparms.rm_db = tbl_db->tbl_db[parms->dir];
        cparms.subtype = parms->type;
 
        TF_TBL_PTR_TO_RM(&cparms.starting_index, parms->starting_idx,
@@ -538,7 +631,7 @@ tf_tbl_bulk_get(struct tf *tfp,
                return rc;
        }
 
-       hparms.rm_db = tbl_db[parms->dir];
+       hparms.rm_db = tbl_db->tbl_db[parms->dir];
        hparms.subtype = parms->type;
        hparms.hcapi_type = &hcapi_type;
        rc = tf_rm_get_hcapi_type(&hparms);
index 9271cf2..83b72d1 100644 (file)
@@ -229,6 +229,16 @@ struct tf_tbl_get_bulk_parms {
        uint64_t physical_mem_addr;
 };
 
+/**
+ * Table RM database
+ *
+ * Table rm database
+ *
+ */
+struct tbl_rm_db {
+       struct rm_db *tbl_db[TF_DIR_MAX];
+};
+
 /**
  * @page tbl Table
  *
index 1b5c298..c2eef26 100644 (file)
 
 struct tf;
 
-/**
- * TCAM DBs.
- */
-static void *tcam_db[TF_DIR_MAX];
-
 /**
  * TCAM Shadow DBs
  */
@@ -55,6 +50,8 @@ tf_tcam_bind(struct tf *tfp,
        uint16_t num_slices = 1;
        struct tf_session *tfs;
        struct tf_dev_info *dev;
+       struct tcam_rm_db *tcam_db;
+       struct tfp_calloc_parms cparms;
 
        TF_CHECK_PARMS2(tfp, parms);
 
@@ -99,6 +96,19 @@ tf_tcam_bind(struct tf *tfp,
        }
 
        memset(&db_cfg, 0, sizeof(db_cfg));
+       cparms.nitems = 1;
+       cparms.size = sizeof(struct tcam_rm_db);
+       cparms.alignment = 0;
+       if (tfp_calloc(&cparms) != 0) {
+               TFP_DRV_LOG(ERR, "tcam_rm_db alloc error %s\n",
+                           strerror(ENOMEM));
+               return -ENOMEM;
+       }
+
+       tcam_db = cparms.mem_va;
+       for (i = 0; i < TF_DIR_MAX; i++)
+               tcam_db->tcam_db[i] = NULL;
+       tf_session_set_db(tfp, TF_MODULE_TYPE_TCAM, tcam_db);
 
        db_cfg.module = TF_MODULE_TYPE_TCAM;
        db_cfg.num_elements = parms->num_elements;
@@ -107,7 +117,7 @@ tf_tcam_bind(struct tf *tfp,
        for (d = 0; d < TF_DIR_MAX; d++) {
                db_cfg.dir = d;
                db_cfg.alloc_cnt = parms->resources->tcam_cnt[d].cnt;
-               db_cfg.rm_db = &tcam_db[d];
+               db_cfg.rm_db = (void *)&tcam_db->tcam_db[d];
                rc = tf_rm_create_db(tfp, &db_cfg);
                if (rc) {
                        TFP_DRV_LOG(ERR,
@@ -120,7 +130,7 @@ tf_tcam_bind(struct tf *tfp,
        /* check if reserved resource for WC is multiple of num_slices */
        for (d = 0; d < TF_DIR_MAX; d++) {
                memset(&info, 0, sizeof(info));
-               ainfo.rm_db = tcam_db[d];
+               ainfo.rm_db = tcam_db->tcam_db[d];
                ainfo.subtype = TF_TCAM_TBL_TYPE_WC_TCAM;
                ainfo.info = &info;
                rc = tf_rm_get_info(&ainfo);
@@ -148,7 +158,7 @@ tf_tcam_bind(struct tf *tfp,
 
                                if (!parms->resources->tcam_cnt[d].cnt[i])
                                        continue;
-                               ainfo.rm_db = tcam_db[d];
+                               ainfo.rm_db = tcam_db->tcam_db[d];
                                ainfo.subtype = i;
                                ainfo.info = &info;
                                rc = tf_rm_get_info(&ainfo);
@@ -186,7 +196,7 @@ error:
        for (i = 0; i < TF_DIR_MAX; i++) {
                memset(&fparms, 0, sizeof(fparms));
                fparms.dir = i;
-               fparms.rm_db = tcam_db[i];
+               fparms.rm_db = tcam_db->tcam_db[i];
                /* Ignoring return here since we are in the error case */
                (void)tf_rm_free_db(tfp, &fparms);
 
@@ -196,7 +206,8 @@ error:
                        shadow_tcam_db[i] = NULL;
                }
 
-               tcam_db[i] = NULL;
+               tcam_db->tcam_db[i] = NULL;
+               tf_session_set_db(tfp, TF_MODULE_TYPE_TCAM, NULL);
        }
 
        shadow_init = 0;
@@ -211,6 +222,8 @@ tf_tcam_unbind(struct tf *tfp)
        int rc;
        int i;
        struct tf_rm_free_db_parms fparms;
+       struct tcam_rm_db *tcam_db;
+       void *tcam_db_ptr = NULL;
        struct tf_shadow_tcam_free_db_parms fshadow;
        TF_CHECK_PARMS1(tfp);
 
@@ -221,15 +234,24 @@ tf_tcam_unbind(struct tf *tfp)
                return 0;
        }
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tcam_db = (struct tcam_rm_db *)tcam_db_ptr;
+
        for (i = 0; i < TF_DIR_MAX; i++) {
                memset(&fparms, 0, sizeof(fparms));
                fparms.dir = i;
-               fparms.rm_db = tcam_db[i];
+               fparms.rm_db = tcam_db->tcam_db[i];
                rc = tf_rm_free_db(tfp, &fparms);
                if (rc)
                        return rc;
 
-               tcam_db[i] = NULL;
+               tcam_db->tcam_db[i] = NULL;
 
                if (shadow_init) {
                        memset(&fshadow, 0, sizeof(fshadow));
@@ -256,6 +278,8 @@ tf_tcam_alloc(struct tf *tfp,
        struct tf_rm_allocate_parms aparms;
        uint16_t num_slices = 1;
        uint32_t index;
+       struct tcam_rm_db *tcam_db;
+       void *tcam_db_ptr = NULL;
 
        TF_CHECK_PARMS2(tfp, parms);
 
@@ -293,13 +317,22 @@ tf_tcam_alloc(struct tf *tfp,
        if (rc)
                return rc;
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tcam_db = (struct tcam_rm_db *)tcam_db_ptr;
+
        /*
         * For WC TCAM, number of slices could be 4, 2, 1 based on
         * the key_size. For other TCAM, it is always 1
         */
        for (i = 0; i < num_slices; i++) {
                memset(&aparms, 0, sizeof(aparms));
-               aparms.rm_db = tcam_db[parms->dir];
+               aparms.rm_db = tcam_db->tcam_db[parms->dir];
                aparms.subtype = parms->type;
                aparms.priority = parms->priority;
                aparms.index = &index;
@@ -334,6 +367,8 @@ tf_tcam_free(struct tf *tfp,
        int allocated = 0;
        struct tf_shadow_tcam_remove_parms shparms;
        int i;
+       struct tcam_rm_db *tcam_db;
+       void *tcam_db_ptr = NULL;
 
        TF_CHECK_PARMS2(tfp, parms);
 
@@ -379,10 +414,18 @@ tf_tcam_free(struct tf *tfp,
                return -EINVAL;
        }
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tcam_db = (struct tcam_rm_db *)tcam_db_ptr;
+
        /* Check if element is in use */
        memset(&aparms, 0, sizeof(aparms));
-
-       aparms.rm_db = tcam_db[parms->dir];
+       aparms.rm_db = tcam_db->tcam_db[parms->dir];
        aparms.subtype = parms->type;
        aparms.index = parms->idx;
        aparms.allocated = &allocated;
@@ -431,7 +474,7 @@ tf_tcam_free(struct tf *tfp,
        for (i = 0; i < num_slices; i++) {
                /* Free requested element */
                memset(&fparms, 0, sizeof(fparms));
-               fparms.rm_db = tcam_db[parms->dir];
+               fparms.rm_db = tcam_db->tcam_db[parms->dir];
                fparms.subtype = parms->type;
                fparms.index = parms->idx + i;
                rc = tf_rm_free(&fparms);
@@ -448,7 +491,7 @@ tf_tcam_free(struct tf *tfp,
        /* Convert TF type to HCAPI RM type */
        memset(&hparms, 0, sizeof(hparms));
 
-       hparms.rm_db = tcam_db[parms->dir];
+       hparms.rm_db = tcam_db->tcam_db[parms->dir];
        hparms.subtype = parms->type;
        hparms.hcapi_type = &parms->hcapi_type;
 
@@ -612,6 +655,8 @@ tf_tcam_set(struct tf *tfp __rte_unused,
        struct tf_shadow_tcam_insert_parms iparms;
        uint16_t num_slice_per_row = 1;
        int allocated = 0;
+       struct tcam_rm_db *tcam_db;
+       void *tcam_db_ptr = NULL;
 
        TF_CHECK_PARMS2(tfp, parms);
 
@@ -649,10 +694,19 @@ tf_tcam_set(struct tf *tfp __rte_unused,
        if (rc)
                return rc;
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tcam_db = (struct tcam_rm_db *)tcam_db_ptr;
+
        /* Check if element is in use */
        memset(&aparms, 0, sizeof(aparms));
 
-       aparms.rm_db = tcam_db[parms->dir];
+       aparms.rm_db = tcam_db->tcam_db[parms->dir];
        aparms.subtype = parms->type;
        aparms.index = parms->idx;
        aparms.allocated = &allocated;
@@ -672,7 +726,7 @@ tf_tcam_set(struct tf *tfp __rte_unused,
        /* Convert TF type to HCAPI RM type */
        memset(&hparms, 0, sizeof(hparms));
 
-       hparms.rm_db = tcam_db[parms->dir];
+       hparms.rm_db = tcam_db->tcam_db[parms->dir];
        hparms.subtype = parms->type;
        hparms.hcapi_type = &parms->hcapi_type;
 
@@ -722,6 +776,8 @@ tf_tcam_get(struct tf *tfp __rte_unused,
        struct tf_rm_is_allocated_parms aparms;
        struct tf_rm_get_hcapi_parms hparms;
        int allocated = 0;
+       struct tcam_rm_db *tcam_db;
+       void *tcam_db_ptr = NULL;
 
        TF_CHECK_PARMS2(tfp, parms);
 
@@ -742,10 +798,19 @@ tf_tcam_get(struct tf *tfp __rte_unused,
        if (rc)
                return rc;
 
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tcam_db = (struct tcam_rm_db *)tcam_db_ptr;
+
        /* Check if element is in use */
        memset(&aparms, 0, sizeof(aparms));
 
-       aparms.rm_db = tcam_db[parms->dir];
+       aparms.rm_db = tcam_db->tcam_db[parms->dir];
        aparms.subtype = parms->type;
        aparms.index = parms->idx;
        aparms.allocated = &allocated;
@@ -765,7 +830,7 @@ tf_tcam_get(struct tf *tfp __rte_unused,
        /* Convert TF type to HCAPI RM type */
        memset(&hparms, 0, sizeof(hparms));
 
-       hparms.rm_db = tcam_db[parms->dir];
+       hparms.rm_db = tcam_db->tcam_db[parms->dir];
        hparms.subtype = parms->type;
        hparms.hcapi_type = &parms->hcapi_type;
 
index b550fa4..acab223 100644 (file)
@@ -237,6 +237,16 @@ struct tf_tcam_get_parms {
        uint16_t result_size;
 };
 
+/**
+ * TCAM database
+ *
+ * Tcam rm database
+ *
+ */
+struct tcam_rm_db {
+       struct rm_db *tcam_db[TF_DIR_MAX];
+};
+
 /**
  * @page tcam TCAM
  *