diff mbox series

[1/3] scsi: ufs: Probe for temperature notification support

Message ID 20210901123707.5014-2-avri.altman@wdc.com
State New
Headers show
Series [1/3] scsi: ufs: Probe for temperature notification support | expand

Commit Message

Avri Altman Sept. 1, 2021, 12:37 p.m. UTC
Probe the dExtendedUFSFeaturesSupport register for the device's
temperature notification support.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
---
 drivers/scsi/ufs/ufs.h    |  7 +++++++
 drivers/scsi/ufs/ufshcd.c | 18 ++++++++++++++++++
 drivers/scsi/ufs/ufshcd.h | 22 ++++++++++++++++++++++
 3 files changed, 47 insertions(+)

Comments

Bart Van Assche Sept. 1, 2021, 4:35 p.m. UTC | #1
On 9/1/21 5:37 AM, Avri Altman wrote:
> +static inline bool ufshcd_is_high_temp_notif_allowed(struct ufs_hba *hba)
> +{
> +	return hba->dev_info.high_temp_notif;
> +}
> +
> +static inline bool ufshcd_is_low_temp_notif_allowed(struct ufs_hba *hba)
> +{
> +	return hba->dev_info.low_temp_notif;
> +}

Please do not introduce single line inline functions.

> +static inline bool ufshcd_is_temp_notif_allowed(struct ufs_hba *hba)
> +{
> +	return ufshcd_is_high_temp_notif_allowed(hba) ||
> +	       ufshcd_is_high_temp_notif_allowed(hba);
> +}

Since this function is not in any hot path (command processing), 
shouldn't it be moved into ufshcd.c?

Thanks,

Bart.
Avri Altman Sept. 2, 2021, 6:24 a.m. UTC | #2
> 

> On 9/1/21 5:37 AM, Avri Altman wrote:

> > +static inline bool ufshcd_is_high_temp_notif_allowed(struct ufs_hba *hba)

> > +{

> > +     return hba->dev_info.high_temp_notif;

> > +}

> > +

> > +static inline bool ufshcd_is_low_temp_notif_allowed(struct ufs_hba *hba)

> > +{

> > +     return hba->dev_info.low_temp_notif;

> > +}

> 

> Please do not introduce single line inline functions.

Done.

> 

> > +static inline bool ufshcd_is_temp_notif_allowed(struct ufs_hba *hba)

> > +{

> > +     return ufshcd_is_high_temp_notif_allowed(hba) ||

> > +            ufshcd_is_high_temp_notif_allowed(hba);

> > +}

> 

> Since this function is not in any hot path (command processing),

> shouldn't it be moved into ufshcd.c?

Done.

> 

> Thanks,

> 

> Bart.
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h
index 8c6b38b1b142..dee897ef9631 100644
--- a/drivers/scsi/ufs/ufs.h
+++ b/drivers/scsi/ufs/ufs.h
@@ -338,6 +338,9 @@  enum {
 
 /* Possible values for dExtendedUFSFeaturesSupport */
 enum {
+	UFS_DEV_LOW_TEMP_NOTIF		= BIT(4),
+	UFS_DEV_HIGH_TEMP_NOTIF		= BIT(5),
+	UFS_DEV_EXT_TEMP_NOTIF		= BIT(6),
 	UFS_DEV_HPB_SUPPORT		= BIT(7),
 	UFS_DEV_WRITE_BOOSTER_SUP	= BIT(8),
 };
@@ -604,6 +607,10 @@  struct ufs_dev_info {
 
 	bool	b_rpm_dev_flush_capable;
 	u8	b_presrv_uspc_en;
+
+	/* temperature notification */
+	bool high_temp_notif;
+	bool low_temp_notif;
 };
 
 /*
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 3841ab49f556..6ad51ae764c5 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -7469,6 +7469,22 @@  static void ufshcd_wb_probe(struct ufs_hba *hba, u8 *desc_buf)
 	hba->caps &= ~UFSHCD_CAP_WB_EN;
 }
 
+static void ufshcd_temp_notif_probe(struct ufs_hba *hba, u8 *desc_buf)
+{
+	struct ufs_dev_info *dev_info = &hba->dev_info;
+	u32 ext_ufs_feature;
+
+	if (!(hba->caps & UFSHCD_CAP_TEMP_NOTIF) ||
+	    dev_info->wspecversion < 0x300)
+		return;
+
+	ext_ufs_feature = get_unaligned_be32(desc_buf +
+					DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP);
+
+	dev_info->low_temp_notif = ext_ufs_feature & UFS_DEV_LOW_TEMP_NOTIF;
+	dev_info->high_temp_notif = ext_ufs_feature & UFS_DEV_HIGH_TEMP_NOTIF;
+}
+
 void ufshcd_fixup_dev_quirks(struct ufs_hba *hba, struct ufs_dev_fix *fixups)
 {
 	struct ufs_dev_fix *f;
@@ -7564,6 +7580,8 @@  static int ufs_get_device_desc(struct ufs_hba *hba)
 
 	ufshcd_wb_probe(hba, desc_buf);
 
+	ufshcd_temp_notif_probe(hba, desc_buf);
+
 	/*
 	 * ufshcd_read_string_desc returns size of the string
 	 * reset the error value
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 52ea6f350b18..467affbaec80 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -653,6 +653,12 @@  enum ufshcd_caps {
 	 * in order to exit DeepSleep state.
 	 */
 	UFSHCD_CAP_DEEPSLEEP				= 1 << 10,
+
+	/*
+	 * This capability allows the host controller driver to use temperature
+	 * notification if it is supported by the UFS device.
+	 */
+	UFSHCD_CAP_TEMP_NOTIF				= 1 << 11,
 };
 
 struct ufs_hba_variant_params {
@@ -972,6 +978,22 @@  static inline bool ufshcd_is_user_access_allowed(struct ufs_hba *hba)
 	return !hba->shutting_down;
 }
 
+static inline bool ufshcd_is_high_temp_notif_allowed(struct ufs_hba *hba)
+{
+	return hba->dev_info.high_temp_notif;
+}
+
+static inline bool ufshcd_is_low_temp_notif_allowed(struct ufs_hba *hba)
+{
+	return hba->dev_info.low_temp_notif;
+}
+
+static inline bool ufshcd_is_temp_notif_allowed(struct ufs_hba *hba)
+{
+	return ufshcd_is_high_temp_notif_allowed(hba) ||
+	       ufshcd_is_high_temp_notif_allowed(hba);
+}
+
 #define ufshcd_writel(hba, val, reg)	\
 	writel((val), (hba)->mmio_base + (reg))
 #define ufshcd_readl(hba, reg)	\