xref: /dpdk/lib/bbdev/rte_bbdev.h (revision f8dbaebb)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2017 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_BBDEV_H_
699a2dd95SBruce Richardson #define _RTE_BBDEV_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file rte_bbdev.h
1099a2dd95SBruce Richardson  *
1199a2dd95SBruce Richardson  * Wireless base band device abstraction APIs.
1299a2dd95SBruce Richardson  *
1399a2dd95SBruce Richardson  * This API allows an application to discover, configure and use a device to
1499a2dd95SBruce Richardson  * process operations. An asynchronous API (enqueue, followed by later dequeue)
1599a2dd95SBruce Richardson  * is used for processing operations.
1699a2dd95SBruce Richardson  *
1799a2dd95SBruce Richardson  * The functions in this API are not thread-safe when called on the same
1899a2dd95SBruce Richardson  * target object (a device, or a queue on a device), with the exception that
1999a2dd95SBruce Richardson  * one thread can enqueue operations to a queue while another thread dequeues
2099a2dd95SBruce Richardson  * from the same queue.
2199a2dd95SBruce Richardson  */
2299a2dd95SBruce Richardson 
2399a2dd95SBruce Richardson #ifdef __cplusplus
2499a2dd95SBruce Richardson extern "C" {
2599a2dd95SBruce Richardson #endif
2699a2dd95SBruce Richardson 
2799a2dd95SBruce Richardson #include <stdint.h>
2899a2dd95SBruce Richardson #include <stdbool.h>
2999a2dd95SBruce Richardson #include <string.h>
3099a2dd95SBruce Richardson 
3199a2dd95SBruce Richardson #include <rte_compat.h>
3299a2dd95SBruce Richardson #include <rte_bus.h>
3399a2dd95SBruce Richardson #include <rte_cpuflags.h>
3499a2dd95SBruce Richardson #include <rte_memory.h>
3599a2dd95SBruce Richardson 
3699a2dd95SBruce Richardson #include "rte_bbdev_op.h"
3799a2dd95SBruce Richardson 
3899a2dd95SBruce Richardson #ifndef RTE_BBDEV_MAX_DEVS
3999a2dd95SBruce Richardson #define RTE_BBDEV_MAX_DEVS 128  /**< Max number of devices */
4099a2dd95SBruce Richardson #endif
4199a2dd95SBruce Richardson 
4299a2dd95SBruce Richardson /** Flags indicate current state of BBDEV device */
4399a2dd95SBruce Richardson enum rte_bbdev_state {
4499a2dd95SBruce Richardson 	RTE_BBDEV_UNUSED,
4599a2dd95SBruce Richardson 	RTE_BBDEV_INITIALIZED
4699a2dd95SBruce Richardson };
4799a2dd95SBruce Richardson 
4899a2dd95SBruce Richardson /**
4999a2dd95SBruce Richardson  * Get the total number of devices that have been successfully initialised.
5099a2dd95SBruce Richardson  *
5199a2dd95SBruce Richardson  * @return
5299a2dd95SBruce Richardson  *   The total number of usable devices.
5399a2dd95SBruce Richardson  */
5499a2dd95SBruce Richardson uint16_t
5599a2dd95SBruce Richardson rte_bbdev_count(void);
5699a2dd95SBruce Richardson 
5799a2dd95SBruce Richardson /**
5899a2dd95SBruce Richardson  * Check if a device is valid.
5999a2dd95SBruce Richardson  *
6099a2dd95SBruce Richardson  * @param dev_id
6199a2dd95SBruce Richardson  *   The identifier of the device.
6299a2dd95SBruce Richardson  *
6399a2dd95SBruce Richardson  * @return
6499a2dd95SBruce Richardson  *   true if device ID is valid and device is attached, false otherwise.
6599a2dd95SBruce Richardson  */
6699a2dd95SBruce Richardson bool
6799a2dd95SBruce Richardson rte_bbdev_is_valid(uint16_t dev_id);
6899a2dd95SBruce Richardson 
6999a2dd95SBruce Richardson /**
7099a2dd95SBruce Richardson  * Get the next enabled device.
7199a2dd95SBruce Richardson  *
7299a2dd95SBruce Richardson  * @param dev_id
7399a2dd95SBruce Richardson  *   The current device
7499a2dd95SBruce Richardson  *
7599a2dd95SBruce Richardson  * @return
7699a2dd95SBruce Richardson  *   - The next device, or
7799a2dd95SBruce Richardson  *   - RTE_BBDEV_MAX_DEVS if none found
7899a2dd95SBruce Richardson  */
7999a2dd95SBruce Richardson uint16_t
8099a2dd95SBruce Richardson rte_bbdev_find_next(uint16_t dev_id);
8199a2dd95SBruce Richardson 
8299a2dd95SBruce Richardson /** Iterate through all enabled devices */
8399a2dd95SBruce Richardson #define RTE_BBDEV_FOREACH(i) for (i = rte_bbdev_find_next(-1); \
8499a2dd95SBruce Richardson 		i < RTE_BBDEV_MAX_DEVS; \
8599a2dd95SBruce Richardson 		i = rte_bbdev_find_next(i))
8699a2dd95SBruce Richardson 
8799a2dd95SBruce Richardson /**
8899a2dd95SBruce Richardson  * Setup up device queues.
8999a2dd95SBruce Richardson  * This function must be called on a device before setting up the queues and
9099a2dd95SBruce Richardson  * starting the device. It can also be called when a device is in the stopped
9199a2dd95SBruce Richardson  * state. If any device queues have been configured their configuration will be
9299a2dd95SBruce Richardson  * cleared by a call to this function.
9399a2dd95SBruce Richardson  *
9499a2dd95SBruce Richardson  * @param dev_id
9599a2dd95SBruce Richardson  *   The identifier of the device.
9699a2dd95SBruce Richardson  * @param num_queues
9799a2dd95SBruce Richardson  *   Number of queues to configure on device.
9899a2dd95SBruce Richardson  * @param socket_id
9999a2dd95SBruce Richardson  *   ID of a socket which will be used to allocate memory.
10099a2dd95SBruce Richardson  *
10199a2dd95SBruce Richardson  * @return
10299a2dd95SBruce Richardson  *   - 0 on success
10399a2dd95SBruce Richardson  *   - -ENODEV if dev_id is invalid or the device is corrupted
10499a2dd95SBruce Richardson  *   - -EINVAL if num_queues is invalid, 0 or greater than maximum
10599a2dd95SBruce Richardson  *   - -EBUSY if the identified device has already started
10699a2dd95SBruce Richardson  *   - -ENOMEM if unable to allocate memory
10799a2dd95SBruce Richardson  */
10899a2dd95SBruce Richardson int
10999a2dd95SBruce Richardson rte_bbdev_setup_queues(uint16_t dev_id, uint16_t num_queues, int socket_id);
11099a2dd95SBruce Richardson 
11199a2dd95SBruce Richardson /**
11299a2dd95SBruce Richardson  * Enable interrupts.
11399a2dd95SBruce Richardson  * This function may be called before starting the device to enable the
11499a2dd95SBruce Richardson  * interrupts if they are available.
11599a2dd95SBruce Richardson  *
11699a2dd95SBruce Richardson  * @param dev_id
11799a2dd95SBruce Richardson  *   The identifier of the device.
11899a2dd95SBruce Richardson  *
11999a2dd95SBruce Richardson  * @return
12099a2dd95SBruce Richardson  *   - 0 on success
12199a2dd95SBruce Richardson  *   - -ENODEV if dev_id is invalid or the device is corrupted
12299a2dd95SBruce Richardson  *   - -EBUSY if the identified device has already started
12399a2dd95SBruce Richardson  *   - -ENOTSUP if the interrupts are not supported by the device
12499a2dd95SBruce Richardson  */
12599a2dd95SBruce Richardson int
12699a2dd95SBruce Richardson rte_bbdev_intr_enable(uint16_t dev_id);
12799a2dd95SBruce Richardson 
12899a2dd95SBruce Richardson /** Device queue configuration structure */
12999a2dd95SBruce Richardson struct rte_bbdev_queue_conf {
13099a2dd95SBruce Richardson 	int socket;  /**< NUMA socket used for memory allocation */
13199a2dd95SBruce Richardson 	uint32_t queue_size;  /**< Size of queue */
13299a2dd95SBruce Richardson 	uint8_t priority;  /**< Queue priority */
13399a2dd95SBruce Richardson 	bool deferred_start; /**< Do not start queue when device is started. */
13499a2dd95SBruce Richardson 	enum rte_bbdev_op_type op_type; /**< Operation type */
13599a2dd95SBruce Richardson };
13699a2dd95SBruce Richardson 
13799a2dd95SBruce Richardson /**
13899a2dd95SBruce Richardson  * Configure a queue on a device.
13999a2dd95SBruce Richardson  * This function can be called after device configuration, and before starting.
14099a2dd95SBruce Richardson  * It can also be called when the device or the queue is in the stopped state.
14199a2dd95SBruce Richardson  *
14299a2dd95SBruce Richardson  * @param dev_id
14399a2dd95SBruce Richardson  *   The identifier of the device.
14499a2dd95SBruce Richardson  * @param queue_id
14599a2dd95SBruce Richardson  *   The index of the queue.
14699a2dd95SBruce Richardson  * @param conf
14799a2dd95SBruce Richardson  *   The queue configuration. If NULL, a default configuration will be used.
14899a2dd95SBruce Richardson  *
14999a2dd95SBruce Richardson  * @return
15099a2dd95SBruce Richardson  *   - 0 on success
15199a2dd95SBruce Richardson  *   - EINVAL if the identified queue size or priority are invalid
15299a2dd95SBruce Richardson  *   - EBUSY if the identified queue or its device have already started
15399a2dd95SBruce Richardson  */
15499a2dd95SBruce Richardson int
15599a2dd95SBruce Richardson rte_bbdev_queue_configure(uint16_t dev_id, uint16_t queue_id,
15699a2dd95SBruce Richardson 		const struct rte_bbdev_queue_conf *conf);
15799a2dd95SBruce Richardson 
15899a2dd95SBruce Richardson /**
15999a2dd95SBruce Richardson  * Start a device.
16099a2dd95SBruce Richardson  * This is the last step needed before enqueueing operations is possible.
16199a2dd95SBruce Richardson  *
16299a2dd95SBruce Richardson  * @param dev_id
16399a2dd95SBruce Richardson  *   The identifier of the device.
16499a2dd95SBruce Richardson  *
16599a2dd95SBruce Richardson  * @return
16699a2dd95SBruce Richardson  *   - 0 on success
167*f8dbaebbSSean Morrissey  *   - negative value on failure - as returned from PMD
16899a2dd95SBruce Richardson  */
16999a2dd95SBruce Richardson int
17099a2dd95SBruce Richardson rte_bbdev_start(uint16_t dev_id);
17199a2dd95SBruce Richardson 
17299a2dd95SBruce Richardson /**
17399a2dd95SBruce Richardson  * Stop a device.
17499a2dd95SBruce Richardson  * The device can be reconfigured, and restarted after being stopped.
17599a2dd95SBruce Richardson  *
17699a2dd95SBruce Richardson  * @param dev_id
17799a2dd95SBruce Richardson  *   The identifier of the device.
17899a2dd95SBruce Richardson  *
17999a2dd95SBruce Richardson  * @return
18099a2dd95SBruce Richardson  *   - 0 on success
18199a2dd95SBruce Richardson  */
18299a2dd95SBruce Richardson int
18399a2dd95SBruce Richardson rte_bbdev_stop(uint16_t dev_id);
18499a2dd95SBruce Richardson 
18599a2dd95SBruce Richardson /**
18699a2dd95SBruce Richardson  * Close a device.
18799a2dd95SBruce Richardson  * The device cannot be restarted without reconfiguration!
18899a2dd95SBruce Richardson  *
18999a2dd95SBruce Richardson  * @param dev_id
19099a2dd95SBruce Richardson  *   The identifier of the device.
19199a2dd95SBruce Richardson  *
19299a2dd95SBruce Richardson  * @return
19399a2dd95SBruce Richardson  *   - 0 on success
19499a2dd95SBruce Richardson  */
19599a2dd95SBruce Richardson int
19699a2dd95SBruce Richardson rte_bbdev_close(uint16_t dev_id);
19799a2dd95SBruce Richardson 
19899a2dd95SBruce Richardson /**
19999a2dd95SBruce Richardson  * Start a specified queue on a device.
20099a2dd95SBruce Richardson  * This is only needed if the queue has been stopped, or if the deferred_start
20199a2dd95SBruce Richardson  * flag has been set when configuring the queue.
20299a2dd95SBruce Richardson  *
20399a2dd95SBruce Richardson  * @param dev_id
20499a2dd95SBruce Richardson  *   The identifier of the device.
20599a2dd95SBruce Richardson  * @param queue_id
20699a2dd95SBruce Richardson  *   The index of the queue.
20799a2dd95SBruce Richardson  *
20899a2dd95SBruce Richardson  * @return
20999a2dd95SBruce Richardson  *   - 0 on success
210*f8dbaebbSSean Morrissey  *   - negative value on failure - as returned from PMD
21199a2dd95SBruce Richardson  */
21299a2dd95SBruce Richardson int
21399a2dd95SBruce Richardson rte_bbdev_queue_start(uint16_t dev_id, uint16_t queue_id);
21499a2dd95SBruce Richardson 
21599a2dd95SBruce Richardson /**
21699a2dd95SBruce Richardson  * Stop a specified queue on a device, to allow re configuration.
21799a2dd95SBruce Richardson  *
21899a2dd95SBruce Richardson  * @param dev_id
21999a2dd95SBruce Richardson  *   The identifier of the device.
22099a2dd95SBruce Richardson  * @param queue_id
22199a2dd95SBruce Richardson  *   The index of the queue.
22299a2dd95SBruce Richardson  *
22399a2dd95SBruce Richardson  * @return
22499a2dd95SBruce Richardson  *   - 0 on success
225*f8dbaebbSSean Morrissey  *   - negative value on failure - as returned from PMD
22699a2dd95SBruce Richardson  */
22799a2dd95SBruce Richardson int
22899a2dd95SBruce Richardson rte_bbdev_queue_stop(uint16_t dev_id, uint16_t queue_id);
22999a2dd95SBruce Richardson 
23099a2dd95SBruce Richardson /** Device statistics. */
23199a2dd95SBruce Richardson struct rte_bbdev_stats {
23299a2dd95SBruce Richardson 	uint64_t enqueued_count;  /**< Count of all operations enqueued */
23399a2dd95SBruce Richardson 	uint64_t dequeued_count;  /**< Count of all operations dequeued */
23499a2dd95SBruce Richardson 	/** Total error count on operations enqueued */
23599a2dd95SBruce Richardson 	uint64_t enqueue_err_count;
23699a2dd95SBruce Richardson 	/** Total error count on operations dequeued */
23799a2dd95SBruce Richardson 	uint64_t dequeue_err_count;
23899a2dd95SBruce Richardson 	/** CPU cycles consumed by the (HW/SW) accelerator device to offload
23999a2dd95SBruce Richardson 	 *  the enqueue request to its internal queues.
24099a2dd95SBruce Richardson 	 *  - For a HW device this is the cycles consumed in MMIO write
24199a2dd95SBruce Richardson 	 *  - For a SW (vdev) device, this is the processing time of the
24299a2dd95SBruce Richardson 	 *     bbdev operation
24399a2dd95SBruce Richardson 	 */
24499a2dd95SBruce Richardson 	uint64_t acc_offload_cycles;
24599a2dd95SBruce Richardson };
24699a2dd95SBruce Richardson 
24799a2dd95SBruce Richardson /**
24899a2dd95SBruce Richardson  * Retrieve the general I/O statistics of a device.
24999a2dd95SBruce Richardson  *
25099a2dd95SBruce Richardson  * @param dev_id
25199a2dd95SBruce Richardson  *   The identifier of the device.
25299a2dd95SBruce Richardson  * @param stats
25399a2dd95SBruce Richardson  *   Pointer to structure to where statistics will be copied. On error, this
25499a2dd95SBruce Richardson  *   location may or may not have been modified.
25599a2dd95SBruce Richardson  *
25699a2dd95SBruce Richardson  * @return
25799a2dd95SBruce Richardson  *   - 0 on success
25899a2dd95SBruce Richardson  *   - EINVAL if invalid parameter pointer is provided
25999a2dd95SBruce Richardson  */
26099a2dd95SBruce Richardson int
26199a2dd95SBruce Richardson rte_bbdev_stats_get(uint16_t dev_id, struct rte_bbdev_stats *stats);
26299a2dd95SBruce Richardson 
26399a2dd95SBruce Richardson /**
26499a2dd95SBruce Richardson  * Reset the statistics of a device.
26599a2dd95SBruce Richardson  *
26699a2dd95SBruce Richardson  * @param dev_id
26799a2dd95SBruce Richardson  *   The identifier of the device.
26899a2dd95SBruce Richardson  * @return
26999a2dd95SBruce Richardson  *   - 0 on success
27099a2dd95SBruce Richardson  */
27199a2dd95SBruce Richardson int
27299a2dd95SBruce Richardson rte_bbdev_stats_reset(uint16_t dev_id);
27399a2dd95SBruce Richardson 
27499a2dd95SBruce Richardson /** Device information supplied by the device's driver */
27599a2dd95SBruce Richardson struct rte_bbdev_driver_info {
27699a2dd95SBruce Richardson 	/** Driver name */
27799a2dd95SBruce Richardson 	const char *driver_name;
27899a2dd95SBruce Richardson 
27999a2dd95SBruce Richardson 	/** Maximum number of queues supported by the device */
28099a2dd95SBruce Richardson 	unsigned int max_num_queues;
28199a2dd95SBruce Richardson 	/** Queue size limit (queue size must also be power of 2) */
28299a2dd95SBruce Richardson 	uint32_t queue_size_lim;
28399a2dd95SBruce Richardson 	/** Set if device off-loads operation to hardware  */
28499a2dd95SBruce Richardson 	bool hardware_accelerated;
28599a2dd95SBruce Richardson 	/** Max value supported by queue priority for DL */
28699a2dd95SBruce Richardson 	uint8_t max_dl_queue_priority;
28799a2dd95SBruce Richardson 	/** Max value supported by queue priority for UL */
28899a2dd95SBruce Richardson 	uint8_t max_ul_queue_priority;
28999a2dd95SBruce Richardson 	/** Set if device supports per-queue interrupts */
29099a2dd95SBruce Richardson 	bool queue_intr_supported;
29199a2dd95SBruce Richardson 	/** Minimum alignment of buffers, in bytes */
29299a2dd95SBruce Richardson 	uint16_t min_alignment;
29399a2dd95SBruce Richardson 	/** HARQ memory available in kB */
29499a2dd95SBruce Richardson 	uint32_t harq_buffer_size;
295ab4e1909SNicolas Chautru 	/** Byte endianness (RTE_BIG_ENDIAN/RTE_LITTLE_ENDIAN) supported
296ab4e1909SNicolas Chautru 	 *  for input/output data
297ab4e1909SNicolas Chautru 	 */
298ab4e1909SNicolas Chautru 	uint8_t data_endianness;
29999a2dd95SBruce Richardson 	/** Default queue configuration used if none is supplied  */
30099a2dd95SBruce Richardson 	struct rte_bbdev_queue_conf default_queue_conf;
30199a2dd95SBruce Richardson 	/** Device operation capabilities */
30299a2dd95SBruce Richardson 	const struct rte_bbdev_op_cap *capabilities;
30399a2dd95SBruce Richardson 	/** Device cpu_flag requirements */
30499a2dd95SBruce Richardson 	const enum rte_cpu_flag_t *cpu_flag_reqs;
30599a2dd95SBruce Richardson };
30699a2dd95SBruce Richardson 
30799a2dd95SBruce Richardson /** Macro used at end of bbdev PMD list */
30899a2dd95SBruce Richardson #define RTE_BBDEV_END_OF_CAPABILITIES_LIST() \
30999a2dd95SBruce Richardson 	{ RTE_BBDEV_OP_NONE }
31099a2dd95SBruce Richardson 
31199a2dd95SBruce Richardson /**
31299a2dd95SBruce Richardson  * Device information structure used by an application to discover a devices
31399a2dd95SBruce Richardson  * capabilities and current configuration
31499a2dd95SBruce Richardson  */
31599a2dd95SBruce Richardson struct rte_bbdev_info {
31699a2dd95SBruce Richardson 	int socket_id;  /**< NUMA socket that device is on */
31799a2dd95SBruce Richardson 	const char *dev_name;  /**< Unique device name */
31899a2dd95SBruce Richardson 	const struct rte_device *device; /**< Device Information */
31999a2dd95SBruce Richardson 	uint16_t num_queues;  /**< Number of queues currently configured */
32099a2dd95SBruce Richardson 	bool started;  /**< Set if device is currently started */
32199a2dd95SBruce Richardson 	struct rte_bbdev_driver_info drv;  /**< Info from device driver */
32299a2dd95SBruce Richardson };
32399a2dd95SBruce Richardson 
32499a2dd95SBruce Richardson /**
32599a2dd95SBruce Richardson  * Retrieve information about a device.
32699a2dd95SBruce Richardson  *
32799a2dd95SBruce Richardson  * @param dev_id
32899a2dd95SBruce Richardson  *   The identifier of the device.
32999a2dd95SBruce Richardson  * @param dev_info
33099a2dd95SBruce Richardson  *   Pointer to structure to where information will be copied. On error, this
33199a2dd95SBruce Richardson  *   location may or may not have been modified.
33299a2dd95SBruce Richardson  *
33399a2dd95SBruce Richardson  * @return
33499a2dd95SBruce Richardson  *   - 0 on success
33599a2dd95SBruce Richardson  *   - EINVAL if invalid parameter pointer is provided
33699a2dd95SBruce Richardson  */
33799a2dd95SBruce Richardson int
33899a2dd95SBruce Richardson rte_bbdev_info_get(uint16_t dev_id, struct rte_bbdev_info *dev_info);
33999a2dd95SBruce Richardson 
34099a2dd95SBruce Richardson /** Queue information */
34199a2dd95SBruce Richardson struct rte_bbdev_queue_info {
34299a2dd95SBruce Richardson 	/** Current device configuration */
34399a2dd95SBruce Richardson 	struct rte_bbdev_queue_conf conf;
34499a2dd95SBruce Richardson 	/** Set if queue is currently started */
34599a2dd95SBruce Richardson 	bool started;
34699a2dd95SBruce Richardson };
34799a2dd95SBruce Richardson 
34899a2dd95SBruce Richardson /**
34999a2dd95SBruce Richardson  * Retrieve information about a specific queue on a device.
35099a2dd95SBruce Richardson  *
35199a2dd95SBruce Richardson  * @param dev_id
35299a2dd95SBruce Richardson  *   The identifier of the device.
35399a2dd95SBruce Richardson  * @param queue_id
35499a2dd95SBruce Richardson  *   The index of the queue.
35599a2dd95SBruce Richardson  * @param queue_info
35699a2dd95SBruce Richardson  *   Pointer to structure to where information will be copied. On error, this
35799a2dd95SBruce Richardson  *   location may or may not have been modified.
35899a2dd95SBruce Richardson  *
35999a2dd95SBruce Richardson  * @return
36099a2dd95SBruce Richardson  *   - 0 on success
36199a2dd95SBruce Richardson  *   - EINVAL if invalid parameter pointer is provided
36299a2dd95SBruce Richardson  */
36399a2dd95SBruce Richardson int
36499a2dd95SBruce Richardson rte_bbdev_queue_info_get(uint16_t dev_id, uint16_t queue_id,
36599a2dd95SBruce Richardson 		struct rte_bbdev_queue_info *queue_info);
36699a2dd95SBruce Richardson 
36799a2dd95SBruce Richardson /** @internal The data structure associated with each queue of a device. */
36899a2dd95SBruce Richardson struct rte_bbdev_queue_data {
36999a2dd95SBruce Richardson 	void *queue_private;  /**< Driver-specific per-queue data */
37099a2dd95SBruce Richardson 	struct rte_bbdev_queue_conf conf;  /**< Current configuration */
37199a2dd95SBruce Richardson 	struct rte_bbdev_stats queue_stats;  /**< Queue statistics */
37299a2dd95SBruce Richardson 	bool started;  /**< Queue state */
37399a2dd95SBruce Richardson };
37499a2dd95SBruce Richardson 
37599a2dd95SBruce Richardson /** @internal Enqueue encode operations for processing on queue of a device. */
37699a2dd95SBruce Richardson typedef uint16_t (*rte_bbdev_enqueue_enc_ops_t)(
37799a2dd95SBruce Richardson 		struct rte_bbdev_queue_data *q_data,
37899a2dd95SBruce Richardson 		struct rte_bbdev_enc_op **ops,
37999a2dd95SBruce Richardson 		uint16_t num);
38099a2dd95SBruce Richardson 
38199a2dd95SBruce Richardson /** @internal Enqueue decode operations for processing on queue of a device. */
38299a2dd95SBruce Richardson typedef uint16_t (*rte_bbdev_enqueue_dec_ops_t)(
38399a2dd95SBruce Richardson 		struct rte_bbdev_queue_data *q_data,
38499a2dd95SBruce Richardson 		struct rte_bbdev_dec_op **ops,
38599a2dd95SBruce Richardson 		uint16_t num);
38699a2dd95SBruce Richardson 
38799a2dd95SBruce Richardson /** @internal Dequeue encode operations from a queue of a device. */
38899a2dd95SBruce Richardson typedef uint16_t (*rte_bbdev_dequeue_enc_ops_t)(
38999a2dd95SBruce Richardson 		struct rte_bbdev_queue_data *q_data,
39099a2dd95SBruce Richardson 		struct rte_bbdev_enc_op **ops, uint16_t num);
39199a2dd95SBruce Richardson 
39299a2dd95SBruce Richardson /** @internal Dequeue decode operations from a queue of a device. */
39399a2dd95SBruce Richardson typedef uint16_t (*rte_bbdev_dequeue_dec_ops_t)(
39499a2dd95SBruce Richardson 		struct rte_bbdev_queue_data *q_data,
39599a2dd95SBruce Richardson 		struct rte_bbdev_dec_op **ops, uint16_t num);
39699a2dd95SBruce Richardson 
39799a2dd95SBruce Richardson #define RTE_BBDEV_NAME_MAX_LEN  64  /**< Max length of device name */
39899a2dd95SBruce Richardson 
39999a2dd95SBruce Richardson /**
40099a2dd95SBruce Richardson  * @internal The data associated with a device, with no function pointers.
40199a2dd95SBruce Richardson  * This structure is safe to place in shared memory to be common among
40299a2dd95SBruce Richardson  * different processes in a multi-process configuration. Drivers can access
40399a2dd95SBruce Richardson  * these fields, but should never write to them!
40499a2dd95SBruce Richardson  */
40599a2dd95SBruce Richardson struct rte_bbdev_data {
40699a2dd95SBruce Richardson 	char name[RTE_BBDEV_NAME_MAX_LEN]; /**< Unique identifier name */
40799a2dd95SBruce Richardson 	void *dev_private;  /**< Driver-specific private data */
40899a2dd95SBruce Richardson 	uint16_t num_queues;  /**< Number of currently configured queues */
40999a2dd95SBruce Richardson 	struct rte_bbdev_queue_data *queues;  /**< Queue structures */
41099a2dd95SBruce Richardson 	uint16_t dev_id;  /**< Device ID */
41199a2dd95SBruce Richardson 	int socket_id;  /**< NUMA socket that device is on */
41299a2dd95SBruce Richardson 	bool started;  /**< Device run-time state */
41399a2dd95SBruce Richardson 	uint16_t process_cnt;  /** Counter of processes using the device */
41499a2dd95SBruce Richardson };
41599a2dd95SBruce Richardson 
41699a2dd95SBruce Richardson /* Forward declarations */
41799a2dd95SBruce Richardson struct rte_bbdev_ops;
41899a2dd95SBruce Richardson struct rte_bbdev_callback;
41999a2dd95SBruce Richardson struct rte_intr_handle;
42099a2dd95SBruce Richardson 
42199a2dd95SBruce Richardson /** Structure to keep track of registered callbacks */
422f1f6ebc0SWilliam Tu RTE_TAILQ_HEAD(rte_bbdev_cb_list, rte_bbdev_callback);
42399a2dd95SBruce Richardson 
42499a2dd95SBruce Richardson /**
42599a2dd95SBruce Richardson  * @internal The data structure associated with a device. Drivers can access
42699a2dd95SBruce Richardson  * these fields, but should only write to the *_ops fields.
42799a2dd95SBruce Richardson  */
42899a2dd95SBruce Richardson struct __rte_cache_aligned rte_bbdev {
42999a2dd95SBruce Richardson 	/** Enqueue encode function */
43099a2dd95SBruce Richardson 	rte_bbdev_enqueue_enc_ops_t enqueue_enc_ops;
43199a2dd95SBruce Richardson 	/** Enqueue decode function */
43299a2dd95SBruce Richardson 	rte_bbdev_enqueue_dec_ops_t enqueue_dec_ops;
43399a2dd95SBruce Richardson 	/** Dequeue encode function */
43499a2dd95SBruce Richardson 	rte_bbdev_dequeue_enc_ops_t dequeue_enc_ops;
43599a2dd95SBruce Richardson 	/** Dequeue decode function */
43699a2dd95SBruce Richardson 	rte_bbdev_dequeue_dec_ops_t dequeue_dec_ops;
43799a2dd95SBruce Richardson 	/** Enqueue encode function */
43899a2dd95SBruce Richardson 	rte_bbdev_enqueue_enc_ops_t enqueue_ldpc_enc_ops;
43999a2dd95SBruce Richardson 	/** Enqueue decode function */
44099a2dd95SBruce Richardson 	rte_bbdev_enqueue_dec_ops_t enqueue_ldpc_dec_ops;
44199a2dd95SBruce Richardson 	/** Dequeue encode function */
44299a2dd95SBruce Richardson 	rte_bbdev_dequeue_enc_ops_t dequeue_ldpc_enc_ops;
44399a2dd95SBruce Richardson 	/** Dequeue decode function */
44499a2dd95SBruce Richardson 	rte_bbdev_dequeue_dec_ops_t dequeue_ldpc_dec_ops;
44599a2dd95SBruce Richardson 	const struct rte_bbdev_ops *dev_ops;  /**< Functions exported by PMD */
44699a2dd95SBruce Richardson 	struct rte_bbdev_data *data;  /**< Pointer to device data */
44799a2dd95SBruce Richardson 	enum rte_bbdev_state state;  /**< If device is currently used or not */
44899a2dd95SBruce Richardson 	struct rte_device *device; /**< Backing device */
44999a2dd95SBruce Richardson 	/** User application callback for interrupts if present */
45099a2dd95SBruce Richardson 	struct rte_bbdev_cb_list list_cbs;
45199a2dd95SBruce Richardson 	struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
45299a2dd95SBruce Richardson };
45399a2dd95SBruce Richardson 
45499a2dd95SBruce Richardson /** @internal array of all devices */
45599a2dd95SBruce Richardson extern struct rte_bbdev rte_bbdev_devices[];
45699a2dd95SBruce Richardson 
45799a2dd95SBruce Richardson /**
45899a2dd95SBruce Richardson  * Enqueue a burst of processed encode operations to a queue of the device.
45999a2dd95SBruce Richardson  * This functions only enqueues as many operations as currently possible and
46099a2dd95SBruce Richardson  * does not block until @p num_ops entries in the queue are available.
46199a2dd95SBruce Richardson  * This function does not provide any error notification to avoid the
46299a2dd95SBruce Richardson  * corresponding overhead.
46399a2dd95SBruce Richardson  *
46499a2dd95SBruce Richardson  * @param dev_id
46599a2dd95SBruce Richardson  *   The identifier of the device.
46699a2dd95SBruce Richardson  * @param queue_id
46799a2dd95SBruce Richardson  *   The index of the queue.
46899a2dd95SBruce Richardson  * @param ops
46999a2dd95SBruce Richardson  *   Pointer array containing operations to be enqueued Must have at least
47099a2dd95SBruce Richardson  *   @p num_ops entries
47199a2dd95SBruce Richardson  * @param num_ops
47299a2dd95SBruce Richardson  *   The maximum number of operations to enqueue.
47399a2dd95SBruce Richardson  *
47499a2dd95SBruce Richardson  * @return
47599a2dd95SBruce Richardson  *   The number of operations actually enqueued (this is the number of processed
47699a2dd95SBruce Richardson  *   entries in the @p ops array).
47799a2dd95SBruce Richardson  */
47899a2dd95SBruce Richardson static inline uint16_t
47999a2dd95SBruce Richardson rte_bbdev_enqueue_enc_ops(uint16_t dev_id, uint16_t queue_id,
48099a2dd95SBruce Richardson 		struct rte_bbdev_enc_op **ops, uint16_t num_ops)
48199a2dd95SBruce Richardson {
48299a2dd95SBruce Richardson 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
48399a2dd95SBruce Richardson 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
48499a2dd95SBruce Richardson 	return dev->enqueue_enc_ops(q_data, ops, num_ops);
48599a2dd95SBruce Richardson }
48699a2dd95SBruce Richardson 
48799a2dd95SBruce Richardson /**
48899a2dd95SBruce Richardson  * Enqueue a burst of processed decode operations to a queue of the device.
48999a2dd95SBruce Richardson  * This functions only enqueues as many operations as currently possible and
49099a2dd95SBruce Richardson  * does not block until @p num_ops entries in the queue are available.
49199a2dd95SBruce Richardson  * This function does not provide any error notification to avoid the
49299a2dd95SBruce Richardson  * corresponding overhead.
49399a2dd95SBruce Richardson  *
49499a2dd95SBruce Richardson  * @param dev_id
49599a2dd95SBruce Richardson  *   The identifier of the device.
49699a2dd95SBruce Richardson  * @param queue_id
49799a2dd95SBruce Richardson  *   The index of the queue.
49899a2dd95SBruce Richardson  * @param ops
49999a2dd95SBruce Richardson  *   Pointer array containing operations to be enqueued Must have at least
50099a2dd95SBruce Richardson  *   @p num_ops entries
50199a2dd95SBruce Richardson  * @param num_ops
50299a2dd95SBruce Richardson  *   The maximum number of operations to enqueue.
50399a2dd95SBruce Richardson  *
50499a2dd95SBruce Richardson  * @return
50599a2dd95SBruce Richardson  *   The number of operations actually enqueued (this is the number of processed
50699a2dd95SBruce Richardson  *   entries in the @p ops array).
50799a2dd95SBruce Richardson  */
50899a2dd95SBruce Richardson static inline uint16_t
50999a2dd95SBruce Richardson rte_bbdev_enqueue_dec_ops(uint16_t dev_id, uint16_t queue_id,
51099a2dd95SBruce Richardson 		struct rte_bbdev_dec_op **ops, uint16_t num_ops)
51199a2dd95SBruce Richardson {
51299a2dd95SBruce Richardson 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
51399a2dd95SBruce Richardson 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
51499a2dd95SBruce Richardson 	return dev->enqueue_dec_ops(q_data, ops, num_ops);
51599a2dd95SBruce Richardson }
51699a2dd95SBruce Richardson 
51799a2dd95SBruce Richardson /**
51899a2dd95SBruce Richardson  * Enqueue a burst of processed encode operations to a queue of the device.
51999a2dd95SBruce Richardson  * This functions only enqueues as many operations as currently possible and
52099a2dd95SBruce Richardson  * does not block until @p num_ops entries in the queue are available.
52199a2dd95SBruce Richardson  * This function does not provide any error notification to avoid the
52299a2dd95SBruce Richardson  * corresponding overhead.
52399a2dd95SBruce Richardson  *
52499a2dd95SBruce Richardson  * @param dev_id
52599a2dd95SBruce Richardson  *   The identifier of the device.
52699a2dd95SBruce Richardson  * @param queue_id
52799a2dd95SBruce Richardson  *   The index of the queue.
52899a2dd95SBruce Richardson  * @param ops
52999a2dd95SBruce Richardson  *   Pointer array containing operations to be enqueued Must have at least
53099a2dd95SBruce Richardson  *   @p num_ops entries
53199a2dd95SBruce Richardson  * @param num_ops
53299a2dd95SBruce Richardson  *   The maximum number of operations to enqueue.
53399a2dd95SBruce Richardson  *
53499a2dd95SBruce Richardson  * @return
53599a2dd95SBruce Richardson  *   The number of operations actually enqueued (this is the number of processed
53699a2dd95SBruce Richardson  *   entries in the @p ops array).
53799a2dd95SBruce Richardson  */
53899a2dd95SBruce Richardson static inline uint16_t
53999a2dd95SBruce Richardson rte_bbdev_enqueue_ldpc_enc_ops(uint16_t dev_id, uint16_t queue_id,
54099a2dd95SBruce Richardson 		struct rte_bbdev_enc_op **ops, uint16_t num_ops)
54199a2dd95SBruce Richardson {
54299a2dd95SBruce Richardson 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
54399a2dd95SBruce Richardson 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
54499a2dd95SBruce Richardson 	return dev->enqueue_ldpc_enc_ops(q_data, ops, num_ops);
54599a2dd95SBruce Richardson }
54699a2dd95SBruce Richardson 
54799a2dd95SBruce Richardson /**
54899a2dd95SBruce Richardson  * Enqueue a burst of processed decode operations to a queue of the device.
54999a2dd95SBruce Richardson  * This functions only enqueues as many operations as currently possible and
55099a2dd95SBruce Richardson  * does not block until @p num_ops entries in the queue are available.
55199a2dd95SBruce Richardson  * This function does not provide any error notification to avoid the
55299a2dd95SBruce Richardson  * corresponding overhead.
55399a2dd95SBruce Richardson  *
55499a2dd95SBruce Richardson  * @param dev_id
55599a2dd95SBruce Richardson  *   The identifier of the device.
55699a2dd95SBruce Richardson  * @param queue_id
55799a2dd95SBruce Richardson  *   The index of the queue.
55899a2dd95SBruce Richardson  * @param ops
55999a2dd95SBruce Richardson  *   Pointer array containing operations to be enqueued Must have at least
56099a2dd95SBruce Richardson  *   @p num_ops entries
56199a2dd95SBruce Richardson  * @param num_ops
56299a2dd95SBruce Richardson  *   The maximum number of operations to enqueue.
56399a2dd95SBruce Richardson  *
56499a2dd95SBruce Richardson  * @return
56599a2dd95SBruce Richardson  *   The number of operations actually enqueued (this is the number of processed
56699a2dd95SBruce Richardson  *   entries in the @p ops array).
56799a2dd95SBruce Richardson  */
56899a2dd95SBruce Richardson static inline uint16_t
56999a2dd95SBruce Richardson rte_bbdev_enqueue_ldpc_dec_ops(uint16_t dev_id, uint16_t queue_id,
57099a2dd95SBruce Richardson 		struct rte_bbdev_dec_op **ops, uint16_t num_ops)
57199a2dd95SBruce Richardson {
57299a2dd95SBruce Richardson 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
57399a2dd95SBruce Richardson 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
57499a2dd95SBruce Richardson 	return dev->enqueue_ldpc_dec_ops(q_data, ops, num_ops);
57599a2dd95SBruce Richardson }
57699a2dd95SBruce Richardson 
57799a2dd95SBruce Richardson 
57899a2dd95SBruce Richardson /**
57999a2dd95SBruce Richardson  * Dequeue a burst of processed encode operations from a queue of the device.
58099a2dd95SBruce Richardson  * This functions returns only the current contents of the queue, and does not
58199a2dd95SBruce Richardson  * block until @ num_ops is available.
58299a2dd95SBruce Richardson  * This function does not provide any error notification to avoid the
58399a2dd95SBruce Richardson  * corresponding overhead.
58499a2dd95SBruce Richardson  *
58599a2dd95SBruce Richardson  * @param dev_id
58699a2dd95SBruce Richardson  *   The identifier of the device.
58799a2dd95SBruce Richardson  * @param queue_id
58899a2dd95SBruce Richardson  *   The index of the queue.
58999a2dd95SBruce Richardson  * @param ops
59099a2dd95SBruce Richardson  *   Pointer array where operations will be dequeued to. Must have at least
59199a2dd95SBruce Richardson  *   @p num_ops entries
59299a2dd95SBruce Richardson  *   ie. A pointer to a table of void * pointers (ops) that will be filled.
59399a2dd95SBruce Richardson  * @param num_ops
59499a2dd95SBruce Richardson  *   The maximum number of operations to dequeue.
59599a2dd95SBruce Richardson  *
59699a2dd95SBruce Richardson  * @return
59799a2dd95SBruce Richardson  *   The number of operations actually dequeued (this is the number of entries
59899a2dd95SBruce Richardson  *   copied into the @p ops array).
59999a2dd95SBruce Richardson  */
60099a2dd95SBruce Richardson static inline uint16_t
60199a2dd95SBruce Richardson rte_bbdev_dequeue_enc_ops(uint16_t dev_id, uint16_t queue_id,
60299a2dd95SBruce Richardson 		struct rte_bbdev_enc_op **ops, uint16_t num_ops)
60399a2dd95SBruce Richardson {
60499a2dd95SBruce Richardson 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
60599a2dd95SBruce Richardson 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
60699a2dd95SBruce Richardson 	return dev->dequeue_enc_ops(q_data, ops, num_ops);
60799a2dd95SBruce Richardson }
60899a2dd95SBruce Richardson 
60999a2dd95SBruce Richardson /**
61099a2dd95SBruce Richardson  * Dequeue a burst of processed decode operations from a queue of the device.
61199a2dd95SBruce Richardson  * This functions returns only the current contents of the queue, and does not
61299a2dd95SBruce Richardson  * block until @ num_ops is available.
61399a2dd95SBruce Richardson  * This function does not provide any error notification to avoid the
61499a2dd95SBruce Richardson  * corresponding overhead.
61599a2dd95SBruce Richardson  *
61699a2dd95SBruce Richardson  * @param dev_id
61799a2dd95SBruce Richardson  *   The identifier of the device.
61899a2dd95SBruce Richardson  * @param queue_id
61999a2dd95SBruce Richardson  *   The index of the queue.
62099a2dd95SBruce Richardson  * @param ops
62199a2dd95SBruce Richardson  *   Pointer array where operations will be dequeued to. Must have at least
62299a2dd95SBruce Richardson  *   @p num_ops entries
62399a2dd95SBruce Richardson  *   ie. A pointer to a table of void * pointers (ops) that will be filled.
62499a2dd95SBruce Richardson  * @param num_ops
62599a2dd95SBruce Richardson  *   The maximum number of operations to dequeue.
62699a2dd95SBruce Richardson  *
62799a2dd95SBruce Richardson  * @return
62899a2dd95SBruce Richardson  *   The number of operations actually dequeued (this is the number of entries
62999a2dd95SBruce Richardson  *   copied into the @p ops array).
63099a2dd95SBruce Richardson  */
63199a2dd95SBruce Richardson 
63299a2dd95SBruce Richardson static inline uint16_t
63399a2dd95SBruce Richardson rte_bbdev_dequeue_dec_ops(uint16_t dev_id, uint16_t queue_id,
63499a2dd95SBruce Richardson 		struct rte_bbdev_dec_op **ops, uint16_t num_ops)
63599a2dd95SBruce Richardson {
63699a2dd95SBruce Richardson 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
63799a2dd95SBruce Richardson 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
63899a2dd95SBruce Richardson 	return dev->dequeue_dec_ops(q_data, ops, num_ops);
63999a2dd95SBruce Richardson }
64099a2dd95SBruce Richardson 
64199a2dd95SBruce Richardson 
64299a2dd95SBruce Richardson /**
64399a2dd95SBruce Richardson  * Dequeue a burst of processed encode operations from a queue of the device.
64499a2dd95SBruce Richardson  * This functions returns only the current contents of the queue, and does not
64599a2dd95SBruce Richardson  * block until @ num_ops is available.
64699a2dd95SBruce Richardson  * This function does not provide any error notification to avoid the
64799a2dd95SBruce Richardson  * corresponding overhead.
64899a2dd95SBruce Richardson  *
64999a2dd95SBruce Richardson  * @param dev_id
65099a2dd95SBruce Richardson  *   The identifier of the device.
65199a2dd95SBruce Richardson  * @param queue_id
65299a2dd95SBruce Richardson  *   The index of the queue.
65399a2dd95SBruce Richardson  * @param ops
65499a2dd95SBruce Richardson  *   Pointer array where operations will be dequeued to. Must have at least
65599a2dd95SBruce Richardson  *   @p num_ops entries
65699a2dd95SBruce Richardson  * @param num_ops
65799a2dd95SBruce Richardson  *   The maximum number of operations to dequeue.
65899a2dd95SBruce Richardson  *
65999a2dd95SBruce Richardson  * @return
66099a2dd95SBruce Richardson  *   The number of operations actually dequeued (this is the number of entries
66199a2dd95SBruce Richardson  *   copied into the @p ops array).
66299a2dd95SBruce Richardson  */
66399a2dd95SBruce Richardson static inline uint16_t
66499a2dd95SBruce Richardson rte_bbdev_dequeue_ldpc_enc_ops(uint16_t dev_id, uint16_t queue_id,
66599a2dd95SBruce Richardson 		struct rte_bbdev_enc_op **ops, uint16_t num_ops)
66699a2dd95SBruce Richardson {
66799a2dd95SBruce Richardson 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
66899a2dd95SBruce Richardson 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
66999a2dd95SBruce Richardson 	return dev->dequeue_ldpc_enc_ops(q_data, ops, num_ops);
67099a2dd95SBruce Richardson }
67199a2dd95SBruce Richardson 
67299a2dd95SBruce Richardson /**
67399a2dd95SBruce Richardson  * Dequeue a burst of processed decode operations from a queue of the device.
67499a2dd95SBruce Richardson  * This functions returns only the current contents of the queue, and does not
67599a2dd95SBruce Richardson  * block until @ num_ops is available.
67699a2dd95SBruce Richardson  * This function does not provide any error notification to avoid the
67799a2dd95SBruce Richardson  * corresponding overhead.
67899a2dd95SBruce Richardson  *
67999a2dd95SBruce Richardson  * @param dev_id
68099a2dd95SBruce Richardson  *   The identifier of the device.
68199a2dd95SBruce Richardson  * @param queue_id
68299a2dd95SBruce Richardson  *   The index of the queue.
68399a2dd95SBruce Richardson  * @param ops
68499a2dd95SBruce Richardson  *   Pointer array where operations will be dequeued to. Must have at least
68599a2dd95SBruce Richardson  *   @p num_ops entries
68699a2dd95SBruce Richardson  * @param num_ops
68799a2dd95SBruce Richardson  *   The maximum number of operations to dequeue.
68899a2dd95SBruce Richardson  *
68999a2dd95SBruce Richardson  * @return
69099a2dd95SBruce Richardson  *   The number of operations actually dequeued (this is the number of entries
69199a2dd95SBruce Richardson  *   copied into the @p ops array).
69299a2dd95SBruce Richardson  */
69399a2dd95SBruce Richardson static inline uint16_t
69499a2dd95SBruce Richardson rte_bbdev_dequeue_ldpc_dec_ops(uint16_t dev_id, uint16_t queue_id,
69599a2dd95SBruce Richardson 		struct rte_bbdev_dec_op **ops, uint16_t num_ops)
69699a2dd95SBruce Richardson {
69799a2dd95SBruce Richardson 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
69899a2dd95SBruce Richardson 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
69999a2dd95SBruce Richardson 	return dev->dequeue_ldpc_dec_ops(q_data, ops, num_ops);
70099a2dd95SBruce Richardson }
70199a2dd95SBruce Richardson 
70299a2dd95SBruce Richardson /** Definitions of device event types */
70399a2dd95SBruce Richardson enum rte_bbdev_event_type {
70499a2dd95SBruce Richardson 	RTE_BBDEV_EVENT_UNKNOWN,  /**< unknown event type */
70599a2dd95SBruce Richardson 	RTE_BBDEV_EVENT_ERROR,  /**< error interrupt event */
70699a2dd95SBruce Richardson 	RTE_BBDEV_EVENT_DEQUEUE,  /**< dequeue event */
70799a2dd95SBruce Richardson 	RTE_BBDEV_EVENT_MAX  /**< max value of this enum */
70899a2dd95SBruce Richardson };
70999a2dd95SBruce Richardson 
71099a2dd95SBruce Richardson /**
71199a2dd95SBruce Richardson  * Typedef for application callback function registered by application
71299a2dd95SBruce Richardson  * software for notification of device events
71399a2dd95SBruce Richardson  *
71499a2dd95SBruce Richardson  * @param dev_id
71599a2dd95SBruce Richardson  *   Device identifier
71699a2dd95SBruce Richardson  * @param event
71799a2dd95SBruce Richardson  *   Device event to register for notification of.
71899a2dd95SBruce Richardson  * @param cb_arg
71999a2dd95SBruce Richardson  *   User specified parameter to be passed to user's callback function.
72099a2dd95SBruce Richardson  * @param ret_param
72199a2dd95SBruce Richardson  *   To pass data back to user application.
72299a2dd95SBruce Richardson  */
72399a2dd95SBruce Richardson typedef void (*rte_bbdev_cb_fn)(uint16_t dev_id,
72499a2dd95SBruce Richardson 		enum rte_bbdev_event_type event, void *cb_arg,
72599a2dd95SBruce Richardson 		void *ret_param);
72699a2dd95SBruce Richardson 
72799a2dd95SBruce Richardson /**
72899a2dd95SBruce Richardson  * Register a callback function for specific device id. Multiple callbacks can
72999a2dd95SBruce Richardson  * be added and will be called in the order they are added when an event is
73099a2dd95SBruce Richardson  * triggered. Callbacks are called in a separate thread created by the DPDK EAL.
73199a2dd95SBruce Richardson  *
73299a2dd95SBruce Richardson  * @param dev_id
73399a2dd95SBruce Richardson  *   Device id.
73499a2dd95SBruce Richardson  * @param event
73599a2dd95SBruce Richardson  *   The event that the callback will be registered for.
73699a2dd95SBruce Richardson  * @param cb_fn
73799a2dd95SBruce Richardson  *   User supplied callback function to be called.
73899a2dd95SBruce Richardson  * @param cb_arg
73999a2dd95SBruce Richardson  *   Pointer to parameter that will be passed to the callback.
74099a2dd95SBruce Richardson  *
74199a2dd95SBruce Richardson  * @return
74299a2dd95SBruce Richardson  *   Zero on success, negative value on failure.
74399a2dd95SBruce Richardson  */
74499a2dd95SBruce Richardson int
74599a2dd95SBruce Richardson rte_bbdev_callback_register(uint16_t dev_id, enum rte_bbdev_event_type event,
74699a2dd95SBruce Richardson 		rte_bbdev_cb_fn cb_fn, void *cb_arg);
74799a2dd95SBruce Richardson 
74899a2dd95SBruce Richardson /**
74999a2dd95SBruce Richardson  * Unregister a callback function for specific device id.
75099a2dd95SBruce Richardson  *
75199a2dd95SBruce Richardson  * @param dev_id
75299a2dd95SBruce Richardson  *   The device identifier.
75399a2dd95SBruce Richardson  * @param event
75499a2dd95SBruce Richardson  *   The event that the callback will be unregistered for.
75599a2dd95SBruce Richardson  * @param cb_fn
75699a2dd95SBruce Richardson  *   User supplied callback function to be unregistered.
75799a2dd95SBruce Richardson  * @param cb_arg
75899a2dd95SBruce Richardson  *   Pointer to the parameter supplied when registering the callback.
75999a2dd95SBruce Richardson  *   (void *)-1 means to remove all registered callbacks with the specified
76099a2dd95SBruce Richardson  *   function address.
76199a2dd95SBruce Richardson  *
76299a2dd95SBruce Richardson  * @return
76399a2dd95SBruce Richardson  *   - 0 on success
76499a2dd95SBruce Richardson  *   - EINVAL if invalid parameter pointer is provided
76599a2dd95SBruce Richardson  *   - EAGAIN if the provided callback pointer does not exist
76699a2dd95SBruce Richardson  */
76799a2dd95SBruce Richardson int
76899a2dd95SBruce Richardson rte_bbdev_callback_unregister(uint16_t dev_id, enum rte_bbdev_event_type event,
76999a2dd95SBruce Richardson 		rte_bbdev_cb_fn cb_fn, void *cb_arg);
77099a2dd95SBruce Richardson 
77199a2dd95SBruce Richardson /**
77299a2dd95SBruce Richardson  * Enable a one-shot interrupt on the next operation enqueued to a particular
77399a2dd95SBruce Richardson  * queue. The interrupt will be triggered when the operation is ready to be
77499a2dd95SBruce Richardson  * dequeued. To handle the interrupt, an epoll file descriptor must be
77599a2dd95SBruce Richardson  * registered using rte_bbdev_queue_intr_ctl(), and then an application
77699a2dd95SBruce Richardson  * thread/lcore can wait for the interrupt using rte_epoll_wait().
77799a2dd95SBruce Richardson  *
77899a2dd95SBruce Richardson  * @param dev_id
77999a2dd95SBruce Richardson  *   The device identifier.
78099a2dd95SBruce Richardson  * @param queue_id
78199a2dd95SBruce Richardson  *   The index of the queue.
78299a2dd95SBruce Richardson  *
78399a2dd95SBruce Richardson  * @return
78499a2dd95SBruce Richardson  *   - 0 on success
785*f8dbaebbSSean Morrissey  *   - negative value on failure - as returned from PMD
78699a2dd95SBruce Richardson  */
78799a2dd95SBruce Richardson int
78899a2dd95SBruce Richardson rte_bbdev_queue_intr_enable(uint16_t dev_id, uint16_t queue_id);
78999a2dd95SBruce Richardson 
79099a2dd95SBruce Richardson /**
79199a2dd95SBruce Richardson  * Disable a one-shot interrupt on the next operation enqueued to a particular
79299a2dd95SBruce Richardson  * queue (if it has been enabled).
79399a2dd95SBruce Richardson  *
79499a2dd95SBruce Richardson  * @param dev_id
79599a2dd95SBruce Richardson  *   The device identifier.
79699a2dd95SBruce Richardson  * @param queue_id
79799a2dd95SBruce Richardson  *   The index of the queue.
79899a2dd95SBruce Richardson  *
79999a2dd95SBruce Richardson  * @return
80099a2dd95SBruce Richardson  *   - 0 on success
801*f8dbaebbSSean Morrissey  *   - negative value on failure - as returned from PMD
80299a2dd95SBruce Richardson  */
80399a2dd95SBruce Richardson int
80499a2dd95SBruce Richardson rte_bbdev_queue_intr_disable(uint16_t dev_id, uint16_t queue_id);
80599a2dd95SBruce Richardson 
80699a2dd95SBruce Richardson /**
80799a2dd95SBruce Richardson  * Control interface for per-queue interrupts.
80899a2dd95SBruce Richardson  *
80999a2dd95SBruce Richardson  * @param dev_id
81099a2dd95SBruce Richardson  *   The device identifier.
81199a2dd95SBruce Richardson  * @param queue_id
81299a2dd95SBruce Richardson  *   The index of the queue.
81399a2dd95SBruce Richardson  * @param epfd
81499a2dd95SBruce Richardson  *   Epoll file descriptor that will be associated with the interrupt source.
81599a2dd95SBruce Richardson  *   If the special value RTE_EPOLL_PER_THREAD is provided, a per thread epoll
81699a2dd95SBruce Richardson  *   file descriptor created by the EAL is used (RTE_EPOLL_PER_THREAD can also
81799a2dd95SBruce Richardson  *   be used when calling rte_epoll_wait()).
81899a2dd95SBruce Richardson  * @param op
81999a2dd95SBruce Richardson  *   The operation be performed for the vector.RTE_INTR_EVENT_ADD or
82099a2dd95SBruce Richardson  *   RTE_INTR_EVENT_DEL.
82199a2dd95SBruce Richardson  * @param data
82299a2dd95SBruce Richardson  *   User context, that will be returned in the epdata.data field of the
82399a2dd95SBruce Richardson  *   rte_epoll_event structure filled in by rte_epoll_wait().
82499a2dd95SBruce Richardson  *
82599a2dd95SBruce Richardson  * @return
82699a2dd95SBruce Richardson  *   - 0 on success
82799a2dd95SBruce Richardson  *   - ENOTSUP if interrupts are not supported by the identified device
828*f8dbaebbSSean Morrissey  *   - negative value on failure - as returned from PMD
82999a2dd95SBruce Richardson  */
83099a2dd95SBruce Richardson int
83199a2dd95SBruce Richardson rte_bbdev_queue_intr_ctl(uint16_t dev_id, uint16_t queue_id, int epfd, int op,
83299a2dd95SBruce Richardson 		void *data);
83399a2dd95SBruce Richardson 
83499a2dd95SBruce Richardson #ifdef __cplusplus
83599a2dd95SBruce Richardson }
83699a2dd95SBruce Richardson #endif
83799a2dd95SBruce Richardson 
83899a2dd95SBruce Richardson #endif /* _RTE_BBDEV_H_ */
839