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 =
89 t->subport_params[subport_id].n_pipes_per_subport_enabled;
93 status = rte_sched_subport_config(sched,
95 &t->subport_params[subport_id],
96 t->subport_to_profile[subport_id]);
98 rte_sched_port_free(sched);
103 for (pipe_id = 0; pipe_id < n_pipes_per_subport; pipe_id++) {
104 int pos = subport_id * TM_MAX_PIPES_PER_SUBPORT + pipe_id;
105 int profile_id = t->pipe_to_profile[pos];
110 status = rte_sched_pipe_config(sched,
115 rte_sched_port_free(sched);
121 /* Node allocation */
122 tmgr_port = calloc(1, sizeof(struct softnic_tmgr_port));
123 if (tmgr_port == NULL) {
124 rte_sched_port_free(sched);
129 strlcpy(tmgr_port->name, name, sizeof(tmgr_port->name));
130 tmgr_port->s = sched;
132 /* Node add to list */
133 TAILQ_INSERT_TAIL(&p->tmgr_port_list, tmgr_port, node);
138 static struct rte_sched_port *
139 SCHED(struct pmd_internals *p)
141 struct softnic_tmgr_port *tmgr_port;
143 tmgr_port = softnic_tmgr_port_find(p, "TMGR");
144 if (tmgr_port == NULL)
151 tm_hierarchy_init(struct pmd_internals *p)
153 memset(&p->soft.tm, 0, sizeof(p->soft.tm));
155 /* Initialize shaper profile list */
156 TAILQ_INIT(&p->soft.tm.h.shaper_profiles);
158 /* Initialize shared shaper list */
159 TAILQ_INIT(&p->soft.tm.h.shared_shapers);
161 /* Initialize wred profile list */
162 TAILQ_INIT(&p->soft.tm.h.wred_profiles);
164 /* Initialize TM node list */
165 TAILQ_INIT(&p->soft.tm.h.nodes);
169 tm_hierarchy_free(struct pmd_internals *p)
171 /* Remove all nodes*/
173 struct tm_node *tm_node;
175 tm_node = TAILQ_FIRST(&p->soft.tm.h.nodes);
179 TAILQ_REMOVE(&p->soft.tm.h.nodes, tm_node, node);
183 /* Remove all WRED profiles */
185 struct tm_wred_profile *wred_profile;
187 wred_profile = TAILQ_FIRST(&p->soft.tm.h.wred_profiles);
188 if (wred_profile == NULL)
191 TAILQ_REMOVE(&p->soft.tm.h.wred_profiles, wred_profile, node);
195 /* Remove all shared shapers */
197 struct tm_shared_shaper *shared_shaper;
199 shared_shaper = TAILQ_FIRST(&p->soft.tm.h.shared_shapers);
200 if (shared_shaper == NULL)
203 TAILQ_REMOVE(&p->soft.tm.h.shared_shapers, shared_shaper, node);
207 /* Remove all shaper profiles */
209 struct tm_shaper_profile *shaper_profile;
211 shaper_profile = TAILQ_FIRST(&p->soft.tm.h.shaper_profiles);
212 if (shaper_profile == NULL)
215 TAILQ_REMOVE(&p->soft.tm.h.shaper_profiles,
216 shaper_profile, node);
217 free(shaper_profile);
220 tm_hierarchy_init(p);
223 static struct tm_shaper_profile *
224 tm_shaper_profile_search(struct rte_eth_dev *dev, uint32_t shaper_profile_id)
226 struct pmd_internals *p = dev->data->dev_private;
227 struct tm_shaper_profile_list *spl = &p->soft.tm.h.shaper_profiles;
228 struct tm_shaper_profile *sp;
230 TAILQ_FOREACH(sp, spl, node)
231 if (shaper_profile_id == sp->shaper_profile_id)
237 static struct tm_shared_shaper *
238 tm_shared_shaper_search(struct rte_eth_dev *dev, uint32_t shared_shaper_id)
240 struct pmd_internals *p = dev->data->dev_private;
241 struct tm_shared_shaper_list *ssl = &p->soft.tm.h.shared_shapers;
242 struct tm_shared_shaper *ss;
244 TAILQ_FOREACH(ss, ssl, node)
245 if (shared_shaper_id == ss->shared_shaper_id)
251 static struct tm_wred_profile *
252 tm_wred_profile_search(struct rte_eth_dev *dev, uint32_t wred_profile_id)
254 struct pmd_internals *p = dev->data->dev_private;
255 struct tm_wred_profile_list *wpl = &p->soft.tm.h.wred_profiles;
256 struct tm_wred_profile *wp;
258 TAILQ_FOREACH(wp, wpl, node)
259 if (wred_profile_id == wp->wred_profile_id)
265 static struct tm_node *
266 tm_node_search(struct rte_eth_dev *dev, uint32_t node_id)
268 struct pmd_internals *p = dev->data->dev_private;
269 struct tm_node_list *nl = &p->soft.tm.h.nodes;
272 TAILQ_FOREACH(n, nl, node)
273 if (n->node_id == node_id)
279 static struct tm_node *
280 tm_root_node_present(struct rte_eth_dev *dev)
282 struct pmd_internals *p = dev->data->dev_private;
283 struct tm_node_list *nl = &p->soft.tm.h.nodes;
286 TAILQ_FOREACH(n, nl, node)
287 if (n->parent_node_id == RTE_TM_NODE_ID_NULL)
294 tm_node_subport_id(struct rte_eth_dev *dev, struct tm_node *subport_node)
296 struct pmd_internals *p = dev->data->dev_private;
297 struct tm_node_list *nl = &p->soft.tm.h.nodes;
302 TAILQ_FOREACH(ns, nl, node) {
303 if (ns->level != TM_NODE_LEVEL_SUBPORT)
306 if (ns->node_id == subport_node->node_id)
316 tm_node_pipe_id(struct rte_eth_dev *dev, struct tm_node *pipe_node)
318 struct pmd_internals *p = dev->data->dev_private;
319 struct tm_node_list *nl = &p->soft.tm.h.nodes;
324 TAILQ_FOREACH(np, nl, node) {
325 if (np->level != TM_NODE_LEVEL_PIPE ||
326 np->parent_node_id != pipe_node->parent_node_id)
329 if (np->node_id == pipe_node->node_id)
339 tm_node_tc_id(struct rte_eth_dev *dev __rte_unused, struct tm_node *tc_node)
341 return tc_node->priority;
345 tm_node_queue_id(struct rte_eth_dev *dev, struct tm_node *queue_node)
347 struct pmd_internals *p = dev->data->dev_private;
348 struct tm_node_list *nl = &p->soft.tm.h.nodes;
353 TAILQ_FOREACH(nq, nl, node) {
354 if (nq->level != TM_NODE_LEVEL_QUEUE ||
355 nq->parent_node_id != queue_node->parent_node_id)
358 if (nq->node_id == queue_node->node_id)
368 tm_level_get_max_nodes(struct rte_eth_dev *dev, enum tm_node_level level)
370 struct pmd_internals *p = dev->data->dev_private;
371 uint32_t n_queues_max = p->params.tm.n_queues;
373 (n_queues_max * RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
374 / RTE_SCHED_QUEUES_PER_PIPE;
375 uint32_t n_pipes_max = n_tc_max / RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE;
376 uint32_t n_subports_max = n_pipes_max;
377 uint32_t n_root_max = 1;
380 case TM_NODE_LEVEL_PORT:
382 case TM_NODE_LEVEL_SUBPORT:
383 return n_subports_max;
384 case TM_NODE_LEVEL_PIPE:
386 case TM_NODE_LEVEL_TC:
388 case TM_NODE_LEVEL_QUEUE:
394 /* Traffic manager node type get */
396 pmd_tm_node_type_get(struct rte_eth_dev *dev,
399 struct rte_tm_error *error)
401 struct pmd_internals *p = dev->data->dev_private;
404 return -rte_tm_error_set(error,
406 RTE_TM_ERROR_TYPE_UNSPECIFIED,
408 rte_strerror(EINVAL));
410 if (node_id == RTE_TM_NODE_ID_NULL ||
411 (tm_node_search(dev, node_id) == NULL))
412 return -rte_tm_error_set(error,
414 RTE_TM_ERROR_TYPE_NODE_ID,
416 rte_strerror(EINVAL));
418 *is_leaf = node_id < p->params.tm.n_queues;
424 #define WRED_SUPPORTED 1
426 #define WRED_SUPPORTED 0
429 #define STATS_MASK_DEFAULT \
430 (RTE_TM_STATS_N_PKTS | \
431 RTE_TM_STATS_N_BYTES | \
432 RTE_TM_STATS_N_PKTS_GREEN_DROPPED | \
433 RTE_TM_STATS_N_BYTES_GREEN_DROPPED)
435 #define STATS_MASK_QUEUE \
436 (STATS_MASK_DEFAULT | \
437 RTE_TM_STATS_N_PKTS_QUEUED)
439 static const struct rte_tm_capabilities tm_cap = {
440 .n_nodes_max = UINT32_MAX,
441 .n_levels_max = TM_NODE_LEVEL_MAX,
443 .non_leaf_nodes_identical = 0,
444 .leaf_nodes_identical = 1,
446 .shaper_n_max = UINT32_MAX,
447 .shaper_private_n_max = UINT32_MAX,
448 .shaper_private_dual_rate_n_max = 0,
449 .shaper_private_rate_min = 1,
450 .shaper_private_rate_max = UINT32_MAX,
451 .shaper_private_packet_mode_supported = 0,
452 .shaper_private_byte_mode_supported = 1,
454 .shaper_shared_n_max = UINT32_MAX,
455 .shaper_shared_n_nodes_per_shaper_max = UINT32_MAX,
456 .shaper_shared_n_shapers_per_node_max = 1,
457 .shaper_shared_dual_rate_n_max = 0,
458 .shaper_shared_rate_min = 1,
459 .shaper_shared_rate_max = UINT32_MAX,
460 .shaper_shared_packet_mode_supported = 0,
461 .shaper_shared_byte_mode_supported = 1,
463 .shaper_pkt_length_adjust_min = RTE_TM_ETH_FRAMING_OVERHEAD_FCS,
464 .shaper_pkt_length_adjust_max = RTE_TM_ETH_FRAMING_OVERHEAD_FCS,
466 .sched_n_children_max = UINT32_MAX,
467 .sched_sp_n_priorities_max = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
468 .sched_wfq_n_children_per_group_max = UINT32_MAX,
469 .sched_wfq_n_groups_max = 1,
470 .sched_wfq_weight_max = UINT32_MAX,
471 .sched_wfq_packet_mode_supported = 0,
472 .sched_wfq_byte_mode_supported = 1,
474 .cman_wred_packet_mode_supported = WRED_SUPPORTED,
475 .cman_wred_byte_mode_supported = 0,
476 .cman_head_drop_supported = 0,
477 .cman_wred_context_n_max = 0,
478 .cman_wred_context_private_n_max = 0,
479 .cman_wred_context_shared_n_max = 0,
480 .cman_wred_context_shared_n_nodes_per_context_max = 0,
481 .cman_wred_context_shared_n_contexts_per_node_max = 0,
483 .mark_vlan_dei_supported = {0, 0, 0},
484 .mark_ip_ecn_tcp_supported = {0, 0, 0},
485 .mark_ip_ecn_sctp_supported = {0, 0, 0},
486 .mark_ip_dscp_supported = {0, 0, 0},
488 .dynamic_update_mask = 0,
490 .stats_mask = STATS_MASK_QUEUE,
493 /* Traffic manager capabilities get */
495 pmd_tm_capabilities_get(struct rte_eth_dev *dev __rte_unused,
496 struct rte_tm_capabilities *cap,
497 struct rte_tm_error *error)
500 return -rte_tm_error_set(error,
502 RTE_TM_ERROR_TYPE_CAPABILITIES,
504 rte_strerror(EINVAL));
506 memcpy(cap, &tm_cap, sizeof(*cap));
508 cap->n_nodes_max = tm_level_get_max_nodes(dev, TM_NODE_LEVEL_PORT) +
509 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_SUBPORT) +
510 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_PIPE) +
511 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_TC) +
512 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_QUEUE);
514 cap->shaper_private_n_max =
515 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_PORT) +
516 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_SUBPORT) +
517 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_PIPE) +
518 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_TC);
520 cap->shaper_shared_n_max = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE *
521 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_SUBPORT);
523 cap->shaper_n_max = cap->shaper_private_n_max +
524 cap->shaper_shared_n_max;
526 cap->shaper_shared_n_nodes_per_shaper_max =
527 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_PIPE);
529 cap->sched_n_children_max = RTE_MAX(
530 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_PIPE),
531 (uint32_t)RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE);
533 cap->sched_wfq_n_children_per_group_max = cap->sched_n_children_max;
536 cap->cman_wred_context_private_n_max =
537 tm_level_get_max_nodes(dev, TM_NODE_LEVEL_QUEUE);
539 cap->cman_wred_context_n_max = cap->cman_wred_context_private_n_max +
540 cap->cman_wred_context_shared_n_max;
545 static const struct rte_tm_level_capabilities tm_level_cap[] = {
546 [TM_NODE_LEVEL_PORT] = {
548 .n_nodes_nonleaf_max = 1,
549 .n_nodes_leaf_max = 0,
550 .non_leaf_nodes_identical = 1,
551 .leaf_nodes_identical = 0,
554 .shaper_private_supported = 1,
555 .shaper_private_dual_rate_supported = 0,
556 .shaper_private_rate_min = 1,
557 .shaper_private_rate_max = UINT32_MAX,
558 .shaper_private_packet_mode_supported = 0,
559 .shaper_private_byte_mode_supported = 1,
560 .shaper_shared_n_max = 0,
561 .shaper_shared_packet_mode_supported = 0,
562 .shaper_shared_byte_mode_supported = 0,
564 .sched_n_children_max = UINT32_MAX,
565 .sched_sp_n_priorities_max = 1,
566 .sched_wfq_n_children_per_group_max = UINT32_MAX,
567 .sched_wfq_n_groups_max = 1,
568 .sched_wfq_weight_max = 1,
569 .sched_wfq_packet_mode_supported = 0,
570 .sched_wfq_byte_mode_supported = 1,
572 .stats_mask = STATS_MASK_DEFAULT,
576 [TM_NODE_LEVEL_SUBPORT] = {
577 .n_nodes_max = UINT32_MAX,
578 .n_nodes_nonleaf_max = UINT32_MAX,
579 .n_nodes_leaf_max = 0,
580 .non_leaf_nodes_identical = 1,
581 .leaf_nodes_identical = 0,
584 .shaper_private_supported = 1,
585 .shaper_private_dual_rate_supported = 0,
586 .shaper_private_rate_min = 1,
587 .shaper_private_rate_max = UINT32_MAX,
588 .shaper_private_packet_mode_supported = 0,
589 .shaper_private_byte_mode_supported = 1,
590 .shaper_shared_n_max = 0,
591 .shaper_shared_packet_mode_supported = 0,
592 .shaper_shared_byte_mode_supported = 0,
594 .sched_n_children_max = UINT32_MAX,
595 .sched_sp_n_priorities_max = 1,
596 .sched_wfq_n_children_per_group_max = UINT32_MAX,
597 .sched_wfq_n_groups_max = 1,
598 #ifdef RTE_SCHED_SUBPORT_TC_OV
599 .sched_wfq_weight_max = UINT32_MAX,
600 .sched_wfq_packet_mode_supported = 0,
601 .sched_wfq_byte_mode_supported = 1,
603 .sched_wfq_weight_max = 1,
604 .sched_wfq_packet_mode_supported = 0,
605 .sched_wfq_byte_mode_supported = 1,
608 .stats_mask = STATS_MASK_DEFAULT,
612 [TM_NODE_LEVEL_PIPE] = {
613 .n_nodes_max = UINT32_MAX,
614 .n_nodes_nonleaf_max = UINT32_MAX,
615 .n_nodes_leaf_max = 0,
616 .non_leaf_nodes_identical = 1,
617 .leaf_nodes_identical = 0,
620 .shaper_private_supported = 1,
621 .shaper_private_dual_rate_supported = 0,
622 .shaper_private_rate_min = 1,
623 .shaper_private_rate_max = UINT32_MAX,
624 .shaper_private_packet_mode_supported = 0,
625 .shaper_private_byte_mode_supported = 1,
626 .shaper_shared_n_max = 0,
627 .shaper_shared_packet_mode_supported = 0,
628 .shaper_shared_byte_mode_supported = 0,
630 .sched_n_children_max =
631 RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
632 .sched_sp_n_priorities_max =
633 RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
634 .sched_wfq_n_children_per_group_max = 1,
635 .sched_wfq_n_groups_max = 0,
636 .sched_wfq_weight_max = 1,
637 .sched_wfq_packet_mode_supported = 0,
638 .sched_wfq_byte_mode_supported = 0,
640 .stats_mask = STATS_MASK_DEFAULT,
644 [TM_NODE_LEVEL_TC] = {
645 .n_nodes_max = UINT32_MAX,
646 .n_nodes_nonleaf_max = UINT32_MAX,
647 .n_nodes_leaf_max = 0,
648 .non_leaf_nodes_identical = 1,
649 .leaf_nodes_identical = 0,
652 .shaper_private_supported = 1,
653 .shaper_private_dual_rate_supported = 0,
654 .shaper_private_rate_min = 1,
655 .shaper_private_rate_max = UINT32_MAX,
656 .shaper_private_packet_mode_supported = 0,
657 .shaper_private_byte_mode_supported = 1,
658 .shaper_shared_n_max = 1,
659 .shaper_shared_packet_mode_supported = 0,
660 .shaper_shared_byte_mode_supported = 1,
662 .sched_n_children_max =
663 RTE_SCHED_BE_QUEUES_PER_PIPE,
664 .sched_sp_n_priorities_max = 1,
665 .sched_wfq_n_children_per_group_max =
666 RTE_SCHED_BE_QUEUES_PER_PIPE,
667 .sched_wfq_n_groups_max = 1,
668 .sched_wfq_weight_max = UINT32_MAX,
669 .sched_wfq_packet_mode_supported = 0,
670 .sched_wfq_byte_mode_supported = 1,
672 .stats_mask = STATS_MASK_DEFAULT,
676 [TM_NODE_LEVEL_QUEUE] = {
677 .n_nodes_max = UINT32_MAX,
678 .n_nodes_nonleaf_max = 0,
679 .n_nodes_leaf_max = UINT32_MAX,
680 .non_leaf_nodes_identical = 0,
681 .leaf_nodes_identical = 1,
684 .shaper_private_supported = 0,
685 .shaper_private_dual_rate_supported = 0,
686 .shaper_private_rate_min = 0,
687 .shaper_private_rate_max = 0,
688 .shaper_private_packet_mode_supported = 0,
689 .shaper_private_byte_mode_supported = 0,
690 .shaper_shared_n_max = 0,
691 .shaper_shared_packet_mode_supported = 0,
692 .shaper_shared_byte_mode_supported = 0,
694 .cman_head_drop_supported = 0,
695 .cman_wred_packet_mode_supported = WRED_SUPPORTED,
696 .cman_wred_byte_mode_supported = 0,
697 .cman_wred_context_private_supported = WRED_SUPPORTED,
698 .cman_wred_context_shared_n_max = 0,
700 .stats_mask = STATS_MASK_QUEUE,
705 /* Traffic manager level capabilities get */
707 pmd_tm_level_capabilities_get(struct rte_eth_dev *dev __rte_unused,
709 struct rte_tm_level_capabilities *cap,
710 struct rte_tm_error *error)
713 return -rte_tm_error_set(error,
715 RTE_TM_ERROR_TYPE_CAPABILITIES,
717 rte_strerror(EINVAL));
719 if (level_id >= TM_NODE_LEVEL_MAX)
720 return -rte_tm_error_set(error,
722 RTE_TM_ERROR_TYPE_LEVEL_ID,
724 rte_strerror(EINVAL));
726 memcpy(cap, &tm_level_cap[level_id], sizeof(*cap));
729 case TM_NODE_LEVEL_PORT:
730 cap->nonleaf.sched_n_children_max =
731 tm_level_get_max_nodes(dev,
732 TM_NODE_LEVEL_SUBPORT);
733 cap->nonleaf.sched_wfq_n_children_per_group_max =
734 cap->nonleaf.sched_n_children_max;
737 case TM_NODE_LEVEL_SUBPORT:
738 cap->n_nodes_max = tm_level_get_max_nodes(dev,
739 TM_NODE_LEVEL_SUBPORT);
740 cap->n_nodes_nonleaf_max = cap->n_nodes_max;
741 cap->nonleaf.sched_n_children_max =
742 tm_level_get_max_nodes(dev,
744 cap->nonleaf.sched_wfq_n_children_per_group_max =
745 cap->nonleaf.sched_n_children_max;
748 case TM_NODE_LEVEL_PIPE:
749 cap->n_nodes_max = tm_level_get_max_nodes(dev,
751 cap->n_nodes_nonleaf_max = cap->n_nodes_max;
754 case TM_NODE_LEVEL_TC:
755 cap->n_nodes_max = tm_level_get_max_nodes(dev,
757 cap->n_nodes_nonleaf_max = cap->n_nodes_max;
760 case TM_NODE_LEVEL_QUEUE:
762 cap->n_nodes_max = tm_level_get_max_nodes(dev,
763 TM_NODE_LEVEL_QUEUE);
764 cap->n_nodes_leaf_max = cap->n_nodes_max;
771 static const struct rte_tm_node_capabilities tm_node_cap[] = {
772 [TM_NODE_LEVEL_PORT] = {
773 .shaper_private_supported = 1,
774 .shaper_private_dual_rate_supported = 0,
775 .shaper_private_rate_min = 1,
776 .shaper_private_rate_max = UINT32_MAX,
777 .shaper_private_packet_mode_supported = 0,
778 .shaper_private_byte_mode_supported = 1,
779 .shaper_shared_n_max = 0,
780 .shaper_shared_packet_mode_supported = 0,
781 .shaper_shared_byte_mode_supported = 0,
784 .sched_n_children_max = UINT32_MAX,
785 .sched_sp_n_priorities_max = 1,
786 .sched_wfq_n_children_per_group_max = UINT32_MAX,
787 .sched_wfq_n_groups_max = 1,
788 .sched_wfq_weight_max = 1,
789 .sched_wfq_packet_mode_supported = 0,
790 .sched_wfq_byte_mode_supported = 1,
793 .stats_mask = STATS_MASK_DEFAULT,
796 [TM_NODE_LEVEL_SUBPORT] = {
797 .shaper_private_supported = 1,
798 .shaper_private_dual_rate_supported = 0,
799 .shaper_private_rate_min = 1,
800 .shaper_private_rate_max = UINT32_MAX,
801 .shaper_private_packet_mode_supported = 0,
802 .shaper_private_byte_mode_supported = 1,
803 .shaper_shared_n_max = 0,
804 .shaper_shared_packet_mode_supported = 0,
805 .shaper_shared_byte_mode_supported = 0,
808 .sched_n_children_max = UINT32_MAX,
809 .sched_sp_n_priorities_max = 1,
810 .sched_wfq_n_children_per_group_max = UINT32_MAX,
811 .sched_wfq_n_groups_max = 1,
812 .sched_wfq_weight_max = UINT32_MAX,
813 .sched_wfq_packet_mode_supported = 0,
814 .sched_wfq_byte_mode_supported = 1,
817 .stats_mask = STATS_MASK_DEFAULT,
820 [TM_NODE_LEVEL_PIPE] = {
821 .shaper_private_supported = 1,
822 .shaper_private_dual_rate_supported = 0,
823 .shaper_private_rate_min = 1,
824 .shaper_private_rate_max = UINT32_MAX,
825 .shaper_private_packet_mode_supported = 0,
826 .shaper_private_byte_mode_supported = 1,
827 .shaper_shared_n_max = 0,
828 .shaper_shared_packet_mode_supported = 0,
829 .shaper_shared_byte_mode_supported = 0,
832 .sched_n_children_max =
833 RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
834 .sched_sp_n_priorities_max =
835 RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
836 .sched_wfq_n_children_per_group_max = 1,
837 .sched_wfq_n_groups_max = 0,
838 .sched_wfq_weight_max = 1,
839 .sched_wfq_packet_mode_supported = 0,
840 .sched_wfq_byte_mode_supported = 0,
843 .stats_mask = STATS_MASK_DEFAULT,
846 [TM_NODE_LEVEL_TC] = {
847 .shaper_private_supported = 1,
848 .shaper_private_dual_rate_supported = 0,
849 .shaper_private_rate_min = 1,
850 .shaper_private_rate_max = UINT32_MAX,
851 .shaper_private_packet_mode_supported = 0,
852 .shaper_private_byte_mode_supported = 1,
853 .shaper_shared_n_max = 1,
854 .shaper_shared_packet_mode_supported = 0,
855 .shaper_shared_byte_mode_supported = 1,
858 .sched_n_children_max =
859 RTE_SCHED_BE_QUEUES_PER_PIPE,
860 .sched_sp_n_priorities_max = 1,
861 .sched_wfq_n_children_per_group_max =
862 RTE_SCHED_BE_QUEUES_PER_PIPE,
863 .sched_wfq_n_groups_max = 1,
864 .sched_wfq_weight_max = UINT32_MAX,
865 .sched_wfq_packet_mode_supported = 0,
866 .sched_wfq_byte_mode_supported = 1,
869 .stats_mask = STATS_MASK_DEFAULT,
872 [TM_NODE_LEVEL_QUEUE] = {
873 .shaper_private_supported = 0,
874 .shaper_private_dual_rate_supported = 0,
875 .shaper_private_rate_min = 0,
876 .shaper_private_rate_max = 0,
877 .shaper_private_packet_mode_supported = 0,
878 .shaper_private_byte_mode_supported = 0,
879 .shaper_shared_n_max = 0,
880 .shaper_shared_packet_mode_supported = 0,
881 .shaper_shared_byte_mode_supported = 0,
885 .cman_head_drop_supported = 0,
886 .cman_wred_packet_mode_supported = WRED_SUPPORTED,
887 .cman_wred_byte_mode_supported = 0,
888 .cman_wred_context_private_supported = WRED_SUPPORTED,
889 .cman_wred_context_shared_n_max = 0,
892 .stats_mask = STATS_MASK_QUEUE,
896 /* Traffic manager node capabilities get */
898 pmd_tm_node_capabilities_get(struct rte_eth_dev *dev __rte_unused,
900 struct rte_tm_node_capabilities *cap,
901 struct rte_tm_error *error)
903 struct tm_node *tm_node;
906 return -rte_tm_error_set(error,
908 RTE_TM_ERROR_TYPE_CAPABILITIES,
910 rte_strerror(EINVAL));
912 tm_node = tm_node_search(dev, node_id);
914 return -rte_tm_error_set(error,
916 RTE_TM_ERROR_TYPE_NODE_ID,
918 rte_strerror(EINVAL));
920 memcpy(cap, &tm_node_cap[tm_node->level], sizeof(*cap));
922 switch (tm_node->level) {
923 case TM_NODE_LEVEL_PORT:
924 cap->nonleaf.sched_n_children_max =
925 tm_level_get_max_nodes(dev,
926 TM_NODE_LEVEL_SUBPORT);
927 cap->nonleaf.sched_wfq_n_children_per_group_max =
928 cap->nonleaf.sched_n_children_max;
931 case TM_NODE_LEVEL_SUBPORT:
932 cap->nonleaf.sched_n_children_max =
933 tm_level_get_max_nodes(dev,
935 cap->nonleaf.sched_wfq_n_children_per_group_max =
936 cap->nonleaf.sched_n_children_max;
939 case TM_NODE_LEVEL_PIPE:
940 case TM_NODE_LEVEL_TC:
941 case TM_NODE_LEVEL_QUEUE:
950 shaper_profile_check(struct rte_eth_dev *dev,
951 uint32_t shaper_profile_id,
952 struct rte_tm_shaper_params *profile,
953 struct rte_tm_error *error)
955 struct tm_shaper_profile *sp;
957 /* Shaper profile ID must not be NONE. */
958 if (shaper_profile_id == RTE_TM_SHAPER_PROFILE_ID_NONE)
959 return -rte_tm_error_set(error,
961 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,
963 rte_strerror(EINVAL));
965 /* Shaper profile must not exist. */
966 sp = tm_shaper_profile_search(dev, shaper_profile_id);
968 return -rte_tm_error_set(error,
970 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,
972 rte_strerror(EEXIST));
974 /* Profile must not be NULL. */
976 return -rte_tm_error_set(error,
978 RTE_TM_ERROR_TYPE_SHAPER_PROFILE,
980 rte_strerror(EINVAL));
982 /* Peak rate: non-zero, 32-bit */
983 if (profile->peak.rate == 0 ||
984 profile->peak.rate >= UINT32_MAX)
985 return -rte_tm_error_set(error,
987 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_RATE,
989 rte_strerror(EINVAL));
991 /* Peak size: non-zero, 32-bit */
992 if (profile->peak.size == 0 ||
993 profile->peak.size >= UINT32_MAX)
994 return -rte_tm_error_set(error,
996 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE,
998 rte_strerror(EINVAL));
1000 /* Dual-rate profiles are not supported. */
1001 if (profile->committed.rate != 0)
1002 return -rte_tm_error_set(error,
1004 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE,
1006 rte_strerror(EINVAL));
1008 /* Packet length adjust: 24 bytes */
1009 if (profile->pkt_length_adjust != RTE_TM_ETH_FRAMING_OVERHEAD_FCS)
1010 return -rte_tm_error_set(error,
1012 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PKT_ADJUST_LEN,
1014 rte_strerror(EINVAL));
1016 /* Packet mode is not supported. */
1017 if (profile->packet_mode != 0)
1018 return -rte_tm_error_set(error,
1020 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PACKET_MODE,
1022 rte_strerror(EINVAL));
1026 /* Traffic manager shaper profile add */
1028 pmd_tm_shaper_profile_add(struct rte_eth_dev *dev,
1029 uint32_t shaper_profile_id,
1030 struct rte_tm_shaper_params *profile,
1031 struct rte_tm_error *error)
1033 struct pmd_internals *p = dev->data->dev_private;
1034 struct tm_shaper_profile_list *spl = &p->soft.tm.h.shaper_profiles;
1035 struct tm_shaper_profile *sp;
1038 /* Check input params */
1039 status = shaper_profile_check(dev, shaper_profile_id, profile, error);
1043 /* Memory allocation */
1044 sp = calloc(1, sizeof(struct tm_shaper_profile));
1046 return -rte_tm_error_set(error,
1048 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1050 rte_strerror(ENOMEM));
1053 sp->shaper_profile_id = shaper_profile_id;
1054 memcpy(&sp->params, profile, sizeof(sp->params));
1057 TAILQ_INSERT_TAIL(spl, sp, node);
1058 p->soft.tm.h.n_shaper_profiles++;
1063 /* Traffic manager shaper profile delete */
1065 pmd_tm_shaper_profile_delete(struct rte_eth_dev *dev,
1066 uint32_t shaper_profile_id,
1067 struct rte_tm_error *error)
1069 struct pmd_internals *p = dev->data->dev_private;
1070 struct tm_shaper_profile *sp;
1072 /* Check existing */
1073 sp = tm_shaper_profile_search(dev, shaper_profile_id);
1075 return -rte_tm_error_set(error,
1077 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,
1079 rte_strerror(EINVAL));
1083 return -rte_tm_error_set(error,
1085 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,
1087 rte_strerror(EBUSY));
1089 /* Remove from list */
1090 TAILQ_REMOVE(&p->soft.tm.h.shaper_profiles, sp, node);
1091 p->soft.tm.h.n_shaper_profiles--;
1097 static struct tm_node *
1098 tm_shared_shaper_get_tc(struct rte_eth_dev *dev,
1099 struct tm_shared_shaper *ss)
1101 struct pmd_internals *p = dev->data->dev_private;
1102 struct tm_node_list *nl = &p->soft.tm.h.nodes;
1105 /* Subport: each TC uses shared shaper */
1106 TAILQ_FOREACH(n, nl, node) {
1107 if (n->level != TM_NODE_LEVEL_TC ||
1108 n->params.n_shared_shapers == 0 ||
1109 n->params.shared_shaper_id[0] != ss->shared_shaper_id)
1119 subport_profile_exists(struct rte_eth_dev *dev,
1120 struct rte_sched_subport_profile_params *sp,
1121 uint32_t *subport_profile_id)
1123 struct pmd_internals *p = dev->data->dev_private;
1124 struct tm_params *t = &p->soft.tm.params;
1127 for (i = 0; i < t->n_subport_profiles; i++)
1128 if (memcmp(&t->subport_profile[i], sp, sizeof(*sp)) == 0) {
1129 if (subport_profile_id)
1130 *subport_profile_id = i;
1138 update_subport_tc_rate(struct rte_eth_dev *dev,
1140 struct tm_shared_shaper *ss,
1141 struct tm_shaper_profile *sp_new)
1143 struct rte_sched_subport_profile_params subport_profile;
1144 struct pmd_internals *p = dev->data->dev_private;
1145 uint32_t tc_id = tm_node_tc_id(dev, nt);
1146 struct tm_node *np = nt->parent_node;
1147 struct tm_node *ns = np->parent_node;
1148 uint32_t subport_id = tm_node_subport_id(dev, ns);
1149 struct tm_params *t = &p->soft.tm.params;
1150 uint32_t subport_profile_id;
1151 struct tm_shaper_profile *sp_old = tm_shaper_profile_search(dev,
1152 ss->shaper_profile_id);
1154 if (subport_id >= TM_MAX_SUBPORT_PROFILE)
1157 subport_profile_id = t->subport_to_profile[subport_id];
1159 /* Derive new subport configuration. */
1160 memcpy(&subport_profile,
1161 &p->soft.tm.params.subport_profile[subport_profile_id],
1162 sizeof(subport_profile));
1163 subport_profile.tc_rate[tc_id] = sp_new->params.peak.rate;
1165 /* Update the subport configuration. */
1166 if (rte_sched_subport_config(SCHED(p),
1167 subport_id, NULL, subport_profile_id))
1170 /* Commit changes. */
1173 ss->shaper_profile_id = sp_new->shaper_profile_id;
1176 memcpy(&p->soft.tm.params.subport_profile[subport_profile_id],
1178 sizeof(subport_profile));
1183 /* Traffic manager shared shaper add/update */
1185 pmd_tm_shared_shaper_add_update(struct rte_eth_dev *dev,
1186 uint32_t shared_shaper_id,
1187 uint32_t shaper_profile_id,
1188 struct rte_tm_error *error)
1190 struct pmd_internals *p = dev->data->dev_private;
1191 struct tm_shared_shaper *ss;
1192 struct tm_shaper_profile *sp;
1195 /* Shaper profile must be valid. */
1196 sp = tm_shaper_profile_search(dev, shaper_profile_id);
1198 return -rte_tm_error_set(error,
1200 RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,
1202 rte_strerror(EINVAL));
1205 * Add new shared shaper
1207 ss = tm_shared_shaper_search(dev, shared_shaper_id);
1209 struct tm_shared_shaper_list *ssl =
1210 &p->soft.tm.h.shared_shapers;
1212 /* Hierarchy must not be frozen */
1213 if (p->soft.tm.hierarchy_frozen)
1214 return -rte_tm_error_set(error,
1216 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1218 rte_strerror(EBUSY));
1220 /* Memory allocation */
1221 ss = calloc(1, sizeof(struct tm_shared_shaper));
1223 return -rte_tm_error_set(error,
1225 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1227 rte_strerror(ENOMEM));
1230 ss->shared_shaper_id = shared_shaper_id;
1231 ss->shaper_profile_id = shaper_profile_id;
1234 TAILQ_INSERT_TAIL(ssl, ss, node);
1235 p->soft.tm.h.n_shared_shapers++;
1241 * Update existing shared shaper
1243 /* Hierarchy must be frozen (run-time update) */
1244 if (p->soft.tm.hierarchy_frozen == 0)
1245 return -rte_tm_error_set(error,
1247 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1249 rte_strerror(EBUSY));
1252 /* Propagate change. */
1253 nt = tm_shared_shaper_get_tc(dev, ss);
1254 if (update_subport_tc_rate(dev, nt, ss, sp))
1255 return -rte_tm_error_set(error,
1257 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1259 rte_strerror(EINVAL));
1264 /* Traffic manager shared shaper delete */
1266 pmd_tm_shared_shaper_delete(struct rte_eth_dev *dev,
1267 uint32_t shared_shaper_id,
1268 struct rte_tm_error *error)
1270 struct pmd_internals *p = dev->data->dev_private;
1271 struct tm_shared_shaper *ss;
1273 /* Check existing */
1274 ss = tm_shared_shaper_search(dev, shared_shaper_id);
1276 return -rte_tm_error_set(error,
1278 RTE_TM_ERROR_TYPE_SHARED_SHAPER_ID,
1280 rte_strerror(EINVAL));
1284 return -rte_tm_error_set(error,
1286 RTE_TM_ERROR_TYPE_SHARED_SHAPER_ID,
1288 rte_strerror(EBUSY));
1290 /* Remove from list */
1291 TAILQ_REMOVE(&p->soft.tm.h.shared_shapers, ss, node);
1292 p->soft.tm.h.n_shared_shapers--;
1299 wred_profile_check(struct rte_eth_dev *dev,
1300 uint32_t wred_profile_id,
1301 struct rte_tm_wred_params *profile,
1302 struct rte_tm_error *error)
1304 struct tm_wred_profile *wp;
1305 enum rte_color color;
1307 /* WRED profile ID must not be NONE. */
1308 if (wred_profile_id == RTE_TM_WRED_PROFILE_ID_NONE)
1309 return -rte_tm_error_set(error,
1311 RTE_TM_ERROR_TYPE_WRED_PROFILE_ID,
1313 rte_strerror(EINVAL));
1315 /* WRED profile must not exist. */
1316 wp = tm_wred_profile_search(dev, wred_profile_id);
1318 return -rte_tm_error_set(error,
1320 RTE_TM_ERROR_TYPE_WRED_PROFILE_ID,
1322 rte_strerror(EEXIST));
1324 /* Profile must not be NULL. */
1325 if (profile == NULL)
1326 return -rte_tm_error_set(error,
1328 RTE_TM_ERROR_TYPE_WRED_PROFILE,
1330 rte_strerror(EINVAL));
1332 /* WRED profile should be in packet mode */
1333 if (profile->packet_mode == 0)
1334 return -rte_tm_error_set(error,
1336 RTE_TM_ERROR_TYPE_WRED_PROFILE,
1338 rte_strerror(ENOTSUP));
1340 /* min_th <= max_th, max_th > 0 */
1341 for (color = RTE_COLOR_GREEN; color < RTE_COLORS; color++) {
1342 uint32_t min_th = profile->red_params[color].min_th;
1343 uint32_t max_th = profile->red_params[color].max_th;
1345 if (min_th > max_th ||
1347 min_th > UINT16_MAX ||
1348 max_th > UINT16_MAX)
1349 return -rte_tm_error_set(error,
1351 RTE_TM_ERROR_TYPE_WRED_PROFILE,
1353 rte_strerror(EINVAL));
1359 /* Traffic manager WRED profile add */
1361 pmd_tm_wred_profile_add(struct rte_eth_dev *dev,
1362 uint32_t wred_profile_id,
1363 struct rte_tm_wred_params *profile,
1364 struct rte_tm_error *error)
1366 struct pmd_internals *p = dev->data->dev_private;
1367 struct tm_wred_profile_list *wpl = &p->soft.tm.h.wred_profiles;
1368 struct tm_wred_profile *wp;
1371 /* Check input params */
1372 status = wred_profile_check(dev, wred_profile_id, profile, error);
1376 /* Memory allocation */
1377 wp = calloc(1, sizeof(struct tm_wred_profile));
1379 return -rte_tm_error_set(error,
1381 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1383 rte_strerror(ENOMEM));
1386 wp->wred_profile_id = wred_profile_id;
1387 memcpy(&wp->params, profile, sizeof(wp->params));
1390 TAILQ_INSERT_TAIL(wpl, wp, node);
1391 p->soft.tm.h.n_wred_profiles++;
1396 /* Traffic manager WRED profile delete */
1398 pmd_tm_wred_profile_delete(struct rte_eth_dev *dev,
1399 uint32_t wred_profile_id,
1400 struct rte_tm_error *error)
1402 struct pmd_internals *p = dev->data->dev_private;
1403 struct tm_wred_profile *wp;
1405 /* Check existing */
1406 wp = tm_wred_profile_search(dev, wred_profile_id);
1408 return -rte_tm_error_set(error,
1410 RTE_TM_ERROR_TYPE_WRED_PROFILE_ID,
1412 rte_strerror(EINVAL));
1416 return -rte_tm_error_set(error,
1418 RTE_TM_ERROR_TYPE_WRED_PROFILE_ID,
1420 rte_strerror(EBUSY));
1422 /* Remove from list */
1423 TAILQ_REMOVE(&p->soft.tm.h.wred_profiles, wp, node);
1424 p->soft.tm.h.n_wred_profiles--;
1431 node_add_check_port(struct rte_eth_dev *dev,
1433 uint32_t parent_node_id __rte_unused,
1436 uint32_t level_id __rte_unused,
1437 struct rte_tm_node_params *params,
1438 struct rte_tm_error *error)
1440 struct pmd_internals *p = dev->data->dev_private;
1441 struct tm_shaper_profile *sp = tm_shaper_profile_search(dev,
1442 params->shaper_profile_id);
1444 /* node type: non-leaf */
1445 if (node_id < p->params.tm.n_queues)
1446 return -rte_tm_error_set(error,
1448 RTE_TM_ERROR_TYPE_NODE_ID,
1450 rte_strerror(EINVAL));
1452 /* Priority must be 0 */
1454 return -rte_tm_error_set(error,
1456 RTE_TM_ERROR_TYPE_NODE_PRIORITY,
1458 rte_strerror(EINVAL));
1460 /* Weight must be 1 */
1462 return -rte_tm_error_set(error,
1464 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
1466 rte_strerror(EINVAL));
1468 /* Shaper must be valid */
1469 if (params->shaper_profile_id == RTE_TM_SHAPER_PROFILE_ID_NONE ||
1471 return -rte_tm_error_set(error,
1473 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID,
1475 rte_strerror(EINVAL));
1477 /* No shared shapers */
1478 if (params->n_shared_shapers != 0)
1479 return -rte_tm_error_set(error,
1481 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS,
1483 rte_strerror(EINVAL));
1485 /* Number of SP priorities must be 1 */
1486 if (params->nonleaf.n_sp_priorities != 1)
1487 return -rte_tm_error_set(error,
1489 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES,
1491 rte_strerror(EINVAL));
1494 if (params->stats_mask & ~STATS_MASK_DEFAULT)
1495 return -rte_tm_error_set(error,
1497 RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,
1499 rte_strerror(EINVAL));
1505 node_add_check_subport(struct rte_eth_dev *dev,
1507 uint32_t parent_node_id __rte_unused,
1510 uint32_t level_id __rte_unused,
1511 struct rte_tm_node_params *params,
1512 struct rte_tm_error *error)
1514 struct pmd_internals *p = dev->data->dev_private;
1516 /* node type: non-leaf */
1517 if (node_id < p->params.tm.n_queues)
1518 return -rte_tm_error_set(error,
1520 RTE_TM_ERROR_TYPE_NODE_ID,
1522 rte_strerror(EINVAL));
1524 /* Priority must be 0 */
1526 return -rte_tm_error_set(error,
1528 RTE_TM_ERROR_TYPE_NODE_PRIORITY,
1530 rte_strerror(EINVAL));
1532 /* Weight must be 1 */
1534 return -rte_tm_error_set(error,
1536 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
1538 rte_strerror(EINVAL));
1540 /* Shaper must be valid */
1541 if (params->shaper_profile_id == RTE_TM_SHAPER_PROFILE_ID_NONE ||
1542 (!tm_shaper_profile_search(dev, params->shaper_profile_id)))
1543 return -rte_tm_error_set(error,
1545 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID,
1547 rte_strerror(EINVAL));
1549 /* No shared shapers */
1550 if (params->n_shared_shapers != 0)
1551 return -rte_tm_error_set(error,
1553 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS,
1555 rte_strerror(EINVAL));
1557 /* Number of SP priorities must be 1 */
1558 if (params->nonleaf.n_sp_priorities != 1)
1559 return -rte_tm_error_set(error,
1561 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES,
1563 rte_strerror(EINVAL));
1566 if (params->stats_mask & ~STATS_MASK_DEFAULT)
1567 return -rte_tm_error_set(error,
1569 RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,
1571 rte_strerror(EINVAL));
1577 node_add_check_pipe(struct rte_eth_dev *dev,
1579 uint32_t parent_node_id __rte_unused,
1581 uint32_t weight __rte_unused,
1582 uint32_t level_id __rte_unused,
1583 struct rte_tm_node_params *params,
1584 struct rte_tm_error *error)
1586 struct pmd_internals *p = dev->data->dev_private;
1588 /* node type: non-leaf */
1589 if (node_id < p->params.tm.n_queues)
1590 return -rte_tm_error_set(error,
1592 RTE_TM_ERROR_TYPE_NODE_ID,
1594 rte_strerror(EINVAL));
1596 /* Priority must be 0 */
1598 return -rte_tm_error_set(error,
1600 RTE_TM_ERROR_TYPE_NODE_PRIORITY,
1602 rte_strerror(EINVAL));
1604 /* Shaper must be valid */
1605 if (params->shaper_profile_id == RTE_TM_SHAPER_PROFILE_ID_NONE ||
1606 (!tm_shaper_profile_search(dev, params->shaper_profile_id)))
1607 return -rte_tm_error_set(error,
1609 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID,
1611 rte_strerror(EINVAL));
1613 /* No shared shapers */
1614 if (params->n_shared_shapers != 0)
1615 return -rte_tm_error_set(error,
1617 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS,
1619 rte_strerror(EINVAL));
1621 /* Number of SP priorities must be 4 */
1622 if (params->nonleaf.n_sp_priorities !=
1623 RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1624 return -rte_tm_error_set(error,
1626 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES,
1628 rte_strerror(EINVAL));
1630 /* WFQ mode must be byte mode */
1631 if (params->nonleaf.wfq_weight_mode != NULL &&
1632 params->nonleaf.wfq_weight_mode[0] != 0 &&
1633 params->nonleaf.wfq_weight_mode[1] != 0 &&
1634 params->nonleaf.wfq_weight_mode[2] != 0 &&
1635 params->nonleaf.wfq_weight_mode[3] != 0)
1636 return -rte_tm_error_set(error,
1638 RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE,
1640 rte_strerror(EINVAL));
1643 if (params->stats_mask & ~STATS_MASK_DEFAULT)
1644 return -rte_tm_error_set(error,
1646 RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,
1648 rte_strerror(EINVAL));
1654 node_add_check_tc(struct rte_eth_dev *dev,
1656 uint32_t parent_node_id __rte_unused,
1657 uint32_t priority __rte_unused,
1659 uint32_t level_id __rte_unused,
1660 struct rte_tm_node_params *params,
1661 struct rte_tm_error *error)
1663 struct pmd_internals *p = dev->data->dev_private;
1665 /* node type: non-leaf */
1666 if (node_id < p->params.tm.n_queues)
1667 return -rte_tm_error_set(error,
1669 RTE_TM_ERROR_TYPE_NODE_ID,
1671 rte_strerror(EINVAL));
1673 /* Weight must be 1 */
1675 return -rte_tm_error_set(error,
1677 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
1679 rte_strerror(EINVAL));
1681 /* Shaper must be valid */
1682 if (params->shaper_profile_id == RTE_TM_SHAPER_PROFILE_ID_NONE ||
1683 (!tm_shaper_profile_search(dev, params->shaper_profile_id)))
1684 return -rte_tm_error_set(error,
1686 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID,
1688 rte_strerror(EINVAL));
1690 /* Single valid shared shaper */
1691 if (params->n_shared_shapers > 1)
1692 return -rte_tm_error_set(error,
1694 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS,
1696 rte_strerror(EINVAL));
1698 if (params->n_shared_shapers == 1 &&
1699 (params->shared_shaper_id == NULL ||
1700 (!tm_shared_shaper_search(dev, params->shared_shaper_id[0]))))
1701 return -rte_tm_error_set(error,
1703 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID,
1705 rte_strerror(EINVAL));
1707 /* Number of priorities must be 1 */
1708 if (params->nonleaf.n_sp_priorities != 1)
1709 return -rte_tm_error_set(error,
1711 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES,
1713 rte_strerror(EINVAL));
1716 if (params->stats_mask & ~STATS_MASK_DEFAULT)
1717 return -rte_tm_error_set(error,
1719 RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,
1721 rte_strerror(EINVAL));
1727 node_add_check_queue(struct rte_eth_dev *dev,
1729 uint32_t parent_node_id __rte_unused,
1731 uint32_t weight __rte_unused,
1732 uint32_t level_id __rte_unused,
1733 struct rte_tm_node_params *params,
1734 struct rte_tm_error *error)
1736 struct pmd_internals *p = dev->data->dev_private;
1738 /* node type: leaf */
1739 if (node_id >= p->params.tm.n_queues)
1740 return -rte_tm_error_set(error,
1742 RTE_TM_ERROR_TYPE_NODE_ID,
1744 rte_strerror(EINVAL));
1746 /* Priority must be 0 */
1748 return -rte_tm_error_set(error,
1750 RTE_TM_ERROR_TYPE_NODE_PRIORITY,
1752 rte_strerror(EINVAL));
1755 if (params->shaper_profile_id != RTE_TM_SHAPER_PROFILE_ID_NONE)
1756 return -rte_tm_error_set(error,
1758 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID,
1760 rte_strerror(EINVAL));
1762 /* No shared shapers */
1763 if (params->n_shared_shapers != 0)
1764 return -rte_tm_error_set(error,
1766 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS,
1768 rte_strerror(EINVAL));
1770 /* Congestion management must not be head drop */
1771 if (params->leaf.cman == RTE_TM_CMAN_HEAD_DROP)
1772 return -rte_tm_error_set(error,
1774 RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN,
1776 rte_strerror(EINVAL));
1778 /* Congestion management set to WRED */
1779 if (params->leaf.cman == RTE_TM_CMAN_WRED) {
1780 uint32_t wred_profile_id = params->leaf.wred.wred_profile_id;
1781 struct tm_wred_profile *wp = tm_wred_profile_search(dev,
1784 /* WRED profile (for private WRED context) must be valid */
1785 if (wred_profile_id == RTE_TM_WRED_PROFILE_ID_NONE ||
1787 return -rte_tm_error_set(error,
1789 RTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID,
1791 rte_strerror(EINVAL));
1793 /* No shared WRED contexts */
1794 if (params->leaf.wred.n_shared_wred_contexts != 0)
1795 return -rte_tm_error_set(error,
1797 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS,
1799 rte_strerror(EINVAL));
1803 if (params->stats_mask & ~STATS_MASK_QUEUE)
1804 return -rte_tm_error_set(error,
1806 RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,
1808 rte_strerror(EINVAL));
1814 node_add_check(struct rte_eth_dev *dev,
1816 uint32_t parent_node_id,
1820 struct rte_tm_node_params *params,
1821 struct rte_tm_error *error)
1827 /* node_id, parent_node_id:
1828 * -node_id must not be RTE_TM_NODE_ID_NULL
1829 * -node_id must not be in use
1830 * -root node add (parent_node_id is RTE_TM_NODE_ID_NULL):
1831 * -root node must not exist
1832 * -non-root node add (parent_node_id is not RTE_TM_NODE_ID_NULL):
1833 * -parent_node_id must be valid
1835 if (node_id == RTE_TM_NODE_ID_NULL)
1836 return -rte_tm_error_set(error,
1838 RTE_TM_ERROR_TYPE_NODE_ID,
1840 rte_strerror(EINVAL));
1842 if (tm_node_search(dev, node_id))
1843 return -rte_tm_error_set(error,
1845 RTE_TM_ERROR_TYPE_NODE_ID,
1847 rte_strerror(EEXIST));
1849 if (parent_node_id == RTE_TM_NODE_ID_NULL) {
1851 if (tm_root_node_present(dev))
1852 return -rte_tm_error_set(error,
1854 RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID,
1856 rte_strerror(EEXIST));
1858 pn = tm_node_search(dev, parent_node_id);
1860 return -rte_tm_error_set(error,
1862 RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID,
1864 rte_strerror(EINVAL));
1867 /* priority: must be 0 .. 3 */
1868 if (priority >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1869 return -rte_tm_error_set(error,
1871 RTE_TM_ERROR_TYPE_NODE_PRIORITY,
1873 rte_strerror(EINVAL));
1875 /* weight: must be 1 .. 255 */
1876 if (weight == 0 || weight >= UINT8_MAX)
1877 return -rte_tm_error_set(error,
1879 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
1881 rte_strerror(EINVAL));
1883 /* level_id: if valid, then
1884 * -root node add (parent_node_id is RTE_TM_NODE_ID_NULL):
1885 * -level_id must be zero
1886 * -non-root node add (parent_node_id is not RTE_TM_NODE_ID_NULL):
1887 * -level_id must be parent level ID plus one
1889 level = (pn == NULL) ? 0 : pn->level + 1;
1890 if (level_id != RTE_TM_NODE_LEVEL_ID_ANY && level_id != level)
1891 return -rte_tm_error_set(error,
1893 RTE_TM_ERROR_TYPE_LEVEL_ID,
1895 rte_strerror(EINVAL));
1897 /* params: must not be NULL */
1899 return -rte_tm_error_set(error,
1901 RTE_TM_ERROR_TYPE_NODE_PARAMS,
1903 rte_strerror(EINVAL));
1905 /* params: per level checks */
1907 case TM_NODE_LEVEL_PORT:
1908 status = node_add_check_port(dev, node_id,
1909 parent_node_id, priority, weight, level_id,
1915 case TM_NODE_LEVEL_SUBPORT:
1916 status = node_add_check_subport(dev, node_id,
1917 parent_node_id, priority, weight, level_id,
1923 case TM_NODE_LEVEL_PIPE:
1924 status = node_add_check_pipe(dev, node_id,
1925 parent_node_id, priority, weight, level_id,
1931 case TM_NODE_LEVEL_TC:
1932 status = node_add_check_tc(dev, node_id,
1933 parent_node_id, priority, weight, level_id,
1939 case TM_NODE_LEVEL_QUEUE:
1940 status = node_add_check_queue(dev, node_id,
1941 parent_node_id, priority, weight, level_id,
1948 return -rte_tm_error_set(error,
1950 RTE_TM_ERROR_TYPE_LEVEL_ID,
1952 rte_strerror(EINVAL));
1958 /* Traffic manager node add */
1960 pmd_tm_node_add(struct rte_eth_dev *dev,
1962 uint32_t parent_node_id,
1966 struct rte_tm_node_params *params,
1967 struct rte_tm_error *error)
1969 struct pmd_internals *p = dev->data->dev_private;
1970 struct tm_node_list *nl = &p->soft.tm.h.nodes;
1976 if (p->soft.tm.hierarchy_frozen)
1977 return -rte_tm_error_set(error,
1979 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1981 rte_strerror(EBUSY));
1983 status = node_add_check(dev, node_id, parent_node_id, priority, weight,
1984 level_id, params, error);
1988 /* Memory allocation */
1989 n = calloc(1, sizeof(struct tm_node));
1991 return -rte_tm_error_set(error,
1993 RTE_TM_ERROR_TYPE_UNSPECIFIED,
1995 rte_strerror(ENOMEM));
1998 n->node_id = node_id;
1999 n->parent_node_id = parent_node_id;
2000 n->priority = priority;
2003 if (parent_node_id != RTE_TM_NODE_ID_NULL) {
2004 n->parent_node = tm_node_search(dev, parent_node_id);
2005 n->level = n->parent_node->level + 1;
2008 if (params->shaper_profile_id != RTE_TM_SHAPER_PROFILE_ID_NONE)
2009 n->shaper_profile = tm_shaper_profile_search(dev,
2010 params->shaper_profile_id);
2012 if (n->level == TM_NODE_LEVEL_QUEUE &&
2013 params->leaf.cman == RTE_TM_CMAN_WRED)
2014 n->wred_profile = tm_wred_profile_search(dev,
2015 params->leaf.wred.wred_profile_id);
2017 memcpy(&n->params, params, sizeof(n->params));
2020 TAILQ_INSERT_TAIL(nl, n, node);
2021 p->soft.tm.h.n_nodes++;
2023 /* Update dependencies */
2025 n->parent_node->n_children++;
2027 if (n->shaper_profile)
2028 n->shaper_profile->n_users++;
2030 for (i = 0; i < params->n_shared_shapers; i++) {
2031 struct tm_shared_shaper *ss;
2033 ss = tm_shared_shaper_search(dev, params->shared_shaper_id[i]);
2037 if (n->wred_profile)
2038 n->wred_profile->n_users++;
2040 p->soft.tm.h.n_tm_nodes[n->level]++;
2045 /* Traffic manager node delete */
2047 pmd_tm_node_delete(struct rte_eth_dev *dev,
2049 struct rte_tm_error *error)
2051 struct pmd_internals *p = dev->data->dev_private;
2055 /* Check hierarchy changes are currently allowed */
2056 if (p->soft.tm.hierarchy_frozen)
2057 return -rte_tm_error_set(error,
2059 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2061 rte_strerror(EBUSY));
2063 /* Check existing */
2064 n = tm_node_search(dev, node_id);
2066 return -rte_tm_error_set(error,
2068 RTE_TM_ERROR_TYPE_NODE_ID,
2070 rte_strerror(EINVAL));
2074 return -rte_tm_error_set(error,
2076 RTE_TM_ERROR_TYPE_NODE_ID,
2078 rte_strerror(EBUSY));
2080 /* Update dependencies */
2081 p->soft.tm.h.n_tm_nodes[n->level]--;
2083 if (n->wred_profile)
2084 n->wred_profile->n_users--;
2086 for (i = 0; i < n->params.n_shared_shapers; i++) {
2087 struct tm_shared_shaper *ss;
2089 ss = tm_shared_shaper_search(dev,
2090 n->params.shared_shaper_id[i]);
2094 if (n->shaper_profile)
2095 n->shaper_profile->n_users--;
2098 n->parent_node->n_children--;
2100 /* Remove from list */
2101 TAILQ_REMOVE(&p->soft.tm.h.nodes, n, node);
2102 p->soft.tm.h.n_nodes--;
2110 pipe_profile_build(struct rte_eth_dev *dev,
2112 struct rte_sched_pipe_params *pp)
2114 struct pmd_internals *p = dev->data->dev_private;
2115 struct tm_hierarchy *h = &p->soft.tm.h;
2116 struct tm_node_list *nl = &h->nodes;
2117 struct tm_node *nt, *nq;
2119 memset(pp, 0, sizeof(*pp));
2122 pp->tb_rate = np->shaper_profile->params.peak.rate;
2123 pp->tb_size = np->shaper_profile->params.peak.size;
2125 /* Traffic Class (TC) */
2126 pp->tc_period = PIPE_TC_PERIOD;
2128 pp->tc_ov_weight = np->weight;
2130 TAILQ_FOREACH(nt, nl, node) {
2131 uint32_t queue_id = 0;
2133 if (nt->level != TM_NODE_LEVEL_TC ||
2134 nt->parent_node_id != np->node_id)
2137 pp->tc_rate[nt->priority] =
2138 nt->shaper_profile->params.peak.rate;
2141 TAILQ_FOREACH(nq, nl, node) {
2143 if (nq->level != TM_NODE_LEVEL_QUEUE ||
2144 nq->parent_node_id != nt->node_id)
2147 if (nt->priority == RTE_SCHED_TRAFFIC_CLASS_BE)
2148 pp->wrr_weights[queue_id] = nq->weight;
2156 pipe_profile_free_exists(struct rte_eth_dev *dev,
2157 uint32_t *pipe_profile_id)
2159 struct pmd_internals *p = dev->data->dev_private;
2160 struct tm_params *t = &p->soft.tm.params;
2162 if (t->n_pipe_profiles < TM_MAX_PIPE_PROFILE) {
2163 *pipe_profile_id = t->n_pipe_profiles;
2171 pipe_profile_exists(struct rte_eth_dev *dev,
2172 struct rte_sched_pipe_params *pp,
2173 uint32_t *pipe_profile_id)
2175 struct pmd_internals *p = dev->data->dev_private;
2176 struct tm_params *t = &p->soft.tm.params;
2179 for (i = 0; i < t->n_pipe_profiles; i++)
2180 if (memcmp(&t->pipe_profiles[i], pp, sizeof(*pp)) == 0) {
2181 if (pipe_profile_id)
2182 *pipe_profile_id = i;
2190 pipe_profile_install(struct rte_eth_dev *dev,
2191 struct rte_sched_pipe_params *pp,
2192 uint32_t pipe_profile_id)
2194 struct pmd_internals *p = dev->data->dev_private;
2195 struct tm_params *t = &p->soft.tm.params;
2197 memcpy(&t->pipe_profiles[pipe_profile_id], pp, sizeof(*pp));
2198 t->n_pipe_profiles++;
2202 pipe_profile_mark(struct rte_eth_dev *dev,
2203 uint32_t subport_id,
2205 uint32_t pipe_profile_id)
2207 struct pmd_internals *p = dev->data->dev_private;
2208 struct tm_hierarchy *h = &p->soft.tm.h;
2209 struct tm_params *t = &p->soft.tm.params;
2210 uint32_t n_pipes_per_subport, pos;
2212 n_pipes_per_subport = h->n_tm_nodes[TM_NODE_LEVEL_PIPE] /
2213 h->n_tm_nodes[TM_NODE_LEVEL_SUBPORT];
2214 pos = subport_id * n_pipes_per_subport + pipe_id;
2216 t->pipe_to_profile[pos] = pipe_profile_id;
2219 static struct rte_sched_pipe_params *
2220 pipe_profile_get(struct rte_eth_dev *dev, struct tm_node *np)
2222 struct pmd_internals *p = dev->data->dev_private;
2223 struct tm_hierarchy *h = &p->soft.tm.h;
2224 struct tm_params *t = &p->soft.tm.params;
2225 uint32_t n_pipes_per_subport = h->n_tm_nodes[TM_NODE_LEVEL_PIPE] /
2226 h->n_tm_nodes[TM_NODE_LEVEL_SUBPORT];
2228 uint32_t subport_id = tm_node_subport_id(dev, np->parent_node);
2229 uint32_t pipe_id = tm_node_pipe_id(dev, np);
2231 uint32_t pos = subport_id * n_pipes_per_subport + pipe_id;
2232 uint32_t pipe_profile_id = t->pipe_to_profile[pos];
2234 return &t->pipe_profiles[pipe_profile_id];
2238 pipe_profiles_generate(struct rte_eth_dev *dev)
2240 struct pmd_internals *p = dev->data->dev_private;
2241 struct tm_hierarchy *h = &p->soft.tm.h;
2242 struct tm_node_list *nl = &h->nodes;
2243 struct tm_node *ns, *np;
2244 uint32_t subport_id;
2246 /* Objective: Fill in the following fields in struct tm_params:
2253 TAILQ_FOREACH(ns, nl, node) {
2256 if (ns->level != TM_NODE_LEVEL_SUBPORT)
2260 TAILQ_FOREACH(np, nl, node) {
2261 struct rte_sched_pipe_params pp;
2264 memset(&pp, 0, sizeof(pp));
2266 if (np->level != TM_NODE_LEVEL_PIPE ||
2267 np->parent_node_id != ns->node_id)
2270 pipe_profile_build(dev, np, &pp);
2272 if (!pipe_profile_exists(dev, &pp, &pos)) {
2273 if (!pipe_profile_free_exists(dev, &pos))
2276 pipe_profile_install(dev, &pp, pos);
2279 pipe_profile_mark(dev, subport_id, pipe_id, pos);
2290 static struct tm_wred_profile *
2291 tm_tc_wred_profile_get(struct rte_eth_dev *dev, uint32_t tc_id)
2293 struct pmd_internals *p = dev->data->dev_private;
2294 struct tm_hierarchy *h = &p->soft.tm.h;
2295 struct tm_node_list *nl = &h->nodes;
2298 TAILQ_FOREACH(nq, nl, node) {
2299 if (nq->level != TM_NODE_LEVEL_QUEUE ||
2300 nq->parent_node->priority != tc_id)
2303 return nq->wred_profile;
2309 #ifdef RTE_SCHED_RED
2312 wred_profiles_set(struct rte_eth_dev *dev, uint32_t subport_id)
2314 struct pmd_internals *p = dev->data->dev_private;
2315 struct rte_sched_subport_params *pp =
2316 &p->soft.tm.params.subport_params[subport_id];
2319 enum rte_color color;
2321 for (tc_id = 0; tc_id < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; tc_id++)
2322 for (color = RTE_COLOR_GREEN; color < RTE_COLORS; color++) {
2323 struct rte_red_params *dst =
2324 &pp->red_params[tc_id][color];
2325 struct tm_wred_profile *src_wp =
2326 tm_tc_wred_profile_get(dev, tc_id);
2327 struct rte_tm_red_params *src =
2328 &src_wp->params.red_params[color];
2330 memcpy(dst, src, sizeof(*dst));
2336 #define wred_profiles_set(dev, subport_id)
2340 static struct tm_shared_shaper *
2341 tm_tc_shared_shaper_get(struct rte_eth_dev *dev, struct tm_node *tc_node)
2343 return (tc_node->params.n_shared_shapers) ?
2344 tm_shared_shaper_search(dev,
2345 tc_node->params.shared_shaper_id[0]) :
2349 static struct tm_shared_shaper *
2350 tm_subport_tc_shared_shaper_get(struct rte_eth_dev *dev,
2351 struct tm_node *subport_node,
2354 struct pmd_internals *p = dev->data->dev_private;
2355 struct tm_node_list *nl = &p->soft.tm.h.nodes;
2358 TAILQ_FOREACH(n, nl, node) {
2359 if (n->level != TM_NODE_LEVEL_TC ||
2360 n->parent_node->parent_node_id !=
2361 subport_node->node_id ||
2362 n->priority != tc_id)
2365 return tm_tc_shared_shaper_get(dev, n);
2371 static struct rte_sched_subport_profile_params *
2372 subport_profile_get(struct rte_eth_dev *dev, struct tm_node *np)
2374 struct pmd_internals *p = dev->data->dev_private;
2375 struct tm_params *t = &p->soft.tm.params;
2376 uint32_t subport_id = tm_node_subport_id(dev, np->parent_node);
2378 if (subport_id >= TM_MAX_SUBPORT_PROFILE)
2381 return &t->subport_profile[subport_id];
2385 subport_profile_mark(struct rte_eth_dev *dev,
2386 uint32_t subport_id,
2387 uint32_t subport_profile_id)
2389 struct pmd_internals *p = dev->data->dev_private;
2390 struct tm_params *t = &p->soft.tm.params;
2392 t->subport_to_profile[subport_id] = subport_profile_id;
2396 subport_profile_install(struct rte_eth_dev *dev,
2397 struct rte_sched_subport_profile_params *sp,
2398 uint32_t subport_profile_id)
2400 struct pmd_internals *p = dev->data->dev_private;
2401 struct tm_params *t = &p->soft.tm.params;
2403 memcpy(&t->subport_profile[subport_profile_id],
2405 t->n_subport_profiles++;
2409 subport_profile_free_exists(struct rte_eth_dev *dev,
2410 uint32_t *subport_profile_id)
2412 struct pmd_internals *p = dev->data->dev_private;
2413 struct tm_params *t = &p->soft.tm.params;
2415 if (t->n_subport_profiles < TM_MAX_SUBPORT_PROFILE) {
2416 *subport_profile_id = t->n_subport_profiles;
2424 subport_profile_build(struct rte_eth_dev *dev, struct tm_node *np,
2425 struct rte_sched_subport_profile_params *sp)
2428 memset(sp, 0, sizeof(*sp));
2430 sp->tb_rate = np->shaper_profile->params.peak.rate;
2431 sp->tb_size = np->shaper_profile->params.peak.size;
2433 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
2434 struct tm_shared_shaper *ss;
2435 struct tm_shaper_profile *ssp;
2437 ss = tm_subport_tc_shared_shaper_get(dev, np, i);
2438 ssp = (ss) ? tm_shaper_profile_search(dev,
2439 ss->shaper_profile_id) :
2441 sp->tc_rate[i] = ssp->params.peak.rate;
2444 /* Traffic Class (TC) */
2445 sp->tc_period = SUBPORT_TC_PERIOD;
2449 subport_profiles_generate(struct rte_eth_dev *dev)
2451 struct pmd_internals *p = dev->data->dev_private;
2452 struct tm_hierarchy *h = &p->soft.tm.h;
2453 struct tm_node_list *nl = &h->nodes;
2455 uint32_t subport_id;
2457 /* Objective: Fill in the following fields in struct tm_params:
2458 * - subport_profiles
2459 * - n_subport_profiles
2460 * - subport_to_profile
2464 TAILQ_FOREACH(ns, nl, node) {
2465 if (ns->level != TM_NODE_LEVEL_SUBPORT)
2468 struct rte_sched_subport_profile_params sp;
2471 memset(&sp, 0, sizeof(sp));
2473 subport_profile_build(dev, ns, &sp);
2475 if (!subport_profile_exists(dev, &sp, &pos)) {
2476 if (!subport_profile_free_exists(dev, &pos))
2479 subport_profile_install(dev, &sp, pos);
2482 subport_profile_mark(dev, subport_id, pos);
2492 hierarchy_commit_check(struct rte_eth_dev *dev, struct rte_tm_error *error)
2494 struct pmd_internals *p = dev->data->dev_private;
2495 struct tm_hierarchy *h = &p->soft.tm.h;
2496 struct tm_node_list *nl = &h->nodes;
2497 struct tm_shared_shaper_list *ssl = &h->shared_shapers;
2498 struct tm_wred_profile_list *wpl = &h->wred_profiles;
2499 struct tm_node *nr = tm_root_node_present(dev), *ns, *np, *nt, *nq;
2500 struct tm_shared_shaper *ss;
2502 uint32_t n_pipes_per_subport;
2504 /* Root node exists. */
2506 return -rte_tm_error_set(error,
2508 RTE_TM_ERROR_TYPE_LEVEL_ID,
2510 rte_strerror(EINVAL));
2512 /* There is at least one subport, max is not exceeded. */
2513 if (nr->n_children == 0 || nr->n_children > TM_MAX_SUBPORTS)
2514 return -rte_tm_error_set(error,
2516 RTE_TM_ERROR_TYPE_LEVEL_ID,
2518 rte_strerror(EINVAL));
2520 /* There is at least one pipe. */
2521 if (h->n_tm_nodes[TM_NODE_LEVEL_PIPE] == 0)
2522 return -rte_tm_error_set(error,
2524 RTE_TM_ERROR_TYPE_LEVEL_ID,
2526 rte_strerror(EINVAL));
2528 /* Number of pipes is the same for all subports. Maximum number of pipes
2529 * per subport is not exceeded.
2531 n_pipes_per_subport = h->n_tm_nodes[TM_NODE_LEVEL_PIPE] /
2532 h->n_tm_nodes[TM_NODE_LEVEL_SUBPORT];
2534 if (n_pipes_per_subport > TM_MAX_PIPES_PER_SUBPORT)
2535 return -rte_tm_error_set(error,
2537 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2539 rte_strerror(EINVAL));
2541 TAILQ_FOREACH(ns, nl, node) {
2542 if (ns->level != TM_NODE_LEVEL_SUBPORT)
2545 if (ns->n_children != n_pipes_per_subport)
2546 return -rte_tm_error_set(error,
2548 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2550 rte_strerror(EINVAL));
2553 /* Each pipe has exactly 13 TCs, with exactly one TC for each priority */
2554 TAILQ_FOREACH(np, nl, node) {
2555 uint32_t mask = 0, mask_expected =
2556 RTE_LEN2MASK(RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
2559 if (np->level != TM_NODE_LEVEL_PIPE)
2562 if (np->n_children != RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
2563 return -rte_tm_error_set(error,
2565 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2567 rte_strerror(EINVAL));
2569 TAILQ_FOREACH(nt, nl, node) {
2570 if (nt->level != TM_NODE_LEVEL_TC ||
2571 nt->parent_node_id != np->node_id)
2574 mask |= 1 << nt->priority;
2577 if (mask != mask_expected)
2578 return -rte_tm_error_set(error,
2580 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2582 rte_strerror(EINVAL));
2585 /** Each Strict priority TC has exactly 1 packet queues while
2586 * lowest priority TC (Best-effort) has 4 queues.
2588 TAILQ_FOREACH(nt, nl, node) {
2589 if (nt->level != TM_NODE_LEVEL_TC)
2592 if (nt->n_children != 1 && nt->n_children != RTE_SCHED_BE_QUEUES_PER_PIPE)
2593 return -rte_tm_error_set(error,
2595 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2597 rte_strerror(EINVAL));
2602 * -For each TC #i, all pipes in the same subport use the same
2603 * shared shaper (or no shared shaper) for their TC#i.
2604 * -Each shared shaper needs to have at least one user. All its
2605 * users have to be TC nodes with the same priority and the same
2608 TAILQ_FOREACH(ns, nl, node) {
2609 struct tm_shared_shaper *s[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
2612 if (ns->level != TM_NODE_LEVEL_SUBPORT)
2615 for (id = 0; id < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; id++)
2616 s[id] = tm_subport_tc_shared_shaper_get(dev, ns, id);
2618 TAILQ_FOREACH(nt, nl, node) {
2619 struct tm_shared_shaper *subport_ss, *tc_ss;
2621 if (nt->level != TM_NODE_LEVEL_TC ||
2622 nt->parent_node->parent_node_id !=
2626 subport_ss = s[nt->priority];
2627 tc_ss = tm_tc_shared_shaper_get(dev, nt);
2629 if (subport_ss == NULL && tc_ss == NULL)
2632 if ((subport_ss == NULL && tc_ss != NULL) ||
2633 (subport_ss != NULL && tc_ss == NULL) ||
2634 subport_ss->shared_shaper_id !=
2635 tc_ss->shared_shaper_id)
2636 return -rte_tm_error_set(error,
2638 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2640 rte_strerror(EINVAL));
2644 TAILQ_FOREACH(ss, ssl, node) {
2645 struct tm_node *nt_any = tm_shared_shaper_get_tc(dev, ss);
2646 uint32_t n_users = 0;
2649 TAILQ_FOREACH(nt, nl, node) {
2650 if (nt->level != TM_NODE_LEVEL_TC ||
2651 nt->priority != nt_any->priority ||
2652 nt->parent_node->parent_node_id !=
2653 nt_any->parent_node->parent_node_id)
2659 if (ss->n_users == 0 || ss->n_users != n_users)
2660 return -rte_tm_error_set(error,
2662 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2664 rte_strerror(EINVAL));
2667 /* Not too many subport profiles. */
2668 if (subport_profiles_generate(dev))
2669 return -rte_tm_error_set(error,
2671 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2673 rte_strerror(EINVAL));
2676 /* Not too many pipe profiles. */
2677 if (pipe_profiles_generate(dev))
2678 return -rte_tm_error_set(error,
2680 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2682 rte_strerror(EINVAL));
2685 * WRED (when used, i.e. at least one WRED profile defined):
2686 * -Each WRED profile must have at least one user.
2687 * -All leaf nodes must have their private WRED context enabled.
2688 * -For each TC #i, all leaf nodes must use the same WRED profile
2689 * for their private WRED context.
2691 if (h->n_wred_profiles) {
2692 struct tm_wred_profile *wp;
2693 struct tm_wred_profile *w[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
2696 TAILQ_FOREACH(wp, wpl, node)
2697 if (wp->n_users == 0)
2698 return -rte_tm_error_set(error,
2700 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2702 rte_strerror(EINVAL));
2704 for (id = 0; id < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; id++) {
2705 w[id] = tm_tc_wred_profile_get(dev, id);
2708 return -rte_tm_error_set(error,
2710 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2712 rte_strerror(EINVAL));
2715 TAILQ_FOREACH(nq, nl, node) {
2718 if (nq->level != TM_NODE_LEVEL_QUEUE)
2721 id = nq->parent_node->priority;
2723 if (nq->wred_profile == NULL ||
2724 nq->wred_profile->wred_profile_id !=
2725 w[id]->wred_profile_id)
2726 return -rte_tm_error_set(error,
2728 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2730 rte_strerror(EINVAL));
2738 hierarchy_blueprints_create(struct rte_eth_dev *dev)
2740 struct pmd_internals *p = dev->data->dev_private;
2741 struct tm_params *t = &p->soft.tm.params;
2742 struct tm_hierarchy *h = &p->soft.tm.h;
2744 struct tm_node_list *nl = &h->nodes;
2745 struct tm_node *root = tm_root_node_present(dev), *n;
2747 uint32_t subport_id;
2749 t->port_params = (struct rte_sched_port_params) {
2750 .name = dev->data->name,
2751 .socket = dev->data->numa_node,
2752 .rate = root->shaper_profile->params.peak.rate,
2753 .mtu = dev->data->mtu,
2755 root->shaper_profile->params.pkt_length_adjust,
2756 .n_subports_per_port = root->n_children,
2757 .n_subport_profiles = t->n_subport_profiles,
2758 .subport_profiles = t->subport_profile,
2759 .n_max_subport_profiles = TM_MAX_SUBPORT_PROFILE,
2760 .n_pipes_per_subport = TM_MAX_PIPES_PER_SUBPORT,
2764 TAILQ_FOREACH(n, nl, node) {
2766 if (n->level != TM_NODE_LEVEL_SUBPORT)
2769 t->subport_params[subport_id] =
2770 (struct rte_sched_subport_params) {
2771 .n_pipes_per_subport_enabled =
2772 h->n_tm_nodes[TM_NODE_LEVEL_PIPE] /
2773 h->n_tm_nodes[TM_NODE_LEVEL_SUBPORT],
2774 .qsize = {p->params.tm.qsize[0],
2775 p->params.tm.qsize[1],
2776 p->params.tm.qsize[2],
2777 p->params.tm.qsize[3],
2778 p->params.tm.qsize[4],
2779 p->params.tm.qsize[5],
2780 p->params.tm.qsize[6],
2781 p->params.tm.qsize[7],
2782 p->params.tm.qsize[8],
2783 p->params.tm.qsize[9],
2784 p->params.tm.qsize[10],
2785 p->params.tm.qsize[11],
2786 p->params.tm.qsize[12],
2788 .pipe_profiles = t->pipe_profiles,
2789 .n_pipe_profiles = t->n_pipe_profiles,
2790 .n_max_pipe_profiles = TM_MAX_PIPE_PROFILE,
2792 wred_profiles_set(dev, subport_id);
2797 /* Traffic manager hierarchy commit */
2799 pmd_tm_hierarchy_commit(struct rte_eth_dev *dev,
2801 struct rte_tm_error *error)
2803 struct pmd_internals *p = dev->data->dev_private;
2807 if (p->soft.tm.hierarchy_frozen)
2808 return -rte_tm_error_set(error,
2810 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2812 rte_strerror(EBUSY));
2814 status = hierarchy_commit_check(dev, error);
2817 tm_hierarchy_free(p);
2822 /* Create blueprints */
2823 hierarchy_blueprints_create(dev);
2825 /* Freeze hierarchy */
2826 p->soft.tm.hierarchy_frozen = 1;
2831 #ifdef RTE_SCHED_SUBPORT_TC_OV
2834 update_pipe_weight(struct rte_eth_dev *dev, struct tm_node *np, uint32_t weight)
2836 struct pmd_internals *p = dev->data->dev_private;
2837 uint32_t pipe_id = tm_node_pipe_id(dev, np);
2839 struct tm_node *ns = np->parent_node;
2840 uint32_t subport_id = tm_node_subport_id(dev, ns);
2842 struct rte_sched_pipe_params *profile0 = pipe_profile_get(dev, np);
2843 struct rte_sched_pipe_params profile1;
2844 uint32_t pipe_profile_id;
2846 /* Derive new pipe profile. */
2847 memcpy(&profile1, profile0, sizeof(profile1));
2848 profile1.tc_ov_weight = (uint8_t)weight;
2850 /* Since implementation does not allow adding more pipe profiles after
2851 * port configuration, the pipe configuration can be successfully
2852 * updated only if the new profile is also part of the existing set of
2855 if (pipe_profile_exists(dev, &profile1, &pipe_profile_id) == 0)
2858 /* Update the pipe profile used by the current pipe. */
2859 if (rte_sched_pipe_config(SCHED(p), subport_id, pipe_id,
2860 (int32_t)pipe_profile_id))
2863 /* Commit changes. */
2864 pipe_profile_mark(dev, subport_id, pipe_id, pipe_profile_id);
2865 np->weight = weight;
2873 update_queue_weight(struct rte_eth_dev *dev,
2874 struct tm_node *nq, uint32_t weight)
2876 struct pmd_internals *p = dev->data->dev_private;
2877 uint32_t queue_id = tm_node_queue_id(dev, nq);
2879 struct tm_node *nt = nq->parent_node;
2881 struct tm_node *np = nt->parent_node;
2882 uint32_t pipe_id = tm_node_pipe_id(dev, np);
2884 struct tm_node *ns = np->parent_node;
2885 uint32_t subport_id = tm_node_subport_id(dev, ns);
2887 uint32_t pipe_be_queue_id =
2888 queue_id - RTE_SCHED_TRAFFIC_CLASS_BE;
2890 struct rte_sched_pipe_params *profile0 = pipe_profile_get(dev, np);
2891 struct rte_sched_pipe_params profile1;
2892 uint32_t pipe_profile_id;
2894 /* Derive new pipe profile. */
2895 memcpy(&profile1, profile0, sizeof(profile1));
2896 profile1.wrr_weights[pipe_be_queue_id] = (uint8_t)weight;
2898 /* Since implementation does not allow adding more pipe profiles after
2899 * port configuration, the pipe configuration can be successfully
2900 * updated only if the new profile is also part of the existing set
2903 if (pipe_profile_exists(dev, &profile1, &pipe_profile_id) == 0)
2906 /* Update the pipe profile used by the current pipe. */
2907 if (rte_sched_pipe_config(SCHED(p), subport_id, pipe_id,
2908 (int32_t)pipe_profile_id))
2911 /* Commit changes. */
2912 pipe_profile_mark(dev, subport_id, pipe_id, pipe_profile_id);
2913 nq->weight = weight;
2918 /* Traffic manager node parent update */
2920 pmd_tm_node_parent_update(struct rte_eth_dev *dev,
2922 uint32_t parent_node_id,
2925 struct rte_tm_error *error)
2929 /* Port must be started and TM used. */
2930 if (dev->data->dev_started == 0 && (tm_used(dev) == 0))
2931 return -rte_tm_error_set(error,
2933 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2935 rte_strerror(EBUSY));
2937 /* Node must be valid */
2938 n = tm_node_search(dev, node_id);
2940 return -rte_tm_error_set(error,
2942 RTE_TM_ERROR_TYPE_NODE_ID,
2944 rte_strerror(EINVAL));
2946 /* Parent node must be the same */
2947 if (n->parent_node_id != parent_node_id)
2948 return -rte_tm_error_set(error,
2950 RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID,
2952 rte_strerror(EINVAL));
2954 /* Priority must be the same */
2955 if (n->priority != priority)
2956 return -rte_tm_error_set(error,
2958 RTE_TM_ERROR_TYPE_NODE_PRIORITY,
2960 rte_strerror(EINVAL));
2962 /* weight: must be 1 .. 255 */
2963 if (weight == 0 || weight >= UINT8_MAX)
2964 return -rte_tm_error_set(error,
2966 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
2968 rte_strerror(EINVAL));
2971 case TM_NODE_LEVEL_PORT:
2972 return -rte_tm_error_set(error,
2974 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
2976 rte_strerror(EINVAL));
2978 case TM_NODE_LEVEL_SUBPORT:
2979 return -rte_tm_error_set(error,
2981 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
2983 rte_strerror(EINVAL));
2985 case TM_NODE_LEVEL_PIPE:
2986 #ifdef RTE_SCHED_SUBPORT_TC_OV
2987 if (update_pipe_weight(dev, n, weight))
2988 return -rte_tm_error_set(error,
2990 RTE_TM_ERROR_TYPE_UNSPECIFIED,
2992 rte_strerror(EINVAL));
2995 return -rte_tm_error_set(error,
2997 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
2999 rte_strerror(EINVAL));
3002 case TM_NODE_LEVEL_TC:
3003 return -rte_tm_error_set(error,
3005 RTE_TM_ERROR_TYPE_NODE_WEIGHT,
3007 rte_strerror(EINVAL));
3009 case TM_NODE_LEVEL_QUEUE:
3012 if (update_queue_weight(dev, n, weight))
3013 return -rte_tm_error_set(error,
3015 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3017 rte_strerror(EINVAL));
3023 update_subport_rate(struct rte_eth_dev *dev,
3025 struct tm_shaper_profile *sp)
3027 struct pmd_internals *p = dev->data->dev_private;
3028 uint32_t subport_id = tm_node_subport_id(dev, ns);
3030 struct rte_sched_subport_profile_params *profile0 =
3031 subport_profile_get(dev, ns);
3032 struct rte_sched_subport_profile_params profile1;
3033 uint32_t subport_profile_id;
3035 if (profile0 == NULL)
3038 /* Derive new pipe profile. */
3039 memcpy(&profile1, profile0, sizeof(profile1));
3040 profile1.tb_rate = sp->params.peak.rate;
3041 profile1.tb_size = sp->params.peak.size;
3043 /* Since implementation does not allow adding more subport profiles
3044 * after port configuration, the pipe configuration can be successfully
3045 * updated only if the new profile is also part of the existing set of
3048 if (subport_profile_exists(dev, &profile1, &subport_profile_id) == 0)
3051 /* Update the subport configuration. */
3052 if (rte_sched_subport_config(SCHED(p), subport_id,
3053 NULL, subport_profile_id))
3056 /* Commit changes. */
3057 ns->shaper_profile->n_users--;
3059 ns->shaper_profile = sp;
3060 ns->params.shaper_profile_id = sp->shaper_profile_id;
3063 subport_profile_mark(dev, subport_id, subport_profile_id);
3065 memcpy(&p->soft.tm.params.subport_profile[subport_profile_id],
3073 update_pipe_rate(struct rte_eth_dev *dev,
3075 struct tm_shaper_profile *sp)
3077 struct pmd_internals *p = dev->data->dev_private;
3078 uint32_t pipe_id = tm_node_pipe_id(dev, np);
3080 struct tm_node *ns = np->parent_node;
3081 uint32_t subport_id = tm_node_subport_id(dev, ns);
3083 struct rte_sched_pipe_params *profile0 = pipe_profile_get(dev, np);
3084 struct rte_sched_pipe_params profile1;
3085 uint32_t pipe_profile_id;
3087 /* Derive new pipe profile. */
3088 memcpy(&profile1, profile0, sizeof(profile1));
3089 profile1.tb_rate = sp->params.peak.rate;
3090 profile1.tb_size = sp->params.peak.size;
3092 /* Since implementation does not allow adding more pipe profiles after
3093 * port configuration, the pipe configuration can be successfully
3094 * updated only if the new profile is also part of the existing set of
3097 if (pipe_profile_exists(dev, &profile1, &pipe_profile_id) == 0)
3100 /* Update the pipe profile used by the current pipe. */
3101 if (rte_sched_pipe_config(SCHED(p), subport_id, pipe_id,
3102 (int32_t)pipe_profile_id))
3105 /* Commit changes. */
3106 pipe_profile_mark(dev, subport_id, pipe_id, pipe_profile_id);
3107 np->shaper_profile->n_users--;
3108 np->shaper_profile = sp;
3109 np->params.shaper_profile_id = sp->shaper_profile_id;
3116 update_tc_rate(struct rte_eth_dev *dev,
3118 struct tm_shaper_profile *sp)
3120 struct pmd_internals *p = dev->data->dev_private;
3121 uint32_t tc_id = tm_node_tc_id(dev, nt);
3123 struct tm_node *np = nt->parent_node;
3124 uint32_t pipe_id = tm_node_pipe_id(dev, np);
3126 struct tm_node *ns = np->parent_node;
3127 uint32_t subport_id = tm_node_subport_id(dev, ns);
3129 struct rte_sched_pipe_params *profile0 = pipe_profile_get(dev, np);
3130 struct rte_sched_pipe_params profile1;
3131 uint32_t pipe_profile_id;
3133 /* Derive new pipe profile. */
3134 memcpy(&profile1, profile0, sizeof(profile1));
3135 profile1.tc_rate[tc_id] = sp->params.peak.rate;
3137 /* Since implementation does not allow adding more pipe profiles after
3138 * port configuration, the pipe configuration can be successfully
3139 * updated only if the new profile is also part of the existing set of
3142 if (pipe_profile_exists(dev, &profile1, &pipe_profile_id) == 0)
3145 /* Update the pipe profile used by the current pipe. */
3146 if (rte_sched_pipe_config(SCHED(p), subport_id, pipe_id,
3147 (int32_t)pipe_profile_id))
3150 /* Commit changes. */
3151 pipe_profile_mark(dev, subport_id, pipe_id, pipe_profile_id);
3152 nt->shaper_profile->n_users--;
3153 nt->shaper_profile = sp;
3154 nt->params.shaper_profile_id = sp->shaper_profile_id;
3160 /* Traffic manager node shaper update */
3162 pmd_tm_node_shaper_update(struct rte_eth_dev *dev,
3164 uint32_t shaper_profile_id,
3165 struct rte_tm_error *error)
3168 struct tm_shaper_profile *sp;
3170 /* Port must be started and TM used. */
3171 if (dev->data->dev_started == 0 && (tm_used(dev) == 0))
3172 return -rte_tm_error_set(error,
3174 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3176 rte_strerror(EBUSY));
3178 /* Node must be valid */
3179 n = tm_node_search(dev, node_id);
3181 return -rte_tm_error_set(error,
3183 RTE_TM_ERROR_TYPE_NODE_ID,
3185 rte_strerror(EINVAL));
3187 /* Shaper profile must be valid. */
3188 sp = tm_shaper_profile_search(dev, shaper_profile_id);
3190 return -rte_tm_error_set(error,
3192 RTE_TM_ERROR_TYPE_SHAPER_PROFILE,
3194 rte_strerror(EINVAL));
3197 case TM_NODE_LEVEL_PORT:
3198 return -rte_tm_error_set(error,
3200 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3202 rte_strerror(EINVAL));
3204 case TM_NODE_LEVEL_SUBPORT:
3205 if (update_subport_rate(dev, n, sp))
3206 return -rte_tm_error_set(error,
3208 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3210 rte_strerror(EINVAL));
3213 case TM_NODE_LEVEL_PIPE:
3214 if (update_pipe_rate(dev, n, sp))
3215 return -rte_tm_error_set(error,
3217 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3219 rte_strerror(EINVAL));
3222 case TM_NODE_LEVEL_TC:
3223 if (update_tc_rate(dev, n, sp))
3224 return -rte_tm_error_set(error,
3226 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3228 rte_strerror(EINVAL));
3231 case TM_NODE_LEVEL_QUEUE:
3234 return -rte_tm_error_set(error,
3236 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3238 rte_strerror(EINVAL));
3242 static inline uint32_t
3243 tm_port_queue_id(struct rte_eth_dev *dev,
3244 uint32_t port_subport_id,
3245 uint32_t subport_pipe_id,
3246 uint32_t pipe_tc_id,
3247 uint32_t tc_queue_id)
3249 struct pmd_internals *p = dev->data->dev_private;
3250 struct tm_hierarchy *h = &p->soft.tm.h;
3251 uint32_t n_pipes_per_subport = h->n_tm_nodes[TM_NODE_LEVEL_PIPE] /
3252 h->n_tm_nodes[TM_NODE_LEVEL_SUBPORT];
3254 uint32_t port_pipe_id =
3255 port_subport_id * n_pipes_per_subport + subport_pipe_id;
3257 uint32_t port_queue_id =
3258 port_pipe_id * RTE_SCHED_QUEUES_PER_PIPE + pipe_tc_id + tc_queue_id;
3260 return port_queue_id;
3264 read_port_stats(struct rte_eth_dev *dev,
3266 struct rte_tm_node_stats *stats,
3267 uint64_t *stats_mask,
3270 struct pmd_internals *p = dev->data->dev_private;
3271 struct tm_hierarchy *h = &p->soft.tm.h;
3272 uint32_t n_subports_per_port = h->n_tm_nodes[TM_NODE_LEVEL_SUBPORT];
3273 uint32_t subport_id;
3275 for (subport_id = 0; subport_id < n_subports_per_port; subport_id++) {
3276 struct rte_sched_subport_stats s;
3280 int status = rte_sched_subport_read_stats(SCHED(p),
3287 /* Stats accumulate */
3288 for (id = 0; id < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; id++) {
3290 s.n_pkts_tc[id] - s.n_pkts_tc_dropped[id];
3291 nr->stats.n_bytes +=
3292 s.n_bytes_tc[id] - s.n_bytes_tc_dropped[id];
3293 nr->stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN] +=
3294 s.n_pkts_tc_dropped[id];
3295 nr->stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN] +=
3296 s.n_bytes_tc_dropped[id];
3302 memcpy(stats, &nr->stats, sizeof(*stats));
3305 *stats_mask = STATS_MASK_DEFAULT;
3309 memset(&nr->stats, 0, sizeof(nr->stats));
3315 read_subport_stats(struct rte_eth_dev *dev,
3317 struct rte_tm_node_stats *stats,
3318 uint64_t *stats_mask,
3321 struct pmd_internals *p = dev->data->dev_private;
3322 uint32_t subport_id = tm_node_subport_id(dev, ns);
3323 struct rte_sched_subport_stats s;
3324 uint32_t tc_ov, tc_id;
3327 int status = rte_sched_subport_read_stats(SCHED(p),
3334 /* Stats accumulate */
3335 for (tc_id = 0; tc_id < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; tc_id++) {
3337 s.n_pkts_tc[tc_id] - s.n_pkts_tc_dropped[tc_id];
3338 ns->stats.n_bytes +=
3339 s.n_bytes_tc[tc_id] - s.n_bytes_tc_dropped[tc_id];
3340 ns->stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN] +=
3341 s.n_pkts_tc_dropped[tc_id];
3342 ns->stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN] +=
3343 s.n_bytes_tc_dropped[tc_id];
3348 memcpy(stats, &ns->stats, sizeof(*stats));
3351 *stats_mask = STATS_MASK_DEFAULT;
3355 memset(&ns->stats, 0, sizeof(ns->stats));
3361 read_pipe_stats(struct rte_eth_dev *dev,
3363 struct rte_tm_node_stats *stats,
3364 uint64_t *stats_mask,
3367 struct pmd_internals *p = dev->data->dev_private;
3369 uint32_t pipe_id = tm_node_pipe_id(dev, np);
3371 struct tm_node *ns = np->parent_node;
3372 uint32_t subport_id = tm_node_subport_id(dev, ns);
3373 uint32_t tc_id, queue_id;
3377 for (i = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++) {
3378 struct rte_sched_queue_stats s;
3381 if (i < RTE_SCHED_TRAFFIC_CLASS_BE) {
3385 tc_id = RTE_SCHED_TRAFFIC_CLASS_BE;
3386 queue_id = i - tc_id;
3389 uint32_t qid = tm_port_queue_id(dev,
3395 int status = rte_sched_queue_read_stats(SCHED(p),
3402 /* Stats accumulate */
3403 np->stats.n_pkts += s.n_pkts - s.n_pkts_dropped;
3404 np->stats.n_bytes += s.n_bytes - s.n_bytes_dropped;
3405 np->stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN] += s.n_pkts_dropped;
3406 np->stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN] +=
3408 np->stats.leaf.n_pkts_queued = qlen;
3413 memcpy(stats, &np->stats, sizeof(*stats));
3416 *stats_mask = STATS_MASK_DEFAULT;
3420 memset(&np->stats, 0, sizeof(np->stats));
3426 read_tc_stats(struct rte_eth_dev *dev,
3428 struct rte_tm_node_stats *stats,
3429 uint64_t *stats_mask,
3432 struct pmd_internals *p = dev->data->dev_private;
3434 uint32_t tc_id = tm_node_tc_id(dev, nt);
3436 struct tm_node *np = nt->parent_node;
3437 uint32_t pipe_id = tm_node_pipe_id(dev, np);
3439 struct tm_node *ns = np->parent_node;
3440 uint32_t subport_id = tm_node_subport_id(dev, ns);
3441 struct rte_sched_queue_stats s;
3447 if (tc_id < RTE_SCHED_TRAFFIC_CLASS_BE) {
3448 qid = tm_port_queue_id(dev,
3454 status = rte_sched_queue_read_stats(SCHED(p),
3461 /* Stats accumulate */
3462 nt->stats.n_pkts += s.n_pkts - s.n_pkts_dropped;
3463 nt->stats.n_bytes += s.n_bytes - s.n_bytes_dropped;
3464 nt->stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN] += s.n_pkts_dropped;
3465 nt->stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN] +=
3467 nt->stats.leaf.n_pkts_queued = qlen;
3469 for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++) {
3470 qid = tm_port_queue_id(dev,
3476 status = rte_sched_queue_read_stats(SCHED(p),
3483 /* Stats accumulate */
3484 nt->stats.n_pkts += s.n_pkts - s.n_pkts_dropped;
3485 nt->stats.n_bytes += s.n_bytes - s.n_bytes_dropped;
3486 nt->stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN] +=
3488 nt->stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN] +=
3490 nt->stats.leaf.n_pkts_queued = qlen;
3496 memcpy(stats, &nt->stats, sizeof(*stats));
3499 *stats_mask = STATS_MASK_DEFAULT;
3503 memset(&nt->stats, 0, sizeof(nt->stats));
3509 read_queue_stats(struct rte_eth_dev *dev,
3511 struct rte_tm_node_stats *stats,
3512 uint64_t *stats_mask,
3515 struct pmd_internals *p = dev->data->dev_private;
3516 struct rte_sched_queue_stats s;
3519 uint32_t queue_id = tm_node_queue_id(dev, nq);
3521 struct tm_node *nt = nq->parent_node;
3522 uint32_t tc_id = tm_node_tc_id(dev, nt);
3524 struct tm_node *np = nt->parent_node;
3525 uint32_t pipe_id = tm_node_pipe_id(dev, np);
3527 struct tm_node *ns = np->parent_node;
3528 uint32_t subport_id = tm_node_subport_id(dev, ns);
3531 uint32_t qid = tm_port_queue_id(dev,
3537 int status = rte_sched_queue_read_stats(SCHED(p),
3544 /* Stats accumulate */
3545 nq->stats.n_pkts += s.n_pkts - s.n_pkts_dropped;
3546 nq->stats.n_bytes += s.n_bytes - s.n_bytes_dropped;
3547 nq->stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN] += s.n_pkts_dropped;
3548 nq->stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN] +=
3550 nq->stats.leaf.n_pkts_queued = qlen;
3554 memcpy(stats, &nq->stats, sizeof(*stats));
3557 *stats_mask = STATS_MASK_QUEUE;
3561 memset(&nq->stats, 0, sizeof(nq->stats));
3566 /* Traffic manager read stats counters for specific node */
3568 pmd_tm_node_stats_read(struct rte_eth_dev *dev,
3570 struct rte_tm_node_stats *stats,
3571 uint64_t *stats_mask,
3573 struct rte_tm_error *error)
3577 /* Port must be started and TM used. */
3578 if (dev->data->dev_started == 0 && (tm_used(dev) == 0))
3579 return -rte_tm_error_set(error,
3581 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3583 rte_strerror(EBUSY));
3585 /* Node must be valid */
3586 n = tm_node_search(dev, node_id);
3588 return -rte_tm_error_set(error,
3590 RTE_TM_ERROR_TYPE_NODE_ID,
3592 rte_strerror(EINVAL));
3595 case TM_NODE_LEVEL_PORT:
3596 if (read_port_stats(dev, n, stats, stats_mask, clear))
3597 return -rte_tm_error_set(error,
3599 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3601 rte_strerror(EINVAL));
3604 case TM_NODE_LEVEL_SUBPORT:
3605 if (read_subport_stats(dev, n, stats, stats_mask, clear))
3606 return -rte_tm_error_set(error,
3608 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3610 rte_strerror(EINVAL));
3613 case TM_NODE_LEVEL_PIPE:
3614 if (read_pipe_stats(dev, n, stats, stats_mask, clear))
3615 return -rte_tm_error_set(error,
3617 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3619 rte_strerror(EINVAL));
3622 case TM_NODE_LEVEL_TC:
3623 if (read_tc_stats(dev, n, stats, stats_mask, clear))
3624 return -rte_tm_error_set(error,
3626 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3628 rte_strerror(EINVAL));
3631 case TM_NODE_LEVEL_QUEUE:
3633 if (read_queue_stats(dev, n, stats, stats_mask, clear))
3634 return -rte_tm_error_set(error,
3636 RTE_TM_ERROR_TYPE_UNSPECIFIED,
3638 rte_strerror(EINVAL));
3643 const struct rte_tm_ops pmd_tm_ops = {
3644 .node_type_get = pmd_tm_node_type_get,
3645 .capabilities_get = pmd_tm_capabilities_get,
3646 .level_capabilities_get = pmd_tm_level_capabilities_get,
3647 .node_capabilities_get = pmd_tm_node_capabilities_get,
3649 .wred_profile_add = pmd_tm_wred_profile_add,
3650 .wred_profile_delete = pmd_tm_wred_profile_delete,
3651 .shared_wred_context_add_update = NULL,
3652 .shared_wred_context_delete = NULL,
3654 .shaper_profile_add = pmd_tm_shaper_profile_add,
3655 .shaper_profile_delete = pmd_tm_shaper_profile_delete,
3656 .shared_shaper_add_update = pmd_tm_shared_shaper_add_update,
3657 .shared_shaper_delete = pmd_tm_shared_shaper_delete,
3659 .node_add = pmd_tm_node_add,
3660 .node_delete = pmd_tm_node_delete,
3661 .node_suspend = NULL,
3662 .node_resume = NULL,
3663 .hierarchy_commit = pmd_tm_hierarchy_commit,
3665 .node_parent_update = pmd_tm_node_parent_update,
3666 .node_shaper_update = pmd_tm_node_shaper_update,
3667 .node_shared_shaper_update = NULL,
3668 .node_stats_update = NULL,
3669 .node_wfq_weight_mode_update = NULL,
3670 .node_cman_update = NULL,
3671 .node_wred_context_update = NULL,
3672 .node_shared_wred_context_update = NULL,
3674 .node_stats_read = pmd_tm_node_stats_read,