1*99a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2*99a2dd95SBruce Richardson * Copyright(c) 2017-2018 Intel Corporation 3*99a2dd95SBruce Richardson */ 4*99a2dd95SBruce Richardson 5*99a2dd95SBruce Richardson #ifndef _RTE_COMP_H_ 6*99a2dd95SBruce Richardson #define _RTE_COMP_H_ 7*99a2dd95SBruce Richardson 8*99a2dd95SBruce Richardson /** 9*99a2dd95SBruce Richardson * @file rte_comp.h 10*99a2dd95SBruce Richardson * 11*99a2dd95SBruce Richardson * RTE definitions for Data Compression Service 12*99a2dd95SBruce Richardson * 13*99a2dd95SBruce Richardson */ 14*99a2dd95SBruce Richardson 15*99a2dd95SBruce Richardson #ifdef __cplusplus 16*99a2dd95SBruce Richardson extern "C" { 17*99a2dd95SBruce Richardson #endif 18*99a2dd95SBruce Richardson 19*99a2dd95SBruce Richardson #include <rte_mbuf.h> 20*99a2dd95SBruce Richardson 21*99a2dd95SBruce Richardson /** 22*99a2dd95SBruce Richardson * compression service feature flags 23*99a2dd95SBruce Richardson * 24*99a2dd95SBruce Richardson * @note New features flags should be added to the end of the list 25*99a2dd95SBruce Richardson * 26*99a2dd95SBruce Richardson * Keep these flags synchronised with rte_comp_get_feature_name() 27*99a2dd95SBruce Richardson */ 28*99a2dd95SBruce Richardson #define RTE_COMP_FF_STATEFUL_COMPRESSION (1ULL << 0) 29*99a2dd95SBruce Richardson /**< Stateful compression is supported */ 30*99a2dd95SBruce Richardson #define RTE_COMP_FF_STATEFUL_DECOMPRESSION (1ULL << 1) 31*99a2dd95SBruce Richardson /**< Stateful decompression is supported */ 32*99a2dd95SBruce Richardson #define RTE_COMP_FF_OOP_SGL_IN_SGL_OUT (1ULL << 2) 33*99a2dd95SBruce Richardson /**< Out-of-place Scatter-gather (SGL) buffers, 34*99a2dd95SBruce Richardson * with multiple segments, are supported in input and output 35*99a2dd95SBruce Richardson */ 36*99a2dd95SBruce Richardson #define RTE_COMP_FF_OOP_SGL_IN_LB_OUT (1ULL << 3) 37*99a2dd95SBruce Richardson /**< Out-of-place Scatter-gather (SGL) buffers are supported 38*99a2dd95SBruce Richardson * in input, combined with linear buffers (LB), with a 39*99a2dd95SBruce Richardson * single segment, in output 40*99a2dd95SBruce Richardson */ 41*99a2dd95SBruce Richardson #define RTE_COMP_FF_OOP_LB_IN_SGL_OUT (1ULL << 4) 42*99a2dd95SBruce Richardson /**< Out-of-place Scatter-gather (SGL) buffers are supported 43*99a2dd95SBruce Richardson * in output, combined with linear buffers (LB) in input 44*99a2dd95SBruce Richardson */ 45*99a2dd95SBruce Richardson #define RTE_COMP_FF_ADLER32_CHECKSUM (1ULL << 5) 46*99a2dd95SBruce Richardson /**< Adler-32 Checksum is supported */ 47*99a2dd95SBruce Richardson #define RTE_COMP_FF_CRC32_CHECKSUM (1ULL << 6) 48*99a2dd95SBruce Richardson /**< CRC32 Checksum is supported */ 49*99a2dd95SBruce Richardson #define RTE_COMP_FF_CRC32_ADLER32_CHECKSUM (1ULL << 7) 50*99a2dd95SBruce Richardson /**< Adler-32/CRC32 Checksum is supported */ 51*99a2dd95SBruce Richardson #define RTE_COMP_FF_MULTI_PKT_CHECKSUM (1ULL << 8) 52*99a2dd95SBruce Richardson /**< Generation of checksum across multiple stateless packets is supported */ 53*99a2dd95SBruce Richardson #define RTE_COMP_FF_SHA1_HASH (1ULL << 9) 54*99a2dd95SBruce Richardson /**< SHA1 Hash is supported */ 55*99a2dd95SBruce Richardson #define RTE_COMP_FF_SHA2_SHA256_HASH (1ULL << 10) 56*99a2dd95SBruce Richardson /**< SHA256 Hash of SHA2 family is supported */ 57*99a2dd95SBruce Richardson #define RTE_COMP_FF_NONCOMPRESSED_BLOCKS (1ULL << 11) 58*99a2dd95SBruce Richardson /**< Creation of non-compressed blocks using RTE_COMP_LEVEL_NONE is supported */ 59*99a2dd95SBruce Richardson #define RTE_COMP_FF_SHAREABLE_PRIV_XFORM (1ULL << 12) 60*99a2dd95SBruce Richardson /**< Private xforms created by the PMD can be shared 61*99a2dd95SBruce Richardson * across multiple stateless operations. If not set, then app needs 62*99a2dd95SBruce Richardson * to create as many priv_xforms as it expects to have stateless 63*99a2dd95SBruce Richardson * operations in-flight. 64*99a2dd95SBruce Richardson */ 65*99a2dd95SBruce Richardson #define RTE_COMP_FF_HUFFMAN_FIXED (1ULL << 13) 66*99a2dd95SBruce Richardson /**< Fixed huffman encoding is supported */ 67*99a2dd95SBruce Richardson #define RTE_COMP_FF_HUFFMAN_DYNAMIC (1ULL << 14) 68*99a2dd95SBruce Richardson /**< Dynamic huffman encoding is supported */ 69*99a2dd95SBruce Richardson 70*99a2dd95SBruce Richardson /** Status of comp operation */ 71*99a2dd95SBruce Richardson enum rte_comp_op_status { 72*99a2dd95SBruce Richardson RTE_COMP_OP_STATUS_SUCCESS = 0, 73*99a2dd95SBruce Richardson /**< Operation completed successfully */ 74*99a2dd95SBruce Richardson RTE_COMP_OP_STATUS_NOT_PROCESSED, 75*99a2dd95SBruce Richardson /**< Operation has not yet been processed by the device */ 76*99a2dd95SBruce Richardson RTE_COMP_OP_STATUS_INVALID_ARGS, 77*99a2dd95SBruce Richardson /**< Operation failed due to invalid arguments in request */ 78*99a2dd95SBruce Richardson RTE_COMP_OP_STATUS_ERROR, 79*99a2dd95SBruce Richardson /**< Error handling operation */ 80*99a2dd95SBruce Richardson RTE_COMP_OP_STATUS_INVALID_STATE, 81*99a2dd95SBruce Richardson /**< Operation is invoked in invalid state */ 82*99a2dd95SBruce Richardson RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED, 83*99a2dd95SBruce Richardson /**< Output buffer ran out of space before operation completed. 84*99a2dd95SBruce Richardson * Error case. Application must resubmit all data with a larger 85*99a2dd95SBruce Richardson * output buffer. 86*99a2dd95SBruce Richardson */ 87*99a2dd95SBruce Richardson RTE_COMP_OP_STATUS_OUT_OF_SPACE_RECOVERABLE, 88*99a2dd95SBruce Richardson /**< Output buffer ran out of space before operation completed, but this 89*99a2dd95SBruce Richardson * is not an error case. Output data up to op.produced can be used and 90*99a2dd95SBruce Richardson * next op in the stream should continue on from op.consumed+1. 91*99a2dd95SBruce Richardson */ 92*99a2dd95SBruce Richardson }; 93*99a2dd95SBruce Richardson 94*99a2dd95SBruce Richardson /** Compression Algorithms */ 95*99a2dd95SBruce Richardson enum rte_comp_algorithm { 96*99a2dd95SBruce Richardson RTE_COMP_ALGO_UNSPECIFIED = 0, 97*99a2dd95SBruce Richardson /** No Compression algorithm */ 98*99a2dd95SBruce Richardson RTE_COMP_ALGO_NULL, 99*99a2dd95SBruce Richardson /**< No compression. 100*99a2dd95SBruce Richardson * Pass-through, data is copied unchanged from source buffer to 101*99a2dd95SBruce Richardson * destination buffer. 102*99a2dd95SBruce Richardson */ 103*99a2dd95SBruce Richardson RTE_COMP_ALGO_DEFLATE, 104*99a2dd95SBruce Richardson /**< DEFLATE compression algorithm 105*99a2dd95SBruce Richardson * https://tools.ietf.org/html/rfc1951 106*99a2dd95SBruce Richardson */ 107*99a2dd95SBruce Richardson RTE_COMP_ALGO_LZS, 108*99a2dd95SBruce Richardson /**< LZS compression algorithm 109*99a2dd95SBruce Richardson * https://tools.ietf.org/html/rfc2395 110*99a2dd95SBruce Richardson */ 111*99a2dd95SBruce Richardson RTE_COMP_ALGO_LIST_END 112*99a2dd95SBruce Richardson }; 113*99a2dd95SBruce Richardson 114*99a2dd95SBruce Richardson /** Compression Hash Algorithms */ 115*99a2dd95SBruce Richardson enum rte_comp_hash_algorithm { 116*99a2dd95SBruce Richardson RTE_COMP_HASH_ALGO_NONE = 0, 117*99a2dd95SBruce Richardson /**< No hash */ 118*99a2dd95SBruce Richardson RTE_COMP_HASH_ALGO_SHA1, 119*99a2dd95SBruce Richardson /**< SHA1 hash algorithm */ 120*99a2dd95SBruce Richardson RTE_COMP_HASH_ALGO_SHA2_256, 121*99a2dd95SBruce Richardson /**< SHA256 hash algorithm of SHA2 family */ 122*99a2dd95SBruce Richardson RTE_COMP_HASH_ALGO_LIST_END 123*99a2dd95SBruce Richardson }; 124*99a2dd95SBruce Richardson 125*99a2dd95SBruce Richardson /**< Compression Level. 126*99a2dd95SBruce Richardson * The number is interpreted by each PMD differently. However, lower numbers 127*99a2dd95SBruce Richardson * give fastest compression, at the expense of compression ratio while 128*99a2dd95SBruce Richardson * higher numbers may give better compression ratios but are likely slower. 129*99a2dd95SBruce Richardson */ 130*99a2dd95SBruce Richardson #define RTE_COMP_LEVEL_PMD_DEFAULT (-1) 131*99a2dd95SBruce Richardson /** Use PMD Default */ 132*99a2dd95SBruce Richardson #define RTE_COMP_LEVEL_NONE (0) 133*99a2dd95SBruce Richardson /** Output uncompressed blocks if supported by the specified algorithm */ 134*99a2dd95SBruce Richardson #define RTE_COMP_LEVEL_MIN (1) 135*99a2dd95SBruce Richardson /** Use minimum compression level supported by the PMD */ 136*99a2dd95SBruce Richardson #define RTE_COMP_LEVEL_MAX (9) 137*99a2dd95SBruce Richardson /** Use maximum compression level supported by the PMD */ 138*99a2dd95SBruce Richardson 139*99a2dd95SBruce Richardson /** Compression checksum types */ 140*99a2dd95SBruce Richardson enum rte_comp_checksum_type { 141*99a2dd95SBruce Richardson RTE_COMP_CHECKSUM_NONE, 142*99a2dd95SBruce Richardson /**< No checksum generated */ 143*99a2dd95SBruce Richardson RTE_COMP_CHECKSUM_CRC32, 144*99a2dd95SBruce Richardson /**< Generates a CRC32 checksum, as used by gzip */ 145*99a2dd95SBruce Richardson RTE_COMP_CHECKSUM_ADLER32, 146*99a2dd95SBruce Richardson /**< Generates an Adler-32 checksum, as used by zlib */ 147*99a2dd95SBruce Richardson RTE_COMP_CHECKSUM_CRC32_ADLER32, 148*99a2dd95SBruce Richardson /**< Generates both Adler-32 and CRC32 checksums, concatenated. 149*99a2dd95SBruce Richardson * CRC32 is in the lower 32bits, Adler-32 in the upper 32 bits. 150*99a2dd95SBruce Richardson */ 151*99a2dd95SBruce Richardson }; 152*99a2dd95SBruce Richardson 153*99a2dd95SBruce Richardson 154*99a2dd95SBruce Richardson /** Compression Huffman Type - used by DEFLATE algorithm */ 155*99a2dd95SBruce Richardson enum rte_comp_huffman { 156*99a2dd95SBruce Richardson RTE_COMP_HUFFMAN_DEFAULT, 157*99a2dd95SBruce Richardson /**< PMD may choose which Huffman codes to use */ 158*99a2dd95SBruce Richardson RTE_COMP_HUFFMAN_FIXED, 159*99a2dd95SBruce Richardson /**< Use Fixed Huffman codes */ 160*99a2dd95SBruce Richardson RTE_COMP_HUFFMAN_DYNAMIC, 161*99a2dd95SBruce Richardson /**< Use Dynamic Huffman codes */ 162*99a2dd95SBruce Richardson }; 163*99a2dd95SBruce Richardson 164*99a2dd95SBruce Richardson /** Compression flush flags */ 165*99a2dd95SBruce Richardson enum rte_comp_flush_flag { 166*99a2dd95SBruce Richardson RTE_COMP_FLUSH_NONE, 167*99a2dd95SBruce Richardson /**< Data is not flushed. Output may remain in the compressor and be 168*99a2dd95SBruce Richardson * processed during a following op. It may not be possible to decompress 169*99a2dd95SBruce Richardson * output until a later op with some other flush flag has been sent. 170*99a2dd95SBruce Richardson */ 171*99a2dd95SBruce Richardson RTE_COMP_FLUSH_SYNC, 172*99a2dd95SBruce Richardson /**< All data should be flushed to output buffer. Output data can be 173*99a2dd95SBruce Richardson * decompressed. However state and history is not cleared, so future 174*99a2dd95SBruce Richardson * operations may use history from this operation. 175*99a2dd95SBruce Richardson */ 176*99a2dd95SBruce Richardson RTE_COMP_FLUSH_FULL, 177*99a2dd95SBruce Richardson /**< All data should be flushed to output buffer. Output data can be 178*99a2dd95SBruce Richardson * decompressed. State and history data is cleared, so future 179*99a2dd95SBruce Richardson * ops will be independent of ops processed before this. 180*99a2dd95SBruce Richardson */ 181*99a2dd95SBruce Richardson RTE_COMP_FLUSH_FINAL 182*99a2dd95SBruce Richardson /**< Same as RTE_COMP_FLUSH_FULL but if op.algo is RTE_COMP_ALGO_DEFLATE 183*99a2dd95SBruce Richardson * then bfinal bit is set in the last block. 184*99a2dd95SBruce Richardson */ 185*99a2dd95SBruce Richardson }; 186*99a2dd95SBruce Richardson 187*99a2dd95SBruce Richardson /** Compression transform types */ 188*99a2dd95SBruce Richardson enum rte_comp_xform_type { 189*99a2dd95SBruce Richardson RTE_COMP_COMPRESS, 190*99a2dd95SBruce Richardson /**< Compression service - compress */ 191*99a2dd95SBruce Richardson RTE_COMP_DECOMPRESS, 192*99a2dd95SBruce Richardson /**< Compression service - decompress */ 193*99a2dd95SBruce Richardson }; 194*99a2dd95SBruce Richardson 195*99a2dd95SBruce Richardson /** Compression operation type */ 196*99a2dd95SBruce Richardson enum rte_comp_op_type { 197*99a2dd95SBruce Richardson RTE_COMP_OP_STATELESS, 198*99a2dd95SBruce Richardson /**< All data to be processed is submitted in the op, no state or 199*99a2dd95SBruce Richardson * history from previous ops is used and none will be stored for future 200*99a2dd95SBruce Richardson * ops. Flush flag must be set to either FLUSH_FULL or FLUSH_FINAL. 201*99a2dd95SBruce Richardson */ 202*99a2dd95SBruce Richardson RTE_COMP_OP_STATEFUL 203*99a2dd95SBruce Richardson /**< There may be more data to be processed after this op, it's part of 204*99a2dd95SBruce Richardson * a stream of data. State and history from previous ops can be used 205*99a2dd95SBruce Richardson * and resulting state and history can be stored for future ops, 206*99a2dd95SBruce Richardson * depending on flush flag. 207*99a2dd95SBruce Richardson */ 208*99a2dd95SBruce Richardson }; 209*99a2dd95SBruce Richardson 210*99a2dd95SBruce Richardson 211*99a2dd95SBruce Richardson /** Parameters specific to the deflate algorithm */ 212*99a2dd95SBruce Richardson struct rte_comp_deflate_params { 213*99a2dd95SBruce Richardson enum rte_comp_huffman huffman; 214*99a2dd95SBruce Richardson /**< Compression huffman encoding type */ 215*99a2dd95SBruce Richardson }; 216*99a2dd95SBruce Richardson 217*99a2dd95SBruce Richardson /** Setup Data for compression */ 218*99a2dd95SBruce Richardson struct rte_comp_compress_xform { 219*99a2dd95SBruce Richardson enum rte_comp_algorithm algo; 220*99a2dd95SBruce Richardson /**< Algorithm to use for compress operation */ 221*99a2dd95SBruce Richardson union { 222*99a2dd95SBruce Richardson struct rte_comp_deflate_params deflate; 223*99a2dd95SBruce Richardson /**< Parameters specific to the deflate algorithm */ 224*99a2dd95SBruce Richardson }; /**< Algorithm specific parameters */ 225*99a2dd95SBruce Richardson int level; 226*99a2dd95SBruce Richardson /**< Compression level */ 227*99a2dd95SBruce Richardson uint8_t window_size; 228*99a2dd95SBruce Richardson /**< Base two log value of sliding window to be used. If window size 229*99a2dd95SBruce Richardson * can't be supported by the PMD then it may fall back to a smaller 230*99a2dd95SBruce Richardson * size. This is likely to result in a worse compression ratio. 231*99a2dd95SBruce Richardson */ 232*99a2dd95SBruce Richardson enum rte_comp_checksum_type chksum; 233*99a2dd95SBruce Richardson /**< Type of checksum to generate on the uncompressed data */ 234*99a2dd95SBruce Richardson enum rte_comp_hash_algorithm hash_algo; 235*99a2dd95SBruce Richardson /**< Hash algorithm to be used with compress operation. Hash is always 236*99a2dd95SBruce Richardson * done on plaintext. 237*99a2dd95SBruce Richardson */ 238*99a2dd95SBruce Richardson }; 239*99a2dd95SBruce Richardson 240*99a2dd95SBruce Richardson /** 241*99a2dd95SBruce Richardson * Setup Data for decompression. 242*99a2dd95SBruce Richardson */ 243*99a2dd95SBruce Richardson struct rte_comp_decompress_xform { 244*99a2dd95SBruce Richardson enum rte_comp_algorithm algo; 245*99a2dd95SBruce Richardson /**< Algorithm to use for decompression */ 246*99a2dd95SBruce Richardson enum rte_comp_checksum_type chksum; 247*99a2dd95SBruce Richardson /**< Type of checksum to generate on the decompressed data */ 248*99a2dd95SBruce Richardson uint8_t window_size; 249*99a2dd95SBruce Richardson /**< Base two log value of sliding window which was used to generate 250*99a2dd95SBruce Richardson * compressed data. If window size can't be supported by the PMD then 251*99a2dd95SBruce Richardson * setup of stream or private_xform should fail. 252*99a2dd95SBruce Richardson */ 253*99a2dd95SBruce Richardson enum rte_comp_hash_algorithm hash_algo; 254*99a2dd95SBruce Richardson /**< Hash algorithm to be used with decompress operation. Hash is always 255*99a2dd95SBruce Richardson * done on plaintext. 256*99a2dd95SBruce Richardson */ 257*99a2dd95SBruce Richardson }; 258*99a2dd95SBruce Richardson 259*99a2dd95SBruce Richardson /** 260*99a2dd95SBruce Richardson * Compression transform structure. 261*99a2dd95SBruce Richardson * 262*99a2dd95SBruce Richardson * This is used to specify the compression transforms required. 263*99a2dd95SBruce Richardson * Each transform structure can hold a single transform, the type field is 264*99a2dd95SBruce Richardson * used to specify which transform is contained within the union. 265*99a2dd95SBruce Richardson */ 266*99a2dd95SBruce Richardson struct rte_comp_xform { 267*99a2dd95SBruce Richardson enum rte_comp_xform_type type; 268*99a2dd95SBruce Richardson /**< xform type */ 269*99a2dd95SBruce Richardson union { 270*99a2dd95SBruce Richardson struct rte_comp_compress_xform compress; 271*99a2dd95SBruce Richardson /**< xform for compress operation */ 272*99a2dd95SBruce Richardson struct rte_comp_decompress_xform decompress; 273*99a2dd95SBruce Richardson /**< decompress xform */ 274*99a2dd95SBruce Richardson }; 275*99a2dd95SBruce Richardson }; 276*99a2dd95SBruce Richardson 277*99a2dd95SBruce Richardson /** 278*99a2dd95SBruce Richardson * Compression Operation. 279*99a2dd95SBruce Richardson * 280*99a2dd95SBruce Richardson * This structure contains data relating to performing a compression 281*99a2dd95SBruce Richardson * operation on the referenced mbuf data buffers. 282*99a2dd95SBruce Richardson * 283*99a2dd95SBruce Richardson * Comp operations are enqueued and dequeued in comp PMDs using the 284*99a2dd95SBruce Richardson * rte_compressdev_enqueue_burst() / rte_compressdev_dequeue_burst() APIs 285*99a2dd95SBruce Richardson */ 286*99a2dd95SBruce Richardson struct rte_comp_op { 287*99a2dd95SBruce Richardson enum rte_comp_op_type op_type; 288*99a2dd95SBruce Richardson union { 289*99a2dd95SBruce Richardson void *private_xform; 290*99a2dd95SBruce Richardson /**< Stateless private PMD data derived from an rte_comp_xform. 291*99a2dd95SBruce Richardson * A handle returned by rte_compressdev_private_xform_create() 292*99a2dd95SBruce Richardson * must be attached to operations of op_type RTE_COMP_STATELESS. 293*99a2dd95SBruce Richardson */ 294*99a2dd95SBruce Richardson void *stream; 295*99a2dd95SBruce Richardson /**< Private PMD data derived initially from an rte_comp_xform, 296*99a2dd95SBruce Richardson * which holds state and history data and evolves as operations 297*99a2dd95SBruce Richardson * are processed. rte_compressdev_stream_create() must be called 298*99a2dd95SBruce Richardson * on a device for all STATEFUL data streams and the resulting 299*99a2dd95SBruce Richardson * stream attached to the one or more operations associated 300*99a2dd95SBruce Richardson * with the data stream. 301*99a2dd95SBruce Richardson * All operations in a stream must be sent to the same device. 302*99a2dd95SBruce Richardson */ 303*99a2dd95SBruce Richardson }; 304*99a2dd95SBruce Richardson 305*99a2dd95SBruce Richardson struct rte_mempool *mempool; 306*99a2dd95SBruce Richardson /**< Pool from which operation is allocated */ 307*99a2dd95SBruce Richardson rte_iova_t iova_addr; 308*99a2dd95SBruce Richardson /**< IOVA address of this operation */ 309*99a2dd95SBruce Richardson struct rte_mbuf *m_src; 310*99a2dd95SBruce Richardson /**< source mbuf 311*99a2dd95SBruce Richardson * The total size of the input buffer(s) can be retrieved using 312*99a2dd95SBruce Richardson * rte_pktmbuf_pkt_len(m_src). The max data size which can fit in a 313*99a2dd95SBruce Richardson * single mbuf is limited by the uint16_t rte_mbuf.data_len to 64k-1. 314*99a2dd95SBruce Richardson * If the input data is bigger than this it can be passed to the PMD in 315*99a2dd95SBruce Richardson * a chain of mbufs if the PMD's capabilities indicate it supports this. 316*99a2dd95SBruce Richardson */ 317*99a2dd95SBruce Richardson struct rte_mbuf *m_dst; 318*99a2dd95SBruce Richardson /**< destination mbuf 319*99a2dd95SBruce Richardson * The total size of the output buffer(s) can be retrieved using 320*99a2dd95SBruce Richardson * rte_pktmbuf_pkt_len(m_dst). The max data size which can fit in a 321*99a2dd95SBruce Richardson * single mbuf is limited by the uint16_t rte_mbuf.data_len to 64k-1. 322*99a2dd95SBruce Richardson * If the output data is expected to be bigger than this a chain of 323*99a2dd95SBruce Richardson * mbufs can be passed to the PMD if the PMD's capabilities indicate 324*99a2dd95SBruce Richardson * it supports this. 325*99a2dd95SBruce Richardson * 326*99a2dd95SBruce Richardson * @note, if incompressible data is passed to an engine for compression 327*99a2dd95SBruce Richardson * using RTE_COMP_ALGO_DEFLATE, it's possible for the output data 328*99a2dd95SBruce Richardson * to be larger than the uncompressed data, due to the inclusion 329*99a2dd95SBruce Richardson * of the DEFLATE header blocks. The size of m_dst should accommodate 330*99a2dd95SBruce Richardson * this, else OUT_OF_SPACE errors can be expected in this case. 331*99a2dd95SBruce Richardson */ 332*99a2dd95SBruce Richardson 333*99a2dd95SBruce Richardson struct { 334*99a2dd95SBruce Richardson uint32_t offset; 335*99a2dd95SBruce Richardson /**< Starting point for compression or decompression, 336*99a2dd95SBruce Richardson * specified as number of bytes from start of packet in 337*99a2dd95SBruce Richardson * source buffer. 338*99a2dd95SBruce Richardson * This offset starts from the first segment 339*99a2dd95SBruce Richardson * of the buffer, in case the m_src is a chain of mbufs. 340*99a2dd95SBruce Richardson * Starting point for checksum generation in compress direction. 341*99a2dd95SBruce Richardson */ 342*99a2dd95SBruce Richardson uint32_t length; 343*99a2dd95SBruce Richardson /**< The length, in bytes, of the data in source buffer 344*99a2dd95SBruce Richardson * to be compressed or decompressed. 345*99a2dd95SBruce Richardson * Also the length of the data over which the checksum 346*99a2dd95SBruce Richardson * should be generated in compress direction 347*99a2dd95SBruce Richardson */ 348*99a2dd95SBruce Richardson } src; 349*99a2dd95SBruce Richardson struct { 350*99a2dd95SBruce Richardson uint32_t offset; 351*99a2dd95SBruce Richardson /**< Starting point for writing output data, specified as 352*99a2dd95SBruce Richardson * number of bytes from start of packet in dest 353*99a2dd95SBruce Richardson * buffer. 354*99a2dd95SBruce Richardson * This offset starts from the first segment 355*99a2dd95SBruce Richardson * of the buffer, in case the m_dst is a chain of mbufs. 356*99a2dd95SBruce Richardson * Starting point for checksum generation in 357*99a2dd95SBruce Richardson * decompress direction. 358*99a2dd95SBruce Richardson */ 359*99a2dd95SBruce Richardson } dst; 360*99a2dd95SBruce Richardson struct { 361*99a2dd95SBruce Richardson uint8_t *digest; 362*99a2dd95SBruce Richardson /**< Output buffer to store hash output, if enabled in xform. 363*99a2dd95SBruce Richardson * Buffer would contain valid value only after an op with 364*99a2dd95SBruce Richardson * flush flag = RTE_COMP_FLUSH_FULL/FLUSH_FINAL is processed 365*99a2dd95SBruce Richardson * successfully. 366*99a2dd95SBruce Richardson * 367*99a2dd95SBruce Richardson * Length of buffer should be contiguous and large enough to 368*99a2dd95SBruce Richardson * accommodate digest produced by specific hash algo. 369*99a2dd95SBruce Richardson */ 370*99a2dd95SBruce Richardson rte_iova_t iova_addr; 371*99a2dd95SBruce Richardson /**< IO address of the buffer */ 372*99a2dd95SBruce Richardson } hash; 373*99a2dd95SBruce Richardson enum rte_comp_flush_flag flush_flag; 374*99a2dd95SBruce Richardson /**< Defines flush characteristics for the output data. 375*99a2dd95SBruce Richardson * Only applicable in compress direction 376*99a2dd95SBruce Richardson */ 377*99a2dd95SBruce Richardson uint64_t input_chksum; 378*99a2dd95SBruce Richardson /**< An input checksum can be provided to generate a 379*99a2dd95SBruce Richardson * cumulative checksum across sequential blocks in a STATELESS stream. 380*99a2dd95SBruce Richardson * Checksum type is as specified in xform chksum_type 381*99a2dd95SBruce Richardson */ 382*99a2dd95SBruce Richardson uint64_t output_chksum; 383*99a2dd95SBruce Richardson /**< If a checksum is generated it will be written in here. 384*99a2dd95SBruce Richardson * Checksum type is as specified in xform chksum_type. 385*99a2dd95SBruce Richardson */ 386*99a2dd95SBruce Richardson uint32_t consumed; 387*99a2dd95SBruce Richardson /**< The number of bytes from the source buffer 388*99a2dd95SBruce Richardson * which were compressed/decompressed. 389*99a2dd95SBruce Richardson */ 390*99a2dd95SBruce Richardson uint32_t produced; 391*99a2dd95SBruce Richardson /**< The number of bytes written to the destination buffer 392*99a2dd95SBruce Richardson * which were compressed/decompressed. 393*99a2dd95SBruce Richardson */ 394*99a2dd95SBruce Richardson uint64_t debug_status; 395*99a2dd95SBruce Richardson /**< 396*99a2dd95SBruce Richardson * Status of the operation is returned in the status param. 397*99a2dd95SBruce Richardson * This field allows the PMD to pass back extra 398*99a2dd95SBruce Richardson * pmd-specific debug information. Value is not defined on the API. 399*99a2dd95SBruce Richardson */ 400*99a2dd95SBruce Richardson uint8_t status; 401*99a2dd95SBruce Richardson /**< 402*99a2dd95SBruce Richardson * Operation status - use values from enum rte_comp_status. 403*99a2dd95SBruce Richardson * This is reset to 404*99a2dd95SBruce Richardson * RTE_COMP_OP_STATUS_NOT_PROCESSED on allocation from mempool and 405*99a2dd95SBruce Richardson * will be set to RTE_COMP_OP_STATUS_SUCCESS after operation 406*99a2dd95SBruce Richardson * is successfully processed by a PMD 407*99a2dd95SBruce Richardson */ 408*99a2dd95SBruce Richardson } __rte_cache_aligned; 409*99a2dd95SBruce Richardson 410*99a2dd95SBruce Richardson /** 411*99a2dd95SBruce Richardson * Creates an operation pool 412*99a2dd95SBruce Richardson * 413*99a2dd95SBruce Richardson * @param name 414*99a2dd95SBruce Richardson * Compress pool name 415*99a2dd95SBruce Richardson * @param nb_elts 416*99a2dd95SBruce Richardson * Number of elements in pool 417*99a2dd95SBruce Richardson * @param cache_size 418*99a2dd95SBruce Richardson * Number of elements to cache on lcore, see 419*99a2dd95SBruce Richardson * *rte_mempool_create* for further details about cache size 420*99a2dd95SBruce Richardson * @param user_size 421*99a2dd95SBruce Richardson * Size of private data to allocate for user with each operation 422*99a2dd95SBruce Richardson * @param socket_id 423*99a2dd95SBruce Richardson * Socket to identifier allocate memory on 424*99a2dd95SBruce Richardson * @return 425*99a2dd95SBruce Richardson * - On success pointer to mempool 426*99a2dd95SBruce Richardson * - On failure NULL 427*99a2dd95SBruce Richardson */ 428*99a2dd95SBruce Richardson __rte_experimental 429*99a2dd95SBruce Richardson struct rte_mempool * 430*99a2dd95SBruce Richardson rte_comp_op_pool_create(const char *name, 431*99a2dd95SBruce Richardson unsigned int nb_elts, unsigned int cache_size, 432*99a2dd95SBruce Richardson uint16_t user_size, int socket_id); 433*99a2dd95SBruce Richardson 434*99a2dd95SBruce Richardson /** 435*99a2dd95SBruce Richardson * Allocate an operation from a mempool with default parameters set 436*99a2dd95SBruce Richardson * 437*99a2dd95SBruce Richardson * @param mempool 438*99a2dd95SBruce Richardson * Compress operation mempool 439*99a2dd95SBruce Richardson * 440*99a2dd95SBruce Richardson * @return 441*99a2dd95SBruce Richardson * - On success returns a valid rte_comp_op structure 442*99a2dd95SBruce Richardson * - On failure returns NULL 443*99a2dd95SBruce Richardson */ 444*99a2dd95SBruce Richardson __rte_experimental 445*99a2dd95SBruce Richardson struct rte_comp_op * 446*99a2dd95SBruce Richardson rte_comp_op_alloc(struct rte_mempool *mempool); 447*99a2dd95SBruce Richardson 448*99a2dd95SBruce Richardson /** 449*99a2dd95SBruce Richardson * Bulk allocate operations from a mempool with default parameters set 450*99a2dd95SBruce Richardson * 451*99a2dd95SBruce Richardson * @param mempool 452*99a2dd95SBruce Richardson * Compress operation mempool 453*99a2dd95SBruce Richardson * @param ops 454*99a2dd95SBruce Richardson * Array to place allocated operations 455*99a2dd95SBruce Richardson * @param nb_ops 456*99a2dd95SBruce Richardson * Number of operations to allocate 457*99a2dd95SBruce Richardson * @return 458*99a2dd95SBruce Richardson * - nb_ops: Success, the nb_ops requested was allocated 459*99a2dd95SBruce Richardson * - 0: Not enough entries in the mempool; no ops are retrieved. 460*99a2dd95SBruce Richardson */ 461*99a2dd95SBruce Richardson __rte_experimental 462*99a2dd95SBruce Richardson int 463*99a2dd95SBruce Richardson rte_comp_op_bulk_alloc(struct rte_mempool *mempool, 464*99a2dd95SBruce Richardson struct rte_comp_op **ops, uint16_t nb_ops); 465*99a2dd95SBruce Richardson 466*99a2dd95SBruce Richardson /** 467*99a2dd95SBruce Richardson * Free operation structure 468*99a2dd95SBruce Richardson * If operation has been allocate from a rte_mempool, then the operation will 469*99a2dd95SBruce Richardson * be returned to the mempool. 470*99a2dd95SBruce Richardson * 471*99a2dd95SBruce Richardson * @param op 472*99a2dd95SBruce Richardson * Compress operation 473*99a2dd95SBruce Richardson */ 474*99a2dd95SBruce Richardson __rte_experimental 475*99a2dd95SBruce Richardson void 476*99a2dd95SBruce Richardson rte_comp_op_free(struct rte_comp_op *op); 477*99a2dd95SBruce Richardson 478*99a2dd95SBruce Richardson /** 479*99a2dd95SBruce Richardson * Bulk free operation structures 480*99a2dd95SBruce Richardson * If operations have been allocated from an rte_mempool, then the operations 481*99a2dd95SBruce Richardson * will be returned to the mempool. 482*99a2dd95SBruce Richardson * The array entry will be cleared. 483*99a2dd95SBruce Richardson * 484*99a2dd95SBruce Richardson * @param ops 485*99a2dd95SBruce Richardson * Array of Compress operations 486*99a2dd95SBruce Richardson * @param nb_ops 487*99a2dd95SBruce Richardson * Number of operations to free 488*99a2dd95SBruce Richardson */ 489*99a2dd95SBruce Richardson __rte_experimental 490*99a2dd95SBruce Richardson void 491*99a2dd95SBruce Richardson rte_comp_op_bulk_free(struct rte_comp_op **ops, uint16_t nb_ops); 492*99a2dd95SBruce Richardson 493*99a2dd95SBruce Richardson /** 494*99a2dd95SBruce Richardson * Get the name of a compress service feature flag 495*99a2dd95SBruce Richardson * 496*99a2dd95SBruce Richardson * @param flag 497*99a2dd95SBruce Richardson * The mask describing the flag 498*99a2dd95SBruce Richardson * 499*99a2dd95SBruce Richardson * @return 500*99a2dd95SBruce Richardson * The name of this flag, or NULL if it's not a valid feature flag. 501*99a2dd95SBruce Richardson */ 502*99a2dd95SBruce Richardson __rte_experimental 503*99a2dd95SBruce Richardson const char * 504*99a2dd95SBruce Richardson rte_comp_get_feature_name(uint64_t flag); 505*99a2dd95SBruce Richardson 506*99a2dd95SBruce Richardson #ifdef __cplusplus 507*99a2dd95SBruce Richardson } 508*99a2dd95SBruce Richardson #endif 509*99a2dd95SBruce Richardson 510*99a2dd95SBruce Richardson #endif /* _RTE_COMP_H_ */ 511