compressdev: add device stats
[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 /** comp device statistics */
67 struct rte_compressdev_stats {
68         uint64_t enqueued_count;
69         /**< Count of all operations enqueued */
70         uint64_t dequeued_count;
71         /**< Count of all operations dequeued */
72
73         uint64_t enqueue_err_count;
74         /**< Total error count on operations enqueued */
75         uint64_t dequeue_err_count;
76         /**< Total error count on operations dequeued */
77 };
78
79 /**
80  * Get the compress device name given a device identifier.
81  *
82  * @param dev_id
83  *   Compress device identifier
84  * @return
85  *   - Returns compress device name.
86  *   - Returns NULL if compress device is not present.
87  */
88 const char * __rte_experimental
89 rte_compressdev_name_get(uint8_t dev_id);
90
91 /**
92  * Get the total number of compress devices that have been successfully
93  * initialised.
94  *
95  * @return
96  *   - The total number of usable compress devices.
97  */
98 uint8_t __rte_experimental
99 rte_compressdev_count(void);
100
101 /**
102  * Get number and identifiers of attached comp devices that
103  * use the same compress driver.
104  *
105  * @param driver_name
106  *   Driver name
107  * @param devices
108  *   Output devices identifiers
109  * @param nb_devices
110  *   Maximal number of devices
111  *
112  * @return
113  *   Returns number of attached compress devices.
114  */
115 uint8_t __rte_experimental
116 rte_compressdev_devices_get(const char *driver_name, uint8_t *devices,
117                 uint8_t nb_devices);
118
119 /*
120  * Return the NUMA socket to which a device is connected.
121  *
122  * @param dev_id
123  *   Compress device identifier
124  * @return
125  *   The NUMA socket id to which the device is connected or
126  *   a default of zero if the socket could not be determined.
127  *   -1 if returned is the dev_id value is out of range.
128  */
129 int __rte_experimental
130 rte_compressdev_socket_id(uint8_t dev_id);
131
132 /** Compress device configuration structure */
133 struct rte_compressdev_config {
134         int socket_id;
135         /**< Socket on which to allocate resources */
136         uint16_t nb_queue_pairs;
137         /**< Total number of queue pairs to configure on a device */
138         uint16_t max_nb_priv_xforms;
139         /**< Max number of private_xforms which will be created on the device */
140         uint16_t max_nb_streams;
141         /**< Max number of streams which will be created on the device */
142 };
143
144 /**
145  * Configure a device.
146  *
147  * This function must be invoked first before any other function in the
148  * API. This function can also be re-invoked when a device is in the
149  * stopped state.
150  *
151  * @param dev_id
152  *   Compress device identifier
153  * @param config
154  *   The compress device configuration
155  * @return
156  *   - 0: Success, device configured.
157  *   - <0: Error code returned by the driver configuration function.
158  */
159 int __rte_experimental
160 rte_compressdev_configure(uint8_t dev_id,
161                         struct rte_compressdev_config *config);
162
163 /**
164  * Start a device.
165  *
166  * The device start step is called after configuring the device and setting up
167  * its queue pairs.
168  * On success, data-path functions exported by the API (enqueue/dequeue, etc)
169  * can be invoked.
170  *
171  * @param dev_id
172  *   Compress device identifier
173  * @return
174  *   - 0: Success, device started.
175  *   - <0: Error code of the driver device start function.
176  */
177 int __rte_experimental
178 rte_compressdev_start(uint8_t dev_id);
179
180 /**
181  * Stop a device. The device can be restarted with a call to
182  * rte_compressdev_start()
183  *
184  * @param dev_id
185  *   Compress device identifier
186  */
187 void __rte_experimental
188 rte_compressdev_stop(uint8_t dev_id);
189
190 /**
191  * Close an device.
192  * The memory allocated in the device gets freed.
193  * After calling this function, in order to use
194  * the device again, it is required to
195  * configure the device again.
196  *
197  * @param dev_id
198  *   Compress device identifier
199  *
200  * @return
201  *  - 0 on successfully closing device
202  *  - <0 on failure to close device
203  */
204 int __rte_experimental
205 rte_compressdev_close(uint8_t dev_id);
206
207 /**
208  * Allocate and set up a receive queue pair for a device.
209  * This should only be called when the device is stopped.
210  *
211  *
212  * @param dev_id
213  *   Compress device identifier
214  * @param queue_pair_id
215  *   The index of the queue pairs to set up. The
216  *   value must be in the range [0, nb_queue_pair - 1]
217  *   previously supplied to rte_compressdev_configure()
218  * @param max_inflight_ops
219  *   Max number of ops which the qp will have to
220  *   accommodate simultaneously
221  * @param socket_id
222  *   The *socket_id* argument is the socket identifier
223  *   in case of NUMA. The value can be *SOCKET_ID_ANY*
224  *   if there is no NUMA constraint for the DMA memory
225  *   allocated for the receive queue pair
226  * @return
227  *   - 0: Success, queue pair correctly set up.
228  *   - <0: Queue pair configuration failed
229  */
230 int __rte_experimental
231 rte_compressdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
232                 uint32_t max_inflight_ops, int socket_id);
233
234 /**
235  * Get the number of queue pairs on a specific comp device
236  *
237  * @param dev_id
238  *   Compress device identifier
239  * @return
240  *   - The number of configured queue pairs.
241  */
242 uint16_t __rte_experimental
243 rte_compressdev_queue_pair_count(uint8_t dev_id);
244
245
246 /**
247  * Retrieve the general I/O statistics of a device.
248  *
249  * @param dev_id
250  *   The identifier of the device
251  * @param stats
252  *   A pointer to a structure of type
253  *   *rte_compressdev_stats* to be filled with the
254  *   values of device counters
255  * @return
256  *   - Zero if successful.
257  *   - Non-zero otherwise.
258  */
259 int __rte_experimental
260 rte_compressdev_stats_get(uint8_t dev_id, struct rte_compressdev_stats *stats);
261
262 /**
263  * Reset the general I/O statistics of a device.
264  *
265  * @param dev_id
266  *   The identifier of the device.
267  */
268 void __rte_experimental
269 rte_compressdev_stats_reset(uint8_t dev_id);
270
271 /**
272  * Retrieve the contextual information of a device.
273  *
274  * @param dev_id
275  *   Compress device identifier
276  * @param dev_info
277  *   A pointer to a structure of type *rte_compressdev_info*
278  *   to be filled with the contextual information of the device
279  *
280  * @note The capabilities field of dev_info is set to point to the first
281  * element of an array of struct rte_compressdev_capabilities.
282  * The element after the last valid element has it's op field set to
283  * RTE_COMP_ALGO_LIST_END.
284  */
285 void __rte_experimental
286 rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info);
287
288 /**
289  *
290  * Dequeue a burst of processed compression operations from a queue on the comp
291  * device. The dequeued operation are stored in *rte_comp_op* structures
292  * whose pointers are supplied in the *ops* array.
293  *
294  * The rte_compressdev_dequeue_burst() function returns the number of ops
295  * actually dequeued, which is the number of *rte_comp_op* data structures
296  * effectively supplied into the *ops* array.
297  *
298  * A return value equal to *nb_ops* indicates that the queue contained
299  * at least *nb_ops* operations, and this is likely to signify that other
300  * processed operations remain in the devices output queue. Applications
301  * implementing a "retrieve as many processed operations as possible" policy
302  * can check this specific case and keep invoking the
303  * rte_compressdev_dequeue_burst() function until a value less than
304  * *nb_ops* is returned.
305  *
306  * The rte_compressdev_dequeue_burst() function does not provide any error
307  * notification to avoid the corresponding overhead.
308  *
309  * @note: operation ordering is not maintained within the queue pair.
310  *
311  * @note: In case op status = OUT_OF_SPACE_TERMINATED, op.consumed=0 and the
312  * op must be resubmitted with the same input data and a larger output buffer.
313  * op.produced is usually 0, but in decompression cases a PMD may return > 0
314  * and the application may find it useful to inspect that data.
315  * This status is only returned on STATELESS ops.
316  *
317  * @note: In case op status = OUT_OF_SPACE_RECOVERABLE, op.produced can be used
318  * and next op in stream should continue on from op.consumed+1 with a fresh
319  * output buffer.
320  * Consumed=0, produced=0 is an unusual but allowed case. There may be useful
321  * state/history stored in the PMD, even though no output was produced yet.
322  *
323  *
324  * @param dev_id
325  *   Compress device identifier
326  * @param qp_id
327  *   The index of the queue pair from which to retrieve
328  *   processed operations. The value must be in the range
329  *   [0, nb_queue_pair - 1] previously supplied to
330  *   rte_compressdev_configure()
331  * @param ops
332  *   The address of an array of pointers to
333  *   *rte_comp_op* structures that must be
334  *   large enough to store *nb_ops* pointers in it
335  * @param nb_ops
336  *   The maximum number of operations to dequeue
337  * @return
338  *   - The number of operations actually dequeued, which is the number
339  *   of pointers to *rte_comp_op* structures effectively supplied to the
340  *   *ops* array.
341  */
342 uint16_t __rte_experimental
343 rte_compressdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
344                 struct rte_comp_op **ops, uint16_t nb_ops);
345
346 /**
347  * Enqueue a burst of operations for processing on a compression device.
348  *
349  * The rte_compressdev_enqueue_burst() function is invoked to place
350  * comp operations on the queue *qp_id* of the device designated by
351  * its *dev_id*.
352  *
353  * The *nb_ops* parameter is the number of operations to process which are
354  * supplied in the *ops* array of *rte_comp_op* structures.
355  *
356  * The rte_compressdev_enqueue_burst() function returns the number of
357  * operations it actually enqueued for processing. A return value equal to
358  * *nb_ops* means that all packets have been enqueued.
359  *
360  * @note All compression operations are Out-of-place (OOP) operations,
361  * as the size of the output data is different to the size of the input data.
362  *
363  * @note The flush flag only applies to operations which return SUCCESS.
364  * In OUT_OF_SPACE cases whether STATEFUL or STATELESS, data in dest buffer
365  * is as if flush flag was FLUSH_NONE.
366  * @note flush flag only applies in compression direction. It has no meaning
367  * for decompression.
368  * @note: operation ordering is not maintained within the queue pair.
369  *
370  * @param dev_id
371  *   Compress device identifier
372  * @param qp_id
373  *   The index of the queue pair on which operations
374  *   are to be enqueued for processing. The value
375  *   must be in the range [0, nb_queue_pairs - 1]
376  *   previously supplied to *rte_compressdev_configure*
377  * @param ops
378  *   The address of an array of *nb_ops* pointers
379  *   to *rte_comp_op* structures which contain
380  *   the operations to be processed
381  * @param nb_ops
382  *   The number of operations to process
383  * @return
384  *   The number of operations actually enqueued on the device. The return
385  *   value can be less than the value of the *nb_ops* parameter when the
386  *   comp devices queue is full or if invalid parameters are specified in
387  *   a *rte_comp_op*.
388  */
389 uint16_t __rte_experimental
390 rte_compressdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
391                 struct rte_comp_op **ops, uint16_t nb_ops);
392
393 /**
394  * This should alloc a stream from the device's mempool and initialise it.
395  * The application should call this API when setting up for the stateful
396  * processing of a set of data on a device. The API can be called multiple
397  * times to set up a stream for each data set. The handle returned is only for
398  * use with ops of op_type STATEFUL and must be passed to the PMD
399  * with every op in the data stream
400  *
401  * @param dev_id
402  *   Compress device identifier
403  * @param xform
404  *   xform data
405  * @param stream
406  *   Pointer to where PMD's private stream handle should be stored
407  *
408  * @return
409  *  - 0 if successful and valid stream handle
410  *  - <0 in error cases
411  *  - Returns -EINVAL if input parameters are invalid.
412  *  - Returns -ENOTSUP if comp device does not support STATEFUL operations.
413  *  - Returns -ENOTSUP if comp device does not support the comp transform.
414  *  - Returns -ENOMEM if the private stream could not be allocated.
415  *
416  */
417 int __rte_experimental
418 rte_compressdev_stream_create(uint8_t dev_id,
419                 const struct rte_comp_xform *xform,
420                 void **stream);
421
422 /**
423  * This should clear the stream and return it to the device's mempool.
424  *
425  * @param dev_id
426  *   Compress device identifier
427  *
428  * @param stream
429  *   PMD's private stream data
430  *
431  * @return
432  *  - 0 if successful
433  *  - <0 in error cases
434  *  - Returns -EINVAL if input parameters are invalid.
435  *  - Returns -ENOTSUP if comp device does not support STATEFUL operations.
436  *  - Returns -EBUSY if can't free stream as there are inflight operations
437  */
438 int __rte_experimental
439 rte_compressdev_stream_free(uint8_t dev_id, void *stream);
440
441 /**
442  * This should alloc a private_xform from the device's mempool and initialise
443  * it. The application should call this API when setting up for stateless
444  * processing on a device. If it returns non-shareable, then the appl cannot
445  * share this handle with multiple in-flight ops and should call this API again
446  * to get a separate handle for every in-flight op.
447  * The handle returned is only valid for use with ops of op_type STATELESS.
448  *
449  * @param dev_id
450  *   Compress device identifier
451  * @param xform
452  *   xform data
453  * @param private_xform
454  *   Pointer to where PMD's private_xform handle should be stored
455  *
456  * @return
457  *  - if successful returns 0
458  *    and valid private_xform handle
459  *  - <0 in error cases
460  *  - Returns -EINVAL if input parameters are invalid.
461  *  - Returns -ENOTSUP if comp device does not support the comp transform.
462  *  - Returns -ENOMEM if the private_xform could not be allocated.
463  */
464 int __rte_experimental
465 rte_compressdev_private_xform_create(uint8_t dev_id,
466                 const struct rte_comp_xform *xform,
467                 void **private_xform);
468
469 /**
470  * This should clear the private_xform and return it to the device's mempool.
471  *
472  * @param dev_id
473  *   Compress device identifier
474  *
475  * @param private_xform
476  *   PMD's private_xform data
477  *
478  * @return
479  *  - 0 if successful
480  *  - <0 in error cases
481  *  - Returns -EINVAL if input parameters are invalid.
482  *  - Returns -EBUSY if can't free private_xform due to inflight operations
483  */
484 int __rte_experimental
485 rte_compressdev_private_xform_free(uint8_t dev_id, void *private_xform);
486
487 #ifdef __cplusplus
488 }
489 #endif
490
491 #endif /* _RTE_COMPRESSDEV_H_ */