1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2017 Brocade Communications Systems, Inc. 5 * Author: Jan Blunck <[email protected]> 6 */ 7 8 #ifndef _RTE_ETHDEV_VDEV_H_ 9 #define _RTE_ETHDEV_VDEV_H_ 10 11 #include <rte_config.h> 12 #include <rte_malloc.h> 13 #include <rte_bus_vdev.h> 14 #include <rte_ethdev_driver.h> 15 16 /** 17 * @internal 18 * Allocates a new ethdev slot for an ethernet device and returns the pointer 19 * to that slot for the driver to use. 20 * 21 * @param dev 22 * Pointer to virtual device 23 * 24 * @param private_data_size 25 * Size of private data structure 26 * 27 * @return 28 * A pointer to a rte_eth_dev or NULL if allocation failed. 29 */ 30 static inline struct rte_eth_dev * 31 rte_eth_vdev_allocate(struct rte_vdev_device *dev, size_t private_data_size) 32 { 33 struct rte_eth_dev *eth_dev; 34 const char *name = rte_vdev_device_name(dev); 35 36 eth_dev = rte_eth_dev_allocate(name); 37 if (!eth_dev) 38 return NULL; 39 40 if (private_data_size) { 41 eth_dev->data->dev_private = rte_zmalloc_socket(name, 42 private_data_size, RTE_CACHE_LINE_SIZE, 43 dev->device.numa_node); 44 if (!eth_dev->data->dev_private) { 45 rte_eth_dev_release_port(eth_dev); 46 return NULL; 47 } 48 } 49 50 eth_dev->device = &dev->device; 51 eth_dev->intr_handle = NULL; 52 53 eth_dev->data->kdrv = RTE_KDRV_NONE; 54 eth_dev->data->numa_node = dev->device.numa_node; 55 return eth_dev; 56 } 57 58 #endif /* _RTE_ETHDEV_VDEV_H_ */ 59