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);
50 const struct rte_tm_ops i40e_tm_ops = {
51 .capabilities_get = i40e_tm_capabilities_get,
52 .shaper_profile_add = i40e_shaper_profile_add,
53 .shaper_profile_delete = i40e_shaper_profile_del,
57 i40e_tm_ops_get(struct rte_eth_dev *dev __rte_unused,
63 *(const void **)arg = &i40e_tm_ops;
69 i40e_tm_conf_init(struct rte_eth_dev *dev)
71 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
73 /* initialize shaper profile list */
74 TAILQ_INIT(&pf->tm_conf.shaper_profile_list);
78 i40e_tm_conf_uninit(struct rte_eth_dev *dev)
80 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
81 struct i40e_tm_shaper_profile *shaper_profile;
83 /* Remove all shaper profiles */
84 while ((shaper_profile =
85 TAILQ_FIRST(&pf->tm_conf.shaper_profile_list))) {
86 TAILQ_REMOVE(&pf->tm_conf.shaper_profile_list,
87 shaper_profile, node);
88 rte_free(shaper_profile);
92 static inline uint16_t
93 i40e_tc_nb_get(struct rte_eth_dev *dev)
95 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
96 struct i40e_vsi *main_vsi = pf->main_vsi;
100 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
101 if (main_vsi->enabled_tc & BIT_ULL(i))
109 i40e_tm_capabilities_get(struct rte_eth_dev *dev,
110 struct rte_tm_capabilities *cap,
111 struct rte_tm_error *error)
113 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
114 uint16_t tc_nb = i40e_tc_nb_get(dev);
119 if (tc_nb > hw->func_caps.num_tx_qp)
122 error->type = RTE_TM_ERROR_TYPE_NONE;
124 /* set all the parameters to 0 first. */
125 memset(cap, 0, sizeof(struct rte_tm_capabilities));
128 * support port + TCs + queues
129 * here shows the max capability not the current configuration.
131 cap->n_nodes_max = 1 + I40E_MAX_TRAFFIC_CLASS + hw->func_caps.num_tx_qp;
132 cap->n_levels_max = 3; /* port, TC, queue */
133 cap->non_leaf_nodes_identical = 1;
134 cap->leaf_nodes_identical = 1;
135 cap->shaper_n_max = cap->n_nodes_max;
136 cap->shaper_private_n_max = cap->n_nodes_max;
137 cap->shaper_private_dual_rate_n_max = 0;
138 cap->shaper_private_rate_min = 0;
139 /* 40Gbps -> 5GBps */
140 cap->shaper_private_rate_max = 5000000000ull;
141 cap->shaper_shared_n_max = 0;
142 cap->shaper_shared_n_nodes_per_shaper_max = 0;
143 cap->shaper_shared_n_shapers_per_node_max = 0;
144 cap->shaper_shared_dual_rate_n_max = 0;
145 cap->shaper_shared_rate_min = 0;
146 cap->shaper_shared_rate_max = 0;
147 cap->sched_n_children_max = hw->func_caps.num_tx_qp;
149 * HW supports SP. But no plan to support it now.
150 * So, all the nodes should have the same priority.
152 cap->sched_sp_n_priorities_max = 1;
153 cap->sched_wfq_n_children_per_group_max = 0;
154 cap->sched_wfq_n_groups_max = 0;
156 * SW only supports fair round robin now.
157 * So, all the nodes should have the same weight.
159 cap->sched_wfq_weight_max = 1;
160 cap->cman_head_drop_supported = 0;
161 cap->dynamic_update_mask = 0;
162 cap->shaper_pkt_length_adjust_min = RTE_TM_ETH_FRAMING_OVERHEAD;
163 cap->shaper_pkt_length_adjust_max = RTE_TM_ETH_FRAMING_OVERHEAD_FCS;
164 cap->cman_wred_context_n_max = 0;
165 cap->cman_wred_context_private_n_max = 0;
166 cap->cman_wred_context_shared_n_max = 0;
167 cap->cman_wred_context_shared_n_nodes_per_context_max = 0;
168 cap->cman_wred_context_shared_n_contexts_per_node_max = 0;
174 static inline struct i40e_tm_shaper_profile *
175 i40e_shaper_profile_search(struct rte_eth_dev *dev,
176 uint32_t shaper_profile_id)
178 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
179 struct i40e_shaper_profile_list *shaper_profile_list =
180 &pf->tm_conf.shaper_profile_list;
181 struct i40e_tm_shaper_profile *shaper_profile;
183 TAILQ_FOREACH(shaper_profile, shaper_profile_list, node) {
184 if (shaper_profile_id == shaper_profile->shaper_profile_id)
185 return shaper_profile;
192 i40e_shaper_profile_param_check(struct rte_tm_shaper_params *profile,
193 struct rte_tm_error *error)
195 /* min rate not supported */
196 if (profile->committed.rate) {
197 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE;
198 error->message = "committed rate not supported";
201 /* min bucket size not supported */
202 if (profile->committed.size) {
203 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_SIZE;
204 error->message = "committed bucket size not supported";
207 /* max bucket size not supported */
208 if (profile->peak.size) {
209 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE;
210 error->message = "peak bucket size not supported";
213 /* length adjustment not supported */
214 if (profile->pkt_length_adjust) {
215 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PKT_ADJUST_LEN;
216 error->message = "packet length adjustment not supported";
224 i40e_shaper_profile_add(struct rte_eth_dev *dev,
225 uint32_t shaper_profile_id,
226 struct rte_tm_shaper_params *profile,
227 struct rte_tm_error *error)
229 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
230 struct i40e_tm_shaper_profile *shaper_profile;
233 if (!profile || !error)
236 ret = i40e_shaper_profile_param_check(profile, error);
240 shaper_profile = i40e_shaper_profile_search(dev, shaper_profile_id);
242 if (shaper_profile) {
243 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
244 error->message = "profile ID exist";
248 shaper_profile = rte_zmalloc("i40e_tm_shaper_profile",
249 sizeof(struct i40e_tm_shaper_profile),
253 shaper_profile->shaper_profile_id = shaper_profile_id;
254 (void)rte_memcpy(&shaper_profile->profile, profile,
255 sizeof(struct rte_tm_shaper_params));
256 TAILQ_INSERT_TAIL(&pf->tm_conf.shaper_profile_list,
257 shaper_profile, node);
263 i40e_shaper_profile_del(struct rte_eth_dev *dev,
264 uint32_t shaper_profile_id,
265 struct rte_tm_error *error)
267 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
268 struct i40e_tm_shaper_profile *shaper_profile;
273 shaper_profile = i40e_shaper_profile_search(dev, shaper_profile_id);
275 if (!shaper_profile) {
276 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
277 error->message = "profile ID not exist";
281 /* don't delete a profile if it's used by one or several nodes */
282 if (shaper_profile->reference_count) {
283 error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
284 error->message = "profile in use";
288 TAILQ_REMOVE(&pf->tm_conf.shaper_profile_list, shaper_profile, node);
289 rte_free(shaper_profile);