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)
90 /** Global structure used for maintaining state of allocated event devices */
91 struct rte_eventdev_global {
92 uint8_t nb_devs; /**< Number of devices found */
95 extern struct rte_eventdev_global *rte_eventdev_globals;
96 /** Pointer to global event devices data structure. */
97 extern struct rte_eventdev *rte_eventdevs;
98 /** The pool of rte_eventdev structures. */
101 * Get the rte_eventdev structure device pointer for the named device.
104 * device name to select the device structure.
107 * - The rte_eventdev structure pointer for the given device ID.
109 static inline struct rte_eventdev *
110 rte_event_pmd_get_named_dev(const char *name)
112 struct rte_eventdev *dev;
118 for (i = 0; i < RTE_EVENT_MAX_DEVS; i++) {
119 dev = &rte_eventdevs[i];
120 if ((dev->attached == RTE_EVENTDEV_ATTACHED) &&
121 (strcmp(dev->data->name, name) == 0))
129 * Validate if the event device index is valid attached event device.
132 * Event device index.
135 * - If the device index is valid (1) or not (0).
137 static inline unsigned
138 rte_event_pmd_is_valid_dev(uint8_t dev_id)
140 struct rte_eventdev *dev;
142 if (dev_id >= RTE_EVENT_MAX_DEVS)
145 dev = &rte_eventdevs[dev_id];
146 if (dev->attached != RTE_EVENTDEV_ATTACHED)
153 * Definitions of all functions exported by a driver through the
154 * the generic structure of type *event_dev_ops* supplied in the
155 * *rte_eventdev* structure associated with a device.
159 * Get device information of a device.
162 * Event device pointer
164 * Event device information structure
167 * Returns 0 on success
169 typedef void (*eventdev_info_get_t)(struct rte_eventdev *dev,
170 struct rte_event_dev_info *dev_info);
173 * Configure a device.
176 * Event device pointer
179 * Returns 0 on success
181 typedef int (*eventdev_configure_t)(const struct rte_eventdev *dev);
184 * Start a configured device.
187 * Event device pointer
190 * Returns 0 on success
192 typedef int (*eventdev_start_t)(struct rte_eventdev *dev);
195 * Stop a configured device.
198 * Event device pointer
200 typedef void (*eventdev_stop_t)(struct rte_eventdev *dev);
203 * Close a configured device.
206 * Event device pointer
210 * - (-EAGAIN) if can't close as device is busy
212 typedef int (*eventdev_close_t)(struct rte_eventdev *dev);
215 * Retrieve the default event queue configuration.
218 * Event device pointer
221 * @param[out] queue_conf
222 * Event queue configuration structure
225 typedef void (*eventdev_queue_default_conf_get_t)(struct rte_eventdev *dev,
226 uint8_t queue_id, struct rte_event_queue_conf *queue_conf);
229 * Setup an event queue.
232 * Event device pointer
236 * Event queue configuration structure
239 * Returns 0 on success.
241 typedef int (*eventdev_queue_setup_t)(struct rte_eventdev *dev,
243 const struct rte_event_queue_conf *queue_conf);
246 * Release resources allocated by given event queue.
249 * Event device pointer
254 typedef void (*eventdev_queue_release_t)(struct rte_eventdev *dev,
258 * Retrieve the default event port configuration.
261 * Event device pointer
264 * @param[out] port_conf
265 * Event port configuration structure
268 typedef void (*eventdev_port_default_conf_get_t)(struct rte_eventdev *dev,
269 uint8_t port_id, struct rte_event_port_conf *port_conf);
272 * Setup an event port.
275 * Event device pointer
279 * Event port configuration structure
282 * Returns 0 on success.
284 typedef int (*eventdev_port_setup_t)(struct rte_eventdev *dev,
286 const struct rte_event_port_conf *port_conf);
289 * Release memory resources allocated by given event port.
295 typedef void (*eventdev_port_release_t)(void *port);
298 * Link multiple source event queues to destination event port.
301 * Event device pointer
305 * Points to an array of *nb_links* event queues to be linked
308 * Points to an array of *nb_links* service priorities associated with each
309 * event queue link to event port.
311 * The number of links to establish
314 * Returns 0 on success.
317 typedef int (*eventdev_port_link_t)(struct rte_eventdev *dev, void *port,
318 const uint8_t queues[], const uint8_t priorities[],
322 * Unlink multiple source event queues from destination event port.
325 * Event device pointer
329 * An array of *nb_unlinks* event queues to be unlinked from the event port.
331 * The number of unlinks to establish
334 * Returns 0 on success.
337 typedef int (*eventdev_port_unlink_t)(struct rte_eventdev *dev, void *port,
338 uint8_t queues[], uint16_t nb_unlinks);
341 * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue()
344 * Event device pointer
346 * Wait time in nanosecond
347 * @param[out] timeout_ticks
348 * Value for the *timeout_ticks* parameter in rte_event_dequeue() function
351 * Returns 0 on success.
354 typedef int (*eventdev_dequeue_timeout_ticks_t)(struct rte_eventdev *dev,
355 uint64_t ns, uint64_t *timeout_ticks);
358 * Dump internal information
361 * Event device pointer
363 * A pointer to a file for output
366 typedef void (*eventdev_dump_t)(struct rte_eventdev *dev, FILE *f);
369 * Retrieve a set of statistics from device
372 * Event device pointer
374 * The stat ids to retrieve
376 * The returned stat values
378 * The number of id values and entries in the values array
380 * The number of stat values successfully filled into the values array
382 typedef int (*eventdev_xstats_get_t)(const struct rte_eventdev *dev,
383 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
384 const unsigned int ids[], uint64_t values[], unsigned int n);
387 * Resets the statistic values in xstats for the device, based on mode.
389 typedef int (*eventdev_xstats_reset_t)(struct rte_eventdev *dev,
390 enum rte_event_dev_xstats_mode mode,
391 int16_t queue_port_id,
392 const uint32_t ids[],
396 * Get names of extended stats of an event device
399 * Event device pointer
400 * @param xstats_names
401 * Array of name values to be filled in
403 * Number of values in the xstats_names array
405 * When size >= the number of stats, return the number of stat values filled
407 * When size < the number of available stats, return the number of stats
408 * values, and do not fill in any data into xstats_names.
410 typedef int (*eventdev_xstats_get_names_t)(const struct rte_eventdev *dev,
411 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
412 struct rte_event_dev_xstats_name *xstats_names,
413 unsigned int *ids, unsigned int size);
416 * Get value of one stats and optionally return its id
419 * Event device pointer
421 * The name of the stat to retrieve
423 * Pointer to an unsigned int where we store the stat-id for future reference.
424 * This pointer may be null if the id is not required.
426 * The value of the stat, or (uint64_t)-1 if the stat is not found.
427 * If the stat is not found, the id value will be returned as (unsigned)-1,
428 * if id pointer is non-NULL
430 typedef uint64_t (*eventdev_xstats_get_by_name)(const struct rte_eventdev *dev,
431 const char *name, unsigned int *id);
433 /** Event device operations function pointer table */
434 struct rte_eventdev_ops {
435 eventdev_info_get_t dev_infos_get; /**< Get device info. */
436 eventdev_configure_t dev_configure; /**< Configure device. */
437 eventdev_start_t dev_start; /**< Start device. */
438 eventdev_stop_t dev_stop; /**< Stop device. */
439 eventdev_close_t dev_close; /**< Close device. */
441 eventdev_queue_default_conf_get_t queue_def_conf;
442 /**< Get default queue configuration. */
443 eventdev_queue_setup_t queue_setup;
444 /**< Set up an event queue. */
445 eventdev_queue_release_t queue_release;
446 /**< Release an event queue. */
448 eventdev_port_default_conf_get_t port_def_conf;
449 /**< Get default port configuration. */
450 eventdev_port_setup_t port_setup;
451 /**< Set up an event port. */
452 eventdev_port_release_t port_release;
453 /**< Release an event port. */
455 eventdev_port_link_t port_link;
456 /**< Link event queues to an event port. */
457 eventdev_port_unlink_t port_unlink;
458 /**< Unlink event queues from an event port. */
459 eventdev_dequeue_timeout_ticks_t timeout_ticks;
460 /**< Converts ns to *timeout_ticks* value for rte_event_dequeue() */
461 eventdev_dump_t dump;
462 /* Dump internal information */
464 eventdev_xstats_get_t xstats_get;
465 /**< Get extended device statistics. */
466 eventdev_xstats_get_names_t xstats_get_names;
467 /**< Get names of extended stats. */
468 eventdev_xstats_get_by_name xstats_get_by_name;
469 /**< Get one value by name. */
470 eventdev_xstats_reset_t xstats_reset;
471 /**< Reset the statistics values in xstats. */
475 * Allocates a new eventdev slot for an event device and returns the pointer
476 * to that slot for the driver to use.
479 * Unique identifier name for each device
481 * Socket to allocate resources on.
483 * - Slot in the rte_dev_devices array for a new device;
485 struct rte_eventdev *
486 rte_event_pmd_allocate(const char *name, int socket_id);
489 * Release the specified eventdev device.
492 * The *eventdev* pointer is the address of the *rte_eventdev* structure.
494 * - 0 on success, negative on error
497 rte_event_pmd_release(struct rte_eventdev *eventdev);
500 * Creates a new virtual event device and returns the pointer to that device.
504 * @param dev_private_size
505 * Size of event PMDs private data
507 * Socket to allocate resources on.
510 * - Eventdev pointer if device is successfully created.
511 * - NULL if device cannot be created.
513 struct rte_eventdev *
514 rte_event_pmd_vdev_init(const char *name, size_t dev_private_size,
518 * Destroy the given virtual event device
523 * - 0 on success, negative on error
526 rte_event_pmd_vdev_uninit(const char *name);
528 typedef int (*eventdev_pmd_pci_callback_t)(struct rte_eventdev *dev);
531 * Wrapper for use by pci drivers as a .probe function to attach to a event
534 int rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv,
535 struct rte_pci_device *pci_dev,
536 size_t private_data_size,
537 eventdev_pmd_pci_callback_t devinit);
540 * Wrapper for use by pci drivers as a .remove function to detach a event
543 int rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev,
544 eventdev_pmd_pci_callback_t devuninit);
550 #endif /* _RTE_EVENTDEV_PMD_H_ */