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