linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] scsi: ufs-pci: Fixes for Intel controllers
@ 2020-12-07  8:31 Adrian Hunter
  2020-12-07  8:31 ` [PATCH 1/4] scsi: ufs-pci: Fix restore from S4 " Adrian Hunter
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Adrian Hunter @ 2020-12-07  8:31 UTC (permalink / raw)
  To: Martin K . Petersen, James E . J . Bottomley
  Cc: linux-scsi, linux-kernel, Alim Akhtar, Avri Altman, Bean Huo,
	Can Guo, Stanley Chu

Hi

Here are some small fixes / amendments.

Adrian Hunter (4):
      scsi: ufs-pci: Fix restore from S4 for Intel controllers
      scsi: ufs-pci: Ensure UFS device is in PowerDown mode for suspend-to-disk ->poweroff()
      scsi: ufs-pci: Fix recovery from hibernate exit errors for Intel controllers
      scsi: ufs-pci: Enable UFSHCD_CAP_RPM_AUTOSUSPEND for Intel controllers

 drivers/scsi/ufs/ufshcd-pci.c | 73 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 71 insertions(+), 2 deletions(-)

Regards
Adrian

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

* [PATCH 1/4] scsi: ufs-pci: Fix restore from S4 for Intel controllers
  2020-12-07  8:31 [PATCH 0/4] scsi: ufs-pci: Fixes for Intel controllers Adrian Hunter
@ 2020-12-07  8:31 ` Adrian Hunter
  2020-12-07  8:31 ` [PATCH 2/4] scsi: ufs-pci: Ensure UFS device is in PowerDown mode for suspend-to-disk ->poweroff() Adrian Hunter
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Adrian Hunter @ 2020-12-07  8:31 UTC (permalink / raw)
  To: Martin K . Petersen, James E . J . Bottomley
  Cc: linux-scsi, linux-kernel, Alim Akhtar, Avri Altman, Bean Huo,
	Can Guo, Stanley Chu

Currently, ufshcd-pci is the only UFS driver with support for
suspend-to-disk PM callbacks (i.e. freeze/thaw/restore/poweroff). These
callbacks are set by the macro SET_SYSTEM_SLEEP_PM_OPS to the same
functions as system suspend/resume. That will work with spm_lvl 5 because
spm_lvl 5 will result in a full restore for the ->restore() callback.
In the absence of a full restore, the host controller registers will
have values set up by the restore kernel (the kernel that boots and
loads the restore image) which are not necessarily the same. However it
turns out, the only registers that sometimes need restore are the base
address registers. This has gone un-noticed because, depending on IOMMU
settings, the kernel can end up allocating the same addresses every
time.

For Intel controllers, an spm_lvl other than 5 can be used, so to support
S4 (suspend-to-disk) with spm_lvl other than 5, restore the base address
registers.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/scsi/ufs/ufshcd-pci.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/scsi/ufs/ufshcd-pci.c b/drivers/scsi/ufs/ufshcd-pci.c
index df3a564c3e33..360c25f1f061 100644
--- a/drivers/scsi/ufs/ufshcd-pci.c
+++ b/drivers/scsi/ufs/ufshcd-pci.c
@@ -163,6 +163,24 @@ static void ufs_intel_common_exit(struct ufs_hba *hba)
 	intel_ltr_hide(hba->dev);
 }
 
+static int ufs_intel_resume(struct ufs_hba *hba, enum ufs_pm_op op)
+{
+	/*
+	 * To support S4 (suspend-to-disk) with spm_lvl other than 5, the base
+	 * address registers must be restored because the restore kernel can
+	 * have used different addresses.
+	 */
+	ufshcd_writel(hba, lower_32_bits(hba->utrdl_dma_addr),
+		      REG_UTP_TRANSFER_REQ_LIST_BASE_L);
+	ufshcd_writel(hba, upper_32_bits(hba->utrdl_dma_addr),
+		      REG_UTP_TRANSFER_REQ_LIST_BASE_H);
+	ufshcd_writel(hba, lower_32_bits(hba->utmrdl_dma_addr),
+		      REG_UTP_TASK_REQ_LIST_BASE_L);
+	ufshcd_writel(hba, upper_32_bits(hba->utmrdl_dma_addr),
+		      REG_UTP_TASK_REQ_LIST_BASE_H);
+	return 0;
+}
+
 static int ufs_intel_ehl_init(struct ufs_hba *hba)
 {
 	hba->quirks |= UFSHCD_QUIRK_BROKEN_AUTO_HIBERN8;
@@ -174,6 +192,7 @@ static struct ufs_hba_variant_ops ufs_intel_cnl_hba_vops = {
 	.init			= ufs_intel_common_init,
 	.exit			= ufs_intel_common_exit,
 	.link_startup_notify	= ufs_intel_link_startup_notify,
+	.resume			= ufs_intel_resume,
 };
 
 static struct ufs_hba_variant_ops ufs_intel_ehl_hba_vops = {
@@ -181,6 +200,7 @@ static struct ufs_hba_variant_ops ufs_intel_ehl_hba_vops = {
 	.init			= ufs_intel_ehl_init,
 	.exit			= ufs_intel_common_exit,
 	.link_startup_notify	= ufs_intel_link_startup_notify,
+	.resume			= ufs_intel_resume,
 };
 
 #ifdef CONFIG_PM_SLEEP
-- 
2.17.1


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

* [PATCH 2/4] scsi: ufs-pci: Ensure UFS device is in PowerDown mode for suspend-to-disk ->poweroff()
  2020-12-07  8:31 [PATCH 0/4] scsi: ufs-pci: Fixes for Intel controllers Adrian Hunter
  2020-12-07  8:31 ` [PATCH 1/4] scsi: ufs-pci: Fix restore from S4 " Adrian Hunter
