xref: /dpdk/lib/eventdev/eventdev_pmd.h (revision 1ff23ce6)
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  * Retrieve the default event port configuration.
346  *
347  * @param dev
348  *   Event device pointer
349  * @param port_id
350  *   Event port index
351  * @param[out] port_conf
352  *   Event port configuration structure
353  *
354  */
355 typedef void (*eventdev_port_default_conf_get_t)(struct rte_eventdev *dev,
356 		uint8_t port_id, struct rte_event_port_conf *port_conf);
357 
358 /**
359  * Setup an event port.
360  *
361  * @param dev
362  *   Event device pointer
363  * @param port_id
364  *   Event port index
365  * @param port_conf
366  *   Event port configuration structure
367  *
368  * @return
369  *   Returns 0 on success.
370  */
371 typedef int (*eventdev_port_setup_t)(struct rte_eventdev *dev,
372 		uint8_t port_id,
373 		const struct rte_event_port_conf *port_conf);
374 
375 /**
376  * Release memory resources allocated by given event port.
377  *
378  * @param port
379  *   Event port pointer
380  *
381  */
382 typedef void (*eventdev_port_release_t)(void *port);
383 
384 /**
385  * Quiesce any core specific resources consumed by the event port
386  *
387  * @param dev
388  *   Event device pointer.
389  * @param port
390  *   Event port pointer.
391  * @param flush_cb
392  *   User-provided event flush function.
393  * @param args
394  *   Arguments to be passed to the user-provided event flush function.
395  *
396  */
397 typedef void (*eventdev_port_quiesce_t)(struct rte_eventdev *dev, void *port,
398 					rte_eventdev_port_flush_t flush_cb,
399 					void *args);
400 
401 /**
402  * Link multiple source event queues to destination event port.
403  *
404  * @param dev
405  *   Event device pointer
406  * @param port
407  *   Event port pointer
408  * @param queues
409  *   Points to an array of *nb_links* event queues to be linked
410  *   to the event port.
411  * @param priorities
412  *   Points to an array of *nb_links* service priorities associated with each
413  *   event queue link to event port.
414  * @param nb_links
415  *   The number of links to establish
416  *
417  * @return
418  *   Returns 0 on success.
419  *
420  */
421 typedef int (*eventdev_port_link_t)(struct rte_eventdev *dev, void *port,
422 		const uint8_t queues[], const uint8_t priorities[],
423 		uint16_t nb_links);
424 
425 /**
426  * Unlink multiple source event queues from destination event port.
427  *
428  * @param dev
429  *   Event device pointer
430  * @param port
431  *   Event port pointer
432  * @param queues
433  *   An array of *nb_unlinks* event queues to be unlinked from the event port.
434  * @param nb_unlinks
435  *   The number of unlinks to establish
436  *
437  * @return
438  *   Returns 0 on success.
439  *
440  */
441 typedef int (*eventdev_port_unlink_t)(struct rte_eventdev *dev, void *port,
442 		uint8_t queues[], uint16_t nb_unlinks);
443 
444 /**
445  * Unlinks in progress. Returns number of unlinks that the PMD is currently
446  * performing, but have not yet been completed.
447  *
448  * @param dev
449  *   Event device pointer
450  *
451  * @param port
452  *   Event port pointer
453  *
454  * @return
455  *   Returns the number of in-progress unlinks. Zero is returned if none are
456  *   in progress.
457  */
458 typedef int (*eventdev_port_unlinks_in_progress_t)(struct rte_eventdev *dev,
459 		void *port);
460 
461 /**
462  * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue()
463  *
464  * @param dev
465  *   Event device pointer
466  * @param ns
467  *   Wait time in nanosecond
468  * @param[out] timeout_ticks
469  *   Value for the *timeout_ticks* parameter in rte_event_dequeue() function
470  *
471  * @return
472  *   Returns 0 on success.
473  *
474  */
475 typedef int (*eventdev_dequeue_timeout_ticks_t)(struct rte_eventdev *dev,
476 		uint64_t ns, uint64_t *timeout_ticks);
477 
478 /**
479  * Dump internal information
480  *
481  * @param dev
482  *   Event device pointer
483  * @param f
484  *   A pointer to a file for output
485  *
486  */
487 typedef void (*eventdev_dump_t)(struct rte_eventdev *dev, FILE *f);
488 
489 /**
490  * Retrieve a set of statistics from device
491  *
492  * @param dev
493  *   Event device pointer
494  * @param mode
495  *   Level (device, port or queue)
496  * @param queue_port_id
497  *   Queue or port number depending on mode
498  * @param ids
499  *   The stat ids to retrieve
500  * @param values
501  *   The returned stat values
502  * @param n
503  *   The number of id values and entries in the values array
504  * @return
505  *   The number of stat values successfully filled into the values array
506  */
507 typedef int (*eventdev_xstats_get_t)(const struct rte_eventdev *dev,
508 		enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
509 		const unsigned int ids[], uint64_t values[], unsigned int n);
510 
511 /**
512  * Resets the statistic values in xstats for the device, based on mode.
513  */
514 typedef int (*eventdev_xstats_reset_t)(struct rte_eventdev *dev,
515 		enum rte_event_dev_xstats_mode mode,
516 		int16_t queue_port_id,
517 		const uint32_t ids[],
518 		uint32_t nb_ids);
519 
520 /**
521  * Get names of extended stats of an event device
522  *
523  * @param dev
524  *   Event device pointer
525  * @param mode
526  *   Level (device, port or queue)
527  * @param queue_port_id
528  *   Queue or port number depending on mode
529  * @param xstats_names
530  *   Array of name values to be filled in
531  * @param ids
532  *   The stat ids to retrieve
533  * @param size
534  *   Number of values in the xstats_names array
535  * @return
536  *   When size >= the number of stats, return the number of stat values filled
537  *   into the array.
538  *   When size < the number of available stats, return the number of stats
539  *   values, and do not fill in any data into xstats_names.
540  */
541 typedef int (*eventdev_xstats_get_names_t)(const struct rte_eventdev *dev,
542 		enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
543 		struct rte_event_dev_xstats_name *xstats_names,
544 		unsigned int *ids, unsigned int size);
545 
546 /**
547  * Get value of one stats and optionally return its id
548  *
549  * @param dev
550  *   Event device pointer
551  * @param name
552  *   The name of the stat to retrieve
553  * @param id
554  *   Pointer to an unsigned int where we store the stat-id for future reference.
555  *   This pointer may be null if the id is not required.
556  * @return
557  *   The value of the stat, or (uint64_t)-1 if the stat is not found.
558  *   If the stat is not found, the id value will be returned as (unsigned)-1,
559  *   if id pointer is non-NULL
560  */
561 typedef uint64_t (*eventdev_xstats_get_by_name)(const struct rte_eventdev *dev,
562 		const char *name, unsigned int *id);
563 
564 
565 /**
566  * Retrieve the event device's ethdev Rx adapter capabilities for the
567  * specified ethernet port
568  *
569  * @param dev
570  *   Event device pointer
571  *
572  * @param eth_dev
573  *   Ethernet device pointer
574  *
575  * @param[out] caps
576  *   A pointer to memory filled with Rx event adapter capabilities.
577  *
578  * @return
579  *   - 0: Success, driver provides Rx event adapter capabilities for the
580  *	ethernet device.
581  *   - <0: Error code returned by the driver function.
582  *
583  */
584 typedef int (*eventdev_eth_rx_adapter_caps_get_t)
585 					(const struct rte_eventdev *dev,
586 					const struct rte_eth_dev *eth_dev,
587 					uint32_t *caps);
588 
589 struct rte_event_eth_rx_adapter_queue_conf;
590 
591 /**
592  * Retrieve the event device's timer adapter capabilities, as well as the ops
593  * structure that an event timer adapter should call through to enter the
594  * driver
595  *
596  * @param dev
597  *   Event device pointer
598  *
599  * @param flags
600  *   Flags that can be used to determine how to select an event timer
601  *   adapter ops structure
602  *
603  * @param[out] caps
604  *   A pointer to memory filled with Rx event adapter capabilities.
605  *
606  * @param[out] ops
607  *   A pointer to the ops pointer to set with the address of the desired ops
608  *   structure
609  *
610  * @return
611  *   - 0: Success, driver provides Rx event adapter capabilities for the
612  *	ethernet device.
613  *   - <0: Error code returned by the driver function.
614  *
615  */
616 typedef int (*eventdev_timer_adapter_caps_get_t)(
617 	const struct rte_eventdev *dev, uint64_t flags, uint32_t *caps,
618 	const struct event_timer_adapter_ops **ops);
619 
620 /**
621  * Add ethernet Rx queues to event device. This callback is invoked if
622  * the caps returned from rte_eventdev_eth_rx_adapter_caps_get(, eth_port_id)
623  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
624  *
625  * @param dev
626  *   Event device pointer
627  *
628  * @param eth_dev
629  *   Ethernet device pointer
630  *
631  * @param rx_queue_id
632  *   Ethernet device receive queue index
633  *
634  * @param queue_conf
635  *  Additional configuration structure
636 
637  * @return
638  *   - 0: Success, ethernet receive queue added successfully.
639  *   - <0: Error code returned by the driver function.
640  *
641  */
642 typedef int (*eventdev_eth_rx_adapter_queue_add_t)(
643 		const struct rte_eventdev *dev,
644 		const struct rte_eth_dev *eth_dev,
645 		int32_t rx_queue_id,
646 		const struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
647 
648 /**
649  * Delete ethernet Rx queues from event device. This callback is invoked if
650  * the caps returned from eventdev_eth_rx_adapter_caps_get(, eth_port_id)
651  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set.
652  *
653  * @param dev
654  *   Event device pointer
655  *
656  * @param eth_dev
657  *   Ethernet device pointer
658  *
659  * @param rx_queue_id
660  *   Ethernet device receive queue index
661  *
662  * @return
663  *   - 0: Success, ethernet receive queue deleted successfully.
664  *   - <0: Error code returned by the driver function.
665  *
666  */
667 typedef int (*eventdev_eth_rx_adapter_queue_del_t)
668 					(const struct rte_eventdev *dev,
669 					const struct rte_eth_dev *eth_dev,
670 					int32_t rx_queue_id);
671 
672 /**
673  * Retrieve Rx adapter queue config information for the specified
674  * rx queue ID.
675  *
676  * @param dev
677  *  Event device pointer
678  *
679  * @param eth_dev
680  *  Ethernet device pointer
681  *
682  * @param rx_queue_id
683  *  Ethernet device receive queue index.
684  *
685  * @param[out] queue_conf
686  *  Pointer to rte_event_eth_rx_adapter_queue_conf structure
687  *
688  * @return
689  *  - 0: Success
690  *  - <0: Error code on failure.
691  */
692 typedef int (*eventdev_eth_rx_adapter_queue_conf_get_t)
693 			(const struct rte_eventdev *dev,
694 			const struct rte_eth_dev *eth_dev,
695 			uint16_t rx_queue_id,
696 			struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
697 
698 /**
699  * Start ethernet Rx adapter. This callback is invoked if
700  * the caps returned from eventdev_eth_rx_adapter_caps_get(.., eth_port_id)
701  * has RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT set and Rx queues
702  * from eth_port_id have been added to the event device.
703  *
704  * @param dev
705  *   Event device pointer
706  *
707  * @param eth_dev
708  *   Ethernet device pointer
709  *
710  * @return
711  *   - 0: Success, ethernet Rx adapter started successfully.
712  *   - <0: Error code returned by the driver function.
713  */
714 typedef int (*eventdev_eth_rx_adapter_start_t)
715 					(const struct rte_eventdev *dev,
716 					const struct rte_eth_dev *eth_dev);
717 
718 /**
719  * Stop 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 stopped successfully.
732  *   - <0: Error code returned by the driver function.
733  */
734 typedef int (*eventdev_eth_rx_adapter_stop_t)
735 					(const struct rte_eventdev *dev,
736 					const struct rte_eth_dev *eth_dev);
737 
738 struct rte_event_eth_rx_adapter_stats;
739 
740 /**
741  * Retrieve ethernet Rx adapter statistics.
742  *
743  * @param dev
744  *   Event device pointer
745  *
746  * @param eth_dev
747  *   Ethernet device pointer
748  *
749  * @param[out] stats
750  *   Pointer to stats structure
751  *
752  * @return
753  *   Return 0 on success.
754  */
755 
756 typedef int (*eventdev_eth_rx_adapter_stats_get)
757 			(const struct rte_eventdev *dev,
758 			const struct rte_eth_dev *eth_dev,
759 			struct rte_event_eth_rx_adapter_stats *stats);
760 /**
761  * Reset ethernet Rx adapter statistics.
762  *
763  * @param dev
764  *   Event device pointer
765  *
766  * @param eth_dev
767  *   Ethernet device pointer
768  *
769  * @return
770  *   Return 0 on success.
771  */
772 typedef int (*eventdev_eth_rx_adapter_stats_reset)
773 			(const struct rte_eventdev *dev,
774 			const struct rte_eth_dev *eth_dev);
775 
776 struct rte_event_eth_rx_adapter_queue_stats;
777 
778 /**
779  * Retrieve ethernet Rx adapter queue statistics.
780  *
781  * @param dev
782  *   Event device pointer
783  *
784  * @param eth_dev
785  *   Ethernet device pointer
786  *
787  * @param rx_queue_id
788  *  Ethernet device receive queue index.
789  *
790  * @param[out] q_stats
791  *   Pointer to queue stats structure
792  *
793  * @return
794  *   Return 0 on success.
795  */
796 typedef int (*eventdev_eth_rx_adapter_q_stats_get)
797 			(const struct rte_eventdev *dev,
798 			 const struct rte_eth_dev *eth_dev,
799 			 uint16_t rx_queue_id,
800 			 struct rte_event_eth_rx_adapter_queue_stats *q_stats);
801 
802 /**
803  * Reset ethernet Rx adapter queue statistics.
804  *
805  * @param dev
806  *   Event device pointer
807  *
808  * @param eth_dev
809  *   Ethernet device pointer
810  *
811  * @param rx_queue_id
812  *  Ethernet device receive queue index.
813  *
814  * @return
815  *   Return 0 on success.
816  */
817 typedef int (*eventdev_eth_rx_adapter_q_stats_reset)
818 			(const struct rte_eventdev *dev,
819 			 const struct rte_eth_dev *eth_dev,
820 			 uint16_t rx_queue_id);
821 
822 /**
823  * Start eventdev selftest.
824  *
825  * @return
826  *   Return 0 on success.
827  */
828 typedef int (*eventdev_selftest)(void);
829 
830 struct rte_event_eth_rx_adapter_vector_limits;
831 /**
832  * Get event vector limits for a given event, ethernet device pair.
833  *
834  * @param dev
835  *   Event device pointer
836  *
837  * @param eth_dev
838  *   Ethernet device pointer
839  *
840  * @param[out] limits
841  *   Pointer to the limits structure to be filled.
842  *
843  * @return
844  *   - 0: Success.
845  *   - <0: Error code returned by the driver function.
846  */
847 typedef int (*eventdev_eth_rx_adapter_vector_limits_get_t)(
848 	const struct rte_eventdev *dev, const struct rte_eth_dev *eth_dev,
849 	struct rte_event_eth_rx_adapter_vector_limits *limits);
850 
851 typedef uint32_t rte_event_pmd_selftest_seqn_t;
852 extern int rte_event_pmd_selftest_seqn_dynfield_offset;
853 
854 /**
855  * Read test sequence number from mbuf.
856  *
857  * @param mbuf Structure to read from.
858  * @return pointer to test sequence number.
859  */
860 __rte_internal
861 static inline rte_event_pmd_selftest_seqn_t *
862 rte_event_pmd_selftest_seqn(struct rte_mbuf *mbuf)
863 {
864 	return RTE_MBUF_DYNFIELD(mbuf,
865 		rte_event_pmd_selftest_seqn_dynfield_offset,
866 		rte_event_pmd_selftest_seqn_t *);
867 }
868 
869 struct rte_cryptodev;
870 
871 /**
872  * This API may change without prior notice
873  *
874  * Retrieve the event device's crypto adapter capabilities for the
875  * specified cryptodev
876  *
877  * @param dev
878  *   Event device pointer
879  *
880  * @param cdev
881  *   cryptodev pointer
882  *
883  * @param[out] caps
884  *   A pointer to memory filled with event adapter capabilities.
885  *   It is expected to be pre-allocated & initialized by caller.
886  *
887  * @return
888  *   - 0: Success, driver provides event adapter capabilities for the
889  *	cryptodev.
890  *   - <0: Error code returned by the driver function.
891  *
892  */
893 typedef int (*eventdev_crypto_adapter_caps_get_t)
894 					(const struct rte_eventdev *dev,
895 					 const struct rte_cryptodev *cdev,
896 					 uint32_t *caps);
897 
898 /**
899  * This API may change without prior notice
900  *
901  * Add crypto queue pair to event device. This callback is invoked if
902  * the caps returned from rte_event_crypto_adapter_caps_get(, cdev_id)
903  * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set.
904  *
905  * @param dev
906  *   Event device pointer
907  *
908  * @param cdev
909  *   cryptodev pointer
910  *
911  * @param queue_pair_id
912  *   cryptodev queue pair identifier.
913  *
914  * @param event
915  *  Event information required for binding cryptodev queue pair to event queue.
916  *  This structure will have a valid value for only those HW PMDs supporting
917  *  @see RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND capability.
918  *
919  * @return
920  *   - 0: Success, cryptodev queue pair added successfully.
921  *   - <0: Error code returned by the driver function.
922  *
923  */
924 typedef int (*eventdev_crypto_adapter_queue_pair_add_t)
925 			(const struct rte_eventdev *dev,
926 			 const struct rte_cryptodev *cdev,
927 			 int32_t queue_pair_id,
928 			 const struct rte_event *event);
929 
930 
931 /**
932  * This API may change without prior notice
933  *
934  * Delete crypto queue pair to event device. This callback is invoked if
935  * the caps returned from rte_event_crypto_adapter_caps_get(, cdev_id)
936  * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set.
937  *
938  * @param dev
939  *   Event device pointer
940  *
941  * @param cdev
942  *   cryptodev pointer
943  *
944  * @param queue_pair_id
945  *   cryptodev queue pair identifier.
946  *
947  * @return
948  *   - 0: Success, cryptodev queue pair deleted successfully.
949  *   - <0: Error code returned by the driver function.
950  *
951  */
952 typedef int (*eventdev_crypto_adapter_queue_pair_del_t)
953 					(const struct rte_eventdev *dev,
954 					 const struct rte_cryptodev *cdev,
955 					 int32_t queue_pair_id);
956 
957 /**
958  * Start crypto adapter. This callback is invoked if
959  * the caps returned from rte_event_crypto_adapter_caps_get(.., cdev_id)
960  * has RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_* set and queue pairs
961  * from cdev_id have been added to the event device.
962  *
963  * @param dev
964  *   Event device pointer
965  *
966  * @param cdev
967  *   Crypto device pointer
968  *
969  * @return
970  *   - 0: Success, crypto adapter started successfully.
971  *   - <0: Error code returned by the driver function.
972  */
973 typedef int (*eventdev_crypto_adapter_start_t)
974 					(const struct rte_eventdev *dev,
975 					 const struct rte_cryptodev *cdev);
976 
977 /**
978  * Stop 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 stopped successfully.
991  *   - <0: Error code returned by the driver function.
992  */
993 typedef int (*eventdev_crypto_adapter_stop_t)
994 					(const struct rte_eventdev *dev,
995 					 const struct rte_cryptodev *cdev);
996 
997 struct rte_event_crypto_adapter_stats;
998 
999 /**
1000  * Retrieve crypto adapter statistics.
1001  *
1002  * @param dev
1003  *   Event device pointer
1004  *
1005  * @param cdev
1006  *   Crypto device pointer
1007  *
1008  * @param[out] stats
1009  *   Pointer to stats structure
1010  *
1011  * @return
1012  *   Return 0 on success.
1013  */
1014 
1015 typedef int (*eventdev_crypto_adapter_stats_get)
1016 			(const struct rte_eventdev *dev,
1017 			 const struct rte_cryptodev *cdev,
1018 			 struct rte_event_crypto_adapter_stats *stats);
1019 
1020 /**
1021  * Reset crypto adapter statistics.
1022  *
1023  * @param dev
1024  *   Event device pointer
1025  *
1026  * @param cdev
1027  *   Crypto device pointer
1028  *
1029  * @return
1030  *   Return 0 on success.
1031  */
1032 
1033 typedef int (*eventdev_crypto_adapter_stats_reset)
1034 			(const struct rte_eventdev *dev,
1035 			 const struct rte_cryptodev *cdev);
1036 
1037 /**
1038  * Retrieve the event device's eth Tx adapter capabilities.
1039  *
1040  * @param dev
1041  *   Event device pointer
1042  *
1043  * @param eth_dev
1044  *   Ethernet device pointer
1045  *
1046  * @param[out] caps
1047  *   A pointer to memory filled with eth Tx adapter capabilities.
1048  *
1049  * @return
1050  *   - 0: Success, driver provides eth Tx adapter capabilities
1051  *   - <0: Error code returned by the driver function.
1052  *
1053  */
1054 typedef int (*eventdev_eth_tx_adapter_caps_get_t)
1055 					(const struct rte_eventdev *dev,
1056 					const struct rte_eth_dev *eth_dev,
1057 					uint32_t *caps);
1058 
1059 /**
1060  * Create adapter callback.
1061  *
1062  * @param id
1063  *   Adapter identifier
1064  *
1065  * @param dev
1066  *   Event device pointer
1067  *
1068  * @return
1069  *   - 0: Success.
1070  *   - <0: Error code on failure.
1071  */
1072 typedef int (*eventdev_eth_tx_adapter_create_t)(uint8_t id,
1073 					const struct rte_eventdev *dev);
1074 
1075 /**
1076  * Free adapter callback.
1077  *
1078  * @param id
1079  *   Adapter identifier
1080  *
1081  * @param dev
1082  *   Event device pointer
1083  *
1084  * @return
1085  *   - 0: Success.
1086  *   - <0: Error code on failure.
1087  */
1088 typedef int (*eventdev_eth_tx_adapter_free_t)(uint8_t id,
1089 					const struct rte_eventdev *dev);
1090 
1091 /**
1092  * Add a Tx queue to the adapter.
1093  * A queue value of -1 is used to indicate all
1094  * queues within the device.
1095  *
1096  * @param id
1097  *   Adapter identifier
1098  *
1099  * @param dev
1100  *   Event device pointer
1101  *
1102  * @param eth_dev
1103  *   Ethernet device pointer
1104  *
1105  * @param tx_queue_id
1106  *   Transmit queue index
1107  *
1108  * @return
1109  *   - 0: Success.
1110  *   - <0: Error code on failure.
1111  */
1112 typedef int (*eventdev_eth_tx_adapter_queue_add_t)(
1113 					uint8_t id,
1114 					const struct rte_eventdev *dev,
1115 					const struct rte_eth_dev *eth_dev,
1116 					int32_t tx_queue_id);
1117 
1118 /**
1119  * Delete a Tx queue from the adapter.
1120  * A queue value of -1 is used to indicate all
1121  * queues within the device, that have been added to this
1122  * adapter.
1123  *
1124  * @param id
1125  *   Adapter identifier
1126  *
1127  * @param dev
1128  *   Event device pointer
1129  *
1130  * @param eth_dev
1131  *   Ethernet device pointer
1132  *
1133  * @param tx_queue_id
1134  *   Transmit queue index
1135  *
1136  * @return
1137  *  - 0: Success, Queues deleted successfully.
1138  *  - <0: Error code on failure.
1139  */
1140 typedef int (*eventdev_eth_tx_adapter_queue_del_t)(
1141 					uint8_t id,
1142 					const struct rte_eventdev *dev,
1143 					const struct rte_eth_dev *eth_dev,
1144 					int32_t tx_queue_id);
1145 
1146 /**
1147  * Start the adapter.
1148  *
1149  * @param id
1150  *   Adapter identifier
1151  *
1152  * @param dev
1153  *   Event device pointer
1154  *
1155  * @return
1156  *  - 0: Success, Adapter started correctly.
1157  *  - <0: Error code on failure.
1158  */
1159 typedef int (*eventdev_eth_tx_adapter_start_t)(uint8_t id,
1160 					const struct rte_eventdev *dev);
1161 
1162 /**
1163  * Stop the adapter.
1164  *
1165  * @param id
1166  *  Adapter identifier
1167  *
1168  * @param dev
1169  *   Event device pointer
1170  *
1171  * @return
1172  *  - 0: Success.
1173  *  - <0: Error code on failure.
1174  */
1175 typedef int (*eventdev_eth_tx_adapter_stop_t)(uint8_t id,
1176 					const struct rte_eventdev *dev);
1177 
1178 struct rte_event_eth_tx_adapter_stats;
1179 
1180 /**
1181  * Retrieve statistics for an adapter
1182  *
1183  * @param id
1184  *  Adapter identifier
1185  *
1186  * @param dev
1187  *   Event device pointer
1188  *
1189  * @param [out] stats
1190  *  A pointer to structure used to retrieve statistics for an adapter
1191  *
1192  * @return
1193  *  - 0: Success, statistics retrieved successfully.
1194  *  - <0: Error code on failure.
1195  */
1196 typedef int (*eventdev_eth_tx_adapter_stats_get_t)(
1197 				uint8_t id,
1198 				const struct rte_eventdev *dev,
1199 				struct rte_event_eth_tx_adapter_stats *stats);
1200 
1201 /**
1202  * Reset statistics for an adapter
1203  *
1204  * @param id
1205  *  Adapter identifier
1206  *
1207  * @param dev
1208  *   Event device pointer
1209  *
1210  * @return
1211  *  - 0: Success, statistics retrieved successfully.
1212  *  - <0: Error code on failure.
1213  */
1214 typedef int (*eventdev_eth_tx_adapter_stats_reset_t)(uint8_t id,
1215 					const struct rte_eventdev *dev);
1216 
1217 /** Event device operations function pointer table */
1218 struct eventdev_ops {
1219 	eventdev_info_get_t dev_infos_get;	/**< Get device info. */
1220 	eventdev_configure_t dev_configure;	/**< Configure device. */
1221 	eventdev_start_t dev_start;		/**< Start device. */
1222 	eventdev_stop_t dev_stop;		/**< Stop device. */
1223 	eventdev_close_t dev_close;		/**< Close device. */
1224 
1225 	eventdev_queue_default_conf_get_t queue_def_conf;
1226 	/**< Get default queue configuration. */
1227 	eventdev_queue_setup_t queue_setup;
1228 	/**< Set up an event queue. */
1229 	eventdev_queue_release_t queue_release;
1230 	/**< Release an event queue. */
1231 
1232 	eventdev_port_default_conf_get_t port_def_conf;
1233 	/**< Get default port configuration. */
1234 	eventdev_port_setup_t port_setup;
1235 	/**< Set up an event port. */
1236 	eventdev_port_release_t port_release;
1237 	/**< Release an event port. */
1238 	eventdev_port_quiesce_t port_quiesce;
1239 	/**< Quiesce an event port. */
1240 
1241 	eventdev_port_link_t port_link;
1242 	/**< Link event queues to an event port. */
1243 	eventdev_port_unlink_t port_unlink;
1244 	/**< Unlink event queues from an event port. */
1245 	eventdev_port_unlinks_in_progress_t port_unlinks_in_progress;
1246 	/**< Unlinks in progress on an event port. */
1247 	eventdev_dequeue_timeout_ticks_t timeout_ticks;
1248 	/**< Converts ns to *timeout_ticks* value for rte_event_dequeue() */
1249 	eventdev_dump_t dump;
1250 	/* Dump internal information */
1251 
1252 	eventdev_xstats_get_t xstats_get;
1253 	/**< Get extended device statistics. */
1254 	eventdev_xstats_get_names_t xstats_get_names;
1255 	/**< Get names of extended stats. */
1256 	eventdev_xstats_get_by_name xstats_get_by_name;
1257 	/**< Get one value by name. */
1258 	eventdev_xstats_reset_t xstats_reset;
1259 	/**< Reset the statistics values in xstats. */
1260 
1261 	eventdev_eth_rx_adapter_caps_get_t eth_rx_adapter_caps_get;
1262 	/**< Get ethernet Rx adapter capabilities */
1263 	eventdev_eth_rx_adapter_queue_add_t eth_rx_adapter_queue_add;
1264 	/**< Add Rx queues to ethernet Rx adapter */
1265 	eventdev_eth_rx_adapter_queue_del_t eth_rx_adapter_queue_del;
1266 	/**< Delete Rx queues from ethernet Rx adapter */
1267 	eventdev_eth_rx_adapter_queue_conf_get_t eth_rx_adapter_queue_conf_get;
1268 	/**< Get Rx adapter queue info */
1269 	eventdev_eth_rx_adapter_start_t eth_rx_adapter_start;
1270 	/**< Start ethernet Rx adapter */
1271 	eventdev_eth_rx_adapter_stop_t eth_rx_adapter_stop;
1272 	/**< Stop ethernet Rx adapter */
1273 	eventdev_eth_rx_adapter_stats_get eth_rx_adapter_stats_get;
1274 	/**< Get ethernet Rx stats */
1275 	eventdev_eth_rx_adapter_stats_reset eth_rx_adapter_stats_reset;
1276 	/**< Reset ethernet Rx stats */
1277 	eventdev_eth_rx_adapter_vector_limits_get_t
1278 		eth_rx_adapter_vector_limits_get;
1279 	/**< Get event vector limits for the Rx adapter */
1280 
1281 	eventdev_timer_adapter_caps_get_t timer_adapter_caps_get;
1282 	/**< Get timer adapter capabilities */
1283 
1284 	eventdev_crypto_adapter_caps_get_t crypto_adapter_caps_get;
1285 	/**< Get crypto adapter capabilities */
1286 	eventdev_crypto_adapter_queue_pair_add_t crypto_adapter_queue_pair_add;
1287 	/**< Add queue pair to crypto adapter */
1288 	eventdev_crypto_adapter_queue_pair_del_t crypto_adapter_queue_pair_del;
1289 	/**< Delete queue pair from crypto adapter */
1290 	eventdev_crypto_adapter_start_t crypto_adapter_start;
1291 	/**< Start crypto adapter */
1292 	eventdev_crypto_adapter_stop_t crypto_adapter_stop;
1293 	/**< Stop crypto adapter */
1294 	eventdev_crypto_adapter_stats_get crypto_adapter_stats_get;
1295 	/**< Get crypto stats */
1296 	eventdev_crypto_adapter_stats_reset crypto_adapter_stats_reset;
1297 	/**< Reset crypto stats */
1298 
1299 	eventdev_eth_rx_adapter_q_stats_get eth_rx_adapter_queue_stats_get;
1300 	/**< Get ethernet Rx queue stats */
1301 	eventdev_eth_rx_adapter_q_stats_reset eth_rx_adapter_queue_stats_reset;
1302 	/**< Reset ethernet Rx queue stats */
1303 
1304 	eventdev_eth_tx_adapter_caps_get_t eth_tx_adapter_caps_get;
1305 	/**< Get ethernet Tx adapter capabilities */
1306 
1307 	eventdev_eth_tx_adapter_create_t eth_tx_adapter_create;
1308 	/**< Create adapter callback */
1309 	eventdev_eth_tx_adapter_free_t eth_tx_adapter_free;
1310 	/**< Free adapter callback */
1311 	eventdev_eth_tx_adapter_queue_add_t eth_tx_adapter_queue_add;
1312 	/**< Add Tx queues to the eth Tx adapter */
1313 	eventdev_eth_tx_adapter_queue_del_t eth_tx_adapter_queue_del;
1314 	/**< Delete Tx queues from the eth Tx adapter */
1315 	eventdev_eth_tx_adapter_start_t eth_tx_adapter_start;
1316 	/**< Start eth Tx adapter */
1317 	eventdev_eth_tx_adapter_stop_t eth_tx_adapter_stop;
1318 	/**< Stop eth Tx adapter */
1319 	eventdev_eth_tx_adapter_stats_get_t eth_tx_adapter_stats_get;
1320 	/**< Get eth Tx adapter statistics */
1321 	eventdev_eth_tx_adapter_stats_reset_t eth_tx_adapter_stats_reset;
1322 	/**< Reset eth Tx adapter statistics */
1323 
1324 	eventdev_selftest dev_selftest;
1325 	/**< Start eventdev Selftest */
1326 
1327 	eventdev_stop_flush_t dev_stop_flush;
1328 	/**< User-provided event flush function */
1329 };
1330 
1331 /**
1332  * Allocates a new eventdev slot for an event device and returns the pointer
1333  * to that slot for the driver to use.
1334  *
1335  * @param name
1336  *   Unique identifier name for each device
1337  * @param socket_id
1338  *   Socket to allocate resources on.
1339  * @return
1340  *   - Slot in the rte_dev_devices array for a new device;
1341  */
1342 __rte_internal
1343 struct rte_eventdev *
1344 rte_event_pmd_allocate(const char *name, int socket_id);
1345 
1346 /**
1347  * Release the specified eventdev device.
1348  *
1349  * @param eventdev
1350  * The *eventdev* pointer is the address of the *rte_eventdev* structure.
1351  * @return
1352  *   - 0 on success, negative on error
1353  */
1354 __rte_internal
1355 int
1356 rte_event_pmd_release(struct rte_eventdev *eventdev);
1357 
1358 /**
1359  *
1360  * @internal
1361  * This is the last step of device probing.
1362  * It must be called after a port is allocated and initialized successfully.
1363  *
1364  * @param eventdev
1365  *  New event device.
1366  */
1367 __rte_internal
1368 void
1369 event_dev_probing_finish(struct rte_eventdev *eventdev);
1370 
1371 /**
1372  * Reset eventdevice fastpath APIs to dummy values.
1373  *
1374  * @param fp_ops
1375  * The *fp_ops* pointer to reset.
1376  */
1377 __rte_internal
1378 void
1379 event_dev_fp_ops_reset(struct rte_event_fp_ops *fp_op);
1380 
1381 /**
1382  * Set eventdevice fastpath APIs to event device values.
1383  *
1384  * @param fp_ops
1385  * The *fp_ops* pointer to set.
1386  */
1387 __rte_internal
1388 void
1389 event_dev_fp_ops_set(struct rte_event_fp_ops *fp_ops,
1390 		     const struct rte_eventdev *dev);
1391 
1392 #ifdef __cplusplus
1393 }
1394 #endif
1395 
1396 #endif /* _RTE_EVENTDEV_PMD_H_ */
1397