1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2019-2021 Broadcom 3 * All rights reserved. 4 */ 5 6 #ifndef _TF_TCAM_H_ 7 #define _TF_TCAM_H_ 8 9 #include "tf_core.h" 10 11 /** 12 * The TCAM module provides processing of Internal TCAM types. 13 */ 14 15 /** 16 * TCAM configuration parameters 17 */ 18 struct tf_tcam_cfg_parms { 19 /** 20 * Number of tcam types in each of the configuration arrays 21 */ 22 uint16_t num_elements; 23 /** 24 * TCAM configuration array 25 */ 26 struct tf_rm_element_cfg *cfg; 27 /** 28 * Shadow table type configuration array 29 */ 30 struct tf_shadow_tcam_cfg *shadow_cfg; 31 /** 32 * Boolean controlling the request shadow copy. 33 */ 34 bool shadow_copy; 35 /** 36 * Session resource allocations 37 */ 38 struct tf_session_resources *resources; 39 }; 40 41 /** 42 * TCAM allocation parameters 43 */ 44 struct tf_tcam_alloc_parms { 45 /** 46 * [in] Receive or transmit direction 47 */ 48 enum tf_dir dir; 49 /** 50 * [in] Type of the allocation 51 */ 52 enum tf_tcam_tbl_type type; 53 /** 54 * [in] key size 55 */ 56 uint16_t key_size; 57 /** 58 * [in] Priority of entry requested (definition TBD) 59 */ 60 uint32_t priority; 61 /** 62 * [out] Idx of allocated entry or found entry (if search_enable) 63 */ 64 uint16_t idx; 65 }; 66 67 /** 68 * TCAM free parameters 69 */ 70 struct tf_tcam_free_parms { 71 /** 72 * [in] Receive or transmit direction 73 */ 74 enum tf_dir dir; 75 /** 76 * [in] Type of the allocation type 77 */ 78 enum tf_tcam_tbl_type type; 79 /** 80 * [in] Type of HCAPI 81 */ 82 uint16_t hcapi_type; 83 /** 84 * [in] Index to free 85 */ 86 uint16_t idx; 87 /** 88 * [out] Reference count after free, only valid if session has been 89 * created with shadow_copy. 90 */ 91 uint16_t ref_cnt; 92 }; 93 94 /** 95 * TCAM allocate search parameters 96 */ 97 struct tf_tcam_alloc_search_parms { 98 /** 99 * [in] receive or transmit direction 100 */ 101 enum tf_dir dir; 102 /** 103 * [in] TCAM table type 104 */ 105 enum tf_tcam_tbl_type type; 106 /** 107 * [in] Type of HCAPI 108 */ 109 uint16_t hcapi_type; 110 /** 111 * [in] Key data to match on 112 */ 113 uint8_t *key; 114 /** 115 * [in] key size in bits 116 */ 117 uint16_t key_size; 118 /** 119 * [in] Mask data to match on 120 */ 121 uint8_t *mask; 122 /** 123 * [in] Priority of entry requested (definition TBD) 124 */ 125 uint32_t priority; 126 /** 127 * [in] Allocate on miss. 128 */ 129 uint8_t alloc; 130 /** 131 * [out] Set if matching entry found 132 */ 133 uint8_t hit; 134 /** 135 * [out] Search result status (hit, miss, reject) 136 */ 137 enum tf_search_status search_status; 138 /** 139 * [out] Current refcnt after allocation 140 */ 141 uint16_t ref_cnt; 142 /** 143 * [in,out] The result data from the search is copied here 144 */ 145 uint8_t *result; 146 /** 147 * [in,out] result size in bits for the result data 148 */ 149 uint16_t result_size; 150 /** 151 * [out] Index found 152 */ 153 uint16_t idx; 154 }; 155 156 /** 157 * TCAM set parameters 158 */ 159 struct tf_tcam_set_parms { 160 /** 161 * [in] Receive or transmit direction 162 */ 163 enum tf_dir dir; 164 /** 165 * [in] Type of object to set 166 */ 167 enum tf_tcam_tbl_type type; 168 /** 169 * [in] Type of HCAPI 170 */ 171 uint16_t hcapi_type; 172 /** 173 * [in] Entry index to write to 174 */ 175 uint32_t idx; 176 /** 177 * [in] array containing key 178 */ 179 uint8_t *key; 180 /** 181 * [in] array containing mask fields 182 */ 183 uint8_t *mask; 184 /** 185 * [in] key size 186 */ 187 uint16_t key_size; 188 /** 189 * [in] array containing result 190 */ 191 uint8_t *result; 192 /** 193 * [in] result size 194 */ 195 uint16_t result_size; 196 }; 197 198 /** 199 * TCAM get parameters 200 */ 201 struct tf_tcam_get_parms { 202 /** 203 * [in] Receive or transmit direction 204 */ 205 enum tf_dir dir; 206 /** 207 * [in] Type of object to get 208 */ 209 enum tf_tcam_tbl_type type; 210 /** 211 * [in] Entry index to read 212 */ 213 uint32_t idx; 214 /** 215 * [out] array containing key 216 */ 217 uint8_t *key; 218 /** 219 * [out] array containing mask fields 220 */ 221 uint8_t *mask; 222 /** 223 * [out] key size 224 */ 225 uint16_t key_size; 226 /** 227 * [out] array containing result 228 */ 229 uint8_t *result; 230 /** 231 * [out] result size 232 */ 233 uint16_t result_size; 234 }; 235 236 /** 237 * @page tcam TCAM 238 * 239 * @ref tf_tcam_bind 240 * 241 * @ref tf_tcam_unbind 242 * 243 * @ref tf_tcam_alloc 244 * 245 * @ref tf_tcam_free 246 * 247 * @ref tf_tcam_alloc_search 248 * 249 * @ref tf_tcam_set 250 * 251 * @ref tf_tcam_get 252 * 253 */ 254 255 /** 256 * Initializes the TCAM module with the requested DBs. Must be 257 * invoked as the first thing before any of the access functions. 258 * 259 * [in] tfp 260 * Pointer to TF handle, used for HCAPI communication 261 * 262 * [in] parms 263 * Pointer to parameters 264 * 265 * Returns 266 * - (0) if successful. 267 * - (-EINVAL) on failure. 268 */ 269 int tf_tcam_bind(struct tf *tfp, 270 struct tf_tcam_cfg_parms *parms); 271 272 /** 273 * Cleans up the private DBs and releases all the data. 274 * 275 * [in] tfp 276 * Pointer to TF handle, used for HCAPI communication 277 * 278 * [in] parms 279 * Pointer to parameters 280 * 281 * Returns 282 * - (0) if successful. 283 * - (-EINVAL) on failure. 284 */ 285 int tf_tcam_unbind(struct tf *tfp); 286 287 /** 288 * Allocates the requested tcam type from the internal RM DB. 289 * 290 * [in] tfp 291 * Pointer to TF handle, used for HCAPI communication 292 * 293 * [in] parms 294 * Pointer to parameters 295 * 296 * Returns 297 * - (0) if successful. 298 * - (-EINVAL) on failure. 299 */ 300 int tf_tcam_alloc(struct tf *tfp, 301 struct tf_tcam_alloc_parms *parms); 302 303 /** 304 * Free's the requested table type and returns it to the DB. If shadow 305 * DB is enabled its searched first and if found the element refcount 306 * is decremented. If refcount goes to 0 then its returned to the 307 * table type DB. 308 * 309 * [in] tfp 310 * Pointer to TF handle, used for HCAPI communication 311 * 312 * [in] parms 313 * Pointer to parameters 314 * 315 * Returns 316 * - (0) if successful. 317 * - (-EINVAL) on failure. 318 */ 319 int tf_tcam_free(struct tf *tfp, 320 struct tf_tcam_free_parms *parms); 321 322 /** 323 * Supported if Shadow DB is configured. Searches the Shadow DB for 324 * any matching element. If found the refcount in the shadow DB is 325 * updated accordingly. If not found a new element is allocated and 326 * installed into the shadow DB. 327 * 328 * [in] tfp 329 * Pointer to TF handle, used for HCAPI communication 330 * 331 * [in] parms 332 * Pointer to parameters 333 * 334 * Returns 335 * - (0) if successful. 336 * - (-EINVAL) on failure. 337 */ 338 int tf_tcam_alloc_search(struct tf *tfp, 339 struct tf_tcam_alloc_search_parms *parms); 340 341 /** 342 * Configures the requested element by sending a firmware request which 343 * then installs it into the device internal structures. 344 * 345 * [in] tfp 346 * Pointer to TF handle, used for HCAPI communication 347 * 348 * [in] parms 349 * Pointer to parameters 350 * 351 * Returns 352 * - (0) if successful. 353 * - (-EINVAL) on failure. 354 */ 355 int tf_tcam_set(struct tf *tfp, 356 struct tf_tcam_set_parms *parms); 357 358 /** 359 * Retrieves the requested element by sending a firmware request to get 360 * the element. 361 * 362 * [in] tfp 363 * Pointer to TF handle, used for HCAPI communication 364 * 365 * [in] parms 366 * Pointer to parameters 367 * 368 * Returns 369 * - (0) if successful. 370 * - (-EINVAL) on failure. 371 */ 372 int tf_tcam_get(struct tf *tfp, 373 struct tf_tcam_get_parms *parms); 374 375 #endif /* _TF_TCAM_H */ 376