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