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