Message ID | 20200501143835.26032-4-stanley.chu@mediatek.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | scsi: ufs: support LU Dedicated buffer type for WriteBooster | expand |
Hi Stanley, Few more nits. Thanks, Avri > > According to UFS specification, there are two WriteBooster mode of > operations: "LU dedicated buffer" mode and "shared buffer" mode. > In the "LU dedicated buffer" mode, the WriteBooster Buffer is > dedicated to a logical unit. > > If the device supports the "LU dedicated buffer" mode, this mode is > configured by setting bWriteBoosterBufferType to 00h. The logical > unit WriteBooster Buffer size is configured by setting the > dLUNumWriteBoosterBufferAllocUnits field of the related Unit > Descriptor. Only a value greater than zero enables the WriteBooster > feature in the logical unit. > > Modify ufshcd_wb_probe() as above description to support LU Dedicated > buffer mode. > > Note that according to UFS 3.1 specification, the valid value of > bDeviceMaxWriteBoosterLUs parameter in Geometry Descriptor is 1, > which means at most one LUN can have WriteBooster buffer in "LU > dedicated buffer mode". Therefore this patch supports only one > LUN with WriteBooster enabled. All WriteBooster related sysfs nodes > are specifically mapped to the LUN with WriteBooster enabled in > LU Dedicated buffer mode. > > Signed-off-by: Stanley Chu <stanley.chu@mediatek.com> > --- > drivers/scsi/ufs/ufs-sysfs.c | 14 ++++++++- > drivers/scsi/ufs/ufs.h | 7 +++++ > drivers/scsi/ufs/ufshcd.c | 60 +++++++++++++++++++++++++++++------- > drivers/scsi/ufs/ufshcd.h | 1 + > 4 files changed, 70 insertions(+), 12 deletions(-) > > diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c > index b86b6a40d7e6..a162f63098e5 100644 > --- a/drivers/scsi/ufs/ufs-sysfs.c > +++ b/drivers/scsi/ufs/ufs-sysfs.c > @@ -622,16 +622,28 @@ static const struct attribute_group > ufs_sysfs_string_descriptors_group = { > .attrs = ufs_sysfs_string_descriptors, > }; > > +static bool ufshcd_is_wb_flags(enum flag_idn idn) Inline? And just return (idn >= QUERY_FLAG_IDN_WB_EN && idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8) > +{ > + if (idn >= QUERY_FLAG_IDN_WB_EN && > + idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8) > + return true; > + else > + return false; > +} > + > > +int ufshcd_wb_get_flag_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; > + else No need for else. Maybe make this static inline in ufshcd.h? > + return 0; > +} > +
Hi Avri, On Sat, 2020-05-02 at 15:32 +0000, Avri Altman wrote: > Hi Stanley, > Few more nits. > Thanks, > Avri All fixed in v4. Thanks for these suggestions. Stanley Chu > > > > > According to UFS specification, there are two WriteBooster mode of > > operations: "LU dedicated buffer" mode and "shared buffer" mode. > > In the "LU dedicated buffer" mode, the WriteBooster Buffer is > > dedicated to a logical unit. > > > > If the device supports the "LU dedicated buffer" mode, this mode is > > configured by setting bWriteBoosterBufferType to 00h. The logical > > unit WriteBooster Buffer size is configured by setting the > > dLUNumWriteBoosterBufferAllocUnits field of the related Unit > > Descriptor. Only a value greater than zero enables the WriteBooster > > feature in the logical unit. > > > > Modify ufshcd_wb_probe() as above description to support LU Dedicated > > buffer mode. > > > > Note that according to UFS 3.1 specification, the valid value of > > bDeviceMaxWriteBoosterLUs parameter in Geometry Descriptor is 1, > > which means at most one LUN can have WriteBooster buffer in "LU > > dedicated buffer mode". Therefore this patch supports only one > > LUN with WriteBooster enabled. All WriteBooster related sysfs nodes > > are specifically mapped to the LUN with WriteBooster enabled in > > LU Dedicated buffer mode. > > > > Signed-off-by: Stanley Chu <stanley.chu@mediatek.com> > > --- > > drivers/scsi/ufs/ufs-sysfs.c | 14 ++++++++- > > drivers/scsi/ufs/ufs.h | 7 +++++ > > drivers/scsi/ufs/ufshcd.c | 60 +++++++++++++++++++++++++++++------- > > drivers/scsi/ufs/ufshcd.h | 1 + > > 4 files changed, 70 insertions(+), 12 deletions(-) > > > > diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c > > index b86b6a40d7e6..a162f63098e5 100644 > > --- a/drivers/scsi/ufs/ufs-sysfs.c > > +++ b/drivers/scsi/ufs/ufs-sysfs.c > > @@ -622,16 +622,28 @@ static const struct attribute_group > > ufs_sysfs_string_descriptors_group = { > > .attrs = ufs_sysfs_string_descriptors, > > }; > > > > +static bool ufshcd_is_wb_flags(enum flag_idn idn) > Inline? > And just return (idn >= QUERY_FLAG_IDN_WB_EN && idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8) > > > +{ > > + if (idn >= QUERY_FLAG_IDN_WB_EN && > > + idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8) > > + return true; > > + else > > + return false; > > +} > > + > > > > > > +int ufshcd_wb_get_flag_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; > > + else > No need for else. > Maybe make this static inline in ufshcd.h? > > > + return 0; > > +} > > +
diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index b86b6a40d7e6..a162f63098e5 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -622,16 +622,28 @@ static const struct attribute_group ufs_sysfs_string_descriptors_group = { .attrs = ufs_sysfs_string_descriptors, }; +static bool ufshcd_is_wb_flags(enum flag_idn idn) +{ + if (idn >= QUERY_FLAG_IDN_WB_EN && + idn <= QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8) + return true; + else + return false; +} + #define UFS_FLAG(_name, _uname) \ static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ { \ bool flag; \ + u8 index = 0; \ 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); \ pm_runtime_get_sync(hba->dev); \ ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG, \ - QUERY_FLAG_IDN##_uname, 0, &flag); \ + QUERY_FLAG_IDN##_uname, index, &flag); \ pm_runtime_put_sync(hba->dev); \ if (ret) \ return -EINVAL; \ diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index daac5053b850..eb3d3cebc87d 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -330,6 +330,12 @@ enum health_desc_param { HEALTH_DESC_PARAM_LIFE_TIME_EST_B = 0x4, }; +/* WriteBooster buffer mode */ +enum { + WB_BUF_MODE_LU_DEDICATED = 0x0, + WB_BUF_MODE_SHARED = 0x1, +}; + /* * Logical Unit Write Protect * 00h: LU not write protected @@ -559,6 +565,7 @@ struct ufs_dev_info { bool is_lu_power_on_wp; /* Maximum number of general LU supported by the UFS device */ u8 max_lu_supported; + u8 wb_dedicated_lu; u16 wmanufacturerid; /*UFS device Product Name */ u8 *model; diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index f23705379b7d..8c256f6f4a65 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -5204,9 +5204,18 @@ static bool ufshcd_wb_sup(struct ufs_hba *hba) return ufshcd_is_wb_allowed(hba); } +int ufshcd_wb_get_flag_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; + else + return 0; +} + static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable) { int ret; + u8 index; enum query_opcode opcode; if (!ufshcd_wb_sup(hba)) @@ -5219,8 +5228,9 @@ 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); ret = ufshcd_query_flag_retry(hba, opcode, - QUERY_FLAG_IDN_WB_EN, 0, NULL); + QUERY_FLAG_IDN_WB_EN, index, NULL); if (ret) { dev_err(hba->dev, "%s write booster %s failed %d\n", __func__, enable ? "enable" : "disable", ret); @@ -5237,15 +5247,17 @@ 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) { int val; + u8 index; if (set) val = UPIU_QUERY_OPCODE_SET_FLAG; else val = UPIU_QUERY_OPCODE_CLEAR_FLAG; + index = ufshcd_wb_get_flag_index(hba); return ufshcd_query_flag_retry(hba, val, - QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8, 0, - NULL); + QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8, + index, NULL); } static inline void ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable) @@ -5260,13 +5272,15 @@ static inline void ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable) static int ufshcd_wb_buf_flush_enable(struct ufs_hba *hba) { int ret; + u8 index; if (!ufshcd_wb_sup(hba) || hba->wb_buf_flush_enabled) return 0; + index = ufshcd_wb_get_flag_index(hba); ret = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG, QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, - 0, NULL); + index, NULL); if (ret) dev_err(hba->dev, "%s WB - buf flush enable failed %d\n", __func__, ret); @@ -5280,12 +5294,15 @@ static int ufshcd_wb_buf_flush_enable(struct ufs_hba *hba) static int ufshcd_wb_buf_flush_disable(struct ufs_hba *hba) { int ret; + u8 index; if (!ufshcd_wb_sup(hba) || !hba->wb_buf_flush_enabled) return 0; + index = ufshcd_wb_get_flag_index(hba); ret = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_CLEAR_FLAG, - QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, 0, NULL); + QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, + index, NULL); if (ret) { dev_warn(hba->dev, "%s: WB - buf flush disable failed %d\n", __func__, ret); @@ -6804,6 +6821,10 @@ static int ufshcd_scsi_add_wlus(struct ufs_hba *hba) static void ufshcd_wb_probe(struct ufs_hba *hba, u8 *desc_buf) { + int ret; + u8 lun; + u32 d_lu_wb_buf_alloc = 0; + if (!ufshcd_is_wb_allowed(hba)) return; @@ -6826,16 +6847,33 @@ static void ufshcd_wb_probe(struct ufs_hba *hba, u8 *desc_buf) 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.b_wb_buffer_type && - hba->dev_info.d_wb_alloc_units)) - goto wb_disabled; + if (hba->dev_info.b_wb_buffer_type == WB_BUF_MODE_SHARED) { + hba->dev_info.d_wb_alloc_units = + get_unaligned_be32(desc_buf + + DEVICE_DESC_PARAM_WB_SHARED_ALLOC_UNITS); + if (!hba->dev_info.d_wb_alloc_units) + goto wb_disabled; + } else { + for (lun = 0; lun < hba->dev_info.max_lu_supported; lun++) { + ret = ufshcd_read_unit_desc_param(hba, + lun, + UNIT_DESC_PARAM_WB_BUF_ALLOC_UNITS, + (u8 *)&d_lu_wb_buf_alloc, + sizeof(d_lu_wb_buf_alloc)); + if (ret) + goto wb_disabled; + if (d_lu_wb_buf_alloc) { + hba->dev_info.wb_dedicated_lu = lun; + break; + } + } + if (!d_lu_wb_buf_alloc) + goto wb_disabled; + } return; wb_disabled: diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index e555d794d441..570961ada57c 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -823,6 +823,7 @@ void ufshcd_delay_us(unsigned long us, unsigned long tolerance); int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask, u32 val, unsigned long interval_us, unsigned long timeout_ms, bool can_sleep); +int ufshcd_wb_get_flag_index(struct ufs_hba *hba); void ufshcd_parse_dev_ref_clk_freq(struct ufs_hba *hba, struct clk *refclk); void ufshcd_update_reg_hist(struct ufs_err_reg_hist *reg_hist, u32 reg);
According to UFS specification, there are two WriteBooster mode of operations: "LU dedicated buffer" mode and "shared buffer" mode. In the "LU dedicated buffer" mode, the WriteBooster Buffer is dedicated to a logical unit. If the device supports the "LU dedicated buffer" mode, this mode is configured by setting bWriteBoosterBufferType to 00h. The logical unit WriteBooster Buffer size is configured by setting the dLUNumWriteBoosterBufferAllocUnits field of the related Unit Descriptor. Only a value greater than zero enables the WriteBooster feature in the logical unit. Modify ufshcd_wb_probe() as above description to support LU Dedicated buffer mode. Note that according to UFS 3.1 specification, the valid value of bDeviceMaxWriteBoosterLUs parameter in Geometry Descriptor is 1, which means at most one LUN can have WriteBooster buffer in "LU dedicated buffer mode". Therefore this patch supports only one LUN with WriteBooster enabled. All WriteBooster related sysfs nodes are specifically mapped to the LUN with WriteBooster enabled in LU Dedicated buffer mode. Signed-off-by: Stanley Chu <stanley.chu@mediatek.com> --- drivers/scsi/ufs/ufs-sysfs.c | 14 ++++++++- drivers/scsi/ufs/ufs.h | 7 +++++ drivers/scsi/ufs/ufshcd.c | 60 +++++++++++++++++++++++++++++------- drivers/scsi/ufs/ufshcd.h | 1 + 4 files changed, 70 insertions(+), 12 deletions(-)