X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fbnxt%2Ftf_core%2Ftf_core.c;h=81a88e2113b3db76f8ab0d08ae4de902c1ecf2e1;hb=a46bbb57605b40201c2bab6386a7890451224836;hp=39f4a110a5798d2bb5a59ab5bd281a61134ea6cc;hpb=82fa189de8ae89b4a3c181140ff4a2490b192a03;p=dpdk.git diff --git a/drivers/net/bnxt/tf_core/tf_core.c b/drivers/net/bnxt/tf_core/tf_core.c index 39f4a110a5..81a88e2113 100644 --- a/drivers/net/bnxt/tf_core/tf_core.c +++ b/drivers/net/bnxt/tf_core/tf_core.c @@ -6,13 +6,18 @@ #include #include "tf_core.h" +#include "tf_util.h" #include "tf_session.h" +#include "tf_tbl.h" +#include "tf_em.h" #include "tf_rm.h" #include "tf_msg.h" #include "tfp.h" #include "bitalloc.h" #include "bnxt.h" #include "rand.h" +#include "tf_common.h" +#include "hwrm_tf.h" static inline uint32_t SWAP_WORDS32(uint32_t val32) { @@ -43,6 +48,100 @@ static void tf_seeds_init(struct tf_session *session) } } +/** + * 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, struct tf_open_session_parms *parms) @@ -52,6 +151,7 @@ tf_open_session(struct tf *tfp, struct tfp_calloc_parms alloc_parms; unsigned int domain, bus, slot, device; uint8_t fw_session_id; + int dir; if (tfp == NULL || parms == NULL) return -EINVAL; @@ -108,7 +208,7 @@ tf_open_session(struct tf *tfp, goto cleanup; } - tfp->session = (struct tf_session_info *)alloc_parms.mem_va; + tfp->session = alloc_parms.mem_va; /* Allocate core data for the session */ alloc_parms.nitems = 1; @@ -131,7 +231,7 @@ tf_open_session(struct tf *tfp, TF_SESSION_NAME_MAX); /* Initialize Session */ - session->device_type = parms->device_type; + session->dev = NULL; tf_rm_init(tfp); /* Construct the Session ID */ @@ -173,6 +273,18 @@ tf_open_session(struct tf *tfp, /* Setup hash seeds */ tf_seeds_init(session); + /* 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 */ @@ -202,6 +314,64 @@ tf_open_session(struct tf *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); + + /* 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; + } + + /* Verify control channel and 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; + } + + parms->session_id.internal.domain = domain; + parms->session_id.internal.bus = bus; + parms->session_id.internal.device = device; + oparms.open_cfg = parms; + + rc = tf_session_open_session(tfp, &oparms); + /* Logging handled by tf_session_open_session */ + if (rc) + return rc; + + 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; +} + int tf_attach_session(struct tf *tfp __rte_unused, struct tf_attach_session_parms *parms __rte_unused) @@ -230,6 +400,69 @@ tf_attach_session(struct tf *tfp __rte_unused, return -1; } +int +tf_attach_session_new(struct tf *tfp, + struct tf_attach_session_parms *parms) +{ + int rc; + unsigned int domain, bus, slot, device; + struct tf_session_attach_session_parms aparms; + + TF_CHECK_PARMS2(tfp, parms); + + /* Verify control channel */ + 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; + } + + /* Verify 'attach' channel */ + rc = sscanf(parms->attach_chan_name, + "%x:%x:%x.%d", + &domain, + &bus, + &slot, + &device); + if (rc != 4) { + TFP_DRV_LOG(ERR, + "Failed to scan device attach_chan_name\n"); + return -EINVAL; + } + + /* Prepare return value of session_id, using ctrl_chan_name + * device values as it becomes the session id. + */ + parms->session_id.internal.domain = domain; + parms->session_id.internal.bus = bus; + parms->session_id.internal.device = device; + aparms.attach_cfg = parms; + rc = tf_session_attach_session(tfp, + &aparms); + /* Logging handled by dev_bind */ + if (rc) + return rc; + + TFP_DRV_LOG(INFO, + "Attached to session, 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 rc; +} + int tf_close_session(struct tf *tfp) { @@ -237,6 +470,7 @@ tf_close_session(struct tf *tfp) int rc_close = 0; struct tf_session *tfs; union tf_session_id session_id; + int dir; if (tfp == NULL || tfp->session == NULL) return -EINVAL; @@ -266,6 +500,10 @@ tf_close_session(struct tf *tfp) /* 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; @@ -285,6 +523,100 @@ tf_close_session(struct tf *tfp) return rc_close; } +int +tf_close_session_new(struct tf *tfp) +{ + int rc; + struct tf_session_close_session_parms cparms = { 0 }; + union tf_session_id session_id = { 0 }; + uint8_t ref_count; + + TF_CHECK_PARMS1(tfp); + + cparms.ref_count = &ref_count; + cparms.session_id = &session_id; + rc = tf_session_close_session(tfp, + &cparms); + /* Logging handled by tf_session_close_session */ + if (rc) + return rc; + + TFP_DRV_LOG(INFO, + "Closed session, session_id:%d, ref_count:%d\n", + cparms.session_id->id, + *cparms.ref_count); + + TFP_DRV_LOG(INFO, + "domain:%d, bus:%d, device:%d, fw_session_id:%d\n", + cparms.session_id->internal.domain, + cparms.session_id->internal.bus, + cparms.session_id->internal.device, + cparms.session_id->internal.fw_session_id); + + return rc; +} + +/** insert EM hash entry API + * + * returns: + * 0 - Success + * -EINVAL - Error + */ +int tf_insert_em_entry(struct tf *tfp, + struct tf_insert_em_entry_parms *parms) +{ + struct tf_tbl_scope_cb *tbl_scope_cb; + + if (tfp == NULL || parms == NULL) + return -EINVAL; + + tbl_scope_cb = tbl_scope_cb_find((struct tf_session *) + (tfp->session->core_data), + parms->tbl_scope_id); + if (tbl_scope_cb == NULL) + return -EINVAL; + + /* Process the EM entry per Table Scope type */ + if (parms->mem == TF_MEM_EXTERNAL) { + /* External EEM */ + return tf_insert_eem_entry((struct tf_session *) + (tfp->session->core_data), + tbl_scope_cb, + parms); + } else if (parms->mem == TF_MEM_INTERNAL) { + /* Internal EM */ + return tf_insert_em_internal_entry(tfp, parms); + } + + return -EINVAL; +} + +/** Delete EM hash entry API + * + * returns: + * 0 - Success + * -EINVAL - Error + */ +int tf_delete_em_entry(struct tf *tfp, + struct tf_delete_em_entry_parms *parms) +{ + struct tf_tbl_scope_cb *tbl_scope_cb; + + if (tfp == NULL || parms == NULL) + return -EINVAL; + + tbl_scope_cb = tbl_scope_cb_find((struct tf_session *) + (tfp->session->core_data), + parms->tbl_scope_id); + if (tbl_scope_cb == NULL) + return -EINVAL; + + if (parms->mem == TF_MEM_EXTERNAL) + return tf_delete_eem_entry(tfp, parms); + else + return tf_delete_em_internal_entry(tfp, parms); +} + /** allocate identifier resource * * Returns success or failure code. @@ -362,10 +694,67 @@ int tf_alloc_identifier(struct tf *tfp, return 0; } -/** free identifier resource - * - * Returns success or failure code. - */ +int +tf_alloc_identifier_new(struct tf *tfp, + struct tf_alloc_identifier_parms *parms) +{ + int rc; + struct tf_session *tfs; + struct tf_dev_info *dev; + struct tf_ident_alloc_parms aparms; + uint16_t id; + + TF_CHECK_PARMS2(tfp, parms); + + /* Can't do static initialization due to UT enum check */ + memset(&aparms, 0, sizeof(struct tf_ident_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_ident == 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.ident_type = parms->ident_type; + aparms.id = &id; + rc = dev->ops->tf_dev_alloc_ident(tfp, &aparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Identifier allocation failed, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + parms->id = id; + + return 0; +} + int tf_free_identifier(struct tf *tfp, struct tf_free_identifier_parms *parms) { @@ -441,6 +830,64 @@ int tf_free_identifier(struct tf *tfp, return 0; } +int +tf_free_identifier_new(struct tf *tfp, + struct tf_free_identifier_parms *parms) +{ + int rc; + struct tf_session *tfs; + struct tf_dev_info *dev; + struct tf_ident_free_parms fparms; + + TF_CHECK_PARMS2(tfp, parms); + + /* Can't do static initialization due to UT enum check */ + memset(&fparms, 0, sizeof(struct tf_ident_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_ident == 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.ident_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", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + return 0; +} + int tf_alloc_tcam_entry(struct tf *tfp, struct tf_alloc_tcam_entry_parms *parms)