Skip to contentSkip to conversation

scsi: ufs: Add error handling of Auto-Hibernate

PATCH Superseded Stanley Chu 2 participants 6 messages May 20, 2019 – May 21, 2019

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover scsi: ufs: Add error handling of Auto-Hibernate

Currently auto-hibernate is activated if host supports auto-hibern8 capability. However error-handling is not implemented, which makes the feature somewhat risky.

If either "Hibernate Enter" or "Hibernate Exit" fail during auto-hibernate flow, the corresponding interrupt "UIC_HIBERNATE_ENTER" or "UIC_HIBERNATE_EXIT" shall be raised according to UFS specification.

This patch adds auto-hibernate error-handling:

- Monitor "Hibernate Enter" and "Hibernate Exit" interrupts after auto-hibernate feature is activated.

- If fail happens, trigger error-handling just like "manual-hibernate" fail and apply the same recovery flow: schedule UFS error handler in ufshcd_check_errors(), and then do host reset and restore in UFS error handler.

v4:
- Replace original patch "[3/3] scsi: ufs: Use re-factored Auto-Hibernate function" by a new preparation patch "[2/3] scsi: ufs: Introduce ufshcd_is_auto_hibern8_supported()" for re-factoring ufshcd_is_auto_hibern8_supported (Avri Altman)
- Refine UIC mask definitions (Avri Altman)

v3:
- Fix typo in patch "scsi: ufs: Do not overwrite Auto-Hibernate timer" (Avri Altman)
- Rebase to Linux 5.2-rc1

v2:
- Fix sentences in commit message (Marc Gonzalez)
- Make "Auto-Hibernate" error detection more precise (Bean Huo)

Stanley Chu (3):
scsi: ufs: Do not overwrite Auto-Hibernate timer
scsi: ufs: Introduce ufshcd_is_auto_hibern8_supported()
scsi: ufs: Add error-handling of Auto-Hibernate

 drivers/scsi/ufs/ufshcd.c | 33 ++++++++++++++++++++++++++++++++-
 drivers/scsi/ufs/ufshcd.h |  5 +++++
 drivers/scsi/ufs/ufshci.h |  6 ++++--
 3 files changed, 41 insertions(+), 3 deletions(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH v4 1/3 scsi: ufs: Do not overwrite Auto-Hibernate timer

Some vendor-specific initialization flow may set its own auto-hibernate timer. In this case, do not overwrite timer value as "default value" in ufshcd_init().

---
 drivers/scsi/ufs/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/ufs/ufshcd.c +1 -1
index 8c1c551f2b42..ba04d07df279 100644
@@ -8312,7 +8312,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
 						UIC_LINK_HIBERN8_STATE);
 
 	/* Set the default auto-hiberate idle timer value to 150 ms */
-	if (hba->capabilities & MASK_AUTO_HIBERN8_SUPPORT) {
+	if ((hba->capabilities & MASK_AUTO_HIBERN8_SUPPORT) && !hba->ahit) {
 		hba->ahit = FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK, 150) |
 			    FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, 3);
 	}
Signature · 1 line
2.18.0
#2 lore raw

PATCH v4 2/3 scsi: ufs: Introduce ufshcd_is_auto_hibern8_supported()

In reply to Stanley Chu

ufshcd_is_auto_hibern8_supported() will be used elsewhere in the driver, thus refactor it for preparation.

---
 drivers/scsi/ufs/ufshcd.c | 2 +-
 drivers/scsi/ufs/ufshcd.h | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/scsi/ufs/ufshcd.c +1 -1
index ba04d07df279..c904625d9905 100644
@@ -8312,7 +8312,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
 						UIC_LINK_HIBERN8_STATE);
 
 	/* Set the default auto-hiberate idle timer value to 150 ms */
-	if ((hba->capabilities & MASK_AUTO_HIBERN8_SUPPORT) && !hba->ahit) {
+	if (ufshcd_is_auto_hibern8_supported(hba) && !hba->ahit) {
 		hba->ahit = FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK, 150) |
 			    FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, 3);
 	}
drivers/scsi/ufs/ufshcd.h +5 -0
index ecfa898b9ccc..994d73d03207 100644
@@ -740,6 +740,11 @@ return true;
 #endif
 }
 
+static inline bool ufshcd_is_auto_hibern8_supported(struct ufs_hba *hba)
+{
+	return (hba->capabilities & MASK_AUTO_HIBERN8_SUPPORT);
+}
+
 #define ufshcd_writel(hba, val, reg)	\
 	writel((val), (hba)->mmio_base + (reg))
 #define ufshcd_readl(hba, reg)	\
Signature · 1 line
2.18.0
#3 lore raw

RE: [PATCH v4 2/3] scsi: ufs: Introduce ufshcd_is_auto_hibern8_supported()

Quoted 3 lines

ufshcd_is_auto_hibern8_supported() will be used elsewhere in the driver, thus refactor it for preparation.

You missed a couple of spots, e.g. in ufshcd_auto_hibern8_enable and in ufs-sysfs.

Thanks,
Avri

#4 lore raw

RE: [PATCH v4 2/3] scsi: ufs: Introduce ufshcd_is_auto_hibern8_supported()

Hi Avri,

Quoted 4 lines · Avri Altman
Quoted 3 lines

