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>
24 /** comp device information */
25 struct rte_compressdev_info {
26 const char *driver_name; /**< Driver name. */
27 uint16_t max_nb_queue_pairs;
28 /**< Maximum number of queues pairs supported by device.
29 * (If 0, there is no limit in maximum number of queue pairs)
34 * Get the compress device name given a device identifier.
37 * Compress device identifier
39 * - Returns compress device name.
40 * - Returns NULL if compress device is not present.
42 const char * __rte_experimental
43 rte_compressdev_name_get(uint8_t dev_id);
46 * Get the total number of compress devices that have been successfully
50 * - The total number of usable compress devices.
52 uint8_t __rte_experimental
53 rte_compressdev_count(void);
56 * Get number and identifiers of attached comp devices that
57 * use the same compress driver.
62 * Output devices identifiers
64 * Maximal number of devices
67 * Returns number of attached compress devices.
69 uint8_t __rte_experimental
70 rte_compressdev_devices_get(const char *driver_name, uint8_t *devices,
74 * Return the NUMA socket to which a device is connected.
77 * Compress device identifier
79 * The NUMA socket id to which the device is connected or
80 * a default of zero if the socket could not be determined.
81 * -1 if returned is the dev_id value is out of range.
83 int __rte_experimental
84 rte_compressdev_socket_id(uint8_t dev_id);
86 /** Compress device configuration structure */
87 struct rte_compressdev_config {
89 /**< Socket on which to allocate resources */
90 uint16_t nb_queue_pairs;
91 /**< Total number of queue pairs to configure on a device */
92 uint16_t max_nb_priv_xforms;
93 /**< Max number of private_xforms which will be created on the device */
94 uint16_t max_nb_streams;
95 /**< Max number of streams which will be created on the device */
101 * This function must be invoked first before any other function in the
102 * API. This function can also be re-invoked when a device is in the
106 * Compress device identifier
108 * The compress device configuration
110 * - 0: Success, device configured.
111 * - <0: Error code returned by the driver configuration function.
113 int __rte_experimental
114 rte_compressdev_configure(uint8_t dev_id,
115 struct rte_compressdev_config *config);
120 * The device start step is called after configuring the device and setting up
122 * On success, data-path functions exported by the API (enqueue/dequeue, etc)
126 * Compress device identifier
128 * - 0: Success, device started.
129 * - <0: Error code of the driver device start function.
131 int __rte_experimental
132 rte_compressdev_start(uint8_t dev_id);
135 * Stop a device. The device can be restarted with a call to
136 * rte_compressdev_start()
139 * Compress device identifier
141 void __rte_experimental
142 rte_compressdev_stop(uint8_t dev_id);
146 * The memory allocated in the device gets freed.
147 * After calling this function, in order to use
148 * the device again, it is required to
149 * configure the device again.
152 * Compress device identifier
155 * - 0 on successfully closing device
156 * - <0 on failure to close device
158 int __rte_experimental
159 rte_compressdev_close(uint8_t dev_id);
162 * Allocate and set up a receive queue pair for a device.
163 * This should only be called when the device is stopped.
167 * Compress device identifier
168 * @param queue_pair_id
169 * The index of the queue pairs to set up. The
170 * value must be in the range [0, nb_queue_pair - 1]
171 * previously supplied to rte_compressdev_configure()
172 * @param max_inflight_ops
173 * Max number of ops which the qp will have to
174 * accommodate simultaneously
176 * The *socket_id* argument is the socket identifier
177 * in case of NUMA. The value can be *SOCKET_ID_ANY*
178 * if there is no NUMA constraint for the DMA memory
179 * allocated for the receive queue pair
181 * - 0: Success, queue pair correctly set up.
182 * - <0: Queue pair configuration failed
184 int __rte_experimental
185 rte_compressdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
186 uint32_t max_inflight_ops, int socket_id);
189 * Get the number of queue pairs on a specific comp device
192 * Compress device identifier
194 * - The number of configured queue pairs.
196 uint16_t __rte_experimental
197 rte_compressdev_queue_pair_count(uint8_t dev_id);
200 * Retrieve the contextual information of a device.
203 * Compress device identifier
205 * A pointer to a structure of type *rte_compressdev_info*
206 * to be filled with the contextual information of the device
208 * @note The capabilities field of dev_info is set to point to the first
209 * element of an array of struct rte_compressdev_capabilities.
210 * The element after the last valid element has it's op field set to
211 * RTE_COMP_ALGO_LIST_END.
213 void __rte_experimental
214 rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info);
218 * Dequeue a burst of processed compression operations from a queue on the comp
219 * device. The dequeued operation are stored in *rte_comp_op* structures
220 * whose pointers are supplied in the *ops* array.
222 * The rte_compressdev_dequeue_burst() function returns the number of ops
223 * actually dequeued, which is the number of *rte_comp_op* data structures
224 * effectively supplied into the *ops* array.
226 * A return value equal to *nb_ops* indicates that the queue contained
227 * at least *nb_ops* operations, and this is likely to signify that other
228 * processed operations remain in the devices output queue. Applications
229 * implementing a "retrieve as many processed operations as possible" policy
230 * can check this specific case and keep invoking the
231 * rte_compressdev_dequeue_burst() function until a value less than
232 * *nb_ops* is returned.
234 * The rte_compressdev_dequeue_burst() function does not provide any error
235 * notification to avoid the corresponding overhead.
237 * @note: operation ordering is not maintained within the queue pair.
239 * @note: In case op status = OUT_OF_SPACE_TERMINATED, op.consumed=0 and the
240 * op must be resubmitted with the same input data and a larger output buffer.
241 * op.produced is usually 0, but in decompression cases a PMD may return > 0
242 * and the application may find it useful to inspect that data.
243 * This status is only returned on STATELESS ops.
245 * @note: In case op status = OUT_OF_SPACE_RECOVERABLE, op.produced can be used
246 * and next op in stream should continue on from op.consumed+1 with a fresh
248 * Consumed=0, produced=0 is an unusual but allowed case. There may be useful
249 * state/history stored in the PMD, even though no output was produced yet.
253 * Compress device identifier
255 * The index of the queue pair from which to retrieve
256 * processed operations. The value must be in the range
257 * [0, nb_queue_pair - 1] previously supplied to
258 * rte_compressdev_configure()
260 * The address of an array of pointers to
261 * *rte_comp_op* structures that must be
262 * large enough to store *nb_ops* pointers in it
264 * The maximum number of operations to dequeue
266 * - The number of operations actually dequeued, which is the number
267 * of pointers to *rte_comp_op* structures effectively supplied to the
270 uint16_t __rte_experimental
271 rte_compressdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
272 struct rte_comp_op **ops, uint16_t nb_ops);
275 * Enqueue a burst of operations for processing on a compression device.
277 * The rte_compressdev_enqueue_burst() function is invoked to place
278 * comp operations on the queue *qp_id* of the device designated by
281 * The *nb_ops* parameter is the number of operations to process which are
282 * supplied in the *ops* array of *rte_comp_op* structures.
284 * The rte_compressdev_enqueue_burst() function returns the number of
285 * operations it actually enqueued for processing. A return value equal to
286 * *nb_ops* means that all packets have been enqueued.
288 * @note All compression operations are Out-of-place (OOP) operations,
289 * as the size of the output data is different to the size of the input data.
291 * @note The flush flag only applies to operations which return SUCCESS.
292 * In OUT_OF_SPACE cases whether STATEFUL or STATELESS, data in dest buffer
293 * is as if flush flag was FLUSH_NONE.
294 * @note flush flag only applies in compression direction. It has no meaning
296 * @note: operation ordering is not maintained within the queue pair.
299 * Compress device identifier
301 * The index of the queue pair on which operations
302 * are to be enqueued for processing. The value
303 * must be in the range [0, nb_queue_pairs - 1]
304 * previously supplied to *rte_compressdev_configure*
306 * The address of an array of *nb_ops* pointers
307 * to *rte_comp_op* structures which contain
308 * the operations to be processed
310 * The number of operations to process
312 * The number of operations actually enqueued on the device. The return
313 * value can be less than the value of the *nb_ops* parameter when the
314 * comp devices queue is full or if invalid parameters are specified in
317 uint16_t __rte_experimental
318 rte_compressdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
319 struct rte_comp_op **ops, uint16_t nb_ops);
322 * This should alloc a stream from the device's mempool and initialise it.
323 * The application should call this API when setting up for the stateful
324 * processing of a set of data on a device. The API can be called multiple
325 * times to set up a stream for each data set. The handle returned is only for
326 * use with ops of op_type STATEFUL and must be passed to the PMD
327 * with every op in the data stream
330 * Compress device identifier
334 * Pointer to where PMD's private stream handle should be stored
337 * - 0 if successful and valid stream handle
338 * - <0 in error cases
339 * - Returns -EINVAL if input parameters are invalid.
340 * - Returns -ENOTSUP if comp device does not support STATEFUL operations.
341 * - Returns -ENOTSUP if comp device does not support the comp transform.
342 * - Returns -ENOMEM if the private stream could not be allocated.
345 int __rte_experimental
346 rte_compressdev_stream_create(uint8_t dev_id,
347 const struct rte_comp_xform *xform,
351 * This should clear the stream and return it to the device's mempool.
354 * Compress device identifier
357 * PMD's private stream data
361 * - <0 in error cases
362 * - Returns -EINVAL if input parameters are invalid.
363 * - Returns -ENOTSUP if comp device does not support STATEFUL operations.
364 * - Returns -EBUSY if can't free stream as there are inflight operations
366 int __rte_experimental
367 rte_compressdev_stream_free(uint8_t dev_id, void *stream);
370 * This should alloc a private_xform from the device's mempool and initialise
371 * it. The application should call this API when setting up for stateless
372 * processing on a device. If it returns non-shareable, then the appl cannot
373 * share this handle with multiple in-flight ops and should call this API again
374 * to get a separate handle for every in-flight op.
375 * The handle returned is only valid for use with ops of op_type STATELESS.
378 * Compress device identifier
381 * @param private_xform
382 * Pointer to where PMD's private_xform handle should be stored
385 * - if successful returns 0
386 * and valid private_xform handle
387 * - <0 in error cases
388 * - Returns -EINVAL if input parameters are invalid.
389 * - Returns -ENOTSUP if comp device does not support the comp transform.
390 * - Returns -ENOMEM if the private_xform could not be allocated.
392 int __rte_experimental
393 rte_compressdev_private_xform_create(uint8_t dev_id,
394 const struct rte_comp_xform *xform,
395 void **private_xform);
398 * This should clear the private_xform and return it to the device's mempool.
401 * Compress device identifier
403 * @param private_xform
404 * PMD's private_xform data
408 * - <0 in error cases
409 * - Returns -EINVAL if input parameters are invalid.
410 * - Returns -EBUSY if can't free private_xform due to inflight operations
412 int __rte_experimental
413 rte_compressdev_private_xform_free(uint8_t dev_id, void *private_xform);
419 #endif /* _RTE_COMPRESSDEV_H_ */