net/bnxt: decrease log level of a debug message
[dpdk.git] / drivers / net / bnxt / tf_core / tf_tcam.c
index 1b5c298..273f208 100644 (file)
 
 struct tf;
 
-/**
- * TCAM DBs.
- */
-static void *tcam_db[TF_DIR_MAX];
-
 /**
  * TCAM Shadow DBs
  */
 static void *shadow_tcam_db[TF_DIR_MAX];
 
-/**
- * Init flag, set on bind and cleared on unbind
- */
-static uint8_t init;
-
 /**
  * Shadow init flag, set on bind and cleared on unbind
  */
@@ -43,6 +33,7 @@ tf_tcam_bind(struct tf *tfp,
             struct tf_tcam_cfg_parms *parms)
 {
        int rc;
+       int db_rc[TF_DIR_MAX] = { 0 };
        int i, d;
        struct tf_rm_alloc_info info;
        struct tf_rm_free_db_parms fparms;
@@ -52,18 +43,14 @@ tf_tcam_bind(struct tf *tfp,
        struct tf_shadow_tcam_free_db_parms fshadow;
        struct tf_shadow_tcam_cfg_parms shadow_cfg;
        struct tf_shadow_tcam_create_db_parms shadow_cdb;
-       uint16_t num_slices = 1;
+       uint16_t num_slices = parms->wc_num_slices;
        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);
 
-       if (init) {
-               TFP_DRV_LOG(ERR,
-                           "TCAM DB already initialized\n");
-               return -EINVAL;
-       }
-
        /* Retrieve the session information */
        rc = tf_session_get_session_internal(tfp, &tfs);
        if (rc)
@@ -74,7 +61,7 @@ tf_tcam_bind(struct tf *tfp,
        if (rc)
                return rc;
 
-       if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
+       if (dev->ops->tf_dev_set_tcam_slice_info == NULL) {
                rc = -EOPNOTSUPP;
                TFP_DRV_LOG(ERR,
                            "Operation not supported, rc:%s\n",
@@ -82,10 +69,8 @@ tf_tcam_bind(struct tf *tfp,
                return rc;
        }
 
-       rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
-                                                 TF_TCAM_TBL_TYPE_WC_TCAM,
-                                                 0,
-                                                 &num_slices);
+       rc = dev->ops->tf_dev_set_tcam_slice_info(tfp,
+                                                 num_slices);
        if (rc)
                return rc;
 
@@ -99,6 +84,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,20 +105,27 @@ 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];
-               rc = tf_rm_create_db(tfp, &db_cfg);
-               if (rc) {
-                       TFP_DRV_LOG(ERR,
-                                   "%s: TCAM DB creation failed\n",
-                                   tf_dir_2_str(d));
-                       return rc;
-               }
+               db_cfg.rm_db = (void *)&tcam_db->tcam_db[d];
+               if (tf_session_is_shared_session(tfs) &&
+                       (!tf_session_is_shared_session_creator(tfs)))
+                       db_rc[d] = tf_rm_create_db_no_reservation(tfp, &db_cfg);
+               else
+                       db_rc[d] = tf_rm_create_db(tfp, &db_cfg);
+       }
+
+       /* No db created */
+       if (db_rc[TF_DIR_RX] && db_rc[TF_DIR_TX]) {
+               TFP_DRV_LOG(ERR, "No TCAM DB created\n");
+               return db_rc[TF_DIR_RX];
        }
 
        /* check if reserved resource for WC is multiple of num_slices */
        for (d = 0; d < TF_DIR_MAX; d++) {
+               if (!tcam_db->tcam_db[d])
+                       continue;
+
                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);
@@ -133,7 +138,8 @@ tf_tcam_bind(struct tf *tfp,
                                    "%s: TCAM reserved resource is not multiple of %d\n",
                                    tf_dir_2_str(d),
                                    num_slices);
-                       return -EINVAL;
+                       rc = -EINVAL;
+                       goto error;
                }
        }
 
@@ -148,7 +154,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);
@@ -176,8 +182,6 @@ tf_tcam_bind(struct tf *tfp,
                shadow_init = 1;
        }
 
-       init = 1;
-
        TFP_DRV_LOG(INFO,
                    "TCAM - initialized\n");
 
@@ -186,7 +190,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,11 +200,11 @@ 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;
-       init = 0;
 
        return rc;
 }
@@ -211,25 +215,28 @@ 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);
 
