UFS driver general fixes bundle 4
Subsystems (2)
v2 cover UFS driver general fixes bundle 4
This bundle includes 6 general fixes for UFS driver.
Changes since v1:
- Fixed minor typo
Asutosh Das (1):
scsi: ufs: set load before setting voltage in regulators
Can Guo (4):
scsi: ufs: Remove the check before call setup clock notify vops
scsi: ufs-qcom: Adjust bus bandwidth voting and unvoting
scsi: ufs: Add dev ref clock gating wait time support
scsi: ufs: Fix ufshcd_hold() caused scheduling while atomic
Sayali Lokhande (1):
scsi: ufs: Flush exception event before suspend
drivers/scsi/ufs/ufs-qcom.c | 57 +++++++++++++++-------- drivers/scsi/ufs/ufs.h | 3 ++ drivers/scsi/ufs/ufshcd.c | 108 ++++++++++++++++++++++++++++++++------------ 3 files changed, 122 insertions(+), 46 deletions(-)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 1/6 scsi: ufs: Flush exception event before suspend
From: Sayali Lokhande <[email protected]>
Exception event can be raised by the device when system suspend is in progress. This will result in unclocked register access in exception event handler as clocks will be turned off during suspend. This change makes sure to flush exception event handler work in suspend before disabling clocks to avoid unclocked register access issue.
--- drivers/scsi/ufs/ufshcd.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/scsi/ufs/ufshcd.c +18 -3
@@ -4760,8 +4760,15 @@ static void ufshcd_slave_destroy(struct scsi_device *sdev)* UFS device needs urgent BKOPs. */ if (!hba->pm_op_in_progress && -ufshcd_is_exception_event (lrbp->ucd_rsp_ptr)) -schedule_work (&hba->eeh_work); +ufshcd_is_exception_event (lrbp->ucd_rsp_ptr)) { +/* +* Prevent suspend once eeh_work is scheduled +* to avoid deadlock between ufshcd_suspend +* and exception event handler. +*/ +if (schedule_work (&hba->eeh_work)) +pm_runtime_get_noresume (hba->dev); + }break ;case UPIU_TRANSACTION_REJECT_UPIU :/* TODO: handle Reject UPIU Response */
@@ -5215,7 +5222,14 @@ static void ufshcd_exception_event_handler(struct work_struct *work) out:scsi_unblock_requests (hba->host); -pm_runtime_put_sync (hba->dev); +/* +* pm_runtime_get_noresume is called while scheduling +* eeh_work to avoid suspend racing with exception work. +* Hence decrement usage counter using pm_runtime_put_noidle +* to allow suspend on completion of exception event handler. +*/ +pm_runtime_put_noidle (hba->dev); +pm_runtime_put (hba->dev);return ; }
@@ -7901,6 +7915,7 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) goto enable_gating; } +flush_work (&hba->eeh_work); ret =ufshcd_link_state_transition (hba, req_link_state,1 );if (ret) goto set_dev_active;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 2/6 scsi: ufs: set load before setting voltage in regulators
In reply to Can GuoFrom: Asutosh Das <[email protected]>
This sequence change is required to avoid dips in voltage during boot-up.
Apparently, this dip is caused because in the original sequence, the regulators are initialized in lpm mode. And then when the load is set to high, and more current is drawn, than is allowed in lpm, the dip is seen.
--- drivers/scsi/ufs/ufshcd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/scsi/ufs/ufshcd.c +5 -5
@@ -7225,6 +7225,11 @@ static int ufshcd_config_vreg(struct device *dev, name = vreg->name;if (regulator_count_voltages (reg) >0 ) { + uA_load = on ? vreg->max_uA :0 ; + ret =ufshcd_config_vreg_load (dev, vreg, uA_load); +if (ret) + goto out; +if (vreg->min_uV && vreg->max_uV) { min_uV = on ? vreg->min_uV :0 ; ret =regulator_set_voltage (reg, min_uV, vreg->max_uV);
@@ -7235,11 +7240,6 @@ static int ufshcd_config_vreg(struct device *dev, goto out; } } - - uA_load = on ? vreg->max_uA :0 ; - ret =ufshcd_config_vreg_load (dev, vreg, uA_load); -if (ret) - goto out; } out:return ret;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 3/6 scsi: ufs: Remove the check before call setup clock notify vops
In reply to Can GuoThe functionality of vendor specific ops should be handled properly in platform specific driver, but should not count on the UFS driver.
--- drivers/scsi/ufs/ufshcd.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-)
drivers/scsi/ufs/ufshcd.c +6 -20
@@ -7379,16 +7379,9 @@ static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,if (list_empty (head)) goto out; -/* -* vendor specific setup_clocks ops may depend on clocks managed by -* this standard driver hence call the vendor specific setup_clocks -* before disabling the clocks managed here. -*/ -if (!on) { - ret =ufshcd_vops_setup_clocks (hba, on,PRE_CHANGE ); -if (ret) -return ret; - } + ret =ufshcd_vops_setup_clocks (hba, on,PRE_CHANGE ); +if (ret) +return ret;list_for_each_entry (clki, head, list) {if (!IS_ERR_OR_NULL (clki->clk)) {
@@ -7412,16 +7405,9 @@ static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on, } } -/* -* vendor specific setup_clocks ops may depend on clocks managed by -* this standard driver hence call the vendor specific setup_clocks -* after enabling the clocks managed here. -*/ -if (on) { - ret =ufshcd_vops_setup_clocks (hba, on,POST_CHANGE ); -if (ret) -return ret; - } + ret =ufshcd_vops_setup_clocks (hba, on,POST_CHANGE ); +if (ret) +return ret; out:if (ret) {
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 4/6 scsi: ufs-qcom: Adjust bus bandwidth voting and unvoting
In reply to Can GuoThe bus bandwidth voting is required to be done before the bus clocks are enabled, and the unvoting is required to be done only after the bus clocks are disabled.
--- drivers/scsi/ufs/ufs-qcom.c | 57 +++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 18 deletions(-)
drivers/scsi/ufs/ufs-qcom.c +39 -18
@@ -38,7 +38,6 @@ enum {static struct ufs_qcom_host *ufs_qcom_hosts[MAX_UFS_QCOM_HOSTS ]; -static int ufs_qcom_set_bus_vote (struct ufs_qcom_host *host,int vote);static void ufs_qcom_get_default_testbus_cfg (struct ufs_qcom_host *host);static int ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div (struct ufs_hba *hba,u32 clk_cycles);
@@ -674,7 +673,7 @@ static void ufs_qcom_get_speed_mode(struct ufs_pa_layer_attr *p, char *result) } } -static int ufs_qcom_set_bus_vote (struct ufs_qcom_host *host,int vote) +static int __ufs_qcom_set_bus_vote (struct ufs_qcom_host *host,int vote) {int err =0 ;
@@ -705,7 +704,7 @@ static int ufs_qcom_update_bus_bw_vote(struct ufs_qcom_host *host) vote =ufs_qcom_get_bus_vote (host, mode);if (vote >=0 ) - err =ufs_qcom_set_bus_vote (host, vote); + err =__ufs_qcom_set_bus_vote (host, vote);else err = vote;
@@ -716,6 +715,35 @@ static int ufs_qcom_update_bus_bw_vote(struct ufs_qcom_host *host)return err; } +static int ufs_qcom_set_bus_vote (struct ufs_hba *hba,bool on) +{ +struct ufs_qcom_host *host =ufshcd_get_variant (hba); +int vote, err; + +/* +* In case ufs_qcom_init() is not yet done, simply ignore. +* This ufs_qcom_set_bus_vote() shall be called from +* ufs_qcom_init() after init is done. +*/ +if (!host) +return 0 ; + +if (on) { + vote = host->bus_vote.saved_vote; +if (vote == host->bus_vote.min_bw_vote) +ufs_qcom_update_bus_bw_vote (host); + }else { + vote = host->bus_vote.min_bw_vote; + } + + err =__ufs_qcom_set_bus_vote (host, vote); +if (err) +dev_err (hba->dev,"%s: set bus vote failed %d\n" , + __func__, err); + +return err; +} +static ssize_t show_ufs_to_mem_max_bus_bw (struct device *dev,struct device_attribute *attr,char *buf)
@@ -792,7 +820,7 @@ static int ufs_qcom_update_bus_bw_vote(struct ufs_qcom_host *host)return 0 ; } -static int ufs_qcom_set_bus_vote (struct ufs_qcom_host *host,int vote) +static int ufs_qcom_set_bus_vote (struct ufs_hba *host,bool on) {return 0 ; }
@@ -1030,8 +1058,7 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, enum ufs_notify_change_status status) {struct ufs_qcom_host *host =ufshcd_get_variant (hba); -int err; -int vote =0 ; +int err =0 ;/* * In case ufs_qcom_init() is not yet done, simply ignore.
@@ -1041,28 +1068,21 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on,if (!host)return 0 ; -if (on && (status ==POST_CHANGE )) { +if (on && (status ==PRE_CHANGE )) { + err =ufs_qcom_set_bus_vote (hba, true); + }else if (on && (status ==POST_CHANGE )) {/* enable the device ref clock for HS mode*/ if (ufshcd_is_hs_mode (&hba->pwr_info))ufs_qcom_dev_ref_clk_ctrl (host, true); - vote = host->bus_vote.saved_vote; -if (vote == host->bus_vote.min_bw_vote) -ufs_qcom_update_bus_bw_vote (host); - }else if (!on && (status ==PRE_CHANGE )) {if (!ufs_qcom_is_link_active (hba)) {/* disable device ref_clk */ ufs_qcom_dev_ref_clk_ctrl (host, false); } - - vote = host->bus_vote.min_bw_vote; + }else if (!on && (status ==POST_CHANGE )) { + err =ufs_qcom_set_bus_vote (hba, false); } - err =ufs_qcom_set_bus_vote (host, vote); -if (err) -dev_err (hba->dev,"%s: set bus vote failed %d\n" , - __func__, err); -return err; }
@@ -1238,6 +1258,7 @@ static int ufs_qcom_init(struct ufs_hba *hba)ufs_qcom_set_caps (hba);ufs_qcom_advertise_quirks (hba); +ufs_qcom_set_bus_vote (hba, true);ufs_qcom_setup_clocks (hba, true,POST_CHANGE );if (hba->dev->id <MAX_UFS_QCOM_HOSTS )
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 5/6 scsi: ufs: Add dev ref clock gating wait time support
In reply to Can GuoIn UFS version 3.0, a newly added attribute bRefClkGatingWaitTime defines the minimum time for which the reference clock is required by device during transition to LS-MODE or HIBERN8 state. Make this change to reflect the new requirement by adding delays before turning off the clock.
--- drivers/scsi/ufs/ufs.h | 3 +++ drivers/scsi/ufs/ufshcd.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
drivers/scsi/ufs/ufs.h +3 -0
@@ -168,6 +168,7 @@ enum attr_idn {QUERY_ATTR_IDN_FFU_STATUS =0x14 ,QUERY_ATTR_IDN_PSA_STATE =0x15 ,QUERY_ATTR_IDN_PSA_DATA_SIZE =0x16 , + QUERY_ATTR_IDN_REF_CLK_GATING_WAIT_TIME = 0x17, };/* Descriptor idn for Query requests */
@@ -530,6 +531,8 @@ struct ufs_dev_info {bool f_power_on_wp_en;/* Keeps information if any of the LU is power on write protected */ bool is_lu_power_on_wp; +u16 spec_version; +u32 clk_gating_wait_us; };#define MAX_MODEL_LEN 16
drivers/scsi/ufs/ufshcd.c +46 -0
82 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 6/6 scsi: ufs: Fix ufshcd_hold() caused scheduling while atomic
In reply to Can GuoThe async version of ufshcd_hold(async == true), which is only called in queuecommand path as for now, is expected to work in atomic context, thus it should not sleep or schedule out. When it runs into the condition that clocks are ON but link is still in hibern8 state, it should bail out without flushing the clock ungate work.
--- drivers/scsi/ufs/ufshcd.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/scsi/ufs/ufshcd.c +5 -0
@@ -1545,6 +1545,11 @@ int ufshcd_hold(struct ufs_hba *hba, bool async)*/ if (ufshcd_can_hibern8_during_gating (hba) &&ufshcd_is_link_hibern8 (hba)) { +if (async) { + rc = -EAGAIN ; + hba->clk_gating.active_reqs--; +break ; + }spin_unlock_irqrestore (hba->host->host_lock, flags);flush_work (&hba->clk_gating.ungate_work);spin_lock_irqsave (hba->host->host_lock, flags);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project