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>
52 #include <rte_malloc.h>
54 #include "rte_eventdev.h"
57 #define RTE_EDEV_LOG_ERR(...) \
58 RTE_LOG(ERR, EVENTDEV, \
59 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
60 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
62 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
63 #define RTE_EDEV_LOG_DEBUG(...) \
64 RTE_LOG(DEBUG, EVENTDEV, \
65 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
66 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
68 #define RTE_EDEV_LOG_DEBUG(...) (void)0
71 /* Macros to check for valid device */
72 #define RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, retval) do { \
73 if (!rte_event_pmd_is_valid_dev((dev_id))) { \
74 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
79 #define RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id) do { \
80 if (!rte_event_pmd_is_valid_dev((dev_id))) { \
81 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
86 #define RTE_EVENT_ETH_RX_ADAPTER_SW_CAP \
87 ((RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID) | \
88 (RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ))
90 /**< Ethernet Rx adapter cap to return If the packet transfers from
91 * the ethdev to eventdev use a SW service function
94 #define RTE_EVENTDEV_DETACHED (0)
95 #define RTE_EVENTDEV_ATTACHED (1)
99 /** Global structure used for maintaining state of allocated event devices */
100 struct rte_eventdev_global {
101 uint8_t nb_devs; /**< Number of devices found */
104 extern struct rte_eventdev_global *rte_eventdev_globals;
105 /** Pointer to global event devices data structure. */
106 extern struct rte_eventdev *rte_eventdevs;
107 /** The pool of rte_eventdev structures. */
110 * Get the rte_eventdev structure device pointer for the named device.
113 * device name to select the device structure.
116 * - The rte_eventdev structure pointer for the given device ID.
118 static inline struct rte_eventdev *
119 rte_event_pmd_get_named_dev(const char *name)
121 struct rte_eventdev *dev;
127 for (i = 0; i < RTE_EVENT_MAX_DEVS; i++) {
128 dev = &rte_eventdevs[i];
129 if ((dev->attached == RTE_EVENTDEV_ATTACHED) &&
130 (strcmp(dev->data->name, name) == 0))
138 * Validate if the event device index is valid attached event device.
141 * Event device index.
144 * - If the device index is valid (1) or not (0).
146 static inline unsigned
147 rte_event_pmd_is_valid_dev(uint8_t dev_id)
149 struct rte_eventdev *dev;
151 if (dev_id >= RTE_EVENT_MAX_DEVS)
154 dev = &rte_eventdevs[dev_id];
155 if (dev->attached != RTE_EVENTDEV_ATTACHED)
162 * Definitions of all functions exported by a driver through the
163 * the generic structure of type *event_dev_ops* supplied in the
164 * *rte_eventdev* structure associated with a device.
168 * Get device information of a device.
171 * Event device pointer
173 * Event device information structure
176 * Returns 0 on success
178 typedef void (*eventdev_info_get_t)(struct rte_eventdev *dev,
179 struct rte_event_dev_info *dev_info);
182 * Configure a device.
185 * Event device pointer
188 * Returns 0 on success
190 typedef int (*eventdev_configure_t)(const struct rte_eventdev *dev);
193 * Start a configured device.
196 * Event device pointer
199 * Returns 0 on success
201 typedef int (*eventdev_start_t)(struct rte_eventdev *dev);
204 * Stop a configured device.
207 * Event device pointer
209 typedef void (*eventdev_stop_t)(struct rte_eventdev *dev);
212 * Close a configured device.
215 * Event device pointer
219 * - (-EAGAIN) if can't close as device is busy
221 typedef int (*eventdev_close_t)(struct rte_eventdev *dev);
224 * Retrieve the default event queue configuration.
227 * Event device pointer
230 * @param[out] queue_conf
231 * Event queue configuration structure
234 typedef void (*eventdev_queue_default_conf_get_t)(struct rte_eventdev *dev,
235 uint8_t queue_id, struct rte_event_queue_conf *queue_conf);
238 * Setup an event queue.
241 * Event device pointer
245 * Event queue configuration structure
248 * Returns 0 on success.
250 typedef int (*eventdev_queue_setup_t)(struct rte_eventdev *dev,
252 const struct rte_event_queue_conf *queue_conf);
255 * Release resources allocated by given event queue.
258 * Event device pointer
263 typedef void (*eventdev_queue_release_t)(struct rte_eventdev *dev,
267 * Retrieve the default event port configuration.
270 * Event device pointer
273 * @param[out] port_conf
274 * Event port configuration structure
277 typedef void (*eventdev_port_default_conf_get_t)(struct rte_eventdev *dev,
278 uint8_t port_id, struct rte_event_port_conf *port_conf);
281 * Setup an event port.
284 * Event device pointer
288 * Event port configuration structure
291 * Returns 0 on success.
293 typedef int (*eventdev_port_setup_t)(struct rte_eventdev *dev,
295 const struct rte_event_port_conf *port_conf);
298 * Release memory resources allocated by given event port.
304 typedef void (*eventdev_port_release_t)(void *port);
307 * Link multiple source event queues to destination event port.
310 * Event device pointer
314 * Points to an array of *nb_links* event queues to be linked
317 * Points to an array of *nb_links* service priorities associated with each
318 * event queue link to event port.
320 * The number of links to establish
323 * Returns 0 on success.
326 typedef int (*eventdev_port_link_t)(struct rte_eventdev *dev, void *port,
327 const uint8_t queues[], const uint8_t priorities[],
331 * Unlink multiple source event queues from destination event port.
334 * Event device pointer
338 * An array of *nb_unlinks* event queues to be unlinked from the event port.
340 * The number of unlinks to establish
343 * Returns 0 on success.
346 typedef int (*eventdev_port_unlink_t)(struct rte_eventdev *dev, void *port,
347 uint8_t queues[], uint16_t nb_unlinks);
350 * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue()
353 * Event device pointer
355 * Wait time in nanosecond
356 * @param[out] timeout_ticks
357 * Value for the *timeout_ticks* parameter in rte_event_dequeue() function
360 * Returns 0 on success.
363 typedef int (*eventdev_dequeue_timeout_ticks_t)(struct rte_eventdev *dev,
364 uint64_t ns, uint64_t *timeout_ticks);
367 * Dump internal information
370 * Event device pointer
372 * A pointer to a file for output
375 typedef void (*eventdev_dump_t)(struct rte_eventdev *dev, FILE *f);
378 * Retrieve a set of statistics from device
381 * Event device pointer
383 * The stat ids to retrieve
385 * The returned stat values
387 * The number of id values and entries in the values array
389 * The number of stat values successfully filled into the values array
391 typedef int (*eventdev_xstats_get_t)(const struct rte_eventdev *dev,
392 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
393 const unsigned int ids[], uint64_t values[], unsigned int n);
396 * Resets the statistic values in xstats for the device, based on mode.
398 typedef int (*eventdev_xstats_reset_t)(struct rte_eventdev *dev,
399 enum rte_event_dev_xstats_mode mode,
400 int16_t queue_port_id,
401 const uint32_t ids[],
405 * Get names of extended stats of an event device
408 * Event device pointer
409 * @param xstats_names
410 * Array of name values to be filled in
412 * Number of values in the xstats_names array
414 * When size >= the number of stats, return the number of stat values filled
416 * When size < the number of available stats, return the number of stats
417 * values, and do not fill in any data into xstats_names.
419 typedef int (*eventdev_xstats_get_names_t)(const struct rte_eventdev *dev,
420 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
421 struct rte_event_dev_xstats_name *xstats_names,
422 unsigned int *ids, unsigned int size);
425 * Get value of one stats and optionally return its id
428 * Event device pointer
430 * The name of the stat to retrieve
432 * Pointer to an unsigned int where we store the stat-id for future reference.
433 * This pointer may be null if the id is not required.
435 * The value of the stat, or (uint64_t)-1 if the stat is not found.
436 * If the stat is not found, the id value will be returned as (unsigned)-1,
437 * if id pointer is non-NULL
439 typedef uint64_t (*eventdev_xstats_get_by_name)(const struct rte_eventdev *dev,
440 const char *name, unsigned int *id);
444 * Retrieve the event device's ethdev Rx adapter capabilities for the
445 * specified ethernet port
448 * Event device pointer
451 * Ethernet device pointer
454 * A pointer to memory filled with Rx event adapter capabilities.
457 * - 0: Success, driver provides Rx event adapter capabilities for the
459 * - <0: Error code returned by the driver function.
462 typedef int (*eventdev_eth_rx_adapter_caps_get_t)
463 (const struct rte_eventdev *dev,
464 const struct rte_eth_dev *eth_dev,
467 struct rte_event_eth_rx_adapter_queue_conf *queue_conf;
470 * Add ethernet Rx queues to event device. This callback is invoked if
471 * the caps returned from rte_eventdev_eth_rx_adapter_caps_get(, eth_port_id)
472 * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
475 * Event device pointer
478 * Ethernet device pointer
481 * Ethernet device receive queue index
484 * Additonal configuration structure
487 * - 0: Success, ethernet receive queue added successfully.
488 * - <0: Error code returned by the driver function.
491 typedef int (*eventdev_eth_rx_adapter_queue_add_t)(
492 const struct rte_eventdev *dev,
493 const struct rte_eth_dev *eth_dev,
495 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
498 * Delete ethernet Rx queues from event device. This callback is invoked if
499 * the caps returned from eventdev_eth_rx_adapter_caps_get(, eth_port_id)
500 * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
503 * Event device pointer
506 * Ethernet device pointer
509 * Ethernet device receive queue index
512 * - 0: Success, ethernet receive queue deleted successfully.
513 * - <0: Error code returned by the driver function.
516 typedef int (*eventdev_eth_rx_adapter_queue_del_t)
517 (const struct rte_eventdev *dev,
518 const struct rte_eth_dev *eth_dev,
519 int32_t rx_queue_id);
522 * Start ethernet Rx adapter. This callback is invoked if
523 * the caps returned from eventdev_eth_rx_adapter_caps_get(.., eth_port_id)
524 * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
525 * from eth_port_id have been added to the event device.
528 * Event device pointer
531 * Ethernet device pointer
534 * - 0: Success, ethernet Rx adapter started successfully.
535 * - <0: Error code returned by the driver function.
537 typedef int (*eventdev_eth_rx_adapter_start_t)
538 (const struct rte_eventdev *dev,
539 const struct rte_eth_dev *eth_dev);
542 * Stop ethernet Rx adapter. This callback is invoked if
543 * the caps returned from eventdev_eth_rx_adapter_caps_get(..,eth_port_id)
544 * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
545 * from eth_port_id have been added to the event device.
548 * Event device pointer
551 * Ethernet device pointer
554 * - 0: Success, ethernet Rx adapter stopped successfully.
555 * - <0: Error code returned by the driver function.
557 typedef int (*eventdev_eth_rx_adapter_stop_t)
558 (const struct rte_eventdev *dev,
559 const struct rte_eth_dev *eth_dev);
561 struct rte_event_eth_rx_adapter_stats *stats;
564 * Retrieve ethernet Rx adapter statistics.
567 * Event device pointer
570 * Ethernet device pointer
573 * Pointer to stats structure
576 * Return 0 on success.
579 typedef int (*eventdev_eth_rx_adapter_stats_get)
580 (const struct rte_eventdev *dev,
581 const struct rte_eth_dev *eth_dev,
582 struct rte_event_eth_rx_adapter_stats *stats);
584 * Reset ethernet Rx adapter statistics.
587 * Event device pointer
590 * Ethernet device pointer
593 * Return 0 on success.
595 typedef int (*eventdev_eth_rx_adapter_stats_reset)
596 (const struct rte_eventdev *dev,
597 const struct rte_eth_dev *eth_dev);
599 /** Event device operations function pointer table */
600 struct rte_eventdev_ops {
601 eventdev_info_get_t dev_infos_get; /**< Get device info. */
602 eventdev_configure_t dev_configure; /**< Configure device. */
603 eventdev_start_t dev_start; /**< Start device. */
604 eventdev_stop_t dev_stop; /**< Stop device. */
605 eventdev_close_t dev_close; /**< Close device. */
607 eventdev_queue_default_conf_get_t queue_def_conf;
608 /**< Get default queue configuration. */
609 eventdev_queue_setup_t queue_setup;
610 /**< Set up an event queue. */
611 eventdev_queue_release_t queue_release;
612 /**< Release an event queue. */
614 eventdev_port_default_conf_get_t port_def_conf;
615 /**< Get default port configuration. */
616 eventdev_port_setup_t port_setup;
617 /**< Set up an event port. */
618 eventdev_port_release_t port_release;
619 /**< Release an event port. */
621 eventdev_port_link_t port_link;
622 /**< Link event queues to an event port. */
623 eventdev_port_unlink_t port_unlink;
624 /**< Unlink event queues from an event port. */
625 eventdev_dequeue_timeout_ticks_t timeout_ticks;
626 /**< Converts ns to *timeout_ticks* value for rte_event_dequeue() */
627 eventdev_dump_t dump;
628 /* Dump internal information */
630 eventdev_xstats_get_t xstats_get;
631 /**< Get extended device statistics. */
632 eventdev_xstats_get_names_t xstats_get_names;
633 /**< Get names of extended stats. */
634 eventdev_xstats_get_by_name xstats_get_by_name;
635 /**< Get one value by name. */
636 eventdev_xstats_reset_t xstats_reset;
637 /**< Reset the statistics values in xstats. */
639 eventdev_eth_rx_adapter_caps_get_t eth_rx_adapter_caps_get;
640 /**< Get ethernet Rx adapter capabilities */
641 eventdev_eth_rx_adapter_queue_add_t eth_rx_adapter_queue_add;
642 /**< Add Rx queues to ethernet Rx adapter */
643 eventdev_eth_rx_adapter_queue_del_t eth_rx_adapter_queue_del;
644 /**< Delete Rx queues from ethernet Rx adapter */
645 eventdev_eth_rx_adapter_start_t eth_rx_adapter_start;
646 /**< Start ethernet Rx adapter */
647 eventdev_eth_rx_adapter_stop_t eth_rx_adapter_stop;
648 /**< Stop ethernet Rx adapter */
649 eventdev_eth_rx_adapter_stats_get eth_rx_adapter_stats_get;
650 /**< Get ethernet Rx stats */
651 eventdev_eth_rx_adapter_stats_reset eth_rx_adapter_stats_reset;
652 /**< Reset ethernet Rx stats */
656 * Allocates a new eventdev slot for an event device and returns the pointer
657 * to that slot for the driver to use.
660 * Unique identifier name for each device
662 * Socket to allocate resources on.
664 * - Slot in the rte_dev_devices array for a new device;
666 struct rte_eventdev *
667 rte_event_pmd_allocate(const char *name, int socket_id);
670 * Release the specified eventdev device.
673 * The *eventdev* pointer is the address of the *rte_eventdev* structure.
675 * - 0 on success, negative on error
678 rte_event_pmd_release(struct rte_eventdev *eventdev);
684 #endif /* _RTE_EVENTDEV_PMD_H_ */