net: add rte prefix to ICMP structure
[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  * Parameter log base 2 range description.
26  * Final value will be 2^value.
27  */
28 struct rte_param_log2_range {
29         uint8_t min;    /**< Minimum log2 value */
30         uint8_t max;    /**< Maximum log2 value */
31         uint8_t increment;
32         /**< If a range of sizes are supported,
33          * this parameter is used to indicate
34          * increments in base 2 log byte value
35          * that are supported between the minimum and maximum
36          */
37 };
38
39 /** Structure used to capture a capability of a comp device */
40 struct rte_compressdev_capabilities {
41         enum rte_comp_algorithm algo;
42         /* Compression algorithm */
43         uint64_t comp_feature_flags;
44         /**< Bitmask of flags for compression service features */
45         struct rte_param_log2_range window_size;
46         /**< Window size range in base two log byte values */
47 };
48
49 /** Macro used at end of comp PMD list */
50 #define RTE_COMP_END_OF_CAPABILITIES_LIST() \
51         { RTE_COMP_ALGO_UNSPECIFIED }
52
53 const struct rte_compressdev_capabilities * __rte_experimental
54 rte_compressdev_capability_get(uint8_t dev_id,
55                         enum rte_comp_algorithm algo);
56
57 /**
58  * compression device supported feature flags
59  *
60  * @note New features flags should be added to the end of the list
61  *
62  * Keep these flags synchronised with rte_compressdev_get_feature_name()
63  */
64 #define RTE_COMPDEV_FF_HW_ACCELERATED           (1ULL << 0)
65 /**< Operations are off-loaded to an external hardware accelerator */
66 #define RTE_COMPDEV_FF_CPU_SSE                  (1ULL << 1)
67 /**< Utilises CPU SIMD SSE instructions */
68 #define RTE_COMPDEV_FF_CPU_AVX                  (1ULL << 2)
69 /**< Utilises CPU SIMD AVX instructions */
70 #define RTE_COMPDEV_FF_CPU_AVX2                 (1ULL << 3)
71 /**< Utilises CPU SIMD AVX2 instructions */
72 #define RTE_COMPDEV_FF_CPU_AVX512               (1ULL << 4)
73 /**< Utilises CPU SIMD AVX512 instructions */
74 #define RTE_COMPDEV_FF_CPU_NEON                 (1ULL << 5)
75 /**< Utilises CPU NEON instructions */
76 #define RTE_COMPDEV_FF_OP_DONE_IN_DEQUEUE       (1ULL << 6)
77 /**< A PMD should set this if the bulk of the
78  * processing is done during the dequeue. It should leave it
79  * cleared if the processing is done during the enqueue (default).
80  * Applications can use this as a hint for tuning.
81  */
82
83 /**
84  * Get the name of a compress device feature flag.
85  *
86  * @param flag
87  *   The mask describing the flag
88  *
89  * @return
90  *   The name of this flag, or NULL if it's not a valid feature flag.
91  */
92 const char * __rte_experimental
93 rte_compressdev_get_feature_name(uint64_t flag);
94
95 /**  comp device information */
96 struct rte_compressdev_info {
97         const char *driver_name;                /**< Driver name. */
98         uint64_t feature_flags;                 /**< Feature flags */
99         const struct rte_compressdev_capabilities *capabilities;
100         /**< Array of devices supported capabilities */
101         uint16_t max_nb_queue_pairs;
102         /**< Maximum number of queues pairs supported by device.
103          * (If 0, there is no limit in maximum number of queue pairs)
104          */
105 };
106
107 /** comp device statistics */
108 struct rte_compressdev_stats {
109         uint64_t enqueued_count;
110         /**< Count of all operations enqueued */
111         uint64_t dequeued_count;
112         /**< Count of all operations dequeued */
113
114         uint64_t enqueue_err_count;
115         /**< Total error count on operations enqueued */
116         uint64_t dequeue_err_count;
117         /**< Total error count on operations dequeued */
118 };
119
120
121 /**
122  * Get the device identifier for the named compress device.
123  *
124  * @param name
125  *   Device name to select the device structure
126  * @return
127  *   - Returns compress device identifier on success.
128  *   - Return -1 on failure to find named compress device.
129  */
130 int __rte_experimental
131 rte_compressdev_get_dev_id(const char *name);
132
133 /**
134  * Get the compress device name given a device identifier.
135  *
136  * @param dev_id
137  *   Compress device identifier
138  * @return
139  *   - Returns compress device name.
140  *   - Returns NULL if compress device is not present.
141  */
142 const char * __rte_experimental
143 rte_compressdev_name_get(uint8_t dev_id);
144
145 /**
146  * Get the total number of compress devices that have been successfully
147  * initialised.
148  *
149  * @return
150  *   - The total number of usable compress devices.
151  */
152 uint8_t __rte_experimental
153 rte_compressdev_count(void);
154
155 /**
156  * Get number and identifiers of attached comp devices that
157  * use the same compress driver.
158  *
159  * @param driver_name
160  *   Driver name
161  * @param devices
162  *   Output devices identifiers
163  * @param nb_devices
164  *   Maximal number of devices
165  *
166  * @return
167  *   Returns number of attached compress devices.
168  */
169 uint8_t __rte_experimental
170 rte_compressdev_devices_get(const char *driver_name, uint8_t *devices,
171                 uint8_t nb_devices);
172
173 /*
174  * Return the NUMA socket to which a device is connected.
175  *
176  * @param dev_id
177  *   Compress device identifier
178  * @return
179  *   The NUMA socket id to which the device is connected or
180  *   a default of zero if the socket could not be determined.
181  *   -1 if returned is the dev_id value is out of range.
182  */
183 int __rte_experimental
184 rte_compressdev_socket_id(uint8_t dev_id);
185
186 /** Compress device configuration structure */
187 struct rte_compressdev_config {
188         int socket_id;
189         /**< Socket on which to allocate resources */
190         uint16_t nb_queue_pairs;
191         /**< Total number of queue pairs to configure on a device */
192         uint16_t max_nb_priv_xforms;
193         /**< Max number of private_xforms which will be created on the device */
194         uint16_t max_nb_streams;
195         /**< Max number of streams which will be created on the device */
196 };
197
198 /**
199  * Configure a device.
200  *
201  * This function must be invoked first before any other function in the
202  * API. This function can also be re-invoked when a device is in the
203  * stopped state.
204  *
205  * @param dev_id
206  *   Compress device identifier
207  * @param config
208  *   The compress device configuration
209  * @return
210  *   - 0: Success, device configured.
211  *   - <0: Error code returned by the driver configuration function.
212  */
213 int __rte_experimental
214 rte_compressdev_configure(uint8_t dev_id,
215                         struct rte_compressdev_config *config);
216
217 /**
218  * Start a device.
219  *
220  * The device start step is called after configuring the device and setting up
221  * its queue pairs.
222  * On success, data-path functions exported by the API (enqueue/dequeue, etc)
223  * can be invoked.
224  *
225  * @param dev_id
226  *   Compress device identifier
227  * @return
228  *   - 0: Success, device started.
229  *   - <0: Error code of the driver device start function.
230  */
231 int __rte_experimental
232 rte_compressdev_start(uint8_t dev_id);
233
234 /**
235  * Stop a device. The device can be restarted with a call to
236  * rte_compressdev_start()
237  *
238  * @param dev_id
239  *   Compress device identifier
240  */
241 void __rte_experimental
242 rte_compressdev_stop(uint8_t dev_id);
243
244 /**
245  * Close an device.
246  * The memory allocated in the device gets freed.
247  * After calling this function, in order to use
248  * the device again, it is required to
249  * configure the device again.
250  *
251  * @param dev_id
252  *   Compress device identifier
253  *
254  * @return
255  *  - 0 on successfully closing device
256  *  - <0 on failure to close device
257  */
258 int __rte_experimental
259 rte_compressdev_close(uint8_t dev_id);
260
261 /**
262  * Allocate and set up a receive queue pair for a device.
263  * This should only be called when the device is stopped.
264  *
265  *
266  * @param dev_id
267  *   Compress device identifier
268  * @param queue_pair_id
269  *   The index of the queue pairs to set up. The
270  *   value must be in the range [0, nb_queue_pair - 1]
271  *   previously supplied to rte_compressdev_configure()
272  * @param max_inflight_ops
273  *   Max number of ops which the qp will have to
274  *   accommodate simultaneously
275  * @param socket_id
276  *   The *socket_id* argument is the socket identifier
277  *   in case of NUMA. The value can be *SOCKET_ID_ANY*
278  *   if there is no NUMA constraint for the DMA memory
279  *   allocated for the receive queue pair
280  * @return
281  *   - 0: Success, queue pair correctly set up.
282  *   - <0: Queue pair configuration failed
283  */
284 int __rte_experimental
285 rte_compressdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
286                 uint32_t max_inflight_ops, int socket_id);
287
288 /**
289  * Get the number of queue pairs on a specific comp device
290  *
291  * @param dev_id
292  *   Compress device identifier
293  * @return
294  *   - The number of configured queue pairs.
295  */
296 uint16_t __rte_experimental
297 rte_compressdev_queue_pair_count(uint8_t dev_id);
298
299
300 /**
301  * Retrieve the general I/O statistics of a device.
302  *
303  * @param dev_id
304  *   The identifier of the device
305  * @param stats
306  *   A pointer to a structure of type
307  *   *rte_compressdev_stats* to be filled with the
308  *   values of device counters
309  * @return
310  *   - Zero if successful.
311  *   - Non-zero otherwise.
312  */
313 int __rte_experimental
314 rte_compressdev_stats_get(uint8_t dev_id, struct rte_compressdev_stats *stats);
315
316 /**
317  * Reset the general I/O statistics of a device.
318  *
319  * @param dev_id
320  *   The identifier of the device.
321  */
322 void __rte_experimental
323 rte_compressdev_stats_reset(uint8_t dev_id);
324
325 /**
326  * Retrieve the contextual information of a device.
327  *
328  * @param dev_id
329  *   Compress device identifier
330  * @param dev_info
331  *   A pointer to a structure of type *rte_compressdev_info*
332  *   to be filled with the contextual information of the device
333  *
334  * @note The capabilities field of dev_info is set to point to the first
335  * element of an array of struct rte_compressdev_capabilities.
336  * The element after the last valid element has it's op field set to
337  * RTE_COMP_ALGO_LIST_END.
338  */
339 void __rte_experimental
340 rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info);
341
342 /**
343  *
344  * Dequeue a burst of processed compression operations from a queue on the comp
345  * device. The dequeued operation are stored in *rte_comp_op* structures
346  * whose pointers are supplied in the *ops* array.
347  *
348  * The rte_compressdev_dequeue_burst() function returns the number of ops
349  * actually dequeued, which is the number of *rte_comp_op* data structures
350  * effectively supplied into the *ops* array.
351  *
352  * A return value equal to *nb_ops* indicates that the queue contained
353  * at least *nb_ops* operations, and this is likely to signify that other
354  * processed operations remain in the devices output queue. Applications
355  * implementing a "retrieve as many processed operations as possible" policy
356  * can check this specific case and keep invoking the
357  * rte_compressdev_dequeue_burst() function until a value less than
358  * *nb_ops* is returned.
359  *
360  * The rte_compressdev_dequeue_burst() function does not provide any error
361  * notification to avoid the corresponding overhead.
362  *
363  * @note: operation ordering is not maintained within the queue pair.
364  *
365  * @note: In case op status = OUT_OF_SPACE_TERMINATED, op.consumed=0 and the
366  * op must be resubmitted with the same input data and a larger output buffer.
367  * op.produced is usually 0, but in decompression cases a PMD may return > 0
368  * and the application may find it useful to inspect that data.
369  * This status is only returned on STATELESS ops.
370  *
371  * @note: In case op status = OUT_OF_SPACE_RECOVERABLE, op.produced can be used
372  * and next op in stream should continue on from op.consumed+1 with a fresh
373  * output buffer.
374  * Consumed=0, produced=0 is an unusual but allowed case. There may be useful
375  * state/history stored in the PMD, even though no output was produced yet.
376  *
377  *
378  * @param dev_id
379  *   Compress device identifier
380  * @param qp_id
381  *   The index of the queue pair from which to retrieve
382  *   processed operations. The value must be in the range
383  *   [0, nb_queue_pair - 1] previously supplied to
384  *   rte_compressdev_configure()
385  * @param ops
386  *   The address of an array of pointers to
387  *   *rte_comp_op* structures that must be
388  *   large enough to store *nb_ops* pointers in it
389  * @param nb_ops
390  *   The maximum number of operations to dequeue
391  * @return
392  *   - The number of operations actually dequeued, which is the number
393  *   of pointers to *rte_comp_op* structures effectively supplied to the
394  *   *ops* array.
395  */
396 uint16_t __rte_experimental
397 rte_compressdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
398                 struct rte_comp_op **ops, uint16_t nb_ops);
399
400 /**
401  * Enqueue a burst of operations for processing on a compression device.
402  *
403  * The rte_compressdev_enqueue_burst() function is invoked to place
404  * comp operations on the queue *qp_id* of the device designated by
405  * its *dev_id*.
406  *
407  * The *nb_ops* parameter is the number of operations to process which are
408  * supplied in the *ops* array of *rte_comp_op* structures.
409  *
410  * The rte_compressdev_enqueue_burst() function returns the number of
411  * operations it actually enqueued for processing. A return value equal to
412  * *nb_ops* means that all packets have been enqueued.
413  *
414  * @note All compression operations are Out-of-place (OOP) operations,
415  * as the size of the output data is different to the size of the input data.
416  *
417  * @note The rte_comp_op contains both input and output parameters and is the
418  * vehicle for the application to pass data into and out of the PMD. While an
419  * op is inflight, i.e. once it has been enqueued, the private_xform or stream
420  * attached to it and any mbufs or memory referenced by it should not be altered
421  * or freed by the application. The PMD may use or change some of this data at
422  * any time until it has been returned in a dequeue operation.
423  *
424  * @note The flush flag only applies to operations which return SUCCESS.
425  * In OUT_OF_SPACE cases whether STATEFUL or STATELESS, data in dest buffer
426  * is as if flush flag was FLUSH_NONE.
427  * @note flush flag only applies in compression direction. It has no meaning
428  * for decompression.
429  * @note: operation ordering is not maintained within the queue pair.
430  *
431  * @param dev_id
432  *   Compress device identifier
433  * @param qp_id
434  *   The index of the queue pair on which operations
435  *   are to be enqueued for processing. The value
436  *   must be in the range [0, nb_queue_pairs - 1]
437  *   previously supplied to *rte_compressdev_configure*
438  * @param ops
439  *   The address of an array of *nb_ops* pointers
440  *   to *rte_comp_op* structures which contain
441  *   the operations to be processed
442  * @param nb_ops
443  *   The number of operations to process
444  * @return
445  *   The number of operations actually enqueued on the device. The return
446  *   value can be less than the value of the *nb_ops* parameter when the
447  *   comp devices queue is full or if invalid parameters are specified in
448  *   a *rte_comp_op*.
449  */
450 uint16_t __rte_experimental
451 rte_compressdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
452                 struct rte_comp_op **ops, uint16_t nb_ops);
453
454 /**
455  * This should alloc a stream from the device's mempool and initialise it.
456  * The application should call this API when setting up for the stateful
457  * processing of a set of data on a device. The API can be called multiple
458  * times to set up a stream for each data set. The handle returned is only for
459  * use with ops of op_type STATEFUL and must be passed to the PMD
460  * with every op in the data stream
461  *
462  * @param dev_id
463  *   Compress device identifier
464  * @param xform
465  *   xform data
466  * @param stream
467  *   Pointer to where PMD's private stream handle should be stored
468  *
469  * @return
470  *  - 0 if successful and valid stream handle
471  *  - <0 in error cases
472  *  - Returns -EINVAL if input parameters are invalid.
473  *  - Returns -ENOTSUP if comp device does not support STATEFUL operations.
474  *  - Returns -ENOTSUP if comp device does not support the comp transform.
475  *  - Returns -ENOMEM if the private stream could not be allocated.
476  *
477  */
478 int __rte_experimental
479 rte_compressdev_stream_create(uint8_t dev_id,
480                 const struct rte_comp_xform *xform,
481                 void **stream);
482
483 /**
484  * This should clear the stream and return it to the device's mempool.
485  *
486  * @param dev_id
487  *   Compress device identifier
488  *
489  * @param stream
490  *   PMD's private stream data
491  *
492  * @return
493  *  - 0 if successful
494  *  - <0 in error cases
495  *  - Returns -EINVAL if input parameters are invalid.
496  *  - Returns -ENOTSUP if comp device does not support STATEFUL operations.
497  *  - Returns -EBUSY if can't free stream as there are inflight operations
498  */
499 int __rte_experimental
500 rte_compressdev_stream_free(uint8_t dev_id, void *stream);
501
502 /**
503  * This should alloc a private_xform from the device's mempool and initialise
504  * it. The application should call this API when setting up for stateless
505  * processing on a device. If it returns non-shareable, then the appl cannot
506  * share this handle with multiple in-flight ops and should call this API again
507  * to get a separate handle for every in-flight op.
508  * The handle returned is only valid for use with ops of op_type STATELESS.
509  *
510  * @param dev_id
511  *   Compress device identifier
512  * @param xform
513  *   xform data
514  * @param private_xform
515  *   Pointer to where PMD's private_xform handle should be stored
516  *
517  * @return
518  *  - if successful returns 0
519  *    and valid private_xform handle
520  *  - <0 in error cases
521  *  - Returns -EINVAL if input parameters are invalid.
522  *  - Returns -ENOTSUP if comp device does not support the comp transform.
523  *  - Returns -ENOMEM if the private_xform could not be allocated.
524  */
525 int __rte_experimental
526 rte_compressdev_private_xform_create(uint8_t dev_id,
527                 const struct rte_comp_xform *xform,
528                 void **private_xform);
529
530 /**
531  * This should clear the private_xform and return it to the device's mempool.
532  * It is the application's responsibility to ensure that private_xform data
533  * is not cleared while there are still in-flight operations using it.
534  *
535  * @param dev_id
536  *   Compress device identifier
537  *
538  * @param private_xform
539  *   PMD's private_xform data
540  *
541  * @return
542  *  - 0 if successful
543  *  - <0 in error cases
544  *  - Returns -EINVAL if input parameters are invalid.
545  */
546 int __rte_experimental
547 rte_compressdev_private_xform_free(uint8_t dev_id, void *private_xform);
548
549 #ifdef __cplusplus
550 }
551 #endif
552
553 #endif /* _RTE_COMPRESSDEV_H_ */