From 48d3dff2b98680c6315593e8b6495b64e678b004 Mon Sep 17 00:00:00 2001 From: Michael Wildt Date: Thu, 2 Jul 2020 16:28:05 -0700 Subject: [PATCH] net/bnxt: support multiple device Implement the Identifier, Table Type and the Resource Manager modules. Integrate Resource Manager with HCAPI. Update open/close session. Move to direct msgs for qcaps and resv messages. Signed-off-by: Michael Wildt Signed-off-by: Venkat Duvvuru Reviewed-by: Randy Schacher Reviewed-by: Ajit Khaparde --- drivers/net/bnxt/tf_core/tf_core.c | 751 ++++++++--------------- drivers/net/bnxt/tf_core/tf_core.h | 97 ++- drivers/net/bnxt/tf_core/tf_device.c | 10 +- drivers/net/bnxt/tf_core/tf_device.h | 1 + drivers/net/bnxt/tf_core/tf_device_p4.c | 26 +- drivers/net/bnxt/tf_core/tf_identifier.c | 29 +- drivers/net/bnxt/tf_core/tf_identifier.h | 4 +- drivers/net/bnxt/tf_core/tf_msg.c | 45 +- drivers/net/bnxt/tf_core/tf_msg.h | 1 + drivers/net/bnxt/tf_core/tf_rm_new.c | 225 +++++-- drivers/net/bnxt/tf_core/tf_rm_new.h | 11 +- drivers/net/bnxt/tf_core/tf_session.c | 28 +- drivers/net/bnxt/tf_core/tf_session.h | 2 +- drivers/net/bnxt/tf_core/tf_tbl.c | 611 +----------------- drivers/net/bnxt/tf_core/tf_tbl_type.c | 252 +++++++- drivers/net/bnxt/tf_core/tf_tbl_type.h | 2 +- drivers/net/bnxt/tf_core/tf_tcam.c | 12 +- drivers/net/bnxt/tf_core/tf_util.h | 45 +- drivers/net/bnxt/tf_core/tfp.c | 4 +- 19 files changed, 880 insertions(+), 1276 deletions(-) diff --git a/drivers/net/bnxt/tf_core/tf_core.c b/drivers/net/bnxt/tf_core/tf_core.c index 29522c66ec..3e23d0513b 100644 --- a/drivers/net/bnxt/tf_core/tf_core.c +++ b/drivers/net/bnxt/tf_core/tf_core.c @@ -19,284 +19,15 @@ #include "tf_common.h" #include "hwrm_tf.h" -/** - * Create EM Tbl pool of memory indexes. - * - * [in] session - * Pointer to session - * [in] dir - * direction - * [in] num_entries - * number of entries to write - * - * Return: - * 0 - Success, entry allocated - no search support - * -ENOMEM -EINVAL -EOPNOTSUPP - * - Failure, entry not allocated, out of resources - */ -static int -tf_create_em_pool(struct tf_session *session, - enum tf_dir dir, - uint32_t num_entries) -{ - struct tfp_calloc_parms parms; - uint32_t i, j; - int rc = 0; - struct stack *pool = &session->em_pool[dir]; - - parms.nitems = num_entries; - parms.size = sizeof(uint32_t); - parms.alignment = 0; - - if (tfp_calloc(&parms) != 0) { - TFP_DRV_LOG(ERR, "EM pool allocation failure %s\n", - strerror(-ENOMEM)); - return -ENOMEM; - } - - /* Create empty stack - */ - rc = stack_init(num_entries, (uint32_t *)parms.mem_va, pool); - - if (rc != 0) { - TFP_DRV_LOG(ERR, "EM pool stack init failure %s\n", - strerror(-rc)); - goto cleanup; - } - - /* Fill pool with indexes - */ - j = num_entries - 1; - - for (i = 0; i < num_entries; i++) { - rc = stack_push(pool, j); - if (rc != 0) { - TFP_DRV_LOG(ERR, "EM pool stack push failure %s\n", - strerror(-rc)); - goto cleanup; - } - j--; - } - - if (!stack_is_full(pool)) { - rc = -EINVAL; - TFP_DRV_LOG(ERR, "EM pool stack failure %s\n", - strerror(-rc)); - goto cleanup; - } - - return 0; -cleanup: - tfp_free((void *)parms.mem_va); - return rc; -} - -/** - * Create EM Tbl pool of memory indexes. - * - * [in] session - * Pointer to session - * [in] dir - * direction - * - * Return: - */ -static void -tf_free_em_pool(struct tf_session *session, - enum tf_dir dir) -{ - struct stack *pool = &session->em_pool[dir]; - uint32_t *ptr; - - ptr = stack_items(pool); - - tfp_free(ptr); -} - int -tf_open_session(struct tf *tfp, +tf_open_session(struct tf *tfp, struct tf_open_session_parms *parms) -{ - int rc; - struct tf_session *session; - struct tfp_calloc_parms alloc_parms; - unsigned int domain, bus, slot, device; - uint8_t fw_session_id; - int dir; - - TF_CHECK_PARMS(tfp, parms); - - /* Filter out any non-supported device types on the Core - * side. It is assumed that the Firmware will be supported if - * firmware open session succeeds. - */ - if (parms->device_type != TF_DEVICE_TYPE_WH) { - TFP_DRV_LOG(ERR, - "Unsupported device type %d\n", - parms->device_type); - return -ENOTSUP; - } - - /* Build the beginning of session_id */ - rc = sscanf(parms->ctrl_chan_name, - "%x:%x:%x.%d", - &domain, - &bus, - &slot, - &device); - if (rc != 4) { - TFP_DRV_LOG(ERR, - "Failed to scan device ctrl_chan_name\n"); - return -EINVAL; - } - - /* open FW session and get a new session_id */ - rc = tf_msg_session_open(tfp, - parms->ctrl_chan_name, - &fw_session_id); - if (rc) { - /* Log error */ - if (rc == -EEXIST) - TFP_DRV_LOG(ERR, - "Session is already open, rc:%s\n", - strerror(-rc)); - else - TFP_DRV_LOG(ERR, - "Open message send failed, rc:%s\n", - strerror(-rc)); - - parms->session_id.id = TF_FW_SESSION_ID_INVALID; - return rc; - } - - /* Allocate session */ - alloc_parms.nitems = 1; - alloc_parms.size = sizeof(struct tf_session_info); - alloc_parms.alignment = 0; - rc = tfp_calloc(&alloc_parms); - if (rc) { - /* Log error */ - TFP_DRV_LOG(ERR, - "Failed to allocate session info, rc:%s\n", - strerror(-rc)); - goto cleanup; - } - - tfp->session = (struct tf_session_info *)alloc_parms.mem_va; - - /* Allocate core data for the session */ - alloc_parms.nitems = 1; - alloc_parms.size = sizeof(struct tf_session); - alloc_parms.alignment = 0; - rc = tfp_calloc(&alloc_parms); - if (rc) { - /* Log error */ - TFP_DRV_LOG(ERR, - "Failed to allocate session data, rc:%s\n", - strerror(-rc)); - goto cleanup; - } - - tfp->session->core_data = alloc_parms.mem_va; - - session = (struct tf_session *)tfp->session->core_data; - tfp_memcpy(session->ctrl_chan_name, - parms->ctrl_chan_name, - TF_SESSION_NAME_MAX); - - /* Initialize Session */ - session->dev = NULL; - tf_rm_init(tfp); - - /* Construct the Session ID */ - session->session_id.internal.domain = domain; - session->session_id.internal.bus = bus; - session->session_id.internal.device = device; - session->session_id.internal.fw_session_id = fw_session_id; - - /* Query for Session Config - */ - rc = tf_msg_session_qcfg(tfp); - if (rc) { - TFP_DRV_LOG(ERR, - "Query config message send failed, rc:%s\n", - strerror(-rc)); - goto cleanup_close; - } - - /* Shadow DB configuration */ - if (parms->shadow_copy) { - /* Ignore shadow_copy setting */ - session->shadow_copy = 0;/* parms->shadow_copy; */ -#if (TF_SHADOW == 1) - rc = tf_rm_shadow_db_init(tfs); - if (rc) - TFP_DRV_LOG(ERR, - "Shadow DB Initialization failed\n, rc:%s", - strerror(-rc)); - /* Add additional processing */ -#endif /* TF_SHADOW */ - } - - /* Adjust the Session with what firmware allowed us to get */ - rc = tf_rm_allocate_validate(tfp); - if (rc) { - TFP_DRV_LOG(ERR, - "Rm allocate validate failed, rc:%s\n", - strerror(-rc)); - goto cleanup_close; - } - - /* Initialize EM pool */ - for (dir = 0; dir < TF_DIR_MAX; dir++) { - rc = tf_create_em_pool(session, - (enum tf_dir)dir, - TF_SESSION_EM_POOL_SIZE); - if (rc) { - TFP_DRV_LOG(ERR, - "EM Pool initialization failed\n"); - goto cleanup_close; - } - } - - session->ref_count++; - - /* Return session ID */ - parms->session_id = session->session_id; - - TFP_DRV_LOG(INFO, - "Session created, session_id:%d\n", - parms->session_id.id); - - TFP_DRV_LOG(INFO, - "domain:%d, bus:%d, device:%d, fw_session_id:%d\n", - parms->session_id.internal.domain, - parms->session_id.internal.bus, - parms->session_id.internal.device, - parms->session_id.internal.fw_session_id); - - return 0; - - cleanup: - tfp_free(tfp->session->core_data); - tfp_free(tfp->session); - tfp->session = NULL; - return rc; - - cleanup_close: - tf_close_session(tfp); - return -EINVAL; -} - -int -tf_open_session_new(struct tf *tfp, - struct tf_open_session_parms *parms) { int rc; unsigned int domain, bus, slot, device; struct tf_session_open_session_parms oparms; - TF_CHECK_PARMS(tfp, parms); + TF_CHECK_PARMS2(tfp, parms); /* Filter out any non-supported device types on the Core * side. It is assumed that the Firmware will be supported if @@ -347,33 +78,8 @@ tf_open_session_new(struct tf *tfp, } int -tf_attach_session(struct tf *tfp __rte_unused, - struct tf_attach_session_parms *parms __rte_unused) -{ -#if (TF_SHARED == 1) - int rc; - - TF_CHECK_PARMS_SESSION(tfp, parms); - - /* - Open the shared memory for the attach_chan_name - * - Point to the shared session for this Device instance - * - Check that session is valid - * - Attach to the firmware so it can record there is more - * than one client of the session. - */ - - if (tfp->session->session_id.id != TF_SESSION_ID_INVALID) { - rc = tf_msg_session_attach(tfp, - parms->ctrl_chan_name, - parms->session_id); - } -#endif /* TF_SHARED */ - return -1; -} - -int -tf_attach_session_new(struct tf *tfp, - struct tf_attach_session_parms *parms) +tf_attach_session(struct tf *tfp, + struct tf_attach_session_parms *parms) { int rc; unsigned int domain, bus, slot, device; @@ -436,65 +142,6 @@ tf_attach_session_new(struct tf *tfp, int tf_close_session(struct tf *tfp) -{ - int rc; - int rc_close = 0; - struct tf_session *tfs; - union tf_session_id session_id; - int dir; - - TF_CHECK_TFP_SESSION(tfp); - - tfs = (struct tf_session *)(tfp->session->core_data); - - /* Cleanup if we're last user of the session */ - if (tfs->ref_count == 1) { - /* Cleanup any outstanding resources */ - rc_close = tf_rm_close(tfp); - } - - if (tfs->session_id.id != TF_SESSION_ID_INVALID) { - rc = tf_msg_session_close(tfp); - if (rc) { - /* Log error */ - TFP_DRV_LOG(ERR, - "Message send failed, rc:%s\n", - strerror(-rc)); - } - - /* Update the ref_count */ - tfs->ref_count--; - } - - session_id = tfs->session_id; - - /* Final cleanup as we're last user of the session */ - if (tfs->ref_count == 0) { - /* Free EM pool */ - for (dir = 0; dir < TF_DIR_MAX; dir++) - tf_free_em_pool(tfs, (enum tf_dir)dir); - - tfp_free(tfp->session->core_data); - tfp_free(tfp->session); - tfp->session = NULL; - } - - TFP_DRV_LOG(INFO, - "Session closed, session_id:%d\n", - session_id.id); - - TFP_DRV_LOG(INFO, - "domain:%d, bus:%d, device:%d, fw_session_id:%d\n", - session_id.internal.domain, - session_id.internal.bus, - session_id.internal.device, - session_id.internal.fw_session_id); - - return rc_close; -} - -int -tf_close_session_new(struct tf *tfp) { int rc; struct tf_session_close_session_parms cparms = { 0 }; @@ -620,76 +267,9 @@ int tf_delete_em_entry(struct tf *tfp, return rc; } -int tf_alloc_identifier(struct tf *tfp, - struct tf_alloc_identifier_parms *parms) -{ - struct bitalloc *session_pool; - struct tf_session *tfs; - int id; - int rc; - - TF_CHECK_PARMS_SESSION(tfp, parms); - - tfs = (struct tf_session *)(tfp->session->core_data); - - switch (parms->ident_type) { - case TF_IDENT_TYPE_L2_CTXT: - TF_RM_GET_POOLS(tfs, parms->dir, &session_pool, - TF_L2_CTXT_REMAP_POOL_NAME, - rc); - break; - case TF_IDENT_TYPE_PROF_FUNC: - TF_RM_GET_POOLS(tfs, parms->dir, &session_pool, - TF_PROF_FUNC_POOL_NAME, - rc); - break; - case TF_IDENT_TYPE_EM_PROF: - TF_RM_GET_POOLS(tfs, parms->dir, &session_pool, - TF_EM_PROF_ID_POOL_NAME, - rc); - break; - case TF_IDENT_TYPE_WC_PROF: - TF_RM_GET_POOLS(tfs, parms->dir, &session_pool, - TF_WC_TCAM_PROF_ID_POOL_NAME, - rc); - break; - case TF_IDENT_TYPE_L2_FUNC: - TFP_DRV_LOG(ERR, "%s: unsupported %s\n", - tf_dir_2_str(parms->dir), - tf_ident_2_str(parms->ident_type)); - rc = -EOPNOTSUPP; - break; - default: - TFP_DRV_LOG(ERR, "%s: %s\n", - tf_dir_2_str(parms->dir), - tf_ident_2_str(parms->ident_type)); - rc = -EOPNOTSUPP; - break; - } - - if (rc) { - TFP_DRV_LOG(ERR, "%s: identifier pool %s failure, rc:%s\n", - tf_dir_2_str(parms->dir), - tf_ident_2_str(parms->ident_type), - strerror(-rc)); - return rc; - } - - id = ba_alloc(session_pool); - - if (id == BA_FAIL) { - TFP_DRV_LOG(ERR, "%s: %s: No resource available\n", - tf_dir_2_str(parms->dir), - tf_ident_2_str(parms->ident_type)); - return -ENOMEM; - } - parms->id = id; - return 0; -} - int -tf_alloc_identifier_new(struct tf *tfp, - struct tf_alloc_identifier_parms *parms) +tf_alloc_identifier(struct tf *tfp, + struct tf_alloc_identifier_parms *parms) { int rc; struct tf_session *tfs; @@ -732,7 +312,7 @@ tf_alloc_identifier_new(struct tf *tfp, } aparms.dir = parms->dir; - aparms.ident_type = parms->ident_type; + aparms.type = parms->ident_type; aparms.id = &id; rc = dev->ops->tf_dev_alloc_ident(tfp, &aparms); if (rc) { @@ -748,79 +328,9 @@ tf_alloc_identifier_new(struct tf *tfp, return 0; } -int tf_free_identifier(struct tf *tfp, - struct tf_free_identifier_parms *parms) -{ - struct bitalloc *session_pool; - int rc; - int ba_rc; - struct tf_session *tfs; - - TF_CHECK_PARMS_SESSION(tfp, parms); - - tfs = (struct tf_session *)(tfp->session->core_data); - - switch (parms->ident_type) { - case TF_IDENT_TYPE_L2_CTXT: - TF_RM_GET_POOLS(tfs, parms->dir, &session_pool, - TF_L2_CTXT_REMAP_POOL_NAME, - rc); - break; - case TF_IDENT_TYPE_PROF_FUNC: - TF_RM_GET_POOLS(tfs, parms->dir, &session_pool, - TF_PROF_FUNC_POOL_NAME, - rc); - break; - case TF_IDENT_TYPE_EM_PROF: - TF_RM_GET_POOLS(tfs, parms->dir, &session_pool, - TF_EM_PROF_ID_POOL_NAME, - rc); - break; - case TF_IDENT_TYPE_WC_PROF: - TF_RM_GET_POOLS(tfs, parms->dir, &session_pool, - TF_WC_TCAM_PROF_ID_POOL_NAME, - rc); - break; - case TF_IDENT_TYPE_L2_FUNC: - TFP_DRV_LOG(ERR, "%s: unsupported %s\n", - tf_dir_2_str(parms->dir), - tf_ident_2_str(parms->ident_type)); - rc = -EOPNOTSUPP; - break; - default: - TFP_DRV_LOG(ERR, "%s: invalid %s\n", - tf_dir_2_str(parms->dir), - tf_ident_2_str(parms->ident_type)); - rc = -EOPNOTSUPP; - break; - } - if (rc) { - TFP_DRV_LOG(ERR, - "%s: %s Identifier pool access failed, rc:%s\n", - tf_dir_2_str(parms->dir), - tf_ident_2_str(parms->ident_type), - strerror(-rc)); - return rc; - } - - ba_rc = ba_inuse(session_pool, (int)parms->id); - - if (ba_rc == BA_FAIL || ba_rc == BA_ENTRY_FREE) { - TFP_DRV_LOG(ERR, "%s: %s: Entry %d already free", - tf_dir_2_str(parms->dir), - tf_ident_2_str(parms->ident_type), - parms->id); - return -EINVAL; - } - - ba_free(session_pool, (int)parms->id); - - return 0; -} - int -tf_free_identifier_new(struct tf *tfp, - struct tf_free_identifier_parms *parms) +tf_free_identifier(struct tf *tfp, + struct tf_free_identifier_parms *parms) { int rc; struct tf_session *tfs; @@ -862,12 +372,12 @@ tf_free_identifier_new(struct tf *tfp, } fparms.dir = parms->dir; - fparms.ident_type = parms->ident_type; + fparms.type = parms->ident_type; fparms.id = parms->id; rc = dev->ops->tf_dev_free_ident(tfp, &fparms); if (rc) { TFP_DRV_LOG(ERR, - "%s: Identifier allocation failed, rc:%s\n", + "%s: Identifier free failed, rc:%s\n", tf_dir_2_str(parms->dir), strerror(-rc)); return rc; @@ -1057,3 +567,242 @@ tf_free_tcam_entry(struct tf *tfp, return 0; } + +int +tf_alloc_tbl_entry(struct tf *tfp, + struct tf_alloc_tbl_entry_parms *parms) +{ + int rc; + struct tf_session *tfs; + struct tf_dev_info *dev; + struct tf_tbl_alloc_parms aparms; + uint32_t idx; + + TF_CHECK_PARMS2(tfp, parms); + + /* Can't do static initialization due to UT enum check */ + memset(&aparms, 0, sizeof(struct tf_tbl_alloc_parms)); + + /* Retrieve the session information */ + rc = tf_session_get_session(tfp, &tfs); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Failed to lookup session, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + /* Retrieve the device information */ + rc = tf_session_get_device(tfs, &dev); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Failed to lookup device, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + if (dev->ops->tf_dev_alloc_tbl == NULL) { + rc = -EOPNOTSUPP; + TFP_DRV_LOG(ERR, + "%s: Operation not supported, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return -EOPNOTSUPP; + } + + aparms.dir = parms->dir; + aparms.type = parms->type; + aparms.idx = &idx; + rc = dev->ops->tf_dev_alloc_tbl(tfp, &aparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Table allocation failed, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + parms->idx = idx; + + return 0; +} + +int +tf_free_tbl_entry(struct tf *tfp, + struct tf_free_tbl_entry_parms *parms) +{ + int rc; + struct tf_session *tfs; + struct tf_dev_info *dev; + struct tf_tbl_free_parms fparms; + + TF_CHECK_PARMS2(tfp, parms); + + /* Can't do static initialization due to UT enum check */ + memset(&fparms, 0, sizeof(struct tf_tbl_free_parms)); + + /* Retrieve the session information */ + rc = tf_session_get_session(tfp, &tfs); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Failed to lookup session, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + /* Retrieve the device information */ + rc = tf_session_get_device(tfs, &dev); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Failed to lookup device, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + if (dev->ops->tf_dev_free_tbl == NULL) { + rc = -EOPNOTSUPP; + TFP_DRV_LOG(ERR, + "%s: Operation not supported, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return -EOPNOTSUPP; + } + + fparms.dir = parms->dir; + fparms.type = parms->type; + fparms.idx = parms->idx; + rc = dev->ops->tf_dev_free_tbl(tfp, &fparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Table free failed, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + return 0; +} + +int +tf_set_tbl_entry(struct tf *tfp, + struct tf_set_tbl_entry_parms *parms) +{ + int rc = 0; + struct tf_session *tfs; + struct tf_dev_info *dev; + struct tf_tbl_set_parms sparms; + + TF_CHECK_PARMS3(tfp, parms, parms->data); + + /* Can't do static initialization due to UT enum check */ + memset(&sparms, 0, sizeof(struct tf_tbl_set_parms)); + + /* Retrieve the session information */ + rc = tf_session_get_session(tfp, &tfs); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Failed to lookup session, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + /* Retrieve the device information */ + rc = tf_session_get_device(tfs, &dev); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Failed to lookup device, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + if (dev->ops->tf_dev_set_tbl == NULL) { + rc = -EOPNOTSUPP; + TFP_DRV_LOG(ERR, + "%s: Operation not supported, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return -EOPNOTSUPP; + } + + sparms.dir = parms->dir; + sparms.type = parms->type; + sparms.data = parms->data; + sparms.data_sz_in_bytes = parms->data_sz_in_bytes; + sparms.idx = parms->idx; + rc = dev->ops->tf_dev_set_tbl(tfp, &sparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Table set failed, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + return rc; +} + +int +tf_get_tbl_entry(struct tf *tfp, + struct tf_get_tbl_entry_parms *parms) +{ + int rc = 0; + struct tf_session *tfs; + struct tf_dev_info *dev; + struct tf_tbl_get_parms gparms; + + TF_CHECK_PARMS3(tfp, parms, parms->data); + + /* Can't do static initialization due to UT enum check */ + memset(&gparms, 0, sizeof(struct tf_tbl_get_parms)); + + /* Retrieve the session information */ + rc = tf_session_get_session(tfp, &tfs); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Failed to lookup session, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + /* Retrieve the device information */ + rc = tf_session_get_device(tfs, &dev); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Failed to lookup device, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + if (dev->ops->tf_dev_get_tbl == NULL) { + rc = -EOPNOTSUPP; + TFP_DRV_LOG(ERR, + "%s: Operation not supported, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return -EOPNOTSUPP; + } + + gparms.dir = parms->dir; + gparms.type = parms->type; + gparms.data = parms->data; + gparms.data_sz_in_bytes = parms->data_sz_in_bytes; + gparms.idx = parms->idx; + rc = dev->ops->tf_dev_get_tbl(tfp, &gparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Table get failed, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + return rc; +} diff --git a/drivers/net/bnxt/tf_core/tf_core.h b/drivers/net/bnxt/tf_core/tf_core.h index bb456bba79..a7a7bd38ab 100644 --- a/drivers/net/bnxt/tf_core/tf_core.h +++ b/drivers/net/bnxt/tf_core/tf_core.h @@ -384,34 +384,87 @@ struct tf { struct tf_session_info *session; }; +/** + * Identifier resource definition + */ +struct tf_identifier_resources { + /** + * Array of TF Identifiers where each entry is expected to be + * set to the requested resource number of that specific type. + * The index used is tf_identifier_type. + */ + uint16_t cnt[TF_IDENT_TYPE_MAX]; +}; + +/** + * Table type resource definition + */ +struct tf_tbl_resources { + /** + * Array of TF Table types where each entry is expected to be + * set to the requeste resource number of that specific + * type. The index used is tf_tbl_type. + */ + uint16_t cnt[TF_TBL_TYPE_MAX]; +}; + +/** + * TCAM type resource definition + */ +struct tf_tcam_resources { + /** + * Array of TF TCAM types where each entry is expected to be + * set to the requested resource number of that specific + * type. The index used is tf_tcam_tbl_type. + */ + uint16_t cnt[TF_TCAM_TBL_TYPE_MAX]; +}; + +/** + * EM type resource definition + */ +struct tf_em_resources { + /** + * Array of TF EM table types where each entry is expected to + * be set to the requested resource number of that specific + * type. The index used is tf_em_tbl_type. + */ + uint16_t cnt[TF_EM_TBL_TYPE_MAX]; +}; + /** * tf_session_resources parameter definition. */ struct tf_session_resources { - /** [in] Requested Identifier Resources + /** + * [in] Requested Identifier Resources * - * The number of identifier resources requested for the session. - * The index used is tf_identifier_type. + * Number of identifier resources requested for the + * session. */ - uint16_t identifier_cnt[TF_IDENT_TYPE_MAX][TF_DIR_MAX]; - /** [in] Requested Index Table resource counts + struct tf_identifier_resources ident_cnt[TF_DIR_MAX]; + /** + * [in] Requested Index Table resource counts * - * The number of index table resources requested for the session. - * The index used is tf_tbl_type. + * The number of index table resources requested for the + * session. */ - uint16_t tbl_cnt[TF_TBL_TYPE_MAX][TF_DIR_MAX]; - /** [in] Requested TCAM Table resource counts + struct tf_tbl_resources tbl_cnt[TF_DIR_MAX]; + /** + * [in] Requested TCAM Table resource counts * - * The number of TCAM table resources requested for the session. - * The index used is tf_tcam_tbl_type. + * The number of TCAM table resources requested for the + * session. */ - uint16_t tcam_tbl_cnt[TF_TCAM_TBL_TYPE_MAX][TF_DIR_MAX]; - /** [in] Requested EM resource counts + + struct tf_tcam_resources tcam_cnt[TF_DIR_MAX]; + /** + * [in] Requested EM resource counts * - * The number of internal EM table resources requested for the session - * The index used is tf_em_tbl_type. + * The number of internal EM table resources requested for the + * session. */ - uint16_t em_tbl_cnt[TF_EM_TBL_TYPE_MAX][TF_DIR_MAX]; + struct tf_em_resources em_cnt[TF_DIR_MAX]; }; /** @@ -497,9 +550,6 @@ struct tf_open_session_parms { int tf_open_session(struct tf *tfp, struct tf_open_session_parms *parms); -int tf_open_session_new(struct tf *tfp, - struct tf_open_session_parms *parms); - struct tf_attach_session_parms { /** * [in] ctrl_chan_name @@ -565,8 +615,6 @@ struct tf_attach_session_parms { */ int tf_attach_session(struct tf *tfp, struct tf_attach_session_parms *parms); -int tf_attach_session_new(struct tf *tfp, - struct tf_attach_session_parms *parms); /** * Closes an existing session. Cleans up all hardware and firmware @@ -576,7 +624,6 @@ int tf_attach_session_new(struct tf *tfp, * Returns success or failure code. */ int tf_close_session(struct tf *tfp); -int tf_close_session_new(struct tf *tfp); /** * @page ident Identity Management @@ -631,8 +678,6 @@ struct tf_free_identifier_parms { */ int tf_alloc_identifier(struct tf *tfp, struct tf_alloc_identifier_parms *parms); -int tf_alloc_identifier_new(struct tf *tfp, - struct tf_alloc_identifier_parms *parms); /** * free identifier resource @@ -645,8 +690,6 @@ int tf_alloc_identifier_new(struct tf *tfp, */ int tf_free_identifier(struct tf *tfp, struct tf_free_identifier_parms *parms); -int tf_free_identifier_new(struct tf *tfp, - struct tf_free_identifier_parms *parms); /** * @page dram_table DRAM Table Scope Interface @@ -1277,7 +1320,7 @@ struct tf_bulk_get_tbl_entry_parms { * provided data buffer is too small for the data type requested. */ int tf_bulk_get_tbl_entry(struct tf *tfp, - struct tf_bulk_get_tbl_entry_parms *parms); + struct tf_bulk_get_tbl_entry_parms *parms); /** * @page exact_match Exact Match Table diff --git a/drivers/net/bnxt/tf_core/tf_device.c b/drivers/net/bnxt/tf_core/tf_device.c index 4c46cadc6d..b474e8c257 100644 --- a/drivers/net/bnxt/tf_core/tf_device.c +++ b/drivers/net/bnxt/tf_core/tf_device.c @@ -43,6 +43,14 @@ dev_bind_p4(struct tf *tfp, struct tf_tbl_cfg_parms tbl_cfg; struct tf_tcam_cfg_parms tcam_cfg; + dev_handle->type = TF_DEVICE_TYPE_WH; + /* Initial function initialization */ + dev_handle->ops = &tf_dev_ops_p4_init; + + dev_handle->type = TF_DEVICE_TYPE_WH; + /* Initial function initialization */ + dev_handle->ops = &tf_dev_ops_p4_init; + /* Initialize the modules */ ident_cfg.num_elements = TF_IDENT_TYPE_MAX; @@ -78,7 +86,7 @@ dev_bind_p4(struct tf *tfp, goto fail; } - dev_handle->type = TF_DEVICE_TYPE_WH; + /* Final function initialization */ dev_handle->ops = &tf_dev_ops_p4; return 0; diff --git a/drivers/net/bnxt/tf_core/tf_device.h b/drivers/net/bnxt/tf_core/tf_device.h index bbdfb151c9..bc92cc0bc1 100644 --- a/drivers/net/bnxt/tf_core/tf_device.h +++ b/drivers/net/bnxt/tf_core/tf_device.h @@ -407,6 +407,7 @@ struct tf_dev_ops { /** * Supported device operation structures */ +extern const struct tf_dev_ops tf_dev_ops_p4_init; extern const struct tf_dev_ops tf_dev_ops_p4; #endif /* _TF_DEVICE_H_ */ diff --git a/drivers/net/bnxt/tf_core/tf_device_p4.c b/drivers/net/bnxt/tf_core/tf_device_p4.c index 77fb693ddb..9e332c5949 100644 --- a/drivers/net/bnxt/tf_core/tf_device_p4.c +++ b/drivers/net/bnxt/tf_core/tf_device_p4.c @@ -75,6 +75,26 @@ tf_dev_p4_get_tcam_slice_info(struct tf *tfp __rte_unused, return 0; } +/** + * Truflow P4 device specific functions + */ +const struct tf_dev_ops tf_dev_ops_p4_init = { + .tf_dev_get_max_types = tf_dev_p4_get_max_types, + .tf_dev_get_tcam_slice_info = tf_dev_p4_get_tcam_slice_info, + .tf_dev_alloc_ident = NULL, + .tf_dev_free_ident = NULL, + .tf_dev_alloc_tbl = NULL, + .tf_dev_free_tbl = NULL, + .tf_dev_alloc_search_tbl = NULL, + .tf_dev_set_tbl = NULL, + .tf_dev_get_tbl = NULL, + .tf_dev_alloc_tcam = NULL, + .tf_dev_free_tcam = NULL, + .tf_dev_alloc_search_tcam = NULL, + .tf_dev_set_tcam = NULL, + .tf_dev_get_tcam = NULL, +}; + /** * Truflow P4 device specific functions */ @@ -85,14 +105,14 @@ const struct tf_dev_ops tf_dev_ops_p4 = { .tf_dev_free_ident = tf_ident_free, .tf_dev_alloc_tbl = tf_tbl_alloc, .tf_dev_free_tbl = tf_tbl_free, - .tf_dev_alloc_search_tbl = tf_tbl_alloc_search, + .tf_dev_alloc_search_tbl = NULL, .tf_dev_set_tbl = tf_tbl_set, .tf_dev_get_tbl = tf_tbl_get, .tf_dev_alloc_tcam = tf_tcam_alloc, .tf_dev_free_tcam = tf_tcam_free, - .tf_dev_alloc_search_tcam = tf_tcam_alloc_search, + .tf_dev_alloc_search_tcam = NULL, .tf_dev_set_tcam = tf_tcam_set, - .tf_dev_get_tcam = tf_tcam_get, + .tf_dev_get_tcam = NULL, .tf_dev_insert_em_entry = tf_em_insert_entry, .tf_dev_delete_em_entry = tf_em_delete_entry, }; diff --git a/drivers/net/bnxt/tf_core/tf_identifier.c b/drivers/net/bnxt/tf_core/tf_identifier.c index e89f9768b6..ee07a6aeac 100644 --- a/drivers/net/bnxt/tf_core/tf_identifier.c +++ b/drivers/net/bnxt/tf_core/tf_identifier.c @@ -45,19 +45,22 @@ tf_ident_bind(struct tf *tfp, db_cfg.dir = i; db_cfg.num_elements = parms->num_elements; db_cfg.cfg = parms->cfg; - db_cfg.alloc_num = parms->resources->identifier_cnt[i]; - db_cfg.rm_db = ident_db[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; } } init = 1; + printf("Identifier - initialized\n"); + return 0; } @@ -73,8 +76,11 @@ tf_ident_unbind(struct tf *tfp __rte_unused) /* Bail if nothing has been initialized done silent as to * allow for creation cleanup. */ - if (!init) + if (!init) { + TFP_DRV_LOG(ERR, + "No Identifier DBs created\n"); return -EINVAL; + } for (i = 0; i < TF_DIR_MAX; i++) { fparms.dir = i; @@ -96,6 +102,7 @@ tf_ident_alloc(struct tf *tfp __rte_unused, struct tf_ident_alloc_parms *parms) { int rc; + uint32_t id; struct tf_rm_allocate_parms aparms = { 0 }; TF_CHECK_PARMS2(tfp, parms); @@ -109,17 +116,19 @@ tf_ident_alloc(struct tf *tfp __rte_unused, /* Allocate requested element */ aparms.rm_db = ident_db[parms->dir]; - aparms.db_index = parms->ident_type; - aparms.index = (uint32_t *)&parms->id; + aparms.db_index = parms->type; + aparms.index = &id; rc = tf_rm_allocate(&aparms); if (rc) { TFP_DRV_LOG(ERR, "%s: Failed allocate, type:%d\n", tf_dir_2_str(parms->dir), - parms->ident_type); + parms->type); return rc; } + *parms->id = id; + return 0; } @@ -143,7 +152,7 @@ tf_ident_free(struct tf *tfp __rte_unused, /* Check if element is in use */ aparms.rm_db = ident_db[parms->dir]; - aparms.db_index = parms->ident_type; + aparms.db_index = parms->type; aparms.index = parms->id; aparms.allocated = &allocated; rc = tf_rm_is_allocated(&aparms); @@ -154,21 +163,21 @@ tf_ident_free(struct tf *tfp __rte_unused, TFP_DRV_LOG(ERR, "%s: Entry already free, type:%d, index:%d\n", tf_dir_2_str(parms->dir), - parms->ident_type, + parms->type, parms->id); return rc; } /* Free requested element */ fparms.rm_db = ident_db[parms->dir]; - fparms.db_index = parms->ident_type; + fparms.db_index = parms->type; fparms.index = parms->id; rc = tf_rm_free(&fparms); if (rc) { TFP_DRV_LOG(ERR, "%s: Free failed, type:%d, index:%d\n", tf_dir_2_str(parms->dir), - parms->ident_type, + parms->type, parms->id); return rc; } diff --git a/drivers/net/bnxt/tf_core/tf_identifier.h b/drivers/net/bnxt/tf_core/tf_identifier.h index 1c5319b5ea..6e36c525fc 100644 --- a/drivers/net/bnxt/tf_core/tf_identifier.h +++ b/drivers/net/bnxt/tf_core/tf_identifier.h @@ -43,7 +43,7 @@ struct tf_ident_alloc_parms { /** * [in] Identifier type */ - enum tf_identifier_type ident_type; + enum tf_identifier_type type; /** * [out] Identifier allocated */ @@ -61,7 +61,7 @@ struct tf_ident_free_parms { /** * [in] Identifier type */ - enum tf_identifier_type ident_type; + enum tf_identifier_type type; /** * [in] ID to free */ diff --git a/drivers/net/bnxt/tf_core/tf_msg.c b/drivers/net/bnxt/tf_core/tf_msg.c index b50e1d48c4..a2e3840f0e 100644 --- a/drivers/net/bnxt/tf_core/tf_msg.c +++ b/drivers/net/bnxt/tf_core/tf_msg.c @@ -12,6 +12,7 @@ #include "tf_device.h" #include "tf_msg.h" #include "tf_util.h" +#include "tf_common.h" #include "tf_session.h" #include "tfp.h" #include "hwrm_tf.h" @@ -935,13 +936,7 @@ tf_msg_session_resc_qcaps(struct tf *tfp, struct tf_rm_resc_req_entry *data; int dma_size; - if (size == 0 || query == NULL || resv_strategy == NULL) { - TFP_DRV_LOG(ERR, - "%s: Resource QCAPS parameter error, rc:%s\n", - tf_dir_2_str(dir), - strerror(-EINVAL)); - return -EINVAL; - } + TF_CHECK_PARMS3(tfp, query, resv_strategy); rc = tf_session_get_fw_session_id(tfp, &fw_session_id); if (rc) { @@ -962,7 +957,7 @@ tf_msg_session_resc_qcaps(struct tf *tfp, req.fw_session_id = tfp_cpu_to_le_32(fw_session_id); req.flags = tfp_cpu_to_le_16(dir); req.qcaps_size = size; - req.qcaps_addr = qcaps_buf.pa_addr; + req.qcaps_addr = tfp_cpu_to_le_64(qcaps_buf.pa_addr); parms.tf_type = HWRM_TF_SESSION_RESC_QCAPS; parms.req_data = (uint32_t *)&req; @@ -980,18 +975,29 @@ tf_msg_session_resc_qcaps(struct tf *tfp, */ if (resp.size != size) { TFP_DRV_LOG(ERR, - "%s: QCAPS message error, rc:%s\n", + "%s: QCAPS message size error, rc:%s\n", tf_dir_2_str(dir), strerror(-EINVAL)); return -EINVAL; } + printf("size: %d\n", resp.size); + /* Post process the response */ data = (struct tf_rm_resc_req_entry *)qcaps_buf.va_addr; + + printf("\nQCAPS\n"); for (i = 0; i < size; i++) { query[i].type = tfp_cpu_to_le_32(data[i].type); query[i].min = tfp_le_to_cpu_16(data[i].min); query[i].max = tfp_le_to_cpu_16(data[i].max); + + printf("type: %d(0x%x) %d %d\n", + query[i].type, + query[i].type, + query[i].min, + query[i].max); + } *resv_strategy = resp.flags & @@ -1021,6 +1027,8 @@ tf_msg_session_resc_alloc(struct tf *tfp, struct tf_rm_resc_entry *resv_data; int dma_size; + TF_CHECK_PARMS3(tfp, request, resv); + rc = tf_session_get_fw_session_id(tfp, &fw_session_id); if (rc) { TFP_DRV_LOG(ERR, @@ -1053,8 +1061,8 @@ tf_msg_session_resc_alloc(struct tf *tfp, req_data[i].max = tfp_cpu_to_le_16(request[i].max); } - req.req_addr = req_buf.pa_addr; - req.resp_addr = resv_buf.pa_addr; + req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr); + req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr); parms.tf_type = HWRM_TF_SESSION_RESC_ALLOC; parms.req_data = (uint32_t *)&req; @@ -1072,18 +1080,28 @@ tf_msg_session_resc_alloc(struct tf *tfp, */ if (resp.size != size) { TFP_DRV_LOG(ERR, - "%s: Alloc message error, rc:%s\n", + "%s: Alloc message size error, rc:%s\n", tf_dir_2_str(dir), strerror(-EINVAL)); return -EINVAL; } + printf("\nRESV\n"); + printf("size: %d\n", resp.size); + /* Post process the response */ resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr; for (i = 0; i < size; i++) { resv[i].type = tfp_cpu_to_le_32(resv_data[i].type); resv[i].start = tfp_cpu_to_le_16(resv_data[i].start); resv[i].stride = tfp_cpu_to_le_16(resv_data[i].stride); + + printf("%d type: %d(0x%x) %d %d\n", + i, + resv[i].type, + resv[i].type, + resv[i].start, + resv[i].stride); } tf_msg_free_dma_buf(&req_buf); @@ -1460,7 +1478,8 @@ tf_msg_bulk_get_tbl_entry(struct tf *tfp, req.start_index = tfp_cpu_to_le_32(params->starting_idx); req.num_entries = tfp_cpu_to_le_32(params->num_entries); - data_size = (params->num_entries * params->entry_sz_in_bytes); + data_size = params->num_entries * params->entry_sz_in_bytes; + req.host_addr = tfp_cpu_to_le_64(params->physical_mem_addr); MSG_PREP(parms, diff --git a/drivers/net/bnxt/tf_core/tf_msg.h b/drivers/net/bnxt/tf_core/tf_msg.h index a3e0f7bba1..fb635f6dc8 100644 --- a/drivers/net/bnxt/tf_core/tf_msg.h +++ b/drivers/net/bnxt/tf_core/tf_msg.h @@ -12,6 +12,7 @@ #include "tf_tbl.h" #include "tf_rm.h" #include "tf_rm_new.h" +#include "tf_tcam.h" struct tf; diff --git a/drivers/net/bnxt/tf_core/tf_rm_new.c b/drivers/net/bnxt/tf_core/tf_rm_new.c index 7cadb231f6..6abf79aa1a 100644 --- a/drivers/net/bnxt/tf_core/tf_rm_new.c +++ b/drivers/net/bnxt/tf_core/tf_rm_new.c @@ -10,6 +10,7 @@ #include #include "tf_rm_new.h" +#include "tf_common.h" #include "tf_util.h" #include "tf_session.h" #include "tf_device.h" @@ -65,6 +66,46 @@ struct tf_rm_new_db { struct tf_rm_element *db; }; +/** + * Adjust an index according to the allocation information. + * + * All resources are controlled in a 0 based pool. Some resources, by + * design, are not 0 based, i.e. Full Action Records (SRAM) thus they + * need to be adjusted before they are handed out. + * + * [in] cfg + * Pointer to the DB configuration + * + * [in] reservations + * Pointer to the allocation values associated with the module + * + * [in] count + * Number of DB configuration elements + * + * [out] valid_count + * Number of HCAPI entries with a reservation value greater than 0 + * + * Returns: + * 0 - Success + * - EOPNOTSUPP - Operation not supported + */ +static void +tf_rm_count_hcapi_reservations(struct tf_rm_element_cfg *cfg, + uint16_t *reservations, + uint16_t count, + uint16_t *valid_count) +{ + int i; + uint16_t cnt = 0; + + for (i = 0; i < count; i++) { + if (cfg[i].cfg_type == TF_RM_ELEM_CFG_HCAPI && + reservations[i] > 0) + cnt++; + } + + *valid_count = cnt; +} /** * Resource Manager Adjust of base index definitions. @@ -132,6 +173,7 @@ tf_rm_create_db(struct tf *tfp, { int rc; int i; + int j; struct tf_session *tfs; struct tf_dev_info *dev; uint16_t max_types; @@ -143,6 +185,9 @@ tf_rm_create_db(struct tf *tfp, struct tf_rm_new_db *rm_db; struct tf_rm_element *db; uint32_t pool_size; + uint16_t hcapi_items; + + TF_CHECK_PARMS2(tfp, parms); /* Retrieve the session information */ rc = tf_session_get_session(tfp, &tfs); @@ -177,10 +222,19 @@ tf_rm_create_db(struct tf *tfp, if (rc) return rc; - /* Process capabilities against db requirements */ + /* Process capabilities against DB requirements. However, as a + * DB can hold elements that are not HCAPI we can reduce the + * req msg content by removing those out of the request yet + * the DB holds them all as to give a fast lookup. We can also + * remove entries where there are no request for elements. + */ + tf_rm_count_hcapi_reservations(parms->cfg, + parms->alloc_cnt, + parms->num_elements, + &hcapi_items); /* Alloc request, alignment already set */ - cparms.nitems = parms->num_elements; + cparms.nitems = (size_t)hcapi_items; cparms.size = sizeof(struct tf_rm_resc_req_entry); rc = tfp_calloc(&cparms); if (rc) @@ -195,15 +249,24 @@ tf_rm_create_db(struct tf *tfp, resv = (struct tf_rm_resc_entry *)cparms.mem_va; /* Build the request */ - for (i = 0; i < parms->num_elements; i++) { + for (i = 0, j = 0; i < parms->num_elements; i++) { /* Skip any non HCAPI cfg elements */ if (parms->cfg[i].cfg_type == TF_RM_ELEM_CFG_HCAPI) { - req[i].type = parms->cfg[i].hcapi_type; - /* Check that we can get the full amount allocated */ - if (parms->alloc_num[i] <= + /* Only perform reservation for entries that + * has been requested + */ + if (parms->alloc_cnt[i] == 0) + continue; + + /* Verify that we can get the full amount + * allocated per the qcaps availability. + */ + if (parms->alloc_cnt[i] <= query[parms->cfg[i].hcapi_type].max) { - req[i].min = parms->alloc_num[i]; - req[i].max = parms->alloc_num[i]; + req[j].type = parms->cfg[i].hcapi_type; + req[j].min = parms->alloc_cnt[i]; + req[j].max = parms->alloc_cnt[i]; + j++; } else { TFP_DRV_LOG(ERR, "%s: Resource failure, type:%d\n", @@ -211,19 +274,16 @@ tf_rm_create_db(struct tf *tfp, parms->cfg[i].hcapi_type); TFP_DRV_LOG(ERR, "req:%d, avail:%d\n", - parms->alloc_num[i], + parms->alloc_cnt[i], query[parms->cfg[i].hcapi_type].max); return -EINVAL; } - } else { - /* Skip the element */ - req[i].type = CFA_RESOURCE_TYPE_INVALID; } } rc = tf_msg_session_resc_alloc(tfp, parms->dir, - parms->num_elements, + hcapi_items, req, resv); if (rc) @@ -246,42 +306,74 @@ tf_rm_create_db(struct tf *tfp, rm_db->db = (struct tf_rm_element *)cparms.mem_va; db = rm_db->db; - for (i = 0; i < parms->num_elements; i++) { - /* If allocation failed for a single entry the DB - * creation is considered a failure. + for (i = 0, j = 0; i < parms->num_elements; i++) { + db[i].cfg_type = parms->cfg[i].cfg_type; + db[i].hcapi_type = parms->cfg[i].hcapi_type; + + /* Skip any non HCAPI types as we didn't include them + * in the reservation request. */ - if (parms->alloc_num[i] != resv[i].stride) { + if (parms->cfg[i].cfg_type != TF_RM_ELEM_CFG_HCAPI) + continue; + + /* If the element didn't request an allocation no need + * to create a pool nor verify if we got a reservation. + */ + if (parms->alloc_cnt[i] == 0) + continue; + + /* If the element had requested an allocation and that + * allocation was a success (full amount) then + * allocate the pool. + */ + if (parms->alloc_cnt[i] == resv[j].stride) { + db[i].alloc.entry.start = resv[j].start; + db[i].alloc.entry.stride = resv[j].stride; + + /* Create pool */ + pool_size = (BITALLOC_SIZEOF(resv[j].stride) / + sizeof(struct bitalloc)); + /* Alloc request, alignment already set */ + cparms.nitems = pool_size; + cparms.size = sizeof(struct bitalloc); + rc = tfp_calloc(&cparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Pool alloc failed, type:%d\n", + tf_dir_2_str(parms->dir), + db[i].cfg_type); + goto fail; + } + db[i].pool = (struct bitalloc *)cparms.mem_va; + + rc = ba_init(db[i].pool, resv[j].stride); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Pool init failed, type:%d\n", + tf_dir_2_str(parms->dir), + db[i].cfg_type); + goto fail; + } + j++; + } else { + /* Bail out as we want what we requested for + * all elements, not any less. + */ TFP_DRV_LOG(ERR, "%s: Alloc failed, type:%d\n", tf_dir_2_str(parms->dir), - i); + db[i].cfg_type); TFP_DRV_LOG(ERR, "req:%d, alloc:%d\n", - parms->alloc_num[i], - resv[i].stride); + parms->alloc_cnt[i], + resv[j].stride); goto fail; } - - db[i].cfg_type = parms->cfg[i].cfg_type; - db[i].hcapi_type = parms->cfg[i].hcapi_type; - db[i].alloc.entry.start = resv[i].start; - db[i].alloc.entry.stride = resv[i].stride; - - /* Create pool */ - pool_size = (BITALLOC_SIZEOF(resv[i].stride) / - sizeof(struct bitalloc)); - /* Alloc request, alignment already set */ - cparms.nitems = pool_size; - cparms.size = sizeof(struct bitalloc); - rc = tfp_calloc(&cparms); - if (rc) - return rc; - db[i].pool = (struct bitalloc *)cparms.mem_va; } rm_db->num_entries = i; rm_db->dir = parms->dir; - parms->rm_db = (void *)rm_db; + *parms->rm_db = (void *)rm_db; tfp_free((void *)req); tfp_free((void *)resv); @@ -307,13 +399,15 @@ tf_rm_free_db(struct tf *tfp __rte_unused, int i; struct tf_rm_new_db *rm_db; + TF_CHECK_PARMS1(parms); + /* Traverse the DB and clear each pool. * NOTE: * Firmware is not cleared. It will be cleared on close only. */ rm_db = (struct tf_rm_new_db *)parms->rm_db; for (i = 0; i < rm_db->num_entries; i++) - tfp_free((void *)rm_db->db->pool); + tfp_free((void *)rm_db->db[i].pool); tfp_free((void *)parms->rm_db); @@ -325,11 +419,11 @@ tf_rm_allocate(struct tf_rm_allocate_parms *parms) { int rc = 0; int id; + uint32_t index; struct tf_rm_new_db *rm_db; enum tf_rm_elem_cfg_type cfg_type; - if (parms == NULL || parms->rm_db == NULL) - return -EINVAL; + TF_CHECK_PARMS2(parms, parms->rm_db); rm_db = (struct tf_rm_new_db *)parms->rm_db; cfg_type = rm_db->db[parms->db_index].cfg_type; @@ -339,6 +433,17 @@ tf_rm_allocate(struct tf_rm_allocate_parms *parms) cfg_type != TF_RM_ELEM_CFG_PRIVATE) return -ENOTSUP; + /* Bail out if the pool is not valid, should never happen */ + if (rm_db->db[parms->db_index].pool == NULL) { + rc = -ENOTSUP; + TFP_DRV_LOG(ERR, + "%s: Invalid pool for this type:%d, rc:%s\n", + tf_dir_2_str(rm_db->dir), + parms->db_index, + strerror(-rc)); + return rc; + } + id = ba_alloc(rm_db->db[parms->db_index].pool); if (id == BA_FAIL) { TFP_DRV_LOG(ERR, @@ -353,15 +458,17 @@ tf_rm_allocate(struct tf_rm_allocate_parms *parms) TF_RM_ADJUST_ADD_BASE, parms->db_index, id, - parms->index); + &index); if (rc) { TFP_DRV_LOG(ERR, "%s: Alloc adjust of base index failed, rc:%s\n", tf_dir_2_str(rm_db->dir), strerror(-rc)); - return -1; + return -EINVAL; } + *parms->index = index; + return rc; } @@ -373,8 +480,7 @@ tf_rm_free(struct tf_rm_free_parms *parms) struct tf_rm_new_db *rm_db; enum tf_rm_elem_cfg_type cfg_type; - if (parms == NULL || parms->rm_db == NULL) - return -EINVAL; + TF_CHECK_PARMS2(parms, parms->rm_db); rm_db = (struct tf_rm_new_db *)parms->rm_db; cfg_type = rm_db->db[parms->db_index].cfg_type; @@ -384,6 +490,17 @@ tf_rm_free(struct tf_rm_free_parms *parms) cfg_type != TF_RM_ELEM_CFG_PRIVATE) return -ENOTSUP; + /* Bail out if the pool is not valid, should never happen */ + if (rm_db->db[parms->db_index].pool == NULL) { + rc = -ENOTSUP; + TFP_DRV_LOG(ERR, + "%s: Invalid pool for this type:%d, rc:%s\n", + tf_dir_2_str(rm_db->dir), + parms->db_index, + strerror(-rc)); + return rc; + } + /* Adjust for any non zero start value */ rc = tf_rm_adjust_index(rm_db->db, TF_RM_ADJUST_RM_BASE, @@ -409,8 +526,7 @@ tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms) struct tf_rm_new_db *rm_db; enum tf_rm_elem_cfg_type cfg_type; - if (parms == NULL || parms->rm_db == NULL) - return -EINVAL; + TF_CHECK_PARMS2(parms, parms->rm_db); rm_db = (struct tf_rm_new_db *)parms->rm_db; cfg_type = rm_db->db[parms->db_index].cfg_type; @@ -420,6 +536,17 @@ tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms) cfg_type != TF_RM_ELEM_CFG_PRIVATE) return -ENOTSUP; + /* Bail out if the pool is not valid, should never happen */ + if (rm_db->db[parms->db_index].pool == NULL) { + rc = -ENOTSUP; + TFP_DRV_LOG(ERR, + "%s: Invalid pool for this type:%d, rc:%s\n", + tf_dir_2_str(rm_db->dir), + parms->db_index, + strerror(-rc)); + return rc; + } + /* Adjust for any non zero start value */ rc = tf_rm_adjust_index(rm_db->db, TF_RM_ADJUST_RM_BASE, @@ -442,8 +569,7 @@ tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms) struct tf_rm_new_db *rm_db; enum tf_rm_elem_cfg_type cfg_type; - if (parms == NULL || parms->rm_db == NULL) - return -EINVAL; + TF_CHECK_PARMS2(parms, parms->rm_db); rm_db = (struct tf_rm_new_db *)parms->rm_db; cfg_type = rm_db->db[parms->db_index].cfg_type; @@ -465,8 +591,7 @@ tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms) struct tf_rm_new_db *rm_db; enum tf_rm_elem_cfg_type cfg_type; - if (parms == NULL || parms->rm_db == NULL) - return -EINVAL; + TF_CHECK_PARMS2(parms, parms->rm_db); rm_db = (struct tf_rm_new_db *)parms->rm_db; cfg_type = rm_db->db[parms->db_index].cfg_type; diff --git a/drivers/net/bnxt/tf_core/tf_rm_new.h b/drivers/net/bnxt/tf_core/tf_rm_new.h index fb4575d85d..4a2d423b5f 100644 --- a/drivers/net/bnxt/tf_core/tf_rm_new.h +++ b/drivers/net/bnxt/tf_core/tf_rm_new.h @@ -135,13 +135,16 @@ struct tf_rm_create_db_parms { */ struct tf_rm_element_cfg *cfg; /** - * Allocation number array. Array size is num_elements. + * Resource allocation count array. This array content + * originates from the tf_session_resources that is passed in + * on session open. + * Array size is num_elements. */ - uint16_t *alloc_num; + uint16_t *alloc_cnt; /** * [out] RM DB Handle */ - void *rm_db; + void **rm_db; }; /** @@ -382,7 +385,7 @@ int tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms); /** * Performs a lookup in the Resource Manager DB and retrieves the - * requested HCAPI type. + * requested HCAPI RM type. * * [in] parms * Pointer to get hcapi parameters diff --git a/drivers/net/bnxt/tf_core/tf_session.c b/drivers/net/bnxt/tf_core/tf_session.c index 0b2b6f4da2..68cd1002f5 100644 --- a/drivers/net/bnxt/tf_core/tf_session.c +++ b/drivers/net/bnxt/tf_core/tf_session.c @@ -95,21 +95,11 @@ tf_session_open_session(struct tf *tfp, parms->open_cfg->device_type, session->shadow_copy, &parms->open_cfg->resources, - session->dev); + &session->dev); /* Logging handled by dev_bind */ if (rc) return rc; - /* Query for Session Config - */ - rc = tf_msg_session_qcfg(tfp); - if (rc) { - TFP_DRV_LOG(ERR, - "Query config message send failed, rc:%s\n", - strerror(-rc)); - goto cleanup_close; - } - session->ref_count++; return 0; @@ -119,10 +109,6 @@ tf_session_open_session(struct tf *tfp, tfp_free(tfp->session); tfp->session = NULL; return rc; - - cleanup_close: - tf_close_session(tfp); - return -EINVAL; } int @@ -231,17 +217,7 @@ int tf_session_get_device(struct tf_session *tfs, struct tf_dev_info **tfd) { - int rc; - - if (tfs->dev == NULL) { - rc = -EINVAL; - TFP_DRV_LOG(ERR, - "Device not created, rc:%s\n", - strerror(-rc)); - return rc; - } - - *tfd = tfs->dev; + *tfd = &tfs->dev; return 0; } diff --git a/drivers/net/bnxt/tf_core/tf_session.h b/drivers/net/bnxt/tf_core/tf_session.h index 92792518b0..705bb0955c 100644 --- a/drivers/net/bnxt/tf_core/tf_session.h +++ b/drivers/net/bnxt/tf_core/tf_session.h @@ -97,7 +97,7 @@ struct tf_session { uint8_t ref_count; /** Device handle */ - struct tf_dev_info *dev; + struct tf_dev_info dev; /** Session HW and SRAM resources */ struct tf_rm_db resc; diff --git a/drivers/net/bnxt/tf_core/tf_tbl.c b/drivers/net/bnxt/tf_core/tf_tbl.c index a68335304f..e594f02485 100644 --- a/drivers/net/bnxt/tf_core/tf_tbl.c +++ b/drivers/net/bnxt/tf_core/tf_tbl.c @@ -761,163 +761,6 @@ tf_em_validate_num_entries(struct tf_tbl_scope_cb *tbl_scope_cb, return 0; } -/** - * Internal function to set a Table Entry. Supports all internal Table Types - * - * [in] tfp - * Pointer to TruFlow handle - * - * [in] parms - * Pointer to input parameters - * - * Returns: - * 0 - Success - * -EINVAL - Parameter error - */ -static int -tf_set_tbl_entry_internal(struct tf *tfp, - struct tf_set_tbl_entry_parms *parms) -{ - int rc; - int id; - uint32_t index; - struct bitalloc *session_pool; - struct tf_session *tfs = (struct tf_session *)(tfp->session->core_data); - - /* Lookup the pool using the table type of the element */ - rc = tf_rm_lookup_tbl_type_pool(tfs, - parms->dir, - parms->type, - &session_pool); - /* Error logging handled by tf_rm_lookup_tbl_type_pool */ - if (rc) - return rc; - - index = parms->idx; - - if (parms->type != TF_TBL_TYPE_FULL_ACT_RECORD && - parms->type != TF_TBL_TYPE_ACT_SP_SMAC_IPV4 && - parms->type != TF_TBL_TYPE_ACT_STATS_64) { - TFP_DRV_LOG(ERR, - "%s, Type not supported, type:%d\n", - tf_dir_2_str(parms->dir), - parms->type); - return -EOPNOTSUPP; - } - - /* Adjust the returned index/offset as there is no guarantee - * that the start is 0 at time of RM allocation - */ - tf_rm_convert_index(tfs, - parms->dir, - parms->type, - TF_RM_CONVERT_RM_BASE, - parms->idx, - &index); - - /* Verify that the entry has been previously allocated */ - id = ba_inuse(session_pool, index); - if (id != 1) { - TFP_DRV_LOG(ERR, - "%s, Invalid or not allocated index, type:%d, idx:%d\n", - tf_dir_2_str(parms->dir), - parms->type, - index); - return -EINVAL; - } - - /* Set the entry */ - rc = tf_msg_set_tbl_entry(tfp, - parms->dir, - parms->type, - parms->data_sz_in_bytes, - parms->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; -} - -/** - * Internal function to get a Table Entry. Supports all Table Types - * except the TF_TBL_TYPE_EXT as that is handled as a table scope. - * - * [in] tfp - * Pointer to TruFlow handle - * - * [in] parms - * Pointer to input parameters - * - * Returns: - * 0 - Success - * -EINVAL - Parameter error - */ -static int -tf_get_tbl_entry_internal(struct tf *tfp, - struct tf_get_tbl_entry_parms *parms) -{ - int rc; - int id; - uint32_t index; - struct bitalloc *session_pool; - struct tf_session *tfs = (struct tf_session *)(tfp->session->core_data); - - /* Lookup the pool using the table type of the element */ - rc = tf_rm_lookup_tbl_type_pool(tfs, - parms->dir, - parms->type, - &session_pool); - /* Error logging handled by tf_rm_lookup_tbl_type_pool */ - if (rc) - return rc; - - index = parms->idx; - - /* Adjust the returned index/offset as there is no guarantee - * that the start is 0 at time of RM allocation - */ - tf_rm_convert_index(tfs, - parms->dir, - parms->type, - TF_RM_CONVERT_RM_BASE, - parms->idx, - &index); - - /* Verify that the entry has been previously allocated */ - id = ba_inuse(session_pool, index); - if (id != 1) { - TFP_DRV_LOG(ERR, - "%s, Invalid or not allocated index, type:%d, idx:%d\n", - tf_dir_2_str(parms->dir), - parms->type, - index); - return -EINVAL; - } - - /* Get the entry */ - rc = tf_msg_get_tbl_entry(tfp, - parms->dir, - parms->type, - parms->data_sz_in_bytes, - parms->data, - parms->idx); - if (rc) { - TFP_DRV_LOG(ERR, - "%s, Get failed, type:%d, rc:%s\n", - tf_dir_2_str(parms->dir), - parms->type, - strerror(-rc)); - } - - return rc; -} - /** * Internal function to get a Table Entry. Supports all Table Types * except the TF_TBL_TYPE_EXT as that is handled as a table scope. @@ -1145,266 +988,6 @@ tf_destroy_tbl_pool_external(enum tf_dir dir, tfp_free(ext_act_pool_mem); } -/** - * Allocate External Tbl entry from the Session Pool. - * - * [in] tfp - * Pointer to Truflow Handle - * [in] parms - * Allocation parameters - * - * Return: - * 0 - Success, entry allocated - no search support - * -ENOMEM -EINVAL -EOPNOTSUPP - * - Failure, entry not allocated, out of resources - */ -static int -tf_alloc_tbl_entry_pool_external(struct tf *tfp, - struct tf_alloc_tbl_entry_parms *parms) -{ - int rc; - uint32_t index; - struct tf_session *tfs; - struct tf_tbl_scope_cb *tbl_scope_cb; - struct stack *pool; - - TF_CHECK_PARMS_SESSION(tfp, parms); - - tfs = (struct tf_session *)(tfp->session->core_data); - - /* Get the pool info from the table scope - */ - tbl_scope_cb = tbl_scope_cb_find(tfs, parms->tbl_scope_id); - - if (tbl_scope_cb == NULL) { - TFP_DRV_LOG(ERR, - "%s, table scope not allocated\n", - tf_dir_2_str(parms->dir)); - return -EINVAL; - } - pool = &tbl_scope_cb->ext_act_pool[parms->dir]; - - /* Allocate an element - */ - rc = stack_pop(pool, &index); - - if (rc != 0) { - TFP_DRV_LOG(ERR, - "%s, Allocation failed, type:%d\n", - tf_dir_2_str(parms->dir), - parms->type); - return rc; - } - parms->idx = index; - return rc; -} - -/** - * Allocate Internal Tbl entry from the Session Pool. - * - * [in] tfp - * Pointer to Truflow Handle - * [in] parms - * Allocation parameters - * - * Return: - * 0 - Success, entry found and ref count decremented - * -ENOMEM - Failure, entry not allocated, out of resources - */ -static int -tf_alloc_tbl_entry_pool_internal(struct tf *tfp, - struct tf_alloc_tbl_entry_parms *parms) -{ - int rc; - int id; - int free_cnt; - uint32_t index; - struct bitalloc *session_pool; - struct tf_session *tfs; - - TF_CHECK_PARMS_SESSION(tfp, parms); - - tfs = (struct tf_session *)(tfp->session->core_data); - - if (parms->type != TF_TBL_TYPE_FULL_ACT_RECORD && - parms->type != TF_TBL_TYPE_ACT_SP_SMAC && - parms->type != TF_TBL_TYPE_ACT_SP_SMAC_IPV4 && - parms->type != TF_TBL_TYPE_ACT_ENCAP_8B && - parms->type != TF_TBL_TYPE_ACT_ENCAP_16B && - parms->type != TF_TBL_TYPE_ACT_ENCAP_64B && - parms->type != TF_TBL_TYPE_ACT_STATS_64) { - TFP_DRV_LOG(ERR, - "%s, Type not supported, type:%d\n", - tf_dir_2_str(parms->dir), - parms->type); - return -EOPNOTSUPP; - } - - /* Lookup the pool using the table type of the element */ - rc = tf_rm_lookup_tbl_type_pool(tfs, - parms->dir, - parms->type, - &session_pool); - /* Error logging handled by tf_rm_lookup_tbl_type_pool */ - if (rc) - return rc; - - id = ba_alloc(session_pool); - if (id == -1) { - free_cnt = ba_free_count(session_pool); - - TFP_DRV_LOG(ERR, - "%s, Allocation failed, type:%d, free:%d\n", - tf_dir_2_str(parms->dir), - parms->type, - free_cnt); - return -ENOMEM; - } - - /* Adjust the returned index/offset as there is no guarantee - * that the start is 0 at time of RM allocation - */ - tf_rm_convert_index(tfs, - parms->dir, - parms->type, - TF_RM_CONVERT_ADD_BASE, - id, - &index); - parms->idx = index; - return rc; -} - -/** - * Free External Tbl entry to the session pool. - * - * [in] tfp - * Pointer to Truflow Handle - * [in] parms - * Allocation parameters - * - * Return: - * 0 - Success, entry freed - * - * - Failure, entry not successfully freed for these reasons - * -ENOMEM - * -EOPNOTSUPP - * -EINVAL - */ -static int -tf_free_tbl_entry_pool_external(struct tf *tfp, - struct tf_free_tbl_entry_parms *parms) -{ - int rc = 0; - struct tf_session *tfs; - uint32_t index; - struct tf_tbl_scope_cb *tbl_scope_cb; - struct stack *pool; - - TF_CHECK_PARMS_SESSION(tfp, parms); - - tfs = (struct tf_session *)(tfp->session->core_data); - - /* Get the pool info from the table scope - */ - tbl_scope_cb = tbl_scope_cb_find(tfs, parms->tbl_scope_id); - - if (tbl_scope_cb == NULL) { - TFP_DRV_LOG(ERR, - "%s, table scope error\n", - tf_dir_2_str(parms->dir)); - return -EINVAL; - } - pool = &tbl_scope_cb->ext_act_pool[parms->dir]; - - index = parms->idx; - - rc = stack_push(pool, index); - - if (rc != 0) { - TFP_DRV_LOG(ERR, - "%s, consistency error, stack full, type:%d, idx:%d\n", - tf_dir_2_str(parms->dir), - parms->type, - index); - } - return rc; -} - -/** - * Free Internal Tbl entry from the Session Pool. - * - * [in] tfp - * Pointer to Truflow Handle - * [in] parms - * Allocation parameters - * - * Return: - * 0 - Success, entry found and ref count decremented - * -ENOMEM - Failure, entry not allocated, out of resources - */ -static int -tf_free_tbl_entry_pool_internal(struct tf *tfp, - struct tf_free_tbl_entry_parms *parms) -{ - int rc = 0; - int id; - struct bitalloc *session_pool; - struct tf_session *tfs; - uint32_t index; - - TF_CHECK_PARMS_SESSION(tfp, parms); - - tfs = (struct tf_session *)(tfp->session->core_data); - - if (parms->type != TF_TBL_TYPE_FULL_ACT_RECORD && - parms->type != TF_TBL_TYPE_ACT_SP_SMAC && - parms->type != TF_TBL_TYPE_ACT_SP_SMAC_IPV4 && - parms->type != TF_TBL_TYPE_ACT_ENCAP_8B && - parms->type != TF_TBL_TYPE_ACT_ENCAP_16B && - parms->type != TF_TBL_TYPE_ACT_ENCAP_64B && - parms->type != TF_TBL_TYPE_ACT_STATS_64) { - TFP_DRV_LOG(ERR, - "%s, Type not supported, type:%d\n", - tf_dir_2_str(parms->dir), - parms->type); - return -EOPNOTSUPP; - } - - /* Lookup the pool using the table type of the element */ - rc = tf_rm_lookup_tbl_type_pool(tfs, - parms->dir, - parms->type, - &session_pool); - /* Error logging handled by tf_rm_lookup_tbl_type_pool */ - if (rc) - return rc; - - index = parms->idx; - - /* Adjust the returned index/offset as there is no guarantee - * that the start is 0 at time of RM allocation - */ - tf_rm_convert_index(tfs, - parms->dir, - parms->type, - TF_RM_CONVERT_RM_BASE, - parms->idx, - &index); - - /* Check if element was indeed allocated */ - id = ba_inuse_free(session_pool, index); - if (id == -1) { - TFP_DRV_LOG(ERR, - "%s, Element not previously alloc'ed, type:%d, idx:%d\n", - tf_dir_2_str(parms->dir), - parms->type, - index); - return -ENOMEM; - } - - return rc; -} - /* API defined in tf_em.h */ struct tf_tbl_scope_cb * tbl_scope_cb_find(struct tf_session *session, @@ -1584,113 +1167,7 @@ tf_alloc_eem_tbl_scope(struct tf *tfp, return -EINVAL; } -/* API defined in tf_core.h */ -int -tf_set_tbl_entry(struct tf *tfp, - struct tf_set_tbl_entry_parms *parms) -{ - int rc = 0; - struct tf_tbl_scope_cb *tbl_scope_cb; - struct tf_session *session; - - TF_CHECK_PARMS_SESSION(tfp, parms); - - if (parms->data == NULL) { - TFP_DRV_LOG(ERR, - "%s, invalid parms->data\n", - tf_dir_2_str(parms->dir)); - return -EINVAL; - } - - if (parms->type == TF_TBL_TYPE_EXT) { - void *base_addr; - uint32_t offset = parms->idx; - uint32_t tbl_scope_id; - - session = (struct tf_session *)(tfp->session->core_data); - - tbl_scope_id = parms->tbl_scope_id; - - if (tbl_scope_id == TF_TBL_SCOPE_INVALID) { - TFP_DRV_LOG(ERR, - "%s, Table scope not allocated\n", - tf_dir_2_str(parms->dir)); - return -EINVAL; - } - - /* Get the table scope control block associated with the - * external pool - */ - tbl_scope_cb = tbl_scope_cb_find(session, tbl_scope_id); - - if (tbl_scope_cb == NULL) { - TFP_DRV_LOG(ERR, - "%s, table scope error\n", - tf_dir_2_str(parms->dir)); - return -EINVAL; - } - - /* External table, implicitly the Action table */ - base_addr = (void *)(uintptr_t) - hcapi_get_table_page(&tbl_scope_cb->em_ctx_info[parms->dir].em_tables[TF_RECORD_TABLE], offset); - - if (base_addr == NULL) { - TFP_DRV_LOG(ERR, - "%s, Base address lookup failed\n", - tf_dir_2_str(parms->dir)); - return -EINVAL; - } - - offset %= TF_EM_PAGE_SIZE; - rte_memcpy((char *)base_addr + offset, - parms->data, - parms->data_sz_in_bytes); - } else { - /* Internal table type processing */ - rc = tf_set_tbl_entry_internal(tfp, parms); - 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; -} - -/* API defined in tf_core.h */ -int -tf_get_tbl_entry(struct tf *tfp, - struct tf_get_tbl_entry_parms *parms) -{ - int rc = 0; - - TF_CHECK_PARMS_SESSION(tfp, parms); - - if (parms->type == TF_TBL_TYPE_EXT) { - /* Not supported, yet */ - TFP_DRV_LOG(ERR, - "%s, External table type not supported\n", - tf_dir_2_str(parms->dir)); - - rc = -EOPNOTSUPP; - } else { - /* Internal table type processing */ - rc = tf_get_tbl_entry_internal(tfp, parms); - if (rc) - TFP_DRV_LOG(ERR, - "%s, Get failed, type:%d, rc:%s\n", - tf_dir_2_str(parms->dir), - parms->type, - strerror(-rc)); - } - - return rc; -} - -/* API defined in tf_core.h */ + /* API defined in tf_core.h */ int tf_bulk_get_tbl_entry(struct tf *tfp, struct tf_bulk_get_tbl_entry_parms *parms) @@ -1749,92 +1226,6 @@ tf_free_tbl_scope(struct tf *tfp, return rc; } -/* API defined in tf_core.h */ -int -tf_alloc_tbl_entry(struct tf *tfp, - struct tf_alloc_tbl_entry_parms *parms) -{ - int rc; -#if (TF_SHADOW == 1) - struct tf_session *tfs; -#endif /* TF_SHADOW */ - - TF_CHECK_PARMS_SESSION(tfp, parms); - /* - * No shadow copy support for external tables, allocate and return - */ - if (parms->type == TF_TBL_TYPE_EXT) { - rc = tf_alloc_tbl_entry_pool_external(tfp, parms); - return rc; - } - -#if (TF_SHADOW == 1) - tfs = (struct tf_session *)(tfp->session->core_data); - - /* Search the Shadow DB for requested element. If not found go - * allocate one from the Session Pool - */ - if (parms->search_enable && tfs->shadow_copy) { - rc = tf_alloc_tbl_entry_shadow(tfs, parms); - /* Entry found and parms populated with return data */ - if (rc == 0) - return rc; - } -#endif /* TF_SHADOW */ - - rc = tf_alloc_tbl_entry_pool_internal(tfp, parms); - if (rc) - TFP_DRV_LOG(ERR, "%s, Alloc failed, rc:%s\n", - tf_dir_2_str(parms->dir), - strerror(-rc)); - - return rc; -} - -/* API defined in tf_core.h */ -int -tf_free_tbl_entry(struct tf *tfp, - struct tf_free_tbl_entry_parms *parms) -{ - int rc; -#if (TF_SHADOW == 1) - struct tf_session *tfs; -#endif /* TF_SHADOW */ - - TF_CHECK_PARMS_SESSION(tfp, parms); - - /* - * No shadow of external tables so just free the entry - */ - if (parms->type == TF_TBL_TYPE_EXT) { - rc = tf_free_tbl_entry_pool_external(tfp, parms); - return rc; - } - -#if (TF_SHADOW == 1) - tfs = (struct tf_session *)(tfp->session->core_data); - - /* Search the Shadow DB for requested element. If not found go - * allocate one from the Session Pool - */ - if (parms->search_enable && tfs->shadow_copy) { - rc = tf_free_tbl_entry_shadow(tfs, parms); - /* Entry free'ed and parms populated with return data */ - if (rc == 0) - return rc; - } -#endif /* TF_SHADOW */ - - rc = tf_free_tbl_entry_pool_internal(tfp, parms); - - if (rc) - TFP_DRV_LOG(ERR, "%s, Alloc failed, rc:%s\n", - tf_dir_2_str(parms->dir), - strerror(-rc)); - return rc; -} - - static void tf_dump_link_page_table(struct hcapi_cfa_em_page_tbl *tp, struct hcapi_cfa_em_page_tbl *tp_next) diff --git a/drivers/net/bnxt/tf_core/tf_tbl_type.c b/drivers/net/bnxt/tf_core/tf_tbl_type.c index b79706f972..51f8f07409 100644 --- a/drivers/net/bnxt/tf_core/tf_tbl_type.c +++ b/drivers/net/bnxt/tf_core/tf_tbl_type.c @@ -6,13 +6,18 @@ #include #include "tf_tbl_type.h" +#include "tf_common.h" +#include "tf_rm_new.h" +#include "tf_util.h" +#include "tf_msg.h" +#include "tfp.h" struct tf; /** * Table DBs. */ -/* static void *tbl_db[TF_DIR_MAX]; */ +static void *tbl_db[TF_DIR_MAX]; /** * Table Shadow DBs @@ -22,7 +27,7 @@ struct tf; /** * Init flag, set on bind and cleared on unbind */ -/* static uint8_t init; */ +static uint8_t init; /** * Shadow init flag, set on bind and cleared on unbind @@ -30,29 +35,164 @@ struct tf; /* static uint8_t shadow_init; */ int -tf_tbl_bind(struct tf *tfp __rte_unused, - struct tf_tbl_cfg_parms *parms __rte_unused) +tf_tbl_bind(struct tf *tfp, + struct tf_tbl_cfg_parms *parms) { + int rc; + int i; + struct tf_rm_create_db_parms db_cfg = { 0 }; + + TF_CHECK_PARMS2(tfp, parms); + + if (init) { + TFP_DRV_LOG(ERR, + "Table already initialized\n"); + return -EINVAL; + } + + db_cfg.num_elements = parms->num_elements; + + for (i = 0; i < TF_DIR_MAX; i++) { + db_cfg.dir = i; + db_cfg.num_elements = parms->num_elements; + db_cfg.cfg = parms->cfg; + db_cfg.alloc_cnt = parms->resources->tbl_cnt[i].cnt; + db_cfg.rm_db = &tbl_db[i]; + rc = tf_rm_create_db(tfp, &db_cfg); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Table DB creation failed\n", + tf_dir_2_str(i)); + + return rc; + } + } + + init = 1; + + printf("Table Type - initialized\n"); + return 0; } int tf_tbl_unbind(struct tf *tfp __rte_unused) { + int rc; + int i; + struct tf_rm_free_db_parms fparms = { 0 }; + + TF_CHECK_PARMS1(tfp); + + /* Bail if nothing has been initialized done silent as to + * allow for creation cleanup. + */ + if (!init) { + TFP_DRV_LOG(ERR, + "No Table DBs created\n"); + return -EINVAL; + } + + for (i = 0; i < TF_DIR_MAX; i++) { + fparms.dir = i; + fparms.rm_db = tbl_db[i]; + rc = tf_rm_free_db(tfp, &fparms); + if (rc) + return rc; + + tbl_db[i] = NULL; + } + + init = 0; + return 0; } int tf_tbl_alloc(struct tf *tfp __rte_unused, - struct tf_tbl_alloc_parms *parms __rte_unused) + struct tf_tbl_alloc_parms *parms) { + int rc; + uint32_t idx; + struct tf_rm_allocate_parms aparms = { 0 }; + + 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; + } + + /* Allocate requested element */ + aparms.rm_db = tbl_db[parms->dir]; + aparms.db_index = parms->type; + aparms.index = &idx; + rc = tf_rm_allocate(&aparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Failed allocate, type:%d\n", + tf_dir_2_str(parms->dir), + parms->type); + return rc; + } + + *parms->idx = idx; + return 0; } int tf_tbl_free(struct tf *tfp __rte_unused, - struct tf_tbl_free_parms *parms __rte_unused) + struct tf_tbl_free_parms *parms) { + int rc; + struct tf_rm_is_allocated_parms aparms = { 0 }; + struct tf_rm_free_parms fparms = { 0 }; + int allocated = 0; + + 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; + } + + /* Check if element is in use */ + aparms.rm_db = tbl_db[parms->dir]; + aparms.db_index = parms->type; + aparms.index = parms->idx; + aparms.allocated = &allocated; + rc = tf_rm_is_allocated(&aparms); + if (rc) + return rc; + + if (!allocated) { + TFP_DRV_LOG(ERR, + "%s: Entry already free, type:%d, index:%d\n", + tf_dir_2_str(parms->dir), + parms->type, + parms->idx); + return rc; + } + + /* Free requested element */ + fparms.rm_db = tbl_db[parms->dir]; + fparms.db_index = parms->type; + fparms.index = parms->idx; + rc = tf_rm_free(&fparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Free failed, type:%d, index:%d\n", + tf_dir_2_str(parms->dir), + parms->type, + parms->idx); + return rc; + } + return 0; } @@ -64,15 +204,107 @@ tf_tbl_alloc_search(struct tf *tfp __rte_unused, } int -tf_tbl_set(struct tf *tfp __rte_unused, - struct tf_tbl_set_parms *parms __rte_unused) +tf_tbl_set(struct tf *tfp, + struct tf_tbl_set_parms *parms) { + int rc; + struct tf_rm_is_allocated_parms aparms; + int allocated = 0; + + 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; + } + + /* Verify that the entry has been previously allocated */ + aparms.rm_db = tbl_db[parms->dir]; + aparms.db_index = parms->type; + aparms.index = parms->idx; + aparms.allocated = &allocated; + rc = tf_rm_is_allocated(&aparms); + if (rc) + return rc; + + if (!allocated) { + TFP_DRV_LOG(ERR, + "%s, Invalid or not allocated index, type:%d, idx:%d\n", + tf_dir_2_str(parms->dir), + parms->type, + parms->idx); + return -EINVAL; + } + + /* Set the entry */ + rc = tf_msg_set_tbl_entry(tfp, + parms->dir, + parms->type, + parms->data_sz_in_bytes, + parms->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 0; } int -tf_tbl_get(struct tf *tfp __rte_unused, - struct tf_tbl_get_parms *parms __rte_unused) +tf_tbl_get(struct tf *tfp, + struct tf_tbl_get_parms *parms) { + int rc; + struct tf_rm_is_allocated_parms aparms; + int allocated = 0; + + 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; + } + + /* Verify that the entry has been previously allocated */ + aparms.rm_db = tbl_db[parms->dir]; + aparms.db_index = parms->type; + aparms.index = parms->idx; + aparms.allocated = &allocated; + rc = tf_rm_is_allocated(&aparms); + if (rc) + return rc; + + if (!allocated) { + TFP_DRV_LOG(ERR, + "%s, Invalid or not allocated index, type:%d, idx:%d\n", + tf_dir_2_str(parms->dir), + parms->type, + parms->idx); + return -EINVAL; + } + + /* Get the entry */ + rc = tf_msg_get_tbl_entry(tfp, + parms->dir, + parms->type, + parms->data_sz_in_bytes, + parms->data, + parms->idx); + if (rc) { + TFP_DRV_LOG(ERR, + "%s, Get failed, type:%d, rc:%s\n", + tf_dir_2_str(parms->dir), + parms->type, + strerror(-rc)); + } + return 0; } diff --git a/drivers/net/bnxt/tf_core/tf_tbl_type.h b/drivers/net/bnxt/tf_core/tf_tbl_type.h index 11f2aa3332..3474489a6c 100644 --- a/drivers/net/bnxt/tf_core/tf_tbl_type.h +++ b/drivers/net/bnxt/tf_core/tf_tbl_type.h @@ -55,7 +55,7 @@ struct tf_tbl_alloc_parms { /** * [out] Idx of allocated entry or found entry (if search_enable) */ - uint32_t idx; + uint32_t *idx; }; /** diff --git a/drivers/net/bnxt/tf_core/tf_tcam.c b/drivers/net/bnxt/tf_core/tf_tcam.c index b9dba5323f..e0fac31f2c 100644 --- a/drivers/net/bnxt/tf_core/tf_tcam.c +++ b/drivers/net/bnxt/tf_core/tf_tcam.c @@ -38,8 +38,8 @@ static uint8_t init; /* static uint8_t shadow_init; */ int -tf_tcam_bind(struct tf *tfp __rte_unused, - struct tf_tcam_cfg_parms *parms __rte_unused) +tf_tcam_bind(struct tf *tfp, + struct tf_tcam_cfg_parms *parms) { int rc; int i; @@ -59,8 +59,8 @@ tf_tcam_bind(struct tf *tfp __rte_unused, db_cfg.dir = i; db_cfg.num_elements = parms->num_elements; db_cfg.cfg = parms->cfg; - db_cfg.alloc_num = parms->resources->tcam_tbl_cnt[i]; - db_cfg.rm_db = tcam_db[i]; + db_cfg.alloc_cnt = parms->resources->tcam_cnt[i].cnt; + db_cfg.rm_db = &tcam_db[i]; rc = tf_rm_create_db(tfp, &db_cfg); if (rc) { TFP_DRV_LOG(ERR, @@ -72,11 +72,13 @@ tf_tcam_bind(struct tf *tfp __rte_unused, init = 1; + printf("TCAM - initialized\n"); + return 0; } int -tf_tcam_unbind(struct tf *tfp __rte_unused) +tf_tcam_unbind(struct tf *tfp) { int rc; int i; diff --git a/drivers/net/bnxt/tf_core/tf_util.h b/drivers/net/bnxt/tf_core/tf_util.h index 4099629ea4..ad8edaf301 100644 --- a/drivers/net/bnxt/tf_core/tf_util.h +++ b/drivers/net/bnxt/tf_core/tf_util.h @@ -10,32 +10,57 @@ /** * Helper function converting direction to text string + * + * [in] dir + * Receive or transmit direction identifier + * + * Returns: + * Pointer to a char string holding the string for the direction */ -const char -*tf_dir_2_str(enum tf_dir dir); +const char *tf_dir_2_str(enum tf_dir dir); /** * Helper function converting identifier to text string + * + * [in] id_type + * Identifier type + * + * Returns: + * Pointer to a char string holding the string for the identifier */ -const char -*tf_ident_2_str(enum tf_identifier_type id_type); +const char *tf_ident_2_str(enum tf_identifier_type id_type); /** * Helper function converting tcam type to text string + * + * [in] tcam_type + * TCAM type + * + * Returns: + * Pointer to a char string holding the string for the tcam */ -const char -*tf_tcam_tbl_2_str(enum tf_tcam_tbl_type tcam_type); +const char *tf_tcam_tbl_2_str(enum tf_tcam_tbl_type tcam_type); /** * Helper function converting tbl type to text string + * + * [in] tbl_type + * Table type + * + * Returns: + * Pointer to a char string holding the string for the table type */ -const char -*tf_tbl_type_2_str(enum tf_tbl_type tbl_type); +const char *tf_tbl_type_2_str(enum tf_tbl_type tbl_type); /** * Helper function converting em tbl type to text string + * + * [in] em_type + * EM type + * + * Returns: + * Pointer to a char string holding the string for the EM type */ -const char -*tf_em_tbl_type_2_str(enum tf_em_tbl_type em_type); +const char *tf_em_tbl_type_2_str(enum tf_em_tbl_type em_type); #endif /* _TF_UTIL_H_ */ diff --git a/drivers/net/bnxt/tf_core/tfp.c b/drivers/net/bnxt/tf_core/tfp.c index 3bce3ade1e..69d1c9a1f9 100644 --- a/drivers/net/bnxt/tf_core/tfp.c +++ b/drivers/net/bnxt/tf_core/tfp.c @@ -102,13 +102,13 @@ tfp_calloc(struct tfp_calloc_parms *parms) (parms->nitems * parms->size), parms->alignment); if (parms->mem_va == NULL) { - PMD_DRV_LOG(ERR, "Allocate failed mem_va\n"); + TFP_DRV_LOG(ERR, "Allocate failed mem_va\n"); return -ENOMEM; } parms->mem_pa = (void *)((uintptr_t)rte_mem_virt2iova(parms->mem_va)); if (parms->mem_pa == (void *)((uintptr_t)RTE_BAD_IOVA)) { - PMD_DRV_LOG(ERR, "Allocate failed mem_pa\n"); + TFP_DRV_LOG(ERR, "Allocate failed mem_pa\n"); return -ENOMEM; }