mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-07 20:33:58 -04:00
Merge "scsi: ufs: Enable WriteBooster"
This commit is contained in:
commit
dfc8288102
5 changed files with 398 additions and 6 deletions
|
|
@ -1604,6 +1604,9 @@ static void ufs_qcom_set_caps(struct ufs_hba *hba)
|
|||
UFSHCD_CAP_HIBERN8_WITH_CLK_GATING |
|
||||
UFSHCD_CAP_CLK_SCALING | UFSHCD_CAP_AUTO_BKOPS_SUSPEND |
|
||||
UFSHCD_CAP_RPM_AUTOSUSPEND;
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
hba->caps |= UFSHCD_CAP_WB_EN;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (host->hw_ver.major >= 0x2) {
|
||||
|
|
|
|||
|
|
@ -277,6 +277,12 @@ UFS_DEVICE_DESC_PARAM(device_version, _DEV_VER, 2);
|
|||
UFS_DEVICE_DESC_PARAM(number_of_secure_wpa, _NUM_SEC_WPA, 1);
|
||||
UFS_DEVICE_DESC_PARAM(psa_max_data_size, _PSA_MAX_DATA, 4);
|
||||
UFS_DEVICE_DESC_PARAM(psa_state_timeout, _PSA_TMT, 1);
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
UFS_DEVICE_DESC_PARAM(ext_feature_sup, _EXT_UFS_FEATURE_SUP, 4);
|
||||
UFS_DEVICE_DESC_PARAM(wb_presv_us_en, _WB_PRESRV_USRSPC_EN, 1);
|
||||
UFS_DEVICE_DESC_PARAM(wb_type, _WB_TYPE, 1);
|
||||
UFS_DEVICE_DESC_PARAM(wb_shared_alloc_units, _WB_SHARED_ALLOC_UNITS, 4);
|
||||
#endif
|
||||
|
||||
static struct attribute *ufs_sysfs_device_descriptor[] = {
|
||||
&dev_attr_device_type.attr,
|
||||
|
|
@ -305,6 +311,12 @@ static struct attribute *ufs_sysfs_device_descriptor[] = {
|
|||
&dev_attr_number_of_secure_wpa.attr,
|
||||
&dev_attr_psa_max_data_size.attr,
|
||||
&dev_attr_psa_state_timeout.attr,
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
&dev_attr_ext_feature_sup.attr,
|
||||
&dev_attr_wb_presv_us_en.attr,
|
||||
&dev_attr_wb_type.attr,
|
||||
&dev_attr_wb_shared_alloc_units.attr,
|
||||
#endif
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
|
@ -374,6 +386,13 @@ UFS_GEOMETRY_DESC_PARAM(enh4_memory_max_alloc_units,
|
|||
_ENM4_MAX_NUM_UNITS, 4);
|
||||
UFS_GEOMETRY_DESC_PARAM(enh4_memory_capacity_adjustment_factor,
|
||||
_ENM4_CAP_ADJ_FCTR, 2);
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
UFS_GEOMETRY_DESC_PARAM(wb_max_alloc_units, _WB_MAX_ALLOC_UNITS, 4);
|
||||
UFS_GEOMETRY_DESC_PARAM(wb_max_wb_luns, _WB_MAX_WB_LUNS, 1);
|
||||
UFS_GEOMETRY_DESC_PARAM(wb_buff_cap_adj, _WB_BUFF_CAP_ADJ, 1);
|
||||
UFS_GEOMETRY_DESC_PARAM(wb_sup_red_type, _WB_SUP_RED_TYPE, 1);
|
||||
UFS_GEOMETRY_DESC_PARAM(wb_sup_wb_type, _WB_SUP_WB_TYPE, 1);
|
||||
#endif
|
||||
|
||||
static struct attribute *ufs_sysfs_geometry_descriptor[] = {
|
||||
&dev_attr_raw_device_capacity.attr,
|
||||
|
|
@ -405,6 +424,13 @@ static struct attribute *ufs_sysfs_geometry_descriptor[] = {
|
|||
&dev_attr_enh3_memory_capacity_adjustment_factor.attr,
|
||||
&dev_attr_enh4_memory_max_alloc_units.attr,
|
||||
&dev_attr_enh4_memory_capacity_adjustment_factor.attr,
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
&dev_attr_wb_max_alloc_units.attr,
|
||||
&dev_attr_wb_max_wb_luns.attr,
|
||||
&dev_attr_wb_buff_cap_adj.attr,
|
||||
&dev_attr_wb_sup_red_type.attr,
|
||||
&dev_attr_wb_sup_wb_type.attr,
|
||||
#endif
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
|
@ -617,7 +643,7 @@ static ssize_t _name##_show(struct device *dev, \
|
|||
pm_runtime_put_sync(hba->dev); \
|
||||
if (ret) \
|
||||
return -EINVAL; \
|
||||
return sprintf(buf, "%s\n", flag ? "true" : "false"); \
|
||||
return sprintf(buf, "%s\n", flag ? "true" : "false"); \
|
||||
} \
|
||||
static DEVICE_ATTR_RO(_name)
|
||||
|
||||
|
|
@ -629,6 +655,11 @@ UFS_FLAG(life_span_mode_enable, _LIFE_SPAN_MODE_ENABLE);
|
|||
UFS_FLAG(phy_resource_removal, _FPHYRESOURCEREMOVAL);
|
||||
UFS_FLAG(busy_rtc, _BUSY_RTC);
|
||||
UFS_FLAG(disable_fw_update, _PERMANENTLY_DISABLE_FW_UPDATE);
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
UFS_FLAG(wb_enable, _WB_EN);
|
||||
UFS_FLAG(wb_flush_en, _WB_BUFF_FLUSH_EN);
|
||||
UFS_FLAG(wb_flush_during_h8, _WB_BUFF_FLUSH_DURING_HIBERN8);
|
||||
#endif
|
||||
|
||||
static struct attribute *ufs_sysfs_device_flags[] = {
|
||||
&dev_attr_device_init.attr,
|
||||
|
|
@ -639,6 +670,11 @@ static struct attribute *ufs_sysfs_device_flags[] = {
|
|||
&dev_attr_phy_resource_removal.attr,
|
||||
&dev_attr_busy_rtc.attr,
|
||||
&dev_attr_disable_fw_update.attr,
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
&dev_attr_wb_enable.attr,
|
||||
&dev_attr_wb_flush_en.attr,
|
||||
&dev_attr_wb_flush_during_h8.attr,
|
||||
#endif
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
|
@ -680,6 +716,12 @@ UFS_ATTRIBUTE(exception_event_status, _EE_STATUS);
|
|||
UFS_ATTRIBUTE(ffu_status, _FFU_STATUS);
|
||||
UFS_ATTRIBUTE(psa_state, _PSA_STATE);
|
||||
UFS_ATTRIBUTE(psa_data_size, _PSA_DATA_SIZE);
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
UFS_ATTRIBUTE(wb_flush_status, _WB_FLUSH_STATUS);
|
||||
UFS_ATTRIBUTE(wb_avail_buf, _AVAIL_WB_BUFF_SIZE);
|
||||
UFS_ATTRIBUTE(wb_life_time_est, _WB_BUFF_LIFE_TIME_EST);
|
||||
UFS_ATTRIBUTE(wb_cur_buf, _CURR_WB_BUFF_SIZE);
|
||||
#endif
|
||||
|
||||
static struct attribute *ufs_sysfs_attributes[] = {
|
||||
&dev_attr_boot_lun_enabled.attr,
|
||||
|
|
@ -698,6 +740,12 @@ static struct attribute *ufs_sysfs_attributes[] = {
|
|||
&dev_attr_ffu_status.attr,
|
||||
&dev_attr_psa_state.attr,
|
||||
&dev_attr_psa_data_size.attr,
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
&dev_attr_wb_flush_status.attr,
|
||||
&dev_attr_wb_avail_buf.attr,
|
||||
&dev_attr_wb_life_time_est.attr,
|
||||
&dev_attr_wb_cur_buf.attr,
|
||||
#endif
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
|
@ -749,6 +797,9 @@ UFS_UNIT_DESC_PARAM(provisioning_type, _PROVISIONING_TYPE, 1);
|
|||
UFS_UNIT_DESC_PARAM(physical_memory_resourse_count, _PHY_MEM_RSRC_CNT, 8);
|
||||
UFS_UNIT_DESC_PARAM(context_capabilities, _CTX_CAPABILITIES, 2);
|
||||
UFS_UNIT_DESC_PARAM(large_unit_granularity, _LARGE_UNIT_SIZE_M1, 1);
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
UFS_UNIT_DESC_PARAM(wb_buf_alloc_units, _WB_BUF_ALLOC_UNITS, 4);
|
||||
#endif
|
||||
|
||||
static struct attribute *ufs_sysfs_unit_descriptor[] = {
|
||||
&dev_attr_boot_lun_id.attr,
|
||||
|
|
@ -764,6 +815,9 @@ static struct attribute *ufs_sysfs_unit_descriptor[] = {
|
|||
&dev_attr_physical_memory_resourse_count.attr,
|
||||
&dev_attr_context_capabilities.attr,
|
||||
&dev_attr_large_unit_granularity.attr,
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
&dev_attr_wb_buf_alloc_units.attr,
|
||||
#endif
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -146,6 +146,11 @@ enum flag_idn {
|
|||
QUERY_FLAG_IDN_BUSY_RTC = 0x09,
|
||||
QUERY_FLAG_IDN_RESERVED3 = 0x0A,
|
||||
QUERY_FLAG_IDN_PERMANENTLY_DISABLE_FW_UPDATE = 0x0B,
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
QUERY_FLAG_IDN_WB_EN = 0x0E,
|
||||
QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN = 0x0F,
|
||||
QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8 = 0x10,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Attribute idn for Query requests */
|
||||
|
|
@ -174,6 +179,12 @@ enum attr_idn {
|
|||
QUERY_ATTR_IDN_PSA_STATE = 0x15,
|
||||
QUERY_ATTR_IDN_PSA_DATA_SIZE = 0x16,
|
||||
QUERY_ATTR_IDN_REF_CLK_GATING_WAIT_TIME = 0x17,
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
QUERY_ATTR_IDN_WB_FLUSH_STATUS = 0x1C,
|
||||
QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE = 0x1D,
|
||||
QUERY_ATTR_IDN_WB_BUFF_LIFE_TIME_EST = 0x1E,
|
||||
QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE = 0x1F,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Descriptor idn for Query requests */
|
||||
|
|
@ -197,9 +208,17 @@ enum desc_header_offset {
|
|||
};
|
||||
|
||||
enum ufs_desc_def_size {
|
||||
QUERY_DESC_DEVICE_DEF_SIZE = 0x40,
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
QUERY_DESC_DEVICE_DEF_SIZE = 0x59,
|
||||
#else
|
||||
QUERY_DESC_DEVICE_DEF_SIZE = 0x40,
|
||||
#endif
|
||||
QUERY_DESC_CONFIGURATION_DEF_SIZE = 0x90,
|
||||
QUERY_DESC_UNIT_DEF_SIZE = 0x23,
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
QUERY_DESC_UNIT_DEF_SIZE = 0x2D,
|
||||
#else
|
||||
QUERY_DESC_UNIT_DEF_SIZE = 0x23,
|
||||
#endif
|
||||
QUERY_DESC_INTERCONNECT_DEF_SIZE = 0x06,
|
||||
QUERY_DESC_GEOMETRY_DEF_SIZE = 0x48,
|
||||
QUERY_DESC_POWER_DEF_SIZE = 0x62,
|
||||
|
|
@ -225,6 +244,9 @@ enum unit_desc_param {
|
|||
UNIT_DESC_PARAM_PHY_MEM_RSRC_CNT = 0x18,
|
||||
UNIT_DESC_PARAM_CTX_CAPABILITIES = 0x20,
|
||||
UNIT_DESC_PARAM_LARGE_UNIT_SIZE_M1 = 0x22,
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
UNIT_DESC_PARAM_WB_BUF_ALLOC_UNITS = 0x29,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Device descriptor parameters offsets in bytes*/
|
||||
|
|
@ -264,6 +286,12 @@ enum device_desc_param {
|
|||
DEVICE_DESC_PARAM_PSA_MAX_DATA = 0x25,
|
||||
DEVICE_DESC_PARAM_PSA_TMT = 0x29,
|
||||
DEVICE_DESC_PARAM_PRDCT_REV = 0x2A,
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP = 0x4F,
|
||||
DEVICE_DESC_PARAM_WB_PRESRV_USRSPC_EN = 0x53,
|
||||
DEVICE_DESC_PARAM_WB_TYPE = 0x54,
|
||||
DEVICE_DESC_PARAM_WB_SHARED_ALLOC_UNITS = 0x55,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Interconnect descriptor parameters offsets in bytes*/
|
||||
|
|
@ -308,6 +336,13 @@ enum geometry_desc_param {
|
|||
GEOMETRY_DESC_PARAM_ENM4_MAX_NUM_UNITS = 0x3E,
|
||||
GEOMETRY_DESC_PARAM_ENM4_CAP_ADJ_FCTR = 0x42,
|
||||
GEOMETRY_DESC_PARAM_OPT_LOG_BLK_SIZE = 0x44,
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
GEOMETRY_DESC_PARAM_WB_MAX_ALLOC_UNITS = 0x4F,
|
||||
GEOMETRY_DESC_PARAM_WB_MAX_WB_LUNS = 0x53,
|
||||
GEOMETRY_DESC_PARAM_WB_BUFF_CAP_ADJ = 0x54,
|
||||
GEOMETRY_DESC_PARAM_WB_SUP_RED_TYPE = 0x55,
|
||||
GEOMETRY_DESC_PARAM_WB_SUP_WB_TYPE = 0x56,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Health descriptor parameters offsets in bytes*/
|
||||
|
|
@ -339,6 +374,13 @@ enum {
|
|||
UFSHCD_AMP = 3,
|
||||
};
|
||||
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
/* Possible values for dExtendedUFSFeaturesSupport */
|
||||
enum {
|
||||
UFS_DEV_WRITE_BOOSTER_SUP = BIT(8),
|
||||
};
|
||||
#endif
|
||||
|
||||
#define POWER_DESC_MAX_SIZE 0x62
|
||||
#define POWER_DESC_MAX_ACTV_ICC_LVLS 16
|
||||
|
||||
|
|
@ -456,6 +498,13 @@ enum ufs_dev_pwr_mode {
|
|||
UFS_POWERDOWN_PWR_MODE = 3,
|
||||
};
|
||||
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
enum ufs_dev_wb_buf_avail_size {
|
||||
UFS_WB_10_PERCENT_BUF_REMAIN = 0x1,
|
||||
UFS_WB_40_PERCENT_BUF_REMAIN = 0x4,
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* struct utp_cmd_rsp - Response UPIU structure
|
||||
* @residual_transfer_count: Residual transfer count DW-3
|
||||
|
|
@ -566,6 +615,13 @@ struct ufs_dev_info {
|
|||
u8 *model;
|
||||
u16 wspecversion;
|
||||
u32 clk_gating_wait_us;
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
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;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@
|
|||
#include <linux/of.h>
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/blk-pm.h>
|
||||
#include <asm/unaligned.h>
|
||||
#include <linux/blkdev.h>
|
||||
#include "ufshcd.h"
|
||||
#include "ufs_quirks.h"
|
||||
#include "unipro.h"
|
||||
|
|
@ -251,6 +253,15 @@ static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up);
|
|||
static irqreturn_t ufshcd_intr(int irq, void *__hba);
|
||||
static int ufshcd_change_power_mode(struct ufs_hba *hba,
|
||||
struct ufs_pa_layer_attr *pwr_mode);
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
static bool ufshcd_wb_sup(struct ufs_hba *hba);
|
||||
static int ufshcd_wb_buf_flush_enable(struct ufs_hba *hba);
|
||||
static int ufshcd_wb_buf_flush_disable(struct ufs_hba *hba);
|
||||
static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable);
|
||||
static int 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);
|
||||
#endif
|
||||
|
||||
static inline bool ufshcd_valid_tag(struct ufs_hba *hba, int tag)
|
||||
{
|
||||
return tag >= 0 && tag < hba->nutrs;
|
||||
|
|
@ -272,6 +283,27 @@ static inline void ufshcd_disable_irq(struct ufs_hba *hba)
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
static inline void ufshcd_wb_config(struct ufs_hba *hba)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!ufshcd_wb_sup(hba))
|
||||
return;
|
||||
|
||||
ret = ufshcd_wb_ctrl(hba, true);
|
||||
if (ret)
|
||||
dev_err(hba->dev, "%s: Enable WB failed: %d\n", __func__, ret);
|
||||
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);
|
||||
ufshcd_wb_toggle_flush(hba, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void ufshcd_scsi_unblock_requests(struct ufs_hba *hba)
|
||||
{
|
||||
if (atomic_dec_and_test(&hba->scsi_block_reqs_cnt))
|
||||
|
|
@ -1191,6 +1223,13 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up)
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
/* Enable Write Booster if we have scaled up else disable it */
|
||||
up_write(&hba->clk_scaling_lock);
|
||||
ufshcd_wb_ctrl(hba, scale_up);
|
||||
down_write(&hba->clk_scaling_lock);
|
||||
#endif
|
||||
|
||||
goto clk_scaling_unprepare;
|
||||
|
||||
scale_up_gear:
|
||||
|
|
@ -5370,6 +5409,168 @@ out:
|
|||
__func__, err);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
static bool ufshcd_wb_sup(struct ufs_hba *hba)
|
||||
{
|
||||
return ufshcd_is_wb_allowed(hba);
|
||||
}
|
||||
|
||||
static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable)
|
||||
{
|
||||
int ret;
|
||||
enum query_opcode opcode;
|
||||
|
||||
if (!ufshcd_wb_sup(hba))
|
||||
return 0;
|
||||
|
||||
if (!(enable ^ hba->wb_enabled))
|
||||
return 0;
|
||||
if (enable)
|
||||
opcode = UPIU_QUERY_OPCODE_SET_FLAG;
|
||||
else
|
||||
opcode = UPIU_QUERY_OPCODE_CLEAR_FLAG;
|
||||
|
||||
ret = ufshcd_query_flag_retry(hba, opcode,
|
||||
QUERY_FLAG_IDN_WB_EN, NULL);
|
||||
if (ret) {
|
||||
dev_err(hba->dev, "%s write booster %s failed %d\n",
|
||||
__func__, enable ? "enable" : "disable", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
hba->wb_enabled = enable;
|
||||
dev_dbg(hba->dev, "%s write booster %s %d\n",
|
||||
__func__, enable ? "enable" : "disable", ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set)
|
||||
{
|
||||
int val;
|
||||
|
||||
if (set)
|
||||
val = UPIU_QUERY_OPCODE_SET_FLAG;
|
||||
else
|
||||
val = UPIU_QUERY_OPCODE_CLEAR_FLAG;
|
||||
|
||||
return ufshcd_query_flag_retry(hba, val,
|
||||
QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static inline void ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
ufshcd_wb_buf_flush_enable(hba);
|
||||
else
|
||||
ufshcd_wb_buf_flush_disable(hba);
|
||||
|
||||
}
|
||||
|
||||
static int ufshcd_wb_buf_flush_enable(struct ufs_hba *hba)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!ufshcd_wb_sup(hba) || hba->wb_buf_flush_enabled)
|
||||
return 0;
|
||||
|
||||
ret = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG,
|
||||
QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, NULL);
|
||||
if (ret)
|
||||
dev_err(hba->dev, "%s WB - buf flush enable failed %d\n",
|
||||
__func__, ret);
|
||||
else
|
||||
hba->wb_buf_flush_enabled = true;
|
||||
|
||||
dev_dbg(hba->dev, "WB - Flush enabled: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ufshcd_wb_buf_flush_disable(struct ufs_hba *hba)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!ufshcd_wb_sup(hba) || !hba->wb_buf_flush_enabled)
|
||||
return 0;
|
||||
|
||||
ret = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_CLEAR_FLAG,
|
||||
QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, NULL);
|
||||
if (ret) {
|
||||
dev_warn(hba->dev, "%s: WB - buf flush disable failed %d\n",
|
||||
__func__, ret);
|
||||
} else {
|
||||
hba->wb_buf_flush_enabled = false;
|
||||
dev_dbg(hba->dev, "WB - Flush disabled: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,
|
||||
u32 avail_buf)
|
||||
{
|
||||
u32 cur_buf;
|
||||
int ret;
|
||||
|
||||
ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
|
||||
QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE,
|
||||
0, 0, &cur_buf);
|
||||
if (ret) {
|
||||
dev_err(hba->dev, "%s dCurWriteBoosterBufferSize read failed %d\n",
|
||||
__func__, ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!cur_buf) {
|
||||
dev_info(hba->dev, "dCurWBBuf: %d WB disabled until free-space is available\n",
|
||||
cur_buf);
|
||||
return false;
|
||||
}
|
||||
/* Let it continue to flush when >60% full */
|
||||
if (avail_buf < UFS_WB_40_PERCENT_BUF_REMAIN)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool ufshcd_wb_keep_vcc_on(struct ufs_hba *hba)
|
||||
{
|
||||
int ret;
|
||||
u32 avail_buf;
|
||||
|
||||
if (!ufshcd_wb_sup(hba))
|
||||
return false;
|
||||
/*
|
||||
* The ufs device needs the vcc to be ON to flush.
|
||||
* With user-space reduction enabled, it's enough to enable flush
|
||||
* by checking only the available buffer. The threshold
|
||||
* defined here is > 90% full.
|
||||
* With user-space preserved enabled, the current-buffer
|
||||
* should be checked too because the wb buffer size can reduce
|
||||
* when disk tends to be full. This info is provided by current
|
||||
* buffer (dCurrentWriteBoosterBufferSize). There's no point in
|
||||
* keeping vcc on when current buffer is empty.
|
||||
*/
|
||||
ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
|
||||
QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE,
|
||||
0, 0, &avail_buf);
|
||||
if (ret) {
|
||||
dev_warn(hba->dev, "%s dAvailableWriteBoosterBufferSize read failed %d\n",
|
||||
__func__, ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!hba->dev_info.b_presrv_uspc_en) {
|
||||
if (avail_buf <= UFS_WB_10_PERCENT_BUF_REMAIN)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return ufshcd_wb_presrv_usrspc_keep_vcc_on(hba, avail_buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ufshcd_exception_event_handler - handle exceptions raised by device
|
||||
* @work: pointer to work data
|
||||
|
|
@ -6777,6 +6978,35 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
static void ufshcd_wb_probe(struct ufs_hba *hba, u8 *desc_buf)
|
||||
{
|
||||
hba->dev_info.d_ext_ufs_feature_sup =
|
||||
get_unaligned_be32(desc_buf +
|
||||
DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP);
|
||||
/*
|
||||
* WB may be supported but not configured while provisioning.
|
||||
* The spec says, in dedicated wb buffer mode,
|
||||
* a max of 1 lun would have wb buffer configured.
|
||||
* Now only shared buffer mode is supported.
|
||||
*/
|
||||
hba->dev_info.b_wb_buffer_type =
|
||||
desc_buf[DEVICE_DESC_PARAM_WB_TYPE];
|
||||
|
||||
hba->dev_info.d_wb_alloc_units =
|
||||
get_unaligned_be32(desc_buf +
|
||||
DEVICE_DESC_PARAM_WB_SHARED_ALLOC_UNITS);
|
||||
hba->dev_info.b_presrv_uspc_en =
|
||||
desc_buf[DEVICE_DESC_PARAM_WB_PRESRV_USRSPC_EN];
|
||||
|
||||
if (!((hba->dev_info.d_ext_ufs_feature_sup &
|
||||
UFS_DEV_WRITE_BOOSTER_SUP) &&
|
||||
hba->dev_info.b_wb_buffer_type &&
|
||||
hba->dev_info.d_wb_alloc_units))
|
||||
hba->caps &= ~UFSHCD_CAP_WB_EN;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int ufs_get_device_desc(struct ufs_hba *hba)
|
||||
{
|
||||
int err;
|
||||
|
|
@ -6812,6 +7042,13 @@ static int ufs_get_device_desc(struct ufs_hba *hba)
|
|||
desc_buf[DEVICE_DESC_PARAM_SPEC_VER + 1];
|
||||
|
||||
model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME];
|
||||
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
/* Enable WB only for UFS-3.1 */
|
||||
if (dev_info->wspecversion >= 0x310)
|
||||
ufshcd_wb_probe(hba, desc_buf);
|
||||
#endif
|
||||
|
||||
err = ufshcd_read_string_desc(hba, model_index,
|
||||
&dev_info->model, SD_ASCII_STD);
|
||||
if (err < 0) {
|
||||
|
|
@ -7288,6 +7525,9 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool async)
|
|||
/* set the state as operational after switching to desired gear */
|
||||
hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL;
|
||||
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
ufshcd_wb_config(hba);
|
||||
#endif
|
||||
/* Enable Auto-Hibernate if configured */
|
||||
ufshcd_auto_hibern8_enable(hba);
|
||||
|
||||
|
|
@ -7985,12 +8225,18 @@ static void ufshcd_vreg_set_lpm(struct ufs_hba *hba)
|
|||
*
|
||||
* Ignore the error returned by ufshcd_toggle_vreg() as device is anyway
|
||||
* in low power state which would save some power.
|
||||
*
|
||||
* If Write Booster is enabled and the device needs to flush the WB
|
||||
* buffer OR if bkops status is urgent for WB, keep Vcc on.
|
||||
*/
|
||||
if (ufshcd_is_ufs_dev_poweroff(hba) && ufshcd_is_link_off(hba) &&
|
||||
!hba->dev_info.is_lu_power_on_wp) {
|
||||
ufshcd_setup_vreg(hba, false);
|
||||
} else if (!ufshcd_is_ufs_dev_active(hba)) {
|
||||
ufshcd_toggle_vreg(hba->dev, hba->vreg_info.vcc, false);
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
if (!hba->dev_info.keep_vcc_on)
|
||||
#endif
|
||||
ufshcd_toggle_vreg(hba->dev, hba->vreg_info.vcc, false);
|
||||
if (!ufshcd_is_link_active(hba)) {
|
||||
ufshcd_config_vreg_lpm(hba, hba->vreg_info.vccq);
|
||||
ufshcd_config_vreg_lpm(hba, hba->vreg_info.vccq2);
|
||||
|
|
@ -8136,11 +8382,25 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
|
|||
/* make sure that auto bkops is disabled */
|
||||
ufshcd_disable_auto_bkops(hba);
|
||||
}
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
/*
|
||||
* With wb enabled, if the bkops is enabled or if the
|
||||
* configured WB type is 70% full, keep vcc ON
|
||||
* for the device to flush the wb buffer
|
||||
*/
|
||||
if ((hba->auto_bkops_enabled && ufshcd_wb_sup(hba)) ||
|
||||
ufshcd_wb_keep_vcc_on(hba))
|
||||
hba->dev_info.keep_vcc_on = true;
|
||||
else
|
||||
hba->dev_info.keep_vcc_on = false;
|
||||
} else if (!ufshcd_is_runtime_pm(pm_op)) {
|
||||
hba->dev_info.keep_vcc_on = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((req_dev_pwr_mode != hba->curr_dev_pwr_mode) &&
|
||||
((ufshcd_is_runtime_pm(pm_op) && !hba->auto_bkops_enabled) ||
|
||||
!ufshcd_is_runtime_pm(pm_op))) {
|
||||
((ufshcd_is_runtime_pm(pm_op) && !hba->auto_bkops_enabled) ||
|
||||
!ufshcd_is_runtime_pm(pm_op))) {
|
||||
/* ensure that bkops is disabled */
|
||||
ufshcd_disable_auto_bkops(hba);
|
||||
ret = ufshcd_set_dev_pwr_mode(hba, req_dev_pwr_mode);
|
||||
|
|
|
|||
|
|
@ -931,6 +931,14 @@ struct ufs_hba {
|
|||
* inline crypto engine, if it is present
|
||||
*/
|
||||
#define UFSHCD_CAP_CRYPTO (1 << 7)
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
/*
|
||||
* This capability allows the host controller driver to turn-on
|
||||
* WriteBooster, if the underlying device supports it and is
|
||||
* provisioned to be used. This would increase the write performance.
|
||||
*/
|
||||
#define UFSHCD_CAP_WB_EN (1 << 8)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SCSI_UFSHCD_QTI
|
||||
#define UFSHCD_CAP_POWER_COLLAPSE_DURING_HIBERN8 (1 << 7)
|
||||
|
|
@ -970,6 +978,10 @@ struct ufs_hba {
|
|||
struct device bsg_dev;
|
||||
struct request_queue *bsg_queue;
|
||||
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
bool wb_buf_flush_enabled;
|
||||
bool wb_enabled;
|
||||
#endif
|
||||
#ifdef CONFIG_SCSI_UFS_CRYPTO
|
||||
/* crypto */
|
||||
union ufs_crypto_capabilities crypto_capabilities;
|
||||
|
|
@ -1061,6 +1073,13 @@ static inline bool ufshcd_is_auto_hibern8_enabled(struct ufs_hba *hba)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_SCSI_UFSHCD_QTI)
|
||||
static inline bool ufshcd_is_wb_allowed(struct ufs_hba *hba)
|
||||
{
|
||||
return hba->caps & UFSHCD_CAP_WB_EN;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define ufshcd_writel(hba, val, reg) \
|
||||
writel((val), (hba)->mmio_base + (reg))
|
||||
#define ufshcd_readl(hba, reg) \
|
||||
|
|
|
|||
Loading…
Reference in a new issue