mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: caam: simplify probe resource and IRQ handling
@ 2026-07-30 20:47 Rosen Penev
  2026-08-10  8:07 ` Herbert Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Rosen Penev @ 2026-07-30 20:47 UTC (permalink / raw)
  To: linux-crypto
  Cc: Horia Geantă,
	Pankaj Gupta, Gaurav Jain, Herbert Xu, David S. Miller,
	open list

Convert the interrupt acquisition from irq_of_parse_and_map() to
platform_get_irq(), which resolves the IRQ from the device's interrupts
property via of_irq_get(). Flip the error check from testing for zero to
testing for a negative errno, and drop the now-unused
caam_jr_irq_dispose_mapping() callback and its devm_add_action_or_reset()
cleanup, since platform_get_irq() manages the mapping internally.

Replace the open-coded platform_get_resource() plus devm_ioremap()
sequence with devm_platform_ioremap_resource(), which fetches the
resource, requests the region and maps it in one call.

Each fsl,sec-*-job-ring node has a distinct 0x10000 reg region and
interrupts property, so the region reservation added by
devm_ioremap_resource() is exclusive and does not introduce overlap
failures.

Assisted-by: opencode:hy3-free
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/crypto/caam/jr.c | 46 +++++++++++-----------------------------
 1 file changed, 12 insertions(+), 34 deletions(-)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index bddeaaaca487..239469f6882e 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -574,23 +574,25 @@ static int caam_jr_init(struct device *dev)
 	return error;
 }
 
-static void caam_jr_irq_dispose_mapping(void *data)
-{
-	irq_dispose_mapping((unsigned long)data);
-}
-
 /*
  * Probe routine for each detected JobR subsystem.
  */
 static int caam_jr_probe(struct platform_device *pdev)
 {
 	struct device *jrdev;
-	struct device_node *nprop;
-	struct caam_job_ring __iomem *ctrl;
 	struct caam_drv_private_jr *jrpriv;
 	static int total_jobrs;
-	struct resource *r;
+	void __iomem *ctrl;
 	int error;
+	int irq;
+
+	ctrl = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(ctrl))
+		return PTR_ERR(ctrl);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
 
 	jrdev = &pdev->dev;
 	jrpriv = devm_kzalloc(jrdev, sizeof(*jrpriv), GFP_KERNEL);
@@ -602,22 +604,7 @@ static int caam_jr_probe(struct platform_device *pdev)
 	/* save ring identity relative to detection */
 	jrpriv->ridx = total_jobrs++;
 
-	nprop = pdev->dev.of_node;
-	/* Get configuration properties from device tree */
-	/* First, get register page */
-	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));
-	if (!ctrl) {
-		dev_err(jrdev, "devm_ioremap() failed\n");
-		return -ENOMEM;
-	}
-
-	jrpriv->rregs = (struct caam_job_ring __iomem __force *)ctrl;
+	jrpriv->rregs = ctrl;
 
 	error = dma_set_mask_and_coherent(jrdev, caam_get_dma_mask(jrdev));
 	if (error) {
@@ -647,16 +634,7 @@ static int caam_jr_probe(struct platform_device *pdev)
 	}
 
 	/* Identify the interrupt */
-	jrpriv->irq = irq_of_parse_and_map(nprop, 0);
-	if (!jrpriv->irq) {
-		dev_err(jrdev, "irq_of_parse_and_map failed\n");
-		return -EINVAL;
-	}
-
-	error = devm_add_action_or_reset(jrdev, caam_jr_irq_dispose_mapping,
-					 (void *)(unsigned long)jrpriv->irq);
-	if (error)
-		return error;
+	jrpriv->irq = irq;
 
 	/* Now do the platform independent part */
 	error = caam_jr_init(jrdev); /* now turn on hardware */
-- 
2.55.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: caam: simplify probe resource and IRQ handling
  2026-07-30 20:47 [PATCH] crypto: caam: simplify probe resource and IRQ handling Rosen Penev
@ 2026-08-10  8:07 ` Herbert Xu
  2026-08-10  8:33 ` Herbert Xu
  2026-09-01 19:45 ` Emanuele Ghidoli
  2 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2026-08-10  8:07 UTC (permalink / raw)
  To: Rosen Penev
  Cc: linux-crypto, Horia Geantă,
	Pankaj Gupta, Gaurav Jain, David S. Miller, open list

