From: palash.kambar@oss.qualcomm.com
To: mani@kernel.org, alim.akhtar@samsung.com, avri.altman@wdc.com,
bvanassche@acm.org, peter.griffin@linaro.org, krzk@kernel.org,
peter.wang@mediatek.com, beanhuo@micron.com,
quic_nguyenb@quicinc.com, adrian.hunter@intel.com,
ebiggers@kernel.org, neil.armstrong@linaro.org,
James.Bottomley@HansenPartnership.com,
martin.petersen@oracle.com
Cc: linux-arm-msm@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org, quic_cang@quicinc.com,
quic_nitirawa@quicinc.com,
Palash Kambar <palash.kambar@oss.qualcomm.com>
Subject: [PATCH V1 2/2] ufs: ufs-qcom: Disable AHIT before SQ tail update to prevent race in MCQ mode
Date: Tue, 14 Oct 2025 11:34:06 +0530 [thread overview]
Message-ID: <20251014060406.1420475-3-palash.kambar@oss.qualcomm.com> (raw)
In-Reply-To: <20251014060406.1420475-1-palash.kambar@oss.qualcomm.com>
From: Can Guo <quic_cang@quicinc.com>
In MCQ mode, a race condition can occur on QCOM UFSHC V6 when the
Auto-Hibernate Idle Timer (AHIT) is close to expiring. If a data
command and a hibernate command are issued simultaneously to the
UniPro layer, the data command may be dropped.
To prevent this, AHIT is disabled by reprogramming it to 0 before
updating the SQ tail pointer. Once there are no active commands in
the UFS host controller, the timer is re-enabled.
This change ensures reliable command delivery in MCQ mode by
avoiding timing conflicts between data and hibernate operations.
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Co-developed-by: Palash Kambar <palash.kambar@oss.qualcomm.com>
Signed-off-by: Palash Kambar <palash.kambar@oss.qualcomm.com>
---
drivers/ufs/host/ufs-qcom.c | 35 +++++++++++++++++++++++++++++++++++
drivers/ufs/host/ufs-qcom.h | 1 +
2 files changed, 36 insertions(+)
diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index 89a3328a7a75..f31239f4fc50 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -1286,6 +1286,39 @@ static int ufs_qcom_icc_init(struct ufs_qcom_host *host)
return 0;
}
+static void ufs_qcom_send_command(struct ufs_hba *hba,
+ struct ufshcd_lrb *lrbp)
+{
+ struct ufs_qcom_host *host = ufshcd_get_variant(hba);
+ unsigned long flags;
+
+ if ((host->hw_ver.major == 6 && host->hw_ver.minor == 0 &&
+ host->hw_ver.step == 0) && hba->mcq_enabled) {
+ spin_lock_irqsave(hba->host->host_lock, flags);
+ if ((++host->active_cmds) == 1)
+ /* Stop the auto-hiberate idle timer */
+ ufshcd_writel(hba, 0, REG_AUTO_HIBERNATE_IDLE_TIMER);
+ spin_unlock_irqrestore(hba->host->host_lock, flags);
+ }
+}
+
+static void ufs_qcom_compl_command(struct ufs_hba *hba,
+ struct ufshcd_lrb *lrbp)
+{
+ struct ufs_qcom_host *host = ufshcd_get_variant(hba);
+ unsigned long flags;
+
+ if ((host->hw_ver.major == 6 && host->hw_ver.minor == 0 &&
+ host->hw_ver.step == 0) && hba->mcq_enabled) {
+ spin_lock_irqsave(hba->host->host_lock, flags);
+ if ((--host->active_cmds) == 0)
+ /* Activate the auto-hiberate idle timer */
+ ufshcd_writel(hba, hba->ahit,
+ REG_AUTO_HIBERNATE_IDLE_TIMER);
+ spin_unlock_irqrestore(hba->host->host_lock, flags);
+ }
+}
+
/**
* ufs_qcom_init - bind phy with controller
* @hba: host controller instance
@@ -2194,6 +2227,8 @@ static const struct ufs_hba_variant_ops ufs_hba_qcom_vops = {
.get_ufs_hci_version = ufs_qcom_get_ufs_hci_version,
.clk_scale_notify = ufs_qcom_clk_scale_notify,
.setup_clocks = ufs_qcom_setup_clocks,
+ .setup_xfer_req = ufs_qcom_send_command,
+ .compl_command = ufs_qcom_compl_command,
.hce_enable_notify = ufs_qcom_hce_enable_notify,
.link_startup_notify = ufs_qcom_link_startup_notify,
.pwr_change_notify = ufs_qcom_pwr_change_notify,
diff --git a/drivers/ufs/host/ufs-qcom.h b/drivers/ufs/host/ufs-qcom.h
index 380d02333d38..a97da99361a8 100644
--- a/drivers/ufs/host/ufs-qcom.h
+++ b/drivers/ufs/host/ufs-qcom.h
@@ -308,6 +308,7 @@ struct ufs_qcom_host {
u32 phy_gear;
bool esi_enabled;
+ unsigned long active_cmds;
};
struct ufs_qcom_drvdata {
--
2.34.1
next prev parent reply other threads:[~2025-10-14 6:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-14 6:04 [PATCH V1 0/2] Address race condition in MCQ mode and enhance palash.kambar
2025-10-14 6:04 ` [PATCH V1 1/2] ufs: core:Add vendor-specific callbacks and update setup_xfer_req interface palash.kambar
2025-10-14 16:10 ` Bart Van Assche
2025-10-18 6:49 ` Palash Kambar
2025-10-14 6:04 ` palash.kambar [this message]
2025-10-14 16:18 ` [PATCH V1 2/2] ufs: ufs-qcom: Disable AHIT before SQ tail update to prevent race in MCQ mode Bart Van Assche
[not found] ` <CAGbPq5dhUXr59U_J3W4haNHughkaiXpnc4kAZWXB0SjPdFQMhg@mail.gmail.com>
2025-10-15 15:45 ` Bart Van Assche
2025-10-18 6:44 ` Palash Kambar
2025-10-20 6:53 ` Peter Wang (王信友)
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=20251014060406.1420475-3-palash.kambar@oss.qualcomm.com \
--to=palash.kambar@oss.qualcomm.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=adrian.hunter@intel.com \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@wdc.com \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--cc=ebiggers@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mani@kernel.org \
--cc=martin.petersen@oracle.com \
--cc=neil.armstrong@linaro.org \
--cc=peter.griffin@linaro.org \
--cc=peter.wang@mediatek.com \
--cc=quic_cang@quicinc.com \
--cc=quic_nguyenb@quicinc.com \
--cc=quic_nitirawa@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 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®