Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 | // SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2018-2022 Marvell International Ltd. */ #include <errno.h> #include <log.h> #include <time.h> #include <linux/delay.h> #include <mach/cvmx-regs.h> #include <mach/cvmx-csr.h> #include <mach/cvmx-bootmem.h> #include <mach/octeon-model.h> #include <mach/cvmx-fuse.h> #include <mach/octeon-feature.h> #include <mach/cvmx-qlm.h> #include <mach/octeon_qlm.h> #include <mach/cvmx-pcie.h> #include <mach/cvmx-coremask.h> #include <mach/cvmx-agl-defs.h> #include <mach/cvmx-bgxx-defs.h> #include <mach/cvmx-ciu-defs.h> #include <mach/cvmx-gmxx-defs.h> #include <mach/cvmx-gserx-defs.h> #include <mach/cvmx-ilk-defs.h> #include <mach/cvmx-ipd-defs.h> #include <mach/cvmx-pcsx-defs.h> #include <mach/cvmx-pcsxx-defs.h> #include <mach/cvmx-pki-defs.h> #include <mach/cvmx-pko-defs.h> #include <mach/cvmx-xcv-defs.h> #include <mach/cvmx-hwpko.h> #include <mach/cvmx-ilk.h> #include <mach/cvmx-pki.h> #include <mach/cvmx-pko3.h> #include <mach/cvmx-pko3-queue.h> #include <mach/cvmx-pko3-resources.h> #include <mach/cvmx-helper.h> #include <mach/cvmx-helper-board.h> #include <mach/cvmx-helper-cfg.h> #include <mach/cvmx-helper-bgx.h> #include <mach/cvmx-helper-cfg.h> #include <mach/cvmx-helper-util.h> #include <mach/cvmx-helper-pki.h> /* Smalles Round-Robin quantum to use +1 */ #define CVMX_PKO3_RR_QUANTUM_MIN 0x10 static int debug; /* 1 for basic, 2 for detailed trace */ struct cvmx_pko3_dq { unsigned dq_count : 6; /* Number of descriptor queues */ unsigned dq_base : 10; /* Descriptor queue start number */ #define CVMX_PKO3_SWIZZLE_IPD 0x0 }; /* * @INTERNAL * Descriptor Queue to IPD port mapping table. * * This pointer is per-core, contains the virtual address * of a global named block which has 2^12 entries per each * possible node. */ struct cvmx_pko3_dq *__cvmx_pko3_dq_table; int cvmx_pko3_get_queue_base(int ipd_port) { struct cvmx_pko3_dq *dq_table; int ret = -1; unsigned int i; struct cvmx_xport xp = cvmx_helper_ipd_port_to_xport(ipd_port); /* get per-node table */ if (cvmx_unlikely(!__cvmx_pko3_dq_table)) __cvmx_pko3_dq_table_setup(); i = CVMX_PKO3_SWIZZLE_IPD ^ xp.port; /* get per-node table */ dq_table = __cvmx_pko3_dq_table + CVMX_PKO3_IPD_NUM_MAX * xp.node; if (cvmx_likely(dq_table[i].dq_count > 0)) ret = xp.node << 10 | dq_table[i].dq_base; else if (debug) cvmx_printf("ERROR: %s: no queues for ipd_port=%#x\n", __func__, ipd_port); return ret; } int cvmx_pko3_get_queue_num(int ipd_port) { struct cvmx_pko3_dq *dq_table; int ret = -1; unsigned int i; struct cvmx_xport xp = cvmx_helper_ipd_port_to_xport(ipd_port); /* get per-node table */ if (cvmx_unlikely(!__cvmx_pko3_dq_table)) __cvmx_pko3_dq_table_setup(); i = CVMX_PKO3_SWIZZLE_IPD ^ xp.port; /* get per-node table */ dq_table = __cvmx_pko3_dq_table + CVMX_PKO3_IPD_NUM_MAX * xp.node; if (cvmx_likely(dq_table[i].dq_count > 0)) ret = dq_table[i].dq_count; else if (debug) debug("ERROR: %s: no queues for ipd_port=%#x\n", __func__, ipd_port); return ret; } /** * @INTERNAL * * Initialize port/dq table contents */ static void __cvmx_pko3_dq_table_init(void *ptr) { unsigned int size = sizeof(struct cvmx_pko3_dq) * CVMX_PKO3_IPD_NUM_MAX * CVMX_MAX_NODES; memset(ptr, 0, size); } /** * @INTERNAL * * Find or allocate global port/dq map table * which is a named table, contains entries for * all possible OCI nodes. * * The table global pointer is stored in core-local variable * so that every core will call this function once, on first use. */ int __cvmx_pko3_dq_table_setup(void) { void *ptr; ptr = cvmx_bootmem_alloc_named_range_once( /* size */ sizeof(struct cvmx_pko3_dq) * CVMX_PKO3_IPD_NUM_MAX * CVMX_MAX_NODES, /* min_addr, max_addr, align */ 0ull, 0ull, sizeof(struct cvmx_pko3_dq), /* name */ "cvmx_pko3_global_dq_table", __cvmx_pko3_dq_table_init); if (debug) debug("%s: dq_table_ptr=%p\n", __func__, ptr); if (!ptr) return -1; __cvmx_pko3_dq_table = ptr; return 0; } /* * @INTERNAL * Register a range of Descriptor Queues with an interface port * * This function populates the DQ-to-IPD translation table * used by the application to retrieve the DQ range (typically ordered * by priority) for a given IPD-port, which is either a physical port, * or a channel on a channelized interface (i.e. ILK). * * @param xiface is the physical interface number * @param index is either a physical port on an interface * or a channel of an ILK interface * @param dq_base is the first Descriptor Queue number in a consecutive range * @param dq_count is the number of consecutive Descriptor Queues leading * the same channel or port. * * Only a consecutive range of Descriptor Queues can be associated with any * given channel/port, and usually they are ordered from most to least * in terms of scheduling priority. * * Note: thus function only populates the node-local translation table. * NOTE: This function would be cleaner if it had a single ipd_port argument * * @returns 0 on success, -1 on failure. */ int __cvmx_pko3_ipd_dq_register(int xiface, int index, unsigned int dq_base, unsigned int dq_count) { struct cvmx_pko3_dq *dq_table; int ipd_port; unsigned int i; struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); struct cvmx_xport xp; if (__cvmx_helper_xiface_is_null(xiface)) { ipd_port = cvmx_helper_node_to_ipd_port(xi.node, CVMX_PKO3_IPD_PORT_NULL); } else { int p; p = cvmx_helper_get_ipd_port(xiface, index); if (p < 0) { cvmx_printf("ERROR: %s: xiface %#x has no IPD port\n", __func__, xiface); return -1; } ipd_port = p; } xp = cvmx_helper_ipd_port_to_xport(ipd_port); i = CVMX_PKO3_SWIZZLE_IPD ^ xp.port; /* get per-node table */ if (!__cvmx_pko3_dq_table) __cvmx_pko3_dq_table_setup(); dq_table = __cvmx_pko3_dq_table + CVMX_PKO3_IPD_NUM_MAX * xi.node; if (debug) debug("%s: ipd_port=%#x ix=%#x dq %u cnt %u\n", __func__, ipd_port, i, dq_base, dq_count); /* Check the IPD port has not already been configured */ if (dq_table[i].dq_count > 0) { cvmx_printf("%s: ERROR: IPD %#x already registered\n", __func__, ipd_port); return -1; } /* Store DQ# range in the queue lookup table */ dq_table[i].dq_base = dq_base; dq_table[i].dq_count = dq_count; return 0; } /* * @INTERNAL * Convert normal CHAN_E (i.e. IPD port) value to compressed channel form * that is used to populate PKO_LUT. * * Note: This code may be model specific. */ static int cvmx_pko3_chan_2_xchan(uint16_t ipd_port) { u16 xchan; u8 off; static const u8 *xchan_base; static const u8 xchan_base_cn78xx[16] = { /* IPD 0x000 */ 0x3c0 >> 4, /* LBK */ /* IPD 0x100 */ 0x380 >> 4, /* DPI */ /* IPD 0x200 */ 0xfff >> 4, /* not used */ /* IPD 0x300 */ 0xfff >> 4, /* not used */ /* IPD 0x400 */ 0x000 >> 4, /* ILK0 */ /* IPD 0x500 */ 0x100 >> 4, /* ILK1 */ /* IPD 0x600 */ 0xfff >> 4, /* not used */ /* IPD 0x700 */ 0xfff >> 4, /* not used */ /* IPD 0x800 */ 0x200 >> 4, /* BGX0 */ /* IPD 0x900 */ 0x240 >> 4, /* BGX1 */ /* IPD 0xa00 */ 0x280 >> 4, /* BGX2 */ /* IPD 0xb00 */ 0x2c0 >> 4, /* BGX3 */ /* IPD 0xc00 */ 0x300 >> 4, /* BGX4 */ /* IPD 0xd00 */ 0x340 >> 4, /* BGX5 */ /* IPD 0xe00 */ 0xfff >> 4, /* not used */ /* IPD 0xf00 */ 0xfff >> 4 /* not used */ }; static const u8 xchan_base_cn73xx[16] = { /* IPD 0x000 */ 0x0c0 >> 4, /* LBK */ /* IPD 0x100 */ 0x100 >> 4, /* DPI */ /* IPD 0x200 */ 0xfff >> 4, /* not used */ /* IPD 0x300 */ 0xfff >> 4, /* not used */ /* IPD 0x400 */ 0xfff >> 4, /* not used */ /* IPD 0x500 */ 0xfff >> 4, /* not used */ /* IPD 0x600 */ 0xfff >> 4, /* not used */ /* IPD 0x700 */ 0xfff >> 4, /* not used */ /* IPD 0x800 */ 0x000 >> 4, /* BGX0 */ /* IPD 0x900 */ 0x040 >> 4, /* BGX1 */ /* IPD 0xa00 */ 0x080 >> 4, /* BGX2 */ /* IPD 0xb00 */ 0xfff >> 4, /* not used */ /* IPD 0xc00 */ 0xfff >> 4, /* not used */ /* IPD 0xd00 */ 0xfff >> 4, /* not used */ /* IPD 0xe00 */ 0xfff >> 4, /* not used */ /* IPD 0xf00 */ 0xfff >> 4 /* not used */ }; static const u8 xchan_base_cn75xx[16] = { /* IPD 0x000 */ 0x040 >> 4, /* LBK */ /* IPD 0x100 */ 0x080 >> 4, /* DPI */ /* IPD 0x200 */ 0xeee >> 4, /* SRIO0 noop */ /* IPD 0x300 */ 0xfff >> 4, /* not used */ /* IPD 0x400 */ 0xfff >> 4, /* not used */ /* IPD 0x500 */ 0xfff >> 4, /* not used */ /* IPD 0x600 */ 0xfff >> 4, /* not used */ /* IPD 0x700 */ 0xfff >> 4, /* not used */ /* IPD 0x800 */ 0x000 >> 4, /* BGX0 */ /* IPD 0x900 */ 0xfff >> 4, /* not used */ /* IPD 0xa00 */ 0xfff >> 4, /* not used */ /* IPD 0xb00 */ 0xfff >> 4, /* not used */ /* IPD 0xc00 */ 0xfff >> 4, /* not used */ /* IPD 0xd00 */ 0xfff >> 4, /* not used */ /* IPD 0xe00 */ 0xfff >> 4, /* not used */ /* IPD 0xf00 */ 0xfff >> 4 /* not used */ }; if (OCTEON_IS_MODEL(OCTEON_CN73XX)) xchan_base = xchan_base_cn73xx; if (OCTEON_IS_MODEL(OCTEON_CNF75XX)) xchan_base = xchan_base_cn75xx; if (OCTEON_IS_MODEL(OCTEON_CN78XX)) xchan_base = xchan_base_cn78xx; if (!xchan_base) return -1; xchan = ipd_port >> 8; /* ILKx, DPI has 8 bits logical channels, others just 6 */ if (((xchan & 0xfe) == 0x04) || xchan == 0x01) off = ipd_port & 0xff; else off = ipd_port & 0x3f; xchan = xchan_base[xchan & 0xf]; if (xchan == 0xff) return -1; /* Invalid IPD_PORT */ else if (xchan == 0xee) return -2; /* LUT not used */ else return (xchan << 4) | off; } /* * Map channel number in PKO * * @param node is to specify the node to which this configuration is applied. * @param pq_num specifies the Port Queue (i.e. L1) queue number. * @param l2_l3_q_num specifies L2/L3 queue number. * @param channel specifies the channel number to map to the queue. * * The channel assignment applies to L2 or L3 Shaper Queues depending * on the setting of channel credit level. * * @return returns none. */ void cvmx_pko3_map_channel(unsigned int node, unsigned int pq_num, unsigned int l2_l3_q_num, uint16_t channel) { union cvmx_pko_l3_l2_sqx_channel sqx_channel; cvmx_pko_lutx_t lutx; int xchan; sqx_channel.u64 = csr_rd_node(node, CVMX_PKO_L3_L2_SQX_CHANNEL(l2_l3_q_num)); sqx_channel.s.cc_channel = channel; csr_wr_node(node, CVMX_PKO_L3_L2_SQX_CHANNEL(l2_l3_q_num), sqx_channel.u64); /* Convert CHAN_E into compressed channel */ xchan = cvmx_pko3_chan_2_xchan(channel); if (debug) debug("%s: ipd_port=%#x xchan=%#x\n", __func__, channel, xchan); if (xchan < 0) { if (xchan == -1) cvmx_printf("%s: ERROR: channel %#x not recognized\n", __func__, channel); return; } lutx.u64 = 0; lutx.s.valid = 1; lutx.s.pq_idx = pq_num; lutx.s.queue_number = l2_l3_q_num; csr_wr_node(node, CVMX_PKO_LUTX(xchan), lutx.u64); if (debug) debug("%s: channel %#x (compressed=%#x) mapped L2/L3 SQ=%u, PQ=%u\n", __func__, channel, xchan, l2_l3_q_num, pq_num); } /* * @INTERNAL * This function configures port queue scheduling and topology parameters * in hardware. * * @param node is to specify the node to which this configuration is applied. * @param port_queue is the port queue number to be configured. * @param mac_num is the mac number of the mac that will be tied to this port_queue. */ static void cvmx_pko_configure_port_queue(int node, int port_queue, int mac_num) { cvmx_pko_l1_sqx_topology_t pko_l1_topology; cvmx_pko_l1_sqx_shape_t pko_l1_shape; cvmx_pko_l1_sqx_link_t pko_l1_link; pko_l1_topology.u64 = 0; pko_l1_topology.s.link = mac_num; csr_wr_node(node, CVMX_PKO_L1_SQX_TOPOLOGY(port_queue), pko_l1_topology.u64); pko_l1_shape.u64 = 0; pko_l1_shape.s.link = mac_num; csr_wr_node(node, CVMX_PKO_L1_SQX_SHAPE(port_queue), pko_l1_shape.u64); pko_l1_link.u64 = 0; pko_l1_link.s.link = mac_num; csr_wr_node(node, CVMX_PKO_L1_SQX_LINK(port_queue), pko_l1_link.u64); } /* * @INTERNAL * This function configures level 2 queues scheduling and topology parameters * in hardware. * * @param node is to specify the node to which this configuration is applied. * @param queue is the level3 queue number to be configured. * @param parent_queue is the parent queue at next level for this l3 queue. * @param prio is this queue's priority in parent's scheduler. * @param rr_quantum is this queue's round robin quantum value. * @param child_base is the first child queue number in the static prioriy children. * @param child_rr_prio is the round robin children priority. */ static void cvmx_pko_configure_l2_queue(int node, int queue, int parent_queue, int prio, int rr_quantum, int child_base, int child_rr_prio) { cvmx_pko_l2_sqx_schedule_t pko_sq_sched; cvmx_pko_l2_sqx_topology_t pko_child_topology; cvmx_pko_l1_sqx_topology_t pko_parent_topology; /* parent topology configuration */ pko_parent_topology.u64 = csr_rd_node(node, CVMX_PKO_L1_SQX_TOPOLOGY(parent_queue)); pko_parent_topology.s.prio_anchor = child_base; pko_parent_topology.s.rr_prio = child_rr_prio; csr_wr_node(node, CVMX_PKO_L1_SQX_TOPOLOGY(parent_queue), pko_parent_topology.u64); if (debug > 1) debug("CVMX_PKO_L1_SQX_TOPOLOGY(%u): PRIO_ANCHOR=%u PARENT=%u\n", parent_queue, pko_parent_topology.s.prio_anchor, pko_parent_topology.s.link); /* scheduler configuration for this sq in the parent queue */ pko_sq_sched.u64 = 0; pko_sq_sched.s.prio = prio; pko_sq_sched.s.rr_quantum = rr_quantum; csr_wr_node(node, CVMX_PKO_L2_SQX_SCHEDULE(queue), pko_sq_sched.u64); /* child topology configuration */ pko_child_topology.u64 = 0; pko_child_topology.s.parent = parent_queue; csr_wr_node(node, CVMX_PKO_L2_SQX_TOPOLOGY(queue), pko_child_topology.u64); } /* * @INTERNAL * This function configures level 3 queues scheduling and topology parameters * in hardware. * * @param node is to specify the node to which this configuration is applied. * @param queue is the level3 queue number to be configured. * @param parent_queue is the parent queue at next level for this l3 queue. * @param prio is this queue's priority in parent's scheduler. * @param rr_quantum is this queue's round robin quantum value. * @param child_base is the first child queue number in the static prioriy children. * @param child_rr_prio is the round robin children priority. */ static void cvmx_pko_configure_l3_queue(int node, int queue, int parent_queue, int prio, int rr_quantum, int child_base, int child_rr_prio) { cvmx_pko_l3_sqx_schedule_t pko_sq_sched; cvmx_pko_l3_sqx_topology_t pko_child_topology; cvmx_pko_l2_sqx_topology_t pko_parent_topology; /* parent topology configuration */ pko_parent_topology.u64 = csr_rd_node(node, CVMX_PKO_L2_SQX_TOPOLOGY(parent_queue)); pko_parent_topology.s.prio_anchor = child_base; pko_parent_topology.s.rr_prio = child_rr_prio; csr_wr_node(node, CVMX_PKO_L2_SQX_TOPOLOGY(parent_queue), pko_parent_topology.u64); if (debug > 1) debug("CVMX_PKO_L2_SQX_TOPOLOGY(%u): PRIO_ANCHOR=%u PARENT=%u\n", parent_queue, pko_parent_topology.s.prio_anchor, pko_parent_topology.s.parent); /* scheduler configuration for this sq in the parent queue */ pko_sq_sched.u64 = 0; pko_sq_sched.s.prio = prio; pko_sq_sched.s.rr_quantum = rr_quantum; csr_wr_node(node, CVMX_PKO_L3_SQX_SCHEDULE(queue), pko_sq_sched.u64); /* child topology configuration */ pko_child_topology.u64 = 0; pko_child_topology.s.parent = parent_queue; csr_wr_node(node, CVMX_PKO_L3_SQX_TOPOLOGY(queue), pko_child_topology.u64); } /* * @INTERNAL * This function configures level 4 queues scheduling and topology parameters * in hardware. * * @param node is to specify the node to which this configuration is applied. * @param queue is the level4 queue number to be configured. * @param parent_queue is the parent queue at next level for this l4 queue. * @param prio is this queue's priority in parent's scheduler. * @param rr_quantum is this queue's round robin quantum value. * @param child_base is the first child queue number in the static prioriy children. * @param child_rr_prio is the round robin children priority. */ static void cvmx_pko_configure_l4_queue(int node, int queue, int parent_queue, int prio, int rr_quantum, int child_base, int child_rr_prio) { cvmx_pko_l4_sqx_schedule_t pko_sq_sched; cvmx_pko_l4_sqx_topology_t pko_child_topology; cvmx_pko_l3_sqx_topology_t pko_parent_topology; /* parent topology configuration */ pko_parent_topology.u64 = csr_rd_node(node, CVMX_PKO_L3_SQX_TOPOLOGY(parent_queue)); pko_parent_topology.s.prio_anchor = child_base; pko_parent_topology.s.rr_prio = child_rr_prio; csr_wr_node(node, CVMX_PKO_L3_SQX_TOPOLOGY(parent_queue), pko_parent_topology.u64); if (debug > 1) debug("CVMX_PKO_L3_SQX_TOPOLOGY(%u): PRIO_ANCHOR=%u PARENT=%u\n", parent_queue, pko_parent_topology.s.prio_anchor, pko_parent_topology.s.parent); /* scheduler configuration for this sq in the parent queue */ pko_sq_sched.u64 = 0; pko_sq_sched.s.prio = prio; pko_sq_sched.s.rr_quantum = rr_quantum; csr_wr_node(node, CVMX_PKO_L4_SQX_SCHEDULE(queue), pko_sq_sched.u64); /* topology configuration */ pko_child_topology.u64 = 0; pko_child_topology.s.parent = parent_queue; csr_wr_node(node, CVMX_PKO_L4_SQX_TOPOLOGY(queue), pko_child_topology.u64); } /* * @INTERNAL * This function configures level 5 queues scheduling and topology parameters * in hardware. * * @param node is to specify the node to which this configuration is applied. * @param queue is the level5 queue number to be configured. * @param parent_queue is the parent queue at next level for this l5 queue. * @param prio is this queue's priority in parent's scheduler. * @param rr_quantum is this queue's round robin quantum value. * @param child_base is the first child queue number in the static prioriy children. * @param child_rr_prio is the round robin children priority. */ static void cvmx_pko_configure_l5_queue(int node, int queue, int parent_queue, int prio, int rr_quantum, int child_base, int child_rr_prio) { cvmx_pko_l5_sqx_schedule_t pko_sq_sched; cvmx_pko_l4_sqx_topology_t pko_parent_topology; cvmx_pko_l5_sqx_topology_t pko_child_topology; /* parent topology configuration */ pko_parent_topology.u64 = csr_rd_node(node, CVMX_PKO_L4_SQX_TOPOLOGY(parent_queue)); pko_parent_topology.s.prio_anchor = child_base; pko_parent_topology.s.rr_prio = child_rr_prio; csr_wr_node(node, CVMX_PKO_L4_SQX_TOPOLOGY(parent_queue), pko_parent_topology.u64); if (debug > 1) debug("CVMX_PKO_L4_SQX_TOPOLOGY(%u): PRIO_ANCHOR=%u PARENT=%u\n", parent_queue, pko_parent_topology.s.prio_anchor, pko_parent_topology.s.parent); /* scheduler configuration for this sq in the parent queue */ pko_sq_sched.u64 = 0; pko_sq_sched.s.prio = prio; pko_sq_sched.s.rr_quantum = rr_quantum; csr_wr_node(node, CVMX_PKO_L5_SQX_SCHEDULE(queue), pko_sq_sched.u64); /* topology configuration */ pko_child_topology.u64 = 0; pko_child_topology.s.parent = parent_queue; csr_wr_node(node, CVMX_PKO_L5_SQX_TOPOLOGY(queue), pko_child_topology.u64); } /* * @INTERNAL * This function configures descriptor queues scheduling and topology parameters * in hardware. * * @param node is to specify the node to which this configuration is applied. * @param dq is the descriptor queue number to be configured. * @param parent_queue is the parent queue at next level for this dq. * @param prio is this queue's priority in parent's scheduler. * @param rr_quantum is this queue's round robin quantum value. * @param child_base is the first child queue number in the static prioriy children. * @param child_rr_prio is the round robin children priority. */ static void cvmx_pko_configure_dq(int node, int dq, int parent_queue, int prio, int rr_quantum, int child_base, int child_rr_prio) { cvmx_pko_dqx_schedule_t pko_dq_sched; cvmx_pko_dqx_topology_t pko_dq_topology; cvmx_pko_l5_sqx_topology_t pko_parent_topology; cvmx_pko_dqx_wm_ctl_t pko_dq_wm_ctl; unsigned long long parent_topology_reg; char lvl; if (debug) debug("%s: dq %u parent %u child_base %u\n", __func__, dq, parent_queue, child_base); if (__cvmx_pko3_sq_lvl_max() == CVMX_PKO_L5_QUEUES) { parent_topology_reg = CVMX_PKO_L5_SQX_TOPOLOGY(parent_queue); lvl = 5; } else if (__cvmx_pko3_sq_lvl_max() == CVMX_PKO_L3_QUEUES) { parent_topology_reg = CVMX_PKO_L3_SQX_TOPOLOGY(parent_queue); lvl = 3; } else { return; } if (debug) debug("%s: parent_topology_reg=%#llx\n", __func__, parent_topology_reg); /* parent topology configuration */ pko_parent_topology.u64 = csr_rd_node(node, parent_topology_reg); pko_parent_topology.s.prio_anchor = child_base; pko_parent_topology.s.rr_prio = child_rr_prio; csr_wr_node(node, parent_topology_reg, pko_parent_topology.u64); if (debug > 1) debug("CVMX_PKO_L%d_SQX_TOPOLOGY(%u): PRIO_ANCHOR=%u PARENT=%u\n", lvl, parent_queue, pko_parent_topology.s.prio_anchor, pko_parent_topology.s.parent); /* scheduler configuration for this dq in the parent queue */ pko_dq_sched.u64 = 0; pko_dq_sched.s.prio = prio; pko_dq_sched.s.rr_quantum = rr_quantum; csr_wr_node(node, CVMX_PKO_DQX_SCHEDULE(dq), pko_dq_sched.u64); /* topology configuration */ pko_dq_topology.u64 = 0; pko_dq_topology.s.parent = parent_queue; csr_wr_node(node, CVMX_PKO_DQX_TOPOLOGY(dq), pko_dq_topology.u64); /* configure for counting packets, not bytes at this level */ pko_dq_wm_ctl.u64 = 0; pko_dq_wm_ctl.s.kind = 1; pko_dq_wm_ctl.s.enable = 0; csr_wr_node(node, CVMX_PKO_DQX_WM_CTL(dq), pko_dq_wm_ctl.u64); if (debug > 1) { pko_dq_sched.u64 = csr_rd_node(node, CVMX_PKO_DQX_SCHEDULE(dq)); pko_dq_topology.u64 = csr_rd_node(node, CVMX_PKO_DQX_TOPOLOGY(dq)); debug("CVMX_PKO_DQX_TOPOLOGY(%u)PARENT=%u CVMX_PKO_DQX_SCHEDULE(%u) PRIO=%u Q=%u\n", dq, pko_dq_topology.s.parent, dq, pko_dq_sched.s.prio, pko_dq_sched.s.rr_quantum); } } /* * @INTERNAL * The following structure selects the Scheduling Queue configuration * routine for each of the supported levels. * The initial content of the table will be setup in accordance * to the specific SoC model and its implemented resources */ struct pko3_cfg_tab_s { /* function pointer for to configure the given level, last=DQ */ struct { u8 parent_level; void (*cfg_sq_func)(int node, int queue, int parent_queue, int prio, int rr_quantum, int child_base, int child_rr_prio); //XXX for debugging exagerated size } lvl[256]; }; static const struct pko3_cfg_tab_s pko3_cn78xx_cfg = { { [CVMX_PKO_L2_QUEUES] = { CVMX_PKO_PORT_QUEUES, cvmx_pko_configure_l2_queue }, [CVMX_PKO_L3_QUEUES] = { CVMX_PKO_L2_QUEUES, cvmx_pko_configure_l3_queue }, [CVMX_PKO_L4_QUEUES] = { CVMX_PKO_L3_QUEUES, cvmx_pko_configure_l4_queue }, [CVMX_PKO_L5_QUEUES] = { CVMX_PKO_L4_QUEUES, cvmx_pko_configure_l5_queue }, [CVMX_PKO_DESCR_QUEUES] = { CVMX_PKO_L5_QUEUES, cvmx_pko_configure_dq } } }; static const struct pko3_cfg_tab_s pko3_cn73xx_cfg = { { [CVMX_PKO_L2_QUEUES] = { CVMX_PKO_PORT_QUEUES, cvmx_pko_configure_l2_queue }, [CVMX_PKO_L3_QUEUES] = { CVMX_PKO_L2_QUEUES, cvmx_pko_configure_l3_queue }, [CVMX_PKO_DESCR_QUEUES] = { CVMX_PKO_L3_QUEUES, cvmx_pko_configure_dq } } }; /* * Configure Port Queue and its children Scheduler Queue * * Port Queues (a.k.a L1) are assigned 1-to-1 to MACs. * L2 Scheduler Queues are used for specifying channels, and thus there * could be multiple L2 SQs attached to a single L1 PQ, either in a * fair round-robin scheduling, or with static and/or round-robin priorities. * * @param node on which to operate * @param mac_num is the LMAC number to that is associated with the Port Queue, * @param pq_num is the number of the L1 PQ attached to the MAC * * @returns 0 on success, -1 on failure. */ int cvmx_pko3_pq_config(unsigned int node, unsigned int mac_num, unsigned int pq_num) { char b1[10]; if (debug) debug("%s: MAC%u -> %s\n", __func__, mac_num, __cvmx_pko3_sq_str(b1, CVMX_PKO_PORT_QUEUES, pq_num)); cvmx_pko_configure_port_queue(node, pq_num, mac_num); return 0; } /* * Configure L3 through L5 Scheduler Queues and Descriptor Queues * * The Scheduler Queues in Levels 3 to 5 and Descriptor Queues are * configured one-to-one or many-to-one to a single parent Scheduler * Queues. The level of the parent SQ is specified in an argument, * as well as the number of children to attach to the specific parent. * The children can have fair round-robin or priority-based scheduling * when multiple children are assigned a single parent. * * @param node on which to operate * @param child_level is the level of the child queue * @param parent_queue is the number of the parent Scheduler Queue * @param child_base is the number of the first child SQ or DQ to assign to * @param child_count is the number of consecutive children to assign * @param stat_prio_count is the priority setting for the children L2 SQs * * If <stat_prio_count> is -1, the Ln children will have equal Round-Robin * relationship with eachother. If <stat_prio_count> is 0, all Ln children * will be arranged in Weighted-Round-Robin, with the first having the most * precedence. If <stat_prio_count> is between 1 and 8, it indicates how * many children will have static priority settings (with the first having * the most precedence), with the remaining Ln children having WRR scheduling. * * @returns 0 on success, -1 on failure. * * Note: this function supports the configuration of node-local unit. */ int cvmx_pko3_sq_config_children(unsigned int node, enum cvmx_pko3_level_e child_level, unsigned int parent_queue, unsigned int child_base, unsigned int child_count, int stat_prio_count) { enum cvmx_pko3_level_e parent_level; unsigned int num_elem = 0; unsigned int rr_quantum, rr_count; unsigned int child, prio, rr_prio; const struct pko3_cfg_tab_s *cfg_tbl = NULL; char b1[10], b2[10]; if (OCTEON_IS_MODEL(OCTEON_CN78XX)) { num_elem = NUM_ELEMENTS(pko3_cn78xx_cfg.lvl); cfg_tbl = &pko3_cn78xx_cfg; } if (OCTEON_IS_MODEL(OCTEON_CN73XX) || OCTEON_IS_MODEL(OCTEON_CNF75XX)) { num_elem = NUM_ELEMENTS(pko3_cn73xx_cfg.lvl); cfg_tbl = &pko3_cn73xx_cfg; } if (!cfg_tbl || child_level >= num_elem) { cvmx_printf("ERROR: %s: model or level %#x invalid\n", __func__, child_level); return -1; } parent_level = cfg_tbl->lvl[child_level].parent_level; if (!cfg_tbl->lvl[child_level].cfg_sq_func || cfg_tbl->lvl[child_level].parent_level == 0) { cvmx_printf("ERROR: %s: queue level %#x invalid\n", __func__, child_level); return -1; } /* First static priority is 0 - top precedence */ prio = 0; if (stat_prio_count > (signed int)child_count) stat_prio_count = child_count; /* Valid PRIO field is 0..9, limit maximum static priorities */ if (stat_prio_count > 9) stat_prio_count = 9; /* Special case of a single child */ if (child_count == 1) { rr_count = 0; rr_prio = 0xF; /* Special case for Fair-RR */ } else if (stat_prio_count < 0) { rr_count = child_count; rr_prio = 0; } else { rr_count = child_count - stat_prio_count; rr_prio = stat_prio_count; } /* Compute highest RR_QUANTUM */ if (stat_prio_count > 0) rr_quantum = CVMX_PKO3_RR_QUANTUM_MIN * rr_count; else rr_quantum = CVMX_PKO3_RR_QUANTUM_MIN; if (debug) debug("%s: Parent %s child_base %u rr_pri %u\n", __func__, __cvmx_pko3_sq_str(b1, parent_level, parent_queue), child_base, rr_prio); /* Parent is configured with child */ for (child = child_base; child < (child_base + child_count); child++) { if (debug) debug("%s: Child %s of %s prio %u rr_quantum %#x\n", __func__, __cvmx_pko3_sq_str(b1, child_level, child), __cvmx_pko3_sq_str(b2, parent_level, parent_queue), prio, rr_quantum); cfg_tbl->lvl[child_level].cfg_sq_func(node, child, parent_queue, prio, rr_quantum, child_base, rr_prio); if (prio < rr_prio) prio++; else if (stat_prio_count > 0) rr_quantum -= CVMX_PKO3_RR_QUANTUM_MIN; } /* for child */ return 0; } |