aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/nx
diff options
context:
space:
mode:
authorMarcelo Cerri <mhcerri@linux.vnet.ibm.com>2013-08-29 10:36:32 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2013-09-02 06:32:52 -0400
commitab74175938c0cd819733e68f5848bb4c818ec7aa (patch)
tree3529686cef29c5f33cd52cadfd883f4c53128c54 /drivers/crypto/nx
parenta8fc391a15957e2f2871c4ea3f6e84c33095c374 (diff)
crypto: nx - fix limits to sg lists for AES-ECB
This patch updates the nx-aes-ecb implementation to perform several hyper calls if needed in order to always respect the length limits for scatter/gather lists. Two different limits are considered: - "ibm,max-sg-len": maximum number of bytes of each scatter/gather list. - "ibm,max-sync-cop": - The total number of bytes that a scatter/gather list can hold. - The maximum number of elements that a scatter/gather list can have. Reviewed-by: Joy Latten <jmlatten@linux.vnet.ibm.com> Signed-off-by: Marcelo Cerri <mhcerri@linux.vnet.ibm.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/nx')
-rw-r--r--drivers/crypto/nx/nx-aes-ecb.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/drivers/crypto/nx/nx-aes-ecb.c b/drivers/crypto/nx/nx-aes-ecb.c
index fe0d803ed233..85a8d23cf29d 100644
--- a/drivers/crypto/nx/nx-aes-ecb.c
+++ b/drivers/crypto/nx/nx-aes-ecb.c
@@ -71,37 +71,49 @@ static int ecb_aes_nx_crypt(struct blkcipher_desc *desc,
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; 73 unsigned long irq_flags;
74 unsigned int processed = 0, to_process;
75 u32 max_sg_len;
74 int rc; 76 int rc;
75 77
76 spin_lock_irqsave(&nx_ctx->lock, irq_flags); 78 spin_lock_irqsave(&nx_ctx->lock, irq_flags);
77 79
78 if (nbytes > nx_ctx->ap->databytelen) { 80 max_sg_len = min_t(u32, nx_driver.of.max_sg_len/sizeof(struct nx_sg),
79 rc = -EINVAL; 81 nx_ctx->ap->sglen);
80 goto out;
81 }
82 82
83 if (enc) 83 if (enc)
84 NX_CPB_FDM(csbcpb) |= NX_FDM_ENDE_ENCRYPT; 84 NX_CPB_FDM(csbcpb) |= NX_FDM_ENDE_ENCRYPT;
85 else 85 else
86 NX_CPB_FDM(csbcpb) &= ~NX_FDM_ENDE_ENCRYPT; 86 NX_CPB_FDM(csbcpb) &= ~NX_FDM_ENDE_ENCRYPT;
87 87
88 rc = nx_build_sg_lists(nx_ctx, desc, dst, src, nbytes, 0, NULL); 88 do {
89 if (rc) 89 to_process = min_t(u64, nbytes - processed,
90 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);
91 94
92 if (!nx_ctx->op.inlen || !nx_ctx->op.outlen) { 95 rc = nx_build_sg_lists(nx_ctx, desc, dst, src, to_process,
93 rc = -EINVAL; 96 processed, NULL);
94 goto out; 97 if (rc)
95 } 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));
96 113
97 rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, 114 processed += to_process;
98 desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP); 115 } while (processed < nbytes);
99 if (rc)
100 goto out;
101 116
102 atomic_inc(&(nx_ctx->stats->aes_ops));
103 atomic64_add(csbcpb->csb.processed_byte_count,
104 &(nx_ctx->stats->aes_bytes));
105out: 117out:
106 spin_unlock_irqrestore(&nx_ctx->lock, irq_flags); 118 spin_unlock_irqrestore(&nx_ctx->lock, irq_flags);
107 return rc; 119 return rc;