From a11f87d3b2caac31623b9f0d190bd93465b27153 Mon Sep 17 00:00:00 2001 From: Jay Ding Date: Thu, 2 Jul 2020 16:28:17 -0700 Subject: [PATCH] net/bnxt: add global config set and get functions - Add support to update global configuration for ACT_TECT and ACT_ABCR. - Add support to allow Tunnel and Action global configuration. - Remove register read and write operations. - Remove the register read and write support. Signed-off-by: Jay Ding Signed-off-by: Venkat Duvvuru Reviewed-by: Randy Schacher Reviewed-by: Ajit Khaparde --- drivers/net/bnxt/hcapi/hcapi_cfa.h | 3 + drivers/net/bnxt/meson.build | 1 + drivers/net/bnxt/tf_core/Makefile | 1 + drivers/net/bnxt/tf_core/hwrm_tf.h | 54 +++++- drivers/net/bnxt/tf_core/tf_core.c | 137 ++++++++++++++++ drivers/net/bnxt/tf_core/tf_core.h | 77 +++++++++ drivers/net/bnxt/tf_core/tf_device.c | 20 +++ drivers/net/bnxt/tf_core/tf_device.h | 33 ++++ drivers/net/bnxt/tf_core/tf_device_p4.c | 4 + drivers/net/bnxt/tf_core/tf_device_p4.h | 5 + drivers/net/bnxt/tf_core/tf_global_cfg.c | 199 +++++++++++++++++++++++ drivers/net/bnxt/tf_core/tf_global_cfg.h | 170 +++++++++++++++++++ drivers/net/bnxt/tf_core/tf_msg.c | 109 ++++++++++++- drivers/net/bnxt/tf_core/tf_msg.h | 31 ++++ 14 files changed, 839 insertions(+), 5 deletions(-) create mode 100644 drivers/net/bnxt/tf_core/tf_global_cfg.c create mode 100644 drivers/net/bnxt/tf_core/tf_global_cfg.h diff --git a/drivers/net/bnxt/hcapi/hcapi_cfa.h b/drivers/net/bnxt/hcapi/hcapi_cfa.h index 89b2315a82..c7d87dec73 100644 --- a/drivers/net/bnxt/hcapi/hcapi_cfa.h +++ b/drivers/net/bnxt/hcapi/hcapi_cfa.h @@ -245,6 +245,9 @@ int hcapi_cfa_p4_wc_tcam_rec_hwop(struct hcapi_cfa_hwop *op, struct hcapi_cfa_data *obj_data); int hcapi_cfa_p4_mirror_hwop(struct hcapi_cfa_hwop *op, struct hcapi_cfa_data *mirror); +int hcapi_cfa_p4_global_cfg_hwop(struct hcapi_cfa_hwop *op, + uint32_t type, + struct hcapi_cfa_data *config); #endif /* SUPPORT_CFA_HW_P4 */ /** * HCAPI CFA device HW operation function callback definition diff --git a/drivers/net/bnxt/meson.build b/drivers/net/bnxt/meson.build index 54564e02eb..ace7353bea 100644 --- a/drivers/net/bnxt/meson.build +++ b/drivers/net/bnxt/meson.build @@ -45,6 +45,7 @@ sources = files('bnxt_cpr.c', 'tf_core/tf_util.c', 'tf_core/tf_if_tbl.c', 'tf_core/ll.c', + 'tf_core/tf_global_cfg.c', 'hcapi/hcapi_cfa_p4.c', diff --git a/drivers/net/bnxt/tf_core/Makefile b/drivers/net/bnxt/tf_core/Makefile index 2b94543b7e..e23e0ebb87 100644 --- a/drivers/net/bnxt/tf_core/Makefile +++ b/drivers/net/bnxt/tf_core/Makefile @@ -27,3 +27,4 @@ SRCS-$(CONFIG_RTE_LIBRTE_BNXT_PMD) += tf_core/tf_shadow_tcam.c SRCS-$(CONFIG_RTE_LIBRTE_BNXT_PMD) += tf_core/tf_tcam.c SRCS-$(CONFIG_RTE_LIBRTE_BNXT_PMD) += tf_core/tf_util.c SRCS-$(CONFIG_RTE_LIBRTE_BNXT_PMD) += tf_core/tf_if_tbl.c +SRCS-$(CONFIG_RTE_LIBRTE_BNXT_PMD) += tf_core/tf_global_cfg.c diff --git a/drivers/net/bnxt/tf_core/hwrm_tf.h b/drivers/net/bnxt/tf_core/hwrm_tf.h index 32f1523142..7ade9927af 100644 --- a/drivers/net/bnxt/tf_core/hwrm_tf.h +++ b/drivers/net/bnxt/tf_core/hwrm_tf.h @@ -13,8 +13,8 @@ typedef enum tf_type { } tf_type_t; typedef enum tf_subtype { - HWRM_TFT_REG_GET = 821, - HWRM_TFT_REG_SET = 822, + HWRM_TFT_GET_GLOBAL_CFG = 821, + HWRM_TFT_SET_GLOBAL_CFG = 822, HWRM_TFT_TBL_TYPE_BULK_GET = 825, HWRM_TFT_IF_TBL_SET = 827, HWRM_TFT_IF_TBL_GET = 828, @@ -66,18 +66,66 @@ typedef enum tf_subtype { #define TF_BITS2BYTES(x) (((x) + 7) >> 3) #define TF_BITS2BYTES_WORD_ALIGN(x) ((((x) + 31) >> 5) * 4) +struct tf_set_global_cfg_input; +struct tf_get_global_cfg_input; +struct tf_get_global_cfg_output; struct tf_tbl_type_bulk_get_input; struct tf_tbl_type_bulk_get_output; struct tf_if_tbl_set_input; struct tf_if_tbl_get_input; struct tf_if_tbl_get_output; +/* Input params for global config set */ +typedef struct tf_set_global_cfg_input { + /* Session Id */ + uint32_t fw_session_id; + /* flags */ + uint32_t flags; + /* When set to 0, indicates the query apply to RX */ +#define TF_SET_GLOBAL_CFG_INPUT_FLAGS_DIR_RX (0x0) + /* When set to 1, indicates the query apply to TX */ +#define TF_SET_GLOBAL_CFG_INPUT_FLAGS_DIR_TX (0x1) + /* Config type */ + uint32_t type; + /* Offset of the type */ + uint32_t offset; + /* Size of the data to set in bytes */ + uint16_t size; + /* Data to set */ + uint8_t data[TF_BULK_SEND]; +} tf_set_global_cfg_input_t, *ptf_set_global_cfg_input_t; + +/* Input params for global config to get */ +typedef struct tf_get_global_cfg_input { + /* Session Id */ + uint32_t fw_session_id; + /* flags */ + uint32_t flags; + /* When set to 0, indicates the query apply to RX */ +#define TF_GET_GLOBAL_CFG_INPUT_FLAGS_DIR_RX (0x0) + /* When set to 1, indicates the query apply to TX */ +#define TF_GET_GLOBAL_CFG_INPUT_FLAGS_DIR_TX (0x1) + /* Config to retrieve */ + uint32_t type; + /* Offset to retrieve */ + uint32_t offset; + /* Size of the data to set in bytes */ + uint16_t size; +} tf_get_global_cfg_input_t, *ptf_get_global_cfg_input_t; + +/* Output params for global config */ +typedef struct tf_get_global_cfg_output { + /* Size of the total data read in bytes */ + uint16_t size; + /* Data to get */ + uint8_t data[TF_BULK_SEND]; +} tf_get_global_cfg_output_t, *ptf_get_global_cfg_output_t; /* Input params for table type get */ typedef struct tf_tbl_type_bulk_get_input { /* Session Id */ uint32_t fw_session_id; /* flags */ - uint16_t flags; + uint32_t flags; /* When set to 0, indicates the get apply to RX */ #define TF_TBL_TYPE_BULK_GET_INPUT_FLAGS_DIR_RX (0x0) /* When set to 1, indicates the get apply to TX */ diff --git a/drivers/net/bnxt/tf_core/tf_core.c b/drivers/net/bnxt/tf_core/tf_core.c index 489c461d11..0f119b45fe 100644 --- a/drivers/net/bnxt/tf_core/tf_core.c +++ b/drivers/net/bnxt/tf_core/tf_core.c @@ -11,6 +11,7 @@ #include "tf_tbl.h" #include "tf_em.h" #include "tf_rm.h" +#include "tf_global_cfg.h" #include "tf_msg.h" #include "tfp.h" #include "bitalloc.h" @@ -277,6 +278,142 @@ int tf_delete_em_entry(struct tf *tfp, return rc; } +/** Get global configuration API + * + * returns: + * 0 - Success + * -EINVAL - Error + */ +int tf_get_global_cfg(struct tf *tfp, + struct tf_global_cfg_parms *parms) +{ + int rc = 0; + struct tf_session *tfs; + struct tf_dev_info *dev; + struct tf_dev_global_cfg_parms gparms = { 0 }; + + TF_CHECK_PARMS2(tfp, 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 (parms->config == NULL || + parms->config_sz_in_bytes == 0) { + TFP_DRV_LOG(ERR, "Invalid Argument(s)\n"); + return -EINVAL; + } + + if (dev->ops->tf_dev_get_global_cfg == 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.offset = parms->offset; + gparms.config = parms->config; + gparms.config_sz_in_bytes = parms->config_sz_in_bytes; + rc = dev->ops->tf_dev_get_global_cfg(tfp, &gparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Global Cfg get failed, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + return rc; +} + +/** Set global configuration API + * + * returns: + * 0 - Success + * -EINVAL - Error + */ +int tf_set_global_cfg(struct tf *tfp, + struct tf_global_cfg_parms *parms) +{ + int rc = 0; + struct tf_session *tfs; + struct tf_dev_info *dev; + struct tf_dev_global_cfg_parms gparms = { 0 }; + + TF_CHECK_PARMS2(tfp, 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 (parms->config == NULL || + parms->config_sz_in_bytes == 0) { + TFP_DRV_LOG(ERR, "Invalid Argument(s)\n"); + return -EINVAL; + } + + if (dev->ops->tf_dev_set_global_cfg == 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.offset = parms->offset; + gparms.config = parms->config; + gparms.config_sz_in_bytes = parms->config_sz_in_bytes; + rc = dev->ops->tf_dev_set_global_cfg(tfp, &gparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Global Cfg set failed, rc:%s\n", + tf_dir_2_str(parms->dir), + strerror(-rc)); + return rc; + } + + return rc; +} + int tf_alloc_identifier(struct tf *tfp, struct tf_alloc_identifier_parms *parms) diff --git a/drivers/net/bnxt/tf_core/tf_core.h b/drivers/net/bnxt/tf_core/tf_core.h index fea222bee4..3f54ab16b0 100644 --- a/drivers/net/bnxt/tf_core/tf_core.h +++ b/drivers/net/bnxt/tf_core/tf_core.h @@ -1611,6 +1611,83 @@ int tf_delete_em_entry(struct tf *tfp, int tf_search_em_entry(struct tf *tfp, struct tf_search_em_entry_parms *parms); +/** + * @page global Global Configuration + * + * @ref tf_set_global_cfg + * + * @ref tf_get_global_cfg + */ +/** + * Tunnel Encapsulation Offsets + */ +enum tf_tunnel_encap_offsets { + TF_TUNNEL_ENCAP_L2, + TF_TUNNEL_ENCAP_NAT, + TF_TUNNEL_ENCAP_MPLS, + TF_TUNNEL_ENCAP_VXLAN, + TF_TUNNEL_ENCAP_GENEVE, + TF_TUNNEL_ENCAP_NVGRE, + TF_TUNNEL_ENCAP_GRE, + TF_TUNNEL_ENCAP_FULL_GENERIC +}; +/** + * Global Configuration Table Types + */ +enum tf_global_config_type { + TF_TUNNEL_ENCAP, /**< Tunnel Encap Config(TECT) */ + TF_ACTION_BLOCK, /**< Action Block Config(ABCR) */ + TF_GLOBAL_CFG_TYPE_MAX +}; + +/** + * tf_global_cfg parameter definition + */ +struct tf_global_cfg_parms { + /** + * [in] receive or transmit direction + */ + enum tf_dir dir; + /** + * [in] Global config type + */ + enum tf_global_config_type type; + /** + * [in] Offset @ the type + */ + uint32_t offset; + /** + * [in/out] Value of the configuration + * set - Read, Modify and Write + * get - Read the full configuration + */ + uint8_t *config; + /** + * [in] struct containing size + */ + uint16_t config_sz_in_bytes; +}; + +/** + * Get global configuration + * + * Retrieve the configuration + * + * Returns success or failure code. + */ +int tf_get_global_cfg(struct tf *tfp, + struct tf_global_cfg_parms *parms); + +/** + * Update the global configuration table + * + * Read, modify write the value. + * + * Returns success or failure code. + */ +int tf_set_global_cfg(struct tf *tfp, + struct tf_global_cfg_parms *parms); + /** * @page if_tbl Interface Table Access * diff --git a/drivers/net/bnxt/tf_core/tf_device.c b/drivers/net/bnxt/tf_core/tf_device.c index a3073c826c..ead9584185 100644 --- a/drivers/net/bnxt/tf_core/tf_device.c +++ b/drivers/net/bnxt/tf_core/tf_device.c @@ -45,6 +45,7 @@ tf_dev_bind_p4(struct tf *tfp, struct tf_tcam_cfg_parms tcam_cfg; struct tf_em_cfg_parms em_cfg; struct tf_if_tbl_cfg_parms if_tbl_cfg; + struct tf_global_cfg_cfg_parms global_cfg; dev_handle->type = TF_DEVICE_TYPE_WH; /* Initial function initialization */ @@ -128,6 +129,18 @@ tf_dev_bind_p4(struct tf *tfp, goto fail; } + /* + * GLOBAL_CFG + */ + global_cfg.num_elements = TF_GLOBAL_CFG_TYPE_MAX; + global_cfg.cfg = tf_global_cfg_p4; + rc = tf_global_cfg_bind(tfp, &global_cfg); + if (rc) { + TFP_DRV_LOG(ERR, + "Global Cfg initialization failure\n"); + goto fail; + } + /* Final function initialization */ dev_handle->ops = &tf_dev_ops_p4; @@ -207,6 +220,13 @@ tf_dev_unbind_p4(struct tf *tfp) fail = true; } + rc = tf_global_cfg_unbind(tfp); + if (rc) { + TFP_DRV_LOG(ERR, + "Device unbind failed, Global Cfg Type\n"); + fail = true; + } + if (fail) return -1; diff --git a/drivers/net/bnxt/tf_core/tf_device.h b/drivers/net/bnxt/tf_core/tf_device.h index 2b20f8b20a..0bc7090568 100644 --- a/drivers/net/bnxt/tf_core/tf_device.h +++ b/drivers/net/bnxt/tf_core/tf_device.h @@ -11,6 +11,7 @@ #include "tf_tbl.h" #include "tf_tcam.h" #include "tf_if_tbl.h" +#include "tf_global_cfg.h" struct tf; struct tf_session; @@ -606,6 +607,38 @@ struct tf_dev_ops { */ int (*tf_dev_get_if_tbl)(struct tf *tfp, struct tf_if_tbl_get_parms *parms); + + /** + * Update global cfg + * + * [in] tfp + * Pointer to TF handle + * + * [in] parms + * Pointer to global cfg parameters + * + * returns: + * 0 - Success + * -EINVAL - Error + */ + int (*tf_dev_set_global_cfg)(struct tf *tfp, + struct tf_dev_global_cfg_parms *parms); + + /** + * Get global cfg + * + * [in] tfp + * Pointer to TF handle + * + * [in] parms + * Pointer to global cfg parameters + * + * returns: + * 0 - Success + * -EINVAL - Error + */ + int (*tf_dev_get_global_cfg)(struct tf *tfp, + struct tf_dev_global_cfg_parms *parms); }; /** diff --git a/drivers/net/bnxt/tf_core/tf_device_p4.c b/drivers/net/bnxt/tf_core/tf_device_p4.c index 2dc34b853d..6526082641 100644 --- a/drivers/net/bnxt/tf_core/tf_device_p4.c +++ b/drivers/net/bnxt/tf_core/tf_device_p4.c @@ -108,6 +108,8 @@ const struct tf_dev_ops tf_dev_ops_p4_init = { .tf_dev_free_tbl_scope = NULL, .tf_dev_set_if_tbl = NULL, .tf_dev_get_if_tbl = NULL, + .tf_dev_set_global_cfg = NULL, + .tf_dev_get_global_cfg = NULL, }; /** @@ -140,4 +142,6 @@ const struct tf_dev_ops tf_dev_ops_p4 = { .tf_dev_free_tbl_scope = tf_em_ext_common_free, .tf_dev_set_if_tbl = tf_if_tbl_set, .tf_dev_get_if_tbl = tf_if_tbl_get, + .tf_dev_set_global_cfg = tf_global_cfg_set, + .tf_dev_get_global_cfg = tf_global_cfg_get, }; diff --git a/drivers/net/bnxt/tf_core/tf_device_p4.h b/drivers/net/bnxt/tf_core/tf_device_p4.h index 3b03a7c4e6..7fabb4ba8d 100644 --- a/drivers/net/bnxt/tf_core/tf_device_p4.h +++ b/drivers/net/bnxt/tf_core/tf_device_p4.h @@ -11,6 +11,7 @@ #include "tf_core.h" #include "tf_rm.h" #include "tf_if_tbl.h" +#include "tf_global_cfg.h" struct tf_rm_element_cfg tf_ident_p4[TF_IDENT_TYPE_MAX] = { { TF_RM_ELEM_CFG_HCAPI_BA, CFA_RESOURCE_TYPE_P4_L2_CTXT_REMAP }, @@ -96,4 +97,8 @@ struct tf_if_tbl_cfg tf_if_tbl_p4[TF_IF_TBL_TYPE_MAX] = { { TF_IF_TBL_CFG_NULL, CFA_IF_TBL_TYPE_INVALID } }; +struct tf_global_cfg_cfg tf_global_cfg_p4[TF_GLOBAL_CFG_TYPE_MAX] = { + { TF_GLOBAL_CFG_CFG_HCAPI, TF_TUNNEL_ENCAP }, + { TF_GLOBAL_CFG_CFG_HCAPI, TF_ACTION_BLOCK }, +}; #endif /* _TF_DEVICE_P4_H_ */ diff --git a/drivers/net/bnxt/tf_core/tf_global_cfg.c b/drivers/net/bnxt/tf_core/tf_global_cfg.c new file mode 100644 index 0000000000..4ed4039db4 --- /dev/null +++ b/drivers/net/bnxt/tf_core/tf_global_cfg.c @@ -0,0 +1,199 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2019-2020 Broadcom + * All rights reserved. + */ + +#include + +#include "tf_global_cfg.h" +#include "tf_common.h" +#include "tf_util.h" +#include "tf_msg.h" +#include "tfp.h" + +struct tf; +/** + * Global Cfg DBs. + */ +static void *global_cfg_db[TF_DIR_MAX]; + +/** + * Init flag, set on bind and cleared on unbind + */ +static uint8_t init; + +/** + * Get HCAPI type parameters for a single element + */ +struct tf_global_cfg_get_hcapi_parms { + /** + * [in] Global Cfg DB Handle + */ + void *global_cfg_db; + /** + * [in] DB Index, indicates which DB entry to perform the + * action on. + */ + uint16_t db_index; + /** + * [out] Pointer to the hcapi type for the specified db_index + */ + uint16_t *hcapi_type; +}; + +/** + * Check global_cfg_type and return hwrm type. + * + * [in] global_cfg_type + * Global Cfg type + * + * [out] hwrm_type + * HWRM device data type + * + * Returns: + * 0 - Success + * -EOPNOTSUPP - Type not supported + */ +static int +tf_global_cfg_get_hcapi_type(struct tf_global_cfg_get_hcapi_parms *parms) +{ + struct tf_global_cfg_cfg *global_cfg; + enum tf_global_cfg_cfg_type cfg_type; + + global_cfg = (struct tf_global_cfg_cfg *)parms->global_cfg_db; + cfg_type = global_cfg[parms->db_index].cfg_type; + + if (cfg_type != TF_GLOBAL_CFG_CFG_HCAPI) + return -ENOTSUP; + + *parms->hcapi_type = global_cfg[parms->db_index].hcapi_type; + + return 0; +} + +int +tf_global_cfg_bind(struct tf *tfp __rte_unused, + struct tf_global_cfg_cfg_parms *parms) +{ + TF_CHECK_PARMS2(tfp, parms); + + if (init) { + TFP_DRV_LOG(ERR, + "Global Cfg DB already initialized\n"); + return -EINVAL; + } + + global_cfg_db[TF_DIR_RX] = parms->cfg; + global_cfg_db[TF_DIR_TX] = parms->cfg; + + init = 1; + + TFP_DRV_LOG(INFO, + "Global Cfg - initialized\n"); + + return 0; +} + +int +tf_global_cfg_unbind(struct tf *tfp __rte_unused) +{ + /* Bail if nothing has been initialized */ + if (!init) { + TFP_DRV_LOG(INFO, + "No Global Cfg DBs created\n"); + return 0; + } + + global_cfg_db[TF_DIR_RX] = NULL; + global_cfg_db[TF_DIR_TX] = NULL; + init = 0; + + return 0; +} + +int +tf_global_cfg_set(struct tf *tfp, + struct tf_dev_global_cfg_parms *parms) +{ + int rc; + struct tf_global_cfg_get_hcapi_parms hparms; + uint16_t hcapi_type; + + TF_CHECK_PARMS3(tfp, parms, parms->config); + + if (!init) { + TFP_DRV_LOG(ERR, + "%s: No Global Cfg DBs created\n", + tf_dir_2_str(parms->dir)); + return -EINVAL; + } + + /* Convert TF type to HCAPI type */ + hparms.global_cfg_db = global_cfg_db[parms->dir]; + hparms.db_index = parms->type; + hparms.hcapi_type = &hcapi_type; + rc = tf_global_cfg_get_hcapi_type(&hparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s, Failed type lookup, type:%d, rc:%s\n", + tf_dir_2_str(parms->dir), + parms->type, + strerror(-rc)); + return rc; + } + + rc = tf_msg_set_global_cfg(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 0; +} + +int +tf_global_cfg_get(struct tf *tfp, + struct tf_dev_global_cfg_parms *parms) + +{ + int rc; + struct tf_global_cfg_get_hcapi_parms hparms; + uint16_t hcapi_type; + + TF_CHECK_PARMS3(tfp, parms, parms->config); + + if (!init) { + TFP_DRV_LOG(ERR, + "%s: No Global Cfg DBs created\n", + tf_dir_2_str(parms->dir)); + return -EINVAL; + } + + hparms.global_cfg_db = global_cfg_db[parms->dir]; + hparms.db_index = parms->type; + hparms.hcapi_type = &hcapi_type; + rc = tf_global_cfg_get_hcapi_type(&hparms); + if (rc) { + TFP_DRV_LOG(ERR, + "%s, Failed type lookup, type:%d, rc:%s\n", + tf_dir_2_str(parms->dir), + parms->type, + strerror(-rc)); + return rc; + } + + /* Get the entry */ + rc = tf_msg_get_global_cfg(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 0; +} diff --git a/drivers/net/bnxt/tf_core/tf_global_cfg.h b/drivers/net/bnxt/tf_core/tf_global_cfg.h new file mode 100644 index 0000000000..5c73bb115b --- /dev/null +++ b/drivers/net/bnxt/tf_core/tf_global_cfg.h @@ -0,0 +1,170 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2019-2020 Broadcom + * All rights reserved. + */ + +#ifndef TF_GLOBAL_CFG_H_ +#define TF_GLOBAL_CFG_H_ + +#include "tf_core.h" +#include "stack.h" + +/** + * The global cfg module provides processing of global cfg types. + */ + +struct tf; + +/** + * Global cfg configuration enumeration. + */ +enum tf_global_cfg_cfg_type { + /** + * No configuration + */ + TF_GLOBAL_CFG_CFG_NULL, + /** + * HCAPI 'controlled' + */ + TF_GLOBAL_CFG_CFG_HCAPI, +}; + +/** + * Global cfg configuration structure, used by the Device to configure + * how an individual global cfg type is configured in regard to the HCAPI type. + */ +struct tf_global_cfg_cfg { + /** + * Global cfg config controls how the DB for that element is + * processed. + */ + enum tf_global_cfg_cfg_type cfg_type; + + /** + * HCAPI Type for the element. Used for TF to HCAPI type + * conversion. + */ + uint16_t hcapi_type; +}; + +/** + * Global Cfg configuration parameters + */ +struct tf_global_cfg_cfg_parms { + /** + * Number of table types in the configuration array + */ + uint16_t num_elements; + /** + * Table Type element configuration array + */ + struct tf_global_cfg_cfg *cfg; +}; + +/** + * global cfg parameters + */ +struct tf_dev_global_cfg_parms { + /** + * [in] Receive or transmit direction + */ + enum tf_dir dir; + /** + * [in] Global config type + */ + enum tf_global_config_type type; + /** + * [in] Offset @ the type + */ + uint32_t offset; + /** + * [in/out] Value of the configuration + * set - Read, Modify and Write + * get - Read the full configuration + */ + uint8_t *config; + /** + * [in] struct containing size + */ + uint16_t config_sz_in_bytes; +}; + +/** + * @page global cfg + * + * @ref tf_global_cfg_bind + * + * @ref tf_global_cfg_unbind + * + * @ref tf_global_cfg_set + * + * @ref tf_global_cfg_get + * + */ +/** + * Initializes the Global Cfg module with the requested DBs. Must be + * invoked as the first thing before any of the access functions. + * + * [in] tfp + * Pointer to TF handle + * + * [in] parms + * Pointer to Global Cfg configuration parameters + * + * Returns + * - (0) if successful. + * - (-EINVAL) on failure. + */ +int +tf_global_cfg_bind(struct tf *tfp, + struct tf_global_cfg_cfg_parms *parms); + +/** + * Cleans up the private DBs and releases all the data. + * + * [in] tfp + * Pointer to TF handle + * + * [in] parms + * Pointer to Global Cfg configuration parameters + * + * Returns + * - (0) if successful. + * - (-EINVAL) on failure. + */ +int +tf_global_cfg_unbind(struct tf *tfp); + +/** + * Updates the global configuration table + * + * [in] tfp + * Pointer to TF handle, used for HCAPI communication + * + * [in] parms + * Pointer to global cfg parameters + * + * Returns + * - (0) if successful. + * - (-EINVAL) on failure. + */ +int tf_global_cfg_set(struct tf *tfp, + struct tf_dev_global_cfg_parms *parms); + +/** + * Get global configuration + * + * [in] tfp + * Pointer to TF handle, used for HCAPI communication + * + * [in] parms + * Pointer to global cfg parameters + * + * Returns + * - (0) if successful. + * - (-EINVAL) on failure. + */ +int tf_global_cfg_get(struct tf *tfp, + struct tf_dev_global_cfg_parms *parms); + +#endif /* TF_GLOBAL_CFG_H */ diff --git a/drivers/net/bnxt/tf_core/tf_msg.c b/drivers/net/bnxt/tf_core/tf_msg.c index 8c2dff8ad6..035c0948d1 100644 --- a/drivers/net/bnxt/tf_core/tf_msg.c +++ b/drivers/net/bnxt/tf_core/tf_msg.c @@ -991,6 +991,111 @@ tf_msg_get_tbl_entry(struct tf *tfp, /* HWRM Tunneled messages */ +int +tf_msg_get_global_cfg(struct tf *tfp, + struct tf_dev_global_cfg_parms *params) +{ + int rc = 0; + struct tfp_send_msg_parms parms = { 0 }; + tf_get_global_cfg_input_t req = { 0 }; + tf_get_global_cfg_output_t resp = { 0 }; + uint32_t flags = 0; + uint8_t fw_session_id; + uint16_t resp_size = 0; + + rc = tf_session_get_fw_session_id(tfp, &fw_session_id); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Unable to lookup FW id, rc:%s\n", + tf_dir_2_str(params->dir), + strerror(-rc)); + return rc; + } + + flags = (params->dir == TF_DIR_TX ? + TF_GET_GLOBAL_CFG_INPUT_FLAGS_DIR_TX : + TF_GET_GLOBAL_CFG_INPUT_FLAGS_DIR_RX); + + /* Populate the request */ + req.fw_session_id = tfp_cpu_to_le_32(fw_session_id); + req.flags = tfp_cpu_to_le_32(flags); + req.type = tfp_cpu_to_le_32(params->type); + req.offset = tfp_cpu_to_le_32(params->offset); + req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes); + + MSG_PREP(parms, + TF_KONG_MB, + HWRM_TF, + HWRM_TFT_GET_GLOBAL_CFG, + req, + resp); + + rc = tfp_send_msg_tunneled(tfp, &parms); + + if (rc != 0) + return rc; + + /* Verify that we got enough buffer to return the requested data */ + resp_size = tfp_le_to_cpu_16(resp.size); + if (resp_size < params->config_sz_in_bytes) + return -EINVAL; + + if (params->config) + tfp_memcpy(params->config, + resp.data, + resp_size); + else + return -EFAULT; + + return tfp_le_to_cpu_32(parms.tf_resp_code); +} + +int +tf_msg_set_global_cfg(struct tf *tfp, + struct tf_dev_global_cfg_parms *params) +{ + int rc = 0; + struct tfp_send_msg_parms parms = { 0 }; + tf_set_global_cfg_input_t req = { 0 }; + uint32_t flags = 0; + uint8_t fw_session_id; + + rc = tf_session_get_fw_session_id(tfp, &fw_session_id); + if (rc) { + TFP_DRV_LOG(ERR, + "%s: Unable to lookup FW id, rc:%s\n", + tf_dir_2_str(params->dir), + strerror(-rc)); + return rc; + } + + flags = (params->dir == TF_DIR_TX ? + TF_SET_GLOBAL_CFG_INPUT_FLAGS_DIR_TX : + TF_SET_GLOBAL_CFG_INPUT_FLAGS_DIR_RX); + + /* Populate the request */ + req.fw_session_id = tfp_cpu_to_le_32(fw_session_id); + req.flags = tfp_cpu_to_le_32(flags); + req.type = tfp_cpu_to_le_32(params->type); + req.offset = tfp_cpu_to_le_32(params->offset); + tfp_memcpy(req.data, params->config, + params->config_sz_in_bytes); + req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes); + + MSG_PREP_NO_RESP(parms, + TF_KONG_MB, + HWRM_TF, + HWRM_TFT_SET_GLOBAL_CFG, + req); + + rc = tfp_send_msg_tunneled(tfp, &parms); + + if (rc != 0) + return rc; + + return tfp_le_to_cpu_32(parms.tf_resp_code); +} + int tf_msg_bulk_get_tbl_entry(struct tf *tfp, enum tf_dir dir, @@ -1066,8 +1171,8 @@ tf_msg_get_if_tbl_entry(struct tf *tfp, return rc; } - flags = (params->dir == TF_DIR_TX ? TF_IF_TBL_SET_INPUT_FLAGS_DIR_TX : - TF_IF_TBL_SET_INPUT_FLAGS_DIR_RX); + flags = (params->dir == TF_DIR_TX ? TF_IF_TBL_GET_INPUT_FLAGS_DIR_TX : + TF_IF_TBL_GET_INPUT_FLAGS_DIR_RX); /* Populate the request */ req.fw_session_id = diff --git a/drivers/net/bnxt/tf_core/tf_msg.h b/drivers/net/bnxt/tf_core/tf_msg.h index c02a5203cb..195710eb80 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_tcam.h" +#include "tf_global_cfg.h" struct tf; @@ -448,6 +449,36 @@ int tf_msg_get_tbl_entry(struct tf *tfp, /* HWRM Tunneled messages */ +/** + * Sends global cfg read request to Firmware + * + * [in] tfp + * Pointer to TF handle + * + * [in] params + * Pointer to read parameters + * + * Returns: + * 0 on Success else internal Truflow error + */ +int tf_msg_get_global_cfg(struct tf *tfp, + struct tf_dev_global_cfg_parms *params); + +/** + * Sends global cfg update request to Firmware + * + * [in] tfp + * Pointer to TF handle + * + * [in] params + * Pointer to write parameters + * + * Returns: + * 0 on Success else internal Truflow error + */ +int tf_msg_set_global_cfg(struct tf *tfp, + struct tf_dev_global_cfg_parms *params); + /** * Sends bulk get message of a Table Type element to the firmware. * -- 2.20.1