1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2017 Intel Corporation 3 */ 4 5 #include <errno.h> 6 #include <getopt.h> 7 #include <stdarg.h> 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <signal.h> 11 #include <string.h> 12 #include <time.h> 13 #include <fcntl.h> 14 #include <sys/types.h> 15 16 #include <sys/queue.h> 17 #include <sys/stat.h> 18 19 #include <stdint.h> 20 #include <unistd.h> 21 #include <inttypes.h> 22 23 #include <rte_common.h> 24 #include <rte_byteorder.h> 25 #include <rte_log.h> 26 #include <rte_debug.h> 27 #include <rte_cycles.h> 28 #include <rte_memory.h> 29 #include <rte_launch.h> 30 #include <rte_eal.h> 31 #include <rte_per_lcore.h> 32 #include <rte_lcore.h> 33 #include <rte_branch_prediction.h> 34 #include <rte_mempool.h> 35 #include <rte_interrupts.h> 36 #include <rte_ether.h> 37 #include <rte_ethdev.h> 38 #include <rte_string_fns.h> 39 #include <rte_flow.h> 40 41 #include "testpmd.h" 42 43 static void 44 usage(char* progname) 45 { 46 printf("\nUsage: %s [EAL options] -- [testpmd options]\n\n", 47 progname); 48 #ifdef RTE_LIB_CMDLINE 49 printf(" --interactive: run in interactive mode.\n"); 50 printf(" --cmdline-file: execute cli commands before startup.\n"); 51 #endif 52 printf(" --auto-start: start forwarding on init " 53 "[always when non-interactive].\n"); 54 printf(" --help: display this message and quit.\n"); 55 printf(" --tx-first: start forwarding sending a burst first " 56 "(only if interactive is disabled).\n"); 57 printf(" --stats-period=PERIOD: statistics will be shown " 58 "every PERIOD seconds (only if interactive is disabled).\n"); 59 printf(" --display-xstats xstat_name1[,...]: comma-separated list of " 60 "extended statistics to show. Used with --stats-period " 61 "specified or interactive commands that show Rx/Tx statistics " 62 "(i.e. 'show port stats').\n"); 63 printf(" --num-procs=N: set the total number of multi-process instances.\n"); 64 printf(" --proc-id=id: set the id of the current process from " 65 "multi-process instances (0 <= id < num-procs).\n"); 66 printf(" --nb-cores=N: set the number of forwarding cores " 67 "(1 <= N <= %d).\n", nb_lcores); 68 printf(" --nb-ports=N: set the number of forwarding ports " 69 "(1 <= N <= %d).\n", nb_ports); 70 printf(" --coremask=COREMASK: hexadecimal bitmask of cores running " 71 "the packet forwarding test. The main lcore is reserved for " 72 "command line parsing only, and cannot be masked on for " 73 "packet forwarding.\n"); 74 printf(" --portmask=PORTMASK: hexadecimal bitmask of ports used " 75 "by the packet forwarding test.\n"); 76 printf(" --portlist=PORTLIST: list of forwarding ports\n"); 77 printf(" --numa: enable NUMA-aware allocation of RX/TX rings and of " 78 "RX memory buffers (mbufs).\n"); 79 printf(" --no-numa: disable NUMA-aware allocation.\n"); 80 printf(" --port-numa-config=(port,socket)[,(port,socket)]: " 81 "specify the socket on which the memory pool " 82 "used by the port will be allocated.\n"); 83 printf(" --ring-numa-config=(port,flag,socket)[,(port,flag,socket)]: " 84 "specify the socket on which the TX/RX rings for " 85 "the port will be allocated " 86 "(flag: 1 for RX; 2 for TX; 3 for RX and TX).\n"); 87 printf(" --socket-num=N: set socket from which all memory is allocated " 88 "in NUMA mode.\n"); 89 printf(" --mbuf-size=N,[N1[,..Nn]: set the data size of mbuf to " 90 "N bytes. If multiple numbers are specified the extra pools " 91 "will be created to receive packets based on the features " 92 "supported, like packet split, multi-rx-mempool.\n"); 93 printf(" --total-num-mbufs=N: set the number of mbufs to be allocated " 94 "in mbuf pools.\n"); 95 printf(" --max-pkt-len=N: set the maximum size of packet to N bytes.\n"); 96 printf(" --max-lro-pkt-size=N: set the maximum LRO aggregated packet " 97 "size to N bytes.\n"); 98 #ifdef RTE_LIB_CMDLINE 99 printf(" --eth-peers-configfile=name: config file with ethernet addresses " 100 "of peer ports.\n"); 101 printf(" --eth-peer=X,M:M:M:M:M:M: set the MAC address of the X peer " 102 "port (0 <= X < %d).\n", RTE_MAX_ETHPORTS); 103 #endif 104 #ifdef RTE_LIB_LATENCYSTATS 105 printf(" --latencystats=N: enable latency and jitter statistics " 106 "monitoring on forwarding lcore id N.\n"); 107 #endif 108 printf(" --disable-crc-strip: disable CRC stripping by hardware.\n"); 109 printf(" --enable-scatter: enable scattered Rx.\n"); 110 printf(" --enable-lro: enable large receive offload.\n"); 111 printf(" --enable-rx-cksum: enable rx hardware checksum offload.\n"); 112 printf(" --enable-rx-timestamp: enable rx hardware timestamp offload.\n"); 113 printf(" --enable-hw-vlan: enable hardware vlan.\n"); 114 printf(" --enable-hw-vlan-filter: enable hardware vlan filter.\n"); 115 printf(" --enable-hw-vlan-strip: enable hardware vlan strip.\n"); 116 printf(" --enable-hw-vlan-extend: enable hardware vlan extend.\n"); 117 printf(" --enable-hw-qinq-strip: enable hardware qinq strip.\n"); 118 printf(" --enable-drop-en: enable per queue packet drop.\n"); 119 printf(" --disable-rss: disable rss.\n"); 120 printf(" --port-topology=<paired|chained|loop>: set port topology (paired " 121 "is default).\n"); 122 printf(" --forward-mode=N: set forwarding mode (N: %s).\n", 123 list_pkt_forwarding_modes()); 124 printf(" --forward-mode=5tswap: set forwarding mode to " 125 "swap L2,L3,L4 for MAC, IPv4/IPv6 and TCP/UDP only.\n"); 126 printf(" --rss-ip: set RSS functions to IPv4/IPv6 only .\n"); 127 printf(" --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n"); 128 printf(" --rss-level-inner: set RSS hash level to innermost\n"); 129 printf(" --rss-level-outer: set RSS hash level to outermost\n"); 130 printf(" --rxq=N: set the number of RX queues per port to N.\n"); 131 printf(" --rxd=N: set the number of descriptors in RX rings to N.\n"); 132 printf(" --txq=N: set the number of TX queues per port to N.\n"); 133 printf(" --txd=N: set the number of descriptors in TX rings to N.\n"); 134 printf(" --hairpinq=N: set the number of hairpin queues per port to " 135 "N.\n"); 136 printf(" --burst=N: set the number of packets per burst to N.\n"); 137 printf(" --flowgen-clones=N: set the number of single packet clones to send in flowgen mode. Should be less than burst value.\n"); 138 printf(" --flowgen-flows=N: set the number of flows in flowgen mode to N (1 <= N <= INT32_MAX).\n"); 139 printf(" --mbcache=N: set the cache of mbuf memory pool to N.\n"); 140 printf(" --rxpt=N: set prefetch threshold register of RX rings to N.\n"); 141 printf(" --rxht=N: set the host threshold register of RX rings to N.\n"); 142 printf(" --rxfreet=N: set the free threshold of RX descriptors to N " 143 "(0 <= N < value of rxd).\n"); 144 printf(" --rxwt=N: set the write-back threshold register of RX rings to N.\n"); 145 printf(" --txpt=N: set the prefetch threshold register of TX rings to N.\n"); 146 printf(" --txht=N: set the nhost threshold register of TX rings to N.\n"); 147 printf(" --txwt=N: set the write-back threshold register of TX rings to N.\n"); 148 printf(" --txfreet=N: set the transmit free threshold of TX rings to N " 149 "(0 <= N <= value of txd).\n"); 150 printf(" --txrst=N: set the transmit RS bit threshold of TX rings to N " 151 "(0 <= N <= value of txd).\n"); 152 printf(" --no-flush-rx: Don't flush RX streams before forwarding." 153 " Used mainly with PCAP drivers.\n"); 154 printf(" --rxoffs=X[,Y]*: set RX segment offsets for split.\n"); 155 printf(" --rxpkts=X[,Y]*: set RX segment sizes to split.\n"); 156 printf(" --rxhdrs=eth[,ipv4]*: set RX segment protocol to split.\n"); 157 printf(" --txpkts=X[,Y]*: set TX segment sizes" 158 " or total packet length.\n"); 159 printf(" --multi-rx-mempool: enable multi-rx-mempool support\n"); 160 printf(" --txonly-multi-flow: generate multiple flows in txonly mode\n"); 161 printf(" --tx-ip=src,dst: IP addresses in Tx-only mode\n"); 162 printf(" --tx-udp=src[,dst]: UDP ports in Tx-only mode\n"); 163 printf(" --eth-link-speed: force link speed.\n"); 164 printf(" --rxq-share=X: number of ports per shared Rx queue groups, defaults to UINT32_MAX (1 group)\n"); 165 printf(" --disable-link-check: disable check on link status when " 166 "starting/stopping ports.\n"); 167 printf(" --disable-device-start: do not automatically start port\n"); 168 printf(" --no-lsc-interrupt: disable link status change interrupt.\n"); 169 printf(" --no-rmv-interrupt: disable device removal interrupt.\n"); 170 printf(" --bitrate-stats=N: set the logical core N to perform " 171 "bit-rate calculation.\n"); 172 printf(" --print-event <unknown|intr_lsc|queue_state|intr_reset|vf_mbox|macsec|intr_rmv|flow_aged|err_recovering|recovery_success|recovery_failed|all>: " 173 "enable print of designated event or all of them.\n"); 174 printf(" --mask-event <unknown|intr_lsc|queue_state|intr_reset|vf_mbox|macsec|intr_rmv|flow_aged|err_recovering|recovery_success|recovery_failed||all>: " 175 "disable print of designated event or all of them.\n"); 176 printf(" --flow-isolate-all: " 177 "requests flow API isolated mode on all ports at initialization time.\n"); 178 printf(" --disable-flow-flush: disable port flow flush when stop port.\n"); 179 printf(" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n"); 180 printf(" --rx-offloads=0xXXXXXXXX: hexadecimal bitmask of RX queue offloads\n"); 181 printf(" --hot-plug: enable hot plug for device.\n"); 182 printf(" --vxlan-gpe-port=N: UPD port of tunnel VXLAN-GPE\n"); 183 printf(" --geneve-parsed-port=N: UPD port to parse GENEVE tunnel protocol\n"); 184 #ifndef RTE_EXEC_ENV_WINDOWS 185 printf(" --mlockall: lock all memory\n"); 186 printf(" --no-mlockall: do not lock all memory\n"); 187 #endif 188 printf(" --mp-alloc <native|anon|xmem|xmemhuge>: mempool allocation method.\n" 189 " native: use regular DPDK memory to create and populate mempool\n" 190 " anon: use regular DPDK memory to create and anonymous memory to populate mempool\n" 191 " xmem: use anonymous memory to create and populate mempool\n" 192 " xmemhuge: use anonymous hugepage memory to create and populate mempool\n"); 193 printf(" --noisy-forward-mode=<io|mac|macswap|5tswap>: set the sub-fwd mode, defaults to io\n"); 194 printf(" --noisy-tx-sw-buffer-size=N: size of FIFO buffer\n"); 195 printf(" --noisy-tx-sw-buffer-flushtime=N: flush FIFO after N ms\n"); 196 printf(" --noisy-lkup-memory=N: allocate N MB of VNF memory\n"); 197 printf(" --noisy-lkup-num-writes=N: do N random writes per packet\n"); 198 printf(" --noisy-lkup-num-reads=N: do N random reads per packet\n"); 199 printf(" --noisy-lkup-num-reads-writes=N: do N random reads and writes per packet\n"); 200 printf(" --no-iova-contig: mempool memory can be IOVA non contiguous. " 201 "valid only with --mp-alloc=anon\n"); 202 printf(" --rx-mq-mode=0xX: hexadecimal bitmask of RX mq mode can be " 203 "enabled\n"); 204 printf(" --record-core-cycles: enable measurement of CPU cycles.\n"); 205 printf(" --record-burst-stats: enable display of RX and TX bursts.\n"); 206 printf(" --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n" 207 " 0x10 - explicit Tx rule, 0x02 - hairpin ports paired\n" 208 " 0x01 - hairpin ports loop, 0x00 - hairpin port self\n"); 209 } 210 211 #ifdef RTE_LIB_CMDLINE 212 static int 213 init_peer_eth_addrs(const char *config_filename) 214 { 215 FILE *config_file; 216 portid_t i; 217 char buf[50]; 218 219 config_file = fopen(config_filename, "r"); 220 if (config_file == NULL) { 221 perror("Failed to open eth config file\n"); 222 return -1; 223 } 224 225 for (i = 0; i < RTE_MAX_ETHPORTS; i++) { 226 227 if (fgets(buf, sizeof(buf), config_file) == NULL) 228 break; 229 230 if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) { 231 fprintf(stderr, "Bad MAC address format on line %d\n", 232 i + 1); 233 fclose(config_file); 234 return -1; 235 } 236 } 237 fclose(config_file); 238 nb_peer_eth_addrs = (portid_t) i; 239 return 0; 240 } 241 #endif 242 243 /* 244 * Parse the coremask given as argument (hexadecimal string) and set 245 * the global configuration of forwarding cores. 246 */ 247 static void 248 parse_fwd_coremask(const char *coremask) 249 { 250 char *end; 251 unsigned long long int cm; 252 253 /* parse hexadecimal string */ 254 end = NULL; 255 cm = strtoull(coremask, &end, 16); 256 if ((coremask[0] == '\0') || (end == NULL) || (*end != '\0')) 257 rte_exit(EXIT_FAILURE, "Invalid fwd core mask\n"); 258 else if (set_fwd_lcores_mask((uint64_t) cm) < 0) 259 rte_exit(EXIT_FAILURE, "coremask is not valid\n"); 260 } 261 262 /* 263 * Parse the coremask given as argument (hexadecimal string) and set 264 * the global configuration of forwarding cores. 265 */ 266 static void 267 parse_fwd_portmask(const char *portmask) 268 { 269 char *end; 270 unsigned long long int pm; 271 272 /* parse hexadecimal string */ 273 end = NULL; 274 pm = strtoull(portmask, &end, 16); 275 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0')) 276 rte_exit(EXIT_FAILURE, "Invalid fwd port mask\n"); 277 else 278 set_fwd_ports_mask((uint64_t) pm); 279 } 280 281 static void 282 print_invalid_socket_id_error(void) 283 { 284 unsigned int i = 0; 285 286 fprintf(stderr, "Invalid socket id, options are: "); 287 for (i = 0; i < num_sockets; i++) { 288 fprintf(stderr, "%u%s", socket_ids[i], 289 (i == num_sockets - 1) ? "\n" : ","); 290 } 291 } 292 293 static int 294 parse_portnuma_config(const char *q_arg) 295 { 296 char s[256]; 297 const char *p, *p0 = q_arg; 298 char *end; 299 uint8_t i, socket_id; 300 portid_t port_id; 301 unsigned size; 302 enum fieldnames { 303 FLD_PORT = 0, 304 FLD_SOCKET, 305 _NUM_FLD 306 }; 307 unsigned long int_fld[_NUM_FLD]; 308 char *str_fld[_NUM_FLD]; 309 310 /* reset from value set at definition */ 311 while ((p = strchr(p0,'(')) != NULL) { 312 ++p; 313 if((p0 = strchr(p,')')) == NULL) 314 return -1; 315 316 size = p0 - p; 317 if(size >= sizeof(s)) 318 return -1; 319 320 snprintf(s, sizeof(s), "%.*s", size, p); 321 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD) 322 return -1; 323 for (i = 0; i < _NUM_FLD; i++) { 324 errno = 0; 325 int_fld[i] = strtoul(str_fld[i], &end, 0); 326 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255) 327 return -1; 328 } 329 port_id = (portid_t)int_fld[FLD_PORT]; 330 if (port_id_is_invalid(port_id, ENABLED_WARN) || 331 port_id == (portid_t)RTE_PORT_ALL) { 332 print_valid_ports(); 333 return -1; 334 } 335 socket_id = (uint8_t)int_fld[FLD_SOCKET]; 336 if (new_socket_id(socket_id)) { 337 if (num_sockets >= RTE_MAX_NUMA_NODES) { 338 print_invalid_socket_id_error(); 339 return -1; 340 } 341 socket_ids[num_sockets++] = socket_id; 342 } 343 port_numa[port_id] = socket_id; 344 } 345 346 return 0; 347 } 348 349 static int 350 parse_ringnuma_config(const char *q_arg) 351 { 352 char s[256]; 353 const char *p, *p0 = q_arg; 354 char *end; 355 uint8_t i, ring_flag, socket_id; 356 portid_t port_id; 357 unsigned size; 358 enum fieldnames { 359 FLD_PORT = 0, 360 FLD_FLAG, 361 FLD_SOCKET, 362 _NUM_FLD 363 }; 364 unsigned long int_fld[_NUM_FLD]; 365 char *str_fld[_NUM_FLD]; 366 #define RX_RING_ONLY 0x1 367 #define TX_RING_ONLY 0x2 368 #define RXTX_RING 0x3 369 370 /* reset from value set at definition */ 371 while ((p = strchr(p0,'(')) != NULL) { 372 ++p; 373 if((p0 = strchr(p,')')) == NULL) 374 return -1; 375 376 size = p0 - p; 377 if(size >= sizeof(s)) 378 return -1; 379 380 snprintf(s, sizeof(s), "%.*s", size, p); 381 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD) 382 return -1; 383 for (i = 0; i < _NUM_FLD; i++) { 384 errno = 0; 385 int_fld[i] = strtoul(str_fld[i], &end, 0); 386 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255) 387 return -1; 388 } 389 port_id = (portid_t)int_fld[FLD_PORT]; 390 if (port_id_is_invalid(port_id, ENABLED_WARN) || 391 port_id == (portid_t)RTE_PORT_ALL) { 392 print_valid_ports(); 393 return -1; 394 } 395 socket_id = (uint8_t)int_fld[FLD_SOCKET]; 396 if (new_socket_id(socket_id)) { 397 if (num_sockets >= RTE_MAX_NUMA_NODES) { 398 print_invalid_socket_id_error(); 399 return -1; 400 } 401 socket_ids[num_sockets++] = socket_id; 402 } 403 ring_flag = (uint8_t)int_fld[FLD_FLAG]; 404 if ((ring_flag < RX_RING_ONLY) || (ring_flag > RXTX_RING)) { 405 fprintf(stderr, 406 "Invalid ring-flag=%d config for port =%d\n", 407 ring_flag,port_id); 408 return -1; 409 } 410 411 switch (ring_flag & RXTX_RING) { 412 case RX_RING_ONLY: 413 rxring_numa[port_id] = socket_id; 414 break; 415 case TX_RING_ONLY: 416 txring_numa[port_id] = socket_id; 417 break; 418 case RXTX_RING: 419 rxring_numa[port_id] = socket_id; 420 txring_numa[port_id] = socket_id; 421 break; 422 default: 423 fprintf(stderr, 424 "Invalid ring-flag=%d config for port=%d\n", 425 ring_flag,port_id); 426 break; 427 } 428 } 429 430 return 0; 431 } 432 433 static int 434 parse_event_printing_config(const char *optarg, int enable) 435 { 436 uint32_t mask = 0; 437 438 if (!strcmp(optarg, "unknown")) 439 mask = UINT32_C(1) << RTE_ETH_EVENT_UNKNOWN; 440 else if (!strcmp(optarg, "intr_lsc")) 441 mask = UINT32_C(1) << RTE_ETH_EVENT_INTR_LSC; 442 else if (!strcmp(optarg, "queue_state")) 443 mask = UINT32_C(1) << RTE_ETH_EVENT_QUEUE_STATE; 444 else if (!strcmp(optarg, "intr_reset")) 445 mask = UINT32_C(1) << RTE_ETH_EVENT_INTR_RESET; 446 else if (!strcmp(optarg, "vf_mbox")) 447 mask = UINT32_C(1) << RTE_ETH_EVENT_VF_MBOX; 448 else if (!strcmp(optarg, "ipsec")) 449 mask = UINT32_C(1) << RTE_ETH_EVENT_IPSEC; 450 else if (!strcmp(optarg, "macsec")) 451 mask = UINT32_C(1) << RTE_ETH_EVENT_MACSEC; 452 else if (!strcmp(optarg, "intr_rmv")) 453 mask = UINT32_C(1) << RTE_ETH_EVENT_INTR_RMV; 454 else if (!strcmp(optarg, "dev_probed")) 455 mask = UINT32_C(1) << RTE_ETH_EVENT_NEW; 456 else if (!strcmp(optarg, "dev_released")) 457 mask = UINT32_C(1) << RTE_ETH_EVENT_DESTROY; 458 else if (!strcmp(optarg, "flow_aged")) 459 mask = UINT32_C(1) << RTE_ETH_EVENT_FLOW_AGED; 460 else if (!strcmp(optarg, "err_recovering")) 461 mask = UINT32_C(1) << RTE_ETH_EVENT_ERR_RECOVERING; 462 else if (!strcmp(optarg, "recovery_success")) 463 mask = UINT32_C(1) << RTE_ETH_EVENT_RECOVERY_SUCCESS; 464 else if (!strcmp(optarg, "recovery_failed")) 465 mask = UINT32_C(1) << RTE_ETH_EVENT_RECOVERY_FAILED; 466 else if (!strcmp(optarg, "all")) 467 mask = ~UINT32_C(0); 468 else { 469 fprintf(stderr, "Invalid event: %s\n", optarg); 470 return -1; 471 } 472 if (enable) 473 event_print_mask |= mask; 474 else 475 event_print_mask &= ~mask; 476 return 0; 477 } 478 479 static int 480 parse_xstats_list(const char *in_str, struct rte_eth_xstat_name **xstats, 481 unsigned int *xstats_num) 482 { 483 int max_names_nb, names_nb, nonempty_names_nb; 484 int name, nonempty_name; 485 int stringlen; 486 char **names; 487 char *str; 488 int ret; 489 int i; 490 491 names = NULL; 492 str = strdup(in_str); 493 if (str == NULL) { 494 ret = -ENOMEM; 495 goto out; 496 } 497 stringlen = strlen(str); 498 499 for (i = 0, max_names_nb = 1; str[i] != '\0'; i++) { 500 if (str[i] == ',') 501 max_names_nb++; 502 } 503 504 names = calloc(max_names_nb, sizeof(*names)); 505 if (names == NULL) { 506 ret = -ENOMEM; 507 goto out; 508 } 509 510 names_nb = rte_strsplit(str, stringlen, names, max_names_nb, ','); 511 if (names_nb < 0) { 512 ret = -EINVAL; 513 goto out; 514 } 515 516 nonempty_names_nb = 0; 517 for (i = 0; i < names_nb; i++) { 518 if (names[i][0] == '\0') 519 continue; 520 nonempty_names_nb++; 521 } 522 *xstats = calloc(nonempty_names_nb, sizeof(**xstats)); 523 if (*xstats == NULL) { 524 ret = -ENOMEM; 525 goto out; 526 } 527 528 for (name = nonempty_name = 0; name < names_nb; name++) { 529 if (names[name][0] == '\0') 530 continue; 531 rte_strscpy((*xstats)[nonempty_name].name, names[name], 532 sizeof((*xstats)[nonempty_name].name)); 533 nonempty_name++; 534 } 535 536 *xstats_num = nonempty_names_nb; 537 ret = 0; 538 539 out: 540 free(names); 541 free(str); 542 return ret; 543 } 544 545 static int 546 parse_link_speed(int n) 547 { 548 uint32_t speed = RTE_ETH_LINK_SPEED_FIXED; 549 550 switch (n) { 551 case 1000: 552 speed |= RTE_ETH_LINK_SPEED_1G; 553 break; 554 case 2500: 555 speed |= RTE_ETH_LINK_SPEED_2_5G; 556 break; 557 case 5000: 558 speed |= RTE_ETH_LINK_SPEED_5G; 559 break; 560 case 10000: 561 speed |= RTE_ETH_LINK_SPEED_10G; 562 break; 563 case 25000: 564 speed |= RTE_ETH_LINK_SPEED_25G; 565 break; 566 case 40000: 567 speed |= RTE_ETH_LINK_SPEED_40G; 568 break; 569 case 50000: 570 speed |= RTE_ETH_LINK_SPEED_50G; 571 break; 572 case 100000: 573 speed |= RTE_ETH_LINK_SPEED_100G; 574 break; 575 case 200000: 576 speed |= RTE_ETH_LINK_SPEED_200G; 577 break; 578 case 400000: 579 speed |= RTE_ETH_LINK_SPEED_400G; 580 break; 581 case 100: 582 case 10: 583 default: 584 fprintf(stderr, "Unsupported fixed speed\n"); 585 return 0; 586 } 587 588 return speed; 589 } 590 591 void 592 launch_args_parse(int argc, char** argv) 593 { 594 #define PARAM_PROC_ID "proc-id" 595 #define PARAM_NUM_PROCS "num-procs" 596 597 int n, opt; 598 char **argvopt; 599 int opt_idx; 600 portid_t pid; 601 enum { TX, RX }; 602 /* Default offloads for all ports. */ 603 uint64_t rx_offloads = rx_mode.offloads; 604 uint64_t tx_offloads = tx_mode.offloads; 605 struct rte_eth_dev_info dev_info; 606 uint16_t rec_nb_pkts; 607 int ret; 608 609 static struct option lgopts[] = { 610 { "help", 0, 0, 0 }, 611 #ifdef RTE_LIB_CMDLINE 612 { "interactive", 0, 0, 0 }, 613 { "cmdline-file", 1, 0, 0 }, 614 { "auto-start", 0, 0, 0 }, 615 { "eth-peers-configfile", 1, 0, 0 }, 616 { "eth-peer", 1, 0, 0 }, 617 #endif 618 { "tx-first", 0, 0, 0 }, 619 { "stats-period", 1, 0, 0 }, 620 { "display-xstats", 1, 0, 0 }, 621 { "nb-cores", 1, 0, 0 }, 622 { "nb-ports", 1, 0, 0 }, 623 { "coremask", 1, 0, 0 }, 624 { "portmask", 1, 0, 0 }, 625 { "portlist", 1, 0, 0 }, 626 { "numa", 0, 0, 0 }, 627 { "no-numa", 0, 0, 0 }, 628 { "mp-anon", 0, 0, 0 }, /* deprecated */ 629 { "port-numa-config", 1, 0, 0 }, 630 { "ring-numa-config", 1, 0, 0 }, 631 { "socket-num", 1, 0, 0 }, 632 { "mbuf-size", 1, 0, 0 }, 633 { "total-num-mbufs", 1, 0, 0 }, 634 { "max-pkt-len", 1, 0, 0 }, 635 { "max-lro-pkt-size", 1, 0, 0 }, 636 #ifdef RTE_LIB_LATENCYSTATS 637 { "latencystats", 1, 0, 0 }, 638 #endif 639 #ifdef RTE_LIB_BITRATESTATS 640 { "bitrate-stats", 1, 0, 0 }, 641 #endif 642 { "disable-crc-strip", 0, 0, 0 }, 643 { "enable-lro", 0, 0, 0 }, 644 { "enable-rx-cksum", 0, 0, 0 }, 645 { "enable-rx-timestamp", 0, 0, 0 }, 646 { "enable-scatter", 0, 0, 0 }, 647 { "enable-hw-vlan", 0, 0, 0 }, 648 { "enable-hw-vlan-filter", 0, 0, 0 }, 649 { "enable-hw-vlan-strip", 0, 0, 0 }, 650 { "enable-hw-vlan-extend", 0, 0, 0 }, 651 { "enable-hw-qinq-strip", 0, 0, 0 }, 652 { "enable-drop-en", 0, 0, 0 }, 653 { "disable-rss", 0, 0, 0 }, 654 { "port-topology", 1, 0, 0 }, 655 { "forward-mode", 1, 0, 0 }, 656 { "rss-ip", 0, 0, 0 }, 657 { "rss-udp", 0, 0, 0 }, 658 { "rss-level-outer", 0, 0, 0 }, 659 { "rss-level-inner", 0, 0, 0 }, 660 { "rxq", 1, 0, 0 }, 661 { "txq", 1, 0, 0 }, 662 { "rxd", 1, 0, 0 }, 663 { "txd", 1, 0, 0 }, 664 { "hairpinq", 1, 0, 0 }, 665 { "hairpin-mode", 1, 0, 0 }, 666 { "burst", 1, 0, 0 }, 667 { "flowgen-clones", 1, 0, 0 }, 668 { "flowgen-flows", 1, 0, 0 }, 669 { "mbcache", 1, 0, 0 }, 670 { "txpt", 1, 0, 0 }, 671 { "txht", 1, 0, 0 }, 672 { "txwt", 1, 0, 0 }, 673 { "txfreet", 1, 0, 0 }, 674 { "txrst", 1, 0, 0 }, 675 { "rxpt", 1, 0, 0 }, 676 { "rxht", 1, 0, 0 }, 677 { "rxwt", 1, 0, 0 }, 678 { "rxfreet", 1, 0, 0 }, 679 { "no-flush-rx", 0, 0, 0 }, 680 { "flow-isolate-all", 0, 0, 0 }, 681 { "disable-flow-flush", 0, 0, 0 }, 682 { "rxoffs", 1, 0, 0 }, 683 { "rxpkts", 1, 0, 0 }, 684 { "rxhdrs", 1, 0, 0 }, 685 { "txpkts", 1, 0, 0 }, 686 { "multi-rx-mempool", 0, 0, 0 }, 687 { "txonly-multi-flow", 0, 0, 0 }, 688 { "rxq-share", 2, 0, 0 }, 689 { "eth-link-speed", 1, 0, 0 }, 690 { "disable-link-check", 0, 0, 0 }, 691 { "disable-device-start", 0, 0, 0 }, 692 { "no-lsc-interrupt", 0, 0, 0 }, 693 { "no-rmv-interrupt", 0, 0, 0 }, 694 { "print-event", 1, 0, 0 }, 695 { "mask-event", 1, 0, 0 }, 696 { "tx-offloads", 1, 0, 0 }, 697 { "rx-offloads", 1, 0, 0 }, 698 { "hot-plug", 0, 0, 0 }, 699 { "vxlan-gpe-port", 1, 0, 0 }, 700 { "geneve-parsed-port", 1, 0, 0 }, 701 #ifndef RTE_EXEC_ENV_WINDOWS 702 { "mlockall", 0, 0, 0 }, 703 { "no-mlockall", 0, 0, 0 }, 704 #endif 705 { "mp-alloc", 1, 0, 0 }, 706 { "tx-ip", 1, 0, 0 }, 707 { "tx-udp", 1, 0, 0 }, 708 { "noisy-forward-mode", 1, 0, 0 }, 709 { "noisy-tx-sw-buffer-size", 1, 0, 0 }, 710 { "noisy-tx-sw-buffer-flushtime", 1, 0, 0 }, 711 { "noisy-lkup-memory", 1, 0, 0 }, 712 { "noisy-lkup-num-writes", 1, 0, 0 }, 713 { "noisy-lkup-num-reads", 1, 0, 0 }, 714 { "noisy-lkup-num-reads-writes", 1, 0, 0 }, 715 { "no-iova-contig", 0, 0, 0 }, 716 { "rx-mq-mode", 1, 0, 0 }, 717 { "record-core-cycles", 0, 0, 0 }, 718 { "record-burst-stats", 0, 0, 0 }, 719 { PARAM_NUM_PROCS, 1, 0, 0 }, 720 { PARAM_PROC_ID, 1, 0, 0 }, 721 { 0, 0, 0, 0 }, 722 }; 723 724 argvopt = argv; 725 726 #ifdef RTE_LIB_CMDLINE 727 #define SHORTOPTS "i" 728 #else 729 #define SHORTOPTS "" 730 #endif 731 while ((opt = getopt_long(argc, argvopt, SHORTOPTS "ah", 732 lgopts, &opt_idx)) != EOF) { 733 switch (opt) { 734 #ifdef RTE_LIB_CMDLINE 735 case 'i': 736 printf("Interactive-mode selected\n"); 737 interactive = 1; 738 break; 739 #endif 740 case 'a': 741 printf("Auto-start selected\n"); 742 auto_start = 1; 743 break; 744 745 case 0: /*long options */ 746 if (!strcmp(lgopts[opt_idx].name, "help")) { 747 usage(argv[0]); 748 exit(EXIT_SUCCESS); 749 } 750 #ifdef RTE_LIB_CMDLINE 751 if (!strcmp(lgopts[opt_idx].name, "interactive")) { 752 printf("Interactive-mode selected\n"); 753 interactive = 1; 754 } 755 if (!strcmp(lgopts[opt_idx].name, "cmdline-file")) { 756 printf("CLI commands to be read from %s\n", 757 optarg); 758 strlcpy(cmdline_filename, optarg, 759 sizeof(cmdline_filename)); 760 } 761 if (!strcmp(lgopts[opt_idx].name, "auto-start")) { 762 printf("Auto-start selected\n"); 763 auto_start = 1; 764 } 765 if (!strcmp(lgopts[opt_idx].name, "tx-first")) { 766 printf("Ports to start sending a burst of " 767 "packets first\n"); 768 tx_first = 1; 769 } 770 if (!strcmp(lgopts[opt_idx].name, "stats-period")) { 771 char *end = NULL; 772 unsigned int n; 773 774 n = strtoul(optarg, &end, 10); 775 if ((optarg[0] == '\0') || (end == NULL) || 776 (*end != '\0')) 777 break; 778 779 stats_period = n; 780 break; 781 } 782 if (!strcmp(lgopts[opt_idx].name, "display-xstats")) { 783 char rc; 784 785 rc = parse_xstats_list(optarg, &xstats_display, 786 &xstats_display_num); 787 if (rc != 0) 788 rte_exit(EXIT_FAILURE, 789 "Failed to parse display-xstats argument: %d\n", 790 rc); 791 } 792 if (!strcmp(lgopts[opt_idx].name, 793 "eth-peers-configfile")) { 794 if (init_peer_eth_addrs(optarg) != 0) 795 rte_exit(EXIT_FAILURE, 796 "Cannot open logfile\n"); 797 } 798 if (!strcmp(lgopts[opt_idx].name, "eth-peer")) { 799 char *port_end; 800 801 errno = 0; 802 n = strtoul(optarg, &port_end, 10); 803 if (errno != 0 || port_end == optarg || *port_end++ != ',') 804 rte_exit(EXIT_FAILURE, 805 "Invalid eth-peer: %s", optarg); 806 if (n >= RTE_MAX_ETHPORTS) 807 rte_exit(EXIT_FAILURE, 808 "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n", 809 n, RTE_MAX_ETHPORTS); 810 811 if (rte_ether_unformat_addr(port_end, 812 &peer_eth_addrs[n]) < 0) 813 rte_exit(EXIT_FAILURE, 814 "Invalid ethernet address: %s\n", 815 port_end); 816 nb_peer_eth_addrs++; 817 } 818 #endif 819 if (!strcmp(lgopts[opt_idx].name, "tx-ip")) { 820 struct in_addr in; 821 char *end; 822 823 end = strchr(optarg, ','); 824 if (end == optarg || !end) 825 rte_exit(EXIT_FAILURE, 826 "Invalid tx-ip: %s", optarg); 827 828 *end++ = 0; 829 if (inet_pton(AF_INET, optarg, &in) == 0) 830 rte_exit(EXIT_FAILURE, 831 "Invalid source IP address: %s\n", 832 optarg); 833 tx_ip_src_addr = rte_be_to_cpu_32(in.s_addr); 834 835 if (inet_pton(AF_INET, end, &in) == 0) 836 rte_exit(EXIT_FAILURE, 837 "Invalid destination IP address: %s\n", 838 optarg); 839 tx_ip_dst_addr = rte_be_to_cpu_32(in.s_addr); 840 } 841 if (!strcmp(lgopts[opt_idx].name, "tx-udp")) { 842 char *end = NULL; 843 844 errno = 0; 845 n = strtoul(optarg, &end, 10); 846 if (errno != 0 || end == optarg || 847 n > UINT16_MAX || 848 !(*end == '\0' || *end == ',')) 849 rte_exit(EXIT_FAILURE, 850 "Invalid UDP port: %s\n", 851 optarg); 852 tx_udp_src_port = n; 853 if (*end == ',') { 854 char *dst = end + 1; 855 856 n = strtoul(dst, &end, 10); 857 if (errno != 0 || end == dst || 858 n > UINT16_MAX || *end) 859 rte_exit(EXIT_FAILURE, 860 "Invalid destination UDP port: %s\n", 861 dst); 862 tx_udp_dst_port = n; 863 } else { 864 tx_udp_dst_port = n; 865 } 866 867 } 868 if (!strcmp(lgopts[opt_idx].name, "nb-ports")) { 869 n = atoi(optarg); 870 if (n > 0 && n <= nb_ports) 871 nb_fwd_ports = n; 872 else 873 rte_exit(EXIT_FAILURE, 874 "Invalid port %d\n", n); 875 } 876 if (!strcmp(lgopts[opt_idx].name, "nb-cores")) { 877 n = atoi(optarg); 878 if (n > 0 && n <= nb_lcores) 879 nb_fwd_lcores = (uint8_t) n; 880 else 881 rte_exit(EXIT_FAILURE, 882 "nb-cores should be > 0 and <= %d\n", 883 nb_lcores); 884 } 885 if (!strcmp(lgopts[opt_idx].name, "coremask")) 886 parse_fwd_coremask(optarg); 887 if (!strcmp(lgopts[opt_idx].name, "portmask")) 888 parse_fwd_portmask(optarg); 889 if (!strcmp(lgopts[opt_idx].name, "portlist")) 890 parse_fwd_portlist(optarg); 891 if (!strcmp(lgopts[opt_idx].name, "no-numa")) 892 numa_support = 0; 893 if (!strcmp(lgopts[opt_idx].name, "numa")) 894 numa_support = 1; 895 if (!strcmp(lgopts[opt_idx].name, "mp-anon")) { 896 mp_alloc_type = MP_ALLOC_ANON; 897 } 898 if (!strcmp(lgopts[opt_idx].name, "mp-alloc")) { 899 if (!strcmp(optarg, "native")) 900 mp_alloc_type = MP_ALLOC_NATIVE; 901 else if (!strcmp(optarg, "anon")) 902 mp_alloc_type = MP_ALLOC_ANON; 903 else if (!strcmp(optarg, "xmem")) 904 mp_alloc_type = MP_ALLOC_XMEM; 905 else if (!strcmp(optarg, "xmemhuge")) 906 mp_alloc_type = MP_ALLOC_XMEM_HUGE; 907 else if (!strcmp(optarg, "xbuf")) 908 mp_alloc_type = MP_ALLOC_XBUF; 909 else 910 rte_exit(EXIT_FAILURE, 911 "mp-alloc %s invalid - must be: " 912 "native, anon, xmem or xmemhuge\n", 913 optarg); 914 } 915 if (!strcmp(lgopts[opt_idx].name, "port-numa-config")) { 916 if (parse_portnuma_config(optarg)) 917 rte_exit(EXIT_FAILURE, 918 "invalid port-numa configuration\n"); 919 } 920 if (!strcmp(lgopts[opt_idx].name, "ring-numa-config")) 921 if (parse_ringnuma_config(optarg)) 922 rte_exit(EXIT_FAILURE, 923 "invalid ring-numa configuration\n"); 924 if (!strcmp(lgopts[opt_idx].name, "socket-num")) { 925 n = atoi(optarg); 926 if (!new_socket_id((uint8_t)n)) { 927 socket_num = (uint8_t)n; 928 } else { 929 print_invalid_socket_id_error(); 930 rte_exit(EXIT_FAILURE, 931 "Invalid socket id"); 932 } 933 } 934 if (!strcmp(lgopts[opt_idx].name, "mbuf-size")) { 935 unsigned int mb_sz[MAX_SEGS_BUFFER_SPLIT]; 936 unsigned int nb_segs, i; 937 938 nb_segs = parse_item_list(optarg, "mbuf-size", 939 MAX_SEGS_BUFFER_SPLIT, mb_sz, 0); 940 if (nb_segs <= 0) 941 rte_exit(EXIT_FAILURE, 942 "bad mbuf-size\n"); 943 for (i = 0; i < nb_segs; i++) { 944 if (mb_sz[i] <= 0 || mb_sz[i] > 0xFFFF) 945 rte_exit(EXIT_FAILURE, 946 "mbuf-size should be " 947 "> 0 and < 65536\n"); 948 mbuf_data_size[i] = (uint16_t) mb_sz[i]; 949 } 950 mbuf_data_size_n = nb_segs; 951 } 952 if (!strcmp(lgopts[opt_idx].name, "total-num-mbufs")) { 953 n = atoi(optarg); 954 if (n > MIN_TOTAL_NUM_MBUFS) 955 param_total_num_mbufs = (unsigned)n; 956 else 957 rte_exit(EXIT_FAILURE, 958 "total-num-mbufs should be > %d\n", 959 MIN_TOTAL_NUM_MBUFS); 960 } 961 if (!strcmp(lgopts[opt_idx].name, "max-pkt-len")) { 962 n = atoi(optarg); 963 if (n >= RTE_ETHER_MIN_LEN) 964 max_rx_pkt_len = n; 965 else 966 rte_exit(EXIT_FAILURE, 967 "Invalid max-pkt-len=%d - should be > %d\n", 968 n, RTE_ETHER_MIN_LEN); 969 } 970 if (!strcmp(lgopts[opt_idx].name, "max-lro-pkt-size")) { 971 n = atoi(optarg); 972 rx_mode.max_lro_pkt_size = (uint32_t) n; 973 } 974 #ifdef RTE_LIB_LATENCYSTATS 975 if (!strcmp(lgopts[opt_idx].name, 976 "latencystats")) { 977 n = atoi(optarg); 978 if (n >= 0) { 979 latencystats_lcore_id = (lcoreid_t) n; 980 latencystats_enabled = 1; 981 } else 982 rte_exit(EXIT_FAILURE, 983 "invalid lcore id %d for latencystats" 984 " must be >= 0\n", n); 985 } 986 #endif 987 #ifdef RTE_LIB_BITRATESTATS 988 if (!strcmp(lgopts[opt_idx].name, "bitrate-stats")) { 989 n = atoi(optarg); 990 if (n >= 0) { 991 bitrate_lcore_id = (lcoreid_t) n; 992 bitrate_enabled = 1; 993 } else 994 rte_exit(EXIT_FAILURE, 995 "invalid lcore id %d for bitrate stats" 996 " must be >= 0\n", n); 997 } 998 #endif 999 if (!strcmp(lgopts[opt_idx].name, "disable-crc-strip")) 1000 rx_offloads |= RTE_ETH_RX_OFFLOAD_KEEP_CRC; 1001 if (!strcmp(lgopts[opt_idx].name, "enable-lro")) 1002 rx_offloads |= RTE_ETH_RX_OFFLOAD_TCP_LRO; 1003 if (!strcmp(lgopts[opt_idx].name, "enable-scatter")) 1004 rx_offloads |= RTE_ETH_RX_OFFLOAD_SCATTER; 1005 if (!strcmp(lgopts[opt_idx].name, "enable-rx-cksum")) 1006 rx_offloads |= RTE_ETH_RX_OFFLOAD_CHECKSUM; 1007 if (!strcmp(lgopts[opt_idx].name, 1008 "enable-rx-timestamp")) 1009 rx_offloads |= RTE_ETH_RX_OFFLOAD_TIMESTAMP; 1010 if (!strcmp(lgopts[opt_idx].name, "enable-hw-vlan")) 1011 rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN; 1012 1013 if (!strcmp(lgopts[opt_idx].name, 1014 "enable-hw-vlan-filter")) 1015 rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER; 1016 1017 if (!strcmp(lgopts[opt_idx].name, 1018 "enable-hw-vlan-strip")) 1019 rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP; 1020 1021 if (!strcmp(lgopts[opt_idx].name, 1022 "enable-hw-vlan-extend")) 1023 rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND; 1024 1025 if (!strcmp(lgopts[opt_idx].name, 1026 "enable-hw-qinq-strip")) 1027 rx_offloads |= RTE_ETH_RX_OFFLOAD_QINQ_STRIP; 1028 1029 if (!strcmp(lgopts[opt_idx].name, "enable-drop-en")) 1030 rx_drop_en = 1; 1031 1032 if (!strcmp(lgopts[opt_idx].name, "disable-rss")) 1033 rss_hf = 0; 1034 if (!strcmp(lgopts[opt_idx].name, "port-topology")) { 1035 if (!strcmp(optarg, "paired")) 1036 port_topology = PORT_TOPOLOGY_PAIRED; 1037 else if (!strcmp(optarg, "chained")) 1038 port_topology = PORT_TOPOLOGY_CHAINED; 1039 else if (!strcmp(optarg, "loop")) 1040 port_topology = PORT_TOPOLOGY_LOOP; 1041 else 1042 rte_exit(EXIT_FAILURE, "port-topology %s invalid -" 1043 " must be: paired, chained or loop\n", 1044 optarg); 1045 } 1046 if (!strcmp(lgopts[opt_idx].name, "forward-mode")) 1047 set_pkt_forwarding_mode(optarg); 1048 if (!strcmp(lgopts[opt_idx].name, "rss-ip")) 1049 rss_hf = RTE_ETH_RSS_IP; 1050 if (!strcmp(lgopts[opt_idx].name, "rss-udp")) 1051 rss_hf = RTE_ETH_RSS_UDP; 1052 if (!strcmp(lgopts[opt_idx].name, "rss-level-inner")) 1053 rss_hf |= RTE_ETH_RSS_LEVEL_INNERMOST; 1054 if (!strcmp(lgopts[opt_idx].name, "rss-level-outer")) 1055 rss_hf |= RTE_ETH_RSS_LEVEL_OUTERMOST; 1056 if (!strcmp(lgopts[opt_idx].name, "rxq")) { 1057 n = atoi(optarg); 1058 if (n >= 0 && check_nb_rxq((queueid_t)n) == 0) 1059 nb_rxq = (queueid_t) n; 1060 else 1061 rte_exit(EXIT_FAILURE, "rxq %d invalid - must be" 1062 " >= 0 && <= %u\n", n, 1063 get_allowed_max_nb_rxq(&pid)); 1064 } 1065 if (!strcmp(lgopts[opt_idx].name, "txq")) { 1066 n = atoi(optarg); 1067 if (n >= 0 && check_nb_txq((queueid_t)n) == 0) 1068 nb_txq = (queueid_t) n; 1069 else 1070 rte_exit(EXIT_FAILURE, "txq %d invalid - must be" 1071 " >= 0 && <= %u\n", n, 1072 get_allowed_max_nb_txq(&pid)); 1073 } 1074 if (!strcmp(lgopts[opt_idx].name, "hairpinq")) { 1075 n = atoi(optarg); 1076 if (n >= 0 && 1077 check_nb_hairpinq((queueid_t)n) == 0) 1078 nb_hairpinq = (queueid_t) n; 1079 else 1080 rte_exit(EXIT_FAILURE, "txq %d invalid - must be" 1081 " >= 0 && <= %u\n", n, 1082 get_allowed_max_nb_hairpinq 1083 (&pid)); 1084 if ((n + nb_txq) < 0 || 1085 check_nb_txq((queueid_t)(n + nb_txq)) != 0) 1086 rte_exit(EXIT_FAILURE, "txq + hairpinq " 1087 "%d invalid - must be" 1088 " >= 0 && <= %u\n", 1089 n + nb_txq, 1090 get_allowed_max_nb_txq(&pid)); 1091 if ((n + nb_rxq) < 0 || 1092 check_nb_rxq((queueid_t)(n + nb_rxq)) != 0) 1093 rte_exit(EXIT_FAILURE, "rxq + hairpinq " 1094 "%d invalid - must be" 1095 " >= 0 && <= %u\n", 1096 n + nb_rxq, 1097 get_allowed_max_nb_rxq(&pid)); 1098 } 1099 if (!nb_rxq && !nb_txq) { 1100 rte_exit(EXIT_FAILURE, "Either rx or tx queues should " 1101 "be non-zero\n"); 1102 } 1103 if (!strcmp(lgopts[opt_idx].name, "hairpin-mode")) { 1104 char *end = NULL; 1105 unsigned int n; 1106 1107 errno = 0; 1108 n = strtoul(optarg, &end, 0); 1109 if (errno != 0 || end == optarg) 1110 rte_exit(EXIT_FAILURE, "hairpin mode invalid\n"); 1111 else 1112 hairpin_mode = (uint32_t)n; 1113 } 1114 if (!strcmp(lgopts[opt_idx].name, "burst")) { 1115 n = atoi(optarg); 1116 if (n == 0) { 1117 /* A burst size of zero means that the 1118 * PMD should be queried for 1119 * recommended Rx burst size. Since 1120 * testpmd uses a single size for all 1121 * ports, port 0 is queried for the 1122 * value, on the assumption that all 1123 * ports are of the same NIC model. 1124 */ 1125 ret = eth_dev_info_get_print_err( 1126 0, 1127 &dev_info); 1128 if (ret != 0) 1129 return; 1130 1131 rec_nb_pkts = dev_info 1132 .default_rxportconf.burst_size; 1133 1134 if (rec_nb_pkts == 0) 1135 rte_exit(EXIT_FAILURE, 1136 "PMD does not recommend a burst size. " 1137 "Provided value must be between " 1138 "1 and %d\n", MAX_PKT_BURST); 1139 else if (rec_nb_pkts > MAX_PKT_BURST) 1140 rte_exit(EXIT_FAILURE, 1141 "PMD recommended burst size of %d" 1142 " exceeds maximum value of %d\n", 1143 rec_nb_pkts, MAX_PKT_BURST); 1144 printf("Using PMD-provided burst value of %d\n", 1145 rec_nb_pkts); 1146 nb_pkt_per_burst = rec_nb_pkts; 1147 } else if (n > MAX_PKT_BURST) 1148 rte_exit(EXIT_FAILURE, 1149 "burst must be between1 and %d\n", 1150 MAX_PKT_BURST); 1151 else 1152 nb_pkt_per_burst = (uint16_t) n; 1153 } 1154 if (!strcmp(lgopts[opt_idx].name, "flowgen-clones")) { 1155 n = atoi(optarg); 1156 if (n >= 0) 1157 nb_pkt_flowgen_clones = (uint16_t) n; 1158 else 1159 rte_exit(EXIT_FAILURE, 1160 "clones must be >= 0 and <= current burst\n"); 1161 } 1162 if (!strcmp(lgopts[opt_idx].name, "flowgen-flows")) { 1163 n = atoi(optarg); 1164 if (n > 0) 1165 nb_flows_flowgen = (int) n; 1166 else 1167 rte_exit(EXIT_FAILURE, 1168 "flows must be >= 1\n"); 1169 } 1170 if (!strcmp(lgopts[opt_idx].name, "mbcache")) { 1171 n = atoi(optarg); 1172 if ((n >= 0) && 1173 (n <= RTE_MEMPOOL_CACHE_MAX_SIZE)) 1174 mb_mempool_cache = (uint16_t) n; 1175 else 1176 rte_exit(EXIT_FAILURE, 1177 "mbcache must be >= 0 and <= %d\n", 1178 RTE_MEMPOOL_CACHE_MAX_SIZE); 1179 } 1180 if (!strcmp(lgopts[opt_idx].name, "txfreet")) { 1181 n = atoi(optarg); 1182 if (n >= 0) 1183 tx_free_thresh = (int16_t)n; 1184 else 1185 rte_exit(EXIT_FAILURE, "txfreet must be >= 0\n"); 1186 } 1187 if (!strcmp(lgopts[opt_idx].name, "txrst")) { 1188 n = atoi(optarg); 1189 if (n >= 0) 1190 tx_rs_thresh = (int16_t)n; 1191 else 1192 rte_exit(EXIT_FAILURE, "txrst must be >= 0\n"); 1193 } 1194 if (!strcmp(lgopts[opt_idx].name, "rxd")) { 1195 n = atoi(optarg); 1196 if (n > 0) { 1197 if (rx_free_thresh >= n) 1198 rte_exit(EXIT_FAILURE, 1199 "rxd must be > " 1200 "rx_free_thresh(%d)\n", 1201 (int)rx_free_thresh); 1202 else 1203 nb_rxd = (uint16_t) n; 1204 } else 1205 rte_exit(EXIT_FAILURE, 1206 "rxd(%d) invalid - must be > 0\n", 1207 n); 1208 } 1209 if (!strcmp(lgopts[opt_idx].name, "txd")) { 1210 n = atoi(optarg); 1211 if (n > 0) 1212 nb_txd = (uint16_t) n; 1213 else 1214 rte_exit(EXIT_FAILURE, "txd must be in > 0\n"); 1215 } 1216 if (!strcmp(lgopts[opt_idx].name, "txpt")) { 1217 n = atoi(optarg); 1218 if (n >= 0) 1219 tx_pthresh = (int8_t)n; 1220 else 1221 rte_exit(EXIT_FAILURE, "txpt must be >= 0\n"); 1222 } 1223 if (!strcmp(lgopts[opt_idx].name, "txht")) { 1224 n = atoi(optarg); 1225 if (n >= 0) 1226 tx_hthresh = (int8_t)n; 1227 else 1228 rte_exit(EXIT_FAILURE, "txht must be >= 0\n"); 1229 } 1230 if (!strcmp(lgopts[opt_idx].name, "txwt")) { 1231 n = atoi(optarg); 1232 if (n >= 0) 1233 tx_wthresh = (int8_t)n; 1234 else 1235 rte_exit(EXIT_FAILURE, "txwt must be >= 0\n"); 1236 } 1237 if (!strcmp(lgopts[opt_idx].name, "rxpt")) { 1238 n = atoi(optarg); 1239 if (n >= 0) 1240 rx_pthresh = (int8_t)n; 1241 else 1242 rte_exit(EXIT_FAILURE, "rxpt must be >= 0\n"); 1243 } 1244 if (!strcmp(lgopts[opt_idx].name, "rxht")) { 1245 n = atoi(optarg); 1246 if (n >= 0) 1247 rx_hthresh = (int8_t)n; 1248 else 1249 rte_exit(EXIT_FAILURE, "rxht must be >= 0\n"); 1250 } 1251 if (!strcmp(lgopts[opt_idx].name, "rxwt")) { 1252 n = atoi(optarg); 1253 if (n >= 0) 1254 rx_wthresh = (int8_t)n; 1255 else 1256 rte_exit(EXIT_FAILURE, "rxwt must be >= 0\n"); 1257 } 1258 if (!strcmp(lgopts[opt_idx].name, "rxfreet")) { 1259 n = atoi(optarg); 1260 if (n >= 0) 1261 rx_free_thresh = (int16_t)n; 1262 else 1263 rte_exit(EXIT_FAILURE, "rxfreet must be >= 0\n"); 1264 } 1265 if (!strcmp(lgopts[opt_idx].name, "rxoffs")) { 1266 unsigned int seg_off[MAX_SEGS_BUFFER_SPLIT]; 1267 unsigned int nb_offs; 1268 1269 nb_offs = parse_item_list 1270 (optarg, "rxpkt offsets", 1271 MAX_SEGS_BUFFER_SPLIT, 1272 seg_off, 0); 1273 if (nb_offs > 0) 1274 set_rx_pkt_offsets(seg_off, nb_offs); 1275 else 1276 rte_exit(EXIT_FAILURE, "bad rxoffs\n"); 1277 } 1278 if (!strcmp(lgopts[opt_idx].name, "rxpkts")) { 1279 unsigned int seg_len[MAX_SEGS_BUFFER_SPLIT]; 1280 unsigned int nb_segs; 1281 nb_segs = parse_item_list 1282 (optarg, "rxpkt segments", 1283 MAX_SEGS_BUFFER_SPLIT, 1284 seg_len, 0); 1285 if (nb_segs > 0) 1286 set_rx_pkt_segments(seg_len, nb_segs); 1287 else 1288 rte_exit(EXIT_FAILURE, "bad rxpkts\n"); 1289 } 1290 if (!strcmp(lgopts[opt_idx].name, "rxhdrs")) { 1291 unsigned int seg_hdrs[MAX_SEGS_BUFFER_SPLIT]; 1292 unsigned int nb_segs; 1293 1294 nb_segs = parse_hdrs_list 1295 (optarg, "rxpkt segments", 1296 MAX_SEGS_BUFFER_SPLIT, 1297 seg_hdrs); 1298 if (nb_segs > 0) 1299 set_rx_pkt_hdrs(seg_hdrs, nb_segs); 1300 else 1301 rte_exit(EXIT_FAILURE, "bad rxpkts\n"); 1302 } 1303 if (!strcmp(lgopts[opt_idx].name, "txpkts")) { 1304 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT]; 1305 unsigned int nb_segs; 1306 1307 nb_segs = parse_item_list(optarg, "txpkt segments", 1308 RTE_MAX_SEGS_PER_PKT, seg_lengths, 0); 1309 if (nb_segs > 0) 1310 set_tx_pkt_segments(seg_lengths, nb_segs); 1311 else 1312 rte_exit(EXIT_FAILURE, "bad txpkts\n"); 1313 } 1314 if (!strcmp(lgopts[opt_idx].name, "multi-rx-mempool")) 1315 multi_rx_mempool = 1; 1316 if (!strcmp(lgopts[opt_idx].name, "txonly-multi-flow")) 1317 txonly_multi_flow = 1; 1318 if (!strcmp(lgopts[opt_idx].name, "rxq-share")) { 1319 if (optarg == NULL) { 1320 rxq_share = UINT32_MAX; 1321 } else { 1322 n = atoi(optarg); 1323 if (n >= 0) 1324 rxq_share = (uint32_t)n; 1325 else 1326 rte_exit(EXIT_FAILURE, "rxq-share must be >= 0\n"); 1327 } 1328 } 1329 if (!strcmp(lgopts[opt_idx].name, "no-flush-rx")) 1330 no_flush_rx = 1; 1331 if (!strcmp(lgopts[opt_idx].name, "eth-link-speed")) { 1332 n = atoi(optarg); 1333 if (n >= 0 && parse_link_speed(n) > 0) 1334 eth_link_speed = parse_link_speed(n); 1335 } 1336 if (!strcmp(lgopts[opt_idx].name, "disable-link-check")) 1337 no_link_check = 1; 1338 if (!strcmp(lgopts[opt_idx].name, "disable-device-start")) 1339 no_device_start = 1; 1340 if (!strcmp(lgopts[opt_idx].name, "no-lsc-interrupt")) 1341 lsc_interrupt = 0; 1342 if (!strcmp(lgopts[opt_idx].name, "no-rmv-interrupt")) 1343 rmv_interrupt = 0; 1344 if (!strcmp(lgopts[opt_idx].name, "flow-isolate-all")) 1345 flow_isolate_all = 1; 1346 if (!strcmp(lgopts[opt_idx].name, "disable-flow-flush")) 1347 no_flow_flush = 1; 1348 if (!strcmp(lgopts[opt_idx].name, "tx-offloads")) { 1349 char *end = NULL; 1350 n = strtoull(optarg, &end, 16); 1351 if (n >= 0) 1352 tx_offloads = (uint64_t)n; 1353 else 1354 rte_exit(EXIT_FAILURE, 1355 "tx-offloads must be >= 0\n"); 1356 } 1357 1358 if (!strcmp(lgopts[opt_idx].name, "rx-offloads")) { 1359 char *end = NULL; 1360 n = strtoull(optarg, &end, 16); 1361 if (n >= 0) 1362 rx_offloads = (uint64_t)n; 1363 else 1364 rte_exit(EXIT_FAILURE, 1365 "rx-offloads must be >= 0\n"); 1366 } 1367 1368 if (!strcmp(lgopts[opt_idx].name, "vxlan-gpe-port")) { 1369 n = atoi(optarg); 1370 if (n >= 0) 1371 vxlan_gpe_udp_port = (uint16_t)n; 1372 else 1373 rte_exit(EXIT_FAILURE, 1374 "vxlan-gpe-port must be >= 0\n"); 1375 } 1376 if (!strcmp(lgopts[opt_idx].name, 1377 "geneve-parsed-port")) { 1378 n = atoi(optarg); 1379 if (n >= 0) 1380 geneve_udp_port = (uint16_t)n; 1381 else 1382 rte_exit(EXIT_FAILURE, 1383 "geneve-parsed-port must be >= 0\n"); 1384 } 1385 if (!strcmp(lgopts[opt_idx].name, "print-event")) 1386 if (parse_event_printing_config(optarg, 1)) { 1387 rte_exit(EXIT_FAILURE, 1388 "invalid print-event argument\n"); 1389 } 1390 if (!strcmp(lgopts[opt_idx].name, "mask-event")) 1391 if (parse_event_printing_config(optarg, 0)) { 1392 rte_exit(EXIT_FAILURE, 1393 "invalid mask-event argument\n"); 1394 } 1395 if (!strcmp(lgopts[opt_idx].name, "hot-plug")) 1396 hot_plug = 1; 1397 if (!strcmp(lgopts[opt_idx].name, "mlockall")) 1398 do_mlockall = 1; 1399 if (!strcmp(lgopts[opt_idx].name, "no-mlockall")) 1400 do_mlockall = 0; 1401 if (!strcmp(lgopts[opt_idx].name, 1402 "noisy-tx-sw-buffer-size")) { 1403 n = atoi(optarg); 1404 if (n >= 0) 1405 noisy_tx_sw_bufsz = n; 1406 else 1407 rte_exit(EXIT_FAILURE, 1408 "noisy-tx-sw-buffer-size must be >= 0\n"); 1409 } 1410 if (!strcmp(lgopts[opt_idx].name, 1411 "noisy-tx-sw-buffer-flushtime")) { 1412 n = atoi(optarg); 1413 if (n >= 0) 1414 noisy_tx_sw_buf_flush_time = n; 1415 else 1416 rte_exit(EXIT_FAILURE, 1417 "noisy-tx-sw-buffer-flushtime must be >= 0\n"); 1418 } 1419 if (!strcmp(lgopts[opt_idx].name, 1420 "noisy-lkup-memory")) { 1421 n = atoi(optarg); 1422 if (n >= 0) 1423 noisy_lkup_mem_sz = n; 1424 else 1425 rte_exit(EXIT_FAILURE, 1426 "noisy-lkup-memory must be >= 0\n"); 1427 } 1428 if (!strcmp(lgopts[opt_idx].name, 1429 "noisy-lkup-num-writes")) { 1430 n = atoi(optarg); 1431 if (n >= 0) 1432 noisy_lkup_num_writes = n; 1433 else 1434 rte_exit(EXIT_FAILURE, 1435 "noisy-lkup-num-writes must be >= 0\n"); 1436 } 1437 if (!strcmp(lgopts[opt_idx].name, 1438 "noisy-lkup-num-reads")) { 1439 n = atoi(optarg); 1440 if (n >= 0) 1441 noisy_lkup_num_reads = n; 1442 else 1443 rte_exit(EXIT_FAILURE, 1444 "noisy-lkup-num-reads must be >= 0\n"); 1445 } 1446 if (!strcmp(lgopts[opt_idx].name, 1447 "noisy-lkup-num-reads-writes")) { 1448 n = atoi(optarg); 1449 if (n >= 0) 1450 noisy_lkup_num_reads_writes = n; 1451 else 1452 rte_exit(EXIT_FAILURE, 1453 "noisy-lkup-num-reads-writes must be >= 0\n"); 1454 } 1455 if (!strcmp(lgopts[opt_idx].name, 1456 "noisy-forward-mode")) { 1457 int i; 1458 for (i = 0; i < NOISY_FWD_MODE_MAX; i++) 1459 if (!strcmp(optarg, noisy_fwd_mode_desc[i])) { 1460 noisy_fwd_mode = i; 1461 break; 1462 } 1463 if (i == NOISY_FWD_MODE_MAX) 1464 rte_exit(EXIT_FAILURE, "noisy-forward-mode %s invalid," 1465 " must be a valid noisy-forward-mode value\n", 1466 optarg); 1467 } 1468 if (!strcmp(lgopts[opt_idx].name, "no-iova-contig")) 1469 mempool_flags = RTE_MEMPOOL_F_NO_IOVA_CONTIG; 1470 1471 if (!strcmp(lgopts[opt_idx].name, "rx-mq-mode")) { 1472 char *end = NULL; 1473 n = strtoul(optarg, &end, 16); 1474 if (n >= 0 && n <= RTE_ETH_MQ_RX_VMDQ_DCB_RSS) 1475 rx_mq_mode = (enum rte_eth_rx_mq_mode)n; 1476 else 1477 rte_exit(EXIT_FAILURE, 1478 "rx-mq-mode must be >= 0 and <= %d\n", 1479 RTE_ETH_MQ_RX_VMDQ_DCB_RSS); 1480 } 1481 if (!strcmp(lgopts[opt_idx].name, "record-core-cycles")) 1482 record_core_cycles = 1; 1483 if (!strcmp(lgopts[opt_idx].name, "record-burst-stats")) 1484 record_burst_stats = 1; 1485 if (!strcmp(lgopts[opt_idx].name, PARAM_NUM_PROCS)) 1486 num_procs = atoi(optarg); 1487 if (!strcmp(lgopts[opt_idx].name, PARAM_PROC_ID)) 1488 proc_id = atoi(optarg); 1489 break; 1490 case 'h': 1491 usage(argv[0]); 1492 exit(EXIT_SUCCESS); 1493 break; 1494 default: 1495 usage(argv[0]); 1496 fprintf(stderr, "Invalid option: %s\n", argv[optind]); 1497 rte_exit(EXIT_FAILURE, 1498 "Command line is incomplete or incorrect\n"); 1499 break; 1500 } 1501 } 1502 1503 if (optind != argc) { 1504 usage(argv[0]); 1505 fprintf(stderr, "Invalid parameter: %s\n", argv[optind]); 1506 rte_exit(EXIT_FAILURE, "Command line is incorrect\n"); 1507 } 1508 1509 if (proc_id >= (int)num_procs) 1510 rte_exit(EXIT_FAILURE, 1511 "The multi-process option '%s(%d)' should be less than '%s(%u)'\n", 1512 PARAM_PROC_ID, proc_id, 1513 PARAM_NUM_PROCS, num_procs); 1514 1515 /* Set offload configuration from command line parameters. */ 1516 rx_mode.offloads = rx_offloads; 1517 tx_mode.offloads = tx_offloads; 1518 1519 if (mempool_flags & RTE_MEMPOOL_F_NO_IOVA_CONTIG && 1520 mp_alloc_type != MP_ALLOC_ANON) { 1521 TESTPMD_LOG(WARNING, "cannot use no-iova-contig without " 1522 "mp-alloc=anon. mempool no-iova-contig is " 1523 "ignored\n"); 1524 mempool_flags = 0; 1525 } 1526 } 1527