All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Qcom UFS driver updates
@ 2022-04-23 14:02 Manivannan Sadhasivam
  2022-04-23 14:02 ` [PATCH v2 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-23 14:02 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, bvanassche,
	ahalaney, 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

Changes in v2:

* Used dev_err_probe() instead of dev_err().
* Removed the wmb() from ufs_qcom_dev_ref_clk_ctrl() as that is not required.
* Added Reviewed-by tag from Bart for patch 4/5.

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 | 44 ++++++++++++++-----------------------
 drivers/scsi/ufs/ufshcd.c   |  3 ---
 2 files changed, 16 insertions(+), 31 deletions(-)

-- 
2.25.1


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

* [PATCH v2 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line
  2022-04-23 14:02 [PATCH v2 0/5] Qcom UFS driver updates Manivannan Sadhasivam
@ 2022-04-23 14:02 ` Manivannan Sadhasivam
  2022-04-23 14:59   ` Bjorn Andersson
  2022-04-23 14:02 ` [PATCH v2 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get() Manivannan Sadhasivam
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-23 14:02 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, bvanassche,
	ahalaney, 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..bee81b45299e 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_probe(dev, err, "Failed to get reset control\n");
+		goto out_variant_clear;
 	}
 
 	/* Fire up the reset controller. Failure here is non-fatal. */
-- 
2.25.1


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

* [PATCH v2 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get()
  2022-04-23 14:02 [PATCH v2 0/5] Qcom UFS driver updates Manivannan Sadhasivam
  2022-04-23 14:02 ` [PATCH v2 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
@ 2022-04-23 14:02 ` Manivannan Sadhasivam
  2022-04-23 15:16   ` Bjorn Andersson
  2022-04-23 14:02 ` [PATCH v2 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled Manivannan Sadhasivam
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-23 14:02 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, bvanassche,
	ahalaney, 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 bee81b45299e..6ee33cc0ad09 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_probe(dev, err, "Failed to get PHY\n");
 			goto out_variant_clear;
 		}
 	}
-- 
2.25.1


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

