1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
15 #include "hcapi_cfa_defs.h"
18 #define SUPPORT_CFA_HW_P45 1
19 #undef SUPPORT_CFA_HW_P4
20 #define SUPPORT_CFA_HW_P4 0
21 #elif CHIP_CFG == CMB_A
22 #define SUPPORT_CFA_HW_P4 1
24 #error "Chip not supported"
27 #if SUPPORT_CFA_HW_P4 && SUPPORT_CFA_HW_P58 && SUPPORT_CFA_HW_P59
28 #define SUPPORT_CFA_HW_ALL 1
32 * Index used for the sram_entries field
34 enum hcapi_cfa_resc_type_sram {
35 HCAPI_CFA_RESC_TYPE_SRAM_FULL_ACTION,
36 HCAPI_CFA_RESC_TYPE_SRAM_MCG,
37 HCAPI_CFA_RESC_TYPE_SRAM_ENCAP_8B,
38 HCAPI_CFA_RESC_TYPE_SRAM_ENCAP_16B,
39 HCAPI_CFA_RESC_TYPE_SRAM_ENCAP_64B,
40 HCAPI_CFA_RESC_TYPE_SRAM_SP_SMAC,
41 HCAPI_CFA_RESC_TYPE_SRAM_SP_SMAC_IPV4,
42 HCAPI_CFA_RESC_TYPE_SRAM_SP_SMAC_IPV6,
43 HCAPI_CFA_RESC_TYPE_SRAM_COUNTER_64B,
44 HCAPI_CFA_RESC_TYPE_SRAM_NAT_SPORT,
45 HCAPI_CFA_RESC_TYPE_SRAM_NAT_DPORT,
46 HCAPI_CFA_RESC_TYPE_SRAM_NAT_S_IPV4,
47 HCAPI_CFA_RESC_TYPE_SRAM_NAT_D_IPV4,
48 HCAPI_CFA_RESC_TYPE_SRAM_MAX
52 * Index used for the hw_entries field in struct cfa_rm_db
54 enum hcapi_cfa_resc_type_hw {
55 /* common HW resources for all chip variants */
56 HCAPI_CFA_RESC_TYPE_HW_L2_CTXT_TCAM,
57 HCAPI_CFA_RESC_TYPE_HW_PROF_FUNC,
58 HCAPI_CFA_RESC_TYPE_HW_PROF_TCAM,
59 HCAPI_CFA_RESC_TYPE_HW_EM_PROF_ID,
60 HCAPI_CFA_RESC_TYPE_HW_EM_REC,
61 HCAPI_CFA_RESC_TYPE_HW_WC_TCAM_PROF_ID,
62 HCAPI_CFA_RESC_TYPE_HW_WC_TCAM,
63 HCAPI_CFA_RESC_TYPE_HW_METER_PROF,
64 HCAPI_CFA_RESC_TYPE_HW_METER_INST,
65 HCAPI_CFA_RESC_TYPE_HW_MIRROR,
66 HCAPI_CFA_RESC_TYPE_HW_UPAR,
67 /* Wh+/SR specific HW resources */
68 HCAPI_CFA_RESC_TYPE_HW_SP_TCAM,
69 /* Thor, SR2 common HW resources */
70 HCAPI_CFA_RESC_TYPE_HW_FKB,
71 /* SR specific HW resources */
72 HCAPI_CFA_RESC_TYPE_HW_TBL_SCOPE,
73 HCAPI_CFA_RESC_TYPE_HW_L2_FUNC,
74 HCAPI_CFA_RESC_TYPE_HW_EPOCH0,
75 HCAPI_CFA_RESC_TYPE_HW_EPOCH1,
76 HCAPI_CFA_RESC_TYPE_HW_METADATA,
77 HCAPI_CFA_RESC_TYPE_HW_CT_STATE,
78 HCAPI_CFA_RESC_TYPE_HW_RANGE_PROF,
79 HCAPI_CFA_RESC_TYPE_HW_RANGE_ENTRY,
80 HCAPI_CFA_RESC_TYPE_HW_LAG_ENTRY,
81 HCAPI_CFA_RESC_TYPE_HW_MAX
84 struct hcapi_cfa_key_result {
85 uint64_t bucket_mem_ptr;
89 /* common CFA register access macros */
90 #define CFA_REG(x) OFFSETOF(cfa_reg_t, cfa_##x)
93 #define TF_REG_WR(_p, x, y) (*((uint32_t volatile *)(x)) = (y))
96 #define TF_REG_RD(_p, x) (*((uint32_t volatile *)(x)))
99 #define TF_CFA_REG_RD(_p, x) \
100 TF_REG_RD(0, (uint32_t)(_p)->base_addr + CFA_REG(x))
102 #ifndef TF_CFA_REG_WR
103 #define TF_CFA_REG_WR(_p, x, y) \
104 TF_REG_WR(0, (uint32_t)(_p)->base_addr + CFA_REG(x), y)
107 /* Constants used by Resource Manager Registration*/
108 #define RM_CLIENT_NAME_MAX_LEN 32
111 * Resource Manager Data Structures used for resource requests
113 struct hcapi_cfa_resc_req_entry {
118 struct hcapi_cfa_resc_req {
119 /* Wh+/SR specific onchip Action SRAM resources */
120 /* Validity of each sram type is indicated by the
121 * corresponding sram type bit in the sram_resc_flags. When
122 * set to 1, the CFA sram resource type is valid and amount of
123 * resources for this type is reserved. Each sram resource
124 * pool is identified by the starting index and number of
125 * resources in the pool.
127 uint32_t sram_resc_flags;
128 struct hcapi_cfa_resc_req_entry sram_resc[HCAPI_CFA_RESC_TYPE_SRAM_MAX];
130 /* Validity of each resource type is indicated by the
131 * corresponding resource type bit in the hw_resc_flags. When
132 * set to 1, the CFA resource type is valid and amount of
133 * resource of this type is reserved. Each resource pool is
134 * identified by the starting index and the number of
135 * resources in the pool.
137 uint32_t hw_resc_flags;
138 struct hcapi_cfa_resc_req_entry hw_resc[HCAPI_CFA_RESC_TYPE_HW_MAX];
141 struct hcapi_cfa_resc_req_db {
142 struct hcapi_cfa_resc_req rx;
143 struct hcapi_cfa_resc_req tx;
146 struct hcapi_cfa_resc_entry {
152 struct hcapi_cfa_resc {
153 /* Wh+/SR specific onchip Action SRAM resources */
154 /* Validity of each sram type is indicated by the
155 * corresponding sram type bit in the sram_resc_flags. When
156 * set to 1, the CFA sram resource type is valid and amount of
157 * resources for this type is reserved. Each sram resource
158 * pool is identified by the starting index and number of
159 * resources in the pool.
161 uint32_t sram_resc_flags;
162 struct hcapi_cfa_resc_entry sram_resc[HCAPI_CFA_RESC_TYPE_SRAM_MAX];
164 /* Validity of each resource type is indicated by the
165 * corresponding resource type bit in the hw_resc_flags. When
166 * set to 1, the CFA resource type is valid and amount of
167 * resource of this type is reserved. Each resource pool is
168 * identified by the starting index and the number of resources
171 uint32_t hw_resc_flags;
172 struct hcapi_cfa_resc_entry hw_resc[HCAPI_CFA_RESC_TYPE_HW_MAX];
175 struct hcapi_cfa_resc_db {
176 struct hcapi_cfa_resc rx;
177 struct hcapi_cfa_resc tx;
181 * This is the main data structure used by the CFA Resource
182 * Manager. This data structure holds all the state and table
183 * management information.
185 typedef struct hcapi_cfa_rm_data {
187 } hcapi_cfa_rm_data_t;
191 struct hcapi_cfa_devops;
193 struct hcapi_cfa_devinfo {
194 uint8_t global_cfg_data[CFA_GLOBAL_CFG_DATA_SZ];
195 struct hcapi_cfa_layout_tbl layouts;
196 struct hcapi_cfa_devops *devops;
199 int hcapi_cfa_dev_bind(enum hcapi_cfa_ver hw_ver,
200 struct hcapi_cfa_devinfo *dev_info);
202 int hcapi_cfa_key_compile_layout(struct hcapi_cfa_key_template *key_template,
203 struct hcapi_cfa_key_layout *key_layout);
204 uint64_t hcapi_cfa_key_hash(uint64_t *key_data, uint16_t bitlen);
206 hcapi_cfa_action_compile_layout(struct hcapi_cfa_action_template *act_template,
207 struct hcapi_cfa_action_layout *act_layout);
208 int hcapi_cfa_action_init_obj(uint64_t *act_obj,
209 struct hcapi_cfa_action_layout *act_layout);
210 int hcapi_cfa_action_compute_ptr(uint64_t *act_obj,
211 struct hcapi_cfa_action_layout *act_layout,
214 int hcapi_cfa_action_hw_op(struct hcapi_cfa_hwop *op,
216 struct hcapi_cfa_data *act_obj);
217 int hcapi_cfa_dev_hw_op(struct hcapi_cfa_hwop *op, uint16_t tbl_id,
218 struct hcapi_cfa_data *obj_data);
219 int hcapi_cfa_rm_register_client(hcapi_cfa_rm_data_t *data,
220 const char *client_name,
222 int hcapi_cfa_rm_unregister_client(hcapi_cfa_rm_data_t *data,
224 int hcapi_cfa_rm_query_resources(hcapi_cfa_rm_data_t *data,
227 struct hcapi_cfa_resc_req_db *req_db);
228 int hcapi_cfa_rm_query_resources_one(hcapi_cfa_rm_data_t *data,
230 struct hcapi_cfa_resc_db *resc_db);
231 int hcapi_cfa_rm_reserve_resources(hcapi_cfa_rm_data_t *data,
233 struct hcapi_cfa_resc_req_db *resc_req,
234 struct hcapi_cfa_resc_db *resc_db);
235 int hcapi_cfa_rm_release_resources(hcapi_cfa_rm_data_t *data,
237 struct hcapi_cfa_resc_req_db *resc_req,
238 struct hcapi_cfa_resc_db *resc_db);
239 int hcapi_cfa_rm_initialize(hcapi_cfa_rm_data_t *data);
241 #if SUPPORT_CFA_HW_P4
243 int hcapi_cfa_p4_dev_hw_op(struct hcapi_cfa_hwop *op, uint16_t tbl_id,
244 struct hcapi_cfa_data *obj_data);
245 int hcapi_cfa_p4_prof_l2ctxt_hwop(struct hcapi_cfa_hwop *op,
246 struct hcapi_cfa_data *obj_data);
247 int hcapi_cfa_p4_prof_l2ctxtrmp_hwop(struct hcapi_cfa_hwop *op,
248 struct hcapi_cfa_data *obj_data);
249 int hcapi_cfa_p4_prof_tcam_hwop(struct hcapi_cfa_hwop *op,
250 struct hcapi_cfa_data *obj_data);
251 int hcapi_cfa_p4_prof_tcamrmp_hwop(struct hcapi_cfa_hwop *op,
252 struct hcapi_cfa_data *obj_data);
253 int hcapi_cfa_p4_wc_tcam_hwop(struct hcapi_cfa_hwop *op,
254 struct hcapi_cfa_data *obj_data);
255 int hcapi_cfa_p4_wc_tcam_rec_hwop(struct hcapi_cfa_hwop *op,
256 struct hcapi_cfa_data *obj_data);
257 int hcapi_cfa_p4_mirror_hwop(struct hcapi_cfa_hwop *op,
258 struct hcapi_cfa_data *mirror);
259 int hcapi_cfa_p4_global_cfg_hwop(struct hcapi_cfa_hwop *op,
261 struct hcapi_cfa_data *config);
262 /* SUPPORT_CFA_HW_P4 */
263 #elif SUPPORT_CFA_HW_P45
264 int hcapi_cfa_p45_mirror_hwop(struct hcapi_cfa_hwop *op,
265 struct hcapi_cfa_data *mirror);
266 int hcapi_cfa_p45_global_cfg_hwop(struct hcapi_cfa_hwop *op,
268 struct hcapi_cfa_data *config);
269 /* SUPPORT_CFA_HW_P45 */
272 * HCAPI CFA device HW operation function callback definition
273 * This is standardized function callback hook to install different
274 * CFA HW table programming function callback.
277 struct hcapi_cfa_tbl_cb {
279 * This function callback provides the functionality to read/write
280 * HW table entry from a HW table.
283 * A pointer to the Hardware operation parameter
285 * @param[in] obj_data
286 * A pointer to the HW data object for the hardware operation
289 * 0 for SUCCESS, negative value for FAILURE
291 int (*hwop_cb)(struct hcapi_cfa_hwop *op,
292 struct hcapi_cfa_data *obj_data);
295 #endif /* HCAPI_CFA_H_ */