public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] scsi: ufs: Add error handling of Auto-Hibernate
@ 2019-05-15  9:36 Stanley Chu
  2019-05-15  9:36 ` [PATCH v2 1/3] scsi: ufs: Do not overwrite Auto-Hibernate timer Stanley Chu
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Stanley Chu @ 2019-05-15  9:36 UTC (permalink / raw)
  To: linux-scsi, martin.petersen, avri.altman, alim.akhtar,
	pedrom.sousa
  Cc: marc.w.gonzalez, andy.teng, chun-hung.wu, kuohong.wang, evgreen,
	linux-mediatek, peter.wang, matthias.bgg, Stanley Chu,
	linux-arm-kernel, beanhuo

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.

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: Add error-handling of Auto-Hibernate
  scsi: ufs: Use re-factored Auto-Hibernate function

 drivers/scsi/ufs/ufshcd.c | 33 ++++++++++++++++++++++++++++++++-
 drivers/scsi/ufs/ufshcd.h |  5 +++++
 drivers/scsi/ufs/ufshci.h |  3 +++
 3 files changed, 40 insertions(+), 1 deletion(-)

-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/3] scsi: ufs: Do not overwrite Auto-Hibernate timer
  2019-05-15  9:36 [PATCH v2 0/3] scsi: ufs: Add error handling of Auto-Hibernate Stanley Chu
@ 2019-05-15  9:36 ` Stanley Chu
  2019-05-20  5:05   ` Alim Akhtar
  2019-05-15  9:36 ` [PATCH v2 2/3] scsi: ufs: Add error-handling of Auto-Hibernate Stanley Chu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Stanley Chu @ 2019-05-15  9:36 UTC (permalink / raw)
  To: linux-scsi, martin.petersen, avri.altman, alim.akhtar,
	pedrom.sousa
  Cc: marc.w.gonzalez, andy.teng, chun-hung.wu, kuohong.wang, evgreen,
	linux-mediatek, peter.wang, matthias.bgg, Stanley Chu,
	linux-arm-kernel, beanhuo

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().

Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
---
 drivers/scsi/ufs/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index e040f9dd9ff3..1665820c22fd 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -8309,7 +8309,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);
 	}
-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/3] scsi: ufs: Add error-handling of Auto-Hibernate
  2019-05-15  9:36 [PATCH v2 0/3] scsi: ufs: Add error handling of Auto-Hibernate Stanley Chu
  2019-05-15  9:36 ` [PATCH v2 1/3] scsi: ufs: Do not overwrite Auto-Hibernate timer Stanley Chu
@ 2019-05-15  9:36 ` Stanley Chu
  2019-05-15 10:03   ` [EXT] " Bean Huo (beanhuo)
  2019-05-20  5:37   ` Alim Akhtar
  2019-05-15  9:36 ` [PATCH v2 3/3] scsi: ufs: Use re-factored Auto-Hibernate function Stanley Chu
  2019-05-20  1:15 ` [PATCH v2 0/3] scsi: ufs: Add error handling of Auto-Hibernate Stanley Chu
  3 siblings, 2 replies; 12+ messages in thread
From: Stanley Chu @ 2019-05-15  9:36 UTC (permalink / raw)
  To: linux-scsi, martin.petersen, avri.altman, alim.akhtar,
	pedrom.sousa
  Cc: marc.w.gonzalez, andy.teng, chun-hung.wu, kuohong.wang, evgreen,
	linux-mediatek, peter.wang, matthias.bgg, Stanley Chu,
	linux-arm-kernel, beanhuo

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.

Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
---
 drivers/scsi/ufs/ufshcd.c | 31 +++++++++++++++++++++++++++++++
 drivers/scsi/ufs/ufshcd.h |  5 +++++
 drivers/scsi/ufs/ufshci.h |  3 +++
 3 files changed, 39 insertions(+)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 1665820c22fd..e6a86223a0d4 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -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_AH8_ERROR_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_AH8_ERROR_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_AH8_ERROR_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_AH8_ERROR_MASK & intr_status);
