4 * Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_malloc.h>
36 #include "ixgbe_ethdev.h"
38 static int ixgbe_tm_capabilities_get(struct rte_eth_dev *dev,
39 struct rte_tm_capabilities *cap,
40 struct rte_tm_error *error);
41 static int ixgbe_shaper_profile_add(struct rte_eth_dev *dev,
42 uint32_t shaper_profile_id,
43 struct rte_tm_shaper_params *profile,
44 struct rte_tm_error *error);
45 static int ixgbe_shaper_profile_del(struct rte_eth_dev *dev,
46 uint32_t shaper_profile_id,
47 struct rte_tm_error *error);
48 static int ixgbe_node_add(struct rte_eth_dev *dev, uint32_t node_id,
49 uint32_t parent_node_id, uint32_t priority,
50 uint32_t weight, uint32_t level_id,
51 struct rte_tm_node_params *params,
52 struct rte_tm_error *error);
53 static int ixgbe_node_delete(struct rte_eth_dev *dev, uint32_t node_id,
54 struct rte_tm_error *error);
55 static int ixgbe_node_type_get(struct rte_eth_dev *dev, uint32_t node_id,
56 int *is_leaf, struct rte_tm_error *error);
57 static int ixgbe_level_capabilities_get(struct rte_eth_dev *dev,
59 struct rte_tm_level_capabilities *cap,
60 struct rte_tm_error *error);
61 static int ixgbe_node_capabilities_get(struct rte_eth_dev *dev,
63 struct rte_tm_node_capabilities *cap,
64 struct rte_tm_error *error);
65 static int ixgbe_hierarchy_commit(struct rte_eth_dev *dev,
67 struct rte_tm_error *error);
69 const struct rte_tm_ops ixgbe_tm_ops = {
70 .capabilities_get = ixgbe_tm_capabilities_get,
71 .shaper_profile_add = ixgbe_shaper_profile_add,
72 .shaper_profile_delete = ixgbe_shaper_profile_del,
73 .node_add = ixgbe_node_add,
74 .node_delete = ixgbe_node_delete,
75 .node_type_get = ixgbe_node_type_get,
76 .level_capabilities_get = ixgbe_level_capabilities_get,
77 .node_capabilities_get = ixgbe_node_capabilities_get,
78 .hierarchy_commit = ixgbe_hierarchy_commit,
82 ixgbe_tm_ops_get(struct rte_eth_dev *dev __rte_unused,
88 *(const void **)arg = &ixgbe_tm_ops;
94 ixgbe_tm_conf_init(struct rte_eth_dev *dev)
96 struct ixgbe_tm_conf *tm_conf =
97 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
99 /* initialize shaper profile list */
100 TAILQ_INIT(&tm_conf->shaper_profile_list);
102 /* initialize node configuration */
103 tm_conf->root = NULL;
104 TAILQ_INIT(&tm_conf->queue_list);
105 TAILQ_INIT(&tm_conf->tc_list);
106 tm_conf->nb_tc_node = 0;
107 tm_conf->nb_queue_node = 0;
108 tm_conf->committed = false;
112 ixgbe_tm_conf_uninit(struct rte_eth_dev *dev)
114 struct ixgbe_tm_conf *tm_conf =
115 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
116 struct ixgbe_tm_shaper_profile *shaper_profile;
117 struct ixgbe_tm_node *tm_node;
119 /* clear node configuration */
120 while ((tm_node = TAILQ_FIRST(&tm_conf->queue_list))) {
121 TAILQ_REMOVE(&tm_conf->queue_list, tm_node, node);
124 tm_conf->nb_queue_node = 0;
125 while ((tm_node = TAILQ_FIRST(&tm_conf->tc_list))) {
126 TAILQ_REMOVE(&tm_conf->tc_list, tm_node, node);
129 tm_conf->nb_tc_node = 0;
131 rte_free(tm_conf->root);
132 tm_conf->root = NULL;
135 /* Remove all shaper profiles */
136 while ((shaper_profile =
137 TAILQ_FIRST(&tm_conf->shaper_profile_list))) {
138 TAILQ_REMOVE(&tm_conf->shaper_profile_list,
139 shaper_profile, node);
140 rte_free(shaper_profile);
144 static inline uint8_t
145 ixgbe_tc_nb_get(struct rte_eth_dev *dev)
147 struct rte_eth_conf *eth_conf;
150 eth_conf = &dev->data->dev_conf;
151 if (eth_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
152 nb_tcs = eth_conf->tx_adv_conf.dcb_tx_conf.nb_tcs;
153 } else if (eth_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
154 if (eth_conf->tx_adv_conf.vmdq_dcb_tx_conf.nb_queue_pools ==
167 ixgbe_tm_capabilities_get(struct rte_eth_dev *dev,
168 struct rte_tm_capabilities *cap,
169 struct rte_tm_error *error)
171 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
172 uint8_t tc_nb = ixgbe_tc_nb_get(dev);
177 if (tc_nb > hw->mac.max_tx_queues)
180 error->type = RTE_TM_ERROR_TYPE_NONE;
182 /* set all the parameters to 0 first. */
183 memset(cap, 0, sizeof(struct rte_tm_capabilities));
186 * here is the max capability not the current configuration.
188 /* port + TCs + queues */
189 cap->n_nodes_max = 1 + IXGBE_DCB_MAX_TRAFFIC_CLASS +
190 hw->mac.max_tx_queues;
191 cap->n_levels_max = 3;
192 cap->non_leaf_nodes_identical = 1;
193 cap->leaf_nodes_identical = 1;
194 cap->shaper_n_max = cap->n_nodes_max;
195 cap->shaper_private_n_max = cap->n_nodes_max;
196 cap->shaper_private_dual_rate_n_max = 0;
197 cap->shaper_private_rate_min = 0;
198 /* 10Gbps -> 1.25GBps */
199 cap->shaper_private_rate_max = 1250000000ull;
200 cap->shaper_shared_n_max = 0;
201 cap->shaper_shared_n_nodes_per_shaper_max = 0;
202 cap->shaper_shared_n_shapers_per_node_max = 0;
203 cap->shaper_shared_dual_rate_n_max = 0;
204 cap->shaper_shared_rate_min = 0;
205 cap->shaper_shared_rate_max = 0;
206 cap->sched_n_children_max = hw->mac.max_tx_queues;
208 * HW supports SP. But no plan to support it now.
209 * So, all the nodes should have the same priority.
211 cap->sched_sp_n_priorities_max = 1;
212 cap->sched_wfq_n_children_per_group_max = 0;
213 cap->sched_wfq_n_groups_max = 0;
215 * SW only supports fair round robin now.
216 * So, all the nodes should have the same weight.
218 cap->sched_wfq_weight_max = 1;
219 cap->cman_head_drop_supported = 0;
220 cap->dynamic_update_mask = 0;
221 cap->shaper_pkt_length_adjust_min = RTE_TM_ETH_FRAMING_OVERHEAD;
222 cap->shaper_pkt_length_adjust_max = RTE_TM_ETH_FRAMING_OVERHEAD_FCS;
223 cap->cman_wred_context_n_max = 0;
224 cap->cman_wred_context_private_n_max = 0;
225 cap->cman_wred_context_shared_n_max = 0;
226 cap->cman_wred_context_shared_n_nodes_per_context_max = 0;
227 cap->cman_wred_context_shared_n_contexts_per_node_max = 0;
233 static inline struct ixgbe_tm_shaper_profile *
234 ixgbe_shaper_profile_search(struct rte_eth_dev *dev,
235 uint32_t shaper_profile_id)
237 struct ixgbe_tm_conf *tm_conf =
238 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
239 struct ixgbe_shaper_profile_list *shaper_profile_list =
240 &tm_conf->shaper_profile_list;
241 struct ixgbe_tm_shaper_profile *shaper_profile;
243 TAILQ_FOREACH(shaper_profile, shaper_profile_list, node) {
244 if (shaper_profile_id == shaper_profile->shaper_profile_id)
245 return shaper_profile;
252 ixgbe_shaper_profile_param_check(struct rte_tm_shaper_params *profile,
253 struct rte_tm_error *error)
255 /* min rate not supported */
256 if (profile->committed.rate) {
257 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE;
258 error->message = "committed rate not supported";
261 /* min bucket size not supported */
262 if (profile->committed.size) {
263 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_SIZE;
264 error->message = "committed bucket size not supported";
267 /* max bucket size not supported */
268 if (profile->peak.size) {
269 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE;
270 error->message = "peak bucket size not supported";
273 /* length adjustment not supported */
274 if (profile->pkt_length_adjust) {
275 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PKT_ADJUST_LEN;
276 error->message = "packet length adjustment not supported";
284 ixgbe_shaper_profile_add(struct rte_eth_dev *dev,
285 uint32_t shaper_profile_id,
286 struct rte_tm_shaper_params *profile,
287 struct rte_tm_error *error)
289 struct ixgbe_tm_conf *tm_conf =
290 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
291 struct ixgbe_tm_shaper_profile *shaper_profile;
294 if (!profile || !error)
297 ret = ixgbe_shaper_profile_param_check(profile, error);
301 shaper_profile = ixgbe_shaper_profile_search(dev, shaper_profile_id);
303 if (shaper_profile) {
304 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
305 error->message = "profile ID exist";
309 shaper_profile = rte_zmalloc("ixgbe_tm_shaper_profile",
310 sizeof(struct ixgbe_tm_shaper_profile),
314 shaper_profile->shaper_profile_id = shaper_profile_id;
315 (void)rte_memcpy(&shaper_profile->profile, profile,
316 sizeof(struct rte_tm_shaper_params));
317 TAILQ_INSERT_TAIL(&tm_conf->shaper_profile_list,
318 shaper_profile, node);
324 ixgbe_shaper_profile_del(struct rte_eth_dev *dev,
325 uint32_t shaper_profile_id,
326 struct rte_tm_error *error)
328 struct ixgbe_tm_conf *tm_conf =
329 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
330 struct ixgbe_tm_shaper_profile *shaper_profile;
335 shaper_profile = ixgbe_shaper_profile_search(dev, shaper_profile_id);
337 if (!shaper_profile) {
338 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
339 error->message = "profile ID not exist";
343 /* don't delete a profile if it's used by one or several nodes */
344 if (shaper_profile->reference_count) {
345 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
346 error->message = "profile in use";
350 TAILQ_REMOVE(&tm_conf->shaper_profile_list, shaper_profile, node);
351 rte_free(shaper_profile);
356 static inline struct ixgbe_tm_node *
357 ixgbe_tm_node_search(struct rte_eth_dev *dev, uint32_t node_id,
358 enum ixgbe_tm_node_type *node_type)
360 struct ixgbe_tm_conf *tm_conf =
361 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
362 struct ixgbe_tm_node *tm_node;
364 if (tm_conf->root && tm_conf->root->id == node_id) {
365 *node_type = IXGBE_TM_NODE_TYPE_PORT;
366 return tm_conf->root;
369 TAILQ_FOREACH(tm_node, &tm_conf->tc_list, node) {
370 if (tm_node->id == node_id) {
371 *node_type = IXGBE_TM_NODE_TYPE_TC;
376 TAILQ_FOREACH(tm_node, &tm_conf->queue_list, node) {
377 if (tm_node->id == node_id) {
378 *node_type = IXGBE_TM_NODE_TYPE_QUEUE;
387 ixgbe_queue_base_nb_get(struct rte_eth_dev *dev, uint16_t tc_node_no,
388 uint16_t *base, uint16_t *nb)
390 uint8_t nb_tcs = ixgbe_tc_nb_get(dev);
391 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
392 uint16_t vf_num = pci_dev->max_vfs;
401 if (vf_num >= ETH_32_POOLS) {
404 } else if (vf_num >= ETH_16_POOLS) {
414 *base = vf_num * nb_tcs + tc_node_no;
418 if (nb_tcs == ETH_8_TCS) {
419 switch (tc_node_no) {
456 switch (tc_node_no) {
458 * If no VF and no DCB, only 64 queues can be used.
459 * This case also be covered by this "case 0".
485 ixgbe_node_param_check(uint32_t node_id, uint32_t parent_node_id,
486 uint32_t priority, uint32_t weight,
487 struct rte_tm_node_params *params,
488 struct rte_tm_error *error)
490 if (node_id == RTE_TM_NODE_ID_NULL) {
491 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
492 error->message = "invalid node id";
497 error->type = RTE_TM_ERROR_TYPE_NODE_PRIORITY;
498 error->message = "priority should be 0";
503 error->type = RTE_TM_ERROR_TYPE_NODE_WEIGHT;
504 error->message = "weight must be 1";
508 /* not support shared shaper */
509 if (params->shared_shaper_id) {
510 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID;
511 error->message = "shared shaper not supported";
514 if (params->n_shared_shapers) {
515 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS;
516 error->message = "shared shaper not supported";
521 if (parent_node_id == RTE_TM_NODE_ID_NULL) {
522 /* check the unsupported parameters */
523 if (params->nonleaf.wfq_weight_mode) {
525 RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE;
526 error->message = "WFQ not supported";
529 if (params->nonleaf.n_sp_priorities != 1) {
531 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES;
532 error->message = "SP priority not supported";
534 } else if (params->nonleaf.wfq_weight_mode &&
535 !(*params->nonleaf.wfq_weight_mode)) {
537 RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE;
538 error->message = "WFP should be byte mode";
545 /* for TC or queue node */
546 /* check the unsupported parameters */
547 if (params->leaf.cman) {
548 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN;
549 error->message = "Congestion management not supported";
552 if (params->leaf.wred.wred_profile_id !=
553 RTE_TM_WRED_PROFILE_ID_NONE) {
555 RTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID;
556 error->message = "WRED not supported";
559 if (params->leaf.wred.shared_wred_context_id) {
561 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_WRED_CONTEXT_ID;
562 error->message = "WRED not supported";
565 if (params->leaf.wred.n_shared_wred_contexts) {
567 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS;
568 error->message = "WRED not supported";
576 * Now the TC and queue configuration is controlled by DCB.
577 * We need check if the node configuration follows the DCB configuration.
578 * In the future, we may use TM to cover DCB.
581 ixgbe_node_add(struct rte_eth_dev *dev, uint32_t node_id,
582 uint32_t parent_node_id, uint32_t priority,
583 uint32_t weight, uint32_t level_id,
584 struct rte_tm_node_params *params,
585 struct rte_tm_error *error)
587 struct ixgbe_tm_conf *tm_conf =
588 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
589 enum ixgbe_tm_node_type node_type = IXGBE_TM_NODE_TYPE_MAX;
590 enum ixgbe_tm_node_type parent_node_type = IXGBE_TM_NODE_TYPE_MAX;
591 struct ixgbe_tm_shaper_profile *shaper_profile;
592 struct ixgbe_tm_node *tm_node;
593 struct ixgbe_tm_node *parent_node;
599 if (!params || !error)
602 /* if already committed */
603 if (tm_conf->committed) {
604 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
605 error->message = "already committed";
609 ret = ixgbe_node_param_check(node_id, parent_node_id, priority, weight,
614 /* check if the node ID is already used */
615 if (ixgbe_tm_node_search(dev, node_id, &node_type)) {
616 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
617 error->message = "node id already used";
621 /* check the shaper profile id */
622 shaper_profile = ixgbe_shaper_profile_search(dev,
623 params->shaper_profile_id);
624 if (!shaper_profile) {
625 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID;
626 error->message = "shaper profile not exist";
630 /* root node if not have a parent */
631 if (parent_node_id == RTE_TM_NODE_ID_NULL) {
633 if (level_id != RTE_TM_NODE_LEVEL_ID_ANY &&
634 level_id > IXGBE_TM_NODE_TYPE_PORT) {
635 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
636 error->message = "Wrong level";
640 /* obviously no more than one root */
642 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
643 error->message = "already have a root";
647 /* add the root node */
648 tm_node = rte_zmalloc("ixgbe_tm_node",
649 sizeof(struct ixgbe_tm_node),
653 tm_node->id = node_id;
654 tm_node->priority = priority;
655 tm_node->weight = weight;
656 tm_node->reference_count = 0;
658 tm_node->parent = NULL;
659 tm_node->shaper_profile = shaper_profile;
660 (void)rte_memcpy(&tm_node->params, params,
661 sizeof(struct rte_tm_node_params));
662 tm_conf->root = tm_node;
664 /* increase the reference counter of the shaper profile */
665 shaper_profile->reference_count++;
670 /* TC or queue node */
671 /* check the parent node */
672 parent_node = ixgbe_tm_node_search(dev, parent_node_id,
675 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
676 error->message = "parent not exist";
679 if (parent_node_type != IXGBE_TM_NODE_TYPE_PORT &&
680 parent_node_type != IXGBE_TM_NODE_TYPE_TC) {
681 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
682 error->message = "parent is not port or TC";
686 if (level_id != RTE_TM_NODE_LEVEL_ID_ANY &&
687 level_id != parent_node_type + 1) {
688 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
689 error->message = "Wrong level";
693 /* check the node number */
694 if (parent_node_type == IXGBE_TM_NODE_TYPE_PORT) {
695 /* check TC number */
696 nb_tcs = ixgbe_tc_nb_get(dev);
697 if (tm_conf->nb_tc_node >= nb_tcs) {
698 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
699 error->message = "too many TCs";
703 /* check queue number */
704 if (tm_conf->nb_queue_node >= dev->data->nb_tx_queues) {
705 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
706 error->message = "too many queues";
710 ixgbe_queue_base_nb_get(dev, parent_node->no, &q_base, &q_nb);
711 if (parent_node->reference_count >= q_nb) {
712 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
713 error->message = "too many queues than TC supported";
719 * For queue, the node id means queue id.
721 if (node_id >= dev->data->nb_tx_queues) {
722 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
723 error->message = "too large queue id";
728 /* add the TC or queue node */
729 tm_node = rte_zmalloc("ixgbe_tm_node",
730 sizeof(struct ixgbe_tm_node),
734 tm_node->id = node_id;
735 tm_node->priority = priority;
736 tm_node->weight = weight;
737 tm_node->reference_count = 0;
738 tm_node->parent = parent_node;
739 tm_node->shaper_profile = shaper_profile;
740 (void)rte_memcpy(&tm_node->params, params,
741 sizeof(struct rte_tm_node_params));
742 if (parent_node_type == IXGBE_TM_NODE_TYPE_PORT) {
743 tm_node->no = parent_node->reference_count;
744 TAILQ_INSERT_TAIL(&tm_conf->tc_list,
746 tm_conf->nb_tc_node++;
748 tm_node->no = q_base + parent_node->reference_count;
749 TAILQ_INSERT_TAIL(&tm_conf->queue_list,
751 tm_conf->nb_queue_node++;
753 tm_node->parent->reference_count++;
755 /* increase the reference counter of the shaper profile */
756 shaper_profile->reference_count++;
762 ixgbe_node_delete(struct rte_eth_dev *dev, uint32_t node_id,
763 struct rte_tm_error *error)
765 struct ixgbe_tm_conf *tm_conf =
766 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
767 enum ixgbe_tm_node_type node_type = IXGBE_TM_NODE_TYPE_MAX;
768 struct ixgbe_tm_node *tm_node;
773 /* if already committed */
774 if (tm_conf->committed) {
775 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
776 error->message = "already committed";
780 if (node_id == RTE_TM_NODE_ID_NULL) {
781 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
782 error->message = "invalid node id";
786 /* check the if the node id exists */
787 tm_node = ixgbe_tm_node_search(dev, node_id, &node_type);
789 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
790 error->message = "no such node";
794 /* the node should have no child */
795 if (tm_node->reference_count) {
796 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
798 "cannot delete a node which has children";
803 if (node_type == IXGBE_TM_NODE_TYPE_PORT) {
804 tm_node->shaper_profile->reference_count--;
806 tm_conf->root = NULL;
810 /* TC or queue node */
811 tm_node->shaper_profile->reference_count--;
812 tm_node->parent->reference_count--;
813 if (node_type == IXGBE_TM_NODE_TYPE_TC) {
814 TAILQ_REMOVE(&tm_conf->tc_list, tm_node, node);
815 tm_conf->nb_tc_node--;
817 TAILQ_REMOVE(&tm_conf->queue_list, tm_node, node);
818 tm_conf->nb_queue_node--;
826 ixgbe_node_type_get(struct rte_eth_dev *dev, uint32_t node_id,
827 int *is_leaf, struct rte_tm_error *error)
829 enum ixgbe_tm_node_type node_type = IXGBE_TM_NODE_TYPE_MAX;
830 struct ixgbe_tm_node *tm_node;
832 if (!is_leaf || !error)
835 if (node_id == RTE_TM_NODE_ID_NULL) {
836 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
837 error->message = "invalid node id";
841 /* check if the node id exists */
842 tm_node = ixgbe_tm_node_search(dev, node_id, &node_type);
844 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
845 error->message = "no such node";
849 if (node_type == IXGBE_TM_NODE_TYPE_QUEUE)
858 ixgbe_level_capabilities_get(struct rte_eth_dev *dev,
860 struct rte_tm_level_capabilities *cap,
861 struct rte_tm_error *error)
863 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
868 if (level_id >= IXGBE_TM_NODE_TYPE_MAX) {
869 error->type = RTE_TM_ERROR_TYPE_LEVEL_ID;
870 error->message = "too deep level";
875 if (level_id == IXGBE_TM_NODE_TYPE_PORT) {
876 cap->n_nodes_max = 1;
877 cap->n_nodes_nonleaf_max = 1;
878 cap->n_nodes_leaf_max = 0;
879 cap->non_leaf_nodes_identical = true;
880 cap->leaf_nodes_identical = true;
881 cap->nonleaf.shaper_private_supported = true;
882 cap->nonleaf.shaper_private_dual_rate_supported = false;
883 cap->nonleaf.shaper_private_rate_min = 0;
884 /* 10Gbps -> 1.25GBps */
885 cap->nonleaf.shaper_private_rate_max = 1250000000ull;
886 cap->nonleaf.shaper_shared_n_max = 0;
887 cap->nonleaf.sched_n_children_max = IXGBE_DCB_MAX_TRAFFIC_CLASS;
888 cap->nonleaf.sched_sp_n_priorities_max = 1;
889 cap->nonleaf.sched_wfq_n_children_per_group_max = 0;
890 cap->nonleaf.sched_wfq_n_groups_max = 0;
891 cap->nonleaf.sched_wfq_weight_max = 1;
892 cap->nonleaf.stats_mask = 0;
897 /* TC or queue node */
898 if (level_id == IXGBE_TM_NODE_TYPE_TC) {
900 cap->n_nodes_max = IXGBE_DCB_MAX_TRAFFIC_CLASS;
901 cap->n_nodes_nonleaf_max = IXGBE_DCB_MAX_TRAFFIC_CLASS;
902 cap->n_nodes_leaf_max = 0;
903 cap->non_leaf_nodes_identical = true;
906 cap->n_nodes_max = hw->mac.max_tx_queues;
907 cap->n_nodes_nonleaf_max = 0;
908 cap->n_nodes_leaf_max = hw->mac.max_tx_queues;
909 cap->non_leaf_nodes_identical = true;
911 cap->leaf_nodes_identical = true;
912 cap->leaf.shaper_private_supported = true;
913 cap->leaf.shaper_private_dual_rate_supported = false;
914 cap->leaf.shaper_private_rate_min = 0;
915 /* 10Gbps -> 1.25GBps */
916 cap->leaf.shaper_private_rate_max = 1250000000ull;
917 cap->leaf.shaper_shared_n_max = 0;
918 cap->leaf.cman_head_drop_supported = false;
919 cap->leaf.cman_wred_context_private_supported = true;
920 cap->leaf.cman_wred_context_shared_n_max = 0;
921 cap->leaf.stats_mask = 0;
927 ixgbe_node_capabilities_get(struct rte_eth_dev *dev,
929 struct rte_tm_node_capabilities *cap,
930 struct rte_tm_error *error)
932 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
933 enum ixgbe_tm_node_type node_type = IXGBE_TM_NODE_TYPE_MAX;
934 struct ixgbe_tm_node *tm_node;
939 if (node_id == RTE_TM_NODE_ID_NULL) {
940 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
941 error->message = "invalid node id";
945 /* check if the node id exists */
946 tm_node = ixgbe_tm_node_search(dev, node_id, &node_type);
948 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
949 error->message = "no such node";
953 cap->shaper_private_supported = true;
954 cap->shaper_private_dual_rate_supported = false;
955 cap->shaper_private_rate_min = 0;
956 /* 10Gbps -> 1.25GBps */
957 cap->shaper_private_rate_max = 1250000000ull;
958 cap->shaper_shared_n_max = 0;
960 if (node_type == IXGBE_TM_NODE_TYPE_QUEUE) {
961 cap->leaf.cman_head_drop_supported = false;
962 cap->leaf.cman_wred_context_private_supported = true;
963 cap->leaf.cman_wred_context_shared_n_max = 0;
965 if (node_type == IXGBE_TM_NODE_TYPE_PORT)
966 cap->nonleaf.sched_n_children_max =
967 IXGBE_DCB_MAX_TRAFFIC_CLASS;
969 cap->nonleaf.sched_n_children_max =
970 hw->mac.max_tx_queues;
971 cap->nonleaf.sched_sp_n_priorities_max = 1;
972 cap->nonleaf.sched_wfq_n_children_per_group_max = 0;
973 cap->nonleaf.sched_wfq_n_groups_max = 0;
974 cap->nonleaf.sched_wfq_weight_max = 1;
983 ixgbe_hierarchy_commit(struct rte_eth_dev *dev,
985 struct rte_tm_error *error)
987 struct ixgbe_tm_conf *tm_conf =
988 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
989 struct ixgbe_tm_node *tm_node;
996 /* check the setting */
1000 /* not support port max bandwidth yet */
1001 if (tm_conf->root->shaper_profile->profile.peak.rate) {
1002 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
1003 error->message = "no port max bandwidth";
1007 /* HW not support TC max bandwidth */
1008 TAILQ_FOREACH(tm_node, &tm_conf->tc_list, node) {
1009 if (tm_node->shaper_profile->profile.peak.rate) {
1010 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
1011 error->message = "no TC max bandwidth";
1016 /* queue max bandwidth */
1017 TAILQ_FOREACH(tm_node, &tm_conf->queue_list, node) {
1018 bw = tm_node->shaper_profile->profile.peak.rate;
1020 /* interpret Bps to Mbps */
1021 bw = bw * 8 / 1000 / 1000;
1022 ret = ixgbe_set_queue_rate_limit(dev, tm_node->no, bw);
1024 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
1026 "failed to set queue max bandwidth";
1033 tm_conf->committed = true;
1037 /* clear all the traffic manager configuration */
1038 if (clear_on_fail) {
1039 ixgbe_tm_conf_uninit(dev);
1040 ixgbe_tm_conf_init(dev);