1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2019-2020 Broadcom 3 * All rights reserved. 4 */ 5 6 #ifndef _HCAPI_CFA_H_ 7 #define _HCAPI_CFA_H_ 8 9 #include <stdio.h> 10 #include <string.h> 11 #include <stdbool.h> 12 #include <stdint.h> 13 #include <stddef.h> 14 15 #include "hcapi_cfa_defs.h" 16 17 #if CHIP_CFG == SR_A 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 23 #else 24 #error "Chip not supported" 25 #endif 26 27 #if SUPPORT_CFA_HW_P4 && SUPPORT_CFA_HW_P58 && SUPPORT_CFA_HW_P59 28 #define SUPPORT_CFA_HW_ALL 1 29 #endif 30 31 /** 32 * Index used for the sram_entries field 33 */ 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 49 }; 50 51 /** 52 * Index used for the hw_entries field in struct cfa_rm_db 53 */ 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 82 }; 83 84 struct hcapi_cfa_key_result { 85 uint64_t bucket_mem_ptr; 86 uint8_t bucket_idx; 87 }; 88 89 /* common CFA register access macros */ 90 #define CFA_REG(x) OFFSETOF(cfa_reg_t, cfa_##x) 91 92 #ifndef TF_REG_WR 93 #define TF_REG_WR(_p, x, y) (*((uint32_t volatile *)(x)) = (y)) 94 #endif 95 #ifndef TF_REG_RD 96 #define TF_REG_RD(_p, x) (*((uint32_t volatile *)(x))) 97 #endif 98 #ifndef TF_CFA_REG_RD 99 #define TF_CFA_REG_RD(_p, x) \ 100 TF_REG_RD(0, (uint32_t)(_p)->base_addr + CFA_REG(x)) 101 #endif 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) 105 #endif 106 107 /* Constants used by Resource Manager Registration*/ 108 #define RM_CLIENT_NAME_MAX_LEN 32 109 110 /** 111 * Resource Manager Data Structures used for resource requests 112 */ 113 struct hcapi_cfa_resc_req_entry { 114 uint16_t min; 115 uint16_t max; 116 }; 117 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. 126 */ 127 uint32_t sram_resc_flags; 128 struct hcapi_cfa_resc_req_entry sram_resc[HCAPI_CFA_RESC_TYPE_SRAM_MAX]; 129 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. 136 */ 137 uint32_t hw_resc_flags; 138 struct hcapi_cfa_resc_req_entry hw_resc[HCAPI_CFA_RESC_TYPE_HW_MAX]; 139 }; 140 141 struct hcapi_cfa_resc_req_db { 142 struct hcapi_cfa_resc_req rx; 143 struct hcapi_cfa_resc_req tx; 144 }; 145 146 struct hcapi_cfa_resc_entry { 147 uint16_t start; 148 uint16_t stride; 149 uint16_t tag; 150 }; 151 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. 160 */ 161 uint32_t sram_resc_flags; 162 struct hcapi_cfa_resc_entry sram_resc[HCAPI_CFA_RESC_TYPE_SRAM_MAX]; 163 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 169 * in the pool. 170 */ 171 uint32_t hw_resc_flags; 172 struct hcapi_cfa_resc_entry hw_resc[HCAPI_CFA_RESC_TYPE_HW_MAX]; 173 }; 174 175 struct hcapi_cfa_resc_db { 176 struct hcapi_cfa_resc rx; 177 struct hcapi_cfa_resc tx; 178 }; 179 180 /** 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. 184 */ 185 typedef struct hcapi_cfa_rm_data { 186 uint32_t dummy_data; 187 } hcapi_cfa_rm_data_t; 188 189 /* End RM support */ 190 191 struct hcapi_cfa_devops; 192 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; 197 }; 198 199 int hcapi_cfa_dev_bind(enum hcapi_cfa_ver hw_ver, 200 struct hcapi_cfa_devinfo *dev_info); 201 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); 205 int 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, 212 uint32_t base_ptr); 213 214 int hcapi_cfa_action_hw_op(struct hcapi_cfa_hwop *op, 215 uint8_t *act_tbl, 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, 221 int *client_id); 222 int hcapi_cfa_rm_unregister_client(hcapi_cfa_rm_data_t *data, 223 int client_id); 224 int hcapi_cfa_rm_query_resources(hcapi_cfa_rm_data_t *data, 225 int client_id, 226 uint16_t chnl_id, 227 struct hcapi_cfa_resc_req_db *req_db); 228 int hcapi_cfa_rm_query_resources_one(hcapi_cfa_rm_data_t *data, 229 int clien_id, 230 struct hcapi_cfa_resc_db *resc_db); 231 int hcapi_cfa_rm_reserve_resources(hcapi_cfa_rm_data_t *data, 232 int client_id, 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, 236 int client_id, 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); 240 241 #if SUPPORT_CFA_HW_P4 242 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, 260 uint32_t type, 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, 267 uint32_t type, 268 struct hcapi_cfa_data *config); 269 /* SUPPORT_CFA_HW_P45 */ 270 #endif 271 /** 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. 275 */ 276 277 struct hcapi_cfa_tbl_cb { 278 /** 279 * This function callback provides the functionality to read/write 280 * HW table entry from a HW table. 281 * 282 * @param[in] op 283 * A pointer to the Hardware operation parameter 284 * 285 * @param[in] obj_data 286 * A pointer to the HW data object for the hardware operation 287 * 288 * @return 289 * 0 for SUCCESS, negative value for FAILURE 290 */ 291 int (*hwop_cb)(struct hcapi_cfa_hwop *op, 292 struct hcapi_cfa_data *obj_data); 293 }; 294 295 #endif /* HCAPI_CFA_H_ */ 296