Lines Matching +full:stm32mp1 +full:- +full:cryp

1 // SPDX-License-Identifier: GPL-2.0-only
24 #define DRIVER_NAME "stm32-cryp"
108 #define _walked_in (cryp->in_walk.offset - cryp->in_sg->offset)
109 #define _walked_out (cryp->out_walk.offset - cryp->out_sg->offset)
119 struct stm32_cryp *cryp; member
180 static inline bool is_aes(struct stm32_cryp *cryp) in is_aes() argument
182 return cryp->flags & FLG_AES; in is_aes()
185 static inline bool is_des(struct stm32_cryp *cryp) in is_des() argument
187 return cryp->flags & FLG_DES; in is_des()
190 static inline bool is_tdes(struct stm32_cryp *cryp) in is_tdes() argument
192 return cryp->flags & FLG_TDES; in is_tdes()
195 static inline bool is_ecb(struct stm32_cryp *cryp) in is_ecb() argument
197 return cryp->flags & FLG_ECB; in is_ecb()
200 static inline bool is_cbc(struct stm32_cryp *cryp) in is_cbc() argument
202 return cryp->flags & FLG_CBC; in is_cbc()
205 static inline bool is_ctr(struct stm32_cryp *cryp) in is_ctr() argument
207 return cryp->flags & FLG_CTR; in is_ctr()
210 static inline bool is_gcm(struct stm32_cryp *cryp) in is_gcm() argument
212 return cryp->flags & FLG_GCM; in is_gcm()
215 static inline bool is_ccm(struct stm32_cryp *cryp) in is_ccm() argument
217 return cryp->flags & FLG_CCM; in is_ccm()
220 static inline bool is_encrypt(struct stm32_cryp *cryp) in is_encrypt() argument
222 return cryp->flags & FLG_ENCRYPT; in is_encrypt()
225 static inline bool is_decrypt(struct stm32_cryp *cryp) in is_decrypt() argument
227 return !is_encrypt(cryp); in is_decrypt()
230 static inline u32 stm32_cryp_read(struct stm32_cryp *cryp, u32 ofst) in stm32_cryp_read() argument
232 return readl_relaxed(cryp->regs + ofst); in stm32_cryp_read()
235 static inline void stm32_cryp_write(struct stm32_cryp *cryp, u32 ofst, u32 val) in stm32_cryp_write() argument
237 writel_relaxed(val, cryp->regs + ofst); in stm32_cryp_write()
240 static inline int stm32_cryp_wait_busy(struct stm32_cryp *cryp) in stm32_cryp_wait_busy() argument
244 return readl_relaxed_poll_timeout(cryp->regs + CRYP_SR, status, in stm32_cryp_wait_busy()
248 static inline int stm32_cryp_wait_enable(struct stm32_cryp *cryp) in stm32_cryp_wait_enable() argument
252 return readl_relaxed_poll_timeout(cryp->regs + CRYP_CR, status, in stm32_cryp_wait_enable()
256 static inline int stm32_cryp_wait_output(struct stm32_cryp *cryp) in stm32_cryp_wait_output() argument
260 return readl_relaxed_poll_timeout(cryp->regs + CRYP_SR, status, in stm32_cryp_wait_output()
264 static int stm32_cryp_read_auth_tag(struct stm32_cryp *cryp);
268 struct stm32_cryp *tmp, *cryp = NULL; in stm32_cryp_find_dev() local
271 if (!ctx->cryp) { in stm32_cryp_find_dev()
273 cryp = tmp; in stm32_cryp_find_dev()
276 ctx->cryp = cryp; in stm32_cryp_find_dev()
278 cryp = ctx->cryp; in stm32_cryp_find_dev()
283 return cryp; in stm32_cryp_find_dev()
295 return -EINVAL; in stm32_cryp_check_aligned()
298 if (!IS_ALIGNED(sg->offset, sizeof(u32))) in stm32_cryp_check_aligned()
299 return -EINVAL; in stm32_cryp_check_aligned()
301 if (!IS_ALIGNED(sg->length, align)) in stm32_cryp_check_aligned()
302 return -EINVAL; in stm32_cryp_check_aligned()
304 len += sg->length; in stm32_cryp_check_aligned()
309 return -EINVAL; in stm32_cryp_check_aligned()
314 static int stm32_cryp_check_io_aligned(struct stm32_cryp *cryp) in stm32_cryp_check_io_aligned() argument
318 ret = stm32_cryp_check_aligned(cryp->in_sg, cryp->total_in, in stm32_cryp_check_io_aligned()
319 cryp->hw_blocksize); in stm32_cryp_check_io_aligned()
323 ret = stm32_cryp_check_aligned(cryp->out_sg, cryp->total_out, in stm32_cryp_check_io_aligned()
324 cryp->hw_blocksize); in stm32_cryp_check_io_aligned()
343 static int stm32_cryp_copy_sgs(struct stm32_cryp *cryp) in stm32_cryp_copy_sgs() argument
348 if (!stm32_cryp_check_io_aligned(cryp)) { in stm32_cryp_copy_sgs()
349 cryp->sgs_copied = 0; in stm32_cryp_copy_sgs()
353 total_in = ALIGN(cryp->total_in, cryp->hw_blocksize); in stm32_cryp_copy_sgs()
357 total_out = ALIGN(cryp->total_out, cryp->hw_blocksize); in stm32_cryp_copy_sgs()
362 dev_err(cryp->dev, "Can't allocate pages when unaligned\n"); in stm32_cryp_copy_sgs()
363 cryp->sgs_copied = 0; in stm32_cryp_copy_sgs()
364 return -EFAULT; in stm32_cryp_copy_sgs()
367 sg_copy_buf(buf_in, cryp->in_sg, 0, cryp->total_in, 0); in stm32_cryp_copy_sgs()
369 sg_init_one(&cryp->in_sgl, buf_in, total_in); in stm32_cryp_copy_sgs()
370 cryp->in_sg = &cryp->in_sgl; in stm32_cryp_copy_sgs()
371 cryp->in_sg_len = 1; in stm32_cryp_copy_sgs()
373 sg_init_one(&cryp->out_sgl, buf_out, total_out); in stm32_cryp_copy_sgs()
374 cryp->out_sg_save = cryp->out_sg; in stm32_cryp_copy_sgs()
375 cryp->out_sg = &cryp->out_sgl; in stm32_cryp_copy_sgs()
376 cryp->out_sg_len = 1; in stm32_cryp_copy_sgs()
378 cryp->sgs_copied = 1; in stm32_cryp_copy_sgs()
383 static void stm32_cryp_hw_write_iv(struct stm32_cryp *cryp, __be32 *iv) in stm32_cryp_hw_write_iv() argument
388 stm32_cryp_write(cryp, CRYP_IV0LR, be32_to_cpu(*iv++)); in stm32_cryp_hw_write_iv()
389 stm32_cryp_write(cryp, CRYP_IV0RR, be32_to_cpu(*iv++)); in stm32_cryp_hw_write_iv()
391 if (is_aes(cryp)) { in stm32_cryp_hw_write_iv()
392 stm32_cryp_write(cryp, CRYP_IV1LR, be32_to_cpu(*iv++)); in stm32_cryp_hw_write_iv()
393 stm32_cryp_write(cryp, CRYP_IV1RR, be32_to_cpu(*iv++)); in stm32_cryp_hw_write_iv()
397 static void stm32_cryp_get_iv(struct stm32_cryp *cryp) in stm32_cryp_get_iv() argument
399 struct skcipher_request *req = cryp->req; in stm32_cryp_get_iv()
400 __be32 *tmp = (void *)req->iv; in stm32_cryp_get_iv()
405 *tmp++ = cpu_to_be32(stm32_cryp_read(cryp, CRYP_IV0LR)); in stm32_cryp_get_iv()
406 *tmp++ = cpu_to_be32(stm32_cryp_read(cryp, CRYP_IV0RR)); in stm32_cryp_get_iv()
408 if (is_aes(cryp)) { in stm32_cryp_get_iv()
409 *tmp++ = cpu_to_be32(stm32_cryp_read(cryp, CRYP_IV1LR)); in stm32_cryp_get_iv()
410 *tmp++ = cpu_to_be32(stm32_cryp_read(cryp, CRYP_IV1RR)); in stm32_cryp_get_iv()
420 stm32_cryp_write(c, CRYP_K1LR, be32_to_cpu(c->ctx->key[0])); in stm32_cryp_hw_write_key()
421 stm32_cryp_write(c, CRYP_K1RR, be32_to_cpu(c->ctx->key[1])); in stm32_cryp_hw_write_key()
424 for (i = c->ctx->keylen / sizeof(u32); i > 0; i--, r_id -= 4) in stm32_cryp_hw_write_key()
426 be32_to_cpu(c->ctx->key[i - 1])); in stm32_cryp_hw_write_key()
430 static u32 stm32_cryp_get_hw_mode(struct stm32_cryp *cryp) in stm32_cryp_get_hw_mode() argument
432 if (is_aes(cryp) && is_ecb(cryp)) in stm32_cryp_get_hw_mode()
435 if (is_aes(cryp) && is_cbc(cryp)) in stm32_cryp_get_hw_mode()
438 if (is_aes(cryp) && is_ctr(cryp)) in stm32_cryp_get_hw_mode()
441 if (is_aes(cryp) && is_gcm(cryp)) in stm32_cryp_get_hw_mode()
444 if (is_aes(cryp) && is_ccm(cryp)) in stm32_cryp_get_hw_mode()
447 if (is_des(cryp) && is_ecb(cryp)) in stm32_cryp_get_hw_mode()
450 if (is_des(cryp) && is_cbc(cryp)) in stm32_cryp_get_hw_mode()
453 if (is_tdes(cryp) && is_ecb(cryp)) in stm32_cryp_get_hw_mode()
456 if (is_tdes(cryp) && is_cbc(cryp)) in stm32_cryp_get_hw_mode()
459 dev_err(cryp->dev, "Unknown mode\n"); in stm32_cryp_get_hw_mode()
463 static unsigned int stm32_cryp_get_input_text_len(struct stm32_cryp *cryp) in stm32_cryp_get_input_text_len() argument
465 return is_encrypt(cryp) ? cryp->areq->cryptlen : in stm32_cryp_get_input_text_len()
466 cryp->areq->cryptlen - cryp->authsize; in stm32_cryp_get_input_text_len()
469 static int stm32_cryp_gcm_init(struct stm32_cryp *cryp, u32 cfg) in stm32_cryp_gcm_init() argument
475 memcpy(iv, cryp->areq->iv, 12); in stm32_cryp_gcm_init()
477 cryp->gcm_ctr = GCM_CTR_INIT; in stm32_cryp_gcm_init()
478 stm32_cryp_hw_write_iv(cryp, iv); in stm32_cryp_gcm_init()
480 stm32_cryp_write(cryp, CRYP_CR, cfg | CR_PH_INIT | CR_CRYPEN); in stm32_cryp_gcm_init()
483 ret = stm32_cryp_wait_enable(cryp); in stm32_cryp_gcm_init()
485 dev_err(cryp->dev, "Timeout (gcm init)\n"); in stm32_cryp_gcm_init()
490 static int stm32_cryp_ccm_init(struct stm32_cryp *cryp, u32 cfg) in stm32_cryp_ccm_init() argument
499 memcpy(iv, cryp->areq->iv, AES_BLOCK_SIZE); in stm32_cryp_ccm_init()
500 memset(iv + AES_BLOCK_SIZE - 1 - iv[0], 0, iv[0] + 1); in stm32_cryp_ccm_init()
501 iv[AES_BLOCK_SIZE - 1] = 1; in stm32_cryp_ccm_init()
502 stm32_cryp_hw_write_iv(cryp, (__be32 *)iv); in stm32_cryp_ccm_init()
507 b0[0] |= (8 * ((cryp->authsize - 2) / 2)); in stm32_cryp_ccm_init()
509 if (cryp->areq->assoclen) in stm32_cryp_ccm_init()
512 textlen = stm32_cryp_get_input_text_len(cryp); in stm32_cryp_ccm_init()
514 b0[AES_BLOCK_SIZE - 2] = textlen >> 8; in stm32_cryp_ccm_init()
515 b0[AES_BLOCK_SIZE - 1] = textlen & 0xFF; in stm32_cryp_ccm_init()
518 stm32_cryp_write(cryp, CRYP_CR, cfg | CR_PH_INIT | CR_CRYPEN); in stm32_cryp_ccm_init()
527 if (!cryp->caps->padding_wa) in stm32_cryp_ccm_init()
529 stm32_cryp_write(cryp, CRYP_DIN, xd); in stm32_cryp_ccm_init()
533 ret = stm32_cryp_wait_enable(cryp); in stm32_cryp_ccm_init()
535 dev_err(cryp->dev, "Timeout (ccm init)\n"); in stm32_cryp_ccm_init()
540 static int stm32_cryp_hw_init(struct stm32_cryp *cryp) in stm32_cryp_hw_init() argument
545 pm_runtime_get_sync(cryp->dev); in stm32_cryp_hw_init()
548 stm32_cryp_write(cryp, CRYP_IMSCR, 0); in stm32_cryp_hw_init()
551 stm32_cryp_hw_write_key(cryp); in stm32_cryp_hw_init()
556 switch (cryp->ctx->keylen) { in stm32_cryp_hw_init()
571 hw_mode = stm32_cryp_get_hw_mode(cryp); in stm32_cryp_hw_init()
573 return -EINVAL; in stm32_cryp_hw_init()
576 if (is_decrypt(cryp) && in stm32_cryp_hw_init()
578 stm32_cryp_write(cryp, CRYP_CR, cfg | CR_AES_KP | CR_CRYPEN); in stm32_cryp_hw_init()
581 ret = stm32_cryp_wait_busy(cryp); in stm32_cryp_hw_init()
583 dev_err(cryp->dev, "Timeout (key preparation)\n"); in stm32_cryp_hw_init()
590 if (is_decrypt(cryp)) in stm32_cryp_hw_init()
594 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_hw_init()
601 ret = stm32_cryp_ccm_init(cryp, cfg); in stm32_cryp_hw_init()
603 ret = stm32_cryp_gcm_init(cryp, cfg); in stm32_cryp_hw_init()
609 if (cryp->areq->assoclen) { in stm32_cryp_hw_init()
611 } else if (stm32_cryp_get_input_text_len(cryp)) { in stm32_cryp_hw_init()
613 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_hw_init()
624 stm32_cryp_hw_write_iv(cryp, (__be32 *)cryp->req->iv); in stm32_cryp_hw_init()
634 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_hw_init()
636 cryp->flags &= ~FLG_CCM_PADDED_WA; in stm32_cryp_hw_init()
641 static void stm32_cryp_finish_req(struct stm32_cryp *cryp, int err) in stm32_cryp_finish_req() argument
643 if (!err && (is_gcm(cryp) || is_ccm(cryp))) in stm32_cryp_finish_req()
645 err = stm32_cryp_read_auth_tag(cryp); in stm32_cryp_finish_req()
647 if (!err && (!(is_gcm(cryp) || is_ccm(cryp)))) in stm32_cryp_finish_req()
648 stm32_cryp_get_iv(cryp); in stm32_cryp_finish_req()
650 if (cryp->sgs_copied) { in stm32_cryp_finish_req()
654 buf_in = sg_virt(&cryp->in_sgl); in stm32_cryp_finish_req()
655 buf_out = sg_virt(&cryp->out_sgl); in stm32_cryp_finish_req()
657 sg_copy_buf(buf_out, cryp->out_sg_save, 0, in stm32_cryp_finish_req()
658 cryp->total_out_save, 1); in stm32_cryp_finish_req()
660 len = ALIGN(cryp->total_in_save, cryp->hw_blocksize); in stm32_cryp_finish_req()
664 len = ALIGN(cryp->total_out_save, cryp->hw_blocksize); in stm32_cryp_finish_req()
669 pm_runtime_mark_last_busy(cryp->dev); in stm32_cryp_finish_req()
670 pm_runtime_put_autosuspend(cryp->dev); in stm32_cryp_finish_req()
672 if (is_gcm(cryp) || is_ccm(cryp)) in stm32_cryp_finish_req()
673 crypto_finalize_aead_request(cryp->engine, cryp->areq, err); in stm32_cryp_finish_req()
675 crypto_finalize_skcipher_request(cryp->engine, cryp->req, in stm32_cryp_finish_req()
678 memset(cryp->ctx->key, 0, cryp->ctx->keylen); in stm32_cryp_finish_req()
681 static int stm32_cryp_cpu_start(struct stm32_cryp *cryp) in stm32_cryp_cpu_start() argument
684 stm32_cryp_write(cryp, CRYP_IMSCR, IMSCR_IN | IMSCR_OUT); in stm32_cryp_cpu_start()
699 ctx->enginectx.op.do_one_request = stm32_cryp_cipher_one_req; in stm32_cryp_init_tfm()
700 ctx->enginectx.op.prepare_request = stm32_cryp_prepare_cipher_req; in stm32_cryp_init_tfm()
701 ctx->enginectx.op.unprepare_request = NULL; in stm32_cryp_init_tfm()
713 tfm->reqsize = sizeof(struct stm32_cryp_reqctx); in stm32_cryp_aes_aead_init()
715 ctx->enginectx.op.do_one_request = stm32_cryp_aead_one_req; in stm32_cryp_aes_aead_init()
716 ctx->enginectx.op.prepare_request = stm32_cryp_prepare_aead_req; in stm32_cryp_aes_aead_init()
717 ctx->enginectx.op.unprepare_request = NULL; in stm32_cryp_aes_aead_init()
727 struct stm32_cryp *cryp = stm32_cryp_find_dev(ctx); in stm32_cryp_crypt() local
729 if (!cryp) in stm32_cryp_crypt()
730 return -ENODEV; in stm32_cryp_crypt()
732 rctx->mode = mode; in stm32_cryp_crypt()
734 return crypto_transfer_skcipher_request_to_engine(cryp->engine, req); in stm32_cryp_crypt()
741 struct stm32_cryp *cryp = stm32_cryp_find_dev(ctx); in stm32_cryp_aead_crypt() local
743 if (!cryp) in stm32_cryp_aead_crypt()
744 return -ENODEV; in stm32_cryp_aead_crypt()
746 rctx->mode = mode; in stm32_cryp_aead_crypt()
748 return crypto_transfer_aead_request_to_engine(cryp->engine, req); in stm32_cryp_aead_crypt()
756 memcpy(ctx->key, key, keylen); in stm32_cryp_setkey()
757 ctx->keylen = keylen; in stm32_cryp_setkey()
767 return -EINVAL; in stm32_cryp_aes_setkey()
793 return -EINVAL; in stm32_cryp_aes_aead_setkey()
795 memcpy(ctx->key, key, keylen); in stm32_cryp_aes_aead_setkey()
796 ctx->keylen = keylen; in stm32_cryp_aes_aead_setkey()
804 return authsize == AES_BLOCK_SIZE ? 0 : -EINVAL; in stm32_cryp_aes_gcm_setauthsize()
820 return -EINVAL; in stm32_cryp_aes_ccm_setauthsize()
920 struct stm32_cryp *cryp; in stm32_cryp_prepare_req() local
925 return -EINVAL; in stm32_cryp_prepare_req()
930 cryp = ctx->cryp; in stm32_cryp_prepare_req()
932 if (!cryp) in stm32_cryp_prepare_req()
933 return -ENODEV; in stm32_cryp_prepare_req()
936 rctx->mode &= FLG_MODE_MASK; in stm32_cryp_prepare_req()
938 ctx->cryp = cryp; in stm32_cryp_prepare_req()
940 cryp->flags = (cryp->flags & ~FLG_MODE_MASK) | rctx->mode; in stm32_cryp_prepare_req()
941 cryp->hw_blocksize = is_aes(cryp) ? AES_BLOCK_SIZE : DES_BLOCK_SIZE; in stm32_cryp_prepare_req()
942 cryp->ctx = ctx; in stm32_cryp_prepare_req()
945 cryp->req = req; in stm32_cryp_prepare_req()
946 cryp->areq = NULL; in stm32_cryp_prepare_req()
947 cryp->total_in = req->cryptlen; in stm32_cryp_prepare_req()
948 cryp->total_out = cryp->total_in; in stm32_cryp_prepare_req()
954 * <- assoclen -> <- cryptlen -> in stm32_cryp_prepare_req()
955 * <------- total_in -----------> in stm32_cryp_prepare_req()
958 * <- assoclen -> <- cryptlen -> <- authsize -> in stm32_cryp_prepare_req()
959 * <---------------- total_out -----------------> in stm32_cryp_prepare_req()
963 * <- assoclen -> <--------- cryptlen ---------> in stm32_cryp_prepare_req()
964 * <- authsize -> in stm32_cryp_prepare_req()
965 * <---------------- total_in ------------------> in stm32_cryp_prepare_req()
968 * <- assoclen -> <- crypten - authsize -> in stm32_cryp_prepare_req()
969 * <---------- total_out -----------------> in stm32_cryp_prepare_req()
971 cryp->areq = areq; in stm32_cryp_prepare_req()
972 cryp->req = NULL; in stm32_cryp_prepare_req()
973 cryp->authsize = crypto_aead_authsize(crypto_aead_reqtfm(areq)); in stm32_cryp_prepare_req()
974 cryp->total_in = areq->assoclen + areq->cryptlen; in stm32_cryp_prepare_req()
975 if (is_encrypt(cryp)) in stm32_cryp_prepare_req()
977 cryp->total_out = cryp->total_in + cryp->authsize; in stm32_cryp_prepare_req()
980 cryp->total_out = cryp->total_in - cryp->authsize; in stm32_cryp_prepare_req()
983 cryp->total_in_save = cryp->total_in; in stm32_cryp_prepare_req()
984 cryp->total_out_save = cryp->total_out; in stm32_cryp_prepare_req()
986 cryp->in_sg = req ? req->src : areq->src; in stm32_cryp_prepare_req()
987 cryp->out_sg = req ? req->dst : areq->dst; in stm32_cryp_prepare_req()
988 cryp->out_sg_save = cryp->out_sg; in stm32_cryp_prepare_req()
990 cryp->in_sg_len = sg_nents_for_len(cryp->in_sg, cryp->total_in); in stm32_cryp_prepare_req()
991 if (cryp->in_sg_len < 0) { in stm32_cryp_prepare_req()
992 dev_err(cryp->dev, "Cannot get in_sg_len\n"); in stm32_cryp_prepare_req()
993 ret = cryp->in_sg_len; in stm32_cryp_prepare_req()
997 cryp->out_sg_len = sg_nents_for_len(cryp->out_sg, cryp->total_out); in stm32_cryp_prepare_req()
998 if (cryp->out_sg_len < 0) { in stm32_cryp_prepare_req()
999 dev_err(cryp->dev, "Cannot get out_sg_len\n"); in stm32_cryp_prepare_req()
1000 ret = cryp->out_sg_len; in stm32_cryp_prepare_req()
1004 ret = stm32_cryp_copy_sgs(cryp); in stm32_cryp_prepare_req()
1008 scatterwalk_start(&cryp->in_walk, cryp->in_sg); in stm32_cryp_prepare_req()
1009 scatterwalk_start(&cryp->out_walk, cryp->out_sg); in stm32_cryp_prepare_req()
1011 if (is_gcm(cryp) || is_ccm(cryp)) { in stm32_cryp_prepare_req()
1013 scatterwalk_advance(&cryp->out_walk, cryp->areq->assoclen); in stm32_cryp_prepare_req()
1014 cryp->total_out -= cryp->areq->assoclen; in stm32_cryp_prepare_req()
1017 ret = stm32_cryp_hw_init(cryp); in stm32_cryp_prepare_req()
1038 struct stm32_cryp *cryp = ctx->cryp; in stm32_cryp_cipher_one_req() local
1040 if (!cryp) in stm32_cryp_cipher_one_req()
1041 return -ENODEV; in stm32_cryp_cipher_one_req()
1043 return stm32_cryp_cpu_start(cryp); in stm32_cryp_cipher_one_req()
1059 struct stm32_cryp *cryp = ctx->cryp; in stm32_cryp_aead_one_req() local
1061 if (!cryp) in stm32_cryp_aead_one_req()
1062 return -ENODEV; in stm32_cryp_aead_one_req()
1064 if (unlikely(!cryp->areq->assoclen && in stm32_cryp_aead_one_req()
1065 !stm32_cryp_get_input_text_len(cryp))) { in stm32_cryp_aead_one_req()
1067 stm32_cryp_finish_req(cryp, 0); in stm32_cryp_aead_one_req()
1071 return stm32_cryp_cpu_start(cryp); in stm32_cryp_aead_one_req()
1074 static u32 *stm32_cryp_next_out(struct stm32_cryp *cryp, u32 *dst, in stm32_cryp_next_out() argument
1077 scatterwalk_advance(&cryp->out_walk, n); in stm32_cryp_next_out()
1079 if (unlikely(cryp->out_sg->length == _walked_out)) { in stm32_cryp_next_out()
1080 cryp->out_sg = sg_next(cryp->out_sg); in stm32_cryp_next_out()
1081 if (cryp->out_sg) { in stm32_cryp_next_out()
1082 scatterwalk_start(&cryp->out_walk, cryp->out_sg); in stm32_cryp_next_out()
1083 return (sg_virt(cryp->out_sg) + _walked_out); in stm32_cryp_next_out()
1090 static u32 *stm32_cryp_next_in(struct stm32_cryp *cryp, u32 *src, in stm32_cryp_next_in() argument
1093 scatterwalk_advance(&cryp->in_walk, n); in stm32_cryp_next_in()
1095 if (unlikely(cryp->in_sg->length == _walked_in)) { in stm32_cryp_next_in()
1096 cryp->in_sg = sg_next(cryp->in_sg); in stm32_cryp_next_in()
1097 if (cryp->in_sg) { in stm32_cryp_next_in()
1098 scatterwalk_start(&cryp->in_walk, cryp->in_sg); in stm32_cryp_next_in()
1099 return (sg_virt(cryp->in_sg) + _walked_in); in stm32_cryp_next_in()
1106 static int stm32_cryp_read_auth_tag(struct stm32_cryp *cryp) in stm32_cryp_read_auth_tag() argument
1114 cfg = stm32_cryp_read(cryp, CRYP_CR); in stm32_cryp_read_auth_tag()
1121 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_read_auth_tag()
1123 if (is_gcm(cryp)) { in stm32_cryp_read_auth_tag()
1125 size_bit = cryp->areq->assoclen * 8; in stm32_cryp_read_auth_tag()
1126 if (cryp->caps->swap_final) in stm32_cryp_read_auth_tag()
1129 stm32_cryp_write(cryp, CRYP_DIN, 0); in stm32_cryp_read_auth_tag()
1130 stm32_cryp_write(cryp, CRYP_DIN, size_bit); in stm32_cryp_read_auth_tag()
1132 size_bit = is_encrypt(cryp) ? cryp->areq->cryptlen : in stm32_cryp_read_auth_tag()
1133 cryp->areq->cryptlen - AES_BLOCK_SIZE; in stm32_cryp_read_auth_tag()
1135 if (cryp->caps->swap_final) in stm32_cryp_read_auth_tag()
1138 stm32_cryp_write(cryp, CRYP_DIN, 0); in stm32_cryp_read_auth_tag()
1139 stm32_cryp_write(cryp, CRYP_DIN, size_bit); in stm32_cryp_read_auth_tag()
1148 memcpy(iv, cryp->areq->iv, AES_BLOCK_SIZE); in stm32_cryp_read_auth_tag()
1149 memset(iv + AES_BLOCK_SIZE - 1 - iv[0], 0, iv[0] + 1); in stm32_cryp_read_auth_tag()
1154 if (!cryp->caps->padding_wa) in stm32_cryp_read_auth_tag()
1156 stm32_cryp_write(cryp, CRYP_DIN, xiv); in stm32_cryp_read_auth_tag()
1161 ret = stm32_cryp_wait_output(cryp); in stm32_cryp_read_auth_tag()
1163 dev_err(cryp->dev, "Timeout (read tag)\n"); in stm32_cryp_read_auth_tag()
1167 if (is_encrypt(cryp)) { in stm32_cryp_read_auth_tag()
1169 dst = sg_virt(cryp->out_sg) + _walked_out; in stm32_cryp_read_auth_tag()
1172 if (cryp->total_out >= sizeof(u32)) { in stm32_cryp_read_auth_tag()
1174 *dst = stm32_cryp_read(cryp, CRYP_DOUT); in stm32_cryp_read_auth_tag()
1176 dst = stm32_cryp_next_out(cryp, dst, in stm32_cryp_read_auth_tag()
1178 cryp->total_out -= sizeof(u32); in stm32_cryp_read_auth_tag()
1179 } else if (!cryp->total_out) { in stm32_cryp_read_auth_tag()
1181 stm32_cryp_read(cryp, CRYP_DOUT); in stm32_cryp_read_auth_tag()
1184 d32 = stm32_cryp_read(cryp, CRYP_DOUT); in stm32_cryp_read_auth_tag()
1187 for (j = 0; j < cryp->total_out; j++) { in stm32_cryp_read_auth_tag()
1189 dst = stm32_cryp_next_out(cryp, dst, 1); in stm32_cryp_read_auth_tag()
1191 cryp->total_out = 0; in stm32_cryp_read_auth_tag()
1198 scatterwalk_map_and_copy(in_tag, cryp->in_sg, in stm32_cryp_read_auth_tag()
1199 cryp->total_in_save - cryp->authsize, in stm32_cryp_read_auth_tag()
1200 cryp->authsize, 0); in stm32_cryp_read_auth_tag()
1203 out_tag[i] = stm32_cryp_read(cryp, CRYP_DOUT); in stm32_cryp_read_auth_tag()
1205 if (crypto_memneq(in_tag, out_tag, cryp->authsize)) in stm32_cryp_read_auth_tag()
1206 ret = -EBADMSG; in stm32_cryp_read_auth_tag()
1209 /* Disable cryp */ in stm32_cryp_read_auth_tag()
1211 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_read_auth_tag()
1216 static void stm32_cryp_check_ctr_counter(struct stm32_cryp *cryp) in stm32_cryp_check_ctr_counter() argument
1220 if (unlikely(cryp->last_ctr[3] == 0xFFFFFFFF)) { in stm32_cryp_check_ctr_counter()
1221 cryp->last_ctr[3] = 0; in stm32_cryp_check_ctr_counter()
1222 cryp->last_ctr[2]++; in stm32_cryp_check_ctr_counter()
1223 if (!cryp->last_ctr[2]) { in stm32_cryp_check_ctr_counter()
1224 cryp->last_ctr[1]++; in stm32_cryp_check_ctr_counter()
1225 if (!cryp->last_ctr[1]) in stm32_cryp_check_ctr_counter()
1226 cryp->last_ctr[0]++; in stm32_cryp_check_ctr_counter()
1229 cr = stm32_cryp_read(cryp, CRYP_CR); in stm32_cryp_check_ctr_counter()
1230 stm32_cryp_write(cryp, CRYP_CR, cr & ~CR_CRYPEN); in stm32_cryp_check_ctr_counter()
1232 stm32_cryp_hw_write_iv(cryp, (u32 *)cryp->last_ctr); in stm32_cryp_check_ctr_counter()
1234 stm32_cryp_write(cryp, CRYP_CR, cr); in stm32_cryp_check_ctr_counter()
1237 cryp->last_ctr[0] = stm32_cryp_read(cryp, CRYP_IV0LR); in stm32_cryp_check_ctr_counter()
1238 cryp->last_ctr[1] = stm32_cryp_read(cryp, CRYP_IV0RR); in stm32_cryp_check_ctr_counter()
1239 cryp->last_ctr[2] = stm32_cryp_read(cryp, CRYP_IV1LR); in stm32_cryp_check_ctr_counter()
1240 cryp->last_ctr[3] = stm32_cryp_read(cryp, CRYP_IV1RR); in stm32_cryp_check_ctr_counter()
1243 static bool stm32_cryp_irq_read_data(struct stm32_cryp *cryp) in stm32_cryp_irq_read_data() argument
1251 if (is_encrypt(cryp) && (is_gcm(cryp) || is_ccm(cryp))) in stm32_cryp_irq_read_data()
1252 tag_size = cryp->authsize; in stm32_cryp_irq_read_data()
1256 dst = sg_virt(cryp->out_sg) + _walked_out; in stm32_cryp_irq_read_data()
1258 for (i = 0; i < cryp->hw_blocksize / sizeof(u32); i++) { in stm32_cryp_irq_read_data()
1259 if (likely(cryp->total_out - tag_size >= sizeof(u32))) { in stm32_cryp_irq_read_data()
1261 *dst = stm32_cryp_read(cryp, CRYP_DOUT); in stm32_cryp_irq_read_data()
1263 dst = stm32_cryp_next_out(cryp, dst, sizeof(u32)); in stm32_cryp_irq_read_data()
1264 cryp->total_out -= sizeof(u32); in stm32_cryp_irq_read_data()
1265 } else if (cryp->total_out == tag_size) { in stm32_cryp_irq_read_data()
1267 d32 = stm32_cryp_read(cryp, CRYP_DOUT); in stm32_cryp_irq_read_data()
1270 d32 = stm32_cryp_read(cryp, CRYP_DOUT); in stm32_cryp_irq_read_data()
1273 for (j = 0; j < cryp->total_out - tag_size; j++) { in stm32_cryp_irq_read_data()
1275 dst = stm32_cryp_next_out(cryp, dst, 1); in stm32_cryp_irq_read_data()
1277 cryp->total_out = tag_size; in stm32_cryp_irq_read_data()
1281 return !(cryp->total_out - tag_size) || !cryp->total_in; in stm32_cryp_irq_read_data()
1284 static void stm32_cryp_irq_write_block(struct stm32_cryp *cryp) in stm32_cryp_irq_write_block() argument
1292 if (is_decrypt(cryp) && (is_gcm(cryp) || is_ccm(cryp))) in stm32_cryp_irq_write_block()
1293 tag_size = cryp->authsize; in stm32_cryp_irq_write_block()
1297 src = sg_virt(cryp->in_sg) + _walked_in; in stm32_cryp_irq_write_block()
1299 for (i = 0; i < cryp->hw_blocksize / sizeof(u32); i++) { in stm32_cryp_irq_write_block()
1300 if (likely(cryp->total_in - tag_size >= sizeof(u32))) { in stm32_cryp_irq_write_block()
1302 stm32_cryp_write(cryp, CRYP_DIN, *src); in stm32_cryp_irq_write_block()
1304 src = stm32_cryp_next_in(cryp, src, sizeof(u32)); in stm32_cryp_irq_write_block()
1305 cryp->total_in -= sizeof(u32); in stm32_cryp_irq_write_block()
1306 } else if (cryp->total_in == tag_size) { in stm32_cryp_irq_write_block()
1308 stm32_cryp_write(cryp, CRYP_DIN, 0); in stm32_cryp_irq_write_block()
1312 for (j = 0; j < cryp->total_in - tag_size; j++) { in stm32_cryp_irq_write_block()
1314 src = stm32_cryp_next_in(cryp, src, 1); in stm32_cryp_irq_write_block()
1317 stm32_cryp_write(cryp, CRYP_DIN, *(u32 *)d8); in stm32_cryp_irq_write_block()
1318 cryp->total_in = tag_size; in stm32_cryp_irq_write_block()
1323 static void stm32_cryp_irq_write_gcm_padded_data(struct stm32_cryp *cryp) in stm32_cryp_irq_write_gcm_padded_data() argument
1327 size_t total_in_ori = cryp->total_in; in stm32_cryp_irq_write_gcm_padded_data()
1328 struct scatterlist *out_sg_ori = cryp->out_sg; in stm32_cryp_irq_write_gcm_padded_data()
1334 stm32_cryp_write(cryp, CRYP_IMSCR, 0); in stm32_cryp_irq_write_gcm_padded_data()
1335 cfg = stm32_cryp_read(cryp, CRYP_CR); in stm32_cryp_irq_write_gcm_padded_data()
1337 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_gcm_padded_data()
1340 stm32_cryp_write(cryp, CRYP_IV1RR, cryp->gcm_ctr - 2); in stm32_cryp_irq_write_gcm_padded_data()
1345 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_gcm_padded_data()
1349 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_gcm_padded_data()
1352 stm32_cryp_irq_write_block(cryp); in stm32_cryp_irq_write_gcm_padded_data()
1353 cryp->total_in = total_in_ori; in stm32_cryp_irq_write_gcm_padded_data()
1354 err = stm32_cryp_wait_output(cryp); in stm32_cryp_irq_write_gcm_padded_data()
1356 dev_err(cryp->dev, "Timeout (write gcm header)\n"); in stm32_cryp_irq_write_gcm_padded_data()
1357 return stm32_cryp_finish_req(cryp, err); in stm32_cryp_irq_write_gcm_padded_data()
1361 stm32_cryp_irq_read_data(cryp); in stm32_cryp_irq_write_gcm_padded_data()
1363 cryp->total_in_save - total_in_ori, in stm32_cryp_irq_write_gcm_padded_data()
1369 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_gcm_padded_data()
1374 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_gcm_padded_data()
1378 if (cryp->total_in) in stm32_cryp_irq_write_gcm_padded_data()
1379 stm32_cryp_write(cryp, CRYP_DIN, tmp[i]); in stm32_cryp_irq_write_gcm_padded_data()
1381 stm32_cryp_write(cryp, CRYP_DIN, 0); in stm32_cryp_irq_write_gcm_padded_data()
1383 cryp->total_in -= min_t(size_t, sizeof(u32), cryp->total_in); in stm32_cryp_irq_write_gcm_padded_data()
1387 err = stm32_cryp_wait_output(cryp); in stm32_cryp_irq_write_gcm_padded_data()
1389 dev_err(cryp->dev, "Timeout (write gcm header)\n"); in stm32_cryp_irq_write_gcm_padded_data()
1390 return stm32_cryp_finish_req(cryp, err); in stm32_cryp_irq_write_gcm_padded_data()
1394 stm32_cryp_read(cryp, CRYP_DOUT); in stm32_cryp_irq_write_gcm_padded_data()
1397 stm32_cryp_finish_req(cryp, 0); in stm32_cryp_irq_write_gcm_padded_data()
1400 static void stm32_cryp_irq_set_npblb(struct stm32_cryp *cryp) in stm32_cryp_irq_set_npblb() argument
1405 cfg = stm32_cryp_read(cryp, CRYP_CR); in stm32_cryp_irq_set_npblb()
1407 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_set_npblb()
1409 payload_bytes = is_decrypt(cryp) ? cryp->total_in - cryp->authsize : in stm32_cryp_irq_set_npblb()
1410 cryp->total_in; in stm32_cryp_irq_set_npblb()
1411 cfg |= (cryp->hw_blocksize - payload_bytes) << CR_NBPBL_SHIFT; in stm32_cryp_irq_set_npblb()
1413 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_set_npblb()
1416 static void stm32_cryp_irq_write_ccm_padded_data(struct stm32_cryp *cryp) in stm32_cryp_irq_write_ccm_padded_data() argument
1421 size_t last_total_out, total_in_ori = cryp->total_in; in stm32_cryp_irq_write_ccm_padded_data()
1422 struct scatterlist *out_sg_ori = cryp->out_sg; in stm32_cryp_irq_write_ccm_padded_data()
1426 cryp->flags |= FLG_CCM_PADDED_WA; in stm32_cryp_irq_write_ccm_padded_data()
1429 stm32_cryp_write(cryp, CRYP_IMSCR, 0); in stm32_cryp_irq_write_ccm_padded_data()
1431 cfg = stm32_cryp_read(cryp, CRYP_CR); in stm32_cryp_irq_write_ccm_padded_data()
1433 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_ccm_padded_data()
1436 iv1tmp = stm32_cryp_read(cryp, CRYP_CSGCMCCM0R + 7 * 4); in stm32_cryp_irq_write_ccm_padded_data()
1440 cstmp1[i] = stm32_cryp_read(cryp, CRYP_CSGCMCCM0R + i * 4); in stm32_cryp_irq_write_ccm_padded_data()
1443 stm32_cryp_write(cryp, CRYP_IV1RR, iv1tmp); in stm32_cryp_irq_write_ccm_padded_data()
1448 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_ccm_padded_data()
1452 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_ccm_padded_data()
1455 stm32_cryp_irq_write_block(cryp); in stm32_cryp_irq_write_ccm_padded_data()
1456 cryp->total_in = total_in_ori; in stm32_cryp_irq_write_ccm_padded_data()
1457 err = stm32_cryp_wait_output(cryp); in stm32_cryp_irq_write_ccm_padded_data()
1459 dev_err(cryp->dev, "Timeout (wite ccm padded data)\n"); in stm32_cryp_irq_write_ccm_padded_data()
1460 return stm32_cryp_finish_req(cryp, err); in stm32_cryp_irq_write_ccm_padded_data()
1464 last_total_out = cryp->total_out; in stm32_cryp_irq_write_ccm_padded_data()
1465 stm32_cryp_irq_read_data(cryp); in stm32_cryp_irq_write_ccm_padded_data()
1469 cryp->total_out_save - last_total_out, in stm32_cryp_irq_write_ccm_padded_data()
1474 cstmp2[i] = stm32_cryp_read(cryp, CRYP_CSGCMCCM0R + i * 4); in stm32_cryp_irq_write_ccm_padded_data()
1479 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_ccm_padded_data()
1484 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_ccm_padded_data()
1490 stm32_cryp_write(cryp, CRYP_DIN, tmp[i]); in stm32_cryp_irq_write_ccm_padded_data()
1494 err = stm32_cryp_wait_busy(cryp); in stm32_cryp_irq_write_ccm_padded_data()
1496 dev_err(cryp->dev, "Timeout (wite ccm padded data)\n"); in stm32_cryp_irq_write_ccm_padded_data()
1499 stm32_cryp_finish_req(cryp, err); in stm32_cryp_irq_write_ccm_padded_data()
1502 static void stm32_cryp_irq_write_data(struct stm32_cryp *cryp) in stm32_cryp_irq_write_data() argument
1504 if (unlikely(!cryp->total_in)) { in stm32_cryp_irq_write_data()
1505 dev_warn(cryp->dev, "No more data to process\n"); in stm32_cryp_irq_write_data()
1509 if (unlikely(cryp->total_in < AES_BLOCK_SIZE && in stm32_cryp_irq_write_data()
1510 (stm32_cryp_get_hw_mode(cryp) == CR_AES_GCM) && in stm32_cryp_irq_write_data()
1511 is_encrypt(cryp))) { in stm32_cryp_irq_write_data()
1513 if (cryp->caps->padding_wa) in stm32_cryp_irq_write_data()
1515 return stm32_cryp_irq_write_gcm_padded_data(cryp); in stm32_cryp_irq_write_data()
1518 stm32_cryp_irq_set_npblb(cryp); in stm32_cryp_irq_write_data()
1521 if (unlikely((cryp->total_in - cryp->authsize < AES_BLOCK_SIZE) && in stm32_cryp_irq_write_data()
1522 (stm32_cryp_get_hw_mode(cryp) == CR_AES_CCM) && in stm32_cryp_irq_write_data()
1523 is_decrypt(cryp))) { in stm32_cryp_irq_write_data()
1525 if (cryp->caps->padding_wa) in stm32_cryp_irq_write_data()
1527 return stm32_cryp_irq_write_ccm_padded_data(cryp); in stm32_cryp_irq_write_data()
1530 stm32_cryp_irq_set_npblb(cryp); in stm32_cryp_irq_write_data()
1533 if (is_aes(cryp) && is_ctr(cryp)) in stm32_cryp_irq_write_data()
1534 stm32_cryp_check_ctr_counter(cryp); in stm32_cryp_irq_write_data()
1536 stm32_cryp_irq_write_block(cryp); in stm32_cryp_irq_write_data()
1539 static void stm32_cryp_irq_write_gcm_header(struct stm32_cryp *cryp) in stm32_cryp_irq_write_gcm_header() argument
1545 src = sg_virt(cryp->in_sg) + _walked_in; in stm32_cryp_irq_write_gcm_header()
1548 stm32_cryp_write(cryp, CRYP_DIN, *src); in stm32_cryp_irq_write_gcm_header()
1550 src = stm32_cryp_next_in(cryp, src, sizeof(u32)); in stm32_cryp_irq_write_gcm_header()
1551 cryp->total_in -= min_t(size_t, sizeof(u32), cryp->total_in); in stm32_cryp_irq_write_gcm_header()
1554 if ((cryp->total_in_save - cryp->total_in) == in stm32_cryp_irq_write_gcm_header()
1555 cryp->areq->assoclen) { in stm32_cryp_irq_write_gcm_header()
1558 stm32_cryp_write(cryp, CRYP_DIN, 0); in stm32_cryp_irq_write_gcm_header()
1561 err = stm32_cryp_wait_busy(cryp); in stm32_cryp_irq_write_gcm_header()
1563 dev_err(cryp->dev, "Timeout (gcm header)\n"); in stm32_cryp_irq_write_gcm_header()
1564 return stm32_cryp_finish_req(cryp, err); in stm32_cryp_irq_write_gcm_header()
1567 if (stm32_cryp_get_input_text_len(cryp)) { in stm32_cryp_irq_write_gcm_header()
1569 cfg = stm32_cryp_read(cryp, CRYP_CR); in stm32_cryp_irq_write_gcm_header()
1571 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_gcm_header()
1576 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_gcm_header()
1579 stm32_cryp_write(cryp, CRYP_IMSCR, 0); in stm32_cryp_irq_write_gcm_header()
1580 stm32_cryp_finish_req(cryp, 0); in stm32_cryp_irq_write_gcm_header()
1586 if (!cryp->total_in) in stm32_cryp_irq_write_gcm_header()
1591 static void stm32_cryp_irq_write_ccm_header(struct stm32_cryp *cryp) in stm32_cryp_irq_write_ccm_header() argument
1598 src = sg_virt(cryp->in_sg) + _walked_in; in stm32_cryp_irq_write_ccm_header()
1599 alen = cryp->areq->assoclen; in stm32_cryp_irq_write_ccm_header()
1602 if (cryp->areq->assoclen <= 65280) { in stm32_cryp_irq_write_ccm_header()
1607 src = stm32_cryp_next_in(cryp, src, 1); in stm32_cryp_irq_write_ccm_header()
1609 src = stm32_cryp_next_in(cryp, src, 1); in stm32_cryp_irq_write_ccm_header()
1611 stm32_cryp_write(cryp, CRYP_DIN, *(u32 *)d8); in stm32_cryp_irq_write_ccm_header()
1614 cryp->total_in -= min_t(size_t, 2, cryp->total_in); in stm32_cryp_irq_write_ccm_header()
1622 stm32_cryp_write(cryp, CRYP_DIN, *(u32 *)d8); in stm32_cryp_irq_write_ccm_header()
1628 src = stm32_cryp_next_in(cryp, src, 1); in stm32_cryp_irq_write_ccm_header()
1630 src = stm32_cryp_next_in(cryp, src, 1); in stm32_cryp_irq_write_ccm_header()
1632 stm32_cryp_write(cryp, CRYP_DIN, *(u32 *)d8); in stm32_cryp_irq_write_ccm_header()
1635 cryp->total_in -= min_t(size_t, 2, cryp->total_in); in stm32_cryp_irq_write_ccm_header()
1645 src = stm32_cryp_next_in(cryp, src, 1); in stm32_cryp_irq_write_ccm_header()
1647 cryp->total_in -= min_t(size_t, 1, cryp->total_in); in stm32_cryp_irq_write_ccm_header()
1648 if ((cryp->total_in_save - cryp->total_in) == alen) in stm32_cryp_irq_write_ccm_header()
1652 stm32_cryp_write(cryp, CRYP_DIN, *(u32 *)d8); in stm32_cryp_irq_write_ccm_header()
1654 if ((cryp->total_in_save - cryp->total_in) == alen) { in stm32_cryp_irq_write_ccm_header()
1657 stm32_cryp_write(cryp, CRYP_DIN, 0); in stm32_cryp_irq_write_ccm_header()
1660 err = stm32_cryp_wait_busy(cryp); in stm32_cryp_irq_write_ccm_header()
1662 dev_err(cryp->dev, "Timeout (ccm header)\n"); in stm32_cryp_irq_write_ccm_header()
1663 return stm32_cryp_finish_req(cryp, err); in stm32_cryp_irq_write_ccm_header()
1666 if (stm32_cryp_get_input_text_len(cryp)) { in stm32_cryp_irq_write_ccm_header()
1668 cfg = stm32_cryp_read(cryp, CRYP_CR); in stm32_cryp_irq_write_ccm_header()
1670 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_ccm_header()
1675 stm32_cryp_write(cryp, CRYP_CR, cfg); in stm32_cryp_irq_write_ccm_header()
1678 stm32_cryp_write(cryp, CRYP_IMSCR, 0); in stm32_cryp_irq_write_ccm_header()
1679 stm32_cryp_finish_req(cryp, 0); in stm32_cryp_irq_write_ccm_header()
1689 struct stm32_cryp *cryp = arg; in stm32_cryp_irq_thread() local
1692 if (cryp->irq_status & MISR_OUT) in stm32_cryp_irq_thread()
1694 if (unlikely(stm32_cryp_irq_read_data(cryp))) { in stm32_cryp_irq_thread()
1696 stm32_cryp_write(cryp, CRYP_IMSCR, 0); in stm32_cryp_irq_thread()
1697 stm32_cryp_finish_req(cryp, 0); in stm32_cryp_irq_thread()
1701 if (cryp->irq_status & MISR_IN) { in stm32_cryp_irq_thread()
1702 if (is_gcm(cryp)) { in stm32_cryp_irq_thread()
1703 ph = stm32_cryp_read(cryp, CRYP_CR) & CR_PH_MASK; in stm32_cryp_irq_thread()
1706 stm32_cryp_irq_write_gcm_header(cryp); in stm32_cryp_irq_thread()
1709 stm32_cryp_irq_write_data(cryp); in stm32_cryp_irq_thread()
1710 cryp->gcm_ctr++; in stm32_cryp_irq_thread()
1711 } else if (is_ccm(cryp)) { in stm32_cryp_irq_thread()
1712 ph = stm32_cryp_read(cryp, CRYP_CR) & CR_PH_MASK; in stm32_cryp_irq_thread()
1715 stm32_cryp_irq_write_ccm_header(cryp); in stm32_cryp_irq_thread()
1718 stm32_cryp_irq_write_data(cryp); in stm32_cryp_irq_thread()
1721 stm32_cryp_irq_write_data(cryp); in stm32_cryp_irq_thread()
1730 struct stm32_cryp *cryp = arg; in stm32_cryp_irq() local
1732 cryp->irq_status = stm32_cryp_read(cryp, CRYP_MISR); in stm32_cryp_irq()
1740 .base.cra_driver_name = "stm32-ecb-aes",
1757 .base.cra_driver_name = "stm32-cbc-aes",
1775 .base.cra_driver_name = "stm32-ctr-aes",
1793 .base.cra_driver_name = "stm32-ecb-des",
1810 .base.cra_driver_name = "stm32-cbc-des",
1828 .base.cra_driver_name = "stm32-ecb-des3",
1845 .base.cra_driver_name = "stm32-cbc-des3",
1875 .cra_driver_name = "stm32-gcm-aes",
1895 .cra_driver_name = "stm32-ccm-aes",
1917 { .compatible = "st,stm32f756-cryp", .data = &f7_data},
1918 { .compatible = "st,stm32mp1-cryp", .data = &mp1_data},
1925 struct device *dev = &pdev->dev; in stm32_cryp_probe()
1926 struct stm32_cryp *cryp; in stm32_cryp_probe() local
1930 cryp = devm_kzalloc(dev, sizeof(*cryp), GFP_KERNEL); in stm32_cryp_probe()
1931 if (!cryp) in stm32_cryp_probe()
1932 return -ENOMEM; in stm32_cryp_probe()
1934 cryp->caps = of_device_get_match_data(dev); in stm32_cryp_probe()
1935 if (!cryp->caps) in stm32_cryp_probe()
1936 return -ENODEV; in stm32_cryp_probe()
1938 cryp->dev = dev; in stm32_cryp_probe()
1940 cryp->regs = devm_platform_ioremap_resource(pdev, 0); in stm32_cryp_probe()
1941 if (IS_ERR(cryp->regs)) in stm32_cryp_probe()
1942 return PTR_ERR(cryp->regs); in stm32_cryp_probe()
1950 dev_name(dev), cryp); in stm32_cryp_probe()
1956 cryp->clk = devm_clk_get(dev, NULL); in stm32_cryp_probe()
1957 if (IS_ERR(cryp->clk)) { in stm32_cryp_probe()
1959 return PTR_ERR(cryp->clk); in stm32_cryp_probe()
1962 ret = clk_prepare_enable(cryp->clk); in stm32_cryp_probe()
1964 dev_err(cryp->dev, "Failed to enable clock\n"); in stm32_cryp_probe()
1982 platform_set_drvdata(pdev, cryp); in stm32_cryp_probe()
1985 list_add(&cryp->list, &cryp_list.dev_list); in stm32_cryp_probe()
1989 cryp->engine = crypto_engine_alloc_init(dev, 1); in stm32_cryp_probe()
1990 if (!cryp->engine) { in stm32_cryp_probe()
1992 ret = -ENOMEM; in stm32_cryp_probe()
1996 ret = crypto_engine_start(cryp->engine); in stm32_cryp_probe()
2022 crypto_engine_exit(cryp->engine); in stm32_cryp_probe()
2025 list_del(&cryp->list); in stm32_cryp_probe()
2033 clk_disable_unprepare(cryp->clk); in stm32_cryp_probe()
2040 struct stm32_cryp *cryp = platform_get_drvdata(pdev); in stm32_cryp_remove() local
2043 if (!cryp) in stm32_cryp_remove()
2044 return -ENODEV; in stm32_cryp_remove()
2046 ret = pm_runtime_get_sync(cryp->dev); in stm32_cryp_remove()
2053 crypto_engine_exit(cryp->engine); in stm32_cryp_remove()
2056 list_del(&cryp->list); in stm32_cryp_remove()
2059 pm_runtime_disable(cryp->dev); in stm32_cryp_remove()
2060 pm_runtime_put_noidle(cryp->dev); in stm32_cryp_remove()
2062 clk_disable_unprepare(cryp->clk); in stm32_cryp_remove()
2070 struct stm32_cryp *cryp = dev_get_drvdata(dev); in stm32_cryp_runtime_suspend() local
2072 clk_disable_unprepare(cryp->clk); in stm32_cryp_runtime_suspend()
2079 struct stm32_cryp *cryp = dev_get_drvdata(dev); in stm32_cryp_runtime_resume() local
2082 ret = clk_prepare_enable(cryp->clk); in stm32_cryp_runtime_resume()
2084 dev_err(cryp->dev, "Failed to prepare_enable clock\n"); in stm32_cryp_runtime_resume()
2112 MODULE_DESCRIPTION("STMicrolectronics STM32 CRYP hardware driver");