示例#1
0
/* initialize rte devices and check the number of available ports */
static uint8_t init_rte_dev(void)
{
	uint8_t nb_ports;
	struct rte_eth_dev_info dev_info;


	/* initialize driver(s) */
	TGEN_PANIC(rte_ixgbe_pmd_init() < 0, "\tError: Cannot init ixgbe pmd\n");

	if (tgen_cfg.flags & TGSF_USE_VF) {
		TGEN_PANIC(rte_ixgbevf_pmd_init() < 0, "\tError: cannot init ixgbevf pmd\n");
	}

	TGEN_PANIC(rte_eal_pci_probe() < 0, "\tError: Cannot probe PCI\n");

	/* get available ports configuration */
	nb_ports = rte_eth_dev_count();
	TGEN_PANIC(nb_ports == 0, "\tError: DPDK could not find any port\n");
	mprintf("\tDPDK has found %u ports\n", nb_ports);

	if (nb_ports > TGEN_MAX_PORTS) {
		mprintf("\tWarning: I can deal with at most %u ports."
		        " Please update TGEN_MAX_PORTS and recompile.\n", TGEN_MAX_PORTS);

		nb_ports = TGEN_MAX_PORTS;
	}

	TGEN_PANIC(tgen_used_port_mask & ~((1U << nb_ports) - 1),
	           "\tError: invalid port(s) specified, used port mask is %#10x\n", tgen_used_port_mask);

	/* read max TX queues per port */
	for (uint8_t port_id = 0; port_id < nb_ports; ++port_id) {
		/* skip ports that are not enabled */
		if ((tgen_used_port_mask & (1U << port_id)) == 0) {
			continue;
		}
		rte_eth_dev_info_get(port_id, &dev_info);
		tgen_port_conf[port_id].max_tx_queue = dev_info.max_tx_queues;
		mprintf("\tPort %u, Max TX queue = %u\n", port_id, dev_info.max_tx_queues);
		if (strcmp(dev_info.driver_name, "rte_ixgbe_pmd") == 0) {
			tgen_port_conf[port_id].type = PORT_IXGBE;
		}
		else {
			tgen_port_conf[port_id].type = PORT_IGB;
		}
	}

	return nb_ports;
}
示例#2
0
/* Main function, does initialisation and calls the per-lcore functions */
int
MAIN(int argc, char *argv[])
{
	unsigned cores;
	struct rte_mempool *mbuf_pool;
	unsigned lcore_id;
	uintptr_t i;
	int ret;
	unsigned nb_ports, valid_num_ports;
	uint8_t portid;

#ifndef RTE_EXEC_ENV_BAREMETAL
	signal(SIGHUP, sighup_handler);
#endif

	/* init EAL */
	ret = rte_eal_init(argc, argv);
	if (ret < 0)
		rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
	argc -= ret;
	argv += ret;

	/* parse app arguments */
	ret = vmdq_parse_args(argc, argv);
	if (ret < 0)
		rte_exit(EXIT_FAILURE, "Invalid VMDQ argument\n");

	if (rte_ixgbe_pmd_init() != 0 ||
			rte_eal_pci_probe() != 0)
		rte_exit(EXIT_FAILURE, "Error with NIC driver initialization\n");
	
	cores = rte_lcore_count();
	if ((cores & (cores - 1)) != 0 || cores > 128) {
		rte_exit(EXIT_FAILURE,"This program can only run on an even"
				"number of cores(1-128)\n\n");
	}
	
	nb_ports = rte_eth_dev_count();
	if (nb_ports > RTE_MAX_ETHPORTS)
		nb_ports = RTE_MAX_ETHPORTS;

        /* 
	 * Update the global var NUM_PORTS and global array PORTS 
	 * and get value of var VALID_NUM_PORTS according to system ports number 
	 */
	valid_num_ports = check_ports_num(nb_ports);
 
	if (valid_num_ports < 2 || valid_num_ports % 2) {
		printf("Current valid ports number is %u\n", valid_num_ports);
		rte_exit(EXIT_FAILURE, "Error with valid ports number is not even or less than 2\n");
	}

	mbuf_pool = rte_mempool_create("MBUF_POOL", NUM_MBUFS * nb_ports,
				       MBUF_SIZE, MBUF_CACHE_SIZE,
				       sizeof(struct rte_pktmbuf_pool_private),
				       rte_pktmbuf_pool_init, NULL,
				       rte_pktmbuf_init, NULL,
				       rte_socket_id(), 0);
	if (mbuf_pool == NULL)
		rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");

	/* initialize all ports */
	for (portid = 0; portid < nb_ports; portid++) {
		/* skip ports that are not enabled */
		if ((enabled_port_mask & (1 << portid)) == 0) {
			printf("\nSkipping disabled port %d\n", portid);
			continue;
		}
		if (port_init(portid, mbuf_pool) != 0) 
			rte_exit(EXIT_FAILURE, "Cannot initialize network ports\n");
	}

	/* call lcore_main() on every slave lcore */
	i = 0;
	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
		rte_eal_remote_launch(lcore_main, (void*)i++, lcore_id);
	}
	/* call on master too */
	(void) lcore_main((void*)i);

	return 0;
}
示例#3
0
static void
app_init_nics(void)
{
	uint32_t socket, lcore;
	uint8_t	port, queue;
	struct ether_addr mac_addr;
	int ret;

	/* Init driver */
	printf("Initializing the PMD driver ...\n");
#ifdef RTE_LIBRTE_IGB_PMD
	if (rte_igb_pmd_init() < 0) {
		rte_panic("Cannot init IGB PMD\n");
	}
#endif
#ifdef RTE_LIBRTE_IXGBE_PMD
	if (rte_ixgbe_pmd_init() < 0) {
		rte_panic("Cannot init IXGBE PMD\n");
	}
#endif
	if (rte_eal_pci_probe() < 0) {
		rte_panic("Cannot probe PCI\n");
	}

	memset(port_stat,0,sizeof(struct port_stat)*MAX_PORT_NUM);
	/* Init NIC ports and queues, then start the ports */
	for (port = 0; port < APP_MAX_NIC_PORTS; port ++) {
		struct rte_eth_link link;
		struct rte_mempool *pool;
		uint32_t n_rx_queues, n_tx_queues;

		n_rx_queues = app_get_nic_rx_queues_per_port(port);
		n_tx_queues = app.nic_tx_port_mask[port];

		if ((n_rx_queues == 0) && (n_tx_queues == 0)) {
			continue;
		}

		/* Init port */
		printf("Initializing NIC port %u ...\n", (uint32_t) port);
		ret = rte_eth_dev_configure(
			port,
			(uint8_t) n_rx_queues,
			(uint8_t) n_tx_queues,
			&port_conf);
		if (ret < 0) {
			rte_panic("Cannot init NIC port %u (%d)\n", (uint32_t) port, ret);
		}
		rte_eth_promiscuous_enable(port);

		/* Init RX queues */
		for (queue = 0; queue < APP_MAX_RX_QUEUES_PER_NIC_PORT; queue ++) {
			if (app.nic_rx_queue_mask[port][queue] == 0) {
				continue;
			}

			app_get_lcore_for_nic_rx(port, queue, &lcore);
			socket = rte_lcore_to_socket_id(lcore);
			pool = app.lcore_params[lcore].pool;

			printf("Initializing NIC port %u RX queue %u ...\n",
				(uint32_t) port,
				(uint32_t) queue);
			ret = rte_eth_rx_queue_setup(
				port,
				queue,
				(uint16_t) app.nic_rx_ring_size,
				socket,
				&rx_conf,
				pool);
			if (ret < 0) {
				rte_panic("Cannot init RX queue %u for port %u (%d)\n",
					(uint32_t) queue,
					(uint32_t) port,
					ret);
			}
		}

		/* Init TX queues */
		
		if (app.nic_tx_port_mask[port] == 1) {
			app_get_lcore_for_nic_tx(port, &lcore);
			socket = rte_lcore_to_socket_id(lcore);
			printf("Initializing NIC port %u TX queue 0 ...\n",
				(uint32_t) port);
			ret = rte_eth_tx_queue_setup(
				port,
				0,
				(uint16_t) app.nic_tx_ring_size,
				socket,
				&tx_conf);
			if (ret < 0) {
				rte_panic("Cannot init TX queue 0 for port %d (%d)\n",
					port,
					ret);
			}
		}
		

		/* Start port */
		ret = rte_eth_dev_start(port);
		if (ret < 0) {
			rte_panic("Cannot start port %d (%d)\n", port, ret);
		}

		/* Get link status */
		rte_eth_link_get(port, &link);
		rte_eth_macaddr_get(port,&mac_addr);
		int i=0;
		for(i=0;i<5;i++)
			printf("%02x:",mac_addr.addr_bytes[i]);
		printf("%02x\n",mac_addr.addr_bytes[i]);
		memcpy(port_stat[port].mac_addr,mac_addr.addr_bytes,6);
		for(i=0;i<5;i++)
			printf("%02x:",port_stat[port].mac_addr[i]);
		printf("%02x\n",port_stat[port].mac_addr[i]);
		if (link.link_status) {
			printf("Port %u is UP (%u Mbps)\n",
				(uint32_t) port,
				(unsigned) link.link_speed);
			port_stat[port].port_status=1;
			port_stat[port].port_speed=link.link_speed;
		} else {
			printf("Port %u is DOWN\n",
				(uint32_t) port);
			port_stat[port].port_status=0;
		}
	}
}