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"
58 #define RTE_EDEV_LOG_ERR(...) \
59 RTE_LOG(ERR, EVENTDEV, \
60 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
61 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
63 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
64 #define RTE_EDEV_LOG_DEBUG(...) \
65 RTE_LOG(DEBUG, EVENTDEV, \
66 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
67 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
69 #define RTE_EDEV_LOG_DEBUG(...) (void)0
72 /* Macros to check for valid device */
73 #define RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, retval) do { \
74 if (!rte_event_pmd_is_valid_dev((dev_id))) { \
75 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
80 #define RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id) do { \
81 if (!rte_event_pmd_is_valid_dev((dev_id))) { \
82 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
87 #define RTE_EVENTDEV_DETACHED (0)
88 #define RTE_EVENTDEV_ATTACHED (1)
91 * Initialisation function of a event driver invoked for each matching
92 * event PCI device detected during the PCI probing phase.
95 * The dev pointer is the address of the *rte_eventdev* structure associated
96 * with the matching device and which has been [automatically] allocated in
97 * the *rte_event_devices* array.
100 * - 0: Success, the device is properly initialised by the driver.
101 * In particular, the driver MUST have set up the *dev_ops* pointer
102 * of the *dev* structure.
103 * - <0: Error code of the device initialisation failure.
105 typedef int (*eventdev_init_t)(struct rte_eventdev *dev);
108 * Finalisation function of a driver invoked for each matching
109 * PCI device detected during the PCI closing phase.
112 * The dev pointer is the address of the *rte_eventdev* structure associated
113 * with the matching device and which has been [automatically] allocated in
114 * the *rte_event_devices* array.
117 * - 0: Success, the device is properly finalised by the driver.
118 * In particular, the driver MUST free the *dev_ops* pointer
119 * of the *dev* structure.
120 * - <0: Error code of the device initialisation failure.
122 typedef int (*eventdev_uninit_t)(struct rte_eventdev *dev);
125 * The structure associated with a PMD driver.
127 * Each driver acts as a PCI driver and is represented by a generic
128 * *event_driver* structure that holds:
130 * - An *rte_pci_driver* structure (which must be the first field).
132 * - The *eventdev_init* function invoked for each matching PCI device.
134 * - The size of the private data to allocate for each matching device.
136 struct rte_eventdev_driver {
137 struct rte_pci_driver pci_drv; /**< The PMD is also a PCI driver. */
138 unsigned int dev_private_size; /**< Size of device private data. */
140 eventdev_init_t eventdev_init; /**< Device init function. */
141 eventdev_uninit_t eventdev_uninit; /**< Device uninit function. */
144 /** Global structure used for maintaining state of allocated event devices */
145 struct rte_eventdev_global {
146 uint8_t nb_devs; /**< Number of devices found */
149 extern struct rte_eventdev_global *rte_eventdev_globals;
150 /** Pointer to global event devices data structure. */
151 extern struct rte_eventdev *rte_eventdevs;
152 /** The pool of rte_eventdev structures. */
155 * Get the rte_eventdev structure device pointer for the named device.
158 * device name to select the device structure.
161 * - The rte_eventdev structure pointer for the given device ID.
163 static inline struct rte_eventdev *
164 rte_event_pmd_get_named_dev(const char *name)
166 struct rte_eventdev *dev;
172 for (i = 0; i < RTE_EVENT_MAX_DEVS; i++) {
173 dev = &rte_eventdevs[i];
174 if ((dev->attached == RTE_EVENTDEV_ATTACHED) &&
175 (strcmp(dev->data->name, name) == 0))
183 * Validate if the event device index is valid attached event device.
186 * Event device index.
189 * - If the device index is valid (1) or not (0).
191 static inline unsigned
192 rte_event_pmd_is_valid_dev(uint8_t dev_id)
194 struct rte_eventdev *dev;
196 if (dev_id >= RTE_EVENT_MAX_DEVS)
199 dev = &rte_eventdevs[dev_id];
200 if (dev->attached != RTE_EVENTDEV_ATTACHED)
207 * Definitions of all functions exported by a driver through the
208 * the generic structure of type *event_dev_ops* supplied in the
209 * *rte_eventdev* structure associated with a device.
213 * Get device information of a device.
216 * Event device pointer
218 * Event device information structure
221 * Returns 0 on success
223 typedef void (*eventdev_info_get_t)(struct rte_eventdev *dev,
224 struct rte_event_dev_info *dev_info);
227 * Configure a device.
230 * Event device pointer
233 * Returns 0 on success
235 typedef int (*eventdev_configure_t)(const struct rte_eventdev *dev);
238 * Start a configured device.
241 * Event device pointer
244 * Returns 0 on success
246 typedef int (*eventdev_start_t)(struct rte_eventdev *dev);
249 * Stop a configured device.
252 * Event device pointer
254 typedef void (*eventdev_stop_t)(struct rte_eventdev *dev);
257 * Close a configured device.
260 * Event device pointer
264 * - (-EAGAIN) if can't close as device is busy
266 typedef int (*eventdev_close_t)(struct rte_eventdev *dev);
269 * Retrieve the default event queue configuration.
272 * Event device pointer
275 * @param[out] queue_conf
276 * Event queue configuration structure
279 typedef void (*eventdev_queue_default_conf_get_t)(struct rte_eventdev *dev,
280 uint8_t queue_id, struct rte_event_queue_conf *queue_conf);
283 * Setup an event queue.
286 * Event device pointer
290 * Event queue configuration structure
293 * Returns 0 on success.
295 typedef int (*eventdev_queue_setup_t)(struct rte_eventdev *dev,
297 const struct rte_event_queue_conf *queue_conf);
300 * Release resources allocated by given event queue.
303 * Event device pointer
308 typedef void (*eventdev_queue_release_t)(struct rte_eventdev *dev,
312 * Retrieve the default event port configuration.
315 * Event device pointer
318 * @param[out] port_conf
319 * Event port configuration structure
322 typedef void (*eventdev_port_default_conf_get_t)(struct rte_eventdev *dev,
323 uint8_t port_id, struct rte_event_port_conf *port_conf);
326 * Setup an event port.
329 * Event device pointer
333 * Event port configuration structure
336 * Returns 0 on success.
338 typedef int (*eventdev_port_setup_t)(struct rte_eventdev *dev,
340 const struct rte_event_port_conf *port_conf);
343 * Release memory resources allocated by given event port.
349 typedef void (*eventdev_port_release_t)(void *port);
352 * Link multiple source event queues to destination event port.
355 * Event device pointer
359 * Points to an array of *nb_links* event queues to be linked
362 * Points to an array of *nb_links* service priorities associated with each
363 * event queue link to event port.
365 * The number of links to establish
368 * Returns 0 on success.
371 typedef int (*eventdev_port_link_t)(struct rte_eventdev *dev, void *port,
372 const uint8_t queues[], const uint8_t priorities[],
376 * Unlink multiple source event queues from destination event port.
379 * Event device pointer
383 * An array of *nb_unlinks* event queues to be unlinked from the event port.
385 * The number of unlinks to establish
388 * Returns 0 on success.
391 typedef int (*eventdev_port_unlink_t)(struct rte_eventdev *dev, void *port,
392 uint8_t queues[], uint16_t nb_unlinks);
395 * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue()
398 * Event device pointer
400 * Wait time in nanosecond
401 * @param[out] timeout_ticks
402 * Value for the *timeout_ticks* parameter in rte_event_dequeue() function
405 * Returns 0 on success.
408 typedef int (*eventdev_dequeue_timeout_ticks_t)(struct rte_eventdev *dev,
409 uint64_t ns, uint64_t *timeout_ticks);
412 * Dump internal information
415 * Event device pointer
417 * A pointer to a file for output
420 typedef void (*eventdev_dump_t)(struct rte_eventdev *dev, FILE *f);
423 * Retrieve a set of statistics from device
426 * Event device pointer
428 * The stat ids to retrieve
430 * The returned stat values
432 * The number of id values and entries in the values array
434 * The number of stat values successfully filled into the values array
436 typedef int (*eventdev_xstats_get_t)(const struct rte_eventdev *dev,
437 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
438 const unsigned int ids[], uint64_t values[], unsigned int n);
441 * Resets the statistic values in xstats for the device, based on mode.
443 typedef int (*eventdev_xstats_reset_t)(struct rte_eventdev *dev,
444 enum rte_event_dev_xstats_mode mode,
445 int16_t queue_port_id,
446 const uint32_t ids[],
450 * Get names of extended stats of an event device
453 * Event device pointer
454 * @param xstats_names
455 * Array of name values to be filled in
457 * Number of values in the xstats_names array
459 * When size >= the number of stats, return the number of stat values filled
461 * When size < the number of available stats, return the number of stats
462 * values, and do not fill in any data into xstats_names.
464 typedef int (*eventdev_xstats_get_names_t)(const struct rte_eventdev *dev,
465 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
466 struct rte_event_dev_xstats_name *xstats_names,
467 unsigned int *ids, unsigned int size);
470 * Get value of one stats and optionally return its id
473 * Event device pointer
475 * The name of the stat to retrieve
477 * Pointer to an unsigned int where we store the stat-id for future reference.
478 * This pointer may be null if the id is not required.
480 * The value of the stat, or (uint64_t)-1 if the stat is not found.
481 * If the stat is not found, the id value will be returned as (unsigned)-1,
482 * if id pointer is non-NULL
484 typedef uint64_t (*eventdev_xstats_get_by_name)(const struct rte_eventdev *dev,
485 const char *name, unsigned int *id);
487 /** Event device operations function pointer table */
488 struct rte_eventdev_ops {
489 eventdev_info_get_t dev_infos_get; /**< Get device info. */
490 eventdev_configure_t dev_configure; /**< Configure device. */
491 eventdev_start_t dev_start; /**< Start device. */
492 eventdev_stop_t dev_stop; /**< Stop device. */
493 eventdev_close_t dev_close; /**< Close device. */
495 eventdev_queue_default_conf_get_t queue_def_conf;
496 /**< Get default queue configuration. */
497 eventdev_queue_setup_t queue_setup;
498 /**< Set up an event queue. */
499 eventdev_queue_release_t queue_release;
500 /**< Release an event queue. */
502 eventdev_port_default_conf_get_t port_def_conf;
503 /**< Get default port configuration. */
504 eventdev_port_setup_t port_setup;
505 /**< Set up an event port. */
506 eventdev_port_release_t port_release;
507 /**< Release an event port. */
509 eventdev_port_link_t port_link;
510 /**< Link event queues to an event port. */
511 eventdev_port_unlink_t port_unlink;
512 /**< Unlink event queues from an event port. */
513 eventdev_dequeue_timeout_ticks_t timeout_ticks;
514 /**< Converts ns to *timeout_ticks* value for rte_event_dequeue() */
515 eventdev_dump_t dump;
516 /* Dump internal information */
518 eventdev_xstats_get_t xstats_get;
519 /**< Get extended device statistics. */
520 eventdev_xstats_get_names_t xstats_get_names;
521 /**< Get names of extended stats. */
522 eventdev_xstats_get_by_name xstats_get_by_name;
523 /**< Get one value by name. */
524 eventdev_xstats_reset_t xstats_reset;
525 /**< Reset the statistics values in xstats. */
529 * Allocates a new eventdev slot for an event device and returns the pointer
530 * to that slot for the driver to use.
533 * Unique identifier name for each device
535 * Socket to allocate resources on.
537 * - Slot in the rte_dev_devices array for a new device;
539 struct rte_eventdev *
540 rte_event_pmd_allocate(const char *name, int socket_id);
543 * Release the specified eventdev device.
546 * The *eventdev* pointer is the address of the *rte_eventdev* structure.
548 * - 0 on success, negative on error
551 rte_event_pmd_release(struct rte_eventdev *eventdev);
554 * Creates a new virtual event device and returns the pointer to that device.
558 * @param dev_private_size
559 * Size of event PMDs private data
561 * Socket to allocate resources on.
564 * - Eventdev pointer if device is successfully created.
565 * - NULL if device cannot be created.
567 struct rte_eventdev *
568 rte_event_pmd_vdev_init(const char *name, size_t dev_private_size,
572 * Destroy the given virtual event device
577 * - 0 on success, negative on error
580 rte_event_pmd_vdev_uninit(const char *name);
583 * Wrapper for use by pci drivers as a .probe function to attach to a event
586 int rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv,
587 struct rte_pci_device *pci_dev);
590 * Wrapper for use by pci drivers as a .remove function to detach a event
593 int rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev);
599 #endif /* _RTE_EVENTDEV_PMD_H_ */