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