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