xref: /dpdk/app/test-pmd/parameters.c (revision c9dd4aad4f55e6b709e8af7d53e7097fa909ad2b)
1af75078fSIntel /*-
2af75078fSIntel  *   BSD LICENSE
3af75078fSIntel  *
4e9d48c00SBruce Richardson  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5af75078fSIntel  *   All rights reserved.
6af75078fSIntel  *
7af75078fSIntel  *   Redistribution and use in source and binary forms, with or without
8af75078fSIntel  *   modification, are permitted provided that the following conditions
9af75078fSIntel  *   are met:
10af75078fSIntel  *
11af75078fSIntel  *     * Redistributions of source code must retain the above copyright
12af75078fSIntel  *       notice, this list of conditions and the following disclaimer.
13af75078fSIntel  *     * Redistributions in binary form must reproduce the above copyright
14af75078fSIntel  *       notice, this list of conditions and the following disclaimer in
15af75078fSIntel  *       the documentation and/or other materials provided with the
16af75078fSIntel  *       distribution.
17af75078fSIntel  *     * Neither the name of Intel Corporation nor the names of its
18af75078fSIntel  *       contributors may be used to endorse or promote products derived
19af75078fSIntel  *       from this software without specific prior written permission.
20af75078fSIntel  *
21af75078fSIntel  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22af75078fSIntel  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23af75078fSIntel  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24af75078fSIntel  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25af75078fSIntel  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26af75078fSIntel  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27af75078fSIntel  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28af75078fSIntel  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29af75078fSIntel  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30af75078fSIntel  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31af75078fSIntel  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32af75078fSIntel  */
33af75078fSIntel 
34af75078fSIntel #include <errno.h>
35af75078fSIntel #include <getopt.h>
36af75078fSIntel #include <stdarg.h>
37af75078fSIntel #include <stdio.h>
38af75078fSIntel #include <stdlib.h>
39af75078fSIntel #include <signal.h>
40af75078fSIntel #include <string.h>
41af75078fSIntel #include <time.h>
42af75078fSIntel #include <fcntl.h>
43af75078fSIntel #include <sys/types.h>
44af75078fSIntel #include <errno.h>
45af75078fSIntel 
46af75078fSIntel #include <sys/queue.h>
47af75078fSIntel #include <sys/stat.h>
48af75078fSIntel 
49af75078fSIntel #include <stdint.h>
50af75078fSIntel #include <unistd.h>
51af75078fSIntel #include <inttypes.h>
52af75078fSIntel 
53af75078fSIntel #include <rte_common.h>
54af75078fSIntel #include <rte_byteorder.h>
55af75078fSIntel #include <rte_log.h>
56af75078fSIntel #include <rte_debug.h>
57af75078fSIntel #include <rte_cycles.h>
58af75078fSIntel #include <rte_memory.h>
59af75078fSIntel #include <rte_memzone.h>
60af75078fSIntel #include <rte_launch.h>
61af75078fSIntel #include <rte_tailq.h>
62af75078fSIntel #include <rte_eal.h>
63af75078fSIntel #include <rte_per_lcore.h>
64af75078fSIntel #include <rte_lcore.h>
65af75078fSIntel #include <rte_atomic.h>
66af75078fSIntel #include <rte_branch_prediction.h>
67af75078fSIntel #include <rte_ring.h>
68af75078fSIntel #include <rte_mempool.h>
69af75078fSIntel #include <rte_interrupts.h>
70af75078fSIntel #include <rte_pci.h>
71af75078fSIntel #include <rte_ether.h>
72af75078fSIntel #include <rte_ethdev.h>
73af75078fSIntel #include <rte_string_fns.h>
740d56cb81SThomas Monjalon #ifdef RTE_LIBRTE_CMDLINE
75af75078fSIntel #include <cmdline_parse.h>
76af75078fSIntel #include <cmdline_parse_etheraddr.h>
770d56cb81SThomas Monjalon #endif
782950a769SDeclan Doherty #ifdef RTE_LIBRTE_PMD_BOND
792950a769SDeclan Doherty #include <rte_eth_bond.h>
802950a769SDeclan Doherty #endif
81af75078fSIntel 
82af75078fSIntel #include "testpmd.h"
83af75078fSIntel 
84af75078fSIntel static void
85af75078fSIntel usage(char* progname)
86af75078fSIntel {
870d56cb81SThomas Monjalon 	printf("usage: %s "
880d56cb81SThomas Monjalon #ifdef RTE_LIBRTE_CMDLINE
890d56cb81SThomas Monjalon 	       "[--interactive|-i] "
900d56cb81SThomas Monjalon #endif
91ca7feb22SCyril Chemparathy 	       "[--help|-h] | [--auto-start|-a] | ["
92af75078fSIntel 	       "--coremask=COREMASK --portmask=PORTMASK --numa "
93c8798818SIntel 	       "--mbuf-size= | --total-num-mbufs= | "
943be52ffcSIntel 	       "--nb-cores= | --nb-ports= | "
950d56cb81SThomas Monjalon #ifdef RTE_LIBRTE_CMDLINE
96af75078fSIntel 	       "--eth-peers-configfile= | "
973be52ffcSIntel 	       "--eth-peer=X,M:M:M:M:M:M | "
980d56cb81SThomas Monjalon #endif
99af75078fSIntel 	       "--pkt-filter-mode= |"
100af75078fSIntel 	       "--rss-ip | --rss-udp | "
101af75078fSIntel 	       "--rxpt= | --rxht= | --rxwt= | --rxfreet= | "
102af75078fSIntel 	       "--txpt= | --txht= | --txwt= | --txfreet= | "
103ce8d5614SIntel 	       "--txrst= | --txqflags= ]\n",
104af75078fSIntel 	       progname);
1050d56cb81SThomas Monjalon #ifdef RTE_LIBRTE_CMDLINE
1063be52ffcSIntel 	printf("  --interactive: run in interactive mode.\n");
1070d56cb81SThomas Monjalon #endif
108ca7feb22SCyril Chemparathy 	printf("  --auto-start: start forwarding on init "
109ca7feb22SCyril Chemparathy 	       "[always when non-interactive].\n");
1103be52ffcSIntel 	printf("  --help: display this message and quit.\n");
1113be52ffcSIntel 	printf("  --nb-cores=N: set the number of forwarding cores "
1123be52ffcSIntel 	       "(1 <= N <= %d).\n", nb_lcores);
1133be52ffcSIntel 	printf("  --nb-ports=N: set the number of forwarding ports "
1143be52ffcSIntel 	       "(1 <= N <= %d).\n", nb_ports);
115af75078fSIntel 	printf("  --coremask=COREMASK: hexadecimal bitmask of cores running "
116013af9b6SIntel 	       "the packet forwarding test. The master lcore is reserved for "
1173be52ffcSIntel 	       "command line parsing only, and cannot be masked on for "
1183be52ffcSIntel 	       "packet forwarding.\n");
119af75078fSIntel 	printf("  --portmask=PORTMASK: hexadecimal bitmask of ports used "
1203be52ffcSIntel 	       "by the packet forwarding test.\n");
121af75078fSIntel 	printf("  --numa: enable NUMA-aware allocation of RX/TX rings and of "
1223be52ffcSIntel 	       "RX memory buffers (mbufs).\n");
123b6ea6408SIntel 	printf("  --port-numa-config=(port,socket)[,(port,socket)]: "
124b6ea6408SIntel 	       "specify the socket on which the memory pool "
125b6ea6408SIntel 	       "used by the port will be allocated.\n");
126b6ea6408SIntel 	printf("  --ring-numa-config=(port,flag,socket)[,(port,flag,socket)]: "
127b6ea6408SIntel 	       "specify the socket on which the TX/RX rings for "
128b6ea6408SIntel 	       "the port will be allocated "
129b6ea6408SIntel 	       "(flag: 1 for RX; 2 for TX; 3 for RX and TX).\n");
130b6ea6408SIntel 	printf("  --socket-num=N: set socket from which all memory is allocated "
131b6ea6408SIntel 	       "in NUMA mode.\n");
1323be52ffcSIntel 	printf("  --mbuf-size=N: set the data size of mbuf to N bytes.\n");
1333be52ffcSIntel 	printf("  --total-num-mbufs=N: set the number of mbufs to be allocated "
1343be52ffcSIntel 	       "in mbuf pools.\n");
1353be52ffcSIntel 	printf("  --max-pkt-len=N: set the maximum size of packet to N bytes.\n");
1360d56cb81SThomas Monjalon #ifdef RTE_LIBRTE_CMDLINE
1373be52ffcSIntel 	printf("  --eth-peers-configfile=name: config file with ethernet addresses "
1383be52ffcSIntel 	       "of peer ports.\n");
1393be52ffcSIntel 	printf("  --eth-peer=X,M:M:M:M:M:M: set the MAC address of the X peer "
1403be52ffcSIntel 	       "port (0 <= X < %d).\n", RTE_MAX_ETHPORTS);
1410d56cb81SThomas Monjalon #endif
1423be52ffcSIntel 	printf("  --pkt-filter-mode=N: set Flow Director mode "
1433be52ffcSIntel 	       "(N: none (default mode) or signature or perfect).\n");
1443be52ffcSIntel 	printf("  --pkt-filter-report-hash=N: set Flow Director report mode "
1453be52ffcSIntel 	       "(N: none  or match (default) or always).\n");
1463be52ffcSIntel 	printf("  --pkt-filter-size=N: set Flow Director mode "
1473be52ffcSIntel 	       "(N: 64K (default mode) or 128K or 256K).\n");
148af75078fSIntel 	printf("  --pkt-filter-drop-queue=N: set drop-queue. "
1493be52ffcSIntel 	       "In perfect mode, when you add a rule with queue = -1 "
150af75078fSIntel 	       "the packet will be enqueued into the rx drop-queue. "
151af75078fSIntel 	       "If the drop-queue doesn't exist, the packet is dropped. "
1523be52ffcSIntel 	       "By default drop-queue=127.\n");
1533be52ffcSIntel 	printf("  --crc-strip: enable CRC stripping by hardware.\n");
1543be52ffcSIntel 	printf("  --enable-rx-cksum: enable rx hardware checksum offload.\n");
1553be52ffcSIntel 	printf("  --disable-hw-vlan: disable hardware vlan.\n");
156*c9dd4aadSOuyang Changchun 	printf("  --disable-hw-vlan-filter: disable hardware vlan filter.\n");
157*c9dd4aadSOuyang Changchun 	printf("  --disable-hw-vlan-strip: disable hardware vlan strip.\n");
158*c9dd4aadSOuyang Changchun 	printf("  --disable-hw-vlan-extend: disable hardware vlan extend.\n");
1593be52ffcSIntel 	printf("  --enable-drop-en: enable per queue packet drop.\n");
1603be52ffcSIntel 	printf("  --disable-rss: disable rss.\n");
161af75078fSIntel 	printf("  --port-topology=N: set port topology (N: paired (default) or "
1623be52ffcSIntel 	       "chained).\n");
163769ce6b1SThomas Monjalon 	printf("  --forward-mode=N: set forwarding mode (N: %s).\n",
164769ce6b1SThomas Monjalon 	       list_pkt_forwarding_modes());
1653be52ffcSIntel 	printf("  --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
1663be52ffcSIntel 	printf("  --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
1673be52ffcSIntel 	printf("  --rxq=N: set the number of RX queues per port to N.\n");
1683be52ffcSIntel 	printf("  --rxd=N: set the number of descriptors in RX rings to N.\n");
1693be52ffcSIntel 	printf("  --txq=N: set the number of TX queues per port to N.\n");
1703be52ffcSIntel 	printf("  --txd=N: set the number of descriptors in TX rings to N.\n");
1713be52ffcSIntel 	printf("  --burst=N: set the number of packets per burst to N.\n");
1723be52ffcSIntel 	printf("  --mbcache=N: set the cache of mbuf memory pool to N.\n");
17357af3415SPablo de Lara 	printf("  --rxpt=N: set prefetch threshold register of RX rings to N.\n");
17457af3415SPablo de Lara 	printf("  --rxht=N: set the host threshold register of RX rings to N.\n");
1753be52ffcSIntel 	printf("  --rxfreet=N: set the free threshold of RX descriptors to N "
1763be52ffcSIntel 	       "(0 <= N < value of rxd).\n");
17757af3415SPablo de Lara 	printf("  --rxwt=N: set the write-back threshold register of RX rings to N.\n");
17857af3415SPablo de Lara 	printf("  --txpt=N: set the prefetch threshold register of TX rings to N.\n");
17957af3415SPablo de Lara 	printf("  --txht=N: set the nhost threshold register of TX rings to N.\n");
18057af3415SPablo de Lara 	printf("  --txwt=N: set the write-back threshold register of TX rings to N.\n");
1813be52ffcSIntel 	printf("  --txfreet=N: set the transmit free threshold of TX rings to N "
1823be52ffcSIntel 	       "(0 <= N <= value of txd).\n");
1833be52ffcSIntel 	printf("  --txrst=N: set the transmit RS bit threshold of TX rings to N "
1843be52ffcSIntel 	       "(0 <= N <= value of txd).\n");
1853be52ffcSIntel 	printf("  --txqflags=0xXXXXXXXX: hexadecimal bitmask of TX queue flags "
1863be52ffcSIntel 	       "(0 <= N <= 0x7FFFFFFF).\n");
1873be52ffcSIntel 	printf("  --tx-queue-stats-mapping=(port,queue,mapping)[,(port,queue,mapping]: "
188ed30d9b6SIntel 	       "tx queues statistics counters mapping "
1893be52ffcSIntel 	       "(0 <= mapping <= %d).\n", RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1903be52ffcSIntel 	printf("  --rx-queue-stats-mapping=(port,queue,mapping)[,(port,queue,mapping]: "
191ed30d9b6SIntel 	       "rx queues statistics counters mapping "
1923be52ffcSIntel 	       "(0 <= mapping <= %d).\n", RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1935e2ee196SIntel 	printf("  --no-flush-rx: Don't flush RX streams before forwarding."
1945e2ee196SIntel 	       " Used mainly with PCAP drivers.\n");
195a7e7bb4eSCyril Chemparathy 	printf("  --txpkts=X[,Y]*: set TX segment sizes.\n");
196bc202406SDavid Marchand 	printf("  --disable-link-check: disable check on link status when "
197bc202406SDavid Marchand 	       "starting/stopping ports.\n");
198af75078fSIntel }
199af75078fSIntel 
2000d56cb81SThomas Monjalon #ifdef RTE_LIBRTE_CMDLINE
201af75078fSIntel static int
202af75078fSIntel init_peer_eth_addrs(char *config_filename)
203af75078fSIntel {
204af75078fSIntel 	FILE *config_file;
205af75078fSIntel 	portid_t i;
206af75078fSIntel 	char buf[50];
207af75078fSIntel 
208af75078fSIntel 	config_file = fopen(config_filename, "r");
209af75078fSIntel 	if (config_file == NULL) {
2103be52ffcSIntel 		perror("Failed to open eth config file\n");
211af75078fSIntel 		return -1;
212af75078fSIntel 	}
213af75078fSIntel 
214af75078fSIntel 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
215af75078fSIntel 
216af75078fSIntel 		if (fgets(buf, sizeof(buf), config_file) == NULL)
217af75078fSIntel 			break;
218af75078fSIntel 
219aaa662e7SAlan Carew 		if (cmdline_parse_etheraddr(NULL, buf, &peer_eth_addrs[i],
220aaa662e7SAlan Carew 				sizeof(peer_eth_addrs[i])) < 0) {
2213be52ffcSIntel 			printf("Bad MAC address format on line %d\n", i+1);
222af75078fSIntel 			fclose(config_file);
223af75078fSIntel 			return -1;
224af75078fSIntel 		}
225af75078fSIntel 	}
226af75078fSIntel 	fclose(config_file);
227af75078fSIntel 	nb_peer_eth_addrs = (portid_t) i;
228af75078fSIntel 	return 0;
229af75078fSIntel }
2300d56cb81SThomas Monjalon #endif
231af75078fSIntel 
232af75078fSIntel /*
233af75078fSIntel  * Parse the coremask given as argument (hexadecimal string) and set
234af75078fSIntel  * the global configuration of forwarding cores.
235af75078fSIntel  */
236af75078fSIntel static void
237af75078fSIntel parse_fwd_coremask(const char *coremask)
238af75078fSIntel {
239af75078fSIntel 	char *end;
240af75078fSIntel 	unsigned long long int cm;
241af75078fSIntel 
242af75078fSIntel 	/* parse hexadecimal string */
243af75078fSIntel 	end = NULL;
244af75078fSIntel 	cm = strtoull(coremask, &end, 16);
245af75078fSIntel 	if ((coremask[0] == '\0') || (end == NULL) || (*end != '\0'))
246af75078fSIntel 		rte_exit(EXIT_FAILURE, "Invalid fwd core mask\n");
247013af9b6SIntel 	else if (set_fwd_lcores_mask((uint64_t) cm) < 0)
248013af9b6SIntel 		rte_exit(EXIT_FAILURE, "coremask is not valid\n");
249af75078fSIntel }
250af75078fSIntel 
251af75078fSIntel /*
252af75078fSIntel  * Parse the coremask given as argument (hexadecimal string) and set
253af75078fSIntel  * the global configuration of forwarding cores.
254af75078fSIntel  */
255af75078fSIntel static void
256af75078fSIntel parse_fwd_portmask(const char *portmask)
257af75078fSIntel {
258af75078fSIntel 	char *end;
259af75078fSIntel 	unsigned long long int pm;
260af75078fSIntel 
261af75078fSIntel 	/* parse hexadecimal string */
262af75078fSIntel 	end = NULL;
263af75078fSIntel 	pm = strtoull(portmask, &end, 16);
264af75078fSIntel 	if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
265af75078fSIntel 		rte_exit(EXIT_FAILURE, "Invalid fwd port mask\n");
266af75078fSIntel 	else
267af75078fSIntel 		set_fwd_ports_mask((uint64_t) pm);
268af75078fSIntel }
269af75078fSIntel 
270ed30d9b6SIntel 
271ed30d9b6SIntel static int
272ed30d9b6SIntel parse_queue_stats_mapping_config(const char *q_arg, int is_rx)
273ed30d9b6SIntel {
274ed30d9b6SIntel 	char s[256];
275ed30d9b6SIntel 	const char *p, *p0 = q_arg;
276ed30d9b6SIntel 	char *end;
277ed30d9b6SIntel 	enum fieldnames {
278ed30d9b6SIntel 		FLD_PORT = 0,
279ed30d9b6SIntel 		FLD_QUEUE,
280ed30d9b6SIntel 		FLD_STATS_COUNTER,
281ed30d9b6SIntel 		_NUM_FLD
282ed30d9b6SIntel 	};
283ed30d9b6SIntel 	unsigned long int_fld[_NUM_FLD];
284ed30d9b6SIntel 	char *str_fld[_NUM_FLD];
285ed30d9b6SIntel 	int i;
286ed30d9b6SIntel 	unsigned size;
287ed30d9b6SIntel 
288ed30d9b6SIntel 	/* reset from value set at definition */
289ed30d9b6SIntel 	is_rx ? (nb_rx_queue_stats_mappings = 0) : (nb_tx_queue_stats_mappings = 0);
290ed30d9b6SIntel 
291ed30d9b6SIntel 	while ((p = strchr(p0,'(')) != NULL) {
292ed30d9b6SIntel 		++p;
293ed30d9b6SIntel 		if((p0 = strchr(p,')')) == NULL)
294ed30d9b6SIntel 			return -1;
295ed30d9b6SIntel 
296ed30d9b6SIntel 		size = p0 - p;
297ed30d9b6SIntel 		if(size >= sizeof(s))
298ed30d9b6SIntel 			return -1;
299ed30d9b6SIntel 
3006f41fe75SStephen Hemminger 		snprintf(s, sizeof(s), "%.*s", size, p);
301ed30d9b6SIntel 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
302ed30d9b6SIntel 			return -1;
303ed30d9b6SIntel 		for (i = 0; i < _NUM_FLD; i++){
304ed30d9b6SIntel 			errno = 0;
305ed30d9b6SIntel 			int_fld[i] = strtoul(str_fld[i], &end, 0);
306ed30d9b6SIntel 			if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
307ed30d9b6SIntel 				return -1;
308ed30d9b6SIntel 		}
309ed30d9b6SIntel 		/* Check mapping field is in correct range (0..RTE_ETHDEV_QUEUE_STAT_CNTRS-1) */
310ed30d9b6SIntel 		if (int_fld[FLD_STATS_COUNTER] >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
311ed30d9b6SIntel 			printf("Stats counter not in the correct range 0..%d\n",
312ed30d9b6SIntel 					RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
313ed30d9b6SIntel 			return -1;
314ed30d9b6SIntel 		}
315ed30d9b6SIntel 
3164dccdc78SBruce Richardson 		if (!is_rx) {
3174dccdc78SBruce Richardson 			if ((nb_tx_queue_stats_mappings >=
3184dccdc78SBruce Richardson 						MAX_TX_QUEUE_STATS_MAPPINGS)) {
3194dccdc78SBruce Richardson 				printf("exceeded max number of TX queue "
3204dccdc78SBruce Richardson 						"statistics mappings: %hu\n",
3214dccdc78SBruce Richardson 						nb_tx_queue_stats_mappings);
322ed30d9b6SIntel 				return -1;
323ed30d9b6SIntel 			}
324ed30d9b6SIntel 			tx_queue_stats_mappings_array[nb_tx_queue_stats_mappings].port_id =
325ed30d9b6SIntel 				(uint8_t)int_fld[FLD_PORT];
326ed30d9b6SIntel 			tx_queue_stats_mappings_array[nb_tx_queue_stats_mappings].queue_id =
327ed30d9b6SIntel 				(uint8_t)int_fld[FLD_QUEUE];
328ed30d9b6SIntel 			tx_queue_stats_mappings_array[nb_tx_queue_stats_mappings].stats_counter_id =
329ed30d9b6SIntel 				(uint8_t)int_fld[FLD_STATS_COUNTER];
330ed30d9b6SIntel 			++nb_tx_queue_stats_mappings;
331ed30d9b6SIntel 		}
332ed30d9b6SIntel 		else {
3334dccdc78SBruce Richardson 			if ((nb_rx_queue_stats_mappings >=
3344dccdc78SBruce Richardson 						MAX_RX_QUEUE_STATS_MAPPINGS)) {
3354dccdc78SBruce Richardson 				printf("exceeded max number of RX queue "
3364dccdc78SBruce Richardson 						"statistics mappings: %hu\n",
3374dccdc78SBruce Richardson 						nb_rx_queue_stats_mappings);
3384dccdc78SBruce Richardson 				return -1;
3394dccdc78SBruce Richardson 			}
340ed30d9b6SIntel 			rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].port_id =
341ed30d9b6SIntel 				(uint8_t)int_fld[FLD_PORT];
342ed30d9b6SIntel 			rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].queue_id =
343ed30d9b6SIntel 				(uint8_t)int_fld[FLD_QUEUE];
344ed30d9b6SIntel 			rx_queue_stats_mappings_array[nb_rx_queue_stats_mappings].stats_counter_id =
345ed30d9b6SIntel 				(uint8_t)int_fld[FLD_STATS_COUNTER];
346ed30d9b6SIntel 			++nb_rx_queue_stats_mappings;
347ed30d9b6SIntel 		}
348ed30d9b6SIntel 
349ed30d9b6SIntel 	}
350ed30d9b6SIntel /* Reassign the rx/tx_queue_stats_mappings pointer to point to this newly populated array rather */
351ed30d9b6SIntel /* than to the default array (that was set at its definition) */
352ed30d9b6SIntel 	is_rx ? (rx_queue_stats_mappings = rx_queue_stats_mappings_array) :
353ed30d9b6SIntel 		(tx_queue_stats_mappings = tx_queue_stats_mappings_array);
354ed30d9b6SIntel 	return 0;
355ed30d9b6SIntel }
356ed30d9b6SIntel 
357b6ea6408SIntel static int
358b6ea6408SIntel parse_portnuma_config(const char *q_arg)
359b6ea6408SIntel {
360b6ea6408SIntel 	char s[256];
361b6ea6408SIntel 	const char *p, *p0 = q_arg;
362b6ea6408SIntel 	char *end;
363b6ea6408SIntel 	uint8_t i,port_id,socket_id;
364b6ea6408SIntel 	unsigned size;
365b6ea6408SIntel 	enum fieldnames {
366b6ea6408SIntel 		FLD_PORT = 0,
367b6ea6408SIntel 		FLD_SOCKET,
368b6ea6408SIntel 		_NUM_FLD
369b6ea6408SIntel 	};
370b6ea6408SIntel 	unsigned long int_fld[_NUM_FLD];
371b6ea6408SIntel 	char *str_fld[_NUM_FLD];
372edab33b1STetsuya Mukawa 	portid_t pid;
373b6ea6408SIntel 
374b6ea6408SIntel 	/* reset from value set at definition */
375b6ea6408SIntel 	while ((p = strchr(p0,'(')) != NULL) {
376b6ea6408SIntel 		++p;
377b6ea6408SIntel 		if((p0 = strchr(p,')')) == NULL)
378b6ea6408SIntel 			return -1;
379b6ea6408SIntel 
380b6ea6408SIntel 		size = p0 - p;
381b6ea6408SIntel 		if(size >= sizeof(s))
382b6ea6408SIntel 			return -1;
383b6ea6408SIntel 
3846f41fe75SStephen Hemminger 		snprintf(s, sizeof(s), "%.*s", size, p);
385b6ea6408SIntel 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
386b6ea6408SIntel 			return -1;
387b6ea6408SIntel 		for (i = 0; i < _NUM_FLD; i++) {
388b6ea6408SIntel 			errno = 0;
389b6ea6408SIntel 			int_fld[i] = strtoul(str_fld[i], &end, 0);
390b6ea6408SIntel 			if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
391b6ea6408SIntel 				return -1;
392b6ea6408SIntel 		}
393b6ea6408SIntel 		port_id = (uint8_t)int_fld[FLD_PORT];
394edab33b1STetsuya Mukawa 		if (port_id_is_invalid(port_id, ENABLED_WARN)) {
395edab33b1STetsuya Mukawa 			printf("Valid port range is [0");
396edab33b1STetsuya Mukawa 			FOREACH_PORT(pid, ports)
397edab33b1STetsuya Mukawa 				printf(", %d", pid);
398edab33b1STetsuya Mukawa 			printf("]\n");
399b6ea6408SIntel 			return -1;
400b6ea6408SIntel 		}
401b6ea6408SIntel 		socket_id = (uint8_t)int_fld[FLD_SOCKET];
402b6ea6408SIntel 		if(socket_id >= MAX_SOCKET) {
403b6ea6408SIntel 			printf("Invalid socket id, range is [0, %d]\n",
404b6ea6408SIntel 				 MAX_SOCKET - 1);
405b6ea6408SIntel 			return -1;
406b6ea6408SIntel 		}
407b6ea6408SIntel 		port_numa[port_id] = socket_id;
408b6ea6408SIntel 	}
409b6ea6408SIntel 
410b6ea6408SIntel 	return 0;
411b6ea6408SIntel }
412b6ea6408SIntel 
413b6ea6408SIntel static int
414b6ea6408SIntel parse_ringnuma_config(const char *q_arg)
415b6ea6408SIntel {
416b6ea6408SIntel 	char s[256];
417b6ea6408SIntel 	const char *p, *p0 = q_arg;
418b6ea6408SIntel 	char *end;
419b6ea6408SIntel 	uint8_t i,port_id,ring_flag,socket_id;
420b6ea6408SIntel 	unsigned size;
421b6ea6408SIntel 	enum fieldnames {
422b6ea6408SIntel 		FLD_PORT = 0,
423b6ea6408SIntel 		FLD_FLAG,
424b6ea6408SIntel 		FLD_SOCKET,
425b6ea6408SIntel 		_NUM_FLD
426b6ea6408SIntel 	};
427b6ea6408SIntel 	unsigned long int_fld[_NUM_FLD];
428b6ea6408SIntel 	char *str_fld[_NUM_FLD];
429edab33b1STetsuya Mukawa 	portid_t pid;
430b6ea6408SIntel 	#define RX_RING_ONLY 0x1
431b6ea6408SIntel 	#define TX_RING_ONLY 0x2
432b6ea6408SIntel 	#define RXTX_RING    0x3
433b6ea6408SIntel 
434b6ea6408SIntel 	/* reset from value set at definition */
435b6ea6408SIntel 	while ((p = strchr(p0,'(')) != NULL) {
436b6ea6408SIntel 		++p;
437b6ea6408SIntel 		if((p0 = strchr(p,')')) == NULL)
438b6ea6408SIntel 			return -1;
439b6ea6408SIntel 
440b6ea6408SIntel 		size = p0 - p;
441b6ea6408SIntel 		if(size >= sizeof(s))
442b6ea6408SIntel 			return -1;
443b6ea6408SIntel 
4446f41fe75SStephen Hemminger 		snprintf(s, sizeof(s), "%.*s", size, p);
445b6ea6408SIntel 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
446b6ea6408SIntel 			return -1;
447b6ea6408SIntel 		for (i = 0; i < _NUM_FLD; i++) {
448b6ea6408SIntel 			errno = 0;
449b6ea6408SIntel 			int_fld[i] = strtoul(str_fld[i], &end, 0);
450b6ea6408SIntel 			if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
451b6ea6408SIntel 				return -1;
452b6ea6408SIntel 		}
453b6ea6408SIntel 		port_id = (uint8_t)int_fld[FLD_PORT];
454edab33b1STetsuya Mukawa 		if (port_id_is_invalid(port_id, ENABLED_WARN)) {
455edab33b1STetsuya Mukawa 			printf("Valid port range is [0");
456edab33b1STetsuya Mukawa 			FOREACH_PORT(pid, ports)
457edab33b1STetsuya Mukawa 				printf(", %d", pid);
458edab33b1STetsuya Mukawa 			printf("]\n");
459b6ea6408SIntel 			return -1;
460b6ea6408SIntel 		}
461b6ea6408SIntel 		socket_id = (uint8_t)int_fld[FLD_SOCKET];
462b6ea6408SIntel 		if (socket_id >= MAX_SOCKET) {
463b6ea6408SIntel 			printf("Invalid socket id, range is [0, %d]\n",
464b6ea6408SIntel 				MAX_SOCKET - 1);
465b6ea6408SIntel 			return -1;
466b6ea6408SIntel 		}
467b6ea6408SIntel 		ring_flag = (uint8_t)int_fld[FLD_FLAG];
468b6ea6408SIntel 		if ((ring_flag < RX_RING_ONLY) || (ring_flag > RXTX_RING)) {
469b6ea6408SIntel 			printf("Invalid ring-flag=%d config for port =%d\n",
470b6ea6408SIntel 				ring_flag,port_id);
471b6ea6408SIntel 			return -1;
472b6ea6408SIntel 		}
473b6ea6408SIntel 
474b6ea6408SIntel 		switch (ring_flag & RXTX_RING) {
475b6ea6408SIntel 		case RX_RING_ONLY:
476b6ea6408SIntel 			rxring_numa[port_id] = socket_id;
477b6ea6408SIntel 			break;
478b6ea6408SIntel 		case TX_RING_ONLY:
479b6ea6408SIntel 			txring_numa[port_id] = socket_id;
480b6ea6408SIntel 			break;
481b6ea6408SIntel 		case RXTX_RING:
482b6ea6408SIntel 			rxring_numa[port_id] = socket_id;
483b6ea6408SIntel 			txring_numa[port_id] = socket_id;
484b6ea6408SIntel 			break;
485b6ea6408SIntel 		default:
486b6ea6408SIntel 			printf("Invalid ring-flag=%d config for port=%d\n",
487b6ea6408SIntel 				ring_flag,port_id);
488b6ea6408SIntel 			break;
489b6ea6408SIntel 		}
490b6ea6408SIntel 	}
491b6ea6408SIntel 
492b6ea6408SIntel 	return 0;
493b6ea6408SIntel }
494ed30d9b6SIntel 
495af75078fSIntel void
496af75078fSIntel launch_args_parse(int argc, char** argv)
497af75078fSIntel {
498af75078fSIntel 	int n, opt;
499af75078fSIntel 	char **argvopt;
500af75078fSIntel 	int opt_idx;
501013af9b6SIntel 	enum { TX, RX };
502013af9b6SIntel 
503af75078fSIntel 	static struct option lgopts[] = {
504af75078fSIntel 		{ "help",			0, 0, 0 },
5050d56cb81SThomas Monjalon #ifdef RTE_LIBRTE_CMDLINE
506af75078fSIntel 		{ "interactive",		0, 0, 0 },
507ca7feb22SCyril Chemparathy 		{ "auto-start",			0, 0, 0 },
508af75078fSIntel 		{ "eth-peers-configfile",	1, 0, 0 },
509af75078fSIntel 		{ "eth-peer",			1, 0, 0 },
5100d56cb81SThomas Monjalon #endif
511af75078fSIntel 		{ "ports",			1, 0, 0 },
512af75078fSIntel 		{ "nb-cores",			1, 0, 0 },
513af75078fSIntel 		{ "nb-ports",			1, 0, 0 },
514af75078fSIntel 		{ "coremask",			1, 0, 0 },
515af75078fSIntel 		{ "portmask",			1, 0, 0 },
516af75078fSIntel 		{ "numa",			0, 0, 0 },
517148f963fSBruce Richardson 		{ "mp-anon",			0, 0, 0 },
518b6ea6408SIntel 		{ "port-numa-config",           1, 0, 0 },
519b6ea6408SIntel 		{ "ring-numa-config",           1, 0, 0 },
520b6ea6408SIntel 		{ "socket-num",			1, 0, 0 },
521af75078fSIntel 		{ "mbuf-size",			1, 0, 0 },
522c8798818SIntel 		{ "total-num-mbufs",		1, 0, 0 },
523af75078fSIntel 		{ "max-pkt-len",		1, 0, 0 },
524af75078fSIntel 		{ "pkt-filter-mode",            1, 0, 0 },
525af75078fSIntel 		{ "pkt-filter-report-hash",     1, 0, 0 },
526af75078fSIntel 		{ "pkt-filter-size",            1, 0, 0 },
527af75078fSIntel 		{ "pkt-filter-drop-queue",      1, 0, 0 },
528af75078fSIntel 		{ "crc-strip",                  0, 0, 0 },
529013af9b6SIntel 		{ "enable-rx-cksum",            0, 0, 0 },
530af75078fSIntel 		{ "disable-hw-vlan",            0, 0, 0 },
531*c9dd4aadSOuyang Changchun 		{ "disable-hw-vlan-filter",     0, 0, 0 },
532*c9dd4aadSOuyang Changchun 		{ "disable-hw-vlan-strip",      0, 0, 0 },
533*c9dd4aadSOuyang Changchun 		{ "disable-hw-vlan-extend",     0, 0, 0 },
534013af9b6SIntel 		{ "enable-drop-en",            0, 0, 0 },
535af75078fSIntel 		{ "disable-rss",                0, 0, 0 },
536af75078fSIntel 		{ "port-topology",              1, 0, 0 },
537ce9b9fb0SCyril Chemparathy 		{ "forward-mode",               1, 0, 0 },
538af75078fSIntel 		{ "rss-ip",			0, 0, 0 },
539af75078fSIntel 		{ "rss-udp",			0, 0, 0 },
540af75078fSIntel 		{ "rxq",			1, 0, 0 },
541af75078fSIntel 		{ "txq",			1, 0, 0 },
542af75078fSIntel 		{ "rxd",			1, 0, 0 },
543af75078fSIntel 		{ "txd",			1, 0, 0 },
544af75078fSIntel 		{ "burst",			1, 0, 0 },
545af75078fSIntel 		{ "mbcache",			1, 0, 0 },
546af75078fSIntel 		{ "txpt",			1, 0, 0 },
547af75078fSIntel 		{ "txht",			1, 0, 0 },
548af75078fSIntel 		{ "txwt",			1, 0, 0 },
549af75078fSIntel 		{ "txfreet",			1, 0, 0 },
550af75078fSIntel 		{ "txrst",			1, 0, 0 },
551ce8d5614SIntel 		{ "txqflags",			1, 0, 0 },
552af75078fSIntel 		{ "rxpt",			1, 0, 0 },
553af75078fSIntel 		{ "rxht",			1, 0, 0 },
554af75078fSIntel 		{ "rxwt",			1, 0, 0 },
555af75078fSIntel 		{ "rxfreet",                    1, 0, 0 },
556ed30d9b6SIntel 		{ "tx-queue-stats-mapping",	1, 0, 0 },
557ed30d9b6SIntel 		{ "rx-queue-stats-mapping",	1, 0, 0 },
5587741e4cfSIntel 		{ "no-flush-rx",	0, 0, 0 },
559a7e7bb4eSCyril Chemparathy 		{ "txpkts",			1, 0, 0 },
560bc202406SDavid Marchand 		{ "disable-link-check",		0, 0, 0 },
561af75078fSIntel 		{ 0, 0, 0, 0 },
562af75078fSIntel 	};
563af75078fSIntel 
564af75078fSIntel 	argvopt = argv;
565af75078fSIntel 
5660d56cb81SThomas Monjalon #ifdef RTE_LIBRTE_CMDLINE
567ca7feb22SCyril Chemparathy #define SHORTOPTS "i"
5680d56cb81SThomas Monjalon #else
569ca7feb22SCyril Chemparathy #define SHORTOPTS ""
5700d56cb81SThomas Monjalon #endif
571ca7feb22SCyril Chemparathy 	while ((opt = getopt_long(argc, argvopt, SHORTOPTS "ah",
572af75078fSIntel 				 lgopts, &opt_idx)) != EOF) {
573af75078fSIntel 		switch (opt) {
5740d56cb81SThomas Monjalon #ifdef RTE_LIBRTE_CMDLINE
575af75078fSIntel 		case 'i':
576af75078fSIntel 			printf("Interactive-mode selected\n");
577af75078fSIntel 			interactive = 1;
578af75078fSIntel 			break;
5790d56cb81SThomas Monjalon #endif
580ca7feb22SCyril Chemparathy 		case 'a':
581ca7feb22SCyril Chemparathy 			printf("Auto-start selected\n");
582ca7feb22SCyril Chemparathy 			auto_start = 1;
583ca7feb22SCyril Chemparathy 			break;
584ca7feb22SCyril Chemparathy 
585af75078fSIntel 		case 0: /*long options */
586af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "help")) {
587af75078fSIntel 				usage(argv[0]);
588af75078fSIntel 				rte_exit(EXIT_SUCCESS, "Displayed help\n");
589af75078fSIntel 			}
5900d56cb81SThomas Monjalon #ifdef RTE_LIBRTE_CMDLINE
591af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "interactive")) {
592af75078fSIntel 				printf("Interactive-mode selected\n");
593af75078fSIntel 				interactive = 1;
594af75078fSIntel 			}
595ca7feb22SCyril Chemparathy 			if (!strcmp(lgopts[opt_idx].name, "auto-start")) {
596ca7feb22SCyril Chemparathy 				printf("Auto-start selected\n");
597ca7feb22SCyril Chemparathy 				auto_start = 1;
598ca7feb22SCyril Chemparathy 			}
599af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name,
600af75078fSIntel 				    "eth-peers-configfile")) {
601af75078fSIntel 				if (init_peer_eth_addrs(optarg) != 0)
602af75078fSIntel 					rte_exit(EXIT_FAILURE,
603af75078fSIntel 						 "Cannot open logfile\n");
604af75078fSIntel 			}
605af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
606af75078fSIntel 				char *port_end;
607af75078fSIntel 				uint8_t c, peer_addr[6];
608af75078fSIntel 
609af75078fSIntel 				errno = 0;
610af75078fSIntel 				n = strtoul(optarg, &port_end, 10);
611af75078fSIntel 				if (errno != 0 || port_end == optarg || *port_end++ != ',')
612af75078fSIntel 					rte_exit(EXIT_FAILURE,
613af75078fSIntel 						 "Invalid eth-peer: %s", optarg);
614af75078fSIntel 				if (n >= RTE_MAX_ETHPORTS)
615af75078fSIntel 					rte_exit(EXIT_FAILURE,
616af75078fSIntel 						 "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
617af75078fSIntel 						 n, RTE_MAX_ETHPORTS);
618af75078fSIntel 
619aaa662e7SAlan Carew 				if (cmdline_parse_etheraddr(NULL, port_end,
620aaa662e7SAlan Carew 						&peer_addr, sizeof(peer_addr)) < 0)
621af75078fSIntel 					rte_exit(EXIT_FAILURE,
622af75078fSIntel 						 "Invalid ethernet address: %s\n",
623af75078fSIntel 						 port_end);
624af75078fSIntel 				for (c = 0; c < 6; c++)
625af75078fSIntel 					peer_eth_addrs[n].addr_bytes[c] =
626af75078fSIntel 						peer_addr[c];
627af75078fSIntel 				nb_peer_eth_addrs++;
628af75078fSIntel 			}
6290d56cb81SThomas Monjalon #endif
630af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "nb-ports")) {
631af75078fSIntel 				n = atoi(optarg);
632edab33b1STetsuya Mukawa 				if (n > 0 &&
633edab33b1STetsuya Mukawa 				    !port_id_is_invalid(n, DISABLED_WARN))
634af75078fSIntel 					nb_fwd_ports = (uint8_t) n;
635af75078fSIntel 				else
636af75078fSIntel 					rte_exit(EXIT_FAILURE,
637edab33b1STetsuya Mukawa 						 "Invalid port %d\n", n);
638af75078fSIntel 			}
639af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "nb-cores")) {
640af75078fSIntel 				n = atoi(optarg);
641af75078fSIntel 				if (n > 0 && n <= nb_lcores)
642af75078fSIntel 					nb_fwd_lcores = (uint8_t) n;
643af75078fSIntel 				else
644af75078fSIntel 					rte_exit(EXIT_FAILURE,
645af75078fSIntel 						 "nb-cores should be > 0 and <= %d\n",
646af75078fSIntel 						 nb_lcores);
647af75078fSIntel 			}
648af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "coremask"))
649af75078fSIntel 				parse_fwd_coremask(optarg);
650af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "portmask"))
651af75078fSIntel 				parse_fwd_portmask(optarg);
652b6ea6408SIntel 			if (!strcmp(lgopts[opt_idx].name, "numa")) {
653af75078fSIntel 				numa_support = 1;
654b6ea6408SIntel 				memset(port_numa,NUMA_NO_CONFIG,RTE_MAX_ETHPORTS);
655b6ea6408SIntel 				memset(rxring_numa,NUMA_NO_CONFIG,RTE_MAX_ETHPORTS);
656b6ea6408SIntel 				memset(txring_numa,NUMA_NO_CONFIG,RTE_MAX_ETHPORTS);
657b6ea6408SIntel 			}
658148f963fSBruce Richardson 			if (!strcmp(lgopts[opt_idx].name, "mp-anon")) {
659148f963fSBruce Richardson 				mp_anon = 1;
660148f963fSBruce Richardson 			}
661b6ea6408SIntel 			if (!strcmp(lgopts[opt_idx].name, "port-numa-config")) {
662b6ea6408SIntel 				if (parse_portnuma_config(optarg))
663b6ea6408SIntel 					rte_exit(EXIT_FAILURE,
664b6ea6408SIntel 					   "invalid port-numa configuration\n");
665b6ea6408SIntel 			}
666b6ea6408SIntel 			if (!strcmp(lgopts[opt_idx].name, "ring-numa-config"))
667b6ea6408SIntel 				if (parse_ringnuma_config(optarg))
668b6ea6408SIntel 					rte_exit(EXIT_FAILURE,
669b6ea6408SIntel 					   "invalid ring-numa configuration\n");
670b6ea6408SIntel 			if (!strcmp(lgopts[opt_idx].name, "socket-num")) {
671b6ea6408SIntel 				n = atoi(optarg);
672b6ea6408SIntel 				if(n < MAX_SOCKET)
673b6ea6408SIntel 					socket_num = (uint8_t)n;
674b6ea6408SIntel 				else
675b6ea6408SIntel 					rte_exit(EXIT_FAILURE,
676b6ea6408SIntel 						"The socket number should be < %d\n",
677b6ea6408SIntel 						MAX_SOCKET);
678b6ea6408SIntel 			}
679af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "mbuf-size")) {
680af75078fSIntel 				n = atoi(optarg);
681af75078fSIntel 				if (n > 0 && n <= 0xFFFF)
682af75078fSIntel 					mbuf_data_size = (uint16_t) n;
683af75078fSIntel 				else
684af75078fSIntel 					rte_exit(EXIT_FAILURE,
685af75078fSIntel 						 "mbuf-size should be > 0 and < 65536\n");
686af75078fSIntel 			}
687c8798818SIntel 			if (!strcmp(lgopts[opt_idx].name, "total-num-mbufs")) {
688c8798818SIntel 				n = atoi(optarg);
689c8798818SIntel 				if (n > 1024)
690c8798818SIntel 					param_total_num_mbufs = (unsigned)n;
691c8798818SIntel 				else
692c8798818SIntel 					rte_exit(EXIT_FAILURE,
693c8798818SIntel 						 "total-num-mbufs should be > 1024\n");
694c8798818SIntel 			}
695af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "max-pkt-len")) {
696af75078fSIntel 				n = atoi(optarg);
697af75078fSIntel 				if (n >= ETHER_MIN_LEN) {
698af75078fSIntel 					rx_mode.max_rx_pkt_len = (uint32_t) n;
699af75078fSIntel 					if (n > ETHER_MAX_LEN)
700af75078fSIntel 					    rx_mode.jumbo_frame = 1;
701af75078fSIntel 				} else
702af75078fSIntel 					rte_exit(EXIT_FAILURE,
703af75078fSIntel 						 "Invalid max-pkt-len=%d - should be > %d\n",
704af75078fSIntel 						 n, ETHER_MIN_LEN);
705af75078fSIntel 			}
706af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "pkt-filter-mode")) {
707af75078fSIntel 				if (!strcmp(optarg, "signature"))
708af75078fSIntel 					fdir_conf.mode =
709af75078fSIntel 						RTE_FDIR_MODE_SIGNATURE;
710af75078fSIntel 				else if (!strcmp(optarg, "perfect"))
711af75078fSIntel 					fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
712af75078fSIntel 				else if (!strcmp(optarg, "none"))
713af75078fSIntel 					fdir_conf.mode = RTE_FDIR_MODE_NONE;
714af75078fSIntel 				else
715af75078fSIntel 					rte_exit(EXIT_FAILURE,
716af75078fSIntel 						 "pkt-mode-invalid %s invalid - must be: "
717af75078fSIntel 						 "none, signature or perfect\n",
718af75078fSIntel 						 optarg);
719af75078fSIntel 			}
720af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name,
721af75078fSIntel 				    "pkt-filter-report-hash")) {
722af75078fSIntel 				if (!strcmp(optarg, "none"))
723af75078fSIntel 					fdir_conf.status =
724af75078fSIntel 						RTE_FDIR_NO_REPORT_STATUS;
725af75078fSIntel 				else if (!strcmp(optarg, "match"))
726af75078fSIntel 					fdir_conf.status =
727af75078fSIntel 						RTE_FDIR_REPORT_STATUS;
728af75078fSIntel 				else if (!strcmp(optarg, "always"))
729af75078fSIntel 					fdir_conf.status =
730af75078fSIntel 						RTE_FDIR_REPORT_STATUS_ALWAYS;
731af75078fSIntel 				else
732af75078fSIntel 					rte_exit(EXIT_FAILURE,
733af75078fSIntel 						 "pkt-filter-report-hash %s invalid "
734af75078fSIntel 						 "- must be: none or match or always\n",
735af75078fSIntel 						 optarg);
736af75078fSIntel 			}
737af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "pkt-filter-size")) {
738af75078fSIntel 				if (!strcmp(optarg, "64K"))
739af75078fSIntel 					fdir_conf.pballoc =
740af75078fSIntel 						RTE_FDIR_PBALLOC_64K;
741af75078fSIntel 				else if (!strcmp(optarg, "128K"))
742af75078fSIntel 					fdir_conf.pballoc =
743af75078fSIntel 						RTE_FDIR_PBALLOC_128K;
744af75078fSIntel 				else if (!strcmp(optarg, "256K"))
745af75078fSIntel 					fdir_conf.pballoc =
746af75078fSIntel 						RTE_FDIR_PBALLOC_256K;
747af75078fSIntel 				else
748af75078fSIntel 					rte_exit(EXIT_FAILURE, "pkt-filter-size %s invalid -"
749af75078fSIntel 						 " must be: 64K or 128K or 256K\n",
750af75078fSIntel 						 optarg);
751af75078fSIntel 			}
752af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name,
753af75078fSIntel 				    "pkt-filter-drop-queue")) {
754af75078fSIntel 				n = atoi(optarg);
755af75078fSIntel 				if (n >= 0)
756af75078fSIntel 					fdir_conf.drop_queue = (uint8_t) n;
757af75078fSIntel 				else
758af75078fSIntel 					rte_exit(EXIT_FAILURE,
759af75078fSIntel 						 "drop queue %d invalid - must"
760af75078fSIntel 						 "be >= 0 \n", n);
761af75078fSIntel 			}
762af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "crc-strip"))
763af75078fSIntel 				rx_mode.hw_strip_crc = 1;
764af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "enable-rx-cksum"))
765af75078fSIntel 				rx_mode.hw_ip_checksum = 1;
766a47aa8b9SIntel 
767a47aa8b9SIntel 			if (!strcmp(lgopts[opt_idx].name, "disable-hw-vlan")) {
768af75078fSIntel 				rx_mode.hw_vlan_filter = 0;
769a47aa8b9SIntel 				rx_mode.hw_vlan_strip  = 0;
770a47aa8b9SIntel 				rx_mode.hw_vlan_extend = 0;
771a47aa8b9SIntel 			}
772a47aa8b9SIntel 
773*c9dd4aadSOuyang Changchun 			if (!strcmp(lgopts[opt_idx].name,
774*c9dd4aadSOuyang Changchun 					"disable-hw-vlan-filter"))
775*c9dd4aadSOuyang Changchun 				rx_mode.hw_vlan_filter = 0;
776*c9dd4aadSOuyang Changchun 
777*c9dd4aadSOuyang Changchun 			if (!strcmp(lgopts[opt_idx].name,
778*c9dd4aadSOuyang Changchun 					"disable-hw-vlan-strip"))
779*c9dd4aadSOuyang Changchun 				rx_mode.hw_vlan_strip  = 0;
780*c9dd4aadSOuyang Changchun 
781*c9dd4aadSOuyang Changchun 			if (!strcmp(lgopts[opt_idx].name,
782*c9dd4aadSOuyang Changchun 					"disable-hw-vlan-extend"))
783*c9dd4aadSOuyang Changchun 				rx_mode.hw_vlan_extend = 0;
784*c9dd4aadSOuyang Changchun 
785ce8d5614SIntel 			if (!strcmp(lgopts[opt_idx].name, "enable-drop-en"))
786ce8d5614SIntel 				rx_drop_en = 1;
787ce8d5614SIntel 
788af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "disable-rss"))
789af75078fSIntel 				rss_hf = 0;
790af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "port-topology")) {
791af75078fSIntel 				if (!strcmp(optarg, "paired"))
792af75078fSIntel 					port_topology = PORT_TOPOLOGY_PAIRED;
793af75078fSIntel 				else if (!strcmp(optarg, "chained"))
794af75078fSIntel 					port_topology = PORT_TOPOLOGY_CHAINED;
7953e2006d6SCyril Chemparathy 				else if (!strcmp(optarg, "loop"))
7963e2006d6SCyril Chemparathy 					port_topology = PORT_TOPOLOGY_LOOP;
797af75078fSIntel 				else
798af75078fSIntel 					rte_exit(EXIT_FAILURE, "port-topology %s invalid -"
799af75078fSIntel 						 " must be: paired or chained \n",
800af75078fSIntel 						 optarg);
801af75078fSIntel 			}
802ce9b9fb0SCyril Chemparathy 			if (!strcmp(lgopts[opt_idx].name, "forward-mode"))
803ce9b9fb0SCyril Chemparathy 				set_pkt_forwarding_mode(optarg);
804af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "rss-ip"))
8058a387fa8SHelin Zhang 				rss_hf = ETH_RSS_IP;
806af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "rss-udp"))
8078a387fa8SHelin Zhang 				rss_hf = ETH_RSS_UDP;
808af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "rxq")) {
809af75078fSIntel 				n = atoi(optarg);
810af75078fSIntel 				if (n >= 1 && n <= (int) MAX_QUEUE_ID)
811af75078fSIntel 					nb_rxq = (queueid_t) n;
812af75078fSIntel 				else
813af75078fSIntel 					rte_exit(EXIT_FAILURE, "rxq %d invalid - must be"
814af75078fSIntel 						  " >= 1 && <= %d\n", n,
815af75078fSIntel 						  (int) MAX_QUEUE_ID);
816af75078fSIntel 			}
817af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "txq")) {
818af75078fSIntel 				n = atoi(optarg);
819af75078fSIntel 				if (n >= 1 && n <= (int) MAX_QUEUE_ID)
820af75078fSIntel 					nb_txq = (queueid_t) n;
821af75078fSIntel 				else
822af75078fSIntel 					rte_exit(EXIT_FAILURE, "txq %d invalid - must be"
823af75078fSIntel 						  " >= 1 && <= %d\n", n,
824af75078fSIntel 						  (int) MAX_QUEUE_ID);
825af75078fSIntel 			}
826af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "burst")) {
827af75078fSIntel 				n = atoi(optarg);
828af75078fSIntel 				if ((n >= 1) && (n <= MAX_PKT_BURST))
829af75078fSIntel 					nb_pkt_per_burst = (uint16_t) n;
830af75078fSIntel 				else
831af75078fSIntel 					rte_exit(EXIT_FAILURE,
832af75078fSIntel 						 "burst must >= 1 and <= %d]",
833af75078fSIntel 						 MAX_PKT_BURST);
834af75078fSIntel 			}
835af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "mbcache")) {
836af75078fSIntel 				n = atoi(optarg);
837af75078fSIntel 				if ((n >= 0) &&
838af75078fSIntel 				    (n <= RTE_MEMPOOL_CACHE_MAX_SIZE))
839af75078fSIntel 					mb_mempool_cache = (uint16_t) n;
840af75078fSIntel 				else
841af75078fSIntel 					rte_exit(EXIT_FAILURE,
842af75078fSIntel 						 "mbcache must be >= 0 and <= %d\n",
843af75078fSIntel 						 RTE_MEMPOOL_CACHE_MAX_SIZE);
844af75078fSIntel 			}
845af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "txfreet")) {
846af75078fSIntel 				n = atoi(optarg);
847af75078fSIntel 				if (n >= 0)
848f2c5125aSPablo de Lara 					tx_free_thresh = (int16_t)n;
849af75078fSIntel 				else
850af75078fSIntel 					rte_exit(EXIT_FAILURE, "txfreet must be >= 0\n");
851af75078fSIntel 			}
852af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "txrst")) {
853af75078fSIntel 				n = atoi(optarg);
854af75078fSIntel 				if (n >= 0)
855f2c5125aSPablo de Lara 					tx_rs_thresh = (int16_t)n;
856af75078fSIntel 				else
857af75078fSIntel 					rte_exit(EXIT_FAILURE, "txrst must be >= 0\n");
858af75078fSIntel 			}
859ce8d5614SIntel 			if (!strcmp(lgopts[opt_idx].name, "txqflags")) {
860ce8d5614SIntel 				char *end = NULL;
861ce8d5614SIntel 				n = strtoul(optarg, &end, 16);
862ce8d5614SIntel 				if (n >= 0)
863f2c5125aSPablo de Lara 					txq_flags = (int32_t)n;
864ce8d5614SIntel 				else
865ce8d5614SIntel 					rte_exit(EXIT_FAILURE,
866ce8d5614SIntel 						 "txqflags must be >= 0\n");
867ce8d5614SIntel 			}
868af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "rxd")) {
869af75078fSIntel 				n = atoi(optarg);
870af75078fSIntel 				if (n > 0) {
871af75078fSIntel 					if (rx_free_thresh >= n)
872af75078fSIntel 						rte_exit(EXIT_FAILURE,
873af75078fSIntel 							 "rxd must be > "
874af75078fSIntel 							 "rx_free_thresh(%d)\n",
875af75078fSIntel 							 (int)rx_free_thresh);
876af75078fSIntel 					else
877af75078fSIntel 						nb_rxd = (uint16_t) n;
878af75078fSIntel 				} else
879af75078fSIntel 					rte_exit(EXIT_FAILURE,
880af75078fSIntel 						 "rxd(%d) invalid - must be > 0\n",
881af75078fSIntel 						 n);
882af75078fSIntel 			}
883af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "txd")) {
884af75078fSIntel 				n = atoi(optarg);
885af75078fSIntel 				if (n > 0)
886af75078fSIntel 					nb_txd = (uint16_t) n;
887af75078fSIntel 				else
888af75078fSIntel 					rte_exit(EXIT_FAILURE, "txd must be in > 0\n");
889af75078fSIntel 			}
890af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "txpt")) {
891af75078fSIntel 				n = atoi(optarg);
892af75078fSIntel 				if (n >= 0)
893f2c5125aSPablo de Lara 					tx_pthresh = (int8_t)n;
894af75078fSIntel 				else
895af75078fSIntel 					rte_exit(EXIT_FAILURE, "txpt must be >= 0\n");
896af75078fSIntel 			}
897af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "txht")) {
898af75078fSIntel 				n = atoi(optarg);
899af75078fSIntel 				if (n >= 0)
900f2c5125aSPablo de Lara 					tx_hthresh = (int8_t)n;
901af75078fSIntel 				else
902af75078fSIntel 					rte_exit(EXIT_FAILURE, "txht must be >= 0\n");
903af75078fSIntel 			}
904af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "txwt")) {
905af75078fSIntel 				n = atoi(optarg);
906af75078fSIntel 				if (n >= 0)
907f2c5125aSPablo de Lara 					tx_wthresh = (int8_t)n;
908af75078fSIntel 				else
909af75078fSIntel 					rte_exit(EXIT_FAILURE, "txwt must be >= 0\n");
910af75078fSIntel 			}
911af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "rxpt")) {
912af75078fSIntel 				n = atoi(optarg);
913af75078fSIntel 				if (n >= 0)
914f2c5125aSPablo de Lara 					rx_pthresh = (int8_t)n;
915af75078fSIntel 				else
916af75078fSIntel 					rte_exit(EXIT_FAILURE, "rxpt must be >= 0\n");
917af75078fSIntel 			}
918af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "rxht")) {
919af75078fSIntel 				n = atoi(optarg);
920af75078fSIntel 				if (n >= 0)
921f2c5125aSPablo de Lara 					rx_hthresh = (int8_t)n;
922af75078fSIntel 				else
923af75078fSIntel 					rte_exit(EXIT_FAILURE, "rxht must be >= 0\n");
924af75078fSIntel 			}
925af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "rxwt")) {
926af75078fSIntel 				n = atoi(optarg);
927af75078fSIntel 				if (n >= 0)
928f2c5125aSPablo de Lara 					rx_wthresh = (int8_t)n;
929af75078fSIntel 				else
930af75078fSIntel 					rte_exit(EXIT_FAILURE, "rxwt must be >= 0\n");
931af75078fSIntel 			}
932af75078fSIntel 			if (!strcmp(lgopts[opt_idx].name, "rxfreet")) {
933af75078fSIntel 				n = atoi(optarg);
934af75078fSIntel 				if (n >= 0)
935f2c5125aSPablo de Lara 					rx_free_thresh = (int16_t)n;
936af75078fSIntel 				else
937af75078fSIntel 					rte_exit(EXIT_FAILURE, "rxfreet must be >= 0\n");
938af75078fSIntel 			}
939ed30d9b6SIntel 			if (!strcmp(lgopts[opt_idx].name, "tx-queue-stats-mapping")) {
940ed30d9b6SIntel 				if (parse_queue_stats_mapping_config(optarg, TX)) {
941ed30d9b6SIntel 					rte_exit(EXIT_FAILURE,
942ed30d9b6SIntel 						 "invalid TX queue statistics mapping config entered\n");
943ed30d9b6SIntel 				}
944ed30d9b6SIntel 			}
945ed30d9b6SIntel 			if (!strcmp(lgopts[opt_idx].name, "rx-queue-stats-mapping")) {
946ed30d9b6SIntel 				if (parse_queue_stats_mapping_config(optarg, RX)) {
947ed30d9b6SIntel 					rte_exit(EXIT_FAILURE,
948ed30d9b6SIntel 						 "invalid RX queue statistics mapping config entered\n");
949ed30d9b6SIntel 				}
950ed30d9b6SIntel 			}
951a7e7bb4eSCyril Chemparathy 			if (!strcmp(lgopts[opt_idx].name, "txpkts")) {
952a7e7bb4eSCyril Chemparathy 				unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
953a7e7bb4eSCyril Chemparathy 				unsigned int nb_segs;
954a7e7bb4eSCyril Chemparathy 
955950d1516SBruce Richardson 				nb_segs = parse_item_list(optarg, "txpkt segments",
956950d1516SBruce Richardson 						RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
957a7e7bb4eSCyril Chemparathy 				if (nb_segs > 0)
958a7e7bb4eSCyril Chemparathy 					set_tx_pkt_segments(seg_lengths, nb_segs);
959a7e7bb4eSCyril Chemparathy 				else
960a7e7bb4eSCyril Chemparathy 					rte_exit(EXIT_FAILURE, "bad txpkts\n");
961a7e7bb4eSCyril Chemparathy 			}
9627741e4cfSIntel 			if (!strcmp(lgopts[opt_idx].name, "no-flush-rx"))
9637741e4cfSIntel 				no_flush_rx = 1;
964bc202406SDavid Marchand 			if (!strcmp(lgopts[opt_idx].name, "disable-link-check"))
965bc202406SDavid Marchand 				no_link_check = 1;
9667741e4cfSIntel 
967af75078fSIntel 			break;
968af75078fSIntel 		case 'h':
969af75078fSIntel 			usage(argv[0]);
970af75078fSIntel 			rte_exit(EXIT_SUCCESS, "Displayed help\n");
971af75078fSIntel 			break;
972af75078fSIntel 		default:
973af75078fSIntel 			usage(argv[0]);
974af75078fSIntel 			rte_exit(EXIT_FAILURE,
975af75078fSIntel 				 "Command line is incomplete or incorrect\n");
976af75078fSIntel 			break;
977af75078fSIntel 		}
978af75078fSIntel 	}
979af75078fSIntel }
980