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