1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #include <rte_malloc.h>
7 #include "otx2_ethdev.h"
10 /* Use last LVL_CNT nodes as default nodes */
11 #define NIX_DEFAULT_NODE_ID_START (RTE_TM_NODE_ID_NULL - NIX_TXSCH_LVL_CNT)
13 enum otx2_tm_node_level {
24 uint64_t shaper2regval(struct shaper_params *shaper)
26 return (shaper->burst_exponent << 37) | (shaper->burst_mantissa << 29) |
27 (shaper->div_exp << 13) | (shaper->exponent << 9) |
28 (shaper->mantissa << 1);
32 otx2_nix_get_link(struct otx2_eth_dev *dev)
34 int link = 13 /* SDP */;
38 lmac_chan = dev->tx_chan_base;
41 if (lmac_chan >= 0x800) {
42 map = lmac_chan & 0x7FF;
43 link = 4 * ((map >> 8) & 0xF) + ((map >> 4) & 0xF);
44 } else if (lmac_chan < 0x700) {
53 nix_get_relchan(struct otx2_eth_dev *dev)
55 return dev->tx_chan_base & 0xff;
59 nix_tm_have_tl1_access(struct otx2_eth_dev *dev)
61 bool is_lbk = otx2_dev_is_lbk(dev);
62 return otx2_dev_is_pf(dev) && !otx2_dev_is_Ax(dev) && !is_lbk;
66 nix_tm_is_leaf(struct otx2_eth_dev *dev, int lvl)
68 if (nix_tm_have_tl1_access(dev))
69 return (lvl == OTX2_TM_LVL_QUEUE);
71 return (lvl == OTX2_TM_LVL_SCH4);
75 find_prio_anchor(struct otx2_eth_dev *dev, uint32_t node_id)
77 struct otx2_nix_tm_node *child_node;
79 TAILQ_FOREACH(child_node, &dev->node_list, node) {
80 if (!child_node->parent)
82 if (!(child_node->parent->id == node_id))
84 if (child_node->priority == child_node->parent->rr_prio)
86 return child_node->hw_id - child_node->priority;
92 static struct otx2_nix_tm_shaper_profile *
93 nix_tm_shaper_profile_search(struct otx2_eth_dev *dev, uint32_t shaper_id)
95 struct otx2_nix_tm_shaper_profile *tm_shaper_profile;
97 TAILQ_FOREACH(tm_shaper_profile, &dev->shaper_profile_list, shaper) {
98 if (tm_shaper_profile->shaper_profile_id == shaper_id)
99 return tm_shaper_profile;
104 static inline uint64_t
105 shaper_rate_to_nix(uint64_t value, uint64_t *exponent_p,
106 uint64_t *mantissa_p, uint64_t *div_exp_p)
108 uint64_t div_exp, exponent, mantissa;
110 /* Boundary checks */
111 if (value < MIN_SHAPER_RATE ||
112 value > MAX_SHAPER_RATE)
115 if (value <= SHAPER_RATE(0, 0, 0)) {
116 /* Calculate rate div_exp and mantissa using
117 * the following formula:
119 * value = (2E6 * (256 + mantissa)
120 * / ((1 << div_exp) * 256))
124 mantissa = MAX_RATE_MANTISSA;
126 while (value < (NIX_SHAPER_RATE_CONST / (1 << div_exp)))
130 ((NIX_SHAPER_RATE_CONST * (256 + mantissa)) /
131 ((1 << div_exp) * 256)))
134 /* Calculate rate exponent and mantissa using
135 * the following formula:
137 * value = (2E6 * ((256 + mantissa) << exponent)) / 256
141 exponent = MAX_RATE_EXPONENT;
142 mantissa = MAX_RATE_MANTISSA;
144 while (value < (NIX_SHAPER_RATE_CONST * (1 << exponent)))
147 while (value < ((NIX_SHAPER_RATE_CONST *
148 ((256 + mantissa) << exponent)) / 256))
152 if (div_exp > MAX_RATE_DIV_EXP ||
153 exponent > MAX_RATE_EXPONENT || mantissa > MAX_RATE_MANTISSA)
157 *div_exp_p = div_exp;
159 *exponent_p = exponent;
161 *mantissa_p = mantissa;
163 /* Calculate real rate value */
164 return SHAPER_RATE(exponent, mantissa, div_exp);
167 static inline uint64_t
168 shaper_burst_to_nix(uint64_t value, uint64_t *exponent_p,
169 uint64_t *mantissa_p)
171 uint64_t exponent, mantissa;
173 if (value < MIN_SHAPER_BURST || value > MAX_SHAPER_BURST)
176 /* Calculate burst exponent and mantissa using
177 * the following formula:
179 * value = (((256 + mantissa) << (exponent + 1)
183 exponent = MAX_BURST_EXPONENT;
184 mantissa = MAX_BURST_MANTISSA;
186 while (value < (1ull << (exponent + 1)))
189 while (value < ((256 + mantissa) << (exponent + 1)) / 256)
192 if (exponent > MAX_BURST_EXPONENT || mantissa > MAX_BURST_MANTISSA)
196 *exponent_p = exponent;
198 *mantissa_p = mantissa;
200 return SHAPER_BURST(exponent, mantissa);
204 shaper_config_to_nix(struct otx2_nix_tm_shaper_profile *profile,
205 struct shaper_params *cir,
206 struct shaper_params *pir)
208 struct rte_tm_shaper_params *param = &profile->params;
213 /* Calculate CIR exponent and mantissa */
214 if (param->committed.rate)
215 cir->rate = shaper_rate_to_nix(param->committed.rate,
220 /* Calculate PIR exponent and mantissa */
221 if (param->peak.rate)
222 pir->rate = shaper_rate_to_nix(param->peak.rate,
227 /* Calculate CIR burst exponent and mantissa */
228 if (param->committed.size)
229 cir->burst = shaper_burst_to_nix(param->committed.size,
230 &cir->burst_exponent,
231 &cir->burst_mantissa);
233 /* Calculate PIR burst exponent and mantissa */
234 if (param->peak.size)
235 pir->burst = shaper_burst_to_nix(param->peak.size,
236 &pir->burst_exponent,
237 &pir->burst_mantissa);
241 shaper_default_red_algo(struct otx2_eth_dev *dev,
242 struct otx2_nix_tm_node *tm_node,
243 struct otx2_nix_tm_shaper_profile *profile)
245 struct shaper_params cir, pir;
247 /* C0 doesn't support STALL when both PIR & CIR are enabled */
248 if (profile && otx2_dev_is_96xx_Cx(dev)) {
249 memset(&cir, 0, sizeof(cir));
250 memset(&pir, 0, sizeof(pir));
251 shaper_config_to_nix(profile, &cir, &pir);
253 if (pir.rate && cir.rate) {
254 tm_node->red_algo = NIX_REDALG_DISCARD;
255 tm_node->flags |= NIX_TM_NODE_RED_DISCARD;
260 tm_node->red_algo = NIX_REDALG_STD;
261 tm_node->flags &= ~NIX_TM_NODE_RED_DISCARD;
265 populate_tm_tl1_default(struct otx2_eth_dev *dev, uint32_t schq)
267 struct otx2_mbox *mbox = dev->mbox;
268 struct nix_txschq_config *req;
271 * Default config for TL1.
272 * For VF this is always ignored.
275 req = otx2_mbox_alloc_msg_nix_txschq_cfg(mbox);
276 req->lvl = NIX_TXSCH_LVL_TL1;
278 /* Set DWRR quantum */
279 req->reg[0] = NIX_AF_TL1X_SCHEDULE(schq);
280 req->regval[0] = TXSCH_TL1_DFLT_RR_QTM;
283 req->reg[1] = NIX_AF_TL1X_TOPOLOGY(schq);
284 req->regval[1] = (TXSCH_TL1_DFLT_RR_PRIO << 1);
287 req->reg[2] = NIX_AF_TL1X_CIR(schq);
291 return otx2_mbox_process(mbox);
295 prepare_tm_sched_reg(struct otx2_eth_dev *dev,
296 struct otx2_nix_tm_node *tm_node,
297 volatile uint64_t *reg, volatile uint64_t *regval)
299 uint64_t strict_prio = tm_node->priority;
300 uint32_t hw_lvl = tm_node->hw_lvl;
301 uint32_t schq = tm_node->hw_id;
305 rr_quantum = NIX_TM_WEIGHT_TO_RR_QUANTUM(tm_node->weight);
307 /* For children to root, strict prio is default if either
308 * device root is TL2 or TL1 Static Priority is disabled.
310 if (hw_lvl == NIX_TXSCH_LVL_TL2 &&
311 (dev->otx2_tm_root_lvl == NIX_TXSCH_LVL_TL2 ||
312 dev->tm_flags & NIX_TM_TL1_NO_SP))
313 strict_prio = TXSCH_TL1_DFLT_RR_PRIO;
315 otx2_tm_dbg("Schedule config node %s(%u) lvl %u id %u, "
316 "prio 0x%" PRIx64 ", rr_quantum 0x%" PRIx64 " (%p)",
317 nix_hwlvl2str(tm_node->hw_lvl), schq, tm_node->lvl,
318 tm_node->id, strict_prio, rr_quantum, tm_node);
321 case NIX_TXSCH_LVL_SMQ:
322 reg[k] = NIX_AF_MDQX_SCHEDULE(schq);
323 regval[k] = (strict_prio << 24) | rr_quantum;
327 case NIX_TXSCH_LVL_TL4:
328 reg[k] = NIX_AF_TL4X_SCHEDULE(schq);
329 regval[k] = (strict_prio << 24) | rr_quantum;
333 case NIX_TXSCH_LVL_TL3:
334 reg[k] = NIX_AF_TL3X_SCHEDULE(schq);
335 regval[k] = (strict_prio << 24) | rr_quantum;
339 case NIX_TXSCH_LVL_TL2:
340 reg[k] = NIX_AF_TL2X_SCHEDULE(schq);
341 regval[k] = (strict_prio << 24) | rr_quantum;
345 case NIX_TXSCH_LVL_TL1:
346 reg[k] = NIX_AF_TL1X_SCHEDULE(schq);
347 regval[k] = rr_quantum;
357 prepare_tm_shaper_reg(struct otx2_nix_tm_node *tm_node,
358 struct otx2_nix_tm_shaper_profile *profile,
359 volatile uint64_t *reg, volatile uint64_t *regval)
361 struct shaper_params cir, pir;
362 uint32_t schq = tm_node->hw_id;
365 memset(&cir, 0, sizeof(cir));
366 memset(&pir, 0, sizeof(pir));
367 shaper_config_to_nix(profile, &cir, &pir);
369 otx2_tm_dbg("Shaper config node %s(%u) lvl %u id %u, "
370 "pir %" PRIu64 "(%" PRIu64 "B),"
371 " cir %" PRIu64 "(%" PRIu64 "B) (%p)",
372 nix_hwlvl2str(tm_node->hw_lvl), schq, tm_node->lvl,
373 tm_node->id, pir.rate, pir.burst,
374 cir.rate, cir.burst, tm_node);
376 switch (tm_node->hw_lvl) {
377 case NIX_TXSCH_LVL_SMQ:
378 /* Configure PIR, CIR */
379 reg[k] = NIX_AF_MDQX_PIR(schq);
380 regval[k] = (pir.rate && pir.burst) ?
381 (shaper2regval(&pir) | 1) : 0;
384 reg[k] = NIX_AF_MDQX_CIR(schq);
385 regval[k] = (cir.rate && cir.burst) ?
386 (shaper2regval(&cir) | 1) : 0;
389 /* Configure RED ALG */
390 reg[k] = NIX_AF_MDQX_SHAPE(schq);
391 regval[k] = ((uint64_t)tm_node->red_algo << 9);
394 case NIX_TXSCH_LVL_TL4:
395 /* Configure PIR, CIR */
396 reg[k] = NIX_AF_TL4X_PIR(schq);
397 regval[k] = (pir.rate && pir.burst) ?
398 (shaper2regval(&pir) | 1) : 0;
401 reg[k] = NIX_AF_TL4X_CIR(schq);
402 regval[k] = (cir.rate && cir.burst) ?
403 (shaper2regval(&cir) | 1) : 0;
406 /* Configure RED algo */
407 reg[k] = NIX_AF_TL4X_SHAPE(schq);
408 regval[k] = ((uint64_t)tm_node->red_algo << 9);
411 case NIX_TXSCH_LVL_TL3:
412 /* Configure PIR, CIR */
413 reg[k] = NIX_AF_TL3X_PIR(schq);
414 regval[k] = (pir.rate && pir.burst) ?
415 (shaper2regval(&pir) | 1) : 0;
418 reg[k] = NIX_AF_TL3X_CIR(schq);
419 regval[k] = (cir.rate && cir.burst) ?
420 (shaper2regval(&cir) | 1) : 0;
423 /* Configure RED algo */
424 reg[k] = NIX_AF_TL3X_SHAPE(schq);
425 regval[k] = ((uint64_t)tm_node->red_algo << 9);
429 case NIX_TXSCH_LVL_TL2:
430 /* Configure PIR, CIR */
431 reg[k] = NIX_AF_TL2X_PIR(schq);
432 regval[k] = (pir.rate && pir.burst) ?
433 (shaper2regval(&pir) | 1) : 0;
436 reg[k] = NIX_AF_TL2X_CIR(schq);
437 regval[k] = (cir.rate && cir.burst) ?
438 (shaper2regval(&cir) | 1) : 0;
441 /* Configure RED algo */
442 reg[k] = NIX_AF_TL2X_SHAPE(schq);
443 regval[k] = ((uint64_t)tm_node->red_algo << 9);
447 case NIX_TXSCH_LVL_TL1:
449 reg[k] = NIX_AF_TL1X_CIR(schq);
450 regval[k] = (cir.rate && cir.burst) ?
451 (shaper2regval(&cir) | 1) : 0;
460 prepare_tm_sw_xoff(struct otx2_nix_tm_node *tm_node, bool enable,
461 volatile uint64_t *reg, volatile uint64_t *regval)
463 uint32_t hw_lvl = tm_node->hw_lvl;
464 uint32_t schq = tm_node->hw_id;
467 otx2_tm_dbg("sw xoff config node %s(%u) lvl %u id %u, enable %u (%p)",
468 nix_hwlvl2str(hw_lvl), schq, tm_node->lvl,
469 tm_node->id, enable, tm_node);
474 case NIX_TXSCH_LVL_MDQ:
475 reg[k] = NIX_AF_MDQX_SW_XOFF(schq);
478 case NIX_TXSCH_LVL_TL4:
479 reg[k] = NIX_AF_TL4X_SW_XOFF(schq);
482 case NIX_TXSCH_LVL_TL3:
483 reg[k] = NIX_AF_TL3X_SW_XOFF(schq);
486 case NIX_TXSCH_LVL_TL2:
487 reg[k] = NIX_AF_TL2X_SW_XOFF(schq);
490 case NIX_TXSCH_LVL_TL1:
491 reg[k] = NIX_AF_TL1X_SW_XOFF(schq);
502 populate_tm_reg(struct otx2_eth_dev *dev,
503 struct otx2_nix_tm_node *tm_node)
505 struct otx2_nix_tm_shaper_profile *profile;
506 uint64_t regval_mask[MAX_REGS_PER_MBOX_MSG];
507 uint64_t regval[MAX_REGS_PER_MBOX_MSG];
508 uint64_t reg[MAX_REGS_PER_MBOX_MSG];
509 struct otx2_mbox *mbox = dev->mbox;
510 uint64_t parent = 0, child = 0;
511 uint32_t hw_lvl, rr_prio, schq;
512 struct nix_txschq_config *req;
516 memset(regval_mask, 0, sizeof(regval_mask));
517 profile = nix_tm_shaper_profile_search(dev,
518 tm_node->params.shaper_profile_id);
519 rr_prio = tm_node->rr_prio;
520 hw_lvl = tm_node->hw_lvl;
521 schq = tm_node->hw_id;
523 /* Root node will not have a parent node */
524 if (hw_lvl == dev->otx2_tm_root_lvl)
525 parent = tm_node->parent_hw_id;
527 parent = tm_node->parent->hw_id;
529 /* Do we need this trigger to configure TL1 */
530 if (dev->otx2_tm_root_lvl == NIX_TXSCH_LVL_TL2 &&
531 hw_lvl == dev->otx2_tm_root_lvl) {
532 rc = populate_tm_tl1_default(dev, parent);
537 if (hw_lvl != NIX_TXSCH_LVL_SMQ)
538 child = find_prio_anchor(dev, tm_node->id);
540 /* Override default rr_prio when TL1
541 * Static Priority is disabled
543 if (hw_lvl == NIX_TXSCH_LVL_TL1 &&
544 dev->tm_flags & NIX_TM_TL1_NO_SP) {
545 rr_prio = TXSCH_TL1_DFLT_RR_PRIO;
549 otx2_tm_dbg("Topology config node %s(%u)->%s(%"PRIu64") lvl %u, id %u"
550 " prio_anchor %"PRIu64" rr_prio %u (%p)",
551 nix_hwlvl2str(hw_lvl), schq, nix_hwlvl2str(hw_lvl + 1),
552 parent, tm_node->lvl, tm_node->id, child, rr_prio, tm_node);
554 /* Prepare Topology and Link config */
556 case NIX_TXSCH_LVL_SMQ:
558 /* Set xoff which will be cleared later */
559 reg[k] = NIX_AF_SMQX_CFG(schq);
560 regval[k] = BIT_ULL(50);
561 regval_mask[k] = ~BIT_ULL(50);
564 /* Parent and schedule conf */
565 reg[k] = NIX_AF_MDQX_PARENT(schq);
566 regval[k] = parent << 16;
570 case NIX_TXSCH_LVL_TL4:
571 /* Parent and schedule conf */
572 reg[k] = NIX_AF_TL4X_PARENT(schq);
573 regval[k] = parent << 16;
576 reg[k] = NIX_AF_TL4X_TOPOLOGY(schq);
577 regval[k] = (child << 32) | (rr_prio << 1);
580 /* Configure TL4 to send to SDP channel instead of CGX/LBK */
581 if (otx2_dev_is_sdp(dev)) {
582 reg[k] = NIX_AF_TL4X_SDP_LINK_CFG(schq);
583 regval[k] = BIT_ULL(12);
587 case NIX_TXSCH_LVL_TL3:
588 /* Parent and schedule conf */
589 reg[k] = NIX_AF_TL3X_PARENT(schq);
590 regval[k] = parent << 16;
593 reg[k] = NIX_AF_TL3X_TOPOLOGY(schq);
594 regval[k] = (child << 32) | (rr_prio << 1);
597 /* Link configuration */
598 if (!otx2_dev_is_sdp(dev) &&
599 dev->link_cfg_lvl == NIX_TXSCH_LVL_TL3) {
600 reg[k] = NIX_AF_TL3_TL2X_LINKX_CFG(schq,
601 otx2_nix_get_link(dev));
602 regval[k] = BIT_ULL(12) | nix_get_relchan(dev);
607 case NIX_TXSCH_LVL_TL2:
608 /* Parent and schedule conf */
609 reg[k] = NIX_AF_TL2X_PARENT(schq);
610 regval[k] = parent << 16;
613 reg[k] = NIX_AF_TL2X_TOPOLOGY(schq);
614 regval[k] = (child << 32) | (rr_prio << 1);
617 /* Link configuration */
618 if (!otx2_dev_is_sdp(dev) &&
619 dev->link_cfg_lvl == NIX_TXSCH_LVL_TL2) {
620 reg[k] = NIX_AF_TL3_TL2X_LINKX_CFG(schq,
621 otx2_nix_get_link(dev));
622 regval[k] = BIT_ULL(12) | nix_get_relchan(dev);
627 case NIX_TXSCH_LVL_TL1:
628 reg[k] = NIX_AF_TL1X_TOPOLOGY(schq);
629 regval[k] = (child << 32) | (rr_prio << 1 /*RR_PRIO*/);
635 /* Prepare schedule config */
636 k += prepare_tm_sched_reg(dev, tm_node, ®[k], ®val[k]);
638 /* Prepare shaping config */
639 k += prepare_tm_shaper_reg(tm_node, profile, ®[k], ®val[k]);
644 /* Copy and send config mbox */
645 req = otx2_mbox_alloc_msg_nix_txschq_cfg(mbox);
649 otx2_mbox_memcpy(req->reg, reg, sizeof(uint64_t) * k);
650 otx2_mbox_memcpy(req->regval, regval, sizeof(uint64_t) * k);
651 otx2_mbox_memcpy(req->regval_mask, regval_mask, sizeof(uint64_t) * k);
653 rc = otx2_mbox_process(mbox);
659 otx2_err("Txschq cfg request failed for node %p, rc=%d", tm_node, rc);
665 nix_tm_txsch_reg_config(struct otx2_eth_dev *dev)
667 struct otx2_nix_tm_node *tm_node;
671 for (hw_lvl = 0; hw_lvl <= dev->otx2_tm_root_lvl; hw_lvl++) {
672 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
673 if (tm_node->hw_lvl == hw_lvl &&
674 tm_node->hw_lvl != NIX_TXSCH_LVL_CNT) {
675 rc = populate_tm_reg(dev, tm_node);
685 static struct otx2_nix_tm_node *
686 nix_tm_node_search(struct otx2_eth_dev *dev,
687 uint32_t node_id, bool user)
689 struct otx2_nix_tm_node *tm_node;
691 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
692 if (tm_node->id == node_id &&
693 (user == !!(tm_node->flags & NIX_TM_NODE_USER)))
700 check_rr(struct otx2_eth_dev *dev, uint32_t priority, uint32_t parent_id)
702 struct otx2_nix_tm_node *tm_node;
705 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
706 if (!tm_node->parent)
709 if (!(tm_node->parent->id == parent_id))
712 if (tm_node->priority == priority)
719 nix_tm_update_parent_info(struct otx2_eth_dev *dev)
721 struct otx2_nix_tm_node *tm_node_child;
722 struct otx2_nix_tm_node *tm_node;
723 struct otx2_nix_tm_node *parent;
727 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
728 if (!tm_node->parent)
730 /* Count group of children of same priority i.e are RR */
731 parent = tm_node->parent;
732 priority = tm_node->priority;
733 rr_num = check_rr(dev, priority, parent->id);
735 /* Assuming that multiple RR groups are
736 * not configured based on capability.
739 parent->rr_prio = priority;
740 parent->rr_num = rr_num;
743 /* Find out static priority children that are not in RR */
744 TAILQ_FOREACH(tm_node_child, &dev->node_list, node) {
745 if (!tm_node_child->parent)
747 if (parent->id != tm_node_child->parent->id)
749 if (parent->max_prio == UINT32_MAX &&
750 tm_node_child->priority != parent->rr_prio)
751 parent->max_prio = 0;
753 if (parent->max_prio < tm_node_child->priority &&
754 parent->rr_prio != tm_node_child->priority)
755 parent->max_prio = tm_node_child->priority;
763 nix_tm_node_add_to_list(struct otx2_eth_dev *dev, uint32_t node_id,
764 uint32_t parent_node_id, uint32_t priority,
765 uint32_t weight, uint16_t hw_lvl,
766 uint16_t lvl, bool user,
767 struct rte_tm_node_params *params)
769 struct otx2_nix_tm_shaper_profile *profile;
770 struct otx2_nix_tm_node *tm_node, *parent_node;
773 profile_id = params->shaper_profile_id;
774 profile = nix_tm_shaper_profile_search(dev, profile_id);
776 parent_node = nix_tm_node_search(dev, parent_node_id, user);
778 tm_node = rte_zmalloc("otx2_nix_tm_node",
779 sizeof(struct otx2_nix_tm_node), 0);
784 tm_node->hw_lvl = hw_lvl;
786 /* Maintain minimum weight */
790 tm_node->id = node_id;
791 tm_node->priority = priority;
792 tm_node->weight = weight;
793 tm_node->rr_prio = 0xf;
794 tm_node->max_prio = UINT32_MAX;
795 tm_node->hw_id = UINT32_MAX;
798 tm_node->flags = NIX_TM_NODE_USER;
799 rte_memcpy(&tm_node->params, params, sizeof(struct rte_tm_node_params));
802 profile->reference_count++;
804 tm_node->parent = parent_node;
805 tm_node->parent_hw_id = UINT32_MAX;
806 shaper_default_red_algo(dev, tm_node, profile);
808 TAILQ_INSERT_TAIL(&dev->node_list, tm_node, node);
814 nix_tm_clear_shaper_profiles(struct otx2_eth_dev *dev)
816 struct otx2_nix_tm_shaper_profile *shaper_profile;
818 while ((shaper_profile = TAILQ_FIRST(&dev->shaper_profile_list))) {
819 if (shaper_profile->reference_count)
820 otx2_tm_dbg("Shaper profile %u has non zero references",
821 shaper_profile->shaper_profile_id);
822 TAILQ_REMOVE(&dev->shaper_profile_list, shaper_profile, shaper);
823 rte_free(shaper_profile);
830 nix_clear_path_xoff(struct otx2_eth_dev *dev,
831 struct otx2_nix_tm_node *tm_node)
833 struct nix_txschq_config *req;
834 struct otx2_nix_tm_node *p;
837 /* Manipulating SW_XOFF not supported on Ax */
838 if (otx2_dev_is_Ax(dev))
841 /* Enable nodes in path for flush to succeed */
842 if (!nix_tm_is_leaf(dev, tm_node->lvl))
847 if (!(p->flags & NIX_TM_NODE_ENABLED) &&
848 (p->flags & NIX_TM_NODE_HWRES)) {
849 req = otx2_mbox_alloc_msg_nix_txschq_cfg(dev->mbox);
850 req->lvl = p->hw_lvl;
851 req->num_regs = prepare_tm_sw_xoff(p, false, req->reg,
853 rc = otx2_mbox_process(dev->mbox);
857 p->flags |= NIX_TM_NODE_ENABLED;
866 nix_smq_xoff(struct otx2_eth_dev *dev,
867 struct otx2_nix_tm_node *tm_node,
870 struct otx2_mbox *mbox = dev->mbox;
871 struct nix_txschq_config *req;
875 smq = tm_node->hw_id;
876 otx2_tm_dbg("Setting SMQ %u XOFF/FLUSH to %s", smq,
877 enable ? "enable" : "disable");
879 rc = nix_clear_path_xoff(dev, tm_node);
883 req = otx2_mbox_alloc_msg_nix_txschq_cfg(mbox);
884 req->lvl = NIX_TXSCH_LVL_SMQ;
887 req->reg[0] = NIX_AF_SMQX_CFG(smq);
888 req->regval[0] = enable ? (BIT_ULL(50) | BIT_ULL(49)) : 0;
889 req->regval_mask[0] = enable ?
890 ~(BIT_ULL(50) | BIT_ULL(49)) : ~BIT_ULL(50);
892 return otx2_mbox_process(mbox);
896 otx2_nix_sq_sqb_aura_fc(void *__txq, bool enable)
898 struct otx2_eth_txq *txq = __txq;
899 struct npa_aq_enq_req *req;
900 struct npa_aq_enq_rsp *rsp;
901 struct otx2_npa_lf *lf;
902 struct otx2_mbox *mbox;
903 uint64_t aura_handle;
906 otx2_tm_dbg("Setting SQ %u SQB aura FC to %s", txq->sq,
907 enable ? "enable" : "disable");
909 lf = otx2_npa_lf_obj_get();
913 /* Set/clear sqb aura fc_ena */
914 aura_handle = txq->sqb_pool->pool_id;
915 req = otx2_mbox_alloc_msg_npa_aq_enq(mbox);
917 req->aura_id = npa_lf_aura_handle_to_aura(aura_handle);
918 req->ctype = NPA_AQ_CTYPE_AURA;
919 req->op = NPA_AQ_INSTOP_WRITE;
920 /* Below is not needed for aura writes but AF driver needs it */
921 /* AF will translate to associated poolctx */
922 req->aura.pool_addr = req->aura_id;
924 req->aura.fc_ena = enable;
925 req->aura_mask.fc_ena = 1;
927 rc = otx2_mbox_process(mbox);
931 /* Read back npa aura ctx */
932 req = otx2_mbox_alloc_msg_npa_aq_enq(mbox);
934 req->aura_id = npa_lf_aura_handle_to_aura(aura_handle);
935 req->ctype = NPA_AQ_CTYPE_AURA;
936 req->op = NPA_AQ_INSTOP_READ;
938 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
942 /* Init when enabled as there might be no triggers */
944 *(volatile uint64_t *)txq->fc_mem = rsp->aura.count;
946 *(volatile uint64_t *)txq->fc_mem = txq->nb_sqb_bufs;
947 /* Sync write barrier */
954 nix_txq_flush_sq_spin(struct otx2_eth_txq *txq)
956 uint16_t sqb_cnt, head_off, tail_off;
957 struct otx2_eth_dev *dev = txq->dev;
958 uint64_t wdata, val, prev;
959 uint16_t sq = txq->sq;
961 uint64_t timeout;/* 10's of usec */
963 /* Wait for enough time based on shaper min rate */
964 timeout = (txq->qconf.nb_desc * NIX_MAX_HW_FRS * 8 * 1E5);
965 timeout = timeout / dev->tm_rate_min;
969 wdata = ((uint64_t)sq << 32);
970 regaddr = (int64_t *)(dev->base + NIX_LF_SQ_OP_STATUS);
971 val = otx2_atomic64_add_nosync(wdata, regaddr);
973 /* Spin multiple iterations as "txq->fc_cache_pkts" can still
974 * have space to send pkts even though fc_mem is disabled
980 val = otx2_atomic64_add_nosync(wdata, regaddr);
981 /* Continue on error */
982 if (val & BIT_ULL(63))
988 sqb_cnt = val & 0xFFFF;
989 head_off = (val >> 20) & 0x3F;
990 tail_off = (val >> 28) & 0x3F;
992 /* SQ reached quiescent state */
993 if (sqb_cnt <= 1 && head_off == tail_off &&
994 (*txq->fc_mem == txq->nb_sqb_bufs)) {
1006 otx2_nix_tm_dump(dev);
1010 /* Flush and disable tx queue and its parent SMQ */
1011 int otx2_nix_sq_flush_pre(void *_txq, bool dev_started)
1013 struct otx2_nix_tm_node *tm_node, *sibling;
1014 struct otx2_eth_txq *txq;
1015 struct otx2_eth_dev *dev;
1024 user = !!(dev->tm_flags & NIX_TM_COMMITTED);
1026 /* Find the node for this SQ */
1027 tm_node = nix_tm_node_search(dev, sq, user);
1028 if (!tm_node || !(tm_node->flags & NIX_TM_NODE_ENABLED)) {
1029 otx2_err("Invalid node/state for sq %u", sq);
1033 /* Enable CGX RXTX to drain pkts */
1035 /* Though it enables both RX MCAM Entries and CGX Link
1036 * we assume all the rx queues are stopped way back.
1038 otx2_mbox_alloc_msg_nix_lf_start_rx(dev->mbox);
1039 rc = otx2_mbox_process(dev->mbox);
1041 otx2_err("cgx start failed, rc=%d", rc);
1046 /* Disable smq xoff for case it was enabled earlier */
1047 rc = nix_smq_xoff(dev, tm_node->parent, false);
1049 otx2_err("Failed to enable smq %u, rc=%d",
1050 tm_node->parent->hw_id, rc);
1054 /* As per HRM, to disable an SQ, all other SQ's
1055 * that feed to same SMQ must be paused before SMQ flush.
1057 TAILQ_FOREACH(sibling, &dev->node_list, node) {
1058 if (sibling->parent != tm_node->parent)
1060 if (!(sibling->flags & NIX_TM_NODE_ENABLED))
1064 txq = dev->eth_dev->data->tx_queues[sq];
1068 rc = otx2_nix_sq_sqb_aura_fc(txq, false);
1070 otx2_err("Failed to disable sqb aura fc, rc=%d", rc);
1074 /* Wait for sq entries to be flushed */
1075 rc = nix_txq_flush_sq_spin(txq);
1077 otx2_err("Failed to drain sq %u, rc=%d\n", txq->sq, rc);
1082 tm_node->flags &= ~NIX_TM_NODE_ENABLED;
1084 /* Disable and flush */
1085 rc = nix_smq_xoff(dev, tm_node->parent, true);
1087 otx2_err("Failed to disable smq %u, rc=%d",
1088 tm_node->parent->hw_id, rc);
1092 /* Restore cgx state */
1094 otx2_mbox_alloc_msg_nix_lf_stop_rx(dev->mbox);
1095 rc |= otx2_mbox_process(dev->mbox);
1101 int otx2_nix_sq_flush_post(void *_txq)
1103 struct otx2_nix_tm_node *tm_node, *sibling;
1104 struct otx2_eth_txq *txq = _txq;
1105 struct otx2_eth_txq *s_txq;
1106 struct otx2_eth_dev *dev;
1114 user = !!(dev->tm_flags & NIX_TM_COMMITTED);
1116 /* Find the node for this SQ */
1117 tm_node = nix_tm_node_search(dev, sq, user);
1119 otx2_err("Invalid node for sq %u", sq);
1123 /* Enable all the siblings back */
1124 TAILQ_FOREACH(sibling, &dev->node_list, node) {
1125 if (sibling->parent != tm_node->parent)
1128 if (sibling->id == sq)
1131 if (!(sibling->flags & NIX_TM_NODE_ENABLED))
1135 s_txq = dev->eth_dev->data->tx_queues[s_sq];
1140 /* Enable back if any SQ is still present */
1141 rc = nix_smq_xoff(dev, tm_node->parent, false);
1143 otx2_err("Failed to enable smq %u, rc=%d",
1144 tm_node->parent->hw_id, rc);
1150 rc = otx2_nix_sq_sqb_aura_fc(s_txq, true);
1152 otx2_err("Failed to enable sqb aura fc, rc=%d", rc);
1161 nix_sq_sched_data(struct otx2_eth_dev *dev,
1162 struct otx2_nix_tm_node *tm_node,
1163 bool rr_quantum_only)
1165 struct rte_eth_dev *eth_dev = dev->eth_dev;
1166 struct otx2_mbox *mbox = dev->mbox;
1167 uint16_t sq = tm_node->id, smq;
1168 struct nix_aq_enq_req *req;
1169 uint64_t rr_quantum;
1172 smq = tm_node->parent->hw_id;
1173 rr_quantum = NIX_TM_WEIGHT_TO_RR_QUANTUM(tm_node->weight);
1175 if (rr_quantum_only)
1176 otx2_tm_dbg("Update sq(%u) rr_quantum 0x%"PRIx64, sq, rr_quantum);
1178 otx2_tm_dbg("Enabling sq(%u)->smq(%u), rr_quantum 0x%"PRIx64,
1179 sq, smq, rr_quantum);
1181 if (sq > eth_dev->data->nb_tx_queues)
1184 req = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
1186 req->ctype = NIX_AQ_CTYPE_SQ;
1187 req->op = NIX_AQ_INSTOP_WRITE;
1189 /* smq update only when needed */
1190 if (!rr_quantum_only) {
1192 req->sq_mask.smq = ~req->sq_mask.smq;
1194 req->sq.smq_rr_quantum = rr_quantum;
1195 req->sq_mask.smq_rr_quantum = ~req->sq_mask.smq_rr_quantum;
1197 rc = otx2_mbox_process(mbox);
1199 otx2_err("Failed to set smq, rc=%d", rc);
1203 int otx2_nix_sq_enable(void *_txq)
1205 struct otx2_eth_txq *txq = _txq;
1208 /* Enable sqb_aura fc */
1209 rc = otx2_nix_sq_sqb_aura_fc(txq, true);
1211 otx2_err("Failed to enable sqb aura fc, rc=%d", rc);
1219 nix_tm_free_resources(struct otx2_eth_dev *dev, uint32_t flags_mask,
1220 uint32_t flags, bool hw_only)
1222 struct otx2_nix_tm_shaper_profile *profile;
1223 struct otx2_nix_tm_node *tm_node, *next_node;
1224 struct otx2_mbox *mbox = dev->mbox;
1225 struct nix_txsch_free_req *req;
1226 uint32_t profile_id;
1229 next_node = TAILQ_FIRST(&dev->node_list);
1231 tm_node = next_node;
1232 next_node = TAILQ_NEXT(tm_node, node);
1234 /* Check for only requested nodes */
1235 if ((tm_node->flags & flags_mask) != flags)
1238 if (!nix_tm_is_leaf(dev, tm_node->lvl) &&
1239 tm_node->hw_lvl != NIX_TXSCH_LVL_TL1 &&
1240 tm_node->flags & NIX_TM_NODE_HWRES) {
1241 /* Free specific HW resource */
1242 otx2_tm_dbg("Free hwres %s(%u) lvl %u id %u (%p)",
1243 nix_hwlvl2str(tm_node->hw_lvl),
1244 tm_node->hw_id, tm_node->lvl,
1245 tm_node->id, tm_node);
1247 rc = nix_clear_path_xoff(dev, tm_node);
1251 req = otx2_mbox_alloc_msg_nix_txsch_free(mbox);
1253 req->schq_lvl = tm_node->hw_lvl;
1254 req->schq = tm_node->hw_id;
1255 rc = otx2_mbox_process(mbox);
1258 tm_node->flags &= ~NIX_TM_NODE_HWRES;
1261 /* Leave software elements if needed */
1265 otx2_tm_dbg("Free node lvl %u id %u (%p)",
1266 tm_node->lvl, tm_node->id, tm_node);
1268 profile_id = tm_node->params.shaper_profile_id;
1269 profile = nix_tm_shaper_profile_search(dev, profile_id);
1271 profile->reference_count--;
1273 TAILQ_REMOVE(&dev->node_list, tm_node, node);
1278 /* Free all hw resources */
1279 req = otx2_mbox_alloc_msg_nix_txsch_free(mbox);
1280 req->flags = TXSCHQ_FREE_ALL;
1282 return otx2_mbox_process(mbox);
1289 nix_tm_copy_rsp_to_dev(struct otx2_eth_dev *dev,
1290 struct nix_txsch_alloc_rsp *rsp)
1295 for (lvl = 0; lvl < NIX_TXSCH_LVL_CNT; lvl++) {
1296 for (schq = 0; schq < MAX_TXSCHQ_PER_FUNC; schq++) {
1297 dev->txschq_list[lvl][schq] = rsp->schq_list[lvl][schq];
1298 dev->txschq_contig_list[lvl][schq] =
1299 rsp->schq_contig_list[lvl][schq];
1302 dev->txschq[lvl] = rsp->schq[lvl];
1303 dev->txschq_contig[lvl] = rsp->schq_contig[lvl];
1309 nix_tm_assign_id_to_node(struct otx2_eth_dev *dev,
1310 struct otx2_nix_tm_node *child,
1311 struct otx2_nix_tm_node *parent)
1313 uint32_t hw_id, schq_con_index, prio_offset;
1314 uint32_t l_id, schq_index;
1316 otx2_tm_dbg("Assign hw id for child node %s lvl %u id %u (%p)",
1317 nix_hwlvl2str(child->hw_lvl), child->lvl, child->id, child);
1319 child->flags |= NIX_TM_NODE_HWRES;
1321 /* Process root nodes */
1322 if (dev->otx2_tm_root_lvl == NIX_TXSCH_LVL_TL2 &&
1323 child->hw_lvl == dev->otx2_tm_root_lvl && !parent) {
1325 uint32_t tschq_con_index;
1327 l_id = child->hw_lvl;
1328 tschq_con_index = dev->txschq_contig_index[l_id];
1329 hw_id = dev->txschq_contig_list[l_id][tschq_con_index];
1330 child->hw_id = hw_id;
1331 dev->txschq_contig_index[l_id]++;
1332 /* Update TL1 hw_id for its parent for config purpose */
1333 idx = dev->txschq_index[NIX_TXSCH_LVL_TL1]++;
1334 hw_id = dev->txschq_list[NIX_TXSCH_LVL_TL1][idx];
1335 child->parent_hw_id = hw_id;
1338 if (dev->otx2_tm_root_lvl == NIX_TXSCH_LVL_TL1 &&
1339 child->hw_lvl == dev->otx2_tm_root_lvl && !parent) {
1340 uint32_t tschq_con_index;
1342 l_id = child->hw_lvl;
1343 tschq_con_index = dev->txschq_index[l_id];
1344 hw_id = dev->txschq_list[l_id][tschq_con_index];
1345 child->hw_id = hw_id;
1346 dev->txschq_index[l_id]++;
1350 /* Process children with parents */
1351 l_id = child->hw_lvl;
1352 schq_index = dev->txschq_index[l_id];
1353 schq_con_index = dev->txschq_contig_index[l_id];
1355 if (child->priority == parent->rr_prio) {
1356 hw_id = dev->txschq_list[l_id][schq_index];
1357 child->hw_id = hw_id;
1358 child->parent_hw_id = parent->hw_id;
1359 dev->txschq_index[l_id]++;
1361 prio_offset = schq_con_index + child->priority;
1362 hw_id = dev->txschq_contig_list[l_id][prio_offset];
1363 child->hw_id = hw_id;
1369 nix_tm_assign_hw_id(struct otx2_eth_dev *dev)
1371 struct otx2_nix_tm_node *parent, *child;
1372 uint32_t child_hw_lvl, con_index_inc, i;
1374 for (i = NIX_TXSCH_LVL_TL1; i > 0; i--) {
1375 TAILQ_FOREACH(parent, &dev->node_list, node) {
1376 child_hw_lvl = parent->hw_lvl - 1;
1377 if (parent->hw_lvl != i)
1379 TAILQ_FOREACH(child, &dev->node_list, node) {
1382 if (child->parent->id != parent->id)
1384 nix_tm_assign_id_to_node(dev, child, parent);
1387 con_index_inc = parent->max_prio + 1;
1388 dev->txschq_contig_index[child_hw_lvl] += con_index_inc;
1391 * Explicitly assign id to parent node if it
1392 * doesn't have a parent
1394 if (parent->hw_lvl == dev->otx2_tm_root_lvl)
1395 nix_tm_assign_id_to_node(dev, parent, NULL);
1402 nix_tm_count_req_schq(struct otx2_eth_dev *dev,
1403 struct nix_txsch_alloc_req *req, uint8_t lvl)
1405 struct otx2_nix_tm_node *tm_node;
1406 uint8_t contig_count;
1408 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
1409 if (lvl == tm_node->hw_lvl) {
1410 req->schq[lvl - 1] += tm_node->rr_num;
1411 if (tm_node->max_prio != UINT32_MAX) {
1412 contig_count = tm_node->max_prio + 1;
1413 req->schq_contig[lvl - 1] += contig_count;
1416 if (lvl == dev->otx2_tm_root_lvl &&
1417 dev->otx2_tm_root_lvl && lvl == NIX_TXSCH_LVL_TL2 &&
1418 tm_node->hw_lvl == dev->otx2_tm_root_lvl) {
1419 req->schq_contig[dev->otx2_tm_root_lvl]++;
1423 req->schq[NIX_TXSCH_LVL_TL1] = 1;
1424 req->schq_contig[NIX_TXSCH_LVL_TL1] = 0;
1430 nix_tm_prepare_txschq_req(struct otx2_eth_dev *dev,
1431 struct nix_txsch_alloc_req *req)
1435 for (i = NIX_TXSCH_LVL_TL1; i > 0; i--)
1436 nix_tm_count_req_schq(dev, req, i);
1438 for (i = 0; i < NIX_TXSCH_LVL_CNT; i++) {
1439 dev->txschq_index[i] = 0;
1440 dev->txschq_contig_index[i] = 0;
1446 nix_tm_send_txsch_alloc_msg(struct otx2_eth_dev *dev)
1448 struct otx2_mbox *mbox = dev->mbox;
1449 struct nix_txsch_alloc_req *req;
1450 struct nix_txsch_alloc_rsp *rsp;
1453 req = otx2_mbox_alloc_msg_nix_txsch_alloc(mbox);
1455 rc = nix_tm_prepare_txschq_req(dev, req);
1459 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1463 nix_tm_copy_rsp_to_dev(dev, rsp);
1464 dev->link_cfg_lvl = rsp->link_cfg_lvl;
1466 nix_tm_assign_hw_id(dev);
1471 nix_tm_alloc_resources(struct rte_eth_dev *eth_dev, bool xmit_enable)
1473 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1474 struct otx2_nix_tm_node *tm_node;
1475 struct otx2_eth_txq *txq;
1479 nix_tm_update_parent_info(dev);
1481 rc = nix_tm_send_txsch_alloc_msg(dev);
1483 otx2_err("TM failed to alloc tm resources=%d", rc);
1487 rc = nix_tm_txsch_reg_config(dev);
1489 otx2_err("TM failed to configure sched registers=%d", rc);
1493 /* Trigger MTU recalculate as SMQ needs MTU conf */
1494 if (eth_dev->data->dev_started && eth_dev->data->nb_rx_queues) {
1495 rc = otx2_nix_recalc_mtu(eth_dev);
1497 otx2_err("TM MTU update failed, rc=%d", rc);
1502 /* Mark all non-leaf's as enabled */
1503 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
1504 if (!nix_tm_is_leaf(dev, tm_node->lvl))
1505 tm_node->flags |= NIX_TM_NODE_ENABLED;
1511 /* Update SQ Sched Data while SQ is idle */
1512 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
1513 if (!nix_tm_is_leaf(dev, tm_node->lvl))
1516 rc = nix_sq_sched_data(dev, tm_node, false);
1518 otx2_err("SQ %u sched update failed, rc=%d",
1524 /* Finally XON all SMQ's */
1525 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
1526 if (tm_node->hw_lvl != NIX_TXSCH_LVL_SMQ)
1529 rc = nix_smq_xoff(dev, tm_node, false);
1531 otx2_err("Failed to enable smq %u, rc=%d",
1532 tm_node->hw_id, rc);
1537 /* Enable xmit as all the topology is ready */
1538 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
1539 if (!nix_tm_is_leaf(dev, tm_node->lvl))
1543 txq = eth_dev->data->tx_queues[sq];
1545 rc = otx2_nix_sq_enable(txq);
1547 otx2_err("TM sw xon failed on SQ %u, rc=%d",
1551 tm_node->flags |= NIX_TM_NODE_ENABLED;
1558 send_tm_reqval(struct otx2_mbox *mbox,
1559 struct nix_txschq_config *req,
1560 struct rte_tm_error *error)
1564 if (!req->num_regs ||
1565 req->num_regs > MAX_REGS_PER_MBOX_MSG) {
1566 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
1567 error->message = "invalid config";
1571 rc = otx2_mbox_process(mbox);
1573 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
1574 error->message = "unexpected fatal error";
1580 nix_tm_lvl2nix(struct otx2_eth_dev *dev, uint32_t lvl)
1582 if (nix_tm_have_tl1_access(dev)) {
1584 case OTX2_TM_LVL_ROOT:
1585 return NIX_TXSCH_LVL_TL1;
1586 case OTX2_TM_LVL_SCH1:
1587 return NIX_TXSCH_LVL_TL2;
1588 case OTX2_TM_LVL_SCH2:
1589 return NIX_TXSCH_LVL_TL3;
1590 case OTX2_TM_LVL_SCH3:
1591 return NIX_TXSCH_LVL_TL4;
1592 case OTX2_TM_LVL_SCH4:
1593 return NIX_TXSCH_LVL_SMQ;
1595 return NIX_TXSCH_LVL_CNT;
1599 case OTX2_TM_LVL_ROOT:
1600 return NIX_TXSCH_LVL_TL2;
1601 case OTX2_TM_LVL_SCH1:
1602 return NIX_TXSCH_LVL_TL3;
1603 case OTX2_TM_LVL_SCH2:
1604 return NIX_TXSCH_LVL_TL4;
1605 case OTX2_TM_LVL_SCH3:
1606 return NIX_TXSCH_LVL_SMQ;
1608 return NIX_TXSCH_LVL_CNT;
1614 nix_max_prio(struct otx2_eth_dev *dev, uint16_t hw_lvl)
1616 if (hw_lvl >= NIX_TXSCH_LVL_CNT)
1619 /* MDQ doesn't support SP */
1620 if (hw_lvl == NIX_TXSCH_LVL_MDQ)
1623 /* PF's TL1 with VF's enabled doesn't support SP */
1624 if (hw_lvl == NIX_TXSCH_LVL_TL1 &&
1625 (dev->otx2_tm_root_lvl == NIX_TXSCH_LVL_TL2 ||
1626 (dev->tm_flags & NIX_TM_TL1_NO_SP)))
1629 return TXSCH_TLX_SP_PRIO_MAX - 1;
1634 validate_prio(struct otx2_eth_dev *dev, uint32_t lvl,
1635 uint32_t parent_id, uint32_t priority,
1636 struct rte_tm_error *error)
1638 uint8_t priorities[TXSCH_TLX_SP_PRIO_MAX];
1639 struct otx2_nix_tm_node *tm_node;
1640 uint32_t rr_num = 0;
1643 /* Validate priority against max */
1644 if (priority > nix_max_prio(dev, nix_tm_lvl2nix(dev, lvl - 1))) {
1645 error->type = RTE_TM_ERROR_TYPE_CAPABILITIES;
1646 error->message = "unsupported priority value";
1650 if (parent_id == RTE_TM_NODE_ID_NULL)
1653 memset(priorities, 0, TXSCH_TLX_SP_PRIO_MAX);
1654 priorities[priority] = 1;
1656 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
1657 if (!tm_node->parent)
1660 if (!(tm_node->flags & NIX_TM_NODE_USER))
1663 if (tm_node->parent->id != parent_id)
1666 priorities[tm_node->priority]++;
1669 for (i = 0; i < TXSCH_TLX_SP_PRIO_MAX; i++)
1670 if (priorities[i] > 1)
1673 /* At max, one rr groups per parent */
1675 error->type = RTE_TM_ERROR_TYPE_NODE_PRIORITY;
1676 error->message = "multiple DWRR node priority";
1680 /* Check for previous priority to avoid holes in priorities */
1681 if (priority && !priorities[priority - 1]) {
1682 error->type = RTE_TM_ERROR_TYPE_NODE_PRIORITY;
1683 error->message = "priority not in order";
1691 read_tm_reg(struct otx2_mbox *mbox, uint64_t reg,
1692 uint64_t *regval, uint32_t hw_lvl)
1694 volatile struct nix_txschq_config *req;
1695 struct nix_txschq_config *rsp;
1698 req = otx2_mbox_alloc_msg_nix_txschq_cfg(mbox);
1704 rc = otx2_mbox_process_msg(mbox, (void **)&rsp);
1707 *regval = rsp->regval[0];
1711 /* Search for min rate in topology */
1713 nix_tm_shaper_profile_update_min(struct otx2_eth_dev *dev)
1715 struct otx2_nix_tm_shaper_profile *profile;
1716 uint64_t rate_min = 1E9; /* 1 Gbps */
1718 TAILQ_FOREACH(profile, &dev->shaper_profile_list, shaper) {
1719 if (profile->params.peak.rate &&
1720 profile->params.peak.rate < rate_min)
1721 rate_min = profile->params.peak.rate;
1723 if (profile->params.committed.rate &&
1724 profile->params.committed.rate < rate_min)
1725 rate_min = profile->params.committed.rate;
1728 dev->tm_rate_min = rate_min;
1732 nix_xmit_disable(struct rte_eth_dev *eth_dev)
1734 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1735 uint16_t sq_cnt = eth_dev->data->nb_tx_queues;
1736 uint16_t sqb_cnt, head_off, tail_off;
1737 struct otx2_nix_tm_node *tm_node;
1738 struct otx2_eth_txq *txq;
1739 uint64_t wdata, val;
1742 otx2_tm_dbg("Disabling xmit on %s", eth_dev->data->name);
1744 /* Enable CGX RXTX to drain pkts */
1745 if (!eth_dev->data->dev_started) {
1746 otx2_mbox_alloc_msg_nix_lf_start_rx(dev->mbox);
1747 rc = otx2_mbox_process(dev->mbox);
1753 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
1754 if (tm_node->hw_lvl != NIX_TXSCH_LVL_SMQ)
1756 if (!(tm_node->flags & NIX_TM_NODE_HWRES))
1759 rc = nix_smq_xoff(dev, tm_node, false);
1761 otx2_err("Failed to enable smq %u, rc=%d",
1762 tm_node->hw_id, rc);
1767 /* Flush all tx queues */
1768 for (i = 0; i < sq_cnt; i++) {
1769 txq = eth_dev->data->tx_queues[i];
1771 rc = otx2_nix_sq_sqb_aura_fc(txq, false);
1773 otx2_err("Failed to disable sqb aura fc, rc=%d", rc);
1777 /* Wait for sq entries to be flushed */
1778 rc = nix_txq_flush_sq_spin(txq);
1780 otx2_err("Failed to drain sq, rc=%d\n", rc);
1785 /* XOFF & Flush all SMQ's. HRM mandates
1786 * all SQ's empty before SMQ flush is issued.
1788 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
1789 if (tm_node->hw_lvl != NIX_TXSCH_LVL_SMQ)
1791 if (!(tm_node->flags & NIX_TM_NODE_HWRES))
1794 rc = nix_smq_xoff(dev, tm_node, true);
1796 otx2_err("Failed to enable smq %u, rc=%d",
1797 tm_node->hw_id, rc);
1802 /* Verify sanity of all tx queues */
1803 for (i = 0; i < sq_cnt; i++) {
1804 txq = eth_dev->data->tx_queues[i];
1806 wdata = ((uint64_t)txq->sq << 32);
1807 val = otx2_atomic64_add_nosync(wdata,
1808 (int64_t *)(dev->base + NIX_LF_SQ_OP_STATUS));
1810 sqb_cnt = val & 0xFFFF;
1811 head_off = (val >> 20) & 0x3F;
1812 tail_off = (val >> 28) & 0x3F;
1814 if (sqb_cnt > 1 || head_off != tail_off ||
1815 (*txq->fc_mem != txq->nb_sqb_bufs))
1816 otx2_err("Failed to gracefully flush sq %u", txq->sq);
1820 /* restore cgx state */
1821 if (!eth_dev->data->dev_started) {
1822 otx2_mbox_alloc_msg_nix_lf_stop_rx(dev->mbox);
1823 rc |= otx2_mbox_process(dev->mbox);
1830 otx2_nix_tm_node_type_get(struct rte_eth_dev *eth_dev, uint32_t node_id,
1831 int *is_leaf, struct rte_tm_error *error)
1833 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1834 struct otx2_nix_tm_node *tm_node;
1836 if (is_leaf == NULL) {
1837 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
1841 tm_node = nix_tm_node_search(dev, node_id, true);
1842 if (node_id == RTE_TM_NODE_ID_NULL || !tm_node) {
1843 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
1846 if (nix_tm_is_leaf(dev, tm_node->lvl))
1854 otx2_nix_tm_capa_get(struct rte_eth_dev *eth_dev,
1855 struct rte_tm_capabilities *cap,
1856 struct rte_tm_error *error)
1858 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1859 struct otx2_mbox *mbox = dev->mbox;
1860 int rc, max_nr_nodes = 0, i;
1861 struct free_rsrcs_rsp *rsp;
1863 memset(cap, 0, sizeof(*cap));
1865 otx2_mbox_alloc_msg_free_rsrc_cnt(mbox);
1866 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1868 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
1869 error->message = "unexpected fatal error";
1873 for (i = 0; i < NIX_TXSCH_LVL_TL1; i++)
1874 max_nr_nodes += rsp->schq[i];
1876 cap->n_nodes_max = max_nr_nodes + dev->tm_leaf_cnt;
1877 /* TL1 level is reserved for PF */
1878 cap->n_levels_max = nix_tm_have_tl1_access(dev) ?
1879 OTX2_TM_LVL_MAX : OTX2_TM_LVL_MAX - 1;
1880 cap->non_leaf_nodes_identical = 1;
1881 cap->leaf_nodes_identical = 1;
1883 /* Shaper Capabilities */
1884 cap->shaper_private_n_max = max_nr_nodes;
1885 cap->shaper_n_max = max_nr_nodes;
1886 cap->shaper_private_dual_rate_n_max = max_nr_nodes;
1887 cap->shaper_private_rate_min = MIN_SHAPER_RATE / 8;
1888 cap->shaper_private_rate_max = MAX_SHAPER_RATE / 8;
1889 cap->shaper_pkt_length_adjust_min = 0;
1890 cap->shaper_pkt_length_adjust_max = 0;
1892 /* Schedule Capabilities */
1893 cap->sched_n_children_max = rsp->schq[NIX_TXSCH_LVL_MDQ];
1894 cap->sched_sp_n_priorities_max = TXSCH_TLX_SP_PRIO_MAX;
1895 cap->sched_wfq_n_children_per_group_max = cap->sched_n_children_max;
1896 cap->sched_wfq_n_groups_max = 1;
1897 cap->sched_wfq_weight_max = MAX_SCHED_WEIGHT;
1899 cap->dynamic_update_mask =
1900 RTE_TM_UPDATE_NODE_PARENT_KEEP_LEVEL |
1901 RTE_TM_UPDATE_NODE_SUSPEND_RESUME;
1903 RTE_TM_STATS_N_PKTS |
1904 RTE_TM_STATS_N_BYTES |
1905 RTE_TM_STATS_N_PKTS_RED_DROPPED |
1906 RTE_TM_STATS_N_BYTES_RED_DROPPED;
1908 for (i = 0; i < RTE_COLORS; i++) {
1909 cap->mark_vlan_dei_supported[i] = false;
1910 cap->mark_ip_ecn_tcp_supported[i] = false;
1911 cap->mark_ip_dscp_supported[i] = false;
1918 otx2_nix_tm_level_capa_get(struct rte_eth_dev *eth_dev, uint32_t lvl,
1919 struct rte_tm_level_capabilities *cap,
1920 struct rte_tm_error *error)
1922 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1923 struct otx2_mbox *mbox = dev->mbox;
1924 struct free_rsrcs_rsp *rsp;
1928 memset(cap, 0, sizeof(*cap));
1930 otx2_mbox_alloc_msg_free_rsrc_cnt(mbox);
1931 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1933 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
1934 error->message = "unexpected fatal error";
1938 hw_lvl = nix_tm_lvl2nix(dev, lvl);
1940 if (nix_tm_is_leaf(dev, lvl)) {
1942 cap->n_nodes_max = dev->tm_leaf_cnt;
1943 cap->n_nodes_leaf_max = dev->tm_leaf_cnt;
1944 cap->leaf_nodes_identical = 1;
1945 cap->leaf.stats_mask =
1946 RTE_TM_STATS_N_PKTS |
1947 RTE_TM_STATS_N_BYTES;
1949 } else if (lvl == OTX2_TM_LVL_ROOT) {
1950 /* Root node, aka TL2(vf)/TL1(pf) */
1951 cap->n_nodes_max = 1;
1952 cap->n_nodes_nonleaf_max = 1;
1953 cap->non_leaf_nodes_identical = 1;
1955 cap->nonleaf.shaper_private_supported = true;
1956 cap->nonleaf.shaper_private_dual_rate_supported =
1957 nix_tm_have_tl1_access(dev) ? false : true;
1958 cap->nonleaf.shaper_private_rate_min = MIN_SHAPER_RATE / 8;
1959 cap->nonleaf.shaper_private_rate_max = MAX_SHAPER_RATE / 8;
1961 cap->nonleaf.sched_n_children_max = rsp->schq[hw_lvl - 1];
1962 cap->nonleaf.sched_sp_n_priorities_max =
1963 nix_max_prio(dev, hw_lvl) + 1;
1964 cap->nonleaf.sched_wfq_n_groups_max = 1;
1965 cap->nonleaf.sched_wfq_weight_max = MAX_SCHED_WEIGHT;
1967 if (nix_tm_have_tl1_access(dev))
1968 cap->nonleaf.stats_mask =
1969 RTE_TM_STATS_N_PKTS_RED_DROPPED |
1970 RTE_TM_STATS_N_BYTES_RED_DROPPED;
1971 } else if ((lvl < OTX2_TM_LVL_MAX) &&
1972 (hw_lvl < NIX_TXSCH_LVL_CNT)) {
1973 /* TL2, TL3, TL4, MDQ */
1974 cap->n_nodes_max = rsp->schq[hw_lvl];
1975 cap->n_nodes_nonleaf_max = cap->n_nodes_max;
1976 cap->non_leaf_nodes_identical = 1;
1978 cap->nonleaf.shaper_private_supported = true;
1979 cap->nonleaf.shaper_private_dual_rate_supported = true;
1980 cap->nonleaf.shaper_private_rate_min = MIN_SHAPER_RATE / 8;
1981 cap->nonleaf.shaper_private_rate_max = MAX_SHAPER_RATE / 8;
1983 /* MDQ doesn't support Strict Priority */
1984 if (hw_lvl == NIX_TXSCH_LVL_MDQ)
1985 cap->nonleaf.sched_n_children_max = dev->tm_leaf_cnt;
1987 cap->nonleaf.sched_n_children_max =
1988 rsp->schq[hw_lvl - 1];
1989 cap->nonleaf.sched_sp_n_priorities_max =
1990 nix_max_prio(dev, hw_lvl) + 1;
1991 cap->nonleaf.sched_wfq_n_groups_max = 1;
1992 cap->nonleaf.sched_wfq_weight_max = MAX_SCHED_WEIGHT;
1994 /* unsupported level */
1995 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
2002 otx2_nix_tm_node_capa_get(struct rte_eth_dev *eth_dev, uint32_t node_id,
2003 struct rte_tm_node_capabilities *cap,
2004 struct rte_tm_error *error)
2006 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2007 struct otx2_mbox *mbox = dev->mbox;
2008 struct otx2_nix_tm_node *tm_node;
2009 struct free_rsrcs_rsp *rsp;
2010 int rc, hw_lvl, lvl;
2012 memset(cap, 0, sizeof(*cap));
2014 tm_node = nix_tm_node_search(dev, node_id, true);
2016 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
2017 error->message = "no such node";
2021 hw_lvl = tm_node->hw_lvl;
2025 if (nix_tm_is_leaf(dev, lvl)) {
2026 cap->stats_mask = RTE_TM_STATS_N_PKTS |
2027 RTE_TM_STATS_N_BYTES;
2031 otx2_mbox_alloc_msg_free_rsrc_cnt(mbox);
2032 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
2034 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
2035 error->message = "unexpected fatal error";
2039 /* Non Leaf Shaper */
2040 cap->shaper_private_supported = true;
2041 cap->shaper_private_dual_rate_supported =
2042 (hw_lvl == NIX_TXSCH_LVL_TL1) ? false : true;
2043 cap->shaper_private_rate_min = MIN_SHAPER_RATE / 8;
2044 cap->shaper_private_rate_max = MAX_SHAPER_RATE / 8;
2046 /* Non Leaf Scheduler */
2047 if (hw_lvl == NIX_TXSCH_LVL_MDQ)
2048 cap->nonleaf.sched_n_children_max = dev->tm_leaf_cnt;
2050 cap->nonleaf.sched_n_children_max = rsp->schq[hw_lvl - 1];
2052 cap->nonleaf.sched_sp_n_priorities_max = nix_max_prio(dev, hw_lvl) + 1;
2053 cap->nonleaf.sched_wfq_n_children_per_group_max =
2054 cap->nonleaf.sched_n_children_max;
2055 cap->nonleaf.sched_wfq_n_groups_max = 1;
2056 cap->nonleaf.sched_wfq_weight_max = MAX_SCHED_WEIGHT;
2058 if (hw_lvl == NIX_TXSCH_LVL_TL1)
2059 cap->stats_mask = RTE_TM_STATS_N_PKTS_RED_DROPPED |
2060 RTE_TM_STATS_N_BYTES_RED_DROPPED;
2065 otx2_nix_tm_shaper_profile_add(struct rte_eth_dev *eth_dev,
2066 uint32_t profile_id,
2067 struct rte_tm_shaper_params *params,
2068 struct rte_tm_error *error)
2070 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2071 struct otx2_nix_tm_shaper_profile *profile;
2073 profile = nix_tm_shaper_profile_search(dev, profile_id);
2075 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
2076 error->message = "shaper profile ID exist";
2080 /* Committed rate and burst size can be enabled/disabled */
2081 if (params->committed.size || params->committed.rate) {
2082 if (params->committed.size < MIN_SHAPER_BURST ||
2083 params->committed.size > MAX_SHAPER_BURST) {
2085 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_SIZE;
2087 } else if (!shaper_rate_to_nix(params->committed.rate * 8,
2088 NULL, NULL, NULL)) {
2090 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE;
2091 error->message = "shaper committed rate invalid";
2096 /* Peak rate and burst size can be enabled/disabled */
2097 if (params->peak.size || params->peak.rate) {
2098 if (params->peak.size < MIN_SHAPER_BURST ||
2099 params->peak.size > MAX_SHAPER_BURST) {
2101 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE;
2103 } else if (!shaper_rate_to_nix(params->peak.rate * 8,
2104 NULL, NULL, NULL)) {
2106 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE;
2107 error->message = "shaper peak rate invalid";
2112 profile = rte_zmalloc("otx2_nix_tm_shaper_profile",
2113 sizeof(struct otx2_nix_tm_shaper_profile), 0);
2117 profile->shaper_profile_id = profile_id;
2118 rte_memcpy(&profile->params, params,
2119 sizeof(struct rte_tm_shaper_params));
2120 TAILQ_INSERT_TAIL(&dev->shaper_profile_list, profile, shaper);
2122 otx2_tm_dbg("Added TM shaper profile %u, "
2123 " pir %" PRIu64 " , pbs %" PRIu64 ", cir %" PRIu64
2124 ", cbs %" PRIu64 " , adj %u",
2126 params->peak.rate * 8,
2128 params->committed.rate * 8,
2129 params->committed.size,
2130 params->pkt_length_adjust);
2132 /* Translate rate as bits per second */
2133 profile->params.peak.rate = profile->params.peak.rate * 8;
2134 profile->params.committed.rate = profile->params.committed.rate * 8;
2135 /* Always use PIR for single rate shaping */
2136 if (!params->peak.rate && params->committed.rate) {
2137 profile->params.peak = profile->params.committed;
2138 memset(&profile->params.committed, 0,
2139 sizeof(profile->params.committed));
2142 /* update min rate */
2143 nix_tm_shaper_profile_update_min(dev);
2148 otx2_nix_tm_shaper_profile_delete(struct rte_eth_dev *eth_dev,
2149 uint32_t profile_id,
2150 struct rte_tm_error *error)
2152 struct otx2_nix_tm_shaper_profile *profile;
2153 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2155 profile = nix_tm_shaper_profile_search(dev, profile_id);
2158 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
2159 error->message = "shaper profile ID not exist";
2163 if (profile->reference_count) {
2164 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
2165 error->message = "shaper profile in use";
2169 otx2_tm_dbg("Removing TM shaper profile %u", profile_id);
2170 TAILQ_REMOVE(&dev->shaper_profile_list, profile, shaper);
2173 /* update min rate */
2174 nix_tm_shaper_profile_update_min(dev);
2179 otx2_nix_tm_node_add(struct rte_eth_dev *eth_dev, uint32_t node_id,
2180 uint32_t parent_node_id, uint32_t priority,
2181 uint32_t weight, uint32_t lvl,
2182 struct rte_tm_node_params *params,
2183 struct rte_tm_error *error)
2185 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2186 struct otx2_nix_tm_node *parent_node;
2187 int rc, clear_on_fail = 0;
2188 uint32_t exp_next_lvl;
2191 /* we don't support dynamic updates */
2192 if (dev->tm_flags & NIX_TM_COMMITTED) {
2193 error->type = RTE_TM_ERROR_TYPE_CAPABILITIES;
2194 error->message = "dynamic update not supported";
2198 /* Leaf nodes have to be same priority */
2199 if (nix_tm_is_leaf(dev, lvl) && priority != 0) {
2200 error->type = RTE_TM_ERROR_TYPE_CAPABILITIES;
2201 error->message = "queue shapers must be priority 0";
2205 parent_node = nix_tm_node_search(dev, parent_node_id, true);
2207 /* find the right level */
2208 if (lvl == RTE_TM_NODE_LEVEL_ID_ANY) {
2209 if (parent_node_id == RTE_TM_NODE_ID_NULL) {
2210 lvl = OTX2_TM_LVL_ROOT;
2211 } else if (parent_node) {
2212 lvl = parent_node->lvl + 1;
2214 /* Neigher proper parent nor proper level id given */
2215 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
2216 error->message = "invalid parent node id";
2221 /* Translate rte_tm level id's to nix hw level id's */
2222 hw_lvl = nix_tm_lvl2nix(dev, lvl);
2223 if (hw_lvl == NIX_TXSCH_LVL_CNT &&
2224 !nix_tm_is_leaf(dev, lvl)) {
2225 error->type = RTE_TM_ERROR_TYPE_LEVEL_ID;
2226 error->message = "invalid level id";
2230 if (node_id < dev->tm_leaf_cnt)
2231 exp_next_lvl = NIX_TXSCH_LVL_SMQ;
2233 exp_next_lvl = hw_lvl + 1;
2235 /* Check if there is no parent node yet */
2236 if (hw_lvl != dev->otx2_tm_root_lvl &&
2237 (!parent_node || parent_node->hw_lvl != exp_next_lvl)) {
2238 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
2239 error->message = "invalid parent node id";
2243 /* Check if a node already exists */
2244 if (nix_tm_node_search(dev, node_id, true)) {
2245 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
2246 error->message = "node already exists";
2250 /* Check if shaper profile exists for non leaf node */
2251 if (!nix_tm_is_leaf(dev, lvl) &&
2252 params->shaper_profile_id != RTE_TM_SHAPER_PROFILE_ID_NONE &&
2253 !nix_tm_shaper_profile_search(dev, params->shaper_profile_id)) {
2254 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
2255 error->message = "invalid shaper profile";
2259 /* Check if there is second DWRR already in siblings or holes in prio */
2260 if (validate_prio(dev, lvl, parent_node_id, priority, error))
2263 if (weight > MAX_SCHED_WEIGHT) {
2264 error->type = RTE_TM_ERROR_TYPE_NODE_WEIGHT;
2265 error->message = "max weight exceeded";
2269 rc = nix_tm_node_add_to_list(dev, node_id, parent_node_id,
2270 priority, weight, hw_lvl,
2273 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
2274 /* cleanup user added nodes */
2276 nix_tm_free_resources(dev, NIX_TM_NODE_USER,
2277 NIX_TM_NODE_USER, false);
2278 error->message = "failed to add node";
2281 error->type = RTE_TM_ERROR_TYPE_NONE;
2286 otx2_nix_tm_node_delete(struct rte_eth_dev *eth_dev, uint32_t node_id,
2287 struct rte_tm_error *error)
2289 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2290 struct otx2_nix_tm_node *tm_node, *child_node;
2291 struct otx2_nix_tm_shaper_profile *profile;
2292 uint32_t profile_id;
2294 /* we don't support dynamic updates yet */
2295 if (dev->tm_flags & NIX_TM_COMMITTED) {
2296 error->type = RTE_TM_ERROR_TYPE_CAPABILITIES;
2297 error->message = "hierarchy exists";
2301 if (node_id == RTE_TM_NODE_ID_NULL) {
2302 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
2303 error->message = "invalid node id";
2307 tm_node = nix_tm_node_search(dev, node_id, true);
2309 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
2310 error->message = "no such node";
2314 /* Check for any existing children */
2315 TAILQ_FOREACH(child_node, &dev->node_list, node) {
2316 if (child_node->parent == tm_node) {
2317 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
2318 error->message = "children exist";
2323 /* Remove shaper profile reference */
2324 profile_id = tm_node->params.shaper_profile_id;
2325 profile = nix_tm_shaper_profile_search(dev, profile_id);
2326 profile->reference_count--;
2328 TAILQ_REMOVE(&dev->node_list, tm_node, node);
2334 nix_tm_node_suspend_resume(struct rte_eth_dev *eth_dev, uint32_t node_id,
2335 struct rte_tm_error *error, bool suspend)
2337 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2338 struct otx2_mbox *mbox = dev->mbox;
2339 struct otx2_nix_tm_node *tm_node;
2340 struct nix_txschq_config *req;
2344 tm_node = nix_tm_node_search(dev, node_id, true);
2346 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
2347 error->message = "no such node";
2351 if (!(dev->tm_flags & NIX_TM_COMMITTED)) {
2352 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
2353 error->message = "hierarchy doesn't exist";
2357 flags = tm_node->flags;
2358 flags = suspend ? (flags & ~NIX_TM_NODE_ENABLED) :
2359 (flags | NIX_TM_NODE_ENABLED);
2361 if (tm_node->flags == flags)
2364 /* send mbox for state change */
2365 req = otx2_mbox_alloc_msg_nix_txschq_cfg(mbox);
2367 req->lvl = tm_node->hw_lvl;
2368 req->num_regs = prepare_tm_sw_xoff(tm_node, suspend,
2369 req->reg, req->regval);
2370 rc = send_tm_reqval(mbox, req, error);
2372 tm_node->flags = flags;
2377 otx2_nix_tm_node_suspend(struct rte_eth_dev *eth_dev, uint32_t node_id,
2378 struct rte_tm_error *error)
2380 return nix_tm_node_suspend_resume(eth_dev, node_id, error, true);
2384 otx2_nix_tm_node_resume(struct rte_eth_dev *eth_dev, uint32_t node_id,
2385 struct rte_tm_error *error)
2387 return nix_tm_node_suspend_resume(eth_dev, node_id, error, false);
2391 otx2_nix_tm_hierarchy_commit(struct rte_eth_dev *eth_dev,
2393 struct rte_tm_error *error)
2395 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2396 struct otx2_nix_tm_node *tm_node;
2397 uint32_t leaf_cnt = 0;
2400 if (dev->tm_flags & NIX_TM_COMMITTED) {
2401 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
2402 error->message = "hierarchy exists";
2406 /* Check if we have all the leaf nodes */
2407 TAILQ_FOREACH(tm_node, &dev->node_list, node) {
2408 if (tm_node->flags & NIX_TM_NODE_USER &&
2409 tm_node->id < dev->tm_leaf_cnt)
2413 if (leaf_cnt != dev->tm_leaf_cnt) {
2414 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
2415 error->message = "incomplete hierarchy";
2420 * Disable xmit will be enabled when
2421 * new topology is available.
2423 rc = nix_xmit_disable(eth_dev);
2425 otx2_err("failed to disable TX, rc=%d", rc);
2429 /* Delete default/ratelimit tree */
2430 if (dev->tm_flags & (NIX_TM_DEFAULT_TREE | NIX_TM_RATE_LIMIT_TREE)) {
2431 rc = nix_tm_free_resources(dev, NIX_TM_NODE_USER, 0, false);
2433 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
2434 error->message = "failed to free default resources";
2437 dev->tm_flags &= ~(NIX_TM_DEFAULT_TREE |
2438 NIX_TM_RATE_LIMIT_TREE);
2441 /* Free up user alloc'ed resources */
2442 rc = nix_tm_free_resources(dev, NIX_TM_NODE_USER,
2443 NIX_TM_NODE_USER, true);
2445 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
2446 error->message = "failed to free user resources";
2450 rc = nix_tm_alloc_resources(eth_dev, true);
2452 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
2453 error->message = "alloc resources failed";
2454 /* TODO should we restore default config ? */
2456 nix_tm_free_resources(dev, 0, 0, false);
2460 error->type = RTE_TM_ERROR_TYPE_NONE;
2461 dev->tm_flags |= NIX_TM_COMMITTED;
2466 otx2_nix_tm_node_shaper_update(struct rte_eth_dev *eth_dev,
2468 uint32_t profile_id,
2469 struct rte_tm_error *error)
2471 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2472 struct otx2_nix_tm_shaper_profile *profile = NULL;
2473 struct otx2_mbox *mbox = dev->mbox;
2474 struct otx2_nix_tm_node *tm_node;
2475 struct nix_txschq_config *req;
2479 tm_node = nix_tm_node_search(dev, node_id, true);
2480 if (!tm_node || nix_tm_is_leaf(dev, tm_node->lvl)) {
2481 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
2482 error->message = "invalid node";
2486 if (profile_id == tm_node->params.shaper_profile_id)
2489 if (profile_id != RTE_TM_SHAPER_PROFILE_ID_NONE) {
2490 profile = nix_tm_shaper_profile_search(dev, profile_id);
2492 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
2493 error->message = "shaper profile ID not exist";
2498 tm_node->params.shaper_profile_id = profile_id;
2500 /* Nothing to do if not yet committed */
2501 if (!(dev->tm_flags & NIX_TM_COMMITTED))
2504 tm_node->flags &= ~NIX_TM_NODE_ENABLED;
2506 /* Flush the specific node with SW_XOFF */
2507 req = otx2_mbox_alloc_msg_nix_txschq_cfg(mbox);
2508 req->lvl = tm_node->hw_lvl;
2509 k = prepare_tm_sw_xoff(tm_node, true, req->reg, req->regval);
2512 rc = send_tm_reqval(mbox, req, error);
2516 shaper_default_red_algo(dev, tm_node, profile);
2518 /* Update the PIR/CIR and clear SW XOFF */
2519 req = otx2_mbox_alloc_msg_nix_txschq_cfg(mbox);
2520 req->lvl = tm_node->hw_lvl;
2522 k = prepare_tm_shaper_reg(tm_node, profile, req->reg, req->regval);
2524 k += prepare_tm_sw_xoff(tm_node, false, &req->reg[k], &req->regval[k]);
2527 rc = send_tm_reqval(mbox, req, error);
2529 tm_node->flags |= NIX_TM_NODE_ENABLED;
2534 otx2_nix_tm_node_parent_update(struct rte_eth_dev *eth_dev,
2535 uint32_t node_id, uint32_t new_parent_id,
2536 uint32_t priority, uint32_t weight,
2537 struct rte_tm_error *error)
2539 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2540 struct otx2_nix_tm_node *tm_node, *sibling;
2541 struct otx2_nix_tm_node *new_parent;
2542 struct nix_txschq_config *req;
2546 if (!(dev->tm_flags & NIX_TM_COMMITTED)) {
2547 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
2548 error->message = "hierarchy doesn't exist";
2552 tm_node = nix_tm_node_search(dev, node_id, true);
2554 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
2555 error->message = "no such node";
2559 /* Parent id valid only for non root nodes */
2560 if (tm_node->hw_lvl != dev->otx2_tm_root_lvl) {
2561 new_parent = nix_tm_node_search(dev, new_parent_id, true);
2563 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
2564 error->message = "no such parent node";
2568 /* Current support is only for dynamic weight update */
2569 if (tm_node->parent != new_parent ||
2570 tm_node->priority != priority) {
2571 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
2572 error->message = "only weight update supported";
2577 /* Skip if no change */
2578 if (tm_node->weight == weight)
2581 tm_node->weight = weight;
2583 /* For leaf nodes, SQ CTX needs update */
2584 if (nix_tm_is_leaf(dev, tm_node->lvl)) {
2585 /* Update SQ quantum data on the fly */
2586 rc = nix_sq_sched_data(dev, tm_node, true);
2588 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
2589 error->message = "sq sched data update failed";
2593 /* XOFF Parent node */
2594 req = otx2_mbox_alloc_msg_nix_txschq_cfg(dev->mbox);
2595 req->lvl = tm_node->parent->hw_lvl;
2596 req->num_regs = prepare_tm_sw_xoff(tm_node->parent, true,
2597 req->reg, req->regval);
2598 rc = send_tm_reqval(dev->mbox, req, error);
2602 /* XOFF this node and all other siblings */
2603 req = otx2_mbox_alloc_msg_nix_txschq_cfg(dev->mbox);
2604 req->lvl = tm_node->hw_lvl;
2607 TAILQ_FOREACH(sibling, &dev->node_list, node) {
2608 if (sibling->parent != tm_node->parent)
2610 k += prepare_tm_sw_xoff(sibling, true, &req->reg[k],
2614 rc = send_tm_reqval(dev->mbox, req, error);
2618 /* Update new weight for current node */
2619 req = otx2_mbox_alloc_msg_nix_txschq_cfg(dev->mbox);
2620 req->lvl = tm_node->hw_lvl;
2621 req->num_regs = prepare_tm_sched_reg(dev, tm_node,
2622 req->reg, req->regval);
2623 rc = send_tm_reqval(dev->mbox, req, error);
2627 /* XON this node and all other siblings */
2628 req = otx2_mbox_alloc_msg_nix_txschq_cfg(dev->mbox);
2629 req->lvl = tm_node->hw_lvl;
2632 TAILQ_FOREACH(sibling, &dev->node_list, node) {
2633 if (sibling->parent != tm_node->parent)
2635 k += prepare_tm_sw_xoff(sibling, false, &req->reg[k],
2639 rc = send_tm_reqval(dev->mbox, req, error);
2643 /* XON Parent node */
2644 req = otx2_mbox_alloc_msg_nix_txschq_cfg(dev->mbox);
2645 req->lvl = tm_node->parent->hw_lvl;
2646 req->num_regs = prepare_tm_sw_xoff(tm_node->parent, false,
2647 req->reg, req->regval);
2648 rc = send_tm_reqval(dev->mbox, req, error);
2656 otx2_nix_tm_node_stats_read(struct rte_eth_dev *eth_dev, uint32_t node_id,
2657 struct rte_tm_node_stats *stats,
2658 uint64_t *stats_mask, int clear,
2659 struct rte_tm_error *error)
2661 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2662 struct otx2_nix_tm_node *tm_node;
2667 tm_node = nix_tm_node_search(dev, node_id, true);
2669 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
2670 error->message = "no such node";
2674 /* Stats support only for leaf node or TL1 root */
2675 if (nix_tm_is_leaf(dev, tm_node->lvl)) {
2676 reg = (((uint64_t)tm_node->id) << 32);
2679 addr = (int64_t *)(dev->base + NIX_LF_SQ_OP_PKTS);
2680 val = otx2_atomic64_add_nosync(reg, addr);
2683 stats->n_pkts = val - tm_node->last_pkts;
2686 addr = (int64_t *)(dev->base + NIX_LF_SQ_OP_OCTS);
2687 val = otx2_atomic64_add_nosync(reg, addr);
2690 stats->n_bytes = val - tm_node->last_bytes;
2693 tm_node->last_pkts = stats->n_pkts;
2694 tm_node->last_bytes = stats->n_bytes;
2697 *stats_mask = RTE_TM_STATS_N_PKTS | RTE_TM_STATS_N_BYTES;
2699 } else if (tm_node->hw_lvl == NIX_TXSCH_LVL_TL1) {
2700 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
2701 error->message = "stats read error";
2703 /* RED Drop packets */
2704 reg = NIX_AF_TL1X_DROPPED_PACKETS(tm_node->hw_id);
2705 rc = read_tm_reg(dev->mbox, reg, &val, NIX_TXSCH_LVL_TL1);
2708 stats->leaf.n_pkts_dropped[RTE_COLOR_RED] =
2709 val - tm_node->last_pkts;
2711 /* RED Drop bytes */
2712 reg = NIX_AF_TL1X_DROPPED_BYTES(tm_node->hw_id);
2713 rc = read_tm_reg(dev->mbox, reg, &val, NIX_TXSCH_LVL_TL1);
2716 stats->leaf.n_bytes_dropped[RTE_COLOR_RED] =
2717 val - tm_node->last_bytes;
2721 tm_node->last_pkts =
2722 stats->leaf.n_pkts_dropped[RTE_COLOR_RED];
2723 tm_node->last_bytes =
2724 stats->leaf.n_bytes_dropped[RTE_COLOR_RED];
2727 *stats_mask = RTE_TM_STATS_N_PKTS_RED_DROPPED |
2728 RTE_TM_STATS_N_BYTES_RED_DROPPED;
2731 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
2732 error->message = "unsupported node";
2740 const struct rte_tm_ops otx2_tm_ops = {
2741 .node_type_get = otx2_nix_tm_node_type_get,
2743 .capabilities_get = otx2_nix_tm_capa_get,
2744 .level_capabilities_get = otx2_nix_tm_level_capa_get,
2745 .node_capabilities_get = otx2_nix_tm_node_capa_get,
2747 .shaper_profile_add = otx2_nix_tm_shaper_profile_add,
2748 .shaper_profile_delete = otx2_nix_tm_shaper_profile_delete,
2750 .node_add = otx2_nix_tm_node_add,
2751 .node_delete = otx2_nix_tm_node_delete,
2752 .node_suspend = otx2_nix_tm_node_suspend,
2753 .node_resume = otx2_nix_tm_node_resume,
2754 .hierarchy_commit = otx2_nix_tm_hierarchy_commit,
2756 .node_shaper_update = otx2_nix_tm_node_shaper_update,
2757 .node_parent_update = otx2_nix_tm_node_parent_update,
2758 .node_stats_read = otx2_nix_tm_node_stats_read,
2762 nix_tm_prepare_default_tree(struct rte_eth_dev *eth_dev)
2764 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2765 uint32_t def = eth_dev->data->nb_tx_queues;
2766 struct rte_tm_node_params params;
2767 uint32_t leaf_parent, i;
2768 int rc = 0, leaf_level;
2770 /* Default params */
2771 memset(¶ms, 0, sizeof(params));
2772 params.shaper_profile_id = RTE_TM_SHAPER_PROFILE_ID_NONE;
2774 if (nix_tm_have_tl1_access(dev)) {
2775 dev->otx2_tm_root_lvl = NIX_TXSCH_LVL_TL1;
2776 rc = nix_tm_node_add_to_list(dev, def, RTE_TM_NODE_ID_NULL, 0,
2779 OTX2_TM_LVL_ROOT, false, ¶ms);
2782 rc = nix_tm_node_add_to_list(dev, def + 1, def, 0,
2785 OTX2_TM_LVL_SCH1, false, ¶ms);
2789 rc = nix_tm_node_add_to_list(dev, def + 2, def + 1, 0,
2792 OTX2_TM_LVL_SCH2, false, ¶ms);
2796 rc = nix_tm_node_add_to_list(dev, def + 3, def + 2, 0,
2799 OTX2_TM_LVL_SCH3, false, ¶ms);
2803 rc = nix_tm_node_add_to_list(dev, def + 4, def + 3, 0,
2806 OTX2_TM_LVL_SCH4, false, ¶ms);
2810 leaf_parent = def + 4;
2811 leaf_level = OTX2_TM_LVL_QUEUE;
2813 dev->otx2_tm_root_lvl = NIX_TXSCH_LVL_TL2;
2814 rc = nix_tm_node_add_to_list(dev, def, RTE_TM_NODE_ID_NULL, 0,
2817 OTX2_TM_LVL_ROOT, false, ¶ms);
2821 rc = nix_tm_node_add_to_list(dev, def + 1, def, 0,
2824 OTX2_TM_LVL_SCH1, false, ¶ms);
2828 rc = nix_tm_node_add_to_list(dev, def + 2, def + 1, 0,
2831 OTX2_TM_LVL_SCH2, false, ¶ms);
2835 rc = nix_tm_node_add_to_list(dev, def + 3, def + 2, 0,
2838 OTX2_TM_LVL_SCH3, false, ¶ms);
2842 leaf_parent = def + 3;
2843 leaf_level = OTX2_TM_LVL_SCH4;
2846 /* Add leaf nodes */
2847 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
2848 rc = nix_tm_node_add_to_list(dev, i, leaf_parent, 0,
2851 leaf_level, false, ¶ms);
2860 void otx2_nix_tm_conf_init(struct rte_eth_dev *eth_dev)
2862 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2864 TAILQ_INIT(&dev->node_list);
2865 TAILQ_INIT(&dev->shaper_profile_list);
2866 dev->tm_rate_min = 1E9; /* 1Gbps */
2869 int otx2_nix_tm_init_default(struct rte_eth_dev *eth_dev)
2871 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2872 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2873 uint16_t sq_cnt = eth_dev->data->nb_tx_queues;
2876 /* Free up all resources already held */
2877 rc = nix_tm_free_resources(dev, 0, 0, false);
2879 otx2_err("Failed to freeup existing resources,rc=%d", rc);
2883 /* Clear shaper profiles */
2884 nix_tm_clear_shaper_profiles(dev);
2885 dev->tm_flags = NIX_TM_DEFAULT_TREE;
2887 /* Disable TL1 Static Priority when VF's are enabled
2888 * as otherwise VF's TL2 reallocation will be needed
2889 * runtime to support a specific topology of PF.
2891 if (pci_dev->max_vfs)
2892 dev->tm_flags |= NIX_TM_TL1_NO_SP;
2894 rc = nix_tm_prepare_default_tree(eth_dev);
2898 rc = nix_tm_alloc_resources(eth_dev, false);
2901 dev->tm_leaf_cnt = sq_cnt;
2907 nix_tm_prepare_rate_limited_tree(struct rte_eth_dev *eth_dev)
2909 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2910 uint32_t def = eth_dev->data->nb_tx_queues;
2911 struct rte_tm_node_params params;
2912 uint32_t leaf_parent, i, rc = 0;
2914 memset(¶ms, 0, sizeof(params));
2916 if (nix_tm_have_tl1_access(dev)) {
2917 dev->otx2_tm_root_lvl = NIX_TXSCH_LVL_TL1;
2918 rc = nix_tm_node_add_to_list(dev, def, RTE_TM_NODE_ID_NULL, 0,
2921 OTX2_TM_LVL_ROOT, false, ¶ms);
2924 rc = nix_tm_node_add_to_list(dev, def + 1, def, 0,
2927 OTX2_TM_LVL_SCH1, false, ¶ms);
2930 rc = nix_tm_node_add_to_list(dev, def + 2, def + 1, 0,
2933 OTX2_TM_LVL_SCH2, false, ¶ms);
2936 rc = nix_tm_node_add_to_list(dev, def + 3, def + 2, 0,
2939 OTX2_TM_LVL_SCH3, false, ¶ms);
2942 leaf_parent = def + 3;
2944 /* Add per queue SMQ nodes */
2945 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
2946 rc = nix_tm_node_add_to_list(dev, leaf_parent + 1 + i,
2948 0, DEFAULT_RR_WEIGHT,
2956 /* Add leaf nodes */
2957 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
2958 rc = nix_tm_node_add_to_list(dev, i,
2959 leaf_parent + 1 + i, 0,
2971 dev->otx2_tm_root_lvl = NIX_TXSCH_LVL_TL2;
2972 rc = nix_tm_node_add_to_list(dev, def, RTE_TM_NODE_ID_NULL, 0,
2973 DEFAULT_RR_WEIGHT, NIX_TXSCH_LVL_TL2,
2974 OTX2_TM_LVL_ROOT, false, ¶ms);
2977 rc = nix_tm_node_add_to_list(dev, def + 1, def, 0,
2978 DEFAULT_RR_WEIGHT, NIX_TXSCH_LVL_TL3,
2979 OTX2_TM_LVL_SCH1, false, ¶ms);
2982 rc = nix_tm_node_add_to_list(dev, def + 2, def + 1, 0,
2983 DEFAULT_RR_WEIGHT, NIX_TXSCH_LVL_TL4,
2984 OTX2_TM_LVL_SCH2, false, ¶ms);
2987 leaf_parent = def + 2;
2989 /* Add per queue SMQ nodes */
2990 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
2991 rc = nix_tm_node_add_to_list(dev, leaf_parent + 1 + i,
2993 0, DEFAULT_RR_WEIGHT,
3001 /* Add leaf nodes */
3002 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
3003 rc = nix_tm_node_add_to_list(dev, i, leaf_parent + 1 + i, 0,
3016 otx2_nix_tm_rate_limit_mdq(struct rte_eth_dev *eth_dev,
3017 struct otx2_nix_tm_node *tm_node,
3020 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
3021 struct otx2_nix_tm_shaper_profile profile;
3022 struct otx2_mbox *mbox = dev->mbox;
3023 volatile uint64_t *reg, *regval;
3024 struct nix_txschq_config *req;
3029 flags = tm_node->flags;
3031 req = otx2_mbox_alloc_msg_nix_txschq_cfg(mbox);
3032 req->lvl = NIX_TXSCH_LVL_MDQ;
3034 regval = req->regval;
3037 k += prepare_tm_sw_xoff(tm_node, true, ®[k], ®val[k]);
3038 flags &= ~NIX_TM_NODE_ENABLED;
3042 if (!(flags & NIX_TM_NODE_ENABLED)) {
3043 k += prepare_tm_sw_xoff(tm_node, false, ®[k], ®val[k]);
3044 flags |= NIX_TM_NODE_ENABLED;
3047 /* Use only PIR for rate limit */
3048 memset(&profile, 0, sizeof(profile));
3049 profile.params.peak.rate = tx_rate;
3050 /* Minimum burst of ~4us Bytes of Tx */
3051 profile.params.peak.size = RTE_MAX(NIX_MAX_HW_FRS,
3052 (4ull * tx_rate) / (1E6 * 8));
3053 if (!dev->tm_rate_min || dev->tm_rate_min > tx_rate)
3054 dev->tm_rate_min = tx_rate;
3056 k += prepare_tm_shaper_reg(tm_node, &profile, ®[k], ®val[k]);
3059 rc = otx2_mbox_process(mbox);
3063 tm_node->flags = flags;
3068 otx2_nix_tm_set_queue_rate_limit(struct rte_eth_dev *eth_dev,
3069 uint16_t queue_idx, uint16_t tx_rate_mbps)
3071 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
3072 uint64_t tx_rate = tx_rate_mbps * (uint64_t)1E6;
3073 struct otx2_nix_tm_node *tm_node;
3076 /* Check for supported revisions */
3077 if (otx2_dev_is_95xx_Ax(dev) ||
3078 otx2_dev_is_96xx_Ax(dev))
3081 if (queue_idx >= eth_dev->data->nb_tx_queues)
3084 if (!(dev->tm_flags & NIX_TM_DEFAULT_TREE) &&
3085 !(dev->tm_flags & NIX_TM_RATE_LIMIT_TREE))
3088 if ((dev->tm_flags & NIX_TM_DEFAULT_TREE) &&
3089 eth_dev->data->nb_tx_queues > 1) {
3090 /* For TM topology change ethdev needs to be stopped */
3091 if (eth_dev->data->dev_started)
3095 * Disable xmit will be enabled when
3096 * new topology is available.
3098 rc = nix_xmit_disable(eth_dev);
3100 otx2_err("failed to disable TX, rc=%d", rc);
3104 rc = nix_tm_free_resources(dev, 0, 0, false);
3106 otx2_tm_dbg("failed to free default resources, rc %d",
3111 rc = nix_tm_prepare_rate_limited_tree(eth_dev);
3113 otx2_tm_dbg("failed to prepare tm tree, rc=%d", rc);
3117 rc = nix_tm_alloc_resources(eth_dev, true);
3119 otx2_tm_dbg("failed to allocate tm tree, rc=%d", rc);
3123 dev->tm_flags &= ~NIX_TM_DEFAULT_TREE;
3124 dev->tm_flags |= NIX_TM_RATE_LIMIT_TREE;
3127 tm_node = nix_tm_node_search(dev, queue_idx, false);
3129 /* check if we found a valid leaf node */
3131 !nix_tm_is_leaf(dev, tm_node->lvl) ||
3133 tm_node->parent->hw_id == UINT32_MAX)
3136 return otx2_nix_tm_rate_limit_mdq(eth_dev, tm_node->parent, tx_rate);
3138 otx2_tm_dbg("Unsupported TM tree 0x%0x", dev->tm_flags);
3143 otx2_nix_tm_ops_get(struct rte_eth_dev *eth_dev, void *arg)
3145 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
3150 /* Check for supported revisions */
3151 if (otx2_dev_is_95xx_Ax(dev) ||
3152 otx2_dev_is_96xx_Ax(dev))
3155 *(const void **)arg = &otx2_tm_ops;
3161 otx2_nix_tm_fini(struct rte_eth_dev *eth_dev)
3163 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
3166 /* Xmit is assumed to be disabled */
3167 /* Free up resources already held */
3168 rc = nix_tm_free_resources(dev, 0, 0, false);
3170 otx2_err("Failed to freeup existing resources,rc=%d", rc);
3174 /* Clear shaper profiles */
3175 nix_tm_clear_shaper_profiles(dev);
3182 otx2_nix_tm_get_leaf_data(struct otx2_eth_dev *dev, uint16_t sq,
3183 uint32_t *rr_quantum, uint16_t *smq)
3185 struct otx2_nix_tm_node *tm_node;
3188 /* 0..sq_cnt-1 are leaf nodes */
3189 if (sq >= dev->tm_leaf_cnt)
3192 /* Search for internal node first */
3193 tm_node = nix_tm_node_search(dev, sq, false);
3195 tm_node = nix_tm_node_search(dev, sq, true);
3197 /* Check if we found a valid leaf node */
3198 if (!tm_node || !nix_tm_is_leaf(dev, tm_node->lvl) ||
3199 !tm_node->parent || tm_node->parent->hw_id == UINT32_MAX) {
3203 /* Get SMQ Id of leaf node's parent */
3204 *smq = tm_node->parent->hw_id;
3205 *rr_quantum = NIX_TM_WEIGHT_TO_RR_QUANTUM(tm_node->weight);
3207 rc = nix_smq_xoff(dev, tm_node->parent, false);
3210 tm_node->flags |= NIX_TM_NODE_ENABLED;