xref: /freebsd-src/sys/dev/qat/qat_api/common/compression/include/dc_session.h (revision b97ee269eae3cbaf35c18f51a459aea581c2a7dc)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4 /**
5  *****************************************************************************
6  * @file dc_session.h
7  *
8  * @ingroup Dc_DataCompression
9  *
10  * @description
11  *      Definition of the Data Compression session parameters.
12  *
13  *****************************************************************************/
14 #ifndef DC_SESSION_H
15 #define DC_SESSION_H
16 
17 #include "cpa_dc_dp.h"
18 #include "icp_qat_fw_comp.h"
19 #include "sal_qat_cmn_msg.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_8K_WINDOW_SIZE (5)
39 #define DC_16K_WINDOW_SIZE (6)
40 #define DC_32K_WINDOW_SIZE (7)
41 
42 /* Context size */
43 #define DC_DEFLATE_MAX_CONTEXT_SIZE (49152)
44 #define DC_INFLATE_CONTEXT_SIZE (36864)
45 
46 #define DC_DEFLATE_EH_MAX_CONTEXT_SIZE (65536)
47 #define DC_DEFLATE_EH_MIN_CONTEXT_SIZE (49152)
48 #define DC_INFLATE_EH_CONTEXT_SIZE (34032)
49 
50 /* Retrieve the session descriptor pointer from the session context structure
51  * that the user allocates. The pointer to the internally realigned address
52  * is stored at the start of the session context that the user allocates */
53 #define DC_SESSION_DESC_FROM_CTX_GET(pSession)                                 \
54 	(dc_session_desc_t *)(*(LAC_ARCH_UINT *)pSession)
55 
56 /* Maximum size for the compression part of the content descriptor */
57 #define DC_QAT_COMP_CONTENT_DESC_SIZE sizeof(icp_qat_fw_comp_cd_hdr_t)
58 
59 /* Maximum size for the translator part of the content descriptor */
60 #define DC_QAT_TRANS_CONTENT_DESC_SIZE                                         \
61 	(sizeof(icp_qat_fw_xlt_cd_hdr_t) + DC_QAT_MAX_TRANS_SETUP_BLK_SZ)
62 
63 /* Maximum size of the decompression content descriptor */
64 #define DC_QAT_CONTENT_DESC_DECOMP_MAX_SIZE                                    \
65 	LAC_ALIGN_POW2_ROUNDUP(DC_QAT_COMP_CONTENT_DESC_SIZE,                  \
66 			       (1 << LAC_64BYTE_ALIGNMENT_SHIFT))
67 
68 /* Maximum size of the compression content descriptor */
69 #define DC_QAT_CONTENT_DESC_COMP_MAX_SIZE                                      \
70 	LAC_ALIGN_POW2_ROUNDUP(DC_QAT_COMP_CONTENT_DESC_SIZE +                 \
71 				   DC_QAT_TRANS_CONTENT_DESC_SIZE,             \
72 			       (1 << LAC_64BYTE_ALIGNMENT_SHIFT))
73 
74 /* Direction of the request */
75 typedef enum dc_request_dir_e {
76 	DC_COMPRESSION_REQUEST = 1,
77 	DC_DECOMPRESSION_REQUEST
78 } dc_request_dir_t;
79 
80 /* Type of the compression request */
81 typedef enum dc_request_type_e {
82 	DC_REQUEST_FIRST = 1,
83 	DC_REQUEST_SUBSEQUENT
84 } dc_request_type_t;
85 
86 typedef enum dc_block_type_e {
87 	DC_CLEARTEXT_TYPE = 0,
88 	DC_STATIC_TYPE,
89 	DC_DYNAMIC_TYPE
90 } dc_block_type_t;
91 
92 /* Internal data structure supporting end to end data integrity checks. */
93 typedef struct dc_integrity_crc_fw_s {
94 	Cpa32U crc32;
95 	/* CRC32 checksum returned for compressed data */
96 	Cpa32U adler32;
97 	/* ADLER32 checksum returned for compressed data */
98 	Cpa32U oCrc32Cpr;
99 	/* CRC32 checksum returned for data output by compression accelerator */
100 	Cpa32U iCrc32Cpr;
101 	/* CRC32 checksum returned for input data to compression accelerator */
102 	Cpa32U oCrc32Xlt;
103 	/* CRC32 checksum returned for data output by translator accelerator */
104 	Cpa32U iCrc32Xlt;
105 	/* CRC32 checksum returned for input data to translator accelerator */
106 	Cpa32U xorFlags;
107 	/* Initialise transactor pCRC controls in state register */
108 	Cpa32U crcPoly;
109 	/* CRC32 polynomial used by hardware */
110 	Cpa32U xorOut;
111 	/* CRC32 from XOR stage (Input CRC is xor'ed with value in the state) */
112 	Cpa32U deflateBlockType;
113 	/* Bit 1 - Bit 0
114 	 *   0        0 -> RAW DATA + Deflate header.
115 	 *                 This will not produced any CRC check because
116 	 *                 the output will not come from the slices.
117 	 *                 It will be a simple copy from input to output
118 	 *                 buffers list.
119 	 *   0        1 -> Static deflate block type
120 	 *   1        0 -> Dynamic deflate block type
121 	 *   1        1 -> Invalid type */
122 } dc_integrity_crc_fw_t;
123 
124 typedef struct dc_sw_checksums_s {
125 	Cpa32U swCrcI;
126 	Cpa32U swCrcO;
127 } dc_sw_checksums_t;
128 
129 /* Session descriptor structure for compression */
130 typedef struct dc_session_desc_s {
131 	Cpa8U stateRegistersComp[DC_QAT_STATE_REGISTERS_MAX_SIZE];
132 	/**< State registers for compression */
133 	Cpa8U stateRegistersDecomp[DC_QAT_STATE_REGISTERS_MAX_SIZE];
134 	/**< State registers for decompression */
135 	icp_qat_fw_comp_req_t reqCacheComp;
136 	/**< Cache as much as possible of the compression request in a pre-built
137 	 * request */
138 	icp_qat_fw_comp_req_t reqCacheDecomp;
139 	/**< Cache as much as possible of the decompression request in a
140 	 * pre-built
141 	 * request */
142 	dc_request_type_t requestType;
143 	/**< Type of the compression request. As stateful mode do not support
144 	 * more
145 	 * than one in-flight request there is no need to use spinlocks */
146 	dc_request_type_t previousRequestType;
147 	/**< Type of the previous compression request. Used in cases where there
148 	 * the
149 	 * stateful operation needs to be resubmitted */
150 	CpaDcHuffType huffType;
151 	/**< Huffman tree type */
152 	CpaDcCompType compType;
153 	/**< Compression type */
154 	CpaDcChecksum checksumType;
155 	/**< Type of checksum */
156 	CpaDcAutoSelectBest autoSelectBestHuffmanTree;
157 	/**< Indicates if the implementation selects the best Huffman encoding
158 	 */
159 	CpaDcSessionDir sessDirection;
160 	/**< Session direction */
161 	CpaDcSessionState sessState;
162 	/**< Session state */
163 	Cpa32U deflateWindowSize;
164 	/**< Window size */
165 	CpaDcCompLvl compLevel;
166 	/**< Compression level */
167 	CpaDcCallbackFn pCompressionCb;
168 	/**< Callback function defined for the traditional compression session
169 	 */
170 	QatUtilsAtomic pendingStatelessCbCount;
171 	/**< Keeps track of number of pending requests on stateless session */
172 	QatUtilsAtomic pendingStatefulCbCount;
173 	/**< Keeps track of number of pending requests on stateful session */
174 	Cpa64U pendingDpStatelessCbCount;
175 	/**< Keeps track of number of data plane pending requests on stateless
176 	 * session */
177 	struct mtx sessionLock;
178 	/**< Lock used to provide exclusive access for number of stateful
179 	 * in-flight
180 	 * requests update */
181 	CpaBoolean isDcDp;
182 	/**< Indicates if the data plane API is used */
183 	Cpa32U minContextSize;
184 	/**< Indicates the minimum size required to allocate the context buffer
185 	 */
186 	CpaBufferList *pContextBuffer;
187 	/**< Context buffer */
188 	Cpa32U historyBuffSize;
189 	/**< Size of the history buffer */
190 	Cpa64U cumulativeConsumedBytes;
191 	/**< Cumulative amount of consumed bytes. Used to build the footer in
192 	 * the
193 	 * stateful case */
194 	Cpa32U previousChecksum;
195 	/**< Save the previous value of the checksum. Used to process zero byte
196 	 * stateful compression or decompression requests */
197 	CpaBoolean isSopForCompressionProcessed;
198 	/**< Indicates whether a Compression Request is received in this session
199 	 */
200 	CpaBoolean isSopForDecompressionProcessed;
201 	/**< Indicates whether a Decompression Request is received in this
202 	 * session
203 	 */
204 	/**< Data integrity table */
205 	dc_integrity_crc_fw_t dataIntegrityCrcs;
206 	/**< Physical address of Data integrity buffer */
207 	CpaPhysicalAddr physDataIntegrityCrcs;
208 	/* Seed checksums structure used to calculate software calculated
209 	 * checksums.
210 	 */
211 	dc_sw_checksums_t seedSwCrc;
212 	/* Driver calculated integrity software CRC */
213 	dc_sw_checksums_t integritySwCrc;
214 } dc_session_desc_t;
215 
216 /**
217  *****************************************************************************
218  * @ingroup Dc_DataCompression
219  *      Initialise a compression session
220  *
221  * @description
222  *      This function will initialise a compression session
223  *
224  * @param[in]       dcInstance       Instance handle derived from discovery
225  *                                   functions
226  * @param[in,out]   pSessionHandle   Pointer to a session handle
227  * @param[in,out]   pSessionData     Pointer to a user instantiated structure
228  *                                   containing session data
229  * @param[in]       pContextBuffer   Pointer to context buffer
230  *
231  * @param[in]       callbackFn       For synchronous operation this callback
232  *                                   shall be a null pointer
233  *
234  * @retval CPA_STATUS_SUCCESS        Function executed successfully
235  * @retval CPA_STATUS_FAIL           Function failed
236  * @retval CPA_STATUS_INVALID_PARAM  Invalid parameter passed in
237  * @retval CPA_STATUS_RESOURCE       Error related to system resources
238  *****************************************************************************/
239 CpaStatus dcInitSession(CpaInstanceHandle dcInstance,
240 			CpaDcSessionHandle pSessionHandle,
241 			CpaDcSessionSetupData *pSessionData,
242 			CpaBufferList *pContextBuffer,
243 			CpaDcCallbackFn callbackFn);
244 
245 /**
246  *****************************************************************************
247  * @ingroup Dc_DataCompression
248  *      Get the size of the memory required to hold the session information
249  *
250  * @description
251  *      This function will get the size of the memory required to hold the
252  *      session information
253  *
254  * @param[in]       dcInstance       Instance handle derived from discovery
255  *                                   functions
256  * @param[in]       pSessionData     Pointer to a user instantiated structure
257  *                                   containing session data
258  * @param[out]      pSessionSize     On return, this parameter will be the size
259  *                                   of the memory that will be
260  *                                   required by cpaDcInitSession() for session
261  *                                   data.
262  * @param[out]      pContextSize     On return, this parameter will be the size
263  *                                   of the memory that will be required
264  *                                   for context data.  Context data is
265  *                                   save/restore data including history and
266  *                                   any implementation specific data that is
267  *                                   required for a save/restore operation.
268  *
269  * @retval CPA_STATUS_SUCCESS        Function executed successfully
270  * @retval CPA_STATUS_FAIL           Function failed
271  * @retval CPA_STATUS_INVALID_PARAM  Invalid parameter passed in
272  *****************************************************************************/
273 CpaStatus dcGetSessionSize(CpaInstanceHandle dcInstance,
274 			   CpaDcSessionSetupData *pSessionData,
275 			   Cpa32U *pSessionSize,
276 			   Cpa32U *pContextSize);
277 
278 #endif /* DC_SESSION_H */
279