Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: "Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, Bart Van Assche <bvanassche@acm.org>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
	Peter Wang <peter.wang@mediatek.com>,
	Avri Altman <avri.altman@wdc.com>,
	Andrew Halaney <ahalaney@redhat.com>,
	Bean Huo <beanhuo@micron.com>,
	Maramaina Naresh <quic_mnaresh@quicinc.com>
Subject: [PATCH v6 06/11] scsi: ufs: core: Move the ufshcd_device_init() calls
Date: Wed, 16 Oct 2024 13:12:02 -0700	[thread overview]
Message-ID: <20241016201249.2256266-7-bvanassche@acm.org> (raw)
In-Reply-To: <20241016201249.2256266-1-bvanassche@acm.org>

Move the ufshcd_device_init() and ufshcd_process_hba_result() calls to
the ufshcd_probe_hba() callers. This change refactors the code without
modifying the behavior of the UFSHCI driver. This change prepares for
moving one ufshcd_device_init() call into ufshcd_init().

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/ufs/core/ufshcd.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 7b8eaf2b9ce2..8803031f1694 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -298,6 +298,7 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba);
 static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd);
 static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag);
 static void ufshcd_hba_exit(struct ufs_hba *hba);
+static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params);
 static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params);
 static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on);
 static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba);
@@ -7736,8 +7737,14 @@ static int ufshcd_host_reset_and_restore(struct ufs_hba *hba)
 	err = ufshcd_hba_enable(hba);
 
 	/* Establish the link again and restore the device */
-	if (!err)
-		err = ufshcd_probe_hba(hba, false);
+	if (!err) {
+		ktime_t probe_start = ktime_get();
+
+		err = ufshcd_device_init(hba, /*init_dev_params=*/false);
+		if (!err)
+			err = ufshcd_probe_hba(hba, false);
+		ufshcd_process_probe_result(hba, probe_start, err);
+	}
 
 	if (err)
 		dev_err(hba->dev, "%s: Host init failed %d\n", __func__, err);
@@ -8873,13 +8880,8 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)
  */
 static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
 {
-	ktime_t start = ktime_get();
 	int ret;
 
-	ret = ufshcd_device_init(hba, init_dev_params);
-	if (ret)
-		goto out;
-
 	if (!hba->pm_op_in_progress &&
 	    (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {
 		/* Reset the device and controller before doing reinit */
@@ -8892,13 +8894,13 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
 			dev_err(hba->dev, "Host controller enable failed\n");
 			ufshcd_print_evt_hist(hba);
 			ufshcd_print_host_state(hba);
-			goto out;
+			return ret;
 		}
 
 		/* Reinit the device */
 		ret = ufshcd_device_init(hba, init_dev_params);
 		if (ret)
-			goto out;
+			return ret;
 	}
 
 	ufshcd_print_pwr_info(hba);
@@ -8918,9 +8920,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
 		ufshcd_write_ee_control(hba);
 	ufshcd_configure_auto_hibern8(hba);
 
-out:
-	ufshcd_process_probe_result(hba, start, ret);
-	return ret;
+	return 0;
 }
 
 /**
@@ -8931,11 +8931,16 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
 static void ufshcd_async_scan(void *data, async_cookie_t cookie)
 {
 	struct ufs_hba *hba = (struct ufs_hba *)data;
+	ktime_t probe_start;
 	int ret;
 
 	down(&hba->host_sem);
 	/* Initialize hba, detect and initialize UFS device */
-	ret = ufshcd_probe_hba(hba, true);
+	probe_start = ktime_get();
+	ret = ufshcd_device_init(hba, /*init_dev_params=*/true);
+	if (ret == 0)
+		ret = ufshcd_probe_hba(hba, true);
+	ufshcd_process_probe_result(hba, probe_start, ret);
 	up(&hba->host_sem);
 	if (ret)
 		goto out;

  parent reply	other threads:[~2024-10-16 20:13 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-16 20:11 [PATCH v6 00/11] Combine the two UFS driver scsi_add_host() calls Bart Van Assche
2024-10-16 20:11 ` [PATCH v6 01/11] scsi: ufs: core: Introduce ufshcd_add_scsi_host() Bart Van Assche
2024-10-16 20:11 ` [PATCH v6 02/11] scsi: ufs: core: Introduce ufshcd_post_device_init() Bart Van Assche
2024-10-16 20:11 ` [PATCH v6 03/11] scsi: ufs: core: Call ufshcd_add_scsi_host() later Bart Van Assche
2024-10-16 20:12 ` [PATCH v6 04/11] scsi: ufs: core: Introduce ufshcd_process_probe_result() Bart Van Assche
2024-10-16 20:12 ` [PATCH v6 05/11] scsi: ufs: core: Convert a comment into an explicit check Bart Van Assche
2024-10-16 20:12 ` Bart Van Assche [this message]
2024-10-16 20:12 ` [PATCH v6 07/11] scsi: ufs: core: Move the ufshcd_device_init(hba, true) call Bart Van Assche
2024-10-16 20:12 ` [PATCH v6 08/11] scsi: ufs: core: Expand " Bart Van Assche
2024-10-16 20:12 ` [PATCH v6 09/11] scsi: ufs: core: Remove code that is no longer needed Bart Van Assche
2024-10-16 20:12 ` [PATCH v6 10/11] scsi: ufs: core: Move the MCQ scsi_add_host() call Bart Van Assche
2024-10-16 20:12 ` [PATCH v6 11/11] scsi: ufs: core: Move code out of an if-statement Bart Van Assche
2024-10-31 14:46   ` Neil Armstrong
2024-10-31 17:51     ` Bart Van Assche
2024-10-31 19:55       ` Neil Armstrong
2024-10-31 21:15         ` Bart Van Assche
2024-11-05 22:01           ` Bart Van Assche
2024-11-06  8:48             ` Neil Armstrong
2024-11-06  9:57             ` Neil Armstrong
2024-11-06 17:51               ` Bart Van Assche
2024-11-07 10:49                 ` Manivannan Sadhasivam
2024-10-25 19:30 ` [PATCH v6 00/11] Combine the two UFS driver scsi_add_host() calls Martin K. Petersen
2024-11-05  2:32 ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241016201249.2256266-7-bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=ahalaney@redhat.com \
    --cc=avri.altman@wdc.com \
    --cc=beanhuo@micron.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=martin.petersen@oracle.com \
    --cc=peter.wang@mediatek.com \
    --cc=quic_mnaresh@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox