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
8*2c552933SBrian Dooley #ifdef __cplusplus
9*2c552933SBrian Dooley extern "C" {
10*2c552933SBrian Dooley #endif
11*2c552933SBrian Dooley
1299a2dd95SBruce Richardson /** @file
1399a2dd95SBruce Richardson * RTE Eventdev PCI PMD APIs
1499a2dd95SBruce Richardson *
1599a2dd95SBruce Richardson * @note
1699a2dd95SBruce Richardson * These API are from event PCI PMD only and user applications should not call
1799a2dd95SBruce Richardson * them directly.
1899a2dd95SBruce Richardson */
1999a2dd95SBruce Richardson
2099a2dd95SBruce Richardson #include <string.h>
2199a2dd95SBruce Richardson
2299a2dd95SBruce Richardson #include <rte_config.h>
2399a2dd95SBruce Richardson #include <rte_eal.h>
2499a2dd95SBruce Richardson #include <rte_lcore.h>
2599a2dd95SBruce Richardson #include <rte_pci.h>
2699a2dd95SBruce Richardson #include <rte_bus_pci.h>
2799a2dd95SBruce Richardson
2899a2dd95SBruce Richardson #include "eventdev_pmd.h"
2999a2dd95SBruce Richardson
3099a2dd95SBruce Richardson typedef int (*eventdev_pmd_pci_callback_t)(struct rte_eventdev *dev);
3199a2dd95SBruce Richardson
3299a2dd95SBruce Richardson /**
3399a2dd95SBruce Richardson * @internal
3499a2dd95SBruce Richardson * Wrapper for use by pci drivers as a .probe function to attach to an event
3599a2dd95SBruce Richardson * interface. Same as rte_event_pmd_pci_probe, except caller can specify
3699a2dd95SBruce Richardson * the name.
3799a2dd95SBruce Richardson */
3823d06e37SPavan Nikhilesh __rte_internal
3999a2dd95SBruce Richardson static inline int
rte_event_pmd_pci_probe_named(struct rte_pci_driver * pci_drv,struct rte_pci_device * pci_dev,size_t private_data_size,eventdev_pmd_pci_callback_t devinit,const char * name)4099a2dd95SBruce Richardson rte_event_pmd_pci_probe_named(struct rte_pci_driver *pci_drv,
4199a2dd95SBruce Richardson struct rte_pci_device *pci_dev,
4299a2dd95SBruce Richardson size_t private_data_size,
4399a2dd95SBruce Richardson eventdev_pmd_pci_callback_t devinit,
4499a2dd95SBruce Richardson const char *name)
4599a2dd95SBruce Richardson {
4699a2dd95SBruce Richardson struct rte_eventdev *eventdev;
4799a2dd95SBruce Richardson int retval;
4899a2dd95SBruce Richardson
4999a2dd95SBruce Richardson if (devinit == NULL)
5099a2dd95SBruce Richardson return -EINVAL;
5199a2dd95SBruce Richardson
5299a2dd95SBruce Richardson eventdev = rte_event_pmd_allocate(name,
5399a2dd95SBruce Richardson pci_dev->device.numa_node);
5499a2dd95SBruce Richardson if (eventdev == NULL)
5599a2dd95SBruce Richardson return -ENOMEM;
5699a2dd95SBruce Richardson
5799a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
5899a2dd95SBruce Richardson eventdev->data->dev_private =
5999a2dd95SBruce Richardson rte_zmalloc_socket(
6099a2dd95SBruce Richardson "eventdev private structure",
6199a2dd95SBruce Richardson private_data_size,
6299a2dd95SBruce Richardson RTE_CACHE_LINE_SIZE,
6399a2dd95SBruce Richardson rte_socket_id());
6499a2dd95SBruce Richardson
6599a2dd95SBruce Richardson if (eventdev->data->dev_private == NULL)
6699a2dd95SBruce Richardson rte_panic("Cannot allocate memzone for private "
6799a2dd95SBruce Richardson "device data");
6899a2dd95SBruce Richardson }
6999a2dd95SBruce Richardson
7099a2dd95SBruce Richardson eventdev->dev = &pci_dev->device;
7199a2dd95SBruce Richardson
7299a2dd95SBruce Richardson /* Invoke PMD device initialization function */
7399a2dd95SBruce Richardson retval = devinit(eventdev);
74d35e6132SPavan Nikhilesh if (retval == 0) {
75d35e6132SPavan Nikhilesh event_dev_probing_finish(eventdev);
7699a2dd95SBruce Richardson return 0;
77d35e6132SPavan Nikhilesh }
7899a2dd95SBruce Richardson
7999a2dd95SBruce Richardson RTE_EDEV_LOG_ERR("driver %s: (vendor_id=0x%x device_id=0x%x)"
8099a2dd95SBruce Richardson " failed", pci_drv->driver.name,
8199a2dd95SBruce Richardson (unsigned int) pci_dev->id.vendor_id,
8299a2dd95SBruce Richardson (unsigned int) pci_dev->id.device_id);
8399a2dd95SBruce Richardson
8499a2dd95SBruce Richardson rte_event_pmd_release(eventdev);
8599a2dd95SBruce Richardson
8699a2dd95SBruce Richardson return -ENXIO;
8799a2dd95SBruce Richardson }
8899a2dd95SBruce Richardson
8999a2dd95SBruce Richardson /**
9099a2dd95SBruce Richardson * @internal
9199a2dd95SBruce Richardson * Wrapper for use by pci drivers as a .probe function to attach to a event
9299a2dd95SBruce Richardson * interface.
9399a2dd95SBruce Richardson */
9423d06e37SPavan Nikhilesh __rte_internal
9599a2dd95SBruce Richardson static inline int
rte_event_pmd_pci_probe(struct rte_pci_driver * pci_drv,struct rte_pci_device * pci_dev,size_t private_data_size,eventdev_pmd_pci_callback_t devinit)9699a2dd95SBruce Richardson rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv,
9799a2dd95SBruce Richardson struct rte_pci_device *pci_dev,
9899a2dd95SBruce Richardson size_t private_data_size,
9999a2dd95SBruce Richardson eventdev_pmd_pci_callback_t devinit)
10099a2dd95SBruce Richardson {
10199a2dd95SBruce Richardson char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
10299a2dd95SBruce Richardson
10399a2dd95SBruce Richardson rte_pci_device_name(&pci_dev->addr, eventdev_name,
10499a2dd95SBruce Richardson sizeof(eventdev_name));
10599a2dd95SBruce Richardson
10699a2dd95SBruce Richardson return rte_event_pmd_pci_probe_named(pci_drv,
10799a2dd95SBruce Richardson pci_dev,
10899a2dd95SBruce Richardson private_data_size,
10999a2dd95SBruce Richardson devinit,
11099a2dd95SBruce Richardson eventdev_name);
11199a2dd95SBruce Richardson }
11299a2dd95SBruce Richardson
11399a2dd95SBruce Richardson /**
11499a2dd95SBruce Richardson * @internal
11599a2dd95SBruce Richardson * Wrapper for use by pci drivers as a .remove function to detach a event
11699a2dd95SBruce Richardson * interface.
11799a2dd95SBruce Richardson */
11823d06e37SPavan Nikhilesh __rte_internal
11999a2dd95SBruce Richardson static inline int
rte_event_pmd_pci_remove(struct rte_pci_device * pci_dev,eventdev_pmd_pci_callback_t devuninit)12099a2dd95SBruce Richardson rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev,
12199a2dd95SBruce Richardson eventdev_pmd_pci_callback_t devuninit)
12299a2dd95SBruce Richardson {
12399a2dd95SBruce Richardson struct rte_eventdev *eventdev;
12499a2dd95SBruce Richardson char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
12599a2dd95SBruce Richardson int ret = 0;
12699a2dd95SBruce Richardson
12799a2dd95SBruce Richardson if (pci_dev == NULL)
12899a2dd95SBruce Richardson return -EINVAL;
12999a2dd95SBruce Richardson
13099a2dd95SBruce Richardson rte_pci_device_name(&pci_dev->addr, eventdev_name,
13199a2dd95SBruce Richardson sizeof(eventdev_name));
13299a2dd95SBruce Richardson
13399a2dd95SBruce Richardson eventdev = rte_event_pmd_get_named_dev(eventdev_name);
13499a2dd95SBruce Richardson if (eventdev == NULL)
13599a2dd95SBruce Richardson return -ENODEV;
13699a2dd95SBruce Richardson
13799a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
13899a2dd95SBruce Richardson ret = rte_event_dev_close(eventdev->data->dev_id);
13999a2dd95SBruce Richardson if (ret < 0)
14099a2dd95SBruce Richardson return ret;
14199a2dd95SBruce Richardson }
14299a2dd95SBruce Richardson
14399a2dd95SBruce Richardson /* Invoke PMD device un-init function */
14499a2dd95SBruce Richardson if (devuninit)
14599a2dd95SBruce Richardson ret = devuninit(eventdev);
14699a2dd95SBruce Richardson if (ret)
14799a2dd95SBruce Richardson return ret;
14899a2dd95SBruce Richardson
14999a2dd95SBruce Richardson /* Free event device */
15099a2dd95SBruce Richardson rte_event_pmd_release(eventdev);
15199a2dd95SBruce Richardson
15299a2dd95SBruce Richardson eventdev->dev = NULL;
15399a2dd95SBruce Richardson
15499a2dd95SBruce Richardson return 0;
15599a2dd95SBruce Richardson }
15699a2dd95SBruce Richardson
157*2c552933SBrian Dooley #ifdef __cplusplus
158*2c552933SBrian Dooley }
159*2c552933SBrian Dooley #endif
160*2c552933SBrian Dooley
16199a2dd95SBruce Richardson #endif /* _RTE_EVENTDEV_PMD_PCI_H_ */
162