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);
49 const struct rte_tm_ops ixgbe_tm_ops = {
50 .capabilities_get = ixgbe_tm_capabilities_get,
51 .shaper_profile_add = ixgbe_shaper_profile_add,
52 .shaper_profile_delete = ixgbe_shaper_profile_del,
56 ixgbe_tm_ops_get(struct rte_eth_dev *dev __rte_unused,
62 *(const void **)arg = &ixgbe_tm_ops;
68 ixgbe_tm_conf_init(struct rte_eth_dev *dev)
70 struct ixgbe_tm_conf *tm_conf =
71 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
73 /* initialize shaper profile list */
74 TAILQ_INIT(&tm_conf->shaper_profile_list);
78 ixgbe_tm_conf_uninit(struct rte_eth_dev *dev)
80 struct ixgbe_tm_conf *tm_conf =
81 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
82 struct ixgbe_tm_shaper_profile *shaper_profile;
84 /* Remove all shaper profiles */
85 while ((shaper_profile =
86 TAILQ_FIRST(&tm_conf->shaper_profile_list))) {
87 TAILQ_REMOVE(&tm_conf->shaper_profile_list,
88 shaper_profile, node);
89 rte_free(shaper_profile);
94 ixgbe_tc_nb_get(struct rte_eth_dev *dev)
96 struct rte_eth_conf *eth_conf;
99 eth_conf = &dev->data->dev_conf;
100 if (eth_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
101 nb_tcs = eth_conf->tx_adv_conf.dcb_tx_conf.nb_tcs;
102 } else if (eth_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
103 if (eth_conf->tx_adv_conf.vmdq_dcb_tx_conf.nb_queue_pools ==
116 ixgbe_tm_capabilities_get(struct rte_eth_dev *dev,
117 struct rte_tm_capabilities *cap,
118 struct rte_tm_error *error)
120 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
121 uint8_t tc_nb = ixgbe_tc_nb_get(dev);
126 if (tc_nb > hw->mac.max_tx_queues)
129 error->type = RTE_TM_ERROR_TYPE_NONE;
131 /* set all the parameters to 0 first. */
132 memset(cap, 0, sizeof(struct rte_tm_capabilities));
135 * here is the max capability not the current configuration.
137 /* port + TCs + queues */
138 cap->n_nodes_max = 1 + IXGBE_DCB_MAX_TRAFFIC_CLASS +
139 hw->mac.max_tx_queues;
140 cap->n_levels_max = 3;
141 cap->non_leaf_nodes_identical = 1;
142 cap->leaf_nodes_identical = 1;
143 cap->shaper_n_max = cap->n_nodes_max;
144 cap->shaper_private_n_max = cap->n_nodes_max;
145 cap->shaper_private_dual_rate_n_max = 0;
146 cap->shaper_private_rate_min = 0;
147 /* 10Gbps -> 1.25GBps */
148 cap->shaper_private_rate_max = 1250000000ull;
149 cap->shaper_shared_n_max = 0;
150 cap->shaper_shared_n_nodes_per_shaper_max = 0;
151 cap->shaper_shared_n_shapers_per_node_max = 0;
152 cap->shaper_shared_dual_rate_n_max = 0;
153 cap->shaper_shared_rate_min = 0;
154 cap->shaper_shared_rate_max = 0;
155 cap->sched_n_children_max = hw->mac.max_tx_queues;
157 * HW supports SP. But no plan to support it now.
158 * So, all the nodes should have the same priority.
160 cap->sched_sp_n_priorities_max = 1;
161 cap->sched_wfq_n_children_per_group_max = 0;
162 cap->sched_wfq_n_groups_max = 0;
164 * SW only supports fair round robin now.
165 * So, all the nodes should have the same weight.
167 cap->sched_wfq_weight_max = 1;
168 cap->cman_head_drop_supported = 0;
169 cap->dynamic_update_mask = 0;
170 cap->shaper_pkt_length_adjust_min = RTE_TM_ETH_FRAMING_OVERHEAD;
171 cap->shaper_pkt_length_adjust_max = RTE_TM_ETH_FRAMING_OVERHEAD_FCS;
172 cap->cman_wred_context_n_max = 0;
173 cap->cman_wred_context_private_n_max = 0;
174 cap->cman_wred_context_shared_n_max = 0;
175 cap->cman_wred_context_shared_n_nodes_per_context_max = 0;
176 cap->cman_wred_context_shared_n_contexts_per_node_max = 0;
182 static inline struct ixgbe_tm_shaper_profile *
183 ixgbe_shaper_profile_search(struct rte_eth_dev *dev,
184 uint32_t shaper_profile_id)
186 struct ixgbe_tm_conf *tm_conf =
187 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
188 struct ixgbe_shaper_profile_list *shaper_profile_list =
189 &tm_conf->shaper_profile_list;
190 struct ixgbe_tm_shaper_profile *shaper_profile;
192 TAILQ_FOREACH(shaper_profile, shaper_profile_list, node) {
193 if (shaper_profile_id == shaper_profile->shaper_profile_id)
194 return shaper_profile;
201 ixgbe_shaper_profile_param_check(struct rte_tm_shaper_params *profile,
202 struct rte_tm_error *error)
204 /* min rate not supported */
205 if (profile->committed.rate) {
206 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE;
207 error->message = "committed rate not supported";
210 /* min bucket size not supported */
211 if (profile->committed.size) {
212 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_SIZE;
213 error->message = "committed bucket size not supported";
216 /* max bucket size not supported */
217 if (profile->peak.size) {
218 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE;
219 error->message = "peak bucket size not supported";
222 /* length adjustment not supported */
223 if (profile->pkt_length_adjust) {
224 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PKT_ADJUST_LEN;
225 error->message = "packet length adjustment not supported";
233 ixgbe_shaper_profile_add(struct rte_eth_dev *dev,
234 uint32_t shaper_profile_id,
235 struct rte_tm_shaper_params *profile,
236 struct rte_tm_error *error)
238 struct ixgbe_tm_conf *tm_conf =
239 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
240 struct ixgbe_tm_shaper_profile *shaper_profile;
243 if (!profile || !error)
246 ret = ixgbe_shaper_profile_param_check(profile, error);
250 shaper_profile = ixgbe_shaper_profile_search(dev, shaper_profile_id);
252 if (shaper_profile) {
253 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
254 error->message = "profile ID exist";
258 shaper_profile = rte_zmalloc("ixgbe_tm_shaper_profile",
259 sizeof(struct ixgbe_tm_shaper_profile),
263 shaper_profile->shaper_profile_id = shaper_profile_id;
264 (void)rte_memcpy(&shaper_profile->profile, profile,
265 sizeof(struct rte_tm_shaper_params));
266 TAILQ_INSERT_TAIL(&tm_conf->shaper_profile_list,
267 shaper_profile, node);
273 ixgbe_shaper_profile_del(struct rte_eth_dev *dev,
274 uint32_t shaper_profile_id,
275 struct rte_tm_error *error)
277 struct ixgbe_tm_conf *tm_conf =
278 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
279 struct ixgbe_tm_shaper_profile *shaper_profile;
284 shaper_profile = ixgbe_shaper_profile_search(dev, shaper_profile_id);
286 if (!shaper_profile) {
287 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
288 error->message = "profile ID not exist";
292 /* don't delete a profile if it's used by one or several nodes */
293 if (shaper_profile->reference_count) {
294 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
295 error->message = "profile in use";
299 TAILQ_REMOVE(&tm_conf->shaper_profile_list, shaper_profile, node);
300 rte_free(shaper_profile);