3 * Copyright(c) 2016 Cavium networks. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
15 * * Neither the name of Cavium networks nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef _RTE_EVENTDEV_PMD_H_
33 #define _RTE_EVENTDEV_PMD_H_
39 * These API are from event PMD only and user applications should not call
51 #include <rte_malloc.h>
53 #include <rte_common.h>
55 #include "rte_eventdev.h"
57 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
58 #define RTE_PMD_DEBUG_TRACE(...) \
59 rte_pmd_debug_trace(__func__, __VA_ARGS__)
61 #define RTE_PMD_DEBUG_TRACE(...)
65 #define RTE_EDEV_LOG_ERR(fmt, args...) \
66 RTE_LOG(ERR, EVENTDEV, "%s() line %u: " fmt "\n", \
67 __func__, __LINE__, ## args)
69 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
70 #define RTE_EDEV_LOG_DEBUG(fmt, args...) \
71 RTE_LOG(DEBUG, EVENTDEV, "%s() line %u: " fmt "\n", \
72 __func__, __LINE__, ## args)
74 #define RTE_EDEV_LOG_DEBUG(fmt, args...) (void)0
77 /* Macros to check for valid device */
78 #define RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, retval) do { \
79 if (!rte_event_pmd_is_valid_dev((dev_id))) { \
80 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
85 #define RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id) do { \
86 if (!rte_event_pmd_is_valid_dev((dev_id))) { \
87 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
92 #define RTE_EVENTDEV_DETACHED (0)
93 #define RTE_EVENTDEV_ATTACHED (1)
96 * Initialisation function of a event driver invoked for each matching
97 * event PCI device detected during the PCI probing phase.
100 * The dev pointer is the address of the *rte_eventdev* structure associated
101 * with the matching device and which has been [automatically] allocated in
102 * the *rte_event_devices* array.
105 * - 0: Success, the device is properly initialised by the driver.
106 * In particular, the driver MUST have set up the *dev_ops* pointer
107 * of the *dev* structure.
108 * - <0: Error code of the device initialisation failure.
110 typedef int (*eventdev_init_t)(struct rte_eventdev *dev);
113 * Finalisation function of a driver invoked for each matching
114 * PCI device detected during the PCI closing phase.
117 * The dev pointer is the address of the *rte_eventdev* structure associated
118 * with the matching device and which has been [automatically] allocated in
119 * the *rte_event_devices* array.
122 * - 0: Success, the device is properly finalised by the driver.
123 * In particular, the driver MUST free the *dev_ops* pointer
124 * of the *dev* structure.
125 * - <0: Error code of the device initialisation failure.
127 typedef int (*eventdev_uninit_t)(struct rte_eventdev *dev);
130 * The structure associated with a PMD driver.
132 * Each driver acts as a PCI driver and is represented by a generic
133 * *event_driver* structure that holds:
135 * - An *rte_pci_driver* structure (which must be the first field).
137 * - The *eventdev_init* function invoked for each matching PCI device.
139 * - The size of the private data to allocate for each matching device.
141 struct rte_eventdev_driver {
142 struct rte_pci_driver pci_drv; /**< The PMD is also a PCI driver. */
143 unsigned int dev_private_size; /**< Size of device private data. */
145 eventdev_init_t eventdev_init; /**< Device init function. */
146 eventdev_uninit_t eventdev_uninit; /**< Device uninit function. */
149 /** Global structure used for maintaining state of allocated event devices */
150 struct rte_eventdev_global {
151 uint8_t nb_devs; /**< Number of devices found */
152 uint8_t max_devs; /**< Max number of devices */
155 extern struct rte_eventdev_global *rte_eventdev_globals;
156 /** Pointer to global event devices data structure. */
157 extern struct rte_eventdev *rte_eventdevs;
158 /** The pool of rte_eventdev structures. */
161 * Get the rte_eventdev structure device pointer for the named device.
164 * device name to select the device structure.
167 * - The rte_eventdev structure pointer for the given device ID.
169 static inline struct rte_eventdev *
170 rte_event_pmd_get_named_dev(const char *name)
172 struct rte_eventdev *dev;
178 for (i = 0, dev = &rte_eventdevs[i];
179 i < rte_eventdev_globals->max_devs; i++) {
180 if ((dev->attached == RTE_EVENTDEV_ATTACHED) &&
181 (strcmp(dev->data->name, name) == 0))
189 * Validate if the event device index is valid attached event device.
192 * Event device index.
195 * - If the device index is valid (1) or not (0).
197 static inline unsigned
198 rte_event_pmd_is_valid_dev(uint8_t dev_id)
200 struct rte_eventdev *dev;
202 if (dev_id >= rte_eventdev_globals->nb_devs)
205 dev = &rte_eventdevs[dev_id];
206 if (dev->attached != RTE_EVENTDEV_ATTACHED)
213 * Definitions of all functions exported by a driver through the
214 * the generic structure of type *event_dev_ops* supplied in the
215 * *rte_eventdev* structure associated with a device.
219 * Get device information of a device.
222 * Event device pointer
224 * Event device information structure
227 * Returns 0 on success
229 typedef void (*eventdev_info_get_t)(struct rte_eventdev *dev,
230 struct rte_event_dev_info *dev_info);
233 * Configure a device.
236 * Event device pointer
239 * Returns 0 on success
241 typedef int (*eventdev_configure_t)(const struct rte_eventdev *dev);
244 * Start a configured device.
247 * Event device pointer
250 * Returns 0 on success
252 typedef int (*eventdev_start_t)(struct rte_eventdev *dev);
255 * Stop a configured device.
258 * Event device pointer
260 typedef void (*eventdev_stop_t)(struct rte_eventdev *dev);
263 * Close a configured device.
266 * Event device pointer
270 * - (-EAGAIN) if can't close as device is busy
272 typedef int (*eventdev_close_t)(struct rte_eventdev *dev);
275 * Retrieve the default event queue configuration.
278 * Event device pointer
281 * @param[out] queue_conf
282 * Event queue configuration structure
285 typedef void (*eventdev_queue_default_conf_get_t)(struct rte_eventdev *dev,
286 uint8_t queue_id, struct rte_event_queue_conf *queue_conf);
289 * Setup an event queue.
292 * Event device pointer
296 * Event queue configuration structure
299 * Returns 0 on success.
301 typedef int (*eventdev_queue_setup_t)(struct rte_eventdev *dev,
303 const struct rte_event_queue_conf *queue_conf);
306 * Release resources allocated by given event queue.
309 * Event device pointer
314 typedef void (*eventdev_queue_release_t)(struct rte_eventdev *dev,
318 * Retrieve the default event port configuration.
321 * Event device pointer
324 * @param[out] port_conf
325 * Event port configuration structure
328 typedef void (*eventdev_port_default_conf_get_t)(struct rte_eventdev *dev,
329 uint8_t port_id, struct rte_event_port_conf *port_conf);
332 * Setup an event port.
335 * Event device pointer
339 * Event port configuration structure
342 * Returns 0 on success.
344 typedef int (*eventdev_port_setup_t)(struct rte_eventdev *dev,
346 const struct rte_event_port_conf *port_conf);
349 * Release memory resources allocated by given event port.
355 typedef void (*eventdev_port_release_t)(void *port);
358 * Link multiple source event queues to destination event port.
361 * Event device pointer
365 * Points to an array of *nb_links* event queues to be linked
368 * Points to an array of *nb_links* service priorities associated with each
369 * event queue link to event port.
371 * The number of links to establish
374 * Returns 0 on success.
377 typedef int (*eventdev_port_link_t)(struct rte_eventdev *dev, void *port,
378 const uint8_t queues[], const uint8_t priorities[],
382 * Unlink multiple source event queues from destination event port.
385 * Event device pointer
389 * An array of *nb_unlinks* event queues to be unlinked from the event port.
391 * The number of unlinks to establish
394 * Returns 0 on success.
397 typedef int (*eventdev_port_unlink_t)(struct rte_eventdev *dev, void *port,
398 uint8_t queues[], uint16_t nb_unlinks);
401 * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue()
404 * Event device pointer
406 * Wait time in nanosecond
407 * @param[out] timeout_ticks
408 * Value for the *timeout_ticks* parameter in rte_event_dequeue() function
411 typedef void (*eventdev_dequeue_timeout_ticks_t)(struct rte_eventdev *dev,
412 uint64_t ns, uint64_t *timeout_ticks);
415 * Dump internal information
418 * Event device pointer
420 * A pointer to a file for output
423 typedef void (*eventdev_dump_t)(struct rte_eventdev *dev, FILE *f);
425 /** Event device operations function pointer table */
426 struct rte_eventdev_ops {
427 eventdev_info_get_t dev_infos_get; /**< Get device info. */
428 eventdev_configure_t dev_configure; /**< Configure device. */
429 eventdev_start_t dev_start; /**< Start device. */
430 eventdev_stop_t dev_stop; /**< Stop device. */
431 eventdev_close_t dev_close; /**< Close device. */
433 eventdev_queue_default_conf_get_t queue_def_conf;
434 /**< Get default queue configuration. */
435 eventdev_queue_setup_t queue_setup;
436 /**< Set up an event queue. */
437 eventdev_queue_release_t queue_release;
438 /**< Release an event queue. */
440 eventdev_port_default_conf_get_t port_def_conf;
441 /**< Get default port configuration. */
442 eventdev_port_setup_t port_setup;
443 /**< Set up an event port. */
444 eventdev_port_release_t port_release;
445 /**< Release an event port. */
447 eventdev_port_link_t port_link;
448 /**< Link event queues to an event port. */
449 eventdev_port_unlink_t port_unlink;
450 /**< Unlink event queues from an event port. */
451 eventdev_dequeue_timeout_ticks_t timeout_ticks;
452 /**< Converts ns to *timeout_ticks* value for rte_event_dequeue() */
453 eventdev_dump_t dump;
454 /* Dump internal information */
458 * Allocates a new eventdev slot for an event device and returns the pointer
459 * to that slot for the driver to use.
462 * Unique identifier name for each device
464 * Socket to allocate resources on.
466 * - Slot in the rte_dev_devices array for a new device;
468 struct rte_eventdev *
469 rte_event_pmd_allocate(const char *name, int socket_id);
472 * Release the specified eventdev device.
475 * The *eventdev* pointer is the address of the *rte_eventdev* structure.
477 * - 0 on success, negative on error
480 rte_event_pmd_release(struct rte_eventdev *eventdev);
483 * Creates a new virtual event device and returns the pointer to that device.
487 * @param dev_private_size
488 * Size of event PMDs private data
490 * Socket to allocate resources on.
493 * - Eventdev pointer if device is successfully created.
494 * - NULL if device cannot be created.
496 struct rte_eventdev *
497 rte_event_pmd_vdev_init(const char *name, size_t dev_private_size,
502 * Wrapper for use by pci drivers as a .probe function to attach to a event
505 int rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv,
506 struct rte_pci_device *pci_dev);
509 * Wrapper for use by pci drivers as a .remove function to detach a event
512 int rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev);
518 #endif /* _RTE_EVENTDEV_PMD_H_ */