linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers
@ 2023-12-21 19:09 Andrew Halaney
  2023-12-21 19:09 ` [PATCH RFC v3 01/11] scsi: ufs: qcom: Perform read back after writing reset bit Andrew Halaney
                   ` (11 more replies)
  0 siblings, 12 replies; 31+ messages in thread
From: Andrew Halaney @ 2023-12-21 19:09 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Andrew Halaney, Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

This is an RFC because I'm not all the confident in this topic. UFS has
a lot of mb() variants used, most with comments saying "ensure this
takes effect before continuing". mb()'s aren't really the way to
guarantee that, a read back is the best method.

Some of these though I think could go a step further and remove the mb()
variant without a read back. As far as I can tell there's no real reason
to ensure it takes effect in most cases (there's no delay() or anything
afterwards, and eventually another readl()/writel() happens which is by
definition ordered).

In this current series I don't do that as I wasn't totally convinced,
but it should be considered when reviewing.

Hopefully this series gets enough interest where we can confidently
merge the final result after review helps improve it.

I'll be travelling a good bit the next 2ish weeks, so expect little
response until my return.

Thanks in advance for the help,
Andrew

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
Changes in v3:
- Nothing changed, I just failed to send with b4 (resulting in 2 half
  sent v2 series on list)
- Link to v2: https://lore.kernel.org/r/pnwsdz3i2liivjxvtfwq6tijotgh5adyqipjjb5wdvo4jpu7yv@j6fkshm5ipue

Changes in v2:
- Added review tags for original patch
- Added new patches to address all other memory barriers used

- Link to v1: https://lore.kernel.org/r/20231208-ufs-reset-ensure-effect-before-delay-v1-1-8a0f82d7a09e@redhat.com

---
Andrew Halaney (11):
      scsi: ufs: qcom: Perform read back after writing reset bit
      scsi: ufs: qcom: Perform read back after writing REG_UFS_SYS1CLK_1US
      scsi: ufs: qcom: Perform read back after writing testbus config
      scsi: ufs: qcom: Perform read back after writing unipro mode
      scsi: ufs: qcom: Perform read back after writing CGC enable
      scsi: ufs: cdns-pltfrm: Perform read back after writing HCLKDIV
      scsi: ufs: core: Perform read back after writing UTP_TASK_REQ_LIST_BASE_H
      scsi: ufs: core: Perform read back after disabling interrupts
      scsi: ufs: core: Perform read back after disabling UIC_COMMAND_COMPL
      scsi: ufs: core: Perform read back to commit doorbell
      scsi: ufs: core: Perform read back before writing run/stop regs

 drivers/ufs/core/ufshcd.c      | 10 +++++-----
 drivers/ufs/host/cdns-pltfrm.c |  2 +-
 drivers/ufs/host/ufs-qcom.c    | 14 ++++++--------
 drivers/ufs/host/ufs-qcom.h    | 12 ++++++------
 4 files changed, 18 insertions(+), 20 deletions(-)
---
base-commit: 20d857259d7d10cd0d5e8b60608455986167cfad
change-id: 20231208-ufs-reset-ensure-effect-before-delay-6e06899d5419

Best regards,
-- 
Andrew Halaney <ahalaney@redhat.com>


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

* [PATCH RFC v3 01/11] scsi: ufs: qcom: Perform read back after writing reset bit
  2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
@ 2023-12-21 19:09 ` Andrew Halaney
  2023-12-22  8:18   ` Can Guo
  2023-12-21 19:09 ` [PATCH RFC v3 02/11] scsi: ufs: qcom: Perform read back after writing REG_UFS_SYS1CLK_1US Andrew Halaney
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 31+ messages in thread
From: Andrew Halaney @ 2023-12-21 19:09 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Andrew Halaney, Will Deacon, linux-arm-msm, linux-scsi,
	linux-kernel, Manivannan Sadhasivam

Currently, the reset bit for the UFS provided reset controller (used by
its phy) is written to, and then a mb() happens to try and ensure that
hit the device. Immediately afterwards a usleep_range() occurs.

mb() ensure that the write completes, but completion doesn't mean that
it isn't stored in a buffer somewhere. The recommendation for
ensuring this bit has taken effect on the device is to perform a read
back to force it to make it all the way to the device. This is
documented in device-io.rst and a talk by Will Deacon on this can
be seen over here:

    https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678

Let's do that to ensure the bit hits the device. By doing so and
guaranteeing the ordering against the immediately following
usleep_range(), the mb() can safely be removed.

Fixes: 81c0fc51b7a7 ("ufs-qcom: add support for Qualcomm Technologies Inc platforms")
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
 drivers/ufs/host/ufs-qcom.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/ufs/host/ufs-qcom.h b/drivers/ufs/host/ufs-qcom.h
index 9dd9a391ebb7..b9de170983c9 100644
--- a/drivers/ufs/host/ufs-qcom.h
+++ b/drivers/ufs/host/ufs-qcom.h
@@ -151,10 +151,10 @@ static inline void ufs_qcom_assert_reset(struct ufs_hba *hba)
 	ufshcd_rmwl(hba, UFS_PHY_SOFT_RESET, UFS_PHY_SOFT_RESET, REG_UFS_CFG1);
 
 	/*
-	 * Make sure assertion of ufs phy reset is written to
-	 * register before returning
+	 * Dummy read to ensure the write takes effect before doing any sort
+	 * of delay
 	 */
-	mb();
+	ufshcd_readl(hba, REG_UFS_CFG1);
 }
 
 static inline void ufs_qcom_deassert_reset(struct ufs_hba *hba)
@@ -162,10 +162,10 @@ static inline void ufs_qcom_deassert_reset(struct ufs_hba *hba)
 	ufshcd_rmwl(hba, UFS_PHY_SOFT_RESET, 0, REG_UFS_CFG1);
 
 	/*
-	 * Make sure de-assertion of ufs phy reset is written to
-	 * register before returning
+	 * Dummy read to ensure the write takes effect before doing any sort
+	 * of delay
 	 */
-	mb();
+	ufshcd_readl(hba, REG_UFS_CFG1);
 }
 
 /* Host controller hardware version: major.minor.step */

-- 
2.43.0


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

* [PATCH RFC v3 02/11] scsi: ufs: qcom: Perform read back after writing REG_UFS_SYS1CLK_1US
  2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
  2023-12-21 19:09 ` [PATCH RFC v3 01/11] scsi: ufs: qcom: Perform read back after writing reset bit Andrew Halaney
@ 2023-12-21 19:09 ` Andrew Halaney
  2023-12-22  8:18   ` Can Guo
  2023-12-21 19:09 ` [PATCH RFC v3 03/11] scsi: ufs: qcom: Perform read back after writing testbus config Andrew Halaney
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 31+ messages in thread
From: Andrew Halaney @ 2023-12-21 19:09 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Andrew Halaney, Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

Currently after writing to REG_UFS_SYS1CLK_1US a mb() is used to ensure
that write has gone through to the device.

mb() ensure that the write completes, but completion doesn't mean that
it isn't stored in a buffer somewhere. The recommendation for
ensuring this bit has taken effect on the device is to perform a read
back to force it to make it all the way to the device. This is
documented in device-io.rst and a talk by Will Deacon on this can
be seen over here:

    https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678

Let's do that to ensure the bit hits the device. Because the mb()'s
purpose wasn't to add extra ordering (on top of the ordering guaranteed
by writel()/readl()), it can safely be removed.

Fixes: f06fcc7155dc ("scsi: ufs-qcom: add QUniPro hardware support and power optimizations")
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
 drivers/ufs/host/ufs-qcom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index 480787048e75..4c15c8a1d058 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -501,7 +501,7 @@ static int ufs_qcom_cfg_timers(struct ufs_hba *hba, u32 gear,
 		 * make sure above write gets applied before we return from
 		 * this function.
 		 */
-		mb();
+		ufshcd_readl(hba, REG_UFS_SYS1CLK_1US);
 	}
 
 	return 0;

-- 
2.43.0


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

* [PATCH RFC v3 03/11] scsi: ufs: qcom: Perform read back after writing testbus config
  2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
  2023-12-21 19:09 ` [PATCH RFC v3 01/11] scsi: ufs: qcom: Perform read back after writing reset bit Andrew Halaney
  2023-12-21 19:09 ` [PATCH RFC v3 02/11] scsi: ufs: qcom: Perform read back after writing REG_UFS_SYS1CLK_1US Andrew Halaney
@ 2023-12-21 19:09 ` Andrew Halaney
  2023-12-22  8:20   ` Can Guo
  2023-12-21 19:09 ` [PATCH RFC v3 04/11] scsi: ufs: qcom: Perform read back after writing unipro mode Andrew Halaney
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 31+ messages in thread
From: Andrew Halaney @ 2023-12-21 19:09 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Andrew Halaney, Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

