net/virtio: fix incorrect cast of void *
[dpdk.git] / eventdev / eventdev_pmd_pci.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2017 Cavium, Inc
3  */
4
5 #ifndef _RTE_EVENTDEV_PMD_PCI_H_
6 #define _RTE_EVENTDEV_PMD_PCI_H_
7
8 /** @file
9  * RTE Eventdev PCI PMD APIs
10  *
11  * @note
12  * These API are from event PCI PMD only and user applications should not call
13  * them directly.
14  */
15
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 #include <string.h>
22
23 #include <rte_config.h>
24 #include <rte_eal.h>
25 #include <rte_lcore.h>
26 #include <rte_pci.h>
27 #include <rte_bus_pci.h>
28
29 #include "eventdev_pmd.h"
30
31 typedef int (*eventdev_pmd_pci_callback_t)(struct rte_eventdev *dev);
32
33 /**
34  * @internal
35  * Wrapper for use by pci drivers as a .probe function to attach to an event
36  * interface.  Same as rte_event_pmd_pci_probe, except caller can specify
37  * the name.
38  */
39 __rte_experimental
40 static inline int
41 rte_event_pmd_pci_probe_named(struct rte_pci_driver *pci_drv,
42                               struct rte_pci_device *pci_dev,
43                               size_t private_data_size,
44                               eventdev_pmd_pci_callback_t devinit,
45                               const char *name)
46 {
47         struct rte_eventdev *eventdev;
48         int retval;
49
50         if (devinit == NULL)
51                 return -EINVAL;
52
53         eventdev = rte_event_pmd_allocate(name,
54                          pci_dev->device.numa_node);
55         if (eventdev == NULL)
56                 return -ENOMEM;
57
58         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
59                 eventdev->data->dev_private =
60                                 rte_zmalloc_socket(
61                                                 "eventdev private structure",
62                                                 private_data_size,
63                                                 RTE_CACHE_LINE_SIZE,
64                                                 rte_socket_id());
65
66                 if (eventdev->data->dev_private == NULL)
67                         rte_panic("Cannot allocate memzone for private "
68                                         "device data");
69         }
70
71         eventdev->dev = &pci_dev->device;
72
73         /* Invoke PMD device initialization function */
74         retval = devinit(eventdev);
75         if (retval == 0)
76                 return 0;
77
78         RTE_EDEV_LOG_ERR("driver %s: (vendor_id=0x%x device_id=0x%x)"
79                         " failed", pci_drv->driver.name,
80                         (unsigned int) pci_dev->id.vendor_id,
81                         (unsigned int) pci_dev->id.device_id);
82
83         rte_event_pmd_release(eventdev);
84
85         return -ENXIO;
86 }
87
88 /**
89  * @internal
90  * Wrapper for use by pci drivers as a .probe function to attach to a event
91  * interface.
92  */
93 static inline int
94 rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv,
95                             struct rte_pci_device *pci_dev,
96                             size_t private_data_size,
97                             eventdev_pmd_pci_callback_t devinit)
98 {
99         char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
100
101         rte_pci_device_name(&pci_dev->addr, eventdev_name,
102                         sizeof(eventdev_name));
103
104         return rte_event_pmd_pci_probe_named(pci_drv,
105                                              pci_dev,
106                                              private_data_size,
107                                              devinit,
108                                              eventdev_name);
109 }
110
111 /**
112  * @internal
113  * Wrapper for use by pci drivers as a .remove function to detach a event
114  * interface.
115  */
116 static inline int
117 rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev,
118                              eventdev_pmd_pci_callback_t devuninit)
119 {
120         struct rte_eventdev *eventdev;
121         char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
122         int ret = 0;
123
124         if (pci_dev == NULL)
125                 return -EINVAL;
126
127         rte_pci_device_name(&pci_dev->addr, eventdev_name,
128                         sizeof(eventdev_name));
129
130         eventdev = rte_event_pmd_get_named_dev(eventdev_name);
131         if (eventdev == NULL)
132                 return -ENODEV;
133
134         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
135                 ret = rte_event_dev_close(eventdev->data->dev_id);
136                 if (ret < 0)
137                         return ret;
138         }
139
140         /* Invoke PMD device un-init function */
141         if (devuninit)
142                 ret = devuninit(eventdev);
143         if (ret)
144                 return ret;
145
146         /* Free event device */
147         rte_event_pmd_release(eventdev);
148
149         eventdev->dev = NULL;
150
151         return 0;
152 }
153
154 #ifdef __cplusplus
155 }
156 #endif
157
158 #endif /* _RTE_EVENTDEV_PMD_PCI_H_ */