DPDK  19.02.0
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  ret = rte_event_dev_close(eventdev->data->dev_id);
116  if (ret < 0)
117  return ret;
118 
119  /* Invoke PMD device un-init function */
120  if (devuninit)
121  ret = devuninit(eventdev);
122  if (ret)
123  return ret;
124 
125  /* Free event device */
126  rte_event_pmd_release(eventdev);
127 
128  eventdev->dev = NULL;
129 
130  return 0;
131 }
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif /* _RTE_EVENTDEV_PMD_PCI_H_ */