mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
To: Neeraj Soni <neeraj.soni@oss.qualcomm.com>,
	andersson@kernel.org, konradybcio@kernel.org
Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] soc: qcom: Add HWKM v1 support for wrapped keys
Date: Mon, 27 Oct 2025 09:54:38 +0100	[thread overview]
Message-ID: <bef7c78c-2257-47ff-bccc-a9422afb1c42@oss.qualcomm.com> (raw)
In-Reply-To: <20251026164708.2771213-1-neeraj.soni@oss.qualcomm.com>

On 10/26/25 5:47 PM, Neeraj Soni wrote:
> HWKM v1 and v2 differ slightly in wrapped key size and the bit fields for
> certain status registers and operating mode (legacy or standard).
> 
> Add support to select HWKM version based on the major and minor revisions.
> Use this HWKM version to select wrapped key size and to configure the bit
> fields in registers for operating modes and hardware status.
> 
> Support for SCM calls for wrapped keys is being added in the TrustZone for
> few SoCs with HWKM v1. Existing check of qcom_scm_has_wrapped_key_support()
> API ensures that HWKM is used only if these SCM calls are supported in
> TrustZone for that SoC.
> 
> Signed-off-by: Neeraj Soni <neeraj.soni@oss.qualcomm.com>
> ---

The subject must say "ice:"

[...]

>  static bool qcom_ice_check_supported(struct qcom_ice *ice)
> @@ -114,9 +126,26 @@ static bool qcom_ice_check_supported(struct qcom_ice *ice)
>  		return false;
>  	}
>  
> +	/* HWKM version v2 is present from ICE 3.2.1 onwards while version v1
> +	 * is present only in ICE 3.2.0.

What about before v3.2.0?

> +	 */
> +	if (major == 4 ||
> +	   (major == 3 && (minor >= 3 || (minor == 2 && step >= 1))))
> +		ice->hwkm_version = QCOM_ICE_HWKM_V2;
> +	else if ((major == 3) && (minor == 2))
> +		ice->hwkm_version = QCOM_ICE_HWKM_V1;
> +	else
> +		ice->hwkm_version = 0;

"if major > 3" is more future-proof than "== 4", unless you know for
a fact major == 5 etc. will have an incompatible software interface

>  	dev_info(dev, "Found QC Inline Crypto Engine (ICE) v%d.%d.%d\n",
>  		 major, minor, step);
>  
> +	if (!ice->hwkm_version)
> +		dev_info(dev, "QC Hard Ware Key Manager (HWKM) not supported\n");

"Hard Ware" looks *really* poor

[...]

> -	BUILD_BUG_ON(QCOM_ICE_HWKM_WRAPPED_KEY_SIZE >
> +	BUILD_BUG_ON(QCOM_ICE_HWKM_WRAPPED_KEY_SIZE(ice->hwkm_version) >
>  		     BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE);

This is not going to work how you want it to..

>  	/*
>  	 * When ICE is in HWKM mode, it only supports wrapped keys.
> @@ -238,9 +266,18 @@ static void qcom_ice_hwkm_init(struct qcom_ice *ice)
>  	 *
>  	 * Put ICE in HWKM mode.  ICE defaults to legacy mode.
>  	 */
> -	regval = qcom_ice_readl(ice, QCOM_ICE_REG_CONTROL);
> -	regval &= ~QCOM_ICE_LEGACY_MODE_ENABLED;
> -	qcom_ice_writel(ice, regval, QCOM_ICE_REG_CONTROL);
> +	if (ice->hwkm_version == QCOM_ICE_HWKM_V2) {
> +		regval = qcom_ice_readl(ice, QCOM_ICE_REG_CONTROL);
> +		regval &= ~QCOM_ICE_LEGACY_MODE_ENABLED;
> +		qcom_ice_writel(ice, regval, QCOM_ICE_REG_CONTROL);
> +	} else if (ice->hwkm_version == QCOM_ICE_HWKM_V1) {
> +		regval = qcom_ice_readl(ice, QCOM_ICE_REG_HWKM_TZ_KM_CTL);
> +		regval &= ~QCOM_ICE_HWKM_ICE_LEGACY_MODE_ENABLED;
> +		qcom_ice_writel(ice, regval, QCOM_ICE_REG_HWKM_TZ_KM_CTL);
> +	} else {
> +		dev_err(ice->dev, "Invalid HWKM version\n");
> +		return;
> +	}

The else path is impossible to reach

>  
>  	/* Disable CRC checks.  This HWKM feature is not used. */
>  	qcom_ice_writel(ice, QCOM_ICE_HWKM_DISABLE_CRC_CHECKS_VAL,
> @@ -298,7 +335,8 @@ EXPORT_SYMBOL_GPL(qcom_ice_suspend);
>  
>  static unsigned int translate_hwkm_slot(struct qcom_ice *ice, unsigned int slot)
>  {
> -	return slot * 2;
> +	/* The slot offset depends upon HWKM version */
> +	return (ice->hwkm_version == QCOM_ICE_HWKM_V1) ? (slot) : (slot * 2);

The parentheses are unnecessary

Konrad

  reply	other threads:[~2025-10-27  8:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-26 16:47 Neeraj Soni
2025-10-27  8:54 ` Konrad Dybcio [this message]
2025-10-27  9:56   ` Neeraj Soni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bef7c78c-2257-47ff-bccc-a9422afb1c42@oss.qualcomm.com \
    --to=konrad.dybcio@oss.qualcomm.com \
    --cc=andersson@kernel.org \
    --cc=konradybcio@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neeraj.soni@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®