From: Can Guo <can.guo@oss.qualcomm.com>
To: avri.altman@wdc.com, bvanassche@acm.org, beanhuo@micron.com,
martin.petersen@oracle.com, mani@kernel.org
Cc: linux-scsi@vger.kernel.org, Can Guo <can.guo@oss.qualcomm.com>,
Alim Akhtar <alim.akhtar@samsung.com>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
Peter Wang <peter.wang@mediatek.com>,
Adrian Hunter <adrian.hunter@intel.com>,
"Bao D. Nguyen" <quic_nguyenb@quicinc.com>,
Archana Patni <archana.patni@intel.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v3 02/12] scsi: ufs: core: Pass force_pmc to ufshcd_config_pwr_mode() as a parameter
Date: Sun, 8 Mar 2026 08:13:59 -0700 [thread overview]
Message-ID: <20260308151409.3779137-3-can.guo@oss.qualcomm.com> (raw)
In-Reply-To: <20260308151409.3779137-1-can.guo@oss.qualcomm.com>
Currently, callers must manually toggle hba->force_pmc before and after
calling ufshcd_config_pwr_mode() to force a Power Mode change. Introduce
enum ufshcd_pmc_policy and refactor ufshcd_config_pwr_mode() to accept
pmc_policy as a parameter to force a Power Mode change.
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Can Guo <can.guo@oss.qualcomm.com>
---
drivers/ufs/core/ufshcd.c | 35 ++++++++++++++++++++++-------------
drivers/ufs/host/ufshcd-pci.c | 3 ++-
include/ufs/ufshcd.h | 19 +++++++++++++++----
3 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 9ff6c5977f2d..7a7944a6f7d4 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -1407,7 +1407,8 @@ static int ufshcd_scale_gear(struct ufs_hba *hba, u32 target_gear, bool scale_up
config_pwr_mode:
/* check if the power mode needs to be changed or not? */
- ret = ufshcd_config_pwr_mode(hba, &new_pwr_info);
+ ret = ufshcd_config_pwr_mode(hba, &new_pwr_info,
+ UFSHCD_PMC_POLICY_DONT_FORCE);
if (ret)
dev_err(hba->dev, "%s: failed err %d, old gear: (tx %d rx %d), new gear: (tx %d rx %d)",
__func__, ret,
@@ -4248,7 +4249,8 @@ int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,
pwr_mode_change = true;
}
if (pwr_mode_change) {
- ret = ufshcd_change_power_mode(hba, &temp_pwr_info);
+ ret = ufshcd_change_power_mode(hba, &temp_pwr_info,
+ UFSHCD_PMC_POLICY_DONT_FORCE);
if (ret)
goto out;
}
@@ -4272,7 +4274,8 @@ int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,
if (peer && (hba->quirks & UFSHCD_QUIRK_DME_PEER_ACCESS_AUTO_MODE)
&& pwr_mode_change)
- ufshcd_change_power_mode(hba, &orig_pwr_info);
+ ufshcd_change_power_mode(hba, &orig_pwr_info,
+ UFSHCD_PMC_POLICY_DONT_FORCE);
out:
return ret;
}
@@ -4664,6 +4667,7 @@ static int ufshcd_get_max_pwr_mode(struct ufs_hba *hba)
* ufshcd_dme_change_power_mode() - UniPro DME Power Mode change sequence
* @hba: per-adapter instance
* @pwr_mode: pointer to the target power mode (gear/lane) attributes
+ * @pmc_policy: Power Mode change policy
*
* This function handles the low-level DME (Device Management Entity)
* configuration required to transition the UFS link to a new power mode. It
@@ -4679,12 +4683,13 @@ static int ufshcd_get_max_pwr_mode(struct ufs_hba *hba)
* Return: 0 on success, non-zero error code on failure.
*/
static int ufshcd_dme_change_power_mode(struct ufs_hba *hba,
- struct ufs_pa_layer_attr *pwr_mode)
+ struct ufs_pa_layer_attr *pwr_mode,
+ enum ufshcd_pmc_policy pmc_policy)
{
int ret;
/* if already configured to the requested pwr_mode */
- if (!hba->force_pmc &&
+ if (pmc_policy == UFSHCD_PMC_POLICY_DONT_FORCE &&
pwr_mode->gear_rx == hba->pwr_info.gear_rx &&
pwr_mode->gear_tx == hba->pwr_info.gear_tx &&
pwr_mode->lane_rx == hba->pwr_info.lane_rx &&
@@ -4767,6 +4772,7 @@ static int ufshcd_dme_change_power_mode(struct ufs_hba *hba,
* ufshcd_change_power_mode() - Change UFS Link Power Mode
* @hba: per-adapter instance
* @pwr_mode: pointer to the target power mode (gear/lane) attributes
+ * @pmc_policy: Power Mode change policy
*
* This function handles the high-level sequence for changing the UFS link
* power mode. It triggers vendor-specific pre-change notification,
@@ -4776,13 +4782,14 @@ static int ufshcd_dme_change_power_mode(struct ufs_hba *hba,
* Return: 0 on success, non-zero error code on failure.
*/
int ufshcd_change_power_mode(struct ufs_hba *hba,
- struct ufs_pa_layer_attr *pwr_mode)
+ struct ufs_pa_layer_attr *pwr_mode,
+ enum ufshcd_pmc_policy pmc_policy)
{
int ret;
ufshcd_vops_pwr_change_notify(hba, PRE_CHANGE, pwr_mode);
- ret = ufshcd_dme_change_power_mode(hba, pwr_mode);
+ ret = ufshcd_dme_change_power_mode(hba, pwr_mode, pmc_policy);
if (!ret)
ufshcd_vops_pwr_change_notify(hba, POST_CHANGE, pwr_mode);
@@ -4795,11 +4802,13 @@ EXPORT_SYMBOL_GPL(ufshcd_change_power_mode);
* ufshcd_config_pwr_mode - configure a new power mode
* @hba: per-adapter instance
* @desired_pwr_mode: desired power configuration
+ * @pmc_policy: Power Mode change policy
*
* Return: 0 upon success; < 0 upon failure.
*/
int ufshcd_config_pwr_mode(struct ufs_hba *hba,
- struct ufs_pa_layer_attr *desired_pwr_mode)
+ struct ufs_pa_layer_attr *desired_pwr_mode,
+ enum ufshcd_pmc_policy pmc_policy)
{
struct ufs_pa_layer_attr final_params = { 0 };
int ret;
@@ -4809,7 +4818,7 @@ int ufshcd_config_pwr_mode(struct ufs_hba *hba,
if (ret)
memcpy(&final_params, desired_pwr_mode, sizeof(final_params));
- return ufshcd_change_power_mode(hba, &final_params);
+ return ufshcd_change_power_mode(hba, &final_params, pmc_policy);
}
EXPORT_SYMBOL_GPL(ufshcd_config_pwr_mode);
@@ -6866,14 +6875,13 @@ static void ufshcd_err_handler(struct work_struct *work)
* are sent via bsg and/or sysfs.
*/
down_write(&hba->clk_scaling_lock);
- hba->force_pmc = true;
- pmc_err = ufshcd_config_pwr_mode(hba, &(hba->pwr_info));
+ pmc_err = ufshcd_config_pwr_mode(hba, &hba->pwr_info,
+ UFSHCD_PMC_POLICY_FORCE);
if (pmc_err) {
needs_reset = true;
dev_err(hba->dev, "%s: Failed to restore power mode, err = %d\n",
__func__, pmc_err);
}
- hba->force_pmc = false;
ufshcd_print_pwr_info(hba);
up_write(&hba->clk_scaling_lock);
spin_lock_irqsave(hba->host->host_lock, flags);
@@ -9148,7 +9156,8 @@ static int ufshcd_post_device_init(struct ufs_hba *hba)
if (hba->dev_ref_clk_freq != REF_CLK_FREQ_INVAL)
ufshcd_set_dev_ref_clk(hba);
/* Gear up to HS gear. */
- ret = ufshcd_config_pwr_mode(hba, &hba->max_pwr_info.info);
+ ret = ufshcd_config_pwr_mode(hba, &hba->max_pwr_info.info,
+ UFSHCD_PMC_POLICY_DONT_FORCE);
if (ret) {
dev_err(hba->dev, "%s: Failed setting power mode, err = %d\n",
__func__, ret);
diff --git a/drivers/ufs/host/ufshcd-pci.c b/drivers/ufs/host/ufshcd-pci.c
index 894b7589b14e..aa5e593769c3 100644
--- a/drivers/ufs/host/ufshcd-pci.c
+++ b/drivers/ufs/host/ufshcd-pci.c
@@ -154,7 +154,8 @@ static int ufs_intel_set_lanes(struct ufs_hba *hba, u32 lanes)
pwr_info.lane_rx = lanes;
pwr_info.lane_tx = lanes;
- ret = ufshcd_change_power_mode(hba, &pwr_info);
+ ret = ufshcd_change_power_mode(hba, &pwr_info,
+ UFSHCD_PMC_POLICY_DONT_FORCE);
if (ret)
dev_err(hba->dev, "%s: Setting %u lanes, err = %d\n",
__func__, lanes, ret);
diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h
index 51c2555bea73..16facaee3e77 100644
--- a/include/ufs/ufshcd.h
+++ b/include/ufs/ufshcd.h
@@ -529,6 +529,17 @@ enum ufshcd_state {
UFSHCD_STATE_ERROR,
};
+/**
+ * enum ufshcd_pmc_policy - Power Mode change policy
+ * @UFSHCD_PMC_POLICY_DONT_FORCE: Do not force a Power Mode change.
+ * @UFSHCD_PMC_POLICY_FORCE: Force a Power Mode change even if current Power
+ * Mode is same as target Power Mode.
+ */
+enum ufshcd_pmc_policy {
+ UFSHCD_PMC_POLICY_DONT_FORCE,
+ UFSHCD_PMC_POLICY_FORCE,
+};
+
enum ufshcd_quirks {
/* Interrupt aggregation support is broken */
UFSHCD_QUIRK_BROKEN_INTR_AGGR = 1 << 0,
@@ -882,7 +893,6 @@ enum ufshcd_mcq_opr {
* @saved_uic_err: sticky UIC error mask
* @ufs_stats: various error counters
* @force_reset: flag to force eh_work perform a full reset
- * @force_pmc: flag to force a power mode change
* @silence_err_logs: flag to silence error logs
* @dev_cmd: ufs device management command information
* @last_dme_cmd_tstamp: time stamp of the last completed DME command
@@ -1036,7 +1046,6 @@ struct ufs_hba {
u32 saved_uic_err;
struct ufs_stats ufs_stats;
bool force_reset;
- bool force_pmc;
bool silence_err_logs;
/* Device management request data */
@@ -1363,9 +1372,11 @@ extern int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel,
extern int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,
u32 *mib_val, u8 peer);
extern int ufshcd_change_power_mode(struct ufs_hba *hba,
- struct ufs_pa_layer_attr *pwr_mode);
+ struct ufs_pa_layer_attr *pwr_mode,
+ enum ufshcd_pmc_policy pmc_policy);
extern int ufshcd_config_pwr_mode(struct ufs_hba *hba,
- struct ufs_pa_layer_attr *desired_pwr_mode);
+ struct ufs_pa_layer_attr *desired_pwr_mode,
+ enum ufshcd_pmc_policy pmc_policy);
extern int ufshcd_uic_change_pwr_mode(struct ufs_hba *hba, u8 mode);
/* UIC command interfaces for DME primitives */
--
2.34.1
next prev parent reply other threads:[~2026-03-08 15:14 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-08 15:13 [PATCH v3 00/12] scsi: ufs: Add TX Equalization support for UFS 5.0 Can Guo
2026-03-08 15:13 ` [PATCH v3 01/12] scsi: ufs: core: Introduce a new ufshcd vops negotiate_pwr_mode() Can Guo
2026-03-13 22:09 ` Bart Van Assche
2026-03-14 7:21 ` Can Guo
2026-03-08 15:13 ` Can Guo [this message]
2026-03-08 15:14 ` [PATCH v3 03/12] scsi: ufs: core: Add UFS_HS_G6 and UFS_HS_GEAR_MAX to enum ufs_hs_gear_tag Can Guo
2026-03-08 15:14 ` [PATCH v3 04/12] scsi: ufs: core: Add support for TX Equalization Can Guo
2026-03-13 22:19 ` Bart Van Assche
2026-03-14 8:19 ` Can Guo
2026-03-14 9:33 ` Can Guo
2026-03-16 16:55 ` Bart Van Assche
2026-03-17 7:04 ` Can Guo
2026-03-17 6:49 ` Peter Wang (王信友)
2026-03-17 7:22 ` Can Guo
2026-03-17 7:35 ` Can Guo
2026-03-17 13:10 ` Peter Wang (王信友)
2026-03-19 5:49 ` Can Guo
2026-03-19 12:42 ` Peter Wang (王信友)
2026-03-21 2:30 ` Can Guo
2026-03-17 13:08 ` Peter Wang (王信友)
2026-03-19 5:42 ` Can Guo
2026-03-08 15:14 ` [PATCH v3 05/12] scsi: ufs: core: Add debugfs entries for TX Equalization params Can Guo
2026-03-13 22:21 ` Bart Van Assche
2026-03-08 15:14 ` [PATCH v3 06/12] scsi: ufs: core: Add helpers to pause and resume command processing Can Guo
2026-03-13 22:26 ` Bart Van Assche
2026-03-14 10:38 ` Can Guo
2026-03-16 17:12 ` Bart Van Assche
2026-03-16 18:07 ` Bart Van Assche
2026-03-08 15:14 ` [PATCH v3 07/12] scsi: ufs: core: Add support to refresh TX Equalization via debugfs Can Guo
2026-03-13 22:30 ` Bart Van Assche
2026-03-14 10:45 ` Can Guo
2026-03-16 17:14 ` Bart Van Assche
2026-03-17 13:05 ` Peter Wang (王信友)
2026-03-19 5:36 ` Can Guo
2026-03-08 15:14 ` [PATCH v3 08/12] scsi: ufs: ufs-qcom: Fixup PAM-4 TX L0_L1_L2_L3 adaptation pattern length Can Guo
2026-03-08 15:14 ` [PATCH v3 09/12] scsi: ufs: ufs-qcom: Implement vops tx_eqtr_notify() Can Guo
2026-03-08 15:14 ` [PATCH v3 10/12] scsi: ufs: ufs-qcom: Implement vops get_rx_fom() Can Guo
2026-03-08 15:14 ` [PATCH v3 11/12] scsi: ufs: ufs-qcom: Implement vops apply_tx_eqtr_settings() Can Guo
2026-03-08 15:14 ` [PATCH v3 12/12] scsi: ufs: ufs-qcom: Enable TX Equalization Can Guo
2026-03-13 21:56 ` [PATCH v3 00/12] scsi: ufs: Add TX Equalization support for UFS 5.0 Bart Van Assche
2026-03-14 10:48 ` Can Guo
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=20260308151409.3779137-3-can.guo@oss.qualcomm.com \
--to=can.guo@oss.qualcomm.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=adrian.hunter@intel.com \
--cc=alim.akhtar@samsung.com \
--cc=archana.patni@intel.com \
--cc=avri.altman@wdc.com \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mani@kernel.org \
--cc=martin.petersen@oracle.com \
--cc=peter.wang@mediatek.com \
--cc=quic_nguyenb@quicinc.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 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.