Currently, the testbus configuration is written and completed with an
mb().

mb() ensure that the write completes, but completion doesn't mean
that it isn't stored in a buffer somewhere. The recommendation for
ensuring this bit has taken effect on the device is to perform a read
back to force it to make it all the way to the device. This is
documented in device-io.rst and a talk by Will Deacon on this can
be seen over here:

    https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678

Let's do that to ensure the bit hits the device. Because the mb()'s
purpose wasn't to add extra ordering (on top of the ordering guaranteed
by writel()/readl()), it can safely be removed.

Fixes: 9c46b8676271 ("scsi: ufs-qcom: dump additional testbus registers")
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
 drivers/ufs/host/ufs-qcom.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index 4c15c8a1d058..6df2ab3b6f23 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -1332,6 +1332,9 @@ static void ufs_qcom_enable_test_bus(struct ufs_qcom_host *host)
 	ufshcd_rmwl(host->hba, UFS_REG_TEST_BUS_EN,
 			UFS_REG_TEST_BUS_EN, REG_UFS_CFG1);
 	ufshcd_rmwl(host->hba, TEST_BUS_EN, TEST_BUS_EN, REG_UFS_CFG1);
+
+	/* dummy read to ensure this has been enabled prior to returning */
+	ufshcd_readl(host->hba, REG_UFS_CFG1);
 }
 
 static void ufs_qcom_get_default_testbus_cfg(struct ufs_qcom_host *host)
@@ -1429,11 +1432,6 @@ int ufs_qcom_testbus_config(struct ufs_qcom_host *host)
 		    (u32)host->testbus.select_minor << offset,
 		    reg);
 	ufs_qcom_enable_test_bus(host);
-	/*
-	 * Make sure the test bus configuration is
-	 * committed before returning.
-	 */
-	mb();
 
 	return 0;
 }

-- 
2.43.0


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

* [PATCH RFC v3 04/11] scsi: ufs: qcom: Perform read back after writing unipro mode
  2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
                   ` (2 preceding siblings ...)
  2023-12-21 19:09 ` [PATCH RFC v3 03/11] scsi: ufs: qcom: Perform read back after writing testbus config Andrew Halaney
@ 2023-12-21 19:09 ` Andrew Halaney
  2023-12-22  8:23   ` Can Guo
  2023-12-21 19:09 ` [PATCH RFC v3 05/11] scsi: ufs: qcom: Perform read back after writing CGC enable Andrew Halaney
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 31+ messages in thread
From: Andrew Halaney @ 2023-12-21 19:09 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Andrew Halaney, Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

Currently, the QUNIPRO_SEL bit is written to and then an mb() is used to
ensure that completes before continuing.

mb() ensure that the write completes, but completion doesn't mean that
it isn't stored in a buffer somewhere. The recommendation for
ensuring this bit has taken effect on the device is to perform a read
back to force it to make it all the way to the device. This is
documented in device-io.rst and a talk by Will Deacon on this can
be seen over here:

    https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678

Let's do that to ensure the bit hits the device. Because the mb()'s
purpose wasn't to add extra ordering (on top of the ordering guaranteed
by writel()/readl()), it can safely be removed.

Fixes: f06fcc7155dc ("scsi: ufs-qcom: add QUniPro hardware support and power optimizations")
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
 drivers/ufs/host/ufs-qcom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index 6df2ab3b6f23..ab1ff7432d11 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -280,7 +280,7 @@ static void ufs_qcom_select_unipro_mode(struct ufs_qcom_host *host)
 		ufshcd_rmwl(host->hba, QUNIPRO_G4_SEL, 0, REG_UFS_CFG0);
 
 	/* make sure above configuration is applied before we return */
-	mb();
+	ufshcd_readl(host->hba, REG_UFS_CFG1);
 }
 
 /*

-- 
2.43.0


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

* [PATCH RFC v3 05/11] scsi: ufs: qcom: Perform read back after writing CGC enable
  2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
                   ` (3 preceding siblings ...)
  2023-12-21 19:09 ` [PATCH RFC v3 04/11] scsi: ufs: qcom: Perform read back after writing unipro mode Andrew Halaney
@ 2023-12-21 19:09 ` Andrew Halaney
  2023-12-22  8:25   ` Can Guo
  2023-12-21 19:09 ` [PATCH RFC v3 06/11] scsi: ufs: cdns-pltfrm: Perform read back after writing HCLKDIV Andrew Halaney
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 31+ messages in thread
From: Andrew Halaney @ 2023-12-21 19:09 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Andrew Halaney, Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

Currently, the CGC enable bit is written and then an mb() is used to
ensure that completes before continuing.

mb() ensure that the write completes, but completion doesn't mean that
it isn't stored in a buffer somewhere. The recommendation for
ensuring this bit has taken effect on the device is to perform a read
back to force it to make it all the way to the device. This is
documented in device-io.rst and a talk by Will Deacon on this can
be seen over here:

    https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678

Let's do that to ensure the bit hits the device. Because the mb()'s
purpose wasn't to add extra ordering (on top of the ordering guaranteed
by writel()/readl()), it can safely be removed.

Fixes: 81c0fc51b7a7 ("ufs-qcom: add support for Qualcomm Technologies Inc platforms")
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
 drivers/ufs/host/ufs-qcom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index ab1ff7432d11..3db19591d008 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -409,7 +409,7 @@ static void ufs_qcom_enable_hw_clk_gating(struct ufs_hba *hba)
 		    REG_UFS_CFG2);
 
 	/* Ensure that HW clock gating is enabled before next operations */
-	mb();
+	ufshcd_readl(hba, REG_UFS_CFG2);
 }
 
 static int ufs_qcom_hce_enable_notify(struct ufs_hba *hba,

-- 
2.43.0


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

* [PATCH RFC v3 06/11] scsi: ufs: cdns-pltfrm: Perform read back after writing HCLKDIV
  2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
                   ` (4 preceding siblings ...)
  2023-12-21 19:09 ` [PATCH RFC v3 05/11] scsi: ufs: qcom: Perform read back after writing CGC enable Andrew Halaney
@ 2023-12-21 19:09 ` Andrew Halaney
  2023-12-21 19:09 ` [PATCH RFC v3 07/11] scsi: ufs: core: Perform read back after writing UTP_TASK_REQ_LIST_BASE_H Andrew Halaney
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 31+ messages in thread
From: Andrew Halaney @ 2023-12-21 19:09 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Andrew Halaney, Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

Currently, HCLKDIV is written to and then completed with an mb().

mb() ensure that the write completes, but completion doesn't mean that
it isn't stored in a buffer somewhere. The recommendation for
ensuring this bit has taken effect on the device is to perform a read
back to force it to make it all the way to the device. This is
documented in device-io.rst and a talk by Will Deacon on this can
be seen over here:

    https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678

Let's do that to ensure the bit hits the device. Because the mb()'s
purpose wasn't to add extra ordering (on top of the ordering guaranteed
by writel()/readl()), it can safely be removed.

