crypto: qat - add AES-CTR support for QAT GEN4 devices

Add support for AES-CTR for QAT GEN4 devices.
Also, introduce the capability ICP_ACCEL_CAPABILITIES_AES_V2 and the
helper macro HW_CAP_AES_V2, which allow to distinguish between
different HW generations.

Co-developed-by: Tomasz Kowalik <tomaszx.kowalik@intel.com>
Signed-off-by: Tomasz Kowalik <tomaszx.kowalik@intel.com>
Co-developed-by: Mateusz Polrola <mateuszx.potrola@intel.com>
Signed-off-by: Mateusz Polrola <mateuszx.potrola@intel.com>
Signed-off-by: Marco Chiappero <marco.chiappero@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by Marco Chiappero and committed by Herbert Xu 67916c95 d33a23b0

+39 -2
+7
drivers/crypto/qat/qat_common/icp_qat_fw_la.h
··· 33 33 struct icp_qat_fw_comn_req_cd_ctrl cd_ctrl; 34 34 }; 35 35 36 + #define ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE 1 37 + #define QAT_LA_SLICE_TYPE_BITPOS 14 38 + #define QAT_LA_SLICE_TYPE_MASK 0x3 36 39 #define ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS 1 37 40 #define ICP_QAT_FW_LA_GCM_IV_LEN_NOT_12_OCTETS 0 38 41 #define QAT_FW_LA_ZUC_3G_PROTO_FLAG_BITPOS 12 ··· 181 178 #define ICP_QAT_FW_LA_PARTIAL_SET(flags, val) \ 182 179 QAT_FIELD_SET(flags, val, QAT_LA_PARTIAL_BITPOS, \ 183 180 QAT_LA_PARTIAL_MASK) 181 + 182 + #define ICP_QAT_FW_LA_SLICE_TYPE_SET(flags, val) \ 183 + QAT_FIELD_SET(flags, val, QAT_LA_SLICE_TYPE_BITPOS, \ 184 + QAT_LA_SLICE_TYPE_MASK) 184 185 185 186 struct icp_qat_fw_cipher_req_hdr_cd_pars { 186 187 union {
+16 -1
drivers/crypto/qat/qat_common/icp_qat_hw.h
··· 65 65 __u32 reserved; 66 66 }; 67 67 68 + struct icp_qat_hw_ucs_cipher_config { 69 + __u32 val; 70 + __u32 reserved[3]; 71 + }; 72 + 68 73 enum icp_qat_slice_mask { 69 74 ICP_ACCEL_MASK_CIPHER_SLICE = BIT(0), 70 75 ICP_ACCEL_MASK_AUTH_SLICE = BIT(1), ··· 91 86 ICP_ACCEL_CAPABILITIES_RAND = BIT(7), 92 87 ICP_ACCEL_CAPABILITIES_ZUC = BIT(8), 93 88 ICP_ACCEL_CAPABILITIES_SHA3 = BIT(9), 89 + /* Bits 10-25 are currently reserved */ 90 + ICP_ACCEL_CAPABILITIES_AES_V2 = BIT(26) 94 91 }; 95 92 96 93 #define QAT_AUTH_MODE_BITPOS 4 ··· 285 278 __u8 key[ICP_QAT_HW_AES_256_F8_KEY_SZ]; 286 279 }; 287 280 281 + struct icp_qat_hw_ucs_cipher_aes256_f8 { 282 + struct icp_qat_hw_ucs_cipher_config cipher_config; 283 + __u8 key[ICP_QAT_HW_AES_256_F8_KEY_SZ]; 284 + }; 285 + 288 286 struct icp_qat_hw_cipher_algo_blk { 289 - struct icp_qat_hw_cipher_aes256_f8 aes; 287 + union { 288 + struct icp_qat_hw_cipher_aes256_f8 aes; 289 + struct icp_qat_hw_ucs_cipher_aes256_f8 ucs_aes; 290 + }; 290 291 } __aligned(64); 291 292 #endif
+16 -1
drivers/crypto/qat/qat_common/qat_algs.c
··· 33 33 ICP_QAT_HW_CIPHER_KEY_CONVERT, \ 34 34 ICP_QAT_HW_CIPHER_DECRYPT) 35 35 36 + #define HW_CAP_AES_V2(accel_dev) \ 37 + (GET_HW_DATA(accel_dev)->accel_capabilities_mask & \ 38 + ICP_ACCEL_CAPABILITIES_AES_V2) 39 + 36 40 static DEFINE_MUTEX(algs_lock); 37 41 static unsigned int active_devs; 38 42 ··· 420 416 struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req->cd_pars; 421 417 struct icp_qat_fw_comn_req_hdr *header = &req->comn_hdr; 422 418 struct icp_qat_fw_cipher_cd_ctrl_hdr *cd_ctrl = (void *)&req->cd_ctrl; 419 + bool aes_v2_capable = HW_CAP_AES_V2(ctx->inst->accel_dev); 420 + int mode = ctx->mode; 423 421 424 - memcpy(cd->aes.key, key, keylen); 425 422 qat_alg_init_common_hdr(header); 426 423 header->service_cmd_id = ICP_QAT_FW_LA_CMD_CIPHER; 427 424 cd_pars->u.s.content_desc_params_sz = 428 425 sizeof(struct icp_qat_hw_cipher_algo_blk) >> 3; 426 + 427 + if (aes_v2_capable && mode == ICP_QAT_HW_CIPHER_CTR_MODE) { 428 + ICP_QAT_FW_LA_SLICE_TYPE_SET(header->serv_specif_flags, 429 + ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE); 430 + keylen = round_up(keylen, 16); 431 + memcpy(cd->ucs_aes.key, key, keylen); 432 + } else { 433 + memcpy(cd->aes.key, key, keylen); 434 + } 435 + 429 436 /* Cipher CD config setup */ 430 437 cd_ctrl->cipher_key_sz = keylen >> 3; 431 438 cd_ctrl->cipher_state_sz = AES_BLOCK_SIZE >> 3;