examples/ip_pipeline: remove passthrough pipeline
[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 #include "pipeline_common_fe.h"
28 #include "pipeline_master.h"
29 #include "pipeline_firewall.h"
30 #include "pipeline_flow_classification.h"
31 #include "pipeline_flow_actions.h"
32 #include "pipeline_routing.h"
33 #include "thread_fe.h"
34
35 #define APP_NAME_SIZE   32
36
37 #define APP_RETA_SIZE_MAX     (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE)
38
39 static void
40 app_init_core_map(struct app_params *app)
41 {
42         APP_LOG(app, HIGH, "Initializing CPU core map ...");
43         app->core_map = cpu_core_map_init(RTE_MAX_NUMA_NODES, RTE_MAX_LCORE,
44                                 4, 0);
45
46         if (app->core_map == NULL)
47                 rte_panic("Cannot create CPU core map\n");
48
49         if (app->log_level >= APP_LOG_LEVEL_LOW)
50                 cpu_core_map_print(app->core_map);
51 }
52
53 /* Core Mask String in Hex Representation */
54 #define APP_CORE_MASK_STRING_SIZE ((64 * APP_CORE_MASK_SIZE) / 8 * 2 + 1)
55
56 static void
57 app_init_core_mask(struct app_params *app)
58 {
59         uint32_t i;
60         char core_mask_str[APP_CORE_MASK_STRING_SIZE];
61
62         for (i = 0; i < app->n_pipelines; i++) {
63                 struct app_pipeline_params *p = &app->pipeline_params[i];
64                 int lcore_id;
65
66                 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
67                         p->socket_id,
68                         p->core_id,
69                         p->hyper_th_id);
70
71                 if (lcore_id < 0)
72                         rte_panic("Cannot create CPU core mask\n");
73
74                 app_core_enable_in_core_mask(app, lcore_id);
75         }
76
77         app_core_build_core_mask_string(app, core_mask_str);
78         APP_LOG(app, HIGH, "CPU core mask = 0x%s", core_mask_str);
79 }
80
81 static void
82 app_init_eal(struct app_params *app)
83 {
84         char buffer[256];
85         char core_mask_str[APP_CORE_MASK_STRING_SIZE];
86         struct app_eal_params *p = &app->eal_params;
87         uint32_t n_args = 0;
88         uint32_t i;
89         int status;
90
91         app->eal_argv[n_args++] = strdup(app->app_name);
92
93         app_core_build_core_mask_string(app, core_mask_str);
94         snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
95         app->eal_argv[n_args++] = strdup(buffer);
96
97         if (p->coremap) {
98                 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
99                 app->eal_argv[n_args++] = strdup(buffer);
100         }
101
102         if (p->master_lcore_present) {
103                 snprintf(buffer,
104                         sizeof(buffer),
105                         "--master-lcore=%" PRIu32,
106                         p->master_lcore);
107                 app->eal_argv[n_args++] = strdup(buffer);
108         }
109
110         snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
111         app->eal_argv[n_args++] = strdup(buffer);
112
113         if (p->memory_present) {
114                 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
115                 app->eal_argv[n_args++] = strdup(buffer);
116         }
117
118         if (p->ranks_present) {
119                 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
120                 app->eal_argv[n_args++] = strdup(buffer);
121         }
122
123         for (i = 0; i < APP_MAX_LINKS; i++) {
124                 if (p->pci_blacklist[i] == NULL)
125                         break;
126
127                 snprintf(buffer,
128                         sizeof(buffer),
129                         "--pci-blacklist=%s",
130                         p->pci_blacklist[i]);
131                 app->eal_argv[n_args++] = strdup(buffer);
132         }
133
134         if (app->port_mask != 0)
135                 for (i = 0; i < APP_MAX_LINKS; i++) {
136                         if (p->pci_whitelist[i] == NULL)
137                                 break;
138
139                         snprintf(buffer,
140                                 sizeof(buffer),
141                                 "--pci-whitelist=%s",
142                                 p->pci_whitelist[i]);
143                         app->eal_argv[n_args++] = strdup(buffer);
144                 }
145         else
146                 for (i = 0; i < app->n_links; i++) {
147                         char *pci_bdf = app->link_params[i].pci_bdf;
148
149                         snprintf(buffer,
150                                 sizeof(buffer),
151                                 "--pci-whitelist=%s",
152                                 pci_bdf);
153                         app->eal_argv[n_args++] = strdup(buffer);
154                 }
155
156         for (i = 0; i < APP_MAX_LINKS; i++) {
157                 if (p->vdev[i] == NULL)
158                         break;
159
160                 snprintf(buffer,
161                         sizeof(buffer),
162                         "--vdev=%s",
163                         p->vdev[i]);
164                 app->eal_argv[n_args++] = strdup(buffer);
165         }
166
167         if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
168                 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
169                 app->eal_argv[n_args++] = strdup(buffer);
170         }
171
172         if (p->proc_type) {
173                 snprintf(buffer,
174                         sizeof(buffer),
175                         "--proc-type=%s",
176                         p->proc_type);
177                 app->eal_argv[n_args++] = strdup(buffer);
178         }
179
180         if (p->syslog) {
181                 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
182                 app->eal_argv[n_args++] = strdup(buffer);
183         }
184
185         if (p->log_level_present) {
186                 snprintf(buffer,
187                         sizeof(buffer),
188                         "--log-level=%" PRIu32,
189                         p->log_level);
190                 app->eal_argv[n_args++] = strdup(buffer);
191         }
192
193         if ((p->version_present) && p->version) {
194                 snprintf(buffer, sizeof(buffer), "-v");
195                 app->eal_argv[n_args++] = strdup(buffer);
196         }
197
198         if ((p->help_present) && p->help) {
199                 snprintf(buffer, sizeof(buffer), "--help");
200                 app->eal_argv[n_args++] = strdup(buffer);
201         }
202
203         if ((p->no_huge_present) && p->no_huge) {
204                 snprintf(buffer, sizeof(buffer), "--no-huge");
205                 app->eal_argv[n_args++] = strdup(buffer);
206         }
207
208         if ((p->no_pci_present) && p->no_pci) {
209                 snprintf(buffer, sizeof(buffer), "--no-pci");
210                 app->eal_argv[n_args++] = strdup(buffer);
211         }
212
213         if ((p->no_hpet_present) && p->no_hpet) {
214                 snprintf(buffer, sizeof(buffer), "--no-hpet");
215                 app->eal_argv[n_args++] = strdup(buffer);
216         }
217
218         if ((p->no_shconf_present) && p->no_shconf) {
219                 snprintf(buffer, sizeof(buffer), "--no-shconf");
220                 app->eal_argv[n_args++] = strdup(buffer);
221         }
222
223         if (p->add_driver) {
224                 snprintf(buffer, sizeof(buffer), "-d%s", p->add_driver);
225                 app->eal_argv[n_args++] = strdup(buffer);
226         }
227
228         if (p->socket_mem) {
229                 snprintf(buffer,
230                         sizeof(buffer),
231                         "--socket-mem=%s",
232                         p->socket_mem);
233                 app->eal_argv[n_args++] = strdup(buffer);
234         }
235
236         if (p->huge_dir) {
237                 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
238                 app->eal_argv[n_args++] = strdup(buffer);
239         }
240
241         if (p->file_prefix) {
242                 snprintf(buffer,
243                         sizeof(buffer),
244                         "--file-prefix=%s",
245                         p->file_prefix);
246                 app->eal_argv[n_args++] = strdup(buffer);
247         }
248
249         if (p->base_virtaddr) {
250                 snprintf(buffer,
251                         sizeof(buffer),
252                         "--base-virtaddr=%s",
253                         p->base_virtaddr);
254                 app->eal_argv[n_args++] = strdup(buffer);
255         }
256
257         if ((p->create_uio_dev_present) && p->create_uio_dev) {
258                 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
259                 app->eal_argv[n_args++] = strdup(buffer);
260         }
261
262         if (p->vfio_intr) {
263                 snprintf(buffer,
264                         sizeof(buffer),
265                         "--vfio-intr=%s",
266                         p->vfio_intr);
267                 app->eal_argv[n_args++] = strdup(buffer);
268         }
269
270         snprintf(buffer, sizeof(buffer), "--");
271         app->eal_argv[n_args++] = strdup(buffer);
272
273         app->eal_argc = n_args;
274
275         APP_LOG(app, HIGH, "Initializing EAL ...");
276         if (app->log_level >= APP_LOG_LEVEL_LOW) {
277                 int i;
278
279                 fprintf(stdout, "[APP] EAL arguments: \"");
280                 for (i = 1; i < app->eal_argc; i++)
281                         fprintf(stdout, "%s ", app->eal_argv[i]);
282                 fprintf(stdout, "\"\n");
283         }
284
285         status = rte_eal_init(app->eal_argc, app->eal_argv);
286         if (status < 0)
287                 rte_panic("EAL init error\n");
288 }
289
290 static void
291 app_init_mempool(struct app_params *app)
292 {
293         uint32_t i;
294
295         for (i = 0; i < app->n_mempools; i++) {
296                 struct app_mempool_params *p = &app->mempool_params[i];
297
298                 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
299                 app->mempool[i] = rte_pktmbuf_pool_create(
300                         p->name,
301                         p->pool_size,
302                         p->cache_size,
303                         0, /* priv_size */
304                         p->buffer_size -
305                                 sizeof(struct rte_mbuf), /* mbuf data size */
306                         p->cpu_socket_id);
307
308                 if (app->mempool[i] == NULL)
309                         rte_panic("%s init error\n", p->name);
310         }
311 }
312
313 static inline int
314 app_link_filter_arp_add(struct app_link_params *link)
315 {
316         struct rte_eth_ethertype_filter filter = {
317                 .ether_type = ETHER_TYPE_ARP,
318                 .flags = 0,
319                 .queue = link->arp_q,
320         };
321
322         return rte_eth_dev_filter_ctrl(link->pmd_id,
323                 RTE_ETH_FILTER_ETHERTYPE,
324                 RTE_ETH_FILTER_ADD,
325                 &filter);
326 }
327
328 static inline int
329 app_link_filter_tcp_syn_add(struct app_link_params *link)
330 {
331         struct rte_eth_syn_filter filter = {
332                 .hig_pri = 1,
333                 .queue = link->tcp_syn_q,
334         };
335
336         return rte_eth_dev_filter_ctrl(link->pmd_id,
337                 RTE_ETH_FILTER_SYN,
338                 RTE_ETH_FILTER_ADD,
339                 &filter);
340 }
341
342 static inline int
343 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
344 {
345         struct rte_eth_ntuple_filter filter = {
346                 .flags = RTE_5TUPLE_FLAGS,
347                 .dst_ip = rte_bswap32(l2->ip),
348                 .dst_ip_mask = UINT32_MAX, /* Enable */
349                 .src_ip = 0,
350                 .src_ip_mask = 0, /* Disable */
351                 .dst_port = 0,
352                 .dst_port_mask = 0, /* Disable */
353                 .src_port = 0,
354                 .src_port_mask = 0, /* Disable */
355                 .proto = 0,
356                 .proto_mask = 0, /* Disable */
357                 .tcp_flags = 0,
358                 .priority = 1, /* Lowest */
359                 .queue = l1->ip_local_q,
360         };
361
362         return rte_eth_dev_filter_ctrl(l1->pmd_id,
363                 RTE_ETH_FILTER_NTUPLE,
364                 RTE_ETH_FILTER_ADD,
365                 &filter);
366 }
367
368 static inline int
369 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
370 {
371         struct rte_eth_ntuple_filter filter = {
372                 .flags = RTE_5TUPLE_FLAGS,
373                 .dst_ip = rte_bswap32(l2->ip),
374                 .dst_ip_mask = UINT32_MAX, /* Enable */
375                 .src_ip = 0,
376                 .src_ip_mask = 0, /* Disable */
377                 .dst_port = 0,
378                 .dst_port_mask = 0, /* Disable */
379                 .src_port = 0,
380                 .src_port_mask = 0, /* Disable */
381                 .proto = 0,
382                 .proto_mask = 0, /* Disable */
383                 .tcp_flags = 0,
384                 .priority = 1, /* Lowest */
385                 .queue = l1->ip_local_q,
386         };
387
388         return rte_eth_dev_filter_ctrl(l1->pmd_id,
389                 RTE_ETH_FILTER_NTUPLE,
390                 RTE_ETH_FILTER_DELETE,
391                 &filter);
392 }
393
394 static inline int
395 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
396 {
397         struct rte_eth_ntuple_filter filter = {
398                 .flags = RTE_5TUPLE_FLAGS,
399                 .dst_ip = rte_bswap32(l2->ip),
400                 .dst_ip_mask = UINT32_MAX, /* Enable */
401                 .src_ip = 0,
402                 .src_ip_mask = 0, /* Disable */
403                 .dst_port = 0,
404                 .dst_port_mask = 0, /* Disable */
405                 .src_port = 0,
406                 .src_port_mask = 0, /* Disable */
407                 .proto = IPPROTO_TCP,
408                 .proto_mask = UINT8_MAX, /* Enable */
409                 .tcp_flags = 0,
410                 .priority = 2, /* Higher priority than IP */
411                 .queue = l1->tcp_local_q,
412         };
413
414         return rte_eth_dev_filter_ctrl(l1->pmd_id,
415                 RTE_ETH_FILTER_NTUPLE,
416                 RTE_ETH_FILTER_ADD,
417                 &filter);
418 }
419
420 static inline int
421 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
422 {
423         struct rte_eth_ntuple_filter filter = {
424                 .flags = RTE_5TUPLE_FLAGS,
425                 .dst_ip = rte_bswap32(l2->ip),
426                 .dst_ip_mask = UINT32_MAX, /* Enable */
427                 .src_ip = 0,
428                 .src_ip_mask = 0, /* Disable */
429                 .dst_port = 0,
430                 .dst_port_mask = 0, /* Disable */
431                 .src_port = 0,
432                 .src_port_mask = 0, /* Disable */
433                 .proto = IPPROTO_TCP,
434                 .proto_mask = UINT8_MAX, /* Enable */
435                 .tcp_flags = 0,
436                 .priority = 2, /* Higher priority than IP */
437                 .queue = l1->tcp_local_q,
438         };
439
440         return rte_eth_dev_filter_ctrl(l1->pmd_id,
441                 RTE_ETH_FILTER_NTUPLE,
442                 RTE_ETH_FILTER_DELETE,
443                 &filter);
444 }
445
446 static inline int
447 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
448 {
449         struct rte_eth_ntuple_filter filter = {
450                 .flags = RTE_5TUPLE_FLAGS,
451                 .dst_ip = rte_bswap32(l2->ip),
452                 .dst_ip_mask = UINT32_MAX, /* Enable */
453                 .src_ip = 0,
454                 .src_ip_mask = 0, /* Disable */
455                 .dst_port = 0,
456                 .dst_port_mask = 0, /* Disable */
457                 .src_port = 0,
458                 .src_port_mask = 0, /* Disable */
459                 .proto = IPPROTO_UDP,
460                 .proto_mask = UINT8_MAX, /* Enable */
461                 .tcp_flags = 0,
462                 .priority = 2, /* Higher priority than IP */
463                 .queue = l1->udp_local_q,
464         };
465
466         return rte_eth_dev_filter_ctrl(l1->pmd_id,
467                 RTE_ETH_FILTER_NTUPLE,
468                 RTE_ETH_FILTER_ADD,
469                 &filter);
470 }
471
472 static inline int
473 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
474 {
475         struct rte_eth_ntuple_filter filter = {
476                 .flags = RTE_5TUPLE_FLAGS,
477                 .dst_ip = rte_bswap32(l2->ip),
478                 .dst_ip_mask = UINT32_MAX, /* Enable */
479                 .src_ip = 0,
480                 .src_ip_mask = 0, /* Disable */
481                 .dst_port = 0,
482                 .dst_port_mask = 0, /* Disable */
483                 .src_port = 0,
484                 .src_port_mask = 0, /* Disable */
485                 .proto = IPPROTO_UDP,
486                 .proto_mask = UINT8_MAX, /* Enable */
487                 .tcp_flags = 0,
488                 .priority = 2, /* Higher priority than IP */
489                 .queue = l1->udp_local_q,
490         };
491
492         return rte_eth_dev_filter_ctrl(l1->pmd_id,
493                 RTE_ETH_FILTER_NTUPLE,
494                 RTE_ETH_FILTER_DELETE,
495                 &filter);
496 }
497
498 static inline int
499 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
500 {
501         struct rte_eth_ntuple_filter filter = {
502                 .flags = RTE_5TUPLE_FLAGS,
503                 .dst_ip = rte_bswap32(l2->ip),
504                 .dst_ip_mask = UINT32_MAX, /* Enable */
505                 .src_ip = 0,
506                 .src_ip_mask = 0, /* Disable */
507                 .dst_port = 0,
508                 .dst_port_mask = 0, /* Disable */
509                 .src_port = 0,
510                 .src_port_mask = 0, /* Disable */
511                 .proto = IPPROTO_SCTP,
512                 .proto_mask = UINT8_MAX, /* Enable */
513                 .tcp_flags = 0,
514                 .priority = 2, /* Higher priority than IP */
515                 .queue = l1->sctp_local_q,
516         };
517
518         return rte_eth_dev_filter_ctrl(l1->pmd_id,
519                 RTE_ETH_FILTER_NTUPLE,
520                 RTE_ETH_FILTER_ADD,
521                 &filter);
522 }
523
524 static inline int
525 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
526 {
527         struct rte_eth_ntuple_filter filter = {
528                 .flags = RTE_5TUPLE_FLAGS,
529                 .dst_ip = rte_bswap32(l2->ip),
530                 .dst_ip_mask = UINT32_MAX, /* Enable */
531                 .src_ip = 0,
532                 .src_ip_mask = 0, /* Disable */
533                 .dst_port = 0,
534                 .dst_port_mask = 0, /* Disable */
535                 .src_port = 0,
536                 .src_port_mask = 0, /* Disable */
537                 .proto = IPPROTO_SCTP,
538                 .proto_mask = UINT8_MAX, /* Enable */
539                 .tcp_flags = 0,
540                 .priority = 2, /* Higher priority than IP */
541                 .queue = l1->sctp_local_q,
542         };
543
544         return rte_eth_dev_filter_ctrl(l1->pmd_id,
545                 RTE_ETH_FILTER_NTUPLE,
546                 RTE_ETH_FILTER_DELETE,
547                 &filter);
548 }
549
550 static void
551 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
552 {
553         if (cp->arp_q != 0) {
554                 int status = app_link_filter_arp_add(cp);
555
556                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
557                         "Adding ARP filter (queue = %" PRIu32 ")",
558                         cp->name, cp->pmd_id, cp->arp_q);
559
560                 if (status)
561                         rte_panic("%s (%" PRIu32 "): "
562                                 "Error adding ARP filter "
563                                 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
564                                 cp->name, cp->pmd_id, cp->arp_q, status);
565         }
566 }
567
568 static void
569 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
570 {
571         if (cp->tcp_syn_q != 0) {
572                 int status = app_link_filter_tcp_syn_add(cp);
573
574                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
575                         "Adding TCP SYN filter (queue = %" PRIu32 ")",
576                         cp->name, cp->pmd_id, cp->tcp_syn_q);
577
578                 if (status)
579                         rte_panic("%s (%" PRIu32 "): "
580                                 "Error adding TCP SYN filter "
581                                 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
582                                 cp->name, cp->pmd_id, cp->tcp_syn_q,
583                                 status);
584         }
585 }
586
587 void
588 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
589 {
590         uint32_t i;
591         int status;
592
593         /* For each link, add filters for IP of current link */
594         if (cp->ip != 0) {
595                 for (i = 0; i < app->n_links; i++) {
596                         struct app_link_params *p = &app->link_params[i];
597
598                         /* IP */
599                         if (p->ip_local_q != 0) {
600                                 int status = app_link_filter_ip_add(p, cp);
601
602                                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
603                                         "Adding IP filter (queue= %" PRIu32
604                                         ", IP = 0x%08" PRIx32 ")",
605                                         p->name, p->pmd_id, p->ip_local_q,
606                                         cp->ip);
607
608                                 if (status)
609                                         rte_panic("%s (%" PRIu32 "): "
610                                                 "Error adding IP "
611                                                 "filter (queue= %" PRIu32 ", "
612                                                 "IP = 0x%08" PRIx32
613                                                 ") (%" PRId32 ")\n",
614                                                 p->name, p->pmd_id,
615                                                 p->ip_local_q, cp->ip, status);
616                         }
617
618                         /* TCP */
619                         if (p->tcp_local_q != 0) {
620                                 int status = app_link_filter_tcp_add(p, cp);
621
622                                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
623                                         "Adding TCP filter "
624                                         "(queue = %" PRIu32
625                                         ", IP = 0x%08" PRIx32 ")",
626                                         p->name, p->pmd_id, p->tcp_local_q,
627                                         cp->ip);
628
629                                 if (status)
630                                         rte_panic("%s (%" PRIu32 "): "
631                                                 "Error adding TCP "
632                                                 "filter (queue = %" PRIu32 ", "
633                                                 "IP = 0x%08" PRIx32
634                                                 ") (%" PRId32 ")\n",
635                                                 p->name, p->pmd_id,
636                                                 p->tcp_local_q, cp->ip, status);
637                         }
638
639                         /* UDP */
640                         if (p->udp_local_q != 0) {
641                                 int status = app_link_filter_udp_add(p, cp);
642
643                                 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
644                                         "Adding UDP filter "
645                                         "(queue = %" PRIu32
646                                         ", IP = 0x%08" PRIx32 ")",
647                                         p->name, p->pmd_id, p->udp_local_q,
648                                         cp->ip);
649
650                                 if (status)
651                                         rte_panic("%s (%" PRIu32 "): "
652                                                 "Error adding UDP "
653                                                 "filter (queue = %" PRIu32 ", "
654                                                 "IP = 0x%08" PRIx32
655                                                 ") (%" PRId32 ")\n",
656                                                 p->name, p->pmd_id,
657                                                 p->udp_local_q, cp->ip, status);
658                         }
659
660                         /* SCTP */
661                         if (p->sctp_local_q != 0) {
662                                 int status = app_link_filter_sctp_add(p, cp);
663
664                                 APP_LOG(app, LOW, "%s (%" PRIu32
665                                         "): Adding SCTP filter "
666                                         "(queue = %" PRIu32
667                                         ", IP = 0x%08" PRIx32 ")",
668                                         p->name, p->pmd_id, p->sctp_local_q,
669                                         cp->ip);
670
671                                 if (status)
672                                         rte_panic("%s (%" PRIu32 "): "
673                                                 "Error adding SCTP "
674                                                 "filter (queue = %" PRIu32 ", "
675                                                 "IP = 0x%08" PRIx32
676                                                 ") (%" PRId32 ")\n",
677                                                 p->name, p->pmd_id,
678                                                 p->sctp_local_q, cp->ip,
679                                                 status);
680                         }
681                 }
682         }
683
684         /* PMD link up */
685         status = rte_eth_dev_set_link_up(cp->pmd_id);
686         /* Do not panic if PMD does not provide link up functionality */
687         if (status < 0 && status != -ENOTSUP)
688                 rte_panic("%s (%" PRIu32 "): PMD set link up error %"
689                         PRId32 "\n", cp->name, cp->pmd_id, status);
690
691         /* Mark link as UP */
692         cp->state = 1;
693 }
694
695 void
696 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
697 {
698         uint32_t i;
699         int status;
700
701         /* PMD link down */
702         status = rte_eth_dev_set_link_down(cp->pmd_id);
703         /* Do not panic if PMD does not provide link down functionality */
704         if (status < 0 && status != -ENOTSUP)
705                 rte_panic("%s (%" PRIu32 "): PMD set link down error %"
706                         PRId32 "\n", cp->name, cp->pmd_id, status);
707
708         /* Mark link as DOWN */
709         cp->state = 0;
710
711         /* Return if current link IP is not valid */
712         if (cp->ip == 0)
713                 return;
714
715         /* For each link, remove filters for IP of current link */
716         for (i = 0; i < app->n_links; i++) {
717                 struct app_link_params *p = &app->link_params[i];
718
719                 /* IP */
720                 if (p->ip_local_q != 0) {
721                         int status = app_link_filter_ip_del(p, cp);
722
723                         APP_LOG(app, LOW, "%s (%" PRIu32
724                                 "): Deleting IP filter "
725                                 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
726                                 p->name, p->pmd_id, p->ip_local_q, cp->ip);
727
728                         if (status)
729                                 rte_panic("%s (%" PRIu32
730                                         "): Error deleting IP filter "
731                                         "(queue = %" PRIu32
732                                         ", IP = 0x%" PRIx32
733                                         ") (%" PRId32 ")\n",
734                                         p->name, p->pmd_id, p->ip_local_q,
735                                         cp->ip, status);
736                 }
737
738                 /* TCP */
739                 if (p->tcp_local_q != 0) {
740                         int status = app_link_filter_tcp_del(p, cp);
741
742                         APP_LOG(app, LOW, "%s (%" PRIu32
743                                 "): Deleting TCP filter "
744                                 "(queue = %" PRIu32
745                                 ", IP = 0x%" PRIx32 ")",
746                                 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
747
748                         if (status)
749                                 rte_panic("%s (%" PRIu32
750                                         "): Error deleting TCP filter "
751                                         "(queue = %" PRIu32
752                                         ", IP = 0x%" PRIx32
753                                         ") (%" PRId32 ")\n",
754                                         p->name, p->pmd_id, p->tcp_local_q,
755                                         cp->ip, status);
756                 }
757
758                 /* UDP */
759                 if (p->udp_local_q != 0) {
760                         int status = app_link_filter_udp_del(p, cp);
761
762                         APP_LOG(app, LOW, "%s (%" PRIu32
763                                 "): Deleting UDP filter "
764                                 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
765                                 p->name, p->pmd_id, p->udp_local_q, cp->ip);
766
767                         if (status)
768                                 rte_panic("%s (%" PRIu32
769                                         "): Error deleting UDP filter "
770                                         "(queue = %" PRIu32
771                                         ", IP = 0x%" PRIx32
772                                         ") (%" PRId32 ")\n",
773                                         p->name, p->pmd_id, p->udp_local_q,
774                                         cp->ip, status);
775                 }
776
777                 /* SCTP */
778                 if (p->sctp_local_q != 0) {
779                         int status = app_link_filter_sctp_del(p, cp);
780
781                         APP_LOG(app, LOW, "%s (%" PRIu32
782                                 "): Deleting SCTP filter "
783                                 "(queue = %" PRIu32
784                                 ", IP = 0x%" PRIx32 ")",
785                                 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
786
787                         if (status)
788                                 rte_panic("%s (%" PRIu32
789                                         "): Error deleting SCTP filter "
790                                         "(queue = %" PRIu32
791                                         ", IP = 0x%" PRIx32
792                                         ") (%" PRId32 ")\n",
793                                         p->name, p->pmd_id, p->sctp_local_q,
794                                         cp->ip, status);
795                 }
796         }
797 }
798
799 static void
800 app_check_link(struct app_params *app)
801 {
802         uint32_t all_links_up, i;
803
804         all_links_up = 1;
805
806         for (i = 0; i < app->n_links; i++) {
807                 struct app_link_params *p = &app->link_params[i];
808                 struct rte_eth_link link_params;
809
810                 memset(&link_params, 0, sizeof(link_params));
811                 rte_eth_link_get(p->pmd_id, &link_params);
812
813                 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
814                         p->name,
815                         p->pmd_id,
816                         link_params.link_speed / 1000,
817                         link_params.link_status ? "UP" : "DOWN");
818
819                 if (link_params.link_status == ETH_LINK_DOWN)
820                         all_links_up = 0;
821         }
822
823         if (all_links_up == 0)
824                 rte_panic("Some links are DOWN\n");
825 }
826
827 static uint32_t
828 is_any_swq_frag_or_ras(struct app_params *app)
829 {
830         uint32_t i;
831
832         for (i = 0; i < app->n_pktq_swq; i++) {
833                 struct app_pktq_swq_params *p = &app->swq_params[i];
834
835                 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
836                         (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
837                         return 1;
838         }
839
840         return 0;
841 }
842
843 static void
844 app_init_link_frag_ras(struct app_params *app)
845 {
846         uint32_t i;
847
848         if (is_any_swq_frag_or_ras(app)) {
849                 for (i = 0; i < app->n_links; i++) {
850                         struct app_link_params *p_link = &app->link_params[i];
851                                 p_link->conf.txmode.offloads |=
852                                                 DEV_TX_OFFLOAD_MULTI_SEGS;
853                 }
854         }
855 }
856
857 static inline int
858 app_get_cpu_socket_id(uint32_t pmd_id)
859 {
860         int status = rte_eth_dev_socket_id(pmd_id);
861
862         return (status != SOCKET_ID_ANY) ? status : 0;
863 }
864
865 static inline int
866 app_link_rss_enabled(struct app_link_params *cp)
867 {
868         return (cp->n_rss_qs) ? 1 : 0;
869 }
870
871 static void
872 app_link_rss_setup(struct app_link_params *cp)
873 {
874         struct rte_eth_dev_info dev_info;
875         struct rte_eth_rss_reta_entry64 reta_conf[APP_RETA_SIZE_MAX];
876         uint32_t i;
877         int status;
878
879     /* Get RETA size */
880         memset(&dev_info, 0, sizeof(dev_info));
881         rte_eth_dev_info_get(cp->pmd_id, &dev_info);
882
883         if (dev_info.reta_size == 0)
884                 rte_panic("%s (%u): RSS setup error (null RETA size)\n",
885                         cp->name, cp->pmd_id);
886
887         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512)
888                 rte_panic("%s (%u): RSS setup error (RETA size too big)\n",
889                         cp->name, cp->pmd_id);
890
891         /* Setup RETA contents */
892         memset(reta_conf, 0, sizeof(reta_conf));
893
894         for (i = 0; i < dev_info.reta_size; i++)
895                 reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX;
896
897         for (i = 0; i < dev_info.reta_size; i++) {
898                 uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
899                 uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
900                 uint32_t rss_qs_pos = i % cp->n_rss_qs;
901
902                 reta_conf[reta_id].reta[reta_pos] =
903                         (uint16_t) cp->rss_qs[rss_qs_pos];
904         }
905
906         /* RETA update */
907         status = rte_eth_dev_rss_reta_update(cp->pmd_id,
908                 reta_conf,
909                 dev_info.reta_size);
910         if (status != 0)
911                 rte_panic("%s (%u): RSS setup error (RETA update failed)\n",
912                         cp->name, cp->pmd_id);
913 }
914
915 static void
916 app_init_link_set_config(struct app_link_params *p)
917 {
918         if (p->n_rss_qs) {
919                 p->conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
920                 p->conf.rx_adv_conf.rss_conf.rss_hf = p->rss_proto_ipv4 |
921                         p->rss_proto_ipv6 |
922                         p->rss_proto_l2;
923         }
924 }
925
926 static void
927 app_init_link(struct app_params *app)
928 {
929         uint32_t i;
930
931         app_init_link_frag_ras(app);
932
933         for (i = 0; i < app->n_links; i++) {
934                 struct app_link_params *p_link = &app->link_params[i];
935                 struct rte_eth_dev_info dev_info;
936                 uint32_t link_id, n_hwq_in, n_hwq_out, j;
937                 int status;
938
939                 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
940                 n_hwq_in = app_link_get_n_rxq(app, p_link);
941                 n_hwq_out = app_link_get_n_txq(app, p_link);
942                 app_init_link_set_config(p_link);
943
944                 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
945                         "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
946                         p_link->name,
947                         p_link->pmd_id,
948                         n_hwq_in,
949                         n_hwq_out);
950
951                 /* LINK */
952                 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
953                 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
954                         p_link->conf.txmode.offloads |=
955                                 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
956                 status = rte_eth_dev_configure(
957                         p_link->pmd_id,
958                         n_hwq_in,
959                         n_hwq_out,
960                         &p_link->conf);
961                 if (status < 0)
962                         rte_panic("%s (%" PRId32 "): "
963                                 "init error (%" PRId32 ")\n",
964                                 p_link->name, p_link->pmd_id, status);
965
966                 rte_eth_macaddr_get(p_link->pmd_id,
967                         (struct ether_addr *) &p_link->mac_addr);
968
969                 if (p_link->promisc)
970                         rte_eth_promiscuous_enable(p_link->pmd_id);
971
972                 /* RXQ */
973                 for (j = 0; j < app->n_pktq_hwq_in; j++) {
974                         struct app_pktq_hwq_in_params *p_rxq =
975                                 &app->hwq_in_params[j];
976                         uint32_t rxq_link_id, rxq_queue_id;
977                         uint16_t nb_rxd = p_rxq->size;
978
979                         sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
980                                 &rxq_link_id, &rxq_queue_id);
981                         if (rxq_link_id != link_id)
982                                 continue;
983
984                         status = rte_eth_dev_adjust_nb_rx_tx_desc(
985                                 p_link->pmd_id,
986                                 &nb_rxd,
987                                 NULL);
988                         if (status < 0)
989                                 rte_panic("%s (%" PRIu32 "): "
990                                         "%s adjust number of Rx descriptors "
991                                         "error (%" PRId32 ")\n",
992                                         p_link->name,
993                                         p_link->pmd_id,
994                                         p_rxq->name,
995                                         status);
996
997                         p_rxq->conf.offloads = p_link->conf.rxmode.offloads;
998                         status = rte_eth_rx_queue_setup(
999                                 p_link->pmd_id,
1000                                 rxq_queue_id,
1001                                 nb_rxd,
1002                                 app_get_cpu_socket_id(p_link->pmd_id),
1003                                 &p_rxq->conf,
1004                                 app->mempool[p_rxq->mempool_id]);
1005                         if (status < 0)
1006                                 rte_panic("%s (%" PRIu32 "): "
1007                                         "%s init error (%" PRId32 ")\n",
1008                                         p_link->name,
1009                                         p_link->pmd_id,
1010                                         p_rxq->name,
1011                                         status);
1012                 }
1013
1014                 /* TXQ */
1015                 for (j = 0; j < app->n_pktq_hwq_out; j++) {
1016                         struct app_pktq_hwq_out_params *p_txq =
1017                                 &app->hwq_out_params[j];
1018                         uint32_t txq_link_id, txq_queue_id;
1019                         uint16_t nb_txd = p_txq->size;
1020
1021                         sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
1022                                 &txq_link_id, &txq_queue_id);
1023                         if (txq_link_id != link_id)
1024                                 continue;
1025
1026                         status = rte_eth_dev_adjust_nb_rx_tx_desc(
1027                                 p_link->pmd_id,
1028                                 NULL,
1029                                 &nb_txd);
1030                         if (status < 0)
1031                                 rte_panic("%s (%" PRIu32 "): "
1032                                         "%s adjust number of Tx descriptors "
1033                                         "error (%" PRId32 ")\n",
1034                                         p_link->name,
1035                                         p_link->pmd_id,
1036                                         p_txq->name,
1037                                         status);
1038
1039                         p_txq->conf.offloads = p_link->conf.txmode.offloads;
1040                         status = rte_eth_tx_queue_setup(
1041                                 p_link->pmd_id,
1042                                 txq_queue_id,
1043                                 nb_txd,
1044                                 app_get_cpu_socket_id(p_link->pmd_id),
1045                                 &p_txq->conf);
1046                         if (status < 0)
1047                                 rte_panic("%s (%" PRIu32 "): "
1048                                         "%s init error (%" PRId32 ")\n",
1049                                         p_link->name,
1050                                         p_link->pmd_id,
1051                                         p_txq->name,
1052                                         status);
1053                 }
1054
1055                 /* LINK START */
1056                 status = rte_eth_dev_start(p_link->pmd_id);
1057                 if (status < 0)
1058                         rte_panic("Cannot start %s (error %" PRId32 ")\n",
1059                                 p_link->name, status);
1060
1061                 /* LINK FILTERS */
1062                 app_link_set_arp_filter(app, p_link);
1063                 app_link_set_tcp_syn_filter(app, p_link);
1064                 if (app_link_rss_enabled(p_link))
1065                         app_link_rss_setup(p_link);
1066
1067                 /* LINK UP */
1068                 app_link_up_internal(app, p_link);
1069         }
1070
1071         app_check_link(app);
1072 }
1073
1074 static void
1075 app_init_swq(struct app_params *app)
1076 {
1077         uint32_t i;
1078
1079         for (i = 0; i < app->n_pktq_swq; i++) {
1080                 struct app_pktq_swq_params *p = &app->swq_params[i];
1081                 unsigned flags = 0;
1082
1083                 if (app_swq_get_readers(app, p) == 1)
1084                         flags |= RING_F_SC_DEQ;
1085                 if (app_swq_get_writers(app, p) == 1)
1086                         flags |= RING_F_SP_ENQ;
1087
1088                 APP_LOG(app, HIGH, "Initializing %s...", p->name);
1089                 app->swq[i] = rte_ring_create(
1090                                 p->name,
1091                                 p->size,
1092                                 p->cpu_socket_id,
1093                                 flags);
1094
1095                 if (app->swq[i] == NULL)
1096                         rte_panic("%s init error\n", p->name);
1097         }
1098 }
1099
1100 static void
1101 app_init_tm(struct app_params *app)
1102 {
1103         uint32_t i;
1104
1105         for (i = 0; i < app->n_pktq_tm; i++) {
1106                 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
1107                 struct app_link_params *p_link;
1108                 struct rte_eth_link link_eth_params;
1109                 struct rte_sched_port *sched;
1110                 uint32_t n_subports, subport_id;
1111                 int status;
1112
1113                 p_link = app_get_link_for_tm(app, p_tm);
1114                 /* LINK */
1115                 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
1116
1117                 /* TM */
1118                 p_tm->sched_port_params.name = p_tm->name;
1119                 p_tm->sched_port_params.socket =
1120                         app_get_cpu_socket_id(p_link->pmd_id);
1121                 p_tm->sched_port_params.rate =
1122                         (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
1123
1124                 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
1125                 sched = rte_sched_port_config(&p_tm->sched_port_params);
1126                 if (sched == NULL)
1127                         rte_panic("%s init error\n", p_tm->name);
1128                 app->tm[i] = sched;
1129
1130                 /* Subport */
1131                 n_subports = p_tm->sched_port_params.n_subports_per_port;
1132                 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1133                         uint32_t n_pipes_per_subport, pipe_id;
1134
1135                         status = rte_sched_subport_config(sched,
1136                                 subport_id,
1137                                 &p_tm->sched_subport_params[subport_id]);
1138                         if (status)
1139                                 rte_panic("%s subport %" PRIu32
1140                                         " init error (%" PRId32 ")\n",
1141                                         p_tm->name, subport_id, status);
1142
1143                         /* Pipe */
1144                         n_pipes_per_subport =
1145                                 p_tm->sched_port_params.n_pipes_per_subport;
1146                         for (pipe_id = 0;
1147                                 pipe_id < n_pipes_per_subport;
1148                                 pipe_id++) {
1149                                 int profile_id = p_tm->sched_pipe_to_profile[
1150                                         subport_id * APP_MAX_SCHED_PIPES +
1151                                         pipe_id];
1152
1153                                 if (profile_id == -1)
1154                                         continue;
1155
1156                                 status = rte_sched_pipe_config(sched,
1157                                         subport_id,
1158                                         pipe_id,
1159                                         profile_id);
1160                                 if (status)
1161                                         rte_panic("%s subport %" PRIu32
1162                                                 " pipe %" PRIu32
1163                                                 " (profile %" PRId32 ") "
1164                                                 "init error (% " PRId32 ")\n",
1165                                                 p_tm->name, subport_id, pipe_id,
1166                                                 profile_id, status);
1167                         }
1168                 }
1169         }
1170 }
1171
1172 #ifndef RTE_EXEC_ENV_LINUXAPP
1173 static void
1174 app_init_tap(struct app_params *app) {
1175         if (app->n_pktq_tap == 0)
1176                 return;
1177
1178         rte_panic("TAP device not supported.\n");
1179 }
1180 #else
1181 static void
1182 app_init_tap(struct app_params *app)
1183 {
1184         uint32_t i;
1185
1186         for (i = 0; i < app->n_pktq_tap; i++) {
1187                 struct app_pktq_tap_params *p_tap = &app->tap_params[i];
1188                 struct ifreq ifr;
1189                 int fd, status;
1190
1191                 APP_LOG(app, HIGH, "Initializing %s ...", p_tap->name);
1192
1193                 fd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
1194                 if (fd < 0)
1195                         rte_panic("Cannot open file /dev/net/tun\n");
1196
1197                 memset(&ifr, 0, sizeof(ifr));
1198                 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
1199                 snprintf(ifr.ifr_name, IFNAMSIZ, "%s", p_tap->name);
1200
1201                 status = ioctl(fd, TUNSETIFF, (void *) &ifr);
1202                 if (status < 0)
1203                         rte_panic("TAP setup error\n");
1204
1205                 app->tap[i] = fd;
1206         }
1207 }
1208 #endif
1209
1210 #ifdef RTE_LIBRTE_KNI
1211 static int
1212 kni_config_network_interface(uint16_t port_id, uint8_t if_up) {
1213         int ret = 0;
1214
1215         if (port_id >= rte_eth_dev_count())
1216                 return -EINVAL;
1217
1218         ret = (if_up) ?
1219                 rte_eth_dev_set_link_up(port_id) :
1220                 rte_eth_dev_set_link_down(port_id);
1221
1222         return ret;
1223 }
1224
1225 static int
1226 kni_change_mtu(uint16_t port_id, unsigned int new_mtu) {
1227         int ret;
1228
1229         if (port_id >= rte_eth_dev_count())
1230                 return -EINVAL;
1231
1232         if (new_mtu > ETHER_MAX_LEN)
1233                 return -EINVAL;
1234
1235         /* Set new MTU */
1236         ret = rte_eth_dev_set_mtu(port_id, new_mtu);
1237         if (ret < 0)
1238                 return ret;
1239
1240         return 0;
1241 }
1242 #endif /* RTE_LIBRTE_KNI */
1243
1244 #ifndef RTE_LIBRTE_KNI
1245 static void
1246 app_init_kni(struct app_params *app) {
1247         if (app->n_pktq_kni == 0)
1248                 return;
1249
1250         rte_panic("Can not init KNI without librte_kni support.\n");
1251 }
1252 #else
1253 static void
1254 app_init_kni(struct app_params *app) {
1255         uint32_t i;
1256
1257         if (app->n_pktq_kni == 0)
1258                 return;
1259
1260         rte_kni_init(app->n_pktq_kni);
1261
1262         for (i = 0; i < app->n_pktq_kni; i++) {
1263                 struct app_pktq_kni_params *p_kni = &app->kni_params[i];
1264                 struct app_link_params *p_link;
1265                 struct rte_eth_dev_info dev_info;
1266                 struct app_mempool_params *mempool_params;
1267                 struct rte_mempool *mempool;
1268                 struct rte_kni_conf conf;
1269                 struct rte_kni_ops ops;
1270
1271                 /* LINK */
1272                 p_link = app_get_link_for_kni(app, p_kni);
1273                 memset(&dev_info, 0, sizeof(dev_info));
1274                 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
1275
1276                 /* MEMPOOL */
1277                 mempool_params = &app->mempool_params[p_kni->mempool_id];
1278                 mempool = app->mempool[p_kni->mempool_id];
1279
1280                 /* KNI */
1281                 memset(&conf, 0, sizeof(conf));
1282                 snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", p_kni->name);
1283                 conf.force_bind = p_kni->force_bind;
1284                 if (conf.force_bind) {
1285                         int lcore_id;
1286
1287                         lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1288                                 p_kni->socket_id,
1289                                 p_kni->core_id,
1290                                 p_kni->hyper_th_id);
1291
1292                         if (lcore_id < 0)
1293                                 rte_panic("%s invalid CPU core\n", p_kni->name);
1294
1295                         conf.core_id = (uint32_t) lcore_id;
1296                 }
1297                 conf.group_id = p_link->pmd_id;
1298                 conf.mbuf_size = mempool_params->buffer_size;
1299                 conf.addr = dev_info.pci_dev->addr;
1300                 conf.id = dev_info.pci_dev->id;
1301
1302                 memset(&ops, 0, sizeof(ops));
1303                 ops.port_id = (uint8_t) p_link->pmd_id;
1304                 ops.change_mtu = kni_change_mtu;
1305                 ops.config_network_if = kni_config_network_interface;
1306
1307                 APP_LOG(app, HIGH, "Initializing %s ...", p_kni->name);
1308                 app->kni[i] = rte_kni_alloc(mempool, &conf, &ops);
1309                 if (!app->kni[i])
1310                         rte_panic("%s init error\n", p_kni->name);
1311         }
1312 }
1313 #endif /* RTE_LIBRTE_KNI */
1314
1315 static void
1316 app_init_msgq(struct app_params *app)
1317 {
1318         uint32_t i;
1319
1320         for (i = 0; i < app->n_msgq; i++) {
1321                 struct app_msgq_params *p = &app->msgq_params[i];
1322
1323                 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1324                 app->msgq[i] = rte_ring_create(
1325                                 p->name,
1326                                 p->size,
1327                                 p->cpu_socket_id,
1328                                 RING_F_SP_ENQ | RING_F_SC_DEQ);
1329
1330                 if (app->msgq[i] == NULL)
1331                         rte_panic("%s init error\n", p->name);
1332         }
1333 }
1334
1335 void app_pipeline_params_get(struct app_params *app,
1336         struct app_pipeline_params *p_in,
1337         struct pipeline_params *p_out)
1338 {
1339         uint32_t i;
1340
1341         snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1342
1343         snprintf(p_out->type, PIPELINE_TYPE_SIZE, "%s", p_in->type);
1344
1345         p_out->socket_id = (int) p_in->socket_id;
1346
1347         p_out->log_level = app->log_level;
1348
1349         /* pktq_in */
1350         p_out->n_ports_in = p_in->n_pktq_in;
1351         for (i = 0; i < p_in->n_pktq_in; i++) {
1352                 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1353                 struct pipeline_port_in_params *out = &p_out->port_in[i];
1354
1355                 switch (in->type) {
1356                 case APP_PKTQ_IN_HWQ:
1357                 {
1358                         struct app_pktq_hwq_in_params *p_hwq_in =
1359                                 &app->hwq_in_params[in->id];
1360                         struct app_link_params *p_link =
1361                                 app_get_link_for_rxq(app, p_hwq_in);
1362                         uint32_t rxq_link_id, rxq_queue_id;
1363
1364                         sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1365                                 &rxq_link_id,
1366                                 &rxq_queue_id);
1367
1368                         out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1369                         out->params.ethdev.port_id = p_link->pmd_id;
1370                         out->params.ethdev.queue_id = rxq_queue_id;
1371                         out->burst_size = p_hwq_in->burst;
1372                         break;
1373                 }
1374                 case APP_PKTQ_IN_SWQ:
1375                 {
1376                         struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1377
1378                         if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1379                                 if (app_swq_get_readers(app, swq_params) == 1) {
1380                                         out->type = PIPELINE_PORT_IN_RING_READER;
1381                                         out->params.ring.ring = app->swq[in->id];
1382                                         out->burst_size = app->swq_params[in->id].burst_read;
1383                                 } else {
1384                                         out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1385                                         out->params.ring_multi.ring = app->swq[in->id];
1386                                         out->burst_size = swq_params->burst_read;
1387                                 }
1388                         } else {
1389                                 if (swq_params->ipv4_frag == 1) {
1390                                         struct rte_port_ring_reader_ipv4_frag_params *params =
1391                                                 &out->params.ring_ipv4_frag;
1392
1393                                         out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1394                                         params->ring = app->swq[in->id];
1395                                         params->mtu = swq_params->mtu;
1396                                         params->metadata_size = swq_params->metadata_size;
1397                                         params->pool_direct =
1398                                                 app->mempool[swq_params->mempool_direct_id];
1399                                         params->pool_indirect =
1400                                                 app->mempool[swq_params->mempool_indirect_id];
1401                                         out->burst_size = swq_params->burst_read;
1402                                 } else {
1403                                         struct rte_port_ring_reader_ipv6_frag_params *params =
1404                                                 &out->params.ring_ipv6_frag;
1405
1406                                         out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1407                                         params->ring = app->swq[in->id];
1408                                         params->mtu = swq_params->mtu;
1409                                         params->metadata_size = swq_params->metadata_size;
1410                                         params->pool_direct =
1411                                                 app->mempool[swq_params->mempool_direct_id];
1412                                         params->pool_indirect =
1413                                                 app->mempool[swq_params->mempool_indirect_id];
1414                                         out->burst_size = swq_params->burst_read;
1415                                 }
1416                         }
1417                         break;
1418                 }
1419                 case APP_PKTQ_IN_TM:
1420                 {
1421                         out->type = PIPELINE_PORT_IN_SCHED_READER;
1422                         out->params.sched.sched = app->tm[in->id];
1423                         out->burst_size = app->tm_params[in->id].burst_read;
1424                         break;
1425                 }
1426 #ifdef RTE_EXEC_ENV_LINUXAPP
1427                 case APP_PKTQ_IN_TAP:
1428                 {
1429                         struct app_pktq_tap_params *tap_params =
1430                                 &app->tap_params[in->id];
1431                         struct app_mempool_params *mempool_params =
1432                                 &app->mempool_params[tap_params->mempool_id];
1433                         struct rte_mempool *mempool =
1434                                 app->mempool[tap_params->mempool_id];
1435
1436                         out->type = PIPELINE_PORT_IN_FD_READER;
1437                         out->params.fd.fd = app->tap[in->id];
1438                         out->params.fd.mtu = mempool_params->buffer_size;
1439                         out->params.fd.mempool = mempool;
1440                         out->burst_size = app->tap_params[in->id].burst_read;
1441                         break;
1442                 }
1443 #endif
1444 #ifdef RTE_LIBRTE_KNI
1445                 case APP_PKTQ_IN_KNI:
1446                 {
1447                         out->type = PIPELINE_PORT_IN_KNI_READER;
1448                         out->params.kni.kni = app->kni[in->id];
1449                         out->burst_size = app->kni_params[in->id].burst_read;
1450                         break;
1451                 }
1452 #endif /* RTE_LIBRTE_KNI */
1453                 case APP_PKTQ_IN_SOURCE:
1454                 {
1455                         uint32_t mempool_id =
1456                                 app->source_params[in->id].mempool_id;
1457
1458                         out->type = PIPELINE_PORT_IN_SOURCE;
1459                         out->params.source.mempool = app->mempool[mempool_id];
1460                         out->burst_size = app->source_params[in->id].burst;
1461                         out->params.source.file_name =
1462                                 app->source_params[in->id].file_name;
1463                         out->params.source.n_bytes_per_pkt =
1464                                 app->source_params[in->id].n_bytes_per_pkt;
1465                         break;
1466                 }
1467                 default:
1468                         break;
1469                 }
1470         }
1471
1472         /* pktq_out */
1473         p_out->n_ports_out = p_in->n_pktq_out;
1474         for (i = 0; i < p_in->n_pktq_out; i++) {
1475                 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1476                 struct pipeline_port_out_params *out = &p_out->port_out[i];
1477
1478                 switch (in->type) {
1479                 case APP_PKTQ_OUT_HWQ:
1480                 {
1481                         struct app_pktq_hwq_out_params *p_hwq_out =
1482                                 &app->hwq_out_params[in->id];
1483                         struct app_link_params *p_link =
1484                                 app_get_link_for_txq(app, p_hwq_out);
1485                         uint32_t txq_link_id, txq_queue_id;
1486
1487                         sscanf(p_hwq_out->name,
1488                                 "TXQ%" SCNu32 ".%" SCNu32,
1489                                 &txq_link_id,
1490                                 &txq_queue_id);
1491
1492                         if (p_hwq_out->dropless == 0) {
1493                                 struct rte_port_ethdev_writer_params *params =
1494                                         &out->params.ethdev;
1495
1496                                 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1497                                 params->port_id = p_link->pmd_id;
1498                                 params->queue_id = txq_queue_id;
1499                                 params->tx_burst_sz =
1500                                         app->hwq_out_params[in->id].burst;
1501                         } else {
1502                                 struct rte_port_ethdev_writer_nodrop_params
1503                                         *params = &out->params.ethdev_nodrop;
1504
1505                                 out->type =
1506                                         PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1507                                 params->port_id = p_link->pmd_id;
1508                                 params->queue_id = txq_queue_id;
1509                                 params->tx_burst_sz = p_hwq_out->burst;
1510                                 params->n_retries = p_hwq_out->n_retries;
1511                         }
1512                         break;
1513                 }
1514                 case APP_PKTQ_OUT_SWQ:
1515                 {
1516                         struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1517
1518                         if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1519                                 if (app_swq_get_writers(app, swq_params) == 1) {
1520                                         if (app->swq_params[in->id].dropless == 0) {
1521                                                 struct rte_port_ring_writer_params *params =
1522                                                         &out->params.ring;
1523
1524                                                 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1525                                                 params->ring = app->swq[in->id];
1526                                                 params->tx_burst_sz =
1527                                                         app->swq_params[in->id].burst_write;
1528                                         } else {
1529                                                 struct rte_port_ring_writer_nodrop_params
1530                                                         *params = &out->params.ring_nodrop;
1531
1532                                                 out->type =
1533                                                         PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1534                                                 params->ring = app->swq[in->id];
1535                                                 params->tx_burst_sz =
1536                                                         app->swq_params[in->id].burst_write;
1537                                                 params->n_retries =
1538                                                         app->swq_params[in->id].n_retries;
1539                                         }
1540                                 } else {
1541                                         if (swq_params->dropless == 0) {
1542                                                 struct rte_port_ring_multi_writer_params *params =
1543                                                         &out->params.ring_multi;
1544
1545                                                 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1546                                                 params->ring = app->swq[in->id];
1547                                                 params->tx_burst_sz = swq_params->burst_write;
1548                                         } else {
1549                                                 struct rte_port_ring_multi_writer_nodrop_params
1550                                                         *params = &out->params.ring_multi_nodrop;
1551
1552                                                 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1553                                                 params->ring = app->swq[in->id];
1554                                                 params->tx_burst_sz = swq_params->burst_write;
1555                                                 params->n_retries = swq_params->n_retries;
1556                                         }
1557                                 }
1558                         } else {
1559                                 if (swq_params->ipv4_ras == 1) {
1560                                         struct rte_port_ring_writer_ipv4_ras_params *params =
1561                                                 &out->params.ring_ipv4_ras;
1562
1563                                         out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1564                                         params->ring = app->swq[in->id];
1565                                         params->tx_burst_sz = swq_params->burst_write;
1566                                 } else {
1567                                         struct rte_port_ring_writer_ipv6_ras_params *params =
1568                                                 &out->params.ring_ipv6_ras;
1569
1570                                         out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1571                                         params->ring = app->swq[in->id];
1572                                         params->tx_burst_sz = swq_params->burst_write;
1573                                 }
1574                         }
1575                         break;
1576                 }
1577                 case APP_PKTQ_OUT_TM:
1578                 {
1579                         struct rte_port_sched_writer_params *params =
1580                                 &out->params.sched;
1581
1582                         out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1583                         params->sched = app->tm[in->id];
1584                         params->tx_burst_sz =
1585                                 app->tm_params[in->id].burst_write;
1586                         break;
1587                 }
1588 #ifdef RTE_EXEC_ENV_LINUXAPP
1589                 case APP_PKTQ_OUT_TAP:
1590                 {
1591                         struct rte_port_fd_writer_params *params =
1592                                 &out->params.fd;
1593
1594                         out->type = PIPELINE_PORT_OUT_FD_WRITER;
1595                         params->fd = app->tap[in->id];
1596                         params->tx_burst_sz =
1597                                 app->tap_params[in->id].burst_write;
1598                         break;
1599                 }
1600 #endif
1601 #ifdef RTE_LIBRTE_KNI
1602                 case APP_PKTQ_OUT_KNI:
1603                 {
1604                         struct app_pktq_kni_params *p_kni =
1605                                 &app->kni_params[in->id];
1606
1607                         if (p_kni->dropless == 0) {
1608                                 struct rte_port_kni_writer_params *params =
1609                                         &out->params.kni;
1610
1611                                 out->type = PIPELINE_PORT_OUT_KNI_WRITER;
1612                                 params->kni = app->kni[in->id];
1613                                 params->tx_burst_sz =
1614                                         app->kni_params[in->id].burst_write;
1615                         } else {
1616                                 struct rte_port_kni_writer_nodrop_params
1617                                         *params = &out->params.kni_nodrop;
1618
1619                                 out->type = PIPELINE_PORT_OUT_KNI_WRITER_NODROP;
1620                                 params->kni = app->kni[in->id];
1621                                 params->tx_burst_sz =
1622                                         app->kni_params[in->id].burst_write;
1623                                 params->n_retries =
1624                                         app->kni_params[in->id].n_retries;
1625                         }
1626                         break;
1627                 }
1628 #endif /* RTE_LIBRTE_KNI */
1629                 case APP_PKTQ_OUT_SINK:
1630                 {
1631                         out->type = PIPELINE_PORT_OUT_SINK;
1632                         out->params.sink.file_name =
1633                                 app->sink_params[in->id].file_name;
1634                         out->params.sink.max_n_pkts =
1635                                 app->sink_params[in->id].
1636                                 n_pkts_to_dump;
1637
1638                         break;
1639                 }
1640                 default:
1641                         break;
1642                 }
1643         }
1644
1645         /* msgq */
1646         p_out->n_msgq = p_in->n_msgq_in;
1647
1648         for (i = 0; i < p_in->n_msgq_in; i++)
1649                 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1650
1651         for (i = 0; i < p_in->n_msgq_out; i++)
1652                 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1653
1654         /* args */
1655         p_out->n_args = p_in->n_args;
1656         for (i = 0; i < p_in->n_args; i++) {
1657                 p_out->args_name[i] = p_in->args_name[i];
1658                 p_out->args_value[i] = p_in->args_value[i];
1659         }
1660 }
1661
1662 static void
1663 app_init_pipelines(struct app_params *app)
1664 {
1665         uint32_t p_id;
1666
1667         for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1668                 struct app_pipeline_params *params =
1669                         &app->pipeline_params[p_id];
1670                 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1671                 struct pipeline_type *ptype;
1672                 struct pipeline_params pp;
1673
1674                 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1675
1676                 ptype = app_pipeline_type_find(app, params->type);
1677                 if (ptype == NULL)
1678                         rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1679                                 params->type);
1680
1681                 app_pipeline_params_get(app, params, &pp);
1682
1683                 /* Back-end */
1684                 data->be = NULL;
1685                 if (ptype->be_ops->f_init) {
1686                         data->be = ptype->be_ops->f_init(&pp, (void *) app);
1687
1688                         if (data->be == NULL)
1689                                 rte_panic("Pipeline instance \"%s\" back-end "
1690                                         "init error\n", params->name);
1691                 }
1692
1693                 /* Front-end */
1694                 data->fe = NULL;
1695                 if (ptype->fe_ops->f_init) {
1696                         data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1697
1698                         if (data->fe == NULL)
1699                                 rte_panic("Pipeline instance \"%s\" front-end "
1700                                 "init error\n", params->name);
1701                 }
1702
1703                 data->ptype = ptype;
1704
1705                 data->timer_period = (rte_get_tsc_hz() *
1706                         params->timer_period) / 1000;
1707         }
1708 }
1709
1710 static void
1711 app_post_init_pipelines(struct app_params *app)
1712 {
1713         uint32_t p_id;
1714
1715         for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1716                 struct app_pipeline_params *params =
1717                         &app->pipeline_params[p_id];
1718                 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1719                 int status;
1720
1721                 if (data->ptype->fe_ops->f_post_init == NULL)
1722                         continue;
1723
1724                 status = data->ptype->fe_ops->f_post_init(data->fe);
1725                 if (status)
1726                         rte_panic("Pipeline instance \"%s\" front-end "
1727                                 "post-init error\n", params->name);
1728         }
1729 }
1730
1731 static void
1732 app_init_threads(struct app_params *app)
1733 {
1734         uint64_t time = rte_get_tsc_cycles();
1735         uint32_t p_id;
1736
1737         for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1738                 struct app_pipeline_params *params =
1739                         &app->pipeline_params[p_id];
1740                 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1741                 struct pipeline_type *ptype;
1742                 struct app_thread_data *t;
1743                 struct app_thread_pipeline_data *p;
1744                 int lcore_id;
1745
1746                 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1747                         params->socket_id,
1748                         params->core_id,
1749                         params->hyper_th_id);
1750
1751                 if (lcore_id < 0)
1752                         rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1753                                 params->socket_id,
1754                                 params->core_id,
1755                                 (params->hyper_th_id) ? "h" : "");
1756
1757                 t = &app->thread_data[lcore_id];
1758
1759                 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1760                 t->thread_req_deadline = time + t->timer_period;
1761
1762                 t->headroom_cycles = 0;
1763                 t->headroom_time = rte_get_tsc_cycles();
1764                 t->headroom_ratio = 0.0;
1765
1766                 t->msgq_in = app_thread_msgq_in_get(app,
1767                                 params->socket_id,
1768                                 params->core_id,
1769                                 params->hyper_th_id);
1770                 if (t->msgq_in == NULL)
1771                         rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1772                                 lcore_id);
1773
1774                 t->msgq_out = app_thread_msgq_out_get(app,
1775                                 params->socket_id,
1776                                 params->core_id,
1777                                 params->hyper_th_id);
1778                 if (t->msgq_out == NULL)
1779                         rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1780                                 lcore_id);
1781
1782                 ptype = app_pipeline_type_find(app, params->type);
1783                 if (ptype == NULL)
1784                         rte_panic("Init error: Unknown pipeline "
1785                                 "type \"%s\"\n", params->type);
1786
1787                 p = (ptype->be_ops->f_run == NULL) ?
1788                         &t->regular[t->n_regular] :
1789                         &t->custom[t->n_custom];
1790
1791                 p->pipeline_id = p_id;
1792                 p->be = data->be;
1793                 p->f_run = ptype->be_ops->f_run;
1794                 p->f_timer = ptype->be_ops->f_timer;
1795                 p->timer_period = data->timer_period;
1796                 p->deadline = time + data->timer_period;
1797
1798                 data->enabled = 1;
1799
1800                 if (ptype->be_ops->f_run == NULL)
1801                         t->n_regular++;
1802                 else
1803                         t->n_custom++;
1804         }
1805 }
1806
1807 int app_init(struct app_params *app)
1808 {
1809         app_init_core_map(app);
1810         app_init_core_mask(app);
1811
1812         app_init_eal(app);
1813         app_init_mempool(app);
1814         app_init_link(app);
1815         app_init_swq(app);
1816         app_init_tm(app);
1817         app_init_tap(app);
1818         app_init_kni(app);
1819         app_init_msgq(app);
1820
1821         app_pipeline_common_cmd_push(app);
1822         app_pipeline_thread_cmd_push(app);
1823         app_pipeline_type_register(app, &pipeline_master);
1824         app_pipeline_type_register(app, &pipeline_flow_classification);
1825         app_pipeline_type_register(app, &pipeline_flow_actions);
1826         app_pipeline_type_register(app, &pipeline_firewall);
1827         app_pipeline_type_register(app, &pipeline_routing);
1828
1829         app_init_pipelines(app);
1830         app_init_threads(app);
1831
1832         return 0;
1833 }
1834
1835 int app_post_init(struct app_params *app)
1836 {
1837         app_post_init_pipelines(app);
1838
1839         return 0;
1840 }
1841
1842 static int
1843 app_pipeline_type_cmd_push(struct app_params *app,
1844         struct pipeline_type *ptype)
1845 {
1846         cmdline_parse_ctx_t *cmds;
1847         uint32_t n_cmds, i;
1848
1849         /* Check input arguments */
1850         if ((app == NULL) ||
1851                 (ptype == NULL))
1852                 return -EINVAL;
1853
1854         n_cmds = pipeline_type_cmds_count(ptype);
1855         if (n_cmds == 0)
1856                 return 0;
1857
1858         cmds = ptype->fe_ops->cmds;
1859
1860         /* Check for available slots in the application commands array */
1861         if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1862                 return -ENOMEM;
1863
1864         /* Push pipeline commands into the application */
1865         memcpy(&app->cmds[app->n_cmds],
1866                 cmds,
1867                 n_cmds * sizeof(cmdline_parse_ctx_t));
1868
1869         for (i = 0; i < n_cmds; i++)
1870                 app->cmds[app->n_cmds + i]->data = app;
1871
1872         app->n_cmds += n_cmds;
1873         app->cmds[app->n_cmds] = NULL;
1874
1875         return 0;
1876 }
1877
1878 int
1879 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1880 {
1881         uint32_t n_cmds, i;
1882
1883         /* Check input arguments */
1884         if ((app == NULL) ||
1885                 (ptype == NULL) ||
1886                 (ptype->name == NULL) ||
1887                 (strlen(ptype->name) == 0) ||
1888                 (ptype->be_ops->f_init == NULL) ||
1889                 (ptype->be_ops->f_timer == NULL))
1890                 return -EINVAL;
1891
1892         /* Check for duplicate entry */
1893         for (i = 0; i < app->n_pipeline_types; i++)
1894                 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1895                         return -EEXIST;
1896
1897         /* Check for resource availability */
1898         n_cmds = pipeline_type_cmds_count(ptype);
1899         if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1900                 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1901                 return -ENOMEM;
1902
1903         /* Copy pipeline type */
1904         memcpy(&app->pipeline_type[app->n_pipeline_types++],
1905                 ptype,
1906                 sizeof(struct pipeline_type));
1907
1908         /* Copy CLI commands */
1909         if (n_cmds)
1910                 app_pipeline_type_cmd_push(app, ptype);
1911
1912         return 0;
1913 }
1914
1915 struct
1916 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1917 {
1918         uint32_t i;
1919
1920         for (i = 0; i < app->n_pipeline_types; i++)
1921                 if (strcmp(app->pipeline_type[i].name, name) == 0)
1922                         return &app->pipeline_type[i];
1923
1924         return NULL;
1925 }