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