Fixes: d90996dae8e4 ("scsi: ufs: Add UFS platform driver for Cadence UFS")
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
 drivers/ufs/host/cdns-pltfrm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ufs/host/cdns-pltfrm.c b/drivers/ufs/host/cdns-pltfrm.c
index bb30267da471..66811d8d1929 100644
--- a/drivers/ufs/host/cdns-pltfrm.c
+++ b/drivers/ufs/host/cdns-pltfrm.c
@@ -136,7 +136,7 @@ static int cdns_ufs_set_hclkdiv(struct ufs_hba *hba)
 	 * Make sure the register was updated,
 	 * UniPro layer will not work with an incorrect value.
 	 */
-	mb();
+	ufshcd_readl(hba, CDNS_UFS_REG_HCLKDIV);
 
 	return 0;
 }

-- 
2.43.0


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

* [PATCH RFC v3 07/11] scsi: ufs: core: Perform read back after writing UTP_TASK_REQ_LIST_BASE_H
  2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
                   ` (5 preceding siblings ...)
  2023-12-21 19:09 ` [PATCH RFC v3 06/11] scsi: ufs: cdns-pltfrm: Perform read back after writing HCLKDIV Andrew Halaney
@ 2023-12-21 19:09 ` Andrew Halaney
  2023-12-21 19:30   ` Bart Van Assche
  2023-12-22  8:26   ` Can Guo
  2023-12-21 19:09 ` [PATCH RFC v3 08/11] scsi: ufs: core: Perform read back after disabling interrupts Andrew Halaney
                   ` (4 subsequent siblings)
  11 siblings, 2 replies; 31+ messages in thread
From: Andrew Halaney @ 2023-12-21 19:09 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Andrew Halaney, Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

Currently, the UTP_TASK_REQ_LIST_BASE_L/UTP_TASK_REQ_LIST_BASE_H regs
are written to and then completed with an mb().

mb() ensure that the write completes, but completion doesn't mean that
it isn't stored in a buffer somewhere. The recommendation for
ensuring these bits have taken effect on the device is to perform a read
back to force it to make it all the way to the device. This is
documented in device-io.rst and a talk by Will Deacon on this can
be seen over here:

    https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678

Let's do that to ensure the bits hit the device. Because the mb()'s
purpose wasn't to add extra ordering (on top of the ordering guaranteed
by writel()/readl()), it can safely be removed.

Fixes: 88441a8d355d ("scsi: ufs: core: Add hibernation callbacks")
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
 drivers/ufs/core/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index d1e33328ff3f..7bfb556e5b8e 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -10351,7 +10351,7 @@ int ufshcd_system_restore(struct device *dev)
 	 * are updated with the latest queue addresses. Only after
 	 * updating these addresses, we can queue the new commands.
 	 */
-	mb();
+	ufshcd_readl(hba, REG_UTP_TASK_REQ_LIST_BASE_H);
 
 	/* Resuming from hibernate, assume that link was OFF */
 	ufshcd_set_link_off(hba);

-- 
2.43.0


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

* [PATCH RFC v3 08/11] scsi: ufs: core: Perform read back after disabling interrupts
  2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
                   ` (6 preceding siblings ...)
  2023-12-21 19:09 ` [PATCH RFC v3 07/11] scsi: ufs: core: Perform read back after writing UTP_TASK_REQ_LIST_BASE_H Andrew Halaney
@ 2023-12-21 19:09 ` Andrew Halaney
  2023-12-21 19:30   ` Bart Van Assche
  2023-12-22  8:26   ` Can Guo
  2023-12-21 19:09 ` [PATCH RFC v3 09/11] scsi: ufs: core: Perform read back after disabling UIC_COMMAND_COMPL Andrew Halaney
                   ` (3 subsequent siblings)
  11 siblings, 2 replies; 31+ messages in thread
From: Andrew Halaney @ 2023-12-21 19:09 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Andrew Halaney, Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

Currently, interrupts are cleared and disabled prior to registering the
interrupt. An mb() is used to complete the clear/disable writes before
the interrupt is registered.

mb() ensure that the write completes, but completion doesn't mean that
it isn't stored in a buffer somewhere. The recommendation for
ensuring these bits have taken effect on the device is to perform a read
back to force it to make it all the way to the device. This is
documented in device-io.rst and a talk by Will Deacon on this can
be seen over here:

    https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678

Let's do that to ensure these bits hit the device. Because the mb()'s
purpose wasn't to add extra ordering (on top of the ordering guaranteed
by writel()/readl()), it can safely be removed.

Fixes: 199ef13cac7d ("scsi: ufs: avoid spurious UFS host controller interrupts")
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
 drivers/ufs/core/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 7bfb556e5b8e..bb603769b029 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -10568,7 +10568,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
 	 * Make sure that UFS interrupts are disabled and any pending interrupt
 	 * status is cleared before registering UFS interrupt handler.
 	 */
-	mb();
+	ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
 
 	/* IRQ registration */
 	err = devm_request_irq(dev, irq, ufshcd_intr, IRQF_SHARED, UFSHCD, hba);

-- 
2.43.0


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

* [PATCH RFC v3 09/11] scsi: ufs: core: Perform read back after disabling UIC_COMMAND_COMPL
  2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
                   ` (7 preceding siblings ...)
  2023-12-21 19:09 ` [PATCH RFC v3 08/11] scsi: ufs: core: Perform read back after disabling interrupts Andrew Halaney
@ 2023-12-21 19:09 ` Andrew Halaney
  2023-12-21 19:29   ` Bart Van Assche
                     ` (2 more replies)
  2023-12-21 19:09 ` [PATCH RFC v3 10/11] scsi: ufs: core: Perform read back to commit doorbell Andrew Halaney
                   ` (2 subsequent siblings)
  11 siblings, 3 replies; 31+ messages in thread
From: Andrew Halaney @ 2023-12-21 19:09 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Andrew Halaney, Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

Currently, the UIC_COMMAND_COMPL interrupt is disabled and a wmb() is
used to complete the register write before any following writes.

wmb() ensures the writes complete in that order, but completion doesn't
mean that it isn't stored in a buffer somewhere. The recommendation for
ensuring this bit has taken effect on the device is to perform a read
back to force it to make it all the way to the device. This is
documented in device-io.rst and a talk by Will Deacon on this can
be seen over here:

    https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678

Let's do that to ensure the bit hits the device. Because the wmb()'s
purpose wasn't to add extra ordering (on top of the ordering guaranteed
by writel()/readl()), it can safely be removed.

Fixes: d75f7fe495cf ("scsi: ufs: reduce the interrupts for power mode change requests")
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
 drivers/ufs/core/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index bb603769b029..75a03ee9a1ba 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -4240,7 +4240,7 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd)
 		 * Make sure UIC command completion interrupt is disabled before
 		 * issuing UIC command.
 		 */
-		wmb();
+		ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
 		reenable_intr = true;
 	}
 	spin_unlock_irqrestore(hba->host->host_lock, flags);

-- 
2.43.0


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

* [PATCH RFC v3 10/11] scsi: ufs: core: Perform read back to commit doorbell
  2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
                   ` (8 preceding siblings ...)
  2023-12-21 19:09 ` [PATCH RFC v3 09/11] scsi: ufs: core: Perform read back after disabling UIC_COMMAND_COMPL Andrew Halaney
@ 2023-12-21 19:09 ` Andrew Halaney
  2023-12-21 19:28   ` Bart Van Assche
                     ` (2 more replies)
  2023-12-21 19:09 ` [PATCH RFC v3 11/11] scsi: ufs: core: Perform read back before writing run/stop regs Andrew Halaney
  2023-12-21 19:13 ` [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Konrad Dybcio
  11 siblings, 3 replies; 31+ messages in thread
From: Andrew Halaney @ 2023-12-21 19:09 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Andrew Halaney, Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

Currently, the doorbell is written to and a wmb() is used to commit it
immediately.

wmb() ensures that the write completes before following writes occur,
but completion doesn't mean that it isn't stored in a buffer somewhere.
The recommendation for ensuring this bit has taken effect on the device
is to perform a read back to force it to make it all the way to the
device. This is documented in device-io.rst and a talk by Will Deacon on
this can be seen over here:

    https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678

Let's do that to ensure the bit hits the device. Because the wmb()'s
purpose wasn't to add extra ordering (on top of the ordering guaranteed
by writel()/readl()), it can safely be removed.

