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