Re: [PATCH] crypto: caam - treat SGT address pointer as u64

2016-09-29 Thread Fabio Estevam
Hi Tudor,

On Thu, Sep 29, 2016 at 11:17 AM, Tudor Ambarus
 wrote:

> diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h
> index b3c5016..effbdd8 100644
> --- a/drivers/crypto/caam/regs.h
> +++ b/drivers/crypto/caam/regs.h
> @@ -196,6 +196,14 @@ static inline u64 rd_reg64(void __iomem *reg)
>  #define caam_dma_to_cpu(value) caam32_to_cpu(value)
>  #endif /* CONFIG_ARCH_DMA_ADDR_T_64BIT  */
>
> +#ifdef CONFIG_SOC_IMX7D

Why is this restricted to mx7d?
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] hwrng: meson: Fix module autoload for OF registration

2016-10-17 Thread Fabio Estevam
On Mon, Oct 17, 2016 at 5:40 PM, Javier Martinez Canillas
 wrote:

> --- a/drivers/char/tpm/Kconfig
> +++ b/drivers/char/tpm/Kconfig
> @@ -32,7 +32,7 @@ config TCG_TIS_CORE
>
>  config TCG_TIS
> tristate "TPM Interface Specification 1.2 Interface / TPM 2.0 FIFO 
> Interface"
> -   depends on X86
> +   depends on X86 || COMPILE_TEST

This is a separate change.
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: mxs-dcp - Remove hash support

2016-10-24 Thread Fabio Estevam
From: Fabio Estevam 

mxs-dcp driver does not probe for a long time:

mxs-dcp 80028000.dcp: Failed to register sha1 hash!
mxs-dcp: probe of 80028000.dcp failed with error -22

There were some previous attempts to fix this, and the following
feedback was given by Herbert Xu's [1]:

"This driver is hopelessly broken as its request context doesn't
contain the hash state at all.  Unless someone can fix that we
should probably just remove the hash implementations altogether."

[1] http://www.spinics.net/lists/linux-crypto/msg18187.html

So remove the hash support for now.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/mxs-dcp.c | 367 +--
 1 file changed, 2 insertions(+), 365 deletions(-)

diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index 625ee50..b1b1dda 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -498,278 +498,6 @@ static void mxs_dcp_aes_fallback_exit(struct crypto_tfm 
*tfm)
crypto_free_skcipher(actx->fallback);
 }
 
-/*
- * Hashing (SHA1/SHA256)
- */
-static int mxs_dcp_run_sha(struct ahash_request *req)
-{
-   struct dcp *sdcp = global_sdcp;
-   int ret;
-
-   struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
-   struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm);
-   struct dcp_sha_req_ctx *rctx = ahash_request_ctx(req);
-   struct hash_alg_common *halg = crypto_hash_alg_common(tfm);
-
-   struct dcp_dma_desc *desc = &sdcp->coh->desc[actx->chan];
-
-   dma_addr_t digest_phys = 0;
-   dma_addr_t buf_phys = dma_map_single(sdcp->dev, sdcp->coh->sha_in_buf,
-DCP_BUF_SZ, DMA_TO_DEVICE);
-
-   /* Fill in the DMA descriptor. */
-   desc->control0 = MXS_DCP_CONTROL0_DECR_SEMAPHORE |
-   MXS_DCP_CONTROL0_INTERRUPT |
-   MXS_DCP_CONTROL0_ENABLE_HASH;
-   if (rctx->init)
-   desc->control0 |= MXS_DCP_CONTROL0_HASH_INIT;
-
-   desc->control1 = actx->alg;
-   desc->next_cmd_addr = 0;
-   desc->source = buf_phys;
-   desc->destination = 0;
-   desc->size = actx->fill;
-   desc->payload = 0;
-   desc->status = 0;
-
-   /* Set HASH_TERM bit for last transfer block. */
-   if (rctx->fini) {
-   digest_phys = dma_map_single(sdcp->dev, req->result,
-halg->digestsize, DMA_FROM_DEVICE);
-   desc->control0 |= MXS_DCP_CONTROL0_HASH_TERM;
-   desc->payload = digest_phys;
-   }
-
-   ret = mxs_dcp_start_dma(actx);
-
-   if (rctx->fini)
-   dma_unmap_single(sdcp->dev, digest_phys, halg->digestsize,
-DMA_FROM_DEVICE);
-
-   dma_unmap_single(sdcp->dev, buf_phys, DCP_BUF_SZ, DMA_TO_DEVICE);
-
-   return ret;
-}
-
-static int dcp_sha_req_to_buf(struct crypto_async_request *arq)
-{
-   struct dcp *sdcp = global_sdcp;
-
-   struct ahash_request *req = ahash_request_cast(arq);
-   struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
-   struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm);
-   struct dcp_sha_req_ctx *rctx = ahash_request_ctx(req);
-   struct hash_alg_common *halg = crypto_hash_alg_common(tfm);
-   const int nents = sg_nents(req->src);
-
-   uint8_t *in_buf = sdcp->coh->sha_in_buf;
-
-   uint8_t *src_buf;
-
-   struct scatterlist *src;
-
-   unsigned int i, len, clen;
-   int ret;
-
-   int fin = rctx->fini;
-   if (fin)
-   rctx->fini = 0;
-
-   for_each_sg(req->src, src, nents, i) {
-   src_buf = sg_virt(src);
-   len = sg_dma_len(src);
-
-   do {
-   if (actx->fill + len > DCP_BUF_SZ)
-   clen = DCP_BUF_SZ - actx->fill;
-   else
-   clen = len;
-
-   memcpy(in_buf + actx->fill, src_buf, clen);
-   len -= clen;
-   src_buf += clen;
-   actx->fill += clen;
-
-   /*
-* If we filled the buffer and still have some
-* more data, submit the buffer.
-*/
-   if (len && actx->fill == DCP_BUF_SZ) {
-   ret = mxs_dcp_run_sha(req);
-   if (ret)
-   return ret;
-   actx->fill = 0;
-   rctx->init = 0;
-   }
-   } while (len);
-   }
-
-   if (fin) {
-   rctx->fini = 1;
-
-   /* Submit whatever is left. */
-   if (!req->result)
-   

[PATCH v2] crypto: mxs-dcp - Remove hash support

2016-10-24 Thread Fabio Estevam
From: Fabio Estevam 

mxs-dcp driver does not probe for a long time:

mxs-dcp 80028000.dcp: Failed to register sha1 hash!
mxs-dcp: probe of 80028000.dcp failed with error -22

There were some previous attempts to fix this, and the following
feedback was given by Herbert Xu [1]:

"This driver is hopelessly broken as its request context doesn't
contain the hash state at all.  Unless someone can fix that we
should probably just remove the hash implementations altogether."

[1] http://www.spinics.net/lists/linux-crypto/msg18187.html

So remove the hash support for now.

Signed-off-by: Fabio Estevam 
---
Changes since v1:
- Fix typo in commit log

 drivers/crypto/mxs-dcp.c | 367 +--
 1 file changed, 2 insertions(+), 365 deletions(-)

diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index 625ee50..b1b1dda 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -498,278 +498,6 @@ static void mxs_dcp_aes_fallback_exit(struct crypto_tfm 
*tfm)
crypto_free_skcipher(actx->fallback);
 }
 
-/*
- * Hashing (SHA1/SHA256)
- */
-static int mxs_dcp_run_sha(struct ahash_request *req)
-{
-   struct dcp *sdcp = global_sdcp;
-   int ret;
-
-   struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
-   struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm);
-   struct dcp_sha_req_ctx *rctx = ahash_request_ctx(req);
-   struct hash_alg_common *halg = crypto_hash_alg_common(tfm);
-
-   struct dcp_dma_desc *desc = &sdcp->coh->desc[actx->chan];
-
-   dma_addr_t digest_phys = 0;
-   dma_addr_t buf_phys = dma_map_single(sdcp->dev, sdcp->coh->sha_in_buf,
-DCP_BUF_SZ, DMA_TO_DEVICE);
-
-   /* Fill in the DMA descriptor. */
-   desc->control0 = MXS_DCP_CONTROL0_DECR_SEMAPHORE |
-   MXS_DCP_CONTROL0_INTERRUPT |
-   MXS_DCP_CONTROL0_ENABLE_HASH;
-   if (rctx->init)
-   desc->control0 |= MXS_DCP_CONTROL0_HASH_INIT;
-
-   desc->control1 = actx->alg;
-   desc->next_cmd_addr = 0;
-   desc->source = buf_phys;
-   desc->destination = 0;
-   desc->size = actx->fill;
-   desc->payload = 0;
-   desc->status = 0;
-
-   /* Set HASH_TERM bit for last transfer block. */
-   if (rctx->fini) {
-   digest_phys = dma_map_single(sdcp->dev, req->result,
-halg->digestsize, DMA_FROM_DEVICE);
-   desc->control0 |= MXS_DCP_CONTROL0_HASH_TERM;
-   desc->payload = digest_phys;
-   }
-
-   ret = mxs_dcp_start_dma(actx);
-
-   if (rctx->fini)
-   dma_unmap_single(sdcp->dev, digest_phys, halg->digestsize,
-DMA_FROM_DEVICE);
-
-   dma_unmap_single(sdcp->dev, buf_phys, DCP_BUF_SZ, DMA_TO_DEVICE);
-
-   return ret;
-}
-
-static int dcp_sha_req_to_buf(struct crypto_async_request *arq)
-{
-   struct dcp *sdcp = global_sdcp;
-
-   struct ahash_request *req = ahash_request_cast(arq);
-   struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
-   struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm);
-   struct dcp_sha_req_ctx *rctx = ahash_request_ctx(req);
-   struct hash_alg_common *halg = crypto_hash_alg_common(tfm);
-   const int nents = sg_nents(req->src);
-
-   uint8_t *in_buf = sdcp->coh->sha_in_buf;
-
-   uint8_t *src_buf;
-
-   struct scatterlist *src;
-
-   unsigned int i, len, clen;
-   int ret;
-
-   int fin = rctx->fini;
-   if (fin)
-   rctx->fini = 0;
-
-   for_each_sg(req->src, src, nents, i) {
-   src_buf = sg_virt(src);
-   len = sg_dma_len(src);
-
-   do {
-   if (actx->fill + len > DCP_BUF_SZ)
-   clen = DCP_BUF_SZ - actx->fill;
-   else
-   clen = len;
-
-   memcpy(in_buf + actx->fill, src_buf, clen);
-   len -= clen;
-   src_buf += clen;
-   actx->fill += clen;
-
-   /*
-* If we filled the buffer and still have some
-* more data, submit the buffer.
-*/
-   if (len && actx->fill == DCP_BUF_SZ) {
-   ret = mxs_dcp_run_sha(req);
-   if (ret)
-   return ret;
-   actx->fill = 0;
-   rctx->init = 0;
-   }
-   } while (len);
-   }
-
-   if (fin) {
-   rctx->fini = 1;
-
-   /* Submit whatever is left. */
-   if (

Re: [PATCH v2] crypto: mxs-dcp - Remove hash support

2016-10-24 Thread Fabio Estevam
On Mon, Oct 24, 2016 at 6:39 PM, Marek Vasut  wrote:

> Can't you rather fix it?

I would love to have this fixed, but I don't know how.

Any volunteers?
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] crypto: mxs-dcp - Remove hash support

2016-10-29 Thread Fabio Estevam
Hi Horia,

On Fri, Oct 28, 2016 at 5:55 PM, Horia Geanta Neag  wrote:

> Looking on the i.MX6 Solo Lite security manual, the fix seems to consist
> in enabling context switching - i.e. setting
> DCP_CTRL[ENABLE_CONTEXT_SWITCHING] - and saving/restoring (part of) the
> context buffer.
>
> However, I am not familiar with DCP crypto engine and don't have HW to test.

I do have access to hardware to test. Could you please propose some
patches I can try?

My previous attempt to fix this issue was this one:
http://www.spinics.net/lists/linux-crypto/msg18039.html

Thanks,

Fabio Estevam
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Fix dma unmap direction in iMX sahara aes calculation

2017-07-25 Thread Fabio Estevam
Hi Mogens,

On Sun, Jul 16, 2017 at 6:21 PM, Mogens Lauridsen
 wrote:
> Hi,
>
> The direction used in dma_unmap_sg in aes calc in sahara.c is wrong.
> This result in the cache not being invalidated correct when aes
> calculation is done and result is dma'ed to memory.
> This is seen as sporadic wrong result from aes calc.
>
> Thanks,
> Mogens
>
> Signed-off-by: Mogens Lauridsen 

Your two fixes are good, but the patch format is not correct.

You could try to use git send-email for submitting the two patches.

Subject could be improved. If you run 'git log
drivers/crypto/sahara.c' you will see the common standard, so you
could do:

crypto: sahara - Fix dma unmap direction as the Subject.

Then you need to run './scripts/checkpatch.pl 0001-your.patch' to see
what people and lists to send it to.

Please resend them.


[PATCH] crypto: caam/qi - Remove unused 'qi_congested' entry

2017-07-29 Thread Fabio Estevam
From: Fabio Estevam 

'qi_congested' member from structure caam_drv_private
is never used at all, so it is safe to remove it.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/caam/intern.h | 3 ---
 drivers/crypto/caam/qi.c | 6 ++
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/caam/intern.h b/drivers/crypto/caam/intern.h
index 9e3f3e0..9625b2d 100644
--- a/drivers/crypto/caam/intern.h
+++ b/drivers/crypto/caam/intern.h
@@ -109,9 +109,6 @@ struct caam_drv_private {
 
struct debugfs_blob_wrapper ctl_kek_wrap, ctl_tkek_wrap, ctl_tdsk_wrap;
struct dentry *ctl_kek, *ctl_tkek, *ctl_tdsk;
-#ifdef CONFIG_CAAM_QI
-   struct dentry *qi_congested;
-#endif
 #endif
 };
 
diff --git a/drivers/crypto/caam/qi.c b/drivers/crypto/caam/qi.c
index 6d5a010..b2f7a42 100644
--- a/drivers/crypto/caam/qi.c
+++ b/drivers/crypto/caam/qi.c
@@ -793,10 +793,8 @@ int caam_qi_init(struct platform_device *caam_pdev)
/* Done with the CGRs; restore the cpus allowed mask */
set_cpus_allowed_ptr(current, &old_cpumask);
 #ifdef CONFIG_DEBUG_FS
-   ctrlpriv->qi_congested = debugfs_create_file("qi_congested", 0444,
-ctrlpriv->ctl,
-×_congested,
-&caam_fops_u64_ro);
+   debugfs_create_file("qi_congested", 0444, ctrlpriv->ctl,
+   ×_congested, &caam_fops_u64_ro);
 #endif
dev_info(qidev, "Linux CAAM Queue I/F driver initialised\n");
return 0;
-- 
2.7.4



Re: [PATCH] crypto: caam/qi - Remove unused 'qi_congested' entry

2017-07-31 Thread Fabio Estevam
On Mon, Jul 31, 2017 at 4:22 AM, Horia Geantă  wrote:
> On 7/30/2017 1:55 AM, Fabio Estevam wrote:
>> From: Fabio Estevam 
>>
>> 'qi_congested' member from structure caam_drv_private
>> is never used at all, so it is safe to remove it.
>
> Agree, though I would remove all the other dentry members not currently
> used - since debugfs_remove_recursive() is called, we don't need the
> file entries.

Ok, it makes sense. Wil do it in v2.

>> diff --git a/drivers/crypto/caam/qi.c b/drivers/crypto/caam/qi.c
>> index 6d5a010..b2f7a42 100644
>> --- a/drivers/crypto/caam/qi.c
>> +++ b/drivers/crypto/caam/qi.c
>> @@ -793,10 +793,8 @@ int caam_qi_init(struct platform_device *caam_pdev)
>>   /* Done with the CGRs; restore the cpus allowed mask */
>>   set_cpus_allowed_ptr(current, &old_cpumask);
>>  #ifdef CONFIG_DEBUG_FS
>> - ctrlpriv->qi_congested = debugfs_create_file("qi_congested", 0444,
>> -  ctrlpriv->ctl,
>> -  ×_congested,
>> -  &caam_fops_u64_ro);
>> + debugfs_create_file("qi_congested", 0444, ctrlpriv->ctl,
>> + ×_congested, &caam_fops_u64_ro);
>
> Either here or in a different patch the return value of debugfs_create_*
> functions should be checked, such that if IS_ERR_OR_NULL(ret) we could
> print a warning.

I will leave the error checking for a separate patch then.


[PATCH v2] crypto: caam: Remove unused dentry members

2017-07-31 Thread Fabio Estevam
Most of the dentry members from structure caam_drv_private
are never used at all, so it is safe to remove them.

Since debugfs_remove_recursive() is called, we don't need the
file entries.

Signed-off-by: Fabio Estevam 
---
Changes since v1:
- Remove all the unused dentry members (Horia)

 drivers/crypto/caam/ctrl.c   | 81 
 drivers/crypto/caam/intern.h |  8 -
 drivers/crypto/caam/qi.c |  6 ++--
 3 files changed, 32 insertions(+), 63 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 7338f15..dc65fed 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -734,59 +734,38 @@ static int caam_probe(struct platform_device *pdev)
 ctrlpriv->total_jobrs, ctrlpriv->qi_present);
 
 #ifdef CONFIG_DEBUG_FS
-
-   ctrlpriv->ctl_rq_dequeued =
-   debugfs_create_file("rq_dequeued",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->req_dequeued,
-   &caam_fops_u64_ro);
-   ctrlpriv->ctl_ob_enc_req =
-   debugfs_create_file("ob_rq_encrypted",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->ob_enc_req,
-   &caam_fops_u64_ro);
-   ctrlpriv->ctl_ib_dec_req =
-   debugfs_create_file("ib_rq_decrypted",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->ib_dec_req,
-   &caam_fops_u64_ro);
-   ctrlpriv->ctl_ob_enc_bytes =
-   debugfs_create_file("ob_bytes_encrypted",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->ob_enc_bytes,
-   &caam_fops_u64_ro);
-   ctrlpriv->ctl_ob_prot_bytes =
-   debugfs_create_file("ob_bytes_protected",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->ob_prot_bytes,
-   &caam_fops_u64_ro);
-   ctrlpriv->ctl_ib_dec_bytes =
-   debugfs_create_file("ib_bytes_decrypted",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->ib_dec_bytes,
-   &caam_fops_u64_ro);
-   ctrlpriv->ctl_ib_valid_bytes =
-   debugfs_create_file("ib_bytes_validated",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->ib_valid_bytes,
-   &caam_fops_u64_ro);
+   debugfs_create_file("rq_dequeued",S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->req_dequeued,
+   &caam_fops_u64_ro);
+   debugfs_create_file("ob_rq_encrypted", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->ob_enc_req,
+   &caam_fops_u64_ro);
+   debugfs_create_file("ib_rq_decrypted", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->ib_dec_req,
+   &caam_fops_u64_ro);
+   debugfs_create_file("ob_bytes_encrypted", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->ob_enc_bytes,
+   &caam_fops_u64_ro);
+   debugfs_create_file("ob_bytes_protected", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->ob_prot_bytes,
+   &caam_fops_u64_ro);
+   debugfs_create_file("ib_bytes_decrypted", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->ib_dec_bytes,
+   &caam_fops_u64_ro);
+   debugfs_create_file("ib_bytes_validated", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->ib_valid_bytes,
+   &caam_fops_u64_ro);
 
/* Controller level - global status values */
-   ctrlpriv->ctl_faultaddr =
-   debugfs_create_file("fault_addr",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->faultaddr,
-   &caam_fops_u32_ro);
-   ctrlpriv->ctl_faultdetail =

[PATCH v3] crypto: caam: Remove unused dentry members

2017-08-01 Thread Fabio Estevam
Most of the dentry members from structure caam_drv_private
are never used at all, so it is safe to remove them.

Since debugfs_remove_recursive() is called, we don't need the
file entries.

Signed-off-by: Fabio Estevam 
---
Changes since v2:
- Add missing space
Changes since v1:
- Remove all the unused dentry members (Horia)

 drivers/crypto/caam/ctrl.c   | 81 
 drivers/crypto/caam/intern.h |  8 -
 drivers/crypto/caam/qi.c |  6 ++--
 3 files changed, 32 insertions(+), 63 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 7338f15..dc65fed 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -734,59 +734,38 @@ static int caam_probe(struct platform_device *pdev)
 ctrlpriv->total_jobrs, ctrlpriv->qi_present);
 
 #ifdef CONFIG_DEBUG_FS
-
-   ctrlpriv->ctl_rq_dequeued =
-   debugfs_create_file("rq_dequeued",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->req_dequeued,
-   &caam_fops_u64_ro);
-   ctrlpriv->ctl_ob_enc_req =
-   debugfs_create_file("ob_rq_encrypted",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->ob_enc_req,
-   &caam_fops_u64_ro);
-   ctrlpriv->ctl_ib_dec_req =
-   debugfs_create_file("ib_rq_decrypted",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->ib_dec_req,
-   &caam_fops_u64_ro);
-   ctrlpriv->ctl_ob_enc_bytes =
-   debugfs_create_file("ob_bytes_encrypted",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->ob_enc_bytes,
-   &caam_fops_u64_ro);
-   ctrlpriv->ctl_ob_prot_bytes =
-   debugfs_create_file("ob_bytes_protected",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->ob_prot_bytes,
-   &caam_fops_u64_ro);
-   ctrlpriv->ctl_ib_dec_bytes =
-   debugfs_create_file("ib_bytes_decrypted",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->ib_dec_bytes,
-   &caam_fops_u64_ro);
-   ctrlpriv->ctl_ib_valid_bytes =
-   debugfs_create_file("ib_bytes_validated",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->ib_valid_bytes,
-   &caam_fops_u64_ro);
+   debugfs_create_file("rq_dequeued", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->req_dequeued,
+   &caam_fops_u64_ro);
+   debugfs_create_file("ob_rq_encrypted", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->ob_enc_req,
+   &caam_fops_u64_ro);
+   debugfs_create_file("ib_rq_decrypted", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->ib_dec_req,
+   &caam_fops_u64_ro);
+   debugfs_create_file("ob_bytes_encrypted", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->ob_enc_bytes,
+   &caam_fops_u64_ro);
+   debugfs_create_file("ob_bytes_protected", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->ob_prot_bytes,
+   &caam_fops_u64_ro);
+   debugfs_create_file("ib_bytes_decrypted", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->ib_dec_bytes,
+   &caam_fops_u64_ro);
+   debugfs_create_file("ib_bytes_validated", S_IRUSR | S_IRGRP | S_IROTH,
+   ctrlpriv->ctl, &perfmon->ib_valid_bytes,
+   &caam_fops_u64_ro);
 
