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