diff mbox series

[v1,2/3] scsi: ufs: override auto suspend tunables for ufs

Message ID 1568194890-24439-3-git-send-email-stanley.chu@mediatek.com (mailing list archive)
State Superseded
Headers show
Series [v1,1/3] scsi: core: allow auto suspend override by low-level driver | expand

Commit Message

Stanley Chu Sept. 11, 2019, 9:41 a.m. UTC
Rework from previous work by:
Sujit Reddy Thumma <sthumma@codeaurora.org>

Override auto suspend tunables for UFS device LUNs during
initialization so as to efficiently manage background operations
and the power consumption.

Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
---
 drivers/scsi/ufs/ufshcd.c |  8 ++++++++
 drivers/scsi/ufs/ufshcd.h | 10 ++++++++++
 2 files changed, 18 insertions(+)

Comments

Avri Altman Sept. 11, 2019, 10:56 a.m. UTC | #1
> 
> Rework from previous work by:
> Sujit Reddy Thumma <sthumma@codeaurora.org>
> 
> Override auto suspend tunables for UFS device LUNs during initialization so
> as to efficiently manage background operations and the power consumption.
> 
> Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>

> ---
>  drivers/scsi/ufs/ufshcd.c |  8 ++++++++  drivers/scsi/ufs/ufshcd.h | 10
> ++++++++++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index
> 30b752c61b97..d253a018a73b 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -88,6 +88,9 @@
>  /* Interrupt aggregation default timeout, unit: 40us */
>  #define INT_AGGR_DEF_TO        0x02
> 
> +/* default delay of autosuspend: 2000 ms */ #define
Typo?

> +RPM_AUTOSUSPEND_DELAY_MS 2000
> +
>  #define ufshcd_toggle_vreg(_dev, _vreg, _on)                           \
>         ({                                                              \
>                 int _ret;                                               \
> @@ -4612,9 +4615,14 @@ static int ufshcd_change_queue_depth(struct
> scsi_device *sdev, int depth)
>   */
>  static int ufshcd_slave_configure(struct scsi_device *sdev)  {
> +       struct ufs_hba *hba = shost_priv(sdev->host);
>         struct request_queue *q = sdev->request_queue;
> 
>         blk_queue_update_dma_pad(q, PRDT_DATA_BYTE_COUNT_PAD - 1);
> +
> +       if (ufshcd_is_rpm_autosuspend_allowed(hba))
> +               sdev->rpm_autosuspend_delay =
> RPM_AUTOSUSPEND_DELAY_MS;
> +
>         return 0;
>  }
> 
> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index
> a43c7135f33d..99ea416519af 100644
> --- a/drivers/scsi/ufs/ufshcd.h
> +++ b/drivers/scsi/ufs/ufshcd.h
> @@ -714,6 +714,12 @@ struct ufs_hba {
>          * the performance of ongoing read/write operations.
>          */
>  #define UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND (1
> << 5)
> +       /*
> +        * This capability allows host controller driver to automatically
> +        * enable runtime power management by itself instead of waiting
> +        * for userspace to control the power management.
> +        */
> +#define UFSHCD_CAP_RPM_AUTOSUSPEND (1 << 6)
> 
>         struct devfreq *devfreq;
>         struct ufs_clk_scaling clk_scaling; @@ -747,6 +753,10 @@ static inline
> bool ufshcd_can_autobkops_during_suspend(struct ufs_hba *hba)  {
>         return hba->caps & UFSHCD_CAP_AUTO_BKOPS_SUSPEND;  }
> +static inline bool ufshcd_is_rpm_autosuspend_allowed(struct ufs_hba
> +*hba) {
> +       return hba->caps & UFSHCD_CAP_RPM_AUTOSUSPEND; }
> 
>  static inline bool ufshcd_is_intr_aggr_allowed(struct ufs_hba *hba)  {
> --
> 2.18.0
Stanley Chu Sept. 12, 2019, 5:37 a.m. UTC | #2
Hi Avri,

> > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index
> > 30b752c61b97..d253a018a73b 100644
> > --- a/drivers/scsi/ufs/ufshcd.c
> > +++ b/drivers/scsi/ufs/ufshcd.c
> > @@ -88,6 +88,9 @@
> >  /* Interrupt aggregation default timeout, unit: 40us */
> >  #define INT_AGGR_DEF_TO        0x02
> > 
> > +/* default delay of autosuspend: 2000 ms */ #define
> Typo?
> 

This is wired because it looks fine in both my local patch and in
patchwork website: https://patchwork.kernel.org/patch/11140759/

Anyway I will try to fix and check it carefully in v2.

Thanks,
Stanley
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 30b752c61b97..d253a018a73b 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -88,6 +88,9 @@ 
 /* Interrupt aggregation default timeout, unit: 40us */
 #define INT_AGGR_DEF_TO	0x02
 
+/* default delay of autosuspend: 2000 ms */
+#define RPM_AUTOSUSPEND_DELAY_MS 2000
+
 #define ufshcd_toggle_vreg(_dev, _vreg, _on)				\
 	({                                                              \
 		int _ret;                                               \
@@ -4612,9 +4615,14 @@  static int ufshcd_change_queue_depth(struct scsi_device *sdev, int depth)
  */
 static int ufshcd_slave_configure(struct scsi_device *sdev)
 {
+	struct ufs_hba *hba = shost_priv(sdev->host);
 	struct request_queue *q = sdev->request_queue;
 
 	blk_queue_update_dma_pad(q, PRDT_DATA_BYTE_COUNT_PAD - 1);
+
+	if (ufshcd_is_rpm_autosuspend_allowed(hba))
+		sdev->rpm_autosuspend_delay = RPM_AUTOSUSPEND_DELAY_MS;
+
 	return 0;
 }
 
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index a43c7135f33d..99ea416519af 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -714,6 +714,12 @@  struct ufs_hba {
 	 * the performance of ongoing read/write operations.
 	 */
 #define UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND (1 << 5)
+	/*
+	 * This capability allows host controller driver to automatically
+	 * enable runtime power management by itself instead of waiting
+	 * for userspace to control the power management.
+	 */
+#define UFSHCD_CAP_RPM_AUTOSUSPEND (1 << 6)
 
 	struct devfreq *devfreq;
 	struct ufs_clk_scaling clk_scaling;
@@ -747,6 +753,10 @@  static inline bool ufshcd_can_autobkops_during_suspend(struct ufs_hba *hba)
 {
 	return hba->caps & UFSHCD_CAP_AUTO_BKOPS_SUSPEND;
 }
+static inline bool ufshcd_is_rpm_autosuspend_allowed(struct ufs_hba *hba)
+{
+	return hba->caps & UFSHCD_CAP_RPM_AUTOSUSPEND;
+}
 
 static inline bool ufshcd_is_intr_aggr_allowed(struct ufs_hba *hba)
 {