raw/cnxk_bphy: keep leading zero in device name
[dpdk.git] / lib / 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 #define RTE_EVENT_PORT_CFG_HINT_PRODUCER       (1ULL << 2)
713 /**< Hint that this event port will primarily enqueue events to the system.
714  * A PMD can optimize its internal workings by assuming that this port is
715  * primarily going to enqueue NEW events.
716  *
717  * Note that this flag is only a hint, so PMDs must operate under the
718  * assumption that any port can enqueue an event with any type of op.
719  *
720  *  @see rte_event_port_setup()
721  */
722 #define RTE_EVENT_PORT_CFG_HINT_CONSUMER       (1ULL << 3)
723 /**< Hint that this event port will primarily dequeue events from the system.
724  * A PMD can optimize its internal workings by assuming that this port is
725  * primarily going to consume events, and not enqueue FORWARD or RELEASE
726  * events.
727  *
728  * Note that this flag is only a hint, so PMDs must operate under the
729  * assumption that any port can enqueue an event with any type of op.
730  *
731  *  @see rte_event_port_setup()
732  */
733 #define RTE_EVENT_PORT_CFG_HINT_WORKER         (1ULL << 4)
734 /**< Hint that this event port will primarily pass existing events through.
735  * A PMD can optimize its internal workings by assuming that this port is
736  * primarily going to FORWARD events, and not enqueue NEW or RELEASE events
737  * often.
738  *
739  * Note that this flag is only a hint, so PMDs must operate under the
740  * assumption that any port can enqueue an event with any type of op.
741  *
742  *  @see rte_event_port_setup()
743  */
744
745 /** Event port configuration structure */
746 struct rte_event_port_conf {
747         int32_t new_event_threshold;
748         /**< A backpressure threshold for new event enqueues on this port.
749          * Use for *closed system* event dev where event capacity is limited,
750          * and cannot exceed the capacity of the event dev.
751          * Configuring ports with different thresholds can make higher priority
752          * traffic less likely to  be backpressured.
753          * For example, a port used to inject NIC Rx packets into the event dev
754          * can have a lower threshold so as not to overwhelm the device,
755          * while ports used for worker pools can have a higher threshold.
756          * This value cannot exceed the *nb_events_limit*
757          * which was previously supplied to rte_event_dev_configure().
758          * This should be set to '-1' for *open system*.
759          */
760         uint16_t dequeue_depth;
761         /**< Configure number of bulk dequeues for this event port.
762          * This value cannot exceed the *nb_event_port_dequeue_depth*
763          * which previously supplied to rte_event_dev_configure().
764          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
765          */
766         uint16_t enqueue_depth;
767         /**< Configure number of bulk enqueues for this event port.
768          * This value cannot exceed the *nb_event_port_enqueue_depth*
769          * which previously supplied to rte_event_dev_configure().
770          * Ignored when device is not RTE_EVENT_DEV_CAP_BURST_MODE capable.
771          */
772         uint32_t event_port_cfg; /**< Port cfg flags(EVENT_PORT_CFG_) */
773 };
774
775 /**
776  * Retrieve the default configuration information of an event port designated
777  * by its *port_id* from the event driver for an event device.
778  *
779  * This function intended to be used in conjunction with rte_event_port_setup()
780  * where caller needs to set up the port by overriding few default values.
781  *
782  * @param dev_id
783  *   The identifier of the device.
784  * @param port_id
785  *   The index of the event port to get the configuration information.
786  *   The value must be in the range [0, nb_event_ports - 1]
787  *   previously supplied to rte_event_dev_configure().
788  * @param[out] port_conf
789  *   The pointer to the default event port configuration data
790  * @return
791  *   - 0: Success, driver updates the default event port configuration data.
792  *   - <0: Error code returned by the driver info get function.
793  *
794  * @see rte_event_port_setup()
795  *
796  */
797 int
798 rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
799                                 struct rte_event_port_conf *port_conf);
800
801 /**
802  * Allocate and set up an event port for an event device.
803  *
804  * @param dev_id
805  *   The identifier of the device.
806  * @param port_id
807  *   The index of the event port to setup. The value must be in the range
808  *   [0, nb_event_ports - 1] previously supplied to rte_event_dev_configure().
809  * @param port_conf
810  *   The pointer to the configuration data to be used for the queue.
811  *   NULL value is allowed, in which case default configuration used.
812  *
813  * @see rte_event_port_default_conf_get()
814  *
815  * @return
816  *   - 0: Success, event port correctly set up.
817  *   - <0: Port configuration failed
818  *   - (-EDQUOT) Quota exceeded(Application tried to link the queue configured
819  *   with RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
820  */
821 int
822 rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
823                      const struct rte_event_port_conf *port_conf);
824
825 /**
826  * The queue depth of the port on the enqueue side
827  */
828 #define RTE_EVENT_PORT_ATTR_ENQ_DEPTH 0
829 /**
830  * The queue depth of the port on the dequeue side
831  */
832 #define RTE_EVENT_PORT_ATTR_DEQ_DEPTH 1
833 /**
834  * The new event threshold of the port
835  */
836 #define RTE_EVENT_PORT_ATTR_NEW_EVENT_THRESHOLD 2
837 /**
838  * The implicit release disable attribute of the port
839  */
840 #define RTE_EVENT_PORT_ATTR_IMPLICIT_RELEASE_DISABLE 3
841
842 /**
843  * Get an attribute from a port.
844  *
845  * @param dev_id
846  *   Eventdev id
847  * @param port_id
848  *   Eventdev port id
849  * @param attr_id
850  *   The attribute ID to retrieve
851  * @param[out] attr_value
852  *   A pointer that will be filled in with the attribute value if successful
853  *
854  * @return
855  *   - 0: Successfully returned value
856  *   - (-EINVAL) Invalid device, port or attr_id, or attr_value was NULL
857  */
858 int
859 rte_event_port_attr_get(uint8_t dev_id, uint8_t port_id, uint32_t attr_id,
860                         uint32_t *attr_value);
861
862 /**
863  * Start an event device.
864  *
865  * The device start step is the last one and consists of setting the event
866  * queues to start accepting the events and schedules to event ports.
867  *
868  * On success, all basic functions exported by the API (event enqueue,
869  * event dequeue and so on) can be invoked.
870  *
871  * @param dev_id
872  *   Event device identifier
873  * @return
874  *   - 0: Success, device started.
875  *   - -ESTALE : Not all ports of the device are configured
876  *   - -ENOLINK: Not all queues are linked, which could lead to deadlock.
877  */
878 int
879 rte_event_dev_start(uint8_t dev_id);
880
881 /**
882  * Stop an event device.
883  *
884  * This function causes all queued events to be drained, including those
885  * residing in event ports. While draining events out of the device, this
886  * function calls the user-provided flush callback (if one was registered) once
887  * per event.
888  *
889  * The device can be restarted with a call to rte_event_dev_start(). Threads
890  * that continue to enqueue/dequeue while the device is stopped, or being
891  * stopped, will result in undefined behavior. This includes event adapters,
892  * which must be stopped prior to stopping the eventdev.
893  *
894  * @param dev_id
895  *   Event device identifier.
896  *
897  * @see rte_event_dev_stop_flush_callback_register()
898  */
899 void
900 rte_event_dev_stop(uint8_t dev_id);
901
902 typedef void (*eventdev_stop_flush_t)(uint8_t dev_id, struct rte_event event,
903                 void *arg);
904 /**< Callback function called during rte_event_dev_stop(), invoked once per
905  * flushed event.
906  */
907
908 /**
909  * Registers a callback function to be invoked during rte_event_dev_stop() for
910  * each flushed event. This function can be used to properly dispose of queued
911  * events, for example events containing memory pointers.
912  *
913  * The callback function is only registered for the calling process. The
914  * callback function must be registered in every process that can call
915  * rte_event_dev_stop().
916  *
917  * To unregister a callback, call this function with a NULL callback pointer.
918  *
919  * @param dev_id
920  *   The identifier of the device.
921  * @param callback
922  *   Callback function invoked once per flushed event.
923  * @param userdata
924  *   Argument supplied to callback.
925  *
926  * @return
927  *  - 0 on success.
928  *  - -EINVAL if *dev_id* is invalid
929  *
930  * @see rte_event_dev_stop()
931  */
932 int
933 rte_event_dev_stop_flush_callback_register(uint8_t dev_id,
934                 eventdev_stop_flush_t callback, void *userdata);
935
936 /**
937  * Close an event device. The device cannot be restarted!
938  *
939  * @param dev_id
940  *   Event device identifier
941  *
942  * @return
943  *  - 0 on successfully closing device
944  *  - <0 on failure to close device
945  *  - (-EAGAIN) if device is busy
946  */
947 int
948 rte_event_dev_close(uint8_t dev_id);
949
950 /**
951  * Event vector structure.
952  */
953 struct rte_event_vector {
954         uint16_t nb_elem;
955         /**< Number of elements in this event vector. */
956         uint16_t rsvd : 15;
957         /**< Reserved for future use */
958         uint16_t attr_valid : 1;
959         /**< Indicates that the below union attributes have valid information.
960          */
961         union {
962                 /* Used by Rx/Tx adapter.
963                  * Indicates that all the elements in this vector belong to the
964                  * same port and queue pair when originating from Rx adapter,
965                  * valid only when event type is ETHDEV_VECTOR or
966                  * ETH_RX_ADAPTER_VECTOR.
967                  * Can also be used to indicate the Tx adapter the destination
968                  * port and queue of the mbufs in the vector
969                  */
970                 struct {
971                         uint16_t port;
972                         /* Ethernet device port id. */
973                         uint16_t queue;
974                         /* Ethernet device queue id. */
975                 };
976         };
977         /**< Union to hold common attributes of the vector array. */
978         uint64_t impl_opaque;
979         /**< Implementation specific opaque value.
980          * An implementation may use this field to hold implementation specific
981          * value to share between dequeue and enqueue operation.
982          * The application should not modify this field.
983          */
984         union {
985                 struct rte_mbuf *mbufs[0];
986                 void *ptrs[0];
987                 uint64_t *u64s[0];
988         } __rte_aligned(16);
989         /**< Start of the vector array union. Depending upon the event type the
990          * vector array can be an array of mbufs or pointers or opaque u64
991          * values.
992          */
993 };
994
995 /* Scheduler type definitions */
996 #define RTE_SCHED_TYPE_ORDERED          0
997 /**< Ordered scheduling
998  *
999  * Events from an ordered flow of an event queue can be scheduled to multiple
1000  * ports for concurrent processing while maintaining the original event order.
1001  * This scheme enables the user to achieve high single flow throughput by
1002  * avoiding SW synchronization for ordering between ports which bound to cores.
1003  *
1004  * The source flow ordering from an event queue is maintained when events are
1005  * enqueued to their destination queue within the same ordered flow context.
1006  * An event port holds the context until application call
1007  * rte_event_dequeue_burst() from the same port, which implicitly releases
1008  * the context.
1009  * User may allow the scheduler to release the context earlier than that
1010  * by invoking rte_event_enqueue_burst() with RTE_EVENT_OP_RELEASE operation.
1011  *
1012  * Events from the source queue appear in their original order when dequeued
1013  * from a destination queue.
1014  * Event ordering is based on the received event(s), but also other
1015  * (newly allocated or stored) events are ordered when enqueued within the same
1016  * ordered context. Events not enqueued (e.g. released or stored) within the
1017  * context are  considered missing from reordering and are skipped at this time
1018  * (but can be ordered again within another context).
1019  *
1020  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
1021  */
1022
1023 #define RTE_SCHED_TYPE_ATOMIC           1
1024 /**< Atomic scheduling
1025  *
1026  * Events from an atomic flow of an event queue can be scheduled only to a
1027  * single port at a time. The port is guaranteed to have exclusive (atomic)
1028  * access to the associated flow context, which enables the user to avoid SW
1029  * synchronization. Atomic flows also help to maintain event ordering
1030  * since only one port at a time can process events from a flow of an
1031  * event queue.
1032  *
1033  * The atomic queue synchronization context is dedicated to the port until
1034  * application call rte_event_dequeue_burst() from the same port,
1035  * which implicitly releases the context. User may allow the scheduler to
1036  * release the context earlier than that by invoking rte_event_enqueue_burst()
1037  * with RTE_EVENT_OP_RELEASE operation.
1038  *
1039  * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
1040  */
1041
1042 #define RTE_SCHED_TYPE_PARALLEL         2
1043 /**< Parallel scheduling
1044  *
1045  * The scheduler performs priority scheduling, load balancing, etc. functions
1046  * but does not provide additional event synchronization or ordering.
1047  * It is free to schedule events from a single parallel flow of an event queue
1048  * to multiple events ports for concurrent processing.
1049  * The application is responsible for flow context synchronization and
1050  * event ordering (SW synchronization).
1051  *
1052  * @see rte_event_queue_setup(), rte_event_dequeue_burst()
1053  */
1054
1055 /* Event types to classify the event source */
1056 #define RTE_EVENT_TYPE_ETHDEV           0x0
1057 /**< The event generated from ethdev subsystem */
1058 #define RTE_EVENT_TYPE_CRYPTODEV        0x1
1059 /**< The event generated from crypodev subsystem */
1060 #define RTE_EVENT_TYPE_TIMER            0x2
1061 /**< The event generated from event timer adapter */
1062 #define RTE_EVENT_TYPE_CPU              0x3
1063 /**< The event generated from cpu for pipelining.
1064  * Application may use *sub_event_type* to further classify the event
1065  */
1066 #define RTE_EVENT_TYPE_ETH_RX_ADAPTER   0x4
1067 /**< The event generated from event eth Rx adapter */
1068 #define RTE_EVENT_TYPE_VECTOR           0x8
1069 /**< Indicates that event is a vector.
1070  * All vector event types should be a logical OR of EVENT_TYPE_VECTOR.
1071  * This simplifies the pipeline design as one can split processing the events
1072  * between vector events and normal event across event types.
1073  * Example:
1074  *      if (ev.event_type & RTE_EVENT_TYPE_VECTOR) {
1075  *              // Classify and handle vector event.
1076  *      } else {
1077  *              // Classify and handle event.
1078  *      }
1079  */
1080 #define RTE_EVENT_TYPE_ETHDEV_VECTOR                                           \
1081         (RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_ETHDEV)
1082 /**< The event vector generated from ethdev subsystem */
1083 #define RTE_EVENT_TYPE_CPU_VECTOR (RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_CPU)
1084 /**< The event vector generated from cpu for pipelining. */
1085 #define RTE_EVENT_TYPE_ETH_RX_ADAPTER_VECTOR                                   \
1086         (RTE_EVENT_TYPE_VECTOR | RTE_EVENT_TYPE_ETH_RX_ADAPTER)
1087 /**< The event vector generated from eth Rx adapter. */
1088
1089 #define RTE_EVENT_TYPE_MAX              0x10
1090 /**< Maximum number of event types */
1091
1092 /* Event enqueue operations */
1093 #define RTE_EVENT_OP_NEW                0
1094 /**< The event producers use this operation to inject a new event to the
1095  * event device.
1096  */
1097 #define RTE_EVENT_OP_FORWARD            1
1098 /**< The CPU use this operation to forward the event to different event queue or
1099  * change to new application specific flow or schedule type to enable
1100  * pipelining.
1101  *
1102  * This operation must only be enqueued to the same port that the
1103  * event to be forwarded was dequeued from.
1104  */
1105 #define RTE_EVENT_OP_RELEASE            2
1106 /**< Release the flow context associated with the schedule type.
1107  *
1108  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ATOMIC*
1109  * then this function hints the scheduler that the user has completed critical
1110  * section processing in the current atomic context.
1111  * The scheduler is now allowed to schedule events from the same flow from
1112  * an event queue to another port. However, the context may be still held
1113  * until the next rte_event_dequeue_burst() call, this call allows but does not
1114  * force the scheduler to release the context early.
1115  *
1116  * Early atomic context release may increase parallelism and thus system
1117  * performance, but the user needs to design carefully the split into critical
1118  * vs non-critical sections.
1119  *
1120  * If current flow's scheduler type method is *RTE_SCHED_TYPE_ORDERED*
1121  * then this function hints the scheduler that the user has done all that need
1122  * to maintain event order in the current ordered context.
1123  * The scheduler is allowed to release the ordered context of this port and
1124  * avoid reordering any following enqueues.
1125  *
1126  * Early ordered context release may increase parallelism and thus system
1127  * performance.
1128  *
1129  * If current flow's scheduler type method is *RTE_SCHED_TYPE_PARALLEL*
1130  * or no scheduling context is held then this function may be an NOOP,
1131  * depending on the implementation.
1132  *
1133  * This operation must only be enqueued to the same port that the
1134  * event to be released was dequeued from.
1135  *
1136  */
1137
1138 /**
1139  * The generic *rte_event* structure to hold the event attributes
1140  * for dequeue and enqueue operation
1141  */
1142 RTE_STD_C11
1143 struct rte_event {
1144         /** WORD0 */
1145         union {
1146                 uint64_t event;
1147                 /** Event attributes for dequeue or enqueue operation */
1148                 struct {
1149                         uint32_t flow_id:20;
1150                         /**< Targeted flow identifier for the enqueue and
1151                          * dequeue operation.
1152                          * The value must be in the range of
1153                          * [0, nb_event_queue_flows - 1] which
1154                          * previously supplied to rte_event_dev_configure().
1155                          */
1156                         uint32_t sub_event_type:8;
1157                         /**< Sub-event types based on the event source.
1158                          * @see RTE_EVENT_TYPE_CPU
1159                          */
1160                         uint32_t event_type:4;
1161                         /**< Event type to classify the event source.
1162                          * @see RTE_EVENT_TYPE_ETHDEV, (RTE_EVENT_TYPE_*)
1163                          */
1164                         uint8_t op:2;
1165                         /**< The type of event enqueue operation - new/forward/
1166                          * etc.This field is not preserved across an instance
1167                          * and is undefined on dequeue.
1168                          * @see RTE_EVENT_OP_NEW, (RTE_EVENT_OP_*)
1169                          */
1170                         uint8_t rsvd:4;
1171                         /**< Reserved for future use */
1172                         uint8_t sched_type:2;
1173                         /**< Scheduler synchronization type (RTE_SCHED_TYPE_*)
1174                          * associated with flow id on a given event queue
1175                          * for the enqueue and dequeue operation.
1176                          */
1177                         uint8_t queue_id;
1178                         /**< Targeted event queue identifier for the enqueue or
1179                          * dequeue operation.
1180                          * The value must be in the range of
1181                          * [0, nb_event_queues - 1] which previously supplied to
1182                          * rte_event_dev_configure().
1183                          */
1184                         uint8_t priority;
1185                         /**< Event priority relative to other events in the
1186                          * event queue. The requested priority should in the
1187                          * range of  [RTE_EVENT_DEV_PRIORITY_HIGHEST,
1188                          * RTE_EVENT_DEV_PRIORITY_LOWEST].
1189                          * The implementation shall normalize the requested
1190                          * priority to supported priority value.
1191                          * Valid when the device has
1192                          * RTE_EVENT_DEV_CAP_EVENT_QOS capability.
1193                          */
1194                         uint8_t impl_opaque;
1195                         /**< Implementation specific opaque value.
1196                          * An implementation may use this field to hold
1197                          * implementation specific value to share between
1198                          * dequeue and enqueue operation.
1199                          * The application should not modify this field.
1200                          */
1201                 };
1202         };
1203         /** WORD1 */
1204         union {
1205                 uint64_t u64;
1206                 /**< Opaque 64-bit value */
1207                 void *event_ptr;
1208                 /**< Opaque event pointer */
1209                 struct rte_mbuf *mbuf;
1210                 /**< mbuf pointer if dequeued event is associated with mbuf */
1211                 struct rte_event_vector *vec;
1212                 /**< Event vector pointer. */
1213         };
1214 };
1215
1216 /* Ethdev Rx adapter capability bitmap flags */
1217 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT      0x1
1218 /**< This flag is sent when the packet transfer mechanism is in HW.
1219  * Ethdev can send packets to the event device using internal event port.
1220  */
1221 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ       0x2
1222 /**< Adapter supports multiple event queues per ethdev. Every ethdev
1223  * Rx queue can be connected to a unique event queue.
1224  */
1225 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID   0x4
1226 /**< The application can override the adapter generated flow ID in the
1227  * event. This flow ID can be specified when adding an ethdev Rx queue
1228  * to the adapter using the ev.flow_id member.
1229  * @see struct rte_event_eth_rx_adapter_queue_conf::ev
1230  * @see struct rte_event_eth_rx_adapter_queue_conf::rx_queue_flags
1231  */
1232 #define RTE_EVENT_ETH_RX_ADAPTER_CAP_EVENT_VECTOR       0x8
1233 /**< Adapter supports event vectorization per ethdev. */
1234
1235 /**
1236  * Retrieve the event device's ethdev Rx adapter capabilities for the
1237  * specified ethernet port
1238  *
1239  * @param dev_id
1240  *   The identifier of the device.
1241  *
1242  * @param eth_port_id
1243  *   The identifier of the ethernet device.
1244  *
1245  * @param[out] caps
1246  *   A pointer to memory filled with Rx event adapter capabilities.
1247  *
1248  * @return
1249  *   - 0: Success, driver provides Rx event adapter capabilities for the
1250  *      ethernet device.
1251  *   - <0: Error code returned by the driver function.
1252  *
1253  */
1254 int
1255 rte_event_eth_rx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
1256                                 uint32_t *caps);
1257
1258 #define RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT (1ULL << 0)
1259 /**< This flag is set when the timer mechanism is in HW. */
1260
1261 #define RTE_EVENT_TIMER_ADAPTER_CAP_PERIODIC      (1ULL << 1)
1262 /**< This flag is set if periodic mode is supported. */
1263
1264 /**
1265  * Retrieve the event device's timer adapter capabilities.
1266  *
1267  * @param dev_id
1268  *   The identifier of the device.
1269  *
1270  * @param[out] caps
1271  *   A pointer to memory to be filled with event timer adapter capabilities.
1272  *
1273  * @return
1274  *   - 0: Success, driver provided event timer adapter capabilities.
1275  *   - <0: Error code returned by the driver function.
1276  */
1277 int
1278 rte_event_timer_adapter_caps_get(uint8_t dev_id, uint32_t *caps);
1279
1280 /* Crypto adapter capability bitmap flag */
1281 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW   0x1
1282 /**< Flag indicates HW is capable of generating events in
1283  * RTE_EVENT_OP_NEW enqueue operation. Cryptodev will send
1284  * packets to the event device as new events using an internal
1285  * event port.
1286  */
1287
1288 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD   0x2
1289 /**< Flag indicates HW is capable of generating events in
1290  * RTE_EVENT_OP_FORWARD enqueue operation. Cryptodev will send
1291  * packets to the event device as forwarded event using an
1292  * internal event port.
1293  */
1294
1295 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND  0x4
1296 /**< Flag indicates HW is capable of mapping crypto queue pair to
1297  * event queue.
1298  */
1299
1300 #define RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA   0x8
1301 /**< Flag indicates HW/SW supports a mechanism to store and retrieve
1302  * the private data information along with the crypto session.
1303  */
1304
1305 /**
1306  * Retrieve the event device's crypto adapter capabilities for the
1307  * specified cryptodev device
1308  *
1309  * @param dev_id
1310  *   The identifier of the device.
1311  *
1312  * @param cdev_id
1313  *   The identifier of the cryptodev device.
1314  *
1315  * @param[out] caps
1316  *   A pointer to memory filled with event adapter capabilities.
1317  *   It is expected to be pre-allocated & initialized by caller.
1318  *
1319  * @return
1320  *   - 0: Success, driver provides event adapter capabilities for the
1321  *     cryptodev device.
1322  *   - <0: Error code returned by the driver function.
1323  *
1324  */
1325 int
1326 rte_event_crypto_adapter_caps_get(uint8_t dev_id, uint8_t cdev_id,
1327                                   uint32_t *caps);
1328
1329 /* Ethdev Tx adapter capability bitmap flags */
1330 #define RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT      0x1
1331 /**< This flag is sent when the PMD supports a packet transmit callback
1332  */
1333 #define RTE_EVENT_ETH_TX_ADAPTER_CAP_EVENT_VECTOR       0x2
1334 /**< Indicates that the Tx adapter is capable of handling event vector of
1335  * mbufs.
1336  */
1337
1338 /**
1339  * Retrieve the event device's eth Tx adapter capabilities
1340  *
1341  * @param dev_id
1342  *   The identifier of the device.
1343  *
1344  * @param eth_port_id
1345  *   The identifier of the ethernet device.
1346  *
1347  * @param[out] caps
1348  *   A pointer to memory filled with eth Tx adapter capabilities.
1349  *
1350  * @return
1351  *   - 0: Success, driver provides eth Tx adapter capabilities.
1352  *   - <0: Error code returned by the driver function.
1353  *
1354  */
1355 int
1356 rte_event_eth_tx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
1357                                 uint32_t *caps);
1358
1359 /**
1360  * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue_burst()
1361  *
1362  * If the device is configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT flag
1363  * then application can use this function to convert timeout value in
1364  * nanoseconds to implementations specific timeout value supplied in
1365  * rte_event_dequeue_burst()
1366  *
1367  * @param dev_id
1368  *   The identifier of the device.
1369  * @param ns
1370  *   Wait time in nanosecond
1371  * @param[out] timeout_ticks
1372  *   Value for the *timeout_ticks* parameter in rte_event_dequeue_burst()
1373  *
1374  * @return
1375  *  - 0 on success.
1376  *  - -ENOTSUP if the device doesn't support timeouts
1377  *  - -EINVAL if *dev_id* is invalid or *timeout_ticks* is NULL
1378  *  - other values < 0 on failure.
1379  *
1380  * @see rte_event_dequeue_burst(), RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1381  * @see rte_event_dev_configure()
1382  *
1383  */
1384 int
1385 rte_event_dequeue_timeout_ticks(uint8_t dev_id, uint64_t ns,
1386                                         uint64_t *timeout_ticks);
1387
1388 /**
1389  * Link multiple source event queues supplied in *queues* to the destination
1390  * event port designated by its *port_id* with associated service priority
1391  * supplied in *priorities* on the event device designated by its *dev_id*.
1392  *
1393  * The link establishment shall enable the event port *port_id* from
1394  * receiving events from the specified event queue(s) supplied in *queues*
1395  *
1396  * An event queue may link to one or more event ports.
1397  * The number of links can be established from an event queue to event port is
1398  * implementation defined.
1399  *
1400  * Event queue(s) to event port link establishment can be changed at runtime
1401  * without re-configuring the device to support scaling and to reduce the
1402  * latency of critical work by establishing the link with more event ports
1403  * at runtime.
1404  *
1405  * @param dev_id
1406  *   The identifier of the device.
1407  *
1408  * @param port_id
1409  *   Event port identifier to select the destination port to link.
1410  *
1411  * @param queues
1412  *   Points to an array of *nb_links* event queues to be linked
1413  *   to the event port.
1414  *   NULL value is allowed, in which case this function links all the configured
1415  *   event queues *nb_event_queues* which previously supplied to
1416  *   rte_event_dev_configure() to the event port *port_id*
1417  *
1418  * @param priorities
1419  *   Points to an array of *nb_links* service priorities associated with each
1420  *   event queue link to event port.
1421  *   The priority defines the event port's servicing priority for
1422  *   event queue, which may be ignored by an implementation.
1423  *   The requested priority should in the range of
1424  *   [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
1425  *   The implementation shall normalize the requested priority to
1426  *   implementation supported priority value.
1427  *   NULL value is allowed, in which case this function links the event queues
1428  *   with RTE_EVENT_DEV_PRIORITY_NORMAL servicing priority
1429  *
1430  * @param nb_links
1431  *   The number of links to establish. This parameter is ignored if queues is
1432  *   NULL.
1433  *
1434  * @return
1435  * The number of links actually established. The return value can be less than
1436  * the value of the *nb_links* parameter when the implementation has the
1437  * limitation on specific queue to port link establishment or if invalid
1438  * parameters are specified in *queues*
1439  * If the return value is less than *nb_links*, the remaining links at the end
1440  * of link[] are not established, and the caller has to take care of them.
1441  * If return value is less than *nb_links* then implementation shall update the
1442  * rte_errno accordingly, Possible rte_errno values are
1443  * (EDQUOT) Quota exceeded(Application tried to link the queue configured with
1444  *  RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
1445  * (EINVAL) Invalid parameter
1446  *
1447  */
1448 int
1449 rte_event_port_link(uint8_t dev_id, uint8_t port_id,
1450                     const uint8_t queues[], const uint8_t priorities[],
1451                     uint16_t nb_links);
1452
1453 /**
1454  * Unlink multiple source event queues supplied in *queues* from the destination
1455  * event port designated by its *port_id* on the event device designated
1456  * by its *dev_id*.
1457  *
1458  * The unlink call issues an async request to disable the event port *port_id*
1459  * from receiving events from the specified event queue *queue_id*.
1460  * Event queue(s) to event port unlink establishment can be changed at runtime
1461  * without re-configuring the device.
1462  *
1463  * @see rte_event_port_unlinks_in_progress() to poll for completed unlinks.
1464  *
1465  * @param dev_id
1466  *   The identifier of the device.
1467  *
1468  * @param port_id
1469  *   Event port identifier to select the destination port to unlink.
1470  *
1471  * @param queues
1472  *   Points to an array of *nb_unlinks* event queues to be unlinked
1473  *   from the event port.
1474  *   NULL value is allowed, in which case this function unlinks all the
1475  *   event queue(s) from the event port *port_id*.
1476  *
1477  * @param nb_unlinks
1478  *   The number of unlinks to establish. This parameter is ignored if queues is
1479  *   NULL.
1480  *
1481  * @return
1482  * The number of unlinks successfully requested. The return value can be less
1483  * than the value of the *nb_unlinks* parameter when the implementation has the
1484  * limitation on specific queue to port unlink establishment or
1485  * if invalid parameters are specified.
1486  * If the return value is less than *nb_unlinks*, the remaining queues at the
1487  * end of queues[] are not unlinked, and the caller has to take care of them.
1488  * If return value is less than *nb_unlinks* then implementation shall update
1489  * the rte_errno accordingly, Possible rte_errno values are
1490  * (EINVAL) Invalid parameter
1491  */
1492 int
1493 rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
1494                       uint8_t queues[], uint16_t nb_unlinks);
1495
1496 /**
1497  * Returns the number of unlinks in progress.
1498  *
1499  * This function provides the application with a method to detect when an
1500  * unlink has been completed by the implementation.
1501  *
1502  * @see rte_event_port_unlink() to issue unlink requests.
1503  *
1504  * @param dev_id
1505  *   The identifier of the device.
1506  *
1507  * @param port_id
1508  *   Event port identifier to select port to check for unlinks in progress.
1509  *
1510  * @return
1511  * The number of unlinks that are in progress. A return of zero indicates that
1512  * there are no outstanding unlink requests. A positive return value indicates
1513  * the number of unlinks that are in progress, but are not yet complete.
1514  * A negative return value indicates an error, -EINVAL indicates an invalid
1515  * parameter passed for *dev_id* or *port_id*.
1516  */
1517 int
1518 rte_event_port_unlinks_in_progress(uint8_t dev_id, uint8_t port_id);
1519
1520 /**
1521  * Retrieve the list of source event queues and its associated service priority
1522  * linked to the destination event port designated by its *port_id*
1523  * on the event device designated by its *dev_id*.
1524  *
1525  * @param dev_id
1526  *   The identifier of the device.
1527  *
1528  * @param port_id
1529  *   Event port identifier.
1530  *
1531  * @param[out] queues
1532  *   Points to an array of *queues* for output.
1533  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1534  *   store the event queue(s) linked with event port *port_id*
1535  *
1536  * @param[out] priorities
1537  *   Points to an array of *priorities* for output.
1538  *   The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1539  *   store the service priority associated with each event queue linked
1540  *
1541  * @return
1542  * The number of links established on the event port designated by its
1543  *  *port_id*.
1544  * - <0 on failure.
1545  *
1546  */
1547 int
1548 rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
1549                          uint8_t queues[], uint8_t priorities[]);
1550
1551 /**
1552  * Retrieve the service ID of the event dev. If the adapter doesn't use
1553  * a rte_service function, this function returns -ESRCH.
1554  *
1555  * @param dev_id
1556  *   The identifier of the device.
1557  *
1558  * @param [out] service_id
1559  *   A pointer to a uint32_t, to be filled in with the service id.
1560  *
1561  * @return
1562  *   - 0: Success
1563  *   - <0: Error code on failure, if the event dev doesn't use a rte_service
1564  *   function, this function returns -ESRCH.
1565  */
1566 int
1567 rte_event_dev_service_id_get(uint8_t dev_id, uint32_t *service_id);
1568
1569 /**
1570  * Dump internal information about *dev_id* to the FILE* provided in *f*.
1571  *
1572  * @param dev_id
1573  *   The identifier of the device.
1574  *
1575  * @param f
1576  *   A pointer to a file for output
1577  *
1578  * @return
1579  *   - 0: on success
1580  *   - <0: on failure.
1581  */
1582 int
1583 rte_event_dev_dump(uint8_t dev_id, FILE *f);
1584
1585 /** Maximum name length for extended statistics counters */
1586 #define RTE_EVENT_DEV_XSTATS_NAME_SIZE 64
1587
1588 /**
1589  * Selects the component of the eventdev to retrieve statistics from.
1590  */
1591 enum rte_event_dev_xstats_mode {
1592         RTE_EVENT_DEV_XSTATS_DEVICE,
1593         RTE_EVENT_DEV_XSTATS_PORT,
1594         RTE_EVENT_DEV_XSTATS_QUEUE,
1595 };
1596
1597 /**
1598  * A name-key lookup element for extended statistics.
1599  *
1600  * This structure is used to map between names and ID numbers
1601  * for extended ethdev statistics.
1602  */
1603 struct rte_event_dev_xstats_name {
1604         char name[RTE_EVENT_DEV_XSTATS_NAME_SIZE];
1605 };
1606
1607 /**
1608  * Retrieve names of extended statistics of an event device.
1609  *
1610  * @param dev_id
1611  *   The identifier of the event device.
1612  * @param mode
1613  *   The mode of statistics to retrieve. Choices include the device statistics,
1614  *   port statistics or queue statistics.
1615  * @param queue_port_id
1616  *   Used to specify the port or queue number in queue or port mode, and is
1617  *   ignored in device mode.
1618  * @param[out] xstats_names
1619  *   Block of memory to insert names into. Must be at least size in capacity.
1620  *   If set to NULL, function returns required capacity.
1621  * @param[out] ids
1622  *   Block of memory to insert ids into. Must be at least size in capacity.
1623  *   If set to NULL, function returns required capacity. The id values returned
1624  *   can be passed to *rte_event_dev_xstats_get* to select statistics.
1625  * @param size
1626  *   Capacity of xstats_names (number of names).
1627  * @return
1628  *   - positive value lower or equal to size: success. The return value
1629  *     is the number of entries filled in the stats table.
1630  *   - positive value higher than size: error, the given statistics table
1631  *     is too small. The return value corresponds to the size that should
1632  *     be given to succeed. The entries in the table are not valid and
1633  *     shall not be used by the caller.
1634  *   - negative value on error:
1635  *        -ENODEV for invalid *dev_id*
1636  *        -EINVAL for invalid mode, queue port or id parameters
1637  *        -ENOTSUP if the device doesn't support this function.
1638  */
1639 int
1640 rte_event_dev_xstats_names_get(uint8_t dev_id,
1641                                enum rte_event_dev_xstats_mode mode,
1642                                uint8_t queue_port_id,
1643                                struct rte_event_dev_xstats_name *xstats_names,
1644                                unsigned int *ids,
1645                                unsigned int size);
1646
1647 /**
1648  * Retrieve extended statistics of an event device.
1649  *
1650  * @param dev_id
1651  *   The identifier of the device.
1652  * @param mode
1653  *  The mode of statistics to retrieve. Choices include the device statistics,
1654  *  port statistics or queue statistics.
1655  * @param queue_port_id
1656  *   Used to specify the port or queue number in queue or port mode, and is
1657  *   ignored in device mode.
1658  * @param ids
1659  *   The id numbers of the stats to get. The ids can be got from the stat
1660  *   position in the stat list from rte_event_dev_get_xstats_names(), or
1661  *   by using rte_event_dev_xstats_by_name_get().
1662  * @param[out] values
1663  *   The values for each stats request by ID.
1664  * @param n
1665  *   The number of stats requested
1666  * @return
1667  *   - positive value: number of stat entries filled into the values array
1668  *   - negative value on error:
1669  *        -ENODEV for invalid *dev_id*
1670  *        -EINVAL for invalid mode, queue port or id parameters
1671  *        -ENOTSUP if the device doesn't support this function.
1672  */
1673 int
1674 rte_event_dev_xstats_get(uint8_t dev_id,
1675                          enum rte_event_dev_xstats_mode mode,
1676                          uint8_t queue_port_id,
1677                          const unsigned int ids[],
1678                          uint64_t values[], unsigned int n);
1679
1680 /**
1681  * Retrieve the value of a single stat by requesting it by name.
1682  *
1683  * @param dev_id
1684  *   The identifier of the device
1685  * @param name
1686  *   The stat name to retrieve
1687  * @param[out] id
1688  *   If non-NULL, the numerical id of the stat will be returned, so that further
1689  *   requests for the stat can be got using rte_event_dev_xstats_get, which will
1690  *   be faster as it doesn't need to scan a list of names for the stat.
1691  *   If the stat cannot be found, the id returned will be (unsigned)-1.
1692  * @return
1693  *   - positive value or zero: the stat value
1694  *   - negative value: -EINVAL if stat not found, -ENOTSUP if not supported.
1695  */
1696 uint64_t
1697 rte_event_dev_xstats_by_name_get(uint8_t dev_id, const char *name,
1698                                  unsigned int *id);
1699
1700 /**
1701  * Reset the values of the xstats of the selected component in the device.
1702  *
1703  * @param dev_id
1704  *   The identifier of the device
1705  * @param mode
1706  *   The mode of the statistics to reset. Choose from device, queue or port.
1707  * @param queue_port_id
1708  *   The queue or port to reset. 0 and positive values select ports and queues,
1709  *   while -1 indicates all ports or queues.
1710  * @param ids
1711  *   Selects specific statistics to be reset. When NULL, all statistics selected
1712  *   by *mode* will be reset. If non-NULL, must point to array of at least
1713  *   *nb_ids* size.
1714  * @param nb_ids
1715  *   The number of ids available from the *ids* array. Ignored when ids is NULL.
1716  * @return
1717  *   - zero: successfully reset the statistics to zero
1718  *   - negative value: -EINVAL invalid parameters, -ENOTSUP if not supported.
1719  */
1720 int
1721 rte_event_dev_xstats_reset(uint8_t dev_id,
1722                            enum rte_event_dev_xstats_mode mode,
1723                            int16_t queue_port_id,
1724                            const uint32_t ids[],
1725                            uint32_t nb_ids);
1726
1727 /**
1728  * Trigger the eventdev self test.
1729  *
1730  * @param dev_id
1731  *   The identifier of the device
1732  * @return
1733  *   - 0: Selftest successful
1734  *   - -ENOTSUP if the device doesn't support selftest
1735  *   - other values < 0 on failure.
1736  */
1737 int rte_event_dev_selftest(uint8_t dev_id);
1738
1739 /**
1740  * Get the memory required per event vector based on the number of elements per
1741  * vector.
1742  * This should be used to create the mempool that holds the event vectors.
1743  *
1744  * @param name
1745  *   The name of the vector pool.
1746  * @param n
1747  *   The number of elements in the mbuf pool.
1748  * @param cache_size
1749  *   Size of the per-core object cache. See rte_mempool_create() for
1750  *   details.
1751  * @param nb_elem
1752  *   The number of elements that a single event vector should be able to hold.
1753  * @param socket_id
1754  *   The socket identifier where the memory should be allocated. The
1755  *   value can be *SOCKET_ID_ANY* if there is no NUMA constraint for the
1756  *   reserved zone
1757  *
1758  * @return
1759  *   The pointer to the newly allocated mempool, on success. NULL on error
1760  *   with rte_errno set appropriately. Possible rte_errno values include:
1761  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
1762  *    - E_RTE_SECONDARY - function was called from a secondary process instance
1763  *    - EINVAL - cache size provided is too large, or priv_size is not aligned.
1764  *    - ENOSPC - the maximum number of memzones has already been allocated
1765  *    - EEXIST - a memzone with the same name already exists
1766  *    - ENOMEM - no appropriate memory area found in which to create memzone
1767  *    - ENAMETOOLONG - mempool name requested is too long.
1768  */
1769 struct rte_mempool *
1770 rte_event_vector_pool_create(const char *name, unsigned int n,
1771                              unsigned int cache_size, uint16_t nb_elem,
1772                              int socket_id);
1773
1774 #include <rte_eventdev_core.h>
1775
1776 static __rte_always_inline uint16_t
1777 __rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1778                           const struct rte_event ev[], uint16_t nb_events,
1779                           const event_enqueue_burst_t fn)
1780 {
1781         const struct rte_event_fp_ops *fp_ops;
1782         void *port;
1783
1784         fp_ops = &rte_event_fp_ops[dev_id];
1785         port = fp_ops->data[port_id];
1786 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
1787         if (dev_id >= RTE_EVENT_MAX_DEVS ||
1788             port_id >= RTE_EVENT_MAX_PORTS_PER_DEV) {
1789                 rte_errno = EINVAL;
1790                 return 0;
1791         }
1792
1793         if (port == NULL) {
1794                 rte_errno = EINVAL;
1795                 return 0;
1796         }
1797 #endif
1798         rte_eventdev_trace_enq_burst(dev_id, port_id, ev, nb_events, fn);
1799         /*
1800          * Allow zero cost non burst mode routine invocation if application
1801          * requests nb_events as const one
1802          */
1803         if (nb_events == 1)
1804                 return (fp_ops->enqueue)(port, ev);
1805         else
1806                 return fn(port, ev, nb_events);
1807 }
1808
1809 /**
1810  * Enqueue a burst of events objects or an event object supplied in *rte_event*
1811  * structure on an  event device designated by its *dev_id* through the event
1812  * port specified by *port_id*. Each event object specifies the event queue on
1813  * which it will be enqueued.
1814  *
1815  * The *nb_events* parameter is the number of event objects to enqueue which are
1816  * supplied in the *ev* array of *rte_event* structure.
1817  *
1818  * Event operations RTE_EVENT_OP_FORWARD and RTE_EVENT_OP_RELEASE must only be
1819  * enqueued to the same port that their associated events were dequeued from.
1820  *
1821  * The rte_event_enqueue_burst() function returns the number of
1822  * events objects it actually enqueued. A return value equal to *nb_events*
1823  * means that all event objects have been enqueued.
1824  *
1825  * @param dev_id
1826  *   The identifier of the device.
1827  * @param port_id
1828  *   The identifier of the event port.
1829  * @param ev
1830  *   Points to an array of *nb_events* objects of type *rte_event* structure
1831  *   which contain the event object enqueue operations to be processed.
1832  * @param nb_events
1833  *   The number of event objects to enqueue, typically number of
1834  *   rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
1835  *   available for this port.
1836  *
1837  * @return
1838  *   The number of event objects actually enqueued on the event device. The
1839  *   return value can be less than the value of the *nb_events* parameter when
1840  *   the event devices queue is full or if invalid parameters are specified in a
1841  *   *rte_event*. If the return value is less than *nb_events*, the remaining
1842  *   events at the end of ev[] are not consumed and the caller has to take care
1843  *   of them, and rte_errno is set accordingly. Possible errno values include:
1844  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
1845  *              ID is invalid, or an event's sched type doesn't match the
1846  *              capabilities of the destination queue.
1847  *   - ENOSPC   The event port was backpressured and unable to enqueue
1848  *              one or more events. This error code is only applicable to
1849  *              closed systems.
1850  * @see rte_event_port_attr_get(), RTE_EVENT_PORT_ATTR_ENQ_DEPTH
1851  */
1852 static inline uint16_t
1853 rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1854                         const struct rte_event ev[], uint16_t nb_events)
1855 {
1856         const struct rte_event_fp_ops *fp_ops;
1857
1858         fp_ops = &rte_event_fp_ops[dev_id];
1859         return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
1860                                          fp_ops->enqueue_burst);
1861 }
1862
1863 /**
1864  * Enqueue a burst of events objects of operation type *RTE_EVENT_OP_NEW* on
1865  * an event device designated by its *dev_id* through the event port specified
1866  * by *port_id*.
1867  *
1868  * Provides the same functionality as rte_event_enqueue_burst(), expect that
1869  * application can use this API when the all objects in the burst contains
1870  * the enqueue operation of the type *RTE_EVENT_OP_NEW*. This specialized
1871  * function can provide the additional hint to the PMD and optimize if possible.
1872  *
1873  * The rte_event_enqueue_new_burst() result is undefined if the enqueue burst
1874  * has event object of operation type != RTE_EVENT_OP_NEW.
1875  *
1876  * @param dev_id
1877  *   The identifier of the device.
1878  * @param port_id
1879  *   The identifier of the event port.
1880  * @param ev
1881  *   Points to an array of *nb_events* objects of type *rte_event* structure
1882  *   which contain the event object enqueue operations to be processed.
1883  * @param nb_events
1884  *   The number of event objects to enqueue, typically number of
1885  *   rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
1886  *   available for this port.
1887  *
1888  * @return
1889  *   The number of event objects actually enqueued on the event device. The
1890  *   return value can be less than the value of the *nb_events* parameter when
1891  *   the event devices queue is full or if invalid parameters are specified in a
1892  *   *rte_event*. If the return value is less than *nb_events*, the remaining
1893  *   events at the end of ev[] are not consumed and the caller has to take care
1894  *   of them, and rte_errno is set accordingly. Possible errno values include:
1895  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
1896  *              ID is invalid, or an event's sched type doesn't match the
1897  *              capabilities of the destination queue.
1898  *   - ENOSPC   The event port was backpressured and unable to enqueue
1899  *              one or more events. This error code is only applicable to
1900  *              closed systems.
1901  * @see rte_event_port_attr_get(), RTE_EVENT_PORT_ATTR_ENQ_DEPTH
1902  * @see rte_event_enqueue_burst()
1903  */
1904 static inline uint16_t
1905 rte_event_enqueue_new_burst(uint8_t dev_id, uint8_t port_id,
1906                             const struct rte_event ev[], uint16_t nb_events)
1907 {
1908         const struct rte_event_fp_ops *fp_ops;
1909
1910         fp_ops = &rte_event_fp_ops[dev_id];
1911         return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
1912                                          fp_ops->enqueue_new_burst);
1913 }
1914
1915 /**
1916  * Enqueue a burst of events objects of operation type *RTE_EVENT_OP_FORWARD*
1917  * on an event device designated by its *dev_id* through the event port
1918  * specified by *port_id*.
1919  *
1920  * Provides the same functionality as rte_event_enqueue_burst(), expect that
1921  * application can use this API when the all objects in the burst contains
1922  * the enqueue operation of the type *RTE_EVENT_OP_FORWARD*. This specialized
1923  * function can provide the additional hint to the PMD and optimize if possible.
1924  *
1925  * The rte_event_enqueue_new_burst() result is undefined if the enqueue burst
1926  * has event object of operation type != RTE_EVENT_OP_FORWARD.
1927  *
1928  * @param dev_id
1929  *   The identifier of the device.
1930  * @param port_id
1931  *   The identifier of the event port.
1932  * @param ev
1933  *   Points to an array of *nb_events* objects of type *rte_event* structure
1934  *   which contain the event object enqueue operations to be processed.
1935  * @param nb_events
1936  *   The number of event objects to enqueue, typically number of
1937  *   rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
1938  *   available for this port.
1939  *
1940  * @return
1941  *   The number of event objects actually enqueued on the event device. The
1942  *   return value can be less than the value of the *nb_events* parameter when
1943  *   the event devices queue is full or if invalid parameters are specified in a
1944  *   *rte_event*. If the return value is less than *nb_events*, the remaining
1945  *   events at the end of ev[] are not consumed and the caller has to take care
1946  *   of them, and rte_errno is set accordingly. Possible errno values include:
1947  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
1948  *              ID is invalid, or an event's sched type doesn't match the
1949  *              capabilities of the destination queue.
1950  *   - ENOSPC   The event port was backpressured and unable to enqueue
1951  *              one or more events. This error code is only applicable to
1952  *              closed systems.
1953  * @see rte_event_port_attr_get(), RTE_EVENT_PORT_ATTR_ENQ_DEPTH
1954  * @see rte_event_enqueue_burst()
1955  */
1956 static inline uint16_t
1957 rte_event_enqueue_forward_burst(uint8_t dev_id, uint8_t port_id,
1958                                 const struct rte_event ev[], uint16_t nb_events)
1959 {
1960         const struct rte_event_fp_ops *fp_ops;
1961
1962         fp_ops = &rte_event_fp_ops[dev_id];
1963         return __rte_event_enqueue_burst(dev_id, port_id, ev, nb_events,
1964                                          fp_ops->enqueue_forward_burst);
1965 }
1966
1967 /**
1968  * Dequeue a burst of events objects or an event object from the event port
1969  * designated by its *event_port_id*, on an event device designated
1970  * by its *dev_id*.
1971  *
1972  * rte_event_dequeue_burst() does not dictate the specifics of scheduling
1973  * algorithm as each eventdev driver may have different criteria to schedule
1974  * an event. However, in general, from an application perspective scheduler may
1975  * use the following scheme to dispatch an event to the port.
1976  *
1977  * 1) Selection of event queue based on
1978  *   a) The list of event queues are linked to the event port.
1979  *   b) If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then event
1980  *   queue selection from list is based on event queue priority relative to
1981  *   other event queue supplied as *priority* in rte_event_queue_setup()
1982  *   c) If the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability then event
1983  *   queue selection from the list is based on event priority supplied as
1984  *   *priority* in rte_event_enqueue_burst()
1985  * 2) Selection of event
1986  *   a) The number of flows available in selected event queue.
1987  *   b) Schedule type method associated with the event
1988  *
1989  * The *nb_events* parameter is the maximum number of event objects to dequeue
1990  * which are returned in the *ev* array of *rte_event* structure.
1991  *
1992  * The rte_event_dequeue_burst() function returns the number of events objects
1993  * it actually dequeued. A return value equal to *nb_events* means that all
1994  * event objects have been dequeued.
1995  *
1996  * The number of events dequeued is the number of scheduler contexts held by
1997  * this port. These contexts are automatically released in the next
1998  * rte_event_dequeue_burst() invocation if the port supports implicit
1999  * releases, or invoking rte_event_enqueue_burst() with RTE_EVENT_OP_RELEASE
2000  * operation can be used to release the contexts early.
2001  *
2002  * Event operations RTE_EVENT_OP_FORWARD and RTE_EVENT_OP_RELEASE must only be
2003  * enqueued to the same port that their associated events were dequeued from.
2004  *
2005  * @param dev_id
2006  *   The identifier of the device.
2007  * @param port_id
2008  *   The identifier of the event port.
2009  * @param[out] ev
2010  *   Points to an array of *nb_events* objects of type *rte_event* structure
2011  *   for output to be populated with the dequeued event objects.
2012  * @param nb_events
2013  *   The maximum number of event objects to dequeue, typically number of
2014  *   rte_event_port_dequeue_depth() available for this port.
2015  *
2016  * @param timeout_ticks
2017  *   - 0 no-wait, returns immediately if there is no event.
2018  *   - >0 wait for the event, if the device is configured with
2019  *   RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT then this function will wait until
2020  *   at least one event is available or *timeout_ticks* time.
2021  *   if the device is not configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
2022  *   then this function will wait until the event available or
2023  *   *dequeue_timeout_ns* ns which was previously supplied to
2024  *   rte_event_dev_configure()
2025  *
2026  * @return
2027  * The number of event objects actually dequeued from the port. The return
2028  * value can be less than the value of the *nb_events* parameter when the
2029  * event port's queue is not full.
2030  *
2031  * @see rte_event_port_dequeue_depth()
2032  */
2033 static inline uint16_t
2034 rte_event_dequeue_burst(uint8_t dev_id, uint8_t port_id, struct rte_event ev[],
2035                         uint16_t nb_events, uint64_t timeout_ticks)
2036 {
2037         const struct rte_event_fp_ops *fp_ops;
2038         void *port;
2039
2040         fp_ops = &rte_event_fp_ops[dev_id];
2041         port = fp_ops->data[port_id];
2042 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
2043         if (dev_id >= RTE_EVENT_MAX_DEVS ||
2044             port_id >= RTE_EVENT_MAX_PORTS_PER_DEV) {
2045                 rte_errno = EINVAL;
2046                 return 0;
2047         }
2048
2049         if (port == NULL) {
2050                 rte_errno = EINVAL;
2051                 return 0;
2052         }
2053 #endif
2054         rte_eventdev_trace_deq_burst(dev_id, port_id, ev, nb_events);
2055         /*
2056          * Allow zero cost non burst mode routine invocation if application
2057          * requests nb_events as const one
2058          */
2059         if (nb_events == 1)
2060                 return (fp_ops->dequeue)(port, ev, timeout_ticks);
2061         else
2062                 return (fp_ops->dequeue_burst)(port, ev, nb_events,
2063                                                timeout_ticks);
2064 }
2065
2066 #ifdef __cplusplus
2067 }
2068 #endif
2069
2070 #endif /* _RTE_EVENTDEV_H_ */