test/dma: check index when no DMA completed
[dpdk.git] / app / test-pipeline / config.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation
3  */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <stdint.h>
8 #include <inttypes.h>
9 #include <sys/types.h>
10 #include <string.h>
11 #include <sys/queue.h>
12 #include <stdarg.h>
13 #include <errno.h>
14 #include <getopt.h>
15
16 #include <rte_common.h>
17 #include <rte_byteorder.h>
18 #include <rte_log.h>
19 #include <rte_memory.h>
20 #include <rte_memcpy.h>
21 #include <rte_eal.h>
22 #include <rte_per_lcore.h>
23 #include <rte_launch.h>
24 #include <rte_cycles.h>
25 #include <rte_prefetch.h>
26 #include <rte_lcore.h>
27 #include <rte_branch_prediction.h>
28 #include <rte_interrupts.h>
29 #include <rte_pci.h>
30 #include <rte_random.h>
31 #include <rte_debug.h>
32 #include <rte_ether.h>
33 #include <rte_ethdev.h>
34 #include <rte_mempool.h>
35 #include <rte_mbuf.h>
36 #include <rte_ip.h>
37 #include <rte_tcp.h>
38 #include <rte_lpm.h>
39 #include <rte_lpm6.h>
40 #include <rte_string_fns.h>
41
42 #include "main.h"
43
44 static const char usage[] = "\n";
45
46 void
47 app_print_usage(void)
48 {
49         printf(usage);
50 }
51
52 static int
53 app_parse_port_mask(const char *arg)
54 {
55         char *end = NULL;
56         uint64_t port_mask;
57         uint32_t i;
58
59         if (arg[0] == '\0')
60                 return -1;
61
62         port_mask = strtoul(arg, &end, 16);
63         if ((end == NULL) || (*end != '\0'))
64                 return -2;
65
66         if (port_mask == 0)
67                 return -3;
68
69         app.n_ports = 0;
70         for (i = 0; i < 64; i++) {
71                 if ((port_mask & (1LLU << i)) == 0)
72                         continue;
73
74                 if (app.n_ports >= APP_MAX_PORTS)
75                         return -4;
76
77                 app.ports[app.n_ports] = i;
78                 app.n_ports++;
79         }
80
81         if (!rte_is_power_of_2(app.n_ports))
82                 return -5;
83
84         return 0;
85 }
86
87 struct {
88         const char *name;
89         uint32_t value;
90 } app_args_table[] = {
91         {"none", e_APP_PIPELINE_NONE},
92         {"stub", e_APP_PIPELINE_STUB},
93         {"hash-8-ext", e_APP_PIPELINE_HASH_KEY8_EXT},
94         {"hash-8-lru", e_APP_PIPELINE_HASH_KEY8_LRU},
95         {"hash-16-ext", e_APP_PIPELINE_HASH_KEY16_EXT},
96         {"hash-16-lru", e_APP_PIPELINE_HASH_KEY16_LRU},
97         {"hash-32-ext", e_APP_PIPELINE_HASH_KEY32_EXT},
98         {"hash-32-lru", e_APP_PIPELINE_HASH_KEY32_LRU},
99         {"hash-spec-8-ext", e_APP_PIPELINE_HASH_SPEC_KEY8_EXT},
100         {"hash-spec-8-lru", e_APP_PIPELINE_HASH_SPEC_KEY8_LRU},
101         {"hash-spec-16-ext", e_APP_PIPELINE_HASH_SPEC_KEY16_EXT},
102         {"hash-spec-16-lru", e_APP_PIPELINE_HASH_SPEC_KEY16_LRU},
103         {"hash-spec-32-ext", e_APP_PIPELINE_HASH_SPEC_KEY32_EXT},
104         {"hash-spec-32-lru", e_APP_PIPELINE_HASH_SPEC_KEY32_LRU},
105         {"acl", e_APP_PIPELINE_ACL},
106         {"lpm", e_APP_PIPELINE_LPM},
107         {"lpm-ipv6", e_APP_PIPELINE_LPM_IPV6},
108         {"hash-cuckoo-8", e_APP_PIPELINE_HASH_CUCKOO_KEY8},
109         {"hash-cuckoo-16", e_APP_PIPELINE_HASH_CUCKOO_KEY16},
110         {"hash-cuckoo-32", e_APP_PIPELINE_HASH_CUCKOO_KEY32},
111         {"hash-cuckoo-48", e_APP_PIPELINE_HASH_CUCKOO_KEY48},
112         {"hash-cuckoo-64", e_APP_PIPELINE_HASH_CUCKOO_KEY64},
113         {"hash-cuckoo-80", e_APP_PIPELINE_HASH_CUCKOO_KEY80},
114         {"hash-cuckoo-96", e_APP_PIPELINE_HASH_CUCKOO_KEY96},
115         {"hash-cuckoo-112", e_APP_PIPELINE_HASH_CUCKOO_KEY112},
116         {"hash-cuckoo-128", e_APP_PIPELINE_HASH_CUCKOO_KEY128},
117 };
118
119 int
120 app_parse_args(int argc, char **argv)
121 {
122         int opt, ret;
123         char **argvopt;
124         int option_index;
125         char *prgname = argv[0];
126         static struct option lgopts[] = {
127                 {"none", 0, 0, 0},
128                 {"stub", 0, 0, 0},
129                 {"hash-8-ext", 0, 0, 0},
130                 {"hash-8-lru", 0, 0, 0},
131                 {"hash-16-ext", 0, 0, 0},
132                 {"hash-16-lru", 0, 0, 0},
133                 {"hash-32-ext", 0, 0, 0},
134                 {"hash-32-lru", 0, 0, 0},
135                 {"hash-spec-8-ext", 0, 0, 0},
136                 {"hash-spec-8-lru", 0, 0, 0},
137                 {"hash-spec-16-ext", 0, 0, 0},
138                 {"hash-spec-16-lru", 0, 0, 0},
139                 {"hash-spec-32-ext", 0, 0, 0},
140                 {"hash-spec-32-lru", 0, 0, 0},
141                 {"acl", 0, 0, 0},
142                 {"lpm", 0, 0, 0},
143                 {"lpm-ipv6", 0, 0, 0},
144                 {"hash-cuckoo-8", 0, 0, 0},
145                 {"hash-cuckoo-16", 0, 0, 0},
146                 {"hash-cuckoo-32", 0, 0, 0},
147                 {"hash-cuckoo-48", 0, 0, 0},
148                 {"hash-cuckoo-64", 0, 0, 0},
149                 {"hash-cuckoo-80", 0, 0, 0},
150                 {"hash-cuckoo-96", 0, 0, 0},
151                 {"hash-cuckoo-112", 0, 0, 0},
152                 {"hash-cuckoo-128", 0, 0, 0},
153                 {NULL, 0, 0, 0}
154         };
155         uint32_t lcores[3], n_lcores, lcore_id, pipeline_type_provided;
156
157         /* EAL args */
158         n_lcores = 0;
159         for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
160                 if (rte_lcore_is_enabled(lcore_id) == 0)
161                         continue;
162
163                 if (n_lcores >= 3) {
164                         RTE_LOG(ERR, USER1, "Number of cores must be 3\n");
165                         app_print_usage();
166                         return -1;
167                 }
168
169                 lcores[n_lcores] = lcore_id;
170                 n_lcores++;
171         }
172
173         if (n_lcores != 3) {
174                 RTE_LOG(ERR, USER1, "Number of cores must be 3\n");
175                 app_print_usage();
176                 return -1;
177         }
178
179         app.core_rx = lcores[0];
180         app.core_worker = lcores[1];
181         app.core_tx = lcores[2];
182
183         /* Non-EAL args */
184         argvopt = argv;
185
186         app.pipeline_type = e_APP_PIPELINE_HASH_KEY16_LRU;
187         pipeline_type_provided = 0;
188
189         while ((opt = getopt_long(argc, argvopt, "p:",
190                         lgopts, &option_index)) != EOF) {
191                 switch (opt) {
192                 case 'p':
193                         if (app_parse_port_mask(optarg) < 0) {
194                                 app_print_usage();
195                                 return -1;
196                         }
197                         break;
198
199                 case 0: /* long options */
200                         if (!pipeline_type_provided) {
201                                 uint32_t i;
202
203                                 for (i = 0; i < e_APP_PIPELINES; i++) {
204                                         if (!strcmp(lgopts[option_index].name,
205                                                 app_args_table[i].name)) {
206                                                 app.pipeline_type =
207                                                         app_args_table[i].value;
208                                                 pipeline_type_provided = 1;
209                                                 break;
210                                         }
211                                 }
212
213                                 break;
214                         }
215
216                         app_print_usage();
217                         return -1;
218
219                 default:
220                         return -1;
221                 }
222         }
223
224         if (optind >= 0)
225                 argv[optind - 1] = prgname;
226
227         ret = optind - 1;
228         optind = 1; /* reset getopt lib */
229         return ret;
230 }