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 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(struct rte_eth_dev *dev, uint32_t 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";
520 /* for non-leaf node */
521 if (node_id >= dev->data->nb_tx_queues) {
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";
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 = NULL;
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(dev, 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 if (params->shaper_profile_id != RTE_TM_SHAPER_PROFILE_ID_NONE) {
623 shaper_profile = ixgbe_shaper_profile_search(
624 dev, params->shaper_profile_id);
625 if (!shaper_profile) {
627 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID;
628 error->message = "shaper profile not exist";
633 /* root node if not have a parent */
634 if (parent_node_id == RTE_TM_NODE_ID_NULL) {
636 if (level_id != RTE_TM_NODE_LEVEL_ID_ANY &&
637 level_id > IXGBE_TM_NODE_TYPE_PORT) {
638 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
639 error->message = "Wrong level";
643 /* obviously no more than one root */
645 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
646 error->message = "already have a root";
650 /* add the root node */
651 tm_node = rte_zmalloc("ixgbe_tm_node",
652 sizeof(struct ixgbe_tm_node),
656 tm_node->id = node_id;
657 tm_node->priority = priority;
658 tm_node->weight = weight;
659 tm_node->reference_count = 0;
661 tm_node->parent = NULL;
662 tm_node->shaper_profile = shaper_profile;
663 rte_memcpy(&tm_node->params, params,
664 sizeof(struct rte_tm_node_params));
665 tm_conf->root = tm_node;
667 /* increase the reference counter of the shaper profile */
669 shaper_profile->reference_count++;
674 /* TC or queue node */
675 /* check the parent node */
676 parent_node = ixgbe_tm_node_search(dev, parent_node_id,
679 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
680 error->message = "parent not exist";
683 if (parent_node_type != IXGBE_TM_NODE_TYPE_PORT &&
684 parent_node_type != IXGBE_TM_NODE_TYPE_TC) {
685 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
686 error->message = "parent is not port or TC";
690 if (level_id != RTE_TM_NODE_LEVEL_ID_ANY &&
691 level_id != parent_node_type + 1) {
692 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
693 error->message = "Wrong level";
697 /* check the node number */
698 if (parent_node_type == IXGBE_TM_NODE_TYPE_PORT) {
699 /* check TC number */
700 nb_tcs = ixgbe_tc_nb_get(dev);
701 if (tm_conf->nb_tc_node >= nb_tcs) {
702 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
703 error->message = "too many TCs";
707 /* check queue number */
708 if (tm_conf->nb_queue_node >= dev->data->nb_tx_queues) {
709 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
710 error->message = "too many queues";
714 ixgbe_queue_base_nb_get(dev, parent_node->no, &q_base, &q_nb);
715 if (parent_node->reference_count >= q_nb) {
716 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
717 error->message = "too many queues than TC supported";
723 * For queue, the node id means queue id.
725 if (node_id >= dev->data->nb_tx_queues) {
726 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
727 error->message = "too large queue id";
732 /* add the TC or queue node */
733 tm_node = rte_zmalloc("ixgbe_tm_node",
734 sizeof(struct ixgbe_tm_node),
738 tm_node->id = node_id;
739 tm_node->priority = priority;
740 tm_node->weight = weight;
741 tm_node->reference_count = 0;
742 tm_node->parent = parent_node;
743 tm_node->shaper_profile = shaper_profile;
744 rte_memcpy(&tm_node->params, params,
745 sizeof(struct rte_tm_node_params));
746 if (parent_node_type == IXGBE_TM_NODE_TYPE_PORT) {
747 tm_node->no = parent_node->reference_count;
748 TAILQ_INSERT_TAIL(&tm_conf->tc_list,
750 tm_conf->nb_tc_node++;
752 tm_node->no = q_base + parent_node->reference_count;
753 TAILQ_INSERT_TAIL(&tm_conf->queue_list,
755 tm_conf->nb_queue_node++;
757 tm_node->parent->reference_count++;
759 /* increase the reference counter of the shaper profile */
761 shaper_profile->reference_count++;
767 ixgbe_node_delete(struct rte_eth_dev *dev, uint32_t node_id,
768 struct rte_tm_error *error)
770 struct ixgbe_tm_conf *tm_conf =
771 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
772 enum ixgbe_tm_node_type node_type = IXGBE_TM_NODE_TYPE_MAX;
773 struct ixgbe_tm_node *tm_node;
778 /* if already committed */
779 if (tm_conf->committed) {
780 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
781 error->message = "already committed";
785 if (node_id == RTE_TM_NODE_ID_NULL) {
786 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
787 error->message = "invalid node id";
791 /* check the if the node id exists */
792 tm_node = ixgbe_tm_node_search(dev, node_id, &node_type);
794 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
795 error->message = "no such node";
799 /* the node should have no child */
800 if (tm_node->reference_count) {
801 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
803 "cannot delete a node which has children";
808 if (node_type == IXGBE_TM_NODE_TYPE_PORT) {
809 if (tm_node->shaper_profile)
810 tm_node->shaper_profile->reference_count--;
812 tm_conf->root = NULL;
816 /* TC or queue node */
817 if (tm_node->shaper_profile)
818 tm_node->shaper_profile->reference_count--;
819 tm_node->parent->reference_count--;
820 if (node_type == IXGBE_TM_NODE_TYPE_TC) {
821 TAILQ_REMOVE(&tm_conf->tc_list, tm_node, node);
822 tm_conf->nb_tc_node--;
824 TAILQ_REMOVE(&tm_conf->queue_list, tm_node, node);
825 tm_conf->nb_queue_node--;
833 ixgbe_node_type_get(struct rte_eth_dev *dev, uint32_t node_id,
834 int *is_leaf, struct rte_tm_error *error)
836 enum ixgbe_tm_node_type node_type = IXGBE_TM_NODE_TYPE_MAX;
837 struct ixgbe_tm_node *tm_node;
839 if (!is_leaf || !error)
842 if (node_id == RTE_TM_NODE_ID_NULL) {
843 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
844 error->message = "invalid node id";
848 /* check if the node id exists */
849 tm_node = ixgbe_tm_node_search(dev, node_id, &node_type);
851 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
852 error->message = "no such node";
856 if (node_type == IXGBE_TM_NODE_TYPE_QUEUE)
865 ixgbe_level_capabilities_get(struct rte_eth_dev *dev,
867 struct rte_tm_level_capabilities *cap,
868 struct rte_tm_error *error)
870 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
875 if (level_id >= IXGBE_TM_NODE_TYPE_MAX) {
876 error->type = RTE_TM_ERROR_TYPE_LEVEL_ID;
877 error->message = "too deep level";
882 if (level_id == IXGBE_TM_NODE_TYPE_PORT) {
883 cap->n_nodes_max = 1;
884 cap->n_nodes_nonleaf_max = 1;
885 cap->n_nodes_leaf_max = 0;
886 } else if (level_id == IXGBE_TM_NODE_TYPE_TC) {
888 cap->n_nodes_max = IXGBE_DCB_MAX_TRAFFIC_CLASS;
889 cap->n_nodes_nonleaf_max = IXGBE_DCB_MAX_TRAFFIC_CLASS;
890 cap->n_nodes_leaf_max = 0;
893 cap->n_nodes_max = hw->mac.max_tx_queues;
894 cap->n_nodes_nonleaf_max = 0;
895 cap->n_nodes_leaf_max = hw->mac.max_tx_queues;
898 cap->non_leaf_nodes_identical = true;
899 cap->leaf_nodes_identical = true;
901 if (level_id != IXGBE_TM_NODE_TYPE_QUEUE) {
902 cap->nonleaf.shaper_private_supported = true;
903 cap->nonleaf.shaper_private_dual_rate_supported = false;
904 cap->nonleaf.shaper_private_rate_min = 0;
905 /* 10Gbps -> 1.25GBps */
906 cap->nonleaf.shaper_private_rate_max = 1250000000ull;
907 cap->nonleaf.shaper_shared_n_max = 0;
908 if (level_id == IXGBE_TM_NODE_TYPE_PORT)
909 cap->nonleaf.sched_n_children_max =
910 IXGBE_DCB_MAX_TRAFFIC_CLASS;
912 cap->nonleaf.sched_n_children_max =
913 hw->mac.max_tx_queues;
914 cap->nonleaf.sched_sp_n_priorities_max = 1;
915 cap->nonleaf.sched_wfq_n_children_per_group_max = 0;
916 cap->nonleaf.sched_wfq_n_groups_max = 0;
917 cap->nonleaf.sched_wfq_weight_max = 1;
918 cap->nonleaf.stats_mask = 0;
924 cap->leaf.shaper_private_supported = true;
925 cap->leaf.shaper_private_dual_rate_supported = false;
926 cap->leaf.shaper_private_rate_min = 0;
927 /* 10Gbps -> 1.25GBps */
928 cap->leaf.shaper_private_rate_max = 1250000000ull;
929 cap->leaf.shaper_shared_n_max = 0;
930 cap->leaf.cman_head_drop_supported = false;
931 cap->leaf.cman_wred_context_private_supported = true;
932 cap->leaf.cman_wred_context_shared_n_max = 0;
933 cap->leaf.stats_mask = 0;
939 ixgbe_node_capabilities_get(struct rte_eth_dev *dev,
941 struct rte_tm_node_capabilities *cap,
942 struct rte_tm_error *error)
944 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
945 enum ixgbe_tm_node_type node_type = IXGBE_TM_NODE_TYPE_MAX;
946 struct ixgbe_tm_node *tm_node;
951 if (node_id == RTE_TM_NODE_ID_NULL) {
952 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
953 error->message = "invalid node id";
957 /* check if the node id exists */
958 tm_node = ixgbe_tm_node_search(dev, node_id, &node_type);
960 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
961 error->message = "no such node";
965 cap->shaper_private_supported = true;
966 cap->shaper_private_dual_rate_supported = false;
967 cap->shaper_private_rate_min = 0;
968 /* 10Gbps -> 1.25GBps */
969 cap->shaper_private_rate_max = 1250000000ull;
970 cap->shaper_shared_n_max = 0;
972 if (node_type == IXGBE_TM_NODE_TYPE_QUEUE) {
973 cap->leaf.cman_head_drop_supported = false;
974 cap->leaf.cman_wred_context_private_supported = true;
975 cap->leaf.cman_wred_context_shared_n_max = 0;
977 if (node_type == IXGBE_TM_NODE_TYPE_PORT)
978 cap->nonleaf.sched_n_children_max =
979 IXGBE_DCB_MAX_TRAFFIC_CLASS;
981 cap->nonleaf.sched_n_children_max =
982 hw->mac.max_tx_queues;
983 cap->nonleaf.sched_sp_n_priorities_max = 1;
984 cap->nonleaf.sched_wfq_n_children_per_group_max = 0;
985 cap->nonleaf.sched_wfq_n_groups_max = 0;
986 cap->nonleaf.sched_wfq_weight_max = 1;
995 ixgbe_hierarchy_commit(struct rte_eth_dev *dev,
997 struct rte_tm_error *error)
999 struct ixgbe_tm_conf *tm_conf =
1000 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
1001 struct ixgbe_tm_node *tm_node;
1008 /* check the setting */
1012 /* not support port max bandwidth yet */
1013 if (tm_conf->root->shaper_profile &&
1014 tm_conf->root->shaper_profile->profile.peak.rate) {
1015 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
1016 error->message = "no port max bandwidth";
1020 /* HW not support TC max bandwidth */
1021 TAILQ_FOREACH(tm_node, &tm_conf->tc_list, node) {
1022 if (tm_node->shaper_profile &&
1023 tm_node->shaper_profile->profile.peak.rate) {
1024 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
1025 error->message = "no TC max bandwidth";
1030 /* queue max bandwidth */
1031 TAILQ_FOREACH(tm_node, &tm_conf->queue_list, node) {
1032 if (tm_node->shaper_profile)
1033 bw = tm_node->shaper_profile->profile.peak.rate;
1037 /* interpret Bps to Mbps */
1038 bw = bw * 8 / 1000 / 1000;
1039 ret = ixgbe_set_queue_rate_limit(dev, tm_node->no, bw);
1041 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
1043 "failed to set queue max bandwidth";
1050 tm_conf->committed = true;
1054 /* clear all the traffic manager configuration */
1055 if (clear_on_fail) {
1056 ixgbe_tm_conf_uninit(dev);
1057 ixgbe_tm_conf_init(dev);