1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
11 * Wireless base band device abstraction APIs.
15 * All functions in this file may be changed or removed without prior notice.
17 * This API allows an application to discover, configure and use a device to
18 * process operations. An asynchronous API (enqueue, followed by later dequeue)
19 * is used for processing operations.
21 * The functions in this API are not thread-safe when called on the same
22 * target object (a device, or a queue on a device), with the exception that
23 * one thread can enqueue operations to a queue while another thread dequeues
24 * from the same queue.
35 #include <rte_compat.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 indicate 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.
60 rte_bbdev_count(void);
63 * Check if a device is valid.
66 * The identifier of the device.
69 * true if device ID is valid and device is attached, false otherwise.
73 rte_bbdev_is_valid(uint16_t dev_id);
76 * Get the next enabled device.
82 * - The next device, or
83 * - RTE_BBDEV_MAX_DEVS if none found
87 rte_bbdev_find_next(uint16_t dev_id);
89 /** Iterate through all enabled devices */
90 #define RTE_BBDEV_FOREACH(i) for (i = rte_bbdev_find_next(-1); \
91 i < RTE_BBDEV_MAX_DEVS; \
92 i = rte_bbdev_find_next(i))
95 * Setup up device queues.
96 * This function must be called on a device before setting up the queues and
97 * starting the device. It can also be called when a device is in the stopped
98 * state. If any device queues have been configured their configuration will be
99 * cleared by a call to this function.
102 * The identifier of the device.
104 * Number of queues to configure on device.
106 * ID of a socket which will be used to allocate memory.
110 * - -ENODEV if dev_id is invalid or the device is corrupted
111 * - -EINVAL if num_queues is invalid, 0 or greater than maximum
112 * - -EBUSY if the identified device has already started
113 * - -ENOMEM if unable to allocate memory
117 rte_bbdev_setup_queues(uint16_t dev_id, uint16_t num_queues, int socket_id);
121 * This function may be called before starting the device to enable the
122 * interrupts if they are available.
125 * The identifier of the device.
129 * - -ENODEV if dev_id is invalid or the device is corrupted
130 * - -EBUSY if the identified device has already started
131 * - -ENOTSUP if the interrupts are not supported by the device
135 rte_bbdev_intr_enable(uint16_t dev_id);
137 /** Device queue configuration structure */
138 struct rte_bbdev_queue_conf {
139 int socket; /**< NUMA socket used for memory allocation */
140 uint32_t queue_size; /**< Size of queue */
141 uint8_t priority; /**< Queue priority */
142 bool deferred_start; /**< Do not start queue when device is started. */
143 enum rte_bbdev_op_type op_type; /**< Operation type */
147 * Configure a queue on a device.
148 * This function can be called after device configuration, and before starting.
149 * It can also be called when the device or the queue is in the stopped state.
152 * The identifier of the device.
154 * The index of the queue.
156 * The queue configuration. If NULL, a default configuration will be used.
160 * - EINVAL if the identified queue size or priority are invalid
161 * - EBUSY if the identified queue or its device have already started
165 rte_bbdev_queue_configure(uint16_t dev_id, uint16_t queue_id,
166 const struct rte_bbdev_queue_conf *conf);
170 * This is the last step needed before enqueueing operations is possible.
173 * The identifier of the device.
177 * - negative value on failure - as returned from PMD driver
181 rte_bbdev_start(uint16_t dev_id);
185 * The device can be reconfigured, and restarted after being stopped.
188 * The identifier of the device.
195 rte_bbdev_stop(uint16_t dev_id);
199 * The device cannot be restarted without reconfiguration!
202 * The identifier of the device.
209 rte_bbdev_close(uint16_t dev_id);
212 * Start a specified queue on a device.
213 * This is only needed if the queue has been stopped, or if the deferred_start
214 * flag has been set when configuring the queue.
217 * The identifier of the device.
219 * The index of the queue.
223 * - negative value on failure - as returned from PMD driver
227 rte_bbdev_queue_start(uint16_t dev_id, uint16_t queue_id);
230 * Stop a specified queue on a device, to allow re configuration.
233 * The identifier of the device.
235 * The index of the queue.
239 * - negative value on failure - as returned from PMD driver
243 rte_bbdev_queue_stop(uint16_t dev_id, uint16_t queue_id);
245 /** Device statistics. */
246 struct rte_bbdev_stats {
247 uint64_t enqueued_count; /**< Count of all operations enqueued */
248 uint64_t dequeued_count; /**< Count of all operations dequeued */
249 /** Total error count on operations enqueued */
250 uint64_t enqueue_err_count;
251 /** Total error count on operations dequeued */
252 uint64_t dequeue_err_count;
253 /** CPU cycles consumed by the (HW/SW) accelerator device to offload
254 * the enqueue request to its internal queues.
255 * - For a HW device this is the cycles consumed in MMIO write
256 * - For a SW (vdev) device, this is the processing time of the
259 uint64_t acc_offload_cycles;
263 * Retrieve the general I/O statistics of a device.
266 * The identifier of the device.
268 * Pointer to structure to where statistics will be copied. On error, this
269 * location may or may not have been modified.
273 * - EINVAL if invalid parameter pointer is provided
277 rte_bbdev_stats_get(uint16_t dev_id, struct rte_bbdev_stats *stats);
280 * Reset the statistics of a device.
283 * The identifier of the device.
289 rte_bbdev_stats_reset(uint16_t dev_id);
291 /** Device information supplied by the device's driver */
292 struct rte_bbdev_driver_info {
294 const char *driver_name;
296 /** Maximum number of queues supported by the device */
297 unsigned int max_num_queues;
298 /** Queue size limit (queue size must also be power of 2) */
299 uint32_t queue_size_lim;
300 /** Set if device off-loads operation to hardware */
301 bool hardware_accelerated;
302 /** Max value supported by queue priority for DL */
303 uint8_t max_dl_queue_priority;
304 /** Max value supported by queue priority for UL */
305 uint8_t max_ul_queue_priority;
306 /** Set if device supports per-queue interrupts */
307 bool queue_intr_supported;
308 /** Minimum alignment of buffers, in bytes */
309 uint16_t min_alignment;
310 /** HARQ memory available in kB */
311 uint32_t harq_buffer_size;
312 /** Default queue configuration used if none is supplied */
313 struct rte_bbdev_queue_conf default_queue_conf;
314 /** Device operation capabilities */
315 const struct rte_bbdev_op_cap *capabilities;
316 /** Device cpu_flag requirements */
317 const enum rte_cpu_flag_t *cpu_flag_reqs;
320 /** Macro used at end of bbdev PMD list */
321 #define RTE_BBDEV_END_OF_CAPABILITIES_LIST() \
322 { RTE_BBDEV_OP_NONE }
325 * Device information structure used by an application to discover a devices
326 * capabilities and current configuration
328 struct rte_bbdev_info {
329 int socket_id; /**< NUMA socket that device is on */
330 const char *dev_name; /**< Unique device name */
331 const struct rte_device *device; /**< Device Information */
332 uint16_t num_queues; /**< Number of queues currently configured */
333 bool started; /**< Set if device is currently started */
334 struct rte_bbdev_driver_info drv; /**< Info from device driver */
338 * Retrieve information about a device.
341 * The identifier of the device.
343 * Pointer to structure to where information will be copied. On error, this
344 * location may or may not have been modified.
348 * - EINVAL if invalid parameter pointer is provided
352 rte_bbdev_info_get(uint16_t dev_id, struct rte_bbdev_info *dev_info);
354 /** Queue information */
355 struct rte_bbdev_queue_info {
356 /** Current device configuration */
357 struct rte_bbdev_queue_conf conf;
358 /** Set if queue is currently started */
363 * Retrieve information about a specific queue on a device.
366 * The identifier of the device.
368 * The index of the queue.
370 * Pointer to structure to where information will be copied. On error, this
371 * location may or may not have been modified.
375 * - EINVAL if invalid parameter pointer is provided
379 rte_bbdev_queue_info_get(uint16_t dev_id, uint16_t queue_id,
380 struct rte_bbdev_queue_info *queue_info);
382 /** @internal The data structure associated with each queue of a device. */
383 struct rte_bbdev_queue_data {
384 void *queue_private; /**< Driver-specific per-queue data */
385 struct rte_bbdev_queue_conf conf; /**< Current configuration */
386 struct rte_bbdev_stats queue_stats; /**< Queue statistics */
387 bool started; /**< Queue state */
390 /** @internal Enqueue encode operations for processing on queue of a device. */
391 typedef uint16_t (*rte_bbdev_enqueue_enc_ops_t)(
392 struct rte_bbdev_queue_data *q_data,
393 struct rte_bbdev_enc_op **ops,
396 /** @internal Enqueue decode operations for processing on queue of a device. */
397 typedef uint16_t (*rte_bbdev_enqueue_dec_ops_t)(
398 struct rte_bbdev_queue_data *q_data,
399 struct rte_bbdev_dec_op **ops,
402 /** @internal Dequeue encode operations from a queue of a device. */
403 typedef uint16_t (*rte_bbdev_dequeue_enc_ops_t)(
404 struct rte_bbdev_queue_data *q_data,
405 struct rte_bbdev_enc_op **ops, uint16_t num);
407 /** @internal Dequeue decode operations from a queue of a device. */
408 typedef uint16_t (*rte_bbdev_dequeue_dec_ops_t)(
409 struct rte_bbdev_queue_data *q_data,
410 struct rte_bbdev_dec_op **ops, uint16_t num);
412 #define RTE_BBDEV_NAME_MAX_LEN 64 /**< Max length of device name */
415 * @internal The data associated with a device, with no function pointers.
416 * This structure is safe to place in shared memory to be common among
417 * different processes in a multi-process configuration. Drivers can access
418 * these fields, but should never write to them!
420 struct rte_bbdev_data {
421 char name[RTE_BBDEV_NAME_MAX_LEN]; /**< Unique identifier name */
422 void *dev_private; /**< Driver-specific private data */
423 uint16_t num_queues; /**< Number of currently configured queues */
424 struct rte_bbdev_queue_data *queues; /**< Queue structures */
425 uint16_t dev_id; /**< Device ID */
426 int socket_id; /**< NUMA socket that device is on */
427 bool started; /**< Device run-time state */
428 uint16_t process_cnt; /** Counter of processes using the device */
431 /* Forward declarations */
432 struct rte_bbdev_ops;
433 struct rte_bbdev_callback;
434 struct rte_intr_handle;
436 /** Structure to keep track of registered callbacks */
437 TAILQ_HEAD(rte_bbdev_cb_list, rte_bbdev_callback);
440 * @internal The data structure associated with a device. Drivers can access
441 * these fields, but should only write to the *_ops fields.
443 struct __rte_cache_aligned rte_bbdev {
444 /** Enqueue encode function */
445 rte_bbdev_enqueue_enc_ops_t enqueue_enc_ops;
446 /** Enqueue decode function */
447 rte_bbdev_enqueue_dec_ops_t enqueue_dec_ops;
448 /** Dequeue encode function */
449 rte_bbdev_dequeue_enc_ops_t dequeue_enc_ops;
450 /** Dequeue decode function */
451 rte_bbdev_dequeue_dec_ops_t dequeue_dec_ops;
452 /** Enqueue encode function */
453 rte_bbdev_enqueue_enc_ops_t enqueue_ldpc_enc_ops;
454 /** Enqueue decode function */
455 rte_bbdev_enqueue_dec_ops_t enqueue_ldpc_dec_ops;
456 /** Dequeue encode function */
457 rte_bbdev_dequeue_enc_ops_t dequeue_ldpc_enc_ops;
458 /** Dequeue decode function */
459 rte_bbdev_dequeue_dec_ops_t dequeue_ldpc_dec_ops;
460 const struct rte_bbdev_ops *dev_ops; /**< Functions exported by PMD */
461 struct rte_bbdev_data *data; /**< Pointer to device data */
462 enum rte_bbdev_state state; /**< If device is currently used or not */
463 struct rte_device *device; /**< Backing device */
464 /** User application callback for interrupts if present */
465 struct rte_bbdev_cb_list list_cbs;
466 struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
469 /** @internal array of all devices */
470 extern struct rte_bbdev rte_bbdev_devices[];
473 * Enqueue a burst of processed encode operations to a queue of the device.
474 * This functions only enqueues as many operations as currently possible and
475 * does not block until @p num_ops entries in the queue are available.
476 * This function does not provide any error notification to avoid the
477 * corresponding overhead.
480 * The identifier of the device.
482 * The index of the queue.
484 * Pointer array containing operations to be enqueued Must have at least
487 * The maximum number of operations to enqueue.
490 * The number of operations actually enqueued (this is the number of processed
491 * entries in the @p ops array).
494 static inline uint16_t
495 rte_bbdev_enqueue_enc_ops(uint16_t dev_id, uint16_t queue_id,
496 struct rte_bbdev_enc_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_enc_ops(q_data, ops, num_ops);
504 * Enqueue a burst of processed decode operations to a queue of the device.
505 * This functions only enqueues as many operations as currently possible and
506 * does not block until @p num_ops entries in the queue are 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 containing operations to be enqueued Must have at least
518 * The maximum number of operations to enqueue.
521 * The number of operations actually enqueued (this is the number of processed
522 * entries in the @p ops array).
525 static inline uint16_t
526 rte_bbdev_enqueue_dec_ops(uint16_t dev_id, uint16_t queue_id,
527 struct rte_bbdev_dec_op **ops, uint16_t num_ops)
529 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
530 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
531 return dev->enqueue_dec_ops(q_data, ops, num_ops);
535 * Enqueue a burst of processed encode operations to a queue of the device.
536 * This functions only enqueues as many operations as currently possible and
537 * does not block until @p num_ops entries in the queue are available.
538 * This function does not provide any error notification to avoid the
539 * corresponding overhead.
542 * The identifier of the device.
544 * The index of the queue.
546 * Pointer array containing operations to be enqueued Must have at least
549 * The maximum number of operations to enqueue.
552 * The number of operations actually enqueued (this is the number of processed
553 * entries in the @p ops array).
556 static inline uint16_t
557 rte_bbdev_enqueue_ldpc_enc_ops(uint16_t dev_id, uint16_t queue_id,
558 struct rte_bbdev_enc_op **ops, uint16_t num_ops)
560 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
561 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
562 return dev->enqueue_ldpc_enc_ops(q_data, ops, num_ops);
566 * Enqueue a burst of processed decode operations to a queue of the device.
567 * This functions only enqueues as many operations as currently possible and
568 * does not block until @p num_ops entries in the queue are available.
569 * This function does not provide any error notification to avoid the
570 * corresponding overhead.
573 * The identifier of the device.
575 * The index of the queue.
577 * Pointer array containing operations to be enqueued Must have at least
580 * The maximum number of operations to enqueue.
583 * The number of operations actually enqueued (this is the number of processed
584 * entries in the @p ops array).
587 static inline uint16_t
588 rte_bbdev_enqueue_ldpc_dec_ops(uint16_t dev_id, uint16_t queue_id,
589 struct rte_bbdev_dec_op **ops, uint16_t num_ops)
591 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
592 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
593 return dev->enqueue_ldpc_dec_ops(q_data, ops, num_ops);
598 * Dequeue a burst of processed encode operations from a queue of the device.
599 * This functions returns only the current contents of the queue, and does not
600 * block until @ num_ops is available.
601 * This function does not provide any error notification to avoid the
602 * corresponding overhead.
605 * The identifier of the device.
607 * The index of the queue.
609 * Pointer array where operations will be dequeued to. Must have at least
611 * ie. A pointer to a table of void * pointers (ops) that will be filled.
613 * The maximum number of operations to dequeue.
616 * The number of operations actually dequeued (this is the number of entries
617 * copied into the @p ops array).
620 static inline uint16_t
621 rte_bbdev_dequeue_enc_ops(uint16_t dev_id, uint16_t queue_id,
622 struct rte_bbdev_enc_op **ops, uint16_t num_ops)
624 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
625 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
626 return dev->dequeue_enc_ops(q_data, ops, num_ops);
630 * Dequeue a burst of processed decode operations from a queue of the device.
631 * This functions returns only the current contents of the queue, and does not
632 * block until @ num_ops is available.
633 * This function does not provide any error notification to avoid the
634 * corresponding overhead.
637 * The identifier of the device.
639 * The index of the queue.
641 * Pointer array where operations will be dequeued to. Must have at least
643 * ie. A pointer to a table of void * pointers (ops) that will be filled.
645 * The maximum number of operations to dequeue.
648 * The number of operations actually dequeued (this is the number of entries
649 * copied into the @p ops array).
653 static inline uint16_t
654 rte_bbdev_dequeue_dec_ops(uint16_t dev_id, uint16_t queue_id,
655 struct rte_bbdev_dec_op **ops, uint16_t num_ops)
657 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
658 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
659 return dev->dequeue_dec_ops(q_data, ops, num_ops);
664 * Dequeue a burst of processed encode operations from a queue of the device.
665 * This functions returns only the current contents of the queue, and does not
666 * block until @ num_ops is available.
667 * This function does not provide any error notification to avoid the
668 * corresponding overhead.
671 * The identifier of the device.
673 * The index of the queue.
675 * Pointer array where operations will be dequeued to. Must have at least
678 * The maximum number of operations to dequeue.
681 * The number of operations actually dequeued (this is the number of entries
682 * copied into the @p ops array).
685 static inline uint16_t
686 rte_bbdev_dequeue_ldpc_enc_ops(uint16_t dev_id, uint16_t queue_id,
687 struct rte_bbdev_enc_op **ops, uint16_t num_ops)
689 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
690 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
691 return dev->dequeue_ldpc_enc_ops(q_data, ops, num_ops);
695 * Dequeue a burst of processed decode operations from a queue of the device.
696 * This functions returns only the current contents of the queue, and does not
697 * block until @ num_ops is available.
698 * This function does not provide any error notification to avoid the
699 * corresponding overhead.
702 * The identifier of the device.
704 * The index of the queue.
706 * Pointer array where operations will be dequeued to. Must have at least
709 * The maximum number of operations to dequeue.
712 * The number of operations actually dequeued (this is the number of entries
713 * copied into the @p ops array).
716 static inline uint16_t
717 rte_bbdev_dequeue_ldpc_dec_ops(uint16_t dev_id, uint16_t queue_id,
718 struct rte_bbdev_dec_op **ops, uint16_t num_ops)
720 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
721 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
722 return dev->dequeue_ldpc_dec_ops(q_data, ops, num_ops);
725 /** Definitions of device event types */
726 enum rte_bbdev_event_type {
727 RTE_BBDEV_EVENT_UNKNOWN, /**< unknown event type */
728 RTE_BBDEV_EVENT_ERROR, /**< error interrupt event */
729 RTE_BBDEV_EVENT_DEQUEUE, /**< dequeue event */
730 RTE_BBDEV_EVENT_MAX /**< max value of this enum */
734 * Typedef for application callback function registered by application
735 * software for notification of device events
740 * Device event to register for notification of.
742 * User specified parameter to be passed to user's callback function.
744 * To pass data back to user application.
746 typedef void (*rte_bbdev_cb_fn)(uint16_t dev_id,
747 enum rte_bbdev_event_type event, void *cb_arg,
751 * Register a callback function for specific device id. Multiple callbacks can
752 * be added and will be called in the order they are added when an event is
753 * triggered. Callbacks are called in a separate thread created by the DPDK EAL.
758 * The event that the callback will be registered for.
760 * User supplied callback function to be called.
762 * Pointer to parameter that will be passed to the callback.
765 * Zero on success, negative value on failure.
769 rte_bbdev_callback_register(uint16_t dev_id, enum rte_bbdev_event_type event,
770 rte_bbdev_cb_fn cb_fn, void *cb_arg);
773 * Unregister a callback function for specific device id.
776 * The device identifier.
778 * The event that the callback will be unregistered for.
780 * User supplied callback function to be unregistered.
782 * Pointer to the parameter supplied when registering the callback.
783 * (void *)-1 means to remove all registered callbacks with the specified
788 * - EINVAL if invalid parameter pointer is provided
789 * - EAGAIN if the provided callback pointer does not exist
793 rte_bbdev_callback_unregister(uint16_t dev_id, enum rte_bbdev_event_type event,
794 rte_bbdev_cb_fn cb_fn, void *cb_arg);
797 * Enable a one-shot interrupt on the next operation enqueued to a particular
798 * queue. The interrupt will be triggered when the operation is ready to be
799 * dequeued. To handle the interrupt, an epoll file descriptor must be
800 * registered using rte_bbdev_queue_intr_ctl(), and then an application
801 * thread/lcore can wait for the interrupt using rte_epoll_wait().
804 * The device identifier.
806 * The index of the queue.
810 * - negative value on failure - as returned from PMD driver
814 rte_bbdev_queue_intr_enable(uint16_t dev_id, uint16_t queue_id);
817 * Disable a one-shot interrupt on the next operation enqueued to a particular
818 * queue (if it has been enabled).
821 * The device identifier.
823 * The index of the queue.
827 * - negative value on failure - as returned from PMD driver
831 rte_bbdev_queue_intr_disable(uint16_t dev_id, uint16_t queue_id);
834 * Control interface for per-queue interrupts.
837 * The device identifier.
839 * The index of the queue.
841 * Epoll file descriptor that will be associated with the interrupt source.
842 * If the special value RTE_EPOLL_PER_THREAD is provided, a per thread epoll
843 * file descriptor created by the EAL is used (RTE_EPOLL_PER_THREAD can also
844 * be used when calling rte_epoll_wait()).
846 * The operation be performed for the vector.RTE_INTR_EVENT_ADD or
847 * RTE_INTR_EVENT_DEL.
849 * User context, that will be returned in the epdata.data field of the
850 * rte_epoll_event structure filled in by rte_epoll_wait().
854 * - ENOTSUP if interrupts are not supported by the identified device
855 * - negative value on failure - as returned from PMD driver
859 rte_bbdev_queue_intr_ctl(uint16_t dev_id, uint16_t queue_id, int epfd, int op,
866 #endif /* _RTE_BBDEV_H_ */