1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
8 #include <netinet/in.h>
9 #ifdef RTE_EXEC_ENV_LINUXAPP
11 #include <linux/if_tun.h>
14 #include <sys/ioctl.h>
17 #include <rte_cycles.h>
18 #include <rte_ethdev.h>
19 #include <rte_ether.h>
22 #include <rte_malloc.h>
23 #include <rte_bus_pci.h>
28 #define APP_NAME_SIZE 32
30 #define APP_RETA_SIZE_MAX (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE)
33 app_init_core_map(struct app_params *app)
35 APP_LOG(app, HIGH, "Initializing CPU core map ...");
36 app->core_map = cpu_core_map_init(RTE_MAX_NUMA_NODES, RTE_MAX_LCORE,
39 if (app->core_map == NULL)
40 rte_panic("Cannot create CPU core map\n");
42 if (app->log_level >= APP_LOG_LEVEL_LOW)
43 cpu_core_map_print(app->core_map);
46 /* Core Mask String in Hex Representation */
47 #define APP_CORE_MASK_STRING_SIZE ((64 * APP_CORE_MASK_SIZE) / 8 * 2 + 1)
50 app_init_core_mask(struct app_params *app)
53 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
55 for (i = 0; i < app->n_pipelines; i++) {
56 struct app_pipeline_params *p = &app->pipeline_params[i];
59 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
65 rte_panic("Cannot create CPU core mask\n");
67 app_core_enable_in_core_mask(app, lcore_id);
70 app_core_build_core_mask_string(app, core_mask_str);
71 APP_LOG(app, HIGH, "CPU core mask = 0x%s", core_mask_str);
75 app_init_eal(struct app_params *app)
78 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
79 struct app_eal_params *p = &app->eal_params;
84 app->eal_argv[n_args++] = strdup(app->app_name);
86 app_core_build_core_mask_string(app, core_mask_str);
87 snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
88 app->eal_argv[n_args++] = strdup(buffer);
91 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
92 app->eal_argv[n_args++] = strdup(buffer);
95 if (p->master_lcore_present) {
98 "--master-lcore=%" PRIu32,
100 app->eal_argv[n_args++] = strdup(buffer);
103 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
104 app->eal_argv[n_args++] = strdup(buffer);
106 if (p->memory_present) {
107 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
108 app->eal_argv[n_args++] = strdup(buffer);
111 if (p->ranks_present) {
112 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
113 app->eal_argv[n_args++] = strdup(buffer);
116 for (i = 0; i < APP_MAX_LINKS; i++) {
117 if (p->pci_blacklist[i] == NULL)
122 "--pci-blacklist=%s",
123 p->pci_blacklist[i]);
124 app->eal_argv[n_args++] = strdup(buffer);
127 if (app->port_mask != 0)
128 for (i = 0; i < APP_MAX_LINKS; i++) {
129 if (p->pci_whitelist[i] == NULL)
134 "--pci-whitelist=%s",
135 p->pci_whitelist[i]);
136 app->eal_argv[n_args++] = strdup(buffer);
139 for (i = 0; i < app->n_links; i++) {
140 char *pci_bdf = app->link_params[i].pci_bdf;
144 "--pci-whitelist=%s",
146 app->eal_argv[n_args++] = strdup(buffer);
149 for (i = 0; i < APP_MAX_LINKS; i++) {
150 if (p->vdev[i] == NULL)
157 app->eal_argv[n_args++] = strdup(buffer);
160 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
161 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
162 app->eal_argv[n_args++] = strdup(buffer);
170 app->eal_argv[n_args++] = strdup(buffer);
174 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
175 app->eal_argv[n_args++] = strdup(buffer);
178 if (p->log_level_present) {
181 "--log-level=%" PRIu32,
183 app->eal_argv[n_args++] = strdup(buffer);
186 if ((p->version_present) && p->version) {
187 snprintf(buffer, sizeof(buffer), "-v");
188 app->eal_argv[n_args++] = strdup(buffer);
191 if ((p->help_present) && p->help) {
192 snprintf(buffer, sizeof(buffer), "--help");
193 app->eal_argv[n_args++] = strdup(buffer);
196 if ((p->no_huge_present) && p->no_huge) {
197 snprintf(buffer, sizeof(buffer), "--no-huge");
198 app->eal_argv[n_args++] = strdup(buffer);
201 if ((p->no_pci_present) && p->no_pci) {
202 snprintf(buffer, sizeof(buffer), "--no-pci");
203 app->eal_argv[n_args++] = strdup(buffer);
206 if ((p->no_hpet_present) && p->no_hpet) {
207 snprintf(buffer, sizeof(buffer), "--no-hpet");
208 app->eal_argv[n_args++] = strdup(buffer);
211 if ((p->no_shconf_present) && p->no_shconf) {
212 snprintf(buffer, sizeof(buffer), "--no-shconf");
213 app->eal_argv[n_args++] = strdup(buffer);
217 snprintf(buffer, sizeof(buffer), "-d%s", p->add_driver);
218 app->eal_argv[n_args++] = strdup(buffer);
226 app->eal_argv[n_args++] = strdup(buffer);
230 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
231 app->eal_argv[n_args++] = strdup(buffer);
234 if (p->file_prefix) {
239 app->eal_argv[n_args++] = strdup(buffer);
242 if (p->base_virtaddr) {
245 "--base-virtaddr=%s",
247 app->eal_argv[n_args++] = strdup(buffer);
250 if ((p->create_uio_dev_present) && p->create_uio_dev) {
251 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
252 app->eal_argv[n_args++] = strdup(buffer);
260 app->eal_argv[n_args++] = strdup(buffer);
263 snprintf(buffer, sizeof(buffer), "--");
264 app->eal_argv[n_args++] = strdup(buffer);
266 app->eal_argc = n_args;
268 APP_LOG(app, HIGH, "Initializing EAL ...");
269 if (app->log_level >= APP_LOG_LEVEL_LOW) {
272 fprintf(stdout, "[APP] EAL arguments: \"");
273 for (i = 1; i < app->eal_argc; i++)
274 fprintf(stdout, "%s ", app->eal_argv[i]);
275 fprintf(stdout, "\"\n");
278 status = rte_eal_init(app->eal_argc, app->eal_argv);
280 rte_panic("EAL init error\n");
284 app_init_mempool(struct app_params *app)
288 for (i = 0; i < app->n_mempools; i++) {
289 struct app_mempool_params *p = &app->mempool_params[i];
291 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
292 app->mempool[i] = rte_pktmbuf_pool_create(
298 sizeof(struct rte_mbuf), /* mbuf data size */
301 if (app->mempool[i] == NULL)
302 rte_panic("%s init error\n", p->name);
307 app_link_filter_arp_add(struct app_link_params *link)
309 struct rte_eth_ethertype_filter filter = {
310 .ether_type = ETHER_TYPE_ARP,
312 .queue = link->arp_q,
315 return rte_eth_dev_filter_ctrl(link->pmd_id,
316 RTE_ETH_FILTER_ETHERTYPE,
322 app_link_filter_tcp_syn_add(struct app_link_params *link)
324 struct rte_eth_syn_filter filter = {
326 .queue = link->tcp_syn_q,
329 return rte_eth_dev_filter_ctrl(link->pmd_id,
336 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
338 struct rte_eth_ntuple_filter filter = {
339 .flags = RTE_5TUPLE_FLAGS,
340 .dst_ip = rte_bswap32(l2->ip),
341 .dst_ip_mask = UINT32_MAX, /* Enable */
343 .src_ip_mask = 0, /* Disable */
345 .dst_port_mask = 0, /* Disable */
347 .src_port_mask = 0, /* Disable */
349 .proto_mask = 0, /* Disable */
351 .priority = 1, /* Lowest */
352 .queue = l1->ip_local_q,
355 return rte_eth_dev_filter_ctrl(l1->pmd_id,
356 RTE_ETH_FILTER_NTUPLE,
362 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
364 struct rte_eth_ntuple_filter filter = {
365 .flags = RTE_5TUPLE_FLAGS,
366 .dst_ip = rte_bswap32(l2->ip),
367 .dst_ip_mask = UINT32_MAX, /* Enable */
369 .src_ip_mask = 0, /* Disable */
371 .dst_port_mask = 0, /* Disable */
373 .src_port_mask = 0, /* Disable */
375 .proto_mask = 0, /* Disable */
377 .priority = 1, /* Lowest */
378 .queue = l1->ip_local_q,
381 return rte_eth_dev_filter_ctrl(l1->pmd_id,
382 RTE_ETH_FILTER_NTUPLE,
383 RTE_ETH_FILTER_DELETE,
388 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
390 struct rte_eth_ntuple_filter filter = {
391 .flags = RTE_5TUPLE_FLAGS,
392 .dst_ip = rte_bswap32(l2->ip),
393 .dst_ip_mask = UINT32_MAX, /* Enable */
395 .src_ip_mask = 0, /* Disable */
397 .dst_port_mask = 0, /* Disable */
399 .src_port_mask = 0, /* Disable */
400 .proto = IPPROTO_TCP,
401 .proto_mask = UINT8_MAX, /* Enable */
403 .priority = 2, /* Higher priority than IP */
404 .queue = l1->tcp_local_q,
407 return rte_eth_dev_filter_ctrl(l1->pmd_id,
408 RTE_ETH_FILTER_NTUPLE,
414 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
416 struct rte_eth_ntuple_filter filter = {
417 .flags = RTE_5TUPLE_FLAGS,
418 .dst_ip = rte_bswap32(l2->ip),
419 .dst_ip_mask = UINT32_MAX, /* Enable */
421 .src_ip_mask = 0, /* Disable */
423 .dst_port_mask = 0, /* Disable */
425 .src_port_mask = 0, /* Disable */
426 .proto = IPPROTO_TCP,
427 .proto_mask = UINT8_MAX, /* Enable */
429 .priority = 2, /* Higher priority than IP */
430 .queue = l1->tcp_local_q,
433 return rte_eth_dev_filter_ctrl(l1->pmd_id,
434 RTE_ETH_FILTER_NTUPLE,
435 RTE_ETH_FILTER_DELETE,
440 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
442 struct rte_eth_ntuple_filter filter = {
443 .flags = RTE_5TUPLE_FLAGS,
444 .dst_ip = rte_bswap32(l2->ip),
445 .dst_ip_mask = UINT32_MAX, /* Enable */
447 .src_ip_mask = 0, /* Disable */
449 .dst_port_mask = 0, /* Disable */
451 .src_port_mask = 0, /* Disable */
452 .proto = IPPROTO_UDP,
453 .proto_mask = UINT8_MAX, /* Enable */
455 .priority = 2, /* Higher priority than IP */
456 .queue = l1->udp_local_q,
459 return rte_eth_dev_filter_ctrl(l1->pmd_id,
460 RTE_ETH_FILTER_NTUPLE,
466 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
468 struct rte_eth_ntuple_filter filter = {
469 .flags = RTE_5TUPLE_FLAGS,
470 .dst_ip = rte_bswap32(l2->ip),
471 .dst_ip_mask = UINT32_MAX, /* Enable */
473 .src_ip_mask = 0, /* Disable */
475 .dst_port_mask = 0, /* Disable */
477 .src_port_mask = 0, /* Disable */
478 .proto = IPPROTO_UDP,
479 .proto_mask = UINT8_MAX, /* Enable */
481 .priority = 2, /* Higher priority than IP */
482 .queue = l1->udp_local_q,
485 return rte_eth_dev_filter_ctrl(l1->pmd_id,
486 RTE_ETH_FILTER_NTUPLE,
487 RTE_ETH_FILTER_DELETE,
492 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
494 struct rte_eth_ntuple_filter filter = {
495 .flags = RTE_5TUPLE_FLAGS,
496 .dst_ip = rte_bswap32(l2->ip),
497 .dst_ip_mask = UINT32_MAX, /* Enable */
499 .src_ip_mask = 0, /* Disable */
501 .dst_port_mask = 0, /* Disable */
503 .src_port_mask = 0, /* Disable */
504 .proto = IPPROTO_SCTP,
505 .proto_mask = UINT8_MAX, /* Enable */
507 .priority = 2, /* Higher priority than IP */
508 .queue = l1->sctp_local_q,
511 return rte_eth_dev_filter_ctrl(l1->pmd_id,
512 RTE_ETH_FILTER_NTUPLE,
518 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
520 struct rte_eth_ntuple_filter filter = {
521 .flags = RTE_5TUPLE_FLAGS,
522 .dst_ip = rte_bswap32(l2->ip),
523 .dst_ip_mask = UINT32_MAX, /* Enable */
525 .src_ip_mask = 0, /* Disable */
527 .dst_port_mask = 0, /* Disable */
529 .src_port_mask = 0, /* Disable */
530 .proto = IPPROTO_SCTP,
531 .proto_mask = UINT8_MAX, /* Enable */
533 .priority = 2, /* Higher priority than IP */
534 .queue = l1->sctp_local_q,
537 return rte_eth_dev_filter_ctrl(l1->pmd_id,
538 RTE_ETH_FILTER_NTUPLE,
539 RTE_ETH_FILTER_DELETE,
544 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
546 if (cp->arp_q != 0) {
547 int status = app_link_filter_arp_add(cp);
549 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
550 "Adding ARP filter (queue = %" PRIu32 ")",
551 cp->name, cp->pmd_id, cp->arp_q);
554 rte_panic("%s (%" PRIu32 "): "
555 "Error adding ARP filter "
556 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
557 cp->name, cp->pmd_id, cp->arp_q, status);
562 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
564 if (cp->tcp_syn_q != 0) {
565 int status = app_link_filter_tcp_syn_add(cp);
567 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
568 "Adding TCP SYN filter (queue = %" PRIu32 ")",
569 cp->name, cp->pmd_id, cp->tcp_syn_q);
572 rte_panic("%s (%" PRIu32 "): "
573 "Error adding TCP SYN filter "
574 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
575 cp->name, cp->pmd_id, cp->tcp_syn_q,
581 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
586 /* For each link, add filters for IP of current link */
588 for (i = 0; i < app->n_links; i++) {
589 struct app_link_params *p = &app->link_params[i];
592 if (p->ip_local_q != 0) {
593 int status = app_link_filter_ip_add(p, cp);
595 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
596 "Adding IP filter (queue= %" PRIu32
597 ", IP = 0x%08" PRIx32 ")",
598 p->name, p->pmd_id, p->ip_local_q,
602 rte_panic("%s (%" PRIu32 "): "
604 "filter (queue= %" PRIu32 ", "
608 p->ip_local_q, cp->ip, status);
612 if (p->tcp_local_q != 0) {
613 int status = app_link_filter_tcp_add(p, cp);
615 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
618 ", IP = 0x%08" PRIx32 ")",
619 p->name, p->pmd_id, p->tcp_local_q,
623 rte_panic("%s (%" PRIu32 "): "
625 "filter (queue = %" PRIu32 ", "
629 p->tcp_local_q, cp->ip, status);
633 if (p->udp_local_q != 0) {
634 int status = app_link_filter_udp_add(p, cp);
636 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
639 ", IP = 0x%08" PRIx32 ")",
640 p->name, p->pmd_id, p->udp_local_q,
644 rte_panic("%s (%" PRIu32 "): "
646 "filter (queue = %" PRIu32 ", "
650 p->udp_local_q, cp->ip, status);
654 if (p->sctp_local_q != 0) {
655 int status = app_link_filter_sctp_add(p, cp);
657 APP_LOG(app, LOW, "%s (%" PRIu32
658 "): Adding SCTP filter "
660 ", IP = 0x%08" PRIx32 ")",
661 p->name, p->pmd_id, p->sctp_local_q,
665 rte_panic("%s (%" PRIu32 "): "
667 "filter (queue = %" PRIu32 ", "
671 p->sctp_local_q, cp->ip,
678 status = rte_eth_dev_set_link_up(cp->pmd_id);
679 /* Do not panic if PMD does not provide link up functionality */
680 if (status < 0 && status != -ENOTSUP)
681 rte_panic("%s (%" PRIu32 "): PMD set link up error %"
682 PRId32 "\n", cp->name, cp->pmd_id, status);
684 /* Mark link as UP */
689 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
695 status = rte_eth_dev_set_link_down(cp->pmd_id);
696 /* Do not panic if PMD does not provide link down functionality */
697 if (status < 0 && status != -ENOTSUP)
698 rte_panic("%s (%" PRIu32 "): PMD set link down error %"
699 PRId32 "\n", cp->name, cp->pmd_id, status);
701 /* Mark link as DOWN */
704 /* Return if current link IP is not valid */
708 /* For each link, remove filters for IP of current link */
709 for (i = 0; i < app->n_links; i++) {
710 struct app_link_params *p = &app->link_params[i];
713 if (p->ip_local_q != 0) {
714 int status = app_link_filter_ip_del(p, cp);
716 APP_LOG(app, LOW, "%s (%" PRIu32
717 "): Deleting IP filter "
718 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
719 p->name, p->pmd_id, p->ip_local_q, cp->ip);
722 rte_panic("%s (%" PRIu32
723 "): Error deleting IP filter "
727 p->name, p->pmd_id, p->ip_local_q,
732 if (p->tcp_local_q != 0) {
733 int status = app_link_filter_tcp_del(p, cp);
735 APP_LOG(app, LOW, "%s (%" PRIu32
736 "): Deleting TCP filter "
738 ", IP = 0x%" PRIx32 ")",
739 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
742 rte_panic("%s (%" PRIu32
743 "): Error deleting TCP filter "
747 p->name, p->pmd_id, p->tcp_local_q,
752 if (p->udp_local_q != 0) {
753 int status = app_link_filter_udp_del(p, cp);
755 APP_LOG(app, LOW, "%s (%" PRIu32
756 "): Deleting UDP filter "
757 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
758 p->name, p->pmd_id, p->udp_local_q, cp->ip);
761 rte_panic("%s (%" PRIu32
762 "): Error deleting UDP filter "
766 p->name, p->pmd_id, p->udp_local_q,
771 if (p->sctp_local_q != 0) {
772 int status = app_link_filter_sctp_del(p, cp);
774 APP_LOG(app, LOW, "%s (%" PRIu32
775 "): Deleting SCTP filter "
777 ", IP = 0x%" PRIx32 ")",
778 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
781 rte_panic("%s (%" PRIu32
782 "): Error deleting SCTP filter "
786 p->name, p->pmd_id, p->sctp_local_q,
793 app_check_link(struct app_params *app)
795 uint32_t all_links_up, i;
799 for (i = 0; i < app->n_links; i++) {
800 struct app_link_params *p = &app->link_params[i];
801 struct rte_eth_link link_params;
803 memset(&link_params, 0, sizeof(link_params));
804 rte_eth_link_get(p->pmd_id, &link_params);
806 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
809 link_params.link_speed / 1000,
810 link_params.link_status ? "UP" : "DOWN");
812 if (link_params.link_status == ETH_LINK_DOWN)
816 if (all_links_up == 0)
817 rte_panic("Some links are DOWN\n");
821 is_any_swq_frag_or_ras(struct app_params *app)
825 for (i = 0; i < app->n_pktq_swq; i++) {
826 struct app_pktq_swq_params *p = &app->swq_params[i];
828 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
829 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
837 app_init_link_frag_ras(struct app_params *app)
841 if (is_any_swq_frag_or_ras(app)) {
842 for (i = 0; i < app->n_links; i++) {
843 struct app_link_params *p_link = &app->link_params[i];
844 p_link->conf.txmode.offloads |=
845 DEV_TX_OFFLOAD_MULTI_SEGS;
851 app_get_cpu_socket_id(uint32_t pmd_id)
853 int status = rte_eth_dev_socket_id(pmd_id);
855 return (status != SOCKET_ID_ANY) ? status : 0;
859 app_link_rss_enabled(struct app_link_params *cp)
861 return (cp->n_rss_qs) ? 1 : 0;
865 app_link_rss_setup(struct app_link_params *cp)
867 struct rte_eth_dev_info dev_info;
868 struct rte_eth_rss_reta_entry64 reta_conf[APP_RETA_SIZE_MAX];
873 memset(&dev_info, 0, sizeof(dev_info));
874 rte_eth_dev_info_get(cp->pmd_id, &dev_info);
876 if (dev_info.reta_size == 0)
877 rte_panic("%s (%u): RSS setup error (null RETA size)\n",
878 cp->name, cp->pmd_id);
880 if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512)
881 rte_panic("%s (%u): RSS setup error (RETA size too big)\n",
882 cp->name, cp->pmd_id);
884 /* Setup RETA contents */
885 memset(reta_conf, 0, sizeof(reta_conf));
887 for (i = 0; i < dev_info.reta_size; i++)
888 reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX;
890 for (i = 0; i < dev_info.reta_size; i++) {
891 uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
892 uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
893 uint32_t rss_qs_pos = i % cp->n_rss_qs;
895 reta_conf[reta_id].reta[reta_pos] =
896 (uint16_t) cp->rss_qs[rss_qs_pos];
900 status = rte_eth_dev_rss_reta_update(cp->pmd_id,
904 rte_panic("%s (%u): RSS setup error (RETA update failed)\n",
905 cp->name, cp->pmd_id);
909 app_init_link_set_config(struct app_link_params *p)
912 p->conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
913 p->conf.rx_adv_conf.rss_conf.rss_hf = p->rss_proto_ipv4 |
920 app_init_link(struct app_params *app)
924 app_init_link_frag_ras(app);
926 for (i = 0; i < app->n_links; i++) {
927 struct app_link_params *p_link = &app->link_params[i];
928 struct rte_eth_dev_info dev_info;
929 uint32_t link_id, n_hwq_in, n_hwq_out, j;
932 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
933 n_hwq_in = app_link_get_n_rxq(app, p_link);
934 n_hwq_out = app_link_get_n_txq(app, p_link);
935 app_init_link_set_config(p_link);
937 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
938 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
945 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
946 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
947 p_link->conf.txmode.offloads |=
948 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
949 status = rte_eth_dev_configure(
955 rte_panic("%s (%" PRId32 "): "
956 "init error (%" PRId32 ")\n",
957 p_link->name, p_link->pmd_id, status);
959 rte_eth_macaddr_get(p_link->pmd_id,
960 (struct ether_addr *) &p_link->mac_addr);
963 rte_eth_promiscuous_enable(p_link->pmd_id);
966 for (j = 0; j < app->n_pktq_hwq_in; j++) {
967 struct app_pktq_hwq_in_params *p_rxq =
968 &app->hwq_in_params[j];
969 uint32_t rxq_link_id, rxq_queue_id;
970 uint16_t nb_rxd = p_rxq->size;
972 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
973 &rxq_link_id, &rxq_queue_id);
974 if (rxq_link_id != link_id)
977 status = rte_eth_dev_adjust_nb_rx_tx_desc(
982 rte_panic("%s (%" PRIu32 "): "
983 "%s adjust number of Rx descriptors "
984 "error (%" PRId32 ")\n",
990 p_rxq->conf.offloads = p_link->conf.rxmode.offloads;
991 status = rte_eth_rx_queue_setup(
995 app_get_cpu_socket_id(p_link->pmd_id),
997 app->mempool[p_rxq->mempool_id]);
999 rte_panic("%s (%" PRIu32 "): "
1000 "%s init error (%" PRId32 ")\n",
1008 for (j = 0; j < app->n_pktq_hwq_out; j++) {
1009 struct app_pktq_hwq_out_params *p_txq =
1010 &app->hwq_out_params[j];
1011 uint32_t txq_link_id, txq_queue_id;
1012 uint16_t nb_txd = p_txq->size;
1014 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
1015 &txq_link_id, &txq_queue_id);
1016 if (txq_link_id != link_id)
1019 status = rte_eth_dev_adjust_nb_rx_tx_desc(
1024 rte_panic("%s (%" PRIu32 "): "
1025 "%s adjust number of Tx descriptors "
1026 "error (%" PRId32 ")\n",
1032 p_txq->conf.offloads = p_link->conf.txmode.offloads;
1033 status = rte_eth_tx_queue_setup(
1037 app_get_cpu_socket_id(p_link->pmd_id),
1040 rte_panic("%s (%" PRIu32 "): "
1041 "%s init error (%" PRId32 ")\n",
1049 status = rte_eth_dev_start(p_link->pmd_id);
1051 rte_panic("Cannot start %s (error %" PRId32 ")\n",
1052 p_link->name, status);
1055 app_link_set_arp_filter(app, p_link);
1056 app_link_set_tcp_syn_filter(app, p_link);
1057 if (app_link_rss_enabled(p_link))
1058 app_link_rss_setup(p_link);
1061 app_link_up_internal(app, p_link);
1064 app_check_link(app);
1068 app_init_swq(struct app_params *app)
1072 for (i = 0; i < app->n_pktq_swq; i++) {
1073 struct app_pktq_swq_params *p = &app->swq_params[i];
1076 if (app_swq_get_readers(app, p) == 1)
1077 flags |= RING_F_SC_DEQ;
1078 if (app_swq_get_writers(app, p) == 1)
1079 flags |= RING_F_SP_ENQ;
1081 APP_LOG(app, HIGH, "Initializing %s...", p->name);
1082 app->swq[i] = rte_ring_create(
1088 if (app->swq[i] == NULL)
1089 rte_panic("%s init error\n", p->name);
1094 app_init_tm(struct app_params *app)
1098 for (i = 0; i < app->n_pktq_tm; i++) {
1099 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
1100 struct app_link_params *p_link;
1101 struct rte_eth_link link_eth_params;
1102 struct rte_sched_port *sched;
1103 uint32_t n_subports, subport_id;
1106 p_link = app_get_link_for_tm(app, p_tm);
1108 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
1111 p_tm->sched_port_params.name = p_tm->name;
1112 p_tm->sched_port_params.socket =
1113 app_get_cpu_socket_id(p_link->pmd_id);
1114 p_tm->sched_port_params.rate =
1115 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
1117 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
1118 sched = rte_sched_port_config(&p_tm->sched_port_params);
1120 rte_panic("%s init error\n", p_tm->name);
1124 n_subports = p_tm->sched_port_params.n_subports_per_port;
1125 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1126 uint32_t n_pipes_per_subport, pipe_id;
1128 status = rte_sched_subport_config(sched,
1130 &p_tm->sched_subport_params[subport_id]);
1132 rte_panic("%s subport %" PRIu32
1133 " init error (%" PRId32 ")\n",
1134 p_tm->name, subport_id, status);
1137 n_pipes_per_subport =
1138 p_tm->sched_port_params.n_pipes_per_subport;
1140 pipe_id < n_pipes_per_subport;
1142 int profile_id = p_tm->sched_pipe_to_profile[
1143 subport_id * APP_MAX_SCHED_PIPES +
1146 if (profile_id == -1)
1149 status = rte_sched_pipe_config(sched,
1154 rte_panic("%s subport %" PRIu32
1156 " (profile %" PRId32 ") "
1157 "init error (% " PRId32 ")\n",
1158 p_tm->name, subport_id, pipe_id,
1159 profile_id, status);
1165 #ifndef RTE_EXEC_ENV_LINUXAPP
1167 app_init_tap(struct app_params *app) {
1168 if (app->n_pktq_tap == 0)
1171 rte_panic("TAP device not supported.\n");
1175 app_init_tap(struct app_params *app)
1179 for (i = 0; i < app->n_pktq_tap; i++) {
1180 struct app_pktq_tap_params *p_tap = &app->tap_params[i];
1184 APP_LOG(app, HIGH, "Initializing %s ...", p_tap->name);
1186 fd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
1188 rte_panic("Cannot open file /dev/net/tun\n");
1190 memset(&ifr, 0, sizeof(ifr));
1191 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
1192 snprintf(ifr.ifr_name, IFNAMSIZ, "%s", p_tap->name);
1194 status = ioctl(fd, TUNSETIFF, (void *) &ifr);
1196 rte_panic("TAP setup error\n");
1203 #ifdef RTE_LIBRTE_KNI
1205 kni_config_network_interface(uint16_t port_id, uint8_t if_up) {
1208 if (port_id >= rte_eth_dev_count())
1212 rte_eth_dev_set_link_up(port_id) :
1213 rte_eth_dev_set_link_down(port_id);
1219 kni_change_mtu(uint16_t port_id, unsigned int new_mtu) {
1222 if (port_id >= rte_eth_dev_count())
1225 if (new_mtu > ETHER_MAX_LEN)
1229 ret = rte_eth_dev_set_mtu(port_id, new_mtu);
1235 #endif /* RTE_LIBRTE_KNI */
1237 #ifndef RTE_LIBRTE_KNI
1239 app_init_kni(struct app_params *app) {
1240 if (app->n_pktq_kni == 0)
1243 rte_panic("Can not init KNI without librte_kni support.\n");
1247 app_init_kni(struct app_params *app) {
1250 if (app->n_pktq_kni == 0)
1253 rte_kni_init(app->n_pktq_kni);
1255 for (i = 0; i < app->n_pktq_kni; i++) {
1256 struct app_pktq_kni_params *p_kni = &app->kni_params[i];
1257 struct app_link_params *p_link;
1258 struct rte_eth_dev_info dev_info;
1259 struct app_mempool_params *mempool_params;
1260 struct rte_mempool *mempool;
1261 struct rte_kni_conf conf;
1262 struct rte_kni_ops ops;
1265 p_link = app_get_link_for_kni(app, p_kni);
1266 memset(&dev_info, 0, sizeof(dev_info));
1267 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
1270 mempool_params = &app->mempool_params[p_kni->mempool_id];
1271 mempool = app->mempool[p_kni->mempool_id];
1274 memset(&conf, 0, sizeof(conf));
1275 snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", p_kni->name);
1276 conf.force_bind = p_kni->force_bind;
1277 if (conf.force_bind) {
1280 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1283 p_kni->hyper_th_id);
1286 rte_panic("%s invalid CPU core\n", p_kni->name);
1288 conf.core_id = (uint32_t) lcore_id;
1290 conf.group_id = p_link->pmd_id;
1291 conf.mbuf_size = mempool_params->buffer_size;
1292 conf.addr = dev_info.pci_dev->addr;
1293 conf.id = dev_info.pci_dev->id;
1295 memset(&ops, 0, sizeof(ops));
1296 ops.port_id = (uint8_t) p_link->pmd_id;
1297 ops.change_mtu = kni_change_mtu;
1298 ops.config_network_if = kni_config_network_interface;
1300 APP_LOG(app, HIGH, "Initializing %s ...", p_kni->name);
1301 app->kni[i] = rte_kni_alloc(mempool, &conf, &ops);
1303 rte_panic("%s init error\n", p_kni->name);
1306 #endif /* RTE_LIBRTE_KNI */
1309 app_init_msgq(struct app_params *app)
1313 for (i = 0; i < app->n_msgq; i++) {
1314 struct app_msgq_params *p = &app->msgq_params[i];
1316 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1317 app->msgq[i] = rte_ring_create(
1321 RING_F_SP_ENQ | RING_F_SC_DEQ);
1323 if (app->msgq[i] == NULL)
1324 rte_panic("%s init error\n", p->name);
1328 int app_init(struct app_params *app)
1330 app_init_core_map(app);
1331 app_init_core_mask(app);
1334 app_init_mempool(app);