1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
11 * Wireless base band device abstraction APIs.
13 * This API allows an application to discover, configure and use a device to
14 * process operations. An asynchronous API (enqueue, followed by later dequeue)
15 * is used for processing operations.
17 * The functions in this API are not thread-safe when called on the same
18 * target object (a device, or a queue on a device), with the exception that
19 * one thread can enqueue operations to a queue while another thread dequeues
20 * from the same queue.
30 #include <rte_cpuflags.h>
32 #include "rte_bbdev_op.h"
34 #ifndef RTE_BBDEV_MAX_DEVS
35 #define RTE_BBDEV_MAX_DEVS 128 /**< Max number of devices */
38 /** Flags indicate current state of BBDEV device */
39 enum rte_bbdev_state {
45 * Get the total number of devices that have been successfully initialised.
48 * The total number of usable devices.
51 rte_bbdev_count(void);
54 * Check if a device is valid.
57 * The identifier of the device.
60 * true if device ID is valid and device is attached, false otherwise.
63 rte_bbdev_is_valid(uint16_t dev_id);
66 * Get the next enabled device.
72 * - The next device, or
73 * - RTE_BBDEV_MAX_DEVS if none found
76 rte_bbdev_find_next(uint16_t dev_id);
78 /** Iterate through all enabled devices */
79 #define RTE_BBDEV_FOREACH(i) for (i = rte_bbdev_find_next(-1); \
80 i < RTE_BBDEV_MAX_DEVS; \
81 i = rte_bbdev_find_next(i))
84 * Setup up device queues.
85 * This function must be called on a device before setting up the queues and
86 * starting the device. It can also be called when a device is in the stopped
87 * state. If any device queues have been configured their configuration will be
88 * cleared by a call to this function.
91 * The identifier of the device.
93 * Number of queues to configure on device.
95 * ID of a socket which will be used to allocate memory.
99 * - -ENODEV if dev_id is invalid or the device is corrupted
100 * - -EINVAL if num_queues is invalid, 0 or greater than maximum
101 * - -EBUSY if the identified device has already started
102 * - -ENOMEM if unable to allocate memory
105 rte_bbdev_setup_queues(uint16_t dev_id, uint16_t num_queues, int socket_id);
109 * This function may be called before starting the device to enable the
110 * interrupts if they are available.
113 * The identifier of the device.
117 * - -ENODEV if dev_id is invalid or the device is corrupted
118 * - -EBUSY if the identified device has already started
119 * - -ENOTSUP if the interrupts are not supported by the device
122 rte_bbdev_intr_enable(uint16_t dev_id);
124 /** Device queue configuration structure */
125 struct rte_bbdev_queue_conf {
126 int socket; /**< NUMA socket used for memory allocation */
127 uint32_t queue_size; /**< Size of queue */
128 uint8_t priority; /**< Queue priority */
129 bool deferred_start; /**< Do not start queue when device is started. */
130 enum rte_bbdev_op_type op_type; /**< Operation type */
134 * Configure a queue on a device.
135 * This function can be called after device configuration, and before starting.
136 * It can also be called when the device or the queue is in the stopped state.
139 * The identifier of the device.
141 * The index of the queue.
143 * The queue configuration. If NULL, a default configuration will be used.
147 * - EINVAL if the identified queue size or priority are invalid
148 * - EBUSY if the identified queue or its device have already started
151 rte_bbdev_queue_configure(uint16_t dev_id, uint16_t queue_id,
152 const struct rte_bbdev_queue_conf *conf);
156 * This is the last step needed before enqueueing operations is possible.
159 * The identifier of the device.
163 * - negative value on failure - as returned from PMD
166 rte_bbdev_start(uint16_t dev_id);
170 * The device can be reconfigured, and restarted after being stopped.
173 * The identifier of the device.
179 rte_bbdev_stop(uint16_t dev_id);
183 * The device cannot be restarted without reconfiguration!
186 * The identifier of the device.
192 rte_bbdev_close(uint16_t dev_id);
195 * Start a specified queue on a device.
196 * This is only needed if the queue has been stopped, or if the deferred_start
197 * flag has been set when configuring the queue.
200 * The identifier of the device.
202 * The index of the queue.
206 * - negative value on failure - as returned from PMD
209 rte_bbdev_queue_start(uint16_t dev_id, uint16_t queue_id);
212 * Stop a specified queue on a device, to allow re configuration.
215 * The identifier of the device.
217 * The index of the queue.
221 * - negative value on failure - as returned from PMD
224 rte_bbdev_queue_stop(uint16_t dev_id, uint16_t queue_id);
226 /** Device statistics. */
227 struct rte_bbdev_stats {
228 uint64_t enqueued_count; /**< Count of all operations enqueued */
229 uint64_t dequeued_count; /**< Count of all operations dequeued */
230 /** Total error count on operations enqueued */
231 uint64_t enqueue_err_count;
232 /** Total error count on operations dequeued */
233 uint64_t dequeue_err_count;
234 /** CPU cycles consumed by the (HW/SW) accelerator device to offload
235 * the enqueue request to its internal queues.
236 * - For a HW device this is the cycles consumed in MMIO write
237 * - For a SW (vdev) device, this is the processing time of the
240 uint64_t acc_offload_cycles;
244 * Retrieve the general I/O statistics of a device.
247 * The identifier of the device.
249 * Pointer to structure to where statistics will be copied. On error, this
250 * location may or may not have been modified.
254 * - EINVAL if invalid parameter pointer is provided
257 rte_bbdev_stats_get(uint16_t dev_id, struct rte_bbdev_stats *stats);
260 * Reset the statistics of a device.
263 * The identifier of the device.
268 rte_bbdev_stats_reset(uint16_t dev_id);
270 /** Device information supplied by the device's driver */
271 struct rte_bbdev_driver_info {
273 const char *driver_name;
275 /** Maximum number of queues supported by the device */
276 unsigned int max_num_queues;
277 /** Queue size limit (queue size must also be power of 2) */
278 uint32_t queue_size_lim;
279 /** Set if device off-loads operation to hardware */
280 bool hardware_accelerated;
281 /** Max value supported by queue priority for DL */
282 uint8_t max_dl_queue_priority;
283 /** Max value supported by queue priority for UL */
284 uint8_t max_ul_queue_priority;
285 /** Set if device supports per-queue interrupts */
286 bool queue_intr_supported;
287 /** Minimum alignment of buffers, in bytes */
288 uint16_t min_alignment;
289 /** HARQ memory available in kB */
290 uint32_t harq_buffer_size;
291 /** Byte endianness (RTE_BIG_ENDIAN/RTE_LITTLE_ENDIAN) supported
292 * for input/output data
294 uint8_t data_endianness;
295 /** Default queue configuration used if none is supplied */
296 struct rte_bbdev_queue_conf default_queue_conf;
297 /** Device operation capabilities */
298 const struct rte_bbdev_op_cap *capabilities;
299 /** Device cpu_flag requirements */
300 const enum rte_cpu_flag_t *cpu_flag_reqs;
303 /** Macro used at end of bbdev PMD list */
304 #define RTE_BBDEV_END_OF_CAPABILITIES_LIST() \
305 { RTE_BBDEV_OP_NONE }
308 * Device information structure used by an application to discover a devices
309 * capabilities and current configuration
311 struct rte_bbdev_info {
312 int socket_id; /**< NUMA socket that device is on */
313 const char *dev_name; /**< Unique device name */
314 const struct rte_device *device; /**< Device Information */
315 uint16_t num_queues; /**< Number of queues currently configured */
316 bool started; /**< Set if device is currently started */
317 struct rte_bbdev_driver_info drv; /**< Info from device driver */
321 * Retrieve information about a device.
324 * The identifier of the device.
326 * Pointer to structure to where information will be copied. On error, this
327 * location may or may not have been modified.
331 * - EINVAL if invalid parameter pointer is provided
334 rte_bbdev_info_get(uint16_t dev_id, struct rte_bbdev_info *dev_info);
336 /** Queue information */
337 struct rte_bbdev_queue_info {
338 /** Current device configuration */
339 struct rte_bbdev_queue_conf conf;
340 /** Set if queue is currently started */
345 * Retrieve information about a specific queue on a device.
348 * The identifier of the device.
350 * The index of the queue.
352 * Pointer to structure to where information will be copied. On error, this
353 * location may or may not have been modified.
357 * - EINVAL if invalid parameter pointer is provided
360 rte_bbdev_queue_info_get(uint16_t dev_id, uint16_t queue_id,
361 struct rte_bbdev_queue_info *queue_info);
363 /** @internal The data structure associated with each queue of a device. */
364 struct rte_bbdev_queue_data {
365 void *queue_private; /**< Driver-specific per-queue data */
366 struct rte_bbdev_queue_conf conf; /**< Current configuration */
367 struct rte_bbdev_stats queue_stats; /**< Queue statistics */
368 bool started; /**< Queue state */
371 /** @internal Enqueue encode operations for processing on queue of a device. */
372 typedef uint16_t (*rte_bbdev_enqueue_enc_ops_t)(
373 struct rte_bbdev_queue_data *q_data,
374 struct rte_bbdev_enc_op **ops,
377 /** @internal Enqueue decode operations for processing on queue of a device. */
378 typedef uint16_t (*rte_bbdev_enqueue_dec_ops_t)(
379 struct rte_bbdev_queue_data *q_data,
380 struct rte_bbdev_dec_op **ops,
383 /** @internal Dequeue encode operations from a queue of a device. */
384 typedef uint16_t (*rte_bbdev_dequeue_enc_ops_t)(
385 struct rte_bbdev_queue_data *q_data,
386 struct rte_bbdev_enc_op **ops, uint16_t num);
388 /** @internal Dequeue decode operations from a queue of a device. */
389 typedef uint16_t (*rte_bbdev_dequeue_dec_ops_t)(
390 struct rte_bbdev_queue_data *q_data,
391 struct rte_bbdev_dec_op **ops, uint16_t num);
393 #define RTE_BBDEV_NAME_MAX_LEN 64 /**< Max length of device name */
396 * @internal The data associated with a device, with no function pointers.
397 * This structure is safe to place in shared memory to be common among
398 * different processes in a multi-process configuration. Drivers can access
399 * these fields, but should never write to them!
401 struct rte_bbdev_data {
402 char name[RTE_BBDEV_NAME_MAX_LEN]; /**< Unique identifier name */
403 void *dev_private; /**< Driver-specific private data */
404 uint16_t num_queues; /**< Number of currently configured queues */
405 struct rte_bbdev_queue_data *queues; /**< Queue structures */
406 uint16_t dev_id; /**< Device ID */
407 int socket_id; /**< NUMA socket that device is on */
408 bool started; /**< Device run-time state */
409 uint16_t process_cnt; /** Counter of processes using the device */
412 /* Forward declarations */
413 struct rte_bbdev_ops;
414 struct rte_bbdev_callback;
415 struct rte_intr_handle;
417 /** Structure to keep track of registered callbacks */
418 RTE_TAILQ_HEAD(rte_bbdev_cb_list, rte_bbdev_callback);
421 * @internal The data structure associated with a device. Drivers can access
422 * these fields, but should only write to the *_ops fields.
424 struct __rte_cache_aligned rte_bbdev {
425 /** Enqueue encode function */
426 rte_bbdev_enqueue_enc_ops_t enqueue_enc_ops;
427 /** Enqueue decode function */
428 rte_bbdev_enqueue_dec_ops_t enqueue_dec_ops;
429 /** Dequeue encode function */
430 rte_bbdev_dequeue_enc_ops_t dequeue_enc_ops;
431 /** Dequeue decode function */
432 rte_bbdev_dequeue_dec_ops_t dequeue_dec_ops;
433 /** Enqueue encode function */
434 rte_bbdev_enqueue_enc_ops_t enqueue_ldpc_enc_ops;
435 /** Enqueue decode function */
436 rte_bbdev_enqueue_dec_ops_t enqueue_ldpc_dec_ops;
437 /** Dequeue encode function */
438 rte_bbdev_dequeue_enc_ops_t dequeue_ldpc_enc_ops;
439 /** Dequeue decode function */
440 rte_bbdev_dequeue_dec_ops_t dequeue_ldpc_dec_ops;
441 const struct rte_bbdev_ops *dev_ops; /**< Functions exported by PMD */
442 struct rte_bbdev_data *data; /**< Pointer to device data */
443 enum rte_bbdev_state state; /**< If device is currently used or not */
444 struct rte_device *device; /**< Backing device */
445 /** User application callback for interrupts if present */
446 struct rte_bbdev_cb_list list_cbs;
447 struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
450 /** @internal array of all devices */
451 extern struct rte_bbdev rte_bbdev_devices[];
454 * Enqueue a burst of processed encode operations to a queue of the device.
455 * This functions only enqueues as many operations as currently possible and
456 * does not block until @p num_ops entries in the queue are available.
457 * This function does not provide any error notification to avoid the
458 * corresponding overhead.
461 * The identifier of the device.
463 * The index of the queue.
465 * Pointer array containing operations to be enqueued Must have at least
468 * The maximum number of operations to enqueue.
471 * The number of operations actually enqueued (this is the number of processed
472 * entries in the @p ops array).
474 static inline uint16_t
475 rte_bbdev_enqueue_enc_ops(uint16_t dev_id, uint16_t queue_id,
476 struct rte_bbdev_enc_op **ops, uint16_t num_ops)
478 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
479 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
480 return dev->enqueue_enc_ops(q_data, ops, num_ops);
484 * Enqueue a burst of processed decode operations to a queue of the device.
485 * This functions only enqueues as many operations as currently possible and
486 * does not block until @p num_ops entries in the queue are available.
487 * This function does not provide any error notification to avoid the
488 * corresponding overhead.
491 * The identifier of the device.
493 * The index of the queue.
495 * Pointer array containing operations to be enqueued Must have at least
498 * The maximum number of operations to enqueue.
501 * The number of operations actually enqueued (this is the number of processed
502 * entries in the @p ops array).
504 static inline uint16_t
505 rte_bbdev_enqueue_dec_ops(uint16_t dev_id, uint16_t queue_id,
506 struct rte_bbdev_dec_op **ops, uint16_t num_ops)
508 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
509 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
510 return dev->enqueue_dec_ops(q_data, ops, num_ops);
514 * Enqueue a burst of processed encode operations to a queue of the device.
515 * This functions only enqueues as many operations as currently possible and
516 * does not block until @p num_ops entries in the queue are available.
517 * This function does not provide any error notification to avoid the
518 * corresponding overhead.
521 * The identifier of the device.
523 * The index of the queue.
525 * Pointer array containing operations to be enqueued Must have at least
528 * The maximum number of operations to enqueue.
531 * The number of operations actually enqueued (this is the number of processed
532 * entries in the @p ops array).
534 static inline uint16_t
535 rte_bbdev_enqueue_ldpc_enc_ops(uint16_t dev_id, uint16_t queue_id,
536 struct rte_bbdev_enc_op **ops, uint16_t num_ops)
538 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
539 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
540 return dev->enqueue_ldpc_enc_ops(q_data, ops, num_ops);
544 * Enqueue a burst of processed decode operations to a queue of the device.
545 * This functions only enqueues as many operations as currently possible and
546 * does not block until @p num_ops entries in the queue are available.
547 * This function does not provide any error notification to avoid the
548 * corresponding overhead.
551 * The identifier of the device.
553 * The index of the queue.
555 * Pointer array containing operations to be enqueued Must have at least
558 * The maximum number of operations to enqueue.
561 * The number of operations actually enqueued (this is the number of processed
562 * entries in the @p ops array).
564 static inline uint16_t
565 rte_bbdev_enqueue_ldpc_dec_ops(uint16_t dev_id, uint16_t queue_id,
566 struct rte_bbdev_dec_op **ops, uint16_t num_ops)
568 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
569 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
570 return dev->enqueue_ldpc_dec_ops(q_data, ops, num_ops);
575 * Dequeue a burst of processed encode operations from a queue of the device.
576 * This functions returns only the current contents of the queue, and does not
577 * block until @ num_ops is available.
578 * This function does not provide any error notification to avoid the
579 * corresponding overhead.
582 * The identifier of the device.
584 * The index of the queue.
586 * Pointer array where operations will be dequeued to. Must have at least
588 * ie. A pointer to a table of void * pointers (ops) that will be filled.
590 * The maximum number of operations to dequeue.
593 * The number of operations actually dequeued (this is the number of entries
594 * copied into the @p ops array).
596 static inline uint16_t
597 rte_bbdev_dequeue_enc_ops(uint16_t dev_id, uint16_t queue_id,
598 struct rte_bbdev_enc_op **ops, uint16_t num_ops)
600 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
601 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
602 return dev->dequeue_enc_ops(q_data, ops, num_ops);
606 * Dequeue a burst of processed decode operations from a queue of the device.
607 * This functions returns only the current contents of the queue, and does not
608 * block until @ num_ops is available.
609 * This function does not provide any error notification to avoid the
610 * corresponding overhead.
613 * The identifier of the device.
615 * The index of the queue.
617 * Pointer array where operations will be dequeued to. Must have at least
619 * ie. A pointer to a table of void * pointers (ops) that will be filled.
621 * The maximum number of operations to dequeue.
624 * The number of operations actually dequeued (this is the number of entries
625 * copied into the @p ops array).
628 static inline uint16_t
629 rte_bbdev_dequeue_dec_ops(uint16_t dev_id, uint16_t queue_id,
630 struct rte_bbdev_dec_op **ops, uint16_t num_ops)
632 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
633 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
634 return dev->dequeue_dec_ops(q_data, ops, num_ops);
639 * Dequeue a burst of processed encode operations from a queue of the device.
640 * This functions returns only the current contents of the queue, and does not
641 * block until @ num_ops is available.
642 * This function does not provide any error notification to avoid the
643 * corresponding overhead.
646 * The identifier of the device.
648 * The index of the queue.
650 * Pointer array where operations will be dequeued to. Must have at least
653 * The maximum number of operations to dequeue.
656 * The number of operations actually dequeued (this is the number of entries
657 * copied into the @p ops array).
659 static inline uint16_t
660 rte_bbdev_dequeue_ldpc_enc_ops(uint16_t dev_id, uint16_t queue_id,
661 struct rte_bbdev_enc_op **ops, uint16_t num_ops)
663 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
664 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
665 return dev->dequeue_ldpc_enc_ops(q_data, ops, num_ops);
669 * Dequeue a burst of processed decode operations from a queue of the device.
670 * This functions returns only the current contents of the queue, and does not
671 * block until @ num_ops is available.
672 * This function does not provide any error notification to avoid the
673 * corresponding overhead.
676 * The identifier of the device.
678 * The index of the queue.
680 * Pointer array where operations will be dequeued to. Must have at least
683 * The maximum number of operations to dequeue.
686 * The number of operations actually dequeued (this is the number of entries
687 * copied into the @p ops array).
689 static inline uint16_t
690 rte_bbdev_dequeue_ldpc_dec_ops(uint16_t dev_id, uint16_t queue_id,
691 struct rte_bbdev_dec_op **ops, uint16_t num_ops)
693 struct rte_bbdev *dev = &rte_bbdev_devices[dev_id];
694 struct rte_bbdev_queue_data *q_data = &dev->data->queues[queue_id];
695 return dev->dequeue_ldpc_dec_ops(q_data, ops, num_ops);
698 /** Definitions of device event types */
699 enum rte_bbdev_event_type {
700 RTE_BBDEV_EVENT_UNKNOWN, /**< unknown event type */
701 RTE_BBDEV_EVENT_ERROR, /**< error interrupt event */
702 RTE_BBDEV_EVENT_DEQUEUE, /**< dequeue event */
703 RTE_BBDEV_EVENT_MAX /**< max value of this enum */
707 * Typedef for application callback function registered by application
708 * software for notification of device events
713 * Device event to register for notification of.
715 * User specified parameter to be passed to user's callback function.
717 * To pass data back to user application.
719 typedef void (*rte_bbdev_cb_fn)(uint16_t dev_id,
720 enum rte_bbdev_event_type event, void *cb_arg,
724 * Register a callback function for specific device id. Multiple callbacks can
725 * be added and will be called in the order they are added when an event is
726 * triggered. Callbacks are called in a separate thread created by the DPDK EAL.
731 * The event that the callback will be registered for.
733 * User supplied callback function to be called.
735 * Pointer to parameter that will be passed to the callback.
738 * Zero on success, negative value on failure.
741 rte_bbdev_callback_register(uint16_t dev_id, enum rte_bbdev_event_type event,
742 rte_bbdev_cb_fn cb_fn, void *cb_arg);
745 * Unregister a callback function for specific device id.
748 * The device identifier.
750 * The event that the callback will be unregistered for.
752 * User supplied callback function to be unregistered.
754 * Pointer to the parameter supplied when registering the callback.
755 * (void *)-1 means to remove all registered callbacks with the specified
760 * - EINVAL if invalid parameter pointer is provided
761 * - EAGAIN if the provided callback pointer does not exist
764 rte_bbdev_callback_unregister(uint16_t dev_id, enum rte_bbdev_event_type event,
765 rte_bbdev_cb_fn cb_fn, void *cb_arg);
768 * Enable a one-shot interrupt on the next operation enqueued to a particular
769 * queue. The interrupt will be triggered when the operation is ready to be
770 * dequeued. To handle the interrupt, an epoll file descriptor must be
771 * registered using rte_bbdev_queue_intr_ctl(), and then an application
772 * thread/lcore can wait for the interrupt using rte_epoll_wait().
775 * The device identifier.
777 * The index of the queue.
781 * - negative value on failure - as returned from PMD
784 rte_bbdev_queue_intr_enable(uint16_t dev_id, uint16_t queue_id);
787 * Disable a one-shot interrupt on the next operation enqueued to a particular
788 * queue (if it has been enabled).
791 * The device identifier.
793 * The index of the queue.
797 * - negative value on failure - as returned from PMD
800 rte_bbdev_queue_intr_disable(uint16_t dev_id, uint16_t queue_id);
803 * Control interface for per-queue interrupts.
806 * The device identifier.
808 * The index of the queue.
810 * Epoll file descriptor that will be associated with the interrupt source.
811 * If the special value RTE_EPOLL_PER_THREAD is provided, a per thread epoll
812 * file descriptor created by the EAL is used (RTE_EPOLL_PER_THREAD can also
813 * be used when calling rte_epoll_wait()).
815 * The operation be performed for the vector.RTE_INTR_EVENT_ADD or
816 * RTE_INTR_EVENT_DEL.
818 * User context, that will be returned in the epdata.data field of the
819 * rte_epoll_event structure filled in by rte_epoll_wait().
823 * - ENOTSUP if interrupts are not supported by the identified device
824 * - negative value on failure - as returned from PMD
827 rte_bbdev_queue_intr_ctl(uint16_t dev_id, uint16_t queue_id, int epfd, int op,
834 #endif /* _RTE_BBDEV_H_ */