mbox series

[v4,0/7] Add dedicated Qcom ICE driver

Message ID 20230327134734.3256974-1-abel.vesa@linaro.org
Headers show
Series Add dedicated Qcom ICE driver | expand

Message

Abel Vesa March 27, 2023, 1:47 p.m. UTC
As both SDCC and UFS drivers use the ICE with duplicated implementation,
while none of the currently supported platforms make use concomitantly
of the same ICE IP block instance, the new SM8550 allows both UFS and
SDCC to do so. In order to support such scenario, there is a need for
a unified implementation and a devicetree node to be shared between
both types of storage devices. So lets drop the duplicate implementation
of the ICE from both SDCC and UFS and make it a dedicated (soc) driver.
Also, switch all UFS and SDCC devicetree nodes to use the new ICE
approach.

See each individual patch for changelogs.

The v3 is here:
https://lore.kernel.org/all/20230313115202.3960700-1-abel.vesa@linaro.org/

Abel Vesa (7):
  dt-bindings: crypto: Add Qualcomm Inline Crypto Engine
  dt-bindings: mmc: sdhci-msm: Add ICE phandle
  dt-bindings: ufs: qcom: Add ICE phandle
  soc: qcom: Make the Qualcomm UFS/SDCC ICE a dedicated driver
  scsi: ufs: ufs-qcom: Switch to the new ICE API
  mmc: sdhci-msm: Switch to the new ICE API
  arm64: dts: qcom: sm8550: Add the Inline Crypto Engine node

 .../crypto/qcom,inline-crypto-engine.yaml     |  42 +++
 .../devicetree/bindings/mmc/sdhci-msm.yaml    |   4 +
 .../devicetree/bindings/ufs/qcom,ufs.yaml     |   4 +
 arch/arm64/boot/dts/qcom/sm8550.dtsi          |  10 +
 drivers/mmc/host/Kconfig                      |   2 +-
 drivers/mmc/host/sdhci-msm.c                  | 220 +++--------
 drivers/soc/qcom/Kconfig                      |   4 +
 drivers/soc/qcom/Makefile                     |   1 +
 drivers/soc/qcom/ice.c                        | 342 ++++++++++++++++++
 drivers/ufs/host/Kconfig                      |   2 +-
 drivers/ufs/host/Makefile                     |   4 +-
 drivers/ufs/host/ufs-qcom-ice.c               | 244 -------------
 drivers/ufs/host/ufs-qcom.c                   |  95 ++++-
 drivers/ufs/host/ufs-qcom.h                   |  32 +-
 include/soc/qcom/ice.h                        |  37 ++
 15 files changed, 591 insertions(+), 452 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/crypto/qcom,inline-crypto-engine.yaml
 create mode 100644 drivers/soc/qcom/ice.c
 delete mode 100644 drivers/ufs/host/ufs-qcom-ice.c
 create mode 100644 include/soc/qcom/ice.h

Comments

Krzysztof Kozlowski March 27, 2023, 2:45 p.m. UTC | #1
On 27/03/2023 15:47, Abel Vesa wrote:
> Starting with SM8550, the ICE will have its own devicetree node
> so add the qcom,ice property to reference it.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
> 
> The v3 (RFC) is here:
> https://lore.kernel.org/all/20230313115202.3960700-4-abel.vesa@linaro.org/
> 
> Changes since v3:
>  * dropped the "and drop core clock" part from subject line
> 
> Changes since v2:
>  * dropped all changes except the qcom,ice property
> 
>  Documentation/devicetree/bindings/ufs/qcom,ufs.yaml | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/ufs/qcom,ufs.yaml b/Documentation/devicetree/bindings/ufs/qcom,ufs.yaml
> index c5a06c048389..7384300c421d 100644
> --- a/Documentation/devicetree/bindings/ufs/qcom,ufs.yaml
> +++ b/Documentation/devicetree/bindings/ufs/qcom,ufs.yaml
> @@ -70,6 +70,10 @@ properties:
>    power-domains:
>      maxItems: 1
>  
> +  qcom,ice:
> +    $ref: /schemas/types.yaml#/definitions/phandle
> +    description: phandle to the Inline Crypto Engine node

