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