xref: /dpdk/lib/eventdev/rte_eventdev.h (revision 0899a87ce7c71576d445cd956036f6f7e555f01c)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016 Cavium, Inc.
3  * Copyright(c) 2016-2018 Intel Corporation.
4  * Copyright 2016 NXP
5  * All rights reserved.
6  */
7 
8 #ifndef _RTE_EVENTDEV_H_
9 #define _RTE_EVENTDEV_H_
10 
11 /**
12  * @file
13  *
14  * RTE Event Device API
15  *
16  * In a polling model, lcores poll ethdev ports and associated rx queues
17  * directly to look for packet. In an event driven model, by contrast, lcores
18  * call the scheduler that selects packets for them based on programmer
19  * specified criteria. Eventdev library adds support for event driven
20  * programming model, which offer applications automatic multicore scaling,
21  * dynamic load balancing, pipelining, packet ingress order maintenance and
22  * synchronization services to simplify application packet processing.
23  *
24  * The Event Device API is composed of two parts:
25  *
26  * - The application-oriented Event API that includes functions to setup
27  *   an event device (configure it, setup its queues, ports and start it), to
28  *   establish the link between queues to port and to receive events, and so on.
29  *
30  * - The driver-oriented Event API that exports a function allowing
31  *   an event poll Mode Driver (PMD) to simultaneously register itself as
32  *   an event device driver.
33  *
34  * Event device components:
35  *
36  *                     +-----------------+
37  *                     | +-------------+ |
38  *        +-------+    | |    flow 0   | |
39  *        |Packet |    | +-------------+ |
40  *        |event  |    | +-------------+ |
41  *        |       |    | |    flow 1   | |port_link(port0, queue0)
42  *        +-------+    | +-------------+ |     |     +--------+
43  *        +-------+    | +-------------+ o-----v-----o        |dequeue +------+
44  *        |Crypto |    | |    flow n   | |           | event  +------->|Core 0|
45  *        |work   |    | +-------------+ o----+      | port 0 |        |      |
46  *        |done ev|    |  event queue 0  |    |      +--------+        +------+
47  *        +-------+    +-----------------+    |
48  *        +-------+                           |
49  *        |Timer  |    +-----------------+    |      +--------+
50  *        |expiry |    | +-------------+ |    +------o        |dequeue +------+
51  *        |event  |    | |    flow 0   | o-----------o event  +------->|Core 1|
52  *        +-------+    | +-------------+ |      +----o port 1 |        |      |
53  *       Event enqueue | +-------------+ |      |    +--------+        +------+
54  *     o-------------> | |    flow 1   | |      |
55  *        enqueue(     | +-------------+ |      |
56  *        queue_id,    |                 |      |    +--------+        +------+
57  *        flow_id,     | +-------------+ |      |    |        |dequeue |Core 2|
58  *        sched_type,  | |    flow n   | o-----------o event  +------->|      |
59  *        event_type,  | +-------------+ |      |    | port 2 |        +------+
60  *        subev_type,  |  event queue 1  |      |    +--------+
61  *        event)       +-----------------+      |    +--------+
62  *                                              |    |        |dequeue +------+
63  *        +-------+    +-----------------+      |    | event  +------->|Core n|
64  *        |Core   |    | +-------------+ o-----------o port n |        |      |
65  *        |(SW)   |    | |    flow 0   | |      |    +--------+        +--+---+
66  *        |event  |    | +-------------+ |      |                         |
67  *        +-------+    | +-------------+ |      |                         |
68  *            ^        | |    flow 1   | |      |                         |
69  *            |        | +-------------+ o------+                         |
70  *            |        | +-------------+ |                                |
71  *            |        | |    flow n   | |                                |
72  *            |        | +-------------+ |                                |
73  *            |        |  event queue n  |                                |
74  *            |        +-----------------+                                |
75  *            |                                                           |
76  *            +-----------------------------------------------------------+
77  *
78  * Event device: A hardware or software-based event scheduler.
79  *
80  * Event: A unit of scheduling that encapsulates a packet or other datatype
81  * like SW generated event from the CPU, Crypto work completion notification,
82  * Timer expiry event notification etc as well as metadata.
83  * The metadata includes flow ID, scheduling type, event priority, event_type,
84  * sub_event_type etc.
85  *
86  * Event queue: A queue containing events that are scheduled by the event dev.
87  * An event queue contains events of different flows associated with scheduling
88  * types, such as atomic, ordered, or parallel.
89  *
90  * Event port: An application's interface into the event dev for enqueue and
91  * dequeue operations. Each event port can be linked with one or more
92  * event queues for dequeue operations.
93  *
94  * By default, all the functions of the Event Device API exported by a PMD
95  * are lock-free functions which assume to not be invoked in parallel on
96  * different logical cores to work on the same target object. For instance,
97  * the dequeue function of a PMD cannot be invoked in parallel on two logical
98  * cores to operates on same  event port. Of course, this function
99  * can be invoked in parallel by different logical cores on different ports.
100  * It is the responsibility of the upper level application to enforce this rule.
101  *
102  * In all functions of the Event API, the Event device is
103  * designated by an integer >= 0 named the device identifier *dev_id*
104  *
105  * At the Event driver level, Event devices are represented by a generic
106  * data structure of type *rte_event_dev*.
107  *
108  * Event devices are dynamically registered during the PCI/SoC device probing
109  * phase performed at EAL initialization time.
110  * When an Event device is being probed, a *rte_event_dev* structure and
111  * a new device identifier are allocated for that device. Then, the
112  * event_dev_init() function supplied by the Event driver matching the probed
113  * device is invoked to properly initialize the device.
114  *
115  * The role of the device init function consists of resetting the hardware or
116  * software event driver implementations.
117  *
118  * If the device init operation is successful, the correspondence between
119  * the device identifier assigned to the new device and its associated
120  * *rte_event_dev* structure is effectively registered.
121  * Otherwise, both the *rte_event_dev* structure and the device identifier are
122  * freed.
123  *
124  * The functions exported by the application Event API to setup a device
125  * designated by its device identifier must be invoked in the following order:
126  *     - rte_event_dev_configure()
127  *     - rte_event_queue_setup()
128  *     - rte_event_port_setup()
129  *     - rte_event_port_link()
130  *     - rte_event_dev_start()
131  *
132  * Then, the application can invoke, in any order, the functions
133  * exported by the Event API to schedule events, dequeue events, enqueue events,
134  * change event queue(s) to event port [un]link establishment and so on.
135  *
136  * Application may use rte_event_[queue/port]_default_conf_get() to get the
137  * default configuration to set up an event queue or event port by
138  * overriding few default values.
139  *
140  * If the application wants to change the configuration (i.e. call
141  * rte_event_dev_configure(), rte_event_queue_setup(), or
142  * rte_event_port_setup()), it must call rte_event_dev_stop() first to stop the
143  * device and then do the reconfiguration before calling rte_event_dev_start()
144  * again. The schedule, enqueue and dequeue functions should not be invoked
145  * when the device is stopped.
146  *
147  * Finally, an application can close an Event device by invoking the
148  * rte_event_dev_close() function.
149  *
150  * Each function of the application Event API invokes a specific function
151  * of the PMD that controls the target device designated by its device
152  * identifier.
153  *
154  * For this purpose, all device-specific functions of an Event driver are
155  * supplied through a set of pointers contained in a generic structure of type
156  * *event_dev_ops*.
157  * The address of the *event_dev_ops* structure is stored in the *rte_event_dev*
158  * structure by the device init function of the Event driver, which is
159  * invoked during the PCI/SoC device probing phase, as explained earlier.
160  *
161  * In other words, each function of the Event API simply retrieves the
162  * *rte_event_dev* structure associated with the device identifier and
163  * performs an indirect invocation of the corresponding driver function
164  * supplied in the *event_dev_ops* structure of the *rte_event_dev* structure.
165  *
166  * For performance reasons, the address of the fast-path functions of the
167  * Event driver is not contained in the *event_dev_ops* structure.
168  * Instead, they are directly stored at the beginning of the *rte_event_dev*
169  * structure to avoid an extra indirect memory access during their invocation.
170  *
171  * RTE event device drivers do not use interrupts for enqueue or dequeue
172  * operation. Instead, Event drivers export Poll-Mode enqueue and dequeue
173  * functions to applications.
174  *
175  * The events are injected to event device through *enqueue* operation by
176  * event producers in the system. The typical event producers are ethdev
177  * subsystem for generating packet events, CPU(SW) for generating events based
178  * on different stages of application processing, cryptodev for generating
179  * crypto work completion notification etc
180  *
181  * The *dequeue* operation gets one or more events from the event ports.
182  * The application process the events and send to downstream event queue through
183  * rte_event_enqueue_burst() if it is an intermediate stage of event processing,
184  * on the final stage, the application may use Tx adapter API for maintaining
185  * the ingress order and then send the packet/event on the wire.
186  *
187  * The point at which events are scheduled to ports depends on the device.
188  * For hardware devices, scheduling occurs asynchronously without any software
189  * intervention. Software schedulers can either be distributed
190  * (each worker thread schedules events to its own port) or centralized
191  * (a dedicated thread schedules to all ports). Distributed software schedulers
192  * perform the scheduling in rte_event_dequeue_burst(), whereas centralized
193  * scheduler logic need a dedicated service core for scheduling.
194  * The RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED capability flag is not set
195  * indicates the device is centralized and thus needs a dedicated scheduling
196  * thread that repeatedly calls software specific scheduling function.
197  *
198  * An event driven worker thread has following typical workflow on fastpath:
199  * \code{.c}
200  *	while (1) {
201  *		rte_event_dequeue_burst(...);
202  *		(event processing)
203  *		rte_event_enqueue_burst(...);
204  *	}
205  * \endcode
206  *
207  */
208 
209 #ifdef __cplusplus
210 extern "C" {
211 #endif
212 
213 #include <rte_common.h>
214 #include <rte_errno.h>
215 #include <rte_mbuf_pool_ops.h>
216 #include <rte_mempool.h>
217 
218 #include "rte_eventdev_trace_fp.h"
219 
220 struct rte_mbuf; /* we just use mbuf pointers; no need to include rte_mbuf.h */
221 struct rte_event;
222 
223 /* Event device capability bitmap flags */
224 #define RTE_EVENT_DEV_CAP_QUEUE_QOS           (1ULL << 0)
225 /**< Event scheduling prioritization is based on the priority and weight
226  * associated with each event queue. Events from a queue with highest priority
227  * is scheduled first. If the queues are of same priority, weight of the queues
228  * are considered to select a queue in a weighted round robin fashion.
229  * Subsequent dequeue calls from an event port could see events from the same
230  * event queue, if the queue is configured with an affinity count. Affinity
231  * count is the number of subsequent dequeue calls, in which an event port
232  * should use the same event queue if the queue is non-empty
233  *
234  *  @see rte_event_queue_setup(), rte_event_queue_attr_set()
235  */
236 #define RTE_EVENT_DEV_CAP_EVENT_QOS           (1ULL << 1)
237 /**< Event scheduling prioritization is based on the priority associated with
238  *  each event. Priority of each event is supplied in *rte_event* structure
239  *  on each enqueue operation.
240  *
241  *  @see rte_event_enqueue_burst()
242  */
243 #define RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED   (1ULL << 2)
244 /**< Event device operates in distributed scheduling mode.
245  * In distributed scheduling mode, event scheduling happens in HW or
246  * rte_event_dequeue_burst() or the combination of these two.
247  * If the flag is not set then eventdev is centralized and thus needs a
248  * dedicated service core that acts as a scheduling thread .
249  *
250  * @see rte_event_dequeue_burst()
251  */
252 #define RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES     (1ULL << 3)
253 /**< Event device is capable of enqueuing events of any type to any queue.
254  * If this capability is not set, the queue only supports events of the
255  *  *RTE_SCHED_TYPE_* type that it was created with.
256  *
257  * @see RTE_SCHED_TYPE_* values
258  */
259 #define RTE_EVENT_DEV_CAP_BURST_MODE          (1ULL << 4)
260 /**< Event device is capable of operating in burst mode for enqueue(forward,
261  * release) and dequeue operation. If this capability is not set, application
262  * still uses the rte_event_dequeue_burst() and rte_event_enqueue_burst() but
263  * PMD accepts only one event at a time.
264  *
265  * @see rte_event_dequeue_burst() rte_event_enqueue_burst()
266  */
267 #define RTE_EVENT_DEV_CAP_IMPLICIT_RELEASE_DISABLE    (1ULL << 5)
268 /**< Event device ports support disabling the implicit release feature, in
269  * which the port will release all unreleased events in its dequeue operation.
270  * If this capability is set and the port is configured with implicit release
271  * disabled, the application is responsible for explicitly releasing events
272  * using either the RTE_EVENT_OP_FORWARD or the RTE_EVENT_OP_RELEASE event
273  * enqueue operations.
274  *
275  * @see rte_event_dequeue_burst() rte_event_enqueue_burst()
276  */
277 
278 #define RTE_EVENT_DEV_CAP_NONSEQ_MODE         (1ULL << 6)
279 /**< Event device is capable of operating in none sequential mode. The path
280  * of the event is not necessary to be sequential. Application can change
281  * the path of event at runtime. If the flag is not set, then event each event
282  * will follow a path from queue 0 to queue 1 to queue 2 etc. If the flag is
283  * set, events may be sent to queues in any order. If the flag is not set, the
284  * eventdev will return an error when the application enqueues an event for a
285  * qid which is not the next in the sequence.
286  */
287 
288 #define RTE_EVENT_DEV_CAP_RUNTIME_PORT_LINK   (1ULL << 7)
289 /**< Event device is capable of configuring the queue/port link at runtime.
290  * If the flag is not set, the eventdev queue/port link is only can be
291  * configured during  initialization.
292  */
293 
294 #define RTE_EVENT_DEV_CAP_MULTIPLE_QUEUE_PORT (1ULL << 8)
295 /**< Event device is capable of setting up the link between multiple queue
296  * with single port. If the flag is not set, the eventdev can only map a
297  * single queue to each port or map a single queue to many port.
298  */
299 
300 #define RTE_EVENT_DEV_CAP_CARRY_FLOW_ID (1ULL << 9)
301 /**< Event device preserves the flow ID from the enqueued
302  * event to the dequeued event if the flag is set. Otherwise,
303  * the content of this field is implementation dependent.
304  */
305 
306 #define RTE_EVENT_DEV_CAP_MAINTENANCE_FREE (1ULL << 10)
307 /**< Event device *does not* require calls to rte_event_maintain().
308  * An event device that does not set this flag requires calls to
309  * rte_event_maintain() during periods when neither
310  * rte_event_dequeue_burst() nor rte_event_enqueue_burst() are called
311  * on a port. This will allow the event device to perform internal
312  * processing, such as flushing buffered events, return credits to a
313  * global pool, or process signaling related to load balancing.
314  */
315 
316 #define RTE_EVENT_DEV_CAP_RUNTIME_QUEUE_ATTR (1ULL << 11)
317 /**< Event device is capable of changing the queue attributes at runtime i.e
318  * after rte_event_queue_setup() or rte_event_start() call sequence. If this
319  * flag is not set, eventdev queue attributes can only be configured during
320  * rte_event_queue_setup().
321  */
322 
323 /* Event device priority levels */
324 #define RTE_EVENT_DEV_PRIORITY_HIGHEST   0
325 /**< Highest priority expressed across eventdev subsystem
326  * @see rte_event_queue_setup(), rte_event_enqueue_burst()
327  * @see rte_event_port_link()
328  */
329 #define RTE_EVENT_DEV_PRIORITY_NORMAL    128
330 /**< Normal priority expressed across eventdev subsystem
331  * @see rte_event_queue_setup(), rte_event_enqueue_burst()
332  * @see rte_event_port_link()
333  */
334 #define RTE_EVENT_DEV_PRIORITY_LOWEST    255
335 /**< Lowest priority expressed across eventdev subsystem
336  * @see rte_event_queue_setup(), rte_event_enqueue_burst()
337  * @see rte_event_port_link()
338  */
339 
340 /* Event queue scheduling weights */
341 #define RTE_EVENT_QUEUE_WEIGHT_HIGHEST 255
342 /**< Highest weight of an event queue
343  * @see rte_event_queue_attr_get(), rte_event_queue_attr_set()
344  */
345 #define RTE_EVENT_QUEUE_WEIGHT_LOWEST 0
346 /**< Lowest weight of an event queue
347  * @see rte_event_queue_attr_get(), rte_event_queue_attr_set()
348  */
349 
350 /* Event queue scheduling affinity */
351 #define RTE_EVENT_QUEUE_AFFINITY_HIGHEST 255
352 /**< Highest scheduling affinity of an event queue
353  * @see rte_event_queue_attr_get(), rte_event_queue_attr_set()
354  */
355 #define RTE_EVENT_QUEUE_AFFINITY_LOWEST 0
356 /**< Lowest scheduling affinity of an event queue
357  * @see rte_event_queue_attr_get(), rte_event_queue_attr_set()
358  */
359 
360 /**
361  * Get the total number of event devices that have been successfully
362  * initialised.
363  *
364  * @return
365  *   The total number of usable event devices.
366  */
367 uint8_t
368 rte_event_dev_count(void);
369 
370 /**
371  * Get the device identifier for the named event device.
372  *
373  * @param name
374  *   Event device name to select the event device identifier.
375  *
376  * @return
377  *   Returns event device identifier on success.
378  *   - <0: Failure to find named event device.
379  */
380 int
381 rte_event_dev_get_dev_id(const char *name);
382 
383 /**
384  * Return the NUMA socket to which a device is connected.
385  *
386  * @param dev_id
387  *   The identifier of the device.
388  * @return
389  *   The NUMA socket id to which the device is connected or
390  *   a default of zero if the socket could not be determined.
391  *   -(-EINVAL)  dev_id value is out of range.
392  */
393 int
394 rte_event_dev_socket_id(uint8_t dev_id);
395 
396 /**
397  * Event device information
398  */
399 struct rte_event_dev_info {
400 	const char *driver_name;	/**< Event driver name */
401 	struct rte_device *dev;	/**< Device information */
402 	uint32_t min_dequeue_timeout_ns;
403 	/**< Minimum supported global dequeue timeout(ns) by this device */
404 	uint32_t max_dequeue_timeout_ns;
405 	/**< Maximum supported global dequeue timeout(ns) by this device */
406 	uint32_t dequeue_timeout_ns;
407 	/**< Configured global dequeue timeout(ns) for this device */
408 	uint8_t max_event_queues;
409 	/**< Maximum event_queues supported by this device */
410 	uint32_t max_event_queue_flows;
411 	/**< Maximum supported flows in an event queue by this device*/
412 	uint8_t max_event_queue_priority_levels;
413 	/**< Maximum number of event queue priority levels by this device.
414 	 * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
415 	 */
416 	uint8_t max_event_priority_levels;
417 	/**< Maximum number of event priority levels by this device.
418 	 * Valid when the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability
419 	 */
420 	uint8_t max_event_ports;
421 	/**< Maximum number of event ports supported by this device */
422 	uint8_t max_event_port_dequeue_depth;
423 	/**< Maximum number of events can be dequeued at a time from an
424 	 * event port by this device.
425 	 * A device that does not support bulk dequeue will set this as 1.
426 	 */
427 	uint32_t max_event_port_enqueue_depth;
428 	/**< Maximum number of events can be enqueued at a time from an
429 	 * event port by this device.
430 	 * A device that does not support bulk enqueue will set this as 1.
431 	 */
432 	uint8_t max_event_port_links;
433 	/**< Maximum number of queues that can be linked to a single event
434 	 * port by this device.
435 	 */
436 	int32_t max_num_events;
437 	/**< A *closed system* event dev has a limit on the number of events it
438 	 * can manage at a time. An *open system* event dev does not have a
439 	 * limit and will specify this as -1.
440 	 */
441 	uint32_t event_dev_cap;
442 	/**< Event device capabilities(RTE_EVENT_DEV_CAP_)*/
443 	uint8_t max_single_link_event_port_queue_pairs;
444 	/**< Maximum number of event ports and queues that are optimized for
445 	 * (and only capable of) single-link configurations supported by this
446 	 * device. These ports and queues are not accounted for in
447 	 * max_event_ports or max_event_queues.
448 	 */
449 };
450 
451 /**
452  * Retrieve the contextual information of an event device.
453  *
454  * @param dev_id
455  *   The identifier of the device.
456  *
457  * @param[out] dev_info
458  *   A pointer to a structure of type *rte_event_dev_info* to be filled with the
459  *   contextual information of the device.
460  *
461  * @return
462  *   - 0: Success, driver updates the contextual information of the event device
463  *   - <0: Error code returned by the driver info get function.
464  *
465  */
466 int
467 rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info);
468 
469 /**
470  * The count of ports.
471  */
472 #define RTE_EVENT_DEV_ATTR_PORT_COUNT 0
473 /**
474  * The count of queues.
475  */
476 #define RTE_EVENT_DEV_ATTR_QUEUE_COUNT 1
477 /**
478  * The status of the device, zero for stopped, non-zero for started.
479  */
480 #define RTE_EVENT_DEV_ATTR_STARTED 2
481 
482 /**
483  * Get an attribute from a device.
484  *
485  * @param dev_id Eventdev id
486  * @param attr_id The attribute ID to retrieve
487  * @param[out] attr_value A pointer that will be filled in with the attribute
488  *             value if successful.
489  *
490  * @return
491  *   - 0: Successfully retrieved attribute value
492  *   - -EINVAL: Invalid device or  *attr_id* provided, or *attr_value* is NULL
493  */
494 int
495 rte_event_dev_attr_get(uint8_t dev_id, uint32_t attr_id,
496 		       uint32_t *attr_value);
497 
498 
499 /* Event device configuration bitmap flags */
500 #define RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT (1ULL << 0)
501 /**< Override the global *dequeue_timeout_ns* and use per dequeue timeout in ns.
502  *  @see rte_event_dequeue_timeout_ticks(), rte_event_dequeue_burst()
503  */
504 
505 /** Event device configuration structure */
506 struct rte_event_dev_config {
507 	uint32_t dequeue_timeout_ns;
508 	/**< rte_event_dequeue_burst() timeout on this device.
509 	 * This value should be in the range of *min_dequeue_timeout_ns* and
510 	 * *max_dequeue_timeout_ns* which previously provided in
511 	 * rte_event_dev_info_get()
512 	 * The value 0 is allowed, in which case, default dequeue timeout used.
513 	 * @see RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
514 	 */
515 	int32_t nb_events_limit;
516 	/**< In a *closed system* this field is the limit on maximum number of
517 	 * events that can be inflight in the eventdev at a given time. The
518 	 * limit is required to ensure that the finite space in a closed system
519 	 * is not overwhelmed. The value cannot exceed the *max_num_events*
520 	 * as provided by rte_event_dev_info_get().
521 	 * This value should be set to -1 for *open system*.
522 	 */
523 	uint8_t nb_event_queues;
524 	/**< Number of event queues to configure on this device.
525 	 * This value cannot exceed the *max_event_queues* which previously
526 	 * provided in rte_event_dev_info_get()
527 	 */
528 	uint8_t nb_event_ports;
529 	/**< Number of event ports to configure on this device.
530 	 * This value cannot exceed the *max_event_ports* which previously
531 	 * provided in rte_event_dev_info_get()
532 	 */
533 	uint32_t nb_event_queue_flows;
534 	/**< Number of flows for any event queue on this device.
535 	 * This value cannot exceed the *max_event_queue_flows* which previously
536 	 * provided in rte_event_dev_info_get()
537 	 */
538 	uint32_t nb_event_port_dequeue_depth;
539 	/**< Maximum number of events can be dequeued at a time from an
540 	 * event port by this device.
541 	 * This value cannot exceed the *max_event_port_dequeue_depth*
542 	 * which previously provided in rte_event_dev_info_get().
543 	 * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
544 	 * @see rte_event_port_setup()
545 	 */
546 	uint32_t nb_event_port_enqueue_depth;
547 	/**< Maximum number of events can be enqueued at a time from an
548 	 * event port by this device.
549 	 * This value cannot exceed the *max_event_port_enqueue_depth*
550 	 * which previously provided in rte_event_dev_info_get().
551 	 * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
552 	 * @see rte_event_port_setup()
553 	 */
554 	uint32_t event_dev_cfg;
555 	/**< Event device config flags(RTE_EVENT_DEV_CFG_)*/
556 	uint8_t nb_single_link_event_port_queues;
557 	/**< Number of event ports and queues that will be singly-linked to
558 	 * each other. These are a subset of the overall event ports and
559 	 * queues; this value cannot exceed *nb_event_ports* or
560 	 * *nb_event_queues*. If the device has ports and queues that are
561 	 * optimized for single-link usage, this field is a hint for how many
562 	 * to allocate; otherwise, regular event ports and queues can be used.
563 	 */
564 };
565 
566 /**
567  * Configure an event device.
568  *
569  * This function must be invoked first before any other function in the
570  * API. This function can also be re-invoked when a device is in the
571  * stopped state.
572  *
573  * The caller may use rte_event_dev_info_get() to get the capability of each
574  * resources available for this event device.
575  *
576  * @param dev_id
577  *   The identifier of the device to configure.
578  * @param dev_conf
579  *   The event device configuration structure.
580  *
581  * @return
582  *   - 0: Success, device configured.
583  *   - <0: Error code returned by the driver configuration function.
584  */
585 int
586 rte_event_dev_configure(uint8_t dev_id,
587 			const struct rte_event_dev_config *dev_conf);
588 
589 /* Event queue specific APIs */
590 
591 /* Event queue configuration bitmap flags */
592 #define RTE_EVENT_QUEUE_CFG_ALL_TYPES          (1ULL << 0)
593 /**< Allow ATOMIC,ORDERED,PARALLEL schedule type enqueue
594  *
595  * @see RTE_SCHED_TYPE_ORDERED, RTE_SCHED_TYPE_ATOMIC, RTE_SCHED_TYPE_PARALLEL
596  * @see rte_event_enqueue_burst()
597  */
598 #define RTE_EVENT_QUEUE_CFG_SINGLE_LINK        (1ULL << 1)
599 /**< This event queue links only to a single event port.
600  *
601  *  @see rte_event_port_setup(), rte_event_port_link()
602  */
603 
604 /** Event queue configuration structure */
605 struct rte_event_queue_conf {
606 	uint32_t nb_atomic_flows;
607 	/**< The maximum number of active flows this queue can track at any
608 	 * given time. If the queue is configured for atomic scheduling (by
609 	 * applying the RTE_EVENT_QUEUE_CFG_ALL_TYPES flag to event_queue_cfg
610 	 * or RTE_SCHED_TYPE_ATOMIC flag to schedule_type), then the
611 	 * value must be in the range of [1, nb_event_queue_flows], which was
612 	 * previously provided in rte_event_dev_configure().
613 	 */
614 	uint32_t nb_atomic_order_sequences;
615 	/**< The maximum number of outstanding events waiting to be
616 	 * reordered by this queue. In other words, the number of entries in
617 	 * this queue’s reorder buffer.When the number of events in the
618 	 * reorder buffer reaches to *nb_atomic_order_sequences* then the
619 	 * scheduler cannot schedule the events from this queue and invalid
620 	 * event will be returned from dequeue until one or more entries are
621 	 * freed up/released.
622 	 * If the queue is configured for ordered scheduling (by applying the
623 	 * RTE_EVENT_QUEUE_CFG_ALL_TYPES flag to event_queue_cfg or
624 	 * RTE_SCHED_TYPE_ORDERED flag to schedule_type), then the value must
625 	 * be in the range of [1, nb_event_queue_flows], which was
626 	 * previously supplied to rte_event_dev_configure().
627 	 */
628 	uint32_t event_queue_cfg;
629 	/**< Queue cfg flags(EVENT_QUEUE_CFG_) */
630 	uint8_t schedule_type;
631 	/**< Queue schedule type(RTE_SCHED_TYPE_*).
632 	 * Valid when RTE_EVENT_QUEUE_CFG_ALL_TYPES bit is not set in
633 	 * event_queue_cfg.
634 	 */
635 	uint8_t priority;
636 	/**< Priority for this event queue relative to other event queues.
637 	 * The requested priority should in the range of
638 	 * [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
639 	 * The implementation shall normalize the requested priority to
640 	 * event device supported priority value.
641 	 * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
642 	 */
643 	uint8_t weight;
644 	/**< Weight of the event queue relative to other event queues.
645 	 * The requested weight should be in the range of
646 	 * [RTE_EVENT_DEV_WEIGHT_HIGHEST, RTE_EVENT_DEV_WEIGHT_LOWEST].
647 	 * The implementation shall normalize the requested weight to event
648 	 * device supported weight value.
649 	 * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability.
650 	 */
651 	uint8_t affinity;
652 	/**< Affinity of the event queue relative to other event queues.
653 	 * The requested affinity should be in the range of
654 	 * [RTE_EVENT_DEV_AFFINITY_HIGHEST, RTE_EVENT_DEV_AFFINITY_LOWEST].
655 	 * The implementation shall normalize the requested affinity to event
656 	 * device supported affinity value.
657 	 * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability.
658 	 */
659 };
660 
661 /**
662  * Retrieve the default configuration information of an event queue designated
663  * by its *queue_id* from the event driver for an event device.
664  *
665  * This function intended to be used in conjunction with rte_event_queue_setup()
666  * where caller needs to set up the queue by overriding few default values.
667  *
668  * @param dev_id
669  *   The identifier of the device.
670  * @param queue_id
671  *   The index of the event queue to get the configuration information.
672  *   The value must be in the range [0, nb_event_queues - 1]
673  *   previously supplied to rte_event_dev_configure().
674  * @param[out] queue_conf
675  *   The pointer to the default event queue configuration data.
676  * @return
677  *   - 0: Success, driver updates the default event queue configuration data.
678  *   - <0: Error code returned by the driver info get function.
679  *
680  * @see rte_event_queue_setup()
681  *
682  */
683 int
684 rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
685 				 struct rte_event_queue_conf *queue_conf);
686 
687 /**
688  * Allocate and set up an event queue for an event device.
689  *
690  * @param dev_id
691  *   The identifier of the device.
692  * @param queue_id
693  *   The index of the event queue to setup. The value must be in the range
694  *   [0, nb_event_queues - 1] previously supplied to rte_event_dev_configure().
695  * @param queue_conf
696  *   The pointer to the configuration data to be used for the event queue.
697  *   NULL value is allowed, in which case default configuration	used.
698  *
699  * @see rte_event_queue_default_conf_get()
700  *
701  * @return
702  *   - 0: Success, event queue correctly set up.
703  *   - <0: event queue configuration failed
704  */
705 int
706 rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
707 		      const struct rte_event_queue_conf *queue_conf);
708 
709 /**
710  * The priority of the queue.
711  */
712 #define RTE_EVENT_QUEUE_ATTR_PRIORITY 0
713 /**
714  * The number of atomic flows configured for the queue.
715  */
716 #define RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_FLOWS 1
717 /**
718  * The number of atomic order sequences configured for the queue.
719  */
720 #define RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_ORDER_SEQUENCES 2
721 /**
722  * The cfg flags for the queue.
723  */
724 #define RTE_EVENT_QUEUE_ATTR_EVENT_QUEUE_CFG 3
725 /**
726  * The schedule type of the queue.
727  */
728 #define RTE_EVENT_QUEUE_ATTR_SCHEDULE_TYPE 4
729 /**
730  * The weight of the queue.
731  */
732 #define RTE_EVENT_QUEUE_ATTR_WEIGHT 5
733 /**
734  * Affinity of the queue.
735  */
736 #define RTE_EVENT_QUEUE_ATTR_AFFINITY 6
737 
738 /**
739  * Get an attribute from a queue.
740  *
741  * @param dev_id
742  *   Eventdev id
743  * @param queue_id
744  *   Eventdev queue id
745  * @param attr_id
746  *   The attribute ID to retrieve
747  * @param[out] attr_value
748  *   A pointer that will be filled in with the attribute value if successful
749  *
750  * @return
751  *   - 0: Successfully returned value
752  *   - -EINVAL: invalid device, queue or attr_id provided, or attr_value was
753  *		NULL
754  *   - -EOVERFLOW: returned when attr_id is set to
755  *   RTE_EVENT_QUEUE_ATTR_SCHEDULE_TYPE and event_queue_cfg is set to
756  *   RTE_EVENT_QUEUE_CFG_ALL_TYPES
757  */
758 int
759 rte_event_queue_attr_get(uint8_t dev_id, uint8_t queue_id, uint32_t attr_id,
760 			uint32_t *attr_value);
761 
762 /**
763  * Set an event queue attribute.
764  *
765  * @param dev_id
766  *   Eventdev id
767  * @param queue_id
768  *   Eventdev queue id
769  * @param attr_id
770  *   The attribute ID to set
771  * @param attr_value
772  *   The attribute value to set
773  *
774  * @return
775  *   - 0: Successfully set attribute.
776  *   - -EINVAL: invalid device, queue or attr_id.
777  *   - -ENOTSUP: device does not support setting the event attribute.
778  *   - <0: failed to set event queue attribute
779  */
780 __rte_experimental
781 int
782 rte_event_queue_attr_set(uint8_t dev_id, uint8_t queue_id, uint32_t attr_id,
783 			 uint64_t attr_value);
784 
785 /* Event port specific APIs */
786 
787 /* Event port configuration bitmap flags */
788 #define RTE_EVENT_PORT_CFG_DISABLE_IMPL_REL    (1ULL << 0)
789 /**< Configure the port not to release outstanding events in
790  * rte_event_dev_dequeue_burst(). If set, all events received through
791  * the port must be explicitly released with RTE_EVENT_OP_RELEASE or
792  * RTE_EVENT_OP_FORWARD. Must be unset if the device is not
793  * RTE_EVENT_DEV_CAP_IMPLICIT_RELEASE_DISABLE capable.
794  */
795 #define RTE_EVENT_PORT_CFG_SINGLE_LINK         (1ULL << 1)
796 /**< This event port links only to a single event queue.
797  *
798  *  @see rte_event_port_setup(), rte_event_port_link()
799  */
800 #define RTE_EVENT_PORT_CFG_HINT_PRODUCER       (1ULL << 2)
801 /**< Hint that this event port will primarily enqueue events to the system.
802  * A PMD can optimize its internal workings by assuming that this port is
803  * primarily going to enqueue NEW events.
804  *
805  * Note that this flag is only a hint, so PMDs must operate under the
806  * assumption that any port can enqueue an event with any type of op.
807  *
808  *  @see rte_event_port_setup()
809  */
810 #define RTE_EVENT_PORT_CFG_HINT_CONSUMER       (1ULL << 3)
811 /**< Hint that this event port will primarily dequeue events from the system.
812  * A PMD can optimize its internal workings by assuming that this port is
813  * primarily going to consume events, and not enqueue FORWARD or RELEASE
814  * events.
815  *
816  * Note that this flag is only a hint, so PMDs must operate under the
817  * assumption that any port can enqueue an event with any type of op.
818  *
819  *  @see rte_event_port_setup()
820  */
821 #define RTE_EVENT_PORT_CFG_HINT_WORKER         (1ULL << 4)
822 /**< Hint that this event port will primarily pass existing events through.
823  * A PMD can optimize its internal workings by assuming that this port is
824  * primarily going to FORWARD events, and not enqueue NEW or RELEASE events
825  * often.
826  *
827  * Note that this flag is only a hint, so PMDs must operate under the
828  * assumption that any port can enqueue an event with any type of op.
829  *
830  *  @see rte_event_port_setup()
831  */
832 
833 /** Event port configuration structure */
834 struct rte_event_port_conf {
835 	int32_t new_event_threshold;
836 	/**< A backpressure threshold for new event enqueues on this port.
837 	 * Use for *closed system* event dev where event capacity is limited,
838 	 * and cannot exceed the capacity of the event dev.
839 	 * Configuring ports with different thresholds can make higher priority
840 	 * traffic less likely to  be backpressured.
841 	 * For example, a port used to inject NIC Rx packets into the event dev
842 	 * can have a lower threshold so as not to overwhelm the device,
843 	 * while ports used for worker pools can have a higher threshold.
844 	 * This value cannot exceed the *nb_events_limit*
845 	 * which was previously supplied to rte_event_dev_configure().
846 	 * This should be set to '-1' for *open system*.
847 	 */
848 	uint16_t dequeue_depth;
849 	/**< Configure number of bulk dequeues for this event port.
850 	 * This value cannot exceed the *nb_event_port_dequeue_depth*
851 	 * which previously supplied to rte_event_dev_configure().
852 	 * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
853 	 */
854 	uint16_t enqueue_depth;
855 	/**< Configure number of bulk enqueues for this event port.
856 	 * This value cannot exceed the *nb_event_port_enqueue_depth*
857 	 * which previously supplied to rte_event_dev_configure().
858 	 * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
859 	 */
860 	uint32_t event_port_cfg; /**< Port cfg flags(EVENT_PORT_CFG_) */
861 };
862 
863 /**
864  * Retrieve the default configuration information of an event port designated
865  * by its *port_id* from the event driver for an event device.
866  *
867  * This function intended to be used in conjunction with rte_event_port_setup()
868  * where caller needs to set up the port by overriding few default values.
869  *
870  * @param dev_id
871  *   The identifier of the device.
872  * @param port_id
873  *   The index of the event port to get the configuration information.
874  *   The value must be in the range [0, nb_event_ports - 1]
875  *   previously supplied to rte_event_dev_configure().
876  * @param[out] port_conf
877  *   The pointer to the default event port configuration data
878  * @return
879  *   - 0: Success, driver updates the default event port configuration data.
880  *   - <0: Error code returned by the driver info get function.
881  *
882  * @see rte_event_port_setup()
883  *
884  */
885 int
886 rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
887 				struct rte_event_port_conf *port_conf);
888 
889 /**
890  * Allocate and set up an event port for an event device.
891  *
892  * @param dev_id
893  *   The identifier of the device.
894  * @param port_id
895  *   The index of the event port to setup. The value must be in the range
896  *   [0, nb_event_ports - 1] previously supplied to rte_event_dev_configure().
897  * @param port_conf
898  *   The pointer to the configuration data to be used for the queue.
899  *   NULL value is allowed, in which case default configuration	used.
900  *
901  * @see rte_event_port_default_conf_get()
902  *
903  * @return
904  *   - 0: Success, event port correctly set up.
905  *   - <0: Port configuration failed
906  *   - (-EDQUOT) Quota exceeded(Application tried to link the queue configured
907  *   with RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
908  */
909 int
910 rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
911 		     const struct rte_event_port_conf *port_conf);
912 
913 typedef void (*rte_eventdev_port_flush_t)(uint8_t dev_id,
914 					  struct rte_event event, void *arg);
915 /**< Callback function prototype that can be passed during
916  * rte_event_port_release(), invoked once per a released event.
917  */
918 
919 /**
920  * Quiesce any core specific resources consumed by the event port.
921  *
922  * Event ports are generally coupled with lcores, and a given Hardware
923  * implementation might require the PMD to store port specific data in the
924  * lcore.
925  * When the application decides to migrate the event port to another lcore
926  * or teardown the current lcore it may to call `rte_event_port_quiesce`
927  * to make sure that all the data associated with the event port are released
928  * from the lcore, this might also include any prefetched events.
929  * While releasing the event port from the lcore, this function calls the
930  * user-provided flush callback once per event.
931  *
932  * @note Invocation of this API does not affect the existing port configuration.
933  *
934  * @param dev_id
935  *   The identifier of the device.
936  * @param port_id
937  *   The index of the event port to setup. The value must be in the range
938  *   [0, nb_event_ports - 1] previously supplied to rte_event_dev_configure().
939  * @param release_cb
940  *   Callback function invoked once per flushed event.
941  * @param args
942  *   Argument supplied to callback.
943  */
944 __rte_experimental
945 void
946 rte_event_port_quiesce(uint8_t dev_id, uint8_t port_id,
947 		       rte_eventdev_port_flush_t release_cb, void *args);
948 
949 /**
950  * The queue depth of the port on the enqueue side
951  */
952 #define RTE_EVENT_PORT_ATTR_ENQ_DEPTH 0
953 /**
954  * The queue depth of the port on the dequeue side
955  */
956 #define RTE_EVENT_PORT_ATTR_DEQ_DEPTH 1
957 /**
958  * The new event threshold of the port
959  */
960 #define RTE_EVENT_PORT_ATTR_NEW_EVENT_THRESHOLD 2
961 /**
962  * The implicit release disable attribute of the port
963  */
964 #define RTE_EVENT_PORT_ATTR_IMPLICIT_RELEASE_DISABLE 3
965 
966 /**
967  * Get an attribute from a port.
968  *
969  * @param dev_id
970  *   Eventdev id
971  * @param port_id
972  *   Eventdev port id
973  * @param attr_id
974  *   The attribute ID to retrieve
975  * @param[out] attr_value
976  *   A pointer that will be filled in with the attribute value if successful
977  *
978  * @return
979  *   - 0: Successfully returned value
980  *   - (-EINVAL) Invalid device, port or attr_id, or attr_value was NULL
981  */
982 int
983 rte_event_port_attr_get(uint8_t dev_id, uint8_t port_id, uint32_t attr_id,
984 			uint32_t *attr_value);
985 
986 /**
987  * Start an event device.
988  *
989  * The device start step is the last one and consists of setting the event
990  * queues to start accepting the events and schedules to event ports.
991  *
992  * On success, all basic functions exported by the API (event enqueue,
993  * event dequeue and so on) can be invoked.
994  *
995  * @param dev_id
996  *   Event device identifier
997  * @return
998  *   - 0: Success, device started.
999  *   - -ESTALE : Not all ports of the device are configured
1000  *   - -ENOLINK: Not all queues are linked, which could lead to deadlock.
1001  */
1002 int
1003 rte_event_dev_start(uint8_t dev_id);
1004 
1005 /**
1006  * Stop an event device.
1007  *
1008  * This function causes all queued events to be drained, including those
1009  * residing in event ports. While draining events out of the device, this
1010  * function calls the user-provided flush callback (if one was registered) once
1011  * per event.
1012  *
1013  * The device can be restarted with a call to rte_event_dev_start(). Threads
1014  * that continue to enqueue/dequeue while the device is stopped, or being
1015  * stopped, will result in undefined behavior. This includes event adapters,
1016  * which must be stopped prior to stopping the eventdev.
1017  *
1018  * @param dev_id
1019  *   Event device identifier.
1020  *
1021  * @see rte_event_dev_stop_flush_callback_register()
1022  */
1023 void
1024 rte_event_dev_stop(uint8_t dev_id);
1025 
1026 typedef void (*eventdev_stop_flush_t)(uint8_t dev_id, struct rte_event event,
1027 		void *arg);
1028 /**< Callback function called during rte_event_dev_stop(), invoked once per
1029  * flushed event.
1030  */
1031 
1032 /**
1033  * Registers a callback function to be invoked during rte_event_dev_stop() for
1034  * each flushed event. This function can be used to properly dispose of queued
1035  * events, for example events containing memory pointers.
1036  *
1037  * The callback function is only registered for the calling process. The
1038  * callback function must be registered in every process that can call
1039  * rte_event_dev_stop().
1040  *
1041  * To unregister a callback, call this function with a NULL callback pointer.
1042  *
1043  * @param dev_id
1044  *   The identifier of the device.
1045  * @param callback
1046  *   Callback function invoked once per flushed event.
1047  * @param userdata
1048  *   Argument supplied to callback.
1049  *
1050  * @return
1051  *  - 0 on success.
1052  *  - -EINVAL if *dev_id* is invalid
1053  *
1054  * @see rte_event_dev_stop()
1055  */
1056 int
1057 rte_event_dev_stop_flush_callback_register(uint8_t dev_id,
1058 		eventdev_stop_flush_t callback, void *userdata);
1059 
1060 /**
1061  * Close an event device. The device cannot be restarted!
1062  *
1063  * @param dev_id
1064  *   Event device identifier
1065  *
1066  * @return
1067  *  - 0 on successfully closing device
1068  *  - <0 on failure to close device
1069  *  - (-EAGAIN) if device is busy
1070  */
1071 int
1072 rte_event_dev_close(uint8_t dev_id);
1073 
1074 /**
1075  * Event vector structure.
1076  */
1077 struct rte_event_vector {
1078 	uint16_t nb_elem;
1079 	/**< Number of elements in this event vector. */
1080 	uint16_t rsvd : 15;
1081 	/**< Reserved for future use */
1082 	uint16_t attr_valid : 1;
1083 	/**< Indicates that the below union attributes have valid information.
1084 	 */
1085 	union {
1086 		/* Used by Rx/Tx adapter.
1087 		 * Indicates that all the elements in this vector belong to the
1088 		 * same port and queue pair when originating from Rx adapter,
1089 		 * valid only when event type is ETHDEV_VECTOR or
1090 		 * ETH_RX_ADAPTER_VECTOR.
1091 		 * Can also be used to indicate the Tx adapter the destination
1092 		 * port and queue of the mbufs in the vector
1093 		 */
1094 		struct {
1095 			uint16_t port;
1096 			/* Ethernet device port id. */
1097 			uint16_t queue;
1098 			/* Ethernet device queue id. */
1099 		};
1100 	};
1101 	/**< Union to hold common attributes of the vector array. */
1102 	uint64_t impl_opaque;
1103 
1104 /* empty structures do not have zero size in C++ leading to compilation errors
1105  * with clang about structure having different sizes in C and C++.
1106  * Since these are all zero-sized arrays, we can omit the "union" wrapper for
1107  * C++ builds, removing the warning.
1108  */
1109 #ifndef __cplusplus
1110 	/**< Implementation specific opaque value.
1111 	 * An implementation may use this field to hold implementation specific
1112 	 * value to share between dequeue and enqueue operation.
1113 	 * The application should not modify this field.
1114 	 */
1115 	union {
1116 #endif
1117 		struct rte_mbuf *mbufs[0];
1118 		void *ptrs[0];
1119 		uint64_t *u64s[0];
1120 #ifndef __cplusplus
1121 	} __rte_aligned(16);
1122 #endif
1123 	/**< Start of the vector array union. Depending upon the event type the
1124 	 * vector array can be an array of mbufs or pointers or opaque u64
1125 	 * values.
1126 	 */
1127 } __rte_aligned(16);
1128 
1129 /* Scheduler type definitions */
1130 #define RTE_SCHED_TYPE_ORDERED          0
1131 /**< Ordered scheduling
1132  *
1133  * Events from an ordered flow of an event queue can be scheduled to multiple
1134  * ports for concurrent processing while maintaining the original event order.
1135  * This scheme enables the user to achieve high single flow throughput by
1136  * avoiding SW synchronization for ordering between ports which bound to cores.
1137  *
1138  * The source flow ordering from an event queue is maintained when events are
1139  * enqueued to their destination queue within the same ordered flow context.
1140  * An event port holds the context until application call
1141  * rte_event_dequeue_burst() from the same port, which implicitly releases
1142  * the context.
1143  * User may allow the scheduler to release the context earlier than that
1144  * by invoking rte_event_enqueue_burst() with RTE_EVENT_OP_RELEASE operation.
1145  *
1146  * Events from the source queue appear in their original order when dequeued
1147  * from a destination queue.
1148  * Event ordering is based on the received event(s), but also other
1149  * (newly allocated or stored) events are ordered when enqueued within the same
1150  * ordered context. Events not enqueued (e.g. released or stored) within the
1151  * context are  considered missing from reordering and are skipped at this time
1152  * (but can be ordered again within another context).
1153  *
1154  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
1155  */
1156 
1157 #define RTE_SCHED_TYPE_ATOMIC           1
1158 /**< Atomic scheduling
1159  *
1160  * Events from an atomic flow of an event queue can be scheduled only to a
1161  * single port at a time. The port is guaranteed to have exclusive (atomic)
1162  * access to the associated flow context, which enables the user to avoid SW
1163  * synchronization. Atomic flows also help to maintain event ordering
1164  * since only one port at a time can process events from a flow of an
1165  * event queue.
1166  *
1167  * The atomic queue synchronization context is dedicated to the port until
1168  * application call rte_event_dequeue_burst() from the same port,
1169  * which implicitly releases the context. User may allow the scheduler to
1170  * release the context earlier than that by invoking rte_event_enqueue_burst()
1171  * with RTE_EVENT_OP_RELEASE operation.
1172  *
1173  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
1174  */
1175 
1176 #define RTE_SCHED_TYPE_PARALLEL         2
1177 /**< Parallel scheduling
1178  *
1179  * The scheduler performs priority scheduling, load balancing, etc. functions
1180  * but does not provide additional event synchronization or ordering.
1181  * It is free to schedule events from a single parallel flow of an event queue
1182  * to multiple events ports for concurrent processing.
1183  * The application is responsible for flow context synchronization and
1184  * event ordering (SW synchronization).
1185  *
1186  * @see rte_event_queue_setup(), rte_event_dequeue_burst()
1187  */
1188 
1189 /* Event types to classify the event source */
1190 #define RTE_EVENT_TYPE_ETHDEV           0x0
1191 /**< The event generated from ethdev subsystem */
1192 #define RTE_EVENT_TYPE_CRYPTODEV        0x1
1193 /**< The event generated from crypodev subsystem */
1194 #define RTE_EVENT_TYPE_TIMER		0x2
1195 /**< The event generated from event timer adapter */
1196 #define RTE_EVENT_TYPE_CPU              0x3
1197 /**< The event generated from cpu for pipelining.
1198  * Application may use *sub_event_type* to further classify the event
1199  */
1200 #define RTE_EVENT_TYPE_ETH_RX_ADAPTER   0x4
1201 /**< The event generated from event eth Rx adapter */
1202 #define RTE_EVENT_TYPE_VECTOR           0x8
1203 /**< Indicates that event is a vector.
1204  * All vector event types should be a logical OR of EVENT_TYPE_VECTOR.
1205  * This simplifies the pipeline design as one can split processing the events
1206  * between vector events and normal event across event types.
1207  * Example:
1208  *	if (ev.event_type & RTE_EVENT_TYPE_VECTOR) {
1209  *		// Classify and handle vector event.
1210  *	} else {
1211  *		// Classify and handle event.
1212  *	}
1213  */
1214 #define RTE_EVENT_TYPE_ETHDEV_VECTOR                                           \
1215 	(RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_ETHDEV)
1216 /**< The event vector generated from ethdev subsystem */
1217 #define RTE_EVENT_TYPE_CPU_VECTOR (RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_CPU)
1218 /**< The event vector generated from cpu for pipelining. */
1219 #define RTE_EVENT_TYPE_ETH_RX_ADAPTER_VECTOR                                   \
1220 	(RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_ETH_RX_ADAPTER)
1221 /**< The event vector generated from eth Rx adapter. */
1222 
1223 #define RTE_EVENT_TYPE_MAX              0x10
1224 /**< Maximum number of event types */
1225 
1226 /* Event enqueue operations */
1227 #define RTE_EVENT_OP_NEW                0
1228 /**< The event producers use this operation to inject a new event to the
1229  * event device.
1230  */
1231 #define RTE_EVENT_OP_FORWARD            1
1232 /**< The CPU use this operation to forward the event to different event queue or
1233  * change to new application specific flow or schedule type to enable
1234  * pipelining.
1235  *
1236  * This operation must only be enqueued to the same port that the
1237  * event to be forwarded was dequeued from.
1238  */
1239 #define RTE_EVENT_OP_RELEASE            2
1240 /**< Release the flow context associated with the schedule type.
1241  *
1242  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ATOMIC*
1243  * then this function hints the scheduler that the user has completed critical
1244  * section processing in the current atomic context.
1245  * The scheduler is now allowed to schedule events from the same flow from
1246  * an event queue to another port. However, the context may be still held
1247  * until the next rte_event_dequeue_burst() call, this call allows but does not
1248  * force the scheduler to release the context early.
1249  *
1250  * Early atomic context release may increase parallelism and thus system
1251  * performance, but the user needs to design carefully the split into critical
1252  * vs non-critical sections.
1253  *
1254  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ORDERED*
1255  * then this function hints the scheduler that the user has done all that need
1256  * to maintain event order in the current ordered context.
1257  * The scheduler is allowed to release the ordered context of this port and
1258  * avoid reordering any following enqueues.
1259  *
1260  * Early ordered context release may increase parallelism and thus system
1261  * performance.
1262  *
1263  * If current flow's scheduler type method is *RTE_SCHED_TYPE_PARALLEL*
1264  * or no scheduling context is held then this function may be an NOOP,
1265  * depending on the implementation.
1266  *
1267  * This operation must only be enqueued to the same port that the
1268  * event to be released was dequeued from.
1269  *
1270  */
1271 
1272 /**
1273  * The generic *rte_event* structure to hold the event attributes
1274  * for dequeue and enqueue operation
1275  */
1276 RTE_STD_C11
1277 struct rte_event {
1278 	/** WORD0 */
1279 	union {
1280 		uint64_t event;
1281 		/** Event attributes for dequeue or enqueue operation */
1282 		struct {
1283 			uint32_t flow_id:20;
1284 			/**< Targeted flow identifier for the enqueue and
1285 			 * dequeue operation.
1286 			 * The value must be in the range of
1287 			 * [0, nb_event_queue_flows - 1] which
1288 			 * previously supplied to rte_event_dev_configure().
1289 			 */
1290 			uint32_t sub_event_type:8;
1291 			/**< Sub-event types based on the event source.
1292 			 * @see RTE_EVENT_TYPE_CPU
1293 			 */
1294 			uint32_t event_type:4;
1295 			/**< Event type to classify the event source.
1296 			 * @see RTE_EVENT_TYPE_ETHDEV, (RTE_EVENT_TYPE_*)
1297 			 */
1298 			uint8_t op:2;
1299 			/**< The type of event enqueue operation - new/forward/
1300 			 * etc.This field is not preserved across an instance
1301 			 * and is undefined on dequeue.
1302 			 * @see RTE_EVENT_OP_NEW, (RTE_EVENT_OP_*)
1303 			 */
1304 			uint8_t rsvd:4;
1305 			/**< Reserved for future use */
1306 			uint8_t sched_type:2;
1307 			/**< Scheduler synchronization type (RTE_SCHED_TYPE_*)
1308 			 * associated with flow id on a given event queue
1309 			 * for the enqueue and dequeue operation.
1310 			 */
1311 			uint8_t queue_id;
1312 			/**< Targeted event queue identifier for the enqueue or
1313 			 * dequeue operation.
1314 			 * The value must be in the range of
1315 			 * [0, nb_event_queues - 1] which previously supplied to
1316 			 * rte_event_dev_configure().
1317 			 */
1318 			uint8_t priority;
1319 			/**< Event priority relative to other events in the
1320 			 * event queue. The requested priority should in the
1321 			 * range of  [RTE_EVENT_DEV_PRIORITY_HIGHEST,
1322 			 * RTE_EVENT_DEV_PRIORITY_LOWEST].
1323 			 * The implementation shall normalize the requested
1324 			 * priority to supported priority value.
1325 			 * Valid when the device has
1326 			 * RTE_EVENT_DEV_CAP_EVENT_QOS capability.
1327 			 */
1328 			uint8_t impl_opaque;
1329 			/**< Implementation specific opaque value.
1330 			 * An implementation may use this field to hold
1331 			 * implementation specific value to share between
1332 			 * dequeue and enqueue operation.
1333 			 * The application should not modify this field.
1334 			 */
1335 		};
1336 	};
1337 	/** WORD1 */
1338 	union {
1339 		uint64_t u64;
1340 		/**< Opaque 64-bit value */
1341 		void *event_ptr;
1342 		/**< Opaque event pointer */
1343 		struct rte_mbuf *mbuf;
1344 		/**< mbuf pointer if dequeued event is associated with mbuf */
1345 		struct rte_event_vector *vec;
1346 		/**< Event vector pointer. */
1347 	};
1348 };
1349 
1350 /* Ethdev Rx adapter capability bitmap flags */
1351 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT	0x1
1352 /**< This flag is sent when the packet transfer mechanism is in HW.
1353  * Ethdev can send packets to the event device using internal event port.
1354  */
1355 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ	0x2
1356 /**< Adapter supports multiple event queues per ethdev. Every ethdev
1357  * Rx queue can be connected to a unique event queue.
1358  */
1359 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID	0x4
1360 /**< The application can override the adapter generated flow ID in the
1361  * event. This flow ID can be specified when adding an ethdev Rx queue
1362  * to the adapter using the ev.flow_id member.
1363  * @see struct rte_event_eth_rx_adapter_queue_conf::ev
1364  * @see struct rte_event_eth_rx_adapter_queue_conf::rx_queue_flags
1365  */
1366 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_EVENT_VECTOR	0x8
1367 /**< Adapter supports event vectorization per ethdev. */
1368 
1369 /**
1370  * Retrieve the event device's ethdev Rx adapter capabilities for the
1371  * specified ethernet port
1372  *
1373  * @param dev_id
1374  *   The identifier of the device.
1375  *
1376  * @param eth_port_id
1377  *   The identifier of the ethernet device.
1378  *
1379  * @param[out] caps
1380  *   A pointer to memory filled with Rx event adapter capabilities.
1381  *
1382  * @return
1383  *   - 0: Success, driver provides Rx event adapter capabilities for the
1384  *	ethernet device.
1385  *   - <0: Error code returned by the driver function.
1386  *
1387  */
1388 int
1389 rte_event_eth_rx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
1390 				uint32_t *caps);
1391 
1392 #define RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT (1ULL << 0)
1393 /**< This flag is set when the timer mechanism is in HW. */
1394 
1395 #define RTE_EVENT_TIMER_ADAPTER_CAP_PERIODIC      (1ULL << 1)
1396 /**< This flag is set if periodic mode is supported. */
1397 
1398 /**
1399  * Retrieve the event device's timer adapter capabilities.
1400  *
1401  * @param dev_id
1402  *   The identifier of the device.
1403  *
1404  * @param[out] caps
1405  *   A pointer to memory to be filled with event timer adapter capabilities.
1406  *
1407  * @return
1408  *   - 0: Success, driver provided event timer adapter capabilities.
1409  *   - <0: Error code returned by the driver function.
1410  */
1411 int
1412 rte_event_timer_adapter_caps_get(uint8_t dev_id, uint32_t *caps);
1413 
1414 /* Crypto adapter capability bitmap flag */
1415 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW   0x1
1416 /**< Flag indicates HW is capable of generating events in
1417  * RTE_EVENT_OP_NEW enqueue operation. Cryptodev will send
1418  * packets to the event device as new events using an internal
1419  * event port.
1420  */
1421 
1422 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD   0x2
1423 /**< Flag indicates HW is capable of generating events in
1424  * RTE_EVENT_OP_FORWARD enqueue operation. Cryptodev will send
1425  * packets to the event device as forwarded event using an
1426  * internal event port.
1427  */
1428 
1429 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND  0x4
1430 /**< Flag indicates HW is capable of mapping crypto queue pair to
1431  * event queue.
1432  */
1433 
1434 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA   0x8
1435 /**< Flag indicates HW/SW supports a mechanism to store and retrieve
1436  * the private data information along with the crypto session.
1437  */
1438 
1439 /**
1440  * Retrieve the event device's crypto adapter capabilities for the
1441  * specified cryptodev device
1442  *
1443  * @param dev_id
1444  *   The identifier of the device.
1445  *
1446  * @param cdev_id
1447  *   The identifier of the cryptodev device.
1448  *
1449  * @param[out] caps
1450  *   A pointer to memory filled with event adapter capabilities.
1451  *   It is expected to be pre-allocated & initialized by caller.
1452  *
1453  * @return
1454  *   - 0: Success, driver provides event adapter capabilities for the
1455  *     cryptodev device.
1456  *   - <0: Error code returned by the driver function.
1457  *
1458  */
1459 int
1460 rte_event_crypto_adapter_caps_get(uint8_t dev_id, uint8_t cdev_id,
1461 				  uint32_t *caps);
1462 
1463 /* Ethdev Tx adapter capability bitmap flags */
1464 #define RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT	0x1
1465 /**< This flag is sent when the PMD supports a packet transmit callback
1466  */
1467 #define RTE_EVENT_ETH_TX_ADAPTER_CAP_EVENT_VECTOR	0x2
1468 /**< Indicates that the Tx adapter is capable of handling event vector of
1469  * mbufs.
1470  */
1471 
1472 /**
1473  * Retrieve the event device's eth Tx adapter capabilities
1474  *
1475  * @param dev_id
1476  *   The identifier of the device.
1477  *
1478  * @param eth_port_id
1479  *   The identifier of the ethernet device.
1480  *
1481  * @param[out] caps
1482  *   A pointer to memory filled with eth Tx adapter capabilities.
1483  *
1484  * @return
1485  *   - 0: Success, driver provides eth Tx adapter capabilities.
1486  *   - <0: Error code returned by the driver function.
1487  *
1488  */
1489 int
1490 rte_event_eth_tx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
1491 				uint32_t *caps);
1492 
1493 /**
1494  * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue_burst()
1495  *
1496  * If the device is configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT flag
1497  * then application can use this function to convert timeout value in
1498  * nanoseconds to implementations specific timeout value supplied in
1499  * rte_event_dequeue_burst()
1500  *
1501  * @param dev_id
1502  *   The identifier of the device.
1503  * @param ns
1504  *   Wait time in nanosecond
1505  * @param[out] timeout_ticks
1506  *   Value for the *timeout_ticks* parameter in rte_event_dequeue_burst()
1507  *
1508  * @return
1509  *  - 0 on success.
1510  *  - -ENOTSUP if the device doesn't support timeouts
1511  *  - -EINVAL if *dev_id* is invalid or *timeout_ticks* is NULL
1512  *  - other values < 0 on failure.
1513  *
1514  * @see rte_event_dequeue_burst(), RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1515  * @see rte_event_dev_configure()
1516  *
1517  */
1518 int
1519 rte_event_dequeue_timeout_ticks(uint8_t dev_id, uint64_t ns,
1520 					uint64_t *timeout_ticks);
1521 
1522 /**
1523  * Link multiple source event queues supplied in *queues* to the destination
1524  * event port designated by its *port_id* with associated service priority
1525  * supplied in *priorities* on the event device designated by its *dev_id*.
1526  *
1527  * The link establishment shall enable the event port *port_id* from
1528  * receiving events from the specified event queue(s) supplied in *queues*
1529  *
1530  * An event queue may link to one or more event ports.
1531  * The number of links can be established from an event queue to event port is
1532  * implementation defined.
1533  *
1534  * Event queue(s) to event port link establishment can be changed at runtime
1535  * without re-configuring the device to support scaling and to reduce the
1536  * latency of critical work by establishing the link with more event ports
1537  * at runtime.
1538  *
1539  * @param dev_id
1540  *   The identifier of the device.
1541  *
1542  * @param port_id
1543  *   Event port identifier to select the destination port to link.
1544  *
1545  * @param queues
1546  *   Points to an array of *nb_links* event queues to be linked
1547  *   to the event port.
1548  *   NULL value is allowed, in which case this function links all the configured
1549  *   event queues *nb_event_queues* which previously supplied to
1550  *   rte_event_dev_configure() to the event port *port_id*
1551  *
1552  * @param priorities
1553  *   Points to an array of *nb_links* service priorities associated with each
1554  *   event queue link to event port.
1555  *   The priority defines the event port's servicing priority for
1556  *   event queue, which may be ignored by an implementation.
1557  *   The requested priority should in the range of
1558  *   [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
1559  *   The implementation shall normalize the requested priority to
1560  *   implementation supported priority value.
1561  *   NULL value is allowed, in which case this function links the event queues
1562  *   with RTE_EVENT_DEV_PRIORITY_NORMAL servicing priority
1563  *
1564  * @param nb_links
1565  *   The number of links to establish. This parameter is ignored if queues is
1566  *   NULL.
1567  *
1568  * @return
1569  * The number of links actually established. The return value can be less than
1570  * the value of the *nb_links* parameter when the implementation has the
1571  * limitation on specific queue to port link establishment or if invalid
1572  * parameters are specified in *queues*
1573  * If the return value is less than *nb_links*, the remaining links at the end
1574  * of link[] are not established, and the caller has to take care of them.
1575  * If return value is less than *nb_links* then implementation shall update the
1576  * rte_errno accordingly, Possible rte_errno values are
1577  * (EDQUOT) Quota exceeded(Application tried to link the queue configured with
1578  *  RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
1579  * (EINVAL) Invalid parameter
1580  *
1581  */
1582 int
1583 rte_event_port_link(uint8_t dev_id, uint8_t port_id,
1584 		    const uint8_t queues[], const uint8_t priorities[],
1585 		    uint16_t nb_links);
1586 
1587 /**
1588  * Unlink multiple source event queues supplied in *queues* from the destination
1589  * event port designated by its *port_id* on the event device designated
1590  * by its *dev_id*.
1591  *
1592  * The unlink call issues an async request to disable the event port *port_id*
1593  * from receiving events from the specified event queue *queue_id*.
1594  * Event queue(s) to event port unlink establishment can be changed at runtime
1595  * without re-configuring the device.
1596  *
1597  * @see rte_event_port_unlinks_in_progress() to poll for completed unlinks.
1598  *
1599  * @param dev_id
1600  *   The identifier of the device.
1601  *
1602  * @param port_id
1603  *   Event port identifier to select the destination port to unlink.
1604  *
1605  * @param queues
1606  *   Points to an array of *nb_unlinks* event queues to be unlinked
1607  *   from the event port.
1608  *   NULL value is allowed, in which case this function unlinks all the
1609  *   event queue(s) from the event port *port_id*.
1610  *
1611  * @param nb_unlinks
1612  *   The number of unlinks to establish. This parameter is ignored if queues is
1613  *   NULL.
1614  *
1615  * @return
1616  * The number of unlinks successfully requested. The return value can be less
1617  * than the value of the *nb_unlinks* parameter when the implementation has the
1618  * limitation on specific queue to port unlink establishment or
1619  * if invalid parameters are specified.
1620  * If the return value is less than *nb_unlinks*, the remaining queues at the
1621  * end of queues[] are not unlinked, and the caller has to take care of them.
1622  * If return value is less than *nb_unlinks* then implementation shall update
1623  * the rte_errno accordingly, Possible rte_errno values are
1624  * (EINVAL) Invalid parameter
1625  */
1626 int
1627 rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
1628 		      uint8_t queues[], uint16_t nb_unlinks);
1629 
1630 /**
1631  * Returns the number of unlinks in progress.
1632  *
1633  * This function provides the application with a method to detect when an
1634  * unlink has been completed by the implementation.
1635  *
1636  * @see rte_event_port_unlink() to issue unlink requests.
1637  *
1638  * @param dev_id
1639  *   The identifier of the device.
1640  *
1641  * @param port_id
1642  *   Event port identifier to select port to check for unlinks in progress.
1643  *
1644  * @return
1645  * The number of unlinks that are in progress. A return of zero indicates that
1646  * there are no outstanding unlink requests. A positive return value indicates
1647  * the number of unlinks that are in progress, but are not yet complete.
1648  * A negative return value indicates an error, -EINVAL indicates an invalid
1649  * parameter passed for *dev_id* or *port_id*.
1650  */
1651 int
1652 rte_event_port_unlinks_in_progress(uint8_t dev_id, uint8_t port_id);
1653 
1654 /**
1655  * Retrieve the list of source event queues and its associated service priority
1656  * linked to the destination event port designated by its *port_id*
1657  * on the event device designated by its *dev_id*.
1658  *
1659  * @param dev_id
1660  *   The identifier of the device.
1661  *
1662  * @param port_id
1663  *   Event port identifier.
1664  *
1665  * @param[out] queues
1666  *   Points to an array of *queues* for output.
1667  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1668  *   store the event queue(s) linked with event port *port_id*
1669  *
1670  * @param[out] priorities
1671  *   Points to an array of *priorities* for output.
1672  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1673  *   store the service priority associated with each event queue linked
1674  *
1675  * @return
1676  * The number of links established on the event port designated by its
1677  *  *port_id*.
1678  * - <0 on failure.
1679  *
1680  */
1681 int
1682 rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
1683 			 uint8_t queues[], uint8_t priorities[]);
1684 
1685 /**
1686  * Retrieve the service ID of the event dev. If the adapter doesn't use
1687  * a rte_service function, this function returns -ESRCH.
1688  *
1689  * @param dev_id
1690  *   The identifier of the device.
1691  *
1692  * @param [out] service_id
1693  *   A pointer to a uint32_t, to be filled in with the service id.
1694  *
1695  * @return
1696  *   - 0: Success
1697  *   - <0: Error code on failure, if the event dev doesn't use a rte_service
1698  *   function, this function returns -ESRCH.
1699  */
1700 int
1701 rte_event_dev_service_id_get(uint8_t dev_id, uint32_t *service_id);
1702 
1703 /**
1704  * Dump internal information about *dev_id* to the FILE* provided in *f*.
1705  *
1706  * @param dev_id
1707  *   The identifier of the device.
1708  *
1709  * @param f
1710  *   A pointer to a file for output
1711  *
1712  * @return
1713  *   - 0: on success
1714  *   - <0: on failure.
1715  */
1716 int
1717 rte_event_dev_dump(uint8_t dev_id, FILE *f);
1718 
1719 /** Maximum name length for extended statistics counters */
1720 #define RTE_EVENT_DEV_XSTATS_NAME_SIZE 64
1721 
1722 /**
1723  * Selects the component of the eventdev to retrieve statistics from.
1724  */
1725 enum rte_event_dev_xstats_mode {
1726 	RTE_EVENT_DEV_XSTATS_DEVICE,
1727 	RTE_EVENT_DEV_XSTATS_PORT,
1728 	RTE_EVENT_DEV_XSTATS_QUEUE,
1729 };
1730 
1731 /**
1732  * A name-key lookup element for extended statistics.
1733  *
1734  * This structure is used to map between names and ID numbers
1735  * for extended ethdev statistics.
1736  */
1737 struct rte_event_dev_xstats_name {
1738 	char name[RTE_EVENT_DEV_XSTATS_NAME_SIZE];
1739 };
1740 
1741 /**
1742  * Retrieve names of extended statistics of an event device.
1743  *
1744  * @param dev_id
1745  *   The identifier of the event device.
1746  * @param mode
1747  *   The mode of statistics to retrieve. Choices include the device statistics,
1748  *   port statistics or queue statistics.
1749  * @param queue_port_id
1750  *   Used to specify the port or queue number in queue or port mode, and is
1751  *   ignored in device mode.
1752  * @param[out] xstats_names
1753  *   Block of memory to insert names into. Must be at least size in capacity.
1754  *   If set to NULL, function returns required capacity.
1755  * @param[out] ids
1756  *   Block of memory to insert ids into. Must be at least size in capacity.
1757  *   If set to NULL, function returns required capacity. The id values returned
1758  *   can be passed to *rte_event_dev_xstats_get* to select statistics.
1759  * @param size
1760  *   Capacity of xstats_names (number of names).
1761  * @return
1762  *   - positive value lower or equal to size: success. The return value
1763  *     is the number of entries filled in the stats table.
1764  *   - positive value higher than size: error, the given statistics table
1765  *     is too small. The return value corresponds to the size that should
1766  *     be given to succeed. The entries in the table are not valid and
1767  *     shall not be used by the caller.
1768  *   - negative value on error:
1769  *        -ENODEV for invalid *dev_id*
1770  *        -EINVAL for invalid mode, queue port or id parameters
1771  *        -ENOTSUP if the device doesn't support this function.
1772  */
1773 int
1774 rte_event_dev_xstats_names_get(uint8_t dev_id,
1775 			       enum rte_event_dev_xstats_mode mode,
1776 			       uint8_t queue_port_id,
1777 			       struct rte_event_dev_xstats_name *xstats_names,
1778 			       unsigned int *ids,
1779 			       unsigned int size);
1780 
1781 /**
1782  * Retrieve extended statistics of an event device.
1783  *
1784  * @param dev_id
1785  *   The identifier of the device.
1786  * @param mode
1787  *  The mode of statistics to retrieve. Choices include the device statistics,
1788  *  port statistics or queue statistics.
1789  * @param queue_port_id
1790  *   Used to specify the port or queue number in queue or port mode, and is
1791  *   ignored in device mode.
1792  * @param ids
1793  *   The id numbers of the stats to get. The ids can be got from the stat
1794  *   position in the stat list from rte_event_dev_get_xstats_names(), or
1795  *   by using rte_event_dev_xstats_by_name_get().
1796  * @param[out] values
1797  *   The values for each stats request by ID.
1798  * @param n
1799  *   The number of stats requested
1800  * @return
1801  *   - positive value: number of stat entries filled into the values array
1802  *   - negative value on error:
1803  *        -ENODEV for invalid *dev_id*
1804  *        -EINVAL for invalid mode, queue port or id parameters
1805  *        -ENOTSUP if the device doesn't support this function.
1806  */
1807 int
1808 rte_event_dev_xstats_get(uint8_t dev_id,
1809 			 enum rte_event_dev_xstats_mode mode,
1810 			 uint8_t queue_port_id,
1811 			 const unsigned int ids[],
1812 			 uint64_t values[], unsigned int n);
1813 
1814 /**
1815  * Retrieve the value of a single stat by requesting it by name.
1816  *
1817  * @param dev_id
1818  *   The identifier of the device
1819  * @param name
1820  *   The stat name to retrieve
1821  * @param[out] id
1822  *   If non-NULL, the numerical id of the stat will be returned, so that further
1823  *   requests for the stat can be got using rte_event_dev_xstats_get, which will
1824  *   be faster as it doesn't need to scan a list of names for the stat.
1825  *   If the stat cannot be found, the id returned will be (unsigned)-1.
1826  * @return
1827  *   - positive value or zero: the stat value
1828  *   - negative value: -EINVAL if stat not found, -ENOTSUP if not supported.
1829  */
1830 uint64_t
1831 rte_event_dev_xstats_by_name_get(uint8_t dev_id, const char *name,
1832 				 unsigned int *id);
1833 
1834 /**
1835  * Reset the values of the xstats of the selected component in the device.
1836  *
1837  * @param dev_id
1838  *   The identifier of the device
1839  * @param mode
1840  *   The mode of the statistics to reset. Choose from device, queue or port.
1841  * @param queue_port_id
1842  *   The queue or port to reset. 0 and positive values select ports and queues,
1843  *   while -1 indicates all ports or queues.
1844  * @param ids
1845  *   Selects specific statistics to be reset. When NULL, all statistics selected
1846  *   by *mode* will be reset. If non-NULL, must point to array of at least
1847  *   *nb_ids* size.
1848  * @param nb_ids
1849  *   The number of ids available from the *ids* array. Ignored when ids is NULL.
1850  * @return
1851  *   - zero: successfully reset the statistics to zero
1852  *   - negative value: -EINVAL invalid parameters, -ENOTSUP if not supported.
1853  */
1854 int
1855 rte_event_dev_xstats_reset(uint8_t dev_id,
1856 			   enum rte_event_dev_xstats_mode mode,
1857 			   int16_t queue_port_id,
1858 			   const uint32_t ids[],
1859 			   uint32_t nb_ids);
1860 
1861 /**
1862  * Trigger the eventdev self test.
1863  *
1864  * @param dev_id
1865  *   The identifier of the device
1866  * @return
1867  *   - 0: Selftest successful
1868  *   - -ENOTSUP if the device doesn't support selftest
1869  *   - other values < 0 on failure.
1870  */
1871 int rte_event_dev_selftest(uint8_t dev_id);
1872 
1873 /**
1874  * Get the memory required per event vector based on the number of elements per
1875  * vector.
1876  * This should be used to create the mempool that holds the event vectors.
1877  *
1878  * @param name
1879  *   The name of the vector pool.
1880  * @param n
1881  *   The number of elements in the mbuf pool.
1882  * @param cache_size
1883  *   Size of the per-core object cache. See rte_mempool_create() for
1884  *   details.
1885  * @param nb_elem
1886  *   The number of elements that a single event vector should be able to hold.
1887  * @param socket_id
1888  *   The socket identifier where the memory should be allocated. The
1889  *   value can be *SOCKET_ID_ANY* if there is no NUMA constraint for the
1890  *   reserved zone
1891  *
1892  * @return
1893  *   The pointer to the newly allocated mempool, on success. NULL on error
1894  *   with rte_errno set appropriately. Possible rte_errno values include:
1895  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
1896  *    - E_RTE_SECONDARY - function was called from a secondary process instance
1897  *    - EINVAL - cache size provided is too large, or priv_size is not aligned.
1898  *    - ENOSPC - the maximum number of memzones has already been allocated
1899  *    - EEXIST - a memzone with the same name already exists
1900  *    - ENOMEM - no appropriate memory area found in which to create memzone
1901  *    - ENAMETOOLONG - mempool name requested is too long.
1902  */
1903 struct rte_mempool *
1904 rte_event_vector_pool_create(const char *name, unsigned int n,
1905 			     unsigned int cache_size, uint16_t nb_elem,
1906 			     int socket_id);
1907 
1908 #include <rte_eventdev_core.h>
1909 
1910 static __rte_always_inline uint16_t
1911 __rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1912 			  const struct rte_event ev[], uint16_t nb_events,
1913 			  const event_enqueue_burst_t fn)
1914 {
1915 	const struct rte_event_fp_ops *fp_ops;
1916 	void *port;
1917 
1918 	fp_ops = &rte_event_fp_ops[dev_id];
1919 	port = fp_ops->data[port_id];
1920 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
1921 	if (dev_id >= RTE_EVENT_MAX_DEVS ||
1922 	    port_id >= RTE_EVENT_MAX_PORTS_PER_DEV) {
1923 		rte_errno = EINVAL;
1924 		return 0;
1925 	}
1926 
1927 	if (port == NULL) {
1928 		rte_errno = EINVAL;
1929 		return 0;
1930 	}
1931 #endif
1932 	rte_eventdev_trace_enq_burst(dev_id, port_id, ev, nb_events, (void *)fn);
1933 	/*
1934 	 * Allow zero cost non burst mode routine invocation if application
1935 	 * requests nb_events as const one
1936 	 */
1937 	if (nb_events == 1)
1938 		return (fp_ops->enqueue)(port, ev);
1939 	else
1940 		return fn(port, ev, nb_events);
1941 }
1942 
1943 /**
1944  * Enqueue a burst of events objects or an event object supplied in *rte_event*
1945  * structure on an  event device designated by its *dev_id* through the event
1946  * port specified by *port_id*. Each event object specifies the event queue on
1947  * which it will be enqueued.
1948  *
1949  * The *nb_events* parameter is the number of event objects to enqueue which are
1950  * supplied in the *ev* array of *rte_event* structure.
1951  *
1952  * Event operations RTE_EVENT_OP_FORWARD and RTE_EVENT_OP_RELEASE must only be
1953  * enqueued to the same port that their associated events were dequeued from.
1954  *
1955  * The rte_event_enqueue_burst() function returns the number of
1956  * events objects it actually enqueued. A return value equal to *nb_events*
1957  * means that all event objects have been enqueued.
1958  *
1959  * @param dev_id
1960  *   The identifier of the device.
1961  * @param port_id
1962  *   The identifier of the event port.
1963  * @param ev
1964  *   Points to an array of *nb_events* objects of type *rte_event* structure
1965  *   which contain the event object enqueue operations to be processed.
1966  * @param nb_events
1967  *   The number of event objects to enqueue, typically number of
1968  *   rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
1969  *   available for this port.
1970  *
1971  * @return
1972  *   The number of event objects actually enqueued on the event device. The
1973  *   return value can be less than the value of the *nb_events* parameter when
1974  *   the event devices queue is full or if invalid parameters are specified in a
1975  *   *rte_event*. If the return value is less than *nb_events*, the remaining
1976  *   events at the end of ev[] are not consumed and the caller has to take care
1977  *   of them, and rte_errno is set accordingly. Possible errno values include:
1978  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
1979  *              ID is invalid, or an event's sched type doesn't match the
1980  *              capabilities of the destination queue.
1981  *   - ENOSPC   The event port was backpressured and unable to enqueue
1982  *              one or more events. This error code is only applicable to
1983  *              closed systems.
1984  * @see rte_event_port_attr_get(), RTE_EVENT_PORT_ATTR_ENQ_DEPTH
1985  */
1986 static inline uint16_t
1987 rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1988 			const struct rte_event ev[], uint16_t nb_events)
1989 {
1990 	const struct rte_event_fp_ops *fp_ops;
1991 
1992 	fp_ops = &rte_event_fp_ops[dev_id];
1993 	return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
1994 					 fp_ops->enqueue_burst);
1995 }
1996 
1997 /**
1998  * Enqueue a burst of events objects of operation type *RTE_EVENT_OP_NEW* on
1999  * an event device designated by its *dev_id* through the event port specified
2000  * by *port_id*.
2001  *
2002  * Provides the same functionality as rte_event_enqueue_burst(), expect that
2003  * application can use this API when the all objects in the burst contains
2004  * the enqueue operation of the type *RTE_EVENT_OP_NEW*. This specialized
2005  * function can provide the additional hint to the PMD and optimize if possible.
2006  *
2007  * The rte_event_enqueue_new_burst() result is undefined if the enqueue burst
2008  * has event object of operation type != RTE_EVENT_OP_NEW.
2009  *
2010  * @param dev_id
2011  *   The identifier of the device.
2012  * @param port_id
2013  *   The identifier of the event port.
2014  * @param ev
2015  *   Points to an array of *nb_events* objects of type *rte_event* structure
2016  *   which contain the event object enqueue operations to be processed.
2017  * @param nb_events
2018  *   The number of event objects to enqueue, typically number of
2019  *   rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
2020  *   available for this port.
2021  *
2022  * @return
2023  *   The number of event objects actually enqueued on the event device. The
2024  *   return value can be less than the value of the *nb_events* parameter when
2025  *   the event devices queue is full or if invalid parameters are specified in a
2026  *   *rte_event*. If the return value is less than *nb_events*, the remaining
2027  *   events at the end of ev[] are not consumed and the caller has to take care
2028  *   of them, and rte_errno is set accordingly. Possible errno values include:
2029  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
2030  *              ID is invalid, or an event's sched type doesn't match the
2031  *              capabilities of the destination queue.
2032  *   - ENOSPC   The event port was backpressured and unable to enqueue
2033  *              one or more events. This error code is only applicable to
2034  *              closed systems.
2035  * @see rte_event_port_attr_get(), RTE_EVENT_PORT_ATTR_ENQ_DEPTH
2036  * @see rte_event_enqueue_burst()
2037  */
2038 static inline uint16_t
2039 rte_event_enqueue_new_burst(uint8_t dev_id, uint8_t port_id,
2040 			    const struct rte_event ev[], uint16_t nb_events)
2041 {
2042 	const struct rte_event_fp_ops *fp_ops;
2043 
2044 	fp_ops = &rte_event_fp_ops[dev_id];
2045 	return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
2046 					 fp_ops->enqueue_new_burst);
2047 }
2048 
2049 /**
2050  * Enqueue a burst of events objects of operation type *RTE_EVENT_OP_FORWARD*
2051  * on an event device designated by its *dev_id* through the event port
2052  * specified by *port_id*.
2053  *
2054  * Provides the same functionality as rte_event_enqueue_burst(), expect that
2055  * application can use this API when the all objects in the burst contains
2056  * the enqueue operation of the type *RTE_EVENT_OP_FORWARD*. This specialized
2057  * function can provide the additional hint to the PMD and optimize if possible.
2058  *
2059  * The rte_event_enqueue_new_burst() result is undefined if the enqueue burst
2060  * has event object of operation type != RTE_EVENT_OP_FORWARD.
2061  *
2062  * @param dev_id
2063  *   The identifier of the device.
2064  * @param port_id
2065  *   The identifier of the event port.
2066  * @param ev
2067  *   Points to an array of *nb_events* objects of type *rte_event* structure
2068  *   which contain the event object enqueue operations to be processed.
2069  * @param nb_events
2070  *   The number of event objects to enqueue, typically number of
2071  *   rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
2072  *   available for this port.
2073  *
2074  * @return
2075  *   The number of event objects actually enqueued on the event device. The
2076  *   return value can be less than the value of the *nb_events* parameter when
2077  *   the event devices queue is full or if invalid parameters are specified in a
2078  *   *rte_event*. If the return value is less than *nb_events*, the remaining
2079  *   events at the end of ev[] are not consumed and the caller has to take care
2080  *   of them, and rte_errno is set accordingly. Possible errno values include:
2081  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
2082  *              ID is invalid, or an event's sched type doesn't match the
2083  *              capabilities of the destination queue.
2084  *   - ENOSPC   The event port was backpressured and unable to enqueue
2085  *              one or more events. This error code is only applicable to
2086  *              closed systems.
2087  * @see rte_event_port_attr_get(), RTE_EVENT_PORT_ATTR_ENQ_DEPTH
2088  * @see rte_event_enqueue_burst()
2089  */
2090 static inline uint16_t
2091 rte_event_enqueue_forward_burst(uint8_t dev_id, uint8_t port_id,
2092 				const struct rte_event ev[], uint16_t nb_events)
2093 {
2094 	const struct rte_event_fp_ops *fp_ops;
2095 
2096 	fp_ops = &rte_event_fp_ops[dev_id];
2097 	return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
2098 					 fp_ops->enqueue_forward_burst);
2099 }
2100 
2101 /**
2102  * Dequeue a burst of events objects or an event object from the event port
2103  * designated by its *event_port_id*, on an event device designated
2104  * by its *dev_id*.
2105  *
2106  * rte_event_dequeue_burst() does not dictate the specifics of scheduling
2107  * algorithm as each eventdev driver may have different criteria to schedule
2108  * an event. However, in general, from an application perspective scheduler may
2109  * use the following scheme to dispatch an event to the port.
2110  *
2111  * 1) Selection of event queue based on
2112  *   a) The list of event queues are linked to the event port.
2113  *   b) If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then event
2114  *   queue selection from list is based on event queue priority relative to
2115  *   other event queue supplied as *priority* in rte_event_queue_setup()
2116  *   c) If the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability then event
2117  *   queue selection from the list is based on event priority supplied as
2118  *   *priority* in rte_event_enqueue_burst()
2119  * 2) Selection of event
2120  *   a) The number of flows available in selected event queue.
2121  *   b) Schedule type method associated with the event
2122  *
2123  * The *nb_events* parameter is the maximum number of event objects to dequeue
2124  * which are returned in the *ev* array of *rte_event* structure.
2125  *
2126  * The rte_event_dequeue_burst() function returns the number of events objects
2127  * it actually dequeued. A return value equal to *nb_events* means that all
2128  * event objects have been dequeued.
2129  *
2130  * The number of events dequeued is the number of scheduler contexts held by
2131  * this port. These contexts are automatically released in the next
2132  * rte_event_dequeue_burst() invocation if the port supports implicit
2133  * releases, or invoking rte_event_enqueue_burst() with RTE_EVENT_OP_RELEASE
2134  * operation can be used to release the contexts early.
2135  *
2136  * Event operations RTE_EVENT_OP_FORWARD and RTE_EVENT_OP_RELEASE must only be
2137  * enqueued to the same port that their associated events were dequeued from.
2138  *
2139  * @param dev_id
2140  *   The identifier of the device.
2141  * @param port_id
2142  *   The identifier of the event port.
2143  * @param[out] ev
2144  *   Points to an array of *nb_events* objects of type *rte_event* structure
2145  *   for output to be populated with the dequeued event objects.
2146  * @param nb_events
2147  *   The maximum number of event objects to dequeue, typically number of
2148  *   rte_event_port_dequeue_depth() available for this port.
2149  *
2150  * @param timeout_ticks
2151  *   - 0 no-wait, returns immediately if there is no event.
2152  *   - >0 wait for the event, if the device is configured with
2153  *   RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT then this function will wait until
2154  *   at least one event is available or *timeout_ticks* time.
2155  *   if the device is not configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
2156  *   then this function will wait until the event available or
2157  *   *dequeue_timeout_ns* ns which was previously supplied to
2158  *   rte_event_dev_configure()
2159  *
2160  * @return
2161  * The number of event objects actually dequeued from the port. The return
2162  * value can be less than the value of the *nb_events* parameter when the
2163  * event port's queue is not full.
2164  *
2165  * @see rte_event_port_dequeue_depth()
2166  */
2167 static inline uint16_t
2168 rte_event_dequeue_burst(uint8_t dev_id, uint8_t port_id, struct rte_event ev[],
2169 			uint16_t nb_events, uint64_t timeout_ticks)
2170 {
2171 	const struct rte_event_fp_ops *fp_ops;
2172 	void *port;
2173 
2174 	fp_ops = &rte_event_fp_ops[dev_id];
2175 	port = fp_ops->data[port_id];
2176 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
2177 	if (dev_id >= RTE_EVENT_MAX_DEVS ||
2178 	    port_id >= RTE_EVENT_MAX_PORTS_PER_DEV) {
2179 		rte_errno = EINVAL;
2180 		return 0;
2181 	}
2182 
2183 	if (port == NULL) {
2184 		rte_errno = EINVAL;
2185 		return 0;
2186 	}
2187 #endif
2188 	rte_eventdev_trace_deq_burst(dev_id, port_id, ev, nb_events);
2189 	/*
2190 	 * Allow zero cost non burst mode routine invocation if application
2191 	 * requests nb_events as const one
2192 	 */
2193 	if (nb_events == 1)
2194 		return (fp_ops->dequeue)(port, ev, timeout_ticks);
2195 	else
2196 		return (fp_ops->dequeue_burst)(port, ev, nb_events,
2197 					       timeout_ticks);
2198 }
2199 
2200 #define RTE_EVENT_DEV_MAINT_OP_FLUSH          (1 << 0)
2201 /**< Force an immediately flush of any buffered events in the port,
2202  * potentially at the cost of additional overhead.
2203  *
2204  * @see rte_event_maintain()
2205  */
2206 
2207 /**
2208  * Maintain an event device.
2209  *
2210  * This function is only relevant for event devices which do not have
2211  * the @ref RTE_EVENT_DEV_CAP_MAINTENANCE_FREE flag set. Such devices
2212  * require an application thread using a particular port to
2213  * periodically call rte_event_maintain() on that port during periods
2214  * which it is neither attempting to enqueue events to nor dequeue
2215  * events from the port. rte_event_maintain() is a low-overhead
2216  * function and should be called at a high rate (e.g., in the
2217  * application's poll loop).
2218  *
2219  * No port may be left unmaintained.
2220  *
2221  * At the application thread's convenience, rte_event_maintain() may
2222  * (but is not required to) be called even during periods when enqueue
2223  * or dequeue functions are being called, at the cost of a slight
2224  * increase in overhead.
2225  *
2226  * rte_event_maintain() may be called on event devices which have set
2227  * @ref RTE_EVENT_DEV_CAP_MAINTENANCE_FREE, in which case it is a
2228  * no-operation.
2229  *
2230  * @param dev_id
2231  *   The identifier of the device.
2232  * @param port_id
2233  *   The identifier of the event port.
2234  * @param op
2235  *   0, or @ref RTE_EVENT_DEV_MAINT_OP_FLUSH.
2236  * @return
2237  *  - 0 on success.
2238  *  - -EINVAL if *dev_id*,  *port_id*, or *op* is invalid.
2239  *
2240  * @see RTE_EVENT_DEV_CAP_MAINTENANCE_FREE
2241  */
2242 __rte_experimental
2243 static inline int
2244 rte_event_maintain(uint8_t dev_id, uint8_t port_id, int op)
2245 {
2246 	const struct rte_event_fp_ops *fp_ops;
2247 	void *port;
2248 
2249 	fp_ops = &rte_event_fp_ops[dev_id];
2250 	port = fp_ops->data[port_id];
2251 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
2252 	if (dev_id >= RTE_EVENT_MAX_DEVS ||
2253 	    port_id >= RTE_EVENT_MAX_PORTS_PER_DEV)
2254 		return -EINVAL;
2255 
2256 	if (port == NULL)
2257 		return -EINVAL;
2258 
2259 	if (op & (~RTE_EVENT_DEV_MAINT_OP_FLUSH))
2260 		return -EINVAL;
2261 #endif
2262 	rte_eventdev_trace_maintain(dev_id, port_id, op);
2263 
2264 	if (fp_ops->maintain != NULL)
2265 		fp_ops->maintain(port, op);
2266 
2267 	return 0;
2268 }
2269 
2270 #ifdef __cplusplus
2271 }
2272 #endif
2273 
2274 #endif /* _RTE_EVENTDEV_H_ */
2275