3 * Copyright(c) 2016 Cavium, Inc. 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, Inc 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
49 #include <rte_common.h>
50 #include <rte_config.h>
53 #include <rte_malloc.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_ERRNO_RET(dev_id, errno, retval) do { \
81 if (!rte_event_pmd_is_valid_dev((dev_id))) { \
82 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
88 #define RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id) do { \
89 if (!rte_event_pmd_is_valid_dev((dev_id))) { \
90 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
95 #define RTE_EVENT_ETH_RX_ADAPTER_SW_CAP \
96 ((RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID) | \
97 (RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ))
99 /**< Ethernet Rx adapter cap to return If the packet transfers from
100 * the ethdev to eventdev use a SW service function
103 #define RTE_EVENTDEV_DETACHED (0)
104 #define RTE_EVENTDEV_ATTACHED (1)
108 /** Global structure used for maintaining state of allocated event devices */
109 struct rte_eventdev_global {
110 uint8_t nb_devs; /**< Number of devices found */
113 extern struct rte_eventdev_global *rte_eventdev_globals;
114 /** Pointer to global event devices data structure. */
115 extern struct rte_eventdev *rte_eventdevs;
116 /** The pool of rte_eventdev structures. */
119 * Get the rte_eventdev structure device pointer for the named device.
122 * device name to select the device structure.
125 * - The rte_eventdev structure pointer for the given device ID.
127 static inline struct rte_eventdev *
128 rte_event_pmd_get_named_dev(const char *name)
130 struct rte_eventdev *dev;
136 for (i = 0; i < RTE_EVENT_MAX_DEVS; i++) {
137 dev = &rte_eventdevs[i];
138 if ((dev->attached == RTE_EVENTDEV_ATTACHED) &&
139 (strcmp(dev->data->name, name) == 0))
147 * Validate if the event device index is valid attached event device.
150 * Event device index.
153 * - If the device index is valid (1) or not (0).
155 static inline unsigned
156 rte_event_pmd_is_valid_dev(uint8_t dev_id)
158 struct rte_eventdev *dev;
160 if (dev_id >= RTE_EVENT_MAX_DEVS)
163 dev = &rte_eventdevs[dev_id];
164 if (dev->attached != RTE_EVENTDEV_ATTACHED)
171 * Definitions of all functions exported by a driver through the
172 * the generic structure of type *event_dev_ops* supplied in the
173 * *rte_eventdev* structure associated with a device.
177 * Get device information of a device.
180 * Event device pointer
182 * Event device information structure
185 * Returns 0 on success
187 typedef void (*eventdev_info_get_t)(struct rte_eventdev *dev,
188 struct rte_event_dev_info *dev_info);
191 * Configure a device.
194 * Event device pointer
197 * Returns 0 on success
199 typedef int (*eventdev_configure_t)(const struct rte_eventdev *dev);
202 * Start a configured device.
205 * Event device pointer
208 * Returns 0 on success
210 typedef int (*eventdev_start_t)(struct rte_eventdev *dev);
213 * Stop a configured device.
216 * Event device pointer
218 typedef void (*eventdev_stop_t)(struct rte_eventdev *dev);
221 * Close a configured device.
224 * Event device pointer
228 * - (-EAGAIN) if can't close as device is busy
230 typedef int (*eventdev_close_t)(struct rte_eventdev *dev);
233 * Retrieve the default event queue configuration.
236 * Event device pointer
239 * @param[out] queue_conf
240 * Event queue configuration structure
243 typedef void (*eventdev_queue_default_conf_get_t)(struct rte_eventdev *dev,
244 uint8_t queue_id, struct rte_event_queue_conf *queue_conf);
247 * Setup an event queue.
250 * Event device pointer
254 * Event queue configuration structure
257 * Returns 0 on success.
259 typedef int (*eventdev_queue_setup_t)(struct rte_eventdev *dev,
261 const struct rte_event_queue_conf *queue_conf);
264 * Release resources allocated by given event queue.
267 * Event device pointer
272 typedef void (*eventdev_queue_release_t)(struct rte_eventdev *dev,
276 * Retrieve the default event port configuration.
279 * Event device pointer
282 * @param[out] port_conf
283 * Event port configuration structure
286 typedef void (*eventdev_port_default_conf_get_t)(struct rte_eventdev *dev,
287 uint8_t port_id, struct rte_event_port_conf *port_conf);
290 * Setup an event port.
293 * Event device pointer
297 * Event port configuration structure
300 * Returns 0 on success.
302 typedef int (*eventdev_port_setup_t)(struct rte_eventdev *dev,
304 const struct rte_event_port_conf *port_conf);
307 * Release memory resources allocated by given event port.
313 typedef void (*eventdev_port_release_t)(void *port);
316 * Link multiple source event queues to destination event port.
319 * Event device pointer
323 * Points to an array of *nb_links* event queues to be linked
326 * Points to an array of *nb_links* service priorities associated with each
327 * event queue link to event port.
329 * The number of links to establish
332 * Returns 0 on success.
335 typedef int (*eventdev_port_link_t)(struct rte_eventdev *dev, void *port,
336 const uint8_t queues[], const uint8_t priorities[],
340 * Unlink multiple source event queues from destination event port.
343 * Event device pointer
347 * An array of *nb_unlinks* event queues to be unlinked from the event port.
349 * The number of unlinks to establish
352 * Returns 0 on success.
355 typedef int (*eventdev_port_unlink_t)(struct rte_eventdev *dev, void *port,
356 uint8_t queues[], uint16_t nb_unlinks);
359 * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue()
362 * Event device pointer
364 * Wait time in nanosecond
365 * @param[out] timeout_ticks
366 * Value for the *timeout_ticks* parameter in rte_event_dequeue() function
369 * Returns 0 on success.
372 typedef int (*eventdev_dequeue_timeout_ticks_t)(struct rte_eventdev *dev,
373 uint64_t ns, uint64_t *timeout_ticks);
376 * Dump internal information
379 * Event device pointer
381 * A pointer to a file for output
384 typedef void (*eventdev_dump_t)(struct rte_eventdev *dev, FILE *f);
387 * Retrieve a set of statistics from device
390 * Event device pointer
392 * The stat ids to retrieve
394 * The returned stat values
396 * The number of id values and entries in the values array
398 * The number of stat values successfully filled into the values array
400 typedef int (*eventdev_xstats_get_t)(const struct rte_eventdev *dev,
401 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
402 const unsigned int ids[], uint64_t values[], unsigned int n);
405 * Resets the statistic values in xstats for the device, based on mode.
407 typedef int (*eventdev_xstats_reset_t)(struct rte_eventdev *dev,
408 enum rte_event_dev_xstats_mode mode,
409 int16_t queue_port_id,
410 const uint32_t ids[],
414 * Get names of extended stats of an event device
417 * Event device pointer
418 * @param xstats_names
419 * Array of name values to be filled in
421 * Number of values in the xstats_names array
423 * When size >= the number of stats, return the number of stat values filled
425 * When size < the number of available stats, return the number of stats
426 * values, and do not fill in any data into xstats_names.
428 typedef int (*eventdev_xstats_get_names_t)(const struct rte_eventdev *dev,
429 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
430 struct rte_event_dev_xstats_name *xstats_names,
431 unsigned int *ids, unsigned int size);
434 * Get value of one stats and optionally return its id
437 * Event device pointer
439 * The name of the stat to retrieve
441 * Pointer to an unsigned int where we store the stat-id for future reference.
442 * This pointer may be null if the id is not required.
444 * The value of the stat, or (uint64_t)-1 if the stat is not found.
445 * If the stat is not found, the id value will be returned as (unsigned)-1,
446 * if id pointer is non-NULL
448 typedef uint64_t (*eventdev_xstats_get_by_name)(const struct rte_eventdev *dev,
449 const char *name, unsigned int *id);
453 * Retrieve the event device's ethdev Rx adapter capabilities for the
454 * specified ethernet port
457 * Event device pointer
460 * Ethernet device pointer
463 * A pointer to memory filled with Rx event adapter capabilities.
466 * - 0: Success, driver provides Rx event adapter capabilities for the
468 * - <0: Error code returned by the driver function.
471 typedef int (*eventdev_eth_rx_adapter_caps_get_t)
472 (const struct rte_eventdev *dev,
473 const struct rte_eth_dev *eth_dev,
476 struct rte_event_eth_rx_adapter_queue_conf *queue_conf;
479 * Add ethernet Rx queues to event device. This callback is invoked if
480 * the caps returned from rte_eventdev_eth_rx_adapter_caps_get(, eth_port_id)
481 * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
484 * Event device pointer
487 * Ethernet device pointer
490 * Ethernet device receive queue index
493 * Additional configuration structure
496 * - 0: Success, ethernet receive queue added successfully.
497 * - <0: Error code returned by the driver function.
500 typedef int (*eventdev_eth_rx_adapter_queue_add_t)(
501 const struct rte_eventdev *dev,
502 const struct rte_eth_dev *eth_dev,
504 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
507 * Delete ethernet Rx queues from event device. This callback is invoked if
508 * the caps returned from eventdev_eth_rx_adapter_caps_get(, eth_port_id)
509 * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
512 * Event device pointer
515 * Ethernet device pointer
518 * Ethernet device receive queue index
521 * - 0: Success, ethernet receive queue deleted successfully.
522 * - <0: Error code returned by the driver function.
525 typedef int (*eventdev_eth_rx_adapter_queue_del_t)
526 (const struct rte_eventdev *dev,
527 const struct rte_eth_dev *eth_dev,
528 int32_t rx_queue_id);
531 * Start ethernet Rx adapter. This callback is invoked if
532 * the caps returned from eventdev_eth_rx_adapter_caps_get(.., eth_port_id)
533 * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
534 * from eth_port_id have been added to the event device.
537 * Event device pointer
540 * Ethernet device pointer
543 * - 0: Success, ethernet Rx adapter started successfully.
544 * - <0: Error code returned by the driver function.
546 typedef int (*eventdev_eth_rx_adapter_start_t)
547 (const struct rte_eventdev *dev,
548 const struct rte_eth_dev *eth_dev);
551 * Stop ethernet Rx adapter. This callback is invoked if
552 * the caps returned from eventdev_eth_rx_adapter_caps_get(..,eth_port_id)
553 * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
554 * from eth_port_id have been added to the event device.
557 * Event device pointer
560 * Ethernet device pointer
563 * - 0: Success, ethernet Rx adapter stopped successfully.
564 * - <0: Error code returned by the driver function.
566 typedef int (*eventdev_eth_rx_adapter_stop_t)
567 (const struct rte_eventdev *dev,
568 const struct rte_eth_dev *eth_dev);
570 struct rte_event_eth_rx_adapter_stats *stats;
573 * Retrieve ethernet Rx adapter statistics.
576 * Event device pointer
579 * Ethernet device pointer
582 * Pointer to stats structure
585 * Return 0 on success.
588 typedef int (*eventdev_eth_rx_adapter_stats_get)
589 (const struct rte_eventdev *dev,
590 const struct rte_eth_dev *eth_dev,
591 struct rte_event_eth_rx_adapter_stats *stats);
593 * Reset ethernet Rx adapter statistics.
596 * Event device pointer
599 * Ethernet device pointer
602 * Return 0 on success.
604 typedef int (*eventdev_eth_rx_adapter_stats_reset)
605 (const struct rte_eventdev *dev,
606 const struct rte_eth_dev *eth_dev);
608 /** Event device operations function pointer table */
609 struct rte_eventdev_ops {
610 eventdev_info_get_t dev_infos_get; /**< Get device info. */
611 eventdev_configure_t dev_configure; /**< Configure device. */
612 eventdev_start_t dev_start; /**< Start device. */
613 eventdev_stop_t dev_stop; /**< Stop device. */
614 eventdev_close_t dev_close; /**< Close device. */
616 eventdev_queue_default_conf_get_t queue_def_conf;
617 /**< Get default queue configuration. */
618 eventdev_queue_setup_t queue_setup;
619 /**< Set up an event queue. */
620 eventdev_queue_release_t queue_release;
621 /**< Release an event queue. */
623 eventdev_port_default_conf_get_t port_def_conf;
624 /**< Get default port configuration. */
625 eventdev_port_setup_t port_setup;
626 /**< Set up an event port. */
627 eventdev_port_release_t port_release;
628 /**< Release an event port. */
630 eventdev_port_link_t port_link;
631 /**< Link event queues to an event port. */
632 eventdev_port_unlink_t port_unlink;
633 /**< Unlink event queues from an event port. */
634 eventdev_dequeue_timeout_ticks_t timeout_ticks;
635 /**< Converts ns to *timeout_ticks* value for rte_event_dequeue() */
636 eventdev_dump_t dump;
637 /* Dump internal information */
639 eventdev_xstats_get_t xstats_get;
640 /**< Get extended device statistics. */
641 eventdev_xstats_get_names_t xstats_get_names;
642 /**< Get names of extended stats. */
643 eventdev_xstats_get_by_name xstats_get_by_name;
644 /**< Get one value by name. */
645 eventdev_xstats_reset_t xstats_reset;
646 /**< Reset the statistics values in xstats. */
648 eventdev_eth_rx_adapter_caps_get_t eth_rx_adapter_caps_get;
649 /**< Get ethernet Rx adapter capabilities */
650 eventdev_eth_rx_adapter_queue_add_t eth_rx_adapter_queue_add;
651 /**< Add Rx queues to ethernet Rx adapter */
652 eventdev_eth_rx_adapter_queue_del_t eth_rx_adapter_queue_del;
653 /**< Delete Rx queues from ethernet Rx adapter */
654 eventdev_eth_rx_adapter_start_t eth_rx_adapter_start;
655 /**< Start ethernet Rx adapter */
656 eventdev_eth_rx_adapter_stop_t eth_rx_adapter_stop;
657 /**< Stop ethernet Rx adapter */
658 eventdev_eth_rx_adapter_stats_get eth_rx_adapter_stats_get;
659 /**< Get ethernet Rx stats */
660 eventdev_eth_rx_adapter_stats_reset eth_rx_adapter_stats_reset;
661 /**< Reset ethernet Rx stats */
665 * Allocates a new eventdev slot for an event device and returns the pointer
666 * to that slot for the driver to use.
669 * Unique identifier name for each device
671 * Socket to allocate resources on.
673 * - Slot in the rte_dev_devices array for a new device;
675 struct rte_eventdev *
676 rte_event_pmd_allocate(const char *name, int socket_id);
679 * Release the specified eventdev device.
682 * The *eventdev* pointer is the address of the *rte_eventdev* structure.
684 * - 0 on success, negative on error
687 rte_event_pmd_release(struct rte_eventdev *eventdev);
693 #endif /* _RTE_EVENTDEV_PMD_H_ */