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