All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Qcom UFS driver updates
@ 2022-04-22 13:21 Manivannan Sadhasivam
  2022-04-22 13:21 ` [PATCH 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-22 13:21 UTC (permalink / raw)
  To: martin.petersen, jejb
  Cc: avri.altman, alim.akhtar, bjorn.andersson, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel,
	Manivannan Sadhasivam

Hi,

This series has some cleanups and updates to the Qcom UFS driver. There
is also a patch that removes the redundant wmb() from
ufshcd_send_command() in ufshcd driver.

All these patches are tested on Qualcomm Robotics RB3 platform.

Thanks,
Mani

Manivannan Sadhasivam (5):
  scsi: ufs: qcom: Fix acquiring the optional reset control line
  scsi: ufs: qcom: Simplify handling of devm_phy_get()
  scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled
  scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command()
  scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM

 drivers/scsi/ufs/ufs-qcom.c | 43 +++++++++++++++----------------------
 drivers/scsi/ufs/ufshcd.c   |  3 ---
 2 files changed, 17 insertions(+), 29 deletions(-)

-- 
2.25.1


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

* [PATCH 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line
  2022-04-22 13:21 [PATCH 0/5] Qcom UFS driver updates Manivannan Sadhasivam
@ 2022-04-22 13:21 ` Manivannan Sadhasivam
  2022-04-22 15:40   ` Andrew Halaney
  2022-04-22 13:21 ` [PATCH 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get() Manivannan Sadhasivam
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-22 13:21 UTC (permalink / raw)
  To: martin.petersen, jejb
  Cc: avri.altman, alim.akhtar, bjorn.andersson, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel,
	Manivannan Sadhasivam

On Qcom UFS platforms, the reset control line seems to be optional
(for SoCs like MSM8996 and probably for others too). The current logic
tries to mimic the `devm_reset_control_get_optional()` API but it also
continues the probe if there is an error with the declared reset line in
DT/ACPI.

In an ideal case, if the reset line is not declared in DT/ACPI, the probe
should continue. But if there is problem in acquiring the declared reset
line (like EPROBE_DEFER) it should fail and return the appropriate error
code.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/scsi/ufs/ufs-qcom.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
index 0d2e950d0865..5db0fd922062 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -1002,13 +1002,13 @@ static int ufs_qcom_init(struct ufs_hba *hba)
 	host->hba = hba;
 	ufshcd_set_variant(hba, host);
 
-	/* Setup the reset control of HCI */
-	host->core_reset = devm_reset_control_get(hba->dev, "rst");
+	/* Setup the optional reset control of HCI */
+	host->core_reset = devm_reset_control_get_optional(hba->dev, "rst");
 	if (IS_ERR(host->core_reset)) {
 		err = PTR_ERR(host->core_reset);
-		dev_warn(dev, "Failed to get reset control %d\n", err);
-		host->core_reset = NULL;
-		err = 0;
+		if (err != -EPROBE_DEFER)
+			dev_err(dev, "Failed to get reset control %d\n", err);
+		goto out_variant_clear;
 	}
 
 	/* Fire up the reset controller. Failure here is non-fatal. */
-- 
2.25.1


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

* [PATCH 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get()
  2022-04-22 13:21 [PATCH 0/5] Qcom UFS driver updates Manivannan Sadhasivam
  2022-04-22 13:21 ` [PATCH 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
@ 2022-04-22 13:21 ` Manivannan Sadhasivam
  2022-04-22 16:51   ` Andrew Halaney
  2022-04-22 13:21 ` [PATCH 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled Manivannan Sadhasivam
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-22 13:21 UTC (permalink / raw)
  To: martin.petersen, jejb
  Cc: avri.altman, alim.akhtar, bjorn.andersson, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel,
	Manivannan Sadhasivam

There is no need to call devm_phy_get() if ACPI is used, so skip it.
The "host->generic_phy" pointer should already be NULL due to the kzalloc,
so no need to set it NULL again.

Also, don't print the error message in case of -EPROBE_DEFER and return
the error code directly.

While at it, also remove the comment that has no relationship with
devm_phy_get().

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/scsi/ufs/ufs-qcom.c | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)

diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
index 5db0fd922062..5f0a8f646eb5 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -1022,28 +1022,12 @@ static int ufs_qcom_init(struct ufs_hba *hba)
 		err = 0;
 	}
 
-	/*
-	 * voting/devoting device ref_clk source is time consuming hence
-	 * skip devoting it during aggressive clock gating. This clock
-	 * will still be gated off during runtime suspend.
-	 */
-	host->generic_phy = devm_phy_get(dev, "ufsphy");
-
-	if (host->generic_phy == ERR_PTR(-EPROBE_DEFER)) {
-		/*
-		 * UFS driver might be probed before the phy driver does.
-		 * In that case we would like to return EPROBE_DEFER code.
-		 */
-		err = -EPROBE_DEFER;
-		dev_warn(dev, "%s: required phy device. hasn't probed yet. err = %d\n",
-			__func__, err);
-		goto out_variant_clear;
-	} else if (IS_ERR(host->generic_phy)) {
-		if (has_acpi_companion(dev)) {
-			host->generic_phy = NULL;
-		} else {
+	if (!has_acpi_companion(dev)) {
+		host->generic_phy = devm_phy_get(dev, "ufsphy");
+		if (IS_ERR(host->generic_phy)) {
 			err = PTR_ERR(host->generic_phy);
-			dev_err(dev, "%s: PHY get failed %d\n", __func__, err);
+			if (err != -EPROBE_DEFER)
+				dev_err(dev, "Failed to get PHY: %d\n", err);
 			goto out_variant_clear;
 		}
 	}
-- 
2.25.1


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

* [PATCH 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled
  2022-04-22 13:21 [PATCH 0/5] Qcom UFS driver updates Manivannan Sadhasivam
  2022-04-22 13:21 ` [PATCH 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
  2022-04-22 13:21 ` [PATCH 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get() Manivannan Sadhasivam
@ 2022-04-22 13:21 ` Manivannan Sadhasivam
  2022-04-23  5:03   ` Bart Van Assche
  2022-04-22 13:21 ` [PATCH 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command() Manivannan Sadhasivam
  2022-04-22 13:21 ` [PATCH 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM Manivannan Sadhasivam
  4 siblings, 1 reply; 13+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-22 13:21 UTC (permalink / raw)
  To: martin.petersen, jejb
  Cc: avri.altman, alim.akhtar, bjorn.andersson, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel,
	Manivannan Sadhasivam, stable

In ufs_qcom_dev_ref_clk_ctrl(), it was noted that the ref_clk needs to be
stable for atleast 1us. Eventhough there is wmb() to make sure the write
gets "completed", there is no guarantee that the write actually reached
the UFS device. There is a good chance that the write could be stored in
a Write Buffer (WB). In that case, eventhough the CPU waits for 1us, the
ref_clk might not be stable for that period.

So lets do a readl() to make sure that the previous write has reached the
UFS device before udelay().

Cc: stable@vger.kernel.org
Fixes: f06fcc7155dc ("scsi: ufs-qcom: add QUniPro hardware support and power optimizations")
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/scsi/ufs/ufs-qcom.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
index 5f0a8f646eb5..5b9986c63eed 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -690,6 +690,12 @@ static void ufs_qcom_dev_ref_clk_ctrl(struct ufs_qcom_host *host, bool enable)
 		/* ensure that ref_clk is enabled/disabled before we return */
 		wmb();
 
+		/*
+		 * Make sure the write to ref_clk reaches the destination and
+		 * not stored in a Write Buffer (WB).
+		 */
+		readl(host->dev_ref_clk_ctrl_mmio);
+
 		/*
 		 * If we call hibern8 exit after this, we need to make sure that
 		 * device ref_clk is stable for at least 1us before the hibern8
-- 
2.25.1


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

* [PATCH 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command()
  2022-04-22 13:21 [PATCH 0/5] Qcom UFS driver updates Manivannan Sadhasivam
                   ` (2 preceding siblings ...)
  2022-04-22 13:21 ` [PATCH 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled Manivannan Sadhasivam
@ 2022-04-22 13:21 ` Manivannan Sadhasivam
  2022-04-23  5:19   ` Bart Van Assche
  2022-04-22 13:21 ` [PATCH 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM Manivannan Sadhasivam
  4 siblings, 1 reply; 13+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-22 13:21 UTC (permalink / raw)
  To: martin.petersen, jejb
  Cc: avri.altman, alim.akhtar, bjorn.andersson, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel,
	Manivannan Sadhasivam

The wmb() inside ufshcd_send_command() is added to make sure that the
doorbell is committed immediately. This leads to couple of expectations:

1. The doorbell write should complete before the function return.
2. The doorbell write should not cross the function boundary.

2nd expectation is fullfilled by the Linux memory model as there is a
guarantee that the critical section won't cross the unlock (release)
operation.

1st expectation is not really needed here as there is no following read/
write that depends on the doorbell to be complete implicitly. Even if the
doorbell write is in a CPUs Write Buffer (WB), wmb() won't flush it. And
there is no real need of a WB flush here as well.

So let's get rid of the wmb() that seems redundant.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/scsi/ufs/ufshcd.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 9349557b8a01..ec514a6c5393 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -2116,9 +2116,6 @@ void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag)
 	__set_bit(task_tag, &hba->outstanding_reqs);
 	ufshcd_writel(hba, 1 << task_tag, REG_UTP_TRANSFER_REQ_DOOR_BELL);
 	spin_unlock_irqrestore(&hba->outstanding_lock, flags);
-
-	/* Make sure that doorbell is committed immediately */
-	wmb();
 }
 
 /**
-- 
2.25.1


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

* [PATCH 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM
  2022-04-22 13:21 [PATCH 0/5] Qcom UFS driver updates Manivannan Sadhasivam
                   ` (3 preceding siblings ...)
  2022-04-22 13:21 ` [PATCH 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command() Manivannan Sadhasivam
@ 2022-04-22 13:21 ` Manivannan Sadhasivam
  4 siblings, 0 replies; 13+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-22 13:21 UTC (permalink / raw)
  To: martin.petersen, jejb
  Cc: avri.altman, alim.akhtar, bjorn.andersson, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel,
	Manivannan Sadhasivam

In order to allow the block devices to enter autosuspend mode during
runtime, thereby allowing the ufshcd host driver to also runtime suspend,
let's make use of the RPM_AUTOSUSPEND flag.

Without this flag, userspace needs to enable the autosuspend feature of
the block devices through sysfs.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/scsi/ufs/ufs-qcom.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
index 5b9986c63eed..bbcaefd44699 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -879,6 +879,7 @@ static void ufs_qcom_set_caps(struct ufs_hba *hba)
 	hba->caps |= UFSHCD_CAP_WB_EN;
 	hba->caps |= UFSHCD_CAP_CRYPTO;
 	hba->caps |= UFSHCD_CAP_AGGR_POWER_COLLAPSE;
+	hba->caps |= UFSHCD_CAP_RPM_AUTOSUSPEND;
 
 	if (host->hw_ver.major >= 0x2) {
 		host->caps = UFS_QCOM_CAP_QUNIPRO |
-- 
2.25.1


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

* Re: [PATCH 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line
  2022-04-22 13:21 ` [PATCH 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
@ 2022-04-22 15:40   ` Andrew Halaney
  2022-04-23  9:54     ` Manivannan Sadhasivam
  0 siblings, 1 reply; 13+ messages in thread
From: Andrew Halaney @ 2022-04-22 15:40 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: martin.petersen, jejb, avri.altman, alim.akhtar, bjorn.andersson,
	linux-arm-msm, quic_asutoshd, quic_cang, linux-scsi,
	linux-kernel

On Fri, Apr 22, 2022 at 06:51:36PM +0530, Manivannan Sadhasivam wrote:
> On Qcom UFS platforms, the reset control line seems to be optional
> (for SoCs like MSM8996 and probably for others too). The current logic
> tries to mimic the `devm_reset_control_get_optional()` API but it also
> continues the probe if there is an error with the declared reset line in
> DT/ACPI.
> 
> In an ideal case, if the reset line is not declared in DT/ACPI, the probe
> should continue. But if there is problem in acquiring the declared reset
> line (like EPROBE_DEFER) it should fail and return the appropriate error
> code.
> 
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
>  drivers/scsi/ufs/ufs-qcom.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
> index 0d2e950d0865..5db0fd922062 100644
> --- a/drivers/scsi/ufs/ufs-qcom.c
> +++ b/drivers/scsi/ufs/ufs-qcom.c
> @@ -1002,13 +1002,13 @@ static int ufs_qcom_init(struct ufs_hba *hba)
>  	host->hba = hba;
>  	ufshcd_set_variant(hba, host);
>  
> -	/* Setup the reset control of HCI */
> -	host->core_reset = devm_reset_control_get(hba->dev, "rst");
> +	/* Setup the optional reset control of HCI */
> +	host->core_reset = devm_reset_control_get_optional(hba->dev, "rst");
>  	if (IS_ERR(host->core_reset)) {
>  		err = PTR_ERR(host->core_reset);
> -		dev_warn(dev, "Failed to get reset control %d\n", err);
> -		host->core_reset = NULL;
> -		err = 0;
> +		if (err != -EPROBE_DEFER)
> +			dev_err(dev, "Failed to get reset control %d\n", err);

Could we use dev_err_probe() here?

Otherwise, looks good to me.

> +		goto out_variant_clear;
>  	}
>  
>  	/* Fire up the reset controller. Failure here is non-fatal. */
> -- 
> 2.25.1
> 


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

* Re: [PATCH 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get()
  2022-04-22 13:21 ` [PATCH 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get() Manivannan Sadhasivam
@ 2022-04-22 16:51   ` Andrew Halaney
  0 siblings, 0 replies; 13+ messages in thread
From: Andrew Halaney @ 2022-04-22 16:51 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: martin.petersen, jejb, avri.altman, alim.akhtar, bjorn.andersson,
	linux-arm-msm, quic_asutoshd, quic_cang, linux-scsi,
	linux-kernel

On Fri, Apr 22, 2022 at 06:51:37PM +0530, Manivannan Sadhasivam wrote:
> There is no need to call devm_phy_get() if ACPI is used, so skip it.
> The "host->generic_phy" pointer should already be NULL due to the kzalloc,
> so no need to set it NULL again.
> 
> Also, don't print the error message in case of -EPROBE_DEFER and return
> the error code directly.
> 
> While at it, also remove the comment that has no relationship with
> devm_phy_get().
> 
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
>  drivers/scsi/ufs/ufs-qcom.c | 26 +++++---------------------
>  1 file changed, 5 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
> index 5db0fd922062..5f0a8f646eb5 100644
> --- a/drivers/scsi/ufs/ufs-qcom.c
> +++ b/drivers/scsi/ufs/ufs-qcom.c
> @@ -1022,28 +1022,12 @@ static int ufs_qcom_init(struct ufs_hba *hba)
>  		err = 0;
>  	}
>  
> -	/*
> -	 * voting/devoting device ref_clk source is time consuming hence
> -	 * skip devoting it during aggressive clock gating. This clock
> -	 * will still be gated off during runtime suspend.
> -	 */
> -	host->generic_phy = devm_phy_get(dev, "ufsphy");
> -
> -	if (host->generic_phy == ERR_PTR(-EPROBE_DEFER)) {
> -		/*
> -		 * UFS driver might be probed before the phy driver does.
> -		 * In that case we would like to return EPROBE_DEFER code.
> -		 */
> -		err = -EPROBE_DEFER;
> -		dev_warn(dev, "%s: required phy device. hasn't probed yet. err = %d\n",
> -			__func__, err);
> -		goto out_variant_clear;
> -	} else if (IS_ERR(host->generic_phy)) {
> -		if (has_acpi_companion(dev)) {
> -			host->generic_phy = NULL;
> -		} else {
> +	if (!has_acpi_companion(dev)) {
> +		host->generic_phy = devm_phy_get(dev, "ufsphy");
> +		if (IS_ERR(host->generic_phy)) {
>  			err = PTR_ERR(host->generic_phy);
> -			dev_err(dev, "%s: PHY get failed %d\n", __func__, err);
> +			if (err != -EPROBE_DEFER)
> +				dev_err(dev, "Failed to get PHY: %d\n", err);

Risking sounding like a bad broken record, but I think this too could
use dev_err_probe().

Looks good to me otherwise!

>  			goto out_variant_clear;
>  		}
>  	}
> -- 
> 2.25.1
> 


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

* Re: [PATCH 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled
  2022-04-22 13:21 ` [PATCH 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled Manivannan Sadhasivam
@ 2022-04-23  5:03   ` Bart Van Assche
  2022-04-23 11:45     ` Manivannan Sadhasivam
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Van Assche @ 2022-04-23  5:03 UTC (permalink / raw)
  To: Manivannan Sadhasivam, martin.petersen, jejb
  Cc: avri.altman, alim.akhtar, bjorn.andersson, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel, stable

On 4/22/22 06:21, Manivannan Sadhasivam wrote:
> In ufs_qcom_dev_ref_clk_ctrl(), it was noted that the ref_clk needs to be
> stable for atleast 1us. Eventhough there is wmb() to make sure the write
                ^              ^
Some spaces are missing.

> gets "completed", there is no guarantee that the write actually reached
> the UFS device. There is a good chance that the write could be stored in
> a Write Buffer (WB). In that case, eventhough the CPU waits for 1us, the
                                          ^
missing space----------------------------

> ref_clk might not be stable for that period.
> 
> So lets do a readl() to make sure that the previous write has reached the
> UFS device before udelay().
> 
> Cc: stable@vger.kernel.org
> Fixes: f06fcc7155dc ("scsi: ufs-qcom: add QUniPro hardware support and power optimizations")
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
>   drivers/scsi/ufs/ufs-qcom.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
> index 5f0a8f646eb5..5b9986c63eed 100644
> --- a/drivers/scsi/ufs/ufs-qcom.c
> +++ b/drivers/scsi/ufs/ufs-qcom.c
> @@ -690,6 +690,12 @@ static void ufs_qcom_dev_ref_clk_ctrl(struct ufs_qcom_host *host, bool enable)
>   		/* ensure that ref_clk is enabled/disabled before we return */
>   		wmb();
>   
> +		/*
> +		 * Make sure the write to ref_clk reaches the destination and
> +		 * not stored in a Write Buffer (WB).
> +		 */
> +		readl(host->dev_ref_clk_ctrl_mmio);
> +
>   		/*
>   		 * If we call hibern8 exit after this, we need to make sure that
>   		 * device ref_clk is stable for at least 1us before the hibern8

The comment above the wmb() call looks wrong to me. How about removing 
that wmb() call?

Thanks,

Bart.

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

* Re: [PATCH 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command()
  2022-04-22 13:21 ` [PATCH 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command() Manivannan Sadhasivam
@ 2022-04-23  5:19   ` Bart Van Assche
  2022-04-23 11:46     ` Manivannan Sadhasivam
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Van Assche @ 2022-04-23  5:19 UTC (permalink / raw)
  To: Manivannan Sadhasivam, martin.petersen, jejb
  Cc: avri.altman, alim.akhtar, bjorn.andersson, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel

On 4/22/22 06:21, Manivannan Sadhasivam wrote:
> The wmb() inside ufshcd_send_command() is added to make sure that the
> doorbell is committed immediately.

That's not the purpose of the wmb() call so I think the comment is wrong.

> This leads to couple of expectations:
> 
> 1. The doorbell write should complete before the function return.
> 2. The doorbell write should not cross the function boundary.
> 
> 2nd expectation is fullfilled by the Linux memory model as there is a
> guarantee that the critical section won't cross the unlock (release)
> operation.

I think you meant that the writel() won't cross the unlock operation?

> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 9349557b8a01..ec514a6c5393 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -2116,9 +2116,6 @@ void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag)
>   	__set_bit(task_tag, &hba->outstanding_reqs);
>   	ufshcd_writel(hba, 1 << task_tag, REG_UTP_TRANSFER_REQ_DOOR_BELL);
>   	spin_unlock_irqrestore(&hba->outstanding_lock, flags);
> -
> -	/* Make sure that doorbell is committed immediately */
> -	wmb();
>   }

Anyway:

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

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

* Re: [PATCH 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line
  2022-04-22 15:40   ` Andrew Halaney
@ 2022-04-23  9:54     ` Manivannan Sadhasivam
  0 siblings, 0 replies; 13+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-23  9:54 UTC (permalink / raw)
  To: Andrew Halaney
  Cc: martin.petersen, jejb, avri.altman, alim.akhtar, bjorn.andersson,
	linux-arm-msm, quic_asutoshd, quic_cang, linux-scsi,
	linux-kernel

On Fri, Apr 22, 2022 at 10:40:10AM -0500, Andrew Halaney wrote:
> On Fri, Apr 22, 2022 at 06:51:36PM +0530, Manivannan Sadhasivam wrote:
> > On Qcom UFS platforms, the reset control line seems to be optional
> > (for SoCs like MSM8996 and probably for others too). The current logic
> > tries to mimic the `devm_reset_control_get_optional()` API but it also
> > continues the probe if there is an error with the declared reset line in
> > DT/ACPI.
> > 
> > In an ideal case, if the reset line is not declared in DT/ACPI, the probe
> > should continue. But if there is problem in acquiring the declared reset
> > line (like EPROBE_DEFER) it should fail and return the appropriate error
> > code.
> > 
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > ---
> >  drivers/scsi/ufs/ufs-qcom.c | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
> > index 0d2e950d0865..5db0fd922062 100644
> > --- a/drivers/scsi/ufs/ufs-qcom.c
> > +++ b/drivers/scsi/ufs/ufs-qcom.c
> > @@ -1002,13 +1002,13 @@ static int ufs_qcom_init(struct ufs_hba *hba)
> >  	host->hba = hba;
> >  	ufshcd_set_variant(hba, host);
> >  
> > -	/* Setup the reset control of HCI */
> > -	host->core_reset = devm_reset_control_get(hba->dev, "rst");
> > +	/* Setup the optional reset control of HCI */
> > +	host->core_reset = devm_reset_control_get_optional(hba->dev, "rst");
> >  	if (IS_ERR(host->core_reset)) {
> >  		err = PTR_ERR(host->core_reset);
> > -		dev_warn(dev, "Failed to get reset control %d\n", err);
> > -		host->core_reset = NULL;
> > -		err = 0;
> > +		if (err != -EPROBE_DEFER)
> > +			dev_err(dev, "Failed to get reset control %d\n", err);
> 
> Could we use dev_err_probe() here?
> 

Yes. Will do the same for patch 2/5 as well.

Thanks,
Mani

> Otherwise, looks good to me.
> 
> > +		goto out_variant_clear;
> >  	}
> >  
> >  	/* Fire up the reset controller. Failure here is non-fatal. */
> > -- 
> > 2.25.1
> > 
> 

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

* Re: [PATCH 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled
  2022-04-23  5:03   ` Bart Van Assche
@ 2022-04-23 11:45     ` Manivannan Sadhasivam
  0 siblings, 0 replies; 13+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-23 11:45 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: martin.petersen, jejb, avri.altman, alim.akhtar, bjorn.andersson,
	linux-arm-msm, quic_asutoshd, quic_cang, linux-scsi,
	linux-kernel, stable

On Fri, Apr 22, 2022 at 10:03:22PM -0700, Bart Van Assche wrote:
> On 4/22/22 06:21, Manivannan Sadhasivam wrote:
> > In ufs_qcom_dev_ref_clk_ctrl(), it was noted that the ref_clk needs to be
> > stable for atleast 1us. Eventhough there is wmb() to make sure the write
>                ^              ^
> Some spaces are missing.
> 
> > gets "completed", there is no guarantee that the write actually reached
> > the UFS device. There is a good chance that the write could be stored in
> > a Write Buffer (WB). In that case, eventhough the CPU waits for 1us, the
>                                          ^
> missing space----------------------------
> 

Kind of used to it ;) Will fix it.

> > ref_clk might not be stable for that period.
> > 
> > So lets do a readl() to make sure that the previous write has reached the
> > UFS device before udelay().
> > 
> > Cc: stable@vger.kernel.org
> > Fixes: f06fcc7155dc ("scsi: ufs-qcom: add QUniPro hardware support and power optimizations")
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > ---
> >   drivers/scsi/ufs/ufs-qcom.c | 6 ++++++
> >   1 file changed, 6 insertions(+)
> > 
> > diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
> > index 5f0a8f646eb5..5b9986c63eed 100644
> > --- a/drivers/scsi/ufs/ufs-qcom.c
> > +++ b/drivers/scsi/ufs/ufs-qcom.c
> > @@ -690,6 +690,12 @@ static void ufs_qcom_dev_ref_clk_ctrl(struct ufs_qcom_host *host, bool enable)
> >   		/* ensure that ref_clk is enabled/disabled before we return */
> >   		wmb();
> > +		/*
> > +		 * Make sure the write to ref_clk reaches the destination and
> > +		 * not stored in a Write Buffer (WB).
> > +		 */
> > +		readl(host->dev_ref_clk_ctrl_mmio);
> > +
> >   		/*
> >   		 * If we call hibern8 exit after this, we need to make sure that
> >   		 * device ref_clk is stable for at least 1us before the hibern8
> 
> The comment above the wmb() call looks wrong to me. How about removing that
> wmb() call?
> 

Hmm, yes it could be removed as well. readl() on weakly ordered architectures
include a control dependency [1] so there is no way the instructions after it
can be speculated.

Thanks,
Mani

[1] https://www.spinics.net/lists/arm-kernel/msg689858.html

> Thanks,
> 
> Bart.

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

* Re: [PATCH 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command()
  2022-04-23  5:19   ` Bart Van Assche
@ 2022-04-23 11:46     ` Manivannan Sadhasivam
  0 siblings, 0 replies; 13+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-23 11:46 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: martin.petersen, jejb, avri.altman, alim.akhtar, bjorn.andersson,
	linux-arm-msm, quic_asutoshd, quic_cang, linux-scsi,
	linux-kernel

On Fri, Apr 22, 2022 at 10:19:14PM -0700, Bart Van Assche wrote:
> On 4/22/22 06:21, Manivannan Sadhasivam wrote:
> > The wmb() inside ufshcd_send_command() is added to make sure that the
> > doorbell is committed immediately.
> 
> That's not the purpose of the wmb() call so I think the comment is wrong.
> 
> > This leads to couple of expectations:
> > 
> > 1. The doorbell write should complete before the function return.
> > 2. The doorbell write should not cross the function boundary.
> > 
> > 2nd expectation is fullfilled by the Linux memory model as there is a
> > guarantee that the critical section won't cross the unlock (release)
> > operation.
> 
> I think you meant that the writel() won't cross the unlock operation?
> 

yes!

Thanks,
Mani

> > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> > index 9349557b8a01..ec514a6c5393 100644
> > --- a/drivers/scsi/ufs/ufshcd.c
> > +++ b/drivers/scsi/ufs/ufshcd.c
> > @@ -2116,9 +2116,6 @@ void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag)
> >   	__set_bit(task_tag, &hba->outstanding_reqs);
> >   	ufshcd_writel(hba, 1 << task_tag, REG_UTP_TRANSFER_REQ_DOOR_BELL);
> >   	spin_unlock_irqrestore(&hba->outstanding_lock, flags);
> > -
> > -	/* Make sure that doorbell is committed immediately */
> > -	wmb();
> >   }
> 
> Anyway:
> 
> Reviewed-by: Bart Van Assche <bvanassche@acm.org>

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

end of thread, other threads:[~2022-04-23 11:46 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-22 13:21 [PATCH 0/5] Qcom UFS driver updates Manivannan Sadhasivam
2022-04-22 13:21 ` [PATCH 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
2022-04-22 15:40   ` Andrew Halaney
2022-04-23  9:54     ` Manivannan Sadhasivam
2022-04-22 13:21 ` [PATCH 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get() Manivannan Sadhasivam
2022-04-22 16:51   ` Andrew Halaney
2022-04-22 13:21 ` [PATCH 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled Manivannan Sadhasivam
2022-04-23  5:03   ` Bart Van Assche
2022-04-23 11:45     ` Manivannan Sadhasivam
2022-04-22 13:21 ` [PATCH 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command() Manivannan Sadhasivam
2022-04-23  5:19   ` Bart Van Assche
2022-04-23 11:46     ` Manivannan Sadhasivam
2022-04-22 13:21 ` [PATCH 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM Manivannan Sadhasivam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.