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