* This function is based on probe() function in virtio_pci.c * It returns 0 on success. */
| 1930 | * It returns 0 on success. |
| 1931 | */ |
| 1932 | int |
| 1933 | eth_virtio_dev_init(struct rte_eth_dev *eth_dev) |
| 1934 | { |
| 1935 | struct virtio_hw *hw = eth_dev->data->dev_private; |
| 1936 | uint32_t speed = RTE_ETH_SPEED_NUM_UNKNOWN; |
| 1937 | int vectorized = 0; |
| 1938 | int ret; |
| 1939 | |
| 1940 | if (sizeof(struct virtio_net_hdr_mrg_rxbuf) > RTE_PKTMBUF_HEADROOM) { |
| 1941 | PMD_INIT_LOG(ERR, |
| 1942 | "Not sufficient headroom required = %d, avail = %d", |
| 1943 | (int)sizeof(struct virtio_net_hdr_mrg_rxbuf), |
| 1944 | RTE_PKTMBUF_HEADROOM); |
| 1945 | |
| 1946 | return -1; |
| 1947 | } |
| 1948 | |
| 1949 | eth_dev->dev_ops = &virtio_eth_dev_ops; |
| 1950 | |
| 1951 | if (rte_eal_process_type() == RTE_PROC_SECONDARY) { |
| 1952 | set_rxtx_funcs(eth_dev); |
| 1953 | return 0; |
| 1954 | } |
| 1955 | |
| 1956 | ret = virtio_dev_devargs_parse(eth_dev->device->devargs, &speed, &vectorized); |
| 1957 | if (ret < 0) |
| 1958 | return ret; |
| 1959 | hw->speed = speed; |
| 1960 | hw->duplex = DUPLEX_UNKNOWN; |
| 1961 | |
| 1962 | /* Allocate memory for storing MAC addresses */ |
| 1963 | eth_dev->data->mac_addrs = rte_zmalloc("virtio", |
| 1964 | VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN, 0); |
| 1965 | if (eth_dev->data->mac_addrs == NULL) { |
| 1966 | PMD_INIT_LOG(ERR, |
| 1967 | "Failed to allocate %d bytes needed to store MAC addresses", |
| 1968 | VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN); |
| 1969 | return -ENOMEM; |
| 1970 | } |
| 1971 | |
| 1972 | rte_spinlock_init(&hw->state_lock); |
| 1973 | |
| 1974 | if (vectorized) { |
| 1975 | hw->use_vec_rx = 1; |
| 1976 | hw->use_vec_tx = 1; |
| 1977 | } |
| 1978 | |
| 1979 | /* reset device and negotiate default features */ |
| 1980 | ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES); |
| 1981 | if (ret < 0) |
| 1982 | goto err_virtio_init; |
| 1983 | |
| 1984 | if (vectorized) { |
| 1985 | if (!virtio_with_packed_queue(hw)) { |
| 1986 | hw->use_vec_tx = 0; |
| 1987 | } else { |
| 1988 | #if !defined(CC_AVX512_SUPPORT) && !defined(RTE_ARCH_ARM) |
| 1989 | hw->use_vec_rx = 0; |
no test coverage detected