ufshcd_is_auto_hibern8_supported() will be used elsewhere in the driver, thus refactor it for preparation.

You missed a couple of spots, e.g. in ufshcd_auto_hibern8_enable and in ufs-sysfs.

Yes...
Will re-factor them as well in next version.

Quoted 3 lines

Thanks,
Avri

Thanks,
Stanley

#5 lore raw

PATCH v4 3/3 scsi: ufs: Add error-handling of Auto-Hibernate

In reply to Stanley Chu

Currently auto-hibernate is activated if host supports auto-hibern8 capability. However error-handling is not implemented, which makes the feature somewhat risky.

If either "Hibernate Enter" or "Hibernate Exit" fail during auto-hibernate flow, the corresponding interrupt "UIC_HIBERNATE_ENTER" or "UIC_HIBERNATE_EXIT" shall be raised according to UFS specification.

This patch adds auto-hibernate error-handling:

- Monitor "Hibernate Enter" and "Hibernate Exit" interrupts after auto-hibernate feature is activated.

- If fail happens, trigger error-handling just like "manual-hibernate" fail and apply the same recovery flow: schedule UFS error handler in ufshcd_check_errors(), and then do host reset and restore in UFS error handler.

---
 drivers/scsi/ufs/ufshcd.c | 31 +++++++++++++++++++++++++++++++
 drivers/scsi/ufs/ufshci.h |  6 ++++--
 2 files changed, 35 insertions(+), 2 deletions(-)
drivers/scsi/ufs/ufshcd.c +31 -0
index c904625d9905..da304cbf9b0b 100644
@@ -5254,6 +5254,7 @@ static void ufshcd_err_handler(struct work_struct *work)
 			goto skip_err_handling;
 	}
 	if ((hba->saved_err & INT_FATAL_ERRORS) ||
+	    (hba->saved_err & UFSHCD_UIC_HIBERN8_MASK) ||
 	    ((hba->saved_err & UIC_ERROR) &&
 	    (hba->saved_uic_err & (UFSHCD_UIC_DL_PA_INIT_ERROR |
 				   UFSHCD_UIC_DL_NAC_RECEIVED_ERROR |
@@ -5413,6 +5414,23 @@ static void ufshcd_update_uic_error(struct ufs_hba *hba)
 			__func__, hba->uic_error);
 }
 
+static bool ufshcd_is_auto_hibern8_error(struct ufs_hba *hba,
+					 u32 intr_mask)
+{
+	if (!ufshcd_is_auto_hibern8_supported(hba))
+		return false;
+
+	if (!(intr_mask & UFSHCD_UIC_HIBERN8_MASK))
+		return false;
+
+	if (hba->active_uic_cmd &&
+	    (hba->active_uic_cmd->command == UIC_CMD_DME_HIBER_ENTER ||
+	    hba->active_uic_cmd->command == UIC_CMD_DME_HIBER_EXIT))
+		return false;
+
+	return true;
+}
+
 /**
  * ufshcd_check_errors - Check for errors that need s/w attention
  * @hba: per-adapter instance
@@ -5431,6 +5449,15 @@ static void ufshcd_check_errors(struct ufs_hba *hba)
 			queue_eh_work = true;
 	}
 
+	if (hba->errors & UFSHCD_UIC_HIBERN8_MASK) {
+		dev_err(hba->dev,
+			"%s: Auto Hibern8 %s failed - status: 0x%08x, upmcrs: 0x%08x\n",
+			__func__, (hba->errors & UIC_HIBERNATE_ENTER) ?
+			"Enter" : "Exit",
+			hba->errors, ufshcd_get_upmcrs(hba));
+		queue_eh_work = true;
+	}
+
 	if (queue_eh_work) {
 		/*
 		 * update the transfer error masks to sticky bits, let's do this
@@ -5493,6 +5520,10 @@ static void ufshcd_tmc_handler(struct ufs_hba *hba)
 static void ufshcd_sl_intr(struct ufs_hba *hba, u32 intr_status)
 {
 	hba->errors = UFSHCD_ERROR_MASK & intr_status;
+
+	if (ufshcd_is_auto_hibern8_error(hba, intr_status))
+		hba->errors |= (UFSHCD_UIC_HIBERN8_MASK & intr_status);
+
 	if (hba->errors)
 		ufshcd_check_errors(hba);
 
drivers/scsi/ufs/ufshci.h +4 -2
index 6fa889de5ee5..dbb75cd28dc8 100644
@@ -144,8 +144,10 @@ enum {
 #define CONTROLLER_FATAL_ERROR			0x10000
 #define SYSTEM_BUS_FATAL_ERROR			0x20000
 
-#define UFSHCD_UIC_PWR_MASK	(UIC_HIBERNATE_ENTER |\
-				UIC_HIBERNATE_EXIT |\
+#define UFSHCD_UIC_HIBERN8_MASK	(UIC_HIBERNATE_ENTER |\
+				UIC_HIBERNATE_EXIT)
+
+#define UFSHCD_UIC_PWR_MASK	(UFSHCD_UIC_HIBERN8_MASK |\
 				UIC_POWER_MODE)
 
 #define UFSHCD_UIC_MASK		(UIC_COMMAND_COMPL | UFSHCD_UIC_PWR_MASK)
Signature · 1 line
2.18.0