1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017-2018 Intel Corporation
5 #ifndef _RTE_COMPRESSDEV_H_
6 #define _RTE_COMPRESSDEV_H_
9 * @file rte_compressdev.h
11 * RTE Compression Device APIs
13 * Defines comp device APIs for the provisioning of compression operations.
20 #include <rte_common.h>
25 * compression device supported feature flags
27 * @note New features flags should be added to the end of the list
29 * Keep these flags synchronised with rte_compressdev_get_feature_name()
31 #define RTE_COMPDEV_FF_HW_ACCELERATED (1ULL << 0)
32 /**< Operations are off-loaded to an external hardware accelerator */
33 #define RTE_COMPDEV_FF_CPU_SSE (1ULL << 1)
34 /**< Utilises CPU SIMD SSE instructions */
35 #define RTE_COMPDEV_FF_CPU_AVX (1ULL << 2)
36 /**< Utilises CPU SIMD AVX instructions */
37 #define RTE_COMPDEV_FF_CPU_AVX2 (1ULL << 3)
38 /**< Utilises CPU SIMD AVX2 instructions */
39 #define RTE_COMPDEV_FF_CPU_AVX512 (1ULL << 4)
40 /**< Utilises CPU SIMD AVX512 instructions */
41 #define RTE_COMPDEV_FF_CPU_NEON (1ULL << 5)
42 /**< Utilises CPU NEON instructions */
45 * Get the name of a compress device feature flag.
48 * The mask describing the flag
51 * The name of this flag, or NULL if it's not a valid feature flag.
53 const char * __rte_experimental
54 rte_compressdev_get_feature_name(uint64_t flag);
56 /** comp device information */
57 struct rte_compressdev_info {
58 const char *driver_name; /**< Driver name. */
59 uint64_t feature_flags; /**< Feature flags */
60 uint16_t max_nb_queue_pairs;
61 /**< Maximum number of queues pairs supported by device.
62 * (If 0, there is no limit in maximum number of queue pairs)
66 /** comp device statistics */
67 struct rte_compressdev_stats {
68 uint64_t enqueued_count;
69 /**< Count of all operations enqueued */
70 uint64_t dequeued_count;
71 /**< Count of all operations dequeued */
73 uint64_t enqueue_err_count;
74 /**< Total error count on operations enqueued */
75 uint64_t dequeue_err_count;
76 /**< Total error count on operations dequeued */
80 * Get the compress device name given a device identifier.
83 * Compress device identifier
85 * - Returns compress device name.
86 * - Returns NULL if compress device is not present.
88 const char * __rte_experimental
89 rte_compressdev_name_get(uint8_t dev_id);
92 * Get the total number of compress devices that have been successfully
96 * - The total number of usable compress devices.
98 uint8_t __rte_experimental
99 rte_compressdev_count(void);
102 * Get number and identifiers of attached comp devices that
103 * use the same compress driver.
108 * Output devices identifiers
110 * Maximal number of devices
113 * Returns number of attached compress devices.
115 uint8_t __rte_experimental
116 rte_compressdev_devices_get(const char *driver_name, uint8_t *devices,
120 * Return the NUMA socket to which a device is connected.
123 * Compress device identifier
125 * The NUMA socket id to which the device is connected or
126 * a default of zero if the socket could not be determined.
127 * -1 if returned is the dev_id value is out of range.
129 int __rte_experimental
130 rte_compressdev_socket_id(uint8_t dev_id);
132 /** Compress device configuration structure */
133 struct rte_compressdev_config {
135 /**< Socket on which to allocate resources */
136 uint16_t nb_queue_pairs;
137 /**< Total number of queue pairs to configure on a device */
138 uint16_t max_nb_priv_xforms;
139 /**< Max number of private_xforms which will be created on the device */
140 uint16_t max_nb_streams;
141 /**< Max number of streams which will be created on the device */
145 * Configure a device.
147 * This function must be invoked first before any other function in the
148 * API. This function can also be re-invoked when a device is in the
152 * Compress device identifier
154 * The compress device configuration
156 * - 0: Success, device configured.
157 * - <0: Error code returned by the driver configuration function.
159 int __rte_experimental
160 rte_compressdev_configure(uint8_t dev_id,
161 struct rte_compressdev_config *config);
166 * The device start step is called after configuring the device and setting up
168 * On success, data-path functions exported by the API (enqueue/dequeue, etc)
172 * Compress device identifier
174 * - 0: Success, device started.
175 * - <0: Error code of the driver device start function.
177 int __rte_experimental
178 rte_compressdev_start(uint8_t dev_id);
181 * Stop a device. The device can be restarted with a call to
182 * rte_compressdev_start()
185 * Compress device identifier
187 void __rte_experimental
188 rte_compressdev_stop(uint8_t dev_id);
192 * The memory allocated in the device gets freed.
193 * After calling this function, in order to use
194 * the device again, it is required to
195 * configure the device again.
198 * Compress device identifier
201 * - 0 on successfully closing device
202 * - <0 on failure to close device
204 int __rte_experimental
205 rte_compressdev_close(uint8_t dev_id);
208 * Allocate and set up a receive queue pair for a device.
209 * This should only be called when the device is stopped.
213 * Compress device identifier
214 * @param queue_pair_id
215 * The index of the queue pairs to set up. The
216 * value must be in the range [0, nb_queue_pair - 1]
217 * previously supplied to rte_compressdev_configure()
218 * @param max_inflight_ops
219 * Max number of ops which the qp will have to
220 * accommodate simultaneously
222 * The *socket_id* argument is the socket identifier
223 * in case of NUMA. The value can be *SOCKET_ID_ANY*
224 * if there is no NUMA constraint for the DMA memory
225 * allocated for the receive queue pair
227 * - 0: Success, queue pair correctly set up.
228 * - <0: Queue pair configuration failed
230 int __rte_experimental
231 rte_compressdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
232 uint32_t max_inflight_ops, int socket_id);
235 * Get the number of queue pairs on a specific comp device
238 * Compress device identifier
240 * - The number of configured queue pairs.
242 uint16_t __rte_experimental
243 rte_compressdev_queue_pair_count(uint8_t dev_id);
247 * Retrieve the general I/O statistics of a device.
250 * The identifier of the device
252 * A pointer to a structure of type
253 * *rte_compressdev_stats* to be filled with the
254 * values of device counters
256 * - Zero if successful.
257 * - Non-zero otherwise.
259 int __rte_experimental
260 rte_compressdev_stats_get(uint8_t dev_id, struct rte_compressdev_stats *stats);
263 * Reset the general I/O statistics of a device.
266 * The identifier of the device.
268 void __rte_experimental
269 rte_compressdev_stats_reset(uint8_t dev_id);
272 * Retrieve the contextual information of a device.
275 * Compress device identifier
277 * A pointer to a structure of type *rte_compressdev_info*
278 * to be filled with the contextual information of the device
280 * @note The capabilities field of dev_info is set to point to the first
281 * element of an array of struct rte_compressdev_capabilities.
282 * The element after the last valid element has it's op field set to
283 * RTE_COMP_ALGO_LIST_END.
285 void __rte_experimental
286 rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info);
290 * Dequeue a burst of processed compression operations from a queue on the comp
291 * device. The dequeued operation are stored in *rte_comp_op* structures
292 * whose pointers are supplied in the *ops* array.
294 * The rte_compressdev_dequeue_burst() function returns the number of ops
295 * actually dequeued, which is the number of *rte_comp_op* data structures
296 * effectively supplied into the *ops* array.
298 * A return value equal to *nb_ops* indicates that the queue contained
299 * at least *nb_ops* operations, and this is likely to signify that other
300 * processed operations remain in the devices output queue. Applications
301 * implementing a "retrieve as many processed operations as possible" policy
302 * can check this specific case and keep invoking the
303 * rte_compressdev_dequeue_burst() function until a value less than
304 * *nb_ops* is returned.
306 * The rte_compressdev_dequeue_burst() function does not provide any error
307 * notification to avoid the corresponding overhead.
309 * @note: operation ordering is not maintained within the queue pair.
311 * @note: In case op status = OUT_OF_SPACE_TERMINATED, op.consumed=0 and the
312 * op must be resubmitted with the same input data and a larger output buffer.
313 * op.produced is usually 0, but in decompression cases a PMD may return > 0
314 * and the application may find it useful to inspect that data.
315 * This status is only returned on STATELESS ops.
317 * @note: In case op status = OUT_OF_SPACE_RECOVERABLE, op.produced can be used
318 * and next op in stream should continue on from op.consumed+1 with a fresh
320 * Consumed=0, produced=0 is an unusual but allowed case. There may be useful
321 * state/history stored in the PMD, even though no output was produced yet.
325 * Compress device identifier
327 * The index of the queue pair from which to retrieve
328 * processed operations. The value must be in the range
329 * [0, nb_queue_pair - 1] previously supplied to
330 * rte_compressdev_configure()
332 * The address of an array of pointers to
333 * *rte_comp_op* structures that must be
334 * large enough to store *nb_ops* pointers in it
336 * The maximum number of operations to dequeue
338 * - The number of operations actually dequeued, which is the number
339 * of pointers to *rte_comp_op* structures effectively supplied to the
342 uint16_t __rte_experimental
343 rte_compressdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
344 struct rte_comp_op **ops, uint16_t nb_ops);
347 * Enqueue a burst of operations for processing on a compression device.
349 * The rte_compressdev_enqueue_burst() function is invoked to place
350 * comp operations on the queue *qp_id* of the device designated by
353 * The *nb_ops* parameter is the number of operations to process which are
354 * supplied in the *ops* array of *rte_comp_op* structures.
356 * The rte_compressdev_enqueue_burst() function returns the number of
357 * operations it actually enqueued for processing. A return value equal to
358 * *nb_ops* means that all packets have been enqueued.
360 * @note All compression operations are Out-of-place (OOP) operations,
361 * as the size of the output data is different to the size of the input data.
363 * @note The flush flag only applies to operations which return SUCCESS.
364 * In OUT_OF_SPACE cases whether STATEFUL or STATELESS, data in dest buffer
365 * is as if flush flag was FLUSH_NONE.
366 * @note flush flag only applies in compression direction. It has no meaning
368 * @note: operation ordering is not maintained within the queue pair.
371 * Compress device identifier
373 * The index of the queue pair on which operations
374 * are to be enqueued for processing. The value
375 * must be in the range [0, nb_queue_pairs - 1]
376 * previously supplied to *rte_compressdev_configure*
378 * The address of an array of *nb_ops* pointers
379 * to *rte_comp_op* structures which contain
380 * the operations to be processed
382 * The number of operations to process
384 * The number of operations actually enqueued on the device. The return
385 * value can be less than the value of the *nb_ops* parameter when the
386 * comp devices queue is full or if invalid parameters are specified in
389 uint16_t __rte_experimental
390 rte_compressdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
391 struct rte_comp_op **ops, uint16_t nb_ops);
394 * This should alloc a stream from the device's mempool and initialise it.
395 * The application should call this API when setting up for the stateful
396 * processing of a set of data on a device. The API can be called multiple
397 * times to set up a stream for each data set. The handle returned is only for
398 * use with ops of op_type STATEFUL and must be passed to the PMD
399 * with every op in the data stream
402 * Compress device identifier
406 * Pointer to where PMD's private stream handle should be stored
409 * - 0 if successful and valid stream handle
410 * - <0 in error cases
411 * - Returns -EINVAL if input parameters are invalid.
412 * - Returns -ENOTSUP if comp device does not support STATEFUL operations.
413 * - Returns -ENOTSUP if comp device does not support the comp transform.
414 * - Returns -ENOMEM if the private stream could not be allocated.
417 int __rte_experimental
418 rte_compressdev_stream_create(uint8_t dev_id,
419 const struct rte_comp_xform *xform,
423 * This should clear the stream and return it to the device's mempool.
426 * Compress device identifier
429 * PMD's private stream data
433 * - <0 in error cases
434 * - Returns -EINVAL if input parameters are invalid.
435 * - Returns -ENOTSUP if comp device does not support STATEFUL operations.
436 * - Returns -EBUSY if can't free stream as there are inflight operations
438 int __rte_experimental
439 rte_compressdev_stream_free(uint8_t dev_id, void *stream);
442 * This should alloc a private_xform from the device's mempool and initialise
443 * it. The application should call this API when setting up for stateless
444 * processing on a device. If it returns non-shareable, then the appl cannot
445 * share this handle with multiple in-flight ops and should call this API again
446 * to get a separate handle for every in-flight op.
447 * The handle returned is only valid for use with ops of op_type STATELESS.
450 * Compress device identifier
453 * @param private_xform
454 * Pointer to where PMD's private_xform handle should be stored
457 * - if successful returns 0
458 * and valid private_xform handle
459 * - <0 in error cases
460 * - Returns -EINVAL if input parameters are invalid.
461 * - Returns -ENOTSUP if comp device does not support the comp transform.
462 * - Returns -ENOMEM if the private_xform could not be allocated.
464 int __rte_experimental
465 rte_compressdev_private_xform_create(uint8_t dev_id,
466 const struct rte_comp_xform *xform,
467 void **private_xform);
470 * This should clear the private_xform and return it to the device's mempool.
473 * Compress device identifier
475 * @param private_xform
476 * PMD's private_xform data
480 * - <0 in error cases
481 * - Returns -EINVAL if input parameters are invalid.
482 * - Returns -EBUSY if can't free private_xform due to inflight operations
484 int __rte_experimental
485 rte_compressdev_private_xform_free(uint8_t dev_id, void *private_xform);
491 #endif /* _RTE_COMPRESSDEV_H_ */