1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
15 #include "hcapi_cfa_defs.h"
17 #define SUPPORT_CFA_HW_P4 1
19 #if SUPPORT_CFA_HW_P4 && SUPPORT_CFA_HW_P58 && SUPPORT_CFA_HW_P59
20 #define SUPPORT_CFA_HW_ALL 1
24 * Index used for the sram_entries field
26 enum hcapi_cfa_resc_type_sram {
27 HCAPI_CFA_RESC_TYPE_SRAM_FULL_ACTION,
28 HCAPI_CFA_RESC_TYPE_SRAM_MCG,
29 HCAPI_CFA_RESC_TYPE_SRAM_ENCAP_8B,
30 HCAPI_CFA_RESC_TYPE_SRAM_ENCAP_16B,
31 HCAPI_CFA_RESC_TYPE_SRAM_ENCAP_64B,
32 HCAPI_CFA_RESC_TYPE_SRAM_SP_SMAC,
33 HCAPI_CFA_RESC_TYPE_SRAM_SP_SMAC_IPV4,
34 HCAPI_CFA_RESC_TYPE_SRAM_SP_SMAC_IPV6,
35 HCAPI_CFA_RESC_TYPE_SRAM_COUNTER_64B,
36 HCAPI_CFA_RESC_TYPE_SRAM_NAT_SPORT,
37 HCAPI_CFA_RESC_TYPE_SRAM_NAT_DPORT,
38 HCAPI_CFA_RESC_TYPE_SRAM_NAT_S_IPV4,
39 HCAPI_CFA_RESC_TYPE_SRAM_NAT_D_IPV4,
40 HCAPI_CFA_RESC_TYPE_SRAM_MAX
44 * Index used for the hw_entries field in struct cfa_rm_db
46 enum hcapi_cfa_resc_type_hw {
47 /* common HW resources for all chip variants */
48 HCAPI_CFA_RESC_TYPE_HW_L2_CTXT_TCAM,
49 HCAPI_CFA_RESC_TYPE_HW_PROF_FUNC,
50 HCAPI_CFA_RESC_TYPE_HW_PROF_TCAM,
51 HCAPI_CFA_RESC_TYPE_HW_EM_PROF_ID,
52 HCAPI_CFA_RESC_TYPE_HW_EM_REC,
53 HCAPI_CFA_RESC_TYPE_HW_WC_TCAM_PROF_ID,
54 HCAPI_CFA_RESC_TYPE_HW_WC_TCAM,
55 HCAPI_CFA_RESC_TYPE_HW_METER_PROF,
56 HCAPI_CFA_RESC_TYPE_HW_METER_INST,
57 HCAPI_CFA_RESC_TYPE_HW_MIRROR,
58 HCAPI_CFA_RESC_TYPE_HW_UPAR,
59 /* Wh+/SR specific HW resources */
60 HCAPI_CFA_RESC_TYPE_HW_SP_TCAM,
61 /* Thor, SR2 common HW resources */
62 HCAPI_CFA_RESC_TYPE_HW_FKB,
63 /* SR specific HW resources */
64 HCAPI_CFA_RESC_TYPE_HW_TBL_SCOPE,
65 HCAPI_CFA_RESC_TYPE_HW_L2_FUNC,
66 HCAPI_CFA_RESC_TYPE_HW_EPOCH0,
67 HCAPI_CFA_RESC_TYPE_HW_EPOCH1,
68 HCAPI_CFA_RESC_TYPE_HW_METADATA,
69 HCAPI_CFA_RESC_TYPE_HW_CT_STATE,
70 HCAPI_CFA_RESC_TYPE_HW_RANGE_PROF,
71 HCAPI_CFA_RESC_TYPE_HW_RANGE_ENTRY,
72 HCAPI_CFA_RESC_TYPE_HW_LAG_ENTRY,
73 HCAPI_CFA_RESC_TYPE_HW_MAX
76 struct hcapi_cfa_key_result {
77 uint64_t bucket_mem_ptr;
81 /* common CFA register access macros */
82 #define CFA_REG(x) OFFSETOF(cfa_reg_t, cfa_##x)
85 #define REG_WR(_p, x, y) (*((uint32_t volatile *)(x)) = (y))
88 #define REG_RD(_p, x) (*((uint32_t volatile *)(x)))
90 #define CFA_REG_RD(_p, x) \
91 REG_RD(0, (uint32_t)(_p)->base_addr + CFA_REG(x))
92 #define CFA_REG_WR(_p, x, y) \
93 REG_WR(0, (uint32_t)(_p)->base_addr + CFA_REG(x), y)
96 /* Constants used by Resource Manager Registration*/
97 #define RM_CLIENT_NAME_MAX_LEN 32
100 * Resource Manager Data Structures used for resource requests
102 struct hcapi_cfa_resc_req_entry {
107 struct hcapi_cfa_resc_req {
108 /* Wh+/SR specific onchip Action SRAM resources */
109 /* Validity of each sram type is indicated by the
110 * corresponding sram type bit in the sram_resc_flags. When
111 * set to 1, the CFA sram resource type is valid and amount of
112 * resources for this type is reserved. Each sram resource
113 * pool is identified by the starting index and number of
114 * resources in the pool.
116 uint32_t sram_resc_flags;
117 struct hcapi_cfa_resc_req_entry sram_resc[HCAPI_CFA_RESC_TYPE_SRAM_MAX];
119 /* Validity of each resource type is indicated by the
120 * corresponding resource type bit in the hw_resc_flags. When
121 * set to 1, the CFA resource type is valid and amount of
122 * resource of this type is reserved. Each resource pool is
123 * identified by the starting index and the number of
124 * resources in the pool.
126 uint32_t hw_resc_flags;
127 struct hcapi_cfa_resc_req_entry hw_resc[HCAPI_CFA_RESC_TYPE_HW_MAX];
130 struct hcapi_cfa_resc_req_db {
131 struct hcapi_cfa_resc_req rx;
132 struct hcapi_cfa_resc_req tx;
135 struct hcapi_cfa_resc_entry {
141 struct hcapi_cfa_resc {
142 /* Wh+/SR specific onchip Action SRAM resources */
143 /* Validity of each sram type is indicated by the
144 * corresponding sram type bit in the sram_resc_flags. When
145 * set to 1, the CFA sram resource type is valid and amount of
146 * resources for this type is reserved. Each sram resource
147 * pool is identified by the starting index and number of
148 * resources in the pool.
150 uint32_t sram_resc_flags;
151 struct hcapi_cfa_resc_entry sram_resc[HCAPI_CFA_RESC_TYPE_SRAM_MAX];
153 /* Validity of each resource type is indicated by the
154 * corresponding resource type bit in the hw_resc_flags. When
155 * set to 1, the CFA resource type is valid and amount of
156 * resource of this type is reserved. Each resource pool is
157 * identified by the starting index and the number of resources
160 uint32_t hw_resc_flags;
161 struct hcapi_cfa_resc_entry hw_resc[HCAPI_CFA_RESC_TYPE_HW_MAX];
164 struct hcapi_cfa_resc_db {
165 struct hcapi_cfa_resc rx;
166 struct hcapi_cfa_resc tx;
170 * This is the main data structure used by the CFA Resource
171 * Manager. This data structure holds all the state and table
172 * management information.
174 typedef struct hcapi_cfa_rm_data {
176 } hcapi_cfa_rm_data_t;
180 struct hcapi_cfa_devops;
182 struct hcapi_cfa_devinfo {
183 uint8_t global_cfg_data[CFA_GLOBAL_CFG_DATA_SZ];
184 struct hcapi_cfa_layout_tbl layouts;
185 struct hcapi_cfa_devops *devops;
188 int hcapi_cfa_dev_bind(enum hcapi_cfa_ver hw_ver,
189 struct hcapi_cfa_devinfo *dev_info);
191 int hcapi_cfa_key_compile_layout(struct hcapi_cfa_key_template *key_template,
192 struct hcapi_cfa_key_layout *key_layout);
193 uint64_t hcapi_cfa_key_hash(uint64_t *key_data, uint16_t bitlen);
195 hcapi_cfa_action_compile_layout(struct hcapi_cfa_action_template *act_template,
196 struct hcapi_cfa_action_layout *act_layout);
197 int hcapi_cfa_action_init_obj(uint64_t *act_obj,
198 struct hcapi_cfa_action_layout *act_layout);
199 int hcapi_cfa_action_compute_ptr(uint64_t *act_obj,
200 struct hcapi_cfa_action_layout *act_layout,
203 int hcapi_cfa_action_hw_op(struct hcapi_cfa_hwop *op,
205 struct hcapi_cfa_data *act_obj);
206 int hcapi_cfa_dev_hw_op(struct hcapi_cfa_hwop *op, uint16_t tbl_id,
207 struct hcapi_cfa_data *obj_data);
208 int hcapi_cfa_rm_register_client(hcapi_cfa_rm_data_t *data,
209 const char *client_name,
211 int hcapi_cfa_rm_unregister_client(hcapi_cfa_rm_data_t *data,
213 int hcapi_cfa_rm_query_resources(hcapi_cfa_rm_data_t *data,
216 struct hcapi_cfa_resc_req_db *req_db);
217 int hcapi_cfa_rm_query_resources_one(hcapi_cfa_rm_data_t *data,
219 struct hcapi_cfa_resc_db *resc_db);
220 int hcapi_cfa_rm_reserve_resources(hcapi_cfa_rm_data_t *data,
222 struct hcapi_cfa_resc_req_db *resc_req,
223 struct hcapi_cfa_resc_db *resc_db);
224 int hcapi_cfa_rm_release_resources(hcapi_cfa_rm_data_t *data,
226 struct hcapi_cfa_resc_req_db *resc_req,
227 struct hcapi_cfa_resc_db *resc_db);
228 int hcapi_cfa_rm_initialize(hcapi_cfa_rm_data_t *data);
230 #if SUPPORT_CFA_HW_P4
232 int hcapi_cfa_p4_dev_hw_op(struct hcapi_cfa_hwop *op, uint16_t tbl_id,
233 struct hcapi_cfa_data *obj_data);
234 int hcapi_cfa_p4_prof_l2ctxt_hwop(struct hcapi_cfa_hwop *op,
235 struct hcapi_cfa_data *obj_data);
236 int hcapi_cfa_p4_prof_l2ctxtrmp_hwop(struct hcapi_cfa_hwop *op,
237 struct hcapi_cfa_data *obj_data);
238 int hcapi_cfa_p4_prof_tcam_hwop(struct hcapi_cfa_hwop *op,
239 struct hcapi_cfa_data *obj_data);
240 int hcapi_cfa_p4_prof_tcamrmp_hwop(struct hcapi_cfa_hwop *op,
241 struct hcapi_cfa_data *obj_data);
242 int hcapi_cfa_p4_wc_tcam_hwop(struct hcapi_cfa_hwop *op,
243 struct hcapi_cfa_data *obj_data);
244 int hcapi_cfa_p4_wc_tcam_rec_hwop(struct hcapi_cfa_hwop *op,
245 struct hcapi_cfa_data *obj_data);
246 int hcapi_cfa_p4_mirror_hwop(struct hcapi_cfa_hwop *op,
247 struct hcapi_cfa_data *mirror);
248 int hcapi_cfa_p4_global_cfg_hwop(struct hcapi_cfa_hwop *op,
250 struct hcapi_cfa_data *config);
251 #endif /* SUPPORT_CFA_HW_P4 */
253 * HCAPI CFA device HW operation function callback definition
254 * This is standardized function callback hook to install different
255 * CFA HW table programming function callback.
258 struct hcapi_cfa_tbl_cb {
260 * This function callback provides the functionality to read/write
261 * HW table entry from a HW table.
264 * A pointer to the Hardware operation parameter
266 * @param[in] obj_data
267 * A pointer to the HW data object for the hardware operation
270 * 0 for SUCCESS, negative value for FAILURE
272 int (*hwop_cb)(struct hcapi_cfa_hwop *op,
273 struct hcapi_cfa_data *obj_data);
276 #endif /* HCAPI_CFA_H_ */