From f000d3dcd57ce07de5f4b11bedd795a5a24bfab7 Mon Sep 17 00:00:00 2001 From: Jay Ding Date: Thu, 2 Jul 2020 16:28:13 -0700 Subject: [PATCH] net/bnxt: add external action allocate and free - Link external action alloc and free to new hcapi interface - Add parameter range checking - Fix issues with index allocation check Signed-off-by: Jay Ding Signed-off-by: Venkat Duvvuru Reviewed-by: Randy Schacher Reviewed-by: Ajit Khaparde --- drivers/net/bnxt/tf_core/tf_core.c | 163 ++++++++++++++++------- drivers/net/bnxt/tf_core/tf_core.h | 4 - drivers/net/bnxt/tf_core/tf_device.h | 58 ++++++++ drivers/net/bnxt/tf_core/tf_device_p4.c | 6 + drivers/net/bnxt/tf_core/tf_device_p4.h | 2 - drivers/net/bnxt/tf_core/tf_em.h | 95 +++++++++++++ drivers/net/bnxt/tf_core/tf_em_common.c | 120 ++++++++++++++++- drivers/net/bnxt/tf_core/tf_em_host.c | 80 ++++++++++- drivers/net/bnxt/tf_core/tf_em_system.c | 6 + drivers/net/bnxt/tf_core/tf_identifier.c | 4 +- drivers/net/bnxt/tf_core/tf_rm.h | 5 + drivers/net/bnxt/tf_core/tf_tbl.c | 10 +- drivers/net/bnxt/tf_core/tf_tbl.h | 12 ++ drivers/net/bnxt/tf_core/tf_tcam.c | 8 +- drivers/net/bnxt/tf_core/tf_util.c | 4 - 15 files changed, 499 insertions(+), 78 deletions(-) diff --git a/drivers/net/bnxt/tf_core/tf_core.c b/drivers/net/bnxt/tf_core/tf_core.c index 6410843f6e..45accb0aba 100644 --- a/drivers/net/bnxt/tf_core/tf_core.c +++ b/drivers/net/bnxt/tf_core/tf_core.c @@ -617,25 +617,48 @@ tf_alloc_tbl_entry(struct tf *tfp, 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; + aparms.tbl_scope_id = parms->tbl_scope_id; + + if (parms->type == TF_TBL_TYPE_EXT) { + if (dev->ops->tf_dev_alloc_ext_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; + } + + rc = dev->ops->tf_dev_alloc_ext_tbl(tfp, &aparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: External table allocation failed, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + } else { + 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; + } + + 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; @@ -677,25 +700,47 @@ tf_free_tbl_entry(struct tf *tfp, 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; + fparms.tbl_scope_id = parms->tbl_scope_id; + + if (parms->type == TF_TBL_TYPE_EXT) { + if (dev->ops->tf_dev_free_ext_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; + } + + rc = dev->ops->tf_dev_free_ext_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; + } + } else { + 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; + } + + 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; @@ -735,27 +780,49 @@ tf_set_tbl_entry(struct tf *tfp, 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; + sparms.tbl_scope_id = parms->tbl_scope_id; + + if (parms->type == TF_TBL_TYPE_EXT) { + if (dev->ops->tf_dev_set_ext_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; + } + + rc = dev->ops->tf_dev_set_ext_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; + } + } else { + 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; + } + + 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; diff --git a/drivers/net/bnxt/tf_core/tf_core.h b/drivers/net/bnxt/tf_core/tf_core.h index a7a7bd38ab..e898f19a01 100644 --- a/drivers/net/bnxt/tf_core/tf_core.h +++ b/drivers/net/bnxt/tf_core/tf_core.h @@ -211,10 +211,6 @@ enum tf_tbl_type { TF_TBL_TYPE_ACT_MODIFY_IPV4_SRC, /** Wh+/SR Action _Modify L4 Dest Port */ TF_TBL_TYPE_ACT_MODIFY_IPV4_DEST, - /** Action Modify IPv6 Source */ - TF_TBL_TYPE_ACT_MODIFY_IPV6_SRC, - /** Action Modify IPv6 Destination */ - TF_TBL_TYPE_ACT_MODIFY_IPV6_DEST, /** Meter Profiles */ TF_TBL_TYPE_METER_PROF, /** Meter Instance */ diff --git a/drivers/net/bnxt/tf_core/tf_device.h b/drivers/net/bnxt/tf_core/tf_device.h index 00bd996e5e..40395eb773 100644 --- a/drivers/net/bnxt/tf_core/tf_device.h +++ b/drivers/net/bnxt/tf_core/tf_device.h @@ -216,6 +216,26 @@ struct tf_dev_ops { int (*tf_dev_alloc_tbl)(struct tf *tfp, struct tf_tbl_alloc_parms *parms); + /** + * Allocation of a external table type element. + * + * This API allocates the specified table type element from a + * device specific table type DB. The allocated element is + * returned. + * + * [in] tfp + * Pointer to TF handle + * + * [in] parms + * Pointer to table allocation parameters + * + * Returns + * - (0) if successful. + * - (-EINVAL) on failure. + */ + int (*tf_dev_alloc_ext_tbl)(struct tf *tfp, + struct tf_tbl_alloc_parms *parms); + /** * Free of a table type element. * @@ -235,6 +255,25 @@ struct tf_dev_ops { int (*tf_dev_free_tbl)(struct tf *tfp, struct tf_tbl_free_parms *parms); + /** + * Free of a external table type element. + * + * This API free's a previous allocated table type element from a + * device specific table type DB. + * + * [in] tfp + * Pointer to TF handle + * + * [in] parms + * Pointer to table free parameters + * + * Returns + * - (0) if successful. + * - (-EINVAL) on failure. + */ + int (*tf_dev_free_ext_tbl)(struct tf *tfp, + struct tf_tbl_free_parms *parms); + /** * Searches for the specified table type element in a shadow DB. * @@ -276,6 +315,25 @@ struct tf_dev_ops { int (*tf_dev_set_tbl)(struct tf *tfp, struct tf_tbl_set_parms *parms); + /** + * Sets the specified external table type element. + * + * This API sets the specified element data by invoking the + * firmware. + * + * [in] tfp + * Pointer to TF handle + * + * [in] parms + * Pointer to table set parameters + * + * Returns + * - (0) if successful. + * - (-EINVAL) on failure. + */ + int (*tf_dev_set_ext_tbl)(struct tf *tfp, + struct tf_tbl_set_parms *parms); + /** * Retrieves the specified table type element. * diff --git a/drivers/net/bnxt/tf_core/tf_device_p4.c b/drivers/net/bnxt/tf_core/tf_device_p4.c index 1eaf182126..9a3230787b 100644 --- a/drivers/net/bnxt/tf_core/tf_device_p4.c +++ b/drivers/net/bnxt/tf_core/tf_device_p4.c @@ -85,10 +85,13 @@ const struct tf_dev_ops tf_dev_ops_p4_init = { .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_ext_tbl = NULL, .tf_dev_alloc_tbl = NULL, + .tf_dev_free_ext_tbl = NULL, .tf_dev_free_tbl = NULL, .tf_dev_alloc_search_tbl = NULL, .tf_dev_set_tbl = NULL, + .tf_dev_set_ext_tbl = NULL, .tf_dev_get_tbl = NULL, .tf_dev_get_bulk_tbl = NULL, .tf_dev_alloc_tcam = NULL, @@ -113,9 +116,12 @@ const struct tf_dev_ops tf_dev_ops_p4 = { .tf_dev_alloc_ident = tf_ident_alloc, .tf_dev_free_ident = tf_ident_free, .tf_dev_alloc_tbl = tf_tbl_alloc, + .tf_dev_alloc_ext_tbl = tf_tbl_ext_alloc, .tf_dev_free_tbl = tf_tbl_free, + .tf_dev_free_ext_tbl = tf_tbl_ext_free, .tf_dev_alloc_search_tbl = NULL, .tf_dev_set_tbl = tf_tbl_set, + .tf_dev_set_ext_tbl = tf_tbl_ext_set, .tf_dev_get_tbl = tf_tbl_get, .tf_dev_get_bulk_tbl = tf_tbl_bulk_get, .tf_dev_alloc_tcam = tf_tcam_alloc, diff --git a/drivers/net/bnxt/tf_core/tf_device_p4.h b/drivers/net/bnxt/tf_core/tf_device_p4.h index 8fae18012f..298e100f30 100644 --- a/drivers/net/bnxt/tf_core/tf_device_p4.h +++ b/drivers/net/bnxt/tf_core/tf_device_p4.h @@ -47,8 +47,6 @@ struct tf_rm_element_cfg tf_tbl_p4[TF_TBL_TYPE_MAX] = { { TF_RM_ELEM_CFG_HCAPI_BA, CFA_RESOURCE_TYPE_P4_NAT_DPORT }, { TF_RM_ELEM_CFG_HCAPI_BA, CFA_RESOURCE_TYPE_P4_NAT_S_IPV4 }, { TF_RM_ELEM_CFG_HCAPI_BA, CFA_RESOURCE_TYPE_P4_NAT_D_IPV4 }, - { TF_RM_ELEM_CFG_HCAPI_BA, CFA_RESOURCE_TYPE_P4_NAT_S_IPV6 }, - { TF_RM_ELEM_CFG_HCAPI_BA, CFA_RESOURCE_TYPE_P4_NAT_D_IPV6 }, { TF_RM_ELEM_CFG_HCAPI_BA, CFA_RESOURCE_TYPE_P4_METER_PROF }, { TF_RM_ELEM_CFG_HCAPI_BA, CFA_RESOURCE_TYPE_P4_METER }, { TF_RM_ELEM_CFG_HCAPI_BA, CFA_RESOURCE_TYPE_P4_MIRROR }, diff --git a/drivers/net/bnxt/tf_core/tf_em.h b/drivers/net/bnxt/tf_core/tf_em.h index 617b075874..39a216341b 100644 --- a/drivers/net/bnxt/tf_core/tf_em.h +++ b/drivers/net/bnxt/tf_core/tf_em.h @@ -456,4 +456,99 @@ int tf_em_ext_common_free(struct tf *tfp, */ int tf_em_ext_common_alloc(struct tf *tfp, struct tf_alloc_tbl_scope_parms *parms); + +/** + * Allocate External Tbl entry from the scope 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 + */ +int +tf_tbl_ext_alloc(struct tf *tfp, + struct tf_tbl_alloc_parms *parms); + +/** + * Free External Tbl entry to the scope 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 + */ +int +tf_tbl_ext_free(struct tf *tfp, + struct tf_tbl_free_parms *parms); + +/** + * Sets the specified external table type element. + * + * This API sets the specified element data by invoking the + * firmware. + * + * [in] tfp + * Pointer to TF handle + * + * [in] parms + * Pointer to table set parameters + * + * Returns + * - (0) if successful. + * - (-EINVAL) on failure. + */ +int tf_tbl_ext_set(struct tf *tfp, + struct tf_tbl_set_parms *parms); + +/** + * Sets the specified external table type element. + * + * This API sets the specified element data by invoking the + * firmware. + * + * [in] tfp + * Pointer to TF handle + * + * [in] parms + * Pointer to table set parameters + * + * Returns + * - (0) if successful. + * - (-EINVAL) on failure. + */ +int tf_tbl_ext_host_set(struct tf *tfp, + struct tf_tbl_set_parms *parms); + +/** + * Sets the specified external table type element. + * + * This API sets the specified element data by invoking the + * firmware. + * + * [in] tfp + * Pointer to TF handle + * + * [in] parms + * Pointer to table set parameters + * + * Returns + * - (0) if successful. + * - (-EINVAL) on failure. + */ +int tf_tbl_ext_system_set(struct tf *tfp, + struct tf_tbl_set_parms *parms); + #endif /* _TF_EM_H_ */ diff --git a/drivers/net/bnxt/tf_core/tf_em_common.c b/drivers/net/bnxt/tf_core/tf_em_common.c index e31a63b466..39a8412b3e 100644 --- a/drivers/net/bnxt/tf_core/tf_em_common.c +++ b/drivers/net/bnxt/tf_core/tf_em_common.c @@ -29,8 +29,6 @@ */ void *eem_db[TF_DIR_MAX]; -#define TF_EEM_DB_TBL_SCOPE 1 - /** * Init flag, set on bind and cleared on unbind */ @@ -54,13 +52,13 @@ tbl_scope_cb_find(uint32_t tbl_scope_id) /* Check that id is valid */ parms.rm_db = eem_db[TF_DIR_RX]; - parms.db_index = TF_EEM_DB_TBL_SCOPE; + parms.db_index = TF_EM_TBL_TYPE_TBL_SCOPE; parms.index = tbl_scope_id; parms.allocated = &allocated; i = tf_rm_is_allocated(&parms); - if (i < 0 || !allocated) + if (i < 0 || allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) return NULL; for (i = 0; i < TF_NUM_TBL_SCOPE; i++) { @@ -158,6 +156,111 @@ tf_destroy_tbl_pool_external(enum tf_dir dir, tfp_free(ext_act_pool_mem); } +/** + * Allocate External Tbl entry from the scope 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 + */ +int +tf_tbl_ext_alloc(struct tf *tfp, + struct tf_tbl_alloc_parms *parms) +{ + int rc; + uint32_t index; + struct tf_tbl_scope_cb *tbl_scope_cb; + struct stack *pool; + + TF_CHECK_PARMS2(tfp, parms); + + /* Get the pool info from the table scope + */ + tbl_scope_cb = tbl_scope_cb_find(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; +} + +/** + * Free External Tbl entry to the scope 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 + */ +int +tf_tbl_ext_free(struct tf *tfp, + struct tf_tbl_free_parms *parms) +{ + int rc = 0; + uint32_t index; + struct tf_tbl_scope_cb *tbl_scope_cb; + struct stack *pool; + + TF_CHECK_PARMS2(tfp, parms); + + /* Get the pool info from the table scope + */ + tbl_scope_cb = tbl_scope_cb_find(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; +} + uint32_t tf_em_get_key_mask(int num_entries) { @@ -273,6 +376,15 @@ tf_em_ext_common_unbind(struct tf *tfp) return 0; } +int tf_tbl_ext_set(struct tf *tfp, + struct tf_tbl_set_parms *parms) +{ + if (mem_type == TF_EEM_MEM_TYPE_HOST) + return tf_tbl_ext_host_set(tfp, parms); + else + return tf_tbl_ext_system_set(tfp, parms); +} + int tf_em_ext_common_alloc(struct tf *tfp, struct tf_alloc_tbl_scope_parms *parms) diff --git a/drivers/net/bnxt/tf_core/tf_em_host.c b/drivers/net/bnxt/tf_core/tf_em_host.c index 2fb83ea22d..aab297b450 100644 --- a/drivers/net/bnxt/tf_core/tf_em_host.c +++ b/drivers/net/bnxt/tf_core/tf_em_host.c @@ -48,7 +48,6 @@ * EM DBs. */ extern void *eem_db[TF_DIR_MAX]; -#define TF_EEM_DB_TBL_SCOPE 1 extern struct tf_tbl_scope_cb tbl_scopes[TF_NUM_TBL_SCOPE]; @@ -986,7 +985,7 @@ tf_em_ext_host_alloc(struct tf *tfp, /* Get Table Scope control block from the session pool */ aparms.rm_db = eem_db[TF_DIR_RX]; - aparms.db_index = TF_EEM_DB_TBL_SCOPE; + aparms.db_index = TF_EM_TBL_TYPE_TBL_SCOPE; aparms.index = (uint32_t *)&parms->tbl_scope_id; rc = tf_rm_allocate(&aparms); if (rc) { @@ -1087,7 +1086,7 @@ cleanup_full: cleanup: /* Free Table control block */ fparms.rm_db = eem_db[TF_DIR_RX]; - fparms.db_index = TF_EEM_DB_TBL_SCOPE; + fparms.db_index = TF_EM_TBL_TYPE_TBL_SCOPE; fparms.index = parms->tbl_scope_id; tf_rm_free(&fparms); return -EINVAL; @@ -1111,7 +1110,7 @@ tf_em_ext_host_free(struct tf *tfp, /* Free Table control block */ aparms.rm_db = eem_db[TF_DIR_RX]; - aparms.db_index = TF_EEM_DB_TBL_SCOPE; + aparms.db_index = TF_EM_TBL_TYPE_TBL_SCOPE; aparms.index = parms->tbl_scope_id; rc = tf_rm_free(&aparms); if (rc) { @@ -1133,6 +1132,77 @@ tf_em_ext_host_free(struct tf *tfp, tf_em_ctx_unreg(tfp, tbl_scope_cb, dir); } - tbl_scopes[parms->tbl_scope_id].tbl_scope_id = -1; + tbl_scopes[parms->tbl_scope_id].tbl_scope_id = TF_TBL_SCOPE_INVALID; + return rc; +} + +/** + * Sets the specified external table type element. + * + * This API sets the specified element data + * + * [in] tfp + * Pointer to TF handle + * + * [in] parms + * Pointer to table set parameters + * + * Returns + * - (0) if successful. + * - (-EINVAL) on failure. + */ +int tf_tbl_ext_host_set(struct tf *tfp, + struct tf_tbl_set_parms *parms) +{ + int rc = 0; + struct tf_tbl_scope_cb *tbl_scope_cb; + uint32_t tbl_scope_id; + struct hcapi_cfa_hwop op; + struct hcapi_cfa_key_tbl key_tbl; + struct hcapi_cfa_key_data key_obj; + struct hcapi_cfa_key_loc key_loc; + + TF_CHECK_PARMS2(tfp, parms); + + if (parms->data == NULL) { + TFP_DRV_LOG(ERR, + "%s, invalid parms->data\n", + tf_dir_2_str(parms->dir)); + return -EINVAL; + } + + 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(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; + } + + op.opcode = HCAPI_CFA_HWOPS_PUT; + key_tbl.base0 = + (uint8_t *)&tbl_scope_cb->em_ctx_info[parms->dir].em_tables[TF_RECORD_TABLE]; + key_obj.offset = parms->idx % TF_EM_PAGE_SIZE; + key_obj.data = parms->data; + key_obj.size = parms->data_sz_in_bytes; + + rc = hcapi_cfa_key_hw_op(&op, + &key_tbl, + &key_obj, + &key_loc); + return rc; } diff --git a/drivers/net/bnxt/tf_core/tf_em_system.c b/drivers/net/bnxt/tf_core/tf_em_system.c index 6dd1154701..10768df03c 100644 --- a/drivers/net/bnxt/tf_core/tf_em_system.c +++ b/drivers/net/bnxt/tf_core/tf_em_system.c @@ -112,3 +112,9 @@ tf_em_ext_system_free(struct tf *tfp __rte_unused, { return 0; } + +int tf_tbl_ext_system_set(struct tf *tfp __rte_unused, + struct tf_tbl_set_parms *parms __rte_unused) +{ + return 0; +} diff --git a/drivers/net/bnxt/tf_core/tf_identifier.c b/drivers/net/bnxt/tf_core/tf_identifier.c index 2113710814..219839272f 100644 --- a/drivers/net/bnxt/tf_core/tf_identifier.c +++ b/drivers/net/bnxt/tf_core/tf_identifier.c @@ -159,13 +159,13 @@ tf_ident_free(struct tf *tfp __rte_unused, if (rc) return rc; - if (!allocated) { + if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) { TFP_DRV_LOG(ERR, "%s: Entry already free, type:%d, index:%d\n", tf_dir_2_str(parms->dir), parms->type, parms->id); - return rc; + return -EINVAL; } /* Free requested element */ diff --git a/drivers/net/bnxt/tf_core/tf_rm.h b/drivers/net/bnxt/tf_core/tf_rm.h index f1c98bed33..775f0aa1a1 100644 --- a/drivers/net/bnxt/tf_core/tf_rm.h +++ b/drivers/net/bnxt/tf_core/tf_rm.h @@ -12,6 +12,11 @@ struct tf; +/** RM return codes */ +#define TF_RM_ALLOCATED_ENTRY_FREE 0 +#define TF_RM_ALLOCATED_ENTRY_IN_USE 1 +#define TF_RM_ALLOCATED_NO_ENTRY_FOUND -1 + /** * The Resource Manager (RM) module provides basic DB handling for * internal resources. These resources exists within the actual device diff --git a/drivers/net/bnxt/tf_core/tf_tbl.c b/drivers/net/bnxt/tf_core/tf_tbl.c index 05e866dc6c..3a3277329e 100644 --- a/drivers/net/bnxt/tf_core/tf_tbl.c +++ b/drivers/net/bnxt/tf_core/tf_tbl.c @@ -172,13 +172,13 @@ tf_tbl_free(struct tf *tfp __rte_unused, if (rc) return rc; - if (!allocated) { + if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) { 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; + return -EINVAL; } /* Free requested element */ @@ -233,7 +233,7 @@ tf_tbl_set(struct tf *tfp, if (rc) return rc; - if (!allocated) { + if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) { TFP_DRV_LOG(ERR, "%s, Invalid or not allocated index, type:%d, idx:%d\n", tf_dir_2_str(parms->dir), @@ -301,7 +301,7 @@ tf_tbl_get(struct tf *tfp, if (rc) return rc; - if (!allocated) { + if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) { TFP_DRV_LOG(ERR, "%s, Invalid or not allocated index, type:%d, idx:%d\n", tf_dir_2_str(parms->dir), @@ -374,7 +374,7 @@ tf_tbl_bulk_get(struct tf *tfp, if (rc) return rc; - if (!allocated) { + if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) { TFP_DRV_LOG(ERR, "%s, Invalid or not allocated index, type:%d, idx:%d\n", tf_dir_2_str(parms->dir), diff --git a/drivers/net/bnxt/tf_core/tf_tbl.h b/drivers/net/bnxt/tf_core/tf_tbl.h index eb560ffa72..2a10b47ce9 100644 --- a/drivers/net/bnxt/tf_core/tf_tbl.h +++ b/drivers/net/bnxt/tf_core/tf_tbl.h @@ -83,6 +83,10 @@ struct tf_tbl_alloc_parms { * [in] Type of the allocation */ enum tf_tbl_type type; + /** + * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT) + */ + uint32_t tbl_scope_id; /** * [out] Idx of allocated entry or found entry (if search_enable) */ @@ -101,6 +105,10 @@ struct tf_tbl_free_parms { * [in] Type of the allocation type */ enum tf_tbl_type type; + /** + * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT) + */ + uint32_t tbl_scope_id; /** * [in] Index to free */ @@ -168,6 +176,10 @@ struct tf_tbl_set_parms { * [in] Type of object to set */ enum tf_tbl_type type; + /** + * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT) + */ + uint32_t tbl_scope_id; /** * [in] Entry data */ diff --git a/drivers/net/bnxt/tf_core/tf_tcam.c b/drivers/net/bnxt/tf_core/tf_tcam.c index b67159a549..b1092cd9da 100644 --- a/drivers/net/bnxt/tf_core/tf_tcam.c +++ b/drivers/net/bnxt/tf_core/tf_tcam.c @@ -252,13 +252,13 @@ tf_tcam_free(struct tf *tfp, if (rc) return rc; - if (!allocated) { + if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) { 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; + return -EINVAL; } /* Free requested element */ @@ -362,13 +362,13 @@ tf_tcam_set(struct tf *tfp __rte_unused, if (rc) return rc; - if (!allocated) { + if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) { TFP_DRV_LOG(ERR, "%s: Entry is not allocated, type:%d, index:%d\n", tf_dir_2_str(parms->dir), parms->type, parms->idx); - return rc; + return -EINVAL; } /* Convert TF type to HCAPI RM type */ diff --git a/drivers/net/bnxt/tf_core/tf_util.c b/drivers/net/bnxt/tf_core/tf_util.c index 3d26d3fff2..aeee3b3068 100644 --- a/drivers/net/bnxt/tf_core/tf_util.c +++ b/drivers/net/bnxt/tf_core/tf_util.c @@ -92,10 +92,6 @@ tf_tbl_type_2_str(enum tf_tbl_type tbl_type) return "NAT IPv4 Source"; case TF_TBL_TYPE_ACT_MODIFY_IPV4_DEST: return "NAT IPv4 Destination"; - case TF_TBL_TYPE_ACT_MODIFY_IPV6_SRC: - return "NAT IPv6 Source"; - case TF_TBL_TYPE_ACT_MODIFY_IPV6_DEST: - return "NAT IPv6 Destination"; case TF_TBL_TYPE_METER_PROF: return "Meter Profile"; case TF_TBL_TYPE_METER_INST: -- 2.20.1