2021-05-19 20:11:02

by Bhupesh Sharma

[permalink] [raw]
Subject: [PATCH v3 16/17] crypto: qce: Defer probing if BAM dma channel is not yet initialized

Since the Qualcomm qce crypto driver needs the BAM dma driver to be
setup first (to allow crypto operations), it makes sense to defer
the qce crypto driver probing in case the BAM dma driver is not yet
probed.

Move the code leg requesting dma channels earlier in the
probe() flow. This fixes the qce probe failure issues when both qce
and BMA dma are compiled as static part of the kernel.

Cc: Thara Gopinath <[email protected]>
Cc: Bjorn Andersson <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Andy Gross <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Stephen Boyd <[email protected]>
Cc: Michael Turquette <[email protected]>
Cc: Vinod Koul <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Bhupesh Sharma <[email protected]>
---
drivers/crypto/qce/core.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/qce/core.c b/drivers/crypto/qce/core.c
index 8b3e2b4580c2..207221d5b996 100644
--- a/drivers/crypto/qce/core.c
+++ b/drivers/crypto/qce/core.c
@@ -218,6 +218,14 @@ static int qce_crypto_probe(struct platform_device *pdev)
if (ret < 0)
goto err_out;

+ /* qce driver requires BAM dma driver to be setup first.
+ * In case the dma channel are not set yet, this check
+ * helps use to return -EPROBE_DEFER earlier.
+ */
+ ret = qce_dma_request(qce->dev, &qce->dma);
+ if (ret)
+ return ret;
+
qce->mem_path = devm_of_icc_get(qce->dev, "memory");
if (IS_ERR(qce->mem_path))
return dev_err_probe(dev, PTR_ERR(qce->mem_path),
@@ -269,10 +277,6 @@ static int qce_crypto_probe(struct platform_device *pdev)
goto err_clks_iface;
}

- ret = qce_dma_request(qce->dev, &qce->dma);
- if (ret)
- goto err_clks;
-
ret = qce_check_version(qce);
if (ret)
goto err_clks;
@@ -287,12 +291,10 @@ static int qce_crypto_probe(struct platform_device *pdev)

ret = qce_register_algs(qce);
if (ret)
- goto err_dma;
+ goto err_clks;

return 0;

-err_dma:
- qce_dma_release(&qce->dma);
err_clks:
clk_disable_unprepare(qce->bus);
err_clks_iface:
--
2.31.1



2021-05-21 09:10:35

by Thara Gopinath

[permalink] [raw]
Subject: Re: [PATCH v3 16/17] crypto: qce: Defer probing if BAM dma channel is not yet initialized



On 5/19/21 10:36 AM, Bhupesh Sharma wrote:
> Since the Qualcomm qce crypto driver needs the BAM dma driver to be
> setup first (to allow crypto operations), it makes sense to defer
> the qce crypto driver probing in case the BAM dma driver is not yet
> probed.
>
> Move the code leg requesting dma channels earlier in the
> probe() flow. This fixes the qce probe failure issues when both qce
> and BMA dma are compiled as static part of the kernel.

So, I do not understand what issue you faced with the current code
ordering. When bam dma is not initialized, qce_dma_request will fail and
rest the error path kicks in.
To me the correct ordering for enabling a driver is to turn on clocks
and interconnect before requesting for dma. Unless, there is a specific
issue, I will ask for that order to be maintained.

Warm Regards
Thara

>
> Cc: Thara Gopinath <[email protected]>
> Cc: Bjorn Andersson <[email protected]>
> Cc: Rob Herring <[email protected]>
> Cc: Andy Gross <[email protected]>
> Cc: Herbert Xu <[email protected]>
> Cc: David S. Miller <[email protected]>
> Cc: Stephen Boyd <[email protected]>
> Cc: Michael Turquette <[email protected]>
> Cc: Vinod Koul <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Bhupesh Sharma <[email protected]>
> ---
> drivers/crypto/qce/core.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/crypto/qce/core.c b/drivers/crypto/qce/core.c
> index 8b3e2b4580c2..207221d5b996 100644
> --- a/drivers/crypto/qce/core.c
> +++ b/drivers/crypto/qce/core.c
> @@ -218,6 +218,14 @@ static int qce_crypto_probe(struct platform_device *pdev)
> if (ret < 0)
> goto err_out;
>
> + /* qce driver requires BAM dma driver to be setup first.
> + * In case the dma channel are not set yet, this check
> + * helps use to return -EPROBE_DEFER earlier.
> + */
> + ret = qce_dma_request(qce->dev, &qce->dma);
> + if (ret)
> + return ret;
> +
> qce->mem_path = devm_of_icc_get(qce->dev, "memory");
> if (IS_ERR(qce->mem_path))
> return dev_err_probe(dev, PTR_ERR(qce->mem_path),
> @@ -269,10 +277,6 @@ static int qce_crypto_probe(struct platform_device *pdev)
> goto err_clks_iface;
> }
>
> - ret = qce_dma_request(qce->dev, &qce->dma);
> - if (ret)
> - goto err_clks;
> -
> ret = qce_check_version(qce);
> if (ret)
> goto err_clks;
> @@ -287,12 +291,10 @@ static int qce_crypto_probe(struct platform_device *pdev)
>
> ret = qce_register_algs(qce);
> if (ret)
> - goto err_dma;
> + goto err_clks;
>
> return 0;
>
> -err_dma:
> - qce_dma_release(&qce->dma);
> err_clks:
> clk_disable_unprepare(qce->bus);
> err_clks_iface:
>


