xref: /dpdk/app/test-pmd/parameters.c (revision 0e459ffa08891a3ba238821a80499b9b17e2f2d3)
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|flow_aged|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|flow_aged|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, "flow_aged"))
549 		mask = UINT32_C(1) << RTE_ETH_EVENT_FLOW_AGED;
550 	else if (!strcmp(optarg, "all"))
551 		mask = ~UINT32_C(0);
552 	else {
553 		fprintf(stderr, "Invalid event: %s\n", optarg);
554 		return -1;
555 	}
556 	if (enable)
557 		event_print_mask |= mask;
558 	else
559 		event_print_mask &= ~mask;
560 	return 0;
561 }
562 
563 void
564 launch_args_parse(int argc, char** argv)
565 {
566 	int n, opt;
567 	char **argvopt;
568 	int opt_idx;
569 	portid_t pid;
570 	enum { TX, RX };
571 	/* Default offloads for all ports. */
572 	uint64_t rx_offloads = rx_mode.offloads;
573 	uint64_t tx_offloads = tx_mode.offloads;
574 	struct rte_eth_dev_info dev_info;
575 	uint16_t rec_nb_pkts;
576 	int ret;
577 
578 	static struct option lgopts[] = {
579 		{ "help",			0, 0, 0 },
580 #ifdef RTE_LIBRTE_CMDLINE
581 		{ "interactive",		0, 0, 0 },
582 		{ "cmdline-file",		1, 0, 0 },
583 		{ "auto-start",			0, 0, 0 },
584 		{ "eth-peers-configfile",	1, 0, 0 },
585 		{ "eth-peer",			1, 0, 0 },
586 #endif
587 		{ "tx-first",			0, 0, 0 },
588 		{ "stats-period",		1, 0, 0 },
589 		{ "ports",			1, 0, 0 },
590 		{ "nb-cores",			1, 0, 0 },
591 		{ "nb-ports",			1, 0, 0 },
592 		{ "coremask",			1, 0, 0 },
593 		{ "portmask",			1, 0, 0 },
594 		{ "portlist",			1, 0, 0 },
595 		{ "numa",			0, 0, 0 },
596 		{ "no-numa",			0, 0, 0 },
597 		{ "mp-anon",			0, 0, 0 },
598 		{ "port-numa-config",           1, 0, 0 },
599 		{ "ring-numa-config",           1, 0, 0 },
600 		{ "socket-num",			1, 0, 0 },
601 		{ "mbuf-size",			1, 0, 0 },
602 		{ "total-num-mbufs",		1, 0, 0 },
603 		{ "max-pkt-len",		1, 0, 0 },
604 		{ "max-lro-pkt-size",		1, 0, 0 },
605 		{ "pkt-filter-mode",            1, 0, 0 },
606 		{ "pkt-filter-report-hash",     1, 0, 0 },
607 		{ "pkt-filter-size",            1, 0, 0 },
608 		{ "pkt-filter-drop-queue",      1, 0, 0 },
609 #ifdef RTE_LIBRTE_LATENCY_STATS
610 		{ "latencystats",               1, 0, 0 },
611 #endif
612 #ifdef RTE_LIBRTE_BITRATE
613 		{ "bitrate-stats",              1, 0, 0 },
614 #endif
615 		{ "disable-crc-strip",          0, 0, 0 },
616 		{ "enable-lro",                 0, 0, 0 },
617 		{ "enable-rx-cksum",            0, 0, 0 },
618 		{ "enable-rx-timestamp",        0, 0, 0 },
619 		{ "enable-scatter",             0, 0, 0 },
620 		{ "enable-hw-vlan",             0, 0, 0 },
621 		{ "enable-hw-vlan-filter",      0, 0, 0 },
622 		{ "enable-hw-vlan-strip",       0, 0, 0 },
623 		{ "enable-hw-vlan-extend",      0, 0, 0 },
624 		{ "enable-hw-qinq-strip",       0, 0, 0 },
625 		{ "enable-drop-en",            0, 0, 0 },
626 		{ "disable-rss",                0, 0, 0 },
627 		{ "port-topology",              1, 0, 0 },
628 		{ "forward-mode",               1, 0, 0 },
629 		{ "rss-ip",			0, 0, 0 },
630 		{ "rss-udp",			0, 0, 0 },
631 		{ "rxq",			1, 0, 0 },
632 		{ "txq",			1, 0, 0 },
633 		{ "rxd",			1, 0, 0 },
634 		{ "txd",			1, 0, 0 },
635 		{ "hairpinq",			1, 0, 0 },
636 		{ "burst",			1, 0, 0 },
637 		{ "mbcache",			1, 0, 0 },
638 		{ "txpt",			1, 0, 0 },
639 		{ "txht",			1, 0, 0 },
640 		{ "txwt",			1, 0, 0 },
641 		{ "txfreet",			1, 0, 0 },
642 		{ "txrst",			1, 0, 0 },
643 		{ "rxpt",			1, 0, 0 },
644 		{ "rxht",			1, 0, 0 },
645 		{ "rxwt",			1, 0, 0 },
646 		{ "rxfreet",                    1, 0, 0 },
647 		{ "tx-queue-stats-mapping",	1, 0, 0 },
648 		{ "rx-queue-stats-mapping",	1, 0, 0 },
649 		{ "no-flush-rx",	0, 0, 0 },
650 		{ "flow-isolate-all",	        0, 0, 0 },
651 		{ "txpkts",			1, 0, 0 },
652 		{ "txonly-multi-flow",		0, 0, 0 },
653 		{ "disable-link-check",		0, 0, 0 },
654 		{ "disable-device-start",	0, 0, 0 },
655 		{ "no-lsc-interrupt",		0, 0, 0 },
656 		{ "no-rmv-interrupt",		0, 0, 0 },
657 		{ "print-event",		1, 0, 0 },
658 		{ "mask-event",			1, 0, 0 },
659 		{ "tx-offloads",		1, 0, 0 },
660 		{ "rx-offloads",		1, 0, 0 },
661 		{ "hot-plug",			0, 0, 0 },
662 		{ "vxlan-gpe-port",		1, 0, 0 },
663 		{ "mlockall",			0, 0, 0 },
664 		{ "no-mlockall",		0, 0, 0 },
665 		{ "mp-alloc",			1, 0, 0 },
666 		{ "tx-ip",			1, 0, 0 },
667 		{ "tx-udp",			1, 0, 0 },
668 		{ "noisy-tx-sw-buffer-size",	1, 0, 0 },
669 		{ "noisy-tx-sw-buffer-flushtime", 1, 0, 0 },
670 		{ "noisy-lkup-memory",		1, 0, 0 },
671 		{ "noisy-lkup-num-writes",	1, 0, 0 },
672 		{ "noisy-lkup-num-reads",	1, 0, 0 },
673 		{ "noisy-lkup-num-reads-writes", 1, 0, 0 },
674 		{ "no-iova-contig",             0, 0, 0 },
675 		{ 0, 0, 0, 0 },
676 	};
677 
678 	argvopt = argv;
679 
680 #ifdef RTE_LIBRTE_CMDLINE
681 #define SHORTOPTS "i"
682 #else
683 #define SHORTOPTS ""
684 #endif
685 	while ((opt = getopt_long(argc, argvopt, SHORTOPTS "ah",
686 				 lgopts, &opt_idx)) != EOF) {
687 		switch (opt) {
688 #ifdef RTE_LIBRTE_CMDLINE
689 		case 'i':
690 			printf("Interactive-mode selected\n");
691 			interactive = 1;
692 			break;
693 #endif
694 		case 'a':
695 			printf("Auto-start selected\n");
696 			auto_start = 1;
697 			break;
698 
699 		case 0: /*long options */
700 			if (!strcmp(lgopts[opt_idx].name, "help")) {
701 				usage(argv[0]);
702 				rte_exit(EXIT_SUCCESS, "Displayed help\n");
703 			}
704 #ifdef RTE_LIBRTE_CMDLINE
705 			if (!strcmp(lgopts[opt_idx].name, "interactive")) {
706 				printf("Interactive-mode selected\n");
707 				interactive = 1;
708 			}
709 			if (!strcmp(lgopts[opt_idx].name, "cmdline-file")) {
710 				printf("CLI commands to be read from %s\n",
711 				       optarg);
712 				strlcpy(cmdline_filename, optarg,
713 					sizeof(cmdline_filename));
714 			}
715 			if (!strcmp(lgopts[opt_idx].name, "auto-start")) {
716 				printf("Auto-start selected\n");
717 				auto_start = 1;
718 			}
719 			if (!strcmp(lgopts[opt_idx].name, "tx-first")) {
720 				printf("Ports to start sending a burst of "
721 						"packets first\n");
722 				tx_first = 1;
723 			}
724 			if (!strcmp(lgopts[opt_idx].name, "stats-period")) {
725 				char *end = NULL;
726 				unsigned int n;
727 
728 				n = strtoul(optarg, &end, 10);
729 				if ((optarg[0] == '\0') || (end == NULL) ||
730 						(*end != '\0'))
731 					break;
732 
733 				stats_period = n;
734 				break;
735 			}
736 			if (!strcmp(lgopts[opt_idx].name,
737 				    "eth-peers-configfile")) {
738 				if (init_peer_eth_addrs(optarg) != 0)
739 					rte_exit(EXIT_FAILURE,
740 						 "Cannot open logfile\n");
741 			}
742 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
743 				char *port_end;
744 
745 				errno = 0;
746 				n = strtoul(optarg, &port_end, 10);
747 				if (errno != 0 || port_end == optarg || *port_end++ != ',')
748 					rte_exit(EXIT_FAILURE,
749 						 "Invalid eth-peer: %s", optarg);
750 				if (n >= RTE_MAX_ETHPORTS)
751 					rte_exit(EXIT_FAILURE,
752 						 "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
753 						 n, RTE_MAX_ETHPORTS);
754 
755 				if (rte_ether_unformat_addr(port_end,
756 						&peer_eth_addrs[n]) < 0)
757 					rte_exit(EXIT_FAILURE,
758 						 "Invalid ethernet address: %s\n",
759 						 port_end);
760 				nb_peer_eth_addrs++;
761 			}
762 #endif
763 			if (!strcmp(lgopts[opt_idx].name, "tx-ip")) {
764 				struct in_addr in;
765 				char *end;
766 
767 				end = strchr(optarg, ',');
768 				if (end == optarg || !end)
769 					rte_exit(EXIT_FAILURE,
770 						 "Invalid tx-ip: %s", optarg);
771 
772 				*end++ = 0;
773 				if (inet_aton(optarg, &in) == 0)
774 					rte_exit(EXIT_FAILURE,
775 						 "Invalid source IP address: %s\n",
776 						 optarg);
777 				tx_ip_src_addr = rte_be_to_cpu_32(in.s_addr);
778 
779 				if (inet_aton(end, &in) == 0)
780 					rte_exit(EXIT_FAILURE,
781 						 "Invalid destination IP address: %s\n",
782 						 optarg);
783 				tx_ip_dst_addr = rte_be_to_cpu_32(in.s_addr);
784 			}
785 			if (!strcmp(lgopts[opt_idx].name, "tx-udp")) {
786 				char *end = NULL;
787 
788 				errno = 0;
789 				n = strtoul(optarg, &end, 10);
790 				if (errno != 0 || end == optarg ||
791 				    n > UINT16_MAX ||
792 				    !(*end == '\0' || *end == ','))
793 					rte_exit(EXIT_FAILURE,
794 						 "Invalid UDP port: %s\n",
795 						 optarg);
796 				tx_udp_src_port = n;
797 				if (*end == ',') {
798 					char *dst = end + 1;
799 
800 					n = strtoul(dst, &end, 10);
801 					if (errno != 0 || end == dst ||
802 					    n > UINT16_MAX || *end)
803 						rte_exit(EXIT_FAILURE,
804 							 "Invalid destination UDP port: %s\n",
805 							 dst);
806 					tx_udp_dst_port = n;
807 				} else {
808 					tx_udp_dst_port = n;
809 				}
810 
811 			}
812 			if (!strcmp(lgopts[opt_idx].name, "nb-ports")) {
813 				n = atoi(optarg);
814 				if (n > 0 && n <= nb_ports)
815 					nb_fwd_ports = n;
816 				else
817 					rte_exit(EXIT_FAILURE,
818 						 "Invalid port %d\n", n);
819 			}
820 			if (!strcmp(lgopts[opt_idx].name, "nb-cores")) {
821 				n = atoi(optarg);
822 				if (n > 0 && n <= nb_lcores)
823 					nb_fwd_lcores = (uint8_t) n;
824 				else
825 					rte_exit(EXIT_FAILURE,
826 						 "nb-cores should be > 0 and <= %d\n",
827 						 nb_lcores);
828 			}
829 			if (!strcmp(lgopts[opt_idx].name, "coremask"))
830 				parse_fwd_coremask(optarg);
831 			if (!strcmp(lgopts[opt_idx].name, "portmask"))
832 				parse_fwd_portmask(optarg);
833 			if (!strcmp(lgopts[opt_idx].name, "portlist"))
834 				parse_fwd_portlist(optarg);
835 			if (!strcmp(lgopts[opt_idx].name, "no-numa"))
836 				numa_support = 0;
837 			if (!strcmp(lgopts[opt_idx].name, "numa"))
838 				numa_support = 1;
839 			if (!strcmp(lgopts[opt_idx].name, "mp-anon")) {
840 				mp_alloc_type = MP_ALLOC_ANON;
841 			}
842 			if (!strcmp(lgopts[opt_idx].name, "mp-alloc")) {
843 				if (!strcmp(optarg, "native"))
844 					mp_alloc_type = MP_ALLOC_NATIVE;
845 				else if (!strcmp(optarg, "anon"))
846 					mp_alloc_type = MP_ALLOC_ANON;
847 				else if (!strcmp(optarg, "xmem"))
848 					mp_alloc_type = MP_ALLOC_XMEM;
849 				else if (!strcmp(optarg, "xmemhuge"))
850 					mp_alloc_type = MP_ALLOC_XMEM_HUGE;
851 				else if (!strcmp(optarg, "xbuf"))
852 					mp_alloc_type = MP_ALLOC_XBUF;
853 				else
854 					rte_exit(EXIT_FAILURE,
855 						"mp-alloc %s invalid - must be: "
856 						"native, anon, xmem or xmemhuge\n",
857 						 optarg);
858 			}
859 			if (!strcmp(lgopts[opt_idx].name, "port-numa-config")) {
860 				if (parse_portnuma_config(optarg))
861 					rte_exit(EXIT_FAILURE,
862 					   "invalid port-numa configuration\n");
863 			}
864 			if (!strcmp(lgopts[opt_idx].name, "ring-numa-config"))
865 				if (parse_ringnuma_config(optarg))
866 					rte_exit(EXIT_FAILURE,
867 					   "invalid ring-numa configuration\n");
868 			if (!strcmp(lgopts[opt_idx].name, "socket-num")) {
869 				n = atoi(optarg);
870 				if (!new_socket_id((uint8_t)n)) {
871 					socket_num = (uint8_t)n;
872 				} else {
873 					print_invalid_socket_id_error();
874 					rte_exit(EXIT_FAILURE,
875 						"Invalid socket id");
876 				}
877 			}
878 			if (!strcmp(lgopts[opt_idx].name, "mbuf-size")) {
879 				n = atoi(optarg);
880 				if (n > 0 && n <= 0xFFFF)
881 					mbuf_data_size = (uint16_t) n;
882 				else
883 					rte_exit(EXIT_FAILURE,
884 						 "mbuf-size should be > 0 and < 65536\n");
885 			}
886 			if (!strcmp(lgopts[opt_idx].name, "total-num-mbufs")) {
887 				n = atoi(optarg);
888 				if (n > 1024)
889 					param_total_num_mbufs = (unsigned)n;
890 				else
891 					rte_exit(EXIT_FAILURE,
892 						 "total-num-mbufs should be > 1024\n");
893 			}
894 			if (!strcmp(lgopts[opt_idx].name, "max-pkt-len")) {
895 				n = atoi(optarg);
896 				if (n >= RTE_ETHER_MIN_LEN) {
897 					rx_mode.max_rx_pkt_len = (uint32_t) n;
898 					if (n > RTE_ETHER_MAX_LEN)
899 						rx_offloads |=
900 							DEV_RX_OFFLOAD_JUMBO_FRAME;
901 				} else
902 					rte_exit(EXIT_FAILURE,
903 						 "Invalid max-pkt-len=%d - should be > %d\n",
904 						 n, RTE_ETHER_MIN_LEN);
905 			}
906 			if (!strcmp(lgopts[opt_idx].name, "max-lro-pkt-size")) {
907 				n = atoi(optarg);
908 				rx_mode.max_lro_pkt_size = (uint32_t) n;
909 			}
910 			if (!strcmp(lgopts[opt_idx].name, "pkt-filter-mode")) {
911 				if (!strcmp(optarg, "signature"))
912 					fdir_conf.mode =
913 						RTE_FDIR_MODE_SIGNATURE;
914 				else if (!strcmp(optarg, "perfect"))
915 					fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
916 				else if (!strcmp(optarg, "perfect-mac-vlan"))
917 					fdir_conf.mode = RTE_FDIR_MODE_PERFECT_MAC_VLAN;
918 				else if (!strcmp(optarg, "perfect-tunnel"))
919 					fdir_conf.mode = RTE_FDIR_MODE_PERFECT_TUNNEL;
920 				else if (!strcmp(optarg, "none"))
921 					fdir_conf.mode = RTE_FDIR_MODE_NONE;
922 				else
923 					rte_exit(EXIT_FAILURE,
924 						 "pkt-mode-invalid %s invalid - must be: "
925 						 "none, signature, perfect, perfect-mac-vlan"
926 						 " or perfect-tunnel\n",
927 						 optarg);
928 			}
929 			if (!strcmp(lgopts[opt_idx].name,
930 				    "pkt-filter-report-hash")) {
931 				if (!strcmp(optarg, "none"))
932 					fdir_conf.status =
933 						RTE_FDIR_NO_REPORT_STATUS;
934 				else if (!strcmp(optarg, "match"))
935 					fdir_conf.status =
936 						RTE_FDIR_REPORT_STATUS;
937 				else if (!strcmp(optarg, "always"))
938 					fdir_conf.status =
939 						RTE_FDIR_REPORT_STATUS_ALWAYS;
940 				else
941 					rte_exit(EXIT_FAILURE,
942 						 "pkt-filter-report-hash %s invalid "
943 						 "- must be: none or match or always\n",
944 						 optarg);
945 			}
946 			if (!strcmp(lgopts[opt_idx].name, "pkt-filter-size")) {
947 				if (!strcmp(optarg, "64K"))
948 					fdir_conf.pballoc =
949 						RTE_FDIR_PBALLOC_64K;
950 				else if (!strcmp(optarg, "128K"))
951 					fdir_conf.pballoc =
952 						RTE_FDIR_PBALLOC_128K;
953 				else if (!strcmp(optarg, "256K"))
954 					fdir_conf.pballoc =
955 						RTE_FDIR_PBALLOC_256K;
956 				else
957 					rte_exit(EXIT_FAILURE, "pkt-filter-size %s invalid -"
958 						 " must be: 64K or 128K or 256K\n",
959 						 optarg);
960 			}
961 			if (!strcmp(lgopts[opt_idx].name,
962 				    "pkt-filter-drop-queue")) {
963 				n = atoi(optarg);
964 				if (n >= 0)
965 					fdir_conf.drop_queue = (uint8_t) n;
966 				else
967 					rte_exit(EXIT_FAILURE,
968 						 "drop queue %d invalid - must"
969 						 "be >= 0 \n", n);
970 			}
971 #ifdef RTE_LIBRTE_LATENCY_STATS
972 			if (!strcmp(lgopts[opt_idx].name,
973 				    "latencystats")) {
974 				n = atoi(optarg);
975 				if (n >= 0) {
976 					latencystats_lcore_id = (lcoreid_t) n;
977 					latencystats_enabled = 1;
978 				} else
979 					rte_exit(EXIT_FAILURE,
980 						 "invalid lcore id %d for latencystats"
981 						 " must be >= 0\n", n);
982 			}
983 #endif
984 #ifdef RTE_LIBRTE_BITRATE
985 			if (!strcmp(lgopts[opt_idx].name, "bitrate-stats")) {
986 				n = atoi(optarg);
987 				if (n >= 0) {
988 					bitrate_lcore_id = (lcoreid_t) n;
989 					bitrate_enabled = 1;
990 				} else
991 					rte_exit(EXIT_FAILURE,
992 						 "invalid lcore id %d for bitrate stats"
993 						 " must be >= 0\n", n);
994 			}
995 #endif
996 			if (!strcmp(lgopts[opt_idx].name, "disable-crc-strip"))
997 				rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
998 			if (!strcmp(lgopts[opt_idx].name, "enable-lro"))
999 				rx_offloads |= DEV_RX_OFFLOAD_TCP_LRO;
1000 			if (!strcmp(lgopts[opt_idx].name, "enable-scatter"))
1001 				rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1002 			if (!strcmp(lgopts[opt_idx].name, "enable-rx-cksum"))
1003 				rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1004 			if (!strcmp(lgopts[opt_idx].name,
1005 					"enable-rx-timestamp"))
1006 				rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1007 			if (!strcmp(lgopts[opt_idx].name, "enable-hw-vlan"))
1008 				rx_offloads |= DEV_RX_OFFLOAD_VLAN;
1009 
1010 			if (!strcmp(lgopts[opt_idx].name,
1011 					"enable-hw-vlan-filter"))
1012 				rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1013 
1014 			if (!strcmp(lgopts[opt_idx].name,
1015 					"enable-hw-vlan-strip"))
1016 				rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1017 
1018 			if (!strcmp(lgopts[opt_idx].name,
1019 					"enable-hw-vlan-extend"))
1020 				rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1021 
1022 			if (!strcmp(lgopts[opt_idx].name,
1023 					"enable-hw-qinq-strip"))
1024 				rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
1025 
1026 			if (!strcmp(lgopts[opt_idx].name, "enable-drop-en"))
1027 				rx_drop_en = 1;
1028 
1029 			if (!strcmp(lgopts[opt_idx].name, "disable-rss"))
1030 				rss_hf = 0;
1031 			if (!strcmp(lgopts[opt_idx].name, "port-topology")) {
1032 				if (!strcmp(optarg, "paired"))
1033 					port_topology = PORT_TOPOLOGY_PAIRED;
1034 				else if (!strcmp(optarg, "chained"))
1035 					port_topology = PORT_TOPOLOGY_CHAINED;
1036 				else if (!strcmp(optarg, "loop"))
1037 					port_topology = PORT_TOPOLOGY_LOOP;
1038 				else
1039 					rte_exit(EXIT_FAILURE, "port-topology %s invalid -"
1040 						 " must be: paired, chained or loop\n",
1041 						 optarg);
1042 			}
1043 			if (!strcmp(lgopts[opt_idx].name, "forward-mode"))
1044 				set_pkt_forwarding_mode(optarg);
1045 			if (!strcmp(lgopts[opt_idx].name, "rss-ip"))
1046 				rss_hf = ETH_RSS_IP;
1047 			if (!strcmp(lgopts[opt_idx].name, "rss-udp"))
1048 				rss_hf = ETH_RSS_UDP;
1049 			if (!strcmp(lgopts[opt_idx].name, "rxq")) {
1050 				n = atoi(optarg);
1051 				if (n >= 0 && check_nb_rxq((queueid_t)n) == 0)
1052 					nb_rxq = (queueid_t) n;
1053 				else
1054 					rte_exit(EXIT_FAILURE, "rxq %d invalid - must be"
1055 						  " >= 0 && <= %u\n", n,
1056 						  get_allowed_max_nb_rxq(&pid));
1057 			}
1058 			if (!strcmp(lgopts[opt_idx].name, "txq")) {
1059 				n = atoi(optarg);
1060 				if (n >= 0 && check_nb_txq((queueid_t)n) == 0)
1061 					nb_txq = (queueid_t) n;
1062 				else
1063 					rte_exit(EXIT_FAILURE, "txq %d invalid - must be"
1064 						  " >= 0 && <= %u\n", n,
1065 						  get_allowed_max_nb_txq(&pid));
1066 			}
1067 			if (!strcmp(lgopts[opt_idx].name, "hairpinq")) {
1068 				n = atoi(optarg);
1069 				if (n >= 0 &&
1070 				    check_nb_hairpinq((queueid_t)n) == 0)
1071 					nb_hairpinq = (queueid_t) n;
1072 				else
1073 					rte_exit(EXIT_FAILURE, "txq %d invalid - must be"
1074 						  " >= 0 && <= %u\n", n,
1075 						  get_allowed_max_nb_hairpinq
1076 						  (&pid));
1077 				if ((n + nb_txq) < 0 ||
1078 				    check_nb_txq((queueid_t)(n + nb_txq)) != 0)
1079 					rte_exit(EXIT_FAILURE, "txq + hairpinq "
1080 						 "%d invalid - must be"
1081 						  " >= 0 && <= %u\n",
1082 						  n + nb_txq,
1083 						  get_allowed_max_nb_txq(&pid));
1084 				if ((n + nb_rxq) < 0 ||
1085 				    check_nb_rxq((queueid_t)(n + nb_rxq)) != 0)
1086 					rte_exit(EXIT_FAILURE, "rxq + hairpinq "
1087 						 "%d invalid - must be"
1088 						  " >= 0 && <= %u\n",
1089 						  n + nb_rxq,
1090 						  get_allowed_max_nb_rxq(&pid));
1091 			}
1092 			if (!nb_rxq && !nb_txq) {
1093 				rte_exit(EXIT_FAILURE, "Either rx or tx queues should "
1094 						"be non-zero\n");
1095 			}
1096 			if (!strcmp(lgopts[opt_idx].name, "burst")) {
1097 				n = atoi(optarg);
1098 				if (n == 0) {
1099 					/* A burst size of zero means that the
1100 					 * PMD should be queried for
1101 					 * recommended Rx burst size. Since
1102 					 * testpmd uses a single size for all
1103 					 * ports, port 0 is queried for the
1104 					 * value, on the assumption that all
1105 					 * ports are of the same NIC model.
1106 					 */
1107 					ret = eth_dev_info_get_print_err(
1108 								0,
1109 								&dev_info);
1110 					if (ret != 0)
1111 						return;
1112 
1113 					rec_nb_pkts = dev_info
1114 						.default_rxportconf.burst_size;
1115 
1116 					if (rec_nb_pkts == 0)
1117 						rte_exit(EXIT_FAILURE,
1118 							"PMD does not recommend a burst size. "
1119 							"Provided value must be between "
1120 							"1 and %d\n", MAX_PKT_BURST);
1121 					else if (rec_nb_pkts > MAX_PKT_BURST)
1122 						rte_exit(EXIT_FAILURE,
1123 							"PMD recommended burst size of %d"
1124 							" exceeds maximum value of %d\n",
1125 							rec_nb_pkts, MAX_PKT_BURST);
1126 					printf("Using PMD-provided burst value of %d\n",
1127 						rec_nb_pkts);
1128 					nb_pkt_per_burst = rec_nb_pkts;
1129 				} else if (n > MAX_PKT_BURST)
1130 					rte_exit(EXIT_FAILURE,
1131 						"burst must be between1 and %d\n",
1132 						MAX_PKT_BURST);
1133 				else
1134 					nb_pkt_per_burst = (uint16_t) n;
1135 			}
1136 			if (!strcmp(lgopts[opt_idx].name, "mbcache")) {
1137 				n = atoi(optarg);
1138 				if ((n >= 0) &&
1139 				    (n <= RTE_MEMPOOL_CACHE_MAX_SIZE))
1140 					mb_mempool_cache = (uint16_t) n;
1141 				else
1142 					rte_exit(EXIT_FAILURE,
1143 						 "mbcache must be >= 0 and <= %d\n",
1144 						 RTE_MEMPOOL_CACHE_MAX_SIZE);
1145 			}
1146 			if (!strcmp(lgopts[opt_idx].name, "txfreet")) {
1147 				n = atoi(optarg);
1148 				if (n >= 0)
1149 					tx_free_thresh = (int16_t)n;
1150 				else
1151 					rte_exit(EXIT_FAILURE, "txfreet must be >= 0\n");
1152 			}
1153 			if (!strcmp(lgopts[opt_idx].name, "txrst")) {
1154 				n = atoi(optarg);
1155 				if (n >= 0)
1156 					tx_rs_thresh = (int16_t)n;
1157 				else
1158 					rte_exit(EXIT_FAILURE, "txrst must be >= 0\n");
1159 			}
1160 			if (!strcmp(lgopts[opt_idx].name, "rxd")) {
1161 				n = atoi(optarg);
1162 				if (n > 0) {
1163 					if (rx_free_thresh >= n)
1164 						rte_exit(EXIT_FAILURE,
1165 							 "rxd must be > "
1166 							 "rx_free_thresh(%d)\n",
1167 							 (int)rx_free_thresh);
1168 					else
1169 						nb_rxd = (uint16_t) n;
1170 				} else
1171 					rte_exit(EXIT_FAILURE,
1172 						 "rxd(%d) invalid - must be > 0\n",
1173 						 n);
1174 			}
1175 			if (!strcmp(lgopts[opt_idx].name, "txd")) {
1176 				n = atoi(optarg);
1177 				if (n > 0)
1178 					nb_txd = (uint16_t) n;
1179 				else
1180 					rte_exit(EXIT_FAILURE, "txd must be in > 0\n");
1181 			}
1182 			if (!strcmp(lgopts[opt_idx].name, "txpt")) {
1183 				n = atoi(optarg);
1184 				if (n >= 0)
1185 					tx_pthresh = (int8_t)n;
1186 				else
1187 					rte_exit(EXIT_FAILURE, "txpt must be >= 0\n");
1188 			}
1189 			if (!strcmp(lgopts[opt_idx].name, "txht")) {
1190 				n = atoi(optarg);
1191 				if (n >= 0)
1192 					tx_hthresh = (int8_t)n;
1193 				else
1194 					rte_exit(EXIT_FAILURE, "txht must be >= 0\n");
1195 			}
1196 			if (!strcmp(lgopts[opt_idx].name, "txwt")) {
1197 				n = atoi(optarg);
1198 				if (n >= 0)
1199 					tx_wthresh = (int8_t)n;
1200 				else
1201 					rte_exit(EXIT_FAILURE, "txwt must be >= 0\n");
1202 			}
1203 			if (!strcmp(lgopts[opt_idx].name, "rxpt")) {
1204 				n = atoi(optarg);
1205 				if (n >= 0)
1206 					rx_pthresh = (int8_t)n;
1207 				else
1208 					rte_exit(EXIT_FAILURE, "rxpt must be >= 0\n");
1209 			}
1210 			if (!strcmp(lgopts[opt_idx].name, "rxht")) {
1211 				n = atoi(optarg);
1212 				if (n >= 0)
1213 					rx_hthresh = (int8_t)n;
1214 				else
1215 					rte_exit(EXIT_FAILURE, "rxht must be >= 0\n");
1216 			}
1217 			if (!strcmp(lgopts[opt_idx].name, "rxwt")) {
1218 				n = atoi(optarg);
1219 				if (n >= 0)
1220 					rx_wthresh = (int8_t)n;
1221 				else
1222 					rte_exit(EXIT_FAILURE, "rxwt must be >= 0\n");
1223 			}
1224 			if (!strcmp(lgopts[opt_idx].name, "rxfreet")) {
1225 				n = atoi(optarg);
1226 				if (n >= 0)
1227 					rx_free_thresh = (int16_t)n;
1228 				else
1229 					rte_exit(EXIT_FAILURE, "rxfreet must be >= 0\n");
1230 			}
1231 			if (!strcmp(lgopts[opt_idx].name, "tx-queue-stats-mapping")) {
1232 				if (parse_queue_stats_mapping_config(optarg, TX)) {
1233 					rte_exit(EXIT_FAILURE,
1234 						 "invalid TX queue statistics mapping config entered\n");
1235 				}
1236 			}
1237 			if (!strcmp(lgopts[opt_idx].name, "rx-queue-stats-mapping")) {
1238 				if (parse_queue_stats_mapping_config(optarg, RX)) {
1239 					rte_exit(EXIT_FAILURE,
1240 						 "invalid RX queue statistics mapping config entered\n");
1241 				}
1242 			}
1243 			if (!strcmp(lgopts[opt_idx].name, "txpkts")) {
1244 				unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
1245 				unsigned int nb_segs;
1246 
1247 				nb_segs = parse_item_list(optarg, "txpkt segments",
1248 						RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
1249 				if (nb_segs > 0)
1250 					set_tx_pkt_segments(seg_lengths, nb_segs);
1251 				else
1252 					rte_exit(EXIT_FAILURE, "bad txpkts\n");
1253 			}
1254 			if (!strcmp(lgopts[opt_idx].name, "txonly-multi-flow"))
1255 				txonly_multi_flow = 1;
1256 			if (!strcmp(lgopts[opt_idx].name, "no-flush-rx"))
1257 				no_flush_rx = 1;
1258 			if (!strcmp(lgopts[opt_idx].name, "disable-link-check"))
1259 				no_link_check = 1;
1260 			if (!strcmp(lgopts[opt_idx].name, "disable-device-start"))
1261 				no_device_start = 1;
1262 			if (!strcmp(lgopts[opt_idx].name, "no-lsc-interrupt"))
1263 				lsc_interrupt = 0;
1264 			if (!strcmp(lgopts[opt_idx].name, "no-rmv-interrupt"))
1265 				rmv_interrupt = 0;
1266 			if (!strcmp(lgopts[opt_idx].name, "flow-isolate-all"))
1267 				flow_isolate_all = 1;
1268 			if (!strcmp(lgopts[opt_idx].name, "tx-offloads")) {
1269 				char *end = NULL;
1270 				n = strtoull(optarg, &end, 16);
1271 				if (n >= 0)
1272 					tx_offloads = (uint64_t)n;
1273 				else
1274 					rte_exit(EXIT_FAILURE,
1275 						 "tx-offloads must be >= 0\n");
1276 			}
1277 
1278 			if (!strcmp(lgopts[opt_idx].name, "rx-offloads")) {
1279 				char *end = NULL;
1280 				n = strtoull(optarg, &end, 16);
1281 				if (n >= 0)
1282 					rx_offloads = (uint64_t)n;
1283 				else
1284 					rte_exit(EXIT_FAILURE,
1285 						 "rx-offloads must be >= 0\n");
1286 			}
1287 
1288 			if (!strcmp(lgopts[opt_idx].name, "vxlan-gpe-port")) {
1289 				n = atoi(optarg);
1290 				if (n >= 0)
1291 					vxlan_gpe_udp_port = (uint16_t)n;
1292 				else
1293 					rte_exit(EXIT_FAILURE,
1294 						 "vxlan-gpe-port must be >= 0\n");
1295 			}
1296 			if (!strcmp(lgopts[opt_idx].name, "print-event"))
1297 				if (parse_event_printing_config(optarg, 1)) {
1298 					rte_exit(EXIT_FAILURE,
1299 						 "invalid print-event argument\n");
1300 				}
1301 			if (!strcmp(lgopts[opt_idx].name, "mask-event"))
1302 				if (parse_event_printing_config(optarg, 0)) {
1303 					rte_exit(EXIT_FAILURE,
1304 						 "invalid mask-event argument\n");
1305 				}
1306 			if (!strcmp(lgopts[opt_idx].name, "hot-plug"))
1307 				hot_plug = 1;
1308 			if (!strcmp(lgopts[opt_idx].name, "mlockall"))
1309 				do_mlockall = 1;
1310 			if (!strcmp(lgopts[opt_idx].name, "no-mlockall"))
1311 				do_mlockall = 0;
1312 			if (!strcmp(lgopts[opt_idx].name,
1313 				    "noisy-tx-sw-buffer-size")) {
1314 				n = atoi(optarg);
1315 				if (n >= 0)
1316 					noisy_tx_sw_bufsz = n;
1317 				else
1318 					rte_exit(EXIT_FAILURE,
1319 						"noisy-tx-sw-buffer-size must be >= 0\n");
1320 			}
1321 			if (!strcmp(lgopts[opt_idx].name,
1322 				    "noisy-tx-sw-buffer-flushtime")) {
1323 				n = atoi(optarg);
1324 				if (n >= 0)
1325 					noisy_tx_sw_buf_flush_time = n;
1326 				else
1327 					rte_exit(EXIT_FAILURE,
1328 						 "noisy-tx-sw-buffer-flushtime must be >= 0\n");
1329 			}
1330 			if (!strcmp(lgopts[opt_idx].name,
1331 				    "noisy-lkup-memory")) {
1332 				n = atoi(optarg);
1333 				if (n >= 0)
1334 					noisy_lkup_mem_sz = n;
1335 				else
1336 					rte_exit(EXIT_FAILURE,
1337 						 "noisy-lkup-memory must be >= 0\n");
1338 			}
1339 			if (!strcmp(lgopts[opt_idx].name,
1340 				    "noisy-lkup-num-writes")) {
1341 				n = atoi(optarg);
1342 				if (n >= 0)
1343 					noisy_lkup_num_writes = n;
1344 				else
1345 					rte_exit(EXIT_FAILURE,
1346 						 "noisy-lkup-num-writes must be >= 0\n");
1347 			}
1348 			if (!strcmp(lgopts[opt_idx].name,
1349 				    "noisy-lkup-num-reads")) {
1350 				n = atoi(optarg);
1351 				if (n >= 0)
1352 					noisy_lkup_num_reads = n;
1353 				else
1354 					rte_exit(EXIT_FAILURE,
1355 						 "noisy-lkup-num-reads must be >= 0\n");
1356 			}
1357 			if (!strcmp(lgopts[opt_idx].name,
1358 				    "noisy-lkup-num-reads-writes")) {
1359 				n = atoi(optarg);
1360 				if (n >= 0)
1361 					noisy_lkup_num_reads_writes = n;
1362 				else
1363 					rte_exit(EXIT_FAILURE,
1364 						 "noisy-lkup-num-reads-writes must be >= 0\n");
1365 			}
1366 			if (!strcmp(lgopts[opt_idx].name, "no-iova-contig"))
1367 				mempool_flags = MEMPOOL_F_NO_IOVA_CONTIG;
1368 			break;
1369 		case 'h':
1370 			usage(argv[0]);
1371 			rte_exit(EXIT_SUCCESS, "Displayed help\n");
1372 			break;
1373 		default:
1374 			usage(argv[0]);
1375 			printf("Invalid option: %s\n", argv[optind]);
1376 			rte_exit(EXIT_FAILURE,
1377 				 "Command line is incomplete or incorrect\n");
1378 			break;
1379 		}
1380 	}
1381 
1382 	if (optind != argc) {
1383 		usage(argv[0]);
1384 		printf("Invalid parameter: %s\n", argv[optind]);
1385 		rte_exit(EXIT_FAILURE, "Command line is incorrect\n");
1386 	}
1387 
1388 	/* Set offload configuration from command line parameters. */
1389 	rx_mode.offloads = rx_offloads;
1390 	tx_mode.offloads = tx_offloads;
1391 
1392 	if (mempool_flags & MEMPOOL_F_NO_IOVA_CONTIG &&
1393 	    mp_alloc_type != MP_ALLOC_ANON) {
1394 		TESTPMD_LOG(WARNING, "cannot use no-iova-contig without "
1395 				  "mp-alloc=anon. mempool no-iova-contig is "
1396 				  "ignored\n");
1397 		mempool_flags = 0;
1398 	}
1399 }
1400