tcam_handler.h (19159B)
1 /** 2 * \file tcam_handler.h 3 * 4 * DESCRIPTION : 5 * This files represents the TCAM handler class, which connects between 6 * its database field and the TCAM, and exposes functions to add/remove 7 * entries for the database. After opening a connection with required 8 * database, user can start adding/removing entries from this database to 9 * the TCAM by calling entry_add and entry_remove. 10 * 11 * Sample API usage: 12 * \code{.c} 13 * uint32 handler_id; 14 * dnx_field_tcam_database_t *db; 15 * dnx_field_tcam_entry_t *entry; 16 * fill_db(db); "foo function to fill data for the db" 17 * fill_entry(entry); "foo function to fill data for the entry" 18 * dnx_field_tcam_handler_create(unit, 19 * db, 20 * NULL, "No bank pre-allocation, struct defined in tcam_bank_manager.h" 21 * FIELD_TCAM_ACCESS_PROFILE_ID_AUTO, "manager will allocate access_profile_id, defined in tcam_access_profile_manager.h" 22 * DNX_FIELD_TCAM_HANDLER_MODE_DEFAULT, 23 * &handler_id 24 * ); 25 * dnx_field_tcam_handler_entry_add(unit, handler_id, entry); 26 * \endcode 27 * 28 * 29 * PUBLIC FUNCTIONS (dnx_field_tcam omitted): 30 * shr_error_e handler_create( unit, database, nof_prealloc, loose, *handler_id) 31 * shr_error_e handler_destroy( unit, handler_id ) 32 * shr_error_e handler_access_profile_id_get( unit, handler_id, *access_p_id ) 33 * shr_error_e handler_entry_location_alloc( unit, handler_id, entry ) 34 * shr_error_e handler_entry_location_free( unit, handler_id, entry_id ) 35 * shr_error_e handler_clear( unit, handler_id ) 36 */ 37 /** 38 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 39 * 40 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 41 */ 42 43 #ifndef TCAM_HANDLER_H_INCLUDED 44 /** { */ 45 #define TCAM_HANDLER_H_INCLUDED 46 47 #include <include/bcm_int/dnx/field/tcam/tcam_entities.h> 48 #include <include/bcm_int/dnx/field/tcam/tcam_bank_manager.h> 49 #include <include/bcm_int/dnx/field/tcam/tcam_access_profile_manager.h> 50 #include <soc/dnx/swstate/auto_generated/types/dnx_field_tcam_manager_types.h> 51 #include <soc/dnx/swstate/auto_generated/types/dnx_field_tcam_location_types.h> 52 53 #include <soc/dnx/dnx_data/auto_generated/dnx_data_field.h> 54 55 #define DNX_FIELD_TCAM_HANDLER_ID_INVALID 0x1023 56 57 /** 58 * \brief 59 * Create a connection between the given database and the TCAM banks by allocating an access 60 * profile id for the given database, then pre-allocating banks according to bank_prealloc data. 61 * 62 * \param [in] unit - Device ID 63 * \param [in] db - The database to open the connection to 64 * \param [in] access_profile_id - Requested access profile ID to allocate for this handler. 65 * If FIELD_TCAM_ACCESS_PROFILE_ID_AUTO then ID is automatically 66 * allocated. 67 * \param [in] mode - Mode for the handler to be created 68 * \param [in] context_sharing_handlers_cb - Callback function that handler will invoke whenever adding 69 * a new bank to the newly created handler that will provide 70 * information about same-context handlers in order to prevent 71 * same-context handlers from allocating the same bank 72 * \param [out] handler_id - ID of the newly created handler 73 * 74 * \return 75 * \retval _SHR_E_NONE success 76 * \remark 77 * SPECIAL_OUTPUTS : 78 * HW: 79 * TCAM_ACCESS_PROFILE 80 * PROCESS : 81 * [1] Check that database doesn't already have an open connection 82 * [2] Allocate an access profile id and write it to HW 83 * [3] Pre-allocate nof_prealloc banks if prealloc info is not NULL 84 */ 85 shr_error_e dnx_field_tcam_handler_create( 86 int unit, 87 dnx_field_tcam_database_t * db, 88 int access_profile_id, 89 dnx_field_tcam_handler_mode_e mode, 90 dnx_field_tcam_context_sharing_handlers_get_p context_sharing_handlers_cb, 91 uint32 *handler_id); 92 93 /** 94 * \brief 95 * Destroys the given handler_id by freeing the access profile ID associated with the handler's 96 * database. If the given handler has any entries installed inside the HW, the destroy operation 97 * will fail. 98 * 99 * \param [in] unit - Device ID 100 * \param [in] handler_id - The handler ID to destroy 101 * 102 * \return 103 * \retval _SHR_E_NONE success 104 * \remark 105 * SPECIAL OUTPUTS: 106 * HW: 107 * TCAM_ACCESS_PROFILE 108 * TCAM_BANK 109 * PROCESS : 110 * [1] Check that handler is valid 111 * [2] Removes all database's entries from TCAM 112 * [3] Frees all allocated banks 113 * [4] Frees the access_profile_id 114 */ 115 shr_error_e dnx_field_tcam_handler_destroy( 116 int unit, 117 uint32 handler_id); 118 119 /** 120 * \brief 121 * Returns the access profile ID for the given handler_id. 122 * 123 * \param [in] unit - Device ID 124 * \param [in] handler_id - The handler ID to get the access profile ID for 125 * \param [out] access_profile_id - The access profile ID of the given handler 126 * 127 * \return 128 * \retval _SHR_E_NONE success 129 * \remark 130 * PROCESS : 131 * [1] Checks that handler is valid 132 * [2] Call dnx_field_tcam_access_profile_id_get 133 */ 134 shr_error_e dnx_field_tcam_handler_access_profile_id_get( 135 int unit, 136 uint32 handler_id, 137 int *access_profile_id); 138 139 /** 140 * \brief 141 * Returns the APP_DB_ID for the given tcam_handler. 142 * 143 * \param [in] unit - Device ID 144 * \param [in] handler_id - The handler ID to get the "app db ID" for 145 * \param [out] app_db_id - the "app db ID" of the given handler_id 146 * 147 * \return 148 * \retval _SHR_E_NONE success 149 * \remark 150 * Calls dnx_field_tcam_handler_access_profile_id_get and converts to dnx_field_app_db_id_t type. 151 */ 152 shr_error_e dnx_field_tcam_handler_app_db_id_get( 153 int unit, 154 uint32 handler_id, 155 dnx_field_app_db_id_t * app_db_id); 156 157 /** 158 * \brief 159 * Adds the given DT entry to TCAM on the given core. 160 * This function must be invoked by direct table handler only. 161 * 162 * \param [in] unit - Device ID 163 * \param [in] core - Core ID 164 * \param [in] handler_id - The DT handler ID associated with the entry 165 * \param [in] entry - The DT entry to allocate location for in TCAM 166 * 167 * \return 168 * \retval _SHR_E_NONE success 169 * \remark 170 * SPECIAL OUTPUT: 171 * HW: 172 * TCAM_BANK/TCAM_BANK_ACTION Writes the entry and its action 173 * PROCESS : 174 * [1] Check that handler is valid/entry is not null 175 * [2] Check that entry doesn't already exist 176 * [3] Find an empty location for the entry 177 * [4] Write entry to HW 178 */ 179 shr_error_e dnx_field_tcam_handler_entry_dt_location_alloc( 180 int unit, 181 int core, 182 uint32 handler_id, 183 dnx_field_tcam_entry_t * entry); 184 185 /** 186 * \brief 187 * Adds the given entry to TCAM on the given core. 188 * 189 * \param [in] unit - Device ID 190 * \param [in] core - Core ID 191 * \param [in] handler_id - The handler ID associated with the entry 192 * \param [in] entry - The entry to allocate location for in TCAM 193 * 194 * \return 195 * \retval _SHR_E_NONE success 196 * \remark 197 * SPECIAL OUTPUT: 198 * HW: 199 * TCAM_BANK/TCAM_BANK_ACTION Writes the entry and its action 200 * PROCESS : 201 * [1] Check that handler is valid/entry is not null 202 * [2] Check that entry doesn't already exist 203 * [3] Find an empty location for the entry 204 * [4] Write entry to HW 205 */ 206 shr_error_e dnx_field_tcam_handler_entry_location_alloc( 207 int unit, 208 int core, 209 uint32 handler_id, 210 dnx_field_tcam_entry_t * entry); 211 212 /** 213 * \brief 214 * Update valid bit for given entry 215 * 216 * \param [in] unit - Device ID 217 * \param [in] core - Core ID entry is found on 218 * \param [in] entry_id - The entry to set valid bit for 219 * \param [in] valid_bit - New valid bit 220 * 221 * \return 222 * \retval _SHR_E_NONE Success 223 * 224 * \remark 225 * None 226 */ 227 228 shr_error_e dnx_field_tcam_handler_entry_valid_set( 229 int unit, 230 int core, 231 uint32 entry_id, 232 uint8 valid_bit); 233 234 /** 235 * \brief 236 * Update valid bit for given entry 237 * 238 * \param [in] unit - Device ID 239 * \param [in] core - Core ID entry is found on 240 * \param [in] entry_id - The entry to get its valid bit 241 * \param [out] valid_bit - Entry's valid bit 242 * 243 * \return 244 * \retval _SHR_E_NONE Success 245 * 246 * \remark 247 * None 248 */ 249 shr_error_e dnx_field_tcam_handler_entry_valid_get( 250 int unit, 251 int core, 252 uint32 entry_id, 253 uint8 *valid_bit); 254 255 /** 256 * \brief 257 * Removes given entry_id associated with the given handler_id from TCAM database 258 * 259 * \param [in] unit - Device ID 260 * \param [in] handler_id - The Handler ID that contains the given entry 261 * \param [in] entry_id - The entry ID to remove from TCAM 262 * 263 * \return 264 * \retval _SHR_E_NONE success 265 * \remark 266 * PROCESS : 267 * [1] Check that tcam_handler is valid 268 * [2] Check that entry already exist 269 * [3] Remove entry from database 270 */ 271 shr_error_e dnx_field_tcam_handler_entry_location_free( 272 int unit, 273 uint32 handler_id, 274 uint32 entry_id); 275 276 /** 277 * \brief 278 * Returns the state of the given TCAM handler_id. 279 * 280 * \param [in] unit - Device ID 281 * \param [in] handler_id - The handler ID to get the "state" for 282 * \param [out] state - the "state" of the given handler_id 283 * 284 * \return 285 * \retval _SHR_E_NONE success 286 */ 287 shr_error_e dnx_field_tcam_handler_state_get( 288 int unit, 289 uint32 handler_id, 290 dnx_field_tcam_handler_state_e * state); 291 292 /** 293 * \brief 294 * Clears the given handler by removing all installed entries from TCAM. 295 * 296 * \param [in] unit - Device ID 297 * \param [in] handler_id - The handler ID to clear 298 * 299 * \return 300 * \retval _SHR_E_NONE success 301 * \remark 302 * SPECIAL OUTPUT: 303 * HW: 304 * TCAM_BANK Invalidates all handler's database entries 305 * PROCESS : 306 * [1] Check that handler is valid 307 * [2] Invalidate all database's installed entries 308 */ 309 shr_error_e dnx_field_tcam_handler_clear( 310 int unit, 311 uint32 handler_id); 312 313 /** 314 * \brief 315 * Notifies the manager about the given handler ID being attached to a field program. 316 * It does so by supplying which other handler IDs are in the same program that the 317 * given handler ID is being attached to. 318 * 319 * \param [in] unit - Device ID 320 * \param [in] handler_id - The handler ID being attached to a program 321 * \param [in] same_program_handler_ids - Array of IDs of the handlers that are already in 322 * the program 323 * \param [in] handlers_count - Count of the handler IDs array 324 * 325 * \return 326 * \retval _SHR_E_NONE - success 327 * \retval _SHR_E_RESOURCE - Attaching error: two handlers in same program will share same bank 328 */ 329 shr_error_e dnx_field_tcam_handler_program_attach( 330 int unit, 331 uint32 handler_id, 332 uint32 *same_program_handler_ids, 333 int handlers_count); 334 335 /** 336 * \brief 337 * Returns the first entry id for the given handler_id. 338 * The first entry id for a given handler is defined to be the id 339 * of the entry that both belongs to the handler and is the first 340 * in line between all other entries that belongs to the same handler 341 * inside the TCAM banks on the given core. 342 * 343 * \param [in] unit - Device ID 344 * \param [in] core - Core ID 345 * \param [in] handler_id - handler ID to get the first entry ID for 346 * \param [out] first_entry_id - The ID of the first entry for the given handler, if exists. 347 * DNX_FIELD_ENTRY_ACCESS_ID_INVALID otherwise 348 * 349 * \return 350 * \retval _SHR_E_NONE - success 351 */ 352 shr_error_e dnx_field_tcam_handler_entry_first( 353 int unit, 354 int core, 355 uint32 handler_id, 356 uint32 *first_entry_id); 357 358 /** 359 * \brief 360 * Returns the next entry id following the given entry id for the specified handler id. 361 * The next entry is defined to be the next-in-line to come inside the TCAM banks on 362 * the given core after the given entry id that belongs to the given handler id. 363 * 364 * \param [in] unit - Device ID 365 * \param [in] core - Core ID 366 * \param [in] handler_id - handler ID to get the next entry for 367 * \param [in] entry_id - The entry ID that precedes the entry that will be returned 368 * \param [out] next_entry_id - The entry ID that both belongs to the handler and comes 369 * after the given entry_id, if exists. 370 * DNX_FIELD_ENTRY_ACCESS_ID_INVALID otherwise 371 * 372 * \return 373 * \retval _SHR_E_NONE - success 374 */ 375 shr_error_e dnx_field_tcam_handler_entry_next( 376 int unit, 377 int core, 378 uint32 handler_id, 379 uint32 entry_id, 380 uint32 *next_entry_id); 381 382 /** 383 * \brief 384 * Returns the location/core for the given entry_id on the given core. 385 * 386 * \param [in] unit - Device ID 387 * \param [in] core - Core ID to get the entry location on 388 * \param [in] entry_id - the entry ID to get the location for 389 * \param [out] location - the location for the given entry_id 390 * 391 * \return 392 * \retval _SHR_E_NONE success 393 */ 394 shr_error_e dnx_field_tcam_handler_entry_location( 395 int unit, 396 int core, 397 uint32 entry_id, 398 dnx_field_tcam_location_t * location); 399 400 /** 401 * \brief 402 * Returns information about the entries for the given TCAM handler id. 403 * The info returned includes info about the number of inserted entries that 404 * belong to the given handler_id distributed over all the TCAM banks on the 405 * given core in the device. This information is returned in the 406 * variable bank_entries_count which is an array of size 407 * DNX_DATA_MAX_FIELD_TCAM_NOF_BANKS that the user needs to allocate before 408 * calling this function. 409 * Another piece of information returned by this function through the banks_bmp 410 * variable, is a bitmap of all allocated banks for the given handler_id. 411 * 412 * \param [in] unit - Device ID 413 * \param [in] core - Core ID 414 * \param [in] handler_id - The handler to get the information for. 415 * \param [out] bank_entries_count - An array that the user should allocate 416 * the space for, should be of size 417 * DNX_DATA_MAX_FIELD_TCAM_NOF_BANKS. 418 * Each element in the array represents 419 * the number of entries for the corresponding 420 * TCAM_BANK which ID is the index to the 421 * element. 422 * \param [out] banks_bmp - An output bitmap of all allocated banks 423 * for the given handler. 424 * 425 * \return 426 * \retval _SHR_E_NONE - Success 427 */ 428 shr_error_e dnx_field_tcam_handler_entries_info( 429 int unit, 430 int core, 431 uint32 handler_id, 432 uint32 bank_entries_count[DNX_DATA_MAX_FIELD_TCAM_NOF_BANKS], 433 uint32 *banks_bmp); 434 435 /** 436 * \brief 437 * Returns the priority for the entry whose id is the given entry_id. 438 * 439 * \param [in] unit - Device ID 440 * \param [in] handler_id - The handler ID that contains the entry 441 * \param [in] entry_id - The entry ID to return the priority for 442 * \param [out] priority - The priority of the entry 443 * 444 * \return 445 * \retval _SHR_E_NONE - Success 446 */ 447 shr_error_e dnx_field_tcam_handler_entry_priority_get( 448 int unit, 449 uint32 handler_id, 450 uint32 entry_id, 451 uint32 *priority); 452 453 /** 454 * \brief 455 * Returns the bank allocation mode (BAM) for the given handler id. 456 * 457 * \param [in] unit - Device ID 458 * \param [in] handler_id - The handler ID to get the BAM for 459 * \param [out] bank_allocation_mode - The BAM for the given handler ID 460 * 461 * \return 462 * \retval _SHR_E_NONE - Success 463 */ 464 shr_error_e dnx_field_tcam_handler_bank_allocation_mode_get( 465 int unit, 466 uint32 handler_id, 467 dnx_field_tcam_bank_allocation_mode_e * bank_allocation_mode); 468 469 /** 470 * \brief 471 * Evacuates the given handler_id from the given bank_id on all cores. 472 * The evacuation process involves moving all handler's entries on the 473 * given bank to other banks allocated by the same handler. 474 * If the evacuation process succeeds, the handler is removed from the bank (therefore, 475 * helping to remove constraints for other handlers to use the evacuated bank). 476 * 477 * This function starts moving entries to other banks allocated by the given handler 478 * until either all handler's entries on the bank are moved to other banks, or no 479 * more empty space is left in the other banks allocated by the given handler. 480 * In case no empty space is left, all the entries that were moved until this point stay 481 * as-is and the function fails. 482 * 483 * \param[in] unit - Device ID 484 * \param[in] handler_id - Handler ID to move its entries from given bank 485 * \param[in] nof_banks - Number of banks to evacuate 486 * \param[in] bank_ids - Array of bank IDs to evacuate 487 * 488 * \return 489 * \retval _SHR_E_NONE - Success 490 * \retval _SHR_E_PARAM - One of the given params is invalid or OOR 491 * \retval _SHR_E_FAIL - No more space left to move entries to 492 * \retval _SHR_E_INTERNAL - Something wrong happened with the algorithm (sanity checks failure) 493 */ 494 shr_error_e dnx_field_tcam_handler_bank_evacuate( 495 int unit, 496 uint32 handler_id, 497 int nof_banks, 498 int bank_ids[]); 499 500 /** 501 * \brief 502 * Adds the given handler_id to the given bank_ids. 503 * 504 * \param[in] unit - Device ID 505 * \param[in] handler_id - Handler ID to add to given banks 506 * \param[in] nof_banks - Number of banks to add 507 * \param[in] bank_ids - Array of bank IDs to add 508 * 509 * \return 510 * \retval _SHR_E_NONE - Success 511 * \retval _SHR_E_PARAM - One of the given params is invalid or OOR 512 */ 513 shr_error_e dnx_field_tcam_handler_bank_add( 514 int unit, 515 uint32 handler_id, 516 int nof_banks, 517 int bank_ids[]); 518 519 /** 520 * \brief 521 * Returns an indication for status of the given entry_id on the given core. 522 * If '1' entry exists, if '0' entry doesn't exist. 523 * 524 * \param [in] unit - Device ID 525 * \param [in] core - Core on which entry have to be checked 526 * \param [in] entry_id - The entry ID to check if exists 527 * \param [out] found_p - '1' if entry exists, '0' if not. 528 * 529 * \return 530 * \retval _SHR_E_NONE success 531 */ 532 shr_error_e dnx_field_tcam_handler_entry_id_exists( 533 int unit, 534 int core, 535 uint32 entry_id, 536 uint8 *found_p); 537 538 /** 539 * \brief 540 * Returns the TCAM handler ID of the given entry ID. 541 * 542 * \param [in] unit - Device ID 543 * \param [in] entry_id - Entry ID to return the TCAM Handler ID for 544 * \param [out] handler_id - TCAM Handler ID of the given entry ID 545 * 546 * \return 547 * \retval _SHR_E_NONE success 548 */ 549 shr_error_e dnx_field_tcam_handler_entry_handler( 550 int unit, 551 uint32 entry_id, 552 uint32 *handler_id); 553 554 /** } */ 555 #endif