scsi: ufs: Fix WriteBooster and cleanup UFS driver
Subsystems (2)
v3 cover scsi: ufs: Fix WriteBooster and cleanup UFS driver
Hi,
This patch set fixes some WriteBooster issues and do small cleanup in UFS driver
v2 -> v3
- Introduce patch [5] to fix possible VCC power drain during runtime suspend (Asutosh)
v1 -> v2
- Remove dummy new line in patch [4] (Asutosh)
- Add more limitation to allow WriteBooster flush during Hibern8 in runtime-suspend. Now the device power mode is kept as Active power mode only if link is put in Hibern8 or Auto-Hibern8 is enabled during runtime-suspend (Asutosh)
Stanley Chu (5):
scsi: ufs: Remove unnecessary memset for dev_info
scsi: ufs: Allow WriteBooster on UFS 2.2 devices
scsi: ufs: Fix index of attributes query for WriteBooster feature
scsi: ufs: Fix WriteBooster flush during runtime suspend
scsi: ufs: Fix possible VCC power drain during runtime suspend
drivers/scsi/ufs/ufs-sysfs.c | 13 ++++- drivers/scsi/ufs/ufs.h | 2 +- drivers/scsi/ufs/ufshcd.c | 99 +++++++++++++++++++++++++----------- drivers/scsi/ufs/ufshcd.h | 3 +- 4 files changed, 82 insertions(+), 35 deletions(-)
Signature · 1 line
2.18.0
PATCH v3 1/5 scsi: ufs: Remove unnecessary memset for dev_info
The whole UFS host instance has been zero-initialized by scsi_host_alloc(), thus UFS driver does not need to clear "dev_info" member specifically in ufshcd_device_params_init().
Simply remove the unnecessary code.
--- drivers/scsi/ufs/ufshcd.c | 3 --- 1 file changed, 3 deletions(-)
drivers/scsi/ufs/ufshcd.c +0 -3
@@ -7262,9 +7262,6 @@ static int ufshcd_device_params_init(struct ufs_hba *hba)bool flag;int ret; -/* Clear any previous UFS device information */ -memset (&hba->dev_info,0 ,sizeof (hba->dev_info)); -/* Init check for device descriptor sizes */ ufshcd_init_desc_sizes (hba);
Signature · 1 line
2.18.0
RE: [PATCH v3 1/5] scsi: ufs: Remove unnecessary memset for dev_info
Quoted 9 lines
The whole UFS host instance has been zero-initialized by
scsi_host_alloc(), thus UFS driver does not need to clear "dev_info" member specifically inufshcd_device_params_init().Simply remove the unnecessary code.
Signed-off-by Stanley Chu <[email protected]>
PATCH v3 2/5 scsi: ufs: Allow WriteBooster on UFS 2.2 devices
In reply to Stanley ChuAccording to the UFS specification, WriteBooster is officially supported by UFS 2.2.
Since UFS 2.2 specification has been finalized in JEDEC and such devices have also showed up in the market, modify the checking rule for ufshcd_wb_probe() to allow these devices to enable WriteBooster.
--- drivers/scsi/ufs/ufshcd.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/ufs/ufshcd.c +1 -0
@@ -6925,6 +6925,7 @@ static int ufs_get_device_desc(struct ufs_hba *hba)* UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES enabled */ if (dev_info->wspecversion >=0x310 || + dev_info->wspecversion ==0x220 || (hba->dev_quirks &UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES ))ufshcd_wb_probe (hba, desc_buf);
Signature · 1 line
2.18.0
RE: [PATCH v3 2/5] scsi: ufs: Allow WriteBooster on UFS 2.2 devices
Quoted 11 lines
According to the UFS specification, WriteBooster is officially supported by UFS 2.2.
Since UFS 2.2 specification has been finalized in JEDEC and such devices have also showed up in the market, modify the checking rule for
ufshcd_wb_probe()to allow these devices to enable WriteBooster.Signed-off-by Stanley Chu <[email protected]>
PATCH v3 3/5 scsi: ufs: Fix index of attributes query for WriteBooster feature
In reply to Stanley ChuFor WriteBooster feature related attributes, the index used by query shall be LUN ID if LU Dedicated buffer mode is enabled.
--- drivers/scsi/ufs/ufs-sysfs.c | 13 +++++++++++-- drivers/scsi/ufs/ufshcd.c | 16 ++++++++++------ drivers/scsi/ufs/ufshcd.h | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-)
drivers/scsi/ufs/ufs-sysfs.c +11 -2
@@ -637,7 +637,7 @@ static ssize_t _name##_show(struct device *dev, \int ret; \struct ufs_hba *hba =dev_get_drvdata (dev); \ if (ufshcd_is_wb_flags(QUERY_FLAG_IDN##_uname)) \ - index =ufshcd_wb_get_flag_index (hba); \ + index =ufshcd_wb_get_query_index (hba); \pm_runtime_get_sync (hba->dev); \ ret =ufshcd_query_flag (hba,UPIU_QUERY_OPCODE_READ_FLAG , \ QUERY_FLAG_IDN##_uname, index, &flag); \
@@ -680,6 +680,12 @@ static const struct attribute_group ufs_sysfs_flags_group = { .attrs = ufs_sysfs_device_flags, }; +static inline bool ufshcd_is_wb_attrs (enum attr_idn idn) +{ +return ((idn >=QUERY_ATTR_IDN_WB_FLUSH_STATUS ) && + (idn <=QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE )); +} +#define UFS_ATTRIBUTE (_name, _uname) \ static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \
@@ -687,9 +693,12 @@ static ssize_t _name##_show(struct device *dev, \struct ufs_hba *hba =dev_get_drvdata (dev); \u32 value; \int ret; \ +u8 index =0 ; \ + if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN##_uname)) \ + index =ufshcd_wb_get_query_index (hba); \pm_runtime_get_sync (hba->dev); \ ret =ufshcd_query_attr (hba,UPIU_QUERY_OPCODE_READ_ATTR , \ - QUERY_ATTR_IDN##_uname, 0, 0, &value); \ + QUERY_ATTR_IDN##_uname, index, 0, &value); \pm_runtime_put_sync (hba->dev); \if (ret) \return -EINVAL ; \
drivers/scsi/ufs/ufshcd.c +10 -6
@@ -5195,7 +5195,7 @@ static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable)else opcode =UPIU_QUERY_OPCODE_CLEAR_FLAG ; - index =ufshcd_wb_get_flag_index (hba); + index =ufshcd_wb_get_query_index (hba); ret =ufshcd_query_flag_retry (hba, opcode,QUERY_FLAG_IDN_WB_EN , index,NULL );if (ret) {
@@ -5221,7 +5221,7 @@ static int ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set)else val =UPIU_QUERY_OPCODE_CLEAR_FLAG ; - index =ufshcd_wb_get_flag_index (hba); + index =ufshcd_wb_get_query_index (hba);return ufshcd_query_flag_retry (hba, val,QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8 , index,NULL );
@@ -5244,7 +5244,7 @@ static int ufshcd_wb_buf_flush_enable(struct ufs_hba *hba)if (!ufshcd_is_wb_allowed (hba) || hba->wb_buf_flush_enabled)return 0 ; - index =ufshcd_wb_get_flag_index (hba); + index =ufshcd_wb_get_query_index (hba); ret =ufshcd_query_flag_retry (hba,UPIU_QUERY_OPCODE_SET_FLAG ,QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN , index,NULL );
@@ -5266,7 +5266,7 @@ static int ufshcd_wb_buf_flush_disable(struct ufs_hba *hba)if (!ufshcd_is_wb_allowed (hba) || !hba->wb_buf_flush_enabled)return 0 ; - index =ufshcd_wb_get_flag_index (hba); + index =ufshcd_wb_get_query_index (hba); ret =ufshcd_query_flag_retry (hba,UPIU_QUERY_OPCODE_CLEAR_FLAG ,QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN , index,NULL );
@@ -5286,10 +5286,12 @@ static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba, {u32 cur_buf;int ret; +u8 index; + index =ufshcd_wb_get_query_index (hba); ret =ufshcd_query_attr_retry (hba,UPIU_QUERY_OPCODE_READ_ATTR ,QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE , -0 ,0 , &cur_buf); + index,0 , &cur_buf);if (ret) {dev_err (hba->dev,"%s dCurWriteBoosterBufferSize read failed %d\n" , __func__, ret);
@@ -5312,6 +5314,7 @@ static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba) {int ret;u32 avail_buf; +u8 index;if (!ufshcd_is_wb_allowed (hba))return false;
@@ -5326,9 +5329,10 @@ static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba)* buffer (dCurrentWriteBoosterBufferSize). There's no point in * keeping vcc on when current buffer is empty. */ + index =ufshcd_wb_get_query_index (hba); ret =ufshcd_query_attr_retry (hba,UPIU_QUERY_OPCODE_READ_ATTR ,QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE , -0 ,0 , &avail_buf); + index,0 , &avail_buf);if (ret) {dev_warn (hba->dev,"%s dAvailableWriteBoosterBufferSize read failed %d\n" , __func__, ret);
drivers/scsi/ufs/ufshcd.h +1 -1
@@ -868,7 +868,7 @@ static inline bool ufshcd_keep_autobkops_enabled_except_suspend(return hba->caps &UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND ; } -static inline u8 ufshcd_wb_get_flag_index (struct ufs_hba *hba) +static inline u8 ufshcd_wb_get_query_index (struct ufs_hba *hba) {if (hba->dev_info.b_wb_buffer_type ==WB_BUF_MODE_LU_DEDICATED )return hba->dev_info.wb_dedicated_lu;
Signature · 1 line
2.18.0
RE: [PATCH v3 3/5] scsi: ufs: Fix index of attributes query for WriteBooster feature
Quoted 6 lines
For WriteBooster feature related attributes, the index used by query shall be LUN ID if LU Dedicated buffer mode is enabled.
Signed-off-by Stanley Chu <[email protected]>
PATCH v3 4/5 scsi: ufs: Fix WriteBooster flush during runtime suspend
In reply to Stanley ChuCurrently UFS host driver promises VCC supply if UFS device needs to do WriteBooster flush during runtime suspend.
However the UFS specification mentions,
"While the flushing operation is in progress, the device is in Active power mode."
Therefore UFS host driver needs to promise more: Keep UFS device as "Active power mode", otherwise UFS device shall not do any flush if device enters Sleep or PowerDown power mode.
Fix this by not changing device power mode if WriteBooster flush is required in ufshcd_suspend().
--- drivers/scsi/ufs/ufs.h | 1 - drivers/scsi/ufs/ufshcd.c | 42 ++++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 21 deletions(-)
drivers/scsi/ufs/ufs.h +0 -1
@@ -574,7 +574,6 @@ struct ufs_dev_info {u32 d_ext_ufs_feature_sup;u8 b_wb_buffer_type;u32 d_wb_alloc_units; -bool keep_vcc_on;u8 b_presrv_uspc_en; };
drivers/scsi/ufs/ufshcd.c +22 -20
63 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v3 5/5 scsi: ufs: Fix possible VCC power drain during runtime suspend
In reply to Stanley ChuThe commit "scsi: ufs: Fix WriteBooster flush during runtime suspend" promises essential resource, i.e., for UFS devices doing WriteBooster buffer flush and Auto BKOPs. However if device finishes its job but not resumed for a very long time, system will have unnecessary power drain because VCC is still supplied.
To fix this, a method to recheck the threshold of keeping VCC supply is required. However, the threshold recheck needs to re-activate the link because the decision depends on the device status.
Introduce a delayed work to force runtime resume after a certain delay during runtime suspend. This makes threshold recheck simpler which will be done in the next runtime-suspend.
--- drivers/scsi/ufs/ufs.h | 1 + drivers/scsi/ufs/ufshcd.c | 43 ++++++++++++++++++++++++++++++++++----- drivers/scsi/ufs/ufshcd.h | 1 + 3 files changed, 40 insertions(+), 5 deletions(-)
drivers/scsi/ufs/ufs.h +1 -0
@@ -574,6 +574,7 @@ struct ufs_dev_info {u32 d_ext_ufs_feature_sup;u8 b_wb_buffer_type;u32 d_wb_alloc_units; +bool b_rpm_dev_flush_capable;u8 b_presrv_uspc_en; };
drivers/scsi/ufs/ufshcd.c +38 -5
103 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +1 -0
@@ -745,6 +745,7 @@ struct ufs_hba {struct request_queue *bsg_queue;bool wb_buf_flush_enabled;bool wb_enabled; +struct delayed_work rpm_dev_flush_recheck_work; };/* Returns true if clocks can be gated. Otherwise false */
Signature · 5 lines
2.18.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v3 5/5] scsi: ufs: Fix possible VCC power drain during runtime suspend
Hi Stanley,
Quoted 11 lines · Stanley Chu
The commit "scsi: ufs: Fix WriteBooster flush during runtime suspend" promises essential resource, i.e., for UFS devices doing WriteBooster buffer flush and Auto BKOPs. However if device finishes its job but not resumed for a very long time, system will have unnecessary power drain because VCC is still supplied.
To fix this, a method to recheck the threshold of keeping VCC supply is required. However, the threshold recheck needs to re-activate the link because the decision depends on the device status.
Quoted 6 lines
Introduce a delayed work to force runtime resume after a certain delay during runtime suspend. This makes threshold recheck simpler which will be done in the next runtime-suspend.
Signed-off-by Stanley Chu <[email protected]>---
Is there a reason to have this code as a separate patch?
[1] Commit: "scsi: ufs: Fix WriteBooster flush during runtime suspend" introduces 'keep_curr_dev_pwr_mode' and the very next change (this one) removes it. Do you think this change and [1] should be merged?
Quoted 98 lines
drivers/scsi/ufs/ufs.h | 1 + drivers/scsi/ufs/ufshcd.c | 43 ++++++++++++++++++++++++++++++++++----- drivers/scsi/ufs/ufshcd.h | 1 + 3 files changed, 40 insertions(+), 5 deletions(-)drivers/scsi/ufs/ufs.h +1
-0@@ -574,6 +574,7 @@ struct ufs_dev_info {u32 d_ext_ufs_feature_sup;u8 b_wb_buffer_type;u32 d_wb_alloc_units; +bool b_rpm_dev_flush_capable;u8 b_presrv_uspc_en; };drivers/scsi/ufs/ufshcd.c +23
-5@@ -94,6 +94,9 @@/* default delay of autosuspend: 2000 ms */ #define RPM_AUTOSUSPEND_DELAY_MS 2000 +/* Default delay of RPM device flush delayed work */ +#define RPM_DEV_FLUSH_RECHECK_WORK_DELAY_MS 5000 +/* Default value of wait time before gating device ref clock */ #define UFSHCD_REF_CLK_GATING_WAIT_US 0xFF/* microsecs */ @@ -5310,7 +5313,7 @@ static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,return false; } -static bool ufshcd_wb_keep_vcc_on (struct ufs_hba *hba) +static bool ufshcd_wb_need_flush (struct ufs_hba *hba) {int ret;u32 avail_buf;@@ -5348,6 +5351,21 @@ static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba)return ufshcd_wb_presrv_usrspc_keep_vcc_on (hba, avail_buf); } +static void ufshcd_rpm_dev_flush_recheck_work (struct work_struct *work) +{ +struct ufs_hba *hba =container_of (to_delayed_work (work), + struct ufs_hba, + rpm_dev_flush_recheck_work); +/* +* To prevent unnecessary VCC power drain after device finishes +* WriteBooster buffer flush or Auto BKOPs, force runtime resume +* after a certain delay to recheck the threshold by next runtime +* supsend. +*/ +pm_runtime_get_sync (hba->dev); +pm_runtime_put_sync (hba->dev); +} +/** * ufshcd_exception_event_handler - handle exceptions raised by device * @work: pointer to work data @@ -8164,7 +8182,6 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)enum ufs_pm_level pm_lvl;enum ufs_dev_pwr_mode req_dev_pwr_mode;enum uic_link_state req_link_state; -bool keep_curr_dev_pwr_mode = false; hba->pm_op_in_progress =1 ;if (!ufshcd_is_shutdown_pm (pm_op)) {@@ -8224,11 +8241,12 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)* Hibern8, keep device power mode as "active power mode" * and VCC supply. */ - keep_curr_dev_pwr_mode = hba->auto_bkops_enabled || + hba->dev_info.b_rpm_dev_flush_capable = + hba->auto_bkops_enabled || (((req_link_state ==UIC_LINK_HIBERN8_STATE ) || ((req_link_state ==UIC_LINK_ACTIVE_STATE ) &&ufshcd_is_auto_hibern8_enabled (hba))) && -ufshcd_wb_keep_vcc_on (hba)); +ufshcd_wb_need_flush (hba)); }if (req_dev_pwr_mode != hba->curr_dev_pwr_mode) {@@ -8238,7 +8256,7 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)ufshcd_disable_auto_bkops (hba); } -if (!keep_curr_dev_pwr_mode) { +if (!hba->dev_info.b_rpm_dev_flush_capable) { ret =ufshcd_set_dev_pwr_mode (hba, req_dev_pwr_mode);if (ret) goto enable_gating;@@ -8295,9 +8313,16 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)if (hba->clk_scaling.is_allowed)ufshcd_resume_clkscaling (hba); hba->clk_gating.is_suspended = false;
drivers/scsi/ufs/ufshcd.c static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) · line 8325
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +7
-0+ hba->dev_info.b_rpm_dev_flush_capable = false;ufshcd_release (hba); out: +if (hba->dev_info.b_rpm_dev_flush_capable) { +schedule_delayed_work (&hba->rpm_dev_flush_recheck_work, +msecs_to_jiffies (RPM_DEV_FLUSH_RECHECK_WORK_DELAY_MS )); + } + hba->pm_op_in_progress =0 ; +
Nitpick; newline, perhaps?
Quoted 38 lines
drivers/scsi/ufs/ufshcd.c +8
-0if (ret)ufshcd_update_reg_hist (&hba->ufs_stats.suspend_err, (u32 )ret);return ret;@@ -8386,6 +8411,11 @@ static int ufshcd_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)/* Enable Auto-Hibernate if configured */ ufshcd_auto_hibern8_enable (hba); +if (hba->dev_info.b_rpm_dev_flush_capable) { + hba->dev_info.b_rpm_dev_flush_capable = false; +cancel_delayed_work (&hba->rpm_dev_flush_recheck_work); + } +/* Schedule clock gating in case of no access to UFS device yet */ ufshcd_release (hba);@@ -8859,6 +8889,9 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)UFS_SLEEP_PWR_MODE , UIC_LINK_HIBERN8_STATE); +INIT_DELAYED_WORK (&hba->rpm_dev_flush_recheck_work, + ufshcd_rpm_dev_flush_recheck_work); +/* Set the default auto-hiberate idle timer value to 150 ms */ if (ufshcd_is_auto_hibern8_supported (hba) && !hba->ahit) { hba->ahit = FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK, 150) |drivers/scsi/ufs/ufshcd.h +1
-0@@ -745,6 +745,7 @@ struct ufs_hba {struct request_queue *bsg_queue;bool wb_buf_flush_enabled;bool wb_enabled; +struct delayed_work rpm_dev_flush_recheck_work; };/* Returns true if clocks can be gated. Otherwise false */
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, Linux Foundation Collaborative Project
Re: [PATCH v3 5/5] scsi: ufs: Fix possible VCC power drain during runtime suspend
Hi, Asutosh,
Thanks for your review.
Quoted 18 lines · Asutosh Das (asd)
Hi Stanley,
Quoted 15 lines · Stanley Chu
The commit "scsi: ufs: Fix WriteBooster flush during runtime suspend" promises essential resource, i.e., for UFS devices doing WriteBooster buffer flush and Auto BKOPs. However if device finishes its job but not resumed for a very long time, system will have unnecessary power drain because VCC is still supplied.
To fix this, a method to recheck the threshold of keeping VCC supply is required. However, the threshold recheck needs to re-activate the link because the decision depends on the device status.
Introduce a delayed work to force runtime resume after a certain delay during runtime suspend. This makes threshold recheck simpler which will be done in the next runtime-suspend.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Stanley Chu <[email protected]>---
Is there a reason to have this code as a separate patch?
[1] Commit: "scsi: ufs: Fix WriteBooster flush during runtime suspend" introduces 'keep_curr_dev_pwr_mode' and the very next change (this one) removes it.
Do you think this change and [1] should be merged?
Yes, these 2 patches shall be merged. I will do it in next version.
Quoted 102 lines
Quoted 102 lines
drivers/scsi/ufs/ufs.h | 1 + drivers/scsi/ufs/ufshcd.c | 43 ++++++++++++++++++++++++++++++++++----- drivers/scsi/ufs/ufshcd.h | 1 + 3 files changed, 40 insertions(+), 5 deletions(-)drivers/scsi/ufs/ufs.h +1
-0@@ -574,6 +574,7 @@ struct ufs_dev_info {u32 d_ext_ufs_feature_sup;u8 b_wb_buffer_type;u32 d_wb_alloc_units; +bool b_rpm_dev_flush_capable;u8 b_presrv_uspc_en; };drivers/scsi/ufs/ufshcd.c +24
-5@@ -94,6 +94,9 @@/* default delay of autosuspend: 2000 ms */ #define RPM_AUTOSUSPEND_DELAY_MS 2000 +/* Default delay of RPM device flush delayed work */ +#define RPM_DEV_FLUSH_RECHECK_WORK_DELAY_MS 5000 +/* Default value of wait time before gating device ref clock */ #define UFSHCD_REF_CLK_GATING_WAIT_US 0xFF/* microsecs */ @@ -5310,7 +5313,7 @@ static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,return false; } -static bool ufshcd_wb_keep_vcc_on (struct ufs_hba *hba) +static bool ufshcd_wb_need_flush (struct ufs_hba *hba) {int ret;u32 avail_buf;@@ -5348,6 +5351,21 @@ static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba)return ufshcd_wb_presrv_usrspc_keep_vcc_on (hba, avail_buf); } +static void ufshcd_rpm_dev_flush_recheck_work (struct work_struct *work) +{ +struct ufs_hba *hba =container_of (to_delayed_work (work), + struct ufs_hba, + rpm_dev_flush_recheck_work); +/* +* To prevent unnecessary VCC power drain after device finishes +* WriteBooster buffer flush or Auto BKOPs, force runtime resume +* after a certain delay to recheck the threshold by next runtime +* supsend. +*/ +pm_runtime_get_sync (hba->dev); +pm_runtime_put_sync (hba->dev); +} +/** * ufshcd_exception_event_handler - handle exceptions raised by device * @work: pointer to work data @@ -8164,7 +8182,6 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)enum ufs_pm_level pm_lvl;enum ufs_dev_pwr_mode req_dev_pwr_mode;enum uic_link_state req_link_state; -bool keep_curr_dev_pwr_mode = false; hba->pm_op_in_progress =1 ;if (!ufshcd_is_shutdown_pm (pm_op)) {@@ -8224,11 +8241,12 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)* Hibern8, keep device power mode as "active power mode" * and VCC supply. */ - keep_curr_dev_pwr_mode = hba->auto_bkops_enabled || + hba->dev_info.b_rpm_dev_flush_capable = + hba->auto_bkops_enabled || (((req_link_state ==UIC_LINK_HIBERN8_STATE ) || ((req_link_state ==UIC_LINK_ACTIVE_STATE ) &&ufshcd_is_auto_hibern8_enabled (hba))) && -ufshcd_wb_keep_vcc_on (hba)); +ufshcd_wb_need_flush (hba)); }if (req_dev_pwr_mode != hba->curr_dev_pwr_mode) {@@ -8238,7 +8256,7 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)ufshcd_disable_auto_bkops (hba); } -if (!keep_curr_dev_pwr_mode) { +if (!hba->dev_info.b_rpm_dev_flush_capable) { ret =ufshcd_set_dev_pwr_mode (hba, req_dev_pwr_mode);if (ret) goto enable_gating;@@ -8295,9 +8313,16 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)if (hba->clk_scaling.is_allowed)ufshcd_resume_clkscaling (hba); hba->clk_gating.is_suspended = false; + hba->dev_info.b_rpm_dev_flush_capable = false;ufshcd_release (hba); out:
Quoted 8 lines
drivers/scsi/ufs/ufshcd.c static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) · line 8325
Quoted 7 lines
drivers/scsi/ufs/ufshcd.c +6
-0+if (hba->dev_info.b_rpm_dev_flush_capable) { +schedule_delayed_work (&hba->rpm_dev_flush_recheck_work, +msecs_to_jiffies (RPM_DEV_FLUSH_RECHECK_WORK_DELAY_MS )); + } + hba->pm_op_in_progress =0 ; +Nitpick; newline, perhaps?
Thanks, I Will remove it.
Quoted 37 lines
Quoted 37 lines
drivers/scsi/ufs/ufshcd.c +8
-0if (ret)ufshcd_update_reg_hist (&hba->ufs_stats.suspend_err, (u32 )ret);return ret;@@ -8386,6 +8411,11 @@ static int ufshcd_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)/* Enable Auto-Hibernate if configured */ ufshcd_auto_hibern8_enable (hba); +if (hba->dev_info.b_rpm_dev_flush_capable) { + hba->dev_info.b_rpm_dev_flush_capable = false; +cancel_delayed_work (&hba->rpm_dev_flush_recheck_work); + } +/* Schedule clock gating in case of no access to UFS device yet */ ufshcd_release (hba);@@ -8859,6 +8889,9 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)UFS_SLEEP_PWR_MODE , UIC_LINK_HIBERN8_STATE); +INIT_DELAYED_WORK (&hba->rpm_dev_flush_recheck_work, + ufshcd_rpm_dev_flush_recheck_work); +/* Set the default auto-hiberate idle timer value to 150 ms */ if (ufshcd_is_auto_hibern8_supported (hba) && !hba->ahit) { hba->ahit = FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK, 150) |drivers/scsi/ufs/ufshcd.h +1
-0@@ -745,6 +745,7 @@ struct ufs_hba {struct request_queue *bsg_queue;bool wb_buf_flush_enabled;bool wb_enabled; +struct delayed_work rpm_dev_flush_recheck_work; };
Quoted 4 lines
drivers/scsi/ufs/ufshcd.h struct ufs_hba { · line 751
Quoted 2 lines
drivers/scsi/ufs/ufshcd.h +0
-0/* Returns true if clocks can be gated. Otherwise false */
Thanks,
Stanley Chu