doc: add Meson coding style to contributors guide
[dpdk.git] / lib / librte_eventdev / rte_eventdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016 Cavium, Inc.
3  * Copyright(c) 2016-2018 Intel Corporation.
4  * Copyright 2016 NXP
5  * All rights reserved.
6  */
7
8 #ifndef _RTE_EVENTDEV_H_
9 #define _RTE_EVENTDEV_H_
10
11 /**
12  * @file
13  *
14  * RTE Event Device API
15  *
16  * In a polling model, lcores poll ethdev ports and associated rx queues
17  * directly to look for packet. In an event driven model, by contrast, lcores
18  * call the scheduler that selects packets for them based on programmer
19  * specified criteria. Eventdev library adds support for event driven
20  * programming model, which offer applications automatic multicore scaling,
21  * dynamic load balancing, pipelining, packet ingress order maintenance and
22  * synchronization services to simplify application packet processing.
23  *
24  * The Event Device API is composed of two parts:
25  *
26  * - The application-oriented Event API that includes functions to setup
27  *   an event device (configure it, setup its queues, ports and start it), to
28  *   establish the link between queues to port and to receive events, and so on.
29  *
30  * - The driver-oriented Event API that exports a function allowing
31  *   an event poll Mode Driver (PMD) to simultaneously register itself as
32  *   an event device driver.
33  *
34  * Event device components:
35  *
36  *                     +-----------------+
37  *                     | +-------------+ |
38  *        +-------+    | |    flow 0   | |
39  *        |Packet |    | +-------------+ |
40  *        |event  |    | +-------------+ |
41  *        |       |    | |    flow 1   | |port_link(port0, queue0)
42  *        +-------+    | +-------------+ |     |     +--------+
43  *        +-------+    | +-------------+ o-----v-----o        |dequeue +------+
44  *        |Crypto |    | |    flow n   | |           | event  +------->|Core 0|
45  *        |work   |    | +-------------+ o----+      | port 0 |        |      |
46  *        |done ev|    |  event queue 0  |    |      +--------+        +------+
47  *        +-------+    +-----------------+    |
48  *        +-------+                           |
49  *        |Timer  |    +-----------------+    |      +--------+
50  *        |expiry |    | +-------------+ |    +------o        |dequeue +------+
51  *        |event  |    | |    flow 0   | o-----------o event  +------->|Core 1|
52  *        +-------+    | +-------------+ |      +----o port 1 |        |      |
53  *       Event enqueue | +-------------+ |      |    +--------+        +------+
54  *     o-------------> | |    flow 1   | |      |
55  *        enqueue(     | +-------------+ |      |
56  *        queue_id,    |                 |      |    +--------+        +------+
57  *        flow_id,     | +-------------+ |      |    |        |dequeue |Core 2|
58  *        sched_type,  | |    flow n   | o-----------o event  +------->|      |
59  *        event_type,  | +-------------+ |      |    | port 2 |        +------+
60  *        subev_type,  |  event queue 1  |      |    +--------+
61  *        event)       +-----------------+      |    +--------+
62  *                                              |    |        |dequeue +------+
63  *        +-------+    +-----------------+      |    | event  +------->|Core n|
64  *        |Core   |    | +-------------+ o-----------o port n |        |      |
65  *        |(SW)   |    | |    flow 0   | |      |    +--------+        +--+---+
66  *        |event  |    | +-------------+ |      |                         |
67  *        +-------+    | +-------------+ |      |                         |
68  *            ^        | |    flow 1   | |      |                         |
69  *            |        | +-------------+ o------+                         |
70  *            |        | +-------------+ |                                |
71  *            |        | |    flow n   | |                                |
72  *            |        | +-------------+ |                                |
73  *            |        |  event queue n  |                                |
74  *            |        +-----------------+                                |
75  *            |                                                           |
76  *            +-----------------------------------------------------------+
77  *
78  * Event device: A hardware or software-based event scheduler.
79  *
80  * Event: A unit of scheduling that encapsulates a packet or other datatype
81  * like SW generated event from the CPU, Crypto work completion notification,
82  * Timer expiry event notification etc as well as metadata.
83  * The metadata includes flow ID, scheduling type, event priority, event_type,
84  * sub_event_type etc.
85  *
86  * Event queue: A queue containing events that are scheduled by the event dev.
87  * An event queue contains events of different flows associated with scheduling
88  * types, such as atomic, ordered, or parallel.
89  *
90  * Event port: An application's interface into the event dev for enqueue and
91  * dequeue operations. Each event port can be linked with one or more
92  * event queues for dequeue operations.
93  *
94  * By default, all the functions of the Event Device API exported by a PMD
95  * are lock-free functions which assume to not be invoked in parallel on
96  * different logical cores to work on the same target object. For instance,
97  * the dequeue function of a PMD cannot be invoked in parallel on two logical
98  * cores to operates on same  event port. Of course, this function
99  * can be invoked in parallel by different logical cores on different ports.
100  * It is the responsibility of the upper level application to enforce this rule.
101  *
102  * In all functions of the Event API, the Event device is
103  * designated by an integer >= 0 named the device identifier *dev_id*
104  *
105  * At the Event driver level, Event devices are represented by a generic
106  * data structure of type *rte_event_dev*.
107  *
108  * Event devices are dynamically registered during the PCI/SoC device probing
109  * phase performed at EAL initialization time.
110  * When an Event device is being probed, a *rte_event_dev* structure and
111  * a new device identifier are allocated for that device. Then, the
112  * event_dev_init() function supplied by the Event driver matching the probed
113  * device is invoked to properly initialize the device.
114  *
115  * The role of the device init function consists of resetting the hardware or
116  * software event driver implementations.
117  *
118  * If the device init operation is successful, the correspondence between
119  * the device identifier assigned to the new device and its associated
120  * *rte_event_dev* structure is effectively registered.
121  * Otherwise, both the *rte_event_dev* structure and the device identifier are
122  * freed.
123  *
124  * The functions exported by the application Event API to setup a device
125  * designated by its device identifier must be invoked in the following order:
126  *     - rte_event_dev_configure()
127  *     - rte_event_queue_setup()
128  *     - rte_event_port_setup()
129  *     - rte_event_port_link()
130  *     - rte_event_dev_start()
131  *
132  * Then, the application can invoke, in any order, the functions
133  * exported by the Event API to schedule events, dequeue events, enqueue events,
134  * change event queue(s) to event port [un]link establishment and so on.
135  *
136  * Application may use rte_event_[queue/port]_default_conf_get() to get the
137  * default configuration to set up an event queue or event port by
138  * overriding few default values.
139  *
140  * If the application wants to change the configuration (i.e. call
141  * rte_event_dev_configure(), rte_event_queue_setup(), or
142  * rte_event_port_setup()), it must call rte_event_dev_stop() first to stop the
143  * device and then do the reconfiguration before calling rte_event_dev_start()
144  * again. The schedule, enqueue and dequeue functions should not be invoked
145  * when the device is stopped.
146  *
147  * Finally, an application can close an Event device by invoking the
148  * rte_event_dev_close() function.
149  *
150  * Each function of the application Event API invokes a specific function
151  * of the PMD that controls the target device designated by its device
152  * identifier.
153  *
154  * For this purpose, all device-specific functions of an Event driver are
155  * supplied through a set of pointers contained in a generic structure of type
156  * *event_dev_ops*.
157  * The address of the *event_dev_ops* structure is stored in the *rte_event_dev*
158  * structure by the device init function of the Event driver, which is
159  * invoked during the PCI/SoC device probing phase, as explained earlier.
160  *
161  * In other words, each function of the Event API simply retrieves the
162  * *rte_event_dev* structure associated with the device identifier and
163  * performs an indirect invocation of the corresponding driver function
164  * supplied in the *event_dev_ops* structure of the *rte_event_dev* structure.
165  *
166  * For performance reasons, the address of the fast-path functions of the
167  * Event driver is not contained in the *event_dev_ops* structure.
168  * Instead, they are directly stored at the beginning of the *rte_event_dev*
169  * structure to avoid an extra indirect memory access during their invocation.
170  *
171  * RTE event device drivers do not use interrupts for enqueue or dequeue
172  * operation. Instead, Event drivers export Poll-Mode enqueue and dequeue
173  * functions to applications.
174  *
175  * The events are injected to event device through *enqueue* operation by
176  * event producers in the system. The typical event producers are ethdev
177  * subsystem for generating packet events, CPU(SW) for generating events based
178  * on different stages of application processing, cryptodev for generating
179  * crypto work completion notification etc
180  *
181  * The *dequeue* operation gets one or more events from the event ports.
182  * The application process the events and send to downstream event queue through
183  * rte_event_enqueue_burst() if it is an intermediate stage of event processing,
184  * on the final stage, the application may use Tx adapter API for maintaining
185  * the ingress order and then send the packet/event on the wire.
186  *
187  * The point at which events are scheduled to ports depends on the device.
188  * For hardware devices, scheduling occurs asynchronously without any software
189  * intervention. Software schedulers can either be distributed
190  * (each worker thread schedules events to its own port) or centralized
191  * (a dedicated thread schedules to all ports). Distributed software schedulers
192  * perform the scheduling in rte_event_dequeue_burst(), whereas centralized
193  * scheduler logic need a dedicated service core for scheduling.
194  * The RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED capability flag is not set
195  * indicates the device is centralized and thus needs a dedicated scheduling
196  * thread that repeatedly calls software specific scheduling function.
197  *
198  * An event driven worker thread has following typical workflow on fastpath:
199  * \code{.c}
200  *      while (1) {
201  *              rte_event_dequeue_burst(...);
202  *              (event processing)
203  *              rte_event_enqueue_burst(...);
204  *      }
205  * \endcode
206  *
207  */
208
209 #ifdef __cplusplus
210 extern "C" {
211 #endif
212
213 #include <rte_common.h>
214 #include <rte_config.h>
215 #include <rte_errno.h>
216 #include <rte_mbuf_pool_ops.h>
217 #include <rte_memory.h>
218 #include <rte_mempool.h>
219
220 #include "rte_eventdev_trace_fp.h"
221
222 struct rte_mbuf; /* we just use mbuf pointers; no need to include rte_mbuf.h */
223 struct rte_event;
224
225 /* Event device capability bitmap flags */
226 #define RTE_EVENT_DEV_CAP_QUEUE_QOS           (1ULL << 0)
227 /**< Event scheduling prioritization is based on the priority associated with
228  *  each event queue.
229  *
230  *  @see rte_event_queue_setup()
231  */
232 #define RTE_EVENT_DEV_CAP_EVENT_QOS           (1ULL << 1)
233 /**< Event scheduling prioritization is based on the priority associated with
234  *  each event. Priority of each event is supplied in *rte_event* structure
235  *  on each enqueue operation.
236  *
237  *  @see rte_event_enqueue_burst()
238  */
239 #define RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED   (1ULL << 2)
240 /**< Event device operates in distributed scheduling mode.
241  * In distributed scheduling mode, event scheduling happens in HW or
242  * rte_event_dequeue_burst() or the combination of these two.
243  * If the flag is not set then eventdev is centralized and thus needs a
244  * dedicated service core that acts as a scheduling thread .
245  *
246  * @see rte_event_dequeue_burst()
247  */
248 #define RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES     (1ULL << 3)
249 /**< Event device is capable of enqueuing events of any type to any queue.
250  * If this capability is not set, the queue only supports events of the
251  *  *RTE_SCHED_TYPE_* type that it was created with.
252  *
253  * @see RTE_SCHED_TYPE_* values
254  */
255 #define RTE_EVENT_DEV_CAP_BURST_MODE          (1ULL << 4)
256 /**< Event device is capable of operating in burst mode for enqueue(forward,
257  * release) and dequeue operation. If this capability is not set, application
258  * still uses the rte_event_dequeue_burst() and rte_event_enqueue_burst() but
259  * PMD accepts only one event at a time.
260  *
261  * @see rte_event_dequeue_burst() rte_event_enqueue_burst()
262  */
263 #define RTE_EVENT_DEV_CAP_IMPLICIT_RELEASE_DISABLE    (1ULL << 5)
264 /**< Event device ports support disabling the implicit release feature, in
265  * which the port will release all unreleased events in its dequeue operation.
266  * If this capability is set and the port is configured with implicit release
267  * disabled, the application is responsible for explicitly releasing events
268  * using either the RTE_EVENT_OP_FORWARD or the RTE_EVENT_OP_RELEASE event
269  * enqueue operations.
270  *
271  * @see rte_event_dequeue_burst() rte_event_enqueue_burst()
272  */
273
274 #define RTE_EVENT_DEV_CAP_NONSEQ_MODE         (1ULL << 6)
275 /**< Event device is capable of operating in none sequential mode. The path
276  * of the event is not necessary to be sequential. Application can change
277  * the path of event at runtime. If the flag is not set, then event each event
278  * will follow a path from queue 0 to queue 1 to queue 2 etc. If the flag is
279  * set, events may be sent to queues in any order. If the flag is not set, the
280  * eventdev will return an error when the application enqueues an event for a
281  * qid which is not the next in the sequence.
282  */
283
284 #define RTE_EVENT_DEV_CAP_RUNTIME_PORT_LINK   (1ULL << 7)
285 /**< Event device is capable of configuring the queue/port link at runtime.
286  * If the flag is not set, the eventdev queue/port link is only can be
287  * configured during  initialization.
288  */
289
290 #define RTE_EVENT_DEV_CAP_MULTIPLE_QUEUE_PORT (1ULL << 8)
291 /**< Event device is capable of setting up the link between multiple queue
292  * with single port. If the flag is not set, the eventdev can only map a
293  * single queue to each port or map a single queue to many port.
294  */
295
296 #define RTE_EVENT_DEV_CAP_CARRY_FLOW_ID (1ULL << 9)
297 /**< Event device preserves the flow ID from the enqueued
298  * event to the dequeued event if the flag is set. Otherwise,
299  * the content of this field is implementation dependent.
300  */
301
302 /* Event device priority levels */
303 #define RTE_EVENT_DEV_PRIORITY_HIGHEST   0
304 /**< Highest priority expressed across eventdev subsystem
305  * @see rte_event_queue_setup(), rte_event_enqueue_burst()
306  * @see rte_event_port_link()
307  */
308 #define RTE_EVENT_DEV_PRIORITY_NORMAL    128
309 /**< Normal priority expressed across eventdev subsystem
310  * @see rte_event_queue_setup(), rte_event_enqueue_burst()
311  * @see rte_event_port_link()
312  */
313 #define RTE_EVENT_DEV_PRIORITY_LOWEST    255
314 /**< Lowest priority expressed across eventdev subsystem
315  * @see rte_event_queue_setup(), rte_event_enqueue_burst()
316  * @see rte_event_port_link()
317  */
318
319 /**
320  * Get the total number of event devices that have been successfully
321  * initialised.
322  *
323  * @return
324  *   The total number of usable event devices.
325  */
326 uint8_t
327 rte_event_dev_count(void);
328
329 /**
330  * Get the device identifier for the named event device.
331  *
332  * @param name
333  *   Event device name to select the event device identifier.
334  *
335  * @return
336  *   Returns event device identifier on success.
337  *   - <0: Failure to find named event device.
338  */
339 int
340 rte_event_dev_get_dev_id(const char *name);
341
342 /**
343  * Return the NUMA socket to which a device is connected.
344  *
345  * @param dev_id
346  *   The identifier of the device.
347  * @return
348  *   The NUMA socket id to which the device is connected or
349  *   a default of zero if the socket could not be determined.
350  *   -(-EINVAL)  dev_id value is out of range.
351  */
352 int
353 rte_event_dev_socket_id(uint8_t dev_id);
354
355 /**
356  * Event device information
357  */
358 struct rte_event_dev_info {
359         const char *driver_name;        /**< Event driver name */
360         struct rte_device *dev; /**< Device information */
361         uint32_t min_dequeue_timeout_ns;
362         /**< Minimum supported global dequeue timeout(ns) by this device */
363         uint32_t max_dequeue_timeout_ns;
364         /**< Maximum supported global dequeue timeout(ns) by this device */
365         uint32_t dequeue_timeout_ns;
366         /**< Configured global dequeue timeout(ns) for this device */
367         uint8_t max_event_queues;
368         /**< Maximum event_queues supported by this device */
369         uint32_t max_event_queue_flows;
370         /**< Maximum supported flows in an event queue by this device*/
371         uint8_t max_event_queue_priority_levels;
372         /**< Maximum number of event queue priority levels by this device.
373          * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
374          */
375         uint8_t max_event_priority_levels;
376         /**< Maximum number of event priority levels by this device.
377          * Valid when the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability
378          */
379         uint8_t max_event_ports;
380         /**< Maximum number of event ports supported by this device */
381         uint8_t max_event_port_dequeue_depth;
382         /**< Maximum number of events can be dequeued at a time from an
383          * event port by this device.
384          * A device that does not support bulk dequeue will set this as 1.
385          */
386         uint32_t max_event_port_enqueue_depth;
387         /**< Maximum number of events can be enqueued at a time from an
388          * event port by this device.
389          * A device that does not support bulk enqueue will set this as 1.
390          */
391         uint8_t max_event_port_links;
392         /**< Maximum number of queues that can be linked to a single event
393          * port by this device.
394          */
395         int32_t max_num_events;
396         /**< A *closed system* event dev has a limit on the number of events it
397          * can manage at a time. An *open system* event dev does not have a
398          * limit and will specify this as -1.
399          */
400         uint32_t event_dev_cap;
401         /**< Event device capabilities(RTE_EVENT_DEV_CAP_)*/
402         uint8_t max_single_link_event_port_queue_pairs;
403         /**< Maximum number of event ports and queues that are optimized for
404          * (and only capable of) single-link configurations supported by this
405          * device. These ports and queues are not accounted for in
406          * max_event_ports or max_event_queues.
407          */
408 };
409
410 /**
411  * Retrieve the contextual information of an event device.
412  *
413  * @param dev_id
414  *   The identifier of the device.
415  *
416  * @param[out] dev_info
417  *   A pointer to a structure of type *rte_event_dev_info* to be filled with the
418  *   contextual information of the device.
419  *
420  * @return
421  *   - 0: Success, driver updates the contextual information of the event device
422  *   - <0: Error code returned by the driver info get function.
423  *
424  */
425 int
426 rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info);
427
428 /**
429  * The count of ports.
430  */
431 #define RTE_EVENT_DEV_ATTR_PORT_COUNT 0
432 /**
433  * The count of queues.
434  */
435 #define RTE_EVENT_DEV_ATTR_QUEUE_COUNT 1
436 /**
437  * The status of the device, zero for stopped, non-zero for started.
438  */
439 #define RTE_EVENT_DEV_ATTR_STARTED 2
440
441 /**
442  * Get an attribute from a device.
443  *
444  * @param dev_id Eventdev id
445  * @param attr_id The attribute ID to retrieve
446  * @param[out] attr_value A pointer that will be filled in with the attribute
447  *             value if successful.
448  *
449  * @return
450  *   - 0: Successfully retrieved attribute value
451  *   - -EINVAL: Invalid device or  *attr_id* provided, or *attr_value* is NULL
452  */
453 int
454 rte_event_dev_attr_get(uint8_t dev_id, uint32_t attr_id,
455                        uint32_t *attr_value);
456
457
458 /* Event device configuration bitmap flags */
459 #define RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT (1ULL << 0)
460 /**< Override the global *dequeue_timeout_ns* and use per dequeue timeout in ns.
461  *  @see rte_event_dequeue_timeout_ticks(), rte_event_dequeue_burst()
462  */
463
464 /** Event device configuration structure */
465 struct rte_event_dev_config {
466         uint32_t dequeue_timeout_ns;
467         /**< rte_event_dequeue_burst() timeout on this device.
468          * This value should be in the range of *min_dequeue_timeout_ns* and
469          * *max_dequeue_timeout_ns* which previously provided in
470          * rte_event_dev_info_get()
471          * The value 0 is allowed, in which case, default dequeue timeout used.
472          * @see RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
473          */
474         int32_t nb_events_limit;
475         /**< In a *closed system* this field is the limit on maximum number of
476          * events that can be inflight in the eventdev at a given time. The
477          * limit is required to ensure that the finite space in a closed system
478          * is not overwhelmed. The value cannot exceed the *max_num_events*
479          * as provided by rte_event_dev_info_get().
480          * This value should be set to -1 for *open system*.
481          */
482         uint8_t nb_event_queues;
483         /**< Number of event queues to configure on this device.
484          * This value cannot exceed the *max_event_queues* which previously
485          * provided in rte_event_dev_info_get()
486          */
487         uint8_t nb_event_ports;
488         /**< Number of event ports to configure on this device.
489          * This value cannot exceed the *max_event_ports* which previously
490          * provided in rte_event_dev_info_get()
491          */
492         uint32_t nb_event_queue_flows;
493         /**< Number of flows for any event queue on this device.
494          * This value cannot exceed the *max_event_queue_flows* which previously
495          * provided in rte_event_dev_info_get()
496          */
497         uint32_t nb_event_port_dequeue_depth;
498         /**< Maximum number of events can be dequeued at a time from an
499          * event port by this device.
500          * This value cannot exceed the *max_event_port_dequeue_depth*
501          * which previously provided in rte_event_dev_info_get().
502          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
503          * @see rte_event_port_setup()
504          */
505         uint32_t nb_event_port_enqueue_depth;
506         /**< Maximum number of events can be enqueued at a time from an
507          * event port by this device.
508          * This value cannot exceed the *max_event_port_enqueue_depth*
509          * which previously provided in rte_event_dev_info_get().
510          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
511          * @see rte_event_port_setup()
512          */
513         uint32_t event_dev_cfg;
514         /**< Event device config flags(RTE_EVENT_DEV_CFG_)*/
515         uint8_t nb_single_link_event_port_queues;
516         /**< Number of event ports and queues that will be singly-linked to
517          * each other. These are a subset of the overall event ports and
518          * queues; this value cannot exceed *nb_event_ports* or
519          * *nb_event_queues*. If the device has ports and queues that are
520          * optimized for single-link usage, this field is a hint for how many
521          * to allocate; otherwise, regular event ports and queues can be used.
522          */
523 };
524
525 /**
526  * Configure an event device.
527  *
528  * This function must be invoked first before any other function in the
529  * API. This function can also be re-invoked when a device is in the
530  * stopped state.
531  *
532  * The caller may use rte_event_dev_info_get() to get the capability of each
533  * resources available for this event device.
534  *
535  * @param dev_id
536  *   The identifier of the device to configure.
537  * @param dev_conf
538  *   The event device configuration structure.
539  *
540  * @return
541  *   - 0: Success, device configured.
542  *   - <0: Error code returned by the driver configuration function.
543  */
544 int
545 rte_event_dev_configure(uint8_t dev_id,
546                         const struct rte_event_dev_config *dev_conf);
547
548 /* Event queue specific APIs */
549
550 /* Event queue configuration bitmap flags */
551 #define RTE_EVENT_QUEUE_CFG_ALL_TYPES          (1ULL << 0)
552 /**< Allow ATOMIC,ORDERED,PARALLEL schedule type enqueue
553  *
554  * @see RTE_SCHED_TYPE_ORDERED, RTE_SCHED_TYPE_ATOMIC, RTE_SCHED_TYPE_PARALLEL
555  * @see rte_event_enqueue_burst()
556  */
557 #define RTE_EVENT_QUEUE_CFG_SINGLE_LINK        (1ULL << 1)
558 /**< This event queue links only to a single event port.
559  *
560  *  @see rte_event_port_setup(), rte_event_port_link()
561  */
562
563 /** Event queue configuration structure */
564 struct rte_event_queue_conf {
565         uint32_t nb_atomic_flows;
566         /**< The maximum number of active flows this queue can track at any
567          * given time. If the queue is configured for atomic scheduling (by
568          * applying the RTE_EVENT_QUEUE_CFG_ALL_TYPES flag to event_queue_cfg
569          * or RTE_SCHED_TYPE_ATOMIC flag to schedule_type), then the
570          * value must be in the range of [1, nb_event_queue_flows], which was
571          * previously provided in rte_event_dev_configure().
572          */
573         uint32_t nb_atomic_order_sequences;
574         /**< The maximum number of outstanding events waiting to be
575          * reordered by this queue. In other words, the number of entries in
576          * this queue’s reorder buffer.When the number of events in the
577          * reorder buffer reaches to *nb_atomic_order_sequences* then the
578          * scheduler cannot schedule the events from this queue and invalid
579          * event will be returned from dequeue until one or more entries are
580          * freed up/released.
581          * If the queue is configured for ordered scheduling (by applying the
582          * RTE_EVENT_QUEUE_CFG_ALL_TYPES flag to event_queue_cfg or
583          * RTE_SCHED_TYPE_ORDERED flag to schedule_type), then the value must
584          * be in the range of [1, nb_event_queue_flows], which was
585          * previously supplied to rte_event_dev_configure().
586          */
587         uint32_t event_queue_cfg;
588         /**< Queue cfg flags(EVENT_QUEUE_CFG_) */
589         uint8_t schedule_type;
590         /**< Queue schedule type(RTE_SCHED_TYPE_*).
591          * Valid when RTE_EVENT_QUEUE_CFG_ALL_TYPES bit is not set in
592          * event_queue_cfg.
593          */
594         uint8_t priority;
595         /**< Priority for this event queue relative to other event queues.
596          * The requested priority should in the range of
597          * [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
598          * The implementation shall normalize the requested priority to
599          * event device supported priority value.
600          * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
601          */
602 };
603
604 /**
605  * Retrieve the default configuration information of an event queue designated
606  * by its *queue_id* from the event driver for an event device.
607  *
608  * This function intended to be used in conjunction with rte_event_queue_setup()
609  * where caller needs to set up the queue by overriding few default values.
610  *
611  * @param dev_id
612  *   The identifier of the device.
613  * @param queue_id
614  *   The index of the event queue to get the configuration information.
615  *   The value must be in the range [0, nb_event_queues - 1]
616  *   previously supplied to rte_event_dev_configure().
617  * @param[out] queue_conf
618  *   The pointer to the default event queue configuration data.
619  * @return
620  *   - 0: Success, driver updates the default event queue configuration data.
621  *   - <0: Error code returned by the driver info get function.
622  *
623  * @see rte_event_queue_setup()
624  *
625  */
626 int
627 rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
628                                  struct rte_event_queue_conf *queue_conf);
629
630 /**
631  * Allocate and set up an event queue for an event device.
632  *
633  * @param dev_id
634  *   The identifier of the device.
635  * @param queue_id
636  *   The index of the event queue to setup. The value must be in the range
637  *   [0, nb_event_queues - 1] previously supplied to rte_event_dev_configure().
638  * @param queue_conf
639  *   The pointer to the configuration data to be used for the event queue.
640  *   NULL value is allowed, in which case default configuration used.
641  *
642  * @see rte_event_queue_default_conf_get()
643  *
644  * @return
645  *   - 0: Success, event queue correctly set up.
646  *   - <0: event queue configuration failed
647  */
648 int
649 rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
650                       const struct rte_event_queue_conf *queue_conf);
651
652 /**
653  * The priority of the queue.
654  */
655 #define RTE_EVENT_QUEUE_ATTR_PRIORITY 0
656 /**
657  * The number of atomic flows configured for the queue.
658  */
659 #define RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_FLOWS 1
660 /**
661  * The number of atomic order sequences configured for the queue.
662  */
663 #define RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_ORDER_SEQUENCES 2
664 /**
665  * The cfg flags for the queue.
666  */
667 #define RTE_EVENT_QUEUE_ATTR_EVENT_QUEUE_CFG 3
668 /**
669  * The schedule type of the queue.
670  */
671 #define RTE_EVENT_QUEUE_ATTR_SCHEDULE_TYPE 4
672
673 /**
674  * Get an attribute from a queue.
675  *
676  * @param dev_id
677  *   Eventdev id
678  * @param queue_id
679  *   Eventdev queue id
680  * @param attr_id
681  *   The attribute ID to retrieve
682  * @param[out] attr_value
683  *   A pointer that will be filled in with the attribute value if successful
684  *
685  * @return
686  *   - 0: Successfully returned value
687  *   - -EINVAL: invalid device, queue or attr_id provided, or attr_value was
688  *              NULL
689  *   - -EOVERFLOW: returned when attr_id is set to
690  *   RTE_EVENT_QUEUE_ATTR_SCHEDULE_TYPE and event_queue_cfg is set to
691  *   RTE_EVENT_QUEUE_CFG_ALL_TYPES
692  */
693 int
694 rte_event_queue_attr_get(uint8_t dev_id, uint8_t queue_id, uint32_t attr_id,
695                         uint32_t *attr_value);
696
697 /* Event port specific APIs */
698
699 /* Event port configuration bitmap flags */
700 #define RTE_EVENT_PORT_CFG_DISABLE_IMPL_REL    (1ULL << 0)
701 /**< Configure the port not to release outstanding events in
702  * rte_event_dev_dequeue_burst(). If set, all events received through
703  * the port must be explicitly released with RTE_EVENT_OP_RELEASE or
704  * RTE_EVENT_OP_FORWARD. Must be unset if the device is not
705  * RTE_EVENT_DEV_CAP_IMPLICIT_RELEASE_DISABLE capable.
706  */
707 #define RTE_EVENT_PORT_CFG_SINGLE_LINK         (1ULL << 1)
708 /**< This event port links only to a single event queue.
709  *
710  *  @see rte_event_port_setup(), rte_event_port_link()
711  */
712
713 /** Event port configuration structure */
714 struct rte_event_port_conf {
715         int32_t new_event_threshold;
716         /**< A backpressure threshold for new event enqueues on this port.
717          * Use for *closed system* event dev where event capacity is limited,
718          * and cannot exceed the capacity of the event dev.
719          * Configuring ports with different thresholds can make higher priority
720          * traffic less likely to  be backpressured.
721          * For example, a port used to inject NIC Rx packets into the event dev
722          * can have a lower threshold so as not to overwhelm the device,
723          * while ports used for worker pools can have a higher threshold.
724          * This value cannot exceed the *nb_events_limit*
725          * which was previously supplied to rte_event_dev_configure().
726          * This should be set to '-1' for *open system*.
727          */
728         uint16_t dequeue_depth;
729         /**< Configure number of bulk dequeues for this event port.
730          * This value cannot exceed the *nb_event_port_dequeue_depth*
731          * which previously supplied to rte_event_dev_configure().
732          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
733          */
734         uint16_t enqueue_depth;
735         /**< Configure number of bulk enqueues for this event port.
736          * This value cannot exceed the *nb_event_port_enqueue_depth*
737          * which previously supplied to rte_event_dev_configure().
738          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
739          */
740         uint32_t event_port_cfg; /**< Port cfg flags(EVENT_PORT_CFG_) */
741 };
742
743 /**
744  * Retrieve the default configuration information of an event port designated
745  * by its *port_id* from the event driver for an event device.
746  *
747  * This function intended to be used in conjunction with rte_event_port_setup()
748  * where caller needs to set up the port by overriding few default values.
749  *
750  * @param dev_id
751  *   The identifier of the device.
752  * @param port_id
753  *   The index of the event port to get the configuration information.
754  *   The value must be in the range [0, nb_event_ports - 1]
755  *   previously supplied to rte_event_dev_configure().
756  * @param[out] port_conf
757  *   The pointer to the default event port configuration data
758  * @return
759  *   - 0: Success, driver updates the default event port configuration data.
760  *   - <0: Error code returned by the driver info get function.
761  *
762  * @see rte_event_port_setup()
763  *
764  */
765 int
766 rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
767                                 struct rte_event_port_conf *port_conf);
768
769 /**
770  * Allocate and set up an event port for an event device.
771  *
772  * @param dev_id
773  *   The identifier of the device.
774  * @param port_id
775  *   The index of the event port to setup. The value must be in the range
776  *   [0, nb_event_ports - 1] previously supplied to rte_event_dev_configure().
777  * @param port_conf
778  *   The pointer to the configuration data to be used for the queue.
779  *   NULL value is allowed, in which case default configuration used.
780  *
781  * @see rte_event_port_default_conf_get()
782  *
783  * @return
784  *   - 0: Success, event port correctly set up.
785  *   - <0: Port configuration failed
786  *   - (-EDQUOT) Quota exceeded(Application tried to link the queue configured
787  *   with RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
788  */
789 int
790 rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
791                      const struct rte_event_port_conf *port_conf);
792
793 /**
794  * The queue depth of the port on the enqueue side
795  */
796 #define RTE_EVENT_PORT_ATTR_ENQ_DEPTH 0
797 /**
798  * The queue depth of the port on the dequeue side
799  */
800 #define RTE_EVENT_PORT_ATTR_DEQ_DEPTH 1
801 /**
802  * The new event threshold of the port
803  */
804 #define RTE_EVENT_PORT_ATTR_NEW_EVENT_THRESHOLD 2
805 /**
806  * The implicit release disable attribute of the port
807  */
808 #define RTE_EVENT_PORT_ATTR_IMPLICIT_RELEASE_DISABLE 3
809
810 /**
811  * Get an attribute from a port.
812  *
813  * @param dev_id
814  *   Eventdev id
815  * @param port_id
816  *   Eventdev port id
817  * @param attr_id
818  *   The attribute ID to retrieve
819  * @param[out] attr_value
820  *   A pointer that will be filled in with the attribute value if successful
821  *
822  * @return
823  *   - 0: Successfully returned value
824  *   - (-EINVAL) Invalid device, port or attr_id, or attr_value was NULL
825  */
826 int
827 rte_event_port_attr_get(uint8_t dev_id, uint8_t port_id, uint32_t attr_id,
828                         uint32_t *attr_value);
829
830 /**
831  * Start an event device.
832  *
833  * The device start step is the last one and consists of setting the event
834  * queues to start accepting the events and schedules to event ports.
835  *
836  * On success, all basic functions exported by the API (event enqueue,
837  * event dequeue and so on) can be invoked.
838  *
839  * @param dev_id
840  *   Event device identifier
841  * @return
842  *   - 0: Success, device started.
843  *   - -ESTALE : Not all ports of the device are configured
844  *   - -ENOLINK: Not all queues are linked, which could lead to deadlock.
845  */
846 int
847 rte_event_dev_start(uint8_t dev_id);
848
849 /**
850  * Stop an event device.
851  *
852  * This function causes all queued events to be drained, including those
853  * residing in event ports. While draining events out of the device, this
854  * function calls the user-provided flush callback (if one was registered) once
855  * per event.
856  *
857  * The device can be restarted with a call to rte_event_dev_start(). Threads
858  * that continue to enqueue/dequeue while the device is stopped, or being
859  * stopped, will result in undefined behavior. This includes event adapters,
860  * which must be stopped prior to stopping the eventdev.
861  *
862  * @param dev_id
863  *   Event device identifier.
864  *
865  * @see rte_event_dev_stop_flush_callback_register()
866  */
867 void
868 rte_event_dev_stop(uint8_t dev_id);
869
870 typedef void (*eventdev_stop_flush_t)(uint8_t dev_id, struct rte_event event,
871                 void *arg);
872 /**< Callback function called during rte_event_dev_stop(), invoked once per
873  * flushed event.
874  */
875
876 /**
877  * Registers a callback function to be invoked during rte_event_dev_stop() for
878  * each flushed event. This function can be used to properly dispose of queued
879  * events, for example events containing memory pointers.
880  *
881  * The callback function is only registered for the calling process. The
882  * callback function must be registered in every process that can call
883  * rte_event_dev_stop().
884  *
885  * To unregister a callback, call this function with a NULL callback pointer.
886  *
887  * @param dev_id
888  *   The identifier of the device.
889  * @param callback
890  *   Callback function invoked once per flushed event.
891  * @param userdata
892  *   Argument supplied to callback.
893  *
894  * @return
895  *  - 0 on success.
896  *  - -EINVAL if *dev_id* is invalid
897  *
898  * @see rte_event_dev_stop()
899  */
900 int
901 rte_event_dev_stop_flush_callback_register(uint8_t dev_id,
902                 eventdev_stop_flush_t callback, void *userdata);
903
904 /**
905  * Close an event device. The device cannot be restarted!
906  *
907  * @param dev_id
908  *   Event device identifier
909  *
910  * @return
911  *  - 0 on successfully closing device
912  *  - <0 on failure to close device
913  *  - (-EAGAIN) if device is busy
914  */
915 int
916 rte_event_dev_close(uint8_t dev_id);
917
918 /**
919  * Event vector structure.
920  */
921 struct rte_event_vector {
922         uint16_t nb_elem;
923         /**< Number of elements in this event vector. */
924         uint16_t rsvd : 15;
925         /**< Reserved for future use */
926         uint16_t attr_valid : 1;
927         /**< Indicates that the below union attributes have valid information.
928          */
929         union {
930                 /* Used by Rx/Tx adapter.
931                  * Indicates that all the elements in this vector belong to the
932                  * same port and queue pair when originating from Rx adapter,
933                  * valid only when event type is ETHDEV_VECTOR or
934                  * ETH_RX_ADAPTER_VECTOR.
935                  * Can also be used to indicate the Tx adapter the destination
936                  * port and queue of the mbufs in the vector
937                  */
938                 struct {
939                         uint16_t port;
940                         /* Ethernet device port id. */
941                         uint16_t queue;
942                         /* Ethernet device queue id. */
943                 };
944         };
945         /**< Union to hold common attributes of the vector array. */
946         uint64_t impl_opaque;
947         /**< Implementation specific opaque value.
948          * An implementation may use this field to hold implementation specific
949          * value to share between dequeue and enqueue operation.
950          * The application should not modify this field.
951          */
952         union {
953                 struct rte_mbuf *mbufs[0];
954                 void *ptrs[0];
955                 uint64_t *u64s[0];
956         } __rte_aligned(16);
957         /**< Start of the vector array union. Depending upon the event type the
958          * vector array can be an array of mbufs or pointers or opaque u64
959          * values.
960          */
961 };
962
963 /* Scheduler type definitions */
964 #define RTE_SCHED_TYPE_ORDERED          0
965 /**< Ordered scheduling
966  *
967  * Events from an ordered flow of an event queue can be scheduled to multiple
968  * ports for concurrent processing while maintaining the original event order.
969  * This scheme enables the user to achieve high single flow throughput by
970  * avoiding SW synchronization for ordering between ports which bound to cores.
971  *
972  * The source flow ordering from an event queue is maintained when events are
973  * enqueued to their destination queue within the same ordered flow context.
974  * An event port holds the context until application call
975  * rte_event_dequeue_burst() from the same port, which implicitly releases
976  * the context.
977  * User may allow the scheduler to release the context earlier than that
978  * by invoking rte_event_enqueue_burst() with RTE_EVENT_OP_RELEASE operation.
979  *
980  * Events from the source queue appear in their original order when dequeued
981  * from a destination queue.
982  * Event ordering is based on the received event(s), but also other
983  * (newly allocated or stored) events are ordered when enqueued within the same
984  * ordered context. Events not enqueued (e.g. released or stored) within the
985  * context are  considered missing from reordering and are skipped at this time
986  * (but can be ordered again within another context).
987  *
988  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
989  */
990
991 #define RTE_SCHED_TYPE_ATOMIC           1
992 /**< Atomic scheduling
993  *
994  * Events from an atomic flow of an event queue can be scheduled only to a
995  * single port at a time. The port is guaranteed to have exclusive (atomic)
996  * access to the associated flow context, which enables the user to avoid SW
997  * synchronization. Atomic flows also help to maintain event ordering
998  * since only one port at a time can process events from a flow of an
999  * event queue.
1000  *
1001  * The atomic queue synchronization context is dedicated to the port until
1002  * application call rte_event_dequeue_burst() from the same port,
1003  * which implicitly releases the context. User may allow the scheduler to
1004  * release the context earlier than that by invoking rte_event_enqueue_burst()
1005  * with RTE_EVENT_OP_RELEASE operation.
1006  *
1007  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
1008  */
1009
1010 #define RTE_SCHED_TYPE_PARALLEL         2
1011 /**< Parallel scheduling
1012  *
1013  * The scheduler performs priority scheduling, load balancing, etc. functions
1014  * but does not provide additional event synchronization or ordering.
1015  * It is free to schedule events from a single parallel flow of an event queue
1016  * to multiple events ports for concurrent processing.
1017  * The application is responsible for flow context synchronization and
1018  * event ordering (SW synchronization).
1019  *
1020  * @see rte_event_queue_setup(), rte_event_dequeue_burst()
1021  */
1022
1023 /* Event types to classify the event source */
1024 #define RTE_EVENT_TYPE_ETHDEV           0x0
1025 /**< The event generated from ethdev subsystem */
1026 #define RTE_EVENT_TYPE_CRYPTODEV        0x1
1027 /**< The event generated from crypodev subsystem */
1028 #define RTE_EVENT_TYPE_TIMER            0x2
1029 /**< The event generated from event timer adapter */
1030 #define RTE_EVENT_TYPE_CPU              0x3
1031 /**< The event generated from cpu for pipelining.
1032  * Application may use *sub_event_type* to further classify the event
1033  */
1034 #define RTE_EVENT_TYPE_ETH_RX_ADAPTER   0x4
1035 /**< The event generated from event eth Rx adapter */
1036 #define RTE_EVENT_TYPE_VECTOR           0x8
1037 /**< Indicates that event is a vector.
1038  * All vector event types should be a logical OR of EVENT_TYPE_VECTOR.
1039  * This simplifies the pipeline design as one can split processing the events
1040  * between vector events and normal event across event types.
1041  * Example:
1042  *      if (ev.event_type & RTE_EVENT_TYPE_VECTOR) {
1043  *              // Classify and handle vector event.
1044  *      } else {
1045  *              // Classify and handle event.
1046  *      }
1047  */
1048 #define RTE_EVENT_TYPE_ETHDEV_VECTOR                                           \
1049         (RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_ETHDEV)
1050 /**< The event vector generated from ethdev subsystem */
1051 #define RTE_EVENT_TYPE_CPU_VECTOR (RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_CPU)
1052 /**< The event vector generated from cpu for pipelining. */
1053 #define RTE_EVENT_TYPE_ETH_RX_ADAPTER_VECTOR                                   \
1054         (RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_ETH_RX_ADAPTER)
1055 /**< The event vector generated from eth Rx adapter. */
1056
1057 #define RTE_EVENT_TYPE_MAX              0x10
1058 /**< Maximum number of event types */
1059
1060 /* Event enqueue operations */
1061 #define RTE_EVENT_OP_NEW                0
1062 /**< The event producers use this operation to inject a new event to the
1063  * event device.
1064  */
1065 #define RTE_EVENT_OP_FORWARD            1
1066 /**< The CPU use this operation to forward the event to different event queue or
1067  * change to new application specific flow or schedule type to enable
1068  * pipelining.
1069  *
1070  * This operation must only be enqueued to the same port that the
1071  * event to be forwarded was dequeued from.
1072  */
1073 #define RTE_EVENT_OP_RELEASE            2
1074 /**< Release the flow context associated with the schedule type.
1075  *
1076  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ATOMIC*
1077  * then this function hints the scheduler that the user has completed critical
1078  * section processing in the current atomic context.
1079  * The scheduler is now allowed to schedule events from the same flow from
1080  * an event queue to another port. However, the context may be still held
1081  * until the next rte_event_dequeue_burst() call, this call allows but does not
1082  * force the scheduler to release the context early.
1083  *
1084  * Early atomic context release may increase parallelism and thus system
1085  * performance, but the user needs to design carefully the split into critical
1086  * vs non-critical sections.
1087  *
1088  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ORDERED*
1089  * then this function hints the scheduler that the user has done all that need
1090  * to maintain event order in the current ordered context.
1091  * The scheduler is allowed to release the ordered context of this port and
1092  * avoid reordering any following enqueues.
1093  *
1094  * Early ordered context release may increase parallelism and thus system
1095  * performance.
1096  *
1097  * If current flow's scheduler type method is *RTE_SCHED_TYPE_PARALLEL*
1098  * or no scheduling context is held then this function may be an NOOP,
1099  * depending on the implementation.
1100  *
1101  * This operation must only be enqueued to the same port that the
1102  * event to be released was dequeued from.
1103  *
1104  */
1105
1106 /**
1107  * The generic *rte_event* structure to hold the event attributes
1108  * for dequeue and enqueue operation
1109  */
1110 RTE_STD_C11
1111 struct rte_event {
1112         /** WORD0 */
1113         union {
1114                 uint64_t event;
1115                 /** Event attributes for dequeue or enqueue operation */
1116                 struct {
1117                         uint32_t flow_id:20;
1118                         /**< Targeted flow identifier for the enqueue and
1119                          * dequeue operation.
1120                          * The value must be in the range of
1121                          * [0, nb_event_queue_flows - 1] which
1122                          * previously supplied to rte_event_dev_configure().
1123                          */
1124                         uint32_t sub_event_type:8;
1125                         /**< Sub-event types based on the event source.
1126                          * @see RTE_EVENT_TYPE_CPU
1127                          */
1128                         uint32_t event_type:4;
1129                         /**< Event type to classify the event source.
1130                          * @see RTE_EVENT_TYPE_ETHDEV, (RTE_EVENT_TYPE_*)
1131                          */
1132                         uint8_t op:2;
1133                         /**< The type of event enqueue operation - new/forward/
1134                          * etc.This field is not preserved across an instance
1135                          * and is undefined on dequeue.
1136                          * @see RTE_EVENT_OP_NEW, (RTE_EVENT_OP_*)
1137                          */
1138                         uint8_t rsvd:4;
1139                         /**< Reserved for future use */
1140                         uint8_t sched_type:2;
1141                         /**< Scheduler synchronization type (RTE_SCHED_TYPE_*)
1142                          * associated with flow id on a given event queue
1143                          * for the enqueue and dequeue operation.
1144                          */
1145                         uint8_t queue_id;
1146                         /**< Targeted event queue identifier for the enqueue or
1147                          * dequeue operation.
1148                          * The value must be in the range of
1149                          * [0, nb_event_queues - 1] which previously supplied to
1150                          * rte_event_dev_configure().
1151                          */
1152                         uint8_t priority;
1153                         /**< Event priority relative to other events in the
1154                          * event queue. The requested priority should in the
1155                          * range of  [RTE_EVENT_DEV_PRIORITY_HIGHEST,
1156                          * RTE_EVENT_DEV_PRIORITY_LOWEST].
1157                          * The implementation shall normalize the requested
1158                          * priority to supported priority value.
1159                          * Valid when the device has
1160                          * RTE_EVENT_DEV_CAP_EVENT_QOS capability.
1161                          */
1162                         uint8_t impl_opaque;
1163                         /**< Implementation specific opaque value.
1164                          * An implementation may use this field to hold
1165                          * implementation specific value to share between
1166                          * dequeue and enqueue operation.
1167                          * The application should not modify this field.
1168                          */
1169                 };
1170         };
1171         /** WORD1 */
1172         union {
1173                 uint64_t u64;
1174                 /**< Opaque 64-bit value */
1175                 void *event_ptr;
1176                 /**< Opaque event pointer */
1177                 struct rte_mbuf *mbuf;
1178                 /**< mbuf pointer if dequeued event is associated with mbuf */
1179                 struct rte_event_vector *vec;
1180                 /**< Event vector pointer. */
1181         };
1182 };
1183
1184 /* Ethdev Rx adapter capability bitmap flags */
1185 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT      0x1
1186 /**< This flag is sent when the packet transfer mechanism is in HW.
1187  * Ethdev can send packets to the event device using internal event port.
1188  */
1189 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ       0x2
1190 /**< Adapter supports multiple event queues per ethdev. Every ethdev
1191  * Rx queue can be connected to a unique event queue.
1192  */
1193 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID   0x4
1194 /**< The application can override the adapter generated flow ID in the
1195  * event. This flow ID can be specified when adding an ethdev Rx queue
1196  * to the adapter using the ev member of struct rte_event_eth_rx_adapter
1197  * @see struct rte_event_eth_rx_adapter_queue_conf::ev
1198  * @see struct rte_event_eth_rx_adapter_queue_conf::rx_queue_flags
1199  */
1200 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_EVENT_VECTOR       0x8
1201 /**< Adapter supports event vectorization per ethdev. */
1202
1203 /**
1204  * Retrieve the event device's ethdev Rx adapter capabilities for the
1205  * specified ethernet port
1206  *
1207  * @param dev_id
1208  *   The identifier of the device.
1209  *
1210  * @param eth_port_id
1211  *   The identifier of the ethernet device.
1212  *
1213  * @param[out] caps
1214  *   A pointer to memory filled with Rx event adapter capabilities.
1215  *
1216  * @return
1217  *   - 0: Success, driver provides Rx event adapter capabilities for the
1218  *      ethernet device.
1219  *   - <0: Error code returned by the driver function.
1220  *
1221  */
1222 int
1223 rte_event_eth_rx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
1224                                 uint32_t *caps);
1225
1226 #define RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT (1ULL << 0)
1227 /**< This flag is set when the timer mechanism is in HW. */
1228
1229 #define RTE_EVENT_TIMER_ADAPTER_CAP_PERIODIC      (1ULL << 1)
1230 /**< This flag is set if periodic mode is supported. */
1231
1232 /**
1233  * Retrieve the event device's timer adapter capabilities.
1234  *
1235  * @param dev_id
1236  *   The identifier of the device.
1237  *
1238  * @param[out] caps
1239  *   A pointer to memory to be filled with event timer adapter capabilities.
1240  *
1241  * @return
1242  *   - 0: Success, driver provided event timer adapter capabilities.
1243  *   - <0: Error code returned by the driver function.
1244  */
1245 int
1246 rte_event_timer_adapter_caps_get(uint8_t dev_id, uint32_t *caps);
1247
1248 /* Crypto adapter capability bitmap flag */
1249 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW   0x1
1250 /**< Flag indicates HW is capable of generating events in
1251  * RTE_EVENT_OP_NEW enqueue operation. Cryptodev will send
1252  * packets to the event device as new events using an internal
1253  * event port.
1254  */
1255
1256 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD   0x2
1257 /**< Flag indicates HW is capable of generating events in
1258  * RTE_EVENT_OP_FORWARD enqueue operation. Cryptodev will send
1259  * packets to the event device as forwarded event using an
1260  * internal event port.
1261  */
1262
1263 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND  0x4
1264 /**< Flag indicates HW is capable of mapping crypto queue pair to
1265  * event queue.
1266  */
1267
1268 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA   0x8
1269 /**< Flag indicates HW/SW supports a mechanism to store and retrieve
1270  * the private data information along with the crypto session.
1271  */
1272
1273 /**
1274  * Retrieve the event device's crypto adapter capabilities for the
1275  * specified cryptodev device
1276  *
1277  * @param dev_id
1278  *   The identifier of the device.
1279  *
1280  * @param cdev_id
1281  *   The identifier of the cryptodev device.
1282  *
1283  * @param[out] caps
1284  *   A pointer to memory filled with event adapter capabilities.
1285  *   It is expected to be pre-allocated & initialized by caller.
1286  *
1287  * @return
1288  *   - 0: Success, driver provides event adapter capabilities for the
1289  *     cryptodev device.
1290  *   - <0: Error code returned by the driver function.
1291  *
1292  */
1293 int
1294 rte_event_crypto_adapter_caps_get(uint8_t dev_id, uint8_t cdev_id,
1295                                   uint32_t *caps);
1296
1297 /* Ethdev Tx adapter capability bitmap flags */
1298 #define RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT      0x1
1299 /**< This flag is sent when the PMD supports a packet transmit callback
1300  */
1301 #define RTE_EVENT_ETH_TX_ADAPTER_CAP_EVENT_VECTOR       0x2
1302 /**< Indicates that the Tx adapter is capable of handling event vector of
1303  * mbufs.
1304  */
1305
1306 /**
1307  * Retrieve the event device's eth Tx adapter capabilities
1308  *
1309  * @param dev_id
1310  *   The identifier of the device.
1311  *
1312  * @param eth_port_id
1313  *   The identifier of the ethernet device.
1314  *
1315  * @param[out] caps
1316  *   A pointer to memory filled with eth Tx adapter capabilities.
1317  *
1318  * @return
1319  *   - 0: Success, driver provides eth Tx adapter capabilities.
1320  *   - <0: Error code returned by the driver function.
1321  *
1322  */
1323 int
1324 rte_event_eth_tx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
1325                                 uint32_t *caps);
1326
1327 struct rte_eventdev_ops;
1328 struct rte_eventdev;
1329
1330 typedef uint16_t (*event_enqueue_t)(void *port, const struct rte_event *ev);
1331 /**< @internal Enqueue event on port of a device */
1332
1333 typedef uint16_t (*event_enqueue_burst_t)(void *port,
1334                         const struct rte_event ev[], uint16_t nb_events);
1335 /**< @internal Enqueue burst of events on port of a device */
1336
1337 typedef uint16_t (*event_dequeue_t)(void *port, struct rte_event *ev,
1338                 uint64_t timeout_ticks);
1339 /**< @internal Dequeue event from port of a device */
1340
1341 typedef uint16_t (*event_dequeue_burst_t)(void *port, struct rte_event ev[],
1342                 uint16_t nb_events, uint64_t timeout_ticks);
1343 /**< @internal Dequeue burst of events from port of a device */
1344
1345 typedef uint16_t (*event_tx_adapter_enqueue)(void *port,
1346                                 struct rte_event ev[], uint16_t nb_events);
1347 /**< @internal Enqueue burst of events on port of a device */
1348
1349 typedef uint16_t (*event_tx_adapter_enqueue_same_dest)(void *port,
1350                 struct rte_event ev[], uint16_t nb_events);
1351 /**< @internal Enqueue burst of events on port of a device supporting
1352  * burst having same destination Ethernet port & Tx queue.
1353  */
1354
1355 typedef uint16_t (*event_crypto_adapter_enqueue)(void *port,
1356                                 struct rte_event ev[], uint16_t nb_events);
1357 /**< @internal Enqueue burst of events on crypto adapter */
1358
1359 #define RTE_EVENTDEV_NAME_MAX_LEN       (64)
1360 /**< @internal Max length of name of event PMD */
1361
1362 /**
1363  * @internal
1364  * The data part, with no function pointers, associated with each device.
1365  *
1366  * This structure is safe to place in shared memory to be common among
1367  * different processes in a multi-process configuration.
1368  */
1369 struct rte_eventdev_data {
1370         int socket_id;
1371         /**< Socket ID where memory is allocated */
1372         uint8_t dev_id;
1373         /**< Device ID for this instance */
1374         uint8_t nb_queues;
1375         /**< Number of event queues. */
1376         uint8_t nb_ports;
1377         /**< Number of event ports. */
1378         void **ports;
1379         /**< Array of pointers to ports. */
1380         struct rte_event_port_conf *ports_cfg;
1381         /**< Array of port configuration structures. */
1382         struct rte_event_queue_conf *queues_cfg;
1383         /**< Array of queue configuration structures. */
1384         uint16_t *links_map;
1385         /**< Memory to store queues to port connections. */
1386         void *dev_private;
1387         /**< PMD-specific private data */
1388         uint32_t event_dev_cap;
1389         /**< Event device capabilities(RTE_EVENT_DEV_CAP_)*/
1390         struct rte_event_dev_config dev_conf;
1391         /**< Configuration applied to device. */
1392         uint8_t service_inited;
1393         /* Service initialization state */
1394         uint32_t service_id;
1395         /* Service ID*/
1396         void *dev_stop_flush_arg;
1397         /**< User-provided argument for event flush function */
1398
1399         RTE_STD_C11
1400         uint8_t dev_started : 1;
1401         /**< Device state: STARTED(1)/STOPPED(0) */
1402
1403         char name[RTE_EVENTDEV_NAME_MAX_LEN];
1404         /**< Unique identifier name */
1405
1406         uint64_t reserved_64s[4]; /**< Reserved for future fields */
1407         void *reserved_ptrs[4];   /**< Reserved for future fields */
1408 } __rte_cache_aligned;
1409
1410 /** @internal The data structure associated with each event device. */
1411 struct rte_eventdev {
1412         event_enqueue_t enqueue;
1413         /**< Pointer to PMD enqueue function. */
1414         event_enqueue_burst_t enqueue_burst;
1415         /**< Pointer to PMD enqueue burst function. */
1416         event_enqueue_burst_t enqueue_new_burst;
1417         /**< Pointer to PMD enqueue burst function(op new variant) */
1418         event_enqueue_burst_t enqueue_forward_burst;
1419         /**< Pointer to PMD enqueue burst function(op forward variant) */
1420         event_dequeue_t dequeue;
1421         /**< Pointer to PMD dequeue function. */
1422         event_dequeue_burst_t dequeue_burst;
1423         /**< Pointer to PMD dequeue burst function. */
1424         event_tx_adapter_enqueue_same_dest txa_enqueue_same_dest;
1425         /**< Pointer to PMD eth Tx adapter burst enqueue function with
1426          * events destined to same Eth port & Tx queue.
1427          */
1428         event_tx_adapter_enqueue txa_enqueue;
1429         /**< Pointer to PMD eth Tx adapter enqueue function. */
1430         struct rte_eventdev_data *data;
1431         /**< Pointer to device data */
1432         struct rte_eventdev_ops *dev_ops;
1433         /**< Functions exported by PMD */
1434         struct rte_device *dev;
1435         /**< Device info. supplied by probing */
1436
1437         RTE_STD_C11
1438         uint8_t attached : 1;
1439         /**< Flag indicating the device is attached */
1440
1441         event_crypto_adapter_enqueue ca_enqueue;
1442         /**< Pointer to PMD crypto adapter enqueue function. */
1443
1444         uint64_t reserved_64s[4]; /**< Reserved for future fields */
1445         void *reserved_ptrs[3];   /**< Reserved for future fields */
1446 } __rte_cache_aligned;
1447
1448 extern struct rte_eventdev *rte_eventdevs;
1449 /** @internal The pool of rte_eventdev structures. */
1450
1451 static __rte_always_inline uint16_t
1452 __rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1453                         const struct rte_event ev[], uint16_t nb_events,
1454                         const event_enqueue_burst_t fn)
1455 {
1456         const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1457
1458 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
1459         if (dev_id >= RTE_EVENT_MAX_DEVS || !rte_eventdevs[dev_id].attached) {
1460                 rte_errno = EINVAL;
1461                 return 0;
1462         }
1463
1464         if (port_id >= dev->data->nb_ports) {
1465                 rte_errno = EINVAL;
1466                 return 0;
1467         }
1468 #endif
1469         rte_eventdev_trace_enq_burst(dev_id, port_id, ev, nb_events, fn);
1470         /*
1471          * Allow zero cost non burst mode routine invocation if application
1472          * requests nb_events as const one
1473          */
1474         if (nb_events == 1)
1475                 return (*dev->enqueue)(dev->data->ports[port_id], ev);
1476         else
1477                 return fn(dev->data->ports[port_id], ev, nb_events);
1478 }
1479
1480 /**
1481  * Enqueue a burst of events objects or an event object supplied in *rte_event*
1482  * structure on an  event device designated by its *dev_id* through the event
1483  * port specified by *port_id*. Each event object specifies the event queue on
1484  * which it will be enqueued.
1485  *
1486  * The *nb_events* parameter is the number of event objects to enqueue which are
1487  * supplied in the *ev* array of *rte_event* structure.
1488  *
1489  * Event operations RTE_EVENT_OP_FORWARD and RTE_EVENT_OP_RELEASE must only be
1490  * enqueued to the same port that their associated events were dequeued from.
1491  *
1492  * The rte_event_enqueue_burst() function returns the number of
1493  * events objects it actually enqueued. A return value equal to *nb_events*
1494  * means that all event objects have been enqueued.
1495  *
1496  * @param dev_id
1497  *   The identifier of the device.
1498  * @param port_id
1499  *   The identifier of the event port.
1500  * @param ev
1501  *   Points to an array of *nb_events* objects of type *rte_event* structure
1502  *   which contain the event object enqueue operations to be processed.
1503  * @param nb_events
1504  *   The number of event objects to enqueue, typically number of
1505  *   rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
1506  *   available for this port.
1507  *
1508  * @return
1509  *   The number of event objects actually enqueued on the event device. The
1510  *   return value can be less than the value of the *nb_events* parameter when
1511  *   the event devices queue is full or if invalid parameters are specified in a
1512  *   *rte_event*. If the return value is less than *nb_events*, the remaining
1513  *   events at the end of ev[] are not consumed and the caller has to take care
1514  *   of them, and rte_errno is set accordingly. Possible errno values include:
1515  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
1516  *              ID is invalid, or an event's sched type doesn't match the
1517  *              capabilities of the destination queue.
1518  *   - ENOSPC   The event port was backpressured and unable to enqueue
1519  *              one or more events. This error code is only applicable to
1520  *              closed systems.
1521  * @see rte_event_port_attr_get(), RTE_EVENT_PORT_ATTR_ENQ_DEPTH
1522  */
1523 static inline uint16_t
1524 rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1525                         const struct rte_event ev[], uint16_t nb_events)
1526 {
1527         const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1528
1529         return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
1530                         dev->enqueue_burst);
1531 }
1532
1533 /**
1534  * Enqueue a burst of events objects of operation type *RTE_EVENT_OP_NEW* on
1535  * an event device designated by its *dev_id* through the event port specified
1536  * by *port_id*.
1537  *
1538  * Provides the same functionality as rte_event_enqueue_burst(), expect that
1539  * application can use this API when the all objects in the burst contains
1540  * the enqueue operation of the type *RTE_EVENT_OP_NEW*. This specialized
1541  * function can provide the additional hint to the PMD and optimize if possible.
1542  *
1543  * The rte_event_enqueue_new_burst() result is undefined if the enqueue burst
1544  * has event object of operation type != RTE_EVENT_OP_NEW.
1545  *
1546  * @param dev_id
1547  *   The identifier of the device.
1548  * @param port_id
1549  *   The identifier of the event port.
1550  * @param ev
1551  *   Points to an array of *nb_events* objects of type *rte_event* structure
1552  *   which contain the event object enqueue operations to be processed.
1553  * @param nb_events
1554  *   The number of event objects to enqueue, typically number of
1555  *   rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
1556  *   available for this port.
1557  *
1558  * @return
1559  *   The number of event objects actually enqueued on the event device. The
1560  *   return value can be less than the value of the *nb_events* parameter when
1561  *   the event devices queue is full or if invalid parameters are specified in a
1562  *   *rte_event*. If the return value is less than *nb_events*, the remaining
1563  *   events at the end of ev[] are not consumed and the caller has to take care
1564  *   of them, and rte_errno is set accordingly. Possible errno values include:
1565  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
1566  *              ID is invalid, or an event's sched type doesn't match the
1567  *              capabilities of the destination queue.
1568  *   - ENOSPC   The event port was backpressured and unable to enqueue
1569  *              one or more events. This error code is only applicable to
1570  *              closed systems.
1571  * @see rte_event_port_attr_get(), RTE_EVENT_PORT_ATTR_ENQ_DEPTH
1572  * @see rte_event_enqueue_burst()
1573  */
1574 static inline uint16_t
1575 rte_event_enqueue_new_burst(uint8_t dev_id, uint8_t port_id,
1576                         const struct rte_event ev[], uint16_t nb_events)
1577 {
1578         const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1579
1580         return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
1581                         dev->enqueue_new_burst);
1582 }
1583
1584 /**
1585  * Enqueue a burst of events objects of operation type *RTE_EVENT_OP_FORWARD*
1586  * on an event device designated by its *dev_id* through the event port
1587  * specified by *port_id*.
1588  *
1589  * Provides the same functionality as rte_event_enqueue_burst(), expect that
1590  * application can use this API when the all objects in the burst contains
1591  * the enqueue operation of the type *RTE_EVENT_OP_FORWARD*. This specialized
1592  * function can provide the additional hint to the PMD and optimize if possible.
1593  *
1594  * The rte_event_enqueue_new_burst() result is undefined if the enqueue burst
1595  * has event object of operation type != RTE_EVENT_OP_FORWARD.
1596  *
1597  * @param dev_id
1598  *   The identifier of the device.
1599  * @param port_id
1600  *   The identifier of the event port.
1601  * @param ev
1602  *   Points to an array of *nb_events* objects of type *rte_event* structure
1603  *   which contain the event object enqueue operations to be processed.
1604  * @param nb_events
1605  *   The number of event objects to enqueue, typically number of
1606  *   rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
1607  *   available for this port.
1608  *
1609  * @return
1610  *   The number of event objects actually enqueued on the event device. The
1611  *   return value can be less than the value of the *nb_events* parameter when
1612  *   the event devices queue is full or if invalid parameters are specified in a
1613  *   *rte_event*. If the return value is less than *nb_events*, the remaining
1614  *   events at the end of ev[] are not consumed and the caller has to take care
1615  *   of them, and rte_errno is set accordingly. Possible errno values include:
1616  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
1617  *              ID is invalid, or an event's sched type doesn't match the
1618  *              capabilities of the destination queue.
1619  *   - ENOSPC   The event port was backpressured and unable to enqueue
1620  *              one or more events. This error code is only applicable to
1621  *              closed systems.
1622  * @see rte_event_port_attr_get(), RTE_EVENT_PORT_ATTR_ENQ_DEPTH
1623  * @see rte_event_enqueue_burst()
1624  */
1625 static inline uint16_t
1626 rte_event_enqueue_forward_burst(uint8_t dev_id, uint8_t port_id,
1627                         const struct rte_event ev[], uint16_t nb_events)
1628 {
1629         const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1630
1631         return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
1632                         dev->enqueue_forward_burst);
1633 }
1634
1635 /**
1636  * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue_burst()
1637  *
1638  * If the device is configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT flag
1639  * then application can use this function to convert timeout value in
1640  * nanoseconds to implementations specific timeout value supplied in
1641  * rte_event_dequeue_burst()
1642  *
1643  * @param dev_id
1644  *   The identifier of the device.
1645  * @param ns
1646  *   Wait time in nanosecond
1647  * @param[out] timeout_ticks
1648  *   Value for the *timeout_ticks* parameter in rte_event_dequeue_burst()
1649  *
1650  * @return
1651  *  - 0 on success.
1652  *  - -ENOTSUP if the device doesn't support timeouts
1653  *  - -EINVAL if *dev_id* is invalid or *timeout_ticks* is NULL
1654  *  - other values < 0 on failure.
1655  *
1656  * @see rte_event_dequeue_burst(), RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1657  * @see rte_event_dev_configure()
1658  *
1659  */
1660 int
1661 rte_event_dequeue_timeout_ticks(uint8_t dev_id, uint64_t ns,
1662                                         uint64_t *timeout_ticks);
1663
1664 /**
1665  * Dequeue a burst of events objects or an event object from the event port
1666  * designated by its *event_port_id*, on an event device designated
1667  * by its *dev_id*.
1668  *
1669  * rte_event_dequeue_burst() does not dictate the specifics of scheduling
1670  * algorithm as each eventdev driver may have different criteria to schedule
1671  * an event. However, in general, from an application perspective scheduler may
1672  * use the following scheme to dispatch an event to the port.
1673  *
1674  * 1) Selection of event queue based on
1675  *   a) The list of event queues are linked to the event port.
1676  *   b) If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then event
1677  *   queue selection from list is based on event queue priority relative to
1678  *   other event queue supplied as *priority* in rte_event_queue_setup()
1679  *   c) If the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability then event
1680  *   queue selection from the list is based on event priority supplied as
1681  *   *priority* in rte_event_enqueue_burst()
1682  * 2) Selection of event
1683  *   a) The number of flows available in selected event queue.
1684  *   b) Schedule type method associated with the event
1685  *
1686  * The *nb_events* parameter is the maximum number of event objects to dequeue
1687  * which are returned in the *ev* array of *rte_event* structure.
1688  *
1689  * The rte_event_dequeue_burst() function returns the number of events objects
1690  * it actually dequeued. A return value equal to *nb_events* means that all
1691  * event objects have been dequeued.
1692  *
1693  * The number of events dequeued is the number of scheduler contexts held by
1694  * this port. These contexts are automatically released in the next
1695  * rte_event_dequeue_burst() invocation if the port supports implicit
1696  * releases, or invoking rte_event_enqueue_burst() with RTE_EVENT_OP_RELEASE
1697  * operation can be used to release the contexts early.
1698  *
1699  * Event operations RTE_EVENT_OP_FORWARD and RTE_EVENT_OP_RELEASE must only be
1700  * enqueued to the same port that their associated events were dequeued from.
1701  *
1702  * @param dev_id
1703  *   The identifier of the device.
1704  * @param port_id
1705  *   The identifier of the event port.
1706  * @param[out] ev
1707  *   Points to an array of *nb_events* objects of type *rte_event* structure
1708  *   for output to be populated with the dequeued event objects.
1709  * @param nb_events
1710  *   The maximum number of event objects to dequeue, typically number of
1711  *   rte_event_port_dequeue_depth() available for this port.
1712  *
1713  * @param timeout_ticks
1714  *   - 0 no-wait, returns immediately if there is no event.
1715  *   - >0 wait for the event, if the device is configured with
1716  *   RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT then this function will wait until
1717  *   at least one event is available or *timeout_ticks* time.
1718  *   if the device is not configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1719  *   then this function will wait until the event available or
1720  *   *dequeue_timeout_ns* ns which was previously supplied to
1721  *   rte_event_dev_configure()
1722  *
1723  * @return
1724  * The number of event objects actually dequeued from the port. The return
1725  * value can be less than the value of the *nb_events* parameter when the
1726  * event port's queue is not full.
1727  *
1728  * @see rte_event_port_dequeue_depth()
1729  */
1730 static inline uint16_t
1731 rte_event_dequeue_burst(uint8_t dev_id, uint8_t port_id, struct rte_event ev[],
1732                         uint16_t nb_events, uint64_t timeout_ticks)
1733 {
1734         struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1735
1736 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
1737         if (dev_id >= RTE_EVENT_MAX_DEVS || !rte_eventdevs[dev_id].attached) {
1738                 rte_errno = EINVAL;
1739                 return 0;
1740         }
1741
1742         if (port_id >= dev->data->nb_ports) {
1743                 rte_errno = EINVAL;
1744                 return 0;
1745         }
1746 #endif
1747         rte_eventdev_trace_deq_burst(dev_id, port_id, ev, nb_events);
1748         /*
1749          * Allow zero cost non burst mode routine invocation if application
1750          * requests nb_events as const one
1751          */
1752         if (nb_events == 1)
1753                 return (*dev->dequeue)(
1754                         dev->data->ports[port_id], ev, timeout_ticks);
1755         else
1756                 return (*dev->dequeue_burst)(
1757                         dev->data->ports[port_id], ev, nb_events,
1758                                 timeout_ticks);
1759 }
1760
1761 /**
1762  * Link multiple source event queues supplied in *queues* to the destination
1763  * event port designated by its *port_id* with associated service priority
1764  * supplied in *priorities* on the event device designated by its *dev_id*.
1765  *
1766  * The link establishment shall enable the event port *port_id* from
1767  * receiving events from the specified event queue(s) supplied in *queues*
1768  *
1769  * An event queue may link to one or more event ports.
1770  * The number of links can be established from an event queue to event port is
1771  * implementation defined.
1772  *
1773  * Event queue(s) to event port link establishment can be changed at runtime
1774  * without re-configuring the device to support scaling and to reduce the
1775  * latency of critical work by establishing the link with more event ports
1776  * at runtime.
1777  *
1778  * @param dev_id
1779  *   The identifier of the device.
1780  *
1781  * @param port_id
1782  *   Event port identifier to select the destination port to link.
1783  *
1784  * @param queues
1785  *   Points to an array of *nb_links* event queues to be linked
1786  *   to the event port.
1787  *   NULL value is allowed, in which case this function links all the configured
1788  *   event queues *nb_event_queues* which previously supplied to
1789  *   rte_event_dev_configure() to the event port *port_id*
1790  *
1791  * @param priorities
1792  *   Points to an array of *nb_links* service priorities associated with each
1793  *   event queue link to event port.
1794  *   The priority defines the event port's servicing priority for
1795  *   event queue, which may be ignored by an implementation.
1796  *   The requested priority should in the range of
1797  *   [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
1798  *   The implementation shall normalize the requested priority to
1799  *   implementation supported priority value.
1800  *   NULL value is allowed, in which case this function links the event queues
1801  *   with RTE_EVENT_DEV_PRIORITY_NORMAL servicing priority
1802  *
1803  * @param nb_links
1804  *   The number of links to establish. This parameter is ignored if queues is
1805  *   NULL.
1806  *
1807  * @return
1808  * The number of links actually established. The return value can be less than
1809  * the value of the *nb_links* parameter when the implementation has the
1810  * limitation on specific queue to port link establishment or if invalid
1811  * parameters are specified in *queues*
1812  * If the return value is less than *nb_links*, the remaining links at the end
1813  * of link[] are not established, and the caller has to take care of them.
1814  * If return value is less than *nb_links* then implementation shall update the
1815  * rte_errno accordingly, Possible rte_errno values are
1816  * (EDQUOT) Quota exceeded(Application tried to link the queue configured with
1817  *  RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
1818  * (EINVAL) Invalid parameter
1819  *
1820  */
1821 int
1822 rte_event_port_link(uint8_t dev_id, uint8_t port_id,
1823                     const uint8_t queues[], const uint8_t priorities[],
1824                     uint16_t nb_links);
1825
1826 /**
1827  * Unlink multiple source event queues supplied in *queues* from the destination
1828  * event port designated by its *port_id* on the event device designated
1829  * by its *dev_id*.
1830  *
1831  * The unlink call issues an async request to disable the event port *port_id*
1832  * from receiving events from the specified event queue *queue_id*.
1833  * Event queue(s) to event port unlink establishment can be changed at runtime
1834  * without re-configuring the device.
1835  *
1836  * @see rte_event_port_unlinks_in_progress() to poll for completed unlinks.
1837  *
1838  * @param dev_id
1839  *   The identifier of the device.
1840  *
1841  * @param port_id
1842  *   Event port identifier to select the destination port to unlink.
1843  *
1844  * @param queues
1845  *   Points to an array of *nb_unlinks* event queues to be unlinked
1846  *   from the event port.
1847  *   NULL value is allowed, in which case this function unlinks all the
1848  *   event queue(s) from the event port *port_id*.
1849  *
1850  * @param nb_unlinks
1851  *   The number of unlinks to establish. This parameter is ignored if queues is
1852  *   NULL.
1853  *
1854  * @return
1855  * The number of unlinks successfully requested. The return value can be less
1856  * than the value of the *nb_unlinks* parameter when the implementation has the
1857  * limitation on specific queue to port unlink establishment or
1858  * if invalid parameters are specified.
1859  * If the return value is less than *nb_unlinks*, the remaining queues at the
1860  * end of queues[] are not unlinked, and the caller has to take care of them.
1861  * If return value is less than *nb_unlinks* then implementation shall update
1862  * the rte_errno accordingly, Possible rte_errno values are
1863  * (EINVAL) Invalid parameter
1864  */
1865 int
1866 rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
1867                       uint8_t queues[], uint16_t nb_unlinks);
1868
1869 /**
1870  * Returns the number of unlinks in progress.
1871  *
1872  * This function provides the application with a method to detect when an
1873  * unlink has been completed by the implementation.
1874  *
1875  * @see rte_event_port_unlink() to issue unlink requests.
1876  *
1877  * @param dev_id
1878  *   The identifier of the device.
1879  *
1880  * @param port_id
1881  *   Event port identifier to select port to check for unlinks in progress.
1882  *
1883  * @return
1884  * The number of unlinks that are in progress. A return of zero indicates that
1885  * there are no outstanding unlink requests. A positive return value indicates
1886  * the number of unlinks that are in progress, but are not yet complete.
1887  * A negative return value indicates an error, -EINVAL indicates an invalid
1888  * parameter passed for *dev_id* or *port_id*.
1889  */
1890 int
1891 rte_event_port_unlinks_in_progress(uint8_t dev_id, uint8_t port_id);
1892
1893 /**
1894  * Retrieve the list of source event queues and its associated service priority
1895  * linked to the destination event port designated by its *port_id*
1896  * on the event device designated by its *dev_id*.
1897  *
1898  * @param dev_id
1899  *   The identifier of the device.
1900  *
1901  * @param port_id
1902  *   Event port identifier.
1903  *
1904  * @param[out] queues
1905  *   Points to an array of *queues* for output.
1906  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1907  *   store the event queue(s) linked with event port *port_id*
1908  *
1909  * @param[out] priorities
1910  *   Points to an array of *priorities* for output.
1911  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1912  *   store the service priority associated with each event queue linked
1913  *
1914  * @return
1915  * The number of links established on the event port designated by its
1916  *  *port_id*.
1917  * - <0 on failure.
1918  *
1919  */
1920 int
1921 rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
1922                          uint8_t queues[], uint8_t priorities[]);
1923
1924 /**
1925  * Retrieve the service ID of the event dev. If the adapter doesn't use
1926  * a rte_service function, this function returns -ESRCH.
1927  *
1928  * @param dev_id
1929  *   The identifier of the device.
1930  *
1931  * @param [out] service_id
1932  *   A pointer to a uint32_t, to be filled in with the service id.
1933  *
1934  * @return
1935  *   - 0: Success
1936  *   - <0: Error code on failure, if the event dev doesn't use a rte_service
1937  *   function, this function returns -ESRCH.
1938  */
1939 int
1940 rte_event_dev_service_id_get(uint8_t dev_id, uint32_t *service_id);
1941
1942 /**
1943  * Dump internal information about *dev_id* to the FILE* provided in *f*.
1944  *
1945  * @param dev_id
1946  *   The identifier of the device.
1947  *
1948  * @param f
1949  *   A pointer to a file for output
1950  *
1951  * @return
1952  *   - 0: on success
1953  *   - <0: on failure.
1954  */
1955 int
1956 rte_event_dev_dump(uint8_t dev_id, FILE *f);
1957
1958 /** Maximum name length for extended statistics counters */
1959 #define RTE_EVENT_DEV_XSTATS_NAME_SIZE 64
1960
1961 /**
1962  * Selects the component of the eventdev to retrieve statistics from.
1963  */
1964 enum rte_event_dev_xstats_mode {
1965         RTE_EVENT_DEV_XSTATS_DEVICE,
1966         RTE_EVENT_DEV_XSTATS_PORT,
1967         RTE_EVENT_DEV_XSTATS_QUEUE,
1968 };
1969
1970 /**
1971  * A name-key lookup element for extended statistics.
1972  *
1973  * This structure is used to map between names and ID numbers
1974  * for extended ethdev statistics.
1975  */
1976 struct rte_event_dev_xstats_name {
1977         char name[RTE_EVENT_DEV_XSTATS_NAME_SIZE];
1978 };
1979
1980 /**
1981  * Retrieve names of extended statistics of an event device.
1982  *
1983  * @param dev_id
1984  *   The identifier of the event device.
1985  * @param mode
1986  *   The mode of statistics to retrieve. Choices include the device statistics,
1987  *   port statistics or queue statistics.
1988  * @param queue_port_id
1989  *   Used to specify the port or queue number in queue or port mode, and is
1990  *   ignored in device mode.
1991  * @param[out] xstats_names
1992  *   Block of memory to insert names into. Must be at least size in capacity.
1993  *   If set to NULL, function returns required capacity.
1994  * @param[out] ids
1995  *   Block of memory to insert ids into. Must be at least size in capacity.
1996  *   If set to NULL, function returns required capacity. The id values returned
1997  *   can be passed to *rte_event_dev_xstats_get* to select statistics.
1998  * @param size
1999  *   Capacity of xstats_names (number of names).
2000  * @return
2001  *   - positive value lower or equal to size: success. The return value
2002  *     is the number of entries filled in the stats table.
2003  *   - positive value higher than size: error, the given statistics table
2004  *     is too small. The return value corresponds to the size that should
2005  *     be given to succeed. The entries in the table are not valid and
2006  *     shall not be used by the caller.
2007  *   - negative value on error:
2008  *        -ENODEV for invalid *dev_id*
2009  *        -EINVAL for invalid mode, queue port or id parameters
2010  *        -ENOTSUP if the device doesn't support this function.
2011  */
2012 int
2013 rte_event_dev_xstats_names_get(uint8_t dev_id,
2014                                enum rte_event_dev_xstats_mode mode,
2015                                uint8_t queue_port_id,
2016                                struct rte_event_dev_xstats_name *xstats_names,
2017                                unsigned int *ids,
2018                                unsigned int size);
2019
2020 /**
2021  * Retrieve extended statistics of an event device.
2022  *
2023  * @param dev_id
2024  *   The identifier of the device.
2025  * @param mode
2026  *  The mode of statistics to retrieve. Choices include the device statistics,
2027  *  port statistics or queue statistics.
2028  * @param queue_port_id
2029  *   Used to specify the port or queue number in queue or port mode, and is
2030  *   ignored in device mode.
2031  * @param ids
2032  *   The id numbers of the stats to get. The ids can be got from the stat
2033  *   position in the stat list from rte_event_dev_get_xstats_names(), or
2034  *   by using rte_event_dev_xstats_by_name_get().
2035  * @param[out] values
2036  *   The values for each stats request by ID.
2037  * @param n
2038  *   The number of stats requested
2039  * @return
2040  *   - positive value: number of stat entries filled into the values array
2041  *   - negative value on error:
2042  *        -ENODEV for invalid *dev_id*
2043  *        -EINVAL for invalid mode, queue port or id parameters
2044  *        -ENOTSUP if the device doesn't support this function.
2045  */
2046 int
2047 rte_event_dev_xstats_get(uint8_t dev_id,
2048                          enum rte_event_dev_xstats_mode mode,
2049                          uint8_t queue_port_id,
2050                          const unsigned int ids[],
2051                          uint64_t values[], unsigned int n);
2052
2053 /**
2054  * Retrieve the value of a single stat by requesting it by name.
2055  *
2056  * @param dev_id
2057  *   The identifier of the device
2058  * @param name
2059  *   The stat name to retrieve
2060  * @param[out] id
2061  *   If non-NULL, the numerical id of the stat will be returned, so that further
2062  *   requests for the stat can be got using rte_event_dev_xstats_get, which will
2063  *   be faster as it doesn't need to scan a list of names for the stat.
2064  *   If the stat cannot be found, the id returned will be (unsigned)-1.
2065  * @return
2066  *   - positive value or zero: the stat value
2067  *   - negative value: -EINVAL if stat not found, -ENOTSUP if not supported.
2068  */
2069 uint64_t
2070 rte_event_dev_xstats_by_name_get(uint8_t dev_id, const char *name,
2071                                  unsigned int *id);
2072
2073 /**
2074  * Reset the values of the xstats of the selected component in the device.
2075  *
2076  * @param dev_id
2077  *   The identifier of the device
2078  * @param mode
2079  *   The mode of the statistics to reset. Choose from device, queue or port.
2080  * @param queue_port_id
2081  *   The queue or port to reset. 0 and positive values select ports and queues,
2082  *   while -1 indicates all ports or queues.
2083  * @param ids
2084  *   Selects specific statistics to be reset. When NULL, all statistics selected
2085  *   by *mode* will be reset. If non-NULL, must point to array of at least
2086  *   *nb_ids* size.
2087  * @param nb_ids
2088  *   The number of ids available from the *ids* array. Ignored when ids is NULL.
2089  * @return
2090  *   - zero: successfully reset the statistics to zero
2091  *   - negative value: -EINVAL invalid parameters, -ENOTSUP if not supported.
2092  */
2093 int
2094 rte_event_dev_xstats_reset(uint8_t dev_id,
2095                            enum rte_event_dev_xstats_mode mode,
2096                            int16_t queue_port_id,
2097                            const uint32_t ids[],
2098                            uint32_t nb_ids);
2099
2100 /**
2101  * Trigger the eventdev self test.
2102  *
2103  * @param dev_id
2104  *   The identifier of the device
2105  * @return
2106  *   - 0: Selftest successful
2107  *   - -ENOTSUP if the device doesn't support selftest
2108  *   - other values < 0 on failure.
2109  */
2110 int rte_event_dev_selftest(uint8_t dev_id);
2111
2112 /**
2113  * Get the memory required per event vector based on the number of elements per
2114  * vector.
2115  * This should be used to create the mempool that holds the event vectors.
2116  *
2117  * @param name
2118  *   The name of the vector pool.
2119  * @param n
2120  *   The number of elements in the mbuf pool.
2121  * @param cache_size
2122  *   Size of the per-core object cache. See rte_mempool_create() for
2123  *   details.
2124  * @param nb_elem
2125  *   The number of elements that a single event vector should be able to hold.
2126  * @param socket_id
2127  *   The socket identifier where the memory should be allocated. The
2128  *   value can be *SOCKET_ID_ANY* if there is no NUMA constraint for the
2129  *   reserved zone
2130  *
2131  * @return
2132  *   The pointer to the newly allocated mempool, on success. NULL on error
2133  *   with rte_errno set appropriately. Possible rte_errno values include:
2134  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
2135  *    - E_RTE_SECONDARY - function was called from a secondary process instance
2136  *    - EINVAL - cache size provided is too large, or priv_size is not aligned.
2137  *    - ENOSPC - the maximum number of memzones has already been allocated
2138  *    - EEXIST - a memzone with the same name already exists
2139  *    - ENOMEM - no appropriate memory area found in which to create memzone
2140  *    - ENAMETOOLONG - mempool name requested is too long.
2141  */
2142 __rte_experimental
2143 struct rte_mempool *
2144 rte_event_vector_pool_create(const char *name, unsigned int n,
2145                              unsigned int cache_size, uint16_t nb_elem,
2146                              int socket_id);
2147
2148 #ifdef __cplusplus
2149 }
2150 #endif
2151
2152 #endif /* _RTE_EVENTDEV_H_ */