Imported Upstream version 16.11
[deb_dpdk.git] / examples / ip_pipeline / init.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <inttypes.h>
35 #include <stdio.h>
36 #include <string.h>
37 #include <netinet/in.h>
38 #ifdef RTE_EXEC_ENV_LINUXAPP
39 #include <linux/if.h>
40 #include <linux/if_tun.h>
41 #endif
42 #include <fcntl.h>
43 #include <sys/ioctl.h>
44 #include <unistd.h>
45
46 #include <rte_cycles.h>
47 #include <rte_ethdev.h>
48 #include <rte_ether.h>
49 #include <rte_ip.h>
50 #include <rte_eal.h>
51 #include <rte_malloc.h>
52
53 #include "app.h"
54 #include "pipeline.h"
55 #include "pipeline_common_fe.h"
56 #include "pipeline_master.h"
57 #include "pipeline_passthrough.h"
58 #include "pipeline_firewall.h"
59 #include "pipeline_flow_classification.h"
60 #include "pipeline_flow_actions.h"
61 #include "pipeline_routing.h"
62 #include "thread_fe.h"
63
64 #define APP_NAME_SIZE   32
65
66 #define APP_RETA_SIZE_MAX     (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE)
67
68 static void
69 app_init_core_map(struct app_params *app)
70 {
71         APP_LOG(app, HIGH, "Initializing CPU core map ...");
72         app->core_map = cpu_core_map_init(4, 32, 4, 0);
73
74         if (app->core_map == NULL)
75                 rte_panic("Cannot create CPU core map\n");
76
77         if (app->log_level >= APP_LOG_LEVEL_LOW)
78                 cpu_core_map_print(app->core_map);
79 }
80
81 static void
82 app_init_core_mask(struct app_params *app)
83 {
84         uint64_t mask = 0;
85         uint32_t i;
86
87         for (i = 0; i < app->n_pipelines; i++) {
88                 struct app_pipeline_params *p = &app->pipeline_params[i];
89                 int lcore_id;
90
91                 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
92                         p->socket_id,
93                         p->core_id,
94                         p->hyper_th_id);
95
96                 if (lcore_id < 0)
97                         rte_panic("Cannot create CPU core mask\n");
98
99                 mask |= 1LLU << lcore_id;
100         }
101
102         app->core_mask = mask;
103         APP_LOG(app, HIGH, "CPU core mask = 0x%016" PRIx64, app->core_mask);
104 }
105
106 static void
107 app_init_eal(struct app_params *app)
108 {
109         char buffer[256];
110         struct app_eal_params *p = &app->eal_params;
111         uint32_t n_args = 0;
112         uint32_t i;
113         int status;
114
115         app->eal_argv[n_args++] = strdup(app->app_name);
116
117         snprintf(buffer, sizeof(buffer), "-c%" PRIx64, app->core_mask);
118         app->eal_argv[n_args++] = strdup(buffer);
119
120         if (p->coremap) {
121                 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
122                 app->eal_argv[n_args++] = strdup(buffer);
123         }
124
125         if (p->master_lcore_present) {
126                 snprintf(buffer,
127                         sizeof(buffer),
128                         "--master-lcore=%" PRIu32,
129                         p->master_lcore);
130                 app->eal_argv[n_args++] = strdup(buffer);
131         }
132
133         snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
134         app->eal_argv[n_args++] = strdup(buffer);
135
136         if (p->memory_present) {
137                 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
138                 app->eal_argv[n_args++] = strdup(buffer);
139         }
140
141         if (p->ranks_present) {
142                 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
143                 app->eal_argv[n_args++] = strdup(buffer);
144         }
145
146         for (i = 0; i < APP_MAX_LINKS; i++) {
147                 if (p->pci_blacklist[i] == NULL)
148                         break;
149
150                 snprintf(buffer,
151                         sizeof(buffer),
152                         "--pci-blacklist=%s",
153                         p->pci_blacklist[i]);
154                 app->eal_argv[n_args++] = strdup(buffer);
155         }
156
157         if (app->port_mask != 0)
158                 for (i = 0; i < APP_MAX_LINKS; i++) {
159                         if (p->pci_whitelist[i] == NULL)
160                                 break;
161
162                         snprintf(buffer,
163                                 sizeof(buffer),
164                                 "--pci-whitelist=%s",
165                                 p->pci_whitelist[i]);
166                         app->eal_argv[n_args++] = strdup(buffer);
167                 }
168         else
169                 for (i = 0; i < app->n_links; i++) {
170                         char *pci_bdf = app->link_params[i].pci_bdf;
171
172                         snprintf(buffer,
173                                 sizeof(buffer),
174                                 "--pci-whitelist=%s",
175                                 pci_bdf);
176                         app->eal_argv[n_args++] = strdup(buffer);
177                 }
178
179         for (i = 0; i < APP_MAX_LINKS; i++) {
180                 if (p->vdev[i] == NULL)
181                         break;
182
183                 snprintf(buffer,
184                         sizeof(buffer),
185                         "--vdev=%s",
186                         p->vdev[i]);
187                 app->eal_argv[n_args++] = strdup(buffer);
188         }
189
190         if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
191                 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
192                 app->eal_argv[n_args++] = strdup(buffer);
193         }
194
195         if (p->proc_type) {
196                 snprintf(buffer,
197                         sizeof(buffer),
198                         "--proc-type=%s",
199                         p->proc_type);
200                 app->eal_argv[n_args++] = strdup(buffer);
201         }
202
203         if (p->syslog) {
204                 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
205                 app->eal_argv[n_args++] = strdup(buffer);
206         }
207
208         if (p->log_level_present) {
209                 snprintf(buffer,
210                         sizeof(buffer),
211                         "--log-level=%" PRIu32,
212                         p->log_level);
213                 app->eal_argv[n_args++] = strdup(buffer);
214         }
215
216         if ((p->version_present) && p->version) {
217                 snprintf(buffer, sizeof(buffer), "-v");
218                 app->eal_argv[n_args++] = strdup(buffer);
219         }
220
221         if ((p->help_present) && p->help) {
222                 snprintf(buffer, sizeof(buffer), "--help");
223                 app->eal_argv[n_args++] = strdup(buffer);
224         }
225
226         if ((p->no_huge_present) && p->no_huge) {
227                 snprintf(buffer, sizeof(buffer), "--no-huge");
228                 app->eal_argv[n_args++] = strdup(buffer);
229         }
230
231         if ((p->no_pci_present) && p->no_pci) {
232                 snprintf(buffer, sizeof(buffer), "--no-pci");
233                 app->eal_argv[n_args++] = strdup(buffer);
234         }
235
236         if ((p->no_hpet_present) && p->no_hpet) {
237                 snprintf(buffer, sizeof(buffer), "--no-hpet");
238                 app->eal_argv[n_args++] = strdup(buffer);
239         }
240
241         if ((p->no_shconf_present) && p->no_shconf) {
242                 snprintf(buffer, sizeof(buffer), "--no-shconf");
243                 app->eal_argv[n_args++] = strdup(buffer);
244         }
245
246         if (p->add_driver) {
247                 snprintf(buffer, sizeof(buffer), "-d%s", p->add_driver);
248                 app->eal_argv[n_args++] = strdup(buffer);
249         }
250
251         if (p->socket_mem) {
252                 snprintf(buffer,
253                         sizeof(buffer),
254                         "--socket-mem=%s",
255                         p->socket_mem);
256                 app->eal_argv[n_args++] = strdup(buffer);
257         }
258
259         if (p->huge_dir) {
260                 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
261                 app->eal_argv[n_args++] = strdup(buffer);
262         }
263
264         if (p->file_prefix) {
265                 snprintf(buffer,
266                         sizeof(buffer),
267                         "--file-prefix=%s",
268                         p->file_prefix);
269                 app->eal_argv[n_args++] = strdup(buffer);
270         }
271
272         if (p->base_virtaddr) {
273                 snprintf(buffer,
274                         sizeof(buffer),
275                         "--base-virtaddr=%s",
276                         p->base_virtaddr);
277                 app->eal_argv[n_args++] = strdup(buffer);
278         }
279
280         if ((p->create_uio_dev_present) && p->create_uio_dev) {
281                 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
282                 app->eal_argv[n_args++] = strdup(buffer);
283         }
284
285         if (p->vfio_intr) {
286                 snprintf(buffer,
287                         sizeof(buffer),
288                         "--vfio-intr=%s",
289                         p->vfio_intr);
290                 app->eal_argv[n_args++] = strdup(buffer);
291         }
292
293         if ((p->xen_dom0_present) && (p->xen_dom0)) {
294                 snprintf(buffer, sizeof(buffer), "--xen-dom0");
295                 app->eal_argv[n_args++] = strdup(buffer);
296         }
297
298         snprintf(buffer, sizeof(buffer), "--");
299         app->eal_argv[n_args++] = strdup(buffer);
300
301         app->eal_argc = n_args;
302
303         APP_LOG(app, HIGH, "Initializing EAL ...");
304         if (app->log_level >= APP_LOG_LEVEL_LOW) {
305                 int i;
306
307                 fprintf(stdout, "[APP] EAL arguments: \"");
308                 for (i = 1; i < app->eal_argc; i++)
309                         fprintf(stdout, "%s ", app->eal_argv[i]);
310                 fprintf(stdout, "\"\n");
311         }
312
313         status = rte_eal_init(app->eal_argc, app->eal_argv);
314         if (status < 0)
315                 rte_panic("EAL init error\n");
316 }
317
318 static void
319 app_init_mempool(struct app_params *app)
320 {
321         uint32_t i;
322
323         for (i = 0; i < app->n_mempools; i++) {
324                 struct app_mempool_params *p = &app->mempool_params[i];
325
326                 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
327                 app->mempool[i] = rte_mempool_create(
328                                 p->name,
329                                 p->pool_size,
330                                 p->buffer_size,
331                                 p->cache_size,
332                                 sizeof(struct rte_pktmbuf_pool_private),
333                                 rte_pktmbuf_pool_init, NULL,
334                                 rte_pktmbuf_init, NULL,
335                                 p->cpu_socket_id,
336                                 0);
337
338                 if (app->mempool[i] == NULL)
339                         rte_panic("%s init error\n", p->name);
340         }
341 }
342
343 static inline int
344 app_link_filter_arp_add(struct app_link_params *link)
345 {
346         struct rte_eth_ethertype_filter filter = {
347                 .ether_type = ETHER_TYPE_ARP,
348                 .flags = 0,
349                 .queue = link->arp_q,
350         };
351
352         return rte_eth_dev_filter_ctrl(link->pmd_id,
353                 RTE_ETH_FILTER_ETHERTYPE,
354                 RTE_ETH_FILTER_ADD,
355                 &filter);
356 }
357
358 static inline int
359 app_link_filter_tcp_syn_add(struct app_link_params *link)
360 {
361         struct rte_eth_syn_filter filter = {
362                 .hig_pri = 1,
363                 .queue = link->tcp_syn_q,
364         };
365
366         return rte_eth_dev_filter_ctrl(link->pmd_id,
367                 RTE_ETH_FILTER_SYN,
368                 RTE_ETH_FILTER_ADD,
369                 &filter);
370 }
371
372 static inline int
373 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
374 {
375         struct rte_eth_ntuple_filter filter = {
376                 .flags = RTE_5TUPLE_FLAGS,
377                 .dst_ip = rte_bswap32(l2->ip),
378                 .dst_ip_mask = UINT32_MAX, /* Enable */
379                 .src_ip = 0,
380                 .src_ip_mask = 0, /* Disable */
381                 .dst_port = 0,
382                 .dst_port_mask = 0, /* Disable */
383                 .src_port = 0,
384                 .src_port_mask = 0, /* Disable */
385                 .proto = 0,
386                 .proto_mask = 0, /* Disable */
387                 .tcp_flags = 0,
388                 .priority = 1, /* Lowest */
389                 .queue = l1->ip_local_q,
390         };
391
392         return rte_eth_dev_filter_ctrl(l1->pmd_id,
393                 RTE_ETH_FILTER_NTUPLE,
394                 RTE_ETH_FILTER_ADD,
395                 &filter);
396 }
397
398 static inline int
399 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
400 {
401         struct rte_eth_ntuple_filter filter = {
402                 .flags = RTE_5TUPLE_FLAGS,
403                 .dst_ip = rte_bswap32(l2->ip),
404                 .dst_ip_mask = UINT32_MAX, /* Enable */
405                 .src_ip = 0,
406                 .src_ip_mask = 0, /* Disable */
407                 .dst_port = 0,
408                 .dst_port_mask = 0, /* Disable */
409                 .src_port = 0,
410                 .src_port_mask = 0, /* Disable */
411                 .proto = 0,
412                 .proto_mask = 0, /* Disable */
413                 .tcp_flags = 0,
414                 .priority = 1, /* Lowest */
415                 .queue = l1->ip_local_q,
416         };
417
418         return rte_eth_dev_filter_ctrl(l1->pmd_id,
419                 RTE_ETH_FILTER_NTUPLE,
420                 RTE_ETH_FILTER_DELETE,
421                 &filter);
422 }
423
424 static inline int
425 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
426 {
427         struct rte_eth_ntuple_filter filter = {
428                 .flags = RTE_5TUPLE_FLAGS,
429                 .dst_ip = rte_bswap32(l2->ip),
430                 .dst_ip_mask = UINT32_MAX, /* Enable */
431                 .src_ip = 0,
432                 .src_ip_mask = 0, /* Disable */
433                 .dst_port = 0,
434                 .dst_port_mask = 0, /* Disable */
435                 .src_port = 0,
436                 .src_port_mask = 0, /* Disable */
437                 .proto = IPPROTO_TCP,
438                 .proto_mask = UINT8_MAX, /* Enable */
439                 .tcp_flags = 0,
440                 .priority = 2, /* Higher priority than IP */
441                 .queue = l1->tcp_local_q,
442         };
443
444         return rte_eth_dev_filter_ctrl(l1->pmd_id,
445                 RTE_ETH_FILTER_NTUPLE,
446                 RTE_ETH_FILTER_ADD,
447                 &filter);
448 }
449
450 static inline int
451 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
452 {
453         struct rte_eth_ntuple_filter filter = {
454                 .flags = RTE_5TUPLE_FLAGS,
455                 .dst_ip = rte_bswap32(l2->ip),
456                 .dst_ip_mask = UINT32_MAX, /* Enable */
457                 .src_ip = 0,
458                 .src_ip_mask = 0, /* Disable */
459                 .dst_port = 0,
460                 .dst_port_mask = 0, /* Disable */
461                 .src_port = 0,
462                 .src_port_mask = 0, /* Disable */
463                 .proto = IPPROTO_TCP,
464                 .proto_mask = UINT8_MAX, /* Enable */
465                 .tcp_flags = 0,
466                 .priority = 2, /* Higher priority than IP */
467                 .queue = l1->tcp_local_q,
468         };
469
470         return rte_eth_dev_filter_ctrl(l1->pmd_id,
471                 RTE_ETH_FILTER_NTUPLE,
472                 RTE_ETH_FILTER_DELETE,
473                 &filter);
474 }
475
476 static inline int
477 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
478 {
479         struct rte_eth_ntuple_filter filter = {
480                 .flags = RTE_5TUPLE_FLAGS,
481                 .dst_ip = rte_bswap32(l2->ip),
482                 .dst_ip_mask = UINT32_MAX, /* Enable */
483                 .src_ip = 0,
484                 .src_ip_mask = 0, /* Disable */
485                 .dst_port = 0,
486                 .dst_port_mask = 0, /* Disable */
487                 .src_port = 0,
488                 .src_port_mask = 0, /* Disable */
489                 .proto = IPPROTO_UDP,
490                 .proto_mask = UINT8_MAX, /* Enable */
491                 .tcp_flags = 0,
492                 .priority = 2, /* Higher priority than IP */
493                 .queue = l1->udp_local_q,
494         };
495
496         return rte_eth_dev_filter_ctrl(l1->pmd_id,
497                 RTE_ETH_FILTER_NTUPLE,
498                 RTE_ETH_FILTER_ADD,
499                 &filter);
500 }
501
502 static inline int
503 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
504 {
505         struct rte_eth_ntuple_filter filter = {
506                 .flags = RTE_5TUPLE_FLAGS,
507                 .dst_ip = rte_bswap32(l2->ip),
508                 .dst_ip_mask = UINT32_MAX, /* Enable */
509                 .src_ip = 0,
510                 .src_ip_mask = 0, /* Disable */
511                 .dst_port = 0,
512                 .dst_port_mask = 0, /* Disable */
513                 .src_port = 0,
514                 .src_port_mask = 0, /* Disable */
515                 .proto = IPPROTO_UDP,
516                 .proto_mask = UINT8_MAX, /* Enable */
517                 .tcp_flags = 0,
518                 .priority = 2, /* Higher priority than IP */
519                 .queue = l1->udp_local_q,
520         };
521
522         return rte_eth_dev_filter_ctrl(l1->pmd_id,
523                 RTE_ETH_FILTER_NTUPLE,
524                 RTE_ETH_FILTER_DELETE,
525                 &filter);
526 }
527
528 static inline int
529 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
530 {
531         struct rte_eth_ntuple_filter filter = {
532                 .flags = RTE_5TUPLE_FLAGS,
533                 .dst_ip = rte_bswap32(l2->ip),
534                 .dst_ip_mask = UINT32_MAX, /* Enable */
535                 .src_ip = 0,
536                 .src_ip_mask = 0, /* Disable */
537                 .dst_port = 0,
538                 .dst_port_mask = 0, /* Disable */
539                 .src_port = 0,
540                 .src_port_mask = 0, /* Disable */
541                 .proto = IPPROTO_SCTP,
542                 .proto_mask = UINT8_MAX, /* Enable */
543                 .tcp_flags = 0,
544                 .priority = 2, /* Higher priority than IP */
545                 .queue = l1->sctp_local_q,
546         };
547
548         return rte_eth_dev_filter_ctrl(l1->pmd_id,
549                 RTE_ETH_FILTER_NTUPLE,
550                 RTE_ETH_FILTER_ADD,
551                 &filter);
552 }
553
554 static inline int
555 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
556 {
557         struct rte_eth_ntuple_filter filter = {
558                 .flags = RTE_5TUPLE_FLAGS,
559                 .dst_ip = rte_bswap32(l2->ip),
560                 .dst_ip_mask = UINT32_MAX, /* Enable */
561                 .src_ip = 0,
562                 .src_ip_mask = 0, /* Disable */
563                 .dst_port = 0,
564                 .dst_port_mask = 0, /* Disable */
565                 .src_port = 0,
566                 .src_port_mask = 0, /* Disable */
567                 .proto = IPPROTO_SCTP,
568                 .proto_mask = UINT8_MAX, /* Enable */
569                 .tcp_flags = 0,
570                 .priority = 2, /* Higher priority than IP */
571                 .queue = l1->sctp_local_q,
572         };
573
574         return rte_eth_dev_filter_ctrl(l1->pmd_id,
575                 RTE_ETH_FILTER_NTUPLE,
576                 RTE_ETH_FILTER_DELETE,
577                 &filter);
578 }
579
580 static void
581 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
582 {
583         if (cp->arp_q != 0) {
584                 int status = app_link_filter_arp_add(cp);
585
586                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
587                         "Adding ARP filter (queue = %" PRIu32 ")",
588                         cp->name, cp->pmd_id, cp->arp_q);
589
590                 if (status)
591                         rte_panic("%s (%" PRIu32 "): "
592                                 "Error adding ARP filter "
593                                 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
594                                 cp->name, cp->pmd_id, cp->arp_q, status);
595         }
596 }
597
598 static void
599 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
600 {
601         if (cp->tcp_syn_q != 0) {
602                 int status = app_link_filter_tcp_syn_add(cp);
603
604                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
605                         "Adding TCP SYN filter (queue = %" PRIu32 ")",
606                         cp->name, cp->pmd_id, cp->tcp_syn_q);
607
608                 if (status)
609                         rte_panic("%s (%" PRIu32 "): "
610                                 "Error adding TCP SYN filter "
611                                 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
612                                 cp->name, cp->pmd_id, cp->tcp_syn_q,
613                                 status);
614         }
615 }
616
617 void
618 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
619 {
620         uint32_t i;
621         int status;
622
623         /* For each link, add filters for IP of current link */
624         if (cp->ip != 0) {
625                 for (i = 0; i < app->n_links; i++) {
626                         struct app_link_params *p = &app->link_params[i];
627
628                         /* IP */
629                         if (p->ip_local_q != 0) {
630                                 int status = app_link_filter_ip_add(p, cp);
631
632                                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
633                                         "Adding IP filter (queue= %" PRIu32
634                                         ", IP = 0x%08" PRIx32 ")",
635                                         p->name, p->pmd_id, p->ip_local_q,
636                                         cp->ip);
637
638                                 if (status)
639                                         rte_panic("%s (%" PRIu32 "): "
640                                                 "Error adding IP "
641                                                 "filter (queue= %" PRIu32 ", "
642                                                 "IP = 0x%08" PRIx32
643                                                 ") (%" PRId32 ")\n",
644                                                 p->name, p->pmd_id,
645                                                 p->ip_local_q, cp->ip, status);
646                         }
647
648                         /* TCP */
649                         if (p->tcp_local_q != 0) {
650                                 int status = app_link_filter_tcp_add(p, cp);
651
652                                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
653                                         "Adding TCP filter "
654                                         "(queue = %" PRIu32
655                                         ", IP = 0x%08" PRIx32 ")",
656                                         p->name, p->pmd_id, p->tcp_local_q,
657                                         cp->ip);
658
659                                 if (status)
660                                         rte_panic("%s (%" PRIu32 "): "
661                                                 "Error adding TCP "
662                                                 "filter (queue = %" PRIu32 ", "
663                                                 "IP = 0x%08" PRIx32
664                                                 ") (%" PRId32 ")\n",
665                                                 p->name, p->pmd_id,
666                                                 p->tcp_local_q, cp->ip, status);
667                         }
668
669                         /* UDP */
670                         if (p->udp_local_q != 0) {
671                                 int status = app_link_filter_udp_add(p, cp);
672
673                                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
674                                         "Adding UDP filter "
675                                         "(queue = %" PRIu32
676                                         ", IP = 0x%08" PRIx32 ")",
677                                         p->name, p->pmd_id, p->udp_local_q,
678                                         cp->ip);
679
680                                 if (status)
681                                         rte_panic("%s (%" PRIu32 "): "
682                                                 "Error adding UDP "
683                                                 "filter (queue = %" PRIu32 ", "
684                                                 "IP = 0x%08" PRIx32
685                                                 ") (%" PRId32 ")\n",
686                                                 p->name, p->pmd_id,
687                                                 p->udp_local_q, cp->ip, status);
688                         }
689
690                         /* SCTP */
691                         if (p->sctp_local_q != 0) {
692                                 int status = app_link_filter_sctp_add(p, cp);
693
694                                 APP_LOG(app, LOW, "%s (%" PRIu32
695                                         "): Adding SCTP filter "
696                                         "(queue = %" PRIu32
697                                         ", IP = 0x%08" PRIx32 ")",
698                                         p->name, p->pmd_id, p->sctp_local_q,
699                                         cp->ip);
700
701                                 if (status)
702                                         rte_panic("%s (%" PRIu32 "): "
703                                                 "Error adding SCTP "
704                                                 "filter (queue = %" PRIu32 ", "
705                                                 "IP = 0x%08" PRIx32
706                                                 ") (%" PRId32 ")\n",
707                                                 p->name, p->pmd_id,
708                                                 p->sctp_local_q, cp->ip,
709                                                 status);
710                         }
711                 }
712         }
713
714         /* PMD link up */
715         status = rte_eth_dev_set_link_up(cp->pmd_id);
716         if (status < 0)
717                 rte_panic("%s (%" PRIu32 "): PMD set link up error %"
718                         PRId32 "\n", cp->name, cp->pmd_id, status);
719
720         /* Mark link as UP */
721         cp->state = 1;
722 }
723
724 void
725 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
726 {
727         uint32_t i;
728         int status;
729
730         /* PMD link down */
731         status = rte_eth_dev_set_link_down(cp->pmd_id);
732         if (status < 0)
733                 rte_panic("%s (%" PRIu32 "): PMD set link down error %"
734                         PRId32 "\n", cp->name, cp->pmd_id, status);
735
736         /* Mark link as DOWN */
737         cp->state = 0;
738
739         /* Return if current link IP is not valid */
740         if (cp->ip == 0)
741                 return;
742
743         /* For each link, remove filters for IP of current link */
744         for (i = 0; i < app->n_links; i++) {
745                 struct app_link_params *p = &app->link_params[i];
746
747                 /* IP */
748                 if (p->ip_local_q != 0) {
749                         int status = app_link_filter_ip_del(p, cp);
750
751                         APP_LOG(app, LOW, "%s (%" PRIu32
752                                 "): Deleting IP filter "
753                                 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
754                                 p->name, p->pmd_id, p->ip_local_q, cp->ip);
755
756                         if (status)
757                                 rte_panic("%s (%" PRIu32
758                                         "): Error deleting IP filter "
759                                         "(queue = %" PRIu32
760                                         ", IP = 0x%" PRIx32
761                                         ") (%" PRId32 ")\n",
762                                         p->name, p->pmd_id, p->ip_local_q,
763                                         cp->ip, status);
764                 }
765
766                 /* TCP */
767                 if (p->tcp_local_q != 0) {
768                         int status = app_link_filter_tcp_del(p, cp);
769
770                         APP_LOG(app, LOW, "%s (%" PRIu32
771                                 "): Deleting TCP filter "
772                                 "(queue = %" PRIu32
773                                 ", IP = 0x%" PRIx32 ")",
774                                 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
775
776                         if (status)
777                                 rte_panic("%s (%" PRIu32
778                                         "): Error deleting TCP filter "
779                                         "(queue = %" PRIu32
780                                         ", IP = 0x%" PRIx32
781                                         ") (%" PRId32 ")\n",
782                                         p->name, p->pmd_id, p->tcp_local_q,
783                                         cp->ip, status);
784                 }
785
786                 /* UDP */
787                 if (p->udp_local_q != 0) {
788                         int status = app_link_filter_udp_del(p, cp);
789
790                         APP_LOG(app, LOW, "%s (%" PRIu32
791                                 "): Deleting UDP filter "
792                                 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
793                                 p->name, p->pmd_id, p->udp_local_q, cp->ip);
794
795                         if (status)
796                                 rte_panic("%s (%" PRIu32
797                                         "): Error deleting UDP filter "
798                                         "(queue = %" PRIu32
799                                         ", IP = 0x%" PRIx32
800                                         ") (%" PRId32 ")\n",
801                                         p->name, p->pmd_id, p->udp_local_q,
802                                         cp->ip, status);
803                 }
804
805                 /* SCTP */
806                 if (p->sctp_local_q != 0) {
807                         int status = app_link_filter_sctp_del(p, cp);
808
809                         APP_LOG(app, LOW, "%s (%" PRIu32
810                                 "): Deleting SCTP filter "
811                                 "(queue = %" PRIu32
812                                 ", IP = 0x%" PRIx32 ")",
813                                 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
814
815                         if (status)
816                                 rte_panic("%s (%" PRIu32
817                                         "): Error deleting SCTP filter "
818                                         "(queue = %" PRIu32
819                                         ", IP = 0x%" PRIx32
820                                         ") (%" PRId32 ")\n",
821                                         p->name, p->pmd_id, p->sctp_local_q,
822                                         cp->ip, status);
823                 }
824         }
825 }
826
827 static void
828 app_check_link(struct app_params *app)
829 {
830         uint32_t all_links_up, i;
831
832         all_links_up = 1;
833
834         for (i = 0; i < app->n_links; i++) {
835                 struct app_link_params *p = &app->link_params[i];
836                 struct rte_eth_link link_params;
837
838                 memset(&link_params, 0, sizeof(link_params));
839                 rte_eth_link_get(p->pmd_id, &link_params);
840
841                 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
842                         p->name,
843                         p->pmd_id,
844                         link_params.link_speed / 1000,
845                         link_params.link_status ? "UP" : "DOWN");
846
847                 if (link_params.link_status == ETH_LINK_DOWN)
848                         all_links_up = 0;
849         }
850
851         if (all_links_up == 0)
852                 rte_panic("Some links are DOWN\n");
853 }
854
855 static uint32_t
856 is_any_swq_frag_or_ras(struct app_params *app)
857 {
858         uint32_t i;
859
860         for (i = 0; i < app->n_pktq_swq; i++) {
861                 struct app_pktq_swq_params *p = &app->swq_params[i];
862
863                 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
864                         (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
865                         return 1;
866         }
867
868         return 0;
869 }
870
871 static void
872 app_init_link_frag_ras(struct app_params *app)
873 {
874         uint32_t i;
875
876         if (is_any_swq_frag_or_ras(app)) {
877                 for (i = 0; i < app->n_pktq_hwq_out; i++) {
878                         struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
879
880                         p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
881                 }
882         }
883 }
884
885 static inline int
886 app_get_cpu_socket_id(uint32_t pmd_id)
887 {
888         int status = rte_eth_dev_socket_id(pmd_id);
889
890         return (status != SOCKET_ID_ANY) ? status : 0;
891 }
892
893 static inline int
894 app_link_rss_enabled(struct app_link_params *cp)
895 {
896         return (cp->n_rss_qs) ? 1 : 0;
897 }
898
899 static void
900 app_link_rss_setup(struct app_link_params *cp)
901 {
902         struct rte_eth_dev_info dev_info;
903         struct rte_eth_rss_reta_entry64 reta_conf[APP_RETA_SIZE_MAX];
904         uint32_t i;
905         int status;
906
907     /* Get RETA size */
908         memset(&dev_info, 0, sizeof(dev_info));
909         rte_eth_dev_info_get(cp->pmd_id, &dev_info);
910
911         if (dev_info.reta_size == 0)
912                 rte_panic("%s (%u): RSS setup error (null RETA size)\n",
913                         cp->name, cp->pmd_id);
914
915         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512)
916                 rte_panic("%s (%u): RSS setup error (RETA size too big)\n",
917                         cp->name, cp->pmd_id);
918
919         /* Setup RETA contents */
920         memset(reta_conf, 0, sizeof(reta_conf));
921
922         for (i = 0; i < dev_info.reta_size; i++)
923                 reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX;
924
925         for (i = 0; i < dev_info.reta_size; i++) {
926                 uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
927                 uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
928                 uint32_t rss_qs_pos = i % cp->n_rss_qs;
929
930                 reta_conf[reta_id].reta[reta_pos] =
931                         (uint16_t) cp->rss_qs[rss_qs_pos];
932         }
933
934         /* RETA update */
935         status = rte_eth_dev_rss_reta_update(cp->pmd_id,
936                 reta_conf,
937                 dev_info.reta_size);
938         if (status != 0)
939                 rte_panic("%s (%u): RSS setup error (RETA update failed)\n",
940                         cp->name, cp->pmd_id);
941 }
942
943 static void
944 app_init_link_set_config(struct app_link_params *p)
945 {
946         if (p->n_rss_qs) {
947                 p->conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
948                 p->conf.rx_adv_conf.rss_conf.rss_hf = p->rss_proto_ipv4 |
949                         p->rss_proto_ipv6 |
950                         p->rss_proto_l2;
951         }
952 }
953
954 static void
955 app_init_link(struct app_params *app)
956 {
957         uint32_t i;
958
959         app_init_link_frag_ras(app);
960
961         for (i = 0; i < app->n_links; i++) {
962                 struct app_link_params *p_link = &app->link_params[i];
963                 uint32_t link_id, n_hwq_in, n_hwq_out, j;
964                 int status;
965
966                 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
967                 n_hwq_in = app_link_get_n_rxq(app, p_link);
968                 n_hwq_out = app_link_get_n_txq(app, p_link);
969                 app_init_link_set_config(p_link);
970
971                 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
972                         "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
973                         p_link->name,
974                         p_link->pmd_id,
975                         n_hwq_in,
976                         n_hwq_out);
977
978                 /* LINK */
979                 status = rte_eth_dev_configure(
980                         p_link->pmd_id,
981                         n_hwq_in,
982                         n_hwq_out,
983                         &p_link->conf);
984                 if (status < 0)
985                         rte_panic("%s (%" PRId32 "): "
986                                 "init error (%" PRId32 ")\n",
987                                 p_link->name, p_link->pmd_id, status);
988
989                 rte_eth_macaddr_get(p_link->pmd_id,
990                         (struct ether_addr *) &p_link->mac_addr);
991
992                 if (p_link->promisc)
993                         rte_eth_promiscuous_enable(p_link->pmd_id);
994
995                 /* RXQ */
996                 for (j = 0; j < app->n_pktq_hwq_in; j++) {
997                         struct app_pktq_hwq_in_params *p_rxq =
998                                 &app->hwq_in_params[j];
999                         uint32_t rxq_link_id, rxq_queue_id;
1000
1001                         sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
1002                                 &rxq_link_id, &rxq_queue_id);
1003                         if (rxq_link_id != link_id)
1004                                 continue;
1005
1006                         status = rte_eth_rx_queue_setup(
1007                                 p_link->pmd_id,
1008                                 rxq_queue_id,
1009                                 p_rxq->size,
1010                                 app_get_cpu_socket_id(p_link->pmd_id),
1011                                 &p_rxq->conf,
1012                                 app->mempool[p_rxq->mempool_id]);
1013                         if (status < 0)
1014                                 rte_panic("%s (%" PRIu32 "): "
1015                                         "%s init error (%" PRId32 ")\n",
1016                                         p_link->name,
1017                                         p_link->pmd_id,
1018                                         p_rxq->name,
1019                                         status);
1020                 }
1021
1022                 /* TXQ */
1023                 for (j = 0; j < app->n_pktq_hwq_out; j++) {
1024                         struct app_pktq_hwq_out_params *p_txq =
1025                                 &app->hwq_out_params[j];
1026                         uint32_t txq_link_id, txq_queue_id;
1027
1028                         sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
1029                                 &txq_link_id, &txq_queue_id);
1030                         if (txq_link_id != link_id)
1031                                 continue;
1032
1033                         status = rte_eth_tx_queue_setup(
1034                                 p_link->pmd_id,
1035                                 txq_queue_id,
1036                                 p_txq->size,
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(uint8_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(uint8_t port_id, unsigned 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 void app_pipeline_params_get(struct app_params *app,
1329         struct app_pipeline_params *p_in,
1330         struct pipeline_params *p_out)
1331 {
1332         uint32_t i;
1333
1334         snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1335
1336         snprintf(p_out->type, PIPELINE_TYPE_SIZE, "%s", p_in->type);
1337
1338         p_out->socket_id = (int) p_in->socket_id;
1339
1340         p_out->log_level = app->log_level;
1341
1342         /* pktq_in */
1343         p_out->n_ports_in = p_in->n_pktq_in;
1344         for (i = 0; i < p_in->n_pktq_in; i++) {
1345                 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1346                 struct pipeline_port_in_params *out = &p_out->port_in[i];
1347
1348                 switch (in->type) {
1349                 case APP_PKTQ_IN_HWQ:
1350                 {
1351                         struct app_pktq_hwq_in_params *p_hwq_in =
1352                                 &app->hwq_in_params[in->id];
1353                         struct app_link_params *p_link =
1354                                 app_get_link_for_rxq(app, p_hwq_in);
1355                         uint32_t rxq_link_id, rxq_queue_id;
1356
1357                         sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1358                                 &rxq_link_id,
1359                                 &rxq_queue_id);
1360
1361                         out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1362                         out->params.ethdev.port_id = p_link->pmd_id;
1363                         out->params.ethdev.queue_id = rxq_queue_id;
1364                         out->burst_size = p_hwq_in->burst;
1365                         break;
1366                 }
1367                 case APP_PKTQ_IN_SWQ:
1368                 {
1369                         struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1370
1371                         if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1372                                 if (app_swq_get_readers(app, swq_params) == 1) {
1373                                         out->type = PIPELINE_PORT_IN_RING_READER;
1374                                         out->params.ring.ring = app->swq[in->id];
1375                                         out->burst_size = app->swq_params[in->id].burst_read;
1376                                 } else {
1377                                         out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1378                                         out->params.ring_multi.ring = app->swq[in->id];
1379                                         out->burst_size = swq_params->burst_read;
1380                                 }
1381                         } else {
1382                                 if (swq_params->ipv4_frag == 1) {
1383                                         struct rte_port_ring_reader_ipv4_frag_params *params =
1384                                                 &out->params.ring_ipv4_frag;
1385
1386                                         out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1387                                         params->ring = app->swq[in->id];
1388                                         params->mtu = swq_params->mtu;
1389                                         params->metadata_size = swq_params->metadata_size;
1390                                         params->pool_direct =
1391                                                 app->mempool[swq_params->mempool_direct_id];
1392                                         params->pool_indirect =
1393                                                 app->mempool[swq_params->mempool_indirect_id];
1394                                         out->burst_size = swq_params->burst_read;
1395                                 } else {
1396                                         struct rte_port_ring_reader_ipv6_frag_params *params =
1397                                                 &out->params.ring_ipv6_frag;
1398
1399                                         out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1400                                         params->ring = app->swq[in->id];
1401                                         params->mtu = swq_params->mtu;
1402                                         params->metadata_size = swq_params->metadata_size;
1403                                         params->pool_direct =
1404                                                 app->mempool[swq_params->mempool_direct_id];
1405                                         params->pool_indirect =
1406                                                 app->mempool[swq_params->mempool_indirect_id];
1407                                         out->burst_size = swq_params->burst_read;
1408                                 }
1409                         }
1410                         break;
1411                 }
1412                 case APP_PKTQ_IN_TM:
1413                 {
1414                         out->type = PIPELINE_PORT_IN_SCHED_READER;
1415                         out->params.sched.sched = app->tm[in->id];
1416                         out->burst_size = app->tm_params[in->id].burst_read;
1417                         break;
1418                 }
1419 #ifdef RTE_EXEC_ENV_LINUXAPP
1420                 case APP_PKTQ_IN_TAP:
1421                 {
1422                         struct app_pktq_tap_params *tap_params =
1423                                 &app->tap_params[in->id];
1424                         struct app_mempool_params *mempool_params =
1425                                 &app->mempool_params[tap_params->mempool_id];
1426                         struct rte_mempool *mempool =
1427                                 app->mempool[tap_params->mempool_id];
1428
1429                         out->type = PIPELINE_PORT_IN_FD_READER;
1430                         out->params.fd.fd = app->tap[in->id];
1431                         out->params.fd.mtu = mempool_params->buffer_size;
1432                         out->params.fd.mempool = mempool;
1433                         out->burst_size = app->tap_params[in->id].burst_read;
1434                         break;
1435                 }
1436 #endif
1437 #ifdef RTE_LIBRTE_KNI
1438                 case APP_PKTQ_IN_KNI:
1439                 {
1440                         out->type = PIPELINE_PORT_IN_KNI_READER;
1441                         out->params.kni.kni = app->kni[in->id];
1442                         out->burst_size = app->kni_params[in->id].burst_read;
1443                         break;
1444                 }
1445 #endif /* RTE_LIBRTE_KNI */
1446                 case APP_PKTQ_IN_SOURCE:
1447                 {
1448                         uint32_t mempool_id =
1449                                 app->source_params[in->id].mempool_id;
1450
1451                         out->type = PIPELINE_PORT_IN_SOURCE;
1452                         out->params.source.mempool = app->mempool[mempool_id];
1453                         out->burst_size = app->source_params[in->id].burst;
1454                         out->params.source.file_name =
1455                                 app->source_params[in->id].file_name;
1456                         out->params.source.n_bytes_per_pkt =
1457                                 app->source_params[in->id].n_bytes_per_pkt;
1458                         break;
1459                 }
1460                 default:
1461                         break;
1462                 }
1463         }
1464
1465         /* pktq_out */
1466         p_out->n_ports_out = p_in->n_pktq_out;
1467         for (i = 0; i < p_in->n_pktq_out; i++) {
1468                 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1469                 struct pipeline_port_out_params *out = &p_out->port_out[i];
1470
1471                 switch (in->type) {
1472                 case APP_PKTQ_OUT_HWQ:
1473                 {
1474                         struct app_pktq_hwq_out_params *p_hwq_out =
1475                                 &app->hwq_out_params[in->id];
1476                         struct app_link_params *p_link =
1477                                 app_get_link_for_txq(app, p_hwq_out);
1478                         uint32_t txq_link_id, txq_queue_id;
1479
1480                         sscanf(p_hwq_out->name,
1481                                 "TXQ%" SCNu32 ".%" SCNu32,
1482                                 &txq_link_id,
1483                                 &txq_queue_id);
1484
1485                         if (p_hwq_out->dropless == 0) {
1486                                 struct rte_port_ethdev_writer_params *params =
1487                                         &out->params.ethdev;
1488
1489                                 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1490                                 params->port_id = p_link->pmd_id;
1491                                 params->queue_id = txq_queue_id;
1492                                 params->tx_burst_sz =
1493                                         app->hwq_out_params[in->id].burst;
1494                         } else {
1495                                 struct rte_port_ethdev_writer_nodrop_params
1496                                         *params = &out->params.ethdev_nodrop;
1497
1498                                 out->type =
1499                                         PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1500                                 params->port_id = p_link->pmd_id;
1501                                 params->queue_id = txq_queue_id;
1502                                 params->tx_burst_sz = p_hwq_out->burst;
1503                                 params->n_retries = p_hwq_out->n_retries;
1504                         }
1505                         break;
1506                 }
1507                 case APP_PKTQ_OUT_SWQ:
1508                 {
1509                         struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1510
1511                         if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1512                                 if (app_swq_get_writers(app, swq_params) == 1) {
1513                                         if (app->swq_params[in->id].dropless == 0) {
1514                                                 struct rte_port_ring_writer_params *params =
1515                                                         &out->params.ring;
1516
1517                                                 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1518                                                 params->ring = app->swq[in->id];
1519                                                 params->tx_burst_sz =
1520                                                         app->swq_params[in->id].burst_write;
1521                                         } else {
1522                                                 struct rte_port_ring_writer_nodrop_params
1523                                                         *params = &out->params.ring_nodrop;
1524
1525                                                 out->type =
1526                                                         PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1527                                                 params->ring = app->swq[in->id];
1528                                                 params->tx_burst_sz =
1529                                                         app->swq_params[in->id].burst_write;
1530                                                 params->n_retries =
1531                                                         app->swq_params[in->id].n_retries;
1532                                         }
1533                                 } else {
1534                                         if (swq_params->dropless == 0) {
1535                                                 struct rte_port_ring_multi_writer_params *params =
1536                                                         &out->params.ring_multi;
1537
1538                                                 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1539                                                 params->ring = app->swq[in->id];
1540                                                 params->tx_burst_sz = swq_params->burst_write;
1541                                         } else {
1542                                                 struct rte_port_ring_multi_writer_nodrop_params
1543                                                         *params = &out->params.ring_multi_nodrop;
1544
1545                                                 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1546                                                 params->ring = app->swq[in->id];
1547                                                 params->tx_burst_sz = swq_params->burst_write;
1548                                                 params->n_retries = swq_params->n_retries;
1549                                         }
1550                                 }
1551                         } else {
1552                                 if (swq_params->ipv4_ras == 1) {
1553                                         struct rte_port_ring_writer_ipv4_ras_params *params =
1554                                                 &out->params.ring_ipv4_ras;
1555
1556                                         out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1557                                         params->ring = app->swq[in->id];
1558                                         params->tx_burst_sz = swq_params->burst_write;
1559                                 } else {
1560                                         struct rte_port_ring_writer_ipv6_ras_params *params =
1561                                                 &out->params.ring_ipv6_ras;
1562
1563                                         out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1564                                         params->ring = app->swq[in->id];
1565                                         params->tx_burst_sz = swq_params->burst_write;
1566                                 }
1567                         }
1568                         break;
1569                 }
1570                 case APP_PKTQ_OUT_TM:
1571                 {
1572                         struct rte_port_sched_writer_params *params =
1573                                 &out->params.sched;
1574
1575                         out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1576                         params->sched = app->tm[in->id];
1577                         params->tx_burst_sz =
1578                                 app->tm_params[in->id].burst_write;
1579                         break;
1580                 }
1581 #ifdef RTE_EXEC_ENV_LINUXAPP
1582                 case APP_PKTQ_OUT_TAP:
1583                 {
1584                         struct rte_port_fd_writer_params *params =
1585                                 &out->params.fd;
1586
1587                         out->type = PIPELINE_PORT_OUT_FD_WRITER;
1588                         params->fd = app->tap[in->id];
1589                         params->tx_burst_sz =
1590                                 app->tap_params[in->id].burst_write;
1591                         break;
1592                 }
1593 #endif
1594 #ifdef RTE_LIBRTE_KNI
1595                 case APP_PKTQ_OUT_KNI:
1596                 {
1597                         struct app_pktq_kni_params *p_kni =
1598                                 &app->kni_params[in->id];
1599
1600                         if (p_kni->dropless == 0) {
1601                                 struct rte_port_kni_writer_params *params =
1602                                         &out->params.kni;
1603
1604                                 out->type = PIPELINE_PORT_OUT_KNI_WRITER;
1605                                 params->kni = app->kni[in->id];
1606                                 params->tx_burst_sz =
1607                                         app->kni_params[in->id].burst_write;
1608                         } else {
1609                                 struct rte_port_kni_writer_nodrop_params
1610                                         *params = &out->params.kni_nodrop;
1611
1612                                 out->type = PIPELINE_PORT_OUT_KNI_WRITER_NODROP;
1613                                 params->kni = app->kni[in->id];
1614                                 params->tx_burst_sz =
1615                                         app->kni_params[in->id].burst_write;
1616                                 params->n_retries =
1617                                         app->kni_params[in->id].n_retries;
1618                         }
1619                         break;
1620                 }
1621 #endif /* RTE_LIBRTE_KNI */
1622                 case APP_PKTQ_OUT_SINK:
1623                 {
1624                         out->type = PIPELINE_PORT_OUT_SINK;
1625                         out->params.sink.file_name =
1626                                 app->sink_params[in->id].file_name;
1627                         out->params.sink.max_n_pkts =
1628                                 app->sink_params[in->id].
1629                                 n_pkts_to_dump;
1630
1631                         break;
1632                 }
1633                 default:
1634                         break;
1635                 }
1636         }
1637
1638         /* msgq */
1639         p_out->n_msgq = p_in->n_msgq_in;
1640
1641         for (i = 0; i < p_in->n_msgq_in; i++)
1642                 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1643
1644         for (i = 0; i < p_in->n_msgq_out; i++)
1645                 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1646
1647         /* args */
1648         p_out->n_args = p_in->n_args;
1649         for (i = 0; i < p_in->n_args; i++) {
1650                 p_out->args_name[i] = p_in->args_name[i];
1651                 p_out->args_value[i] = p_in->args_value[i];
1652         }
1653 }
1654
1655 static void
1656 app_init_pipelines(struct app_params *app)
1657 {
1658         uint32_t p_id;
1659
1660         for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1661                 struct app_pipeline_params *params =
1662                         &app->pipeline_params[p_id];
1663                 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1664                 struct pipeline_type *ptype;
1665                 struct pipeline_params pp;
1666
1667                 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1668
1669                 ptype = app_pipeline_type_find(app, params->type);
1670                 if (ptype == NULL)
1671                         rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1672                                 params->type);
1673
1674                 app_pipeline_params_get(app, params, &pp);
1675
1676                 /* Back-end */
1677                 data->be = NULL;
1678                 if (ptype->be_ops->f_init) {
1679                         data->be = ptype->be_ops->f_init(&pp, (void *) app);
1680
1681                         if (data->be == NULL)
1682                                 rte_panic("Pipeline instance \"%s\" back-end "
1683                                         "init error\n", params->name);
1684                 }
1685
1686                 /* Front-end */
1687                 data->fe = NULL;
1688                 if (ptype->fe_ops->f_init) {
1689                         data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1690
1691                         if (data->fe == NULL)
1692                                 rte_panic("Pipeline instance \"%s\" front-end "
1693                                 "init error\n", params->name);
1694                 }
1695
1696                 data->ptype = ptype;
1697
1698                 data->timer_period = (rte_get_tsc_hz() *
1699                         params->timer_period) / 100;
1700         }
1701 }
1702
1703 static void
1704 app_post_init_pipelines(struct app_params *app)
1705 {
1706         uint32_t p_id;
1707
1708         for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1709                 struct app_pipeline_params *params =
1710                         &app->pipeline_params[p_id];
1711                 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1712                 int status;
1713
1714                 if (data->ptype->fe_ops->f_post_init == NULL)
1715                         continue;
1716
1717                 status = data->ptype->fe_ops->f_post_init(data->fe);
1718                 if (status)
1719                         rte_panic("Pipeline instance \"%s\" front-end "
1720                                 "post-init error\n", params->name);
1721         }
1722 }
1723
1724 static void
1725 app_init_threads(struct app_params *app)
1726 {
1727         uint64_t time = rte_get_tsc_cycles();
1728         uint32_t p_id;
1729
1730         for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1731                 struct app_pipeline_params *params =
1732                         &app->pipeline_params[p_id];
1733                 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1734                 struct pipeline_type *ptype;
1735                 struct app_thread_data *t;
1736                 struct app_thread_pipeline_data *p;
1737                 int lcore_id;
1738
1739                 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1740                         params->socket_id,
1741                         params->core_id,
1742                         params->hyper_th_id);
1743
1744                 if (lcore_id < 0)
1745                         rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1746                                 params->socket_id,
1747                                 params->core_id,
1748                                 (params->hyper_th_id) ? "h" : "");
1749
1750                 t = &app->thread_data[lcore_id];
1751
1752                 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1753                 t->thread_req_deadline = time + t->timer_period;
1754
1755                 t->headroom_cycles = 0;
1756                 t->headroom_time = rte_get_tsc_cycles();
1757                 t->headroom_ratio = 0.0;
1758
1759                 t->msgq_in = app_thread_msgq_in_get(app,
1760                                 params->socket_id,
1761                                 params->core_id,
1762                                 params->hyper_th_id);
1763                 if (t->msgq_in == NULL)
1764                         rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1765                                 lcore_id);
1766
1767                 t->msgq_out = app_thread_msgq_out_get(app,
1768                                 params->socket_id,
1769                                 params->core_id,
1770                                 params->hyper_th_id);
1771                 if (t->msgq_out == NULL)
1772                         rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1773                                 lcore_id);
1774
1775                 ptype = app_pipeline_type_find(app, params->type);
1776                 if (ptype == NULL)
1777                         rte_panic("Init error: Unknown pipeline "
1778                                 "type \"%s\"\n", params->type);
1779
1780                 p = (ptype->be_ops->f_run == NULL) ?
1781                         &t->regular[t->n_regular] :
1782                         &t->custom[t->n_custom];
1783
1784                 p->pipeline_id = p_id;
1785                 p->be = data->be;
1786                 p->f_run = ptype->be_ops->f_run;
1787                 p->f_timer = ptype->be_ops->f_timer;
1788                 p->timer_period = data->timer_period;
1789                 p->deadline = time + data->timer_period;
1790
1791                 data->enabled = 1;
1792
1793                 if (ptype->be_ops->f_run == NULL)
1794                         t->n_regular++;
1795                 else
1796                         t->n_custom++;
1797         }
1798 }
1799
1800 int app_init(struct app_params *app)
1801 {
1802         app_init_core_map(app);
1803         app_init_core_mask(app);
1804
1805         app_init_eal(app);
1806         app_init_mempool(app);
1807         app_init_link(app);
1808         app_init_swq(app);
1809         app_init_tm(app);
1810         app_init_tap(app);
1811         app_init_kni(app);
1812         app_init_msgq(app);
1813
1814         app_pipeline_common_cmd_push(app);
1815         app_pipeline_thread_cmd_push(app);
1816         app_pipeline_type_register(app, &pipeline_master);
1817         app_pipeline_type_register(app, &pipeline_passthrough);
1818         app_pipeline_type_register(app, &pipeline_flow_classification);
1819         app_pipeline_type_register(app, &pipeline_flow_actions);
1820         app_pipeline_type_register(app, &pipeline_firewall);
1821         app_pipeline_type_register(app, &pipeline_routing);
1822
1823         app_init_pipelines(app);
1824         app_init_threads(app);
1825
1826         return 0;
1827 }
1828
1829 int app_post_init(struct app_params *app)
1830 {
1831         app_post_init_pipelines(app);
1832
1833         return 0;
1834 }
1835
1836 static int
1837 app_pipeline_type_cmd_push(struct app_params *app,
1838         struct pipeline_type *ptype)
1839 {
1840         cmdline_parse_ctx_t *cmds;
1841         uint32_t n_cmds, i;
1842
1843         /* Check input arguments */
1844         if ((app == NULL) ||
1845                 (ptype == NULL))
1846                 return -EINVAL;
1847
1848         n_cmds = pipeline_type_cmds_count(ptype);
1849         if (n_cmds == 0)
1850                 return 0;
1851
1852         cmds = ptype->fe_ops->cmds;
1853
1854         /* Check for available slots in the application commands array */
1855         if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1856                 return -ENOMEM;
1857
1858         /* Push pipeline commands into the application */
1859         memcpy(&app->cmds[app->n_cmds],
1860                 cmds,
1861                 n_cmds * sizeof(cmdline_parse_ctx_t));
1862
1863         for (i = 0; i < n_cmds; i++)
1864                 app->cmds[app->n_cmds + i]->data = app;
1865
1866         app->n_cmds += n_cmds;
1867         app->cmds[app->n_cmds] = NULL;
1868
1869         return 0;
1870 }
1871
1872 int
1873 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1874 {
1875         uint32_t n_cmds, i;
1876
1877         /* Check input arguments */
1878         if ((app == NULL) ||
1879                 (ptype == NULL) ||
1880                 (ptype->name == NULL) ||
1881                 (strlen(ptype->name) == 0) ||
1882                 (ptype->be_ops->f_init == NULL) ||
1883                 (ptype->be_ops->f_timer == NULL))
1884                 return -EINVAL;
1885
1886         /* Check for duplicate entry */
1887         for (i = 0; i < app->n_pipeline_types; i++)
1888                 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1889                         return -EEXIST;
1890
1891         /* Check for resource availability */
1892         n_cmds = pipeline_type_cmds_count(ptype);
1893         if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1894                 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1895                 return -ENOMEM;
1896
1897         /* Copy pipeline type */
1898         memcpy(&app->pipeline_type[app->n_pipeline_types++],
1899                 ptype,
1900                 sizeof(struct pipeline_type));
1901
1902         /* Copy CLI commands */
1903         if (n_cmds)
1904                 app_pipeline_type_cmd_push(app, ptype);
1905
1906         return 0;
1907 }
1908
1909 struct
1910 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1911 {
1912         uint32_t i;
1913
1914         for (i = 0; i < app->n_pipeline_types; i++)
1915                 if (strcmp(app->pipeline_type[i].name, name) == 0)
1916                         return &app->pipeline_type[i];
1917
1918         return NULL;
1919 }