199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2017 Brocade Communications Systems, Inc. 399a2dd95SBruce Richardson * Author: Jan Blunck <[email protected]> 499a2dd95SBruce Richardson */ 599a2dd95SBruce Richardson 699a2dd95SBruce Richardson #ifndef _RTE_ETHDEV_VDEV_H_ 799a2dd95SBruce Richardson #define _RTE_ETHDEV_VDEV_H_ 899a2dd95SBruce Richardson 999a2dd95SBruce Richardson #include <rte_config.h> 1099a2dd95SBruce Richardson #include <rte_malloc.h> 1199a2dd95SBruce Richardson #include <rte_bus_vdev.h> 1299a2dd95SBruce Richardson #include <ethdev_driver.h> 1399a2dd95SBruce Richardson 1499a2dd95SBruce Richardson /** 1599a2dd95SBruce Richardson * @internal 16*0d9f56a8SAndrew Rybchenko * Allocates a new ethdev slot for an Ethernet device and returns the pointer 1799a2dd95SBruce Richardson * to that slot for the driver to use. 1899a2dd95SBruce Richardson * 1999a2dd95SBruce Richardson * @param dev 2099a2dd95SBruce Richardson * Pointer to virtual device 2199a2dd95SBruce Richardson * 2299a2dd95SBruce Richardson * @param private_data_size 2399a2dd95SBruce Richardson * Size of private data structure 2499a2dd95SBruce Richardson * 2599a2dd95SBruce Richardson * @return 2699a2dd95SBruce Richardson * A pointer to a rte_eth_dev or NULL if allocation failed. 2799a2dd95SBruce Richardson */ 2899a2dd95SBruce Richardson static inline struct rte_eth_dev * 2999a2dd95SBruce Richardson rte_eth_vdev_allocate(struct rte_vdev_device *dev, size_t private_data_size) 3099a2dd95SBruce Richardson { 3199a2dd95SBruce Richardson struct rte_eth_dev *eth_dev; 3299a2dd95SBruce Richardson const char *name = rte_vdev_device_name(dev); 3399a2dd95SBruce Richardson 3499a2dd95SBruce Richardson eth_dev = rte_eth_dev_allocate(name); 3599a2dd95SBruce Richardson if (!eth_dev) 3699a2dd95SBruce Richardson return NULL; 3799a2dd95SBruce Richardson 3899a2dd95SBruce Richardson if (private_data_size) { 3999a2dd95SBruce Richardson eth_dev->data->dev_private = rte_zmalloc_socket(name, 4099a2dd95SBruce Richardson private_data_size, RTE_CACHE_LINE_SIZE, 4199a2dd95SBruce Richardson dev->device.numa_node); 4299a2dd95SBruce Richardson if (!eth_dev->data->dev_private) { 4399a2dd95SBruce Richardson rte_eth_dev_release_port(eth_dev); 4499a2dd95SBruce Richardson return NULL; 4599a2dd95SBruce Richardson } 4699a2dd95SBruce Richardson } 4799a2dd95SBruce Richardson 4899a2dd95SBruce Richardson eth_dev->device = &dev->device; 4999a2dd95SBruce Richardson eth_dev->intr_handle = NULL; 5099a2dd95SBruce Richardson 5199a2dd95SBruce Richardson eth_dev->data->numa_node = dev->device.numa_node; 5299a2dd95SBruce Richardson return eth_dev; 5399a2dd95SBruce Richardson } 5499a2dd95SBruce Richardson 5599a2dd95SBruce Richardson #endif /* _RTE_ETHDEV_VDEV_H_ */ 56