-       /* Bail if nothing has been initialized */
-       if (!init) {
-               TFP_DRV_LOG(INFO,
-                           "No TCAM DBs created\n");
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
+       if (rc) {
                return 0;
        }
+       tcam_db = (struct tcam_rm_db *)tcam_db_ptr;
 
        for (i = 0; i < TF_DIR_MAX; i++) {
+               if (tcam_db->tcam_db[i] == NULL)
+                       continue;
                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));
@@ -241,7 +248,6 @@ tf_tcam_unbind(struct tf *tfp)
        }
 
        shadow_init = 0;
-       init = 0;
 
        return 0;
 }
@@ -256,16 +262,11 @@ 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);
 
-       if (!init) {
-               TFP_DRV_LOG(ERR,
-                           "%s: No TCAM DBs created\n",
-                           tf_dir_2_str(parms->dir));
-               return -EINVAL;
-       }
-
        /* Retrieve the session information */
        rc = tf_session_get_session_internal(tfp, &tfs);
        if (rc)
@@ -293,13 +294,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 tcam_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;
@@ -313,8 +323,12 @@ tf_tcam_alloc(struct tf *tfp,
                }
 
                /* return the start index of each row */
-               if (i == 0)
+               if (parms->priority == 0) {
+                       if (i == 0)
+                               parms->idx = index;
+               } else {
                        parms->idx = index;
+               }
        }
 
        return 0;
@@ -334,16 +348,11 @@ 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);
 
-       if (!init) {
-               TFP_DRV_LOG(ERR,
-                           "%s: No TCAM DBs created\n",
-                           tf_dir_2_str(parms->dir));
-               return -EINVAL;
-       }
-
        /* Retrieve the session information */
        rc = tf_session_get_session_internal(tfp, &tfs);
        if (rc)
@@ -379,10 +388,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 +448,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 +465,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;
 
@@ -486,13 +503,6 @@ tf_tcam_alloc_search(struct tf *tfp,
 
        TF_CHECK_PARMS2(tfp, parms);
 
-       if (!init) {
-               TFP_DRV_LOG(ERR,
-                           "%s: No TCAM DBs created\n",
-                           tf_dir_2_str(parms->dir));
-               return -EINVAL;
-       }
-
        if (!shadow_init || !shadow_tcam_db[parms->dir]) {
                TFP_DRV_LOG(ERR, "%s: TCAM Shadow not initialized for %s\n",
                            tf_dir_2_str(parms->dir),
@@ -612,16 +622,11 @@ 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);
 
-       if (!init) {
-               TFP_DRV_LOG(ERR,
-                           "%s: No TCAM DBs created\n",
-                           tf_dir_2_str(parms->dir));
-               return -EINVAL;
-       }
-
        /* Retrieve the session information */
        rc = tf_session_get_session_internal(tfp, &tfs);
        if (rc)
@@ -649,10 +654,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 +686,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,16 +736,11 @@ 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);
 
-       if (!init) {
-               TFP_DRV_LOG(ERR,
-                           "%s: No TCAM DBs created\n",
-                           tf_dir_2_str(parms->dir));
-               return -EINVAL;
-       }
-
        /* Retrieve the session information */
        rc = tf_session_get_session_internal(tfp, &tfs);
        if (rc)
@@ -742,10 +751,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 +783,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;
 
@@ -787,3 +805,43 @@ tf_tcam_get(struct tf *tfp __rte_unused,
 
        return 0;
 }
+
+int
+tf_tcam_get_resc_info(struct tf *tfp,
+                     struct tf_tcam_resource_info *tcam)
+{
+       int rc;
+       int d;
+       struct tf_resource_info *dinfo;
+       struct tf_rm_get_alloc_info_parms ainfo;
+       void *tcam_db_ptr = NULL;
+       struct tcam_rm_db *tcam_db;
+
+       TF_CHECK_PARMS2(tfp, tcam);
+
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
+       if (rc == -ENOMEM)
+               return 0;  /* db doesn't exist */
+       else if (rc)
+               return rc; /* error getting db */
+
+       tcam_db = (struct tcam_rm_db *)tcam_db_ptr;
+
+       /* check if reserved resource for WC is multiple of num_slices */
+       for (d = 0; d < TF_DIR_MAX; d++) {
+               ainfo.rm_db = tcam_db->tcam_db[d];
+
+               if (!ainfo.rm_db)
+                       continue;
+
+               dinfo = tcam[d].info;
+
+               ainfo.info = (struct tf_rm_alloc_info *)dinfo;
+               ainfo.subtype = 0;
+               rc = tf_rm_get_all_info(&ainfo, TF_TCAM_TBL_TYPE_MAX);
+               if (rc && rc != -ENOTSUP)
+                       return rc;
+       }
+
+       return 0;
+}