1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017-2018 Intel Corporation
11 * RTE definitions for Data Compression Service
19 #include <rte_mempool.h>
22 /** Status of comp operation */
23 enum rte_comp_op_status {
24 RTE_COMP_OP_STATUS_SUCCESS = 0,
25 /**< Operation completed successfully */
26 RTE_COMP_OP_STATUS_NOT_PROCESSED,
27 /**< Operation has not yet been processed by the device */
28 RTE_COMP_OP_STATUS_INVALID_ARGS,
29 /**< Operation failed due to invalid arguments in request */
30 RTE_COMP_OP_STATUS_ERROR,
31 /**< Error handling operation */
32 RTE_COMP_OP_STATUS_INVALID_STATE,
33 /**< Operation is invoked in invalid state */
34 RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED,
35 /**< Output buffer ran out of space before operation completed.
36 * Error case. Application must resubmit all data with a larger
39 RTE_COMP_OP_STATUS_OUT_OF_SPACE_RECOVERABLE,
40 /**< Output buffer ran out of space before operation completed, but this
41 * is not an error case. Output data up to op.produced can be used and
42 * next op in the stream should continue on from op.consumed+1.
46 /** Compression Algorithms */
47 enum rte_comp_algorithm {
48 RTE_COMP_ALGO_UNSPECIFIED = 0,
49 /** No Compression algorithm */
52 * Pass-through, data is copied unchanged from source buffer to
55 RTE_COMP_ALGO_DEFLATE,
56 /**< DEFLATE compression algorithm
57 * https://tools.ietf.org/html/rfc1951
60 /**< LZS compression algorithm
61 * https://tools.ietf.org/html/rfc2395
63 RTE_COMP_ALGO_LIST_END
66 /**< Compression Level.
67 * The number is interpreted by each PMD differently. However, lower numbers
68 * give fastest compression, at the expense of compression ratio while
69 * higher numbers may give better compression ratios but are likely slower.
71 #define RTE_COMP_LEVEL_PMD_DEFAULT (-1)
72 /** Use PMD Default */
73 #define RTE_COMP_LEVEL_NONE (0)
74 /** Output uncompressed blocks if supported by the specified algorithm */
75 #define RTE_COMP_LEVEL_MIN (1)
76 /** Use minimum compression level supported by the PMD */
77 #define RTE_COMP_LEVEL_MAX (9)
78 /** Use maximum compression level supported by the PMD */
80 /** Compression checksum types */
81 enum rte_comp_checksum_type {
82 RTE_COMP_CHECKSUM_NONE,
83 /**< No checksum generated */
84 RTE_COMP_CHECKSUM_CRC32,
85 /**< Generates a CRC32 checksum, as used by gzip */
86 RTE_COMP_CHECKSUM_ADLER32,
87 /**< Generates an Adler-32 checksum, as used by zlib */
88 RTE_COMP_CHECKSUM_CRC32_ADLER32,
89 /**< Generates both Adler-32 and CRC32 checksums, concatenated.
90 * CRC32 is in the lower 32bits, Adler-32 in the upper 32 bits.
95 /** Compression Huffman Type - used by DEFLATE algorithm */
96 enum rte_comp_huffman {
97 RTE_COMP_HUFFMAN_DEFAULT,
98 /**< PMD may choose which Huffman codes to use */
99 RTE_COMP_HUFFMAN_FIXED,
100 /**< Use Fixed Huffman codes */
101 RTE_COMP_HUFFMAN_DYNAMIC,
102 /**< Use Dynamic Huffman codes */
105 /** Compression flush flags */
106 enum rte_comp_flush_flag {
108 /**< Data is not flushed. Output may remain in the compressor and be
109 * processed during a following op. It may not be possible to decompress
110 * output until a later op with some other flush flag has been sent.
113 /**< All data should be flushed to output buffer. Output data can be
114 * decompressed. However state and history is not cleared, so future
115 * operations may use history from this operation.
118 /**< All data should be flushed to output buffer. Output data can be
119 * decompressed. State and history data is cleared, so future
120 * ops will be independent of ops processed before this.
123 /**< Same as RTE_COMP_FLUSH_FULL but if op.algo is RTE_COMP_ALGO_DEFLATE
124 * then bfinal bit is set in the last block.
128 /** Compression transform types */
129 enum rte_comp_xform_type {
131 /**< Compression service - compress */
133 /**< Compression service - decompress */
136 /** Compression operation type */
137 enum rte_comp_op_type {
138 RTE_COMP_OP_STATELESS,
139 /**< All data to be processed is submitted in the op, no state or
140 * history from previous ops is used and none will be stored for future
141 * ops. Flush flag must be set to either FLUSH_FULL or FLUSH_FINAL.
144 /**< There may be more data to be processed after this op, it's part of
145 * a stream of data. State and history from previous ops can be used
146 * and resulting state and history can be stored for future ops,
147 * depending on flush flag.
152 /** Parameters specific to the deflate algorithm */
153 struct rte_comp_deflate_params {
154 enum rte_comp_huffman huffman;
155 /**< Compression huffman encoding type */
158 /** Setup Data for compression */
159 struct rte_comp_compress_xform {
160 enum rte_comp_algorithm algo;
161 /**< Algorithm to use for compress operation */
163 struct rte_comp_deflate_params deflate;
164 /**< Parameters specific to the deflate algorithm */
165 }; /**< Algorithm specific parameters */
167 /**< Compression level */
169 /**< Base two log value of sliding window to be used. If window size
170 * can't be supported by the PMD then it may fall back to a smaller
171 * size. This is likely to result in a worse compression ratio.
173 enum rte_comp_checksum_type chksum;
174 /**< Type of checksum to generate on the uncompressed data */
178 * Setup Data for decompression.
180 struct rte_comp_decompress_xform {
181 enum rte_comp_algorithm algo;
182 /**< Algorithm to use for decompression */
183 enum rte_comp_checksum_type chksum;
184 /**< Type of checksum to generate on the decompressed data */
186 /**< Base two log value of sliding window which was used to generate
187 * compressed data. If window size can't be supported by the PMD then
188 * setup of stream or private_xform should fail.
193 * Compression transform structure.
195 * This is used to specify the compression transforms required.
196 * Each transform structure can hold a single transform, the type field is
197 * used to specify which transform is contained within the union.
199 struct rte_comp_xform {
200 enum rte_comp_xform_type type;
203 struct rte_comp_compress_xform compress;
204 /**< xform for compress operation */
205 struct rte_comp_decompress_xform decompress;
206 /**< decompress xform */
211 * Compression Operation.
213 * This structure contains data relating to performing a compression
214 * operation on the referenced mbuf data buffers.
216 * Comp operations are enqueued and dequeued in comp PMDs using the
217 * rte_compressdev_enqueue_burst() / rte_compressdev_dequeue_burst() APIs
220 enum rte_comp_op_type op_type;
223 /**< Stateless private PMD data derived from an rte_comp_xform.
224 * A handle returned by rte_compressdev_private_xform_create()
225 * must be attached to operations of op_type RTE_COMP_STATELESS.
228 /**< Private PMD data derived initially from an rte_comp_xform,
229 * which holds state and history data and evolves as operations
230 * are processed. rte_compressdev_stream_create() must be called
231 * on a device for all STATEFUL data streams and the resulting
232 * stream attached to the one or more operations associated
233 * with the data stream.
234 * All operations in a stream must be sent to the same device.
238 struct rte_mempool *mempool;
239 /**< Pool from which operation is allocated */
240 rte_iova_t iova_addr;
241 /**< IOVA address of this operation */
242 struct rte_mbuf *m_src;
244 * The total size of the input buffer(s) can be retrieved using
245 * rte_pktmbuf_data_len(m_src)
247 struct rte_mbuf *m_dst;
248 /**< destination mbuf
249 * The total size of the output buffer(s) can be retrieved using
250 * rte_pktmbuf_data_len(m_dst)
255 /**< Starting point for compression or decompression,
256 * specified as number of bytes from start of packet in
258 * Starting point for checksum generation in compress direction.
261 /**< The length, in bytes, of the data in source buffer
262 * to be compressed or decompressed.
263 * Also the length of the data over which the checksum
264 * should be generated in compress direction
269 /**< Starting point for writing output data, specified as
270 * number of bytes from start of packet in dest
271 * buffer. Starting point for checksum generation in
272 * decompress direction.
275 enum rte_comp_flush_flag flush_flag;
276 /**< Defines flush characteristics for the output data.
277 * Only applicable in compress direction
279 uint64_t input_chksum;
280 /**< An input checksum can be provided to generate a
281 * cumulative checksum across sequential blocks in a STATELESS stream.
282 * Checksum type is as specified in xform chksum_type
284 uint64_t output_chksum;
285 /**< If a checksum is generated it will be written in here.
286 * Checksum type is as specified in xform chksum_type.
289 /**< The number of bytes from the source buffer
290 * which were compressed/decompressed.
293 /**< The number of bytes written to the destination buffer
294 * which were compressed/decompressed.
296 uint64_t debug_status;
298 * Status of the operation is returned in the status param.
299 * This field allows the PMD to pass back extra
300 * pmd-specific debug information. Value is not defined on the API.
304 * Operation status - use values from enum rte_comp_status.
306 * RTE_COMP_OP_STATUS_NOT_PROCESSED on allocation from mempool and
307 * will be set to RTE_COMP_OP_STATUS_SUCCESS after operation
308 * is successfully processed by a PMD
310 } __rte_cache_aligned;
313 * Creates an operation pool
318 * Number of elements in pool
320 * Number of elements to cache on lcore, see
321 * *rte_mempool_create* for further details about cache size
323 * Size of private data to allocate for user with each operation
325 * Socket to identifier allocate memory on
327 * - On success pointer to mempool
330 struct rte_mempool * __rte_experimental
331 rte_comp_op_pool_create(const char *name,
332 unsigned int nb_elts, unsigned int cache_size,
333 uint16_t user_size, int socket_id);
336 * Allocate an operation from a mempool with default parameters set
339 * Compress operation mempool
342 * - On success returns a valid rte_comp_op structure
343 * - On failure returns NULL
345 struct rte_comp_op * __rte_experimental
346 rte_comp_op_alloc(struct rte_mempool *mempool);
349 * Bulk allocate operations from a mempool with default parameters set
352 * Compress operation mempool
354 * Array to place allocated operations
356 * Number of operations to allocate
359 * - -ENOENT: Not enough entries in the mempool; no ops are retrieved.
361 int __rte_experimental
362 rte_comp_op_bulk_alloc(struct rte_mempool *mempool,
363 struct rte_comp_op **ops, uint16_t nb_ops);
366 * Free operation structure
367 * If operation has been allocate from a rte_mempool, then the operation will
368 * be returned to the mempool.
373 void __rte_experimental
374 rte_comp_op_free(struct rte_comp_op *op);
380 #endif /* _RTE_COMP_H_ */