1*99a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2*99a2dd95SBruce Richardson * Copyright(c) 2016-2017 Cavium, Inc 3*99a2dd95SBruce Richardson */ 4*99a2dd95SBruce Richardson 5*99a2dd95SBruce Richardson #ifndef _RTE_EVENTDEV_PMD_PCI_H_ 6*99a2dd95SBruce Richardson #define _RTE_EVENTDEV_PMD_PCI_H_ 7*99a2dd95SBruce Richardson 8*99a2dd95SBruce Richardson /** @file 9*99a2dd95SBruce Richardson * RTE Eventdev PCI PMD APIs 10*99a2dd95SBruce Richardson * 11*99a2dd95SBruce Richardson * @note 12*99a2dd95SBruce Richardson * These API are from event PCI PMD only and user applications should not call 13*99a2dd95SBruce Richardson * them directly. 14*99a2dd95SBruce Richardson */ 15*99a2dd95SBruce Richardson 16*99a2dd95SBruce Richardson 17*99a2dd95SBruce Richardson #ifdef __cplusplus 18*99a2dd95SBruce Richardson extern "C" { 19*99a2dd95SBruce Richardson #endif 20*99a2dd95SBruce Richardson 21*99a2dd95SBruce Richardson #include <string.h> 22*99a2dd95SBruce Richardson 23*99a2dd95SBruce Richardson #include <rte_config.h> 24*99a2dd95SBruce Richardson #include <rte_eal.h> 25*99a2dd95SBruce Richardson #include <rte_lcore.h> 26*99a2dd95SBruce Richardson #include <rte_pci.h> 27*99a2dd95SBruce Richardson #include <rte_bus_pci.h> 28*99a2dd95SBruce Richardson 29*99a2dd95SBruce Richardson #include "eventdev_pmd.h" 30*99a2dd95SBruce Richardson 31*99a2dd95SBruce Richardson typedef int (*eventdev_pmd_pci_callback_t)(struct rte_eventdev *dev); 32*99a2dd95SBruce Richardson 33*99a2dd95SBruce Richardson /** 34*99a2dd95SBruce Richardson * @internal 35*99a2dd95SBruce Richardson * Wrapper for use by pci drivers as a .probe function to attach to an event 36*99a2dd95SBruce Richardson * interface. Same as rte_event_pmd_pci_probe, except caller can specify 37*99a2dd95SBruce Richardson * the name. 38*99a2dd95SBruce Richardson */ 39*99a2dd95SBruce Richardson __rte_experimental 40*99a2dd95SBruce Richardson static inline int 41*99a2dd95SBruce Richardson rte_event_pmd_pci_probe_named(struct rte_pci_driver *pci_drv, 42*99a2dd95SBruce Richardson struct rte_pci_device *pci_dev, 43*99a2dd95SBruce Richardson size_t private_data_size, 44*99a2dd95SBruce Richardson eventdev_pmd_pci_callback_t devinit, 45*99a2dd95SBruce Richardson const char *name) 46*99a2dd95SBruce Richardson { 47*99a2dd95SBruce Richardson struct rte_eventdev *eventdev; 48*99a2dd95SBruce Richardson int retval; 49*99a2dd95SBruce Richardson 50*99a2dd95SBruce Richardson if (devinit == NULL) 51*99a2dd95SBruce Richardson return -EINVAL; 52*99a2dd95SBruce Richardson 53*99a2dd95SBruce Richardson eventdev = rte_event_pmd_allocate(name, 54*99a2dd95SBruce Richardson pci_dev->device.numa_node); 55*99a2dd95SBruce Richardson if (eventdev == NULL) 56*99a2dd95SBruce Richardson return -ENOMEM; 57*99a2dd95SBruce Richardson 58*99a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 59*99a2dd95SBruce Richardson eventdev->data->dev_private = 60*99a2dd95SBruce Richardson rte_zmalloc_socket( 61*99a2dd95SBruce Richardson "eventdev private structure", 62*99a2dd95SBruce Richardson private_data_size, 63*99a2dd95SBruce Richardson RTE_CACHE_LINE_SIZE, 64*99a2dd95SBruce Richardson rte_socket_id()); 65*99a2dd95SBruce Richardson 66*99a2dd95SBruce Richardson if (eventdev->data->dev_private == NULL) 67*99a2dd95SBruce Richardson rte_panic("Cannot allocate memzone for private " 68*99a2dd95SBruce Richardson "device data"); 69*99a2dd95SBruce Richardson } 70*99a2dd95SBruce Richardson 71*99a2dd95SBruce Richardson eventdev->dev = &pci_dev->device; 72*99a2dd95SBruce Richardson 73*99a2dd95SBruce Richardson /* Invoke PMD device initialization function */ 74*99a2dd95SBruce Richardson retval = devinit(eventdev); 75*99a2dd95SBruce Richardson if (retval == 0) 76*99a2dd95SBruce Richardson return 0; 77*99a2dd95SBruce Richardson 78*99a2dd95SBruce Richardson RTE_EDEV_LOG_ERR("driver %s: (vendor_id=0x%x device_id=0x%x)" 79*99a2dd95SBruce Richardson " failed", pci_drv->driver.name, 80*99a2dd95SBruce Richardson (unsigned int) pci_dev->id.vendor_id, 81*99a2dd95SBruce Richardson (unsigned int) pci_dev->id.device_id); 82*99a2dd95SBruce Richardson 83*99a2dd95SBruce Richardson rte_event_pmd_release(eventdev); 84*99a2dd95SBruce Richardson 85*99a2dd95SBruce Richardson return -ENXIO; 86*99a2dd95SBruce Richardson } 87*99a2dd95SBruce Richardson 88*99a2dd95SBruce Richardson /** 89*99a2dd95SBruce Richardson * @internal 90*99a2dd95SBruce Richardson * Wrapper for use by pci drivers as a .probe function to attach to a event 91*99a2dd95SBruce Richardson * interface. 92*99a2dd95SBruce Richardson */ 93*99a2dd95SBruce Richardson static inline int 94*99a2dd95SBruce Richardson rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv, 95*99a2dd95SBruce Richardson struct rte_pci_device *pci_dev, 96*99a2dd95SBruce Richardson size_t private_data_size, 97*99a2dd95SBruce Richardson eventdev_pmd_pci_callback_t devinit) 98*99a2dd95SBruce Richardson { 99*99a2dd95SBruce Richardson char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN]; 100*99a2dd95SBruce Richardson 101*99a2dd95SBruce Richardson rte_pci_device_name(&pci_dev->addr, eventdev_name, 102*99a2dd95SBruce Richardson sizeof(eventdev_name)); 103*99a2dd95SBruce Richardson 104*99a2dd95SBruce Richardson return rte_event_pmd_pci_probe_named(pci_drv, 105*99a2dd95SBruce Richardson pci_dev, 106*99a2dd95SBruce Richardson private_data_size, 107*99a2dd95SBruce Richardson devinit, 108*99a2dd95SBruce Richardson eventdev_name); 109*99a2dd95SBruce Richardson } 110*99a2dd95SBruce Richardson 111*99a2dd95SBruce Richardson /** 112*99a2dd95SBruce Richardson * @internal 113*99a2dd95SBruce Richardson * Wrapper for use by pci drivers as a .remove function to detach a event 114*99a2dd95SBruce Richardson * interface. 115*99a2dd95SBruce Richardson */ 116*99a2dd95SBruce Richardson static inline int 117*99a2dd95SBruce Richardson rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev, 118*99a2dd95SBruce Richardson eventdev_pmd_pci_callback_t devuninit) 119*99a2dd95SBruce Richardson { 120*99a2dd95SBruce Richardson struct rte_eventdev *eventdev; 121*99a2dd95SBruce Richardson char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN]; 122*99a2dd95SBruce Richardson int ret = 0; 123*99a2dd95SBruce Richardson 124*99a2dd95SBruce Richardson if (pci_dev == NULL) 125*99a2dd95SBruce Richardson return -EINVAL; 126*99a2dd95SBruce Richardson 127*99a2dd95SBruce Richardson rte_pci_device_name(&pci_dev->addr, eventdev_name, 128*99a2dd95SBruce Richardson sizeof(eventdev_name)); 129*99a2dd95SBruce Richardson 130*99a2dd95SBruce Richardson eventdev = rte_event_pmd_get_named_dev(eventdev_name); 131*99a2dd95SBruce Richardson if (eventdev == NULL) 132*99a2dd95SBruce Richardson return -ENODEV; 133*99a2dd95SBruce Richardson 134*99a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 135*99a2dd95SBruce Richardson ret = rte_event_dev_close(eventdev->data->dev_id); 136*99a2dd95SBruce Richardson if (ret < 0) 137*99a2dd95SBruce Richardson return ret; 138*99a2dd95SBruce Richardson } 139*99a2dd95SBruce Richardson 140*99a2dd95SBruce Richardson /* Invoke PMD device un-init function */ 141*99a2dd95SBruce Richardson if (devuninit) 142*99a2dd95SBruce Richardson ret = devuninit(eventdev); 143*99a2dd95SBruce Richardson if (ret) 144*99a2dd95SBruce Richardson return ret; 145*99a2dd95SBruce Richardson 146*99a2dd95SBruce Richardson /* Free event device */ 147*99a2dd95SBruce Richardson rte_event_pmd_release(eventdev); 148*99a2dd95SBruce Richardson 149*99a2dd95SBruce Richardson eventdev->dev = NULL; 150*99a2dd95SBruce Richardson 151*99a2dd95SBruce Richardson return 0; 152*99a2dd95SBruce Richardson } 153*99a2dd95SBruce Richardson 154*99a2dd95SBruce Richardson #ifdef __cplusplus 155*99a2dd95SBruce Richardson } 156*99a2dd95SBruce Richardson #endif 157*99a2dd95SBruce Richardson 158*99a2dd95SBruce Richardson #endif /* _RTE_EVENTDEV_PMD_PCI_H_ */ 159