+
 	if (hba->errors)
 		ufshcd_check_errors(hba);
 
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index ecfa898b9ccc..994d73d03207 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -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)	\
diff --git a/drivers/scsi/ufs/ufshci.h b/drivers/scsi/ufs/ufshci.h
index 6fa889de5ee5..4bcb205f2077 100644
--- a/drivers/scsi/ufs/ufshci.h
+++ b/drivers/scsi/ufs/ufshci.h
@@ -148,6 +148,9 @@ enum {
 				UIC_HIBERNATE_EXIT |\
 				UIC_POWER_MODE)
 
+#define UFSHCD_UIC_AH8_ERROR_MASK	(UIC_HIBERNATE_ENTER |\
+					UIC_HIBERNATE_EXIT)
+
 #define UFSHCD_UIC_MASK		(UIC_COMMAND_COMPL | UFSHCD_UIC_PWR_MASK)
 
 #define UFSHCD_ERROR_MASK	(UIC_ERROR |\
-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 3/3] scsi: ufs: Use re-factored Auto-Hibernate function
  2019-05-15  9:36 [PATCH v2 0/3] scsi: ufs: Add error handling of Auto-Hibernate Stanley Chu
  2019-05-15  9:36 ` [PATCH v2 1/3] scsi: ufs: Do not overwrite Auto-Hibernate timer Stanley Chu
  2019-05-15  9:36 ` [PATCH v2 2/3] scsi: ufs: Add error-handling of Auto-Hibernate Stanley Chu
@ 2019-05-15  9:36 ` Stanley Chu
  2019-05-15 10:05   ` [EXT] " Bean Huo (beanhuo)
  2019-05-20  5:41   ` Alim Akhtar
  2019-05-20  1:15 ` [PATCH v2 0/3] scsi: ufs: Add error handling of Auto-Hibernate Stanley Chu
  3 siblings, 2 replies; 12+ messages in thread
From: Stanley Chu @ 2019-05-15  9:36 UTC (permalink / raw)
  To: linux-scsi, martin.petersen, avri.altman, alim.akhtar,
	pedrom.sousa
  Cc: marc.w.gonzalez, andy.teng, chun-hung.wu, kuohong.wang, evgreen,
	linux-mediatek, peter.wang, matthias.bgg, Stanley Chu,
	linux-arm-kernel, beanhuo

Use re-factored ufshcd_is_auto_hibern8_supported() function
in ufshcd_init() instead to make code more cleaner.

Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
---
 drivers/scsi/ufs/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index e6a86223a0d4..17af157c2cc1 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -8340,7 +8340,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);
 	}
-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* RE: [EXT] [PATCH v2 2/3] scsi: ufs: Add error-handling of Auto-Hibernate
  2019-05-15  9:36 ` [PATCH v2 2/3] scsi: ufs: Add error-handling of Auto-Hibernate Stanley Chu
@ 2019-05-15 10:03   ` Bean Huo (beanhuo)
  2019-05-20  5:37   ` Alim Akhtar
  1 sibling, 0 replies; 12+ messages in thread
From: Bean Huo (beanhuo) @ 2019-05-15 10:03 UTC (permalink / raw)
  To: Stanley Chu, linux-scsi@vger.kernel.org,
	martin.petersen@oracle.com, avri.altman@wdc.com,
	alim.akhtar@samsung.com, pedrom.sousa@synopsys.com
  Cc: marc.w.gonzalez@free.fr, andy.teng@mediatek.com,
	chun-hung.wu@mediatek.com, kuohong.wang@mediatek.com,
	evgreen@chromium.org, linux-mediatek@lists.infradead.org,
	peter.wang@mediatek.com, matthias.bgg@gmail.com,
	linux-arm-kernel@lists.infradead.org

Hi, Stanley
Thanks for update.

>Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>

>2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [EXT] [PATCH v2 3/3] scsi: ufs: Use re-factored Auto-Hibernate function
  2019-05-15  9:36 ` [PATCH v2 3/3] scsi: ufs: Use re-factored Auto-Hibernate function Stanley Chu
@ 2019-05-15 10:05   ` Bean Huo (beanhuo)
  2019-05-20  5:41   ` Alim Akhtar
  1 sibling, 0 replies; 12+ messages in thread