Didn't we discuss to disallow the ICE IO space if this is provided? Same
for previous patch actually...

Best regards,
Krzysztof
Eric Biggers March 27, 2023, 5:52 p.m. UTC | #2
On Mon, Mar 27, 2023 at 04:47:29PM +0300, Abel Vesa wrote:
> Starting with SM8550, the ICE will have its own devicetree node
> so add the qcom,ice property to reference it.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
> 
> The v3 (RFC) is here:
> https://lore.kernel.org/all/20230313115202.3960700-3-abel.vesa@linaro.org/
> 
> Changes since v3:
>  * dropped the "and drop core clock" part from subject line
> 
> Changes since v2:
>  * dropped all changes except the qcom,ice property
> 
>  Documentation/devicetree/bindings/mmc/sdhci-msm.yaml | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/mmc/sdhci-msm.yaml b/Documentation/devicetree/bindings/mmc/sdhci-msm.yaml
> index 64df6919abaf..0ad14d5b722e 100644
> --- a/Documentation/devicetree/bindings/mmc/sdhci-msm.yaml
> +++ b/Documentation/devicetree/bindings/mmc/sdhci-msm.yaml
> @@ -120,6 +120,10 @@ properties:
>      $ref: /schemas/types.yaml#/definitions/uint32
>      description: platform specific settings for DLL_CONFIG reg.
>  
> +  qcom,ice:
> +    $ref: /schemas/types.yaml#/definitions/phandle
> +    description: phandle to the Inline Crypto Engine node
> +

It would be helpful if the description was more detailed and explained that this
is a replacement for the directly specified reg and clock.

Otherwise, looks good to me.

Reviewed-by: Eric Biggers <ebiggers@google.com>

- Eric
Eric Biggers March 27, 2023, 6:19 p.m. UTC | #3
Hi Abel,

On Mon, Mar 27, 2023 at 04:47:32PM +0300, Abel Vesa wrote:
> Now that there is a new dedicated ICE driver, drop the ufs-qcom-ice and
> use the new ICE api provided by the Qualcomm soc driver ice. The platforms
> that already have ICE support will use the API as library since there will
> not be a devicetree node, but instead they have reg range. In this case,
> the of_qcom_ice_get will return an ICE instance created for the consumer's
> device. But if there are platforms that do not have ice reg in the
> consumer devicetree node and instead provide a dedicated ICE devicetree
> node, the of_qcom_ice_get will look up the device based on qcom,ice
> property and will get the ICE instance registered by the probe function
> of the ice driver.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>

I am still worried about the ICE clock.  Are you sure it is being managed
correctly?  With your patch, the ICE clock gets enabled in ufs_qcom_ice_resume
and disabled in ufs_qcom_ice_suspend, which hopefully pair up.  But it also gets
enabled in ufs_qcom_ice_enable which isn't paired with anything.  Also, this all
happens at a different time from the existing UFS clocks being enabled/disabled.

I wonder if the ICE clock should be enabled/disabled in ufs_qcom_setup_clocks()
instead of what you are doing currently?

> +static int ufs_qcom_ice_init(struct ufs_qcom_host *host)
> +{
> +	struct ufs_hba *hba = host->hba;
> +	struct device *dev = hba->dev;
> +
> +	host->ice = of_qcom_ice_get(dev);
> +	if (host->ice == ERR_PTR(-EOPNOTSUPP)) {
> +		dev_warn(dev, "Disabling inline encryption support\n");
> +		hba->caps &= ~UFSHCD_CAP_CRYPTO;
> +		host->ice = NULL;
> +	}
> +
> +	if (IS_ERR(host->ice))
> +		return PTR_ERR(host->ice);
> +
> +	return 0;
> +}