@ 2020-12-07  8:31 ` Adrian Hunter
  2020-12-07  8:31 ` [PATCH 3/4] scsi: ufs-pci: Fix recovery from hibernate exit errors for Intel controllers Adrian Hunter
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Adrian Hunter @ 2020-12-07  8:31 UTC (permalink / raw)
  To: Martin K . Petersen, James E . J . Bottomley
  Cc: linux-scsi, linux-kernel, Alim Akhtar, Avri Altman, Bean Huo,
	Can Guo, Stanley Chu

The expectation for suspend-to-disk is that devices will be powered-off,
so the UFS device should be put in PowerDown mode. If spm_lvl is not 5,
then that will not happen. Change the pm callbacks to force spm_lvl 5 for
suspend-to-disk poweroff.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/scsi/ufs/ufshcd-pci.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd-pci.c b/drivers/scsi/ufs/ufshcd-pci.c
index 360c25f1f061..5d33c39fa82f 100644
--- a/drivers/scsi/ufs/ufshcd-pci.c
+++ b/drivers/scsi/ufs/ufshcd-pci.c
@@ -227,6 +227,30 @@ static int ufshcd_pci_resume(struct device *dev)
 {
 	return ufshcd_system_resume(dev_get_drvdata(dev));
 }
+
+/**
+ * ufshcd_pci_poweroff - suspend-to-disk poweroff function
+ * @dev: pointer to PCI device handle
+ *
+ * Returns 0 if successful
+ * Returns non-zero otherwise
+ */
+static int ufshcd_pci_poweroff(struct device *dev)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+	int spm_lvl = hba->spm_lvl;
+	int ret;
+
+	/*
+	 * For poweroff we need to set the UFS device to PowerDown mode.
+	 * Force spm_lvl to ensure that.
+	 */
+	hba->spm_lvl = 5;
+	ret = ufshcd_system_suspend(hba);
+	hba->spm_lvl = spm_lvl;
+	return ret;
+}
+
 #endif /* !CONFIG_PM_SLEEP */
 
 #ifdef CONFIG_PM
