DPDK  18.11.11
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 
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 "rte_eventdev_pmd.h"
30 
31 typedef int (*eventdev_pmd_pci_callback_t)(struct rte_eventdev *dev);
32 
38 static inline int
39 rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv,
40  struct rte_pci_device *pci_dev,
41  size_t private_data_size,
42  eventdev_pmd_pci_callback_t devinit)
43 {
44  struct rte_eventdev *eventdev;
45 
46  char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
47 
48  int retval;
49 
50  if (devinit == NULL)
51  return -EINVAL;
52 
53  rte_pci_device_name(&pci_dev->addr, eventdev_name,
54  sizeof(eventdev_name));
55 
56  eventdev = rte_event_pmd_allocate(eventdev_name,
57  pci_dev->device.numa_node);
58  if (eventdev == NULL)
59  return -ENOMEM;
60 
61  if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
62  eventdev->data->dev_private =
64  "eventdev private structure",
65  private_data_size,
66  RTE_CACHE_LINE_SIZE,
67  rte_socket_id());
68 
69  if (eventdev->data->dev_private == NULL)
70  rte_panic("Cannot allocate memzone for private "
71  "device data");
72  }
73 
74  eventdev->dev = &pci_dev->device;
75 
76  /* Invoke PMD device initialization function */
77  retval = devinit(eventdev);
78  if (retval == 0)
79  return 0;
80 
81  RTE_EDEV_LOG_ERR("driver %s: (vendor_id=0x%x device_id=0x%x)"
82  " failed", pci_drv->driver.name,
83  (unsigned int) pci_dev->id.vendor_id,
84  (unsigned int) pci_dev->id.device_id);
85 
86  rte_event_pmd_release(eventdev);
87 
88  return -ENXIO;
89 }
90 
91 
97 static inline int
98 rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev,
99  eventdev_pmd_pci_callback_t devuninit)
100 {
101  struct rte_eventdev *eventdev;
102  char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
103  int ret = 0;
104 
105  if (pci_dev == NULL)
106  return -EINVAL;
107 
108  rte_pci_device_name(&pci_dev->addr, eventdev_name,
109  sizeof(eventdev_name));
110 
111  eventdev = rte_event_pmd_get_named_dev(eventdev_name);
112  if (eventdev == NULL)
113  return -ENODEV;
114 
115  if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
116  ret = rte_event_dev_close(eventdev->data->dev_id);
117  if (ret < 0)
118  return ret;
119  }
120 
121  /* Invoke PMD device un-init function */
122  if (devuninit)
123  ret = devuninit(eventdev);
124  if (ret)
125  return ret;
126 
127  /* Free event device */
128  rte_event_pmd_release(eventdev);
129 
130  eventdev->dev = NULL;
131 
132  return 0;
133 }
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #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)
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:50
void * rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket)
int rte_event_dev_close(uint8_t dev_id)
void rte_pci_device_name(const struct rte_pci_addr *addr, char *output, size_t size)
unsigned rte_socket_id(void)