1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
9 nix_tm_shaper2regval(struct nix_tm_shaper_data *shaper)
13 if (roc_model_is_cn9k()) {
14 regval = (shaper->burst_exponent << 37);
15 regval |= (shaper->burst_mantissa << 29);
16 regval |= (shaper->div_exp << 13);
17 regval |= (shaper->exponent << 9);
18 regval |= (shaper->mantissa << 1);
22 regval = (shaper->burst_exponent << 44);
23 regval |= (shaper->burst_mantissa << 29);
24 regval |= (shaper->div_exp << 13);
25 regval |= (shaper->exponent << 9);
26 regval |= (shaper->mantissa << 1);
31 nix_tm_lvl2nix_tl1_root(uint32_t lvl)
35 return NIX_TXSCH_LVL_TL1;
37 return NIX_TXSCH_LVL_TL2;
39 return NIX_TXSCH_LVL_TL3;
41 return NIX_TXSCH_LVL_TL4;
43 return NIX_TXSCH_LVL_SMQ;
45 return NIX_TXSCH_LVL_CNT;
50 nix_tm_lvl2nix_tl2_root(uint32_t lvl)
54 return NIX_TXSCH_LVL_TL2;
56 return NIX_TXSCH_LVL_TL3;
58 return NIX_TXSCH_LVL_TL4;
60 return NIX_TXSCH_LVL_SMQ;
62 return NIX_TXSCH_LVL_CNT;
67 nix_tm_lvl2nix(struct nix *nix, uint32_t lvl)
69 if (nix_tm_have_tl1_access(nix))
70 return nix_tm_lvl2nix_tl1_root(lvl);
72 return nix_tm_lvl2nix_tl2_root(lvl);
76 nix_tm_relchan_get(struct nix *nix)
78 return nix->tx_chan_base & 0xff;
82 nix_tm_find_prio_anchor(struct nix *nix, uint32_t node_id,
83 enum roc_nix_tm_tree tree)
85 struct nix_tm_node *child_node;
86 struct nix_tm_node_list *list;
88 list = nix_tm_node_list(nix, tree);
90 TAILQ_FOREACH(child_node, list, node) {
91 if (!child_node->parent)
93 if (!(child_node->parent->id == node_id))
95 if (child_node->priority == child_node->parent->rr_prio)
97 return child_node->hw_id - child_node->priority;
102 struct nix_tm_shaper_profile *
103 nix_tm_shaper_profile_search(struct nix *nix, uint32_t id)
105 struct nix_tm_shaper_profile *profile;
107 TAILQ_FOREACH(profile, &nix->shaper_profile_list, shaper) {
108 if (profile->id == id)
115 nix_tm_node_search(struct nix *nix, uint32_t node_id, enum roc_nix_tm_tree tree)
117 struct nix_tm_node_list *list;
118 struct nix_tm_node *node;
120 list = nix_tm_node_list(nix, tree);
121 TAILQ_FOREACH(node, list, node) {
122 if (node->id == node_id)
129 nix_tm_shaper_rate_conv(uint64_t value, uint64_t *exponent_p,
130 uint64_t *mantissa_p, uint64_t *div_exp_p)
132 uint64_t div_exp, exponent, mantissa;
134 /* Boundary checks */
135 if (value < NIX_TM_MIN_SHAPER_RATE || value > NIX_TM_MAX_SHAPER_RATE)
138 if (value <= NIX_TM_SHAPER_RATE(0, 0, 0)) {
139 /* Calculate rate div_exp and mantissa using
140 * the following formula:
142 * value = (2E6 * (256 + mantissa)
143 * / ((1 << div_exp) * 256))
147 mantissa = NIX_TM_MAX_RATE_MANTISSA;
149 while (value < (NIX_TM_SHAPER_RATE_CONST / (1 << div_exp)))
152 while (value < ((NIX_TM_SHAPER_RATE_CONST * (256 + mantissa)) /
153 ((1 << div_exp) * 256)))
156 /* Calculate rate exponent and mantissa using
157 * the following formula:
159 * value = (2E6 * ((256 + mantissa) << exponent)) / 256
163 exponent = NIX_TM_MAX_RATE_EXPONENT;
164 mantissa = NIX_TM_MAX_RATE_MANTISSA;
166 while (value < (NIX_TM_SHAPER_RATE_CONST * (1 << exponent)))
169 while (value < ((NIX_TM_SHAPER_RATE_CONST *
170 ((256 + mantissa) << exponent)) /
175 if (div_exp > NIX_TM_MAX_RATE_DIV_EXP ||
176 exponent > NIX_TM_MAX_RATE_EXPONENT ||
177 mantissa > NIX_TM_MAX_RATE_MANTISSA)
181 *div_exp_p = div_exp;
183 *exponent_p = exponent;
185 *mantissa_p = mantissa;
187 /* Calculate real rate value */
188 return NIX_TM_SHAPER_RATE(exponent, mantissa, div_exp);
192 nix_tm_shaper_burst_conv(uint64_t value, uint64_t *exponent_p,
193 uint64_t *mantissa_p)
195 uint64_t min_burst, max_burst;
196 uint64_t exponent, mantissa;
197 uint32_t max_mantissa;
199 min_burst = NIX_TM_MIN_SHAPER_BURST;
200 max_burst = roc_nix_tm_max_shaper_burst_get();
202 if (value < min_burst || value > max_burst)
205 max_mantissa = (roc_model_is_cn9k() ? NIX_CN9K_TM_MAX_BURST_MANTISSA :
206 NIX_TM_MAX_BURST_MANTISSA);
207 /* Calculate burst exponent and mantissa using
208 * the following formula:
210 * value = (((256 + mantissa) << (exponent + 1) / 256)
213 exponent = NIX_TM_MAX_BURST_EXPONENT;
214 mantissa = max_mantissa;
216 while (value < (1ull << (exponent + 1)))
219 while (value < ((256 + mantissa) << (exponent + 1)) / 256)
222 if (exponent > NIX_TM_MAX_BURST_EXPONENT || mantissa > max_mantissa)
226 *exponent_p = exponent;
228 *mantissa_p = mantissa;
230 return NIX_TM_SHAPER_BURST(exponent, mantissa);
234 nix_tm_shaper_conf_get(struct nix_tm_shaper_profile *profile,
235 struct nix_tm_shaper_data *cir,
236 struct nix_tm_shaper_data *pir)
241 /* Calculate CIR exponent and mantissa */
242 if (profile->commit.rate)
243 cir->rate = nix_tm_shaper_rate_conv(
244 profile->commit.rate, &cir->exponent, &cir->mantissa,
247 /* Calculate PIR exponent and mantissa */
248 if (profile->peak.rate)
249 pir->rate = nix_tm_shaper_rate_conv(
250 profile->peak.rate, &pir->exponent, &pir->mantissa,
253 /* Calculate CIR burst exponent and mantissa */
254 if (profile->commit.size)
255 cir->burst = nix_tm_shaper_burst_conv(profile->commit.size,
256 &cir->burst_exponent,
257 &cir->burst_mantissa);
259 /* Calculate PIR burst exponent and mantissa */
260 if (profile->peak.size)
261 pir->burst = nix_tm_shaper_burst_conv(profile->peak.size,
262 &pir->burst_exponent,
263 &pir->burst_mantissa);
267 nix_tm_check_rr(struct nix *nix, uint32_t parent_id, enum roc_nix_tm_tree tree,
268 uint32_t *rr_prio, uint32_t *max_prio)
270 uint32_t node_cnt[NIX_TM_TLX_SP_PRIO_MAX];
271 struct nix_tm_node_list *list;
272 struct nix_tm_node *node;
273 uint32_t rr_num = 0, i;
274 uint32_t children = 0;
277 memset(node_cnt, 0, sizeof(node_cnt));
279 *max_prio = UINT32_MAX;
281 list = nix_tm_node_list(nix, tree);
282 TAILQ_FOREACH(node, list, node) {
286 if (!(node->parent->id == parent_id))
289 priority = node->priority;
290 node_cnt[priority]++;
294 for (i = 0; i < NIX_TM_TLX_SP_PRIO_MAX; i++) {
298 if (node_cnt[i] > rr_num) {
300 rr_num = node_cnt[i];
304 /* RR group of single RR child is considered as SP */
310 /* Max prio will be returned only when we have non zero prio
311 * or if a parent has single child.
313 if (i > 1 || (children == 1))
319 nix_tm_max_prio(struct nix *nix, uint16_t hw_lvl)
321 if (hw_lvl >= NIX_TXSCH_LVL_CNT)
324 /* MDQ does not support SP */
325 if (hw_lvl == NIX_TXSCH_LVL_MDQ)
328 /* PF's TL1 with VF's enabled does not support SP */
329 if (hw_lvl == NIX_TXSCH_LVL_TL1 && (!nix_tm_have_tl1_access(nix) ||
330 (nix->tm_flags & NIX_TM_TL1_NO_SP)))
333 return NIX_TM_TLX_SP_PRIO_MAX - 1;
337 nix_tm_validate_prio(struct nix *nix, uint32_t lvl, uint32_t parent_id,
338 uint32_t priority, enum roc_nix_tm_tree tree)
340 uint8_t priorities[NIX_TM_TLX_SP_PRIO_MAX];
341 struct nix_tm_node_list *list;
342 struct nix_tm_node *node;
346 list = nix_tm_node_list(nix, tree);
347 /* Validate priority against max */
348 if (priority > nix_tm_max_prio(nix, nix_tm_lvl2nix(nix, lvl - 1)))
349 return NIX_ERR_TM_PRIO_EXCEEDED;
351 if (parent_id == ROC_NIX_TM_NODE_ID_INVALID)
354 memset(priorities, 0, sizeof(priorities));
355 priorities[priority] = 1;
357 TAILQ_FOREACH(node, list, node) {
361 if (node->parent->id != parent_id)
364 priorities[node->priority]++;
367 for (i = 0; i < NIX_TM_TLX_SP_PRIO_MAX; i++)
368 if (priorities[i] > 1)
371 /* At max, one rr groups per parent */
373 return NIX_ERR_TM_MULTIPLE_RR_GROUPS;
375 /* Check for previous priority to avoid holes in priorities */
376 if (priority && !priorities[priority - 1])
377 return NIX_ERR_TM_PRIO_ORDER;
383 nix_tm_child_res_valid(struct nix_tm_node_list *list,
384 struct nix_tm_node *parent)
386 struct nix_tm_node *child;
388 TAILQ_FOREACH(child, list, node) {
389 if (child->parent != parent)
391 if (!(child->flags & NIX_TM_NODE_HWRES))
398 nix_tm_tl1_default_prep(uint32_t schq, volatile uint64_t *reg,
399 volatile uint64_t *regval)
404 * Default config for TL1.
405 * For VF this is always ignored.
407 plt_tm_dbg("Default config for main root %s(%u)",
408 nix_tm_hwlvl2str(NIX_TXSCH_LVL_TL1), schq);
410 /* Set DWRR quantum */
411 reg[k] = NIX_AF_TL1X_SCHEDULE(schq);
412 regval[k] = NIX_TM_TL1_DFLT_RR_QTM;
415 reg[k] = NIX_AF_TL1X_TOPOLOGY(schq);
416 regval[k] = (NIX_TM_TL1_DFLT_RR_PRIO << 1);
419 reg[k] = NIX_AF_TL1X_CIR(schq);
427 nix_tm_topology_reg_prep(struct nix *nix, struct nix_tm_node *node,
428 volatile uint64_t *reg, volatile uint64_t *regval,
429 volatile uint64_t *regval_mask)
431 struct roc_nix *roc_nix = nix_priv_to_roc_nix(nix);
432 uint8_t k = 0, hw_lvl, parent_lvl;
433 uint64_t parent = 0, child = 0;
434 enum roc_nix_tm_tree tree;
435 uint32_t rr_prio, schq;
436 uint16_t link, relchan;
440 hw_lvl = node->hw_lvl;
441 parent_lvl = hw_lvl + 1;
442 rr_prio = node->rr_prio;
444 /* Root node will not have a parent node */
445 if (hw_lvl == nix->tm_root_lvl)
446 parent = node->parent_hw_id;
448 parent = node->parent->hw_id;
451 relchan = nix_tm_relchan_get(nix);
453 if (hw_lvl != NIX_TXSCH_LVL_SMQ)
454 child = nix_tm_find_prio_anchor(nix, node->id, tree);
456 /* Override default rr_prio when TL1
457 * Static Priority is disabled
459 if (hw_lvl == NIX_TXSCH_LVL_TL1 && nix->tm_flags & NIX_TM_TL1_NO_SP) {
460 rr_prio = NIX_TM_TL1_DFLT_RR_PRIO;
464 plt_tm_dbg("Topology config node %s(%u)->%s(%" PRIu64 ") lvl %u, id %u"
465 " prio_anchor %" PRIu64 " rr_prio %u (%p)",
466 nix_tm_hwlvl2str(hw_lvl), schq, nix_tm_hwlvl2str(parent_lvl),
467 parent, node->lvl, node->id, child, rr_prio, node);
469 /* Prepare Topology and Link config */
471 case NIX_TXSCH_LVL_SMQ:
473 /* Set xoff which will be cleared later */
474 reg[k] = NIX_AF_SMQX_CFG(schq);
475 regval[k] = (BIT_ULL(50) | NIX_MIN_HW_FRS |
476 ((nix->mtu & 0xFFFF) << 8));
477 /* Maximum Vtag insertion size as a multiple of four bytes */
478 if (roc_nix->hw_vlan_ins)
479 regval[k] |= (0x2ULL << 36);
480 regval_mask[k] = ~(BIT_ULL(50) | GENMASK_ULL(6, 0) |
481 GENMASK_ULL(23, 8) | GENMASK_ULL(38, 36));
484 /* Parent and schedule conf */
485 reg[k] = NIX_AF_MDQX_PARENT(schq);
486 regval[k] = parent << 16;
490 case NIX_TXSCH_LVL_TL4:
491 /* Parent and schedule conf */
492 reg[k] = NIX_AF_TL4X_PARENT(schq);
493 regval[k] = parent << 16;
496 reg[k] = NIX_AF_TL4X_TOPOLOGY(schq);
497 regval[k] = (child << 32) | (rr_prio << 1);
500 /* Configure TL4 to send to SDP channel instead of CGX/LBK */
502 reg[k] = NIX_AF_TL4X_SDP_LINK_CFG(schq);
503 regval[k] = BIT_ULL(12);
507 case NIX_TXSCH_LVL_TL3:
508 /* Parent and schedule conf */
509 reg[k] = NIX_AF_TL3X_PARENT(schq);
510 regval[k] = parent << 16;
513 reg[k] = NIX_AF_TL3X_TOPOLOGY(schq);
514 regval[k] = (child << 32) | (rr_prio << 1);
517 /* Link configuration */
518 if (!nix->sdp_link &&
519 nix->tm_link_cfg_lvl == NIX_TXSCH_LVL_TL3) {
520 reg[k] = NIX_AF_TL3_TL2X_LINKX_CFG(schq, link);
521 regval[k] = BIT_ULL(12) | relchan;
526 case NIX_TXSCH_LVL_TL2:
527 /* Parent and schedule conf */
528 reg[k] = NIX_AF_TL2X_PARENT(schq);
529 regval[k] = parent << 16;
532 reg[k] = NIX_AF_TL2X_TOPOLOGY(schq);
533 regval[k] = (child << 32) | (rr_prio << 1);
536 /* Link configuration */
537 if (!nix->sdp_link &&
538 nix->tm_link_cfg_lvl == NIX_TXSCH_LVL_TL2) {
539 reg[k] = NIX_AF_TL3_TL2X_LINKX_CFG(schq, link);
540 regval[k] = BIT_ULL(12) | relchan;
545 case NIX_TXSCH_LVL_TL1:
546 reg[k] = NIX_AF_TL1X_TOPOLOGY(schq);
547 regval[k] = (child << 32) | (rr_prio << 1 /*RR_PRIO*/);
557 nix_tm_sched_reg_prep(struct nix *nix, struct nix_tm_node *node,
558 volatile uint64_t *reg, volatile uint64_t *regval)
560 uint64_t strict_prio = node->priority;
561 uint32_t hw_lvl = node->hw_lvl;
562 uint32_t schq = node->hw_id;
566 /* For CN9K, weight needs to be converted to quantum */
567 rr_quantum = nix_tm_weight_to_rr_quantum(node->weight);
569 /* For children to root, strict prio is default if either
570 * device root is TL2 or TL1 Static Priority is disabled.
572 if (hw_lvl == NIX_TXSCH_LVL_TL2 &&
573 (!nix_tm_have_tl1_access(nix) || nix->tm_flags & NIX_TM_TL1_NO_SP))
574 strict_prio = NIX_TM_TL1_DFLT_RR_PRIO;
576 plt_tm_dbg("Schedule config node %s(%u) lvl %u id %u, "
577 "prio 0x%" PRIx64 ", rr_quantum/rr_wt 0x%" PRIx64 " (%p)",
578 nix_tm_hwlvl2str(node->hw_lvl), schq, node->lvl, node->id,
579 strict_prio, rr_quantum, node);
582 case NIX_TXSCH_LVL_SMQ:
583 reg[k] = NIX_AF_MDQX_SCHEDULE(schq);
584 regval[k] = (strict_prio << 24) | rr_quantum;
588 case NIX_TXSCH_LVL_TL4:
589 reg[k] = NIX_AF_TL4X_SCHEDULE(schq);
590 regval[k] = (strict_prio << 24) | rr_quantum;
594 case NIX_TXSCH_LVL_TL3:
595 reg[k] = NIX_AF_TL3X_SCHEDULE(schq);
596 regval[k] = (strict_prio << 24) | rr_quantum;
600 case NIX_TXSCH_LVL_TL2:
601 reg[k] = NIX_AF_TL2X_SCHEDULE(schq);
602 regval[k] = (strict_prio << 24) | rr_quantum;
606 case NIX_TXSCH_LVL_TL1:
607 reg[k] = NIX_AF_TL1X_SCHEDULE(schq);
608 regval[k] = rr_quantum;
618 nix_tm_shaper_reg_prep(struct nix_tm_node *node,
619 struct nix_tm_shaper_profile *profile,
620 volatile uint64_t *reg, volatile uint64_t *regval)
622 struct nix_tm_shaper_data cir, pir;
623 uint32_t schq = node->hw_id;
627 memset(&cir, 0, sizeof(cir));
628 memset(&pir, 0, sizeof(pir));
629 nix_tm_shaper_conf_get(profile, &cir, &pir);
631 if (profile && node->pkt_mode)
632 adjust = profile->pkt_mode_adj;
634 adjust = profile->pkt_len_adj;
636 plt_tm_dbg("Shaper config node %s(%u) lvl %u id %u, "
637 "pir %" PRIu64 "(%" PRIu64 "B),"
638 " cir %" PRIu64 "(%" PRIu64 "B)"
639 "adjust 0x%" PRIx64 "(pktmode %u) (%p)",
640 nix_tm_hwlvl2str(node->hw_lvl), schq, node->lvl, node->id,
641 pir.rate, pir.burst, cir.rate, cir.burst, adjust,
642 node->pkt_mode, node);
644 switch (node->hw_lvl) {
645 case NIX_TXSCH_LVL_SMQ:
646 /* Configure PIR, CIR */
647 reg[k] = NIX_AF_MDQX_PIR(schq);
648 regval[k] = (pir.rate && pir.burst) ?
649 (nix_tm_shaper2regval(&pir) | 1) :
653 reg[k] = NIX_AF_MDQX_CIR(schq);
654 regval[k] = (cir.rate && cir.burst) ?
655 (nix_tm_shaper2regval(&cir) | 1) :
659 /* Configure RED ALG */
660 reg[k] = NIX_AF_MDQX_SHAPE(schq);
661 regval[k] = (adjust | (uint64_t)node->red_algo << 9 |
662 (uint64_t)node->pkt_mode << 24);
665 case NIX_TXSCH_LVL_TL4:
666 /* Configure PIR, CIR */
667 reg[k] = NIX_AF_TL4X_PIR(schq);
668 regval[k] = (pir.rate && pir.burst) ?
669 (nix_tm_shaper2regval(&pir) | 1) :
673 reg[k] = NIX_AF_TL4X_CIR(schq);
674 regval[k] = (cir.rate && cir.burst) ?
675 (nix_tm_shaper2regval(&cir) | 1) :
679 /* Configure RED algo */
680 reg[k] = NIX_AF_TL4X_SHAPE(schq);
681 regval[k] = (adjust | (uint64_t)node->red_algo << 9 |
682 (uint64_t)node->pkt_mode << 24);
685 case NIX_TXSCH_LVL_TL3:
686 /* Configure PIR, CIR */
687 reg[k] = NIX_AF_TL3X_PIR(schq);
688 regval[k] = (pir.rate && pir.burst) ?
689 (nix_tm_shaper2regval(&pir) | 1) :
693 reg[k] = NIX_AF_TL3X_CIR(schq);
694 regval[k] = (cir.rate && cir.burst) ?
695 (nix_tm_shaper2regval(&cir) | 1) :
699 /* Configure RED algo */
700 reg[k] = NIX_AF_TL3X_SHAPE(schq);
701 regval[k] = (adjust | (uint64_t)node->red_algo << 9 |
702 (uint64_t)node->pkt_mode);
706 case NIX_TXSCH_LVL_TL2:
707 /* Configure PIR, CIR */
708 reg[k] = NIX_AF_TL2X_PIR(schq);
709 regval[k] = (pir.rate && pir.burst) ?
710 (nix_tm_shaper2regval(&pir) | 1) :
714 reg[k] = NIX_AF_TL2X_CIR(schq);
715 regval[k] = (cir.rate && cir.burst) ?
716 (nix_tm_shaper2regval(&cir) | 1) :
720 /* Configure RED algo */
721 reg[k] = NIX_AF_TL2X_SHAPE(schq);
722 regval[k] = (adjust | (uint64_t)node->red_algo << 9 |
723 (uint64_t)node->pkt_mode << 24);
727 case NIX_TXSCH_LVL_TL1:
729 reg[k] = NIX_AF_TL1X_CIR(schq);
730 regval[k] = (cir.rate && cir.burst) ?
731 (nix_tm_shaper2regval(&cir) | 1) :
735 /* Configure length disable and adjust */
736 reg[k] = NIX_AF_TL1X_SHAPE(schq);
737 regval[k] = (adjust | (uint64_t)node->pkt_mode << 24);
746 nix_tm_sw_xoff_prep(struct nix_tm_node *node, bool enable,
747 volatile uint64_t *reg, volatile uint64_t *regval)
749 uint32_t hw_lvl = node->hw_lvl;
750 uint32_t schq = node->hw_id;
753 plt_tm_dbg("sw xoff config node %s(%u) lvl %u id %u, enable %u (%p)",
754 nix_tm_hwlvl2str(hw_lvl), schq, node->lvl, node->id, enable,
760 case NIX_TXSCH_LVL_MDQ:
761 reg[k] = NIX_AF_MDQX_SW_XOFF(schq);
764 case NIX_TXSCH_LVL_TL4:
765 reg[k] = NIX_AF_TL4X_SW_XOFF(schq);
768 case NIX_TXSCH_LVL_TL3:
769 reg[k] = NIX_AF_TL3X_SW_XOFF(schq);
772 case NIX_TXSCH_LVL_TL2:
773 reg[k] = NIX_AF_TL2X_SW_XOFF(schq);
776 case NIX_TXSCH_LVL_TL1:
777 reg[k] = NIX_AF_TL1X_SW_XOFF(schq);
787 /* Search for min rate in topology */
789 nix_tm_shaper_profile_rate_min(struct nix *nix)
791 struct nix_tm_shaper_profile *profile;
792 uint64_t rate_min = 1E9; /* 1 Gbps */
794 TAILQ_FOREACH(profile, &nix->shaper_profile_list, shaper) {
795 if (profile->peak.rate && profile->peak.rate < rate_min)
796 rate_min = profile->peak.rate;
798 if (profile->commit.rate && profile->commit.rate < rate_min)
799 rate_min = profile->commit.rate;
805 nix_tm_resource_avail(struct nix *nix, uint8_t hw_lvl, bool contig)
807 uint32_t pos = 0, start_pos = 0;
808 struct plt_bitmap *bmp;
812 bmp = contig ? nix->schq_contig_bmp[hw_lvl] : nix->schq_bmp[hw_lvl];
813 plt_bitmap_scan_init(bmp);
815 if (!plt_bitmap_scan(bmp, &pos, &slab))
821 count += __builtin_popcountll(slab);
822 if (!plt_bitmap_scan(bmp, &pos, &slab))
824 } while (pos != start_pos);
830 nix_tm_resource_estimate(struct nix *nix, uint16_t *schq_contig, uint16_t *schq,
831 enum roc_nix_tm_tree tree)
833 struct nix_tm_node_list *list;
834 uint8_t contig_cnt, hw_lvl;
835 struct nix_tm_node *parent;
836 uint16_t cnt = 0, avail;
838 list = nix_tm_node_list(nix, tree);
839 /* Walk through parents from TL1..TL4 */
840 for (hw_lvl = NIX_TXSCH_LVL_TL1; hw_lvl > 0; hw_lvl--) {
841 TAILQ_FOREACH(parent, list, node) {
842 if (hw_lvl != parent->hw_lvl)
845 /* Skip accounting for children whose
846 * parent does not indicate so.
848 if (!parent->child_realloc)
851 /* Count children needed */
852 schq[hw_lvl - 1] += parent->rr_num;
853 if (parent->max_prio != UINT32_MAX) {
854 contig_cnt = parent->max_prio + 1;
855 schq_contig[hw_lvl - 1] += contig_cnt;
856 /* When we have SP + DWRR at a parent,
857 * we will always have a spare schq at rr prio
858 * location in contiguous queues. Hence reduce
859 * discontiguous count by 1.
861 if (parent->max_prio > 0 && parent->rr_num)
862 schq[hw_lvl - 1] -= 1;
867 schq[nix->tm_root_lvl] = 1;
868 if (!nix_tm_have_tl1_access(nix))
869 schq[NIX_TXSCH_LVL_TL1] = 1;
871 /* Now check for existing resources */
872 for (hw_lvl = 0; hw_lvl < NIX_TXSCH_LVL_CNT; hw_lvl++) {
873 avail = nix_tm_resource_avail(nix, hw_lvl, false);
874 if (schq[hw_lvl] <= avail)
877 schq[hw_lvl] -= avail;
879 /* For contiguous queues, realloc everything */
880 avail = nix_tm_resource_avail(nix, hw_lvl, true);
881 if (schq_contig[hw_lvl] <= avail)
882 schq_contig[hw_lvl] = 0;
885 cnt += schq_contig[hw_lvl];
887 plt_tm_dbg("Estimate resources needed for %s: dis %u cont %u",
888 nix_tm_hwlvl2str(hw_lvl), schq[hw_lvl],
889 schq_contig[hw_lvl]);
896 roc_nix_tm_leaf_cnt(struct roc_nix *roc_nix)
898 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
899 struct nix_tm_node_list *list;
900 struct nix_tm_node *node;
901 uint16_t leaf_cnt = 0;
903 /* Count leafs only in user list */
904 list = nix_tm_node_list(nix, ROC_NIX_TM_USER);
905 TAILQ_FOREACH(node, list, node) {
906 if (node->id < nix->nb_tx_queues)
914 roc_nix_tm_node_lvl(struct roc_nix *roc_nix, uint32_t node_id)
916 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
917 struct nix_tm_node *node;
919 node = nix_tm_node_search(nix, node_id, ROC_NIX_TM_USER);
921 return NIX_ERR_TM_INVALID_NODE;
926 struct roc_nix_tm_node *
927 roc_nix_tm_node_get(struct roc_nix *roc_nix, uint32_t node_id)
929 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
930 struct nix_tm_node *node;
932 node = nix_tm_node_search(nix, node_id, ROC_NIX_TM_USER);
933 return (struct roc_nix_tm_node *)node;
936 struct roc_nix_tm_node *
937 roc_nix_tm_node_next(struct roc_nix *roc_nix, struct roc_nix_tm_node *__prev)
939 struct nix_tm_node *prev = (struct nix_tm_node *)__prev;
940 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
941 struct nix_tm_node_list *list;
943 list = nix_tm_node_list(nix, ROC_NIX_TM_USER);
945 /* HEAD of the list */
947 return (struct roc_nix_tm_node *)TAILQ_FIRST(list);
950 if (prev->tree != ROC_NIX_TM_USER)
953 return (struct roc_nix_tm_node *)TAILQ_NEXT(prev, node);
956 struct roc_nix_tm_shaper_profile *
957 roc_nix_tm_shaper_profile_get(struct roc_nix *roc_nix, uint32_t profile_id)
959 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
960 struct nix_tm_shaper_profile *profile;
962 profile = nix_tm_shaper_profile_search(nix, profile_id);
963 return (struct roc_nix_tm_shaper_profile *)profile;
966 struct roc_nix_tm_shaper_profile *
967 roc_nix_tm_shaper_profile_next(struct roc_nix *roc_nix,
968 struct roc_nix_tm_shaper_profile *__prev)
970 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
971 struct nix_tm_shaper_profile_list *list;
972 struct nix_tm_shaper_profile *prev;
974 prev = (struct nix_tm_shaper_profile *)__prev;
975 list = &nix->shaper_profile_list;
977 /* HEAD of the list */
979 return (struct roc_nix_tm_shaper_profile *)TAILQ_FIRST(list);
981 return (struct roc_nix_tm_shaper_profile *)TAILQ_NEXT(prev, shaper);
985 nix_tm_node_alloc(void)
987 struct nix_tm_node *node;
989 node = plt_zmalloc(sizeof(struct nix_tm_node), 0);
993 node->free_fn = plt_free;
998 nix_tm_node_free(struct nix_tm_node *node)
1000 if (!node || node->free_fn == NULL)
1003 (node->free_fn)(node);
1006 struct nix_tm_shaper_profile *
1007 nix_tm_shaper_profile_alloc(void)
1009 struct nix_tm_shaper_profile *profile;
1011 profile = plt_zmalloc(sizeof(struct nix_tm_shaper_profile), 0);
1015 profile->free_fn = plt_free;
1020 nix_tm_shaper_profile_free(struct nix_tm_shaper_profile *profile)
1022 if (!profile || !profile->free_fn)
1025 (profile->free_fn)(profile);
1029 roc_nix_tm_node_stats_get(struct roc_nix *roc_nix, uint32_t node_id, bool clear,
1030 struct roc_nix_tm_node_stats *n_stats)
1032 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1033 struct mbox *mbox = (&nix->dev)->mbox;
1034 struct nix_txschq_config *req, *rsp;
1035 struct nix_tm_node *node;
1039 node = nix_tm_node_search(nix, node_id, ROC_NIX_TM_USER);
1041 return NIX_ERR_TM_INVALID_NODE;
1043 if (node->hw_lvl != NIX_TXSCH_LVL_TL1)
1044 return NIX_ERR_OP_NOTSUP;
1047 /* Skip fetch if not requested */
1051 memset(n_stats, 0, sizeof(struct roc_nix_tm_node_stats));
1052 /* Check if node has HW resource */
1053 if (!(node->flags & NIX_TM_NODE_HWRES))
1056 req = mbox_alloc_msg_nix_txschq_cfg(mbox);
1058 req->lvl = NIX_TXSCH_LVL_TL1;
1061 req->reg[i++] = NIX_AF_TL1X_DROPPED_PACKETS(schq);
1062 req->reg[i++] = NIX_AF_TL1X_DROPPED_BYTES(schq);
1063 req->reg[i++] = NIX_AF_TL1X_GREEN_PACKETS(schq);
1064 req->reg[i++] = NIX_AF_TL1X_GREEN_BYTES(schq);
1065 req->reg[i++] = NIX_AF_TL1X_YELLOW_PACKETS(schq);
1066 req->reg[i++] = NIX_AF_TL1X_YELLOW_BYTES(schq);
1067 req->reg[i++] = NIX_AF_TL1X_RED_PACKETS(schq);
1068 req->reg[i++] = NIX_AF_TL1X_RED_BYTES(schq);
1071 rc = mbox_process_msg(mbox, (void **)&rsp);
1076 n_stats->stats[ROC_NIX_TM_NODE_PKTS_DROPPED] = rsp->regval[0];
1077 n_stats->stats[ROC_NIX_TM_NODE_BYTES_DROPPED] = rsp->regval[1];
1078 n_stats->stats[ROC_NIX_TM_NODE_GREEN_PKTS] = rsp->regval[2];
1079 n_stats->stats[ROC_NIX_TM_NODE_GREEN_BYTES] = rsp->regval[3];
1080 n_stats->stats[ROC_NIX_TM_NODE_YELLOW_PKTS] = rsp->regval[4];
1081 n_stats->stats[ROC_NIX_TM_NODE_YELLOW_BYTES] = rsp->regval[5];
1082 n_stats->stats[ROC_NIX_TM_NODE_RED_PKTS] = rsp->regval[6];
1083 n_stats->stats[ROC_NIX_TM_NODE_RED_BYTES] = rsp->regval[7];
1089 /* Clear all the stats */
1090 req = mbox_alloc_msg_nix_txschq_cfg(mbox);
1091 req->lvl = NIX_TXSCH_LVL_TL1;
1093 req->reg[i++] = NIX_AF_TL1X_DROPPED_PACKETS(schq);
1094 req->reg[i++] = NIX_AF_TL1X_DROPPED_BYTES(schq);
1095 req->reg[i++] = NIX_AF_TL1X_GREEN_PACKETS(schq);
1096 req->reg[i++] = NIX_AF_TL1X_GREEN_BYTES(schq);
1097 req->reg[i++] = NIX_AF_TL1X_YELLOW_PACKETS(schq);
1098 req->reg[i++] = NIX_AF_TL1X_YELLOW_BYTES(schq);
1099 req->reg[i++] = NIX_AF_TL1X_RED_PACKETS(schq);
1100 req->reg[i++] = NIX_AF_TL1X_RED_BYTES(schq);
1103 return mbox_process_msg(mbox, (void **)&rsp);