diff mbox series

[v2,5/9] ufs: core: Move the ufshcd_device_init() call

Message ID 20240822213645.1125016-6-bvanassche@acm.org (mailing list archive)
State Superseded
Headers show
Series Simplify the UFS driver initialization code | expand

Commit Message

Bart Van Assche Aug. 22, 2024, 9:36 p.m. UTC
Move the ufshcd_device_init() call to the ufshcd_probe_hba() callers and
remove the 'init_dev_params' argument of ufshcd_probe_hba(). This change
refactors the code without modifying the behavior of the UFSHCI driver.

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

Comments

Manivannan Sadhasivam Aug. 25, 2024, 5:22 a.m. UTC | #1
On Thu, Aug 22, 2024 at 02:36:06PM -0700, Bart Van Assche wrote:
> Move the ufshcd_device_init() call to the ufshcd_probe_hba() callers and
> remove the 'init_dev_params' argument of ufshcd_probe_hba(). This change
> refactors the code without modifying the behavior of the UFSHCI driver.
> 

I don't see an explanation on why this refactoring is necessary though.
Especially when you move it to callers.

- Mani

> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>  drivers/ufs/core/ufshcd.c | 25 +++++++++++++------------
>  1 file changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index b513ef46d848..5c8751672bc7 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -298,7 +298,8 @@ 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_probe_hba(struct ufs_hba *hba, bool init_dev_params);
> +static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params);
> +static int ufshcd_probe_hba(struct ufs_hba *hba);
>  static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on);
>  static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba);
>  static int ufshcd_host_reset_and_restore(struct ufs_hba *hba);
> @@ -7717,8 +7718,11 @@ 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) {
> +		err = ufshcd_device_init(hba, /*init_dev_params=*/false);
> +		if (!err)
> +			err = ufshcd_probe_hba(hba);
> +	}
>  
>  	if (err)
>  		dev_err(hba->dev, "%s: Host init failed %d\n", __func__, err);
> @@ -8855,21 +8859,16 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)
>  /**
>   * ufshcd_probe_hba - probe hba to detect device and initialize it
>   * @hba: per-adapter instance
> - * @init_dev_params: whether or not to call ufshcd_device_params_init().
>   *
>   * Execute link-startup and verify device initialization
>   *
>   * Return: 0 upon success; < 0 upon failure.
>   */
> -static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
> +static int ufshcd_probe_hba(struct ufs_hba *hba)
>  {
>  	ktime_t start = ktime_get();
>  	unsigned long flags;
> -	int ret;
> -
> -	ret = ufshcd_device_init(hba, init_dev_params);
> -	if (ret)
> -		goto out;
> +	int ret = 0;
>  
>  	if (!hba->pm_op_in_progress &&
>  	    (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {
> @@ -8887,7 +8886,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
>  		}
>  
>  		/* Reinit the device */
> -		ret = ufshcd_device_init(hba, init_dev_params);
> +		ret = ufshcd_device_init(hba, /*init_dev_params=*/false);
>  		if (ret)
>  			goto out;
>  	}
> @@ -8935,7 +8934,9 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
>  
>  	down(&hba->host_sem);
>  	/* Initialize hba, detect and initialize UFS device */
> -	ret = ufshcd_probe_hba(hba, true);
> +	ret = ufshcd_device_init(hba, /*init_dev_params=*/true);
> +	if (ret == 0)
> +		ret = ufshcd_probe_hba(hba);
>  	up(&hba->host_sem);
>  	if (ret)
>  		goto out;
Bart Van Assche Aug. 28, 2024, 5:14 p.m. UTC | #2
On 8/25/24 1:22 AM, Manivannan Sadhasivam wrote:
> On Thu, Aug 22, 2024 at 02:36:06PM -0700, Bart Van Assche wrote:
>> Move the ufshcd_device_init() call to the ufshcd_probe_hba() callers and
>> remove the 'init_dev_params' argument of ufshcd_probe_hba(). This change
>> refactors the code without modifying the behavior of the UFSHCI driver.
>>
> 
> I don't see an explanation on why this refactoring is necessary though.
> Especially when you move it to callers.

Hi Mani,

I will add the following in the patch description: "This change prepares
for moving one ufshcd_device_init() call into ufshcd_init()."

Thanks,

Bart.
diff mbox series

Patch

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index b513ef46d848..5c8751672bc7 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -298,7 +298,8 @@  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_probe_hba(struct ufs_hba *hba, bool init_dev_params);
+static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params);
+static int ufshcd_probe_hba(struct ufs_hba *hba);
 static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on);
 static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba);
 static int ufshcd_host_reset_and_restore(struct ufs_hba *hba);
@@ -7717,8 +7718,11 @@  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) {
+		err = ufshcd_device_init(hba, /*init_dev_params=*/false);
+		if (!err)
+			err = ufshcd_probe_hba(hba);
+	}
 
 	if (err)
 		dev_err(hba->dev, "%s: Host init failed %d\n", __func__, err);
@@ -8855,21 +8859,16 @@  static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)
 /**
  * ufshcd_probe_hba - probe hba to detect device and initialize it
  * @hba: per-adapter instance
- * @init_dev_params: whether or not to call ufshcd_device_params_init().
  *
  * Execute link-startup and verify device initialization
  *
  * Return: 0 upon success; < 0 upon failure.
  */
-static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
+static int ufshcd_probe_hba(struct ufs_hba *hba)
 {
 	ktime_t start = ktime_get();
 	unsigned long flags;
-	int ret;
-
-	ret = ufshcd_device_init(hba, init_dev_params);
-	if (ret)
-		goto out;
+	int ret = 0;
 
 	if (!hba->pm_op_in_progress &&
 	    (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {
@@ -8887,7 +8886,7 @@  static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
 		}
 
 		/* Reinit the device */
-		ret = ufshcd_device_init(hba, init_dev_params);
+		ret = ufshcd_device_init(hba, /*init_dev_params=*/false);
 		if (ret)
 			goto out;
 	}
@@ -8935,7 +8934,9 @@  static void ufshcd_async_scan(void *data, async_cookie_t cookie)
 
 	down(&hba->host_sem);
 	/* Initialize hba, detect and initialize UFS device */
-	ret = ufshcd_probe_hba(hba, true);
+	ret = ufshcd_device_init(hba, /*init_dev_params=*/true);
+	if (ret == 0)
+		ret = ufshcd_probe_hba(hba);
 	up(&hba->host_sem);
 	if (ret)
 		goto out;