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