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