b20a6c688bedd902d532db02c88b1ad226d9594e
[dpdk.git] / lib / librte_eventdev / rte_eventdev.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright 2016 Cavium.
5  *   Copyright 2016 Intel Corporation.
6  *   Copyright 2016 NXP.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Cavium nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #ifndef _RTE_EVENTDEV_H_
36 #define _RTE_EVENTDEV_H_
37
38 /**
39  * @file
40  *
41  * RTE Event Device API
42  *
43  * In a polling model, lcores poll ethdev ports and associated rx queues
44  * directly to look for packet. In an event driven model, by contrast, lcores
45  * call the scheduler that selects packets for them based on programmer
46  * specified criteria. Eventdev library adds support for event driven
47  * programming model, which offer applications automatic multicore scaling,
48  * dynamic load balancing, pipelining, packet ingress order maintenance and
49  * synchronization services to simplify application packet processing.
50  *
51  * The Event Device API is composed of two parts:
52  *
53  * - The application-oriented Event API that includes functions to setup
54  *   an event device (configure it, setup its queues, ports and start it), to
55  *   establish the link between queues to port and to receive events, and so on.
56  *
57  * - The driver-oriented Event API that exports a function allowing
58  *   an event poll Mode Driver (PMD) to simultaneously register itself as
59  *   an event device driver.
60  *
61  * Event device components:
62  *
63  *                     +-----------------+
64  *                     | +-------------+ |
65  *        +-------+    | |    flow 0   | |
66  *        |Packet |    | +-------------+ |
67  *        |event  |    | +-------------+ |
68  *        |       |    | |    flow 1   | |port_link(port0, queue0)
69  *        +-------+    | +-------------+ |     |     +--------+
70  *        +-------+    | +-------------+ o-----v-----o        |dequeue +------+
71  *        |Crypto |    | |    flow n   | |           | event  +------->|Core 0|
72  *        |work   |    | +-------------+ o----+      | port 0 |        |      |
73  *        |done ev|    |  event queue 0  |    |      +--------+        +------+
74  *        +-------+    +-----------------+    |
75  *        +-------+                           |
76  *        |Timer  |    +-----------------+    |      +--------+
77  *        |expiry |    | +-------------+ |    +------o        |dequeue +------+
78  *        |event  |    | |    flow 0   | o-----------o event  +------->|Core 1|
79  *        +-------+    | +-------------+ |      +----o port 1 |        |      |
80  *       Event enqueue | +-------------+ |      |    +--------+        +------+
81  *     o-------------> | |    flow 1   | |      |
82  *        enqueue(     | +-------------+ |      |
83  *        queue_id,    |                 |      |    +--------+        +------+
84  *        flow_id,     | +-------------+ |      |    |        |dequeue |Core 2|
85  *        sched_type,  | |    flow n   | o-----------o event  +------->|      |
86  *        event_type,  | +-------------+ |      |    | port 2 |        +------+
87  *        subev_type,  |  event queue 1  |      |    +--------+
88  *        event)       +-----------------+      |    +--------+
89  *                                              |    |        |dequeue +------+
90  *        +-------+    +-----------------+      |    | event  +------->|Core n|
91  *        |Core   |    | +-------------+ o-----------o port n |        |      |
92  *        |(SW)   |    | |    flow 0   | |      |    +--------+        +--+---+
93  *        |event  |    | +-------------+ |      |                         |
94  *        +-------+    | +-------------+ |      |                         |
95  *            ^        | |    flow 1   | |      |                         |
96  *            |        | +-------------+ o------+                         |
97  *            |        | +-------------+ |                                |
98  *            |        | |    flow n   | |                                |
99  *            |        | +-------------+ |                                |
100  *            |        |  event queue n  |                                |
101  *            |        +-----------------+                                |
102  *            |                                                           |
103  *            +-----------------------------------------------------------+
104  *
105  * Event device: A hardware or software-based event scheduler.
106  *
107  * Event: A unit of scheduling that encapsulates a packet or other datatype
108  * like SW generated event from the CPU, Crypto work completion notification,
109  * Timer expiry event notification etc as well as metadata.
110  * The metadata includes flow ID, scheduling type, event priority, event_type,
111  * sub_event_type etc.
112  *
113  * Event queue: A queue containing events that are scheduled by the event dev.
114  * An event queue contains events of different flows associated with scheduling
115  * types, such as atomic, ordered, or parallel.
116  *
117  * Event port: An application's interface into the event dev for enqueue and
118  * dequeue operations. Each event port can be linked with one or more
119  * event queues for dequeue operations.
120  *
121  * By default, all the functions of the Event Device API exported by a PMD
122  * are lock-free functions which assume to not be invoked in parallel on
123  * different logical cores to work on the same target object. For instance,
124  * the dequeue function of a PMD cannot be invoked in parallel on two logical
125  * cores to operates on same  event port. Of course, this function
126  * can be invoked in parallel by different logical cores on different ports.
127  * It is the responsibility of the upper level application to enforce this rule.
128  *
129  * In all functions of the Event API, the Event device is
130  * designated by an integer >= 0 named the device identifier *dev_id*
131  *
132  * At the Event driver level, Event devices are represented by a generic
133  * data structure of type *rte_event_dev*.
134  *
135  * Event devices are dynamically registered during the PCI/SoC device probing
136  * phase performed at EAL initialization time.
137  * When an Event device is being probed, a *rte_event_dev* structure and
138  * a new device identifier are allocated for that device. Then, the
139  * event_dev_init() function supplied by the Event driver matching the probed
140  * device is invoked to properly initialize the device.
141  *
142  * The role of the device init function consists of resetting the hardware or
143  * software event driver implementations.
144  *
145  * If the device init operation is successful, the correspondence between
146  * the device identifier assigned to the new device and its associated
147  * *rte_event_dev* structure is effectively registered.
148  * Otherwise, both the *rte_event_dev* structure and the device identifier are
149  * freed.
150  *
151  * The functions exported by the application Event API to setup a device
152  * designated by its device identifier must be invoked in the following order:
153  *     - rte_event_dev_configure()
154  *     - rte_event_queue_setup()
155  *     - rte_event_port_setup()
156  *     - rte_event_port_link()
157  *     - rte_event_dev_start()
158  *
159  * Then, the application can invoke, in any order, the functions
160  * exported by the Event API to schedule events, dequeue events, enqueue events,
161  * change event queue(s) to event port [un]link establishment and so on.
162  *
163  * Application may use rte_event_[queue/port]_default_conf_get() to get the
164  * default configuration to set up an event queue or event port by
165  * overriding few default values.
166  *
167  * If the application wants to change the configuration (i.e. call
168  * rte_event_dev_configure(), rte_event_queue_setup(), or
169  * rte_event_port_setup()), it must call rte_event_dev_stop() first to stop the
170  * device and then do the reconfiguration before calling rte_event_dev_start()
171  * again. The schedule, enqueue and dequeue functions should not be invoked
172  * when the device is stopped.
173  *
174  * Finally, an application can close an Event device by invoking the
175  * rte_event_dev_close() function.
176  *
177  * Each function of the application Event API invokes a specific function
178  * of the PMD that controls the target device designated by its device
179  * identifier.
180  *
181  * For this purpose, all device-specific functions of an Event driver are
182  * supplied through a set of pointers contained in a generic structure of type
183  * *event_dev_ops*.
184  * The address of the *event_dev_ops* structure is stored in the *rte_event_dev*
185  * structure by the device init function of the Event driver, which is
186  * invoked during the PCI/SoC device probing phase, as explained earlier.
187  *
188  * In other words, each function of the Event API simply retrieves the
189  * *rte_event_dev* structure associated with the device identifier and
190  * performs an indirect invocation of the corresponding driver function
191  * supplied in the *event_dev_ops* structure of the *rte_event_dev* structure.
192  *
193  * For performance reasons, the address of the fast-path functions of the
194  * Event driver is not contained in the *event_dev_ops* structure.
195  * Instead, they are directly stored at the beginning of the *rte_event_dev*
196  * structure to avoid an extra indirect memory access during their invocation.
197  *
198  * RTE event device drivers do not use interrupts for enqueue or dequeue
199  * operation. Instead, Event drivers export Poll-Mode enqueue and dequeue
200  * functions to applications.
201  *
202  * The events are injected to event device through *enqueue* operation by
203  * event producers in the system. The typical event producers are ethdev
204  * subsystem for generating packet events, CPU(SW) for generating events based
205  * on different stages of application processing, cryptodev for generating
206  * crypto work completion notification etc
207  *
208  * The *dequeue* operation gets one or more events from the event ports.
209  * The application process the events and send to downstream event queue through
210  * rte_event_enqueue_burst() if it is an intermediate stage of event processing,
211  * on the final stage, the application may send to different subsystem like
212  * ethdev to send the packet/event on the wire using ethdev
213  * rte_eth_tx_burst() API.
214  *
215  * The point at which events are scheduled to ports depends on the device.
216  * For hardware devices, scheduling occurs asynchronously without any software
217  * intervention. Software schedulers can either be distributed
218  * (each worker thread schedules events to its own port) or centralized
219  * (a dedicated thread schedules to all ports). Distributed software schedulers
220  * perform the scheduling in rte_event_dequeue_burst(), whereas centralized
221  * scheduler logic is located in rte_event_schedule().
222  * The RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED capability flag is not set
223  * indicates the device is centralized and thus needs a dedicated scheduling
224  * thread that repeatedly calls rte_event_schedule().
225  *
226  * An event driven worker thread has following typical workflow on fastpath:
227  * \code{.c}
228  *      while (1) {
229  *              rte_event_dequeue_burst(...);
230  *              (event processing)
231  *              rte_event_enqueue_burst(...);
232  *      }
233  * \endcode
234  *
235  */
236
237 #ifdef __cplusplus
238 extern "C" {
239 #endif
240
241 #include <rte_common.h>
242 #include <rte_memory.h>
243 #include <rte_errno.h>
244
245 struct rte_mbuf; /* we just use mbuf pointers; no need to include rte_mbuf.h */
246
247 /* Event device capability bitmap flags */
248 #define RTE_EVENT_DEV_CAP_QUEUE_QOS           (1ULL << 0)
249 /**< Event scheduling prioritization is based on the priority associated with
250  *  each event queue.
251  *
252  *  @see rte_event_queue_setup()
253  */
254 #define RTE_EVENT_DEV_CAP_EVENT_QOS           (1ULL << 1)
255 /**< Event scheduling prioritization is based on the priority associated with
256  *  each event. Priority of each event is supplied in *rte_event* structure
257  *  on each enqueue operation.
258  *
259  *  @see rte_event_enqueue_burst()
260  */
261 #define RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED   (1ULL << 2)
262 /**< Event device operates in distributed scheduling mode.
263  * In distributed scheduling mode, event scheduling happens in HW or
264  * rte_event_dequeue_burst() or the combination of these two.
265  * If the flag is not set then eventdev is centralized and thus needs a
266  * dedicated scheduling thread that repeatedly calls rte_event_schedule().
267  *
268  * @see rte_event_schedule(), rte_event_dequeue_burst()
269  */
270 #define RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES     (1ULL << 3)
271 /**< Event device is capable of enqueuing events of any type to any queue.
272  * If this capability is not set, the queue only supports events of the
273  *  *RTE_EVENT_QUEUE_CFG_* type that it was created with.
274  *
275  * @see RTE_EVENT_QUEUE_CFG_* values
276  */
277 #define RTE_EVENT_DEV_CAP_BURST_MODE          (1ULL << 4)
278 /**< Event device is capable of operating in burst mode for enqueue(forward,
279  * release) and dequeue operation. If this capability is not set, application
280  * still uses the rte_event_dequeue_burst() and rte_event_enqueue_burst() but
281  * PMD accepts only one event at a time.
282  *
283  * @see rte_event_dequeue_burst() rte_event_enqueue_burst()
284  */
285
286 /* Event device priority levels */
287 #define RTE_EVENT_DEV_PRIORITY_HIGHEST   0
288 /**< Highest priority expressed across eventdev subsystem
289  * @see rte_event_queue_setup(), rte_event_enqueue_burst()
290  * @see rte_event_port_link()
291  */
292 #define RTE_EVENT_DEV_PRIORITY_NORMAL    128
293 /**< Normal priority expressed across eventdev subsystem
294  * @see rte_event_queue_setup(), rte_event_enqueue_burst()
295  * @see rte_event_port_link()
296  */
297 #define RTE_EVENT_DEV_PRIORITY_LOWEST    255
298 /**< Lowest priority expressed across eventdev subsystem
299  * @see rte_event_queue_setup(), rte_event_enqueue_burst()
300  * @see rte_event_port_link()
301  */
302
303 /**
304  * Get the total number of event devices that have been successfully
305  * initialised.
306  *
307  * @return
308  *   The total number of usable event devices.
309  */
310 uint8_t
311 rte_event_dev_count(void);
312
313 /**
314  * Get the device identifier for the named event device.
315  *
316  * @param name
317  *   Event device name to select the event device identifier.
318  *
319  * @return
320  *   Returns event device identifier on success.
321  *   - <0: Failure to find named event device.
322  */
323 int
324 rte_event_dev_get_dev_id(const char *name);
325
326 /**
327  * Return the NUMA socket to which a device is connected.
328  *
329  * @param dev_id
330  *   The identifier of the device.
331  * @return
332  *   The NUMA socket id to which the device is connected or
333  *   a default of zero if the socket could not be determined.
334  *   -(-EINVAL)  dev_id value is out of range.
335  */
336 int
337 rte_event_dev_socket_id(uint8_t dev_id);
338
339 /**
340  * Event device information
341  */
342 struct rte_event_dev_info {
343         const char *driver_name;        /**< Event driver name */
344         struct rte_device *dev; /**< Device information */
345         uint32_t min_dequeue_timeout_ns;
346         /**< Minimum supported global dequeue timeout(ns) by this device */
347         uint32_t max_dequeue_timeout_ns;
348         /**< Maximum supported global dequeue timeout(ns) by this device */
349         uint32_t dequeue_timeout_ns;
350         /**< Configured global dequeue timeout(ns) for this device */
351         uint8_t max_event_queues;
352         /**< Maximum event_queues supported by this device */
353         uint32_t max_event_queue_flows;
354         /**< Maximum supported flows in an event queue by this device*/
355         uint8_t max_event_queue_priority_levels;
356         /**< Maximum number of event queue priority levels by this device.
357          * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
358          */
359         uint8_t max_event_priority_levels;
360         /**< Maximum number of event priority levels by this device.
361          * Valid when the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability
362          */
363         uint8_t max_event_ports;
364         /**< Maximum number of event ports supported by this device */
365         uint8_t max_event_port_dequeue_depth;
366         /**< Maximum number of events can be dequeued at a time from an
367          * event port by this device.
368          * A device that does not support bulk dequeue will set this as 1.
369          */
370         uint32_t max_event_port_enqueue_depth;
371         /**< Maximum number of events can be enqueued at a time from an
372          * event port by this device.
373          * A device that does not support bulk enqueue will set this as 1.
374          */
375         int32_t max_num_events;
376         /**< A *closed system* event dev has a limit on the number of events it
377          * can manage at a time. An *open system* event dev does not have a
378          * limit and will specify this as -1.
379          */
380         uint32_t event_dev_cap;
381         /**< Event device capabilities(RTE_EVENT_DEV_CAP_)*/
382 };
383
384 /**
385  * Retrieve the contextual information of an event device.
386  *
387  * @param dev_id
388  *   The identifier of the device.
389  *
390  * @param[out] dev_info
391  *   A pointer to a structure of type *rte_event_dev_info* to be filled with the
392  *   contextual information of the device.
393  *
394  * @return
395  *   - 0: Success, driver updates the contextual information of the event device
396  *   - <0: Error code returned by the driver info get function.
397  *
398  */
399 int
400 rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info);
401
402 /* Event device configuration bitmap flags */
403 #define RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT (1ULL << 0)
404 /**< Override the global *dequeue_timeout_ns* and use per dequeue timeout in ns.
405  *  @see rte_event_dequeue_timeout_ticks(), rte_event_dequeue_burst()
406  */
407
408 /** Event device configuration structure */
409 struct rte_event_dev_config {
410         uint32_t dequeue_timeout_ns;
411         /**< rte_event_dequeue_burst() timeout on this device.
412          * This value should be in the range of *min_dequeue_timeout_ns* and
413          * *max_dequeue_timeout_ns* which previously provided in
414          * rte_event_dev_info_get()
415          * @see RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
416          */
417         int32_t nb_events_limit;
418         /**< In a *closed system* this field is the limit on maximum number of
419          * events that can be inflight in the eventdev at a given time. The
420          * limit is required to ensure that the finite space in a closed system
421          * is not overwhelmed. The value cannot exceed the *max_num_events*
422          * as provided by rte_event_dev_info_get().
423          * This value should be set to -1 for *open system*.
424          */
425         uint8_t nb_event_queues;
426         /**< Number of event queues to configure on this device.
427          * This value cannot exceed the *max_event_queues* which previously
428          * provided in rte_event_dev_info_get()
429          */
430         uint8_t nb_event_ports;
431         /**< Number of event ports to configure on this device.
432          * This value cannot exceed the *max_event_ports* which previously
433          * provided in rte_event_dev_info_get()
434          */
435         uint32_t nb_event_queue_flows;
436         /**< Number of flows for any event queue on this device.
437          * This value cannot exceed the *max_event_queue_flows* which previously
438          * provided in rte_event_dev_info_get()
439          */
440         uint32_t nb_event_port_dequeue_depth;
441         /**< Maximum number of events can be dequeued at a time from an
442          * event port by this device.
443          * This value cannot exceed the *max_event_port_dequeue_depth*
444          * which previously provided in rte_event_dev_info_get().
445          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
446          * @see rte_event_port_setup()
447          */
448         uint32_t nb_event_port_enqueue_depth;
449         /**< Maximum number of events can be enqueued at a time from an
450          * event port by this device.
451          * This value cannot exceed the *max_event_port_enqueue_depth*
452          * which previously provided in rte_event_dev_info_get().
453          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
454          * @see rte_event_port_setup()
455          */
456         uint32_t event_dev_cfg;
457         /**< Event device config flags(RTE_EVENT_DEV_CFG_)*/
458 };
459
460 /**
461  * Configure an event device.
462  *
463  * This function must be invoked first before any other function in the
464  * API. This function can also be re-invoked when a device is in the
465  * stopped state.
466  *
467  * The caller may use rte_event_dev_info_get() to get the capability of each
468  * resources available for this event device.
469  *
470  * @param dev_id
471  *   The identifier of the device to configure.
472  * @param dev_conf
473  *   The event device configuration structure.
474  *
475  * @return
476  *   - 0: Success, device configured.
477  *   - <0: Error code returned by the driver configuration function.
478  */
479 int
480 rte_event_dev_configure(uint8_t dev_id,
481                         const struct rte_event_dev_config *dev_conf);
482
483
484 /* Event queue specific APIs */
485
486 /* Event queue configuration bitmap flags */
487 #define RTE_EVENT_QUEUE_CFG_TYPE_MASK          (3ULL << 0)
488 /**< Mask for event queue schedule type configuration request */
489 #define RTE_EVENT_QUEUE_CFG_ALL_TYPES          (0ULL << 0)
490 /**< Allow ATOMIC,ORDERED,PARALLEL schedule type enqueue
491  *
492  * @see RTE_SCHED_TYPE_ORDERED, RTE_SCHED_TYPE_ATOMIC, RTE_SCHED_TYPE_PARALLEL
493  * @see rte_event_enqueue_burst()
494  */
495 #define RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY        (1ULL << 0)
496 /**< Allow only ATOMIC schedule type enqueue
497  *
498  * The rte_event_enqueue_burst() result is undefined if the queue configured
499  * with ATOMIC only and sched_type != RTE_SCHED_TYPE_ATOMIC
500  *
501  * @see RTE_SCHED_TYPE_ATOMIC, rte_event_enqueue_burst()
502  */
503 #define RTE_EVENT_QUEUE_CFG_ORDERED_ONLY       (2ULL << 0)
504 /**< Allow only ORDERED schedule type enqueue
505  *
506  * The rte_event_enqueue_burst() result is undefined if the queue configured
507  * with ORDERED only and sched_type != RTE_SCHED_TYPE_ORDERED
508  *
509  * @see RTE_SCHED_TYPE_ORDERED, rte_event_enqueue_burst()
510  */
511 #define RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY      (3ULL << 0)
512 /**< Allow only PARALLEL schedule type enqueue
513  *
514  * The rte_event_enqueue_burst() result is undefined if the queue configured
515  * with PARALLEL only and sched_type != RTE_SCHED_TYPE_PARALLEL
516  *
517  * @see RTE_SCHED_TYPE_PARALLEL, rte_event_enqueue_burst()
518  */
519 #define RTE_EVENT_QUEUE_CFG_SINGLE_LINK        (1ULL << 2)
520 /**< This event queue links only to a single event port.
521  *
522  *  @see rte_event_port_setup(), rte_event_port_link()
523  */
524
525 /** Event queue configuration structure */
526 struct rte_event_queue_conf {
527         uint32_t nb_atomic_flows;
528         /**< The maximum number of active flows this queue can track at any
529          * given time. If the queue is configured for atomic scheduling (by
530          * applying the RTE_EVENT_QUEUE_CFG_ALL_TYPES or
531          * RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY flags to event_queue_cfg), then the
532          * value must be in the range of [1, nb_event_queue_flows], which was
533          * previously provided in rte_event_dev_configure().
534          */
535         uint32_t nb_atomic_order_sequences;
536         /**< The maximum number of outstanding events waiting to be
537          * reordered by this queue. In other words, the number of entries in
538          * this queue’s reorder buffer.When the number of events in the
539          * reorder buffer reaches to *nb_atomic_order_sequences* then the
540          * scheduler cannot schedule the events from this queue and invalid
541          * event will be returned from dequeue until one or more entries are
542          * freed up/released.
543          * If the queue is configured for ordered scheduling (by applying the
544          * RTE_EVENT_QUEUE_CFG_ALL_TYPES or RTE_EVENT_QUEUE_CFG_ORDERED_ONLY
545          * flags to event_queue_cfg), then the value must be in the range of
546          * [1, nb_event_queue_flows], which was previously supplied to
547          * rte_event_dev_configure().
548          */
549         uint32_t event_queue_cfg; /**< Queue cfg flags(EVENT_QUEUE_CFG_) */
550         uint8_t priority;
551         /**< Priority for this event queue relative to other event queues.
552          * The requested priority should in the range of
553          * [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
554          * The implementation shall normalize the requested priority to
555          * event device supported priority value.
556          * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
557          */
558 };
559
560 /**
561  * Retrieve the default configuration information of an event queue designated
562  * by its *queue_id* from the event driver for an event device.
563  *
564  * This function intended to be used in conjunction with rte_event_queue_setup()
565  * where caller needs to set up the queue by overriding few default values.
566  *
567  * @param dev_id
568  *   The identifier of the device.
569  * @param queue_id
570  *   The index of the event queue to get the configuration information.
571  *   The value must be in the range [0, nb_event_queues - 1]
572  *   previously supplied to rte_event_dev_configure().
573  * @param[out] queue_conf
574  *   The pointer to the default event queue configuration data.
575  * @return
576  *   - 0: Success, driver updates the default event queue configuration data.
577  *   - <0: Error code returned by the driver info get function.
578  *
579  * @see rte_event_queue_setup()
580  *
581  */
582 int
583 rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
584                                  struct rte_event_queue_conf *queue_conf);
585
586 /**
587  * Allocate and set up an event queue for an event device.
588  *
589  * @param dev_id
590  *   The identifier of the device.
591  * @param queue_id
592  *   The index of the event queue to setup. The value must be in the range
593  *   [0, nb_event_queues - 1] previously supplied to rte_event_dev_configure().
594  * @param queue_conf
595  *   The pointer to the configuration data to be used for the event queue.
596  *   NULL value is allowed, in which case default configuration used.
597  *
598  * @see rte_event_queue_default_conf_get()
599  *
600  * @return
601  *   - 0: Success, event queue correctly set up.
602  *   - <0: event queue configuration failed
603  */
604 int
605 rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
606                       const struct rte_event_queue_conf *queue_conf);
607
608 /**
609  * Get the number of event queues on a specific event device
610  *
611  * @param dev_id
612  *   Event device identifier.
613  * @return
614  *   - The number of configured event queues
615  */
616 uint8_t
617 rte_event_queue_count(uint8_t dev_id);
618
619 /**
620  * Get the priority of the event queue on a specific event device
621  *
622  * @param dev_id
623  *   Event device identifier.
624  * @param queue_id
625  *   Event queue identifier.
626  * @return
627  *   - If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then the
628  *    configured priority of the event queue in
629  *    [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST] range
630  *    else the value RTE_EVENT_DEV_PRIORITY_NORMAL
631  */
632 uint8_t
633 rte_event_queue_priority(uint8_t dev_id, uint8_t queue_id);
634
635 /* Event port specific APIs */
636
637 /** Event port configuration structure */
638 struct rte_event_port_conf {
639         int32_t new_event_threshold;
640         /**< A backpressure threshold for new event enqueues on this port.
641          * Use for *closed system* event dev where event capacity is limited,
642          * and cannot exceed the capacity of the event dev.
643          * Configuring ports with different thresholds can make higher priority
644          * traffic less likely to  be backpressured.
645          * For example, a port used to inject NIC Rx packets into the event dev
646          * can have a lower threshold so as not to overwhelm the device,
647          * while ports used for worker pools can have a higher threshold.
648          * This value cannot exceed the *nb_events_limit*
649          * which was previously supplied to rte_event_dev_configure().
650          * This should be set to '-1' for *open system*.
651          */
652         uint16_t dequeue_depth;
653         /**< Configure number of bulk dequeues for this event port.
654          * This value cannot exceed the *nb_event_port_dequeue_depth*
655          * which previously supplied to rte_event_dev_configure().
656          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
657          */
658         uint16_t enqueue_depth;
659         /**< Configure number of bulk enqueues for this event port.
660          * This value cannot exceed the *nb_event_port_enqueue_depth*
661          * which previously supplied to rte_event_dev_configure().
662          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
663          */
664 };
665
666 /**
667  * Retrieve the default configuration information of an event port designated
668  * by its *port_id* from the event driver for an event device.
669  *
670  * This function intended to be used in conjunction with rte_event_port_setup()
671  * where caller needs to set up the port by overriding few default values.
672  *
673  * @param dev_id
674  *   The identifier of the device.
675  * @param port_id
676  *   The index of the event port to get the configuration information.
677  *   The value must be in the range [0, nb_event_ports - 1]
678  *   previously supplied to rte_event_dev_configure().
679  * @param[out] port_conf
680  *   The pointer to the default event port configuration data
681  * @return
682  *   - 0: Success, driver updates the default event port configuration data.
683  *   - <0: Error code returned by the driver info get function.
684  *
685  * @see rte_event_port_setup()
686  *
687  */
688 int
689 rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
690                                 struct rte_event_port_conf *port_conf);
691
692 /**
693  * Allocate and set up an event port for an event device.
694  *
695  * @param dev_id
696  *   The identifier of the device.
697  * @param port_id
698  *   The index of the event port to setup. The value must be in the range
699  *   [0, nb_event_ports - 1] previously supplied to rte_event_dev_configure().
700  * @param port_conf
701  *   The pointer to the configuration data to be used for the queue.
702  *   NULL value is allowed, in which case default configuration used.
703  *
704  * @see rte_event_port_default_conf_get()
705  *
706  * @return
707  *   - 0: Success, event port correctly set up.
708  *   - <0: Port configuration failed
709  *   - (-EDQUOT) Quota exceeded(Application tried to link the queue configured
710  *   with RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
711  */
712 int
713 rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
714                      const struct rte_event_port_conf *port_conf);
715
716 /**
717  * Get the number of dequeue queue depth configured for event port designated
718  * by its *port_id* on a specific event device
719  *
720  * @param dev_id
721  *   Event device identifier.
722  * @param port_id
723  *   Event port identifier.
724  * @return
725  *   - The number of configured dequeue queue depth
726  *
727  * @see rte_event_dequeue_burst()
728  */
729 uint8_t
730 rte_event_port_dequeue_depth(uint8_t dev_id, uint8_t port_id);
731
732 /**
733  * Get the number of enqueue queue depth configured for event port designated
734  * by its *port_id* on a specific event device
735  *
736  * @param dev_id
737  *   Event device identifier.
738  * @param port_id
739  *   Event port identifier.
740  * @return
741  *   - The number of configured enqueue queue depth
742  *
743  * @see rte_event_enqueue_burst()
744  */
745 uint8_t
746 rte_event_port_enqueue_depth(uint8_t dev_id, uint8_t port_id);
747
748 /**
749  * Get the number of ports on a specific event device
750  *
751  * @param dev_id
752  *   Event device identifier.
753  * @return
754  *   - The number of configured ports
755  */
756 uint8_t
757 rte_event_port_count(uint8_t dev_id);
758
759 /**
760  * Start an event device.
761  *
762  * The device start step is the last one and consists of setting the event
763  * queues to start accepting the events and schedules to event ports.
764  *
765  * On success, all basic functions exported by the API (event enqueue,
766  * event dequeue and so on) can be invoked.
767  *
768  * @param dev_id
769  *   Event device identifier
770  * @return
771  *   - 0: Success, device started.
772  *   - -ESTALE : Not all ports of the device are configured
773  *   - -ENOLINK: Not all queues are linked, which could lead to deadlock.
774  */
775 int
776 rte_event_dev_start(uint8_t dev_id);
777
778 /**
779  * Stop an event device. The device can be restarted with a call to
780  * rte_event_dev_start()
781  *
782  * @param dev_id
783  *   Event device identifier.
784  */
785 void
786 rte_event_dev_stop(uint8_t dev_id);
787
788 /**
789  * Close an event device. The device cannot be restarted!
790  *
791  * @param dev_id
792  *   Event device identifier
793  *
794  * @return
795  *  - 0 on successfully closing device
796  *  - <0 on failure to close device
797  *  - (-EAGAIN) if device is busy
798  */
799 int
800 rte_event_dev_close(uint8_t dev_id);
801
802 /* Scheduler type definitions */
803 #define RTE_SCHED_TYPE_ORDERED          0
804 /**< Ordered scheduling
805  *
806  * Events from an ordered flow of an event queue can be scheduled to multiple
807  * ports for concurrent processing while maintaining the original event order.
808  * This scheme enables the user to achieve high single flow throughput by
809  * avoiding SW synchronization for ordering between ports which bound to cores.
810  *
811  * The source flow ordering from an event queue is maintained when events are
812  * enqueued to their destination queue within the same ordered flow context.
813  * An event port holds the context until application call
814  * rte_event_dequeue_burst() from the same port, which implicitly releases
815  * the context.
816  * User may allow the scheduler to release the context earlier than that
817  * by invoking rte_event_enqueue_burst() with RTE_EVENT_OP_RELEASE operation.
818  *
819  * Events from the source queue appear in their original order when dequeued
820  * from a destination queue.
821  * Event ordering is based on the received event(s), but also other
822  * (newly allocated or stored) events are ordered when enqueued within the same
823  * ordered context. Events not enqueued (e.g. released or stored) within the
824  * context are  considered missing from reordering and are skipped at this time
825  * (but can be ordered again within another context).
826  *
827  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
828  */
829
830 #define RTE_SCHED_TYPE_ATOMIC           1
831 /**< Atomic scheduling
832  *
833  * Events from an atomic flow of an event queue can be scheduled only to a
834  * single port at a time. The port is guaranteed to have exclusive (atomic)
835  * access to the associated flow context, which enables the user to avoid SW
836  * synchronization. Atomic flows also help to maintain event ordering
837  * since only one port at a time can process events from a flow of an
838  * event queue.
839  *
840  * The atomic queue synchronization context is dedicated to the port until
841  * application call rte_event_dequeue_burst() from the same port,
842  * which implicitly releases the context. User may allow the scheduler to
843  * release the context earlier than that by invoking rte_event_enqueue_burst()
844  * with RTE_EVENT_OP_RELEASE operation.
845  *
846  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
847  */
848
849 #define RTE_SCHED_TYPE_PARALLEL         2
850 /**< Parallel scheduling
851  *
852  * The scheduler performs priority scheduling, load balancing, etc. functions
853  * but does not provide additional event synchronization or ordering.
854  * It is free to schedule events from a single parallel flow of an event queue
855  * to multiple events ports for concurrent processing.
856  * The application is responsible for flow context synchronization and
857  * event ordering (SW synchronization).
858  *
859  * @see rte_event_queue_setup(), rte_event_dequeue_burst()
860  */
861
862 /* Event types to classify the event source */
863 #define RTE_EVENT_TYPE_ETHDEV           0x0
864 /**< The event generated from ethdev subsystem */
865 #define RTE_EVENT_TYPE_CRYPTODEV        0x1
866 /**< The event generated from crypodev subsystem */
867 #define RTE_EVENT_TYPE_TIMERDEV         0x2
868 /**< The event generated from timerdev subsystem */
869 #define RTE_EVENT_TYPE_CPU              0x3
870 /**< The event generated from cpu for pipelining.
871  * Application may use *sub_event_type* to further classify the event
872  */
873 #define RTE_EVENT_TYPE_MAX              0x10
874 /**< Maximum number of event types */
875
876 /* Event enqueue operations */
877 #define RTE_EVENT_OP_NEW                0
878 /**< The event producers use this operation to inject a new event to the
879  * event device.
880  */
881 #define RTE_EVENT_OP_FORWARD            1
882 /**< The CPU use this operation to forward the event to different event queue or
883  * change to new application specific flow or schedule type to enable
884  * pipelining
885  */
886 #define RTE_EVENT_OP_RELEASE            2
887 /**< Release the flow context associated with the schedule type.
888  *
889  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ATOMIC*
890  * then this function hints the scheduler that the user has completed critical
891  * section processing in the current atomic context.
892  * The scheduler is now allowed to schedule events from the same flow from
893  * an event queue to another port. However, the context may be still held
894  * until the next rte_event_dequeue_burst() call, this call allows but does not
895  * force the scheduler to release the context early.
896  *
897  * Early atomic context release may increase parallelism and thus system
898  * performance, but the user needs to design carefully the split into critical
899  * vs non-critical sections.
900  *
901  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ORDERED*
902  * then this function hints the scheduler that the user has done all that need
903  * to maintain event order in the current ordered context.
904  * The scheduler is allowed to release the ordered context of this port and
905  * avoid reordering any following enqueues.
906  *
907  * Early ordered context release may increase parallelism and thus system
908  * performance.
909  *
910  * If current flow's scheduler type method is *RTE_SCHED_TYPE_PARALLEL*
911  * or no scheduling context is held then this function may be an NOOP,
912  * depending on the implementation.
913  *
914  */
915
916 /**
917  * The generic *rte_event* structure to hold the event attributes
918  * for dequeue and enqueue operation
919  */
920 RTE_STD_C11
921 struct rte_event {
922         /** WORD0 */
923         union {
924                 uint64_t event;
925                 /** Event attributes for dequeue or enqueue operation */
926                 struct {
927                         uint32_t flow_id:20;
928                         /**< Targeted flow identifier for the enqueue and
929                          * dequeue operation.
930                          * The value must be in the range of
931                          * [0, nb_event_queue_flows - 1] which
932                          * previously supplied to rte_event_dev_configure().
933                          */
934                         uint32_t sub_event_type:8;
935                         /**< Sub-event types based on the event source.
936                          * @see RTE_EVENT_TYPE_CPU
937                          */
938                         uint32_t event_type:4;
939                         /**< Event type to classify the event source.
940                          * @see RTE_EVENT_TYPE_ETHDEV, (RTE_EVENT_TYPE_*)
941                          */
942                         uint8_t op:2;
943                         /**< The type of event enqueue operation - new/forward/
944                          * etc.This field is not preserved across an instance
945                          * and is undefined on dequeue.
946                          * @see RTE_EVENT_OP_NEW, (RTE_EVENT_OP_*)
947                          */
948                         uint8_t rsvd:4;
949                         /**< Reserved for future use */
950                         uint8_t sched_type:2;
951                         /**< Scheduler synchronization type (RTE_SCHED_TYPE_*)
952                          * associated with flow id on a given event queue
953                          * for the enqueue and dequeue operation.
954                          */
955                         uint8_t queue_id;
956                         /**< Targeted event queue identifier for the enqueue or
957                          * dequeue operation.
958                          * The value must be in the range of
959                          * [0, nb_event_queues - 1] which previously supplied to
960                          * rte_event_dev_configure().
961                          */
962                         uint8_t priority;
963                         /**< Event priority relative to other events in the
964                          * event queue. The requested priority should in the
965                          * range of  [RTE_EVENT_DEV_PRIORITY_HIGHEST,
966                          * RTE_EVENT_DEV_PRIORITY_LOWEST].
967                          * The implementation shall normalize the requested
968                          * priority to supported priority value.
969                          * Valid when the device has
970                          * RTE_EVENT_DEV_CAP_EVENT_QOS capability.
971                          */
972                         uint8_t impl_opaque;
973                         /**< Implementation specific opaque value.
974                          * An implementation may use this field to hold
975                          * implementation specific value to share between
976                          * dequeue and enqueue operation.
977                          * The application should not modify this field.
978                          */
979                 };
980         };
981         /** WORD1 */
982         union {
983                 uint64_t u64;
984                 /**< Opaque 64-bit value */
985                 void *event_ptr;
986                 /**< Opaque event pointer */
987                 struct rte_mbuf *mbuf;
988                 /**< mbuf pointer if dequeued event is associated with mbuf */
989         };
990 };
991
992
993 struct rte_eventdev_driver;
994 struct rte_eventdev_ops;
995 struct rte_eventdev;
996
997 typedef void (*event_schedule_t)(struct rte_eventdev *dev);
998 /**< @internal Schedule one or more events in the event dev. */
999
1000 typedef uint16_t (*event_enqueue_t)(void *port, const struct rte_event *ev);
1001 /**< @internal Enqueue event on port of a device */
1002
1003 typedef uint16_t (*event_enqueue_burst_t)(void *port,
1004                         const struct rte_event ev[], uint16_t nb_events);
1005 /**< @internal Enqueue burst of events on port of a device */
1006
1007 typedef uint16_t (*event_dequeue_t)(void *port, struct rte_event *ev,
1008                 uint64_t timeout_ticks);
1009 /**< @internal Dequeue event from port of a device */
1010
1011 typedef uint16_t (*event_dequeue_burst_t)(void *port, struct rte_event ev[],
1012                 uint16_t nb_events, uint64_t timeout_ticks);
1013 /**< @internal Dequeue burst of events from port of a device */
1014
1015 #define RTE_EVENTDEV_NAME_MAX_LEN       (64)
1016 /**< @internal Max length of name of event PMD */
1017
1018 /**
1019  * @internal
1020  * The data part, with no function pointers, associated with each device.
1021  *
1022  * This structure is safe to place in shared memory to be common among
1023  * different processes in a multi-process configuration.
1024  */
1025 struct rte_eventdev_data {
1026         int socket_id;
1027         /**< Socket ID where memory is allocated */
1028         uint8_t dev_id;
1029         /**< Device ID for this instance */
1030         uint8_t nb_queues;
1031         /**< Number of event queues. */
1032         uint8_t nb_ports;
1033         /**< Number of event ports. */
1034         void **ports;
1035         /**< Array of pointers to ports. */
1036         uint8_t *ports_dequeue_depth;
1037         /**< Array of port dequeue depth. */
1038         uint8_t *ports_enqueue_depth;
1039         /**< Array of port enqueue depth. */
1040         uint8_t *queues_prio;
1041         /**< Array of queue priority. */
1042         uint16_t *links_map;
1043         /**< Memory to store queues to port connections. */
1044         void *dev_private;
1045         /**< PMD-specific private data */
1046         uint32_t event_dev_cap;
1047         /**< Event device capabilities(RTE_EVENT_DEV_CAP_)*/
1048         struct rte_event_dev_config dev_conf;
1049         /**< Configuration applied to device. */
1050
1051         RTE_STD_C11
1052         uint8_t dev_started : 1;
1053         /**< Device state: STARTED(1)/STOPPED(0) */
1054
1055         char name[RTE_EVENTDEV_NAME_MAX_LEN];
1056         /**< Unique identifier name */
1057 } __rte_cache_aligned;
1058
1059 /** @internal The data structure associated with each event device. */
1060 struct rte_eventdev {
1061         event_schedule_t schedule;
1062         /**< Pointer to PMD schedule function. */
1063         event_enqueue_t enqueue;
1064         /**< Pointer to PMD enqueue function. */
1065         event_enqueue_burst_t enqueue_burst;
1066         /**< Pointer to PMD enqueue burst function. */
1067         event_dequeue_t dequeue;
1068         /**< Pointer to PMD dequeue function. */
1069         event_dequeue_burst_t dequeue_burst;
1070         /**< Pointer to PMD dequeue burst function. */
1071
1072         struct rte_eventdev_data *data;
1073         /**< Pointer to device data */
1074         const struct rte_eventdev_ops *dev_ops;
1075         /**< Functions exported by PMD */
1076         struct rte_device *dev;
1077         /**< Device info. supplied by probing */
1078
1079         RTE_STD_C11
1080         uint8_t attached : 1;
1081         /**< Flag indicating the device is attached */
1082 } __rte_cache_aligned;
1083
1084 extern struct rte_eventdev *rte_eventdevs;
1085 /** @internal The pool of rte_eventdev structures. */
1086
1087
1088 /**
1089  * Schedule one or more events in the event dev.
1090  *
1091  * An event dev implementation may define this is a NOOP, for instance if
1092  * the event dev performs its scheduling in hardware.
1093  *
1094  * @param dev_id
1095  *   The identifier of the device.
1096  */
1097 static inline void
1098 rte_event_schedule(uint8_t dev_id)
1099 {
1100         struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1101         if (*dev->schedule)
1102                 (*dev->schedule)(dev);
1103 }
1104
1105 /**
1106  * Enqueue a burst of events objects or an event object supplied in *rte_event*
1107  * structure on an  event device designated by its *dev_id* through the event
1108  * port specified by *port_id*. Each event object specifies the event queue on
1109  * which it will be enqueued.
1110  *
1111  * The *nb_events* parameter is the number of event objects to enqueue which are
1112  * supplied in the *ev* array of *rte_event* structure.
1113  *
1114  * The rte_event_enqueue_burst() function returns the number of
1115  * events objects it actually enqueued. A return value equal to *nb_events*
1116  * means that all event objects have been enqueued.
1117  *
1118  * @param dev_id
1119  *   The identifier of the device.
1120  * @param port_id
1121  *   The identifier of the event port.
1122  * @param ev
1123  *   Points to an array of *nb_events* objects of type *rte_event* structure
1124  *   which contain the event object enqueue operations to be processed.
1125  * @param nb_events
1126  *   The number of event objects to enqueue, typically number of
1127  *   rte_event_port_enqueue_depth() available for this port.
1128  *
1129  * @return
1130  *   The number of event objects actually enqueued on the event device. The
1131  *   return value can be less than the value of the *nb_events* parameter when
1132  *   the event devices queue is full or if invalid parameters are specified in a
1133  *   *rte_event*. If the return value is less than *nb_events*, the remaining
1134  *   events at the end of ev[] are not consumed and the caller has to take care
1135  *   of them, and rte_errno is set accordingly. Possible errno values include:
1136  *   - -EINVAL  The port ID is invalid, device ID is invalid, an event's queue
1137  *              ID is invalid, or an event's sched type doesn't match the
1138  *              capabilities of the destination queue.
1139  *   - -ENOSPC  The event port was backpressured and unable to enqueue
1140  *              one or more events. This error code is only applicable to
1141  *              closed systems.
1142  * @see rte_event_port_enqueue_depth()
1143  */
1144 static inline uint16_t
1145 rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1146                         const struct rte_event ev[], uint16_t nb_events)
1147 {
1148         struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1149
1150 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
1151         if (dev_id >= RTE_EVENT_MAX_DEVS || !rte_eventdevs[dev_id].attached) {
1152                 rte_errno = -EINVAL;
1153                 return 0;
1154         }
1155
1156         if (port_id >= dev->data->nb_ports) {
1157                 rte_errno = -EINVAL;
1158                 return 0;
1159         }
1160 #endif
1161
1162         /*
1163          * Allow zero cost non burst mode routine invocation if application
1164          * requests nb_events as const one
1165          */
1166         if (nb_events == 1)
1167                 return (*dev->enqueue)(
1168                         dev->data->ports[port_id], ev);
1169         else
1170                 return (*dev->enqueue_burst)(
1171                         dev->data->ports[port_id], ev, nb_events);
1172 }
1173
1174 /**
1175  * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue_burst()
1176  *
1177  * If the device is configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT flag
1178  * then application can use this function to convert timeout value in
1179  * nanoseconds to implementations specific timeout value supplied in
1180  * rte_event_dequeue_burst()
1181  *
1182  * @param dev_id
1183  *   The identifier of the device.
1184  * @param ns
1185  *   Wait time in nanosecond
1186  * @param[out] timeout_ticks
1187  *   Value for the *timeout_ticks* parameter in rte_event_dequeue_burst()
1188  *
1189  * @return
1190  *  - 0 on success.
1191  *  - -ENOTSUP if the device doesn't support timeouts
1192  *  - -EINVAL if *dev_id* is invalid or *timeout_ticks* is NULL
1193  *  - other values < 0 on failure.
1194  *
1195  * @see rte_event_dequeue_burst(), RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1196  * @see rte_event_dev_configure()
1197  *
1198  */
1199 int
1200 rte_event_dequeue_timeout_ticks(uint8_t dev_id, uint64_t ns,
1201                                         uint64_t *timeout_ticks);
1202
1203 /**
1204  * Dequeue a burst of events objects or an event object from the event port
1205  * designated by its *event_port_id*, on an event device designated
1206  * by its *dev_id*.
1207  *
1208  * rte_event_dequeue_burst() does not dictate the specifics of scheduling
1209  * algorithm as each eventdev driver may have different criteria to schedule
1210  * an event. However, in general, from an application perspective scheduler may
1211  * use the following scheme to dispatch an event to the port.
1212  *
1213  * 1) Selection of event queue based on
1214  *   a) The list of event queues are linked to the event port.
1215  *   b) If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then event
1216  *   queue selection from list is based on event queue priority relative to
1217  *   other event queue supplied as *priority* in rte_event_queue_setup()
1218  *   c) If the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability then event
1219  *   queue selection from the list is based on event priority supplied as
1220  *   *priority* in rte_event_enqueue_burst()
1221  * 2) Selection of event
1222  *   a) The number of flows available in selected event queue.
1223  *   b) Schedule type method associated with the event
1224  *
1225  * The *nb_events* parameter is the maximum number of event objects to dequeue
1226  * which are returned in the *ev* array of *rte_event* structure.
1227  *
1228  * The rte_event_dequeue_burst() function returns the number of events objects
1229  * it actually dequeued. A return value equal to *nb_events* means that all
1230  * event objects have been dequeued.
1231  *
1232  * The number of events dequeued is the number of scheduler contexts held by
1233  * this port. These contexts are automatically released in the next
1234  * rte_event_dequeue_burst() invocation, or invoking rte_event_enqueue_burst()
1235  * with RTE_EVENT_OP_RELEASE operation can be used to release the
1236  * contexts early.
1237  *
1238  * @param dev_id
1239  *   The identifier of the device.
1240  * @param port_id
1241  *   The identifier of the event port.
1242  * @param[out] ev
1243  *   Points to an array of *nb_events* objects of type *rte_event* structure
1244  *   for output to be populated with the dequeued event objects.
1245  * @param nb_events
1246  *   The maximum number of event objects to dequeue, typically number of
1247  *   rte_event_port_dequeue_depth() available for this port.
1248  *
1249  * @param timeout_ticks
1250  *   - 0 no-wait, returns immediately if there is no event.
1251  *   - >0 wait for the event, if the device is configured with
1252  *   RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT then this function will wait until
1253  *   at least one event is available or *timeout_ticks* time.
1254  *   if the device is not configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1255  *   then this function will wait until the event available or
1256  *   *dequeue_timeout_ns* ns which was previously supplied to
1257  *   rte_event_dev_configure()
1258  *
1259  * @return
1260  * The number of event objects actually dequeued from the port. The return
1261  * value can be less than the value of the *nb_events* parameter when the
1262  * event port's queue is not full.
1263  *
1264  * @see rte_event_port_dequeue_depth()
1265  */
1266 static inline uint16_t
1267 rte_event_dequeue_burst(uint8_t dev_id, uint8_t port_id, struct rte_event ev[],
1268                         uint16_t nb_events, uint64_t timeout_ticks)
1269 {
1270         struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1271
1272 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
1273         if (dev_id >= RTE_EVENT_MAX_DEVS || !rte_eventdevs[dev_id].attached) {
1274                 rte_errno = -EINVAL;
1275                 return 0;
1276         }
1277
1278         if (port_id >= dev->data->nb_ports) {
1279                 rte_errno = -EINVAL;
1280                 return 0;
1281         }
1282 #endif
1283
1284         /*
1285          * Allow zero cost non burst mode routine invocation if application
1286          * requests nb_events as const one
1287          */
1288         if (nb_events == 1)
1289                 return (*dev->dequeue)(
1290                         dev->data->ports[port_id], ev, timeout_ticks);
1291         else
1292                 return (*dev->dequeue_burst)(
1293                         dev->data->ports[port_id], ev, nb_events,
1294                                 timeout_ticks);
1295 }
1296
1297 /**
1298  * Link multiple source event queues supplied in *queues* to the destination
1299  * event port designated by its *port_id* with associated service priority
1300  * supplied in *priorities* on the event device designated by its *dev_id*.
1301  *
1302  * The link establishment shall enable the event port *port_id* from
1303  * receiving events from the specified event queue(s) supplied in *queues*
1304  *
1305  * An event queue may link to one or more event ports.
1306  * The number of links can be established from an event queue to event port is
1307  * implementation defined.
1308  *
1309  * Event queue(s) to event port link establishment can be changed at runtime
1310  * without re-configuring the device to support scaling and to reduce the
1311  * latency of critical work by establishing the link with more event ports
1312  * at runtime.
1313  *
1314  * @param dev_id
1315  *   The identifier of the device.
1316  *
1317  * @param port_id
1318  *   Event port identifier to select the destination port to link.
1319  *
1320  * @param queues
1321  *   Points to an array of *nb_links* event queues to be linked
1322  *   to the event port.
1323  *   NULL value is allowed, in which case this function links all the configured
1324  *   event queues *nb_event_queues* which previously supplied to
1325  *   rte_event_dev_configure() to the event port *port_id*
1326  *
1327  * @param priorities
1328  *   Points to an array of *nb_links* service priorities associated with each
1329  *   event queue link to event port.
1330  *   The priority defines the event port's servicing priority for
1331  *   event queue, which may be ignored by an implementation.
1332  *   The requested priority should in the range of
1333  *   [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
1334  *   The implementation shall normalize the requested priority to
1335  *   implementation supported priority value.
1336  *   NULL value is allowed, in which case this function links the event queues
1337  *   with RTE_EVENT_DEV_PRIORITY_NORMAL servicing priority
1338  *
1339  * @param nb_links
1340  *   The number of links to establish. This parameter is ignored if queues is
1341  *   NULL.
1342  *
1343  * @return
1344  * The number of links actually established. The return value can be less than
1345  * the value of the *nb_links* parameter when the implementation has the
1346  * limitation on specific queue to port link establishment or if invalid
1347  * parameters are specified in *queues*
1348  * If the return value is less than *nb_links*, the remaining links at the end
1349  * of link[] are not established, and the caller has to take care of them.
1350  * If return value is less than *nb_links* then implementation shall update the
1351  * rte_errno accordingly, Possible rte_errno values are
1352  * (-EDQUOT) Quota exceeded(Application tried to link the queue configured with
1353  *  RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
1354  * (-EINVAL) Invalid parameter
1355  *
1356  */
1357 int
1358 rte_event_port_link(uint8_t dev_id, uint8_t port_id,
1359                     const uint8_t queues[], const uint8_t priorities[],
1360                     uint16_t nb_links);
1361
1362 /**
1363  * Unlink multiple source event queues supplied in *queues* from the destination
1364  * event port designated by its *port_id* on the event device designated
1365  * by its *dev_id*.
1366  *
1367  * The unlink establishment shall disable the event port *port_id* from
1368  * receiving events from the specified event queue *queue_id*
1369  *
1370  * Event queue(s) to event port unlink establishment can be changed at runtime
1371  * without re-configuring the device.
1372  *
1373  * @param dev_id
1374  *   The identifier of the device.
1375  *
1376  * @param port_id
1377  *   Event port identifier to select the destination port to unlink.
1378  *
1379  * @param queues
1380  *   Points to an array of *nb_unlinks* event queues to be unlinked
1381  *   from the event port.
1382  *   NULL value is allowed, in which case this function unlinks all the
1383  *   event queue(s) from the event port *port_id*.
1384  *
1385  * @param nb_unlinks
1386  *   The number of unlinks to establish. This parameter is ignored if queues is
1387  *   NULL.
1388  *
1389  * @return
1390  * The number of unlinks actually established. The return value can be less
1391  * than the value of the *nb_unlinks* parameter when the implementation has the
1392  * limitation on specific queue to port unlink establishment or
1393  * if invalid parameters are specified.
1394  * If the return value is less than *nb_unlinks*, the remaining queues at the
1395  * end of queues[] are not established, and the caller has to take care of them.
1396  * If return value is less than *nb_unlinks* then implementation shall update
1397  * the rte_errno accordingly, Possible rte_errno values are
1398  * (-EINVAL) Invalid parameter
1399  *
1400  */
1401 int
1402 rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
1403                       uint8_t queues[], uint16_t nb_unlinks);
1404
1405 /**
1406  * Retrieve the list of source event queues and its associated service priority
1407  * linked to the destination event port designated by its *port_id*
1408  * on the event device designated by its *dev_id*.
1409  *
1410  * @param dev_id
1411  *   The identifier of the device.
1412  *
1413  * @param port_id
1414  *   Event port identifier.
1415  *
1416  * @param[out] queues
1417  *   Points to an array of *queues* for output.
1418  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1419  *   store the event queue(s) linked with event port *port_id*
1420  *
1421  * @param[out] priorities
1422  *   Points to an array of *priorities* for output.
1423  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1424  *   store the service priority associated with each event queue linked
1425  *
1426  * @return
1427  * The number of links established on the event port designated by its
1428  *  *port_id*.
1429  * - <0 on failure.
1430  *
1431  */
1432 int
1433 rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
1434                          uint8_t queues[], uint8_t priorities[]);
1435
1436 /**
1437  * Dump internal information about *dev_id* to the FILE* provided in *f*.
1438  *
1439  * @param dev_id
1440  *   The identifier of the device.
1441  *
1442  * @param f
1443  *   A pointer to a file for output
1444  *
1445  * @return
1446  *   - 0: on success
1447  *   - <0: on failure.
1448  */
1449 int
1450 rte_event_dev_dump(uint8_t dev_id, FILE *f);
1451
1452 /** Maximum name length for extended statistics counters */
1453 #define RTE_EVENT_DEV_XSTATS_NAME_SIZE 64
1454
1455 /**
1456  * Selects the component of the eventdev to retrieve statistics from.
1457  */
1458 enum rte_event_dev_xstats_mode {
1459         RTE_EVENT_DEV_XSTATS_DEVICE,
1460         RTE_EVENT_DEV_XSTATS_PORT,
1461         RTE_EVENT_DEV_XSTATS_QUEUE,
1462 };
1463
1464 /**
1465  * A name-key lookup element for extended statistics.
1466  *
1467  * This structure is used to map between names and ID numbers
1468  * for extended ethdev statistics.
1469  */
1470 struct rte_event_dev_xstats_name {
1471         char name[RTE_EVENT_DEV_XSTATS_NAME_SIZE];
1472 };
1473
1474 /**
1475  * Retrieve names of extended statistics of an event device.
1476  *
1477  * @param dev_id
1478  *   The identifier of the event device.
1479  * @param mode
1480  *   The mode of statistics to retrieve. Choices include the device statistics,
1481  *   port statistics or queue statistics.
1482  * @param queue_port_id
1483  *   Used to specify the port or queue number in queue or port mode, and is
1484  *   ignored in device mode.
1485  * @param[out] xstats_names
1486  *   Block of memory to insert names into. Must be at least size in capacity.
1487  *   If set to NULL, function returns required capacity.
1488  * @param[out] ids
1489  *   Block of memory to insert ids into. Must be at least size in capacity.
1490  *   If set to NULL, function returns required capacity. The id values returned
1491  *   can be passed to *rte_event_dev_xstats_get* to select statistics.
1492  * @param size
1493  *   Capacity of xstats_names (number of names).
1494  * @return
1495  *   - positive value lower or equal to size: success. The return value
1496  *     is the number of entries filled in the stats table.
1497  *   - positive value higher than size: error, the given statistics table
1498  *     is too small. The return value corresponds to the size that should
1499  *     be given to succeed. The entries in the table are not valid and
1500  *     shall not be used by the caller.
1501  *   - negative value on error:
1502  *        -ENODEV for invalid *dev_id*
1503  *        -EINVAL for invalid mode, queue port or id parameters
1504  *        -ENOTSUP if the device doesn't support this function.
1505  */
1506 int
1507 rte_event_dev_xstats_names_get(uint8_t dev_id,
1508                                enum rte_event_dev_xstats_mode mode,
1509                                uint8_t queue_port_id,
1510                                struct rte_event_dev_xstats_name *xstats_names,
1511                                unsigned int *ids,
1512                                unsigned int size);
1513
1514 /**
1515  * Retrieve extended statistics of an event device.
1516  *
1517  * @param dev_id
1518  *   The identifier of the device.
1519  * @param mode
1520  *  The mode of statistics to retrieve. Choices include the device statistics,
1521  *  port statistics or queue statistics.
1522  * @param queue_port_id
1523  *   Used to specify the port or queue number in queue or port mode, and is
1524  *   ignored in device mode.
1525  * @param ids
1526  *   The id numbers of the stats to get. The ids can be got from the stat
1527  *   position in the stat list from rte_event_dev_get_xstats_names(), or
1528  *   by using rte_eventdev_get_xstats_by_name()
1529  * @param[out] values
1530  *   The values for each stats request by ID.
1531  * @param n
1532  *   The number of stats requested
1533  * @return
1534  *   - positive value: number of stat entries filled into the values array
1535  *   - negative value on error:
1536  *        -ENODEV for invalid *dev_id*
1537  *        -EINVAL for invalid mode, queue port or id parameters
1538  *        -ENOTSUP if the device doesn't support this function.
1539  */
1540 int
1541 rte_event_dev_xstats_get(uint8_t dev_id,
1542                          enum rte_event_dev_xstats_mode mode,
1543                          uint8_t queue_port_id,
1544                          const unsigned int ids[],
1545                          uint64_t values[], unsigned int n);
1546
1547 /**
1548  * Retrieve the value of a single stat by requesting it by name.
1549  *
1550  * @param dev_id
1551  *   The identifier of the device
1552  * @param name
1553  *   The stat name to retrieve
1554  * @param[out] id
1555  *   If non-NULL, the numerical id of the stat will be returned, so that further
1556  *   requests for the stat can be got using rte_eventdev_xstats_get, which will
1557  *   be faster as it doesn't need to scan a list of names for the stat.
1558  *   If the stat cannot be found, the id returned will be (unsigned)-1.
1559  * @return
1560  *   - positive value or zero: the stat value
1561  *   - negative value: -EINVAL if stat not found, -ENOTSUP if not supported.
1562  */
1563 uint64_t
1564 rte_event_dev_xstats_by_name_get(uint8_t dev_id, const char *name,
1565                                  unsigned int *id);
1566
1567 /**
1568  * Reset the values of the xstats of the selected component in the device.
1569  *
1570  * @param dev_id
1571  *   The identifier of the device
1572  * @param mode
1573  *   The mode of the statistics to reset. Choose from device, queue or port.
1574  * @param queue_port_id
1575  *   The queue or port to reset. 0 and positive values select ports and queues,
1576  *   while -1 indicates all ports or queues.
1577  * @param ids
1578  *   Selects specific statistics to be reset. When NULL, all statistics selected
1579  *   by *mode* will be reset. If non-NULL, must point to array of at least
1580  *   *nb_ids* size.
1581  * @param nb_ids
1582  *   The number of ids available from the *ids* array. Ignored when ids is NULL.
1583  * @return
1584  *   - zero: successfully reset the statistics to zero
1585  *   - negative value: -EINVAL invalid parameters, -ENOTSUP if not supported.
1586  */
1587 int
1588 rte_event_dev_xstats_reset(uint8_t dev_id,
1589                            enum rte_event_dev_xstats_mode mode,
1590                            int16_t queue_port_id,
1591                            const uint32_t ids[],
1592                            uint32_t nb_ids);
1593
1594 #ifdef __cplusplus
1595 }
1596 #endif
1597
1598 #endif /* _RTE_EVENTDEV_H_ */