On Thu, Jul 30, 2026 at 01:47:22PM -0700, Rosen Penev wrote:
> Convert the interrupt acquisition from irq_of_parse_and_map() to
> platform_get_irq(), which resolves the IRQ from the device's interrupts
> property via of_irq_get(). Flip the error check from testing for zero to
> testing for a negative errno, and drop the now-unused
> caam_jr_irq_dispose_mapping() callback and its devm_add_action_or_reset()
> cleanup, since platform_get_irq() manages the mapping internally.
> 
> Replace the open-coded platform_get_resource() plus devm_ioremap()
> sequence with devm_platform_ioremap_resource(), which fetches the
> resource, requests the region and maps it in one call.
> 
> Each fsl,sec-*-job-ring node has a distinct 0x10000 reg region and
> interrupts property, so the region reservation added by
> devm_ioremap_resource() is exclusive and does not introduce overlap
> failures.
> 
> Assisted-by: opencode:hy3-free
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/crypto/caam/jr.c | 46 +++++++++++-----------------------------
>  1 file changed, 12 insertions(+), 34 deletions(-)

Please check the Sashiko comments on this patch:

https://sashiko.dev/#/patchset/20260730204915.1102403-1-rosenp%40gmail.com

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: caam: simplify probe resource and IRQ handling
  2026-07-30 20:47 [PATCH] crypto: caam: simplify probe resource and IRQ handling Rosen Penev
  2026-08-10  8:07 ` Herbert Xu
@ 2026-08-10  8:33 ` Herbert Xu
  2026-09-01 19:45 ` Emanuele Ghidoli
  2 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2026-08-10  8:33 UTC (permalink / raw)
  To: Rosen Penev
  Cc: linux-crypto, Horia Geantă,
	Pankaj Gupta, Gaurav Jain, David S. Miller, open list

On Thu, Jul 30, 2026 at 01:47:22PM -0700, Rosen Penev wrote:
> Convert the interrupt acquisition from irq_of_parse_and_map() to
> platform_get_irq(), which resolves the IRQ from the device's interrupts
> property via of_irq_get(). Flip the error check from testing for zero to
> testing for a negative errno, and drop the now-unused
> caam_jr_irq_dispose_mapping() callback and its devm_add_action_or_reset()
> cleanup, since platform_get_irq() manages the mapping internally.
> 
> Replace the open-coded platform_get_resource() plus devm_ioremap()
> sequence with devm_platform_ioremap_resource(), which fetches the
> resource, requests the region and maps it in one call.
> 
> Each fsl,sec-*-job-ring node has a distinct 0x10000 reg region and
> interrupts property, so the region reservation added by
> devm_ioremap_resource() is exclusive and does not introduce overlap
> failures.
> 
> Assisted-by: opencode:hy3-free
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/crypto/caam/jr.c | 46 +++++++++++-----------------------------
>  1 file changed, 12 insertions(+), 34 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: caam: simplify probe resource and IRQ handling
  2026-07-30 20:47 [PATCH] crypto: caam: simplify probe resource and IRQ handling Rosen Penev
  2026-08-10  8:07 ` Herbert Xu
  2026-08-10  8:33 ` Herbert Xu
@ 2026-09-01 19:45 ` Emanuele Ghidoli
  2026-09-01 20:39   ` Rosen Penev
  2 siblings, 1 reply; 5+ messages in thread
From: Emanuele Ghidoli @ 2026-09-01 19:45 UTC (permalink / raw)
  To: Rosen Penev, Herbert Xu
  Cc: Horia Geantă,
	Pankaj Gupta, Gaurav Jain, David S. Miller, linux-crypto,
	linux-kernel, regressions, Emanuele Ghidoli

On Thu, Jul 30, 2026 at 01:47:22PM -0700, Rosen Penev wrote:
> Replace the open-coded platform_get_resource() plus devm_ioremap()
> sequence with devm_platform_ioremap_resource(), which fetches the
> resource, requests the region and maps it in one call.
>
> Each fsl,sec-*-job-ring node has a distinct 0x10000 reg region and
> interrupts property, so the region reservation added by
> devm_ioremap_resource() is exclusive and does not introduce overlap
> failures.

This patch, now commit 9a955c0a7d11 in v7.3-rc1, breaks CAAM on most i.MX
SoCs (i.MX6, i.MX7, i.MX8). All job rings fail to probe and the machine
loses its hardware RNG:

  caam_jr 30902000.jr: error -EBUSY: can't request region for resource [mem 0x30902000-0x30902fff]
  caam_jr 30902000.jr: probe with driver caam_jr failed with error -16
  caam_jr 30903000.jr: error -EBUSY: can't request region for resource [mem 0x30903000-0x30903fff]
  caam_jr 30903000.jr: probe with driver caam_jr failed with error -16

The job rings do not overlap each other, but they all sit inside the reg
window of their parent fsl,sec-v4.0 node, which caam_probe() already
reserves exclusively via devm_of_iomap() before it populates the children.
So each job ring now collides with its own parent.

Seen on these boards (CI/CD):
 - apalis-imx6
 - apalis-imx8
 - colibri-imx6
 - colibri-imx7
 - colibri-imx8
 - verdin-imx8mm
 - verdin-imx8mp

Reverting 9a955c0a7d11 on colibri-imx7 makes the errors disappear.

#regzbot introduced: 9a955c0a7d11

Thanks,
Emanuele

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: caam: simplify probe resource and IRQ handling
  2026-09-01 19:45 ` Emanuele Ghidoli
