* [PATCH 1/1] ufs: core: add fatal errors check for LINERESET
@ 2025-05-23 10:10 naomi.chu
2025-05-23 16:14 ` Bart Van Assche
0 siblings, 1 reply; 2+ messages in thread
From: naomi.chu @ 2025-05-23 10:10 UTC (permalink / raw)
To: linux-scsi, linux-kernel, linux-arm-kernel, linux-mediatek,
Alim Akhtar, Avri Altman, Bart Van Assche, James E.J. Bottomley,
Martin K. Petersen, Matthias Brugger, AngeloGioacchino Del Regno
Cc: wsd_upstream, naomi.chu, peter.wang, alice.chao, chun-hung.wu,
cc.chou, yi-fan.peng
From: Naomi Chu <naomi.chu@mediatek.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@mediatek.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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] ufs: core: add fatal errors check for LINERESET
2025-05-23 10:10 [PATCH 1/1] ufs: core: add fatal errors check for LINERESET naomi.chu
@ 2025-05-23 16:14 ` Bart Van Assche
0 siblings, 0 replies; 2+ messages in thread
From: Bart Van Assche @ 2025-05-23 16:14 UTC (permalink / raw)
To: naomi.chu, linux-scsi, linux-kernel, linux-arm-kernel,
linux-mediatek, Alim Akhtar, Avri Altman, James E.J. Bottomley,
Martin K. Petersen, Matthias Brugger, AngeloGioacchino Del Regno
Cc: wsd_upstream, peter.wang, alice.chao, chun-hung.wu, cc.chou, yi-fan.peng
On 5/23/25 3:10 AM, naomi.chu@mediatek.com wrote:
> +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);
Please use scoped_guard(spinlock_irqsave) instead of calling
spin_lock_irqsave() and spin_unlock_irqrestore() directly.
> + msleep(100);
Can ufshcd_is_linereset_fatal() be called from IRQ context? If so,
calling msleep() is not allowed. If it can't be called from IRQ
context, saving and restoring 'flags' is not necessary.
Bart.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-05-23 16:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-23 10:10 [PATCH 1/1] ufs: core: add fatal errors check for LINERESET naomi.chu
2025-05-23 16:14 ` Bart Van Assche
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®