xref: /dpdk/lib/eventdev/rte_eventdev.h (revision c56185fc183fc0532d2f03aaf04bbf0989ea91a5)
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 #ifdef __cplusplus
209 extern "C" {
210 #endif
211 
212 #include <rte_compat.h>
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 int
466 rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info);
467 
468 /**
469  * The count of ports.
470  */
471 #define RTE_EVENT_DEV_ATTR_PORT_COUNT 0
472 /**
473  * The count of queues.
474  */
475 #define RTE_EVENT_DEV_ATTR_QUEUE_COUNT 1
476 /**
477  * The status of the device, zero for stopped, non-zero for started.
478  */
479 #define RTE_EVENT_DEV_ATTR_STARTED 2
480 
481 /**
482  * Get an attribute from a device.
483  *
484  * @param dev_id Eventdev id
485  * @param attr_id The attribute ID to retrieve
486  * @param[out] attr_value A pointer that will be filled in with the attribute
487  *             value if successful.
488  *
489  * @return
490  *   - 0: Successfully retrieved attribute value
491  *   - -EINVAL: Invalid device or  *attr_id* provided, or *attr_value* is NULL
492  */
493 int
494 rte_event_dev_attr_get(uint8_t dev_id, uint32_t attr_id,
495 		       uint32_t *attr_value);
496 
497 
498 /* Event device configuration bitmap flags */
499 #define RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT (1ULL << 0)
500 /**< Override the global *dequeue_timeout_ns* and use per dequeue timeout in ns.
501  *  @see rte_event_dequeue_timeout_ticks(), rte_event_dequeue_burst()
502  */
503 
504 /** Event device configuration structure */
505 struct rte_event_dev_config {
506 	uint32_t dequeue_timeout_ns;
507 	/**< rte_event_dequeue_burst() timeout on this device.
508 	 * This value should be in the range of *min_dequeue_timeout_ns* and
509 	 * *max_dequeue_timeout_ns* which previously provided in
510 	 * rte_event_dev_info_get()
511 	 * The value 0 is allowed, in which case, default dequeue timeout used.
512 	 * @see RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
513 	 */
514 	int32_t nb_events_limit;
515 	/**< In a *closed system* this field is the limit on maximum number of
516 	 * events that can be inflight in the eventdev at a given time. The
517 	 * limit is required to ensure that the finite space in a closed system
518 	 * is not overwhelmed. The value cannot exceed the *max_num_events*
519 	 * as provided by rte_event_dev_info_get().
520 	 * This value should be set to -1 for *open system*.
521 	 */
522 	uint8_t nb_event_queues;
523 	/**< Number of event queues to configure on this device.
524 	 * This value cannot exceed the *max_event_queues* which previously
525 	 * provided in rte_event_dev_info_get()
526 	 */
527 	uint8_t nb_event_ports;
528 	/**< Number of event ports to configure on this device.
529 	 * This value cannot exceed the *max_event_ports* which previously
530 	 * provided in rte_event_dev_info_get()
531 	 */
532 	uint32_t nb_event_queue_flows;
533 	/**< Number of flows for any event queue on this device.
534 	 * This value cannot exceed the *max_event_queue_flows* which previously
535 	 * provided in rte_event_dev_info_get()
536 	 */
537 	uint32_t nb_event_port_dequeue_depth;
538 	/**< Maximum number of events can be dequeued at a time from an
539 	 * event port by this device.
540 	 * This value cannot exceed the *max_event_port_dequeue_depth*
541 	 * which previously provided in rte_event_dev_info_get().
542 	 * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
543 	 * @see rte_event_port_setup()
544 	 */
545 	uint32_t nb_event_port_enqueue_depth;
546 	/**< Maximum number of events can be enqueued at a time from an
547 	 * event port by this device.
548 	 * This value cannot exceed the *max_event_port_enqueue_depth*
549 	 * which previously provided in rte_event_dev_info_get().
550 	 * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
551 	 * @see rte_event_port_setup()
552 	 */
553 	uint32_t event_dev_cfg;
554 	/**< Event device config flags(RTE_EVENT_DEV_CFG_)*/
555 	uint8_t nb_single_link_event_port_queues;
556 	/**< Number of event ports and queues that will be singly-linked to
557 	 * each other. These are a subset of the overall event ports and
558 	 * queues; this value cannot exceed *nb_event_ports* or
559 	 * *nb_event_queues*. If the device has ports and queues that are
560 	 * optimized for single-link usage, this field is a hint for how many
561 	 * to allocate; otherwise, regular event ports and queues can be used.
562 	 */
563 };
564 
565 /**
566  * Configure an event device.
567  *
568  * This function must be invoked first before any other function in the
569  * API. This function can also be re-invoked when a device is in the
570  * stopped state.
571  *
572  * The caller may use rte_event_dev_info_get() to get the capability of each
573  * resources available for this event device.
574  *
575  * @param dev_id
576  *   The identifier of the device to configure.
577  * @param dev_conf
578  *   The event device configuration structure.
579  *
580  * @return
581  *   - 0: Success, device configured.
582  *   - <0: Error code returned by the driver configuration function.
583  */
584 int
585 rte_event_dev_configure(uint8_t dev_id,
586 			const struct rte_event_dev_config *dev_conf);
587 
588 /* Event queue specific APIs */
589 
590 /* Event queue configuration bitmap flags */
591 #define RTE_EVENT_QUEUE_CFG_ALL_TYPES          (1ULL << 0)
592 /**< Allow ATOMIC,ORDERED,PARALLEL schedule type enqueue
593  *
594  * @see RTE_SCHED_TYPE_ORDERED, RTE_SCHED_TYPE_ATOMIC, RTE_SCHED_TYPE_PARALLEL
595  * @see rte_event_enqueue_burst()
596  */
597 #define RTE_EVENT_QUEUE_CFG_SINGLE_LINK        (1ULL << 1)
598 /**< This event queue links only to a single event port.
599  *
600  *  @see rte_event_port_setup(), rte_event_port_link()
601  */
602 
603 /** Event queue configuration structure */
604 struct rte_event_queue_conf {
605 	uint32_t nb_atomic_flows;
606 	/**< The maximum number of active flows this queue can track at any
607 	 * given time. If the queue is configured for atomic scheduling (by
608 	 * applying the RTE_EVENT_QUEUE_CFG_ALL_TYPES flag to event_queue_cfg
609 	 * or RTE_SCHED_TYPE_ATOMIC flag to schedule_type), then the
610 	 * value must be in the range of [1, nb_event_queue_flows], which was
611 	 * previously provided in rte_event_dev_configure().
612 	 */
613 	uint32_t nb_atomic_order_sequences;
614 	/**< The maximum number of outstanding events waiting to be
615 	 * reordered by this queue. In other words, the number of entries in
616 	 * this queue’s reorder buffer.When the number of events in the
617 	 * reorder buffer reaches to *nb_atomic_order_sequences* then the
618 	 * scheduler cannot schedule the events from this queue and invalid
619 	 * event will be returned from dequeue until one or more entries are
620 	 * freed up/released.
621 	 * If the queue is configured for ordered scheduling (by applying the
622 	 * RTE_EVENT_QUEUE_CFG_ALL_TYPES flag to event_queue_cfg or
623 	 * RTE_SCHED_TYPE_ORDERED flag to schedule_type), then the value must
624 	 * be in the range of [1, nb_event_queue_flows], which was
625 	 * previously supplied to rte_event_dev_configure().
626 	 */
627 	uint32_t event_queue_cfg;
628 	/**< Queue cfg flags(EVENT_QUEUE_CFG_) */
629 	uint8_t schedule_type;
630 	/**< Queue schedule type(RTE_SCHED_TYPE_*).
631 	 * Valid when RTE_EVENT_QUEUE_CFG_ALL_TYPES bit is not set in
632 	 * event_queue_cfg.
633 	 */
634 	uint8_t priority;
635 	/**< Priority for this event queue relative to other event queues.
636 	 * The requested priority should in the range of
637 	 * [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
638 	 * The implementation shall normalize the requested priority to
639 	 * event device supported priority value.
640 	 * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
641 	 */
642 	uint8_t weight;
643 	/**< Weight of the event queue relative to other event queues.
644 	 * The requested weight should be in the range of
645 	 * [RTE_EVENT_DEV_WEIGHT_HIGHEST, RTE_EVENT_DEV_WEIGHT_LOWEST].
646 	 * The implementation shall normalize the requested weight to event
647 	 * device supported weight value.
648 	 * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability.
649 	 */
650 	uint8_t affinity;
651 	/**< Affinity of the event queue relative to other event queues.
652 	 * The requested affinity should be in the range of
653 	 * [RTE_EVENT_DEV_AFFINITY_HIGHEST, RTE_EVENT_DEV_AFFINITY_LOWEST].
654 	 * The implementation shall normalize the requested affinity to event
655 	 * device supported affinity value.
656 	 * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability.
657 	 */
658 };
659 
660 /**
661  * Retrieve the default configuration information of an event queue designated
662  * by its *queue_id* from the event driver for an event device.
663  *
664  * This function intended to be used in conjunction with rte_event_queue_setup()
665  * where caller needs to set up the queue by overriding few default values.
666  *
667  * @param dev_id
668  *   The identifier of the device.
669  * @param queue_id
670  *   The index of the event queue to get the configuration information.
671  *   The value must be in the range [0, nb_event_queues - 1]
672  *   previously supplied to rte_event_dev_configure().
673  * @param[out] queue_conf
674  *   The pointer to the default event queue configuration data.
675  * @return
676  *   - 0: Success, driver updates the default event queue configuration data.
677  *   - <0: Error code returned by the driver info get function.
678  *
679  * @see rte_event_queue_setup()
680  */
681 int
682 rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
683 				 struct rte_event_queue_conf *queue_conf);
684 
685 /**
686  * Allocate and set up an event queue for an event device.
687  *
688  * @param dev_id
689  *   The identifier of the device.
690  * @param queue_id
691  *   The index of the event queue to setup. The value must be in the range
692  *   [0, nb_event_queues - 1] previously supplied to rte_event_dev_configure().
693  * @param queue_conf
694  *   The pointer to the configuration data to be used for the event queue.
695  *   NULL value is allowed, in which case default configuration	used.
696  *
697  * @see rte_event_queue_default_conf_get()
698  *
699  * @return
700  *   - 0: Success, event queue correctly set up.
701  *   - <0: event queue configuration failed
702  */
703 int
704 rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
705 		      const struct rte_event_queue_conf *queue_conf);
706 
707 /**
708  * The priority of the queue.
709  */
710 #define RTE_EVENT_QUEUE_ATTR_PRIORITY 0
711 /**
712  * The number of atomic flows configured for the queue.
713  */
714 #define RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_FLOWS 1
715 /**
716  * The number of atomic order sequences configured for the queue.
717  */
718 #define RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_ORDER_SEQUENCES 2
719 /**
720  * The cfg flags for the queue.
721  */
722 #define RTE_EVENT_QUEUE_ATTR_EVENT_QUEUE_CFG 3
723 /**
724  * The schedule type of the queue.
725  */
726 #define RTE_EVENT_QUEUE_ATTR_SCHEDULE_TYPE 4
727 /**
728  * The weight of the queue.
729  */
730 #define RTE_EVENT_QUEUE_ATTR_WEIGHT 5
731 /**
732  * Affinity of the queue.
733  */
734 #define RTE_EVENT_QUEUE_ATTR_AFFINITY 6
735 
736 /**
737  * Get an attribute from a queue.
738  *
739  * @param dev_id
740  *   Eventdev id
741  * @param queue_id
742  *   Eventdev queue id
743  * @param attr_id
744  *   The attribute ID to retrieve
745  * @param[out] attr_value
746  *   A pointer that will be filled in with the attribute value if successful
747  *
748  * @return
749  *   - 0: Successfully returned value
750  *   - -EINVAL: invalid device, queue or attr_id provided, or attr_value was
751  *		NULL
752  *   - -EOVERFLOW: returned when attr_id is set to
753  *   RTE_EVENT_QUEUE_ATTR_SCHEDULE_TYPE and event_queue_cfg is set to
754  *   RTE_EVENT_QUEUE_CFG_ALL_TYPES
755  */
756 int
757 rte_event_queue_attr_get(uint8_t dev_id, uint8_t queue_id, uint32_t attr_id,
758 			uint32_t *attr_value);
759 
760 /**
761  * Set an event queue attribute.
762  *
763  * @param dev_id
764  *   Eventdev id
765  * @param queue_id
766  *   Eventdev queue id
767  * @param attr_id
768  *   The attribute ID to set
769  * @param attr_value
770  *   The attribute value to set
771  *
772  * @return
773  *   - 0: Successfully set attribute.
774  *   - -EINVAL: invalid device, queue or attr_id.
775  *   - -ENOTSUP: device does not support setting the event attribute.
776  *   - <0: failed to set event queue attribute
777  */
778 __rte_experimental
779 int
780 rte_event_queue_attr_set(uint8_t dev_id, uint8_t queue_id, uint32_t attr_id,
781 			 uint64_t attr_value);
782 
783 /* Event port specific APIs */
784 
785 /* Event port configuration bitmap flags */
786 #define RTE_EVENT_PORT_CFG_DISABLE_IMPL_REL    (1ULL << 0)
787 /**< Configure the port not to release outstanding events in
788  * rte_event_dev_dequeue_burst(). If set, all events received through
789  * the port must be explicitly released with RTE_EVENT_OP_RELEASE or
790  * RTE_EVENT_OP_FORWARD. Must be unset if the device is not
791  * RTE_EVENT_DEV_CAP_IMPLICIT_RELEASE_DISABLE capable.
792  */
793 #define RTE_EVENT_PORT_CFG_SINGLE_LINK         (1ULL << 1)
794 /**< This event port links only to a single event queue.
795  *
796  *  @see rte_event_port_setup(), rte_event_port_link()
797  */
798 #define RTE_EVENT_PORT_CFG_HINT_PRODUCER       (1ULL << 2)
799 /**< Hint that this event port will primarily enqueue events to the system.
800  * A PMD can optimize its internal workings by assuming that this port is
801  * primarily going to enqueue NEW events.
802  *
803  * Note that this flag is only a hint, so PMDs must operate under the
804  * assumption that any port can enqueue an event with any type of op.
805  *
806  *  @see rte_event_port_setup()
807  */
808 #define RTE_EVENT_PORT_CFG_HINT_CONSUMER       (1ULL << 3)
809 /**< Hint that this event port will primarily dequeue events from the system.
810  * A PMD can optimize its internal workings by assuming that this port is
811  * primarily going to consume events, and not enqueue FORWARD or RELEASE
812  * events.
813  *
814  * Note that this flag is only a hint, so PMDs must operate under the
815  * assumption that any port can enqueue an event with any type of op.
816  *
817  *  @see rte_event_port_setup()
818  */
819 #define RTE_EVENT_PORT_CFG_HINT_WORKER         (1ULL << 4)
820 /**< Hint that this event port will primarily pass existing events through.
821  * A PMD can optimize its internal workings by assuming that this port is
822  * primarily going to FORWARD events, and not enqueue NEW or RELEASE events
823  * often.
824  *
825  * Note that this flag is only a hint, so PMDs must operate under the
826  * assumption that any port can enqueue an event with any type of op.
827  *
828  *  @see rte_event_port_setup()
829  */
830 
831 /** Event port configuration structure */
832 struct rte_event_port_conf {
833 	int32_t new_event_threshold;
834 	/**< A backpressure threshold for new event enqueues on this port.
835 	 * Use for *closed system* event dev where event capacity is limited,
836 	 * and cannot exceed the capacity of the event dev.
837 	 * Configuring ports with different thresholds can make higher priority
838 	 * traffic less likely to  be backpressured.
839 	 * For example, a port used to inject NIC Rx packets into the event dev
840 	 * can have a lower threshold so as not to overwhelm the device,
841 	 * while ports used for worker pools can have a higher threshold.
842 	 * This value cannot exceed the *nb_events_limit*
843 	 * which was previously supplied to rte_event_dev_configure().
844 	 * This should be set to '-1' for *open system*.
845 	 */
846 	uint16_t dequeue_depth;
847 	/**< Configure number of bulk dequeues for this event port.
848 	 * This value cannot exceed the *nb_event_port_dequeue_depth*
849 	 * which previously supplied to rte_event_dev_configure().
850 	 * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
851 	 */
852 	uint16_t enqueue_depth;
853 	/**< Configure number of bulk enqueues for this event port.
854 	 * This value cannot exceed the *nb_event_port_enqueue_depth*
855 	 * which previously supplied to rte_event_dev_configure().
856 	 * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
857 	 */
858 	uint32_t event_port_cfg; /**< Port cfg flags(EVENT_PORT_CFG_) */
859 };
860 
861 /**
862  * Retrieve the default configuration information of an event port designated
863  * by its *port_id* from the event driver for an event device.
864  *
865  * This function intended to be used in conjunction with rte_event_port_setup()
866  * where caller needs to set up the port by overriding few default values.
867  *
868  * @param dev_id
869  *   The identifier of the device.
870  * @param port_id
871  *   The index of the event port to get the configuration information.
872  *   The value must be in the range [0, nb_event_ports - 1]
873  *   previously supplied to rte_event_dev_configure().
874  * @param[out] port_conf
875  *   The pointer to the default event port configuration data
876  * @return
877  *   - 0: Success, driver updates the default event port configuration data.
878  *   - <0: Error code returned by the driver info get function.
879  *
880  * @see rte_event_port_setup()
881  */
882 int
883 rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
884 				struct rte_event_port_conf *port_conf);
885 
886 /**
887  * Allocate and set up an event port for an event device.
888  *
889  * @param dev_id
890  *   The identifier of the device.
891  * @param port_id
892  *   The index of the event port to setup. The value must be in the range
893  *   [0, nb_event_ports - 1] previously supplied to rte_event_dev_configure().
894  * @param port_conf
895  *   The pointer to the configuration data to be used for the queue.
896  *   NULL value is allowed, in which case default configuration	used.
897  *
898  * @see rte_event_port_default_conf_get()
899  *
900  * @return
901  *   - 0: Success, event port correctly set up.
902  *   - <0: Port configuration failed
903  *   - (-EDQUOT) Quota exceeded(Application tried to link the queue configured
904  *   with RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
905  */
906 int
907 rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
908 		     const struct rte_event_port_conf *port_conf);
909 
910 typedef void (*rte_eventdev_port_flush_t)(uint8_t dev_id,
911 					  struct rte_event event, void *arg);
912 /**< Callback function prototype that can be passed during
913  * rte_event_port_release(), invoked once per a released event.
914  */
915 
916 /**
917  * Quiesce any core specific resources consumed by the event port.
918  *
919  * Event ports are generally coupled with lcores, and a given Hardware
920  * implementation might require the PMD to store port specific data in the
921  * lcore.
922  * When the application decides to migrate the event port to another lcore
923  * or teardown the current lcore it may to call `rte_event_port_quiesce`
924  * to make sure that all the data associated with the event port are released
925  * from the lcore, this might also include any prefetched events.
926  * While releasing the event port from the lcore, this function calls the
927  * user-provided flush callback once per event.
928  *
929  * @note Invocation of this API does not affect the existing port configuration.
930  *
931  * @param dev_id
932  *   The identifier of the device.
933  * @param port_id
934  *   The index of the event port to setup. The value must be in the range
935  *   [0, nb_event_ports - 1] previously supplied to rte_event_dev_configure().
936  * @param release_cb
937  *   Callback function invoked once per flushed event.
938  * @param args
939  *   Argument supplied to callback.
940  */
941 __rte_experimental
942 void
943 rte_event_port_quiesce(uint8_t dev_id, uint8_t port_id,
944 		       rte_eventdev_port_flush_t release_cb, void *args);
945 
946 /**
947  * The queue depth of the port on the enqueue side
948  */
949 #define RTE_EVENT_PORT_ATTR_ENQ_DEPTH 0
950 /**
951  * The queue depth of the port on the dequeue side
952  */
953 #define RTE_EVENT_PORT_ATTR_DEQ_DEPTH 1
954 /**
955  * The new event threshold of the port
956  */
957 #define RTE_EVENT_PORT_ATTR_NEW_EVENT_THRESHOLD 2
958 /**
959  * The implicit release disable attribute of the port
960  */
961 #define RTE_EVENT_PORT_ATTR_IMPLICIT_RELEASE_DISABLE 3
962 
963 /**
964  * Get an attribute from a port.
965  *
966  * @param dev_id
967  *   Eventdev id
968  * @param port_id
969  *   Eventdev port id
970  * @param attr_id
971  *   The attribute ID to retrieve
972  * @param[out] attr_value
973  *   A pointer that will be filled in with the attribute value if successful
974  *
975  * @return
976  *   - 0: Successfully returned value
977  *   - (-EINVAL) Invalid device, port or attr_id, or attr_value was NULL
978  */
979 int
980 rte_event_port_attr_get(uint8_t dev_id, uint8_t port_id, uint32_t attr_id,
981 			uint32_t *attr_value);
982 
983 /**
984  * Start an event device.
985  *
986  * The device start step is the last one and consists of setting the event
987  * queues to start accepting the events and schedules to event ports.
988  *
989  * On success, all basic functions exported by the API (event enqueue,
990  * event dequeue and so on) can be invoked.
991  *
992  * @param dev_id
993  *   Event device identifier
994  * @return
995  *   - 0: Success, device started.
996  *   - -ESTALE : Not all ports of the device are configured
997  *   - -ENOLINK: Not all queues are linked, which could lead to deadlock.
998  */
999 int
1000 rte_event_dev_start(uint8_t dev_id);
1001 
1002 /**
1003  * Stop an event device.
1004  *
1005  * This function causes all queued events to be drained, including those
1006  * residing in event ports. While draining events out of the device, this
1007  * function calls the user-provided flush callback (if one was registered) once
1008  * per event.
1009  *
1010  * The device can be restarted with a call to rte_event_dev_start(). Threads
1011  * that continue to enqueue/dequeue while the device is stopped, or being
1012  * stopped, will result in undefined behavior. This includes event adapters,
1013  * which must be stopped prior to stopping the eventdev.
1014  *
1015  * @param dev_id
1016  *   Event device identifier.
1017  *
1018  * @see rte_event_dev_stop_flush_callback_register()
1019  */
1020 void
1021 rte_event_dev_stop(uint8_t dev_id);
1022 
1023 typedef void (*rte_eventdev_stop_flush_t)(uint8_t dev_id,
1024 					  struct rte_event event, void *arg);
1025 /**< Callback function called during rte_event_dev_stop(), invoked once per
1026  * flushed event.
1027  */
1028 
1029 /**
1030  * Registers a callback function to be invoked during rte_event_dev_stop() for
1031  * each flushed event. This function can be used to properly dispose of queued
1032  * events, for example events containing memory pointers.
1033  *
1034  * The callback function is only registered for the calling process. The
1035  * callback function must be registered in every process that can call
1036  * rte_event_dev_stop().
1037  *
1038  * To unregister a callback, call this function with a NULL callback pointer.
1039  *
1040  * @param dev_id
1041  *   The identifier of the device.
1042  * @param callback
1043  *   Callback function invoked once per flushed event.
1044  * @param userdata
1045  *   Argument supplied to callback.
1046  *
1047  * @return
1048  *  - 0 on success.
1049  *  - -EINVAL if *dev_id* is invalid
1050  *
1051  * @see rte_event_dev_stop()
1052  */
1053 int rte_event_dev_stop_flush_callback_register(uint8_t dev_id,
1054 					       rte_eventdev_stop_flush_t callback, void *userdata);
1055 
1056 /**
1057  * Close an event device. The device cannot be restarted!
1058  *
1059  * @param dev_id
1060  *   Event device identifier
1061  *
1062  * @return
1063  *  - 0 on successfully closing device
1064  *  - <0 on failure to close device
1065  *  - (-EAGAIN) if device is busy
1066  */
1067 int
1068 rte_event_dev_close(uint8_t dev_id);
1069 
1070 /**
1071  * Event vector structure.
1072  */
1073 struct rte_event_vector {
1074 	uint16_t nb_elem;
1075 	/**< Number of elements valid in this event vector. */
1076 	uint16_t elem_offset : 12;
1077 	/**< Offset into the vector array where valid elements start from. */
1078 	uint16_t rsvd : 3;
1079 	/**< Reserved for future use */
1080 	uint16_t attr_valid : 1;
1081 	/**< Indicates that the below union attributes have valid information.
1082 	 */
1083 	union {
1084 		/* Used by Rx/Tx adapter.
1085 		 * Indicates that all the elements in this vector belong to the
1086 		 * same port and queue pair when originating from Rx adapter,
1087 		 * valid only when event type is ETHDEV_VECTOR or
1088 		 * ETH_RX_ADAPTER_VECTOR.
1089 		 * Can also be used to indicate the Tx adapter the destination
1090 		 * port and queue of the mbufs in the vector
1091 		 */
1092 		struct {
1093 			uint16_t port;
1094 			/* Ethernet device port id. */
1095 			uint16_t queue;
1096 			/* Ethernet device queue id. */
1097 		};
1098 	};
1099 	/**< Union to hold common attributes of the vector array. */
1100 	uint64_t impl_opaque;
1101 
1102 /* empty structures do not have zero size in C++ leading to compilation errors
1103  * with clang about structure having different sizes in C and C++.
1104  * Since these are all zero-sized arrays, we can omit the "union" wrapper for
1105  * C++ builds, removing the warning.
1106  */
1107 #ifndef __cplusplus
1108 	/**< Implementation specific opaque value.
1109 	 * An implementation may use this field to hold implementation specific
1110 	 * value to share between dequeue and enqueue operation.
1111 	 * The application should not modify this field.
1112 	 */
1113 	union {
1114 #endif
1115 		struct rte_mbuf *mbufs[0];
1116 		void *ptrs[0];
1117 		uint64_t u64s[0];
1118 #ifndef __cplusplus
1119 	} __rte_aligned(16);
1120 #endif
1121 	/**< Start of the vector array union. Depending upon the event type the
1122 	 * vector array can be an array of mbufs or pointers or opaque u64
1123 	 * values.
1124 	 */
1125 } __rte_aligned(16);
1126 
1127 /* Scheduler type definitions */
1128 #define RTE_SCHED_TYPE_ORDERED          0
1129 /**< Ordered scheduling
1130  *
1131  * Events from an ordered flow of an event queue can be scheduled to multiple
1132  * ports for concurrent processing while maintaining the original event order.
1133  * This scheme enables the user to achieve high single flow throughput by
1134  * avoiding SW synchronization for ordering between ports which bound to cores.
1135  *
1136  * The source flow ordering from an event queue is maintained when events are
1137  * enqueued to their destination queue within the same ordered flow context.
1138  * An event port holds the context until application call
1139  * rte_event_dequeue_burst() from the same port, which implicitly releases
1140  * the context.
1141  * User may allow the scheduler to release the context earlier than that
1142  * by invoking rte_event_enqueue_burst() with RTE_EVENT_OP_RELEASE operation.
1143  *
1144  * Events from the source queue appear in their original order when dequeued
1145  * from a destination queue.
1146  * Event ordering is based on the received event(s), but also other
1147  * (newly allocated or stored) events are ordered when enqueued within the same
1148  * ordered context. Events not enqueued (e.g. released or stored) within the
1149  * context are  considered missing from reordering and are skipped at this time
1150  * (but can be ordered again within another context).
1151  *
1152  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
1153  */
1154 
1155 #define RTE_SCHED_TYPE_ATOMIC           1
1156 /**< Atomic scheduling
1157  *
1158  * Events from an atomic flow of an event queue can be scheduled only to a
1159  * single port at a time. The port is guaranteed to have exclusive (atomic)
1160  * access to the associated flow context, which enables the user to avoid SW
1161  * synchronization. Atomic flows also help to maintain event ordering
1162  * since only one port at a time can process events from a flow of an
1163  * event queue.
1164  *
1165  * The atomic queue synchronization context is dedicated to the port until
1166  * application call rte_event_dequeue_burst() from the same port,
1167  * which implicitly releases the context. User may allow the scheduler to
1168  * release the context earlier than that by invoking rte_event_enqueue_burst()
1169  * with RTE_EVENT_OP_RELEASE operation.
1170  *
1171  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
1172  */
1173 
1174 #define RTE_SCHED_TYPE_PARALLEL         2
1175 /**< Parallel scheduling
1176  *
1177  * The scheduler performs priority scheduling, load balancing, etc. functions
1178  * but does not provide additional event synchronization or ordering.
1179  * It is free to schedule events from a single parallel flow of an event queue
1180  * to multiple events ports for concurrent processing.
1181  * The application is responsible for flow context synchronization and
1182  * event ordering (SW synchronization).
1183  *
1184  * @see rte_event_queue_setup(), rte_event_dequeue_burst()
1185  */
1186 
1187 /* Event types to classify the event source */
1188 #define RTE_EVENT_TYPE_ETHDEV           0x0
1189 /**< The event generated from ethdev subsystem */
1190 #define RTE_EVENT_TYPE_CRYPTODEV        0x1
1191 /**< The event generated from crypodev subsystem */
1192 #define RTE_EVENT_TYPE_TIMER		0x2
1193 /**< The event generated from event timer adapter */
1194 #define RTE_EVENT_TYPE_CPU              0x3
1195 /**< The event generated from cpu for pipelining.
1196  * Application may use *sub_event_type* to further classify the event
1197  */
1198 #define RTE_EVENT_TYPE_ETH_RX_ADAPTER   0x4
1199 /**< The event generated from event eth Rx adapter */
1200 #define RTE_EVENT_TYPE_VECTOR           0x8
1201 /**< Indicates that event is a vector.
1202  * All vector event types should be a logical OR of EVENT_TYPE_VECTOR.
1203  * This simplifies the pipeline design as one can split processing the events
1204  * between vector events and normal event across event types.
1205  * Example:
1206  *	if (ev.event_type & RTE_EVENT_TYPE_VECTOR) {
1207  *		// Classify and handle vector event.
1208  *	} else {
1209  *		// Classify and handle event.
1210  *	}
1211  */
1212 #define RTE_EVENT_TYPE_ETHDEV_VECTOR                                           \
1213 	(RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_ETHDEV)
1214 /**< The event vector generated from ethdev subsystem */
1215 #define RTE_EVENT_TYPE_CPU_VECTOR (RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_CPU)
1216 /**< The event vector generated from cpu for pipelining. */
1217 #define RTE_EVENT_TYPE_ETH_RX_ADAPTER_VECTOR                                   \
1218 	(RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_ETH_RX_ADAPTER)
1219 /**< The event vector generated from eth Rx adapter. */
1220 #define RTE_EVENT_TYPE_CRYPTODEV_VECTOR                                        \
1221 	(RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_CRYPTODEV)
1222 /**< The event vector generated from cryptodev adapter. */
1223 
1224 #define RTE_EVENT_TYPE_MAX              0x10
1225 /**< Maximum number of event types */
1226 
1227 /* Event enqueue operations */
1228 #define RTE_EVENT_OP_NEW                0
1229 /**< The event producers use this operation to inject a new event to the
1230  * event device.
1231  */
1232 #define RTE_EVENT_OP_FORWARD            1
1233 /**< The CPU use this operation to forward the event to different event queue or
1234  * change to new application specific flow or schedule type to enable
1235  * pipelining.
1236  *
1237  * This operation must only be enqueued to the same port that the
1238  * event to be forwarded was dequeued from.
1239  */
1240 #define RTE_EVENT_OP_RELEASE            2
1241 /**< Release the flow context associated with the schedule type.
1242  *
1243  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ATOMIC*
1244  * then this function hints the scheduler that the user has completed critical
1245  * section processing in the current atomic context.
1246  * The scheduler is now allowed to schedule events from the same flow from
1247  * an event queue to another port. However, the context may be still held
1248  * until the next rte_event_dequeue_burst() call, this call allows but does not
1249  * force the scheduler to release the context early.
1250  *
1251  * Early atomic context release may increase parallelism and thus system
1252  * performance, but the user needs to design carefully the split into critical
1253  * vs non-critical sections.
1254  *
1255  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ORDERED*
1256  * then this function hints the scheduler that the user has done all that need
1257  * to maintain event order in the current ordered context.
1258  * The scheduler is allowed to release the ordered context of this port and
1259  * avoid reordering any following enqueues.
1260  *
1261  * Early ordered context release may increase parallelism and thus system
1262  * performance.
1263  *
1264  * If current flow's scheduler type method is *RTE_SCHED_TYPE_PARALLEL*
1265  * or no scheduling context is held then this function may be an NOOP,
1266  * depending on the implementation.
1267  *
1268  * This operation must only be enqueued to the same port that the
1269  * event to be released was dequeued from.
1270  */
1271 
1272 /**
1273  * The generic *rte_event* structure to hold the event attributes
1274  * for dequeue and enqueue operation
1275  */
1276 struct rte_event {
1277 	/** WORD0 */
1278 	union {
1279 		uint64_t event;
1280 		/** Event attributes for dequeue or enqueue operation */
1281 		struct {
1282 			uint32_t flow_id:20;
1283 			/**< Targeted flow identifier for the enqueue and
1284 			 * dequeue operation.
1285 			 * The value must be in the range of
1286 			 * [0, nb_event_queue_flows - 1] which
1287 			 * previously supplied to rte_event_dev_configure().
1288 			 */
1289 			uint32_t sub_event_type:8;
1290 			/**< Sub-event types based on the event source.
1291 			 * @see RTE_EVENT_TYPE_CPU
1292 			 */
1293 			uint32_t event_type:4;
1294 			/**< Event type to classify the event source.
1295 			 * @see RTE_EVENT_TYPE_ETHDEV, (RTE_EVENT_TYPE_*)
1296 			 */
1297 			uint8_t op:2;
1298 			/**< The type of event enqueue operation - new/forward/
1299 			 * etc.This field is not preserved across an instance
1300 			 * and is undefined on dequeue.
1301 			 * @see RTE_EVENT_OP_NEW, (RTE_EVENT_OP_*)
1302 			 */
1303 			uint8_t rsvd:4;
1304 			/**< Reserved for future use */
1305 			uint8_t sched_type:2;
1306 			/**< Scheduler synchronization type (RTE_SCHED_TYPE_*)
1307 			 * associated with flow id on a given event queue
1308 			 * for the enqueue and dequeue operation.
1309 			 */
1310 			uint8_t queue_id;
1311 			/**< Targeted event queue identifier for the enqueue or
1312 			 * dequeue operation.
1313 			 * The value must be in the range of
1314 			 * [0, nb_event_queues - 1] which previously supplied to
1315 			 * rte_event_dev_configure().
1316 			 */
1317 			uint8_t priority;
1318 			/**< Event priority relative to other events in the
1319 			 * event queue. The requested priority should in the
1320 			 * range of  [RTE_EVENT_DEV_PRIORITY_HIGHEST,
1321 			 * RTE_EVENT_DEV_PRIORITY_LOWEST].
1322 			 * The implementation shall normalize the requested
1323 			 * priority to supported priority value.
1324 			 * Valid when the device has
1325 			 * RTE_EVENT_DEV_CAP_EVENT_QOS capability.
1326 			 */
1327 			uint8_t impl_opaque;
1328 			/**< Implementation specific opaque value.
1329 			 * An implementation may use this field to hold
1330 			 * implementation specific value to share between
1331 			 * dequeue and enqueue operation.
1332 			 * The application should not modify this field.
1333 			 */
1334 		};
1335 	};
1336 	/** WORD1 */
1337 	union {
1338 		uint64_t u64;
1339 		/**< Opaque 64-bit value */
1340 		void *event_ptr;
1341 		/**< Opaque event pointer */
1342 		struct rte_mbuf *mbuf;
1343 		/**< mbuf pointer if dequeued event is associated with mbuf */
1344 		struct rte_event_vector *vec;
1345 		/**< Event vector pointer. */
1346 	};
1347 };
1348 
1349 /* Ethdev Rx adapter capability bitmap flags */
1350 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT	0x1
1351 /**< This flag is sent when the packet transfer mechanism is in HW.
1352  * Ethdev can send packets to the event device using internal event port.
1353  */
1354 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ	0x2
1355 /**< Adapter supports multiple event queues per ethdev. Every ethdev
1356  * Rx queue can be connected to a unique event queue.
1357  */
1358 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID	0x4
1359 /**< The application can override the adapter generated flow ID in the
1360  * event. This flow ID can be specified when adding an ethdev Rx queue
1361  * to the adapter using the ev.flow_id member.
1362  * @see struct rte_event_eth_rx_adapter_queue_conf::ev
1363  * @see struct rte_event_eth_rx_adapter_queue_conf::rx_queue_flags
1364  */
1365 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_EVENT_VECTOR	0x8
1366 /**< Adapter supports event vectorization per ethdev. */
1367 
1368 /**
1369  * Retrieve the event device's ethdev Rx adapter capabilities for the
1370  * specified ethernet port
1371  *
1372  * @param dev_id
1373  *   The identifier of the device.
1374  *
1375  * @param eth_port_id
1376  *   The identifier of the ethernet device.
1377  *
1378  * @param[out] caps
1379  *   A pointer to memory filled with Rx event adapter capabilities.
1380  *
1381  * @return
1382  *   - 0: Success, driver provides Rx event adapter capabilities for the
1383  *	ethernet device.
1384  *   - <0: Error code returned by the driver function.
1385  */
1386 int
1387 rte_event_eth_rx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
1388 				uint32_t *caps);
1389 
1390 #define RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT (1ULL << 0)
1391 /**< This flag is set when the timer mechanism is in HW. */
1392 
1393 #define RTE_EVENT_TIMER_ADAPTER_CAP_PERIODIC      (1ULL << 1)
1394 /**< This flag is set if periodic mode is supported. */
1395 
1396 /**
1397  * Retrieve the event device's timer adapter capabilities.
1398  *
1399  * @param dev_id
1400  *   The identifier of the device.
1401  *
1402  * @param[out] caps
1403  *   A pointer to memory to be filled with event timer adapter capabilities.
1404  *
1405  * @return
1406  *   - 0: Success, driver provided event timer adapter capabilities.
1407  *   - <0: Error code returned by the driver function.
1408  */
1409 int
1410 rte_event_timer_adapter_caps_get(uint8_t dev_id, uint32_t *caps);
1411 
1412 /* Crypto adapter capability bitmap flag */
1413 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW   0x1
1414 /**< Flag indicates HW is capable of generating events in
1415  * RTE_EVENT_OP_NEW enqueue operation. Cryptodev will send
1416  * packets to the event device as new events using an internal
1417  * event port.
1418  */
1419 
1420 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD   0x2
1421 /**< Flag indicates HW is capable of generating events in
1422  * RTE_EVENT_OP_FORWARD enqueue operation. Cryptodev will send
1423  * packets to the event device as forwarded event using an
1424  * internal event port.
1425  */
1426 
1427 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND  0x4
1428 /**< Flag indicates HW is capable of mapping crypto queue pair to
1429  * event queue.
1430  */
1431 
1432 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA   0x8
1433 /**< Flag indicates HW/SW supports a mechanism to store and retrieve
1434  * the private data information along with the crypto session.
1435  */
1436 
1437 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_EVENT_VECTOR   0x10
1438 /**< Flag indicates HW is capable of aggregating processed
1439  * crypto operations into rte_event_vector.
1440  */
1441 
1442 /**
1443  * Retrieve the event device's crypto adapter capabilities for the
1444  * specified cryptodev device
1445  *
1446  * @param dev_id
1447  *   The identifier of the device.
1448  *
1449  * @param cdev_id
1450  *   The identifier of the cryptodev device.
1451  *
1452  * @param[out] caps
1453  *   A pointer to memory filled with event adapter capabilities.
1454  *   It is expected to be pre-allocated & initialized by caller.
1455  *
1456  * @return
1457  *   - 0: Success, driver provides event adapter capabilities for the
1458  *     cryptodev device.
1459  *   - <0: Error code returned by the driver function.
1460  */
1461 int
1462 rte_event_crypto_adapter_caps_get(uint8_t dev_id, uint8_t cdev_id,
1463 				  uint32_t *caps);
1464 
1465 /* Ethdev Tx adapter capability bitmap flags */
1466 #define RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT	0x1
1467 /**< This flag is sent when the PMD supports a packet transmit callback
1468  */
1469 #define RTE_EVENT_ETH_TX_ADAPTER_CAP_EVENT_VECTOR	0x2
1470 /**< Indicates that the Tx adapter is capable of handling event vector of
1471  * mbufs.
1472  */
1473 
1474 /**
1475  * Retrieve the event device's eth Tx adapter capabilities
1476  *
1477  * @param dev_id
1478  *   The identifier of the device.
1479  *
1480  * @param eth_port_id
1481  *   The identifier of the ethernet device.
1482  *
1483  * @param[out] caps
1484  *   A pointer to memory filled with eth Tx adapter capabilities.
1485  *
1486  * @return
1487  *   - 0: Success, driver provides eth Tx adapter capabilities.
1488  *   - <0: Error code returned by the driver function.
1489  */
1490 int
1491 rte_event_eth_tx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
1492 				uint32_t *caps);
1493 
1494 /**
1495  * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue_burst()
1496  *
1497  * If the device is configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT flag
1498  * then application can use this function to convert timeout value in
1499  * nanoseconds to implementations specific timeout value supplied in
1500  * rte_event_dequeue_burst()
1501  *
1502  * @param dev_id
1503  *   The identifier of the device.
1504  * @param ns
1505  *   Wait time in nanosecond
1506  * @param[out] timeout_ticks
1507  *   Value for the *timeout_ticks* parameter in rte_event_dequeue_burst()
1508  *
1509  * @return
1510  *  - 0 on success.
1511  *  - -ENOTSUP if the device doesn't support timeouts
1512  *  - -EINVAL if *dev_id* is invalid or *timeout_ticks* is NULL
1513  *  - other values < 0 on failure.
1514  *
1515  * @see rte_event_dequeue_burst(), RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1516  * @see rte_event_dev_configure()
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 int
1582 rte_event_port_link(uint8_t dev_id, uint8_t port_id,
1583 		    const uint8_t queues[], const uint8_t priorities[],
1584 		    uint16_t nb_links);
1585 
1586 /**
1587  * Unlink multiple source event queues supplied in *queues* from the destination
1588  * event port designated by its *port_id* on the event device designated
1589  * by its *dev_id*.
1590  *
1591  * The unlink call issues an async request to disable the event port *port_id*
1592  * from receiving events from the specified event queue *queue_id*.
1593  * Event queue(s) to event port unlink establishment can be changed at runtime
1594  * without re-configuring the device.
1595  *
1596  * @see rte_event_port_unlinks_in_progress() to poll for completed unlinks.
1597  *
1598  * @param dev_id
1599  *   The identifier of the device.
1600  *
1601  * @param port_id
1602  *   Event port identifier to select the destination port to unlink.
1603  *
1604  * @param queues
1605  *   Points to an array of *nb_unlinks* event queues to be unlinked
1606  *   from the event port.
1607  *   NULL value is allowed, in which case this function unlinks all the
1608  *   event queue(s) from the event port *port_id*.
1609  *
1610  * @param nb_unlinks
1611  *   The number of unlinks to establish. This parameter is ignored if queues is
1612  *   NULL.
1613  *
1614  * @return
1615  * The number of unlinks successfully requested. The return value can be less
1616  * than the value of the *nb_unlinks* parameter when the implementation has the
1617  * limitation on specific queue to port unlink establishment or
1618  * if invalid parameters are specified.
1619  * If the return value is less than *nb_unlinks*, the remaining queues at the
1620  * end of queues[] are not unlinked, and the caller has to take care of them.
1621  * If return value is less than *nb_unlinks* then implementation shall update
1622  * the rte_errno accordingly, Possible rte_errno values are
1623  * (EINVAL) Invalid parameter
1624  */
1625 int
1626 rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
1627 		      uint8_t queues[], uint16_t nb_unlinks);
1628 
1629 /**
1630  * Returns the number of unlinks in progress.
1631  *
1632  * This function provides the application with a method to detect when an
1633  * unlink has been completed by the implementation.
1634  *
1635  * @see rte_event_port_unlink() to issue unlink requests.
1636  *
1637  * @param dev_id
1638  *   The identifier of the device.
1639  *
1640  * @param port_id
1641  *   Event port identifier to select port to check for unlinks in progress.
1642  *
1643  * @return
1644  * The number of unlinks that are in progress. A return of zero indicates that
1645  * there are no outstanding unlink requests. A positive return value indicates
1646  * the number of unlinks that are in progress, but are not yet complete.
1647  * A negative return value indicates an error, -EINVAL indicates an invalid
1648  * parameter passed for *dev_id* or *port_id*.
1649  */
1650 int
1651 rte_event_port_unlinks_in_progress(uint8_t dev_id, uint8_t port_id);
1652 
1653 /**
1654  * Retrieve the list of source event queues and its associated service priority
1655  * linked to the destination event port designated by its *port_id*
1656  * on the event device designated by its *dev_id*.
1657  *
1658  * @param dev_id
1659  *   The identifier of the device.
1660  *
1661  * @param port_id
1662  *   Event port identifier.
1663  *
1664  * @param[out] queues
1665  *   Points to an array of *queues* for output.
1666  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1667  *   store the event queue(s) linked with event port *port_id*
1668  *
1669  * @param[out] priorities
1670  *   Points to an array of *priorities* for output.
1671  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1672  *   store the service priority associated with each event queue linked
1673  *
1674  * @return
1675  * The number of links established on the event port designated by its
1676  *  *port_id*.
1677  * - <0 on failure.
1678  */
1679 int
1680 rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
1681 			 uint8_t queues[], uint8_t priorities[]);
1682 
1683 /**
1684  * Retrieve the service ID of the event dev. If the adapter doesn't use
1685  * a rte_service function, this function returns -ESRCH.
1686  *
1687  * @param dev_id
1688  *   The identifier of the device.
1689  *
1690  * @param [out] service_id
1691  *   A pointer to a uint32_t, to be filled in with the service id.
1692  *
1693  * @return
1694  *   - 0: Success
1695  *   - <0: Error code on failure, if the event dev doesn't use a rte_service
1696  *   function, this function returns -ESRCH.
1697  */
1698 int
1699 rte_event_dev_service_id_get(uint8_t dev_id, uint32_t *service_id);
1700 
1701 /**
1702  * Dump internal information about *dev_id* to the FILE* provided in *f*.
1703  *
1704  * @param dev_id
1705  *   The identifier of the device.
1706  *
1707  * @param f
1708  *   A pointer to a file for output
1709  *
1710  * @return
1711  *   - 0: on success
1712  *   - <0: on failure.
1713  */
1714 int
1715 rte_event_dev_dump(uint8_t dev_id, FILE *f);
1716 
1717 /** Maximum name length for extended statistics counters */
1718 #define RTE_EVENT_DEV_XSTATS_NAME_SIZE 64
1719 
1720 /**
1721  * Selects the component of the eventdev to retrieve statistics from.
1722  */
1723 enum rte_event_dev_xstats_mode {
1724 	RTE_EVENT_DEV_XSTATS_DEVICE,
1725 	RTE_EVENT_DEV_XSTATS_PORT,
1726 	RTE_EVENT_DEV_XSTATS_QUEUE,
1727 };
1728 
1729 /**
1730  * A name-key lookup element for extended statistics.
1731  *
1732  * This structure is used to map between names and ID numbers
1733  * for extended ethdev statistics.
1734  */
1735 struct rte_event_dev_xstats_name {
1736 	char name[RTE_EVENT_DEV_XSTATS_NAME_SIZE];
1737 };
1738 
1739 /**
1740  * Retrieve names of extended statistics of an event device.
1741  *
1742  * @param dev_id
1743  *   The identifier of the event device.
1744  * @param mode
1745  *   The mode of statistics to retrieve. Choices include the device statistics,
1746  *   port statistics or queue statistics.
1747  * @param queue_port_id
1748  *   Used to specify the port or queue number in queue or port mode, and is
1749  *   ignored in device mode.
1750  * @param[out] xstats_names
1751  *   Block of memory to insert names into. Must be at least size in capacity.
1752  *   If set to NULL, function returns required capacity.
1753  * @param[out] ids
1754  *   Block of memory to insert ids into. Must be at least size in capacity.
1755  *   If set to NULL, function returns required capacity. The id values returned
1756  *   can be passed to *rte_event_dev_xstats_get* to select statistics.
1757  * @param size
1758  *   Capacity of xstats_names (number of names).
1759  * @return
1760  *   - positive value lower or equal to size: success. The return value
1761  *     is the number of entries filled in the stats table.
1762  *   - positive value higher than size: error, the given statistics table
1763  *     is too small. The return value corresponds to the size that should
1764  *     be given to succeed. The entries in the table are not valid and
1765  *     shall not be used by the caller.
1766  *   - negative value on error:
1767  *        -ENODEV for invalid *dev_id*
1768  *        -EINVAL for invalid mode, queue port or id parameters
1769  *        -ENOTSUP if the device doesn't support this function.
1770  */
1771 int
1772 rte_event_dev_xstats_names_get(uint8_t dev_id,
1773 			       enum rte_event_dev_xstats_mode mode,
1774 			       uint8_t queue_port_id,
1775 			       struct rte_event_dev_xstats_name *xstats_names,
1776 			       uint64_t *ids,
1777 			       unsigned int size);
1778 
1779 /**
1780  * Retrieve extended statistics of an event device.
1781  *
1782  * @param dev_id
1783  *   The identifier of the device.
1784  * @param mode
1785  *  The mode of statistics to retrieve. Choices include the device statistics,
1786  *  port statistics or queue statistics.
1787  * @param queue_port_id
1788  *   Used to specify the port or queue number in queue or port mode, and is
1789  *   ignored in device mode.
1790  * @param ids
1791  *   The id numbers of the stats to get. The ids can be got from the stat
1792  *   position in the stat list from rte_event_dev_get_xstats_names(), or
1793  *   by using rte_event_dev_xstats_by_name_get().
1794  * @param[out] values
1795  *   The values for each stats request by ID.
1796  * @param n
1797  *   The number of stats requested
1798  * @return
1799  *   - positive value: number of stat entries filled into the values array
1800  *   - negative value on error:
1801  *        -ENODEV for invalid *dev_id*
1802  *        -EINVAL for invalid mode, queue port or id parameters
1803  *        -ENOTSUP if the device doesn't support this function.
1804  */
1805 int
1806 rte_event_dev_xstats_get(uint8_t dev_id,
1807 			 enum rte_event_dev_xstats_mode mode,
1808 			 uint8_t queue_port_id,
1809 			 const uint64_t ids[],
1810 			 uint64_t values[], unsigned int n);
1811 
1812 /**
1813  * Retrieve the value of a single stat by requesting it by name.
1814  *
1815  * @param dev_id
1816  *   The identifier of the device
1817  * @param name
1818  *   The stat name to retrieve
1819  * @param[out] id
1820  *   If non-NULL, the numerical id of the stat will be returned, so that further
1821  *   requests for the stat can be got using rte_event_dev_xstats_get, which will
1822  *   be faster as it doesn't need to scan a list of names for the stat.
1823  *   If the stat cannot be found, the id returned will be (unsigned)-1.
1824  * @return
1825  *   - positive value or zero: the stat value
1826  *   - negative value: -EINVAL if stat not found, -ENOTSUP if not supported.
1827  */
1828 uint64_t
1829 rte_event_dev_xstats_by_name_get(uint8_t dev_id, const char *name,
1830 				 uint64_t *id);
1831 
1832 /**
1833  * Reset the values of the xstats of the selected component in the device.
1834  *
1835  * @param dev_id
1836  *   The identifier of the device
1837  * @param mode
1838  *   The mode of the statistics to reset. Choose from device, queue or port.
1839  * @param queue_port_id
1840  *   The queue or port to reset. 0 and positive values select ports and queues,
1841  *   while -1 indicates all ports or queues.
1842  * @param ids
1843  *   Selects specific statistics to be reset. When NULL, all statistics selected
1844  *   by *mode* will be reset. If non-NULL, must point to array of at least
1845  *   *nb_ids* size.
1846  * @param nb_ids
1847  *   The number of ids available from the *ids* array. Ignored when ids is NULL.
1848  * @return
1849  *   - zero: successfully reset the statistics to zero
1850  *   - negative value: -EINVAL invalid parameters, -ENOTSUP if not supported.
1851  */
1852 int
1853 rte_event_dev_xstats_reset(uint8_t dev_id,
1854 			   enum rte_event_dev_xstats_mode mode,
1855 			   int16_t queue_port_id,
1856 			   const uint64_t ids[],
1857 			   uint32_t nb_ids);
1858 
1859 /**
1860  * Trigger the eventdev self test.
1861  *
1862  * @param dev_id
1863  *   The identifier of the device
1864  * @return
1865  *   - 0: Selftest successful
1866  *   - -ENOTSUP if the device doesn't support selftest
1867  *   - other values < 0 on failure.
1868  */
1869 int rte_event_dev_selftest(uint8_t dev_id);
1870 
1871 /**
1872  * Get the memory required per event vector based on the number of elements per
1873  * vector.
1874  * This should be used to create the mempool that holds the event vectors.
1875  *
1876  * @param name
1877  *   The name of the vector pool.
1878  * @param n
1879  *   The number of elements in the mbuf pool.
1880  * @param cache_size
1881  *   Size of the per-core object cache. See rte_mempool_create() for
1882  *   details.
1883  * @param nb_elem
1884  *   The number of elements that a single event vector should be able to hold.
1885  * @param socket_id
1886  *   The socket identifier where the memory should be allocated. The
1887  *   value can be *SOCKET_ID_ANY* if there is no NUMA constraint for the
1888  *   reserved zone
1889  *
1890  * @return
1891  *   The pointer to the newly allocated mempool, on success. NULL on error
1892  *   with rte_errno set appropriately. Possible rte_errno values include:
1893  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
1894  *    - E_RTE_SECONDARY - function was called from a secondary process instance
1895  *    - EINVAL - cache size provided is too large, or priv_size is not aligned.
1896  *    - ENOSPC - the maximum number of memzones has already been allocated
1897  *    - EEXIST - a memzone with the same name already exists
1898  *    - ENOMEM - no appropriate memory area found in which to create memzone
1899  *    - ENAMETOOLONG - mempool name requested is too long.
1900  */
1901 struct rte_mempool *
1902 rte_event_vector_pool_create(const char *name, unsigned int n,
1903 			     unsigned int cache_size, uint16_t nb_elem,
1904 			     int socket_id);
1905 
1906 #include <rte_eventdev_core.h>
1907 
1908 static __rte_always_inline uint16_t
1909 __rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1910 			  const struct rte_event ev[], uint16_t nb_events,
1911 			  const event_enqueue_burst_t fn)
1912 {
1913 	const struct rte_event_fp_ops *fp_ops;
1914 	void *port;
1915 
1916 	fp_ops = &rte_event_fp_ops[dev_id];
1917 	port = fp_ops->data[port_id];
1918 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
1919 	if (dev_id >= RTE_EVENT_MAX_DEVS ||
1920 	    port_id >= RTE_EVENT_MAX_PORTS_PER_DEV) {
1921 		rte_errno = EINVAL;
1922 		return 0;
1923 	}
1924 
1925 	if (port == NULL) {
1926 		rte_errno = EINVAL;
1927 		return 0;
1928 	}
1929 #endif
1930 	rte_eventdev_trace_enq_burst(dev_id, port_id, ev, nb_events, (void *)fn);
1931 	/*
1932 	 * Allow zero cost non burst mode routine invocation if application
1933 	 * requests nb_events as const one
1934 	 */
1935 	if (nb_events == 1)
1936 		return (fp_ops->enqueue)(port, ev);
1937 	else
1938 		return fn(port, ev, nb_events);
1939 }
1940 
1941 /**
1942  * Enqueue a burst of events objects or an event object supplied in *rte_event*
1943  * structure on an  event device designated by its *dev_id* through the event
1944  * port specified by *port_id*. Each event object specifies the event queue on
1945  * which it will be enqueued.
1946  *
1947  * The *nb_events* parameter is the number of event objects to enqueue which are
1948  * supplied in the *ev* array of *rte_event* structure.
1949  *
1950  * Event operations RTE_EVENT_OP_FORWARD and RTE_EVENT_OP_RELEASE must only be
1951  * enqueued to the same port that their associated events were dequeued from.
1952  *
1953  * The rte_event_enqueue_burst() function returns the number of
1954  * events objects it actually enqueued. A return value equal to *nb_events*
1955  * means that all event objects have been enqueued.
1956  *
1957  * @param dev_id
1958  *   The identifier of the device.
1959  * @param port_id
1960  *   The identifier of the event port.
1961  * @param ev
1962  *   Points to an array of *nb_events* objects of type *rte_event* structure
1963  *   which contain the event object enqueue operations to be processed.
1964  * @param nb_events
1965  *   The number of event objects to enqueue, typically number of
1966  *   rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
1967  *   available for this port.
1968  *
1969  * @return
1970  *   The number of event objects actually enqueued on the event device. The
1971  *   return value can be less than the value of the *nb_events* parameter when
1972  *   the event devices queue is full or if invalid parameters are specified in a
1973  *   *rte_event*. If the return value is less than *nb_events*, the remaining
1974  *   events at the end of ev[] are not consumed and the caller has to take care
1975  *   of them, and rte_errno is set accordingly. Possible errno values include:
1976  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
1977  *              ID is invalid, or an event's sched type doesn't match the
1978  *              capabilities of the destination queue.
1979  *   - ENOSPC   The event port was backpressured and unable to enqueue
1980  *              one or more events. This error code is only applicable to
1981  *              closed systems.
1982  * @see rte_event_port_attr_get(), RTE_EVENT_PORT_ATTR_ENQ_DEPTH
1983  */
1984 static inline uint16_t
1985 rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1986 			const struct rte_event ev[], uint16_t nb_events)
1987 {
1988 	const struct rte_event_fp_ops *fp_ops;
1989 
1990 	fp_ops = &rte_event_fp_ops[dev_id];
1991 	return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
1992 					 fp_ops->enqueue_burst);
1993 }
1994 
1995 /**
1996  * Enqueue a burst of events objects of operation type *RTE_EVENT_OP_NEW* on
1997  * an event device designated by its *dev_id* through the event port specified
1998  * by *port_id*.
1999  *
2000  * Provides the same functionality as rte_event_enqueue_burst(), expect that
2001  * application can use this API when the all objects in the burst contains
2002  * the enqueue operation of the type *RTE_EVENT_OP_NEW*. This specialized
2003  * function can provide the additional hint to the PMD and optimize if possible.
2004  *
2005  * The rte_event_enqueue_new_burst() result is undefined if the enqueue burst
2006  * has event object of operation type != RTE_EVENT_OP_NEW.
2007  *
2008  * @param dev_id
2009  *   The identifier of the device.
2010  * @param port_id
2011  *   The identifier of the event port.
2012  * @param ev
2013  *   Points to an array of *nb_events* objects of type *rte_event* structure
2014  *   which contain the event object enqueue operations to be processed.
2015  * @param nb_events
2016  *   The number of event objects to enqueue, typically number of
2017  *   rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
2018  *   available for this port.
2019  *
2020  * @return
2021  *   The number of event objects actually enqueued on the event device. The
2022  *   return value can be less than the value of the *nb_events* parameter when
2023  *   the event devices queue is full or if invalid parameters are specified in a
2024  *   *rte_event*. If the return value is less than *nb_events*, the remaining
2025  *   events at the end of ev[] are not consumed and the caller has to take care
2026  *   of them, and rte_errno is set accordingly. Possible errno values include:
2027  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
2028  *              ID is invalid, or an event's sched type doesn't match the
2029  *              capabilities of the destination queue.
2030  *   - ENOSPC   The event port was backpressured and unable to enqueue
2031  *              one or more events. This error code is only applicable to
2032  *              closed systems.
2033  * @see rte_event_port_attr_get(), RTE_EVENT_PORT_ATTR_ENQ_DEPTH
2034  * @see rte_event_enqueue_burst()
2035  */
2036 static inline uint16_t
2037 rte_event_enqueue_new_burst(uint8_t dev_id, uint8_t port_id,
2038 			    const struct rte_event ev[], uint16_t nb_events)
2039 {
2040 	const struct rte_event_fp_ops *fp_ops;
2041 
2042 	fp_ops = &rte_event_fp_ops[dev_id];
2043 	return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
2044 					 fp_ops->enqueue_new_burst);
2045 }
2046 
2047 /**
2048  * Enqueue a burst of events objects of operation type *RTE_EVENT_OP_FORWARD*
2049  * on an event device designated by its *dev_id* through the event port
2050  * specified by *port_id*.
2051  *
2052  * Provides the same functionality as rte_event_enqueue_burst(), expect that
2053  * application can use this API when the all objects in the burst contains
2054  * the enqueue operation of the type *RTE_EVENT_OP_FORWARD*. This specialized
2055  * function can provide the additional hint to the PMD and optimize if possible.
2056  *
2057  * The rte_event_enqueue_new_burst() result is undefined if the enqueue burst
2058  * has event object of operation type != RTE_EVENT_OP_FORWARD.
2059  *
2060  * @param dev_id
2061  *   The identifier of the device.
2062  * @param port_id
2063  *   The identifier of the event port.
2064  * @param ev
2065  *   Points to an array of *nb_events* objects of type *rte_event* structure
2066  *   which contain the event object enqueue operations to be processed.
2067  * @param nb_events
2068  *   The number of event objects to enqueue, typically number of
2069  *   rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
2070  *   available for this port.
2071  *
2072  * @return
2073  *   The number of event objects actually enqueued on the event device. The
2074  *   return value can be less than the value of the *nb_events* parameter when
2075  *   the event devices queue is full or if invalid parameters are specified in a
2076  *   *rte_event*. If the return value is less than *nb_events*, the remaining
2077  *   events at the end of ev[] are not consumed and the caller has to take care
2078  *   of them, and rte_errno is set accordingly. Possible errno values include:
2079  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
2080  *              ID is invalid, or an event's sched type doesn't match the
2081  *              capabilities of the destination queue.
2082  *   - ENOSPC   The event port was backpressured and unable to enqueue
2083  *              one or more events. This error code is only applicable to
2084  *              closed systems.
2085  * @see rte_event_port_attr_get(), RTE_EVENT_PORT_ATTR_ENQ_DEPTH
2086  * @see rte_event_enqueue_burst()
2087  */
2088 static inline uint16_t
2089 rte_event_enqueue_forward_burst(uint8_t dev_id, uint8_t port_id,
2090 				const struct rte_event ev[], uint16_t nb_events)
2091 {
2092 	const struct rte_event_fp_ops *fp_ops;
2093 
2094 	fp_ops = &rte_event_fp_ops[dev_id];
2095 	return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
2096 					 fp_ops->enqueue_forward_burst);
2097 }
2098 
2099 /**
2100  * Dequeue a burst of events objects or an event object from the event port
2101  * designated by its *event_port_id*, on an event device designated
2102  * by its *dev_id*.
2103  *
2104  * rte_event_dequeue_burst() does not dictate the specifics of scheduling
2105  * algorithm as each eventdev driver may have different criteria to schedule
2106  * an event. However, in general, from an application perspective scheduler may
2107  * use the following scheme to dispatch an event to the port.
2108  *
2109  * 1) Selection of event queue based on
2110  *   a) The list of event queues are linked to the event port.
2111  *   b) If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then event
2112  *   queue selection from list is based on event queue priority relative to
2113  *   other event queue supplied as *priority* in rte_event_queue_setup()
2114  *   c) If the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability then event
2115  *   queue selection from the list is based on event priority supplied as
2116  *   *priority* in rte_event_enqueue_burst()
2117  * 2) Selection of event
2118  *   a) The number of flows available in selected event queue.
2119  *   b) Schedule type method associated with the event
2120  *
2121  * The *nb_events* parameter is the maximum number of event objects to dequeue
2122  * which are returned in the *ev* array of *rte_event* structure.
2123  *
2124  * The rte_event_dequeue_burst() function returns the number of events objects
2125  * it actually dequeued. A return value equal to *nb_events* means that all
2126  * event objects have been dequeued.
2127  *
2128  * The number of events dequeued is the number of scheduler contexts held by
2129  * this port. These contexts are automatically released in the next
2130  * rte_event_dequeue_burst() invocation if the port supports implicit
2131  * releases, or invoking rte_event_enqueue_burst() with RTE_EVENT_OP_RELEASE
2132  * operation can be used to release the contexts early.
2133  *
2134  * Event operations RTE_EVENT_OP_FORWARD and RTE_EVENT_OP_RELEASE must only be
2135  * enqueued to the same port that their associated events were dequeued from.
2136  *
2137  * @param dev_id
2138  *   The identifier of the device.
2139  * @param port_id
2140  *   The identifier of the event port.
2141  * @param[out] ev
2142  *   Points to an array of *nb_events* objects of type *rte_event* structure
2143  *   for output to be populated with the dequeued event objects.
2144  * @param nb_events
2145  *   The maximum number of event objects to dequeue, typically number of
2146  *   rte_event_port_dequeue_depth() available for this port.
2147  *
2148  * @param timeout_ticks
2149  *   - 0 no-wait, returns immediately if there is no event.
2150  *   - >0 wait for the event, if the device is configured with
2151  *   RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT then this function will wait until
2152  *   at least one event is available or *timeout_ticks* time.
2153  *   if the device is not configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
2154  *   then this function will wait until the event available or
2155  *   *dequeue_timeout_ns* ns which was previously supplied to
2156  *   rte_event_dev_configure()
2157  *
2158  * @return
2159  * The number of event objects actually dequeued from the port. The return
2160  * value can be less than the value of the *nb_events* parameter when the
2161  * event port's queue is not full.
2162  *
2163  * @see rte_event_port_dequeue_depth()
2164  */
2165 static inline uint16_t
2166 rte_event_dequeue_burst(uint8_t dev_id, uint8_t port_id, struct rte_event ev[],
2167 			uint16_t nb_events, uint64_t timeout_ticks)
2168 {
2169 	const struct rte_event_fp_ops *fp_ops;
2170 	void *port;
2171 
2172 	fp_ops = &rte_event_fp_ops[dev_id];
2173 	port = fp_ops->data[port_id];
2174 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
2175 	if (dev_id >= RTE_EVENT_MAX_DEVS ||
2176 	    port_id >= RTE_EVENT_MAX_PORTS_PER_DEV) {
2177 		rte_errno = EINVAL;
2178 		return 0;
2179 	}
2180 
2181 	if (port == NULL) {
2182 		rte_errno = EINVAL;
2183 		return 0;
2184 	}
2185 #endif
2186 	rte_eventdev_trace_deq_burst(dev_id, port_id, ev, nb_events);
2187 	/*
2188 	 * Allow zero cost non burst mode routine invocation if application
2189 	 * requests nb_events as const one
2190 	 */
2191 	if (nb_events == 1)
2192 		return (fp_ops->dequeue)(port, ev, timeout_ticks);
2193 	else
2194 		return (fp_ops->dequeue_burst)(port, ev, nb_events,
2195 					       timeout_ticks);
2196 }
2197 
2198 #define RTE_EVENT_DEV_MAINT_OP_FLUSH          (1 << 0)
2199 /**< Force an immediately flush of any buffered events in the port,
2200  * potentially at the cost of additional overhead.
2201  *
2202  * @see rte_event_maintain()
2203  */
2204 
2205 /**
2206  * Maintain an event device.
2207  *
2208  * This function is only relevant for event devices which do not have
2209  * the @ref RTE_EVENT_DEV_CAP_MAINTENANCE_FREE flag set. Such devices
2210  * require an application thread using a particular port to
2211  * periodically call rte_event_maintain() on that port during periods
2212  * which it is neither attempting to enqueue events to nor dequeue
2213  * events from the port. rte_event_maintain() is a low-overhead
2214  * function and should be called at a high rate (e.g., in the
2215  * application's poll loop).
2216  *
2217  * No port may be left unmaintained.
2218  *
2219  * At the application thread's convenience, rte_event_maintain() may
2220  * (but is not required to) be called even during periods when enqueue
2221  * or dequeue functions are being called, at the cost of a slight
2222  * increase in overhead.
2223  *
2224  * rte_event_maintain() may be called on event devices which have set
2225  * @ref RTE_EVENT_DEV_CAP_MAINTENANCE_FREE, in which case it is a
2226  * no-operation.
2227  *
2228  * @param dev_id
2229  *   The identifier of the device.
2230  * @param port_id
2231  *   The identifier of the event port.
2232  * @param op
2233  *   0, or @ref RTE_EVENT_DEV_MAINT_OP_FLUSH.
2234  * @return
2235  *  - 0 on success.
2236  *  - -EINVAL if *dev_id*,  *port_id*, or *op* is invalid.
2237  *
2238  * @see RTE_EVENT_DEV_CAP_MAINTENANCE_FREE
2239  */
2240 __rte_experimental
2241 static inline int
2242 rte_event_maintain(uint8_t dev_id, uint8_t port_id, int op)
2243 {
2244 	const struct rte_event_fp_ops *fp_ops;
2245 	void *port;
2246 
2247 	fp_ops = &rte_event_fp_ops[dev_id];
2248 	port = fp_ops->data[port_id];
2249 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
2250 	if (dev_id >= RTE_EVENT_MAX_DEVS ||
2251 	    port_id >= RTE_EVENT_MAX_PORTS_PER_DEV)
2252 		return -EINVAL;
2253 
2254 	if (port == NULL)
2255 		return -EINVAL;
2256 
2257 	if (op & (~RTE_EVENT_DEV_MAINT_OP_FLUSH))
2258 		return -EINVAL;
2259 #endif
2260 	rte_eventdev_trace_maintain(dev_id, port_id, op);
2261 
2262 	if (fp_ops->maintain != NULL)
2263 		fp_ops->maintain(port, op);
2264 
2265 	return 0;
2266 }
2267 
2268 #ifdef __cplusplus
2269 }
2270 #endif
2271 
2272 #endif /* _RTE_EVENTDEV_H_ */
2273