* [PATCH v2 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled
  2022-04-23 14:02 [PATCH v2 0/5] Qcom UFS driver updates Manivannan Sadhasivam
  2022-04-23 14:02 ` [PATCH v2 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
  2022-04-23 14:02 ` [PATCH v2 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get() Manivannan Sadhasivam
@ 2022-04-23 14:02 ` Manivannan Sadhasivam
  2022-04-23 15:18   ` Bjorn Andersson
  2022-04-23 14:02 ` [PATCH v2 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command() Manivannan Sadhasivam
  2022-04-23 14:02 ` [PATCH v2 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM Manivannan Sadhasivam
  4 siblings, 1 reply; 14+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-23 14:02 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, bvanassche,
	ahalaney, Manivannan Sadhasivam, stable

In ufs_qcom_dev_ref_clk_ctrl(), it was noted that the ref_clk needs to be
stable for at least 1us. Even though 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, even though 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().

Also, the wmb() after writel_relaxed is not really needed. Both writel and
readl are ordered on all architectures and the CPU won't speculate
instructions after readl() due to the in-built control dependency with
read value on weakly ordered architectures. So it can be safely removed.

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 | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
index 6ee33cc0ad09..f47a16b7cff5 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -687,8 +687,11 @@ static void ufs_qcom_dev_ref_clk_ctrl(struct ufs_qcom_host *host, bool enable)
 
 		writel_relaxed(temp, host->dev_ref_clk_ctrl_mmio);
 
-		/* 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
-- 
2.25.1


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

* [PATCH v2 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command()
  2022-04-23 14:02 [PATCH v2 0/5] Qcom UFS driver updates Manivannan Sadhasivam
                   ` (2 preceding siblings ...)
  2022-04-23 14:02 ` [PATCH v2 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled Manivannan Sadhasivam
@ 2022-04-23 14:02 ` Manivannan Sadhasivam
  2022-04-23 15:19   ` Bjorn Andersson
  2022-04-24 11:04   ` Bean Huo
  2022-04-23 14:02 ` [PATCH v2 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM Manivannan Sadhasivam
  4 siblings, 2 replies; 14+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-23 14:02 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, bvanassche,
	ahalaney, 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.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
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] 14+ messages in thread

* [PATCH v2 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM
  2022-04-23 14:02 [PATCH v2 0/5] Qcom UFS driver updates Manivannan Sadhasivam
                   ` (3 preceding siblings ...)
  2022-04-23 14:02 ` [PATCH v2 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command() Manivannan Sadhasivam
@ 2022-04-23 14:02 ` Manivannan Sadhasivam
  2022-04-23 15:20   ` Bjorn Andersson
  4 siblings, 1 reply; 14+ messages in thread
From: Manivannan Sadhasivam @ 2022-04-23 14:02 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, bvanassche,
	ahalaney, 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 f47a16b7cff5..34c5970db445 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -876,6 +876,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] 14+ messages in thread

* Re: [PATCH v2 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line
  2022-04-23 14:02 ` [PATCH v2 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
@ 2022-04-23 14:59   ` Bjorn Andersson
  2022-04-25 12:59     ` Andrew Halaney
  0 siblings, 1 reply; 14+ messages in thread
From: Bjorn Andersson @ 2022-04-23 14:59 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: martin.petersen, jejb, avri.altman, alim.akhtar, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel, bvanassche,
	ahalaney

On Sat 23 Apr 07:02 PDT 2022, 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..bee81b45299e 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_probe() does this comparison internally, so you can omit it
here.

With that removed, feel free to add my:
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> +			dev_err_probe(dev, err, "Failed to get reset control\n");
> +		goto out_variant_clear;
>  	}
>  
>  	/* Fire up the reset controller. Failure here is non-fatal. */
> -- 
> 2.25.1
> 

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

* Re: [PATCH v2 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get()
  2022-04-23 14:02 ` [PATCH v2 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get() Manivannan Sadhasivam
@ 2022-04-23 15:16   ` Bjorn Andersson
  2022-04-25 13:01     ` Andrew Halaney
  0 siblings, 1 reply; 14+ messages in thread
From: Bjorn Andersson @ 2022-04-23 15:16 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: martin.petersen, jejb, avri.altman, alim.akhtar, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel, bvanassche,
	ahalaney

On Sat 23 Apr 07:02 PDT 2022, 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 bee81b45299e..6ee33cc0ad09 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_probe(dev, err, "Failed to get PHY\n");

I believe the idiomatic form is:
			err = dev_err_probe(dev, PTR_ERR(host->generic_phy), "Failed to get PHY\n");


But as with the previous patch, please remove the condition and you have
my:

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

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

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

* Re: [PATCH v2 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled
  2022-04-23 14:02 ` [PATCH v2 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled Manivannan Sadhasivam
@ 2022-04-23 15:18   ` Bjorn Andersson
  0 siblings, 0 replies; 14+ messages in thread
From: Bjorn Andersson @ 2022-04-23 15:18 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: martin.petersen, jejb, avri.altman, alim.akhtar, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel, bvanassche,
	ahalaney, stable

On Sat 23 Apr 07:02 PDT 2022, Manivannan Sadhasivam wrote:

> In ufs_qcom_dev_ref_clk_ctrl(), it was noted that the ref_clk needs to be
> stable for at least 1us. Even though 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, even though 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().
> 
> Also, the wmb() after writel_relaxed is not really needed. Both writel and
> readl are ordered on all architectures and the CPU won't speculate
> instructions after readl() due to the in-built control dependency with
> read value on weakly ordered architectures. So it can be safely removed.
> 
> 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>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

> ---
>  drivers/scsi/ufs/ufs-qcom.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
> index 6ee33cc0ad09..f47a16b7cff5 100644
> --- a/drivers/scsi/ufs/ufs-qcom.c
> +++ b/drivers/scsi/ufs/ufs-qcom.c
> @@ -687,8 +687,11 @@ static void ufs_qcom_dev_ref_clk_ctrl(struct ufs_qcom_host *host, bool enable)
>  
>  		writel_relaxed(temp, host->dev_ref_clk_ctrl_mmio);
>  
> -		/* 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
> -- 
> 2.25.1
> 

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

* Re: [PATCH v2 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command()
  2022-04-23 14:02 ` [PATCH v2 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command() Manivannan Sadhasivam
@ 2022-04-23 15:19   ` Bjorn Andersson
  2022-04-24 11:04   ` Bean Huo
  1 sibling, 0 replies; 14+ messages in thread
From: Bjorn Andersson @ 2022-04-23 15:19 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: martin.petersen, jejb, avri.altman, alim.akhtar, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel, bvanassche,
	ahalaney

On Sat 23 Apr 07:02 PDT 2022, Manivannan Sadhasivam wrote:

> 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.
> 
> Reviewed-by: Bart Van Assche <bvanassche@acm.org>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> ---
>  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	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM
  2022-04-23 14:02 ` [PATCH v2 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM Manivannan Sadhasivam
@ 2022-04-23 15:20   ` Bjorn Andersson
  0 siblings, 0 replies; 14+ messages in thread
From: Bjorn Andersson @ 2022-04-23 15:20 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: martin.petersen, jejb, avri.altman, alim.akhtar, linux-arm-msm,
	quic_asutoshd, quic_cang, linux-scsi, linux-kernel, bvanassche,
	ahalaney

On Sat 23 Apr 07:02 PDT 2022, Manivannan Sadhasivam wrote:

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

Reviewed-by: Bjorn Andersson <bjorn.andersson@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 f47a16b7cff5..34c5970db445 100644
> --- a/drivers/scsi/ufs/ufs-qcom.c
> +++ b/drivers/scsi/ufs/ufs-qcom.c
> @@ -876,6 +876,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	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command()
  2022-04-23 14:02 ` [PATCH v2 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command() Manivannan Sadhasivam
  2022-04-23 15:19   ` Bjorn Andersson
@ 2022-04-24 11:04   ` Bean Huo
  1 sibling, 0 replies; 14+ messages in thread
From: Bean Huo @ 2022-04-24 11:04 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, bvanassche,
	ahalaney


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

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

* Re: [PATCH v2 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line
  2022-04-23 14:59   ` Bjorn Andersson
@ 2022-04-25 12:59     ` Andrew Halaney
  0 siblings, 0 replies; 14+ messages in thread
From: Andrew Halaney @ 2022-04-25 12:59 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Manivannan Sadhasivam, martin.petersen, jejb, avri.altman,
	alim.akhtar, linux-arm-msm, quic_asutoshd, quic_cang, linux-scsi,
	linux-kernel, bvanassche

On Sat, Apr 23, 2022 at 07:59:17AM -0700, Bjorn Andersson wrote:
> On Sat 23 Apr 07:02 PDT 2022, 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..bee81b45299e 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_probe() does this comparison internally, so you can omit it
> here.
> 
> With that removed, feel free to add my:
> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> 
> Regards,
> Bjorn

+1; well with that change in place:
Reviewed-by: Andrew Halaney <ahalaney@redhat.com>

Thanks,
Andrew

> 
> > +			dev_err_probe(dev, err, "Failed to get reset control\n");
> > +		goto out_variant_clear;
> >  	}
> >  
> >  	/* Fire up the reset controller. Failure here is non-fatal. */
> > -- 
> > 2.25.1
> > 
> 


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

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

On Sat, Apr 23, 2022 at 08:16:55AM -0700, Bjorn Andersson wrote:
> On Sat 23 Apr 07:02 PDT 2022, 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 bee81b45299e..6ee33cc0ad09 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_probe(dev, err, "Failed to get PHY\n");
> 
> I believe the idiomatic form is:
> 			err = dev_err_probe(dev, PTR_ERR(host->generic_phy), "Failed to get PHY\n");
> 
> 
> But as with the previous patch, please remove the condition and you have
> my:
> 
> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> 
> Regards,
> Bjorn

With the Bjorn's suggested change applied:
Reviewed-by: Andrew Halaney <ahalaney@redhat.com>

Thanks,
Andrew

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


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

end of thread, other threads:[~2022-04-25 13:01 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-23 14:02 [PATCH v2 0/5] Qcom UFS driver updates Manivannan Sadhasivam
2022-04-23 14:02 ` [PATCH v2 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
2022-04-23 14:59   ` Bjorn Andersson
2022-04-25 12:59     ` Andrew Halaney
2022-04-23 14:02 ` [PATCH v2 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get() Manivannan Sadhasivam
2022-04-23 15:16   ` Bjorn Andersson
2022-04-25 13:01     ` Andrew Halaney
2022-04-23 14:02 ` [PATCH v2 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled Manivannan Sadhasivam
2022-04-23 15:18   ` Bjorn Andersson
2022-04-23 14:02 ` [PATCH v2 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command() Manivannan Sadhasivam
2022-04-23 15:19   ` Bjorn Andersson
2022-04-24 11:04   ` Bean Huo
2022-04-23 14:02 ` [PATCH v2 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM Manivannan Sadhasivam
2022-04-23 15:20   ` Bjorn Andersson

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.