xref: /dpdk/examples/vm_power_manager/main.c (revision ec8fb5696c7e0ddc7c1e9821b2dcaa8d8afde74c)
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_per_lcore.h>
218db653ffSAlan Carew #include <rte_lcore.h>
2220c78ac9SDavid Hunt #include <rte_ethdev.h>
2320c78ac9SDavid Hunt #include <getopt.h>
2420c78ac9SDavid Hunt #include <rte_cycles.h>
258db653ffSAlan Carew #include <rte_debug.h>
268db653ffSAlan Carew 
278db653ffSAlan Carew #include "channel_manager.h"
288db653ffSAlan Carew #include "channel_monitor.h"
298db653ffSAlan Carew #include "power_manager.h"
308db653ffSAlan Carew #include "vm_power_cli.h"
31d42b1300SDavid Hunt #include "oob_monitor.h"
3299a968faSDavid Hunt #include "parse.h"
33a8d0d473SBruce Richardson #ifdef RTE_NET_IXGBE
34c9a47791SDavid Hunt #include <rte_pmd_ixgbe.h>
3570b2c7f1SDavid Christensen #endif
36a8d0d473SBruce Richardson #ifdef RTE_NET_I40E
37c9a47791SDavid Hunt #include <rte_pmd_i40e.h>
3870b2c7f1SDavid Christensen #endif
39a8d0d473SBruce Richardson #ifdef RTE_NET_BNXT
40c9a47791SDavid Hunt #include <rte_pmd_bnxt.h>
4170b2c7f1SDavid Christensen #endif
428db653ffSAlan Carew 
43867a6c66SKevin Laatz #define RX_RING_SIZE 1024
44867a6c66SKevin Laatz #define TX_RING_SIZE 1024
4520c78ac9SDavid Hunt 
4620c78ac9SDavid Hunt #define NUM_MBUFS 8191
4720c78ac9SDavid Hunt #define MBUF_CACHE_SIZE 250
4820c78ac9SDavid Hunt #define BURST_SIZE 32
4920c78ac9SDavid Hunt 
5020c78ac9SDavid Hunt static uint32_t enabled_port_mask;
5120c78ac9SDavid Hunt static volatile bool force_quit;
5220c78ac9SDavid Hunt 
5320c78ac9SDavid Hunt static inline int
port_init(uint16_t port,struct rte_mempool * mbuf_pool)5420c78ac9SDavid Hunt port_init(uint16_t port, struct rte_mempool *mbuf_pool)
5520c78ac9SDavid Hunt {
561bb4a528SFerruh Yigit 	struct rte_eth_conf port_conf;
5720c78ac9SDavid Hunt 	const uint16_t rx_rings = 1, tx_rings = 1;
5820c78ac9SDavid Hunt 	int retval;
5920c78ac9SDavid Hunt 	uint16_t q;
60f21e3b88SShahaf Shuler 	struct rte_eth_dev_info dev_info;
61f21e3b88SShahaf Shuler 	struct rte_eth_txconf txq_conf;
6220c78ac9SDavid Hunt 
63a9dbe180SThomas Monjalon 	if (!rte_eth_dev_is_valid_port(port))
6420c78ac9SDavid Hunt 		return -1;
6520c78ac9SDavid Hunt 
661bb4a528SFerruh Yigit 	memset(&port_conf, 0, sizeof(struct rte_eth_conf));
671bb4a528SFerruh Yigit 
68089e5ed7SIvan Ilchenko 	retval = rte_eth_dev_info_get(port, &dev_info);
69089e5ed7SIvan Ilchenko 	if (retval != 0) {
70089e5ed7SIvan Ilchenko 		printf("Error during getting device (port %u) info: %s\n",
71089e5ed7SIvan Ilchenko 				port, strerror(-retval));
72089e5ed7SIvan Ilchenko 		return retval;
73089e5ed7SIvan Ilchenko 	}
74089e5ed7SIvan Ilchenko 
75295968d1SFerruh Yigit 	if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
76f21e3b88SShahaf Shuler 		port_conf.txmode.offloads |=
77295968d1SFerruh Yigit 			RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
78f21e3b88SShahaf Shuler 
7920c78ac9SDavid Hunt 	/* Configure the Ethernet device. */
8020c78ac9SDavid Hunt 	retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
8120c78ac9SDavid Hunt 	if (retval != 0)
8220c78ac9SDavid Hunt 		return retval;
8320c78ac9SDavid Hunt 
8420c78ac9SDavid Hunt 	/* Allocate and set up 1 RX queue per Ethernet port. */
8520c78ac9SDavid Hunt 	for (q = 0; q < rx_rings; q++) {
8620c78ac9SDavid Hunt 		retval = rte_eth_rx_queue_setup(port, q, RX_RING_SIZE,
8720c78ac9SDavid Hunt 				rte_eth_dev_socket_id(port), NULL, mbuf_pool);
8820c78ac9SDavid Hunt 		if (retval < 0)
8920c78ac9SDavid Hunt 			return retval;
9020c78ac9SDavid Hunt 	}
9120c78ac9SDavid Hunt 
92f21e3b88SShahaf Shuler 	txq_conf = dev_info.default_txconf;
93f21e3b88SShahaf Shuler 	txq_conf.offloads = port_conf.txmode.offloads;
9420c78ac9SDavid Hunt 	/* Allocate and set up 1 TX queue per Ethernet port. */
9520c78ac9SDavid Hunt 	for (q = 0; q < tx_rings; q++) {
9620c78ac9SDavid Hunt 		retval = rte_eth_tx_queue_setup(port, q, TX_RING_SIZE,
97f21e3b88SShahaf Shuler 				rte_eth_dev_socket_id(port), &txq_conf);
9820c78ac9SDavid Hunt 		if (retval < 0)
9920c78ac9SDavid Hunt 			return retval;
10020c78ac9SDavid Hunt 	}
10120c78ac9SDavid Hunt 
10220c78ac9SDavid Hunt 	/* Start the Ethernet port. */
10320c78ac9SDavid Hunt 	retval = rte_eth_dev_start(port);
10420c78ac9SDavid Hunt 	if (retval < 0)
10520c78ac9SDavid Hunt 		return retval;
10620c78ac9SDavid Hunt 
10720c78ac9SDavid Hunt 	/* Display the port MAC address. */
1086d13ea8eSOlivier Matz 	struct rte_ether_addr addr;
10970febdcfSIgor Romanov 	retval = rte_eth_macaddr_get(port, &addr);
11070febdcfSIgor Romanov 	if (retval != 0) {
11170febdcfSIgor Romanov 		printf("Failed to get device (port %u) MAC address: %s\n",
11270febdcfSIgor Romanov 				port, rte_strerror(-retval));
11370febdcfSIgor Romanov 		return retval;
11470febdcfSIgor Romanov 	}
11570febdcfSIgor Romanov 
11620c78ac9SDavid Hunt 	printf("Port %u MAC: %02" PRIx8 " %02" PRIx8 " %02" PRIx8
11720c78ac9SDavid Hunt 			   " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 "\n",
118a7db3afcSAman Deep Singh 			(unsigned int)port, RTE_ETHER_ADDR_BYTES(&addr));
11920c78ac9SDavid Hunt 
12020c78ac9SDavid Hunt 	/* Enable RX in promiscuous mode for the Ethernet device. */
121f430bbceSIvan Ilchenko 	retval = rte_eth_promiscuous_enable(port);
122f430bbceSIvan Ilchenko 	if (retval != 0)
123f430bbceSIvan Ilchenko 		return retval;
12420c78ac9SDavid Hunt 
12520c78ac9SDavid Hunt 
12620c78ac9SDavid Hunt 	return 0;
12720c78ac9SDavid Hunt }
12820c78ac9SDavid Hunt 
12920c78ac9SDavid Hunt static int
parse_portmask(const char * portmask)13020c78ac9SDavid Hunt parse_portmask(const char *portmask)
13120c78ac9SDavid Hunt {
13220c78ac9SDavid Hunt 	char *end = NULL;
13320c78ac9SDavid Hunt 	unsigned long pm;
13420c78ac9SDavid Hunt 
13520c78ac9SDavid Hunt 	/* parse hexadecimal string */
13620c78ac9SDavid Hunt 	pm = strtoul(portmask, &end, 16);
13720c78ac9SDavid Hunt 	if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
138ce6b8c31SSarosh Arif 		return 0;
13920c78ac9SDavid Hunt 
14020c78ac9SDavid Hunt 	return pm;
14120c78ac9SDavid Hunt }
14220c78ac9SDavid Hunt /* Parse the argument given in the command line of the application */
14320c78ac9SDavid Hunt static int
parse_args(int argc,char ** argv)14420c78ac9SDavid Hunt parse_args(int argc, char **argv)
14520c78ac9SDavid Hunt {
14699a968faSDavid Hunt 	int opt, ret, cnt, i;
14720c78ac9SDavid Hunt 	char **argvopt;
14899a968faSDavid Hunt 	uint16_t *oob_enable;
14920c78ac9SDavid Hunt 	int option_index;
15020c78ac9SDavid Hunt 	char *prgname = argv[0];
15199a968faSDavid Hunt 	struct core_info *ci;
152711f43baSDavid Hunt 	float branch_ratio;
15320c78ac9SDavid Hunt 	static struct option lgopts[] = {
15420c78ac9SDavid Hunt 		{ "mac-updating", no_argument, 0, 1},
15520c78ac9SDavid Hunt 		{ "no-mac-updating", no_argument, 0, 0},
15695f648ffSRory Sexton 		{ "core-branch-ratio", optional_argument, 0, 'b'},
1576e269577SDavid Hunt 		{ "port-list", optional_argument, 0, 'p'},
15820c78ac9SDavid Hunt 		{NULL, 0, 0, 0}
15920c78ac9SDavid Hunt 	};
16020c78ac9SDavid Hunt 	argvopt = argv;
16199a968faSDavid Hunt 	ci = get_core_info();
16220c78ac9SDavid Hunt 
16395f648ffSRory Sexton 	while ((opt = getopt_long(argc, argvopt, "p:q:T:b:",
16420c78ac9SDavid Hunt 				  lgopts, &option_index)) != EOF) {
16520c78ac9SDavid Hunt 
16620c78ac9SDavid Hunt 		switch (opt) {
16720c78ac9SDavid Hunt 		/* portmask */
16820c78ac9SDavid Hunt 		case 'p':
16920c78ac9SDavid Hunt 			enabled_port_mask = parse_portmask(optarg);
17020c78ac9SDavid Hunt 			if (enabled_port_mask == 0) {
17120c78ac9SDavid Hunt 				printf("invalid portmask\n");
17220c78ac9SDavid Hunt 				return -1;
17320c78ac9SDavid Hunt 			}
17420c78ac9SDavid Hunt 			break;
17595f648ffSRory Sexton 		case 'b':
17695f648ffSRory Sexton 			branch_ratio = BRANCH_RATIO_THRESHOLD;
17799a968faSDavid Hunt 			oob_enable = malloc(ci->core_count * sizeof(uint16_t));
17899a968faSDavid Hunt 			if (oob_enable == NULL) {
17999a968faSDavid Hunt 				printf("Error - Unable to allocate memory\n");
18099a968faSDavid Hunt 				return -1;
18199a968faSDavid Hunt 			}
18299a968faSDavid Hunt 			cnt = parse_set(optarg, oob_enable, ci->core_count);
18399a968faSDavid Hunt 			if (cnt < 0) {
18495f648ffSRory Sexton 				printf("Invalid core-list section in "
18595f648ffSRory Sexton 				       "core-branch-ratio matrix - [%s]\n",
18699a968faSDavid Hunt 						optarg);
187da4ac8e5SDavid Hunt 				free(oob_enable);
18899a968faSDavid Hunt 				break;
18999a968faSDavid Hunt 			}
19095f648ffSRory Sexton 			cnt = parse_branch_ratio(optarg, &branch_ratio);
19195f648ffSRory Sexton 			if (cnt < 0) {
19295f648ffSRory Sexton 				printf("Invalid branch-ratio section in "
19395f648ffSRory Sexton 				       "core-branch-ratio matrix - [%s]\n",
19495f648ffSRory Sexton 						optarg);
19599a968faSDavid Hunt 				free(oob_enable);
19699a968faSDavid Hunt 				break;
19795f648ffSRory Sexton 			}
19895f648ffSRory Sexton 			if (branch_ratio <= 0.0 || branch_ratio > 100.0) {
199711f43baSDavid Hunt 				printf("invalid branch ratio specified\n");
2003ac192b3SRory Sexton 				free(oob_enable);
201711f43baSDavid Hunt 				return -1;
202711f43baSDavid Hunt 			}
20395f648ffSRory Sexton 			for (i = 0; i < ci->core_count; i++) {
20495f648ffSRory Sexton 				if (oob_enable[i]) {
20595f648ffSRory Sexton 					printf("***Using core %d "
20695f648ffSRory Sexton 					       "with branch ratio %f\n",
20795f648ffSRory Sexton 					       i, branch_ratio);
20895f648ffSRory Sexton 					ci->cd[i].oob_enabled = 1;
20995f648ffSRory Sexton 					ci->cd[i].global_enabled_cpus = 1;
21095f648ffSRory Sexton 					ci->cd[i].branch_ratio_threshold =
21195f648ffSRory Sexton 								branch_ratio;
21295f648ffSRory Sexton 				}
21395f648ffSRory Sexton 			}
21495f648ffSRory Sexton 			free(oob_enable);
215711f43baSDavid Hunt 			break;
21620c78ac9SDavid Hunt 		/* long options */
21720c78ac9SDavid Hunt 		case 0:
21820c78ac9SDavid Hunt 			break;
21920c78ac9SDavid Hunt 
22020c78ac9SDavid Hunt 		default:
22120c78ac9SDavid Hunt 			return -1;
22220c78ac9SDavid Hunt 		}
22320c78ac9SDavid Hunt 	}
22420c78ac9SDavid Hunt 
22520c78ac9SDavid Hunt 	if (optind >= 0)
22620c78ac9SDavid Hunt 		argv[optind-1] = prgname;
22720c78ac9SDavid Hunt 
22820c78ac9SDavid Hunt 	ret = optind-1;
22920c78ac9SDavid Hunt 	optind = 0; /* reset getopt lib */
23020c78ac9SDavid Hunt 	return ret;
23120c78ac9SDavid Hunt }
23220c78ac9SDavid Hunt 
23320c78ac9SDavid Hunt static void
check_all_ports_link_status(uint32_t port_mask)2348728ccf3SThomas Monjalon check_all_ports_link_status(uint32_t port_mask)
23520c78ac9SDavid Hunt {
23620c78ac9SDavid Hunt #define CHECK_INTERVAL 100 /* 100ms */
23720c78ac9SDavid Hunt #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
23820c78ac9SDavid Hunt 	uint16_t portid, count, all_ports_up, print_flag = 0;
23920c78ac9SDavid Hunt 	struct rte_eth_link link;
24022e5c73bSIgor Romanov 	int ret;
241db4e8135SIvan Dyukov 	char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
24220c78ac9SDavid Hunt 
24320c78ac9SDavid Hunt 	printf("\nChecking link status");
24420c78ac9SDavid Hunt 	fflush(stdout);
24520c78ac9SDavid Hunt 	for (count = 0; count <= MAX_CHECK_TIME; count++) {
24620c78ac9SDavid Hunt 		if (force_quit)
24720c78ac9SDavid Hunt 			return;
24820c78ac9SDavid Hunt 		all_ports_up = 1;
2498728ccf3SThomas Monjalon 		RTE_ETH_FOREACH_DEV(portid) {
25020c78ac9SDavid Hunt 			if (force_quit)
25120c78ac9SDavid Hunt 				return;
25220c78ac9SDavid Hunt 			if ((port_mask & (1 << portid)) == 0)
25320c78ac9SDavid Hunt 				continue;
25420c78ac9SDavid Hunt 			memset(&link, 0, sizeof(link));
25522e5c73bSIgor Romanov 			ret = rte_eth_link_get_nowait(portid, &link);
25622e5c73bSIgor Romanov 			if (ret < 0) {
25722e5c73bSIgor Romanov 				all_ports_up = 0;
25822e5c73bSIgor Romanov 				if (print_flag == 1)
25922e5c73bSIgor Romanov 					printf("Port %u link get failed: %s\n",
26022e5c73bSIgor Romanov 						portid, rte_strerror(-ret));
26122e5c73bSIgor Romanov 				continue;
26222e5c73bSIgor Romanov 			}
26320c78ac9SDavid Hunt 			/* print link status if flag set */
26420c78ac9SDavid Hunt 			if (print_flag == 1) {
265db4e8135SIvan Dyukov 				rte_eth_link_to_str(link_status_text,
266db4e8135SIvan Dyukov 					sizeof(link_status_text), &link);
267db4e8135SIvan Dyukov 				printf("Port %d %s\n", portid,
268db4e8135SIvan Dyukov 				       link_status_text);
26920c78ac9SDavid Hunt 				continue;
27020c78ac9SDavid Hunt 			}
27120c78ac9SDavid Hunt 		       /* clear all_ports_up flag if any link down */
272295968d1SFerruh Yigit 			if (link.link_status == RTE_ETH_LINK_DOWN) {
27320c78ac9SDavid Hunt 				all_ports_up = 0;
27420c78ac9SDavid Hunt 				break;
27520c78ac9SDavid Hunt 			}
27620c78ac9SDavid Hunt 		}
27720c78ac9SDavid Hunt 		/* after finally printing all link status, get out */
27820c78ac9SDavid Hunt 		if (print_flag == 1)
27920c78ac9SDavid Hunt 			break;
28020c78ac9SDavid Hunt 
28120c78ac9SDavid Hunt 		if (all_ports_up == 0) {
28220c78ac9SDavid Hunt 			printf(".");
28320c78ac9SDavid Hunt 			fflush(stdout);
28420c78ac9SDavid Hunt 			rte_delay_ms(CHECK_INTERVAL);
28520c78ac9SDavid Hunt 		}
28620c78ac9SDavid Hunt 
28720c78ac9SDavid Hunt 		/* set the print_flag if all ports up or timeout */
28820c78ac9SDavid Hunt 		if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
28920c78ac9SDavid Hunt 			print_flag = 1;
29020c78ac9SDavid Hunt 			printf("done\n");
29120c78ac9SDavid Hunt 		}
29220c78ac9SDavid Hunt 	}
29320c78ac9SDavid Hunt }
2948db653ffSAlan Carew static int
run_monitor(__rte_unused void * arg)295f2fc83b4SThomas Monjalon run_monitor(__rte_unused void *arg)
2968db653ffSAlan Carew {
2978db653ffSAlan Carew 	if (channel_monitor_init() < 0) {
2988db653ffSAlan Carew 		printf("Unable to initialize channel monitor\n");
2998db653ffSAlan Carew 		return -1;
3008db653ffSAlan Carew 	}
3018db653ffSAlan Carew 	run_channel_monitor();
3028db653ffSAlan Carew 	return 0;
3038db653ffSAlan Carew }
3048db653ffSAlan Carew 
305d42b1300SDavid Hunt static int
run_core_monitor(__rte_unused void * arg)306f2fc83b4SThomas Monjalon run_core_monitor(__rte_unused void *arg)
307d42b1300SDavid Hunt {
308d42b1300SDavid Hunt 	if (branch_monitor_init() < 0) {
309d42b1300SDavid Hunt 		printf("Unable to initialize core monitor\n");
310d42b1300SDavid Hunt 		return -1;
311d42b1300SDavid Hunt 	}
312d42b1300SDavid Hunt 	run_branch_monitor();
313d42b1300SDavid Hunt 	return 0;
314d42b1300SDavid Hunt }
315d42b1300SDavid Hunt 
3168db653ffSAlan Carew static void
sig_handler(int signo)3178db653ffSAlan Carew sig_handler(int signo)
3188db653ffSAlan Carew {
3198db653ffSAlan Carew 	printf("Received signal %d, exiting...\n", signo);
3208db653ffSAlan Carew 	channel_monitor_exit();
3218db653ffSAlan Carew 	channel_manager_exit();
3228db653ffSAlan Carew 	power_manager_exit();
3238db653ffSAlan Carew 
3248db653ffSAlan Carew }
3258db653ffSAlan Carew 
3268db653ffSAlan Carew int
main(int argc,char ** argv)32798a16481SDavid Marchand main(int argc, char **argv)
3288db653ffSAlan Carew {
3298db653ffSAlan Carew 	int ret;
3308db653ffSAlan Carew 	unsigned lcore_id;
33120c78ac9SDavid Hunt 	unsigned int nb_ports;
33220c78ac9SDavid Hunt 	struct rte_mempool *mbuf_pool;
33320c78ac9SDavid Hunt 	uint16_t portid;
334d42b1300SDavid Hunt 	struct core_info *ci;
33520c78ac9SDavid Hunt 
3368db653ffSAlan Carew 
33799a968faSDavid Hunt 	ret = core_info_init();
33899a968faSDavid Hunt 	if (ret < 0)
33999a968faSDavid Hunt 		rte_panic("Cannot allocate core info\n");
34099a968faSDavid Hunt 
341d42b1300SDavid Hunt 	ci = get_core_info();
342d42b1300SDavid Hunt 
3438db653ffSAlan Carew 	ret = rte_eal_init(argc, argv);
3448db653ffSAlan Carew 	if (ret < 0)
3458db653ffSAlan Carew 		rte_panic("Cannot init EAL\n");
3468db653ffSAlan Carew 
3478db653ffSAlan Carew 	signal(SIGINT, sig_handler);
3488db653ffSAlan Carew 	signal(SIGTERM, sig_handler);
3498db653ffSAlan Carew 
35020c78ac9SDavid Hunt 	argc -= ret;
35120c78ac9SDavid Hunt 	argv += ret;
35220c78ac9SDavid Hunt 
35320c78ac9SDavid Hunt 	/* parse application arguments (after the EAL ones) */
35420c78ac9SDavid Hunt 	ret = parse_args(argc, argv);
35520c78ac9SDavid Hunt 	if (ret < 0)
35620c78ac9SDavid Hunt 		rte_exit(EXIT_FAILURE, "Invalid arguments\n");
35720c78ac9SDavid Hunt 
358d9a42a69SThomas Monjalon 	nb_ports = rte_eth_dev_count_avail();
35920c78ac9SDavid Hunt 
360ace158c4SDavid Hunt 	if (nb_ports > 0) {
361ace158c4SDavid Hunt 		mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL",
362ace158c4SDavid Hunt 				NUM_MBUFS * nb_ports, MBUF_CACHE_SIZE, 0,
363ace158c4SDavid Hunt 				RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
36420c78ac9SDavid Hunt 
36520c78ac9SDavid Hunt 		if (mbuf_pool == NULL)
36620c78ac9SDavid Hunt 			rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
36720c78ac9SDavid Hunt 
36820c78ac9SDavid Hunt 		/* Initialize ports. */
3698728ccf3SThomas Monjalon 		RTE_ETH_FOREACH_DEV(portid) {
3706d13ea8eSOlivier Matz 			struct rte_ether_addr eth;
371c9a47791SDavid Hunt 			int w, j;
372a032a081SDavid Coyle 			int ret;
373c9a47791SDavid Hunt 
37420c78ac9SDavid Hunt 			if ((enabled_port_mask & (1 << portid)) == 0)
37520c78ac9SDavid Hunt 				continue;
376c9a47791SDavid Hunt 
377c9a47791SDavid Hunt 			eth.addr_bytes[0] = 0xe0;
378c9a47791SDavid Hunt 			eth.addr_bytes[1] = 0xe0;
379c9a47791SDavid Hunt 			eth.addr_bytes[2] = 0xe0;
380c9a47791SDavid Hunt 			eth.addr_bytes[3] = 0xe0;
381c9a47791SDavid Hunt 			eth.addr_bytes[4] = portid + 0xf0;
382c9a47791SDavid Hunt 
38320c78ac9SDavid Hunt 			if (port_init(portid, mbuf_pool) != 0)
384ace158c4SDavid Hunt 				rte_exit(EXIT_FAILURE,
385ace158c4SDavid Hunt 					"Cannot init port %"PRIu8 "\n",
38620c78ac9SDavid Hunt 					portid);
387c9a47791SDavid Hunt 
38838d232b9SBruce Richardson 			for (w = 0; w < RTE_POWER_MAX_VFS; w++) {
389c9a47791SDavid Hunt 				eth.addr_bytes[5] = w + 0xf0;
390c9a47791SDavid Hunt 
39170b2c7f1SDavid Christensen 				ret = -ENOTSUP;
392a8d0d473SBruce Richardson #ifdef RTE_NET_IXGBE
393c9a47791SDavid Hunt 				ret = rte_pmd_ixgbe_set_vf_mac_addr(portid,
394c9a47791SDavid Hunt 							w, &eth);
39570b2c7f1SDavid Christensen #endif
396a8d0d473SBruce Richardson #ifdef RTE_NET_I40E
397c9a47791SDavid Hunt 				if (ret == -ENOTSUP)
398ace158c4SDavid Hunt 					ret = rte_pmd_i40e_set_vf_mac_addr(
399ace158c4SDavid Hunt 							portid, w, &eth);
40070b2c7f1SDavid Christensen #endif
401a8d0d473SBruce Richardson #ifdef RTE_NET_BNXT
402c9a47791SDavid Hunt 				if (ret == -ENOTSUP)
403ace158c4SDavid Hunt 					ret = rte_pmd_bnxt_set_vf_mac_addr(
404ace158c4SDavid Hunt 							portid, w, &eth);
40570b2c7f1SDavid Christensen #endif
406c9a47791SDavid Hunt 
407c9a47791SDavid Hunt 				switch (ret) {
408c9a47791SDavid Hunt 				case 0:
409c9a47791SDavid Hunt 					printf("Port %d VF %d MAC: ",
410c9a47791SDavid Hunt 							portid, w);
411ace158c4SDavid Hunt 					for (j = 0; j < 5; j++) {
412ace158c4SDavid Hunt 						printf("%02x:",
413ace158c4SDavid Hunt 							eth.addr_bytes[j]);
414ace158c4SDavid Hunt 					}
415ace158c4SDavid Hunt 					printf("%02x\n", eth.addr_bytes[5]);
416ace158c4SDavid Hunt 					break;
417c9a47791SDavid Hunt 				}
418c9a47791SDavid Hunt 				printf("\n");
419c9a47791SDavid Hunt 			}
420c9a47791SDavid Hunt 		}
42120c78ac9SDavid Hunt 	}
42220c78ac9SDavid Hunt 
423d42b1300SDavid Hunt 	check_all_ports_link_status(enabled_port_mask);
424d42b1300SDavid Hunt 
4258db653ffSAlan Carew 	lcore_id = rte_get_next_lcore(-1, 1, 0);
4268db653ffSAlan Carew 	if (lcore_id == RTE_MAX_LCORE) {
427*ec8fb569SStephen Hemminger 		fprintf(stderr, "A minimum of three cores are required to run application\n");
4288db653ffSAlan Carew 		return 0;
4298db653ffSAlan Carew 	}
430d42b1300SDavid Hunt 	printf("Running channel monitor on lcore id %d\n", lcore_id);
4318db653ffSAlan Carew 	rte_eal_remote_launch(run_monitor, NULL, lcore_id);
4328db653ffSAlan Carew 
433d42b1300SDavid Hunt 	lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
434d42b1300SDavid Hunt 	if (lcore_id == RTE_MAX_LCORE) {
435*ec8fb569SStephen Hemminger 		fprintf(stderr, "A minimum of three cores are required to run application\n");
436d42b1300SDavid Hunt 		return 0;
437d42b1300SDavid Hunt 	}
4388db653ffSAlan Carew 	if (power_manager_init() < 0) {
439*ec8fb569SStephen Hemminger 		fprintf(stderr, "Unable to initialize power manager\n");
4408db653ffSAlan Carew 		return -1;
4418db653ffSAlan Carew 	}
4428db653ffSAlan Carew 	if (channel_manager_init(CHANNEL_MGR_DEFAULT_HV_PATH) < 0) {
443*ec8fb569SStephen Hemminger 		fprintf(stderr, "Unable to initialize channel manager\n");
4448db653ffSAlan Carew 		return -1;
4458db653ffSAlan Carew 	}
446d42b1300SDavid Hunt 
447221e7026SMarcin Hajkowski 	add_host_channels();
4483618326fSDavid Hunt 
449d42b1300SDavid Hunt 	printf("Running core monitor on lcore id %d\n", lcore_id);
450d42b1300SDavid Hunt 	rte_eal_remote_launch(run_core_monitor, NULL, lcore_id);
451d42b1300SDavid Hunt 
4528db653ffSAlan Carew 	run_cli(NULL);
4538db653ffSAlan Carew 
454d42b1300SDavid Hunt 	branch_monitor_exit();
455d42b1300SDavid Hunt 
4568db653ffSAlan Carew 	rte_eal_mp_wait_lcore();
457d42b1300SDavid Hunt 
458d42b1300SDavid Hunt 	free(ci->cd);
459d42b1300SDavid Hunt 
46010aa3757SChengchang Tang 	/* clean up the EAL */
46110aa3757SChengchang Tang 	rte_eal_cleanup();
46210aa3757SChengchang Tang 
4638db653ffSAlan Carew 	return 0;
4648db653ffSAlan Carew }
465