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