Fixes: ad1a1b9cd67a ("scsi: ufs: commit descriptors before setting the doorbell")
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
 drivers/ufs/core/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 75a03ee9a1ba..caebd589e08c 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -7050,7 +7050,7 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba,
 
 	ufshcd_writel(hba, 1 << task_tag, REG_UTP_TASK_REQ_DOOR_BELL);
 	/* Make sure that doorbell is committed immediately */
-	wmb();
+	ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL);
 
 	spin_unlock_irqrestore(host->host_lock, flags);
 

-- 
2.43.0


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

* [PATCH RFC v3 11/11] scsi: ufs: core: Perform read back before writing run/stop regs
  2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
                   ` (9 preceding siblings ...)
  2023-12-21 19:09 ` [PATCH RFC v3 10/11] scsi: ufs: core: Perform read back to commit doorbell Andrew Halaney
@ 2023-12-21 19:09 ` Andrew Halaney
  2023-12-21 19:25   ` Bart Van Assche
                     ` (2 more replies)
  2023-12-21 19:13 ` [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Konrad Dybcio
  11 siblings, 3 replies; 31+ messages in thread
From: Andrew Halaney @ 2023-12-21 19:09 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Andrew Halaney, Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

Currently a wmb() is used to ensure that writes to the
UTP_TASK_REQ_LIST_BASE* regs are completed prior to following writes to
the run/stop registers.

wmb() ensure that the write completes, but completion doesn't mean that
it isn't stored in a buffer somewhere. The recommendation for
ensuring the bits have taken effect on the device is to perform a read
back to force it to make it all the way to the device. This is
documented in device-io.rst and a talk by Will Deacon on this can
be seen over here:

    https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678

Let's do that to ensure the bits hit the device. Because the wmb()'s
purpose wasn't to add extra ordering (on top of the ordering guaranteed
by writel()/readl()), it can safely be removed.

Fixes: 897efe628d7e ("scsi: ufs: add missing memory barriers")
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
 drivers/ufs/core/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index caebd589e08c..7c1975a1181f 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -4726,7 +4726,7 @@ int ufshcd_make_hba_operational(struct ufs_hba *hba)
 	 * Make sure base address and interrupt setup are updated before
 	 * enabling the run/stop registers below.
 	 */
-	wmb();
+	ufshcd_readl(hba, REG_UTP_TASK_REQ_LIST_BASE_H);
 
 	/*
 	 * UCRDY, UTMRLDY and UTRLRDY bits must be 1

-- 
2.43.0


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

* Re: [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers
  2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
                   ` (10 preceding siblings ...)
  2023-12-21 19:09 ` [PATCH RFC v3 11/11] scsi: ufs: core: Perform read back before writing run/stop regs Andrew Halaney
@ 2023-12-21 19:13 ` Konrad Dybcio
  11 siblings, 0 replies; 31+ messages in thread
From: Konrad Dybcio @ 2023-12-21 19:13 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

On 21.12.2023 20:09, Andrew Halaney wrote:
> This is an RFC because I'm not all the confident in this topic. UFS has
> a lot of mb() variants used, most with comments saying "ensure this
> takes effect before continuing". mb()'s aren't really the way to
> guarantee that, a read back is the best method.
> 
> Some of these though I think could go a step further and remove the mb()
> variant without a read back. As far as I can tell there's no real reason
> to ensure it takes effect in most cases (there's no delay() or anything
> afterwards, and eventually another readl()/writel() happens which is by
> definition ordered).
If I understand this correctly - and I'm no expert - it's probably good
practice to read it back in critical places, so that if the code around
it changes, the most crucial writes arrive when expected.

Konrad

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

* Re: [PATCH RFC v3 11/11] scsi: ufs: core: Perform read back before writing run/stop regs
  2023-12-21 19:09 ` [PATCH RFC v3 11/11] scsi: ufs: core: Perform read back before writing run/stop regs Andrew Halaney
@ 2023-12-21 19:25   ` Bart Van Assche
  2023-12-22  8:27   ` Can Guo
  2023-12-27  6:21   ` Manivannan Sadhasivam
  2 siblings, 0 replies; 31+ messages in thread
From: Bart Van Assche @ 2023-12-21 19:25 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman, Can Guo
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

On 12/21/23 11:09, Andrew Halaney wrote:
> Currently a wmb() is used to ensure that writes to the
> UTP_TASK_REQ_LIST_BASE* regs are completed prior to following writes to
> the run/stop registers.
> 
> wmb() ensure that the write completes, but completion doesn't mean that
> it isn't stored in a buffer somewhere. The recommendation for
> ensuring the bits have taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bits hit the device. Because the wmb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

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

* Re: [PATCH RFC v3 10/11] scsi: ufs: core: Perform read back to commit doorbell
  2023-12-21 19:09 ` [PATCH RFC v3 10/11] scsi: ufs: core: Perform read back to commit doorbell Andrew Halaney
@ 2023-12-21 19:28   ` Bart Van Assche
  2023-12-22  8:27   ` Can Guo
  2023-12-27  6:18   ` Manivannan Sadhasivam
  2 siblings, 0 replies; 31+ messages in thread
From: Bart Van Assche @ 2023-12-21 19:28 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman, Can Guo
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

On 12/21/23 11:09, Andrew Halaney wrote:
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 75a03ee9a1ba..caebd589e08c 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -7050,7 +7050,7 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba,
>   
>   	ufshcd_writel(hba, 1 << task_tag, REG_UTP_TASK_REQ_DOOR_BELL);
>   	/* Make sure that doorbell is committed immediately */
> -	wmb();
> +	ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL);
>   
>   	spin_unlock_irqrestore(host->host_lock, flags);

There is a wait_for_completion_io_timeout() call later in this function and
it is safe to write to the REG_UTP_TASK_REQ_DOOR_BELL register from multiple
threads concurrently so I think the above wmb() call can be left out entirely.

Thanks,

Bart.

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

* Re: [PATCH RFC v3 09/11] scsi: ufs: core: Perform read back after disabling UIC_COMMAND_COMPL
  2023-12-21 19:09 ` [PATCH RFC v3 09/11] scsi: ufs: core: Perform read back after disabling UIC_COMMAND_COMPL Andrew Halaney
@ 2023-12-21 19:29   ` Bart Van Assche
  2023-12-22  8:26   ` Can Guo
  2023-12-27  6:16   ` Manivannan Sadhasivam
  2 siblings, 0 replies; 31+ messages in thread
From: Bart Van Assche @ 2023-12-21 19:29 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman, Can Guo
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

On 12/21/23 11:09, Andrew Halaney wrote:
> Currently, the UIC_COMMAND_COMPL interrupt is disabled and a wmb() is
> used to complete the register write before any following writes.
> 
> wmb() ensures the writes complete in that order, but completion doesn't
> mean that it isn't stored in a buffer somewhere. The recommendation for
> ensuring this bit has taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bit hits the device. Because the wmb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: d75f7fe495cf ("scsi: ufs: reduce the interrupts for power mode change requests")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/core/ufshcd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index bb603769b029..75a03ee9a1ba 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -4240,7 +4240,7 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd)
>   		 * Make sure UIC command completion interrupt is disabled before
>   		 * issuing UIC command.
>   		 */
> -		wmb();
> +		ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
>   		reenable_intr = true;
>   	}
>   	spin_unlock_irqrestore(hba->host->host_lock, flags);

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

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

