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