1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
15 #include "hcapi_cfa_defs.h"
18 * Index used for the sram_entries field
20 enum hcapi_cfa_resc_type_sram {
21 HCAPI_CFA_RESC_TYPE_SRAM_FULL_ACTION,
22 HCAPI_CFA_RESC_TYPE_SRAM_MCG,
23 HCAPI_CFA_RESC_TYPE_SRAM_ENCAP_8B,
24 HCAPI_CFA_RESC_TYPE_SRAM_ENCAP_16B,
25 HCAPI_CFA_RESC_TYPE_SRAM_ENCAP_64B,
26 HCAPI_CFA_RESC_TYPE_SRAM_SP_SMAC,
27 HCAPI_CFA_RESC_TYPE_SRAM_SP_SMAC_IPV4,
28 HCAPI_CFA_RESC_TYPE_SRAM_SP_SMAC_IPV6,
29 HCAPI_CFA_RESC_TYPE_SRAM_COUNTER_64B,
30 HCAPI_CFA_RESC_TYPE_SRAM_NAT_SPORT,
31 HCAPI_CFA_RESC_TYPE_SRAM_NAT_DPORT,
32 HCAPI_CFA_RESC_TYPE_SRAM_NAT_S_IPV4,
33 HCAPI_CFA_RESC_TYPE_SRAM_NAT_D_IPV4,
34 HCAPI_CFA_RESC_TYPE_SRAM_MAX
38 * Index used for the hw_entries field in struct cfa_rm_db
40 enum hcapi_cfa_resc_type_hw {
41 /* common HW resources for all chip variants */
42 HCAPI_CFA_RESC_TYPE_HW_L2_CTXT_TCAM,
43 HCAPI_CFA_RESC_TYPE_HW_PROF_FUNC,
44 HCAPI_CFA_RESC_TYPE_HW_PROF_TCAM,
45 HCAPI_CFA_RESC_TYPE_HW_EM_PROF_ID,
46 HCAPI_CFA_RESC_TYPE_HW_EM_REC,
47 HCAPI_CFA_RESC_TYPE_HW_WC_TCAM_PROF_ID,
48 HCAPI_CFA_RESC_TYPE_HW_WC_TCAM,
49 HCAPI_CFA_RESC_TYPE_HW_METER_PROF,
50 HCAPI_CFA_RESC_TYPE_HW_METER_INST,
51 HCAPI_CFA_RESC_TYPE_HW_MIRROR,
52 HCAPI_CFA_RESC_TYPE_HW_UPAR,
53 /* Wh+/SR specific HW resources */
54 HCAPI_CFA_RESC_TYPE_HW_SP_TCAM,
55 /* Thor, SR2 common HW resources */
56 HCAPI_CFA_RESC_TYPE_HW_FKB,
57 /* SR specific HW resources */
58 HCAPI_CFA_RESC_TYPE_HW_TBL_SCOPE,
59 HCAPI_CFA_RESC_TYPE_HW_L2_FUNC,
60 HCAPI_CFA_RESC_TYPE_HW_EPOCH0,
61 HCAPI_CFA_RESC_TYPE_HW_EPOCH1,
62 HCAPI_CFA_RESC_TYPE_HW_METADATA,
63 HCAPI_CFA_RESC_TYPE_HW_CT_STATE,
64 HCAPI_CFA_RESC_TYPE_HW_RANGE_PROF,
65 HCAPI_CFA_RESC_TYPE_HW_RANGE_ENTRY,
66 HCAPI_CFA_RESC_TYPE_HW_LAG_ENTRY,
67 HCAPI_CFA_RESC_TYPE_HW_MAX
70 struct hcapi_cfa_key_result {
71 uint64_t bucket_mem_ptr;
75 /* common CFA register access macros */
76 #define CFA_REG(x) OFFSETOF(cfa_reg_t, cfa_##x)
79 #define TF_REG_WR(_p, x, y) (*((uint32_t volatile *)(x)) = (y))
82 #define TF_REG_RD(_p, x) (*((uint32_t volatile *)(x)))
85 #define TF_CFA_REG_RD(_p, x) \
86 TF_REG_RD(0, (uint32_t)(_p)->base_addr + CFA_REG(x))
89 #define TF_CFA_REG_WR(_p, x, y) \
90 TF_REG_WR(0, (uint32_t)(_p)->base_addr + CFA_REG(x), y)
93 /* Constants used by Resource Manager Registration*/
94 #define RM_CLIENT_NAME_MAX_LEN 32
97 * Resource Manager Data Structures used for resource requests
99 struct hcapi_cfa_resc_req_entry {
104 struct hcapi_cfa_resc_req {
105 /* Wh+/SR specific onchip Action SRAM resources */
106 /* Validity of each sram type is indicated by the
107 * corresponding sram type bit in the sram_resc_flags. When
108 * set to 1, the CFA sram resource type is valid and amount of
109 * resources for this type is reserved. Each sram resource
110 * pool is identified by the starting index and number of
111 * resources in the pool.
113 uint32_t sram_resc_flags;
114 struct hcapi_cfa_resc_req_entry sram_resc[HCAPI_CFA_RESC_TYPE_SRAM_MAX];
116 /* Validity of each resource type is indicated by the
117 * corresponding resource type bit in the hw_resc_flags. When
118 * set to 1, the CFA resource type is valid and amount of
119 * resource of this type is reserved. Each resource pool is
120 * identified by the starting index and the number of
121 * resources in the pool.
123 uint32_t hw_resc_flags;
124 struct hcapi_cfa_resc_req_entry hw_resc[HCAPI_CFA_RESC_TYPE_HW_MAX];
127 struct hcapi_cfa_resc_req_db {
128 struct hcapi_cfa_resc_req rx;
129 struct hcapi_cfa_resc_req tx;
132 struct hcapi_cfa_resc_entry {
138 struct hcapi_cfa_resc {
139 /* Wh+/SR specific onchip Action SRAM resources */
140 /* Validity of each sram type is indicated by the
141 * corresponding sram type bit in the sram_resc_flags. When
142 * set to 1, the CFA sram resource type is valid and amount of
143 * resources for this type is reserved. Each sram resource
144 * pool is identified by the starting index and number of
145 * resources in the pool.
147 uint32_t sram_resc_flags;
148 struct hcapi_cfa_resc_entry sram_resc[HCAPI_CFA_RESC_TYPE_SRAM_MAX];
150 /* Validity of each resource type is indicated by the
151 * corresponding resource type bit in the hw_resc_flags. When
152 * set to 1, the CFA resource type is valid and amount of
153 * resource of this type is reserved. Each resource pool is
154 * identified by the starting index and the number of resources
157 uint32_t hw_resc_flags;
158 struct hcapi_cfa_resc_entry hw_resc[HCAPI_CFA_RESC_TYPE_HW_MAX];
161 struct hcapi_cfa_resc_db {
162 struct hcapi_cfa_resc rx;
163 struct hcapi_cfa_resc tx;
167 * This is the main data structure used by the CFA Resource
168 * Manager. This data structure holds all the state and table
169 * management information.
171 typedef struct hcapi_cfa_rm_data {
173 } hcapi_cfa_rm_data_t;
177 struct hcapi_cfa_devops;
179 struct hcapi_cfa_devinfo {
180 uint8_t global_cfg_data[CFA_GLOBAL_CFG_DATA_SZ];
181 struct hcapi_cfa_layout_tbl layouts;
182 struct hcapi_cfa_devops *devops;
185 int hcapi_cfa_dev_bind(enum hcapi_cfa_ver hw_ver,
186 struct hcapi_cfa_devinfo *dev_info);
188 int hcapi_cfa_key_compile_layout(struct hcapi_cfa_key_template *key_template,
189 struct hcapi_cfa_key_layout *key_layout);
190 uint64_t hcapi_cfa_key_hash(uint64_t *key_data, uint16_t bitlen);
192 hcapi_cfa_action_compile_layout(struct hcapi_cfa_action_template *act_template,
193 struct hcapi_cfa_action_layout *act_layout);
194 int hcapi_cfa_action_init_obj(uint64_t *act_obj,
195 struct hcapi_cfa_action_layout *act_layout);
196 int hcapi_cfa_action_compute_ptr(uint64_t *act_obj,
197 struct hcapi_cfa_action_layout *act_layout,
200 int hcapi_cfa_action_hw_op(struct hcapi_cfa_hwop *op,
202 struct hcapi_cfa_data *act_obj);
203 int hcapi_cfa_dev_hw_op(struct hcapi_cfa_hwop *op, uint16_t tbl_id,
204 struct hcapi_cfa_data *obj_data);
205 int hcapi_cfa_rm_register_client(hcapi_cfa_rm_data_t *data,
206 const char *client_name,
208 int hcapi_cfa_rm_unregister_client(hcapi_cfa_rm_data_t *data,
210 int hcapi_cfa_rm_query_resources(hcapi_cfa_rm_data_t *data,
213 struct hcapi_cfa_resc_req_db *req_db);
214 int hcapi_cfa_rm_query_resources_one(hcapi_cfa_rm_data_t *data,
216 struct hcapi_cfa_resc_db *resc_db);
217 int hcapi_cfa_rm_reserve_resources(hcapi_cfa_rm_data_t *data,
219 struct hcapi_cfa_resc_req_db *resc_req,
220 struct hcapi_cfa_resc_db *resc_db);
221 int hcapi_cfa_rm_release_resources(hcapi_cfa_rm_data_t *data,
223 struct hcapi_cfa_resc_req_db *resc_req,
224 struct hcapi_cfa_resc_db *resc_db);
225 int hcapi_cfa_rm_initialize(hcapi_cfa_rm_data_t *data);
227 #if SUPPORT_CFA_HW_P4
229 int hcapi_cfa_p4_dev_hw_op(struct hcapi_cfa_hwop *op, uint16_t tbl_id,
230 struct hcapi_cfa_data *obj_data);
231 int hcapi_cfa_p4_prof_l2ctxt_hwop(struct hcapi_cfa_hwop *op,
232 struct hcapi_cfa_data *obj_data);
233 int hcapi_cfa_p4_prof_l2ctxtrmp_hwop(struct hcapi_cfa_hwop *op,
234 struct hcapi_cfa_data *obj_data);
235 int hcapi_cfa_p4_prof_tcam_hwop(struct hcapi_cfa_hwop *op,
236 struct hcapi_cfa_data *obj_data);
237 int hcapi_cfa_p4_prof_tcamrmp_hwop(struct hcapi_cfa_hwop *op,
238 struct hcapi_cfa_data *obj_data);
239 int hcapi_cfa_p4_wc_tcam_hwop(struct hcapi_cfa_hwop *op,
240 struct hcapi_cfa_data *obj_data);
241 int hcapi_cfa_p4_wc_tcam_rec_hwop(struct hcapi_cfa_hwop *op,
242 struct hcapi_cfa_data *obj_data);
243 int hcapi_cfa_p4_mirror_hwop(struct hcapi_cfa_hwop *op,
244 struct hcapi_cfa_data *mirror);
245 int hcapi_cfa_p4_global_cfg_hwop(struct hcapi_cfa_hwop *op,
247 struct hcapi_cfa_data *config);
248 /* SUPPORT_CFA_HW_P4 */
249 #elif SUPPORT_CFA_HW_P45
250 int hcapi_cfa_p45_mirror_hwop(struct hcapi_cfa_hwop *op,
251 struct hcapi_cfa_data *mirror);
252 int hcapi_cfa_p45_global_cfg_hwop(struct hcapi_cfa_hwop *op,
254 struct hcapi_cfa_data *config);
255 /* SUPPORT_CFA_HW_P45 */
258 * HCAPI CFA device HW operation function callback definition
259 * This is standardized function callback hook to install different
260 * CFA HW table programming function callback.
263 struct hcapi_cfa_tbl_cb {
265 * This function callback provides the functionality to read/write
266 * HW table entry from a HW table.
269 * A pointer to the Hardware operation parameter
271 * @param[in] obj_data
272 * A pointer to the HW data object for the hardware operation
275 * 0 for SUCCESS, negative value for FAILURE
277 int (*hwop_cb)(struct hcapi_cfa_hwop *op,
278 struct hcapi_cfa_data *obj_data);
281 #endif /* HCAPI_CFA_H_ */