flex_ctr_ingress.c (71122B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: flex_ctr_ingress.c 8 * Purpose: Manage flex counter ingress group creation and deletion 9 */ 10 11 #include <shared/bsl.h> 12 13 #include <bcm_int/esw/flex_ctr.h> 14 15 static soc_reg_t _ingress_pkt_selector_key_reg[] = { 16 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_0r, 17 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_1r, 18 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_2r, 19 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_3r, 20 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_4r, 21 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_5r, 22 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_6r, 23 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_7r, 24 #if defined(BCM_TRIUMPH3_SUPPORT) || defined(BCM_TOMAHAWK_SUPPORT) || defined (BCM_APACHE_SUPPORT) 25 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_8r, 26 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_9r, 27 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_10r, 28 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_11r, 29 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_12r, 30 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_13r, 31 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_14r, 32 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_15r, 33 #endif 34 #if defined(BCM_TOMAHAWK_SUPPORT) || defined (BCM_APACHE_SUPPORT) 35 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_16r, 36 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_17r, 37 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_18r, 38 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_19r, 39 #endif 40 #if defined (BCM_APACHE_SUPPORT) 41 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_20r, 42 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_21r, 43 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_22r, 44 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_23r, 45 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_24r, 46 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_25r, 47 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_26r, 48 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_27r, 49 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_28r, 50 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_29r, 51 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_30r, 52 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_31r 53 #endif 54 }; 55 56 #define NUM_ING_KEYS_APACHE 8 57 #define NUM_ING_KEYS_TOMAHAWK 4 58 #define NUM_ING_KEYS_DEFAULT 2 59 #define NUM_ING_KEYS_METROLITE 1 60 #define NUM_ING_KEYS_TRIUMPH3 4 61 62 /* Getting the number ingress keys for the device */ 63 #define GET_NUM_UNCOMP_ING_KEYS(num, unit) \ 64 if (SOC_IS_APACHE(unit)) { \ 65 num = NUM_ING_KEYS_APACHE ; \ 66 } else if (SOC_IS_METROLITE(unit)) { \ 67 num = NUM_ING_KEYS_METROLITE ; \ 68 } else if (SOC_IS_TOMAHAWKX(unit) || SOC_IS_TRIDENT3X(unit)) { \ 69 num = NUM_ING_KEYS_TOMAHAWK ; \ 70 } else if (SOC_IS_TRIUMPH3(unit) && !SOC_IS_HELIX4(unit)) { \ 71 num = NUM_ING_KEYS_TRIUMPH3; \ 72 } else { \ 73 num = NUM_ING_KEYS_DEFAULT ; \ 74 } 75 76 #define GET_NUM_COMP_ING_KEYS(num, unit) \ 77 if (SOC_IS_APACHE(unit)) { \ 78 num = NUM_ING_KEYS_APACHE ; \ 79 } else if (SOC_IS_METROLITE(unit)) { \ 80 num = NUM_ING_KEYS_METROLITE ; \ 81 } else if (SOC_IS_TRIUMPH3(unit) && !SOC_IS_HELIX4(unit)) { \ 82 num = NUM_ING_KEYS_TRIUMPH3; \ 83 } else { \ 84 num = NUM_ING_KEYS_DEFAULT ; \ 85 } 86 87 /* 88 * Function: 89 * _bcm_esw_stat_flex_update_ingress_selector_keys 90 * Description: 91 * Update flex ingress selector keys 92 * Parameters: 93 * unit - (IN) unit number 94 * pkt_attr_type - (IN) Flex Packet Attribute Type 95 * pkt_selector_key_reg - (IN) Flex Packet Attribute selector key register 96 * pkt_attr_bits - (IN) Flex Packet Attribute Bits 97 * Return Value: 98 * BCM_E_XXX 99 * Notes: 100 */ 101 static bcm_error_t 102 _bcm_esw_stat_flex_update_ingress_selector_keys( 103 int unit, 104 bcm_stat_flex_packet_attr_type_t pkt_attr_type, 105 soc_reg_t pkt_selector_key_reg, 106 bcm_stat_flex_ing_pkt_attr_bits_t pkt_attr_bits) 107 { 108 uint64 pkt_selector_key_reg_value, val64; 109 uint8 current_bit_position = 0; 110 uint8 index = 0; 111 int num_pkt_sel_key_reg = COUNTOF(_ingress_pkt_selector_key_reg); 112 113 COMPILER_64_ZERO(pkt_selector_key_reg_value); 114 COMPILER_64_ZERO(val64); 115 116 for (index = 0; index < num_pkt_sel_key_reg; index++) { 117 if (pkt_selector_key_reg == _ingress_pkt_selector_key_reg[index]) { 118 break; 119 } 120 } 121 if (index == num_pkt_sel_key_reg) { 122 return BCM_E_PARAM; 123 } 124 /* bcmStatFlexPacketAttrTypeUdf not supported here */ 125 if (!((pkt_attr_type==bcmStatFlexPacketAttrTypeUncompressed) || 126 (pkt_attr_type==bcmStatFlexPacketAttrTypeCompressed))) { 127 return BCM_E_PARAM; 128 } 129 /* Valid register value go ahead for setting 130 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_?r:SELECTOR_KEY field */ 131 132 /* First Get complete value of ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_?r value*/ 133 SOC_IF_ERROR_RETURN(soc_reg_get(unit, 134 pkt_selector_key_reg, 135 REG_PORT_ANY, 136 0, 137 &pkt_selector_key_reg_value)); 138 139 /* Next set field value for 140 ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_?r:SELECTOR_KEY field*/ 141 soc_reg64_field_set(unit, 142 pkt_selector_key_reg, 143 &pkt_selector_key_reg_value, 144 USER_SPECIFIED_UDF_VALIDf, 145 val64); 146 soc_reg64_field_set(unit, 147 pkt_selector_key_reg, 148 &pkt_selector_key_reg_value, 149 USE_UDF_KEYf, 150 val64); 151 if (soc_reg_field_valid(unit, pkt_selector_key_reg, USE_COMPRESSED_PKT_KEYf)) { 152 if (pkt_attr_type==bcmStatFlexPacketAttrTypeCompressed) { 153 COMPILER_64_SET(val64, 0, 1); 154 soc_reg64_field_set(unit, 155 pkt_selector_key_reg, 156 &pkt_selector_key_reg_value, 157 USE_COMPRESSED_PKT_KEYf, 158 val64); 159 }else { 160 soc_reg64_field_set(unit, 161 pkt_selector_key_reg, 162 &pkt_selector_key_reg_value, 163 USE_COMPRESSED_PKT_KEYf, 164 val64); 165 } 166 } 167 if (pkt_attr_bits.ip_pkt != 0) { 168 BCM_IF_ERROR_RETURN( 169 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 170 unit, 171 pkt_selector_key_reg, 172 &pkt_selector_key_reg_value, 173 /* IP_PKT bit position */ 174 pkt_attr_bits.ip_pkt_pos, 175 /* 1:IP_PKT total bits */ 176 pkt_attr_bits.ip_pkt, 177 pkt_attr_bits.ip_pkt_mask, 178 ¤t_bit_position)); 179 } 180 if (pkt_attr_bits.drop != 0) { 181 BCM_IF_ERROR_RETURN( 182 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 183 unit, 184 pkt_selector_key_reg, 185 &pkt_selector_key_reg_value, 186 /* DROP bit position */ 187 pkt_attr_bits.drop_pos, 188 /*1:DROP total bits */ 189 pkt_attr_bits.drop, 190 pkt_attr_bits.drop_mask, 191 ¤t_bit_position)); 192 } 193 if (pkt_attr_bits.svp_type != 0) { 194 BCM_IF_ERROR_RETURN( 195 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 196 unit, 197 pkt_selector_key_reg, 198 &pkt_selector_key_reg_value, 199 /*SVP_TYPE bit position*/ 200 pkt_attr_bits.svp_type_pos, 201 /*1:SVP_TYPE total bits */ 202 pkt_attr_bits.svp_type, 203 pkt_attr_bits.svp_type_mask, 204 ¤t_bit_position)); 205 } 206 if (pkt_attr_bits.pkt_resolution != 0) { 207 BCM_IF_ERROR_RETURN( 208 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 209 unit, 210 pkt_selector_key_reg, 211 &pkt_selector_key_reg_value, 212 /*PKT_RESOLUTION bit position*/ 213 pkt_attr_bits.pkt_resolution_pos, 214 /*6:SVP_TYPE total bits */ 215 pkt_attr_bits.pkt_resolution, 216 pkt_attr_bits.pkt_resolution_mask, 217 ¤t_bit_position)); 218 } 219 if (pkt_attr_bits.tos_dscp != 0) { 220 BCM_IF_ERROR_RETURN( 221 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 222 unit, 223 pkt_selector_key_reg, 224 &pkt_selector_key_reg_value, 225 /*TOS bit position*/ 226 pkt_attr_bits.tos_dscp_pos, 227 /*8:TOS total bits */ 228 pkt_attr_bits.tos_dscp, 229 pkt_attr_bits.tos_dscp_mask, 230 ¤t_bit_position)); 231 } 232 if (pkt_attr_bits.tos_ecn != 0) { 233 BCM_IF_ERROR_RETURN( 234 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 235 unit, 236 pkt_selector_key_reg, 237 &pkt_selector_key_reg_value, 238 /*TOS bit position*/ 239 pkt_attr_bits.tos_ecn_pos, 240 /*8:TOS total bits */ 241 pkt_attr_bits.tos_ecn, 242 pkt_attr_bits.tos_ecn_mask, 243 ¤t_bit_position)); 244 } 245 if (pkt_attr_bits.ing_port != 0) { 246 BCM_IF_ERROR_RETURN( 247 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 248 unit, 249 pkt_selector_key_reg, 250 &pkt_selector_key_reg_value, 251 /*ING_PORT bit position*/ 252 pkt_attr_bits.ing_port_pos, 253 /*6:ING_PORT total bits */ 254 pkt_attr_bits.ing_port, 255 pkt_attr_bits.ing_port_mask, 256 ¤t_bit_position)); 257 } 258 if (pkt_attr_bits.inner_dot1p != 0) { 259 BCM_IF_ERROR_RETURN( 260 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 261 unit, 262 pkt_selector_key_reg, 263 &pkt_selector_key_reg_value, 264 /*INNER_DOT1P bit position*/ 265 pkt_attr_bits.inner_dot1p_pos, 266 /*3:INNER_DOT1P total bits */ 267 pkt_attr_bits.inner_dot1p, 268 pkt_attr_bits.inner_dot1p_mask, 269 ¤t_bit_position)); 270 } 271 if (pkt_attr_bits.outer_dot1p != 0) { 272 BCM_IF_ERROR_RETURN( 273 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 274 unit, 275 pkt_selector_key_reg, 276 &pkt_selector_key_reg_value, 277 /*OUTER_DOT1P bit position*/ 278 pkt_attr_bits.outer_dot1p_pos, 279 /*3:OUTER_DOT1P total bits */ 280 pkt_attr_bits.outer_dot1p, 281 pkt_attr_bits.outer_dot1p_mask, 282 ¤t_bit_position)); 283 } 284 if (pkt_attr_bits.vlan_format != 0) { 285 BCM_IF_ERROR_RETURN( 286 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 287 unit, 288 pkt_selector_key_reg, 289 &pkt_selector_key_reg_value, 290 /*VLAN_FORMAT bit position*/ 291 pkt_attr_bits.vlan_format_pos, 292 /*2:VLAN_FORMAT total bits */ 293 pkt_attr_bits.vlan_format, 294 pkt_attr_bits.vlan_format_mask, 295 ¤t_bit_position)); 296 } 297 if (pkt_attr_bits.int_pri != 0) { 298 BCM_IF_ERROR_RETURN( 299 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 300 unit, 301 pkt_selector_key_reg, 302 &pkt_selector_key_reg_value, 303 /*INT_PRI bit position*/ 304 pkt_attr_bits.int_pri_pos, 305 /*4:INT_PRI total bits */ 306 pkt_attr_bits.int_pri, 307 pkt_attr_bits.int_pri_mask, 308 ¤t_bit_position)); 309 } 310 if (pkt_attr_bits.ifp_cng != 0) { 311 BCM_IF_ERROR_RETURN( 312 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 313 unit, 314 pkt_selector_key_reg, 315 &pkt_selector_key_reg_value, 316 /*IFP_CNG bit position*/ 317 pkt_attr_bits.ifp_cng_pos, 318 /*2:IFP_CNG total bits */ 319 pkt_attr_bits.ifp_cng, 320 pkt_attr_bits.ifp_cng_mask, 321 ¤t_bit_position)); 322 } 323 if (pkt_attr_bits.cng != 0) { 324 BCM_IF_ERROR_RETURN( 325 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 326 unit, 327 pkt_selector_key_reg, 328 &pkt_selector_key_reg_value, 329 /*CNG bit position*/ 330 pkt_attr_bits.cng_pos, 331 /*2:CNG total bits */ 332 pkt_attr_bits.cng, 333 pkt_attr_bits.cng_mask, 334 ¤t_bit_position)); 335 } 336 #ifdef BCM_APACHE_SUPPORT 337 if (soc_feature(unit,soc_feature_flex_ctr_mpls_3_label_count)) { 338 if (pkt_attr_bits.phb_1 != 0) { 339 BCM_IF_ERROR_RETURN( 340 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 341 unit, 342 pkt_selector_key_reg, 343 &pkt_selector_key_reg_value, 344 /* bit position */ 345 pkt_attr_bits.phb_1_pos, /* */ 346 /* total bits */ 347 pkt_attr_bits.phb_1, 348 pkt_attr_bits.phb_1_mask, 349 ¤t_bit_position)); 350 } 351 if (pkt_attr_bits.cng_1 != 0) { 352 BCM_IF_ERROR_RETURN( 353 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 354 unit, 355 pkt_selector_key_reg, 356 &pkt_selector_key_reg_value, 357 /* bit position */ 358 pkt_attr_bits.cng_1_pos, /* */ 359 /* total bits */ 360 pkt_attr_bits.cng_1, 361 pkt_attr_bits.cng_1_mask, 362 ¤t_bit_position)); 363 } 364 if (pkt_attr_bits.phb_2 != 0) { 365 BCM_IF_ERROR_RETURN( 366 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 367 unit, 368 pkt_selector_key_reg, 369 &pkt_selector_key_reg_value, 370 /* bit position */ 371 pkt_attr_bits.phb_2_pos, /* */ 372 /* total bits */ 373 pkt_attr_bits.phb_2, 374 pkt_attr_bits.phb_2_mask, 375 ¤t_bit_position)); 376 } 377 if (pkt_attr_bits.cng_2 != 0) { 378 BCM_IF_ERROR_RETURN( 379 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 380 unit, 381 pkt_selector_key_reg, 382 &pkt_selector_key_reg_value, 383 /* bit position */ 384 pkt_attr_bits.cng_2_pos, /* */ 385 /* total bits */ 386 pkt_attr_bits.cng_2, 387 pkt_attr_bits.cng_2_mask, 388 ¤t_bit_position)); 389 } 390 if (pkt_attr_bits.phb_3 != 0) { 391 BCM_IF_ERROR_RETURN( 392 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 393 unit, 394 pkt_selector_key_reg, 395 &pkt_selector_key_reg_value, 396 /* bit position */ 397 pkt_attr_bits.phb_3_pos, /* */ 398 /* total bits */ 399 pkt_attr_bits.phb_3, 400 pkt_attr_bits.phb_3_mask, 401 ¤t_bit_position)); 402 } 403 if (pkt_attr_bits.cng_3 != 0) { 404 BCM_IF_ERROR_RETURN( 405 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 406 unit, 407 pkt_selector_key_reg, 408 &pkt_selector_key_reg_value, 409 /* bit position */ 410 pkt_attr_bits.cng_3_pos, /* */ 411 /* total bits */ 412 pkt_attr_bits.cng_3, 413 pkt_attr_bits.cng_3_mask, 414 ¤t_bit_position)); 415 } 416 } 417 #endif 418 if (soc_feature(unit, soc_feature_flex_stat_ing_tcp_flags_support)) { 419 if (pkt_attr_bits.tcp_flags != 0) { 420 BCM_IF_ERROR_RETURN( 421 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 422 unit, 423 pkt_selector_key_reg, 424 &pkt_selector_key_reg_value, 425 /* bit position */ 426 pkt_attr_bits.tcp_flags_pos, /* */ 427 /* total bits */ 428 pkt_attr_bits.tcp_flags, 429 pkt_attr_bits.tcp_flags_mask, 430 ¤t_bit_position)); 431 } 432 } 433 if (soc_feature(unit, soc_feature_flex_stat_int_cn_support)) { 434 if (pkt_attr_bits.int_cn != 0) { 435 BCM_IF_ERROR_RETURN( 436 _bcm_esw_stat_flex_update_selector_keys_enable_fields( 437 unit, 438 pkt_selector_key_reg, 439 &pkt_selector_key_reg_value, 440 /* bit position */ 441 pkt_attr_bits.int_cn_pos, /* */ 442 /* total bits */ 443 pkt_attr_bits.int_cn, 444 pkt_attr_bits.int_cn_mask, 445 ¤t_bit_position)); 446 } 447 } 448 /* Finally set value for ING_FLEX_CTR_PKT_ATTR_SELECTOR_KEY_?r */ 449 SOC_IF_ERROR_RETURN(soc_reg_set(unit, 450 pkt_selector_key_reg, 451 REG_PORT_ANY, 452 0, 453 pkt_selector_key_reg_value)); 454 return BCM_E_NONE; 455 } 456 457 /* 458 * Function: 459 * _bcm_esw_stat_flex_create_ingress_uncompress_mode 460 * Description: 461 * Creates New Flex Ingress Uncompressed Mode 462 * 463 * Parameters: 464 * unit - (IN) unit number 465 * uncmprsd_attr_selectors - (IN) Flex attributes 466 * mode - (OUT) Flex mode 467 * total_counters - (OUT) Total Counters associated with new 468 * flex uncompressed mode 469 * 470 * Return Value: 471 * BCM_E_XXX 472 * Notes: 473 */ 474 static bcm_error_t 475 _bcm_esw_stat_flex_create_ingress_uncompress_mode( 476 int unit, 477 bcm_stat_flex_ing_uncmprsd_attr_selectors_t *uncmprsd_attr_selectors, 478 bcm_stat_flex_mode_t *mode, 479 uint32 *total_counters) 480 { 481 bcm_stat_flex_mode_t mode_l=0; 482 bcm_stat_flex_ing_pkt_attr_bits_t pkt_attr_bits={0}; 483 uint32 total_ingress_bits=0; 484 uint32 index=0; 485 bcm_stat_flex_ingress_mode_t *flex_ingress_mode=NULL; 486 bcm_stat_flex_ing_uncmprsd_attr_selectors_t uncmprsd_attr_selectors_l; 487 uint32 num_flex_ingress_pools; 488 int num_pkt_sel_key; 489 490 num_flex_ingress_pools = SOC_INFO(unit).num_flex_ingress_pools; 491 492 flex_ingress_mode = sal_alloc(sizeof(bcm_stat_flex_ingress_mode_t), 493 "flex_ingress_mode"); 494 if (flex_ingress_mode == NULL) { 495 return BCM_E_MEMORY; 496 } 497 498 sal_memset(flex_ingress_mode, 0, sizeof(bcm_stat_flex_ingress_mode_t)); 499 500 for (index =0; index < BCM_STAT_FLEX_COUNTER_MAX_MODE; index++) { 501 if (_bcm_esw_stat_flex_get_ingress_mode_info( 502 unit, 503 index, 504 flex_ingress_mode) == BCM_E_NONE) { 505 if (flex_ingress_mode->ing_attr.packet_attr_type != 506 bcmStatFlexPacketAttrTypeUncompressed) { 507 continue; 508 } 509 uncmprsd_attr_selectors_l = flex_ingress_mode->ing_attr. 510 uncmprsd_attr_selectors; 511 if ((flex_ingress_mode->total_counters == 512 uncmprsd_attr_selectors->total_counters) && 513 (sal_memcmp(&uncmprsd_attr_selectors_l,uncmprsd_attr_selectors, 514 sizeof(uncmprsd_attr_selectors_l)) == 0)) { 515 *total_counters = flex_ingress_mode->total_counters; 516 *mode=index; 517 sal_free(flex_ingress_mode); 518 return BCM_E_EXISTS; 519 } 520 } 521 } 522 sal_free(flex_ingress_mode); 523 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_get_available_mode( 524 unit, 525 bcmStatFlexDirectionIngress, 526 &mode_l)); 527 /* Step2: Packet Attribute selection */ 528 #ifdef BCM_APACHE_SUPPORT 529 if (soc_feature(unit,soc_feature_flex_ctr_mpls_3_label_count)) { 530 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 531 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_CNG_3_ATTR_BITS) { 532 pkt_attr_bits.cng_3 = ing_pkt_attr_uncmprsd_bits_g[unit].cng_3; 533 pkt_attr_bits.cng_3_mask = ing_pkt_attr_uncmprsd_bits_g[unit].cng_3_mask; 534 pkt_attr_bits.cng_3_pos = ing_pkt_attr_uncmprsd_bits_g[unit].cng_3_pos; 535 total_ingress_bits += pkt_attr_bits.cng_3; 536 } 537 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 538 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_PHB_3_ATTR_BITS) { 539 pkt_attr_bits.phb_3 = ing_pkt_attr_uncmprsd_bits_g[unit].phb_3; 540 pkt_attr_bits.phb_3_mask = ing_pkt_attr_uncmprsd_bits_g[unit].phb_3_mask; 541 pkt_attr_bits.phb_3_pos = ing_pkt_attr_uncmprsd_bits_g[unit].phb_3_pos; 542 total_ingress_bits += pkt_attr_bits.phb_3; 543 } 544 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 545 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_CNG_2_ATTR_BITS) { 546 pkt_attr_bits.cng_2 = ing_pkt_attr_uncmprsd_bits_g[unit].cng_2; 547 pkt_attr_bits.cng_2_mask = ing_pkt_attr_uncmprsd_bits_g[unit].cng_2_mask; 548 pkt_attr_bits.cng_2_pos = ing_pkt_attr_uncmprsd_bits_g[unit].cng_2_pos; 549 total_ingress_bits += pkt_attr_bits.cng_2; 550 } 551 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 552 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_PHB_2_ATTR_BITS) { 553 pkt_attr_bits.phb_2 = ing_pkt_attr_uncmprsd_bits_g[unit].phb_2; 554 pkt_attr_bits.phb_2_mask = ing_pkt_attr_uncmprsd_bits_g[unit].phb_2_mask; 555 pkt_attr_bits.phb_2_pos = ing_pkt_attr_uncmprsd_bits_g[unit].phb_2_pos; 556 total_ingress_bits += pkt_attr_bits.phb_2; 557 } 558 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 559 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_CNG_1_ATTR_BITS) { 560 pkt_attr_bits.cng_1 = ing_pkt_attr_uncmprsd_bits_g[unit].cng_1; 561 pkt_attr_bits.cng_1_mask = ing_pkt_attr_uncmprsd_bits_g[unit].cng_1_mask; 562 pkt_attr_bits.cng_1_pos = ing_pkt_attr_uncmprsd_bits_g[unit].cng_1_pos; 563 total_ingress_bits += pkt_attr_bits.cng_1; 564 } 565 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 566 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_PHB_1_ATTR_BITS) { 567 pkt_attr_bits.phb_1 = ing_pkt_attr_uncmprsd_bits_g[unit].phb_1; 568 pkt_attr_bits.phb_1_mask = ing_pkt_attr_uncmprsd_bits_g[unit].phb_1_mask; 569 pkt_attr_bits.phb_1_pos = ing_pkt_attr_uncmprsd_bits_g[unit].phb_1_pos; 570 total_ingress_bits += pkt_attr_bits.phb_1; 571 } 572 } 573 #endif 574 if (soc_feature(unit, soc_feature_flex_stat_ing_tcp_flags_support)) { 575 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 576 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_TCP_FLAG_ATTR_BITS) { 577 pkt_attr_bits.tcp_flags = ing_pkt_attr_uncmprsd_bits_g[unit].tcp_flags; 578 pkt_attr_bits.tcp_flags_mask = ing_pkt_attr_uncmprsd_bits_g[unit].tcp_flags_mask; 579 pkt_attr_bits.tcp_flags_pos = ing_pkt_attr_uncmprsd_bits_g[unit].tcp_flags_pos; 580 total_ingress_bits += pkt_attr_bits.tcp_flags; 581 } 582 } 583 if (soc_feature(unit, soc_feature_flex_stat_int_cn_support)) { 584 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 585 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_INT_CN_ATTR_BITS) { 586 pkt_attr_bits.int_cn = ing_pkt_attr_uncmprsd_bits_g[unit].int_cn; 587 pkt_attr_bits.int_cn_mask = ing_pkt_attr_uncmprsd_bits_g[unit].int_cn_mask; 588 pkt_attr_bits.int_cn_pos = ing_pkt_attr_uncmprsd_bits_g[unit].int_cn_pos; 589 total_ingress_bits += pkt_attr_bits.int_cn; 590 } 591 } 592 593 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 594 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_CNG_ATTR_BITS) { 595 pkt_attr_bits.cng = ing_pkt_attr_uncmprsd_bits_g[unit].cng; 596 pkt_attr_bits.cng_mask = ing_pkt_attr_uncmprsd_bits_g[unit].cng_mask; 597 pkt_attr_bits.cng_pos = ing_pkt_attr_uncmprsd_bits_g[unit].cng_pos; 598 total_ingress_bits +=pkt_attr_bits.cng; 599 } 600 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 601 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_IFP_CNG_ATTR_BITS) { 602 pkt_attr_bits.ifp_cng = ing_pkt_attr_uncmprsd_bits_g[unit].ifp_cng ; 603 pkt_attr_bits.ifp_cng_mask = ing_pkt_attr_uncmprsd_bits_g[unit].ifp_cng_mask; 604 pkt_attr_bits.ifp_cng_pos = ing_pkt_attr_uncmprsd_bits_g[unit].ifp_cng_pos; 605 total_ingress_bits +=pkt_attr_bits.ifp_cng; 606 } 607 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 608 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_INT_PRI_ATTR_BITS) { 609 pkt_attr_bits.int_pri = ing_pkt_attr_uncmprsd_bits_g[unit].int_pri ; 610 pkt_attr_bits.int_pri_mask = ing_pkt_attr_uncmprsd_bits_g[unit].int_pri_mask ; 611 pkt_attr_bits.int_pri_pos = ing_pkt_attr_uncmprsd_bits_g[unit].int_pri_pos ; 612 total_ingress_bits +=pkt_attr_bits.int_pri; 613 } 614 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 615 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_VLAN_FORMAT_ATTR_BITS) { 616 pkt_attr_bits.vlan_format = ing_pkt_attr_uncmprsd_bits_g[unit].vlan_format ; 617 pkt_attr_bits.vlan_format_mask = ing_pkt_attr_uncmprsd_bits_g[unit].vlan_format_mask ; 618 pkt_attr_bits.vlan_format_pos = ing_pkt_attr_uncmprsd_bits_g[unit].vlan_format_pos ; 619 total_ingress_bits +=pkt_attr_bits.vlan_format; 620 } 621 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 622 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_OUTER_DOT1P_ATTR_BITS) { 623 pkt_attr_bits.outer_dot1p = ing_pkt_attr_uncmprsd_bits_g[unit].outer_dot1p; 624 pkt_attr_bits.outer_dot1p_mask = ing_pkt_attr_uncmprsd_bits_g[unit].outer_dot1p_mask; 625 pkt_attr_bits.outer_dot1p_pos = ing_pkt_attr_uncmprsd_bits_g[unit].outer_dot1p_pos; 626 total_ingress_bits +=pkt_attr_bits.outer_dot1p; 627 } 628 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 629 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_INNER_DOT1P_ATTR_BITS) { 630 pkt_attr_bits.inner_dot1p = ing_pkt_attr_uncmprsd_bits_g[unit].inner_dot1p ; 631 pkt_attr_bits.inner_dot1p_mask = ing_pkt_attr_uncmprsd_bits_g[unit].inner_dot1p_mask ; 632 pkt_attr_bits.inner_dot1p_pos = ing_pkt_attr_uncmprsd_bits_g[unit].inner_dot1p_pos ; 633 total_ingress_bits += pkt_attr_bits.inner_dot1p; 634 } 635 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 636 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_INGRESS_PORT_ATTR_BITS) { 637 pkt_attr_bits.ing_port = ing_pkt_attr_uncmprsd_bits_g[unit].ing_port; 638 pkt_attr_bits.ing_port_mask = ing_pkt_attr_uncmprsd_bits_g[unit].ing_port_mask ; 639 pkt_attr_bits.ing_port_pos = ing_pkt_attr_uncmprsd_bits_g[unit].ing_port_pos ; 640 total_ingress_bits += pkt_attr_bits.ing_port; 641 } 642 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 643 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_TOS_DSCP_ATTR_BITS) { 644 pkt_attr_bits.tos_dscp = ing_pkt_attr_uncmprsd_bits_g[unit].tos_dscp ; 645 pkt_attr_bits.tos_dscp_mask = ing_pkt_attr_uncmprsd_bits_g[unit].tos_dscp_mask ; 646 pkt_attr_bits.tos_dscp_pos = ing_pkt_attr_uncmprsd_bits_g[unit].tos_dscp_pos ; 647 total_ingress_bits += pkt_attr_bits.tos_dscp; 648 } 649 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 650 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_TOS_ECN_ATTR_BITS) { 651 pkt_attr_bits.tos_ecn = ing_pkt_attr_uncmprsd_bits_g[unit].tos_ecn ; 652 pkt_attr_bits.tos_ecn_mask = ing_pkt_attr_uncmprsd_bits_g[unit].tos_ecn_mask ; 653 pkt_attr_bits.tos_ecn_pos = ing_pkt_attr_uncmprsd_bits_g[unit].tos_ecn_pos ; 654 total_ingress_bits += pkt_attr_bits.tos_ecn; 655 } 656 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 657 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_PKT_RESOLUTION_ATTR_BITS) { 658 pkt_attr_bits.pkt_resolution = ing_pkt_attr_uncmprsd_bits_g[unit].pkt_resolution ; 659 pkt_attr_bits.pkt_resolution_mask= ing_pkt_attr_uncmprsd_bits_g[unit]. 660 pkt_resolution_mask; 661 pkt_attr_bits.pkt_resolution_pos= ing_pkt_attr_uncmprsd_bits_g[unit]. 662 pkt_resolution_pos; 663 total_ingress_bits +=pkt_attr_bits.pkt_resolution ; 664 } 665 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 666 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_SVP_TYPE_ATTR_BITS) { 667 pkt_attr_bits.svp_type = ing_pkt_attr_uncmprsd_bits_g[unit].svp_type ; 668 pkt_attr_bits.svp_type_mask = ing_pkt_attr_uncmprsd_bits_g[unit].svp_type_mask ; 669 pkt_attr_bits.svp_type_pos = ing_pkt_attr_uncmprsd_bits_g[unit].svp_type_pos ; 670 total_ingress_bits +=pkt_attr_bits.svp_type; 671 } 672 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 673 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_DROP_ATTR_BITS) { 674 pkt_attr_bits.drop = ing_pkt_attr_uncmprsd_bits_g[unit].drop ; 675 pkt_attr_bits.drop_mask = ing_pkt_attr_uncmprsd_bits_g[unit].drop_mask ; 676 pkt_attr_bits.drop_pos = ing_pkt_attr_uncmprsd_bits_g[unit].drop_pos ; 677 total_ingress_bits += pkt_attr_bits.drop; 678 } 679 if (uncmprsd_attr_selectors->uncmprsd_attr_bits_selector & 680 BCM_STAT_FLEX_ING_UNCOMPRESSED_USE_IP_PKT_ATTR_BITS) { 681 pkt_attr_bits.ip_pkt = ing_pkt_attr_uncmprsd_bits_g[unit].ip_pkt ; 682 pkt_attr_bits.ip_pkt_mask = ing_pkt_attr_uncmprsd_bits_g[unit].ip_pkt_mask; 683 pkt_attr_bits.ip_pkt_pos = ing_pkt_attr_uncmprsd_bits_g[unit].ip_pkt_pos; 684 total_ingress_bits += pkt_attr_bits.ip_pkt; 685 } 686 if (total_ingress_bits > BCM_STAT_FLEX_MAX_PKT_ATTR_SEL_KEY_SIZE) { 687 return BCM_E_PARAM; 688 } 689 /* Step3: Packet Attribute filling */ 690 691 /* APACHE supports 4 pkt keys per pool */ 692 GET_NUM_UNCOMP_ING_KEYS(num_pkt_sel_key, unit); 693 for (index = 0; index < num_pkt_sel_key ; index++) { 694 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_update_ingress_selector_keys(unit, 695 bcmStatFlexPacketAttrTypeUncompressed, 696 _ingress_pkt_selector_key_reg[mode_l + (index*4)], 697 pkt_attr_bits)); 698 } 699 /* Step4: Offset table filling */ 700 for (index = 0; index < num_flex_ingress_pools ; index++) { 701 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_update_offset_table(unit, 702 bcmStatFlexDirectionIngress, 703 ING_FLEX_CTR_OFFSET_TABLE_0m+index, 704 mode_l, 705 BCM_STAT_FLEX_MAX_COUNTER, 706 uncmprsd_attr_selectors->offset_table_map)); 707 } 708 /* Step5: Final: reserve mode and return */ 709 *total_counters = uncmprsd_attr_selectors->total_counters; 710 *mode=mode_l; 711 return BCM_E_NONE; 712 } 713 714 /* 715 * Function: 716 * _bcm_esw_stat_flex_create_ingress_compress_mode 717 * Description: 718 * Creates New Flex Ingress Compressed Mode 719 * Parameters: 720 * unit - (IN) unit number 721 * cmprsd_attr_selectors - (IN) Flex Compressed Attribute Selector 722 * mode - (OUT) Flex mode 723 * total_counters - (OUT) Total Counters associated with new 724 * Return Value: 725 * BCM_E_XXX 726 * Notes: 727 */ 728 static bcm_error_t 729 _bcm_esw_stat_flex_create_ingress_compress_mode( 730 int unit, 731 bcm_stat_flex_ing_cmprsd_attr_selectors_t *cmprsd_attr_selectors, 732 bcm_stat_flex_mode_t *mode, 733 uint32 *total_counters, 734 bcm_stat_flex_attribute_t *flex_attribute) 735 { 736 bcm_stat_flex_mode_t mode_l=0; 737 bcm_stat_flex_ing_pkt_attr_bits_t pkt_attr_bits={0}; 738 uint32 total_ingress_bits=0; 739 uint32 index=0; 740 bcm_stat_flex_ingress_mode_t *flex_ingress_mode=NULL; 741 bcm_stat_flex_ing_pkt_attr_bits_t pkt_attr_bits_exist={0}; 742 uint32 num_flex_ingress_pools; 743 744 /*soc_mem_info_t *mem_info; */ 745 #ifdef BCM_APACHE_SUPPORT 746 uint32 mpls_label_3_exist = 0; 747 uint32 cng_3_map_used = 0; 748 uint32 phb_3_map_used = 0; 749 uint32 cng_2_map_used = 0; 750 uint32 phb_2_map_used = 0; 751 uint32 cng_1_map_used = 0; 752 uint32 phb_1_map_used = 0; 753 #endif 754 uint32 pri_cnf_map_used=0; 755 uint32 pkt_pri_map_used=0; 756 uint32 port_map_used=0; 757 uint32 tos_map_used=0; 758 uint32 pkt_res_map_used=0; 759 760 uint32 alloc_size=0; 761 ing_flex_ctr_pkt_pri_map_entry_t *pkt_pri_map_dma=NULL; 762 uint32 pkt_pri_map_value=0; 763 ing_flex_ctr_pkt_res_map_entry_t *pkt_res_map_dma=NULL; 764 uint32 pkt_res_map_value=0; 765 ing_flex_ctr_port_map_entry_t *port_map_dma=NULL; 766 uint32 port_map_value=0; 767 ing_flex_ctr_pri_cng_map_entry_t *pri_cng_map_dma=NULL; 768 uint32 pri_cng_map_value=0; 769 ing_flex_ctr_tos_map_entry_t *tos_map_dma=NULL; 770 uint32 tos_map_value=0; 771 int num_pkt_sel_key; 772 int rv = BCM_E_NONE; 773 774 num_flex_ingress_pools = SOC_INFO(unit).num_flex_ingress_pools; 775 flex_ingress_mode = sal_alloc(sizeof(bcm_stat_flex_ingress_mode_t), 776 "flex_ingress_mode"); 777 if (flex_ingress_mode == NULL) { 778 return BCM_E_MEMORY; 779 } 780 781 sal_memset(flex_ingress_mode, 0, sizeof(bcm_stat_flex_ingress_mode_t)); 782 /* Step1: Compare with existing mode_ids. */ 783 if (soc_feature(unit, soc_feature_flex_stat_compression_share)) { 784 rv = _bcm_esw_stat_flex_compress_mode_id_compare(unit, 785 bcmStatFlexDirectionIngress, 786 mode, 787 flex_attribute); 788 if (BCM_FAILURE(rv)) { 789 sal_free(flex_ingress_mode); 790 return rv; 791 } 792 } else { 793 for (index =0 ; index < BCM_STAT_FLEX_COUNTER_MAX_MODE ; index++) { 794 sal_memset(flex_ingress_mode,0,sizeof(bcm_stat_flex_ingress_mode_t)); 795 if (_bcm_esw_stat_flex_get_ingress_mode_info( 796 unit, 797 index, 798 flex_ingress_mode) == BCM_E_NONE) { 799 if (flex_ingress_mode->ing_attr.packet_attr_type != 800 bcmStatFlexPacketAttrTypeCompressed) { 801 continue; 802 } 803 pkt_attr_bits_exist = flex_ingress_mode->ing_attr. 804 cmprsd_attr_selectors.pkt_attr_bits; 805 #ifdef BCM_APACHE_SUPPORT 806 if (soc_feature(unit,soc_feature_flex_ctr_mpls_3_label_count)) { 807 if ((pkt_attr_bits_exist.cng_3 == 808 cmprsd_attr_selectors->pkt_attr_bits.cng_3) && 809 (pkt_attr_bits_exist.phb_3 == 810 cmprsd_attr_selectors->pkt_attr_bits.phb_3) && 811 (pkt_attr_bits_exist.cng_2 == 812 cmprsd_attr_selectors->pkt_attr_bits.cng_2) && 813 (pkt_attr_bits_exist.phb_2 == 814 cmprsd_attr_selectors->pkt_attr_bits.phb_2) && 815 (pkt_attr_bits_exist.cng_1 == 816 cmprsd_attr_selectors->pkt_attr_bits.cng_1) && 817 (pkt_attr_bits_exist.phb_1 == 818 cmprsd_attr_selectors->pkt_attr_bits.phb_1)) { 819 mpls_label_3_exist = 1; 820 } 821 } else { 822 mpls_label_3_exist = 1; 823 } 824 #endif 825 if ( 826 #ifdef BCM_APACHE_SUPPORT 827 mpls_label_3_exist && 828 #endif 829 (pkt_attr_bits_exist.cng == 830 cmprsd_attr_selectors->pkt_attr_bits.cng) && 831 (pkt_attr_bits_exist.ifp_cng == 832 cmprsd_attr_selectors->pkt_attr_bits.ifp_cng) && 833 (pkt_attr_bits_exist.int_pri == 834 cmprsd_attr_selectors->pkt_attr_bits.int_pri) && 835 (pkt_attr_bits_exist.vlan_format == 836 cmprsd_attr_selectors->pkt_attr_bits.vlan_format) && 837 (pkt_attr_bits_exist.outer_dot1p == 838 cmprsd_attr_selectors->pkt_attr_bits.outer_dot1p) && 839 (pkt_attr_bits_exist.inner_dot1p == 840 cmprsd_attr_selectors->pkt_attr_bits.inner_dot1p) && 841 (pkt_attr_bits_exist.ing_port == 842 cmprsd_attr_selectors->pkt_attr_bits.ing_port) && 843 (pkt_attr_bits_exist.tos_dscp == 844 cmprsd_attr_selectors->pkt_attr_bits.tos_dscp) && 845 (pkt_attr_bits_exist.tos_ecn == 846 cmprsd_attr_selectors->pkt_attr_bits.tos_ecn) && 847 (pkt_attr_bits_exist.pkt_resolution == 848 cmprsd_attr_selectors->pkt_attr_bits.pkt_resolution) && 849 (pkt_attr_bits_exist.svp_type == 850 cmprsd_attr_selectors->pkt_attr_bits.svp_type) && 851 (pkt_attr_bits_exist.drop == 852 cmprsd_attr_selectors->pkt_attr_bits.drop) && 853 (pkt_attr_bits_exist.ip_pkt == 854 cmprsd_attr_selectors->pkt_attr_bits.ip_pkt)) { 855 *total_counters = flex_ingress_mode->total_counters; 856 *mode=index; 857 sal_free(flex_ingress_mode); 858 return BCM_E_EXISTS; 859 } 860 #ifdef BCM_APACHE_SUPPORT 861 if (soc_feature(unit,soc_feature_flex_ctr_mpls_3_label_count)) { 862 if (pkt_attr_bits_exist.cng_3 != 0) { 863 cng_3_map_used = 1; 864 } 865 if (pkt_attr_bits_exist.phb_3 != 0) { 866 phb_3_map_used = 1; 867 } 868 if (pkt_attr_bits_exist.cng_2 != 0) { 869 cng_2_map_used = 1; 870 } 871 if (pkt_attr_bits_exist.phb_2 != 0) { 872 phb_2_map_used = 1; 873 } 874 if (pkt_attr_bits_exist.cng_1 != 0) { 875 cng_1_map_used = 1; 876 } 877 if (pkt_attr_bits_exist.phb_1 != 0) { 878 phb_1_map_used = 1; 879 } 880 } 881 #endif 882 if ((pkt_attr_bits_exist.cng) || 883 (pkt_attr_bits_exist.ifp_cng) || 884 (pkt_attr_bits_exist.int_pri)) { 885 pri_cnf_map_used=1; 886 } 887 if ((pkt_attr_bits_exist.vlan_format) || 888 (pkt_attr_bits_exist.outer_dot1p) || 889 (pkt_attr_bits_exist.inner_dot1p)) { 890 pkt_pri_map_used=1; 891 } 892 if (pkt_attr_bits_exist.ing_port) { 893 port_map_used=1; 894 } 895 if ((pkt_attr_bits_exist.tos_dscp) || 896 (pkt_attr_bits_exist.tos_ecn)) { 897 tos_map_used=1; 898 } 899 if ((pkt_attr_bits_exist.pkt_resolution) || 900 (pkt_attr_bits_exist.svp_type) || 901 (pkt_attr_bits_exist.drop)) { 902 pkt_res_map_used=1; 903 } 904 } 905 } 906 } 907 sal_free(flex_ingress_mode); 908 909 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_get_available_mode( 910 unit, 911 bcmStatFlexDirectionIngress, 912 &mode_l)); 913 if (cmprsd_attr_selectors->pkt_attr_bits.cng !=0) { 914 if (cmprsd_attr_selectors->pkt_attr_bits.cng > 915 ing_pkt_attr_cmprsd_bits_g[unit].cng) { 916 return BCM_E_PARAM; 917 } 918 if (pri_cnf_map_used==1) { 919 return BCM_E_PARAM; 920 } 921 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits.cng; 922 } 923 #ifdef BCM_APACHE_SUPPORT 924 if (soc_feature(unit,soc_feature_flex_ctr_mpls_3_label_count)) { 925 if (cmprsd_attr_selectors->pkt_attr_bits.cng_3 != 0) { 926 if (cmprsd_attr_selectors->pkt_attr_bits.cng_3 > 927 ing_pkt_attr_cmprsd_bits_g[unit].cng_3) { 928 return BCM_E_PARAM; 929 } 930 if (cng_3_map_used == 1) { 931 return BCM_E_PARAM; 932 } 933 total_ingress_bits += cmprsd_attr_selectors->pkt_attr_bits.cng_3; 934 } 935 if (cmprsd_attr_selectors->pkt_attr_bits.phb_3 != 0) { 936 if (cmprsd_attr_selectors->pkt_attr_bits.phb_3 > 937 ing_pkt_attr_cmprsd_bits_g[unit].phb_3) { 938 return BCM_E_PARAM; 939 } 940 if (phb_3_map_used == 1) { 941 return BCM_E_PARAM; 942 } 943 total_ingress_bits += cmprsd_attr_selectors->pkt_attr_bits.phb_3; 944 } 945 if (cmprsd_attr_selectors->pkt_attr_bits.cng_2 != 0) { 946 if (cmprsd_attr_selectors->pkt_attr_bits.cng_2 > 947 ing_pkt_attr_cmprsd_bits_g[unit].cng_2) { 948 return BCM_E_PARAM; 949 } 950 if (cng_2_map_used == 1) { 951 return BCM_E_PARAM; 952 } 953 total_ingress_bits += cmprsd_attr_selectors->pkt_attr_bits.cng_2; 954 } 955 if (cmprsd_attr_selectors->pkt_attr_bits.phb_2 != 0) { 956 if (cmprsd_attr_selectors->pkt_attr_bits.phb_2 > 957 ing_pkt_attr_cmprsd_bits_g[unit].phb_2) { 958 return BCM_E_PARAM; 959 } 960 if (phb_2_map_used == 1) { 961 return BCM_E_PARAM; 962 } 963 total_ingress_bits += cmprsd_attr_selectors->pkt_attr_bits.phb_2; 964 } 965 if (cmprsd_attr_selectors->pkt_attr_bits.cng_1 != 0) { 966 if (cmprsd_attr_selectors->pkt_attr_bits.cng_1 > 967 ing_pkt_attr_cmprsd_bits_g[unit].cng_1) { 968 return BCM_E_PARAM; 969 } 970 if (cng_1_map_used == 1) { 971 return BCM_E_PARAM; 972 } 973 total_ingress_bits += cmprsd_attr_selectors->pkt_attr_bits.cng_1; 974 } 975 if (cmprsd_attr_selectors->pkt_attr_bits.phb_1 != 0) { 976 if (cmprsd_attr_selectors->pkt_attr_bits.phb_1 > 977 ing_pkt_attr_cmprsd_bits_g[unit].phb_1) { 978 return BCM_E_PARAM; 979 } 980 if (phb_1_map_used == 1) { 981 return BCM_E_PARAM; 982 } 983 total_ingress_bits += cmprsd_attr_selectors->pkt_attr_bits.phb_1; 984 } 985 } 986 #endif 987 if (cmprsd_attr_selectors->pkt_attr_bits.ifp_cng !=0) { 988 if (cmprsd_attr_selectors->pkt_attr_bits.ifp_cng > 989 ing_pkt_attr_cmprsd_bits_g[unit].ifp_cng) { 990 return BCM_E_PARAM; 991 } 992 if (pri_cnf_map_used==1) { 993 return BCM_E_PARAM; 994 } 995 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits.ifp_cng; 996 } 997 if (cmprsd_attr_selectors->pkt_attr_bits.int_pri !=0) { 998 if (cmprsd_attr_selectors->pkt_attr_bits.int_pri > 999 ing_pkt_attr_cmprsd_bits_g[unit].int_pri) { 1000 return BCM_E_PARAM; 1001 } 1002 if (pri_cnf_map_used==1) { 1003 return BCM_E_PARAM; 1004 } 1005 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits.int_pri; 1006 } 1007 if (cmprsd_attr_selectors->pkt_attr_bits.vlan_format !=0) { 1008 if (cmprsd_attr_selectors->pkt_attr_bits.vlan_format > 1009 ing_pkt_attr_cmprsd_bits_g[unit].vlan_format) { 1010 return BCM_E_PARAM; 1011 } 1012 if (pkt_pri_map_used==1) { 1013 return BCM_E_PARAM; 1014 } 1015 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits.vlan_format; 1016 } 1017 if (cmprsd_attr_selectors->pkt_attr_bits.outer_dot1p !=0) { 1018 if (cmprsd_attr_selectors->pkt_attr_bits.outer_dot1p > 1019 ing_pkt_attr_cmprsd_bits_g[unit].outer_dot1p) { 1020 return BCM_E_PARAM; 1021 } 1022 if (pkt_pri_map_used==1) { 1023 return BCM_E_PARAM; 1024 } 1025 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits.outer_dot1p ; 1026 } 1027 if (cmprsd_attr_selectors->pkt_attr_bits.inner_dot1p !=0) { 1028 if (cmprsd_attr_selectors->pkt_attr_bits.inner_dot1p > 1029 ing_pkt_attr_cmprsd_bits_g[unit].inner_dot1p) { 1030 return BCM_E_PARAM; 1031 } 1032 if (pkt_pri_map_used==1) { 1033 return BCM_E_PARAM; 1034 } 1035 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits.inner_dot1p ; 1036 } 1037 if (cmprsd_attr_selectors->pkt_attr_bits.ing_port !=0) { 1038 if (cmprsd_attr_selectors->pkt_attr_bits.ing_port > 1039 ing_pkt_attr_cmprsd_bits_g[unit].ing_port) { 1040 return BCM_E_PARAM; 1041 } 1042 if (port_map_used==1) { 1043 return BCM_E_PARAM; 1044 } 1045 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits.ing_port ; 1046 } 1047 if (cmprsd_attr_selectors->pkt_attr_bits.tos_dscp !=0) { 1048 if (cmprsd_attr_selectors->pkt_attr_bits.tos_dscp > 1049 ing_pkt_attr_cmprsd_bits_g[unit].tos_dscp) { 1050 return BCM_E_PARAM; 1051 } 1052 if (tos_map_used==1) { 1053 return BCM_E_PARAM; 1054 } 1055 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits.tos_dscp ; 1056 } 1057 if (cmprsd_attr_selectors->pkt_attr_bits.tos_ecn !=0) { 1058 if (cmprsd_attr_selectors->pkt_attr_bits.tos_ecn > 1059 ing_pkt_attr_cmprsd_bits_g[unit].tos_ecn) { 1060 return BCM_E_PARAM; 1061 } 1062 if (tos_map_used==1) { 1063 return BCM_E_PARAM; 1064 } 1065 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits.tos_ecn ; 1066 } 1067 if (cmprsd_attr_selectors->pkt_attr_bits.pkt_resolution !=0) { 1068 if (cmprsd_attr_selectors->pkt_attr_bits.pkt_resolution > 1069 ing_pkt_attr_cmprsd_bits_g[unit].pkt_resolution) { 1070 return BCM_E_PARAM; 1071 } 1072 if (pkt_res_map_used==1) { 1073 return BCM_E_PARAM; 1074 } 1075 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits. 1076 pkt_resolution ; 1077 } 1078 if (cmprsd_attr_selectors->pkt_attr_bits.svp_type !=0) { 1079 if (cmprsd_attr_selectors->pkt_attr_bits.svp_type > 1080 ing_pkt_attr_cmprsd_bits_g[unit].svp_type) { 1081 return BCM_E_PARAM; 1082 } 1083 if (pkt_res_map_used==1) { 1084 return BCM_E_PARAM; 1085 } 1086 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits.svp_type ; 1087 } 1088 if (cmprsd_attr_selectors->pkt_attr_bits.drop !=0) { 1089 if (cmprsd_attr_selectors->pkt_attr_bits.drop > 1090 ing_pkt_attr_cmprsd_bits_g[unit].drop) { 1091 return BCM_E_PARAM; 1092 } 1093 if (pkt_res_map_used==1) { 1094 return BCM_E_PARAM; 1095 } 1096 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits.drop ; 1097 } 1098 if (cmprsd_attr_selectors->pkt_attr_bits.ip_pkt !=0) { 1099 if (cmprsd_attr_selectors->pkt_attr_bits.ip_pkt > 1100 ing_pkt_attr_cmprsd_bits_g[unit].ip_pkt) { 1101 return BCM_E_PARAM; 1102 } 1103 total_ingress_bits +=cmprsd_attr_selectors->pkt_attr_bits.ip_pkt ; 1104 } 1105 if (total_ingress_bits > 8) { 1106 return BCM_E_PARAM; 1107 } 1108 pkt_attr_bits = cmprsd_attr_selectors->pkt_attr_bits; 1109 1110 if (soc_feature(unit, soc_feature_flex_stat_compression_share)) { 1111 /* Write global compression tables */ 1112 rv = _bcm_stat_flex_compressed_attr_tbl_write(unit, 1113 bcmStatFlexDirectionIngress, 1114 cmprsd_attr_selectors,NULL); 1115 if (BCM_FAILURE(rv)) { 1116 return rv; 1117 } 1118 } else { 1119 /* Step3: Fill up map array */ 1120 if ((pkt_attr_bits.cng != 0) || 1121 (pkt_attr_bits.ifp_cng) || 1122 (pkt_attr_bits.int_pri)) { 1123 alloc_size = soc_mem_index_count(unit,ING_FLEX_CTR_PRI_CNG_MAPm) * 1124 sizeof(ing_flex_ctr_pri_cng_map_entry_t); 1125 1126 pri_cng_map_dma=soc_cm_salloc( unit,alloc_size, "pri_cng_map"); 1127 if (pri_cng_map_dma == NULL) { 1128 return BCM_E_MEMORY; 1129 } 1130 sal_memset(pri_cng_map_dma, 0,alloc_size); 1131 if (soc_mem_read_range( 1132 unit, 1133 ING_FLEX_CTR_PRI_CNG_MAPm, 1134 MEM_BLOCK_ANY, 1135 soc_mem_index_min(unit,ING_FLEX_CTR_PRI_CNG_MAPm), 1136 soc_mem_index_max(unit,ING_FLEX_CTR_PRI_CNG_MAPm), 1137 pri_cng_map_dma) != BCM_E_NONE){ 1138 soc_cm_sfree(unit,pri_cng_map_dma); 1139 return BCM_E_INTERNAL; 1140 } 1141 for (index=0; 1142 index< soc_mem_index_count(unit,ING_FLEX_CTR_PRI_CNG_MAPm); 1143 index++) { 1144 pri_cng_map_value=cmprsd_attr_selectors->pri_cnf_attr_map[index]; 1145 soc_mem_field_set( 1146 unit, 1147 ING_FLEX_CTR_PRI_CNG_MAPm, 1148 (uint32 *)&pri_cng_map_dma[index], 1149 PRI_CNG_FNf, 1150 &pri_cng_map_value); 1151 } 1152 if (soc_mem_write_range( 1153 unit, 1154 ING_FLEX_CTR_PRI_CNG_MAPm, 1155 MEM_BLOCK_ALL, 1156 soc_mem_index_min(unit,ING_FLEX_CTR_PRI_CNG_MAPm), 1157 soc_mem_index_max(unit,ING_FLEX_CTR_PRI_CNG_MAPm), 1158 pri_cng_map_dma) != BCM_E_NONE){ 1159 soc_cm_sfree(unit,pri_cng_map_dma); 1160 return BCM_E_INTERNAL; 1161 } 1162 soc_cm_sfree(unit,pri_cng_map_dma); 1163 } 1164 if ((pkt_attr_bits.vlan_format != 0) || 1165 (pkt_attr_bits.outer_dot1p) || 1166 (pkt_attr_bits.inner_dot1p)) { 1167 /* Sanity Check */ 1168 alloc_size = soc_mem_index_count(unit, ING_FLEX_CTR_PKT_PRI_MAPm) * 1169 sizeof(ing_flex_ctr_pkt_pri_map_entry_t); 1170 pkt_pri_map_dma = soc_cm_salloc( unit,alloc_size, "pkt_pri_map"); 1171 if (pkt_pri_map_dma == NULL) { 1172 return BCM_E_MEMORY; 1173 } 1174 sal_memset(pkt_pri_map_dma, 0,alloc_size); 1175 if (soc_mem_read_range( 1176 unit, 1177 ING_FLEX_CTR_PKT_PRI_MAPm, 1178 MEM_BLOCK_ANY, 1179 soc_mem_index_min(unit,ING_FLEX_CTR_PKT_PRI_MAPm), 1180 soc_mem_index_max(unit,ING_FLEX_CTR_PKT_PRI_MAPm), 1181 pkt_pri_map_dma) != BCM_E_NONE){ 1182 soc_cm_sfree(unit,pkt_pri_map_dma); 1183 return BCM_E_INTERNAL; 1184 } 1185 for (index=0; 1186 index< soc_mem_index_count(unit, ING_FLEX_CTR_PKT_PRI_MAPm); 1187 index++) { 1188 pkt_pri_map_value= cmprsd_attr_selectors->pkt_pri_attr_map[index]; 1189 soc_mem_field_set( 1190 unit, 1191 ING_FLEX_CTR_PKT_PRI_MAPm, 1192 (uint32 *)&pkt_pri_map_dma[index], 1193 PKT_PRI_FNf, 1194 &pkt_pri_map_value); 1195 } 1196 if (soc_mem_write_range( 1197 unit, 1198 ING_FLEX_CTR_PKT_PRI_MAPm, 1199 MEM_BLOCK_ALL, 1200 soc_mem_index_min(unit,ING_FLEX_CTR_PKT_PRI_MAPm), 1201 soc_mem_index_max(unit,ING_FLEX_CTR_PKT_PRI_MAPm), 1202 pkt_pri_map_dma) != BCM_E_NONE){ 1203 soc_cm_sfree(unit,pkt_pri_map_dma); 1204 return BCM_E_INTERNAL; 1205 } 1206 soc_cm_sfree(unit,pkt_pri_map_dma); 1207 } 1208 if (pkt_attr_bits.ing_port != 0){ 1209 alloc_size = soc_mem_index_count(unit, ING_FLEX_CTR_PORT_MAPm) * 1210 sizeof(ing_flex_ctr_port_map_entry_t); 1211 port_map_dma = soc_cm_salloc( 1212 unit,alloc_size, "port_map"); 1213 if (port_map_dma == NULL) { 1214 return BCM_E_MEMORY; 1215 } 1216 sal_memset(port_map_dma, 0,alloc_size); 1217 if (soc_mem_read_range( 1218 unit, 1219 ING_FLEX_CTR_PORT_MAPm, 1220 MEM_BLOCK_ANY, 1221 soc_mem_index_min(unit,ING_FLEX_CTR_PORT_MAPm), 1222 soc_mem_index_max(unit,ING_FLEX_CTR_PORT_MAPm), 1223 port_map_dma) != BCM_E_NONE) { 1224 soc_cm_sfree(unit,port_map_dma); 1225 return BCM_E_INTERNAL; 1226 } 1227 for (index=0; 1228 index< soc_mem_index_count(unit, ING_FLEX_CTR_PORT_MAPm); 1229 index++) { 1230 port_map_value = cmprsd_attr_selectors->port_attr_map[index]; 1231 soc_mem_field_set( 1232 unit, 1233 ING_FLEX_CTR_PORT_MAPm, 1234 (uint32 *)&port_map_dma[index], 1235 PORT_FNf, 1236 &port_map_value); 1237 } 1238 if (soc_mem_write_range( 1239 unit, 1240 ING_FLEX_CTR_PORT_MAPm, 1241 MEM_BLOCK_ALL, 1242 soc_mem_index_min(unit,ING_FLEX_CTR_PORT_MAPm), 1243 soc_mem_index_max(unit,ING_FLEX_CTR_PORT_MAPm), 1244 port_map_dma) != BCM_E_NONE) { 1245 soc_cm_sfree(unit,port_map_dma); 1246 return BCM_E_INTERNAL; 1247 } 1248 soc_cm_sfree(unit,port_map_dma); 1249 } 1250 if ((pkt_attr_bits.tos_dscp != 0) || 1251 (pkt_attr_bits.tos_ecn != 0)) { 1252 alloc_size = soc_mem_index_count(unit,ING_FLEX_CTR_TOS_MAPm) * 1253 sizeof(ing_flex_ctr_tos_map_entry_t); 1254 tos_map_dma = soc_cm_salloc( unit,alloc_size, "tos_map"); 1255 if (tos_map_dma == NULL) { 1256 return BCM_E_MEMORY; 1257 } 1258 sal_memset(tos_map_dma, 0,alloc_size); 1259 if (soc_mem_read_range( 1260 unit, 1261 ING_FLEX_CTR_TOS_MAPm, 1262 MEM_BLOCK_ANY, 1263 soc_mem_index_min(unit,ING_FLEX_CTR_TOS_MAPm), 1264 soc_mem_index_max(unit,ING_FLEX_CTR_TOS_MAPm), 1265 tos_map_dma) != BCM_E_NONE){ 1266 soc_cm_sfree(unit,tos_map_dma); 1267 return BCM_E_INTERNAL; 1268 } 1269 for (index=0; 1270 index< soc_mem_index_count(unit,ING_FLEX_CTR_TOS_MAPm); 1271 index++) { 1272 tos_map_value = cmprsd_attr_selectors->tos_attr_map[index]; 1273 soc_mem_field_set( 1274 unit, 1275 ING_FLEX_CTR_TOS_MAPm, 1276 (uint32 *)&tos_map_dma[index], 1277 TOS_FNf, 1278 &tos_map_value); 1279 } 1280 if (soc_mem_write_range( 1281 unit, 1282 ING_FLEX_CTR_TOS_MAPm, 1283 MEM_BLOCK_ALL, 1284 soc_mem_index_min(unit,ING_FLEX_CTR_TOS_MAPm), 1285 soc_mem_index_max(unit,ING_FLEX_CTR_TOS_MAPm), 1286 tos_map_dma) != BCM_E_NONE){ 1287 soc_cm_sfree(unit,tos_map_dma); 1288 return BCM_E_INTERNAL; 1289 } 1290 soc_cm_sfree(unit,tos_map_dma); 1291 } 1292 if ((pkt_attr_bits.pkt_resolution != 0) || 1293 (pkt_attr_bits.svp_type) || 1294 (pkt_attr_bits.drop)){ 1295 alloc_size = soc_mem_index_count(unit, ING_FLEX_CTR_PKT_RES_MAPm) * 1296 sizeof(ing_flex_ctr_pkt_res_map_entry_t); 1297 pkt_res_map_dma= soc_cm_salloc( unit, alloc_size, "pkt_res_map"); 1298 if (pkt_res_map_dma == NULL) { 1299 return BCM_E_MEMORY; 1300 } 1301 sal_memset(pkt_res_map_dma, 0,alloc_size); 1302 if (soc_mem_read_range( 1303 unit, 1304 ING_FLEX_CTR_PKT_RES_MAPm, 1305 MEM_BLOCK_ANY, 1306 soc_mem_index_min(unit,ING_FLEX_CTR_PKT_RES_MAPm), 1307 soc_mem_index_max(unit,ING_FLEX_CTR_PKT_RES_MAPm), 1308 pkt_res_map_dma) != BCM_E_NONE){ 1309 soc_cm_sfree(unit,pkt_res_map_dma); 1310 return BCM_E_INTERNAL; 1311 } 1312 for (index=0; 1313 index< soc_mem_index_count(unit, ING_FLEX_CTR_PKT_RES_MAPm); 1314 index++) { 1315 pkt_res_map_value = cmprsd_attr_selectors->pkt_res_attr_map[index]; 1316 soc_mem_field_set( 1317 unit, 1318 ING_FLEX_CTR_PKT_RES_MAPm, 1319 (uint32 *)&pkt_res_map_dma[index], 1320 PKT_RES_FNf, 1321 &pkt_res_map_value); 1322 } 1323 if (soc_mem_write_range(unit, 1324 ING_FLEX_CTR_PKT_RES_MAPm, 1325 MEM_BLOCK_ALL, 1326 soc_mem_index_min(unit,ING_FLEX_CTR_PKT_RES_MAPm), 1327 soc_mem_index_max(unit,ING_FLEX_CTR_PKT_RES_MAPm), 1328 pkt_res_map_dma) != BCM_E_NONE){ 1329 soc_cm_sfree(unit,pkt_res_map_dma); 1330 return BCM_E_INTERNAL; 1331 } 1332 soc_cm_sfree(unit,pkt_res_map_dma); 1333 } 1334 } 1335 /* Step4: Packet Attribute filling */ 1336 /* APACHE supports 4 pkt keys per pool */ 1337 GET_NUM_COMP_ING_KEYS(num_pkt_sel_key, unit); 1338 for (index = 0; index < num_pkt_sel_key ; index++) { 1339 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_update_ingress_selector_keys( 1340 unit, 1341 bcmStatFlexPacketAttrTypeCompressed, 1342 _ingress_pkt_selector_key_reg[mode_l+(index*4)], 1343 pkt_attr_bits)); 1344 } 1345 /* Step5: Offset table filling */ 1346 for (index=0;index < num_flex_ingress_pools ; index++) { 1347 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_update_offset_table( 1348 unit, 1349 bcmStatFlexDirectionIngress, 1350 ING_FLEX_CTR_OFFSET_TABLE_0m+index, 1351 mode_l, 1352 256, 1353 cmprsd_attr_selectors->offset_table_map)); 1354 } 1355 /* Step6: Final: reserve mode and return */ 1356 *total_counters = cmprsd_attr_selectors->total_counters; 1357 *mode=mode_l; 1358 return BCM_E_NONE; 1359 } 1360 1361 /* 1362 * Function: 1363 * _bcm_esw_stat_flex_create_ingress_udf_mode 1364 * Description: 1365 * Creates New Flex Ingress UDF(User Defined Field) Mode 1366 * Parameters: 1367 * unit - (IN) unit number 1368 * udf_pkt_attr_selectors - (IN) Flex attributes 1369 * mode - (OUT) Flex mode 1370 * total_counters - (OUT) Total Counters associated with new 1371 * Return Value: 1372 * BCM_E_XXX 1373 * Notes: 1374 * Not being used currently 1375 */ 1376 static bcm_error_t 1377 _bcm_esw_stat_flex_create_ingress_udf_mode( 1378 int unit, 1379 bcm_stat_flex_udf_pkt_attr_selectors_t *udf_pkt_attr_selectors, 1380 bcm_stat_flex_offset_table_entry_t *offset_table, 1381 bcm_stat_flex_mode_t *mode, 1382 uint32 *total_counters) 1383 { 1384 bcm_stat_flex_mode_t mode_l=0; 1385 uint32 total_udf_bits=0; 1386 uint32 index=0; 1387 bcm_stat_flex_ingress_mode_t *flex_ingress_mode=NULL; 1388 bcm_stat_flex_udf_pkt_attr_bits_t udf_pkt_attr_bits_l; 1389 uint32 num_flex_ingress_pools; 1390 int num_pkt_sel_key; 1391 1392 num_flex_ingress_pools=SOC_INFO(unit).num_flex_ingress_pools; 1393 flex_ingress_mode = sal_alloc(sizeof(bcm_stat_flex_ingress_mode_t), 1394 "flex_ingress_mode"); 1395 if (flex_ingress_mode == NULL) { 1396 return BCM_E_MEMORY; 1397 } 1398 1399 sal_memset(flex_ingress_mode, 0, sizeof(bcm_stat_flex_ingress_mode_t)); 1400 1401 for (index =0 ; index < BCM_STAT_FLEX_COUNTER_MAX_MODE ; index++) { 1402 sal_memset(flex_ingress_mode,0,sizeof(bcm_stat_flex_ingress_mode_t)); 1403 if (_bcm_esw_stat_flex_get_ingress_mode_info( 1404 unit, 1405 index, 1406 flex_ingress_mode) == BCM_E_NONE) { 1407 if (flex_ingress_mode->ing_attr.packet_attr_type != 1408 bcmStatFlexPacketAttrTypeUdf) { 1409 continue; 1410 } 1411 udf_pkt_attr_bits_l = flex_ingress_mode->ing_attr. 1412 udf_pkt_attr_selectors.udf_pkt_attr_bits; 1413 if ((udf_pkt_attr_bits_l.udf0== 1414 udf_pkt_attr_selectors->udf_pkt_attr_bits.udf0) && 1415 (udf_pkt_attr_bits_l.udf1== 1416 udf_pkt_attr_selectors->udf_pkt_attr_bits.udf1)) { 1417 *total_counters = flex_ingress_mode->total_counters; 1418 *mode=index; 1419 sal_free(flex_ingress_mode); 1420 return BCM_E_EXISTS; 1421 } 1422 } 1423 } 1424 sal_free(flex_ingress_mode); 1425 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_get_available_mode( 1426 unit, 1427 bcmStatFlexDirectionIngress, 1428 &mode_l)); 1429 /* Step2: Packet Attribute filling */ 1430 /* APACHE supports 4 pkt keys per pool */ 1431 GET_NUM_COMP_ING_KEYS(num_pkt_sel_key, unit); 1432 for (index = 0; index < num_pkt_sel_key; index++) { 1433 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_update_udf_selector_keys( 1434 unit, 1435 bcmStatFlexDirectionIngress, 1436 _ingress_pkt_selector_key_reg[mode_l+(index*4)], 1437 udf_pkt_attr_selectors, 1438 &total_udf_bits)); 1439 } 1440 /* Step3: Offset table filling */ 1441 for (index=0;index < num_flex_ingress_pools ; index++) { 1442 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_update_offset_table( 1443 unit, 1444 bcmStatFlexDirectionIngress, 1445 ING_FLEX_CTR_OFFSET_TABLE_0m+index, 1446 mode_l, 1447 256, 1448 offset_table)); 1449 } 1450 /* Step4: Final: reserve mode and return */ 1451 *total_counters = udf_pkt_attr_selectors->total_counters; 1452 *mode=mode_l; 1453 return BCM_E_NONE; 1454 } 1455 1456 /* 1457 * Function: 1458 * _bcm_esw_stat_flex_create_ingress_mode 1459 * Description: 1460 * Creates New Flex Ingress Mode(Either uncompressd or compressed or udf) 1461 * 1462 * Parameters: 1463 * unit - (IN) unit number 1464 * ing_attr - (IN) Flex Ingress attributes 1465 * mode - (OUT) Flex mode 1466 * Return Value: 1467 * BCM_E_XXX 1468 * Notes: 1469 */ 1470 bcm_error_t _bcm_esw_stat_flex_create_ingress_mode ( 1471 int unit, 1472 bcm_stat_flex_ing_attr_t *ing_attr, 1473 bcm_stat_flex_mode_t *mode, 1474 bcm_stat_flex_attribute_t *flex_attribute) 1475 { 1476 uint32 total_counters=0; 1477 switch(ing_attr->packet_attr_type) { 1478 case bcmStatFlexPacketAttrTypeUncompressed: 1479 LOG_DEBUG(BSL_LS_BCM_FLEXCTR, 1480 (BSL_META_U(unit, 1481 "Creating Ingress uncompressed mode \n"))); 1482 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_create_ingress_uncompress_mode( 1483 unit, 1484 &(ing_attr->uncmprsd_attr_selectors), 1485 mode,&total_counters)); 1486 break; 1487 case bcmStatFlexPacketAttrTypeCompressed: 1488 if (SOC_IS_TOMAHAWK3(unit)) { 1489 LOG_ERROR(BSL_LS_BCM_FLEXCTR, 1490 (BSL_META_U(unit, 1491 "bcmStatFlexPacketAttrTypeCompressed IsNotAvailable" 1492 "for %s\n"), SOC_UNIT_NAME(unit))); 1493 return BCM_E_UNAVAIL; 1494 } 1495 LOG_DEBUG(BSL_LS_BCM_FLEXCTR, 1496 (BSL_META_U(unit, 1497 "Creating Ingress compressed mode \n"))); 1498 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_create_ingress_compress_mode( 1499 unit, 1500 &(ing_attr->cmprsd_attr_selectors), 1501 mode,&total_counters,flex_attribute)); 1502 break; 1503 case bcmStatFlexPacketAttrTypeUdf: 1504 LOG_DEBUG(BSL_LS_BCM_FLEXCTR, 1505 (BSL_META_U(unit, 1506 "Creating Ingress udf mode \n"))); 1507 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_create_ingress_udf_mode( 1508 unit, 1509 &(ing_attr->udf_pkt_attr_selectors), 1510 (ing_attr->uncmprsd_attr_selectors).offset_table_map, 1511 mode,&total_counters)); 1512 break; 1513 default: 1514 return BCM_E_PARAM; 1515 } 1516 BCM_IF_ERROR_RETURN(_bcm_esw_stat_flex_ingress_reserve_mode( 1517 unit, 1518 *mode, 1519 total_counters, 1520 ing_attr)); 1521 LOG_DEBUG(BSL_LS_BCM_FLEXCTR, 1522 (BSL_META_U(unit, 1523 "\n Done %d \n"), 1524 *mode)); 1525 return BCM_E_NONE; 1526 } 1527 /* 1528 * Function: 1529 * _bcm_esw_stat_flex_delete_ingress_mode 1530 * Description: 1531 * Destroys New Flex Ingress Mode(Either uncompressd or compressed or udf) 1532 * 1533 * Parameters: 1534 * unit - (IN) unit number 1535 * mode - (IN) Flex mode 1536 * Return Value: 1537 * BCM_E_XXX 1538 * Notes: 1539 */ 1540 bcm_error_t _bcm_esw_stat_flex_delete_ingress_mode( 1541 int unit, 1542 bcm_stat_flex_mode_t mode) 1543 { 1544 #if defined (BCM_TOMAHAWK_SUPPORT) 1545 bcm_stat_flex_custom_ingress_mode_t cmode; 1546 if ((mode >= BCM_CUSTOM_INGRESS_MODE_START) && 1547 (mode < BCM_STAT_FLEX_CUSTOM_INGRESS_COUNTER_MAX_MODE)) { 1548 _bcm_esw_stat_flex_get_custom_ingress_mode_info(unit, mode, &cmode); 1549 mode = cmode.offset_mode; 1550 } 1551 #endif 1552 if (mode > (BCM_STAT_FLEX_COUNTER_MAX_MODE-1)) { 1553 /* Exceeding max allowed value : (BCM_STAT_FLEX_COUNTER_MAX_MODE-1) */ 1554 return BCM_E_PARAM; 1555 } 1556 return _bcm_esw_stat_flex_unreserve_mode( 1557 unit, 1558 bcmStatFlexDirectionIngress, 1559 mode); 1560 } 1561 1562 /* 1563 * Function: 1564 * _bcm_esw_stat_flex_delete_ingress_flags 1565 * Description: 1566 * Deletes New Flex Ingress Mode Flags(Either uncompressd or compressed or 1567 udf) 1568 * 1569 * Parameters: 1570 * unit - (IN) unit number 1571 * mode - (IN) Flex mode 1572 * flags - (IN) Flex mode flags 1573 * Return Value: 1574 * BCM_E_XXX 1575 * Notes: 1576 */ 1577 bcm_error_t _bcm_esw_stat_flex_delete_ingress_flags( 1578 int unit, 1579 bcm_stat_flex_mode_t mode, 1580 uint32 flags) 1581 { 1582 if (mode > (BCM_STAT_FLEX_COUNTER_MAX_MODE-1)) { 1583 /* Exceeding max allowed value : 1584 (BCM_STAT_FLEX_COUNTER_MAX_MODE-1) */ 1585 return BCM_E_PARAM; 1586 } 1587 return _bcm_esw_stat_flex_unreserve_flags( 1588 unit, 1589 mode, 1590 flags); 1591 } 1592