aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/nx/nx-aes-ecb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/crypto/nx/nx-aes-ecb.c')
-rw-r--r--drivers/crypto/nx/nx-aes-ecb.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/drivers/crypto/nx/nx-aes-ecb.c b/drivers/crypto/nx/nx-aes-ecb.c
index 7bbc9a81da21..85a8d23cf29d 100644
--- a/drivers/crypto/nx/nx-aes-ecb.c
+++ b/drivers/crypto/nx/nx-aes-ecb.c
@@ -70,34 +70,52 @@ static int ecb_aes_nx_crypt(struct blkcipher_desc *desc,
70{ 70{
71 struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm); 71 struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm);
72 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; 72 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb;
73 unsigned long irq_flags;
74 unsigned int processed = 0, to_process;
75 u32 max_sg_len;
73 int rc; 76 int rc;
74 77
75 if (nbytes > nx_ctx->ap->databytelen) 78 spin_lock_irqsave(&nx_ctx->lock, irq_flags);
76 return -EINVAL; 79
80 max_sg_len = min_t(u32, nx_driver.of.max_sg_len/sizeof(struct nx_sg),
81 nx_ctx->ap->sglen);
77 82
78 if (enc) 83 if (enc)
79 NX_CPB_FDM(csbcpb) |= NX_FDM_ENDE_ENCRYPT; 84 NX_CPB_FDM(csbcpb) |= NX_FDM_ENDE_ENCRYPT;
80 else 85 else
81 NX_CPB_FDM(csbcpb) &= ~NX_FDM_ENDE_ENCRYPT; 86 NX_CPB_FDM(csbcpb) &= ~NX_FDM_ENDE_ENCRYPT;
82 87
83 rc = nx_build_sg_lists(nx_ctx, desc, dst, src, nbytes, NULL); 88 do {
84 if (rc) 89 to_process = min_t(u64, nbytes - processed,
85 goto out; 90 nx_ctx->ap->databytelen);
91 to_process = min_t(u64, to_process,
92 NX_PAGE_SIZE * (max_sg_len - 1));
93 to_process = to_process & ~(AES_BLOCK_SIZE - 1);
86 94
87 if (!nx_ctx->op.inlen || !nx_ctx->op.outlen) { 95 rc = nx_build_sg_lists(nx_ctx, desc, dst, src, to_process,
88 rc = -EINVAL; 96 processed, NULL);
89 goto out; 97 if (rc)
90 } 98 goto out;
99
100 if (!nx_ctx->op.inlen || !nx_ctx->op.outlen) {
101 rc = -EINVAL;
102 goto out;
103 }
104
105 rc = nx_hcall_sync(nx_ctx, &nx_ctx->op,
106 desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP);
107 if (rc)
108 goto out;
109
110 atomic_inc(&(nx_ctx->stats->aes_ops));
111 atomic64_add(csbcpb->csb.processed_byte_count,
112 &(nx_ctx->stats->aes_bytes));
91 113
92 rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, 114 processed += to_process;
93 desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP); 115 } while (processed < nbytes);
94 if (rc)
95 goto out;
96 116
97 atomic_inc(&(nx_ctx->stats->aes_ops));
98 atomic64_add(csbcpb->csb.processed_byte_count,
99 &(nx_ctx->stats->aes_bytes));
100out: 117out:
118 spin_unlock_irqrestore(&nx_ctx->lock, irq_flags);
101 return rc; 119 return rc;
102} 120}
103 121