8879e43feb71d1591c6e8dd70570262bde49c45c
[dpdk.git] / lib / 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 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 /** @file
13  * RTE Event PMD APIs
14  *
15  * @note
16  * These API are from event PMD only and user applications should not call
17  * them directly.
18  */
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 "event_timer_adapter_pmd.h"
32 #include "rte_eventdev.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          (RTE_EVENT_ETH_RX_ADAPTER_CAP_EVENT_VECTOR))
76
77 #define RTE_EVENT_CRYPTO_ADAPTER_SW_CAP \
78                 RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA
79
80 /**< Ethernet Rx adapter cap to return If the packet transfers from
81  * the ethdev to eventdev use a SW service function
82  */
83
84 #define RTE_EVENTDEV_DETACHED  (0)
85 #define RTE_EVENTDEV_ATTACHED  (1)
86
87 #define RTE_EVENTDEV_NAME_MAX_LEN (64)
88 /**< @internal Max length of name of event PMD */
89
90 struct rte_eth_dev;
91
92 /** Global structure used for maintaining state of allocated event devices */
93 struct rte_eventdev_global {
94         uint8_t nb_devs;        /**< Number of devices found */
95 };
96
97 /**
98  * @internal
99  * The data part, with no function pointers, associated with each device.
100  *
101  * This structure is safe to place in shared memory to be common among
102  * different processes in a multi-process configuration.
103  */
104 struct rte_eventdev_data {
105         int socket_id;
106         /**< Socket ID where memory is allocated */
107         uint8_t dev_id;
108         /**< Device ID for this instance */
109         uint8_t nb_queues;
110         /**< Number of event queues. */
111         uint8_t nb_ports;
112         /**< Number of event ports. */
113         void *ports[RTE_EVENT_MAX_PORTS_PER_DEV];
114         /**< Array of pointers to ports. */
115         struct rte_event_port_conf ports_cfg[RTE_EVENT_MAX_PORTS_PER_DEV];
116         /**< Array of port configuration structures. */
117         struct rte_event_queue_conf queues_cfg[RTE_EVENT_MAX_QUEUES_PER_DEV];
118         /**< Array of queue configuration structures. */
119         uint16_t links_map[RTE_EVENT_MAX_PORTS_PER_DEV *
120                            RTE_EVENT_MAX_QUEUES_PER_DEV];
121         /**< Memory to store queues to port connections. */
122         void *dev_private;
123         /**< PMD-specific private data */
124         uint32_t event_dev_cap;
125         /**< Event device capabilities(RTE_EVENT_DEV_CAP_)*/
126         struct rte_event_dev_config dev_conf;
127         /**< Configuration applied to device. */
128         uint8_t service_inited;
129         /* Service initialization state */
130         uint32_t service_id;
131         /* Service ID*/
132         void *dev_stop_flush_arg;
133         /**< User-provided argument for event flush function */
134
135         RTE_STD_C11
136         uint8_t dev_started : 1;
137         /**< Device state: STARTED(1)/STOPPED(0) */
138
139         char name[RTE_EVENTDEV_NAME_MAX_LEN];
140         /**< Unique identifier name */
141
142         uint64_t reserved_64s[4]; /**< Reserved for future fields */
143         void *reserved_ptrs[4];   /**< Reserved for future fields */
144 } __rte_cache_aligned;
145
146 /** @internal The data structure associated with each event device. */
147 struct rte_eventdev {
148         struct rte_eventdev_data *data;
149         /**< Pointer to device data */
150         struct eventdev_ops *dev_ops;
151         /**< Functions exported by PMD */
152         struct rte_device *dev;
153         /**< Device info. supplied by probing */
154
155         RTE_STD_C11
156         uint8_t attached : 1;
157         /**< Flag indicating the device is attached */
158
159         event_enqueue_t enqueue;
160         /**< Pointer to PMD enqueue function. */
161         event_enqueue_burst_t enqueue_burst;
162         /**< Pointer to PMD enqueue burst function. */
163         event_enqueue_burst_t enqueue_new_burst;
164         /**< Pointer to PMD enqueue burst function(op new variant) */
165         event_enqueue_burst_t enqueue_forward_burst;
166         /**< Pointer to PMD enqueue burst function(op forward variant) */
167         event_dequeue_t dequeue;
168         /**< Pointer to PMD dequeue function. */
169         event_dequeue_burst_t dequeue_burst;
170         /**< Pointer to PMD dequeue burst function. */
171         event_maintain_t maintain;
172         /**< Pointer to PMD port maintenance function. */
173         event_tx_adapter_enqueue_t txa_enqueue_same_dest;
174         /**< Pointer to PMD eth Tx adapter burst enqueue function with
175          * events destined to same Eth port & Tx queue.
176          */
177         event_tx_adapter_enqueue_t txa_enqueue;
178         /**< Pointer to PMD eth Tx adapter enqueue function. */
179         event_crypto_adapter_enqueue_t ca_enqueue;
180
181         uint64_t reserved_64s[4]; /**< Reserved for future fields */
182         void *reserved_ptrs[3];   /**< Reserved for future fields */
183 } __rte_cache_aligned;
184
185 extern struct rte_eventdev *rte_eventdevs;
186 /** @internal The pool of rte_eventdev structures. */
187
188 /**
189  * Get the rte_eventdev structure device pointer for the named device.
190  *
191  * @param name
192  *   device name to select the device structure.
193  *
194  * @return
195  *   - The rte_eventdev structure pointer for the given device ID.
196  */
197 __rte_internal
198 static inline struct rte_eventdev *
199 rte_event_pmd_get_named_dev(const char *name)
200 {
201         struct rte_eventdev *dev;
202         unsigned int i;
203
204         if (name == NULL)
205                 return NULL;
206
207         for (i = 0; i < RTE_EVENT_MAX_DEVS; i++) {
208                 dev = &rte_eventdevs[i];
209                 if ((dev->attached == RTE_EVENTDEV_ATTACHED) &&
210                                 (strcmp(dev->data->name, name) == 0))
211                         return dev;
212         }
213
214         return NULL;
215 }
216
217 /**
218  * Validate if the event device index is valid attached event device.
219  *
220  * @param dev_id
221  *   Event device index.
222  *
223  * @return
224  *   - If the device index is valid (1) or not (0).
225  */
226 __rte_internal
227 static inline unsigned
228 rte_event_pmd_is_valid_dev(uint8_t dev_id)
229 {
230         struct rte_eventdev *dev;
231
232         if (dev_id >= RTE_EVENT_MAX_DEVS)
233                 return 0;
234
235         dev = &rte_eventdevs[dev_id];
236         if (dev->attached != RTE_EVENTDEV_ATTACHED)
237                 return 0;
238         else
239                 return 1;
240 }
241
242 /**
243  * Definitions of all functions exported by a driver through the
244  * generic structure of type *event_dev_ops* supplied in the
245  * *rte_eventdev* structure associated with a device.
246  */
247
248 /**
249  * Get device information of a device.
250  *
251  * @param dev
252  *   Event device pointer
253  * @param dev_info
254  *   Event device information structure
255  */
256 typedef void (*eventdev_info_get_t)(struct rte_eventdev *dev,
257                 struct rte_event_dev_info *dev_info);
258
259 /**
260  * Configure a device.
261  *
262  * @param dev
263  *   Event device pointer
264  *
265  * @return
266  *   Returns 0 on success
267  */
268 typedef int (*eventdev_configure_t)(const struct rte_eventdev *dev);
269
270 /**
271  * Start a configured device.
272  *
273  * @param dev
274  *   Event device pointer
275  *
276  * @return
277  *   Returns 0 on success
278  */
279 typedef int (*eventdev_start_t)(struct rte_eventdev *dev);
280
281 /**
282  * Stop a configured device.
283  *
284  * @param dev
285  *   Event device pointer
286  */
287 typedef void (*eventdev_stop_t)(struct rte_eventdev *dev);
288
289 /**
290  * Close a configured device.
291  *
292  * @param dev
293  *   Event device pointer
294  *
295  * @return
296  * - 0 on success
297  * - (-EAGAIN) if can't close as device is busy
298  */
299 typedef int (*eventdev_close_t)(struct rte_eventdev *dev);
300
301 /**
302  * Retrieve the default event queue configuration.
303  *
304  * @param dev
305  *   Event device pointer
306  * @param queue_id
307  *   Event queue index
308  * @param[out] queue_conf
309  *   Event queue configuration structure
310  *
311  */
312 typedef void (*eventdev_queue_default_conf_get_t)(struct rte_eventdev *dev,
313                 uint8_t queue_id, struct rte_event_queue_conf *queue_conf);
314
315 /**
316  * Setup an event queue.
317  *
318  * @param dev
319  *   Event device pointer
320  * @param queue_id
321  *   Event queue index
322  * @param queue_conf
323  *   Event queue configuration structure
324  *
325  * @return
326  *   Returns 0 on success.
327  */
328 typedef int (*eventdev_queue_setup_t)(struct rte_eventdev *dev,
329                 uint8_t queue_id,
330                 const struct rte_event_queue_conf *queue_conf);
331
332 /**
333  * Release resources allocated by given event queue.
334  *
335  * @param dev
336  *   Event device pointer
337  * @param queue_id
338  *   Event queue index
339  *
340  */
341 typedef void (*eventdev_queue_release_t)(struct rte_eventdev *dev,
342                 uint8_t queue_id);
343
344 /**
345  * Set an event queue attribute at runtime.
346  *
347  * @param dev
348  *   Event device pointer
349  * @param queue_id
350  *   Event queue index
351  * @param attr_id
352  *   Event queue attribute id
353  * @param attr_value
354  *   Event queue attribute value
355  *
356  * @return
357  *  - 0: Success.
358  *  - <0: Error code on failure.
359  */
360 typedef int (*eventdev_queue_attr_set_t)(struct rte_eventdev *dev,
361                                          uint8_t queue_id, uint32_t attr_id,
362                                          uint64_t attr_value);
363
364 /**
365  * Retrieve the default event port configuration.
366  *
367  * @param dev
368  *   Event device pointer
369  * @param port_id
370  *   Event port index
371  * @param[out] port_conf
372  *   Event port configuration structure
373  *
374  */
375 typedef void (*eventdev_port_default_conf_get_t)(struct rte_eventdev *dev,
376                 uint8_t port_id, struct rte_event_port_conf *port_conf);
377
378 /**
379  * Setup an event port.
380  *
381  * @param dev
382  *   Event device pointer
383  * @param port_id
384  *   Event port index
385  * @param port_conf
386  *   Event port configuration structure
387  *
388  * @return
389  *   Returns 0 on success.
390  */
391 typedef int (*eventdev_port_setup_t)(struct rte_eventdev *dev,
392                 uint8_t port_id,
393                 const struct rte_event_port_conf *port_conf);
394
395 /**
396  * Release memory resources allocated by given event port.
397  *
398  * @param port
399  *   Event port pointer
400  *
401  */
402 typedef void (*eventdev_port_release_t)(void *port);
403
404 /**
405  * Quiesce any core specific resources consumed by the event port
406  *
407  * @param dev
408  *   Event device pointer.
409  * @param port
410  *   Event port pointer.
411  * @param flush_cb
412  *   User-provided event flush function.
413  * @param args
414  *   Arguments to be passed to the user-provided event flush function.
415  *
416  */
417 typedef void (*eventdev_port_quiesce_t)(struct rte_eventdev *dev, void *port,
418                                         rte_eventdev_port_flush_t flush_cb,
419                                         void *args);
420
421 /**
422  * Link multiple source event queues to destination event port.
423  *
424  * @param dev
425  *   Event device pointer
426  * @param port
427  *   Event port pointer
428  * @param queues
429  *   Points to an array of *nb_links* event queues to be linked
430  *   to the event port.
431  * @param priorities
432  *   Points to an array of *nb_links* service priorities associated with each
433  *   event queue link to event port.
434  * @param nb_links
435  *   The number of links to establish
436  *
437  * @return
438  *   Returns 0 on success.
439  *
440  */
441 typedef int (*eventdev_port_link_t)(struct rte_eventdev *dev, void *port,
442                 const uint8_t queues[], const uint8_t priorities[],
443                 uint16_t nb_links);
444
445 /**
446  * Unlink multiple source event queues from destination event port.
447  *
448  * @param dev
449  *   Event device pointer
450  * @param port
451  *   Event port pointer
452  * @param queues
453  *   An array of *nb_unlinks* event queues to be unlinked from the event port.
454  * @param nb_unlinks
455  *   The number of unlinks to establish
456  *
457  * @return
458  *   Returns 0 on success.
459  *
460  */
461 typedef int (*eventdev_port_unlink_t)(struct rte_eventdev *dev, void *port,
462                 uint8_t queues[], uint16_t nb_unlinks);
463
464 /**
465  * Unlinks in progress. Returns number of unlinks that the PMD is currently
466  * performing, but have not yet been completed.
467  *
468  * @param dev
469  *   Event device pointer
470  *
471  * @param port
472  *   Event port pointer
473  *
474  * @return
475  *   Returns the number of in-progress unlinks. Zero is returned if none are
476  *   in progress.
477  */
478 typedef int (*eventdev_port_unlinks_in_progress_t)(struct rte_eventdev *dev,
479                 void *port);
480
481 /**
482  * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue()
483  *
484  * @param dev
485  *   Event device pointer
486  * @param ns
487  *   Wait time in nanosecond
488  * @param[out] timeout_ticks
489  *   Value for the *timeout_ticks* parameter in rte_event_dequeue() function
490  *
491  * @return
492  *   Returns 0 on success.
493  *
494  */
495 typedef int (*eventdev_dequeue_timeout_ticks_t)(struct rte_eventdev *dev,
496                 uint64_t ns, uint64_t *timeout_ticks);
497
498 /**
499  * Dump internal information
500  *
501  * @param dev
502  *   Event device pointer
503  * @param f
504  *   A pointer to a file for output
505  *
506  */
507 typedef void (*eventdev_dump_t)(struct rte_eventdev *dev, FILE *f);
508
509 /**
510  * Retrieve a set of statistics from device
511  *
512  * @param dev
513  *   Event device pointer
514  * @param mode
515  *   Level (device, port or queue)
516  * @param queue_port_id
517  *   Queue or port number depending on mode
518  * @param ids
519  *   The stat ids to retrieve
520  * @param values
521  *   The returned stat values
522  * @param n
523  *   The number of id values and entries in the values array
524  * @return
525  *   The number of stat values successfully filled into the values array
526  */
527 typedef int (*eventdev_xstats_get_t)(const struct rte_eventdev *dev,
528                 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
529                 const unsigned int ids[], uint64_t values[], unsigned int n);
530
531 /**
532  * Resets the statistic values in xstats for the device, based on mode.
533  */
534 typedef int (*eventdev_xstats_reset_t)(struct rte_eventdev *dev,
535                 enum rte_event_dev_xstats_mode mode,
536                 int16_t queue_port_id,
537                 const uint32_t ids[],
538                 uint32_t nb_ids);
539
540 /**
541  * Get names of extended stats of an event device
542  *
543  * @param dev
544  *   Event device pointer
545  * @param mode
546  *   Level (device, port or queue)
547  * @param queue_port_id
548  *   Queue or port number depending on mode
549  * @param xstats_names
550  *   Array of name values to be filled in
551  * @param ids
552  *   The stat ids to retrieve
553  * @param size
554  *   Number of values in the xstats_names array
555  * @return
556  *   When size >= the number of stats, return the number of stat values filled
557  *   into the array.
558  *   When size < the number of available stats, return the number of stats
559  *   values, and do not fill in any data into xstats_names.
560  */
561 typedef int (*eventdev_xstats_get_names_t)(const struct rte_eventdev *dev,
562                 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
563                 struct rte_event_dev_xstats_name *xstats_names,
564                 unsigned int *ids, unsigned int size);
565
566 /**
567  * Get value of one stats and optionally return its id
568  *
569  * @param dev
570  *   Event device pointer
571  * @param name
572  *   The name of the stat to retrieve
573  * @param id
574  *   Pointer to an unsigned int where we store the stat-id for future reference.
575  *   This pointer may be null if the id is not required.
576  * @return
577  *   The value of the stat, or (uint64_t)-1 if the stat is not found.
578  *   If the stat is not found, the id value will be returned as (unsigned)-1,
579  *   if id pointer is non-NULL
580  */
581 typedef uint64_t (*eventdev_xstats_get_by_name)(const struct rte_eventdev *dev,
582                 const char *name, unsigned int *id);
583
584
585 /**
586  * Retrieve the event device's ethdev Rx adapter capabilities for the
587  * specified ethernet port
588  *
589  * @param dev
590  *   Event device pointer
591  *
592  * @param eth_dev
593  *   Ethernet device pointer
594  *
595  * @param[out] caps
596  *   A pointer to memory filled with Rx event adapter capabilities.
597  *
598  * @return
599  *   - 0: Success, driver provides Rx event adapter capabilities for the
600  *      ethernet device.
601  *   - <0: Error code returned by the driver function.
602  *
603  */
604 typedef int (*eventdev_eth_rx_adapter_caps_get_t)
605                                         (const struct rte_eventdev *dev,
606                                         const struct rte_eth_dev *eth_dev,
607                                         uint32_t *caps);
608
609 struct rte_event_eth_rx_adapter_queue_conf;
610
611 /**
612  * Retrieve the event device's timer adapter capabilities, as well as the ops
613  * structure that an event timer adapter should call through to enter the
614  * driver
615  *
616  * @param dev
617  *   Event device pointer
618  *
619  * @param flags
620  *   Flags that can be used to determine how to select an event timer
621  *   adapter ops structure
622  *
623  * @param[out] caps
624  *   A pointer to memory filled with Rx event adapter capabilities.
625  *
626  * @param[out] ops
627  *   A pointer to the ops pointer to set with the address of the desired ops
628  *   structure
629  *
630  * @return
631  *   - 0: Success, driver provides Rx event adapter capabilities for the
632  *      ethernet device.
633  *   - <0: Error code returned by the driver function.
634  *
635  */
636 typedef int (*eventdev_timer_adapter_caps_get_t)(
637         const struct rte_eventdev *dev, uint64_t flags, uint32_t *caps,
638         const struct event_timer_adapter_ops **ops);
639
640 /**
641  * Add ethernet Rx queues to event device. This callback is invoked if
642  * the caps returned from rte_eventdev_eth_rx_adapter_caps_get(, eth_port_id)
643  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
644  *
645  * @param dev
646  *   Event device pointer
647  *
648  * @param eth_dev
649  *   Ethernet device pointer
650  *
651  * @param rx_queue_id
652  *   Ethernet device receive queue index
653  *
654  * @param queue_conf
655  *  Additional configuration structure
656
657  * @return
658  *   - 0: Success, ethernet receive queue added successfully.
659  *   - <0: Error code returned by the driver function.
660  *
661  */
662 typedef int (*eventdev_eth_rx_adapter_queue_add_t)(
663                 const struct rte_eventdev *dev,
664                 const struct rte_eth_dev *eth_dev,
665                 int32_t rx_queue_id,
666                 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
667
668 /**
669  * Delete ethernet Rx queues from event device. This callback is invoked if
670  * the caps returned from eventdev_eth_rx_adapter_caps_get(, eth_port_id)
671  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
672  *
673  * @param dev
674  *   Event device pointer
675  *
676  * @param eth_dev
677  *   Ethernet device pointer
678  *
679  * @param rx_queue_id
680  *   Ethernet device receive queue index
681  *
682  * @return
683  *   - 0: Success, ethernet receive queue deleted successfully.
684  *   - <0: Error code returned by the driver function.
685  *
686  */
687 typedef int (*eventdev_eth_rx_adapter_queue_del_t)
688                                         (const struct rte_eventdev *dev,
689                                         const struct rte_eth_dev *eth_dev,
690                                         int32_t rx_queue_id);
691
692 /**
693  * Retrieve Rx adapter queue config information for the specified
694  * rx queue ID.
695  *
696  * @param dev
697  *  Event device pointer
698  *
699  * @param eth_dev
700  *  Ethernet device pointer
701  *
702  * @param rx_queue_id
703  *  Ethernet device receive queue index.
704  *
705  * @param[out] queue_conf
706  *  Pointer to rte_event_eth_rx_adapter_queue_conf structure
707  *
708  * @return
709  *  - 0: Success
710  *  - <0: Error code on failure.
711  */
712 typedef int (*eventdev_eth_rx_adapter_queue_conf_get_t)
713                         (const struct rte_eventdev *dev,
714                         const struct rte_eth_dev *eth_dev,
715                         uint16_t rx_queue_id,
716                         struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
717
718 /**
719  * Start ethernet Rx adapter. This callback is invoked if
720  * the caps returned from eventdev_eth_rx_adapter_caps_get(.., eth_port_id)
721  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
722  * from eth_port_id have been added to the event device.
723  *
724  * @param dev
725  *   Event device pointer
726  *
727  * @param eth_dev
728  *   Ethernet device pointer
729  *
730  * @return
731  *   - 0: Success, ethernet Rx adapter started successfully.
732  *   - <0: Error code returned by the driver function.
733  */
734 typedef int (*eventdev_eth_rx_adapter_start_t)
735                                         (const struct rte_eventdev *dev,
736                                         const struct rte_eth_dev *eth_dev);
737
738 /**
739  * Stop ethernet Rx adapter. This callback is invoked if
740  * the caps returned from eventdev_eth_rx_adapter_caps_get(..,eth_port_id)
741  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
742  * from eth_port_id have been added to the event device.
743  *
744  * @param dev
745  *   Event device pointer
746  *
747  * @param eth_dev
748  *   Ethernet device pointer
749  *
750  * @return
751  *   - 0: Success, ethernet Rx adapter stopped successfully.
752  *   - <0: Error code returned by the driver function.
753  */
754 typedef int (*eventdev_eth_rx_adapter_stop_t)
755                                         (const struct rte_eventdev *dev,
756                                         const struct rte_eth_dev *eth_dev);
757
758 struct rte_event_eth_rx_adapter_stats;
759
760 /**
761  * Retrieve ethernet Rx adapter statistics.
762  *
763  * @param dev
764  *   Event device pointer
765  *
766  * @param eth_dev
767  *   Ethernet device pointer
768  *
769  * @param[out] stats
770  *   Pointer to stats structure
771  *
772  * @return
773  *   Return 0 on success.
774  */
775
776 typedef int (*eventdev_eth_rx_adapter_stats_get)
777                         (const struct rte_eventdev *dev,
778                         const struct rte_eth_dev *eth_dev,
779                         struct rte_event_eth_rx_adapter_stats *stats);
780 /**
781  * Reset ethernet Rx adapter statistics.
782  *
783  * @param dev
784  *   Event device pointer
785  *
786  * @param eth_dev
787  *   Ethernet device pointer
788  *
789  * @return
790  *   Return 0 on success.
791  */
792 typedef int (*eventdev_eth_rx_adapter_stats_reset)
793                         (const struct rte_eventdev *dev,
794                         const struct rte_eth_dev *eth_dev);
795
796 struct rte_event_eth_rx_adapter_queue_stats;
797
798 /**
799  * Retrieve ethernet Rx adapter queue statistics.
800  *
801  * @param dev
802  *   Event device pointer
803  *
804  * @param eth_dev
805  *   Ethernet device pointer
806  *
807  * @param rx_queue_id
808  *  Ethernet device receive queue index.
809  *
810  * @param[out] q_stats
811  *   Pointer to queue stats structure
812  *
813  * @return
814  *   Return 0 on success.
815  */
816 typedef int (*eventdev_eth_rx_adapter_q_stats_get)
817                         (const struct rte_eventdev *dev,
818                          const struct rte_eth_dev *eth_dev,
819                          uint16_t rx_queue_id,
820                          struct rte_event_eth_rx_adapter_queue_stats *q_stats);
821
822 /**
823  * Reset ethernet Rx adapter queue statistics.
824  *
825  * @param dev
826  *   Event device pointer
827  *
828  * @param eth_dev
829  *   Ethernet device pointer
830  *
831  * @param rx_queue_id
832  *  Ethernet device receive queue index.
833  *
834  * @return
835  *   Return 0 on success.
836  */
837 typedef int (*eventdev_eth_rx_adapter_q_stats_reset)
838                         (const struct rte_eventdev *dev,
839                          const struct rte_eth_dev *eth_dev,
840                          uint16_t rx_queue_id);
841
842 /**
843  * Start eventdev selftest.
844  *
845  * @return
846  *   Return 0 on success.
847  */
848 typedef int (*eventdev_selftest)(void);
849
850 struct rte_event_eth_rx_adapter_vector_limits;
851 /**
852  * Get event vector limits for a given event, ethernet device pair.
853  *
854  * @param dev
855  *   Event device pointer
856  *
857  * @param eth_dev
858  *   Ethernet device pointer
859  *
860  * @param[out] limits
861  *   Pointer to the limits structure to be filled.
862  *
863  * @return
864  *   - 0: Success.
865  *   - <0: Error code returned by the driver function.
866  */
867 typedef int (*eventdev_eth_rx_adapter_vector_limits_get_t)(
868         const struct rte_eventdev *dev, const struct rte_eth_dev *eth_dev,
869         struct rte_event_eth_rx_adapter_vector_limits *limits);
870
871 typedef uint32_t rte_event_pmd_selftest_seqn_t;
872 extern int rte_event_pmd_selftest_seqn_dynfield_offset;
873
874 /**
875  * Read test sequence number from mbuf.
876  *
877  * @param mbuf Structure to read from.
878  * @return pointer to test sequence number.
879  */
880 __rte_internal
881 static inline rte_event_pmd_selftest_seqn_t *
882 rte_event_pmd_selftest_seqn(struct rte_mbuf *mbuf)
883 {
884         return RTE_MBUF_DYNFIELD(mbuf,
885                 rte_event_pmd_selftest_seqn_dynfield_offset,
886                 rte_event_pmd_selftest_seqn_t *);
887 }
888
889 struct rte_cryptodev;
890
891 /**
892  * This API may change without prior notice
893  *
894  * Retrieve the event device's crypto adapter capabilities for the
895  * specified cryptodev
896  *
897  * @param dev
898  *   Event device pointer
899  *
900  * @param cdev
901  *   cryptodev pointer
902  *
903  * @param[out] caps
904  *   A pointer to memory filled with event adapter capabilities.
905  *   It is expected to be pre-allocated & initialized by caller.
906  *
907  * @return
908  *   - 0: Success, driver provides event adapter capabilities for the
909  *      cryptodev.
910  *   - <0: Error code returned by the driver function.
911  *
912  */
913 typedef int (*eventdev_crypto_adapter_caps_get_t)
914                                         (const struct rte_eventdev *dev,
915                                          const struct rte_cryptodev *cdev,
916                                          uint32_t *caps);
917
918 /**
919  * This API may change without prior notice
920  *
921  * Add crypto queue pair to event device. This callback is invoked if
922  * the caps returned from rte_event_crypto_adapter_caps_get(, cdev_id)
923  * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set.
924  *
925  * @param dev
926  *   Event device pointer
927  *
928  * @param cdev
929  *   cryptodev pointer
930  *
931  * @param queue_pair_id
932  *   cryptodev queue pair identifier.
933  *
934  * @param event
935  *  Event information required for binding cryptodev queue pair to event queue.
936  *  This structure will have a valid value for only those HW PMDs supporting
937  *  @see RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND capability.
938  *
939  * @return
940  *   - 0: Success, cryptodev queue pair added successfully.
941  *   - <0: Error code returned by the driver function.
942  *
943  */
944 typedef int (*eventdev_crypto_adapter_queue_pair_add_t)
945                         (const struct rte_eventdev *dev,
946                          const struct rte_cryptodev *cdev,
947                          int32_t queue_pair_id,
948                          const struct rte_event *event);
949
950
951 /**
952  * This API may change without prior notice
953  *
954  * Delete crypto queue pair to event device. This callback is invoked if
955  * the caps returned from rte_event_crypto_adapter_caps_get(, cdev_id)
956  * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set.
957  *
958  * @param dev
959  *   Event device pointer
960  *
961  * @param cdev
962  *   cryptodev pointer
963  *
964  * @param queue_pair_id
965  *   cryptodev queue pair identifier.
966  *
967  * @return
968  *   - 0: Success, cryptodev queue pair deleted successfully.
969  *   - <0: Error code returned by the driver function.
970  *
971  */
972 typedef int (*eventdev_crypto_adapter_queue_pair_del_t)
973                                         (const struct rte_eventdev *dev,
974                                          const struct rte_cryptodev *cdev,
975                                          int32_t queue_pair_id);
976
977 /**
978  * Start crypto adapter. This callback is invoked if
979  * the caps returned from rte_event_crypto_adapter_caps_get(.., cdev_id)
980  * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set and queue pairs
981  * from cdev_id have been added to the event device.
982  *
983  * @param dev
984  *   Event device pointer
985  *
986  * @param cdev
987  *   Crypto device pointer
988  *
989  * @return
990  *   - 0: Success, crypto adapter started successfully.
991  *   - <0: Error code returned by the driver function.
992  */
993 typedef int (*eventdev_crypto_adapter_start_t)
994                                         (const struct rte_eventdev *dev,
995                                          const struct rte_cryptodev *cdev);
996
997 /**
998  * Stop crypto adapter. This callback is invoked if
999  * the caps returned from rte_event_crypto_adapter_caps_get(.., cdev_id)
1000  * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set and queue pairs
1001  * from cdev_id have been added to the event device.
1002  *
1003  * @param dev
1004  *   Event device pointer
1005  *
1006  * @param cdev
1007  *   Crypto device pointer
1008  *
1009  * @return
1010  *   - 0: Success, crypto adapter stopped successfully.
1011  *   - <0: Error code returned by the driver function.
1012  */
1013 typedef int (*eventdev_crypto_adapter_stop_t)
1014                                         (const struct rte_eventdev *dev,
1015                                          const struct rte_cryptodev *cdev);
1016
1017 struct rte_event_crypto_adapter_stats;
1018
1019 /**
1020  * Retrieve crypto adapter statistics.
1021  *
1022  * @param dev
1023  *   Event device pointer
1024  *
1025  * @param cdev
1026  *   Crypto device pointer
1027  *
1028  * @param[out] stats
1029  *   Pointer to stats structure
1030  *
1031  * @return
1032  *   Return 0 on success.
1033  */
1034
1035 typedef int (*eventdev_crypto_adapter_stats_get)
1036                         (const struct rte_eventdev *dev,
1037                          const struct rte_cryptodev *cdev,
1038                          struct rte_event_crypto_adapter_stats *stats);
1039
1040 /**
1041  * Reset crypto adapter statistics.
1042  *
1043  * @param dev
1044  *   Event device pointer
1045  *
1046  * @param cdev
1047  *   Crypto device pointer
1048  *
1049  * @return
1050  *   Return 0 on success.
1051  */
1052
1053 typedef int (*eventdev_crypto_adapter_stats_reset)
1054                         (const struct rte_eventdev *dev,
1055                          const struct rte_cryptodev *cdev);
1056
1057 /**
1058  * Retrieve the event device's eth Tx adapter capabilities.
1059  *
1060  * @param dev
1061  *   Event device pointer
1062  *
1063  * @param eth_dev
1064  *   Ethernet device pointer
1065  *
1066  * @param[out] caps
1067  *   A pointer to memory filled with eth Tx adapter capabilities.
1068  *
1069  * @return
1070  *   - 0: Success, driver provides eth Tx adapter capabilities
1071  *   - <0: Error code returned by the driver function.
1072  *
1073  */
1074 typedef int (*eventdev_eth_tx_adapter_caps_get_t)
1075                                         (const struct rte_eventdev *dev,
1076                                         const struct rte_eth_dev *eth_dev,
1077                                         uint32_t *caps);
1078
1079 /**
1080  * Create adapter callback.
1081  *
1082  * @param id
1083  *   Adapter identifier
1084  *
1085  * @param dev
1086  *   Event device pointer
1087  *
1088  * @return
1089  *   - 0: Success.
1090  *   - <0: Error code on failure.
1091  */
1092 typedef int (*eventdev_eth_tx_adapter_create_t)(uint8_t id,
1093                                         const struct rte_eventdev *dev);
1094
1095 /**
1096  * Free adapter callback.
1097  *
1098  * @param id
1099  *   Adapter identifier
1100  *
1101  * @param dev
1102  *   Event device pointer
1103  *
1104  * @return
1105  *   - 0: Success.
1106  *   - <0: Error code on failure.
1107  */
1108 typedef int (*eventdev_eth_tx_adapter_free_t)(uint8_t id,
1109                                         const struct rte_eventdev *dev);
1110
1111 /**
1112  * Add a Tx queue to the adapter.
1113  * A queue value of -1 is used to indicate all
1114  * queues within the device.
1115  *
1116  * @param id
1117  *   Adapter identifier
1118  *
1119  * @param dev
1120  *   Event device pointer
1121  *
1122  * @param eth_dev
1123  *   Ethernet device pointer
1124  *
1125  * @param tx_queue_id
1126  *   Transmit queue index
1127  *
1128  * @return
1129  *   - 0: Success.
1130  *   - <0: Error code on failure.
1131  */
1132 typedef int (*eventdev_eth_tx_adapter_queue_add_t)(
1133                                         uint8_t id,
1134                                         const struct rte_eventdev *dev,
1135                                         const struct rte_eth_dev *eth_dev,
1136                                         int32_t tx_queue_id);
1137
1138 /**
1139  * Delete a Tx queue from the adapter.
1140  * A queue value of -1 is used to indicate all
1141  * queues within the device, that have been added to this
1142  * adapter.
1143  *
1144  * @param id
1145  *   Adapter identifier
1146  *
1147  * @param dev
1148  *   Event device pointer
1149  *
1150  * @param eth_dev
1151  *   Ethernet device pointer
1152  *
1153  * @param tx_queue_id
1154  *   Transmit queue index
1155  *
1156  * @return
1157  *  - 0: Success, Queues deleted successfully.
1158  *  - <0: Error code on failure.
1159  */
1160 typedef int (*eventdev_eth_tx_adapter_queue_del_t)(
1161                                         uint8_t id,
1162                                         const struct rte_eventdev *dev,
1163                                         const struct rte_eth_dev *eth_dev,
1164                                         int32_t tx_queue_id);
1165
1166 /**
1167  * Start the adapter.
1168  *
1169  * @param id
1170  *   Adapter identifier
1171  *
1172  * @param dev
1173  *   Event device pointer
1174  *
1175  * @return
1176  *  - 0: Success, Adapter started correctly.
1177  *  - <0: Error code on failure.
1178  */
1179 typedef int (*eventdev_eth_tx_adapter_start_t)(uint8_t id,
1180                                         const struct rte_eventdev *dev);
1181
1182 /**
1183  * Stop the adapter.
1184  *
1185  * @param id
1186  *  Adapter identifier
1187  *
1188  * @param dev
1189  *   Event device pointer
1190  *
1191  * @return
1192  *  - 0: Success.
1193  *  - <0: Error code on failure.
1194  */
1195 typedef int (*eventdev_eth_tx_adapter_stop_t)(uint8_t id,
1196                                         const struct rte_eventdev *dev);
1197
1198 struct rte_event_eth_tx_adapter_stats;
1199
1200 /**
1201  * Retrieve statistics for an adapter
1202  *
1203  * @param id
1204  *  Adapter identifier
1205  *
1206  * @param dev
1207  *   Event device pointer
1208  *
1209  * @param [out] stats
1210  *  A pointer to structure used to retrieve statistics for an adapter
1211  *
1212  * @return
1213  *  - 0: Success, statistics retrieved successfully.
1214  *  - <0: Error code on failure.
1215  */
1216 typedef int (*eventdev_eth_tx_adapter_stats_get_t)(
1217                                 uint8_t id,
1218                                 const struct rte_eventdev *dev,
1219                                 struct rte_event_eth_tx_adapter_stats *stats);
1220
1221 /**
1222  * Reset statistics for an adapter
1223  *
1224  * @param id
1225  *  Adapter identifier
1226  *
1227  * @param dev
1228  *   Event device pointer
1229  *
1230  * @return
1231  *  - 0: Success, statistics retrieved successfully.
1232  *  - <0: Error code on failure.
1233  */
1234 typedef int (*eventdev_eth_tx_adapter_stats_reset_t)(uint8_t id,
1235                                         const struct rte_eventdev *dev);
1236
1237 /** Event device operations function pointer table */
1238 struct eventdev_ops {
1239         eventdev_info_get_t dev_infos_get;      /**< Get device info. */
1240         eventdev_configure_t dev_configure;     /**< Configure device. */
1241         eventdev_start_t dev_start;             /**< Start device. */
1242         eventdev_stop_t dev_stop;               /**< Stop device. */
1243         eventdev_close_t dev_close;             /**< Close device. */
1244
1245         eventdev_queue_default_conf_get_t queue_def_conf;
1246         /**< Get default queue configuration. */
1247         eventdev_queue_setup_t queue_setup;
1248         /**< Set up an event queue. */
1249         eventdev_queue_release_t queue_release;
1250         /**< Release an event queue. */
1251         eventdev_queue_attr_set_t queue_attr_set;
1252         /**< Set an event queue attribute. */
1253
1254         eventdev_port_default_conf_get_t port_def_conf;
1255         /**< Get default port configuration. */
1256         eventdev_port_setup_t port_setup;
1257         /**< Set up an event port. */
1258         eventdev_port_release_t port_release;
1259         /**< Release an event port. */
1260         eventdev_port_quiesce_t port_quiesce;
1261         /**< Quiesce an event port. */
1262
1263         eventdev_port_link_t port_link;
1264         /**< Link event queues to an event port. */
1265         eventdev_port_unlink_t port_unlink;
1266         /**< Unlink event queues from an event port. */
1267         eventdev_port_unlinks_in_progress_t port_unlinks_in_progress;
1268         /**< Unlinks in progress on an event port. */
1269         eventdev_dequeue_timeout_ticks_t timeout_ticks;
1270         /**< Converts ns to *timeout_ticks* value for rte_event_dequeue() */
1271         eventdev_dump_t dump;
1272         /* Dump internal information */
1273
1274         eventdev_xstats_get_t xstats_get;
1275         /**< Get extended device statistics. */
1276         eventdev_xstats_get_names_t xstats_get_names;
1277         /**< Get names of extended stats. */
1278         eventdev_xstats_get_by_name xstats_get_by_name;
1279         /**< Get one value by name. */
1280         eventdev_xstats_reset_t xstats_reset;
1281         /**< Reset the statistics values in xstats. */
1282
1283         eventdev_eth_rx_adapter_caps_get_t eth_rx_adapter_caps_get;
1284         /**< Get ethernet Rx adapter capabilities */
1285         eventdev_eth_rx_adapter_queue_add_t eth_rx_adapter_queue_add;
1286         /**< Add Rx queues to ethernet Rx adapter */
1287         eventdev_eth_rx_adapter_queue_del_t eth_rx_adapter_queue_del;
1288         /**< Delete Rx queues from ethernet Rx adapter */
1289         eventdev_eth_rx_adapter_queue_conf_get_t eth_rx_adapter_queue_conf_get;
1290         /**< Get Rx adapter queue info */
1291         eventdev_eth_rx_adapter_start_t eth_rx_adapter_start;
1292         /**< Start ethernet Rx adapter */
1293         eventdev_eth_rx_adapter_stop_t eth_rx_adapter_stop;
1294         /**< Stop ethernet Rx adapter */
1295         eventdev_eth_rx_adapter_stats_get eth_rx_adapter_stats_get;
1296         /**< Get ethernet Rx stats */
1297         eventdev_eth_rx_adapter_stats_reset eth_rx_adapter_stats_reset;
1298         /**< Reset ethernet Rx stats */
1299         eventdev_eth_rx_adapter_vector_limits_get_t
1300                 eth_rx_adapter_vector_limits_get;
1301         /**< Get event vector limits for the Rx adapter */
1302
1303         eventdev_timer_adapter_caps_get_t timer_adapter_caps_get;
1304         /**< Get timer adapter capabilities */
1305
1306         eventdev_crypto_adapter_caps_get_t crypto_adapter_caps_get;
1307         /**< Get crypto adapter capabilities */
1308         eventdev_crypto_adapter_queue_pair_add_t crypto_adapter_queue_pair_add;
1309         /**< Add queue pair to crypto adapter */
1310         eventdev_crypto_adapter_queue_pair_del_t crypto_adapter_queue_pair_del;
1311         /**< Delete queue pair from crypto adapter */
1312         eventdev_crypto_adapter_start_t crypto_adapter_start;
1313         /**< Start crypto adapter */
1314         eventdev_crypto_adapter_stop_t crypto_adapter_stop;
1315         /**< Stop crypto adapter */
1316         eventdev_crypto_adapter_stats_get crypto_adapter_stats_get;
1317         /**< Get crypto stats */
1318         eventdev_crypto_adapter_stats_reset crypto_adapter_stats_reset;
1319         /**< Reset crypto stats */
1320
1321         eventdev_eth_rx_adapter_q_stats_get eth_rx_adapter_queue_stats_get;
1322         /**< Get ethernet Rx queue stats */
1323         eventdev_eth_rx_adapter_q_stats_reset eth_rx_adapter_queue_stats_reset;
1324         /**< Reset ethernet Rx queue stats */
1325
1326         eventdev_eth_tx_adapter_caps_get_t eth_tx_adapter_caps_get;
1327         /**< Get ethernet Tx adapter capabilities */
1328
1329         eventdev_eth_tx_adapter_create_t eth_tx_adapter_create;
1330         /**< Create adapter callback */
1331         eventdev_eth_tx_adapter_free_t eth_tx_adapter_free;
1332         /**< Free adapter callback */
1333         eventdev_eth_tx_adapter_queue_add_t eth_tx_adapter_queue_add;
1334         /**< Add Tx queues to the eth Tx adapter */
1335         eventdev_eth_tx_adapter_queue_del_t eth_tx_adapter_queue_del;
1336         /**< Delete Tx queues from the eth Tx adapter */
1337         eventdev_eth_tx_adapter_start_t eth_tx_adapter_start;
1338         /**< Start eth Tx adapter */
1339         eventdev_eth_tx_adapter_stop_t eth_tx_adapter_stop;
1340         /**< Stop eth Tx adapter */
1341         eventdev_eth_tx_adapter_stats_get_t eth_tx_adapter_stats_get;
1342         /**< Get eth Tx adapter statistics */
1343         eventdev_eth_tx_adapter_stats_reset_t eth_tx_adapter_stats_reset;
1344         /**< Reset eth Tx adapter statistics */
1345
1346         eventdev_selftest dev_selftest;
1347         /**< Start eventdev Selftest */
1348
1349         eventdev_stop_flush_t dev_stop_flush;
1350         /**< User-provided event flush function */
1351 };
1352
1353 /**
1354  * Allocates a new eventdev slot for an event device and returns the pointer
1355  * to that slot for the driver to use.
1356  *
1357  * @param name
1358  *   Unique identifier name for each device
1359  * @param socket_id
1360  *   Socket to allocate resources on.
1361  * @return
1362  *   - Slot in the rte_dev_devices array for a new device;
1363  */
1364 __rte_internal
1365 struct rte_eventdev *
1366 rte_event_pmd_allocate(const char *name, int socket_id);
1367
1368 /**
1369  * Release the specified eventdev device.
1370  *
1371  * @param eventdev
1372  * The *eventdev* pointer is the address of the *rte_eventdev* structure.
1373  * @return
1374  *   - 0 on success, negative on error
1375  */
1376 __rte_internal
1377 int
1378 rte_event_pmd_release(struct rte_eventdev *eventdev);
1379
1380 /**
1381  *
1382  * @internal
1383  * This is the last step of device probing.
1384  * It must be called after a port is allocated and initialized successfully.
1385  *
1386  * @param eventdev
1387  *  New event device.
1388  */
1389 __rte_internal
1390 void
1391 event_dev_probing_finish(struct rte_eventdev *eventdev);
1392
1393 /**
1394  * Reset eventdevice fastpath APIs to dummy values.
1395  *
1396  * @param fp_ops
1397  * The *fp_ops* pointer to reset.
1398  */
1399 __rte_internal
1400 void
1401 event_dev_fp_ops_reset(struct rte_event_fp_ops *fp_op);
1402
1403 /**
1404  * Set eventdevice fastpath APIs to event device values.
1405  *
1406  * @param fp_ops
1407  * The *fp_ops* pointer to set.
1408  */
1409 __rte_internal
1410 void
1411 event_dev_fp_ops_set(struct rte_event_fp_ops *fp_ops,
1412                      const struct rte_eventdev *dev);
1413
1414 #ifdef __cplusplus
1415 }
1416 #endif
1417
1418 #endif /* _RTE_EVENTDEV_PMD_H_ */