From: Bean Huo (beanhuo) @ 2019-05-15 10:05 UTC (permalink / raw)
  To: Stanley Chu, linux-scsi@vger.kernel.org,
	martin.petersen@oracle.com, avri.altman@wdc.com,
	alim.akhtar@samsung.com, pedrom.sousa@synopsys.com
  Cc: marc.w.gonzalez@free.fr, andy.teng@mediatek.com,
	chun-hung.wu@mediatek.com, kuohong.wang@mediatek.com,
	evgreen@chromium.org, linux-mediatek@lists.infradead.org,
	peter.wang@mediatek.com, matthias.bgg@gmail.com,
	linux-arm-kernel@lists.infradead.org

>
>Use re-factored ufshcd_is_auto_hibern8_supported() function in ufshcd_init()
>instead to make code more cleaner.
>
>Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>


Reviewed-by: Bean Huo <beanhuo@micron.com>



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 0/3] scsi: ufs: Add error handling of Auto-Hibernate
  2019-05-15  9:36 [PATCH v2 0/3] scsi: ufs: Add error handling of Auto-Hibernate Stanley Chu
                   ` (2 preceding siblings ...)
  2019-05-15  9:36 ` [PATCH v2 3/3] scsi: ufs: Use re-factored Auto-Hibernate function Stanley Chu
@ 2019-05-20  1:15 ` Stanley Chu
  3 siblings, 0 replies; 12+ messages in thread
From: Stanley Chu @ 2019-05-20  1:15 UTC (permalink / raw)
  To: linux-scsi@vger.kernel.org
  Cc: martin.petersen@oracle.com, marc.w.gonzalez@free.fr,
	Andy Teng (鄧如宏),
	Chun-Hung Wu (巫駿宏),
	Kuohong Wang (王國鴻), evgreen@chromium.org,
	avri.altman@wdc.com, linux-mediatek@lists.infradead.org,
	Peter Wang (王信友), alim.akhtar@samsung.com,
	matthias.bgg@gmail.com, pedrom.sousa@synopsys.com,
	linux-arm-kernel@lists.infradead.org, beanhuo@micron.com

Hi Avri, Alim, Pedro,

Gentle ping for this patch.

On Wed, 2019-05-15 at 17:36 +0800, Stanley Chu wrote:
> 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.
> 
> 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: Add error-handling of Auto-Hibernate
>   scsi: ufs: Use re-factored Auto-Hibernate function
> 
>  drivers/scsi/ufs/ufshcd.c | 33 ++++++++++++++++++++++++++++++++-
>  drivers/scsi/ufs/ufshcd.h |  5 +++++
>  drivers/scsi/ufs/ufshci.h |  3 +++
>  3 files changed, 40 insertions(+), 1 deletion(-)
> 
Thanks,
Stanley


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/3] scsi: ufs: Do not overwrite Auto-Hibernate timer
  2019-05-15  9:36 ` [PATCH v2 1/3] scsi: ufs: Do not overwrite Auto-Hibernate timer Stanley Chu
@ 2019-05-20  5:05   ` Alim Akhtar
  2019-05-20  5:47     ` Avri Altman
  0 siblings, 1 reply; 12+ messages in thread
From: Alim Akhtar @ 2019-05-20  5:05 UTC (permalink / raw)
  To: Stanley Chu, linux-scsi, martin.petersen, avri.altman,
	pedrom.sousa
  Cc: marc.w.gonzalez, andy.teng, chun-hung.wu, kuohong.wang, evgreen,
	linux-mediatek, peter.wang, matthias.bgg, linux-arm-kernel,
	beanhuo

Hello Stanley,

On 5/15/19 3:06 PM, Stanley Chu wrote:
> 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().
> 
> Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
> ---
>   drivers/scsi/ufs/ufshcd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index e040f9dd9ff3..1665820c22fd 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -8309,7 +8309,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);
>   	}
> 
Looks good to me,
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/3] scsi: ufs: Add error-handling of Auto-Hibernate
  2019-05-15  9:36 ` [PATCH v2 2/3] scsi: ufs: Add error-handling of Auto-Hibernate Stanley Chu
  2019-05-15 10:03   ` [EXT] " Bean Huo (beanhuo)
