RE: [PATCH v1] scsi: ufs: remove clk_scaling_lock when clkscaling isn't supported.

From: Avri Altman
Date: Sun Feb 06 2022 - 03:22:08 EST



> clk_scaling_lock is to prevent from running clkscaling related operations
> with others which might be affected by the operations concurrently.
> I think it looks hardware specific.
> If the feature isn't supported, I think there is no reasonto prevent from
^^^ reason to

> running other functions, such as ufshcd_queuecommand and
It is no longer used in queuecommand since 5675c381ea51 and 8d077ede48c1

> ufshcd_exec_dev_cmd, concurrently.
>
> So I add a condition at some points protecting with clk_scaling_lock.
But you still need a way to serialize device management commands.

Thanks,
Avri

>
> Signed-off-by: Kiwoong Kim <kwmad.kim@xxxxxxxxxxx>
> ---
> drivers/scsi/ufs/ufshcd.c | 21 ++++++++++++++-------
> 1 file changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 460d2b4..8471c90 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -2980,7 +2980,8 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba,
> /* Protects use of hba->reserved_slot. */
> lockdep_assert_held(&hba->dev_cmd.lock);
>
> - down_read(&hba->clk_scaling_lock);
> + if (ufshcd_is_clkscaling_supported(hba))
> + down_read(&hba->clk_scaling_lock);
>
> lrbp = &hba->lrb[tag];
> WARN_ON(lrbp->cmd);
> @@ -2998,7 +2999,8 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba,
> (struct utp_upiu_req *)lrbp->ucd_rsp_ptr);
>
> out:
> - up_read(&hba->clk_scaling_lock);
> + if (ufshcd_is_clkscaling_supported(hba))
> + up_read(&hba->clk_scaling_lock);
> return err;
> }
>
> @@ -6014,7 +6016,8 @@ static void ufshcd_err_handling_prepare(struct
> ufs_hba *hba)
> if (ufshcd_is_clkscaling_supported(hba) &&
> hba->clk_scaling.is_enabled)
> ufshcd_suspend_clkscaling(hba);
> - ufshcd_clk_scaling_allow(hba, false);
> + if (ufshcd_is_clkscaling_supported(hba))
> + ufshcd_clk_scaling_allow(hba, false);
> }
> ufshcd_scsi_block_requests(hba);
> /* Drain ufshcd_queuecommand() */
> @@ -6247,7 +6250,8 @@ static void ufshcd_err_handler(struct work_struct
> *work)
> * Hold the scaling lock just in case dev cmds
> * are sent via bsg and/or sysfs.
> */
> - down_write(&hba->clk_scaling_lock);
> + if (ufshcd_is_clkscaling_supported(hba))
> + down_write(&hba->clk_scaling_lock);
> hba->force_pmc = true;
> pmc_err = ufshcd_config_pwr_mode(hba, &(hba->pwr_info));
> if (pmc_err) {
> @@ -6257,7 +6261,8 @@ static void ufshcd_err_handler(struct work_struct
> *work)
> }
> hba->force_pmc = false;
> ufshcd_print_pwr_info(hba);
> - up_write(&hba->clk_scaling_lock);
> + if (ufshcd_is_clkscaling_supported(hba))
> + up_write(&hba->clk_scaling_lock);
> spin_lock_irqsave(hba->host->host_lock, flags);
> }
>
> @@ -6753,7 +6758,8 @@ static int ufshcd_issue_devman_upiu_cmd(struct
> ufs_hba *hba,
> /* Protects use of hba->reserved_slot. */
> lockdep_assert_held(&hba->dev_cmd.lock);
>
> - down_read(&hba->clk_scaling_lock);
> + if (ufshcd_is_clkscaling_supported(hba))
> + down_read(&hba->clk_scaling_lock);
>
> lrbp = &hba->lrb[tag];
> WARN_ON(lrbp->cmd);
> @@ -6822,7 +6828,8 @@ static int ufshcd_issue_devman_upiu_cmd(struct
> ufs_hba *hba,
> ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR :
> UFS_QUERY_COMP,
> (struct utp_upiu_req *)lrbp->ucd_rsp_ptr);
>
> - up_read(&hba->clk_scaling_lock);
> + if (ufshcd_is_clkscaling_supported(hba))
> + up_read(&hba->clk_scaling_lock);
> return err;
> }
>
> --
> 2.7.4