X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fbnxt%2Ftf_core%2Ftf_tbl.c;h=ced59130b2ddea013c8fa7e7eaed6fc2d75d7c3a;hb=aebe3cb74c9046a122e948ef9631988423175cea;hp=75dbe2066f1c9683e601655f71ba4bd6f19daef3;hpb=20339b09cf71bc195dc6cf3facacbc5548505fd5;p=dpdk.git diff --git a/drivers/net/bnxt/tf_core/tf_tbl.c b/drivers/net/bnxt/tf_core/tf_tbl.c index 75dbe2066f..ced59130b2 100644 --- a/drivers/net/bnxt/tf_core/tf_tbl.c +++ b/drivers/net/bnxt/tf_core/tf_tbl.c @@ -26,21 +26,11 @@ struct tf; -/** - * Table DBs. - */ -static void *tbl_db[TF_DIR_MAX]; - /** * Table Shadow DBs */ static void *shadow_tbl_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 */ @@ -50,17 +40,35 @@ int tf_tbl_bind(struct tf *tfp, struct tf_tbl_cfg_parms *parms) { - int rc, d; + int rc, d, i; + int db_rc[TF_DIR_MAX] = { 0 }; struct tf_rm_create_db_parms db_cfg = { 0 }; + struct tbl_rm_db *tbl_db; + struct tfp_calloc_parms cparms; + struct tf_session *tfs; TF_CHECK_PARMS2(tfp, parms); - if (init) { - TFP_DRV_LOG(ERR, - "Table 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 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,18 +77,21 @@ 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]; - rc = tf_rm_create_db(tfp, &db_cfg); - if (rc) { - TFP_DRV_LOG(ERR, - "%s: Table DB creation failed\n", - tf_dir_2_str(d)); - - return rc; - } + db_cfg.rm_db = (void *)&tbl_db->tbl_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); } - init = 1; + /* No db created */ + if (db_rc[TF_DIR_RX] && db_rc[TF_DIR_TX]) { + TFP_DRV_LOG(ERR, + "%s: No Table DB created\n", + tf_dir_2_str(d)); + return db_rc[TF_DIR_RX]; + } TFP_DRV_LOG(INFO, "Table Type - initialized\n"); @@ -94,26 +105,27 @@ 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 */ - if (!init) { - TFP_DRV_LOG(INFO, - "No Table DBs created\n"); + rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr); + if (rc) return 0; - } + tbl_db = (struct tbl_rm_db *)tbl_db_ptr; for (i = 0; i < TF_DIR_MAX; i++) { + if (tbl_db->tbl_db[i] == NULL) + continue; 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; shadow_init = 0; return 0; @@ -129,16 +141,11 @@ 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); - if (!init) { - TFP_DRV_LOG(ERR, - "%s: No Table 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) @@ -149,10 +156,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 +182,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,15 +211,11 @@ 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); - if (!init) { - TFP_DRV_LOG(ERR, - "%s: No Table 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) @@ -211,10 +226,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 +252,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); @@ -243,8 +270,46 @@ tf_tbl_free(struct tf *tfp __rte_unused, parms->idx); return -EINVAL; } + + /* If this is counter table, clear the entry on free */ + if (parms->type == TF_TBL_TYPE_ACT_STATS_64) { + uint8_t data[8] = { 0 }; + uint16_t hcapi_type = 0; + struct tf_rm_get_hcapi_parms hparms = { 0 }; + + /* Get the hcapi type */ + 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); + if (rc) { + TFP_DRV_LOG(ERR, + "%s, Failed type lookup, type:%d, rc:%s\n", + tf_dir_2_str(parms->dir), + parms->type, + strerror(-rc)); + return rc; + } + /* Clear the counter + */ + rc = tf_msg_set_tbl_entry(tfp, + parms->dir, + hcapi_type, + sizeof(data), + data, + parms->idx); + if (rc) { + TFP_DRV_LOG(ERR, + "%s, Set failed, type:%d, rc:%s\n", + tf_dir_2_str(parms->dir), + parms->type, + strerror(-rc)); + return rc; + } + } + /* 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,16 +355,11 @@ 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); - if (!init) { - TFP_DRV_LOG(ERR, - "%s: No Table 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) @@ -310,10 +370,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 +396,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 +415,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,17 +458,11 @@ 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); - if (!init) { - TFP_DRV_LOG(ERR, - "%s: No Table 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) @@ -407,10 +473,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 +499,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 +518,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,17 +561,11 @@ 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); - if (!init) { - TFP_DRV_LOG(ERR, - "%s: No Table 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) @@ -504,10 +576,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 +602,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 +622,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); @@ -569,3 +653,79 @@ tf_tbl_bulk_get(struct tf *tfp, return rc; } + +int +tf_tbl_get_resc_info(struct tf *tfp, + struct tf_tbl_resource_info *tbl) +{ + int rc; + int d, i; + struct tf_resource_info *dinfo; + struct tf_rm_get_alloc_info_parms ainfo; + void *tbl_db_ptr = NULL; + struct tbl_rm_db *tbl_db; + uint16_t base = 0, shift = 0; + struct tf_dev_info *dev; + struct tf_session *tfs; + + TF_CHECK_PARMS2(tfp, tbl); + + /* Retrieve the session information */ + rc = tf_session_get_session_internal(tfp, &tfs); + if (rc) + return rc; + + /* Retrieve the device information */ + rc = tf_session_get_device(tfs, &dev); + if (rc) + return rc; + + rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr); + if (rc == -ENOMEM) + return 0; /* db doesn't exist */ + else if (rc) + return rc; /* error getting db */ + + tbl_db = (struct tbl_rm_db *)tbl_db_ptr; + + /* check if reserved resource for WC is multiple of num_slices */ + for (d = 0; d < TF_DIR_MAX; d++) { + ainfo.rm_db = tbl_db->tbl_db[d]; + dinfo = tbl[d].info; + + if (!ainfo.rm_db) + continue; + + ainfo.info = (struct tf_rm_alloc_info *)dinfo; + ainfo.subtype = 0; + rc = tf_rm_get_all_info(&ainfo, TF_TBL_TYPE_MAX); + if (rc) + return rc; + + if (dev->ops->tf_dev_get_tbl_info) { + /* Adjust all */ + for (i = 0; i < TF_TBL_TYPE_MAX; i++) { + /* Only get table info if required for the device */ + rc = dev->ops->tf_dev_get_tbl_info(tfp, + tbl_db->tbl_db[d], + i, + &base, + &shift); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Failed to get table info:%d\n", + tf_dir_2_str(d), + i); + return rc; + } + if (dinfo[i].stride) + TF_TBL_RM_TO_PTR(&dinfo[i].start, + dinfo[i].start, + base, + shift); + } + } + } + + return 0; +}