1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2 * Copyright(c) 2015-2018 Intel Corporation
7 #include "icp_qat_hw.h"
9 #define QAT_FIELD_SET(flags, val, bitpos, mask) \
10 { (flags) = (((flags) & (~((mask) << (bitpos)))) | \
11 (((val) & (mask)) << (bitpos))) ; }
13 #define QAT_FIELD_GET(flags, bitpos, mask) \
14 (((flags) >> (bitpos)) & (mask))
16 #define ICP_QAT_FW_REQ_DEFAULT_SZ 128
17 #define ICP_QAT_FW_RESP_DEFAULT_SZ 32
18 #define ICP_QAT_FW_COMN_ONE_BYTE_SHIFT 8
19 #define ICP_QAT_FW_COMN_SINGLE_BYTE_MASK 0xFF
20 #define ICP_QAT_FW_NUM_LONGWORDS_1 1
21 #define ICP_QAT_FW_NUM_LONGWORDS_2 2
22 #define ICP_QAT_FW_NUM_LONGWORDS_3 3
23 #define ICP_QAT_FW_NUM_LONGWORDS_4 4
24 #define ICP_QAT_FW_NUM_LONGWORDS_5 5
25 #define ICP_QAT_FW_NUM_LONGWORDS_6 6
26 #define ICP_QAT_FW_NUM_LONGWORDS_7 7
27 #define ICP_QAT_FW_NUM_LONGWORDS_10 10
28 #define ICP_QAT_FW_NUM_LONGWORDS_13 13
29 #define ICP_QAT_FW_NULL_REQ_SERV_ID 1
31 enum icp_qat_fw_comn_resp_serv_id {
32 ICP_QAT_FW_COMN_RESP_SERV_NULL,
33 ICP_QAT_FW_COMN_RESP_SERV_CPM_FW,
34 ICP_QAT_FW_COMN_RESP_SERV_DELIMITER
37 enum icp_qat_fw_comn_request_id {
38 ICP_QAT_FW_COMN_REQ_NULL = 0,
39 ICP_QAT_FW_COMN_REQ_CPM_FW_PKE = 3,
40 ICP_QAT_FW_COMN_REQ_CPM_FW_LA = 4,
41 ICP_QAT_FW_COMN_REQ_CPM_FW_DMA = 7,
42 ICP_QAT_FW_COMN_REQ_CPM_FW_COMP = 9,
43 ICP_QAT_FW_COMN_REQ_DELIMITER
46 struct icp_qat_fw_comn_req_hdr_cd_pars {
49 uint64_t content_desc_addr;
50 uint16_t content_desc_resrvd1;
51 uint8_t content_desc_params_sz;
52 uint8_t content_desc_hdr_resrvd2;
53 uint32_t content_desc_resrvd3;
56 uint32_t serv_specif_fields[4];
61 struct icp_qat_fw_comn_req_mid {
63 uint64_t src_data_addr;
64 uint64_t dest_data_addr;
69 struct icp_qat_fw_comn_req_cd_ctrl {
70 uint32_t content_desc_ctrl_lw[ICP_QAT_FW_NUM_LONGWORDS_5];
73 struct icp_qat_fw_comn_req_hdr {
75 uint8_t service_cmd_id;
78 uint16_t serv_specif_flags;
79 uint16_t comn_req_flags;
82 struct icp_qat_fw_comn_req_rqpars {
83 uint32_t serv_specif_rqpars_lw[ICP_QAT_FW_NUM_LONGWORDS_13];
86 struct icp_qat_fw_comn_req {
87 struct icp_qat_fw_comn_req_hdr comn_hdr;
88 struct icp_qat_fw_comn_req_hdr_cd_pars cd_pars;
89 struct icp_qat_fw_comn_req_mid comn_mid;
90 struct icp_qat_fw_comn_req_rqpars serv_specif_rqpars;
91 struct icp_qat_fw_comn_req_cd_ctrl cd_ctrl;
94 struct icp_qat_fw_comn_error {
95 uint8_t xlat_err_code;
99 struct icp_qat_fw_comn_resp_hdr {
102 uint8_t response_type;
104 struct icp_qat_fw_comn_error comn_error;
109 struct icp_qat_fw_comn_resp {
110 struct icp_qat_fw_comn_resp_hdr comn_hdr;
111 uint64_t opaque_data;
112 uint32_t resrvd[ICP_QAT_FW_NUM_LONGWORDS_4];
115 #define ICP_QAT_FW_COMN_REQ_FLAG_SET 1
116 #define ICP_QAT_FW_COMN_REQ_FLAG_CLR 0
117 #define ICP_QAT_FW_COMN_VALID_FLAG_BITPOS 7
118 #define ICP_QAT_FW_COMN_VALID_FLAG_MASK 0x1
119 #define ICP_QAT_FW_COMN_HDR_RESRVD_FLD_MASK 0x7F
120 #define ICP_QAT_FW_COMN_CNV_FLAG_BITPOS 6
121 #define ICP_QAT_FW_COMN_CNV_FLAG_MASK 0x1
122 #define ICP_QAT_FW_COMN_CNVNR_FLAG_BITPOS 5
123 #define ICP_QAT_FW_COMN_CNVNR_FLAG_MASK 0x1
125 #define ICP_QAT_FW_COMN_OV_SRV_TYPE_GET(icp_qat_fw_comn_req_hdr_t) \
126 icp_qat_fw_comn_req_hdr_t.service_type
128 #define ICP_QAT_FW_COMN_OV_SRV_TYPE_SET(icp_qat_fw_comn_req_hdr_t, val) \
129 icp_qat_fw_comn_req_hdr_t.service_type = val
131 #define ICP_QAT_FW_COMN_OV_SRV_CMD_ID_GET(icp_qat_fw_comn_req_hdr_t) \
132 icp_qat_fw_comn_req_hdr_t.service_cmd_id
134 #define ICP_QAT_FW_COMN_OV_SRV_CMD_ID_SET(icp_qat_fw_comn_req_hdr_t, val) \
135 icp_qat_fw_comn_req_hdr_t.service_cmd_id = val
137 #define ICP_QAT_FW_COMN_HDR_VALID_FLAG_GET(hdr_t) \
138 ICP_QAT_FW_COMN_VALID_FLAG_GET(hdr_t.hdr_flags)
140 #define ICP_QAT_FW_COMN_HDR_CNVNR_FLAG_GET(hdr_flags) \
141 QAT_FIELD_GET(hdr_flags, \
142 ICP_QAT_FW_COMN_CNVNR_FLAG_BITPOS, \
143 ICP_QAT_FW_COMN_CNVNR_FLAG_MASK)
145 #define ICP_QAT_FW_COMN_HDR_CNV_FLAG_GET(hdr_flags) \
146 QAT_FIELD_GET(hdr_flags, \
147 ICP_QAT_FW_COMN_CNV_FLAG_BITPOS, \
148 ICP_QAT_FW_COMN_CNV_FLAG_MASK)
150 #define ICP_QAT_FW_COMN_HDR_VALID_FLAG_SET(hdr_t, val) \
151 ICP_QAT_FW_COMN_VALID_FLAG_SET(hdr_t, val)
153 #define ICP_QAT_FW_COMN_VALID_FLAG_GET(hdr_flags) \
154 QAT_FIELD_GET(hdr_flags, \
155 ICP_QAT_FW_COMN_VALID_FLAG_BITPOS, \
156 ICP_QAT_FW_COMN_VALID_FLAG_MASK)
158 #define ICP_QAT_FW_COMN_HDR_RESRVD_FLD_GET(hdr_flags) \
159 (hdr_flags & ICP_QAT_FW_COMN_HDR_RESRVD_FLD_MASK)
161 #define ICP_QAT_FW_COMN_VALID_FLAG_SET(hdr_t, val) \
162 QAT_FIELD_SET((hdr_t.hdr_flags), (val), \
163 ICP_QAT_FW_COMN_VALID_FLAG_BITPOS, \
164 ICP_QAT_FW_COMN_VALID_FLAG_MASK)
166 #define ICP_QAT_FW_COMN_HDR_FLAGS_BUILD(valid) \
167 (((valid) & ICP_QAT_FW_COMN_VALID_FLAG_MASK) << \
168 ICP_QAT_FW_COMN_VALID_FLAG_BITPOS)
170 #define QAT_COMN_PTR_TYPE_BITPOS 0
171 #define QAT_COMN_PTR_TYPE_MASK 0x1
172 #define QAT_COMN_CD_FLD_TYPE_BITPOS 1
173 #define QAT_COMN_CD_FLD_TYPE_MASK 0x1
174 #define QAT_COMN_PTR_TYPE_FLAT 0x0
175 #define QAT_COMN_PTR_TYPE_SGL 0x1
176 #define QAT_COMN_CD_FLD_TYPE_64BIT_ADR 0x0
177 #define QAT_COMN_CD_FLD_TYPE_16BYTE_DATA 0x1
179 #define ICP_QAT_FW_COMN_FLAGS_BUILD(cdt, ptr) \
180 ((((cdt) & QAT_COMN_CD_FLD_TYPE_MASK) << QAT_COMN_CD_FLD_TYPE_BITPOS) \
181 | (((ptr) & QAT_COMN_PTR_TYPE_MASK) << QAT_COMN_PTR_TYPE_BITPOS))
183 #define ICP_QAT_FW_COMN_PTR_TYPE_GET(flags) \
184 QAT_FIELD_GET(flags, QAT_COMN_PTR_TYPE_BITPOS, QAT_COMN_PTR_TYPE_MASK)
186 #define ICP_QAT_FW_COMN_CD_FLD_TYPE_GET(flags) \
187 QAT_FIELD_GET(flags, QAT_COMN_CD_FLD_TYPE_BITPOS, \
188 QAT_COMN_CD_FLD_TYPE_MASK)
190 #define ICP_QAT_FW_COMN_PTR_TYPE_SET(flags, val) \
191 QAT_FIELD_SET(flags, val, QAT_COMN_PTR_TYPE_BITPOS, \
192 QAT_COMN_PTR_TYPE_MASK)
194 #define ICP_QAT_FW_COMN_CD_FLD_TYPE_SET(flags, val) \
195 QAT_FIELD_SET(flags, val, QAT_COMN_CD_FLD_TYPE_BITPOS, \
196 QAT_COMN_CD_FLD_TYPE_MASK)
198 #define ICP_QAT_FW_COMN_NEXT_ID_BITPOS 4
199 #define ICP_QAT_FW_COMN_NEXT_ID_MASK 0xF0
200 #define ICP_QAT_FW_COMN_CURR_ID_BITPOS 0
201 #define ICP_QAT_FW_COMN_CURR_ID_MASK 0x0F
203 #define ICP_QAT_FW_COMN_NEXT_ID_GET(cd_ctrl_hdr_t) \
204 ((((cd_ctrl_hdr_t)->next_curr_id) & ICP_QAT_FW_COMN_NEXT_ID_MASK) \
205 >> (ICP_QAT_FW_COMN_NEXT_ID_BITPOS))
207 #define ICP_QAT_FW_COMN_NEXT_ID_SET(cd_ctrl_hdr_t, val) \
208 { ((cd_ctrl_hdr_t)->next_curr_id) = ((((cd_ctrl_hdr_t)->next_curr_id) \
209 & ICP_QAT_FW_COMN_CURR_ID_MASK) | \
210 ((val << ICP_QAT_FW_COMN_NEXT_ID_BITPOS) \
211 & ICP_QAT_FW_COMN_NEXT_ID_MASK)); }
213 #define ICP_QAT_FW_COMN_CURR_ID_GET(cd_ctrl_hdr_t) \
214 (((cd_ctrl_hdr_t)->next_curr_id) & ICP_QAT_FW_COMN_CURR_ID_MASK)
216 #define ICP_QAT_FW_COMN_CURR_ID_SET(cd_ctrl_hdr_t, val) \
217 { ((cd_ctrl_hdr_t)->next_curr_id) = ((((cd_ctrl_hdr_t)->next_curr_id) \
218 & ICP_QAT_FW_COMN_NEXT_ID_MASK) | \
219 ((val) & ICP_QAT_FW_COMN_CURR_ID_MASK)); }
221 #define ICP_QAT_FW_COMN_NEXT_ID_SET_2(next_curr_id, val) \
224 (((next_curr_id) & ICP_QAT_FW_COMN_CURR_ID_MASK) | \
225 (((val) << ICP_QAT_FW_COMN_NEXT_ID_BITPOS) & \
226 ICP_QAT_FW_COMN_NEXT_ID_MASK)) \
229 #define ICP_QAT_FW_COMN_CURR_ID_SET_2(next_curr_id, val) \
232 (((next_curr_id) & ICP_QAT_FW_COMN_NEXT_ID_MASK) | \
233 ((val) & ICP_QAT_FW_COMN_CURR_ID_MASK)) \
236 #define QAT_COMN_RESP_CRYPTO_STATUS_BITPOS 7
237 #define QAT_COMN_RESP_CRYPTO_STATUS_MASK 0x1
238 #define QAT_COMN_RESP_PKE_STATUS_BITPOS 6
239 #define QAT_COMN_RESP_PKE_STATUS_MASK 0x1
240 #define QAT_COMN_RESP_CMP_STATUS_BITPOS 5
241 #define QAT_COMN_RESP_CMP_STATUS_MASK 0x1
242 #define QAT_COMN_RESP_XLAT_STATUS_BITPOS 4
243 #define QAT_COMN_RESP_XLAT_STATUS_MASK 0x1
244 #define QAT_COMN_RESP_CMP_END_OF_LAST_BLK_BITPOS 3
245 #define QAT_COMN_RESP_CMP_END_OF_LAST_BLK_MASK 0x1
246 #define QAT_COMN_RESP_UNSUPPORTED_REQUEST_BITPOS 2
247 #define QAT_COMN_RESP_UNSUPPORTED_REQUEST_MASK 0x1
248 #define QAT_COMN_RESP_XLT_WA_APPLIED_BITPOS 0
249 #define QAT_COMN_RESP_XLT_WA_APPLIED_MASK 0x1
251 #define ICP_QAT_FW_COMN_RESP_CRYPTO_STAT_GET(status) \
252 QAT_FIELD_GET(status, QAT_COMN_RESP_CRYPTO_STATUS_BITPOS, \
253 QAT_COMN_RESP_CRYPTO_STATUS_MASK)
255 #define ICP_QAT_FW_COMN_RESP_PKE_STAT_GET(status) \
256 QAT_FIELD_GET(status, QAT_COMN_RESP_PKE_STATUS_BITPOS, \
257 QAT_COMN_RESP_PKE_STATUS_MASK)
259 #define ICP_QAT_FW_COMN_RESP_CMP_STAT_GET(status) \
260 QAT_FIELD_GET(status, QAT_COMN_RESP_CMP_STATUS_BITPOS, \
261 QAT_COMN_RESP_CMP_STATUS_MASK)
263 #define ICP_QAT_FW_COMN_RESP_XLAT_STAT_GET(status) \
264 QAT_FIELD_GET(status, QAT_COMN_RESP_XLAT_STATUS_BITPOS, \
265 QAT_COMN_RESP_XLAT_STATUS_MASK)
267 #define ICP_QAT_FW_COMN_RESP_XLT_WA_APPLIED_GET(status) \
268 QAT_FIELD_GET(status, QAT_COMN_RESP_XLT_WA_APPLIED_BITPOS, \
269 QAT_COMN_RESP_XLT_WA_APPLIED_MASK)
271 #define ICP_QAT_FW_COMN_RESP_CMP_END_OF_LAST_BLK_FLAG_GET(status) \
272 QAT_FIELD_GET(status, QAT_COMN_RESP_CMP_END_OF_LAST_BLK_BITPOS, \
273 QAT_COMN_RESP_CMP_END_OF_LAST_BLK_MASK)
275 #define ICP_QAT_FW_COMN_RESP_UNSUPPORTED_REQUEST_STAT_GET(status) \
276 QAT_FIELD_GET(status, QAT_COMN_RESP_UNSUPPORTED_REQUEST_BITPOS, \
277 QAT_COMN_RESP_UNSUPPORTED_REQUEST_MASK)
279 #define ICP_QAT_FW_COMN_STATUS_FLAG_OK 0
280 #define ICP_QAT_FW_COMN_STATUS_FLAG_ERROR 1
281 #define ICP_QAT_FW_COMN_STATUS_CMP_END_OF_LAST_BLK_FLAG_CLR 0
282 #define ICP_QAT_FW_COMN_STATUS_CMP_END_OF_LAST_BLK_FLAG_SET 1
283 #define ERR_CODE_NO_ERROR 0
284 #define ERR_CODE_INVALID_BLOCK_TYPE -1
285 #define ERR_CODE_NO_MATCH_ONES_COMP -2
286 #define ERR_CODE_TOO_MANY_LEN_OR_DIS -3
287 #define ERR_CODE_INCOMPLETE_LEN -4
288 #define ERR_CODE_RPT_LEN_NO_FIRST_LEN -5
289 #define ERR_CODE_RPT_GT_SPEC_LEN -6
290 #define ERR_CODE_INV_LIT_LEN_CODE_LEN -7
291 #define ERR_CODE_INV_DIS_CODE_LEN -8
292 #define ERR_CODE_INV_LIT_LEN_DIS_IN_BLK -9
293 #define ERR_CODE_DIS_TOO_FAR_BACK -10
294 #define ERR_CODE_OVERFLOW_ERROR -11
295 #define ERR_CODE_SOFT_ERROR -12
296 #define ERR_CODE_FATAL_ERROR -13
297 #define ERR_CODE_COMP_OUTPUT_CORRUPTION -14
298 #define ERR_CODE_HW_INCOMPLETE_FILE -15
299 #define ERR_CODE_SSM_ERROR -16
300 #define ERR_CODE_ENDPOINT_ERROR -17
301 #define ERR_CODE_CNV_ERROR -18
302 #define ERR_CODE_EMPTY_DYM_BLOCK -19
303 #define ERR_CODE_KPT_CRYPTO_SERVICE_FAIL_INVALID_HANDLE -20
304 #define ERR_CODE_KPT_CRYPTO_SERVICE_FAIL_HMAC_FAILED -21
305 #define ERR_CODE_KPT_CRYPTO_SERVICE_FAIL_INVALID_WRAPPING_ALGO -22
306 #define ERR_CODE_KPT_DRNG_SEED_NOT_LOAD -23
308 enum icp_qat_fw_slice {
309 ICP_QAT_FW_SLICE_NULL = 0,
310 ICP_QAT_FW_SLICE_CIPHER = 1,
311 ICP_QAT_FW_SLICE_AUTH = 2,
312 ICP_QAT_FW_SLICE_DRAM_RD = 3,
313 ICP_QAT_FW_SLICE_DRAM_WR = 4,
314 ICP_QAT_FW_SLICE_COMP = 5,
315 ICP_QAT_FW_SLICE_XLAT = 6,
316 ICP_QAT_FW_SLICE_DELIMITER