mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RESEND v2] scsi: ufs: Use wait-for-reg in HCE init
@ 2024-10-16 10:21 Avri Altman
  2024-10-17 21:50 ` Bart Van Assche
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Avri Altman @ 2024-10-16 10:21 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, linux-kernel, Bart Van Assche, Avri Altman

The current so called "inner loop" in ufshcd_hba_execute_hce() is open
coding ufshcd_wait_for_register. Replace it by ufshcd_wait_for_register.
This is a code simplification - no functional change.

Signed-off-by: Avri Altman <avri.altman@wdc.com>

---
Changes in v2:
 - Elaborate the commit log (Bart)
 - Change a while-loop into a for-loop (Bart)
---
 drivers/ufs/core/ufshcd.c | 67 ++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 37 deletions(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 9e6d008f4ea4..146915f92a85 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -4818,51 +4818,44 @@ EXPORT_SYMBOL_GPL(ufshcd_hba_stop);
  */
 static int ufshcd_hba_execute_hce(struct ufs_hba *hba)
 {
-	int retry_outer = 3;
-	int retry_inner;
+	int retry;
 
-start:
-	if (ufshcd_is_hba_active(hba))
-		/* change controller state to "reset state" */
-		ufshcd_hba_stop(hba);
+	for (retry = 3; retry > 0; retry--) {
+		if (ufshcd_is_hba_active(hba))
+			/* change controller state to "reset state" */
+			ufshcd_hba_stop(hba);
 
-	/* UniPro link is disabled at this point */
-	ufshcd_set_link_off(hba);
+		/* UniPro link is disabled at this point */
+		ufshcd_set_link_off(hba);
 
-	ufshcd_vops_hce_enable_notify(hba, PRE_CHANGE);
+		ufshcd_vops_hce_enable_notify(hba, PRE_CHANGE);
 
-	/* start controller initialization sequence */
-	ufshcd_hba_start(hba);
+		/* start controller initialization sequence */
+		ufshcd_hba_start(hba);
 
-	/*
-	 * To initialize a UFS host controller HCE bit must be set to 1.
-	 * During initialization the HCE bit value changes from 1->0->1.
-	 * When the host controller completes initialization sequence
-	 * it sets the value of HCE bit to 1. The same HCE bit is read back
-	 * to check if the controller has completed initialization sequence.
-	 * So without this delay the value HCE = 1, set in the previous
-	 * instruction might be read back.
-	 * This delay can be changed based on the controller.
-	 */
-	ufshcd_delay_us(hba->vps->hba_enable_delay_us, 100);
+		/*
+		 * To initialize a UFS host controller HCE bit must be set to 1.
+		 * During initialization the HCE bit value changes from 1->0->1.
+		 * When the host controller completes initialization sequence
+		 * it sets the value of HCE bit to 1. The same HCE bit is read back
+		 * to check if the controller has completed initialization sequence.
+		 * So without this delay the value HCE = 1, set in the previous
+		 * instruction might be read back.
+		 * This delay can be changed based on the controller.
+		 */
+		ufshcd_delay_us(hba->vps->hba_enable_delay_us, 100);
 
-	/* wait for the host controller to complete initialization */
-	retry_inner = 50;
-	while (!ufshcd_is_hba_active(hba)) {
-		if (retry_inner) {
-			retry_inner--;
-		} else {
-			dev_err(hba->dev,
-				"Controller enable failed\n");
-			if (retry_outer) {
-				retry_outer--;
-				goto start;
-			}
-			return -EIO;
-		}
-		usleep_range(1000, 1100);
+		/* wait for the host controller to complete initialization */
+		if (!ufshcd_wait_for_register(hba, REG_CONTROLLER_ENABLE, CONTROLLER_ENABLE,
+					      CONTROLLER_ENABLE, 1000, 50))
+			break;
+
+		dev_err(hba->dev, "Enabling the controller failed\n");
 	}
 
+	if (!retry)
+		return -EIO;
+
 	/* enable UIC related interrupts */
 	ufshcd_enable_intr(hba, UFSHCD_UIC_MASK);
 
-- 
2.25.1


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

* Re: [PATCH RESEND v2] scsi: ufs: Use wait-for-reg in HCE init
  2024-10-16 10:21 [PATCH RESEND v2] scsi: ufs: Use wait-for-reg in HCE init Avri Altman
@ 2024-10-17 21:50 ` Bart Van Assche
  2024-10-25 18:40 ` Martin K. Petersen
  2024-11-05  2:32 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2024-10-17 21:50 UTC (permalink / raw)
  To: Avri Altman, Martin K . Petersen; +Cc: linux-scsi, linux-kernel

On 10/16/24 3:21 AM, Avri Altman wrote:
> The current so called "inner loop" in ufshcd_hba_execute_hce() is open
> coding ufshcd_wait_for_register. Replace it by ufshcd_wait_for_register.
> This is a code simplification - no functional change.

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

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

* Re: [PATCH RESEND v2] scsi: ufs: Use wait-for-reg in HCE init
  2024-10-16 10:21 [PATCH RESEND v2] scsi: ufs: Use wait-for-reg in HCE init Avri Altman
  2024-10-17 21:50 ` Bart Van Assche
@ 2024-10-25 18:40 ` Martin K. Petersen
  2024-11-05  2:32 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2024-10-25 18:40 UTC (permalink / raw)
  To: Avri Altman
  Cc: Martin K . Petersen, linux-scsi, linux-kernel, Bart Van Assche


Avri,

> The current so called "inner loop" in ufshcd_hba_execute_hce() is open
> coding ufshcd_wait_for_register. Replace it by
> ufshcd_wait_for_register. This is a code simplification - no
> functional change.

Applied to 6.13/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH RESEND v2] scsi: ufs: Use wait-for-reg in HCE init
  2024-10-16 10:21 [PATCH RESEND v2] scsi: ufs: Use wait-for-reg in HCE init Avri Altman
  2024-10-17 21:50 ` Bart Van Assche
  2024-10-25 18:40 ` Martin K. Petersen
@ 2024-11-05  2:32 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2024-11-05  2:32 UTC (permalink / raw)
  To: Avri Altman
  Cc: Martin K . Petersen, linux-scsi, linux-kernel, Bart Van Assche

On Wed, 16 Oct 2024 13:21:41 +0300, Avri Altman wrote:

> The current so called "inner loop" in ufshcd_hba_execute_hce() is open
> coding ufshcd_wait_for_register. Replace it by ufshcd_wait_for_register.
> This is a code simplification - no functional change.
> 
> 

Applied to 6.13/scsi-queue, thanks!

[1/1] scsi: ufs: Use wait-for-reg in HCE init
      https://git.kernel.org/mkp/scsi/c/6c1143bb5d12

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2024-11-05  2:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-16 10:21 [PATCH RESEND v2] scsi: ufs: Use wait-for-reg in HCE init Avri Altman
2024-10-17 21:50 ` Bart Van Assche
2024-10-25 18:40 ` Martin K. Petersen
2024-11-05  2:32 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®