7eb9a77393b1b8e06645e022533d835fea08e019
[dpdk.git] / lib / librte_eventdev / eventdev_pmd.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016 Cavium, Inc
3  */
4
5 #ifndef _RTE_EVENTDEV_PMD_H_
6 #define _RTE_EVENTDEV_PMD_H_
7
8 /** @file
9  * RTE Event PMD APIs
10  *
11  * @note
12  * These API are from event PMD only and user applications should not call
13  * them directly.
14  */
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #include <string.h>
21
22 #include <rte_common.h>
23 #include <rte_compat.h>
24 #include <rte_config.h>
25 #include <rte_dev.h>
26 #include <rte_log.h>
27 #include <rte_malloc.h>
28 #include <rte_mbuf.h>
29 #include <rte_mbuf_dyn.h>
30
31 #include "rte_eventdev.h"
32 #include "rte_event_timer_adapter_pmd.h"
33
34 /* Logging Macros */
35 #define RTE_EDEV_LOG_ERR(...) \
36         RTE_LOG(ERR, EVENTDEV, \
37                 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
38                         __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
39
40 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
41 #define RTE_EDEV_LOG_DEBUG(...) \
42         RTE_LOG(DEBUG, EVENTDEV, \
43                 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
44                         __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
45 #else
46 #define RTE_EDEV_LOG_DEBUG(...) (void)0
47 #endif
48
49 /* Macros to check for valid device */
50 #define RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, retval) do { \
51         if (!rte_event_pmd_is_valid_dev((dev_id))) { \
52                 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
53                 return retval; \
54         } \
55 } while (0)
56
57 #define RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, errno, retval) do { \
58         if (!rte_event_pmd_is_valid_dev((dev_id))) { \
59                 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
60                 rte_errno = errno; \
61                 return retval; \
62         } \
63 } while (0)
64
65 #define RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id) do { \
66         if (!rte_event_pmd_is_valid_dev((dev_id))) { \
67                 RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
68                 return; \
69         } \
70 } while (0)
71
72 #define RTE_EVENT_ETH_RX_ADAPTER_SW_CAP \
73                 ((RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID) | \
74                         (RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ))
75
76 #define RTE_EVENT_CRYPTO_ADAPTER_SW_CAP \
77                 RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA
78
79 /**< Ethernet Rx adapter cap to return If the packet transfers from
80  * the ethdev to eventdev use a SW service function
81  */
82
83 #define RTE_EVENTDEV_DETACHED  (0)
84 #define RTE_EVENTDEV_ATTACHED  (1)
85
86 struct rte_eth_dev;
87
88 /** Global structure used for maintaining state of allocated event devices */
89 struct rte_eventdev_global {
90         uint8_t nb_devs;        /**< Number of devices found */
91 };
92
93 extern struct rte_eventdev *rte_eventdevs;
94 /** The pool of rte_eventdev structures. */
95
96 /**
97  * Get the rte_eventdev structure device pointer for the named device.
98  *
99  * @param name
100  *   device name to select the device structure.
101  *
102  * @return
103  *   - The rte_eventdev structure pointer for the given device ID.
104  */
105 static inline struct rte_eventdev *
106 rte_event_pmd_get_named_dev(const char *name)
107 {
108         struct rte_eventdev *dev;
109         unsigned int i;
110
111         if (name == NULL)
112                 return NULL;
113
114         for (i = 0; i < RTE_EVENT_MAX_DEVS; i++) {
115                 dev = &rte_eventdevs[i];
116                 if ((dev->attached == RTE_EVENTDEV_ATTACHED) &&
117                                 (strcmp(dev->data->name, name) == 0))
118                         return dev;
119         }
120
121         return NULL;
122 }
123
124 /**
125  * Validate if the event device index is valid attached event device.
126  *
127  * @param dev_id
128  *   Event device index.
129  *
130  * @return
131  *   - If the device index is valid (1) or not (0).
132  */
133 static inline unsigned
134 rte_event_pmd_is_valid_dev(uint8_t dev_id)
135 {
136         struct rte_eventdev *dev;
137
138         if (dev_id >= RTE_EVENT_MAX_DEVS)
139                 return 0;
140
141         dev = &rte_eventdevs[dev_id];
142         if (dev->attached != RTE_EVENTDEV_ATTACHED)
143                 return 0;
144         else
145                 return 1;
146 }
147
148 /**
149  * Definitions of all functions exported by a driver through the
150  * the generic structure of type *event_dev_ops* supplied in the
151  * *rte_eventdev* structure associated with a device.
152  */
153
154 /**
155  * Get device information of a device.
156  *
157  * @param dev
158  *   Event device pointer
159  * @param dev_info
160  *   Event device information structure
161  */
162 typedef void (*eventdev_info_get_t)(struct rte_eventdev *dev,
163                 struct rte_event_dev_info *dev_info);
164
165 /**
166  * Configure a device.
167  *
168  * @param dev
169  *   Event device pointer
170  *
171  * @return
172  *   Returns 0 on success
173  */
174 typedef int (*eventdev_configure_t)(const struct rte_eventdev *dev);
175
176 /**
177  * Start a configured device.
178  *
179  * @param dev
180  *   Event device pointer
181  *
182  * @return
183  *   Returns 0 on success
184  */
185 typedef int (*eventdev_start_t)(struct rte_eventdev *dev);
186
187 /**
188  * Stop a configured device.
189  *
190  * @param dev
191  *   Event device pointer
192  */
193 typedef void (*eventdev_stop_t)(struct rte_eventdev *dev);
194
195 /**
196  * Close a configured device.
197  *
198  * @param dev
199  *   Event device pointer
200  *
201  * @return
202  * - 0 on success
203  * - (-EAGAIN) if can't close as device is busy
204  */
205 typedef int (*eventdev_close_t)(struct rte_eventdev *dev);
206
207 /**
208  * Retrieve the default event queue configuration.
209  *
210  * @param dev
211  *   Event device pointer
212  * @param queue_id
213  *   Event queue index
214  * @param[out] queue_conf
215  *   Event queue configuration structure
216  *
217  */
218 typedef void (*eventdev_queue_default_conf_get_t)(struct rte_eventdev *dev,
219                 uint8_t queue_id, struct rte_event_queue_conf *queue_conf);
220
221 /**
222  * Setup an event queue.
223  *
224  * @param dev
225  *   Event device pointer
226  * @param queue_id
227  *   Event queue index
228  * @param queue_conf
229  *   Event queue configuration structure
230  *
231  * @return
232  *   Returns 0 on success.
233  */
234 typedef int (*eventdev_queue_setup_t)(struct rte_eventdev *dev,
235                 uint8_t queue_id,
236                 const struct rte_event_queue_conf *queue_conf);
237
238 /**
239  * Release resources allocated by given event queue.
240  *
241  * @param dev
242  *   Event device pointer
243  * @param queue_id
244  *   Event queue index
245  *
246  */
247 typedef void (*eventdev_queue_release_t)(struct rte_eventdev *dev,
248                 uint8_t queue_id);
249
250 /**
251  * Retrieve the default event port configuration.
252  *
253  * @param dev
254  *   Event device pointer
255  * @param port_id
256  *   Event port index
257  * @param[out] port_conf
258  *   Event port configuration structure
259  *
260  */
261 typedef void (*eventdev_port_default_conf_get_t)(struct rte_eventdev *dev,
262                 uint8_t port_id, struct rte_event_port_conf *port_conf);
263
264 /**
265  * Setup an event port.
266  *
267  * @param dev
268  *   Event device pointer
269  * @param port_id
270  *   Event port index
271  * @param port_conf
272  *   Event port configuration structure
273  *
274  * @return
275  *   Returns 0 on success.
276  */
277 typedef int (*eventdev_port_setup_t)(struct rte_eventdev *dev,
278                 uint8_t port_id,
279                 const struct rte_event_port_conf *port_conf);
280
281 /**
282  * Release memory resources allocated by given event port.
283  *
284  * @param port
285  *   Event port pointer
286  *
287  */
288 typedef void (*eventdev_port_release_t)(void *port);
289
290 /**
291  * Link multiple source event queues to destination event port.
292  *
293  * @param dev
294  *   Event device pointer
295  * @param port
296  *   Event port pointer
297  * @param queues
298  *   Points to an array of *nb_links* event queues to be linked
299  *   to the event port.
300  * @param priorities
301  *   Points to an array of *nb_links* service priorities associated with each
302  *   event queue link to event port.
303  * @param nb_links
304  *   The number of links to establish
305  *
306  * @return
307  *   Returns 0 on success.
308  *
309  */
310 typedef int (*eventdev_port_link_t)(struct rte_eventdev *dev, void *port,
311                 const uint8_t queues[], const uint8_t priorities[],
312                 uint16_t nb_links);
313
314 /**
315  * Unlink multiple source event queues from destination event port.
316  *
317  * @param dev
318  *   Event device pointer
319  * @param port
320  *   Event port pointer
321  * @param queues
322  *   An array of *nb_unlinks* event queues to be unlinked from the event port.
323  * @param nb_unlinks
324  *   The number of unlinks to establish
325  *
326  * @return
327  *   Returns 0 on success.
328  *
329  */
330 typedef int (*eventdev_port_unlink_t)(struct rte_eventdev *dev, void *port,
331                 uint8_t queues[], uint16_t nb_unlinks);
332
333 /**
334  * Unlinks in progress. Returns number of unlinks that the PMD is currently
335  * performing, but have not yet been completed.
336  *
337  * @param dev
338  *   Event device pointer
339  *
340  * @param port
341  *   Event port pointer
342  *
343  * @return
344  *   Returns the number of in-progress unlinks. Zero is returned if none are
345  *   in progress.
346  */
347 typedef int (*eventdev_port_unlinks_in_progress_t)(struct rte_eventdev *dev,
348                 void *port);
349
350 /**
351  * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue()
352  *
353  * @param dev
354  *   Event device pointer
355  * @param ns
356  *   Wait time in nanosecond
357  * @param[out] timeout_ticks
358  *   Value for the *timeout_ticks* parameter in rte_event_dequeue() function
359  *
360  * @return
361  *   Returns 0 on success.
362  *
363  */
364 typedef int (*eventdev_dequeue_timeout_ticks_t)(struct rte_eventdev *dev,
365                 uint64_t ns, uint64_t *timeout_ticks);
366
367 /**
368  * Dump internal information
369  *
370  * @param dev
371  *   Event device pointer
372  * @param f
373  *   A pointer to a file for output
374  *
375  */
376 typedef void (*eventdev_dump_t)(struct rte_eventdev *dev, FILE *f);
377
378 /**
379  * Retrieve a set of statistics from device
380  *
381  * @param dev
382  *   Event device pointer
383  * @param mode
384  *   Level (device, port or queue)
385  * @param queue_port_id
386  *   Queue or port number depending on mode
387  * @param ids
388  *   The stat ids to retrieve
389  * @param values
390  *   The returned stat values
391  * @param n
392  *   The number of id values and entries in the values array
393  * @return
394  *   The number of stat values successfully filled into the values array
395  */
396 typedef int (*eventdev_xstats_get_t)(const struct rte_eventdev *dev,
397                 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
398                 const unsigned int ids[], uint64_t values[], unsigned int n);
399
400 /**
401  * Resets the statistic values in xstats for the device, based on mode.
402  */
403 typedef int (*eventdev_xstats_reset_t)(struct rte_eventdev *dev,
404                 enum rte_event_dev_xstats_mode mode,
405                 int16_t queue_port_id,
406                 const uint32_t ids[],
407                 uint32_t nb_ids);
408
409 /**
410  * Get names of extended stats of an event device
411  *
412  * @param dev
413  *   Event device pointer
414  * @param mode
415  *   Level (device, port or queue)
416  * @param queue_port_id
417  *   Queue or port number depending on mode
418  * @param xstats_names
419  *   Array of name values to be filled in
420  * @param ids
421  *   The stat ids to retrieve
422  * @param size
423  *   Number of values in the xstats_names array
424  * @return
425  *   When size >= the number of stats, return the number of stat values filled
426  *   into the array.
427  *   When size < the number of available stats, return the number of stats
428  *   values, and do not fill in any data into xstats_names.
429  */
430 typedef int (*eventdev_xstats_get_names_t)(const struct rte_eventdev *dev,
431                 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
432                 struct rte_event_dev_xstats_name *xstats_names,
433                 unsigned int *ids, unsigned int size);
434
435 /**
436  * Get value of one stats and optionally return its id
437  *
438  * @param dev
439  *   Event device pointer
440  * @param name
441  *   The name of the stat to retrieve
442  * @param id
443  *   Pointer to an unsigned int where we store the stat-id for future reference.
444  *   This pointer may be null if the id is not required.
445  * @return
446  *   The value of the stat, or (uint64_t)-1 if the stat is not found.
447  *   If the stat is not found, the id value will be returned as (unsigned)-1,
448  *   if id pointer is non-NULL
449  */
450 typedef uint64_t (*eventdev_xstats_get_by_name)(const struct rte_eventdev *dev,
451                 const char *name, unsigned int *id);
452
453
454 /**
455  * Retrieve the event device's ethdev Rx adapter capabilities for the
456  * specified ethernet port
457  *
458  * @param dev
459  *   Event device pointer
460  *
461  * @param eth_dev
462  *   Ethernet device pointer
463  *
464  * @param[out] caps
465  *   A pointer to memory filled with Rx event adapter capabilities.
466  *
467  * @return
468  *   - 0: Success, driver provides Rx event adapter capabilities for the
469  *      ethernet device.
470  *   - <0: Error code returned by the driver function.
471  *
472  */
473 typedef int (*eventdev_eth_rx_adapter_caps_get_t)
474                                         (const struct rte_eventdev *dev,
475                                         const struct rte_eth_dev *eth_dev,
476                                         uint32_t *caps);
477
478 struct rte_event_eth_rx_adapter_queue_conf;
479
480 /**
481  * Retrieve the event device's timer adapter capabilities, as well as the ops
482  * structure that an event timer adapter should call through to enter the
483  * driver
484  *
485  * @param dev
486  *   Event device pointer
487  *
488  * @param flags
489  *   Flags that can be used to determine how to select an event timer
490  *   adapter ops structure
491  *
492  * @param[out] caps
493  *   A pointer to memory filled with Rx event adapter capabilities.
494  *
495  * @param[out] ops
496  *   A pointer to the ops pointer to set with the address of the desired ops
497  *   structure
498  *
499  * @return
500  *   - 0: Success, driver provides Rx event adapter capabilities for the
501  *      ethernet device.
502  *   - <0: Error code returned by the driver function.
503  *
504  */
505 typedef int (*eventdev_timer_adapter_caps_get_t)(
506                                 const struct rte_eventdev *dev,
507                                 uint64_t flags,
508                                 uint32_t *caps,
509                                 const struct rte_event_timer_adapter_ops **ops);
510
511 /**
512  * Add ethernet Rx queues to event device. This callback is invoked if
513  * the caps returned from rte_eventdev_eth_rx_adapter_caps_get(, eth_port_id)
514  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
515  *
516  * @param dev
517  *   Event device pointer
518  *
519  * @param eth_dev
520  *   Ethernet device pointer
521  *
522  * @param rx_queue_id
523  *   Ethernet device receive queue index
524  *
525  * @param queue_conf
526  *  Additional configuration structure
527
528  * @return
529  *   - 0: Success, ethernet receive queue added successfully.
530  *   - <0: Error code returned by the driver function.
531  *
532  */
533 typedef int (*eventdev_eth_rx_adapter_queue_add_t)(
534                 const struct rte_eventdev *dev,
535                 const struct rte_eth_dev *eth_dev,
536                 int32_t rx_queue_id,
537                 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
538
539 /**
540  * Delete ethernet Rx queues from event device. This callback is invoked if
541  * the caps returned from eventdev_eth_rx_adapter_caps_get(, eth_port_id)
542  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
543  *
544  * @param dev
545  *   Event device pointer
546  *
547  * @param eth_dev
548  *   Ethernet device pointer
549  *
550  * @param rx_queue_id
551  *   Ethernet device receive queue index
552  *
553  * @return
554  *   - 0: Success, ethernet receive queue deleted successfully.
555  *   - <0: Error code returned by the driver function.
556  *
557  */
558 typedef int (*eventdev_eth_rx_adapter_queue_del_t)
559                                         (const struct rte_eventdev *dev,
560                                         const struct rte_eth_dev *eth_dev,
561                                         int32_t rx_queue_id);
562
563 /**
564  * Start ethernet Rx adapter. This callback is invoked if
565  * the caps returned from eventdev_eth_rx_adapter_caps_get(.., eth_port_id)
566  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
567  * from eth_port_id have been added to the event device.
568  *
569  * @param dev
570  *   Event device pointer
571  *
572  * @param eth_dev
573  *   Ethernet device pointer
574  *
575  * @return
576  *   - 0: Success, ethernet Rx adapter started successfully.
577  *   - <0: Error code returned by the driver function.
578  */
579 typedef int (*eventdev_eth_rx_adapter_start_t)
580                                         (const struct rte_eventdev *dev,
581                                         const struct rte_eth_dev *eth_dev);
582
583 /**
584  * Stop ethernet Rx adapter. This callback is invoked if
585  * the caps returned from eventdev_eth_rx_adapter_caps_get(..,eth_port_id)
586  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
587  * from eth_port_id have been added to the event device.
588  *
589  * @param dev
590  *   Event device pointer
591  *
592  * @param eth_dev
593  *   Ethernet device pointer
594  *
595  * @return
596  *   - 0: Success, ethernet Rx adapter stopped successfully.
597  *   - <0: Error code returned by the driver function.
598  */
599 typedef int (*eventdev_eth_rx_adapter_stop_t)
600                                         (const struct rte_eventdev *dev,
601                                         const struct rte_eth_dev *eth_dev);
602
603 struct rte_event_eth_rx_adapter_stats;
604
605 /**
606  * Retrieve ethernet Rx adapter statistics.
607  *
608  * @param dev
609  *   Event device pointer
610  *
611  * @param eth_dev
612  *   Ethernet device pointer
613  *
614  * @param[out] stats
615  *   Pointer to stats structure
616  *
617  * @return
618  *   Return 0 on success.
619  */
620
621 typedef int (*eventdev_eth_rx_adapter_stats_get)
622                         (const struct rte_eventdev *dev,
623                         const struct rte_eth_dev *eth_dev,
624                         struct rte_event_eth_rx_adapter_stats *stats);
625 /**
626  * Reset ethernet Rx adapter statistics.
627  *
628  * @param dev
629  *   Event device pointer
630  *
631  * @param eth_dev
632  *   Ethernet device pointer
633  *
634  * @return
635  *   Return 0 on success.
636  */
637 typedef int (*eventdev_eth_rx_adapter_stats_reset)
638                         (const struct rte_eventdev *dev,
639                         const struct rte_eth_dev *eth_dev);
640 /**
641  * Start eventdev selftest.
642  *
643  * @return
644  *   Return 0 on success.
645  */
646 typedef int (*eventdev_selftest)(void);
647
648 typedef uint32_t rte_event_pmd_selftest_seqn_t;
649 extern int rte_event_pmd_selftest_seqn_dynfield_offset;
650
651 /**
652  * Read test sequence number from mbuf.
653  *
654  * @param mbuf Structure to read from.
655  * @return pointer to test sequence number.
656  */
657 __rte_internal
658 static inline rte_event_pmd_selftest_seqn_t *
659 rte_event_pmd_selftest_seqn(struct rte_mbuf *mbuf)
660 {
661         return RTE_MBUF_DYNFIELD(mbuf,
662                 rte_event_pmd_selftest_seqn_dynfield_offset,
663                 rte_event_pmd_selftest_seqn_t *);
664 }
665
666 struct rte_cryptodev;
667
668 /**
669  * This API may change without prior notice
670  *
671  * Retrieve the event device's crypto adapter capabilities for the
672  * specified cryptodev
673  *
674  * @param dev
675  *   Event device pointer
676  *
677  * @param cdev
678  *   cryptodev pointer
679  *
680  * @param[out] caps
681  *   A pointer to memory filled with event adapter capabilities.
682  *   It is expected to be pre-allocated & initialized by caller.
683  *
684  * @return
685  *   - 0: Success, driver provides event adapter capabilities for the
686  *      cryptodev.
687  *   - <0: Error code returned by the driver function.
688  *
689  */
690 typedef int (*eventdev_crypto_adapter_caps_get_t)
691                                         (const struct rte_eventdev *dev,
692                                          const struct rte_cryptodev *cdev,
693                                          uint32_t *caps);
694
695 /**
696  * This API may change without prior notice
697  *
698  * Add crypto queue pair to event device. This callback is invoked if
699  * the caps returned from rte_event_crypto_adapter_caps_get(, cdev_id)
700  * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set.
701  *
702  * @param dev
703  *   Event device pointer
704  *
705  * @param cdev
706  *   cryptodev pointer
707  *
708  * @param queue_pair_id
709  *   cryptodev queue pair identifier.
710  *
711  * @param event
712  *  Event information required for binding cryptodev queue pair to event queue.
713  *  This structure will have a valid value for only those HW PMDs supporting
714  *  @see RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND capability.
715  *
716  * @return
717  *   - 0: Success, cryptodev queue pair added successfully.
718  *   - <0: Error code returned by the driver function.
719  *
720  */
721 typedef int (*eventdev_crypto_adapter_queue_pair_add_t)
722                         (const struct rte_eventdev *dev,
723                          const struct rte_cryptodev *cdev,
724                          int32_t queue_pair_id,
725                          const struct rte_event *event);
726
727
728 /**
729  * This API may change without prior notice
730  *
731  * Delete crypto queue pair to event device. This callback is invoked if
732  * the caps returned from rte_event_crypto_adapter_caps_get(, cdev_id)
733  * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set.
734  *
735  * @param dev
736  *   Event device pointer
737  *
738  * @param cdev
739  *   cryptodev pointer
740  *
741  * @param queue_pair_id
742  *   cryptodev queue pair identifier.
743  *
744  * @return
745  *   - 0: Success, cryptodev queue pair deleted successfully.
746  *   - <0: Error code returned by the driver function.
747  *
748  */
749 typedef int (*eventdev_crypto_adapter_queue_pair_del_t)
750                                         (const struct rte_eventdev *dev,
751                                          const struct rte_cryptodev *cdev,
752                                          int32_t queue_pair_id);
753
754 /**
755  * Start crypto adapter. This callback is invoked if
756  * the caps returned from rte_event_crypto_adapter_caps_get(.., cdev_id)
757  * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set and queue pairs
758  * from cdev_id have been added to the event device.
759  *
760  * @param dev
761  *   Event device pointer
762  *
763  * @param cdev
764  *   Crypto device pointer
765  *
766  * @return
767  *   - 0: Success, crypto adapter started successfully.
768  *   - <0: Error code returned by the driver function.
769  */
770 typedef int (*eventdev_crypto_adapter_start_t)
771                                         (const struct rte_eventdev *dev,
772                                          const struct rte_cryptodev *cdev);
773
774 /**
775  * Stop crypto adapter. This callback is invoked if
776  * the caps returned from rte_event_crypto_adapter_caps_get(.., cdev_id)
777  * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set and queue pairs
778  * from cdev_id have been added to the event device.
779  *
780  * @param dev
781  *   Event device pointer
782  *
783  * @param cdev
784  *   Crypto device pointer
785  *
786  * @return
787  *   - 0: Success, crypto adapter stopped successfully.
788  *   - <0: Error code returned by the driver function.
789  */
790 typedef int (*eventdev_crypto_adapter_stop_t)
791                                         (const struct rte_eventdev *dev,
792                                          const struct rte_cryptodev *cdev);
793
794 struct rte_event_crypto_adapter_stats;
795
796 /**
797  * Retrieve crypto adapter statistics.
798  *
799  * @param dev
800  *   Event device pointer
801  *
802  * @param cdev
803  *   Crypto device pointer
804  *
805  * @param[out] stats
806  *   Pointer to stats structure
807  *
808  * @return
809  *   Return 0 on success.
810  */
811
812 typedef int (*eventdev_crypto_adapter_stats_get)
813                         (const struct rte_eventdev *dev,
814                          const struct rte_cryptodev *cdev,
815                          struct rte_event_crypto_adapter_stats *stats);
816
817 /**
818  * Reset crypto adapter statistics.
819  *
820  * @param dev
821  *   Event device pointer
822  *
823  * @param cdev
824  *   Crypto device pointer
825  *
826  * @return
827  *   Return 0 on success.
828  */
829
830 typedef int (*eventdev_crypto_adapter_stats_reset)
831                         (const struct rte_eventdev *dev,
832                          const struct rte_cryptodev *cdev);
833
834 /**
835  * Retrieve the event device's eth Tx adapter capabilities.
836  *
837  * @param dev
838  *   Event device pointer
839  *
840  * @param eth_dev
841  *   Ethernet device pointer
842  *
843  * @param[out] caps
844  *   A pointer to memory filled with eth Tx adapter capabilities.
845  *
846  * @return
847  *   - 0: Success, driver provides eth Tx adapter capabilities
848  *   - <0: Error code returned by the driver function.
849  *
850  */
851 typedef int (*eventdev_eth_tx_adapter_caps_get_t)
852                                         (const struct rte_eventdev *dev,
853                                         const struct rte_eth_dev *eth_dev,
854                                         uint32_t *caps);
855
856 /**
857  * Create adapter callback.
858  *
859  * @param id
860  *   Adapter identifier
861  *
862  * @param dev
863  *   Event device pointer
864  *
865  * @return
866  *   - 0: Success.
867  *   - <0: Error code on failure.
868  */
869 typedef int (*eventdev_eth_tx_adapter_create_t)(uint8_t id,
870                                         const struct rte_eventdev *dev);
871
872 /**
873  * Free adapter callback.
874  *
875  * @param id
876  *   Adapter identifier
877  *
878  * @param dev
879  *   Event device pointer
880  *
881  * @return
882  *   - 0: Success.
883  *   - <0: Error code on failure.
884  */
885 typedef int (*eventdev_eth_tx_adapter_free_t)(uint8_t id,
886                                         const struct rte_eventdev *dev);
887
888 /**
889  * Add a Tx queue to the adapter.
890  * A queue value of -1 is used to indicate all
891  * queues within the device.
892  *
893  * @param id
894  *   Adapter identifier
895  *
896  * @param dev
897  *   Event device pointer
898  *
899  * @param eth_dev
900  *   Ethernet device pointer
901  *
902  * @param tx_queue_id
903  *   Transmit queue index
904  *
905  * @return
906  *   - 0: Success.
907  *   - <0: Error code on failure.
908  */
909 typedef int (*eventdev_eth_tx_adapter_queue_add_t)(
910                                         uint8_t id,
911                                         const struct rte_eventdev *dev,
912                                         const struct rte_eth_dev *eth_dev,
913                                         int32_t tx_queue_id);
914
915 /**
916  * Delete a Tx queue from the adapter.
917  * A queue value of -1 is used to indicate all
918  * queues within the device, that have been added to this
919  * adapter.
920  *
921  * @param id
922  *   Adapter identifier
923  *
924  * @param dev
925  *   Event device pointer
926  *
927  * @param eth_dev
928  *   Ethernet device pointer
929  *
930  * @param tx_queue_id
931  *   Transmit queue index
932  *
933  * @return
934  *  - 0: Success, Queues deleted successfully.
935  *  - <0: Error code on failure.
936  */
937 typedef int (*eventdev_eth_tx_adapter_queue_del_t)(
938                                         uint8_t id,
939                                         const struct rte_eventdev *dev,
940                                         const struct rte_eth_dev *eth_dev,
941                                         int32_t tx_queue_id);
942
943 /**
944  * Start the adapter.
945  *
946  * @param id
947  *   Adapter identifier
948  *
949  * @param dev
950  *   Event device pointer
951  *
952  * @return
953  *  - 0: Success, Adapter started correctly.
954  *  - <0: Error code on failure.
955  */
956 typedef int (*eventdev_eth_tx_adapter_start_t)(uint8_t id,
957                                         const struct rte_eventdev *dev);
958
959 /**
960  * Stop the adapter.
961  *
962  * @param id
963  *  Adapter identifier
964  *
965  * @param dev
966  *   Event device pointer
967  *
968  * @return
969  *  - 0: Success.
970  *  - <0: Error code on failure.
971  */
972 typedef int (*eventdev_eth_tx_adapter_stop_t)(uint8_t id,
973                                         const struct rte_eventdev *dev);
974
975 struct rte_event_eth_tx_adapter_stats;
976
977 /**
978  * Retrieve statistics for an adapter
979  *
980  * @param id
981  *  Adapter identifier
982  *
983  * @param dev
984  *   Event device pointer
985  *
986  * @param [out] stats
987  *  A pointer to structure used to retrieve statistics for an adapter
988  *
989  * @return
990  *  - 0: Success, statistics retrieved successfully.
991  *  - <0: Error code on failure.
992  */
993 typedef int (*eventdev_eth_tx_adapter_stats_get_t)(
994                                 uint8_t id,
995                                 const struct rte_eventdev *dev,
996                                 struct rte_event_eth_tx_adapter_stats *stats);
997
998 /**
999  * Reset statistics for an adapter
1000  *
1001  * @param id
1002  *  Adapter identifier
1003  *
1004  * @param dev
1005  *   Event device pointer
1006  *
1007  * @return
1008  *  - 0: Success, statistics retrieved successfully.
1009  *  - <0: Error code on failure.
1010  */
1011 typedef int (*eventdev_eth_tx_adapter_stats_reset_t)(uint8_t id,
1012                                         const struct rte_eventdev *dev);
1013
1014 /** Event device operations function pointer table */
1015 struct rte_eventdev_ops {
1016         eventdev_info_get_t dev_infos_get;      /**< Get device info. */
1017         eventdev_configure_t dev_configure;     /**< Configure device. */
1018         eventdev_start_t dev_start;             /**< Start device. */
1019         eventdev_stop_t dev_stop;               /**< Stop device. */
1020         eventdev_close_t dev_close;             /**< Close device. */
1021
1022         eventdev_queue_default_conf_get_t queue_def_conf;
1023         /**< Get default queue configuration. */
1024         eventdev_queue_setup_t queue_setup;
1025         /**< Set up an event queue. */
1026         eventdev_queue_release_t queue_release;
1027         /**< Release an event queue. */
1028
1029         eventdev_port_default_conf_get_t port_def_conf;
1030         /**< Get default port configuration. */
1031         eventdev_port_setup_t port_setup;
1032         /**< Set up an event port. */
1033         eventdev_port_release_t port_release;
1034         /**< Release an event port. */
1035
1036         eventdev_port_link_t port_link;
1037         /**< Link event queues to an event port. */
1038         eventdev_port_unlink_t port_unlink;
1039         /**< Unlink event queues from an event port. */
1040         eventdev_port_unlinks_in_progress_t port_unlinks_in_progress;
1041         /**< Unlinks in progress on an event port. */
1042         eventdev_dequeue_timeout_ticks_t timeout_ticks;
1043         /**< Converts ns to *timeout_ticks* value for rte_event_dequeue() */
1044         eventdev_dump_t dump;
1045         /* Dump internal information */
1046
1047         eventdev_xstats_get_t xstats_get;
1048         /**< Get extended device statistics. */
1049         eventdev_xstats_get_names_t xstats_get_names;
1050         /**< Get names of extended stats. */
1051         eventdev_xstats_get_by_name xstats_get_by_name;
1052         /**< Get one value by name. */
1053         eventdev_xstats_reset_t xstats_reset;
1054         /**< Reset the statistics values in xstats. */
1055
1056         eventdev_eth_rx_adapter_caps_get_t eth_rx_adapter_caps_get;
1057         /**< Get ethernet Rx adapter capabilities */
1058         eventdev_eth_rx_adapter_queue_add_t eth_rx_adapter_queue_add;
1059         /**< Add Rx queues to ethernet Rx adapter */
1060         eventdev_eth_rx_adapter_queue_del_t eth_rx_adapter_queue_del;
1061         /**< Delete Rx queues from ethernet Rx adapter */
1062         eventdev_eth_rx_adapter_start_t eth_rx_adapter_start;
1063         /**< Start ethernet Rx adapter */
1064         eventdev_eth_rx_adapter_stop_t eth_rx_adapter_stop;
1065         /**< Stop ethernet Rx adapter */
1066         eventdev_eth_rx_adapter_stats_get eth_rx_adapter_stats_get;
1067         /**< Get ethernet Rx stats */
1068         eventdev_eth_rx_adapter_stats_reset eth_rx_adapter_stats_reset;
1069         /**< Reset ethernet Rx stats */
1070
1071         eventdev_timer_adapter_caps_get_t timer_adapter_caps_get;
1072         /**< Get timer adapter capabilities */
1073
1074         eventdev_crypto_adapter_caps_get_t crypto_adapter_caps_get;
1075         /**< Get crypto adapter capabilities */
1076         eventdev_crypto_adapter_queue_pair_add_t crypto_adapter_queue_pair_add;
1077         /**< Add queue pair to crypto adapter */
1078         eventdev_crypto_adapter_queue_pair_del_t crypto_adapter_queue_pair_del;
1079         /**< Delete queue pair from crypto adapter */
1080         eventdev_crypto_adapter_start_t crypto_adapter_start;
1081         /**< Start crypto adapter */
1082         eventdev_crypto_adapter_stop_t crypto_adapter_stop;
1083         /**< Stop crypto adapter */
1084         eventdev_crypto_adapter_stats_get crypto_adapter_stats_get;
1085         /**< Get crypto stats */
1086         eventdev_crypto_adapter_stats_reset crypto_adapter_stats_reset;
1087         /**< Reset crypto stats */
1088
1089         eventdev_eth_tx_adapter_caps_get_t eth_tx_adapter_caps_get;
1090         /**< Get ethernet Tx adapter capabilities */
1091
1092         eventdev_eth_tx_adapter_create_t eth_tx_adapter_create;
1093         /**< Create adapter callback */
1094         eventdev_eth_tx_adapter_free_t eth_tx_adapter_free;
1095         /**< Free adapter callback */
1096         eventdev_eth_tx_adapter_queue_add_t eth_tx_adapter_queue_add;
1097         /**< Add Tx queues to the eth Tx adapter */
1098         eventdev_eth_tx_adapter_queue_del_t eth_tx_adapter_queue_del;
1099         /**< Delete Tx queues from the eth Tx adapter */
1100         eventdev_eth_tx_adapter_start_t eth_tx_adapter_start;
1101         /**< Start eth Tx adapter */
1102         eventdev_eth_tx_adapter_stop_t eth_tx_adapter_stop;
1103         /**< Stop eth Tx adapter */
1104         eventdev_eth_tx_adapter_stats_get_t eth_tx_adapter_stats_get;
1105         /**< Get eth Tx adapter statistics */
1106         eventdev_eth_tx_adapter_stats_reset_t eth_tx_adapter_stats_reset;
1107         /**< Reset eth Tx adapter statistics */
1108
1109         eventdev_selftest dev_selftest;
1110         /**< Start eventdev Selftest */
1111
1112         eventdev_stop_flush_t dev_stop_flush;
1113         /**< User-provided event flush function */
1114 };
1115
1116 /**
1117  * Allocates a new eventdev slot for an event device and returns the pointer
1118  * to that slot for the driver to use.
1119  *
1120  * @param name
1121  *   Unique identifier name for each device
1122  * @param socket_id
1123  *   Socket to allocate resources on.
1124  * @return
1125  *   - Slot in the rte_dev_devices array for a new device;
1126  */
1127 struct rte_eventdev *
1128 rte_event_pmd_allocate(const char *name, int socket_id);
1129
1130 /**
1131  * Release the specified eventdev device.
1132  *
1133  * @param eventdev
1134  * The *eventdev* pointer is the address of the *rte_eventdev* structure.
1135  * @return
1136  *   - 0 on success, negative on error
1137  */
1138 int
1139 rte_event_pmd_release(struct rte_eventdev *eventdev);
1140
1141 #ifdef __cplusplus
1142 }
1143 #endif
1144
1145 #endif /* _RTE_EVENTDEV_PMD_H_ */