* Re: [PATCH RFC v3 08/11] scsi: ufs: core: Perform read back after disabling interrupts
  2023-12-21 19:09 ` [PATCH RFC v3 08/11] scsi: ufs: core: Perform read back after disabling interrupts Andrew Halaney
@ 2023-12-21 19:30   ` Bart Van Assche
  2023-12-22  8:26   ` Can Guo
  1 sibling, 0 replies; 31+ messages in thread
From: Bart Van Assche @ 2023-12-21 19:30 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman, Can Guo
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

On 12/21/23 11:09, Andrew Halaney wrote:
> Currently, interrupts are cleared and disabled prior to registering the
> interrupt. An mb() is used to complete the clear/disable writes before
> the interrupt is registered.
> 
> mb() ensure that the write completes, but completion doesn't mean that
> it isn't stored in a buffer somewhere. The recommendation for
> ensuring these bits have taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure these bits hit the device. Because the mb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: 199ef13cac7d ("scsi: ufs: avoid spurious UFS host controller interrupts")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/core/ufshcd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 7bfb556e5b8e..bb603769b029 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -10568,7 +10568,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
>   	 * Make sure that UFS interrupts are disabled and any pending interrupt
>   	 * status is cleared before registering UFS interrupt handler.
>   	 */
> -	mb();
> +	ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
>   
>   	/* IRQ registration */
>   	err = devm_request_irq(dev, irq, ufshcd_intr, IRQF_SHARED, UFSHCD, hba);

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

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

* Re: [PATCH RFC v3 07/11] scsi: ufs: core: Perform read back after writing UTP_TASK_REQ_LIST_BASE_H
  2023-12-21 19:09 ` [PATCH RFC v3 07/11] scsi: ufs: core: Perform read back after writing UTP_TASK_REQ_LIST_BASE_H Andrew Halaney
@ 2023-12-21 19:30   ` Bart Van Assche
  2023-12-22  8:26   ` Can Guo
  1 sibling, 0 replies; 31+ messages in thread
From: Bart Van Assche @ 2023-12-21 19:30 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman, Can Guo
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel

On 12/21/23 11:09, Andrew Halaney wrote:
> Currently, the UTP_TASK_REQ_LIST_BASE_L/UTP_TASK_REQ_LIST_BASE_H regs
> are written to and then completed with an mb().
> 
> mb() ensure that the write completes, but completion doesn't mean that
> it isn't stored in a buffer somewhere. The recommendation for
> ensuring these bits have taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bits hit the device. Because the mb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: 88441a8d355d ("scsi: ufs: core: Add hibernation callbacks")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/core/ufshcd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index d1e33328ff3f..7bfb556e5b8e 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -10351,7 +10351,7 @@ int ufshcd_system_restore(struct device *dev)
>   	 * are updated with the latest queue addresses. Only after
>   	 * updating these addresses, we can queue the new commands.
>   	 */
> -	mb();
> +	ufshcd_readl(hba, REG_UTP_TASK_REQ_LIST_BASE_H);
>   
>   	/* Resuming from hibernate, assume that link was OFF */
>   	ufshcd_set_link_off(hba);

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

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

* Re: [PATCH RFC v3 01/11] scsi: ufs: qcom: Perform read back after writing reset bit
  2023-12-21 19:09 ` [PATCH RFC v3 01/11] scsi: ufs: qcom: Perform read back after writing reset bit Andrew Halaney
@ 2023-12-22  8:18   ` Can Guo
  0 siblings, 0 replies; 31+ messages in thread
From: Can Guo @ 2023-12-22  8:18 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel,
	Manivannan Sadhasivam



On 12/22/2023 3:09 AM, Andrew Halaney wrote:
> Currently, the reset bit for the UFS provided reset controller (used by
> its phy) is written to, and then a mb() happens to try and ensure that
> hit the device. Immediately afterwards a usleep_range() occurs.
> 
> mb() ensure that the write completes, but completion doesn't mean that
> it isn't stored in a buffer somewhere. The recommendation for
> ensuring this bit has taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bit hits the device. By doing so and
> guaranteeing the ordering against the immediately following
> usleep_range(), the mb() can safely be removed.
> 
> Fixes: 81c0fc51b7a7 ("ufs-qcom: add support for Qualcomm Technologies Inc platforms")
> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/host/ufs-qcom.h | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/ufs/host/ufs-qcom.h b/drivers/ufs/host/ufs-qcom.h
> index 9dd9a391ebb7..b9de170983c9 100644
> --- a/drivers/ufs/host/ufs-qcom.h
> +++ b/drivers/ufs/host/ufs-qcom.h
> @@ -151,10 +151,10 @@ static inline void ufs_qcom_assert_reset(struct ufs_hba *hba)
>   	ufshcd_rmwl(hba, UFS_PHY_SOFT_RESET, UFS_PHY_SOFT_RESET, REG_UFS_CFG1);
>   
>   	/*
> -	 * Make sure assertion of ufs phy reset is written to
> -	 * register before returning
> +	 * Dummy read to ensure the write takes effect before doing any sort
> +	 * of delay
>   	 */
> -	mb();
> +	ufshcd_readl(hba, REG_UFS_CFG1);
>   }
>   
>   static inline void ufs_qcom_deassert_reset(struct ufs_hba *hba)
> @@ -162,10 +162,10 @@ static inline void ufs_qcom_deassert_reset(struct ufs_hba *hba)
>   	ufshcd_rmwl(hba, UFS_PHY_SOFT_RESET, 0, REG_UFS_CFG1);
>   
>   	/*
> -	 * Make sure de-assertion of ufs phy reset is written to
> -	 * register before returning
> +	 * Dummy read to ensure the write takes effect before doing any sort
> +	 * of delay
>   	 */
> -	mb();
> +	ufshcd_readl(hba, REG_UFS_CFG1);
>   }
>   
>   /* Host controller hardware version: major.minor.step */
> 
Reviewed-by: Can Guo <quic_cang@quicinc.com>

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

* Re: [PATCH RFC v3 02/11] scsi: ufs: qcom: Perform read back after writing REG_UFS_SYS1CLK_1US
  2023-12-21 19:09 ` [PATCH RFC v3 02/11] scsi: ufs: qcom: Perform read back after writing REG_UFS_SYS1CLK_1US Andrew Halaney
@ 2023-12-22  8:18   ` Can Guo
  0 siblings, 0 replies; 31+ messages in thread
From: Can Guo @ 2023-12-22  8:18 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel



On 12/22/2023 3:09 AM, Andrew Halaney wrote:
> Currently after writing to REG_UFS_SYS1CLK_1US a mb() is used to ensure
> that write has gone through to the device.
> 
> mb() ensure that the write completes, but completion doesn't mean that
> it isn't stored in a buffer somewhere. The recommendation for
> ensuring this bit has taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bit hits the device. Because the mb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: f06fcc7155dc ("scsi: ufs-qcom: add QUniPro hardware support and power optimizations")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/host/ufs-qcom.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
> index 480787048e75..4c15c8a1d058 100644
> --- a/drivers/ufs/host/ufs-qcom.c
> +++ b/drivers/ufs/host/ufs-qcom.c
> @@ -501,7 +501,7 @@ static int ufs_qcom_cfg_timers(struct ufs_hba *hba, u32 gear,
>   		 * make sure above write gets applied before we return from
>   		 * this function.
>   		 */
> -		mb();
> +		ufshcd_readl(hba, REG_UFS_SYS1CLK_1US);
>   	}
>   
>   	return 0;
> 
Reviewed-by: Can Guo <quic_cang@quicinc.com>

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

