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