xref: /dpdk/lib/eventdev/eventdev_pmd_pci.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2016-2017 Cavium, Inc
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_EVENTDEV_PMD_PCI_H_
699a2dd95SBruce Richardson #define _RTE_EVENTDEV_PMD_PCI_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /** @file
999a2dd95SBruce Richardson  * RTE Eventdev PCI PMD APIs
1099a2dd95SBruce Richardson  *
1199a2dd95SBruce Richardson  * @note
1299a2dd95SBruce Richardson  * These API are from event PCI PMD only and user applications should not call
1399a2dd95SBruce Richardson  * them directly.
1499a2dd95SBruce Richardson  */
1599a2dd95SBruce Richardson 
1699a2dd95SBruce Richardson #include <string.h>
1799a2dd95SBruce Richardson 
181094dd94SDavid Marchand #include <rte_compat.h>
1999a2dd95SBruce Richardson #include <rte_config.h>
2099a2dd95SBruce Richardson #include <rte_eal.h>
2199a2dd95SBruce Richardson #include <rte_lcore.h>
2299a2dd95SBruce Richardson #include <rte_pci.h>
231f37cb2bSDavid Marchand #include <bus_pci_driver.h>
2499a2dd95SBruce Richardson 
2599a2dd95SBruce Richardson #include "eventdev_pmd.h"
2699a2dd95SBruce Richardson 
27*719834a6SMattias Rönnblom #ifdef __cplusplus
28*719834a6SMattias Rönnblom extern "C" {
29*719834a6SMattias Rönnblom #endif
30*719834a6SMattias Rönnblom 
3199a2dd95SBruce Richardson typedef int (*eventdev_pmd_pci_callback_t)(struct rte_eventdev *dev);
3299a2dd95SBruce Richardson 
3399a2dd95SBruce Richardson /**
3499a2dd95SBruce Richardson  * @internal
3599a2dd95SBruce Richardson  * Wrapper for use by pci drivers as a .probe function to attach to an event
3699a2dd95SBruce Richardson  * interface.  Same as rte_event_pmd_pci_probe, except caller can specify
3799a2dd95SBruce Richardson  * the name.
3899a2dd95SBruce Richardson  */
3923d06e37SPavan Nikhilesh __rte_internal
4099a2dd95SBruce Richardson static inline int
4199a2dd95SBruce Richardson rte_event_pmd_pci_probe_named(struct rte_pci_driver *pci_drv,
4299a2dd95SBruce Richardson 			      struct rte_pci_device *pci_dev,
4399a2dd95SBruce Richardson 			      size_t private_data_size,
4499a2dd95SBruce Richardson 			      eventdev_pmd_pci_callback_t devinit,
4599a2dd95SBruce Richardson 			      const char *name)
4699a2dd95SBruce Richardson {
4799a2dd95SBruce Richardson 	struct rte_eventdev *eventdev;
4899a2dd95SBruce Richardson 	int retval;
4999a2dd95SBruce Richardson 
5099a2dd95SBruce Richardson 	if (devinit == NULL)
5199a2dd95SBruce Richardson 		return -EINVAL;
5299a2dd95SBruce Richardson 
5399a2dd95SBruce Richardson 	eventdev = rte_event_pmd_allocate(name,
5499a2dd95SBruce Richardson 			 pci_dev->device.numa_node);
5599a2dd95SBruce Richardson 	if (eventdev == NULL)
5699a2dd95SBruce Richardson 		return -ENOMEM;
5799a2dd95SBruce Richardson 
5899a2dd95SBruce Richardson 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
5999a2dd95SBruce Richardson 		eventdev->data->dev_private =
6099a2dd95SBruce Richardson 				rte_zmalloc_socket(
6199a2dd95SBruce Richardson 						"eventdev private structure",
6299a2dd95SBruce Richardson 						private_data_size,
6399a2dd95SBruce Richardson 						RTE_CACHE_LINE_SIZE,
6499a2dd95SBruce Richardson 						rte_socket_id());
6599a2dd95SBruce Richardson 
6699a2dd95SBruce Richardson 		if (eventdev->data->dev_private == NULL)
6799a2dd95SBruce Richardson 			rte_panic("Cannot allocate memzone for private "
6899a2dd95SBruce Richardson 					"device data");
6999a2dd95SBruce Richardson 	}
7099a2dd95SBruce Richardson 
7199a2dd95SBruce Richardson 	eventdev->dev = &pci_dev->device;
7299a2dd95SBruce Richardson 
7399a2dd95SBruce Richardson 	/* Invoke PMD device initialization function */
7499a2dd95SBruce Richardson 	retval = devinit(eventdev);
75d35e6132SPavan Nikhilesh 	if (retval == 0) {
76d35e6132SPavan Nikhilesh 		event_dev_probing_finish(eventdev);
7799a2dd95SBruce Richardson 		return 0;
78d35e6132SPavan Nikhilesh 	}
7999a2dd95SBruce Richardson 
8099a2dd95SBruce Richardson 	RTE_EDEV_LOG_ERR("driver %s: (vendor_id=0x%x device_id=0x%x)"
8199a2dd95SBruce Richardson 			" failed", pci_drv->driver.name,
8299a2dd95SBruce Richardson 			(unsigned int) pci_dev->id.vendor_id,
8399a2dd95SBruce Richardson 			(unsigned int) pci_dev->id.device_id);
8499a2dd95SBruce Richardson 
8599a2dd95SBruce Richardson 	rte_event_pmd_release(eventdev);
8699a2dd95SBruce Richardson 
8799a2dd95SBruce Richardson 	return -ENXIO;
8899a2dd95SBruce Richardson }
8999a2dd95SBruce Richardson 
9099a2dd95SBruce Richardson /**
9199a2dd95SBruce Richardson  * @internal
9299a2dd95SBruce Richardson  * Wrapper for use by pci drivers as a .probe function to attach to a event
9399a2dd95SBruce Richardson  * interface.
9499a2dd95SBruce Richardson  */
9523d06e37SPavan Nikhilesh __rte_internal
9699a2dd95SBruce Richardson static inline int
9799a2dd95SBruce Richardson rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv,
9899a2dd95SBruce Richardson 			    struct rte_pci_device *pci_dev,
9999a2dd95SBruce Richardson 			    size_t private_data_size,
10099a2dd95SBruce Richardson 			    eventdev_pmd_pci_callback_t devinit)
10199a2dd95SBruce Richardson {
10299a2dd95SBruce Richardson 	char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
10399a2dd95SBruce Richardson 
10499a2dd95SBruce Richardson 	rte_pci_device_name(&pci_dev->addr, eventdev_name,
10599a2dd95SBruce Richardson 			sizeof(eventdev_name));
10699a2dd95SBruce Richardson 
10799a2dd95SBruce Richardson 	return rte_event_pmd_pci_probe_named(pci_drv,
10899a2dd95SBruce Richardson 					     pci_dev,
10999a2dd95SBruce Richardson 					     private_data_size,
11099a2dd95SBruce Richardson 					     devinit,
11199a2dd95SBruce Richardson 					     eventdev_name);
11299a2dd95SBruce Richardson }
11399a2dd95SBruce Richardson 
11499a2dd95SBruce Richardson /**
11599a2dd95SBruce Richardson  * @internal
11699a2dd95SBruce Richardson  * Wrapper for use by pci drivers as a .remove function to detach a event
11799a2dd95SBruce Richardson  * interface.
11899a2dd95SBruce Richardson  */
11923d06e37SPavan Nikhilesh __rte_internal
12099a2dd95SBruce Richardson static inline int
12199a2dd95SBruce Richardson rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev,
12299a2dd95SBruce Richardson 			     eventdev_pmd_pci_callback_t devuninit)
12399a2dd95SBruce Richardson {
12499a2dd95SBruce Richardson 	struct rte_eventdev *eventdev;
12599a2dd95SBruce Richardson 	char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
12699a2dd95SBruce Richardson 	int ret = 0;
12799a2dd95SBruce Richardson 
12899a2dd95SBruce Richardson 	if (pci_dev == NULL)
12999a2dd95SBruce Richardson 		return -EINVAL;
13099a2dd95SBruce Richardson 
13199a2dd95SBruce Richardson 	rte_pci_device_name(&pci_dev->addr, eventdev_name,
13299a2dd95SBruce Richardson 			sizeof(eventdev_name));
13399a2dd95SBruce Richardson 
13499a2dd95SBruce Richardson 	eventdev = rte_event_pmd_get_named_dev(eventdev_name);
13599a2dd95SBruce Richardson 	if (eventdev == NULL)
13699a2dd95SBruce Richardson 		return -ENODEV;
13799a2dd95SBruce Richardson 
13899a2dd95SBruce Richardson 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
13999a2dd95SBruce Richardson 		ret = rte_event_dev_close(eventdev->data->dev_id);
14099a2dd95SBruce Richardson 		if (ret < 0)
14199a2dd95SBruce Richardson 			return ret;
14299a2dd95SBruce Richardson 	}
14399a2dd95SBruce Richardson 
14499a2dd95SBruce Richardson 	/* Invoke PMD device un-init function */
14599a2dd95SBruce Richardson 	if (devuninit)
14699a2dd95SBruce Richardson 		ret = devuninit(eventdev);
14799a2dd95SBruce Richardson 	if (ret)
14899a2dd95SBruce Richardson 		return ret;
14999a2dd95SBruce Richardson 
15099a2dd95SBruce Richardson 	/* Free event device */
15199a2dd95SBruce Richardson 	rte_event_pmd_release(eventdev);
15299a2dd95SBruce Richardson 
15399a2dd95SBruce Richardson 	eventdev->dev = NULL;
15499a2dd95SBruce Richardson 
15599a2dd95SBruce Richardson 	return 0;
15699a2dd95SBruce Richardson }
15799a2dd95SBruce Richardson 
1582c552933SBrian Dooley #ifdef __cplusplus
1592c552933SBrian Dooley }
1602c552933SBrian Dooley #endif
1612c552933SBrian Dooley 
16299a2dd95SBruce Richardson #endif /* _RTE_EVENTDEV_PMD_PCI_H_ */
163