scsi: ufs: wb: Add sysfs attribute and cleanup
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): CGME20220804074224epcms2p18f0ac2f92073aeed981718a9cab23866@epcms2p1
v7 cover scsi: ufs: wb: Add sysfs attribute and cleanup
This patch series is to clean up UFS's Write Booster code and adds sysfs attribute which can control the specific feature of it.
V2:
- modify commit message
- move & modify err messages
- remove unnesscessary debug messages
V3:
- split patch (functional, non-functional)
V4:
- split patch (The number of patches from 2 to 7)
- modify dev messages
- modify commit message
V5:
- drop (scsi: ufs: wb: Move ufshcd_is_wb_allowed() to callee)
- fix condition check
- add document for sysfs attribute
- move ufshcd_is_wb_buf_flush_allowed() to ufs-priv.h
V6:
- Change the function name from ufshcd_wb_config() to ufshcd_configure_wb()
- modify document description for wb_buf_flush_en attribute
- fix some dev_err messages
V7:
- renaming sysfs attribute name
(wb_buf_flush_en -> enable_wb_buf_flush)
- update document description
- change debug message level (info -> dbg) (5.19/scsi-fixes, https://git.kernel.org/mkp/scsi/c/2ae57c995003)
Jinyoung Choi (6):
scsi: ufs: wb: Change wb_enabled condition test
scsi: ufs: wb: Change functions name and modify parameter name
scsi: ufs: wb: Add explicit flush sysfs attribute
scsi: ufs: wb: Introduce ufshcd_is_wb_buf_flush_allowed() to improve
readability
scsi: ufs: wb: Modify messages
scsi: ufs: wb: Move the comment to the right position
Documentation/ABI/testing/sysfs-driver-ufs | 9 +++ drivers/ufs/core/ufs-sysfs.c | 47 ++++++++++++++- drivers/ufs/core/ufshcd-priv.h | 6 ++ drivers/ufs/core/ufshcd.c | 70 ++++++++++++---------- include/ufs/ufshcd.h | 1 + 5 files changed, 99 insertions(+), 34 deletions(-)
Signature · 1 line
2.25.1
PATCH v7 1/6 scsi: ufs: wb: Change wb_enabled condition test
Changed to improve readability.
As implemented in ufshcd_wb_togle_flush(), the conditional test is modified in the same way.
--- drivers/ufs/core/ufshcd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/ufs/core/ufshcd.c +2 -4
@@ -5730,10 +5730,8 @@ int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable) {int ret; -if (!ufshcd_is_wb_allowed (hba)) -return 0 ; - -if (!(enable ^ hba->dev_info.wb_enabled)) +if (!ufshcd_is_wb_allowed (hba) || + hba->dev_info.wb_enabled == enable)return 0 ; ret =__ufshcd_wb_toggle (hba, enable,QUERY_FLAG_IDN_WB_EN );
Signature · 1 line
2.25.1
PATCH v7 2/6 scsi: ufs: wb: Change functions name and modify parameter name
The parameter name of ufshcd_wb_toggle_flush_during_h8() has been changed in the same as other toggle functions.
Function names were ambiguous. So changed to suit the meaning.
--- drivers/ufs/core/ufshcd.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
drivers/ufs/core/ufshcd.c +17 -13
@@ -265,8 +265,9 @@ static int ufshcd_setup_vreg(struct ufs_hba *hba, bool on);static inline int ufshcd_config_vreg_hpm (struct ufs_hba *hba,struct ufs_vreg *vreg);static int ufshcd_try_to_abort_task (struct ufs_hba *hba,int tag); -static void ufshcd_wb_toggle_flush_during_h8 (struct ufs_hba *hba,bool set); -static inline void ufshcd_wb_toggle_flush (struct ufs_hba *hba,bool enable); +static void ufshcd_wb_toggle_buf_flush_during_h8 (struct ufs_hba *hba, +bool enable); +static void ufshcd_wb_toggle_buf_flush (struct ufs_hba *hba,bool enable);static void ufshcd_hba_vreg_set_lpm (struct ufs_hba *hba);static void ufshcd_hba_vreg_set_hpm (struct ufs_hba *hba);
@@ -286,16 +287,16 @@ static inline void ufshcd_disable_irq(struct ufs_hba *hba) } } -static inline void ufshcd_wb_config (struct ufs_hba *hba) +static void ufshcd_configure_wb (struct ufs_hba *hba) {if (!ufshcd_is_wb_allowed (hba))return ;ufshcd_wb_toggle (hba, true); -ufshcd_wb_toggle_flush_during_h8 (hba, true); +ufshcd_wb_toggle_buf_flush_during_h8 (hba, true);if (!(hba->quirks &UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL )) -ufshcd_wb_toggle_flush (hba, true); +ufshcd_wb_toggle_buf_flush (hba, true); }static void ufshcd_scsi_unblock_requests (struct ufs_hba *hba)
@@ -5748,22 +5749,23 @@ int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable)return ret; } -static void ufshcd_wb_toggle_flush_during_h8 (struct ufs_hba *hba,bool set) +static void ufshcd_wb_toggle_buf_flush_during_h8 (struct ufs_hba *hba, +bool enable) {int ret; - ret =__ufshcd_wb_toggle (hba, set, + ret =__ufshcd_wb_toggle (hba, enable,QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8 );if (ret) {dev_err (hba->dev,"%s: WB-Buf Flush during H8 %s failed: %d\n" , - __func__, set ?"enable" :"disable" , ret); + __func__, enable ?"enable" :"disable" , ret);return ; }dev_dbg (hba->dev,"%s WB-Buf Flush during H8 %s\n" , - __func__, set ?"enabled" :"disabled" ); + __func__, enable ?"enabled" :"disabled" ); } -static inline void ufshcd_wb_toggle_flush (struct ufs_hba *hba,bool enable) +static void ufshcd_wb_toggle_buf_flush (struct ufs_hba *hba,bool enable) {int ret;
@@ -5813,9 +5815,9 @@ static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,static void ufshcd_wb_force_disable (struct ufs_hba *hba) {if (!(hba->quirks &UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL )) -ufshcd_wb_toggle_flush (hba, false); +ufshcd_wb_toggle_buf_flush (hba, false); -ufshcd_wb_toggle_flush_during_h8 (hba, false); +ufshcd_wb_toggle_buf_flush_during_h8 (hba, false);ufshcd_wb_toggle (hba, false); hba->caps &= ~UFSHCD_CAP_WB_EN ;
@@ -8212,7 +8214,9 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)*/ ufshcd_set_active_icc_lvl (hba); -ufshcd_wb_config (hba); +/* Enable UFS Write Booster if supported */ +ufshcd_configure_wb (hba); +if (hba->ee_usr_mask)ufshcd_write_ee_control (hba);/* Enable Auto-Hibernate if configured */
Signature · 1 line
2.25.1
PATCH v7 3/6 scsi: ufs: wb: Add explicit flush sysfs attribute
In reply to Jinyoung CHOIThere is the following quirk to bypass "WB Flush" in Write Booster.
- UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL
If this quirk is not set, there is no knob that can control "WB Flush".
There are three flags that control Write Booster Feature.
1. WB ON/OFF
2. WB Hibern Flush ON/OFF (implicitly)
3. WB Flush ON/OFF (explicit)
The sysfs attribute that controls the WB was implemented. (1)
In the case of "Hibern Flush", it is always good to turn on. Control may not be required. (2)
Finally, "Flush" may be necessary because the Auto-Hibern8 is not supported in a specific environment.
So the sysfs attribute that controls this is necessary. (3)
--- Documentation/ABI/testing/sysfs-driver-ufs | 9 +++++ drivers/ufs/core/ufs-sysfs.c | 46 ++++++++++++++++++++++ drivers/ufs/core/ufshcd.c | 9 +++-- include/ufs/ufshcd.h | 1 + 4 files changed, 61 insertions(+), 4 deletions(-)
Documentation/ABI/testing/sysfs-driver-ufs +9 -0
@@ -1417,6 +1417,15 @@ Description: This node is used to set or display whether UFS WriteBooster is platform that doesn't support UFSHCD_CAP_CLK_SCALING, we can disable/enable WriteBooster through this sysfs node. +What: /sys/bus/platform/drivers/ufshcd/*/enable_wb_buf_flush +What: /sys/bus/platform/devices/*.ufs/enable_wb_buf_flush +Date: July 2022 +Contact: Jinyoung Choi <[email protected]> +Description: This entry shows the status of WriteBooster buffer flushing + and it can be used to enable or disable the flushing. + If flushing is enabled, the device executes the flush + operation when the command queue is empty. + What: /sys/bus/platform/drivers/ufshcd/*/device_descriptor/hpb_version What: /sys/bus/platform/devices/*.ufs/device_descriptor/hpb_version Date: June 2021
drivers/ufs/core/ufs-sysfs.c +46 -0
64 lines not on this page · raw message
drivers/ufs/core/ufshcd.c +5 -4
@@ -267,7 +267,6 @@ static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba,static int ufshcd_try_to_abort_task (struct ufs_hba *hba,int tag);static void ufshcd_wb_toggle_buf_flush_during_h8 (struct ufs_hba *hba,bool enable); -static void ufshcd_wb_toggle_buf_flush (struct ufs_hba *hba,bool enable);static void ufshcd_hba_vreg_set_lpm (struct ufs_hba *hba);static void ufshcd_hba_vreg_set_hpm (struct ufs_hba *hba);
@@ -5765,25 +5764,27 @@ static void ufshcd_wb_toggle_buf_flush_during_h8(struct ufs_hba *hba, __func__, enable ? "enabled" : "disabled"); } -static void ufshcd_wb_toggle_buf_flush (struct ufs_hba *hba,bool enable) +int ufshcd_wb_toggle_buf_flush (struct ufs_hba *hba,bool enable) {int ret;if (!ufshcd_is_wb_allowed (hba) || hba->dev_info.wb_buf_flush_enabled == enable) -return ; +return 0 ; ret =__ufshcd_wb_toggle (hba, enable,QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN );if (ret) {dev_err (hba->dev,"%s WB-Buf Flush %s failed %d\n" , __func__, enable ?"enable" :"disable" , ret); -return ; +return ret; } hba->dev_info.wb_buf_flush_enabled = enable;dev_dbg (hba->dev,"%s WB-Buf Flush %s\n" , __func__, enable ?"enabled" :"disabled" ); + +return ret; } static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,
include/ufs/ufshcd.h +1 -0
@@ -1211,6 +1211,7 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, enum query_opcode desc_op);int ufshcd_wb_toggle (struct ufs_hba *hba,bool enable); +int ufshcd_wb_toggle_buf_flush (struct ufs_hba *hba,bool enable);int ufshcd_suspend_prepare (struct device *dev);int __ufshcd_suspend_prepare (struct device *dev,bool rpm_ok_for_spm);void ufshcd_resume_complete (struct device *dev);
Signature · 1 line
2.25.1
PATCH v7 4/6 scsi: ufs: wb: Introduce ufshcd_is_wb_buf_flush_allowed() to improve readability
In reply to Jinyoung CHOIThe explicit flushing should check the following.
- UFSHCD_CAP_WB_EN
- UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL
Changed to improve readability.
--- drivers/ufs/core/ufs-sysfs.c | 3 +-- drivers/ufs/core/ufshcd-priv.h | 6 ++++++ drivers/ufs/core/ufshcd.c | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-)
drivers/ufs/core/ufs-sysfs.c +1 -2
@@ -271,8 +271,7 @@ static ssize_t enable_wb_buf_flush_store(struct device *dev,unsigned int enable_wb_buf_flush;ssize_t res; -if (!ufshcd_is_wb_allowed (hba) || - (hba->quirks &UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL )) { +if (!ufshcd_is_wb_buf_flush_allowed (hba)) {dev_warn (dev,"It is not allowed to configure WB buf flushing!\n" );return -EOPNOTSUPP ; }
drivers/ufs/core/ufshcd-priv.h +6 -0
@@ -26,6 +26,12 @@ static inline u8 ufshcd_wb_get_query_index(struct ufs_hba *hba)return 0 ; } +static inline bool ufshcd_is_wb_buf_flush_allowed (struct ufs_hba *hba) +{ +return ufshcd_is_wb_allowed (hba) && + !(hba->quirks &UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL ); +} +#ifdef CONFIG_SCSI_UFS_HWMON void ufs_hwmon_probe (struct ufs_hba *hba,u8 mask);void ufs_hwmon_remove (struct ufs_hba *hba);
drivers/ufs/core/ufshcd.c +3 -2
@@ -294,7 +294,8 @@ static void ufshcd_configure_wb(struct ufs_hba *hba)ufshcd_wb_toggle (hba, true);ufshcd_wb_toggle_buf_flush_during_h8 (hba, true); -if (!(hba->quirks &UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL )) + +if (ufshcd_is_wb_buf_flush_allowed (hba))ufshcd_wb_toggle_buf_flush (hba, true); }
@@ -5815,7 +5816,7 @@ static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,static void ufshcd_wb_force_disable (struct ufs_hba *hba) { -if (!(hba->quirks &UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL )) +if (ufshcd_is_wb_buf_flush_allowed (hba))ufshcd_wb_toggle_buf_flush (hba, false);ufshcd_wb_toggle_buf_flush_during_h8 (hba, false);
Signature · 1 line
2.25.1
PATCH v7 5/6 scsi: ufs: wb: Modify messages
In reply to Jinyoung CHOIMessages are modified to fit the format of others.
--- drivers/ufs/core/ufs-sysfs.c | 2 +- drivers/ufs/core/ufshcd.c | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-)
drivers/ufs/core/ufs-sysfs.c +1 -1
@@ -230,7 +230,7 @@ static ssize_t wb_on_store(struct device *dev, struct device_attribute *attr,* If the platform supports UFSHCD_CAP_CLK_SCALING, turn WB * on/off will be done while clock scaling up/down. */ -dev_warn (dev,"To control WB through wb_on is not allowed!\n" ); +dev_warn (dev,"It is not allowed to configure WB!\n" );return -EOPNOTSUPP ; }
drivers/ufs/core/ufshcd.c +11 -12
@@ -5737,13 +5737,13 @@ int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable) ret =__ufshcd_wb_toggle (hba, enable,QUERY_FLAG_IDN_WB_EN );if (ret) { -dev_err (hba->dev,"%s Write Booster %s failed %d\n" , - __func__, enable ?"enable" :"disable" , ret); +dev_err (hba->dev,"%s: Write Booster %s failed %d\n" , + __func__, enable ?"enabling" :"disabling" , ret);return ret; } hba->dev_info.wb_enabled = enable; -dev_info (hba->dev,"%s Write Booster %s\n" , +dev_dbg (hba->dev,"%s: Write Booster %s\n" , __func__, enable ?"enabled" :"disabled" );return ret;
@@ -5757,11 +5757,11 @@ static void ufshcd_wb_toggle_buf_flush_during_h8(struct ufs_hba *hba, ret =__ufshcd_wb_toggle (hba, enable,QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8 );if (ret) { -dev_err (hba->dev,"%s: WB-Buf Flush during H8 %s failed: %d\n" , - __func__, enable ?"enable" :"disable" , ret); +dev_err (hba->dev,"%s: WB-Buf Flush during H8 %s failed %d\n" , + __func__, enable ?"enabling" :"disabling" , ret);return ; } -dev_dbg (hba->dev,"%s WB-Buf Flush during H8 %s\n" , +dev_dbg (hba->dev,"%s: WB-Buf Flush during H8 %s\n" , __func__, enable ?"enabled" :"disabled" ); }
@@ -5775,14 +5775,13 @@ int ufshcd_wb_toggle_buf_flush(struct ufs_hba *hba, bool enable) ret =__ufshcd_wb_toggle (hba, enable,QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN );if (ret) { -dev_err (hba->dev,"%s WB-Buf Flush %s failed %d\n" , __func__, - enable ?"enable" :"disable" , ret); +dev_err (hba->dev,"%s: WB-Buf Flush %s failed %d\n" , + __func__, enable ?"enabling" :"disabling" , ret);return ret; } hba->dev_info.wb_buf_flush_enabled = enable; - -dev_dbg (hba->dev,"%s WB-Buf Flush %s\n" , +dev_dbg (hba->dev,"%s: WB-Buf Flush %s\n" , __func__, enable ?"enabled" :"disabled" );return ret;
@@ -5800,7 +5799,7 @@ static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE , index, 0, &cur_buf);if (ret) { -dev_err (hba->dev,"%s dCurWriteBoosterBufferSize read failed %d\n" , +dev_err (hba->dev,"%s: dCurWriteBoosterBufferSize read failed %d\n" , __func__, ret);return false; }
@@ -5885,7 +5884,7 @@ static bool ufshcd_wb_need_flush(struct ufs_hba *hba)QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE , index, 0, &avail_buf);if (ret) { -dev_warn (hba->dev,"%s dAvailableWriteBoosterBufferSize read failed %d\n" , +dev_warn (hba->dev,"%s: dAvailableWriteBoosterBufferSize read failed %d\n" , __func__, ret);return false; }
Signature · 1 line
2.25.1
PATCH v7 6/6 scsi: ufs: wb: Move the comment to the right position
In reply to Jinyoung CHOIThe location of the comment is wrong. so fix it.
--- drivers/ufs/core/ufshcd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +2 -1
@@ -1298,9 +1298,10 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up) } } -/* Enable Write Booster if we have scaled up else disable it */ downgrade_write (&hba->clk_scaling_lock); is_writelock = false; + +/* Enable Write Booster if we have scaled up else disable it */ ufshcd_wb_toggle (hba, scale_up); out_unprepare:
Signature · 1 line
2.25.1
Martin K. Petersen
AppliedJinyoung,
Quoted 2 lines
This patch series is to clean up UFS's Write Booster code and adds sysfs attribute which can control the specific feature of it.
Applied to 6.1/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering