1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016 Cavium, Inc
5 #ifndef _RTE_EVENTDEV_PMD_H_
6 #define _RTE_EVENTDEV_PMD_H_
12 * These API are from event PMD only and user applications should not call
22 #include <rte_common.h>
23 #include <rte_config.h>
26 #include <rte_malloc.h>
28 #include "rte_eventdev.h"
29 #include "rte_event_timer_adapter_pmd.h"
32 #define RTE_EDEV_LOG_ERR(...) \
33 RTE_LOG(ERR, EVENTDEV, \
34 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
35 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
37 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
38 #define RTE_EDEV_LOG_DEBUG(...) \
39 RTE_LOG(DEBUG, EVENTDEV, \
40 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
41 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
43 #define RTE_EDEV_LOG_DEBUG(...) (void)0
46 /* Macros to check for valid device */
47 #define RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, retval) do { \
48 if (!rte_event_pmd_is_valid_dev((dev_id))) { \
49 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
54 #define RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, errno, retval) do { \
55 if (!rte_event_pmd_is_valid_dev((dev_id))) { \
56 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
62 #define RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id) do { \
63 if (!rte_event_pmd_is_valid_dev((dev_id))) { \
64 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
69 #define RTE_EVENT_ETH_RX_ADAPTER_SW_CAP \
70 ((RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID) | \
71 (RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ))
73 #define RTE_EVENT_CRYPTO_ADAPTER_SW_CAP \
74 RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA
76 /**< Ethernet Rx adapter cap to return If the packet transfers from
77 * the ethdev to eventdev use a SW service function
80 #define RTE_EVENTDEV_DETACHED (0)
81 #define RTE_EVENTDEV_ATTACHED (1)
85 /** Global structure used for maintaining state of allocated event devices */
86 struct rte_eventdev_global {
87 uint8_t nb_devs; /**< Number of devices found */
90 extern struct rte_eventdev_global *rte_eventdev_globals;
91 /** Pointer to global event devices data structure. */
92 extern struct rte_eventdev *rte_eventdevs;
93 /** The pool of rte_eventdev structures. */
96 * Get the rte_eventdev structure device pointer for the named device.
99 * device name to select the device structure.
102 * - The rte_eventdev structure pointer for the given device ID.
104 static inline struct rte_eventdev *
105 rte_event_pmd_get_named_dev(const char *name)
107 struct rte_eventdev *dev;
113 for (i = 0; i < RTE_EVENT_MAX_DEVS; i++) {
114 dev = &rte_eventdevs[i];
115 if ((dev->attached == RTE_EVENTDEV_ATTACHED) &&
116 (strcmp(dev->data->name, name) == 0))
124 * Validate if the event device index is valid attached event device.
127 * Event device index.
130 * - If the device index is valid (1) or not (0).
132 static inline unsigned
133 rte_event_pmd_is_valid_dev(uint8_t dev_id)
135 struct rte_eventdev *dev;
137 if (dev_id >= RTE_EVENT_MAX_DEVS)
140 dev = &rte_eventdevs[dev_id];
141 if (dev->attached != RTE_EVENTDEV_ATTACHED)
148 * Definitions of all functions exported by a driver through the
149 * the generic structure of type *event_dev_ops* supplied in the
150 * *rte_eventdev* structure associated with a device.
154 * Get device information of a device.
157 * Event device pointer
159 * Event device information structure
162 * Returns 0 on success
164 typedef void (*eventdev_info_get_t)(struct rte_eventdev *dev,
165 struct rte_event_dev_info *dev_info);
168 * Configure a device.
171 * Event device pointer
174 * Returns 0 on success
176 typedef int (*eventdev_configure_t)(const struct rte_eventdev *dev);
179 * Start a configured device.
182 * Event device pointer
185 * Returns 0 on success
187 typedef int (*eventdev_start_t)(struct rte_eventdev *dev);
190 * Stop a configured device.
193 * Event device pointer
195 typedef void (*eventdev_stop_t)(struct rte_eventdev *dev);
198 * Close a configured device.
201 * Event device pointer
205 * - (-EAGAIN) if can't close as device is busy
207 typedef int (*eventdev_close_t)(struct rte_eventdev *dev);
210 * Retrieve the default event queue configuration.
213 * Event device pointer
216 * @param[out] queue_conf
217 * Event queue configuration structure
220 typedef void (*eventdev_queue_default_conf_get_t)(struct rte_eventdev *dev,
221 uint8_t queue_id, struct rte_event_queue_conf *queue_conf);
224 * Setup an event queue.
227 * Event device pointer
231 * Event queue configuration structure
234 * Returns 0 on success.
236 typedef int (*eventdev_queue_setup_t)(struct rte_eventdev *dev,
238 const struct rte_event_queue_conf *queue_conf);
241 * Release resources allocated by given event queue.
244 * Event device pointer
249 typedef void (*eventdev_queue_release_t)(struct rte_eventdev *dev,
253 * Retrieve the default event port configuration.
256 * Event device pointer
259 * @param[out] port_conf
260 * Event port configuration structure
263 typedef void (*eventdev_port_default_conf_get_t)(struct rte_eventdev *dev,
264 uint8_t port_id, struct rte_event_port_conf *port_conf);
267 * Setup an event port.
270 * Event device pointer
274 * Event port configuration structure
277 * Returns 0 on success.
279 typedef int (*eventdev_port_setup_t)(struct rte_eventdev *dev,
281 const struct rte_event_port_conf *port_conf);
284 * Release memory resources allocated by given event port.
290 typedef void (*eventdev_port_release_t)(void *port);
293 * Link multiple source event queues to destination event port.
296 * Event device pointer
300 * Points to an array of *nb_links* event queues to be linked
303 * Points to an array of *nb_links* service priorities associated with each
304 * event queue link to event port.
306 * The number of links to establish
309 * Returns 0 on success.
312 typedef int (*eventdev_port_link_t)(struct rte_eventdev *dev, void *port,
313 const uint8_t queues[], const uint8_t priorities[],
317 * Unlink multiple source event queues from destination event port.
320 * Event device pointer
324 * An array of *nb_unlinks* event queues to be unlinked from the event port.
326 * The number of unlinks to establish
329 * Returns 0 on success.
332 typedef int (*eventdev_port_unlink_t)(struct rte_eventdev *dev, void *port,
333 uint8_t queues[], uint16_t nb_unlinks);
336 * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue()
339 * Event device pointer
341 * Wait time in nanosecond
342 * @param[out] timeout_ticks
343 * Value for the *timeout_ticks* parameter in rte_event_dequeue() function
346 * Returns 0 on success.
349 typedef int (*eventdev_dequeue_timeout_ticks_t)(struct rte_eventdev *dev,
350 uint64_t ns, uint64_t *timeout_ticks);
353 * Dump internal information
356 * Event device pointer
358 * A pointer to a file for output
361 typedef void (*eventdev_dump_t)(struct rte_eventdev *dev, FILE *f);
364 * Retrieve a set of statistics from device
367 * Event device pointer
369 * The stat ids to retrieve
371 * The returned stat values
373 * The number of id values and entries in the values array
375 * The number of stat values successfully filled into the values array
377 typedef int (*eventdev_xstats_get_t)(const struct rte_eventdev *dev,
378 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
379 const unsigned int ids[], uint64_t values[], unsigned int n);
382 * Resets the statistic values in xstats for the device, based on mode.
384 typedef int (*eventdev_xstats_reset_t)(struct rte_eventdev *dev,
385 enum rte_event_dev_xstats_mode mode,
386 int16_t queue_port_id,
387 const uint32_t ids[],
391 * Get names of extended stats of an event device
394 * Event device pointer
395 * @param xstats_names
396 * Array of name values to be filled in
398 * Number of values in the xstats_names array
400 * When size >= the number of stats, return the number of stat values filled
402 * When size < the number of available stats, return the number of stats
403 * values, and do not fill in any data into xstats_names.
405 typedef int (*eventdev_xstats_get_names_t)(const struct rte_eventdev *dev,
406 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
407 struct rte_event_dev_xstats_name *xstats_names,
408 unsigned int *ids, unsigned int size);
411 * Get value of one stats and optionally return its id
414 * Event device pointer
416 * The name of the stat to retrieve
418 * Pointer to an unsigned int where we store the stat-id for future reference.
419 * This pointer may be null if the id is not required.
421 * The value of the stat, or (uint64_t)-1 if the stat is not found.
422 * If the stat is not found, the id value will be returned as (unsigned)-1,
423 * if id pointer is non-NULL
425 typedef uint64_t (*eventdev_xstats_get_by_name)(const struct rte_eventdev *dev,
426 const char *name, unsigned int *id);
430 * Retrieve the event device's ethdev Rx adapter capabilities for the
431 * specified ethernet port
434 * Event device pointer
437 * Ethernet device pointer
440 * A pointer to memory filled with Rx event adapter capabilities.
443 * - 0: Success, driver provides Rx event adapter capabilities for the
445 * - <0: Error code returned by the driver function.
448 typedef int (*eventdev_eth_rx_adapter_caps_get_t)
449 (const struct rte_eventdev *dev,
450 const struct rte_eth_dev *eth_dev,
453 struct rte_event_eth_rx_adapter_queue_conf *queue_conf;
456 * Retrieve the event device's timer adapter capabilities, as well as the ops
457 * structure that an event timer adapter should call through to enter the
461 * Event device pointer
464 * Flags that can be used to determine how to select an event timer
465 * adapter ops structure
468 * A pointer to memory filled with Rx event adapter capabilities.
471 * A pointer to the ops pointer to set with the address of the desired ops
475 * - 0: Success, driver provides Rx event adapter capabilities for the
477 * - <0: Error code returned by the driver function.
480 typedef int (*eventdev_timer_adapter_caps_get_t)(
481 const struct rte_eventdev *dev,
484 const struct rte_event_timer_adapter_ops **ops);
487 * Add ethernet Rx queues to event device. This callback is invoked if
488 * the caps returned from rte_eventdev_eth_rx_adapter_caps_get(, eth_port_id)
489 * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
492 * Event device pointer
495 * Ethernet device pointer
498 * Ethernet device receive queue index
501 * Additional configuration structure
504 * - 0: Success, ethernet receive queue added successfully.
505 * - <0: Error code returned by the driver function.
508 typedef int (*eventdev_eth_rx_adapter_queue_add_t)(
509 const struct rte_eventdev *dev,
510 const struct rte_eth_dev *eth_dev,
512 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
515 * Delete ethernet Rx queues from event device. This callback is invoked if
516 * the caps returned from eventdev_eth_rx_adapter_caps_get(, eth_port_id)
517 * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
520 * Event device pointer
523 * Ethernet device pointer
526 * Ethernet device receive queue index
529 * - 0: Success, ethernet receive queue deleted successfully.
530 * - <0: Error code returned by the driver function.
533 typedef int (*eventdev_eth_rx_adapter_queue_del_t)
534 (const struct rte_eventdev *dev,
535 const struct rte_eth_dev *eth_dev,
536 int32_t rx_queue_id);
539 * Start ethernet Rx adapter. This callback is invoked if
540 * the caps returned from eventdev_eth_rx_adapter_caps_get(.., eth_port_id)
541 * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
542 * from eth_port_id have been added to the event device.
545 * Event device pointer
548 * Ethernet device pointer
551 * - 0: Success, ethernet Rx adapter started successfully.
552 * - <0: Error code returned by the driver function.
554 typedef int (*eventdev_eth_rx_adapter_start_t)
555 (const struct rte_eventdev *dev,
556 const struct rte_eth_dev *eth_dev);
559 * Stop ethernet Rx adapter. This callback is invoked if
560 * the caps returned from eventdev_eth_rx_adapter_caps_get(..,eth_port_id)
561 * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
562 * from eth_port_id have been added to the event device.
565 * Event device pointer
568 * Ethernet device pointer
571 * - 0: Success, ethernet Rx adapter stopped successfully.
572 * - <0: Error code returned by the driver function.
574 typedef int (*eventdev_eth_rx_adapter_stop_t)
575 (const struct rte_eventdev *dev,
576 const struct rte_eth_dev *eth_dev);
578 struct rte_event_eth_rx_adapter_stats *stats;
581 * Retrieve ethernet Rx adapter statistics.
584 * Event device pointer
587 * Ethernet device pointer
590 * Pointer to stats structure
593 * Return 0 on success.
596 typedef int (*eventdev_eth_rx_adapter_stats_get)
597 (const struct rte_eventdev *dev,
598 const struct rte_eth_dev *eth_dev,
599 struct rte_event_eth_rx_adapter_stats *stats);
601 * Reset ethernet Rx adapter statistics.
604 * Event device pointer
607 * Ethernet device pointer
610 * Return 0 on success.
612 typedef int (*eventdev_eth_rx_adapter_stats_reset)
613 (const struct rte_eventdev *dev,
614 const struct rte_eth_dev *eth_dev);
616 * Start eventdev selftest.
619 * Return 0 on success.
621 typedef int (*eventdev_selftest)(void);
624 struct rte_cryptodev;
627 * This API may change without prior notice
629 * Retrieve the event device's crypto adapter capabilities for the
630 * specified cryptodev
633 * Event device pointer
639 * A pointer to memory filled with event adapter capabilities.
640 * It is expected to be pre-allocated & initialized by caller.
643 * - 0: Success, driver provides event adapter capabilities for the
645 * - <0: Error code returned by the driver function.
648 typedef int (*eventdev_crypto_adapter_caps_get_t)
649 (const struct rte_eventdev *dev,
650 const struct rte_cryptodev *cdev,
654 * This API may change without prior notice
656 * Add crypto queue pair to event device. This callback is invoked if
657 * the caps returned from rte_event_crypto_adapter_caps_get(, cdev_id)
658 * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set.
661 * Event device pointer
666 * @param queue_pair_id
667 * cryptodev queue pair identifier.
670 * Event information required for binding cryptodev queue pair to event queue.
671 * This structure will have a valid value for only those HW PMDs supporting
672 * @see RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND capability.
675 * - 0: Success, cryptodev queue pair added successfully.
676 * - <0: Error code returned by the driver function.
679 typedef int (*eventdev_crypto_adapter_queue_pair_add_t)
680 (const struct rte_eventdev *dev,
681 const struct rte_cryptodev *cdev,
682 int32_t queue_pair_id,
683 const struct rte_event *event);
687 * This API may change without prior notice
689 * Delete crypto queue pair to event device. This callback is invoked if
690 * the caps returned from rte_event_crypto_adapter_caps_get(, cdev_id)
691 * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set.
694 * Event device pointer
699 * @param queue_pair_id
700 * cryptodev queue pair identifier.
703 * - 0: Success, cryptodev queue pair deleted successfully.
704 * - <0: Error code returned by the driver function.
707 typedef int (*eventdev_crypto_adapter_queue_pair_del_t)
708 (const struct rte_eventdev *dev,
709 const struct rte_cryptodev *cdev,
710 int32_t queue_pair_id);
713 * Start crypto adapter. This callback is invoked if
714 * the caps returned from rte_event_crypto_adapter_caps_get(.., cdev_id)
715 * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set and queue pairs
716 * from cdev_id have been added to the event device.
719 * Event device pointer
722 * Crypto device pointer
725 * - 0: Success, crypto adapter started successfully.
726 * - <0: Error code returned by the driver function.
728 typedef int (*eventdev_crypto_adapter_start_t)
729 (const struct rte_eventdev *dev,
730 const struct rte_cryptodev *cdev);
733 * Stop crypto adapter. This callback is invoked if
734 * the caps returned from rte_event_crypto_adapter_caps_get(.., cdev_id)
735 * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set and queue pairs
736 * from cdev_id have been added to the event device.
739 * Event device pointer
742 * Crypto device pointer
745 * - 0: Success, crypto adapter stopped successfully.
746 * - <0: Error code returned by the driver function.
748 typedef int (*eventdev_crypto_adapter_stop_t)
749 (const struct rte_eventdev *dev,
750 const struct rte_cryptodev *cdev);
752 struct rte_event_crypto_adapter_stats;
755 * Retrieve crypto adapter statistics.
758 * Event device pointer
761 * Crypto device pointer
764 * Pointer to stats structure
767 * Return 0 on success.
770 typedef int (*eventdev_crypto_adapter_stats_get)
771 (const struct rte_eventdev *dev,
772 const struct rte_cryptodev *cdev,
773 struct rte_event_crypto_adapter_stats *stats);
776 * Reset crypto adapter statistics.
779 * Event device pointer
782 * Crypto device pointer
785 * Return 0 on success.
788 typedef int (*eventdev_crypto_adapter_stats_reset)
789 (const struct rte_eventdev *dev,
790 const struct rte_cryptodev *cdev);
792 /** Event device operations function pointer table */
793 struct rte_eventdev_ops {
794 eventdev_info_get_t dev_infos_get; /**< Get device info. */
795 eventdev_configure_t dev_configure; /**< Configure device. */
796 eventdev_start_t dev_start; /**< Start device. */
797 eventdev_stop_t dev_stop; /**< Stop device. */
798 eventdev_close_t dev_close; /**< Close device. */
800 eventdev_queue_default_conf_get_t queue_def_conf;
801 /**< Get default queue configuration. */
802 eventdev_queue_setup_t queue_setup;
803 /**< Set up an event queue. */
804 eventdev_queue_release_t queue_release;
805 /**< Release an event queue. */
807 eventdev_port_default_conf_get_t port_def_conf;
808 /**< Get default port configuration. */
809 eventdev_port_setup_t port_setup;
810 /**< Set up an event port. */
811 eventdev_port_release_t port_release;
812 /**< Release an event port. */
814 eventdev_port_link_t port_link;
815 /**< Link event queues to an event port. */
816 eventdev_port_unlink_t port_unlink;
817 /**< Unlink event queues from an event port. */
818 eventdev_dequeue_timeout_ticks_t timeout_ticks;
819 /**< Converts ns to *timeout_ticks* value for rte_event_dequeue() */
820 eventdev_dump_t dump;
821 /* Dump internal information */
823 eventdev_xstats_get_t xstats_get;
824 /**< Get extended device statistics. */
825 eventdev_xstats_get_names_t xstats_get_names;
826 /**< Get names of extended stats. */
827 eventdev_xstats_get_by_name xstats_get_by_name;
828 /**< Get one value by name. */
829 eventdev_xstats_reset_t xstats_reset;
830 /**< Reset the statistics values in xstats. */
832 eventdev_eth_rx_adapter_caps_get_t eth_rx_adapter_caps_get;
833 /**< Get ethernet Rx adapter capabilities */
834 eventdev_eth_rx_adapter_queue_add_t eth_rx_adapter_queue_add;
835 /**< Add Rx queues to ethernet Rx adapter */
836 eventdev_eth_rx_adapter_queue_del_t eth_rx_adapter_queue_del;
837 /**< Delete Rx queues from ethernet Rx adapter */
838 eventdev_eth_rx_adapter_start_t eth_rx_adapter_start;
839 /**< Start ethernet Rx adapter */
840 eventdev_eth_rx_adapter_stop_t eth_rx_adapter_stop;
841 /**< Stop ethernet Rx adapter */
842 eventdev_eth_rx_adapter_stats_get eth_rx_adapter_stats_get;
843 /**< Get ethernet Rx stats */
844 eventdev_eth_rx_adapter_stats_reset eth_rx_adapter_stats_reset;
845 /**< Reset ethernet Rx stats */
847 eventdev_timer_adapter_caps_get_t timer_adapter_caps_get;
848 /**< Get timer adapter capabilities */
850 eventdev_crypto_adapter_caps_get_t crypto_adapter_caps_get;
851 /**< Get crypto adapter capabilities */
852 eventdev_crypto_adapter_queue_pair_add_t crypto_adapter_queue_pair_add;
853 /**< Add queue pair to crypto adapter */
854 eventdev_crypto_adapter_queue_pair_del_t crypto_adapter_queue_pair_del;
855 /**< Delete queue pair from crypto adapter */
856 eventdev_crypto_adapter_start_t crypto_adapter_start;
857 /**< Start crypto adapter */
858 eventdev_crypto_adapter_stop_t crypto_adapter_stop;
859 /**< Stop crypto adapter */
860 eventdev_crypto_adapter_stats_get crypto_adapter_stats_get;
861 /**< Get crypto stats */
862 eventdev_crypto_adapter_stats_reset crypto_adapter_stats_reset;
863 /**< Reset crypto stats */
865 eventdev_selftest dev_selftest;
866 /**< Start eventdev Selftest */
868 eventdev_stop_flush_t dev_stop_flush;
869 /**< User-provided event flush function */
873 * Allocates a new eventdev slot for an event device and returns the pointer
874 * to that slot for the driver to use.
877 * Unique identifier name for each device
879 * Socket to allocate resources on.
881 * - Slot in the rte_dev_devices array for a new device;
883 struct rte_eventdev *
884 rte_event_pmd_allocate(const char *name, int socket_id);
887 * Release the specified eventdev device.
890 * The *eventdev* pointer is the address of the *rte_eventdev* structure.
892 * - 0 on success, negative on error
895 rte_event_pmd_release(struct rte_eventdev *eventdev);
901 #endif /* _RTE_EVENTDEV_PMD_H_ */