[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250523101041.3615819-1-naomi.chu@mediatek.com>
Date: Fri, 23 May 2025 18:10:34 +0800
From: <naomi.chu@...iatek.com>
To: <linux-scsi@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-arm-kernel@...ts.infradead.org>, <linux-mediatek@...ts.infradead.org>,
Alim Akhtar <alim.akhtar@...sung.com>, Avri Altman <avri.altman@....com>,
Bart Van Assche <bvanassche@....org>, "James E.J. Bottomley"
<James.Bottomley@...senPartnership.com>, "Martin K. Petersen"
<martin.petersen@...cle.com>, Matthias Brugger <matthias.bgg@...il.com>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>
CC: <wsd_upstream@...iatek.com>, <naomi.chu@...iatek.com>,
<peter.wang@...iatek.com>, <alice.chao@...iatek.com>,
<chun-hung.wu@...iatek.com>, <cc.chou@...iatek.com>,
<yi-fan.peng@...iatek.com>
Subject: [PATCH 1/1] ufs: core: add fatal errors check for LINERESET
From: Naomi Chu <naomi.chu@...iatek.com>
The current error handling flow directly checks the power mode after a
LINERESET occurs. However, if a PA_INIT_ERR occurs after the LINERESET,
checking the power mode may require waiting for three DME_GET timeouts,
which wastes 1.5 seconds.
To improve efficiency, when a LINERESET occurs, wait for PA_INIT to
complete and check for any other errors. After a LINERESET, PA_INIT
takes up to 75.4ms to complete. Therefore, a 100ms delay is added.
Signed-off-by: Naomi Chu <naomi.chu@...iatek.com>
---
drivers/ufs/core/ufshcd.c | 45 +++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 7735421e3991..c7cc62429fc9 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -6359,6 +6359,46 @@ static inline bool ufshcd_is_saved_err_fatal(struct ufs_hba *hba)
(hba->saved_err & (INT_FATAL_ERRORS | UFSHCD_UIC_HIBERN8_MASK));
}
+static bool ufshcd_is_linereset_fatal(struct ufs_hba *hba)
+{
+ bool needs_reset = true;
+ unsigned long flags;
+ int err;
+
+ spin_lock_irqsave(hba->host->host_lock, flags);
+
+ if (ufshcd_is_saved_err_fatal(hba)) {
+ spin_unlock_irqrestore(hba->host->host_lock, flags);
+ goto out;
+ }
+
+ /*
+ * Wait for 100ms to ensure the PA_INIT flow is complete,
+ * and check for PA_INIT_ERR or other fatal errors.
+ */
+ spin_unlock_irqrestore(hba->host->host_lock, flags);
+ msleep(100);
+ spin_lock_irqsave(hba->host->host_lock, flags);
+
+ if (ufshcd_is_saved_err_fatal(hba)) {
+ spin_unlock_irqrestore(hba->host->host_lock, flags);
+ goto out;
+ }
+
+ /*
+ * PA_INIT_ERR on the device side will not trigger UIC
+ * error interrupt.
+ * Send NOP to check if the link is alive.
+ */
+ spin_unlock_irqrestore(hba->host->host_lock, flags);
+ err = ufshcd_verify_dev_init(hba);
+ if (!err)
+ needs_reset = false;
+
+out:
+ return needs_reset;
+}
+
void ufshcd_schedule_eh_work(struct ufs_hba *hba)
{
lockdep_assert_held(hba->host->host_lock);
@@ -6655,6 +6695,11 @@ static void ufshcd_err_handler(struct work_struct *work)
if (!hba->saved_uic_err)
hba->saved_err &= ~UIC_ERROR;
spin_unlock_irqrestore(hba->host->host_lock, flags);
+ if (ufshcd_is_linereset_fatal(hba)) {
+ needs_reset = true;
+ spin_lock_irqsave(hba->host->host_lock, flags);
+ goto do_reset;
+ }
if (ufshcd_is_pwr_mode_restore_needed(hba))
needs_restore = true;
spin_lock_irqsave(hba->host->host_lock, flags);
--
2.45.2
Powered by blists - more mailing lists