1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright(c) 2007-2022 Intel Corporation */ 3 /** 4 ***************************************************************************** 5 * @file dc_session.h 6 * 7 * @ingroup Dc_DataCompression 8 * 9 * @description 10 * Definition of the Data Compression session parameters. 11 * 12 *****************************************************************************/ 13 #ifndef DC_SESSION_H 14 #define DC_SESSION_H 15 16 #include "cpa_dc_dp.h" 17 #include "icp_qat_fw_comp.h" 18 #include "sal_qat_cmn_msg.h" 19 #include "sal_types_compression.h" 20 21 /* Maximum number of intermediate buffers SGLs for devices 22 * with a maximum of 6 compression slices */ 23 #define DC_QAT_MAX_NUM_INTER_BUFFERS_6COMP_SLICES (12) 24 25 /* Maximum number of intermediate buffers SGLs for devices 26 * with a maximum of 10 max compression slices */ 27 #define DC_QAT_MAX_NUM_INTER_BUFFERS_10COMP_SLICES (20) 28 29 /* Maximum number of intermediate buffers SGLs for devices 30 * with a maximum of 24 max compression slices and 32 MEs */ 31 #define DC_QAT_MAX_NUM_INTER_BUFFERS_24COMP_SLICES (64) 32 33 /* Maximum size of the state registers 64 bytes */ 34 #define DC_QAT_STATE_REGISTERS_MAX_SIZE (64) 35 36 /* Size of the history window. 37 * Base 2 logarithm of maximum window size minus 8 */ 38 #define DC_4K_WINDOW_SIZE (4) 39 #define DC_8K_WINDOW_SIZE (5) 40 #define DC_16K_WINDOW_SIZE (6) 41 #define DC_32K_WINDOW_SIZE (7) 42 43 /* Context size */ 44 #define DC_DEFLATE_MAX_CONTEXT_SIZE (49152) 45 #define DC_INFLATE_CONTEXT_SIZE (36864) 46 47 #define DC_DEFLATE_EH_MAX_CONTEXT_SIZE (65536) 48 #define DC_DEFLATE_EH_MIN_CONTEXT_SIZE (49152) 49 #define DC_INFLATE_EH_CONTEXT_SIZE (34032) 50 51 /* Retrieve the session descriptor pointer from the session context structure 52 * that the user allocates. The pointer to the internally realigned address 53 * is stored at the start of the session context that the user allocates */ 54 #define DC_SESSION_DESC_FROM_CTX_GET(pSession) \ 55 (dc_session_desc_t *)(*(LAC_ARCH_UINT *)pSession) 56 57 /* Maximum size for the compression part of the content descriptor */ 58 #define DC_QAT_COMP_CONTENT_DESC_SIZE sizeof(icp_qat_fw_comp_cd_hdr_t) 59 60 /* Maximum size for the translator part of the content descriptor */ 61 #define DC_QAT_TRANS_CONTENT_DESC_SIZE \ 62 (sizeof(icp_qat_fw_xlt_cd_hdr_t) + DC_QAT_MAX_TRANS_SETUP_BLK_SZ) 63 64 /* Maximum size of the decompression content descriptor */ 65 #define DC_QAT_CONTENT_DESC_DECOMP_MAX_SIZE \ 66 LAC_ALIGN_POW2_ROUNDUP(DC_QAT_COMP_CONTENT_DESC_SIZE, \ 67 (1 << LAC_64BYTE_ALIGNMENT_SHIFT)) 68 69 /* Maximum size of the compression content descriptor */ 70 #define DC_QAT_CONTENT_DESC_COMP_MAX_SIZE \ 71 LAC_ALIGN_POW2_ROUNDUP(DC_QAT_COMP_CONTENT_DESC_SIZE + \ 72 DC_QAT_TRANS_CONTENT_DESC_SIZE, \ 73 (1 << LAC_64BYTE_ALIGNMENT_SHIFT)) 74 75 /* Direction of the request */ 76 typedef enum dc_request_dir_e { 77 DC_COMPRESSION_REQUEST = 1, 78 DC_DECOMPRESSION_REQUEST 79 } dc_request_dir_t; 80 81 /* Type of the compression request */ 82 typedef enum dc_request_type_e { 83 DC_REQUEST_FIRST = 1, 84 DC_REQUEST_SUBSEQUENT 85 } dc_request_type_t; 86 87 typedef enum dc_block_type_e { 88 DC_CLEARTEXT_TYPE = 0, 89 DC_STATIC_TYPE, 90 DC_DYNAMIC_TYPE 91 } dc_block_type_t; 92 93 /* Internal data structure supporting end to end data integrity checks. */ 94 typedef struct dc_integrity_crc_fw_s { 95 Cpa32U crc32; 96 /* CRC32 checksum returned for compressed data */ 97 Cpa32U adler32; 98 /* ADLER32 checksum returned for compressed data */ 99 100 union { 101 struct { 102 Cpa32U oCrc32Cpr; 103 /* CRC32 checksum returned for data output by 104 * compression accelerator */ 105 Cpa32U iCrc32Cpr; 106 /* CRC32 checksum returned for input data to compression 107 * accelerator 108 */ 109 Cpa32U oCrc32Xlt; 110 /* CRC32 checksum returned for data output by translator 111 * accelerator 112 */ 113 Cpa32U iCrc32Xlt; 114 /* CRC32 checksum returned for input data to translator 115 * accelerator 116 */ 117 Cpa32U xorFlags; 118 /* Initialise transactor pCRC controls in state register 119 */ 120 Cpa32U crcPoly; 121 /* CRC32 polynomial used by hardware */ 122 Cpa32U xorOut; 123 /* CRC32 from XOR stage (Input CRC is xor'ed with value 124 * in the state) */ 125 Cpa32U deflateBlockType; 126 /* Bit 1 - Bit 0 127 * 0 0 -> RAW DATA + Deflate header. 128 * This will not produced any CRC check 129 * because the output will not come 130 * from the slices. It will be a simple 131 * copy from input to output buffer 132 * list. 0 1 -> Static deflate block type 1 0 -> 133 * Dynamic deflate block type 1 1 -> Invalid type 134 */ 135 }; 136 137 struct { 138 Cpa64U iCrc64Cpr; 139 /* CRC64 checksum returned for input data to compression 140 * accelerator 141 */ 142 Cpa64U oCrc64Cpr; 143 /* CRC64 checksum returned for data output by 144 * compression accelerator */ 145 Cpa64U iCrc64Xlt; 146 /* CRC64 checksum returned for input data to translator 147 * accelerator 148 */ 149 Cpa64U oCrc64Xlt; 150 /* CRC64 checksum returned for data output by translator 151 * accelerator 152 */ 153 Cpa64U crc64Poly; 154 /* CRC64 polynomial used by hardware */ 155 Cpa64U xor64Out; 156 /* CRC64 from XOR stage (Input CRC is xor'ed with value 157 * in the state) */ 158 }; 159 }; 160 } dc_integrity_crc_fw_t; 161 162 typedef struct dc_sw_checksums_s { 163 union { 164 struct { 165 Cpa32U swCrc32I; 166 Cpa32U swCrc32O; 167 }; 168 169 struct { 170 Cpa64U swCrc64I; 171 Cpa64U swCrc64O; 172 }; 173 }; 174 } dc_sw_checksums_t; 175 176 /* Session descriptor structure for compression */ 177 typedef struct dc_session_desc_s { 178 Cpa8U stateRegistersComp[DC_QAT_STATE_REGISTERS_MAX_SIZE]; 179 /**< State registers for compression */ 180 Cpa8U stateRegistersDecomp[DC_QAT_STATE_REGISTERS_MAX_SIZE]; 181 /**< State registers for decompression */ 182 icp_qat_fw_comp_req_t reqCacheComp; 183 /**< Cache as much as possible of the compression request in a pre-built 184 * request */ 185 icp_qat_fw_comp_req_t reqCacheDecomp; 186 /**< Cache as much as possible of the decompression request in a 187 * pre-built 188 * request */ 189 dc_request_type_t requestType; 190 /**< Type of the compression request. As stateful mode do not support 191 * more 192 * than one in-flight request there is no need to use spinlocks */ 193 dc_request_type_t previousRequestType; 194 /**< Type of the previous compression request. Used in cases where there 195 * the 196 * stateful operation needs to be resubmitted */ 197 CpaDcHuffType huffType; 198 /**< Huffman tree type */ 199 CpaDcCompType compType; 200 /**< Compression type */ 201 CpaDcChecksum checksumType; 202 /**< Type of checksum */ 203 CpaDcAutoSelectBest autoSelectBestHuffmanTree; 204 /**< Indicates if the implementation selects the best Huffman encoding 205 */ 206 CpaDcSessionDir sessDirection; 207 /**< Session direction */ 208 CpaDcSessionState sessState; 209 /**< Session state */ 210 CpaDcCompLvl compLevel; 211 /**< Compression level */ 212 CpaDcCallbackFn pCompressionCb; 213 /**< Callback function defined for the traditional compression session 214 */ 215 QatUtilsAtomic pendingStatelessCbCount; 216 /**< Keeps track of number of pending requests on stateless session */ 217 QatUtilsAtomic pendingStatefulCbCount; 218 /**< Keeps track of number of pending requests on stateful session */ 219 Cpa64U pendingDpStatelessCbCount; 220 /**< Keeps track of number of data plane pending requests on stateless 221 * session */ 222 struct mtx sessionLock; 223 /**< Lock used to provide exclusive access for number of stateful 224 * in-flight 225 * requests update */ 226 CpaBoolean isDcDp; 227 /**< Indicates if the data plane API is used */ 228 Cpa32U minContextSize; 229 /**< Indicates the minimum size required to allocate the context buffer 230 */ 231 CpaBufferList *pContextBuffer; 232 /**< Context buffer */ 233 Cpa32U historyBuffSize; 234 /**< Size of the history buffer */ 235 Cpa64U cumulativeConsumedBytes; 236 /**< Cumulative amount of consumed bytes. Used to build the footer in 237 * the 238 * stateful case */ 239 Cpa32U previousChecksum; 240 /**< Save the previous value of the checksum. Used to process zero byte 241 * stateful compression or decompression requests */ 242 CpaBoolean isSopForCompressionProcessed; 243 /**< Indicates whether a Compression Request is received in this session 244 */ 245 CpaBoolean isSopForDecompressionProcessed; 246 /**< Indicates whether a Decompression Request is received in this 247 * session 248 */ 249 /**< Data integrity table */ 250 dc_integrity_crc_fw_t dataIntegrityCrcs; 251 /**< Physical address of Data integrity buffer */ 252 CpaPhysicalAddr physDataIntegrityCrcs; 253 /* Seed checksums structure used to calculate software calculated 254 * checksums. 255 */ 256 dc_sw_checksums_t seedSwCrc; 257 /* Driver calculated integrity software CRC */ 258 dc_sw_checksums_t integritySwCrc; 259 /* Flag to disable or enable CnV Error Injection mechanism */ 260 CpaBoolean cnvErrorInjection; 261 } dc_session_desc_t; 262 263 /** 264 ***************************************************************************** 265 * @ingroup Dc_DataCompression 266 * Initialise a compression session 267 * 268 * @description 269 * This function will initialise a compression session 270 * 271 * @param[in] dcInstance Instance handle derived from discovery 272 * functions 273 * @param[in,out] pSessionHandle Pointer to a session handle 274 * @param[in,out] pSessionData Pointer to a user instantiated structure 275 * containing session data 276 * @param[in] pContextBuffer Pointer to context buffer 277 * 278 * @param[in] callbackFn For synchronous operation this callback 279 * shall be a null pointer 280 * 281 * @retval CPA_STATUS_SUCCESS Function executed successfully 282 * @retval CPA_STATUS_FAIL Function failed 283 * @retval CPA_STATUS_INVALID_PARAM Invalid parameter passed in 284 * @retval CPA_STATUS_RESOURCE Error related to system resources 285 *****************************************************************************/ 286 CpaStatus dcInitSession(CpaInstanceHandle dcInstance, 287 CpaDcSessionHandle pSessionHandle, 288 CpaDcSessionSetupData *pSessionData, 289 CpaBufferList *pContextBuffer, 290 CpaDcCallbackFn callbackFn); 291 292 /** 293 ***************************************************************************** 294 * @ingroup Dc_DataCompression 295 * Get the size of the memory required to hold the session information 296 * 297 * @description 298 * This function will get the size of the memory required to hold the 299 * session information 300 * 301 * @param[in] dcInstance Instance handle derived from discovery 302 * functions 303 * @param[in] pSessionData Pointer to a user instantiated structure 304 * containing session data 305 * @param[out] pSessionSize On return, this parameter will be the size 306 * of the memory that will be 307 * required by cpaDcInitSession() for session 308 * data. 309 * @param[out] pContextSize On return, this parameter will be the size 310 * of the memory that will be required 311 * for context data. Context data is 312 * save/restore data including history and 313 * any implementation specific data that is 314 * required for a save/restore operation. 315 * 316 * @retval CPA_STATUS_SUCCESS Function executed successfully 317 * @retval CPA_STATUS_FAIL Function failed 318 * @retval CPA_STATUS_INVALID_PARAM Invalid parameter passed in 319 *****************************************************************************/ 320 CpaStatus dcGetSessionSize(CpaInstanceHandle dcInstance, 321 CpaDcSessionSetupData *pSessionData, 322 Cpa32U *pSessionSize, 323 Cpa32U *pContextSize); 324 325 /** 326 ***************************************************************************** 327 * @ingroup Dc_DataCompression 328 * Set the cnvErrorInjection flag in session descriptor 329 * 330 * @description 331 * This function enables the CnVError injection for the session 332 * passed in. All Compression requests sent within the session 333 * are injected with CnV errors. This error injection is for the 334 * duration of the session. Resetting the session results in 335 * setting being cleared. CnV error injection does not apply to 336 * Data Plane API. 337 * 338 * @param[in] dcInstance Instance Handle 339 * @param[in] pSessionHandle Pointer to a session handle 340 * 341 * @retval CPA_STATUS_SUCCESS Function executed successfully 342 * @retval CPA_STATUS_INVALID_PARAM Invalid parameter passed in 343 * @retval CPA_STATUS_UNSUPPORTED Unsupported feature 344 *****************************************************************************/ 345 CpaStatus dcSetCnvError(CpaInstanceHandle dcInstance, 346 CpaDcSessionHandle pSessionHandle); 347 348 /** 349 ***************************************************************************** 350 * @ingroup Dc_DataCompression 351 * Check that pSessionData is valid 352 * 353 * @description 354 * Check that all the parameters defined in the pSessionData are valid 355 * 356 * @param[in] pSessionData Pointer to a user instantiated structure 357 * containing session data 358 * 359 * @retval CPA_STATUS_SUCCESS Function executed successfully 360 * @retval CPA_STATUS_FAIL Function failed to find device 361 * @retval CPA_STATUS_INVALID_PARAM Invalid parameter passed in 362 * @retval CPA_STATUS_UNSUPPORTED Unsupported algorithm/feature 363 * 364 *****************************************************************************/ 365 CpaStatus dcCheckSessionData(const CpaDcSessionSetupData *pSessionData, 366 CpaInstanceHandle dcInstance); 367 368 /** 369 ***************************************************************************** 370 * @ingroup Dc_DataCompression 371 * Get the compression command id for the given session setup data. 372 * 373 * @description 374 * This function will get the compression command id based on parameters 375 * passed in the given session setup data. 376 * 377 * @param[in] pService Pointer to the service 378 * @param[in] pSessionData Pointer to a user instantiated 379 * structure containing session data 380 * @param[out] pDcCmdId Pointer to the command id 381 * 382 * @retval CPA_STATUS_SUCCESS Function executed successfully 383 * @retval CPA_STATUS_UNSUPPORTED Unsupported algorithm/feature 384 * 385 *****************************************************************************/ 386 CpaStatus dcGetCompressCommandId(sal_compression_service_t *pService, 387 CpaDcSessionSetupData *pSessionData, 388 Cpa8U *pDcCmdId); 389 390 /** 391 ***************************************************************************** 392 * @ingroup Dc_DataCompression 393 * Get the decompression command id for the given session setup data. 394 * 395 * @description 396 * This function will get the decompression command id based on parameters 397 * passed in the given session setup data. 398 * 399 * @param[in] pService Pointer to the service 400 * @param[in] pSessionData Pointer to a user instantiated 401 * structure containing session data 402 * @param[out] pDcCmdId Pointer to the command id 403 * 404 * @retval CPA_STATUS_SUCCESS Function executed successfully 405 * @retval CPA_STATUS_UNSUPPORTED Unsupported algorithm/feature 406 * 407 *****************************************************************************/ 408 CpaStatus dcGetDecompressCommandId(sal_compression_service_t *pService, 409 CpaDcSessionSetupData *pSessionData, 410 Cpa8U *pDcCmdId); 411 412 /** 413 ***************************************************************************** 414 * @ingroup Dc_DataCompression 415 * Populate the translator content descriptor 416 * 417 * @description 418 * This function will populate the translator content descriptor 419 * 420 * @param[out] pMsg Pointer to the compression message 421 * @param[in] nextSlice Next slice 422 * 423 *****************************************************************************/ 424 void dcTransContentDescPopulate(icp_qat_fw_comp_req_t *pMsg, 425 icp_qat_fw_slice_t nextSlice); 426 427 #endif /* DC_SESSION_H */ 428