compressdev: support stateful operations
[dpdk.git] / lib / librte_compressdev / rte_compressdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017-2018 Intel Corporation
3  */
4
5 #ifndef _RTE_COMPRESSDEV_H_
6 #define _RTE_COMPRESSDEV_H_
7
8 /**
9  * @file rte_compressdev.h
10  *
11  * RTE Compression Device APIs
12  *
13  * Defines comp device APIs for the provisioning of compression operations.
14  */
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #include <rte_common.h>
21
22 #include "rte_comp.h"
23
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)
30          */
31 };
32
33 /**
34  * Get the compress device name given a device identifier.
35  *
36  * @param dev_id
37  *   Compress device identifier
38  * @return
39  *   - Returns compress device name.
40  *   - Returns NULL if compress device is not present.
41  */
42 const char * __rte_experimental
43 rte_compressdev_name_get(uint8_t dev_id);
44
45 /**
46  * Get the total number of compress devices that have been successfully
47  * initialised.
48  *
49  * @return
50  *   - The total number of usable compress devices.
51  */
52 uint8_t __rte_experimental
53 rte_compressdev_count(void);
54
55 /**
56  * Get number and identifiers of attached comp devices that
57  * use the same compress driver.
58  *
59  * @param driver_name
60  *   Driver name
61  * @param devices
62  *   Output devices identifiers
63  * @param nb_devices
64  *   Maximal number of devices
65  *
66  * @return
67  *   Returns number of attached compress devices.
68  */
69 uint8_t __rte_experimental
70 rte_compressdev_devices_get(const char *driver_name, uint8_t *devices,
71                 uint8_t nb_devices);
72
73 /*
74  * Return the NUMA socket to which a device is connected.
75  *
76  * @param dev_id
77  *   Compress device identifier
78  * @return
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.
82  */
83 int __rte_experimental
84 rte_compressdev_socket_id(uint8_t dev_id);
85
86 /** Compress device configuration structure */
87 struct rte_compressdev_config {
88         int socket_id;
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 */
96 };
97
98 /**
99  * Configure a device.
100  *
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
103  * stopped state.
104  *
105  * @param dev_id
106  *   Compress device identifier
107  * @param config
108  *   The compress device configuration
109  * @return
110  *   - 0: Success, device configured.
111  *   - <0: Error code returned by the driver configuration function.
112  */
113 int __rte_experimental
114 rte_compressdev_configure(uint8_t dev_id,
115                         struct rte_compressdev_config *config);
116
117 /**
118  * Start a device.
119  *
120  * The device start step is called after configuring the device and setting up
121  * its queue pairs.
122  * On success, data-path functions exported by the API (enqueue/dequeue, etc)
123  * can be invoked.
124  *
125  * @param dev_id
126  *   Compress device identifier
127  * @return
128  *   - 0: Success, device started.
129  *   - <0: Error code of the driver device start function.
130  */
131 int __rte_experimental
132 rte_compressdev_start(uint8_t dev_id);
133
134 /**
135  * Stop a device. The device can be restarted with a call to
136  * rte_compressdev_start()
137  *
138  * @param dev_id
139  *   Compress device identifier
140  */
141 void __rte_experimental
142 rte_compressdev_stop(uint8_t dev_id);
143
144 /**
145  * Close an device.
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.
150  *
151  * @param dev_id
152  *   Compress device identifier
153  *
154  * @return
155  *  - 0 on successfully closing device
156  *  - <0 on failure to close device
157  */
158 int __rte_experimental
159 rte_compressdev_close(uint8_t dev_id);
160
161 /**
162  * Allocate and set up a receive queue pair for a device.
163  * This should only be called when the device is stopped.
164  *
165  *
166  * @param dev_id
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
175  * @param socket_id
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
180  * @return
181  *   - 0: Success, queue pair correctly set up.
182  *   - <0: Queue pair configuration failed
183  */
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);
187
188 /**
189  * Get the number of queue pairs on a specific comp device
190  *
191  * @param dev_id
192  *   Compress device identifier
193  * @return
194  *   - The number of configured queue pairs.
195  */
196 uint16_t __rte_experimental
197 rte_compressdev_queue_pair_count(uint8_t dev_id);
198
199 /**
200  * Retrieve the contextual information of a device.
201  *
202  * @param dev_id
203  *   Compress device identifier
204  * @param dev_info
205  *   A pointer to a structure of type *rte_compressdev_info*
206  *   to be filled with the contextual information of the device
207  *
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.
212  */
213 void __rte_experimental
214 rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info);
215
216 /**
217  *
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.
221  *
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.
225  *
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.
233  *
234  * The rte_compressdev_dequeue_burst() function does not provide any error
235  * notification to avoid the corresponding overhead.
236  *
237  * @note: operation ordering is not maintained within the queue pair.
238  *
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.
244  *
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
247  * output buffer.
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.
250  *
251  *
252  * @param dev_id
253  *   Compress device identifier
254  * @param qp_id
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()
259  * @param ops
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
263  * @param nb_ops
264  *   The maximum number of operations to dequeue
265  * @return
266  *   - The number of operations actually dequeued, which is the number
267  *   of pointers to *rte_comp_op* structures effectively supplied to the
268  *   *ops* array.
269  */
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);
273
274 /**
275  * Enqueue a burst of operations for processing on a compression device.
276  *
277  * The rte_compressdev_enqueue_burst() function is invoked to place
278  * comp operations on the queue *qp_id* of the device designated by
279  * its *dev_id*.
280  *
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.
283  *
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.
287  *
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.
290  *
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
295  * for decompression.
296  * @note: operation ordering is not maintained within the queue pair.
297  *
298  * @param dev_id
299  *   Compress device identifier
300  * @param qp_id
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*
305  * @param ops
306  *   The address of an array of *nb_ops* pointers
307  *   to *rte_comp_op* structures which contain
308  *   the operations to be processed
309  * @param nb_ops
310  *   The number of operations to process
311  * @return
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
315  *   a *rte_comp_op*.
316  */
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);
320
321 /**
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
328  *
329  * @param dev_id
330  *   Compress device identifier
331  * @param xform
332  *   xform data
333  * @param stream
334  *   Pointer to where PMD's private stream handle should be stored
335  *
336  * @return
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.
343  *
344  */
345 int __rte_experimental
346 rte_compressdev_stream_create(uint8_t dev_id,
347                 const struct rte_comp_xform *xform,
348                 void **stream);
349
350 /**
351  * This should clear the stream and return it to the device's mempool.
352  *
353  * @param dev_id
354  *   Compress device identifier
355  *
356  * @param stream
357  *   PMD's private stream data
358  *
359  * @return
360  *  - 0 if successful
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
365  */
366 int __rte_experimental
367 rte_compressdev_stream_free(uint8_t dev_id, void *stream);
368
369 /**
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.
376  *
377  * @param dev_id
378  *   Compress device identifier
379  * @param xform
380  *   xform data
381  * @param private_xform
382  *   Pointer to where PMD's private_xform handle should be stored
383  *
384  * @return
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.
391  */
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);
396
397 /**
398  * This should clear the private_xform and return it to the device's mempool.
399  *
400  * @param dev_id
401  *   Compress device identifier
402  *
403  * @param private_xform
404  *   PMD's private_xform data
405  *
406  * @return
407  *  - 0 if successful
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
411  */
412 int __rte_experimental
413 rte_compressdev_private_xform_free(uint8_t dev_id, void *private_xform);
414
415 #ifdef __cplusplus
416 }
417 #endif
418
419 #endif /* _RTE_COMPRESSDEV_H_ */