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