crypto: caam: simplify probe resource and IRQ handling
Subsystems (3)
PATCH 1/1 crypto: caam: simplify probe resource and IRQ handling
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.
--- drivers/crypto/caam/jr.c | 46 +++++++++++----------------------------- 1 file changed, 12 insertions(+), 34 deletions(-)
drivers/crypto/caam/jr.c +12 -34
@@ -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 */
Signature · 1 line
2.55.0
Herbert Xu
maintainerQuoted 16 lines · Rosen Penev
Convert the interrupt acquisition from
irq_of_parse_and_map()toplatform_get_irq(), which resolves the IRQ from the device's interrupts property viaof_irq_get(). Flip the error check from testing for zero to testing for a negative errno, and drop the now-unusedcaam_jr_irq_dispose_mapping()callback and itsdevm_add_action_or_reset()cleanup, sinceplatform_get_irq()manages the mapping internally.Replace the open-coded
platform_get_resource()plusdevm_ioremap()sequence withdevm_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
0x10000reg region and interrupts property, so the region reservation added bydevm_ioremap_resource()is exclusive and does not introduce overlap failures.
Quoted 5 lines
Assisted-by opencode:hy3-freeSigned-off-by Rosen Penev <[email protected]>--- 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,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerQuoted 16 lines · Rosen Penev
Convert the interrupt acquisition from
irq_of_parse_and_map()toplatform_get_irq(), which resolves the IRQ from the device's interrupts property viaof_irq_get(). Flip the error check from testing for zero to testing for a negative errno, and drop the now-unusedcaam_jr_irq_dispose_mapping()callback and itsdevm_add_action_or_reset()cleanup, sinceplatform_get_irq()manages the mapping internally.Replace the open-coded
platform_get_resource()plusdevm_ioremap()sequence withdevm_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
0x10000reg region and interrupts property, so the region reservation added bydevm_ioremap_resource()is exclusive and does not introduce overlap failures.
Quoted 5 lines
Assisted-by opencode:hy3-freeSigned-off-by Rosen Penev <[email protected]>--- drivers/crypto/caam/jr.c | 46 +++++++++++----------------------------- 1 file changed, 12 insertions(+), 34 deletions(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 8 lines · Rosen Penev
Replace the open-coded
platform_get_resource()plusdevm_ioremap()sequence withdevm_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
0x10000reg region and interrupts property, so the region reservation added bydevm_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
Quoted 6 lines · Emanuele Ghidoli
Quoted 4 lines · Rosen Penev
Replace the open-coded
platform_get_resource()plusdevm_ioremap()sequence withdevm_platform_ioremap_resource(), which fetches the resource, requests the region and maps it in one call.
Quoted 8 lines
Quoted 4 lines
Each fsl,sec-*-job-ring node has a distinct
0x10000reg region and interrupts property, so the region reservation added bydevm_ioremap_resource()is exclusive and does not introduce overlap failures.This patch, now commit
9a955c0a7d11in 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.
Quoted 26 lines
caam_jr30902000.jr: error-EBUSY: can't request region for resource [mem 0x30902000-0x30902fff]caam_jr30902000.jr: probe with drivercaam_jrfailed with error -16
caam_jr30903000.jr: error-EBUSY: can't request region for resource [mem 0x30903000-0x30903fff]caam_jr30903000.jr: probe with drivercaam_jrfailed with error -16The 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 viadevm_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-imx8mpReverting
9a955c0a7d11on colibri-imx7 makes the errors disappear.#regzbot introduced:
9a955c0a7d11Thanks,
Emanuele