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(fmt, args...) \
59 RTE_LOG(ERR, EVENTDEV, "%s() line %u: " fmt "\n", \
60 __func__, __LINE__, ## args)
62 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
63 #define RTE_EDEV_LOG_DEBUG(fmt, args...) \
64 RTE_LOG(DEBUG, EVENTDEV, "%s() line %u: " fmt "\n", \
65 __func__, __LINE__, ## args)
67 #define RTE_EDEV_LOG_DEBUG(fmt, args...) (void)0
70 /* Macros to check for valid device */
71 #define RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, retval) do { \
72 if (!rte_event_pmd_is_valid_dev((dev_id))) { \
73 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
78 #define RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id) 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_DETACHED (0)
86 #define RTE_EVENTDEV_ATTACHED (1)
89 * Initialisation function of a event driver invoked for each matching
90 * event PCI device detected during the PCI probing phase.
93 * The dev pointer is the address of the *rte_eventdev* structure associated
94 * with the matching device and which has been [automatically] allocated in
95 * the *rte_event_devices* array.
98 * - 0: Success, the device is properly initialised by the driver.
99 * In particular, the driver MUST have set up the *dev_ops* pointer
100 * of the *dev* structure.
101 * - <0: Error code of the device initialisation failure.
103 typedef int (*eventdev_init_t)(struct rte_eventdev *dev);
106 * Finalisation function of a driver invoked for each matching
107 * PCI device detected during the PCI closing phase.
110 * The dev pointer is the address of the *rte_eventdev* structure associated
111 * with the matching device and which has been [automatically] allocated in
112 * the *rte_event_devices* array.
115 * - 0: Success, the device is properly finalised by the driver.
116 * In particular, the driver MUST free the *dev_ops* pointer
117 * of the *dev* structure.
118 * - <0: Error code of the device initialisation failure.
120 typedef int (*eventdev_uninit_t)(struct rte_eventdev *dev);
123 * The structure associated with a PMD driver.
125 * Each driver acts as a PCI driver and is represented by a generic
126 * *event_driver* structure that holds:
128 * - An *rte_pci_driver* structure (which must be the first field).
130 * - The *eventdev_init* function invoked for each matching PCI device.
132 * - The size of the private data to allocate for each matching device.
134 struct rte_eventdev_driver {
135 struct rte_pci_driver pci_drv; /**< The PMD is also a PCI driver. */
136 unsigned int dev_private_size; /**< Size of device private data. */
138 eventdev_init_t eventdev_init; /**< Device init function. */
139 eventdev_uninit_t eventdev_uninit; /**< Device uninit function. */
142 /** Global structure used for maintaining state of allocated event devices */
143 struct rte_eventdev_global {
144 uint8_t nb_devs; /**< Number of devices found */
147 extern struct rte_eventdev_global *rte_eventdev_globals;
148 /** Pointer to global event devices data structure. */
149 extern struct rte_eventdev *rte_eventdevs;
150 /** The pool of rte_eventdev structures. */
153 * Get the rte_eventdev structure device pointer for the named device.
156 * device name to select the device structure.
159 * - The rte_eventdev structure pointer for the given device ID.
161 static inline struct rte_eventdev *
162 rte_event_pmd_get_named_dev(const char *name)
164 struct rte_eventdev *dev;
170 for (i = 0; i < RTE_EVENT_MAX_DEVS; i++) {
171 dev = &rte_eventdevs[i];
172 if ((dev->attached == RTE_EVENTDEV_ATTACHED) &&
173 (strcmp(dev->data->name, name) == 0))
181 * Validate if the event device index is valid attached event device.
184 * Event device index.
187 * - If the device index is valid (1) or not (0).
189 static inline unsigned
190 rte_event_pmd_is_valid_dev(uint8_t dev_id)
192 struct rte_eventdev *dev;
194 if (dev_id >= RTE_EVENT_MAX_DEVS)
197 dev = &rte_eventdevs[dev_id];
198 if (dev->attached != RTE_EVENTDEV_ATTACHED)
205 * Definitions of all functions exported by a driver through the
206 * the generic structure of type *event_dev_ops* supplied in the
207 * *rte_eventdev* structure associated with a device.
211 * Get device information of a device.
214 * Event device pointer
216 * Event device information structure
219 * Returns 0 on success
221 typedef void (*eventdev_info_get_t)(struct rte_eventdev *dev,
222 struct rte_event_dev_info *dev_info);
225 * Configure a device.
228 * Event device pointer
231 * Returns 0 on success
233 typedef int (*eventdev_configure_t)(const struct rte_eventdev *dev);
236 * Start a configured device.
239 * Event device pointer
242 * Returns 0 on success
244 typedef int (*eventdev_start_t)(struct rte_eventdev *dev);
247 * Stop a configured device.
250 * Event device pointer
252 typedef void (*eventdev_stop_t)(struct rte_eventdev *dev);
255 * Close a configured device.
258 * Event device pointer
262 * - (-EAGAIN) if can't close as device is busy
264 typedef int (*eventdev_close_t)(struct rte_eventdev *dev);
267 * Retrieve the default event queue configuration.
270 * Event device pointer
273 * @param[out] queue_conf
274 * Event queue configuration structure
277 typedef void (*eventdev_queue_default_conf_get_t)(struct rte_eventdev *dev,
278 uint8_t queue_id, struct rte_event_queue_conf *queue_conf);
281 * Setup an event queue.
284 * Event device pointer
288 * Event queue configuration structure
291 * Returns 0 on success.
293 typedef int (*eventdev_queue_setup_t)(struct rte_eventdev *dev,
295 const struct rte_event_queue_conf *queue_conf);
298 * Release resources allocated by given event queue.
301 * Event device pointer
306 typedef void (*eventdev_queue_release_t)(struct rte_eventdev *dev,
310 * Retrieve the default event port configuration.
313 * Event device pointer
316 * @param[out] port_conf
317 * Event port configuration structure
320 typedef void (*eventdev_port_default_conf_get_t)(struct rte_eventdev *dev,
321 uint8_t port_id, struct rte_event_port_conf *port_conf);
324 * Setup an event port.
327 * Event device pointer
331 * Event port configuration structure
334 * Returns 0 on success.
336 typedef int (*eventdev_port_setup_t)(struct rte_eventdev *dev,
338 const struct rte_event_port_conf *port_conf);
341 * Release memory resources allocated by given event port.
347 typedef void (*eventdev_port_release_t)(void *port);
350 * Link multiple source event queues to destination event port.
353 * Event device pointer
357 * Points to an array of *nb_links* event queues to be linked
360 * Points to an array of *nb_links* service priorities associated with each
361 * event queue link to event port.
363 * The number of links to establish
366 * Returns 0 on success.
369 typedef int (*eventdev_port_link_t)(struct rte_eventdev *dev, void *port,
370 const uint8_t queues[], const uint8_t priorities[],
374 * Unlink multiple source event queues from destination event port.
377 * Event device pointer
381 * An array of *nb_unlinks* event queues to be unlinked from the event port.
383 * The number of unlinks to establish
386 * Returns 0 on success.
389 typedef int (*eventdev_port_unlink_t)(struct rte_eventdev *dev, void *port,
390 uint8_t queues[], uint16_t nb_unlinks);
393 * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue()
396 * Event device pointer
398 * Wait time in nanosecond
399 * @param[out] timeout_ticks
400 * Value for the *timeout_ticks* parameter in rte_event_dequeue() function
403 * Returns 0 on success.
406 typedef int (*eventdev_dequeue_timeout_ticks_t)(struct rte_eventdev *dev,
407 uint64_t ns, uint64_t *timeout_ticks);
410 * Dump internal information
413 * Event device pointer
415 * A pointer to a file for output
418 typedef void (*eventdev_dump_t)(struct rte_eventdev *dev, FILE *f);
421 * Retrieve a set of statistics from device
424 * Event device pointer
426 * The stat ids to retrieve
428 * The returned stat values
430 * The number of id values and entries in the values array
432 * The number of stat values successfully filled into the values array
434 typedef int (*eventdev_xstats_get_t)(const struct rte_eventdev *dev,
435 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
436 const unsigned int ids[], uint64_t values[], unsigned int n);
439 * Resets the statistic values in xstats for the device, based on mode.
441 typedef int (*eventdev_xstats_reset_t)(struct rte_eventdev *dev,
442 enum rte_event_dev_xstats_mode mode,
443 int16_t queue_port_id,
444 const uint32_t ids[],
448 * Get names of extended stats of an event device
451 * Event device pointer
452 * @param xstats_names
453 * Array of name values to be filled in
455 * Number of values in the xstats_names array
457 * When size >= the number of stats, return the number of stat values filled
459 * When size < the number of available stats, return the number of stats
460 * values, and do not fill in any data into xstats_names.
462 typedef int (*eventdev_xstats_get_names_t)(const struct rte_eventdev *dev,
463 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
464 struct rte_event_dev_xstats_name *xstats_names,
465 unsigned int *ids, unsigned int size);
468 * Get value of one stats and optionally return its id
471 * Event device pointer
473 * The name of the stat to retrieve
475 * Pointer to an unsigned int where we store the stat-id for future reference.
476 * This pointer may be null if the id is not required.
478 * The value of the stat, or (uint64_t)-1 if the stat is not found.
479 * If the stat is not found, the id value will be returned as (unsigned)-1,
480 * if id pointer is non-NULL
482 typedef uint64_t (*eventdev_xstats_get_by_name)(const struct rte_eventdev *dev,
483 const char *name, unsigned int *id);
485 /** Event device operations function pointer table */
486 struct rte_eventdev_ops {
487 eventdev_info_get_t dev_infos_get; /**< Get device info. */
488 eventdev_configure_t dev_configure; /**< Configure device. */
489 eventdev_start_t dev_start; /**< Start device. */
490 eventdev_stop_t dev_stop; /**< Stop device. */
491 eventdev_close_t dev_close; /**< Close device. */
493 eventdev_queue_default_conf_get_t queue_def_conf;
494 /**< Get default queue configuration. */
495 eventdev_queue_setup_t queue_setup;
496 /**< Set up an event queue. */
497 eventdev_queue_release_t queue_release;
498 /**< Release an event queue. */
500 eventdev_port_default_conf_get_t port_def_conf;
501 /**< Get default port configuration. */
502 eventdev_port_setup_t port_setup;
503 /**< Set up an event port. */
504 eventdev_port_release_t port_release;
505 /**< Release an event port. */
507 eventdev_port_link_t port_link;
508 /**< Link event queues to an event port. */
509 eventdev_port_unlink_t port_unlink;
510 /**< Unlink event queues from an event port. */
511 eventdev_dequeue_timeout_ticks_t timeout_ticks;
512 /**< Converts ns to *timeout_ticks* value for rte_event_dequeue() */
513 eventdev_dump_t dump;
514 /* Dump internal information */
516 eventdev_xstats_get_t xstats_get;
517 /**< Get extended device statistics. */
518 eventdev_xstats_get_names_t xstats_get_names;
519 /**< Get names of extended stats. */
520 eventdev_xstats_get_by_name xstats_get_by_name;
521 /**< Get one value by name. */
522 eventdev_xstats_reset_t xstats_reset;
523 /**< Reset the statistics values in xstats. */
527 * Allocates a new eventdev slot for an event device and returns the pointer
528 * to that slot for the driver to use.
531 * Unique identifier name for each device
533 * Socket to allocate resources on.
535 * - Slot in the rte_dev_devices array for a new device;
537 struct rte_eventdev *
538 rte_event_pmd_allocate(const char *name, int socket_id);
541 * Release the specified eventdev device.
544 * The *eventdev* pointer is the address of the *rte_eventdev* structure.
546 * - 0 on success, negative on error
549 rte_event_pmd_release(struct rte_eventdev *eventdev);
552 * Creates a new virtual event device and returns the pointer to that device.
556 * @param dev_private_size
557 * Size of event PMDs private data
559 * Socket to allocate resources on.
562 * - Eventdev pointer if device is successfully created.
563 * - NULL if device cannot be created.
565 struct rte_eventdev *
566 rte_event_pmd_vdev_init(const char *name, size_t dev_private_size,
570 * Destroy the given virtual event device
575 * - 0 on success, negative on error
578 rte_event_pmd_vdev_uninit(const char *name);
581 * Wrapper for use by pci drivers as a .probe function to attach to a event
584 int rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv,
585 struct rte_pci_device *pci_dev);
588 * Wrapper for use by pci drivers as a .remove function to detach a event
591 int rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev);
597 #endif /* _RTE_EVENTDEV_PMD_H_ */