From 3e234bd251f71ed13a06e64c99f103b49eb7d8ab Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 29 Mar 2022 15:37:26 -0700 Subject: [PATCH] FROMLIST: scsi: ufs: Pass the clock scaling timeout as an argument Prepare for adding an additional ufshcd_clock_scaling_prepare() call with a different timeout. Bug: 227177294 Link: https://lore.kernel.org/all/20220427233855.2685505-4-bvanassche@acm.org/ Change-Id: I67a569b074c292a3c37f20a1b1e36f95b682c5e8 Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index c8794045b14d..226e161bcee2 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1078,6 +1078,12 @@ static bool ufshcd_is_devfreq_scaling_required(struct ufs_hba *hba, return false; } +/* + * Wait until all pending SCSI commands and TMFs have finished or the timeout + * has expired. + * + * Return: 0 upon success; -EBUSY upon timeout. + */ static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba, u64 wait_timeout_us) { @@ -1182,9 +1188,14 @@ static int ufshcd_scale_gear(struct ufs_hba *hba, bool scale_up) return ret; } -static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba) +/* + * Wait until all pending SCSI commands and TMFs have finished or the timeout + * has expired. + * + * Return: 0 upon success; -EBUSY upon timeout. + */ +static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba, u64 timeout_us) { - #define DOORBELL_CLR_TOUT_US (1000 * 1000) /* 1 sec */ int ret = 0; /* * make sure that there are no outstanding requests when @@ -1193,7 +1204,7 @@ static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba) ufshcd_scsi_block_requests(hba); down_write(&hba->clk_scaling_lock); - if (ufshcd_wait_for_doorbell_clr(hba, DOORBELL_CLR_TOUT_US)) { + if (ufshcd_wait_for_doorbell_clr(hba, timeout_us)) { ret = -EBUSY; up_write(&hba->clk_scaling_lock); ufshcd_scsi_unblock_requests(hba); @@ -1234,7 +1245,7 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up) if (!hba->clk_scaling.is_allowed) return -EBUSY; - ret = ufshcd_clock_scaling_prepare(hba); + ret = ufshcd_clock_scaling_prepare(hba, 1 * USEC_PER_SEC); if (ret) return ret;