e1bd05f12b85313a3288fb72b636c38557a72cef
[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  * An event driven based application has following typical workflow on fastpath:
203  * \code{.c}
204  *      while (1) {
205  *
206  *              rte_event_schedule(dev_id);
207  *
208  *              rte_event_dequeue(...);
209  *
210  *              (event processing)
211  *
212  *              rte_event_enqueue(...);
213  *      }
214  * \endcode
215  *
216  * The events are injected to event device through *enqueue* operation by
217  * event producers in the system. The typical event producers are ethdev
218  * subsystem for generating packet events, CPU(SW) for generating events based
219  * on different stages of application processing, cryptodev for generating
220  * crypto work completion notification etc
221  *
222  * The *dequeue* operation gets one or more events from the event ports.
223  * The application process the events and send to downstream event queue through
224  * rte_event_enqueue_burst() if it is an intermediate stage of event processing,
225  * on the final stage, the application may send to different subsystem like
226  * ethdev to send the packet/event on the wire using ethdev
227  * rte_eth_tx_burst() API.
228  *
229  * The point at which events are scheduled to ports depends on the device.
230  * For hardware devices, scheduling occurs asynchronously without any software
231  * intervention. Software schedulers can either be distributed
232  * (each worker thread schedules events to its own port) or centralized
233  * (a dedicated thread schedules to all ports). Distributed software schedulers
234  * perform the scheduling in rte_event_dequeue_burst(), whereas centralized
235  * scheduler logic is located in rte_event_schedule().
236  * The RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED capability flag is not set
237  * indicates the device is centralized and thus needs a dedicated scheduling
238  * thread that repeatedly calls rte_event_schedule().
239  *
240  */
241
242 #ifdef __cplusplus
243 extern "C" {
244 #endif
245
246 #include <rte_common.h>
247 #include <rte_pci.h>
248 #include <rte_mbuf.h>
249
250 /* Event device capability bitmap flags */
251 #define RTE_EVENT_DEV_CAP_QUEUE_QOS           (1ULL << 0)
252 /**< Event scheduling prioritization is based on the priority associated with
253  *  each event queue.
254  *
255  *  @see rte_event_queue_setup()
256  */
257 #define RTE_EVENT_DEV_CAP_EVENT_QOS           (1ULL << 1)
258 /**< Event scheduling prioritization is based on the priority associated with
259  *  each event. Priority of each event is supplied in *rte_event* structure
260  *  on each enqueue operation.
261  *
262  *  @see rte_event_enqueue_burst()
263  */
264 #define RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED   (1ULL << 2)
265 /**< Event device operates in distributed scheduling mode.
266  * In distributed scheduling mode, event scheduling happens in HW or
267  * rte_event_dequeue_burst() or the combination of these two.
268  * If the flag is not set then eventdev is centralized and thus needs a
269  * dedicated scheduling thread that repeatedly calls rte_event_schedule().
270  *
271  * @see rte_event_schedule(), rte_event_dequeue_burst()
272  */
273
274 /* Event device priority levels */
275 #define RTE_EVENT_DEV_PRIORITY_HIGHEST   0
276 /**< Highest priority expressed across eventdev subsystem
277  * @see rte_event_queue_setup(), rte_event_enqueue_burst()
278  * @see rte_event_port_link()
279  */
280 #define RTE_EVENT_DEV_PRIORITY_NORMAL    128
281 /**< Normal priority expressed across eventdev subsystem
282  * @see rte_event_queue_setup(), rte_event_enqueue_burst()
283  * @see rte_event_port_link()
284  */
285 #define RTE_EVENT_DEV_PRIORITY_LOWEST    255
286 /**< Lowest priority expressed across eventdev subsystem
287  * @see rte_event_queue_setup(), rte_event_enqueue_burst()
288  * @see rte_event_port_link()
289  */
290
291 /**
292  * Get the total number of event devices that have been successfully
293  * initialised.
294  *
295  * @return
296  *   The total number of usable event devices.
297  */
298 uint8_t
299 rte_event_dev_count(void);
300
301 /**
302  * Get the device identifier for the named event device.
303  *
304  * @param name
305  *   Event device name to select the event device identifier.
306  *
307  * @return
308  *   Returns event device identifier on success.
309  *   - <0: Failure to find named event device.
310  */
311 int
312 rte_event_dev_get_dev_id(const char *name);
313
314 /**
315  * Return the NUMA socket to which a device is connected.
316  *
317  * @param dev_id
318  *   The identifier of the device.
319  * @return
320  *   The NUMA socket id to which the device is connected or
321  *   a default of zero if the socket could not be determined.
322  *   -(-EINVAL)  dev_id value is out of range.
323  */
324 int
325 rte_event_dev_socket_id(uint8_t dev_id);
326
327 /**
328  * Event device information
329  */
330 struct rte_event_dev_info {
331         const char *driver_name;        /**< Event driver name */
332         struct rte_pci_device *pci_dev; /**< PCI information */
333         uint32_t min_dequeue_timeout_ns;
334         /**< Minimum supported global dequeue timeout(ns) by this device */
335         uint32_t max_dequeue_timeout_ns;
336         /**< Maximum supported global dequeue timeout(ns) by this device */
337         uint32_t dequeue_timeout_ns;
338         /**< Configured global dequeue timeout(ns) for this device */
339         uint8_t max_event_queues;
340         /**< Maximum event_queues supported by this device */
341         uint32_t max_event_queue_flows;
342         /**< Maximum supported flows in an event queue by this device*/
343         uint8_t max_event_queue_priority_levels;
344         /**< Maximum number of event queue priority levels by this device.
345          * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
346          */
347         uint8_t max_event_priority_levels;
348         /**< Maximum number of event priority levels by this device.
349          * Valid when the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability
350          */
351         uint8_t max_event_ports;
352         /**< Maximum number of event ports supported by this device */
353         uint8_t max_event_port_dequeue_depth;
354         /**< Maximum number of events can be dequeued at a time from an
355          * event port by this device.
356          * A device that does not support bulk dequeue will set this as 1.
357          */
358         uint32_t max_event_port_enqueue_depth;
359         /**< Maximum number of events can be enqueued at a time from an
360          * event port by this device.
361          * A device that does not support bulk enqueue will set this as 1.
362          */
363         int32_t max_num_events;
364         /**< A *closed system* event dev has a limit on the number of events it
365          * can manage at a time. An *open system* event dev does not have a
366          * limit and will specify this as -1.
367          */
368         uint32_t event_dev_cap;
369         /**< Event device capabilities(RTE_EVENT_DEV_CAP_)*/
370 };
371
372 /**
373  * Retrieve the contextual information of an event device.
374  *
375  * @param dev_id
376  *   The identifier of the device.
377  *
378  * @param[out] dev_info
379  *   A pointer to a structure of type *rte_event_dev_info* to be filled with the
380  *   contextual information of the device.
381  *
382  * @return
383  *   - 0: Success, driver updates the contextual information of the event device
384  *   - <0: Error code returned by the driver info get function.
385  *
386  */
387 int
388 rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info);
389
390 /* Event device configuration bitmap flags */
391 #define RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT (1ULL << 0)
392 /**< Override the global *dequeue_timeout_ns* and use per dequeue timeout in ns.
393  *  @see rte_event_dequeue_timeout_ticks(), rte_event_dequeue_burst()
394  */
395
396 /** Event device configuration structure */
397 struct rte_event_dev_config {
398         uint32_t dequeue_timeout_ns;
399         /**< rte_event_dequeue_burst() timeout on this device.
400          * This value should be in the range of *min_dequeue_timeout_ns* and
401          * *max_dequeue_timeout_ns* which previously provided in
402          * rte_event_dev_info_get()
403          * @see RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
404          */
405         int32_t nb_events_limit;
406         /**< Applies to *closed system* event dev only. This field indicates a
407          * limit to ethdev-like devices to limit the number of events injected
408          * into the system to not overwhelm core-to-core events.
409          * This value cannot exceed the *max_num_events* which previously
410          * provided in rte_event_dev_info_get()
411          */
412         uint8_t nb_event_queues;
413         /**< Number of event queues to configure on this device.
414          * This value cannot exceed the *max_event_queues* which previously
415          * provided in rte_event_dev_info_get()
416          */
417         uint8_t nb_event_ports;
418         /**< Number of event ports to configure on this device.
419          * This value cannot exceed the *max_event_ports* which previously
420          * provided in rte_event_dev_info_get()
421          */
422         uint32_t nb_event_queue_flows;
423         /**< Number of flows for any event queue on this device.
424          * This value cannot exceed the *max_event_queue_flows* which previously
425          * provided in rte_event_dev_info_get()
426          */
427         uint8_t nb_event_port_dequeue_depth;
428         /**< Maximum number of events can be dequeued at a time from an
429          * event port by this device.
430          * This value cannot exceed the *max_event_port_dequeue_depth*
431          * which previously provided in rte_event_dev_info_get()
432          * @see rte_event_port_setup()
433          */
434         uint32_t nb_event_port_enqueue_depth;
435         /**< Maximum number of events can be enqueued at a time from an
436          * event port by this device.
437          * This value cannot exceed the *max_event_port_enqueue_depth*
438          * which previously provided in rte_event_dev_info_get()
439          * @see rte_event_port_setup()
440          */
441         uint32_t event_dev_cfg;
442         /**< Event device config flags(RTE_EVENT_DEV_CFG_)*/
443 };
444
445 /**
446  * Configure an event device.
447  *
448  * This function must be invoked first before any other function in the
449  * API. This function can also be re-invoked when a device is in the
450  * stopped state.
451  *
452  * The caller may use rte_event_dev_info_get() to get the capability of each
453  * resources available for this event device.
454  *
455  * @param dev_id
456  *   The identifier of the device to configure.
457  * @param dev_conf
458  *   The event device configuration structure.
459  *
460  * @return
461  *   - 0: Success, device configured.
462  *   - <0: Error code returned by the driver configuration function.
463  */
464 int
465 rte_event_dev_configure(uint8_t dev_id,
466                         const struct rte_event_dev_config *dev_conf);
467
468
469 /* Event queue specific APIs */
470
471 /* Event queue configuration bitmap flags */
472 #define RTE_EVENT_QUEUE_CFG_DEFAULT            (0)
473 /**< Default value of *event_queue_cfg* when rte_event_queue_setup() invoked
474  * with queue_conf == NULL
475  *
476  * @see rte_event_queue_setup()
477  */
478 #define RTE_EVENT_QUEUE_CFG_TYPE_MASK          (3ULL << 0)
479 /**< Mask for event queue schedule type configuration request */
480 #define RTE_EVENT_QUEUE_CFG_ALL_TYPES          (0ULL << 0)
481 /**< Allow ATOMIC,ORDERED,PARALLEL schedule type enqueue
482  *
483  * @see RTE_SCHED_TYPE_ORDERED, RTE_SCHED_TYPE_ATOMIC, RTE_SCHED_TYPE_PARALLEL
484  * @see rte_event_enqueue_burst()
485  */
486 #define RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY        (1ULL << 0)
487 /**< Allow only ATOMIC schedule type enqueue
488  *
489  * The rte_event_enqueue_burst() result is undefined if the queue configured
490  * with ATOMIC only and sched_type != RTE_SCHED_TYPE_ATOMIC
491  *
492  * @see RTE_SCHED_TYPE_ATOMIC, rte_event_enqueue_burst()
493  */
494 #define RTE_EVENT_QUEUE_CFG_ORDERED_ONLY       (2ULL << 0)
495 /**< Allow only ORDERED schedule type enqueue
496  *
497  * The rte_event_enqueue_burst() result is undefined if the queue configured
498  * with ORDERED only and sched_type != RTE_SCHED_TYPE_ORDERED
499  *
500  * @see RTE_SCHED_TYPE_ORDERED, rte_event_enqueue_burst()
501  */
502 #define RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY      (3ULL << 0)
503 /**< Allow only PARALLEL schedule type enqueue
504  *
505  * The rte_event_enqueue_burst() result is undefined if the queue configured
506  * with PARALLEL only and sched_type != RTE_SCHED_TYPE_PARALLEL
507  *
508  * @see RTE_SCHED_TYPE_PARALLEL, rte_event_enqueue_burst()
509  */
510 #define RTE_EVENT_QUEUE_CFG_SINGLE_LINK        (1ULL << 2)
511 /**< This event queue links only to a single event port.
512  *
513  *  @see rte_event_port_setup(), rte_event_port_link()
514  */
515
516 /** Event queue configuration structure */
517 struct rte_event_queue_conf {
518         uint32_t nb_atomic_flows;
519         /**< The maximum number of active flows this queue can track at any
520          * given time. The value must be in the range of
521          * [1 - nb_event_queue_flows)] which previously provided in
522          * rte_event_dev_info_get().
523          */
524         uint32_t nb_atomic_order_sequences;
525         /**< The maximum number of outstanding events waiting to be
526          * reordered by this queue. In other words, the number of entries in
527          * this queue’s reorder buffer.When the number of events in the
528          * reorder buffer reaches to *nb_atomic_order_sequences* then the
529          * scheduler cannot schedule the events from this queue and invalid
530          * event will be returned from dequeue until one or more entries are
531          * freed up/released.
532          * The value must be in the range of [1 - nb_event_queue_flows)]
533          * which previously supplied to rte_event_dev_configure().
534          */
535         uint32_t event_queue_cfg; /**< Queue cfg flags(EVENT_QUEUE_CFG_) */
536         uint8_t priority;
537         /**< Priority for this event queue relative to other event queues.
538          * The requested priority should in the range of
539          * [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
540          * The implementation shall normalize the requested priority to
541          * event device supported priority value.
542          * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
543          */
544 };
545
546 /**
547  * Retrieve the default configuration information of an event queue designated
548  * by its *queue_id* from the event driver for an event device.
549  *
550  * This function intended to be used in conjunction with rte_event_queue_setup()
551  * where caller needs to set up the queue by overriding few default values.
552  *
553  * @param dev_id
554  *   The identifier of the device.
555  * @param queue_id
556  *   The index of the event queue to get the configuration information.
557  *   The value must be in the range [0, nb_event_queues - 1]
558  *   previously supplied to rte_event_dev_configure().
559  * @param[out] queue_conf
560  *   The pointer to the default event queue configuration data.
561  * @return
562  *   - 0: Success, driver updates the default event queue configuration data.
563  *   - <0: Error code returned by the driver info get function.
564  *
565  * @see rte_event_queue_setup()
566  *
567  */
568 int
569 rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
570                                  struct rte_event_queue_conf *queue_conf);
571
572 /**
573  * Allocate and set up an event queue for an event device.
574  *
575  * @param dev_id
576  *   The identifier of the device.
577  * @param queue_id
578  *   The index of the event queue to setup. The value must be in the range
579  *   [0, nb_event_queues - 1] previously supplied to rte_event_dev_configure().
580  * @param queue_conf
581  *   The pointer to the configuration data to be used for the event queue.
582  *   NULL value is allowed, in which case default configuration used.
583  *
584  * @see rte_event_queue_default_conf_get()
585  *
586  * @return
587  *   - 0: Success, event queue correctly set up.
588  *   - <0: event queue configuration failed
589  */
590 int
591 rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
592                       const struct rte_event_queue_conf *queue_conf);
593
594 /**
595  * Get the number of event queues on a specific event device
596  *
597  * @param dev_id
598  *   Event device identifier.
599  * @return
600  *   - The number of configured event queues
601  */
602 uint8_t
603 rte_event_queue_count(uint8_t dev_id);
604
605 /**
606  * Get the priority of the event queue on a specific event device
607  *
608  * @param dev_id
609  *   Event device identifier.
610  * @param queue_id
611  *   Event queue identifier.
612  * @return
613  *   - If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then the
614  *    configured priority of the event queue in
615  *    [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST] range
616  *    else the value RTE_EVENT_DEV_PRIORITY_NORMAL
617  */
618 uint8_t
619 rte_event_queue_priority(uint8_t dev_id, uint8_t queue_id);
620
621 /* Event port specific APIs */
622
623 /** Event port configuration structure */
624 struct rte_event_port_conf {
625         int32_t new_event_threshold;
626         /**< A backpressure threshold for new event enqueues on this port.
627          * Use for *closed system* event dev where event capacity is limited,
628          * and cannot exceed the capacity of the event dev.
629          * Configuring ports with different thresholds can make higher priority
630          * traffic less likely to  be backpressured.
631          * For example, a port used to inject NIC Rx packets into the event dev
632          * can have a lower threshold so as not to overwhelm the device,
633          * while ports used for worker pools can have a higher threshold.
634          * This value cannot exceed the *nb_events_limit*
635          * which previously supplied to rte_event_dev_configure()
636          */
637         uint8_t dequeue_depth;
638         /**< Configure number of bulk dequeues for this event port.
639          * This value cannot exceed the *nb_event_port_dequeue_depth*
640          * which previously supplied to rte_event_dev_configure()
641          */
642         uint8_t enqueue_depth;
643         /**< Configure number of bulk enqueues for this event port.
644          * This value cannot exceed the *nb_event_port_enqueue_depth*
645          * which previously supplied to rte_event_dev_configure()
646          */
647 };
648
649 /**
650  * Retrieve the default configuration information of an event port designated
651  * by its *port_id* from the event driver for an event device.
652  *
653  * This function intended to be used in conjunction with rte_event_port_setup()
654  * where caller needs to set up the port by overriding few default values.
655  *
656  * @param dev_id
657  *   The identifier of the device.
658  * @param port_id
659  *   The index of the event port to get the configuration information.
660  *   The value must be in the range [0, nb_event_ports - 1]
661  *   previously supplied to rte_event_dev_configure().
662  * @param[out] port_conf
663  *   The pointer to the default event port configuration data
664  * @return
665  *   - 0: Success, driver updates the default event port configuration data.
666  *   - <0: Error code returned by the driver info get function.
667  *
668  * @see rte_event_port_setup()
669  *
670  */
671 int
672 rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
673                                 struct rte_event_port_conf *port_conf);
674
675 /**
676  * Allocate and set up an event port for an event device.
677  *
678  * @param dev_id
679  *   The identifier of the device.
680  * @param port_id
681  *   The index of the event port to setup. The value must be in the range
682  *   [0, nb_event_ports - 1] previously supplied to rte_event_dev_configure().
683  * @param port_conf
684  *   The pointer to the configuration data to be used for the queue.
685  *   NULL value is allowed, in which case default configuration used.
686  *
687  * @see rte_event_port_default_conf_get()
688  *
689  * @return
690  *   - 0: Success, event port correctly set up.
691  *   - <0: Port configuration failed
692  *   - (-EDQUOT) Quota exceeded(Application tried to link the queue configured
693  *   with RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
694  */
695 int
696 rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
697                      const struct rte_event_port_conf *port_conf);
698
699 /**
700  * Get the number of dequeue queue depth configured for event port designated
701  * by its *port_id* on a specific event device
702  *
703  * @param dev_id
704  *   Event device identifier.
705  * @param port_id
706  *   Event port identifier.
707  * @return
708  *   - The number of configured dequeue queue depth
709  *
710  * @see rte_event_dequeue_burst()
711  */
712 uint8_t
713 rte_event_port_dequeue_depth(uint8_t dev_id, uint8_t port_id);
714
715 /**
716  * Get the number of enqueue queue depth configured for event port designated
717  * by its *port_id* on a specific event device
718  *
719  * @param dev_id
720  *   Event device identifier.
721  * @param port_id
722  *   Event port identifier.
723  * @return
724  *   - The number of configured enqueue queue depth
725  *
726  * @see rte_event_enqueue_burst()
727  */
728 uint8_t
729 rte_event_port_enqueue_depth(uint8_t dev_id, uint8_t port_id);
730
731 /**
732  * Get the number of ports on a specific event device
733  *
734  * @param dev_id
735  *   Event device identifier.
736  * @return
737  *   - The number of configured ports
738  */
739 uint8_t
740 rte_event_port_count(uint8_t dev_id);
741
742 /**
743  * Start an event device.
744  *
745  * The device start step is the last one and consists of setting the event
746  * queues to start accepting the events and schedules to event ports.
747  *
748  * On success, all basic functions exported by the API (event enqueue,
749  * event dequeue and so on) can be invoked.
750  *
751  * @param dev_id
752  *   Event device identifier
753  * @return
754  *   - 0: Success, device started.
755  *   - <0: Error code of the driver device start function.
756  */
757 int
758 rte_event_dev_start(uint8_t dev_id);
759
760 /**
761  * Stop an event device. The device can be restarted with a call to
762  * rte_event_dev_start()
763  *
764  * @param dev_id
765  *   Event device identifier.
766  */
767 void
768 rte_event_dev_stop(uint8_t dev_id);
769
770 /**
771  * Close an event device. The device cannot be restarted!
772  *
773  * @param dev_id
774  *   Event device identifier
775  *
776  * @return
777  *  - 0 on successfully closing device
778  *  - <0 on failure to close device
779  *  - (-EAGAIN) if device is busy
780  */
781 int
782 rte_event_dev_close(uint8_t dev_id);
783
784 /* Scheduler type definitions */
785 #define RTE_SCHED_TYPE_ORDERED          0
786 /**< Ordered scheduling
787  *
788  * Events from an ordered flow of an event queue can be scheduled to multiple
789  * ports for concurrent processing while maintaining the original event order.
790  * This scheme enables the user to achieve high single flow throughput by
791  * avoiding SW synchronization for ordering between ports which bound to cores.
792  *
793  * The source flow ordering from an event queue is maintained when events are
794  * enqueued to their destination queue within the same ordered flow context.
795  * An event port holds the context until application call
796  * rte_event_dequeue_burst() from the same port, which implicitly releases
797  * the context.
798  * User may allow the scheduler to release the context earlier than that
799  * by invoking rte_event_enqueue_burst() with RTE_EVENT_OP_RELEASE operation.
800  *
801  * Events from the source queue appear in their original order when dequeued
802  * from a destination queue.
803  * Event ordering is based on the received event(s), but also other
804  * (newly allocated or stored) events are ordered when enqueued within the same
805  * ordered context. Events not enqueued (e.g. released or stored) within the
806  * context are  considered missing from reordering and are skipped at this time
807  * (but can be ordered again within another context).
808  *
809  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
810  */
811
812 #define RTE_SCHED_TYPE_ATOMIC           1
813 /**< Atomic scheduling
814  *
815  * Events from an atomic flow of an event queue can be scheduled only to a
816  * single port at a time. The port is guaranteed to have exclusive (atomic)
817  * access to the associated flow context, which enables the user to avoid SW
818  * synchronization. Atomic flows also help to maintain event ordering
819  * since only one port at a time can process events from a flow of an
820  * event queue.
821  *
822  * The atomic queue synchronization context is dedicated to the port until
823  * application call rte_event_dequeue_burst() from the same port,
824  * which implicitly releases the context. User may allow the scheduler to
825  * release the context earlier than that by invoking rte_event_enqueue_burst()
826  * with RTE_EVENT_OP_RELEASE operation.
827  *
828  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
829  */
830
831 #define RTE_SCHED_TYPE_PARALLEL         2
832 /**< Parallel scheduling
833  *
834  * The scheduler performs priority scheduling, load balancing, etc. functions
835  * but does not provide additional event synchronization or ordering.
836  * It is free to schedule events from a single parallel flow of an event queue
837  * to multiple events ports for concurrent processing.
838  * The application is responsible for flow context synchronization and
839  * event ordering (SW synchronization).
840  *
841  * @see rte_event_queue_setup(), rte_event_dequeue_burst()
842  */
843
844 /* Event types to classify the event source */
845 #define RTE_EVENT_TYPE_ETHDEV           0x0
846 /**< The event generated from ethdev subsystem */
847 #define RTE_EVENT_TYPE_CRYPTODEV        0x1
848 /**< The event generated from crypodev subsystem */
849 #define RTE_EVENT_TYPE_TIMERDEV         0x2
850 /**< The event generated from timerdev subsystem */
851 #define RTE_EVENT_TYPE_CPU              0x3
852 /**< The event generated from cpu for pipelining.
853  * Application may use *sub_event_type* to further classify the event
854  */
855 #define RTE_EVENT_TYPE_MAX              0x10
856 /**< Maximum number of event types */
857
858 /* Event enqueue operations */
859 #define RTE_EVENT_OP_NEW                0
860 /**< The event producers use this operation to inject a new event to the
861  * event device.
862  */
863 #define RTE_EVENT_OP_FORWARD            1
864 /**< The CPU use this operation to forward the event to different event queue or
865  * change to new application specific flow or schedule type to enable
866  * pipelining
867  */
868 #define RTE_EVENT_OP_RELEASE            2
869 /**< Release the flow context associated with the schedule type.
870  *
871  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ATOMIC*
872  * then this function hints the scheduler that the user has completed critical
873  * section processing in the current atomic context.
874  * The scheduler is now allowed to schedule events from the same flow from
875  * an event queue to another port. However, the context may be still held
876  * until the next rte_event_dequeue_burst() call, this call allows but does not
877  * force the scheduler to release the context early.
878  *
879  * Early atomic context release may increase parallelism and thus system
880  * performance, but the user needs to design carefully the split into critical
881  * vs non-critical sections.
882  *
883  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ORDERED*
884  * then this function hints the scheduler that the user has done all that need
885  * to maintain event order in the current ordered context.
886  * The scheduler is allowed to release the ordered context of this port and
887  * avoid reordering any following enqueues.
888  *
889  * Early ordered context release may increase parallelism and thus system
890  * performance.
891  *
892  * If current flow's scheduler type method is *RTE_SCHED_TYPE_PARALLEL*
893  * or no scheduling context is held then this function may be an NOOP,
894  * depending on the implementation.
895  *
896  */
897
898 /**
899  * The generic *rte_event* structure to hold the event attributes
900  * for dequeue and enqueue operation
901  */
902 struct rte_event {
903         /** WORD0 */
904         RTE_STD_C11
905         union {
906                 uint64_t event;
907                 /** Event attributes for dequeue or enqueue operation */
908                 struct {
909                         uint32_t flow_id:20;
910                         /**< Targeted flow identifier for the enqueue and
911                          * dequeue operation.
912                          * The value must be in the range of
913                          * [0, nb_event_queue_flows - 1] which
914                          * previously supplied to rte_event_dev_configure().
915                          */
916                         uint32_t sub_event_type:8;
917                         /**< Sub-event types based on the event source.
918                          * @see RTE_EVENT_TYPE_CPU
919                          */
920                         uint32_t event_type:4;
921                         /**< Event type to classify the event source.
922                          * @see RTE_EVENT_TYPE_ETHDEV, (RTE_EVENT_TYPE_*)
923                          */
924                         uint8_t op:2;
925                         /**< The type of event enqueue operation - new/forward/
926                          * etc.This field is not preserved across an instance
927                          * and is undefined on dequeue.
928                          * @see RTE_EVENT_OP_NEW, (RTE_EVENT_OP_*)
929                          */
930                         uint8_t rsvd:4;
931                         /**< Reserved for future use */
932                         uint8_t sched_type:2;
933                         /**< Scheduler synchronization type (RTE_SCHED_TYPE_*)
934                          * associated with flow id on a given event queue
935                          * for the enqueue and dequeue operation.
936                          */
937                         uint8_t queue_id;
938                         /**< Targeted event queue identifier for the enqueue or
939                          * dequeue operation.
940                          * The value must be in the range of
941                          * [0, nb_event_queues - 1] which previously supplied to
942                          * rte_event_dev_configure().
943                          */
944                         uint8_t priority;
945                         /**< Event priority relative to other events in the
946                          * event queue. The requested priority should in the
947                          * range of  [RTE_EVENT_DEV_PRIORITY_HIGHEST,
948                          * RTE_EVENT_DEV_PRIORITY_LOWEST].
949                          * The implementation shall normalize the requested
950                          * priority to supported priority value.
951                          * Valid when the device has
952                          * RTE_EVENT_DEV_CAP_EVENT_QOS capability.
953                          */
954                         uint8_t impl_opaque;
955                         /**< Implementation specific opaque value.
956                          * An implementation may use this field to hold
957                          * implementation specific value to share between
958                          * dequeue and enqueue operation.
959                          * The application should not modify this field.
960                          */
961                 };
962         };
963         /** WORD1 */
964         RTE_STD_C11
965         union {
966                 uint64_t u64;
967                 /**< Opaque 64-bit value */
968                 void *event_ptr;
969                 /**< Opaque event pointer */
970                 struct rte_mbuf *mbuf;
971                 /**< mbuf pointer if dequeued event is associated with mbuf */
972         };
973 };
974
975
976 struct rte_eventdev_driver;
977 struct rte_eventdev_ops;
978 struct rte_eventdev;
979
980 typedef void (*event_schedule_t)(struct rte_eventdev *dev);
981 /**< @internal Schedule one or more events in the event dev. */
982
983 typedef uint16_t (*event_enqueue_t)(void *port, const struct rte_event *ev);
984 /**< @internal Enqueue event on port of a device */
985
986 typedef uint16_t (*event_enqueue_burst_t)(void *port,
987                         const struct rte_event ev[], uint16_t nb_events);
988 /**< @internal Enqueue burst of events on port of a device */
989
990 typedef uint16_t (*event_dequeue_t)(void *port, struct rte_event *ev,
991                 uint64_t timeout_ticks);
992 /**< @internal Dequeue event from port of a device */
993
994 typedef uint16_t (*event_dequeue_burst_t)(void *port, struct rte_event ev[],
995                 uint16_t nb_events, uint64_t timeout_ticks);
996 /**< @internal Dequeue burst of events from port of a device */
997
998 #define RTE_EVENTDEV_NAME_MAX_LEN       (64)
999 /**< @internal Max length of name of event PMD */
1000
1001 /**
1002  * @internal
1003  * The data part, with no function pointers, associated with each device.
1004  *
1005  * This structure is safe to place in shared memory to be common among
1006  * different processes in a multi-process configuration.
1007  */
1008 struct rte_eventdev_data {
1009         int socket_id;
1010         /**< Socket ID where memory is allocated */
1011         uint8_t dev_id;
1012         /**< Device ID for this instance */
1013         uint8_t nb_queues;
1014         /**< Number of event queues. */
1015         uint8_t nb_ports;
1016         /**< Number of event ports. */
1017         void **ports;
1018         /**< Array of pointers to ports. */
1019         uint8_t *ports_dequeue_depth;
1020         /**< Array of port dequeue depth. */
1021         uint8_t *ports_enqueue_depth;
1022         /**< Array of port enqueue depth. */
1023         uint8_t *queues_prio;
1024         /**< Array of queue priority. */
1025         uint16_t *links_map;
1026         /**< Memory to store queues to port connections. */
1027         void *dev_private;
1028         /**< PMD-specific private data */
1029         uint32_t event_dev_cap;
1030         /**< Event device capabilities(RTE_EVENT_DEV_CAP_)*/
1031         struct rte_event_dev_config dev_conf;
1032         /**< Configuration applied to device. */
1033
1034         RTE_STD_C11
1035         uint8_t dev_started : 1;
1036         /**< Device state: STARTED(1)/STOPPED(0) */
1037
1038         char name[RTE_EVENTDEV_NAME_MAX_LEN];
1039         /**< Unique identifier name */
1040 } __rte_cache_aligned;
1041
1042 /** @internal The data structure associated with each event device. */
1043 struct rte_eventdev {
1044         event_schedule_t schedule;
1045         /**< Pointer to PMD schedule function. */
1046         event_enqueue_t enqueue;
1047         /**< Pointer to PMD enqueue function. */
1048         event_enqueue_burst_t enqueue_burst;
1049         /**< Pointer to PMD enqueue burst function. */
1050         event_dequeue_t dequeue;
1051         /**< Pointer to PMD dequeue function. */
1052         event_dequeue_burst_t dequeue_burst;
1053         /**< Pointer to PMD dequeue burst function. */
1054
1055         struct rte_eventdev_data *data;
1056         /**< Pointer to device data */
1057         const struct rte_eventdev_ops *dev_ops;
1058         /**< Functions exported by PMD */
1059         struct rte_pci_device *pci_dev;
1060         /**< PCI info. supplied by probing */
1061         const struct rte_eventdev_driver *driver;
1062         /**< Driver for this device */
1063
1064         RTE_STD_C11
1065         uint8_t attached : 1;
1066         /**< Flag indicating the device is attached */
1067 } __rte_cache_aligned;
1068
1069 extern struct rte_eventdev *rte_eventdevs;
1070 /** @internal The pool of rte_eventdev structures. */
1071
1072
1073 /**
1074  * Schedule one or more events in the event dev.
1075  *
1076  * An event dev implementation may define this is a NOOP, for instance if
1077  * the event dev performs its scheduling in hardware.
1078  *
1079  * @param dev_id
1080  *   The identifier of the device.
1081  */
1082 static inline void
1083 rte_event_schedule(uint8_t dev_id)
1084 {
1085         struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1086         if (*dev->schedule)
1087                 (*dev->schedule)(dev);
1088 }
1089
1090 /**
1091  * Enqueue a burst of events objects or an event object supplied in *rte_event*
1092  * structure on an  event device designated by its *dev_id* through the event
1093  * port specified by *port_id*. Each event object specifies the event queue on
1094  * which it will be enqueued.
1095  *
1096  * The *nb_events* parameter is the number of event objects to enqueue which are
1097  * supplied in the *ev* array of *rte_event* structure.
1098  *
1099  * The rte_event_enqueue_burst() function returns the number of
1100  * events objects it actually enqueued. A return value equal to *nb_events*
1101  * means that all event objects have been enqueued.
1102  *
1103  * @param dev_id
1104  *   The identifier of the device.
1105  * @param port_id
1106  *   The identifier of the event port.
1107  * @param ev
1108  *   Points to an array of *nb_events* objects of type *rte_event* structure
1109  *   which contain the event object enqueue operations to be processed.
1110  * @param nb_events
1111  *   The number of event objects to enqueue, typically number of
1112  *   rte_event_port_enqueue_depth() available for this port.
1113  *
1114  * @return
1115  *   The number of event objects actually enqueued on the event device. The
1116  *   return value can be less than the value of the *nb_events* parameter when
1117  *   the event devices queue is full or if invalid parameters are specified in a
1118  *   *rte_event*. If return value is less than *nb_events*, the remaining events
1119  *   at the end of ev[] are not consumed,and the caller has to take care of them
1120  *
1121  * @see rte_event_port_enqueue_depth()
1122  */
1123 static inline uint16_t
1124 rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1125                         const struct rte_event ev[], uint16_t nb_events)
1126 {
1127         struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1128
1129         /*
1130          * Allow zero cost non burst mode routine invocation if application
1131          * requests nb_events as const one
1132          */
1133         if (nb_events == 1)
1134                 return (*dev->enqueue)(
1135                         dev->data->ports[port_id], ev);
1136         else
1137                 return (*dev->enqueue_burst)(
1138                         dev->data->ports[port_id], ev, nb_events);
1139 }
1140
1141 /**
1142  * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue_burst()
1143  *
1144  * If the device is configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT flag
1145  * then application can use this function to convert timeout value in
1146  * nanoseconds to implementations specific timeout value supplied in
1147  * rte_event_dequeue_burst()
1148  *
1149  * @param dev_id
1150  *   The identifier of the device.
1151  * @param ns
1152  *   Wait time in nanosecond
1153  * @param[out] timeout_ticks
1154  *   Value for the *timeout_ticks* parameter in rte_event_dequeue_burst()
1155  *
1156  * @return
1157  *  - 0 on success.
1158  *  - <0 on failure.
1159  *
1160  * @see rte_event_dequeue_burst(), RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1161  * @see rte_event_dev_configure()
1162  *
1163  */
1164 int
1165 rte_event_dequeue_timeout_ticks(uint8_t dev_id, uint64_t ns,
1166                                         uint64_t *timeout_ticks);
1167
1168 /**
1169  * Dequeue a burst of events objects or an event object from the event port
1170  * designated by its *event_port_id*, on an event device designated
1171  * by its *dev_id*.
1172  *
1173  * rte_event_dequeue_burst() does not dictate the specifics of scheduling
1174  * algorithm as each eventdev driver may have different criteria to schedule
1175  * an event. However, in general, from an application perspective scheduler may
1176  * use the following scheme to dispatch an event to the port.
1177  *
1178  * 1) Selection of event queue based on
1179  *   a) The list of event queues are linked to the event port.
1180  *   b) If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then event
1181  *   queue selection from list is based on event queue priority relative to
1182  *   other event queue supplied as *priority* in rte_event_queue_setup()
1183  *   c) If the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability then event
1184  *   queue selection from the list is based on event priority supplied as
1185  *   *priority* in rte_event_enqueue_burst()
1186  * 2) Selection of event
1187  *   a) The number of flows available in selected event queue.
1188  *   b) Schedule type method associated with the event
1189  *
1190  * The *nb_events* parameter is the maximum number of event objects to dequeue
1191  * which are returned in the *ev* array of *rte_event* structure.
1192  *
1193  * The rte_event_dequeue_burst() function returns the number of events objects
1194  * it actually dequeued. A return value equal to *nb_events* means that all
1195  * event objects have been dequeued.
1196  *
1197  * The number of events dequeued is the number of scheduler contexts held by
1198  * this port. These contexts are automatically released in the next
1199  * rte_event_dequeue_burst() invocation, or invoking rte_event_enqueue_burst()
1200  * with RTE_EVENT_OP_RELEASE operation can be used to release the
1201  * contexts early.
1202  *
1203  * @param dev_id
1204  *   The identifier of the device.
1205  * @param port_id
1206  *   The identifier of the event port.
1207  * @param[out] ev
1208  *   Points to an array of *nb_events* objects of type *rte_event* structure
1209  *   for output to be populated with the dequeued event objects.
1210  * @param nb_events
1211  *   The maximum number of event objects to dequeue, typically number of
1212  *   rte_event_port_dequeue_depth() available for this port.
1213  *
1214  * @param timeout_ticks
1215  *   - 0 no-wait, returns immediately if there is no event.
1216  *   - >0 wait for the event, if the device is configured with
1217  *   RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT then this function will wait until
1218  *   the event available or *timeout_ticks* time.
1219  *   if the device is not configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1220  *   then this function will wait until the event available or
1221  *   *dequeue_timeout_ns* ns which was previously supplied to
1222  *   rte_event_dev_configure()
1223  *
1224  * @return
1225  * The number of event objects actually dequeued from the port. The return
1226  * value can be less than the value of the *nb_events* parameter when the
1227  * event port's queue is not full.
1228  *
1229  * @see rte_event_port_dequeue_depth()
1230  */
1231 static inline uint16_t
1232 rte_event_dequeue_burst(uint8_t dev_id, uint8_t port_id, struct rte_event ev[],
1233                         uint16_t nb_events, uint64_t timeout_ticks)
1234 {
1235         struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1236
1237         /*
1238          * Allow zero cost non burst mode routine invocation if application
1239          * requests nb_events as const one
1240          */
1241         if (nb_events == 1)
1242                 return (*dev->dequeue)(
1243                         dev->data->ports[port_id], ev, timeout_ticks);
1244         else
1245                 return (*dev->dequeue_burst)(
1246                         dev->data->ports[port_id], ev, nb_events,
1247                                 timeout_ticks);
1248 }
1249
1250 /**
1251  * Link multiple source event queues supplied in *queues* to the destination
1252  * event port designated by its *port_id* with associated service priority
1253  * supplied in *priorities* on the event device designated by its *dev_id*.
1254  *
1255  * The link establishment shall enable the event port *port_id* from
1256  * receiving events from the specified event queue(s) supplied in *queues*
1257  *
1258  * An event queue may link to one or more event ports.
1259  * The number of links can be established from an event queue to event port is
1260  * implementation defined.
1261  *
1262  * Event queue(s) to event port link establishment can be changed at runtime
1263  * without re-configuring the device to support scaling and to reduce the
1264  * latency of critical work by establishing the link with more event ports
1265  * at runtime.
1266  *
1267  * @param dev_id
1268  *   The identifier of the device.
1269  *
1270  * @param port_id
1271  *   Event port identifier to select the destination port to link.
1272  *
1273  * @param queues
1274  *   Points to an array of *nb_links* event queues to be linked
1275  *   to the event port.
1276  *   NULL value is allowed, in which case this function links all the configured
1277  *   event queues *nb_event_queues* which previously supplied to
1278  *   rte_event_dev_configure() to the event port *port_id*
1279  *
1280  * @param priorities
1281  *   Points to an array of *nb_links* service priorities associated with each
1282  *   event queue link to event port.
1283  *   The priority defines the event port's servicing priority for
1284  *   event queue, which may be ignored by an implementation.
1285  *   The requested priority should in the range of
1286  *   [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
1287  *   The implementation shall normalize the requested priority to
1288  *   implementation supported priority value.
1289  *   NULL value is allowed, in which case this function links the event queues
1290  *   with RTE_EVENT_DEV_PRIORITY_NORMAL servicing priority
1291  *
1292  * @param nb_links
1293  *   The number of links to establish
1294  *
1295  * @return
1296  * The number of links actually established. The return value can be less than
1297  * the value of the *nb_links* parameter when the implementation has the
1298  * limitation on specific queue to port link establishment or if invalid
1299  * parameters are specified in *queues*
1300  * If the return value is less than *nb_links*, the remaining links at the end
1301  * of link[] are not established, and the caller has to take care of them.
1302  * If return value is less than *nb_links* then implementation shall update the
1303  * rte_errno accordingly, Possible rte_errno values are
1304  * (-EDQUOT) Quota exceeded(Application tried to link the queue configured with
1305  *  RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
1306  * (-EINVAL) Invalid parameter
1307  *
1308  */
1309 int
1310 rte_event_port_link(uint8_t dev_id, uint8_t port_id,
1311                     const uint8_t queues[], const uint8_t priorities[],
1312                     uint16_t nb_links);
1313
1314 /**
1315  * Unlink multiple source event queues supplied in *queues* from the destination
1316  * event port designated by its *port_id* on the event device designated
1317  * by its *dev_id*.
1318  *
1319  * The unlink establishment shall disable the event port *port_id* from
1320  * receiving events from the specified event queue *queue_id*
1321  *
1322  * Event queue(s) to event port unlink establishment can be changed at runtime
1323  * without re-configuring the device.
1324  *
1325  * @param dev_id
1326  *   The identifier of the device.
1327  *
1328  * @param port_id
1329  *   Event port identifier to select the destination port to unlink.
1330  *
1331  * @param queues
1332  *   Points to an array of *nb_unlinks* event queues to be unlinked
1333  *   from the event port.
1334  *   NULL value is allowed, in which case this function unlinks all the
1335  *   event queue(s) from the event port *port_id*.
1336  *
1337  * @param nb_unlinks
1338  *   The number of unlinks to establish
1339  *
1340  * @return
1341  * The number of unlinks actually established. The return value can be less
1342  * than the value of the *nb_unlinks* parameter when the implementation has the
1343  * limitation on specific queue to port unlink establishment or
1344  * if invalid parameters are specified.
1345  * If the return value is less than *nb_unlinks*, the remaining queues at the
1346  * end of queues[] are not established, and the caller has to take care of them.
1347  * If return value is less than *nb_unlinks* then implementation shall update
1348  * the rte_errno accordingly, Possible rte_errno values are
1349  * (-EINVAL) Invalid parameter
1350  *
1351  */
1352 int
1353 rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
1354                       uint8_t queues[], uint16_t nb_unlinks);
1355
1356 /**
1357  * Retrieve the list of source event queues and its associated service priority
1358  * linked to the destination event port designated by its *port_id*
1359  * on the event device designated by its *dev_id*.
1360  *
1361  * @param dev_id
1362  *   The identifier of the device.
1363  *
1364  * @param port_id
1365  *   Event port identifier.
1366  *
1367  * @param[out] queues
1368  *   Points to an array of *queues* for output.
1369  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1370  *   store the event queue(s) linked with event port *port_id*
1371  *
1372  * @param[out] priorities
1373  *   Points to an array of *priorities* for output.
1374  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1375  *   store the service priority associated with each event queue linked
1376  *
1377  * @return
1378  * The number of links established on the event port designated by its
1379  *  *port_id*.
1380  * - <0 on failure.
1381  *
1382  */
1383 int
1384 rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
1385                          uint8_t queues[], uint8_t priorities[]);
1386
1387 /**
1388  * Dump internal information about *dev_id* to the FILE* provided in *f*.
1389  *
1390  * @param dev_id
1391  *   The identifier of the device.
1392  *
1393  * @param f
1394  *   A pointer to a file for output
1395  *
1396  * @return
1397  *   - 0: on success
1398  *   - <0: on failure.
1399  */
1400 int
1401 rte_event_dev_dump(uint8_t dev_id, FILE *f);
1402
1403 #ifdef __cplusplus
1404 }
1405 #endif
1406
1407 #endif /* _RTE_EVENTDEV_H_ */