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_VDEV_H_ 699a2dd95SBruce Richardson #define _RTE_EVENTDEV_PMD_VDEV_H_ 799a2dd95SBruce Richardson 82c552933SBrian Dooley #ifdef __cplusplus 92c552933SBrian Dooley extern "C" { 102c552933SBrian Dooley #endif 112c552933SBrian Dooley 1299a2dd95SBruce Richardson /** @file 1399a2dd95SBruce Richardson * RTE Eventdev VDEV PMD APIs 1499a2dd95SBruce Richardson * 1599a2dd95SBruce Richardson * @note 1699a2dd95SBruce Richardson * These API are from event VDEV 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_debug.h> 2499a2dd95SBruce Richardson #include <rte_eal.h> 25*4851ef2bSDavid Marchand #include <bus_vdev_driver.h> 2699a2dd95SBruce Richardson 2799a2dd95SBruce Richardson #include "eventdev_pmd.h" 2899a2dd95SBruce Richardson 2999a2dd95SBruce Richardson /** 3099a2dd95SBruce Richardson * @internal 3199a2dd95SBruce Richardson * Creates a new virtual event device and returns the pointer to that device. 3299a2dd95SBruce Richardson * 3399a2dd95SBruce Richardson * @param name 3499a2dd95SBruce Richardson * PMD type name 3599a2dd95SBruce Richardson * @param dev_private_size 3699a2dd95SBruce Richardson * Size of event PMDs private data 3799a2dd95SBruce Richardson * @param socket_id 3899a2dd95SBruce Richardson * Socket to allocate resources on. 3999a2dd95SBruce Richardson * 4099a2dd95SBruce Richardson * @return 4199a2dd95SBruce Richardson * - Eventdev pointer if device is successfully created. 4299a2dd95SBruce Richardson * - NULL if device cannot be created. 4399a2dd95SBruce Richardson */ 4423d06e37SPavan Nikhilesh __rte_internal 4599a2dd95SBruce Richardson static inline struct rte_eventdev * 4699a2dd95SBruce Richardson rte_event_pmd_vdev_init(const char *name, size_t dev_private_size, 4799a2dd95SBruce Richardson int socket_id) 4899a2dd95SBruce Richardson { 4999a2dd95SBruce Richardson 5099a2dd95SBruce Richardson struct rte_eventdev *eventdev; 5199a2dd95SBruce Richardson 5299a2dd95SBruce Richardson /* Allocate device structure */ 5399a2dd95SBruce Richardson eventdev = rte_event_pmd_allocate(name, socket_id); 5499a2dd95SBruce Richardson if (eventdev == NULL) 5599a2dd95SBruce Richardson return NULL; 5699a2dd95SBruce Richardson 5799a2dd95SBruce Richardson /* Allocate private device structure */ 5899a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 5999a2dd95SBruce Richardson eventdev->data->dev_private = 6099a2dd95SBruce Richardson rte_zmalloc_socket("eventdev device private", 6199a2dd95SBruce Richardson dev_private_size, 6299a2dd95SBruce Richardson RTE_CACHE_LINE_SIZE, 6399a2dd95SBruce Richardson socket_id); 6499a2dd95SBruce Richardson 6599a2dd95SBruce Richardson if (eventdev->data->dev_private == NULL) 6699a2dd95SBruce Richardson rte_panic("Cannot allocate memzone for private device" 6799a2dd95SBruce Richardson " data"); 6899a2dd95SBruce Richardson } 6999a2dd95SBruce Richardson 7099a2dd95SBruce Richardson return eventdev; 7199a2dd95SBruce Richardson } 7299a2dd95SBruce Richardson 7399a2dd95SBruce Richardson /** 7499a2dd95SBruce Richardson * @internal 7599a2dd95SBruce Richardson * Destroy the given virtual event device 7699a2dd95SBruce Richardson * 7799a2dd95SBruce Richardson * @param name 7899a2dd95SBruce Richardson * PMD type name 7999a2dd95SBruce Richardson * @return 8099a2dd95SBruce Richardson * - 0 on success, negative on error 8199a2dd95SBruce Richardson */ 8223d06e37SPavan Nikhilesh __rte_internal 8399a2dd95SBruce Richardson static inline int 8499a2dd95SBruce Richardson rte_event_pmd_vdev_uninit(const char *name) 8599a2dd95SBruce Richardson { 8699a2dd95SBruce Richardson int ret; 8799a2dd95SBruce Richardson struct rte_eventdev *eventdev; 8899a2dd95SBruce Richardson 8999a2dd95SBruce Richardson if (name == NULL) 9099a2dd95SBruce Richardson return -EINVAL; 9199a2dd95SBruce Richardson 9299a2dd95SBruce Richardson eventdev = rte_event_pmd_get_named_dev(name); 9399a2dd95SBruce Richardson if (eventdev == NULL) 9499a2dd95SBruce Richardson return -ENODEV; 9599a2dd95SBruce Richardson 9699a2dd95SBruce Richardson ret = rte_event_dev_close(eventdev->data->dev_id); 9799a2dd95SBruce Richardson if (ret < 0) 9899a2dd95SBruce Richardson return ret; 9999a2dd95SBruce Richardson 10099a2dd95SBruce Richardson /* Free the event device */ 10199a2dd95SBruce Richardson rte_event_pmd_release(eventdev); 10299a2dd95SBruce Richardson 10399a2dd95SBruce Richardson return 0; 10499a2dd95SBruce Richardson } 10599a2dd95SBruce Richardson 1062c552933SBrian Dooley #ifdef __cplusplus 1072c552933SBrian Dooley } 1082c552933SBrian Dooley #endif 1092c552933SBrian Dooley 11099a2dd95SBruce Richardson #endif /* _RTE_EVENTDEV_PMD_VDEV_H_ */ 111