xref: /dpdk/lib/eventdev/eventdev_pmd_pci.h (revision 23d06e3766a82b97ff97bdd7021cbddc5e9ccc7e)
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 
1899a2dd95SBruce Richardson #include <rte_config.h>
1999a2dd95SBruce Richardson #include <rte_eal.h>
2099a2dd95SBruce Richardson #include <rte_lcore.h>
2199a2dd95SBruce Richardson #include <rte_pci.h>
2299a2dd95SBruce Richardson #include <rte_bus_pci.h>
2399a2dd95SBruce Richardson 
2499a2dd95SBruce Richardson #include "eventdev_pmd.h"
2599a2dd95SBruce Richardson 
2699a2dd95SBruce Richardson typedef int (*eventdev_pmd_pci_callback_t)(struct rte_eventdev *dev);
2799a2dd95SBruce Richardson 
2899a2dd95SBruce Richardson /**
2999a2dd95SBruce Richardson  * @internal
3099a2dd95SBruce Richardson  * Wrapper for use by pci drivers as a .probe function to attach to an event
3199a2dd95SBruce Richardson  * interface.  Same as rte_event_pmd_pci_probe, except caller can specify
3299a2dd95SBruce Richardson  * the name.
3399a2dd95SBruce Richardson  */
34*23d06e37SPavan Nikhilesh __rte_internal
3599a2dd95SBruce Richardson static inline int
3699a2dd95SBruce Richardson rte_event_pmd_pci_probe_named(struct rte_pci_driver *pci_drv,
3799a2dd95SBruce Richardson 			      struct rte_pci_device *pci_dev,
3899a2dd95SBruce Richardson 			      size_t private_data_size,
3999a2dd95SBruce Richardson 			      eventdev_pmd_pci_callback_t devinit,
4099a2dd95SBruce Richardson 			      const char *name)
4199a2dd95SBruce Richardson {
4299a2dd95SBruce Richardson 	struct rte_eventdev *eventdev;
4399a2dd95SBruce Richardson 	int retval;
4499a2dd95SBruce Richardson 
4599a2dd95SBruce Richardson 	if (devinit == NULL)
4699a2dd95SBruce Richardson 		return -EINVAL;
4799a2dd95SBruce Richardson 
4899a2dd95SBruce Richardson 	eventdev = rte_event_pmd_allocate(name,
4999a2dd95SBruce Richardson 			 pci_dev->device.numa_node);
5099a2dd95SBruce Richardson 	if (eventdev == NULL)
5199a2dd95SBruce Richardson 		return -ENOMEM;
5299a2dd95SBruce Richardson 
5399a2dd95SBruce Richardson 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
5499a2dd95SBruce Richardson 		eventdev->data->dev_private =
5599a2dd95SBruce Richardson 				rte_zmalloc_socket(
5699a2dd95SBruce Richardson 						"eventdev private structure",
5799a2dd95SBruce Richardson 						private_data_size,
5899a2dd95SBruce Richardson 						RTE_CACHE_LINE_SIZE,
5999a2dd95SBruce Richardson 						rte_socket_id());
6099a2dd95SBruce Richardson 
6199a2dd95SBruce Richardson 		if (eventdev->data->dev_private == NULL)
6299a2dd95SBruce Richardson 			rte_panic("Cannot allocate memzone for private "
6399a2dd95SBruce Richardson 					"device data");
6499a2dd95SBruce Richardson 	}
6599a2dd95SBruce Richardson 
6699a2dd95SBruce Richardson 	eventdev->dev = &pci_dev->device;
6799a2dd95SBruce Richardson 
6899a2dd95SBruce Richardson 	/* Invoke PMD device initialization function */
6999a2dd95SBruce Richardson 	retval = devinit(eventdev);
7099a2dd95SBruce Richardson 	if (retval == 0)
7199a2dd95SBruce Richardson 		return 0;
7299a2dd95SBruce Richardson 
7399a2dd95SBruce Richardson 	RTE_EDEV_LOG_ERR("driver %s: (vendor_id=0x%x device_id=0x%x)"
7499a2dd95SBruce Richardson 			" failed", pci_drv->driver.name,
7599a2dd95SBruce Richardson 			(unsigned int) pci_dev->id.vendor_id,
7699a2dd95SBruce Richardson 			(unsigned int) pci_dev->id.device_id);
7799a2dd95SBruce Richardson 
7899a2dd95SBruce Richardson 	rte_event_pmd_release(eventdev);
7999a2dd95SBruce Richardson 
8099a2dd95SBruce Richardson 	return -ENXIO;
8199a2dd95SBruce Richardson }
8299a2dd95SBruce Richardson 
8399a2dd95SBruce Richardson /**
8499a2dd95SBruce Richardson  * @internal
8599a2dd95SBruce Richardson  * Wrapper for use by pci drivers as a .probe function to attach to a event
8699a2dd95SBruce Richardson  * interface.
8799a2dd95SBruce Richardson  */
88*23d06e37SPavan Nikhilesh __rte_internal
8999a2dd95SBruce Richardson static inline int
9099a2dd95SBruce Richardson rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv,
9199a2dd95SBruce Richardson 			    struct rte_pci_device *pci_dev,
9299a2dd95SBruce Richardson 			    size_t private_data_size,
9399a2dd95SBruce Richardson 			    eventdev_pmd_pci_callback_t devinit)
9499a2dd95SBruce Richardson {
9599a2dd95SBruce Richardson 	char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
9699a2dd95SBruce Richardson 
9799a2dd95SBruce Richardson 	rte_pci_device_name(&pci_dev->addr, eventdev_name,
9899a2dd95SBruce Richardson 			sizeof(eventdev_name));
9999a2dd95SBruce Richardson 
10099a2dd95SBruce Richardson 	return rte_event_pmd_pci_probe_named(pci_drv,
10199a2dd95SBruce Richardson 					     pci_dev,
10299a2dd95SBruce Richardson 					     private_data_size,
10399a2dd95SBruce Richardson 					     devinit,
10499a2dd95SBruce Richardson 					     eventdev_name);
10599a2dd95SBruce Richardson }
10699a2dd95SBruce Richardson 
10799a2dd95SBruce Richardson /**
10899a2dd95SBruce Richardson  * @internal
10999a2dd95SBruce Richardson  * Wrapper for use by pci drivers as a .remove function to detach a event
11099a2dd95SBruce Richardson  * interface.
11199a2dd95SBruce Richardson  */
112*23d06e37SPavan Nikhilesh __rte_internal
11399a2dd95SBruce Richardson static inline int
11499a2dd95SBruce Richardson rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev,
11599a2dd95SBruce Richardson 			     eventdev_pmd_pci_callback_t devuninit)
11699a2dd95SBruce Richardson {
11799a2dd95SBruce Richardson 	struct rte_eventdev *eventdev;
11899a2dd95SBruce Richardson 	char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
11999a2dd95SBruce Richardson 	int ret = 0;
12099a2dd95SBruce Richardson 
12199a2dd95SBruce Richardson 	if (pci_dev == NULL)
12299a2dd95SBruce Richardson 		return -EINVAL;
12399a2dd95SBruce Richardson 
12499a2dd95SBruce Richardson 	rte_pci_device_name(&pci_dev->addr, eventdev_name,
12599a2dd95SBruce Richardson 			sizeof(eventdev_name));
12699a2dd95SBruce Richardson 
12799a2dd95SBruce Richardson 	eventdev = rte_event_pmd_get_named_dev(eventdev_name);
12899a2dd95SBruce Richardson 	if (eventdev == NULL)
12999a2dd95SBruce Richardson 		return -ENODEV;
13099a2dd95SBruce Richardson 
13199a2dd95SBruce Richardson 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
13299a2dd95SBruce Richardson 		ret = rte_event_dev_close(eventdev->data->dev_id);
13399a2dd95SBruce Richardson 		if (ret < 0)
13499a2dd95SBruce Richardson 			return ret;
13599a2dd95SBruce Richardson 	}
13699a2dd95SBruce Richardson 
13799a2dd95SBruce Richardson 	/* Invoke PMD device un-init function */
13899a2dd95SBruce Richardson 	if (devuninit)
13999a2dd95SBruce Richardson 		ret = devuninit(eventdev);
14099a2dd95SBruce Richardson 	if (ret)
14199a2dd95SBruce Richardson 		return ret;
14299a2dd95SBruce Richardson 
14399a2dd95SBruce Richardson 	/* Free event device */
14499a2dd95SBruce Richardson 	rte_event_pmd_release(eventdev);
14599a2dd95SBruce Richardson 
14699a2dd95SBruce Richardson 	eventdev->dev = NULL;
14799a2dd95SBruce Richardson 
14899a2dd95SBruce Richardson 	return 0;
14999a2dd95SBruce Richardson }
15099a2dd95SBruce Richardson 
15199a2dd95SBruce Richardson #endif /* _RTE_EVENTDEV_PMD_PCI_H_ */
152