Skip to content

Commit 67916c9

Browse files
intmcherbertx
authored andcommitted
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 <[email protected]> Signed-off-by: Tomasz Kowalik <[email protected]> Co-developed-by: Mateusz Polrola <[email protected]> Signed-off-by: Mateusz Polrola <[email protected]> Signed-off-by: Marco Chiappero <[email protected]> Reviewed-by: Giovanni Cabiddu <[email protected]> Signed-off-by: Giovanni Cabiddu <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent d33a23b commit 67916c9

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

drivers/crypto/qat/qat_common/icp_qat_fw_la.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ struct icp_qat_fw_la_bulk_req {
3333
struct icp_qat_fw_comn_req_cd_ctrl cd_ctrl;
3434
};
3535

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
3639
#define ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS 1
3740
#define ICP_QAT_FW_LA_GCM_IV_LEN_NOT_12_OCTETS 0
3841
#define QAT_FW_LA_ZUC_3G_PROTO_FLAG_BITPOS 12
@@ -179,6 +182,10 @@ struct icp_qat_fw_la_bulk_req {
179182
QAT_FIELD_SET(flags, val, QAT_LA_PARTIAL_BITPOS, \
180183
QAT_LA_PARTIAL_MASK)
181184

185+
#define ICP_QAT_FW_LA_SLICE_TYPE_SET(flags, val) \
186+
QAT_FIELD_SET(flags, val, QAT_LA_SLICE_TYPE_BITPOS, \
187+
QAT_LA_SLICE_TYPE_MASK)
188+
182189
struct icp_qat_fw_cipher_req_hdr_cd_pars {
183190
union {
184191
struct {

drivers/crypto/qat/qat_common/icp_qat_hw.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ struct icp_qat_hw_auth_config {
6565
__u32 reserved;
6666
};
6767

68+
struct icp_qat_hw_ucs_cipher_config {
69+
__u32 val;
70+
__u32 reserved[3];
71+
};
72+
6873
enum icp_qat_slice_mask {
6974
ICP_ACCEL_MASK_CIPHER_SLICE = BIT(0),
7075
ICP_ACCEL_MASK_AUTH_SLICE = BIT(1),
@@ -86,6 +91,8 @@ enum icp_qat_capabilities_mask {
8691
ICP_ACCEL_CAPABILITIES_RAND = BIT(7),
8792
ICP_ACCEL_CAPABILITIES_ZUC = BIT(8),
8893
ICP_ACCEL_CAPABILITIES_SHA3 = BIT(9),
94+
/* Bits 10-25 are currently reserved */
95+
ICP_ACCEL_CAPABILITIES_AES_V2 = BIT(26)
8996
};
9097

9198
#define QAT_AUTH_MODE_BITPOS 4
@@ -278,7 +285,15 @@ struct icp_qat_hw_cipher_aes256_f8 {
278285
__u8 key[ICP_QAT_HW_AES_256_F8_KEY_SZ];
279286
};
280287

288+
struct icp_qat_hw_ucs_cipher_aes256_f8 {
289+
struct icp_qat_hw_ucs_cipher_config cipher_config;
290+
__u8 key[ICP_QAT_HW_AES_256_F8_KEY_SZ];
291+
};
292+
281293
struct icp_qat_hw_cipher_algo_blk {
282-
struct icp_qat_hw_cipher_aes256_f8 aes;
294+
union {
295+
struct icp_qat_hw_cipher_aes256_f8 aes;
296+
struct icp_qat_hw_ucs_cipher_aes256_f8 ucs_aes;
297+
};
283298
} __aligned(64);
284299
#endif

drivers/crypto/qat/qat_common/qat_algs.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
ICP_QAT_HW_CIPHER_KEY_CONVERT, \
3434
ICP_QAT_HW_CIPHER_DECRYPT)
3535

36+
#define HW_CAP_AES_V2(accel_dev) \
37+
(GET_HW_DATA(accel_dev)->accel_capabilities_mask & \
38+
ICP_ACCEL_CAPABILITIES_AES_V2)
39+
3640
static DEFINE_MUTEX(algs_lock);
3741
static unsigned int active_devs;
3842

@@ -416,12 +420,23 @@ static void qat_alg_skcipher_init_com(struct qat_alg_skcipher_ctx *ctx,
416420
struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req->cd_pars;
417421
struct icp_qat_fw_comn_req_hdr *header = &req->comn_hdr;
418422
struct icp_qat_fw_cipher_cd_ctrl_hdr *cd_ctrl = (void *)&req->cd_ctrl;
423+
bool aes_v2_capable = HW_CAP_AES_V2(ctx->inst->accel_dev);
424+
int mode = ctx->mode;
419425

420-
memcpy(cd->aes.key, key, keylen);
421426
qat_alg_init_common_hdr(header);
422427
header->service_cmd_id = ICP_QAT_FW_LA_CMD_CIPHER;
423428
cd_pars->u.s.content_desc_params_sz =
424429
sizeof(struct icp_qat_hw_cipher_algo_blk) >> 3;
430+
431+
if (aes_v2_capable && mode == ICP_QAT_HW_CIPHER_CTR_MODE) {
432+
ICP_QAT_FW_LA_SLICE_TYPE_SET(header->serv_specif_flags,
433+
ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE);
434+
keylen = round_up(keylen, 16);
435+
memcpy(cd->ucs_aes.key, key, keylen);
436+
} else {
437+
memcpy(cd->aes.key, key, keylen);
438+
}
439+
425440
/* Cipher CD config setup */
426441
cd_ctrl->cipher_key_sz = keylen >> 3;
427442
cd_ctrl->cipher_state_sz = AES_BLOCK_SIZE >> 3;

0 commit comments

Comments
 (0)