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