diff options
author | Tadeusz Struk <tadeusz.struk@intel.com> | 2014-12-08 15:08:49 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2014-12-22 07:02:42 -0500 |
commit | 338e84f3a9740ab3582c8b6bc5a1a027794dac72 (patch) | |
tree | 9fa044b1905ba87668ae2d22886f1260d7ab324f /drivers/crypto | |
parent | 82f82504b8f5f1013678bbc74e0882891114594a (diff) |
crypto: qat - add support for cbc(aes) ablkcipher
Add support for cbc(aes) ablkcipher.
Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
Acked-by: Bruce W. Allan <bruce.w.allan@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r-- | drivers/crypto/qat/qat_common/icp_qat_hw.h | 2 | ||||
-rw-r--r-- | drivers/crypto/qat/qat_common/qat_algs.c | 528 | ||||
-rw-r--r-- | drivers/crypto/qat/qat_common/qat_crypto.h | 15 |
3 files changed, 433 insertions, 112 deletions
diff --git a/drivers/crypto/qat/qat_common/icp_qat_hw.h b/drivers/crypto/qat/qat_common/icp_qat_hw.h index 5031f8c10d75..68f191b653b0 100644 --- a/drivers/crypto/qat/qat_common/icp_qat_hw.h +++ b/drivers/crypto/qat/qat_common/icp_qat_hw.h | |||
@@ -301,5 +301,5 @@ struct icp_qat_hw_cipher_aes256_f8 { | |||
301 | 301 | ||
302 | struct icp_qat_hw_cipher_algo_blk { | 302 | struct icp_qat_hw_cipher_algo_blk { |
303 | struct icp_qat_hw_cipher_aes256_f8 aes; | 303 | struct icp_qat_hw_cipher_aes256_f8 aes; |
304 | }; | 304 | } __aligned(64); |
305 | #endif | 305 | #endif |
diff --git a/drivers/crypto/qat/qat_common/qat_algs.c b/drivers/crypto/qat/qat_common/qat_algs.c index e4e32d872902..f32d0a58bcc0 100644 --- a/drivers/crypto/qat/qat_common/qat_algs.c +++ b/drivers/crypto/qat/qat_common/qat_algs.c | |||
@@ -63,15 +63,15 @@ | |||
63 | #include "icp_qat_fw.h" | 63 | #include "icp_qat_fw.h" |
64 | #include "icp_qat_fw_la.h" | 64 | #include "icp_qat_fw_la.h" |
65 | 65 | ||
66 | #define QAT_AES_HW_CONFIG_ENC(alg) \ | 66 | #define QAT_AES_HW_CONFIG_CBC_ENC(alg) \ |
67 | ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_CBC_MODE, alg, \ | 67 | ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_CBC_MODE, alg, \ |
68 | ICP_QAT_HW_CIPHER_NO_CONVERT, \ | 68 | ICP_QAT_HW_CIPHER_NO_CONVERT, \ |
69 | ICP_QAT_HW_CIPHER_ENCRYPT) | 69 | ICP_QAT_HW_CIPHER_ENCRYPT) |
70 | 70 | ||
71 | #define QAT_AES_HW_CONFIG_DEC(alg) \ | 71 | #define QAT_AES_HW_CONFIG_CBC_DEC(alg) \ |
72 | ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_CBC_MODE, alg, \ | 72 | ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_CBC_MODE, alg, \ |
73 | ICP_QAT_HW_CIPHER_KEY_CONVERT, \ | 73 | ICP_QAT_HW_CIPHER_KEY_CONVERT, \ |
74 | ICP_QAT_HW_CIPHER_DECRYPT) | 74 | ICP_QAT_HW_CIPHER_DECRYPT) |
75 | 75 | ||
76 | static atomic_t active_dev; | 76 | static atomic_t active_dev; |
77 | 77 | ||
@@ -108,19 +108,31 @@ struct qat_auth_state { | |||
108 | uint8_t data[MAX_AUTH_STATE_SIZE + 64]; | 108 | uint8_t data[MAX_AUTH_STATE_SIZE + 64]; |
109 | } __aligned(64); | 109 | } __aligned(64); |
110 | 110 | ||
111 | struct qat_alg_session_ctx { | 111 | struct qat_alg_aead_ctx { |
112 | struct qat_alg_cd *enc_cd; | 112 | struct qat_alg_cd *enc_cd; |
113 | dma_addr_t enc_cd_paddr; | ||
114 | struct qat_alg_cd *dec_cd; | 113 | struct qat_alg_cd *dec_cd; |
114 | dma_addr_t enc_cd_paddr; | ||
115 | dma_addr_t dec_cd_paddr; | 115 | dma_addr_t dec_cd_paddr; |
116 | struct icp_qat_fw_la_bulk_req enc_fw_req_tmpl; | 116 | struct icp_qat_fw_la_bulk_req enc_fw_req; |
117 | struct icp_qat_fw_la_bulk_req dec_fw_req_tmpl; | 117 | struct icp_qat_fw_la_bulk_req dec_fw_req; |
118 | struct qat_crypto_instance *inst; | ||
119 | struct crypto_tfm *tfm; | ||
120 | struct crypto_shash *hash_tfm; | 118 | struct crypto_shash *hash_tfm; |
121 | enum icp_qat_hw_auth_algo qat_hash_alg; | 119 | enum icp_qat_hw_auth_algo qat_hash_alg; |
120 | struct qat_crypto_instance *inst; | ||
121 | struct crypto_tfm *tfm; | ||
122 | uint8_t salt[AES_BLOCK_SIZE]; | 122 | uint8_t salt[AES_BLOCK_SIZE]; |
123 | spinlock_t lock; /* protects qat_alg_session_ctx struct */ | 123 | spinlock_t lock; /* protects qat_alg_aead_ctx struct */ |
124 | }; | ||
125 | |||
126 | struct qat_alg_ablkcipher_ctx { | ||
127 | struct icp_qat_hw_cipher_algo_blk *enc_cd; | ||
128 | struct icp_qat_hw_cipher_algo_blk *dec_cd; | ||
129 | dma_addr_t enc_cd_paddr; | ||
130 | dma_addr_t dec_cd_paddr; | ||
131 | struct icp_qat_fw_la_bulk_req enc_fw_req; | ||
132 | struct icp_qat_fw_la_bulk_req dec_fw_req; | ||
133 | struct qat_crypto_instance *inst; | ||
134 | struct crypto_tfm *tfm; | ||
135 | spinlock_t lock; /* protects qat_alg_ablkcipher_ctx struct */ | ||
124 | }; | 136 | }; |
125 | 137 | ||
126 | static int get_current_node(void) | 138 | static int get_current_node(void) |
@@ -144,7 +156,7 @@ static int qat_get_inter_state_size(enum icp_qat_hw_auth_algo qat_hash_alg) | |||
144 | } | 156 | } |
145 | 157 | ||
146 | static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash, | 158 | static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash, |
147 | struct qat_alg_session_ctx *ctx, | 159 | struct qat_alg_aead_ctx *ctx, |
148 | const uint8_t *auth_key, | 160 | const uint8_t *auth_key, |
149 | unsigned int auth_keylen) | 161 | unsigned int auth_keylen) |
150 | { | 162 | { |
@@ -267,8 +279,6 @@ static void qat_alg_init_common_hdr(struct icp_qat_fw_comn_req_hdr *header) | |||
267 | header->comn_req_flags = | 279 | header->comn_req_flags = |
268 | ICP_QAT_FW_COMN_FLAGS_BUILD(QAT_COMN_CD_FLD_TYPE_64BIT_ADR, | 280 | ICP_QAT_FW_COMN_FLAGS_BUILD(QAT_COMN_CD_FLD_TYPE_64BIT_ADR, |
269 | QAT_COMN_PTR_TYPE_SGL); | 281 | QAT_COMN_PTR_TYPE_SGL); |
270 | ICP_QAT_FW_LA_DIGEST_IN_BUFFER_SET(header->serv_specif_flags, | ||
271 | ICP_QAT_FW_LA_DIGEST_IN_BUFFER); | ||
272 | ICP_QAT_FW_LA_PARTIAL_SET(header->serv_specif_flags, | 282 | ICP_QAT_FW_LA_PARTIAL_SET(header->serv_specif_flags, |
273 | ICP_QAT_FW_LA_PARTIAL_NONE); | 283 | ICP_QAT_FW_LA_PARTIAL_NONE); |
274 | ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET(header->serv_specif_flags, | 284 | ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET(header->serv_specif_flags, |
@@ -279,8 +289,9 @@ static void qat_alg_init_common_hdr(struct icp_qat_fw_comn_req_hdr *header) | |||
279 | ICP_QAT_FW_LA_NO_UPDATE_STATE); | 289 | ICP_QAT_FW_LA_NO_UPDATE_STATE); |
280 | } | 290 | } |
281 | 291 | ||
282 | static int qat_alg_init_enc_session(struct qat_alg_session_ctx *ctx, | 292 | static int qat_alg_aead_init_enc_session(struct qat_alg_aead_ctx *ctx, |
283 | int alg, struct crypto_authenc_keys *keys) | 293 | int alg, |
294 | struct crypto_authenc_keys *keys) | ||
284 | { | 295 | { |
285 | struct crypto_aead *aead_tfm = __crypto_aead_cast(ctx->tfm); | 296 | struct crypto_aead *aead_tfm = __crypto_aead_cast(ctx->tfm); |
286 | unsigned int digestsize = crypto_aead_crt(aead_tfm)->authsize; | 297 | unsigned int digestsize = crypto_aead_crt(aead_tfm)->authsize; |
@@ -289,7 +300,7 @@ static int qat_alg_init_enc_session(struct qat_alg_session_ctx *ctx, | |||
289 | struct icp_qat_hw_auth_algo_blk *hash = | 300 | struct icp_qat_hw_auth_algo_blk *hash = |
290 | (struct icp_qat_hw_auth_algo_blk *)((char *)enc_ctx + | 301 | (struct icp_qat_hw_auth_algo_blk *)((char *)enc_ctx + |
291 | sizeof(struct icp_qat_hw_auth_setup) + keys->enckeylen); | 302 | sizeof(struct icp_qat_hw_auth_setup) + keys->enckeylen); |
292 | struct icp_qat_fw_la_bulk_req *req_tmpl = &ctx->enc_fw_req_tmpl; | 303 | struct icp_qat_fw_la_bulk_req *req_tmpl = &ctx->enc_fw_req; |
293 | struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req_tmpl->cd_pars; | 304 | struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req_tmpl->cd_pars; |
294 | struct icp_qat_fw_comn_req_hdr *header = &req_tmpl->comn_hdr; | 305 | struct icp_qat_fw_comn_req_hdr *header = &req_tmpl->comn_hdr; |
295 | void *ptr = &req_tmpl->cd_ctrl; | 306 | void *ptr = &req_tmpl->cd_ctrl; |
@@ -297,7 +308,7 @@ static int qat_alg_init_enc_session(struct qat_alg_session_ctx *ctx, | |||
297 | struct icp_qat_fw_auth_cd_ctrl_hdr *hash_cd_ctrl = ptr; | 308 | struct icp_qat_fw_auth_cd_ctrl_hdr *hash_cd_ctrl = ptr; |
298 | 309 | ||
299 | /* CD setup */ | 310 | /* CD setup */ |
300 | cipher->aes.cipher_config.val = QAT_AES_HW_CONFIG_ENC(alg); | 311 | cipher->aes.cipher_config.val = QAT_AES_HW_CONFIG_CBC_ENC(alg); |
301 | memcpy(cipher->aes.key, keys->enckey, keys->enckeylen); | 312 | memcpy(cipher->aes.key, keys->enckey, keys->enckeylen); |
302 | hash->sha.inner_setup.auth_config.config = | 313 | hash->sha.inner_setup.auth_config.config = |
303 | ICP_QAT_HW_AUTH_CONFIG_BUILD(ICP_QAT_HW_AUTH_MODE1, | 314 | ICP_QAT_HW_AUTH_CONFIG_BUILD(ICP_QAT_HW_AUTH_MODE1, |
@@ -311,6 +322,8 @@ static int qat_alg_init_enc_session(struct qat_alg_session_ctx *ctx, | |||
311 | /* Request setup */ | 322 | /* Request setup */ |
312 | qat_alg_init_common_hdr(header); | 323 | qat_alg_init_common_hdr(header); |
313 | header->service_cmd_id = ICP_QAT_FW_LA_CMD_CIPHER_HASH; | 324 | header->service_cmd_id = ICP_QAT_FW_LA_CMD_CIPHER_HASH; |
325 | ICP_QAT_FW_LA_DIGEST_IN_BUFFER_SET(header->serv_specif_flags, | ||
326 | ICP_QAT_FW_LA_DIGEST_IN_BUFFER); | ||
314 | ICP_QAT_FW_LA_RET_AUTH_SET(header->serv_specif_flags, | 327 | ICP_QAT_FW_LA_RET_AUTH_SET(header->serv_specif_flags, |
315 | ICP_QAT_FW_LA_RET_AUTH_RES); | 328 | ICP_QAT_FW_LA_RET_AUTH_RES); |
316 | ICP_QAT_FW_LA_CMP_AUTH_SET(header->serv_specif_flags, | 329 | ICP_QAT_FW_LA_CMP_AUTH_SET(header->serv_specif_flags, |
@@ -356,8 +369,9 @@ static int qat_alg_init_enc_session(struct qat_alg_session_ctx *ctx, | |||
356 | return 0; | 369 | return 0; |
357 | } | 370 | } |
358 | 371 | ||
359 | static int qat_alg_init_dec_session(struct qat_alg_session_ctx *ctx, | 372 | static int qat_alg_aead_init_dec_session(struct qat_alg_aead_ctx *ctx, |
360 | int alg, struct crypto_authenc_keys *keys) | 373 | int alg, |
374 | struct crypto_authenc_keys *keys) | ||
361 | { | 375 | { |
362 | struct crypto_aead *aead_tfm = __crypto_aead_cast(ctx->tfm); | 376 | struct crypto_aead *aead_tfm = __crypto_aead_cast(ctx->tfm); |
363 | unsigned int digestsize = crypto_aead_crt(aead_tfm)->authsize; | 377 | unsigned int digestsize = crypto_aead_crt(aead_tfm)->authsize; |
@@ -367,7 +381,7 @@ static int qat_alg_init_dec_session(struct qat_alg_session_ctx *ctx, | |||
367 | (struct icp_qat_hw_cipher_algo_blk *)((char *)dec_ctx + | 381 | (struct icp_qat_hw_cipher_algo_blk *)((char *)dec_ctx + |
368 | sizeof(struct icp_qat_hw_auth_setup) + | 382 | sizeof(struct icp_qat_hw_auth_setup) + |
369 | roundup(crypto_shash_digestsize(ctx->hash_tfm), 8) * 2); | 383 | roundup(crypto_shash_digestsize(ctx->hash_tfm), 8) * 2); |
370 | struct icp_qat_fw_la_bulk_req *req_tmpl = &ctx->dec_fw_req_tmpl; | 384 | struct icp_qat_fw_la_bulk_req *req_tmpl = &ctx->dec_fw_req; |
371 | struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req_tmpl->cd_pars; | 385 | struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req_tmpl->cd_pars; |
372 | struct icp_qat_fw_comn_req_hdr *header = &req_tmpl->comn_hdr; | 386 | struct icp_qat_fw_comn_req_hdr *header = &req_tmpl->comn_hdr; |
373 | void *ptr = &req_tmpl->cd_ctrl; | 387 | void *ptr = &req_tmpl->cd_ctrl; |
@@ -379,7 +393,7 @@ static int qat_alg_init_dec_session(struct qat_alg_session_ctx *ctx, | |||
379 | sizeof(struct icp_qat_fw_la_cipher_req_params)); | 393 | sizeof(struct icp_qat_fw_la_cipher_req_params)); |
380 | 394 | ||
381 | /* CD setup */ | 395 | /* CD setup */ |
382 | cipher->aes.cipher_config.val = QAT_AES_HW_CONFIG_DEC(alg); | 396 | cipher->aes.cipher_config.val = QAT_AES_HW_CONFIG_CBC_DEC(alg); |
383 | memcpy(cipher->aes.key, keys->enckey, keys->enckeylen); | 397 | memcpy(cipher->aes.key, keys->enckey, keys->enckeylen); |
384 | hash->sha.inner_setup.auth_config.config = | 398 | hash->sha.inner_setup.auth_config.config = |
385 | ICP_QAT_HW_AUTH_CONFIG_BUILD(ICP_QAT_HW_AUTH_MODE1, | 399 | ICP_QAT_HW_AUTH_CONFIG_BUILD(ICP_QAT_HW_AUTH_MODE1, |
@@ -394,6 +408,8 @@ static int qat_alg_init_dec_session(struct qat_alg_session_ctx *ctx, | |||
394 | /* Request setup */ | 408 | /* Request setup */ |
395 | qat_alg_init_common_hdr(header); | 409 | qat_alg_init_common_hdr(header); |
396 | header->service_cmd_id = ICP_QAT_FW_LA_CMD_HASH_CIPHER; | 410 | header->service_cmd_id = ICP_QAT_FW_LA_CMD_HASH_CIPHER; |
411 | ICP_QAT_FW_LA_DIGEST_IN_BUFFER_SET(header->serv_specif_flags, | ||
412 | ICP_QAT_FW_LA_DIGEST_IN_BUFFER); | ||
397 | ICP_QAT_FW_LA_RET_AUTH_SET(header->serv_specif_flags, | 413 | ICP_QAT_FW_LA_RET_AUTH_SET(header->serv_specif_flags, |
398 | ICP_QAT_FW_LA_NO_RET_AUTH_RES); | 414 | ICP_QAT_FW_LA_NO_RET_AUTH_RES); |
399 | ICP_QAT_FW_LA_CMP_AUTH_SET(header->serv_specif_flags, | 415 | ICP_QAT_FW_LA_CMP_AUTH_SET(header->serv_specif_flags, |
@@ -444,36 +460,91 @@ static int qat_alg_init_dec_session(struct qat_alg_session_ctx *ctx, | |||
444 | return 0; | 460 | return 0; |
445 | } | 461 | } |
446 | 462 | ||
447 | static int qat_alg_init_sessions(struct qat_alg_session_ctx *ctx, | 463 | static void qat_alg_ablkcipher_init_com(struct qat_alg_ablkcipher_ctx *ctx, |
448 | const uint8_t *key, unsigned int keylen) | 464 | struct icp_qat_fw_la_bulk_req *req, |
465 | struct icp_qat_hw_cipher_algo_blk *cd, | ||
466 | const uint8_t *key, unsigned int keylen) | ||
449 | { | 467 | { |
450 | struct crypto_authenc_keys keys; | 468 | struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req->cd_pars; |
451 | int alg; | 469 | struct icp_qat_fw_comn_req_hdr *header = &req->comn_hdr; |
470 | struct icp_qat_fw_cipher_cd_ctrl_hdr *cd_ctrl = (void *)&req->cd_ctrl; | ||
452 | 471 | ||
453 | if (crypto_rng_get_bytes(crypto_default_rng, ctx->salt, AES_BLOCK_SIZE)) | 472 | memcpy(cd->aes.key, key, keylen); |
454 | return -EFAULT; | 473 | qat_alg_init_common_hdr(header); |
474 | header->service_cmd_id = ICP_QAT_FW_LA_CMD_CIPHER; | ||
475 | cd_pars->u.s.content_desc_params_sz = | ||
476 | sizeof(struct icp_qat_hw_cipher_algo_blk) >> 3; | ||
477 | /* Cipher CD config setup */ | ||
478 | cd_ctrl->cipher_key_sz = keylen >> 3; | ||
479 | cd_ctrl->cipher_state_sz = AES_BLOCK_SIZE >> 3; | ||
480 | cd_ctrl->cipher_cfg_offset = 0; | ||
481 | ICP_QAT_FW_COMN_CURR_ID_SET(cd_ctrl, ICP_QAT_FW_SLICE_CIPHER); | ||
482 | ICP_QAT_FW_COMN_NEXT_ID_SET(cd_ctrl, ICP_QAT_FW_SLICE_DRAM_WR); | ||
483 | } | ||
455 | 484 | ||
456 | if (crypto_authenc_extractkeys(&keys, key, keylen)) | 485 | static void qat_alg_ablkcipher_init_enc(struct qat_alg_ablkcipher_ctx *ctx, |
457 | goto bad_key; | 486 | int alg, const uint8_t *key, |
487 | unsigned int keylen) | ||
488 | { | ||
489 | struct icp_qat_hw_cipher_algo_blk *enc_cd = ctx->enc_cd; | ||
490 | struct icp_qat_fw_la_bulk_req *req = &ctx->enc_fw_req; | ||
491 | struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req->cd_pars; | ||
458 | 492 | ||
459 | switch (keys.enckeylen) { | 493 | qat_alg_ablkcipher_init_com(ctx, req, enc_cd, key, keylen); |
494 | cd_pars->u.s.content_desc_addr = ctx->enc_cd_paddr; | ||
495 | enc_cd->aes.cipher_config.val = QAT_AES_HW_CONFIG_CBC_ENC(alg); | ||
496 | } | ||
497 | |||
498 | static void qat_alg_ablkcipher_init_dec(struct qat_alg_ablkcipher_ctx *ctx, | ||
499 | int alg, const uint8_t *key, | ||
500 | unsigned int keylen) | ||
501 | { | ||
502 | struct icp_qat_hw_cipher_algo_blk *dec_cd = ctx->dec_cd; | ||
503 | struct icp_qat_fw_la_bulk_req *req = &ctx->dec_fw_req; | ||
504 | struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req->cd_pars; | ||
505 | |||
506 | qat_alg_ablkcipher_init_com(ctx, req, dec_cd, key, keylen); | ||
507 | cd_pars->u.s.content_desc_addr = ctx->dec_cd_paddr; | ||
508 | dec_cd->aes.cipher_config.val = QAT_AES_HW_CONFIG_CBC_DEC(alg); | ||
509 | } | ||
510 | |||
511 | static int qat_alg_validate_key(int key_len, int *alg) | ||
512 | { | ||
513 | switch (key_len) { | ||
460 | case AES_KEYSIZE_128: | 514 | case AES_KEYSIZE_128: |
461 | alg = ICP_QAT_HW_CIPHER_ALGO_AES128; | 515 | *alg = ICP_QAT_HW_CIPHER_ALGO_AES128; |
462 | break; | 516 | break; |
463 | case AES_KEYSIZE_192: | 517 | case AES_KEYSIZE_192: |
464 | alg = ICP_QAT_HW_CIPHER_ALGO_AES192; | 518 | *alg = ICP_QAT_HW_CIPHER_ALGO_AES192; |
465 | break; | 519 | break; |
466 | case AES_KEYSIZE_256: | 520 | case AES_KEYSIZE_256: |
467 | alg = ICP_QAT_HW_CIPHER_ALGO_AES256; | 521 | *alg = ICP_QAT_HW_CIPHER_ALGO_AES256; |
468 | break; | 522 | break; |
469 | default: | 523 | default: |
470 | goto bad_key; | 524 | return -EINVAL; |
471 | } | 525 | } |
526 | return 0; | ||
527 | } | ||
472 | 528 | ||
473 | if (qat_alg_init_enc_session(ctx, alg, &keys)) | 529 | static int qat_alg_aead_init_sessions(struct qat_alg_aead_ctx *ctx, |
530 | const uint8_t *key, unsigned int keylen) | ||
531 | { | ||
532 | struct crypto_authenc_keys keys; | ||
533 | int alg; | ||
534 | |||
535 | if (crypto_rng_get_bytes(crypto_default_rng, ctx->salt, AES_BLOCK_SIZE)) | ||
536 | return -EFAULT; | ||
537 | |||
538 | if (crypto_authenc_extractkeys(&keys, key, keylen)) | ||
539 | goto bad_key; | ||
540 | |||
541 | if (qat_alg_validate_key(keys.enckeylen, &alg)) | ||
542 | goto bad_key; | ||
543 | |||
544 | if (qat_alg_aead_init_enc_session(ctx, alg, &keys)) | ||
474 | goto error; | 545 | goto error; |
475 | 546 | ||
476 | if (qat_alg_init_dec_session(ctx, alg, &keys)) | 547 | if (qat_alg_aead_init_dec_session(ctx, alg, &keys)) |
477 | goto error; | 548 | goto error; |
478 | 549 | ||
479 | return 0; | 550 | return 0; |
@@ -484,22 +555,37 @@ error: | |||
484 | return -EFAULT; | 555 | return -EFAULT; |
485 | } | 556 | } |
486 | 557 | ||
487 | static int qat_alg_setkey(struct crypto_aead *tfm, const uint8_t *key, | 558 | static int qat_alg_ablkcipher_init_sessions(struct qat_alg_ablkcipher_ctx *ctx, |
488 | unsigned int keylen) | 559 | const uint8_t *key, |
560 | unsigned int keylen) | ||
489 | { | 561 | { |
490 | struct qat_alg_session_ctx *ctx = crypto_aead_ctx(tfm); | 562 | int alg; |
563 | |||
564 | if (qat_alg_validate_key(keylen, &alg)) | ||
565 | goto bad_key; | ||
566 | |||
567 | qat_alg_ablkcipher_init_enc(ctx, alg, key, keylen); | ||
568 | qat_alg_ablkcipher_init_dec(ctx, alg, key, keylen); | ||
569 | return 0; | ||
570 | bad_key: | ||
571 | crypto_tfm_set_flags(ctx->tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); | ||
572 | return -EINVAL; | ||
573 | } | ||
574 | |||
575 | static int qat_alg_aead_setkey(struct crypto_aead *tfm, const uint8_t *key, | ||
576 | unsigned int keylen) | ||
577 | { | ||
578 | struct qat_alg_aead_ctx *ctx = crypto_aead_ctx(tfm); | ||
491 | struct device *dev; | 579 | struct device *dev; |
492 | 580 | ||
493 | spin_lock(&ctx->lock); | 581 | spin_lock(&ctx->lock); |
494 | if (ctx->enc_cd) { | 582 | if (ctx->enc_cd) { |
495 | /* rekeying */ | 583 | /* rekeying */ |
496 | dev = &GET_DEV(ctx->inst->accel_dev); | 584 | dev = &GET_DEV(ctx->inst->accel_dev); |
497 | memzero_explicit(ctx->enc_cd, sizeof(struct qat_alg_cd)); | 585 | memzero_explicit(ctx->enc_cd, sizeof(*ctx->enc_cd)); |
498 | memzero_explicit(ctx->dec_cd, sizeof(struct qat_alg_cd)); | 586 | memzero_explicit(ctx->dec_cd, sizeof(*ctx->dec_cd)); |
499 | memzero_explicit(&ctx->enc_fw_req_tmpl, | 587 | memzero_explicit(&ctx->enc_fw_req, sizeof(ctx->enc_fw_req)); |
500 | sizeof(struct icp_qat_fw_la_bulk_req)); | 588 | memzero_explicit(&ctx->dec_fw_req, sizeof(ctx->dec_fw_req)); |
501 | memzero_explicit(&ctx->dec_fw_req_tmpl, | ||
502 | sizeof(struct icp_qat_fw_la_bulk_req)); | ||
503 | } else { | 589 | } else { |
504 | /* new key */ | 590 | /* new key */ |
505 | int node = get_current_node(); | 591 | int node = get_current_node(); |
@@ -512,16 +598,14 @@ static int qat_alg_setkey(struct crypto_aead *tfm, const uint8_t *key, | |||
512 | 598 | ||
513 | dev = &GET_DEV(inst->accel_dev); | 599 | dev = &GET_DEV(inst->accel_dev); |
514 | ctx->inst = inst; | 600 | ctx->inst = inst; |
515 | ctx->enc_cd = dma_zalloc_coherent(dev, | 601 | ctx->enc_cd = dma_zalloc_coherent(dev, sizeof(*ctx->enc_cd), |
516 | sizeof(struct qat_alg_cd), | ||
517 | &ctx->enc_cd_paddr, | 602 | &ctx->enc_cd_paddr, |
518 | GFP_ATOMIC); | 603 | GFP_ATOMIC); |
519 | if (!ctx->enc_cd) { | 604 | if (!ctx->enc_cd) { |
520 | spin_unlock(&ctx->lock); | 605 | spin_unlock(&ctx->lock); |
521 | return -ENOMEM; | 606 | return -ENOMEM; |
522 | } | 607 | } |
523 | ctx->dec_cd = dma_zalloc_coherent(dev, | 608 | ctx->dec_cd = dma_zalloc_coherent(dev, sizeof(*ctx->dec_cd), |
524 | sizeof(struct qat_alg_cd), | ||
525 | &ctx->dec_cd_paddr, | 609 | &ctx->dec_cd_paddr, |
526 | GFP_ATOMIC); | 610 | GFP_ATOMIC); |
527 | if (!ctx->dec_cd) { | 611 | if (!ctx->dec_cd) { |
@@ -530,7 +614,7 @@ static int qat_alg_setkey(struct crypto_aead *tfm, const uint8_t *key, | |||
530 | } | 614 | } |
531 | } | 615 | } |
532 | spin_unlock(&ctx->lock); | 616 | spin_unlock(&ctx->lock); |
533 | if (qat_alg_init_sessions(ctx, key, keylen)) | 617 | if (qat_alg_aead_init_sessions(ctx, key, keylen)) |
534 | goto out_free_all; | 618 | goto out_free_all; |
535 | 619 | ||
536 | return 0; | 620 | return 0; |
@@ -722,14 +806,12 @@ err: | |||
722 | return -ENOMEM; | 806 | return -ENOMEM; |
723 | } | 807 | } |
724 | 808 | ||
725 | void qat_alg_callback(void *resp) | 809 | static void qat_aead_alg_callback(struct icp_qat_fw_la_resp *qat_resp, |
810 | struct qat_crypto_request *qat_req) | ||
726 | { | 811 | { |
727 | struct icp_qat_fw_la_resp *qat_resp = resp; | 812 | struct qat_alg_aead_ctx *ctx = qat_req->aead_ctx; |
728 | struct qat_crypto_request *qat_req = | ||
729 | (void *)(__force long)qat_resp->opaque_data; | ||
730 | struct qat_alg_session_ctx *ctx = qat_req->ctx; | ||
731 | struct qat_crypto_instance *inst = ctx->inst; | 813 | struct qat_crypto_instance *inst = ctx->inst; |
732 | struct aead_request *areq = qat_req->areq; | 814 | struct aead_request *areq = qat_req->aead_req; |
733 | uint8_t stat_filed = qat_resp->comn_resp.comn_status; | 815 | uint8_t stat_filed = qat_resp->comn_resp.comn_status; |
734 | int res = 0, qat_res = ICP_QAT_FW_COMN_RESP_CRYPTO_STAT_GET(stat_filed); | 816 | int res = 0, qat_res = ICP_QAT_FW_COMN_RESP_CRYPTO_STAT_GET(stat_filed); |
735 | 817 | ||
@@ -739,11 +821,35 @@ void qat_alg_callback(void *resp) | |||
739 | areq->base.complete(&areq->base, res); | 821 | areq->base.complete(&areq->base, res); |
740 | } | 822 | } |
741 | 823 | ||
742 | static int qat_alg_dec(struct aead_request *areq) | 824 | static void qat_ablkcipher_alg_callback(struct icp_qat_fw_la_resp *qat_resp, |
825 | struct qat_crypto_request *qat_req) | ||
826 | { | ||
827 | struct qat_alg_ablkcipher_ctx *ctx = qat_req->ablkcipher_ctx; | ||
828 | struct qat_crypto_instance *inst = ctx->inst; | ||
829 | struct ablkcipher_request *areq = qat_req->ablkcipher_req; | ||
830 | uint8_t stat_filed = qat_resp->comn_resp.comn_status; | ||
831 | int res = 0, qat_res = ICP_QAT_FW_COMN_RESP_CRYPTO_STAT_GET(stat_filed); | ||
832 | |||
833 | qat_alg_free_bufl(inst, qat_req); | ||
834 | if (unlikely(qat_res != ICP_QAT_FW_COMN_STATUS_FLAG_OK)) | ||
835 | res = -EINVAL; | ||
836 | areq->base.complete(&areq->base, res); | ||
837 | } | ||
838 | |||
839 | void qat_alg_callback(void *resp) | ||
840 | { | ||
841 | struct icp_qat_fw_la_resp *qat_resp = resp; | ||
842 | struct qat_crypto_request *qat_req = | ||
843 | (void *)(__force long)qat_resp->opaque_data; | ||
844 | |||
845 | qat_req->cb(qat_resp, qat_req); | ||
846 | } | ||
847 | |||
848 | static int qat_alg_aead_dec(struct aead_request *areq) | ||
743 | { | 849 | { |
744 | struct crypto_aead *aead_tfm = crypto_aead_reqtfm(areq); | 850 | struct crypto_aead *aead_tfm = crypto_aead_reqtfm(areq); |
745 | struct crypto_tfm *tfm = crypto_aead_tfm(aead_tfm); | 851 | struct crypto_tfm *tfm = crypto_aead_tfm(aead_tfm); |
746 | struct qat_alg_session_ctx *ctx = crypto_tfm_ctx(tfm); | 852 | struct qat_alg_aead_ctx *ctx = crypto_tfm_ctx(tfm); |
747 | struct qat_crypto_request *qat_req = aead_request_ctx(areq); | 853 | struct qat_crypto_request *qat_req = aead_request_ctx(areq); |
748 | struct icp_qat_fw_la_cipher_req_params *cipher_param; | 854 | struct icp_qat_fw_la_cipher_req_params *cipher_param; |
749 | struct icp_qat_fw_la_auth_req_params *auth_param; | 855 | struct icp_qat_fw_la_auth_req_params *auth_param; |
@@ -757,9 +863,10 @@ static int qat_alg_dec(struct aead_request *areq) | |||
757 | return ret; | 863 | return ret; |
758 | 864 | ||
759 | msg = &qat_req->req; | 865 | msg = &qat_req->req; |
760 | *msg = ctx->dec_fw_req_tmpl; | 866 | *msg = ctx->dec_fw_req; |
761 | qat_req->ctx = ctx; | 867 | qat_req->aead_ctx = ctx; |
762 | qat_req->areq = areq; | 868 | qat_req->aead_req = areq; |
869 | qat_req->cb = qat_aead_alg_callback; | ||
763 | qat_req->req.comn_mid.opaque_data = (uint64_t)(__force long)qat_req; | 870 | qat_req->req.comn_mid.opaque_data = (uint64_t)(__force long)qat_req; |
764 | qat_req->req.comn_mid.src_data_addr = qat_req->buf.blp; | 871 | qat_req->req.comn_mid.src_data_addr = qat_req->buf.blp; |
765 | qat_req->req.comn_mid.dest_data_addr = qat_req->buf.bloutp; | 872 | qat_req->req.comn_mid.dest_data_addr = qat_req->buf.bloutp; |
@@ -782,12 +889,12 @@ static int qat_alg_dec(struct aead_request *areq) | |||
782 | return -EINPROGRESS; | 889 | return -EINPROGRESS; |
783 | } | 890 | } |
784 | 891 | ||
785 | static int qat_alg_enc_internal(struct aead_request *areq, uint8_t *iv, | 892 | static int qat_alg_aead_enc_internal(struct aead_request *areq, uint8_t *iv, |
786 | int enc_iv) | 893 | int enc_iv) |
787 | { | 894 | { |
788 | struct crypto_aead *aead_tfm = crypto_aead_reqtfm(areq); | 895 | struct crypto_aead *aead_tfm = crypto_aead_reqtfm(areq); |
789 | struct crypto_tfm *tfm = crypto_aead_tfm(aead_tfm); | 896 | struct crypto_tfm *tfm = crypto_aead_tfm(aead_tfm); |
790 | struct qat_alg_session_ctx *ctx = crypto_tfm_ctx(tfm); | 897 | struct qat_alg_aead_ctx *ctx = crypto_tfm_ctx(tfm); |
791 | struct qat_crypto_request *qat_req = aead_request_ctx(areq); | 898 | struct qat_crypto_request *qat_req = aead_request_ctx(areq); |
792 | struct icp_qat_fw_la_cipher_req_params *cipher_param; | 899 | struct icp_qat_fw_la_cipher_req_params *cipher_param; |
793 | struct icp_qat_fw_la_auth_req_params *auth_param; | 900 | struct icp_qat_fw_la_auth_req_params *auth_param; |
@@ -800,9 +907,10 @@ static int qat_alg_enc_internal(struct aead_request *areq, uint8_t *iv, | |||
800 | return ret; | 907 | return ret; |
801 | 908 | ||
802 | msg = &qat_req->req; | 909 | msg = &qat_req->req; |
803 | *msg = ctx->enc_fw_req_tmpl; | 910 | *msg = ctx->enc_fw_req; |
804 | qat_req->ctx = ctx; | 911 | qat_req->aead_ctx = ctx; |
805 | qat_req->areq = areq; | 912 | qat_req->aead_req = areq; |
913 | qat_req->cb = qat_aead_alg_callback; | ||
806 | qat_req->req.comn_mid.opaque_data = (uint64_t)(__force long)qat_req; | 914 | qat_req->req.comn_mid.opaque_data = (uint64_t)(__force long)qat_req; |
807 | qat_req->req.comn_mid.src_data_addr = qat_req->buf.blp; | 915 | qat_req->req.comn_mid.src_data_addr = qat_req->buf.blp; |
808 | qat_req->req.comn_mid.dest_data_addr = qat_req->buf.bloutp; | 916 | qat_req->req.comn_mid.dest_data_addr = qat_req->buf.bloutp; |
@@ -831,29 +939,167 @@ static int qat_alg_enc_internal(struct aead_request *areq, uint8_t *iv, | |||
831 | return -EINPROGRESS; | 939 | return -EINPROGRESS; |
832 | } | 940 | } |
833 | 941 | ||
834 | static int qat_alg_enc(struct aead_request *areq) | 942 | static int qat_alg_aead_enc(struct aead_request *areq) |
835 | { | 943 | { |
836 | return qat_alg_enc_internal(areq, areq->iv, 0); | 944 | return qat_alg_aead_enc_internal(areq, areq->iv, 0); |
837 | } | 945 | } |
838 | 946 | ||
839 | static int qat_alg_genivenc(struct aead_givcrypt_request *req) | 947 | static int qat_alg_aead_genivenc(struct aead_givcrypt_request *req) |
840 | { | 948 | { |
841 | struct crypto_aead *aead_tfm = crypto_aead_reqtfm(&req->areq); | 949 | struct crypto_aead *aead_tfm = crypto_aead_reqtfm(&req->areq); |
842 | struct crypto_tfm *tfm = crypto_aead_tfm(aead_tfm); | 950 | struct crypto_tfm *tfm = crypto_aead_tfm(aead_tfm); |
843 | struct qat_alg_session_ctx *ctx = crypto_tfm_ctx(tfm); | 951 | struct qat_alg_aead_ctx *ctx = crypto_tfm_ctx(tfm); |
844 | __be64 seq; | 952 | __be64 seq; |
845 | 953 | ||
846 | memcpy(req->giv, ctx->salt, AES_BLOCK_SIZE); | 954 | memcpy(req->giv, ctx->salt, AES_BLOCK_SIZE); |
847 | seq = cpu_to_be64(req->seq); | 955 | seq = cpu_to_be64(req->seq); |
848 | memcpy(req->giv + AES_BLOCK_SIZE - sizeof(uint64_t), | 956 | memcpy(req->giv + AES_BLOCK_SIZE - sizeof(uint64_t), |
849 | &seq, sizeof(uint64_t)); | 957 | &seq, sizeof(uint64_t)); |
850 | return qat_alg_enc_internal(&req->areq, req->giv, 1); | 958 | return qat_alg_aead_enc_internal(&req->areq, req->giv, 1); |
851 | } | 959 | } |
852 | 960 | ||
853 | static int qat_alg_init(struct crypto_tfm *tfm, | 961 | static int qat_alg_ablkcipher_setkey(struct crypto_ablkcipher *tfm, |
854 | enum icp_qat_hw_auth_algo hash, const char *hash_name) | 962 | const uint8_t *key, |
963 | unsigned int keylen) | ||
855 | { | 964 | { |
856 | struct qat_alg_session_ctx *ctx = crypto_tfm_ctx(tfm); | 965 | struct qat_alg_ablkcipher_ctx *ctx = crypto_ablkcipher_ctx(tfm); |
966 | struct device *dev; | ||
967 | |||
968 | spin_lock(&ctx->lock); | ||
969 | if (ctx->enc_cd) { | ||
970 | /* rekeying */ | ||
971 | dev = &GET_DEV(ctx->inst->accel_dev); | ||
972 | memzero_explicit(ctx->enc_cd, sizeof(*ctx->enc_cd)); | ||
973 | memzero_explicit(ctx->dec_cd, sizeof(*ctx->dec_cd)); | ||
974 | memzero_explicit(&ctx->enc_fw_req, sizeof(ctx->enc_fw_req)); | ||
975 | memzero_explicit(&ctx->dec_fw_req, sizeof(ctx->dec_fw_req)); | ||
976 | } else { | ||
977 | /* new key */ | ||
978 | int node = get_current_node(); | ||
979 | struct qat_crypto_instance *inst = | ||
980 | qat_crypto_get_instance_node(node); | ||
981 | if (!inst) { | ||
982 | spin_unlock(&ctx->lock); | ||
983 | return -EINVAL; | ||
984 | } | ||
985 | |||
986 | dev = &GET_DEV(inst->accel_dev); | ||
987 | ctx->inst = inst; | ||
988 | ctx->enc_cd = dma_zalloc_coherent(dev, sizeof(*ctx->enc_cd), | ||
989 | &ctx->enc_cd_paddr, | ||
990 | GFP_ATOMIC); | ||
991 | if (!ctx->enc_cd) { | ||
992 | spin_unlock(&ctx->lock); | ||
993 | return -ENOMEM; | ||
994 | } | ||
995 | ctx->dec_cd = dma_zalloc_coherent(dev, sizeof(*ctx->dec_cd), | ||
996 | &ctx->dec_cd_paddr, | ||
997 | GFP_ATOMIC); | ||
998 | if (!ctx->dec_cd) { | ||
999 | spin_unlock(&ctx->lock); | ||
1000 | goto out_free_enc; | ||
1001 | } | ||
1002 | } | ||
1003 | spin_unlock(&ctx->lock); | ||
1004 | if (qat_alg_ablkcipher_init_sessions(ctx, key, keylen)) | ||
1005 | goto out_free_all; | ||
1006 | |||
1007 | return 0; | ||
1008 | |||
1009 | out_free_all: | ||
1010 | memzero_explicit(ctx->dec_cd, sizeof(*ctx->enc_cd)); | ||
1011 | dma_free_coherent(dev, sizeof(*ctx->enc_cd), | ||
1012 | ctx->dec_cd, ctx->dec_cd_paddr); | ||
1013 | ctx->dec_cd = NULL; | ||
1014 | out_free_enc: | ||
1015 | memzero_explicit(ctx->enc_cd, sizeof(*ctx->dec_cd)); | ||
1016 | dma_free_coherent(dev, sizeof(*ctx->dec_cd), | ||
1017 | ctx->enc_cd, ctx->enc_cd_paddr); | ||
1018 | ctx->enc_cd = NULL; | ||
1019 | return -ENOMEM; | ||
1020 | } | ||
1021 | |||
1022 | static int qat_alg_ablkcipher_encrypt(struct ablkcipher_request *req) | ||
1023 | { | ||
1024 | struct crypto_ablkcipher *atfm = crypto_ablkcipher_reqtfm(req); | ||
1025 | struct crypto_tfm *tfm = crypto_ablkcipher_tfm(atfm); | ||
1026 | struct qat_alg_ablkcipher_ctx *ctx = crypto_tfm_ctx(tfm); | ||
1027 | struct qat_crypto_request *qat_req = ablkcipher_request_ctx(req); | ||
1028 | struct icp_qat_fw_la_cipher_req_params *cipher_param; | ||
1029 | struct icp_qat_fw_la_bulk_req *msg; | ||
1030 | int ret, ctr = 0; | ||
1031 | |||
1032 | ret = qat_alg_sgl_to_bufl(ctx->inst, NULL, req->src, req->dst, | ||
1033 | NULL, 0, qat_req); | ||
1034 | if (unlikely(ret)) | ||
1035 | return ret; | ||
1036 | |||
1037 | msg = &qat_req->req; | ||
1038 | *msg = ctx->enc_fw_req; | ||
1039 | qat_req->ablkcipher_ctx = ctx; | ||
1040 | qat_req->ablkcipher_req = req; | ||
1041 | qat_req->cb = qat_ablkcipher_alg_callback; | ||
1042 | qat_req->req.comn_mid.opaque_data = (uint64_t)(__force long)qat_req; | ||
1043 | qat_req->req.comn_mid.src_data_addr = qat_req->buf.blp; | ||
1044 | qat_req->req.comn_mid.dest_data_addr = qat_req->buf.bloutp; | ||
1045 | cipher_param = (void *)&qat_req->req.serv_specif_rqpars; | ||
1046 | cipher_param->cipher_length = req->nbytes; | ||
1047 | cipher_param->cipher_offset = 0; | ||
1048 | memcpy(cipher_param->u.cipher_IV_array, req->info, AES_BLOCK_SIZE); | ||
1049 | do { | ||
1050 | ret = adf_send_message(ctx->inst->sym_tx, (uint32_t *)msg); | ||
1051 | } while (ret == -EAGAIN && ctr++ < 10); | ||
1052 | |||
1053 | if (ret == -EAGAIN) { | ||
1054 | qat_alg_free_bufl(ctx->inst, qat_req); | ||
1055 | return -EBUSY; | ||
1056 | } | ||
1057 | return -EINPROGRESS; | ||
1058 | } | ||
1059 | |||
1060 | static int qat_alg_ablkcipher_decrypt(struct ablkcipher_request *req) | ||
1061 | { | ||
1062 | struct crypto_ablkcipher *atfm = crypto_ablkcipher_reqtfm(req); | ||
1063 | struct crypto_tfm *tfm = crypto_ablkcipher_tfm(atfm); | ||
1064 | struct qat_alg_ablkcipher_ctx *ctx = crypto_tfm_ctx(tfm); | ||
1065 | struct qat_crypto_request *qat_req = ablkcipher_request_ctx(req); | ||
1066 | struct icp_qat_fw_la_cipher_req_params *cipher_param; | ||
1067 | struct icp_qat_fw_la_bulk_req *msg; | ||
1068 | int ret, ctr = 0; | ||
1069 | |||
1070 | ret = qat_alg_sgl_to_bufl(ctx->inst, NULL, req->src, req->dst, | ||
1071 | NULL, 0, qat_req); | ||
1072 | if (unlikely(ret)) | ||
1073 | return ret; | ||
1074 | |||
1075 | msg = &qat_req->req; | ||
1076 | *msg = ctx->dec_fw_req; | ||
1077 | qat_req->ablkcipher_ctx = ctx; | ||
1078 | qat_req->ablkcipher_req = req; | ||
1079 | qat_req->cb = qat_ablkcipher_alg_callback; | ||
1080 | qat_req->req.comn_mid.opaque_data = (uint64_t)(__force long)qat_req; | ||
1081 | qat_req->req.comn_mid.src_data_addr = qat_req->buf.blp; | ||
1082 | qat_req->req.comn_mid.dest_data_addr = qat_req->buf.bloutp; | ||
1083 | cipher_param = (void *)&qat_req->req.serv_specif_rqpars; | ||
1084 | cipher_param->cipher_length = req->nbytes; | ||
1085 | cipher_param->cipher_offset = 0; | ||
1086 | memcpy(cipher_param->u.cipher_IV_array, req->info, AES_BLOCK_SIZE); | ||
1087 | do { | ||
1088 | ret = adf_send_message(ctx->inst->sym_tx, (uint32_t *)msg); | ||
1089 | } while (ret == -EAGAIN && ctr++ < 10); | ||
1090 | |||
1091 | if (ret == -EAGAIN) { | ||
1092 | qat_alg_free_bufl(ctx->inst, qat_req); | ||
1093 | return -EBUSY; | ||
1094 | } | ||
1095 | return -EINPROGRESS; | ||
1096 | } | ||
1097 | |||
1098 | static int qat_alg_aead_init(struct crypto_tfm *tfm, | ||
1099 | enum icp_qat_hw_auth_algo hash, | ||
1100 | const char *hash_name) | ||
1101 | { | ||
1102 | struct qat_alg_aead_ctx *ctx = crypto_tfm_ctx(tfm); | ||
857 | 1103 | ||
858 | memzero_explicit(ctx, sizeof(*ctx)); | 1104 | memzero_explicit(ctx, sizeof(*ctx)); |
859 | ctx->hash_tfm = crypto_alloc_shash(hash_name, 0, 0); | 1105 | ctx->hash_tfm = crypto_alloc_shash(hash_name, 0, 0); |
@@ -867,24 +1113,24 @@ static int qat_alg_init(struct crypto_tfm *tfm, | |||
867 | return 0; | 1113 | return 0; |
868 | } | 1114 | } |
869 | 1115 | ||
870 | static int qat_alg_sha1_init(struct crypto_tfm *tfm) | 1116 | static int qat_alg_aead_sha1_init(struct crypto_tfm *tfm) |
871 | { | 1117 | { |
872 | return qat_alg_init(tfm, ICP_QAT_HW_AUTH_ALGO_SHA1, "sha1"); | 1118 | return qat_alg_aead_init(tfm, ICP_QAT_HW_AUTH_ALGO_SHA1, "sha1"); |
873 | } | 1119 | } |
874 | 1120 | ||
875 | static int qat_alg_sha256_init(struct crypto_tfm *tfm) | 1121 | static int qat_alg_aead_sha256_init(struct crypto_tfm *tfm) |
876 | { | 1122 | { |
877 | return qat_alg_init(tfm, ICP_QAT_HW_AUTH_ALGO_SHA256, "sha256"); | 1123 | return qat_alg_aead_init(tfm, ICP_QAT_HW_AUTH_ALGO_SHA256, "sha256"); |
878 | } | 1124 | } |
879 | 1125 | ||
880 | static int qat_alg_sha512_init(struct crypto_tfm *tfm) | 1126 | static int qat_alg_aead_sha512_init(struct crypto_tfm *tfm) |
881 | { | 1127 | { |
882 | return qat_alg_init(tfm, ICP_QAT_HW_AUTH_ALGO_SHA512, "sha512"); | 1128 | return qat_alg_aead_init(tfm, ICP_QAT_HW_AUTH_ALGO_SHA512, "sha512"); |
883 | } | 1129 | } |
884 | 1130 | ||
885 | static void qat_alg_exit(struct crypto_tfm *tfm) | 1131 | static void qat_alg_aead_exit(struct crypto_tfm *tfm) |
886 | { | 1132 | { |
887 | struct qat_alg_session_ctx *ctx = crypto_tfm_ctx(tfm); | 1133 | struct qat_alg_aead_ctx *ctx = crypto_tfm_ctx(tfm); |
888 | struct qat_crypto_instance *inst = ctx->inst; | 1134 | struct qat_crypto_instance *inst = ctx->inst; |
889 | struct device *dev; | 1135 | struct device *dev; |
890 | 1136 | ||
@@ -908,24 +1154,63 @@ static void qat_alg_exit(struct crypto_tfm *tfm) | |||
908 | qat_crypto_put_instance(inst); | 1154 | qat_crypto_put_instance(inst); |
909 | } | 1155 | } |
910 | 1156 | ||
1157 | static int qat_alg_ablkcipher_init(struct crypto_tfm *tfm) | ||
1158 | { | ||
1159 | struct qat_alg_ablkcipher_ctx *ctx = crypto_tfm_ctx(tfm); | ||
1160 | |||
1161 | memzero_explicit(ctx, sizeof(*ctx)); | ||
1162 | spin_lock_init(&ctx->lock); | ||
1163 | tfm->crt_ablkcipher.reqsize = sizeof(struct ablkcipher_request) + | ||
1164 | sizeof(struct qat_crypto_request); | ||
1165 | ctx->tfm = tfm; | ||
1166 | return 0; | ||
1167 | } | ||
1168 | |||
1169 | static void qat_alg_ablkcipher_exit(struct crypto_tfm *tfm) | ||
1170 | { | ||
1171 | struct qat_alg_ablkcipher_ctx *ctx = crypto_tfm_ctx(tfm); | ||
1172 | struct qat_crypto_instance *inst = ctx->inst; | ||
1173 | struct device *dev; | ||
1174 | |||
1175 | if (!inst) | ||
1176 | return; | ||
1177 | |||
1178 | dev = &GET_DEV(inst->accel_dev); | ||
1179 | if (ctx->enc_cd) { | ||
1180 | memzero_explicit(ctx->enc_cd, | ||
1181 | sizeof(struct icp_qat_hw_cipher_algo_blk)); | ||
1182 | dma_free_coherent(dev, | ||
1183 | sizeof(struct icp_qat_hw_cipher_algo_blk), | ||
1184 | ctx->enc_cd, ctx->enc_cd_paddr); | ||
1185 | } | ||
1186 | if (ctx->dec_cd) { | ||
1187 | memzero_explicit(ctx->dec_cd, | ||
1188 | sizeof(struct icp_qat_hw_cipher_algo_blk)); | ||
1189 | dma_free_coherent(dev, | ||
1190 | sizeof(struct icp_qat_hw_cipher_algo_blk), | ||
1191 | ctx->dec_cd, ctx->dec_cd_paddr); | ||
1192 | } | ||
1193 | qat_crypto_put_instance(inst); | ||
1194 | } | ||
1195 | |||
911 | static struct crypto_alg qat_algs[] = { { | 1196 | static struct crypto_alg qat_algs[] = { { |
912 | .cra_name = "authenc(hmac(sha1),cbc(aes))", | 1197 | .cra_name = "authenc(hmac(sha1),cbc(aes))", |
913 | .cra_driver_name = "qat_aes_cbc_hmac_sha1", | 1198 | .cra_driver_name = "qat_aes_cbc_hmac_sha1", |
914 | .cra_priority = 4001, | 1199 | .cra_priority = 4001, |
915 | .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC, | 1200 | .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC, |
916 | .cra_blocksize = AES_BLOCK_SIZE, | 1201 | .cra_blocksize = AES_BLOCK_SIZE, |
917 | .cra_ctxsize = sizeof(struct qat_alg_session_ctx), | 1202 | .cra_ctxsize = sizeof(struct qat_alg_aead_ctx), |
918 | .cra_alignmask = 0, | 1203 | .cra_alignmask = 0, |
919 | .cra_type = &crypto_aead_type, | 1204 | .cra_type = &crypto_aead_type, |
920 | .cra_module = THIS_MODULE, | 1205 | .cra_module = THIS_MODULE, |
921 | .cra_init = qat_alg_sha1_init, | 1206 | .cra_init = qat_alg_aead_sha1_init, |
922 | .cra_exit = qat_alg_exit, | 1207 | .cra_exit = qat_alg_aead_exit, |
923 | .cra_u = { | 1208 | .cra_u = { |
924 | .aead = { | 1209 | .aead = { |
925 | .setkey = qat_alg_setkey, | 1210 | .setkey = qat_alg_aead_setkey, |
926 | .decrypt = qat_alg_dec, | 1211 | .decrypt = qat_alg_aead_dec, |
927 | .encrypt = qat_alg_enc, | 1212 | .encrypt = qat_alg_aead_enc, |
928 | .givencrypt = qat_alg_genivenc, | 1213 | .givencrypt = qat_alg_aead_genivenc, |
929 | .ivsize = AES_BLOCK_SIZE, | 1214 | .ivsize = AES_BLOCK_SIZE, |
930 | .maxauthsize = SHA1_DIGEST_SIZE, | 1215 | .maxauthsize = SHA1_DIGEST_SIZE, |
931 | }, | 1216 | }, |
@@ -936,18 +1221,18 @@ static struct crypto_alg qat_algs[] = { { | |||
936 | .cra_priority = 4001, | 1221 | .cra_priority = 4001, |
937 | .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC, | 1222 | .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC, |
938 | .cra_blocksize = AES_BLOCK_SIZE, | 1223 | .cra_blocksize = AES_BLOCK_SIZE, |
939 | .cra_ctxsize = sizeof(struct qat_alg_session_ctx), | 1224 | .cra_ctxsize = sizeof(struct qat_alg_aead_ctx), |
940 | .cra_alignmask = 0, | 1225 | .cra_alignmask = 0, |
941 | .cra_type = &crypto_aead_type, | 1226 | .cra_type = &crypto_aead_type, |
942 | .cra_module = THIS_MODULE, | 1227 | .cra_module = THIS_MODULE, |
943 | .cra_init = qat_alg_sha256_init, | 1228 | .cra_init = qat_alg_aead_sha256_init, |
944 | .cra_exit = qat_alg_exit, | 1229 | .cra_exit = qat_alg_aead_exit, |
945 | .cra_u = { | 1230 | .cra_u = { |
946 | .aead = { | 1231 | .aead = { |
947 | .setkey = qat_alg_setkey, | 1232 | .setkey = qat_alg_aead_setkey, |
948 | .decrypt = qat_alg_dec, | 1233 | .decrypt = qat_alg_aead_dec, |
949 | .encrypt = qat_alg_enc, | 1234 | .encrypt = qat_alg_aead_enc, |
950 | .givencrypt = qat_alg_genivenc, | 1235 | .givencrypt = qat_alg_aead_genivenc, |
951 | .ivsize = AES_BLOCK_SIZE, | 1236 | .ivsize = AES_BLOCK_SIZE, |
952 | .maxauthsize = SHA256_DIGEST_SIZE, | 1237 | .maxauthsize = SHA256_DIGEST_SIZE, |
953 | }, | 1238 | }, |
@@ -958,22 +1243,44 @@ static struct crypto_alg qat_algs[] = { { | |||
958 | .cra_priority = 4001, | 1243 | .cra_priority = 4001, |
959 | .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC, | 1244 | .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC, |
960 | .cra_blocksize = AES_BLOCK_SIZE, | 1245 | .cra_blocksize = AES_BLOCK_SIZE, |
961 | .cra_ctxsize = sizeof(struct qat_alg_session_ctx), | 1246 | .cra_ctxsize = sizeof(struct qat_alg_aead_ctx), |
962 | .cra_alignmask = 0, | 1247 | .cra_alignmask = 0, |
963 | .cra_type = &crypto_aead_type, | 1248 | .cra_type = &crypto_aead_type, |
964 | .cra_module = THIS_MODULE, | 1249 | .cra_module = THIS_MODULE, |
965 | .cra_init = qat_alg_sha512_init, | 1250 | .cra_init = qat_alg_aead_sha512_init, |
966 | .cra_exit = qat_alg_exit, | 1251 | .cra_exit = qat_alg_aead_exit, |
967 | .cra_u = { | 1252 | .cra_u = { |
968 | .aead = { | 1253 | .aead = { |
969 | .setkey = qat_alg_setkey, | 1254 | .setkey = qat_alg_aead_setkey, |
970 | .decrypt = qat_alg_dec, | 1255 | .decrypt = qat_alg_aead_dec, |
971 | .encrypt = qat_alg_enc, | 1256 | .encrypt = qat_alg_aead_enc, |
972 | .givencrypt = qat_alg_genivenc, | 1257 | .givencrypt = qat_alg_aead_genivenc, |
973 | .ivsize = AES_BLOCK_SIZE, | 1258 | .ivsize = AES_BLOCK_SIZE, |
974 | .maxauthsize = SHA512_DIGEST_SIZE, | 1259 | .maxauthsize = SHA512_DIGEST_SIZE, |
975 | }, | 1260 | }, |
976 | }, | 1261 | }, |
1262 | }, { | ||
1263 | .cra_name = "cbc(aes)", | ||
1264 | .cra_driver_name = "qat_aes_cbc", | ||
1265 | .cra_priority = 4001, | ||
1266 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, | ||
1267 | .cra_blocksize = AES_BLOCK_SIZE, | ||
1268 | .cra_ctxsize = sizeof(struct qat_alg_ablkcipher_ctx), | ||
1269 | .cra_alignmask = 0, | ||
1270 | .cra_type = &crypto_ablkcipher_type, | ||
1271 | .cra_module = THIS_MODULE, | ||
1272 | .cra_init = qat_alg_ablkcipher_init, | ||
1273 | .cra_exit = qat_alg_ablkcipher_exit, | ||
1274 | .cra_u = { | ||
1275 | .ablkcipher = { | ||
1276 | .setkey = qat_alg_ablkcipher_setkey, | ||
1277 | .decrypt = qat_alg_ablkcipher_decrypt, | ||
1278 | .encrypt = qat_alg_ablkcipher_encrypt, | ||
1279 | .min_keysize = AES_MIN_KEY_SIZE, | ||
1280 | .max_keysize = AES_MAX_KEY_SIZE, | ||
1281 | .ivsize = AES_BLOCK_SIZE, | ||
1282 | }, | ||
1283 | }, | ||
977 | } }; | 1284 | } }; |
978 | 1285 | ||
979 | int qat_algs_register(void) | 1286 | int qat_algs_register(void) |
@@ -982,8 +1289,11 @@ int qat_algs_register(void) | |||
982 | int i; | 1289 | int i; |
983 | 1290 | ||
984 | for (i = 0; i < ARRAY_SIZE(qat_algs); i++) | 1291 | for (i = 0; i < ARRAY_SIZE(qat_algs); i++) |
985 | qat_algs[i].cra_flags = CRYPTO_ALG_TYPE_AEAD | | 1292 | qat_algs[i].cra_flags = |
986 | CRYPTO_ALG_ASYNC; | 1293 | (qat_algs[i].cra_type == &crypto_aead_type) ? |
1294 | CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC : | ||
1295 | CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC; | ||
1296 | |||
987 | return crypto_register_algs(qat_algs, ARRAY_SIZE(qat_algs)); | 1297 | return crypto_register_algs(qat_algs, ARRAY_SIZE(qat_algs)); |
988 | } | 1298 | } |
989 | return 0; | 1299 | return 0; |
diff --git a/drivers/crypto/qat/qat_common/qat_crypto.h b/drivers/crypto/qat/qat_common/qat_crypto.h index fcb323116e60..d503007b49e6 100644 --- a/drivers/crypto/qat/qat_common/qat_crypto.h +++ b/drivers/crypto/qat/qat_common/qat_crypto.h | |||
@@ -75,10 +75,21 @@ struct qat_crypto_request_buffs { | |||
75 | size_t sz_out; | 75 | size_t sz_out; |
76 | }; | 76 | }; |
77 | 77 | ||
78 | struct qat_crypto_request; | ||
79 | |||
78 | struct qat_crypto_request { | 80 | struct qat_crypto_request { |
79 | struct icp_qat_fw_la_bulk_req req; | 81 | struct icp_qat_fw_la_bulk_req req; |
80 | struct qat_alg_session_ctx *ctx; | 82 | union { |
81 | struct aead_request *areq; | 83 | struct qat_alg_aead_ctx *aead_ctx; |
84 | struct qat_alg_ablkcipher_ctx *ablkcipher_ctx; | ||
85 | }; | ||
86 | union { | ||
87 | struct aead_request *aead_req; | ||
88 | struct ablkcipher_request *ablkcipher_req; | ||
89 | }; | ||
82 | struct qat_crypto_request_buffs buf; | 90 | struct qat_crypto_request_buffs buf; |
91 | void (*cb)(struct icp_qat_fw_la_resp *resp, | ||
92 | struct qat_crypto_request *req); | ||
83 | }; | 93 | }; |
94 | |||
84 | #endif | 95 | #endif |