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