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