@@ -322,8 +346,14 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 }
 
 static const struct dev_pm_ops ufshcd_pci_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(ufshcd_pci_suspend,
-				ufshcd_pci_resume)
+#ifdef CONFIG_PM_SLEEP
+	.suspend	= ufshcd_pci_suspend,
+	.resume		= ufshcd_pci_resume,
+	.freeze		= ufshcd_pci_suspend,
+	.thaw		= ufshcd_pci_resume,
+	.poweroff	= ufshcd_pci_poweroff,
+	.restore	= ufshcd_pci_resume,
+#endif
 	SET_RUNTIME_PM_OPS(ufshcd_pci_runtime_suspend,
 			   ufshcd_pci_runtime_resume,
 			   ufshcd_pci_runtime_idle)
-- 
2.17.1


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

* [PATCH 3/4] scsi: ufs-pci: Fix recovery from hibernate exit errors for Intel controllers
  2020-12-07  8:31 [PATCH 0/4] scsi: ufs-pci: Fixes for Intel controllers Adrian Hunter
  2020-12-07  8:31 ` [PATCH 1/4] scsi: ufs-pci: Fix restore from S4 " Adrian Hunter
  2020-12-07  8:31 ` [PATCH 2/4] scsi: ufs-pci: Ensure UFS device is in PowerDown mode for suspend-to-disk ->poweroff() Adrian Hunter
@ 2020-12-07  8:31 ` Adrian Hunter
  2020-12-07  8:31 ` [PATCH 4/4] scsi: ufs-pci: Enable UFSHCD_CAP_RPM_AUTOSUSPEND " Adrian Hunter
  2020-12-09  2:46 ` [PATCH 0/4] scsi: ufs-pci: Fixes " Martin K. Petersen
  4 siblings, 0 replies; 6+ messages in thread
From: Adrian Hunter @ 2020-12-07  8:31 UTC (permalink / raw)
  To: Martin K . Petersen, James E . J . Bottomley
  Cc: linux-scsi, linux-kernel, Alim Akhtar, Avri Altman, Bean Huo,
	Can Guo, Stanley Chu

Intel controllers can end up in an unrecoverable state after a hibernate
exit error unless a full reset and restore is done before anything else.
Force that to happen.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/scsi/ufs/ufshcd-pci.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/scsi/ufs/ufshcd-pci.c b/drivers/scsi/ufs/ufshcd-pci.c
index 5d33c39fa82f..888d8c9ca3a5 100644
--- a/drivers/scsi/ufs/ufshcd-pci.c
+++ b/drivers/scsi/ufs/ufshcd-pci.c
@@ -178,6 +178,23 @@ static int ufs_intel_resume(struct ufs_hba *hba, enum ufs_pm_op op)
 		      REG_UTP_TASK_REQ_LIST_BASE_L);
 	ufshcd_writel(hba, upper_32_bits(hba->utmrdl_dma_addr),
 		      REG_UTP_TASK_REQ_LIST_BASE_H);
+
+	if (ufshcd_is_link_hibern8(hba)) {
+		int ret = ufshcd_uic_hibern8_exit(hba);
+
+		if (!ret) {
+			ufshcd_set_link_active(hba);
+		} else {
+			dev_err(hba->dev, "%s: hibern8 exit failed %d\n",
+				__func__, ret);
+			/*
+			 * Force reset and restore. Any other actions can lead
+			 * to an unrecoverable state.
+			 */
+			ufshcd_set_link_off(hba);
+		}
+	}
+
 	return 0;
 }
 
-- 
2.17.1


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

* [PATCH 4/4] scsi: ufs-pci: Enable UFSHCD_CAP_RPM_AUTOSUSPEND for Intel controllers
  2020-12-07  8:31 [PATCH 0/4] scsi: ufs-pci: Fixes for Intel controllers Adrian Hunter
                   ` (2 preceding siblings ...)
  2020-12-07  8:31 ` [PATCH 3/4] scsi: ufs-pci: Fix recovery from hibernate exit errors for Intel controllers Adrian Hunter
@ 2020-12-07  8:31 ` Adrian Hunter
  2020-12-09  2:46 ` [PATCH 0/4] scsi: ufs-pci: Fixes " Martin K. Petersen
  4 siblings, 0 replies; 6+ messages in thread
From: Adrian Hunter @ 2020-12-07  8:31 UTC (permalink / raw)
  To: Martin K . Petersen, James E . J . Bottomley
  Cc: linux-scsi, linux-kernel, Alim Akhtar, Avri Altman, Bean Huo,
	Can Guo, Stanley Chu

Enable runtime PM auto-suspend by default for Intel host controllers.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/scsi/ufs/ufshcd-pci.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/ufs/ufshcd-pci.c b/drivers/scsi/ufs/ufshcd-pci.c
index 888d8c9ca3a5..fadd566025b8 100644
--- a/drivers/scsi/ufs/ufshcd-pci.c
+++ b/drivers/scsi/ufs/ufshcd-pci.c
@@ -148,6 +148,8 @@ static int ufs_intel_common_init(struct ufs_hba *hba)
 {
 	struct intel_host *host;
 
+	hba->caps |= UFSHCD_CAP_RPM_AUTOSUSPEND;
+
 	host = devm_kzalloc(hba->dev, sizeof(*host), GFP_KERNEL);
 	if (!host)
 		return -ENOMEM;
-- 
2.17.1


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

* Re: [PATCH 0/4] scsi: ufs-pci: Fixes for Intel controllers
  2020-12-07  8:31 [PATCH 0/4] scsi: ufs-pci: Fixes for Intel controllers Adrian Hunter
                   ` (3 preceding siblings ...)
  2020-12-07  8:31 ` [PATCH 4/4] scsi: ufs-pci: Enable UFSHCD_CAP_RPM_AUTOSUSPEND " Adrian Hunter
@ 2020-12-09  2:46 ` Martin K. Petersen
  4 siblings, 0 replies; 6+ messages in thread
