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