examples/ip_pipeline: remove config
[dpdk.git] / examples / ip_pipeline / init.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation
3  */
4
5 #include <inttypes.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <netinet/in.h>
9 #ifdef RTE_EXEC_ENV_LINUXAPP
10 #include <linux/if.h>
11 #include <linux/if_tun.h>
12 #endif
13 #include <fcntl.h>
14 #include <sys/ioctl.h>
15 #include <unistd.h>
16
17 #include <rte_cycles.h>
18 #include <rte_ethdev.h>
19 #include <rte_ether.h>
20 #include <rte_ip.h>
21 #include <rte_eal.h>
22 #include <rte_malloc.h>
23 #include <rte_bus_pci.h>
24
25 #include "app.h"
26 #include "pipeline.h"
27
28 #define APP_NAME_SIZE   32
29
30 #define APP_RETA_SIZE_MAX     (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE)
31
32 static void
33 app_init_core_map(struct app_params *app)
34 {
35         APP_LOG(app, HIGH, "Initializing CPU core map ...");
36         app->core_map = cpu_core_map_init(RTE_MAX_NUMA_NODES, RTE_MAX_LCORE,
37                                 4, 0);
38
39         if (app->core_map == NULL)
40                 rte_panic("Cannot create CPU core map\n");
41
42         if (app->log_level >= APP_LOG_LEVEL_LOW)
43                 cpu_core_map_print(app->core_map);
44 }
45
46 /* Core Mask String in Hex Representation */
47 #define APP_CORE_MASK_STRING_SIZE ((64 * APP_CORE_MASK_SIZE) / 8 * 2 + 1)
48
49 static void
50 app_init_core_mask(struct app_params *app)
51 {
52         uint32_t i;
53         char core_mask_str[APP_CORE_MASK_STRING_SIZE];
54
55         for (i = 0; i < app->n_pipelines; i++) {
56                 struct app_pipeline_params *p = &app->pipeline_params[i];
57                 int lcore_id;
58
59                 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
60                         p->socket_id,
61                         p->core_id,
62                         p->hyper_th_id);
63
64                 if (lcore_id < 0)
65                         rte_panic("Cannot create CPU core mask\n");
66
67                 app_core_enable_in_core_mask(app, lcore_id);
68         }
69
70         app_core_build_core_mask_string(app, core_mask_str);
71         APP_LOG(app, HIGH, "CPU core mask = 0x%s", core_mask_str);
72 }
73
74 static void
75 app_init_eal(struct app_params *app)
76 {
77         char buffer[256];
78         char core_mask_str[APP_CORE_MASK_STRING_SIZE];
79         struct app_eal_params *p = &app->eal_params;
80         uint32_t n_args = 0;
81         uint32_t i;
82         int status;
83
84         app->eal_argv[n_args++] = strdup(app->app_name);
85
86         app_core_build_core_mask_string(app, core_mask_str);
87         snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
88         app->eal_argv[n_args++] = strdup(buffer);
89
90         if (p->coremap) {
91                 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
92                 app->eal_argv[n_args++] = strdup(buffer);
93         }
94
95         if (p->master_lcore_present) {
96                 snprintf(buffer,
97                         sizeof(buffer),
98                         "--master-lcore=%" PRIu32,
99                         p->master_lcore);
100                 app->eal_argv[n_args++] = strdup(buffer);
101         }
102
103         snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
104         app->eal_argv[n_args++] = strdup(buffer);
105
106         if (p->memory_present) {
107                 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
108                 app->eal_argv[n_args++] = strdup(buffer);
109         }
110
111         if (p->ranks_present) {
112                 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
113                 app->eal_argv[n_args++] = strdup(buffer);
114         }
115
116         for (i = 0; i < APP_MAX_LINKS; i++) {
117                 if (p->pci_blacklist[i] == NULL)
118                         break;
119
120                 snprintf(buffer,
121                         sizeof(buffer),
122                         "--pci-blacklist=%s",
123                         p->pci_blacklist[i]);
124                 app->eal_argv[n_args++] = strdup(buffer);
125         }
126
127         if (app->port_mask != 0)
128                 for (i = 0; i < APP_MAX_LINKS; i++) {
129                         if (p->pci_whitelist[i] == NULL)
130                                 break;
131
132                         snprintf(buffer,
133                                 sizeof(buffer),
134                                 "--pci-whitelist=%s",
135                                 p->pci_whitelist[i]);
136                         app->eal_argv[n_args++] = strdup(buffer);
137                 }
138         else
139                 for (i = 0; i < app->n_links; i++) {
140                         char *pci_bdf = app->link_params[i].pci_bdf;
141
142                         snprintf(buffer,
143                                 sizeof(buffer),
144                                 "--pci-whitelist=%s",
145                                 pci_bdf);
146                         app->eal_argv[n_args++] = strdup(buffer);
147                 }
148
149         for (i = 0; i < APP_MAX_LINKS; i++) {
150                 if (p->vdev[i] == NULL)
151                         break;
152
153                 snprintf(buffer,
154                         sizeof(buffer),
155                         "--vdev=%s",
156                         p->vdev[i]);
157                 app->eal_argv[n_args++] = strdup(buffer);
158         }
159
160         if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
161                 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
162                 app->eal_argv[n_args++] = strdup(buffer);
163         }
164
165         if (p->proc_type) {
166                 snprintf(buffer,
167                         sizeof(buffer),
168                         "--proc-type=%s",
169                         p->proc_type);
170                 app->eal_argv[n_args++] = strdup(buffer);
171         }
172
173         if (p->syslog) {
174                 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
175                 app->eal_argv[n_args++] = strdup(buffer);
176         }
177
178         if (p->log_level_present) {
179                 snprintf(buffer,
180                         sizeof(buffer),
181                         "--log-level=%" PRIu32,
182                         p->log_level);
183                 app->eal_argv[n_args++] = strdup(buffer);
184         }
185
186         if ((p->version_present) && p->version) {
187                 snprintf(buffer, sizeof(buffer), "-v");
188                 app->eal_argv[n_args++] = strdup(buffer);
189         }
190
191         if ((p->help_present) && p->help) {
192                 snprintf(buffer, sizeof(buffer), "--help");
193                 app->eal_argv[n_args++] = strdup(buffer);
194         }
195
196         if ((p->no_huge_present) && p->no_huge) {
197                 snprintf(buffer, sizeof(buffer), "--no-huge");
198                 app->eal_argv[n_args++] = strdup(buffer);
199         }
200
201         if ((p->no_pci_present) && p->no_pci) {
202                 snprintf(buffer, sizeof(buffer), "--no-pci");
203                 app->eal_argv[n_args++] = strdup(buffer);
204         }
205
206         if ((p->no_hpet_present) && p->no_hpet) {
207                 snprintf(buffer, sizeof(buffer), "--no-hpet");
208                 app->eal_argv[n_args++] = strdup(buffer);
209         }
210
211         if ((p->no_shconf_present) && p->no_shconf) {
212                 snprintf(buffer, sizeof(buffer), "--no-shconf");
213                 app->eal_argv[n_args++] = strdup(buffer);
214         }
215
216         if (p->add_driver) {
217                 snprintf(buffer, sizeof(buffer), "-d%s", p->add_driver);
218                 app->eal_argv[n_args++] = strdup(buffer);
219         }
220
221         if (p->socket_mem) {
222                 snprintf(buffer,
223                         sizeof(buffer),
224                         "--socket-mem=%s",
225                         p->socket_mem);
226                 app->eal_argv[n_args++] = strdup(buffer);
227         }
228
229         if (p->huge_dir) {
230                 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
231                 app->eal_argv[n_args++] = strdup(buffer);
232         }
233
234         if (p->file_prefix) {
235                 snprintf(buffer,
236                         sizeof(buffer),
237                         "--file-prefix=%s",
238                         p->file_prefix);
239                 app->eal_argv[n_args++] = strdup(buffer);
240         }
241
242         if (p->base_virtaddr) {
243                 snprintf(buffer,
244                         sizeof(buffer),
245                         "--base-virtaddr=%s",
246                         p->base_virtaddr);
247                 app->eal_argv[n_args++] = strdup(buffer);
248         }
249
250         if ((p->create_uio_dev_present) && p->create_uio_dev) {
251                 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
252                 app->eal_argv[n_args++] = strdup(buffer);
253         }
254
255         if (p->vfio_intr) {
256                 snprintf(buffer,
257                         sizeof(buffer),
258                         "--vfio-intr=%s",
259                         p->vfio_intr);
260                 app->eal_argv[n_args++] = strdup(buffer);
261         }
262
263         snprintf(buffer, sizeof(buffer), "--");
264         app->eal_argv[n_args++] = strdup(buffer);
265
266         app->eal_argc = n_args;
267
268         APP_LOG(app, HIGH, "Initializing EAL ...");
269         if (app->log_level >= APP_LOG_LEVEL_LOW) {
270                 int i;
271
272                 fprintf(stdout, "[APP] EAL arguments: \"");
273                 for (i = 1; i < app->eal_argc; i++)
274                         fprintf(stdout, "%s ", app->eal_argv[i]);
275                 fprintf(stdout, "\"\n");
276         }
277
278         status = rte_eal_init(app->eal_argc, app->eal_argv);
279         if (status < 0)
280                 rte_panic("EAL init error\n");
281 }
282
283 static void
284 app_init_mempool(struct app_params *app)
285 {
286         uint32_t i;
287
288         for (i = 0; i < app->n_mempools; i++) {
289                 struct app_mempool_params *p = &app->mempool_params[i];
290
291                 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
292                 app->mempool[i] = rte_pktmbuf_pool_create(
293                         p->name,
294                         p->pool_size,
295                         p->cache_size,
296                         0, /* priv_size */
297                         p->buffer_size -
298                                 sizeof(struct rte_mbuf), /* mbuf data size */
299                         p->cpu_socket_id);
300
301                 if (app->mempool[i] == NULL)
302                         rte_panic("%s init error\n", p->name);
303         }
304 }
305
306 static inline int
307 app_link_filter_arp_add(struct app_link_params *link)
308 {
309         struct rte_eth_ethertype_filter filter = {
310                 .ether_type = ETHER_TYPE_ARP,
311                 .flags = 0,
312                 .queue = link->arp_q,
313         };
314
315         return rte_eth_dev_filter_ctrl(link->pmd_id,
316                 RTE_ETH_FILTER_ETHERTYPE,
317                 RTE_ETH_FILTER_ADD,
318                 &filter);
319 }
320
321 static inline int
322 app_link_filter_tcp_syn_add(struct app_link_params *link)
323 {
324         struct rte_eth_syn_filter filter = {
325                 .hig_pri = 1,
326                 .queue = link->tcp_syn_q,
327         };
328
329         return rte_eth_dev_filter_ctrl(link->pmd_id,
330                 RTE_ETH_FILTER_SYN,
331                 RTE_ETH_FILTER_ADD,
332                 &filter);
333 }
334
335 static inline int
336 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
337 {
338         struct rte_eth_ntuple_filter filter = {
339                 .flags = RTE_5TUPLE_FLAGS,
340                 .dst_ip = rte_bswap32(l2->ip),
341                 .dst_ip_mask = UINT32_MAX, /* Enable */
342                 .src_ip = 0,
343                 .src_ip_mask = 0, /* Disable */
344                 .dst_port = 0,
345                 .dst_port_mask = 0, /* Disable */
346                 .src_port = 0,
347                 .src_port_mask = 0, /* Disable */
348                 .proto = 0,
349                 .proto_mask = 0, /* Disable */
350                 .tcp_flags = 0,
351                 .priority = 1, /* Lowest */
352                 .queue = l1->ip_local_q,
353         };
354
355         return rte_eth_dev_filter_ctrl(l1->pmd_id,
356                 RTE_ETH_FILTER_NTUPLE,
357                 RTE_ETH_FILTER_ADD,
358                 &filter);
359 }
360
361 static inline int
362 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
363 {
364         struct rte_eth_ntuple_filter filter = {
365                 .flags = RTE_5TUPLE_FLAGS,
366                 .dst_ip = rte_bswap32(l2->ip),
367                 .dst_ip_mask = UINT32_MAX, /* Enable */
368                 .src_ip = 0,
369                 .src_ip_mask = 0, /* Disable */
370                 .dst_port = 0,
371                 .dst_port_mask = 0, /* Disable */
372                 .src_port = 0,
373                 .src_port_mask = 0, /* Disable */
374                 .proto = 0,
375                 .proto_mask = 0, /* Disable */
376                 .tcp_flags = 0,
377                 .priority = 1, /* Lowest */
378                 .queue = l1->ip_local_q,
379         };
380
381         return rte_eth_dev_filter_ctrl(l1->pmd_id,
382                 RTE_ETH_FILTER_NTUPLE,
383                 RTE_ETH_FILTER_DELETE,
384                 &filter);
385 }
386
387 static inline int
388 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
389 {
390         struct rte_eth_ntuple_filter filter = {
391                 .flags = RTE_5TUPLE_FLAGS,
392                 .dst_ip = rte_bswap32(l2->ip),
393                 .dst_ip_mask = UINT32_MAX, /* Enable */
394                 .src_ip = 0,
395                 .src_ip_mask = 0, /* Disable */
396                 .dst_port = 0,
397                 .dst_port_mask = 0, /* Disable */
398                 .src_port = 0,
399                 .src_port_mask = 0, /* Disable */
400                 .proto = IPPROTO_TCP,
401                 .proto_mask = UINT8_MAX, /* Enable */
402                 .tcp_flags = 0,
403                 .priority = 2, /* Higher priority than IP */
404                 .queue = l1->tcp_local_q,
405         };
406
407         return rte_eth_dev_filter_ctrl(l1->pmd_id,
408                 RTE_ETH_FILTER_NTUPLE,
409                 RTE_ETH_FILTER_ADD,
410                 &filter);
411 }
412
413 static inline int
414 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
415 {
416         struct rte_eth_ntuple_filter filter = {
417                 .flags = RTE_5TUPLE_FLAGS,
418                 .dst_ip = rte_bswap32(l2->ip),
419                 .dst_ip_mask = UINT32_MAX, /* Enable */
420                 .src_ip = 0,
421                 .src_ip_mask = 0, /* Disable */
422                 .dst_port = 0,
423                 .dst_port_mask = 0, /* Disable */
424                 .src_port = 0,
425                 .src_port_mask = 0, /* Disable */
426                 .proto = IPPROTO_TCP,
427                 .proto_mask = UINT8_MAX, /* Enable */
428                 .tcp_flags = 0,
429                 .priority = 2, /* Higher priority than IP */
430                 .queue = l1->tcp_local_q,
431         };
432
433         return rte_eth_dev_filter_ctrl(l1->pmd_id,
434                 RTE_ETH_FILTER_NTUPLE,
435                 RTE_ETH_FILTER_DELETE,
436                 &filter);
437 }
438
439 static inline int
440 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
441 {
442         struct rte_eth_ntuple_filter filter = {
443                 .flags = RTE_5TUPLE_FLAGS,
444                 .dst_ip = rte_bswap32(l2->ip),
445                 .dst_ip_mask = UINT32_MAX, /* Enable */
446                 .src_ip = 0,
447                 .src_ip_mask = 0, /* Disable */
448                 .dst_port = 0,
449                 .dst_port_mask = 0, /* Disable */
450                 .src_port = 0,
451                 .src_port_mask = 0, /* Disable */
452                 .proto = IPPROTO_UDP,
453                 .proto_mask = UINT8_MAX, /* Enable */
454                 .tcp_flags = 0,
455                 .priority = 2, /* Higher priority than IP */
456                 .queue = l1->udp_local_q,
457         };
458
459         return rte_eth_dev_filter_ctrl(l1->pmd_id,
460                 RTE_ETH_FILTER_NTUPLE,
461                 RTE_ETH_FILTER_ADD,
462                 &filter);
463 }
464
465 static inline int
466 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
467 {
468         struct rte_eth_ntuple_filter filter = {
469                 .flags = RTE_5TUPLE_FLAGS,
470                 .dst_ip = rte_bswap32(l2->ip),
471                 .dst_ip_mask = UINT32_MAX, /* Enable */
472                 .src_ip = 0,
473                 .src_ip_mask = 0, /* Disable */
474                 .dst_port = 0,
475                 .dst_port_mask = 0, /* Disable */
476                 .src_port = 0,
477                 .src_port_mask = 0, /* Disable */
478                 .proto = IPPROTO_UDP,
479                 .proto_mask = UINT8_MAX, /* Enable */
480                 .tcp_flags = 0,
481                 .priority = 2, /* Higher priority than IP */
482                 .queue = l1->udp_local_q,
483         };
484
485         return rte_eth_dev_filter_ctrl(l1->pmd_id,
486                 RTE_ETH_FILTER_NTUPLE,
487                 RTE_ETH_FILTER_DELETE,
488                 &filter);
489 }
490
491 static inline int
492 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
493 {
494         struct rte_eth_ntuple_filter filter = {
495                 .flags = RTE_5TUPLE_FLAGS,
496                 .dst_ip = rte_bswap32(l2->ip),
497                 .dst_ip_mask = UINT32_MAX, /* Enable */
498                 .src_ip = 0,
499                 .src_ip_mask = 0, /* Disable */
500                 .dst_port = 0,
501                 .dst_port_mask = 0, /* Disable */
502                 .src_port = 0,
503                 .src_port_mask = 0, /* Disable */
504                 .proto = IPPROTO_SCTP,
505                 .proto_mask = UINT8_MAX, /* Enable */
506                 .tcp_flags = 0,
507                 .priority = 2, /* Higher priority than IP */
508                 .queue = l1->sctp_local_q,
509         };
510
511         return rte_eth_dev_filter_ctrl(l1->pmd_id,
512                 RTE_ETH_FILTER_NTUPLE,
513                 RTE_ETH_FILTER_ADD,
514                 &filter);
515 }
516
517 static inline int
518 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
519 {
520         struct rte_eth_ntuple_filter filter = {
521                 .flags = RTE_5TUPLE_FLAGS,
522                 .dst_ip = rte_bswap32(l2->ip),
523                 .dst_ip_mask = UINT32_MAX, /* Enable */
524                 .src_ip = 0,
525                 .src_ip_mask = 0, /* Disable */
526                 .dst_port = 0,
527                 .dst_port_mask = 0, /* Disable */
528                 .src_port = 0,
529                 .src_port_mask = 0, /* Disable */
530                 .proto = IPPROTO_SCTP,
531                 .proto_mask = UINT8_MAX, /* Enable */
532                 .tcp_flags = 0,
533                 .priority = 2, /* Higher priority than IP */
534                 .queue = l1->sctp_local_q,
535         };
536
537         return rte_eth_dev_filter_ctrl(l1->pmd_id,
538                 RTE_ETH_FILTER_NTUPLE,
539                 RTE_ETH_FILTER_DELETE,
540                 &filter);
541 }
542
543 static void
544 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
545 {
546         if (cp->arp_q != 0) {
547                 int status = app_link_filter_arp_add(cp);
548
549                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
550                         "Adding ARP filter (queue = %" PRIu32 ")",
551                         cp->name, cp->pmd_id, cp->arp_q);
552
553                 if (status)
554                         rte_panic("%s (%" PRIu32 "): "
555                                 "Error adding ARP filter "
556                                 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
557                                 cp->name, cp->pmd_id, cp->arp_q, status);
558         }
559 }
560
561 static void
562 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
563 {
564         if (cp->tcp_syn_q != 0) {
565                 int status = app_link_filter_tcp_syn_add(cp);
566
567                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
568                         "Adding TCP SYN filter (queue = %" PRIu32 ")",
569                         cp->name, cp->pmd_id, cp->tcp_syn_q);
570
571                 if (status)
572                         rte_panic("%s (%" PRIu32 "): "
573                                 "Error adding TCP SYN filter "
574                                 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
575                                 cp->name, cp->pmd_id, cp->tcp_syn_q,
576                                 status);
577         }
578 }
579
580 void
581 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
582 {
583         uint32_t i;
584         int status;
585
586         /* For each link, add filters for IP of current link */
587         if (cp->ip != 0) {
588                 for (i = 0; i < app->n_links; i++) {
589                         struct app_link_params *p = &app->link_params[i];
590
591                         /* IP */
592                         if (p->ip_local_q != 0) {
593                                 int status = app_link_filter_ip_add(p, cp);
594
595                                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
596                                         "Adding IP filter (queue= %" PRIu32
597                                         ", IP = 0x%08" PRIx32 ")",
598                                         p->name, p->pmd_id, p->ip_local_q,
599                                         cp->ip);
600
601                                 if (status)
602                                         rte_panic("%s (%" PRIu32 "): "
603                                                 "Error adding IP "
604                                                 "filter (queue= %" PRIu32 ", "
605                                                 "IP = 0x%08" PRIx32
606                                                 ") (%" PRId32 ")\n",
607                                                 p->name, p->pmd_id,
608                                                 p->ip_local_q, cp->ip, status);
609                         }
610
611                         /* TCP */
612                         if (p->tcp_local_q != 0) {
613                                 int status = app_link_filter_tcp_add(p, cp);
614
615                                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
616                                         "Adding TCP filter "
617                                         "(queue = %" PRIu32
618                                         ", IP = 0x%08" PRIx32 ")",
619                                         p->name, p->pmd_id, p->tcp_local_q,
620                                         cp->ip);
621
622                                 if (status)
623                                         rte_panic("%s (%" PRIu32 "): "
624                                                 "Error adding TCP "
625                                                 "filter (queue = %" PRIu32 ", "
626                                                 "IP = 0x%08" PRIx32
627                                                 ") (%" PRId32 ")\n",
628                                                 p->name, p->pmd_id,
629                                                 p->tcp_local_q, cp->ip, status);
630                         }
631
632                         /* UDP */
633                         if (p->udp_local_q != 0) {
634                                 int status = app_link_filter_udp_add(p, cp);
635
636                                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
637                                         "Adding UDP filter "
638                                         "(queue = %" PRIu32
639                                         ", IP = 0x%08" PRIx32 ")",
640                                         p->name, p->pmd_id, p->udp_local_q,
641                                         cp->ip);
642
643                                 if (status)
644                                         rte_panic("%s (%" PRIu32 "): "
645                                                 "Error adding UDP "
646                                                 "filter (queue = %" PRIu32 ", "
647                                                 "IP = 0x%08" PRIx32
648                                                 ") (%" PRId32 ")\n",
649                                                 p->name, p->pmd_id,
650                                                 p->udp_local_q, cp->ip, status);
651                         }
652
653                         /* SCTP */
654                         if (p->sctp_local_q != 0) {
655                                 int status = app_link_filter_sctp_add(p, cp);
656
657                                 APP_LOG(app, LOW, "%s (%" PRIu32
658                                         "): Adding SCTP filter "
659                                         "(queue = %" PRIu32
660                                         ", IP = 0x%08" PRIx32 ")",
661                                         p->name, p->pmd_id, p->sctp_local_q,
662                                         cp->ip);
663
664                                 if (status)
665                                         rte_panic("%s (%" PRIu32 "): "
666                                                 "Error adding SCTP "
667                                                 "filter (queue = %" PRIu32 ", "
668                                                 "IP = 0x%08" PRIx32
669                                                 ") (%" PRId32 ")\n",
670                                                 p->name, p->pmd_id,
671                                                 p->sctp_local_q, cp->ip,
672                                                 status);
673                         }
674                 }
675         }
676
677         /* PMD link up */
678         status = rte_eth_dev_set_link_up(cp->pmd_id);
679         /* Do not panic if PMD does not provide link up functionality */
680         if (status < 0 && status != -ENOTSUP)
681                 rte_panic("%s (%" PRIu32 "): PMD set link up error %"
682                         PRId32 "\n", cp->name, cp->pmd_id, status);
683
684         /* Mark link as UP */
685         cp->state = 1;
686 }
687
688 void
689 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
690 {
691         uint32_t i;
692         int status;
693
694         /* PMD link down */
695         status = rte_eth_dev_set_link_down(cp->pmd_id);
696         /* Do not panic if PMD does not provide link down functionality */
697         if (status < 0 && status != -ENOTSUP)
698                 rte_panic("%s (%" PRIu32 "): PMD set link down error %"
699                         PRId32 "\n", cp->name, cp->pmd_id, status);
700
701         /* Mark link as DOWN */
702         cp->state = 0;
703
704         /* Return if current link IP is not valid */
705         if (cp->ip == 0)
706                 return;
707
708         /* For each link, remove filters for IP of current link */
709         for (i = 0; i < app->n_links; i++) {
710                 struct app_link_params *p = &app->link_params[i];
711
712                 /* IP */
713                 if (p->ip_local_q != 0) {
714                         int status = app_link_filter_ip_del(p, cp);
715
716                         APP_LOG(app, LOW, "%s (%" PRIu32
717                                 "): Deleting IP filter "
718                                 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
719                                 p->name, p->pmd_id, p->ip_local_q, cp->ip);
720
721                         if (status)
722                                 rte_panic("%s (%" PRIu32
723                                         "): Error deleting IP filter "
724                                         "(queue = %" PRIu32
725                                         ", IP = 0x%" PRIx32
726                                         ") (%" PRId32 ")\n",
727                                         p->name, p->pmd_id, p->ip_local_q,
728                                         cp->ip, status);
729                 }
730
731                 /* TCP */
732                 if (p->tcp_local_q != 0) {
733                         int status = app_link_filter_tcp_del(p, cp);
734
735                         APP_LOG(app, LOW, "%s (%" PRIu32
736                                 "): Deleting TCP filter "
737                                 "(queue = %" PRIu32
738                                 ", IP = 0x%" PRIx32 ")",
739                                 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
740
741                         if (status)
742                                 rte_panic("%s (%" PRIu32
743                                         "): Error deleting TCP filter "
744                                         "(queue = %" PRIu32
745                                         ", IP = 0x%" PRIx32
746                                         ") (%" PRId32 ")\n",
747                                         p->name, p->pmd_id, p->tcp_local_q,
748                                         cp->ip, status);
749                 }
750
751                 /* UDP */
752                 if (p->udp_local_q != 0) {
753                         int status = app_link_filter_udp_del(p, cp);
754
755                         APP_LOG(app, LOW, "%s (%" PRIu32
756                                 "): Deleting UDP filter "
757                                 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
758                                 p->name, p->pmd_id, p->udp_local_q, cp->ip);
759
760                         if (status)
761                                 rte_panic("%s (%" PRIu32
762                                         "): Error deleting UDP filter "
763                                         "(queue = %" PRIu32
764                                         ", IP = 0x%" PRIx32
765                                         ") (%" PRId32 ")\n",
766                                         p->name, p->pmd_id, p->udp_local_q,
767                                         cp->ip, status);
768                 }
769
770                 /* SCTP */
771                 if (p->sctp_local_q != 0) {
772                         int status = app_link_filter_sctp_del(p, cp);
773
774                         APP_LOG(app, LOW, "%s (%" PRIu32
775                                 "): Deleting SCTP filter "
776                                 "(queue = %" PRIu32
777                                 ", IP = 0x%" PRIx32 ")",
778                                 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
779
780                         if (status)
781                                 rte_panic("%s (%" PRIu32
782                                         "): Error deleting SCTP filter "
783                                         "(queue = %" PRIu32
784                                         ", IP = 0x%" PRIx32
785                                         ") (%" PRId32 ")\n",
786                                         p->name, p->pmd_id, p->sctp_local_q,
787                                         cp->ip, status);
788                 }
789         }
790 }
791
792 static void
793 app_check_link(struct app_params *app)
794 {
795         uint32_t all_links_up, i;
796
797         all_links_up = 1;
798
799         for (i = 0; i < app->n_links; i++) {
800                 struct app_link_params *p = &app->link_params[i];
801                 struct rte_eth_link link_params;
802
803                 memset(&link_params, 0, sizeof(link_params));
804                 rte_eth_link_get(p->pmd_id, &link_params);
805
806                 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
807                         p->name,
808                         p->pmd_id,
809                         link_params.link_speed / 1000,
810                         link_params.link_status ? "UP" : "DOWN");
811
812                 if (link_params.link_status == ETH_LINK_DOWN)
813                         all_links_up = 0;
814         }
815
816         if (all_links_up == 0)
817                 rte_panic("Some links are DOWN\n");
818 }
819
820 static uint32_t
821 is_any_swq_frag_or_ras(struct app_params *app)
822 {
823         uint32_t i;
824
825         for (i = 0; i < app->n_pktq_swq; i++) {
826                 struct app_pktq_swq_params *p = &app->swq_params[i];
827
828                 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
829                         (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
830                         return 1;
831         }
832
833         return 0;
834 }
835
836 static void
837 app_init_link_frag_ras(struct app_params *app)
838 {
839         uint32_t i;
840
841         if (is_any_swq_frag_or_ras(app)) {
842                 for (i = 0; i < app->n_links; i++) {
843                         struct app_link_params *p_link = &app->link_params[i];
844                                 p_link->conf.txmode.offloads |=
845                                                 DEV_TX_OFFLOAD_MULTI_SEGS;
846                 }
847         }
848 }
849
850 static inline int
851 app_get_cpu_socket_id(uint32_t pmd_id)
852 {
853         int status = rte_eth_dev_socket_id(pmd_id);
854
855         return (status != SOCKET_ID_ANY) ? status : 0;
856 }
857
858 static inline int
859 app_link_rss_enabled(struct app_link_params *cp)
860 {
861         return (cp->n_rss_qs) ? 1 : 0;
862 }
863
864 static void
865 app_link_rss_setup(struct app_link_params *cp)
866 {
867         struct rte_eth_dev_info dev_info;
868         struct rte_eth_rss_reta_entry64 reta_conf[APP_RETA_SIZE_MAX];
869         uint32_t i;
870         int status;
871
872     /* Get RETA size */
873         memset(&dev_info, 0, sizeof(dev_info));
874         rte_eth_dev_info_get(cp->pmd_id, &dev_info);
875
876         if (dev_info.reta_size == 0)
877                 rte_panic("%s (%u): RSS setup error (null RETA size)\n",
878                         cp->name, cp->pmd_id);
879
880         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512)
881                 rte_panic("%s (%u): RSS setup error (RETA size too big)\n",
882                         cp->name, cp->pmd_id);
883
884         /* Setup RETA contents */
885         memset(reta_conf, 0, sizeof(reta_conf));
886
887         for (i = 0; i < dev_info.reta_size; i++)
888                 reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX;
889
890         for (i = 0; i < dev_info.reta_size; i++) {
891                 uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
892                 uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
893                 uint32_t rss_qs_pos = i % cp->n_rss_qs;
894
895                 reta_conf[reta_id].reta[reta_pos] =
896                         (uint16_t) cp->rss_qs[rss_qs_pos];
897         }
898
899         /* RETA update */
900         status = rte_eth_dev_rss_reta_update(cp->pmd_id,
901                 reta_conf,
902                 dev_info.reta_size);
903         if (status != 0)
904                 rte_panic("%s (%u): RSS setup error (RETA update failed)\n",
905                         cp->name, cp->pmd_id);
906 }
907
908 static void
909 app_init_link_set_config(struct app_link_params *p)
910 {
911         if (p->n_rss_qs) {
912                 p->conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
913                 p->conf.rx_adv_conf.rss_conf.rss_hf = p->rss_proto_ipv4 |
914                         p->rss_proto_ipv6 |
915                         p->rss_proto_l2;
916         }
917 }
918
919 static void
920 app_init_link(struct app_params *app)
921 {
922         uint32_t i;
923
924         app_init_link_frag_ras(app);
925
926         for (i = 0; i < app->n_links; i++) {
927                 struct app_link_params *p_link = &app->link_params[i];
928                 struct rte_eth_dev_info dev_info;
929                 uint32_t link_id, n_hwq_in, n_hwq_out, j;
930                 int status;
931
932                 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
933                 n_hwq_in = app_link_get_n_rxq(app, p_link);
934                 n_hwq_out = app_link_get_n_txq(app, p_link);
935                 app_init_link_set_config(p_link);
936
937                 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
938                         "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
939                         p_link->name,
940                         p_link->pmd_id,
941                         n_hwq_in,
942                         n_hwq_out);
943
944                 /* LINK */
945                 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
946                 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
947                         p_link->conf.txmode.offloads |=
948                                 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
949                 status = rte_eth_dev_configure(
950                         p_link->pmd_id,
951                         n_hwq_in,
952                         n_hwq_out,
953                         &p_link->conf);
954                 if (status < 0)
955                         rte_panic("%s (%" PRId32 "): "
956                                 "init error (%" PRId32 ")\n",
957                                 p_link->name, p_link->pmd_id, status);
958
959                 rte_eth_macaddr_get(p_link->pmd_id,
960                         (struct ether_addr *) &p_link->mac_addr);
961
962                 if (p_link->promisc)
963                         rte_eth_promiscuous_enable(p_link->pmd_id);
964
965                 /* RXQ */
966                 for (j = 0; j < app->n_pktq_hwq_in; j++) {
967                         struct app_pktq_hwq_in_params *p_rxq =
968                                 &app->hwq_in_params[j];
969                         uint32_t rxq_link_id, rxq_queue_id;
970                         uint16_t nb_rxd = p_rxq->size;
971
972                         sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
973                                 &rxq_link_id, &rxq_queue_id);
974                         if (rxq_link_id != link_id)
975                                 continue;
976
977                         status = rte_eth_dev_adjust_nb_rx_tx_desc(
978                                 p_link->pmd_id,
979                                 &nb_rxd,
980                                 NULL);
981                         if (status < 0)
982                                 rte_panic("%s (%" PRIu32 "): "
983                                         "%s adjust number of Rx descriptors "
984                                         "error (%" PRId32 ")\n",
985                                         p_link->name,
986                                         p_link->pmd_id,
987                                         p_rxq->name,
988                                         status);
989
990                         p_rxq->conf.offloads = p_link->conf.rxmode.offloads;
991                         status = rte_eth_rx_queue_setup(
992                                 p_link->pmd_id,
993                                 rxq_queue_id,
994                                 nb_rxd,
995                                 app_get_cpu_socket_id(p_link->pmd_id),
996                                 &p_rxq->conf,
997                                 app->mempool[p_rxq->mempool_id]);
998                         if (status < 0)
999                                 rte_panic("%s (%" PRIu32 "): "
1000                                         "%s init error (%" PRId32 ")\n",
1001                                         p_link->name,
1002                                         p_link->pmd_id,
1003                                         p_rxq->name,
1004                                         status);
1005                 }
1006
1007                 /* TXQ */
1008                 for (j = 0; j < app->n_pktq_hwq_out; j++) {
1009                         struct app_pktq_hwq_out_params *p_txq =
1010                                 &app->hwq_out_params[j];
1011                         uint32_t txq_link_id, txq_queue_id;
1012                         uint16_t nb_txd = p_txq->size;
1013
1014                         sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
1015                                 &txq_link_id, &txq_queue_id);
1016                         if (txq_link_id != link_id)
1017                                 continue;
1018
1019                         status = rte_eth_dev_adjust_nb_rx_tx_desc(
1020                                 p_link->pmd_id,
1021                                 NULL,
1022                                 &nb_txd);
1023                         if (status < 0)
1024                                 rte_panic("%s (%" PRIu32 "): "
1025                                         "%s adjust number of Tx descriptors "
1026                                         "error (%" PRId32 ")\n",
1027                                         p_link->name,
1028                                         p_link->pmd_id,
1029                                         p_txq->name,
1030                                         status);
1031
1032                         p_txq->conf.offloads = p_link->conf.txmode.offloads;
1033                         status = rte_eth_tx_queue_setup(
1034                                 p_link->pmd_id,
1035                                 txq_queue_id,
1036                                 nb_txd,
1037                                 app_get_cpu_socket_id(p_link->pmd_id),
1038                                 &p_txq->conf);
1039                         if (status < 0)
1040                                 rte_panic("%s (%" PRIu32 "): "
1041                                         "%s init error (%" PRId32 ")\n",
1042                                         p_link->name,
1043                                         p_link->pmd_id,
1044                                         p_txq->name,
1045                                         status);
1046                 }
1047
1048                 /* LINK START */
1049                 status = rte_eth_dev_start(p_link->pmd_id);
1050                 if (status < 0)
1051                         rte_panic("Cannot start %s (error %" PRId32 ")\n",
1052                                 p_link->name, status);
1053
1054                 /* LINK FILTERS */
1055                 app_link_set_arp_filter(app, p_link);
1056                 app_link_set_tcp_syn_filter(app, p_link);
1057                 if (app_link_rss_enabled(p_link))
1058                         app_link_rss_setup(p_link);
1059
1060                 /* LINK UP */
1061                 app_link_up_internal(app, p_link);
1062         }
1063
1064         app_check_link(app);
1065 }
1066
1067 static void
1068 app_init_swq(struct app_params *app)
1069 {
1070         uint32_t i;
1071
1072         for (i = 0; i < app->n_pktq_swq; i++) {
1073                 struct app_pktq_swq_params *p = &app->swq_params[i];
1074                 unsigned flags = 0;
1075
1076                 if (app_swq_get_readers(app, p) == 1)
1077                         flags |= RING_F_SC_DEQ;
1078                 if (app_swq_get_writers(app, p) == 1)
1079                         flags |= RING_F_SP_ENQ;
1080
1081                 APP_LOG(app, HIGH, "Initializing %s...", p->name);
1082                 app->swq[i] = rte_ring_create(
1083                                 p->name,
1084                                 p->size,
1085                                 p->cpu_socket_id,
1086                                 flags);
1087
1088                 if (app->swq[i] == NULL)
1089                         rte_panic("%s init error\n", p->name);
1090         }
1091 }
1092
1093 static void
1094 app_init_tm(struct app_params *app)
1095 {
1096         uint32_t i;
1097
1098         for (i = 0; i < app->n_pktq_tm; i++) {
1099                 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
1100                 struct app_link_params *p_link;
1101                 struct rte_eth_link link_eth_params;
1102                 struct rte_sched_port *sched;
1103                 uint32_t n_subports, subport_id;
1104                 int status;
1105
1106                 p_link = app_get_link_for_tm(app, p_tm);
1107                 /* LINK */
1108                 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
1109
1110                 /* TM */
1111                 p_tm->sched_port_params.name = p_tm->name;
1112                 p_tm->sched_port_params.socket =
1113                         app_get_cpu_socket_id(p_link->pmd_id);
1114                 p_tm->sched_port_params.rate =
1115                         (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
1116
1117                 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
1118                 sched = rte_sched_port_config(&p_tm->sched_port_params);
1119                 if (sched == NULL)
1120                         rte_panic("%s init error\n", p_tm->name);
1121                 app->tm[i] = sched;
1122
1123                 /* Subport */
1124                 n_subports = p_tm->sched_port_params.n_subports_per_port;
1125                 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1126                         uint32_t n_pipes_per_subport, pipe_id;
1127
1128                         status = rte_sched_subport_config(sched,
1129                                 subport_id,
1130                                 &p_tm->sched_subport_params[subport_id]);
1131                         if (status)
1132                                 rte_panic("%s subport %" PRIu32
1133                                         " init error (%" PRId32 ")\n",
1134                                         p_tm->name, subport_id, status);
1135
1136                         /* Pipe */
1137                         n_pipes_per_subport =
1138                                 p_tm->sched_port_params.n_pipes_per_subport;
1139                         for (pipe_id = 0;
1140                                 pipe_id < n_pipes_per_subport;
1141                                 pipe_id++) {
1142                                 int profile_id = p_tm->sched_pipe_to_profile[
1143                                         subport_id * APP_MAX_SCHED_PIPES +
1144                                         pipe_id];
1145
1146                                 if (profile_id == -1)
1147                                         continue;
1148
1149                                 status = rte_sched_pipe_config(sched,
1150                                         subport_id,
1151                                         pipe_id,
1152                                         profile_id);
1153                                 if (status)
1154                                         rte_panic("%s subport %" PRIu32
1155                                                 " pipe %" PRIu32
1156                                                 " (profile %" PRId32 ") "
1157                                                 "init error (% " PRId32 ")\n",
1158                                                 p_tm->name, subport_id, pipe_id,
1159                                                 profile_id, status);
1160                         }
1161                 }
1162         }
1163 }
1164
1165 #ifndef RTE_EXEC_ENV_LINUXAPP
1166 static void
1167 app_init_tap(struct app_params *app) {
1168         if (app->n_pktq_tap == 0)
1169                 return;
1170
1171         rte_panic("TAP device not supported.\n");
1172 }
1173 #else
1174 static void
1175 app_init_tap(struct app_params *app)
1176 {
1177         uint32_t i;
1178
1179         for (i = 0; i < app->n_pktq_tap; i++) {
1180                 struct app_pktq_tap_params *p_tap = &app->tap_params[i];
1181                 struct ifreq ifr;
1182                 int fd, status;
1183
1184                 APP_LOG(app, HIGH, "Initializing %s ...", p_tap->name);
1185
1186                 fd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
1187                 if (fd < 0)
1188                         rte_panic("Cannot open file /dev/net/tun\n");
1189
1190                 memset(&ifr, 0, sizeof(ifr));
1191                 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
1192                 snprintf(ifr.ifr_name, IFNAMSIZ, "%s", p_tap->name);
1193
1194                 status = ioctl(fd, TUNSETIFF, (void *) &ifr);
1195                 if (status < 0)
1196                         rte_panic("TAP setup error\n");
1197
1198                 app->tap[i] = fd;
1199         }
1200 }
1201 #endif
1202
1203 #ifdef RTE_LIBRTE_KNI
1204 static int
1205 kni_config_network_interface(uint16_t port_id, uint8_t if_up) {
1206         int ret = 0;
1207
1208         if (port_id >= rte_eth_dev_count())
1209                 return -EINVAL;
1210
1211         ret = (if_up) ?
1212                 rte_eth_dev_set_link_up(port_id) :
1213                 rte_eth_dev_set_link_down(port_id);
1214
1215         return ret;
1216 }
1217
1218 static int
1219 kni_change_mtu(uint16_t port_id, unsigned int new_mtu) {
1220         int ret;
1221
1222         if (port_id >= rte_eth_dev_count())
1223                 return -EINVAL;
1224
1225         if (new_mtu > ETHER_MAX_LEN)
1226                 return -EINVAL;
1227
1228         /* Set new MTU */
1229         ret = rte_eth_dev_set_mtu(port_id, new_mtu);
1230         if (ret < 0)
1231                 return ret;
1232
1233         return 0;
1234 }
1235 #endif /* RTE_LIBRTE_KNI */
1236
1237 #ifndef RTE_LIBRTE_KNI
1238 static void
1239 app_init_kni(struct app_params *app) {
1240         if (app->n_pktq_kni == 0)
1241                 return;
1242
1243         rte_panic("Can not init KNI without librte_kni support.\n");
1244 }
1245 #else
1246 static void
1247 app_init_kni(struct app_params *app) {
1248         uint32_t i;
1249
1250         if (app->n_pktq_kni == 0)
1251                 return;
1252
1253         rte_kni_init(app->n_pktq_kni);
1254
1255         for (i = 0; i < app->n_pktq_kni; i++) {
1256                 struct app_pktq_kni_params *p_kni = &app->kni_params[i];
1257                 struct app_link_params *p_link;
1258                 struct rte_eth_dev_info dev_info;
1259                 struct app_mempool_params *mempool_params;
1260                 struct rte_mempool *mempool;
1261                 struct rte_kni_conf conf;
1262                 struct rte_kni_ops ops;
1263
1264                 /* LINK */
1265                 p_link = app_get_link_for_kni(app, p_kni);
1266                 memset(&dev_info, 0, sizeof(dev_info));
1267                 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
1268
1269                 /* MEMPOOL */
1270                 mempool_params = &app->mempool_params[p_kni->mempool_id];
1271                 mempool = app->mempool[p_kni->mempool_id];
1272
1273                 /* KNI */
1274                 memset(&conf, 0, sizeof(conf));
1275                 snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", p_kni->name);
1276                 conf.force_bind = p_kni->force_bind;
1277                 if (conf.force_bind) {
1278                         int lcore_id;
1279
1280                         lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1281                                 p_kni->socket_id,
1282                                 p_kni->core_id,
1283                                 p_kni->hyper_th_id);
1284
1285                         if (lcore_id < 0)
1286                                 rte_panic("%s invalid CPU core\n", p_kni->name);
1287
1288                         conf.core_id = (uint32_t) lcore_id;
1289                 }
1290                 conf.group_id = p_link->pmd_id;
1291                 conf.mbuf_size = mempool_params->buffer_size;
1292                 conf.addr = dev_info.pci_dev->addr;
1293                 conf.id = dev_info.pci_dev->id;
1294
1295                 memset(&ops, 0, sizeof(ops));
1296                 ops.port_id = (uint8_t) p_link->pmd_id;
1297                 ops.change_mtu = kni_change_mtu;
1298                 ops.config_network_if = kni_config_network_interface;
1299
1300                 APP_LOG(app, HIGH, "Initializing %s ...", p_kni->name);
1301                 app->kni[i] = rte_kni_alloc(mempool, &conf, &ops);
1302                 if (!app->kni[i])
1303                         rte_panic("%s init error\n", p_kni->name);
1304         }
1305 }
1306 #endif /* RTE_LIBRTE_KNI */
1307
1308 static void
1309 app_init_msgq(struct app_params *app)
1310 {
1311         uint32_t i;
1312
1313         for (i = 0; i < app->n_msgq; i++) {
1314                 struct app_msgq_params *p = &app->msgq_params[i];
1315
1316                 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1317                 app->msgq[i] = rte_ring_create(
1318                                 p->name,
1319                                 p->size,
1320                                 p->cpu_socket_id,
1321                                 RING_F_SP_ENQ | RING_F_SC_DEQ);
1322
1323                 if (app->msgq[i] == NULL)
1324                         rte_panic("%s init error\n", p->name);
1325         }
1326 }
1327
1328 int app_init(struct app_params *app)
1329 {
1330         app_init_core_map(app);
1331         app_init_core_mask(app);
1332
1333         app_init_eal(app);
1334         app_init_mempool(app);
1335         app_init_link(app);
1336         app_init_swq(app);
1337         app_init_tm(app);
1338         app_init_tap(app);
1339         app_init_kni(app);
1340         app_init_msgq(app);
1341
1342         return 0;
1343 }