Commit 3b5f3c0d authored by Yue Hu's avatar Yue Hu Committed by Martin K. Petersen

scsi: ufs: core: Tidy up WB configuration code

There are similar code implementations for WB configuration in
ufshcd_wb_{ctrl, toggle_flush_during_h8, toggle_flush}. Extract the common
parts to create a new helper with a flag parameter to reduce code
duplication.

Meanwhile, rename ufshcd_wb_ctrl() to ufshcd_wb_toggle() for better
readability. And remove unnecessary log messages from ufshcd_wb_config()
since relevant toggle function will emit messages. Also change
ufshcd_wb_toggle_flush{__during_h8} to void type accordingly.

Link: https://lore.kernel.org/r/20210318095536.2048-1-zbestahu@gmail.comReviewed-by: default avatarAvri Altman <avri.altman@wdc.com>
Signed-off-by: default avatarYue Hu <huyue2@yulong.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 69a1709e
...@@ -246,7 +246,7 @@ static ssize_t wb_on_store(struct device *dev, struct device_attribute *attr, ...@@ -246,7 +246,7 @@ static ssize_t wb_on_store(struct device *dev, struct device_attribute *attr,
} }
pm_runtime_get_sync(hba->dev); pm_runtime_get_sync(hba->dev);
res = ufshcd_wb_ctrl(hba, wb_enable); res = ufshcd_wb_toggle(hba, wb_enable);
pm_runtime_put_sync(hba->dev); pm_runtime_put_sync(hba->dev);
out: out:
up(&hba->host_sem); up(&hba->host_sem);
......
...@@ -246,8 +246,8 @@ static int ufshcd_setup_vreg(struct ufs_hba *hba, bool on); ...@@ -246,8 +246,8 @@ static int ufshcd_setup_vreg(struct ufs_hba *hba, bool on);
static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba, static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba,
struct ufs_vreg *vreg); struct ufs_vreg *vreg);
static int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag); static int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag);
static int ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set); static void ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set);
static inline int ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable); static inline void ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable);
static void ufshcd_hba_vreg_set_lpm(struct ufs_hba *hba); static void ufshcd_hba_vreg_set_lpm(struct ufs_hba *hba);
static void ufshcd_hba_vreg_set_hpm(struct ufs_hba *hba); static void ufshcd_hba_vreg_set_hpm(struct ufs_hba *hba);
...@@ -274,20 +274,12 @@ static inline void ufshcd_disable_irq(struct ufs_hba *hba) ...@@ -274,20 +274,12 @@ static inline void ufshcd_disable_irq(struct ufs_hba *hba)
static inline void ufshcd_wb_config(struct ufs_hba *hba) static inline void ufshcd_wb_config(struct ufs_hba *hba)
{ {
int ret;
if (!ufshcd_is_wb_allowed(hba)) if (!ufshcd_is_wb_allowed(hba))
return; return;
ret = ufshcd_wb_ctrl(hba, true); ufshcd_wb_toggle(hba, true);
if (ret)
dev_err(hba->dev, "%s: Enable WB failed: %d\n", __func__, ret); ufshcd_wb_toggle_flush_during_h8(hba, true);
else
dev_info(hba->dev, "%s: Write Booster Configured\n", __func__);
ret = ufshcd_wb_toggle_flush_during_h8(hba, true);
if (ret)
dev_err(hba->dev, "%s: En WB flush during H8: failed: %d\n",
__func__, ret);
if (!(hba->quirks & UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL)) if (!(hba->quirks & UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL))
ufshcd_wb_toggle_flush(hba, true); ufshcd_wb_toggle_flush(hba, true);
} }
...@@ -1267,7 +1259,7 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up) ...@@ -1267,7 +1259,7 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up)
/* Enable Write Booster if we have scaled up else disable it */ /* Enable Write Booster if we have scaled up else disable it */
downgrade_write(&hba->clk_scaling_lock); downgrade_write(&hba->clk_scaling_lock);
is_writelock = false; is_writelock = false;
ufshcd_wb_ctrl(hba, scale_up); ufshcd_wb_toggle(hba, scale_up);
out_unprepare: out_unprepare:
ufshcd_clock_scaling_unprepare(hba, is_writelock); ufshcd_clock_scaling_unprepare(hba, is_writelock);
...@@ -5443,85 +5435,74 @@ static void ufshcd_bkops_exception_event_handler(struct ufs_hba *hba) ...@@ -5443,85 +5435,74 @@ static void ufshcd_bkops_exception_event_handler(struct ufs_hba *hba)
__func__, err); __func__, err);
} }
int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable) static int __ufshcd_wb_toggle(struct ufs_hba *hba, bool set, enum flag_idn idn)
{ {
int ret;
u8 index; u8 index;
enum query_opcode opcode; enum query_opcode opcode = set ? UPIU_QUERY_OPCODE_SET_FLAG :
UPIU_QUERY_OPCODE_CLEAR_FLAG;
index = ufshcd_wb_get_query_index(hba);
return ufshcd_query_flag_retry(hba, opcode, idn, index, NULL);
}
int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable)
{
int ret;
if (!ufshcd_is_wb_allowed(hba)) if (!ufshcd_is_wb_allowed(hba))
return 0; return 0;
if (!(enable ^ hba->dev_info.wb_enabled)) if (!(enable ^ hba->dev_info.wb_enabled))
return 0; return 0;
if (enable)
opcode = UPIU_QUERY_OPCODE_SET_FLAG;
else
opcode = UPIU_QUERY_OPCODE_CLEAR_FLAG;
index = ufshcd_wb_get_query_index(hba); ret = __ufshcd_wb_toggle(hba, enable, QUERY_FLAG_IDN_WB_EN);
ret = ufshcd_query_flag_retry(hba, opcode,
QUERY_FLAG_IDN_WB_EN, index, NULL);
if (ret) { if (ret) {
dev_err(hba->dev, "%s write booster %s failed %d\n", dev_err(hba->dev, "%s Write Booster %s failed %d\n",
__func__, enable ? "enable" : "disable", ret); __func__, enable ? "enable" : "disable", ret);
return ret; return ret;
} }
hba->dev_info.wb_enabled = enable; hba->dev_info.wb_enabled = enable;
dev_dbg(hba->dev, "%s write booster %s %d\n", dev_info(hba->dev, "%s Write Booster %s\n",
__func__, enable ? "enable" : "disable", ret); __func__, enable ? "enabled" : "disabled");
return ret; return ret;
} }
static int ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set) static void ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set)
{ {
int val; int ret;
u8 index;
if (set)
val = UPIU_QUERY_OPCODE_SET_FLAG;
else
val = UPIU_QUERY_OPCODE_CLEAR_FLAG;
index = ufshcd_wb_get_query_index(hba); ret = __ufshcd_wb_toggle(hba, set,
return ufshcd_query_flag_retry(hba, val, QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8);
QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8, if (ret) {
index, NULL); dev_err(hba->dev, "%s: WB-Buf Flush during H8 %s failed: %d\n",
__func__, set ? "enable" : "disable", ret);
return;
}
dev_dbg(hba->dev, "%s WB-Buf Flush during H8 %s\n",
__func__, set ? "enabled" : "disabled");
} }
static inline int ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable) static inline void ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable)
{ {
int ret; int ret;
u8 index;
enum query_opcode opcode;
if (!ufshcd_is_wb_allowed(hba) || if (!ufshcd_is_wb_allowed(hba) ||
hba->dev_info.wb_buf_flush_enabled == enable) hba->dev_info.wb_buf_flush_enabled == enable)
return 0; return;
if (enable)
opcode = UPIU_QUERY_OPCODE_SET_FLAG;
else
opcode = UPIU_QUERY_OPCODE_CLEAR_FLAG;
index = ufshcd_wb_get_query_index(hba); ret = __ufshcd_wb_toggle(hba, enable, QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN);
ret = ufshcd_query_flag_retry(hba, opcode,
QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, index,
NULL);
if (ret) { if (ret) {
dev_err(hba->dev, "%s WB-Buf Flush %s failed %d\n", __func__, dev_err(hba->dev, "%s WB-Buf Flush %s failed %d\n", __func__,
enable ? "enable" : "disable", ret); enable ? "enable" : "disable", ret);
goto out; return;
} }
hba->dev_info.wb_buf_flush_enabled = enable; hba->dev_info.wb_buf_flush_enabled = enable;
dev_dbg(hba->dev, "WB-Buf Flush %s\n", enable ? "enabled" : "disabled"); dev_dbg(hba->dev, "%s WB-Buf Flush %s\n",
out: __func__, enable ? "enabled" : "disabled");
return ret;
} }
static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba, static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,
......
...@@ -1104,7 +1104,7 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, ...@@ -1104,7 +1104,7 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba,
u8 *desc_buff, int *buff_len, u8 *desc_buff, int *buff_len,
enum query_opcode desc_op); enum query_opcode desc_op);
int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable); int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable);
/* Wrapper functions for safely calling variant operations */ /* Wrapper functions for safely calling variant operations */
static inline const char *ufshcd_get_var_name(struct ufs_hba *hba) static inline const char *ufshcd_get_var_name(struct ufs_hba *hba)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment