All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Giri Prasad Goriparthi" <giri.goriparthi@oss.qualcomm.com>
Cc: linux-scsi@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 1/3] scsi: ufs: ufs-qcom: Add specified gear support for multi gear scaling
Date: Wed, 02 Dec 2026 08:32:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-245203@kernel.org> (raw)
In-Reply-To: <20261202-b4-ufs-qcom-multi-gear-scaling-v2-1-e2fe4cbce19d@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] scsi: ufs: ufs-qcom: opp-level gear clobbers PM domain
  performance state
- [Medium] scsi: ufs: ufs-qcom: ufs_qcom_freq_to_gear_speed() fails to
  clamp opp-level
--

commit 73d84f7e8cb1062be352f4560a2e81fc675ef5ff
Author: Giri Prasad Goriparthi <giri.goriparthi@oss.qualcomm.com>

scsi: ufs: ufs-qcom: Add specified gear support for multi gear scaling

This commit reads the opp-level property from the UFS OPP table in
ufs_qcom_freq_to_gear_speed() to select the HS gear for a given operating
frequency, falling back to the hardcoded frequency-to-gear table when
opp-level is unset or exceeds the maximum Rx gear.

> diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
> index 6afb8498b8c26..cc6380ebb1458 100644
> --- a/drivers/ufs/host/ufs-qcom.c
> +++ b/drivers/ufs/host/ufs-qcom.c

[ ... ]

> @@ -2535,12 +2535,32 @@ static unsigned long ufs_qcom_opp_freq_to_clk_freq(struct ufs_hba *hba,
>  
>  static u32 ufs_qcom_freq_to_gear_speed(struct ufs_hba *hba, unsigned long freq)
>  {
> -	u32 gear = UFS_HS_DONT_CHANGE;
>  	unsigned long unipro_freq;
> +	struct dev_pm_opp *opp;
> +	u32 gear = UFS_HS_DONT_CHANGE;
>  
>  	if (!hba->use_pm_opp)
>  		return gear;
>  
> +	opp = dev_pm_opp_find_freq_exact_indexed(hba->dev, freq, 0, true);
> +	if (IS_ERR_OR_NULL(opp)) {
> +		dev_err(hba->dev, "Failed to find OPP for exact frequency %lu\n", freq);
> +		return gear;
> +	}
> +
> +	/* Get HS gear speed from 'opp-level' */
> +	gear = dev_pm_opp_get_level(opp);
> +	dev_pm_opp_put(opp);

[Severity: High]
Does repurposing opp-level in the UFS controller's OPP table to store UFS
HS gear values (1..6) overwrite the device's required-opps PM domain
performance state vote when scaling up clocks?

On Qualcomm SoCs, the UFS host controller has a single power-domains entry
(GCC_UFS_PHY_GDSC, a subdomain of RPMHPD_CX) and per-OPP required-opps
entries pointing to RPMHPD voltage corners (for example,
RPMH_REGULATOR_LEVEL_NOM = 256).  When a single power domain is attached,
__genpd_dev_pm_attach() -> genpd_set_required_opp_dev() registers hba->dev
itself as opp_table->required_devs[0].

During clock initialization and devfreq scaling, ufshcd_opp_set_rate()
calls dev_pm_opp_set_opp(hba->dev, opp) -> _set_opp():

drivers/opp/core.c:_set_opp() {
	...
	if (!scaling_down) {
		ret = _set_required_opps(dev, opp_table, opp, true);
		if (ret) {
			dev_err(dev, "Failed to set required opps: %d\n", ret);
			return ret;
		}

		ret = _set_opp_level(dev, opp);
		if (ret)
			return ret;
	...
}

When scaling up, _set_required_opps() first votes the required RPMHPD
corner on hba->dev via dev_pm_domain_set_performance_state().  With
opp-level populated on the UFS OPP node, _set_opp_level(hba->dev, opp)
immediately calls dev_pm_domain_set_performance_state(hba->dev, opp->level)
on the same device, replacing the required RPMHPD corner vote with the raw
UFS gear number (1..6) and dropping the CX rail vote to its floor corner
before raising the UFS clock rates.

> +
> +	/*
> +	 * If opp-level is not configured in DT or the specified gear exceeds
> +	 * the max supported gear, fall back to the frequency-to-gear table.
> +	 */
> +	if (gear != OPP_LEVEL_UNSET && gear <= hba->max_pwr_info.info.gear_rx)
> +		return gear;

[Severity: Medium]
When opp-level is configured in DT with a gear above
hba->max_pwr_info.info.gear_rx (for example, when attached to a lower-gear
UFS device or constrained by limit-hs-gear), should this clamp gear to
hba->max_pwr_info.info.gear_rx with min_t() as the bottom of
ufs_qcom_freq_to_gear_speed() does, instead of falling back to the
hardcoded unipro_freq switch table?

Falling back to the switch table defeats the platform-specific mapping
whenever the platform's UniPro clock frequency maps to a different gear in
the switch table (such as 150 MHz mapping to UFS_HS_G2 in the switch table
instead of UFS_HS_G3), or returns UFS_HS_DONT_CHANGE (0) if the frequency
is not in the switch table.  Returning 0 causes ufshcd_scale_gear() to fall
into its legacy two-gear scaling path, where a subsequent scale-up copies
an uninitialized zeroed hba->clk_scaling.saved_pwr_info into new_pwr_info.

Also, if opp-level is 0, gear != OPP_LEVEL_UNSET && gear <=
hba->max_pwr_info.info.gear_rx evaluates to true and returns
UFS_HS_DONT_CHANGE (0) directly instead of falling back.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-b4-ufs-qcom-multi-gear-scaling-v2-0-e2fe4cbce19d@oss.qualcomm.com?part=1

  reply	other threads:[~2026-12-02  8:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  8:14 [PATCH v2 0/3] ufs-qcom: Add specified gear support for multi gear scaling Giri Prasad Goriparthi
2026-12-02  8:14 ` [PATCH v2 1/3] scsi: ufs: " Giri Prasad Goriparthi
2026-12-02  8:32   ` sashiko-bot [this message]
2026-12-02  8:14 ` [PATCH v2 2/3] arm64: dts: qcom: hamoa: Add opp-level for UFS gear speed Giri Prasad Goriparthi
2026-12-02  8:28   ` sashiko-bot
2026-12-02  8:15 ` [PATCH v2 3/3] arm64: dts: qcom: talos: " Giri Prasad Goriparthi
2026-12-02  8:30   ` sashiko-bot

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=sashiko-outbox-245203@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=giri.goriparthi@oss.qualcomm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.