/* Controller level - global status values */
-   ctrlpriv->ctl_faultaddr =
-   debugfs_create_file("fault_addr",
-   S_IRUSR | S_IRGRP | S_IROTH,
-   ctrlpriv->ctl, &perfmon->faultaddr,
-   &caam_fops_u32_ro);
-   ctrlpriv->ctl_faul

Re: [PATCH v2 1/3] crypto: sahara - avoid needlessly saving and restoring sahara_ctx

2016-02-02 Thread Fabio Estevam
Hi Herbert,

On Mon, Jan 25, 2016 at 12:07 PM, Herbert Xu
 wrote:

> Very good.  Not only is it a waste, it's a gaping security hole
> because modifying the tfm from import will corrupt it.
>
> But this is not enough, you're still copying things like the mutex
> which should not be copied but instead should be reinitialised in
> import.

So import() will look like this?

static int sahara_sha_import(struct ahash_request *req, const void *in)
{
struct sahara_sha_reqctx *rctx = ahash_request_ctx(req);

mutex_init(&rctx->mutex);
memcpy(rctx, in, sizeof(struct sahara_sha_reqctx));

return 0;
}

Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/3] crypto: sahara - avoid needlessly saving and restoring sahara_ctx

2016-02-02 Thread Fabio Estevam
On Tue, Feb 2, 2016 at 12:43 PM, Herbert Xu  wrote:

> Preferably you shouldn't include the mutex in the exported state
> at all.

Ok, so would it be safe to completely remove the mutex like this?

--- a/drivers/crypto/sahara.c
+++ b/drivers/crypto/sahara.c
@@ -182,7 +182,6 @@ struct sahara_sha_reqctx {
u8  buf[SAHARA_MAX_SHA_BLOCK_SIZE];
u8  rembuf[SAHARA_MAX_SHA_BLOCK_SIZE];
u8  context[SHA256_DIGEST_SIZE + 4];
-   struct mutexmutex;
unsigned intmode;
unsigned intdigest_size;
unsigned intcontext_size;
@@ -1096,7 +1095,6 @@ static int sahara_sha_enqueue(struct ahash_request *req, i
if (!req->nbytes && !last)
return 0;

-   mutex_lock(&rctx->mutex);
rctx->last = last;

if (!rctx->active) {
@@ -1109,7 +1107,6 @@ static int sahara_sha_enqueue(struct ahash_request *req, i
mutex_unlock(&dev->queue_mutex);

wake_up_process(dev->kthread);
-   mutex_unlock(&rctx->mutex);

return ret;
 }
@@ -1137,8 +1134,6 @@ static int sahara_sha_init(struct ahash_request *req)
rctx->context_size = rctx->digest_size + 4;
rctx->active = 0;

-   mutex_init(&rctx->mutex);
-
return 0;
 }

Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 1/3] crypto: sahara - remove unneeded mutex in the exported state

2016-02-03 Thread Fabio Estevam
As pointed out by Herbert Xu we should not include the mutex in the
exported state, so let's just get rid of it.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/sahara.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c
index 6c4f91c..7e8147d 100644
--- a/drivers/crypto/sahara.c
+++ b/drivers/crypto/sahara.c
@@ -182,7 +182,6 @@ struct sahara_sha_reqctx {
u8  buf[SAHARA_MAX_SHA_BLOCK_SIZE];
u8  rembuf[SAHARA_MAX_SHA_BLOCK_SIZE];
u8  context[SHA256_DIGEST_SIZE + 4];
-   struct mutexmutex;
unsigned intmode;
unsigned intdigest_size;
unsigned intcontext_size;
@@ -1096,7 +1095,6 @@ static int sahara_sha_enqueue(struct ahash_request *req, 
int last)
if (!req->nbytes && !last)
return 0;
 
-   mutex_lock(&rctx->mutex);
rctx->last = last;
 
if (!rctx->active) {
@@ -1109,7 +1107,6 @@ static int sahara_sha_enqueue(struct ahash_request *req, 
int last)
mutex_unlock(&dev->queue_mutex);
 
wake_up_process(dev->kthread);
-   mutex_unlock(&rctx->mutex);
 
return ret;
 }
@@ -1137,8 +1134,6 @@ static int sahara_sha_init(struct ahash_request *req)
rctx->context_size = rctx->digest_size + 4;
rctx->active = 0;
 
-   mutex_init(&rctx->mutex);
-
return 0;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 2/3] crypto: sahara - avoid needlessly saving and restoring sahara_ctx

2016-02-03 Thread Fabio Estevam
Based on commit 434b421241f2d0 ("crypto: caam - avoid needlessly saving and
restoring caam_hash_ctx") from Russell King.

When exporting and importing the hash state, we will only export and
import into hashes which share the same struct crypto_ahash pointer.
(See hash_accept->af_alg_accept->hash_accept_parent.)

This means that saving the sahara_ctx structure on export, and
restoring it on import is a waste of resources.  So, remove this code.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/sahara.c | 12 ++--
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c
index 7e8147d..9db09b6 100644
--- a/drivers/crypto/sahara.c
+++ b/drivers/crypto/sahara.c
@@ -1162,26 +1162,18 @@ static int sahara_sha_digest(struct ahash_request *req)
 
 static int sahara_sha_export(struct ahash_request *req, void *out)
 {
-   struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
-   struct sahara_ctx *ctx = crypto_ahash_ctx(ahash);
struct sahara_sha_reqctx *rctx = ahash_request_ctx(req);
 
-   memcpy(out, ctx, sizeof(struct sahara_ctx));
-   memcpy(out + sizeof(struct sahara_sha_reqctx), rctx,
-  sizeof(struct sahara_sha_reqctx));
+   memcpy(out, rctx, sizeof(struct sahara_sha_reqctx));
 
return 0;
 }
 
 static int sahara_sha_import(struct ahash_request *req, const void *in)
 {
-   struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
-   struct sahara_ctx *ctx = crypto_ahash_ctx(ahash);
struct sahara_sha_reqctx *rctx = ahash_request_ctx(req);
 
-   memcpy(ctx, in, sizeof(struct sahara_ctx));
-   memcpy(rctx, in + sizeof(struct sahara_sha_reqctx),
-  sizeof(struct sahara_sha_reqctx));
+   memcpy(rctx, in, sizeof(struct sahara_sha_reqctx));
 
return 0;
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 3/3] crypto: sahara - fill the statesize field

2016-02-03 Thread Fabio Estevam
Currently the sahara driver fails to probe:

sahara: probe of 63ff8000.crypto failed with error -22

This happens since commit 8996eafdcbad ("crypto: ahash - ensure statesize
is non-zero"), which requires statesize to be filled.

Pass the statesize members for sha1 and sha256, so we can probe
the driver successfully again.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/sahara.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c
index 9db09b6..c3f3d89 100644
--- a/drivers/crypto/sahara.c
+++ b/drivers/crypto/sahara.c
@@ -1259,6 +1259,7 @@ static struct ahash_alg sha_v3_algs[] = {
.export = sahara_sha_export,
.import = sahara_sha_import,
.halg.digestsize= SHA1_DIGEST_SIZE,
+   .halg.statesize = sizeof(struct sahara_sha_reqctx),
.halg.base  = {
.cra_name   = "sha1",
.cra_driver_name= "sahara-sha1",
@@ -1286,6 +1287,7 @@ static struct ahash_alg sha_v4_algs[] = {
.export = sahara_sha_export,
.import = sahara_sha_import,
.halg.digestsize= SHA256_DIGEST_SIZE,
+   .halg.statesize = sizeof(struct sahara_sha_reqctx),
.halg.base  = {
.cra_name   = "sha256",
.cra_driver_name= "sahara-sha256",
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: caam - Staticize caam_jr_shutdown()

2016-02-14 Thread Fabio Estevam
From: Fabio Estevam 

caam_jr_shutdown() is only used in this file, so it can be
made static.

This avoids the following sparse warning:

drivers/crypto/caam/jr.c:68:5: warning: symbol 'caam_jr_shutdown' was not 
declared. Should it be static?

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/caam/jr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index f7e0d8d..6fd63a6 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -65,7 +65,7 @@ static int caam_reset_hw_jr(struct device *dev)
 /*
  * Shutdown JobR independent of platform property code
  */
-int caam_jr_shutdown(struct device *dev)
+static int caam_jr_shutdown(struct device *dev)
 {
struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
dma_addr_t inpbusaddr, outbusaddr;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] hwrng: mxc-fsl - add support for Freescale RNGC

2016-02-29 Thread Fabio Estevam
On Mon, Feb 29, 2016 at 12:52 PM, Steffen Trumtrar
 wrote:

> +   ret = clk_prepare_enable(rngc->clk);
> +   if (ret)
> +   return ret;
> +
> +   rngc->irq = platform_get_irq(pdev, 0);
> +   if (!rngc->irq) {
> +   dev_err(&pdev->dev, "FSL RNGC couldn't get irq\n");
> +   clk_disable_unprepare(rngc->clk);
> +
> +   return ret;

You are returning the wrong error code here:

Better do like this:

   rngc->irq = platform_get_irq(pdev, 0);
   if (rngc->irq < 0) {
   dev_err(&pdev->dev, "FSL RNGC couldn't get irq\n");
   clk_disable_unprepare(rngc->clk);
   return rngc->irq;
   }
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] hwrng: mxc-fsl - add support for Freescale RNGC

2016-02-29 Thread Fabio Estevam
On Mon, Feb 29, 2016 at 6:38 PM, Uwe Kleine-König
 wrote:
> On Mon, Feb 29, 2016 at 06:16:50PM -0300, Fabio Estevam wrote:
>> On Mon, Feb 29, 2016 at 12:52 PM, Steffen Trumtrar
>>  wrote:
>>
>> > +   ret = clk_prepare_enable(rngc->clk);
>> > +   if (ret)
>> > +   return ret;
>> > +
>> > +   rngc->irq = platform_get_irq(pdev, 0);
>> > +   if (!rngc->irq) {
>> > +   dev_err(&pdev->dev, "FSL RNGC couldn't get irq\n");
>> > +   clk_disable_unprepare(rngc->clk);
>> > +
>> > +   return ret;
>>
>> You are returning the wrong error code here:
>>
>> Better do like this:
>>
>>rngc->irq = platform_get_irq(pdev, 0);
>>if (rngc->irq < 0) {
>
> rngc->irq is unsigned, so this is never true.
>
>>dev_err(&pdev->dev, "FSL RNGC couldn't get irq\n");
>>clk_disable_unprepare(rngc->clk);
>>return rngc->irq;
>>}
>
> So here comes my better approach:

As irq is only used inside probe it can be removed from struct mxc_rngc.

Or maybe like this:

 ret = platform_get_irq(pdev, 0);
 if (ret < 0) {
 dev_err(&pdev->dev, "FSL RNGC couldn't get irq\n");
 clk_disable_unprepare(rngc->clk);
 return ret;
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 00/11] Further iMX CAAM updates

2016-08-08 Thread Fabio Estevam
Hi Russell,

On Mon, Aug 8, 2016 at 2:04 PM, Russell King - ARM Linux
 wrote:
> This is a re-post (with hopefully bugs fixed from December's review).
> Untested, because AF_ALG appears to be broken in 4.8-rc1.  Maybe
> someone can provide some hints how to test using tcrypt please?
>
> Here are further imx-caam updates that I've had since before the
> previous merge window.  Please review and (I guess) if Freescale
> folk can provide acks etc that would be nice.  Thanks.

I am adding Horia on Cc, who is familiar with the caam driver.

Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: mxc-scc - check clk_prepare_enable() error

2016-08-21 Thread Fabio Estevam
From: Fabio Estevam 

clk_prepare_enable() may fail, so we should better check its return
value and propagate it in the case of failure.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/mxc-scc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/mxc-scc.c b/drivers/crypto/mxc-scc.c
index ff383ef..ee4be1b0 100644
--- a/drivers/crypto/mxc-scc.c
+++ b/drivers/crypto/mxc-scc.c
@@ -668,7 +668,9 @@ static int mxc_scc_probe(struct platform_device *pdev)
return PTR_ERR(scc->clk);
}
 
-   clk_prepare_enable(scc->clk);
+   ret = clk_prepare_enable(scc->clk);
+   if (ret)
+   return ret;
 
/* clear error status register */
writel(0x0, scc->base + SCC_SCM_ERROR_STATUS);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: crypto: mxs-dcp: do not call blocking ops when !TASK_RUNNING; state=1

2016-08-24 Thread Fabio Estevam
Hi Stefan,

On Tue, Aug 23, 2016 at 5:38 PM, Stefan Wahren  wrote:
> Hi,
>
> i'm using a iMX233-OLinuXino board and i get the following warning during boot
> with 4.8.0-rc2-next-20160819:
>
> [2.45] [ cut here ]
> [2.45] WARNING: CPU: 0 PID: 42 at kernel/sched/core.c:7602
> __might_sleep+0x8c/0xa0
> [2.47] do not call blocking ops when !TASK_RUNNING; state=1 set at
> [] dcp_chan_thread_aes+0x24/0x664

Did you select any debug option to observe such messages?

The kernelci boot log does not show this problem on a imx23-olinuxino
running linux-next:
https://storage.kernelci.org/next/next-20160824/arm-mxs_defconfig/lab-pengutronix/boot-imx23-olinuxino.html

We still have the errors below:

[4.40] mxs-dcp 80028000.dcp: Failed to register sha1 hash!
[4.41] mxs-dcp: probe of 80028000.dcp failed with error -22

,but that's a different issue.

Regards,

Fabio Estevam
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: sahara - propagate the error on clk_disable_unprepare() failure

2015-06-20 Thread Fabio Estevam
From: Fabio Estevam 

clk_prepare_enable() may fail, so we should better check its return value
and propagate it in the case of error.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/sahara.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c
index 6be377f..397a500b 100644
--- a/drivers/crypto/sahara.c
+++ b/drivers/crypto/sahara.c
@@ -1578,8 +1578,12 @@ static int sahara_probe(struct platform_device *pdev)
 
init_completion(&dev->dma_completion);
 
-   clk_prepare_enable(dev->clk_ipg);
-   clk_prepare_enable(dev->clk_ahb);
+   err = clk_prepare_enable(dev->clk_ipg);
+   if (err)
+   goto err_link;
+   err = clk_prepare_enable(dev->clk_ahb);
+   if (err)
+   goto clk_ipg_disable;
 
version = sahara_read(dev, SAHARA_REG_VERSION);
if (of_device_is_compatible(pdev->dev.of_node, "fsl,imx27-sahara")) {
@@ -1619,10 +1623,11 @@ err_algs:
dma_free_coherent(&pdev->dev,
  SAHARA_MAX_HW_LINK * sizeof(struct sahara_hw_link),
  dev->hw_link[0], dev->hw_phys_link[0]);
-   clk_disable_unprepare(dev->clk_ipg);
-   clk_disable_unprepare(dev->clk_ahb);
kthread_stop(dev->kthread);
dev_ptr = NULL;
+   clk_disable_unprepare(dev->clk_ahb);
+clk_ipg_disable:
+   clk_disable_unprepare(dev->clk_ipg);
 err_link:
dma_free_coherent(&pdev->dev,
  2 * AES_KEYSIZE_128,
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in


[PATCH] crypto: caam - Fix error handling in caam_rng_init()

2015-08-12 Thread Fabio Estevam
From: Fabio Estevam 

In the error paths we should free the resources that were 
previously acquired, so fix it accordingly.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/caam/caamrng.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index 345024c..fb0cc54 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -352,14 +352,22 @@ static int __init caam_rng_init(void)
return PTR_ERR(dev);
}
rng_ctx = kmalloc(sizeof(struct caam_rng_ctx), GFP_DMA);
-   if (!rng_ctx)
-   return -ENOMEM;
+   if (!rng_ctx) {
+   err = -ENOMEM;
+   goto free_caam_alloc;
+   }
err = caam_init_rng(rng_ctx, dev);
if (err)
-   return err;
+   goto free_rng_ctx;
 
dev_info(dev, "registering rng-caam\n");
return hwrng_register(&caam_rng);
+
+free_rng_ctx:
+   kfree(rng_ctx);
+free_caam_alloc:
+   caam_jr_free(dev);
+   return err;
 }
 
 module_init(caam_rng_init);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: caam - Remove unneeded 'ret' variable

2015-08-12 Thread Fabio Estevam
From: Fabio Estevam 

Variable 'ret' is only used for returning the value 0.

We can make it simpler and just return 0 instead.

The semantic patch that makes this change is available
in scripts/coccinelle/misc/returnvar.cocci.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/caam/ctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 37c2d8d..4f174ee 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -298,7 +298,7 @@ static int caam_remove(struct platform_device *pdev)
struct device *ctrldev;
struct caam_drv_private *ctrlpriv;
struct caam_ctrl __iomem *ctrl;
-   int ring, ret = 0;
+   int ring;
 
ctrldev = &pdev->dev;
ctrlpriv = dev_get_drvdata(ctrldev);
@@ -328,7 +328,7 @@ static int caam_remove(struct platform_device *pdev)
clk_disable_unprepare(ctrlpriv->caam_aclk);
clk_disable_unprepare(ctrlpriv->caam_emi_slow);
 
-   return ret;
+   return 0;
 }
 
 /*
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: amcc: Do a NULL check for pointer

2015-08-13 Thread Fabio Estevam
From: Fabio Estevam 

Compare pointer-typed values to NULL rather than 0.

The semantic patch that makes this change is available
in scripts/coccinelle/null/badzero.cocci

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/amcc/crypto4xx_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/amcc/crypto4xx_core.c 
b/drivers/crypto/amcc/crypto4xx_core.c
index 3b28e8c..47c4b08 100644
--- a/drivers/crypto/amcc/crypto4xx_core.c
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -1113,7 +1113,7 @@ static irqreturn_t crypto4xx_ce_interrupt_handler(int 
irq, void *data)
struct device *dev = (struct device *)data;
struct crypto4xx_core_device *core_dev = dev_get_drvdata(dev);
 
-   if (core_dev->dev->ce_base == 0)
+   if (core_dev->dev->ce_base == NULL)
return 0;
 
writel(PPC4XX_INTERRUPT_CLR,
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] crypto: amcc: Do a NULL check for pointer

2015-08-13 Thread Fabio Estevam
From: Fabio Estevam 

Compare pointer-typed values to NULL rather than 0.

The semantic patch that makes this change is available
in scripts/coccinelle/null/badzero.cocci

Signed-off-by: Fabio Estevam 
---
Changes since v1:
- Use !core_dev->dev->ce_base
 drivers/crypto/amcc/crypto4xx_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/amcc/crypto4xx_core.c 
b/drivers/crypto/amcc/crypto4xx_core.c
index 3b28e8c..47c4b08 100644
--- a/drivers/crypto/amcc/crypto4xx_core.c
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -1113,7 +1113,7 @@ static irqreturn_t crypto4xx_ce_interrupt_handler(int 
irq, void *data)
struct device *dev = (struct device *)data;
struct crypto4xx_core_device *core_dev = dev_get_drvdata(dev);
 
-   if (core_dev->dev->ce_base == 0)
+   if (!core_dev->dev->ce_base)
return 0;
 
writel(PPC4XX_INTERRUPT_CLR,
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/4] crypto: caam: ctrl: Fix the error handling

2015-08-21 Thread Fabio Estevam
From: Fabio Estevam 

In the error path we should disable the resources that were previously
acquired, so fix the error handling accordingly.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/caam/ctrl.c | 35 ---
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 81b552d..9c5ca46 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -474,27 +474,27 @@ static int caam_probe(struct platform_device *pdev)
ret = clk_prepare_enable(ctrlpriv->caam_ipg);
if (ret < 0) {
dev_err(&pdev->dev, "can't enable CAAM ipg clock: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
 
ret = clk_prepare_enable(ctrlpriv->caam_mem);
if (ret < 0) {
dev_err(&pdev->dev, "can't enable CAAM secure mem clock: %d\n",
ret);
-   return -ENODEV;
+   goto disable_caam_ipg;
}
 
ret = clk_prepare_enable(ctrlpriv->caam_aclk);
if (ret < 0) {
dev_err(&pdev->dev, "can't enable CAAM aclk clock: %d\n", ret);
-   return -ENODEV;
+   goto disable_caam_mem;
}
 
ret = clk_prepare_enable(ctrlpriv->caam_emi_slow);
if (ret < 0) {
dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n",
ret);
-   return -ENODEV;
+   goto disable_caam_aclk;
}
 
/* Get configuration properties from device tree */
@@ -502,7 +502,7 @@ static int caam_probe(struct platform_device *pdev)
ctrl = of_iomap(nprop, 0);
if (ctrl == NULL) {
dev_err(dev, "caam: of_iomap() failed\n");
-   return -ENOMEM;
+   goto disable_caam_emi_slow;
}
/* Finding the page size for using the CTPR_MS register */
comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ms);
@@ -586,8 +586,8 @@ static int caam_probe(struct platform_device *pdev)
sizeof(struct platform_device *) * 
rspec,
GFP_KERNEL);
if (ctrlpriv->jrpdev == NULL) {
-   iounmap(ctrl);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto iounmap_ctrl;
}
 
ring = 0;
@@ -627,8 +627,8 @@ static int caam_probe(struct platform_device *pdev)
/* If no QI and no rings specified, quit and go home */
if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
dev_err(dev, "no queues configured, terminating\n");
-   caam_remove(pdev);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto caam_remove;
}
 
cha_vid_ls = rd_reg32(&ctrl->perfmon.cha_id_ls);
@@ -685,8 +685,7 @@ static int caam_probe(struct platform_device *pdev)
} while ((ret == -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX));
if (ret) {
dev_err(dev, "failed to instantiate RNG");
-   caam_remove(pdev);
-   return ret;
+   goto caam_remove;
}
/*
 * Set handles init'ed by this module as the complement of the
@@ -790,6 +789,20 @@ static int caam_probe(struct platform_device *pdev)
 &ctrlpriv->ctl_tdsk_wrap);
 #endif
return 0;
+
+caam_remove:
+   caam_remove(pdev);
+iounmap_ctrl:
+   iounmap(ctrl);
+disable_caam_emi_slow:
+   clk_disable_unprepare(ctrlpriv->caam_emi_slow);
+disable_caam_aclk:
+   clk_disable_unprepare(ctrlpriv->caam_aclk);
+disable_caam_mem:
+   clk_disable_unprepare(ctrlpriv->caam_mem);
+disable_caam_ipg:
+   clk_disable_unprepare(ctrlpriv->caam_ipg);
+   return ret;
 }
 
 static struct of_device_id caam_match[] = {
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/4] crypto: caam: ctrl: Propagate the real error code

2015-08-21 Thread Fabio Estevam
From: Fabio Estevam 

Instead of propagating a 'fake' error code, just propagate the real
one in the case of caam_drv_identify_clk() failure.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/caam/ctrl.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 9c5ca46..1153417 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -440,7 +440,7 @@ static int caam_probe(struct platform_device *pdev)
ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"can't identify CAAM ipg clk: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
ctrlpriv->caam_ipg = clk;
 
@@ -449,7 +449,7 @@ static int caam_probe(struct platform_device *pdev)
ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"can't identify CAAM mem clk: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
ctrlpriv->caam_mem = clk;
 
@@ -458,7 +458,7 @@ static int caam_probe(struct platform_device *pdev)
ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"can't identify CAAM aclk clk: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
ctrlpriv->caam_aclk = clk;
 
@@ -467,7 +467,7 @@ static int caam_probe(struct platform_device *pdev)
ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"can't identify CAAM emi_slow clk: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
ctrlpriv->caam_emi_slow = clk;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/4] crypto: caam: ctrl: Use the preferred method for devm_kzalloc()

2015-08-21 Thread Fabio Estevam
From: Fabio Estevam 

>From Documentation/CodingStyle:

"The preferred form for passing a size of a struct is the following:

p = kmalloc(sizeof(*p), ...);"

, so do as suggested.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/caam/ctrl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 1153417..aab8b2a 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -424,8 +424,7 @@ static int caam_probe(struct platform_device *pdev)
int pg_size;
int BLOCK_OFFSET = 0;
 
-   ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(struct caam_drv_private),
-   GFP_KERNEL);
+   ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL);
if (!ctrlpriv)
return -ENOMEM;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/4] crypto: caam: ctrl: Use devm_kcalloc()

2015-08-21 Thread Fabio Estevam
From: Fabio Estevam 

>From Documentation/CodingStyle:

"The preferred form for allocating a zeroed array is the following:

p = kcalloc(n, sizeof(...), ...); "

, so do as suggested.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/caam/ctrl.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index aab8b2a..c9c5892 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -581,9 +581,8 @@ static int caam_probe(struct platform_device *pdev)
of_device_is_compatible(np, "fsl,sec4.0-job-ring"))
rspec++;
 
-   ctrlpriv->jrpdev = devm_kzalloc(&pdev->dev,
-   sizeof(struct platform_device *) * 
rspec,
-   GFP_KERNEL);
+   ctrlpriv->jrpdev = devm_kcalloc(&pdev->dev, rspec,
+   sizeof(*ctrlpriv->jrpdev), GFP_KERNEL);
if (ctrlpriv->jrpdev == NULL) {
ret = -ENOMEM;
goto iounmap_ctrl;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/3] crypto: caam: ctrl: Propagate the real error code

2015-08-21 Thread Fabio Estevam
From: Fabio Estevam 

Instead of propagating a 'fake' error code, just propagate the real
one in the case of caam_drv_identify_clk() failure.

Signed-off-by: Fabio Estevam 
---
Changes since v1:
- None

 drivers/crypto/caam/ctrl.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 9c5ca46..1153417 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -440,7 +440,7 @@ static int caam_probe(struct platform_device *pdev)
ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"can't identify CAAM ipg clk: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
ctrlpriv->caam_ipg = clk;
 
@@ -449,7 +449,7 @@ static int caam_probe(struct platform_device *pdev)
ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"can't identify CAAM mem clk: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
ctrlpriv->caam_mem = clk;
 
@@ -458,7 +458,7 @@ static int caam_probe(struct platform_device *pdev)
ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"can't identify CAAM aclk clk: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
ctrlpriv->caam_aclk = clk;
 
@@ -467,7 +467,7 @@ static int caam_probe(struct platform_device *pdev)
ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"can't identify CAAM emi_slow clk: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
ctrlpriv->caam_emi_slow = clk;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/3] crypto: caam: ctrl: Fix the error handling

2015-08-21 Thread Fabio Estevam
From: Fabio Estevam 

In the error path we should disable the resources that were previously
acquired, so fix the error handling accordingly.

Signed-off-by: Fabio Estevam 
---
Changes since v1:
- None

 drivers/crypto/caam/ctrl.c | 35 ---
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 81b552d..9c5ca46 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -474,27 +474,27 @@ static int caam_probe(struct platform_device *pdev)
ret = clk_prepare_enable(ctrlpriv->caam_ipg);
if (ret < 0) {
dev_err(&pdev->dev, "can't enable CAAM ipg clock: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
 
ret = clk_prepare_enable(ctrlpriv->caam_mem);
if (ret < 0) {
dev_err(&pdev->dev, "can't enable CAAM secure mem clock: %d\n",
ret);
-   return -ENODEV;
+   goto disable_caam_ipg;
}
 
ret = clk_prepare_enable(ctrlpriv->caam_aclk);
if (ret < 0) {
dev_err(&pdev->dev, "can't enable CAAM aclk clock: %d\n", ret);
-   return -ENODEV;
+   goto disable_caam_mem;
}
 
ret = clk_prepare_enable(ctrlpriv->caam_emi_slow);
if (ret < 0) {
dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n",
ret);
-   return -ENODEV;
+   goto disable_caam_aclk;
}
 
/* Get configuration properties from device tree */
@@ -502,7 +502,7 @@ static int caam_probe(struct platform_device *pdev)
ctrl = of_iomap(nprop, 0);
if (ctrl == NULL) {
dev_err(dev, "caam: of_iomap() failed\n");
-   return -ENOMEM;
+   goto disable_caam_emi_slow;
}
/* Finding the page size for using the CTPR_MS register */
comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ms);
@@ -586,8 +586,8 @@ static int caam_probe(struct platform_device *pdev)
sizeof(struct platform_device *) * 
rspec,
GFP_KERNEL);
if (ctrlpriv->jrpdev == NULL) {
-   iounmap(ctrl);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto iounmap_ctrl;
}
 
ring = 0;
@@ -627,8 +627,8 @@ static int caam_probe(struct platform_device *pdev)
/* If no QI and no rings specified, quit and go home */
if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
dev_err(dev, "no queues configured, terminating\n");
-   caam_remove(pdev);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto caam_remove;
}
 
