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