@ 2019-05-20  5:37   ` Alim Akhtar
  1 sibling, 0 replies; 12+ messages in thread
From: Alim Akhtar @ 2019-05-20  5:37 UTC (permalink / raw)
  To: Stanley Chu, linux-scsi, martin.petersen, avri.altman,
	pedrom.sousa
  Cc: marc.w.gonzalez, andy.teng, chun-hung.wu, kuohong.wang, evgreen,
	linux-mediatek, peter.wang, matthias.bgg, linux-arm-kernel,
	beanhuo

Hi Stanley,

On 5/15/19 3:06 PM, Stanley Chu wrote:
> 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.
> 
> Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
> ---
>   drivers/scsi/ufs/ufshcd.c | 31 +++++++++++++++++++++++++++++++
>   drivers/scsi/ufs/ufshcd.h |  5 +++++
>   drivers/scsi/ufs/ufshci.h |  3 +++
>   3 files changed, 39 insertions(+)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 1665820c22fd..e6a86223a0d4 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -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_AH8_ERROR_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_AH8_ERROR_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_AH8_ERROR_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_AH8_ERROR_MASK & intr_status);
> +
>   	if (hba->errors)
>   		ufshcd_check_errors(hba);
>   
> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> index ecfa898b9ccc..994d73d03207 100644
> --- a/drivers/scsi/ufs/ufshcd.h
> +++ b/drivers/scsi/ufs/ufshcd.h
> @@ -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)	\
> diff --git a/drivers/scsi/ufs/ufshci.h b/drivers/scsi/ufs/ufshci.h
> index 6fa889de5ee5..4bcb205f2077 100644
> --- a/drivers/scsi/ufs/ufshci.h
> +++ b/drivers/scsi/ufs/ufshci.h
> @@ -148,6 +148,9 @@ enum {
>   				UIC_HIBERNATE_EXIT |\
>   				UIC_POWER_MODE)
>   
> +#define UFSHCD_UIC_AH8_ERROR_MASK	(UIC_HIBERNATE_ENTER |\
> +					UIC_HIBERNATE_EXIT)
> +
>   #define UFSHCD_UIC_MASK		(UIC_COMMAND_COMPL | UFSHCD_UIC_PWR_MASK)
>   
>   #define UFSHCD_ERROR_MASK	(UIC_ERROR |\
> 
I don't have a way to test this patch, as my current platform does not 
support Auto Hibern8, over all this look ok to me.
Thanks,
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 3/3] scsi: ufs: Use re-factored Auto-Hibernate function
  2019-05-15  9:36 ` [PATCH v2 3/3] scsi: ufs: Use re-factored Auto-Hibernate function Stanley Chu
  2019-05-15 10:05   ` [EXT] " Bean Huo (beanhuo)
@ 2019-05-20  5:41   ` Alim Akhtar
  1 sibling, 0 replies; 12+ messages in thread
From: Alim Akhtar @ 2019-05-20  5:41 UTC (permalink / raw)
  To: Stanley Chu, linux-scsi, martin.petersen, avri.altman,
	pedrom.sousa
  Cc: marc.w.gonzalez, andy.teng, chun-hung.wu, kuohong.wang, evgreen,
	linux-mediatek, peter.wang, matthias.bgg, linux-arm-kernel,
	beanhuo



