1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2017 Intel Corporation 3 */ 4 5 #include <cmdline_parse.h> 6 #include <cmdline_parse_num.h> 7 #include <cmdline_parse_string.h> 8 9 #include <rte_ethdev.h> 10 #include <rte_flow.h> 11 #include <rte_tm.h> 12 13 #include "testpmd.h" 14 #include "cmdline_tm.h" 15 16 #define PARSE_DELIMITER " \f\n\r\t\v" 17 #define MAX_NUM_SHARED_SHAPERS 256 18 19 #define skip_white_spaces(pos) \ 20 ({ \ 21 __typeof__(pos) _p = (pos); \ 22 for ( ; isspace(*_p); _p++) \ 23 ; \ 24 _p; \ 25 }) 26 27 /** Display TM Error Message */ 28 static void 29 print_err_msg(struct rte_tm_error *error) 30 { 31 static const char *const errstrlist[] = { 32 [RTE_TM_ERROR_TYPE_NONE] = "no error", 33 [RTE_TM_ERROR_TYPE_UNSPECIFIED] = "cause unspecified", 34 [RTE_TM_ERROR_TYPE_CAPABILITIES] 35 = "capability parameter null", 36 [RTE_TM_ERROR_TYPE_LEVEL_ID] = "level id", 37 [RTE_TM_ERROR_TYPE_WRED_PROFILE] 38 = "wred profile null", 39 [RTE_TM_ERROR_TYPE_WRED_PROFILE_GREEN] = "wred profile(green)", 40 [RTE_TM_ERROR_TYPE_WRED_PROFILE_YELLOW] 41 = "wred profile(yellow)", 42 [RTE_TM_ERROR_TYPE_WRED_PROFILE_RED] = "wred profile(red)", 43 [RTE_TM_ERROR_TYPE_WRED_PROFILE_ID] = "wred profile id", 44 [RTE_TM_ERROR_TYPE_SHARED_WRED_CONTEXT_ID] 45 = "shared wred context id", 46 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE] = "shaper profile null", 47 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE] 48 = "committed rate field (shaper profile)", 49 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_SIZE] 50 = "committed size field (shaper profile)", 51 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_RATE] 52 = "peak rate field (shaper profile)", 53 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE] 54 = "peak size field (shaper profile)", 55 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PKT_ADJUST_LEN] 56 = "packet adjust length field (shaper profile)", 57 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID] = "shaper profile id", 58 [RTE_TM_ERROR_TYPE_SHARED_SHAPER_ID] = "shared shaper id", 59 [RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID] = "parent node id", 60 [RTE_TM_ERROR_TYPE_NODE_PRIORITY] = "node priority", 61 [RTE_TM_ERROR_TYPE_NODE_WEIGHT] = "node weight", 62 [RTE_TM_ERROR_TYPE_NODE_PARAMS] = "node parameter null", 63 [RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID] 64 = "shaper profile id field (node params)", 65 [RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID] 66 = "shared shaper id field (node params)", 67 [RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS] 68 = "num shared shapers field (node params)", 69 [RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE] 70 = "wfq weght mode field (node params)", 71 [RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES] 72 = "num strict priorities field (node params)", 73 [RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN] 74 = "congestion management mode field (node params)", 75 [RTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID] = 76 "wred profile id field (node params)", 77 [RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_WRED_CONTEXT_ID] 78 = "shared wred context id field (node params)", 79 [RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS] 80 = "num shared wred contexts field (node params)", 81 [RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS] 82 = "stats field (node params)", 83 [RTE_TM_ERROR_TYPE_NODE_ID] = "node id", 84 }; 85 86 const char *errstr; 87 char buf[64]; 88 89 if ((unsigned int)error->type >= RTE_DIM(errstrlist) || 90 !errstrlist[error->type]) 91 errstr = "unknown type"; 92 else 93 errstr = errstrlist[error->type]; 94 95 if (error->cause) 96 snprintf(buf, sizeof(buf), "cause: %p, ", error->cause); 97 98 printf("%s: %s%s (error %d)\n", errstr, error->cause ? buf : "", 99 error->message ? error->message : "(no stated reason)", 100 error->type); 101 } 102 103 static int 104 read_uint64(uint64_t *value, const char *p) 105 { 106 char *next; 107 uint64_t val; 108 109 p = skip_white_spaces(p); 110 if (!isdigit(*p)) 111 return -EINVAL; 112 113 val = strtoul(p, &next, 10); 114 if (p == next) 115 return -EINVAL; 116 117 p = next; 118 switch (*p) { 119 case 'T': 120 val *= 1024ULL; 121 /* fall through */ 122 case 'G': 123 val *= 1024ULL; 124 /* fall through */ 125 case 'M': 126 val *= 1024ULL; 127 /* fall through */ 128 case 'k': 129 case 'K': 130 val *= 1024ULL; 131 p++; 132 break; 133 } 134 135 p = skip_white_spaces(p); 136 if (*p != '\0') 137 return -EINVAL; 138 139 *value = val; 140 return 0; 141 } 142 143 static int 144 read_uint32(uint32_t *value, const char *p) 145 { 146 uint64_t val = 0; 147 int ret = read_uint64(&val, p); 148 149 if (ret < 0) 150 return ret; 151 152 if (val > UINT32_MAX) 153 return -ERANGE; 154 155 *value = val; 156 return 0; 157 } 158 159 static int 160 parse_multi_ss_id_str(char *s_str, uint32_t *n_ssp, uint32_t shaper_id[]) 161 { 162 uint32_t n_shared_shapers = 0, i = 0; 163 char *token; 164 165 /* First token: num of shared shapers */ 166 token = strtok_r(s_str, PARSE_DELIMITER, &s_str); 167 if (token == NULL) 168 return -1; 169 170 if (read_uint32(&n_shared_shapers, token)) 171 return -1; 172 173 /* Check: num of shared shaper */ 174 if (n_shared_shapers >= MAX_NUM_SHARED_SHAPERS) { 175 printf(" Number of shared shapers exceed the max (error)\n"); 176 return -1; 177 } 178 179 /* Parse shared shaper ids */ 180 while (1) { 181 token = strtok_r(s_str, PARSE_DELIMITER, &s_str); 182 if ((token != NULL && n_shared_shapers == 0) || 183 (token == NULL && i < n_shared_shapers)) 184 return -1; 185 186 if (token == NULL) 187 break; 188 189 if (read_uint32(&shaper_id[i], token)) 190 return -1; 191 i++; 192 } 193 *n_ssp = n_shared_shapers; 194 195 return 0; 196 } 197 /* *** Port TM Capability *** */ 198 struct cmd_show_port_tm_cap_result { 199 cmdline_fixed_string_t show; 200 cmdline_fixed_string_t port; 201 cmdline_fixed_string_t tm; 202 cmdline_fixed_string_t cap; 203 uint16_t port_id; 204 }; 205 206 cmdline_parse_token_string_t cmd_show_port_tm_cap_show = 207 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result, 208 show, "show"); 209 cmdline_parse_token_string_t cmd_show_port_tm_cap_port = 210 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result, 211 port, "port"); 212 cmdline_parse_token_string_t cmd_show_port_tm_cap_tm = 213 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result, 214 tm, "tm"); 215 cmdline_parse_token_string_t cmd_show_port_tm_cap_cap = 216 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result, 217 cap, "cap"); 218 cmdline_parse_token_num_t cmd_show_port_tm_cap_port_id = 219 TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_cap_result, 220 port_id, UINT16); 221 222 static void cmd_show_port_tm_cap_parsed(void *parsed_result, 223 __attribute__((unused)) struct cmdline *cl, 224 __attribute__((unused)) void *data) 225 { 226 struct cmd_show_port_tm_cap_result *res = parsed_result; 227 struct rte_tm_capabilities cap; 228 struct rte_tm_error error; 229 portid_t port_id = res->port_id; 230 uint32_t i; 231 int ret; 232 233 if (port_id_is_invalid(port_id, ENABLED_WARN)) 234 return; 235 236 memset(&cap, 0, sizeof(struct rte_tm_capabilities)); 237 memset(&error, 0, sizeof(struct rte_tm_error)); 238 ret = rte_tm_capabilities_get(port_id, &cap, &error); 239 if (ret) { 240 print_err_msg(&error); 241 return; 242 } 243 244 printf("\n**** Port TM Capabilities ****\n\n"); 245 printf("cap.n_nodes_max %" PRIu32 "\n", cap.n_nodes_max); 246 printf("cap.n_levels_max %" PRIu32 "\n", cap.n_levels_max); 247 printf("cap.non_leaf_nodes_identical %" PRId32 "\n", 248 cap.non_leaf_nodes_identical); 249 printf("cap.leaf_nodes_identical %" PRId32 "\n", 250 cap.leaf_nodes_identical); 251 printf("cap.shaper_n_max %u\n", cap.shaper_n_max); 252 printf("cap.shaper_private_n_max %" PRIu32 "\n", 253 cap.shaper_private_n_max); 254 printf("cap.shaper_private_dual_rate_n_max %" PRId32 "\n", 255 cap.shaper_private_dual_rate_n_max); 256 printf("cap.shaper_private_rate_min %" PRIu64 "\n", 257 cap.shaper_private_rate_min); 258 printf("cap.shaper_private_rate_max %" PRIu64 "\n", 259 cap.shaper_private_rate_max); 260 printf("cap.shaper_shared_n_max %" PRIu32 "\n", 261 cap.shaper_shared_n_max); 262 printf("cap.shaper_shared_n_nodes_per_shaper_max %" PRIu32 "\n", 263 cap.shaper_shared_n_nodes_per_shaper_max); 264 printf("cap.shaper_shared_n_shapers_per_node_max %" PRIu32 "\n", 265 cap.shaper_shared_n_shapers_per_node_max); 266 printf("cap.shaper_shared_dual_rate_n_max %" PRIu32 "\n", 267 cap.shaper_shared_dual_rate_n_max); 268 printf("cap.shaper_shared_rate_min %" PRIu64 "\n", 269 cap.shaper_shared_rate_min); 270 printf("cap.shaper_shared_rate_max %" PRIu64 "\n", 271 cap.shaper_shared_rate_max); 272 printf("cap.shaper_pkt_length_adjust_min %" PRId32 "\n", 273 cap.shaper_pkt_length_adjust_min); 274 printf("cap.shaper_pkt_length_adjust_max %" PRId32 "\n", 275 cap.shaper_pkt_length_adjust_max); 276 printf("cap.sched_n_children_max %" PRIu32 "\n", 277 cap.sched_n_children_max); 278 printf("cap.sched_sp_n_priorities_max %" PRIu32 "\n", 279 cap.sched_sp_n_priorities_max); 280 printf("cap.sched_wfq_n_children_per_group_max %" PRIu32 "\n", 281 cap.sched_wfq_n_children_per_group_max); 282 printf("cap.sched_wfq_n_groups_max %" PRIu32 "\n", 283 cap.sched_wfq_n_groups_max); 284 printf("cap.sched_wfq_weight_max %" PRIu32 "\n", 285 cap.sched_wfq_weight_max); 286 printf("cap.cman_head_drop_supported %" PRId32 "\n", 287 cap.cman_head_drop_supported); 288 printf("cap.cman_wred_context_n_max %" PRIu32 "\n", 289 cap.cman_wred_context_n_max); 290 printf("cap.cman_wred_context_private_n_max %" PRIu32 "\n", 291 cap.cman_wred_context_private_n_max); 292 printf("cap.cman_wred_context_shared_n_max %" PRIu32 "\n", 293 cap.cman_wred_context_shared_n_max); 294 printf("cap.cman_wred_context_shared_n_nodes_per_context_max %" PRIu32 295 "\n", cap.cman_wred_context_shared_n_nodes_per_context_max); 296 printf("cap.cman_wred_context_shared_n_contexts_per_node_max %" PRIu32 297 "\n", cap.cman_wred_context_shared_n_contexts_per_node_max); 298 299 for (i = 0; i < RTE_TM_COLORS; i++) { 300 printf("cap.mark_vlan_dei_supported %" PRId32 "\n", 301 cap.mark_vlan_dei_supported[i]); 302 printf("cap.mark_ip_ecn_tcp_supported %" PRId32 "\n", 303 cap.mark_ip_ecn_tcp_supported[i]); 304 printf("cap.mark_ip_ecn_sctp_supported %" PRId32 "\n", 305 cap.mark_ip_ecn_sctp_supported[i]); 306 printf("cap.mark_ip_dscp_supported %" PRId32 "\n", 307 cap.mark_ip_dscp_supported[i]); 308 } 309 310 printf("cap.dynamic_update_mask %" PRIx64 "\n", 311 cap.dynamic_update_mask); 312 printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask); 313 } 314 315 cmdline_parse_inst_t cmd_show_port_tm_cap = { 316 .f = cmd_show_port_tm_cap_parsed, 317 .data = NULL, 318 .help_str = "Show Port TM Capabilities", 319 .tokens = { 320 (void *)&cmd_show_port_tm_cap_show, 321 (void *)&cmd_show_port_tm_cap_port, 322 (void *)&cmd_show_port_tm_cap_tm, 323 (void *)&cmd_show_port_tm_cap_cap, 324 (void *)&cmd_show_port_tm_cap_port_id, 325 NULL, 326 }, 327 }; 328 329 /* *** Port TM Hierarchical Level Capability *** */ 330 struct cmd_show_port_tm_level_cap_result { 331 cmdline_fixed_string_t show; 332 cmdline_fixed_string_t port; 333 cmdline_fixed_string_t tm; 334 cmdline_fixed_string_t level; 335 cmdline_fixed_string_t cap; 336 uint16_t port_id; 337 uint32_t level_id; 338 }; 339 340 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_show = 341 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 342 show, "show"); 343 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_port = 344 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 345 port, "port"); 346 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_tm = 347 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 348 tm, "tm"); 349 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_level = 350 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 351 level, "level"); 352 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_cap = 353 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 354 cap, "cap"); 355 cmdline_parse_token_num_t cmd_show_port_tm_level_cap_port_id = 356 TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 357 port_id, UINT16); 358 cmdline_parse_token_num_t cmd_show_port_tm_level_cap_level_id = 359 TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 360 level_id, UINT32); 361 362 363 static void cmd_show_port_tm_level_cap_parsed(void *parsed_result, 364 __attribute__((unused)) struct cmdline *cl, 365 __attribute__((unused)) void *data) 366 { 367 struct cmd_show_port_tm_level_cap_result *res = parsed_result; 368 struct rte_tm_level_capabilities lcap; 369 struct rte_tm_error error; 370 portid_t port_id = res->port_id; 371 uint32_t level_id = res->level_id; 372 int ret; 373 374 if (port_id_is_invalid(port_id, ENABLED_WARN)) 375 return; 376 377 memset(&lcap, 0, sizeof(struct rte_tm_level_capabilities)); 378 memset(&error, 0, sizeof(struct rte_tm_error)); 379 ret = rte_tm_level_capabilities_get(port_id, level_id, &lcap, &error); 380 if (ret) { 381 print_err_msg(&error); 382 return; 383 } 384 printf("\n** Port TM Hierarchy level %" PRIu32 " Capability **\n\n", 385 level_id); 386 387 printf("cap.n_nodes_max %" PRIu32 "\n", lcap.n_nodes_max); 388 printf("cap.n_nodes_nonleaf_max %" PRIu32 "\n", 389 lcap.n_nodes_nonleaf_max); 390 printf("cap.n_nodes_leaf_max %" PRIu32 "\n", lcap.n_nodes_leaf_max); 391 printf("cap.non_leaf_nodes_identical %" PRId32 "\n", 392 lcap.non_leaf_nodes_identical); 393 printf("cap.leaf_nodes_identical %" PRId32 "\n", 394 lcap.leaf_nodes_identical); 395 if (level_id <= 3) { 396 printf("cap.nonleaf.shaper_private_supported %" PRId32 "\n", 397 lcap.nonleaf.shaper_private_supported); 398 printf("cap.nonleaf.shaper_private_dual_rate_supported %" PRId32 399 "\n", lcap.nonleaf.shaper_private_dual_rate_supported); 400 printf("cap.nonleaf.shaper_private_rate_min %" PRIu64 "\n", 401 lcap.nonleaf.shaper_private_rate_min); 402 printf("cap.nonleaf.shaper_private_rate_max %" PRIu64 "\n", 403 lcap.nonleaf.shaper_private_rate_max); 404 printf("cap.nonleaf.shaper_shared_n_max %" PRIu32 "\n", 405 lcap.nonleaf.shaper_shared_n_max); 406 printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n", 407 lcap.nonleaf.sched_n_children_max); 408 printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n", 409 lcap.nonleaf.sched_sp_n_priorities_max); 410 printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32 411 "\n", lcap.nonleaf.sched_wfq_n_children_per_group_max); 412 printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n", 413 lcap.nonleaf.sched_wfq_n_groups_max); 414 printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n", 415 lcap.nonleaf.sched_wfq_weight_max); 416 printf("cap.nonleaf.stats_mask %" PRIx64 "\n", 417 lcap.nonleaf.stats_mask); 418 } else { 419 printf("cap.leaf.shaper_private_supported %" PRId32 "\n", 420 lcap.leaf.shaper_private_supported); 421 printf("cap.leaf.shaper_private_dual_rate_supported %" PRId32 422 "\n", lcap.leaf.shaper_private_dual_rate_supported); 423 printf("cap.leaf.shaper_private_rate_min %" PRIu64 "\n", 424 lcap.leaf.shaper_private_rate_min); 425 printf("cap.leaf.shaper_private_rate_max %" PRIu64 "\n", 426 lcap.leaf.shaper_private_rate_max); 427 printf("cap.leaf.shaper_shared_n_max %" PRIu32 "\n", 428 lcap.leaf.shaper_shared_n_max); 429 printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n", 430 lcap.leaf.cman_head_drop_supported); 431 printf("cap.leaf.cman_wred_context_private_supported %" PRId32 432 "\n", lcap.leaf.cman_wred_context_private_supported); 433 printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n", 434 lcap.leaf.cman_wred_context_shared_n_max); 435 printf("cap.leaf.stats_mask %" PRIx64 "\n", 436 lcap.leaf.stats_mask); 437 } 438 } 439 440 cmdline_parse_inst_t cmd_show_port_tm_level_cap = { 441 .f = cmd_show_port_tm_level_cap_parsed, 442 .data = NULL, 443 .help_str = "Show Port TM Hierarhical level Capabilities", 444 .tokens = { 445 (void *)&cmd_show_port_tm_level_cap_show, 446 (void *)&cmd_show_port_tm_level_cap_port, 447 (void *)&cmd_show_port_tm_level_cap_tm, 448 (void *)&cmd_show_port_tm_level_cap_level, 449 (void *)&cmd_show_port_tm_level_cap_cap, 450 (void *)&cmd_show_port_tm_level_cap_port_id, 451 (void *)&cmd_show_port_tm_level_cap_level_id, 452 NULL, 453 }, 454 }; 455 456 /* *** Port TM Hierarchy Node Capability *** */ 457 struct cmd_show_port_tm_node_cap_result { 458 cmdline_fixed_string_t show; 459 cmdline_fixed_string_t port; 460 cmdline_fixed_string_t tm; 461 cmdline_fixed_string_t node; 462 cmdline_fixed_string_t cap; 463 uint16_t port_id; 464 uint32_t node_id; 465 }; 466 467 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_show = 468 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 469 show, "show"); 470 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_port = 471 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 472 port, "port"); 473 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_tm = 474 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 475 tm, "tm"); 476 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_node = 477 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 478 node, "node"); 479 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_cap = 480 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 481 cap, "cap"); 482 cmdline_parse_token_num_t cmd_show_port_tm_node_cap_port_id = 483 TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 484 port_id, UINT16); 485 cmdline_parse_token_num_t cmd_show_port_tm_node_cap_node_id = 486 TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 487 node_id, UINT32); 488 489 static void cmd_show_port_tm_node_cap_parsed(void *parsed_result, 490 __attribute__((unused)) struct cmdline *cl, 491 __attribute__((unused)) void *data) 492 { 493 struct cmd_show_port_tm_node_cap_result *res = parsed_result; 494 struct rte_tm_node_capabilities ncap; 495 struct rte_tm_error error; 496 uint32_t node_id = res->node_id; 497 portid_t port_id = res->port_id; 498 int ret, is_leaf = 0; 499 500 if (port_id_is_invalid(port_id, ENABLED_WARN)) 501 return; 502 503 memset(&error, 0, sizeof(struct rte_tm_error)); 504 /* Node id must be valid */ 505 ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error); 506 if (ret != 0) { 507 print_err_msg(&error); 508 return; 509 } 510 511 memset(&ncap, 0, sizeof(struct rte_tm_node_capabilities)); 512 ret = rte_tm_node_capabilities_get(port_id, node_id, &ncap, &error); 513 if (ret != 0) { 514 print_err_msg(&error); 515 return; 516 } 517 printf("\n** Port TM Hierarchy node %" PRIu32 " Capability **\n\n", 518 node_id); 519 printf("cap.shaper_private_supported %" PRId32 "\n", 520 ncap.shaper_private_supported); 521 printf("cap.shaper_private_dual_rate_supported %" PRId32 "\n", 522 ncap.shaper_private_dual_rate_supported); 523 printf("cap.shaper_private_rate_min %" PRIu64 "\n", 524 ncap.shaper_private_rate_min); 525 printf("cap.shaper_private_rate_max %" PRIu64 "\n", 526 ncap.shaper_private_rate_max); 527 printf("cap.shaper_shared_n_max %" PRIu32 "\n", 528 ncap.shaper_shared_n_max); 529 if (!is_leaf) { 530 printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n", 531 ncap.nonleaf.sched_n_children_max); 532 printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n", 533 ncap.nonleaf.sched_sp_n_priorities_max); 534 printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32 535 "\n", ncap.nonleaf.sched_wfq_n_children_per_group_max); 536 printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n", 537 ncap.nonleaf.sched_wfq_n_groups_max); 538 printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n", 539 ncap.nonleaf.sched_wfq_weight_max); 540 } else { 541 printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n", 542 ncap.leaf.cman_head_drop_supported); 543 printf("cap.leaf.cman_wred_context_private_supported %" PRId32 544 "\n", ncap.leaf.cman_wred_context_private_supported); 545 printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n", 546 ncap.leaf.cman_wred_context_shared_n_max); 547 } 548 printf("cap.stats_mask %" PRIx64 "\n", ncap.stats_mask); 549 } 550 551 cmdline_parse_inst_t cmd_show_port_tm_node_cap = { 552 .f = cmd_show_port_tm_node_cap_parsed, 553 .data = NULL, 554 .help_str = "Show Port TM Hierarchy node capabilities", 555 .tokens = { 556 (void *)&cmd_show_port_tm_node_cap_show, 557 (void *)&cmd_show_port_tm_node_cap_port, 558 (void *)&cmd_show_port_tm_node_cap_tm, 559 (void *)&cmd_show_port_tm_node_cap_node, 560 (void *)&cmd_show_port_tm_node_cap_cap, 561 (void *)&cmd_show_port_tm_node_cap_port_id, 562 (void *)&cmd_show_port_tm_node_cap_node_id, 563 NULL, 564 }, 565 }; 566 567 /* *** Show Port TM Node Statistics *** */ 568 struct cmd_show_port_tm_node_stats_result { 569 cmdline_fixed_string_t show; 570 cmdline_fixed_string_t port; 571 cmdline_fixed_string_t tm; 572 cmdline_fixed_string_t node; 573 cmdline_fixed_string_t stats; 574 uint16_t port_id; 575 uint32_t node_id; 576 uint32_t clear; 577 }; 578 579 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_show = 580 TOKEN_STRING_INITIALIZER( 581 struct cmd_show_port_tm_node_stats_result, show, "show"); 582 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_port = 583 TOKEN_STRING_INITIALIZER( 584 struct cmd_show_port_tm_node_stats_result, port, "port"); 585 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_tm = 586 TOKEN_STRING_INITIALIZER( 587 struct cmd_show_port_tm_node_stats_result, tm, "tm"); 588 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_node = 589 TOKEN_STRING_INITIALIZER( 590 struct cmd_show_port_tm_node_stats_result, node, "node"); 591 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_stats = 592 TOKEN_STRING_INITIALIZER( 593 struct cmd_show_port_tm_node_stats_result, stats, "stats"); 594 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_port_id = 595 TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_stats_result, 596 port_id, UINT16); 597 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_node_id = 598 TOKEN_NUM_INITIALIZER( 599 struct cmd_show_port_tm_node_stats_result, 600 node_id, UINT32); 601 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_clear = 602 TOKEN_NUM_INITIALIZER( 603 struct cmd_show_port_tm_node_stats_result, clear, UINT32); 604 605 static void cmd_show_port_tm_node_stats_parsed(void *parsed_result, 606 __attribute__((unused)) struct cmdline *cl, 607 __attribute__((unused)) void *data) 608 { 609 struct cmd_show_port_tm_node_stats_result *res = parsed_result; 610 struct rte_tm_node_stats stats; 611 struct rte_tm_error error; 612 uint64_t stats_mask = 0; 613 uint32_t node_id = res->node_id; 614 uint32_t clear = res->clear; 615 portid_t port_id = res->port_id; 616 int ret; 617 618 if (port_id_is_invalid(port_id, ENABLED_WARN)) 619 return; 620 621 memset(&error, 0, sizeof(struct rte_tm_error)); 622 /* Port status */ 623 if (!port_is_started(port_id)) { 624 printf(" Port %u not started (error)\n", port_id); 625 return; 626 } 627 628 memset(&stats, 0, sizeof(struct rte_tm_node_stats)); 629 ret = rte_tm_node_stats_read(port_id, node_id, &stats, 630 &stats_mask, clear, &error); 631 if (ret != 0) { 632 print_err_msg(&error); 633 return; 634 } 635 636 /* Display stats */ 637 if (stats_mask & RTE_TM_STATS_N_PKTS) 638 printf("\tPkts scheduled from node: %" PRIu64 "\n", 639 stats.n_pkts); 640 if (stats_mask & RTE_TM_STATS_N_BYTES) 641 printf("\tBytes scheduled from node: %" PRIu64 "\n", 642 stats.n_bytes); 643 if (stats_mask & RTE_TM_STATS_N_PKTS_GREEN_DROPPED) 644 printf("\tPkts dropped (green): %" PRIu64 "\n", 645 stats.leaf.n_pkts_dropped[RTE_TM_GREEN]); 646 if (stats_mask & RTE_TM_STATS_N_PKTS_YELLOW_DROPPED) 647 printf("\tPkts dropped (yellow): %" PRIu64 "\n", 648 stats.leaf.n_pkts_dropped[RTE_TM_YELLOW]); 649 if (stats_mask & RTE_TM_STATS_N_PKTS_RED_DROPPED) 650 printf("\tPkts dropped (red): %" PRIu64 "\n", 651 stats.leaf.n_pkts_dropped[RTE_TM_RED]); 652 if (stats_mask & RTE_TM_STATS_N_BYTES_GREEN_DROPPED) 653 printf("\tBytes dropped (green): %" PRIu64 "\n", 654 stats.leaf.n_bytes_dropped[RTE_TM_GREEN]); 655 if (stats_mask & RTE_TM_STATS_N_BYTES_YELLOW_DROPPED) 656 printf("\tBytes dropped (yellow): %" PRIu64 "\n", 657 stats.leaf.n_bytes_dropped[RTE_TM_YELLOW]); 658 if (stats_mask & RTE_TM_STATS_N_BYTES_RED_DROPPED) 659 printf("\tBytes dropped (red): %" PRIu64 "\n", 660 stats.leaf.n_bytes_dropped[RTE_TM_RED]); 661 if (stats_mask & RTE_TM_STATS_N_PKTS_QUEUED) 662 printf("\tPkts queued: %" PRIu64 "\n", 663 stats.leaf.n_pkts_queued); 664 if (stats_mask & RTE_TM_STATS_N_BYTES_QUEUED) 665 printf("\tBytes queued: %" PRIu64 "\n", 666 stats.leaf.n_bytes_queued); 667 } 668 669 cmdline_parse_inst_t cmd_show_port_tm_node_stats = { 670 .f = cmd_show_port_tm_node_stats_parsed, 671 .data = NULL, 672 .help_str = "Show port tm node stats", 673 .tokens = { 674 (void *)&cmd_show_port_tm_node_stats_show, 675 (void *)&cmd_show_port_tm_node_stats_port, 676 (void *)&cmd_show_port_tm_node_stats_tm, 677 (void *)&cmd_show_port_tm_node_stats_node, 678 (void *)&cmd_show_port_tm_node_stats_stats, 679 (void *)&cmd_show_port_tm_node_stats_port_id, 680 (void *)&cmd_show_port_tm_node_stats_node_id, 681 (void *)&cmd_show_port_tm_node_stats_clear, 682 NULL, 683 }, 684 }; 685 686 /* *** Show Port TM Node Type *** */ 687 struct cmd_show_port_tm_node_type_result { 688 cmdline_fixed_string_t show; 689 cmdline_fixed_string_t port; 690 cmdline_fixed_string_t tm; 691 cmdline_fixed_string_t node; 692 cmdline_fixed_string_t type; 693 uint16_t port_id; 694 uint32_t node_id; 695 }; 696 697 cmdline_parse_token_string_t cmd_show_port_tm_node_type_show = 698 TOKEN_STRING_INITIALIZER( 699 struct cmd_show_port_tm_node_type_result, show, "show"); 700 cmdline_parse_token_string_t cmd_show_port_tm_node_type_port = 701 TOKEN_STRING_INITIALIZER( 702 struct cmd_show_port_tm_node_type_result, port, "port"); 703 cmdline_parse_token_string_t cmd_show_port_tm_node_type_tm = 704 TOKEN_STRING_INITIALIZER( 705 struct cmd_show_port_tm_node_type_result, tm, "tm"); 706 cmdline_parse_token_string_t cmd_show_port_tm_node_type_node = 707 TOKEN_STRING_INITIALIZER( 708 struct cmd_show_port_tm_node_type_result, node, "node"); 709 cmdline_parse_token_string_t cmd_show_port_tm_node_type_type = 710 TOKEN_STRING_INITIALIZER( 711 struct cmd_show_port_tm_node_type_result, type, "type"); 712 cmdline_parse_token_num_t cmd_show_port_tm_node_type_port_id = 713 TOKEN_NUM_INITIALIZER( 714 struct cmd_show_port_tm_node_type_result, 715 port_id, UINT16); 716 cmdline_parse_token_num_t cmd_show_port_tm_node_type_node_id = 717 TOKEN_NUM_INITIALIZER( 718 struct cmd_show_port_tm_node_type_result, 719 node_id, UINT32); 720 721 static void cmd_show_port_tm_node_type_parsed(void *parsed_result, 722 __attribute__((unused)) struct cmdline *cl, 723 __attribute__((unused)) void *data) 724 { 725 struct cmd_show_port_tm_node_type_result *res = parsed_result; 726 struct rte_tm_error error; 727 uint32_t node_id = res->node_id; 728 portid_t port_id = res->port_id; 729 int ret, is_leaf = 0; 730 731 if (port_id_is_invalid(port_id, ENABLED_WARN)) 732 return; 733 734 memset(&error, 0, sizeof(struct rte_tm_error)); 735 ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error); 736 if (ret != 0) { 737 print_err_msg(&error); 738 return; 739 } 740 741 if (is_leaf == 1) 742 printf("leaf node\n"); 743 else 744 printf("nonleaf node\n"); 745 746 } 747 748 cmdline_parse_inst_t cmd_show_port_tm_node_type = { 749 .f = cmd_show_port_tm_node_type_parsed, 750 .data = NULL, 751 .help_str = "Show port tm node type", 752 .tokens = { 753 (void *)&cmd_show_port_tm_node_type_show, 754 (void *)&cmd_show_port_tm_node_type_port, 755 (void *)&cmd_show_port_tm_node_type_tm, 756 (void *)&cmd_show_port_tm_node_type_node, 757 (void *)&cmd_show_port_tm_node_type_type, 758 (void *)&cmd_show_port_tm_node_type_port_id, 759 (void *)&cmd_show_port_tm_node_type_node_id, 760 NULL, 761 }, 762 }; 763 764 /* *** Add Port TM Private Shaper Profile *** */ 765 struct cmd_add_port_tm_node_shaper_profile_result { 766 cmdline_fixed_string_t add; 767 cmdline_fixed_string_t port; 768 cmdline_fixed_string_t tm; 769 cmdline_fixed_string_t node; 770 cmdline_fixed_string_t shaper; 771 cmdline_fixed_string_t profile; 772 uint16_t port_id; 773 uint32_t shaper_id; 774 uint64_t tb_rate; 775 uint64_t tb_size; 776 uint32_t pktlen_adjust; 777 }; 778 779 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_add = 780 TOKEN_STRING_INITIALIZER( 781 struct cmd_add_port_tm_node_shaper_profile_result, add, "add"); 782 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_port = 783 TOKEN_STRING_INITIALIZER( 784 struct cmd_add_port_tm_node_shaper_profile_result, 785 port, "port"); 786 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_tm = 787 TOKEN_STRING_INITIALIZER( 788 struct cmd_add_port_tm_node_shaper_profile_result, 789 tm, "tm"); 790 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_node = 791 TOKEN_STRING_INITIALIZER( 792 struct cmd_add_port_tm_node_shaper_profile_result, 793 node, "node"); 794 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_shaper = 795 TOKEN_STRING_INITIALIZER( 796 struct cmd_add_port_tm_node_shaper_profile_result, 797 shaper, "shaper"); 798 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_profile = 799 TOKEN_STRING_INITIALIZER( 800 struct cmd_add_port_tm_node_shaper_profile_result, 801 profile, "profile"); 802 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_port_id = 803 TOKEN_NUM_INITIALIZER( 804 struct cmd_add_port_tm_node_shaper_profile_result, 805 port_id, UINT16); 806 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_shaper_id = 807 TOKEN_NUM_INITIALIZER( 808 struct cmd_add_port_tm_node_shaper_profile_result, 809 shaper_id, UINT32); 810 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_tb_rate = 811 TOKEN_NUM_INITIALIZER( 812 struct cmd_add_port_tm_node_shaper_profile_result, 813 tb_rate, UINT64); 814 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_tb_size = 815 TOKEN_NUM_INITIALIZER( 816 struct cmd_add_port_tm_node_shaper_profile_result, 817 tb_size, UINT64); 818 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_pktlen_adjust = 819 TOKEN_NUM_INITIALIZER( 820 struct cmd_add_port_tm_node_shaper_profile_result, 821 pktlen_adjust, UINT32); 822 823 static void cmd_add_port_tm_node_shaper_profile_parsed(void *parsed_result, 824 __attribute__((unused)) struct cmdline *cl, 825 __attribute__((unused)) void *data) 826 { 827 struct cmd_add_port_tm_node_shaper_profile_result *res = parsed_result; 828 struct rte_tm_shaper_params sp; 829 struct rte_tm_error error; 830 uint32_t shaper_id = res->shaper_id; 831 uint32_t pkt_len_adjust = res->pktlen_adjust; 832 portid_t port_id = res->port_id; 833 int ret; 834 835 if (port_id_is_invalid(port_id, ENABLED_WARN)) 836 return; 837 838 /* Private shaper profile params */ 839 memset(&sp, 0, sizeof(struct rte_tm_shaper_params)); 840 memset(&error, 0, sizeof(struct rte_tm_error)); 841 sp.peak.rate = res->tb_rate; 842 sp.peak.size = res->tb_size; 843 sp.pkt_length_adjust = pkt_len_adjust; 844 845 ret = rte_tm_shaper_profile_add(port_id, shaper_id, &sp, &error); 846 if (ret != 0) { 847 print_err_msg(&error); 848 return; 849 } 850 } 851 852 cmdline_parse_inst_t cmd_add_port_tm_node_shaper_profile = { 853 .f = cmd_add_port_tm_node_shaper_profile_parsed, 854 .data = NULL, 855 .help_str = "Add port tm node private shaper profile", 856 .tokens = { 857 (void *)&cmd_add_port_tm_node_shaper_profile_add, 858 (void *)&cmd_add_port_tm_node_shaper_profile_port, 859 (void *)&cmd_add_port_tm_node_shaper_profile_tm, 860 (void *)&cmd_add_port_tm_node_shaper_profile_node, 861 (void *)&cmd_add_port_tm_node_shaper_profile_shaper, 862 (void *)&cmd_add_port_tm_node_shaper_profile_profile, 863 (void *)&cmd_add_port_tm_node_shaper_profile_port_id, 864 (void *)&cmd_add_port_tm_node_shaper_profile_shaper_id, 865 (void *)&cmd_add_port_tm_node_shaper_profile_tb_rate, 866 (void *)&cmd_add_port_tm_node_shaper_profile_tb_size, 867 (void *)&cmd_add_port_tm_node_shaper_profile_pktlen_adjust, 868 NULL, 869 }, 870 }; 871 872 /* *** Delete Port TM Private Shaper Profile *** */ 873 struct cmd_del_port_tm_node_shaper_profile_result { 874 cmdline_fixed_string_t del; 875 cmdline_fixed_string_t port; 876 cmdline_fixed_string_t tm; 877 cmdline_fixed_string_t node; 878 cmdline_fixed_string_t shaper; 879 cmdline_fixed_string_t profile; 880 uint16_t port_id; 881 uint32_t shaper_id; 882 }; 883 884 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_del = 885 TOKEN_STRING_INITIALIZER( 886 struct cmd_del_port_tm_node_shaper_profile_result, del, "del"); 887 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_port = 888 TOKEN_STRING_INITIALIZER( 889 struct cmd_del_port_tm_node_shaper_profile_result, 890 port, "port"); 891 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_tm = 892 TOKEN_STRING_INITIALIZER( 893 struct cmd_del_port_tm_node_shaper_profile_result, tm, "tm"); 894 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_node = 895 TOKEN_STRING_INITIALIZER( 896 struct cmd_del_port_tm_node_shaper_profile_result, 897 node, "node"); 898 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_shaper = 899 TOKEN_STRING_INITIALIZER( 900 struct cmd_del_port_tm_node_shaper_profile_result, 901 shaper, "shaper"); 902 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_profile = 903 TOKEN_STRING_INITIALIZER( 904 struct cmd_del_port_tm_node_shaper_profile_result, 905 profile, "profile"); 906 cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_port_id = 907 TOKEN_NUM_INITIALIZER( 908 struct cmd_del_port_tm_node_shaper_profile_result, 909 port_id, UINT16); 910 cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_shaper_id = 911 TOKEN_NUM_INITIALIZER( 912 struct cmd_del_port_tm_node_shaper_profile_result, 913 shaper_id, UINT32); 914 915 static void cmd_del_port_tm_node_shaper_profile_parsed(void *parsed_result, 916 __attribute__((unused)) struct cmdline *cl, 917 __attribute__((unused)) void *data) 918 { 919 struct cmd_del_port_tm_node_shaper_profile_result *res = parsed_result; 920 struct rte_tm_error error; 921 uint32_t shaper_id = res->shaper_id; 922 portid_t port_id = res->port_id; 923 int ret; 924 925 if (port_id_is_invalid(port_id, ENABLED_WARN)) 926 return; 927 928 memset(&error, 0, sizeof(struct rte_tm_error)); 929 ret = rte_tm_shaper_profile_delete(port_id, shaper_id, &error); 930 if (ret != 0) { 931 print_err_msg(&error); 932 return; 933 } 934 } 935 936 cmdline_parse_inst_t cmd_del_port_tm_node_shaper_profile = { 937 .f = cmd_del_port_tm_node_shaper_profile_parsed, 938 .data = NULL, 939 .help_str = "Delete port tm node private shaper profile", 940 .tokens = { 941 (void *)&cmd_del_port_tm_node_shaper_profile_del, 942 (void *)&cmd_del_port_tm_node_shaper_profile_port, 943 (void *)&cmd_del_port_tm_node_shaper_profile_tm, 944 (void *)&cmd_del_port_tm_node_shaper_profile_node, 945 (void *)&cmd_del_port_tm_node_shaper_profile_shaper, 946 (void *)&cmd_del_port_tm_node_shaper_profile_profile, 947 (void *)&cmd_del_port_tm_node_shaper_profile_port_id, 948 (void *)&cmd_del_port_tm_node_shaper_profile_shaper_id, 949 NULL, 950 }, 951 }; 952 953 /* *** Add/Update Port TM shared Shaper *** */ 954 struct cmd_add_port_tm_node_shared_shaper_result { 955 cmdline_fixed_string_t cmd_type; 956 cmdline_fixed_string_t port; 957 cmdline_fixed_string_t tm; 958 cmdline_fixed_string_t node; 959 cmdline_fixed_string_t shared; 960 cmdline_fixed_string_t shaper; 961 uint16_t port_id; 962 uint32_t shared_shaper_id; 963 uint32_t shaper_profile_id; 964 }; 965 966 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_cmd_type = 967 TOKEN_STRING_INITIALIZER( 968 struct cmd_add_port_tm_node_shared_shaper_result, 969 cmd_type, "add#set"); 970 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_port = 971 TOKEN_STRING_INITIALIZER( 972 struct cmd_add_port_tm_node_shared_shaper_result, port, "port"); 973 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_tm = 974 TOKEN_STRING_INITIALIZER( 975 struct cmd_add_port_tm_node_shared_shaper_result, tm, "tm"); 976 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_node = 977 TOKEN_STRING_INITIALIZER( 978 struct cmd_add_port_tm_node_shared_shaper_result, node, "node"); 979 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shared = 980 TOKEN_STRING_INITIALIZER( 981 struct cmd_add_port_tm_node_shared_shaper_result, 982 shared, "shared"); 983 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shaper = 984 TOKEN_STRING_INITIALIZER( 985 struct cmd_add_port_tm_node_shared_shaper_result, 986 shaper, "shaper"); 987 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_port_id = 988 TOKEN_NUM_INITIALIZER( 989 struct cmd_add_port_tm_node_shared_shaper_result, 990 port_id, UINT16); 991 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shared_shaper_id = 992 TOKEN_NUM_INITIALIZER( 993 struct cmd_add_port_tm_node_shared_shaper_result, 994 shared_shaper_id, UINT32); 995 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shaper_profile_id = 996 TOKEN_NUM_INITIALIZER( 997 struct cmd_add_port_tm_node_shared_shaper_result, 998 shaper_profile_id, UINT32); 999 1000 static void cmd_add_port_tm_node_shared_shaper_parsed(void *parsed_result, 1001 __attribute__((unused)) struct cmdline *cl, 1002 __attribute__((unused)) void *data) 1003 { 1004 struct cmd_add_port_tm_node_shared_shaper_result *res = parsed_result; 1005 struct rte_tm_error error; 1006 uint32_t shared_shaper_id = res->shared_shaper_id; 1007 uint32_t shaper_profile_id = res->shaper_profile_id; 1008 portid_t port_id = res->port_id; 1009 int ret; 1010 1011 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1012 return; 1013 1014 memset(&error, 0, sizeof(struct rte_tm_error)); 1015 /* Command type: add */ 1016 if ((strcmp(res->cmd_type, "add") == 0) && 1017 (port_is_started(port_id))) { 1018 printf(" Port %u not stopped (error)\n", port_id); 1019 return; 1020 } 1021 1022 /* Command type: set (update) */ 1023 if ((strcmp(res->cmd_type, "set") == 0) && 1024 (!port_is_started(port_id))) { 1025 printf(" Port %u not started (error)\n", port_id); 1026 return; 1027 } 1028 1029 ret = rte_tm_shared_shaper_add_update(port_id, shared_shaper_id, 1030 shaper_profile_id, &error); 1031 if (ret != 0) { 1032 print_err_msg(&error); 1033 return; 1034 } 1035 } 1036 1037 cmdline_parse_inst_t cmd_add_port_tm_node_shared_shaper = { 1038 .f = cmd_add_port_tm_node_shared_shaper_parsed, 1039 .data = NULL, 1040 .help_str = "add/update port tm node shared shaper", 1041 .tokens = { 1042 (void *)&cmd_add_port_tm_node_shared_shaper_cmd_type, 1043 (void *)&cmd_add_port_tm_node_shared_shaper_port, 1044 (void *)&cmd_add_port_tm_node_shared_shaper_tm, 1045 (void *)&cmd_add_port_tm_node_shared_shaper_node, 1046 (void *)&cmd_add_port_tm_node_shared_shaper_shared, 1047 (void *)&cmd_add_port_tm_node_shared_shaper_shaper, 1048 (void *)&cmd_add_port_tm_node_shared_shaper_port_id, 1049 (void *)&cmd_add_port_tm_node_shared_shaper_shared_shaper_id, 1050 (void *)&cmd_add_port_tm_node_shared_shaper_shaper_profile_id, 1051 NULL, 1052 }, 1053 }; 1054 1055 /* *** Delete Port TM shared Shaper *** */ 1056 struct cmd_del_port_tm_node_shared_shaper_result { 1057 cmdline_fixed_string_t del; 1058 cmdline_fixed_string_t port; 1059 cmdline_fixed_string_t tm; 1060 cmdline_fixed_string_t node; 1061 cmdline_fixed_string_t shared; 1062 cmdline_fixed_string_t shaper; 1063 uint16_t port_id; 1064 uint32_t shared_shaper_id; 1065 }; 1066 1067 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_del = 1068 TOKEN_STRING_INITIALIZER( 1069 struct cmd_del_port_tm_node_shared_shaper_result, del, "del"); 1070 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_port = 1071 TOKEN_STRING_INITIALIZER( 1072 struct cmd_del_port_tm_node_shared_shaper_result, port, "port"); 1073 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_tm = 1074 TOKEN_STRING_INITIALIZER( 1075 struct cmd_del_port_tm_node_shared_shaper_result, tm, "tm"); 1076 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_node = 1077 TOKEN_STRING_INITIALIZER( 1078 struct cmd_del_port_tm_node_shared_shaper_result, node, "node"); 1079 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shared = 1080 TOKEN_STRING_INITIALIZER( 1081 struct cmd_del_port_tm_node_shared_shaper_result, 1082 shared, "shared"); 1083 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shaper = 1084 TOKEN_STRING_INITIALIZER( 1085 struct cmd_del_port_tm_node_shared_shaper_result, 1086 shaper, "shaper"); 1087 cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_port_id = 1088 TOKEN_NUM_INITIALIZER( 1089 struct cmd_del_port_tm_node_shared_shaper_result, 1090 port_id, UINT16); 1091 cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_shared_shaper_id = 1092 TOKEN_NUM_INITIALIZER( 1093 struct cmd_del_port_tm_node_shared_shaper_result, 1094 shared_shaper_id, UINT32); 1095 1096 static void cmd_del_port_tm_node_shared_shaper_parsed(void *parsed_result, 1097 __attribute__((unused)) struct cmdline *cl, 1098 __attribute__((unused)) void *data) 1099 { 1100 struct cmd_del_port_tm_node_shared_shaper_result *res = parsed_result; 1101 struct rte_tm_error error; 1102 uint32_t shared_shaper_id = res->shared_shaper_id; 1103 portid_t port_id = res->port_id; 1104 int ret; 1105 1106 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1107 return; 1108 1109 memset(&error, 0, sizeof(struct rte_tm_error)); 1110 ret = rte_tm_shared_shaper_delete(port_id, shared_shaper_id, &error); 1111 if (ret != 0) { 1112 print_err_msg(&error); 1113 return; 1114 } 1115 } 1116 1117 cmdline_parse_inst_t cmd_del_port_tm_node_shared_shaper = { 1118 .f = cmd_del_port_tm_node_shared_shaper_parsed, 1119 .data = NULL, 1120 .help_str = "delete port tm node shared shaper", 1121 .tokens = { 1122 (void *)&cmd_del_port_tm_node_shared_shaper_del, 1123 (void *)&cmd_del_port_tm_node_shared_shaper_port, 1124 (void *)&cmd_del_port_tm_node_shared_shaper_tm, 1125 (void *)&cmd_del_port_tm_node_shared_shaper_node, 1126 (void *)&cmd_del_port_tm_node_shared_shaper_shared, 1127 (void *)&cmd_del_port_tm_node_shared_shaper_shaper, 1128 (void *)&cmd_del_port_tm_node_shared_shaper_port_id, 1129 (void *)&cmd_del_port_tm_node_shared_shaper_shared_shaper_id, 1130 NULL, 1131 }, 1132 }; 1133 1134 /* *** Add Port TM Node WRED Profile *** */ 1135 struct cmd_add_port_tm_node_wred_profile_result { 1136 cmdline_fixed_string_t add; 1137 cmdline_fixed_string_t port; 1138 cmdline_fixed_string_t tm; 1139 cmdline_fixed_string_t node; 1140 cmdline_fixed_string_t wred; 1141 cmdline_fixed_string_t profile; 1142 uint16_t port_id; 1143 uint32_t wred_profile_id; 1144 cmdline_fixed_string_t color_g; 1145 uint16_t min_th_g; 1146 uint16_t max_th_g; 1147 uint16_t maxp_inv_g; 1148 uint16_t wq_log2_g; 1149 cmdline_fixed_string_t color_y; 1150 uint16_t min_th_y; 1151 uint16_t max_th_y; 1152 uint16_t maxp_inv_y; 1153 uint16_t wq_log2_y; 1154 cmdline_fixed_string_t color_r; 1155 uint16_t min_th_r; 1156 uint16_t max_th_r; 1157 uint16_t maxp_inv_r; 1158 uint16_t wq_log2_r; 1159 }; 1160 1161 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_add = 1162 TOKEN_STRING_INITIALIZER( 1163 struct cmd_add_port_tm_node_wred_profile_result, add, "add"); 1164 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_port = 1165 TOKEN_STRING_INITIALIZER( 1166 struct cmd_add_port_tm_node_wred_profile_result, port, "port"); 1167 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_tm = 1168 TOKEN_STRING_INITIALIZER( 1169 struct cmd_add_port_tm_node_wred_profile_result, tm, "tm"); 1170 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_node = 1171 TOKEN_STRING_INITIALIZER( 1172 struct cmd_add_port_tm_node_wred_profile_result, node, "node"); 1173 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_wred = 1174 TOKEN_STRING_INITIALIZER( 1175 struct cmd_add_port_tm_node_wred_profile_result, wred, "wred"); 1176 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_profile = 1177 TOKEN_STRING_INITIALIZER( 1178 struct cmd_add_port_tm_node_wred_profile_result, 1179 profile, "profile"); 1180 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_port_id = 1181 TOKEN_NUM_INITIALIZER( 1182 struct cmd_add_port_tm_node_wred_profile_result, 1183 port_id, UINT16); 1184 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wred_profile_id = 1185 TOKEN_NUM_INITIALIZER( 1186 struct cmd_add_port_tm_node_wred_profile_result, 1187 wred_profile_id, UINT32); 1188 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_g = 1189 TOKEN_STRING_INITIALIZER( 1190 struct cmd_add_port_tm_node_wred_profile_result, 1191 color_g, "G#g"); 1192 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_g = 1193 TOKEN_NUM_INITIALIZER( 1194 struct cmd_add_port_tm_node_wred_profile_result, 1195 min_th_g, UINT16); 1196 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_g = 1197 TOKEN_NUM_INITIALIZER( 1198 struct cmd_add_port_tm_node_wred_profile_result, 1199 max_th_g, UINT16); 1200 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_g = 1201 TOKEN_NUM_INITIALIZER( 1202 struct cmd_add_port_tm_node_wred_profile_result, 1203 maxp_inv_g, UINT16); 1204 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_g = 1205 TOKEN_NUM_INITIALIZER( 1206 struct cmd_add_port_tm_node_wred_profile_result, 1207 wq_log2_g, UINT16); 1208 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_y = 1209 TOKEN_STRING_INITIALIZER( 1210 struct cmd_add_port_tm_node_wred_profile_result, 1211 color_y, "Y#y"); 1212 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_y = 1213 TOKEN_NUM_INITIALIZER( 1214 struct cmd_add_port_tm_node_wred_profile_result, 1215 min_th_y, UINT16); 1216 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_y = 1217 TOKEN_NUM_INITIALIZER( 1218 struct cmd_add_port_tm_node_wred_profile_result, 1219 max_th_y, UINT16); 1220 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_y = 1221 TOKEN_NUM_INITIALIZER( 1222 struct cmd_add_port_tm_node_wred_profile_result, 1223 maxp_inv_y, UINT16); 1224 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_y = 1225 TOKEN_NUM_INITIALIZER( 1226 struct cmd_add_port_tm_node_wred_profile_result, 1227 wq_log2_y, UINT16); 1228 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_r = 1229 TOKEN_STRING_INITIALIZER( 1230 struct cmd_add_port_tm_node_wred_profile_result, 1231 color_r, "R#r"); 1232 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_r = 1233 TOKEN_NUM_INITIALIZER( 1234 struct cmd_add_port_tm_node_wred_profile_result, 1235 min_th_r, UINT16); 1236 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_r = 1237 TOKEN_NUM_INITIALIZER( 1238 struct cmd_add_port_tm_node_wred_profile_result, 1239 max_th_r, UINT16); 1240 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_r = 1241 TOKEN_NUM_INITIALIZER( 1242 struct cmd_add_port_tm_node_wred_profile_result, 1243 maxp_inv_r, UINT16); 1244 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_r = 1245 TOKEN_NUM_INITIALIZER( 1246 struct cmd_add_port_tm_node_wred_profile_result, 1247 wq_log2_r, UINT16); 1248 1249 1250 static void cmd_add_port_tm_node_wred_profile_parsed(void *parsed_result, 1251 __attribute__((unused)) struct cmdline *cl, 1252 __attribute__((unused)) void *data) 1253 { 1254 struct cmd_add_port_tm_node_wred_profile_result *res = parsed_result; 1255 struct rte_tm_wred_params wp; 1256 enum rte_tm_color color; 1257 struct rte_tm_error error; 1258 uint32_t wred_profile_id = res->wred_profile_id; 1259 portid_t port_id = res->port_id; 1260 int ret; 1261 1262 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1263 return; 1264 1265 memset(&wp, 0, sizeof(struct rte_tm_wred_params)); 1266 memset(&error, 0, sizeof(struct rte_tm_error)); 1267 1268 /* WRED Params (Green Color)*/ 1269 color = RTE_TM_GREEN; 1270 wp.red_params[color].min_th = res->min_th_g; 1271 wp.red_params[color].max_th = res->max_th_g; 1272 wp.red_params[color].maxp_inv = res->maxp_inv_g; 1273 wp.red_params[color].wq_log2 = res->wq_log2_g; 1274 1275 1276 /* WRED Params (Yellow Color)*/ 1277 color = RTE_TM_YELLOW; 1278 wp.red_params[color].min_th = res->min_th_y; 1279 wp.red_params[color].max_th = res->max_th_y; 1280 wp.red_params[color].maxp_inv = res->maxp_inv_y; 1281 wp.red_params[color].wq_log2 = res->wq_log2_y; 1282 1283 /* WRED Params (Red Color)*/ 1284 color = RTE_TM_RED; 1285 wp.red_params[color].min_th = res->min_th_r; 1286 wp.red_params[color].max_th = res->max_th_r; 1287 wp.red_params[color].maxp_inv = res->maxp_inv_r; 1288 wp.red_params[color].wq_log2 = res->wq_log2_r; 1289 1290 ret = rte_tm_wred_profile_add(port_id, wred_profile_id, &wp, &error); 1291 if (ret != 0) { 1292 print_err_msg(&error); 1293 return; 1294 } 1295 } 1296 1297 cmdline_parse_inst_t cmd_add_port_tm_node_wred_profile = { 1298 .f = cmd_add_port_tm_node_wred_profile_parsed, 1299 .data = NULL, 1300 .help_str = "Add port tm node wred profile", 1301 .tokens = { 1302 (void *)&cmd_add_port_tm_node_wred_profile_add, 1303 (void *)&cmd_add_port_tm_node_wred_profile_port, 1304 (void *)&cmd_add_port_tm_node_wred_profile_tm, 1305 (void *)&cmd_add_port_tm_node_wred_profile_node, 1306 (void *)&cmd_add_port_tm_node_wred_profile_wred, 1307 (void *)&cmd_add_port_tm_node_wred_profile_profile, 1308 (void *)&cmd_add_port_tm_node_wred_profile_port_id, 1309 (void *)&cmd_add_port_tm_node_wred_profile_wred_profile_id, 1310 (void *)&cmd_add_port_tm_node_wred_profile_color_g, 1311 (void *)&cmd_add_port_tm_node_wred_profile_min_th_g, 1312 (void *)&cmd_add_port_tm_node_wred_profile_max_th_g, 1313 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_g, 1314 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_g, 1315 (void *)&cmd_add_port_tm_node_wred_profile_color_y, 1316 (void *)&cmd_add_port_tm_node_wred_profile_min_th_y, 1317 (void *)&cmd_add_port_tm_node_wred_profile_max_th_y, 1318 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_y, 1319 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_y, 1320 (void *)&cmd_add_port_tm_node_wred_profile_color_r, 1321 (void *)&cmd_add_port_tm_node_wred_profile_min_th_r, 1322 (void *)&cmd_add_port_tm_node_wred_profile_max_th_r, 1323 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_r, 1324 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_r, 1325 NULL, 1326 }, 1327 }; 1328 1329 /* *** Delete Port TM node WRED Profile *** */ 1330 struct cmd_del_port_tm_node_wred_profile_result { 1331 cmdline_fixed_string_t del; 1332 cmdline_fixed_string_t port; 1333 cmdline_fixed_string_t tm; 1334 cmdline_fixed_string_t node; 1335 cmdline_fixed_string_t wred; 1336 cmdline_fixed_string_t profile; 1337 uint16_t port_id; 1338 uint32_t wred_profile_id; 1339 }; 1340 1341 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_del = 1342 TOKEN_STRING_INITIALIZER( 1343 struct cmd_del_port_tm_node_wred_profile_result, del, "del"); 1344 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_port = 1345 TOKEN_STRING_INITIALIZER( 1346 struct cmd_del_port_tm_node_wred_profile_result, port, "port"); 1347 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_tm = 1348 TOKEN_STRING_INITIALIZER( 1349 struct cmd_del_port_tm_node_wred_profile_result, tm, "tm"); 1350 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_node = 1351 TOKEN_STRING_INITIALIZER( 1352 struct cmd_del_port_tm_node_wred_profile_result, node, "node"); 1353 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_wred = 1354 TOKEN_STRING_INITIALIZER( 1355 struct cmd_del_port_tm_node_wred_profile_result, wred, "wred"); 1356 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_profile = 1357 TOKEN_STRING_INITIALIZER( 1358 struct cmd_del_port_tm_node_wred_profile_result, 1359 profile, "profile"); 1360 cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_port_id = 1361 TOKEN_NUM_INITIALIZER( 1362 struct cmd_del_port_tm_node_wred_profile_result, 1363 port_id, UINT16); 1364 cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_wred_profile_id = 1365 TOKEN_NUM_INITIALIZER( 1366 struct cmd_del_port_tm_node_wred_profile_result, 1367 wred_profile_id, UINT32); 1368 1369 static void cmd_del_port_tm_node_wred_profile_parsed(void *parsed_result, 1370 __attribute__((unused)) struct cmdline *cl, 1371 __attribute__((unused)) void *data) 1372 { 1373 struct cmd_del_port_tm_node_wred_profile_result *res = parsed_result; 1374 struct rte_tm_error error; 1375 uint32_t wred_profile_id = res->wred_profile_id; 1376 portid_t port_id = res->port_id; 1377 int ret; 1378 1379 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1380 return; 1381 1382 memset(&error, 0, sizeof(struct rte_tm_error)); 1383 ret = rte_tm_wred_profile_delete(port_id, wred_profile_id, &error); 1384 if (ret != 0) { 1385 print_err_msg(&error); 1386 return; 1387 } 1388 } 1389 1390 cmdline_parse_inst_t cmd_del_port_tm_node_wred_profile = { 1391 .f = cmd_del_port_tm_node_wred_profile_parsed, 1392 .data = NULL, 1393 .help_str = "Delete port tm node wred profile", 1394 .tokens = { 1395 (void *)&cmd_del_port_tm_node_wred_profile_del, 1396 (void *)&cmd_del_port_tm_node_wred_profile_port, 1397 (void *)&cmd_del_port_tm_node_wred_profile_tm, 1398 (void *)&cmd_del_port_tm_node_wred_profile_node, 1399 (void *)&cmd_del_port_tm_node_wred_profile_wred, 1400 (void *)&cmd_del_port_tm_node_wred_profile_profile, 1401 (void *)&cmd_del_port_tm_node_wred_profile_port_id, 1402 (void *)&cmd_del_port_tm_node_wred_profile_wred_profile_id, 1403 NULL, 1404 }, 1405 }; 1406 1407 /* *** Update Port TM Node Shaper profile *** */ 1408 struct cmd_set_port_tm_node_shaper_profile_result { 1409 cmdline_fixed_string_t set; 1410 cmdline_fixed_string_t port; 1411 cmdline_fixed_string_t tm; 1412 cmdline_fixed_string_t node; 1413 cmdline_fixed_string_t shaper; 1414 cmdline_fixed_string_t profile; 1415 uint16_t port_id; 1416 uint32_t node_id; 1417 uint32_t shaper_profile_id; 1418 }; 1419 1420 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_set = 1421 TOKEN_STRING_INITIALIZER( 1422 struct cmd_set_port_tm_node_shaper_profile_result, set, "set"); 1423 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_port = 1424 TOKEN_STRING_INITIALIZER( 1425 struct cmd_set_port_tm_node_shaper_profile_result, 1426 port, "port"); 1427 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_tm = 1428 TOKEN_STRING_INITIALIZER( 1429 struct cmd_set_port_tm_node_shaper_profile_result, tm, "tm"); 1430 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_node = 1431 TOKEN_STRING_INITIALIZER( 1432 struct cmd_set_port_tm_node_shaper_profile_result, 1433 node, "node"); 1434 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_shaper = 1435 TOKEN_STRING_INITIALIZER( 1436 struct cmd_set_port_tm_node_shaper_profile_result, 1437 shaper, "shaper"); 1438 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_profile = 1439 TOKEN_STRING_INITIALIZER( 1440 struct cmd_set_port_tm_node_shaper_profile_result, 1441 profile, "profile"); 1442 cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_port_id = 1443 TOKEN_NUM_INITIALIZER( 1444 struct cmd_set_port_tm_node_shaper_profile_result, 1445 port_id, UINT16); 1446 cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_node_id = 1447 TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_shaper_profile_result, 1448 node_id, UINT32); 1449 cmdline_parse_token_num_t 1450 cmd_set_port_tm_node_shaper_shaper_profile_profile_id = 1451 TOKEN_NUM_INITIALIZER( 1452 struct cmd_set_port_tm_node_shaper_profile_result, 1453 shaper_profile_id, UINT32); 1454 1455 static void cmd_set_port_tm_node_shaper_profile_parsed(void *parsed_result, 1456 __attribute__((unused)) struct cmdline *cl, 1457 __attribute__((unused)) void *data) 1458 { 1459 struct cmd_set_port_tm_node_shaper_profile_result *res = parsed_result; 1460 struct rte_tm_error error; 1461 uint32_t node_id = res->node_id; 1462 uint32_t shaper_profile_id = res->shaper_profile_id; 1463 portid_t port_id = res->port_id; 1464 int ret; 1465 1466 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1467 return; 1468 1469 memset(&error, 0, sizeof(struct rte_tm_error)); 1470 /* Port status */ 1471 if (!port_is_started(port_id)) { 1472 printf(" Port %u not started (error)\n", port_id); 1473 return; 1474 } 1475 1476 ret = rte_tm_node_shaper_update(port_id, node_id, 1477 shaper_profile_id, &error); 1478 if (ret != 0) { 1479 print_err_msg(&error); 1480 return; 1481 } 1482 } 1483 1484 cmdline_parse_inst_t cmd_set_port_tm_node_shaper_profile = { 1485 .f = cmd_set_port_tm_node_shaper_profile_parsed, 1486 .data = NULL, 1487 .help_str = "Set port tm node shaper profile", 1488 .tokens = { 1489 (void *)&cmd_set_port_tm_node_shaper_profile_set, 1490 (void *)&cmd_set_port_tm_node_shaper_profile_port, 1491 (void *)&cmd_set_port_tm_node_shaper_profile_tm, 1492 (void *)&cmd_set_port_tm_node_shaper_profile_node, 1493 (void *)&cmd_set_port_tm_node_shaper_profile_shaper, 1494 (void *)&cmd_set_port_tm_node_shaper_profile_profile, 1495 (void *)&cmd_set_port_tm_node_shaper_profile_port_id, 1496 (void *)&cmd_set_port_tm_node_shaper_profile_node_id, 1497 (void *)&cmd_set_port_tm_node_shaper_shaper_profile_profile_id, 1498 NULL, 1499 }, 1500 }; 1501 1502 /* *** Add Port TM nonleaf node *** */ 1503 struct cmd_add_port_tm_nonleaf_node_result { 1504 cmdline_fixed_string_t add; 1505 cmdline_fixed_string_t port; 1506 cmdline_fixed_string_t tm; 1507 cmdline_fixed_string_t nonleaf; 1508 cmdline_fixed_string_t node; 1509 uint16_t port_id; 1510 uint32_t node_id; 1511 int32_t parent_node_id; 1512 uint32_t priority; 1513 uint32_t weight; 1514 uint32_t level_id; 1515 int32_t shaper_profile_id; 1516 uint32_t n_sp_priorities; 1517 uint64_t stats_mask; 1518 cmdline_multi_string_t multi_shared_shaper_id; 1519 }; 1520 1521 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_add = 1522 TOKEN_STRING_INITIALIZER( 1523 struct cmd_add_port_tm_nonleaf_node_result, add, "add"); 1524 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_port = 1525 TOKEN_STRING_INITIALIZER( 1526 struct cmd_add_port_tm_nonleaf_node_result, port, "port"); 1527 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_tm = 1528 TOKEN_STRING_INITIALIZER( 1529 struct cmd_add_port_tm_nonleaf_node_result, tm, "tm"); 1530 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_nonleaf = 1531 TOKEN_STRING_INITIALIZER( 1532 struct cmd_add_port_tm_nonleaf_node_result, nonleaf, "nonleaf"); 1533 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_node = 1534 TOKEN_STRING_INITIALIZER( 1535 struct cmd_add_port_tm_nonleaf_node_result, node, "node"); 1536 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_port_id = 1537 TOKEN_NUM_INITIALIZER( 1538 struct cmd_add_port_tm_nonleaf_node_result, 1539 port_id, UINT16); 1540 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_node_id = 1541 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1542 node_id, UINT32); 1543 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_parent_node_id = 1544 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1545 parent_node_id, INT32); 1546 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_priority = 1547 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1548 priority, UINT32); 1549 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_weight = 1550 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1551 weight, UINT32); 1552 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_level_id = 1553 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1554 level_id, UINT32); 1555 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_shaper_profile_id = 1556 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1557 shaper_profile_id, INT32); 1558 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_n_sp_priorities = 1559 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1560 n_sp_priorities, UINT32); 1561 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_stats_mask = 1562 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1563 stats_mask, UINT64); 1564 cmdline_parse_token_string_t 1565 cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id = 1566 TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1567 multi_shared_shaper_id, TOKEN_STRING_MULTI); 1568 1569 static void cmd_add_port_tm_nonleaf_node_parsed(void *parsed_result, 1570 __attribute__((unused)) struct cmdline *cl, 1571 __attribute__((unused)) void *data) 1572 { 1573 struct cmd_add_port_tm_nonleaf_node_result *res = parsed_result; 1574 struct rte_tm_error error; 1575 struct rte_tm_node_params np; 1576 uint32_t *shared_shaper_id; 1577 uint32_t parent_node_id, n_shared_shapers = 0; 1578 char *s_str = res->multi_shared_shaper_id; 1579 portid_t port_id = res->port_id; 1580 int ret; 1581 1582 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1583 return; 1584 1585 memset(&np, 0, sizeof(struct rte_tm_node_params)); 1586 memset(&error, 0, sizeof(struct rte_tm_error)); 1587 1588 /* Node parameters */ 1589 if (res->parent_node_id < 0) 1590 parent_node_id = UINT32_MAX; 1591 else 1592 parent_node_id = res->parent_node_id; 1593 1594 shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS * 1595 sizeof(uint32_t)); 1596 if (shared_shaper_id == NULL) { 1597 printf(" Memory not allocated for shared shapers (error)\n"); 1598 return; 1599 } 1600 1601 /* Parse multi shared shaper id string */ 1602 ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id); 1603 if (ret) { 1604 printf(" Shared shapers params string parse error\n"); 1605 free(shared_shaper_id); 1606 return; 1607 } 1608 1609 if (res->shaper_profile_id < 0) 1610 np.shaper_profile_id = UINT32_MAX; 1611 else 1612 np.shaper_profile_id = res->shaper_profile_id; 1613 1614 np.n_shared_shapers = n_shared_shapers; 1615 if (np.n_shared_shapers) { 1616 np.shared_shaper_id = &shared_shaper_id[0]; 1617 } else { 1618 free(shared_shaper_id); 1619 shared_shaper_id = NULL; 1620 } 1621 1622 np.nonleaf.n_sp_priorities = res->n_sp_priorities; 1623 np.stats_mask = res->stats_mask; 1624 np.nonleaf.wfq_weight_mode = NULL; 1625 1626 ret = rte_tm_node_add(port_id, res->node_id, parent_node_id, 1627 res->priority, res->weight, res->level_id, 1628 &np, &error); 1629 if (ret != 0) { 1630 print_err_msg(&error); 1631 free(shared_shaper_id); 1632 return; 1633 } 1634 } 1635 1636 cmdline_parse_inst_t cmd_add_port_tm_nonleaf_node = { 1637 .f = cmd_add_port_tm_nonleaf_node_parsed, 1638 .data = NULL, 1639 .help_str = "Add port tm nonleaf node", 1640 .tokens = { 1641 (void *)&cmd_add_port_tm_nonleaf_node_add, 1642 (void *)&cmd_add_port_tm_nonleaf_node_port, 1643 (void *)&cmd_add_port_tm_nonleaf_node_tm, 1644 (void *)&cmd_add_port_tm_nonleaf_node_nonleaf, 1645 (void *)&cmd_add_port_tm_nonleaf_node_node, 1646 (void *)&cmd_add_port_tm_nonleaf_node_port_id, 1647 (void *)&cmd_add_port_tm_nonleaf_node_node_id, 1648 (void *)&cmd_add_port_tm_nonleaf_node_parent_node_id, 1649 (void *)&cmd_add_port_tm_nonleaf_node_priority, 1650 (void *)&cmd_add_port_tm_nonleaf_node_weight, 1651 (void *)&cmd_add_port_tm_nonleaf_node_level_id, 1652 (void *)&cmd_add_port_tm_nonleaf_node_shaper_profile_id, 1653 (void *)&cmd_add_port_tm_nonleaf_node_n_sp_priorities, 1654 (void *)&cmd_add_port_tm_nonleaf_node_stats_mask, 1655 (void *)&cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id, 1656 NULL, 1657 }, 1658 }; 1659 1660 /* *** Add Port TM leaf node *** */ 1661 struct cmd_add_port_tm_leaf_node_result { 1662 cmdline_fixed_string_t add; 1663 cmdline_fixed_string_t port; 1664 cmdline_fixed_string_t tm; 1665 cmdline_fixed_string_t leaf; 1666 cmdline_fixed_string_t node; 1667 uint16_t port_id; 1668 uint32_t node_id; 1669 int32_t parent_node_id; 1670 uint32_t priority; 1671 uint32_t weight; 1672 uint32_t level_id; 1673 int32_t shaper_profile_id; 1674 uint32_t cman_mode; 1675 uint32_t wred_profile_id; 1676 uint64_t stats_mask; 1677 cmdline_multi_string_t multi_shared_shaper_id; 1678 }; 1679 1680 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_add = 1681 TOKEN_STRING_INITIALIZER( 1682 struct cmd_add_port_tm_leaf_node_result, add, "add"); 1683 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_port = 1684 TOKEN_STRING_INITIALIZER( 1685 struct cmd_add_port_tm_leaf_node_result, port, "port"); 1686 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_tm = 1687 TOKEN_STRING_INITIALIZER( 1688 struct cmd_add_port_tm_leaf_node_result, tm, "tm"); 1689 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_nonleaf = 1690 TOKEN_STRING_INITIALIZER( 1691 struct cmd_add_port_tm_leaf_node_result, leaf, "leaf"); 1692 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_node = 1693 TOKEN_STRING_INITIALIZER( 1694 struct cmd_add_port_tm_leaf_node_result, node, "node"); 1695 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_port_id = 1696 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1697 port_id, UINT16); 1698 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_node_id = 1699 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1700 node_id, UINT32); 1701 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_parent_node_id = 1702 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1703 parent_node_id, INT32); 1704 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_priority = 1705 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1706 priority, UINT32); 1707 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_weight = 1708 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1709 weight, UINT32); 1710 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_level_id = 1711 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1712 level_id, UINT32); 1713 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_shaper_profile_id = 1714 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1715 shaper_profile_id, INT32); 1716 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_cman_mode = 1717 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1718 cman_mode, UINT32); 1719 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_wred_profile_id = 1720 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1721 wred_profile_id, UINT32); 1722 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_stats_mask = 1723 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1724 stats_mask, UINT64); 1725 cmdline_parse_token_string_t 1726 cmd_add_port_tm_leaf_node_multi_shared_shaper_id = 1727 TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1728 multi_shared_shaper_id, TOKEN_STRING_MULTI); 1729 1730 static void cmd_add_port_tm_leaf_node_parsed(void *parsed_result, 1731 __attribute__((unused)) struct cmdline *cl, 1732 __attribute__((unused)) void *data) 1733 { 1734 struct cmd_add_port_tm_leaf_node_result *res = parsed_result; 1735 struct rte_tm_error error; 1736 struct rte_tm_node_params np; 1737 uint32_t *shared_shaper_id; 1738 uint32_t parent_node_id, n_shared_shapers = 0; 1739 portid_t port_id = res->port_id; 1740 char *s_str = res->multi_shared_shaper_id; 1741 int ret; 1742 1743 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1744 return; 1745 1746 memset(&np, 0, sizeof(struct rte_tm_node_params)); 1747 memset(&error, 0, sizeof(struct rte_tm_error)); 1748 1749 /* Node parameters */ 1750 if (res->parent_node_id < 0) 1751 parent_node_id = UINT32_MAX; 1752 else 1753 parent_node_id = res->parent_node_id; 1754 1755 shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS * 1756 sizeof(uint32_t)); 1757 if (shared_shaper_id == NULL) { 1758 printf(" Memory not allocated for shared shapers (error)\n"); 1759 return; 1760 } 1761 1762 /* Parse multi shared shaper id string */ 1763 ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id); 1764 if (ret) { 1765 printf(" Shared shapers params string parse error\n"); 1766 free(shared_shaper_id); 1767 return; 1768 } 1769 1770 if (res->shaper_profile_id < 0) 1771 np.shaper_profile_id = UINT32_MAX; 1772 else 1773 np.shaper_profile_id = res->shaper_profile_id; 1774 1775 np.n_shared_shapers = n_shared_shapers; 1776 1777 if (np.n_shared_shapers) { 1778 np.shared_shaper_id = &shared_shaper_id[0]; 1779 } else { 1780 free(shared_shaper_id); 1781 shared_shaper_id = NULL; 1782 } 1783 1784 np.leaf.cman = res->cman_mode; 1785 np.leaf.wred.wred_profile_id = res->wred_profile_id; 1786 np.stats_mask = res->stats_mask; 1787 1788 ret = rte_tm_node_add(port_id, res->node_id, parent_node_id, 1789 res->priority, res->weight, res->level_id, 1790 &np, &error); 1791 if (ret != 0) { 1792 print_err_msg(&error); 1793 free(shared_shaper_id); 1794 return; 1795 } 1796 } 1797 1798 cmdline_parse_inst_t cmd_add_port_tm_leaf_node = { 1799 .f = cmd_add_port_tm_leaf_node_parsed, 1800 .data = NULL, 1801 .help_str = "Add port tm leaf node", 1802 .tokens = { 1803 (void *)&cmd_add_port_tm_leaf_node_add, 1804 (void *)&cmd_add_port_tm_leaf_node_port, 1805 (void *)&cmd_add_port_tm_leaf_node_tm, 1806 (void *)&cmd_add_port_tm_leaf_node_nonleaf, 1807 (void *)&cmd_add_port_tm_leaf_node_node, 1808 (void *)&cmd_add_port_tm_leaf_node_port_id, 1809 (void *)&cmd_add_port_tm_leaf_node_node_id, 1810 (void *)&cmd_add_port_tm_leaf_node_parent_node_id, 1811 (void *)&cmd_add_port_tm_leaf_node_priority, 1812 (void *)&cmd_add_port_tm_leaf_node_weight, 1813 (void *)&cmd_add_port_tm_leaf_node_level_id, 1814 (void *)&cmd_add_port_tm_leaf_node_shaper_profile_id, 1815 (void *)&cmd_add_port_tm_leaf_node_cman_mode, 1816 (void *)&cmd_add_port_tm_leaf_node_wred_profile_id, 1817 (void *)&cmd_add_port_tm_leaf_node_stats_mask, 1818 (void *)&cmd_add_port_tm_leaf_node_multi_shared_shaper_id, 1819 NULL, 1820 }, 1821 }; 1822 1823 /* *** Delete Port TM Node *** */ 1824 struct cmd_del_port_tm_node_result { 1825 cmdline_fixed_string_t del; 1826 cmdline_fixed_string_t port; 1827 cmdline_fixed_string_t tm; 1828 cmdline_fixed_string_t node; 1829 uint16_t port_id; 1830 uint32_t node_id; 1831 }; 1832 1833 cmdline_parse_token_string_t cmd_del_port_tm_node_del = 1834 TOKEN_STRING_INITIALIZER( 1835 struct cmd_del_port_tm_node_result, del, "del"); 1836 cmdline_parse_token_string_t cmd_del_port_tm_node_port = 1837 TOKEN_STRING_INITIALIZER( 1838 struct cmd_del_port_tm_node_result, port, "port"); 1839 cmdline_parse_token_string_t cmd_del_port_tm_node_tm = 1840 TOKEN_STRING_INITIALIZER( 1841 struct cmd_del_port_tm_node_result, tm, "tm"); 1842 cmdline_parse_token_string_t cmd_del_port_tm_node_node = 1843 TOKEN_STRING_INITIALIZER( 1844 struct cmd_del_port_tm_node_result, node, "node"); 1845 cmdline_parse_token_num_t cmd_del_port_tm_node_port_id = 1846 TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result, 1847 port_id, UINT16); 1848 cmdline_parse_token_num_t cmd_del_port_tm_node_node_id = 1849 TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result, 1850 node_id, UINT32); 1851 1852 static void cmd_del_port_tm_node_parsed(void *parsed_result, 1853 __attribute__((unused)) struct cmdline *cl, 1854 __attribute__((unused)) void *data) 1855 { 1856 struct cmd_del_port_tm_node_result *res = parsed_result; 1857 struct rte_tm_error error; 1858 uint32_t node_id = res->node_id; 1859 portid_t port_id = res->port_id; 1860 int ret; 1861 1862 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1863 return; 1864 1865 memset(&error, 0, sizeof(struct rte_tm_error)); 1866 /* Port status */ 1867 if (port_is_started(port_id)) { 1868 printf(" Port %u not stopped (error)\n", port_id); 1869 return; 1870 } 1871 1872 ret = rte_tm_node_delete(port_id, node_id, &error); 1873 if (ret != 0) { 1874 print_err_msg(&error); 1875 return; 1876 } 1877 } 1878 1879 cmdline_parse_inst_t cmd_del_port_tm_node = { 1880 .f = cmd_del_port_tm_node_parsed, 1881 .data = NULL, 1882 .help_str = "Delete port tm node", 1883 .tokens = { 1884 (void *)&cmd_del_port_tm_node_del, 1885 (void *)&cmd_del_port_tm_node_port, 1886 (void *)&cmd_del_port_tm_node_tm, 1887 (void *)&cmd_del_port_tm_node_node, 1888 (void *)&cmd_del_port_tm_node_port_id, 1889 (void *)&cmd_del_port_tm_node_node_id, 1890 NULL, 1891 }, 1892 }; 1893 1894 /* *** Update Port TM Node Parent *** */ 1895 struct cmd_set_port_tm_node_parent_result { 1896 cmdline_fixed_string_t set; 1897 cmdline_fixed_string_t port; 1898 cmdline_fixed_string_t tm; 1899 cmdline_fixed_string_t node; 1900 cmdline_fixed_string_t parent; 1901 uint16_t port_id; 1902 uint32_t node_id; 1903 uint32_t parent_id; 1904 uint32_t priority; 1905 uint32_t weight; 1906 }; 1907 1908 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_set = 1909 TOKEN_STRING_INITIALIZER( 1910 struct cmd_set_port_tm_node_parent_result, set, "set"); 1911 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_port = 1912 TOKEN_STRING_INITIALIZER( 1913 struct cmd_set_port_tm_node_parent_result, port, "port"); 1914 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_tm = 1915 TOKEN_STRING_INITIALIZER( 1916 struct cmd_set_port_tm_node_parent_result, tm, "tm"); 1917 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_node = 1918 TOKEN_STRING_INITIALIZER( 1919 struct cmd_set_port_tm_node_parent_result, node, "node"); 1920 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_parent = 1921 TOKEN_STRING_INITIALIZER( 1922 struct cmd_set_port_tm_node_parent_result, parent, "parent"); 1923 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_port_id = 1924 TOKEN_NUM_INITIALIZER( 1925 struct cmd_set_port_tm_node_parent_result, port_id, UINT16); 1926 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_node_id = 1927 TOKEN_NUM_INITIALIZER( 1928 struct cmd_set_port_tm_node_parent_result, node_id, UINT32); 1929 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_parent_id = 1930 TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result, 1931 parent_id, UINT32); 1932 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_priority = 1933 TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result, 1934 priority, UINT32); 1935 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_weight = 1936 TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result, 1937 weight, UINT32); 1938 1939 static void cmd_set_port_tm_node_parent_parsed(void *parsed_result, 1940 __attribute__((unused)) struct cmdline *cl, 1941 __attribute__((unused)) void *data) 1942 { 1943 struct cmd_set_port_tm_node_parent_result *res = parsed_result; 1944 struct rte_tm_error error; 1945 uint32_t node_id = res->node_id; 1946 uint32_t parent_id = res->parent_id; 1947 uint32_t priority = res->priority; 1948 uint32_t weight = res->weight; 1949 portid_t port_id = res->port_id; 1950 int ret; 1951 1952 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1953 return; 1954 1955 memset(&error, 0, sizeof(struct rte_tm_error)); 1956 /* Port status */ 1957 if (!port_is_started(port_id)) { 1958 printf(" Port %u not started (error)\n", port_id); 1959 return; 1960 } 1961 1962 ret = rte_tm_node_parent_update(port_id, node_id, 1963 parent_id, priority, weight, &error); 1964 if (ret != 0) { 1965 print_err_msg(&error); 1966 return; 1967 } 1968 } 1969 1970 cmdline_parse_inst_t cmd_set_port_tm_node_parent = { 1971 .f = cmd_set_port_tm_node_parent_parsed, 1972 .data = NULL, 1973 .help_str = "Set port tm node parent", 1974 .tokens = { 1975 (void *)&cmd_set_port_tm_node_parent_set, 1976 (void *)&cmd_set_port_tm_node_parent_port, 1977 (void *)&cmd_set_port_tm_node_parent_tm, 1978 (void *)&cmd_set_port_tm_node_parent_node, 1979 (void *)&cmd_set_port_tm_node_parent_parent, 1980 (void *)&cmd_set_port_tm_node_parent_port_id, 1981 (void *)&cmd_set_port_tm_node_parent_node_id, 1982 (void *)&cmd_set_port_tm_node_parent_parent_id, 1983 (void *)&cmd_set_port_tm_node_parent_priority, 1984 (void *)&cmd_set_port_tm_node_parent_weight, 1985 NULL, 1986 }, 1987 }; 1988 1989 /* *** Suspend Port TM Node *** */ 1990 struct cmd_suspend_port_tm_node_result { 1991 cmdline_fixed_string_t suspend; 1992 cmdline_fixed_string_t port; 1993 cmdline_fixed_string_t tm; 1994 cmdline_fixed_string_t node; 1995 uint16_t port_id; 1996 uint32_t node_id; 1997 }; 1998 1999 cmdline_parse_token_string_t cmd_suspend_port_tm_node_suspend = 2000 TOKEN_STRING_INITIALIZER( 2001 struct cmd_suspend_port_tm_node_result, suspend, "suspend"); 2002 cmdline_parse_token_string_t cmd_suspend_port_tm_node_port = 2003 TOKEN_STRING_INITIALIZER( 2004 struct cmd_suspend_port_tm_node_result, port, "port"); 2005 cmdline_parse_token_string_t cmd_suspend_port_tm_node_tm = 2006 TOKEN_STRING_INITIALIZER( 2007 struct cmd_suspend_port_tm_node_result, tm, "tm"); 2008 cmdline_parse_token_string_t cmd_suspend_port_tm_node_node = 2009 TOKEN_STRING_INITIALIZER( 2010 struct cmd_suspend_port_tm_node_result, node, "node"); 2011 cmdline_parse_token_num_t cmd_suspend_port_tm_node_port_id = 2012 TOKEN_NUM_INITIALIZER( 2013 struct cmd_suspend_port_tm_node_result, port_id, UINT16); 2014 cmdline_parse_token_num_t cmd_suspend_port_tm_node_node_id = 2015 TOKEN_NUM_INITIALIZER( 2016 struct cmd_suspend_port_tm_node_result, node_id, UINT32); 2017 2018 static void cmd_suspend_port_tm_node_parsed(void *parsed_result, 2019 __attribute__((unused)) struct cmdline *cl, 2020 __attribute__((unused)) void *data) 2021 { 2022 struct cmd_suspend_port_tm_node_result *res = parsed_result; 2023 struct rte_tm_error error; 2024 uint32_t node_id = res->node_id; 2025 portid_t port_id = res->port_id; 2026 int ret; 2027 2028 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2029 return; 2030 2031 memset(&error, 0, sizeof(struct rte_tm_error)); 2032 ret = rte_tm_node_suspend(port_id, node_id, &error); 2033 if (ret != 0) { 2034 print_err_msg(&error); 2035 return; 2036 } 2037 } 2038 2039 cmdline_parse_inst_t cmd_suspend_port_tm_node = { 2040 .f = cmd_suspend_port_tm_node_parsed, 2041 .data = NULL, 2042 .help_str = "Suspend port tm node", 2043 .tokens = { 2044 (void *)&cmd_suspend_port_tm_node_suspend, 2045 (void *)&cmd_suspend_port_tm_node_port, 2046 (void *)&cmd_suspend_port_tm_node_tm, 2047 (void *)&cmd_suspend_port_tm_node_node, 2048 (void *)&cmd_suspend_port_tm_node_port_id, 2049 (void *)&cmd_suspend_port_tm_node_node_id, 2050 NULL, 2051 }, 2052 }; 2053 2054 /* *** Resume Port TM Node *** */ 2055 struct cmd_resume_port_tm_node_result { 2056 cmdline_fixed_string_t resume; 2057 cmdline_fixed_string_t port; 2058 cmdline_fixed_string_t tm; 2059 cmdline_fixed_string_t node; 2060 uint16_t port_id; 2061 uint32_t node_id; 2062 }; 2063 2064 cmdline_parse_token_string_t cmd_resume_port_tm_node_resume = 2065 TOKEN_STRING_INITIALIZER( 2066 struct cmd_resume_port_tm_node_result, resume, "resume"); 2067 cmdline_parse_token_string_t cmd_resume_port_tm_node_port = 2068 TOKEN_STRING_INITIALIZER( 2069 struct cmd_resume_port_tm_node_result, port, "port"); 2070 cmdline_parse_token_string_t cmd_resume_port_tm_node_tm = 2071 TOKEN_STRING_INITIALIZER( 2072 struct cmd_resume_port_tm_node_result, tm, "tm"); 2073 cmdline_parse_token_string_t cmd_resume_port_tm_node_node = 2074 TOKEN_STRING_INITIALIZER( 2075 struct cmd_resume_port_tm_node_result, node, "node"); 2076 cmdline_parse_token_num_t cmd_resume_port_tm_node_port_id = 2077 TOKEN_NUM_INITIALIZER( 2078 struct cmd_resume_port_tm_node_result, port_id, UINT16); 2079 cmdline_parse_token_num_t cmd_resume_port_tm_node_node_id = 2080 TOKEN_NUM_INITIALIZER( 2081 struct cmd_resume_port_tm_node_result, node_id, UINT32); 2082 2083 static void cmd_resume_port_tm_node_parsed(void *parsed_result, 2084 __attribute__((unused)) struct cmdline *cl, 2085 __attribute__((unused)) void *data) 2086 { 2087 struct cmd_resume_port_tm_node_result *res = parsed_result; 2088 struct rte_tm_error error; 2089 uint32_t node_id = res->node_id; 2090 portid_t port_id = res->port_id; 2091 int ret; 2092 2093 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2094 return; 2095 2096 memset(&error, 0, sizeof(struct rte_tm_error)); 2097 ret = rte_tm_node_resume(port_id, node_id, &error); 2098 if (ret != 0) { 2099 print_err_msg(&error); 2100 return; 2101 } 2102 } 2103 2104 cmdline_parse_inst_t cmd_resume_port_tm_node = { 2105 .f = cmd_resume_port_tm_node_parsed, 2106 .data = NULL, 2107 .help_str = "Resume port tm node", 2108 .tokens = { 2109 (void *)&cmd_resume_port_tm_node_resume, 2110 (void *)&cmd_resume_port_tm_node_port, 2111 (void *)&cmd_resume_port_tm_node_tm, 2112 (void *)&cmd_resume_port_tm_node_node, 2113 (void *)&cmd_resume_port_tm_node_port_id, 2114 (void *)&cmd_resume_port_tm_node_node_id, 2115 NULL, 2116 }, 2117 }; 2118 2119 /* *** Port TM Hierarchy Commit *** */ 2120 struct cmd_port_tm_hierarchy_commit_result { 2121 cmdline_fixed_string_t port; 2122 cmdline_fixed_string_t tm; 2123 cmdline_fixed_string_t hierarchy; 2124 cmdline_fixed_string_t commit; 2125 uint16_t port_id; 2126 cmdline_fixed_string_t clean_on_fail; 2127 }; 2128 2129 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_port = 2130 TOKEN_STRING_INITIALIZER( 2131 struct cmd_port_tm_hierarchy_commit_result, port, "port"); 2132 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_tm = 2133 TOKEN_STRING_INITIALIZER( 2134 struct cmd_port_tm_hierarchy_commit_result, tm, "tm"); 2135 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_hierarchy = 2136 TOKEN_STRING_INITIALIZER( 2137 struct cmd_port_tm_hierarchy_commit_result, 2138 hierarchy, "hierarchy"); 2139 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_commit = 2140 TOKEN_STRING_INITIALIZER( 2141 struct cmd_port_tm_hierarchy_commit_result, commit, "commit"); 2142 cmdline_parse_token_num_t cmd_port_tm_hierarchy_commit_port_id = 2143 TOKEN_NUM_INITIALIZER( 2144 struct cmd_port_tm_hierarchy_commit_result, 2145 port_id, UINT16); 2146 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_clean_on_fail = 2147 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_hierarchy_commit_result, 2148 clean_on_fail, "yes#no"); 2149 2150 static void cmd_port_tm_hierarchy_commit_parsed(void *parsed_result, 2151 __attribute__((unused)) struct cmdline *cl, 2152 __attribute__((unused)) void *data) 2153 { 2154 struct cmd_port_tm_hierarchy_commit_result *res = parsed_result; 2155 struct rte_tm_error error; 2156 uint32_t clean_on_fail; 2157 portid_t port_id = res->port_id; 2158 int ret; 2159 2160 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2161 return; 2162 2163 if (strcmp(res->clean_on_fail, "yes") == 0) 2164 clean_on_fail = 1; 2165 else 2166 clean_on_fail = 0; 2167 2168 memset(&error, 0, sizeof(struct rte_tm_error)); 2169 ret = rte_tm_hierarchy_commit(port_id, clean_on_fail, &error); 2170 if (ret != 0) { 2171 print_err_msg(&error); 2172 return; 2173 } 2174 } 2175 2176 cmdline_parse_inst_t cmd_port_tm_hierarchy_commit = { 2177 .f = cmd_port_tm_hierarchy_commit_parsed, 2178 .data = NULL, 2179 .help_str = "Commit port tm hierarchy", 2180 .tokens = { 2181 (void *)&cmd_port_tm_hierarchy_commit_port, 2182 (void *)&cmd_port_tm_hierarchy_commit_tm, 2183 (void *)&cmd_port_tm_hierarchy_commit_hierarchy, 2184 (void *)&cmd_port_tm_hierarchy_commit_commit, 2185 (void *)&cmd_port_tm_hierarchy_commit_port_id, 2186 (void *)&cmd_port_tm_hierarchy_commit_clean_on_fail, 2187 NULL, 2188 }, 2189 }; 2190