199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2017-2018 Intel Corporation 399a2dd95SBruce Richardson */ 499a2dd95SBruce Richardson 599a2dd95SBruce Richardson #ifndef _RTE_COMP_H_ 699a2dd95SBruce Richardson #define _RTE_COMP_H_ 799a2dd95SBruce Richardson 899a2dd95SBruce Richardson /** 999a2dd95SBruce Richardson * @file rte_comp.h 1099a2dd95SBruce Richardson * 1199a2dd95SBruce Richardson * RTE definitions for Data Compression Service 1299a2dd95SBruce Richardson */ 1399a2dd95SBruce Richardson 14*719834a6SMattias Rönnblom #include <rte_mbuf.h> 15*719834a6SMattias Rönnblom 1699a2dd95SBruce Richardson #ifdef __cplusplus 1799a2dd95SBruce Richardson extern "C" { 1899a2dd95SBruce Richardson #endif 1999a2dd95SBruce Richardson 2099a2dd95SBruce Richardson /** 2199a2dd95SBruce Richardson * compression service feature flags 2299a2dd95SBruce Richardson * 2399a2dd95SBruce Richardson * @note New features flags should be added to the end of the list 2499a2dd95SBruce Richardson * 2599a2dd95SBruce Richardson * Keep these flags synchronised with rte_comp_get_feature_name() 2699a2dd95SBruce Richardson */ 2799a2dd95SBruce Richardson #define RTE_COMP_FF_STATEFUL_COMPRESSION (1ULL << 0) 2899a2dd95SBruce Richardson /**< Stateful compression is supported */ 2999a2dd95SBruce Richardson #define RTE_COMP_FF_STATEFUL_DECOMPRESSION (1ULL << 1) 3099a2dd95SBruce Richardson /**< Stateful decompression is supported */ 3199a2dd95SBruce Richardson #define RTE_COMP_FF_OOP_SGL_IN_SGL_OUT (1ULL << 2) 3299a2dd95SBruce Richardson /**< Out-of-place Scatter-gather (SGL) buffers, 3399a2dd95SBruce Richardson * with multiple segments, are supported in input and output 3499a2dd95SBruce Richardson */ 3599a2dd95SBruce Richardson #define RTE_COMP_FF_OOP_SGL_IN_LB_OUT (1ULL << 3) 3699a2dd95SBruce Richardson /**< Out-of-place Scatter-gather (SGL) buffers are supported 3799a2dd95SBruce Richardson * in input, combined with linear buffers (LB), with a 3899a2dd95SBruce Richardson * single segment, in output 3999a2dd95SBruce Richardson */ 4099a2dd95SBruce Richardson #define RTE_COMP_FF_OOP_LB_IN_SGL_OUT (1ULL << 4) 4199a2dd95SBruce Richardson /**< Out-of-place Scatter-gather (SGL) buffers are supported 4299a2dd95SBruce Richardson * in output, combined with linear buffers (LB) in input 4399a2dd95SBruce Richardson */ 4499a2dd95SBruce Richardson #define RTE_COMP_FF_ADLER32_CHECKSUM (1ULL << 5) 4599a2dd95SBruce Richardson /**< Adler-32 Checksum is supported */ 4699a2dd95SBruce Richardson #define RTE_COMP_FF_CRC32_CHECKSUM (1ULL << 6) 4799a2dd95SBruce Richardson /**< CRC32 Checksum is supported */ 4899a2dd95SBruce Richardson #define RTE_COMP_FF_CRC32_ADLER32_CHECKSUM (1ULL << 7) 4999a2dd95SBruce Richardson /**< Adler-32/CRC32 Checksum is supported */ 5099a2dd95SBruce Richardson #define RTE_COMP_FF_MULTI_PKT_CHECKSUM (1ULL << 8) 5199a2dd95SBruce Richardson /**< Generation of checksum across multiple stateless packets is supported */ 5299a2dd95SBruce Richardson #define RTE_COMP_FF_SHA1_HASH (1ULL << 9) 5399a2dd95SBruce Richardson /**< SHA1 Hash is supported */ 5499a2dd95SBruce Richardson #define RTE_COMP_FF_SHA2_SHA256_HASH (1ULL << 10) 5599a2dd95SBruce Richardson /**< SHA256 Hash of SHA2 family is supported */ 5699a2dd95SBruce Richardson #define RTE_COMP_FF_NONCOMPRESSED_BLOCKS (1ULL << 11) 5799a2dd95SBruce Richardson /**< Creation of non-compressed blocks using RTE_COMP_LEVEL_NONE is supported */ 5899a2dd95SBruce Richardson #define RTE_COMP_FF_SHAREABLE_PRIV_XFORM (1ULL << 12) 5999a2dd95SBruce Richardson /**< Private xforms created by the PMD can be shared 6099a2dd95SBruce Richardson * across multiple stateless operations. If not set, then app needs 6199a2dd95SBruce Richardson * to create as many priv_xforms as it expects to have stateless 6299a2dd95SBruce Richardson * operations in-flight. 6399a2dd95SBruce Richardson */ 6499a2dd95SBruce Richardson #define RTE_COMP_FF_HUFFMAN_FIXED (1ULL << 13) 6599a2dd95SBruce Richardson /**< Fixed huffman encoding is supported */ 6699a2dd95SBruce Richardson #define RTE_COMP_FF_HUFFMAN_DYNAMIC (1ULL << 14) 6799a2dd95SBruce Richardson /**< Dynamic huffman encoding is supported */ 683372c4a6SMichael Baum #define RTE_COMP_FF_XXHASH32_CHECKSUM (1ULL << 15) 693372c4a6SMichael Baum /**< xxHash-32 Checksum is supported */ 703372c4a6SMichael Baum #define RTE_COMP_FF_LZ4_DICT_ID (1ULL << 16) 713372c4a6SMichael Baum /**< LZ4 dictionary ID is supported */ 723372c4a6SMichael Baum #define RTE_COMP_FF_LZ4_CONTENT_WITH_CHECKSUM (1ULL << 17) 733372c4a6SMichael Baum /**< LZ4 content with checksum is supported */ 743372c4a6SMichael Baum #define RTE_COMP_FF_LZ4_CONTENT_SIZE (1ULL << 18) 753372c4a6SMichael Baum /**< LZ4 content size is supported */ 763372c4a6SMichael Baum #define RTE_COMP_FF_LZ4_BLOCK_INDEPENDENCE (1ULL << 19) 773372c4a6SMichael Baum /**< LZ4 block independent is supported */ 783372c4a6SMichael Baum #define RTE_COMP_FF_LZ4_BLOCK_WITH_CHECKSUM (1ULL << 20) 793372c4a6SMichael Baum /**< LZ4 block with checksum is supported */ 8099a2dd95SBruce Richardson 8199a2dd95SBruce Richardson /** Status of comp operation */ 8299a2dd95SBruce Richardson enum rte_comp_op_status { 8399a2dd95SBruce Richardson RTE_COMP_OP_STATUS_SUCCESS = 0, 8499a2dd95SBruce Richardson /**< Operation completed successfully */ 8599a2dd95SBruce Richardson RTE_COMP_OP_STATUS_NOT_PROCESSED, 8699a2dd95SBruce Richardson /**< Operation has not yet been processed by the device */ 8799a2dd95SBruce Richardson RTE_COMP_OP_STATUS_INVALID_ARGS, 8899a2dd95SBruce Richardson /**< Operation failed due to invalid arguments in request */ 8999a2dd95SBruce Richardson RTE_COMP_OP_STATUS_ERROR, 9099a2dd95SBruce Richardson /**< Error handling operation */ 9199a2dd95SBruce Richardson RTE_COMP_OP_STATUS_INVALID_STATE, 9299a2dd95SBruce Richardson /**< Operation is invoked in invalid state */ 9399a2dd95SBruce Richardson RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED, 9499a2dd95SBruce Richardson /**< Output buffer ran out of space before operation completed. 9599a2dd95SBruce Richardson * Error case. Application must resubmit all data with a larger 9699a2dd95SBruce Richardson * output buffer. 9799a2dd95SBruce Richardson */ 9899a2dd95SBruce Richardson RTE_COMP_OP_STATUS_OUT_OF_SPACE_RECOVERABLE, 9999a2dd95SBruce Richardson /**< Output buffer ran out of space before operation completed, but this 10099a2dd95SBruce Richardson * is not an error case. Output data up to op.produced can be used and 10199a2dd95SBruce Richardson * next op in the stream should continue on from op.consumed+1. 10299a2dd95SBruce Richardson */ 10399a2dd95SBruce Richardson }; 10499a2dd95SBruce Richardson 10599a2dd95SBruce Richardson /** Compression Algorithms */ 10699a2dd95SBruce Richardson enum rte_comp_algorithm { 10799a2dd95SBruce Richardson RTE_COMP_ALGO_UNSPECIFIED = 0, 10899a2dd95SBruce Richardson /** No Compression algorithm */ 10999a2dd95SBruce Richardson RTE_COMP_ALGO_NULL, 11099a2dd95SBruce Richardson /**< No compression. 11199a2dd95SBruce Richardson * Pass-through, data is copied unchanged from source buffer to 11299a2dd95SBruce Richardson * destination buffer. 11399a2dd95SBruce Richardson */ 11499a2dd95SBruce Richardson RTE_COMP_ALGO_DEFLATE, 11599a2dd95SBruce Richardson /**< DEFLATE compression algorithm 11699a2dd95SBruce Richardson * https://tools.ietf.org/html/rfc1951 11799a2dd95SBruce Richardson */ 11899a2dd95SBruce Richardson RTE_COMP_ALGO_LZS, 11999a2dd95SBruce Richardson /**< LZS compression algorithm 12099a2dd95SBruce Richardson * https://tools.ietf.org/html/rfc2395 12199a2dd95SBruce Richardson */ 1223372c4a6SMichael Baum RTE_COMP_ALGO_LZ4, 1233372c4a6SMichael Baum /**< LZ4 compression algorithm 1243372c4a6SMichael Baum * https://github.com/lz4/lz4 1253372c4a6SMichael Baum */ 12699a2dd95SBruce Richardson }; 12799a2dd95SBruce Richardson 12899a2dd95SBruce Richardson /** Compression Hash Algorithms */ 12999a2dd95SBruce Richardson enum rte_comp_hash_algorithm { 13099a2dd95SBruce Richardson RTE_COMP_HASH_ALGO_NONE = 0, 13199a2dd95SBruce Richardson /**< No hash */ 13299a2dd95SBruce Richardson RTE_COMP_HASH_ALGO_SHA1, 13399a2dd95SBruce Richardson /**< SHA1 hash algorithm */ 13499a2dd95SBruce Richardson RTE_COMP_HASH_ALGO_SHA2_256, 13599a2dd95SBruce Richardson /**< SHA256 hash algorithm of SHA2 family */ 13699a2dd95SBruce Richardson }; 13799a2dd95SBruce Richardson 13899a2dd95SBruce Richardson /**< Compression Level. 13999a2dd95SBruce Richardson * The number is interpreted by each PMD differently. However, lower numbers 14099a2dd95SBruce Richardson * give fastest compression, at the expense of compression ratio while 14199a2dd95SBruce Richardson * higher numbers may give better compression ratios but are likely slower. 14299a2dd95SBruce Richardson */ 14399a2dd95SBruce Richardson #define RTE_COMP_LEVEL_PMD_DEFAULT (-1) 14499a2dd95SBruce Richardson /** Use PMD Default */ 14599a2dd95SBruce Richardson #define RTE_COMP_LEVEL_NONE (0) 14699a2dd95SBruce Richardson /** Output uncompressed blocks if supported by the specified algorithm */ 14799a2dd95SBruce Richardson #define RTE_COMP_LEVEL_MIN (1) 14899a2dd95SBruce Richardson /** Use minimum compression level supported by the PMD */ 14999a2dd95SBruce Richardson #define RTE_COMP_LEVEL_MAX (9) 15099a2dd95SBruce Richardson /** Use maximum compression level supported by the PMD */ 15199a2dd95SBruce Richardson 15299a2dd95SBruce Richardson /** Compression checksum types */ 15399a2dd95SBruce Richardson enum rte_comp_checksum_type { 15499a2dd95SBruce Richardson RTE_COMP_CHECKSUM_NONE, 15599a2dd95SBruce Richardson /**< No checksum generated */ 15699a2dd95SBruce Richardson RTE_COMP_CHECKSUM_CRC32, 15799a2dd95SBruce Richardson /**< Generates a CRC32 checksum, as used by gzip */ 15899a2dd95SBruce Richardson RTE_COMP_CHECKSUM_ADLER32, 15999a2dd95SBruce Richardson /**< Generates an Adler-32 checksum, as used by zlib */ 16099a2dd95SBruce Richardson RTE_COMP_CHECKSUM_CRC32_ADLER32, 16199a2dd95SBruce Richardson /**< Generates both Adler-32 and CRC32 checksums, concatenated. 16299a2dd95SBruce Richardson * CRC32 is in the lower 32bits, Adler-32 in the upper 32 bits. 16399a2dd95SBruce Richardson */ 1643372c4a6SMichael Baum RTE_COMP_CHECKSUM_XXHASH32, 1653372c4a6SMichael Baum /**< Generates a xxHash-32 checksum, as used by LZ4. 1663372c4a6SMichael Baum * https://github.com/Cyan4973/xxHash/blob/dev/doc/xxhash_spec.md 1673372c4a6SMichael Baum */ 16899a2dd95SBruce Richardson }; 16999a2dd95SBruce Richardson 17099a2dd95SBruce Richardson /** Compression Huffman Type - used by DEFLATE algorithm */ 17199a2dd95SBruce Richardson enum rte_comp_huffman { 17299a2dd95SBruce Richardson RTE_COMP_HUFFMAN_DEFAULT, 17399a2dd95SBruce Richardson /**< PMD may choose which Huffman codes to use */ 17499a2dd95SBruce Richardson RTE_COMP_HUFFMAN_FIXED, 17599a2dd95SBruce Richardson /**< Use Fixed Huffman codes */ 17699a2dd95SBruce Richardson RTE_COMP_HUFFMAN_DYNAMIC, 17799a2dd95SBruce Richardson /**< Use Dynamic Huffman codes */ 17899a2dd95SBruce Richardson }; 17999a2dd95SBruce Richardson 18099a2dd95SBruce Richardson /** Compression flush flags */ 18199a2dd95SBruce Richardson enum rte_comp_flush_flag { 18299a2dd95SBruce Richardson RTE_COMP_FLUSH_NONE, 18399a2dd95SBruce Richardson /**< Data is not flushed. Output may remain in the compressor and be 18499a2dd95SBruce Richardson * processed during a following op. It may not be possible to decompress 18599a2dd95SBruce Richardson * output until a later op with some other flush flag has been sent. 18699a2dd95SBruce Richardson */ 18799a2dd95SBruce Richardson RTE_COMP_FLUSH_SYNC, 18899a2dd95SBruce Richardson /**< All data should be flushed to output buffer. Output data can be 18999a2dd95SBruce Richardson * decompressed. However state and history is not cleared, so future 19099a2dd95SBruce Richardson * operations may use history from this operation. 19199a2dd95SBruce Richardson */ 19299a2dd95SBruce Richardson RTE_COMP_FLUSH_FULL, 19399a2dd95SBruce Richardson /**< All data should be flushed to output buffer. Output data can be 19499a2dd95SBruce Richardson * decompressed. State and history data is cleared, so future 19599a2dd95SBruce Richardson * ops will be independent of ops processed before this. 19699a2dd95SBruce Richardson */ 19799a2dd95SBruce Richardson RTE_COMP_FLUSH_FINAL 19899a2dd95SBruce Richardson /**< Same as RTE_COMP_FLUSH_FULL but if op.algo is RTE_COMP_ALGO_DEFLATE 19999a2dd95SBruce Richardson * then bfinal bit is set in the last block. 20099a2dd95SBruce Richardson */ 20199a2dd95SBruce Richardson }; 20299a2dd95SBruce Richardson 20399a2dd95SBruce Richardson /** Compression transform types */ 20499a2dd95SBruce Richardson enum rte_comp_xform_type { 20599a2dd95SBruce Richardson RTE_COMP_COMPRESS, 20699a2dd95SBruce Richardson /**< Compression service - compress */ 20799a2dd95SBruce Richardson RTE_COMP_DECOMPRESS, 20899a2dd95SBruce Richardson /**< Compression service - decompress */ 20999a2dd95SBruce Richardson }; 21099a2dd95SBruce Richardson 21199a2dd95SBruce Richardson /** Compression operation type */ 21299a2dd95SBruce Richardson enum rte_comp_op_type { 21399a2dd95SBruce Richardson RTE_COMP_OP_STATELESS, 21499a2dd95SBruce Richardson /**< All data to be processed is submitted in the op, no state or 21599a2dd95SBruce Richardson * history from previous ops is used and none will be stored for future 21699a2dd95SBruce Richardson * ops. Flush flag must be set to either FLUSH_FULL or FLUSH_FINAL. 21799a2dd95SBruce Richardson */ 21899a2dd95SBruce Richardson RTE_COMP_OP_STATEFUL 21999a2dd95SBruce Richardson /**< There may be more data to be processed after this op, it's part of 22099a2dd95SBruce Richardson * a stream of data. State and history from previous ops can be used 22199a2dd95SBruce Richardson * and resulting state and history can be stored for future ops, 22299a2dd95SBruce Richardson * depending on flush flag. 22399a2dd95SBruce Richardson */ 22499a2dd95SBruce Richardson }; 22599a2dd95SBruce Richardson 22699a2dd95SBruce Richardson /** Parameters specific to the deflate algorithm */ 22799a2dd95SBruce Richardson struct rte_comp_deflate_params { 22899a2dd95SBruce Richardson enum rte_comp_huffman huffman; 22999a2dd95SBruce Richardson /**< Compression huffman encoding type */ 23099a2dd95SBruce Richardson }; 23199a2dd95SBruce Richardson 2323372c4a6SMichael Baum /** 2333372c4a6SMichael Baum * Dictionary ID flag 2343372c4a6SMichael Baum * If this flag is set, a 4-byte dict-ID field will be present, 2353372c4a6SMichael Baum * after the descriptor flags and the content size. 2363372c4a6SMichael Baum */ 2373372c4a6SMichael Baum #define RTE_COMP_LZ4_FLAG_DICT_ID (1 << 0) 2383372c4a6SMichael Baum 2393372c4a6SMichael Baum /** 2403372c4a6SMichael Baum * Content checksum flag 2413372c4a6SMichael Baum * If this flag is set, a 32-bit content checksum 2423372c4a6SMichael Baum * will be appended after the end mark. 2433372c4a6SMichael Baum */ 2443372c4a6SMichael Baum #define RTE_COMP_LZ4_FLAG_CONTENT_CHECKSUM (1 << 2) 2453372c4a6SMichael Baum 2463372c4a6SMichael Baum /** 2473372c4a6SMichael Baum * Content size flag 2483372c4a6SMichael Baum * If this flag is set, the uncompressed size of data included within the frame 2493372c4a6SMichael Baum * will be present as an 8-byte unsigned little-endian value, after the flags. 2503372c4a6SMichael Baum * Content size usage is optional. 2513372c4a6SMichael Baum */ 2523372c4a6SMichael Baum #define RTE_COMP_LZ4_FLAG_CONTENT_SIZE (1 << 3) 2533372c4a6SMichael Baum 2543372c4a6SMichael Baum /** 2553372c4a6SMichael Baum * Block checksum flag. 2563372c4a6SMichael Baum * If this flag is set, each data block will be followed by a 4-byte checksum, 2573372c4a6SMichael Baum * calculated with the xxHash-32 algorithm on the raw (compressed) data block. 2583372c4a6SMichael Baum * The intent is to detect data corruption (storage or transmission errors) 2593372c4a6SMichael Baum * immediately, before decoding. 2603372c4a6SMichael Baum * Block checksum usage is optional. 2613372c4a6SMichael Baum */ 2623372c4a6SMichael Baum #define RTE_COMP_LZ4_FLAG_BLOCK_CHECKSUM (1 << 4) 2633372c4a6SMichael Baum 2643372c4a6SMichael Baum /** 2653372c4a6SMichael Baum * Block independence flag. 2663372c4a6SMichael Baum * If this flag is set to 1, blocks are independent. 2673372c4a6SMichael Baum * If this flag is set to 0, each block depends on previous ones 2683372c4a6SMichael Baum * (up to LZ4 window size, which is 64 KB). 2693372c4a6SMichael Baum * In such case, it is necessary to decode all blocks in sequence. 2703372c4a6SMichael Baum * Block dependency improves compression ratio, especially for small blocks. 2713372c4a6SMichael Baum * On the other hand, it makes random access or multi-threaded decoding impossible. 2723372c4a6SMichael Baum */ 2733372c4a6SMichael Baum #define RTE_COMP_LZ4_FLAG_BLOCK_INDEPENDENCE (1 << 5) 2743372c4a6SMichael Baum 2753372c4a6SMichael Baum /** Parameters specific to the LZ4 algorithm */ 2763372c4a6SMichael Baum struct rte_comp_lz4_params { 2773372c4a6SMichael Baum uint8_t flags; 2783372c4a6SMichael Baum /**< Compression LZ4 parameter flags. 2793372c4a6SMichael Baum * Based on LZ4 standard flags: 2803372c4a6SMichael Baum * https://github.com/lz4/lz4/blob/dev/doc/lz4_Frame_format.md#frame-descriptor 2813372c4a6SMichael Baum */ 2823372c4a6SMichael Baum }; 2833372c4a6SMichael Baum 28499a2dd95SBruce Richardson /** Setup Data for compression */ 28599a2dd95SBruce Richardson struct rte_comp_compress_xform { 28699a2dd95SBruce Richardson enum rte_comp_algorithm algo; 28799a2dd95SBruce Richardson /**< Algorithm to use for compress operation */ 28899a2dd95SBruce Richardson union { 28999a2dd95SBruce Richardson struct rte_comp_deflate_params deflate; 29099a2dd95SBruce Richardson /**< Parameters specific to the deflate algorithm */ 2913372c4a6SMichael Baum struct rte_comp_lz4_params lz4; 2923372c4a6SMichael Baum /**< Parameters specific to the LZ4 algorithm */ 29399a2dd95SBruce Richardson }; /**< Algorithm specific parameters */ 29499a2dd95SBruce Richardson int level; 29599a2dd95SBruce Richardson /**< Compression level */ 29699a2dd95SBruce Richardson uint8_t window_size; 29799a2dd95SBruce Richardson /**< Base two log value of sliding window to be used. If window size 29899a2dd95SBruce Richardson * can't be supported by the PMD then it may fall back to a smaller 29999a2dd95SBruce Richardson * size. This is likely to result in a worse compression ratio. 30099a2dd95SBruce Richardson */ 30199a2dd95SBruce Richardson enum rte_comp_checksum_type chksum; 30299a2dd95SBruce Richardson /**< Type of checksum to generate on the uncompressed data */ 30399a2dd95SBruce Richardson enum rte_comp_hash_algorithm hash_algo; 30499a2dd95SBruce Richardson /**< Hash algorithm to be used with compress operation. Hash is always 30599a2dd95SBruce Richardson * done on plaintext. 30699a2dd95SBruce Richardson */ 30799a2dd95SBruce Richardson }; 30899a2dd95SBruce Richardson 30999a2dd95SBruce Richardson /** 31099a2dd95SBruce Richardson * Setup Data for decompression. 31199a2dd95SBruce Richardson */ 31299a2dd95SBruce Richardson struct rte_comp_decompress_xform { 31399a2dd95SBruce Richardson enum rte_comp_algorithm algo; 31499a2dd95SBruce Richardson /**< Algorithm to use for decompression */ 31599a2dd95SBruce Richardson enum rte_comp_checksum_type chksum; 31699a2dd95SBruce Richardson /**< Type of checksum to generate on the decompressed data */ 31799a2dd95SBruce Richardson uint8_t window_size; 31899a2dd95SBruce Richardson /**< Base two log value of sliding window which was used to generate 31999a2dd95SBruce Richardson * compressed data. If window size can't be supported by the PMD then 32099a2dd95SBruce Richardson * setup of stream or private_xform should fail. 32199a2dd95SBruce Richardson */ 3223372c4a6SMichael Baum union { 3233372c4a6SMichael Baum struct rte_comp_lz4_params lz4; 3243372c4a6SMichael Baum /**< Parameters specific to the LZ4 algorithm */ 3253372c4a6SMichael Baum }; /**< Algorithm specific parameters */ 32699a2dd95SBruce Richardson enum rte_comp_hash_algorithm hash_algo; 32799a2dd95SBruce Richardson /**< Hash algorithm to be used with decompress operation. Hash is always 32899a2dd95SBruce Richardson * done on plaintext. 32999a2dd95SBruce Richardson */ 33099a2dd95SBruce Richardson }; 33199a2dd95SBruce Richardson 33299a2dd95SBruce Richardson /** 33399a2dd95SBruce Richardson * Compression transform structure. 33499a2dd95SBruce Richardson * 33599a2dd95SBruce Richardson * This is used to specify the compression transforms required. 33699a2dd95SBruce Richardson * Each transform structure can hold a single transform, the type field is 33799a2dd95SBruce Richardson * used to specify which transform is contained within the union. 33899a2dd95SBruce Richardson */ 33999a2dd95SBruce Richardson struct rte_comp_xform { 34099a2dd95SBruce Richardson enum rte_comp_xform_type type; 34199a2dd95SBruce Richardson /**< xform type */ 34299a2dd95SBruce Richardson union { 34399a2dd95SBruce Richardson struct rte_comp_compress_xform compress; 34499a2dd95SBruce Richardson /**< xform for compress operation */ 34599a2dd95SBruce Richardson struct rte_comp_decompress_xform decompress; 34699a2dd95SBruce Richardson /**< decompress xform */ 34799a2dd95SBruce Richardson }; 34899a2dd95SBruce Richardson }; 34999a2dd95SBruce Richardson 35099a2dd95SBruce Richardson /** 35199a2dd95SBruce Richardson * Compression Operation. 35299a2dd95SBruce Richardson * 35399a2dd95SBruce Richardson * This structure contains data relating to performing a compression 35499a2dd95SBruce Richardson * operation on the referenced mbuf data buffers. 35599a2dd95SBruce Richardson * 35699a2dd95SBruce Richardson * Comp operations are enqueued and dequeued in comp PMDs using the 35799a2dd95SBruce Richardson * rte_compressdev_enqueue_burst() / rte_compressdev_dequeue_burst() APIs 35899a2dd95SBruce Richardson */ 359c6552d9aSTyler Retzlaff struct __rte_cache_aligned rte_comp_op { 36099a2dd95SBruce Richardson enum rte_comp_op_type op_type; 36199a2dd95SBruce Richardson union { 36299a2dd95SBruce Richardson void *private_xform; 36399a2dd95SBruce Richardson /**< Stateless private PMD data derived from an rte_comp_xform. 36499a2dd95SBruce Richardson * A handle returned by rte_compressdev_private_xform_create() 36599a2dd95SBruce Richardson * must be attached to operations of op_type RTE_COMP_STATELESS. 36699a2dd95SBruce Richardson */ 36799a2dd95SBruce Richardson void *stream; 36899a2dd95SBruce Richardson /**< Private PMD data derived initially from an rte_comp_xform, 36999a2dd95SBruce Richardson * which holds state and history data and evolves as operations 37099a2dd95SBruce Richardson * are processed. rte_compressdev_stream_create() must be called 37199a2dd95SBruce Richardson * on a device for all STATEFUL data streams and the resulting 37299a2dd95SBruce Richardson * stream attached to the one or more operations associated 37399a2dd95SBruce Richardson * with the data stream. 37499a2dd95SBruce Richardson * All operations in a stream must be sent to the same device. 37599a2dd95SBruce Richardson */ 37699a2dd95SBruce Richardson }; 37799a2dd95SBruce Richardson 37899a2dd95SBruce Richardson struct rte_mempool *mempool; 37999a2dd95SBruce Richardson /**< Pool from which operation is allocated */ 38099a2dd95SBruce Richardson rte_iova_t iova_addr; 38199a2dd95SBruce Richardson /**< IOVA address of this operation */ 38299a2dd95SBruce Richardson struct rte_mbuf *m_src; 38399a2dd95SBruce Richardson /**< source mbuf 38499a2dd95SBruce Richardson * The total size of the input buffer(s) can be retrieved using 38599a2dd95SBruce Richardson * rte_pktmbuf_pkt_len(m_src). The max data size which can fit in a 38699a2dd95SBruce Richardson * single mbuf is limited by the uint16_t rte_mbuf.data_len to 64k-1. 38799a2dd95SBruce Richardson * If the input data is bigger than this it can be passed to the PMD in 38899a2dd95SBruce Richardson * a chain of mbufs if the PMD's capabilities indicate it supports this. 38999a2dd95SBruce Richardson */ 39099a2dd95SBruce Richardson struct rte_mbuf *m_dst; 39199a2dd95SBruce Richardson /**< destination mbuf 39299a2dd95SBruce Richardson * The total size of the output buffer(s) can be retrieved using 39399a2dd95SBruce Richardson * rte_pktmbuf_pkt_len(m_dst). The max data size which can fit in a 39499a2dd95SBruce Richardson * single mbuf is limited by the uint16_t rte_mbuf.data_len to 64k-1. 39599a2dd95SBruce Richardson * If the output data is expected to be bigger than this a chain of 39699a2dd95SBruce Richardson * mbufs can be passed to the PMD if the PMD's capabilities indicate 39799a2dd95SBruce Richardson * it supports this. 39899a2dd95SBruce Richardson * 39999a2dd95SBruce Richardson * @note, if incompressible data is passed to an engine for compression 40099a2dd95SBruce Richardson * using RTE_COMP_ALGO_DEFLATE, it's possible for the output data 40199a2dd95SBruce Richardson * to be larger than the uncompressed data, due to the inclusion 40299a2dd95SBruce Richardson * of the DEFLATE header blocks. The size of m_dst should accommodate 40399a2dd95SBruce Richardson * this, else OUT_OF_SPACE errors can be expected in this case. 40499a2dd95SBruce Richardson */ 40599a2dd95SBruce Richardson 40699a2dd95SBruce Richardson struct { 40799a2dd95SBruce Richardson uint32_t offset; 40899a2dd95SBruce Richardson /**< Starting point for compression or decompression, 40999a2dd95SBruce Richardson * specified as number of bytes from start of packet in 41099a2dd95SBruce Richardson * source buffer. 41199a2dd95SBruce Richardson * This offset starts from the first segment 41299a2dd95SBruce Richardson * of the buffer, in case the m_src is a chain of mbufs. 41399a2dd95SBruce Richardson * Starting point for checksum generation in compress direction. 41499a2dd95SBruce Richardson */ 41599a2dd95SBruce Richardson uint32_t length; 41699a2dd95SBruce Richardson /**< The length, in bytes, of the data in source buffer 41799a2dd95SBruce Richardson * to be compressed or decompressed. 41899a2dd95SBruce Richardson * Also the length of the data over which the checksum 41999a2dd95SBruce Richardson * should be generated in compress direction 42099a2dd95SBruce Richardson */ 42199a2dd95SBruce Richardson } src; 42299a2dd95SBruce Richardson struct { 42399a2dd95SBruce Richardson uint32_t offset; 42499a2dd95SBruce Richardson /**< Starting point for writing output data, specified as 42599a2dd95SBruce Richardson * number of bytes from start of packet in dest 42699a2dd95SBruce Richardson * buffer. 42799a2dd95SBruce Richardson * This offset starts from the first segment 42899a2dd95SBruce Richardson * of the buffer, in case the m_dst is a chain of mbufs. 42999a2dd95SBruce Richardson * Starting point for checksum generation in 43099a2dd95SBruce Richardson * decompress direction. 43199a2dd95SBruce Richardson */ 43299a2dd95SBruce Richardson } dst; 43399a2dd95SBruce Richardson struct { 43499a2dd95SBruce Richardson uint8_t *digest; 43599a2dd95SBruce Richardson /**< Output buffer to store hash output, if enabled in xform. 43699a2dd95SBruce Richardson * Buffer would contain valid value only after an op with 43799a2dd95SBruce Richardson * flush flag = RTE_COMP_FLUSH_FULL/FLUSH_FINAL is processed 43899a2dd95SBruce Richardson * successfully. 43999a2dd95SBruce Richardson * 44099a2dd95SBruce Richardson * Length of buffer should be contiguous and large enough to 44199a2dd95SBruce Richardson * accommodate digest produced by specific hash algo. 44299a2dd95SBruce Richardson */ 44399a2dd95SBruce Richardson rte_iova_t iova_addr; 44499a2dd95SBruce Richardson /**< IO address of the buffer */ 44599a2dd95SBruce Richardson } hash; 44699a2dd95SBruce Richardson enum rte_comp_flush_flag flush_flag; 44799a2dd95SBruce Richardson /**< Defines flush characteristics for the output data. 44899a2dd95SBruce Richardson * Only applicable in compress direction 44999a2dd95SBruce Richardson */ 45099a2dd95SBruce Richardson uint64_t input_chksum; 45199a2dd95SBruce Richardson /**< An input checksum can be provided to generate a 45299a2dd95SBruce Richardson * cumulative checksum across sequential blocks in a STATELESS stream. 45399a2dd95SBruce Richardson * Checksum type is as specified in xform chksum_type 45499a2dd95SBruce Richardson */ 45599a2dd95SBruce Richardson uint64_t output_chksum; 45699a2dd95SBruce Richardson /**< If a checksum is generated it will be written in here. 45799a2dd95SBruce Richardson * Checksum type is as specified in xform chksum_type. 45899a2dd95SBruce Richardson */ 45999a2dd95SBruce Richardson uint32_t consumed; 46099a2dd95SBruce Richardson /**< The number of bytes from the source buffer 46199a2dd95SBruce Richardson * which were compressed/decompressed. 46299a2dd95SBruce Richardson */ 46399a2dd95SBruce Richardson uint32_t produced; 46499a2dd95SBruce Richardson /**< The number of bytes written to the destination buffer 46599a2dd95SBruce Richardson * which were compressed/decompressed. 46699a2dd95SBruce Richardson */ 46799a2dd95SBruce Richardson uint64_t debug_status; 46899a2dd95SBruce Richardson /**< 46999a2dd95SBruce Richardson * Status of the operation is returned in the status param. 47099a2dd95SBruce Richardson * This field allows the PMD to pass back extra 47199a2dd95SBruce Richardson * pmd-specific debug information. Value is not defined on the API. 47299a2dd95SBruce Richardson */ 47399a2dd95SBruce Richardson uint8_t status; 47499a2dd95SBruce Richardson /**< 47599a2dd95SBruce Richardson * Operation status - use values from enum rte_comp_status. 47699a2dd95SBruce Richardson * This is reset to 47799a2dd95SBruce Richardson * RTE_COMP_OP_STATUS_NOT_PROCESSED on allocation from mempool and 47899a2dd95SBruce Richardson * will be set to RTE_COMP_OP_STATUS_SUCCESS after operation 47999a2dd95SBruce Richardson * is successfully processed by a PMD 48099a2dd95SBruce Richardson */ 481c6552d9aSTyler Retzlaff }; 48299a2dd95SBruce Richardson 48399a2dd95SBruce Richardson /** 48499a2dd95SBruce Richardson * Creates an operation pool 48599a2dd95SBruce Richardson * 48699a2dd95SBruce Richardson * @param name 48799a2dd95SBruce Richardson * Compress pool name 48899a2dd95SBruce Richardson * @param nb_elts 48999a2dd95SBruce Richardson * Number of elements in pool 49099a2dd95SBruce Richardson * @param cache_size 49199a2dd95SBruce Richardson * Number of elements to cache on lcore, see 49299a2dd95SBruce Richardson * *rte_mempool_create* for further details about cache size 49399a2dd95SBruce Richardson * @param user_size 49499a2dd95SBruce Richardson * Size of private data to allocate for user with each operation 49599a2dd95SBruce Richardson * @param socket_id 49699a2dd95SBruce Richardson * Socket to identifier allocate memory on 49799a2dd95SBruce Richardson * @return 49899a2dd95SBruce Richardson * - On success pointer to mempool 49999a2dd95SBruce Richardson * - On failure NULL 50099a2dd95SBruce Richardson */ 50199a2dd95SBruce Richardson struct rte_mempool * 50299a2dd95SBruce Richardson rte_comp_op_pool_create(const char *name, 50399a2dd95SBruce Richardson unsigned int nb_elts, unsigned int cache_size, 50499a2dd95SBruce Richardson uint16_t user_size, int socket_id); 50599a2dd95SBruce Richardson 50699a2dd95SBruce Richardson /** 50799a2dd95SBruce Richardson * Allocate an operation from a mempool with default parameters set 50899a2dd95SBruce Richardson * 50999a2dd95SBruce Richardson * @param mempool 51099a2dd95SBruce Richardson * Compress operation mempool 51199a2dd95SBruce Richardson * 51299a2dd95SBruce Richardson * @return 51399a2dd95SBruce Richardson * - On success returns a valid rte_comp_op structure 51499a2dd95SBruce Richardson * - On failure returns NULL 51599a2dd95SBruce Richardson */ 51699a2dd95SBruce Richardson struct rte_comp_op * 51799a2dd95SBruce Richardson rte_comp_op_alloc(struct rte_mempool *mempool); 51899a2dd95SBruce Richardson 51999a2dd95SBruce Richardson /** 52099a2dd95SBruce Richardson * Bulk allocate operations from a mempool with default parameters set 52199a2dd95SBruce Richardson * 52299a2dd95SBruce Richardson * @param mempool 52399a2dd95SBruce Richardson * Compress operation mempool 52499a2dd95SBruce Richardson * @param ops 52599a2dd95SBruce Richardson * Array to place allocated operations 52699a2dd95SBruce Richardson * @param nb_ops 52799a2dd95SBruce Richardson * Number of operations to allocate 52899a2dd95SBruce Richardson * @return 52999a2dd95SBruce Richardson * - nb_ops: Success, the nb_ops requested was allocated 53099a2dd95SBruce Richardson * - 0: Not enough entries in the mempool; no ops are retrieved. 53199a2dd95SBruce Richardson */ 53299a2dd95SBruce Richardson int 53399a2dd95SBruce Richardson rte_comp_op_bulk_alloc(struct rte_mempool *mempool, 53499a2dd95SBruce Richardson struct rte_comp_op **ops, uint16_t nb_ops); 53599a2dd95SBruce Richardson 53699a2dd95SBruce Richardson /** 53799a2dd95SBruce Richardson * Free operation structure 53899a2dd95SBruce Richardson * If operation has been allocate from a rte_mempool, then the operation will 53999a2dd95SBruce Richardson * be returned to the mempool. 54099a2dd95SBruce Richardson * 54199a2dd95SBruce Richardson * @param op 542448e01f1SStephen Hemminger * Compress operation pointer allocated from rte_comp_op_alloc() 543448e01f1SStephen Hemminger * If op is NULL, no operation is performed. 54499a2dd95SBruce Richardson */ 54599a2dd95SBruce Richardson void 54699a2dd95SBruce Richardson rte_comp_op_free(struct rte_comp_op *op); 54799a2dd95SBruce Richardson 54899a2dd95SBruce Richardson /** 54999a2dd95SBruce Richardson * Bulk free operation structures 55099a2dd95SBruce Richardson * If operations have been allocated from an rte_mempool, then the operations 55199a2dd95SBruce Richardson * will be returned to the mempool. 55299a2dd95SBruce Richardson * The array entry will be cleared. 55399a2dd95SBruce Richardson * 55499a2dd95SBruce Richardson * @param ops 55599a2dd95SBruce Richardson * Array of Compress operations 55699a2dd95SBruce Richardson * @param nb_ops 55799a2dd95SBruce Richardson * Number of operations to free 55899a2dd95SBruce Richardson */ 55999a2dd95SBruce Richardson void 56099a2dd95SBruce Richardson rte_comp_op_bulk_free(struct rte_comp_op **ops, uint16_t nb_ops); 56199a2dd95SBruce Richardson 56299a2dd95SBruce Richardson /** 56399a2dd95SBruce Richardson * Get the name of a compress service feature flag 56499a2dd95SBruce Richardson * 56599a2dd95SBruce Richardson * @param flag 56699a2dd95SBruce Richardson * The mask describing the flag 56799a2dd95SBruce Richardson * 56899a2dd95SBruce Richardson * @return 56999a2dd95SBruce Richardson * The name of this flag, or NULL if it's not a valid feature flag. 57099a2dd95SBruce Richardson */ 57199a2dd95SBruce Richardson const char * 57299a2dd95SBruce Richardson rte_comp_get_feature_name(uint64_t flag); 57399a2dd95SBruce Richardson 57499a2dd95SBruce Richardson #ifdef __cplusplus 57599a2dd95SBruce Richardson } 57699a2dd95SBruce Richardson #endif 57799a2dd95SBruce Richardson 57899a2dd95SBruce Richardson #endif /* _RTE_COMP_H_ */ 579