1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2022 Broadcom 3 * All rights reserved. 4 */ 5 #ifndef _TFO_H_ 6 #define _TFO_H_ 7 8 #include <stdint.h> 9 #include <stdbool.h> 10 #include "rte_memzone.h" 11 #include "cfa_types.h" 12 #include "cfa_bld_mpcops.h" 13 #include "tfc.h" 14 #include "tfc_cpm.h" 15 16 /** 17 * @file 18 * 19 * @brief TFC (Truflow Core v3) Object Header File 20 * 21 * @page TFCOV3 Truflow Core v3 Object 22 * 23 * The TF Object stores internal TFC data. 24 * This data must be set/get using accessor functions. 25 * 26 * @ref tfo_open 27 * 28 * @ref tfo_close 29 * 30 * @ref tfo_mpcinfo_get 31 * 32 * @ref tfo_ts_set 33 * 34 * @ref tfo_ts_get 35 * 36 * @ref tfo_ts_validate 37 * 38 * @ref tfo_ts_set_mem_cfg 39 * 40 * @ref tfo_ts_get_mem_cfg 41 * 42 * @ref tfo_ts_get_cpm_inst 43 * 44 * @ref tfo_ts_set_cpm_inst 45 * 46 * @ref tfo_ts_get_pool_info 47 * 48 * @ref tfo_ts_set_pool_info 49 * 50 * @ref tfo_sid_set 51 * 52 * @ref tfo_sid_get 53 */ 54 55 /** Invalid Table Scope ID */ 56 #define INVALID_TSID UINT8_MAX 57 58 /** Maximum number of table scopes */ 59 #define TFC_TBL_SCOPE_MAX 32 60 61 /** Backing store/memory page levels */ 62 enum tfc_ts_pg_tbl_lvl { 63 TFC_TS_PT_LVL_0 = 0, 64 TFC_TS_PT_LVL_1, 65 TFC_TS_PT_LVL_2, 66 TFC_TS_PT_LVL_MAX 67 }; 68 69 /** 70 * Backing store and page table control struct that 71 * is used for storing the memory zone pointer and 72 * page allocation. 73 */ 74 struct tfc_ts_mz { 75 const struct rte_memzone *mz; 76 uint32_t page_count; 77 uint32_t page_size; 78 uint32_t alloc_count; 79 }; 80 81 /** 82 * Backing store/memory page table level config structure 83 */ 84 struct tfc_ts_page_tbl { 85 uint64_t *pg_pa_tbl; /**< Array of pointers to physical addresses */ 86 void **pg_va_tbl; /**< Array of pointers to virtual addresses */ 87 uint32_t pg_count; /**< Number of pages in this level */ 88 uint32_t pg_size; /**< Size of each page in bytes */ 89 }; 90 91 /** 92 * Backing store/memory config structure 93 */ 94 struct tfc_ts_mem_cfg { 95 /** page table configuration */ 96 struct tfc_ts_page_tbl pg_tbl[TFC_TS_PT_LVL_MAX]; 97 uint64_t num_data_pages; /**< Total number of pages */ 98 uint64_t l0_dma_addr; /**< Physical base memory address */ 99 void *l0_addr; /**< Virtual base memory address */ 100 int num_lvl; /**< Number of page levels */ 101 uint32_t page_cnt[TFC_TS_PT_LVL_MAX]; /**< Page count per level */ 102 uint32_t rec_cnt; /**< Total number of records in memory */ 103 uint32_t lkup_rec_start_offset; /**< Offset of lkup rec start (in records) */ 104 uint32_t entry_size; /**< Size of record in bytes */ 105 struct tfc_ts_mz ts_mz; /**< Memory zone control struct */ 106 }; 107 108 /** 109 * Backing store pool info 110 */ 111 struct tfc_ts_pool_info { 112 uint16_t lkup_max_contig_rec; /**< max contig records */ 113 uint16_t act_max_contig_rec; /**< max contig records */ 114 uint8_t lkup_pool_sz_exp; /**< lookup pool size exp */ 115 uint8_t act_pool_sz_exp; /**< action pool size exp */ 116 struct tfc_cpm *lkup_cpm; /**< CPM lookup pool manager pointer */ 117 struct tfc_cpm *act_cpm; /**< CPM action pool manager pointer */ 118 }; 119 120 121 /* TFO APIs */ 122 123 /** 124 * Allocate a TFC object for this DPDK port/function. 125 * 126 * @param[out] tfo 127 * Pointer to TFC object 128 * 129 * @param[in] is_pf 130 * Indicates whether the DPDK port is a PF. 131 */ 132 void tfo_open(void **tfo, bool is_pf); 133 134 /** 135 * Free the TFC object for this DPDK port/function. 136 * 137 * @param[in] tfo 138 * Pointer to TFC object 139 * 140 */ 141 void tfo_close(void **tfo); 142 143 /** 144 * Validate table scope id 145 * 146 * @param[in] tfo 147 * 148 * @param[in] ts_tsid 149 * 150 * @param[out] ts_valid 151 * 152 * @return 0 for tsid within range 153 */ 154 int tfo_ts_validate(void *tfo, uint8_t ts_tsid, bool *ts_valid); 155 /** 156 * Set the table scope configuration. 157 * 158 * @param[in] tfo 159 * Pointer to TFC object 160 * 161 * @param[in] ts_tsid 162 * The table scope ID 163 * 164 * @param[in] ts_is_shared 165 * True if the table scope is shared 166 * 167 * @param[in] ts_app 168 * Application type TF/AFM 169 * 170 * @param[in] ts_valid 171 * True if the table scope is valid 172 * 173 * @param[in] ts_max_pools 174 * Maximum number of pools if shared. 175 * 176 * @return 177 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 178 */ 179 int tfo_ts_set(void *tfo, uint8_t ts_tsid, bool ts_is_shared, 180 enum cfa_app_type ts_app, bool ts_valid, 181 uint16_t ts_max_pools); 182 183 /** 184 * Get the table scope configuration. 185 * 186 * @param[in] tfo 187 * Pointer to TFC object 188 * 189 * @param[in] ts_tsid 190 * The table scope ID 191 * 192 * @param[out] ts_is_shared 193 * True if the table scope is shared 194 * 195 * @param[out] ts_app 196 * Application type TF/AFM 197 * 198 * @param[out] ts_valid 199 * True if the table scope is valid 200 * 201 * @param[out] ts_max_pools 202 * Maximum number of pools returned if shared. 203 * 204 * @return 205 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 206 */ 207 int tfo_ts_get(void *tfo, uint8_t ts_tsid, bool *ts_is_shared, 208 enum cfa_app_type *ts_app, bool *ts_valid, 209 uint16_t *ts_max_pools); 210 211 /** 212 * Set the table scope memory configuration for this direction. 213 * 214 * @param[in] tfo 215 * Pointer to TFC object 216 * 217 * @param[in] ts_tsid 218 * The table scope ID 219 * 220 * @param[in] dir 221 * The direction (RX/TX) 222 * 223 * @param[in] region 224 * The memory region (lookup/action) 225 * 226 * @param[in] is_bs_owner 227 * True if the caller is the owner of the backing store 228 * 229 * @param[in] mem_cfg 230 * Backing store/memory config structure 231 * 232 * @return 233 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 234 */ 235 int tfo_ts_set_mem_cfg(void *tfo, uint8_t ts_tsid, enum cfa_dir dir, 236 enum cfa_region_type region, bool is_bs_owner, 237 struct tfc_ts_mem_cfg *mem_cfg); 238 239 /** 240 * Get the table scope memory configuration for this direction. 241 * 242 * @param[in] tfo 243 * Pointer to TFC object 244 * 245 * @param[in] ts_tsid 246 * The table scope ID 247 * 248 * @param[in] dir 249 * The direction (RX/TX) 250 * 251 * @param[in] region 252 * The memory table region (lookup/action) 253 * 254 * @param[out] is_bs_owner 255 * True if the caller is the owner of the backing store 256 * 257 * @param[out] mem_cfg 258 * Backing store/memory config structure 259 * 260 * @return 261 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 262 */ 263 int tfo_ts_get_mem_cfg(void *tfo, uint8_t ts_tsid, enum cfa_dir dir, 264 enum cfa_region_type region, bool *is_bs_owner, 265 struct tfc_ts_mem_cfg *mem_cfg); 266 267 /** 268 * Set the pool memory configuration for this direction. 269 * 270 * @param[in] tfo 271 * Pointer to TFC object 272 * 273 * @param[in] ts_tsid 274 * The table scope ID 275 * 276 * @param[in] dir 277 * The direction (RX/TX) 278 * 279 * @param[out] ts_pool 280 * Table scope pool info 281 * 282 * @return 283 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 284 */ 285 int tfo_ts_get_pool_info(void *tfo, uint8_t ts_tsid, enum cfa_dir dir, 286 struct tfc_ts_pool_info *ts_pool); 287 288 /** 289 * Get the pool memory configuration for this direction. 290 * 291 * @param[in] tfo 292 * Pointer to TFC object 293 * 294 * @param[in] ts_tsid 295 * The table scope ID 296 * 297 * @param[in] dir 298 * The direction (RX/TX) 299 * 300 * @param[in] ts_pool 301 * Table scope pool info 302 * 303 * @return 304 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 305 */ 306 int tfo_ts_set_pool_info(void *tfo, uint8_t ts_tsid, enum cfa_dir dir, 307 struct tfc_ts_pool_info *ts_pool); 308 309 310 /** Get the Pool Manager instance 311 * 312 * @param[in] tfo 313 * Pointer to TFC object 314 * 315 * @param[in] ts_tsid 316 * The table scope ID 317 * 318 * @param[in] dir 319 * The direction (RX/TX) 320 * 321 * @param[in] cpm_lkup 322 * Lookup CPM instance 323 * 324 * @param[in] cpm_act 325 * Action CPM instance 326 * 327 * @return 328 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 329 */ 330 int tfo_ts_get_cpm_inst(void *tfo, uint8_t ts_tsid, enum cfa_dir dir, 331 struct tfc_cpm **cpm_lkup, struct tfc_cpm **cpm_act); 332 333 /** Set the Pool Manager instance 334 * 335 * @param[in] tfo 336 * Pointer to TFC object 337 * 338 * @param[in] ts_tsid 339 * The table scope ID 340 * 341 * @param[in] dir 342 * The direction (RX/TX) 343 * 344 * @param[in] cpm_lkup 345 * Lookup CPM instance 346 * 347 * @param[in] cpm_act 348 * Action CPM instance 349 * 350 * @return 351 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 352 */ 353 int tfo_ts_set_cpm_inst(void *tfo, uint8_t ts_tsid, enum cfa_dir dir, 354 struct tfc_cpm *cpm_lkup, struct tfc_cpm *cpm_act); 355 356 /** Get the MPC info reference 357 * 358 * @param[in] tfo 359 * Pointer to TFC object 360 * 361 * @param[in] mpc_info 362 * MPC reference 363 * 364 * @return 365 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 366 */ 367 int tfo_mpcinfo_get(void *tfo, struct cfa_bld_mpcinfo **mpc_info); 368 369 370 /** Invalid session ID */ 371 #define INVALID_SID UINT16_MAX 372 373 /** 374 * Set the session ID. 375 * 376 * @param[in] tfo 377 * Pointer to TFC object 378 * 379 * @param[in] sid 380 * The session ID 381 * 382 * @return 383 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 384 */ 385 int tfo_sid_set(void *tfo, uint16_t sid); 386 387 /** 388 * Get the session ID. 389 * 390 * @param[in] tfo 391 * Pointer to TFC object 392 * 393 * @param[out] sid 394 * The session ID 395 * 396 * @return 397 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 398 */ 399 int tfo_sid_get(void *tfo, uint16_t *sid); 400 401 /** 402 * Set the table scope instance manager. 403 * 404 * @param[in] tfo 405 * Pointer to TFC object 406 * 407 * @param[in] tim 408 * Pointer to the table scope instance manager 409 * 410 * @return 411 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 412 */ 413 int tfo_tim_set(void *tfo, void *tim); 414 415 /** 416 * Get the table scope instance manager. 417 * 418 * @param[in] tfo 419 * Pointer to TFC object 420 * 421 * @param[out] tim 422 * Pointer to a pointer to the table scope instance manager 423 * 424 * @return 425 * 0 for SUCCESS, negative error value for FAILURE (errno.h) 426 */ 427 int tfo_tim_get(void *tfo, void **tim); 428 429 #endif /* _TFO_H_ */ 430