Chain crypto requests together at the DMA level
Subsystems (2)
cover Chain crypto requests together at the DMA level
The Cryptographic Engines and Security Accelerators (CESA) supports the TDMA chained mode support. When this mode is enabled and crypto requests are chained at the DMA level, multiple crypto requests can be handled by the hardware engine without requiring any software intervention. This approach limits the number of interrupts generated by the engines thus improving its throughput and making the whole system behave nicely under heavy crypto load.
Benchmarking results with dmcrypt
=================================
I/O read I/O write
Before 81.7 MB/s 31.7 MB/s
After 129 MB/s 39.8 MB/s
Improvement +57.8 % +25.5 %
Romain Perier (7):
crypto: marvell: Add a macro constant for the size of the crypto queue
crypto: marvell: Check engine is not already running when enabling a
req
crypto: marvell: Copy IV vectors by DMA transfers for acipher requests
crypto: marvell: Moving the tdma chain out of mv_cesa_tdma_req
crypto: marvell: Adding a complete operation for async requests
crypto: marvell: Adding load balancing between engines
crypto: marvell: Add support for chaining crypto requests in TDMA mode
drivers/crypto/marvell/cesa.c | 142 ++++++++++++++++++++++++++++++---------- drivers/crypto/marvell/cesa.h | 103 +++++++++++++++++++++++------ drivers/crypto/marvell/cipher.c | 141 +++++++++++++++++++++++---------------- drivers/crypto/marvell/hash.c | 126 +++++++++++++++++------------------ drivers/crypto/marvell/tdma.c | 120 +++++++++++++++++++++++++++++++-- 5 files changed, 452 insertions(+), 180 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/7 crypto: marvell: Add a macro constant for the size of the crypto queue
Adding a macro constant to be used for the size of the crypto queue, instead of using a numeric value directly. It will be easier to maintain in case we add more than one crypto queue of the same size.
--- drivers/crypto/marvell/cesa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/crypto/marvell/cesa.c +4 -1
@@ -31,6 +31,9 @@#include "cesa.h" +/* Limit of the crypto queue before reaching the backlog */ +#define CESA_CRYPTO_DEFAULT_MAX_QLEN 50 +static int allhwsupport = !IS_ENABLED (CONFIG_CRYPTO_DEV_MV_CESA );module_param_named (allhwsupport, allhwsupport, int,0444 );MODULE_PARM_DESC (allhwsupport,"Enable support for all hardware (even it if overlaps with the mv_cesa driver)" );
@@ -416,7 +419,7 @@ static int mv_cesa_probe(struct platform_device *pdev)return -ENOMEM ;spin_lock_init (&cesa->lock); -crypto_init_queue (&cesa->queue,50 ); +crypto_init_queue (&cesa->queue,CESA_CRYPTO_DEFAULT_MAX_QLEN ); res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"regs" ); cesa->regs =devm_ioremap_resource (dev, res);if (IS_ERR (cesa->regs))
Signature · 1 line
2.7.4
PATCH 1/7 crypto: marvell: Add a macro constant for the size of the crypto queue
Quoted 5 lines · On Wed, 15 Jun 2016 21:15:28 +0200 Romain Perier…
Adding a macro constant to be used for the size of the crypto queue, instead of using a numeric value directly. It will be easier to maintain in case we add more than one crypto queue of the same size.
Signed-off-by Romain Perier <[email protected]>
Quoted 27 lines
--- drivers/crypto/marvell/cesa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/crypto/marvell/cesa.c +4
-1@@ -31,6 +31,9 @@#include "cesa.h" +/* Limit of the crypto queue before reaching the backlog */ +#define CESA_CRYPTO_DEFAULT_MAX_QLEN 50 +static int allhwsupport = !IS_ENABLED (CONFIG_CRYPTO_DEV_MV_CESA );module_param_named (allhwsupport, allhwsupport, int,0444 );MODULE_PARM_DESC (allhwsupport,"Enable support for all hardware (even it if overlaps with the mv_cesa driver)" );@@ -416,7 +419,7 @@ static int mv_cesa_probe(struct platform_device *pdev)return -ENOMEM ;spin_lock_init (&cesa->lock); -crypto_init_queue (&cesa->queue,50 ); +crypto_init_queue (&cesa->queue,CESA_CRYPTO_DEFAULT_MAX_QLEN ); res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"regs" ); cesa->regs =devm_ioremap_resource (dev, res);if (IS_ERR (cesa->regs))
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 2/7 crypto: marvell: Check engine is not already running when enabling a req
In reply to Romain PerierAdding BUG_ON() macro to be sure that the step operation is not about to activate a request on the engine if the corresponding engine is already processing a crypto request. This is helpful when the support for chaining crypto requests will be added. Instead of hanging the system when the engine is in an incoherent state, we add this macro which throws an understandable error.
--- drivers/crypto/marvell/cipher.c | 2 ++ drivers/crypto/marvell/hash.c | 2 ++ drivers/crypto/marvell/tdma.c | 2 ++ 3 files changed, 6 insertions(+)
drivers/crypto/marvell/cipher.c +2 -0
@@ -106,6 +106,8 @@ static void mv_cesa_ablkcipher_std_step(struct ablkcipher_request *req)mv_cesa_set_int_mask (engine,CESA_SA_INT_ACCEL0_DONE );writel_relaxed (CESA_SA_CFG_PARA_DIS , engine->regs +CESA_SA_CFG ); +BUG_ON (readl (engine->regs +CESA_SA_CMD ) + &CESA_SA_CMD_EN_CESA_SA_ACCL0 );writel (CESA_SA_CMD_EN_CESA_SA_ACCL0 , engine->regs +CESA_SA_CMD ); }
drivers/crypto/marvell/hash.c +2 -0
@@ -237,6 +237,8 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)mv_cesa_set_int_mask (engine,CESA_SA_INT_ACCEL0_DONE );writel_relaxed (CESA_SA_CFG_PARA_DIS , engine->regs +CESA_SA_CFG ); +BUG_ON (readl (engine->regs +CESA_SA_CMD ) + &CESA_SA_CMD_EN_CESA_SA_ACCL0 );writel (CESA_SA_CMD_EN_CESA_SA_ACCL0 , engine->regs +CESA_SA_CMD ); }
drivers/crypto/marvell/tdma.c +2 -0
@@ -53,6 +53,8 @@ void mv_cesa_dma_step(struct mv_cesa_tdma_req *dreq) engine->regs + CESA_SA_CFG);writel_relaxed (dreq->chain.first->cur_dma, engine->regs +CESA_TDMA_NEXT_ADDR ); +BUG_ON (readl (engine->regs +CESA_SA_CMD ) + &CESA_SA_CMD_EN_CESA_SA_ACCL0 );writel (CESA_SA_CMD_EN_CESA_SA_ACCL0 , engine->regs +CESA_SA_CMD ); }
Signature · 1 line
2.7.4
PATCH 2/7 crypto: marvell: Check engine is not already running when enabling a req
Quoted 5 lines · On Wed, 15 Jun 2016 21:15:29 +0200 Romain Perier…
Adding
BUG_ON()macro to be sure that the step operation is not about to activate a request on the engine if the corresponding engine is already processing a crypto request. This is helpful when the support for chaining crypto requests will be added. Instead of hanging the system when the engine is in an incoherent state, we add this macro
You don't add the macro, you use it.
Quoted 1 line
which throws an understandable error.
How about rewording the commit message this way:
"
Add a BUG_ON() call when the driver tries to launch a crypto request while the engine is still processing the previous one. This replaces a silent system hang by a verbose kernel panic with the associated backtrace to let the user know that something went wrong in the CESA driver.
"
Quoted 2 lines
Signed-off-by Romain Perier <[email protected]>
Apart from the coding style issue mentioned below,
Quoted 11 lines
--- drivers/crypto/marvell/cipher.c | 2 ++ drivers/crypto/marvell/hash.c | 2 ++ drivers/crypto/marvell/tdma.c | 2 ++ 3 files changed, 6 insertions(+)drivers/crypto/marvell/cipher.c +0
-0
drivers/crypto/marvell/cipher.c static void mv_cesa_ablkcipher_std_step(struct ablkcipher_request *req) · line 110
Quoted 5 lines
drivers/crypto/marvell/cipher.c +2
-0@@ -106,6 +106,8 @@ static void mv_cesa_ablkcipher_std_step(struct ablkcipher_request *req)mv_cesa_set_int_mask (engine,CESA_SA_INT_ACCEL0_DONE );writel_relaxed (CESA_SA_CFG_PARA_DIS , engine->regs +CESA_SA_CFG ); +BUG_ON (readl (engine->regs +CESA_SA_CMD ) + &CESA_SA_CMD_EN_CESA_SA_ACCL0 );
Nit: please put the '&' operator at the end of the first line and align CESA_SA_CMD_EN_CESA_SA_ACCL0 on the open parenthesis.
BUG_ON(readl(engine->regs + CESA_SA_CMD) & CESA_SA_CMD_EN_CESA_SA_ACCL0);
drivers/crypto/marvell/hash.c static void mv_cesa_ahash_std_step(struct ahash_request *req) · line 241
Quoted 13 lines
drivers/crypto/marvell/cipher.c +0
-0writel (CESA_SA_CMD_EN_CESA_SA_ACCL0 , engine->regs +CESA_SA_CMD ); }drivers/crypto/marvell/hash.c +2
-0@@ -237,6 +237,8 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)mv_cesa_set_int_mask (engine,CESA_SA_INT_ACCEL0_DONE );writel_relaxed (CESA_SA_CFG_PARA_DIS , engine->regs +CESA_SA_CFG ); +BUG_ON (readl (engine->regs +CESA_SA_CMD ) + &CESA_SA_CMD_EN_CESA_SA_ACCL0 );
Ditto.
drivers/crypto/marvell/tdma.c void mv_cesa_dma_step(struct mv_cesa_tdma_req *dreq) · line 57
Quoted 13 lines
drivers/crypto/marvell/hash.c +0
-0writel (CESA_SA_CMD_EN_CESA_SA_ACCL0 , engine->regs +CESA_SA_CMD ); }drivers/crypto/marvell/tdma.c +2
-0@@ -53,6 +53,8 @@ void mv_cesa_dma_step(struct mv_cesa_tdma_req *dreq) engine->regs + CESA_SA_CFG);writel_relaxed (dreq->chain.first->cur_dma, engine->regs +CESA_TDMA_NEXT_ADDR ); +BUG_ON (readl (engine->regs +CESA_SA_CMD ) + &CESA_SA_CMD_EN_CESA_SA_ACCL0 );
Ditto.
Quoted 3 lines
drivers/crypto/marvell/tdma.c +0
-0writel (CESA_SA_CMD_EN_CESA_SA_ACCL0 , engine->regs +CESA_SA_CMD ); }
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 2/7 crypto: marvell: Check engine is not already running when enabling a req
Hello,
Le 15/06/2016 21:37, Boris Brezillon a ?crit :
Quoted 8 lines
"
Add aBUG_ON()call when the driver tries to launch a crypto request while the engine is still processing the previous one. This replaces a silent system hang by a verbose kernel panic with the associated backtrace to let the user know that something went wrong in the CESA driver.
"
thanks
Quoted 13 lines
Quoted 13 lines
--- drivers/crypto/marvell/cipher.c | 2 ++ drivers/crypto/marvell/hash.c | 2 ++ drivers/crypto/marvell/tdma.c | 2 ++ 3 files changed, 6 insertions(+)drivers/crypto/marvell/cipher.c +0
-0@@ -106,6 +106,8 @@ static void mv_cesa_ablkcipher_std_step(struct ablkcipher_request *req)
Quoted 7 lines
drivers/crypto/marvell/cipher.c static void mv_cesa_ablkcipher_std_step(struct ablkcipher_request *req) · line 110
Quoted 4 lines
drivers/crypto/marvell/cipher.c +2
-0mv_cesa_set_int_mask (engine,CESA_SA_INT_ACCEL0_DONE );writel_relaxed (CESA_SA_CFG_PARA_DIS , engine->regs +CESA_SA_CFG ); +BUG_ON (readl (engine->regs +CESA_SA_CMD ) + &CESA_SA_CMD_EN_CESA_SA_ACCL0 );Nit: please put the '&' operator at the end of the first line and align
CESA_SA_CMD_EN_CESA_SA_ACCL0on the open parenthesis.
Arf, ok I will fix this.
Quoted 13 lines
BUG_ON(readl(engine->regs + CESA_SA_CMD) & CESA_SA_CMD_EN_CESA_SA_ACCL0);Quoted 9 lines
drivers/crypto/marvell/cipher.c +0
-0writel (CESA_SA_CMD_EN_CESA_SA_ACCL0 , engine->regs +CESA_SA_CMD ); }drivers/crypto/marvell/hash.c +0
-0@@ -237,6 +237,8 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
Quoted 6 lines
drivers/crypto/marvell/hash.c static void mv_cesa_ahash_std_step(struct ahash_request *req) · line 241
Quoted 4 lines
drivers/crypto/marvell/hash.c +2
-0mv_cesa_set_int_mask (engine,CESA_SA_INT_ACCEL0_DONE );writel_relaxed (CESA_SA_CFG_PARA_DIS , engine->regs +CESA_SA_CFG ); +BUG_ON (readl (engine->regs +CESA_SA_CMD ) + &CESA_SA_CMD_EN_CESA_SA_ACCL0 );Ditto.
ack
Quoted 4 lines
Quoted 4 lines
drivers/crypto/marvell/hash.c +0
-0writel (CESA_SA_CMD_EN_CESA_SA_ACCL0 , engine->regs +CESA_SA_CMD ); }
Quoted 12 lines
drivers/crypto/marvell/tdma.c void mv_cesa_dma_step(struct mv_cesa_tdma_req *dreq) · line 57
Quoted 10 lines
drivers/crypto/marvell/tdma.c +2
-0@@ -53,6 +53,8 @@ void mv_cesa_dma_step(struct mv_cesa_tdma_req *dreq) engine->regs + CESA_SA_CFG);writel_relaxed (dreq->chain.first->cur_dma, engine->regs +CESA_TDMA_NEXT_ADDR ); +BUG_ON (readl (engine->regs +CESA_SA_CMD ) + &CESA_SA_CMD_EN_CESA_SA_ACCL0 );Ditto.
ack
Regards,
Romain
Signature · 3 lines
Romain Perier, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 3/7 crypto: marvell: Copy IV vectors by DMA transfers for acipher requests
In reply to Romain PerierAdding a TDMA descriptor at the end of the request for copying the output IV vector via a DMA transfer. This is required for processing cipher requests asynchroniously in chained mode, otherwise the content of the IV vector will be overwriten for each new finished request.
--- drivers/crypto/marvell/cesa.c | 4 ++++ drivers/crypto/marvell/cesa.h | 5 +++++ drivers/crypto/marvell/cipher.c | 40 +++++++++++++++++++++++++++------------- drivers/crypto/marvell/tdma.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 13 deletions(-)
drivers/crypto/marvell/cesa.c +4 -0
@@ -312,6 +312,10 @@ static int mv_cesa_dev_dma_init(struct mv_cesa_dev *cesa)if (!dma->padding_pool)return -ENOMEM ; + dma->iv_pool =dmam_pool_create ("cesa_iv" , dev,16 ,1 ,0 ); +if (!dma->iv_pool) +return -ENOMEM ; + cesa->dma = dma;return 0 ;
drivers/crypto/marvell/cesa.h +5 -0
@@ -275,6 +275,7 @@ struct mv_cesa_op_ctx {#define CESA_TDMA_DUMMY 0#define CESA_TDMA_DATA 1#define CESA_TDMA_OP 2 +#define CESA_TDMA_IV 4/** * struct mv_cesa_tdma_desc - TDMA descriptor
@@ -390,6 +391,7 @@ struct mv_cesa_dev_dma {struct dma_pool *op_pool;struct dma_pool *cache_pool;struct dma_pool *padding_pool; +struct dma_pool *iv_pool; };/**
@@ -790,6 +792,9 @@ mv_cesa_tdma_desc_iter_init(struct mv_cesa_tdma_chain *chain)memset (chain,0 ,sizeof (*chain)); } +int mv_cesa_dma_add_iv_op (struct mv_cesa_tdma_chain *chain,dma_addr_t src, +u32 size,u32 flags,gfp_t gfp_flags); + struct mv_cesa_op_ctx *mv_cesa_dma_add_op(struct mv_cesa_tdma_chain *chain, const struct mv_cesa_op_ctx *op_templ, bool skip_ctx,
drivers/crypto/marvell/cipher.c +27 -13
@@ -118,6 +118,7 @@ static int mv_cesa_ablkcipher_std_process(struct ablkcipher_request *req,struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std;struct mv_cesa_engine *engine = sreq->base.engine;size_t len; +unsigned int ivsize; len = sg_pcopy_from_buffer(req->dst, creq->dst_nents, engine->sram + CESA_SA_DATA_SRAM_OFFSET,
@@ -127,6 +128,10 @@ static int mv_cesa_ablkcipher_std_process(struct ablkcipher_request *req,if (sreq->offset < req->nbytes)return -EINPROGRESS ; + ivsize =crypto_ablkcipher_ivsize (crypto_ablkcipher_reqtfm (req)); +memcpy_fromio (req->info, + engine->sram +CESA_SA_CRYPT_IV_SRAM_OFFSET , ivsize); +return 0 ; }
@@ -135,23 +140,23 @@ static int mv_cesa_ablkcipher_process(struct crypto_async_request *req, {struct ablkcipher_request *ablkreq =ablkcipher_request_cast (req);struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq); -struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std; -struct mv_cesa_engine *engine = sreq->base.engine; -int ret; -if (creq->req.base.type ==CESA_DMA_REQ ) +if (creq->req.base.type ==CESA_DMA_REQ ) { +int ret; +struct mv_cesa_tdma_req *dreq; +unsigned int ivsize; + ret =mv_cesa_dma_process (&creq->req.dma, status); -else - ret =mv_cesa_ablkcipher_std_process (ablkreq, status); +if (ret) +return ret; -if (ret) + dreq = &creq->req.dma; + ivsize =crypto_ablkcipher_ivsize ( +crypto_ablkcipher_reqtfm (ablkreq)); +memcpy_fromio (ablkreq->info, dreq->chain.last->data, ivsize);return ret; - -memcpy_fromio (ablkreq->info, - engine->sram +CESA_SA_CRYPT_IV_SRAM_OFFSET , -crypto_ablkcipher_ivsize (crypto_ablkcipher_reqtfm (ablkreq))); - -return 0 ; + } +return mv_cesa_ablkcipher_std_process (ablkreq, status); }static void mv_cesa_ablkcipher_step (struct crypto_async_request *req)
@@ -302,6 +307,7 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req,struct mv_cesa_tdma_chain chain;bool skip_ctx = false;int ret; +unsigned int ivsize; dreq->base.type =CESA_DMA_REQ ; dreq->chain.first =NULL ;
@@ -360,6 +366,14 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req, }while (mv_cesa_ablkcipher_req_iter_next_op (&iter)); +/* Add output data for IV */ + ivsize =crypto_ablkcipher_ivsize (crypto_ablkcipher_reqtfm (req)); + ret =mv_cesa_dma_add_iv_op (&chain,CESA_SA_CRYPT_IV_SRAM_OFFSET , + ivsize,CESA_TDMA_SRC_IN_SRAM , flags); + +if (ret) + goto err_free_tdma; + dreq->chain = chain;return 0 ;
drivers/crypto/marvell/tdma.c +29 -0
@@ -68,6 +68,9 @@ void mv_cesa_dma_cleanup(struct mv_cesa_tdma_req *dreq)if (tdma->flags &CESA_TDMA_OP )dma_pool_free (cesa_dev->dma->op_pool, tdma->op,le32_to_cpu (tdma->src)); +else if (tdma->flags &CESA_TDMA_IV ) +dma_pool_free (cesa_dev->dma->iv_pool, tdma->data, +le32_to_cpu (tdma->dst)); tdma = tdma->next; dma_pool_free(cesa_dev->dma->tdma_desc_pool, old_tdma,
@@ -120,6 +123,32 @@ mv_cesa_dma_add_desc(struct mv_cesa_tdma_chain *chain, gfp_t flags)return new_tdma; } +int mv_cesa_dma_add_iv_op (struct mv_cesa_tdma_chain *chain,dma_addr_t src, +u32 size,u32 flags,gfp_t gfp_flags) +{ + +struct mv_cesa_tdma_desc *tdma; +u8 *cache; +dma_addr_t dma_handle; + + tdma =mv_cesa_dma_add_desc (chain, gfp_flags); +if (IS_ERR (tdma)) +return PTR_ERR (tdma); + + cache =dma_pool_alloc (cesa_dev->dma->iv_pool, flags, &dma_handle); +if (!cache) +return -ENOMEM ; + + tdma->byte_cnt =cpu_to_le32 (size |BIT (31 )); + tdma->src = src; + tdma->dst =cpu_to_le32 (dma_handle); + tdma->data = cache; + + flags &= (CESA_TDMA_DST_IN_SRAM |CESA_TDMA_SRC_IN_SRAM ); + tdma->flags = flags |CESA_TDMA_DATA |CESA_TDMA_IV ; +return 0 ; +} + struct mv_cesa_op_ctx *mv_cesa_dma_add_op(struct mv_cesa_tdma_chain *chain, const struct mv_cesa_op_ctx *op_templ, bool skip_ctx,
Signature · 1 line
2.7.4
PATCH 3/7 crypto: marvell: Copy IV vectors by DMA transfers for acipher requests
Quoted 3 lines · On Wed, 15 Jun 2016 21:15:30 +0200 Romain Perier…
Adding a TDMA descriptor at the end of the request for copying the output IV vector via a DMA transfer. This is required for processing cipher requests asynchroniously in chained mode, otherwise the content
asynchronously
Quoted 1 line
of the IV vector will be overwriten for each new finished request.
BTW, Not sure the term 'asynchronously' is appropriate here. The standard (AKA non-DMA) processing is also asynchronous. The real reason here is that you want to chain the requests and offload as much processing as possible to the DMA and crypto engine. And as you explained, this is only possible if we retrieve the updated IV using DMA.
Quoted 29 lines
Signed-off-by Romain Perier <[email protected]>--- drivers/crypto/marvell/cesa.c | 4 ++++ drivers/crypto/marvell/cesa.h | 5 +++++ drivers/crypto/marvell/cipher.c | 40 +++++++++++++++++++++++++++------------- drivers/crypto/marvell/tdma.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 13 deletions(-)drivers/crypto/marvell/cesa.c +4
-0@@ -312,6 +312,10 @@ static int mv_cesa_dev_dma_init(struct mv_cesa_dev *cesa)if (!dma->padding_pool)return -ENOMEM ; + dma->iv_pool =dmam_pool_create ("cesa_iv" , dev,16 ,1 ,0 ); +if (!dma->iv_pool) +return -ENOMEM ; + cesa->dma = dma;return 0 ;drivers/crypto/marvell/cesa.h +0
-0
drivers/crypto/marvell/cesa.h struct mv_cesa_op_ctx { · line 278
Quoted 4 lines
drivers/crypto/marvell/cesa.h +1
-0@@ -275,6 +275,7 @@ struct mv_cesa_op_ctx {#define CESA_TDMA_DUMMY 0#define CESA_TDMA_DATA 1#define CESA_TDMA_OP 2 +#define CESA_TDMA_IV 4
Should be 3 and not 4: TDMA_TYPE is an enum, not a bit field.
Quoted 58 lines
drivers/crypto/marvell/cesa.h +4
-0/** * struct mv_cesa_tdma_desc - TDMA descriptor @@ -390,6 +391,7 @@ struct mv_cesa_dev_dma {struct dma_pool *op_pool;struct dma_pool *cache_pool;struct dma_pool *padding_pool; +struct dma_pool *iv_pool; };/** @@ -790,6 +792,9 @@ mv_cesa_tdma_desc_iter_init(struct mv_cesa_tdma_chain *chain)memset (chain,0 ,sizeof (*chain)); } +int mv_cesa_dma_add_iv_op (struct mv_cesa_tdma_chain *chain,dma_addr_t src, +u32 size,u32 flags,gfp_t gfp_flags); + struct mv_cesa_op_ctx *mv_cesa_dma_add_op(struct mv_cesa_tdma_chain *chain, const struct mv_cesa_op_ctx *op_templ, bool skip_ctx,drivers/crypto/marvell/cipher.c +10
-4@@ -118,6 +118,7 @@ static int mv_cesa_ablkcipher_std_process(struct ablkcipher_request *req,struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std;struct mv_cesa_engine *engine = sreq->base.engine;size_t len; +unsigned int ivsize; len = sg_pcopy_from_buffer(req->dst, creq->dst_nents, engine->sram + CESA_SA_DATA_SRAM_OFFSET,@@ -127,6 +128,10 @@ static int mv_cesa_ablkcipher_std_process(struct ablkcipher_request *req,if (sreq->offset < req->nbytes)return -EINPROGRESS ; + ivsize =crypto_ablkcipher_ivsize (crypto_ablkcipher_reqtfm (req)); +memcpy_fromio (req->info, + engine->sram +CESA_SA_CRYPT_IV_SRAM_OFFSET , ivsize); +return 0 ; }@@ -135,23 +140,23 @@ static int mv_cesa_ablkcipher_process(struct crypto_async_request *req, {struct ablkcipher_request *ablkreq =ablkcipher_request_cast (req);struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq); -struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std; -struct mv_cesa_engine *engine = sreq->base.engine; -int ret; -if (creq->req.base.type ==CESA_DMA_REQ ) +if (creq->req.base.type ==CESA_DMA_REQ ) { +int ret; +struct mv_cesa_tdma_req *dreq; +unsigned int ivsize; +
drivers/crypto/marvell/cipher.c static int mv_cesa_ablkcipher_process(struct crypto_async_request *req, · line 155
Quoted 10 lines
drivers/crypto/marvell/cipher.c +5
-3ret =mv_cesa_dma_process (&creq->req.dma, status); - else - ret =mv_cesa_ablkcipher_std_process (ablkreq, status); +if (ret) +return ret; -if (ret) + dreq = &creq->req.dma; + ivsize =crypto_ablkcipher_ivsize ( +crypto_ablkcipher_reqtfm (ablkreq));
Sometime it's better to offend the < 80 characters rule than doing funky stuff ;).
drivers/crypto/marvell/cipher.c static int mv_cesa_ablkcipher_process(struct crypto_async_request *req, · line 158
Quoted 9 lines
drivers/crypto/marvell/cipher.c +2
-6+memcpy_fromio (ablkreq->info, dreq->chain.last->data, ivsize);return ret; - -memcpy_fromio (ablkreq->info, - engine->sram +CESA_SA_CRYPT_IV_SRAM_OFFSET , -crypto_ablkcipher_ivsize (crypto_ablkcipher_reqtfm (ablkreq))); - -return 0 ; + }
Missing blank line.
drivers/crypto/marvell/cipher.c static int mv_cesa_ablkcipher_process(struct crypto_async_request *req, · line 159
Quoted 1 line
drivers/crypto/marvell/cipher.c +1
-0+return mv_cesa_ablkcipher_std_process (ablkreq, status);
This version is more readable IMHO:
struct mv_cesa_tdma_req *dreq; unsigned int ivsize; int ret; if (creq->req.base.type == CESA_STD_REQ) return mv_cesa_ablkcipher_std_process(ablkreq, status); ret = mv_cesa_dma_process(&creq->req.dma, status); if (ret) return ret; dreq = &creq->req.dma; ivsize = crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(ablkreq)); memcpy_fromio(ablkreq->info, dreq->chain.last->data, ivsize); return 0;
Quoted 30 lines
drivers/crypto/marvell/cipher.c +9
-0static void mv_cesa_ablkcipher_step (struct crypto_async_request *req)@@ -302,6 +307,7 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req,struct mv_cesa_tdma_chain chain;bool skip_ctx = false;int ret; +unsigned int ivsize; dreq->base.type =CESA_DMA_REQ ; dreq->chain.first =NULL ;@@ -360,6 +366,14 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req, }while (mv_cesa_ablkcipher_req_iter_next_op (&iter)); +/* Add output data for IV */ + ivsize =crypto_ablkcipher_ivsize (crypto_ablkcipher_reqtfm (req)); + ret =mv_cesa_dma_add_iv_op (&chain,CESA_SA_CRYPT_IV_SRAM_OFFSET , + ivsize,CESA_TDMA_SRC_IN_SRAM , flags); + +if (ret) + goto err_free_tdma; + dreq->chain = chain;return 0 ;drivers/crypto/marvell/tdma.c +0
-0
drivers/crypto/marvell/tdma.c void mv_cesa_dma_cleanup(struct mv_cesa_tdma_req *dreq) · line 68
Quoted 1 line
drivers/crypto/marvell/tdma.c +0
-0@@ -68,6 +68,9 @@ void mv_cesa_dma_cleanup(struct mv_cesa_tdma_req *dreq)if (tdma->flags &CESA_TDMA_OP )
I realize this test is wrong.
It should be
type = tdma->flags & CESA_TDMA_TYPE_MSK; if (type == CESA_TDMA_OP)
drivers/crypto/marvell/tdma.c void mv_cesa_dma_cleanup(struct mv_cesa_tdma_req *dreq) · line 71
Quoted 3 lines
drivers/crypto/marvell/tdma.c +1
-0dma_pool_free (cesa_dev->dma->op_pool, tdma->op,le32_to_cpu (tdma->src)); + else if (tdma->flags & CESA_TDMA_IV)
and here
else if (type == CESA_TDMA_IV)
Quoted 6 lines
drivers/crypto/marvell/tdma.c +2
-0+dma_pool_free (cesa_dev->dma->iv_pool, tdma->data, +le32_to_cpu (tdma->dst)); tdma = tdma->next; dma_pool_free(cesa_dev->dma->tdma_desc_pool, old_tdma,
drivers/crypto/marvell/tdma.c mv_cesa_dma_add_desc(struct mv_cesa_tdma_chain *chain, gfp_t flags) · line 131
Quoted 9 lines
drivers/crypto/marvell/tdma.c +6
-0@@ -120,6 +123,32 @@ mv_cesa_dma_add_desc(struct mv_cesa_tdma_chain *chain, gfp_t flags)return new_tdma; } +int mv_cesa_dma_add_iv_op (struct mv_cesa_tdma_chain *chain,dma_addr_t src, +u32 size,u32 flags,gfp_t gfp_flags) +{ + +struct mv_cesa_tdma_desc *tdma; +u8 *cache;
Why do you name that one cache? iv would be a better name.
Quoted 7 lines
drivers/crypto/marvell/tdma.c +7
-0+dma_addr_t dma_handle; + + tdma =mv_cesa_dma_add_desc (chain, gfp_flags); +if (IS_ERR (tdma)) +return PTR_ERR (tdma); + + cache =dma_pool_alloc (cesa_dev->dma->iv_pool, flags, &dma_handle);
drivers/crypto/marvell/tdma.c mv_cesa_dma_add_desc(struct mv_cesa_tdma_chain *chain, gfp_t flags) · line 148
Quoted 10 lines
drivers/crypto/marvell/tdma.c +10
-0+if (!cache) +return -ENOMEM ; + + tdma->byte_cnt =cpu_to_le32 (size |BIT (31 )); + tdma->src = src; + tdma->dst =cpu_to_le32 (dma_handle); + tdma->data = cache; + + flags &= (CESA_TDMA_DST_IN_SRAM |CESA_TDMA_SRC_IN_SRAM ); + tdma->flags = flags |CESA_TDMA_DATA |CESA_TDMA_IV ;
You should not mix 2 different types, it's either CESA_TDMA_DATA or CESA_TDMA_IV, and in this case it should be CESA_TDMA_IV.
Quoted 6 lines
drivers/crypto/marvell/tdma.c +3
-0+return 0 ; +} + struct mv_cesa_op_ctx *mv_cesa_dma_add_op(struct mv_cesa_tdma_chain *chain, const struct mv_cesa_op_ctx *op_templ, bool skip_ctx,
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 3/7 crypto: marvell: Copy IV vectors by DMA transfers for acipher requests
Hello,
Le 15/06/2016 22:07, Boris Brezillon a ?crit :
Quoted 9 lines
Quoted 3 lines · On Wed, 15 Jun 2016 21:15:30 +0200 Romain Perier…
Adding a TDMA descriptor at the end of the request for copying the output IV vector via a DMA transfer. This is required for processing cipher requests asynchroniously in chained mode, otherwise the content
asynchronously
Quoted 9 lines
Quoted 1 line
of the IV vector will be overwriten for each new finished request.
BTW, Not sure the term 'asynchronously' is appropriate here. The standard (AKA non-DMA) processing is also asynchronous. The real reason here is that you want to chain the requests and offload as much processing as possible to the DMA and crypto engine. And as you explained, this is only possible if we retrieve the updated IV using DMA.
What do you think of the following description ?
"
Adding a TDMA descriptor at the end of the request for copying the output IV vector via a DMA transfer. This is a good way for offloading as much as processing as possible to the DMA and the crypto engine. This is also required for processing multiple cipher requests in chained mode, otherwise the content of the IV vector would be overwritten by the last processed request.
"
This point is true if multiple chained requests are processed via TDMA, the content of the "global" IV output vector would be overwritten by the last request.
Quoted 11 lines
drivers/crypto/marvell/cesa.h struct mv_cesa_op_ctx { · line 278
Quoted 9 lines
drivers/crypto/marvell/cesa.h +1
-0@@ -275,6 +275,7 @@ struct mv_cesa_op_ctx {#define CESA_TDMA_DUMMY 0#define CESA_TDMA_DATA 1#define CESA_TDMA_OP 2 +#define CESA_TDMA_IV 4Should be 3 and not 4:
TDMA_TYPEis an enum, not a bit field.
Ok
Quoted 3 lines
Sometime it's better to offend the < 80 characters rule than doing funky stuff ;).
I just wanted to make checkpatch happy :D
Yeah, that's ugly, I agree. I will fix this.
Quoted 12 lines
drivers/crypto/marvell/cesa.h struct mv_cesa_op_ctx {
Quoted 10 lines
drivers/crypto/marvell/cesa.h +2
-6+memcpy_fromio (ablkreq->info, dreq->chain.last->data, ivsize);return ret; - -memcpy_fromio (ablkreq->info, - engine->sram +CESA_SA_CRYPT_IV_SRAM_OFFSET , -crypto_ablkcipher_ivsize (crypto_ablkcipher_reqtfm (ablkreq))); - -return 0 ; + }Missing blank line.
ack
Quoted 58 lines
drivers/crypto/marvell/cesa.h
Quoted 2 lines
drivers/crypto/marvell/cesa.h +1
-0+return mv_cesa_ablkcipher_std_process (ablkreq, status);This version is more readable IMHO:
struct mv_cesa_tdma_req *dreq; unsigned int ivsize; int ret; if (creq->req.base.type == CESA_STD_REQ) return mv_cesa_ablkcipher_std_process(ablkreq, status); ret = mv_cesa_dma_process(&creq->req.dma, status); if (ret) return ret; dreq = &creq->req.dma; ivsize = crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(ablkreq)); memcpy_fromio(ablkreq->info, dreq->chain.last->data, ivsize); return 0;Quoted 30 lines
static void
mv_cesa_ablkcipher_step(struct crypto_async_request *req)drivers/crypto/marvell/cesa.h +9
-0@@ -302,6 +307,7 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req,struct mv_cesa_tdma_chain chain;bool skip_ctx = false;int ret; +unsigned int ivsize; dreq->base.type =CESA_DMA_REQ ; dreq->chain.first =NULL ;@@ -360,6 +366,14 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req, }while (mv_cesa_ablkcipher_req_iter_next_op (&iter)); +/* Add output data for IV */ + ivsize =crypto_ablkcipher_ivsize (crypto_ablkcipher_reqtfm (req)); + ret =mv_cesa_dma_add_iv_op (&chain,CESA_SA_CRYPT_IV_SRAM_OFFSET , + ivsize,CESA_TDMA_SRC_IN_SRAM , flags); + +if (ret) + goto err_free_tdma; + dreq->chain = chain;return 0 ;drivers/crypto/marvell/tdma.c +0
-0drivers/crypto/marvell/tdma.c void mv_cesa_dma_cleanup(struct mv_cesa_tdma_req *dreq) · line 68
Quoted 1 line
drivers/crypto/marvell/tdma.c +0
-0@@ -68,6 +68,9 @@ void mv_cesa_dma_cleanup(struct mv_cesa_tdma_req *dreq)if (tdma->flags &CESA_TDMA_OP )I realize this test is wrong.
It should be
Quoted 8 lines
type = tdma->flags & CESA_TDMA_TYPE_MSK; if (type == CESA_TDMA_OP)drivers/crypto/marvell/tdma.c void mv_cesa_dma_cleanup(struct mv_cesa_tdma_req *dreq) · line 71
Quoted 3 lines
drivers/crypto/marvell/tdma.c +1
-0dma_pool_free (cesa_dev->dma->op_pool, tdma->op,le32_to_cpu (tdma->src)); + else if (tdma->flags & CESA_TDMA_IV)and here
I propose a separated commit to fix this problem. What do you think ?
Quoted 11 lines
else if (type == CESA_TDMA_IV)Quoted 9 lines
drivers/crypto/marvell/tdma.c +2
-0+dma_pool_free (cesa_dev->dma->iv_pool, tdma->data, +le32_to_cpu (tdma->dst)); tdma = tdma->next; dma_pool_free(cesa_dev->dma->tdma_desc_pool, old_tdma,@@ -120,6 +123,32 @@ mv_cesa_dma_add_desc(struct mv_cesa_tdma_chain *chain, gfp_t flags)return new_tdma; }
Quoted 8 lines
drivers/crypto/marvell/tdma.c mv_cesa_dma_add_desc(struct mv_cesa_tdma_chain *chain, gfp_t flags) · line 131
Quoted 6 lines
drivers/crypto/marvell/tdma.c +6
-0+int mv_cesa_dma_add_iv_op (struct mv_cesa_tdma_chain *chain,dma_addr_t src, +u32 size,u32 flags,gfp_t gfp_flags) +{ + +struct mv_cesa_tdma_desc *tdma; +u8 *cache;Why do you name that one cache? iv would be a better name.
ok
Quoted 13 lines
Quoted 13 lines
drivers/crypto/marvell/tdma.c +12
-0+dma_addr_t dma_handle; + + tdma =mv_cesa_dma_add_desc (chain, gfp_flags); +if (IS_ERR (tdma)) +return PTR_ERR (tdma); + + cache =dma_pool_alloc (cesa_dev->dma->iv_pool, flags, &dma_handle); +if (!cache) +return -ENOMEM ; + + tdma->byte_cnt =cpu_to_le32 (size |BIT (31 )); + tdma->src = src;
Quoted 8 lines
drivers/crypto/marvell/tdma.c mv_cesa_dma_add_desc(struct mv_cesa_tdma_chain *chain, gfp_t flags) · line 148
Quoted 5 lines
drivers/crypto/marvell/tdma.c +5
-0+ tdma->dst =cpu_to_le32 (dma_handle); + tdma->data = cache; + + flags &= (CESA_TDMA_DST_IN_SRAM |CESA_TDMA_SRC_IN_SRAM ); + tdma->flags = flags |CESA_TDMA_DATA |CESA_TDMA_IV ;You should not mix 2 different types, it's either
CESA_TDMA_DATAorCESA_TDMA_IV, and in this case it should beCESA_TDMA_IV.
good catch.
Quoted 10 lines
drivers/crypto/marvell/tdma.c mv_cesa_dma_add_desc(struct mv_cesa_tdma_chain *chain, gfp_t flags) · line 154
Quoted 7 lines
drivers/crypto/marvell/tdma.c +3
-0+return 0 ; +} + struct mv_cesa_op_ctx *mv_cesa_dma_add_op(struct mv_cesa_tdma_chain *chain, const struct mv_cesa_op_ctx *op_templ, bool skip_ctx,
Thanks,
Regards,
Romain
Signature · 3 lines
Romain Perier, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 3/7 crypto: marvell: Copy IV vectors by DMA transfers for acipher requests
Hi Romain,
Quoted 13 lines · Romain Perier
Quoted 12 lines
drivers/crypto/marvell/cesa.h struct mv_cesa_op_ctx { · line 278
Quoted 10 lines
drivers/crypto/marvell/cesa.h +1
-0@@ -275,6 +275,7 @@ struct mv_cesa_op_ctx {#define CESA_TDMA_DUMMY 0#define CESA_TDMA_DATA 1#define CESA_TDMA_OP 2 +#define CESA_TDMA_IV 4Should be 3 and not 4:
TDMA_TYPEis an enum, not a bit field.
Quoted 7 lines
Ok
Quoted 3 lines
Sometime it's better to offend the < 80 characters rule than doing funky stuff ;).
I just wanted to make checkpatch happy :D
In this case you can use a temporary variable.
Signature · 4 lines
Gregory Clement, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com
PATCH 3/7 crypto: marvell: Copy IV vectors by DMA transfers for acipher requests
In reply to Romain PerierQuoted 15 lines · On Wed, 15 Jun 2016 21:15:30 +0200 Romain Perier…
drivers/crypto/marvell/cipher.c +5
-4@@ -135,23 +140,23 @@ static int mv_cesa_ablkcipher_process(struct crypto_async_request *req, {struct ablkcipher_request *ablkreq =ablkcipher_request_cast (req);struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq); -struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std; -struct mv_cesa_engine *engine = sreq->base.engine; -int ret; -if (creq->req.base.type ==CESA_DMA_REQ ) +if (creq->req.base.type ==CESA_DMA_REQ ) { +int ret; +struct mv_cesa_tdma_req *dreq; +unsigned int ivsize; + ret =mv_cesa_dma_process (&creq->req.dma, status);
drivers/crypto/marvell/cipher.c static int mv_cesa_ablkcipher_process(struct crypto_async_request *req, · line 156
Quoted 10 lines
drivers/crypto/marvell/cipher.c +6
-3-else - ret =mv_cesa_ablkcipher_std_process (ablkreq, status); +if (ret) +return ret; -if (ret) + dreq = &creq->req.dma; + ivsize =crypto_ablkcipher_ivsize ( +crypto_ablkcipher_reqtfm (ablkreq)); +memcpy_fromio (ablkreq->info, dreq->chain.last->data, ivsize);
Just use memcpy() here: you're not copying from an iomem region here.
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 4/7 crypto: marvell: Moving the tdma chain out of mv_cesa_tdma_req
In reply to Romain PerierActually the only way to access the tdma chain is to use the 'req' union from a mv_cesa_{ablkcipher,ahash}. This will soon become a problem if we want to handle the TDMA chaining vs standard/non-DMA processing in a generic way (with generic functions at the cesa.c level detecting whether the request should be queued at the DMA level or not). Hence the decision to move the chain field a the mv_cesa_req level at the expense of adding 2 void * fields to all request contexts (including non-DMA ones). To limit the overhead, we get rid of the type field, which can now be deduced from the req->chain.first value.
--- drivers/crypto/marvell/cesa.c | 3 ++- drivers/crypto/marvell/cesa.h | 31 +++++++++++++------------------ drivers/crypto/marvell/cipher.c | 40 ++++++++++++++++++++++------------------ drivers/crypto/marvell/hash.c | 36 +++++++++++++++--------------------- drivers/crypto/marvell/tdma.c | 8 ++++---- 5 files changed, 56 insertions(+), 62 deletions(-)
drivers/crypto/marvell/cesa.c +2 -1
@@ -111,7 +111,8 @@ static irqreturn_t mv_cesa_int(int irq, void *priv)return ret; } -int mv_cesa_queue_req (struct crypto_async_request *req) +int mv_cesa_queue_req (struct crypto_async_request *req, +struct mv_cesa_req *creq) {int ret;int i;
drivers/crypto/marvell/cesa.h +13 -18
@@ -509,21 +509,11 @@ enum mv_cesa_req_type {/** * struct mv_cesa_req - CESA request -* @type: request type * @engine: engine associated with this request +* @chain: list of tdma descriptors associated with this request */ struct mv_cesa_req { -enum mv_cesa_req_type type;struct mv_cesa_engine *engine; -}; - -/** -* struct mv_cesa_tdma_req - CESA TDMA request -* @base: base information -* @chain: TDMA chain -*/ -struct mv_cesa_tdma_req { -struct mv_cesa_req base;struct mv_cesa_tdma_chain chain; };
@@ -562,7 +552,6 @@ struct mv_cesa_ablkcipher_std_req {struct mv_cesa_ablkcipher_req {union {struct mv_cesa_req base; -struct mv_cesa_tdma_req dma;struct mv_cesa_ablkcipher_std_req std; } req;int src_nents;
@@ -587,7 +576,6 @@ struct mv_cesa_ahash_std_req {* @cache_dma: DMA address of the cache buffer */ struct mv_cesa_ahash_dma_req { -struct mv_cesa_tdma_req base;u8 *padding;dma_addr_t padding_dma;u8 *cache;
@@ -625,6 +613,12 @@ struct mv_cesa_ahash_req {extern struct mv_cesa_dev *cesa_dev; +static inline enum mv_cesa_req_type +mv_cesa_req_get_type (struct mv_cesa_req *req) +{ +return req->chain.first ?CESA_DMA_REQ :CESA_STD_REQ ; +} +static inline void mv_cesa_update_op_cfg (struct mv_cesa_op_ctx *op,u32 cfg,u32 mask) {
@@ -697,7 +691,8 @@ static inline bool mv_cesa_mac_op_is_first_frag(const struct mv_cesa_op_ctx *op)CESA_SA_DESC_CFG_FIRST_FRAG ; } -int mv_cesa_queue_req (struct crypto_async_request *req); +int mv_cesa_queue_req (struct crypto_async_request *req, +struct mv_cesa_req *creq);/* * Helper function that indicates whether a crypto request needs to be
@@ -767,9 +762,9 @@ static inline bool mv_cesa_req_dma_iter_next_op(struct mv_cesa_dma_iter *iter)return iter->op_len; } -void mv_cesa_dma_step (struct mv_cesa_tdma_req *dreq); +void mv_cesa_dma_step (struct mv_cesa_req *dreq); -static inline int mv_cesa_dma_process (struct mv_cesa_tdma_req *dreq, +static inline int mv_cesa_dma_process (struct mv_cesa_req *dreq,u32 status) {if (!(status &CESA_SA_INT_ACC0_IDMA_DONE ))
@@ -781,10 +776,10 @@ static inline int mv_cesa_dma_process(struct mv_cesa_tdma_req *dreq,return 0 ; } -void mv_cesa_dma_prepare (struct mv_cesa_tdma_req *dreq, +void mv_cesa_dma_prepare (struct mv_cesa_req *dreq,struct mv_cesa_engine *engine); +void mv_cesa_dma_cleanup (struct mv_cesa_req *dreq); -void mv_cesa_dma_cleanup (struct mv_cesa_tdma_req *dreq);static inline void mv_cesa_tdma_desc_iter_init (struct mv_cesa_tdma_chain *chain)
drivers/crypto/marvell/cipher.c +22 -18
@@ -70,14 +70,14 @@ mv_cesa_ablkcipher_dma_cleanup(struct ablkcipher_request *req)dma_unmap_sg (cesa_dev->dev, req->src, creq->src_nents,DMA_BIDIRECTIONAL ); } -mv_cesa_dma_cleanup (&creq->req.dma); +mv_cesa_dma_cleanup (&creq->req.base); }static inline void mv_cesa_ablkcipher_cleanup (struct ablkcipher_request *req) {struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req); -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_ablkcipher_dma_cleanup (req); }
@@ -141,19 +141,19 @@ static int mv_cesa_ablkcipher_process(struct crypto_async_request *req,struct ablkcipher_request *ablkreq =ablkcipher_request_cast (req);struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq); -if (creq->req.base.type ==CESA_DMA_REQ ) { +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) {int ret; -struct mv_cesa_tdma_req *dreq; +struct mv_cesa_req *basereq;unsigned int ivsize; - ret =mv_cesa_dma_process (&creq->req.dma, status); + ret =mv_cesa_dma_process (&creq->req.base, status);if (ret)return ret; - dreq = &creq->req.dma; + basereq = &creq->req.base; ivsize =crypto_ablkcipher_ivsize (crypto_ablkcipher_reqtfm (ablkreq)); -memcpy_fromio (ablkreq->info, dreq->chain.last->data, ivsize); +memcpy_fromio (ablkreq->info, basereq->chain.last->data, ivsize);return ret; }return mv_cesa_ablkcipher_std_process (ablkreq, status);
@@ -164,8 +164,8 @@ static void mv_cesa_ablkcipher_step(struct crypto_async_request *req)struct ablkcipher_request *ablkreq =ablkcipher_request_cast (req);struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq); -if (creq->req.base.type ==CESA_DMA_REQ ) -mv_cesa_dma_step (&creq->req.dma); +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) +mv_cesa_dma_step (&creq->req.base);else mv_cesa_ablkcipher_std_step (ablkreq); }
@@ -174,9 +174,9 @@ static inline void mv_cesa_ablkcipher_dma_prepare(struct ablkcipher_request *req) {struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req); -struct mv_cesa_tdma_req *dreq = &creq->req.dma; +struct mv_cesa_req *dreq = &creq->req.base; -mv_cesa_dma_prepare (dreq, dreq->base.engine); +mv_cesa_dma_prepare (dreq, dreq->engine); } static inline void
@@ -199,7 +199,7 @@ static inline void mv_cesa_ablkcipher_prepare(struct crypto_async_request *req,struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq); creq->req.base.engine = engine; -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_ablkcipher_dma_prepare (ablkreq);else mv_cesa_ablkcipher_std_prepare (ablkreq);
@@ -302,14 +302,13 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req,struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);gfp_t flags = (req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ) ?GFP_KERNEL :GFP_ATOMIC ; -struct mv_cesa_tdma_req *dreq = &creq->req.dma; +struct mv_cesa_req *dreq = &creq->req.base;struct mv_cesa_ablkcipher_dma_iter iter;struct mv_cesa_tdma_chain chain;bool skip_ctx = false;int ret;unsigned int ivsize; - dreq->base.type =CESA_DMA_REQ ; dreq->chain.first =NULL ; dreq->chain.last =NULL ;
@@ -397,10 +396,12 @@ mv_cesa_ablkcipher_std_req_init(struct ablkcipher_request *req, {struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std; +struct mv_cesa_req *basereq = &creq->req.base; - sreq->base.type =CESA_STD_REQ ; sreq->op = *op_templ; sreq->skip_ctx = false; + basereq->chain.first =NULL ; + basereq->chain.last =NULL ;return 0 ; }
@@ -442,6 +443,7 @@ static int mv_cesa_ablkcipher_req_init(struct ablkcipher_request *req,static int mv_cesa_des_op (struct ablkcipher_request *req,struct mv_cesa_op_ctx *tmpl) { +struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);struct mv_cesa_des_ctx *ctx =crypto_tfm_ctx (req->base.tfm);int ret;
@@ -454,7 +456,7 @@ static int mv_cesa_des_op(struct ablkcipher_request *req,if (ret)return ret; - ret =mv_cesa_queue_req (&req->base); + ret =mv_cesa_queue_req (&req->base, &creq->req.base);if (mv_cesa_req_needs_cleanup (&req->base, ret))mv_cesa_ablkcipher_cleanup (req);
@@ -562,6 +564,7 @@ struct crypto_alg mv_cesa_cbc_des_alg = {static int mv_cesa_des3_op (struct ablkcipher_request *req,struct mv_cesa_op_ctx *tmpl) { +struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);struct mv_cesa_des3_ctx *ctx =crypto_tfm_ctx (req->base.tfm);int ret;
@@ -574,7 +577,7 @@ static int mv_cesa_des3_op(struct ablkcipher_request *req,if (ret)return ret; - ret =mv_cesa_queue_req (&req->base); + ret =mv_cesa_queue_req (&req->base, &creq->req.base);if (mv_cesa_req_needs_cleanup (&req->base, ret))mv_cesa_ablkcipher_cleanup (req);
@@ -688,6 +691,7 @@ struct crypto_alg mv_cesa_cbc_des3_ede_alg = {static int mv_cesa_aes_op (struct ablkcipher_request *req,struct mv_cesa_op_ctx *tmpl) { +struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);struct mv_cesa_aes_ctx *ctx =crypto_tfm_ctx (req->base.tfm);int ret, i;u32 *key;
@@ -716,7 +720,7 @@ static int mv_cesa_aes_op(struct ablkcipher_request *req,if (ret)return ret; - ret =mv_cesa_queue_req (&req->base); + ret =mv_cesa_queue_req (&req->base, &creq->req.base);if (mv_cesa_req_needs_cleanup (&req->base, ret))mv_cesa_ablkcipher_cleanup (req);
drivers/crypto/marvell/hash.c +15 -21
@@ -103,14 +103,14 @@ static inline void mv_cesa_ahash_dma_cleanup(struct ahash_request *req)dma_unmap_sg (cesa_dev->dev, req->src, creq->src_nents,DMA_TO_DEVICE );mv_cesa_ahash_dma_free_cache (&creq->req.dma); -mv_cesa_dma_cleanup (&creq->req.dma.base); +mv_cesa_dma_cleanup (&creq->req.base); }static inline void mv_cesa_ahash_cleanup (struct ahash_request *req) {struct mv_cesa_ahash_req *creq =ahash_request_ctx (req); -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_ahash_dma_cleanup (req); }
@@ -118,7 +118,7 @@ static void mv_cesa_ahash_last_cleanup(struct ahash_request *req) {struct mv_cesa_ahash_req *creq =ahash_request_ctx (req); -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_ahash_dma_last_cleanup (req); }
@@ -256,9 +256,9 @@ static int mv_cesa_ahash_std_process(struct ahash_request *req, u32 status)static inline void mv_cesa_ahash_dma_prepare (struct ahash_request *req) {struct mv_cesa_ahash_req *creq =ahash_request_ctx (req); -struct mv_cesa_tdma_req *dreq = &creq->req.dma.base; +struct mv_cesa_req *dreq = &creq->req.base; -mv_cesa_dma_prepare (dreq, dreq->base.engine); +mv_cesa_dma_prepare (dreq, dreq->engine); }static void mv_cesa_ahash_std_prepare (struct ahash_request *req)
@@ -277,8 +277,8 @@ static void mv_cesa_ahash_step(struct crypto_async_request *req)struct ahash_request *ahashreq =ahash_request_cast (req);struct mv_cesa_ahash_req *creq =ahash_request_ctx (ahashreq); -if (creq->req.base.type ==CESA_DMA_REQ ) -mv_cesa_dma_step (&creq->req.dma.base); +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) +mv_cesa_dma_step (&creq->req.base);else mv_cesa_ahash_std_step (ahashreq); }
@@ -291,8 +291,8 @@ static int mv_cesa_ahash_process(struct crypto_async_request *req, u32 status)unsigned int digsize;int ret, i; -if (creq->req.base.type ==CESA_DMA_REQ ) - ret =mv_cesa_dma_process (&creq->req.dma.base, status); +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) + ret =mv_cesa_dma_process (&creq->req.base, status);else ret =mv_cesa_ahash_std_process (ahashreq, status);
@@ -340,7 +340,7 @@ static void mv_cesa_ahash_prepare(struct crypto_async_request *req, creq->req.base.engine = engine; -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_ahash_dma_prepare (ahashreq);else mv_cesa_ahash_std_prepare (ahashreq);
@@ -555,8 +555,7 @@ static int mv_cesa_ahash_dma_req_init(struct ahash_request *req)struct mv_cesa_ahash_req *creq =ahash_request_ctx (req);gfp_t flags = (req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ) ?GFP_KERNEL :GFP_ATOMIC ; -struct mv_cesa_ahash_dma_req *ahashdreq = &creq->req.dma; -struct mv_cesa_tdma_req *dreq = &ahashdreq->base; +struct mv_cesa_req *dreq = &creq->req.base;struct mv_cesa_ahash_dma_iter iter;struct mv_cesa_op_ctx *op =NULL ;unsigned int frag_len;
@@ -662,11 +661,6 @@ static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached)struct mv_cesa_ahash_req *creq =ahash_request_ctx (req);int ret; -if (cesa_dev->caps->has_tdma) - creq->req.base.type =CESA_DMA_REQ ; -else - creq->req.base.type =CESA_STD_REQ ; - creq->src_nents =sg_nents_for_len (req->src, req->nbytes);if (creq->src_nents <0 ) {dev_err (cesa_dev->dev,"Invalid number of src SG" );
@@ -680,7 +674,7 @@ static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached)if (*cached)return 0 ; -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) ret =mv_cesa_ahash_dma_req_init (req);return ret;
@@ -700,7 +694,7 @@ static int mv_cesa_ahash_update(struct ahash_request *req)if (cached)return 0 ; - ret =mv_cesa_queue_req (&req->base); + ret =mv_cesa_queue_req (&req->base, &creq->req.base);if (mv_cesa_req_needs_cleanup (&req->base, ret))mv_cesa_ahash_cleanup (req);
@@ -725,7 +719,7 @@ static int mv_cesa_ahash_final(struct ahash_request *req)if (cached)return 0 ; - ret =mv_cesa_queue_req (&req->base); + ret =mv_cesa_queue_req (&req->base, &creq->req.base);if (mv_cesa_req_needs_cleanup (&req->base, ret))mv_cesa_ahash_cleanup (req);
@@ -750,7 +744,7 @@ static int mv_cesa_ahash_finup(struct ahash_request *req)if (cached)return 0 ; - ret =mv_cesa_queue_req (&req->base); + ret =mv_cesa_queue_req (&req->base, &creq->req.base);if (mv_cesa_req_needs_cleanup (&req->base, ret))mv_cesa_ahash_cleanup (req);
drivers/crypto/marvell/tdma.c +4 -4
@@ -37,9 +37,9 @@ bool mv_cesa_req_dma_iter_next_transfer(struct mv_cesa_dma_iter *iter,return true; } -void mv_cesa_dma_step (struct mv_cesa_tdma_req *dreq) +void mv_cesa_dma_step (struct mv_cesa_req *dreq) { -struct mv_cesa_engine *engine = dreq->base.engine; +struct mv_cesa_engine *engine = dreq->engine;writel_relaxed (0 , engine->regs +CESA_SA_CFG );
@@ -58,7 +58,7 @@ void mv_cesa_dma_step(struct mv_cesa_tdma_req *dreq)writel (CESA_SA_CMD_EN_CESA_SA_ACCL0 , engine->regs +CESA_SA_CMD ); } -void mv_cesa_dma_cleanup (struct mv_cesa_tdma_req *dreq) +void mv_cesa_dma_cleanup (struct mv_cesa_req *dreq) {struct mv_cesa_tdma_desc *tdma;
@@ -81,7 +81,7 @@ void mv_cesa_dma_cleanup(struct mv_cesa_tdma_req *dreq) dreq->chain.last =NULL ; } -void mv_cesa_dma_prepare (struct mv_cesa_tdma_req *dreq, +void mv_cesa_dma_prepare (struct mv_cesa_req *dreq,struct mv_cesa_engine *engine) {struct mv_cesa_tdma_desc *tdma;
Signature · 1 line
2.7.4
PATCH 4/7 crypto: marvell: Moving the tdma chain out of mv_cesa_tdma_req
Quoted 1 line · On Wed, 15 Jun 2016 21:15:31 +0200 Romain Perier…
Actually the only way to access the tdma chain is to use the 'req' union
Currently, ...
Quoted 5 lines
from a mv_cesa_{ablkcipher,ahash}. This will soon become a problem if we want to handle the TDMA chaining vs standard/non-DMA processing in a generic way (with generic functions at the
cesa.clevel detecting whether the request should be queued at the DMA level or not). Hence the decision to move the chain field a themv_cesa_reqlevel at the expense
at
Quoted 32 lines
of adding 2 void * fields to all request contexts (including non-DMA ones). To limit the overhead, we get rid of the type field, which can now be deduced from the
req->chain.firstvalue.Signed-off-by Romain Perier <[email protected]>--- drivers/crypto/marvell/cesa.c | 3 ++- drivers/crypto/marvell/cesa.h | 31 +++++++++++++------------------ drivers/crypto/marvell/cipher.c | 40 ++++++++++++++++++++++------------------ drivers/crypto/marvell/hash.c | 36 +++++++++++++++--------------------- drivers/crypto/marvell/tdma.c | 8 ++++---- 5 files changed, 56 insertions(+), 62 deletions(-)drivers/crypto/marvell/cesa.c +2
-1@@ -111,7 +111,8 @@ static irqreturn_t mv_cesa_int(int irq, void *priv)return ret; } -int mv_cesa_queue_req (struct crypto_async_request *req) +int mv_cesa_queue_req (struct crypto_async_request *req, +struct mv_cesa_req *creq) {int ret;int i;drivers/crypto/marvell/cesa.h +0
-0
drivers/crypto/marvell/cesa.h enum mv_cesa_req_type { · line 513
Quoted 6 lines
drivers/crypto/marvell/cesa.h +1
-1@@ -509,21 +509,11 @@ enum mv_cesa_req_type {/** * struct mv_cesa_req - CESA request -* @type: request type * @engine: engine associated with this request +* @chain: list of tdma descriptors associated with this request
^ extra white space.
Quoted 17 lines
drivers/crypto/marvell/cesa.h +0
-10*/ struct mv_cesa_req { -enum mv_cesa_req_type type;struct mv_cesa_engine *engine; -}; - -/** -* struct mv_cesa_tdma_req - CESA TDMA request -* @base: base information -* @chain: TDMA chain -*/ -struct mv_cesa_tdma_req { -struct mv_cesa_req base;struct mv_cesa_tdma_chain chain; };
drivers/crypto/marvell/cesa.h struct mv_cesa_ablkcipher_std_req { · line 555
Quoted 5 lines
drivers/crypto/marvell/cesa.h +0
-1@@ -562,7 +552,6 @@ struct mv_cesa_ablkcipher_std_req {struct mv_cesa_ablkcipher_req {union {struct mv_cesa_req base; -struct mv_cesa_tdma_req dma;struct mv_cesa_ablkcipher_std_req std;
Now that the dma specific fields are part of the base request there's no reason to keep this union.
You can just put struct mv_cesa_req base; directly under struct mv_cesa_ablkcipher_req, and move mv_cesa_ablkcipher_std_req fields in mv_cesa_ablkcipher_req.
Quoted 82 lines
drivers/crypto/marvell/cesa.h +12
-6} req;int src_nents;@@ -587,7 +576,6 @@ struct mv_cesa_ahash_std_req {* @cache_dma: DMA address of the cache buffer */ struct mv_cesa_ahash_dma_req { -struct mv_cesa_tdma_req base;u8 *padding;dma_addr_t padding_dma;u8 *cache;@@ -625,6 +613,12 @@ struct mv_cesa_ahash_req {extern struct mv_cesa_dev *cesa_dev; +static inline enum mv_cesa_req_type +mv_cesa_req_get_type (struct mv_cesa_req *req) +{ +return req->chain.first ?CESA_DMA_REQ :CESA_STD_REQ ; +} +static inline void mv_cesa_update_op_cfg (struct mv_cesa_op_ctx *op,u32 cfg,u32 mask) {@@ -697,7 +691,8 @@ static inline bool mv_cesa_mac_op_is_first_frag(const struct mv_cesa_op_ctx *op)CESA_SA_DESC_CFG_FIRST_FRAG ; } -int mv_cesa_queue_req (struct crypto_async_request *req); +int mv_cesa_queue_req (struct crypto_async_request *req, +struct mv_cesa_req *creq);/* * Helper function that indicates whether a crypto request needs to be @@ -767,9 +762,9 @@ static inline bool mv_cesa_req_dma_iter_next_op(struct mv_cesa_dma_iter *iter)return iter->op_len; } -void mv_cesa_dma_step (struct mv_cesa_tdma_req *dreq); +void mv_cesa_dma_step (struct mv_cesa_req *dreq); -static inline int mv_cesa_dma_process (struct mv_cesa_tdma_req *dreq, +static inline int mv_cesa_dma_process (struct mv_cesa_req *dreq,u32 status) {if (!(status &CESA_SA_INT_ACC0_IDMA_DONE ))@@ -781,10 +776,10 @@ static inline int mv_cesa_dma_process(struct mv_cesa_tdma_req *dreq,return 0 ; } -void mv_cesa_dma_prepare (struct mv_cesa_tdma_req *dreq, +void mv_cesa_dma_prepare (struct mv_cesa_req *dreq,struct mv_cesa_engine *engine); +void mv_cesa_dma_cleanup (struct mv_cesa_req *dreq); -void mv_cesa_dma_cleanup (struct mv_cesa_tdma_req *dreq);static inline void mv_cesa_tdma_desc_iter_init (struct mv_cesa_tdma_chain *chain)drivers/crypto/marvell/cipher.c +2
-2@@ -70,14 +70,14 @@ mv_cesa_ablkcipher_dma_cleanup(struct ablkcipher_request *req)dma_unmap_sg (cesa_dev->dev, req->src, creq->src_nents,DMA_BIDIRECTIONAL ); } -mv_cesa_dma_cleanup (&creq->req.dma); +mv_cesa_dma_cleanup (&creq->req.base); }static inline void mv_cesa_ablkcipher_cleanup (struct ablkcipher_request *req) {struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req); -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_ablkcipher_dma_cleanup (req); }@@ -141,19 +141,19 @@ static int mv_cesa_ablkcipher_process(struct crypto_async_request *req,struct ablkcipher_request *ablkreq =ablkcipher_request_cast (req);struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq);
drivers/crypto/marvell/cipher.c static int mv_cesa_ablkcipher_process(struct crypto_async_request *req, · line 149
Quoted 10 lines
drivers/crypto/marvell/cipher.c +3
-3-if (creq->req.base.type ==CESA_DMA_REQ ) { +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) {int ret; -struct mv_cesa_tdma_req *dreq; +struct mv_cesa_req *basereq;unsigned int ivsize; - ret =mv_cesa_dma_process (&creq->req.dma, status); + ret =mv_cesa_dma_process (&creq->req.base, status);
Initialize basereq earlier and pass it as the first argument of mv_cesa_dma_process().
Quoted 24 lines
drivers/crypto/marvell/cipher.c +4
-4if (ret)return ret; - dreq = &creq->req.dma; + basereq = &creq->req.base; ivsize =crypto_ablkcipher_ivsize (crypto_ablkcipher_reqtfm (ablkreq)); -memcpy_fromio (ablkreq->info, dreq->chain.last->data, ivsize); +memcpy_fromio (ablkreq->info, basereq->chain.last->data, ivsize);return ret; }return mv_cesa_ablkcipher_std_process (ablkreq, status);@@ -164,8 +164,8 @@ static void mv_cesa_ablkcipher_step(struct crypto_async_request *req)struct ablkcipher_request *ablkreq =ablkcipher_request_cast (req);struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq); -if (creq->req.base.type ==CESA_DMA_REQ ) -mv_cesa_dma_step (&creq->req.dma); +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) +mv_cesa_dma_step (&creq->req.base);else mv_cesa_ablkcipher_std_step (ablkreq); }
drivers/crypto/marvell/cipher.c static inline void · line 177
Quoted 5 lines
drivers/crypto/marvell/cipher.c +1
-1@@ -174,9 +174,9 @@ static inline void mv_cesa_ablkcipher_dma_prepare(struct ablkcipher_request *req) {struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req); -struct mv_cesa_tdma_req *dreq = &creq->req.dma; +struct mv_cesa_req *dreq = &creq->req.base;
You named it basereq in mv_cesa_ablkcipher_step(). Try to be consistent, no matter the name.
Quoted 16 lines
drivers/crypto/marvell/cipher.c +2
-2-mv_cesa_dma_prepare (dreq, dreq->base.engine); +mv_cesa_dma_prepare (dreq, dreq->engine); } static inline void@@ -199,7 +199,7 @@ static inline void mv_cesa_ablkcipher_prepare(struct crypto_async_request *req,struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq); creq->req.base.engine = engine; -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_ablkcipher_dma_prepare (ablkreq);else mv_cesa_ablkcipher_std_prepare (ablkreq);
drivers/crypto/marvell/cipher.c static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req, · line 305
Quoted 5 lines
drivers/crypto/marvell/cipher.c +1
-1@@ -302,14 +302,13 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req,struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);gfp_t flags = (req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ) ?GFP_KERNEL :GFP_ATOMIC ; -struct mv_cesa_tdma_req *dreq = &creq->req.dma; +struct mv_cesa_req *dreq = &creq->req.base;
Ditto.
Quoted 106 lines
drivers/crypto/marvell/cipher.c +9
-5struct mv_cesa_ablkcipher_dma_iter iter;struct mv_cesa_tdma_chain chain;bool skip_ctx = false;int ret;unsigned int ivsize; - dreq->base.type =CESA_DMA_REQ ; dreq->chain.first =NULL ; dreq->chain.last =NULL ;@@ -397,10 +396,12 @@ mv_cesa_ablkcipher_std_req_init(struct ablkcipher_request *req, {struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std; +struct mv_cesa_req *basereq = &creq->req.base; - sreq->base.type =CESA_STD_REQ ; sreq->op = *op_templ; sreq->skip_ctx = false; + basereq->chain.first =NULL ; + basereq->chain.last =NULL ;return 0 ; }@@ -442,6 +443,7 @@ static int mv_cesa_ablkcipher_req_init(struct ablkcipher_request *req,static int mv_cesa_des_op (struct ablkcipher_request *req,struct mv_cesa_op_ctx *tmpl) { +struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);struct mv_cesa_des_ctx *ctx =crypto_tfm_ctx (req->base.tfm);int ret;@@ -454,7 +456,7 @@ static int mv_cesa_des_op(struct ablkcipher_request *req,if (ret)return ret; - ret =mv_cesa_queue_req (&req->base); + ret =mv_cesa_queue_req (&req->base, &creq->req.base);if (mv_cesa_req_needs_cleanup (&req->base, ret))mv_cesa_ablkcipher_cleanup (req);@@ -562,6 +564,7 @@ struct crypto_alg mv_cesa_cbc_des_alg = {static int mv_cesa_des3_op (struct ablkcipher_request *req,struct mv_cesa_op_ctx *tmpl) { +struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);struct mv_cesa_des3_ctx *ctx =crypto_tfm_ctx (req->base.tfm);int ret;@@ -574,7 +577,7 @@ static int mv_cesa_des3_op(struct ablkcipher_request *req,if (ret)return ret; - ret =mv_cesa_queue_req (&req->base); + ret =mv_cesa_queue_req (&req->base, &creq->req.base);if (mv_cesa_req_needs_cleanup (&req->base, ret))mv_cesa_ablkcipher_cleanup (req);@@ -688,6 +691,7 @@ struct crypto_alg mv_cesa_cbc_des3_ede_alg = {static int mv_cesa_aes_op (struct ablkcipher_request *req,struct mv_cesa_op_ctx *tmpl) { +struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);struct mv_cesa_aes_ctx *ctx =crypto_tfm_ctx (req->base.tfm);int ret, i;u32 *key;@@ -716,7 +720,7 @@ static int mv_cesa_aes_op(struct ablkcipher_request *req,if (ret)return ret; - ret =mv_cesa_queue_req (&req->base); + ret =mv_cesa_queue_req (&req->base, &creq->req.base);if (mv_cesa_req_needs_cleanup (&req->base, ret))mv_cesa_ablkcipher_cleanup (req);drivers/crypto/marvell/hash.c +3
-3@@ -103,14 +103,14 @@ static inline void mv_cesa_ahash_dma_cleanup(struct ahash_request *req)dma_unmap_sg (cesa_dev->dev, req->src, creq->src_nents,DMA_TO_DEVICE );mv_cesa_ahash_dma_free_cache (&creq->req.dma); -mv_cesa_dma_cleanup (&creq->req.dma.base); +mv_cesa_dma_cleanup (&creq->req.base); }static inline void mv_cesa_ahash_cleanup (struct ahash_request *req) {struct mv_cesa_ahash_req *creq =ahash_request_ctx (req); -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_ahash_dma_cleanup (req); }@@ -118,7 +118,7 @@ static void mv_cesa_ahash_last_cleanup(struct ahash_request *req) {struct mv_cesa_ahash_req *creq =ahash_request_ctx (req); -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_ahash_dma_last_cleanup (req); }
drivers/crypto/marvell/hash.c static int mv_cesa_ahash_std_process(struct ahash_request *req, u32 status) · line 259
Quoted 5 lines
drivers/crypto/marvell/hash.c +1
-1@@ -256,9 +256,9 @@ static int mv_cesa_ahash_std_process(struct ahash_request *req, u32 status)static inline void mv_cesa_ahash_dma_prepare (struct ahash_request *req) {struct mv_cesa_ahash_req *creq =ahash_request_ctx (req); -struct mv_cesa_tdma_req *dreq = &creq->req.dma.base; +struct mv_cesa_req *dreq = &creq->req.base;
Ditto.
Quoted 38 lines
drivers/crypto/marvell/hash.c +6
-6-mv_cesa_dma_prepare (dreq, dreq->base.engine); +mv_cesa_dma_prepare (dreq, dreq->engine); }static void mv_cesa_ahash_std_prepare (struct ahash_request *req)@@ -277,8 +277,8 @@ static void mv_cesa_ahash_step(struct crypto_async_request *req)struct ahash_request *ahashreq =ahash_request_cast (req);struct mv_cesa_ahash_req *creq =ahash_request_ctx (ahashreq); -if (creq->req.base.type ==CESA_DMA_REQ ) -mv_cesa_dma_step (&creq->req.dma.base); +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) +mv_cesa_dma_step (&creq->req.base);else mv_cesa_ahash_std_step (ahashreq); }@@ -291,8 +291,8 @@ static int mv_cesa_ahash_process(struct crypto_async_request *req, u32 status)unsigned int digsize;int ret, i; -if (creq->req.base.type ==CESA_DMA_REQ ) - ret =mv_cesa_dma_process (&creq->req.dma.base, status); +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) + ret =mv_cesa_dma_process (&creq->req.base, status);else ret =mv_cesa_ahash_std_process (ahashreq, status);@@ -340,7 +340,7 @@ static void mv_cesa_ahash_prepare(struct crypto_async_request *req, creq->req.base.engine = engine; -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_ahash_dma_prepare (ahashreq);else mv_cesa_ahash_std_prepare (ahashreq);
drivers/crypto/marvell/hash.c static int mv_cesa_ahash_dma_req_init(struct ahash_request *req) · line 558
Quoted 6 lines
drivers/crypto/marvell/hash.c +1
-2@@ -555,8 +555,7 @@ static int mv_cesa_ahash_dma_req_init(struct ahash_request *req)struct mv_cesa_ahash_req *creq =ahash_request_ctx (req);gfp_t flags = (req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ) ?GFP_KERNEL :GFP_ATOMIC ; -struct mv_cesa_ahash_dma_req *ahashdreq = &creq->req.dma; -struct mv_cesa_tdma_req *dreq = &ahashdreq->base; +struct mv_cesa_req *dreq = &creq->req.base;
Ditto.
drivers/crypto/marvell/hash.c static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached) · line 669
Quoted 12 lines
drivers/crypto/marvell/hash.c +0
-5struct mv_cesa_ahash_dma_iter iter;struct mv_cesa_op_ctx *op =NULL ;unsigned int frag_len;@@ -662,11 +661,6 @@ static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached)struct mv_cesa_ahash_req *creq =ahash_request_ctx (req);int ret; -if (cesa_dev->caps->has_tdma) - creq->req.base.type =CESA_DMA_REQ ; -else - creq->req.base.type =CESA_STD_REQ ; -
Hm, where is it decided now? I mean, I don't see this test anywhere else in your patch, which means you're now always using standard mode.
drivers/crypto/marvell/hash.c static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached) · line 677
Quoted 9 lines
drivers/crypto/marvell/hash.c +1
-1creq->src_nents =sg_nents_for_len (req->src, req->nbytes);if (creq->src_nents <0 ) {dev_err (cesa_dev->dev,"Invalid number of src SG" );@@ -680,7 +674,7 @@ static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached)if (*cached)return 0 ; -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )
Should be
if (cesa_dev->caps->has_tdma)
Quoted 64 lines
drivers/crypto/marvell/hash.c +3
-3ret =mv_cesa_ahash_dma_req_init (req);return ret;@@ -700,7 +694,7 @@ static int mv_cesa_ahash_update(struct ahash_request *req)if (cached)return 0 ; - ret =mv_cesa_queue_req (&req->base); + ret =mv_cesa_queue_req (&req->base, &creq->req.base);if (mv_cesa_req_needs_cleanup (&req->base, ret))mv_cesa_ahash_cleanup (req);@@ -725,7 +719,7 @@ static int mv_cesa_ahash_final(struct ahash_request *req)if (cached)return 0 ; - ret =mv_cesa_queue_req (&req->base); + ret =mv_cesa_queue_req (&req->base, &creq->req.base);if (mv_cesa_req_needs_cleanup (&req->base, ret))mv_cesa_ahash_cleanup (req);@@ -750,7 +744,7 @@ static int mv_cesa_ahash_finup(struct ahash_request *req)if (cached)return 0 ; - ret =mv_cesa_queue_req (&req->base); + ret =mv_cesa_queue_req (&req->base, &creq->req.base);if (mv_cesa_req_needs_cleanup (&req->base, ret))mv_cesa_ahash_cleanup (req);drivers/crypto/marvell/tdma.c +4
-4@@ -37,9 +37,9 @@ bool mv_cesa_req_dma_iter_next_transfer(struct mv_cesa_dma_iter *iter,return true; } -void mv_cesa_dma_step (struct mv_cesa_tdma_req *dreq) +void mv_cesa_dma_step (struct mv_cesa_req *dreq) { -struct mv_cesa_engine *engine = dreq->base.engine; +struct mv_cesa_engine *engine = dreq->engine;writel_relaxed (0 , engine->regs +CESA_SA_CFG );@@ -58,7 +58,7 @@ void mv_cesa_dma_step(struct mv_cesa_tdma_req *dreq)writel (CESA_SA_CMD_EN_CESA_SA_ACCL0 , engine->regs +CESA_SA_CMD ); } -void mv_cesa_dma_cleanup (struct mv_cesa_tdma_req *dreq) +void mv_cesa_dma_cleanup (struct mv_cesa_req *dreq) {struct mv_cesa_tdma_desc *tdma;@@ -81,7 +81,7 @@ void mv_cesa_dma_cleanup(struct mv_cesa_tdma_req *dreq) dreq->chain.last =NULL ; } -void mv_cesa_dma_prepare (struct mv_cesa_tdma_req *dreq, +void mv_cesa_dma_prepare (struct mv_cesa_req *dreq,struct mv_cesa_engine *engine) {struct mv_cesa_tdma_desc *tdma;
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 4/7 crypto: marvell: Moving the tdma chain out of mv_cesa_tdma_req
Hello,
Le 15/06/2016 22:42, Boris Brezillon a ?crit :
Quoted 6 lines
Quoted 1 line · On Wed, 15 Jun 2016 21:15:31 +0200 Romain Perier…
Actually the only way to access the tdma chain is to use the 'req' union
Currently, ...
ok
Quoted 6 lines
Now that the dma specific fields are part of the base request there's no reason to keep this union.
You can just put struct
mv_cesa_reqbase; directly under structmv_cesa_ablkcipher_req, and movemv_cesa_ablkcipher_std_reqfields inmv_cesa_ablkcipher_req.
Well, I think that I might keep the changes related to mv_cesa_tdma_req in this commit (+ put struct mv_cesa_req base; direct under struct mv_cesa_ablkcipher_req) and move the changes related to mv_cesa_ablkcipher_std_req into another commit. What do you think ?
Quoted 2 lines
Initialize basereq earlier and pass it as the first argument of
mv_cesa_dma_process().
ok
Quoted 9 lines
drivers/crypto/marvell/cipher.c static inline void · line 177
Quoted 6 lines
drivers/crypto/marvell/cipher.c +1
-1@@ -174,9 +174,9 @@ static inline void mv_cesa_ablkcipher_dma_prepare(struct ablkcipher_request *req) {struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req); -struct mv_cesa_tdma_req *dreq = &creq->req.dma; +struct mv_cesa_req *dreq = &creq->req.base;You named it basereq in
mv_cesa_ablkcipher_step(). Try to be consistent, no matter the name.
ack
Quoted 11 lines
Quoted 11 lines
drivers/crypto/marvell/cipher.c +1
-1-mv_cesa_dma_prepare (dreq, dreq->base.engine); +mv_cesa_dma_prepare (dreq, dreq->engine); } static inline void@@ -199,7 +199,7 @@ static inline void mv_cesa_ablkcipher_prepare(struct crypto_async_request *req,struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq); creq->req.base.engine = engine;
Quoted 13 lines
drivers/crypto/marvell/cipher.c static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req, · line 305
Quoted 11 lines
drivers/crypto/marvell/cipher.c +2
-2-if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_ablkcipher_dma_prepare (ablkreq);else mv_cesa_ablkcipher_std_prepare (ablkreq);@@ -302,14 +302,13 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req,struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);gfp_t flags = (req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ) ?GFP_KERNEL :GFP_ATOMIC ; -struct mv_cesa_tdma_req *dreq = &creq->req.dma; +struct mv_cesa_req *dreq = &creq->req.base;Ditto.
ack
Quoted 8 lines
drivers/crypto/marvell/hash.c static int mv_cesa_ahash_std_process(struct ahash_request *req, u32 status) · line 259
Quoted 6 lines
drivers/crypto/marvell/hash.c +1
-1@@ -256,9 +256,9 @@ static int mv_cesa_ahash_std_process(struct ahash_request *req, u32 status)static inline void mv_cesa_ahash_dma_prepare (struct ahash_request *req) {struct mv_cesa_ahash_req *creq =ahash_request_ctx (req); -struct mv_cesa_tdma_req *dreq = &creq->req.dma.base; +struct mv_cesa_req *dreq = &creq->req.base;Ditto.
ack
Quoted 4 lines
Quoted 4 lines
drivers/crypto/marvell/hash.c +0
-0@@ -340,7 +340,7 @@ static void mv_cesa_ahash_prepare(struct crypto_async_request *req, creq->req.base.engine = engine;
Quoted 14 lines
drivers/crypto/marvell/hash.c static int mv_cesa_ahash_dma_req_init(struct ahash_request *req) · line 558
Quoted 12 lines
drivers/crypto/marvell/hash.c +2
-3-if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_ahash_dma_prepare (ahashreq);else mv_cesa_ahash_std_prepare (ahashreq);@@ -555,8 +555,7 @@ static int mv_cesa_ahash_dma_req_init(struct ahash_request *req)struct mv_cesa_ahash_req *creq =ahash_request_ctx (req);gfp_t flags = (req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ) ?GFP_KERNEL :GFP_ATOMIC ; -struct mv_cesa_ahash_dma_req *ahashdreq = &creq->req.dma; -struct mv_cesa_tdma_req *dreq = &ahashdreq->base; +struct mv_cesa_req *dreq = &creq->req.base;Ditto.
ack
Quoted 8 lines
Quoted 8 lines
drivers/crypto/marvell/hash.c +0
-0struct mv_cesa_ahash_dma_iter iter;struct mv_cesa_op_ctx *op =NULL ;unsigned int frag_len;@@ -662,11 +661,6 @@ static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached)struct mv_cesa_ahash_req *creq =ahash_request_ctx (req);int ret;
Quoted 8 lines
drivers/crypto/marvell/hash.c static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached) · line 669
Quoted 5 lines
drivers/crypto/marvell/hash.c +0
-5-if (cesa_dev->caps->has_tdma) - creq->req.base.type =CESA_DMA_REQ ; -else - creq->req.base.type =CESA_STD_REQ ; -Hm, where is it decided now? I mean, I don't see this test anywhere else in your patch, which means you're now always using standard mode.
It has been replaced by mv_cesa_req_get_type() + initializing chain.first to NULL in std_init. So, that's the same thing, no ?
Quoted 8 lines
Quoted 8 lines
drivers/crypto/marvell/hash.c +0
-0creq->src_nents =sg_nents_for_len (req->src, req->nbytes);if (creq->src_nents <0 ) {dev_err (cesa_dev->dev,"Invalid number of src SG" );@@ -680,7 +674,7 @@ static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached)if (*cached)return 0 ;
Quoted 8 lines
Review static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached) · line 677
Quoted 2 lines
(quoted diff) +1
-1- if (creq->req.base.type == CESA_DMA_REQ) + if (mv_cesa_req_get_type(&creq->req.base) == CESA_DMA_REQ)Should be
if (cesa_dev->caps->has_tdma)Quoted 1 line
drivers/crypto/marvell/hash.c +0
-0ret =mv_cesa_ahash_dma_req_init (req);
Why ? mv_cesa_req_get_type() tests mv_cesa_req->chain and returns a code depending on its value. This value is initialized according to what is set un "has_tdma"...
Thanks,
Regards,
Romain
Signature · 3 lines
Romain Perier, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 4/7 crypto: marvell: Moving the tdma chain out of mv_cesa_tdma_req
Quoted 8 lines · On Thu, 16 Jun 2016 14:02:42 +0200 Romain Perier…
Quoted 6 lines
Now that the dma specific fields are part of the base request there's no reason to keep this union.
You can just put struct
mv_cesa_reqbase; directly under structmv_cesa_ablkcipher_req, and movemv_cesa_ablkcipher_std_reqfields inmv_cesa_ablkcipher_req.
Quoted 4 lines
Well, I think that I might keep the changes related to
mv_cesa_tdma_reqin this commit (+ put structmv_cesa_reqbase; direct under structmv_cesa_ablkcipher_req) and move the changes related tomv_cesa_ablkcipher_std_reqinto another commit. What do you think ?
Sounds good.
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
struct mv_cesa_ahash_dma_iter iter; struct mv_cesa_op_ctx *op = NULL; unsigned int frag_len;drivers/crypto/marvell/hash.c +0
-0@@ -662,11 +661,6 @@ static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached)struct mv_cesa_ahash_req *creq =ahash_request_ctx (req);int ret;Quoted 8 lines
drivers/crypto/marvell/hash.c static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached) · line 669
Quoted 5 lines
drivers/crypto/marvell/hash.c +0
-5-if (cesa_dev->caps->has_tdma) - creq->req.base.type =CESA_DMA_REQ ; -else - creq->req.base.type =CESA_STD_REQ ; -Hm, where is it decided now? I mean, I don't see this test anywhere else in your patch, which means you're now always using standard mode.
Quoted 2 lines
It has been replaced by
mv_cesa_req_get_type()+ initializing chain.first to NULL instd_init. So, that's the same thing, no ?
And that's exactly my point :-). When these fields are NULL the request is a STD request...
Quoted 11 lines
Quoted 11 lines
drivers/crypto/marvell/hash.c static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached) · line 677
Quoted 11 lines
drivers/crypto/marvell/hash.c +1
-1creq->src_nents =sg_nents_for_len (req->src, req->nbytes);if (creq->src_nents <0 ) {dev_err (cesa_dev->dev,"Invalid number of src SG" );@@ -680,7 +674,7 @@ static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached)if (*cached)return 0 ; -if (creq->req.base.type ==CESA_DMA_REQ ) +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )
... and here you're testing if it's a DMA request, which will always be false, since mv_cesa_ahash_dma_req_init() is the function supposed to fill the ->first and ->last fields.
Quoted 10 lines
Quoted 6 lines
Should be
if (cesa_dev->caps->has_tdma)Quoted 1 line
drivers/crypto/marvell/hash.c +0
-0ret =mv_cesa_ahash_dma_req_init (req);Why ?
mv_cesa_req_get_type()testsmv_cesa_req->chainand returns a code depending on its value. This value is initialized according to what is set un "has_tdma"...
As explained above, it's not ;).
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 4/7 crypto: marvell: Moving the tdma chain out of mv_cesa_tdma_req
In reply to Romain PerierQuoted 8 lines · On Thu, 16 Jun 2016 14:02:42 +0200 Romain Perier…
Quoted 6 lines
Now that the dma specific fields are part of the base request there's no reason to keep this union.
You can just put struct
mv_cesa_reqbase; directly under structmv_cesa_ablkcipher_req, and movemv_cesa_ablkcipher_std_reqfields inmv_cesa_ablkcipher_req.
Quoted 4 lines
Well, I think that I might keep the changes related to
mv_cesa_tdma_reqin this commit (+ put structmv_cesa_reqbase; direct under structmv_cesa_ablkcipher_req) and move the changes related tomv_cesa_ablkcipher_std_reqinto another commit. What do you think ?
After re-reading the code, I'm not sure the last part (moving mv_cesa_ablkcipher_std_req fields into mv_cesa_ablkcipher_req) is a good idea anymore.
So let's just kill the union, and move mv_cesa_ablkcipher_std_req and mv_cesa_req base in mv_cesa_ablkcipher_req (you'll also have to remove the base field from the mv_cesa_ablkcipher_std_req struct).
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 5/7 crypto: marvell: Adding a complete operation for async requests
In reply to Romain PerierSo far, the 'process' operation was used to check if the current request was correctly handled by the engine, if it was the case it copied information from the SRAM to the main memory. Now, we split this operation. We keep the 'process' operation, which still checks if the request was correctly handled by the engine or not, then we add a new operation for completion. The 'complete' method copies the content of the SRAM to memory. This will soon become useful if we want to call the process and the complete operations from different locations depending on the type of the request (different cleanup logic).
--- drivers/crypto/marvell/cesa.c | 1 + drivers/crypto/marvell/cesa.h | 3 +++ drivers/crypto/marvell/cipher.c | 47 ++++++++++++++++++++++++----------------- drivers/crypto/marvell/hash.c | 22 ++++++++++--------- 4 files changed, 44 insertions(+), 29 deletions(-)
drivers/crypto/marvell/cesa.c +1 -0
@@ -98,6 +98,7 @@ static irqreturn_t mv_cesa_int(int irq, void *priv) engine->req =NULL ;mv_cesa_dequeue_req_unlocked (engine);spin_unlock_bh (&engine->lock); + ctx->ops->complete (req); ctx->ops->cleanup (req);local_bh_disable (); req->complete (req, res);
drivers/crypto/marvell/cesa.h +3 -0
@@ -456,6 +456,8 @@ struct mv_cesa_engine {* code) * @step: launch the crypto operation on the next chunk * @cleanup: cleanup the crypto request (release associated data) +* @complete: complete the request, i.e copy result from sram or contexts +* when it is needed. */ struct mv_cesa_req_ops { void (*prepare)(struct crypto_async_request *req,
@@ -463,6 +465,7 @@ struct mv_cesa_req_ops {int (*process)(struct crypto_async_request *req,u32 status);void (*step)(struct crypto_async_request *req);void (*cleanup)(struct crypto_async_request *req); +void (*complete)(struct crypto_async_request *req); };/**
drivers/crypto/marvell/cipher.c +28 -19
83 lines not on this page · raw message
drivers/crypto/marvell/hash.c +12 -10
@@ -287,17 +287,20 @@ static int mv_cesa_ahash_process(struct crypto_async_request *req, u32 status) {struct ahash_request *ahashreq =ahash_request_cast (req);struct mv_cesa_ahash_req *creq =ahash_request_ctx (ahashreq); -struct mv_cesa_engine *engine = creq->req.base.engine; -unsigned int digsize; -int ret, i;if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) - ret =mv_cesa_dma_process (&creq->req.base, status); -else - ret =mv_cesa_ahash_std_process (ahashreq, status); +return mv_cesa_dma_process (&creq->req.base, status); -if (ret == -EINPROGRESS ) -return ret; +return mv_cesa_ahash_std_process (ahashreq, status); +} + +static void mv_cesa_ahash_complete (struct crypto_async_request *req) +{ +struct ahash_request *ahashreq =ahash_request_cast (req); +struct mv_cesa_ahash_req *creq =ahash_request_ctx (ahashreq); +struct mv_cesa_engine *engine = creq->req.base.engine; +unsigned int digsize; +int i; digsize =crypto_ahash_digestsize (crypto_ahash_reqtfm (ahashreq));for (i =0 ; i < digsize /4 ; i++)
@@ -326,8 +329,6 @@ static int mv_cesa_ahash_process(struct crypto_async_request *req, u32 status) result[i] =cpu_to_be32 (creq->state[i]); } } - -return ret; } static void mv_cesa_ahash_prepare(struct crypto_async_request *req,
@@ -366,6 +367,7 @@ static const struct mv_cesa_req_ops mv_cesa_ahash_req_ops = { .process = mv_cesa_ahash_process, .prepare = mv_cesa_ahash_prepare, .cleanup = mv_cesa_ahash_req_cleanup, + .complete = mv_cesa_ahash_complete, }; static int mv_cesa_ahash_init(struct ahash_request *req,
Signature · 1 line
2.7.4
PATCH 5/7 crypto: marvell: Adding a complete operation for async requests
Quoted 99 lines · On Wed, 15 Jun 2016 21:15:32 +0200 Romain Perier…
So far, the 'process' operation was used to check if the current request was correctly handled by the engine, if it was the case it copied information from the SRAM to the main memory. Now, we split this operation. We keep the 'process' operation, which still checks if the request was correctly handled by the engine or not, then we add a new operation for completion. The 'complete' method copies the content of the SRAM to memory. This will soon become useful if we want to call the process and the complete operations from different locations depending on the type of the request (different cleanup logic).
Signed-off-by Romain Perier <[email protected]>--- drivers/crypto/marvell/cesa.c | 1 + drivers/crypto/marvell/cesa.h | 3 +++ drivers/crypto/marvell/cipher.c | 47 ++++++++++++++++++++++++----------------- drivers/crypto/marvell/hash.c | 22 ++++++++++--------- 4 files changed, 44 insertions(+), 29 deletions(-)drivers/crypto/marvell/cesa.c +1
-0@@ -98,6 +98,7 @@ static irqreturn_t mv_cesa_int(int irq, void *priv) engine->req =NULL ;mv_cesa_dequeue_req_unlocked (engine);spin_unlock_bh (&engine->lock); + ctx->ops->complete (req); ctx->ops->cleanup (req);local_bh_disable (); req->complete (req, res);drivers/crypto/marvell/cesa.h +3
-0@@ -456,6 +456,8 @@ struct mv_cesa_engine {* code) * @step: launch the crypto operation on the next chunk * @cleanup: cleanup the crypto request (release associated data) +* @complete: complete the request, i.e copy result from sram or contexts +* when it is needed. */ struct mv_cesa_req_ops { void (*prepare)(struct crypto_async_request *req,@@ -463,6 +465,7 @@ struct mv_cesa_req_ops {int (*process)(struct crypto_async_request *req,u32 status);void (*step)(struct crypto_async_request *req);void (*cleanup)(struct crypto_async_request *req); +void (*complete)(struct crypto_async_request *req); };/** drivers/crypto/marvell/cipher.c +2
-19@@ -118,7 +118,6 @@ static int mv_cesa_ablkcipher_std_process(struct ablkcipher_request *req,struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std;struct mv_cesa_engine *engine = sreq->base.engine;size_t len; -unsigned int ivsize; len = sg_pcopy_from_buffer(req->dst, creq->dst_nents, engine->sram + CESA_SA_DATA_SRAM_OFFSET,@@ -128,10 +127,6 @@ static int mv_cesa_ablkcipher_std_process(struct ablkcipher_request *req,if (sreq->offset < req->nbytes)return -EINPROGRESS ; - ivsize =crypto_ablkcipher_ivsize (crypto_ablkcipher_reqtfm (req)); -memcpy_fromio (req->info, - engine->sram +CESA_SA_CRYPT_IV_SRAM_OFFSET , ivsize); -return 0 ; }@@ -141,21 +136,9 @@ static int mv_cesa_ablkcipher_process(struct crypto_async_request *req,struct ablkcipher_request *ablkreq =ablkcipher_request_cast (req);struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq); -if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) { -int ret; -struct mv_cesa_req *basereq; -unsigned int ivsize; - - ret =mv_cesa_dma_process (&creq->req.base, status); -if (ret) -return ret; +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) +return mv_cesa_dma_process (&creq->req.base, status); - basereq = &creq->req.base; - ivsize =crypto_ablkcipher_ivsize ( -crypto_ablkcipher_reqtfm (ablkreq)); -memcpy_fromio (ablkreq->info, basereq->chain.last->data, ivsize); -return ret; - }return mv_cesa_ablkcipher_std_process (ablkreq, status); }
drivers/crypto/marvell/cipher.c static inline void mv_cesa_ablkcipher_prepare(struct crypto_async_request *req, · line 183
Quoted 4 lines
drivers/crypto/marvell/cipher.c +1
-0@@ -197,6 +180,7 @@ static inline void mv_cesa_ablkcipher_prepare(struct crypto_async_request *req, {struct ablkcipher_request *ablkreq =ablkcipher_request_cast (req);struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq); +
Nit: not sure you should mix this cosmetic change with the other changes.
Quoted 13 lines
drivers/crypto/marvell/cipher.c +6
-0creq->req.base.engine = engine;if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )@@ -213,11 +197,36 @@ mv_cesa_ablkcipher_req_cleanup(struct crypto_async_request *req)mv_cesa_ablkcipher_cleanup (ablkreq); } +static void +mv_cesa_ablkcipher_complete (struct crypto_async_request *req) +{ +struct ablkcipher_request *ablkreq =ablkcipher_request_cast (req); +struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (ablkreq); +struct mv_cesa_engine *engine = creq->req.base.engine;
drivers/crypto/marvell/cipher.c mv_cesa_ablkcipher_req_cleanup(struct crypto_async_request *req) · line 215
Quoted 10 lines
drivers/crypto/marvell/cipher.c +10
-0+unsigned int ivsize; + + ivsize =crypto_ablkcipher_ivsize (crypto_ablkcipher_reqtfm (ablkreq)); + +if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) { +struct mv_cesa_req *basereq; + + basereq = &creq->req.base; + ivsize =crypto_ablkcipher_ivsize ( +crypto_ablkcipher_reqtfm (ablkreq));
You already have ivsize initialized.
drivers/crypto/marvell/cipher.c mv_cesa_ablkcipher_req_cleanup(struct crypto_async_request *req) · line 216
Quoted 1 line
drivers/crypto/marvell/cipher.c +1
-0+memcpy_fromio (ablkreq->info, basereq->chain.last->data, ivsize);
Use memcpy() here.
Quoted 66 lines
drivers/crypto/marvell/cipher.c +8
-0+ }else { +memcpy_fromio (ablkreq->info, + engine->sram +CESA_SA_CRYPT_IV_SRAM_OFFSET , + ivsize); + } +} +static const struct mv_cesa_req_ops mv_cesa_ablkcipher_req_ops = { .step = mv_cesa_ablkcipher_step, .process = mv_cesa_ablkcipher_process, .prepare = mv_cesa_ablkcipher_prepare, .cleanup = mv_cesa_ablkcipher_req_cleanup, + .complete = mv_cesa_ablkcipher_complete, };static int mv_cesa_ablkcipher_cra_init (struct crypto_tfm *tfm)drivers/crypto/marvell/hash.c +12
-10@@ -287,17 +287,20 @@ static int mv_cesa_ahash_process(struct crypto_async_request *req, u32 status) {struct ahash_request *ahashreq =ahash_request_cast (req);struct mv_cesa_ahash_req *creq =ahash_request_ctx (ahashreq); -struct mv_cesa_engine *engine = creq->req.base.engine; -unsigned int digsize; -int ret, i;if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ ) - ret =mv_cesa_dma_process (&creq->req.base, status); -else - ret =mv_cesa_ahash_std_process (ahashreq, status); +return mv_cesa_dma_process (&creq->req.base, status); -if (ret == -EINPROGRESS ) -return ret; +return mv_cesa_ahash_std_process (ahashreq, status); +} + +static void mv_cesa_ahash_complete (struct crypto_async_request *req) +{ +struct ahash_request *ahashreq =ahash_request_cast (req); +struct mv_cesa_ahash_req *creq =ahash_request_ctx (ahashreq); +struct mv_cesa_engine *engine = creq->req.base.engine; +unsigned int digsize; +int i; digsize =crypto_ahash_digestsize (crypto_ahash_reqtfm (ahashreq));for (i =0 ; i < digsize /4 ; i++)@@ -326,8 +329,6 @@ static int mv_cesa_ahash_process(struct crypto_async_request *req, u32 status) result[i] =cpu_to_be32 (creq->state[i]); } } - -return ret; } static void mv_cesa_ahash_prepare(struct crypto_async_request *req,@@ -366,6 +367,7 @@ static const struct mv_cesa_req_ops mv_cesa_ahash_req_ops = { .process = mv_cesa_ahash_process, .prepare = mv_cesa_ahash_prepare, .cleanup = mv_cesa_ahash_req_cleanup, + .complete = mv_cesa_ahash_complete, }; static int mv_cesa_ahash_init(struct ahash_request *req,
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 5/7 crypto: marvell: Adding a complete operation for async requests
Hello,
Le 15/06/2016 22:55, Boris Brezillon a ?crit :
Quoted 4 lines
Quoted 1 line
+
Nit: not sure you should mix this cosmetic change with the other changes.
Ok
Quoted 5 lines
You already have ivsize initialized.
drivers/crypto/marvell/cipher.c mv_cesa_ablkcipher_req_cleanup(struct crypto_async_request *req) · line 216
Quoted 1 line
drivers/crypto/marvell/cipher.c +1
-0+memcpy_fromio (ablkreq->info, basereq->chain.last->data, ivsize);Use
memcpy()here.
good catch, for both.
Thanks,
Romain
Signature · 3 lines
Romain Perier, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 6/7 crypto: marvell: Adding load balancing between engines
In reply to Romain PerierThis commits adds support for fine grained load balancing on multi-engine IPs. The engine is pre-selected based on its current load and on the weight of the crypto request that is about to be processed. The global crypto queue is also moved to each engine. These changes are useful for preparing the code to support TDMA chaining between crypto requests, because each tdma chain will be handled per engine. By using a crypto queue per engine, we make sure that we keep the state of the tdma chain synchronized with the crypto queue. We also reduce contention on 'cesa_dev->lock' and improve parallelism.
--- drivers/crypto/marvell/cesa.c | 30 +++++++++---------- drivers/crypto/marvell/cesa.h | 26 +++++++++++++++-- drivers/crypto/marvell/cipher.c | 59 ++++++++++++++++++------------------- drivers/crypto/marvell/hash.c | 65 +++++++++++++++++++---------------------- 4 files changed, 97 insertions(+), 83 deletions(-)
drivers/crypto/marvell/cesa.c +14 -16
@@ -45,11 +45,9 @@ static void mv_cesa_dequeue_req_unlocked(struct mv_cesa_engine *engine)struct crypto_async_request *req, *backlog;struct mv_cesa_ctx *ctx; -spin_lock_bh (&cesa_dev->lock); - backlog =crypto_get_backlog (&cesa_dev->queue); - req =crypto_dequeue_request (&cesa_dev->queue); + backlog =crypto_get_backlog (&engine->queue); + req =crypto_dequeue_request (&engine->queue); engine->req = req; -spin_unlock_bh (&cesa_dev->lock);if (!req)return ;
@@ -58,7 +56,6 @@ static void mv_cesa_dequeue_req_unlocked(struct mv_cesa_engine *engine) backlog->complete (backlog, -EINPROGRESS ); ctx =crypto_tfm_ctx (req->tfm); - ctx->ops->prepare (req, engine); ctx->ops->step (req); }
@@ -116,21 +113,19 @@ int mv_cesa_queue_req(struct crypto_async_request *req, struct mv_cesa_req *creq) {int ret; -int i; +struct mv_cesa_engine *engine = creq->engine; -spin_lock_bh (&cesa_dev->lock); - ret =crypto_enqueue_request (&cesa_dev->queue, req); -spin_unlock_bh (&cesa_dev->lock); +spin_lock_bh (&engine->lock); + ret =crypto_enqueue_request (&engine->queue, req); +spin_unlock_bh (&engine->lock);if (ret != -EINPROGRESS )return ret; -for (i =0 ; i < cesa_dev->caps->nengines; i++) { -spin_lock_bh (&cesa_dev->engines[i].lock); -if (!cesa_dev->engines[i].req) -mv_cesa_dequeue_req_unlocked (&cesa_dev->engines[i]); -spin_unlock_bh (&cesa_dev->engines[i].lock); - } +spin_lock_bh (&engine->lock); +if (!engine->req) +mv_cesa_dequeue_req_unlocked (engine); +spin_unlock_bh (&engine->lock);return -EINPROGRESS ; }
@@ -425,7 +420,7 @@ static int mv_cesa_probe(struct platform_device *pdev)return -ENOMEM ;spin_lock_init (&cesa->lock); -crypto_init_queue (&cesa->queue,CESA_CRYPTO_DEFAULT_MAX_QLEN ); + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"regs" ); cesa->regs =devm_ioremap_resource (dev, res);if (IS_ERR (cesa->regs))
@@ -498,6 +493,9 @@ static int mv_cesa_probe(struct platform_device *pdev) engine);if (ret) goto err_cleanup; + +crypto_init_queue (&engine->queue,CESA_CRYPTO_DEFAULT_MAX_QLEN ); +atomic_set (&engine->load,0 ); } cesa_dev = cesa;
drivers/crypto/marvell/cesa.h +24 -2
@@ -400,7 +400,6 @@ struct mv_cesa_dev_dma {* @regs: device registers * @sram_size: usable SRAM size * @lock: device lock -* @queue: crypto request queue * @engines: array of engines * @dma: dma pools *
@@ -412,7 +411,6 @@ struct mv_cesa_dev {struct device *dev;unsigned int sram_size;spinlock_t lock; -struct crypto_queue queue;struct mv_cesa_engine *engines;struct mv_cesa_dev_dma *dma; };
@@ -431,6 +429,8 @@ struct mv_cesa_dev {* @int_mask: interrupt mask cache * @pool: memory pool pointing to the memory region reserved in * SRAM +* @queue: fifo of the pending crypto requests +* @load: engine load counter, useful for load balancing * * Structure storing CESA engine information. */
@@ -446,6 +446,8 @@ struct mv_cesa_engine {size_t max_req_len;u32 int_mask;struct gen_pool *pool; +struct crypto_queue queue; +atomic_t load; };/**
@@ -697,6 +699,26 @@ static inline bool mv_cesa_mac_op_is_first_frag(const struct mv_cesa_op_ctx *op)int mv_cesa_queue_req (struct crypto_async_request *req,struct mv_cesa_req *creq); +static inline struct mv_cesa_engine *mv_cesa_select_engine (int weight) +{ +int i; +u32 min_load =U32_MAX ; +struct mv_cesa_engine *selected =NULL ; + +for (i =0 ; i < cesa_dev->caps->nengines; i++) { +struct mv_cesa_engine *engine = cesa_dev->engines + i; +u32 load =atomic_read (&engine->load); +if (load < min_load) { + min_load = load; + selected = engine; + } + } + +atomic_add (weight, &selected->load); + +return selected; +} +/* * Helper function that indicates whether a crypto request needs to be * cleaned up or not after being enqueued using mv_cesa_queue_req().
drivers/crypto/marvell/cipher.c +29 -30
112 lines not on this page · raw message
drivers/crypto/marvell/hash.c +30 -35
133 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 6/7 crypto: marvell: Adding load balancing between engines
Quoted 4 lines · On Wed, 15 Jun 2016 21:15:33 +0200 Romain Perier…
This commits adds support for fine grained load balancing on multi-engine IPs. The engine is pre-selected based on its current load and on the weight of the crypto request that is about to be processed. The global crypto queue is also moved to each engine. These changes are
to the mv_cesa_engine object.
Quoted 2 lines
useful for preparing the code to support TDMA chaining between crypto requests, because each tdma chain will be handled per engine.
These changes are required to allow chaining crypto requests at the DMA level.
Quoted 13 lines
By using
a crypto queue per engine, we make sure that we keep the state of the tdma chain synchronized with the crypto queue. We also reduce contention on 'cesa_dev->lock' and improve parallelism.Signed-off-by Romain Perier <[email protected]>--- drivers/crypto/marvell/cesa.c | 30 +++++++++---------- drivers/crypto/marvell/cesa.h | 26 +++++++++++++++-- drivers/crypto/marvell/cipher.c | 59 ++++++++++++++++++------------------- drivers/crypto/marvell/hash.c | 65 +++++++++++++++++++---------------------- 4 files changed, 97 insertions(+), 83 deletions(-)
[...]
Quoted 15 lines
drivers/crypto/marvell/cipher.c +3
-0@@ -89,6 +89,9 @@ static void mv_cesa_ablkcipher_std_step(struct ablkcipher_request *req)size_t len =min_t (size_t, req->nbytes - sreq->offset,CESA_SA_SRAM_PAYLOAD_SIZE ); +mv_cesa_adjust_op (engine, &sreq->op); +memcpy_toio (engine->sram, &sreq->op,sizeof (sreq->op)); + len =sg_pcopy_to_buffer (req->src, creq->src_nents, engine->sram +CESA_SA_DATA_SRAM_OFFSET , len, sreq->offset);
drivers/crypto/marvell/cipher.c mv_cesa_ablkcipher_std_prepare(struct ablkcipher_request *req) · line 175
Quoted 9 lines
drivers/crypto/marvell/cipher.c +0
-3@@ -167,12 +170,9 @@ mv_cesa_ablkcipher_std_prepare(struct ablkcipher_request *req) {struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std; -struct mv_cesa_engine *engine = sreq->base.engine; sreq->size =0 ; sreq->offset =0 ; -mv_cesa_adjust_op (engine, &sreq->op); -memcpy_toio (engine->sram, &sreq->op,sizeof (sreq->op));
Are these changes really related to this load balancing support? AFAICT, it's something that could have been done earlier, and is not dependent on the changes your introducing here, but maybe I'm missing something.
Quoted 1 line
drivers/crypto/marvell/cipher.c +0
-0}
[...]
Quoted 22 lines
static int
mv_cesa_ecb_aes_encrypt(struct ablkcipher_request *req)drivers/crypto/marvell/hash.c +9
-0@@ -162,6 +162,15 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)unsigned int new_cache_ptr =0 ;u32 frag_mode;size_t len; +unsigned int digsize; +int i; + +mv_cesa_adjust_op (engine, &creq->op_tmpl); +memcpy_toio (engine->sram, &creq->op_tmpl,sizeof (creq->op_tmpl)); + + digsize =crypto_ahash_digestsize (crypto_ahash_reqtfm (req)); +for (i =0 ; i < digsize /4 ; i++) +writel_relaxed (creq->state[i], engine->regs +CESA_IVDIG (i));if (creq->cache_ptr) memcpy_toio(engine->sram + CESA_SA_DATA_SRAM_OFFSET,
drivers/crypto/marvell/hash.c static void mv_cesa_ahash_std_prepare(struct ahash_request *req) · line 272
Quoted 8 lines
drivers/crypto/marvell/hash.c +0
-3@@ -265,11 +274,8 @@ static void mv_cesa_ahash_std_prepare(struct ahash_request *req) {struct mv_cesa_ahash_req *creq =ahash_request_ctx (req);struct mv_cesa_ahash_std_req *sreq = &creq->req.std; -struct mv_cesa_engine *engine = sreq->base.engine; sreq->offset =0 ; -mv_cesa_adjust_op (engine, &creq->op_tmpl); -memcpy_toio (engine->sram, &creq->op_tmpl,sizeof (creq->op_tmpl));
Same as above: it doesn't seem related to the load balancing stuff.
Quoted 1 line
drivers/crypto/marvell/hash.c +0
-0}
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 6/7 crypto: marvell: Adding load balancing between engines
Hello,
Le 15/06/2016 23:13, Boris Brezillon a ?crit :
Quoted 8 lines
Quoted 4 lines · On Wed, 15 Jun 2016 21:15:33 +0200 Romain Perier…
This commits adds support for fine grained load balancing on multi-engine IPs. The engine is pre-selected based on its current load and on the weight of the crypto request that is about to be processed. The global crypto queue is also moved to each engine. These changes are
Quoted 7 lines
to the
mv_cesa_engineobject.Quoted 2 lines
useful for preparing the code to support TDMA chaining between crypto requests, because each tdma chain will be handled per engine.
These changes are required to allow chaining crypto requests at the DMA level.
ack
Quoted 20 lines
Quoted 20 lines
drivers/crypto/marvell/cipher.c +3
-1@@ -89,6 +89,9 @@ static void mv_cesa_ablkcipher_std_step(struct ablkcipher_request *req)size_t len =min_t (size_t, req->nbytes - sreq->offset,CESA_SA_SRAM_PAYLOAD_SIZE ); +mv_cesa_adjust_op (engine, &sreq->op); +memcpy_toio (engine->sram, &sreq->op,sizeof (sreq->op)); + len =sg_pcopy_to_buffer (req->src, creq->src_nents, engine->sram +CESA_SA_DATA_SRAM_OFFSET , len, sreq->offset);@@ -167,12 +170,9 @@ mv_cesa_ablkcipher_std_prepare(struct ablkcipher_request *req) {struct mv_cesa_ablkcipher_req *creq =ablkcipher_request_ctx (req);struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std; -struct mv_cesa_engine *engine = sreq->base.engine;
Quoted 9 lines
drivers/crypto/marvell/cipher.c mv_cesa_ablkcipher_std_prepare(struct ablkcipher_request *req) · line 175
Quoted 4 lines
drivers/crypto/marvell/cipher.c +0
-2sreq->size =0 ; sreq->offset =0 ; -mv_cesa_adjust_op (engine, &sreq->op); -memcpy_toio (engine->sram, &sreq->op,sizeof (sreq->op));Are these changes really related to this load balancing support? AFAICT, it's something that could have been done earlier, and is not dependent on the changes your introducing here, but maybe I'm missing something.
Yeah, indeed. I suggest another commit for doing it. What do you think ?
Quoted 32 lines
Quoted 2 lines
drivers/crypto/marvell/cipher.c +0
-0}[...]
Quoted 27 lines
static int
mv_cesa_ecb_aes_encrypt(struct ablkcipher_request *req)drivers/crypto/marvell/hash.c +9
-1@@ -162,6 +162,15 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)unsigned int new_cache_ptr =0 ;u32 frag_mode;size_t len; +unsigned int digsize; +int i; + +mv_cesa_adjust_op (engine, &creq->op_tmpl); +memcpy_toio (engine->sram, &creq->op_tmpl,sizeof (creq->op_tmpl)); + + digsize =crypto_ahash_digestsize (crypto_ahash_reqtfm (req)); +for (i =0 ; i < digsize /4 ; i++) +writel_relaxed (creq->state[i], engine->regs +CESA_IVDIG (i));if (creq->cache_ptr) memcpy_toio(engine->sram + CESA_SA_DATA_SRAM_OFFSET,@@ -265,11 +274,8 @@ static void mv_cesa_ahash_std_prepare(struct ahash_request *req) {struct mv_cesa_ahash_req *creq =ahash_request_ctx (req);struct mv_cesa_ahash_std_req *sreq = &creq->req.std; -struct mv_cesa_engine *engine = sreq->base.engine;
Quoted 5 lines
drivers/crypto/marvell/hash.c static void mv_cesa_ahash_std_prepare(struct ahash_request *req) · line 272
Quoted 3 lines
drivers/crypto/marvell/hash.c +0
-2sreq->offset =0 ; -mv_cesa_adjust_op (engine, &creq->op_tmpl); -memcpy_toio (engine->sram, &creq->op_tmpl,sizeof (creq->op_tmpl));Same as above: it doesn't seem related to the load balancing stuff.
It might be moved into this "separated commit" described above.
Thanks,
Romain
Signature · 3 lines
Romain Perier, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 7/7 crypto: marvell: Add support for chaining crypto requests in TDMA mode
In reply to Romain PerierThe Cryptographic Engines and Security Accelerators (CESA) supports the Multi-Packet Chain Mode. With this mode enabled, multiple tdma requests can be chained and processed by the hardware without software interferences. This mode was already activated, however the crypto requests were not chained together. By doing so, we reduce significantly the number of IRQs. Instead of being interrupted at the end of each crypto request, we are interrupted at the end of the last cryptographic request processed by the engine.
This commits re-factorizes the code, changes the code architecture and adds the required data structures to chain cryptographic requests together before sending them to an engine.
--- drivers/crypto/marvell/cesa.c | 117 +++++++++++++++++++++++++++++++--------- drivers/crypto/marvell/cesa.h | 38 ++++++++++++- drivers/crypto/marvell/cipher.c | 3 +- drivers/crypto/marvell/hash.c | 9 +++- drivers/crypto/marvell/tdma.c | 81 ++++++++++++++++++++++++++++ 5 files changed, 218 insertions(+), 30 deletions(-)
drivers/crypto/marvell/cesa.c +91 -26
@@ -32,7 +32,7 @@#include "cesa.h" /* Limit of the crypto queue before reaching the backlog */ -#define CESA_CRYPTO_DEFAULT_MAX_QLEN 50 +#define CESA_CRYPTO_DEFAULT_MAX_QLEN 128static int allhwsupport = !IS_ENABLED (CONFIG_CRYPTO_DEV_MV_CESA );module_param_named (allhwsupport, allhwsupport, int,0444 );
@@ -40,23 +40,83 @@ MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if overstruct mv_cesa_dev *cesa_dev; -static void mv_cesa_dequeue_req_unlocked (struct mv_cesa_engine *engine) +struct crypto_async_request *mv_cesa_dequeue_req_locked ( +struct mv_cesa_engine *engine,struct crypto_async_request **backlog) +{ +struct crypto_async_request *req; + + *backlog =crypto_get_backlog (&engine->queue); + req =crypto_dequeue_request (&engine->queue); + +if (!req) +return NULL ; + +return req; +} + +static void mv_cesa_rearm_engine (struct mv_cesa_engine *engine) {struct crypto_async_request *req, *backlog;struct mv_cesa_ctx *ctx; - backlog =crypto_get_backlog (&engine->queue); - req =crypto_dequeue_request (&engine->queue); - engine->req = req; +spin_lock_bh (&engine->lock); +if (engine->req) + goto out_unlock; + + req =mv_cesa_dequeue_req_locked (engine, &backlog);if (!req) -return ; + goto out_unlock; + + engine->req = req; +spin_unlock_bh (&engine->lock);if (backlog) backlog->complete (backlog, -EINPROGRESS ); ctx =crypto_tfm_ctx (req->tfm); ctx->ops->step (req); +return ; +out_unlock: +spin_unlock_bh (&engine->lock); +} + +static int mv_cesa_std_process (struct mv_cesa_engine *engine,u32 status) +{ +struct crypto_async_request *req; +struct mv_cesa_ctx *ctx; +int res; + + req = engine->req; + ctx =crypto_tfm_ctx (req->tfm); + res = ctx->ops->process (req, status); + +if (res ==0 ) { + ctx->ops->complete (req); +mv_cesa_engine_enqueue_complete_request (engine, req); + }else if (res == -EINPROGRESS ) { + ctx->ops->step (req); + }else { + ctx->ops->complete (req); + } + +return res; +} + +static int mv_cesa_int_process (struct mv_cesa_engine *engine,u32 status) +{ +if (engine->chain.first && engine->chain.last) +return mv_cesa_tdma_process (engine, status); +return mv_cesa_std_process (engine, status); +} + +static inline void mv_cesa_complete_req (struct mv_cesa_ctx *ctx, +struct crypto_async_request *req,int res) +{ + ctx->ops->cleanup (req); +local_bh_disable (); + req->complete (req, res); +local_bh_enable (); }static irqreturn_t mv_cesa_int (int irq,void *priv)
@@ -83,26 +143,31 @@ static irqreturn_t mv_cesa_int(int irq, void *priv)writel (~status, engine->regs +CESA_SA_FPGA_INT_STATUS );writel (~status, engine->regs +CESA_SA_INT_STATUS ); +/* Process fetched requests */ + res =mv_cesa_int_process (engine, status & mask); ret =IRQ_HANDLED ; +spin_lock_bh (&engine->lock); req = engine->req; +if (res != -EINPROGRESS ) + engine->req =NULL ;spin_unlock_bh (&engine->lock); -if (req) { - ctx =crypto_tfm_ctx (req->tfm); - res = ctx->ops->process (req, status & mask); -if (res != -EINPROGRESS ) { -spin_lock_bh (&engine->lock); - engine->req =NULL ; -mv_cesa_dequeue_req_unlocked (engine); -spin_unlock_bh (&engine->lock); - ctx->ops->complete (req); - ctx->ops->cleanup (req); -local_bh_disable (); - req->complete (req, res); -local_bh_enable (); - }else { - ctx->ops->step (req); - } + + ctx =crypto_tfm_ctx (req->tfm); + +if (res && res != -EINPROGRESS ) +mv_cesa_complete_req (ctx, req, res); + +/* Launch the next pending request */ +mv_cesa_rearm_engine (engine); + +/* Iterate over the complete queue */ +while (true) { + req =mv_cesa_engine_dequeue_complete_request (engine); +if (!req) +break ; + +mv_cesa_complete_req (ctx, req,0 ); } }
@@ -116,16 +181,15 @@ int mv_cesa_queue_req(struct crypto_async_request *req,struct mv_cesa_engine *engine = creq->engine;spin_lock_bh (&engine->lock); +if (mv_cesa_req_get_type (creq) ==CESA_DMA_REQ ) +mv_cesa_tdma_chain (engine, creq); ret =crypto_enqueue_request (&engine->queue, req);spin_unlock_bh (&engine->lock);if (ret != -EINPROGRESS )return ret; -spin_lock_bh (&engine->lock); -if (!engine->req) -mv_cesa_dequeue_req_unlocked (engine); -spin_unlock_bh (&engine->lock); +mv_cesa_rearm_engine (engine);return -EINPROGRESS ; }
@@ -496,6 +560,7 @@ static int mv_cesa_probe(struct platform_device *pdev)crypto_init_queue (&engine->queue,CESA_CRYPTO_DEFAULT_MAX_QLEN );atomic_set (&engine->load,0 ); +INIT_LIST_HEAD (&engine->complete_queue); } cesa_dev = cesa;
drivers/crypto/marvell/cesa.h +37 -1
@@ -271,7 +271,9 @@ struct mv_cesa_op_ctx {/* TDMA descriptor flags */ #define CESA_TDMA_DST_IN_SRAM BIT(31)#define CESA_TDMA_SRC_IN_SRAM BIT(30) -#define CESA_TDMA_TYPE_MSK GENMASK(29, 0) +#define CESA_TDMA_END_OF_REQ BIT(29) +#define CESA_TDMA_NOT_CHAIN BIT(28) +#define CESA_TDMA_TYPE_MSK GENMASK(27, 0)#define CESA_TDMA_DUMMY 0#define CESA_TDMA_DATA 1#define CESA_TDMA_OP 2
@@ -431,6 +433,9 @@ struct mv_cesa_dev {* SRAM * @queue: fifo of the pending crypto requests * @load: engine load counter, useful for load balancing +* @chain: list of the current tdma descriptors being processed +* by this engine. +* @complete_queue: fifo of the processed requests by the engine * * Structure storing CESA engine information. */
@@ -448,6 +453,8 @@ struct mv_cesa_engine {struct gen_pool *pool;struct crypto_queue queue;atomic_t load; +struct mv_cesa_tdma_chain chain; +struct list_head complete_queue; };/**
@@ -618,6 +625,28 @@ struct mv_cesa_ahash_req {extern struct mv_cesa_dev *cesa_dev; + +static inline void mv_cesa_engine_enqueue_complete_request ( +struct mv_cesa_engine *engine,struct crypto_async_request *req) +{ +list_add_tail (&req->list, &engine->complete_queue); +} + +static inline struct crypto_async_request * +mv_cesa_engine_dequeue_complete_request (struct mv_cesa_engine *engine) +{ +struct crypto_async_request *req; + + req =list_first_entry_or_null (&engine->complete_queue, + struct crypto_async_request, + list); +if (req) +list_del (&req->list); + +return req; +} + +static inline enum mv_cesa_req_type mv_cesa_req_get_type (struct mv_cesa_req *req) {
@@ -699,6 +728,10 @@ static inline bool mv_cesa_mac_op_is_first_frag(const struct mv_cesa_op_ctx *op)int mv_cesa_queue_req (struct crypto_async_request *req,struct mv_cesa_req *creq); +struct crypto_async_request *mv_cesa_dequeue_req_locked ( +struct mv_cesa_engine *engine, +struct crypto_async_request **backlog); +static inline struct mv_cesa_engine *mv_cesa_select_engine (int weight) {int i;
@@ -804,6 +837,9 @@ static inline int mv_cesa_dma_process(struct mv_cesa_req *dreq,void mv_cesa_dma_prepare (struct mv_cesa_req *dreq,struct mv_cesa_engine *engine);void mv_cesa_dma_cleanup (struct mv_cesa_req *dreq); +void mv_cesa_tdma_chain (struct mv_cesa_engine *engine, +struct mv_cesa_req *dreq); +int mv_cesa_tdma_process (struct mv_cesa_engine *engine,u32 status); static inline void
drivers/crypto/marvell/cipher.c +1 -2
@@ -225,7 +225,6 @@ mv_cesa_ablkcipher_complete(struct crypto_async_request *req)static const struct mv_cesa_req_ops mv_cesa_ablkcipher_req_ops = { .step = mv_cesa_ablkcipher_step, .process = mv_cesa_ablkcipher_process, - .prepare = mv_cesa_ablkcipher_prepare, .cleanup = mv_cesa_ablkcipher_req_cleanup, .complete = mv_cesa_ablkcipher_complete, };
@@ -384,6 +383,7 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req, goto err_free_tdma; dreq->chain = chain; + dreq->chain.last->flags |=CESA_TDMA_END_OF_REQ ;return 0 ;
@@ -441,7 +441,6 @@ static int mv_cesa_ablkcipher_req_init(struct ablkcipher_request *req,mv_cesa_update_op_cfg (tmpl,CESA_SA_DESC_CFG_OP_CRYPT_ONLY ,CESA_SA_DESC_CFG_OP_MSK ); -/* TODO: add a threshold for DMA usage */ if (cesa_dev->caps->has_tdma) ret =mv_cesa_ablkcipher_dma_req_init (req, tmpl);else
drivers/crypto/marvell/hash.c +8 -1
@@ -172,6 +172,9 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)for (i =0 ; i < digsize /4 ; i++)writel_relaxed (creq->state[i], engine->regs +CESA_IVDIG (i)); +mv_cesa_adjust_op (engine, &creq->op_tmpl); +memcpy_toio (engine->sram, &creq->op_tmpl,sizeof (creq->op_tmpl)); +if (creq->cache_ptr)memcpy_toio (engine->sram +CESA_SA_DATA_SRAM_OFFSET , creq->cache, creq->cache_ptr);
@@ -282,6 +285,9 @@ static void mv_cesa_ahash_step(struct crypto_async_request *req) {struct ahash_request *ahashreq =ahash_request_cast (req);struct mv_cesa_ahash_req *creq =ahash_request_ctx (ahashreq); +struct mv_cesa_engine *engine = creq->req.base.engine; +unsigned int digsize; +int i;if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_dma_step (&creq->req.base);
@@ -367,7 +373,6 @@ static void mv_cesa_ahash_req_cleanup(struct crypto_async_request *req)static const struct mv_cesa_req_ops mv_cesa_ahash_req_ops = { .step = mv_cesa_ahash_step, .process = mv_cesa_ahash_process, - .prepare = mv_cesa_ahash_prepare, .cleanup = mv_cesa_ahash_req_cleanup, .complete = mv_cesa_ahash_complete, };
@@ -648,6 +653,8 @@ static int mv_cesa_ahash_dma_req_init(struct ahash_request *req)else creq->cache_ptr =0 ; + dreq->chain.last->flags |= (CESA_TDMA_END_OF_REQ |CESA_TDMA_NOT_CHAIN ); +return 0 ; err_free_tdma:
drivers/crypto/marvell/tdma.c +81 -0
87 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 7/7 crypto: marvell: Add support for chaining crypto requests in TDMA mode
Quoted 4 lines · On Wed, 15 Jun 2016 21:15:34 +0200 Romain Perier…
The Cryptographic Engines and Security Accelerators (CESA) supports the Multi-Packet Chain Mode. With this mode enabled, multiple tdma requests can be chained and processed by the hardware without software interferences.
intervention.
Quoted 2 lines
This mode was already activated, however the crypto
requests were not chained together. By doing so, we reduce significantly
significantly reduce
Quoted 7 lines
the number of IRQs. Instead of being interrupted at the end of each crypto request, we are interrupted at the end of the last cryptographic request processed by the engine.
This commits re-factorizes the code, changes the code architecture and adds the required data structures to chain cryptographic requests together before sending them to an engine.
Not necessarily before sending them to the engine, it can be done while the engine is running.
Quoted 24 lines
Signed-off-by Romain Perier <[email protected]>--- drivers/crypto/marvell/cesa.c | 117 +++++++++++++++++++++++++++++++--------- drivers/crypto/marvell/cesa.h | 38 ++++++++++++- drivers/crypto/marvell/cipher.c | 3 +- drivers/crypto/marvell/hash.c | 9 +++- drivers/crypto/marvell/tdma.c | 81 ++++++++++++++++++++++++++++ 5 files changed, 218 insertions(+), 30 deletions(-)drivers/crypto/marvell/cesa.c +1
-1@@ -32,7 +32,7 @@#include "cesa.h" /* Limit of the crypto queue before reaching the backlog */ -#define CESA_CRYPTO_DEFAULT_MAX_QLEN 50 +#define CESA_CRYPTO_DEFAULT_MAX_QLEN 128static int allhwsupport = !IS_ENABLED (CONFIG_CRYPTO_DEV_MV_CESA );module_param_named (allhwsupport, allhwsupport, int,0444 );
drivers/crypto/marvell/cesa.c MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if over · line 44
Quoted 6 lines
drivers/crypto/marvell/cesa.c +2
-1@@ -40,23 +40,83 @@ MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if overstruct mv_cesa_dev *cesa_dev; -static void mv_cesa_dequeue_req_unlocked (struct mv_cesa_engine *engine) +struct crypto_async_request *mv_cesa_dequeue_req_locked ( +struct mv_cesa_engine *engine,struct crypto_async_request **backlog)
Coding style issue:
struct crypto_async_request * mv_cesa_dequeue_req_locked(struct mv_cesa_engine *engine,
struct crypto_async_request **backlog)
Quoted 22 lines
drivers/crypto/marvell/cesa.c +14
-3+{ +struct crypto_async_request *req; + + *backlog =crypto_get_backlog (&engine->queue); + req =crypto_dequeue_request (&engine->queue); + +if (!req) +return NULL ; + +return req; +} + +static void mv_cesa_rearm_engine (struct mv_cesa_engine *engine) {struct crypto_async_request *req, *backlog;struct mv_cesa_ctx *ctx; - backlog =crypto_get_backlog (&engine->queue); - req =crypto_dequeue_request (&engine->queue); - engine->req = req; +spin_lock_bh (&engine->lock);
drivers/crypto/marvell/cesa.c MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if over · line 72
Quoted 10 lines
drivers/crypto/marvell/cesa.c +8
-1+if (engine->req) + goto out_unlock; + + req =mv_cesa_dequeue_req_locked (engine, &backlog);if (!req) -return ; + goto out_unlock; + + engine->req = req; +spin_unlock_bh (&engine->lock);
I'm not a big fan of those multiple 'unlock() locations', and since your code is pretty simple I'd prefer seeing something like.
spin_lock_bh(&engine->lock);
if (!engine->req) {
req = mv_cesa_dequeue_req_locked(engine, &backlog);
engine->req = req;
}
spin_unlock_bh(&engine->lock);
if (!req)
return;With req and backlog initialized to NULL at the beginning of the function.
drivers/crypto/marvell/cesa.c MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if over · line 79
Quoted 7 lines
drivers/crypto/marvell/cesa.c +1
-0if (backlog) backlog->complete (backlog, -EINPROGRESS ); ctx =crypto_tfm_ctx (req->tfm); ctx->ops->step (req); +return ;
Missing blank line.
Quoted 11 lines
drivers/crypto/marvell/cesa.c +11
-0+out_unlock: +spin_unlock_bh (&engine->lock); +} + +static int mv_cesa_std_process (struct mv_cesa_engine *engine,u32 status) +{ +struct crypto_async_request *req; +struct mv_cesa_ctx *ctx; +int res; + + req = engine->req;
drivers/crypto/marvell/cesa.c MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if over · line 100
Quoted 10 lines
drivers/crypto/marvell/cesa.c +10
-0+ ctx =crypto_tfm_ctx (req->tfm); + res = ctx->ops->process (req, status); + +if (res ==0 ) { + ctx->ops->complete (req); +mv_cesa_engine_enqueue_complete_request (engine, req); + }else if (res == -EINPROGRESS ) { + ctx->ops->step (req); + }else { + ctx->ops->complete (req);
Do we really have to call ->complete() in this case?
drivers/crypto/marvell/cesa.c MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if over · line 109
Quoted 9 lines
drivers/crypto/marvell/cesa.c +9
-0+ } + +return res; +} + +static int mv_cesa_int_process (struct mv_cesa_engine *engine,u32 status) +{ +if (engine->chain.first && engine->chain.last) +return mv_cesa_tdma_process (engine, status);
Missing blank line.
drivers/crypto/marvell/cesa.c MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if over · line 114
Quoted 5 lines
drivers/crypto/marvell/cesa.c +5
-0+return mv_cesa_std_process (engine, status); +} + +static inline void mv_cesa_complete_req (struct mv_cesa_ctx *ctx, +struct crypto_async_request *req,int res)
Align parameters to the open parenthesis.
Quoted 57 lines
drivers/crypto/marvell/cesa.c +26
-16+{ + ctx->ops->cleanup (req); +local_bh_disable (); + req->complete (req, res); +local_bh_enable (); }static irqreturn_t mv_cesa_int (int irq,void *priv)@@ -83,26 +143,31 @@ static irqreturn_t mv_cesa_int(int irq, void *priv)writel (~status, engine->regs +CESA_SA_FPGA_INT_STATUS );writel (~status, engine->regs +CESA_SA_INT_STATUS ); +/* Process fetched requests */ + res =mv_cesa_int_process (engine, status & mask); ret =IRQ_HANDLED ; +spin_lock_bh (&engine->lock); req = engine->req; +if (res != -EINPROGRESS ) + engine->req =NULL ;spin_unlock_bh (&engine->lock); -if (req) { - ctx =crypto_tfm_ctx (req->tfm); - res = ctx->ops->process (req, status & mask); -if (res != -EINPROGRESS ) { -spin_lock_bh (&engine->lock); - engine->req =NULL ; -mv_cesa_dequeue_req_unlocked (engine); -spin_unlock_bh (&engine->lock); - ctx->ops->complete (req); - ctx->ops->cleanup (req); -local_bh_disable (); - req->complete (req, res); -local_bh_enable (); - }else { - ctx->ops->step (req); - } + + ctx =crypto_tfm_ctx (req->tfm); + +if (res && res != -EINPROGRESS ) +mv_cesa_complete_req (ctx, req, res); + +/* Launch the next pending request */ +mv_cesa_rearm_engine (engine); + +/* Iterate over the complete queue */ +while (true) { + req =mv_cesa_engine_dequeue_complete_request (engine); +if (!req) +break ; + +mv_cesa_complete_req (ctx, req,0 ); } }
drivers/crypto/marvell/cesa.c int mv_cesa_queue_req(struct crypto_async_request *req, · line 185
Quoted 5 lines
drivers/crypto/marvell/cesa.c +2
-0@@ -116,16 +181,15 @@ int mv_cesa_queue_req(struct crypto_async_request *req,struct mv_cesa_engine *engine = creq->engine;spin_lock_bh (&engine->lock); +if (mv_cesa_req_get_type (creq) ==CESA_DMA_REQ ) +mv_cesa_tdma_chain (engine, creq);
Missing blank line.
Quoted 27 lines
drivers/crypto/marvell/cesa.c +2
-4ret =crypto_enqueue_request (&engine->queue, req);spin_unlock_bh (&engine->lock);if (ret != -EINPROGRESS )return ret; -spin_lock_bh (&engine->lock); -if (!engine->req) -mv_cesa_dequeue_req_unlocked (engine); -spin_unlock_bh (&engine->lock); +mv_cesa_rearm_engine (engine);return -EINPROGRESS ; }@@ -496,6 +560,7 @@ static int mv_cesa_probe(struct platform_device *pdev)crypto_init_queue (&engine->queue,CESA_CRYPTO_DEFAULT_MAX_QLEN );atomic_set (&engine->load,0 ); +INIT_LIST_HEAD (&engine->complete_queue); } cesa_dev = cesa;drivers/crypto/marvell/cesa.h +0
-0
drivers/crypto/marvell/cesa.h struct mv_cesa_op_ctx { · line 275
Quoted 6 lines
drivers/crypto/marvell/cesa.h +2
-1@@ -271,7 +271,9 @@ struct mv_cesa_op_ctx {/* TDMA descriptor flags */ #define CESA_TDMA_DST_IN_SRAM BIT(31)#define CESA_TDMA_SRC_IN_SRAM BIT(30) -#define CESA_TDMA_TYPE_MSK GENMASK(29, 0) +#define CESA_TDMA_END_OF_REQ BIT(29) +#define CESA_TDMA_NOT_CHAIN BIT(28)
I would name it CESA_TDMA_BREAK_CHAIN.
Quoted 24 lines
drivers/crypto/marvell/cesa.h +6
-0+#define CESA_TDMA_TYPE_MSK GENMASK(27, 0)#define CESA_TDMA_DUMMY 0#define CESA_TDMA_DATA 1#define CESA_TDMA_OP 2@@ -431,6 +433,9 @@ struct mv_cesa_dev {* SRAM * @queue: fifo of the pending crypto requests * @load: engine load counter, useful for load balancing +* @chain: list of the current tdma descriptors being processed +* by this engine. +* @complete_queue: fifo of the processed requests by the engine * * Structure storing CESA engine information. */ @@ -448,6 +453,8 @@ struct mv_cesa_engine {struct gen_pool *pool;struct crypto_queue queue;atomic_t load; +struct mv_cesa_tdma_chain chain; +struct list_head complete_queue; };/**
drivers/crypto/marvell/cesa.h struct mv_cesa_ahash_req { · line 630
Quoted 6 lines
drivers/crypto/marvell/cesa.h +3
-0@@ -618,6 +625,28 @@ struct mv_cesa_ahash_req {extern struct mv_cesa_dev *cesa_dev; + +static inline void mv_cesa_engine_enqueue_complete_request ( +struct mv_cesa_engine *engine,struct crypto_async_request *req)
Coding style issue (see my previous comments).
Quoted 23 lines
drivers/crypto/marvell/cesa.h +19
-0+{ +list_add_tail (&req->list, &engine->complete_queue); +} + +static inline struct crypto_async_request * +mv_cesa_engine_dequeue_complete_request (struct mv_cesa_engine *engine) +{ +struct crypto_async_request *req; + + req =list_first_entry_or_null (&engine->complete_queue, + struct crypto_async_request, + list); +if (req) +list_del (&req->list); + +return req; +} + +static inline enum mv_cesa_req_type mv_cesa_req_get_type (struct mv_cesa_req *req) {
drivers/crypto/marvell/cesa.h static inline bool mv_cesa_mac_op_is_first_frag(const struct mv_cesa_op_ctx *op) · line 733
Quoted 6 lines
drivers/crypto/marvell/cesa.h +3
-0@@ -699,6 +728,10 @@ static inline bool mv_cesa_mac_op_is_first_frag(const struct mv_cesa_op_ctx *op)int mv_cesa_queue_req (struct crypto_async_request *req,struct mv_cesa_req *creq); +struct crypto_async_request *mv_cesa_dequeue_req_locked ( +struct mv_cesa_engine *engine, +struct crypto_async_request **backlog);
Ditto.
Quoted 67 lines
drivers/crypto/marvell/cesa.h +4
-0+static inline struct mv_cesa_engine *mv_cesa_select_engine (int weight) {int i;@@ -804,6 +837,9 @@ static inline int mv_cesa_dma_process(struct mv_cesa_req *dreq,void mv_cesa_dma_prepare (struct mv_cesa_req *dreq,struct mv_cesa_engine *engine);void mv_cesa_dma_cleanup (struct mv_cesa_req *dreq); +void mv_cesa_tdma_chain (struct mv_cesa_engine *engine, +struct mv_cesa_req *dreq); +int mv_cesa_tdma_process (struct mv_cesa_engine *engine,u32 status); static inline voiddrivers/crypto/marvell/cipher.c +1
-2@@ -225,7 +225,6 @@ mv_cesa_ablkcipher_complete(struct crypto_async_request *req)static const struct mv_cesa_req_ops mv_cesa_ablkcipher_req_ops = { .step = mv_cesa_ablkcipher_step, .process = mv_cesa_ablkcipher_process, - .prepare = mv_cesa_ablkcipher_prepare, .cleanup = mv_cesa_ablkcipher_req_cleanup, .complete = mv_cesa_ablkcipher_complete, };@@ -384,6 +383,7 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req, goto err_free_tdma; dreq->chain = chain; + dreq->chain.last->flags |=CESA_TDMA_END_OF_REQ ;return 0 ;@@ -441,7 +441,6 @@ static int mv_cesa_ablkcipher_req_init(struct ablkcipher_request *req,mv_cesa_update_op_cfg (tmpl,CESA_SA_DESC_CFG_OP_CRYPT_ONLY ,CESA_SA_DESC_CFG_OP_MSK ); -/* TODO: add a threshold for DMA usage */ if (cesa_dev->caps->has_tdma) ret =mv_cesa_ablkcipher_dma_req_init (req, tmpl);else drivers/crypto/marvell/hash.c +6
-0@@ -172,6 +172,9 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)for (i =0 ; i < digsize /4 ; i++)writel_relaxed (creq->state[i], engine->regs +CESA_IVDIG (i)); +mv_cesa_adjust_op (engine, &creq->op_tmpl); +memcpy_toio (engine->sram, &creq->op_tmpl,sizeof (creq->op_tmpl)); +if (creq->cache_ptr)memcpy_toio (engine->sram +CESA_SA_DATA_SRAM_OFFSET , creq->cache, creq->cache_ptr);@@ -282,6 +285,9 @@ static void mv_cesa_ahash_step(struct crypto_async_request *req) {struct ahash_request *ahashreq =ahash_request_cast (req);struct mv_cesa_ahash_req *creq =ahash_request_ctx (ahashreq); +struct mv_cesa_engine *engine = creq->req.base.engine; +unsigned int digsize; +int i;if (mv_cesa_req_get_type (&creq->req.base) ==CESA_DMA_REQ )mv_cesa_dma_step (&creq->req.base);
drivers/crypto/marvell/hash.c static void mv_cesa_ahash_req_cleanup(struct crypto_async_request *req) · line 370
Quoted 4 lines
drivers/crypto/marvell/hash.c +0
-1@@ -367,7 +373,6 @@ static void mv_cesa_ahash_req_cleanup(struct crypto_async_request *req)static const struct mv_cesa_req_ops mv_cesa_ahash_req_ops = { .step = mv_cesa_ahash_step, .process = mv_cesa_ahash_process, - .prepare = mv_cesa_ahash_prepare,
Why are you doing that?
Quoted 22 lines
drivers/crypto/marvell/hash.c +2
-0.cleanup = mv_cesa_ahash_req_cleanup, .complete = mv_cesa_ahash_complete, };@@ -648,6 +653,8 @@ static int mv_cesa_ahash_dma_req_init(struct ahash_request *req)else creq->cache_ptr =0 ; + dreq->chain.last->flags |= (CESA_TDMA_END_OF_REQ |CESA_TDMA_NOT_CHAIN ); +return 0 ; err_free_tdma:drivers/crypto/marvell/tdma.c +2
-0@@ -98,6 +98,87 @@ void mv_cesa_dma_prepare(struct mv_cesa_req *dreq, } } +void +mv_cesa_tdma_chain (struct mv_cesa_engine *engine,struct mv_cesa_req *dreq)
drivers/crypto/marvell/tdma.c void mv_cesa_dma_prepare(struct mv_cesa_req *dreq, · line 112
Quoted 10 lines
drivers/crypto/marvell/tdma.c +10
-0+{ +if (engine->chain.first ==NULL && engine->chain.last ==NULL ) { + engine->chain.first = dreq->chain.first; + engine->chain.last = dreq->chain.last; + }else { +struct mv_cesa_tdma_desc *last; + + last = engine->chain.last; + last->next = dreq->chain.first; + engine->chain.last = dreq->chain.last;
Missing blank line.
Quoted 36 lines
drivers/crypto/marvell/tdma.c +36
-0+if (!(last->flags &CESA_TDMA_NOT_CHAIN )) + last->next_dma = dreq->chain.first->cur_dma; + } +} + +int +mv_cesa_tdma_process (struct mv_cesa_engine *engine,u32 status) +{ +struct crypto_async_request *req =NULL ; +struct mv_cesa_tdma_desc *tdma =NULL , *next =NULL ; +dma_addr_t tdma_cur; +int res =0 ; + + tdma_cur =readl (engine->regs +CESA_TDMA_CUR ); + +for (tdma = engine->chain.first; tdma; tdma = next) { +spin_lock_bh (&engine->lock); + next = tdma->next; +spin_unlock_bh (&engine->lock); + +if (tdma->flags &CESA_TDMA_END_OF_REQ ) { +struct crypto_async_request *backlog =NULL ; +struct mv_cesa_ctx *ctx; + +spin_lock_bh (&engine->lock); +/* +* if req is NULL, this means we're processing the +* request in engine->req. +*/ +if (!req) + req = engine->req; +else + req =mv_cesa_dequeue_req_locked (engine, + &backlog); + +/* Re-chaining to the next request */
drivers/crypto/marvell/tdma.c void mv_cesa_dma_prepare(struct mv_cesa_req *dreq, · line 158
Quoted 10 lines
drivers/crypto/marvell/tdma.c +10
-0+ engine->chain.first = tdma->next; + tdma->next =NULL ; + +/* If this is the last request, clear the chain */ +if (engine->chain.first ==NULL ) + engine->chain.last =NULL ; +spin_unlock_bh (&engine->lock); + + ctx =crypto_tfm_ctx (req->tfm); + res = ctx->ops->process (req, status);
Hm, that's not exactly true. The status you're passing here is only valid for the last request that has been processed. Say you queued 3 requests. 2 of them were correctly processed, but the last one triggered an error. You don't want the first 2 requests to be considered bad.
A solution would be to pass a 'fake' valid status, until we reach the last request (IOW, tdma->cur_dma == tdma_cur).
drivers/crypto/marvell/tdma.c void mv_cesa_dma_prepare(struct mv_cesa_req *dreq, · line 167
Quoted 9 lines
drivers/crypto/marvell/tdma.c +9
-0+ ctx->ops->complete (req); + +if (res ==0 ) +mv_cesa_engine_enqueue_complete_request (engine, + req); + +if (backlog) + backlog->complete (backlog, -EINPROGRESS ); + }
Missing blank line.
drivers/crypto/marvell/tdma.c void mv_cesa_dma_prepare(struct mv_cesa_req *dreq, · line 176
Quoted 9 lines
drivers/crypto/marvell/tdma.c +9
-0+if (res || tdma->cur_dma == tdma_cur) +break ; + } + +if (res) { +spin_lock_bh (&engine->lock); + engine->req = req; +spin_unlock_bh (&engine->lock); + }
Maybe you can add a comment explaining that you are actually setting the last processed request into engine->req, so that the core can know which request was faulty.
Quoted 8 lines
drivers/crypto/marvell/tdma.c +5
-0+ +return res; +} + +static struct mv_cesa_tdma_desc *mv_cesa_dma_add_desc (struct mv_cesa_tdma_chain *chain,gfp_t flags) {
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 7/7 crypto: marvell: Add support for chaining crypto requests in TDMA mode
Hello,
Le 15/06/2016 23:43, Boris Brezillon a ?crit :
Quoted 9 lines
Quoted 4 lines · On Wed, 15 Jun 2016 21:15:34 +0200 Romain Perier…
The Cryptographic Engines and Security Accelerators (CESA) supports the Multi-Packet Chain Mode. With this mode enabled, multiple tdma requests can be chained and processed by the hardware without software interferences.
intervention.
ack
Quoted 2 lines
Not necessarily before sending them to the engine, it can be done while the engine is running.
I re-worded it
Quoted 5 lines
Coding style issue:
struct
crypto_async_request* mv_cesa_dequeue_req_locked(structmv_cesa_engine*engine,
structcrypto_async_request**backlog)
ack
Quoted 22 lines
Quoted 22 lines
drivers/crypto/marvell/cesa.c +13
-3+{ +struct crypto_async_request *req; + + *backlog =crypto_get_backlog (&engine->queue); + req =crypto_dequeue_request (&engine->queue); + +if (!req) +return NULL ; + +return req; +} + +static void mv_cesa_rearm_engine (struct mv_cesa_engine *engine) {struct crypto_async_request *req, *backlog;struct mv_cesa_ctx *ctx; - backlog =crypto_get_backlog (&engine->queue); - req =crypto_dequeue_request (&engine->queue); - engine->req = req;
Quoted 14 lines
drivers/crypto/marvell/cesa.c MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if over · line 72
Quoted 11 lines
drivers/crypto/marvell/cesa.c +9
-1+spin_lock_bh (&engine->lock); +if (engine->req) + goto out_unlock; + + req =mv_cesa_dequeue_req_locked (engine, &backlog);if (!req) -return ; + goto out_unlock; + + engine->req = req; +spin_unlock_bh (&engine->lock);I'm not a big fan of those multiple '
unlock()locations', and since your code is pretty simple I'd prefer seeing something like.
mhhh, yes I have re-worked this function recently (the locking was more complicated before), I will change the code.
Quoted 11 lines
spin_lock_bh(&engine->lock);
if (!engine->req) {
req = mv_cesa_dequeue_req_locked(engine, &backlog);
engine->req = req;
}
spin_unlock_bh(&engine->lock);
if (!req)
return;Quoted 2 lines
With req and backlog initialized to NULL at the beginning of the function.
ack
Quoted 10 lines
drivers/crypto/marvell/cesa.c MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if over · line 79
Quoted 8 lines
if (backlog) backlog->complete(backlog, -EINPROGRESS); ctx = crypto_tfm_ctx(req->tfm); ctx->ops->step(req);drivers/crypto/marvell/cesa.c +1
-0+return ;Missing blank line.
ack
Quoted 16 lines
Quoted 16 lines
drivers/crypto/marvell/cesa.c +15
-0+out_unlock: +spin_unlock_bh (&engine->lock); +} + +static int mv_cesa_std_process (struct mv_cesa_engine *engine,u32 status) +{ +struct crypto_async_request *req; +struct mv_cesa_ctx *ctx; +int res; + + req = engine->req; + ctx =crypto_tfm_ctx (req->tfm); + res = ctx->ops->process (req, status); + +if (res ==0 ) {
Quoted 8 lines
drivers/crypto/marvell/cesa.c MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if over · line 100
Quoted 6 lines
drivers/crypto/marvell/cesa.c +6
-0+ ctx->ops->complete (req); +mv_cesa_engine_enqueue_complete_request (engine, req); + }else if (res == -EINPROGRESS ) { + ctx->ops->step (req); + }else { + ctx->ops->complete (req);Do we really have to call ->complete() in this case?
I was simply to be consistent with the old code (that is currently in mainline) but to be honest I don't think so...
Quoted 12 lines
drivers/crypto/marvell/cesa.c MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if over · line 109
Quoted 10 lines
drivers/crypto/marvell/cesa.c +9
-0+ } + +return res; +} + +static int mv_cesa_int_process (struct mv_cesa_engine *engine,u32 status) +{ +if (engine->chain.first && engine->chain.last) +return mv_cesa_tdma_process (engine, status);Missing blank line.
ack
Quoted 8 lines
drivers/crypto/marvell/cesa.c MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if over · line 114
Quoted 6 lines
drivers/crypto/marvell/cesa.c +5
-0+return mv_cesa_std_process (engine, status); +} + +static inline void mv_cesa_complete_req (struct mv_cesa_ctx *ctx, +struct crypto_async_request *req,int res)Align parameters to the open parenthesis.
ack
Quoted 8 lines
drivers/crypto/marvell/cesa.c int mv_cesa_queue_req(struct crypto_async_request *req, · line 185
Quoted 6 lines
drivers/crypto/marvell/cesa.c +2
-0@@ -116,16 +181,15 @@ int mv_cesa_queue_req(struct crypto_async_request *req,struct mv_cesa_engine *engine = creq->engine;spin_lock_bh (&engine->lock); +if (mv_cesa_req_get_type (creq) ==CESA_DMA_REQ ) +mv_cesa_tdma_chain (engine, creq);Missing blank line.
ack
Quoted 5 lines
Quoted 5 lines
drivers/crypto/marvell/cesa.h +0
-0@@ -271,7 +271,9 @@ struct mv_cesa_op_ctx {
Quoted 8 lines
drivers/crypto/marvell/cesa.h struct mv_cesa_op_ctx { · line 275
Quoted 6 lines
drivers/crypto/marvell/cesa.h +2
-1/* TDMA descriptor flags */ #define CESA_TDMA_DST_IN_SRAM BIT(31)#define CESA_TDMA_SRC_IN_SRAM BIT(30) -#define CESA_TDMA_TYPE_MSK GENMASK(29, 0) +#define CESA_TDMA_END_OF_REQ BIT(29) +#define CESA_TDMA_NOT_CHAIN BIT(28)I would name it
CESA_TDMA_BREAK_CHAIN.
ack
Quoted 26 lines
Quoted 26 lines
drivers/crypto/marvell/cesa.h +6
-0+#define CESA_TDMA_TYPE_MSK GENMASK(27, 0)#define CESA_TDMA_DUMMY 0#define CESA_TDMA_DATA 1#define CESA_TDMA_OP 2@@ -431,6 +433,9 @@ struct mv_cesa_dev {* SRAM * @queue: fifo of the pending crypto requests * @load: engine load counter, useful for load balancing +* @chain: list of the current tdma descriptors being processed +* by this engine. +* @complete_queue: fifo of the processed requests by the engine * * Structure storing CESA engine information. */ @@ -448,6 +453,8 @@ struct mv_cesa_engine {struct gen_pool *pool;struct crypto_queue queue;atomic_t load; +struct mv_cesa_tdma_chain chain; +struct list_head complete_queue; };/** @@ -618,6 +625,28 @@ struct mv_cesa_ahash_req {
Quoted 7 lines
drivers/crypto/marvell/cesa.h struct mv_cesa_ahash_req { · line 630
Quoted 5 lines
drivers/crypto/marvell/cesa.h +3
-0extern struct mv_cesa_dev *cesa_dev; + +static inline void mv_cesa_engine_enqueue_complete_request ( +struct mv_cesa_engine *engine,struct crypto_async_request *req)Coding style issue (see my previous comments).
ok
Quoted 6 lines
drivers/crypto/marvell/cesa.h static inline bool mv_cesa_mac_op_is_first_frag(const struct mv_cesa_op_ctx *op) · line 733
Quoted 4 lines
drivers/crypto/marvell/cesa.h +3
-0+struct crypto_async_request *mv_cesa_dequeue_req_locked ( +struct mv_cesa_engine *engine, +struct crypto_async_request **backlog);Ditto.
ok
Quoted 6 lines
Quoted 6 lines
drivers/crypto/marvell/cesa.h +6
-0+void +mv_cesa_tdma_chain (struct mv_cesa_engine *engine,struct mv_cesa_req *dreq) +{ +if (engine->chain.first ==NULL && engine->chain.last ==NULL ) { + engine->chain.first = dreq->chain.first; + engine->chain.last = dreq->chain.last;
Quoted 8 lines
drivers/crypto/marvell/cesa.h struct mv_cesa_ahash_req { · line 645
Quoted 6 lines
drivers/crypto/marvell/cesa.h +6
-0+ }else { +struct mv_cesa_tdma_desc *last; + + last = engine->chain.last; + last->next = dreq->chain.first; + engine->chain.last = dreq->chain.last;Missing blank line.
ack
Quoted 45 lines
Quoted 45 lines
drivers/crypto/marvell/cesa.h +44
-0+if (!(last->flags &CESA_TDMA_NOT_CHAIN )) + last->next_dma = dreq->chain.first->cur_dma; + } +} + +int +mv_cesa_tdma_process (struct mv_cesa_engine *engine,u32 status) +{ +struct crypto_async_request *req =NULL ; +struct mv_cesa_tdma_desc *tdma =NULL , *next =NULL ; +dma_addr_t tdma_cur; +int res =0 ; + + tdma_cur =readl (engine->regs +CESA_TDMA_CUR ); + +for (tdma = engine->chain.first; tdma; tdma = next) { +spin_lock_bh (&engine->lock); + next = tdma->next; +spin_unlock_bh (&engine->lock); + +if (tdma->flags &CESA_TDMA_END_OF_REQ ) { +struct crypto_async_request *backlog =NULL ; +struct mv_cesa_ctx *ctx; + +spin_lock_bh (&engine->lock); +/* +* if req is NULL, this means we're processing the +* request in engine->req. +*/ +if (!req) + req = engine->req; +else + req =mv_cesa_dequeue_req_locked (engine, + &backlog); + +/* Re-chaining to the next request */ + engine->chain.first = tdma->next; + tdma->next =NULL ; + +/* If this is the last request, clear the chain */ +if (engine->chain.first ==NULL ) + engine->chain.last =NULL ; +spin_unlock_bh (&engine->lock); +
Quoted 8 lines
drivers/crypto/marvell/cesa.h
Quoted 2 lines
drivers/crypto/marvell/cesa.h +2
-0+ ctx =crypto_tfm_ctx (req->tfm); + res = ctx->ops->process (req, status);Hm, that's not exactly true. The status you're passing here is only valid for the last request that has been processed. Say you queued 3 requests. 2 of them were correctly processed, but the last one triggered an error. You don't want the first 2 requests to be considered bad.
I will re-work this part
Quoted 12 lines
drivers/crypto/marvell/cesa.h
Quoted 10 lines
drivers/crypto/marvell/cesa.h +9
-0+ ctx->ops->complete (req); + +if (res ==0 ) +mv_cesa_engine_enqueue_complete_request (engine, + req); + +if (backlog) + backlog->complete (backlog, -EINPROGRESS ); + }Missing blank line.
ok
Quoted 15 lines
drivers/crypto/marvell/cesa.h
Quoted 10 lines
drivers/crypto/marvell/cesa.h +9
-0+if (res || tdma->cur_dma == tdma_cur) +break ; + } + +if (res) { +spin_lock_bh (&engine->lock); + engine->req = req; +spin_unlock_bh (&engine->lock); + }Maybe you can add a comment explaining that you are actually setting the last processed request into
engine->req, so that the core can know which request was faulty.
I added a comment
Thanks !
Romain
Signature · 3 lines
Romain Perier, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com