switch_match.c (52332B)
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 8 #include <shared/bsl.h> 9 #include <soc/debug.h> 10 #include <soc/drv.h> 11 #include <soc/scache.h> 12 #include <soc/mem.h> 13 #include <bcm/switch.h> 14 #include <bcm/error.h> 15 #include <bcm_int/esw/trx.h> 16 #include <bcm_int/esw/switch.h> 17 #include <bcm_int/esw/switch_match.h> 18 #include <bcm_int/esw/hurricane3.h> 19 #include <bcm_int/esw/greyhound2.h> 20 #include <bcm_int/esw/triumph2.h> 21 #include <bcm_int/esw/xgs3.h> 22 #include <bcm_int/esw/stack.h> 23 #if defined(BCM_GREYHOUND2_SUPPORT) 24 #if defined(BCM_SWITCH_MATCH_SUPPORT) 25 26 /* Parameter NULL error handling */ 27 #define GH2_MATCH_CHECK_NULL_PARAMETER(_u_, _parameter_) \ 28 do { \ 29 if (NULL == (_parameter_)) { \ 30 LOG_ERROR(BSL_LS_BCM_SWITCH, \ 31 (BSL_META_U((_u_), \ 32 "Error: NULL parameter\n"))); \ 33 return BCM_E_PARAM; \ 34 } \ 35 } while (0) 36 37 /* Function Enter/Leave Tracing */ 38 #define GH2_MATCH_FUNCTION_TRACE(_u_, _str_) \ 39 do { \ 40 LOG_VERBOSE(BSL_LS_BCM_SWITCH, \ 41 (BSL_META_U((_u_), \ 42 "%s: " _str_ "\n"), __FUNCTION__)); \ 43 } while (0) 44 45 #define GH2_SWITCH_MATCH_TABLE_SIZE_HSRPRP (1) 46 #define GH2_SWITCH_MATCH_TABLE_SIZE_DOT1CB (1) 47 #define GH2_SWITCH_MATCH_TABLE_SIZE_LINKLOCAL (2) 48 49 /* default values for HsrPrp & dot1cb (reset Value) */ 50 #define GH2_ETHERTYPE_EMPTY_VALUE 0 51 static const bcm_mac_t GH2_EMPTY_MACADDR = 52 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 53 static const bcm_mac_t GH2_EMPTY_MACADDR_MASK = 54 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 55 56 /* 57 * Function: 58 * bcmi_gh2_hsrprp_sup_match_table_size_get 59 * Purpose: 60 * Get the table size for HSRPRP 61 * Parameters: 62 * unit - (IN) Unit number 63 * table_size - (OUT) table size 64 * Returns: 65 * BCM_E_xxx 66 */ 67 STATIC int 68 bcmi_gh2_hsrprp_sup_match_table_size_get( 69 int unit, 70 uint32 *table_size) 71 { 72 /* Parameter NULL error handling */ 73 GH2_MATCH_CHECK_NULL_PARAMETER(unit, table_size); 74 75 *table_size = GH2_SWITCH_MATCH_TABLE_SIZE_HSRPRP; 76 return BCM_E_NONE; 77 } 78 79 /* 80 * Function: 81 * bcmi_gh2_hsrprp_sup_match_hw_idx_get 82 * Purpose: 83 * Get HW memory index 84 * Parameters: 85 * unit - (IN) Unit number 86 * sw_idx - (IN) SW memory index 87 * hw_idx - (OUT) HW memory index 88 * Returns: 89 * BCM_E_xxx 90 */ 91 STATIC int 92 bcmi_gh2_hsrprp_sup_match_hw_idx_get( 93 int unit, 94 uint32 sw_idx, 95 uint32 *hw_idx) 96 { 97 uint32 table_size; 98 /* 99 * The tables size of HSRPRP/DOT1CB are only with 1 hw entry. Further more 100 * in HSRPRP/DOT1CB cases, sw_idx should be the same as hw_idx = 0 all 101 * the time. 102 */ 103 104 GH2_MATCH_FUNCTION_TRACE(unit, "IN"); 105 /* Parameter NULL error handling */ 106 GH2_MATCH_CHECK_NULL_PARAMETER(unit, hw_idx); 107 108 /* Parameter validation */ 109 BCM_IF_ERROR_RETURN 110 (bcmi_gh2_hsrprp_sup_match_table_size_get(unit, &table_size)); 111 112 if (sw_idx >= table_size) { 113 LOG_ERROR(BSL_LS_BCM_SWITCH, 114 (BSL_META_U(unit, 115 "Invalid sw_idx.\n"))); 116 return BCM_E_RESOURCE; 117 } 118 119 *hw_idx = sw_idx; 120 LOG_DEBUG(BSL_LS_BCM_SWITCH, 121 (BSL_META_U(unit, 122 "hw_idx %u\n"), *hw_idx)); 123 GH2_MATCH_FUNCTION_TRACE(unit, "OUT"); 124 return BCM_E_NONE; 125 } 126 127 /* 128 * Function: 129 * bcmi_gh2_hsrprp_sup_match_sw_idx_get 130 * Purpose: 131 * Get SW memory index 132 * Parameters: 133 * unit - (IN) Unit number 134 * hw_idx - (IN) HW memory index 135 * sw_idx - (OUT) SW memory index 136 * Returns: 137 * BCM_E_xxx 138 */ 139 STATIC int 140 bcmi_gh2_hsrprp_sup_match_sw_idx_get( 141 int unit, 142 uint32 hw_idx, 143 uint32 *sw_idx) 144 { 145 uint32 table_size; 146 /* 147 * The tables size of HSRPRP/DOT1CB are only with 1 hw entry. Further more 148 * in HSRPRP/DOT1CB cases, sw_idx should be the same as hw_idx = 0 all 149 * the time. 150 */ 151 152 GH2_MATCH_FUNCTION_TRACE(unit, "IN"); 153 154 /* Parameter NULL error handling */ 155 GH2_MATCH_CHECK_NULL_PARAMETER(unit, sw_idx); 156 157 /* Parameter validation */ 158 BCM_IF_ERROR_RETURN 159 (bcmi_gh2_hsrprp_sup_match_table_size_get(unit, &table_size)); 160 161 if (hw_idx >= table_size) { 162 LOG_ERROR(BSL_LS_BCM_SWITCH, 163 (BSL_META_U(unit, 164 "Invalid hw_idx.\n"))); 165 return BCM_E_RESOURCE; 166 } 167 168 *sw_idx = hw_idx; 169 170 LOG_DEBUG(BSL_LS_BCM_SWITCH, 171 (BSL_META_U(unit, 172 "sw_idx %u\n"), *sw_idx)); 173 GH2_MATCH_FUNCTION_TRACE(unit, "OUT"); 174 return BCM_E_NONE; 175 } 176 177 /* 178 * Function: 179 * bcmi_gh2_dot1cb_sup_match_table_size_get 180 * Purpose: 181 * Get the table size for DOT1CB 182 * Parameters: 183 * unit - (IN) Unit number 184 * table_size - (OUT) table size 185 * Returns: 186 * BCM_E_xxx 187 */ 188 STATIC int 189 bcmi_gh2_dot1cb_sup_match_table_size_get( 190 int unit, 191 uint32 *table_size) 192 { 193 /* Parameter NULL error handling */ 194 GH2_MATCH_CHECK_NULL_PARAMETER(unit, table_size); 195 196 *table_size = GH2_SWITCH_MATCH_TABLE_SIZE_DOT1CB; 197 return BCM_E_NONE; 198 } 199 200 /* 201 * Function: 202 * bcmi_gh2_dot1cb_sup_match_hw_idx_get 203 * Purpose: 204 * Get HW memory index 205 * Parameters: 206 * unit - (IN) Unit number 207 * sw_idx - (IN) SW memory index 208 * hw_idx - (OUT) HW memory index 209 * Returns: 210 * BCM_E_xxx 211 */ 212 STATIC int 213 bcmi_gh2_dot1cb_sup_match_hw_idx_get( 214 int unit, 215 uint32 sw_idx, 216 uint32 *hw_idx) 217 { 218 uint32 table_size; 219 /* 220 * The tables size of HSRPRP/DOT1CB are only with 1 hw entry. Further more 221 * in HSRPRP/DOT1CB cases, sw_idx should be the same as hw_idx = 0 all 222 * the time. 223 */ 224 225 GH2_MATCH_FUNCTION_TRACE(unit, "IN"); 226 /* Parameter NULL error handling */ 227 GH2_MATCH_CHECK_NULL_PARAMETER(unit, hw_idx); 228 229 /* Parameter validation */ 230 BCM_IF_ERROR_RETURN 231 (bcmi_gh2_dot1cb_sup_match_table_size_get(unit, &table_size)); 232 233 if (sw_idx >= table_size) { 234 LOG_ERROR(BSL_LS_BCM_SWITCH, 235 (BSL_META_U(unit, 236 "Invalid sw_idx.\n"))); 237 return BCM_E_RESOURCE; 238 } 239 240 *hw_idx = sw_idx; 241 242 LOG_DEBUG(BSL_LS_BCM_SWITCH, 243 (BSL_META_U(unit, 244 "hw_idx %u\n"), *hw_idx)); 245 GH2_MATCH_FUNCTION_TRACE(unit, "OUT"); 246 return BCM_E_NONE; 247 } 248 249 /* 250 * Function: 251 * bcmi_gh2_dot1cb_sup_match_sw_idx_get 252 * Purpose: 253 * Get SW memory index 254 * Parameters: 255 * unit - (IN) Unit number 256 * hw_idx - (IN) HW memory index 257 * sw_idx - (OUT) SW memory index 258 * Returns: 259 * BCM_E_xxx 260 */ 261 STATIC int 262 bcmi_gh2_dot1cb_sup_match_sw_idx_get( 263 int unit, 264 uint32 hw_idx, 265 uint32 *sw_idx) 266 { 267 uint32 table_size; 268 /* 269 * The tables size of HSRPRP/DOT1CB are only with 1 hw entry. Further more 270 * in HSRPRP/DOT1CB cases, sw_idx should be the same as hw_idx = 0 all 271 * the time. 272 */ 273 274 GH2_MATCH_FUNCTION_TRACE(unit, "IN"); 275 276 /* Parameter NULL error handling */ 277 GH2_MATCH_CHECK_NULL_PARAMETER(unit, sw_idx); 278 279 /* Parameter validation */ 280 BCM_IF_ERROR_RETURN 281 (bcmi_gh2_dot1cb_sup_match_table_size_get(unit, &table_size)); 282 283 if (hw_idx >= table_size) { 284 LOG_ERROR(BSL_LS_BCM_SWITCH, 285 (BSL_META_U(unit, 286 "Invalid hw_idx.\n"))); 287 return BCM_E_RESOURCE; 288 } 289 290 *sw_idx = hw_idx; 291 292 LOG_DEBUG(BSL_LS_BCM_SWITCH, 293 (BSL_META_U(unit, 294 "sw_idx %u\n"), *sw_idx)); 295 GH2_MATCH_FUNCTION_TRACE(unit, "OUT"); 296 return BCM_E_NONE; 297 } 298 299 /* 300 * Function: 301 * bcmi_gh2_linklocal_match_table_size_get 302 * Purpose: 303 * Get the table size for LINKLOCAL 304 * Parameters: 305 * unit - (IN) Unit number 306 * table_size - (OUT) table size 307 * Returns: 308 * BCM_E_xxx 309 */ 310 STATIC int 311 bcmi_gh2_linklocal_match_table_size_get( 312 int unit, 313 uint32 *table_size) 314 { 315 /* Parameter NULL error handling */ 316 GH2_MATCH_CHECK_NULL_PARAMETER(unit, table_size); 317 318 *table_size = GH2_SWITCH_MATCH_TABLE_SIZE_LINKLOCAL; 319 return BCM_E_NONE; 320 } 321 322 /* 323 * Function: 324 * bcmi_gh2_linklocal_match_hw_id_get 325 * Purpose: 326 * Get HW memory index 327 * Parameters: 328 * unit - (IN) Unit number 329 * sw_idx - (IN) SW memory index 330 * hw_id - (OUT) HW field entry # in memory index 0 331 * Returns: 332 * BCM_E_xxx 333 */ 334 STATIC int 335 bcmi_gh2_linklocal_match_hw_id_get( 336 int unit, 337 uint32 sw_idx, 338 uint32 *hw_id) 339 { 340 uint32 table_size; 341 342 /* Note: 343 * For linklocal case, Since there is only one memory entry in 344 * LINK_LOCAL_MAC_ADDRESSm, the hw_id here means the field 345 * entries #1 (hw_id = 0) or #2 (hw_id = 1). The hw_id should equal to 346 * sw_idx all the time. 347 */ 348 349 GH2_MATCH_FUNCTION_TRACE(unit, "IN"); 350 /* Parameter NULL error handling */ 351 GH2_MATCH_CHECK_NULL_PARAMETER(unit, hw_id); 352 353 /* Parameter validation */ 354 BCM_IF_ERROR_RETURN 355 (bcmi_gh2_linklocal_match_table_size_get(unit, &table_size)); 356 357 if (sw_idx >= table_size) { 358 LOG_ERROR(BSL_LS_BCM_SWITCH, 359 (BSL_META_U(unit, 360 "Invalid sw_idx.\n"))); 361 return BCM_E_RESOURCE; 362 } 363 364 *hw_id = sw_idx; 365 366 LOG_DEBUG(BSL_LS_BCM_SWITCH, 367 (BSL_META_U(unit, 368 "hw_id %u\n"), *hw_id)); 369 GH2_MATCH_FUNCTION_TRACE(unit, "OUT"); 370 return BCM_E_NONE; 371 } 372 373 /* 374 * Function: 375 * bcmi_gh2_linklocal_match_sw_idx_get 376 * Purpose: 377 * Get SW memory index 378 * Parameters: 379 * unit - (IN) Unit number 380 * hw_id - (IN) HW field entry # in memory index 0 381 * sw_idx - (OUT) SW memory index 382 * Returns: 383 * BCM_E_xxx 384 */ 385 STATIC int 386 bcmi_gh2_linklocal_match_sw_idx_get( 387 int unit, 388 uint32 hw_id, 389 uint32 *sw_idx) 390 { 391 uint32 table_size; 392 393 /* Note: 394 * For linklocal case, Since there is only one memory entry in 395 * LINK_LOCAL_MAC_ADDRESSm, the hw_id here means the field 396 * entries #1 (hw_id = 0) or #2 (hw_id = 1). The hw_id should equal to 397 * sw_idx all the time. 398 */ 399 400 GH2_MATCH_FUNCTION_TRACE(unit, "IN"); 401 402 /* Parameter NULL error handling */ 403 GH2_MATCH_CHECK_NULL_PARAMETER(unit, sw_idx); 404 405 /* Parameter validation */ 406 BCM_IF_ERROR_RETURN 407 (bcmi_gh2_linklocal_match_table_size_get(unit, &table_size)); 408 409 if (hw_id >= table_size) { 410 LOG_ERROR(BSL_LS_BCM_SWITCH, 411 (BSL_META_U(unit, 412 "Invalid hw_idx.\n"))); 413 return BCM_E_RESOURCE; 414 } 415 416 *sw_idx = hw_id; 417 LOG_DEBUG(BSL_LS_BCM_SWITCH, 418 (BSL_META_U(unit, 419 "sw_idx %u\n"), *sw_idx)); 420 GH2_MATCH_FUNCTION_TRACE(unit, "OUT"); 421 return BCM_E_NONE; 422 } 423 424 /* 425 * Function: 426 * bcmi_gh2_hsrprp_sup_match_config_write 427 * Purpose: 428 * Write the match configuration to hardware 429 * Parameters: 430 * unit - (IN) Unit number 431 * hw_idx - (IN) HW memory index 432 * config_info - (IN) Match configuration 433 * Returns: 434 * BCM_E_xxx 435 */ 436 STATIC int 437 bcmi_gh2_hsrprp_sup_match_config_write( 438 int unit, 439 uint32 hw_idx, 440 bcm_switch_match_config_info_t *config_info) 441 { 442 sr_ethertypes_entry_t sr_ethertypes_entry; 443 egr_sr_ethertypes_entry_t egr_sr_ethertypes_entry; 444 sr_supervisory_mac_address_entry_t sr_sup_mac_address_entry; 445 446 /* Parameter NULL error handling */ 447 GH2_MATCH_CHECK_NULL_PARAMETER(unit, config_info); 448 449 sal_memset(&sr_ethertypes_entry, 0, 450 sizeof(sr_ethertypes_entry_t)); 451 sal_memset(&egr_sr_ethertypes_entry, 0, 452 sizeof(egr_sr_ethertypes_entry_t)); 453 sal_memset(&sr_sup_mac_address_entry, 0, 454 sizeof(sr_supervisory_mac_address_entry_t)); 455 456 /* Write PRP/HSR_SUPERVISION_ETHERTYPE to SR_ETHERTYPESm */ 457 BCM_IF_ERROR_RETURN 458 (soc_mem_read(unit, SR_ETHERTYPESm, MEM_BLOCK_ANY, 459 hw_idx, &sr_ethertypes_entry)); 460 soc_mem_field32_set(unit, SR_ETHERTYPESm, &sr_ethertypes_entry, 461 PRP_SUPERVISION_ETHERTYPEf, config_info->ethtype1); 462 soc_mem_field32_set(unit, SR_ETHERTYPESm, &sr_ethertypes_entry, 463 HSR_SUPERVISION_ETHERTYPEf, config_info->ethtype2); 464 BCM_IF_ERROR_RETURN 465 (soc_mem_write(unit, SR_ETHERTYPESm, MEM_BLOCK_ALL, 466 hw_idx, &sr_ethertypes_entry)); 467 468 /* Write PRP/HSR_SUPERVISION_ETHERTYPE to EGR_SR_ETHERTYPESm */ 469 BCM_IF_ERROR_RETURN 470 (soc_mem_read(unit, EGR_SR_ETHERTYPESm, MEM_BLOCK_ANY, 471 hw_idx, &egr_sr_ethertypes_entry)); 472 soc_mem_field32_set(unit, EGR_SR_ETHERTYPESm, &egr_sr_ethertypes_entry, 473 PRP_SUPERVISION_ETHERTYPEf, config_info->ethtype1); 474 soc_mem_field32_set(unit, EGR_SR_ETHERTYPESm, &egr_sr_ethertypes_entry, 475 HSR_SUPERVISION_ETHERTYPEf, config_info->ethtype2); 476 BCM_IF_ERROR_RETURN 477 (soc_mem_write(unit, EGR_SR_ETHERTYPESm, MEM_BLOCK_ALL, 478 hw_idx, &egr_sr_ethertypes_entry)); 479 480 /* Write MAC_ADDRESS/ADDRESS_MASK to SR_SUPERVISORY_MAC_ADDRESSm */ 481 BCM_IF_ERROR_RETURN 482 (soc_mem_read(unit, SR_SUPERVISORY_MAC_ADDRESSm, MEM_BLOCK_ANY, 483 hw_idx, &sr_sup_mac_address_entry)); 484 485 soc_SR_SUPERVISORY_MAC_ADDRESSm_mac_addr_set(unit, 486 &sr_sup_mac_address_entry, 487 MAC_ADDRESSf, 488 config_info->dst_mac); 489 soc_SR_SUPERVISORY_MAC_ADDRESSm_mac_addr_set(unit, 490 &sr_sup_mac_address_entry, 491 MAC_ADDRESS_MASKf, 492 config_info->dst_mac_mask); 493 494 BCM_IF_ERROR_RETURN 495 (soc_mem_write(unit, SR_SUPERVISORY_MAC_ADDRESSm, MEM_BLOCK_ALL, 496 hw_idx, &sr_sup_mac_address_entry)); 497 498 return BCM_E_NONE; 499 } 500 501 /* 502 * Function: 503 * bcmi_gh2_dot1cb_sup_match_config_write 504 * Purpose: 505 * Write the match configuration to hardware 506 * Parameters: 507 * unit - (IN) Unit number 508 * hw_idx - (IN) HW memory index 509 * config_info - (IN) Match configuration 510 * Returns: 511 * BCM_E_xxx 512 */ 513 STATIC int 514 bcmi_gh2_dot1cb_sup_match_config_write( 515 int unit, 516 uint32 hw_idx, 517 bcm_switch_match_config_info_t *config_info) 518 { 519 sr_ethertypes_entry_t sr_ethertypes_entry; 520 egr_sr_ethertypes_entry_t egr_sr_ethertypes_entry; 521 sr_supervisory_mac_address_dot1cb_entry_t sr_sup_mac_address_dot1cb_entry; 522 523 /* Parameter NULL error handling */ 524 GH2_MATCH_CHECK_NULL_PARAMETER(unit, config_info); 525 526 sal_memset(&sr_ethertypes_entry, 0, 527 sizeof(sr_ethertypes_entry_t)); 528 sal_memset(&egr_sr_ethertypes_entry, 0, 529 sizeof(egr_sr_ethertypes_entry_t)); 530 sal_memset(&sr_sup_mac_address_dot1cb_entry, 0, 531 sizeof(sr_supervisory_mac_address_dot1cb_entry_t)); 532 533 /* Write DOT1CB_SUPERVISION_ETHERTYPE to SR_ETHERTYPESm */ 534 BCM_IF_ERROR_RETURN 535 (soc_mem_read(unit, SR_ETHERTYPESm, MEM_BLOCK_ANY, 536 hw_idx, &sr_ethertypes_entry)); 537 soc_mem_field32_set(unit, SR_ETHERTYPESm, &sr_ethertypes_entry, 538 DOT1CB_SUPERVISION_ETHERTYPEf, config_info->ethtype1); 539 BCM_IF_ERROR_RETURN 540 (soc_mem_write(unit, SR_ETHERTYPESm, MEM_BLOCK_ALL, 541 hw_idx, &sr_ethertypes_entry)); 542 543 /* Write DOT1CB_SUPERVISION_ETHERTYPE to EGR_SR_ETHERTYPESm */ 544 BCM_IF_ERROR_RETURN 545 (soc_mem_read(unit, EGR_SR_ETHERTYPESm, MEM_BLOCK_ANY, 546 hw_idx, &egr_sr_ethertypes_entry)); 547 soc_mem_field32_set(unit, EGR_SR_ETHERTYPESm, &egr_sr_ethertypes_entry, 548 DOT1CB_SUPERVISION_ETHERTYPEf, config_info->ethtype1); 549 BCM_IF_ERROR_RETURN 550 (soc_mem_write(unit, EGR_SR_ETHERTYPESm, MEM_BLOCK_ALL, 551 hw_idx, &egr_sr_ethertypes_entry)); 552 553 /* Write MAC_ADDRESS/ADDRESS_MASK to SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm */ 554 BCM_IF_ERROR_RETURN 555 (soc_mem_read(unit, SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, MEM_BLOCK_ANY, 556 hw_idx, &sr_sup_mac_address_dot1cb_entry)); 557 558 soc_mem_mac_addr_set(unit, SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, 559 &sr_sup_mac_address_dot1cb_entry, MAC_ADDRESSf, 560 config_info->dst_mac); 561 soc_mem_mac_addr_set(unit, SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, 562 &sr_sup_mac_address_dot1cb_entry, MAC_ADDRESS_MASKf, 563 config_info->dst_mac_mask); 564 565 566 BCM_IF_ERROR_RETURN 567 (soc_mem_write(unit, SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, MEM_BLOCK_ALL, 568 hw_idx, &sr_sup_mac_address_dot1cb_entry)); 569 570 return BCM_E_NONE; 571 } 572 573 /* 574 * Function: 575 * bcmi_gh2_linklocal_match_config_write 576 * Purpose: 577 * Write the match configuration to hardware 578 * Parameters: 579 * unit - (IN) Unit number 580 * sw_idx - (IN) SW memory index 581 * config_info - (IN) Match configuration 582 * Returns: 583 * BCM_E_xxx 584 */ 585 STATIC int 586 bcmi_gh2_linklocal_match_config_write( 587 int unit, 588 uint32 sw_idx, 589 bcm_switch_match_config_info_t *config_info) 590 { 591 /* 592 * For linklocal case, the hardware index (hw_idx) is always 0 and there are 593 * two entries for MACs/MAC_MASK . Thus, sw_idx could be 0 or 1, but the 594 * hw_idx is 0 all the time. 595 */ 596 uint32 hw_idx; 597 link_local_mac_address_entry_t link_local_mac_addr_ent; 598 egr_link_local_mac_address_entry_t egr_link_local_mac_addr_ent; 599 soc_field_t mac_field, mac_mask_field; 600 601 /* Parameter NULL error handling */ 602 GH2_MATCH_CHECK_NULL_PARAMETER(unit, config_info); 603 604 if (sw_idx == 0) { 605 mac_field = MAC_ADDRESS_1f; 606 mac_mask_field = MASK_1f; 607 } else if (sw_idx == 1) { 608 mac_field = MAC_ADDRESS_2f; 609 mac_mask_field = MASK_2f; 610 } else { 611 LOG_ERROR(BSL_LS_BCM_SWITCH, 612 (BSL_META_U(unit, 613 "Invalid sw_idx.\n"))); 614 return BCM_E_RESOURCE; 615 } 616 sal_memset(&link_local_mac_addr_ent, 0, 617 sizeof(link_local_mac_address_entry_t)); 618 sal_memset(&egr_link_local_mac_addr_ent, 0, 619 sizeof(egr_link_local_mac_address_entry_t)); 620 621 /* The hw index for linklocal is always 0 */ 622 hw_idx = 0; 623 624 /* Write MAC_ADDRESS/ADDRESS_MASK to LINK_LOCAL_MAC_ADDRESSm */ 625 BCM_IF_ERROR_RETURN 626 (soc_mem_read(unit, LINK_LOCAL_MAC_ADDRESSm, MEM_BLOCK_ANY, 627 hw_idx, &link_local_mac_addr_ent)); 628 629 soc_LINK_LOCAL_MAC_ADDRESSm_mac_addr_set(unit, 630 &link_local_mac_addr_ent, 631 mac_field, 632 config_info->dst_mac); 633 soc_LINK_LOCAL_MAC_ADDRESSm_mac_addr_set(unit, 634 &link_local_mac_addr_ent, 635 mac_mask_field, 636 config_info->dst_mac_mask); 637 638 BCM_IF_ERROR_RETURN 639 (soc_mem_write(unit, LINK_LOCAL_MAC_ADDRESSm, MEM_BLOCK_ALL, 640 hw_idx, &link_local_mac_addr_ent)); 641 642 /* Write MAC_ADDRESS/ADDRESS_MASK to EGR_LINK_LOCAL_MAC_ADDRESSm */ 643 BCM_IF_ERROR_RETURN 644 (soc_mem_read(unit, EGR_LINK_LOCAL_MAC_ADDRESSm, MEM_BLOCK_ANY, 645 hw_idx, &egr_link_local_mac_addr_ent)); 646 soc_EGR_LINK_LOCAL_MAC_ADDRESSm_mac_addr_set(unit, 647 &egr_link_local_mac_addr_ent, 648 mac_field, 649 config_info->dst_mac); 650 soc_EGR_LINK_LOCAL_MAC_ADDRESSm_mac_addr_set(unit, 651 &egr_link_local_mac_addr_ent, 652 mac_mask_field, 653 config_info->dst_mac_mask); 654 655 BCM_IF_ERROR_RETURN 656 (soc_mem_write(unit, EGR_LINK_LOCAL_MAC_ADDRESSm, MEM_BLOCK_ALL, 657 hw_idx, &egr_link_local_mac_addr_ent)); 658 659 return BCM_E_NONE; 660 } 661 662 /* 663 * Function: 664 * bcmi_gh2_hsrprp_sup_match_config_add 665 * Purpose: 666 * Add a match config, return match_id after matched 667 * config created. 668 * Parameters: 669 * unit - (IN) Unit number 670 * config_info - (IN) Match configuration 671 * sw_idx - (OUT) SW memory index 672 * Returns: 673 * BCM_E_xxx 674 */ 675 STATIC int 676 bcmi_gh2_hsrprp_sup_match_config_add( 677 int unit, 678 bcm_switch_match_config_info_t *config_info, 679 uint32 *sw_idx) 680 { 681 /* 682 * The tables size of HSRPRP/DOT1CB is only with 1 hw entry. So, forcing to 683 * write 0 means to write the only entry. Further more in HSRPRP/DOT1CB 684 * cases, sw_idx should be the same as hw_idx all the time. 685 */ 686 uint32 hw_idx = 0; 687 688 /* Parameter NULL error handling */ 689 GH2_MATCH_CHECK_NULL_PARAMETER(unit, config_info); 690 GH2_MATCH_CHECK_NULL_PARAMETER(unit, sw_idx); 691 692 BCM_IF_ERROR_RETURN 693 (bcmi_gh2_hsrprp_sup_match_config_write(unit, 694 hw_idx, 695 config_info)); 696 *sw_idx = hw_idx; 697 return BCM_E_NONE; 698 } 699 700 /* 701 * Function: 702 * bcmi_gh2_dot1cb_sup_match_config_add 703 * Purpose: 704 * Add a match config, return match_id after matched 705 * config created. 706 * Parameters: 707 * unit - (IN) Unit number 708 * config_info - (IN) Match configuration 709 * sw_idx - (OUT) SW memory index 710 * Returns: 711 * BCM_E_xxx 712 */ 713 STATIC int 714 bcmi_gh2_dot1cb_sup_match_config_add( 715 int unit, 716 bcm_switch_match_config_info_t *config_info, 717 uint32 *sw_idx) 718 { 719 /* 720 * The tables size of HSRPRP/DOT1CB is only with 1 hw entry. So, forcing to 721 * write 0 means to write the only entry. Further more in HSRPRP/DOT1CB 722 * cases, sw_idx should be the same as hw_idx all the time. 723 */ 724 uint32 hw_idx = 0; 725 726 /* Parameter NULL error handling */ 727 GH2_MATCH_CHECK_NULL_PARAMETER(unit, config_info); 728 GH2_MATCH_CHECK_NULL_PARAMETER(unit, sw_idx); 729 730 BCM_IF_ERROR_RETURN 731 (bcmi_gh2_dot1cb_sup_match_config_write(unit, 732 hw_idx, 733 config_info)); 734 *sw_idx = hw_idx; 735 return BCM_E_NONE; 736 } 737 738 739 /* 740 * Function: 741 * bcmi_gh2_linklocal_match_config_add 742 * Purpose: 743 * Add a match config, return match_id after matched 744 * config created. 745 * Parameters: 746 * unit - (IN) Unit number 747 * config_info - (IN) Match configuration 748 * sw_idx - (OUT) SW memory index 749 * Returns: 750 * BCM_E_xxx 751 */ 752 STATIC int 753 bcmi_gh2_linklocal_match_config_add( 754 int unit, 755 bcm_switch_match_config_info_t *config_info, 756 uint32 *sw_idx) 757 { 758 /* 759 * For linklocal case, the hardware index (hw_idx) is always 0 and there are 760 * two entries for MACs/MAC_MASK . Thus, sw_idx could be 0 or 1, but the 761 * hw_idx is 0 all the time. 762 * sw_idx == 0 is for MAC_ADDRESS_1f & MASK_1f 763 * sw_idx == 1 is for MAC_ADDRESS_2f & MASK_2f 764 */ 765 uint32 hw_idx = 0; 766 link_local_mac_address_entry_t link_local_mac_addr_ent; 767 egr_link_local_mac_address_entry_t egr_link_local_mac_addr_ent; 768 bcm_mac_t tmp_mac_mask1, tmp_mac_mask2; 769 770 /* Parameter NULL error handling */ 771 GH2_MATCH_CHECK_NULL_PARAMETER(unit, config_info); 772 GH2_MATCH_CHECK_NULL_PARAMETER(unit, sw_idx); 773 774 sal_memset(&link_local_mac_addr_ent, 0, 775 sizeof(link_local_mac_address_entry_t)); 776 sal_memset(&egr_link_local_mac_addr_ent, 0, 777 sizeof(egr_link_local_mac_address_entry_t)); 778 779 BCM_IF_ERROR_RETURN 780 (soc_mem_read(unit, LINK_LOCAL_MAC_ADDRESSm, MEM_BLOCK_ANY, 781 hw_idx, &link_local_mac_addr_ent)); 782 soc_LINK_LOCAL_MAC_ADDRESSm_mac_addr_get(unit, 783 &link_local_mac_addr_ent, 784 MASK_1f, 785 tmp_mac_mask1); 786 soc_LINK_LOCAL_MAC_ADDRESSm_mac_addr_get(unit, 787 &link_local_mac_addr_ent, 788 MASK_2f, 789 tmp_mac_mask2); 790 791 /* If the MASK_1f/2f == GH2_EMPTY_MACADDR_MASK, then it's empty */ 792 if (SAL_MAC_ADDR_EQUAL(tmp_mac_mask1, GH2_EMPTY_MACADDR_MASK)) { 793 *sw_idx = 0; 794 } else if (SAL_MAC_ADDR_EQUAL(tmp_mac_mask2, GH2_EMPTY_MACADDR_MASK)) { 795 *sw_idx = 1; 796 } else { 797 LOG_ERROR(BSL_LS_BCM_SWITCH, 798 (BSL_META_U(unit, 799 "bcm_gh2_linklocal_match_config_add failed: " 800 "No hardware resource.\n"))); 801 return BCM_E_RESOURCE; 802 } 803 804 /* linklocal's hw_idx is always 0 with MAC_ADDRESS_1f/2f & MASK_1f/2f */ 805 BCM_IF_ERROR_RETURN 806 (bcmi_gh2_linklocal_match_config_write(unit, 807 *sw_idx, 808 config_info)); 809 return BCM_E_NONE; 810 } 811 812 /* 813 * Function: 814 * bcmi_gh2_hsrprp_sup_match_config_delete 815 * Purpose: 816 * Destroy a match ID by removing it from hardware. 817 * Parameters: 818 * unit - (IN) Unit number 819 * sw_idx - (IN) SW memory index 820 * Returns: 821 * BCM_E_XXX 822 */ 823 STATIC int 824 bcmi_gh2_hsrprp_sup_match_config_delete( 825 int unit, 826 uint32 sw_idx) 827 { 828 uint32 hw_idx = sw_idx; 829 sr_ethertypes_entry_t sr_ethertypes_entry; 830 egr_sr_ethertypes_entry_t egr_sr_ethertypes_entry; 831 sr_supervisory_mac_address_entry_t sr_sup_mac_address_entry; 832 833 sal_memset(&sr_ethertypes_entry, 0, 834 sizeof(sr_ethertypes_entry_t)); 835 sal_memset(&egr_sr_ethertypes_entry, 0, 836 sizeof(egr_sr_ethertypes_entry_t)); 837 sal_memset(&sr_sup_mac_address_entry, 0, 838 sizeof(sr_supervisory_mac_address_entry_t)); 839 840 /* Write PRP/HSR_SUPERVISION_ETHERTYPE to SR_ETHERTYPESm */ 841 BCM_IF_ERROR_RETURN 842 (soc_mem_read(unit, SR_ETHERTYPESm, MEM_BLOCK_ANY, 843 hw_idx, &sr_ethertypes_entry)); 844 soc_mem_field32_set(unit, SR_ETHERTYPESm, &sr_ethertypes_entry, 845 PRP_SUPERVISION_ETHERTYPEf, 846 GH2_ETHERTYPE_EMPTY_VALUE); 847 soc_mem_field32_set(unit, SR_ETHERTYPESm, &sr_ethertypes_entry, 848 HSR_SUPERVISION_ETHERTYPEf, 849 GH2_ETHERTYPE_EMPTY_VALUE); 850 BCM_IF_ERROR_RETURN 851 (soc_mem_write(unit, SR_ETHERTYPESm, MEM_BLOCK_ALL, 852 hw_idx, &sr_ethertypes_entry)); 853 854 /* Write PRP/HSR_SUPERVISION_ETHERTYPE to EGR_SR_ETHERTYPESm */ 855 BCM_IF_ERROR_RETURN 856 (soc_mem_read(unit, EGR_SR_ETHERTYPESm, MEM_BLOCK_ANY, 857 hw_idx, &egr_sr_ethertypes_entry)); 858 soc_mem_field32_set(unit, EGR_SR_ETHERTYPESm, &egr_sr_ethertypes_entry, 859 PRP_SUPERVISION_ETHERTYPEf, 860 GH2_ETHERTYPE_EMPTY_VALUE); 861 soc_mem_field32_set(unit, EGR_SR_ETHERTYPESm, &egr_sr_ethertypes_entry, 862 HSR_SUPERVISION_ETHERTYPEf, 863 GH2_ETHERTYPE_EMPTY_VALUE); 864 BCM_IF_ERROR_RETURN 865 (soc_mem_write(unit, EGR_SR_ETHERTYPESm, MEM_BLOCK_ALL, 866 hw_idx, &egr_sr_ethertypes_entry)); 867 868 /* Write MAC_ADDRESS/ADDRESS_MASK to SR_SUPERVISORY_MAC_ADDRESSm */ 869 BCM_IF_ERROR_RETURN 870 (soc_mem_read(unit, SR_SUPERVISORY_MAC_ADDRESSm, MEM_BLOCK_ANY, 871 hw_idx, &sr_sup_mac_address_entry)); 872 soc_SR_SUPERVISORY_MAC_ADDRESSm_mac_addr_set(unit, 873 &sr_sup_mac_address_entry, 874 MAC_ADDRESSf, 875 GH2_EMPTY_MACADDR); 876 soc_SR_SUPERVISORY_MAC_ADDRESSm_mac_addr_set(unit, 877 &sr_sup_mac_address_entry, 878 MAC_ADDRESS_MASKf, 879 GH2_EMPTY_MACADDR_MASK); 880 881 BCM_IF_ERROR_RETURN 882 (soc_mem_write(unit, SR_SUPERVISORY_MAC_ADDRESSm, MEM_BLOCK_ALL, 883 hw_idx, &sr_sup_mac_address_entry)); 884 885 return BCM_E_NONE; 886 } 887 888 /* 889 * Function: 890 * bcmi_gh2_dot1cb_sup_match_config_delete 891 * Purpose: 892 * Destroy a match ID by removing it from hardware. 893 * Parameters: 894 * unit - (IN) Unit number 895 * sw_idx - (IN) SW memory index 896 * Returns: 897 * BCM_E_XXX 898 */ 899 STATIC int 900 bcmi_gh2_dot1cb_sup_match_config_delete( 901 int unit, 902 uint32 sw_idx) 903 { 904 uint32 hw_idx = sw_idx; 905 sr_ethertypes_entry_t sr_ethertypes_entry; 906 egr_sr_ethertypes_entry_t egr_sr_ethertypes_entry; 907 sr_supervisory_mac_address_dot1cb_entry_t sr_sup_mac_address_dot1cb_entry; 908 909 sal_memset(&sr_ethertypes_entry, 0, 910 sizeof(sr_ethertypes_entry_t)); 911 sal_memset(&egr_sr_ethertypes_entry, 0, 912 sizeof(egr_sr_ethertypes_entry_t)); 913 sal_memset(&sr_sup_mac_address_dot1cb_entry, 0, 914 sizeof(sr_supervisory_mac_address_dot1cb_entry_t)); 915 916 /* Write DOT1CB_SUPERVISION_ETHERTYPE to SR_ETHERTYPESm */ 917 BCM_IF_ERROR_RETURN 918 (soc_mem_read(unit, SR_ETHERTYPESm, MEM_BLOCK_ANY, 919 hw_idx, &sr_ethertypes_entry)); 920 soc_mem_field32_set(unit, SR_ETHERTYPESm, 921 &sr_ethertypes_entry, 922 DOT1CB_SUPERVISION_ETHERTYPEf, 923 GH2_ETHERTYPE_EMPTY_VALUE); 924 BCM_IF_ERROR_RETURN 925 (soc_mem_write(unit, SR_ETHERTYPESm, MEM_BLOCK_ALL, 926 hw_idx, &sr_ethertypes_entry)); 927 928 /* Write DOT1CB_SUPERVISION_ETHERTYPE to EGR_SR_ETHERTYPESm */ 929 BCM_IF_ERROR_RETURN 930 (soc_mem_read(unit, EGR_SR_ETHERTYPESm, MEM_BLOCK_ANY, 931 hw_idx, &egr_sr_ethertypes_entry)); 932 soc_mem_field32_set(unit, EGR_SR_ETHERTYPESm, 933 &egr_sr_ethertypes_entry, 934 DOT1CB_SUPERVISION_ETHERTYPEf, 935 GH2_ETHERTYPE_EMPTY_VALUE); 936 BCM_IF_ERROR_RETURN 937 (soc_mem_write(unit, EGR_SR_ETHERTYPESm, MEM_BLOCK_ALL, 938 hw_idx, &egr_sr_ethertypes_entry)); 939 940 /* Write MAC_ADDRESS/ADDRESS_MASK to SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm */ 941 BCM_IF_ERROR_RETURN 942 (soc_mem_read(unit, SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, MEM_BLOCK_ANY, 943 hw_idx, &sr_sup_mac_address_dot1cb_entry)); 944 945 soc_mem_mac_addr_set(unit, 946 SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, 947 &sr_sup_mac_address_dot1cb_entry, 948 MAC_ADDRESSf, 949 GH2_EMPTY_MACADDR); 950 soc_mem_mac_addr_set(unit, 951 SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, 952 &sr_sup_mac_address_dot1cb_entry, 953 MAC_ADDRESS_MASKf, 954 GH2_EMPTY_MACADDR_MASK); 955 956 BCM_IF_ERROR_RETURN 957 (soc_mem_write(unit, SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, MEM_BLOCK_ALL, 958 hw_idx, &sr_sup_mac_address_dot1cb_entry)); 959 960 return BCM_E_NONE; 961 } 962 963 /* 964 * Function: 965 * bcmi_gh2_linklocal_match_config_delete 966 * Purpose: 967 * Destroy a match ID by removing it from hardware. 968 * Parameters: 969 * unit - (IN) Unit number 970 * sw_idx - (IN) SW memory index 971 * Returns: 972 * BCM_E_XXX 973 */ 974 STATIC int 975 bcmi_gh2_linklocal_match_config_delete( 976 int unit, 977 uint32 sw_idx) 978 { 979 /* 980 * For linklocal case, the hardware index (hw_idx) is always 0 and there are 981 * two entries for MACs/MAC_MASK . Thus, sw_idx could be 0 or 1, but the 982 * hw_idx is 0 all the time. 983 */ 984 uint32 hw_idx = 0; 985 link_local_mac_address_entry_t link_local_mac_addr_ent; 986 egr_link_local_mac_address_entry_t egr_link_local_mac_addr_ent; 987 soc_field_t mac_field, mac_mask_field; 988 989 if (sw_idx == 0) { 990 mac_field = MAC_ADDRESS_1f; 991 mac_mask_field = MASK_1f; 992 } else if (sw_idx == 1) { 993 mac_field = MAC_ADDRESS_2f; 994 mac_mask_field = MASK_2f; 995 } else { 996 LOG_ERROR(BSL_LS_BCM_SWITCH, 997 (BSL_META_U(unit, 998 "Invalid sw_idx.\n"))); 999 return BCM_E_RESOURCE; 1000 } 1001 sal_memset(&link_local_mac_addr_ent, 0, 1002 sizeof(link_local_mac_address_entry_t)); 1003 sal_memset(&egr_link_local_mac_addr_ent, 0, 1004 sizeof(egr_link_local_mac_address_entry_t)); 1005 1006 /* Write MAC_ADDRESS/ADDRESS_MASK to LINK_LOCAL_MAC_ADDRESSm */ 1007 BCM_IF_ERROR_RETURN 1008 (soc_mem_read(unit, LINK_LOCAL_MAC_ADDRESSm, MEM_BLOCK_ANY, 1009 hw_idx, &link_local_mac_addr_ent)); 1010 1011 soc_LINK_LOCAL_MAC_ADDRESSm_mac_addr_set(unit, 1012 &link_local_mac_addr_ent, 1013 mac_field, 1014 GH2_EMPTY_MACADDR); 1015 soc_LINK_LOCAL_MAC_ADDRESSm_mac_addr_set(unit, 1016 &link_local_mac_addr_ent, 1017 mac_mask_field, 1018 GH2_EMPTY_MACADDR_MASK); 1019 1020 BCM_IF_ERROR_RETURN 1021 (soc_mem_write(unit, LINK_LOCAL_MAC_ADDRESSm, MEM_BLOCK_ALL, 1022 hw_idx, &link_local_mac_addr_ent)); 1023 1024 /* Write MAC_ADDRESS/ADDRESS_MASK to EGR_LINK_LOCAL_MAC_ADDRESSm */ 1025 BCM_IF_ERROR_RETURN 1026 (soc_mem_read(unit, EGR_LINK_LOCAL_MAC_ADDRESSm, MEM_BLOCK_ANY, 1027 hw_idx, &egr_link_local_mac_addr_ent)); 1028 soc_EGR_LINK_LOCAL_MAC_ADDRESSm_mac_addr_set(unit, 1029 &egr_link_local_mac_addr_ent, 1030 mac_field, 1031 GH2_EMPTY_MACADDR); 1032 soc_EGR_LINK_LOCAL_MAC_ADDRESSm_mac_addr_set(unit, 1033 &egr_link_local_mac_addr_ent, 1034 mac_mask_field, 1035 GH2_EMPTY_MACADDR_MASK); 1036 1037 BCM_IF_ERROR_RETURN 1038 (soc_mem_write(unit, EGR_LINK_LOCAL_MAC_ADDRESSm, MEM_BLOCK_ALL, 1039 hw_idx, &egr_link_local_mac_addr_ent)); 1040 1041 return BCM_E_NONE; 1042 } 1043 1044 /* 1045 * Function: 1046 * bcmi_gh2_hsrprp_sup_match_config_get 1047 * Purpose: 1048 * Get the match configuration from hardware 1049 * Parameters: 1050 * unit - (IN) Unit number 1051 * sw_idx - (IN) SW memory index 1052 * config_info - (OUT) Match configuration 1053 * Returns: 1054 * BCM_E_xxx 1055 */ 1056 STATIC int 1057 bcmi_gh2_hsrprp_sup_match_config_get( 1058 int unit, 1059 uint32 sw_idx, 1060 bcm_switch_match_config_info_t *config_info) 1061 { 1062 uint32 hw_idx = sw_idx; 1063 uint32 rval = 0; 1064 sr_ethertypes_entry_t sr_ethertypes_entry; 1065 sr_supervisory_mac_address_entry_t sr_sup_mac_address_entry; 1066 1067 /* Parameter NULL error handling */ 1068 GH2_MATCH_CHECK_NULL_PARAMETER(unit, config_info); 1069 1070 sal_memset(&sr_ethertypes_entry, 0, 1071 sizeof(sr_ethertypes_entry_t)); 1072 sal_memset(&sr_sup_mac_address_entry, 0, 1073 sizeof(sr_supervisory_mac_address_entry_t)); 1074 1075 /* 1076 * Get PRP/HSR_SUPERVISION_ETHERTYPE from SR_ETHERTYPESm 1077 * Note: 1078 * Only retrieve Ethernet Type from SR_ETHERTYPES since both 1079 * SR_ETHERTYPES/EGR_SR_ETHERTYPES are filled with the same Ethernet Type 1080 */ 1081 BCM_IF_ERROR_RETURN 1082 (soc_mem_read(unit, SR_ETHERTYPESm, MEM_BLOCK_ANY, 1083 hw_idx, &sr_ethertypes_entry)); 1084 rval = soc_mem_field32_get(unit, SR_ETHERTYPESm, &sr_ethertypes_entry, 1085 PRP_SUPERVISION_ETHERTYPEf); 1086 config_info->ethtype1 = rval; 1087 rval = soc_mem_field32_get(unit, SR_ETHERTYPESm, &sr_ethertypes_entry, 1088 HSR_SUPERVISION_ETHERTYPEf); 1089 config_info->ethtype2 = rval; 1090 1091 /* Get MAC_ADDRESS/ADDRESS_MASK from SR_SUPERVISORY_MAC_ADDRESSm */ 1092 BCM_IF_ERROR_RETURN 1093 (soc_mem_read(unit, SR_SUPERVISORY_MAC_ADDRESSm, MEM_BLOCK_ANY, 1094 hw_idx, &sr_sup_mac_address_entry)); 1095 1096 soc_SR_SUPERVISORY_MAC_ADDRESSm_mac_addr_get(unit, 1097 &sr_sup_mac_address_entry, 1098 MAC_ADDRESSf, 1099 config_info->dst_mac); 1100 soc_SR_SUPERVISORY_MAC_ADDRESSm_mac_addr_get(unit, 1101 &sr_sup_mac_address_entry, 1102 MAC_ADDRESS_MASKf, 1103 config_info->dst_mac_mask); 1104 1105 return BCM_E_NONE; 1106 } 1107 1108 /* 1109 * Function: 1110 * bcmi_gh2_dot1cb_sup_match_config_get 1111 * Purpose: 1112 * Get the match configuration from hardware 1113 * Parameters: 1114 * unit - (IN) Unit number 1115 * sw_idx - (IN) SW memory index 1116 * config_info - (OUT) Match configuration 1117 * Returns: 1118 * BCM_E_xxx 1119 */ 1120 STATIC int 1121 bcmi_gh2_dot1cb_sup_match_config_get( 1122 int unit, 1123 uint32 sw_idx, 1124 bcm_switch_match_config_info_t *config_info) 1125 { 1126 uint32 hw_idx = sw_idx; 1127 uint32 rval = 0; 1128 sr_ethertypes_entry_t sr_ethertypes_entry; 1129 sr_supervisory_mac_address_dot1cb_entry_t sr_sup_mac_address_dot1cb_entry; 1130 1131 /* Parameter NULL error handling */ 1132 GH2_MATCH_CHECK_NULL_PARAMETER(unit, config_info); 1133 1134 sal_memset(&sr_ethertypes_entry, 0, 1135 sizeof(sr_ethertypes_entry_t)); 1136 sal_memset(&sr_sup_mac_address_dot1cb_entry, 0, 1137 sizeof(sr_supervisory_mac_address_dot1cb_entry_t)); 1138 1139 /* 1140 * Get DOT1CB_SUPERVISION_ETHERTYPE from SR_ETHERTYPESm 1141 * Note: 1142 * Only retrive Ethernet Type from SR_ETHERTYPES since both 1143 * SR_ETHERTYPES/EGR_SR_ETHERTYPES are filled with the same Ethernet Type 1144 */ 1145 BCM_IF_ERROR_RETURN 1146 (soc_mem_read(unit, SR_ETHERTYPESm, MEM_BLOCK_ANY, 1147 hw_idx, &sr_ethertypes_entry)); 1148 rval = soc_mem_field32_get(unit, SR_ETHERTYPESm, &sr_ethertypes_entry, 1149 DOT1CB_SUPERVISION_ETHERTYPEf); 1150 config_info->ethtype1 = rval; 1151 1152 /* Get MAC_ADDRESS/ADDRESS_MASK from SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm */ 1153 BCM_IF_ERROR_RETURN 1154 (soc_mem_read(unit, SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, MEM_BLOCK_ANY, 1155 hw_idx, &sr_sup_mac_address_dot1cb_entry)); 1156 1157 1158 soc_mem_mac_addr_get(unit, SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, 1159 &sr_sup_mac_address_dot1cb_entry, 1160 MAC_ADDRESSf, config_info->dst_mac); 1161 soc_mem_mac_addr_get(unit, SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, 1162 &sr_sup_mac_address_dot1cb_entry, 1163 MAC_ADDRESS_MASKf, config_info->dst_mac_mask); 1164 1165 return BCM_E_NONE; 1166 } 1167 1168 /* 1169 * Function: 1170 * bcmi_gh2_linklocal_match_config_get 1171 * Purpose: 1172 * Get the match configuration from hardware 1173 * Parameters: 1174 * unit - (IN) Unit number 1175 * sw_idx - (IN) SW memory index 1176 * config_info - (OUT) Match configuration 1177 * Returns: 1178 * BCM_E_xxx 1179 */ 1180 STATIC int 1181 bcmi_gh2_linklocal_match_config_get( 1182 int unit, 1183 uint32 sw_idx, 1184 bcm_switch_match_config_info_t *config_info) 1185 { 1186 /* 1187 * For linklocal case, the hardware index (hw_idx) is always 0 and there are 1188 * two entries for MACs/MAC_MASK . Thus, sw_idx could be 0 or 1, but the 1189 * hw_idx is 0 all the time. 1190 */ 1191 uint32 hw_idx = 0; 1192 link_local_mac_address_entry_t link_local_mac_addr_ent; 1193 soc_field_t mac_field, mac_mask_field; 1194 1195 /* Parameter NULL error handling */ 1196 GH2_MATCH_CHECK_NULL_PARAMETER(unit, config_info); 1197 1198 if (sw_idx == 0) { 1199 mac_field = MAC_ADDRESS_1f; 1200 mac_mask_field = MASK_1f; 1201 } else if (sw_idx == 1) { 1202 mac_field = MAC_ADDRESS_2f; 1203 mac_mask_field = MASK_2f; 1204 } else { 1205 LOG_ERROR(BSL_LS_BCM_SWITCH, 1206 (BSL_META_U(unit, 1207 "Invalid sw_idx.\n"))); 1208 return BCM_E_RESOURCE; 1209 } 1210 sal_memset(&link_local_mac_addr_ent, 0, 1211 sizeof(link_local_mac_address_entry_t)); 1212 1213 /* Get MAC_ADDRESS/ADDRESS_MASK to LINK_LOCAL_MAC_ADDRESSm */ 1214 BCM_IF_ERROR_RETURN 1215 (soc_mem_read(unit, LINK_LOCAL_MAC_ADDRESSm, MEM_BLOCK_ANY, 1216 hw_idx, &link_local_mac_addr_ent)); 1217 1218 soc_LINK_LOCAL_MAC_ADDRESSm_mac_addr_get(unit, 1219 &link_local_mac_addr_ent, 1220 mac_field, 1221 config_info->dst_mac); 1222 soc_LINK_LOCAL_MAC_ADDRESSm_mac_addr_get(unit, 1223 &link_local_mac_addr_ent, 1224 mac_mask_field, 1225 config_info->dst_mac_mask); 1226 1227 return BCM_E_NONE; 1228 } 1229 1230 /* 1231 * Function: 1232 * bcmi_gh2_hsrprp_sup_match_config_set 1233 * Purpose: 1234 * Set the match configuration from hardware 1235 * Parameters: 1236 * unit - (IN) Unit number 1237 * sw_idx - (IN) SW memory index 1238 * config_info - (IN) Match configuration 1239 * Returns: 1240 * BCM_E_xxx 1241 */ 1242 STATIC int 1243 bcmi_gh2_hsrprp_sup_match_config_set( 1244 int unit, 1245 uint32 sw_idx, 1246 bcm_switch_match_config_info_t *config_info) 1247 { 1248 uint32 hw_idx = sw_idx; 1249 1250 /* Parameter NULL error handling */ 1251 GH2_MATCH_CHECK_NULL_PARAMETER(unit, config_info); 1252 1253 BCM_IF_ERROR_RETURN 1254 (bcmi_gh2_hsrprp_sup_match_config_write(unit, 1255 hw_idx, 1256 config_info)); 1257 return BCM_E_NONE; 1258 } 1259 1260 /* 1261 * Function: 1262 * bcmi_gh2_dot1cb_sup_match_config_set 1263 * Purpose: 1264 * Set the match configuration from hardware 1265 * Parameters: 1266 * unit - (IN) Unit number 1267 * sw_idx - (IN) SW memory index 1268 * config_info - (IN) Match configuration 1269 * Returns: 1270 * BCM_E_xxx 1271 */ 1272 STATIC int 1273 bcmi_gh2_dot1cb_sup_match_config_set( 1274 int unit, 1275 uint32 sw_idx, 1276 bcm_switch_match_config_info_t *config_info) 1277 { 1278 uint32 hw_idx = sw_idx; 1279 1280 /* Parameter NULL error handling */ 1281 GH2_MATCH_CHECK_NULL_PARAMETER(unit, config_info); 1282 1283 BCM_IF_ERROR_RETURN 1284 (bcmi_gh2_dot1cb_sup_match_config_write(unit, 1285 hw_idx, 1286 config_info)); 1287 return BCM_E_NONE; 1288 } 1289 1290 /* 1291 * Function: 1292 * bcmi_gh2_linklocal_match_config_set 1293 * Purpose: 1294 * Set the match configuration from hardware 1295 * Parameters: 1296 * unit - (IN) Unit number 1297 * sw_idx - (IN) SW memory index 1298 * config_info - (IN) Match configuration 1299 * Returns: 1300 * BCM_E_xxx 1301 */ 1302 STATIC int 1303 bcmi_gh2_linklocal_match_config_set( 1304 int unit, 1305 uint32 sw_idx, 1306 bcm_switch_match_config_info_t *config_info) 1307 { 1308 /* Parameter NULL error handling */ 1309 GH2_MATCH_CHECK_NULL_PARAMETER(unit, config_info); 1310 1311 if ((sw_idx != 0) && (sw_idx != 1)) { 1312 LOG_ERROR(BSL_LS_BCM_SWITCH, 1313 (BSL_META_U(unit, 1314 "Invalid sw_idx.\n"))); 1315 return BCM_E_RESOURCE; 1316 } 1317 1318 /* linklocal's hw_idx is always 0 with MAC_ADDRESS_1f/2f & MASK_1f/2f */ 1319 BCM_IF_ERROR_RETURN 1320 (bcmi_gh2_linklocal_match_config_write(unit, 1321 sw_idx, 1322 config_info)); 1323 1324 return BCM_E_NONE; 1325 } 1326 1327 /* 1328 * Function: 1329 * bcmi_gh2_hsrprp_sup_match_wb_hw_existed 1330 * Purpose: 1331 * check if the HW existed value or not 1332 * Parameters: 1333 * unit - (IN) Unit being initialized 1334 * sw_idx - (IN) memory index 1335 * Returns: 1336 * BCM_E_NOT_FOUND means HW doesn't exist 1337 * BCM_E_NONE means HW existed 1338 */ 1339 STATIC int 1340 bcmi_gh2_hsrprp_sup_match_wb_hw_existed( 1341 int unit, 1342 uint32 sw_idx) 1343 { 1344 #if defined(BCM_WARM_BOOT_SUPPORT) 1345 uint32 hw_idx = sw_idx; 1346 bcm_mac_t mac_mask; 1347 sr_supervisory_mac_address_entry_t sr_sup_mac_address_entry; 1348 1349 sal_memset(&sr_sup_mac_address_entry, 0, 1350 sizeof(sr_supervisory_mac_address_entry_t)); 1351 1352 /* Get MAC_ADDRESS_MASK from SR_SUPERVISORY_MAC_ADDRESSm */ 1353 BCM_IF_ERROR_RETURN 1354 (soc_mem_read(unit, SR_SUPERVISORY_MAC_ADDRESSm, MEM_BLOCK_ANY, 1355 hw_idx, &sr_sup_mac_address_entry)); 1356 1357 soc_SR_SUPERVISORY_MAC_ADDRESSm_mac_addr_get(unit, 1358 &sr_sup_mac_address_entry, 1359 MAC_ADDRESS_MASKf, 1360 mac_mask); 1361 1362 if (SAL_MAC_ADDR_EQUAL(mac_mask, GH2_EMPTY_MACADDR_MASK)) { 1363 /* Return BCM_E_NOT_FOUND means HW doesn't exist */ 1364 return BCM_E_NOT_FOUND; 1365 } 1366 /* BCM_E_NONE means HW existed */ 1367 return BCM_E_NONE; 1368 #else /* BCM_WARM_BOOT_SUPPORT */ 1369 return BCM_E_UNAVAIL; 1370 #endif /* BCM_WARM_BOOT_SUPPORT */ 1371 } 1372 1373 /* 1374 * Function: 1375 * bcmi_gh2_dot1cb_sup_match_wb_hw_existed 1376 * Purpose: 1377 * check if the HW existed value or not 1378 * Parameters: 1379 * unit - (IN) Unit being initialized 1380 * sw_idx - (IN) memory index 1381 * Returns: 1382 * BCM_E_NOT_FOUND means HW doesn't exist 1383 * BCM_E_NONE means HW existed 1384 */ 1385 STATIC int 1386 bcmi_gh2_dot1cb_sup_match_wb_hw_existed( 1387 int unit, 1388 uint32 sw_idx) 1389 { 1390 #if defined(BCM_WARM_BOOT_SUPPORT) 1391 uint32 hw_idx = sw_idx; 1392 bcm_mac_t mac_mask; 1393 sr_supervisory_mac_address_dot1cb_entry_t sr_sup_mac_address_dot1cb_entry; 1394 1395 sal_memset(&sr_sup_mac_address_dot1cb_entry, 0, 1396 sizeof(sr_supervisory_mac_address_dot1cb_entry_t)); 1397 1398 /* Get MAC_ADDRESS_MASK from SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm */ 1399 BCM_IF_ERROR_RETURN 1400 (soc_mem_read(unit, SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, MEM_BLOCK_ANY, 1401 hw_idx, &sr_sup_mac_address_dot1cb_entry)); 1402 1403 soc_mem_mac_addr_get(unit, SR_SUPERVISORY_MAC_ADDRESS_DOT1CBm, 1404 &sr_sup_mac_address_dot1cb_entry, 1405 MAC_ADDRESS_MASKf, mac_mask); 1406 1407 1408 if (SAL_MAC_ADDR_EQUAL(mac_mask, GH2_EMPTY_MACADDR_MASK)) { 1409 /* Return BCM_E_NOT_FOUND means HW doesn't exist */ 1410 return BCM_E_NOT_FOUND; 1411 } 1412 /* BCM_E_NONE means HW existed */ 1413 return BCM_E_NONE; 1414 #else /* BCM_WARM_BOOT_SUPPORT */ 1415 return BCM_E_UNAVAIL; 1416 #endif /* BCM_WARM_BOOT_SUPPORT */ 1417 } 1418 1419 /* 1420 * Function: 1421 * bcmi_gh2_linklocal_match_wb_hw_existed 1422 * Purpose: 1423 * check if the HW existed value or not 1424 * Parameters: 1425 * unit - (IN) Unit being initialized 1426 * sw_idx - (IN) memory index 1427 * Returns: 1428 * BCM_E_NOT_FOUND means HW doesn't exist 1429 * BCM_E_NONE means HW existed 1430 */ 1431 STATIC int 1432 bcmi_gh2_linklocal_match_wb_hw_existed( 1433 int unit, 1434 uint32 sw_idx) 1435 { 1436 #if defined(BCM_WARM_BOOT_SUPPORT) 1437 /* The hw index for linklocal is always 0 */ 1438 uint32 hw_idx = 0; 1439 bcm_mac_t mac_mask; 1440 1441 link_local_mac_address_entry_t link_local_mac_addr_ent; 1442 soc_field_t mac_mask_field; 1443 1444 sal_memset(&link_local_mac_addr_ent, 0, 1445 sizeof(link_local_mac_address_entry_t)); 1446 1447 if (sw_idx == 0) { 1448 mac_mask_field = MASK_1f; 1449 } else if (sw_idx == 1) { 1450 mac_mask_field = MASK_2f; 1451 } else { 1452 LOG_ERROR(BSL_LS_BCM_SWITCH, 1453 (BSL_META_U(unit, 1454 "Invalid sw_idx.\n"))); 1455 return BCM_E_RESOURCE; 1456 } 1457 1458 /* The hw index for linklocal is 0 */ 1459 hw_idx = 0; 1460 1461 /* Get MAC_ADDRESS_MASK from LINK_LOCAL_MAC_ADDRESSm */ 1462 BCM_IF_ERROR_RETURN 1463 (soc_mem_read(unit, LINK_LOCAL_MAC_ADDRESSm, MEM_BLOCK_ANY, 1464 hw_idx, &link_local_mac_addr_ent)); 1465 1466 soc_LINK_LOCAL_MAC_ADDRESSm_mac_addr_get(unit, 1467 &link_local_mac_addr_ent, 1468 mac_mask_field, 1469 mac_mask); 1470 1471 if (SAL_MAC_ADDR_EQUAL(mac_mask, GH2_EMPTY_MACADDR_MASK)) { 1472 /* Return BCM_E_NOT_FOUND means HW doesn't exist */ 1473 return BCM_E_NOT_FOUND; 1474 } 1475 /* BCM_E_NONE means HW existed */ 1476 return BCM_E_NONE; 1477 #else /* BCM_WARM_BOOT_SUPPORT */ 1478 return BCM_E_UNAVAIL; 1479 #endif /* BCM_WARM_BOOT_SUPPORT */ 1480 } 1481 1482 STATIC const 1483 bcmi_switch_match_service_info_t bcmi_gh2_hsrprp_sup_match_info = { 1484 "gh2_hsrprp_sup_match", /* table_name */ 1485 bcmi_gh2_hsrprp_sup_match_table_size_get, /* switch_match_table_size_get */ 1486 bcmi_gh2_hsrprp_sup_match_hw_idx_get, /* switch_match_hw_id_get */ 1487 bcmi_gh2_hsrprp_sup_match_sw_idx_get, /* switch_match_sw_idx_get */ 1488 bcmi_gh2_hsrprp_sup_match_wb_hw_existed, /* switch_match_wb_hw_existed */ 1489 bcmi_gh2_hsrprp_sup_match_config_add, /* switch_match_config_add */ 1490 bcmi_gh2_hsrprp_sup_match_config_delete, /* switch_match_config_delete */ 1491 bcmi_gh2_hsrprp_sup_match_config_get, /* switch_match_config_get */ 1492 bcmi_gh2_hsrprp_sup_match_config_set, /* switch_match_config_set */ 1493 NULL, /* switch_match_control_get */ 1494 NULL /* switch_match_control_set */ 1495 }; 1496 1497 STATIC const 1498 bcmi_switch_match_service_info_t bcmi_gh2_dot1cb_sup_match_info = { 1499 "gh2_dot1cb_sup_match", /* table_name */ 1500 bcmi_gh2_dot1cb_sup_match_table_size_get, /* switch_match_table_size_get */ 1501 bcmi_gh2_dot1cb_sup_match_hw_idx_get, /* switch_match_hw_id_get */ 1502 bcmi_gh2_dot1cb_sup_match_sw_idx_get, /* switch_match_sw_idx_get */ 1503 bcmi_gh2_dot1cb_sup_match_wb_hw_existed, /* switch_match_wb_hw_existed */ 1504 bcmi_gh2_dot1cb_sup_match_config_add, /* switch_match_config_add */ 1505 bcmi_gh2_dot1cb_sup_match_config_delete, /* switch_match_config_delete */ 1506 bcmi_gh2_dot1cb_sup_match_config_get, /* switch_match_config_get */ 1507 bcmi_gh2_dot1cb_sup_match_config_set, /* switch_match_config_set */ 1508 NULL, /* switch_match_control_get */ 1509 NULL /* switch_match_control_set */ 1510 }; 1511 1512 STATIC const 1513 bcmi_switch_match_service_info_t bcmi_gh2_linklocal_match_info = { 1514 "gh2_linklocal_match", /* table_name */ 1515 bcmi_gh2_linklocal_match_table_size_get, /* switch_match_table_size_get */ 1516 bcmi_gh2_linklocal_match_hw_id_get, /* switch_match_hw_id_get */ 1517 bcmi_gh2_linklocal_match_sw_idx_get, /* switch_match_sw_idx_get */ 1518 bcmi_gh2_linklocal_match_wb_hw_existed, /* switch_match_wb_hw_existed */ 1519 bcmi_gh2_linklocal_match_config_add, /* switch_match_config_add */ 1520 bcmi_gh2_linklocal_match_config_delete, /* switch_match_config_delete */ 1521 bcmi_gh2_linklocal_match_config_get, /* switch_match_config_get */ 1522 bcmi_gh2_linklocal_match_config_set, /* switch_match_config_set */ 1523 NULL, /* switch_match_control_get */ 1524 NULL /* switch_match_control_set */ 1525 }; 1526 1527 STATIC const bcmi_switch_match_dev_info_t bcmi_gh2_match_dev_info = { 1528 { /* service_info[bcmSwitchMatchService__Count] */ 1529 &bcmi_hr3_miml_match_info, /* Miml */ 1530 &bcmi_hr3_custom_hdr_match_info, /* Customer Header */ 1531 NULL, /* GTP */ 1532 &bcmi_gh2_hsrprp_sup_match_info, /* HsrPrp */ 1533 &bcmi_gh2_dot1cb_sup_match_info, /* Dot1cb */ 1534 &bcmi_gh2_linklocal_match_info /* LinkLocal */ 1535 } 1536 }; 1537 1538 /* 1539 * Function: 1540 * bcmi_gh2_switch_match_info_init 1541 * Purpose: 1542 * Setup the chip specific info. 1543 * Parameters: 1544 * unit - (IN) Unit being initialized 1545 * devinfo - (OUT) device info structure. 1546 * Returns: 1547 * none 1548 */ 1549 int 1550 bcmi_gh2_switch_match_dev_info_init( 1551 int unit, 1552 const bcmi_switch_match_dev_info_t **dev_info) 1553 { 1554 if (dev_info == NULL) { 1555 return BCM_E_PARAM; 1556 } 1557 1558 /* Return the chip info structure */ 1559 *dev_info = &bcmi_gh2_match_dev_info; 1560 return BCM_E_NONE; 1561 } 1562 #endif /* BCM_SWITCH_MATCH_SUPPORT */ 1563 #endif /* BCM_GREYHOUND2_SUPPORT */ 1564