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