macsec_cmn.c (20914B)
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: macsec_cmn.c 8 * Purpose: MACSEC software module intergation support 9 */ 10 11 #ifdef INCLUDE_MACSEC 12 13 #include <shared/bsl.h> 14 15 #include <soc/mem.h> 16 #include <soc/debug.h> 17 #include <soc/cm.h> 18 #include <soc/drv.h> 19 #include <soc/register.h> 20 #include <soc/memory.h> 21 #include <soc/phy.h> 22 #include <soc/ll.h> 23 #include <soc/ptable.h> 24 #include <soc/tucana.h> 25 #include <soc/firebolt.h> 26 #include <soc/xaui.h> 27 #include <soc/phyctrl.h> 28 #include <soc/phyreg.h> 29 #include <soc/macsecphy.h> 30 #include <sal/core/libc.h> 31 #include <bcm/debug.h> 32 33 #include <bcm_int/common/macsec_cmn.h> 34 35 #include <bcm_int/control.h> 36 #include <bcm_int/esw_dispatch.h> 37 38 #define UNIT_VALID(unit) \ 39 { \ 40 if (!BCM_UNIT_VALID(unit)) { return BCM_E_UNIT; } \ 41 } 42 43 static bmacsec_error_t error_tbl[] = { 44 BCM_E_NONE, 45 BCM_E_INTERNAL, 46 BCM_E_MEMORY, 47 BCM_E_PARAM, 48 BCM_E_EMPTY, 49 BCM_E_FULL, 50 BCM_E_NOT_FOUND, 51 BCM_E_EXISTS, 52 BCM_E_TIMEOUT, 53 BCM_E_FAIL, 54 BCM_E_DISABLED, 55 BCM_E_BADID, 56 BCM_E_RESOURCE, 57 BCM_E_CONFIG, 58 BCM_E_UNAVAIL, 59 BCM_E_INIT, 60 BCM_E_PORT, 61 }; 62 /* 63 * Convert MACSEC return codes to BCM return code. 64 */ 65 #define BCM_ERROR(e) error_tbl[-(e)] 66 67 typedef struct _bcm_macsec_cb_args_s { 68 void *user_arg; 69 bcm_macsec_port_traverse_cb user_cb_port; 70 bcm_macsec_chan_traverse_cb user_cb_chan; 71 bcm_macsec_secure_assoc_traverse_cb user_cb_assoc; 72 bcm_macsec_flow_traverse_cb user_cb_flow; 73 int unit; 74 int port; 75 } _bcm_macsec_cb_args_t; 76 77 static int macsec_cb_registered = 0; 78 79 /* 80 * Function: 81 * bcm_common_macsec_init 82 * Purpose: 83 * Intiialize MACSEC for the specified unit. 84 */ 85 int _bcm_common_macsec_init(int unit) 86 { 87 static int _bmacsec_init_done = 0; 88 89 /* 90 * Do MACSEC init and MDIO registration for the MACSEC module. 91 */ 92 if (!_bmacsec_init_done) { 93 /* Initilaize the MACSEC module */ 94 bmacsec_init(); 95 /* register MDIO routines */ 96 bmacsec_dev_mmi_mdio_register(soc_macsecphy_miim_read, 97 soc_macsecphy_miim_write); 98 /* Initialize the default print vectors. */ 99 bmacsec_config_print_set(BMACSEC_PRINT_PRINTF, bsl_printf); 100 _bmacsec_init_done = 1; 101 } 102 return BCM_E_NONE; 103 } 104 105 /* 106 * Local port traverse handler to filter out ports belonging to specified 107 * unit. 108 */ 109 STATIC int 110 _bcm_macsec_port_traverse_cb(bmacsec_port_t p, 111 bmacsec_core_t dev_core, 112 bmacsec_dev_addr_t dev_addr, 113 int dev_port, 114 bmacsec_dev_io_f devio_f, 115 void *user_data) 116 { 117 int rv = BMACSEC_E_NONE ; 118 _bcm_macsec_cb_args_t *ua; 119 bcm_macsec_port_traverse_cb callback; 120 121 ua = (_bcm_macsec_cb_args_t*) user_data; 122 123 if (SOC_MACSEC_PORTID2UNIT(p) == ua->unit) { 124 callback = ua->user_cb_port; 125 rv = callback(SOC_MACSEC_PORTID2UNIT(p), 126 SOC_MACSEC_PORTID2PORT(p), 127 dev_core, dev_addr, 128 dev_port, devio_f, ua->user_arg); 129 } 130 return rv; 131 } 132 133 /* 134 * Function: 135 * bcm_macsec_port_traverse 136 * Purpose: 137 * Destroy a MACSEC Port 138 */ 139 int 140 bcm_common_macsec_port_traverse(int unit, 141 bcm_macsec_port_traverse_cb callback, 142 void *user_data) 143 { 144 int rv = BCM_E_UNAVAIL; 145 _bcm_macsec_cb_args_t ua; 146 147 UNIT_VALID(unit); 148 149 ua.user_arg = user_data; 150 ua.user_cb_port = callback; 151 ua.unit = unit; 152 153 rv = bmacsec_port_traverse(_bcm_macsec_port_traverse_cb, (void*) &ua); 154 155 return BCM_ERROR(rv); 156 } 157 158 /* 159 * Function: 160 * bcm_macsec_port_config_set 161 * Purpose: 162 * Set the MACSEC Port configuration. 163 */ 164 int 165 bcm_common_macsec_port_config_set(int unit, bcm_port_t port, 166 bcm_macsec_port_config_t *cfg) 167 { 168 int rv = BCM_E_UNAVAIL; 169 bmacsec_port_t p; 170 171 UNIT_VALID(unit); 172 173 p = SOC_MACSEC_PORTID(unit, port); 174 rv = bmacsec_port_config_set(p, cfg); 175 return BCM_ERROR(rv); 176 } 177 178 /* 179 * Function: 180 * bcm_macsec_port_config_get 181 * Purpose: 182 * Get the current MACSEC Port configuration. 183 */ 184 int 185 bcm_common_macsec_port_config_get(int unit, bcm_port_t port, 186 bcm_macsec_port_config_t *cfg) 187 { 188 int rv = BCM_E_UNAVAIL; 189 bmacsec_port_t p; 190 191 UNIT_VALID(unit); 192 193 p = SOC_MACSEC_PORTID(unit, port); 194 rv = bmacsec_port_config_get(p, cfg); 195 return BCM_ERROR(rv); 196 } 197 198 /* 199 * Function: 200 * bcm_macsec_port_capability_get 201 * Purpose: 202 * Get the MACSEC Port capability 203 */ 204 int 205 bcm_common_macsec_port_capability_get(int unit, bcm_port_t port, 206 bcm_macsec_port_capability_t *cap) 207 { 208 int rv = BCM_E_UNAVAIL; 209 bmacsec_port_t p; 210 211 UNIT_VALID(unit); 212 213 p = SOC_MACSEC_PORTID(unit, port); 214 rv = bmacsec_port_capability_get(p, cap); 215 return BCM_ERROR(rv); 216 } 217 218 /* 219 * Function: 220 * macsec_secure_chan_create 221 * Purpose: 222 * Create MACSEC secure channel 223 */ 224 int 225 bcm_common_macsec_secure_chan_create(int unit, bcm_port_t port, 226 uint32 flags, 227 bcm_macsec_secure_chan_t *chan, 228 int *chanId) 229 { 230 int rv = BCM_E_UNAVAIL; 231 bmacsec_port_t p; 232 233 UNIT_VALID(unit); 234 235 p = SOC_MACSEC_PORTID(unit, port); 236 rv = bmacsec_secure_chan_create(p, flags, chan, chanId); 237 return BCM_ERROR(rv); 238 } 239 240 /* 241 * Function: 242 * macsec_secure_chan_get 243 * Purpose: 244 * Return current MACSEC secure channel corresponding to channel-id 245 */ 246 int 247 bcm_common_macsec_secure_chan_get(int unit, bcm_port_t port, int chanId, 248 bcm_macsec_secure_chan_t *chan) 249 { 250 int rv = BCM_E_UNAVAIL; 251 bmacsec_port_t p; 252 253 UNIT_VALID(unit); 254 255 p = SOC_MACSEC_PORTID(unit, port); 256 rv = bmacsec_secure_chan_get(p, chanId, chan); 257 return BCM_ERROR(rv); 258 } 259 260 /* 261 * Function: 262 * bcm_macsec_secure_chan_destroy 263 * Purpose: 264 * Destroy a secure channel. This function will free any resources 265 * associated with the secure channel, including any secure assocs. 266 */ 267 int 268 bcm_common_macsec_secure_chan_destroy(int unit, bcm_port_t port, int chanId) 269 { 270 int rv = BCM_E_UNAVAIL; 271 bmacsec_port_t p; 272 273 UNIT_VALID(unit); 274 275 p = SOC_MACSEC_PORTID(unit, port); 276 rv = bmacsec_secure_chan_destroy(p, chanId); 277 return BCM_ERROR(rv); 278 } 279 280 281 /* 282 * Local secure channel traver handler to call user provided callback 283 * function for only the secure channels belonging to specified port. 284 */ 285 STATIC int _bcm_macsec_secure_chan_cb(bmacsec_port_t p, 286 bmacsec_secure_chan_t *chan, 287 int chanId, 288 void *user_data) 289 { 290 int rv = BMACSEC_E_NONE ; 291 _bcm_macsec_cb_args_t *ua; 292 bcm_macsec_chan_traverse_cb callback; 293 294 ua = (_bcm_macsec_cb_args_t*) user_data; 295 296 if ((SOC_MACSEC_PORTID2UNIT(p) == ua->unit) && 297 (SOC_MACSEC_PORTID2PORT(p) == ua->port)) { 298 callback = ua->user_cb_chan; 299 rv = callback(SOC_MACSEC_PORTID2UNIT(p), 300 SOC_MACSEC_PORTID2PORT(p), 301 chan, chanId, ua->user_arg); 302 } 303 return rv; 304 } 305 306 /* 307 * Function: 308 * macsec_secure_chan_traverse 309 * Purpose: 310 * This function will traverse over all the secure channels that 311 * are associated with the specified macsec port and call the 312 * user provided callback function for each of the secure channel. 313 */ 314 int 315 bcm_common_macsec_secure_chan_traverse(int unit, bcm_port_t port, 316 bcm_macsec_chan_traverse_cb callback, 317 void *user_data) 318 { 319 int rv = BCM_E_UNAVAIL; 320 bmacsec_port_t p; 321 _bcm_macsec_cb_args_t ua; 322 323 UNIT_VALID(unit); 324 325 ua.user_arg = user_data; 326 ua.user_cb_chan = callback; 327 ua.unit = unit; 328 ua.port = port; 329 330 p = SOC_MACSEC_PORTID(unit, port); 331 rv = bmacsec_secure_chan_traverse(p, _bcm_macsec_secure_chan_cb, 332 (void*) &ua); 333 return BCM_ERROR(rv); 334 } 335 336 337 /* 338 * Function: 339 * macsec_secure_assoc_create 340 * Purpose: 341 * This function will create an secure association bound to a 342 * secure channel. 343 */ 344 int 345 bcm_common_macsec_secure_assoc_create(int unit, bcm_port_t port, 346 uint32 flags, int chanId, 347 bcm_macsec_secure_assoc_t *assoc, 348 int *assocId) 349 { 350 int rv = BCM_E_UNAVAIL; 351 bmacsec_port_t p; 352 353 UNIT_VALID(unit); 354 355 p = SOC_MACSEC_PORTID(unit, port); 356 rv = bmacsec_secure_assoc_create(p, flags, chanId, assoc, assocId); 357 return BCM_ERROR(rv); 358 } 359 360 /* 361 * Function: 362 * macsec_secure_assoc_get 363 * Purpose: 364 * This function returns the secure assoc for the specified 365 * assoc-id. 366 */ 367 int 368 bcm_common_macsec_secure_assoc_get(int unit, bcm_port_t port, int assocId, 369 bcm_macsec_secure_assoc_t *assoc, int *chanId) 370 { 371 int rv = BCM_E_UNAVAIL; 372 bmacsec_port_t p; 373 374 UNIT_VALID(unit); 375 376 p = SOC_MACSEC_PORTID(unit, port); 377 rv = bmacsec_secure_assoc_get(p, assocId, assoc, chanId); 378 return BCM_ERROR(rv); 379 380 } 381 382 /* 383 * Function: 384 * macsec_secure_assoc_destroy 385 * Purpose: 386 * This function destroys the secure assoc correspondig to 387 * assoc-id. 388 */ 389 int 390 bcm_common_macsec_secure_assoc_destroy(int unit, bcm_port_t port, int assocId) 391 { 392 int rv = BCM_E_UNAVAIL; 393 bmacsec_port_t p; 394 395 UNIT_VALID(unit); 396 397 p = SOC_MACSEC_PORTID(unit, port); 398 rv = bmacsec_secure_assoc_destroy(p, assocId); 399 return BCM_ERROR(rv); 400 } 401 402 /* 403 * Local secure assoc traver handler to filter assocs and call the user provided 404 * callback function for only the assocs belonging to spcified port. 405 */ 406 STATIC int _bcm_macsec_secure_assoc_cb(bmacsec_port_t p, 407 bcm_macsec_secure_assoc_t *chan, 408 int chanId, 409 int assocId, 410 void *user_data) 411 { 412 int rv = BMACSEC_E_NONE ; 413 _bcm_macsec_cb_args_t *ua; 414 bcm_macsec_secure_assoc_traverse_cb callback; 415 416 ua = (_bcm_macsec_cb_args_t*) user_data; 417 418 if ((SOC_MACSEC_PORTID2UNIT(p) == ua->unit) && 419 (SOC_MACSEC_PORTID2PORT(p) == ua->port)) { 420 callback = ua->user_cb_assoc; 421 rv = callback(SOC_MACSEC_PORTID2UNIT(p), 422 SOC_MACSEC_PORTID2PORT(p), 423 chan, chanId, assocId, (void*) ua->user_arg); 424 } 425 return rv; 426 } 427 428 /* 429 * Function: 430 * macsec_secure_assoc_traverse 431 * Purpose: 432 * Traverse all the secure assoc for the specified secure channel 433 * and calls user provided callabck function with information 434 * about the assoc in macsec_secure_assoc_t structure and its 435 * corresponding assoc-id. 436 */ 437 int 438 bcm_common_macsec_secure_assoc_traverse(int unit, bcm_port_t port, 439 int chanId, 440 bcm_macsec_secure_assoc_traverse_cb callback, 441 void *user_data) 442 { 443 int rv = BCM_E_UNAVAIL; 444 bmacsec_port_t p; 445 _bcm_macsec_cb_args_t ua; 446 447 UNIT_VALID(unit); 448 449 ua.user_arg = user_data; 450 ua.user_cb_assoc = callback; 451 ua.unit = unit; 452 ua.port = port; 453 454 p = SOC_MACSEC_PORTID(unit, port); 455 rv = bmacsec_secure_assoc_traverse(p, chanId, 456 _bcm_macsec_secure_assoc_cb, (void*) &ua); 457 return BCM_ERROR(rv); 458 } 459 460 /* 461 * Function: 462 * macsec_flow_create 463 * Purpose: 464 * This fucntion creates/updates a flow and assigns the 465 * actions for the flow. 466 */ 467 int 468 bcm_common_macsec_flow_create(int unit, bcm_port_t port, 469 uint32 flags, bcm_macsec_flow_match_t *flow, 470 bcm_macsec_flow_action_t *action, int *flowId) 471 { 472 int rv = BCM_E_UNAVAIL; 473 bmacsec_port_t p; 474 475 UNIT_VALID(unit); 476 477 p = SOC_MACSEC_PORTID(unit, port); 478 rv = bmacsec_flow_create(p, flags, flow, action, flowId); 479 return BCM_ERROR(rv); 480 } 481 482 /* 483 * Function: 484 * macsec_flow_get 485 * Purpose: 486 * Return flow and corresponding action for the specified flowId 487 */ 488 int 489 bcm_common_macsec_flow_get(int unit, bcm_port_t port, int flowId, 490 bcm_macsec_flow_match_t *flow, bcm_macsec_flow_action_t *action) 491 { 492 int rv = BCM_E_UNAVAIL; 493 bmacsec_port_t p; 494 495 UNIT_VALID(unit); 496 497 p = SOC_MACSEC_PORTID(unit, port); 498 rv = bmacsec_flow_get(p, flowId, flow, action); 499 return BCM_ERROR(rv); 500 } 501 502 /* 503 * Function: 504 * macsec_flow_destroy 505 * Purpose: 506 * Destroy the flow corresponding to flowId. 507 */ 508 int 509 bcm_common_macsec_flow_destroy(int unit, bcm_port_t port, int flowId) 510 { 511 int rv = BCM_E_UNAVAIL; 512 bmacsec_port_t p; 513 514 UNIT_VALID(unit); 515 516 p = SOC_MACSEC_PORTID(unit, port); 517 rv = bmacsec_flow_destroy(p, flowId); 518 return BCM_ERROR(rv); 519 } 520 521 /* 522 * Local flow traver handler to filter the flows belonging to specified port. 523 */ 524 STATIC int _bcm_macsec_flow_cb(bmacsec_port_t p, 525 bcm_macsec_flow_match_t *flow, 526 bcm_macsec_flow_action_t *action, 527 int flowId, 528 void *user_data) 529 { 530 int rv = BMACSEC_E_NONE ; 531 _bcm_macsec_cb_args_t *ua; 532 bcm_macsec_flow_traverse_cb callback; 533 534 ua = (_bcm_macsec_cb_args_t*) user_data; 535 536 if ((SOC_MACSEC_PORTID2UNIT(p) == ua->unit) && 537 (SOC_MACSEC_PORTID2PORT(p) == ua->port)) { 538 callback = ua->user_cb_flow; 539 rv = callback(SOC_MACSEC_PORTID2UNIT(p), 540 SOC_MACSEC_PORTID2PORT(p), 541 flow, action, flowId, ua->user_arg); 542 } 543 return rv; 544 } 545 546 /* 547 * Function: 548 * macsec_flow_traverse 549 * Purpose: 550 * Traverse all the flows and call user provided callback 551 * for each flow. 552 */ 553 int 554 bcm_common_macsec_flow_traverse(int unit, bcm_port_t port, 555 bcm_macsec_flow_traverse_cb callbk, 556 void *user_data) 557 { 558 int rv = BCM_E_UNAVAIL; 559 bmacsec_port_t p; 560 _bcm_macsec_cb_args_t ua; 561 562 UNIT_VALID(unit); 563 564 ua.user_arg = user_data; 565 ua.user_cb_flow = callbk; 566 ua.unit = unit; 567 ua.port = port; 568 569 p = SOC_MACSEC_PORTID(unit, port); 570 rv = bmacsec_flow_traverse(p, _bcm_macsec_flow_cb, (void*) &ua); 571 return BCM_ERROR(rv); 572 } 573 574 /* 575 * Function: 576 * bcm_macsec_stat_clear 577 * Purpose: 578 * Clear stats for the specified port. 579 */ 580 int 581 bcm_common_macsec_stat_clear(int unit, bcm_port_t port) 582 { 583 int rv = BCM_E_UNAVAIL; 584 bmacsec_port_t p; 585 586 UNIT_VALID(unit); 587 588 p = SOC_MACSEC_PORTID(unit, port); 589 rv = bmacsec_stat_clear(p); 590 return BCM_ERROR(rv); 591 } 592 593 int 594 bcm_common_macsec_stat_get(int unit, bcm_port_t port, bcm_macsec_stat_t stat, 595 int chanId, int assocId, uint64 *val) 596 { 597 int rv = BCM_E_UNAVAIL; 598 bmacsec_port_t p; 599 600 UNIT_VALID(unit); 601 602 p = SOC_MACSEC_PORTID(unit, port); 603 rv = bmacsec_stat_get(p, stat, chanId, assocId, (buint64_t *)val); 604 return BCM_ERROR(rv); 605 } 606 607 int 608 bcm_common_macsec_stat_get32(int unit, bcm_port_t port, 609 bcm_macsec_stat_t stat, int chanId, 610 int assocId, uint32 *val) 611 { 612 int rv = BCM_E_UNAVAIL; 613 bmacsec_port_t p; 614 615 UNIT_VALID(unit); 616 617 p = SOC_MACSEC_PORTID(unit, port); 618 rv = bmacsec_stat_get32(p, stat, chanId, assocId, (buint32_t*)val); 619 return BCM_ERROR(rv); 620 } 621 622 int 623 bcm_common_macsec_stat_set(int unit, bcm_port_t port, bcm_macsec_stat_t stat, 624 int chanId, int assocId, uint64 val) 625 { 626 int rv = BCM_E_UNAVAIL; 627 bmacsec_port_t p; 628 buint64_t bval; 629 BMACSEC_COMPILER_64_SET(bval, COMPILER_64_HI(val), COMPILER_64_LO(val)); 630 631 UNIT_VALID(unit); 632 633 p = SOC_MACSEC_PORTID(unit, port); 634 rv = bmacsec_stat_set(p, stat, chanId, assocId, bval); 635 return BCM_ERROR(rv); 636 } 637 638 int 639 bcm_common_macsec_stat_set32(int unit, bcm_port_t port, bcm_macsec_stat_t stat, 640 int chanId, int assocId, uint32 val) 641 { 642 int rv = BCM_E_UNAVAIL; 643 bmacsec_port_t p; 644 645 UNIT_VALID(unit); 646 647 p = SOC_MACSEC_PORTID(unit, port); 648 rv = bmacsec_stat_set32(p, stat, chanId, assocId, val); 649 return BCM_ERROR(rv); 650 } 651 652 typedef struct _bcm_macsec_event_data_s { 653 bcm_macsec_event_cb callback; 654 uint32 event_map; 655 } _bcm_macsec_event_data_t; 656 657 STATIC _bcm_macsec_event_data_t _macsec_event_data[BCM_UNITS_MAX]; 658 659 STATIC int 660 _bcm_macsec_event_cb(bmacsec_port_t p, /* Port ID */ 661 bmacsec_event_t event, /* Event */ 662 int chanId, /* secure channel ID*/ 663 int assocId, 664 void *user_data) 665 { 666 int unit; 667 bcm_macsec_event_cb callback; 668 _bcm_macsec_event_data_t *event_data; 669 670 unit = SOC_MACSEC_PORTID2UNIT(p); 671 672 event_data = &_macsec_event_data[unit]; 673 callback = (bcm_macsec_event_cb) event_data->callback; 674 675 if (callback && (event_data->event_map & (1 << (uint32) event))) { 676 callback(SOC_MACSEC_PORTID2UNIT(p), 677 SOC_MACSEC_PORTID2PORT(p), 678 event, chanId, assocId, user_data); 679 } 680 return BMACSEC_E_NONE; 681 } 682 683 int 684 bcm_common_macsec_event_register(int unit, bcm_macsec_event_cb cb, void *user_data) 685 { 686 int rv = BCM_E_NONE; 687 _bcm_macsec_event_data_t *event_data; 688 689 UNIT_VALID(unit); 690 691 event_data = &_macsec_event_data[unit]; 692 event_data->callback = cb; 693 event_data->event_map = 0; 694 if (macsec_cb_registered == 0) { 695 rv = bmacsec_event_register(_bcm_macsec_event_cb, user_data); 696 if (rv == BMACSEC_E_NONE) { 697 macsec_cb_registered = 1; 698 } 699 } 700 return BCM_ERROR(rv); 701 } 702 703 int 704 bcm_common_macsec_event_unregister(int unit, bcm_macsec_event_cb cb) 705 { 706 int rv = BCM_E_NONE, unregister = 1, ii; 707 _bcm_macsec_event_data_t *event_data; 708 709 UNIT_VALID(unit); 710 711 event_data = &_macsec_event_data[unit]; 712 if (event_data->callback) { 713 event_data->callback = NULL; 714 } 715 716 for (ii = 0; ii < BCM_UNITS_MAX; ii++) { 717 event_data = &_macsec_event_data[ii]; 718 if (event_data->callback) { 719 unregister = 0; 720 break; 721 } 722 } 723 if (unregister) { 724 macsec_cb_registered = 0; 725 rv = bmacsec_event_unregister(_bcm_macsec_event_cb); 726 } 727 return BCM_ERROR(rv); 728 } 729 730 int 731 bcm_common_macsec_event_enable_set(int unit, 732 bcm_macsec_event_t event, int enable) 733 { 734 int rv = BCM_E_NONE, disable, ii; 735 _bcm_macsec_event_data_t *event_data; 736 737 UNIT_VALID(unit); 738 739 event_data = &_macsec_event_data[unit]; 740 if (enable) { 741 event_data->event_map |= (1 << (uint32) event); 742 rv = bmacsec_event_enable_set(event, enable); 743 } else { 744 event_data->event_map &= ~(1 << (uint32) event); 745 disable = 1; 746 for (ii = 0; ii < BCM_UNITS_MAX; ii++) { 747 event_data = &_macsec_event_data[ii]; 748 if (event_data->event_map & (1 << (uint32) event)) { 749 disable = 0; 750 break; 751 } 752 } 753 if (disable) { 754 rv = bmacsec_event_enable_set(event, enable); 755 } 756 } 757 return BCM_ERROR(rv); 758 } 759 760 int 761 bcm_common_macsec_event_enable_get(int unit, 762 bcm_macsec_event_t event, int *enable) 763 { 764 int rv = BCM_E_NONE; 765 _bcm_macsec_event_data_t *event_data; 766 767 UNIT_VALID(unit); 768 769 event_data = &_macsec_event_data[unit]; 770 *enable = (event_data->event_map & (1 << (uint32) event)) ? 1 : 0; 771 return BCM_ERROR(rv); 772 } 773 774 775 /* 776 * Configure MACSEC print function for debug. 777 */ 778 int bcm_common_macsec_config_print(uint32 level) 779 { 780 int rv = BCM_E_NONE; 781 uint32 flag = BMACSEC_PRINT_PRINTF; 782 783 #if defined(BROADCOM_DEBUG) 784 if (LOG_CHECK(BSL_LS_BCM_MACSEC | BSL_INFO)) { 785 flag |= BMACSEC_PRINT_DEBUG; 786 } 787 #endif /* BROADCOM_DEBUG */ 788 789 rv = bmacsec_config_print_set(flag, bsl_printf); 790 return BCM_ERROR(rv); 791 } 792 793 794 #else 795 int _macsec_cmn_not_empty; 796 #endif /* INCLUDE_MACSEC */ 797