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 "base/i40e_prototype.h"
37 #include "i40e_ethdev.h"
39 static int i40e_tm_capabilities_get(struct rte_eth_dev *dev,
40 struct rte_tm_capabilities *cap,
41 struct rte_tm_error *error);
42 static int i40e_shaper_profile_add(struct rte_eth_dev *dev,
43 uint32_t shaper_profile_id,
44 struct rte_tm_shaper_params *profile,
45 struct rte_tm_error *error);
46 static int i40e_shaper_profile_del(struct rte_eth_dev *dev,
47 uint32_t shaper_profile_id,
48 struct rte_tm_error *error);
49 static int i40e_node_add(struct rte_eth_dev *dev, uint32_t node_id,
50 uint32_t parent_node_id, uint32_t priority,
51 uint32_t weight, uint32_t level_id,
52 struct rte_tm_node_params *params,
53 struct rte_tm_error *error);
54 static int i40e_node_delete(struct rte_eth_dev *dev, uint32_t node_id,
55 struct rte_tm_error *error);
56 static int i40e_node_type_get(struct rte_eth_dev *dev, uint32_t node_id,
57 int *is_leaf, struct rte_tm_error *error);
58 static int i40e_level_capabilities_get(struct rte_eth_dev *dev,
60 struct rte_tm_level_capabilities *cap,
61 struct rte_tm_error *error);
62 static int i40e_node_capabilities_get(struct rte_eth_dev *dev,
64 struct rte_tm_node_capabilities *cap,
65 struct rte_tm_error *error);
66 static int i40e_hierarchy_commit(struct rte_eth_dev *dev,
68 struct rte_tm_error *error);
70 const struct rte_tm_ops i40e_tm_ops = {
71 .capabilities_get = i40e_tm_capabilities_get,
72 .shaper_profile_add = i40e_shaper_profile_add,
73 .shaper_profile_delete = i40e_shaper_profile_del,
74 .node_add = i40e_node_add,
75 .node_delete = i40e_node_delete,
76 .node_type_get = i40e_node_type_get,
77 .level_capabilities_get = i40e_level_capabilities_get,
78 .node_capabilities_get = i40e_node_capabilities_get,
79 .hierarchy_commit = i40e_hierarchy_commit,
83 i40e_tm_ops_get(struct rte_eth_dev *dev __rte_unused,
89 *(const void **)arg = &i40e_tm_ops;
95 i40e_tm_conf_init(struct rte_eth_dev *dev)
97 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
99 /* initialize shaper profile list */
100 TAILQ_INIT(&pf->tm_conf.shaper_profile_list);
102 /* initialize node configuration */
103 pf->tm_conf.root = NULL;
104 TAILQ_INIT(&pf->tm_conf.tc_list);
105 TAILQ_INIT(&pf->tm_conf.queue_list);
106 pf->tm_conf.nb_tc_node = 0;
107 pf->tm_conf.nb_queue_node = 0;
108 pf->tm_conf.committed = false;
112 i40e_tm_conf_uninit(struct rte_eth_dev *dev)
114 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
115 struct i40e_tm_shaper_profile *shaper_profile;
116 struct i40e_tm_node *tm_node;
118 /* clear node configuration */
119 while ((tm_node = TAILQ_FIRST(&pf->tm_conf.queue_list))) {
120 TAILQ_REMOVE(&pf->tm_conf.queue_list, tm_node, node);
123 pf->tm_conf.nb_queue_node = 0;
124 while ((tm_node = TAILQ_FIRST(&pf->tm_conf.tc_list))) {
125 TAILQ_REMOVE(&pf->tm_conf.tc_list, tm_node, node);
128 pf->tm_conf.nb_tc_node = 0;
129 if (pf->tm_conf.root) {
130 rte_free(pf->tm_conf.root);
131 pf->tm_conf.root = NULL;
134 /* Remove all shaper profiles */
135 while ((shaper_profile =
136 TAILQ_FIRST(&pf->tm_conf.shaper_profile_list))) {
137 TAILQ_REMOVE(&pf->tm_conf.shaper_profile_list,
138 shaper_profile, node);
139 rte_free(shaper_profile);
143 static inline uint16_t
144 i40e_tc_nb_get(struct rte_eth_dev *dev)
146 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
147 struct i40e_vsi *main_vsi = pf->main_vsi;
151 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
152 if (main_vsi->enabled_tc & BIT_ULL(i))
160 i40e_tm_capabilities_get(struct rte_eth_dev *dev,
161 struct rte_tm_capabilities *cap,
162 struct rte_tm_error *error)
164 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
165 uint16_t tc_nb = i40e_tc_nb_get(dev);
170 if (tc_nb > hw->func_caps.num_tx_qp)
173 error->type = RTE_TM_ERROR_TYPE_NONE;
175 /* set all the parameters to 0 first. */
176 memset(cap, 0, sizeof(struct rte_tm_capabilities));
179 * support port + TCs + queues
180 * here shows the max capability not the current configuration.
182 cap->n_nodes_max = 1 + I40E_MAX_TRAFFIC_CLASS + hw->func_caps.num_tx_qp;
183 cap->n_levels_max = 3; /* port, TC, queue */
184 cap->non_leaf_nodes_identical = 1;
185 cap->leaf_nodes_identical = 1;
186 cap->shaper_n_max = cap->n_nodes_max;
187 cap->shaper_private_n_max = cap->n_nodes_max;
188 cap->shaper_private_dual_rate_n_max = 0;
189 cap->shaper_private_rate_min = 0;
190 /* 40Gbps -> 5GBps */
191 cap->shaper_private_rate_max = 5000000000ull;
192 cap->shaper_shared_n_max = 0;
193 cap->shaper_shared_n_nodes_per_shaper_max = 0;
194 cap->shaper_shared_n_shapers_per_node_max = 0;
195 cap->shaper_shared_dual_rate_n_max = 0;
196 cap->shaper_shared_rate_min = 0;
197 cap->shaper_shared_rate_max = 0;
198 cap->sched_n_children_max = hw->func_caps.num_tx_qp;
200 * HW supports SP. But no plan to support it now.
201 * So, all the nodes should have the same priority.
203 cap->sched_sp_n_priorities_max = 1;
204 cap->sched_wfq_n_children_per_group_max = 0;
205 cap->sched_wfq_n_groups_max = 0;
207 * SW only supports fair round robin now.
208 * So, all the nodes should have the same weight.
210 cap->sched_wfq_weight_max = 1;
211 cap->cman_head_drop_supported = 0;
212 cap->dynamic_update_mask = 0;
213 cap->shaper_pkt_length_adjust_min = RTE_TM_ETH_FRAMING_OVERHEAD;
214 cap->shaper_pkt_length_adjust_max = RTE_TM_ETH_FRAMING_OVERHEAD_FCS;
215 cap->cman_wred_context_n_max = 0;
216 cap->cman_wred_context_private_n_max = 0;
217 cap->cman_wred_context_shared_n_max = 0;
218 cap->cman_wred_context_shared_n_nodes_per_context_max = 0;
219 cap->cman_wred_context_shared_n_contexts_per_node_max = 0;
225 static inline struct i40e_tm_shaper_profile *
226 i40e_shaper_profile_search(struct rte_eth_dev *dev,
227 uint32_t shaper_profile_id)
229 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
230 struct i40e_shaper_profile_list *shaper_profile_list =
231 &pf->tm_conf.shaper_profile_list;
232 struct i40e_tm_shaper_profile *shaper_profile;
234 TAILQ_FOREACH(shaper_profile, shaper_profile_list, node) {
235 if (shaper_profile_id == shaper_profile->shaper_profile_id)
236 return shaper_profile;
243 i40e_shaper_profile_param_check(struct rte_tm_shaper_params *profile,
244 struct rte_tm_error *error)
246 /* min rate not supported */
247 if (profile->committed.rate) {
248 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE;
249 error->message = "committed rate not supported";
252 /* min bucket size not supported */
253 if (profile->committed.size) {
254 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_SIZE;
255 error->message = "committed bucket size not supported";
258 /* max bucket size not supported */
259 if (profile->peak.size) {
260 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE;
261 error->message = "peak bucket size not supported";
264 /* length adjustment not supported */
265 if (profile->pkt_length_adjust) {
266 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PKT_ADJUST_LEN;
267 error->message = "packet length adjustment not supported";
275 i40e_shaper_profile_add(struct rte_eth_dev *dev,
276 uint32_t shaper_profile_id,
277 struct rte_tm_shaper_params *profile,
278 struct rte_tm_error *error)
280 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
281 struct i40e_tm_shaper_profile *shaper_profile;
284 if (!profile || !error)
287 ret = i40e_shaper_profile_param_check(profile, error);
291 shaper_profile = i40e_shaper_profile_search(dev, shaper_profile_id);
293 if (shaper_profile) {
294 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
295 error->message = "profile ID exist";
299 shaper_profile = rte_zmalloc("i40e_tm_shaper_profile",
300 sizeof(struct i40e_tm_shaper_profile),
304 shaper_profile->shaper_profile_id = shaper_profile_id;
305 rte_memcpy(&shaper_profile->profile, profile,
306 sizeof(struct rte_tm_shaper_params));
307 TAILQ_INSERT_TAIL(&pf->tm_conf.shaper_profile_list,
308 shaper_profile, node);
314 i40e_shaper_profile_del(struct rte_eth_dev *dev,
315 uint32_t shaper_profile_id,
316 struct rte_tm_error *error)
318 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
319 struct i40e_tm_shaper_profile *shaper_profile;
324 shaper_profile = i40e_shaper_profile_search(dev, shaper_profile_id);
326 if (!shaper_profile) {
327 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
328 error->message = "profile ID not exist";
332 /* don't delete a profile if it's used by one or several nodes */
333 if (shaper_profile->reference_count) {
334 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
335 error->message = "profile in use";
339 TAILQ_REMOVE(&pf->tm_conf.shaper_profile_list, shaper_profile, node);
340 rte_free(shaper_profile);
345 static inline struct i40e_tm_node *
346 i40e_tm_node_search(struct rte_eth_dev *dev,
347 uint32_t node_id, enum i40e_tm_node_type *node_type)
349 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
350 struct i40e_tm_node_list *queue_list = &pf->tm_conf.queue_list;
351 struct i40e_tm_node_list *tc_list = &pf->tm_conf.tc_list;
352 struct i40e_tm_node *tm_node;
354 if (pf->tm_conf.root && pf->tm_conf.root->id == node_id) {
355 *node_type = I40E_TM_NODE_TYPE_PORT;
356 return pf->tm_conf.root;
359 TAILQ_FOREACH(tm_node, tc_list, node) {
360 if (tm_node->id == node_id) {
361 *node_type = I40E_TM_NODE_TYPE_TC;
366 TAILQ_FOREACH(tm_node, queue_list, node) {
367 if (tm_node->id == node_id) {
368 *node_type = I40E_TM_NODE_TYPE_QUEUE;
377 i40e_node_param_check(uint32_t node_id, uint32_t parent_node_id,
378 uint32_t priority, uint32_t weight,
379 struct rte_tm_node_params *params,
380 struct rte_tm_error *error)
382 if (node_id == RTE_TM_NODE_ID_NULL) {
383 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
384 error->message = "invalid node id";
389 error->type = RTE_TM_ERROR_TYPE_NODE_PRIORITY;
390 error->message = "priority should be 0";
395 error->type = RTE_TM_ERROR_TYPE_NODE_WEIGHT;
396 error->message = "weight must be 1";
400 /* not support shared shaper */
401 if (params->shared_shaper_id) {
402 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID;
403 error->message = "shared shaper not supported";
406 if (params->n_shared_shapers) {
407 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS;
408 error->message = "shared shaper not supported";
413 if (parent_node_id == RTE_TM_NODE_ID_NULL) {
414 if (params->nonleaf.wfq_weight_mode) {
416 RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE;
417 error->message = "WFQ not supported";
420 if (params->nonleaf.n_sp_priorities != 1) {
422 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES;
423 error->message = "SP priority not supported";
425 } else if (params->nonleaf.wfq_weight_mode &&
426 !(*params->nonleaf.wfq_weight_mode)) {
428 RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE;
429 error->message = "WFP should be byte mode";
436 /* for TC or queue node */
437 if (params->leaf.cman) {
438 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN;
439 error->message = "Congestion management not supported";
442 if (params->leaf.wred.wred_profile_id !=
443 RTE_TM_WRED_PROFILE_ID_NONE) {
445 RTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID;
446 error->message = "WRED not supported";
449 if (params->leaf.wred.shared_wred_context_id) {
451 RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_WRED_CONTEXT_ID;
452 error->message = "WRED not supported";
455 if (params->leaf.wred.n_shared_wred_contexts) {
457 RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS;
458 error->message = "WRED not supported";
466 * Now the TC and queue configuration is controlled by DCB.
467 * We need check if the node configuration follows the DCB configuration.
468 * In the future, we may use TM to cover DCB.
471 i40e_node_add(struct rte_eth_dev *dev, uint32_t node_id,
472 uint32_t parent_node_id, uint32_t priority,
473 uint32_t weight, uint32_t level_id,
474 struct rte_tm_node_params *params,
475 struct rte_tm_error *error)
477 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
478 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
479 enum i40e_tm_node_type node_type = I40E_TM_NODE_TYPE_MAX;
480 enum i40e_tm_node_type parent_node_type = I40E_TM_NODE_TYPE_MAX;
481 struct i40e_tm_shaper_profile *shaper_profile;
482 struct i40e_tm_node *tm_node;
483 struct i40e_tm_node *parent_node;
487 if (!params || !error)
490 /* if already committed */
491 if (pf->tm_conf.committed) {
492 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
493 error->message = "already committed";
497 ret = i40e_node_param_check(node_id, parent_node_id, priority, weight,
502 /* check if the node ID is already used */
503 if (i40e_tm_node_search(dev, node_id, &node_type)) {
504 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
505 error->message = "node id already used";
509 /* check the shaper profile id */
510 shaper_profile = i40e_shaper_profile_search(dev,
511 params->shaper_profile_id);
512 if (!shaper_profile) {
513 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID;
514 error->message = "shaper profile not exist";
518 /* root node if not have a parent */
519 if (parent_node_id == RTE_TM_NODE_ID_NULL) {
521 if (level_id != RTE_TM_NODE_LEVEL_ID_ANY &&
522 level_id > I40E_TM_NODE_TYPE_PORT) {
523 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
524 error->message = "Wrong level";
528 /* obviously no more than one root */
529 if (pf->tm_conf.root) {
530 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
531 error->message = "already have a root";
535 /* add the root node */
536 tm_node = rte_zmalloc("i40e_tm_node",
537 sizeof(struct i40e_tm_node),
541 tm_node->id = node_id;
542 tm_node->priority = priority;
543 tm_node->weight = weight;
544 tm_node->reference_count = 0;
545 tm_node->parent = NULL;
546 tm_node->shaper_profile = shaper_profile;
547 rte_memcpy(&tm_node->params, params,
548 sizeof(struct rte_tm_node_params));
549 pf->tm_conf.root = tm_node;
551 /* increase the reference counter of the shaper profile */
552 shaper_profile->reference_count++;
557 /* TC or queue node */
558 /* check the parent node */
559 parent_node = i40e_tm_node_search(dev, parent_node_id,
562 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
563 error->message = "parent not exist";
566 if (parent_node_type != I40E_TM_NODE_TYPE_PORT &&
567 parent_node_type != I40E_TM_NODE_TYPE_TC) {
568 error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
569 error->message = "parent is not port or TC";
573 if (level_id != RTE_TM_NODE_LEVEL_ID_ANY &&
574 level_id != parent_node_type + 1) {
575 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
576 error->message = "Wrong level";
580 /* check the node number */
581 if (parent_node_type == I40E_TM_NODE_TYPE_PORT) {
582 /* check the TC number */
583 tc_nb = i40e_tc_nb_get(dev);
584 if (pf->tm_conf.nb_tc_node >= tc_nb) {
585 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
586 error->message = "too many TCs";
590 /* check the queue number */
591 if (pf->tm_conf.nb_queue_node >= hw->func_caps.num_tx_qp) {
592 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
593 error->message = "too many queues";
599 * For queue, the node id means queue id.
601 if (node_id >= hw->func_caps.num_tx_qp) {
602 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
603 error->message = "too large queue id";
608 /* add the TC or queue node */
609 tm_node = rte_zmalloc("i40e_tm_node",
610 sizeof(struct i40e_tm_node),
614 tm_node->id = node_id;
615 tm_node->priority = priority;
616 tm_node->weight = weight;
617 tm_node->reference_count = 0;
618 tm_node->parent = pf->tm_conf.root;
619 tm_node->shaper_profile = shaper_profile;
620 rte_memcpy(&tm_node->params, params,
621 sizeof(struct rte_tm_node_params));
622 if (parent_node_type == I40E_TM_NODE_TYPE_PORT) {
623 TAILQ_INSERT_TAIL(&pf->tm_conf.tc_list,
625 pf->tm_conf.nb_tc_node++;
627 TAILQ_INSERT_TAIL(&pf->tm_conf.queue_list,
629 pf->tm_conf.nb_queue_node++;
631 tm_node->parent->reference_count++;
633 /* increase the reference counter of the shaper profile */
634 shaper_profile->reference_count++;
640 i40e_node_delete(struct rte_eth_dev *dev, uint32_t node_id,
641 struct rte_tm_error *error)
643 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
644 enum i40e_tm_node_type node_type = I40E_TM_NODE_TYPE_MAX;
645 struct i40e_tm_node *tm_node;
650 /* if already committed */
651 if (pf->tm_conf.committed) {
652 error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
653 error->message = "already committed";
657 if (node_id == RTE_TM_NODE_ID_NULL) {
658 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
659 error->message = "invalid node id";
663 /* check if the node id exists */
664 tm_node = i40e_tm_node_search(dev, node_id, &node_type);
666 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
667 error->message = "no such node";
671 /* the node should have no child */
672 if (tm_node->reference_count) {
673 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
675 "cannot delete a node which has children";
680 if (node_type == I40E_TM_NODE_TYPE_PORT) {
681 tm_node->shaper_profile->reference_count--;
683 pf->tm_conf.root = NULL;
687 /* TC or queue node */
688 tm_node->shaper_profile->reference_count--;
689 tm_node->parent->reference_count--;
690 if (node_type == I40E_TM_NODE_TYPE_TC) {
691 TAILQ_REMOVE(&pf->tm_conf.tc_list, tm_node, node);
692 pf->tm_conf.nb_tc_node--;
694 TAILQ_REMOVE(&pf->tm_conf.queue_list, tm_node, node);
695 pf->tm_conf.nb_queue_node--;
703 i40e_node_type_get(struct rte_eth_dev *dev, uint32_t node_id,
704 int *is_leaf, struct rte_tm_error *error)
706 enum i40e_tm_node_type node_type = I40E_TM_NODE_TYPE_MAX;
707 struct i40e_tm_node *tm_node;
709 if (!is_leaf || !error)
712 if (node_id == RTE_TM_NODE_ID_NULL) {
713 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
714 error->message = "invalid node id";
718 /* check if the node id exists */
719 tm_node = i40e_tm_node_search(dev, node_id, &node_type);
721 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
722 error->message = "no such node";
726 if (node_type == I40E_TM_NODE_TYPE_QUEUE)
735 i40e_level_capabilities_get(struct rte_eth_dev *dev,
737 struct rte_tm_level_capabilities *cap,
738 struct rte_tm_error *error)
740 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
745 if (level_id >= I40E_TM_NODE_TYPE_MAX) {
746 error->type = RTE_TM_ERROR_TYPE_LEVEL_ID;
747 error->message = "too deep level";
752 if (level_id == I40E_TM_NODE_TYPE_PORT) {
753 cap->n_nodes_max = 1;
754 cap->n_nodes_nonleaf_max = 1;
755 cap->n_nodes_leaf_max = 0;
756 cap->non_leaf_nodes_identical = true;
757 cap->leaf_nodes_identical = true;
758 cap->nonleaf.shaper_private_supported = true;
759 cap->nonleaf.shaper_private_dual_rate_supported = false;
760 cap->nonleaf.shaper_private_rate_min = 0;
761 /* 40Gbps -> 5GBps */
762 cap->nonleaf.shaper_private_rate_max = 5000000000ull;
763 cap->nonleaf.shaper_shared_n_max = 0;
764 cap->nonleaf.sched_n_children_max = I40E_MAX_TRAFFIC_CLASS;
765 cap->nonleaf.sched_sp_n_priorities_max = 1;
766 cap->nonleaf.sched_wfq_n_children_per_group_max = 0;
767 cap->nonleaf.sched_wfq_n_groups_max = 0;
768 cap->nonleaf.sched_wfq_weight_max = 1;
769 cap->nonleaf.stats_mask = 0;
774 /* TC or queue node */
775 if (level_id == I40E_TM_NODE_TYPE_TC) {
777 cap->n_nodes_max = I40E_MAX_TRAFFIC_CLASS;
778 cap->n_nodes_nonleaf_max = I40E_MAX_TRAFFIC_CLASS;
779 cap->n_nodes_leaf_max = 0;
780 cap->non_leaf_nodes_identical = true;
783 cap->n_nodes_max = hw->func_caps.num_tx_qp;
784 cap->n_nodes_nonleaf_max = 0;
785 cap->n_nodes_leaf_max = hw->func_caps.num_tx_qp;
786 cap->non_leaf_nodes_identical = true;
788 cap->leaf_nodes_identical = true;
789 cap->leaf.shaper_private_supported = true;
790 cap->leaf.shaper_private_dual_rate_supported = false;
791 cap->leaf.shaper_private_rate_min = 0;
792 /* 40Gbps -> 5GBps */
793 cap->leaf.shaper_private_rate_max = 5000000000ull;
794 cap->leaf.shaper_shared_n_max = 0;
795 cap->leaf.cman_head_drop_supported = false;
796 cap->leaf.cman_wred_context_private_supported = true;
797 cap->leaf.cman_wred_context_shared_n_max = 0;
798 cap->leaf.stats_mask = 0;
804 i40e_node_capabilities_get(struct rte_eth_dev *dev,
806 struct rte_tm_node_capabilities *cap,
807 struct rte_tm_error *error)
809 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
810 enum i40e_tm_node_type node_type;
811 struct i40e_tm_node *tm_node;
816 if (node_id == RTE_TM_NODE_ID_NULL) {
817 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
818 error->message = "invalid node id";
822 /* check if the node id exists */
823 tm_node = i40e_tm_node_search(dev, node_id, &node_type);
825 error->type = RTE_TM_ERROR_TYPE_NODE_ID;
826 error->message = "no such node";
830 cap->shaper_private_supported = true;
831 cap->shaper_private_dual_rate_supported = false;
832 cap->shaper_private_rate_min = 0;
833 /* 40Gbps -> 5GBps */
834 cap->shaper_private_rate_max = 5000000000ull;
835 cap->shaper_shared_n_max = 0;
837 if (node_type == I40E_TM_NODE_TYPE_QUEUE) {
838 cap->leaf.cman_head_drop_supported = false;
839 cap->leaf.cman_wred_context_private_supported = true;
840 cap->leaf.cman_wred_context_shared_n_max = 0;
842 if (node_type == I40E_TM_NODE_TYPE_PORT)
843 cap->nonleaf.sched_n_children_max =
844 I40E_MAX_TRAFFIC_CLASS;
846 cap->nonleaf.sched_n_children_max =
847 hw->func_caps.num_tx_qp;
848 cap->nonleaf.sched_sp_n_priorities_max = 1;
849 cap->nonleaf.sched_wfq_n_children_per_group_max = 0;
850 cap->nonleaf.sched_wfq_n_groups_max = 0;
851 cap->nonleaf.sched_wfq_weight_max = 1;
860 i40e_hierarchy_commit(struct rte_eth_dev *dev,
862 struct rte_tm_error *error)
864 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
865 struct i40e_tm_node_list *tc_list = &pf->tm_conf.tc_list;
866 struct i40e_tm_node_list *queue_list = &pf->tm_conf.queue_list;
867 struct i40e_tm_node *tm_node;
868 struct i40e_vsi *vsi;
870 struct i40e_aqc_configure_vsi_ets_sla_bw_data tc_bw;
879 /* check the setting */
880 if (!pf->tm_conf.root)
884 hw = I40E_VSI_TO_HW(vsi);
887 * Don't support bandwidth control for port and TCs in parallel.
888 * If the port has a max bandwidth, the TCs should have none.
891 bw = pf->tm_conf.root->shaper_profile->profile.peak.rate;
893 /* check if any TC has a max bandwidth */
894 TAILQ_FOREACH(tm_node, tc_list, node) {
895 if (tm_node->shaper_profile->profile.peak.rate) {
896 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
897 error->message = "no port and TC max bandwidth"
903 /* interpret Bps to 50Mbps */
904 bw = bw * 8 / 1000 / 1000 / I40E_QOS_BW_GRANULARITY;
906 /* set the max bandwidth */
907 ret = i40e_aq_config_vsi_bw_limit(hw, vsi->seid,
908 (uint16_t)bw, 0, NULL);
910 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
911 error->message = "fail to set port max bandwidth";
919 memset(&tc_bw, 0, sizeof(tc_bw));
920 tc_bw.tc_valid_bits = vsi->enabled_tc;
921 tc_map = vsi->enabled_tc;
922 TAILQ_FOREACH(tm_node, tc_list, node) {
923 if (!tm_node->reference_count) {
924 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
925 error->message = "TC without queue assigned";
930 while (i < I40E_MAX_TRAFFIC_CLASS && !(tc_map & BIT_ULL(i)))
932 if (i >= I40E_MAX_TRAFFIC_CLASS) {
933 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
934 error->message = "cannot find the TC";
937 tc_map &= ~BIT_ULL(i);
939 bw = tm_node->shaper_profile->profile.peak.rate;
943 /* interpret Bps to 50Mbps */
944 bw = bw * 8 / 1000 / 1000 / I40E_QOS_BW_GRANULARITY;
946 tc_bw.tc_bw_credits[i] = rte_cpu_to_le_16((uint16_t)bw);
949 TAILQ_FOREACH(tm_node, queue_list, node) {
950 bw = tm_node->shaper_profile->profile.peak.rate;
952 error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
953 error->message = "not support queue QoS";
958 ret = i40e_aq_config_vsi_ets_sla_bw_limit(hw, vsi->seid, &tc_bw, NULL);
960 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
961 error->message = "fail to set TC max bandwidth";
966 pf->tm_conf.committed = true;
970 /* clear all the traffic manager configuration */
972 i40e_tm_conf_uninit(dev);
973 i40e_tm_conf_init(dev);