* [PATCH RFC v4 01/11] scsi: ufs: qcom: Perform read back after writing reset bit
2024-01-22 17:21 [PATCH RFC v4 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
@ 2024-01-22 17:21 ` Andrew Halaney
2024-01-22 17:21 ` [PATCH RFC v4 02/11] scsi: ufs: qcom: Perform read back after writing REG_UFS_SYS1CLK_1US Andrew Halaney
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Halaney @ 2024-01-22 17:21 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: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel,
Andrew Halaney, 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>
Reviewed-by: Can Guo <quic_cang@quicinc.com>
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] 6+ messages in thread
* [PATCH RFC v4 02/11] scsi: ufs: qcom: Perform read back after writing REG_UFS_SYS1CLK_1US
2024-01-22 17:21 [PATCH RFC v4 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
2024-01-22 17:21 ` [PATCH RFC v4 01/11] scsi: ufs: qcom: Perform read back after writing reset bit Andrew Halaney
@ 2024-01-22 17:21 ` Andrew Halaney
2024-01-22 17:21 ` [PATCH RFC v4 03/11] scsi: ufs: qcom: Remove unnecessary mb() after writing testbus config Andrew Halaney
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Halaney @ 2024-01-22 17:21 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: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel,
Andrew Halaney
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")
Reviewed-by: Can Guo <quic_cang@quicinc.com>
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 39eef470f8fa..0603a07a23a2 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] 6+ messages in thread
* [PATCH RFC v4 03/11] scsi: ufs: qcom: Remove unnecessary mb() after writing testbus config
2024-01-22 17:21 [PATCH RFC v4 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
2024-01-22 17:21 ` [PATCH RFC v4 01/11] scsi: ufs: qcom: Perform read back after writing reset bit Andrew Halaney
2024-01-22 17:21 ` [PATCH RFC v4 02/11] scsi: ufs: qcom: Perform read back after writing REG_UFS_SYS1CLK_1US Andrew Halaney
@ 2024-01-22 17:21 ` Andrew Halaney
2024-01-22 17:21 ` [PATCH RFC v4 04/11] scsi: ufs: qcom: Perform read back after writing unipro mode Andrew Halaney
2024-01-22 17:21 ` [PATCH RFC v4 05/11] scsi: ufs: qcom: Perform read back after writing CGC enable Andrew Halaney
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Halaney @ 2024-01-22 17:21 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: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel,
Andrew Halaney
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
But, there's really no reason to even ensure completion before
continuing. The only requirement here is that this write is ordered to
this endpoint (which readl()/writel() guarantees already). For that
reason the mb() can be dropped altogether without anything forcing
completion.
Fixes: 9c46b8676271 ("scsi: ufs-qcom: dump additional testbus registers")
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
drivers/ufs/host/ufs-qcom.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index 0603a07a23a2..a489c8c6f849 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -1429,11 +1429,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] 6+ messages in thread
* [PATCH RFC v4 04/11] scsi: ufs: qcom: Perform read back after writing unipro mode
2024-01-22 17:21 [PATCH RFC v4 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
` (2 preceding siblings ...)
2024-01-22 17:21 ` [PATCH RFC v4 03/11] scsi: ufs: qcom: Remove unnecessary mb() after writing testbus config Andrew Halaney
@ 2024-01-22 17:21 ` Andrew Halaney
2024-01-22 17:21 ` [PATCH RFC v4 05/11] scsi: ufs: qcom: Perform read back after writing CGC enable Andrew Halaney
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Halaney @ 2024-01-22 17:21 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: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel,
Andrew Halaney
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
But, there's really no reason to even ensure completion before
continuing. The only requirement here is that this write is ordered to
this endpoint (which readl()/writel() guarantees already). For that
reason the mb() can be dropped altogether without anything forcing
completion.
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 | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index a489c8c6f849..decad95bd444 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -278,9 +278,6 @@ static void ufs_qcom_select_unipro_mode(struct ufs_qcom_host *host)
if (host->hw_ver.major >= 0x05)
ufshcd_rmwl(host->hba, QUNIPRO_G4_SEL, 0, REG_UFS_CFG0);
-
- /* make sure above configuration is applied before we return */
- mb();
}
/*
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH RFC v4 05/11] scsi: ufs: qcom: Perform read back after writing CGC enable
2024-01-22 17:21 [PATCH RFC v4 00/11] scsi: ufs: Remove overzealous memory barriers Andrew Halaney
` (3 preceding siblings ...)
2024-01-22 17:21 ` [PATCH RFC v4 04/11] scsi: ufs: qcom: Perform read back after writing unipro mode Andrew Halaney
@ 2024-01-22 17:21 ` Andrew Halaney
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Halaney @ 2024-01-22 17:21 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: Will Deacon, linux-arm-msm, linux-scsi, linux-kernel,
Andrew Halaney, Manivannan Sadhasivam
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.
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reviewed-by: Can Guo <quic_cang@quicinc.com>
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 decad95bd444..881074fc2329 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -406,7 +406,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] 6+ messages in thread