1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
11 * Wireless base band device abstraction APIs.
14 * @b EXPERIMENTAL: this API may change without prior notice
16 * This API allows an application to discover, configure and use a device to
17 * process operations. An asynchronous API (enqueue, followed by later dequeue)
18 * is used for processing operations.
20 * The functions in this API are not thread-safe when called on the same
21 * target object (a device, or a queue on a device), with the exception that
22 * one thread can enqueue operations to a queue while another thread dequeues
23 * from the same queue.
34 #include <rte_compat.h>
35 #include <rte_atomic.h>
37 #include <rte_cpuflags.h>
38 #include <rte_memory.h>
40 #include "rte_bbdev_op.h"
42 #ifndef RTE_BBDEV_MAX_DEVS
43 #define RTE_BBDEV_MAX_DEVS 128 /**< Max number of devices */
46 /** Flags indiciate current state of BBDEV device */
47 enum rte_bbdev_state {
53 * Get the total number of devices that have been successfully initialised.
56 * The total number of usable devices.
58 uint16_t __rte_experimental
59 rte_bbdev_count(void);
62 * Check if a device is valid.
65 * The identifier of the device.
68 * true if device ID is valid and device is attached, false otherwise.
70 bool __rte_experimental
71 rte_bbdev_is_valid(uint16_t dev_id);
74 * Get the next enabled device.
80 * - The next device, or
81 * - RTE_BBDEV_MAX_DEVS if none found
83 uint16_t __rte_experimental
84 rte_bbdev_find_next(uint16_t dev_id);
86 /** Iterate through all enabled devices */
87 #define RTE_BBDEV_FOREACH(i) for (i = rte_bbdev_find_next(-1); \
88 i < RTE_BBDEV_MAX_DEVS; \
89 i = rte_bbdev_find_next(i))
92 * Setup up device queues.
93 * This function must be called on a device before setting up the queues and
94 * starting the device. It can also be called when a device is in the stopped
95 * state. If any device queues have been configured their configuration will be
96 * cleared by a call to this function.
99 * The identifier of the device.
101 * Number of queues to configure on device.
103 * ID of a socket which will be used to allocate memory.
107 * - -ENODEV if dev_id is invalid or the device is corrupted
108 * - -EINVAL if num_queues is invalid, 0 or greater than maximum
109 * - -EBUSY if the identified device has already started
110 * - -ENOMEM if unable to allocate memory
112 int __rte_experimental
113 rte_bbdev_setup_queues(uint16_t dev_id, uint16_t num_queues, int socket_id);
117 * This function may be called before starting the device to enable the
118 * interrupts if they are available.
121 * The identifier of the device.
125 * - -ENODEV if dev_id is invalid or the device is corrupted
126 * - -EBUSY if the identified device has already started
127 * - -ENOTSUP if the interrupts are not supported by the device
129 int __rte_experimental
130 rte_bbdev_intr_enable(uint16_t dev_id);
132 /** Device queue configuration structure */
133 struct rte_bbdev_queue_conf {
134 int socket; /**< NUMA socket used for memory allocation */
135 uint32_t queue_size; /**< Size of queue */
136 uint8_t priority; /**< Queue priority */
137 bool deferred_start; /**< Do not start queue when device is started. */
138 enum rte_bbdev_op_type op_type; /**< Operation type */
142 * Configure a queue on a device.
143 * This function can be called after device configuration, and before starting.
144 * It can also be called when the device or the queue is in the stopped state.
147 * The identifier of the device.
149 * The index of the queue.
151 * The queue configuration. If NULL, a default configuration will be used.
155 * - EINVAL if the identified queue size or priority are invalid
156 * - EBUSY if the identified queue or its device have already started
158 int __rte_experimental
159 rte_bbdev_queue_configure(uint16_t dev_id, uint16_t queue_id,
160 const struct rte_bbdev_queue_conf *conf);
164 * This is the last step needed before enqueueing operations is possible.
167 * The identifier of the device.
171 * - negative value on failure - as returned from PMD driver
173 int __rte_experimental
174 rte_bbdev_start(uint16_t dev_id);
178 * The device can be reconfigured, and restarted after being stopped.
181 * The identifier of the device.
186 int __rte_experimental
187 rte_bbdev_stop(uint16_t dev_id);
191 * The device cannot be restarted without reconfiguration!
194 * The identifier of the device.
199 int __rte_experimental
200 rte_bbdev_close(uint16_t dev_id);
203 * Start a specified queue on a device.
204 * This is only needed if the queue has been stopped, or if the deferred_start
205 * flag has been set when configuring the queue.
208 * The identifier of the device.
210 * The index of the queue.
214 * - negative value on failure - as returned from PMD driver
216 int __rte_experimental
217 rte_bbdev_queue_start(uint16_t dev_id, uint16_t queue_id);
220 * Stop a specified queue on a device, to allow re configuration.
223 * The identifier of the device.
225 * The index of the queue.
229 * - negative value on failure - as returned from PMD driver
231 int __rte_experimental
232 rte_bbdev_queue_stop(uint16_t dev_id, uint16_t queue_id);
234 /** Device statistics. */
235 struct rte_bbdev_stats {
236 uint64_t enqueued_count; /**< Count of all operations enqueued */
237 uint64_t dequeued_count; /**< Count of all operations dequeued */
238 /** Total error count on operations enqueued */
239 uint64_t enqueue_err_count;
240 /** Total error count on operations dequeued */
241 uint64_t dequeue_err_count;
243 uint64_t offload_time;
247 * Retrieve the general I/O statistics of a device.
250 * The identifier of the device.
252 * Pointer to structure to where statistics will be copied. On error, this
253 * location may or may not have been modified.
257 * - EINVAL if invalid parameter pointer is provided
259 int __rte_experimental
260 rte_bbdev_stats_get(uint16_t dev_id, struct rte_bbdev_stats *stats);
263 * Reset the statistics of a device.
266 * The identifier of the device.
270 int __rte_experimental
271 rte_bbdev_stats_reset(uint16_t dev_id);
273 /** Device information supplied by the device's driver */
274 struct rte_bbdev_driver_info {
276 const char *driver_name;
278 /** Maximum number of queues supported by the device */
279 unsigned int max_num_queues;
280 /** Queue size limit (queue size must also be power of 2) */
281 uint32_t queue_size_lim;
282 /** Set if device off-loads operation to hardware */
283 bool hardware_accelerated;
284 /** Max value supported by queue priority for DL */
285 uint8_t max_dl_queue_priority;
286 /** Max value supported by queue priority for UL */
287 uint8_t max_ul_queue_priority;
288 /** Set if device supports per-queue interrupts */
289 bool queue_intr_supported;
290 /** Minimum alignment of buffers, in bytes */
291 uint16_t min_alignment;
292 /** Default queue configuration used if none is supplied */
293 struct rte_bbdev_queue_conf default_queue_conf;
294 /** Device operation capabilities */
295 const struct rte_bbdev_op_cap *capabilities;
296 /** Device cpu_flag requirements */
297 const enum rte_cpu_flag_t *cpu_flag_reqs;
300 /** Macro used at end of bbdev PMD list */
301 #define RTE_BBDEV_END_OF_CAPABILITIES_LIST() \
302 { RTE_BBDEV_OP_NONE }
305 * Device information structure used by an application to discover a devices
306 * capabilities and current configuration
308 struct rte_bbdev_info {
309 int socket_id; /**< NUMA socket that device is on */
310 const char *dev_name; /**< Unique device name */
311 const struct rte_bus *bus; /**< Bus information */
312 uint16_t num_queues; /**< Number of queues currently configured */
313 bool started; /**< Set if device is currently started */
314 struct rte_bbdev_driver_info drv; /**< Info from device driver */
318 * Retrieve information about a device.
321 * The identifier of the device.
323 * Pointer to structure to where information will be copied. On error, this
324 * location may or may not have been modified.
328 * - EINVAL if invalid parameter pointer is provided
330 int __rte_experimental
331 rte_bbdev_info_get(uint16_t dev_id, struct rte_bbdev_info *dev_info);
333 /** Queue information */
334 struct rte_bbdev_queue_info {
335 /** Current device configuration */
336 struct rte_bbdev_queue_conf conf;
337 /** Set if queue is currently started */
342 * Retrieve information about a specific queue on a device.
345 * The identifier of the device.
347 * The index of the queue.
349 * Pointer to structure to where information will be copied. On error, this
350 * location may or may not have been modified.
354 * - EINVAL if invalid parameter pointer is provided
356 int __rte_experimental
357 rte_bbdev_queue_info_get(uint16_t dev_id, uint16_t queue_id,
358 struct rte_bbdev_queue_info *queue_info);
360 /** @internal The data structure associated with each queue of a device. */
361 struct rte_bbdev_queue_data {
362 void *queue_private; /**< Driver-specific per-queue data */
363 struct rte_bbdev_queue_conf conf; /**< Current configuration */
364 struct rte_bbdev_stats queue_stats; /**< Queue statistics */
365 bool started; /**< Queue state */
368 /** @internal Enqueue encode operations for processing on queue of a device. */
369 typedef uint16_t (*rte_bbdev_enqueue_enc_ops_t)(
370 struct rte_bbdev_queue_data *q_data,
371 struct rte_bbdev_enc_op **ops,
374 /** @internal Enqueue decode operations for processing on queue of a device. */
375 typedef uint16_t (*rte_bbdev_enqueue_dec_ops_t)(
376 struct rte_bbdev_queue_data *q_data,
377 struct rte_bbdev_dec_op **ops,
380 /** @internal Dequeue encode operations from a queue of a device. */
381 typedef uint16_t (*rte_bbdev_dequeue_enc_ops_t)(
382 struct rte_bbdev_queue_data *q_data,
383 struct rte_bbdev_enc_op **ops, uint16_t num);
385 /** @internal Dequeue decode operations from a queue of a device. */
386 typedef uint16_t (*rte_bbdev_dequeue_dec_ops_t)(
387 struct rte_bbdev_queue_data *q_data,
388 struct rte_bbdev_dec_op **ops, uint16_t num);
390 #define RTE_BBDEV_NAME_MAX_LEN 64 /**< Max length of device name */
393 * @internal The data associated with a device, with no function pointers.
394 * This structure is safe to place in shared memory to be common among
395 * different processes in a multi-process configuration. Drivers can access
396 * these fields, but should never write to them!
398 struct rte_bbdev_data {
399 char name[RTE_BBDEV_NAME_MAX_LEN]; /**< Unique identifier name */
400 void *dev_private; /**< Driver-specific private data */
401 uint16_t num_queues; /**< Number of currently configured queues */
402 struct rte_bbdev_queue_data *queues; /**< Queue structures */
403 uint16_t dev_id; /**< Device ID */
404 int socket_id; /**< NUMA socket that device is on */
405 bool started; /**< Device run-time state */
406 /** Counter of processes using the device */
407 rte_atomic16_t process_cnt;
410 /* Forward declarations */
411 struct rte_bbdev_ops;
412 struct rte_bbdev_callback;
413 struct rte_intr_handle;
415 /** Structure to keep track of registered callbacks */
416 TAILQ_HEAD(rte_bbdev_cb_list, rte_bbdev_callback);
419 * @internal The data structure associated with a device. Drivers can access
420 * these fields, but should only write to the *_ops fields.
422 struct __rte_cache_aligned rte_bbdev {
423 /**< Enqueue encode function */
424 rte_bbdev_enqueue_enc_ops_t enqueue_enc_ops;
425 /**< Enqueue decode function */
426 rte_bbdev_enqueue_dec_ops_t enqueue_dec_ops;
427 /**< Dequeue encode function */
428 rte_bbdev_dequeue_enc_ops_t dequeue_enc_ops;
429 /**< Dequeue decode function */
430 rte_bbdev_dequeue_dec_ops_t dequeue_dec_ops;
431 const struct rte_bbdev_ops *dev_ops; /**< Functions exported by PMD */
432 struct rte_bbdev_data *data; /**< Pointer to device data */
433 enum rte_bbdev_state state; /**< If device is currently used or not */
434 struct rte_device *device; /**< Backing device */
435 /** User application callback for interrupts if present */
436 struct rte_bbdev_cb_list list_cbs;
437 struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
440 /** @internal array of all devices */
441 extern struct rte_bbdev rte_bbdev_devices[];
444 * Enqueue a burst of processed encode operations to a queue of the device.
445 * This functions only enqueues as many operations as currently possible and
446 * does not block until @p num_ops entries in the queue are available.
447 * This function does not provide any error notification to avoid the
448 * corresponding overhead.
451 * The identifier of the device.
453 * The index of the queue.
455 * Pointer array containing operations to be enqueued Must have at least
458 * The maximum number of operations to enqueue.
461 * The number of operations actually enqueued (this is the number of processed
462 * entries in the @p ops array).
464 static inline uint16_t
465 rte_bbdev_enqueue_enc_ops(uint16_t dev_id, uint16_t queue_id,
466 struct rte_bbdev_enc_op **ops, uint16_t num_ops)
468 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
469 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
470 return dev->enqueue_enc_ops(q_data, ops, num_ops);
474 * Enqueue a burst of processed decode operations to a queue of the device.
475 * This functions only enqueues as many operations as currently possible and
476 * does not block until @p num_ops entries in the queue are available.
477 * This function does not provide any error notification to avoid the
478 * corresponding overhead.
481 * The identifier of the device.
483 * The index of the queue.
485 * Pointer array containing operations to be enqueued Must have at least
488 * The maximum number of operations to enqueue.
491 * The number of operations actually enqueued (this is the number of processed
492 * entries in the @p ops array).
494 static inline uint16_t
495 rte_bbdev_enqueue_dec_ops(uint16_t dev_id, uint16_t queue_id,
496 struct rte_bbdev_dec_op **ops, uint16_t num_ops)
498 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
499 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
500 return dev->enqueue_dec_ops(q_data, ops, num_ops);
504 * Dequeue a burst of processed encode operations from a queue of the device.
505 * This functions returns only the current contents of the queue, and does not
506 * block until @ num_ops is available.
507 * This function does not provide any error notification to avoid the
508 * corresponding overhead.
511 * The identifier of the device.
513 * The index of the queue.
515 * Pointer array where operations will be dequeued to. Must have at least
518 * The maximum number of operations to dequeue.
521 * The number of operations actually dequeued (this is the number of entries
522 * copied into the @p ops array).
524 static inline uint16_t
525 rte_bbdev_dequeue_enc_ops(uint16_t dev_id, uint16_t queue_id,
526 struct rte_bbdev_enc_op **ops, uint16_t num_ops)
528 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
529 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
530 return dev->dequeue_enc_ops(q_data, ops, num_ops);
534 * Dequeue a burst of processed decode operations from a queue of the device.
535 * This functions returns only the current contents of the queue, and does not
536 * block until @ num_ops is available.
537 * This function does not provide any error notification to avoid the
538 * corresponding overhead.
541 * The identifier of the device.
543 * The index of the queue.
545 * Pointer array where operations will be dequeued to. Must have at least
548 * The maximum number of operations to dequeue.
551 * The number of operations actually dequeued (this is the number of entries
552 * copied into the @p ops array).
555 static inline uint16_t
556 rte_bbdev_dequeue_dec_ops(uint16_t dev_id, uint16_t queue_id,
557 struct rte_bbdev_dec_op **ops, uint16_t num_ops)
559 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
560 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
561 return dev->dequeue_dec_ops(q_data, ops, num_ops);
564 /** Definitions of device event types */
565 enum rte_bbdev_event_type {
566 RTE_BBDEV_EVENT_UNKNOWN, /**< unknown event type */
567 RTE_BBDEV_EVENT_ERROR, /**< error interrupt event */
568 RTE_BBDEV_EVENT_DEQUEUE, /**< dequeue event */
569 RTE_BBDEV_EVENT_MAX /**< max value of this enum */
573 * Typedef for application callback function registered by application
574 * software for notification of device events
579 * Device event to register for notification of.
581 * User specified parameter to be passed to user's callback function.
583 * To pass data back to user application.
585 typedef void (*rte_bbdev_cb_fn)(uint16_t dev_id,
586 enum rte_bbdev_event_type event, void *cb_arg,
590 * Register a callback function for specific device id. Multiple callbacks can
591 * be added and will be called in the order they are added when an event is
592 * triggered. Callbacks are called in a separate thread created by the DPDK EAL.
597 * The event that the callback will be registered for.
599 * User supplied callback function to be called.
601 * Pointer to parameter that will be passed to the callback.
604 * Zero on success, negative value on failure.
606 int __rte_experimental
607 rte_bbdev_callback_register(uint16_t dev_id, enum rte_bbdev_event_type event,
608 rte_bbdev_cb_fn cb_fn, void *cb_arg);
611 * Unregister a callback function for specific device id.
614 * The device identifier.
616 * The event that the callback will be unregistered for.
618 * User supplied callback function to be unregistered.
620 * Pointer to the parameter supplied when registering the callback.
621 * (void *)-1 means to remove all registered callbacks with the specified
626 * - EINVAL if invalid parameter pointer is provided
627 * - EAGAIN if the provided callback pointer does not exist
629 int __rte_experimental
630 rte_bbdev_callback_unregister(uint16_t dev_id, enum rte_bbdev_event_type event,
631 rte_bbdev_cb_fn cb_fn, void *cb_arg);
634 * Enable a one-shot interrupt on the next operation enqueued to a particular
635 * queue. The interrupt will be triggered when the operation is ready to be
636 * dequeued. To handle the interrupt, an epoll file descriptor must be
637 * registered using rte_bbdev_queue_intr_ctl(), and then an application
638 * thread/lcore can wait for the interrupt using rte_epoll_wait().
641 * The device identifier.
643 * The index of the queue.
647 * - negative value on failure - as returned from PMD driver
649 int __rte_experimental
650 rte_bbdev_queue_intr_enable(uint16_t dev_id, uint16_t queue_id);
653 * Disable a one-shot interrupt on the next operation enqueued to a particular
654 * queue (if it has been enabled).
657 * The device identifier.
659 * The index of the queue.
663 * - negative value on failure - as returned from PMD driver
665 int __rte_experimental
666 rte_bbdev_queue_intr_disable(uint16_t dev_id, uint16_t queue_id);
669 * Control interface for per-queue interrupts.
672 * The device identifier.
674 * The index of the queue.
676 * Epoll file descriptor that will be associated with the interrupt source.
677 * If the special value RTE_EPOLL_PER_THREAD is provided, a per thread epoll
678 * file descriptor created by the EAL is used (RTE_EPOLL_PER_THREAD can also
679 * be used when calling rte_epoll_wait()).
681 * The operation be performed for the vector.RTE_INTR_EVENT_ADD or
682 * RTE_INTR_EVENT_DEL.
684 * User context, that will be returned in the epdata.data field of the
685 * rte_epoll_event structure filled in by rte_epoll_wait().
689 * - ENOTSUP if interrupts are not supported by the identified device
690 * - negative value on failure - as returned from PMD driver
692 int __rte_experimental
693 rte_bbdev_queue_intr_ctl(uint16_t dev_id, uint16_t queue_id, int epfd, int op,
700 #endif /* _RTE_BBDEV_H_ */