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)
67 * Get the compress device name given a device identifier.
70 * Compress device identifier
72 * - Returns compress device name.
73 * - Returns NULL if compress device is not present.
75 const char * __rte_experimental
76 rte_compressdev_name_get(uint8_t dev_id);
79 * Get the total number of compress devices that have been successfully
83 * - The total number of usable compress devices.
85 uint8_t __rte_experimental
86 rte_compressdev_count(void);
89 * Get number and identifiers of attached comp devices that
90 * use the same compress driver.
95 * Output devices identifiers
97 * Maximal number of devices
100 * Returns number of attached compress devices.
102 uint8_t __rte_experimental
103 rte_compressdev_devices_get(const char *driver_name, uint8_t *devices,
107 * Return the NUMA socket to which a device is connected.
110 * Compress device identifier
112 * The NUMA socket id to which the device is connected or
113 * a default of zero if the socket could not be determined.
114 * -1 if returned is the dev_id value is out of range.
116 int __rte_experimental
117 rte_compressdev_socket_id(uint8_t dev_id);
119 /** Compress device configuration structure */
120 struct rte_compressdev_config {
122 /**< Socket on which to allocate resources */
123 uint16_t nb_queue_pairs;
124 /**< Total number of queue pairs to configure on a device */
125 uint16_t max_nb_priv_xforms;
126 /**< Max number of private_xforms which will be created on the device */
127 uint16_t max_nb_streams;
128 /**< Max number of streams which will be created on the device */
132 * Configure a device.
134 * This function must be invoked first before any other function in the
135 * API. This function can also be re-invoked when a device is in the
139 * Compress device identifier
141 * The compress device configuration
143 * - 0: Success, device configured.
144 * - <0: Error code returned by the driver configuration function.
146 int __rte_experimental
147 rte_compressdev_configure(uint8_t dev_id,
148 struct rte_compressdev_config *config);
153 * The device start step is called after configuring the device and setting up
155 * On success, data-path functions exported by the API (enqueue/dequeue, etc)
159 * Compress device identifier
161 * - 0: Success, device started.
162 * - <0: Error code of the driver device start function.
164 int __rte_experimental
165 rte_compressdev_start(uint8_t dev_id);
168 * Stop a device. The device can be restarted with a call to
169 * rte_compressdev_start()
172 * Compress device identifier
174 void __rte_experimental
175 rte_compressdev_stop(uint8_t dev_id);
179 * The memory allocated in the device gets freed.
180 * After calling this function, in order to use
181 * the device again, it is required to
182 * configure the device again.
185 * Compress device identifier
188 * - 0 on successfully closing device
189 * - <0 on failure to close device
191 int __rte_experimental
192 rte_compressdev_close(uint8_t dev_id);
195 * Allocate and set up a receive queue pair for a device.
196 * This should only be called when the device is stopped.
200 * Compress device identifier
201 * @param queue_pair_id
202 * The index of the queue pairs to set up. The
203 * value must be in the range [0, nb_queue_pair - 1]
204 * previously supplied to rte_compressdev_configure()
205 * @param max_inflight_ops
206 * Max number of ops which the qp will have to
207 * accommodate simultaneously
209 * The *socket_id* argument is the socket identifier
210 * in case of NUMA. The value can be *SOCKET_ID_ANY*
211 * if there is no NUMA constraint for the DMA memory
212 * allocated for the receive queue pair
214 * - 0: Success, queue pair correctly set up.
215 * - <0: Queue pair configuration failed
217 int __rte_experimental
218 rte_compressdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
219 uint32_t max_inflight_ops, int socket_id);
222 * Get the number of queue pairs on a specific comp device
225 * Compress device identifier
227 * - The number of configured queue pairs.
229 uint16_t __rte_experimental
230 rte_compressdev_queue_pair_count(uint8_t dev_id);
233 * Retrieve the contextual information of a device.
236 * Compress device identifier
238 * A pointer to a structure of type *rte_compressdev_info*
239 * to be filled with the contextual information of the device
241 * @note The capabilities field of dev_info is set to point to the first
242 * element of an array of struct rte_compressdev_capabilities.
243 * The element after the last valid element has it's op field set to
244 * RTE_COMP_ALGO_LIST_END.
246 void __rte_experimental
247 rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info);
251 * Dequeue a burst of processed compression operations from a queue on the comp
252 * device. The dequeued operation are stored in *rte_comp_op* structures
253 * whose pointers are supplied in the *ops* array.
255 * The rte_compressdev_dequeue_burst() function returns the number of ops
256 * actually dequeued, which is the number of *rte_comp_op* data structures
257 * effectively supplied into the *ops* array.
259 * A return value equal to *nb_ops* indicates that the queue contained
260 * at least *nb_ops* operations, and this is likely to signify that other
261 * processed operations remain in the devices output queue. Applications
262 * implementing a "retrieve as many processed operations as possible" policy
263 * can check this specific case and keep invoking the
264 * rte_compressdev_dequeue_burst() function until a value less than
265 * *nb_ops* is returned.
267 * The rte_compressdev_dequeue_burst() function does not provide any error
268 * notification to avoid the corresponding overhead.
270 * @note: operation ordering is not maintained within the queue pair.
272 * @note: In case op status = OUT_OF_SPACE_TERMINATED, op.consumed=0 and the
273 * op must be resubmitted with the same input data and a larger output buffer.
274 * op.produced is usually 0, but in decompression cases a PMD may return > 0
275 * and the application may find it useful to inspect that data.
276 * This status is only returned on STATELESS ops.
278 * @note: In case op status = OUT_OF_SPACE_RECOVERABLE, op.produced can be used
279 * and next op in stream should continue on from op.consumed+1 with a fresh
281 * Consumed=0, produced=0 is an unusual but allowed case. There may be useful
282 * state/history stored in the PMD, even though no output was produced yet.
286 * Compress device identifier
288 * The index of the queue pair from which to retrieve
289 * processed operations. The value must be in the range
290 * [0, nb_queue_pair - 1] previously supplied to
291 * rte_compressdev_configure()
293 * The address of an array of pointers to
294 * *rte_comp_op* structures that must be
295 * large enough to store *nb_ops* pointers in it
297 * The maximum number of operations to dequeue
299 * - The number of operations actually dequeued, which is the number
300 * of pointers to *rte_comp_op* structures effectively supplied to the
303 uint16_t __rte_experimental
304 rte_compressdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
305 struct rte_comp_op **ops, uint16_t nb_ops);
308 * Enqueue a burst of operations for processing on a compression device.
310 * The rte_compressdev_enqueue_burst() function is invoked to place
311 * comp operations on the queue *qp_id* of the device designated by
314 * The *nb_ops* parameter is the number of operations to process which are
315 * supplied in the *ops* array of *rte_comp_op* structures.
317 * The rte_compressdev_enqueue_burst() function returns the number of
318 * operations it actually enqueued for processing. A return value equal to
319 * *nb_ops* means that all packets have been enqueued.
321 * @note All compression operations are Out-of-place (OOP) operations,
322 * as the size of the output data is different to the size of the input data.
324 * @note The flush flag only applies to operations which return SUCCESS.
325 * In OUT_OF_SPACE cases whether STATEFUL or STATELESS, data in dest buffer
326 * is as if flush flag was FLUSH_NONE.
327 * @note flush flag only applies in compression direction. It has no meaning
329 * @note: operation ordering is not maintained within the queue pair.
332 * Compress device identifier
334 * The index of the queue pair on which operations
335 * are to be enqueued for processing. The value
336 * must be in the range [0, nb_queue_pairs - 1]
337 * previously supplied to *rte_compressdev_configure*
339 * The address of an array of *nb_ops* pointers
340 * to *rte_comp_op* structures which contain
341 * the operations to be processed
343 * The number of operations to process
345 * The number of operations actually enqueued on the device. The return
346 * value can be less than the value of the *nb_ops* parameter when the
347 * comp devices queue is full or if invalid parameters are specified in
350 uint16_t __rte_experimental
351 rte_compressdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
352 struct rte_comp_op **ops, uint16_t nb_ops);
355 * This should alloc a stream from the device's mempool and initialise it.
356 * The application should call this API when setting up for the stateful
357 * processing of a set of data on a device. The API can be called multiple
358 * times to set up a stream for each data set. The handle returned is only for
359 * use with ops of op_type STATEFUL and must be passed to the PMD
360 * with every op in the data stream
363 * Compress device identifier
367 * Pointer to where PMD's private stream handle should be stored
370 * - 0 if successful and valid stream handle
371 * - <0 in error cases
372 * - Returns -EINVAL if input parameters are invalid.
373 * - Returns -ENOTSUP if comp device does not support STATEFUL operations.
374 * - Returns -ENOTSUP if comp device does not support the comp transform.
375 * - Returns -ENOMEM if the private stream could not be allocated.
378 int __rte_experimental
379 rte_compressdev_stream_create(uint8_t dev_id,
380 const struct rte_comp_xform *xform,
384 * This should clear the stream and return it to the device's mempool.
387 * Compress device identifier
390 * PMD's private stream data
394 * - <0 in error cases
395 * - Returns -EINVAL if input parameters are invalid.
396 * - Returns -ENOTSUP if comp device does not support STATEFUL operations.
397 * - Returns -EBUSY if can't free stream as there are inflight operations
399 int __rte_experimental
400 rte_compressdev_stream_free(uint8_t dev_id, void *stream);
403 * This should alloc a private_xform from the device's mempool and initialise
404 * it. The application should call this API when setting up for stateless
405 * processing on a device. If it returns non-shareable, then the appl cannot
406 * share this handle with multiple in-flight ops and should call this API again
407 * to get a separate handle for every in-flight op.
408 * The handle returned is only valid for use with ops of op_type STATELESS.
411 * Compress device identifier
414 * @param private_xform
415 * Pointer to where PMD's private_xform handle should be stored
418 * - if successful returns 0
419 * and valid private_xform handle
420 * - <0 in error cases
421 * - Returns -EINVAL if input parameters are invalid.
422 * - Returns -ENOTSUP if comp device does not support the comp transform.
423 * - Returns -ENOMEM if the private_xform could not be allocated.
425 int __rte_experimental
426 rte_compressdev_private_xform_create(uint8_t dev_id,
427 const struct rte_comp_xform *xform,
428 void **private_xform);
431 * This should clear the private_xform and return it to the device's mempool.
434 * Compress device identifier
436 * @param private_xform
437 * PMD's private_xform data
441 * - <0 in error cases
442 * - Returns -EINVAL if input parameters are invalid.
443 * - Returns -EBUSY if can't free private_xform due to inflight operations
445 int __rte_experimental
446 rte_compressdev_private_xform_free(uint8_t dev_id, void *private_xform);
452 #endif /* _RTE_COMPRESSDEV_H_ */