1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
9 #include <rte_malloc.h>
10 #include <rte_string_fns.h>
12 #include "rte_eth_softnic_internals.h"
13 #include "rte_eth_softnic.h"
15 #define SUBPORT_TC_PERIOD 10
16 #define PIPE_TC_PERIOD 40
19 softnic_tmgr_init(struct pmd_internals *p)
21 TAILQ_INIT(&p->tmgr_port_list);
27 softnic_tmgr_free(struct pmd_internals *p)
30 struct softnic_tmgr_port *tmgr_port;
32 tmgr_port = TAILQ_FIRST(&p->tmgr_port_list);
33 if (tmgr_port == NULL)
36 TAILQ_REMOVE(&p->tmgr_port_list, tmgr_port, node);
37 rte_sched_port_free(tmgr_port->s);
42 struct softnic_tmgr_port *
43 softnic_tmgr_port_find(struct pmd_internals *p,
46 struct softnic_tmgr_port *tmgr_port;
51 TAILQ_FOREACH(tmgr_port, &p->tmgr_port_list, node)
52 if (strcmp(tmgr_port->name, name) == 0)
58 struct softnic_tmgr_port *
59 softnic_tmgr_port_create(struct pmd_internals *p,
62 struct softnic_tmgr_port *tmgr_port;
63 struct tm_params *t = &p->soft.tm.params;
64 struct rte_sched_port *sched;
65 uint32_t n_subports, subport_id;
67 /* Check input params */
69 softnic_tmgr_port_find(p, name))
76 /* Is hierarchy frozen? */
77 if (p->soft.tm.hierarchy_frozen == 0)
81 sched = rte_sched_port_config(&t->port_params);
86 n_subports = t->port_params.n_subports_per_port;
87 for (subport_id = 0; subport_id < n_subports; subport_id++) {
88 uint32_t n_pipes_per_subport = t->port_params.n_pipes_per_subport;
92 status = rte_sched_subport_config(sched,
94 &t->subport_params[subport_id]);
96 rte_sched_port_free(sched);
101 for (pipe_id = 0; pipe_id < n_pipes_per_subport; pipe_id++) {
102 int pos = subport_id * TM_MAX_PIPES_PER_SUBPORT + pipe_id;
103 int profile_id = t->pipe_to_profile[pos];
108 status = rte_sched_pipe_config(sched,
113 rte_sched_port_free(sched);
119 /* Node allocation */
120 tmgr_port = calloc(1, sizeof(struct softnic_tmgr_port));
121 if (tmgr_port == NULL) {
122 rte_sched_port_free(sched);
127 strlcpy(tmgr_port->name, name, sizeof(tmgr_port->name));
128 tmgr_port->s = sched;
130 /* Node add to list */
131 TAILQ_INSERT_TAIL(&p->tmgr_port_list, tmgr_port, node);
136 static struct rte_sched_port *
137 SCHED(struct pmd_internals *p)
139 struct softnic_tmgr_port *tmgr_port;
141 tmgr_port = softnic_tmgr_port_find(p, "TMGR");
142 if (tmgr_port == NULL)
149 tm_hierarchy_init(struct pmd_internals *p)
151 memset(&p->soft.tm, 0, sizeof(p->soft.tm));
153 /* Initialize shaper profile list */
154 TAILQ_INIT(&p->soft.tm.h.shaper_profiles);
156 /* Initialize shared shaper list */
157 TAILQ_INIT(&p->soft.tm.h.shared_shapers);
159 /* Initialize wred profile list */
160 TAILQ_INIT(&p->soft.tm.h.wred_profiles);
162 /* Initialize TM node list */
163 TAILQ_INIT(&p->soft.tm.h.nodes);
167 tm_hierarchy_free(struct pmd_internals *p)
169 /* Remove all nodes*/
171 struct tm_node *tm_node;
173 tm_node = TAILQ_FIRST(&p->soft.tm.h.nodes);
177 TAILQ_REMOVE(&p->soft.tm.h.nodes, tm_node, node);
181 /* Remove all WRED profiles */
183 struct tm_wred_profile *wred_profile;
185 wred_profile = TAILQ_FIRST(&p->soft.tm.h.wred_profiles);
186 if (wred_profile == NULL)
189 TAILQ_REMOVE(&p->soft.tm.h.wred_profiles, wred_profile, node);
193 /* Remove all shared shapers */
195 struct tm_shared_shaper *shared_shaper;
197 shared_shaper = TAILQ_FIRST(&p->soft.tm.h.shared_shapers);
198 if (shared_shaper == NULL)
201 TAILQ_REMOVE(&p->soft.tm.h.shared_shapers, shared_shaper, node);
205 /* Remove all shaper profiles */
207 struct tm_shaper_profile *shaper_profile;
209 shaper_profile = TAILQ_FIRST(&p->soft.tm.h.shaper_profiles);
210 if (shaper_profile == NULL)
213 TAILQ_REMOVE(&p->soft.tm.h.shaper_profiles,
214 shaper_profile, node);
215 free(shaper_profile);
218 tm_hierarchy_init(p);
221 static struct tm_shaper_profile *
222 tm_shaper_profile_search(struct rte_eth_dev *dev, uint32_t shaper_profile_id)
224 struct pmd_internals *p = dev->data->dev_private;
225 struct tm_shaper_profile_list *spl = &p->soft.tm.h.shaper_profiles;
226 struct tm_shaper_profile *sp;
228 TAILQ_FOREACH(sp, spl, node)
229 if (shaper_profile_id == sp->shaper_profile_id)
235 static struct tm_shared_shaper *
236 tm_shared_shaper_search(struct rte_eth_dev *dev, uint32_t shared_shaper_id)
238 struct pmd_internals *p = dev->data->dev_private;
239 struct tm_shared_shaper_list *ssl = &p->soft.tm.h.shared_shapers;
240 struct tm_shared_shaper *ss;
242 TAILQ_FOREACH(ss, ssl, node)
243 if (shared_shaper_id == ss->shared_shaper_id)
249 static struct tm_wred_profile *
250 tm_wred_profile_search(struct rte_eth_dev *dev, uint32_t wred_profile_id)
252 struct pmd_internals *p = dev->data->dev_private;
253 struct tm_wred_profile_list *wpl = &p->soft.tm.h.wred_profiles;
254 struct tm_wred_profile *wp;
256 TAILQ_FOREACH(wp, wpl, node)
257 if (wred_profile_id == wp->wred_profile_id)
263 static struct tm_node *
264 tm_node_search(struct rte_eth_dev *dev, uint32_t node_id)
266 struct pmd_internals *p = dev->data->dev_private;
267 struct tm_node_list *nl = &p->soft.tm.h.nodes;
270 TAILQ_FOREACH(n, nl, node)
271 if (n->node_id == node_id)
277 static struct tm_node *
278 tm_root_node_present(struct rte_eth_dev *dev)
280 struct pmd_internals *p = dev->data->dev_private;
281 struct tm_node_list *nl = &p->soft.tm.h.nodes;
284 TAILQ_FOREACH(n, nl, node)
285 if (n->parent_node_id == RTE_TM_NODE_ID_NULL)
292 tm_node_subport_id(struct rte_eth_dev *dev, struct tm_node *subport_node)
294 struct pmd_internals *p = dev->data->dev_private;
295 struct tm_node_list *nl = &p->soft.tm.h.nodes;
300 TAILQ_FOREACH(ns, nl, node) {
301 if (ns->level != TM_NODE_LEVEL_SUBPORT)
304 if (ns->node_id == subport_node->node_id)
314 tm_node_pipe_id(struct rte_eth_dev *dev, struct tm_node *pipe_node)
316 struct pmd_internals *p = dev->data->dev_private;
317 struct tm_node_list *nl = &p->soft.tm.h.nodes;
322 TAILQ_FOREACH(np, nl, node) {
323 if (np->level != TM_NODE_LEVEL_PIPE ||
324 np->parent_node_id != pipe_node->parent_node_id)
327 if (np->node_id == pipe_node->node_id)
337 tm_node_tc_id(struct rte_eth_dev *dev __rte_unused, struct tm_node *tc_node)
339 return tc_node->priority;
343 tm_node_queue_id(struct rte_eth_dev *dev, struct tm_node *queue_node)
345 struct pmd_internals *p = dev->data->dev_private;
346 struct tm_node_list *nl = &p->soft.tm.h.nodes;
351 TAILQ_FOREACH(nq, nl, node) {
352 if (nq->level != TM_NODE_LEVEL_QUEUE ||
353 nq->parent_node_id != queue_node->parent_node_id)
356 if (nq->node_id == queue_node->node_id)
366 tm_level_get_max_nodes(struct rte_eth_dev *dev, enum tm_node_level level)
368 struct pmd_internals *p = dev->data->dev_private;
369 uint32_t n_queues_max = p->params.tm.n_queues;
370 uint32_t n_tc_max = n_queues_max / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS;
371 uint32_t n_pipes_max = n_tc_max / RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE;
372 uint32_t n_subports_max = n_pipes_max;
373 uint32_t n_root_max = 1;
376 case TM_NODE_LEVEL_PORT:
378 case TM_NODE_LEVEL_SUBPORT:
379 return n_subports_max;
380 case TM_NODE_LEVEL_PIPE:
382 case TM_NODE_LEVEL_TC:
384 case TM_NODE_LEVEL_QUEUE:
390 /* Traffic manager node type get */
392 pmd_tm_node_type_get(struct rte_eth_dev *dev,
395 struct rte_tm_error *error)
397 struct pmd_internals *p = dev->data->dev_private;
400 return -rte_tm_error_set(error,
402 RTE_TM_ERROR_TYPE_UNSPECIFIED,
404 rte_strerror(EINVAL));
406 if (node_id == RTE_TM_NODE_ID_NULL ||
407 (tm_node_search(dev, node_id) == NULL))
408 return -rte_tm_error_set(error,
410 RTE_TM_ERROR_TYPE_NODE_ID,
412 rte_strerror(EINVAL));
414 *is_leaf = node_id < p->params.tm.n_queues;
420 #define WRED_SUPPORTED 1
422 #define WRED_SUPPORTED 0
425 #define STATS_MASK_DEFAULT \
426 (RTE_TM_STATS_N_PKTS | \
427 RTE_TM_STATS_N_BYTES | \
428 RTE_TM_STATS_N_PKTS_GREEN_DROPPED | \
429 RTE_TM_STATS_N_BYTES_GREEN_DROPPED)
431 #define STATS_MASK_QUEUE \
432 (STATS_MASK_DEFAULT | \
433 RTE_TM_STATS_N_PKTS_QUEUED)
435 static const struct rte_tm_capabilities tm_cap = {
436 .n_nodes_max = UINT32_MAX,
437 .n_levels_max = TM_NODE_LEVEL_MAX,
439 .non_leaf_nodes_identical = 0,
440 .leaf_nodes_identical = 1,
442 .shaper_n_max = UINT32_MAX,
443 .shaper_private_n_max = UINT32_MAX,
444 .shaper_private_dual_rate_n_max = 0,
445 .shaper_private_rate_min = 1,
446 .shaper_private_rate_max = UINT32_MAX,
448 .shaper_shared_n_max = UINT32_MAX,
449 .shaper_shared_n_nodes_per_shaper_max = UINT32_MAX,
450 .shaper_shared_n_shapers_per_node_max = 1,
451 .shaper_shared_dual_rate_n_max = 0,
452 .shaper_shared_rate_min = 1,
453 .shaper_shared_rate_max = UINT32_MAX,
455 .shaper_pkt_length_adjust_min = RTE_TM_ETH_FRAMING_OVERHEAD_FCS,
456 .shaper_pkt_length_adjust_max = RTE_TM_ETH_FRAMING_OVERHEAD_FCS,
458 .sched_n_children_max = UINT32_MAX,
459 .sched_sp_n_priorities_max = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
460 .sched_wfq_n_children_per_group_max = UINT32_MAX,
461 .sched_wfq_n_groups_max = 1,
462 .sched_wfq_weight_max = UINT32_MAX,
464 .cman_wred_packet_mode_supported = WRED_SUPPORTED,
465 .cman_wred_byte_mode_supported = 0,
466 .cman_head_drop_supported = 0,
467 .cman_wred_context_n_max = 0,
468 .cman_wred_context_private_n_max = 0,
469 .cman_wred_context_shared_n_max = 0,
470 .cman_wred_context_shared_n_nodes_per_context_max = 0,
471 .cman_wred_context_shared_n_contexts_per_node_max = 0,
473 .mark_vlan_dei_supported = {0, 0, 0},
474 .mark_ip_ecn_tcp_supported = {0, 0, 0},
475 .mark_ip_ecn_sctp_supported = {0, 0, 0},
476 .mark_ip_dscp_supported = {0, 0, 0},
478 .dynamic_update_mask = 0,
480 .stats_mask = STATS_MASK_QUEUE,
483 /* Traffic manager capabilities get */
485 pmd_tm_capabilities_get(struct rte_eth_dev *dev __rte_unused,
486 struct rte_tm_capabilities *cap,
487 struct rte_tm_error *error)
490 return -rte_tm_error_set(error,
492 RTE_TM_ERROR_TYPE_CAPABILITIES,
494 rte_strerror(EINVAL));
496 memcpy(cap, &tm_cap, sizeof(*cap));
498 cap->n_nodes_max = tm_level_get_max_nodes(dev, TM_NODE_LEVEL_PORT) +
499 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_SUBPORT) +
500 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_PIPE) +
501 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_TC) +
502 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_QUEUE);
504 cap->shaper_private_n_max =
505 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_PORT) +
506 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_SUBPORT) +
507 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_PIPE) +
508 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_TC);
510 cap->shaper_shared_n_max = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE *
511 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_SUBPORT);
513 cap->shaper_n_max = cap->shaper_private_n_max +
514 cap->shaper_shared_n_max;
516 cap->shaper_shared_n_nodes_per_shaper_max =
517 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_PIPE);
519 cap->sched_n_children_max = RTE_MAX(
520 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_PIPE),
521 (uint32_t)RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE);
523 cap->sched_wfq_n_children_per_group_max = cap->sched_n_children_max;
526 cap->cman_wred_context_private_n_max =
527 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_QUEUE);
529 cap->cman_wred_context_n_max = cap->cman_wred_context_private_n_max +
530 cap->cman_wred_context_shared_n_max;
535 static const struct rte_tm_level_capabilities tm_level_cap[] = {
536 [TM_NODE_LEVEL_PORT] = {
538 .n_nodes_nonleaf_max = 1,
539 .n_nodes_leaf_max = 0,
540 .non_leaf_nodes_identical = 1,
541 .leaf_nodes_identical = 0,
544 .shaper_private_supported = 1,
545 .shaper_private_dual_rate_supported = 0,
546 .shaper_private_rate_min = 1,
547 .shaper_private_rate_max = UINT32_MAX,
548 .shaper_shared_n_max = 0,
550 .sched_n_children_max = UINT32_MAX,
551 .sched_sp_n_priorities_max = 1,
552 .sched_wfq_n_children_per_group_max = UINT32_MAX,
553 .sched_wfq_n_groups_max = 1,
554 .sched_wfq_weight_max = 1,
556 .stats_mask = STATS_MASK_DEFAULT,
560 [TM_NODE_LEVEL_SUBPORT] = {
561 .n_nodes_max = UINT32_MAX,
562 .n_nodes_nonleaf_max = UINT32_MAX,
563 .n_nodes_leaf_max = 0,
564 .non_leaf_nodes_identical = 1,
565 .leaf_nodes_identical = 0,
568 .shaper_private_supported = 1,
569 .shaper_private_dual_rate_supported = 0,
570 .shaper_private_rate_min = 1,
571 .shaper_private_rate_max = UINT32_MAX,
572 .shaper_shared_n_max = 0,
574 .sched_n_children_max = UINT32_MAX,
575 .sched_sp_n_priorities_max = 1,
576 .sched_wfq_n_children_per_group_max = UINT32_MAX,
577 .sched_wfq_n_groups_max = 1,
578 #ifdef RTE_SCHED_SUBPORT_TC_OV
579 .sched_wfq_weight_max = UINT32_MAX,
581 .sched_wfq_weight_max = 1,
583 .stats_mask = STATS_MASK_DEFAULT,
587 [TM_NODE_LEVEL_PIPE] = {
588 .n_nodes_max = UINT32_MAX,
589 .n_nodes_nonleaf_max = UINT32_MAX,
590 .n_nodes_leaf_max = 0,
591 .non_leaf_nodes_identical = 1,
592 .leaf_nodes_identical = 0,
595 .shaper_private_supported = 1,
596 .shaper_private_dual_rate_supported = 0,
597 .shaper_private_rate_min = 1,
598 .shaper_private_rate_max = UINT32_MAX,
599 .shaper_shared_n_max = 0,
601 .sched_n_children_max =
602 RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
603 .sched_sp_n_priorities_max =
604 RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
605 .sched_wfq_n_children_per_group_max = 1,
606 .sched_wfq_n_groups_max = 0,
607 .sched_wfq_weight_max = 1,
609 .stats_mask = STATS_MASK_DEFAULT,
613 [TM_NODE_LEVEL_TC] = {
614 .n_nodes_max = UINT32_MAX,
615 .n_nodes_nonleaf_max = UINT32_MAX,
616 .n_nodes_leaf_max = 0,
617 .non_leaf_nodes_identical = 1,
618 .leaf_nodes_identical = 0,
621 .shaper_private_supported = 1,
622 .shaper_private_dual_rate_supported = 0,
623 .shaper_private_rate_min = 1,
624 .shaper_private_rate_max = UINT32_MAX,
625 .shaper_shared_n_max = 1,
627 .sched_n_children_max =
628 RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
629 .sched_sp_n_priorities_max = 1,
630 .sched_wfq_n_children_per_group_max =
631 RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
632 .sched_wfq_n_groups_max = 1,
633 .sched_wfq_weight_max = UINT32_MAX,
635 .stats_mask = STATS_MASK_DEFAULT,
639 [TM_NODE_LEVEL_QUEUE] = {
640 .n_nodes_max = UINT32_MAX,
641 .n_nodes_nonleaf_max = 0,
642 .n_nodes_leaf_max = UINT32_MAX,
643 .non_leaf_nodes_identical = 0,
644 .leaf_nodes_identical = 1,
647 .shaper_private_supported = 0,
648 .shaper_private_dual_rate_supported = 0,
649 .shaper_private_rate_min = 0,
650 .shaper_private_rate_max = 0,
651 .shaper_shared_n_max = 0,
653 .cman_head_drop_supported = 0,
654 .cman_wred_packet_mode_supported = WRED_SUPPORTED,
655 .cman_wred_byte_mode_supported = 0,
656 .cman_wred_context_private_supported = WRED_SUPPORTED,
657 .cman_wred_context_shared_n_max = 0,
659 .stats_mask = STATS_MASK_QUEUE,
664 /* Traffic manager level capabilities get */
666 pmd_tm_level_capabilities_get(struct rte_eth_dev *dev __rte_unused,
668 struct rte_tm_level_capabilities *cap,
669 struct rte_tm_error *error)
672 return -rte_tm_error_set(error,
674 RTE_TM_ERROR_TYPE_CAPABILITIES,
676 rte_strerror(EINVAL));
678 if (level_id >= TM_NODE_LEVEL_MAX)
679 return -rte_tm_error_set(error,
681 RTE_TM_ERROR_TYPE_LEVEL_ID,
683 rte_strerror(EINVAL));
685 memcpy(cap, &tm_level_cap[level_id], sizeof(*cap));
688 case TM_NODE_LEVEL_PORT:
689 cap->nonleaf.sched_n_children_max =
690 tm_level_get_max_nodes(dev,
691 TM_NODE_LEVEL_SUBPORT);
692 cap->nonleaf.sched_wfq_n_children_per_group_max =
693 cap->nonleaf.sched_n_children_max;
696 case TM_NODE_LEVEL_SUBPORT:
697 cap->n_nodes_max = tm_level_get_max_nodes(dev,
698 TM_NODE_LEVEL_SUBPORT);
699 cap->n_nodes_nonleaf_max = cap->n_nodes_max;
700 cap->nonleaf.sched_n_children_max =
701 tm_level_get_max_nodes(dev,
703 cap->nonleaf.sched_wfq_n_children_per_group_max =
704 cap->nonleaf.sched_n_children_max;
707 case TM_NODE_LEVEL_PIPE:
708 cap->n_nodes_max = tm_level_get_max_nodes(dev,
710 cap->n_nodes_nonleaf_max = cap->n_nodes_max;
713 case TM_NODE_LEVEL_TC:
714 cap->n_nodes_max = tm_level_get_max_nodes(dev,
716 cap->n_nodes_nonleaf_max = cap->n_nodes_max;
719 case TM_NODE_LEVEL_QUEUE:
721 cap->n_nodes_max = tm_level_get_max_nodes(dev,
722 TM_NODE_LEVEL_QUEUE);
723 cap->n_nodes_leaf_max = cap->n_nodes_max;
730 static const struct rte_tm_node_capabilities tm_node_cap[] = {
731 [TM_NODE_LEVEL_PORT] = {
732 .shaper_private_supported = 1,
733 .shaper_private_dual_rate_supported = 0,
734 .shaper_private_rate_min = 1,
735 .shaper_private_rate_max = UINT32_MAX,
736 .shaper_shared_n_max = 0,
739 .sched_n_children_max = UINT32_MAX,
740 .sched_sp_n_priorities_max = 1,
741 .sched_wfq_n_children_per_group_max = UINT32_MAX,
742 .sched_wfq_n_groups_max = 1,
743 .sched_wfq_weight_max = 1,
746 .stats_mask = STATS_MASK_DEFAULT,
749 [TM_NODE_LEVEL_SUBPORT] = {
750 .shaper_private_supported = 1,
751 .shaper_private_dual_rate_supported = 0,
752 .shaper_private_rate_min = 1,
753 .shaper_private_rate_max = UINT32_MAX,
754 .shaper_shared_n_max = 0,
757 .sched_n_children_max = UINT32_MAX,
758 .sched_sp_n_priorities_max = 1,
759 .sched_wfq_n_children_per_group_max = UINT32_MAX,
760 .sched_wfq_n_groups_max = 1,
761 .sched_wfq_weight_max = UINT32_MAX,
764 .stats_mask = STATS_MASK_DEFAULT,
767 [TM_NODE_LEVEL_PIPE] = {
768 .shaper_private_supported = 1,
769 .shaper_private_dual_rate_supported = 0,
770 .shaper_private_rate_min = 1,
771 .shaper_private_rate_max = UINT32_MAX,
772 .shaper_shared_n_max = 0,
775 .sched_n_children_max =
776 RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
777 .sched_sp_n_priorities_max =
778 RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
779 .sched_wfq_n_children_per_group_max = 1,
780 .sched_wfq_n_groups_max = 0,
781 .sched_wfq_weight_max = 1,
784 .stats_mask = STATS_MASK_DEFAULT,
787 [TM_NODE_LEVEL_TC] = {
788 .shaper_private_supported = 1,
789 .shaper_private_dual_rate_supported = 0,
790 .shaper_private_rate_min = 1,
791 .shaper_private_rate_max = UINT32_MAX,
792 .shaper_shared_n_max = 1,
795 .sched_n_children_max =
796 RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
797 .sched_sp_n_priorities_max = 1,
798 .sched_wfq_n_children_per_group_max =
799 RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
800 .sched_wfq_n_groups_max = 1,
801 .sched_wfq_weight_max = UINT32_MAX,
804 .stats_mask = STATS_MASK_DEFAULT,
807 [TM_NODE_LEVEL_QUEUE] = {
808 .shaper_private_supported = 0,
809 .shaper_private_dual_rate_supported = 0,
810 .shaper_private_rate_min = 0,
811 .shaper_private_rate_max = 0,
812 .shaper_shared_n_max = 0,
816 .cman_head_drop_supported = 0,
817 .cman_wred_packet_mode_supported = WRED_SUPPORTED,
818 .cman_wred_byte_mode_supported = 0,
819 .cman_wred_context_private_supported = WRED_SUPPORTED,
820 .cman_wred_context_shared_n_max = 0,
823 .stats_mask = STATS_MASK_QUEUE,
827 /* Traffic manager node capabilities get */
829 pmd_tm_node_capabilities_get(struct rte_eth_dev *dev __rte_unused,
831 struct rte_tm_node_capabilities *cap,
832 struct rte_tm_error *error)
834 struct tm_node *tm_node;
837 return -rte_tm_error_set(error,
839 RTE_TM_ERROR_TYPE_CAPABILITIES,
841 rte_strerror(EINVAL));
843 tm_node = tm_node_search(dev, node_id);
845 return -rte_tm_error_set(error,
847 RTE_TM_ERROR_TYPE_NODE_ID,
849 rte_strerror(EINVAL));
851 memcpy(cap, &tm_node_cap[tm_node->level], sizeof(*cap));
853 switch (tm_node->level) {
854 case TM_NODE_LEVEL_PORT:
855 cap->nonleaf.sched_n_children_max =
856 tm_level_get_max_nodes(dev,
857 TM_NODE_LEVEL_SUBPORT);
858 cap->nonleaf.sched_wfq_n_children_per_group_max =
859 cap->nonleaf.sched_n_children_max;
862 case TM_NODE_LEVEL_SUBPORT:
863 cap->nonleaf.sched_n_children_max =
864 tm_level_get_max_nodes(dev,
866 cap->nonleaf.sched_wfq_n_children_per_group_max =
867 cap->nonleaf.sched_n_children_max;
870 case TM_NODE_LEVEL_PIPE:
871 case TM_NODE_LEVEL_TC:
872 case TM_NODE_LEVEL_QUEUE:
881 shaper_profile_check(struct rte_eth_dev *dev,
882 uint32_t shaper_profile_id,
883 struct rte_tm_shaper_params *profile,
884 struct rte_tm_error *error)
886 struct tm_shaper_profile *sp;
888 /* Shaper profile ID must not be NONE. */
889 if (shaper_profile_id == RTE_TM_SHAPER_PROFILE_ID_NONE)
890 return -rte_tm_error_set(error,
892 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,
894 rte_strerror(EINVAL));
896 /* Shaper profile must not exist. */
897 sp = tm_shaper_profile_search(dev, shaper_profile_id);
899 return -rte_tm_error_set(error,
901 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,
903 rte_strerror(EEXIST));
905 /* Profile must not be NULL. */
907 return -rte_tm_error_set(error,
909 RTE_TM_ERROR_TYPE_SHAPER_PROFILE,
911 rte_strerror(EINVAL));
913 /* Peak rate: non-zero, 32-bit */
914 if (profile->peak.rate == 0 ||
915 profile->peak.rate >= UINT32_MAX)
916 return -rte_tm_error_set(error,
918 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_RATE,
920 rte_strerror(EINVAL));
922 /* Peak size: non-zero, 32-bit */
923 if (profile->peak.size == 0 ||
924 profile->peak.size >= UINT32_MAX)
925 return -rte_tm_error_set(error,
927 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE,
929 rte_strerror(EINVAL));
931 /* Dual-rate profiles are not supported. */
932 if (profile->committed.rate != 0)
933 return -rte_tm_error_set(error,
935 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE,
937 rte_strerror(EINVAL));
939 /* Packet length adjust: 24 bytes */
940 if (profile->pkt_length_adjust != RTE_TM_ETH_FRAMING_OVERHEAD_FCS)
941 return -rte_tm_error_set(error,
943 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PKT_ADJUST_LEN,
945 rte_strerror(EINVAL));
950 /* Traffic manager shaper profile add */
952 pmd_tm_shaper_profile_add(struct rte_eth_dev *dev,
953 uint32_t shaper_profile_id,
954 struct rte_tm_shaper_params *profile,
955 struct rte_tm_error *error)
957 struct pmd_internals *p = dev->data->dev_private;
958 struct tm_shaper_profile_list *spl = &p->soft.tm.h.shaper_profiles;
959 struct tm_shaper_profile *sp;
962 /* Check input params */
963 status = shaper_profile_check(dev, shaper_profile_id, profile, error);
967 /* Memory allocation */
968 sp = calloc(1, sizeof(struct tm_shaper_profile));
970 return -rte_tm_error_set(error,
972 RTE_TM_ERROR_TYPE_UNSPECIFIED,
974 rte_strerror(ENOMEM));
977 sp->shaper_profile_id = shaper_profile_id;
978 memcpy(&sp->params, profile, sizeof(sp->params));
981 TAILQ_INSERT_TAIL(spl, sp, node);
982 p->soft.tm.h.n_shaper_profiles++;
987 /* Traffic manager shaper profile delete */
989 pmd_tm_shaper_profile_delete(struct rte_eth_dev *dev,
990 uint32_t shaper_profile_id,
991 struct rte_tm_error *error)
993 struct pmd_internals *p = dev->data->dev_private;
994 struct tm_shaper_profile *sp;
997 sp = tm_shaper_profile_search(dev, shaper_profile_id);
999 return -rte_tm_error_set(error,
1001 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,
1003 rte_strerror(EINVAL));
1007 return -rte_tm_error_set(error,
1009 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,
1011 rte_strerror(EBUSY));
1013 /* Remove from list */
1014 TAILQ_REMOVE(&p->soft.tm.h.shaper_profiles, sp, node);
1015 p->soft.tm.h.n_shaper_profiles--;
1021 static struct tm_node *
1022 tm_shared_shaper_get_tc(struct rte_eth_dev *dev,
1023 struct tm_shared_shaper *ss)
1025 struct pmd_internals *p = dev->data->dev_private;
1026 struct tm_node_list *nl = &p->soft.tm.h.nodes;
1029 /* Subport: each TC uses shared shaper */
1030 TAILQ_FOREACH(n, nl, node) {
1031 if (n->level != TM_NODE_LEVEL_TC ||
1032 n->params.n_shared_shapers == 0 ||
1033 n->params.shared_shaper_id[0] != ss->shared_shaper_id)
1043 update_subport_tc_rate(struct rte_eth_dev *dev,
1045 struct tm_shared_shaper *ss,
1046 struct tm_shaper_profile *sp_new)
1048 struct pmd_internals *p = dev->data->dev_private;
1049 uint32_t tc_id = tm_node_tc_id(dev, nt);
1051 struct tm_node *np = nt->parent_node;
1053 struct tm_node *ns = np->parent_node;
1054 uint32_t subport_id = tm_node_subport_id(dev, ns);
1056 struct rte_sched_subport_params subport_params;
1058 struct tm_shaper_profile *sp_old = tm_shaper_profile_search(dev,
1059 ss->shaper_profile_id);
1061 /* Derive new subport configuration. */
1062 memcpy(&subport_params,
1063 &p->soft.tm.params.subport_params[subport_id],
1064 sizeof(subport_params));
1065 subport_params.tc_rate[tc_id] = sp_new->params.peak.rate;
1067 /* Update the subport configuration. */
1068 if (rte_sched_subport_config(SCHED(p),
1069 subport_id, &subport_params))
1072 /* Commit changes. */
1075 ss->shaper_profile_id = sp_new->shaper_profile_id;
1078 memcpy(&p->soft.tm.params.subport_params[subport_id],
1080 sizeof(subport_params));
1085 /* Traffic manager shared shaper add/update */
1087 pmd_tm_shared_shaper_add_update(struct rte_eth_dev *dev,
1088 uint32_t shared_shaper_id,
1089 uint32_t shaper_profile_id,
1090 struct rte_tm_error *error)
1092 struct pmd_internals *p = dev->data->dev_private;
1093 struct tm_shared_shaper *ss;
1094 struct tm_shaper_profile *sp;
1097 /* Shaper profile must be valid. */
1098 sp = tm_shaper_profile_search(dev, shaper_profile_id);
1100 return -rte_tm_error_set(error,
1102 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,
1104 rte_strerror(EINVAL));
1107 * Add new shared shaper
1109 ss = tm_shared_shaper_search(dev, shared_shaper_id);
1111 struct tm_shared_shaper_list *ssl =
1112 &p->soft.tm.h.shared_shapers;
1114 /* Hierarchy must not be frozen */
1115 if (p->soft.tm.hierarchy_frozen)
1116 return -rte_tm_error_set(error,
1118 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1120 rte_strerror(EBUSY));
1122 /* Memory allocation */
1123 ss = calloc(1, sizeof(struct tm_shared_shaper));
1125 return -rte_tm_error_set(error,
1127 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1129 rte_strerror(ENOMEM));
1132 ss->shared_shaper_id = shared_shaper_id;
1133 ss->shaper_profile_id = shaper_profile_id;
1136 TAILQ_INSERT_TAIL(ssl, ss, node);
1137 p->soft.tm.h.n_shared_shapers++;
1143 * Update existing shared shaper
1145 /* Hierarchy must be frozen (run-time update) */
1146 if (p->soft.tm.hierarchy_frozen == 0)
1147 return -rte_tm_error_set(error,
1149 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1151 rte_strerror(EBUSY));
1154 /* Propagate change. */
1155 nt = tm_shared_shaper_get_tc(dev, ss);
1156 if (update_subport_tc_rate(dev, nt, ss, sp))
1157 return -rte_tm_error_set(error,
1159 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1161 rte_strerror(EINVAL));
1166 /* Traffic manager shared shaper delete */
1168 pmd_tm_shared_shaper_delete(struct rte_eth_dev *dev,
1169 uint32_t shared_shaper_id,
1170 struct rte_tm_error *error)
1172 struct pmd_internals *p = dev->data->dev_private;
1173 struct tm_shared_shaper *ss;
1175 /* Check existing */
1176 ss = tm_shared_shaper_search(dev, shared_shaper_id);
1178 return -rte_tm_error_set(error,
1180 RTE_TM_ERROR_TYPE_SHARED_SHAPER_ID,
1182 rte_strerror(EINVAL));
1186 return -rte_tm_error_set(error,
1188 RTE_TM_ERROR_TYPE_SHARED_SHAPER_ID,
1190 rte_strerror(EBUSY));
1192 /* Remove from list */
1193 TAILQ_REMOVE(&p->soft.tm.h.shared_shapers, ss, node);
1194 p->soft.tm.h.n_shared_shapers--;
1201 wred_profile_check(struct rte_eth_dev *dev,
1202 uint32_t wred_profile_id,
1203 struct rte_tm_wred_params *profile,
1204 struct rte_tm_error *error)
1206 struct tm_wred_profile *wp;
1207 enum rte_color color;
1209 /* WRED profile ID must not be NONE. */
1210 if (wred_profile_id == RTE_TM_WRED_PROFILE_ID_NONE)
1211 return -rte_tm_error_set(error,
1213 RTE_TM_ERROR_TYPE_WRED_PROFILE_ID,
1215 rte_strerror(EINVAL));
1217 /* WRED profile must not exist. */
1218 wp = tm_wred_profile_search(dev, wred_profile_id);
1220 return -rte_tm_error_set(error,
1222 RTE_TM_ERROR_TYPE_WRED_PROFILE_ID,
1224 rte_strerror(EEXIST));
1226 /* Profile must not be NULL. */
1227 if (profile == NULL)
1228 return -rte_tm_error_set(error,
1230 RTE_TM_ERROR_TYPE_WRED_PROFILE,
1232 rte_strerror(EINVAL));
1234 /* WRED profile should be in packet mode */
1235 if (profile->packet_mode == 0)
1236 return -rte_tm_error_set(error,
1238 RTE_TM_ERROR_TYPE_WRED_PROFILE,
1240 rte_strerror(ENOTSUP));
1242 /* min_th <= max_th, max_th > 0 */
1243 for (color = RTE_COLOR_GREEN; color < RTE_COLORS; color++) {
1244 uint32_t min_th = profile->red_params[color].min_th;
1245 uint32_t max_th = profile->red_params[color].max_th;
1247 if (min_th > max_th ||
1249 min_th > UINT16_MAX ||
1250 max_th > UINT16_MAX)
1251 return -rte_tm_error_set(error,
1253 RTE_TM_ERROR_TYPE_WRED_PROFILE,
1255 rte_strerror(EINVAL));
1261 /* Traffic manager WRED profile add */
1263 pmd_tm_wred_profile_add(struct rte_eth_dev *dev,
1264 uint32_t wred_profile_id,
1265 struct rte_tm_wred_params *profile,
1266 struct rte_tm_error *error)
1268 struct pmd_internals *p = dev->data->dev_private;
1269 struct tm_wred_profile_list *wpl = &p->soft.tm.h.wred_profiles;
1270 struct tm_wred_profile *wp;
1273 /* Check input params */
1274 status = wred_profile_check(dev, wred_profile_id, profile, error);
1278 /* Memory allocation */
1279 wp = calloc(1, sizeof(struct tm_wred_profile));
1281 return -rte_tm_error_set(error,
1283 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1285 rte_strerror(ENOMEM));
1288 wp->wred_profile_id = wred_profile_id;
1289 memcpy(&wp->params, profile, sizeof(wp->params));
1292 TAILQ_INSERT_TAIL(wpl, wp, node);
1293 p->soft.tm.h.n_wred_profiles++;
1298 /* Traffic manager WRED profile delete */
1300 pmd_tm_wred_profile_delete(struct rte_eth_dev *dev,
1301 uint32_t wred_profile_id,
1302 struct rte_tm_error *error)
1304 struct pmd_internals *p = dev->data->dev_private;
1305 struct tm_wred_profile *wp;
1307 /* Check existing */
1308 wp = tm_wred_profile_search(dev, wred_profile_id);
1310 return -rte_tm_error_set(error,
1312 RTE_TM_ERROR_TYPE_WRED_PROFILE_ID,
1314 rte_strerror(EINVAL));
1318 return -rte_tm_error_set(error,
1320 RTE_TM_ERROR_TYPE_WRED_PROFILE_ID,
1322 rte_strerror(EBUSY));
1324 /* Remove from list */
1325 TAILQ_REMOVE(&p->soft.tm.h.wred_profiles, wp, node);
1326 p->soft.tm.h.n_wred_profiles--;
1333 node_add_check_port(struct rte_eth_dev *dev,
1335 uint32_t parent_node_id __rte_unused,
1338 uint32_t level_id __rte_unused,
1339 struct rte_tm_node_params *params,
1340 struct rte_tm_error *error)
1342 struct pmd_internals *p = dev->data->dev_private;
1343 struct tm_shaper_profile *sp = tm_shaper_profile_search(dev,
1344 params->shaper_profile_id);
1346 /* node type: non-leaf */
1347 if (node_id < p->params.tm.n_queues)
1348 return -rte_tm_error_set(error,
1350 RTE_TM_ERROR_TYPE_NODE_ID,
1352 rte_strerror(EINVAL));
1354 /* Priority must be 0 */
1356 return -rte_tm_error_set(error,
1358 RTE_TM_ERROR_TYPE_NODE_PRIORITY,
1360 rte_strerror(EINVAL));
1362 /* Weight must be 1 */
1364 return -rte_tm_error_set(error,
1366 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
1368 rte_strerror(EINVAL));
1370 /* Shaper must be valid */
1371 if (params->shaper_profile_id == RTE_TM_SHAPER_PROFILE_ID_NONE ||
1373 return -rte_tm_error_set(error,
1375 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID,
1377 rte_strerror(EINVAL));
1379 /* No shared shapers */
1380 if (params->n_shared_shapers != 0)
1381 return -rte_tm_error_set(error,
1383 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS,
1385 rte_strerror(EINVAL));
1387 /* Number of SP priorities must be 1 */
1388 if (params->nonleaf.n_sp_priorities != 1)
1389 return -rte_tm_error_set(error,
1391 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES,
1393 rte_strerror(EINVAL));
1396 if (params->stats_mask & ~STATS_MASK_DEFAULT)
1397 return -rte_tm_error_set(error,
1399 RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,
1401 rte_strerror(EINVAL));
1407 node_add_check_subport(struct rte_eth_dev *dev,
1409 uint32_t parent_node_id __rte_unused,
1412 uint32_t level_id __rte_unused,
1413 struct rte_tm_node_params *params,
1414 struct rte_tm_error *error)
1416 struct pmd_internals *p = dev->data->dev_private;
1418 /* node type: non-leaf */
1419 if (node_id < p->params.tm.n_queues)
1420 return -rte_tm_error_set(error,
1422 RTE_TM_ERROR_TYPE_NODE_ID,
1424 rte_strerror(EINVAL));
1426 /* Priority must be 0 */
1428 return -rte_tm_error_set(error,
1430 RTE_TM_ERROR_TYPE_NODE_PRIORITY,
1432 rte_strerror(EINVAL));
1434 /* Weight must be 1 */
1436 return -rte_tm_error_set(error,
1438 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
1440 rte_strerror(EINVAL));
1442 /* Shaper must be valid */
1443 if (params->shaper_profile_id == RTE_TM_SHAPER_PROFILE_ID_NONE ||
1444 (!tm_shaper_profile_search(dev, params->shaper_profile_id)))
1445 return -rte_tm_error_set(error,
1447 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID,
1449 rte_strerror(EINVAL));
1451 /* No shared shapers */
1452 if (params->n_shared_shapers != 0)
1453 return -rte_tm_error_set(error,
1455 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS,
1457 rte_strerror(EINVAL));
1459 /* Number of SP priorities must be 1 */
1460 if (params->nonleaf.n_sp_priorities != 1)
1461 return -rte_tm_error_set(error,
1463 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES,
1465 rte_strerror(EINVAL));
1468 if (params->stats_mask & ~STATS_MASK_DEFAULT)
1469 return -rte_tm_error_set(error,
1471 RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,
1473 rte_strerror(EINVAL));
1479 node_add_check_pipe(struct rte_eth_dev *dev,
1481 uint32_t parent_node_id __rte_unused,
1483 uint32_t weight __rte_unused,
1484 uint32_t level_id __rte_unused,
1485 struct rte_tm_node_params *params,
1486 struct rte_tm_error *error)
1488 struct pmd_internals *p = dev->data->dev_private;
1490 /* node type: non-leaf */
1491 if (node_id < p->params.tm.n_queues)
1492 return -rte_tm_error_set(error,
1494 RTE_TM_ERROR_TYPE_NODE_ID,
1496 rte_strerror(EINVAL));
1498 /* Priority must be 0 */
1500 return -rte_tm_error_set(error,
1502 RTE_TM_ERROR_TYPE_NODE_PRIORITY,
1504 rte_strerror(EINVAL));
1506 /* Shaper must be valid */
1507 if (params->shaper_profile_id == RTE_TM_SHAPER_PROFILE_ID_NONE ||
1508 (!tm_shaper_profile_search(dev, params->shaper_profile_id)))
1509 return -rte_tm_error_set(error,
1511 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID,
1513 rte_strerror(EINVAL));
1515 /* No shared shapers */
1516 if (params->n_shared_shapers != 0)
1517 return -rte_tm_error_set(error,
1519 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS,
1521 rte_strerror(EINVAL));
1523 /* Number of SP priorities must be 4 */
1524 if (params->nonleaf.n_sp_priorities !=
1525 RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1526 return -rte_tm_error_set(error,
1528 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES,
1530 rte_strerror(EINVAL));
1532 /* WFQ mode must be byte mode */
1533 if (params->nonleaf.wfq_weight_mode != NULL &&
1534 params->nonleaf.wfq_weight_mode[0] != 0 &&
1535 params->nonleaf.wfq_weight_mode[1] != 0 &&
1536 params->nonleaf.wfq_weight_mode[2] != 0 &&
1537 params->nonleaf.wfq_weight_mode[3] != 0)
1538 return -rte_tm_error_set(error,
1540 RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE,
1542 rte_strerror(EINVAL));
1545 if (params->stats_mask & ~STATS_MASK_DEFAULT)
1546 return -rte_tm_error_set(error,
1548 RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,
1550 rte_strerror(EINVAL));
1556 node_add_check_tc(struct rte_eth_dev *dev,
1558 uint32_t parent_node_id __rte_unused,
1559 uint32_t priority __rte_unused,
1561 uint32_t level_id __rte_unused,
1562 struct rte_tm_node_params *params,
1563 struct rte_tm_error *error)
1565 struct pmd_internals *p = dev->data->dev_private;
1567 /* node type: non-leaf */
1568 if (node_id < p->params.tm.n_queues)
1569 return -rte_tm_error_set(error,
1571 RTE_TM_ERROR_TYPE_NODE_ID,
1573 rte_strerror(EINVAL));
1575 /* Weight must be 1 */
1577 return -rte_tm_error_set(error,
1579 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
1581 rte_strerror(EINVAL));
1583 /* Shaper must be valid */
1584 if (params->shaper_profile_id == RTE_TM_SHAPER_PROFILE_ID_NONE ||
1585 (!tm_shaper_profile_search(dev, params->shaper_profile_id)))
1586 return -rte_tm_error_set(error,
1588 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID,
1590 rte_strerror(EINVAL));
1592 /* Single valid shared shaper */
1593 if (params->n_shared_shapers > 1)
1594 return -rte_tm_error_set(error,
1596 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS,
1598 rte_strerror(EINVAL));
1600 if (params->n_shared_shapers == 1 &&
1601 (params->shared_shaper_id == NULL ||
1602 (!tm_shared_shaper_search(dev, params->shared_shaper_id[0]))))
1603 return -rte_tm_error_set(error,
1605 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID,
1607 rte_strerror(EINVAL));
1609 /* Number of priorities must be 1 */
1610 if (params->nonleaf.n_sp_priorities != 1)
1611 return -rte_tm_error_set(error,
1613 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES,
1615 rte_strerror(EINVAL));
1618 if (params->stats_mask & ~STATS_MASK_DEFAULT)
1619 return -rte_tm_error_set(error,
1621 RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,
1623 rte_strerror(EINVAL));
1629 node_add_check_queue(struct rte_eth_dev *dev,
1631 uint32_t parent_node_id __rte_unused,
1633 uint32_t weight __rte_unused,
1634 uint32_t level_id __rte_unused,
1635 struct rte_tm_node_params *params,
1636 struct rte_tm_error *error)
1638 struct pmd_internals *p = dev->data->dev_private;
1640 /* node type: leaf */
1641 if (node_id >= p->params.tm.n_queues)
1642 return -rte_tm_error_set(error,
1644 RTE_TM_ERROR_TYPE_NODE_ID,
1646 rte_strerror(EINVAL));
1648 /* Priority must be 0 */
1650 return -rte_tm_error_set(error,
1652 RTE_TM_ERROR_TYPE_NODE_PRIORITY,
1654 rte_strerror(EINVAL));
1657 if (params->shaper_profile_id != RTE_TM_SHAPER_PROFILE_ID_NONE)
1658 return -rte_tm_error_set(error,
1660 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID,
1662 rte_strerror(EINVAL));
1664 /* No shared shapers */
1665 if (params->n_shared_shapers != 0)
1666 return -rte_tm_error_set(error,
1668 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS,
1670 rte_strerror(EINVAL));
1672 /* Congestion management must not be head drop */
1673 if (params->leaf.cman == RTE_TM_CMAN_HEAD_DROP)
1674 return -rte_tm_error_set(error,
1676 RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN,
1678 rte_strerror(EINVAL));
1680 /* Congestion management set to WRED */
1681 if (params->leaf.cman == RTE_TM_CMAN_WRED) {
1682 uint32_t wred_profile_id = params->leaf.wred.wred_profile_id;
1683 struct tm_wred_profile *wp = tm_wred_profile_search(dev,
1686 /* WRED profile (for private WRED context) must be valid */
1687 if (wred_profile_id == RTE_TM_WRED_PROFILE_ID_NONE ||
1689 return -rte_tm_error_set(error,
1691 RTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID,
1693 rte_strerror(EINVAL));
1695 /* No shared WRED contexts */
1696 if (params->leaf.wred.n_shared_wred_contexts != 0)
1697 return -rte_tm_error_set(error,
1699 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS,
1701 rte_strerror(EINVAL));
1705 if (params->stats_mask & ~STATS_MASK_QUEUE)
1706 return -rte_tm_error_set(error,
1708 RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,
1710 rte_strerror(EINVAL));
1716 node_add_check(struct rte_eth_dev *dev,
1718 uint32_t parent_node_id,
1722 struct rte_tm_node_params *params,
1723 struct rte_tm_error *error)
1729 /* node_id, parent_node_id:
1730 * -node_id must not be RTE_TM_NODE_ID_NULL
1731 * -node_id must not be in use
1732 * -root node add (parent_node_id is RTE_TM_NODE_ID_NULL):
1733 * -root node must not exist
1734 * -non-root node add (parent_node_id is not RTE_TM_NODE_ID_NULL):
1735 * -parent_node_id must be valid
1737 if (node_id == RTE_TM_NODE_ID_NULL)
1738 return -rte_tm_error_set(error,
1740 RTE_TM_ERROR_TYPE_NODE_ID,
1742 rte_strerror(EINVAL));
1744 if (tm_node_search(dev, node_id))
1745 return -rte_tm_error_set(error,
1747 RTE_TM_ERROR_TYPE_NODE_ID,
1749 rte_strerror(EEXIST));
1751 if (parent_node_id == RTE_TM_NODE_ID_NULL) {
1753 if (tm_root_node_present(dev))
1754 return -rte_tm_error_set(error,
1756 RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID,
1758 rte_strerror(EEXIST));
1760 pn = tm_node_search(dev, parent_node_id);
1762 return -rte_tm_error_set(error,
1764 RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID,
1766 rte_strerror(EINVAL));
1769 /* priority: must be 0 .. 3 */
1770 if (priority >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1771 return -rte_tm_error_set(error,
1773 RTE_TM_ERROR_TYPE_NODE_PRIORITY,
1775 rte_strerror(EINVAL));
1777 /* weight: must be 1 .. 255 */
1778 if (weight == 0 || weight >= UINT8_MAX)
1779 return -rte_tm_error_set(error,
1781 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
1783 rte_strerror(EINVAL));
1785 /* level_id: if valid, then
1786 * -root node add (parent_node_id is RTE_TM_NODE_ID_NULL):
1787 * -level_id must be zero
1788 * -non-root node add (parent_node_id is not RTE_TM_NODE_ID_NULL):
1789 * -level_id must be parent level ID plus one
1791 level = (pn == NULL) ? 0 : pn->level + 1;
1792 if (level_id != RTE_TM_NODE_LEVEL_ID_ANY && level_id != level)
1793 return -rte_tm_error_set(error,
1795 RTE_TM_ERROR_TYPE_LEVEL_ID,
1797 rte_strerror(EINVAL));
1799 /* params: must not be NULL */
1801 return -rte_tm_error_set(error,
1803 RTE_TM_ERROR_TYPE_NODE_PARAMS,
1805 rte_strerror(EINVAL));
1807 /* params: per level checks */
1809 case TM_NODE_LEVEL_PORT:
1810 status = node_add_check_port(dev, node_id,
1811 parent_node_id, priority, weight, level_id,
1817 case TM_NODE_LEVEL_SUBPORT:
1818 status = node_add_check_subport(dev, node_id,
1819 parent_node_id, priority, weight, level_id,
1825 case TM_NODE_LEVEL_PIPE:
1826 status = node_add_check_pipe(dev, node_id,
1827 parent_node_id, priority, weight, level_id,
1833 case TM_NODE_LEVEL_TC:
1834 status = node_add_check_tc(dev, node_id,
1835 parent_node_id, priority, weight, level_id,
1841 case TM_NODE_LEVEL_QUEUE:
1842 status = node_add_check_queue(dev, node_id,
1843 parent_node_id, priority, weight, level_id,
1850 return -rte_tm_error_set(error,
1852 RTE_TM_ERROR_TYPE_LEVEL_ID,
1854 rte_strerror(EINVAL));
1860 /* Traffic manager node add */
1862 pmd_tm_node_add(struct rte_eth_dev *dev,
1864 uint32_t parent_node_id,
1868 struct rte_tm_node_params *params,
1869 struct rte_tm_error *error)
1871 struct pmd_internals *p = dev->data->dev_private;
1872 struct tm_node_list *nl = &p->soft.tm.h.nodes;
1878 if (p->soft.tm.hierarchy_frozen)
1879 return -rte_tm_error_set(error,
1881 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1883 rte_strerror(EBUSY));
1885 status = node_add_check(dev, node_id, parent_node_id, priority, weight,
1886 level_id, params, error);
1890 /* Memory allocation */
1891 n = calloc(1, sizeof(struct tm_node));
1893 return -rte_tm_error_set(error,
1895 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1897 rte_strerror(ENOMEM));
1900 n->node_id = node_id;
1901 n->parent_node_id = parent_node_id;
1902 n->priority = priority;
1905 if (parent_node_id != RTE_TM_NODE_ID_NULL) {
1906 n->parent_node = tm_node_search(dev, parent_node_id);
1907 n->level = n->parent_node->level + 1;
1910 if (params->shaper_profile_id != RTE_TM_SHAPER_PROFILE_ID_NONE)
1911 n->shaper_profile = tm_shaper_profile_search(dev,
1912 params->shaper_profile_id);
1914 if (n->level == TM_NODE_LEVEL_QUEUE &&
1915 params->leaf.cman == RTE_TM_CMAN_WRED)
1916 n->wred_profile = tm_wred_profile_search(dev,
1917 params->leaf.wred.wred_profile_id);
1919 memcpy(&n->params, params, sizeof(n->params));
1922 TAILQ_INSERT_TAIL(nl, n, node);
1923 p->soft.tm.h.n_nodes++;
1925 /* Update dependencies */
1927 n->parent_node->n_children++;
1929 if (n->shaper_profile)
1930 n->shaper_profile->n_users++;
1932 for (i = 0; i < params->n_shared_shapers; i++) {
1933 struct tm_shared_shaper *ss;
1935 ss = tm_shared_shaper_search(dev, params->shared_shaper_id[i]);
1939 if (n->wred_profile)
1940 n->wred_profile->n_users++;
1942 p->soft.tm.h.n_tm_nodes[n->level]++;
1947 /* Traffic manager node delete */
1949 pmd_tm_node_delete(struct rte_eth_dev *dev,
1951 struct rte_tm_error *error)
1953 struct pmd_internals *p = dev->data->dev_private;
1957 /* Check hierarchy changes are currently allowed */
1958 if (p->soft.tm.hierarchy_frozen)
1959 return -rte_tm_error_set(error,
1961 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1963 rte_strerror(EBUSY));
1965 /* Check existing */
1966 n = tm_node_search(dev, node_id);
1968 return -rte_tm_error_set(error,
1970 RTE_TM_ERROR_TYPE_NODE_ID,
1972 rte_strerror(EINVAL));
1976 return -rte_tm_error_set(error,
1978 RTE_TM_ERROR_TYPE_NODE_ID,
1980 rte_strerror(EBUSY));
1982 /* Update dependencies */
1983 p->soft.tm.h.n_tm_nodes[n->level]--;
1985 if (n->wred_profile)
1986 n->wred_profile->n_users--;
1988 for (i = 0; i < n->params.n_shared_shapers; i++) {
1989 struct tm_shared_shaper *ss;
1991 ss = tm_shared_shaper_search(dev,
1992 n->params.shared_shaper_id[i]);
1996 if (n->shaper_profile)
1997 n->shaper_profile->n_users--;
2000 n->parent_node->n_children--;
2002 /* Remove from list */
2003 TAILQ_REMOVE(&p->soft.tm.h.nodes, n, node);
2004 p->soft.tm.h.n_nodes--;
2012 pipe_profile_build(struct rte_eth_dev *dev,
2014 struct rte_sched_pipe_params *pp)
2016 struct pmd_internals *p = dev->data->dev_private;
2017 struct tm_hierarchy *h = &p->soft.tm.h;
2018 struct tm_node_list *nl = &h->nodes;
2019 struct tm_node *nt, *nq;
2021 memset(pp, 0, sizeof(*pp));
2024 pp->tb_rate = np->shaper_profile->params.peak.rate;
2025 pp->tb_size = np->shaper_profile->params.peak.size;
2027 /* Traffic Class (TC) */
2028 pp->tc_period = PIPE_TC_PERIOD;
2030 #ifdef RTE_SCHED_SUBPORT_TC_OV
2031 pp->tc_ov_weight = np->weight;
2034 TAILQ_FOREACH(nt, nl, node) {
2035 uint32_t queue_id = 0;
2037 if (nt->level != TM_NODE_LEVEL_TC ||
2038 nt->parent_node_id != np->node_id)
2041 pp->tc_rate[nt->priority] =
2042 nt->shaper_profile->params.peak.rate;
2045 TAILQ_FOREACH(nq, nl, node) {
2046 uint32_t pipe_queue_id;
2048 if (nq->level != TM_NODE_LEVEL_QUEUE ||
2049 nq->parent_node_id != nt->node_id)
2052 pipe_queue_id = nt->priority *
2053 RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue_id;
2054 pp->wrr_weights[pipe_queue_id] = nq->weight;
2062 pipe_profile_free_exists(struct rte_eth_dev *dev,
2063 uint32_t *pipe_profile_id)
2065 struct pmd_internals *p = dev->data->dev_private;
2066 struct tm_params *t = &p->soft.tm.params;
2068 if (t->n_pipe_profiles < RTE_SCHED_PIPE_PROFILES_PER_PORT) {
2069 *pipe_profile_id = t->n_pipe_profiles;
2077 pipe_profile_exists(struct rte_eth_dev *dev,
2078 struct rte_sched_pipe_params *pp,
2079 uint32_t *pipe_profile_id)
2081 struct pmd_internals *p = dev->data->dev_private;
2082 struct tm_params *t = &p->soft.tm.params;
2085 for (i = 0; i < t->n_pipe_profiles; i++)
2086 if (memcmp(&t->pipe_profiles[i], pp, sizeof(*pp)) == 0) {
2087 if (pipe_profile_id)
2088 *pipe_profile_id = i;
2096 pipe_profile_install(struct rte_eth_dev *dev,
2097 struct rte_sched_pipe_params *pp,
2098 uint32_t pipe_profile_id)
2100 struct pmd_internals *p = dev->data->dev_private;
2101 struct tm_params *t = &p->soft.tm.params;
2103 memcpy(&t->pipe_profiles[pipe_profile_id], pp, sizeof(*pp));
2104 t->n_pipe_profiles++;
2108 pipe_profile_mark(struct rte_eth_dev *dev,
2109 uint32_t subport_id,
2111 uint32_t pipe_profile_id)
2113 struct pmd_internals *p = dev->data->dev_private;
2114 struct tm_hierarchy *h = &p->soft.tm.h;
2115 struct tm_params *t = &p->soft.tm.params;
2116 uint32_t n_pipes_per_subport, pos;
2118 n_pipes_per_subport = h->n_tm_nodes[TM_NODE_LEVEL_PIPE] /
2119 h->n_tm_nodes[TM_NODE_LEVEL_SUBPORT];
2120 pos = subport_id * n_pipes_per_subport + pipe_id;
2122 t->pipe_to_profile[pos] = pipe_profile_id;
2125 static struct rte_sched_pipe_params *
2126 pipe_profile_get(struct rte_eth_dev *dev, struct tm_node *np)
2128 struct pmd_internals *p = dev->data->dev_private;
2129 struct tm_hierarchy *h = &p->soft.tm.h;
2130 struct tm_params *t = &p->soft.tm.params;
2131 uint32_t n_pipes_per_subport = h->n_tm_nodes[TM_NODE_LEVEL_PIPE] /
2132 h->n_tm_nodes[TM_NODE_LEVEL_SUBPORT];
2134 uint32_t subport_id = tm_node_subport_id(dev, np->parent_node);
2135 uint32_t pipe_id = tm_node_pipe_id(dev, np);
2137 uint32_t pos = subport_id * n_pipes_per_subport + pipe_id;
2138 uint32_t pipe_profile_id = t->pipe_to_profile[pos];
2140 return &t->pipe_profiles[pipe_profile_id];
2144 pipe_profiles_generate(struct rte_eth_dev *dev)
2146 struct pmd_internals *p = dev->data->dev_private;
2147 struct tm_hierarchy *h = &p->soft.tm.h;
2148 struct tm_node_list *nl = &h->nodes;
2149 struct tm_node *ns, *np;
2150 uint32_t subport_id;
2152 /* Objective: Fill in the following fields in struct tm_params:
2159 TAILQ_FOREACH(ns, nl, node) {
2162 if (ns->level != TM_NODE_LEVEL_SUBPORT)
2166 TAILQ_FOREACH(np, nl, node) {
2167 struct rte_sched_pipe_params pp;
2170 if (np->level != TM_NODE_LEVEL_PIPE ||
2171 np->parent_node_id != ns->node_id)
2174 pipe_profile_build(dev, np, &pp);
2176 if (!pipe_profile_exists(dev, &pp, &pos)) {
2177 if (!pipe_profile_free_exists(dev, &pos))
2180 pipe_profile_install(dev, &pp, pos);
2183 pipe_profile_mark(dev, subport_id, pipe_id, pos);
2194 static struct tm_wred_profile *
2195 tm_tc_wred_profile_get(struct rte_eth_dev *dev, uint32_t tc_id)
2197 struct pmd_internals *p = dev->data->dev_private;
2198 struct tm_hierarchy *h = &p->soft.tm.h;
2199 struct tm_node_list *nl = &h->nodes;
2202 TAILQ_FOREACH(nq, nl, node) {
2203 if (nq->level != TM_NODE_LEVEL_QUEUE ||
2204 nq->parent_node->priority != tc_id)
2207 return nq->wred_profile;
2213 #ifdef RTE_SCHED_RED
2216 wred_profiles_set(struct rte_eth_dev *dev)
2218 struct pmd_internals *p = dev->data->dev_private;
2219 struct rte_sched_port_params *pp = &p->soft.tm.params.port_params;
2221 enum rte_color color;
2223 for (tc_id = 0; tc_id < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; tc_id++)
2224 for (color = RTE_COLOR_GREEN; color < RTE_COLORS; color++) {
2225 struct rte_red_params *dst =
2226 &pp->red_params[tc_id][color];
2227 struct tm_wred_profile *src_wp =
2228 tm_tc_wred_profile_get(dev, tc_id);
2229 struct rte_tm_red_params *src =
2230 &src_wp->params.red_params[color];
2232 memcpy(dst, src, sizeof(*dst));
2238 #define wred_profiles_set(dev)
2242 static struct tm_shared_shaper *
2243 tm_tc_shared_shaper_get(struct rte_eth_dev *dev, struct tm_node *tc_node)
2245 return (tc_node->params.n_shared_shapers) ?
2246 tm_shared_shaper_search(dev,
2247 tc_node->params.shared_shaper_id[0]) :
2251 static struct tm_shared_shaper *
2252 tm_subport_tc_shared_shaper_get(struct rte_eth_dev *dev,
2253 struct tm_node *subport_node,
2256 struct pmd_internals *p = dev->data->dev_private;
2257 struct tm_node_list *nl = &p->soft.tm.h.nodes;
2260 TAILQ_FOREACH(n, nl, node) {
2261 if (n->level != TM_NODE_LEVEL_TC ||
2262 n->parent_node->parent_node_id !=
2263 subport_node->node_id ||
2264 n->priority != tc_id)
2267 return tm_tc_shared_shaper_get(dev, n);
2274 hierarchy_commit_check(struct rte_eth_dev *dev, struct rte_tm_error *error)
2276 struct pmd_internals *p = dev->data->dev_private;
2277 struct tm_hierarchy *h = &p->soft.tm.h;
2278 struct tm_node_list *nl = &h->nodes;
2279 struct tm_shared_shaper_list *ssl = &h->shared_shapers;
2280 struct tm_wred_profile_list *wpl = &h->wred_profiles;
2281 struct tm_node *nr = tm_root_node_present(dev), *ns, *np, *nt, *nq;
2282 struct tm_shared_shaper *ss;
2284 uint32_t n_pipes_per_subport;
2286 /* Root node exists. */
2288 return -rte_tm_error_set(error,
2290 RTE_TM_ERROR_TYPE_LEVEL_ID,
2292 rte_strerror(EINVAL));
2294 /* There is at least one subport, max is not exceeded. */
2295 if (nr->n_children == 0 || nr->n_children > TM_MAX_SUBPORTS)
2296 return -rte_tm_error_set(error,
2298 RTE_TM_ERROR_TYPE_LEVEL_ID,
2300 rte_strerror(EINVAL));
2302 /* There is at least one pipe. */
2303 if (h->n_tm_nodes[TM_NODE_LEVEL_PIPE] == 0)
2304 return -rte_tm_error_set(error,
2306 RTE_TM_ERROR_TYPE_LEVEL_ID,
2308 rte_strerror(EINVAL));
2310 /* Number of pipes is the same for all subports. Maximum number of pipes
2311 * per subport is not exceeded.
2313 n_pipes_per_subport = h->n_tm_nodes[TM_NODE_LEVEL_PIPE] /
2314 h->n_tm_nodes[TM_NODE_LEVEL_SUBPORT];
2316 if (n_pipes_per_subport > TM_MAX_PIPES_PER_SUBPORT)
2317 return -rte_tm_error_set(error,
2319 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2321 rte_strerror(EINVAL));
2323 TAILQ_FOREACH(ns, nl, node) {
2324 if (ns->level != TM_NODE_LEVEL_SUBPORT)
2327 if (ns->n_children != n_pipes_per_subport)
2328 return -rte_tm_error_set(error,
2330 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2332 rte_strerror(EINVAL));
2335 /* Each pipe has exactly 4 TCs, with exactly one TC for each priority */
2336 TAILQ_FOREACH(np, nl, node) {
2337 uint32_t mask = 0, mask_expected =
2338 RTE_LEN2MASK(RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
2341 if (np->level != TM_NODE_LEVEL_PIPE)
2344 if (np->n_children != RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
2345 return -rte_tm_error_set(error,
2347 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2349 rte_strerror(EINVAL));
2351 TAILQ_FOREACH(nt, nl, node) {
2352 if (nt->level != TM_NODE_LEVEL_TC ||
2353 nt->parent_node_id != np->node_id)
2356 mask |= 1 << nt->priority;
2359 if (mask != mask_expected)
2360 return -rte_tm_error_set(error,
2362 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2364 rte_strerror(EINVAL));
2367 /* Each TC has exactly 4 packet queues. */
2368 TAILQ_FOREACH(nt, nl, node) {
2369 if (nt->level != TM_NODE_LEVEL_TC)
2372 if (nt->n_children != RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
2373 return -rte_tm_error_set(error,
2375 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2377 rte_strerror(EINVAL));
2382 * -For each TC #i, all pipes in the same subport use the same
2383 * shared shaper (or no shared shaper) for their TC#i.
2384 * -Each shared shaper needs to have at least one user. All its
2385 * users have to be TC nodes with the same priority and the same
2388 TAILQ_FOREACH(ns, nl, node) {
2389 struct tm_shared_shaper *s[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
2392 if (ns->level != TM_NODE_LEVEL_SUBPORT)
2395 for (id = 0; id < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; id++)
2396 s[id] = tm_subport_tc_shared_shaper_get(dev, ns, id);
2398 TAILQ_FOREACH(nt, nl, node) {
2399 struct tm_shared_shaper *subport_ss, *tc_ss;
2401 if (nt->level != TM_NODE_LEVEL_TC ||
2402 nt->parent_node->parent_node_id !=
2406 subport_ss = s[nt->priority];
2407 tc_ss = tm_tc_shared_shaper_get(dev, nt);
2409 if (subport_ss == NULL && tc_ss == NULL)
2412 if ((subport_ss == NULL && tc_ss != NULL) ||
2413 (subport_ss != NULL && tc_ss == NULL) ||
2414 subport_ss->shared_shaper_id !=
2415 tc_ss->shared_shaper_id)
2416 return -rte_tm_error_set(error,
2418 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2420 rte_strerror(EINVAL));
2424 TAILQ_FOREACH(ss, ssl, node) {
2425 struct tm_node *nt_any = tm_shared_shaper_get_tc(dev, ss);
2426 uint32_t n_users = 0;
2429 TAILQ_FOREACH(nt, nl, node) {
2430 if (nt->level != TM_NODE_LEVEL_TC ||
2431 nt->priority != nt_any->priority ||
2432 nt->parent_node->parent_node_id !=
2433 nt_any->parent_node->parent_node_id)
2439 if (ss->n_users == 0 || ss->n_users != n_users)
2440 return -rte_tm_error_set(error,
2442 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2444 rte_strerror(EINVAL));
2447 /* Not too many pipe profiles. */
2448 if (pipe_profiles_generate(dev))
2449 return -rte_tm_error_set(error,
2451 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2453 rte_strerror(EINVAL));
2456 * WRED (when used, i.e. at least one WRED profile defined):
2457 * -Each WRED profile must have at least one user.
2458 * -All leaf nodes must have their private WRED context enabled.
2459 * -For each TC #i, all leaf nodes must use the same WRED profile
2460 * for their private WRED context.
2462 if (h->n_wred_profiles) {
2463 struct tm_wred_profile *wp;
2464 struct tm_wred_profile *w[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
2467 TAILQ_FOREACH(wp, wpl, node)
2468 if (wp->n_users == 0)
2469 return -rte_tm_error_set(error,
2471 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2473 rte_strerror(EINVAL));
2475 for (id = 0; id < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; id++) {
2476 w[id] = tm_tc_wred_profile_get(dev, id);
2479 return -rte_tm_error_set(error,
2481 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2483 rte_strerror(EINVAL));
2486 TAILQ_FOREACH(nq, nl, node) {
2489 if (nq->level != TM_NODE_LEVEL_QUEUE)
2492 id = nq->parent_node->priority;
2494 if (nq->wred_profile == NULL ||
2495 nq->wred_profile->wred_profile_id !=
2496 w[id]->wred_profile_id)
2497 return -rte_tm_error_set(error,
2499 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2501 rte_strerror(EINVAL));
2509 hierarchy_blueprints_create(struct rte_eth_dev *dev)
2511 struct pmd_internals *p = dev->data->dev_private;
2512 struct tm_params *t = &p->soft.tm.params;
2513 struct tm_hierarchy *h = &p->soft.tm.h;
2515 struct tm_node_list *nl = &h->nodes;
2516 struct tm_node *root = tm_root_node_present(dev), *n;
2518 uint32_t subport_id;
2520 t->port_params = (struct rte_sched_port_params) {
2521 .name = dev->data->name,
2522 .socket = dev->data->numa_node,
2523 .rate = root->shaper_profile->params.peak.rate,
2524 .mtu = dev->data->mtu,
2526 root->shaper_profile->params.pkt_length_adjust,
2527 .n_subports_per_port = root->n_children,
2528 .n_pipes_per_subport = h->n_tm_nodes[TM_NODE_LEVEL_PIPE] /
2529 h->n_tm_nodes[TM_NODE_LEVEL_SUBPORT],
2530 .qsize = {p->params.tm.qsize[0],
2531 p->params.tm.qsize[1],
2532 p->params.tm.qsize[2],
2533 p->params.tm.qsize[3],
2535 .pipe_profiles = t->pipe_profiles,
2536 .n_pipe_profiles = t->n_pipe_profiles,
2539 wred_profiles_set(dev);
2542 TAILQ_FOREACH(n, nl, node) {
2543 uint64_t tc_rate[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
2546 if (n->level != TM_NODE_LEVEL_SUBPORT)
2549 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
2550 struct tm_shared_shaper *ss;
2551 struct tm_shaper_profile *sp;
2553 ss = tm_subport_tc_shared_shaper_get(dev, n, i);
2554 sp = (ss) ? tm_shaper_profile_search(dev,
2555 ss->shaper_profile_id) :
2557 tc_rate[i] = sp->params.peak.rate;
2560 t->subport_params[subport_id] =
2561 (struct rte_sched_subport_params) {
2562 .tb_rate = n->shaper_profile->params.peak.rate,
2563 .tb_size = n->shaper_profile->params.peak.size,
2565 .tc_rate = {tc_rate[0],
2570 .tc_period = SUBPORT_TC_PERIOD,
2577 /* Traffic manager hierarchy commit */
2579 pmd_tm_hierarchy_commit(struct rte_eth_dev *dev,
2581 struct rte_tm_error *error)
2583 struct pmd_internals *p = dev->data->dev_private;
2587 if (p->soft.tm.hierarchy_frozen)
2588 return -rte_tm_error_set(error,
2590 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2592 rte_strerror(EBUSY));
2594 status = hierarchy_commit_check(dev, error);
2597 tm_hierarchy_free(p);
2602 /* Create blueprints */
2603 hierarchy_blueprints_create(dev);
2605 /* Freeze hierarchy */
2606 p->soft.tm.hierarchy_frozen = 1;
2611 #ifdef RTE_SCHED_SUBPORT_TC_OV
2614 update_pipe_weight(struct rte_eth_dev *dev, struct tm_node *np, uint32_t weight)
2616 struct pmd_internals *p = dev->data->dev_private;
2617 uint32_t pipe_id = tm_node_pipe_id(dev, np);
2619 struct tm_node *ns = np->parent_node;
2620 uint32_t subport_id = tm_node_subport_id(dev, ns);
2622 struct rte_sched_pipe_params *profile0 = pipe_profile_get(dev, np);
2623 struct rte_sched_pipe_params profile1;
2624 uint32_t pipe_profile_id;
2626 /* Derive new pipe profile. */
2627 memcpy(&profile1, profile0, sizeof(profile1));
2628 profile1.tc_ov_weight = (uint8_t)weight;
2630 /* Since implementation does not allow adding more pipe profiles after
2631 * port configuration, the pipe configuration can be successfully
2632 * updated only if the new profile is also part of the existing set of
2635 if (pipe_profile_exists(dev, &profile1, &pipe_profile_id) == 0)
2638 /* Update the pipe profile used by the current pipe. */
2639 if (rte_sched_pipe_config(SCHED(p), subport_id, pipe_id,
2640 (int32_t)pipe_profile_id))
2643 /* Commit changes. */
2644 pipe_profile_mark(dev, subport_id, pipe_id, pipe_profile_id);
2645 np->weight = weight;
2653 update_queue_weight(struct rte_eth_dev *dev,
2654 struct tm_node *nq, uint32_t weight)
2656 struct pmd_internals *p = dev->data->dev_private;
2657 uint32_t queue_id = tm_node_queue_id(dev, nq);
2659 struct tm_node *nt = nq->parent_node;
2660 uint32_t tc_id = tm_node_tc_id(dev, nt);
2662 struct tm_node *np = nt->parent_node;
2663 uint32_t pipe_id = tm_node_pipe_id(dev, np);
2665 struct tm_node *ns = np->parent_node;
2666 uint32_t subport_id = tm_node_subport_id(dev, ns);
2668 uint32_t pipe_queue_id =
2669 tc_id * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue_id;
2671 struct rte_sched_pipe_params *profile0 = pipe_profile_get(dev, np);
2672 struct rte_sched_pipe_params profile1;
2673 uint32_t pipe_profile_id;
2675 /* Derive new pipe profile. */
2676 memcpy(&profile1, profile0, sizeof(profile1));
2677 profile1.wrr_weights[pipe_queue_id] = (uint8_t)weight;
2679 /* Since implementation does not allow adding more pipe profiles after
2680 * port configuration, the pipe configuration can be successfully
2681 * updated only if the new profile is also part of the existing set
2684 if (pipe_profile_exists(dev, &profile1, &pipe_profile_id) == 0)
2687 /* Update the pipe profile used by the current pipe. */
2688 if (rte_sched_pipe_config(SCHED(p), subport_id, pipe_id,
2689 (int32_t)pipe_profile_id))
2692 /* Commit changes. */
2693 pipe_profile_mark(dev, subport_id, pipe_id, pipe_profile_id);
2694 nq->weight = weight;
2699 /* Traffic manager node parent update */
2701 pmd_tm_node_parent_update(struct rte_eth_dev *dev,
2703 uint32_t parent_node_id,
2706 struct rte_tm_error *error)
2710 /* Port must be started and TM used. */
2711 if (dev->data->dev_started == 0 && (tm_used(dev) == 0))
2712 return -rte_tm_error_set(error,
2714 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2716 rte_strerror(EBUSY));
2718 /* Node must be valid */
2719 n = tm_node_search(dev, node_id);
2721 return -rte_tm_error_set(error,
2723 RTE_TM_ERROR_TYPE_NODE_ID,
2725 rte_strerror(EINVAL));
2727 /* Parent node must be the same */
2728 if (n->parent_node_id != parent_node_id)
2729 return -rte_tm_error_set(error,
2731 RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID,
2733 rte_strerror(EINVAL));
2735 /* Priority must be the same */
2736 if (n->priority != priority)
2737 return -rte_tm_error_set(error,
2739 RTE_TM_ERROR_TYPE_NODE_PRIORITY,
2741 rte_strerror(EINVAL));
2743 /* weight: must be 1 .. 255 */
2744 if (weight == 0 || weight >= UINT8_MAX)
2745 return -rte_tm_error_set(error,
2747 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
2749 rte_strerror(EINVAL));
2752 case TM_NODE_LEVEL_PORT:
2753 return -rte_tm_error_set(error,
2755 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
2757 rte_strerror(EINVAL));
2759 case TM_NODE_LEVEL_SUBPORT:
2760 return -rte_tm_error_set(error,
2762 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
2764 rte_strerror(EINVAL));
2766 case TM_NODE_LEVEL_PIPE:
2767 #ifdef RTE_SCHED_SUBPORT_TC_OV
2768 if (update_pipe_weight(dev, n, weight))
2769 return -rte_tm_error_set(error,
2771 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2773 rte_strerror(EINVAL));
2776 return -rte_tm_error_set(error,
2778 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
2780 rte_strerror(EINVAL));
2783 case TM_NODE_LEVEL_TC:
2784 return -rte_tm_error_set(error,
2786 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
2788 rte_strerror(EINVAL));
2790 case TM_NODE_LEVEL_QUEUE:
2793 if (update_queue_weight(dev, n, weight))
2794 return -rte_tm_error_set(error,
2796 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2798 rte_strerror(EINVAL));
2804 update_subport_rate(struct rte_eth_dev *dev,
2806 struct tm_shaper_profile *sp)
2808 struct pmd_internals *p = dev->data->dev_private;
2809 uint32_t subport_id = tm_node_subport_id(dev, ns);
2811 struct rte_sched_subport_params subport_params;
2813 /* Derive new subport configuration. */
2814 memcpy(&subport_params,
2815 &p->soft.tm.params.subport_params[subport_id],
2816 sizeof(subport_params));
2817 subport_params.tb_rate = sp->params.peak.rate;
2818 subport_params.tb_size = sp->params.peak.size;
2820 /* Update the subport configuration. */
2821 if (rte_sched_subport_config(SCHED(p), subport_id,
2825 /* Commit changes. */
2826 ns->shaper_profile->n_users--;
2828 ns->shaper_profile = sp;
2829 ns->params.shaper_profile_id = sp->shaper_profile_id;
2832 memcpy(&p->soft.tm.params.subport_params[subport_id],
2834 sizeof(subport_params));
2840 update_pipe_rate(struct rte_eth_dev *dev,
2842 struct tm_shaper_profile *sp)
2844 struct pmd_internals *p = dev->data->dev_private;
2845 uint32_t pipe_id = tm_node_pipe_id(dev, np);
2847 struct tm_node *ns = np->parent_node;
2848 uint32_t subport_id = tm_node_subport_id(dev, ns);
2850 struct rte_sched_pipe_params *profile0 = pipe_profile_get(dev, np);
2851 struct rte_sched_pipe_params profile1;
2852 uint32_t pipe_profile_id;
2854 /* Derive new pipe profile. */
2855 memcpy(&profile1, profile0, sizeof(profile1));
2856 profile1.tb_rate = sp->params.peak.rate;
2857 profile1.tb_size = sp->params.peak.size;
2859 /* Since implementation does not allow adding more pipe profiles after
2860 * port configuration, the pipe configuration can be successfully
2861 * updated only if the new profile is also part of the existing set of
2864 if (pipe_profile_exists(dev, &profile1, &pipe_profile_id) == 0)
2867 /* Update the pipe profile used by the current pipe. */
2868 if (rte_sched_pipe_config(SCHED(p), subport_id, pipe_id,
2869 (int32_t)pipe_profile_id))
2872 /* Commit changes. */
2873 pipe_profile_mark(dev, subport_id, pipe_id, pipe_profile_id);
2874 np->shaper_profile->n_users--;
2875 np->shaper_profile = sp;
2876 np->params.shaper_profile_id = sp->shaper_profile_id;
2883 update_tc_rate(struct rte_eth_dev *dev,
2885 struct tm_shaper_profile *sp)
2887 struct pmd_internals *p = dev->data->dev_private;
2888 uint32_t tc_id = tm_node_tc_id(dev, nt);
2890 struct tm_node *np = nt->parent_node;
2891 uint32_t pipe_id = tm_node_pipe_id(dev, np);
2893 struct tm_node *ns = np->parent_node;
2894 uint32_t subport_id = tm_node_subport_id(dev, ns);
2896 struct rte_sched_pipe_params *profile0 = pipe_profile_get(dev, np);
2897 struct rte_sched_pipe_params profile1;
2898 uint32_t pipe_profile_id;
2900 /* Derive new pipe profile. */
2901 memcpy(&profile1, profile0, sizeof(profile1));
2902 profile1.tc_rate[tc_id] = sp->params.peak.rate;
2904 /* Since implementation does not allow adding more pipe profiles after
2905 * port configuration, the pipe configuration can be successfully
2906 * updated only if the new profile is also part of the existing set of
2909 if (pipe_profile_exists(dev, &profile1, &pipe_profile_id) == 0)
2912 /* Update the pipe profile used by the current pipe. */
2913 if (rte_sched_pipe_config(SCHED(p), subport_id, pipe_id,
2914 (int32_t)pipe_profile_id))
2917 /* Commit changes. */
2918 pipe_profile_mark(dev, subport_id, pipe_id, pipe_profile_id);
2919 nt->shaper_profile->n_users--;
2920 nt->shaper_profile = sp;
2921 nt->params.shaper_profile_id = sp->shaper_profile_id;
2927 /* Traffic manager node shaper update */
2929 pmd_tm_node_shaper_update(struct rte_eth_dev *dev,
2931 uint32_t shaper_profile_id,
2932 struct rte_tm_error *error)
2935 struct tm_shaper_profile *sp;
2937 /* Port must be started and TM used. */
2938 if (dev->data->dev_started == 0 && (tm_used(dev) == 0))
2939 return -rte_tm_error_set(error,
2941 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2943 rte_strerror(EBUSY));
2945 /* Node must be valid */
2946 n = tm_node_search(dev, node_id);
2948 return -rte_tm_error_set(error,
2950 RTE_TM_ERROR_TYPE_NODE_ID,
2952 rte_strerror(EINVAL));
2954 /* Shaper profile must be valid. */
2955 sp = tm_shaper_profile_search(dev, shaper_profile_id);
2957 return -rte_tm_error_set(error,
2959 RTE_TM_ERROR_TYPE_SHAPER_PROFILE,
2961 rte_strerror(EINVAL));
2964 case TM_NODE_LEVEL_PORT:
2965 return -rte_tm_error_set(error,
2967 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2969 rte_strerror(EINVAL));
2971 case TM_NODE_LEVEL_SUBPORT:
2972 if (update_subport_rate(dev, n, sp))
2973 return -rte_tm_error_set(error,
2975 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2977 rte_strerror(EINVAL));
2980 case TM_NODE_LEVEL_PIPE:
2981 if (update_pipe_rate(dev, n, sp))
2982 return -rte_tm_error_set(error,
2984 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2986 rte_strerror(EINVAL));
2989 case TM_NODE_LEVEL_TC:
2990 if (update_tc_rate(dev, n, sp))
2991 return -rte_tm_error_set(error,
2993 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2995 rte_strerror(EINVAL));
2998 case TM_NODE_LEVEL_QUEUE:
3001 return -rte_tm_error_set(error,
3003 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3005 rte_strerror(EINVAL));
3009 static inline uint32_t
3010 tm_port_queue_id(struct rte_eth_dev *dev,
3011 uint32_t port_subport_id,
3012 uint32_t subport_pipe_id,
3013 uint32_t pipe_tc_id,
3014 uint32_t tc_queue_id)
3016 struct pmd_internals *p = dev->data->dev_private;
3017 struct tm_hierarchy *h = &p->soft.tm.h;
3018 uint32_t n_pipes_per_subport = h->n_tm_nodes[TM_NODE_LEVEL_PIPE] /
3019 h->n_tm_nodes[TM_NODE_LEVEL_SUBPORT];
3021 uint32_t port_pipe_id =
3022 port_subport_id * n_pipes_per_subport + subport_pipe_id;
3023 uint32_t port_tc_id =
3024 port_pipe_id * RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE + pipe_tc_id;
3025 uint32_t port_queue_id =
3026 port_tc_id * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + tc_queue_id;
3028 return port_queue_id;
3032 read_port_stats(struct rte_eth_dev *dev,
3034 struct rte_tm_node_stats *stats,
3035 uint64_t *stats_mask,
3038 struct pmd_internals *p = dev->data->dev_private;
3039 struct tm_hierarchy *h = &p->soft.tm.h;
3040 uint32_t n_subports_per_port = h->n_tm_nodes[TM_NODE_LEVEL_SUBPORT];
3041 uint32_t subport_id;
3043 for (subport_id = 0; subport_id < n_subports_per_port; subport_id++) {
3044 struct rte_sched_subport_stats s;
3048 int status = rte_sched_subport_read_stats(SCHED(p),
3055 /* Stats accumulate */
3056 for (id = 0; id < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; id++) {
3058 s.n_pkts_tc[id] - s.n_pkts_tc_dropped[id];
3059 nr->stats.n_bytes +=
3060 s.n_bytes_tc[id] - s.n_bytes_tc_dropped[id];
3061 nr->stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN] +=
3062 s.n_pkts_tc_dropped[id];
3063 nr->stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN] +=
3064 s.n_bytes_tc_dropped[id];
3070 memcpy(stats, &nr->stats, sizeof(*stats));
3073 *stats_mask = STATS_MASK_DEFAULT;
3077 memset(&nr->stats, 0, sizeof(nr->stats));
3083 read_subport_stats(struct rte_eth_dev *dev,
3085 struct rte_tm_node_stats *stats,
3086 uint64_t *stats_mask,
3089 struct pmd_internals *p = dev->data->dev_private;
3090 uint32_t subport_id = tm_node_subport_id(dev, ns);
3091 struct rte_sched_subport_stats s;
3092 uint32_t tc_ov, tc_id;
3095 int status = rte_sched_subport_read_stats(SCHED(p),
3102 /* Stats accumulate */
3103 for (tc_id = 0; tc_id < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; tc_id++) {
3105 s.n_pkts_tc[tc_id] - s.n_pkts_tc_dropped[tc_id];
3106 ns->stats.n_bytes +=
3107 s.n_bytes_tc[tc_id] - s.n_bytes_tc_dropped[tc_id];
3108 ns->stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN] +=
3109 s.n_pkts_tc_dropped[tc_id];
3110 ns->stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN] +=
3111 s.n_bytes_tc_dropped[tc_id];
3116 memcpy(stats, &ns->stats, sizeof(*stats));
3119 *stats_mask = STATS_MASK_DEFAULT;
3123 memset(&ns->stats, 0, sizeof(ns->stats));
3129 read_pipe_stats(struct rte_eth_dev *dev,
3131 struct rte_tm_node_stats *stats,
3132 uint64_t *stats_mask,
3135 struct pmd_internals *p = dev->data->dev_private;
3137 uint32_t pipe_id = tm_node_pipe_id(dev, np);
3139 struct tm_node *ns = np->parent_node;
3140 uint32_t subport_id = tm_node_subport_id(dev, ns);
3145 for (i = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++) {
3146 struct rte_sched_queue_stats s;
3149 uint32_t qid = tm_port_queue_id(dev,
3152 i / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
3153 i % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS);
3155 int status = rte_sched_queue_read_stats(SCHED(p),
3162 /* Stats accumulate */
3163 np->stats.n_pkts += s.n_pkts - s.n_pkts_dropped;
3164 np->stats.n_bytes += s.n_bytes - s.n_bytes_dropped;
3165 np->stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN] += s.n_pkts_dropped;
3166 np->stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN] +=
3168 np->stats.leaf.n_pkts_queued = qlen;
3173 memcpy(stats, &np->stats, sizeof(*stats));
3176 *stats_mask = STATS_MASK_DEFAULT;
3180 memset(&np->stats, 0, sizeof(np->stats));
3186 read_tc_stats(struct rte_eth_dev *dev,
3188 struct rte_tm_node_stats *stats,
3189 uint64_t *stats_mask,
3192 struct pmd_internals *p = dev->data->dev_private;
3194 uint32_t tc_id = tm_node_tc_id(dev, nt);
3196 struct tm_node *np = nt->parent_node;
3197 uint32_t pipe_id = tm_node_pipe_id(dev, np);
3199 struct tm_node *ns = np->parent_node;
3200 uint32_t subport_id = tm_node_subport_id(dev, ns);
3205 for (i = 0; i < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) {
3206 struct rte_sched_queue_stats s;
3209 uint32_t qid = tm_port_queue_id(dev,
3215 int status = rte_sched_queue_read_stats(SCHED(p),
3222 /* Stats accumulate */
3223 nt->stats.n_pkts += s.n_pkts - s.n_pkts_dropped;
3224 nt->stats.n_bytes += s.n_bytes - s.n_bytes_dropped;
3225 nt->stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN] += s.n_pkts_dropped;
3226 nt->stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN] +=
3228 nt->stats.leaf.n_pkts_queued = qlen;
3233 memcpy(stats, &nt->stats, sizeof(*stats));
3236 *stats_mask = STATS_MASK_DEFAULT;
3240 memset(&nt->stats, 0, sizeof(nt->stats));
3246 read_queue_stats(struct rte_eth_dev *dev,
3248 struct rte_tm_node_stats *stats,
3249 uint64_t *stats_mask,
3252 struct pmd_internals *p = dev->data->dev_private;
3253 struct rte_sched_queue_stats s;
3256 uint32_t queue_id = tm_node_queue_id(dev, nq);
3258 struct tm_node *nt = nq->parent_node;
3259 uint32_t tc_id = tm_node_tc_id(dev, nt);
3261 struct tm_node *np = nt->parent_node;
3262 uint32_t pipe_id = tm_node_pipe_id(dev, np);
3264 struct tm_node *ns = np->parent_node;
3265 uint32_t subport_id = tm_node_subport_id(dev, ns);
3268 uint32_t qid = tm_port_queue_id(dev,
3274 int status = rte_sched_queue_read_stats(SCHED(p),
3281 /* Stats accumulate */
3282 nq->stats.n_pkts += s.n_pkts - s.n_pkts_dropped;
3283 nq->stats.n_bytes += s.n_bytes - s.n_bytes_dropped;
3284 nq->stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN] += s.n_pkts_dropped;
3285 nq->stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN] +=
3287 nq->stats.leaf.n_pkts_queued = qlen;
3291 memcpy(stats, &nq->stats, sizeof(*stats));
3294 *stats_mask = STATS_MASK_QUEUE;
3298 memset(&nq->stats, 0, sizeof(nq->stats));
3303 /* Traffic manager read stats counters for specific node */
3305 pmd_tm_node_stats_read(struct rte_eth_dev *dev,
3307 struct rte_tm_node_stats *stats,
3308 uint64_t *stats_mask,
3310 struct rte_tm_error *error)
3314 /* Port must be started and TM used. */
3315 if (dev->data->dev_started == 0 && (tm_used(dev) == 0))
3316 return -rte_tm_error_set(error,
3318 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3320 rte_strerror(EBUSY));
3322 /* Node must be valid */
3323 n = tm_node_search(dev, node_id);
3325 return -rte_tm_error_set(error,
3327 RTE_TM_ERROR_TYPE_NODE_ID,
3329 rte_strerror(EINVAL));
3332 case TM_NODE_LEVEL_PORT:
3333 if (read_port_stats(dev, n, stats, stats_mask, clear))
3334 return -rte_tm_error_set(error,
3336 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3338 rte_strerror(EINVAL));
3341 case TM_NODE_LEVEL_SUBPORT:
3342 if (read_subport_stats(dev, n, stats, stats_mask, clear))
3343 return -rte_tm_error_set(error,
3345 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3347 rte_strerror(EINVAL));
3350 case TM_NODE_LEVEL_PIPE:
3351 if (read_pipe_stats(dev, n, stats, stats_mask, clear))
3352 return -rte_tm_error_set(error,
3354 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3356 rte_strerror(EINVAL));
3359 case TM_NODE_LEVEL_TC:
3360 if (read_tc_stats(dev, n, stats, stats_mask, clear))
3361 return -rte_tm_error_set(error,
3363 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3365 rte_strerror(EINVAL));
3368 case TM_NODE_LEVEL_QUEUE:
3370 if (read_queue_stats(dev, n, stats, stats_mask, clear))
3371 return -rte_tm_error_set(error,
3373 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3375 rte_strerror(EINVAL));
3380 const struct rte_tm_ops pmd_tm_ops = {
3381 .node_type_get = pmd_tm_node_type_get,
3382 .capabilities_get = pmd_tm_capabilities_get,
3383 .level_capabilities_get = pmd_tm_level_capabilities_get,
3384 .node_capabilities_get = pmd_tm_node_capabilities_get,
3386 .wred_profile_add = pmd_tm_wred_profile_add,
3387 .wred_profile_delete = pmd_tm_wred_profile_delete,
3388 .shared_wred_context_add_update = NULL,
3389 .shared_wred_context_delete = NULL,
3391 .shaper_profile_add = pmd_tm_shaper_profile_add,
3392 .shaper_profile_delete = pmd_tm_shaper_profile_delete,
3393 .shared_shaper_add_update = pmd_tm_shared_shaper_add_update,
3394 .shared_shaper_delete = pmd_tm_shared_shaper_delete,
3396 .node_add = pmd_tm_node_add,
3397 .node_delete = pmd_tm_node_delete,
3398 .node_suspend = NULL,
3399 .node_resume = NULL,
3400 .hierarchy_commit = pmd_tm_hierarchy_commit,
3402 .node_parent_update = pmd_tm_node_parent_update,
3403 .node_shaper_update = pmd_tm_node_shaper_update,
3404 .node_shared_shaper_update = NULL,
3405 .node_stats_update = NULL,
3406 .node_wfq_weight_mode_update = NULL,
3407 .node_cman_update = NULL,
3408 .node_wred_context_update = NULL,
3409 .node_shared_wred_context_update = NULL,
3411 .node_stats_read = pmd_tm_node_stats_read,