cosq.c (27164B)
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: bcmx/cosq.c 8 * Purpose: BCMX Class of Service Queue APIs 9 */ 10 11 #include <bcm/types.h> 12 13 #include <bcmx/cosq.h> 14 #include <bcmx/lport.h> 15 #include <bcmx/bcmx.h> 16 #include <bcmx/lplist.h> 17 18 #include "bcmx_int.h" 19 20 #define BCMX_COSQ_INIT_CHECK BCMX_READY_CHECK 21 22 #define BCMX_COSQ_ERROR_CHECK(_unit, _check, _rv) \ 23 BCMX_ERROR_CHECK(_unit, _check, _rv) 24 25 #define BCMX_COSQ_SET_ERROR_CHECK(_unit, _check, _rv) \ 26 BCMX_SET_ERROR_CHECK(_unit, _check, _rv) 27 28 #define BCMX_COSQ_DELETE_ERROR_CHECK(_unit, _check, _rv) \ 29 BCMX_DELETE_ERROR_CHECK(_unit, _check, _rv) 30 31 #define BCMX_COSQ_GET_IS_VALID(_unit, _rv) \ 32 BCMX_ERROR_IS_VALID(_unit, _rv) 33 34 35 #define BCMX_COSQ_GPORT_DISCARD_T_PTR_TO_BCM(_discard) \ 36 ((bcm_cosq_gport_discard_t *)(_discard)) 37 38 /* 39 * Function: 40 * bcmx_cosq_init 41 */ 42 43 int 44 bcmx_cosq_init(void) 45 { 46 int rv = BCM_E_UNAVAIL, tmp_rv; 47 int i, bcm_unit; 48 49 BCMX_COSQ_INIT_CHECK; 50 51 BCMX_UNIT_ITER(bcm_unit, i) { 52 tmp_rv = bcm_cosq_init(bcm_unit); 53 BCM_IF_ERROR_RETURN(BCMX_COSQ_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 54 } 55 56 return rv; 57 } 58 59 60 /* 61 * Function: 62 * bcmx_cosq_detach 63 */ 64 65 int 66 bcmx_cosq_detach(void) 67 { 68 int rv = BCM_E_UNAVAIL, tmp_rv; 69 int i, bcm_unit; 70 71 BCMX_COSQ_INIT_CHECK; 72 73 BCMX_UNIT_ITER(bcm_unit, i) { 74 tmp_rv = bcm_cosq_detach(bcm_unit); 75 BCM_IF_ERROR_RETURN(BCMX_COSQ_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 76 } 77 78 return rv; 79 } 80 81 82 /* 83 * Function: 84 * bcmx_cosq_config_set 85 */ 86 87 int 88 bcmx_cosq_config_set(int numq) 89 { 90 int rv = BCM_E_UNAVAIL, tmp_rv; 91 int i, bcm_unit; 92 93 BCMX_COSQ_INIT_CHECK; 94 95 BCMX_UNIT_ITER(bcm_unit, i) { 96 tmp_rv = bcm_cosq_config_set(bcm_unit, numq); 97 BCM_IF_ERROR_RETURN(BCMX_COSQ_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 98 } 99 100 return rv; 101 } 102 103 104 /* 105 * Function: 106 * bcmx_cosq_config_get 107 */ 108 109 int 110 bcmx_cosq_config_get(int *numq) 111 { 112 int rv, i, bcm_unit; 113 114 BCMX_COSQ_INIT_CHECK; 115 116 BCMX_PARAM_NULL_CHECK(numq); 117 118 BCMX_UNIT_ITER(bcm_unit, i) { 119 rv = bcm_cosq_config_get(bcm_unit, numq); 120 if (BCMX_COSQ_GET_IS_VALID(bcm_unit, rv)) { 121 return rv; 122 } 123 } 124 125 return BCM_E_UNAVAIL; 126 } 127 128 129 /* 130 * Function: 131 * bcmx_cosq_mapping_set 132 */ 133 134 int 135 bcmx_cosq_mapping_set(bcm_cos_t priority, 136 bcm_cos_queue_t cosq) 137 { 138 int rv = BCM_E_UNAVAIL, tmp_rv; 139 int i, bcm_unit; 140 141 BCMX_COSQ_INIT_CHECK; 142 143 BCMX_UNIT_ITER(bcm_unit, i) { 144 tmp_rv = bcm_cosq_mapping_set(bcm_unit, priority, cosq); 145 BCM_IF_ERROR_RETURN(BCMX_COSQ_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 146 } 147 148 return rv; 149 } 150 151 152 /* 153 * Function: 154 * bcmx_cosq_mapping_get 155 */ 156 157 int 158 bcmx_cosq_mapping_get(bcm_cos_t priority, 159 bcm_cos_queue_t *cosq) 160 { 161 int rv, i, bcm_unit; 162 163 BCMX_COSQ_INIT_CHECK; 164 165 BCMX_PARAM_NULL_CHECK(cosq); 166 167 BCMX_UNIT_ITER(bcm_unit, i) { 168 rv = bcm_cosq_mapping_get(bcm_unit, priority, cosq); 169 if (BCMX_COSQ_GET_IS_VALID(bcm_unit, rv)) { 170 return rv; 171 } 172 } 173 174 return BCM_E_UNAVAIL; 175 } 176 177 /* 178 * Function: 179 * bcmx_cosq_port_mapping_set 180 */ 181 182 int 183 bcmx_cosq_port_mapping_set(bcmx_lport_t port, 184 bcm_cos_t priority, 185 bcm_cos_queue_t cosq) 186 { 187 int bcm_unit; 188 bcm_port_t bcm_port; 189 190 BCMX_COSQ_INIT_CHECK; 191 192 BCM_IF_ERROR_RETURN 193 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 194 BCMX_DEST_CONVERT_NON_GPORT)); 195 196 return bcm_cosq_port_mapping_set(bcm_unit, bcm_port, priority, cosq); 197 } 198 199 200 /* 201 * Function: 202 * bcmx_cosq_port_mapping_get 203 */ 204 205 int 206 bcmx_cosq_port_mapping_get(bcmx_lport_t port, 207 bcm_cos_t priority, 208 bcm_cos_queue_t *cosq) 209 { 210 int bcm_unit; 211 bcm_port_t bcm_port; 212 213 BCMX_COSQ_INIT_CHECK; 214 215 BCMX_PARAM_NULL_CHECK(cosq); 216 217 BCM_IF_ERROR_RETURN 218 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 219 BCMX_DEST_CONVERT_NON_GPORT)); 220 221 return bcm_cosq_port_mapping_get(bcm_unit, bcm_port, priority, cosq); 222 } 223 224 /* 225 * Function: 226 * bcmx_cosq_sched_set 227 */ 228 229 int 230 bcmx_cosq_sched_set(int mode, 231 const int weights[BCM_COS_COUNT], 232 int delay) 233 { 234 int rv = BCM_E_UNAVAIL, tmp_rv; 235 int i, bcm_unit; 236 237 BCMX_COSQ_INIT_CHECK; 238 239 BCMX_UNIT_ITER(bcm_unit, i) { 240 tmp_rv = bcm_cosq_sched_set(bcm_unit, mode, weights, delay); 241 BCM_IF_ERROR_RETURN(BCMX_COSQ_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 242 } 243 244 return rv; 245 } 246 247 248 /* 249 * Function: 250 * bcmx_cosq_port_sched_set 251 */ 252 253 int 254 bcmx_cosq_port_sched_set(bcmx_lplist_t lplist, 255 int mode, 256 const int weights[BCM_COS_COUNT], 257 int delay) 258 { 259 int rv = BCM_E_UNAVAIL, tmp_rv; 260 int i, bcm_unit; 261 bcm_pbmp_t pbmp; 262 263 BCMX_COSQ_INIT_CHECK; 264 265 BCMX_UNIT_ITER(bcm_unit, i) { 266 BCMX_LPLIST_TO_PBMP(lplist, bcm_unit, pbmp); 267 if (BCM_PBMP_NOT_NULL(pbmp)) { 268 tmp_rv = bcm_cosq_port_sched_set(bcm_unit, pbmp, mode, 269 weights, delay); 270 BCM_IF_ERROR_RETURN 271 (BCMX_COSQ_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 272 } 273 } 274 275 return rv; 276 } 277 278 279 /* 280 * Function: 281 * bcmx_cosq_sched_get 282 */ 283 284 int 285 bcmx_cosq_sched_get(int *mode, 286 int weights[BCM_COS_COUNT], 287 int *delay) 288 { 289 int rv, i, bcm_unit; 290 291 BCMX_COSQ_INIT_CHECK; 292 293 BCMX_PARAM_NULL_CHECK(mode); 294 295 BCMX_UNIT_ITER(bcm_unit, i) { 296 rv = bcm_cosq_sched_get(bcm_unit, mode, weights, delay); 297 if (BCMX_COSQ_GET_IS_VALID(bcm_unit, rv)) { 298 return rv; 299 } 300 } 301 302 return BCM_E_UNAVAIL; 303 } 304 305 306 /* 307 * Function: 308 * bcmx_cosq_port_sched_get 309 */ 310 311 int 312 bcmx_cosq_port_sched_get(bcmx_lplist_t lplist, 313 int *mode, 314 int weights[BCM_COS_COUNT], 315 int *delay) 316 { 317 int rv, i, bcm_unit; 318 bcm_pbmp_t pbmp; 319 320 BCMX_COSQ_INIT_CHECK; 321 322 BCMX_PARAM_NULL_CHECK(mode); 323 324 BCMX_UNIT_ITER(bcm_unit, i) { 325 BCMX_LPLIST_TO_PBMP(lplist, bcm_unit, pbmp); 326 if (BCM_PBMP_NOT_NULL(pbmp)) { 327 rv = bcm_cosq_port_sched_get(bcm_unit, pbmp, mode, 328 weights, delay); 329 if (BCMX_COSQ_GET_IS_VALID(bcm_unit, rv)) { 330 return rv; 331 } 332 } 333 } 334 335 return BCM_E_UNAVAIL; 336 } 337 338 int 339 bcmx_cosq_sched_weight_max_get(int mode, 340 int *weight_max) 341 { 342 int rv, i, bcm_unit; 343 344 BCMX_COSQ_INIT_CHECK; 345 346 BCMX_PARAM_NULL_CHECK(weight_max); 347 348 BCMX_UNIT_ITER(bcm_unit, i) { 349 rv = bcm_cosq_sched_weight_max_get(bcm_unit, mode, weight_max); 350 if (BCMX_COSQ_GET_IS_VALID(bcm_unit, rv)) { 351 return rv; 352 } 353 } 354 355 return BCM_E_UNAVAIL; 356 } 357 358 int 359 bcmx_cosq_port_bandwidth_set(bcmx_lport_t port, bcm_cos_queue_t cosq, 360 uint32 kbits_sec_min, uint32 kbits_sec_max, 361 uint32 flags) 362 { 363 int bcm_unit; 364 bcm_port_t bcm_port; 365 366 BCMX_COSQ_INIT_CHECK; 367 368 BCM_IF_ERROR_RETURN 369 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 370 BCMX_DEST_CONVERT_NON_GPORT)); 371 372 return bcm_cosq_port_bandwidth_set(bcm_unit, bcm_port, cosq, 373 kbits_sec_min, kbits_sec_max, flags); 374 } 375 376 int 377 bcmx_cosq_port_bandwidth_get(bcmx_lport_t port, bcm_cos_queue_t cosq, 378 uint32 *kbits_sec_min, uint32 *kbits_sec_max, 379 uint32 *flags) 380 { 381 int bcm_unit; 382 bcm_port_t bcm_port; 383 384 BCMX_COSQ_INIT_CHECK; 385 386 BCMX_PARAM_NULL_CHECK(kbits_sec_min); 387 BCMX_PARAM_NULL_CHECK(kbits_sec_max); 388 BCMX_PARAM_NULL_CHECK(flags); 389 390 BCM_IF_ERROR_RETURN 391 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 392 BCMX_DEST_CONVERT_NON_GPORT)); 393 394 return bcm_cosq_port_bandwidth_get(bcm_unit, bcm_port, cosq, 395 kbits_sec_min, kbits_sec_max, flags); 396 } 397 398 /* 399 * Function: 400 * bcmx_cosq_discard_set 401 */ 402 403 int 404 bcmx_cosq_discard_set(uint32 flags) 405 { 406 int rv = BCM_E_UNAVAIL, tmp_rv; 407 int i, bcm_unit; 408 409 BCMX_COSQ_INIT_CHECK; 410 411 BCMX_UNIT_ITER(bcm_unit, i) { 412 tmp_rv = bcm_cosq_discard_set(bcm_unit, flags); 413 BCM_IF_ERROR_RETURN(BCMX_COSQ_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 414 } 415 416 return rv; 417 } 418 419 /* 420 * Function: 421 * bcmx_cosq_discard_get 422 */ 423 424 int 425 bcmx_cosq_discard_get(uint32 *flags) 426 { 427 int rv, i, bcm_unit; 428 429 BCMX_COSQ_INIT_CHECK; 430 431 BCMX_PARAM_NULL_CHECK(flags); 432 433 BCMX_UNIT_ITER(bcm_unit, i) { 434 rv = bcm_cosq_discard_get(bcm_unit, flags); 435 if (BCMX_COSQ_GET_IS_VALID(bcm_unit, rv)) { 436 return rv; 437 } 438 } 439 440 return BCM_E_UNAVAIL; 441 } 442 443 int 444 bcmx_cosq_discard_port_set(bcmx_lport_t port, 445 bcm_cos_queue_t cosq, 446 uint32 color, 447 int drop_start, 448 int drop_slope, 449 int average_time) 450 { 451 int bcm_unit; 452 bcm_port_t bcm_port; 453 454 BCMX_COSQ_INIT_CHECK; 455 456 BCM_IF_ERROR_RETURN 457 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 458 BCMX_DEST_CONVERT_DEFAULT)); 459 460 return bcm_cosq_discard_port_set(bcm_unit, bcm_port, cosq, color, 461 drop_start, drop_slope, average_time); 462 } 463 464 int 465 bcmx_cosq_discard_port_get(bcmx_lport_t port, 466 bcm_cos_queue_t cosq, 467 uint32 color, 468 int *drop_start, 469 int *drop_slope, 470 int *average_time) 471 { 472 int bcm_unit; 473 bcm_port_t bcm_port; 474 475 BCMX_COSQ_INIT_CHECK; 476 477 BCMX_PARAM_NULL_CHECK(drop_start); 478 BCMX_PARAM_NULL_CHECK(drop_slope); 479 BCMX_PARAM_NULL_CHECK(average_time); 480 481 BCM_IF_ERROR_RETURN 482 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 483 BCMX_DEST_CONVERT_DEFAULT)); 484 485 return bcm_cosq_discard_port_get(bcm_unit, bcm_port, cosq, color, 486 drop_start, drop_slope, average_time); 487 } 488 489 490 /* 491 * Function: 492 * bcmx_cosq_control_set 493 */ 494 int 495 bcmx_cosq_control_set(bcm_gport_t port, bcm_cos_queue_t cosq, 496 bcm_cosq_control_t type, int arg) 497 { 498 int rv = BCM_E_UNAVAIL, tmp_rv; 499 int i, bcm_unit; 500 bcm_port_t bcm_port; 501 502 BCMX_COSQ_INIT_CHECK; 503 504 /* A negative port value indicates all ports */ 505 if (!BCMX_IS_LPORT(port) && (port >= 0)) { 506 return BCM_E_PORT; 507 } 508 509 if (BCMX_LPORT_IS_PHYSICAL(port)) { 510 if (BCM_FAILURE(_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 511 BCMX_DEST_CONVERT_DEFAULT))) { 512 return BCM_E_PORT; 513 } 514 return bcm_cosq_control_set(bcm_unit, port, cosq, type, arg); 515 } 516 517 /* Virtual port */ 518 BCMX_UNIT_ITER(bcm_unit, i) { 519 tmp_rv = bcm_cosq_control_set(bcm_unit, port, cosq, type, arg); 520 BCM_IF_ERROR_RETURN(BCMX_COSQ_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 521 } 522 523 return rv; 524 } 525 526 /* 527 * Function: 528 * bcmx_cosq_control_get 529 */ 530 int 531 bcmx_cosq_control_get(bcm_gport_t port, bcm_cos_queue_t cosq, 532 bcm_cosq_control_t type, int *arg) 533 { 534 int rv; 535 int i, bcm_unit; 536 bcm_port_t bcm_port; 537 538 BCMX_COSQ_INIT_CHECK; 539 540 BCMX_PARAM_NULL_CHECK(arg); 541 542 /* A negative port value indicates any port */ 543 if (!BCMX_IS_LPORT(port) && (port >= 0)) { 544 return BCM_E_PORT; 545 } 546 547 if (BCMX_LPORT_IS_PHYSICAL(port)) { 548 if (BCM_FAILURE(_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 549 BCMX_DEST_CONVERT_DEFAULT))) { 550 return BCM_E_PORT; 551 } 552 return bcm_cosq_control_get(bcm_unit, port, cosq, type, arg); 553 } 554 555 /* Virtual port */ 556 BCMX_UNIT_ITER(bcm_unit, i) { 557 rv = bcm_cosq_control_get(bcm_unit, port, cosq, type, arg); 558 if (BCMX_COSQ_GET_IS_VALID(bcm_unit, rv)) { 559 return rv; 560 } 561 } 562 563 return BCM_E_UNAVAIL; 564 } 565 566 /* 567 * Function: 568 * bcmx_cosq_gport_add 569 */ 570 int 571 bcmx_cosq_gport_add(bcm_gport_t port, int numq, uint32 flags, 572 bcm_gport_t *gport) 573 { 574 int bcm_unit; 575 bcm_port_t bcm_port; 576 577 BCMX_COSQ_INIT_CHECK; 578 579 BCMX_PARAM_NULL_CHECK(gport); 580 581 BCM_IF_ERROR_RETURN 582 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 583 BCMX_DEST_CONVERT_DEFAULT)); 584 585 return bcm_cosq_gport_add(bcm_unit, port, numq, flags, gport); 586 } 587 588 /* 589 * Function: 590 * bcmx_cosq_gport_delete 591 */ 592 int 593 bcmx_cosq_gport_delete(bcm_gport_t gport) 594 { 595 int rv = BCM_E_UNAVAIL, tmp_rv; 596 int i; 597 int bcm_unit; 598 bcm_port_t bcm_port; 599 600 BCMX_COSQ_INIT_CHECK; 601 602 /* 603 * 'gport' can be a physical local port or a system-wide value. 604 */ 605 if (BCM_SUCCESS(_bcmx_dest_to_unit_port(gport, &bcm_unit, &bcm_port, 606 BCMX_DEST_CONVERT_DEFAULT))) { 607 return bcm_cosq_gport_delete(bcm_unit, gport); 608 } 609 610 BCMX_UNIT_ITER(bcm_unit, i) { 611 tmp_rv = bcm_cosq_gport_delete(bcm_unit, gport); 612 BCM_IF_ERROR_RETURN 613 (BCMX_COSQ_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 614 } 615 616 return rv; 617 } 618 619 /* 620 * Function: 621 * bcmx_cosq_gport_bandwidth_set 622 */ 623 int 624 bcmx_cosq_gport_bandwidth_set(bcm_gport_t gport, bcm_cos_queue_t cosq, 625 uint32 kbits_sec_min, uint32 kbits_sec_max, 626 uint32 flags) 627 { 628 int rv = BCM_E_UNAVAIL, tmp_rv; 629 int i; 630 int bcm_unit; 631 bcm_port_t bcm_port; 632 633 BCMX_COSQ_INIT_CHECK; 634 635 /* 636 * 'gport' can be a physical local port or a system-wide value. 637 */ 638 if (BCM_SUCCESS(_bcmx_dest_to_unit_port(gport, &bcm_unit, &bcm_port, 639 BCMX_DEST_CONVERT_DEFAULT))) { 640 return bcm_cosq_gport_bandwidth_set(bcm_unit, gport, cosq, 641 kbits_sec_min, kbits_sec_max, 642 flags); 643 } 644 645 BCMX_UNIT_ITER(bcm_unit, i) { 646 tmp_rv = bcm_cosq_gport_bandwidth_set(bcm_unit, gport, cosq, 647 kbits_sec_min, kbits_sec_max, 648 flags); 649 BCM_IF_ERROR_RETURN 650 (BCMX_COSQ_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 651 } 652 653 return rv; 654 } 655 656 /* 657 * Function: 658 * bcmx_cosq_gport_bandwidth_get 659 */ 660 int 661 bcmx_cosq_gport_bandwidth_get(bcm_gport_t gport, bcm_cos_queue_t cosq, 662 uint32 *kbits_sec_min, uint32 *kbits_sec_max, 663 uint32 *flags) 664 { 665 int rv; 666 int i; 667 int bcm_unit; 668 bcm_port_t bcm_port; 669 670 BCMX_COSQ_INIT_CHECK; 671 672 BCMX_PARAM_NULL_CHECK(kbits_sec_min); 673 BCMX_PARAM_NULL_CHECK(kbits_sec_max); 674 BCMX_PARAM_NULL_CHECK(flags); 675 676 /* 677 * 'gport' can be a physical local port or a system-wide value. 678 */ 679 if (BCM_SUCCESS(_bcmx_dest_to_unit_port(gport, &bcm_unit, &bcm_port, 680 BCMX_DEST_CONVERT_DEFAULT))) { 681 return bcm_cosq_gport_bandwidth_get(bcm_unit, gport, cosq, 682 kbits_sec_min, kbits_sec_max, 683 flags); 684 } 685 686 BCMX_UNIT_ITER(bcm_unit, i) { 687 rv = bcm_cosq_gport_bandwidth_get(bcm_unit, gport, cosq, 688 kbits_sec_min, kbits_sec_max, 689 flags); 690 if (BCMX_COSQ_GET_IS_VALID(bcm_unit, rv)) { 691 return rv; 692 } 693 } 694 695 return BCM_E_UNAVAIL; 696 } 697 698 /* 699 * Function: 700 * bcmx_cosq_gport_sched_set 701 */ 702 int 703 bcmx_cosq_gport_sched_set(bcm_gport_t gport, bcm_cos_queue_t cosq, 704 int mode, int weight) 705 { 706 int rv = BCM_E_UNAVAIL, tmp_rv; 707 int i; 708 int bcm_unit; 709 bcm_port_t bcm_port; 710 711 BCMX_COSQ_INIT_CHECK; 712 713 /* 714 * 'gport' can be a physical local port or a system-wide value. 715 */ 716 if (BCM_SUCCESS(_bcmx_dest_to_unit_port(gport, &bcm_unit, &bcm_port, 717 BCMX_DEST_CONVERT_DEFAULT))) { 718 return bcm_cosq_gport_sched_set(bcm_unit, gport, cosq, 719 mode, weight); 720 } 721 722 BCMX_UNIT_ITER(bcm_unit, i) { 723 tmp_rv = bcm_cosq_gport_sched_set(bcm_unit, gport, cosq, 724 mode, weight); 725 BCM_IF_ERROR_RETURN(BCMX_COSQ_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 726 } 727 728 return rv; 729 } 730 731 /* 732 * Function: 733 * bcmx_cosq_gport_sched_get 734 */ 735 int 736 bcmx_cosq_gport_sched_get(bcm_gport_t gport, bcm_cos_queue_t cosq, 737 int *mode, int *weight) 738 { 739 int rv; 740 int i; 741 int bcm_unit; 742 bcm_port_t bcm_port; 743 744 BCMX_COSQ_INIT_CHECK; 745 746 BCMX_PARAM_NULL_CHECK(mode); 747 BCMX_PARAM_NULL_CHECK(weight); 748 749 /* 750 * 'gport' can be a physical local port or a system-wide value. 751 */ 752 if (BCM_SUCCESS(_bcmx_dest_to_unit_port(gport, &bcm_unit, &bcm_port, 753 BCMX_DEST_CONVERT_DEFAULT))) { 754 return bcm_cosq_gport_sched_get(bcm_unit, gport, cosq, 755 mode, weight); 756 } 757 758 BCMX_UNIT_ITER(bcm_unit, i) { 759 rv = bcm_cosq_gport_sched_get(bcm_unit, gport, cosq, 760 mode, weight); 761 if (BCMX_COSQ_GET_IS_VALID(bcm_unit, rv)) { 762 return rv; 763 } 764 } 765 766 return BCM_E_UNAVAIL; 767 } 768 769 /* 770 * Function: 771 * bcmx_cosq_gport_attach 772 */ 773 int 774 bcmx_cosq_gport_attach(bcm_gport_t sched_port, bcm_gport_t input_port, 775 bcm_cos_queue_t cosq) 776 { 777 int bcm_unit; 778 bcm_port_t bcm_port; 779 780 BCMX_COSQ_INIT_CHECK; 781 782 /* 783 * 'sched_port' is a system-wide value (scheduler) 784 * 'input_port' is a physical local port 785 */ 786 BCM_IF_ERROR_RETURN 787 (_bcmx_dest_to_unit_port(input_port, &bcm_unit, &bcm_port, 788 BCMX_DEST_CONVERT_DEFAULT)); 789 790 return bcm_cosq_gport_attach(bcm_unit, sched_port, input_port, cosq); 791 } 792 793 /* 794 * Function: 795 * bcmx_cosq_gport_detach 796 */ 797 int 798 bcmx_cosq_gport_detach(bcm_gport_t sched_port, bcm_gport_t input_port, 799 bcm_cos_queue_t cosq) 800 { 801 int bcm_unit; 802 bcm_port_t bcm_port; 803 804 BCMX_COSQ_INIT_CHECK; 805 806 /* 807 * 'sched_port' is a system-wide value (scheduler) 808 * 'input_port' is a physical local port 809 */ 810 BCM_IF_ERROR_RETURN 811 (_bcmx_dest_to_unit_port(input_port, &bcm_unit, &bcm_port, 812 BCMX_DEST_CONVERT_DEFAULT)); 813 814 return bcm_cosq_gport_detach(bcm_unit, sched_port, input_port, cosq); 815 } 816 817 /* 818 * Function: 819 * bcmx_cosq_gport_attach_get 820 */ 821 int 822 bcmx_cosq_gport_attach_get(bcm_gport_t sched_port, bcm_gport_t *input_port, 823 bcm_cos_queue_t *cosq) 824 { 825 int rv = BCM_E_UNAVAIL, tmp_rv; 826 int i; 827 int bcm_unit; 828 829 BCMX_COSQ_INIT_CHECK; 830 831 BCMX_PARAM_NULL_CHECK(input_port); 832 BCMX_PARAM_NULL_CHECK(cosq); 833 834 BCMX_UNIT_ITER(bcm_unit, i) { 835 tmp_rv = bcm_cosq_gport_attach_get(bcm_unit, sched_port, input_port, 836 cosq); 837 /* 838 * Find the device where the input_port was set, so 839 * ignore BCM_E_NOT_FOUND errors (but save it) 840 */ 841 if (tmp_rv == BCM_E_NOT_FOUND) { 842 rv = tmp_rv; 843 continue; 844 } 845 846 if (BCMX_COSQ_GET_IS_VALID(bcm_unit, tmp_rv)) { 847 return tmp_rv; 848 } 849 } 850 851 return rv; 852 } 853 854 855 /* 856 * Function: 857 * bcmx_cosq_gport_discard_t_init 858 */ 859 void 860 bcmx_cosq_gport_discard_t_init(bcmx_cosq_gport_discard_t *discard) 861 { 862 if (discard != NULL) { 863 bcm_cosq_gport_discard_t_init 864 (BCMX_COSQ_GPORT_DISCARD_T_PTR_TO_BCM(discard)); 865 } 866 } 867 868 /* 869 * Function: 870 * bcmx_cosq_gport_discard_set 871 */ 872 int 873 bcmx_cosq_gport_discard_set(bcm_gport_t gport, bcm_cos_queue_t cosq, 874 bcmx_cosq_gport_discard_t *discard) 875 { 876 int rv = BCM_E_UNAVAIL, tmp_rv; 877 int i; 878 int bcm_unit; 879 bcm_port_t bcm_port; 880 881 BCMX_COSQ_INIT_CHECK; 882 883 BCMX_PARAM_NULL_CHECK(discard); 884 885 /* 886 * If gport is a valid BCMX logical port, then gport refers to 887 * a specific physical port (mod/port or dev/port). 888 * Else, gport is a system-wide value. 889 */ 890 if (BCM_SUCCESS(_bcmx_dest_to_unit_port(gport, &bcm_unit, &bcm_port, 891 BCMX_DEST_CONVERT_DEFAULT))) { 892 return bcm_cosq_gport_discard_set(bcm_unit, gport, cosq, 893 BCMX_COSQ_GPORT_DISCARD_T_PTR_TO_BCM 894 (discard)); 895 } 896 897 BCMX_UNIT_ITER(bcm_unit, i) { 898 tmp_rv = bcm_cosq_gport_discard_set(bcm_unit, gport, cosq, 899 BCMX_COSQ_GPORT_DISCARD_T_PTR_TO_BCM 900 (discard)); 901 BCM_IF_ERROR_RETURN(BCMX_COSQ_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 902 } 903 904 return rv; 905 } 906 907 /* 908 * Function: 909 * bcmx_cosq_gport_discard_get 910 */ 911 int 912 bcmx_cosq_gport_discard_get(bcm_gport_t gport, bcm_cos_queue_t cosq, 913 bcmx_cosq_gport_discard_t *discard) 914 { 915 int rv; 916 int i; 917 int bcm_unit; 918 bcm_port_t bcm_port; 919 920 BCMX_COSQ_INIT_CHECK; 921 922 BCMX_PARAM_NULL_CHECK(discard); 923 924 /* 925 * If gport is a valid BCMX logical port, then gport refers to 926 * a specific physical port (mod/port or dev/port). 927 * Else, gport is a system-wide value. 928 */ 929 if (BCM_SUCCESS(_bcmx_dest_to_unit_port(gport, &bcm_unit, &bcm_port, 930 BCMX_DEST_CONVERT_DEFAULT))) { 931 return bcm_cosq_gport_discard_get(bcm_unit, gport, cosq, 932 BCMX_COSQ_GPORT_DISCARD_T_PTR_TO_BCM 933 (discard)); 934 } 935 936 BCMX_UNIT_ITER(bcm_unit, i) { 937 rv = bcm_cosq_gport_discard_get(bcm_unit, gport, cosq, 938 BCMX_COSQ_GPORT_DISCARD_T_PTR_TO_BCM 939 (discard)); 940 if (BCMX_COSQ_GET_IS_VALID(bcm_unit, rv)) { 941 return rv; 942 } 943 } 944 945 return BCM_E_UNAVAIL; 946 } 947 948 /* 949 * Function: 950 * bcmx_cosq_gport_destmod_attach/detach 951 * Purpose: 952 * Attach/detach gport mapping from ingress port, dest_modid to 953 * fabric egress port. 954 * Parameters: 955 * gport - GPORT ID 956 * ingress_port - Ingress port 957 * dest_modid - Destination module ID 958 * fabric_egress_port - Port number on fabric that 959 * is connected to dest_modid 960 * Returns: 961 * BCM_E_xxx 962 */ 963 int 964 bcmx_cosq_gport_destmod_attach(bcm_gport_t gport, bcm_gport_t ingress_port, 965 bcm_module_t dest_modid,int fabric_egress_port) 966 { 967 int bcm_unit; 968 bcm_port_t bcm_port; 969 970 BCMX_COSQ_INIT_CHECK; 971 972 /* 973 * 'gport' is a system-wide value 974 * 'ingress_port' is a physical local port 975 */ 976 BCM_IF_ERROR_RETURN 977 (_bcmx_dest_to_unit_port(ingress_port, &bcm_unit, &bcm_port, 978 BCMX_DEST_CONVERT_NON_GPORT)); 979 980 return bcm_cosq_gport_destmod_attach(bcm_unit, gport, bcm_port, 981 dest_modid, fabric_egress_port); 982 } 983 984 int 985 bcmx_cosq_gport_destmod_detach(bcm_gport_t gport, bcm_gport_t ingress_port, 986 bcm_module_t dest_modid, int fabric_egress_port) 987 { 988 int bcm_unit; 989 bcm_port_t bcm_port; 990 991 BCMX_COSQ_INIT_CHECK; 992 993 /* 994 * 'gport' is a system-wide value 995 * 'ingress_port' is a physical local port 996 */ 997 BCM_IF_ERROR_RETURN 998 (_bcmx_dest_to_unit_port(ingress_port, &bcm_unit, &bcm_port, 999 BCMX_DEST_CONVERT_NON_GPORT)); 1000 1001 return bcm_cosq_gport_destmod_detach(bcm_unit, gport, bcm_port, 1002 dest_modid, fabric_egress_port); 1003 } 1004 1005 /* 1006 * Function: 1007 * bcmx_cosq_stat_get/get32 1008 * Purpose: 1009 * Get MMU drop statistics on a per port per cosq basis. 1010 * Parameters: 1011 * gport - Logical port 1012 * cosq - COS queue 1013 * stat - Statistic to be retrieved 1014 * value - (OUT) Returned statistic value 1015 * Returns: 1016 * BCM_E_XXX 1017 * Notes: 1018 */ 1019 int 1020 bcmx_cosq_stat_get(bcm_gport_t gport, bcm_cos_queue_t cosq, 1021 bcm_cosq_stat_t stat, uint64 *value) 1022 { 1023 int bcm_unit; 1024 bcm_port_t bcm_port; 1025 1026 BCMX_COSQ_INIT_CHECK; 1027 1028 BCMX_PARAM_NULL_CHECK(value); 1029 1030 BCM_IF_ERROR_RETURN 1031 (_bcmx_dest_to_unit_port(gport, &bcm_unit, &bcm_port, 1032 BCMX_DEST_CONVERT_DEFAULT)); 1033 1034 return bcm_cosq_stat_get(bcm_unit, gport, cosq, stat, value); 1035 } 1036 1037 int 1038 bcmx_cosq_stat_get32(bcm_gport_t gport, bcm_cos_queue_t cosq, 1039 bcm_cosq_stat_t stat, uint32 *value) 1040 { 1041 int bcm_unit; 1042 bcm_port_t bcm_port; 1043 1044 BCMX_COSQ_INIT_CHECK; 1045 1046 BCMX_PARAM_NULL_CHECK(value); 1047 1048 BCM_IF_ERROR_RETURN 1049 (_bcmx_dest_to_unit_port(gport, &bcm_unit, &bcm_port, 1050 BCMX_DEST_CONVERT_DEFAULT)); 1051 1052 return bcm_cosq_stat_get32(bcm_unit, gport, cosq, stat, value); 1053 } 1054 1055 /* 1056 * Function: 1057 * bcmx_cosq_stat_set/set32 1058 * Purpose: 1059 * Set MMU drop statistics on a per port per cosq basis. 1060 * Parameters: 1061 * gport - Logical port 1062 * cosq - COS queue 1063 * stat - Statistic to be set 1064 * value - Statistic value to be set 1065 * Returns: 1066 * BCM_E_XXX 1067 * Notes: 1068 */ 1069 int 1070 bcmx_cosq_stat_set(bcm_gport_t gport, bcm_cos_queue_t cosq, 1071 bcm_cosq_stat_t stat, uint64 value) 1072 { 1073 int bcm_unit; 1074 bcm_port_t bcm_port; 1075 1076 BCMX_COSQ_INIT_CHECK; 1077 1078 BCM_IF_ERROR_RETURN 1079 (_bcmx_dest_to_unit_port(gport, &bcm_unit, &bcm_port, 1080 BCMX_DEST_CONVERT_DEFAULT)); 1081 1082 return bcm_cosq_stat_set(bcm_unit, gport, cosq, stat, value); 1083 } 1084 1085 int 1086 bcmx_cosq_stat_set32(bcm_gport_t gport, bcm_cos_queue_t cosq, 1087 bcm_cosq_stat_t stat, uint32 value) 1088 { 1089 int bcm_unit; 1090 bcm_port_t bcm_port; 1091 1092 BCMX_COSQ_INIT_CHECK; 1093 1094 BCM_IF_ERROR_RETURN 1095 (_bcmx_dest_to_unit_port(gport, &bcm_unit, &bcm_port, 1096 BCMX_DEST_CONVERT_DEFAULT)); 1097 1098 return bcm_cosq_stat_set32(bcm_unit, gport, cosq, stat, value); 1099 }