Skip to content

Commit

Permalink
scsi: ufs: core: Move the ufshcd_device_init() calls
Browse files Browse the repository at this point in the history
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>
Link: https://lore.kernel.org/r/20241016201249.2256266-7-bvanassche@acm.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Bart Van Assche authored and Martin K. Petersen committed Oct 25, 2024
1 parent 0936001 commit 639e204
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions drivers/ufs/core/ufshcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -7690,8 +7691,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);
Expand Down Expand Up @@ -8827,13 +8834,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 */
Expand All @@ -8846,13 +8848,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);
Expand All @@ -8872,9 +8874,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;
}

/**
Expand All @@ -8885,11 +8885,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;
Expand Down

0 comments on commit 639e204

Please sign in to comment.