Commit 0c99620f authored by Romain Perier's avatar Romain Perier Committed by Herbert Xu

crypto: marvell - Use an unique pool to copy results of requests

So far, we used a dedicated dma pool to copy the result of outer IV for
cipher requests. Instead of using a dma pool per outer data, we prefer
use the op dma pool that contains all part of the request from the SRAM.
Then, the outer data that is likely to be used by the 'complete'
operation, is copied later. In this way, any type of result can be
retrieved by DMA for cipher or ahash requests.
Signed-off-by: default avatarRomain Perier <romain.perier@free-electrons.com>
Acked-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 1f696097
...@@ -375,10 +375,6 @@ static int mv_cesa_dev_dma_init(struct mv_cesa_dev *cesa) ...@@ -375,10 +375,6 @@ static int mv_cesa_dev_dma_init(struct mv_cesa_dev *cesa)
if (!dma->padding_pool) if (!dma->padding_pool)
return -ENOMEM; return -ENOMEM;
dma->iv_pool = dmam_pool_create("cesa_iv", dev, 16, 1, 0);
if (!dma->iv_pool)
return -ENOMEM;
cesa->dma = dma; cesa->dma = dma;
return 0; return 0;
......
...@@ -277,7 +277,7 @@ struct mv_cesa_op_ctx { ...@@ -277,7 +277,7 @@ struct mv_cesa_op_ctx {
#define CESA_TDMA_DUMMY 0 #define CESA_TDMA_DUMMY 0
#define CESA_TDMA_DATA 1 #define CESA_TDMA_DATA 1
#define CESA_TDMA_OP 2 #define CESA_TDMA_OP 2
#define CESA_TDMA_IV 3 #define CESA_TDMA_RESULT 3
/** /**
* struct mv_cesa_tdma_desc - TDMA descriptor * struct mv_cesa_tdma_desc - TDMA descriptor
...@@ -393,7 +393,6 @@ struct mv_cesa_dev_dma { ...@@ -393,7 +393,6 @@ struct mv_cesa_dev_dma {
struct dma_pool *op_pool; struct dma_pool *op_pool;
struct dma_pool *cache_pool; struct dma_pool *cache_pool;
struct dma_pool *padding_pool; struct dma_pool *padding_pool;
struct dma_pool *iv_pool;
}; };
/** /**
...@@ -839,7 +838,7 @@ mv_cesa_tdma_desc_iter_init(struct mv_cesa_tdma_chain *chain) ...@@ -839,7 +838,7 @@ mv_cesa_tdma_desc_iter_init(struct mv_cesa_tdma_chain *chain)
memset(chain, 0, sizeof(*chain)); memset(chain, 0, sizeof(*chain));
} }
int mv_cesa_dma_add_iv_op(struct mv_cesa_tdma_chain *chain, dma_addr_t src, int mv_cesa_dma_add_result_op(struct mv_cesa_tdma_chain *chain, dma_addr_t src,
u32 size, u32 flags, gfp_t gfp_flags); u32 size, u32 flags, gfp_t gfp_flags);
struct mv_cesa_op_ctx *mv_cesa_dma_add_op(struct mv_cesa_tdma_chain *chain, struct mv_cesa_op_ctx *mv_cesa_dma_add_op(struct mv_cesa_tdma_chain *chain,
......
...@@ -212,7 +212,8 @@ mv_cesa_ablkcipher_complete(struct crypto_async_request *req) ...@@ -212,7 +212,8 @@ mv_cesa_ablkcipher_complete(struct crypto_async_request *req)
struct mv_cesa_req *basereq; struct mv_cesa_req *basereq;
basereq = &creq->base; basereq = &creq->base;
memcpy(ablkreq->info, basereq->chain.last->data, ivsize); memcpy(ablkreq->info, basereq->chain.last->op->ctx.blkcipher.iv,
ivsize);
} else { } else {
memcpy_fromio(ablkreq->info, memcpy_fromio(ablkreq->info,
engine->sram + CESA_SA_CRYPT_IV_SRAM_OFFSET, engine->sram + CESA_SA_CRYPT_IV_SRAM_OFFSET,
...@@ -373,8 +374,9 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req, ...@@ -373,8 +374,9 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req,
/* Add output data for IV */ /* Add output data for IV */
ivsize = crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(req)); ivsize = crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(req));
ret = mv_cesa_dma_add_iv_op(&basereq->chain, CESA_SA_CRYPT_IV_SRAM_OFFSET, ret = mv_cesa_dma_add_result_op(&basereq->chain, CESA_SA_CFG_SRAM_OFFSET,
ivsize, CESA_TDMA_SRC_IN_SRAM, flags); CESA_SA_DATA_SRAM_OFFSET,
CESA_TDMA_SRC_IN_SRAM, flags);
if (ret) if (ret)
goto err_free_tdma; goto err_free_tdma;
......
...@@ -69,9 +69,6 @@ void mv_cesa_dma_cleanup(struct mv_cesa_req *dreq) ...@@ -69,9 +69,6 @@ void mv_cesa_dma_cleanup(struct mv_cesa_req *dreq)
if (type == CESA_TDMA_OP) if (type == CESA_TDMA_OP)
dma_pool_free(cesa_dev->dma->op_pool, tdma->op, dma_pool_free(cesa_dev->dma->op_pool, tdma->op,
le32_to_cpu(tdma->src)); le32_to_cpu(tdma->src));
else if (type == CESA_TDMA_IV)
dma_pool_free(cesa_dev->dma->iv_pool, tdma->data,
le32_to_cpu(tdma->dst));
tdma = tdma->next; tdma = tdma->next;
dma_pool_free(cesa_dev->dma->tdma_desc_pool, old_tdma, dma_pool_free(cesa_dev->dma->tdma_desc_pool, old_tdma,
...@@ -209,29 +206,37 @@ mv_cesa_dma_add_desc(struct mv_cesa_tdma_chain *chain, gfp_t flags) ...@@ -209,29 +206,37 @@ mv_cesa_dma_add_desc(struct mv_cesa_tdma_chain *chain, gfp_t flags)
return new_tdma; return new_tdma;
} }
int mv_cesa_dma_add_iv_op(struct mv_cesa_tdma_chain *chain, dma_addr_t src, int mv_cesa_dma_add_result_op(struct mv_cesa_tdma_chain *chain, dma_addr_t src,
u32 size, u32 flags, gfp_t gfp_flags) u32 size, u32 flags, gfp_t gfp_flags)
{ {
struct mv_cesa_tdma_desc *tdma, *op_desc;
struct mv_cesa_tdma_desc *tdma;
u8 *iv;
dma_addr_t dma_handle;
tdma = mv_cesa_dma_add_desc(chain, gfp_flags); tdma = mv_cesa_dma_add_desc(chain, gfp_flags);
if (IS_ERR(tdma)) if (IS_ERR(tdma))
return PTR_ERR(tdma); return PTR_ERR(tdma);
iv = dma_pool_alloc(cesa_dev->dma->iv_pool, gfp_flags, &dma_handle); /* We re-use an existing op_desc object to retrieve the context
if (!iv) * and result instead of allocating a new one.
return -ENOMEM; * There is at least one object of this type in a CESA crypto
* req, just pick the first one in the chain.
*/
for (op_desc = chain->first; op_desc; op_desc = op_desc->next) {
u32 type = op_desc->flags & CESA_TDMA_TYPE_MSK;
if (type == CESA_TDMA_OP)
break;
}
if (!op_desc)
return -EIO;
tdma->byte_cnt = cpu_to_le32(size | BIT(31)); tdma->byte_cnt = cpu_to_le32(size | BIT(31));
tdma->src = src; tdma->src = src;
tdma->dst = cpu_to_le32(dma_handle); tdma->dst = op_desc->src;
tdma->data = iv; tdma->op = op_desc->op;
flags &= (CESA_TDMA_DST_IN_SRAM | CESA_TDMA_SRC_IN_SRAM); flags &= (CESA_TDMA_DST_IN_SRAM | CESA_TDMA_SRC_IN_SRAM);
tdma->flags = flags | CESA_TDMA_IV; tdma->flags = flags | CESA_TDMA_RESULT;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment