Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2017 Intel Corporation
3 : : */
4 : : #include <stdlib.h>
5 : :
6 : : #include <rte_tm_driver.h>
7 : :
8 : : #include "iavf.h"
9 : :
10 : : static int iavf_hierarchy_commit(struct rte_eth_dev *dev,
11 : : __rte_unused int clear_on_fail,
12 : : __rte_unused struct rte_tm_error *error);
13 : : static int iavf_shaper_profile_add(struct rte_eth_dev *dev,
14 : : uint32_t shaper_profile_id,
15 : : const struct rte_tm_shaper_params *profile,
16 : : struct rte_tm_error *error);
17 : : static int iavf_shaper_profile_del(struct rte_eth_dev *dev,
18 : : uint32_t shaper_profile_id,
19 : : struct rte_tm_error *error);
20 : : static int iavf_tm_node_add(struct rte_eth_dev *dev, uint32_t node_id,
21 : : uint32_t parent_node_id, uint32_t priority,
22 : : uint32_t weight, uint32_t level_id,
23 : : const struct rte_tm_node_params *params,
24 : : struct rte_tm_error *error);
25 : : static int iavf_tm_node_delete(struct rte_eth_dev *dev, uint32_t node_id,
26 : : struct rte_tm_error *error);
27 : : static int iavf_tm_capabilities_get(struct rte_eth_dev *dev,
28 : : struct rte_tm_capabilities *cap,
29 : : struct rte_tm_error *error);
30 : : static int iavf_level_capabilities_get(struct rte_eth_dev *dev,
31 : : uint32_t level_id,
32 : : struct rte_tm_level_capabilities *cap,
33 : : struct rte_tm_error *error);
34 : : static int iavf_node_capabilities_get(struct rte_eth_dev *dev,
35 : : uint32_t node_id,
36 : : struct rte_tm_node_capabilities *cap,
37 : : struct rte_tm_error *error);
38 : : static int iavf_node_type_get(struct rte_eth_dev *dev, uint32_t node_id,
39 : : int *is_leaf, struct rte_tm_error *error);
40 : :
41 : : const struct rte_tm_ops iavf_tm_ops = {
42 : : .shaper_profile_add = iavf_shaper_profile_add,
43 : : .shaper_profile_delete = iavf_shaper_profile_del,
44 : : .node_add = iavf_tm_node_add,
45 : : .node_delete = iavf_tm_node_delete,
46 : : .capabilities_get = iavf_tm_capabilities_get,
47 : : .level_capabilities_get = iavf_level_capabilities_get,
48 : : .node_capabilities_get = iavf_node_capabilities_get,
49 : : .node_type_get = iavf_node_type_get,
50 : : .hierarchy_commit = iavf_hierarchy_commit,
51 : : };
52 : :
53 : : void
54 : 0 : iavf_tm_conf_init(struct rte_eth_dev *dev)
55 : : {
56 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
57 : :
58 : : /* initialize shaper profile list */
59 : 0 : TAILQ_INIT(&vf->tm_conf.shaper_profile_list);
60 : :
61 : : /* initialize node configuration */
62 : 0 : vf->tm_conf.root = NULL;
63 : 0 : TAILQ_INIT(&vf->tm_conf.tc_list);
64 : 0 : TAILQ_INIT(&vf->tm_conf.queue_list);
65 : 0 : vf->tm_conf.nb_tc_node = 0;
66 : 0 : vf->tm_conf.nb_queue_node = 0;
67 : 0 : vf->tm_conf.committed = false;
68 : 0 : }
69 : :
70 : : void
71 : 0 : iavf_tm_conf_uninit(struct rte_eth_dev *dev)
72 : : {
73 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
74 : : struct iavf_tm_shaper_profile *shaper_profile;
75 : : struct iavf_tm_node *tm_node;
76 : :
77 : : /* clear node configuration */
78 [ # # ]: 0 : while ((tm_node = TAILQ_FIRST(&vf->tm_conf.queue_list))) {
79 [ # # ]: 0 : TAILQ_REMOVE(&vf->tm_conf.queue_list, tm_node, node);
80 : 0 : rte_free(tm_node);
81 : : }
82 : 0 : vf->tm_conf.nb_queue_node = 0;
83 [ # # ]: 0 : while ((tm_node = TAILQ_FIRST(&vf->tm_conf.tc_list))) {
84 [ # # ]: 0 : TAILQ_REMOVE(&vf->tm_conf.tc_list, tm_node, node);
85 : 0 : rte_free(tm_node);
86 : : }
87 : 0 : vf->tm_conf.nb_tc_node = 0;
88 [ # # ]: 0 : if (vf->tm_conf.root) {
89 : 0 : rte_free(vf->tm_conf.root);
90 : 0 : vf->tm_conf.root = NULL;
91 : : }
92 : :
93 : : /* Remove all shaper profiles */
94 [ # # ]: 0 : while ((shaper_profile =
95 : : TAILQ_FIRST(&vf->tm_conf.shaper_profile_list))) {
96 [ # # ]: 0 : TAILQ_REMOVE(&vf->tm_conf.shaper_profile_list,
97 : : shaper_profile, node);
98 : 0 : rte_free(shaper_profile);
99 : : }
100 : :
101 : 0 : free(vf->qtc_map);
102 : 0 : vf->qtc_map = NULL;
103 : 0 : }
104 : :
105 : : /* qos_cap and the TM lists exist only if the PF grants VIRTCHNL_VF_OFFLOAD_QOS. */
106 : : static int
107 : : iavf_tm_qos_check(struct iavf_info *vf, struct rte_tm_error *error)
108 : : {
109 [ # # # # : 0 : if (vf->qos_cap != NULL)
# # # # ]
110 : : return 0;
111 : :
112 : 0 : error->type = RTE_TM_ERROR_TYPE_CAPABILITIES;
113 : 0 : error->message = "VF has no QoS capability";
114 : : return -ENOTSUP;
115 : : }
116 : :
117 : : static inline struct iavf_tm_node *
118 : 0 : iavf_tm_node_search(struct rte_eth_dev *dev,
119 : : uint32_t node_id, enum iavf_tm_node_type *node_type)
120 : : {
121 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
122 : : struct iavf_tm_node_list *tc_list = &vf->tm_conf.tc_list;
123 : : struct iavf_tm_node_list *queue_list = &vf->tm_conf.queue_list;
124 : : struct iavf_tm_node *tm_node;
125 : :
126 [ # # # # ]: 0 : if (vf->tm_conf.root && vf->tm_conf.root->id == node_id) {
127 : 0 : *node_type = IAVF_TM_NODE_TYPE_PORT;
128 : 0 : return vf->tm_conf.root;
129 : : }
130 : :
131 [ # # ]: 0 : TAILQ_FOREACH(tm_node, tc_list, node) {
132 [ # # ]: 0 : if (tm_node->id == node_id) {
133 : 0 : *node_type = IAVF_TM_NODE_TYPE_TC;
134 : 0 : return tm_node;
135 : : }
136 : : }
137 : :
138 [ # # ]: 0 : TAILQ_FOREACH(tm_node, queue_list, node) {
139 [ # # ]: 0 : if (tm_node->id == node_id) {
140 : 0 : *node_type = IAVF_TM_NODE_TYPE_QUEUE;
141 : 0 : return tm_node;
142 : : }
143 : : }
144 : :
145 : : return NULL;
146 : : }
147 : :
148 : : static int
149 : 0 : iavf_node_param_check(struct iavf_info *vf, uint32_t node_id,
150 : : uint32_t priority, uint32_t weight,
151 : : const struct rte_tm_node_params *params,
152 : : struct rte_tm_error *error)
153 : : {
154 : : /* checked all the unsupported parameter */
155 [ # # ]: 0 : if (node_id == RTE_TM_NODE_ID_NULL) {
156 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_ID;
157 : 0 : error->message = "invalid node id";
158 : 0 : return -EINVAL;
159 : : }
160 : :
161 [ # # ]: 0 : if (priority) {
162 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_PRIORITY;
163 : 0 : error->message = "priority should be 0";
164 : 0 : return -EINVAL;
165 : : }
166 : :
167 [ # # ]: 0 : if (weight != 1) {
168 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_WEIGHT;
169 : 0 : error->message = "weight must be 1";
170 : 0 : return -EINVAL;
171 : : }
172 : :
173 : : /* not support shared shaper */
174 [ # # ]: 0 : if (params->shared_shaper_id) {
175 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID;
176 : 0 : error->message = "shared shaper not supported";
177 : 0 : return -EINVAL;
178 : : }
179 [ # # ]: 0 : if (params->n_shared_shapers) {
180 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS;
181 : 0 : error->message = "shared shaper not supported";
182 : 0 : return -EINVAL;
183 : : }
184 : :
185 : : /* for non-leaf node */
186 [ # # ]: 0 : if (node_id >= vf->num_queue_pairs) {
187 [ # # ]: 0 : if (params->nonleaf.wfq_weight_mode) {
188 : 0 : error->type =
189 : : RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE;
190 : 0 : error->message = "WFQ not supported";
191 : 0 : return -EINVAL;
192 : : }
193 [ # # ]: 0 : if (params->nonleaf.n_sp_priorities != 1) {
194 : 0 : error->type =
195 : : RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES;
196 : 0 : error->message = "SP priority not supported";
197 : 0 : return -EINVAL;
198 : : }
199 : :
200 : : return 0;
201 : : }
202 : :
203 : : /* for leaf node */
204 [ # # ]: 0 : if (params->leaf.cman) {
205 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN;
206 : 0 : error->message = "Congestion management not supported";
207 : 0 : return -EINVAL;
208 : : }
209 [ # # ]: 0 : if (params->leaf.wred.wred_profile_id !=
210 : : RTE_TM_WRED_PROFILE_ID_NONE) {
211 : 0 : error->type =
212 : : RTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID;
213 : 0 : error->message = "WRED not supported";
214 : 0 : return -EINVAL;
215 : : }
216 [ # # ]: 0 : if (params->leaf.wred.shared_wred_context_id) {
217 : 0 : error->type =
218 : : RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_WRED_CONTEXT_ID;
219 : 0 : error->message = "WRED not supported";
220 : 0 : return -EINVAL;
221 : : }
222 [ # # ]: 0 : if (params->leaf.wred.n_shared_wred_contexts) {
223 : 0 : error->type =
224 : : RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS;
225 : 0 : error->message = "WRED not supported";
226 : 0 : return -EINVAL;
227 : : }
228 : :
229 : : return 0;
230 : : }
231 : :
232 : : static int
233 : 0 : iavf_node_type_get(struct rte_eth_dev *dev, uint32_t node_id,
234 : : int *is_leaf, struct rte_tm_error *error)
235 : : {
236 : 0 : enum iavf_tm_node_type node_type = IAVF_TM_NODE_TYPE_MAX;
237 : : struct iavf_tm_node *tm_node;
238 : :
239 [ # # ]: 0 : if (!is_leaf || !error)
240 : : return -EINVAL;
241 : :
242 [ # # ]: 0 : if (node_id == RTE_TM_NODE_ID_NULL) {
243 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_ID;
244 : 0 : error->message = "invalid node id";
245 : 0 : return -EINVAL;
246 : : }
247 : :
248 : : /* check if the node id exists */
249 : 0 : tm_node = iavf_tm_node_search(dev, node_id, &node_type);
250 [ # # ]: 0 : if (!tm_node) {
251 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_ID;
252 : 0 : error->message = "no such node";
253 : 0 : return -EINVAL;
254 : : }
255 : :
256 [ # # ]: 0 : if (node_type == IAVF_TM_NODE_TYPE_QUEUE)
257 : 0 : *is_leaf = true;
258 : : else
259 : 0 : *is_leaf = false;
260 : :
261 : : return 0;
262 : : }
263 : :
264 : : static inline struct iavf_tm_shaper_profile *
265 : : iavf_shaper_profile_search(struct rte_eth_dev *dev,
266 : : uint32_t shaper_profile_id)
267 : : {
268 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
269 : : struct iavf_shaper_profile_list *shaper_profile_list =
270 : : &vf->tm_conf.shaper_profile_list;
271 : : struct iavf_tm_shaper_profile *shaper_profile;
272 : :
273 [ # # # # : 0 : TAILQ_FOREACH(shaper_profile, shaper_profile_list, node) {
# # ]
274 [ # # # # : 0 : if (shaper_profile_id == shaper_profile->shaper_profile_id)
# # ]
275 : : return shaper_profile;
276 : : }
277 : :
278 : : return NULL;
279 : : }
280 : :
281 : : static int
282 : 0 : iavf_tm_node_add(struct rte_eth_dev *dev, uint32_t node_id,
283 : : uint32_t parent_node_id, uint32_t priority,
284 : : uint32_t weight, uint32_t level_id,
285 : : const struct rte_tm_node_params *params,
286 : : struct rte_tm_error *error)
287 : : {
288 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
289 : 0 : enum iavf_tm_node_type node_type = IAVF_TM_NODE_TYPE_MAX;
290 : 0 : enum iavf_tm_node_type parent_node_type = IAVF_TM_NODE_TYPE_MAX;
291 : : struct iavf_tm_shaper_profile *shaper_profile = NULL;
292 : : struct iavf_tm_node *tm_node;
293 : : struct iavf_tm_node *parent_node;
294 : : uint16_t tc_nb;
295 : : int ret;
296 : :
297 [ # # ]: 0 : if (!params || !error)
298 : : return -EINVAL;
299 : :
300 : : ret = iavf_tm_qos_check(vf, error);
301 : : if (ret)
302 : 0 : return ret;
303 : :
304 : 0 : tc_nb = vf->qos_cap->num_elem;
305 : :
306 : : /* if already committed */
307 [ # # ]: 0 : if (vf->tm_conf.committed) {
308 : 0 : error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
309 : 0 : error->message = "already committed";
310 : 0 : return -EINVAL;
311 : : }
312 : :
313 : 0 : ret = iavf_node_param_check(vf, node_id, priority, weight,
314 : : params, error);
315 [ # # ]: 0 : if (ret)
316 : : return ret;
317 : :
318 : : /* check if the node is already existed */
319 [ # # ]: 0 : if (iavf_tm_node_search(dev, node_id, &node_type)) {
320 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_ID;
321 : 0 : error->message = "node id already used";
322 : 0 : return -EINVAL;
323 : : }
324 : :
325 : : /* check the shaper profile id */
326 [ # # ]: 0 : if (params->shaper_profile_id != RTE_TM_SHAPER_PROFILE_ID_NONE) {
327 : : shaper_profile = iavf_shaper_profile_search(dev,
328 : : params->shaper_profile_id);
329 [ # # ]: 0 : if (!shaper_profile) {
330 : 0 : error->type =
331 : : RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID;
332 : 0 : error->message = "shaper profile not exist";
333 : 0 : return -EINVAL;
334 : : }
335 : : }
336 : :
337 : : /* root node if not have a parent */
338 [ # # ]: 0 : if (parent_node_id == RTE_TM_NODE_ID_NULL) {
339 : : /* check level */
340 [ # # ]: 0 : if (level_id != IAVF_TM_NODE_TYPE_PORT) {
341 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
342 : 0 : error->message = "Wrong level";
343 : 0 : return -EINVAL;
344 : : }
345 : :
346 : : /* obviously no more than one root */
347 [ # # ]: 0 : if (vf->tm_conf.root) {
348 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
349 : 0 : error->message = "already have a root";
350 : 0 : return -EINVAL;
351 : : }
352 : :
353 : : /* add the root node */
354 : 0 : tm_node = rte_zmalloc("iavf_tm_node",
355 : : sizeof(struct iavf_tm_node),
356 : : 0);
357 [ # # ]: 0 : if (!tm_node)
358 : : return -ENOMEM;
359 : 0 : tm_node->id = node_id;
360 : 0 : tm_node->parent = NULL;
361 : 0 : tm_node->reference_count = 0;
362 : 0 : memcpy(&tm_node->params, params,
363 : : sizeof(struct rte_tm_node_params));
364 : 0 : vf->tm_conf.root = tm_node;
365 : 0 : return 0;
366 : : }
367 : :
368 : : /* TC or queue node */
369 : : /* check the parent node */
370 : 0 : parent_node = iavf_tm_node_search(dev, parent_node_id,
371 : : &parent_node_type);
372 [ # # ]: 0 : if (!parent_node) {
373 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
374 : 0 : error->message = "parent not exist";
375 : 0 : return -EINVAL;
376 : : }
377 [ # # ]: 0 : if (parent_node_type != IAVF_TM_NODE_TYPE_PORT &&
378 : : parent_node_type != IAVF_TM_NODE_TYPE_TC) {
379 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
380 : 0 : error->message = "parent is not root or TC";
381 : 0 : return -EINVAL;
382 : : }
383 : : /* check level */
384 [ # # ]: 0 : if (level_id != RTE_TM_NODE_LEVEL_ID_ANY &&
385 [ # # ]: 0 : level_id != (uint32_t)parent_node_type + 1) {
386 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
387 : 0 : error->message = "Wrong level";
388 : 0 : return -EINVAL;
389 : : }
390 : :
391 : : /* check the node number */
392 [ # # ]: 0 : if (parent_node_type == IAVF_TM_NODE_TYPE_PORT) {
393 : : /* check the TC number */
394 [ # # ]: 0 : if (vf->tm_conf.nb_tc_node >= tc_nb) {
395 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_ID;
396 : 0 : error->message = "too many TCs";
397 : 0 : return -EINVAL;
398 : : }
399 : : } else {
400 : : /* check the queue number */
401 [ # # ]: 0 : if (parent_node->reference_count >= vf->num_queue_pairs) {
402 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_ID;
403 : 0 : error->message = "too many queues";
404 : 0 : return -EINVAL;
405 : : }
406 [ # # ]: 0 : if (node_id >= vf->num_queue_pairs) {
407 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_ID;
408 : 0 : error->message = "too large queue id";
409 : 0 : return -EINVAL;
410 : : }
411 : : }
412 : :
413 : : /* add the TC or queue node */
414 : 0 : tm_node = rte_zmalloc("iavf_tm_node",
415 : : sizeof(struct iavf_tm_node),
416 : : 0);
417 [ # # ]: 0 : if (!tm_node)
418 : : return -ENOMEM;
419 : 0 : tm_node->id = node_id;
420 : 0 : tm_node->reference_count = 0;
421 : 0 : tm_node->parent = parent_node;
422 : 0 : tm_node->shaper_profile = shaper_profile;
423 [ # # ]: 0 : memcpy(&tm_node->params, params,
424 : : sizeof(struct rte_tm_node_params));
425 [ # # ]: 0 : if (parent_node_type == IAVF_TM_NODE_TYPE_PORT) {
426 : 0 : TAILQ_INSERT_TAIL(&vf->tm_conf.tc_list,
427 : : tm_node, node);
428 : 0 : tm_node->tc = vf->tm_conf.nb_tc_node;
429 : 0 : vf->tm_conf.nb_tc_node++;
430 : : } else {
431 : 0 : TAILQ_INSERT_TAIL(&vf->tm_conf.queue_list,
432 : : tm_node, node);
433 : 0 : tm_node->tc = parent_node->tc;
434 : 0 : vf->tm_conf.nb_queue_node++;
435 : : }
436 : 0 : tm_node->parent->reference_count++;
437 : :
438 : : /* increase the reference counter of the shaper profile */
439 [ # # ]: 0 : if (shaper_profile)
440 : 0 : shaper_profile->reference_count++;
441 : :
442 : : return 0;
443 : : }
444 : :
445 : : static int
446 : 0 : iavf_tm_node_delete(struct rte_eth_dev *dev, uint32_t node_id,
447 : : struct rte_tm_error *error)
448 : : {
449 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
450 : 0 : enum iavf_tm_node_type node_type = IAVF_TM_NODE_TYPE_MAX;
451 : : struct iavf_tm_node *tm_node;
452 : :
453 [ # # ]: 0 : if (!error)
454 : : return -EINVAL;
455 : :
456 : : /* if already committed */
457 [ # # ]: 0 : if (vf->tm_conf.committed) {
458 : 0 : error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED;
459 : 0 : error->message = "already committed";
460 : 0 : return -EINVAL;
461 : : }
462 : :
463 [ # # ]: 0 : if (node_id == RTE_TM_NODE_ID_NULL) {
464 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_ID;
465 : 0 : error->message = "invalid node id";
466 : 0 : return -EINVAL;
467 : : }
468 : :
469 : : /* check if the node id exists */
470 : 0 : tm_node = iavf_tm_node_search(dev, node_id, &node_type);
471 [ # # ]: 0 : if (!tm_node) {
472 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_ID;
473 : 0 : error->message = "no such node";
474 : 0 : return -EINVAL;
475 : : }
476 : :
477 : : /* the node should have no child */
478 [ # # ]: 0 : if (tm_node->reference_count) {
479 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_ID;
480 : 0 : error->message =
481 : : "cannot delete a node which has children";
482 : 0 : return -EINVAL;
483 : : }
484 : :
485 : : /* root node */
486 [ # # ]: 0 : if (node_type == IAVF_TM_NODE_TYPE_PORT) {
487 : 0 : rte_free(tm_node);
488 : 0 : vf->tm_conf.root = NULL;
489 : 0 : return 0;
490 : : }
491 : :
492 : : /* TC or queue node */
493 : 0 : tm_node->parent->reference_count--;
494 [ # # ]: 0 : if (node_type == IAVF_TM_NODE_TYPE_TC) {
495 [ # # ]: 0 : TAILQ_REMOVE(&vf->tm_conf.tc_list, tm_node, node);
496 : 0 : vf->tm_conf.nb_tc_node--;
497 : : } else {
498 [ # # ]: 0 : TAILQ_REMOVE(&vf->tm_conf.queue_list, tm_node, node);
499 : 0 : vf->tm_conf.nb_queue_node--;
500 : : }
501 : 0 : rte_free(tm_node);
502 : :
503 : 0 : return 0;
504 : : }
505 : :
506 : : static int
507 : : iavf_shaper_profile_param_check(const struct rte_tm_shaper_params *profile,
508 : : struct rte_tm_error *error)
509 : : {
510 : : /* min bucket size not supported */
511 [ # # ]: 0 : if (profile->committed.size) {
512 : 0 : error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_SIZE;
513 : 0 : error->message = "committed bucket size not supported";
514 : : return -EINVAL;
515 : : }
516 : : /* max bucket size not supported */
517 [ # # ]: 0 : if (profile->peak.size) {
518 : 0 : error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE;
519 : 0 : error->message = "peak bucket size not supported";
520 : : return -EINVAL;
521 : : }
522 : : /* length adjustment not supported */
523 [ # # ]: 0 : if (profile->pkt_length_adjust) {
524 : 0 : error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PKT_ADJUST_LEN;
525 : 0 : error->message = "packet length adjustment not supported";
526 : : return -EINVAL;
527 : : }
528 : :
529 : : return 0;
530 : : }
531 : :
532 : : static int
533 : 0 : iavf_shaper_profile_add(struct rte_eth_dev *dev,
534 : : uint32_t shaper_profile_id,
535 : : const struct rte_tm_shaper_params *profile,
536 : : struct rte_tm_error *error)
537 : : {
538 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
539 : : struct iavf_tm_shaper_profile *shaper_profile;
540 : : int ret;
541 : :
542 [ # # ]: 0 : if (!profile || !error)
543 : : return -EINVAL;
544 : :
545 : : ret = iavf_tm_qos_check(vf, error);
546 : : if (ret)
547 : 0 : return ret;
548 : :
549 : : ret = iavf_shaper_profile_param_check(profile, error);
550 : : if (ret)
551 : 0 : return ret;
552 : :
553 : : shaper_profile = iavf_shaper_profile_search(dev, shaper_profile_id);
554 : :
555 [ # # ]: 0 : if (shaper_profile) {
556 : 0 : error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
557 : 0 : error->message = "profile ID exist";
558 : 0 : return -EINVAL;
559 : : }
560 : :
561 : 0 : shaper_profile = rte_zmalloc("iavf_tm_shaper_profile",
562 : : sizeof(struct iavf_tm_shaper_profile),
563 : : 0);
564 [ # # ]: 0 : if (!shaper_profile)
565 : : return -ENOMEM;
566 : 0 : shaper_profile->shaper_profile_id = shaper_profile_id;
567 : 0 : memcpy(&shaper_profile->profile, profile,
568 : : sizeof(struct rte_tm_shaper_params));
569 : 0 : TAILQ_INSERT_TAIL(&vf->tm_conf.shaper_profile_list,
570 : : shaper_profile, node);
571 : :
572 : 0 : return 0;
573 : : }
574 : :
575 : : static int
576 : 0 : iavf_shaper_profile_del(struct rte_eth_dev *dev,
577 : : uint32_t shaper_profile_id,
578 : : struct rte_tm_error *error)
579 : : {
580 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
581 : : struct iavf_tm_shaper_profile *shaper_profile;
582 : :
583 [ # # ]: 0 : if (!error)
584 : : return -EINVAL;
585 : :
586 : : shaper_profile = iavf_shaper_profile_search(dev, shaper_profile_id);
587 : :
588 [ # # ]: 0 : if (!shaper_profile) {
589 : 0 : error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID;
590 : 0 : error->message = "profile ID not exist";
591 : 0 : return -EINVAL;
592 : : }
593 : :
594 : : /* don't delete a profile if it's used by one or several nodes */
595 [ # # ]: 0 : if (shaper_profile->reference_count) {
596 : 0 : error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE;
597 : 0 : error->message = "profile in use";
598 : 0 : return -EINVAL;
599 : : }
600 : :
601 [ # # ]: 0 : TAILQ_REMOVE(&vf->tm_conf.shaper_profile_list, shaper_profile, node);
602 : 0 : rte_free(shaper_profile);
603 : :
604 : 0 : return 0;
605 : : }
606 : :
607 : : static int
608 : 0 : iavf_tm_capabilities_get(struct rte_eth_dev *dev,
609 : : struct rte_tm_capabilities *cap,
610 : : struct rte_tm_error *error)
611 : : {
612 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
613 : : uint16_t tc_nb;
614 : : int ret;
615 : :
616 [ # # ]: 0 : if (!cap || !error)
617 : : return -EINVAL;
618 : :
619 : : ret = iavf_tm_qos_check(vf, error);
620 : : if (ret)
621 : 0 : return ret;
622 : :
623 : 0 : tc_nb = vf->qos_cap->num_elem;
624 [ # # ]: 0 : if (tc_nb > vf->vf_res->num_queue_pairs)
625 : : return -EINVAL;
626 : :
627 : 0 : error->type = RTE_TM_ERROR_TYPE_NONE;
628 : :
629 : : /* set all the parameters to 0 first. */
630 : : memset(cap, 0, sizeof(struct rte_tm_capabilities));
631 : :
632 : : /**
633 : : * support port + TCs + queues
634 : : * here shows the max capability not the current configuration.
635 : : */
636 : 0 : cap->n_nodes_max = 1 + IAVF_MAX_TRAFFIC_CLASS
637 : 0 : + vf->num_queue_pairs;
638 : 0 : cap->n_levels_max = 3; /* port, TC, queue */
639 : 0 : cap->non_leaf_nodes_identical = 1;
640 : 0 : cap->leaf_nodes_identical = 1;
641 : 0 : cap->shaper_n_max = cap->n_nodes_max;
642 : 0 : cap->shaper_private_n_max = cap->n_nodes_max;
643 : : cap->shaper_private_dual_rate_n_max = 0;
644 : : cap->shaper_private_rate_min = 0;
645 : : /* Bytes per second */
646 : 0 : cap->shaper_private_rate_max =
647 : 0 : (uint64_t)vf->link_speed * 1000000 / IAVF_BITS_PER_BYTE;
648 : : cap->shaper_private_packet_mode_supported = 0;
649 : 0 : cap->shaper_private_byte_mode_supported = 1;
650 : : cap->shaper_shared_n_max = 0;
651 : : cap->shaper_shared_n_nodes_per_shaper_max = 0;
652 : : cap->shaper_shared_n_shapers_per_node_max = 0;
653 : : cap->shaper_shared_dual_rate_n_max = 0;
654 : : cap->shaper_shared_rate_min = 0;
655 : : cap->shaper_shared_rate_max = 0;
656 : : cap->shaper_shared_packet_mode_supported = 0;
657 : : cap->shaper_shared_byte_mode_supported = 0;
658 : 0 : cap->sched_n_children_max = vf->num_queue_pairs;
659 : 0 : cap->sched_sp_n_priorities_max = 1;
660 : : cap->sched_wfq_n_children_per_group_max = 0;
661 : : cap->sched_wfq_n_groups_max = 0;
662 : 0 : cap->sched_wfq_weight_max = 1;
663 : : cap->sched_wfq_packet_mode_supported = 0;
664 : : cap->sched_wfq_byte_mode_supported = 0;
665 : : cap->cman_head_drop_supported = 0;
666 : : cap->dynamic_update_mask = 0;
667 : 0 : cap->shaper_pkt_length_adjust_min = RTE_TM_ETH_FRAMING_OVERHEAD;
668 : 0 : cap->shaper_pkt_length_adjust_max = RTE_TM_ETH_FRAMING_OVERHEAD_FCS;
669 : : cap->cman_wred_context_n_max = 0;
670 : : cap->cman_wred_context_private_n_max = 0;
671 : : cap->cman_wred_context_shared_n_max = 0;
672 : : cap->cman_wred_context_shared_n_nodes_per_context_max = 0;
673 : : cap->cman_wred_context_shared_n_contexts_per_node_max = 0;
674 : : cap->stats_mask = 0;
675 : :
676 : 0 : return 0;
677 : : }
678 : :
679 : : static int
680 : 0 : iavf_level_capabilities_get(struct rte_eth_dev *dev,
681 : : uint32_t level_id,
682 : : struct rte_tm_level_capabilities *cap,
683 : : struct rte_tm_error *error)
684 : : {
685 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
686 : :
687 [ # # ]: 0 : if (!cap || !error)
688 : : return -EINVAL;
689 : :
690 [ # # ]: 0 : if (level_id >= IAVF_TM_NODE_TYPE_MAX) {
691 : 0 : error->type = RTE_TM_ERROR_TYPE_LEVEL_ID;
692 : 0 : error->message = "too deep level";
693 : 0 : return -EINVAL;
694 : : }
695 : :
696 : : /* root node */
697 [ # # ]: 0 : if (level_id == IAVF_TM_NODE_TYPE_PORT) {
698 : 0 : cap->n_nodes_max = 1;
699 : 0 : cap->n_nodes_nonleaf_max = 1;
700 : 0 : cap->n_nodes_leaf_max = 0;
701 [ # # ]: 0 : } else if (level_id == IAVF_TM_NODE_TYPE_TC) {
702 : : /* TC */
703 : 0 : cap->n_nodes_max = IAVF_MAX_TRAFFIC_CLASS;
704 : 0 : cap->n_nodes_nonleaf_max = IAVF_MAX_TRAFFIC_CLASS;
705 : 0 : cap->n_nodes_leaf_max = 0;
706 : : } else {
707 : : /* queue */
708 : 0 : cap->n_nodes_max = vf->num_queue_pairs;
709 : 0 : cap->n_nodes_nonleaf_max = 0;
710 : 0 : cap->n_nodes_leaf_max = vf->num_queue_pairs;
711 : : }
712 : :
713 : 0 : cap->non_leaf_nodes_identical = true;
714 : 0 : cap->leaf_nodes_identical = true;
715 : :
716 [ # # ]: 0 : if (level_id != IAVF_TM_NODE_TYPE_QUEUE) {
717 : 0 : cap->nonleaf.shaper_private_supported = true;
718 : 0 : cap->nonleaf.shaper_private_dual_rate_supported = false;
719 : 0 : cap->nonleaf.shaper_private_rate_min = 0;
720 : : /* Bytes per second */
721 : 0 : cap->nonleaf.shaper_private_rate_max =
722 : 0 : (uint64_t)vf->link_speed * 1000000 / IAVF_BITS_PER_BYTE;
723 : 0 : cap->nonleaf.shaper_private_packet_mode_supported = 0;
724 : 0 : cap->nonleaf.shaper_private_byte_mode_supported = 1;
725 : 0 : cap->nonleaf.shaper_shared_n_max = 0;
726 : 0 : cap->nonleaf.shaper_shared_packet_mode_supported = 0;
727 : 0 : cap->nonleaf.shaper_shared_byte_mode_supported = 0;
728 [ # # ]: 0 : if (level_id == IAVF_TM_NODE_TYPE_PORT)
729 : 0 : cap->nonleaf.sched_n_children_max =
730 : : IAVF_MAX_TRAFFIC_CLASS;
731 : : else
732 : 0 : cap->nonleaf.sched_n_children_max =
733 : 0 : vf->num_queue_pairs;
734 : 0 : cap->nonleaf.sched_sp_n_priorities_max = 1;
735 : 0 : cap->nonleaf.sched_wfq_n_children_per_group_max = 0;
736 : 0 : cap->nonleaf.sched_wfq_n_groups_max = 0;
737 : 0 : cap->nonleaf.sched_wfq_weight_max = 1;
738 : 0 : cap->nonleaf.sched_wfq_packet_mode_supported = 0;
739 : 0 : cap->nonleaf.sched_wfq_byte_mode_supported = 0;
740 : 0 : cap->nonleaf.stats_mask = 0;
741 : :
742 : 0 : return 0;
743 : : }
744 : :
745 : : /* queue node */
746 : 0 : cap->leaf.shaper_private_supported = false;
747 : 0 : cap->leaf.shaper_private_dual_rate_supported = false;
748 : 0 : cap->leaf.shaper_private_rate_min = 0;
749 : : /* Bytes per second */
750 : 0 : cap->leaf.shaper_private_rate_max =
751 : 0 : (uint64_t)vf->link_speed * 1000000 / IAVF_BITS_PER_BYTE;
752 : 0 : cap->leaf.shaper_private_packet_mode_supported = 0;
753 : 0 : cap->leaf.shaper_private_byte_mode_supported = 1;
754 : 0 : cap->leaf.shaper_shared_n_max = 0;
755 : 0 : cap->leaf.shaper_shared_packet_mode_supported = 0;
756 : 0 : cap->leaf.shaper_shared_byte_mode_supported = 0;
757 : 0 : cap->leaf.cman_head_drop_supported = false;
758 : 0 : cap->leaf.cman_wred_context_private_supported = true;
759 : 0 : cap->leaf.cman_wred_context_shared_n_max = 0;
760 : 0 : cap->leaf.stats_mask = 0;
761 : :
762 : 0 : return 0;
763 : : }
764 : :
765 : : static int
766 : 0 : iavf_node_capabilities_get(struct rte_eth_dev *dev,
767 : : uint32_t node_id,
768 : : struct rte_tm_node_capabilities *cap,
769 : : struct rte_tm_error *error)
770 : : {
771 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
772 : : enum iavf_tm_node_type node_type;
773 : : struct virtchnl_qos_cap_elem tc_cap;
774 : : struct iavf_tm_node *tm_node;
775 : : int ret;
776 : :
777 [ # # ]: 0 : if (!cap || !error)
778 : : return -EINVAL;
779 : :
780 : : ret = iavf_tm_qos_check(vf, error);
781 : : if (ret)
782 : 0 : return ret;
783 : :
784 [ # # ]: 0 : if (node_id == RTE_TM_NODE_ID_NULL) {
785 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_ID;
786 : 0 : error->message = "invalid node id";
787 : 0 : return -EINVAL;
788 : : }
789 : :
790 : : /* check if the node id exists */
791 : 0 : tm_node = iavf_tm_node_search(dev, node_id, &node_type);
792 [ # # ]: 0 : if (!tm_node) {
793 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_ID;
794 : 0 : error->message = "no such node";
795 : 0 : return -EINVAL;
796 : : }
797 : :
798 [ # # ]: 0 : if (node_type != IAVF_TM_NODE_TYPE_TC) {
799 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
800 : 0 : error->message = "not support capability get";
801 : 0 : return -EINVAL;
802 : : }
803 : :
804 : 0 : tc_cap = vf->qos_cap->cap[tm_node->tc];
805 [ # # ]: 0 : if (tc_cap.tc_num != tm_node->tc) {
806 : 0 : error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
807 : 0 : error->message = "tc not match";
808 : 0 : return -EINVAL;
809 : : }
810 : :
811 : 0 : cap->shaper_private_supported = true;
812 : 0 : cap->shaper_private_dual_rate_supported = false;
813 : : /* Bytes per second */
814 : 0 : cap->shaper_private_rate_min =
815 : 0 : (uint64_t)tc_cap.shaper.committed * 1000 / IAVF_BITS_PER_BYTE;
816 : 0 : cap->shaper_private_rate_max =
817 : 0 : (uint64_t)tc_cap.shaper.peak * 1000 / IAVF_BITS_PER_BYTE;
818 : 0 : cap->shaper_shared_n_max = 0;
819 : 0 : cap->nonleaf.sched_n_children_max = vf->num_queue_pairs;
820 : 0 : cap->nonleaf.sched_sp_n_priorities_max = 1;
821 : 0 : cap->nonleaf.sched_wfq_n_children_per_group_max = 1;
822 : 0 : cap->nonleaf.sched_wfq_n_groups_max = 0;
823 : 0 : cap->nonleaf.sched_wfq_weight_max = tc_cap.weight;
824 : 0 : cap->stats_mask = 0;
825 : :
826 : 0 : return 0;
827 : : }
828 : :
829 : 0 : static int iavf_hierarchy_commit(struct rte_eth_dev *dev,
830 : : int clear_on_fail,
831 : : __rte_unused struct rte_tm_error *error)
832 : : {
833 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
834 : : struct iavf_adapter *adapter =
835 : : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
836 : : struct virtchnl_queue_tc_mapping *q_tc_mapping = NULL;
837 : : struct virtchnl_queues_bw_cfg *q_bw = NULL;
838 : : struct iavf_tm_node_list *queue_list = &vf->tm_conf.queue_list;
839 : : struct iavf_tm_node *tm_node;
840 : : struct iavf_qtc_map *qtc_map = NULL;
841 : 0 : struct iavf_qtc_map *old_qtc_map = vf->qtc_map; /* to free memory if new map assigned */
842 : : uint16_t size, size_q;
843 : : int index = 0, node_committed = 0;
844 : : int i, ret_val = IAVF_SUCCESS;
845 : :
846 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS)) {
847 : 0 : PMD_DRV_LOG(ERR, "VF queue tc mapping is not supported");
848 : : ret_val = IAVF_NOT_SUPPORTED;
849 : 0 : goto fail_clear;
850 : : }
851 : :
852 : : /*
853 : : * Allow reconfiguration on a running port only when a single queue is
854 : : * involved (single TC node and single QoS element); otherwise the port
855 : : * must be stopped first. qos_cap is valid here because the
856 : : * VIRTCHNL_VF_OFFLOAD_QOS capability was checked above.
857 : : */
858 [ # # # # ]: 0 : if ((vf->tm_conf.nb_tc_node != 1 || vf->qos_cap->num_elem != 1) &&
859 [ # # ]: 0 : adapter->stopped != 1) {
860 : 0 : PMD_DRV_LOG(ERR, "Please stop port first");
861 : : ret_val = IAVF_ERR_NOT_READY;
862 : 0 : goto err;
863 : : }
864 : :
865 : : /* check if all TC nodes are set with VF vsi */
866 [ # # ]: 0 : if (vf->tm_conf.nb_tc_node != vf->qos_cap->num_elem) {
867 : 0 : PMD_DRV_LOG(ERR, "Does not set VF vsi nodes to all TCs");
868 : : ret_val = IAVF_ERR_PARAM;
869 : 0 : goto fail_clear;
870 : : }
871 : :
872 : 0 : size = sizeof(*q_tc_mapping) + sizeof(q_tc_mapping->tc[0]) *
873 : : (vf->qos_cap->num_elem - 1);
874 : 0 : q_tc_mapping = calloc(1, size);
875 [ # # ]: 0 : if (!q_tc_mapping) {
876 : : ret_val = IAVF_ERR_NO_MEMORY;
877 : 0 : goto fail_clear;
878 : : }
879 : :
880 : 0 : size_q = sizeof(*q_bw) + sizeof(q_bw->cfg[0]) *
881 : 0 : (vf->num_queue_pairs - 1);
882 : 0 : q_bw = calloc(1, size_q);
883 [ # # ]: 0 : if (!q_bw) {
884 : : ret_val = IAVF_ERR_NO_MEMORY;
885 : 0 : goto fail_clear;
886 : : }
887 : :
888 : 0 : q_tc_mapping->vsi_id = vf->vsi.vsi_id;
889 : 0 : q_tc_mapping->num_tc = vf->qos_cap->num_elem;
890 : 0 : q_tc_mapping->num_queue_pairs = vf->num_queue_pairs;
891 : :
892 : 0 : q_bw->vsi_id = vf->vsi.vsi_id;
893 : 0 : q_bw->num_queues = vf->num_queue_pairs;
894 : :
895 [ # # ]: 0 : TAILQ_FOREACH(tm_node, queue_list, node) {
896 [ # # ]: 0 : if (tm_node->tc >= q_tc_mapping->num_tc) {
897 : 0 : PMD_DRV_LOG(ERR, "TC%d is not enabled", tm_node->tc);
898 : : ret_val = IAVF_ERR_PARAM;
899 : 0 : goto fail_clear;
900 : : }
901 : 0 : q_tc_mapping->tc[tm_node->tc].req.queue_count++;
902 : :
903 : 0 : q_bw->cfg[node_committed].queue_id = tm_node->id;
904 : 0 : q_bw->cfg[node_committed].tc = tm_node->tc;
905 [ # # ]: 0 : if (tm_node->shaper_profile) {
906 : 0 : q_bw->cfg[node_committed].shaper.peak =
907 : 0 : tm_node->shaper_profile->profile.peak.rate /
908 : : 1000 * IAVF_BITS_PER_BYTE;
909 : 0 : q_bw->cfg[node_committed].shaper.committed =
910 : 0 : tm_node->shaper_profile->profile.committed.rate /
911 : : 1000 * IAVF_BITS_PER_BYTE;
912 : : }
913 : :
914 : 0 : node_committed++;
915 : : }
916 : :
917 : : /* All queues allocated to this VF should be mapped */
918 [ # # ]: 0 : if (node_committed < vf->num_queue_pairs) {
919 : 0 : PMD_DRV_LOG(ERR, "queue node is less than allocated queue pairs");
920 : : ret_val = IAVF_ERR_PARAM;
921 : 0 : goto fail_clear;
922 : : }
923 : :
924 : 0 : ret_val = iavf_set_q_bw(dev, q_bw, size_q);
925 [ # # ]: 0 : if (ret_val)
926 : 0 : goto fail_clear;
927 : :
928 : : /* store the queue TC mapping info */
929 : 0 : qtc_map = calloc(q_tc_mapping->num_tc, sizeof(struct iavf_qtc_map));
930 [ # # ]: 0 : if (!qtc_map) {
931 : : ret_val = IAVF_ERR_NO_MEMORY;
932 : 0 : goto fail_clear;
933 : : }
934 : :
935 [ # # ]: 0 : for (i = 0; i < q_tc_mapping->num_tc; i++) {
936 : 0 : q_tc_mapping->tc[i].req.start_queue_id = index;
937 : 0 : index += q_tc_mapping->tc[i].req.queue_count;
938 : 0 : qtc_map[i].tc = i;
939 : 0 : qtc_map[i].start_queue_id =
940 : : q_tc_mapping->tc[i].req.start_queue_id;
941 : 0 : qtc_map[i].queue_count = q_tc_mapping->tc[i].req.queue_count;
942 : : }
943 : :
944 : 0 : ret_val = iavf_set_q_tc_map(dev, q_tc_mapping, size);
945 [ # # ]: 0 : if (ret_val)
946 : 0 : goto fail_clear;
947 : :
948 : : /* replace the previously committed mapping, if any */
949 : 0 : vf->qtc_map = qtc_map;
950 : 0 : free(old_qtc_map);
951 [ # # ]: 0 : if (adapter->stopped == 1)
952 : 0 : vf->tm_conf.committed = true;
953 : 0 : free(q_bw);
954 : 0 : free(q_tc_mapping);
955 : 0 : return ret_val;
956 : :
957 : 0 : fail_clear:
958 : : /* clear all the traffic manager configuration */
959 [ # # ]: 0 : if (clear_on_fail) {
960 : 0 : iavf_tm_conf_uninit(dev);
961 : 0 : iavf_tm_conf_init(dev);
962 : : }
963 : 0 : err:
964 : 0 : free(q_bw);
965 : 0 : free(q_tc_mapping);
966 : 0 : free(qtc_map);
967 : 0 : return ret_val;
968 : : }
|