cha_vid_ls = rd_reg32(&ctrl->perfmon.cha_id_ls);
@@ -685,8 +685,7 @@ static int caam_probe(struct platform_device *pdev)
} while ((ret == -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX));
if (ret) {
dev_err(dev, "failed to instantiate RNG");
-   caam_remove(pdev);
-   return ret;
+   goto caam_remove;
}
/*
 * Set handles init'ed by this module as the complement of the
@@ -790,6 +789,20 @@ static int caam_probe(struct platform_device *pdev)
 &ctrlpriv->ctl_tdsk_wrap);
 #endif
return 0;
+
+caam_remove:
+   caam_remove(pdev);
+iounmap_ctrl:
+   iounmap(ctrl);
+disable_caam_emi_slow:
+   clk_disable_unprepare(ctrlpriv->caam_emi_slow);
+disable_caam_aclk:
+   clk_disable_unprepare(ctrlpriv->caam_aclk);
+disable_caam_mem:
+   clk_disable_unprepare(ctrlpriv->caam_mem);
+disable_caam_ipg:
+   clk_disable_unprepare(ctrlpriv->caam_ipg);
+   return ret;
 }
 
 static struct of_device_id caam_match[] = {
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/3] crypto: caam: Use the preferred style for memory allocations

2015-08-21 Thread Fabio Estevam
From: Fabio Estevam 

>From Documentation/CodingStyle:

"The preferred form for passing a size of a struct is the following:

p = kmalloc(sizeof(*p), ...);


The preferred form for allocating a zeroed array is the following:

p = kcalloc(n, sizeof(...), ...); "

,so do as suggested.

Signed-off-by: Fabio Estevam 
---
Changes since v1:
- Consolidate patches 3 and 4 into a single one (Horia Geantă)
- Fix all the occurrences inside drivers/crypto/caam (Horia Geantă)

 drivers/crypto/caam/caamalg.c  |  2 +-
 drivers/crypto/caam/caamhash.c |  2 +-
 drivers/crypto/caam/caamrng.c  |  2 +-
 drivers/crypto/caam/ctrl.c |  8 +++-
 drivers/crypto/caam/jr.c   | 12 +---
 5 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index 83d2306..ba79d63 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -4314,7 +4314,7 @@ static struct caam_crypto_alg *caam_alg_alloc(struct 
caam_alg_template
struct caam_crypto_alg *t_alg;
struct crypto_alg *alg;
 
-   t_alg = kzalloc(sizeof(struct caam_crypto_alg), GFP_KERNEL);
+   t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
if (!t_alg) {
pr_err("failed to allocate t_alg\n");
return ERR_PTR(-ENOMEM);
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 6c14261..94433b9 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -1842,7 +1842,7 @@ caam_hash_alloc(struct caam_hash_template *template,
struct ahash_alg *halg;
struct crypto_alg *alg;
 
-   t_alg = kzalloc(sizeof(struct caam_hash_alg), GFP_KERNEL);
+   t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
if (!t_alg) {
pr_err("failed to allocate t_alg\n");
return ERR_PTR(-ENOMEM);
diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index fb0cc54..9b92af2 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -351,7 +351,7 @@ static int __init caam_rng_init(void)
pr_err("Job Ring Device allocation for transform failed\n");
return PTR_ERR(dev);
}
-   rng_ctx = kmalloc(sizeof(struct caam_rng_ctx), GFP_DMA);
+   rng_ctx = kmalloc(sizeof(*rng_ctx), GFP_DMA);
if (!rng_ctx) {
err = -ENOMEM;
goto free_caam_alloc;
diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 1153417..c9c5892 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -424,8 +424,7 @@ static int caam_probe(struct platform_device *pdev)
int pg_size;
int BLOCK_OFFSET = 0;
 
-   ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(struct caam_drv_private),
-   GFP_KERNEL);
+   ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL);
if (!ctrlpriv)
return -ENOMEM;
 
@@ -582,9 +581,8 @@ static int caam_probe(struct platform_device *pdev)
of_device_is_compatible(np, "fsl,sec4.0-job-ring"))
rspec++;
 
-   ctrlpriv->jrpdev = devm_kzalloc(&pdev->dev,
-   sizeof(struct platform_device *) * 
rspec,
-   GFP_KERNEL);
+   ctrlpriv->jrpdev = devm_kcalloc(&pdev->dev, rspec,
+   sizeof(*ctrlpriv->jrpdev), GFP_KERNEL);
if (ctrlpriv->jrpdev == NULL) {
ret = -ENOMEM;
goto iounmap_ctrl;
diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index b7ec1ad..f7e0d8d 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -410,18 +410,17 @@ static int caam_jr_init(struct device *dev)
goto out_free_irq;
 
error = -ENOMEM;
-   jrp->inpring = dma_alloc_coherent(dev, sizeof(dma_addr_t) * JOBR_DEPTH,
- &inpbusaddr, GFP_KERNEL);
+   jrp->inpring = dma_alloc_coherent(dev, sizeof(*jrp->inpring) *
+ JOBR_DEPTH, &inpbusaddr, GFP_KERNEL);
if (!jrp->inpring)
goto out_free_irq;
 
-   jrp->outring = dma_alloc_coherent(dev, sizeof(struct jr_outentry) *
+   jrp->outring = dma_alloc_coherent(dev, sizeof(*jrp->outring) *
  JOBR_DEPTH, &outbusaddr, GFP_KERNEL);
if (!jrp->outring)
goto out_free_inpring;
 
-   jrp->entinfo = kzalloc(sizeof(struct caam_jrentry_info) * JOBR_DEPTH,
-  GFP_KERNEL);
+   jrp->entinfo = kcalloc(JOBR_DEPTH, sizeof(*jrp->entinfo), GFP_KERNEL);
if (!jrp->entinfo)
goto out_free_outring;
 
@@ -479,8 +4

Re: [PATCH v2 1/3] crypto: caam: ctrl: Fix the error handling

2015-08-21 Thread Fabio Estevam
On Fri, Aug 21, 2015 at 1:16 PM, Fabio Estevam  wrote:
> From: Fabio Estevam 
>
> In the error path we should disable the resources that were previously
> acquired, so fix the error handling accordingly.
>
> Signed-off-by: Fabio Estevam 
> ---
> Changes since v1:
> - None
>
>  drivers/crypto/caam/ctrl.c | 35 ---
>  1 file changed, 24 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
> index 81b552d..9c5ca46 100644
> --- a/drivers/crypto/caam/ctrl.c
> +++ b/drivers/crypto/caam/ctrl.c
> @@ -474,27 +474,27 @@ static int caam_probe(struct platform_device *pdev)
> ret = clk_prepare_enable(ctrlpriv->caam_ipg);
> if (ret < 0) {
> dev_err(&pdev->dev, "can't enable CAAM ipg clock: %d\n", ret);
> -   return -ENODEV;
> +   return ret;
> }
>
> ret = clk_prepare_enable(ctrlpriv->caam_mem);
> if (ret < 0) {
> dev_err(&pdev->dev, "can't enable CAAM secure mem clock: 
> %d\n",
> ret);
> -   return -ENODEV;
> +   goto disable_caam_ipg;
> }
>
> ret = clk_prepare_enable(ctrlpriv->caam_aclk);
> if (ret < 0) {
> dev_err(&pdev->dev, "can't enable CAAM aclk clock: %d\n", 
> ret);
> -   return -ENODEV;
> +   goto disable_caam_mem;
> }
>
> ret = clk_prepare_enable(ctrlpriv->caam_emi_slow);
> if (ret < 0) {
> dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n",
> ret);
> -   return -ENODEV;
> +   goto disable_caam_aclk;
> }
>
> /* Get configuration properties from device tree */
> @@ -502,7 +502,7 @@ static int caam_probe(struct platform_device *pdev)
> ctrl = of_iomap(nprop, 0);
> if (ctrl == NULL) {
> dev_err(dev, "caam: of_iomap() failed\n");
> -   return -ENOMEM;
> +   goto disable_caam_emi_slow;

Ops, I missed a 'ret = -ENOMEM' here.

Will send a v3.
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 1/3] crypto: caam: ctrl: Fix the error handling

2015-08-21 Thread Fabio Estevam
From: Fabio Estevam 

In the error path we should disable the resources that were previously
acquired, so fix the error handling accordingly.

Signed-off-by: Fabio Estevam 
---
Changes since v2:
- Add a missing "ret = -ENOMEM"

 drivers/crypto/caam/ctrl.c | 36 +---
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 81b552d..cd22849 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -474,27 +474,27 @@ static int caam_probe(struct platform_device *pdev)
ret = clk_prepare_enable(ctrlpriv->caam_ipg);
if (ret < 0) {
dev_err(&pdev->dev, "can't enable CAAM ipg clock: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
 
ret = clk_prepare_enable(ctrlpriv->caam_mem);
if (ret < 0) {
dev_err(&pdev->dev, "can't enable CAAM secure mem clock: %d\n",
ret);
-   return -ENODEV;
+   goto disable_caam_ipg;
}
 
ret = clk_prepare_enable(ctrlpriv->caam_aclk);
if (ret < 0) {
dev_err(&pdev->dev, "can't enable CAAM aclk clock: %d\n", ret);
-   return -ENODEV;
+   goto disable_caam_mem;
}
 
ret = clk_prepare_enable(ctrlpriv->caam_emi_slow);
if (ret < 0) {
dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n",
ret);
-   return -ENODEV;
+   goto disable_caam_aclk;
}
 
/* Get configuration properties from device tree */
@@ -502,7 +502,8 @@ static int caam_probe(struct platform_device *pdev)
ctrl = of_iomap(nprop, 0);
if (ctrl == NULL) {
dev_err(dev, "caam: of_iomap() failed\n");
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto disable_caam_emi_slow;
}
/* Finding the page size for using the CTPR_MS register */
comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ms);
@@ -586,8 +587,8 @@ static int caam_probe(struct platform_device *pdev)
sizeof(struct platform_device *) * 
rspec,
GFP_KERNEL);
if (ctrlpriv->jrpdev == NULL) {
-   iounmap(ctrl);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto iounmap_ctrl;
}
 
ring = 0;
@@ -627,8 +628,8 @@ static int caam_probe(struct platform_device *pdev)
/* If no QI and no rings specified, quit and go home */
if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
dev_err(dev, "no queues configured, terminating\n");
-   caam_remove(pdev);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto caam_remove;
}
 
