705e9fe79a106a058b79bbc16c7a0940a139c61f
[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 };
95
96 /**
97  * Configure a device.
98  *
99  * This function must be invoked first before any other function in the
100  * API. This function can also be re-invoked when a device is in the
101  * stopped state.
102  *
103  * @param dev_id
104  *   Compress device identifier
105  * @param config
106  *   The compress device configuration
107  * @return
108  *   - 0: Success, device configured.
109  *   - <0: Error code returned by the driver configuration function.
110  */
111 int __rte_experimental
112 rte_compressdev_configure(uint8_t dev_id,
113                         struct rte_compressdev_config *config);
114
115 /**
116  * Start a device.
117  *
118  * The device start step is called after configuring the device and setting up
119  * its queue pairs.
120  * On success, data-path functions exported by the API (enqueue/dequeue, etc)
121  * can be invoked.
122  *
123  * @param dev_id
124  *   Compress device identifier
125  * @return
126  *   - 0: Success, device started.
127  *   - <0: Error code of the driver device start function.
128  */
129 int __rte_experimental
130 rte_compressdev_start(uint8_t dev_id);
131
132 /**
133  * Stop a device. The device can be restarted with a call to
134  * rte_compressdev_start()
135  *
136  * @param dev_id
137  *   Compress device identifier
138  */
139 void __rte_experimental
140 rte_compressdev_stop(uint8_t dev_id);
141
142 /**
143  * Close an device.
144  * The memory allocated in the device gets freed.
145  * After calling this function, in order to use
146  * the device again, it is required to
147  * configure the device again.
148  *
149  * @param dev_id
150  *   Compress device identifier
151  *
152  * @return
153  *  - 0 on successfully closing device
154  *  - <0 on failure to close device
155  */
156 int __rte_experimental
157 rte_compressdev_close(uint8_t dev_id);
158
159 /**
160  * Allocate and set up a receive queue pair for a device.
161  * This should only be called when the device is stopped.
162  *
163  *
164  * @param dev_id
165  *   Compress device identifier
166  * @param queue_pair_id
167  *   The index of the queue pairs to set up. The
168  *   value must be in the range [0, nb_queue_pair - 1]
169  *   previously supplied to rte_compressdev_configure()
170  * @param max_inflight_ops
171  *   Max number of ops which the qp will have to
172  *   accommodate simultaneously
173  * @param socket_id
174  *   The *socket_id* argument is the socket identifier
175  *   in case of NUMA. The value can be *SOCKET_ID_ANY*
176  *   if there is no NUMA constraint for the DMA memory
177  *   allocated for the receive queue pair
178  * @return
179  *   - 0: Success, queue pair correctly set up.
180  *   - <0: Queue pair configuration failed
181  */
182 int __rte_experimental
183 rte_compressdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
184                 uint32_t max_inflight_ops, int socket_id);
185
186 /**
187  * Get the number of queue pairs on a specific comp device
188  *
189  * @param dev_id
190  *   Compress device identifier
191  * @return
192  *   - The number of configured queue pairs.
193  */
194 uint16_t __rte_experimental
195 rte_compressdev_queue_pair_count(uint8_t dev_id);
196
197 /**
198  * Retrieve the contextual information of a device.
199  *
200  * @param dev_id
201  *   Compress device identifier
202  * @param dev_info
203  *   A pointer to a structure of type *rte_compressdev_info*
204  *   to be filled with the contextual information of the device
205  *
206  * @note The capabilities field of dev_info is set to point to the first
207  * element of an array of struct rte_compressdev_capabilities.
208  * The element after the last valid element has it's op field set to
209  * RTE_COMP_ALGO_LIST_END.
210  */
211 void __rte_experimental
212 rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info);
213
214 /**
215  *
216  * Dequeue a burst of processed compression operations from a queue on the comp
217  * device. The dequeued operation are stored in *rte_comp_op* structures
218  * whose pointers are supplied in the *ops* array.
219  *
220  * The rte_compressdev_dequeue_burst() function returns the number of ops
221  * actually dequeued, which is the number of *rte_comp_op* data structures
222  * effectively supplied into the *ops* array.
223  *
224  * A return value equal to *nb_ops* indicates that the queue contained
225  * at least *nb_ops* operations, and this is likely to signify that other
226  * processed operations remain in the devices output queue. Applications
227  * implementing a "retrieve as many processed operations as possible" policy
228  * can check this specific case and keep invoking the
229  * rte_compressdev_dequeue_burst() function until a value less than
230  * *nb_ops* is returned.
231  *
232  * The rte_compressdev_dequeue_burst() function does not provide any error
233  * notification to avoid the corresponding overhead.
234  *
235  * @note: operation ordering is not maintained within the queue pair.
236  *
237  * @note: In case op status = OUT_OF_SPACE_TERMINATED, op.consumed=0 and the
238  * op must be resubmitted with the same input data and a larger output buffer.
239  * op.produced is usually 0, but in decompression cases a PMD may return > 0
240  * and the application may find it useful to inspect that data.
241  * This status is only returned on STATELESS ops.
242  *
243  * @note: In case op status = OUT_OF_SPACE_RECOVERABLE, op.produced can be used
244  * and next op in stream should continue on from op.consumed+1 with a fresh
245  * output buffer.
246  * Consumed=0, produced=0 is an unusual but allowed case. There may be useful
247  * state/history stored in the PMD, even though no output was produced yet.
248  *
249  *
250  * @param dev_id
251  *   Compress device identifier
252  * @param qp_id
253  *   The index of the queue pair from which to retrieve
254  *   processed operations. The value must be in the range
255  *   [0, nb_queue_pair - 1] previously supplied to
256  *   rte_compressdev_configure()
257  * @param ops
258  *   The address of an array of pointers to
259  *   *rte_comp_op* structures that must be
260  *   large enough to store *nb_ops* pointers in it
261  * @param nb_ops
262  *   The maximum number of operations to dequeue
263  * @return
264  *   - The number of operations actually dequeued, which is the number
265  *   of pointers to *rte_comp_op* structures effectively supplied to the
266  *   *ops* array.
267  */
268 uint16_t __rte_experimental
269 rte_compressdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
270                 struct rte_comp_op **ops, uint16_t nb_ops);
271
272 /**
273  * Enqueue a burst of operations for processing on a compression device.
274  *
275  * The rte_compressdev_enqueue_burst() function is invoked to place
276  * comp operations on the queue *qp_id* of the device designated by
277  * its *dev_id*.
278  *
279  * The *nb_ops* parameter is the number of operations to process which are
280  * supplied in the *ops* array of *rte_comp_op* structures.
281  *
282  * The rte_compressdev_enqueue_burst() function returns the number of
283  * operations it actually enqueued for processing. A return value equal to
284  * *nb_ops* means that all packets have been enqueued.
285  *
286  * @note All compression operations are Out-of-place (OOP) operations,
287  * as the size of the output data is different to the size of the input data.
288  *
289  * @note The flush flag only applies to operations which return SUCCESS.
290  * In OUT_OF_SPACE cases whether STATEFUL or STATELESS, data in dest buffer
291  * is as if flush flag was FLUSH_NONE.
292  * @note flush flag only applies in compression direction. It has no meaning
293  * for decompression.
294  * @note: operation ordering is not maintained within the queue pair.
295  *
296  * @param dev_id
297  *   Compress device identifier
298  * @param qp_id
299  *   The index of the queue pair on which operations
300  *   are to be enqueued for processing. The value
301  *   must be in the range [0, nb_queue_pairs - 1]
302  *   previously supplied to *rte_compressdev_configure*
303  * @param ops
304  *   The address of an array of *nb_ops* pointers
305  *   to *rte_comp_op* structures which contain
306  *   the operations to be processed
307  * @param nb_ops
308  *   The number of operations to process
309  * @return
310  *   The number of operations actually enqueued on the device. The return
311  *   value can be less than the value of the *nb_ops* parameter when the
312  *   comp devices queue is full or if invalid parameters are specified in
313  *   a *rte_comp_op*.
314  */
315 uint16_t __rte_experimental
316 rte_compressdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
317                 struct rte_comp_op **ops, uint16_t nb_ops);
318
319 /**
320  * This should alloc a private_xform from the device's mempool and initialise
321  * it. The application should call this API when setting up for stateless
322  * processing on a device. If it returns non-shareable, then the appl cannot
323  * share this handle with multiple in-flight ops and should call this API again
324  * to get a separate handle for every in-flight op.
325  * The handle returned is only valid for use with ops of op_type STATELESS.
326  *
327  * @param dev_id
328  *   Compress device identifier
329  * @param xform
330  *   xform data
331  * @param private_xform
332  *   Pointer to where PMD's private_xform handle should be stored
333  *
334  * @return
335  *  - if successful returns 0
336  *    and valid private_xform handle
337  *  - <0 in error cases
338  *  - Returns -EINVAL if input parameters are invalid.
339  *  - Returns -ENOTSUP if comp device does not support the comp transform.
340  *  - Returns -ENOMEM if the private_xform could not be allocated.
341  */
342 int __rte_experimental
343 rte_compressdev_private_xform_create(uint8_t dev_id,
344                 const struct rte_comp_xform *xform,
345                 void **private_xform);
346
347 /**
348  * This should clear the private_xform and return it to the device's mempool.
349  *
350  * @param dev_id
351  *   Compress device identifier
352  *
353  * @param private_xform
354  *   PMD's private_xform data
355  *
356  * @return
357  *  - 0 if successful
358  *  - <0 in error cases
359  *  - Returns -EINVAL if input parameters are invalid.
360  *  - Returns -EBUSY if can't free private_xform due to inflight operations
361  */
362 int __rte_experimental
363 rte_compressdev_private_xform_free(uint8_t dev_id, void *private_xform);
364
365 #ifdef __cplusplus
366 }
367 #endif
368
369 #endif /* _RTE_COMPRESSDEV_H_ */