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