1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright(c) 2007-2022 Intel Corporation */ 3 /* $FreeBSD$ */ 4 /** 5 ***************************************************************************** 6 * @file dc_datapath.h 7 * 8 * @ingroup Dc_DataCompression 9 * 10 * @description 11 * Definition of the Data Compression datapath parameters. 12 * 13 ******************* 14 * **********************************************************/ 15 #ifndef DC_DATAPATH_H_ 16 #define DC_DATAPATH_H_ 17 18 #define LAC_QAT_DC_REQ_SZ_LW 32 19 #define LAC_QAT_DC_RESP_SZ_LW 8 20 21 /* Restriction on the source buffer size for compression due to the firmware 22 * processing */ 23 #define DC_SRC_BUFFER_MIN_SIZE (15) 24 25 /* Restriction on the destination buffer size for compression due to 26 * the management of skid buffers in the firmware */ 27 #define DC_DEST_BUFFER_DYN_MIN_SIZE (128) 28 #define DC_DEST_BUFFER_STA_MIN_SIZE (64) 29 /* C62x and C3xxx pcie rev0 devices require an additional 32bytes */ 30 #define DC_DEST_BUFFER_STA_ADDITIONAL_SIZE (32) 31 32 /* C4xxx device only requires 47 bytes */ 33 #define DC_DEST_BUFFER_MIN_SIZE (47) 34 35 /* Minimum destination buffer size for decompression */ 36 #define DC_DEST_BUFFER_DEC_MIN_SIZE (1) 37 38 /* Restriction on the source and destination buffer sizes for compression due 39 * to the firmware taking 32 bits parameters. The max size is 2^32-1 */ 40 #define DC_BUFFER_MAX_SIZE (0xFFFFFFFF) 41 42 /* DC Source & Destination buffer type (FLAT/SGL) */ 43 #define DC_DEFAULT_QAT_PTR_TYPE QAT_COMN_PTR_TYPE_SGL 44 #define DC_DP_QAT_PTR_TYPE QAT_COMN_PTR_TYPE_FLAT 45 46 /* Offset to first byte of Input Byte Counter (IBC) in state register */ 47 #define DC_STATE_IBC_OFFSET (8) 48 /* Size in bytes of input byte counter (IBC) in state register */ 49 #define DC_IBC_SIZE_IN_BYTES (4) 50 51 /* Offset to first byte to CRC32 in state register */ 52 #define DC_STATE_CRC32_OFFSET (40) 53 /* Offset to first byte to output CRC32 in state register */ 54 #define DC_STATE_OUTPUT_CRC32_OFFSET (48) 55 /* Offset to first byte to input CRC32 in state register */ 56 #define DC_STATE_INPUT_CRC32_OFFSET (52) 57 58 /* Offset to first byte of ADLER32 in state register */ 59 #define DC_STATE_ADLER32_OFFSET (48) 60 61 /* 8 bit mask value */ 62 #define DC_8_BIT_MASK (0xff) 63 64 /* 8 bit shift position */ 65 #define DC_8_BIT_SHIFT_POS (8) 66 67 /* Size in bytes of checksum */ 68 #define DC_CHECKSUM_SIZE_IN_BYTES (4) 69 70 /* Mask used to set the most significant bit to zero */ 71 #define DC_STATE_REGISTER_ZERO_MSB_MASK (0x7F) 72 73 /* Mask used to keep only the most significant bit and set the others to zero */ 74 #define DC_STATE_REGISTER_KEEP_MSB_MASK (0x80) 75 76 /* Compression state register word containing the parity bit */ 77 #define DC_STATE_REGISTER_PARITY_BIT_WORD (5) 78 79 /* Location of the parity bit within the compression state register word */ 80 #define DC_STATE_REGISTER_PARITY_BIT (7) 81 82 /* size which needs to be reserved before the results field to 83 * align the results field with the API struct */ 84 #define DC_API_ALIGNMENT_OFFSET (offsetof(CpaDcDpOpData, results)) 85 86 /* Mask used to check the CompressAndVerify capability bit */ 87 #define DC_CNV_EXTENDED_CAPABILITY (0x01) 88 89 /* Mask used to check the CompressAndVerifyAndRecover capability bit */ 90 #define DC_CNVNR_EXTENDED_CAPABILITY (0x100) 91 92 /* Default values for CNV integrity checks, 93 * those are used to inform hardware of specifying CRC parameters to be used 94 * when calculating CRCs */ 95 #define DC_CRC_POLY_DEFAULT 0x04c11db7 96 #define DC_XOR_FLAGS_DEFAULT 0xe0000 97 #define DC_XOR_OUT_DEFAULT 0xffffffff 98 #define DC_INVALID_CRC 0x0 99 100 /** 101 ******************************************************************************* 102 * @ingroup cpaDc Data Compression 103 * Compression cookie 104 * @description 105 * This cookie stores information for a particular compression perform op. 106 * This includes various user-supplied parameters for the operation which 107 * will be needed in our callback function. 108 * A pointer to this cookie is stored in the opaque data field of the QAT 109 * message so that it can be accessed in the asynchronous callback. 110 * @note 111 * The order of the parameters within this structure is important. It needs 112 * to match the order of the parameters in CpaDcDpOpData up to the 113 * pSessionHandle. This allows the correct processing of the callback. 114 *****************************************************************************/ 115 typedef struct dc_compression_cookie_s { 116 Cpa8U dcReqParamsBuffer[DC_API_ALIGNMENT_OFFSET]; 117 /**< Memory block - was previously reserved for request parameters. 118 * Now size maintained so following members align with API struct, 119 * but no longer used for request parameters */ 120 CpaDcRqResults reserved; 121 /**< This is reserved for results to correctly align the structure 122 * to match the one from the data plane API */ 123 CpaInstanceHandle dcInstance; 124 /**< Compression instance handle */ 125 CpaDcSessionHandle pSessionHandle; 126 /**< Pointer to the session handle */ 127 icp_qat_fw_comp_req_t request; 128 /**< Compression request */ 129 void *callbackTag; 130 /**< Opaque data supplied by the client */ 131 dc_session_desc_t *pSessionDesc; 132 /**< Pointer to the session descriptor */ 133 CpaDcFlush flushFlag; 134 /**< Flush flag */ 135 CpaDcOpData *pDcOpData; 136 /**< struct containing flags and CRC related data for this session */ 137 CpaDcRqResults *pResults; 138 /**< Pointer to result buffer holding consumed and produced data */ 139 Cpa32U srcTotalDataLenInBytes; 140 /**< Total length of the source data */ 141 Cpa32U dstTotalDataLenInBytes; 142 /**< Total length of the destination data */ 143 dc_request_dir_t compDecomp; 144 /**< Used to know whether the request is compression or decompression. 145 * Useful when defining the session as combined */ 146 CpaBufferList *pUserSrcBuff; 147 /**< virtual userspace ptr to source SGL */ 148 CpaBufferList *pUserDestBuff; 149 /**< virtual userspace ptr to destination SGL */ 150 } dc_compression_cookie_t; 151 152 /** 153 ***************************************************************************** 154 * @ingroup Dc_DataCompression 155 * Callback function called for compression and decompression requests in 156 * asynchronous mode 157 * 158 * @description 159 * Called to process compression and decompression response messages. This 160 * callback will check for errors, update the statistics and will call the 161 * user callback 162 * 163 * @param[in] pRespMsg Response message 164 * 165 *****************************************************************************/ 166 void dcCompression_ProcessCallback(void *pRespMsg); 167 168 /** 169 ***************************************************************************** 170 * @ingroup Dc_DataCompression 171 * Describes CNV and CNVNR modes 172 * 173 * @description 174 * This enum is used to indicate the CNV modes. 175 * 176 *****************************************************************************/ 177 typedef enum dc_cnv_mode_s { 178 DC_NO_CNV = 0, 179 /* CNV = FALSE, CNVNR = FALSE */ 180 DC_CNV, 181 /* CNV = TRUE, CNVNR = FALSE */ 182 DC_CNVNR, 183 /* CNV = TRUE, CNVNR = TRUE */ 184 } dc_cnv_mode_t; 185 186 #endif /* DC_DATAPATH_H_ */ 187