199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2017 Brocade Communications Systems, Inc. 399a2dd95SBruce Richardson * Author: Jan Blunck <jblunck@infradead.org> 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> 114851ef2bSDavid Marchand #include <bus_vdev_driver.h> 1299a2dd95SBruce Richardson #include <ethdev_driver.h> 1399a2dd95SBruce Richardson 14*719834a6SMattias Rönnblom #ifdef __cplusplus 15*719834a6SMattias Rönnblom extern "C" { 16*719834a6SMattias Rönnblom #endif 17*719834a6SMattias Rönnblom 1899a2dd95SBruce Richardson /** 1999a2dd95SBruce Richardson * @internal 200d9f56a8SAndrew Rybchenko * Allocates a new ethdev slot for an Ethernet device and returns the pointer 2199a2dd95SBruce Richardson * to that slot for the driver to use. 2299a2dd95SBruce Richardson * 2399a2dd95SBruce Richardson * @param dev 2499a2dd95SBruce Richardson * Pointer to virtual device 2599a2dd95SBruce Richardson * 2699a2dd95SBruce Richardson * @param private_data_size 2799a2dd95SBruce Richardson * Size of private data structure 2899a2dd95SBruce Richardson * 2999a2dd95SBruce Richardson * @return 3099a2dd95SBruce Richardson * A pointer to a rte_eth_dev or NULL if allocation failed. 3199a2dd95SBruce Richardson */ 3299a2dd95SBruce Richardson static inline struct rte_eth_dev * 3399a2dd95SBruce Richardson rte_eth_vdev_allocate(struct rte_vdev_device *dev, size_t private_data_size) 3499a2dd95SBruce Richardson { 3599a2dd95SBruce Richardson struct rte_eth_dev *eth_dev; 3699a2dd95SBruce Richardson const char *name = rte_vdev_device_name(dev); 3799a2dd95SBruce Richardson 3899a2dd95SBruce Richardson eth_dev = rte_eth_dev_allocate(name); 3999a2dd95SBruce Richardson if (!eth_dev) 4099a2dd95SBruce Richardson return NULL; 4199a2dd95SBruce Richardson 4299a2dd95SBruce Richardson if (private_data_size) { 4399a2dd95SBruce Richardson eth_dev->data->dev_private = rte_zmalloc_socket(name, 4499a2dd95SBruce Richardson private_data_size, RTE_CACHE_LINE_SIZE, 4599a2dd95SBruce Richardson dev->device.numa_node); 4699a2dd95SBruce Richardson if (!eth_dev->data->dev_private) { 4799a2dd95SBruce Richardson rte_eth_dev_release_port(eth_dev); 4899a2dd95SBruce Richardson return NULL; 4999a2dd95SBruce Richardson } 5099a2dd95SBruce Richardson } 5199a2dd95SBruce Richardson 5299a2dd95SBruce Richardson eth_dev->device = &dev->device; 5399a2dd95SBruce Richardson eth_dev->intr_handle = NULL; 5499a2dd95SBruce Richardson 5599a2dd95SBruce Richardson eth_dev->data->numa_node = dev->device.numa_node; 5699a2dd95SBruce Richardson return eth_dev; 5799a2dd95SBruce Richardson } 5899a2dd95SBruce Richardson 59dbf9fc1dSBrian Dooley #ifdef __cplusplus 60dbf9fc1dSBrian Dooley } 61dbf9fc1dSBrian Dooley #endif 62dbf9fc1dSBrian Dooley 6399a2dd95SBruce Richardson #endif /* _RTE_ETHDEV_VDEV_H_ */ 64