l3_ecmp.h (15024B)
1 /** \file bcm_int/dnx/l3/l3_ecmp.h Internal DNX L3 APIs 2 PIs This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 3 PIs 4 PIs Copyright 2007-2020 Broadcom Inc. All rights reserved. 5 */ 6 7 #ifndef L3_ECMP_H_INCLUDED 8 /* 9 * { 10 */ 11 #define L3_ECMP_H_INCLUDED 12 13 #ifndef BCM_DNX_SUPPORT 14 #error "This file is for use by DNX (JR2) family only!" 15 #endif 16 17 /* 18 * Include files. 19 * { 20 */ 21 #include <soc/dnx/dnx_data/auto_generated/dnx_data_internal_l3.h> 22 #include <soc/dnx/dnx_data/auto_generated/dnx_data_l3.h> 23 #include <bcm_int/dnx/algo/consistent_hashing/consistent_hashing_manager.h> 24 #include <soc/dnx/dbal/dbal.h> 25 #include <bcm/l3.h> 26 /* 27 * } 28 */ 29 30 /* 31 * DEFINES 32 * { 33 */ 34 35 /* 36 * The max NOF entries that a consistent table can hold 37 */ 38 #define L3_ECMP_CONSISTENT_TABLE_MAX_NOF_ENTRIES 512 39 /* 40 * Currently each member entry size can be either 4 bits (small table) or 8 bits (medium/large table). 41 */ 42 #define L3_ECMP_4_BITS_MEMBER 4 43 #define L3_ECMP_8_BITS_MEMBER 8 44 #define L3_ECMP_HIERARCHY_FIELD_SIZE utilex_log2_round_up(DNX_DATA_MAX_MDB_DIRECT_NOF_FEC_ECMP_HIERARCHIES) 45 #define L3_ECMP_HIERARCHY_FIELD_MASK UTILEX_BITS_MASK((L3_ECMP_HIERARCHY_FIELD_SIZE - 1), 0) 46 47 /* 48 * } 49 */ 50 /* 51 * Enumeration. 52 * { 53 */ 54 55 /* 56 * } 57 */ 58 59 /* 60 * MACROs 61 * { 62 */ 63 /* 64 * The profile ID is used as a key to the consistent hashing manager. 65 * As the profile ID isn't unique (there is one per hierarchy) the hierarchy information is part of the key. 66 * Below are defines that will provide the information how to pack the hierarchy and the profile ID in a uint32 variable. 67 */ 68 #define L3_ECMP_PROFILE_ID_FIELD_MASK(unit) UTILEX_BITS_MASK(dnx_data_l3.ecmp.profile_id_size_get(unit) - 1, 0) 69 #define L3_ECMP_HIERARCHY_FIELD_OFFSET(unit) (dnx_data_l3.ecmp.profile_id_size_get(unit)) 70 /* 71 * The total number of consistent resources available. 72 * which is the total memory size divided by the smallest resource size 73 */ 74 #define L3_ECMP_TOTAL_NOF_CONSISTENT_RESOURCES(unit) ((dnx_data_l3.ecmp.consistent_mem_row_size_in_bits_get(unit)*(1 << dnx_data_l3.ecmp.member_table_nof_rows_size_in_bits_get(unit))) / L3_ECMP_CONSISTENT_TABLE_SIZE_IN_BITS(unit,DBAL_ENUM_FVAL_ECMP_CONSISTENT_TABLE_SMALL_SIZE)) 75 76 /* 77 * The NOF members that a single row in the consistent memory contains depending on the table type 78 */ 79 #define L3_ECMP_CONSISTENT_NOF_MEMBERS_IN_MEM_ROW(unit,consistent_table_type) (dnx_data_l3.ecmp.consistent_mem_row_size_in_bits_get(unit)/dnx_data_l3.ecmp.consistent_tables_info_get(unit,consistent_table_type)->entry_size_in_bits) 80 /* 81 * The number of rows that a consistent table takes in the member table memory. 82 * The table address is calculated using this size 83 */ 84 #define L3_ECMP_CONSISTENT_NOF_ROWS_IN_MEMBER_TABLE(unit,consistent_table_type) (dnx_data_l3.ecmp.consistent_tables_info_get(unit,consistent_table_type)->nof_entries / L3_ECMP_CONSISTENT_NOF_MEMBERS_IN_MEM_ROW(unit,consistent_table_type)) 85 86 /* 87 * The size in bits that a consistent table takes from the member table memory 88 */ 89 #define L3_ECMP_CONSISTENT_TABLE_SIZE_IN_BITS(unit,consistent_table_type) (dnx_data_l3.ecmp.consistent_tables_info_get(unit,consistent_table_type)->entry_size_in_bits*dnx_data_l3.ecmp.consistent_tables_info_get(unit,consistent_table_type)->nof_entries) 90 91 /* 92 * The smallest table size is the base resource and each table should be some multiplication of that table which is the NOF 93 * resources that that table takes. 94 */ 95 #define L3_ECMP_CONSISTENT_NOF_RESOURCES_TAKEN(unit,consistent_table_type) (L3_ECMP_CONSISTENT_TABLE_SIZE_IN_BITS(unit,consistent_table_type) / L3_ECMP_CONSISTENT_TABLE_SIZE_IN_BITS(unit,DBAL_ENUM_FVAL_ECMP_CONSISTENT_TABLE_SMALL_SIZE)) 96 97 /* 98 * the consistent hashing manager unique key is composed from the profile id and the hierarchy. 99 * This MACRO creates it 100 */ 101 #define L3_ECMP_CHM_KEY_GET(unit, profile_id, hierarchy) (((profile_id & L3_ECMP_PROFILE_ID_FIELD_MASK(unit)) << dnx_data_l3.ecmp.profile_id_offset_get(unit)) | ((hierarchy & L3_ECMP_HIERARCHY_FIELD_MASK) << L3_ECMP_HIERARCHY_FIELD_OFFSET(unit)) ) 102 /* 103 * TP mode has 4 values and each of them require a different NOF consistent tables 104 * MODE NOF tables 105 * 0 1 106 * 1 2 107 * 2 4 108 * 3 8 109 */ 110 #define L3_ECMP_NOF_CONSISTENT_TABLES_REQUIRED_BY_TP_MODE(tp_mode) (1 << tp_mode) 111 112 /* 113 * } 114 */ 115 /* 116 * Globals 117 * { 118 */ 119 120 /* 121 * } 122 */ 123 /* 124 * Structures 125 * { 126 */ 127 128 /* 129 * This structure holds all the ECMP profile fields which match the HW profile. 130 * This profile is used as a key for the template manager for profile allocations. 131 */ 132 typedef struct 133 { 134 /* 135 * Statistic object id 136 */ 137 uint32 statistic_object_id; 138 /* 139 * Statistic object profile 140 */ 141 uint8 statistic_object_profile; 142 /* 143 * The hashing mode (see dbal_enum_value_field_ecmp_mode_e enumeration for more details) 144 */ 145 dbal_enum_value_field_ecmp_mode_e ecmp_mode; 146 /* 147 * Identification of the consistent members table allocation. 148 * In case the actual NOF members equal the group size this value isn't important as a general table for the "group size" is used. 149 * In case NOF members is smaller than the group size, a special members table is used for this group and it's indentified 150 * by this value which will be the ECMP ID for simplification. 151 */ 152 uint32 members_table_id; 153 /* 154 * The ECMP group size (the maximal size of the group) 155 */ 156 uint32 group_size; 157 /* 158 * Indicate if this ECMP is statful or not 159 */ 160 uint8 stateful; 161 /* 162 * Is this ECMP group point to a group of protected FECs 163 */ 164 uint8 protection_flag; 165 166 /* 167 * Tunnel Priority mode. 168 */ 169 bcm_l3_ecmp_tunnel_priority_mode_t tunnel_priority_mode; 170 /* 171 * Tunnel Priority Map profile. 172 */ 173 uint8 tunnel_priority_map_profile; 174 175 /* 176 * The ECMP RPF mode 177 */ 178 dbal_enum_value_field_ecmp_rpf_mode_e rpf_mode; 179 } dnx_l3_ecmp_profile_t; 180 181 /* 182 * Holds the ECMP attributes 183 */ 184 typedef struct 185 { 186 /* 187 * The ECMP group base FEC. 188 */ 189 uint32 fec_base; 190 /* 191 * The index of the ECMP profile in the ECMP profile table 192 */ 193 uint32 profile_index; 194 /* 195 * A bit that is set to 1 in case the ECMP RPF more is EM. 196 */ 197 uint8 is_rpf_mode_em; 198 } dnx_l3_ecmp_attributes_t; 199 /* 200 * } 201 */ 202 /* 203 * Externs 204 * { 205 */ 206 207 /* 208 * } 209 */ 210 /* 211 * Function declaration 212 * { 213 */ 214 215 /** 216 * \brief 217 * Convert ECMP mode into consistent table type. 218 * \param [in] unit - 219 * The unit number. 220 * \param [in] ecmp_mode - 221 * The ECMP mode (see dbal_enum_value_field_ecmp_mode_e for more details). 222 * \param [out] consistent_table_type - 223 * The consistent table type (see dbal_enum_value_field_ecmp_consistent_table_e for more details). 224 * \return 225 * \retval Zero if no error was detected 226 * \retval Negative if error was detected. See \ref shr_error_e 227 */ 228 shr_error_e dnx_l3_ecmp_consistent_table_type_from_ecmp_mode_get( 229 int unit, 230 dbal_enum_value_field_ecmp_mode_e ecmp_mode, 231 dbal_enum_value_field_ecmp_consistent_table_e * consistent_table_type); 232 233 /** 234 * \brief 235 * Returns the hierarchy ECMP profiles template manager handle name. 236 * \param [in] unit - 237 * The unit number. 238 * \param [in] hierarchy - 239 * The hierarchy of the requested ECMP profile resource handle name. 240 * \param [out] profile_resouce - 241 * the returned name of the ECMP profiles resource name. 242 * \return 243 * \retval Zero if no error was detected 244 * \retval Negative if error was detected. See \ref shr_error_e 245 */ 246 shr_error_e dnx_l3_ecmp_hierarchy_profile_resource_get( 247 int unit, 248 dbal_enum_value_field_hierarchy_level_e hierarchy, 249 char **profile_resouce); 250 251 /** 252 * \brief 253 * A consistent hashing manager CB. 254 * Returns the amount of resource needed for a given profile type. 255 * \param [in] unit - 256 * The unit number. 257 * \param [in] profile_type - 258 * the consistent table type (small, medium or large). 259 * \param [out] nof_resources - 260 * returns the NOF resources that the profile type consume. 261 * \return 262 * \retval Zero if no error was detected 263 * \retval Negative if error was detected. See \ref shr_error_e 264 */ 265 shr_error_e ecmp_chm_get_nof_resources_from_table_size( 266 int unit, 267 int profile_type, 268 uint32 *nof_resources); 269 /** 270 * \brief 271 * A consistent hashing manager CB. 272 * Returns a profile type that matches NOF resources. 273 * \param [in] unit - 274 * The unit number. 275 * \param [in] nof_resources - 276 * returns the NOF resources that the profile type consume. 277 * \param [out] profile_type - 278 * returns the consistent table type (small, medium or large). 279 * \return 280 * \retval Zero if no error was detected 281 * \retval Negative if error was detected. See \ref shr_error_e 282 */ 283 shr_error_e ecmp_chm_get_table_size_from_nof_resources( 284 int unit, 285 uint32 nof_resources, 286 int *profile_type); 287 /** 288 * \brief 289 * A consistent hashing manager CB. 290 * Gets a resource number which is used to locate the relevant HW members table and returns that members offsets that were found. 291 * table in the HW. 292 * \param [in] unit - 293 * The unit number. 294 * \param [in] chm_offset - 295 * row in the ECMP members table. 296 * \param [in ] calendar - 297 * Holds the type of the member table and an array of members to be updated from the HW. 298 * \return 299 * \retval Zero if no error was detected 300 * \retval Negative if error was detected. See \ref shr_error_e 301 */ 302 shr_error_e ecmp_chm_members_table_set( 303 int unit, 304 uint32 chm_offset, 305 consistent_hashing_calendar_t * calendar); 306 /** 307 * \brief 308 * A consistent hashing manager CB. 309 * Update the array of members offset (placed in calendar) from members offset that read from the HW. 310 * \param [in] unit - 311 * The unit number. 312 * \param [in] chm_offset - 313 * row in the ECMP members table. 314 * \param [out] calendar - 315 * Holds the type of the member table and an array of members to be filled from the ECMP members table. 316 * \return 317 * \retval Zero if no error was detected 318 * \retval Negative if error was detected. See \ref shr_error_e 319 */ 320 shr_error_e ecmp_chm_members_table_get( 321 int unit, 322 uint32 chm_offset, 323 consistent_hashing_calendar_t * calendar); 324 325 /** 326 * \brief 327 * A consistent hashing manager (chm) CB. 328 * Sometimes the CHM moves tables inside the ECMP members memory banks for fragmentation reasons in the HW member table. 329 * This function moves a single table from one place in the memory to a new position. 330 * \param [in] unit - 331 * The unit number. 332 * \param [in] old_offset - 333 * The address of the table that should be moved into a new address. 334 * \param [in ] new_offset - 335 * The new address of the table that is placed in the old_offset. 336 * \param [in] profile_type - 337 * the consistent table type (small, medium or large). 338 * \param [in] nof_consecutive_profiles - 339 * the number of consecutive profiles. 340 * \return 341 * \retval Zero if no error was detected 342 * \retval Negative if error was detected. See \ref shr_error_e 343 */ 344 shr_error_e ecmp_chm_update_members_table_offset( 345 int unit, 346 uint32 old_offset, 347 uint32 new_offset, 348 int profile_type, 349 uint32 nof_consecutive_profiles); 350 /** 351 * \brief 352 * A consistent hashing manager CB. 353 * Once the consistent hashing manger allocated a resource, an address (resulted from the allocated resource) 354 * should be update in the profile of the calling ECMP. 355 * So basicly this function updates the "member base address" in the ECMP profile. 356 * \param [in] unit - 357 * The unit number. 358 * \param [in] chm_handle - 359 * consistent hashing manager handle. 360 * \param [in ] unique_identifyer - 361 * this is the profile ID and hierarchy. 362 * \param [in] chm_offset - 363 * address in the ECMP members table. 364 * \param [in] user_info - 365 * additional user info. 366 * \return 367 * \retval Zero if no error was detected 368 * \retval Negative if error was detected. See \ref shr_error_e 369 */ 370 shr_error_e ecmp_chm_update_ecmp_profile_with_members_table_offset( 371 int unit, 372 uint32 chm_handle, 373 uint32 unique_identifyer, 374 uint32 chm_offset, 375 void *user_info); 376 377 /** 378 * \brief 379 * A consistent hashing manager CB. 380 * Given a profile ID (unique_identifyer) the resource offset (chm_offset) that calculate from the ECMP profile is returned. 381 * \param [in] unit - 382 * The unit number. 383 * \param [in ] unique_identifyer - 384 * this is the profile ID and hierarchy 385 * \param [out] chm_offset - 386 * address in the ECMP members table to be returned. 387 * \return 388 * \retval Zero if no error was detected 389 * \retval Negative if error was detected. See \ref shr_error_e 390 */ 391 shr_error_e ecmp_chm_members_table_offset_get( 392 int unit, 393 uint32 unique_identifyer, 394 uint32 *chm_offset); 395 396 /** 397 * \brief 398 * A consistent hashing manager CB. 399 * Returns the actual NOF entries that a table uses (the tables doesn't always use all of their entries) 400 * \param [in] unit - 401 * The unit number. 402 * \param [in ] profile_type - 403 * the consistent table type (small, medium or large). 404 * \param [in] max_nof_members_in_profile - 405 * This is the max size of the ECMP group (not the table). 406 * \param [out] nof_calendar_entries - 407 * pointer to the returned value which is the NOF relevant members in the table. 408 * \return 409 * \retval Zero if no error was detected 410 * \retval Negative if error was detected. See \ref shr_error_e 411 */ 412 shr_error_e ecmp_chm_entries_in_profile_get_cb( 413 int unit, 414 int profile_type, 415 uint32 max_nof_members_in_profile, 416 uint32 *nof_calendar_entries); 417 418 /** 419 * \brief 420 * Return all the relevant information that a single ECMP group holds including the interface array. 421 * \param [in] unit - 422 * The unit number. 423 * \param [in] ecmp_index - 424 * The ECMP ID. 425 * \param [in] tp_table_index - 426 * the tunnel priority (TP) table index, in case TP isn't use this parameter should be set to 0. 427 * \param [out] member_count - 428 * pointer that receive the NOF members in the group 429 * \param [out] intf_array - 430 * Array of the group members 431 * \param [out] ecmp_profile - 432 * pointer that returns the attributes of the ECMP profile 433 */ 434 shr_error_e dnx_l3_egress_ecmp_get_ecmp_group_info( 435 int unit, 436 bcm_if_t ecmp_index, 437 int tp_table_index, 438 int *member_count, 439 bcm_if_t * intf_array, 440 dnx_l3_ecmp_profile_t * ecmp_profile); 441 442 /** 443 * \brief 444 * This function find an ECMP group profile based on the ECMP ID. 445 * \param [in] unit - 446 * The unit number. 447 * \param [in] ecmp_intf - 448 * The ECMP group ID. 449 * \param [out] ecmp_atr - 450 * The ECMP group attributes 451 * \return 452 * \retval Zero if no error was detected 453 * \retval Negative if error was detected. See \ref shr_error_e 454 * \see 455 * * bcm_dnx_l3_egress_ecmp_get 456 * * bcm_dnx_l3_egress_ecmp_destroy 457 * * bcm_dnx_l3_egress_ecmp_add 458 * * bcm_dnx_l3_egress_ecmp_delete 459 */ 460 shr_error_e dnx_l3_ecmp_group_entry_result_get( 461 int unit, 462 bcm_if_t ecmp_intf, 463 dnx_l3_ecmp_attributes_t * ecmp_atr); 464 /* 465 * } 466 */ 467 #endif /* L3_ECMP_H_INCLUDED */