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

* Removed check for EPROBE_DEFER and used the return value from dev_err_probe
* Collected Reviewed-by and Acked-by tags

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

-- 
2.25.1


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

* [PATCH v3 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line
  2022-05-04  8:42 [PATCH v3 0/5] Qcom UFS driver updates Manivannan Sadhasivam
@ 2022-05-04  8:42 ` Manivannan Sadhasivam
  2022-05-04  8:42 ` [PATCH v3 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get() Manivannan Sadhasivam
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Manivannan Sadhasivam @ 2022-05-04  8:42 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.

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Reviewed-by: Andrew Halaney <ahalaney@redhat.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/scsi/ufs/ufs-qcom.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
index 0d2e950d0865..9e69b9ac58f9 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -1002,13 +1002,12 @@ 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;
+		err = dev_err_probe(dev, PTR_ERR(host->core_reset),
+				    "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] 8+ messages in thread

* [PATCH v3 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get()
  2022-05-04  8:42 [PATCH v3 0/5] Qcom UFS driver updates Manivannan Sadhasivam
  2022-05-04  8:42 ` [PATCH v3 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
@ 2022-05-04  8:42 ` Manivannan Sadhasivam
  2022-05-04  8:42 ` [PATCH v3 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled Manivannan Sadhasivam
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Manivannan Sadhasivam @ 2022-05-04  8:42 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.

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

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Reviewed-by: Andrew Halaney <ahalaney@redhat.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/scsi/ufs/ufs-qcom.c | 26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)

diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
index 9e69b9ac58f9..6126e50b9af4 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -1021,28 +1021,10 @@ 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 {
-			err = PTR_ERR(host->generic_phy);
-			dev_err(dev, "%s: PHY get failed %d\n", __func__, err);
+	if (!has_acpi_companion(dev)) {
+		host->generic_phy = devm_phy_get(dev, "ufsphy");
+		if (IS_ERR(host->generic_phy)) {
+			err = dev_err_probe(dev, PTR_ERR(host->generic_phy), "Failed to get PHY\n");
 			goto out_variant_clear;
 		}
 	}
-- 
2.25.1


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

* [PATCH v3 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled
  2022-05-04  8:42 [PATCH v3 0/5] Qcom UFS driver updates Manivannan Sadhasivam
  2022-05-04  8:42 ` [PATCH v3 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
  2022-05-04  8:42 ` [PATCH v3 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get() Manivannan Sadhasivam
@ 2022-05-04  8:42 ` Manivannan Sadhasivam
  2022-05-04  8:42 ` [PATCH v3 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command() Manivannan Sadhasivam
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Manivannan Sadhasivam @ 2022-05-04  8:42 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")
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
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 6126e50b9af4..b718c38fccc9 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] 8+ messages in thread

* [PATCH v3 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command()
  2022-05-04  8:42 [PATCH v3 0/5] Qcom UFS driver updates Manivannan Sadhasivam
                   ` (2 preceding siblings ...)
  2022-05-04  8:42 ` [PATCH v3 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled Manivannan Sadhasivam
@ 2022-05-04  8:42 ` Manivannan Sadhasivam
  2022-05-04  8:42 ` [PATCH v3 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM Manivannan Sadhasivam
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Manivannan Sadhasivam @ 2022-05-04  8:42 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, Bean Huo

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>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Acked-by: Bean Huo <beanhuo@micron.com>
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] 8+ messages in thread

* [PATCH v3 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM
  2022-05-04  8:42 [PATCH v3 0/5] Qcom UFS driver updates Manivannan Sadhasivam
                   ` (3 preceding siblings ...)
  2022-05-04  8:42 ` [PATCH v3 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command() Manivannan Sadhasivam
@ 2022-05-04  8:42 ` Manivannan Sadhasivam
  2022-05-11  1:53 ` [PATCH v3 0/5] Qcom UFS driver updates Martin K. Petersen
  2022-05-17  2:16 ` Martin K. Petersen
  6 siblings, 0 replies; 8+ messages in thread
From: Manivannan Sadhasivam @ 2022-05-04  8:42 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.

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
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 b718c38fccc9..358fa8ce51b8 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] 8+ messages in thread

* Re: [PATCH v3 0/5] Qcom UFS driver updates
  2022-05-04  8:42 [PATCH v3 0/5] Qcom UFS driver updates Manivannan Sadhasivam
                   ` (4 preceding siblings ...)
  2022-05-04  8:42 ` [PATCH v3 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM Manivannan Sadhasivam
@ 2022-05-11  1:53 ` Martin K. Petersen
  2022-05-17  2:16 ` Martin K. Petersen
  6 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2022-05-11  1:53 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, bvanassche, ahalaney


Manivannan,

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

Applied to 5.19/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH v3 0/5] Qcom UFS driver updates
  2022-05-04  8:42 [PATCH v3 0/5] Qcom UFS driver updates Manivannan Sadhasivam
                   ` (5 preceding siblings ...)
  2022-05-11  1:53 ` [PATCH v3 0/5] Qcom UFS driver updates Martin K. Petersen
@ 2022-05-17  2:16 ` Martin K. Petersen
  6 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2022-05-17  2:16 UTC (permalink / raw)
  To: Manivannan Sadhasivam, jejb
  Cc: Martin K . Petersen, bjorn.andersson, quic_cang, alim.akhtar,
	avri.altman, linux-kernel, linux-scsi, linux-arm-msm, ahalaney,
	quic_asutoshd, bvanassche

On Wed, 4 May 2022 14:12:07 +0530, Manivannan Sadhasivam wrote:

> 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
> 
> [...]

Applied to 5.19/scsi-queue, thanks!

[1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line
      https://git.kernel.org/mkp/scsi/c/223b17ed76eb
[2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get()
      https://git.kernel.org/mkp/scsi/c/c9ed9a6c56af
[3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled
      https://git.kernel.org/mkp/scsi/c/8eecddfca30e
[4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command()
      https://git.kernel.org/mkp/scsi/c/23803bacaab4
[5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM
      https://git.kernel.org/mkp/scsi/c/6f21d9274c77

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2022-05-17  2:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-04  8:42 [PATCH v3 0/5] Qcom UFS driver updates Manivannan Sadhasivam
2022-05-04  8:42 ` [PATCH v3 1/5] scsi: ufs: qcom: Fix acquiring the optional reset control line Manivannan Sadhasivam
2022-05-04  8:42 ` [PATCH v3 2/5] scsi: ufs: qcom: Simplify handling of devm_phy_get() Manivannan Sadhasivam
2022-05-04  8:42 ` [PATCH v3 3/5] scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled Manivannan Sadhasivam
2022-05-04  8:42 ` [PATCH v3 4/5] scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command() Manivannan Sadhasivam
2022-05-04  8:42 ` [PATCH v3 5/5] scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM Manivannan Sadhasivam
2022-05-11  1:53 ` [PATCH v3 0/5] Qcom UFS driver updates Martin K. Petersen
2022-05-17  2:16 ` Martin K. Petersen

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.