DPDK  20.11.10
rte_eventdev_pmd_pci.h
Go to the documentation of this file.
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 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #include <string.h>
26 
27 #include <rte_config.h>
28 #include <rte_eal.h>
29 #include <rte_lcore.h>
30 #include <rte_pci.h>
31 #include <rte_bus_pci.h>
32 
33 #include "rte_eventdev_pmd.h"
34 
35 typedef int (*eventdev_pmd_pci_callback_t)(struct rte_eventdev *dev);
36 
43 __rte_experimental
44 static inline int
45 rte_event_pmd_pci_probe_named(struct rte_pci_driver *pci_drv,
46  struct rte_pci_device *pci_dev,
47  size_t private_data_size,
48  eventdev_pmd_pci_callback_t devinit,
49  const char *name)
50 {
51  struct rte_eventdev *eventdev;
52  int retval;
53 
54  if (devinit == NULL)
55  return -EINVAL;
56 
57  eventdev = rte_event_pmd_allocate(name,
58  pci_dev->device.numa_node);
59  if (eventdev == NULL)
60  return -ENOMEM;
61 
62  if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
63  eventdev->data->dev_private =
65  "eventdev private structure",
66  private_data_size,
67  RTE_CACHE_LINE_SIZE,
68  rte_socket_id());
69 
70  if (eventdev->data->dev_private == NULL)
71  rte_panic("Cannot allocate memzone for private "
72  "device data");
73  }
74 
75  eventdev->dev = &pci_dev->device;
76 
77  /* Invoke PMD device initialization function */
78  retval = devinit(eventdev);
79  if (retval == 0)
80  return 0;
81 
82  RTE_EDEV_LOG_ERR("driver %s: (vendor_id=0x%x device_id=0x%x)"
83  " failed", pci_drv->driver.name,
84  (unsigned int) pci_dev->id.vendor_id,
85  (unsigned int) pci_dev->id.device_id);
86 
87  rte_event_pmd_release(eventdev);
88 
89  return -ENXIO;
90 }
91 
97 static inline int
98 rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv,
99  struct rte_pci_device *pci_dev,
100  size_t private_data_size,
101  eventdev_pmd_pci_callback_t devinit)
102 {
103  char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
104 
105  rte_pci_device_name(&pci_dev->addr, eventdev_name,
106  sizeof(eventdev_name));
107 
108  return rte_event_pmd_pci_probe_named(pci_drv,
109  pci_dev,
110  private_data_size,
111  devinit,
112  eventdev_name);
113 }
114 
120 static inline int
121 rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev,
122  eventdev_pmd_pci_callback_t devuninit)
123 {
124  struct rte_eventdev *eventdev;
125  char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
126  int ret = 0;
127 
128  if (pci_dev == NULL)
129  return -EINVAL;
130 
131  rte_pci_device_name(&pci_dev->addr, eventdev_name,
132  sizeof(eventdev_name));
133 
134  eventdev = rte_event_pmd_get_named_dev(eventdev_name);
135  if (eventdev == NULL)
136  return -ENODEV;
137 
138  if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
139  ret = rte_event_dev_close(eventdev->data->dev_id);
140  if (ret < 0)
141  return ret;
142  }
143 
144  /* Invoke PMD device un-init function */
145  if (devuninit)
146  ret = devuninit(eventdev);
147  if (ret)
148  return ret;
149 
150  /* Free event device */
151  rte_event_pmd_release(eventdev);
152 
153  eventdev->dev = NULL;
154 
155  return 0;
156 }
157 
158 #ifdef __cplusplus
159 }
160 #endif
161 
162 #endif /* _RTE_EVENTDEV_PMD_PCI_H_ */
enum rte_proc_type_t rte_eal_process_type(void)
int rte_event_pmd_release(struct rte_eventdev *eventdev)
unsigned int rte_socket_id(void)
struct rte_eventdev * rte_event_pmd_allocate(const char *name, int socket_id)
static struct rte_eventdev * rte_event_pmd_get_named_dev(const char *name)
#define rte_panic(...)
Definition: rte_debug.h:43
int rte_event_dev_close(uint8_t dev_id)
void * rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket) __rte_alloc_size(2)
void rte_pci_device_name(const struct rte_pci_addr *addr, char *output, size_t size)