src/dpdk/drivers/net/virtio/virtio_ethdev.c
int
eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
{
	struct virtio_hw *hw = eth_dev->data->dev_private;
	uint32_t speed = ETH_SPEED_NUM_UNKNOWN;
	int vectorized = 0;
	int ret;

	if (sizeof(struct virtio_net_hdr_mrg_rxbuf) > RTE_PKTMBUF_HEADROOM) {
		PMD_INIT_LOG(ERR,
			"Not sufficient headroom required = %d, avail = %d",
			(int)sizeof(struct virtio_net_hdr_mrg_rxbuf),
			RTE_PKTMBUF_HEADROOM);

		return -1;
	}

	eth_dev->dev_ops = &virtio_eth_dev_ops;
	eth_dev->rx_descriptor_done = virtio_dev_rx_queue_done;

	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
		set_rxtx_funcs(eth_dev);
		return 0;
	}

	ret = virtio_dev_devargs_parse(eth_dev->device->devargs, &speed, &vectorized);
	if (ret < 0)
		return ret;
	hw->speed = speed;

	/* Allocate memory for storing MAC addresses */
	eth_dev->data->mac_addrs = rte_zmalloc("virtio",
				VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN, 0);
	if (eth_dev->data->mac_addrs == NULL) {
		PMD_INIT_LOG(ERR,
			"Failed to allocate %d bytes needed to store MAC addresses",
			VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN);
		return -ENOMEM;
	}

	rte_spinlock_init(&hw->state_lock);

	/* reset device and negotiate default features */
	ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
	if (ret < 0)
		goto err_virtio_init;

	if (vectorized) {
		if (!virtio_with_packed_queue(hw)) {
			hw->use_vec_rx = 1;
		} else {
#if defined(CC_AVX512_SUPPORT) || defined(RTE_ARCH_ARM)
			hw->use_vec_rx = 1;
			hw->use_vec_tx = 1;
#else
			PMD_DRV_LOG(INFO,
				"building environment do not support packed ring vectorized");
#endif
		}
	}

	hw->opened = 1;

	return 0;

err_virtio_init:
	rte_free(eth_dev->data->mac_addrs);
	eth_dev->data->mac_addrs = NULL;
	return ret;
}
/*
 * This function is based on probe() function in virtio_pci.c
 * It returns 0 on success.
 */
This function is based on probe() function in virtio_pci.c
It returns 0 on success.
This function is based on probe () function in virtio_pci . c It returns 0 on success .
int
eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
{
	struct virtio_hw *hw = eth_dev->data->dev_private;
	uint32_t speed = ETH_SPEED_NUM_UNKNOWN;
	int vectorized = 0;
	int ret;
	if (sizeof(struct virtio_net_hdr_mrg_rxbuf) > RTE_PKTMBUF_HEADROOM) {
		PMD_INIT_LOG(ERR,
			"Not sufficient headroom required = %d, avail = %d",
			(int)sizeof(struct virtio_net_hdr_mrg_rxbuf),
			RTE_PKTMBUF_HEADROOM);
		return -1;
	}
	eth_dev->dev_ops = &virtio_eth_dev_ops;
	eth_dev->rx_descriptor_done = virtio_dev_rx_queue_done;
	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
		set_rxtx_funcs(eth_dev);
		return 0;
	}
	ret = virtio_dev_devargs_parse(eth_dev->device->devargs, &speed, &vectorized);
	if (ret < 0)
		return ret;
	hw->speed = speed;
	eth_dev->data->mac_addrs = rte_zmalloc("virtio",
				VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN, 0);
	if (eth_dev->data->mac_addrs == NULL) {
		PMD_INIT_LOG(ERR,
			"Failed to allocate %d bytes needed to store MAC addresses",
			VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN);
		return -ENOMEM;
	}
	rte_spinlock_init(&hw->state_lock);
	ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
	if (ret < 0)
		goto err_virtio_init;
	if (vectorized) {
		if (!virtio_with_packed_queue(hw)) {
			hw->use_vec_rx = 1;
		} else {
#if defined(CC_AVX512_SUPPORT) || defined(RTE_ARCH_ARM)
			hw->use_vec_rx = 1;
			hw->use_vec_tx = 1;
#else
			PMD_DRV_LOG(INFO,
				"building environment do not support packed ring vectorized");
#endif
		}
	}
	hw->opened = 1;
	return 0;
err_virtio_init:
	rte_free(eth_dev->data->mac_addrs);
	eth_dev->data->mac_addrs = NULL;
	return ret;
}
int eth_virtio_dev_init ( struct rte_eth_dev * eth_dev ) { struct virtio_hw * hw = eth_dev -> data -> dev_private ; uint32_t speed = ETH_SPEED_NUM_UNKNOWN ; int vectorized = 0 ; int ret ; if ( sizeof ( struct virtio_net_hdr_mrg_rxbuf ) > RTE_PKTMBUF_HEADROOM ) { PMD_INIT_LOG ( ERR , " " , ( int ) sizeof ( struct virtio_net_hdr_mrg_rxbuf ) , RTE_PKTMBUF_HEADROOM ) ; return -1 ; } eth_dev -> dev_ops = & virtio_eth_dev_ops ; eth_dev -> rx_descriptor_done = virtio_dev_rx_queue_done ; if ( rte_eal_process_type ( ) == RTE_PROC_SECONDARY ) { set_rxtx_funcs ( eth_dev ) ; return 0 ; } ret = virtio_dev_devargs_parse ( eth_dev -> device -> devargs , & speed , & vectorized ) ; if ( ret < 0 ) return ret ; hw -> speed = speed ; eth_dev -> data -> mac_addrs = rte_zmalloc ( " " , VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN , 0 ) ; if ( eth_dev -> data -> mac_addrs == NULL ) { PMD_INIT_LOG ( ERR , " " , VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN ) ; return - ENOMEM ; } rte_spinlock_init ( & hw -> state_lock ) ; ret = virtio_init_device ( eth_dev , VIRTIO_PMD_DEFAULT_GUEST_FEATURES ) ; if ( ret < 0 ) goto err_virtio_init ; if ( vectorized ) { if ( ! virtio_with_packed_queue ( hw ) ) { hw -> use_vec_rx = 1 ; } else { #if defined ( CC_AVX512_SUPPORT ) || defined ( RTE_ARCH_ARM ) hw -> use_vec_rx = 1 ; hw -> use_vec_tx = 1 ; #else PMD_DRV_LOG ( INFO , " " ) ; #endif } } hw -> opened = 1 ; return 0 ; err_virtio_init : rte_free ( eth_dev -> data -> mac_addrs ) ; eth_dev -> data -> mac_addrs = NULL ; return ret ; }
This function is based on probe() function in virtio_pci.c
 It returns 0 on success.
This function is based on probe () function in virtio_pci . c It returns 0 on success .
/* Allocate memory for storing MAC addresses */ /* reset device and negotiate default features */