1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2017 Intel Corporation 3 */ 4 5 #include <ctype.h> 6 #include <stdlib.h> 7 8 #include <cmdline_parse.h> 9 #include <cmdline_parse_num.h> 10 #include <cmdline_parse_string.h> 11 12 #include <rte_ethdev.h> 13 #include <rte_flow.h> 14 #include <rte_string_fns.h> 15 #include <rte_tm.h> 16 17 #include "testpmd.h" 18 #include "cmdline_tm.h" 19 20 #define PARSE_DELIMITER " \f\n\r\t\v" 21 #define MAX_NUM_SHARED_SHAPERS 256 22 23 /** Display TM Error Message */ 24 static void 25 print_err_msg(struct rte_tm_error *error) 26 { 27 static const char *const errstrlist[] = { 28 [RTE_TM_ERROR_TYPE_NONE] = "no error", 29 [RTE_TM_ERROR_TYPE_UNSPECIFIED] = "cause unspecified", 30 [RTE_TM_ERROR_TYPE_CAPABILITIES] 31 = "capability parameter null", 32 [RTE_TM_ERROR_TYPE_LEVEL_ID] = "level id", 33 [RTE_TM_ERROR_TYPE_WRED_PROFILE] 34 = "wred profile null", 35 [RTE_TM_ERROR_TYPE_WRED_PROFILE_GREEN] = "wred profile(green)", 36 [RTE_TM_ERROR_TYPE_WRED_PROFILE_YELLOW] 37 = "wred profile(yellow)", 38 [RTE_TM_ERROR_TYPE_WRED_PROFILE_RED] = "wred profile(red)", 39 [RTE_TM_ERROR_TYPE_WRED_PROFILE_ID] = "wred profile id", 40 [RTE_TM_ERROR_TYPE_SHARED_WRED_CONTEXT_ID] 41 = "shared wred context id", 42 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE] = "shaper profile null", 43 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE] 44 = "committed rate field (shaper profile)", 45 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_SIZE] 46 = "committed size field (shaper profile)", 47 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_RATE] 48 = "peak rate field (shaper profile)", 49 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE] 50 = "peak size field (shaper profile)", 51 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PKT_ADJUST_LEN] 52 = "packet adjust length field (shaper profile)", 53 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PACKET_MODE] 54 = "packet mode field (shaper profile)", 55 [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID] = "shaper profile id", 56 [RTE_TM_ERROR_TYPE_SHARED_SHAPER_ID] = "shared shaper id", 57 [RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID] = "parent node id", 58 [RTE_TM_ERROR_TYPE_NODE_PRIORITY] = "node priority", 59 [RTE_TM_ERROR_TYPE_NODE_WEIGHT] = "node weight", 60 [RTE_TM_ERROR_TYPE_NODE_PARAMS] = "node parameter null", 61 [RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID] 62 = "shaper profile id field (node params)", 63 [RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID] 64 = "shared shaper id field (node params)", 65 [RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS] 66 = "num shared shapers field (node params)", 67 [RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE] 68 = "wfq weight mode field (node params)", 69 [RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES] 70 = "num strict priorities field (node params)", 71 [RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN] 72 = "congestion management mode field (node params)", 73 [RTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID] = 74 "wred profile id field (node params)", 75 [RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_WRED_CONTEXT_ID] 76 = "shared wred context id field (node params)", 77 [RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS] 78 = "num shared wred contexts field (node params)", 79 [RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS] 80 = "stats field (node params)", 81 [RTE_TM_ERROR_TYPE_NODE_ID] = "node id", 82 }; 83 84 const char *errstr; 85 char buf[64]; 86 87 if ((unsigned int)error->type >= RTE_DIM(errstrlist) || 88 !errstrlist[error->type]) 89 errstr = "unknown type"; 90 else 91 errstr = errstrlist[error->type]; 92 93 if (error->cause) 94 snprintf(buf, sizeof(buf), "cause: %p, ", error->cause); 95 96 fprintf(stderr, "%s: %s%s (error %d)\n", 97 errstr, error->cause ? buf : "", 98 error->message ? error->message : "(no stated reason)", 99 error->type); 100 } 101 102 static int 103 read_uint64(uint64_t *value, const char *p) 104 { 105 char *next; 106 uint64_t val; 107 108 p = rte_str_skip_leading_spaces(p); 109 if (!isdigit(*p)) 110 return -EINVAL; 111 112 val = strtoul(p, &next, 10); 113 if (p == next) 114 return -EINVAL; 115 116 p = next; 117 switch (*p) { 118 case 'T': 119 val *= 1024ULL; 120 /* fall through */ 121 case 'G': 122 val *= 1024ULL; 123 /* fall through */ 124 case 'M': 125 val *= 1024ULL; 126 /* fall through */ 127 case 'k': 128 case 'K': 129 val *= 1024ULL; 130 p++; 131 break; 132 } 133 134 p = rte_str_skip_leading_spaces(p); 135 if (*p != '\0') 136 return -EINVAL; 137 138 *value = val; 139 return 0; 140 } 141 142 static int 143 read_uint32(uint32_t *value, const char *p) 144 { 145 uint64_t val = 0; 146 int ret = read_uint64(&val, p); 147 148 if (ret < 0) 149 return ret; 150 151 if (val > UINT32_MAX) 152 return -ERANGE; 153 154 *value = val; 155 return 0; 156 } 157 158 static int 159 parse_multi_ss_id_str(char *s_str, uint32_t *n_ssp, uint32_t shaper_id[]) 160 { 161 uint32_t n_shared_shapers = 0, i = 0; 162 char *token; 163 164 /* First token: num of shared shapers */ 165 token = strtok_r(s_str, PARSE_DELIMITER, &s_str); 166 if (token == NULL) 167 return -1; 168 169 if (read_uint32(&n_shared_shapers, token)) 170 return -1; 171 172 /* Check: num of shared shaper */ 173 if (n_shared_shapers >= MAX_NUM_SHARED_SHAPERS) { 174 fprintf(stderr, 175 " 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 static 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 static 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 static 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 static 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 static 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, RTE_UINT16); 221 222 static void cmd_show_port_tm_cap_parsed(void *parsed_result, 223 __rte_unused struct cmdline *cl, 224 __rte_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_private_packet_mode_supported %" PRId32 "\n", 261 cap.shaper_private_packet_mode_supported); 262 printf("cap.shaper_private_byte_mode_supported %" PRId32 "\n", 263 cap.shaper_private_byte_mode_supported); 264 printf("cap.shaper_shared_n_max %" PRIu32 "\n", 265 cap.shaper_shared_n_max); 266 printf("cap.shaper_shared_n_nodes_per_shaper_max %" PRIu32 "\n", 267 cap.shaper_shared_n_nodes_per_shaper_max); 268 printf("cap.shaper_shared_n_shapers_per_node_max %" PRIu32 "\n", 269 cap.shaper_shared_n_shapers_per_node_max); 270 printf("cap.shaper_shared_dual_rate_n_max %" PRIu32 "\n", 271 cap.shaper_shared_dual_rate_n_max); 272 printf("cap.shaper_shared_rate_min %" PRIu64 "\n", 273 cap.shaper_shared_rate_min); 274 printf("cap.shaper_shared_rate_max %" PRIu64 "\n", 275 cap.shaper_shared_rate_max); 276 printf("cap.shaper_shared_packet_mode_supported %" PRId32 "\n", 277 cap.shaper_shared_packet_mode_supported); 278 printf("cap.shaper_shared_byte_mode_supported %" PRId32 "\n", 279 cap.shaper_shared_byte_mode_supported); 280 printf("cap.shaper_pkt_length_adjust_min %" PRId32 "\n", 281 cap.shaper_pkt_length_adjust_min); 282 printf("cap.shaper_pkt_length_adjust_max %" PRId32 "\n", 283 cap.shaper_pkt_length_adjust_max); 284 printf("cap.sched_n_children_max %" PRIu32 "\n", 285 cap.sched_n_children_max); 286 printf("cap.sched_sp_n_priorities_max %" PRIu32 "\n", 287 cap.sched_sp_n_priorities_max); 288 printf("cap.sched_wfq_n_children_per_group_max %" PRIu32 "\n", 289 cap.sched_wfq_n_children_per_group_max); 290 printf("cap.sched_wfq_n_groups_max %" PRIu32 "\n", 291 cap.sched_wfq_n_groups_max); 292 printf("cap.sched_wfq_weight_max %" PRIu32 "\n", 293 cap.sched_wfq_weight_max); 294 printf("cap.sched_wfq_packet_mode_supported %" PRId32 "\n", 295 cap.sched_wfq_packet_mode_supported); 296 printf("cap.sched_wfq_byte_mode_supported %" PRId32 "\n", 297 cap.sched_wfq_byte_mode_supported); 298 printf("cap.cman_head_drop_supported %" PRId32 "\n", 299 cap.cman_head_drop_supported); 300 printf("cap.cman_wred_context_n_max %" PRIu32 "\n", 301 cap.cman_wred_context_n_max); 302 printf("cap.cman_wred_context_private_n_max %" PRIu32 "\n", 303 cap.cman_wred_context_private_n_max); 304 printf("cap.cman_wred_context_shared_n_max %" PRIu32 "\n", 305 cap.cman_wred_context_shared_n_max); 306 printf("cap.cman_wred_context_shared_n_nodes_per_context_max %" PRIu32 307 "\n", cap.cman_wred_context_shared_n_nodes_per_context_max); 308 printf("cap.cman_wred_context_shared_n_contexts_per_node_max %" PRIu32 309 "\n", cap.cman_wred_context_shared_n_contexts_per_node_max); 310 311 for (i = 0; i < RTE_COLORS; i++) { 312 printf("cap.mark_vlan_dei_supported %" PRId32 "\n", 313 cap.mark_vlan_dei_supported[i]); 314 printf("cap.mark_ip_ecn_tcp_supported %" PRId32 "\n", 315 cap.mark_ip_ecn_tcp_supported[i]); 316 printf("cap.mark_ip_ecn_sctp_supported %" PRId32 "\n", 317 cap.mark_ip_ecn_sctp_supported[i]); 318 printf("cap.mark_ip_dscp_supported %" PRId32 "\n", 319 cap.mark_ip_dscp_supported[i]); 320 } 321 322 printf("cap.dynamic_update_mask %" PRIx64 "\n", 323 cap.dynamic_update_mask); 324 printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask); 325 } 326 327 cmdline_parse_inst_t cmd_show_port_tm_cap = { 328 .f = cmd_show_port_tm_cap_parsed, 329 .data = NULL, 330 .help_str = "Show Port TM Capabilities", 331 .tokens = { 332 (void *)&cmd_show_port_tm_cap_show, 333 (void *)&cmd_show_port_tm_cap_port, 334 (void *)&cmd_show_port_tm_cap_tm, 335 (void *)&cmd_show_port_tm_cap_cap, 336 (void *)&cmd_show_port_tm_cap_port_id, 337 NULL, 338 }, 339 }; 340 341 /* *** Port TM Hierarchical Level Capability *** */ 342 struct cmd_show_port_tm_level_cap_result { 343 cmdline_fixed_string_t show; 344 cmdline_fixed_string_t port; 345 cmdline_fixed_string_t tm; 346 cmdline_fixed_string_t level; 347 cmdline_fixed_string_t cap; 348 uint16_t port_id; 349 uint32_t level_id; 350 }; 351 352 static cmdline_parse_token_string_t cmd_show_port_tm_level_cap_show = 353 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 354 show, "show"); 355 static cmdline_parse_token_string_t cmd_show_port_tm_level_cap_port = 356 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 357 port, "port"); 358 static cmdline_parse_token_string_t cmd_show_port_tm_level_cap_tm = 359 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 360 tm, "tm"); 361 static cmdline_parse_token_string_t cmd_show_port_tm_level_cap_level = 362 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 363 level, "level"); 364 static cmdline_parse_token_string_t cmd_show_port_tm_level_cap_cap = 365 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 366 cap, "cap"); 367 static cmdline_parse_token_num_t cmd_show_port_tm_level_cap_port_id = 368 TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 369 port_id, RTE_UINT16); 370 static cmdline_parse_token_num_t cmd_show_port_tm_level_cap_level_id = 371 TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result, 372 level_id, RTE_UINT32); 373 374 375 static void cmd_show_port_tm_level_cap_parsed(void *parsed_result, 376 __rte_unused struct cmdline *cl, 377 __rte_unused void *data) 378 { 379 struct cmd_show_port_tm_level_cap_result *res = parsed_result; 380 struct rte_tm_level_capabilities lcap; 381 struct rte_tm_error error; 382 portid_t port_id = res->port_id; 383 uint32_t level_id = res->level_id; 384 int ret; 385 386 if (port_id_is_invalid(port_id, ENABLED_WARN)) 387 return; 388 389 memset(&lcap, 0, sizeof(struct rte_tm_level_capabilities)); 390 memset(&error, 0, sizeof(struct rte_tm_error)); 391 ret = rte_tm_level_capabilities_get(port_id, level_id, &lcap, &error); 392 if (ret) { 393 print_err_msg(&error); 394 return; 395 } 396 printf("\n** Port TM Hierarchy level %" PRIu32 " Capability **\n\n", 397 level_id); 398 399 printf("cap.n_nodes_max %" PRIu32 "\n", lcap.n_nodes_max); 400 printf("cap.n_nodes_nonleaf_max %" PRIu32 "\n", 401 lcap.n_nodes_nonleaf_max); 402 printf("cap.n_nodes_leaf_max %" PRIu32 "\n", lcap.n_nodes_leaf_max); 403 printf("cap.non_leaf_nodes_identical %" PRId32 "\n", 404 lcap.non_leaf_nodes_identical); 405 printf("cap.leaf_nodes_identical %" PRId32 "\n", 406 lcap.leaf_nodes_identical); 407 if (level_id <= 3) { 408 printf("cap.nonleaf.shaper_private_supported %" PRId32 "\n", 409 lcap.nonleaf.shaper_private_supported); 410 printf("cap.nonleaf.shaper_private_dual_rate_supported %" PRId32 411 "\n", lcap.nonleaf.shaper_private_dual_rate_supported); 412 printf("cap.nonleaf.shaper_private_rate_min %" PRIu64 "\n", 413 lcap.nonleaf.shaper_private_rate_min); 414 printf("cap.nonleaf.shaper_private_rate_max %" PRIu64 "\n", 415 lcap.nonleaf.shaper_private_rate_max); 416 printf("cap.nonleaf.shaper_private_packet_mode_supported %" 417 PRId32 "\n", 418 lcap.nonleaf.shaper_private_packet_mode_supported); 419 printf("cap.nonleaf.shaper_private_byte_mode_supported %" PRId32 420 "\n", lcap.nonleaf.shaper_private_byte_mode_supported); 421 printf("cap.nonleaf.shaper_shared_n_max %" PRIu32 "\n", 422 lcap.nonleaf.shaper_shared_n_max); 423 printf("cap.nonleaf.shaper_shared_packet_mode_supported %" 424 PRId32 "\n", 425 lcap.nonleaf.shaper_shared_packet_mode_supported); 426 printf("cap.nonleaf.shaper_shared_byte_mode_supported %" 427 PRId32 "\n", 428 lcap.nonleaf.shaper_shared_byte_mode_supported); 429 printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n", 430 lcap.nonleaf.sched_n_children_max); 431 printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n", 432 lcap.nonleaf.sched_sp_n_priorities_max); 433 printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32 434 "\n", lcap.nonleaf.sched_wfq_n_children_per_group_max); 435 printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n", 436 lcap.nonleaf.sched_wfq_n_groups_max); 437 printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n", 438 lcap.nonleaf.sched_wfq_weight_max); 439 printf("cap.nonleaf.sched_wfq_packet_mode_supported %" PRId32 "\n", 440 lcap.nonleaf.sched_wfq_packet_mode_supported); 441 printf("cap.nonleaf.sched_wfq_byte_mode_supported %" PRId32 442 "\n", lcap.nonleaf.sched_wfq_byte_mode_supported); 443 printf("cap.nonleaf.stats_mask %" PRIx64 "\n", 444 lcap.nonleaf.stats_mask); 445 } else { 446 printf("cap.leaf.shaper_private_supported %" PRId32 "\n", 447 lcap.leaf.shaper_private_supported); 448 printf("cap.leaf.shaper_private_dual_rate_supported %" PRId32 449 "\n", lcap.leaf.shaper_private_dual_rate_supported); 450 printf("cap.leaf.shaper_private_rate_min %" PRIu64 "\n", 451 lcap.leaf.shaper_private_rate_min); 452 printf("cap.leaf.shaper_private_rate_max %" PRIu64 "\n", 453 lcap.leaf.shaper_private_rate_max); 454 printf("cap.leaf.shaper_private_packet_mode_supported %" PRId32 455 "\n", lcap.leaf.shaper_private_packet_mode_supported); 456 printf("cap.leaf.shaper_private_byte_mode_supported %" PRId32 "\n", 457 lcap.leaf.shaper_private_byte_mode_supported); 458 printf("cap.leaf.shaper_shared_n_max %" PRIu32 "\n", 459 lcap.leaf.shaper_shared_n_max); 460 printf("cap.leaf.shaper_shared_packet_mode_supported %" PRId32 "\n", 461 lcap.leaf.shaper_shared_packet_mode_supported); 462 printf("cap.leaf.shaper_shared_byte_mode_supported %" PRId32 "\n", 463 lcap.leaf.shaper_shared_byte_mode_supported); 464 printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n", 465 lcap.leaf.cman_head_drop_supported); 466 printf("cap.leaf.cman_wred_context_private_supported %" PRId32 467 "\n", lcap.leaf.cman_wred_context_private_supported); 468 printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n", 469 lcap.leaf.cman_wred_context_shared_n_max); 470 printf("cap.leaf.stats_mask %" PRIx64 "\n", 471 lcap.leaf.stats_mask); 472 } 473 } 474 475 cmdline_parse_inst_t cmd_show_port_tm_level_cap = { 476 .f = cmd_show_port_tm_level_cap_parsed, 477 .data = NULL, 478 .help_str = "Show port TM hierarchical level capabilities", 479 .tokens = { 480 (void *)&cmd_show_port_tm_level_cap_show, 481 (void *)&cmd_show_port_tm_level_cap_port, 482 (void *)&cmd_show_port_tm_level_cap_tm, 483 (void *)&cmd_show_port_tm_level_cap_level, 484 (void *)&cmd_show_port_tm_level_cap_cap, 485 (void *)&cmd_show_port_tm_level_cap_port_id, 486 (void *)&cmd_show_port_tm_level_cap_level_id, 487 NULL, 488 }, 489 }; 490 491 /* *** Port TM Hierarchy Node Capability *** */ 492 struct cmd_show_port_tm_node_cap_result { 493 cmdline_fixed_string_t show; 494 cmdline_fixed_string_t port; 495 cmdline_fixed_string_t tm; 496 cmdline_fixed_string_t node; 497 cmdline_fixed_string_t cap; 498 uint16_t port_id; 499 uint32_t node_id; 500 }; 501 502 static cmdline_parse_token_string_t cmd_show_port_tm_node_cap_show = 503 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 504 show, "show"); 505 static cmdline_parse_token_string_t cmd_show_port_tm_node_cap_port = 506 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 507 port, "port"); 508 static cmdline_parse_token_string_t cmd_show_port_tm_node_cap_tm = 509 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 510 tm, "tm"); 511 static cmdline_parse_token_string_t cmd_show_port_tm_node_cap_node = 512 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 513 node, "node"); 514 static cmdline_parse_token_string_t cmd_show_port_tm_node_cap_cap = 515 TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 516 cap, "cap"); 517 static cmdline_parse_token_num_t cmd_show_port_tm_node_cap_port_id = 518 TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 519 port_id, RTE_UINT16); 520 static cmdline_parse_token_num_t cmd_show_port_tm_node_cap_node_id = 521 TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result, 522 node_id, RTE_UINT32); 523 524 static void cmd_show_port_tm_node_cap_parsed(void *parsed_result, 525 __rte_unused struct cmdline *cl, 526 __rte_unused void *data) 527 { 528 struct cmd_show_port_tm_node_cap_result *res = parsed_result; 529 struct rte_tm_node_capabilities ncap; 530 struct rte_tm_error error; 531 uint32_t node_id = res->node_id; 532 portid_t port_id = res->port_id; 533 int ret, is_leaf = 0; 534 535 if (port_id_is_invalid(port_id, ENABLED_WARN)) 536 return; 537 538 memset(&error, 0, sizeof(struct rte_tm_error)); 539 /* Node id must be valid */ 540 ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error); 541 if (ret != 0) { 542 print_err_msg(&error); 543 return; 544 } 545 546 memset(&ncap, 0, sizeof(struct rte_tm_node_capabilities)); 547 ret = rte_tm_node_capabilities_get(port_id, node_id, &ncap, &error); 548 if (ret != 0) { 549 print_err_msg(&error); 550 return; 551 } 552 printf("\n** Port TM Hierarchy node %" PRIu32 " Capability **\n\n", 553 node_id); 554 printf("cap.shaper_private_supported %" PRId32 "\n", 555 ncap.shaper_private_supported); 556 printf("cap.shaper_private_dual_rate_supported %" PRId32 "\n", 557 ncap.shaper_private_dual_rate_supported); 558 printf("cap.shaper_private_rate_min %" PRIu64 "\n", 559 ncap.shaper_private_rate_min); 560 printf("cap.shaper_private_rate_max %" PRIu64 "\n", 561 ncap.shaper_private_rate_max); 562 printf("cap.shaper_private_packet_mode_supported %" PRId32 "\n", 563 ncap.shaper_private_packet_mode_supported); 564 printf("cap.shaper_private_byte_mode_supported %" PRId32 "\n", 565 ncap.shaper_private_byte_mode_supported); 566 printf("cap.shaper_shared_n_max %" PRIu32 "\n", 567 ncap.shaper_shared_n_max); 568 printf("cap.shaper_shared_packet_mode_supported %" PRId32 "\n", 569 ncap.shaper_shared_packet_mode_supported); 570 printf("cap.shaper_shared_byte_mode_supported %" PRId32 "\n", 571 ncap.shaper_shared_byte_mode_supported); 572 if (!is_leaf) { 573 printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n", 574 ncap.nonleaf.sched_n_children_max); 575 printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n", 576 ncap.nonleaf.sched_sp_n_priorities_max); 577 printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32 578 "\n", ncap.nonleaf.sched_wfq_n_children_per_group_max); 579 printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n", 580 ncap.nonleaf.sched_wfq_n_groups_max); 581 printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n", 582 ncap.nonleaf.sched_wfq_weight_max); 583 printf("cap.nonleaf.sched_wfq_packet_mode_supported %" PRId32 "\n", 584 ncap.nonleaf.sched_wfq_packet_mode_supported); 585 printf("cap.nonleaf.sched_wfq_byte_mode_supported %" PRId32 "\n", 586 ncap.nonleaf.sched_wfq_byte_mode_supported); 587 } else { 588 printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n", 589 ncap.leaf.cman_head_drop_supported); 590 printf("cap.leaf.cman_wred_context_private_supported %" PRId32 591 "\n", ncap.leaf.cman_wred_context_private_supported); 592 printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n", 593 ncap.leaf.cman_wred_context_shared_n_max); 594 } 595 printf("cap.stats_mask %" PRIx64 "\n", ncap.stats_mask); 596 } 597 598 cmdline_parse_inst_t cmd_show_port_tm_node_cap = { 599 .f = cmd_show_port_tm_node_cap_parsed, 600 .data = NULL, 601 .help_str = "Show Port TM Hierarchy node capabilities", 602 .tokens = { 603 (void *)&cmd_show_port_tm_node_cap_show, 604 (void *)&cmd_show_port_tm_node_cap_port, 605 (void *)&cmd_show_port_tm_node_cap_tm, 606 (void *)&cmd_show_port_tm_node_cap_node, 607 (void *)&cmd_show_port_tm_node_cap_cap, 608 (void *)&cmd_show_port_tm_node_cap_port_id, 609 (void *)&cmd_show_port_tm_node_cap_node_id, 610 NULL, 611 }, 612 }; 613 614 /* *** Show Port TM Node Statistics *** */ 615 struct cmd_show_port_tm_node_stats_result { 616 cmdline_fixed_string_t show; 617 cmdline_fixed_string_t port; 618 cmdline_fixed_string_t tm; 619 cmdline_fixed_string_t node; 620 cmdline_fixed_string_t stats; 621 uint16_t port_id; 622 uint32_t node_id; 623 uint32_t clear; 624 }; 625 626 static cmdline_parse_token_string_t cmd_show_port_tm_node_stats_show = 627 TOKEN_STRING_INITIALIZER( 628 struct cmd_show_port_tm_node_stats_result, show, "show"); 629 static cmdline_parse_token_string_t cmd_show_port_tm_node_stats_port = 630 TOKEN_STRING_INITIALIZER( 631 struct cmd_show_port_tm_node_stats_result, port, "port"); 632 static cmdline_parse_token_string_t cmd_show_port_tm_node_stats_tm = 633 TOKEN_STRING_INITIALIZER( 634 struct cmd_show_port_tm_node_stats_result, tm, "tm"); 635 static cmdline_parse_token_string_t cmd_show_port_tm_node_stats_node = 636 TOKEN_STRING_INITIALIZER( 637 struct cmd_show_port_tm_node_stats_result, node, "node"); 638 static cmdline_parse_token_string_t cmd_show_port_tm_node_stats_stats = 639 TOKEN_STRING_INITIALIZER( 640 struct cmd_show_port_tm_node_stats_result, stats, "stats"); 641 static cmdline_parse_token_num_t cmd_show_port_tm_node_stats_port_id = 642 TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_stats_result, 643 port_id, RTE_UINT16); 644 static cmdline_parse_token_num_t cmd_show_port_tm_node_stats_node_id = 645 TOKEN_NUM_INITIALIZER( 646 struct cmd_show_port_tm_node_stats_result, 647 node_id, RTE_UINT32); 648 static cmdline_parse_token_num_t cmd_show_port_tm_node_stats_clear = 649 TOKEN_NUM_INITIALIZER( 650 struct cmd_show_port_tm_node_stats_result, clear, RTE_UINT32); 651 652 static void cmd_show_port_tm_node_stats_parsed(void *parsed_result, 653 __rte_unused struct cmdline *cl, 654 __rte_unused void *data) 655 { 656 struct cmd_show_port_tm_node_stats_result *res = parsed_result; 657 struct rte_tm_node_stats stats; 658 struct rte_tm_error error; 659 uint64_t stats_mask = 0; 660 uint32_t node_id = res->node_id; 661 uint32_t clear = res->clear; 662 portid_t port_id = res->port_id; 663 int ret; 664 665 if (port_id_is_invalid(port_id, ENABLED_WARN)) 666 return; 667 668 memset(&error, 0, sizeof(struct rte_tm_error)); 669 /* Port status */ 670 if (!port_is_started(port_id)) { 671 fprintf(stderr, " Port %u not started (error)\n", port_id); 672 return; 673 } 674 675 memset(&stats, 0, sizeof(struct rte_tm_node_stats)); 676 ret = rte_tm_node_stats_read(port_id, node_id, &stats, 677 &stats_mask, clear, &error); 678 if (ret != 0) { 679 print_err_msg(&error); 680 return; 681 } 682 683 /* Display stats */ 684 if (stats_mask & RTE_TM_STATS_N_PKTS) 685 printf("\tPkts scheduled from node: %" PRIu64 "\n", 686 stats.n_pkts); 687 if (stats_mask & RTE_TM_STATS_N_BYTES) 688 printf("\tBytes scheduled from node: %" PRIu64 "\n", 689 stats.n_bytes); 690 if (stats_mask & RTE_TM_STATS_N_PKTS_GREEN_DROPPED) 691 printf("\tPkts dropped (green): %" PRIu64 "\n", 692 stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN]); 693 if (stats_mask & RTE_TM_STATS_N_PKTS_YELLOW_DROPPED) 694 printf("\tPkts dropped (yellow): %" PRIu64 "\n", 695 stats.leaf.n_pkts_dropped[RTE_COLOR_YELLOW]); 696 if (stats_mask & RTE_TM_STATS_N_PKTS_RED_DROPPED) 697 printf("\tPkts dropped (red): %" PRIu64 "\n", 698 stats.leaf.n_pkts_dropped[RTE_COLOR_RED]); 699 if (stats_mask & RTE_TM_STATS_N_BYTES_GREEN_DROPPED) 700 printf("\tBytes dropped (green): %" PRIu64 "\n", 701 stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN]); 702 if (stats_mask & RTE_TM_STATS_N_BYTES_YELLOW_DROPPED) 703 printf("\tBytes dropped (yellow): %" PRIu64 "\n", 704 stats.leaf.n_bytes_dropped[RTE_COLOR_YELLOW]); 705 if (stats_mask & RTE_TM_STATS_N_BYTES_RED_DROPPED) 706 printf("\tBytes dropped (red): %" PRIu64 "\n", 707 stats.leaf.n_bytes_dropped[RTE_COLOR_RED]); 708 if (stats_mask & RTE_TM_STATS_N_PKTS_QUEUED) 709 printf("\tPkts queued: %" PRIu64 "\n", 710 stats.leaf.n_pkts_queued); 711 if (stats_mask & RTE_TM_STATS_N_BYTES_QUEUED) 712 printf("\tBytes queued: %" PRIu64 "\n", 713 stats.leaf.n_bytes_queued); 714 } 715 716 cmdline_parse_inst_t cmd_show_port_tm_node_stats = { 717 .f = cmd_show_port_tm_node_stats_parsed, 718 .data = NULL, 719 .help_str = "Show port tm node stats", 720 .tokens = { 721 (void *)&cmd_show_port_tm_node_stats_show, 722 (void *)&cmd_show_port_tm_node_stats_port, 723 (void *)&cmd_show_port_tm_node_stats_tm, 724 (void *)&cmd_show_port_tm_node_stats_node, 725 (void *)&cmd_show_port_tm_node_stats_stats, 726 (void *)&cmd_show_port_tm_node_stats_port_id, 727 (void *)&cmd_show_port_tm_node_stats_node_id, 728 (void *)&cmd_show_port_tm_node_stats_clear, 729 NULL, 730 }, 731 }; 732 733 /* *** Show Port TM Node Type *** */ 734 struct cmd_show_port_tm_node_type_result { 735 cmdline_fixed_string_t show; 736 cmdline_fixed_string_t port; 737 cmdline_fixed_string_t tm; 738 cmdline_fixed_string_t node; 739 cmdline_fixed_string_t type; 740 uint16_t port_id; 741 uint32_t node_id; 742 }; 743 744 static cmdline_parse_token_string_t cmd_show_port_tm_node_type_show = 745 TOKEN_STRING_INITIALIZER( 746 struct cmd_show_port_tm_node_type_result, show, "show"); 747 static cmdline_parse_token_string_t cmd_show_port_tm_node_type_port = 748 TOKEN_STRING_INITIALIZER( 749 struct cmd_show_port_tm_node_type_result, port, "port"); 750 static cmdline_parse_token_string_t cmd_show_port_tm_node_type_tm = 751 TOKEN_STRING_INITIALIZER( 752 struct cmd_show_port_tm_node_type_result, tm, "tm"); 753 static cmdline_parse_token_string_t cmd_show_port_tm_node_type_node = 754 TOKEN_STRING_INITIALIZER( 755 struct cmd_show_port_tm_node_type_result, node, "node"); 756 static cmdline_parse_token_string_t cmd_show_port_tm_node_type_type = 757 TOKEN_STRING_INITIALIZER( 758 struct cmd_show_port_tm_node_type_result, type, "type"); 759 static cmdline_parse_token_num_t cmd_show_port_tm_node_type_port_id = 760 TOKEN_NUM_INITIALIZER( 761 struct cmd_show_port_tm_node_type_result, 762 port_id, RTE_UINT16); 763 static cmdline_parse_token_num_t cmd_show_port_tm_node_type_node_id = 764 TOKEN_NUM_INITIALIZER( 765 struct cmd_show_port_tm_node_type_result, 766 node_id, RTE_UINT32); 767 768 static void cmd_show_port_tm_node_type_parsed(void *parsed_result, 769 __rte_unused struct cmdline *cl, 770 __rte_unused void *data) 771 { 772 struct cmd_show_port_tm_node_type_result *res = parsed_result; 773 struct rte_tm_error error; 774 uint32_t node_id = res->node_id; 775 portid_t port_id = res->port_id; 776 int ret, is_leaf = 0; 777 778 if (port_id_is_invalid(port_id, ENABLED_WARN)) 779 return; 780 781 memset(&error, 0, sizeof(struct rte_tm_error)); 782 ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error); 783 if (ret != 0) { 784 print_err_msg(&error); 785 return; 786 } 787 788 if (is_leaf == 1) 789 printf("leaf node\n"); 790 else 791 printf("nonleaf node\n"); 792 793 } 794 795 cmdline_parse_inst_t cmd_show_port_tm_node_type = { 796 .f = cmd_show_port_tm_node_type_parsed, 797 .data = NULL, 798 .help_str = "Show port tm node type", 799 .tokens = { 800 (void *)&cmd_show_port_tm_node_type_show, 801 (void *)&cmd_show_port_tm_node_type_port, 802 (void *)&cmd_show_port_tm_node_type_tm, 803 (void *)&cmd_show_port_tm_node_type_node, 804 (void *)&cmd_show_port_tm_node_type_type, 805 (void *)&cmd_show_port_tm_node_type_port_id, 806 (void *)&cmd_show_port_tm_node_type_node_id, 807 NULL, 808 }, 809 }; 810 811 /* *** Add Port TM Private Shaper Profile *** */ 812 struct cmd_add_port_tm_node_shaper_profile_result { 813 cmdline_fixed_string_t add; 814 cmdline_fixed_string_t port; 815 cmdline_fixed_string_t tm; 816 cmdline_fixed_string_t node; 817 cmdline_fixed_string_t shaper; 818 cmdline_fixed_string_t profile; 819 uint16_t port_id; 820 uint32_t shaper_id; 821 uint64_t cmit_tb_rate; 822 uint64_t cmit_tb_size; 823 uint64_t peak_tb_rate; 824 uint64_t peak_tb_size; 825 uint32_t pktlen_adjust; 826 int pkt_mode; 827 }; 828 829 static cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_add = 830 TOKEN_STRING_INITIALIZER( 831 struct cmd_add_port_tm_node_shaper_profile_result, add, "add"); 832 static cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_port = 833 TOKEN_STRING_INITIALIZER( 834 struct cmd_add_port_tm_node_shaper_profile_result, 835 port, "port"); 836 static cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_tm = 837 TOKEN_STRING_INITIALIZER( 838 struct cmd_add_port_tm_node_shaper_profile_result, 839 tm, "tm"); 840 static cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_node = 841 TOKEN_STRING_INITIALIZER( 842 struct cmd_add_port_tm_node_shaper_profile_result, 843 node, "node"); 844 static cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_shaper = 845 TOKEN_STRING_INITIALIZER( 846 struct cmd_add_port_tm_node_shaper_profile_result, 847 shaper, "shaper"); 848 static cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_profile = 849 TOKEN_STRING_INITIALIZER( 850 struct cmd_add_port_tm_node_shaper_profile_result, 851 profile, "profile"); 852 static cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_port_id = 853 TOKEN_NUM_INITIALIZER( 854 struct cmd_add_port_tm_node_shaper_profile_result, 855 port_id, RTE_UINT16); 856 static cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_shaper_id = 857 TOKEN_NUM_INITIALIZER( 858 struct cmd_add_port_tm_node_shaper_profile_result, 859 shaper_id, RTE_UINT32); 860 static cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_cmit_tb_rate = 861 TOKEN_NUM_INITIALIZER( 862 struct cmd_add_port_tm_node_shaper_profile_result, 863 cmit_tb_rate, RTE_UINT64); 864 static cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_cmit_tb_size = 865 TOKEN_NUM_INITIALIZER( 866 struct cmd_add_port_tm_node_shaper_profile_result, 867 cmit_tb_size, RTE_UINT64); 868 static cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_peak_tb_rate = 869 TOKEN_NUM_INITIALIZER( 870 struct cmd_add_port_tm_node_shaper_profile_result, 871 peak_tb_rate, RTE_UINT64); 872 static cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_peak_tb_size = 873 TOKEN_NUM_INITIALIZER( 874 struct cmd_add_port_tm_node_shaper_profile_result, 875 peak_tb_size, RTE_UINT64); 876 static cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_pktlen_adjust = 877 TOKEN_NUM_INITIALIZER( 878 struct cmd_add_port_tm_node_shaper_profile_result, 879 pktlen_adjust, RTE_UINT32); 880 static cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_packet_mode = 881 TOKEN_NUM_INITIALIZER( 882 struct cmd_add_port_tm_node_shaper_profile_result, 883 pkt_mode, RTE_UINT32); 884 885 static int 886 get_printable_rate(uint64_t rate, char *buffer, size_t size) 887 { 888 if (rate >= 1000 * 1000 * 1000) 889 return snprintf(buffer, size, "%.1fG", rate / (1000 * 1000 * 1000.0)); 890 else if (rate >= 1000 * 1000) 891 return snprintf(buffer, size, "%.1fM", rate / (1000 * 1000.0)); 892 else if (rate >= 1000) 893 return snprintf(buffer, size, "%.1fK", rate / 1000.0); 894 else 895 return snprintf(buffer, size, "%"PRIu64, rate); 896 } 897 898 static void cmd_add_port_tm_node_shaper_profile_parsed(void *parsed_result, 899 struct cmdline *cl, 900 __rte_unused void *data) 901 { 902 struct cmd_add_port_tm_node_shaper_profile_result *res = parsed_result; 903 struct rte_tm_shaper_params sp; 904 struct rte_tm_error error; 905 uint32_t shaper_id = res->shaper_id; 906 uint32_t pkt_len_adjust = res->pktlen_adjust; 907 portid_t port_id = res->port_id; 908 char rate_str[20]; 909 int ret; 910 911 cmdline_printf(cl, "adding node shaper on port %u, with id %u\n", res->port_id, shaper_id); 912 get_printable_rate(res->cmit_tb_rate, rate_str, sizeof(rate_str)); 913 cmdline_printf(cl, "# committed rate: %s, t.b. size: %"PRIu64"\n", 914 rate_str, res->cmit_tb_size); 915 916 get_printable_rate(res->peak_tb_rate, rate_str, sizeof(rate_str)); 917 cmdline_printf(cl, "# peak rate: %s, t.b. size: %"PRIu64"\n", 918 rate_str, res->peak_tb_size); 919 cmdline_printf(cl, "# pkt length adjust: %u\n", res->pktlen_adjust); 920 cmdline_printf(cl, "# packet mode: %s\n", res->pkt_mode ? "true" : "false (bytes mode)"); 921 922 if (port_id_is_invalid(port_id, ENABLED_WARN)) 923 return; 924 925 /* Private shaper profile params */ 926 memset(&sp, 0, sizeof(struct rte_tm_shaper_params)); 927 memset(&error, 0, sizeof(struct rte_tm_error)); 928 sp.committed.rate = res->cmit_tb_rate; 929 sp.committed.size = res->cmit_tb_size; 930 sp.peak.rate = res->peak_tb_rate; 931 sp.peak.size = res->peak_tb_size; 932 sp.pkt_length_adjust = pkt_len_adjust; 933 sp.packet_mode = res->pkt_mode; 934 935 ret = rte_tm_shaper_profile_add(port_id, shaper_id, &sp, &error); 936 if (ret != 0) { 937 print_err_msg(&error); 938 return; 939 } 940 } 941 942 cmdline_parse_inst_t cmd_add_port_tm_node_shaper_profile = { 943 .f = cmd_add_port_tm_node_shaper_profile_parsed, 944 .data = NULL, 945 .help_str = "Add port tm node private shaper profile", 946 .tokens = { 947 (void *)&cmd_add_port_tm_node_shaper_profile_add, 948 (void *)&cmd_add_port_tm_node_shaper_profile_port, 949 (void *)&cmd_add_port_tm_node_shaper_profile_tm, 950 (void *)&cmd_add_port_tm_node_shaper_profile_node, 951 (void *)&cmd_add_port_tm_node_shaper_profile_shaper, 952 (void *)&cmd_add_port_tm_node_shaper_profile_profile, 953 (void *)&cmd_add_port_tm_node_shaper_profile_port_id, 954 (void *)&cmd_add_port_tm_node_shaper_profile_shaper_id, 955 (void *)&cmd_add_port_tm_node_shaper_profile_cmit_tb_rate, 956 (void *)&cmd_add_port_tm_node_shaper_profile_cmit_tb_size, 957 (void *)&cmd_add_port_tm_node_shaper_profile_peak_tb_rate, 958 (void *)&cmd_add_port_tm_node_shaper_profile_peak_tb_size, 959 (void *)&cmd_add_port_tm_node_shaper_profile_pktlen_adjust, 960 (void *)&cmd_add_port_tm_node_shaper_profile_packet_mode, 961 NULL, 962 }, 963 }; 964 965 /* *** Delete Port TM Private Shaper Profile *** */ 966 struct cmd_del_port_tm_node_shaper_profile_result { 967 cmdline_fixed_string_t del; 968 cmdline_fixed_string_t port; 969 cmdline_fixed_string_t tm; 970 cmdline_fixed_string_t node; 971 cmdline_fixed_string_t shaper; 972 cmdline_fixed_string_t profile; 973 uint16_t port_id; 974 uint32_t shaper_id; 975 }; 976 977 static cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_del = 978 TOKEN_STRING_INITIALIZER( 979 struct cmd_del_port_tm_node_shaper_profile_result, del, "del"); 980 static cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_port = 981 TOKEN_STRING_INITIALIZER( 982 struct cmd_del_port_tm_node_shaper_profile_result, 983 port, "port"); 984 static cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_tm = 985 TOKEN_STRING_INITIALIZER( 986 struct cmd_del_port_tm_node_shaper_profile_result, tm, "tm"); 987 static cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_node = 988 TOKEN_STRING_INITIALIZER( 989 struct cmd_del_port_tm_node_shaper_profile_result, 990 node, "node"); 991 static cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_shaper = 992 TOKEN_STRING_INITIALIZER( 993 struct cmd_del_port_tm_node_shaper_profile_result, 994 shaper, "shaper"); 995 static cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_profile = 996 TOKEN_STRING_INITIALIZER( 997 struct cmd_del_port_tm_node_shaper_profile_result, 998 profile, "profile"); 999 static cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_port_id = 1000 TOKEN_NUM_INITIALIZER( 1001 struct cmd_del_port_tm_node_shaper_profile_result, 1002 port_id, RTE_UINT16); 1003 static cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_shaper_id = 1004 TOKEN_NUM_INITIALIZER( 1005 struct cmd_del_port_tm_node_shaper_profile_result, 1006 shaper_id, RTE_UINT32); 1007 1008 static void cmd_del_port_tm_node_shaper_profile_parsed(void *parsed_result, 1009 __rte_unused struct cmdline *cl, 1010 __rte_unused void *data) 1011 { 1012 struct cmd_del_port_tm_node_shaper_profile_result *res = parsed_result; 1013 struct rte_tm_error error; 1014 uint32_t shaper_id = res->shaper_id; 1015 portid_t port_id = res->port_id; 1016 int ret; 1017 1018 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1019 return; 1020 1021 memset(&error, 0, sizeof(struct rte_tm_error)); 1022 ret = rte_tm_shaper_profile_delete(port_id, shaper_id, &error); 1023 if (ret != 0) { 1024 print_err_msg(&error); 1025 return; 1026 } 1027 } 1028 1029 cmdline_parse_inst_t cmd_del_port_tm_node_shaper_profile = { 1030 .f = cmd_del_port_tm_node_shaper_profile_parsed, 1031 .data = NULL, 1032 .help_str = "Delete port tm node private shaper profile", 1033 .tokens = { 1034 (void *)&cmd_del_port_tm_node_shaper_profile_del, 1035 (void *)&cmd_del_port_tm_node_shaper_profile_port, 1036 (void *)&cmd_del_port_tm_node_shaper_profile_tm, 1037 (void *)&cmd_del_port_tm_node_shaper_profile_node, 1038 (void *)&cmd_del_port_tm_node_shaper_profile_shaper, 1039 (void *)&cmd_del_port_tm_node_shaper_profile_profile, 1040 (void *)&cmd_del_port_tm_node_shaper_profile_port_id, 1041 (void *)&cmd_del_port_tm_node_shaper_profile_shaper_id, 1042 NULL, 1043 }, 1044 }; 1045 1046 /* *** Add/Update Port TM shared Shaper *** */ 1047 struct cmd_add_port_tm_node_shared_shaper_result { 1048 cmdline_fixed_string_t cmd_type; 1049 cmdline_fixed_string_t port; 1050 cmdline_fixed_string_t tm; 1051 cmdline_fixed_string_t node; 1052 cmdline_fixed_string_t shared; 1053 cmdline_fixed_string_t shaper; 1054 uint16_t port_id; 1055 uint32_t shared_shaper_id; 1056 uint32_t shaper_profile_id; 1057 }; 1058 1059 static cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_cmd_type = 1060 TOKEN_STRING_INITIALIZER( 1061 struct cmd_add_port_tm_node_shared_shaper_result, 1062 cmd_type, "add#set"); 1063 static cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_port = 1064 TOKEN_STRING_INITIALIZER( 1065 struct cmd_add_port_tm_node_shared_shaper_result, port, "port"); 1066 static cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_tm = 1067 TOKEN_STRING_INITIALIZER( 1068 struct cmd_add_port_tm_node_shared_shaper_result, tm, "tm"); 1069 static cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_node = 1070 TOKEN_STRING_INITIALIZER( 1071 struct cmd_add_port_tm_node_shared_shaper_result, node, "node"); 1072 static cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shared = 1073 TOKEN_STRING_INITIALIZER( 1074 struct cmd_add_port_tm_node_shared_shaper_result, 1075 shared, "shared"); 1076 static cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shaper = 1077 TOKEN_STRING_INITIALIZER( 1078 struct cmd_add_port_tm_node_shared_shaper_result, 1079 shaper, "shaper"); 1080 static cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_port_id = 1081 TOKEN_NUM_INITIALIZER( 1082 struct cmd_add_port_tm_node_shared_shaper_result, 1083 port_id, RTE_UINT16); 1084 static cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shared_shaper_id = 1085 TOKEN_NUM_INITIALIZER( 1086 struct cmd_add_port_tm_node_shared_shaper_result, 1087 shared_shaper_id, RTE_UINT32); 1088 static cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shaper_profile_id = 1089 TOKEN_NUM_INITIALIZER( 1090 struct cmd_add_port_tm_node_shared_shaper_result, 1091 shaper_profile_id, RTE_UINT32); 1092 1093 static void cmd_add_port_tm_node_shared_shaper_parsed(void *parsed_result, 1094 __rte_unused struct cmdline *cl, 1095 __rte_unused void *data) 1096 { 1097 struct cmd_add_port_tm_node_shared_shaper_result *res = parsed_result; 1098 struct rte_tm_error error; 1099 uint32_t shared_shaper_id = res->shared_shaper_id; 1100 uint32_t shaper_profile_id = res->shaper_profile_id; 1101 portid_t port_id = res->port_id; 1102 int ret; 1103 1104 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1105 return; 1106 1107 memset(&error, 0, sizeof(struct rte_tm_error)); 1108 /* Command type: add */ 1109 if ((strcmp(res->cmd_type, "add") == 0) && 1110 (port_is_started(port_id))) { 1111 fprintf(stderr, " Port %u not stopped (error)\n", port_id); 1112 return; 1113 } 1114 1115 /* Command type: set (update) */ 1116 if ((strcmp(res->cmd_type, "set") == 0) && 1117 (!port_is_started(port_id))) { 1118 fprintf(stderr, " Port %u not started (error)\n", port_id); 1119 return; 1120 } 1121 1122 ret = rte_tm_shared_shaper_add_update(port_id, shared_shaper_id, 1123 shaper_profile_id, &error); 1124 if (ret != 0) { 1125 print_err_msg(&error); 1126 return; 1127 } 1128 } 1129 1130 cmdline_parse_inst_t cmd_add_port_tm_node_shared_shaper = { 1131 .f = cmd_add_port_tm_node_shared_shaper_parsed, 1132 .data = NULL, 1133 .help_str = "add/update port tm node shared shaper", 1134 .tokens = { 1135 (void *)&cmd_add_port_tm_node_shared_shaper_cmd_type, 1136 (void *)&cmd_add_port_tm_node_shared_shaper_port, 1137 (void *)&cmd_add_port_tm_node_shared_shaper_tm, 1138 (void *)&cmd_add_port_tm_node_shared_shaper_node, 1139 (void *)&cmd_add_port_tm_node_shared_shaper_shared, 1140 (void *)&cmd_add_port_tm_node_shared_shaper_shaper, 1141 (void *)&cmd_add_port_tm_node_shared_shaper_port_id, 1142 (void *)&cmd_add_port_tm_node_shared_shaper_shared_shaper_id, 1143 (void *)&cmd_add_port_tm_node_shared_shaper_shaper_profile_id, 1144 NULL, 1145 }, 1146 }; 1147 1148 /* *** Delete Port TM shared Shaper *** */ 1149 struct cmd_del_port_tm_node_shared_shaper_result { 1150 cmdline_fixed_string_t del; 1151 cmdline_fixed_string_t port; 1152 cmdline_fixed_string_t tm; 1153 cmdline_fixed_string_t node; 1154 cmdline_fixed_string_t shared; 1155 cmdline_fixed_string_t shaper; 1156 uint16_t port_id; 1157 uint32_t shared_shaper_id; 1158 }; 1159 1160 static cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_del = 1161 TOKEN_STRING_INITIALIZER( 1162 struct cmd_del_port_tm_node_shared_shaper_result, del, "del"); 1163 static cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_port = 1164 TOKEN_STRING_INITIALIZER( 1165 struct cmd_del_port_tm_node_shared_shaper_result, port, "port"); 1166 static cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_tm = 1167 TOKEN_STRING_INITIALIZER( 1168 struct cmd_del_port_tm_node_shared_shaper_result, tm, "tm"); 1169 static cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_node = 1170 TOKEN_STRING_INITIALIZER( 1171 struct cmd_del_port_tm_node_shared_shaper_result, node, "node"); 1172 static cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shared = 1173 TOKEN_STRING_INITIALIZER( 1174 struct cmd_del_port_tm_node_shared_shaper_result, 1175 shared, "shared"); 1176 static cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shaper = 1177 TOKEN_STRING_INITIALIZER( 1178 struct cmd_del_port_tm_node_shared_shaper_result, 1179 shaper, "shaper"); 1180 static cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_port_id = 1181 TOKEN_NUM_INITIALIZER( 1182 struct cmd_del_port_tm_node_shared_shaper_result, 1183 port_id, RTE_UINT16); 1184 static cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_shared_shaper_id = 1185 TOKEN_NUM_INITIALIZER( 1186 struct cmd_del_port_tm_node_shared_shaper_result, 1187 shared_shaper_id, RTE_UINT32); 1188 1189 static void cmd_del_port_tm_node_shared_shaper_parsed(void *parsed_result, 1190 __rte_unused struct cmdline *cl, 1191 __rte_unused void *data) 1192 { 1193 struct cmd_del_port_tm_node_shared_shaper_result *res = parsed_result; 1194 struct rte_tm_error error; 1195 uint32_t shared_shaper_id = res->shared_shaper_id; 1196 portid_t port_id = res->port_id; 1197 int ret; 1198 1199 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1200 return; 1201 1202 memset(&error, 0, sizeof(struct rte_tm_error)); 1203 ret = rte_tm_shared_shaper_delete(port_id, shared_shaper_id, &error); 1204 if (ret != 0) { 1205 print_err_msg(&error); 1206 return; 1207 } 1208 } 1209 1210 cmdline_parse_inst_t cmd_del_port_tm_node_shared_shaper = { 1211 .f = cmd_del_port_tm_node_shared_shaper_parsed, 1212 .data = NULL, 1213 .help_str = "delete port tm node shared shaper", 1214 .tokens = { 1215 (void *)&cmd_del_port_tm_node_shared_shaper_del, 1216 (void *)&cmd_del_port_tm_node_shared_shaper_port, 1217 (void *)&cmd_del_port_tm_node_shared_shaper_tm, 1218 (void *)&cmd_del_port_tm_node_shared_shaper_node, 1219 (void *)&cmd_del_port_tm_node_shared_shaper_shared, 1220 (void *)&cmd_del_port_tm_node_shared_shaper_shaper, 1221 (void *)&cmd_del_port_tm_node_shared_shaper_port_id, 1222 (void *)&cmd_del_port_tm_node_shared_shaper_shared_shaper_id, 1223 NULL, 1224 }, 1225 }; 1226 1227 /* *** Add Port TM Node WRED Profile *** */ 1228 struct cmd_add_port_tm_node_wred_profile_result { 1229 cmdline_fixed_string_t add; 1230 cmdline_fixed_string_t port; 1231 cmdline_fixed_string_t tm; 1232 cmdline_fixed_string_t node; 1233 cmdline_fixed_string_t wred; 1234 cmdline_fixed_string_t profile; 1235 uint16_t port_id; 1236 uint32_t wred_profile_id; 1237 cmdline_fixed_string_t color_g; 1238 uint64_t min_th_g; 1239 uint64_t max_th_g; 1240 uint16_t maxp_inv_g; 1241 uint16_t wq_log2_g; 1242 cmdline_fixed_string_t color_y; 1243 uint64_t min_th_y; 1244 uint64_t max_th_y; 1245 uint16_t maxp_inv_y; 1246 uint16_t wq_log2_y; 1247 cmdline_fixed_string_t color_r; 1248 uint64_t min_th_r; 1249 uint64_t max_th_r; 1250 uint16_t maxp_inv_r; 1251 uint16_t wq_log2_r; 1252 }; 1253 1254 static cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_add = 1255 TOKEN_STRING_INITIALIZER( 1256 struct cmd_add_port_tm_node_wred_profile_result, add, "add"); 1257 static cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_port = 1258 TOKEN_STRING_INITIALIZER( 1259 struct cmd_add_port_tm_node_wred_profile_result, port, "port"); 1260 static cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_tm = 1261 TOKEN_STRING_INITIALIZER( 1262 struct cmd_add_port_tm_node_wred_profile_result, tm, "tm"); 1263 static cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_node = 1264 TOKEN_STRING_INITIALIZER( 1265 struct cmd_add_port_tm_node_wred_profile_result, node, "node"); 1266 static cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_wred = 1267 TOKEN_STRING_INITIALIZER( 1268 struct cmd_add_port_tm_node_wred_profile_result, wred, "wred"); 1269 static cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_profile = 1270 TOKEN_STRING_INITIALIZER( 1271 struct cmd_add_port_tm_node_wred_profile_result, 1272 profile, "profile"); 1273 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_port_id = 1274 TOKEN_NUM_INITIALIZER( 1275 struct cmd_add_port_tm_node_wred_profile_result, 1276 port_id, RTE_UINT16); 1277 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wred_profile_id = 1278 TOKEN_NUM_INITIALIZER( 1279 struct cmd_add_port_tm_node_wred_profile_result, 1280 wred_profile_id, RTE_UINT32); 1281 static cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_g = 1282 TOKEN_STRING_INITIALIZER( 1283 struct cmd_add_port_tm_node_wred_profile_result, 1284 color_g, "G#g"); 1285 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_g = 1286 TOKEN_NUM_INITIALIZER( 1287 struct cmd_add_port_tm_node_wred_profile_result, 1288 min_th_g, RTE_UINT64); 1289 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_g = 1290 TOKEN_NUM_INITIALIZER( 1291 struct cmd_add_port_tm_node_wred_profile_result, 1292 max_th_g, RTE_UINT64); 1293 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_g = 1294 TOKEN_NUM_INITIALIZER( 1295 struct cmd_add_port_tm_node_wred_profile_result, 1296 maxp_inv_g, RTE_UINT16); 1297 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_g = 1298 TOKEN_NUM_INITIALIZER( 1299 struct cmd_add_port_tm_node_wred_profile_result, 1300 wq_log2_g, RTE_UINT16); 1301 static cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_y = 1302 TOKEN_STRING_INITIALIZER( 1303 struct cmd_add_port_tm_node_wred_profile_result, 1304 color_y, "Y#y"); 1305 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_y = 1306 TOKEN_NUM_INITIALIZER( 1307 struct cmd_add_port_tm_node_wred_profile_result, 1308 min_th_y, RTE_UINT64); 1309 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_y = 1310 TOKEN_NUM_INITIALIZER( 1311 struct cmd_add_port_tm_node_wred_profile_result, 1312 max_th_y, RTE_UINT64); 1313 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_y = 1314 TOKEN_NUM_INITIALIZER( 1315 struct cmd_add_port_tm_node_wred_profile_result, 1316 maxp_inv_y, RTE_UINT16); 1317 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_y = 1318 TOKEN_NUM_INITIALIZER( 1319 struct cmd_add_port_tm_node_wred_profile_result, 1320 wq_log2_y, RTE_UINT16); 1321 static cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_r = 1322 TOKEN_STRING_INITIALIZER( 1323 struct cmd_add_port_tm_node_wred_profile_result, 1324 color_r, "R#r"); 1325 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_r = 1326 TOKEN_NUM_INITIALIZER( 1327 struct cmd_add_port_tm_node_wred_profile_result, 1328 min_th_r, RTE_UINT64); 1329 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_r = 1330 TOKEN_NUM_INITIALIZER( 1331 struct cmd_add_port_tm_node_wred_profile_result, 1332 max_th_r, RTE_UINT64); 1333 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_r = 1334 TOKEN_NUM_INITIALIZER( 1335 struct cmd_add_port_tm_node_wred_profile_result, 1336 maxp_inv_r, RTE_UINT16); 1337 static cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_r = 1338 TOKEN_NUM_INITIALIZER( 1339 struct cmd_add_port_tm_node_wred_profile_result, 1340 wq_log2_r, RTE_UINT16); 1341 1342 1343 static void cmd_add_port_tm_node_wred_profile_parsed(void *parsed_result, 1344 __rte_unused struct cmdline *cl, 1345 __rte_unused void *data) 1346 { 1347 struct cmd_add_port_tm_node_wred_profile_result *res = parsed_result; 1348 struct rte_tm_wred_params wp; 1349 enum rte_color color; 1350 struct rte_tm_error error; 1351 uint32_t wred_profile_id = res->wred_profile_id; 1352 portid_t port_id = res->port_id; 1353 int ret; 1354 1355 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1356 return; 1357 1358 memset(&wp, 0, sizeof(struct rte_tm_wred_params)); 1359 memset(&error, 0, sizeof(struct rte_tm_error)); 1360 1361 /* WRED Params (Green Color)*/ 1362 color = RTE_COLOR_GREEN; 1363 wp.red_params[color].min_th = res->min_th_g; 1364 wp.red_params[color].max_th = res->max_th_g; 1365 wp.red_params[color].maxp_inv = res->maxp_inv_g; 1366 wp.red_params[color].wq_log2 = res->wq_log2_g; 1367 1368 1369 /* WRED Params (Yellow Color)*/ 1370 color = RTE_COLOR_YELLOW; 1371 wp.red_params[color].min_th = res->min_th_y; 1372 wp.red_params[color].max_th = res->max_th_y; 1373 wp.red_params[color].maxp_inv = res->maxp_inv_y; 1374 wp.red_params[color].wq_log2 = res->wq_log2_y; 1375 1376 /* WRED Params (Red Color)*/ 1377 color = RTE_COLOR_RED; 1378 wp.red_params[color].min_th = res->min_th_r; 1379 wp.red_params[color].max_th = res->max_th_r; 1380 wp.red_params[color].maxp_inv = res->maxp_inv_r; 1381 wp.red_params[color].wq_log2 = res->wq_log2_r; 1382 1383 ret = rte_tm_wred_profile_add(port_id, wred_profile_id, &wp, &error); 1384 if (ret != 0) { 1385 print_err_msg(&error); 1386 return; 1387 } 1388 } 1389 1390 cmdline_parse_inst_t cmd_add_port_tm_node_wred_profile = { 1391 .f = cmd_add_port_tm_node_wred_profile_parsed, 1392 .data = NULL, 1393 .help_str = "Add port tm node wred profile", 1394 .tokens = { 1395 (void *)&cmd_add_port_tm_node_wred_profile_add, 1396 (void *)&cmd_add_port_tm_node_wred_profile_port, 1397 (void *)&cmd_add_port_tm_node_wred_profile_tm, 1398 (void *)&cmd_add_port_tm_node_wred_profile_node, 1399 (void *)&cmd_add_port_tm_node_wred_profile_wred, 1400 (void *)&cmd_add_port_tm_node_wred_profile_profile, 1401 (void *)&cmd_add_port_tm_node_wred_profile_port_id, 1402 (void *)&cmd_add_port_tm_node_wred_profile_wred_profile_id, 1403 (void *)&cmd_add_port_tm_node_wred_profile_color_g, 1404 (void *)&cmd_add_port_tm_node_wred_profile_min_th_g, 1405 (void *)&cmd_add_port_tm_node_wred_profile_max_th_g, 1406 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_g, 1407 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_g, 1408 (void *)&cmd_add_port_tm_node_wred_profile_color_y, 1409 (void *)&cmd_add_port_tm_node_wred_profile_min_th_y, 1410 (void *)&cmd_add_port_tm_node_wred_profile_max_th_y, 1411 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_y, 1412 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_y, 1413 (void *)&cmd_add_port_tm_node_wred_profile_color_r, 1414 (void *)&cmd_add_port_tm_node_wred_profile_min_th_r, 1415 (void *)&cmd_add_port_tm_node_wred_profile_max_th_r, 1416 (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_r, 1417 (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_r, 1418 NULL, 1419 }, 1420 }; 1421 1422 /* *** Delete Port TM node WRED Profile *** */ 1423 struct cmd_del_port_tm_node_wred_profile_result { 1424 cmdline_fixed_string_t del; 1425 cmdline_fixed_string_t port; 1426 cmdline_fixed_string_t tm; 1427 cmdline_fixed_string_t node; 1428 cmdline_fixed_string_t wred; 1429 cmdline_fixed_string_t profile; 1430 uint16_t port_id; 1431 uint32_t wred_profile_id; 1432 }; 1433 1434 static cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_del = 1435 TOKEN_STRING_INITIALIZER( 1436 struct cmd_del_port_tm_node_wred_profile_result, del, "del"); 1437 static cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_port = 1438 TOKEN_STRING_INITIALIZER( 1439 struct cmd_del_port_tm_node_wred_profile_result, port, "port"); 1440 static cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_tm = 1441 TOKEN_STRING_INITIALIZER( 1442 struct cmd_del_port_tm_node_wred_profile_result, tm, "tm"); 1443 static cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_node = 1444 TOKEN_STRING_INITIALIZER( 1445 struct cmd_del_port_tm_node_wred_profile_result, node, "node"); 1446 static cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_wred = 1447 TOKEN_STRING_INITIALIZER( 1448 struct cmd_del_port_tm_node_wred_profile_result, wred, "wred"); 1449 static cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_profile = 1450 TOKEN_STRING_INITIALIZER( 1451 struct cmd_del_port_tm_node_wred_profile_result, 1452 profile, "profile"); 1453 static cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_port_id = 1454 TOKEN_NUM_INITIALIZER( 1455 struct cmd_del_port_tm_node_wred_profile_result, 1456 port_id, RTE_UINT16); 1457 static cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_wred_profile_id = 1458 TOKEN_NUM_INITIALIZER( 1459 struct cmd_del_port_tm_node_wred_profile_result, 1460 wred_profile_id, RTE_UINT32); 1461 1462 static void cmd_del_port_tm_node_wred_profile_parsed(void *parsed_result, 1463 __rte_unused struct cmdline *cl, 1464 __rte_unused void *data) 1465 { 1466 struct cmd_del_port_tm_node_wred_profile_result *res = parsed_result; 1467 struct rte_tm_error error; 1468 uint32_t wred_profile_id = res->wred_profile_id; 1469 portid_t port_id = res->port_id; 1470 int ret; 1471 1472 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1473 return; 1474 1475 memset(&error, 0, sizeof(struct rte_tm_error)); 1476 ret = rte_tm_wred_profile_delete(port_id, wred_profile_id, &error); 1477 if (ret != 0) { 1478 print_err_msg(&error); 1479 return; 1480 } 1481 } 1482 1483 cmdline_parse_inst_t cmd_del_port_tm_node_wred_profile = { 1484 .f = cmd_del_port_tm_node_wred_profile_parsed, 1485 .data = NULL, 1486 .help_str = "Delete port tm node wred profile", 1487 .tokens = { 1488 (void *)&cmd_del_port_tm_node_wred_profile_del, 1489 (void *)&cmd_del_port_tm_node_wred_profile_port, 1490 (void *)&cmd_del_port_tm_node_wred_profile_tm, 1491 (void *)&cmd_del_port_tm_node_wred_profile_node, 1492 (void *)&cmd_del_port_tm_node_wred_profile_wred, 1493 (void *)&cmd_del_port_tm_node_wred_profile_profile, 1494 (void *)&cmd_del_port_tm_node_wred_profile_port_id, 1495 (void *)&cmd_del_port_tm_node_wred_profile_wred_profile_id, 1496 NULL, 1497 }, 1498 }; 1499 1500 /* *** Update Port TM Node Shaper profile *** */ 1501 struct cmd_set_port_tm_node_shaper_profile_result { 1502 cmdline_fixed_string_t set; 1503 cmdline_fixed_string_t port; 1504 cmdline_fixed_string_t tm; 1505 cmdline_fixed_string_t node; 1506 cmdline_fixed_string_t shaper; 1507 cmdline_fixed_string_t profile; 1508 uint16_t port_id; 1509 uint32_t node_id; 1510 uint32_t shaper_profile_id; 1511 }; 1512 1513 static cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_set = 1514 TOKEN_STRING_INITIALIZER( 1515 struct cmd_set_port_tm_node_shaper_profile_result, set, "set"); 1516 static cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_port = 1517 TOKEN_STRING_INITIALIZER( 1518 struct cmd_set_port_tm_node_shaper_profile_result, 1519 port, "port"); 1520 static cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_tm = 1521 TOKEN_STRING_INITIALIZER( 1522 struct cmd_set_port_tm_node_shaper_profile_result, tm, "tm"); 1523 static cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_node = 1524 TOKEN_STRING_INITIALIZER( 1525 struct cmd_set_port_tm_node_shaper_profile_result, 1526 node, "node"); 1527 static cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_shaper = 1528 TOKEN_STRING_INITIALIZER( 1529 struct cmd_set_port_tm_node_shaper_profile_result, 1530 shaper, "shaper"); 1531 static cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_profile = 1532 TOKEN_STRING_INITIALIZER( 1533 struct cmd_set_port_tm_node_shaper_profile_result, 1534 profile, "profile"); 1535 static cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_port_id = 1536 TOKEN_NUM_INITIALIZER( 1537 struct cmd_set_port_tm_node_shaper_profile_result, 1538 port_id, RTE_UINT16); 1539 static cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_node_id = 1540 TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_shaper_profile_result, 1541 node_id, RTE_UINT32); 1542 static cmdline_parse_token_num_t 1543 cmd_set_port_tm_node_shaper_shaper_profile_profile_id = 1544 TOKEN_NUM_INITIALIZER( 1545 struct cmd_set_port_tm_node_shaper_profile_result, 1546 shaper_profile_id, RTE_UINT32); 1547 1548 static void cmd_set_port_tm_node_shaper_profile_parsed(void *parsed_result, 1549 __rte_unused struct cmdline *cl, 1550 __rte_unused void *data) 1551 { 1552 struct cmd_set_port_tm_node_shaper_profile_result *res = parsed_result; 1553 struct rte_tm_error error; 1554 uint32_t node_id = res->node_id; 1555 uint32_t shaper_profile_id = res->shaper_profile_id; 1556 portid_t port_id = res->port_id; 1557 int ret; 1558 1559 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1560 return; 1561 1562 memset(&error, 0, sizeof(struct rte_tm_error)); 1563 /* Port status */ 1564 if (!port_is_started(port_id)) { 1565 fprintf(stderr, " Port %u not started (error)\n", port_id); 1566 return; 1567 } 1568 1569 ret = rte_tm_node_shaper_update(port_id, node_id, 1570 shaper_profile_id, &error); 1571 if (ret != 0) { 1572 print_err_msg(&error); 1573 return; 1574 } 1575 } 1576 1577 cmdline_parse_inst_t cmd_set_port_tm_node_shaper_profile = { 1578 .f = cmd_set_port_tm_node_shaper_profile_parsed, 1579 .data = NULL, 1580 .help_str = "Set port tm node shaper profile", 1581 .tokens = { 1582 (void *)&cmd_set_port_tm_node_shaper_profile_set, 1583 (void *)&cmd_set_port_tm_node_shaper_profile_port, 1584 (void *)&cmd_set_port_tm_node_shaper_profile_tm, 1585 (void *)&cmd_set_port_tm_node_shaper_profile_node, 1586 (void *)&cmd_set_port_tm_node_shaper_profile_shaper, 1587 (void *)&cmd_set_port_tm_node_shaper_profile_profile, 1588 (void *)&cmd_set_port_tm_node_shaper_profile_port_id, 1589 (void *)&cmd_set_port_tm_node_shaper_profile_node_id, 1590 (void *)&cmd_set_port_tm_node_shaper_shaper_profile_profile_id, 1591 NULL, 1592 }, 1593 }; 1594 1595 /* *** Add Port TM nonleaf node *** */ 1596 struct cmd_add_port_tm_nonleaf_node_result { 1597 cmdline_fixed_string_t add; 1598 cmdline_fixed_string_t port; 1599 cmdline_fixed_string_t tm; 1600 cmdline_fixed_string_t nonleaf; 1601 cmdline_fixed_string_t node; 1602 uint16_t port_id; 1603 uint32_t node_id; 1604 int32_t parent_node_id; 1605 uint32_t priority; 1606 uint32_t weight; 1607 uint32_t level_id; 1608 int32_t shaper_profile_id; 1609 uint32_t n_sp_priorities; 1610 uint64_t stats_mask; 1611 cmdline_multi_string_t multi_shared_shaper_id; 1612 }; 1613 1614 static cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_add = 1615 TOKEN_STRING_INITIALIZER( 1616 struct cmd_add_port_tm_nonleaf_node_result, add, "add"); 1617 static cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_port = 1618 TOKEN_STRING_INITIALIZER( 1619 struct cmd_add_port_tm_nonleaf_node_result, port, "port"); 1620 static cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_tm = 1621 TOKEN_STRING_INITIALIZER( 1622 struct cmd_add_port_tm_nonleaf_node_result, tm, "tm"); 1623 static cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_nonleaf = 1624 TOKEN_STRING_INITIALIZER( 1625 struct cmd_add_port_tm_nonleaf_node_result, nonleaf, "nonleaf"); 1626 static cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_node = 1627 TOKEN_STRING_INITIALIZER( 1628 struct cmd_add_port_tm_nonleaf_node_result, node, "node"); 1629 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_port_id = 1630 TOKEN_NUM_INITIALIZER( 1631 struct cmd_add_port_tm_nonleaf_node_result, 1632 port_id, RTE_UINT16); 1633 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_node_id = 1634 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1635 node_id, RTE_UINT32); 1636 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_parent_node_id = 1637 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1638 parent_node_id, RTE_INT32); 1639 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_priority = 1640 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1641 priority, RTE_UINT32); 1642 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_weight = 1643 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1644 weight, RTE_UINT32); 1645 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_level_id = 1646 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1647 level_id, RTE_UINT32); 1648 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_shaper_profile_id = 1649 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1650 shaper_profile_id, RTE_INT32); 1651 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_n_sp_priorities = 1652 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1653 n_sp_priorities, RTE_UINT32); 1654 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_stats_mask = 1655 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1656 stats_mask, RTE_UINT64); 1657 static cmdline_parse_token_string_t 1658 cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id = 1659 TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, 1660 multi_shared_shaper_id, TOKEN_STRING_MULTI); 1661 1662 static void cmd_add_port_tm_nonleaf_node_parsed(void *parsed_result, 1663 struct cmdline *cl, 1664 __rte_unused void *data) 1665 { 1666 struct cmd_add_port_tm_nonleaf_node_result *res = parsed_result; 1667 struct rte_tm_error error; 1668 struct rte_tm_node_params np; 1669 uint32_t *shared_shaper_id; 1670 uint32_t parent_node_id, n_shared_shapers = 0; 1671 char *s_str = res->multi_shared_shaper_id; 1672 portid_t port_id = res->port_id; 1673 int ret; 1674 1675 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1676 return; 1677 1678 memset(&np, 0, sizeof(struct rte_tm_node_params)); 1679 memset(&error, 0, sizeof(struct rte_tm_error)); 1680 1681 /* Node parameters */ 1682 if (res->parent_node_id < 0) 1683 parent_node_id = UINT32_MAX; 1684 else 1685 parent_node_id = res->parent_node_id; 1686 1687 if (parent_node_id != UINT32_MAX) 1688 cmdline_printf(cl, "adding node on port %u, with id %u and parent node %u\n", 1689 port_id, res->node_id, parent_node_id); 1690 else 1691 cmdline_printf(cl, "adding node on port %u, with id %u as root node\n", 1692 port_id, res->node_id); 1693 cmdline_printf(cl, "# priority: %u\n", res->priority); 1694 cmdline_printf(cl, "# weight: %u\n", res->weight); 1695 cmdline_printf(cl, "# level_id: %u\n", res->level_id); 1696 cmdline_printf(cl, "# shaper_profile_id: %d\n", res->shaper_profile_id); 1697 cmdline_printf(cl, "# num SP priorities: %u\n", res->n_sp_priorities); 1698 cmdline_printf(cl, "# stats_mask: %"PRIx64"\n", res->stats_mask); 1699 cmdline_printf(cl, "# shared shapers: '%s'\n", s_str); 1700 1701 shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS * 1702 sizeof(uint32_t)); 1703 if (shared_shaper_id == NULL) { 1704 fprintf(stderr, 1705 " Memory not allocated for shared shapers (error)\n"); 1706 return; 1707 } 1708 1709 /* Parse multi shared shaper id string */ 1710 ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id); 1711 if (ret) { 1712 fprintf(stderr, " Shared shapers params string parse error\n"); 1713 free(shared_shaper_id); 1714 return; 1715 } 1716 1717 if (res->shaper_profile_id < 0) 1718 np.shaper_profile_id = UINT32_MAX; 1719 else 1720 np.shaper_profile_id = res->shaper_profile_id; 1721 1722 np.n_shared_shapers = n_shared_shapers; 1723 if (np.n_shared_shapers) { 1724 np.shared_shaper_id = &shared_shaper_id[0]; 1725 } else { 1726 free(shared_shaper_id); 1727 shared_shaper_id = NULL; 1728 } 1729 1730 np.nonleaf.n_sp_priorities = res->n_sp_priorities; 1731 np.stats_mask = res->stats_mask; 1732 np.nonleaf.wfq_weight_mode = NULL; 1733 1734 ret = rte_tm_node_add(port_id, res->node_id, parent_node_id, 1735 res->priority, res->weight, res->level_id, 1736 &np, &error); 1737 if (ret != 0) { 1738 print_err_msg(&error); 1739 free(shared_shaper_id); 1740 return; 1741 } 1742 } 1743 1744 cmdline_parse_inst_t cmd_add_port_tm_nonleaf_node = { 1745 .f = cmd_add_port_tm_nonleaf_node_parsed, 1746 .data = NULL, 1747 .help_str = "Add port tm nonleaf node", 1748 .tokens = { 1749 (void *)&cmd_add_port_tm_nonleaf_node_add, 1750 (void *)&cmd_add_port_tm_nonleaf_node_port, 1751 (void *)&cmd_add_port_tm_nonleaf_node_tm, 1752 (void *)&cmd_add_port_tm_nonleaf_node_nonleaf, 1753 (void *)&cmd_add_port_tm_nonleaf_node_node, 1754 (void *)&cmd_add_port_tm_nonleaf_node_port_id, 1755 (void *)&cmd_add_port_tm_nonleaf_node_node_id, 1756 (void *)&cmd_add_port_tm_nonleaf_node_parent_node_id, 1757 (void *)&cmd_add_port_tm_nonleaf_node_priority, 1758 (void *)&cmd_add_port_tm_nonleaf_node_weight, 1759 (void *)&cmd_add_port_tm_nonleaf_node_level_id, 1760 (void *)&cmd_add_port_tm_nonleaf_node_shaper_profile_id, 1761 (void *)&cmd_add_port_tm_nonleaf_node_n_sp_priorities, 1762 (void *)&cmd_add_port_tm_nonleaf_node_stats_mask, 1763 (void *)&cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id, 1764 NULL, 1765 }, 1766 }; 1767 1768 /* *** Add Port TM nonleaf node pkt mode *** */ 1769 struct cmd_add_port_tm_nonleaf_node_pmode_result { 1770 cmdline_fixed_string_t add; 1771 cmdline_fixed_string_t port; 1772 cmdline_fixed_string_t tm; 1773 cmdline_fixed_string_t nonleaf; 1774 cmdline_fixed_string_t node; 1775 uint16_t port_id; 1776 uint32_t node_id; 1777 int32_t parent_node_id; 1778 uint32_t priority; 1779 uint32_t weight; 1780 uint32_t level_id; 1781 int32_t shaper_profile_id; 1782 uint32_t n_sp_priorities; 1783 uint64_t stats_mask; 1784 cmdline_multi_string_t multi_shared_shaper_id; 1785 }; 1786 1787 static cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_pmode_add = 1788 TOKEN_STRING_INITIALIZER( 1789 struct cmd_add_port_tm_nonleaf_node_pmode_result, add, "add"); 1790 static cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_pmode_port = 1791 TOKEN_STRING_INITIALIZER( 1792 struct cmd_add_port_tm_nonleaf_node_pmode_result, port, "port"); 1793 static cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_pmode_tm = 1794 TOKEN_STRING_INITIALIZER( 1795 struct cmd_add_port_tm_nonleaf_node_pmode_result, tm, "tm"); 1796 static cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_pmode_nonleaf = 1797 TOKEN_STRING_INITIALIZER( 1798 struct cmd_add_port_tm_nonleaf_node_pmode_result, nonleaf, "nonleaf"); 1799 static cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_pmode_node = 1800 TOKEN_STRING_INITIALIZER( 1801 struct cmd_add_port_tm_nonleaf_node_pmode_result, node, "node"); 1802 static cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_pmode_pktmode = 1803 TOKEN_STRING_INITIALIZER( 1804 struct cmd_add_port_tm_nonleaf_node_pmode_result, node, "pktmode"); 1805 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_port_id = 1806 TOKEN_NUM_INITIALIZER( 1807 struct cmd_add_port_tm_nonleaf_node_pmode_result, 1808 port_id, RTE_UINT16); 1809 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_node_id = 1810 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result, 1811 node_id, RTE_UINT32); 1812 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_parent_node_id = 1813 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result, 1814 parent_node_id, RTE_INT32); 1815 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_priority = 1816 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result, 1817 priority, RTE_UINT32); 1818 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_weight = 1819 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result, 1820 weight, RTE_UINT32); 1821 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_level_id = 1822 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result, 1823 level_id, RTE_UINT32); 1824 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_shaper_profile_id = 1825 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result, 1826 shaper_profile_id, RTE_INT32); 1827 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_n_sp_priorities = 1828 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result, 1829 n_sp_priorities, RTE_UINT32); 1830 static cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_stats_mask = 1831 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result, 1832 stats_mask, RTE_UINT64); 1833 static cmdline_parse_token_string_t 1834 cmd_add_port_tm_nonleaf_node_pmode_multi_shrd_shpr_id = 1835 TOKEN_STRING_INITIALIZER( 1836 struct cmd_add_port_tm_nonleaf_node_pmode_result, 1837 multi_shared_shaper_id, TOKEN_STRING_MULTI); 1838 1839 static void cmd_add_port_tm_nonleaf_node_pmode_parsed(void *parsed_result, 1840 __rte_unused struct cmdline *cl, 1841 __rte_unused void *data) 1842 { 1843 struct cmd_add_port_tm_nonleaf_node_pmode_result *res = parsed_result; 1844 uint32_t parent_node_id, n_shared_shapers = 0; 1845 char *s_str = res->multi_shared_shaper_id; 1846 portid_t port_id = res->port_id; 1847 struct rte_tm_node_params np; 1848 int *wfq_weight_mode = NULL; 1849 uint32_t *shared_shaper_id; 1850 struct rte_tm_error error; 1851 int ret; 1852 1853 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1854 return; 1855 1856 memset(&np, 0, sizeof(struct rte_tm_node_params)); 1857 memset(&error, 0, sizeof(struct rte_tm_error)); 1858 1859 /* Node parameters */ 1860 if (res->parent_node_id < 0) 1861 parent_node_id = UINT32_MAX; 1862 else 1863 parent_node_id = res->parent_node_id; 1864 1865 shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS * 1866 sizeof(uint32_t)); 1867 if (shared_shaper_id == NULL) { 1868 fprintf(stderr, 1869 " Memory not allocated for shared shapers (error)\n"); 1870 return; 1871 } 1872 1873 /* Parse multi shared shaper id string */ 1874 ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id); 1875 if (ret) { 1876 fprintf(stderr, " Shared shapers params string parse error\n"); 1877 free(shared_shaper_id); 1878 return; 1879 } 1880 1881 if (res->shaper_profile_id < 0) 1882 np.shaper_profile_id = UINT32_MAX; 1883 else 1884 np.shaper_profile_id = res->shaper_profile_id; 1885 1886 np.n_shared_shapers = n_shared_shapers; 1887 if (np.n_shared_shapers) { 1888 np.shared_shaper_id = &shared_shaper_id[0]; 1889 } else { 1890 free(shared_shaper_id); 1891 shared_shaper_id = NULL; 1892 } 1893 1894 if (res->n_sp_priorities) 1895 wfq_weight_mode = calloc(res->n_sp_priorities, sizeof(int)); 1896 np.nonleaf.n_sp_priorities = res->n_sp_priorities; 1897 np.stats_mask = res->stats_mask; 1898 np.nonleaf.wfq_weight_mode = wfq_weight_mode; 1899 1900 ret = rte_tm_node_add(port_id, res->node_id, parent_node_id, 1901 res->priority, res->weight, res->level_id, 1902 &np, &error); 1903 if (ret != 0) { 1904 print_err_msg(&error); 1905 free(shared_shaper_id); 1906 free(wfq_weight_mode); 1907 return; 1908 } 1909 } 1910 1911 cmdline_parse_inst_t cmd_add_port_tm_nonleaf_node_pmode = { 1912 .f = cmd_add_port_tm_nonleaf_node_pmode_parsed, 1913 .data = NULL, 1914 .help_str = "Add port tm nonleaf node pktmode", 1915 .tokens = { 1916 (void *)&cmd_add_port_tm_nonleaf_node_pmode_add, 1917 (void *)&cmd_add_port_tm_nonleaf_node_pmode_port, 1918 (void *)&cmd_add_port_tm_nonleaf_node_pmode_tm, 1919 (void *)&cmd_add_port_tm_nonleaf_node_pmode_nonleaf, 1920 (void *)&cmd_add_port_tm_nonleaf_node_pmode_node, 1921 (void *)&cmd_add_port_tm_nonleaf_node_pmode_pktmode, 1922 (void *)&cmd_add_port_tm_nonleaf_node_pmode_port_id, 1923 (void *)&cmd_add_port_tm_nonleaf_node_pmode_node_id, 1924 (void *)&cmd_add_port_tm_nonleaf_node_pmode_parent_node_id, 1925 (void *)&cmd_add_port_tm_nonleaf_node_pmode_priority, 1926 (void *)&cmd_add_port_tm_nonleaf_node_pmode_weight, 1927 (void *)&cmd_add_port_tm_nonleaf_node_pmode_level_id, 1928 (void *)&cmd_add_port_tm_nonleaf_node_pmode_shaper_profile_id, 1929 (void *)&cmd_add_port_tm_nonleaf_node_pmode_n_sp_priorities, 1930 (void *)&cmd_add_port_tm_nonleaf_node_pmode_stats_mask, 1931 (void *)&cmd_add_port_tm_nonleaf_node_pmode_multi_shrd_shpr_id, 1932 NULL, 1933 }, 1934 }; 1935 /* *** Add Port TM leaf node *** */ 1936 struct cmd_add_port_tm_leaf_node_result { 1937 cmdline_fixed_string_t add; 1938 cmdline_fixed_string_t port; 1939 cmdline_fixed_string_t tm; 1940 cmdline_fixed_string_t leaf; 1941 cmdline_fixed_string_t node; 1942 uint16_t port_id; 1943 uint32_t node_id; 1944 int32_t parent_node_id; 1945 uint32_t priority; 1946 uint32_t weight; 1947 uint32_t level_id; 1948 int32_t shaper_profile_id; 1949 uint32_t cman_mode; 1950 uint32_t wred_profile_id; 1951 uint64_t stats_mask; 1952 cmdline_multi_string_t multi_shared_shaper_id; 1953 }; 1954 1955 static cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_add = 1956 TOKEN_STRING_INITIALIZER( 1957 struct cmd_add_port_tm_leaf_node_result, add, "add"); 1958 static cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_port = 1959 TOKEN_STRING_INITIALIZER( 1960 struct cmd_add_port_tm_leaf_node_result, port, "port"); 1961 static cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_tm = 1962 TOKEN_STRING_INITIALIZER( 1963 struct cmd_add_port_tm_leaf_node_result, tm, "tm"); 1964 static cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_nonleaf = 1965 TOKEN_STRING_INITIALIZER( 1966 struct cmd_add_port_tm_leaf_node_result, leaf, "leaf"); 1967 static cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_node = 1968 TOKEN_STRING_INITIALIZER( 1969 struct cmd_add_port_tm_leaf_node_result, node, "node"); 1970 static cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_port_id = 1971 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1972 port_id, RTE_UINT16); 1973 static cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_node_id = 1974 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1975 node_id, RTE_UINT32); 1976 static cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_parent_node_id = 1977 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1978 parent_node_id, RTE_INT32); 1979 static cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_priority = 1980 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1981 priority, RTE_UINT32); 1982 static cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_weight = 1983 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1984 weight, RTE_UINT32); 1985 static cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_level_id = 1986 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1987 level_id, RTE_UINT32); 1988 static cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_shaper_profile_id = 1989 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1990 shaper_profile_id, RTE_INT32); 1991 static cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_cman_mode = 1992 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1993 cman_mode, RTE_UINT32); 1994 static cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_wred_profile_id = 1995 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1996 wred_profile_id, RTE_UINT32); 1997 static cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_stats_mask = 1998 TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 1999 stats_mask, RTE_UINT64); 2000 static cmdline_parse_token_string_t 2001 cmd_add_port_tm_leaf_node_multi_shared_shaper_id = 2002 TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, 2003 multi_shared_shaper_id, TOKEN_STRING_MULTI); 2004 2005 static void cmd_add_port_tm_leaf_node_parsed(void *parsed_result, 2006 struct cmdline *cl, 2007 __rte_unused void *data) 2008 { 2009 struct cmd_add_port_tm_leaf_node_result *res = parsed_result; 2010 struct rte_tm_error error; 2011 struct rte_tm_node_params np; 2012 uint32_t *shared_shaper_id; 2013 uint32_t parent_node_id, n_shared_shapers = 0; 2014 portid_t port_id = res->port_id; 2015 char *s_str = res->multi_shared_shaper_id; 2016 int ret; 2017 2018 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2019 return; 2020 2021 memset(&np, 0, sizeof(struct rte_tm_node_params)); 2022 memset(&error, 0, sizeof(struct rte_tm_error)); 2023 2024 /* Node parameters */ 2025 if (res->parent_node_id < 0) 2026 parent_node_id = UINT32_MAX; 2027 else 2028 parent_node_id = res->parent_node_id; 2029 2030 if (parent_node_id != UINT32_MAX) 2031 cmdline_printf(cl, "adding leaf node on port %u, with id %u and parent node %u\n", 2032 port_id, res->node_id, parent_node_id); 2033 else 2034 cmdline_printf(cl, "adding leaf node on port %u, with id %u as root node\n", 2035 port_id, res->node_id); 2036 cmdline_printf(cl, "# priority: %u\n", res->priority); 2037 cmdline_printf(cl, "# weight: %u\n", res->weight); 2038 cmdline_printf(cl, "# level_id: %u\n", res->level_id); 2039 cmdline_printf(cl, "# shaper_profile_id: %d\n", res->shaper_profile_id); 2040 cmdline_printf(cl, "# cman_mode: %u\n", res->cman_mode); 2041 cmdline_printf(cl, "# wred_profile_id: %d\n", res->wred_profile_id); 2042 cmdline_printf(cl, "# stats_mask: %"PRIx64"\n", res->stats_mask); 2043 cmdline_printf(cl, "# shared shapers: '%s'\n", s_str); 2044 2045 shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS * 2046 sizeof(uint32_t)); 2047 if (shared_shaper_id == NULL) { 2048 fprintf(stderr, 2049 " Memory not allocated for shared shapers (error)\n"); 2050 return; 2051 } 2052 2053 /* Parse multi shared shaper id string */ 2054 ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id); 2055 if (ret) { 2056 fprintf(stderr, " Shared shapers params string parse error\n"); 2057 free(shared_shaper_id); 2058 return; 2059 } 2060 2061 if (res->shaper_profile_id < 0) 2062 np.shaper_profile_id = UINT32_MAX; 2063 else 2064 np.shaper_profile_id = res->shaper_profile_id; 2065 2066 np.n_shared_shapers = n_shared_shapers; 2067 2068 if (np.n_shared_shapers) { 2069 np.shared_shaper_id = &shared_shaper_id[0]; 2070 } else { 2071 free(shared_shaper_id); 2072 shared_shaper_id = NULL; 2073 } 2074 2075 np.leaf.cman = res->cman_mode; 2076 np.leaf.wred.wred_profile_id = res->wred_profile_id; 2077 np.stats_mask = res->stats_mask; 2078 2079 ret = rte_tm_node_add(port_id, res->node_id, parent_node_id, 2080 res->priority, res->weight, res->level_id, 2081 &np, &error); 2082 if (ret != 0) { 2083 print_err_msg(&error); 2084 free(shared_shaper_id); 2085 return; 2086 } 2087 } 2088 2089 cmdline_parse_inst_t cmd_add_port_tm_leaf_node = { 2090 .f = cmd_add_port_tm_leaf_node_parsed, 2091 .data = NULL, 2092 .help_str = "Add port tm leaf node", 2093 .tokens = { 2094 (void *)&cmd_add_port_tm_leaf_node_add, 2095 (void *)&cmd_add_port_tm_leaf_node_port, 2096 (void *)&cmd_add_port_tm_leaf_node_tm, 2097 (void *)&cmd_add_port_tm_leaf_node_nonleaf, 2098 (void *)&cmd_add_port_tm_leaf_node_node, 2099 (void *)&cmd_add_port_tm_leaf_node_port_id, 2100 (void *)&cmd_add_port_tm_leaf_node_node_id, 2101 (void *)&cmd_add_port_tm_leaf_node_parent_node_id, 2102 (void *)&cmd_add_port_tm_leaf_node_priority, 2103 (void *)&cmd_add_port_tm_leaf_node_weight, 2104 (void *)&cmd_add_port_tm_leaf_node_level_id, 2105 (void *)&cmd_add_port_tm_leaf_node_shaper_profile_id, 2106 (void *)&cmd_add_port_tm_leaf_node_cman_mode, 2107 (void *)&cmd_add_port_tm_leaf_node_wred_profile_id, 2108 (void *)&cmd_add_port_tm_leaf_node_stats_mask, 2109 (void *)&cmd_add_port_tm_leaf_node_multi_shared_shaper_id, 2110 NULL, 2111 }, 2112 }; 2113 2114 /* *** Delete Port TM Node *** */ 2115 struct cmd_del_port_tm_node_result { 2116 cmdline_fixed_string_t del; 2117 cmdline_fixed_string_t port; 2118 cmdline_fixed_string_t tm; 2119 cmdline_fixed_string_t node; 2120 uint16_t port_id; 2121 uint32_t node_id; 2122 }; 2123 2124 static cmdline_parse_token_string_t cmd_del_port_tm_node_del = 2125 TOKEN_STRING_INITIALIZER( 2126 struct cmd_del_port_tm_node_result, del, "del"); 2127 static cmdline_parse_token_string_t cmd_del_port_tm_node_port = 2128 TOKEN_STRING_INITIALIZER( 2129 struct cmd_del_port_tm_node_result, port, "port"); 2130 static cmdline_parse_token_string_t cmd_del_port_tm_node_tm = 2131 TOKEN_STRING_INITIALIZER( 2132 struct cmd_del_port_tm_node_result, tm, "tm"); 2133 static cmdline_parse_token_string_t cmd_del_port_tm_node_node = 2134 TOKEN_STRING_INITIALIZER( 2135 struct cmd_del_port_tm_node_result, node, "node"); 2136 static cmdline_parse_token_num_t cmd_del_port_tm_node_port_id = 2137 TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result, 2138 port_id, RTE_UINT16); 2139 static cmdline_parse_token_num_t cmd_del_port_tm_node_node_id = 2140 TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result, 2141 node_id, RTE_UINT32); 2142 2143 static void cmd_del_port_tm_node_parsed(void *parsed_result, 2144 __rte_unused struct cmdline *cl, 2145 __rte_unused void *data) 2146 { 2147 struct cmd_del_port_tm_node_result *res = parsed_result; 2148 struct rte_tm_error error; 2149 uint32_t node_id = res->node_id; 2150 portid_t port_id = res->port_id; 2151 int ret; 2152 2153 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2154 return; 2155 2156 memset(&error, 0, sizeof(struct rte_tm_error)); 2157 /* Port status */ 2158 if (port_is_started(port_id)) { 2159 fprintf(stderr, " Port %u not stopped (error)\n", port_id); 2160 return; 2161 } 2162 2163 ret = rte_tm_node_delete(port_id, node_id, &error); 2164 if (ret != 0) { 2165 print_err_msg(&error); 2166 return; 2167 } 2168 } 2169 2170 cmdline_parse_inst_t cmd_del_port_tm_node = { 2171 .f = cmd_del_port_tm_node_parsed, 2172 .data = NULL, 2173 .help_str = "Delete port tm node", 2174 .tokens = { 2175 (void *)&cmd_del_port_tm_node_del, 2176 (void *)&cmd_del_port_tm_node_port, 2177 (void *)&cmd_del_port_tm_node_tm, 2178 (void *)&cmd_del_port_tm_node_node, 2179 (void *)&cmd_del_port_tm_node_port_id, 2180 (void *)&cmd_del_port_tm_node_node_id, 2181 NULL, 2182 }, 2183 }; 2184 2185 /* *** Update Port TM Node Parent *** */ 2186 struct cmd_set_port_tm_node_parent_result { 2187 cmdline_fixed_string_t set; 2188 cmdline_fixed_string_t port; 2189 cmdline_fixed_string_t tm; 2190 cmdline_fixed_string_t node; 2191 cmdline_fixed_string_t parent; 2192 uint16_t port_id; 2193 uint32_t node_id; 2194 uint32_t parent_id; 2195 uint32_t priority; 2196 uint32_t weight; 2197 }; 2198 2199 static cmdline_parse_token_string_t cmd_set_port_tm_node_parent_set = 2200 TOKEN_STRING_INITIALIZER( 2201 struct cmd_set_port_tm_node_parent_result, set, "set"); 2202 static cmdline_parse_token_string_t cmd_set_port_tm_node_parent_port = 2203 TOKEN_STRING_INITIALIZER( 2204 struct cmd_set_port_tm_node_parent_result, port, "port"); 2205 static cmdline_parse_token_string_t cmd_set_port_tm_node_parent_tm = 2206 TOKEN_STRING_INITIALIZER( 2207 struct cmd_set_port_tm_node_parent_result, tm, "tm"); 2208 static cmdline_parse_token_string_t cmd_set_port_tm_node_parent_node = 2209 TOKEN_STRING_INITIALIZER( 2210 struct cmd_set_port_tm_node_parent_result, node, "node"); 2211 static cmdline_parse_token_string_t cmd_set_port_tm_node_parent_parent = 2212 TOKEN_STRING_INITIALIZER( 2213 struct cmd_set_port_tm_node_parent_result, parent, "parent"); 2214 static cmdline_parse_token_num_t cmd_set_port_tm_node_parent_port_id = 2215 TOKEN_NUM_INITIALIZER( 2216 struct cmd_set_port_tm_node_parent_result, port_id, 2217 RTE_UINT16); 2218 static cmdline_parse_token_num_t cmd_set_port_tm_node_parent_node_id = 2219 TOKEN_NUM_INITIALIZER( 2220 struct cmd_set_port_tm_node_parent_result, node_id, 2221 RTE_UINT32); 2222 static cmdline_parse_token_num_t cmd_set_port_tm_node_parent_parent_id = 2223 TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result, 2224 parent_id, RTE_UINT32); 2225 static cmdline_parse_token_num_t cmd_set_port_tm_node_parent_priority = 2226 TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result, 2227 priority, RTE_UINT32); 2228 static cmdline_parse_token_num_t cmd_set_port_tm_node_parent_weight = 2229 TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result, 2230 weight, RTE_UINT32); 2231 2232 static void cmd_set_port_tm_node_parent_parsed(void *parsed_result, 2233 __rte_unused struct cmdline *cl, 2234 __rte_unused void *data) 2235 { 2236 struct cmd_set_port_tm_node_parent_result *res = parsed_result; 2237 struct rte_tm_error error; 2238 uint32_t node_id = res->node_id; 2239 uint32_t parent_id = res->parent_id; 2240 uint32_t priority = res->priority; 2241 uint32_t weight = res->weight; 2242 portid_t port_id = res->port_id; 2243 int ret; 2244 2245 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2246 return; 2247 2248 memset(&error, 0, sizeof(struct rte_tm_error)); 2249 /* Port status */ 2250 if (!port_is_started(port_id)) { 2251 fprintf(stderr, " Port %u not started (error)\n", port_id); 2252 return; 2253 } 2254 2255 ret = rte_tm_node_parent_update(port_id, node_id, 2256 parent_id, priority, weight, &error); 2257 if (ret != 0) { 2258 print_err_msg(&error); 2259 return; 2260 } 2261 } 2262 2263 cmdline_parse_inst_t cmd_set_port_tm_node_parent = { 2264 .f = cmd_set_port_tm_node_parent_parsed, 2265 .data = NULL, 2266 .help_str = "Set port tm node parent", 2267 .tokens = { 2268 (void *)&cmd_set_port_tm_node_parent_set, 2269 (void *)&cmd_set_port_tm_node_parent_port, 2270 (void *)&cmd_set_port_tm_node_parent_tm, 2271 (void *)&cmd_set_port_tm_node_parent_node, 2272 (void *)&cmd_set_port_tm_node_parent_parent, 2273 (void *)&cmd_set_port_tm_node_parent_port_id, 2274 (void *)&cmd_set_port_tm_node_parent_node_id, 2275 (void *)&cmd_set_port_tm_node_parent_parent_id, 2276 (void *)&cmd_set_port_tm_node_parent_priority, 2277 (void *)&cmd_set_port_tm_node_parent_weight, 2278 NULL, 2279 }, 2280 }; 2281 2282 /* *** Suspend Port TM Node *** */ 2283 struct cmd_suspend_port_tm_node_result { 2284 cmdline_fixed_string_t suspend; 2285 cmdline_fixed_string_t port; 2286 cmdline_fixed_string_t tm; 2287 cmdline_fixed_string_t node; 2288 uint16_t port_id; 2289 uint32_t node_id; 2290 }; 2291 2292 static cmdline_parse_token_string_t cmd_suspend_port_tm_node_suspend = 2293 TOKEN_STRING_INITIALIZER( 2294 struct cmd_suspend_port_tm_node_result, suspend, "suspend"); 2295 static cmdline_parse_token_string_t cmd_suspend_port_tm_node_port = 2296 TOKEN_STRING_INITIALIZER( 2297 struct cmd_suspend_port_tm_node_result, port, "port"); 2298 static cmdline_parse_token_string_t cmd_suspend_port_tm_node_tm = 2299 TOKEN_STRING_INITIALIZER( 2300 struct cmd_suspend_port_tm_node_result, tm, "tm"); 2301 static cmdline_parse_token_string_t cmd_suspend_port_tm_node_node = 2302 TOKEN_STRING_INITIALIZER( 2303 struct cmd_suspend_port_tm_node_result, node, "node"); 2304 static cmdline_parse_token_num_t cmd_suspend_port_tm_node_port_id = 2305 TOKEN_NUM_INITIALIZER( 2306 struct cmd_suspend_port_tm_node_result, port_id, 2307 RTE_UINT16); 2308 static cmdline_parse_token_num_t cmd_suspend_port_tm_node_node_id = 2309 TOKEN_NUM_INITIALIZER( 2310 struct cmd_suspend_port_tm_node_result, node_id, 2311 RTE_UINT32); 2312 2313 static void cmd_suspend_port_tm_node_parsed(void *parsed_result, 2314 __rte_unused struct cmdline *cl, 2315 __rte_unused void *data) 2316 { 2317 struct cmd_suspend_port_tm_node_result *res = parsed_result; 2318 struct rte_tm_error error; 2319 uint32_t node_id = res->node_id; 2320 portid_t port_id = res->port_id; 2321 int ret; 2322 2323 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2324 return; 2325 2326 memset(&error, 0, sizeof(struct rte_tm_error)); 2327 ret = rte_tm_node_suspend(port_id, node_id, &error); 2328 if (ret != 0) { 2329 print_err_msg(&error); 2330 return; 2331 } 2332 } 2333 2334 cmdline_parse_inst_t cmd_suspend_port_tm_node = { 2335 .f = cmd_suspend_port_tm_node_parsed, 2336 .data = NULL, 2337 .help_str = "Suspend port tm node", 2338 .tokens = { 2339 (void *)&cmd_suspend_port_tm_node_suspend, 2340 (void *)&cmd_suspend_port_tm_node_port, 2341 (void *)&cmd_suspend_port_tm_node_tm, 2342 (void *)&cmd_suspend_port_tm_node_node, 2343 (void *)&cmd_suspend_port_tm_node_port_id, 2344 (void *)&cmd_suspend_port_tm_node_node_id, 2345 NULL, 2346 }, 2347 }; 2348 2349 /* *** Resume Port TM Node *** */ 2350 struct cmd_resume_port_tm_node_result { 2351 cmdline_fixed_string_t resume; 2352 cmdline_fixed_string_t port; 2353 cmdline_fixed_string_t tm; 2354 cmdline_fixed_string_t node; 2355 uint16_t port_id; 2356 uint32_t node_id; 2357 }; 2358 2359 static cmdline_parse_token_string_t cmd_resume_port_tm_node_resume = 2360 TOKEN_STRING_INITIALIZER( 2361 struct cmd_resume_port_tm_node_result, resume, "resume"); 2362 static cmdline_parse_token_string_t cmd_resume_port_tm_node_port = 2363 TOKEN_STRING_INITIALIZER( 2364 struct cmd_resume_port_tm_node_result, port, "port"); 2365 static cmdline_parse_token_string_t cmd_resume_port_tm_node_tm = 2366 TOKEN_STRING_INITIALIZER( 2367 struct cmd_resume_port_tm_node_result, tm, "tm"); 2368 static cmdline_parse_token_string_t cmd_resume_port_tm_node_node = 2369 TOKEN_STRING_INITIALIZER( 2370 struct cmd_resume_port_tm_node_result, node, "node"); 2371 static cmdline_parse_token_num_t cmd_resume_port_tm_node_port_id = 2372 TOKEN_NUM_INITIALIZER( 2373 struct cmd_resume_port_tm_node_result, port_id, RTE_UINT16); 2374 static cmdline_parse_token_num_t cmd_resume_port_tm_node_node_id = 2375 TOKEN_NUM_INITIALIZER( 2376 struct cmd_resume_port_tm_node_result, node_id, RTE_UINT32); 2377 2378 static void cmd_resume_port_tm_node_parsed(void *parsed_result, 2379 __rte_unused struct cmdline *cl, 2380 __rte_unused void *data) 2381 { 2382 struct cmd_resume_port_tm_node_result *res = parsed_result; 2383 struct rte_tm_error error; 2384 uint32_t node_id = res->node_id; 2385 portid_t port_id = res->port_id; 2386 int ret; 2387 2388 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2389 return; 2390 2391 memset(&error, 0, sizeof(struct rte_tm_error)); 2392 ret = rte_tm_node_resume(port_id, node_id, &error); 2393 if (ret != 0) { 2394 print_err_msg(&error); 2395 return; 2396 } 2397 } 2398 2399 cmdline_parse_inst_t cmd_resume_port_tm_node = { 2400 .f = cmd_resume_port_tm_node_parsed, 2401 .data = NULL, 2402 .help_str = "Resume port tm node", 2403 .tokens = { 2404 (void *)&cmd_resume_port_tm_node_resume, 2405 (void *)&cmd_resume_port_tm_node_port, 2406 (void *)&cmd_resume_port_tm_node_tm, 2407 (void *)&cmd_resume_port_tm_node_node, 2408 (void *)&cmd_resume_port_tm_node_port_id, 2409 (void *)&cmd_resume_port_tm_node_node_id, 2410 NULL, 2411 }, 2412 }; 2413 2414 /* *** Port TM Hierarchy Commit *** */ 2415 struct cmd_port_tm_hierarchy_commit_result { 2416 cmdline_fixed_string_t port; 2417 cmdline_fixed_string_t tm; 2418 cmdline_fixed_string_t hierarchy; 2419 cmdline_fixed_string_t commit; 2420 uint16_t port_id; 2421 cmdline_fixed_string_t clean_on_fail; 2422 }; 2423 2424 static cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_port = 2425 TOKEN_STRING_INITIALIZER( 2426 struct cmd_port_tm_hierarchy_commit_result, port, "port"); 2427 static cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_tm = 2428 TOKEN_STRING_INITIALIZER( 2429 struct cmd_port_tm_hierarchy_commit_result, tm, "tm"); 2430 static cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_hierarchy = 2431 TOKEN_STRING_INITIALIZER( 2432 struct cmd_port_tm_hierarchy_commit_result, 2433 hierarchy, "hierarchy"); 2434 static cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_commit = 2435 TOKEN_STRING_INITIALIZER( 2436 struct cmd_port_tm_hierarchy_commit_result, commit, "commit"); 2437 static cmdline_parse_token_num_t cmd_port_tm_hierarchy_commit_port_id = 2438 TOKEN_NUM_INITIALIZER( 2439 struct cmd_port_tm_hierarchy_commit_result, 2440 port_id, RTE_UINT16); 2441 static cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_clean_on_fail = 2442 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_hierarchy_commit_result, 2443 clean_on_fail, "yes#no"); 2444 2445 static void cmd_port_tm_hierarchy_commit_parsed(void *parsed_result, 2446 __rte_unused struct cmdline *cl, 2447 __rte_unused void *data) 2448 { 2449 struct cmd_port_tm_hierarchy_commit_result *res = parsed_result; 2450 struct rte_tm_error error; 2451 uint32_t clean_on_fail; 2452 portid_t port_id = res->port_id; 2453 int ret; 2454 2455 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2456 return; 2457 2458 if (strcmp(res->clean_on_fail, "yes") == 0) 2459 clean_on_fail = 1; 2460 else 2461 clean_on_fail = 0; 2462 2463 memset(&error, 0, sizeof(struct rte_tm_error)); 2464 ret = rte_tm_hierarchy_commit(port_id, clean_on_fail, &error); 2465 if (ret != 0) { 2466 print_err_msg(&error); 2467 return; 2468 } 2469 } 2470 2471 cmdline_parse_inst_t cmd_port_tm_hierarchy_commit = { 2472 .f = cmd_port_tm_hierarchy_commit_parsed, 2473 .data = NULL, 2474 .help_str = "Commit port tm hierarchy", 2475 .tokens = { 2476 (void *)&cmd_port_tm_hierarchy_commit_port, 2477 (void *)&cmd_port_tm_hierarchy_commit_tm, 2478 (void *)&cmd_port_tm_hierarchy_commit_hierarchy, 2479 (void *)&cmd_port_tm_hierarchy_commit_commit, 2480 (void *)&cmd_port_tm_hierarchy_commit_port_id, 2481 (void *)&cmd_port_tm_hierarchy_commit_clean_on_fail, 2482 NULL, 2483 }, 2484 }; 2485 2486 /* *** Port TM Mark IP ECN *** */ 2487 struct cmd_port_tm_mark_ip_ecn_result { 2488 cmdline_fixed_string_t set; 2489 cmdline_fixed_string_t port; 2490 cmdline_fixed_string_t tm; 2491 cmdline_fixed_string_t mark; 2492 cmdline_fixed_string_t ip_ecn; 2493 uint16_t port_id; 2494 uint16_t green; 2495 uint16_t yellow; 2496 uint16_t red; 2497 }; 2498 2499 static cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_set = 2500 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result, 2501 set, "set"); 2502 2503 static cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_port = 2504 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result, 2505 port, "port"); 2506 2507 static cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_tm = 2508 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result, tm, 2509 "tm"); 2510 2511 static cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_mark = 2512 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result, 2513 mark, "mark"); 2514 2515 static cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_ip_ecn = 2516 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result, 2517 ip_ecn, "ip_ecn"); 2518 static cmdline_parse_token_num_t cmd_port_tm_mark_ip_ecn_port_id = 2519 TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result, 2520 port_id, RTE_UINT16); 2521 2522 static cmdline_parse_token_num_t cmd_port_tm_mark_ip_ecn_green = 2523 TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result, 2524 green, RTE_UINT16); 2525 static cmdline_parse_token_num_t cmd_port_tm_mark_ip_ecn_yellow = 2526 TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result, 2527 yellow, RTE_UINT16); 2528 static cmdline_parse_token_num_t cmd_port_tm_mark_ip_ecn_red = 2529 TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result, 2530 red, RTE_UINT16); 2531 2532 static void cmd_port_tm_mark_ip_ecn_parsed(void *parsed_result, 2533 __rte_unused struct cmdline *cl, 2534 __rte_unused void *data) 2535 { 2536 struct cmd_port_tm_mark_ip_ecn_result *res = parsed_result; 2537 struct rte_tm_error error; 2538 portid_t port_id = res->port_id; 2539 int green = res->green; 2540 int yellow = res->yellow; 2541 int red = res->red; 2542 int ret; 2543 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2544 return; 2545 2546 memset(&error, 0, sizeof(struct rte_tm_error)); 2547 ret = rte_tm_mark_ip_ecn(port_id, green, yellow, red, &error); 2548 if (ret != 0) { 2549 print_err_msg(&error); 2550 return; 2551 } 2552 } 2553 2554 cmdline_parse_inst_t cmd_port_tm_mark_ip_ecn = { 2555 .f = cmd_port_tm_mark_ip_ecn_parsed, 2556 .data = NULL, 2557 .help_str = "set port tm mark ip_ecn <port> <green> <yellow> <red>", 2558 .tokens = { 2559 (void *)&cmd_port_tm_mark_ip_ecn_set, 2560 (void *)&cmd_port_tm_mark_ip_ecn_port, 2561 (void *)&cmd_port_tm_mark_ip_ecn_tm, 2562 (void *)&cmd_port_tm_mark_ip_ecn_mark, 2563 (void *)&cmd_port_tm_mark_ip_ecn_ip_ecn, 2564 (void *)&cmd_port_tm_mark_ip_ecn_port_id, 2565 (void *)&cmd_port_tm_mark_ip_ecn_green, 2566 (void *)&cmd_port_tm_mark_ip_ecn_yellow, 2567 (void *)&cmd_port_tm_mark_ip_ecn_red, 2568 NULL, 2569 }, 2570 }; 2571 2572 2573 /* *** Port TM Mark IP DSCP *** */ 2574 struct cmd_port_tm_mark_ip_dscp_result { 2575 cmdline_fixed_string_t set; 2576 cmdline_fixed_string_t port; 2577 cmdline_fixed_string_t tm; 2578 cmdline_fixed_string_t mark; 2579 cmdline_fixed_string_t ip_dscp; 2580 uint16_t port_id; 2581 uint16_t green; 2582 uint16_t yellow; 2583 uint16_t red; 2584 }; 2585 2586 static cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_set = 2587 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result, 2588 set, "set"); 2589 2590 static cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_port = 2591 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result, 2592 port, "port"); 2593 2594 static cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_tm = 2595 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result, tm, 2596 "tm"); 2597 2598 static cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_mark = 2599 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result, 2600 mark, "mark"); 2601 2602 static cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_ip_dscp = 2603 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result, 2604 ip_dscp, "ip_dscp"); 2605 static cmdline_parse_token_num_t cmd_port_tm_mark_ip_dscp_port_id = 2606 TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result, 2607 port_id, RTE_UINT16); 2608 2609 static cmdline_parse_token_num_t cmd_port_tm_mark_ip_dscp_green = 2610 TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result, 2611 green, RTE_UINT16); 2612 static cmdline_parse_token_num_t cmd_port_tm_mark_ip_dscp_yellow = 2613 TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result, 2614 yellow, RTE_UINT16); 2615 static cmdline_parse_token_num_t cmd_port_tm_mark_ip_dscp_red = 2616 TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result, 2617 red, RTE_UINT16); 2618 2619 static void cmd_port_tm_mark_ip_dscp_parsed(void *parsed_result, 2620 __rte_unused struct cmdline *cl, 2621 __rte_unused void *data) 2622 { 2623 struct cmd_port_tm_mark_ip_dscp_result *res = parsed_result; 2624 struct rte_tm_error error; 2625 portid_t port_id = res->port_id; 2626 int green = res->green; 2627 int yellow = res->yellow; 2628 int red = res->red; 2629 int ret; 2630 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2631 return; 2632 2633 memset(&error, 0, sizeof(struct rte_tm_error)); 2634 ret = rte_tm_mark_ip_dscp(port_id, green, yellow, red, &error); 2635 if (ret != 0) { 2636 print_err_msg(&error); 2637 return; 2638 } 2639 } 2640 2641 cmdline_parse_inst_t cmd_port_tm_mark_ip_dscp = { 2642 .f = cmd_port_tm_mark_ip_dscp_parsed, 2643 .data = NULL, 2644 .help_str = "set port tm mark ip_dscp <port> <green> <yellow> <red>", 2645 .tokens = { 2646 (void *)&cmd_port_tm_mark_ip_dscp_set, 2647 (void *)&cmd_port_tm_mark_ip_dscp_port, 2648 (void *)&cmd_port_tm_mark_ip_dscp_tm, 2649 (void *)&cmd_port_tm_mark_ip_dscp_mark, 2650 (void *)&cmd_port_tm_mark_ip_dscp_ip_dscp, 2651 (void *)&cmd_port_tm_mark_ip_dscp_port_id, 2652 (void *)&cmd_port_tm_mark_ip_dscp_green, 2653 (void *)&cmd_port_tm_mark_ip_dscp_yellow, 2654 (void *)&cmd_port_tm_mark_ip_dscp_red, 2655 NULL, 2656 }, 2657 }; 2658 2659 2660 /* *** Port TM Mark VLAN_DEI *** */ 2661 struct cmd_port_tm_mark_vlan_dei_result { 2662 cmdline_fixed_string_t set; 2663 cmdline_fixed_string_t port; 2664 cmdline_fixed_string_t tm; 2665 cmdline_fixed_string_t mark; 2666 cmdline_fixed_string_t vlan_dei; 2667 uint16_t port_id; 2668 uint16_t green; 2669 uint16_t yellow; 2670 uint16_t red; 2671 }; 2672 2673 static cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_set = 2674 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result, 2675 set, "set"); 2676 2677 static cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_port = 2678 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result, 2679 port, "port"); 2680 2681 static cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_tm = 2682 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result, tm, 2683 "tm"); 2684 2685 static cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_mark = 2686 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result, 2687 mark, "mark"); 2688 2689 static cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_vlan_dei = 2690 TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result, 2691 vlan_dei, "vlan_dei"); 2692 static cmdline_parse_token_num_t cmd_port_tm_mark_vlan_dei_port_id = 2693 TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result, 2694 port_id, RTE_UINT16); 2695 2696 static cmdline_parse_token_num_t cmd_port_tm_mark_vlan_dei_green = 2697 TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result, 2698 green, RTE_UINT16); 2699 static cmdline_parse_token_num_t cmd_port_tm_mark_vlan_dei_yellow = 2700 TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result, 2701 yellow, RTE_UINT16); 2702 static cmdline_parse_token_num_t cmd_port_tm_mark_vlan_dei_red = 2703 TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result, 2704 red, RTE_UINT16); 2705 2706 static void cmd_port_tm_mark_vlan_dei_parsed(void *parsed_result, 2707 __rte_unused struct cmdline *cl, 2708 __rte_unused void *data) 2709 { 2710 struct cmd_port_tm_mark_vlan_dei_result *res = parsed_result; 2711 struct rte_tm_error error; 2712 portid_t port_id = res->port_id; 2713 int green = res->green; 2714 int yellow = res->yellow; 2715 int red = res->red; 2716 int ret; 2717 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2718 return; 2719 2720 memset(&error, 0, sizeof(struct rte_tm_error)); 2721 ret = rte_tm_mark_vlan_dei(port_id, green, yellow, red, &error); 2722 if (ret != 0) { 2723 print_err_msg(&error); 2724 return; 2725 } 2726 } 2727 2728 cmdline_parse_inst_t cmd_port_tm_mark_vlan_dei = { 2729 .f = cmd_port_tm_mark_vlan_dei_parsed, 2730 .data = NULL, 2731 .help_str = "set port tm mark vlan_dei <port> <green> <yellow> <red>", 2732 .tokens = { 2733 (void *)&cmd_port_tm_mark_vlan_dei_set, 2734 (void *)&cmd_port_tm_mark_vlan_dei_port, 2735 (void *)&cmd_port_tm_mark_vlan_dei_tm, 2736 (void *)&cmd_port_tm_mark_vlan_dei_mark, 2737 (void *)&cmd_port_tm_mark_vlan_dei_vlan_dei, 2738 (void *)&cmd_port_tm_mark_vlan_dei_port_id, 2739 (void *)&cmd_port_tm_mark_vlan_dei_green, 2740 (void *)&cmd_port_tm_mark_vlan_dei_yellow, 2741 (void *)&cmd_port_tm_mark_vlan_dei_red, 2742 NULL, 2743 }, 2744 }; 2745