2021-06-05 08:31:29

by Bhupesh Sharma

[permalink] [raw]
Subject: Re: [PATCH v3 16/17] crypto: qce: Defer probing if BAM dma channel is not yet initialized

Hi Thara,

Thanks for the review and sorry for the late reply.

On Fri, 21 May 2021 at 07:27, Thara Gopinath <[email protected]> wrote:
>
>
>
> On 5/19/21 10:36 AM, Bhupesh Sharma wrote:
> > Since the Qualcomm qce crypto driver needs the BAM dma driver to be
> > setup first (to allow crypto operations), it makes sense to defer
> > the qce crypto driver probing in case the BAM dma driver is not yet
> > probed.
> >
> > Move the code leg requesting dma channels earlier in the
> > probe() flow. This fixes the qce probe failure issues when both qce
> > and BMA dma are compiled as static part of the kernel.
>
> So, I do not understand what issue you faced with the current code
> ordering. When bam dma is not initialized, qce_dma_request will fail and
> rest the error path kicks in.
> To me the correct ordering for enabling a driver is to turn on clocks
> and interconnect before requesting for dma. Unless, there is a specific
> issue, I will ask for that order to be maintained.

Sure. The problem I faced was the following. Let's consider the
scenario where while the qce crypto driver and the interconnect are
compiled as static parts of the kernel, the bam DMA driver is compiled
as a module, then the -EPROBE_DEFER return leg from the qce crypto
driver is very late in the probe() flow, as we first turn on the
clocks and then the interconnect.

Now the suggested linux deferred probe implementation is to return as
early from the caling driver in case the called driver (subdev) is not
yet ready. SInce the qce crypto driver requires the bam DMA to be set
up first, it makes sense to move 'qce_dma_request' early in the boot
flow. If it's not yet probed(), it probably doesn't make sense to set
up the clks and interconnects yet in the qce driver. We can do it
later when the bam DMA is setup.

I have tested the following combinations with the change I made in
this patchset:

1. qce - static, bam - module, interconnect - module ->
qce_dma_request returned -EPROBE_DEFER
2. qce - static, bam - module, interconnect - static ->
qce_dma_request returned -EPROBE_DEFER
3. qce - static, bam - static, interconnect - module ->
qce_dma_request returned -EPROBE_DEFER
4. qce - static, bam - static, interconnect - static -> no -EPROBE_DEFER

Thanks,
Bhupesh

> > Cc: Thara Gopinath <[email protected]>
> > Cc: Bjorn Andersson <[email protected]>
> > Cc: Rob Herring <[email protected]>
> > Cc: Andy Gross <[email protected]>
> > Cc: Herbert Xu <[email protected]>
> > Cc: David S. Miller <[email protected]>
> > Cc: Stephen Boyd <[email protected]>
> > Cc: Michael Turquette <[email protected]>
> > Cc: Vinod Koul <[email protected]>
> > Cc: [email protected]
> > Cc: [email protected]
> > Cc: [email protected]
> > Cc: [email protected]
> > Cc: [email protected]
> > Cc: [email protected]
> > Signed-off-by: Bhupesh Sharma <[email protected]>
> > ---
> > drivers/crypto/qce/core.c | 16 +++++++++-------
> > 1 file changed, 9 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/crypto/qce/core.c b/drivers/crypto/qce/core.c
> > index 8b3e2b4580c2..207221d5b996 100644
> > --- a/drivers/crypto/qce/core.c
> > +++ b/drivers/crypto/qce/core.c
> > @@ -218,6 +218,14 @@ static int qce_crypto_probe(struct platform_device *pdev)
> > if (ret < 0)
> > goto err_out;
> >
> > + /* qce driver requires BAM dma driver to be setup first.
> > + * In case the dma channel are not set yet, this check
> > + * helps use to return -EPROBE_DEFER earlier.
> > + */
> > + ret = qce_dma_request(qce->dev, &qce->dma);
> > + if (ret)
> > + return ret;
> > +
> > qce->mem_path = devm_of_icc_get(qce->dev, "memory");
> > if (IS_ERR(qce->mem_path))
> > return dev_err_probe(dev, PTR_ERR(qce->mem_path),
> > @@ -269,10 +277,6 @@ static int qce_crypto_probe(struct platform_device *pdev)
> > goto err_clks_iface;
> > }
> >
> > - ret = qce_dma_request(qce->dev, &qce->dma);
> > - if (ret)
> > - goto err_clks;
> > -
> > ret = qce_check_version(qce);
> > if (ret)
> > goto err_clks;
> > @@ -287,12 +291,10 @@ static int qce_crypto_probe(struct platform_device *pdev)
> >
> > ret = qce_register_algs(qce);
> > if (ret)
> > - goto err_dma;
> > + goto err_clks;
> >
> > return 0;
> >
> > -err_dma:
> > - qce_dma_release(&qce->dma);
> > err_clks:
> > clk_disable_unprepare(qce->bus);
> > err_clks_iface:
> >
>
>