* Re: [PATCH RFC v3 03/11] scsi: ufs: qcom: Perform read back after writing testbus config
  2023-12-21 19:09 ` [PATCH RFC v3 03/11] scsi: ufs: qcom: Perform read back after writing testbus config Andrew Halaney
@ 2023-12-22  8:20   ` Can Guo
  0 siblings, 0 replies; 31+ messages in thread
From: Can Guo @ 2023-12-22  8:20 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel



On 12/22/2023 3:09 AM, Andrew Halaney wrote:
> Currently, the testbus configuration is written and completed with an
> mb().
> 
> mb() ensure that the write completes, but completion doesn't mean
> that it isn't stored in a buffer somewhere. The recommendation for
> ensuring this bit has taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bit hits the device. Because the mb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: 9c46b8676271 ("scsi: ufs-qcom: dump additional testbus registers")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/host/ufs-qcom.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
> index 4c15c8a1d058..6df2ab3b6f23 100644
> --- a/drivers/ufs/host/ufs-qcom.c
> +++ b/drivers/ufs/host/ufs-qcom.c
> @@ -1332,6 +1332,9 @@ static void ufs_qcom_enable_test_bus(struct ufs_qcom_host *host)
>   	ufshcd_rmwl(host->hba, UFS_REG_TEST_BUS_EN,
>   			UFS_REG_TEST_BUS_EN, REG_UFS_CFG1);
>   	ufshcd_rmwl(host->hba, TEST_BUS_EN, TEST_BUS_EN, REG_UFS_CFG1);
> +
> +	/* dummy read to ensure this has been enabled prior to returning */
> +	ufshcd_readl(host->hba, REG_UFS_CFG1);
>   }
>   
>   static void ufs_qcom_get_default_testbus_cfg(struct ufs_qcom_host *host)
> @@ -1429,11 +1432,6 @@ int ufs_qcom_testbus_config(struct ufs_qcom_host *host)
>   		    (u32)host->testbus.select_minor << offset,
>   		    reg);
>   	ufs_qcom_enable_test_bus(host);
> -	/*
> -	 * Make sure the test bus configuration is
> -	 * committed before returning.
> -	 */
> -	mb();
>   
>   	return 0;
>   }
> 
Reviewed-by: Can Guo <quic_cang@quicinc.com>

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

* Re: [PATCH RFC v3 04/11] scsi: ufs: qcom: Perform read back after writing unipro mode
  2023-12-21 19:09 ` [PATCH RFC v3 04/11] scsi: ufs: qcom: Perform read back after writing unipro mode Andrew Halaney
@ 2023-12-22  8:23   ` Can Guo
  0 siblings, 0 replies; 31+ messages in thread
From: Can Guo @ 2023-12-22  8:23 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel



On 12/22/2023 3:09 AM, Andrew Halaney wrote:
> Currently, the QUNIPRO_SEL bit is written to and then an mb() is used to
> ensure that completes before continuing.
> 
> mb() ensure that the write completes, but completion doesn't mean that
> it isn't stored in a buffer somewhere. The recommendation for
> ensuring this bit has taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bit hits the device. Because the mb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: f06fcc7155dc ("scsi: ufs-qcom: add QUniPro hardware support and power optimizations")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/host/ufs-qcom.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
> index 6df2ab3b6f23..ab1ff7432d11 100644
> --- a/drivers/ufs/host/ufs-qcom.c
> +++ b/drivers/ufs/host/ufs-qcom.c
> @@ -280,7 +280,7 @@ static void ufs_qcom_select_unipro_mode(struct ufs_qcom_host *host)
>   		ufshcd_rmwl(host->hba, QUNIPRO_G4_SEL, 0, REG_UFS_CFG0);
>   
>   	/* make sure above configuration is applied before we return */
> -	mb();
> +	ufshcd_readl(host->hba, REG_UFS_CFG1);

nit: please also add the dummy read comment line to avoid confusions.

>   }
>   
>   /*
> 
With above addressed,

Reviewed-by: Can Guo <quic_cang@quicinc.com>

Thanks,
Can Guo.

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

* Re: [PATCH RFC v3 05/11] scsi: ufs: qcom: Perform read back after writing CGC enable
  2023-12-21 19:09 ` [PATCH RFC v3 05/11] scsi: ufs: qcom: Perform read back after writing CGC enable Andrew Halaney
@ 2023-12-22  8:25   ` Can Guo
  0 siblings, 0 replies; 31+ messages in thread
From: Can Guo @ 2023-12-22  8:25 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel



On 12/22/2023 3:09 AM, Andrew Halaney wrote:
> Currently, the CGC enable bit is written and then an mb() is used to
> ensure that completes before continuing.
> 
> mb() ensure that the write completes, but completion doesn't mean that
> it isn't stored in a buffer somewhere. The recommendation for
> ensuring this bit has taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bit hits the device. Because the mb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: 81c0fc51b7a7 ("ufs-qcom: add support for Qualcomm Technologies Inc platforms")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/host/ufs-qcom.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
> index ab1ff7432d11..3db19591d008 100644
> --- a/drivers/ufs/host/ufs-qcom.c
> +++ b/drivers/ufs/host/ufs-qcom.c
> @@ -409,7 +409,7 @@ static void ufs_qcom_enable_hw_clk_gating(struct ufs_hba *hba)
>   		    REG_UFS_CFG2);
>   
>   	/* Ensure that HW clock gating is enabled before next operations */
> -	mb();
> +	ufshcd_readl(hba, REG_UFS_CFG2);
>   }
>   
>   static int ufs_qcom_hce_enable_notify(struct ufs_hba *hba,
> 
Reviewed-by: Can Guo <quic_cang@quicinc.com>

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

* Re: [PATCH RFC v3 07/11] scsi: ufs: core: Perform read back after writing UTP_TASK_REQ_LIST_BASE_H
  2023-12-21 19:09 ` [PATCH RFC v3 07/11] scsi: ufs: core: Perform read back after writing UTP_TASK_REQ_LIST_BASE_H Andrew Halaney
  2023-12-21 19:30   ` Bart Van Assche
@ 2023-12-22  8:26   ` Can Guo
  1 sibling, 0 replies; 31+ messages in thread
From: Can Guo @ 2023-12-22  8:26 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel



On 12/22/2023 3:09 AM, Andrew Halaney wrote:
> Currently, the UTP_TASK_REQ_LIST_BASE_L/UTP_TASK_REQ_LIST_BASE_H regs
> are written to and then completed with an mb().
> 
> mb() ensure that the write completes, but completion doesn't mean that
> it isn't stored in a buffer somewhere. The recommendation for
> ensuring these bits have taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bits hit the device. Because the mb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: 88441a8d355d ("scsi: ufs: core: Add hibernation callbacks")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/core/ufshcd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index d1e33328ff3f..7bfb556e5b8e 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -10351,7 +10351,7 @@ int ufshcd_system_restore(struct device *dev)
>   	 * are updated with the latest queue addresses. Only after
>   	 * updating these addresses, we can queue the new commands.
>   	 */
> -	mb();
> +	ufshcd_readl(hba, REG_UTP_TASK_REQ_LIST_BASE_H);
>   
>   	/* Resuming from hibernate, assume that link was OFF */
>   	ufshcd_set_link_off(hba);
> 
Reviewed-by: Can Guo <quic_cang@quicinc.com>

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

* Re: [PATCH RFC v3 08/11] scsi: ufs: core: Perform read back after disabling interrupts
  2023-12-21 19:09 ` [PATCH RFC v3 08/11] scsi: ufs: core: Perform read back after disabling interrupts Andrew Halaney
  2023-12-21 19:30   ` Bart Van Assche
@ 2023-12-22  8:26   ` Can Guo
  1 sibling, 0 replies; 31+ messages in thread
From: Can Guo @ 2023-12-22  8:26 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel



On 12/22/2023 3:09 AM, Andrew Halaney wrote:
> Currently, interrupts are cleared and disabled prior to registering the
> interrupt. An mb() is used to complete the clear/disable writes before
> the interrupt is registered.
> 
> mb() ensure that the write completes, but completion doesn't mean that
> it isn't stored in a buffer somewhere. The recommendation for
> ensuring these bits have taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure these bits hit the device. Because the mb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: 199ef13cac7d ("scsi: ufs: avoid spurious UFS host controller interrupts")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/core/ufshcd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 7bfb556e5b8e..bb603769b029 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -10568,7 +10568,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
>   	 * Make sure that UFS interrupts are disabled and any pending interrupt
>   	 * status is cleared before registering UFS interrupt handler.
>   	 */
> -	mb();
> +	ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
>   
>   	/* IRQ registration */
>   	err = devm_request_irq(dev, irq, ufshcd_intr, IRQF_SHARED, UFSHCD, hba);
> 
Reviewed-by: Can Guo <quic_cang@quicinc.com>

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

* Re: [PATCH RFC v3 09/11] scsi: ufs: core: Perform read back after disabling UIC_COMMAND_COMPL
  2023-12-21 19:09 ` [PATCH RFC v3 09/11] scsi: ufs: core: Perform read back after disabling UIC_COMMAND_COMPL Andrew Halaney
  2023-12-21 19:29   ` Bart Van Assche
@ 2023-12-22  8:26   ` Can Guo
  2023-12-27  6:16   ` Manivannan Sadhasivam
  2 siblings, 0 replies; 31+ messages in thread
From: Can Guo @ 2023-12-22  8:26 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel



On 12/22/2023 3:09 AM, Andrew Halaney wrote:
> Currently, the UIC_COMMAND_COMPL interrupt is disabled and a wmb() is
> used to complete the register write before any following writes.
> 
> wmb() ensures the writes complete in that order, but completion doesn't
> mean that it isn't stored in a buffer somewhere. The recommendation for
> ensuring this bit has taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bit hits the device. Because the wmb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: d75f7fe495cf ("scsi: ufs: reduce the interrupts for power mode change requests")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/core/ufshcd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index bb603769b029..75a03ee9a1ba 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -4240,7 +4240,7 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd)
>   		 * Make sure UIC command completion interrupt is disabled before
>   		 * issuing UIC command.
>   		 */
> -		wmb();
> +		ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
>   		reenable_intr = true;
>   	}
>   	spin_unlock_irqrestore(hba->host->host_lock, flags);
> 
Reviewed-by: Can Guo <quic_cang@quicinc.com>

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