On 5/15/19 3:06 PM, Stanley Chu wrote:
> Use re-factored ufshcd_is_auto_hibern8_supported() function
> in ufshcd_init() instead to make code more cleaner.
> 
> Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
> ---
>   drivers/scsi/ufs/ufshcd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index e6a86223a0d4..17af157c2cc1 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -8340,7 +8340,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) {
After fixing the typo in above line (as pointed by Avri in patch 1), 
feel free to add
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>
>   		hba->ahit = FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK, 150) |
>   			    FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, 3);
>   	}
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH v2 1/3] scsi: ufs: Do not overwrite Auto-Hibernate timer
  2019-05-20  5:05   ` Alim Akhtar
@ 2019-05-20  5:47     ` Avri Altman
  2019-05-20  5:50       ` Stanley Chu
  0 siblings, 1 reply; 12+ messages in thread
From: Avri Altman @ 2019-05-20  5:47 UTC (permalink / raw)
  To: Alim Akhtar, Stanley Chu, linux-scsi@vger.kernel.org,
	martin.petersen@oracle.com, pedrom.sousa@synopsys.com
  Cc: marc.w.gonzalez@free.fr, andy.teng@mediatek.com,
	chun-hung.wu@mediatek.com, kuohong.wang@mediatek.com,
	evgreen@chromium.org, linux-mediatek@lists.infradead.org,
	peter.wang@mediatek.com, matthias.bgg@gmail.com,
	linux-arm-kernel@lists.infradead.org, beanhuo@micron.com


> 
> Hello Stanley,
> 
> On 5/15/19 3:06 PM, Stanley Chu wrote:
> > 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().
> >
> > Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
> > ---
> >   drivers/scsi/ufs/ufshcd.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> > index e040f9dd9ff3..1665820c22fd 100644
> > --- a/drivers/scsi/ufs/ufshcd.c
> > +++ b/drivers/scsi/ufs/ufshcd.c
> > @@ -8309,7 +8309,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) {
A typo?


> >   		hba->ahit = FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK,
> 150) |
> >   			    FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, 3);
> >   	}
> >
> Looks good to me,
> Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH v2 1/3] scsi: ufs: Do not overwrite Auto-Hibernate timer
  2019-05-20  5:47     ` Avri Altman
@ 2019-05-20  5:50       ` Stanley Chu
  0 siblings, 0 replies; 12+ messages in thread
From: Stanley Chu @ 2019-05-20  5:50 UTC (permalink / raw)
  To: Avri Altman
  Cc: martin.petersen@oracle.com, linux-scsi@vger.kernel.org,
	marc.w.gonzalez@free.fr, andy.teng@mediatek.com,
	chun-hung.wu@mediatek.com, kuohong.wang@mediatek.com,
	evgreen@chromium.org, linux-mediatek@lists.infradead.org,
	peter.wang@mediatek.com, Alim Akhtar, matthias.bgg@gmail.com,
	pedrom.sousa@synopsys.com, linux-arm-kernel@lists.infradead.org,
	beanhuo@micron.com

Hi Avri,

On Mon, 2019-05-20 at 05:47 +0000, Avri Altman wrote:
> > 
> > Hello Stanley,
> > 
> > On 5/15/19 3:06 PM, Stanley Chu wrote:
> > > 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().
> > >
> > > Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
> > > ---
> > >   drivers/scsi/ufs/ufshcd.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> > > index e040f9dd9ff3..1665820c22fd 100644
> > > --- a/drivers/scsi/ufs/ufshcd.c
> > > +++ b/drivers/scsi/ufs/ufshcd.c
> > > @@ -8309,7 +8309,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) {
> A typo?

Yes! Thanks for remind this.
Will fix it in next version.

> 
> 
> > >   		hba->ahit = FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK,
> > 150) |
> > >   			    FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, 3);
> > >   	}
> > >
> > Looks good to me,
> > Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>

Thanks.
Stanley


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-05-20  6:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-15  9:36 [PATCH v2 0/3] scsi: ufs: Add error handling of Auto-Hibernate Stanley Chu
2019-05-15  9:36 ` [PATCH v2 1/3] scsi: ufs: Do not overwrite Auto-Hibernate timer Stanley Chu
2019-05-20  5:05   ` Alim Akhtar
2019-05-20  5:47     ` Avri Altman
2019-05-20  5:50       ` Stanley Chu
2019-05-15  9:36 ` [PATCH v2 2/3] scsi: ufs: Add error-handling of Auto-Hibernate Stanley Chu
2019-05-15 10:03   ` [EXT] " Bean Huo (beanhuo)
2019-05-20  5:37   ` Alim Akhtar
2019-05-15  9:36 ` [PATCH v2 3/3] scsi: ufs: Use re-factored Auto-Hibernate function Stanley Chu
2019-05-15 10:05   ` [EXT] " Bean Huo (beanhuo)
2019-05-20  5:41   ` Alim Akhtar
2019-05-20  1:15 ` [PATCH v2 0/3] scsi: ufs: Add error handling of Auto-Hibernate Stanley Chu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox