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