* Re: [PATCH RFC v3 10/11] scsi: ufs: core: Perform read back to commit doorbell
  2023-12-21 19:09 ` [PATCH RFC v3 10/11] scsi: ufs: core: Perform read back to commit doorbell Andrew Halaney
  2023-12-21 19:28   ` Bart Van Assche
@ 2023-12-22  8:27   ` Can Guo
  2023-12-27  6:18   ` Manivannan Sadhasivam
  2 siblings, 0 replies; 31+ messages in thread
From: Can Guo @ 2023-12-22  8:27 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel



On 12/22/2023 3:09 AM, Andrew Halaney wrote:
> Currently, the doorbell is written to and a wmb() is used to commit it
> immediately.
> 
> wmb() ensures that the write completes before following writes occur,
> but completion doesn't mean that it isn't stored in a buffer somewhere.
> The recommendation for ensuring this bit has taken effect on the device
> is to perform a read back to force it to make it all the way to the
> device. This is documented in device-io.rst and a talk by Will Deacon on
> this can be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bit hits the device. Because the wmb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: ad1a1b9cd67a ("scsi: ufs: commit descriptors before setting the doorbell")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/core/ufshcd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 75a03ee9a1ba..caebd589e08c 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -7050,7 +7050,7 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba,
>   
>   	ufshcd_writel(hba, 1 << task_tag, REG_UTP_TASK_REQ_DOOR_BELL);
>   	/* Make sure that doorbell is committed immediately */
> -	wmb();
> +	ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL);
>   
>   	spin_unlock_irqrestore(host->host_lock, flags);
>   
> 
Reviewed-by: Can Guo <quic_cang@quicinc.com>

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

* Re: [PATCH RFC v3 11/11] scsi: ufs: core: Perform read back before writing run/stop regs
  2023-12-21 19:09 ` [PATCH RFC v3 11/11] scsi: ufs: core: Perform read back before writing run/stop regs Andrew Halaney
  2023-12-21 19:25   ` Bart Van Assche
@ 2023-12-22  8:27   ` Can Guo
  2023-12-27  6:21   ` Manivannan Sadhasivam
  2 siblings, 0 replies; 31+ messages in thread
From: Can Guo @ 2023-12-22  8:27 UTC (permalink / raw)
  To: Andrew Halaney, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche
  Cc: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel



On 12/22/2023 3:09 AM, Andrew Halaney wrote:
> Currently a wmb() is used to ensure that writes to the
> UTP_TASK_REQ_LIST_BASE* regs are completed prior to following writes to
> the run/stop registers.
> 
> wmb() ensure that the write completes, but completion doesn't mean that
> it isn't stored in a buffer somewhere. The recommendation for
> ensuring the bits have taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>      https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bits hit the device. Because the wmb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: 897efe628d7e ("scsi: ufs: add missing memory barriers")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>   drivers/ufs/core/ufshcd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index caebd589e08c..7c1975a1181f 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -4726,7 +4726,7 @@ int ufshcd_make_hba_operational(struct ufs_hba *hba)
>   	 * Make sure base address and interrupt setup are updated before
>   	 * enabling the run/stop registers below.
>   	 */
> -	wmb();
> +	ufshcd_readl(hba, REG_UTP_TASK_REQ_LIST_BASE_H);
>   
>   	/*
>   	 * UCRDY, UTMRLDY and UTRLRDY bits must be 1
> 
Reviewed-by: Can Guo <quic_cang@quicinc.com>

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

* Re: [PATCH RFC v3 09/11] scsi: ufs: core: Perform read back after disabling UIC_COMMAND_COMPL
  2023-12-21 19:09 ` [PATCH RFC v3 09/11] scsi: ufs: core: Perform read back after disabling UIC_COMMAND_COMPL Andrew Halaney
  2023-12-21 19:29   ` Bart Van Assche
  2023-12-22  8:26   ` Can Guo
@ 2023-12-27  6:16   ` Manivannan Sadhasivam
  2 siblings, 0 replies; 31+ messages in thread
From: Manivannan Sadhasivam @ 2023-12-27  6:16 UTC (permalink / raw)
  To: Andrew Halaney
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, James E.J. Bottomley,
	Martin K. Petersen, Hannes Reinecke, Janek Kotas, Alim Akhtar,
	Avri Altman, Bart Van Assche, Can Guo, Will Deacon,
	linux-arm-msm, linux-scsi, linux-kernel

On Thu, Dec 21, 2023 at 01:09:55PM -0600, Andrew Halaney wrote:
> Currently, the UIC_COMMAND_COMPL interrupt is disabled and a wmb() is
> used to complete the register write before any following writes.
> 
> wmb() ensures the writes complete in that order, but completion doesn't
> mean that it isn't stored in a buffer somewhere. The recommendation for
> ensuring this bit has taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>     https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bit hits the device. Because the wmb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: d75f7fe495cf ("scsi: ufs: reduce the interrupts for power mode change requests")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

- Mani

> ---
>  drivers/ufs/core/ufshcd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index bb603769b029..75a03ee9a1ba 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -4240,7 +4240,7 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd)
>  		 * Make sure UIC command completion interrupt is disabled before
>  		 * issuing UIC command.
>  		 */
> -		wmb();
> +		ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
>  		reenable_intr = true;
>  	}
>  	spin_unlock_irqrestore(hba->host->host_lock, flags);
> 
> -- 
> 2.43.0
> 

