xref: /dpdk/examples/vm_power_manager/main.c (revision 95f648ff9eedc11f9c888f2cc331aadb95cb9b47)
13998e2a0SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
23998e2a0SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
38db653ffSAlan Carew  */
48db653ffSAlan Carew 
58db653ffSAlan Carew #include <stdio.h>
68db653ffSAlan Carew #include <string.h>
78db653ffSAlan Carew #include <stdint.h>
88db653ffSAlan Carew #include <sys/epoll.h>
98db653ffSAlan Carew #include <fcntl.h>
108db653ffSAlan Carew #include <unistd.h>
118db653ffSAlan Carew #include <stdlib.h>
128db653ffSAlan Carew #include <signal.h>
138db653ffSAlan Carew #include <errno.h>
148db653ffSAlan Carew 
158db653ffSAlan Carew #include <sys/queue.h>
168db653ffSAlan Carew 
178db653ffSAlan Carew #include <rte_common.h>
188db653ffSAlan Carew #include <rte_eal.h>
198db653ffSAlan Carew #include <rte_launch.h>
208db653ffSAlan Carew #include <rte_log.h>
218db653ffSAlan Carew #include <rte_per_lcore.h>
228db653ffSAlan Carew #include <rte_lcore.h>
2320c78ac9SDavid Hunt #include <rte_ethdev.h>
2420c78ac9SDavid Hunt #include <getopt.h>
2520c78ac9SDavid Hunt #include <rte_cycles.h>
268db653ffSAlan Carew #include <rte_debug.h>
278db653ffSAlan Carew 
288db653ffSAlan Carew #include "channel_manager.h"
298db653ffSAlan Carew #include "channel_monitor.h"
308db653ffSAlan Carew #include "power_manager.h"
318db653ffSAlan Carew #include "vm_power_cli.h"
32d42b1300SDavid Hunt #include "oob_monitor.h"
3399a968faSDavid Hunt #include "parse.h"
3470b2c7f1SDavid Christensen #ifdef RTE_LIBRTE_IXGBE_PMD
35c9a47791SDavid Hunt #include <rte_pmd_ixgbe.h>
3670b2c7f1SDavid Christensen #endif
3770b2c7f1SDavid Christensen #ifdef RTE_LIBRTE_I40E_PMD
38c9a47791SDavid Hunt #include <rte_pmd_i40e.h>
3970b2c7f1SDavid Christensen #endif
4070b2c7f1SDavid Christensen #ifdef RTE_LIBRTE_BNXT_PMD
41c9a47791SDavid Hunt #include <rte_pmd_bnxt.h>
4270b2c7f1SDavid Christensen #endif
438db653ffSAlan Carew 
44867a6c66SKevin Laatz #define RX_RING_SIZE 1024
45867a6c66SKevin Laatz #define TX_RING_SIZE 1024
4620c78ac9SDavid Hunt 
4720c78ac9SDavid Hunt #define NUM_MBUFS 8191
4820c78ac9SDavid Hunt #define MBUF_CACHE_SIZE 250
4920c78ac9SDavid Hunt #define BURST_SIZE 32
5020c78ac9SDavid Hunt 
5120c78ac9SDavid Hunt static uint32_t enabled_port_mask;
5220c78ac9SDavid Hunt static volatile bool force_quit;
5320c78ac9SDavid Hunt 
5420c78ac9SDavid Hunt /****************/
5520c78ac9SDavid Hunt static const struct rte_eth_conf port_conf_default = {
56f21e3b88SShahaf Shuler 	.rxmode = {
5735b2d13fSOlivier Matz 		.max_rx_pkt_len = RTE_ETHER_MAX_LEN,
58f21e3b88SShahaf Shuler 	},
5920c78ac9SDavid Hunt };
6020c78ac9SDavid Hunt 
6120c78ac9SDavid Hunt static inline int
6220c78ac9SDavid Hunt port_init(uint16_t port, struct rte_mempool *mbuf_pool)
6320c78ac9SDavid Hunt {
6420c78ac9SDavid Hunt 	struct rte_eth_conf port_conf = port_conf_default;
6520c78ac9SDavid Hunt 	const uint16_t rx_rings = 1, tx_rings = 1;
6620c78ac9SDavid Hunt 	int retval;
6720c78ac9SDavid Hunt 	uint16_t q;
68f21e3b88SShahaf Shuler 	struct rte_eth_dev_info dev_info;
69f21e3b88SShahaf Shuler 	struct rte_eth_txconf txq_conf;
7020c78ac9SDavid Hunt 
71a9dbe180SThomas Monjalon 	if (!rte_eth_dev_is_valid_port(port))
7220c78ac9SDavid Hunt 		return -1;
7320c78ac9SDavid Hunt 
74089e5ed7SIvan Ilchenko 	retval = rte_eth_dev_info_get(port, &dev_info);
75089e5ed7SIvan Ilchenko 	if (retval != 0) {
76089e5ed7SIvan Ilchenko 		printf("Error during getting device (port %u) info: %s\n",
77089e5ed7SIvan Ilchenko 				port, strerror(-retval));
78089e5ed7SIvan Ilchenko 		return retval;
79089e5ed7SIvan Ilchenko 	}
80089e5ed7SIvan Ilchenko 
81f21e3b88SShahaf Shuler 	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
82f21e3b88SShahaf Shuler 		port_conf.txmode.offloads |=
83f21e3b88SShahaf Shuler 			DEV_TX_OFFLOAD_MBUF_FAST_FREE;
84f21e3b88SShahaf Shuler 
8520c78ac9SDavid Hunt 	/* Configure the Ethernet device. */
8620c78ac9SDavid Hunt 	retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
8720c78ac9SDavid Hunt 	if (retval != 0)
8820c78ac9SDavid Hunt 		return retval;
8920c78ac9SDavid Hunt 
9020c78ac9SDavid Hunt 	/* Allocate and set up 1 RX queue per Ethernet port. */
9120c78ac9SDavid Hunt 	for (q = 0; q < rx_rings; q++) {
9220c78ac9SDavid Hunt 		retval = rte_eth_rx_queue_setup(port, q, RX_RING_SIZE,
9320c78ac9SDavid Hunt 				rte_eth_dev_socket_id(port), NULL, mbuf_pool);
9420c78ac9SDavid Hunt 		if (retval < 0)
9520c78ac9SDavid Hunt 			return retval;
9620c78ac9SDavid Hunt 	}
9720c78ac9SDavid Hunt 
98f21e3b88SShahaf Shuler 	txq_conf = dev_info.default_txconf;
99f21e3b88SShahaf Shuler 	txq_conf.offloads = port_conf.txmode.offloads;
10020c78ac9SDavid Hunt 	/* Allocate and set up 1 TX queue per Ethernet port. */
10120c78ac9SDavid Hunt 	for (q = 0; q < tx_rings; q++) {
10220c78ac9SDavid Hunt 		retval = rte_eth_tx_queue_setup(port, q, TX_RING_SIZE,
103f21e3b88SShahaf Shuler 				rte_eth_dev_socket_id(port), &txq_conf);
10420c78ac9SDavid Hunt 		if (retval < 0)
10520c78ac9SDavid Hunt 			return retval;
10620c78ac9SDavid Hunt 	}
10720c78ac9SDavid Hunt 
10820c78ac9SDavid Hunt 	/* Start the Ethernet port. */
10920c78ac9SDavid Hunt 	retval = rte_eth_dev_start(port);
11020c78ac9SDavid Hunt 	if (retval < 0)
11120c78ac9SDavid Hunt 		return retval;
11220c78ac9SDavid Hunt 
11320c78ac9SDavid Hunt 	/* Display the port MAC address. */
1146d13ea8eSOlivier Matz 	struct rte_ether_addr addr;
11570febdcfSIgor Romanov 	retval = rte_eth_macaddr_get(port, &addr);
11670febdcfSIgor Romanov 	if (retval != 0) {
11770febdcfSIgor Romanov 		printf("Failed to get device (port %u) MAC address: %s\n",
11870febdcfSIgor Romanov 				port, rte_strerror(-retval));
11970febdcfSIgor Romanov 		return retval;
12070febdcfSIgor Romanov 	}
12170febdcfSIgor Romanov 
12220c78ac9SDavid Hunt 	printf("Port %u MAC: %02" PRIx8 " %02" PRIx8 " %02" PRIx8
12320c78ac9SDavid Hunt 			   " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 "\n",
12420c78ac9SDavid Hunt 			(unsigned int)port,
12520c78ac9SDavid Hunt 			addr.addr_bytes[0], addr.addr_bytes[1],
12620c78ac9SDavid Hunt 			addr.addr_bytes[2], addr.addr_bytes[3],
12720c78ac9SDavid Hunt 			addr.addr_bytes[4], addr.addr_bytes[5]);
12820c78ac9SDavid Hunt 
12920c78ac9SDavid Hunt 	/* Enable RX in promiscuous mode for the Ethernet device. */
130f430bbceSIvan Ilchenko 	retval = rte_eth_promiscuous_enable(port);
131f430bbceSIvan Ilchenko 	if (retval != 0)
132f430bbceSIvan Ilchenko 		return retval;
13320c78ac9SDavid Hunt 
13420c78ac9SDavid Hunt 
13520c78ac9SDavid Hunt 	return 0;
13620c78ac9SDavid Hunt }
13720c78ac9SDavid Hunt 
13820c78ac9SDavid Hunt static int
13920c78ac9SDavid Hunt parse_portmask(const char *portmask)
14020c78ac9SDavid Hunt {
14120c78ac9SDavid Hunt 	char *end = NULL;
14220c78ac9SDavid Hunt 	unsigned long pm;
14320c78ac9SDavid Hunt 
14420c78ac9SDavid Hunt 	/* parse hexadecimal string */
14520c78ac9SDavid Hunt 	pm = strtoul(portmask, &end, 16);
14620c78ac9SDavid Hunt 	if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
14720c78ac9SDavid Hunt 		return -1;
14820c78ac9SDavid Hunt 
14920c78ac9SDavid Hunt 	if (pm == 0)
15020c78ac9SDavid Hunt 		return -1;
15120c78ac9SDavid Hunt 
15220c78ac9SDavid Hunt 	return pm;
15320c78ac9SDavid Hunt }
15420c78ac9SDavid Hunt /* Parse the argument given in the command line of the application */
15520c78ac9SDavid Hunt static int
15620c78ac9SDavid Hunt parse_args(int argc, char **argv)
15720c78ac9SDavid Hunt {
15899a968faSDavid Hunt 	int opt, ret, cnt, i;
15920c78ac9SDavid Hunt 	char **argvopt;
16099a968faSDavid Hunt 	uint16_t *oob_enable;
16120c78ac9SDavid Hunt 	int option_index;
16220c78ac9SDavid Hunt 	char *prgname = argv[0];
16399a968faSDavid Hunt 	struct core_info *ci;
164711f43baSDavid Hunt 	float branch_ratio;
16520c78ac9SDavid Hunt 	static struct option lgopts[] = {
16620c78ac9SDavid Hunt 		{ "mac-updating", no_argument, 0, 1},
16720c78ac9SDavid Hunt 		{ "no-mac-updating", no_argument, 0, 0},
168*95f648ffSRory Sexton 		{ "core-branch-ratio", optional_argument, 0, 'b'},
1696e269577SDavid Hunt 		{ "port-list", optional_argument, 0, 'p'},
17020c78ac9SDavid Hunt 		{NULL, 0, 0, 0}
17120c78ac9SDavid Hunt 	};
17220c78ac9SDavid Hunt 	argvopt = argv;
17399a968faSDavid Hunt 	ci = get_core_info();
17420c78ac9SDavid Hunt 
175*95f648ffSRory Sexton 	while ((opt = getopt_long(argc, argvopt, "p:q:T:b:",
17620c78ac9SDavid Hunt 				  lgopts, &option_index)) != EOF) {
17720c78ac9SDavid Hunt 
17820c78ac9SDavid Hunt 		switch (opt) {
17920c78ac9SDavid Hunt 		/* portmask */
18020c78ac9SDavid Hunt 		case 'p':
18120c78ac9SDavid Hunt 			enabled_port_mask = parse_portmask(optarg);
18220c78ac9SDavid Hunt 			if (enabled_port_mask == 0) {
18320c78ac9SDavid Hunt 				printf("invalid portmask\n");
18420c78ac9SDavid Hunt 				return -1;
18520c78ac9SDavid Hunt 			}
18620c78ac9SDavid Hunt 			break;
187*95f648ffSRory Sexton 		case 'b':
188*95f648ffSRory Sexton 			branch_ratio = BRANCH_RATIO_THRESHOLD;
18999a968faSDavid Hunt 			oob_enable = malloc(ci->core_count * sizeof(uint16_t));
19099a968faSDavid Hunt 			if (oob_enable == NULL) {
19199a968faSDavid Hunt 				printf("Error - Unable to allocate memory\n");
19299a968faSDavid Hunt 				return -1;
19399a968faSDavid Hunt 			}
19499a968faSDavid Hunt 			cnt = parse_set(optarg, oob_enable, ci->core_count);
19599a968faSDavid Hunt 			if (cnt < 0) {
196*95f648ffSRory Sexton 				printf("Invalid core-list section in "
197*95f648ffSRory Sexton 				       "core-branch-ratio matrix - [%s]\n",
19899a968faSDavid Hunt 						optarg);
199da4ac8e5SDavid Hunt 				free(oob_enable);
20099a968faSDavid Hunt 				break;
20199a968faSDavid Hunt 			}
202*95f648ffSRory Sexton 			cnt = parse_branch_ratio(optarg, &branch_ratio);
203*95f648ffSRory Sexton 			if (cnt < 0) {
204*95f648ffSRory Sexton 				printf("Invalid branch-ratio section in "
205*95f648ffSRory Sexton 				       "core-branch-ratio matrix - [%s]\n",
206*95f648ffSRory Sexton 						optarg);
20799a968faSDavid Hunt 				free(oob_enable);
20899a968faSDavid Hunt 				break;
209*95f648ffSRory Sexton 			}
210*95f648ffSRory Sexton 			if (branch_ratio <= 0.0 || branch_ratio > 100.0) {
211711f43baSDavid Hunt 				printf("invalid branch ratio specified\n");
212711f43baSDavid Hunt 				return -1;
213711f43baSDavid Hunt 			}
214*95f648ffSRory Sexton 			for (i = 0; i < ci->core_count; i++) {
215*95f648ffSRory Sexton 				if (oob_enable[i]) {
216*95f648ffSRory Sexton 					printf("***Using core %d "
217*95f648ffSRory Sexton 					       "with branch ratio %f\n",
218*95f648ffSRory Sexton 					       i, branch_ratio);
219*95f648ffSRory Sexton 					ci->cd[i].oob_enabled = 1;
220*95f648ffSRory Sexton 					ci->cd[i].global_enabled_cpus = 1;
221*95f648ffSRory Sexton 					ci->cd[i].branch_ratio_threshold =
222*95f648ffSRory Sexton 								branch_ratio;
223*95f648ffSRory Sexton 				}
224*95f648ffSRory Sexton 			}
225*95f648ffSRory Sexton 			free(oob_enable);
226711f43baSDavid Hunt 			break;
22720c78ac9SDavid Hunt 		/* long options */
22820c78ac9SDavid Hunt 		case 0:
22920c78ac9SDavid Hunt 			break;
23020c78ac9SDavid Hunt 
23120c78ac9SDavid Hunt 		default:
23220c78ac9SDavid Hunt 			return -1;
23320c78ac9SDavid Hunt 		}
23420c78ac9SDavid Hunt 	}
23520c78ac9SDavid Hunt 
23620c78ac9SDavid Hunt 	if (optind >= 0)
23720c78ac9SDavid Hunt 		argv[optind-1] = prgname;
23820c78ac9SDavid Hunt 
23920c78ac9SDavid Hunt 	ret = optind-1;
24020c78ac9SDavid Hunt 	optind = 0; /* reset getopt lib */
24120c78ac9SDavid Hunt 	return ret;
24220c78ac9SDavid Hunt }
24320c78ac9SDavid Hunt 
24420c78ac9SDavid Hunt static void
2458728ccf3SThomas Monjalon check_all_ports_link_status(uint32_t port_mask)
24620c78ac9SDavid Hunt {
24720c78ac9SDavid Hunt #define CHECK_INTERVAL 100 /* 100ms */
24820c78ac9SDavid Hunt #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
24920c78ac9SDavid Hunt 	uint16_t portid, count, all_ports_up, print_flag = 0;
25020c78ac9SDavid Hunt 	struct rte_eth_link link;
25122e5c73bSIgor Romanov 	int ret;
25220c78ac9SDavid Hunt 
25320c78ac9SDavid Hunt 	printf("\nChecking link status");
25420c78ac9SDavid Hunt 	fflush(stdout);
25520c78ac9SDavid Hunt 	for (count = 0; count <= MAX_CHECK_TIME; count++) {
25620c78ac9SDavid Hunt 		if (force_quit)
25720c78ac9SDavid Hunt 			return;
25820c78ac9SDavid Hunt 		all_ports_up = 1;
2598728ccf3SThomas Monjalon 		RTE_ETH_FOREACH_DEV(portid) {
26020c78ac9SDavid Hunt 			if (force_quit)
26120c78ac9SDavid Hunt 				return;
26220c78ac9SDavid Hunt 			if ((port_mask & (1 << portid)) == 0)
26320c78ac9SDavid Hunt 				continue;
26420c78ac9SDavid Hunt 			memset(&link, 0, sizeof(link));
26522e5c73bSIgor Romanov 			ret = rte_eth_link_get_nowait(portid, &link);
26622e5c73bSIgor Romanov 			if (ret < 0) {
26722e5c73bSIgor Romanov 				all_ports_up = 0;
26822e5c73bSIgor Romanov 				if (print_flag == 1)
26922e5c73bSIgor Romanov 					printf("Port %u link get failed: %s\n",
27022e5c73bSIgor Romanov 						portid, rte_strerror(-ret));
27122e5c73bSIgor Romanov 				continue;
27222e5c73bSIgor Romanov 			}
27320c78ac9SDavid Hunt 			/* print link status if flag set */
27420c78ac9SDavid Hunt 			if (print_flag == 1) {
27520c78ac9SDavid Hunt 				if (link.link_status)
27620c78ac9SDavid Hunt 					printf("Port %d Link Up - speed %u "
27720c78ac9SDavid Hunt 						"Mbps - %s\n", (uint16_t)portid,
27820c78ac9SDavid Hunt 						(unsigned int)link.link_speed,
27920c78ac9SDavid Hunt 				(link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
280c81e3f21SIvan Dyukov 					("full-duplex") : ("half-duplex"));
28120c78ac9SDavid Hunt 				else
28220c78ac9SDavid Hunt 					printf("Port %d Link Down\n",
28320c78ac9SDavid Hunt 						(uint16_t)portid);
28420c78ac9SDavid Hunt 				continue;
28520c78ac9SDavid Hunt 			}
28620c78ac9SDavid Hunt 		       /* clear all_ports_up flag if any link down */
28720c78ac9SDavid Hunt 			if (link.link_status == ETH_LINK_DOWN) {
28820c78ac9SDavid Hunt 				all_ports_up = 0;
28920c78ac9SDavid Hunt 				break;
29020c78ac9SDavid Hunt 			}
29120c78ac9SDavid Hunt 		}
29220c78ac9SDavid Hunt 		/* after finally printing all link status, get out */
29320c78ac9SDavid Hunt 		if (print_flag == 1)
29420c78ac9SDavid Hunt 			break;
29520c78ac9SDavid Hunt 
29620c78ac9SDavid Hunt 		if (all_ports_up == 0) {
29720c78ac9SDavid Hunt 			printf(".");
29820c78ac9SDavid Hunt 			fflush(stdout);
29920c78ac9SDavid Hunt 			rte_delay_ms(CHECK_INTERVAL);
30020c78ac9SDavid Hunt 		}
30120c78ac9SDavid Hunt 
30220c78ac9SDavid Hunt 		/* set the print_flag if all ports up or timeout */
30320c78ac9SDavid Hunt 		if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
30420c78ac9SDavid Hunt 			print_flag = 1;
30520c78ac9SDavid Hunt 			printf("done\n");
30620c78ac9SDavid Hunt 		}
30720c78ac9SDavid Hunt 	}
30820c78ac9SDavid Hunt }
3098db653ffSAlan Carew static int
310f2fc83b4SThomas Monjalon run_monitor(__rte_unused void *arg)
3118db653ffSAlan Carew {
3128db653ffSAlan Carew 	if (channel_monitor_init() < 0) {
3138db653ffSAlan Carew 		printf("Unable to initialize channel monitor\n");
3148db653ffSAlan Carew 		return -1;
3158db653ffSAlan Carew 	}
3168db653ffSAlan Carew 	run_channel_monitor();
3178db653ffSAlan Carew 	return 0;
3188db653ffSAlan Carew }
3198db653ffSAlan Carew 
320d42b1300SDavid Hunt static int
321f2fc83b4SThomas Monjalon run_core_monitor(__rte_unused void *arg)
322d42b1300SDavid Hunt {
323d42b1300SDavid Hunt 	if (branch_monitor_init() < 0) {
324d42b1300SDavid Hunt 		printf("Unable to initialize core monitor\n");
325d42b1300SDavid Hunt 		return -1;
326d42b1300SDavid Hunt 	}
327d42b1300SDavid Hunt 	run_branch_monitor();
328d42b1300SDavid Hunt 	return 0;
329d42b1300SDavid Hunt }
330d42b1300SDavid Hunt 
3318db653ffSAlan Carew static void
3328db653ffSAlan Carew sig_handler(int signo)
3338db653ffSAlan Carew {
3348db653ffSAlan Carew 	printf("Received signal %d, exiting...\n", signo);
3358db653ffSAlan Carew 	channel_monitor_exit();
3368db653ffSAlan Carew 	channel_manager_exit();
3378db653ffSAlan Carew 	power_manager_exit();
3388db653ffSAlan Carew 
3398db653ffSAlan Carew }
3408db653ffSAlan Carew 
3418db653ffSAlan Carew int
34298a16481SDavid Marchand main(int argc, char **argv)
3438db653ffSAlan Carew {
3448db653ffSAlan Carew 	int ret;
3458db653ffSAlan Carew 	unsigned lcore_id;
34620c78ac9SDavid Hunt 	unsigned int nb_ports;
34720c78ac9SDavid Hunt 	struct rte_mempool *mbuf_pool;
34820c78ac9SDavid Hunt 	uint16_t portid;
349d42b1300SDavid Hunt 	struct core_info *ci;
35020c78ac9SDavid Hunt 
3518db653ffSAlan Carew 
35299a968faSDavid Hunt 	ret = core_info_init();
35399a968faSDavid Hunt 	if (ret < 0)
35499a968faSDavid Hunt 		rte_panic("Cannot allocate core info\n");
35599a968faSDavid Hunt 
356d42b1300SDavid Hunt 	ci = get_core_info();
357d42b1300SDavid Hunt 
3588db653ffSAlan Carew 	ret = rte_eal_init(argc, argv);
3598db653ffSAlan Carew 	if (ret < 0)
3608db653ffSAlan Carew 		rte_panic("Cannot init EAL\n");
3618db653ffSAlan Carew 
3628db653ffSAlan Carew 	signal(SIGINT, sig_handler);
3638db653ffSAlan Carew 	signal(SIGTERM, sig_handler);
3648db653ffSAlan Carew 
36520c78ac9SDavid Hunt 	argc -= ret;
36620c78ac9SDavid Hunt 	argv += ret;
36720c78ac9SDavid Hunt 
36820c78ac9SDavid Hunt 	/* parse application arguments (after the EAL ones) */
36920c78ac9SDavid Hunt 	ret = parse_args(argc, argv);
37020c78ac9SDavid Hunt 	if (ret < 0)
37120c78ac9SDavid Hunt 		rte_exit(EXIT_FAILURE, "Invalid arguments\n");
37220c78ac9SDavid Hunt 
373d9a42a69SThomas Monjalon 	nb_ports = rte_eth_dev_count_avail();
37420c78ac9SDavid Hunt 
375ace158c4SDavid Hunt 	if (nb_ports > 0) {
376ace158c4SDavid Hunt 		mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL",
377ace158c4SDavid Hunt 				NUM_MBUFS * nb_ports, MBUF_CACHE_SIZE, 0,
378ace158c4SDavid Hunt 				RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
37920c78ac9SDavid Hunt 
38020c78ac9SDavid Hunt 		if (mbuf_pool == NULL)
38120c78ac9SDavid Hunt 			rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
38220c78ac9SDavid Hunt 
38320c78ac9SDavid Hunt 		/* Initialize ports. */
3848728ccf3SThomas Monjalon 		RTE_ETH_FOREACH_DEV(portid) {
3856d13ea8eSOlivier Matz 			struct rte_ether_addr eth;
386c9a47791SDavid Hunt 			int w, j;
387a032a081SDavid Coyle 			int ret;
388c9a47791SDavid Hunt 
38920c78ac9SDavid Hunt 			if ((enabled_port_mask & (1 << portid)) == 0)
39020c78ac9SDavid Hunt 				continue;
391c9a47791SDavid Hunt 
392c9a47791SDavid Hunt 			eth.addr_bytes[0] = 0xe0;
393c9a47791SDavid Hunt 			eth.addr_bytes[1] = 0xe0;
394c9a47791SDavid Hunt 			eth.addr_bytes[2] = 0xe0;
395c9a47791SDavid Hunt 			eth.addr_bytes[3] = 0xe0;
396c9a47791SDavid Hunt 			eth.addr_bytes[4] = portid + 0xf0;
397c9a47791SDavid Hunt 
39820c78ac9SDavid Hunt 			if (port_init(portid, mbuf_pool) != 0)
399ace158c4SDavid Hunt 				rte_exit(EXIT_FAILURE,
400ace158c4SDavid Hunt 					"Cannot init port %"PRIu8 "\n",
40120c78ac9SDavid Hunt 					portid);
402c9a47791SDavid Hunt 
403c9a47791SDavid Hunt 			for (w = 0; w < MAX_VFS; w++) {
404c9a47791SDavid Hunt 				eth.addr_bytes[5] = w + 0xf0;
405c9a47791SDavid Hunt 
40670b2c7f1SDavid Christensen 				ret = -ENOTSUP;
40770b2c7f1SDavid Christensen #ifdef RTE_LIBRTE_IXGBE_PMD
408c9a47791SDavid Hunt 				ret = rte_pmd_ixgbe_set_vf_mac_addr(portid,
409c9a47791SDavid Hunt 							w, &eth);
41070b2c7f1SDavid Christensen #endif
41170b2c7f1SDavid Christensen #ifdef RTE_LIBRTE_I40E_PMD
412c9a47791SDavid Hunt 				if (ret == -ENOTSUP)
413ace158c4SDavid Hunt 					ret = rte_pmd_i40e_set_vf_mac_addr(
414ace158c4SDavid Hunt 							portid, w, &eth);
41570b2c7f1SDavid Christensen #endif
41670b2c7f1SDavid Christensen #ifdef RTE_LIBRTE_BNXT_PMD
417c9a47791SDavid Hunt 				if (ret == -ENOTSUP)
418ace158c4SDavid Hunt 					ret = rte_pmd_bnxt_set_vf_mac_addr(
419ace158c4SDavid Hunt 							portid, w, &eth);
42070b2c7f1SDavid Christensen #endif
421c9a47791SDavid Hunt 
422c9a47791SDavid Hunt 				switch (ret) {
423c9a47791SDavid Hunt 				case 0:
424c9a47791SDavid Hunt 					printf("Port %d VF %d MAC: ",
425c9a47791SDavid Hunt 							portid, w);
426ace158c4SDavid Hunt 					for (j = 0; j < 5; j++) {
427ace158c4SDavid Hunt 						printf("%02x:",
428ace158c4SDavid Hunt 							eth.addr_bytes[j]);
429ace158c4SDavid Hunt 					}
430ace158c4SDavid Hunt 					printf("%02x\n", eth.addr_bytes[5]);
431ace158c4SDavid Hunt 					break;
432c9a47791SDavid Hunt 				}
433c9a47791SDavid Hunt 				printf("\n");
434c9a47791SDavid Hunt 			}
435c9a47791SDavid Hunt 		}
43620c78ac9SDavid Hunt 	}
43720c78ac9SDavid Hunt 
438d42b1300SDavid Hunt 	check_all_ports_link_status(enabled_port_mask);
439d42b1300SDavid Hunt 
4408db653ffSAlan Carew 	lcore_id = rte_get_next_lcore(-1, 1, 0);
4418db653ffSAlan Carew 	if (lcore_id == RTE_MAX_LCORE) {
442d42b1300SDavid Hunt 		RTE_LOG(ERR, EAL, "A minimum of three cores are required to run "
4438db653ffSAlan Carew 				"application\n");
4448db653ffSAlan Carew 		return 0;
4458db653ffSAlan Carew 	}
446d42b1300SDavid Hunt 	printf("Running channel monitor on lcore id %d\n", lcore_id);
4478db653ffSAlan Carew 	rte_eal_remote_launch(run_monitor, NULL, lcore_id);
4488db653ffSAlan Carew 
449d42b1300SDavid Hunt 	lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
450d42b1300SDavid Hunt 	if (lcore_id == RTE_MAX_LCORE) {
451d42b1300SDavid Hunt 		RTE_LOG(ERR, EAL, "A minimum of three cores are required to run "
452d42b1300SDavid Hunt 				"application\n");
453d42b1300SDavid Hunt 		return 0;
454d42b1300SDavid Hunt 	}
4558db653ffSAlan Carew 	if (power_manager_init() < 0) {
4568db653ffSAlan Carew 		printf("Unable to initialize power manager\n");
4578db653ffSAlan Carew 		return -1;
4588db653ffSAlan Carew 	}
4598db653ffSAlan Carew 	if (channel_manager_init(CHANNEL_MGR_DEFAULT_HV_PATH) < 0) {
4608db653ffSAlan Carew 		printf("Unable to initialize channel manager\n");
4618db653ffSAlan Carew 		return -1;
4628db653ffSAlan Carew 	}
463d42b1300SDavid Hunt 
464221e7026SMarcin Hajkowski 	add_host_channels();
4653618326fSDavid Hunt 
466d42b1300SDavid Hunt 	printf("Running core monitor on lcore id %d\n", lcore_id);
467d42b1300SDavid Hunt 	rte_eal_remote_launch(run_core_monitor, NULL, lcore_id);
468d42b1300SDavid Hunt 
4698db653ffSAlan Carew 	run_cli(NULL);
4708db653ffSAlan Carew 
471d42b1300SDavid Hunt 	branch_monitor_exit();
472d42b1300SDavid Hunt 
4738db653ffSAlan Carew 	rte_eal_mp_wait_lcore();
474d42b1300SDavid Hunt 
475d42b1300SDavid Hunt 	free(ci->cd);
476d42b1300SDavid Hunt 
4778db653ffSAlan Carew 	return 0;
4788db653ffSAlan Carew }
479