@ 2026-09-01 20:39   ` Rosen Penev
  0 siblings, 0 replies; 5+ messages in thread
From: Rosen Penev @ 2026-09-01 20:39 UTC (permalink / raw)
  To: Emanuele Ghidoli
  Cc: Herbert Xu, Horia Geantă,
	Pankaj Gupta, Gaurav Jain, David S. Miller, linux-crypto,
	linux-kernel, regressions, Emanuele Ghidoli

On Tue, Sep 1, 2026 at 12:45 PM Emanuele Ghidoli
<ghidoliemanuele@gmail.com> wrote:
>
> On Thu, Jul 30, 2026 at 01:47:22PM -0700, Rosen Penev wrote:
> > Replace the open-coded platform_get_resource() plus devm_ioremap()
> > sequence with devm_platform_ioremap_resource(), which fetches the
> > resource, requests the region and maps it in one call.
> >
> > Each fsl,sec-*-job-ring node has a distinct 0x10000 reg region and
> > interrupts property, so the region reservation added by
> > devm_ioremap_resource() is exclusive and does not introduce overlap
> > failures.
>
> This patch, now commit 9a955c0a7d11 in v7.3-rc1, breaks CAAM on most i.MX
> SoCs (i.MX6, i.MX7, i.MX8). All job rings fail to probe and the machine
> loses its hardware RNG:
Sent fix.
>
>   caam_jr 30902000.jr: error -EBUSY: can't request region for resource [mem 0x30902000-0x30902fff]
>   caam_jr 30902000.jr: probe with driver caam_jr failed with error -16
>   caam_jr 30903000.jr: error -EBUSY: can't request region for resource [mem 0x30903000-0x30903fff]
>   caam_jr 30903000.jr: probe with driver caam_jr failed with error -16
>
> The job rings do not overlap each other, but they all sit inside the reg
> window of their parent fsl,sec-v4.0 node, which caam_probe() already
> reserves exclusively via devm_of_iomap() before it populates the children.
> So each job ring now collides with its own parent.
>
> Seen on these boards (CI/CD):
>  - apalis-imx6
>  - apalis-imx8
>  - colibri-imx6
>  - colibri-imx7
>  - colibri-imx8
>  - verdin-imx8mm
>  - verdin-imx8mp
>
> Reverting 9a955c0a7d11 on colibri-imx7 makes the errors disappear.
>
> #regzbot introduced: 9a955c0a7d11
>
> Thanks,
> Emanuele

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-01 20:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-30 20:47 [PATCH] crypto: caam: simplify probe resource and IRQ handling Rosen Penev
2026-08-10  8:07 ` Herbert Xu
2026-08-10  8:33 ` Herbert Xu
2026-09-01 19:45 ` Emanuele Ghidoli
2026-09-01 20:39   ` Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®