xref: /f-stack/dpdk/lib/librte_bbdev/rte_bbdev.h (revision 2d9fd380)
1d30ea906Sjfb8856606 /* SPDX-License-Identifier: BSD-3-Clause
2d30ea906Sjfb8856606  * Copyright(c) 2017 Intel Corporation
3d30ea906Sjfb8856606  */
4d30ea906Sjfb8856606 
5d30ea906Sjfb8856606 #ifndef _RTE_BBDEV_H_
6d30ea906Sjfb8856606 #define _RTE_BBDEV_H_
7d30ea906Sjfb8856606 
8d30ea906Sjfb8856606 /**
9d30ea906Sjfb8856606  * @file rte_bbdev.h
10d30ea906Sjfb8856606  *
11d30ea906Sjfb8856606  * Wireless base band device abstraction APIs.
12d30ea906Sjfb8856606  *
13d30ea906Sjfb8856606  * @warning
140c6bd470Sfengbojiang  * @b EXPERIMENTAL:
150c6bd470Sfengbojiang  * All functions in this file may be changed or removed without prior notice.
16d30ea906Sjfb8856606  *
17d30ea906Sjfb8856606  * This API allows an application to discover, configure and use a device to
18d30ea906Sjfb8856606  * process operations. An asynchronous API (enqueue, followed by later dequeue)
19d30ea906Sjfb8856606  * is used for processing operations.
20d30ea906Sjfb8856606  *
21d30ea906Sjfb8856606  * The functions in this API are not thread-safe when called on the same
22d30ea906Sjfb8856606  * target object (a device, or a queue on a device), with the exception that
23d30ea906Sjfb8856606  * one thread can enqueue operations to a queue while another thread dequeues
24d30ea906Sjfb8856606  * from the same queue.
25d30ea906Sjfb8856606  */
26d30ea906Sjfb8856606 
27d30ea906Sjfb8856606 #ifdef __cplusplus
28d30ea906Sjfb8856606 extern "C" {
29d30ea906Sjfb8856606 #endif
30d30ea906Sjfb8856606 
31d30ea906Sjfb8856606 #include <stdint.h>
32d30ea906Sjfb8856606 #include <stdbool.h>
33d30ea906Sjfb8856606 #include <string.h>
34d30ea906Sjfb8856606 
35d30ea906Sjfb8856606 #include <rte_compat.h>
36d30ea906Sjfb8856606 #include <rte_bus.h>
37d30ea906Sjfb8856606 #include <rte_cpuflags.h>
38d30ea906Sjfb8856606 #include <rte_memory.h>
39d30ea906Sjfb8856606 
40d30ea906Sjfb8856606 #include "rte_bbdev_op.h"
41d30ea906Sjfb8856606 
42d30ea906Sjfb8856606 #ifndef RTE_BBDEV_MAX_DEVS
43d30ea906Sjfb8856606 #define RTE_BBDEV_MAX_DEVS 128  /**< Max number of devices */
44d30ea906Sjfb8856606 #endif
45d30ea906Sjfb8856606 
461646932aSjfb8856606 /** Flags indicate current state of BBDEV device */
47d30ea906Sjfb8856606 enum rte_bbdev_state {
48d30ea906Sjfb8856606 	RTE_BBDEV_UNUSED,
49d30ea906Sjfb8856606 	RTE_BBDEV_INITIALIZED
50d30ea906Sjfb8856606 };
51d30ea906Sjfb8856606 
52d30ea906Sjfb8856606 /**
53d30ea906Sjfb8856606  * Get the total number of devices that have been successfully initialised.
54d30ea906Sjfb8856606  *
55d30ea906Sjfb8856606  * @return
56d30ea906Sjfb8856606  *   The total number of usable devices.
57d30ea906Sjfb8856606  */
584418919fSjohnjiang __rte_experimental
594418919fSjohnjiang uint16_t
60d30ea906Sjfb8856606 rte_bbdev_count(void);
61d30ea906Sjfb8856606 
62d30ea906Sjfb8856606 /**
63d30ea906Sjfb8856606  * Check if a device is valid.
64d30ea906Sjfb8856606  *
65d30ea906Sjfb8856606  * @param dev_id
66d30ea906Sjfb8856606  *   The identifier of the device.
67d30ea906Sjfb8856606  *
68d30ea906Sjfb8856606  * @return
69d30ea906Sjfb8856606  *   true if device ID is valid and device is attached, false otherwise.
70d30ea906Sjfb8856606  */
714418919fSjohnjiang __rte_experimental
724418919fSjohnjiang bool
73d30ea906Sjfb8856606 rte_bbdev_is_valid(uint16_t dev_id);
74d30ea906Sjfb8856606 
75d30ea906Sjfb8856606 /**
76d30ea906Sjfb8856606  * Get the next enabled device.
77d30ea906Sjfb8856606  *
78d30ea906Sjfb8856606  * @param dev_id
79d30ea906Sjfb8856606  *   The current device
80d30ea906Sjfb8856606  *
81d30ea906Sjfb8856606  * @return
82d30ea906Sjfb8856606  *   - The next device, or
83d30ea906Sjfb8856606  *   - RTE_BBDEV_MAX_DEVS if none found
84d30ea906Sjfb8856606  */
854418919fSjohnjiang __rte_experimental
864418919fSjohnjiang uint16_t
87d30ea906Sjfb8856606 rte_bbdev_find_next(uint16_t dev_id);
88d30ea906Sjfb8856606 
89d30ea906Sjfb8856606 /** Iterate through all enabled devices */
90d30ea906Sjfb8856606 #define RTE_BBDEV_FOREACH(i) for (i = rte_bbdev_find_next(-1); \
91d30ea906Sjfb8856606 		i < RTE_BBDEV_MAX_DEVS; \
92d30ea906Sjfb8856606 		i = rte_bbdev_find_next(i))
93d30ea906Sjfb8856606 
94d30ea906Sjfb8856606 /**
95d30ea906Sjfb8856606  * Setup up device queues.
96d30ea906Sjfb8856606  * This function must be called on a device before setting up the queues and
97d30ea906Sjfb8856606  * starting the device. It can also be called when a device is in the stopped
98d30ea906Sjfb8856606  * state. If any device queues have been configured their configuration will be
99d30ea906Sjfb8856606  * cleared by a call to this function.
100d30ea906Sjfb8856606  *
101d30ea906Sjfb8856606  * @param dev_id
102d30ea906Sjfb8856606  *   The identifier of the device.
103d30ea906Sjfb8856606  * @param num_queues
104d30ea906Sjfb8856606  *   Number of queues to configure on device.
105d30ea906Sjfb8856606  * @param socket_id
106d30ea906Sjfb8856606  *   ID of a socket which will be used to allocate memory.
107d30ea906Sjfb8856606  *
108d30ea906Sjfb8856606  * @return
109d30ea906Sjfb8856606  *   - 0 on success
110d30ea906Sjfb8856606  *   - -ENODEV if dev_id is invalid or the device is corrupted
111d30ea906Sjfb8856606  *   - -EINVAL if num_queues is invalid, 0 or greater than maximum
112d30ea906Sjfb8856606  *   - -EBUSY if the identified device has already started
113d30ea906Sjfb8856606  *   - -ENOMEM if unable to allocate memory
114d30ea906Sjfb8856606  */
1154418919fSjohnjiang __rte_experimental
1164418919fSjohnjiang int
117d30ea906Sjfb8856606 rte_bbdev_setup_queues(uint16_t dev_id, uint16_t num_queues, int socket_id);
118d30ea906Sjfb8856606 
119d30ea906Sjfb8856606 /**
120d30ea906Sjfb8856606  * Enable interrupts.
121d30ea906Sjfb8856606  * This function may be called before starting the device to enable the
122d30ea906Sjfb8856606  * interrupts if they are available.
123d30ea906Sjfb8856606  *
124d30ea906Sjfb8856606  * @param dev_id
125d30ea906Sjfb8856606  *   The identifier of the device.
126d30ea906Sjfb8856606  *
127d30ea906Sjfb8856606  * @return
128d30ea906Sjfb8856606  *   - 0 on success
129d30ea906Sjfb8856606  *   - -ENODEV if dev_id is invalid or the device is corrupted
130d30ea906Sjfb8856606  *   - -EBUSY if the identified device has already started
131d30ea906Sjfb8856606  *   - -ENOTSUP if the interrupts are not supported by the device
132d30ea906Sjfb8856606  */
1334418919fSjohnjiang __rte_experimental
1344418919fSjohnjiang int
135d30ea906Sjfb8856606 rte_bbdev_intr_enable(uint16_t dev_id);
136d30ea906Sjfb8856606 
137d30ea906Sjfb8856606 /** Device queue configuration structure */
138d30ea906Sjfb8856606 struct rte_bbdev_queue_conf {
139d30ea906Sjfb8856606 	int socket;  /**< NUMA socket used for memory allocation */
140d30ea906Sjfb8856606 	uint32_t queue_size;  /**< Size of queue */
141d30ea906Sjfb8856606 	uint8_t priority;  /**< Queue priority */
142d30ea906Sjfb8856606 	bool deferred_start; /**< Do not start queue when device is started. */
143d30ea906Sjfb8856606 	enum rte_bbdev_op_type op_type; /**< Operation type */
144d30ea906Sjfb8856606 };
145d30ea906Sjfb8856606 
146d30ea906Sjfb8856606 /**
147d30ea906Sjfb8856606  * Configure a queue on a device.
148d30ea906Sjfb8856606  * This function can be called after device configuration, and before starting.
149d30ea906Sjfb8856606  * It can also be called when the device or the queue is in the stopped state.
150d30ea906Sjfb8856606  *
151d30ea906Sjfb8856606  * @param dev_id
152d30ea906Sjfb8856606  *   The identifier of the device.
153d30ea906Sjfb8856606  * @param queue_id
154d30ea906Sjfb8856606  *   The index of the queue.
155d30ea906Sjfb8856606  * @param conf
156d30ea906Sjfb8856606  *   The queue configuration. If NULL, a default configuration will be used.
157d30ea906Sjfb8856606  *
158d30ea906Sjfb8856606  * @return
159d30ea906Sjfb8856606  *   - 0 on success
160d30ea906Sjfb8856606  *   - EINVAL if the identified queue size or priority are invalid
161d30ea906Sjfb8856606  *   - EBUSY if the identified queue or its device have already started
162d30ea906Sjfb8856606  */
1634418919fSjohnjiang __rte_experimental
1644418919fSjohnjiang int
165d30ea906Sjfb8856606 rte_bbdev_queue_configure(uint16_t dev_id, uint16_t queue_id,
166d30ea906Sjfb8856606 		const struct rte_bbdev_queue_conf *conf);
167d30ea906Sjfb8856606 
168d30ea906Sjfb8856606 /**
169d30ea906Sjfb8856606  * Start a device.
1704418919fSjohnjiang  * This is the last step needed before enqueueing operations is possible.
171d30ea906Sjfb8856606  *
172d30ea906Sjfb8856606  * @param dev_id
173d30ea906Sjfb8856606  *   The identifier of the device.
174d30ea906Sjfb8856606  *
175d30ea906Sjfb8856606  * @return
176d30ea906Sjfb8856606  *   - 0 on success
177d30ea906Sjfb8856606  *   - negative value on failure - as returned from PMD driver
178d30ea906Sjfb8856606  */
1794418919fSjohnjiang __rte_experimental
1804418919fSjohnjiang int
181d30ea906Sjfb8856606 rte_bbdev_start(uint16_t dev_id);
182d30ea906Sjfb8856606 
183d30ea906Sjfb8856606 /**
184d30ea906Sjfb8856606  * Stop a device.
185d30ea906Sjfb8856606  * The device can be reconfigured, and restarted after being stopped.
186d30ea906Sjfb8856606  *
187d30ea906Sjfb8856606  * @param dev_id
188d30ea906Sjfb8856606  *   The identifier of the device.
189d30ea906Sjfb8856606  *
190d30ea906Sjfb8856606  * @return
191d30ea906Sjfb8856606  *   - 0 on success
192d30ea906Sjfb8856606  */
1934418919fSjohnjiang __rte_experimental
1944418919fSjohnjiang int
195d30ea906Sjfb8856606 rte_bbdev_stop(uint16_t dev_id);
196d30ea906Sjfb8856606 
197d30ea906Sjfb8856606 /**
198d30ea906Sjfb8856606  * Close a device.
199d30ea906Sjfb8856606  * The device cannot be restarted without reconfiguration!
200d30ea906Sjfb8856606  *
201d30ea906Sjfb8856606  * @param dev_id
202d30ea906Sjfb8856606  *   The identifier of the device.
203d30ea906Sjfb8856606  *
204d30ea906Sjfb8856606  * @return
205d30ea906Sjfb8856606  *   - 0 on success
206d30ea906Sjfb8856606  */
2074418919fSjohnjiang __rte_experimental
2084418919fSjohnjiang int
209d30ea906Sjfb8856606 rte_bbdev_close(uint16_t dev_id);
210d30ea906Sjfb8856606 
211d30ea906Sjfb8856606 /**
212d30ea906Sjfb8856606  * Start a specified queue on a device.
213d30ea906Sjfb8856606  * This is only needed if the queue has been stopped, or if the deferred_start
214d30ea906Sjfb8856606  * flag has been set when configuring the queue.
215d30ea906Sjfb8856606  *
216d30ea906Sjfb8856606  * @param dev_id
217d30ea906Sjfb8856606  *   The identifier of the device.
218d30ea906Sjfb8856606  * @param queue_id
219d30ea906Sjfb8856606  *   The index of the queue.
220d30ea906Sjfb8856606  *
221d30ea906Sjfb8856606  * @return
222d30ea906Sjfb8856606  *   - 0 on success
223d30ea906Sjfb8856606  *   - negative value on failure - as returned from PMD driver
224d30ea906Sjfb8856606  */
2254418919fSjohnjiang __rte_experimental
2264418919fSjohnjiang int
227d30ea906Sjfb8856606 rte_bbdev_queue_start(uint16_t dev_id, uint16_t queue_id);
228d30ea906Sjfb8856606 
229d30ea906Sjfb8856606 /**
230d30ea906Sjfb8856606  * Stop a specified queue on a device, to allow re configuration.
231d30ea906Sjfb8856606  *
232d30ea906Sjfb8856606  * @param dev_id
233d30ea906Sjfb8856606  *   The identifier of the device.
234d30ea906Sjfb8856606  * @param queue_id
235d30ea906Sjfb8856606  *   The index of the queue.
236d30ea906Sjfb8856606  *
237d30ea906Sjfb8856606  * @return
238d30ea906Sjfb8856606  *   - 0 on success
239d30ea906Sjfb8856606  *   - negative value on failure - as returned from PMD driver
240d30ea906Sjfb8856606  */
2414418919fSjohnjiang __rte_experimental
2424418919fSjohnjiang int
243d30ea906Sjfb8856606 rte_bbdev_queue_stop(uint16_t dev_id, uint16_t queue_id);
244d30ea906Sjfb8856606 
245d30ea906Sjfb8856606 /** Device statistics. */
246d30ea906Sjfb8856606 struct rte_bbdev_stats {
247d30ea906Sjfb8856606 	uint64_t enqueued_count;  /**< Count of all operations enqueued */
248d30ea906Sjfb8856606 	uint64_t dequeued_count;  /**< Count of all operations dequeued */
249d30ea906Sjfb8856606 	/** Total error count on operations enqueued */
250d30ea906Sjfb8856606 	uint64_t enqueue_err_count;
251d30ea906Sjfb8856606 	/** Total error count on operations dequeued */
252d30ea906Sjfb8856606 	uint64_t dequeue_err_count;
2534418919fSjohnjiang 	/** CPU cycles consumed by the (HW/SW) accelerator device to offload
2544418919fSjohnjiang 	 *  the enqueue request to its internal queues.
2554418919fSjohnjiang 	 *  - For a HW device this is the cycles consumed in MMIO write
2564418919fSjohnjiang 	 *  - For a SW (vdev) device, this is the processing time of the
2574418919fSjohnjiang 	 *     bbdev operation
2584418919fSjohnjiang 	 */
2594418919fSjohnjiang 	uint64_t acc_offload_cycles;
260d30ea906Sjfb8856606 };
261d30ea906Sjfb8856606 
262d30ea906Sjfb8856606 /**
263d30ea906Sjfb8856606  * Retrieve the general I/O statistics of a device.
264d30ea906Sjfb8856606  *
265d30ea906Sjfb8856606  * @param dev_id
266d30ea906Sjfb8856606  *   The identifier of the device.
267d30ea906Sjfb8856606  * @param stats
268d30ea906Sjfb8856606  *   Pointer to structure to where statistics will be copied. On error, this
269d30ea906Sjfb8856606  *   location may or may not have been modified.
270d30ea906Sjfb8856606  *
271d30ea906Sjfb8856606  * @return
272d30ea906Sjfb8856606  *   - 0 on success
273d30ea906Sjfb8856606  *   - EINVAL if invalid parameter pointer is provided
274d30ea906Sjfb8856606  */
2754418919fSjohnjiang __rte_experimental
2764418919fSjohnjiang int
277d30ea906Sjfb8856606 rte_bbdev_stats_get(uint16_t dev_id, struct rte_bbdev_stats *stats);
278d30ea906Sjfb8856606 
279d30ea906Sjfb8856606 /**
280d30ea906Sjfb8856606  * Reset the statistics of a device.
281d30ea906Sjfb8856606  *
282d30ea906Sjfb8856606  * @param dev_id
283d30ea906Sjfb8856606  *   The identifier of the device.
284d30ea906Sjfb8856606  * @return
285d30ea906Sjfb8856606  *   - 0 on success
286d30ea906Sjfb8856606  */
2874418919fSjohnjiang __rte_experimental
2884418919fSjohnjiang int
289d30ea906Sjfb8856606 rte_bbdev_stats_reset(uint16_t dev_id);
290d30ea906Sjfb8856606 
291d30ea906Sjfb8856606 /** Device information supplied by the device's driver */
292d30ea906Sjfb8856606 struct rte_bbdev_driver_info {
293d30ea906Sjfb8856606 	/** Driver name */
294d30ea906Sjfb8856606 	const char *driver_name;
295d30ea906Sjfb8856606 
296d30ea906Sjfb8856606 	/** Maximum number of queues supported by the device */
297d30ea906Sjfb8856606 	unsigned int max_num_queues;
298d30ea906Sjfb8856606 	/** Queue size limit (queue size must also be power of 2) */
299d30ea906Sjfb8856606 	uint32_t queue_size_lim;
300d30ea906Sjfb8856606 	/** Set if device off-loads operation to hardware  */
301d30ea906Sjfb8856606 	bool hardware_accelerated;
302d30ea906Sjfb8856606 	/** Max value supported by queue priority for DL */
303d30ea906Sjfb8856606 	uint8_t max_dl_queue_priority;
304d30ea906Sjfb8856606 	/** Max value supported by queue priority for UL */
305d30ea906Sjfb8856606 	uint8_t max_ul_queue_priority;
306d30ea906Sjfb8856606 	/** Set if device supports per-queue interrupts */
307d30ea906Sjfb8856606 	bool queue_intr_supported;
308d30ea906Sjfb8856606 	/** Minimum alignment of buffers, in bytes */
309d30ea906Sjfb8856606 	uint16_t min_alignment;
310*2d9fd380Sjfb8856606 	/** HARQ memory available in kB */
311*2d9fd380Sjfb8856606 	uint32_t harq_buffer_size;
312d30ea906Sjfb8856606 	/** Default queue configuration used if none is supplied  */
313d30ea906Sjfb8856606 	struct rte_bbdev_queue_conf default_queue_conf;
314d30ea906Sjfb8856606 	/** Device operation capabilities */
315d30ea906Sjfb8856606 	const struct rte_bbdev_op_cap *capabilities;
316d30ea906Sjfb8856606 	/** Device cpu_flag requirements */
317d30ea906Sjfb8856606 	const enum rte_cpu_flag_t *cpu_flag_reqs;
318d30ea906Sjfb8856606 };
319d30ea906Sjfb8856606 
320d30ea906Sjfb8856606 /** Macro used at end of bbdev PMD list */
321d30ea906Sjfb8856606 #define RTE_BBDEV_END_OF_CAPABILITIES_LIST() \
322d30ea906Sjfb8856606 	{ RTE_BBDEV_OP_NONE }
323d30ea906Sjfb8856606 
324d30ea906Sjfb8856606 /**
325d30ea906Sjfb8856606  * Device information structure used by an application to discover a devices
326d30ea906Sjfb8856606  * capabilities and current configuration
327d30ea906Sjfb8856606  */
328d30ea906Sjfb8856606 struct rte_bbdev_info {
329d30ea906Sjfb8856606 	int socket_id;  /**< NUMA socket that device is on */
330d30ea906Sjfb8856606 	const char *dev_name;  /**< Unique device name */
3314418919fSjohnjiang 	const struct rte_device *device; /**< Device Information */
332d30ea906Sjfb8856606 	uint16_t num_queues;  /**< Number of queues currently configured */
333d30ea906Sjfb8856606 	bool started;  /**< Set if device is currently started */
334d30ea906Sjfb8856606 	struct rte_bbdev_driver_info drv;  /**< Info from device driver */
335d30ea906Sjfb8856606 };
336d30ea906Sjfb8856606 
337d30ea906Sjfb8856606 /**
338d30ea906Sjfb8856606  * Retrieve information about a device.
339d30ea906Sjfb8856606  *
340d30ea906Sjfb8856606  * @param dev_id
341d30ea906Sjfb8856606  *   The identifier of the device.
342d30ea906Sjfb8856606  * @param dev_info
343d30ea906Sjfb8856606  *   Pointer to structure to where information will be copied. On error, this
344d30ea906Sjfb8856606  *   location may or may not have been modified.
345d30ea906Sjfb8856606  *
346d30ea906Sjfb8856606  * @return
347d30ea906Sjfb8856606  *   - 0 on success
348d30ea906Sjfb8856606  *   - EINVAL if invalid parameter pointer is provided
349d30ea906Sjfb8856606  */
3504418919fSjohnjiang __rte_experimental
3514418919fSjohnjiang int
352d30ea906Sjfb8856606 rte_bbdev_info_get(uint16_t dev_id, struct rte_bbdev_info *dev_info);
353d30ea906Sjfb8856606 
354d30ea906Sjfb8856606 /** Queue information */
355d30ea906Sjfb8856606 struct rte_bbdev_queue_info {
356d30ea906Sjfb8856606 	/** Current device configuration */
357d30ea906Sjfb8856606 	struct rte_bbdev_queue_conf conf;
358d30ea906Sjfb8856606 	/** Set if queue is currently started */
359d30ea906Sjfb8856606 	bool started;
360d30ea906Sjfb8856606 };
361d30ea906Sjfb8856606 
362d30ea906Sjfb8856606 /**
363d30ea906Sjfb8856606  * Retrieve information about a specific queue on a device.
364d30ea906Sjfb8856606  *
365d30ea906Sjfb8856606  * @param dev_id
366d30ea906Sjfb8856606  *   The identifier of the device.
367d30ea906Sjfb8856606  * @param queue_id
368d30ea906Sjfb8856606  *   The index of the queue.
369d30ea906Sjfb8856606  * @param queue_info
370d30ea906Sjfb8856606  *   Pointer to structure to where information will be copied. On error, this
371d30ea906Sjfb8856606  *   location may or may not have been modified.
372d30ea906Sjfb8856606  *
373d30ea906Sjfb8856606  * @return
374d30ea906Sjfb8856606  *   - 0 on success
375d30ea906Sjfb8856606  *   - EINVAL if invalid parameter pointer is provided
376d30ea906Sjfb8856606  */
3774418919fSjohnjiang __rte_experimental
3784418919fSjohnjiang int
379d30ea906Sjfb8856606 rte_bbdev_queue_info_get(uint16_t dev_id, uint16_t queue_id,
380d30ea906Sjfb8856606 		struct rte_bbdev_queue_info *queue_info);
381d30ea906Sjfb8856606 
382d30ea906Sjfb8856606 /** @internal The data structure associated with each queue of a device. */
383d30ea906Sjfb8856606 struct rte_bbdev_queue_data {
384d30ea906Sjfb8856606 	void *queue_private;  /**< Driver-specific per-queue data */
385d30ea906Sjfb8856606 	struct rte_bbdev_queue_conf conf;  /**< Current configuration */
386d30ea906Sjfb8856606 	struct rte_bbdev_stats queue_stats;  /**< Queue statistics */
387d30ea906Sjfb8856606 	bool started;  /**< Queue state */
388d30ea906Sjfb8856606 };
389d30ea906Sjfb8856606 
390d30ea906Sjfb8856606 /** @internal Enqueue encode operations for processing on queue of a device. */
391d30ea906Sjfb8856606 typedef uint16_t (*rte_bbdev_enqueue_enc_ops_t)(
392d30ea906Sjfb8856606 		struct rte_bbdev_queue_data *q_data,
393d30ea906Sjfb8856606 		struct rte_bbdev_enc_op **ops,
394d30ea906Sjfb8856606 		uint16_t num);
395d30ea906Sjfb8856606 
396d30ea906Sjfb8856606 /** @internal Enqueue decode operations for processing on queue of a device. */
397d30ea906Sjfb8856606 typedef uint16_t (*rte_bbdev_enqueue_dec_ops_t)(
398d30ea906Sjfb8856606 		struct rte_bbdev_queue_data *q_data,
399d30ea906Sjfb8856606 		struct rte_bbdev_dec_op **ops,
400d30ea906Sjfb8856606 		uint16_t num);
401d30ea906Sjfb8856606 
402d30ea906Sjfb8856606 /** @internal Dequeue encode operations from a queue of a device. */
403d30ea906Sjfb8856606 typedef uint16_t (*rte_bbdev_dequeue_enc_ops_t)(
404d30ea906Sjfb8856606 		struct rte_bbdev_queue_data *q_data,
405d30ea906Sjfb8856606 		struct rte_bbdev_enc_op **ops, uint16_t num);
406d30ea906Sjfb8856606 
407d30ea906Sjfb8856606 /** @internal Dequeue decode operations from a queue of a device. */
408d30ea906Sjfb8856606 typedef uint16_t (*rte_bbdev_dequeue_dec_ops_t)(
409d30ea906Sjfb8856606 		struct rte_bbdev_queue_data *q_data,
410d30ea906Sjfb8856606 		struct rte_bbdev_dec_op **ops, uint16_t num);
411d30ea906Sjfb8856606 
412d30ea906Sjfb8856606 #define RTE_BBDEV_NAME_MAX_LEN  64  /**< Max length of device name */
413d30ea906Sjfb8856606 
414d30ea906Sjfb8856606 /**
415d30ea906Sjfb8856606  * @internal The data associated with a device, with no function pointers.
416d30ea906Sjfb8856606  * This structure is safe to place in shared memory to be common among
417d30ea906Sjfb8856606  * different processes in a multi-process configuration. Drivers can access
418d30ea906Sjfb8856606  * these fields, but should never write to them!
419d30ea906Sjfb8856606  */
420d30ea906Sjfb8856606 struct rte_bbdev_data {
421d30ea906Sjfb8856606 	char name[RTE_BBDEV_NAME_MAX_LEN]; /**< Unique identifier name */
422d30ea906Sjfb8856606 	void *dev_private;  /**< Driver-specific private data */
423d30ea906Sjfb8856606 	uint16_t num_queues;  /**< Number of currently configured queues */
424d30ea906Sjfb8856606 	struct rte_bbdev_queue_data *queues;  /**< Queue structures */
425d30ea906Sjfb8856606 	uint16_t dev_id;  /**< Device ID */
426d30ea906Sjfb8856606 	int socket_id;  /**< NUMA socket that device is on */
427d30ea906Sjfb8856606 	bool started;  /**< Device run-time state */
428*2d9fd380Sjfb8856606 	uint16_t process_cnt;  /** Counter of processes using the device */
429d30ea906Sjfb8856606 };
430d30ea906Sjfb8856606 
431d30ea906Sjfb8856606 /* Forward declarations */
432d30ea906Sjfb8856606 struct rte_bbdev_ops;
433d30ea906Sjfb8856606 struct rte_bbdev_callback;
434d30ea906Sjfb8856606 struct rte_intr_handle;
435d30ea906Sjfb8856606 
436d30ea906Sjfb8856606 /** Structure to keep track of registered callbacks */
437d30ea906Sjfb8856606 TAILQ_HEAD(rte_bbdev_cb_list, rte_bbdev_callback);
438d30ea906Sjfb8856606 
439d30ea906Sjfb8856606 /**
440d30ea906Sjfb8856606  * @internal The data structure associated with a device. Drivers can access
441d30ea906Sjfb8856606  * these fields, but should only write to the *_ops fields.
442d30ea906Sjfb8856606  */
443d30ea906Sjfb8856606 struct __rte_cache_aligned rte_bbdev {
4440c6bd470Sfengbojiang 	/** Enqueue encode function */
445d30ea906Sjfb8856606 	rte_bbdev_enqueue_enc_ops_t enqueue_enc_ops;
4460c6bd470Sfengbojiang 	/** Enqueue decode function */
447d30ea906Sjfb8856606 	rte_bbdev_enqueue_dec_ops_t enqueue_dec_ops;
4480c6bd470Sfengbojiang 	/** Dequeue encode function */
449d30ea906Sjfb8856606 	rte_bbdev_dequeue_enc_ops_t dequeue_enc_ops;
4500c6bd470Sfengbojiang 	/** Dequeue decode function */
451d30ea906Sjfb8856606 	rte_bbdev_dequeue_dec_ops_t dequeue_dec_ops;
4520c6bd470Sfengbojiang 	/** Enqueue encode function */
4534418919fSjohnjiang 	rte_bbdev_enqueue_enc_ops_t enqueue_ldpc_enc_ops;
4540c6bd470Sfengbojiang 	/** Enqueue decode function */
4554418919fSjohnjiang 	rte_bbdev_enqueue_dec_ops_t enqueue_ldpc_dec_ops;
4560c6bd470Sfengbojiang 	/** Dequeue encode function */
4574418919fSjohnjiang 	rte_bbdev_dequeue_enc_ops_t dequeue_ldpc_enc_ops;
4580c6bd470Sfengbojiang 	/** Dequeue decode function */
4594418919fSjohnjiang 	rte_bbdev_dequeue_dec_ops_t dequeue_ldpc_dec_ops;
460d30ea906Sjfb8856606 	const struct rte_bbdev_ops *dev_ops;  /**< Functions exported by PMD */
461d30ea906Sjfb8856606 	struct rte_bbdev_data *data;  /**< Pointer to device data */
462d30ea906Sjfb8856606 	enum rte_bbdev_state state;  /**< If device is currently used or not */
463d30ea906Sjfb8856606 	struct rte_device *device; /**< Backing device */
464d30ea906Sjfb8856606 	/** User application callback for interrupts if present */
465d30ea906Sjfb8856606 	struct rte_bbdev_cb_list list_cbs;
466d30ea906Sjfb8856606 	struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
467d30ea906Sjfb8856606 };
468d30ea906Sjfb8856606 
469d30ea906Sjfb8856606 /** @internal array of all devices */
470d30ea906Sjfb8856606 extern struct rte_bbdev rte_bbdev_devices[];
471d30ea906Sjfb8856606 
472d30ea906Sjfb8856606 /**
473d30ea906Sjfb8856606  * Enqueue a burst of processed encode operations to a queue of the device.
474d30ea906Sjfb8856606  * This functions only enqueues as many operations as currently possible and
475d30ea906Sjfb8856606  * does not block until @p num_ops entries in the queue are available.
476d30ea906Sjfb8856606  * This function does not provide any error notification to avoid the
477d30ea906Sjfb8856606  * corresponding overhead.
478d30ea906Sjfb8856606  *
479d30ea906Sjfb8856606  * @param dev_id
480d30ea906Sjfb8856606  *   The identifier of the device.
481d30ea906Sjfb8856606  * @param queue_id
482d30ea906Sjfb8856606  *   The index of the queue.
483d30ea906Sjfb8856606  * @param ops
484d30ea906Sjfb8856606  *   Pointer array containing operations to be enqueued Must have at least
485d30ea906Sjfb8856606  *   @p num_ops entries
486d30ea906Sjfb8856606  * @param num_ops
487d30ea906Sjfb8856606  *   The maximum number of operations to enqueue.
488d30ea906Sjfb8856606  *
489d30ea906Sjfb8856606  * @return
490d30ea906Sjfb8856606  *   The number of operations actually enqueued (this is the number of processed
491d30ea906Sjfb8856606  *   entries in the @p ops array).
492d30ea906Sjfb8856606  */
4934418919fSjohnjiang __rte_experimental
494d30ea906Sjfb8856606 static inline uint16_t
rte_bbdev_enqueue_enc_ops(uint16_t dev_id,uint16_t queue_id,struct rte_bbdev_enc_op ** ops,uint16_t num_ops)495d30ea906Sjfb8856606 rte_bbdev_enqueue_enc_ops(uint16_t dev_id, uint16_t queue_id,
496d30ea906Sjfb8856606 		struct rte_bbdev_enc_op **ops, uint16_t num_ops)
497d30ea906Sjfb8856606 {
498d30ea906Sjfb8856606 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
499d30ea906Sjfb8856606 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
500d30ea906Sjfb8856606 	return dev->enqueue_enc_ops(q_data, ops, num_ops);
501d30ea906Sjfb8856606 }
502d30ea906Sjfb8856606 
503d30ea906Sjfb8856606 /**
504d30ea906Sjfb8856606  * Enqueue a burst of processed decode operations to a queue of the device.
505d30ea906Sjfb8856606  * This functions only enqueues as many operations as currently possible and
506d30ea906Sjfb8856606  * does not block until @p num_ops entries in the queue are available.
507d30ea906Sjfb8856606  * This function does not provide any error notification to avoid the
508d30ea906Sjfb8856606  * corresponding overhead.
509d30ea906Sjfb8856606  *
510d30ea906Sjfb8856606  * @param dev_id
511d30ea906Sjfb8856606  *   The identifier of the device.
512d30ea906Sjfb8856606  * @param queue_id
513d30ea906Sjfb8856606  *   The index of the queue.
514d30ea906Sjfb8856606  * @param ops
515d30ea906Sjfb8856606  *   Pointer array containing operations to be enqueued Must have at least
516d30ea906Sjfb8856606  *   @p num_ops entries
517d30ea906Sjfb8856606  * @param num_ops
518d30ea906Sjfb8856606  *   The maximum number of operations to enqueue.
519d30ea906Sjfb8856606  *
520d30ea906Sjfb8856606  * @return
521d30ea906Sjfb8856606  *   The number of operations actually enqueued (this is the number of processed
522d30ea906Sjfb8856606  *   entries in the @p ops array).
523d30ea906Sjfb8856606  */
5244418919fSjohnjiang __rte_experimental
525d30ea906Sjfb8856606 static inline uint16_t
rte_bbdev_enqueue_dec_ops(uint16_t dev_id,uint16_t queue_id,struct rte_bbdev_dec_op ** ops,uint16_t num_ops)526d30ea906Sjfb8856606 rte_bbdev_enqueue_dec_ops(uint16_t dev_id, uint16_t queue_id,
527d30ea906Sjfb8856606 		struct rte_bbdev_dec_op **ops, uint16_t num_ops)
528d30ea906Sjfb8856606 {
529d30ea906Sjfb8856606 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
530d30ea906Sjfb8856606 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
531d30ea906Sjfb8856606 	return dev->enqueue_dec_ops(q_data, ops, num_ops);
532d30ea906Sjfb8856606 }
533d30ea906Sjfb8856606 
534d30ea906Sjfb8856606 /**
5354418919fSjohnjiang  * Enqueue a burst of processed encode operations to a queue of the device.
5364418919fSjohnjiang  * This functions only enqueues as many operations as currently possible and
5374418919fSjohnjiang  * does not block until @p num_ops entries in the queue are available.
5384418919fSjohnjiang  * This function does not provide any error notification to avoid the
5394418919fSjohnjiang  * corresponding overhead.
5404418919fSjohnjiang  *
5414418919fSjohnjiang  * @param dev_id
5424418919fSjohnjiang  *   The identifier of the device.
5434418919fSjohnjiang  * @param queue_id
5444418919fSjohnjiang  *   The index of the queue.
5454418919fSjohnjiang  * @param ops
5464418919fSjohnjiang  *   Pointer array containing operations to be enqueued Must have at least
5474418919fSjohnjiang  *   @p num_ops entries
5484418919fSjohnjiang  * @param num_ops
5494418919fSjohnjiang  *   The maximum number of operations to enqueue.
5504418919fSjohnjiang  *
5514418919fSjohnjiang  * @return
5524418919fSjohnjiang  *   The number of operations actually enqueued (this is the number of processed
5534418919fSjohnjiang  *   entries in the @p ops array).
5544418919fSjohnjiang  */
5554418919fSjohnjiang __rte_experimental
5564418919fSjohnjiang static inline uint16_t
rte_bbdev_enqueue_ldpc_enc_ops(uint16_t dev_id,uint16_t queue_id,struct rte_bbdev_enc_op ** ops,uint16_t num_ops)5574418919fSjohnjiang rte_bbdev_enqueue_ldpc_enc_ops(uint16_t dev_id, uint16_t queue_id,
5584418919fSjohnjiang 		struct rte_bbdev_enc_op **ops, uint16_t num_ops)
5594418919fSjohnjiang {
5604418919fSjohnjiang 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
5614418919fSjohnjiang 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
5624418919fSjohnjiang 	return dev->enqueue_ldpc_enc_ops(q_data, ops, num_ops);
5634418919fSjohnjiang }
5644418919fSjohnjiang 
5654418919fSjohnjiang /**
5664418919fSjohnjiang  * Enqueue a burst of processed decode operations to a queue of the device.
5674418919fSjohnjiang  * This functions only enqueues as many operations as currently possible and
5684418919fSjohnjiang  * does not block until @p num_ops entries in the queue are available.
5694418919fSjohnjiang  * This function does not provide any error notification to avoid the
5704418919fSjohnjiang  * corresponding overhead.
5714418919fSjohnjiang  *
5724418919fSjohnjiang  * @param dev_id
5734418919fSjohnjiang  *   The identifier of the device.
5744418919fSjohnjiang  * @param queue_id
5754418919fSjohnjiang  *   The index of the queue.
5764418919fSjohnjiang  * @param ops
5774418919fSjohnjiang  *   Pointer array containing operations to be enqueued Must have at least
5784418919fSjohnjiang  *   @p num_ops entries
5794418919fSjohnjiang  * @param num_ops
5804418919fSjohnjiang  *   The maximum number of operations to enqueue.
5814418919fSjohnjiang  *
5824418919fSjohnjiang  * @return
5834418919fSjohnjiang  *   The number of operations actually enqueued (this is the number of processed
5844418919fSjohnjiang  *   entries in the @p ops array).
5854418919fSjohnjiang  */
5864418919fSjohnjiang __rte_experimental
5874418919fSjohnjiang static inline uint16_t
rte_bbdev_enqueue_ldpc_dec_ops(uint16_t dev_id,uint16_t queue_id,struct rte_bbdev_dec_op ** ops,uint16_t num_ops)5884418919fSjohnjiang rte_bbdev_enqueue_ldpc_dec_ops(uint16_t dev_id, uint16_t queue_id,
5894418919fSjohnjiang 		struct rte_bbdev_dec_op **ops, uint16_t num_ops)
5904418919fSjohnjiang {
5914418919fSjohnjiang 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
5924418919fSjohnjiang 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
5934418919fSjohnjiang 	return dev->enqueue_ldpc_dec_ops(q_data, ops, num_ops);
5944418919fSjohnjiang }
5954418919fSjohnjiang 
5964418919fSjohnjiang 
5974418919fSjohnjiang /**
598d30ea906Sjfb8856606  * Dequeue a burst of processed encode operations from a queue of the device.
599d30ea906Sjfb8856606  * This functions returns only the current contents of the queue, and does not
600d30ea906Sjfb8856606  * block until @ num_ops is available.
601d30ea906Sjfb8856606  * This function does not provide any error notification to avoid the
602d30ea906Sjfb8856606  * corresponding overhead.
603d30ea906Sjfb8856606  *
604d30ea906Sjfb8856606  * @param dev_id
605d30ea906Sjfb8856606  *   The identifier of the device.
606d30ea906Sjfb8856606  * @param queue_id
607d30ea906Sjfb8856606  *   The index of the queue.
608d30ea906Sjfb8856606  * @param ops
609d30ea906Sjfb8856606  *   Pointer array where operations will be dequeued to. Must have at least
610d30ea906Sjfb8856606  *   @p num_ops entries
611*2d9fd380Sjfb8856606  *   ie. A pointer to a table of void * pointers (ops) that will be filled.
612d30ea906Sjfb8856606  * @param num_ops
613d30ea906Sjfb8856606  *   The maximum number of operations to dequeue.
614d30ea906Sjfb8856606  *
615d30ea906Sjfb8856606  * @return
616d30ea906Sjfb8856606  *   The number of operations actually dequeued (this is the number of entries
617d30ea906Sjfb8856606  *   copied into the @p ops array).
618d30ea906Sjfb8856606  */
6194418919fSjohnjiang __rte_experimental
620d30ea906Sjfb8856606 static inline uint16_t
rte_bbdev_dequeue_enc_ops(uint16_t dev_id,uint16_t queue_id,struct rte_bbdev_enc_op ** ops,uint16_t num_ops)621d30ea906Sjfb8856606 rte_bbdev_dequeue_enc_ops(uint16_t dev_id, uint16_t queue_id,
622d30ea906Sjfb8856606 		struct rte_bbdev_enc_op **ops, uint16_t num_ops)
623d30ea906Sjfb8856606 {
624d30ea906Sjfb8856606 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
625d30ea906Sjfb8856606 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
626d30ea906Sjfb8856606 	return dev->dequeue_enc_ops(q_data, ops, num_ops);
627d30ea906Sjfb8856606 }
628d30ea906Sjfb8856606 
629d30ea906Sjfb8856606 /**
630d30ea906Sjfb8856606  * Dequeue a burst of processed decode operations from a queue of the device.
631d30ea906Sjfb8856606  * This functions returns only the current contents of the queue, and does not
632d30ea906Sjfb8856606  * block until @ num_ops is available.
633d30ea906Sjfb8856606  * This function does not provide any error notification to avoid the
634d30ea906Sjfb8856606  * corresponding overhead.
635d30ea906Sjfb8856606  *
636d30ea906Sjfb8856606  * @param dev_id
637d30ea906Sjfb8856606  *   The identifier of the device.
638d30ea906Sjfb8856606  * @param queue_id
639d30ea906Sjfb8856606  *   The index of the queue.
640d30ea906Sjfb8856606  * @param ops
641d30ea906Sjfb8856606  *   Pointer array where operations will be dequeued to. Must have at least
642d30ea906Sjfb8856606  *   @p num_ops entries
643*2d9fd380Sjfb8856606  *   ie. A pointer to a table of void * pointers (ops) that will be filled.
644d30ea906Sjfb8856606  * @param num_ops
645d30ea906Sjfb8856606  *   The maximum number of operations to dequeue.
646d30ea906Sjfb8856606  *
647d30ea906Sjfb8856606  * @return
648d30ea906Sjfb8856606  *   The number of operations actually dequeued (this is the number of entries
649d30ea906Sjfb8856606  *   copied into the @p ops array).
650d30ea906Sjfb8856606  */
651d30ea906Sjfb8856606 
6524418919fSjohnjiang __rte_experimental
653d30ea906Sjfb8856606 static inline uint16_t
rte_bbdev_dequeue_dec_ops(uint16_t dev_id,uint16_t queue_id,struct rte_bbdev_dec_op ** ops,uint16_t num_ops)654d30ea906Sjfb8856606 rte_bbdev_dequeue_dec_ops(uint16_t dev_id, uint16_t queue_id,
655d30ea906Sjfb8856606 		struct rte_bbdev_dec_op **ops, uint16_t num_ops)
656d30ea906Sjfb8856606 {
657d30ea906Sjfb8856606 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
658d30ea906Sjfb8856606 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
659d30ea906Sjfb8856606 	return dev->dequeue_dec_ops(q_data, ops, num_ops);
660d30ea906Sjfb8856606 }
661d30ea906Sjfb8856606 
6624418919fSjohnjiang 
6634418919fSjohnjiang /**
6644418919fSjohnjiang  * Dequeue a burst of processed encode operations from a queue of the device.
6654418919fSjohnjiang  * This functions returns only the current contents of the queue, and does not
6664418919fSjohnjiang  * block until @ num_ops is available.
6674418919fSjohnjiang  * This function does not provide any error notification to avoid the
6684418919fSjohnjiang  * corresponding overhead.
6694418919fSjohnjiang  *
6704418919fSjohnjiang  * @param dev_id
6714418919fSjohnjiang  *   The identifier of the device.
6724418919fSjohnjiang  * @param queue_id
6734418919fSjohnjiang  *   The index of the queue.
6744418919fSjohnjiang  * @param ops
6754418919fSjohnjiang  *   Pointer array where operations will be dequeued to. Must have at least
6764418919fSjohnjiang  *   @p num_ops entries
6774418919fSjohnjiang  * @param num_ops
6784418919fSjohnjiang  *   The maximum number of operations to dequeue.
6794418919fSjohnjiang  *
6804418919fSjohnjiang  * @return
6814418919fSjohnjiang  *   The number of operations actually dequeued (this is the number of entries
6824418919fSjohnjiang  *   copied into the @p ops array).
6834418919fSjohnjiang  */
6844418919fSjohnjiang __rte_experimental
6854418919fSjohnjiang static inline uint16_t
rte_bbdev_dequeue_ldpc_enc_ops(uint16_t dev_id,uint16_t queue_id,struct rte_bbdev_enc_op ** ops,uint16_t num_ops)6864418919fSjohnjiang rte_bbdev_dequeue_ldpc_enc_ops(uint16_t dev_id, uint16_t queue_id,
6874418919fSjohnjiang 		struct rte_bbdev_enc_op **ops, uint16_t num_ops)
6884418919fSjohnjiang {
6894418919fSjohnjiang 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
6904418919fSjohnjiang 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
6914418919fSjohnjiang 	return dev->dequeue_ldpc_enc_ops(q_data, ops, num_ops);
6924418919fSjohnjiang }
6934418919fSjohnjiang 
6944418919fSjohnjiang /**
6954418919fSjohnjiang  * Dequeue a burst of processed decode operations from a queue of the device.
6964418919fSjohnjiang  * This functions returns only the current contents of the queue, and does not
6974418919fSjohnjiang  * block until @ num_ops is available.
6984418919fSjohnjiang  * This function does not provide any error notification to avoid the
6994418919fSjohnjiang  * corresponding overhead.
7004418919fSjohnjiang  *
7014418919fSjohnjiang  * @param dev_id
7024418919fSjohnjiang  *   The identifier of the device.
7034418919fSjohnjiang  * @param queue_id
7044418919fSjohnjiang  *   The index of the queue.
7054418919fSjohnjiang  * @param ops
7064418919fSjohnjiang  *   Pointer array where operations will be dequeued to. Must have at least
7074418919fSjohnjiang  *   @p num_ops entries
7084418919fSjohnjiang  * @param num_ops
7094418919fSjohnjiang  *   The maximum number of operations to dequeue.
7104418919fSjohnjiang  *
7114418919fSjohnjiang  * @return
7124418919fSjohnjiang  *   The number of operations actually dequeued (this is the number of entries
7134418919fSjohnjiang  *   copied into the @p ops array).
7144418919fSjohnjiang  */
7154418919fSjohnjiang __rte_experimental
7164418919fSjohnjiang static inline uint16_t
rte_bbdev_dequeue_ldpc_dec_ops(uint16_t dev_id,uint16_t queue_id,struct rte_bbdev_dec_op ** ops,uint16_t num_ops)7174418919fSjohnjiang rte_bbdev_dequeue_ldpc_dec_ops(uint16_t dev_id, uint16_t queue_id,
7184418919fSjohnjiang 		struct rte_bbdev_dec_op **ops, uint16_t num_ops)
7194418919fSjohnjiang {
7204418919fSjohnjiang 	struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
7214418919fSjohnjiang 	struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
7224418919fSjohnjiang 	return dev->dequeue_ldpc_dec_ops(q_data, ops, num_ops);
7234418919fSjohnjiang }
7244418919fSjohnjiang 
725d30ea906Sjfb8856606 /** Definitions of device event types */
726d30ea906Sjfb8856606 enum rte_bbdev_event_type {
727d30ea906Sjfb8856606 	RTE_BBDEV_EVENT_UNKNOWN,  /**< unknown event type */
728d30ea906Sjfb8856606 	RTE_BBDEV_EVENT_ERROR,  /**< error interrupt event */
729d30ea906Sjfb8856606 	RTE_BBDEV_EVENT_DEQUEUE,  /**< dequeue event */
730d30ea906Sjfb8856606 	RTE_BBDEV_EVENT_MAX  /**< max value of this enum */
731d30ea906Sjfb8856606 };
732d30ea906Sjfb8856606 
733d30ea906Sjfb8856606 /**
734d30ea906Sjfb8856606  * Typedef for application callback function registered by application
735d30ea906Sjfb8856606  * software for notification of device events
736d30ea906Sjfb8856606  *
737d30ea906Sjfb8856606  * @param dev_id
738d30ea906Sjfb8856606  *   Device identifier
739d30ea906Sjfb8856606  * @param event
740d30ea906Sjfb8856606  *   Device event to register for notification of.
741d30ea906Sjfb8856606  * @param cb_arg
742d30ea906Sjfb8856606  *   User specified parameter to be passed to user's callback function.
743d30ea906Sjfb8856606  * @param ret_param
744d30ea906Sjfb8856606  *   To pass data back to user application.
745d30ea906Sjfb8856606  */
746d30ea906Sjfb8856606 typedef void (*rte_bbdev_cb_fn)(uint16_t dev_id,
747d30ea906Sjfb8856606 		enum rte_bbdev_event_type event, void *cb_arg,
748d30ea906Sjfb8856606 		void *ret_param);
749d30ea906Sjfb8856606 
750d30ea906Sjfb8856606 /**
751d30ea906Sjfb8856606  * Register a callback function for specific device id. Multiple callbacks can
752d30ea906Sjfb8856606  * be added and will be called in the order they are added when an event is
753d30ea906Sjfb8856606  * triggered. Callbacks are called in a separate thread created by the DPDK EAL.
754d30ea906Sjfb8856606  *
755d30ea906Sjfb8856606  * @param dev_id
756d30ea906Sjfb8856606  *   Device id.
757d30ea906Sjfb8856606  * @param event
758d30ea906Sjfb8856606  *   The event that the callback will be registered for.
759d30ea906Sjfb8856606  * @param cb_fn
760d30ea906Sjfb8856606  *   User supplied callback function to be called.
761d30ea906Sjfb8856606  * @param cb_arg
762d30ea906Sjfb8856606  *   Pointer to parameter that will be passed to the callback.
763d30ea906Sjfb8856606  *
764d30ea906Sjfb8856606  * @return
765d30ea906Sjfb8856606  *   Zero on success, negative value on failure.
766d30ea906Sjfb8856606  */
7674418919fSjohnjiang __rte_experimental
7684418919fSjohnjiang int
769d30ea906Sjfb8856606 rte_bbdev_callback_register(uint16_t dev_id, enum rte_bbdev_event_type event,
770d30ea906Sjfb8856606 		rte_bbdev_cb_fn cb_fn, void *cb_arg);
771d30ea906Sjfb8856606 
772d30ea906Sjfb8856606 /**
773d30ea906Sjfb8856606  * Unregister a callback function for specific device id.
774d30ea906Sjfb8856606  *
775d30ea906Sjfb8856606  * @param dev_id
776d30ea906Sjfb8856606  *   The device identifier.
777d30ea906Sjfb8856606  * @param event
778d30ea906Sjfb8856606  *   The event that the callback will be unregistered for.
779d30ea906Sjfb8856606  * @param cb_fn
780d30ea906Sjfb8856606  *   User supplied callback function to be unregistered.
781d30ea906Sjfb8856606  * @param cb_arg
782d30ea906Sjfb8856606  *   Pointer to the parameter supplied when registering the callback.
783d30ea906Sjfb8856606  *   (void *)-1 means to remove all registered callbacks with the specified
784d30ea906Sjfb8856606  *   function address.
785d30ea906Sjfb8856606  *
786d30ea906Sjfb8856606  * @return
787d30ea906Sjfb8856606  *   - 0 on success
788d30ea906Sjfb8856606  *   - EINVAL if invalid parameter pointer is provided
789d30ea906Sjfb8856606  *   - EAGAIN if the provided callback pointer does not exist
790d30ea906Sjfb8856606  */
7914418919fSjohnjiang __rte_experimental
7924418919fSjohnjiang int
793d30ea906Sjfb8856606 rte_bbdev_callback_unregister(uint16_t dev_id, enum rte_bbdev_event_type event,
794d30ea906Sjfb8856606 		rte_bbdev_cb_fn cb_fn, void *cb_arg);
795d30ea906Sjfb8856606 
796d30ea906Sjfb8856606 /**
797d30ea906Sjfb8856606  * Enable a one-shot interrupt on the next operation enqueued to a particular
798d30ea906Sjfb8856606  * queue. The interrupt will be triggered when the operation is ready to be
799d30ea906Sjfb8856606  * dequeued. To handle the interrupt, an epoll file descriptor must be
800d30ea906Sjfb8856606  * registered using rte_bbdev_queue_intr_ctl(), and then an application
801d30ea906Sjfb8856606  * thread/lcore can wait for the interrupt using rte_epoll_wait().
802d30ea906Sjfb8856606  *
803d30ea906Sjfb8856606  * @param dev_id
804d30ea906Sjfb8856606  *   The device identifier.
805d30ea906Sjfb8856606  * @param queue_id
806d30ea906Sjfb8856606  *   The index of the queue.
807d30ea906Sjfb8856606  *
808d30ea906Sjfb8856606  * @return
809d30ea906Sjfb8856606  *   - 0 on success
810d30ea906Sjfb8856606  *   - negative value on failure - as returned from PMD driver
811d30ea906Sjfb8856606  */
8124418919fSjohnjiang __rte_experimental
8134418919fSjohnjiang int
814d30ea906Sjfb8856606 rte_bbdev_queue_intr_enable(uint16_t dev_id, uint16_t queue_id);
815d30ea906Sjfb8856606 
816d30ea906Sjfb8856606 /**
817d30ea906Sjfb8856606  * Disable a one-shot interrupt on the next operation enqueued to a particular
818d30ea906Sjfb8856606  * queue (if it has been enabled).
819d30ea906Sjfb8856606  *
820d30ea906Sjfb8856606  * @param dev_id
821d30ea906Sjfb8856606  *   The device identifier.
822d30ea906Sjfb8856606  * @param queue_id
823d30ea906Sjfb8856606  *   The index of the queue.
824d30ea906Sjfb8856606  *
825d30ea906Sjfb8856606  * @return
826d30ea906Sjfb8856606  *   - 0 on success
827d30ea906Sjfb8856606  *   - negative value on failure - as returned from PMD driver
828d30ea906Sjfb8856606  */
8294418919fSjohnjiang __rte_experimental
8304418919fSjohnjiang int
831d30ea906Sjfb8856606 rte_bbdev_queue_intr_disable(uint16_t dev_id, uint16_t queue_id);
832d30ea906Sjfb8856606 
833d30ea906Sjfb8856606 /**
834d30ea906Sjfb8856606  * Control interface for per-queue interrupts.
835d30ea906Sjfb8856606  *
836d30ea906Sjfb8856606  * @param dev_id
837d30ea906Sjfb8856606  *   The device identifier.
838d30ea906Sjfb8856606  * @param queue_id
839d30ea906Sjfb8856606  *   The index of the queue.
840d30ea906Sjfb8856606  * @param epfd
841d30ea906Sjfb8856606  *   Epoll file descriptor that will be associated with the interrupt source.
842d30ea906Sjfb8856606  *   If the special value RTE_EPOLL_PER_THREAD is provided, a per thread epoll
843d30ea906Sjfb8856606  *   file descriptor created by the EAL is used (RTE_EPOLL_PER_THREAD can also
844d30ea906Sjfb8856606  *   be used when calling rte_epoll_wait()).
845d30ea906Sjfb8856606  * @param op
846d30ea906Sjfb8856606  *   The operation be performed for the vector.RTE_INTR_EVENT_ADD or
847d30ea906Sjfb8856606  *   RTE_INTR_EVENT_DEL.
848d30ea906Sjfb8856606  * @param data
849d30ea906Sjfb8856606  *   User context, that will be returned in the epdata.data field of the
850d30ea906Sjfb8856606  *   rte_epoll_event structure filled in by rte_epoll_wait().
851d30ea906Sjfb8856606  *
852d30ea906Sjfb8856606  * @return
853d30ea906Sjfb8856606  *   - 0 on success
854d30ea906Sjfb8856606  *   - ENOTSUP if interrupts are not supported by the identified device
855d30ea906Sjfb8856606  *   - negative value on failure - as returned from PMD driver
856d30ea906Sjfb8856606  */
8574418919fSjohnjiang __rte_experimental
8584418919fSjohnjiang int
859d30ea906Sjfb8856606 rte_bbdev_queue_intr_ctl(uint16_t dev_id, uint16_t queue_id, int epfd, int op,
860d30ea906Sjfb8856606 		void *data);
861d30ea906Sjfb8856606 
862d30ea906Sjfb8856606 #ifdef __cplusplus
863d30ea906Sjfb8856606 }
864d30ea906Sjfb8856606 #endif
865d30ea906Sjfb8856606 
866d30ea906Sjfb8856606 #endif /* _RTE_BBDEV_H_ */
867