compressdev: add device feature flags
[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 /**
25  * compression device supported feature flags
26  *
27  * @note New features flags should be added to the end of the list
28  *
29  * Keep these flags synchronised with rte_compressdev_get_feature_name()
30  */
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 */
43
44 /**
45  * Get the name of a compress device feature flag.
46  *
47  * @param flag
48  *   The mask describing the flag
49  *
50  * @return
51  *   The name of this flag, or NULL if it's not a valid feature flag.
52  */
53 const char * __rte_experimental
54 rte_compressdev_get_feature_name(uint64_t flag);
55
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)
63          */
64 };
65
66 /**
67  * Get the compress device name given a device identifier.
68  *
69  * @param dev_id
70  *   Compress device identifier
71  * @return
72  *   - Returns compress device name.
73  *   - Returns NULL if compress device is not present.
74  */
75 const char * __rte_experimental
76 rte_compressdev_name_get(uint8_t dev_id);
77
78 /**
79  * Get the total number of compress devices that have been successfully
80  * initialised.
81  *
82  * @return
83  *   - The total number of usable compress devices.
84  */
85 uint8_t __rte_experimental
86 rte_compressdev_count(void);
87
88 /**
89  * Get number and identifiers of attached comp devices that
90  * use the same compress driver.
91  *
92  * @param driver_name
93  *   Driver name
94  * @param devices
95  *   Output devices identifiers
96  * @param nb_devices
97  *   Maximal number of devices
98  *
99  * @return
100  *   Returns number of attached compress devices.
101  */
102 uint8_t __rte_experimental
103 rte_compressdev_devices_get(const char *driver_name, uint8_t *devices,
104                 uint8_t nb_devices);
105
106 /*
107  * Return the NUMA socket to which a device is connected.
108  *
109  * @param dev_id
110  *   Compress device identifier
111  * @return
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.
115  */
116 int __rte_experimental
117 rte_compressdev_socket_id(uint8_t dev_id);
118
119 /** Compress device configuration structure */
120 struct rte_compressdev_config {
121         int socket_id;
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 */
129 };
130
131 /**
132  * Configure a device.
133  *
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
136  * stopped state.
137  *
138  * @param dev_id
139  *   Compress device identifier
140  * @param config
141  *   The compress device configuration
142  * @return
143  *   - 0: Success, device configured.
144  *   - <0: Error code returned by the driver configuration function.
145  */
146 int __rte_experimental
147 rte_compressdev_configure(uint8_t dev_id,
148                         struct rte_compressdev_config *config);
149
150 /**
151  * Start a device.
152  *
153  * The device start step is called after configuring the device and setting up
154  * its queue pairs.
155  * On success, data-path functions exported by the API (enqueue/dequeue, etc)
156  * can be invoked.
157  *
158  * @param dev_id
159  *   Compress device identifier
160  * @return
161  *   - 0: Success, device started.
162  *   - <0: Error code of the driver device start function.
163  */
164 int __rte_experimental
165 rte_compressdev_start(uint8_t dev_id);
166
167 /**
168  * Stop a device. The device can be restarted with a call to
169  * rte_compressdev_start()
170  *
171  * @param dev_id
172  *   Compress device identifier
173  */
174 void __rte_experimental
175 rte_compressdev_stop(uint8_t dev_id);
176
177 /**
178  * Close an device.
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.
183  *
184  * @param dev_id
185  *   Compress device identifier
186  *
187  * @return
188  *  - 0 on successfully closing device
189  *  - <0 on failure to close device
190  */
191 int __rte_experimental
192 rte_compressdev_close(uint8_t dev_id);
193
194 /**
195  * Allocate and set up a receive queue pair for a device.
196  * This should only be called when the device is stopped.
197  *
198  *
199  * @param dev_id
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
208  * @param socket_id
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
213  * @return
214  *   - 0: Success, queue pair correctly set up.
215  *   - <0: Queue pair configuration failed
216  */
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);
220
221 /**
222  * Get the number of queue pairs on a specific comp device
223  *
224  * @param dev_id
225  *   Compress device identifier
226  * @return
227  *   - The number of configured queue pairs.
228  */
229 uint16_t __rte_experimental
230 rte_compressdev_queue_pair_count(uint8_t dev_id);
231
232 /**
233  * Retrieve the contextual information of a device.
234  *
235  * @param dev_id
236  *   Compress device identifier
237  * @param dev_info
238  *   A pointer to a structure of type *rte_compressdev_info*
239  *   to be filled with the contextual information of the device
240  *
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.
245  */
246 void __rte_experimental
247 rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info);
248
249 /**
250  *
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.
254  *
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.
258  *
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.
266  *
267  * The rte_compressdev_dequeue_burst() function does not provide any error
268  * notification to avoid the corresponding overhead.
269  *
270  * @note: operation ordering is not maintained within the queue pair.
271  *
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.
277  *
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
280  * output buffer.
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.
283  *
284  *
285  * @param dev_id
286  *   Compress device identifier
287  * @param qp_id
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()
292  * @param ops
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
296  * @param nb_ops
297  *   The maximum number of operations to dequeue
298  * @return
299  *   - The number of operations actually dequeued, which is the number
300  *   of pointers to *rte_comp_op* structures effectively supplied to the
301  *   *ops* array.
302  */
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);
306
307 /**
308  * Enqueue a burst of operations for processing on a compression device.
309  *
310  * The rte_compressdev_enqueue_burst() function is invoked to place
311  * comp operations on the queue *qp_id* of the device designated by
312  * its *dev_id*.
313  *
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.
316  *
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.
320  *
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.
323  *
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
328  * for decompression.
329  * @note: operation ordering is not maintained within the queue pair.
330  *
331  * @param dev_id
332  *   Compress device identifier
333  * @param qp_id
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*
338  * @param ops
339  *   The address of an array of *nb_ops* pointers
340  *   to *rte_comp_op* structures which contain
341  *   the operations to be processed
342  * @param nb_ops
343  *   The number of operations to process
344  * @return
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
348  *   a *rte_comp_op*.
349  */
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);
353
354 /**
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
361  *
362  * @param dev_id
363  *   Compress device identifier
364  * @param xform
365  *   xform data
366  * @param stream
367  *   Pointer to where PMD's private stream handle should be stored
368  *
369  * @return
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.
376  *
377  */
378 int __rte_experimental
379 rte_compressdev_stream_create(uint8_t dev_id,
380                 const struct rte_comp_xform *xform,
381                 void **stream);
382
383 /**
384  * This should clear the stream and return it to the device's mempool.
385  *
386  * @param dev_id
387  *   Compress device identifier
388  *
389  * @param stream
390  *   PMD's private stream data
391  *
392  * @return
393  *  - 0 if successful
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
398  */
399 int __rte_experimental
400 rte_compressdev_stream_free(uint8_t dev_id, void *stream);
401
402 /**
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.
409  *
410  * @param dev_id
411  *   Compress device identifier
412  * @param xform
413  *   xform data
414  * @param private_xform
415  *   Pointer to where PMD's private_xform handle should be stored
416  *
417  * @return
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.
424  */
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);
429
430 /**
431  * This should clear the private_xform and return it to the device's mempool.
432  *
433  * @param dev_id
434  *   Compress device identifier
435  *
436  * @param private_xform
437  *   PMD's private_xform data
438  *
439  * @return
440  *  - 0 if successful
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
444  */
445 int __rte_experimental
446 rte_compressdev_private_xform_free(uint8_t dev_id, void *private_xform);
447
448 #ifdef __cplusplus
449 }
450 #endif
451
452 #endif /* _RTE_COMPRESSDEV_H_ */