From: Martin K. Petersen @ 2020-12-09  2:46 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Martin K . Petersen, James E . J . Bottomley, linux-scsi,
	linux-kernel, Alim Akhtar, Avri Altman, Bean Huo, Can Guo,
	Stanley Chu


Adrian,

> Here are some small fixes / amendments.
>
> Adrian Hunter (4):
>       scsi: ufs-pci: Fix restore from S4 for Intel controllers
>       scsi: ufs-pci: Ensure UFS device is in PowerDown mode for suspend-to-disk ->poweroff()
>       scsi: ufs-pci: Fix recovery from hibernate exit errors for Intel controllers
>       scsi: ufs-pci: Enable UFSHCD_CAP_RPM_AUTOSUSPEND for Intel controllers

Applied to 5.11/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2020-12-09  2:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-07  8:31 [PATCH 0/4] scsi: ufs-pci: Fixes for Intel controllers Adrian Hunter
2020-12-07  8:31 ` [PATCH 1/4] scsi: ufs-pci: Fix restore from S4 " Adrian Hunter
2020-12-07  8:31 ` [PATCH 2/4] scsi: ufs-pci: Ensure UFS device is in PowerDown mode for suspend-to-disk ->poweroff() Adrian Hunter
2020-12-07  8:31 ` [PATCH 3/4] scsi: ufs-pci: Fix recovery from hibernate exit errors for Intel controllers Adrian Hunter
2020-12-07  8:31 ` [PATCH 4/4] scsi: ufs-pci: Enable UFSHCD_CAP_RPM_AUTOSUSPEND " Adrian Hunter
2020-12-09  2:46 ` [PATCH 0/4] scsi: ufs-pci: Fixes " Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).