-- 
மணிவண்ணன் சதாசிவம்

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

* Re: [PATCH RFC v3 10/11] scsi: ufs: core: Perform read back to commit doorbell
  2023-12-21 19:09 ` [PATCH RFC v3 10/11] scsi: ufs: core: Perform read back to commit doorbell Andrew Halaney
  2023-12-21 19:28   ` Bart Van Assche
  2023-12-22  8:27   ` Can Guo
@ 2023-12-27  6:18   ` Manivannan Sadhasivam
  2 siblings, 0 replies; 31+ messages in thread
From: Manivannan Sadhasivam @ 2023-12-27  6:18 UTC (permalink / raw)
  To: Andrew Halaney
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Manivannan Sadhasivam, James E.J. Bottomley, Martin K. Petersen,
	Hannes Reinecke, Janek Kotas, Alim Akhtar, Avri Altman,
	Bart Van Assche, Can Guo, Will Deacon, linux-arm-msm, linux-scsi,
	linux-kernel

On Thu, Dec 21, 2023 at 01:09:56PM -0600, Andrew Halaney wrote:
> Currently, the doorbell is written to and a wmb() is used to commit it
> immediately.
> 
> wmb() ensures that the write completes before following writes occur,
> but completion doesn't mean that it isn't stored in a buffer somewhere.
> The recommendation for ensuring this bit has taken effect on the device
> is to perform a read back to force it to make it all the way to the
> device. This is documented in device-io.rst and a talk by Will Deacon on
> this can be seen over here:
> 
>     https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bit hits the device. Because the wmb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: ad1a1b9cd67a ("scsi: ufs: commit descriptors before setting the doorbell")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

- Mani

> ---
>  drivers/ufs/core/ufshcd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 75a03ee9a1ba..caebd589e08c 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -7050,7 +7050,7 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba,
>  
>  	ufshcd_writel(hba, 1 << task_tag, REG_UTP_TASK_REQ_DOOR_BELL);
>  	/* Make sure that doorbell is committed immediately */
> -	wmb();
> +	ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL);
>  
>  	spin_unlock_irqrestore(host->host_lock, flags);
>  
> 
> -- 
> 2.43.0
> 

-- 
மணிவண்ணன் சதாசிவம்

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

* Re: [PATCH RFC v3 11/11] scsi: ufs: core: Perform read back before writing run/stop regs
  2023-12-21 19:09 ` [PATCH RFC v3 11/11] scsi: ufs: core: Perform read back before writing run/stop regs Andrew Halaney
  2023-12-21 19:25   ` Bart Van Assche
  2023-12-22  8:27   ` Can Guo
@ 2023-12-27  6:21   ` Manivannan Sadhasivam
  2 siblings, 0 replies; 31+ messages in thread
From: Manivannan Sadhasivam @ 2023-12-27  6:21 UTC (permalink / raw)
  To: Andrew Halaney
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, James E.J. Bottomley,
	Martin K. Petersen, Hannes Reinecke, Janek Kotas, Alim Akhtar,
	Avri Altman, Bart Van Assche, Can Guo, Will Deacon,
	linux-arm-msm, linux-scsi, linux-kernel

On Thu, Dec 21, 2023 at 01:09:57PM -0600, Andrew Halaney wrote:
> Currently a wmb() is used to ensure that writes to the
> UTP_TASK_REQ_LIST_BASE* regs are completed prior to following writes to
> the run/stop registers.
> 
> wmb() ensure that the write completes, but completion doesn't mean that
> it isn't stored in a buffer somewhere. The recommendation for
> ensuring the bits have taken effect on the device is to perform a read
> back to force it to make it all the way to the device. This is
> documented in device-io.rst and a talk by Will Deacon on this can
> be seen over here:
> 
>     https://youtu.be/i6DayghhA8Q?si=MiyxB5cKJXSaoc01&t=1678
> 
> Let's do that to ensure the bits hit the device. Because the wmb()'s
> purpose wasn't to add extra ordering (on top of the ordering guaranteed
> by writel()/readl()), it can safely be removed.
> 
> Fixes: 897efe628d7e ("scsi: ufs: add missing memory barriers")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>  drivers/ufs/core/ufshcd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index caebd589e08c..7c1975a1181f 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -4726,7 +4726,7 @@ int ufshcd_make_hba_operational(struct ufs_hba *hba)
>  	 * Make sure base address and interrupt setup are updated before
>  	 * enabling the run/stop registers below.
>  	 */
> -	wmb();
> +	ufshcd_readl(hba, REG_UTP_TASK_REQ_LIST_BASE_H);

I don't think the readback is really needed here. Because, the dependency is
with UTP registers and both should be in the same domain. So there is no way the
following write can happen before prior UTP write completion.

- Mani

>  
>  	/*
>  	 * UCRDY, UTMRLDY and UTRLRDY bits must be 1
> 
> -- 
> 2.43.0
> 

-- 
மணிவண்ணன் சதாசிவம்

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

end of thread, other threads:[~2023-12-27  6:21 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-21 19:09 [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
2023-12-21 19:09 ` [PATCH RFC v3 01/11] scsi: ufs: qcom: Perform read back after writing reset bit Andrew Halaney
2023-12-22  8:18   ` Can Guo
2023-12-21 19:09 ` [PATCH RFC v3 02/11] scsi: ufs: qcom: Perform read back after writing REG_UFS_SYS1CLK_1US Andrew Halaney
2023-12-22  8:18   ` Can Guo
2023-12-21 19:09 ` [PATCH RFC v3 03/11] scsi: ufs: qcom: Perform read back after writing testbus config Andrew Halaney
2023-12-22  8:20   ` Can Guo
2023-12-21 19:09 ` [PATCH RFC v3 04/11] scsi: ufs: qcom: Perform read back after writing unipro mode Andrew Halaney
2023-12-22  8:23   ` Can Guo
2023-12-21 19:09 ` [PATCH RFC v3 05/11] scsi: ufs: qcom: Perform read back after writing CGC enable Andrew Halaney
2023-12-22  8:25   ` Can Guo
2023-12-21 19:09 ` [PATCH RFC v3 06/11] scsi: ufs: cdns-pltfrm: Perform read back after writing HCLKDIV Andrew Halaney
2023-12-21 19:09 ` [PATCH RFC v3 07/11] scsi: ufs: core: Perform read back after writing UTP_TASK_REQ_LIST_BASE_H Andrew Halaney
2023-12-21 19:30   ` Bart Van Assche
2023-12-22  8:26   ` Can Guo
2023-12-21 19:09 ` [PATCH RFC v3 08/11] scsi: ufs: core: Perform read back after disabling interrupts Andrew Halaney
2023-12-21 19:30   ` Bart Van Assche
2023-12-22  8:26   ` Can Guo
2023-12-21 19:09 ` [PATCH RFC v3 09/11] scsi: ufs: core: Perform read back after disabling UIC_COMMAND_COMPL Andrew Halaney
2023-12-21 19:29   ` Bart Van Assche
2023-12-22  8:26   ` Can Guo
2023-12-27  6:16   ` Manivannan Sadhasivam
2023-12-21 19:09 ` [PATCH RFC v3 10/11] scsi: ufs: core: Perform read back to commit doorbell Andrew Halaney
2023-12-21 19:28   ` Bart Van Assche
2023-12-22  8:27   ` Can Guo
2023-12-27  6:18   ` Manivannan Sadhasivam
2023-12-21 19:09 ` [PATCH RFC v3 11/11] scsi: ufs: core: Perform read back before writing run/stop regs Andrew Halaney
2023-12-21 19:25   ` Bart Van Assche
2023-12-22  8:27   ` Can Guo
2023-12-27  6:21   ` Manivannan Sadhasivam
2023-12-21 19:13 ` [PATCH RFC v3 00/11] scsi: ufs: Remove overzealous memory barriers Konrad Dybcio

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