This is still sometimes leaving UFSHCD_CAP_CRYPTO set in cases where ICE is
unsupported.

Moving the *setting* of UFSHCD_CAP_CRYPTO into here would fix that.

It is also hard to understand how the -EOPNOTSUPP case differs from the NULL
case.  Can you add a comment?  Or just consider keeping the original behavior,
which did not distinguish between these cases (as long as MASK_CRYPTO_SUPPORT
was set in REG_CONTROLLER_CAPABILITIES, which was checked first).

- Eric
Abel Vesa March 31, 2023, 5:13 a.m. UTC | #4
On 23-03-27 11:19:34, Eric Biggers wrote:
> Hi Abel,
> 
> On Mon, Mar 27, 2023 at 04:47:32PM +0300, Abel Vesa wrote:
> > Now that there is a new dedicated ICE driver, drop the ufs-qcom-ice and
> > use the new ICE api provided by the Qualcomm soc driver ice. The platforms
> > that already have ICE support will use the API as library since there will
> > not be a devicetree node, but instead they have reg range. In this case,
> > the of_qcom_ice_get will return an ICE instance created for the consumer's
> > device. But if there are platforms that do not have ice reg in the
> > consumer devicetree node and instead provide a dedicated ICE devicetree
> > node, the of_qcom_ice_get will look up the device based on qcom,ice
> > property and will get the ICE instance registered by the probe function
> > of the ice driver.
> > 
> > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> 
> I am still worried about the ICE clock.  Are you sure it is being managed
> correctly?  With your patch, the ICE clock gets enabled in ufs_qcom_ice_resume
> and disabled in ufs_qcom_ice_suspend, which hopefully pair up.  But it also gets
> enabled in ufs_qcom_ice_enable which isn't paired with anything.  Also, this all
> happens at a different time from the existing UFS clocks being enabled/disabled.

Right, I messed this up since the last version. Sorry about that.

What I need to do is to drop the enabling of the clock from
qcom_ice_enable and only do it from qcom_ice_resume. As for disabling
it, it remains as is, that is, in qcom_ice_disable.

Then, I need to enable the clock right before checking the supported
version. I'll do that with devm_clk_get_enabled (also optional for the
legacy once as I explained in the reply to the 6th patch).

> 
> I wonder if the ICE clock should be enabled/disabled in ufs_qcom_setup_clocks()
> instead of what you are doing currently?
> 
> > +static int ufs_qcom_ice_init(struct ufs_qcom_host *host)
> > +{
> > +	struct ufs_hba *hba = host->hba;
> > +	struct device *dev = hba->dev;
> > +
> > +	host->ice = of_qcom_ice_get(dev);
> > +	if (host->ice == ERR_PTR(-EOPNOTSUPP)) {
> > +		dev_warn(dev, "Disabling inline encryption support\n");
> > +		hba->caps &= ~UFSHCD_CAP_CRYPTO;
> > +		host->ice = NULL;
> > +	}
> > +
> > +	if (IS_ERR(host->ice))
> > +		return PTR_ERR(host->ice);
> > +
> > +	return 0;
> > +}
> 
> This is still sometimes leaving UFSHCD_CAP_CRYPTO set in cases where ICE is
> unsupported.
> 
> Moving the *setting* of UFSHCD_CAP_CRYPTO into here would fix that.
> 

I'll do exactly that. Thanks.

> It is also hard to understand how the -EOPNOTSUPP case differs from the NULL
> case.  Can you add a comment?  Or just consider keeping the original behavior,
> which did not distinguish between these cases (as long as MASK_CRYPTO_SUPPORT
> was set in REG_CONTROLLER_CAPABILITIES, which was checked first).

I believe it makes more sense to return -EOPNOTSUPP when the driver
doesn't support a specific version of the HW. If you do not agree, I'll
make it return NULL then.

> 
> - Eric