eventdev: bump library version
[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  * The status of the device, zero for stopped, non-zero for started.
412  */
413 #define RTE_EVENT_DEV_ATTR_STARTED 2
414
415 /**
416  * Get an attribute from a device.
417  *
418  * @param dev_id Eventdev id
419  * @param attr_id The attribute ID to retrieve
420  * @param[out] attr_value A pointer that will be filled in with the attribute
421  *             value if successful.
422  *
423  * @retval 0 Successfully retrieved attribute value
424  *         -EINVAL Invalid device or  *attr_id* provided, or *attr_value*
425  *         is NULL
426  */
427 int
428 rte_event_dev_attr_get(uint8_t dev_id, uint32_t attr_id,
429                        uint32_t *attr_value);
430
431
432 /* Event device configuration bitmap flags */
433 #define RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT (1ULL << 0)
434 /**< Override the global *dequeue_timeout_ns* and use per dequeue timeout in ns.
435  *  @see rte_event_dequeue_timeout_ticks(), rte_event_dequeue_burst()
436  */
437
438 /** Event device configuration structure */
439 struct rte_event_dev_config {
440         uint32_t dequeue_timeout_ns;
441         /**< rte_event_dequeue_burst() timeout on this device.
442          * This value should be in the range of *min_dequeue_timeout_ns* and
443          * *max_dequeue_timeout_ns* which previously provided in
444          * rte_event_dev_info_get()
445          * The value 0 is allowed, in which case, default dequeue timeout used.
446          * @see RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
447          */
448         int32_t nb_events_limit;
449         /**< In a *closed system* this field is the limit on maximum number of
450          * events that can be inflight in the eventdev at a given time. The
451          * limit is required to ensure that the finite space in a closed system
452          * is not overwhelmed. The value cannot exceed the *max_num_events*
453          * as provided by rte_event_dev_info_get().
454          * This value should be set to -1 for *open system*.
455          */
456         uint8_t nb_event_queues;
457         /**< Number of event queues to configure on this device.
458          * This value cannot exceed the *max_event_queues* which previously
459          * provided in rte_event_dev_info_get()
460          */
461         uint8_t nb_event_ports;
462         /**< Number of event ports to configure on this device.
463          * This value cannot exceed the *max_event_ports* which previously
464          * provided in rte_event_dev_info_get()
465          */
466         uint32_t nb_event_queue_flows;
467         /**< Number of flows for any event queue on this device.
468          * This value cannot exceed the *max_event_queue_flows* which previously
469          * provided in rte_event_dev_info_get()
470          */
471         uint32_t nb_event_port_dequeue_depth;
472         /**< Maximum number of events can be dequeued at a time from an
473          * event port by this device.
474          * This value cannot exceed the *max_event_port_dequeue_depth*
475          * which previously provided in rte_event_dev_info_get().
476          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
477          * @see rte_event_port_setup()
478          */
479         uint32_t nb_event_port_enqueue_depth;
480         /**< Maximum number of events can be enqueued at a time from an
481          * event port by this device.
482          * This value cannot exceed the *max_event_port_enqueue_depth*
483          * which previously provided in rte_event_dev_info_get().
484          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
485          * @see rte_event_port_setup()
486          */
487         uint32_t event_dev_cfg;
488         /**< Event device config flags(RTE_EVENT_DEV_CFG_)*/
489 };
490
491 /**
492  * Configure an event device.
493  *
494  * This function must be invoked first before any other function in the
495  * API. This function can also be re-invoked when a device is in the
496  * stopped state.
497  *
498  * The caller may use rte_event_dev_info_get() to get the capability of each
499  * resources available for this event device.
500  *
501  * @param dev_id
502  *   The identifier of the device to configure.
503  * @param dev_conf
504  *   The event device configuration structure.
505  *
506  * @return
507  *   - 0: Success, device configured.
508  *   - <0: Error code returned by the driver configuration function.
509  */
510 int
511 rte_event_dev_configure(uint8_t dev_id,
512                         const struct rte_event_dev_config *dev_conf);
513
514
515 /* Event queue specific APIs */
516
517 /* Event queue configuration bitmap flags */
518 #define RTE_EVENT_QUEUE_CFG_TYPE_MASK          (3ULL << 0)
519 /**< Mask for event queue schedule type configuration request */
520 #define RTE_EVENT_QUEUE_CFG_ALL_TYPES          (0ULL << 0)
521 /**< Allow ATOMIC,ORDERED,PARALLEL schedule type enqueue
522  *
523  * @see RTE_SCHED_TYPE_ORDERED, RTE_SCHED_TYPE_ATOMIC, RTE_SCHED_TYPE_PARALLEL
524  * @see rte_event_enqueue_burst()
525  */
526 #define RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY        (1ULL << 0)
527 /**< Allow only ATOMIC schedule type enqueue
528  *
529  * The rte_event_enqueue_burst() result is undefined if the queue configured
530  * with ATOMIC only and sched_type != RTE_SCHED_TYPE_ATOMIC
531  *
532  * @see RTE_SCHED_TYPE_ATOMIC, rte_event_enqueue_burst()
533  */
534 #define RTE_EVENT_QUEUE_CFG_ORDERED_ONLY       (2ULL << 0)
535 /**< Allow only ORDERED schedule type enqueue
536  *
537  * The rte_event_enqueue_burst() result is undefined if the queue configured
538  * with ORDERED only and sched_type != RTE_SCHED_TYPE_ORDERED
539  *
540  * @see RTE_SCHED_TYPE_ORDERED, rte_event_enqueue_burst()
541  */
542 #define RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY      (3ULL << 0)
543 /**< Allow only PARALLEL schedule type enqueue
544  *
545  * The rte_event_enqueue_burst() result is undefined if the queue configured
546  * with PARALLEL only and sched_type != RTE_SCHED_TYPE_PARALLEL
547  *
548  * @see RTE_SCHED_TYPE_PARALLEL, rte_event_enqueue_burst()
549  */
550 #define RTE_EVENT_QUEUE_CFG_SINGLE_LINK        (1ULL << 2)
551 /**< This event queue links only to a single event port.
552  *
553  *  @see rte_event_port_setup(), rte_event_port_link()
554  */
555
556 /** Event queue configuration structure */
557 struct rte_event_queue_conf {
558         uint32_t nb_atomic_flows;
559         /**< The maximum number of active flows this queue can track at any
560          * given time. If the queue is configured for atomic scheduling (by
561          * applying the RTE_EVENT_QUEUE_CFG_ALL_TYPES or
562          * RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY flags to event_queue_cfg), then the
563          * value must be in the range of [1, nb_event_queue_flows], which was
564          * previously provided in rte_event_dev_configure().
565          */
566         uint32_t nb_atomic_order_sequences;
567         /**< The maximum number of outstanding events waiting to be
568          * reordered by this queue. In other words, the number of entries in
569          * this queue’s reorder buffer.When the number of events in the
570          * reorder buffer reaches to *nb_atomic_order_sequences* then the
571          * scheduler cannot schedule the events from this queue and invalid
572          * event will be returned from dequeue until one or more entries are
573          * freed up/released.
574          * If the queue is configured for ordered scheduling (by applying the
575          * RTE_EVENT_QUEUE_CFG_ALL_TYPES or RTE_EVENT_QUEUE_CFG_ORDERED_ONLY
576          * flags to event_queue_cfg), then the value must be in the range of
577          * [1, nb_event_queue_flows], which was previously supplied to
578          * rte_event_dev_configure().
579          */
580         uint32_t event_queue_cfg; /**< Queue cfg flags(EVENT_QUEUE_CFG_) */
581         uint8_t priority;
582         /**< Priority for this event queue relative to other event queues.
583          * The requested priority should in the range of
584          * [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
585          * The implementation shall normalize the requested priority to
586          * event device supported priority value.
587          * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
588          */
589 };
590
591 /**
592  * Retrieve the default configuration information of an event queue designated
593  * by its *queue_id* from the event driver for an event device.
594  *
595  * This function intended to be used in conjunction with rte_event_queue_setup()
596  * where caller needs to set up the queue by overriding few default values.
597  *
598  * @param dev_id
599  *   The identifier of the device.
600  * @param queue_id
601  *   The index of the event queue to get the configuration information.
602  *   The value must be in the range [0, nb_event_queues - 1]
603  *   previously supplied to rte_event_dev_configure().
604  * @param[out] queue_conf
605  *   The pointer to the default event queue configuration data.
606  * @return
607  *   - 0: Success, driver updates the default event queue configuration data.
608  *   - <0: Error code returned by the driver info get function.
609  *
610  * @see rte_event_queue_setup()
611  *
612  */
613 int
614 rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
615                                  struct rte_event_queue_conf *queue_conf);
616
617 /**
618  * Allocate and set up an event queue for an event device.
619  *
620  * @param dev_id
621  *   The identifier of the device.
622  * @param queue_id
623  *   The index of the event queue to setup. The value must be in the range
624  *   [0, nb_event_queues - 1] previously supplied to rte_event_dev_configure().
625  * @param queue_conf
626  *   The pointer to the configuration data to be used for the event queue.
627  *   NULL value is allowed, in which case default configuration used.
628  *
629  * @see rte_event_queue_default_conf_get()
630  *
631  * @return
632  *   - 0: Success, event queue correctly set up.
633  *   - <0: event queue configuration failed
634  */
635 int
636 rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
637                       const struct rte_event_queue_conf *queue_conf);
638
639 /**
640  * The priority of the queue.
641  */
642 #define RTE_EVENT_QUEUE_ATTR_PRIORITY 0
643
644 /**
645  * Get an attribute from a queue.
646  *
647  * @param dev_id Eventdev id
648  * @param queue_id Eventdev queue id
649  * @param attr_id The attribute ID to retrieve
650  * @param[out] attr_value A pointer that will be filled in with the attribute
651  *             value if successful
652  *
653  * @retval 0 Successfully returned value
654  *         -EINVAL invalid device, queue or attr_id provided, or attr_value
655  *         was NULL
656  */
657 int
658 rte_event_queue_attr_get(uint8_t dev_id, uint8_t queue_id, uint32_t attr_id,
659                         uint32_t *attr_value);
660
661 /* Event port specific APIs */
662
663 /** Event port configuration structure */
664 struct rte_event_port_conf {
665         int32_t new_event_threshold;
666         /**< A backpressure threshold for new event enqueues on this port.
667          * Use for *closed system* event dev where event capacity is limited,
668          * and cannot exceed the capacity of the event dev.
669          * Configuring ports with different thresholds can make higher priority
670          * traffic less likely to  be backpressured.
671          * For example, a port used to inject NIC Rx packets into the event dev
672          * can have a lower threshold so as not to overwhelm the device,
673          * while ports used for worker pools can have a higher threshold.
674          * This value cannot exceed the *nb_events_limit*
675          * which was previously supplied to rte_event_dev_configure().
676          * This should be set to '-1' for *open system*.
677          */
678         uint16_t dequeue_depth;
679         /**< Configure number of bulk dequeues for this event port.
680          * This value cannot exceed the *nb_event_port_dequeue_depth*
681          * which previously supplied to rte_event_dev_configure().
682          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
683          */
684         uint16_t enqueue_depth;
685         /**< Configure number of bulk enqueues for this event port.
686          * This value cannot exceed the *nb_event_port_enqueue_depth*
687          * which previously supplied to rte_event_dev_configure().
688          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
689          */
690 };
691
692 /**
693  * Retrieve the default configuration information of an event port designated
694  * by its *port_id* from the event driver for an event device.
695  *
696  * This function intended to be used in conjunction with rte_event_port_setup()
697  * where caller needs to set up the port by overriding few default values.
698  *
699  * @param dev_id
700  *   The identifier of the device.
701  * @param port_id
702  *   The index of the event port to get the configuration information.
703  *   The value must be in the range [0, nb_event_ports - 1]
704  *   previously supplied to rte_event_dev_configure().
705  * @param[out] port_conf
706  *   The pointer to the default event port configuration data
707  * @return
708  *   - 0: Success, driver updates the default event port configuration data.
709  *   - <0: Error code returned by the driver info get function.
710  *
711  * @see rte_event_port_setup()
712  *
713  */
714 int
715 rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
716                                 struct rte_event_port_conf *port_conf);
717
718 /**
719  * Allocate and set up an event port for an event device.
720  *
721  * @param dev_id
722  *   The identifier of the device.
723  * @param port_id
724  *   The index of the event port to setup. The value must be in the range
725  *   [0, nb_event_ports - 1] previously supplied to rte_event_dev_configure().
726  * @param port_conf
727  *   The pointer to the configuration data to be used for the queue.
728  *   NULL value is allowed, in which case default configuration used.
729  *
730  * @see rte_event_port_default_conf_get()
731  *
732  * @return
733  *   - 0: Success, event port correctly set up.
734  *   - <0: Port configuration failed
735  *   - (-EDQUOT) Quota exceeded(Application tried to link the queue configured
736  *   with RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
737  */
738 int
739 rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
740                      const struct rte_event_port_conf *port_conf);
741
742 /**
743  * The queue depth of the port on the enqueue side
744  */
745 #define RTE_EVENT_PORT_ATTR_ENQ_DEPTH 0
746 /**
747  * The queue depth of the port on the dequeue side
748  */
749 #define RTE_EVENT_PORT_ATTR_DEQ_DEPTH 1
750
751 /**
752  * Get an attribute from a port.
753  *
754  * @param dev_id Eventdev id
755  * @param port_id Eventdev port id
756  * @param attr_id The attribute ID to retrieve
757  * @param[out] attr_value A pointer that will be filled in with the attribute
758  *             value if successful
759  *
760  * @retval 0 Successfully returned value
761  *         -EINVAL Invalid device, port or attr_id, or attr_value was NULL
762  */
763 int
764 rte_event_port_attr_get(uint8_t dev_id, uint8_t port_id, uint32_t attr_id,
765                         uint32_t *attr_value);
766
767 /**
768  * Start an event device.
769  *
770  * The device start step is the last one and consists of setting the event
771  * queues to start accepting the events and schedules to event ports.
772  *
773  * On success, all basic functions exported by the API (event enqueue,
774  * event dequeue and so on) can be invoked.
775  *
776  * @param dev_id
777  *   Event device identifier
778  * @return
779  *   - 0: Success, device started.
780  *   - -ESTALE : Not all ports of the device are configured
781  *   - -ENOLINK: Not all queues are linked, which could lead to deadlock.
782  */
783 int
784 rte_event_dev_start(uint8_t dev_id);
785
786 /**
787  * Stop an event device. The device can be restarted with a call to
788  * rte_event_dev_start()
789  *
790  * @param dev_id
791  *   Event device identifier.
792  */
793 void
794 rte_event_dev_stop(uint8_t dev_id);
795
796 /**
797  * Close an event device. The device cannot be restarted!
798  *
799  * @param dev_id
800  *   Event device identifier
801  *
802  * @return
803  *  - 0 on successfully closing device
804  *  - <0 on failure to close device
805  *  - (-EAGAIN) if device is busy
806  */
807 int
808 rte_event_dev_close(uint8_t dev_id);
809
810 /* Scheduler type definitions */
811 #define RTE_SCHED_TYPE_ORDERED          0
812 /**< Ordered scheduling
813  *
814  * Events from an ordered flow of an event queue can be scheduled to multiple
815  * ports for concurrent processing while maintaining the original event order.
816  * This scheme enables the user to achieve high single flow throughput by
817  * avoiding SW synchronization for ordering between ports which bound to cores.
818  *
819  * The source flow ordering from an event queue is maintained when events are
820  * enqueued to their destination queue within the same ordered flow context.
821  * An event port holds the context until application call
822  * rte_event_dequeue_burst() from the same port, which implicitly releases
823  * the context.
824  * User may allow the scheduler to release the context earlier than that
825  * by invoking rte_event_enqueue_burst() with RTE_EVENT_OP_RELEASE operation.
826  *
827  * Events from the source queue appear in their original order when dequeued
828  * from a destination queue.
829  * Event ordering is based on the received event(s), but also other
830  * (newly allocated or stored) events are ordered when enqueued within the same
831  * ordered context. Events not enqueued (e.g. released or stored) within the
832  * context are  considered missing from reordering and are skipped at this time
833  * (but can be ordered again within another context).
834  *
835  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
836  */
837
838 #define RTE_SCHED_TYPE_ATOMIC           1
839 /**< Atomic scheduling
840  *
841  * Events from an atomic flow of an event queue can be scheduled only to a
842  * single port at a time. The port is guaranteed to have exclusive (atomic)
843  * access to the associated flow context, which enables the user to avoid SW
844  * synchronization. Atomic flows also help to maintain event ordering
845  * since only one port at a time can process events from a flow of an
846  * event queue.
847  *
848  * The atomic queue synchronization context is dedicated to the port until
849  * application call rte_event_dequeue_burst() from the same port,
850  * which implicitly releases the context. User may allow the scheduler to
851  * release the context earlier than that by invoking rte_event_enqueue_burst()
852  * with RTE_EVENT_OP_RELEASE operation.
853  *
854  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
855  */
856
857 #define RTE_SCHED_TYPE_PARALLEL         2
858 /**< Parallel scheduling
859  *
860  * The scheduler performs priority scheduling, load balancing, etc. functions
861  * but does not provide additional event synchronization or ordering.
862  * It is free to schedule events from a single parallel flow of an event queue
863  * to multiple events ports for concurrent processing.
864  * The application is responsible for flow context synchronization and
865  * event ordering (SW synchronization).
866  *
867  * @see rte_event_queue_setup(), rte_event_dequeue_burst()
868  */
869
870 /* Event types to classify the event source */
871 #define RTE_EVENT_TYPE_ETHDEV           0x0
872 /**< The event generated from ethdev subsystem */
873 #define RTE_EVENT_TYPE_CRYPTODEV        0x1
874 /**< The event generated from crypodev subsystem */
875 #define RTE_EVENT_TYPE_TIMERDEV         0x2
876 /**< The event generated from timerdev subsystem */
877 #define RTE_EVENT_TYPE_CPU              0x3
878 /**< The event generated from cpu for pipelining.
879  * Application may use *sub_event_type* to further classify the event
880  */
881 #define RTE_EVENT_TYPE_MAX              0x10
882 /**< Maximum number of event types */
883
884 /* Event enqueue operations */
885 #define RTE_EVENT_OP_NEW                0
886 /**< The event producers use this operation to inject a new event to the
887  * event device.
888  */
889 #define RTE_EVENT_OP_FORWARD            1
890 /**< The CPU use this operation to forward the event to different event queue or
891  * change to new application specific flow or schedule type to enable
892  * pipelining.
893  *
894  * This operation must only be enqueued to the same port that the
895  * event to be forwarded was dequeued from.
896  */
897 #define RTE_EVENT_OP_RELEASE            2
898 /**< Release the flow context associated with the schedule type.
899  *
900  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ATOMIC*
901  * then this function hints the scheduler that the user has completed critical
902  * section processing in the current atomic context.
903  * The scheduler is now allowed to schedule events from the same flow from
904  * an event queue to another port. However, the context may be still held
905  * until the next rte_event_dequeue_burst() call, this call allows but does not
906  * force the scheduler to release the context early.
907  *
908  * Early atomic context release may increase parallelism and thus system
909  * performance, but the user needs to design carefully the split into critical
910  * vs non-critical sections.
911  *
912  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ORDERED*
913  * then this function hints the scheduler that the user has done all that need
914  * to maintain event order in the current ordered context.
915  * The scheduler is allowed to release the ordered context of this port and
916  * avoid reordering any following enqueues.
917  *
918  * Early ordered context release may increase parallelism and thus system
919  * performance.
920  *
921  * If current flow's scheduler type method is *RTE_SCHED_TYPE_PARALLEL*
922  * or no scheduling context is held then this function may be an NOOP,
923  * depending on the implementation.
924  *
925  * This operation must only be enqueued to the same port that the
926  * event to be released was dequeued from.
927  *
928  */
929
930 /**
931  * The generic *rte_event* structure to hold the event attributes
932  * for dequeue and enqueue operation
933  */
934 RTE_STD_C11
935 struct rte_event {
936         /** WORD0 */
937         union {
938                 uint64_t event;
939                 /** Event attributes for dequeue or enqueue operation */
940                 struct {
941                         uint32_t flow_id:20;
942                         /**< Targeted flow identifier for the enqueue and
943                          * dequeue operation.
944                          * The value must be in the range of
945                          * [0, nb_event_queue_flows - 1] which
946                          * previously supplied to rte_event_dev_configure().
947                          */
948                         uint32_t sub_event_type:8;
949                         /**< Sub-event types based on the event source.
950                          * @see RTE_EVENT_TYPE_CPU
951                          */
952                         uint32_t event_type:4;
953                         /**< Event type to classify the event source.
954                          * @see RTE_EVENT_TYPE_ETHDEV, (RTE_EVENT_TYPE_*)
955                          */
956                         uint8_t op:2;
957                         /**< The type of event enqueue operation - new/forward/
958                          * etc.This field is not preserved across an instance
959                          * and is undefined on dequeue.
960                          * @see RTE_EVENT_OP_NEW, (RTE_EVENT_OP_*)
961                          */
962                         uint8_t rsvd:4;
963                         /**< Reserved for future use */
964                         uint8_t sched_type:2;
965                         /**< Scheduler synchronization type (RTE_SCHED_TYPE_*)
966                          * associated with flow id on a given event queue
967                          * for the enqueue and dequeue operation.
968                          */
969                         uint8_t queue_id;
970                         /**< Targeted event queue identifier for the enqueue or
971                          * dequeue operation.
972                          * The value must be in the range of
973                          * [0, nb_event_queues - 1] which previously supplied to
974                          * rte_event_dev_configure().
975                          */
976                         uint8_t priority;
977                         /**< Event priority relative to other events in the
978                          * event queue. The requested priority should in the
979                          * range of  [RTE_EVENT_DEV_PRIORITY_HIGHEST,
980                          * RTE_EVENT_DEV_PRIORITY_LOWEST].
981                          * The implementation shall normalize the requested
982                          * priority to supported priority value.
983                          * Valid when the device has
984                          * RTE_EVENT_DEV_CAP_EVENT_QOS capability.
985                          */
986                         uint8_t impl_opaque;
987                         /**< Implementation specific opaque value.
988                          * An implementation may use this field to hold
989                          * implementation specific value to share between
990                          * dequeue and enqueue operation.
991                          * The application should not modify this field.
992                          */
993                 };
994         };
995         /** WORD1 */
996         union {
997                 uint64_t u64;
998                 /**< Opaque 64-bit value */
999                 void *event_ptr;
1000                 /**< Opaque event pointer */
1001                 struct rte_mbuf *mbuf;
1002                 /**< mbuf pointer if dequeued event is associated with mbuf */
1003         };
1004 };
1005
1006
1007 struct rte_eventdev_driver;
1008 struct rte_eventdev_ops;
1009 struct rte_eventdev;
1010
1011 typedef void (*event_schedule_t)(struct rte_eventdev *dev);
1012 /**< @internal Schedule one or more events in the event dev. */
1013
1014 typedef uint16_t (*event_enqueue_t)(void *port, const struct rte_event *ev);
1015 /**< @internal Enqueue event on port of a device */
1016
1017 typedef uint16_t (*event_enqueue_burst_t)(void *port,
1018                         const struct rte_event ev[], uint16_t nb_events);
1019 /**< @internal Enqueue burst of events on port of a device */
1020
1021 typedef uint16_t (*event_dequeue_t)(void *port, struct rte_event *ev,
1022                 uint64_t timeout_ticks);
1023 /**< @internal Dequeue event from port of a device */
1024
1025 typedef uint16_t (*event_dequeue_burst_t)(void *port, struct rte_event ev[],
1026                 uint16_t nb_events, uint64_t timeout_ticks);
1027 /**< @internal Dequeue burst of events from port of a device */
1028
1029 #define RTE_EVENTDEV_NAME_MAX_LEN       (64)
1030 /**< @internal Max length of name of event PMD */
1031
1032 /**
1033  * @internal
1034  * The data part, with no function pointers, associated with each device.
1035  *
1036  * This structure is safe to place in shared memory to be common among
1037  * different processes in a multi-process configuration.
1038  */
1039 struct rte_eventdev_data {
1040         int socket_id;
1041         /**< Socket ID where memory is allocated */
1042         uint8_t dev_id;
1043         /**< Device ID for this instance */
1044         uint8_t nb_queues;
1045         /**< Number of event queues. */
1046         uint8_t nb_ports;
1047         /**< Number of event ports. */
1048         void **ports;
1049         /**< Array of pointers to ports. */
1050         uint8_t *ports_dequeue_depth;
1051         /**< Array of port dequeue depth. */
1052         uint8_t *ports_enqueue_depth;
1053         /**< Array of port enqueue depth. */
1054         uint8_t *queues_prio;
1055         /**< Array of queue priority. */
1056         uint16_t *links_map;
1057         /**< Memory to store queues to port connections. */
1058         void *dev_private;
1059         /**< PMD-specific private data */
1060         uint32_t event_dev_cap;
1061         /**< Event device capabilities(RTE_EVENT_DEV_CAP_)*/
1062         struct rte_event_dev_config dev_conf;
1063         /**< Configuration applied to device. */
1064
1065         RTE_STD_C11
1066         uint8_t dev_started : 1;
1067         /**< Device state: STARTED(1)/STOPPED(0) */
1068
1069         char name[RTE_EVENTDEV_NAME_MAX_LEN];
1070         /**< Unique identifier name */
1071 } __rte_cache_aligned;
1072
1073 /** @internal The data structure associated with each event device. */
1074 struct rte_eventdev {
1075         event_schedule_t schedule;
1076         /**< Pointer to PMD schedule function. */
1077         event_enqueue_t enqueue;
1078         /**< Pointer to PMD enqueue function. */
1079         event_enqueue_burst_t enqueue_burst;
1080         /**< Pointer to PMD enqueue burst function. */
1081         event_enqueue_burst_t enqueue_new_burst;
1082         /**< Pointer to PMD enqueue burst function(op new variant) */
1083         event_enqueue_burst_t enqueue_forward_burst;
1084         /**< Pointer to PMD enqueue burst function(op forward variant) */
1085         event_dequeue_t dequeue;
1086         /**< Pointer to PMD dequeue function. */
1087         event_dequeue_burst_t dequeue_burst;
1088         /**< Pointer to PMD dequeue burst function. */
1089
1090         struct rte_eventdev_data *data;
1091         /**< Pointer to device data */
1092         const struct rte_eventdev_ops *dev_ops;
1093         /**< Functions exported by PMD */
1094         struct rte_device *dev;
1095         /**< Device info. supplied by probing */
1096
1097         RTE_STD_C11
1098         uint8_t attached : 1;
1099         /**< Flag indicating the device is attached */
1100 } __rte_cache_aligned;
1101
1102 extern struct rte_eventdev *rte_eventdevs;
1103 /** @internal The pool of rte_eventdev structures. */
1104
1105
1106 /**
1107  * Schedule one or more events in the event dev.
1108  *
1109  * An event dev implementation may define this is a NOOP, for instance if
1110  * the event dev performs its scheduling in hardware.
1111  *
1112  * @param dev_id
1113  *   The identifier of the device.
1114  */
1115 static inline void
1116 rte_event_schedule(uint8_t dev_id)
1117 {
1118         struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1119         if (*dev->schedule)
1120                 (*dev->schedule)(dev);
1121 }
1122
1123 static __rte_always_inline uint16_t
1124 __rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1125                         const struct rte_event ev[], uint16_t nb_events,
1126                         const event_enqueue_burst_t fn)
1127 {
1128         const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1129
1130 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
1131         if (dev_id >= RTE_EVENT_MAX_DEVS || !rte_eventdevs[dev_id].attached) {
1132                 rte_errno = -EINVAL;
1133                 return 0;
1134         }
1135
1136         if (port_id >= dev->data->nb_ports) {
1137                 rte_errno = -EINVAL;
1138                 return 0;
1139         }
1140 #endif
1141         /*
1142          * Allow zero cost non burst mode routine invocation if application
1143          * requests nb_events as const one
1144          */
1145         if (nb_events == 1)
1146                 return (*dev->enqueue)(dev->data->ports[port_id], ev);
1147         else
1148                 return fn(dev->data->ports[port_id], ev, nb_events);
1149 }
1150
1151 /**
1152  * Enqueue a burst of events objects or an event object supplied in *rte_event*
1153  * structure on an  event device designated by its *dev_id* through the event
1154  * port specified by *port_id*. Each event object specifies the event queue on
1155  * which it will be enqueued.
1156  *
1157  * The *nb_events* parameter is the number of event objects to enqueue which are
1158  * supplied in the *ev* array of *rte_event* structure.
1159  *
1160  * Event operations RTE_EVENT_OP_FORWARD and RTE_EVENT_OP_RELEASE must only be
1161  * enqueued to the same port that their associated events were dequeued from.
1162  *
1163  * The rte_event_enqueue_burst() function returns the number of
1164  * events objects it actually enqueued. A return value equal to *nb_events*
1165  * means that all event objects have been enqueued.
1166  *
1167  * @param dev_id
1168  *   The identifier of the device.
1169  * @param port_id
1170  *   The identifier of the event port.
1171  * @param ev
1172  *   Points to an array of *nb_events* objects of type *rte_event* structure
1173  *   which contain the event object enqueue operations to be processed.
1174  * @param nb_events
1175  *   The number of event objects to enqueue, typically number of
1176  *   rte_event_port_enqueue_depth() available for this port.
1177  *
1178  * @return
1179  *   The number of event objects actually enqueued on the event device. The
1180  *   return value can be less than the value of the *nb_events* parameter when
1181  *   the event devices queue is full or if invalid parameters are specified in a
1182  *   *rte_event*. If the return value is less than *nb_events*, the remaining
1183  *   events at the end of ev[] are not consumed and the caller has to take care
1184  *   of them, and rte_errno is set accordingly. Possible errno values include:
1185  *   - -EINVAL  The port ID is invalid, device ID is invalid, an event's queue
1186  *              ID is invalid, or an event's sched type doesn't match the
1187  *              capabilities of the destination queue.
1188  *   - -ENOSPC  The event port was backpressured and unable to enqueue
1189  *              one or more events. This error code is only applicable to
1190  *              closed systems.
1191  * @see rte_event_port_enqueue_depth()
1192  */
1193 static inline uint16_t
1194 rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1195                         const struct rte_event ev[], uint16_t nb_events)
1196 {
1197         const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1198
1199         return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
1200                         dev->enqueue_burst);
1201 }
1202
1203 /**
1204  * Enqueue a burst of events objects of operation type *RTE_EVENT_OP_NEW* on
1205  * an event device designated by its *dev_id* through the event port specified
1206  * by *port_id*.
1207  *
1208  * Provides the same functionality as rte_event_enqueue_burst(), expect that
1209  * application can use this API when the all objects in the burst contains
1210  * the enqueue operation of the type *RTE_EVENT_OP_NEW*. This specialized
1211  * function can provide the additional hint to the PMD and optimize if possible.
1212  *
1213  * The rte_event_enqueue_new_burst() result is undefined if the enqueue burst
1214  * has event object of operation type != RTE_EVENT_OP_NEW.
1215  *
1216  * @param dev_id
1217  *   The identifier of the device.
1218  * @param port_id
1219  *   The identifier of the event port.
1220  * @param ev
1221  *   Points to an array of *nb_events* objects of type *rte_event* structure
1222  *   which contain the event object enqueue operations to be processed.
1223  * @param nb_events
1224  *   The number of event objects to enqueue, typically number of
1225  *   rte_event_port_enqueue_depth() available for this port.
1226  *
1227  * @return
1228  *   The number of event objects actually enqueued on the event device. The
1229  *   return value can be less than the value of the *nb_events* parameter when
1230  *   the event devices queue is full or if invalid parameters are specified in a
1231  *   *rte_event*. If the return value is less than *nb_events*, the remaining
1232  *   events at the end of ev[] are not consumed and the caller has to take care
1233  *   of them, and rte_errno is set accordingly. Possible errno values include:
1234  *   - -EINVAL  The port ID is invalid, device ID is invalid, an event's queue
1235  *              ID is invalid, or an event's sched type doesn't match the
1236  *              capabilities of the destination queue.
1237  *   - -ENOSPC  The event port was backpressured and unable to enqueue
1238  *              one or more events. This error code is only applicable to
1239  *              closed systems.
1240  * @see rte_event_port_enqueue_depth() rte_event_enqueue_burst()
1241  */
1242 static inline uint16_t
1243 rte_event_enqueue_new_burst(uint8_t dev_id, uint8_t port_id,
1244                         const struct rte_event ev[], uint16_t nb_events)
1245 {
1246         const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1247
1248         return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
1249                         dev->enqueue_new_burst);
1250 }
1251
1252 /**
1253  * Enqueue a burst of events objects of operation type *RTE_EVENT_OP_FORWARD*
1254  * on an event device designated by its *dev_id* through the event port
1255  * specified by *port_id*.
1256  *
1257  * Provides the same functionality as rte_event_enqueue_burst(), expect that
1258  * application can use this API when the all objects in the burst contains
1259  * the enqueue operation of the type *RTE_EVENT_OP_FORWARD*. This specialized
1260  * function can provide the additional hint to the PMD and optimize if possible.
1261  *
1262  * The rte_event_enqueue_new_burst() result is undefined if the enqueue burst
1263  * has event object of operation type != RTE_EVENT_OP_FORWARD.
1264  *
1265  * @param dev_id
1266  *   The identifier of the device.
1267  * @param port_id
1268  *   The identifier of the event port.
1269  * @param ev
1270  *   Points to an array of *nb_events* objects of type *rte_event* structure
1271  *   which contain the event object enqueue operations to be processed.
1272  * @param nb_events
1273  *   The number of event objects to enqueue, typically number of
1274  *   rte_event_port_enqueue_depth() available for this port.
1275  *
1276  * @return
1277  *   The number of event objects actually enqueued on the event device. The
1278  *   return value can be less than the value of the *nb_events* parameter when
1279  *   the event devices queue is full or if invalid parameters are specified in a
1280  *   *rte_event*. If the return value is less than *nb_events*, the remaining
1281  *   events at the end of ev[] are not consumed and the caller has to take care
1282  *   of them, and rte_errno is set accordingly. Possible errno values include:
1283  *   - -EINVAL  The port ID is invalid, device ID is invalid, an event's queue
1284  *              ID is invalid, or an event's sched type doesn't match the
1285  *              capabilities of the destination queue.
1286  *   - -ENOSPC  The event port was backpressured and unable to enqueue
1287  *              one or more events. This error code is only applicable to
1288  *              closed systems.
1289  * @see rte_event_port_enqueue_depth() rte_event_enqueue_burst()
1290  */
1291 static inline uint16_t
1292 rte_event_enqueue_forward_burst(uint8_t dev_id, uint8_t port_id,
1293                         const struct rte_event ev[], uint16_t nb_events)
1294 {
1295         const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1296
1297         return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
1298                         dev->enqueue_forward_burst);
1299 }
1300
1301 /**
1302  * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue_burst()
1303  *
1304  * If the device is configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT flag
1305  * then application can use this function to convert timeout value in
1306  * nanoseconds to implementations specific timeout value supplied in
1307  * rte_event_dequeue_burst()
1308  *
1309  * @param dev_id
1310  *   The identifier of the device.
1311  * @param ns
1312  *   Wait time in nanosecond
1313  * @param[out] timeout_ticks
1314  *   Value for the *timeout_ticks* parameter in rte_event_dequeue_burst()
1315  *
1316  * @return
1317  *  - 0 on success.
1318  *  - -ENOTSUP if the device doesn't support timeouts
1319  *  - -EINVAL if *dev_id* is invalid or *timeout_ticks* is NULL
1320  *  - other values < 0 on failure.
1321  *
1322  * @see rte_event_dequeue_burst(), RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1323  * @see rte_event_dev_configure()
1324  *
1325  */
1326 int
1327 rte_event_dequeue_timeout_ticks(uint8_t dev_id, uint64_t ns,
1328                                         uint64_t *timeout_ticks);
1329
1330 /**
1331  * Dequeue a burst of events objects or an event object from the event port
1332  * designated by its *event_port_id*, on an event device designated
1333  * by its *dev_id*.
1334  *
1335  * rte_event_dequeue_burst() does not dictate the specifics of scheduling
1336  * algorithm as each eventdev driver may have different criteria to schedule
1337  * an event. However, in general, from an application perspective scheduler may
1338  * use the following scheme to dispatch an event to the port.
1339  *
1340  * 1) Selection of event queue based on
1341  *   a) The list of event queues are linked to the event port.
1342  *   b) If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then event
1343  *   queue selection from list is based on event queue priority relative to
1344  *   other event queue supplied as *priority* in rte_event_queue_setup()
1345  *   c) If the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability then event
1346  *   queue selection from the list is based on event priority supplied as
1347  *   *priority* in rte_event_enqueue_burst()
1348  * 2) Selection of event
1349  *   a) The number of flows available in selected event queue.
1350  *   b) Schedule type method associated with the event
1351  *
1352  * The *nb_events* parameter is the maximum number of event objects to dequeue
1353  * which are returned in the *ev* array of *rte_event* structure.
1354  *
1355  * The rte_event_dequeue_burst() function returns the number of events objects
1356  * it actually dequeued. A return value equal to *nb_events* means that all
1357  * event objects have been dequeued.
1358  *
1359  * The number of events dequeued is the number of scheduler contexts held by
1360  * this port. These contexts are automatically released in the next
1361  * rte_event_dequeue_burst() invocation, or invoking rte_event_enqueue_burst()
1362  * with RTE_EVENT_OP_RELEASE operation can be used to release the
1363  * contexts early.
1364  *
1365  * Event operations RTE_EVENT_OP_FORWARD and RTE_EVENT_OP_RELEASE must only be
1366  * enqueued to the same port that their associated events were dequeued from.
1367  *
1368  * @param dev_id
1369  *   The identifier of the device.
1370  * @param port_id
1371  *   The identifier of the event port.
1372  * @param[out] ev
1373  *   Points to an array of *nb_events* objects of type *rte_event* structure
1374  *   for output to be populated with the dequeued event objects.
1375  * @param nb_events
1376  *   The maximum number of event objects to dequeue, typically number of
1377  *   rte_event_port_dequeue_depth() available for this port.
1378  *
1379  * @param timeout_ticks
1380  *   - 0 no-wait, returns immediately if there is no event.
1381  *   - >0 wait for the event, if the device is configured with
1382  *   RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT then this function will wait until
1383  *   at least one event is available or *timeout_ticks* time.
1384  *   if the device is not configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1385  *   then this function will wait until the event available or
1386  *   *dequeue_timeout_ns* ns which was previously supplied to
1387  *   rte_event_dev_configure()
1388  *
1389  * @return
1390  * The number of event objects actually dequeued from the port. The return
1391  * value can be less than the value of the *nb_events* parameter when the
1392  * event port's queue is not full.
1393  *
1394  * @see rte_event_port_dequeue_depth()
1395  */
1396 static inline uint16_t
1397 rte_event_dequeue_burst(uint8_t dev_id, uint8_t port_id, struct rte_event ev[],
1398                         uint16_t nb_events, uint64_t timeout_ticks)
1399 {
1400         struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1401
1402 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
1403         if (dev_id >= RTE_EVENT_MAX_DEVS || !rte_eventdevs[dev_id].attached) {
1404                 rte_errno = -EINVAL;
1405                 return 0;
1406         }
1407
1408         if (port_id >= dev->data->nb_ports) {
1409                 rte_errno = -EINVAL;
1410                 return 0;
1411         }
1412 #endif
1413
1414         /*
1415          * Allow zero cost non burst mode routine invocation if application
1416          * requests nb_events as const one
1417          */
1418         if (nb_events == 1)
1419                 return (*dev->dequeue)(
1420                         dev->data->ports[port_id], ev, timeout_ticks);
1421         else
1422                 return (*dev->dequeue_burst)(
1423                         dev->data->ports[port_id], ev, nb_events,
1424                                 timeout_ticks);
1425 }
1426
1427 /**
1428  * Link multiple source event queues supplied in *queues* to the destination
1429  * event port designated by its *port_id* with associated service priority
1430  * supplied in *priorities* on the event device designated by its *dev_id*.
1431  *
1432  * The link establishment shall enable the event port *port_id* from
1433  * receiving events from the specified event queue(s) supplied in *queues*
1434  *
1435  * An event queue may link to one or more event ports.
1436  * The number of links can be established from an event queue to event port is
1437  * implementation defined.
1438  *
1439  * Event queue(s) to event port link establishment can be changed at runtime
1440  * without re-configuring the device to support scaling and to reduce the
1441  * latency of critical work by establishing the link with more event ports
1442  * at runtime.
1443  *
1444  * @param dev_id
1445  *   The identifier of the device.
1446  *
1447  * @param port_id
1448  *   Event port identifier to select the destination port to link.
1449  *
1450  * @param queues
1451  *   Points to an array of *nb_links* event queues to be linked
1452  *   to the event port.
1453  *   NULL value is allowed, in which case this function links all the configured
1454  *   event queues *nb_event_queues* which previously supplied to
1455  *   rte_event_dev_configure() to the event port *port_id*
1456  *
1457  * @param priorities
1458  *   Points to an array of *nb_links* service priorities associated with each
1459  *   event queue link to event port.
1460  *   The priority defines the event port's servicing priority for
1461  *   event queue, which may be ignored by an implementation.
1462  *   The requested priority should in the range of
1463  *   [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
1464  *   The implementation shall normalize the requested priority to
1465  *   implementation supported priority value.
1466  *   NULL value is allowed, in which case this function links the event queues
1467  *   with RTE_EVENT_DEV_PRIORITY_NORMAL servicing priority
1468  *
1469  * @param nb_links
1470  *   The number of links to establish. This parameter is ignored if queues is
1471  *   NULL.
1472  *
1473  * @return
1474  * The number of links actually established. The return value can be less than
1475  * the value of the *nb_links* parameter when the implementation has the
1476  * limitation on specific queue to port link establishment or if invalid
1477  * parameters are specified in *queues*
1478  * If the return value is less than *nb_links*, the remaining links at the end
1479  * of link[] are not established, and the caller has to take care of them.
1480  * If return value is less than *nb_links* then implementation shall update the
1481  * rte_errno accordingly, Possible rte_errno values are
1482  * (-EDQUOT) Quota exceeded(Application tried to link the queue configured with
1483  *  RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
1484  * (-EINVAL) Invalid parameter
1485  *
1486  */
1487 int
1488 rte_event_port_link(uint8_t dev_id, uint8_t port_id,
1489                     const uint8_t queues[], const uint8_t priorities[],
1490                     uint16_t nb_links);
1491
1492 /**
1493  * Unlink multiple source event queues supplied in *queues* from the destination
1494  * event port designated by its *port_id* on the event device designated
1495  * by its *dev_id*.
1496  *
1497  * The unlink establishment shall disable the event port *port_id* from
1498  * receiving events from the specified event queue *queue_id*
1499  *
1500  * Event queue(s) to event port unlink establishment can be changed at runtime
1501  * without re-configuring the device.
1502  *
1503  * @param dev_id
1504  *   The identifier of the device.
1505  *
1506  * @param port_id
1507  *   Event port identifier to select the destination port to unlink.
1508  *
1509  * @param queues
1510  *   Points to an array of *nb_unlinks* event queues to be unlinked
1511  *   from the event port.
1512  *   NULL value is allowed, in which case this function unlinks all the
1513  *   event queue(s) from the event port *port_id*.
1514  *
1515  * @param nb_unlinks
1516  *   The number of unlinks to establish. This parameter is ignored if queues is
1517  *   NULL.
1518  *
1519  * @return
1520  * The number of unlinks actually established. The return value can be less
1521  * than the value of the *nb_unlinks* parameter when the implementation has the
1522  * limitation on specific queue to port unlink establishment or
1523  * if invalid parameters are specified.
1524  * If the return value is less than *nb_unlinks*, the remaining queues at the
1525  * end of queues[] are not established, and the caller has to take care of them.
1526  * If return value is less than *nb_unlinks* then implementation shall update
1527  * the rte_errno accordingly, Possible rte_errno values are
1528  * (-EINVAL) Invalid parameter
1529  *
1530  */
1531 int
1532 rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
1533                       uint8_t queues[], uint16_t nb_unlinks);
1534
1535 /**
1536  * Retrieve the list of source event queues and its associated service priority
1537  * linked to the destination event port designated by its *port_id*
1538  * on the event device designated by its *dev_id*.
1539  *
1540  * @param dev_id
1541  *   The identifier of the device.
1542  *
1543  * @param port_id
1544  *   Event port identifier.
1545  *
1546  * @param[out] queues
1547  *   Points to an array of *queues* for output.
1548  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1549  *   store the event queue(s) linked with event port *port_id*
1550  *
1551  * @param[out] priorities
1552  *   Points to an array of *priorities* for output.
1553  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1554  *   store the service priority associated with each event queue linked
1555  *
1556  * @return
1557  * The number of links established on the event port designated by its
1558  *  *port_id*.
1559  * - <0 on failure.
1560  *
1561  */
1562 int
1563 rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
1564                          uint8_t queues[], uint8_t priorities[]);
1565
1566 /**
1567  * Dump internal information about *dev_id* to the FILE* provided in *f*.
1568  *
1569  * @param dev_id
1570  *   The identifier of the device.
1571  *
1572  * @param f
1573  *   A pointer to a file for output
1574  *
1575  * @return
1576  *   - 0: on success
1577  *   - <0: on failure.
1578  */
1579 int
1580 rte_event_dev_dump(uint8_t dev_id, FILE *f);
1581
1582 /** Maximum name length for extended statistics counters */
1583 #define RTE_EVENT_DEV_XSTATS_NAME_SIZE 64
1584
1585 /**
1586  * Selects the component of the eventdev to retrieve statistics from.
1587  */
1588 enum rte_event_dev_xstats_mode {
1589         RTE_EVENT_DEV_XSTATS_DEVICE,
1590         RTE_EVENT_DEV_XSTATS_PORT,
1591         RTE_EVENT_DEV_XSTATS_QUEUE,
1592 };
1593
1594 /**
1595  * A name-key lookup element for extended statistics.
1596  *
1597  * This structure is used to map between names and ID numbers
1598  * for extended ethdev statistics.
1599  */
1600 struct rte_event_dev_xstats_name {
1601         char name[RTE_EVENT_DEV_XSTATS_NAME_SIZE];
1602 };
1603
1604 /**
1605  * Retrieve names of extended statistics of an event device.
1606  *
1607  * @param dev_id
1608  *   The identifier of the event device.
1609  * @param mode
1610  *   The mode of statistics to retrieve. Choices include the device statistics,
1611  *   port statistics or queue statistics.
1612  * @param queue_port_id
1613  *   Used to specify the port or queue number in queue or port mode, and is
1614  *   ignored in device mode.
1615  * @param[out] xstats_names
1616  *   Block of memory to insert names into. Must be at least size in capacity.
1617  *   If set to NULL, function returns required capacity.
1618  * @param[out] ids
1619  *   Block of memory to insert ids into. Must be at least size in capacity.
1620  *   If set to NULL, function returns required capacity. The id values returned
1621  *   can be passed to *rte_event_dev_xstats_get* to select statistics.
1622  * @param size
1623  *   Capacity of xstats_names (number of names).
1624  * @return
1625  *   - positive value lower or equal to size: success. The return value
1626  *     is the number of entries filled in the stats table.
1627  *   - positive value higher than size: error, the given statistics table
1628  *     is too small. The return value corresponds to the size that should
1629  *     be given to succeed. The entries in the table are not valid and
1630  *     shall not be used by the caller.
1631  *   - negative value on error:
1632  *        -ENODEV for invalid *dev_id*
1633  *        -EINVAL for invalid mode, queue port or id parameters
1634  *        -ENOTSUP if the device doesn't support this function.
1635  */
1636 int
1637 rte_event_dev_xstats_names_get(uint8_t dev_id,
1638                                enum rte_event_dev_xstats_mode mode,
1639                                uint8_t queue_port_id,
1640                                struct rte_event_dev_xstats_name *xstats_names,
1641                                unsigned int *ids,
1642                                unsigned int size);
1643
1644 /**
1645  * Retrieve extended statistics of an event device.
1646  *
1647  * @param dev_id
1648  *   The identifier of the device.
1649  * @param mode
1650  *  The mode of statistics to retrieve. Choices include the device statistics,
1651  *  port statistics or queue statistics.
1652  * @param queue_port_id
1653  *   Used to specify the port or queue number in queue or port mode, and is
1654  *   ignored in device mode.
1655  * @param ids
1656  *   The id numbers of the stats to get. The ids can be got from the stat
1657  *   position in the stat list from rte_event_dev_get_xstats_names(), or
1658  *   by using rte_eventdev_get_xstats_by_name()
1659  * @param[out] values
1660  *   The values for each stats request by ID.
1661  * @param n
1662  *   The number of stats requested
1663  * @return
1664  *   - positive value: number of stat entries filled into the values array
1665  *   - negative value on error:
1666  *        -ENODEV for invalid *dev_id*
1667  *        -EINVAL for invalid mode, queue port or id parameters
1668  *        -ENOTSUP if the device doesn't support this function.
1669  */
1670 int
1671 rte_event_dev_xstats_get(uint8_t dev_id,
1672                          enum rte_event_dev_xstats_mode mode,
1673                          uint8_t queue_port_id,
1674                          const unsigned int ids[],
1675                          uint64_t values[], unsigned int n);
1676
1677 /**
1678  * Retrieve the value of a single stat by requesting it by name.
1679  *
1680  * @param dev_id
1681  *   The identifier of the device
1682  * @param name
1683  *   The stat name to retrieve
1684  * @param[out] id
1685  *   If non-NULL, the numerical id of the stat will be returned, so that further
1686  *   requests for the stat can be got using rte_eventdev_xstats_get, which will
1687  *   be faster as it doesn't need to scan a list of names for the stat.
1688  *   If the stat cannot be found, the id returned will be (unsigned)-1.
1689  * @return
1690  *   - positive value or zero: the stat value
1691  *   - negative value: -EINVAL if stat not found, -ENOTSUP if not supported.
1692  */
1693 uint64_t
1694 rte_event_dev_xstats_by_name_get(uint8_t dev_id, const char *name,
1695                                  unsigned int *id);
1696
1697 /**
1698  * Reset the values of the xstats of the selected component in the device.
1699  *
1700  * @param dev_id
1701  *   The identifier of the device
1702  * @param mode
1703  *   The mode of the statistics to reset. Choose from device, queue or port.
1704  * @param queue_port_id
1705  *   The queue or port to reset. 0 and positive values select ports and queues,
1706  *   while -1 indicates all ports or queues.
1707  * @param ids
1708  *   Selects specific statistics to be reset. When NULL, all statistics selected
1709  *   by *mode* will be reset. If non-NULL, must point to array of at least
1710  *   *nb_ids* size.
1711  * @param nb_ids
1712  *   The number of ids available from the *ids* array. Ignored when ids is NULL.
1713  * @return
1714  *   - zero: successfully reset the statistics to zero
1715  *   - negative value: -EINVAL invalid parameters, -ENOTSUP if not supported.
1716  */
1717 int
1718 rte_event_dev_xstats_reset(uint8_t dev_id,
1719                            enum rte_event_dev_xstats_mode mode,
1720                            int16_t queue_port_id,
1721                            const uint32_t ids[],
1722                            uint32_t nb_ids);
1723
1724 #ifdef __cplusplus
1725 }
1726 #endif
1727
1728 #endif /* _RTE_EVENTDEV_H_ */