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