1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
6 #include <rte_common.h>
8 #include "tf_global_cfg.h"
19 struct tf_global_cfg_db {
20 struct tf_global_cfg_cfg *global_cfg_db[TF_DIR_MAX];
24 * Get HCAPI type parameters for a single element
26 struct tf_global_cfg_get_hcapi_parms {
28 * [in] Global Cfg DB Handle
32 * [in] DB Index, indicates which DB entry to perform the
37 * [out] Pointer to the hcapi type for the specified db_index
43 * Check global_cfg_type and return hwrm type.
45 * [in] global_cfg_type
49 * HWRM device data type
53 * -EOPNOTSUPP - Type not supported
56 tf_global_cfg_get_hcapi_type(struct tf_global_cfg_get_hcapi_parms *parms)
58 struct tf_global_cfg_cfg *global_cfg;
59 enum tf_global_cfg_cfg_type cfg_type;
61 global_cfg = (struct tf_global_cfg_cfg *)parms->global_cfg_db;
62 cfg_type = global_cfg[parms->db_index].cfg_type;
64 if (cfg_type != TF_GLOBAL_CFG_CFG_HCAPI)
67 *parms->hcapi_type = global_cfg[parms->db_index].hcapi_type;
73 tf_global_cfg_bind(struct tf *tfp,
74 struct tf_global_cfg_cfg_parms *parms)
76 struct tfp_calloc_parms cparms;
77 struct tf_global_cfg_db *global_cfg_db;
79 TF_CHECK_PARMS2(tfp, parms);
82 cparms.size = sizeof(struct tf_global_cfg_db);
84 if (tfp_calloc(&cparms) != 0) {
85 TFP_DRV_LOG(ERR, "global_rm_db alloc error %s\n",
90 global_cfg_db = cparms.mem_va;
91 global_cfg_db->global_cfg_db[TF_DIR_RX] = parms->cfg;
92 global_cfg_db->global_cfg_db[TF_DIR_TX] = parms->cfg;
93 tf_session_set_global_db(tfp, (void *)global_cfg_db);
95 TFP_DRV_LOG(INFO, "Global Cfg - initialized\n");
100 tf_global_cfg_unbind(struct tf *tfp)
103 struct tf_global_cfg_db *global_cfg_db_ptr;
105 TF_CHECK_PARMS1(tfp);
107 rc = tf_session_get_global_db(tfp, (void **)&global_cfg_db_ptr);
109 TFP_DRV_LOG(INFO, "global_cfg_db is not initialized\n");
113 tfp_free((void *)global_cfg_db_ptr);
118 tf_global_cfg_set(struct tf *tfp,
119 struct tf_global_cfg_parms *parms)
122 struct tf_global_cfg_get_hcapi_parms hparms;
123 struct tf_global_cfg_db *global_cfg_db_ptr;
126 TF_CHECK_PARMS3(tfp, parms, parms->config);
128 rc = tf_session_get_global_db(tfp, (void **)&global_cfg_db_ptr);
130 TFP_DRV_LOG(INFO, "No global cfg DBs initialized\n");
134 /* Convert TF type to HCAPI type */
135 hparms.global_cfg_db = global_cfg_db_ptr->global_cfg_db[parms->dir];
136 hparms.db_index = parms->type;
137 hparms.hcapi_type = &hcapi_type;
138 rc = tf_global_cfg_get_hcapi_type(&hparms);
141 "%s, Failed type lookup, type:%d, rc:%s\n",
142 tf_dir_2_str(parms->dir),
148 rc = tf_msg_set_global_cfg(tfp, parms);
151 "%s, Set failed, type:%d, rc:%s\n",
152 tf_dir_2_str(parms->dir),
161 tf_global_cfg_get(struct tf *tfp,
162 struct tf_global_cfg_parms *parms)
166 struct tf_global_cfg_get_hcapi_parms hparms;
167 struct tf_global_cfg_db *global_cfg_db_ptr;
170 TF_CHECK_PARMS3(tfp, parms, parms->config);
172 rc = tf_session_get_global_db(tfp, (void **)&global_cfg_db_ptr);
174 TFP_DRV_LOG(INFO, "No Global cfg DBs initialized\n");
178 /* Convert TF type to HCAPI type */
179 hparms.global_cfg_db = global_cfg_db_ptr->global_cfg_db[parms->dir];
180 hparms.db_index = parms->type;
181 hparms.hcapi_type = &hcapi_type;
182 rc = tf_global_cfg_get_hcapi_type(&hparms);
185 "%s, Failed type lookup, type:%d, rc:%s\n",
186 tf_dir_2_str(parms->dir),
193 rc = tf_msg_get_global_cfg(tfp, parms);
196 "%s, Get failed, type:%d, rc:%s\n",
197 tf_dir_2_str(parms->dir),