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_VDEV_H_ 6*99a2dd95SBruce Richardson #define _RTE_EVENTDEV_PMD_VDEV_H_ 7*99a2dd95SBruce Richardson 8*99a2dd95SBruce Richardson /** @file 9*99a2dd95SBruce Richardson * RTE Eventdev VDEV PMD APIs 10*99a2dd95SBruce Richardson * 11*99a2dd95SBruce Richardson * @note 12*99a2dd95SBruce Richardson * These API are from event VDEV PMD only and user applications should not call 13*99a2dd95SBruce Richardson * them directly. 14*99a2dd95SBruce Richardson */ 15*99a2dd95SBruce Richardson 16*99a2dd95SBruce Richardson #ifdef __cplusplus 17*99a2dd95SBruce Richardson extern "C" { 18*99a2dd95SBruce Richardson #endif 19*99a2dd95SBruce Richardson 20*99a2dd95SBruce Richardson #include <string.h> 21*99a2dd95SBruce Richardson 22*99a2dd95SBruce Richardson #include <rte_config.h> 23*99a2dd95SBruce Richardson #include <rte_debug.h> 24*99a2dd95SBruce Richardson #include <rte_eal.h> 25*99a2dd95SBruce Richardson #include <rte_bus_vdev.h> 26*99a2dd95SBruce Richardson 27*99a2dd95SBruce Richardson #include "eventdev_pmd.h" 28*99a2dd95SBruce Richardson 29*99a2dd95SBruce Richardson /** 30*99a2dd95SBruce Richardson * @internal 31*99a2dd95SBruce Richardson * Creates a new virtual event device and returns the pointer to that device. 32*99a2dd95SBruce Richardson * 33*99a2dd95SBruce Richardson * @param name 34*99a2dd95SBruce Richardson * PMD type name 35*99a2dd95SBruce Richardson * @param dev_private_size 36*99a2dd95SBruce Richardson * Size of event PMDs private data 37*99a2dd95SBruce Richardson * @param socket_id 38*99a2dd95SBruce Richardson * Socket to allocate resources on. 39*99a2dd95SBruce Richardson * 40*99a2dd95SBruce Richardson * @return 41*99a2dd95SBruce Richardson * - Eventdev pointer if device is successfully created. 42*99a2dd95SBruce Richardson * - NULL if device cannot be created. 43*99a2dd95SBruce Richardson */ 44*99a2dd95SBruce Richardson static inline struct rte_eventdev * 45*99a2dd95SBruce Richardson rte_event_pmd_vdev_init(const char *name, size_t dev_private_size, 46*99a2dd95SBruce Richardson int socket_id) 47*99a2dd95SBruce Richardson { 48*99a2dd95SBruce Richardson 49*99a2dd95SBruce Richardson struct rte_eventdev *eventdev; 50*99a2dd95SBruce Richardson 51*99a2dd95SBruce Richardson /* Allocate device structure */ 52*99a2dd95SBruce Richardson eventdev = rte_event_pmd_allocate(name, socket_id); 53*99a2dd95SBruce Richardson if (eventdev == NULL) 54*99a2dd95SBruce Richardson return NULL; 55*99a2dd95SBruce Richardson 56*99a2dd95SBruce Richardson /* Allocate private device structure */ 57*99a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 58*99a2dd95SBruce Richardson eventdev->data->dev_private = 59*99a2dd95SBruce Richardson rte_zmalloc_socket("eventdev device private", 60*99a2dd95SBruce Richardson dev_private_size, 61*99a2dd95SBruce Richardson RTE_CACHE_LINE_SIZE, 62*99a2dd95SBruce Richardson socket_id); 63*99a2dd95SBruce Richardson 64*99a2dd95SBruce Richardson if (eventdev->data->dev_private == NULL) 65*99a2dd95SBruce Richardson rte_panic("Cannot allocate memzone for private device" 66*99a2dd95SBruce Richardson " data"); 67*99a2dd95SBruce Richardson } 68*99a2dd95SBruce Richardson 69*99a2dd95SBruce Richardson return eventdev; 70*99a2dd95SBruce Richardson } 71*99a2dd95SBruce Richardson 72*99a2dd95SBruce Richardson /** 73*99a2dd95SBruce Richardson * @internal 74*99a2dd95SBruce Richardson * Destroy the given virtual event device 75*99a2dd95SBruce Richardson * 76*99a2dd95SBruce Richardson * @param name 77*99a2dd95SBruce Richardson * PMD type name 78*99a2dd95SBruce Richardson * @return 79*99a2dd95SBruce Richardson * - 0 on success, negative on error 80*99a2dd95SBruce Richardson */ 81*99a2dd95SBruce Richardson static inline int 82*99a2dd95SBruce Richardson rte_event_pmd_vdev_uninit(const char *name) 83*99a2dd95SBruce Richardson { 84*99a2dd95SBruce Richardson int ret; 85*99a2dd95SBruce Richardson struct rte_eventdev *eventdev; 86*99a2dd95SBruce Richardson 87*99a2dd95SBruce Richardson if (name == NULL) 88*99a2dd95SBruce Richardson return -EINVAL; 89*99a2dd95SBruce Richardson 90*99a2dd95SBruce Richardson eventdev = rte_event_pmd_get_named_dev(name); 91*99a2dd95SBruce Richardson if (eventdev == NULL) 92*99a2dd95SBruce Richardson return -ENODEV; 93*99a2dd95SBruce Richardson 94*99a2dd95SBruce Richardson ret = rte_event_dev_close(eventdev->data->dev_id); 95*99a2dd95SBruce Richardson if (ret < 0) 96*99a2dd95SBruce Richardson return ret; 97*99a2dd95SBruce Richardson 98*99a2dd95SBruce Richardson /* Free the event device */ 99*99a2dd95SBruce Richardson rte_event_pmd_release(eventdev); 100*99a2dd95SBruce Richardson 101*99a2dd95SBruce Richardson return 0; 102*99a2dd95SBruce Richardson } 103*99a2dd95SBruce Richardson 104*99a2dd95SBruce Richardson #ifdef __cplusplus 105*99a2dd95SBruce Richardson } 106*99a2dd95SBruce Richardson #endif 107*99a2dd95SBruce Richardson 108*99a2dd95SBruce Richardson #endif /* _RTE_EVENTDEV_PMD_VDEV_H_ */ 109