cha_vid_ls = rd_reg32(&ctrl->perfmon.cha_id_ls);
@@ -685,8 +686,7 @@ static int caam_probe(struct platform_device *pdev)
} while ((ret == -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX));
if (ret) {
dev_err(dev, "failed to instantiate RNG");
-   caam_remove(pdev);
-   return ret;
+   goto caam_remove;
}
/*
 * Set handles init'ed by this module as the complement of the
@@ -790,6 +790,20 @@ static int caam_probe(struct platform_device *pdev)
 &ctrlpriv->ctl_tdsk_wrap);
 #endif
return 0;
+
+caam_remove:
+   caam_remove(pdev);
+iounmap_ctrl:
+   iounmap(ctrl);
+disable_caam_emi_slow:
+   clk_disable_unprepare(ctrlpriv->caam_emi_slow);
+disable_caam_aclk:
+   clk_disable_unprepare(ctrlpriv->caam_aclk);
+disable_caam_mem:
+   clk_disable_unprepare(ctrlpriv->caam_mem);
+disable_caam_ipg:
+   clk_disable_unprepare(ctrlpriv->caam_ipg);
+   return ret;
 }
 
 static struct of_device_id caam_match[] = {
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 3/3] crypto: caam: Use the preferred style for memory allocations

2015-08-21 Thread Fabio Estevam
From: Fabio Estevam 

>From Documentation/CodingStyle:

"The preferred form for passing a size of a struct is the following:

p = kmalloc(sizeof(*p), ...);


The preferred form for allocating a zeroed array is the following:

p = kcalloc(n, sizeof(...), ...); "

,so do as suggested.

Signed-off-by: Fabio Estevam 
Reviewed-by: Horia Geantă 
---
Changes since v2:
- None

 drivers/crypto/caam/caamalg.c  |  2 +-
 drivers/crypto/caam/caamhash.c |  2 +-
 drivers/crypto/caam/caamrng.c  |  2 +-
 drivers/crypto/caam/ctrl.c |  8 +++-
 drivers/crypto/caam/jr.c   | 12 +---
 5 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index 83d2306..ba79d63 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -4314,7 +4314,7 @@ static struct caam_crypto_alg *caam_alg_alloc(struct 
caam_alg_template
struct caam_crypto_alg *t_alg;
struct crypto_alg *alg;
 
-   t_alg = kzalloc(sizeof(struct caam_crypto_alg), GFP_KERNEL);
+   t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
if (!t_alg) {
pr_err("failed to allocate t_alg\n");
return ERR_PTR(-ENOMEM);
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 6c14261..94433b9 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -1842,7 +1842,7 @@ caam_hash_alloc(struct caam_hash_template *template,
struct ahash_alg *halg;
struct crypto_alg *alg;
 
-   t_alg = kzalloc(sizeof(struct caam_hash_alg), GFP_KERNEL);
+   t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
if (!t_alg) {
pr_err("failed to allocate t_alg\n");
return ERR_PTR(-ENOMEM);
diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index fb0cc54..9b92af2 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -351,7 +351,7 @@ static int __init caam_rng_init(void)
pr_err("Job Ring Device allocation for transform failed\n");
return PTR_ERR(dev);
}
-   rng_ctx = kmalloc(sizeof(struct caam_rng_ctx), GFP_DMA);
+   rng_ctx = kmalloc(sizeof(*rng_ctx), GFP_DMA);
if (!rng_ctx) {
err = -ENOMEM;
goto free_caam_alloc;
diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index b4124a6..918c00a 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -424,8 +424,7 @@ static int caam_probe(struct platform_device *pdev)
int pg_size;
int BLOCK_OFFSET = 0;
 
-   ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(struct caam_drv_private),
-   GFP_KERNEL);
+   ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL);
if (!ctrlpriv)
return -ENOMEM;
 
@@ -583,9 +582,8 @@ static int caam_probe(struct platform_device *pdev)
of_device_is_compatible(np, "fsl,sec4.0-job-ring"))
rspec++;
 
-   ctrlpriv->jrpdev = devm_kzalloc(&pdev->dev,
-   sizeof(struct platform_device *) * 
rspec,
-   GFP_KERNEL);
+   ctrlpriv->jrpdev = devm_kcalloc(&pdev->dev, rspec,
+   sizeof(*ctrlpriv->jrpdev), GFP_KERNEL);
if (ctrlpriv->jrpdev == NULL) {
ret = -ENOMEM;
goto iounmap_ctrl;
diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index b7ec1ad..f7e0d8d 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -410,18 +410,17 @@ static int caam_jr_init(struct device *dev)
goto out_free_irq;
 
error = -ENOMEM;
-   jrp->inpring = dma_alloc_coherent(dev, sizeof(dma_addr_t) * JOBR_DEPTH,
- &inpbusaddr, GFP_KERNEL);
+   jrp->inpring = dma_alloc_coherent(dev, sizeof(*jrp->inpring) *
+ JOBR_DEPTH, &inpbusaddr, GFP_KERNEL);
if (!jrp->inpring)
goto out_free_irq;
 
-   jrp->outring = dma_alloc_coherent(dev, sizeof(struct jr_outentry) *
+   jrp->outring = dma_alloc_coherent(dev, sizeof(*jrp->outring) *
  JOBR_DEPTH, &outbusaddr, GFP_KERNEL);
if (!jrp->outring)
goto out_free_inpring;
 
-   jrp->entinfo = kzalloc(sizeof(struct caam_jrentry_info) * JOBR_DEPTH,
-  GFP_KERNEL);
+   jrp->entinfo = kcalloc(JOBR_DEPTH, sizeof(*jrp->entinfo), GFP_KERNEL);
if (!jrp->entinfo)
goto out_free_outring;
 
@@ -479,8 +478,7 @@ static int caam_jr_probe(struct platform_device *pdev)
int error;
 
jrdev = &

[PATCH v3 2/3] crypto: caam: ctrl: Propagate the real error code

2015-08-21 Thread Fabio Estevam
From: Fabio Estevam 

Instead of propagating a 'fake' error code, just propagate the real
one in the case of caam_drv_identify_clk() failure.

Signed-off-by: Fabio Estevam 
Reviewed-by: Horia Geantă 
---
Changes since v2:
- None

 drivers/crypto/caam/ctrl.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index cd22849..b4124a6 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -440,7 +440,7 @@ static int caam_probe(struct platform_device *pdev)
ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"can't identify CAAM ipg clk: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
ctrlpriv->caam_ipg = clk;
 
@@ -449,7 +449,7 @@ static int caam_probe(struct platform_device *pdev)
ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"can't identify CAAM mem clk: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
ctrlpriv->caam_mem = clk;
 
@@ -458,7 +458,7 @@ static int caam_probe(struct platform_device *pdev)
ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"can't identify CAAM aclk clk: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
ctrlpriv->caam_aclk = clk;
 
@@ -467,7 +467,7 @@ static int caam_probe(struct platform_device *pdev)
ret = PTR_ERR(clk);
dev_err(&pdev->dev,
"can't identify CAAM emi_slow clk: %d\n", ret);
-   return -ENODEV;
+   return ret;
}
ctrlpriv->caam_emi_slow = clk;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: Kconfig: Allow MXS_DCP to be used on MX6SL

2015-09-02 Thread Fabio Estevam
From: Fabio Estevam 

MX6SL has the same DCP crypto block as in MX23/MX28, so allow it to be
built for ARCH_MXC.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 07bc7aa..99b4795 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -429,7 +429,7 @@ endif
 
 config CRYPTO_DEV_MXS_DCP
tristate "Support for Freescale MXS DCP"
-   depends on ARCH_MXS
+   depends on (ARCH_MXS || ARCH_MXC)
select CRYPTO_CBC
select CRYPTO_ECB
select CRYPTO_AES
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] caam: desc: Remove unused JUMP_TYPE_MASK definition

2015-09-03 Thread Fabio Estevam
From: Fabio Estevam 

JUMP_TYPE_MASK is defined in desc.h and it is never used, so we can
safely remove it to avoid the following build warning:

In file included from drivers/crypto/caam/desc_constr.h:7:0,
 from drivers/crypto/caam/ctrl.c:15:
drivers/crypto/caam/desc.h:1495:0: warning: "JUMP_TYPE_MASK" redefined
 #define JUMP_TYPE_MASK  (0x03 << JUMP_TYPE_SHIFT)
 ^
In file included from include/linux/module.h:19:0,
 from drivers/crypto/caam/compat.h:9,
 from drivers/crypto/caam/ctrl.c:11:
include/linux/jump_label.h:131:0: note: this is the location of the previous 
definition
 #define JUMP_TYPE_MASK 1UL

Reported-by: Olof's autobuilder 
Signed-off-by: Fabio Estevam 
---
 drivers/crypto/caam/desc.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/crypto/caam/desc.h b/drivers/crypto/caam/desc.h
index 983d663..1e93c6a 100644
--- a/drivers/crypto/caam/desc.h
+++ b/drivers/crypto/caam/desc.h
@@ -1492,7 +1492,6 @@ struct sec4_sg_entry {
 #define JUMP_JSL   (1 << JUMP_JSL_SHIFT)
 
 #define JUMP_TYPE_SHIFT22
-#define JUMP_TYPE_MASK (0x03 << JUMP_TYPE_SHIFT)
 #define JUMP_TYPE_LOCAL(0x00 << JUMP_TYPE_SHIFT)
 #define JUMP_TYPE_NONLOCAL (0x01 << JUMP_TYPE_SHIFT)
 #define JUMP_TYPE_HALT (0x02 << JUMP_TYPE_SHIFT)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/6] hwrng: st: Add support for ST's HW Random Number Generator

2015-09-12 Thread Fabio Estevam
On Fri, Sep 11, 2015 at 5:08 PM, Lee Jones  wrote:

> +   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +   base = devm_ioremap_resource(&pdev->dev, res);
> +   if (IS_ERR(base))
> +   return PTR_ERR(base);
> +
> +   clk = devm_clk_get(&pdev->dev, NULL);
> +   if (!clk)
> +   return -EINVAL;

This should be:

if (IS_ERR(clk))
return PTR_ERR(clk);

> +
> +   clk_prepare_enable(clk);

This may fail, so better check its return value and propagate it on error.

> +
> +   ddata->ops.priv = (unsigned long)ddata;
> +   ddata->ops.read = st_rng_read;
> +   ddata->ops.name = pdev->name;
> +   ddata->base = base;
> +   ddata->clk  = clk;
> +
> +   dev_set_drvdata(&pdev->dev, ddata);
> +
> +   ret = hwrng_register(&ddata->ops);
> +   if (ret) {
> +   dev_err(&pdev->dev, "Failed to register HW RNG\n");
> +   return ret;
> +   }
> +
> +   dev_info(&pdev->dev, "Successfully registered HW RNG\n");

No need to put this info.
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/4] hwrng: mxc-rnga - Remove unneeded goto label

2015-09-12 Thread Fabio Estevam
From: Fabio Estevam 

We can simplify the code by returning the error code immediately
instead of jumping to a goto label.

Signed-off-by: Fabio Estevam 
---
 drivers/char/hw_random/mxc-rnga.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/char/hw_random/mxc-rnga.c 
b/drivers/char/hw_random/mxc-rnga.c
index 6cbb72e..8803126 100644
--- a/drivers/char/hw_random/mxc-rnga.c
+++ b/drivers/char/hw_random/mxc-rnga.c
@@ -160,13 +160,12 @@ static int __init mxc_rnga_probe(struct platform_device 
*pdev)
mxc_rng->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(mxc_rng->clk)) {
dev_err(&pdev->dev, "Could not get rng_clk!\n");
-   err = PTR_ERR(mxc_rng->clk);
-   goto out;
+   return PTR_ERR(mxc_rng->clk);
}
 
err = clk_prepare_enable(mxc_rng->clk);
if (err)
-   goto out;
+   return err;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
mxc_rng->mem = devm_ioremap_resource(&pdev->dev, res);
@@ -187,8 +186,6 @@ static int __init mxc_rnga_probe(struct platform_device 
*pdev)
 
 err_ioremap:
clk_disable_unprepare(mxc_rng->clk);
-
-out:
return err;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/4] hwrng: mxc-rnga - Remove unnecessary dev_info message

2015-09-12 Thread Fabio Estevam
From: Fabio Estevam 

There is no need to print a message simply saying that a kernel
driver has been registered, so remove it.

Signed-off-by: Fabio Estevam 
---
 drivers/char/hw_random/mxc-rnga.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/char/hw_random/mxc-rnga.c 
b/drivers/char/hw_random/mxc-rnga.c
index c7380b8..ed2e3ef 100644
--- a/drivers/char/hw_random/mxc-rnga.c
+++ b/drivers/char/hw_random/mxc-rnga.c
@@ -180,8 +180,6 @@ static int __init mxc_rnga_probe(struct platform_device 
*pdev)
goto err_ioremap;
}
 
-   dev_info(&pdev->dev, "MXC RNGA Registered.\n");
-
return 0;
 
 err_ioremap:
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/4] hwrng: mxc-rnga - Remove uneeded initialization

2015-09-12 Thread Fabio Estevam
From: Fabio Estevam 

There is no need to pre-initialize variable 'err' as this
initial value will be overwritten later on.

Signed-off-by: Fabio Estevam 
---
 drivers/char/hw_random/mxc-rnga.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/hw_random/mxc-rnga.c 
b/drivers/char/hw_random/mxc-rnga.c
index 8803126..c7380b8 100644
--- a/drivers/char/hw_random/mxc-rnga.c
+++ b/drivers/char/hw_random/mxc-rnga.c
@@ -141,7 +141,7 @@ static void mxc_rnga_cleanup(struct hwrng *rng)
 
 static int __init mxc_rnga_probe(struct platform_device *pdev)
 {
-   int err = -ENODEV;
+   int err;
struct resource *res;
struct mxc_rng *mxc_rng;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/4] hwrng: mxc-rnga - Use the preferred format for kzalloc

2015-09-12 Thread Fabio Estevam
From: Fabio Estevam 

According to Documentation/CodingStyle:

"The preferred form for passing a size of a struct is the following:

p = kmalloc(sizeof(*p), ...);"

,so do as suggested.

Signed-off-by: Fabio Estevam 
---
 drivers/char/hw_random/mxc-rnga.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/char/hw_random/mxc-rnga.c 
b/drivers/char/hw_random/mxc-rnga.c
index ed2e3ef..4673622 100644
--- a/drivers/char/hw_random/mxc-rnga.c
+++ b/drivers/char/hw_random/mxc-rnga.c
@@ -145,8 +145,7 @@ static int __init mxc_rnga_probe(struct platform_device 
*pdev)
struct resource *res;
struct mxc_rng *mxc_rng;
 
-   mxc_rng = devm_kzalloc(&pdev->dev, sizeof(struct mxc_rng),
-   GFP_KERNEL);
+   mxc_rng = devm_kzalloc(&pdev->dev, sizeof(*mxc_rng), GFP_KERNEL);
if (!mxc_rng)
return -ENOMEM;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] caam: desc: Remove unused JUMP_TYPE_MASK definition

2015-09-15 Thread Fabio Estevam
Commit a1efb01feca597b ("jump_label, locking/static_keys: Rename 
JUMP_LABEL_TYPE_* and related helpers to the static_key* pattern")
introduced the definition of JUMP_TYPE_MASK in 
include/linux/jump_label.h causing the following name collision:

In file included from drivers/crypto/caam/desc_constr.h:7:0,
 from drivers/crypto/caam/ctrl.c:15:
drivers/crypto/caam/desc.h:1495:0: warning: "JUMP_TYPE_MASK" redefined
 #define JUMP_TYPE_MASK  (0x03 << JUMP_TYPE_SHIFT)
 ^
In file included from include/linux/module.h:19:0,
 from drivers/crypto/caam/compat.h:9,
 from drivers/crypto/caam/ctrl.c:11:
include/linux/jump_label.h:131:0: note: this is the location of the previous 
definition
 #define JUMP_TYPE_MASK 1UL

As JUMP_TYPE_MASK definition in desc.h is never used, we can safely remove
it to avoid the name collision.

Reported-by: Olof's autobuilder 
Signed-off-by: Fabio Estevam 
Reviewed-by: Horia Geantă 
---
Changes since v1:
- Explain the commit that caused the name collision (Horia)

 drivers/crypto/caam/desc.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/crypto/caam/desc.h b/drivers/crypto/caam/desc.h
index 983d663..1e93c6a 100644
--- a/drivers/crypto/caam/desc.h
+++ b/drivers/crypto/caam/desc.h
@@ -1492,7 +1492,6 @@ struct sec4_sg_entry {
 #define JUMP_JSL   (1 << JUMP_JSL_SHIFT)
 
 #define JUMP_TYPE_SHIFT22
-#define JUMP_TYPE_MASK (0x03 << JUMP_TYPE_SHIFT)
 #define JUMP_TYPE_LOCAL(0x00 << JUMP_TYPE_SHIFT)
 #define JUMP_TYPE_NONLOCAL (0x01 << JUMP_TYPE_SHIFT)
 #define JUMP_TYPE_HALT (0x02 << JUMP_TYPE_SHIFT)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


mxs-dcp: Failed to register sha1 hash

2015-11-26 Thread Fabio Estevam
Hi,

On kernel 4.1.13 and also on 4.4.0-rc2-next-20151126 I see the
following error on mx28:

[2.245453] mxs-dcp 80028000.dcp: Failed to register sha1 hash!
[2.253928] mxs-dcp: probe of 80028000.dcp failed with error -22

Does anyone have any idea how to fix this?

Thanks,

Fabio Estevam
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: mxs-dcp: Failed to register sha1 hash

2015-11-26 Thread Fabio Estevam
Hi Stephan,

On Thu, Nov 26, 2015 at 1:25 PM, Stephan Mueller  wrote:

> Briefly looking into drivers/crypto/mxs-dcp.c, it is an ahash and does not
> contain halg.statesize in the algo definitions. Thus it looks very much like
> the same issue that I see with ghash.

Thanks for your suggestion!

You are right: this makes the error goes away:

--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -836,6 +836,7 @@ static struct ahash_alg dcp_sha1_alg = {
.digest = dcp_sha_digest,
.halg   = {
.digestsize = SHA1_DIGEST_SIZE,
+   .statesize  = sizeof(struct sha1_state),
.base   = {
.cra_name   = "sha1",
.cra_driver_name= "sha1-dcp",
@@ -860,6 +861,7 @@ static struct ahash_alg dcp_sha256_alg = {
.digest = dcp_sha_digest,
.halg   = {
.digestsize = SHA256_DIGEST_SIZE,
+   .statesize  = sizeof(struct sha256_state),
.base   = {
.cra_name   = "sha256",
.cra_driver_name= "sha256-dcp",


Will submit it as a formal patch.

Thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: mxs-dcp - Initialize .statesize fields

2015-11-26 Thread Fabio Estevam
Initialize .statesize fields in order to avoid the following error
on probe:

mxs-dcp 80028000.dcp: Failed to register sha1 hash!
mxs-dcp: probe of 80028000.dcp failed with error -22

Cc:  # 4.1+
Suggested-by: Stephan Mueller 
Signed-off-by: Fabio Estevam 
---
 drivers/crypto/mxs-dcp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index 59ed54e..e65d379 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -836,6 +836,7 @@ static struct ahash_alg dcp_sha1_alg = {
.digest = dcp_sha_digest,
.halg   = {
.digestsize = SHA1_DIGEST_SIZE,
+   .statesize  = sizeof(struct sha1_state),
.base   = {
.cra_name   = "sha1",
.cra_driver_name= "sha1-dcp",
@@ -860,6 +861,7 @@ static struct ahash_alg dcp_sha256_alg = {
.digest = dcp_sha_digest,
.halg   = {
.digestsize = SHA256_DIGEST_SIZE,
+   .statesize  = sizeof(struct sha256_state),
.base   = {
.cra_name   = "sha256",
.cra_driver_name= "sha256-dcp",
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: caam - pass the correct buffer length

2015-11-30 Thread Fabio Estevam
When buffer 0 is used we should use buflen_0 instead of buflen_1.

Fix it.

Signed-off-by: Fabio Estevam 
---
Untested.

 drivers/crypto/caam/caamhash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index fe9c156..5845d4a 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -1596,7 +1596,7 @@ static int ahash_export(struct ahash_request *req, void 
*out)
len = state->buflen_1;
} else {
buf = state->buf_0;
-   len = state->buflen_1;
+   len = state->buflen_0;
}
 
memcpy(export->buf, buf, len);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH RFC 00/13] Further iMX CAAM updates

2015-12-07 Thread Fabio Estevam
Horia and Victoria,

On Mon, Dec 7, 2015 at 5:11 PM, Russell King - ARM Linux
 wrote:
> Here are further imx-caam updates that I've had since before the
> previous merge window.  Please review and (I guess) if Freescale
> folk can provide acks etc that would be nice.  Thanks.

Could you please help reviewing? Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/3] crypto: sahara: Add support for SAHARA in i.MX27.

2013-02-21 Thread Fabio Estevam
On Thu, Feb 21, 2013 at 12:23 PM, Sascha Hauer  wrote:

> Neither i.MX25, i.MX31 nor i.MX21 have this unit. I haven't checked the
> others, but I assume this is i.MX27 only.

There is Sahara variants on mx51/mx53.
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/3] crypto: sahara: Add support for SAHARA in i.MX27.

2013-02-21 Thread Fabio Estevam
On Thu, Feb 21, 2013 at 1:40 PM, Arnaud Patard
 wrote:

> How different are the variants ? I've a imx51 device with DT support so
> if someone running sahara on a system with DT is needed, I can be this
> person (as long as a way to test it is provided too).

mx27 has Saharav2, mx51 has Saharav4. I didn't check the differences
in detail though.

For mx51 the Sahara block is described in the document "MCIMX51
Applications Processor Security Reference Manual, Rev. 1"

I can also test the sahara dt support on a mx27pdk.
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/3] crypto: dcp: Use devm_ioremap_resource()

2013-09-22 Thread Fabio Estevam
From: Fabio Estevam 

Using devm_ioremap_resource() can make the code simpler and smaller.

When devm_ioremap_resource() is used there is no need to explicitely check the 
error returned by platform_get_resource().

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/dcp.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/crypto/dcp.c b/drivers/crypto/dcp.c
index a8a7dd4..90a7cb7 100644
--- a/drivers/crypto/dcp.c
+++ b/drivers/crypto/dcp.c
@@ -733,12 +733,7 @@ static int dcp_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, dev);
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-   if (!r) {
-   dev_err(&pdev->dev, "failed to get IORESOURCE_MEM\n");
-   return -ENXIO;
-   }
-   dev->dcp_regs_base = devm_ioremap(&pdev->dev, r->start,
- resource_size(r));
+   dev->dcp_regs_base = devm_ioremap_resource(&pdev->dev, r);
 
dcp_set(dev, DCP_CTRL_SFRST, DCP_REG_CTRL);
udelay(10);
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] crypto: dcp: Fix the path for releasing the resources

2013-09-22 Thread Fabio Estevam
From: Fabio Estevam 

tasklet_kill() is not being called in probe and the remove function releases
the resources in the wrong order.

Fix these issues.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/dcp.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/crypto/dcp.c b/drivers/crypto/dcp.c
index 93ab753..38d7a9f 100644
--- a/drivers/crypto/dcp.c
+++ b/drivers/crypto/dcp.c
@@ -842,6 +842,8 @@ err_unregister:
for (j = 0; j < i; j++)
crypto_unregister_alg(&algs[j]);
 err_free_key_iv:
+   tasklet_kill(&dev->done_task);
+   tasklet_kill(&dev->queue_task);
dma_free_coherent(&pdev->dev, 2 * AES_KEYSIZE_128, dev->payload_base,
dev->payload_base_dma);
 err_free_hw_packet:
@@ -857,21 +859,21 @@ static int dcp_remove(struct platform_device *pdev)
struct dcp_dev *dev;
int j;
dev = platform_get_drvdata(pdev);
+
+   misc_deregister(&dev->dcp_bootstream_misc);
 
-   dma_free_coherent(&pdev->dev,
-   DCP_MAX_PKG * sizeof(struct dcp_hw_packet),
-   dev->hw_pkg[0], dev->hw_phys_pkg);
-
-   dma_free_coherent(&pdev->dev, 2 * AES_KEYSIZE_128, dev->payload_base,
-   dev->payload_base_dma);
+   for (j = 0; j < ARRAY_SIZE(algs); j++)
+   crypto_unregister_alg(&algs[j]);
 
tasklet_kill(&dev->done_task);
tasklet_kill(&dev->queue_task);
 
-   for (j = 0; j < ARRAY_SIZE(algs); j++)
-   crypto_unregister_alg(&algs[j]);
+   dma_free_coherent(&pdev->dev, 2 * AES_KEYSIZE_128, dev->payload_base,
+   dev->payload_base_dma);
 
-   misc_deregister(&dev->dcp_bootstream_misc);
+   dma_free_coherent(&pdev->dev,
+   DCP_MAX_PKG * sizeof(struct dcp_hw_packet),
+   dev->hw_pkg[0], dev->hw_phys_pkg);
 
return 0;
 }
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] crypto: dcp: Use devm_request_irq()

2013-09-22 Thread Fabio Estevam
From: Fabio Estevam 

Using Use devm_request_irq() can make the code smaller and simpler, as we do
not need to call free_irq() in the probe error path and in the remove function.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/dcp.c | 22 +++---
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/crypto/dcp.c b/drivers/crypto/dcp.c
index 90a7cb7..93ab753 100644
--- a/drivers/crypto/dcp.c
+++ b/drivers/crypto/dcp.c
@@ -757,7 +757,8 @@ static int dcp_probe(struct platform_device *pdev)
return -EIO;
}
dev->dcp_vmi_irq = r->start;
-   ret = request_irq(dev->dcp_vmi_irq, dcp_vmi_irq, 0, "dcp", dev);
+   ret = devm_request_irq(&pdev->dev, dev->dcp_vmi_irq, dcp_vmi_irq, 0,
+  "dcp", dev);
if (ret != 0) {
dev_err(&pdev->dev, "can't request_irq (0)\n");
return -EIO;
@@ -766,15 +767,14 @@ static int dcp_probe(struct platform_device *pdev)
r = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
if (!r) {
dev_err(&pdev->dev, "can't get IRQ resource (1)\n");
-   ret = -EIO;
-   goto err_free_irq0;
+   return -EIO;
}
dev->dcp_irq = r->start;
-   ret = request_irq(dev->dcp_irq, dcp_irq, 0, "dcp", dev);
+   ret = devm_request_irq(&pdev->dev, dev->dcp_irq, dcp_irq, 0, "dcp",
+  dev);
if (ret != 0) {
dev_err(&pdev->dev, "can't request_irq (1)\n");
-   ret = -EIO;
-   goto err_free_irq0;
+   return -EIO;
}
 
dev->hw_pkg[0] = dma_alloc_coherent(&pdev->dev,
@@ -783,8 +783,7 @@ static int dcp_probe(struct platform_device *pdev)
GFP_KERNEL);
if (!dev->hw_pkg[0]) {
dev_err(&pdev->dev, "Could not allocate hw descriptors\n");
-   ret = -ENOMEM;
-   goto err_free_irq1;
+   return -ENOMEM;
}
 
for (i = 1; i < DCP_MAX_PKG; i++) {
@@ -849,10 +848,6 @@ err_free_hw_packet:
dma_free_coherent(&pdev->dev, DCP_MAX_PKG *
sizeof(struct dcp_hw_packet), dev->hw_pkg[0],
dev->hw_phys_pkg);
-err_free_irq1:
-   free_irq(dev->dcp_irq, dev);
-err_free_irq0:
-   free_irq(dev->dcp_vmi_irq, dev);
 
return ret;
 }
@@ -870,9 +865,6 @@ static int dcp_remove(struct platform_device *pdev)
dma_free_coherent(&pdev->dev, 2 * AES_KEYSIZE_128, dev->payload_base,
dev->payload_base_dma);
 
-   free_irq(dev->dcp_irq, dev);
-   free_irq(dev->dcp_vmi_irq, dev);
-
tasklet_kill(&dev->done_task);
tasklet_kill(&dev->queue_task);
 
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: dcp: Check the return value from devm_ioremap_resource()

2013-09-23 Thread Fabio Estevam
From: Fabio Estevam 

devm_ioremap_resource() may fail, so better check its return value and propagate
it in the case of error.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/dcp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/crypto/dcp.c b/drivers/crypto/dcp.c
index 7b77c84..247ab80 100644
--- a/drivers/crypto/dcp.c
+++ b/drivers/crypto/dcp.c
@@ -734,6 +734,8 @@ static int dcp_probe(struct platform_device *pdev)
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
dev->dcp_regs_base = devm_ioremap_resource(&pdev->dev, r);
+   if (IS_ERR(dev->dcp_regs_base))
+   return PTR_ERR(dev->dcp_regs_base);
 
dcp_set(dev, DCP_CTRL_SFRST, DCP_REG_CTRL);
udelay(10);
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] ARM: mxs: crypto: Add Freescale MXS DCP driver

2013-09-26 Thread Fabio Estevam
Hi Marek,

On Thu, Sep 26, 2013 at 8:18 AM, Marek Vasut  wrote:
> Add support for the MXS DCP block. The driver currently supports
> SHA-1/SHA-256 hashing and AES-128 CBC/ECB modes. The non-standard
> CRC32 is not yet supported.
>
> Signed-off-by: Marek Vasut 
> Cc: Herbert Xu 
> Cc: David S. Miller 
> ---
>  drivers/crypto/Kconfig   |   17 +
>  drivers/crypto/Makefile  |1 +
>  drivers/crypto/mxs-dcp.c | 1082 
> ++

What about the existing DCP driver at drivers/crypto/dcp.c ?

Why do we need to have two drivers for the same IP block? It looks
confusing to have both.

Regards,

Fabio Estevam
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] ARM: mxs: crypto: Add Freescale MXS DCP driver

2013-09-26 Thread Fabio Estevam
On Thu, Sep 26, 2013 at 8:18 AM, Marek Vasut  wrote:

> +config CRYPTO_DEV_MXS_DCP
> +   tristate "Support for Freescale MXS DCP"
> +   depends on ARCH_MXS
> +   select CRYPTO_SHA1
> +   select CRYPTO_SHA256
> +   select CRYPTO_CBC
> +   select CRYPTO_ECB
> +   select CRYPTO_AES
> +   select CRYPTO_BLKCIPHER
> +   select CRYPTO_ALGAPI
> +   help
> + The Freescale i.MX23/i.MX28 has SHA1/SHA256 and AES128 CBC/ECB
> + co-processor on the die.
> +
> + To compile this driver as a module, choose M here: the module
> + will be called atmel-sha.

Actually it will be called 'mxs-dcp'.

> + * There can even be only one instance of the MXS DCP due to the
> + * design of Linux Crypto API.

Is this true? Usually we don't want to create a global struct.

> +
> +/* AES 128 ECB and AES 128 CBC */
> +static struct crypto_alg dcp_aes_algs[] = {
> +   [0] = {

No need for explicitely add this [0]

> +   .cra_name   = "ecb(aes)",
> +   .cra_driver_name= "ecb-aes-dcp",
> +   .cra_priority   = 400,
> +   .cra_alignmask  = 15,
> +   .cra_flags  = CRYPTO_ALG_TYPE_ABLKCIPHER |
> + CRYPTO_ALG_ASYNC |
> + CRYPTO_ALG_NEED_FALLBACK,
> +   .cra_init   = mxs_dcp_aes_fallback_init,
> +   .cra_exit   = mxs_dcp_aes_fallback_exit,
> +   .cra_blocksize  = AES_BLOCK_SIZE,
> +   .cra_ctxsize= sizeof(struct dcp_async_ctx),
> +   .cra_type   = &crypto_ablkcipher_type,
> +   .cra_module = THIS_MODULE,
> +   .cra_u  = {
> +   .ablkcipher = {
> +   .min_keysize= AES_MIN_KEY_SIZE,
> +   .max_keysize= AES_MAX_KEY_SIZE,
> +   .setkey = mxs_dcp_aes_setkey,
> +   .encrypt= mxs_dcp_aes_ecb_encrypt,
> +   .decrypt= mxs_dcp_aes_ecb_decrypt
> +   }
> +   }
> +   },
> +   [1] = {

Same here.

> +static int mxs_dcp_probe(struct platform_device *pdev)
> +{
> +   struct device *dev = &pdev->dev;
> +   struct dcp *sdcp = NULL;
> +   int i, ret;
> +
> +   struct resource *iores;
> +   int dcp_vmi_irq, dcp_irq;
> +
> +   mutex_lock(&global_mutex);
> +   if (global_sdcp) {
> +   dev_err(dev, "Only one DCP instance allowed!\n");
> +   ret = -ENODEV;
> +   goto err_mutex;
> +   }
> +
> +   iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +   dcp_vmi_irq = platform_get_irq(pdev, 0);
> +   dcp_irq = platform_get_irq(pdev, 1);
> +   if (!iores || dcp_vmi_irq < 0 || dcp_irq < 0) {

No need to check for !iores here.

You use it inside devm_ioremap_resource, which already does this checking.


> +   /*
> +* We do not enable context switching. Give the context buffer a
> +* pointer to an illegal address so if context switching is
> +* inadvertantly enabled, the DCP will return an error instead of
> +* trashing good memory. The DCP DMA cannot access ROM, so any ROM
> +* address will do.
> +*/
> +   writel(0x, sdcp->base + MXS_DCP_CONTEXT);

Can you use a define instead of this hardcoded number?

> +static int mxs_dcp_remove(struct platform_device *pdev)
> +{
> +   struct dcp *sdcp;
> +   int i;
> +
> +   sdcp = platform_get_drvdata(pdev);
> +
> +   kthread_stop(sdcp->thread[DCP_CHAN_HASH_SHA]);
> +   kthread_stop(sdcp->thread[DCP_CHAN_CRYPTO]);
> +
> +   platform_set_drvdata(pdev, NULL);
> +
> +   dma_free_coherent(sdcp->dev, sizeof(struct dcp_coherent_block),
> + sdcp->coh, sdcp->coh_phys);
> +
> +   if (sdcp->caps & MXS_DCP_CAPABILITY1_SHA256)
> +   crypto_unregister_ahash(&dcp_sha256_alg);
> +
> +   if (sdcp->caps & MXS_DCP_CAPABILITY1_SHA1)
> +   crypto_unregister_ahash(&dcp_sha1_alg);
> +
> +   if (sdcp->caps & MXS_DCP_CAPABILITY1_AES128) {
> +   for (i = ARRAY_SIZE(dcp_aes_algs); i >= 0; i--)
> +   crypto_unregister_alg(&dcp_aes_algs[i]);
> +   }
> +
> +   mutex_lock(&global_mutex);
> +   global_sdcp = NULL;
> +   mutex_unlock(&global_mutex);


The order of the resources removal does not look correct here.

It should match the order of the error path in probe.

> +
> +   return 0;
> +}
> +
> +static const struct of_device_id mxs_dcp_dt_ids[] = {
> +   {.compatible = "fsl,mxs-dcp", .data = NULL,},

In the other mxs/imx drivers we use:

.compatible = "fsl,-dcp"

You also need to provide a devicetree documentation for this binding.

> + 

[PATCH 2/2] crypto: mxs-dcp: Check the return value of stmp_reset_block()

2014-01-28 Thread Fabio Estevam
From: Fabio Estevam 

stmp_reset_block() may fail, so check its return value and propagate it in the
case of error.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/mxs-dcp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index 2d7d497..4d18c40 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -942,7 +942,9 @@ static int mxs_dcp_probe(struct platform_device *pdev)
}
 
/* Restart the DCP block. */
-   stmp_reset_block(sdcp->base);
+   ret = stmp_reset_block(sdcp->base);
+   if (ret)
+   goto err_mutex;
 
/* Initialize control register. */
writel(MXS_DCP_CTRL_GATHER_RESIDUAL_WRITES |
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] crypto: mxs-dcp: Use devm_kzalloc()

2014-01-28 Thread Fabio Estevam
From: Fabio Estevam 

Using devm_kzalloc() can make the code cleaner.

While at it, remove the devm_kzalloc error message as there is standard OOM
message done by the core.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/mxs-dcp.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index a6db7fa..2d7d497 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -935,9 +935,8 @@ static int mxs_dcp_probe(struct platform_device *pdev)
}
 
/* Allocate coherent helper block. */
-   sdcp->coh = kzalloc(sizeof(struct dcp_coherent_block), GFP_KERNEL);
+   sdcp->coh = devm_kzalloc(dev, sizeof(*sdcp->coh), GFP_KERNEL);
if (!sdcp->coh) {
-   dev_err(dev, "Error allocating coherent block\n");
ret = -ENOMEM;
goto err_mutex;
}
@@ -982,7 +981,7 @@ static int mxs_dcp_probe(struct platform_device *pdev)
if (IS_ERR(sdcp->thread[DCP_CHAN_HASH_SHA])) {
dev_err(dev, "Error starting SHA thread!\n");
ret = PTR_ERR(sdcp->thread[DCP_CHAN_HASH_SHA]);
-   goto err_free_coherent;
+   goto err_mutex;
}
 
sdcp->thread[DCP_CHAN_CRYPTO] = kthread_run(dcp_chan_thread_aes,
@@ -1040,8 +1039,6 @@ err_destroy_aes_thread:
 err_destroy_sha_thread:
kthread_stop(sdcp->thread[DCP_CHAN_HASH_SHA]);
 
-err_free_coherent:
-   kfree(sdcp->coh);
 err_mutex:
mutex_unlock(&global_mutex);
return ret;
@@ -1051,8 +1048,6 @@ static int mxs_dcp_remove(struct platform_device *pdev)
 {
struct dcp *sdcp = platform_get_drvdata(pdev);
 
-   kfree(sdcp->coh);
-
if (sdcp->caps & MXS_DCP_CAPABILITY1_SHA256)
crypto_unregister_ahash(&dcp_sha256_alg);
 
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: mxs-dcp: Fix platform_get_irq() error handling

2014-02-13 Thread Fabio Estevam
From: Fabio Estevam 

We should test the error case for each platform_get_irq() assignment and
propagate the error accordingly.

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/mxs-dcp.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index 37e0706..08761d6 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -908,9 +908,14 @@ static int mxs_dcp_probe(struct platform_device *pdev)
 
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
dcp_vmi_irq = platform_get_irq(pdev, 0);
+   if (dcp_vmi_irq < 0) {
+   ret = dcp_vmi_irq;
+   goto err_mutex;
+   }
+
dcp_irq = platform_get_irq(pdev, 1);
-   if (dcp_vmi_irq < 0 || dcp_irq < 0) {
-   ret = -EINVAL;
+   if (dcp_irq < 0) {
+   ret = dcp_irq;
goto err_mutex;
}
 
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


mxs-dcp: BUG: init/1 still has locks held!

2014-05-11 Thread Fabio Estevam
Hi,

Running linux-next 20140509 on a mx28evk I observe the following warning:

[8.526613] Freeing unused kernel memory: 232K (c0683000 - c06bd000)
starting pid 56, tty '': '/etc/rc.d/rcS'
[9.110314]
[9.111864] =
[9.116603] [ BUG: init/1 still has locks held! ]
[9.121488] 3.15.0-rc4-next-20140509-1-g319564e #1154 Not tainted
[9.128071] -
[9.132825] 1 lock held by init/1:
[9.136252]  #0:  (global_mutex){+.+.+.}, at: [] mxs_dcp_probe+0x14
[9.144196]
[9.144196] stack backtrace:
[9.14] CPU: 0 PID: 1 Comm: init Not tainted 3.15.0-rc4-next-20140509-004
[9.157610] [] (unwind_backtrace) from [] (show_stack+0x)
[9.165595] [] (show_stack) from [] (do_fork+0x2c8/0x3cc)
[9.172921] [] (do_fork) from [] (sys_vfork+0x20/0x2c)
[9.179973] [] (sys_vfork) from [] (ret_fast_syscall+0x0)
Mounting /proc and /sys

Should we really use a global mutex here? What is a proper fix for this?

Regards,

Fabio Estevam
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: mxs-dcp: BUG: init/1 still has locks held!

2014-05-11 Thread Fabio Estevam
On Sun, May 11, 2014 at 5:08 PM, Alexander Shiyan  wrote:
> Sun, 11 May 2014 16:57:57 -0300 от Fabio Estevam :
>> Hi,
>>
>> Running linux-next 20140509 on a mx28evk I observe the following warning:
>>
>> [8.526613] Freeing unused kernel memory: 232K (c0683000 - c06bd000)
>> starting pid 56, tty '': '/etc/rc.d/rcS'
>> [9.110314]
>> [9.111864] =
>> [9.116603] [ BUG: init/1 still has locks held! ]
>> [9.121488] 3.15.0-rc4-next-20140509-1-g319564e #1154 Not tainted
>> [9.128071] -
>> [9.132825] 1 lock held by init/1:
>> [9.136252]  #0:  (global_mutex){+.+.+.}, at: [] 
>> mxs_dcp_probe+0x14
>> [9.144196]
>> [9.144196] stack backtrace:
>> [9.14] CPU: 0 PID: 1 Comm: init Not tainted 
>> 3.15.0-rc4-next-20140509-004
>> [9.157610] [] (unwind_backtrace) from [] 
>> (show_stack+0x)
>> [9.165595] [] (show_stack) from [] 
>> (do_fork+0x2c8/0x3cc)
>> [9.172921] [] (do_fork) from [] (sys_vfork+0x20/0x2c)
>> [9.179973] [] (sys_vfork) from [] 
>> (ret_fast_syscall+0x0)
>> Mounting /proc and /sys
>>
>> Should we really use a global mutex here? What is a proper fix for this?
>
> On my opinion mutex_lock/unlock should not be used in probe.
> Try to remove this entirely.

I think the same. Will submit a patch doing as suggested.

Regards,

Fabio Estevam
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] mxs-dcp: Remove mutex_lock from probe

2014-05-11 Thread Fabio Estevam
From: Fabio Estevam 

Remove mutex_lock from probe in order to avoid the following warning:

[8.526613] Freeing unused kernel memory: 232K (c0683000 - c06bd000)
starting pid 56, tty '': '/etc/rc.d/rcS'
[9.110314]
[9.111864] =
[9.116603] [ BUG: init/1 still has locks held! ]
[9.121488] 3.15.0-rc4-next-20140509-1-g319564e #1154 Not tainted
[9.128071] -
[9.132825] 1 lock held by init/1:
[9.136252]  #0:  (global_mutex){+.+.+.}, at: [] mxs_dcp_probe+0x14
[9.144196]
[9.144196] stack backtrace:
[9.14] CPU: 0 PID: 1 Comm: init Not tainted 3.15.0-rc4-next-20140509-004
[9.157610] [] (unwind_backtrace) from [] (show_stack+0x)
[9.165595] [] (show_stack) from [] (do_fork+0x2c8/0x3cc)
[9.172921] [] (do_fork) from [] (sys_vfork+0x20/0x2c)
[9.179973] [] (sys_vfork) from [] (ret_fast_syscall+0x0)

Signed-off-by: Fabio Estevam 
---
 drivers/crypto/mxs-dcp.c | 47 ---
 1 file changed, 16 insertions(+), 31 deletions(-)

diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index 7bbe0ab..f100ee1 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -907,60 +907,49 @@ static int mxs_dcp_probe(struct platform_device *pdev)
struct resource *iores;
int dcp_vmi_irq, dcp_irq;
 
-   mutex_lock(&global_mutex);
if (global_sdcp) {
dev_err(dev, "Only one DCP instance allowed!\n");
-   ret = -ENODEV;
-   goto err_mutex;
+   return -ENODEV;
}
 
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
dcp_vmi_irq = platform_get_irq(pdev, 0);
-   if (dcp_vmi_irq < 0) {
-   ret = dcp_vmi_irq;
-   goto err_mutex;
-   }
+   if (dcp_vmi_irq < 0)
+   return dcp_vmi_irq;
 
dcp_irq = platform_get_irq(pdev, 1);
-   if (dcp_irq < 0) {
-   ret = dcp_irq;
-   goto err_mutex;
-   }
+   if (dcp_irq < 0)
+   return dcp_irq;
 
sdcp = devm_kzalloc(dev, sizeof(*sdcp), GFP_KERNEL);
-   if (!sdcp) {
-   ret = -ENOMEM;
-   goto err_mutex;
-   }
+   if (!sdcp)
+   return -ENOMEM;
 
sdcp->dev = dev;
sdcp->base = devm_ioremap_resource(dev, iores);
-   if (IS_ERR(sdcp->base)) {
-   ret = PTR_ERR(sdcp->base);
-   goto err_mutex;
-   }
+   if (IS_ERR(sdcp->base))
+   return PTR_ERR(sdcp->base);
+
 
ret = devm_request_irq(dev, dcp_vmi_irq, mxs_dcp_irq, 0,
   "dcp-vmi-irq", sdcp);
if (ret) {
dev_err(dev, "Failed to claim DCP VMI IRQ!\n");
-   goto err_mutex;
+   return ret;
}
 
ret = devm_request_irq(dev, dcp_irq, mxs_dcp_irq, 0,
   "dcp-irq", sdcp);
if (ret) {
dev_err(dev, "Failed to claim DCP IRQ!\n");
-   goto err_mutex;
+   return ret;
}
 
/* Allocate coherent helper block. */
sdcp->coh = devm_kzalloc(dev, sizeof(*sdcp->coh) + DCP_ALIGNMENT,
   GFP_KERNEL);
-   if (!sdcp->coh) {
-   ret = -ENOMEM;
-   goto err_mutex;
-   }
+   if (!sdcp->coh)
+   return -ENOMEM;
 
/* Re-align the structure so it fits the DCP constraints. */
sdcp->coh = PTR_ALIGN(sdcp->coh, DCP_ALIGNMENT);
@@ -968,7 +957,7 @@ static int mxs_dcp_probe(struct platform_device *pdev)
/* Restart the DCP block. */
ret = stmp_reset_block(sdcp->base);
if (ret)
-   goto err_mutex;
+   return ret;
 
/* Initialize control register. */
writel(MXS_DCP_CTRL_GATHER_RESIDUAL_WRITES |
@@ -1006,8 +995,7 @@ static int mxs_dcp_probe(struct platform_device *pdev)
  NULL, "mxs_dcp_chan/sha");
if (IS_ERR(sdcp->thread[DCP_CHAN_HASH_SHA])) {
dev_err(dev, "Error starting SHA thread!\n");
-   ret = PTR_ERR(sdcp->thread[DCP_CHAN_HASH_SHA]);
-   goto err_mutex;
+   return PTR_ERR(sdcp->thread[DCP_CHAN_HASH_SHA]);
}
 
sdcp->thread[DCP_CHAN_CRYPTO] = kthread_run(dcp_chan_thread_aes,
@@ -1064,9 +1052,6 @@ err_destroy_aes_thread:
 
 err_destroy_sha_thread:
kthread_stop(sdcp->thread[DCP_CHAN_HASH_SHA]);
-
-err_mutex:
-   mutex_unlock(&global_mutex);
return ret;
 }
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] mxs-dcp: Remove global mutex

2014-05-12 Thread Fabio Estevam
Remove mutex_lock from probe in order to avoid the following warning:

[8.526613] Freeing unused kernel memory: 232K (c0683000 - c06bd000)
starting pid 56, tty '': '/etc/rc.d/rcS'
[9.110314]
[9.111864] =
[9.116603] [ BUG: init/1 still has locks held! ]
[9.121488] 3.15.0-rc4-next-20140509-1-g319564e #1154 Not tainted
[9.128071] -
[9.132825] 1 lock held by init/1:
[9.136252]  #0:  (global_mutex){+.+.+.}, at: [] mxs_dcp_probe+0x14
[9.144196]
[9.144196] stack backtrace:
[9.14] CPU: 0 PID: 1 Comm: init Not tainted 3.15.0-rc4-next-20140509-004
[9.157610] [] (unwind_backtrace) from [] (show_stack+0x)
[9.165595] [] (show_stack) from [] (do_fork+0x2c8/0x3cc)
[9.172921] [] (do_fork) from [] (sys_vfork+0x20/0x2c)
[9.179973] [] (sys_vfork) from [] (ret_fast_syscall+0x0)

Signed-off-by: Fabio Estevam 
---
Changes since v1:
- Remove global_mutex entirely

 drivers/crypto/mxs-dcp.c | 50 
 1 file changed, 16 insertions(+), 34 deletions(-)

diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index 7bbe0ab..e48f0b8 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -104,7 +104,6 @@ struct dcp_sha_req_ctx {
  * design of Linux Crypto API.
  */
 static struct dcp *global_sdcp;
-static DEFINE_MUTEX(global_mutex);
 
 /* DCP register layout. */
 #define MXS_DCP_CTRL   0x00
@@ -907,60 +906,49 @@ static int mxs_dcp_probe(struct platform_device *pdev)
struct resource *iores;
int dcp_vmi_irq, dcp_irq;
 
-   mutex_lock(&global_mutex);
if (global_sdcp) {
dev_err(dev, "Only one DCP instance allowed!\n");
-   ret = -ENODEV;
-   goto err_mutex;
+   return -ENODEV;
}
 
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
dcp_vmi_irq = platform_get_irq(pdev, 0);
-   if (dcp_vmi_irq < 0) {
-   ret = dcp_vmi_irq;
-   goto err_mutex;
-   }
+   if (dcp_vmi_irq < 0)
+   return dcp_vmi_irq;
 
dcp_irq = platform_get_irq(pdev, 1);
-   if (dcp_irq < 0) {
-   ret = dcp_irq;
-   goto err_mutex;
-   }
+   if (dcp_irq < 0)
+   return dcp_irq;
 
sdcp = devm_kzalloc(dev, sizeof(*sdcp), GFP_KERNEL);
-   if (!sdcp) {
-   ret = -ENOMEM;
-   goto err_mutex;
-   }
+   if (!sdcp)
+   return -ENOMEM;
 
sdcp->dev = dev;
sdcp->base = devm_ioremap_resource(dev, iores);
-   if (IS_ERR(sdcp->base)) {
-   ret = PTR_ERR(sdcp->base);
-   goto err_mutex;
-   }
+   if (IS_ERR(sdcp->base))
+   return PTR_ERR(sdcp->base);
+
 
ret = devm_request_irq(dev, dcp_vmi_irq, mxs_dcp_irq, 0,
   "dcp-vmi-irq", sdcp);
if (ret) {
dev_err(dev, "Failed to claim DCP VMI IRQ!\n");
-   goto err_mutex;
+   return ret;
}
 
ret = devm_request_irq(dev, dcp_irq, mxs_dcp_irq, 0,
   "dcp-irq", sdcp);
if (ret) {
dev_err(dev, "Failed to claim DCP IRQ!\n");
-   goto err_mutex;
+   return ret;
}
 
/* Allocate coherent helper block. */
sdcp->coh = devm_kzalloc(dev, sizeof(*sdcp->coh) + DCP_ALIGNMENT,
   GFP_KERNEL);
-   if (!sdcp->coh) {
-   ret = -ENOMEM;
-   goto err_mutex;
-   }
+   if (!sdcp->coh)
+   return -ENOMEM;
 
/* Re-align the structure so it fits the DCP constraints. */
sdcp->coh = PTR_ALIGN(sdcp->coh, DCP_ALIGNMENT);
@@ -968,7 +956,7 @@ static int mxs_dcp_probe(struct platform_device *pdev)
/* Restart the DCP block. */
ret = stmp_reset_block(sdcp->base);
if (ret)
-   goto err_mutex;
+   return ret;
 
/* Initialize control register. */
writel(MXS_DCP_CTRL_GATHER_RESIDUAL_WRITES |
@@ -1006,8 +994,7 @@ static int mxs_dcp_probe(struct platform_device *pdev)
  NULL, "mxs_dcp_chan/sha");
if (IS_ERR(sdcp->thread[DCP_CHAN_HASH_SHA])) {
dev_err(dev, "Error starting SHA thread!\n");
-   ret = PTR_ERR(sdcp->thread[DCP_CHAN_HASH_SHA]);
-   goto err_mutex;
+   return PTR_ERR(sdcp->thread[DCP_CHAN_HASH_SHA]);
}
 
sdcp->thread[DCP_CHAN_CRYPTO] = kthread_run(dcp_chan_thread_aes,
@@ -1064,9 +1051,6 @@ err_destroy_aes_thread:
 
 err_destroy_sha_thread:
kthread_stop(sdcp->thread[DCP_CHAN_HASH

Re: [PATCH v3 5/5] hwrng: imx-rngc: enable driver for i.MX6

2020-07-14 Thread Fabio Estevam
On Tue, Jul 14, 2020 at 9:39 AM Horia Geantă  wrote:

>  static const struct of_device_id imx_rngc_dt_ids[] = {
> { .compatible = "fsl,imx25-rngb", .data = NULL, },
> +   { .compatible = "fsl,imx6sl-rngb", .data = NULL, },
> +   { .compatible = "fsl,imx6sll-rngb", .data = NULL, },
> +   { .compatible = "fsl,imx6ull-rngb", .data = NULL, },

It seems that these new entries are not needed, since they fallback to
"fsl,imx25-rngb".


Re: [PATCH 1/3] ARM: dts: imx6ull: Add rngb node

2020-07-27 Thread Fabio Estevam
Hi Christian,

On Mon, Jul 27, 2020 at 8:00 AM Christian Eggers  wrote:
>
> The RNGB block on 6ull has no major differences, but it has no
> switchable clock.

Horia has already sent a patch series that adds imx6ull rngb support:
https://lkml.org/lkml/2020/7/23/173


[PATCH 1/2] crypto: stm32/crc32 - include

2020-08-24 Thread Fabio Estevam
Building ARM allmodconfig leads to the following warnings:

drivers/crypto/stm32/stm32-crc32.c:128:2: error: implicit declaration of 
function 'writel_relaxed' [-Werror=implicit-function-declaration]
drivers/crypto/stm32/stm32-crc32.c:134:17: error: implicit declaration of 
function 'readl_relaxed' [-Werror=implicit-function-declaration]
drivers/crypto/stm32/stm32-crc32.c:176:4: error: implicit declaration of 
function 'writeb_relaxed' [-Werror=implicit-function-declaration]

Include  to fix such warnings.

Reported-by: Olof's autobuilder 
Signed-off-by: Fabio Estevam 
---
 drivers/crypto/stm32/stm32-crc32.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/stm32/stm32-crc32.c 
b/drivers/crypto/stm32/stm32-crc32.c
index 3ba41148c2a4..2994549beba3 100644
--- a/drivers/crypto/stm32/stm32-crc32.c
+++ b/drivers/crypto/stm32/stm32-crc32.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
2.17.1



[PATCH 2/2] crypto: stm32/hash - include

2020-08-24 Thread Fabio Estevam
Building ARM allmodconfig leads to the following warnings:

drivers/crypto/stm32/stm32-hash.c:492:18: error: implicit declaration of 
function 'dma_map_sg'; did you mean 'dma_cap_set'? 
[-Werror=implicit-function-declaration]
drivers/crypto/stm32/stm32-hash.c:493:8: error: 'DMA_TO_DEVICE' undeclared 
(first use in this function); did you mean 'MT_DEVICE'?
drivers/crypto/stm32/stm32-hash.c:501:3: error: implicit declaration of 
function 'dma_unmap_sg' [-Werror=implicit-function-declaration]
drivers/crypto/stm32/stm32-hash.c:589:8: error: 'DMA_TO_DEVICE' undeclared 
(first use in this function); did you mean 'MT_DEVICE'?

Include  to fix such warnings

Reported-by: Olof's autobuilder 
Signed-off-by: Fabio Estevam 
---
 drivers/crypto/stm32/stm32-hash.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/stm32/stm32-hash.c 
b/drivers/crypto/stm32/stm32-hash.c
index 03c5e6683805..092eaabda238 100644
--- a/drivers/crypto/stm32/stm32-hash.c
+++ b/drivers/crypto/stm32/stm32-hash.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
2.17.1



[PATCH] crypto: arm/curve25519 - include

2020-08-24 Thread Fabio Estevam
Building ARM allmodconfig leads to the following warnings:

arch/arm/crypto/curve25519-glue.c:73:12: error: implicit declaration of 
function 'sg_copy_to_buffer' [-Werror=implicit-function-declaration]
arch/arm/crypto/curve25519-glue.c:74:9: error: implicit declaration of function 
'sg_nents_for_len' [-Werror=implicit-function-declaration]
arch/arm/crypto/curve25519-glue.c:88:11: error: implicit declaration of 
function 'sg_copy_from_buffer' [-Werror=implicit-function-declaration]

Include  to fix such warnings

Reported-by: Olof's autobuilder 
Signed-off-by: Fabio Estevam 
---
 arch/arm/crypto/curve25519-glue.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/crypto/curve25519-glue.c 
b/arch/arm/crypto/curve25519-glue.c
index 776ae07e0469..31eb75b6002f 100644
--- a/arch/arm/crypto/curve25519-glue.c
+++ b/arch/arm/crypto/curve25519-glue.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 asmlinkage void curve25519_neon(u8 mypublic[CURVE25519_KEY_SIZE],
-- 
2.17.1



Re: [PATCH 02/12] crypto: caam - use devres to unmap JR's registers

2019-09-03 Thread Fabio Estevam
Hi Andrey,

On Tue, Sep 3, 2019 at 11:37 PM Andrey Smirnov  wrote:
>
> Use devres to unmap memory and drop explicit de-initialization
> code.
>
> NOTE: There's no corresponding unmapping code in caam_jr_remove which
> seems like a resource leak.
>
> Signed-off-by: Andrey Smirnov 
> Cc: Chris Healy 
> Cc: Lucas Stach 
> Cc: Horia Geantă 
> Cc: Herbert Xu 
> Cc: Iuliana Prodan 
> Cc: linux-crypto@vger.kernel.org
> Cc: linux-ker...@vger.kernel.org
> ---
>  drivers/crypto/caam/jr.c | 13 +
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
> index 417ad52615c6..7947d61a25cf 100644
> --- a/drivers/crypto/caam/jr.c
> +++ b/drivers/crypto/caam/jr.c
> @@ -498,6 +498,7 @@ static int caam_jr_probe(struct platform_device *pdev)
> struct caam_job_ring __iomem *ctrl;
> struct caam_drv_private_jr *jrpriv;
> static int total_jobrs;
> +   struct resource *r;
> int error;
>
> jrdev = &pdev->dev;
> @@ -513,9 +514,15 @@ static int caam_jr_probe(struct platform_device *pdev)
> nprop = pdev->dev.of_node;
> /* Get configuration properties from device tree */
> /* First, get register page */
> -   ctrl = of_iomap(nprop, 0);
> +   r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +   if (!r) {
> +   dev_err(jrdev, "platform_get_resource() failed\n");
> +   return -ENOMEM;
> +   }
> +
> +   ctrl = devm_ioremap(jrdev, r->start, resource_size(r));

It seems that using devm_platform_ioremap_resource() could make the
code even smaller.

Regards,

Fabio Estevam


Re: [PATCH 1/4] ARM: dts: imx6sl: fix rng node

2020-06-19 Thread Fabio Estevam
Hi Horia,

On Fri, Jun 19, 2020 at 6:34 PM Horia Geantă  wrote:
>
> rng DT node was added without a compatible string.
>
> i.MX driver for RNGC (drivers/char/hw_random/imx-rngc.c) also claims
> support for RNGB, and is currently used for i.MX25.
>
> Let's used this driver also for RNGB block in i.MX6SL.

"Let's use"

>
> Fixes: e29fe21cff96 ("ARM: dts: add device tree source for imx6sl SoC")
> Signed-off-by: Horia Geantă 
> ---
>  arch/arm/boot/dts/imx6sl.dtsi | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/arch/arm/boot/dts/imx6sl.dtsi b/arch/arm/boot/dts/imx6sl.dtsi
> index 911d8cf77f2c..1f0f250ee175 100644
> --- a/arch/arm/boot/dts/imx6sl.dtsi
> +++ b/arch/arm/boot/dts/imx6sl.dtsi
> @@ -939,8 +939,10 @@
> };
>
> rngb: rngb@21b4000 {
> +   compatible = "fsl,imx25-rngb";

Better to use:

 compatible = "fsl,imx6sl-rngb","fsl,imx25-rngb";

and document fsl,imx6sl-rngb


Re: [PATCH 4/4] hwrng: imx-rngc: enable driver for i.MX6

2020-06-19 Thread Fabio Estevam
On Fri, Jun 19, 2020 at 6:34 PM Horia Geantă  wrote:
>
> i.MX6 SL, SLL, ULL, ULZ SoCs have an RNGB block.
>
> Since imx-rngc driver supports also rngb,
> let's enable it for these SoCs too.
>
> Signed-off-by: Horia Geantă 
> ---
>  drivers/char/hw_random/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
> index 0ad17efc96df..53f6a7e4392f 100644
> --- a/drivers/char/hw_random/Kconfig
> +++ b/drivers/char/hw_random/Kconfig
> @@ -245,7 +245,7 @@ config HW_RANDOM_MXC_RNGA
>  config HW_RANDOM_IMX_RNGC
> tristate "Freescale i.MX RNGC Random Number Generator"
> depends on HAS_IOMEM && HAVE_CLK
> -   depends on SOC_IMX25 || COMPILE_TEST
> +   depends on SOC_IMX25 || SOC_IMX6SL || SOC_IMX6SLL || SOC_IMX6UL || 
> COMPILE_TEST

If in the future more SoCs will use this IP, then we will need to keep
extending this list over and over again.

Maybe you could use:

depends on MACH_IMX || COMPILE_TEST



> default HW_RANDOM
> help
>   This driver provides kernel-side support for the Random Number
> --
> 2.17.1
>


Re: [PATCH 4/4] hwrng: imx-rngc: enable driver for i.MX6

2020-06-19 Thread Fabio Estevam
On Fri, Jun 19, 2020 at 6:46 PM Fabio Estevam  wrote:

> If in the future more SoCs will use this IP, then we will need to keep
> extending this list over and over again.
>
> Maybe you could use:
>
> depends on MACH_IMX || COMPILE_TEST

MACH_MXC is what I meant ;-)


Re: [PATCH V2 2/2] ARM: dts: imx7s: add snvs rtc clock

2018-01-09 Thread Fabio Estevam
Hi Anson,

On Tue, Jan 9, 2018 at 12:51 AM, Anson Huang  wrote:

> +   - clocks
> +  Usage: required if SNVS LP RTC requires explicit enablement of clocks
> +  Value type: 
> +  Definition:  A list of phandle and clock specifier pairs describing
> +  the clocks required for enabling and disabling SNVS LP RTC.


It is a single clock that is used here, so it would be better to
describe the text as:

  Definition:  A clock specifier describing the clock required for
enabling and disabling SNVS LP RTC

> +   - clock-names
> +  Usage: required if SNVS LP RTC requires explicit enablement of clocks
> +  Value type: 
> +  Definition: A list of clock name strings in the same order as the
> +  clocks property.

and here you must describe that the name should be "snvs-rtc":

  Definition: Clock name string should be "snvs-rtc".


Re: [PATCH] crypto: mxs-dcp: Add empty hash export and import

2018-01-16 Thread Fabio Estevam
Hi Kamil,

On Tue, Jan 16, 2018 at 2:16 PM, Kamil Konieczny
 wrote:
> Crypto framework will require async hash export/import, so add empty
> functions to prevent OOPS.

Which Oops exactly are you getting?

Just booted 4.14.13 and the mxs-dcp driver does not even probe successfully:

[2.455404] mxs-dcp 80028000.dcp: Failed to register sha1 hash!
[2.464042] mxs-dcp: probe of 80028000.dcp failed with error -22


Re: [RESEND PATCH v2 0/5] Enable CAAM on i.MX7s fix TrustZone issues

2018-01-26 Thread Fabio Estevam
Hi Bryan,

On Fri, Jan 26, 2018 at 5:04 PM, Bryan O'Donoghue
 wrote:

> Bryan O'Donoghue (1):
>   crypto: caam: Fix endless loop when RNG is already initialized
>
> Rui Miguel Silva (4):
>   crypto: caam: Fix null dereference at error path
>   crypto: caam: do not use mem and emi_slow clock for imx7x

Thanks for your series!

>   clk: imx7d: add CAAM clock

This one should be posted to the clock driver maintainers.

>   ARM: dts: imx7s: add CAAM device node

This one should be posted to the i.MX arch maintainers.


Re: [PATCH v3 4/5] clk: imx7d: add CAAM clock

2018-02-01 Thread Fabio Estevam
On Wed, Jan 31, 2018 at 12:00 AM, Bryan O'Donoghue
 wrote:
> From: Rui Miguel Silva 
>
> Add CAAM clock so that we could use the Cryptographic Acceleration and
> Assurance Module (CAAM) hardware block.
>
> Signed-off-by: Rui Miguel Silva 
> Cc: Michael Turquette 
> Cc: Stephen Boyd 
> Cc: linux-...@vger.kernel.org
> Cc: "Horia Geantă" 
> Cc: Aymen Sghaier 
> Cc: Fabio Estevam 
> Cc: Peng Fan 
> Cc: "David S. Miller" 
> Cc: Lukas Auer 
> Signed-off-by: Bryan O'Donoghue 

Reviewed-by: Fabio Estevam 


Re: [PATCH v2 2/2] hwrng: mxc-rnga - add driver support on boards with device tree

2018-03-05 Thread Fabio Estevam
Hi Vladimir,

On Mon, Mar 5, 2018 at 7:21 PM, Vladimir Zapolskiy  wrote:
> The driver works well on i.MX31 powered boards with device description
> taken from board device tree, the only change to add to the driver is
> the missing OF device id, the affected list of included headers and
> indentation in platform driver struct are beautified a little.

Patch looks good.

I have an off-topic question though :-)

Do you have mx31 device tree related patches so that you can test this?

Do we have mx31 pinctrl support?

Please advise.


Re: [PATCH v2 1/2] dt-bindings: rng: Document Freescale i.MX21 and i.MX31 RNGA compatibles

2018-03-05 Thread Fabio Estevam
On Mon, Mar 5, 2018 at 7:20 PM, Vladimir Zapolskiy  wrote:
> Freescale i.MX21 and i.MX31 SoCs contain a Random Number Generator
> Accelerator module (RNGA), which is replaced by RNGB and RNGC modules
> on later i.MX SoC series, the change adds a new compatible property
> to describe the controller.
>
> Since all versions of Freescale RNG modules are legacy, apparently
> the documentation file has no more potential for further extensions,
> nevertheless generalize it by removing explicit RNGC specifics.
>
> Signed-off-by: Vladimir Zapolskiy 
> Reviewed-by: Rob Herring 

Reviewed-by: Fabio Estevam 


Re: [PATCH v2 2/2] hwrng: mxc-rnga - add driver support on boards with device tree

2018-03-05 Thread Fabio Estevam
On Mon, Mar 5, 2018 at 7:21 PM, Vladimir Zapolskiy  wrote:
> The driver works well on i.MX31 powered boards with device description
> taken from board device tree, the only change to add to the driver is
> the missing OF device id, the affected list of included headers and
> indentation in platform driver struct are beautified a little.
>
> Signed-off-by: Vladimir Zapolskiy 

Reviewed-by: Fabio Estevam 


Re: [PATCH v2 2/2] hwrng: mxc-rnga - add driver support on boards with device tree

2018-03-05 Thread Fabio Estevam
Hi Vladimir,

On Mon, Mar 5, 2018 at 8:44 PM, Vladimir Zapolskiy  wrote:

> Yes, I have a pretty good i.MX31 dtsi change (tested everything but USB
> and multimedia, and that notorious watchdog problem still has to be
> agreed with Uwe and solved), but I'm trying to save my time a little, and
> my plan is to send everything altogether as a single imx31.dtsi update
> (without instant pinctrl though). And basically RNGA support is the only
> missing part at the moment.

Ok, that's good news.

> Yes, I have a complete and well tested i.MX31 pinctrl driver, it is done
> similarly to all known Freescale pin controller drivers.

It would be nice if you could post it even in the current form.

> I sort of dislike it, and my preference is to "upgrade" it to utilize
> generic pin multiplexing with groups, functions and pin configuration
> as it is described in pinctrl-bindings.txt, then hopefully some ideas

On i.MX8M there was a recent discussion about using the new generic
pinctl versus the old method where we encode the pinmux value in dts.

i.MX maintainers are in favor of the old method, so that we can have
this same scheme for all i.MX variants.

Well, that is a topic for another mailing list :-)

Thanks


Re: CAAM and IMA/EVM : caam_rsa_enc: DECO: desc idx 7: Protocol Size Error

2018-04-10 Thread Fabio Estevam
Hi Martin,

On Mon, Apr 9, 2018 at 5:41 AM, Martin Townsend  wrote:
> Hi,
>
> I'm trying to get to the bottom of an issue I'm seeing when enabling
> the CAAM in the kernel with IMA/EVM enabled.  I'm using the official
> NXP (imx_4.9.11_1.0.0_ga) vendor Kernel.

Does it work better if you try mainline kernel instead?


Re: CAAM and IMA/EVM : caam_rsa_enc: DECO: desc idx 7: Protocol Size Error

2018-04-10 Thread Fabio Estevam
Hi Martin,

On Tue, Apr 10, 2018 at 2:06 PM, Martin Townsend
 wrote:
> Hi Fabio,
>
> On Tue, Apr 10, 2018 at 5:59 PM, Fabio Estevam  wrote:
>> Hi Martin,
>>
>> On Mon, Apr 9, 2018 at 5:41 AM, Martin Townsend  
>> wrote:
>>> Hi,
>>>
>>> I'm trying to get to the bottom of an issue I'm seeing when enabling
>>> the CAAM in the kernel with IMA/EVM enabled.  I'm using the official
>>> NXP (imx_4.9.11_1.0.0_ga) vendor Kernel.
>>
>> Does it work better if you try mainline kernel instead?
>
> I had a few issues getting mainline working, the board kept resetting,

Let's try to fix this reset problem then :-)

> when I checked there are lots of patches in the NXP kernel not in
> mainline.   This CAAM problem does occur really early in the boot so
> just for an experiment its worth a try.

Ok, I just applied this patch that adds CAAM for mx6ull against linux-next:

http://code.bulix.org/rjkzt5-317022

and I see the following issue with cfg80211 certificate, but I do not
get a reset as you reported:

[2.999416] caam_jr 2142000.jr1: 4789: DECO: desc idx 7:
Protocol Size Error - A protocol has seen an error in size. When
running RSA, pdb size N < (size of F) when no formatting is used; or
pdb si
ze N < (F + 11) when formatting is used.
[3.022168] [ cut here ]
[3.027247] WARNING: CPU: 0 PID: 1 at
crypto/asymmetric_keys/public_key.c:148
public_key_verify_signature+0x27c/0x2b0
[3.038075] Modules linked in:
[3.041226] CPU: 0 PID: 1 Comm: swapper/0 Not tainted
4.16.0-next-20180410-2-gf0ccf31-dirty #223
[3.050413] Hardware name: Freescale i.MX6 Ultralite (Device Tree)
[3.056643] Backtrace:
[3.059173] [] (dump_backtrace) from []
(show_stack+0x18/0x1c)
[3.066802]  r7: r6:6153 r5: r4:c107ae78
[3.072523] [] (show_stack) from []
(dump_stack+0xb4/0xe8)
[3.079810] [] (dump_stack) from [] (__warn+0x104/0x130)
[3.086922]  r9:d604dc94 r8:0094 r7:0009 r6:c0d3aea8
r5: r4:
[3.094728] [] (__warn) from []
(warn_slowpath_null+0x44/0x50)
[3.102356]  r8:c1008908 r7:d67846c0 r6:c040bbc4 r5:0094 r4:c0d3aea8
[3.109120] [] (warn_slowpath_null) from []
(public_key_verify_signature+0x27c/0x2b0)
[3.118745]  r6:4789 r5:d6782f00 r4:d6787f40
[3.123428] [] (public_key_verify_signature) from
[] (x509_check_for_self_signed+0xc8/0x104)
[3.133664]  r10:d602f000 r9:c0bcb1d0 r8:02a8 r7:d6787f00
r6:d6787f40 r5:
[3.141543]  r4:d6782d80
[3.144140] [] (x509_check_for_self_signed) from
[] (x509_cert_parse+0x11c/0x190)
[3.153415]  r7:c0bcb1d0 r6:d6787f80 r5:d6782d80 r4:d6787f00
[3.159138] [] (x509_cert_parse) from []
(x509_key_preparse+0x1c/0x194)
[3.167550]  r9:c0bcb1d0 r8:c10235dc r7:d604de30 r6:c1026a84
r5:d604de30 r4:c1026af0
[3.175357] [] (x509_key_preparse) from []
(asymmetric_key_preparse+0x50/0x80)
[3.184376]  r9:c0bcb1d0 r8:c10235dc r7:d604de30 r6:c1026a84
r5:c1008908 r4:c1026af0
[3.192187] [] (asymmetric_key_preparse) from
[] (key_create_or_update+0x138/0x404)
[3.201638]  r7:d6495601 r6:d6495600 r5:c1008908 r4:c1026a8c
[3.207366] [] (key_create_or_update) from []
(regulatory_init_db+0xf4/0x1e8)
[3.216303]  r10:000e r9:1f03 r8:c0d1d144 r7:c17f1e7c
r6:c0bcb478 r5:02a8
[3.224180]  r4:c0bcb1d0
[3.226780] [] (regulatory_init_db) from []
(do_one_initcall+0x50/0x1a4)
[3.235278]  r10:c0f00630 r9:c0f64858 r8:c107cb00 r7:
r6:c0f5a8d0 r5:c1008908
[3.243155]  r4:e000
[3.245753] [] (do_one_initcall) from []
(kernel_init_freeable+0x118/0x1d8)
[3.254512]  r9:c0f64858 r8:00f4 r7:c0e1ec98 r6:c0f64854
r5:c107cb00 r4:c0f78f70
[3.262324] [] (kernel_init_freeable) from []
(kernel_init+0x10/0x118)
[3.270650]  r10: r9: r8: r7:
r6: r5:c0a665a8
[3.278527]  r4:
[3.281127] [] (kernel_init) from []
(ret_from_fork+0x14/0x20)
[3.288749] Exception stack(0xd604dfb0 to 0xd604dff8)
[3.293859] dfa0: 
  
[3.302098] dfc0:     
  
[3.310329] dfe0:     0013 
[3.316993]  r5:c0a665a8 r4:
[3.320825] irq event stamp: 186525
[3.324504] hardirqs last  enabled at (186543): []
console_unlock+0x4d4/0x5c8
[3.332584] hardirqs last disabled at (186550): []
console_unlock+0xc8/0x5c8
[3.340664] softirqs last  enabled at (186566): []
__do_softirq+0x1f8/0x2a0
[3.348665] softirqs last disabled at (186577): []
irq_exit+0x14c/0x1a8
[3.356307] ---[ end trace abf8fdf803902ee1 ]---
[3.361030] cfg80211: Problem loading in-kernel X.509 certificate (-22)
[3.370633] platform regulatory.0: Direct firmware load for
regulatory.db failed wi

[PATCH v2 2/2] crypto: caam - allow retrieving 'era' from register

2018-04-10 Thread Fabio Estevam
From: Fabio Estevam 

The 'era' information can be retrieved from CAAM registers, so
introduce a caam_get_era_from_hw() function that gets it via register
reads in case the 'fsl,sec-era' property is not passed in the device
tree.

This function is based on the U-Boot implementation from
drivers/crypto/fsl/sec.c

Signed-off-by: Fabio Estevam 
---
Changes since v1:
- None. I previously asked to put the linux-crypto list on Cc

 drivers/crypto/caam/ctrl.c | 45 ++---
 drivers/crypto/caam/regs.h |  6 ++
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index bee690a..3f10791 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -396,11 +396,47 @@ static void kick_trng(struct platform_device *pdev, int 
ent_delay)
clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM, RTMCTL_SAMP_MODE_RAW_ES_SC);
 }
 
+static u8 caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl)
+{
+   const struct sec_vid id[] = {
+   {0x0A10, 1, 1},
+   {0x0A10, 2, 2},
+   {0x0A12, 1, 3},
+   {0x0A14, 1, 3},
+   {0x0A14, 2, 4},
+   {0x0A16, 1, 4},
+   {0x0A10, 3, 4},
+   {0x0A11, 1, 4},
+   {0x0A18, 1, 4},
+   {0x0A11, 2, 5},
+   {0x0A12, 2, 5},
+   {0x0A13, 1, 5},
+   {0x0A1C, 1, 5},
+   };
+   int i;
+
+   u32 secvid_ms = rd_reg32(&ctrl->perfmon.caam_id_ms);
+   u32 ccbvid = rd_reg32(&ctrl->perfmon.ccb_id);
+   u16 ip_id = (secvid_ms & SECVID_MS_IPID_MASK) >> SECVID_MS_IPID_SHIFT;
+   u8 maj_rev = (secvid_ms & SECVID_MS_MAJ_REV_MASK) >>
+ SECVID_MS_MAJ_REV_SHIFT;
+   u8 era = (ccbvid & CCBVID_ERA_MASK) >> CCBVID_ERA_SHIFT;
+
+   if (era)/* This is '0' prior to CAAM ERA-6 */
+   return era;
+
+   for (i = 0; i < ARRAY_SIZE(id); i++)
+   if (id[i].ip_id == ip_id && id[i].maj_rev == maj_rev)
+   return id[i].min_rev;
+
+   return 0;
+}
+
 /**
  * caam_get_era() - Return the ERA of the SEC on SoC, based
  * on "sec-era" propery in the DTS. This property is updated by u-boot.
  **/
-static int caam_get_era(void)
+static int caam_get_era(struct caam_ctrl __iomem *ctrl)
 {
struct device_node *caam_node;
int ret;
@@ -410,7 +446,10 @@ static int caam_get_era(void)
ret = of_property_read_u32(caam_node, "fsl,sec-era", &prop);
of_node_put(caam_node);
 
-   return ret ? -ENOTSUPP : prop;
+   if (!ret)
+   return prop;
+   else
+   return caam_get_era_from_hw(ctrl);
 }
 
 static const struct of_device_id caam_match[] = {
@@ -622,7 +661,7 @@ static int caam_probe(struct platform_device *pdev)
goto iounmap_ctrl;
}
 
-   ctrlpriv->era = caam_get_era();
+   ctrlpriv->era = caam_get_era(ctrl);
 
ret = of_platform_populate(nprop, caam_match, NULL, dev);
if (ret) {
diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h
index fee3638..6f96d7b 100644
--- a/drivers/crypto/caam/regs.h
+++ b/drivers/crypto/caam/regs.h
@@ -311,6 +311,12 @@ struct caam_perfmon {
u64 rsvd3;
 
/* Component Instantiation Parameters   fe0-fff */
+#define SECVID_MS_IPID_MASK0x
+#define SECVID_MS_IPID_SHIFT   16
+#define SECVID_MS_MAJ_REV_MASK 0xff00
+#define SECVID_MS_MAJ_REV_SHIFT8
+#define CCBVID_ERA_MASK0xff00
+#define CCBVID_ERA_SHIFT   24
u32 rtic_id;/* RVID - RTIC Version ID   */
u32 ccb_id; /* CCBVID - CCB Version ID  */
u32 cha_id_ms;  /* CHAVID - CHA Version ID Most Significant*/
-- 
2.7.4



[PATCH v2 1/2] crypto: caam - staticize caam_get_era()

2018-04-10 Thread Fabio Estevam
From: Fabio Estevam 

caam_get_era() is only used locally, so do not export this function
and make it static instead.

Signed-off-by: Fabio Estevam 
---
Changes since v1:
- None. I previously asked to put the linux-crypto list on Cc

 drivers/crypto/caam/ctrl.c | 3 +--
 drivers/crypto/caam/ctrl.h | 2 --
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index e4cc636..bee690a 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -400,7 +400,7 @@ static void kick_trng(struct platform_device *pdev, int 
ent_delay)
  * caam_get_era() - Return the ERA of the SEC on SoC, based
  * on "sec-era" propery in the DTS. This property is updated by u-boot.
  **/
-int caam_get_era(void)
+static int caam_get_era(void)
 {
struct device_node *caam_node;
int ret;
@@ -412,7 +412,6 @@ int caam_get_era(void)
 
return ret ? -ENOTSUPP : prop;
 }
-EXPORT_SYMBOL(caam_get_era);
 
 static const struct of_device_id caam_match[] = {
{
diff --git a/drivers/crypto/caam/ctrl.h b/drivers/crypto/caam/ctrl.h
index be693a2..f3ecd67 100644
--- a/drivers/crypto/caam/ctrl.h
+++ b/drivers/crypto/caam/ctrl.h
@@ -9,8 +9,6 @@
 #define CTRL_H
 
 /* Prototypes for backend-level services exposed to APIs */
-int caam_get_era(void);
-
 extern bool caam_dpaa2;
 
 #endif /* CTRL_H */
-- 
2.7.4



Re: [PATCH v2 1/2] crypto: caam - staticize caam_get_era()

2018-04-10 Thread Fabio Estevam
On Tue, Apr 10, 2018 at 10:54 PM, Fabio Estevam  wrote:
> From: Fabio Estevam 
>
> caam_get_era() is only used locally, so do not export this function
> and make it static instead.
>
> Signed-off-by: Fabio Estevam 
> ---
> Changes since v1:
> - None. I previously asked to put the linux-crypto list on Cc

Ops, I meant "None. I previously forgot to put the linux-crypto list on Cc"


Re: CAAM and IMA/EVM : caam_rsa_enc: DECO: desc idx 7: Protocol Size Error

2018-04-10 Thread Fabio Estevam
Hi Martin,

On Tue, Apr 10, 2018 at 7:01 PM, Martin Townsend
 wrote:

> A hexdump of the signature reveals a 0x00 at the start

Yes, same is happening here on my mx6ul evk running linux-next:

[2.990651] cfg80211: Loading compiled-in X.509 certificates for
regulatory database
[2.999046] signature: 00 87 03 da f2 82 c2 dd af 7c 44 2f
86 d3 5f 4c  .|D/.._L
[3.008213] signature0010: 93 48 b9 fe 07 17 bb 21 f7 25 23 4e
aa 22 0c 16  .H.!.%#N."..
[3.017069] signature0020: b9 73 ae 9d 46 7c 75 d9 c3 49 57 47
bf 33 b7 97  .s..F|u..IWG.3..
[3.026064] signature0030: ec f5 40 75 c0 46 22 f0 a0 5d 9c 79
13 a1 ff b8  ..@u.F"..].y
[3.035049] signature0040: a3 2f 7b 8e 06 3f c8 b6 e4 6a 28 f2
34 5c 23 3f  ./{..?...j(.4\#?
[3.043994] signature0050: 32 c0 e6 ad 0f ac cf 55 74 47 73 d3
01 85 b7 0b  2..UtGs.
[3.052941] signature0060: 22 56 24 7d 9f 09 a9 0e 86 9e 37 5b
9c 6d 02 d9  "V$}..7[.m..
[3.061879] signature0070: 8c c8 50 6a e2 59 f3 16 06 ea b2 42
b5 58 fe ba  ..Pj.Y.B.X..
[3.070813] signature0080: d1 81 57 1a ef b2 38 88 58 f6 aa c4
2e 8b 5a 27  ..W...8.X.Z'
[3.079742] signature0090: e4 a5 e8 a4 ca 67 5c ac 72 67 c3 6f
13 c3 2d 35  .g\.rg.o..-5
[3.088669] signature00a0: 79 d7 8a e7 f5 d4 21 30 4a d5 f6 a3
d9 79 56 f2  y.!0JyV.
[3.097512] signature00b0: 0f 10 f7 7d d0 51 93 2f 47 f8 7d 4b
0a 84 55 12  ...}.Q./G.}K..U.
[3.106437] signature00c0: 0a 7d 4e 3b 1f 2b 2f fc 28 b3 69 34
e1 80 80 bb  .}N;.+/.(.i4
[3.115366] signature00d0: e2 af b9 d6 30 f1 1d 54 87 23 99 9f
51 03 4c 45  0..T.#..Q.LE
[3.124292] signature00e0: 7d 02 65 73 ab fd cf 94 cc 0d 3a 60
fd 3c 14 2f  }.es..:`.<./
[3.133238] signature00f0: 16 33 a9 21 1f cb 50 b1 8f 03 ee a0
66 a9 16 79  .3.!..P.f..y
[3.142189] signature0100: 14
.
[3.155013] caam_jr 2142000.jr1: 4789: DECO: desc idx 7:
Protocol Size Error - A protocol has seen an error in size. When
running RSA, pdb size N < (size of F) when no formatting is used; or
pdb si
ze N < (F + 11) when formatting is used.

However, the same kernel running on a mx6 board does not give the
"Protocol Size Error":

[2.654244] cfg80211: Loading compiled-in X.509 certificates for
regulatory database
[2.662221] signature: 00 87 03 da f2 82 c2 dd af 7c 44 2f
86 d3 5f 4c  .|D/.._L
[2.671221] signature0010: 93 48 b9 fe 07 17 bb 21 f7 25 23 4e
aa 22 0c 16  .H.!.%#N."..
[2.680082] signature0020: b9 73 ae 9d 46 7c 75 d9 c3 49 57 47
bf 33 b7 97  .s..F|u..IWG.3..
[2.688893] signature0030: ec f5 40 75 c0 46 22 f0 a0 5d 9c 79
13 a1 ff b8  ..@u.F"..].y
[2.697750] signature0040: a3 2f 7b 8e 06 3f c8 b6 e4 6a 28 f2
34 5c 23 3f  ./{..?...j(.4\#?
[2.706604] signature0050: 32 c0 e6 ad 0f ac cf 55 74 47 73 d3
01 85 b7 0b  2..UtGs.
[2.715460] signature0060: 22 56 24 7d 9f 09 a9 0e 86 9e 37 5b
9c 6d 02 d9  "V$}..7[.m..
[2.724323] signature0070: 8c c8 50 6a e2 59 f3 16 06 ea b2 42
b5 58 fe ba  ..Pj.Y.B.X..
[2.733182] signature0080: d1 81 57 1a ef b2 38 88 58 f6 aa c4
2e 8b 5a 27  ..W...8.X.Z'
[2.742032] signature0090: e4 a5 e8 a4 ca 67 5c ac 72 67 c3 6f
13 c3 2d 35  .g\.rg.o..-5
[2.750883] signature00a0: 79 d7 8a e7 f5 d4 21 30 4a d5 f6 a3
d9 79 56 f2  y.!0JyV.
[2.759737] signature00b0: 0f 10 f7 7d d0 51 93 2f 47 f8 7d 4b
0a 84 55 12  ...}.Q./G.}K..U.
[2.768543] signature00c0: 0a 7d 4e 3b 1f 2b 2f fc 28 b3 69 34
e1 80 80 bb  .}N;.+/.(.i4
[2.777403] signature00d0: e2 af b9 d6 30 f1 1d 54 87 23 99 9f
51 03 4c 45  0..T.#..Q.LE
[2.786259] signature00e0: 7d 02 65 73 ab fd cf 94 cc 0d 3a 60
fd 3c 14 2f  }.es..:`.<./
[2.795110] signature00f0: 16 33 a9 21 1f cb 50 b1 8f 03 ee a0
66 a9 16 79  .3.!..P.f..y
[2.803957] signature0100: 14
.
[2.816788] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[2.824922] platform regulatory.0: Direct firmware load for
regulatory.db failed with error -2
[2.829396] ALSA device list:
[2.833904] cfg80211: failed to load regulatory.db


[PATCH v3 1/2] crypto: caam - staticize caam_get_era()

2018-04-11 Thread Fabio Estevam
From: Fabio Estevam 

caam_get_era() is only used locally, so do not export this function
and make it static instead.

Signed-off-by: Fabio Estevam 
---
Changes since v2:
- None.

 drivers/crypto/caam/ctrl.c | 3 +--
 drivers/crypto/caam/ctrl.h | 2 --
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index e4cc636..bee690a 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -400,7 +400,7 @@ static void kick_trng(struct platform_device *pdev, int 
ent_delay)
  * caam_get_era() - Return the ERA of the SEC on SoC, based
  * on "sec-era" propery in the DTS. This property is updated by u-boot.
  **/
-int caam_get_era(void)
+static int caam_get_era(void)
 {
struct device_node *caam_node;
int ret;
@@ -412,7 +412,6 @@ int caam_get_era(void)
 
return ret ? -ENOTSUPP : prop;
 }
-EXPORT_SYMBOL(caam_get_era);
 
 static const struct of_device_id caam_match[] = {
{
diff --git a/drivers/crypto/caam/ctrl.h b/drivers/crypto/caam/ctrl.h
index be693a2..f3ecd67 100644
--- a/drivers/crypto/caam/ctrl.h
+++ b/drivers/crypto/caam/ctrl.h
@@ -9,8 +9,6 @@
 #define CTRL_H
 
 /* Prototypes for backend-level services exposed to APIs */
-int caam_get_era(void);
-
 extern bool caam_dpaa2;
 
 #endif /* CTRL_H */
-- 
2.7.4



[PATCH v3 2/2] crypto: caam - allow retrieving 'era' from register

2018-04-11 Thread Fabio Estevam
From: Fabio Estevam 

The 'era' information can be retrieved from CAAM registers, so
introduce a caam_get_era_from_hw() function that gets it via register
reads in case the 'fsl,sec-era' property is not passed in the device
tree.

This function is based on the U-Boot implementation from
drivers/crypto/fsl/sec.c

Signed-off-by: Fabio Estevam 
---
Changes since v2:
- Use a local struct for the CAAM era ID
- Only read caam_id_ms only if ccb_id register does not provide era
- Improve comment on caam_get_era()
- Return -ENOTSUPP to keep old behavior
- Put the defines before the relevant fields

 drivers/crypto/caam/ctrl.c | 56 ++
 drivers/crypto/caam/regs.h |  6 +
 2 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index bee690a..ab67e97 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -396,11 +396,56 @@ static void kick_trng(struct platform_device *pdev, int 
ent_delay)
clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM, RTMCTL_SAMP_MODE_RAW_ES_SC);
 }
 
+static int caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl)
+{
+   static const struct {
+   u16 ip_id;
+   u8 maj_rev;
+   u8 era;
+   } id[] = {
+   {0x0A10, 1, 1},
+   {0x0A10, 2, 2},
+   {0x0A12, 1, 3},
+   {0x0A14, 1, 3},
+   {0x0A14, 2, 4},
+   {0x0A16, 1, 4},
+   {0x0A10, 3, 4},
+   {0x0A11, 1, 4},
+   {0x0A18, 1, 4},
+   {0x0A11, 2, 5},
+   {0x0A12, 2, 5},
+   {0x0A13, 1, 5},
+   {0x0A1C, 1, 5}
+   };
+   u32 ccbvid, id_ms;
+   u8 maj_rev,era;
+   u16 ip_id;
+   int i;
+
+   ccbvid = rd_reg32(&ctrl->perfmon.ccb_id);
+   era = (ccbvid & CCBVID_ERA_MASK) >> CCBVID_ERA_SHIFT;
+   if (era)/* This is '0' prior to CAAM ERA-6 */
+   return era;
+
+   id_ms = rd_reg32(&ctrl->perfmon.caam_id_ms);
+   ip_id = (id_ms & SECVID_MS_IPID_MASK) >> SECVID_MS_IPID_SHIFT;
+   maj_rev = (id_ms & SECVID_MS_MAJ_REV_MASK) >> SECVID_MS_MAJ_REV_SHIFT;
+
+   for (i = 0; i < ARRAY_SIZE(id); i++)
+   if (id[i].ip_id == ip_id && id[i].maj_rev == maj_rev)
+   return id[i].era;
+
+   return -ENOTSUPP;
+}
+
 /**
  * caam_get_era() - Return the ERA of the SEC on SoC, based
- * on "sec-era" propery in the DTS. This property is updated by u-boot.
+ * on "sec-era" optional property in the DTS. This property is updated
+ * by u-boot.
+ * In case this property is not passed an attempt to retrieve the CAAM
+ * era via register reads will be made.
  **/
-static int caam_get_era(void)
+static int caam_get_era(struct caam_ctrl __iomem *ctrl)
 {
struct device_node *caam_node;
int ret;
@@ -410,7 +455,10 @@ static int caam_get_era(void)
ret = of_property_read_u32(caam_node, "fsl,sec-era", &prop);
of_node_put(caam_node);
 
-   return ret ? -ENOTSUPP : prop;
+   if (!ret)
+   return prop;
+   else
+   return caam_get_era_from_hw(ctrl);
 }
 
 static const struct of_device_id caam_match[] = {
@@ -622,7 +670,7 @@ static int caam_probe(struct platform_device *pdev)
goto iounmap_ctrl;
}
 
-   ctrlpriv->era = caam_get_era();
+   ctrlpriv->era = caam_get_era(ctrl);
 
ret = of_platform_populate(nprop, caam_match, NULL, dev);
if (ret) {
diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h
index fee3638..4fb91ba 100644
--- a/drivers/crypto/caam/regs.h
+++ b/drivers/crypto/caam/regs.h
@@ -312,11 +312,17 @@ struct caam_perfmon {
 
/* Component Instantiation Parameters   fe0-fff */
u32 rtic_id;/* RVID - RTIC Version ID   */
+#define CCBVID_ERA_MASK0xff00
+#define CCBVID_ERA_SHIFT   24
u32 ccb_id; /* CCBVID - CCB Version ID  */
u32 cha_id_ms;  /* CHAVID - CHA Version ID Most Significant*/
u32 cha_id_ls;  /* CHAVID - CHA Version ID Least Significant*/
u32 cha_num_ms; /* CHANUM - CHA Number Most Significant */
u32 cha_num_ls; /* CHANUM - CHA Number Least Significant*/
+#define SECVID_MS_IPID_MASK0x
+#define SECVID_MS_IPID_SHIFT   16
+#define SECVID_MS_MAJ_REV_MASK 0xff00
+#define SECVID_MS_MAJ_REV_SHIFT8
u32 caam_id_ms; /* CAAMVID - CAAM Version ID MS */
u32 caam_id_ls; /* CAAMVID - CAAM Version ID LS */
 };
-- 
2.7.4



Re: [PATCH v2 2/2] crypto: caam - allow retrieving 'era' from register

2018-04-11 Thread Fabio Estevam
Hi Horia,

On Wed, Apr 11, 2018 at 4:47 AM, Horia Geantă  wrote:

> Have you actually hit a case where the property was missing from DT?

Yes, on imx7s.dtsi it is missing.

I also started adding CAAM support to mx6ul and I did not pass the
""fsl,sec-era"

Thanks for your review.

I addressed all of your comments and sent a v3.


[PATCH v4 1/2] crypto: caam - staticize caam_get_era()

2018-04-11 Thread Fabio Estevam
From: Fabio Estevam 

caam_get_era() is only used locally, so do not export this function
and make it static instead.

Signed-off-by: Fabio Estevam 
Reviewed-by: Horia Geantă 
---
Changes since v3:
- None.

 drivers/crypto/caam/ctrl.c | 3 +--
 drivers/crypto/caam/ctrl.h | 2 --
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index e4cc636..bee690a 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -400,7 +400,7 @@ static void kick_trng(struct platform_device *pdev, int 
ent_delay)
  * caam_get_era() - Return the ERA of the SEC on SoC, based
  * on "sec-era" propery in the DTS. This property is updated by u-boot.
  **/
-int caam_get_era(void)
+static int caam_get_era(void)
 {
struct device_node *caam_node;
int ret;
@@ -412,7 +412,6 @@ int caam_get_era(void)
 
return ret ? -ENOTSUPP : prop;
 }
-EXPORT_SYMBOL(caam_get_era);
 
 static const struct of_device_id caam_match[] = {
{
diff --git a/drivers/crypto/caam/ctrl.h b/drivers/crypto/caam/ctrl.h
index be693a2..f3ecd67 100644
--- a/drivers/crypto/caam/ctrl.h
+++ b/drivers/crypto/caam/ctrl.h
@@ -9,8 +9,6 @@
 #define CTRL_H
 
 /* Prototypes for backend-level services exposed to APIs */
-int caam_get_era(void);
-
 extern bool caam_dpaa2;
 
 #endif /* CTRL_H */
-- 
2.7.4



[PATCH v4 2/2] crypto: caam - allow retrieving 'era' from register

2018-04-11 Thread Fabio Estevam
From: Fabio Estevam 

The 'era' information can be retrieved from CAAM registers, so
introduce a caam_get_era_from_hw() function that gets it via register
reads in case the 'fsl,sec-era' property is not passed in the device
tree.

This function is based on the U-Boot implementation from
drivers/crypto/fsl/sec.c

Signed-off-by: Fabio Estevam 
---
Changes since v3:
- Make checkpatch happy

 drivers/crypto/caam/ctrl.c | 56 ++
 drivers/crypto/caam/regs.h |  6 +
 2 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index bee690a..ab67e97 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -396,11 +396,56 @@ static void kick_trng(struct platform_device *pdev, int 
ent_delay)
clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM, RTMCTL_SAMP_MODE_RAW_ES_SC);
 }
 
+static int caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl)
+{
+   static const struct {
+   u16 ip_id;
+   u8 maj_rev;
+   u8 era;
+   } id[] = {
+   {0x0A10, 1, 1},
+   {0x0A10, 2, 2},
+   {0x0A12, 1, 3},
+   {0x0A14, 1, 3},
+   {0x0A14, 2, 4},
+   {0x0A16, 1, 4},
+   {0x0A10, 3, 4},
+   {0x0A11, 1, 4},
+   {0x0A18, 1, 4},
+   {0x0A11, 2, 5},
+   {0x0A12, 2, 5},
+   {0x0A13, 1, 5},
+   {0x0A1C, 1, 5}
+   };
+   u32 ccbvid, id_ms;
+   u8 maj_rev, era;
+   u16 ip_id;
+   int i;
+
+   ccbvid = rd_reg32(&ctrl->perfmon.ccb_id);
+   era = (ccbvid & CCBVID_ERA_MASK) >> CCBVID_ERA_SHIFT;
+   if (era)/* This is '0' prior to CAAM ERA-6 */
+   return era;
+
+   id_ms = rd_reg32(&ctrl->perfmon.caam_id_ms);
+   ip_id = (id_ms & SECVID_MS_IPID_MASK) >> SECVID_MS_IPID_SHIFT;
+   maj_rev = (id_ms & SECVID_MS_MAJ_REV_MASK) >> SECVID_MS_MAJ_REV_SHIFT;
+
+   for (i = 0; i < ARRAY_SIZE(id); i++)
+   if (id[i].ip_id == ip_id && id[i].maj_rev == maj_rev)
+   return id[i].era;
+
+   return -ENOTSUPP;
+}
+
 /**
  * caam_get_era() - Return the ERA of the SEC on SoC, based
- * on "sec-era" propery in the DTS. This property is updated by u-boot.
+ * on "sec-era" optional property in the DTS. This property is updated
+ * by u-boot.
+ * In case this property is not passed an attempt to retrieve the CAAM
+ * era via register reads will be made.
  **/
-static int caam_get_era(void)
+static int caam_get_era(struct caam_ctrl __iomem *ctrl)
 {
struct device_node *caam_node;
int ret;
@@ -410,7 +455,10 @@ static int caam_get_era(void)
ret = of_property_read_u32(caam_node, "fsl,sec-era", &prop);
of_node_put(caam_node);
 
-   return ret ? -ENOTSUPP : prop;
+   if (!ret)
+   return prop;
+   else
+   return caam_get_era_from_hw(ctrl);
 }
 
 static const struct of_device_id caam_match[] = {
@@ -622,7 +670,7 @@ static int caam_probe(struct platform_device *pdev)
goto iounmap_ctrl;
}
 
-   ctrlpriv->era = caam_get_era();
+   ctrlpriv->era = caam_get_era(ctrl);
 
ret = of_platform_populate(nprop, caam_match, NULL, dev);
if (ret) {
diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h
index fee3638..4fb91ba 100644
--- a/drivers/crypto/caam/regs.h
+++ b/drivers/crypto/caam/regs.h
@@ -312,11 +312,17 @@ struct caam_perfmon {
 
/* Component Instantiation Parameters   fe0-fff */
u32 rtic_id;/* RVID - RTIC Version ID   */
+#define CCBVID_ERA_MASK0xff00
+#define CCBVID_ERA_SHIFT   24
u32 ccb_id; /* CCBVID - CCB Version ID  */
u32 cha_id_ms;  /* CHAVID - CHA Version ID Most Significant*/
u32 cha_id_ls;  /* CHAVID - CHA Version ID Least Significant*/
u32 cha_num_ms; /* CHANUM - CHA Number Most Significant */
u32 cha_num_ls; /* CHANUM - CHA Number Least Significant*/
+#define SECVID_MS_IPID_MASK0x
+#define SECVID_MS_IPID_SHIFT   16
+#define SECVID_MS_MAJ_REV_MASK 0xff00
+#define SECVID_MS_MAJ_REV_SHIFT8
u32 caam_id_ms; /* CAAMVID - CAAM Version ID MS */
u32 caam_id_ls; /* CAAMVID - CAAM Version ID LS */
 };
-- 
2.7.4



Re: CAAM and IMA/EVM : caam_rsa_enc: DECO: desc idx 7: Protocol Size Error

2018-04-11 Thread Fabio Estevam
Hi Horia,

On Wed, Apr 11, 2018 at 7:15 AM, Horia Geantă  wrote:

> You'd want to make sure rsa is offloaded to caam in this case - check in
> /proc/crypto.
> IIRC there are some i.mx parts that don't have support for Public Key
> acceleration (PKHA).

PKHA is present on mx6ul and not present on mx6q.

mx6uq uses the generic rsa driver and handles the certificate correctly.

mx6ul uses pkcs1pad(rsa-caam,sha256) and it fails to handle the certificate.

So that explains the different behavior of mx6q versus mx6ul.

Any ideas as to how to fix rsa-caam?

Thanks


[PATCH] crypto: rsa - Remove unneeded error assignment

2018-04-11 Thread Fabio Estevam
From: Fabio Estevam 

There is no need to assign an error value to 'ret' prior
to calling mpi_read_raw_from_sgl() because in the case
of error the 'ret' variable will be assigned to the error
code inside the if block.

In the case of non failure, 'ret' will be overwritten
immediately after, so remove the unneeded assignment.

Signed-off-by: Fabio Estevam 
---
 crypto/rsa.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/crypto/rsa.c b/crypto/rsa.c
index b067f3a..4167980 100644
--- a/crypto/rsa.c
+++ b/crypto/rsa.c
@@ -215,7 +215,6 @@ static int rsa_verify(struct akcipher_request *req)
goto err_free_m;
}
 
-   ret = -ENOMEM;
s = mpi_read_raw_from_sgl(req->src, req->src_len);
if (!s) {
ret = -ENOMEM;
-- 
2.7.4



Re: CAAM and IMA/EVM : caam_rsa_enc: DECO: desc idx 7: Protocol Size Error

2018-04-12 Thread Fabio Estevam
Hi Horia,

On Thu, Apr 12, 2018 at 4:12 AM, Horia Geantă  wrote:

> Yes, driver needs to strip off leading zeros from input data before feeding it
> to the accelerator.
> I am working at a fix.

I was able to to strip off the leading zeros from input data as you suggested.

My changes are like this at the moment:

diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
index 7a897209..ef9b9c2 100644
--- a/drivers/crypto/caam/caampkc.c
+++ b/drivers/crypto/caam/caampkc.c
@@ -500,6 +500,14 @@ static int set_rsa_priv_f3_pdb(struct
akcipher_request *req,
return -ENOMEM;
 }

+static void caam_rsa_drop_leading_zeros(const u8 **ptr, size_t *nbytes)
+{
+   while (!**ptr && *nbytes) {
+   (*ptr)++;
+   (*nbytes)--;
+   }
+}
+
 static int caam_rsa_enc(struct akcipher_request *req)
 {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
@@ -507,7 +515,10 @@ static int caam_rsa_enc(struct akcipher_request *req)
struct caam_rsa_key *key = &ctx->key;
struct device *jrdev = ctx->dev;
struct rsa_edesc *edesc;
+   void *buffer;
+   const u8 *temp;
int ret;
+   size_t len;

if (unlikely(!key->n || !key->e))
return -EINVAL;
@@ -531,6 +542,46 @@ static int caam_rsa_enc(struct akcipher_request *req)
/* Initialize Job Descriptor */
init_rsa_pub_desc(edesc->hw_desc, &edesc->pdb.pub);

+   buffer = kmalloc(req->src_len, GFP_ATOMIC);
+   if (!buffer)
+   return -ENOMEM;
+
+   temp = kmalloc(req->src_len, GFP_ATOMIC);
+   if (!temp)
+   return -ENOMEM;
+
+   sg_copy_to_buffer(req->src, sg_nents(req->src),
+ buffer, req->src_len);
+
+   temp = (u8 *)buffer;
+   len = req->src_len;
+   if (temp[0] != 0)
+   goto jr_enqueue;
+   else
+   pr_err("*** Leading zero found\n");
+
+   pr_err("*** Original buffer \n");
+   pr_err("* temp[0] = 0x%x\n", temp[0]);
+   pr_err("* temp[1] = 0x%x\n", temp[1]);
+   pr_err("* temp[2] = 0x%x\n", temp[2]);
+   pr_err("* temp[3] = 0x%x\n", temp[3]);
+   pr_err("* Original size: %d\n", req->src_len);
+
+   caam_rsa_drop_leading_zeros(&temp, &len);
+   if (!temp)
+   return -ENOMEM;
+
+   pr_err("*** Buffer after dropping lead zero \n");
+   pr_err("* temp[0] = 0x%x\n", temp[0]);
+   pr_err("* temp[1] = 0x%x\n", temp[1]);
+   pr_err("* temp[2] = 0x%x\n", temp[2]);
+   pr_err("* temp[3] = 0x%x\n", temp[3]);
+
+   req->src_len = req->src_len - 1;
+   pr_err("* Final size: %d\n", req->src_len);
+   sg_copy_from_buffer(req->src, sg_nents(req->src),
+ (void *)temp, req->src_len);
+jr_enqueue:
ret = caam_jr_enqueue(jrdev, edesc->hw_desc, rsa_pub_done, req);
if (!ret)
return -EINPROGRESS;
@@ -683,14 +734,6 @@ static void caam_rsa_free_key(struct caam_rsa_key *key)
memset(key, 0, sizeof(*key));
 }

-static void caam_rsa_drop_leading_zeros(const u8 **ptr, size_t *nbytes)
-{
-   while (!**ptr && *nbytes) {
-   (*ptr)++;
-   (*nbytes)--;
-   }
-}
-
 /**
  * caam_read_rsa_crt - Used for reading dP, dQ, qInv CRT members.
  * dP, dQ and qInv could decode to less than corresponding p, q length, as the

but still get the original error as shown below.

Any ideas?

Thanks

[2.985258] cfg80211: Loading compiled-in X.509 certificates for
regulatory database
[2.998105] *** Leading zero found
[3.002100] *** Original buffer
[3.005734] * temp[0] = 0x0
[3.009147] * temp[1] = 0x87
[3.012440] * temp[2] = 0x3
[3.015634] * temp[3] = 0xda
[3.019036] * Original size: 257
[3.022675] *** Buffer after dropping lead zero
[3.027805] * temp[0] = 0x87
[3.031092] * temp[1] = 0x3
[3.034286] * temp[2] = 0xda
[3.037673] * temp[3] = 0xf2
[3.040960] * Final size: 256
[3.044501] caam_jr 2142000.jr1: 4789: DECO: desc idx 7:
Protocol Size Error - A protocol has seen an error in size. When
running RSA, pdb size N < (size of F) when no formatting is used; or
pdb si
ze N < (F + 11) when formatting is used.
[3.067864] [ cut here ]
[3.072600] WARNING: CPU: 0 PID: 1 at
crypto/asymmetric_keys/public_key.c:148
public_key_verify_signature+0x27c/0x2b0
[3.083390] Modules linked in:
[3.086542] CPU: 0 PID: 1 Comm: swapper/0 Not tainted
4.16.0-next-20180410-5-g5e59986-dirty #323
[3.095726] Hardware name: Freescale i.MX6 Ultralite (Device Tree)
[3.101954] Backtrace:
[3.104482] [] (dump_backtrace) from []
(show_stack+0x18/0x1c)
[3.112113]  r7: r6:6153 r5: r4:c107ae78
[3.117840] [] (show_stack) from []
(dump_stack+0xb4/0xe8)
[3.125126] [] (dump_stack) from [] (__warn+0x104/0x130)

Re: CAAM and IMA/EVM : caam_rsa_enc: DECO: desc idx 7: Protocol Size Error

2018-04-13 Thread Fabio Estevam
Hi Horia,

On Fri, Apr 13, 2018 at 3:18 AM, Horia Geantă  wrote:

> Stripping should happen before set_rsa_pub_pdb() is called since the Protocol
> Data Block contains the input length that is used by the accelerator:
> pdb->f_len = req->src_len;
>
> It should probably be moved at the top of rsa_edesc_alloc().

That did the trick, thanks!

> Ideally stripping would avoid copying data (and memory allocation for 
> temporary
> buffers).

I will try to optimize this aspect and will post a proper patch.

Martin,

Before I try to optimize it, I would like to share the patch
(generated against linux-next) so that you can try it in your IMA
usecase:
http://code.bulix.org/n77z3e-318473

Does it work for you?

Thanks


[PATCH] crypto: caam: Drop leading zero from input buffer

2018-04-14 Thread Fabio Estevam
From: Fabio Estevam 

imx6ul and imx7 report the following error:

caam_jr 2142000.jr1: 4789: DECO: desc idx 7:
Protocol Size Error - A protocol has seen an error in size. When
running RSA, pdb size N < (size of F) when no formatting is used; or
pdb size N < (F + 11) when formatting is used.

[ cut here ]
WARNING: CPU: 0 PID: 1 at crypto/asymmetric_keys/public_key.c:148
public_key_verify_signature+0x27c/0x2b0

This error happens because the signature contains 257 bytes, including
a leading zero as the first element.

Fix the problem by striping off the leading zero from input data
before feeding it to the CAAM accelerator.

Fixes: 8c419778ab57e497b5 ("crypto: caam - add support for RSA algorithm")
Cc: 
Reported-by: Martin Townsend 
Signed-off-by: Fabio Estevam 
---
 drivers/crypto/caam/caampkc.c | 43 +++
 1 file changed, 35 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
index 7a897209..d2ad547 100644
--- a/drivers/crypto/caam/caampkc.c
+++ b/drivers/crypto/caam/caampkc.c
@@ -166,6 +166,14 @@ static void rsa_priv_f3_done(struct device *dev, u32 
*desc, u32 err,
akcipher_request_complete(req, err);
 }
 
+static void caam_rsa_drop_leading_zeros(const u8 **ptr, size_t *nbytes)
+{
+   while (!**ptr && *nbytes) {
+   (*ptr)++;
+   (*nbytes)--;
+   }
+}
+
 static struct rsa_edesc *rsa_edesc_alloc(struct akcipher_request *req,
 size_t desclen)
 {
@@ -178,7 +186,34 @@ static struct rsa_edesc *rsa_edesc_alloc(struct 
akcipher_request *req,
int sgc;
int sec4_sg_index, sec4_sg_len = 0, sec4_sg_bytes;
int src_nents, dst_nents;
+   const u8 *buffer;
+   size_t len;
+
+   buffer = kzalloc(req->src_len, GFP_ATOMIC);
+   if (!buffer)
+   return ERR_PTR(-ENOMEM);
+
+   sg_copy_to_buffer(req->src, sg_nents(req->src),
+ (void *)buffer, req->src_len);
+   len = req->src_len;
 
+   /*
+* Check if the buffer contains leading zero and if
+* it does, drop the leading zero
+*/
+   if (buffer[0] == 0) {
+   caam_rsa_drop_leading_zeros(&buffer, &len);
+   if (!buffer) {
+   kfree(buffer);
+   return ERR_PTR(-ENOMEM);
+   }
+
+   req->src_len -= 1;
+   sg_copy_from_buffer(req->src, sg_nents(req->src),
+   (void *)buffer, req->src_len);
+   }
+
+   kfree(buffer);
src_nents = sg_nents_for_len(req->src, req->src_len);
dst_nents = sg_nents_for_len(req->dst, req->dst_len);
 
@@ -683,14 +718,6 @@ static void caam_rsa_free_key(struct caam_rsa_key *key)
memset(key, 0, sizeof(*key));
 }
 
-static void caam_rsa_drop_leading_zeros(const u8 **ptr, size_t *nbytes)
-{
-   while (!**ptr && *nbytes) {
-   (*ptr)++;
-   (*nbytes)--;
-   }
-}
-
 /**
  * caam_read_rsa_crt - Used for reading dP, dQ, qInv CRT members.
  * dP, dQ and qInv could decode to less than corresponding p, q length, as the
-- 
2.7.4



[PATCH v2] crypto: caam: Drop leading zero from input buffer

2018-04-15 Thread Fabio Estevam
From: Fabio Estevam 

imx6ul and imx7 report the following error:

caam_jr 2142000.jr1: 4789: DECO: desc idx 7:
Protocol Size Error - A protocol has seen an error in size. When
running RSA, pdb size N < (size of F) when no formatting is used; or
pdb size N < (F + 11) when formatting is used.

[ cut here ]
WARNING: CPU: 0 PID: 1 at crypto/asymmetric_keys/public_key.c:148
public_key_verify_signature+0x27c/0x2b0

This error happens because the signature contains 257 bytes, including
a leading zero as the first element.

Fix the problem by stripping off the leading zero from input data
before feeding it to the CAAM accelerator.

Fixes: 8c419778ab57e497b5 ("crypto: caam - add support for RSA algorithm")
Cc: 
Reported-by: Martin Townsend 
Signed-off-by: Fabio Estevam 
---
Changes since v1:
- Use a temp pointer
- Assign len to req->src_len , so that more than one leading zero
can be taken into account

 drivers/crypto/caam/caampkc.c | 45 +++
 1 file changed, 37 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
index 7a897209..5f3e627 100644
--- a/drivers/crypto/caam/caampkc.c
+++ b/drivers/crypto/caam/caampkc.c
@@ -166,6 +166,14 @@ static void rsa_priv_f3_done(struct device *dev, u32 
*desc, u32 err,
akcipher_request_complete(req, err);
 }
 
+static void caam_rsa_drop_leading_zeros(const u8 **ptr, size_t *nbytes)
+{
+   while (!**ptr && *nbytes) {
+   (*ptr)++;
+   (*nbytes)--;
+   }
+}
+
 static struct rsa_edesc *rsa_edesc_alloc(struct akcipher_request *req,
 size_t desclen)
 {
@@ -178,7 +186,36 @@ static struct rsa_edesc *rsa_edesc_alloc(struct 
akcipher_request *req,
int sgc;
int sec4_sg_index, sec4_sg_len = 0, sec4_sg_bytes;
int src_nents, dst_nents;
+   const u8 *temp;
+   void *buffer;
+   size_t len;
+
+   buffer = kzalloc(req->src_len, GFP_ATOMIC);
+   if (!buffer)
+   return ERR_PTR(-ENOMEM);
+
+   sg_copy_to_buffer(req->src, sg_nents(req->src),
+ buffer, req->src_len);
+   temp = (u8 *)buffer;
+   len = req->src_len;
 
+   /*
+* Check if the buffer contains leading zeros and if
+* it does, drop the leading zeros
+*/
+   if (temp[0] == 0) {
+   caam_rsa_drop_leading_zeros(&temp, &len);
+   if (!temp) {
+   kfree(buffer);
+   return ERR_PTR(-ENOMEM);
+   }
+
+   req->src_len = len;
+   sg_copy_from_buffer(req->src, sg_nents(req->src),
+   (void *)temp, req->src_len);
+   }
+
+   kfree(buffer);
src_nents = sg_nents_for_len(req->src, req->src_len);
dst_nents = sg_nents_for_len(req->dst, req->dst_len);
 
@@ -683,14 +720,6 @@ static void caam_rsa_free_key(struct caam_rsa_key *key)
memset(key, 0, sizeof(*key));
 }
 
-static void caam_rsa_drop_leading_zeros(const u8 **ptr, size_t *nbytes)
-{
-   while (!**ptr && *nbytes) {
-   (*ptr)++;
-   (*nbytes)--;
-   }
-}
-
 /**
  * caam_read_rsa_crt - Used for reading dP, dQ, qInv CRT members.
  * dP, dQ and qInv could decode to less than corresponding p, q length, as the
-- 
2.7.4



  1   2   >