mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yue Hu <zbestahu@gmail.com>
To: Avri Altman <Avri.Altman@wdc.com>
Cc: "martin.petersen@oracle.com" <martin.petersen@oracle.com>,
	"jejb@linux.ibm.com" <jejb@linux.ibm.com>,
	"alim.akhtar@samsung.com" <alim.akhtar@samsung.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"huyue2@yulong.com" <huyue2@yulong.com>,
	"zbestahu@163.com" <zbestahu@163.com>
Subject: Re: [PATCH] scsi: ufs: Tidy up WB configuration code
Date: Thu, 18 Mar 2021 09:33:13 +0800	[thread overview]
Message-ID: <20210318093313.000073ad.zbestahu@gmail.com> (raw)
In-Reply-To: <DM6PR04MB6575F4023FAC6600288A8973FC6A9@DM6PR04MB6575.namprd04.prod.outlook.com>

On Wed, 17 Mar 2021 14:02:23 +0000
Avri Altman <Avri.Altman@wdc.com> wrote:

> > 
> > From: Yue Hu <huyue2@yulong.com>
> > 
> > There are similar code implemetentions for WB configurations in
> > ufshcd_wb_{ctrl, toggle_flush_during_h8, toggle_flush}. We can
> > extract the part to create a new helper with a flag parameter to
> > reduce code duplication.
> > 
> > Meanwhile, change ufshcd_wb_ctrl() -> ufshcd_wb_toggle() for better
> > readability.
> > 
> > And remove unnecessary log messages from ufshcd_wb_config() since
> > relevant toggle function will spew log respectively. Also change
> > ufshcd_wb_toggle_flush{__during_h8} to void type accordingly.
> > 
> > Signed-off-by: Yue Hu <huyue2@yulong.com>  
> A small nit below, otherwise - looks good to me.
> Reviewed-by: Avri Altman <avri.altman@wdc.com>
> 
> > ---
> >  drivers/scsi/ufs/ufs-sysfs.c |  2 +-
> >  drivers/scsi/ufs/ufshcd.c    | 99 +++++++++++++++++++-------------------------
> >  drivers/scsi/ufs/ufshcd.h    |  2 +-
> >  3 files changed, 44 insertions(+), 59 deletions(-)
> > 
> > diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c
> > index acc54f5..d7c3cff 100644
> > --- a/drivers/scsi/ufs/ufs-sysfs.c
> > +++ b/drivers/scsi/ufs/ufs-sysfs.c
> > @@ -246,7 +246,7 @@ static ssize_t wb_on_store(struct device *dev, struct
> > device_attribute *attr,
> >         }
> > 
> >         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);
> >  out:
> >         up(&hba->host_sem);
> > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> > index 7716175..1368f9e 100644
> > --- a/drivers/scsi/ufs/ufshcd.c
> > +++ b/drivers/scsi/ufs/ufshcd.c
> > @@ -247,8 +247,8 @@ static int ufshcd_change_power_mode(struct ufs_hba
> > *hba,
> >  static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba,
> >                                          struct ufs_vreg *vreg);
> >  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 inline int ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable);
> > +static void 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);
> >  static void ufshcd_hba_vreg_set_lpm(struct ufs_hba *hba);
> >  static void ufshcd_hba_vreg_set_hpm(struct ufs_hba *hba);
> > 
> > @@ -275,20 +275,12 @@ static inline void ufshcd_disable_irq(struct ufs_hba
> > *hba)
> > 
> >  static inline void ufshcd_wb_config(struct ufs_hba *hba)
> >  {
> > -       int ret;
> > -
> >         if (!ufshcd_is_wb_allowed(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(hba, true);
> > +
> > +       ufshcd_wb_toggle_flush_during_h8(hba, true);
> >         if (!(hba->quirks & UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL))
> >                 ufshcd_wb_toggle_flush(hba, true);
> >  }
> > @@ -1268,7 +1260,7 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba,
> > bool scale_up)
> >         /* Enable Write Booster if we have scaled up else disable it */
> >         downgrade_write(&hba->clk_scaling_lock);
> >         is_writelock = false;
> > -       ufshcd_wb_ctrl(hba, scale_up);
> > +       ufshcd_wb_toggle(hba, scale_up);
> > 
> >  out_unprepare:
> >         ufshcd_clock_scaling_unprepare(hba, is_writelock);
> > @@ -5432,85 +5424,78 @@ static void
> > ufshcd_bkops_exception_event_handler(struct ufs_hba *hba)
> >                                 __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;
> > +       int val;  
> Use turnery here?

Hi Avri,

Should use "enum query_opcode opcode", rt? will fix it in v2.

Thank you for reviewing the patch!

> 
> 
> >         u8 index;
> > -       enum query_opcode opcode;
> > +
> > +       if (set)
> > +               val = UPIU_QUERY_OPCODE_SET_FLAG;
> > +       else
> > +               val = UPIU_QUERY_OPCODE_CLEAR_FLAG;
> > +
> > +       index = ufshcd_wb_get_query_index(hba);
> > +       return ufshcd_query_flag_retry(hba, val, idn, index, NULL);
> > +}
> > +
> > +int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable)
> > +{
> > +       int ret;
> > 
> >         if (!ufshcd_is_wb_allowed(hba))
> >                 return 0;
> > 
> >         if (!(enable ^ hba->dev_info.wb_enabled))
> >                 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_query_flag_retry(hba, opcode,
> > -                                     QUERY_FLAG_IDN_WB_EN, index, NULL);
> > +       ret = __ufshcd_wb_toggle(hba, enable, QUERY_FLAG_IDN_WB_EN);
> >         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);
> >                 return ret;
> >         }
> > 
> >         hba->dev_info.wb_enabled = enable;
> > -       dev_dbg(hba->dev, "%s write booster %s %d\n",
> > -                       __func__, enable ? "enable" : "disable", ret);
> > +       dev_info(hba->dev, "%s Write Booster %s\n",
> > +                       __func__, enable ? "enabled" : "disabled");
> > 
> >         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;
> > -       u8 index;
> > -
> > -       if (set)
> > -               val =  UPIU_QUERY_OPCODE_SET_FLAG;
> > -       else
> > -               val = UPIU_QUERY_OPCODE_CLEAR_FLAG;
> > +       int ret;
> > 
> > -       index = ufshcd_wb_get_query_index(hba);
> > -       return ufshcd_query_flag_retry(hba, val,
> > -                               QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8,
> > -                               index, NULL);
> > +       ret = __ufshcd_wb_toggle(hba, set,
> > +                       QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8);
> > +       if (ret) {
> > +               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;
> > -       u8 index;
> > -       enum query_opcode opcode;
> > 
> >         if (!ufshcd_is_wb_allowed(hba) ||
> >             hba->dev_info.wb_buf_flush_enabled == enable)
> > -               return 0;
> > -
> > -       if (enable)
> > -               opcode = UPIU_QUERY_OPCODE_SET_FLAG;
> > -       else
> > -               opcode = UPIU_QUERY_OPCODE_CLEAR_FLAG;
> > +               return;
> > 
> > -       index = ufshcd_wb_get_query_index(hba);
> > -       ret = ufshcd_query_flag_retry(hba, opcode,
> > -                                     QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, index,
> > -                                     NULL);
> > +       ret = __ufshcd_wb_toggle(hba, enable,
> > QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN);
> >         if (ret) {
> >                 dev_err(hba->dev, "%s WB-Buf Flush %s failed %d\n", __func__,
> >                         enable ? "enable" : "disable", ret);
> > -               goto out;
> > +               return;
> >         }
> > 
> >         hba->dev_info.wb_buf_flush_enabled = enable;
> > 
> > -       dev_dbg(hba->dev, "WB-Buf Flush %s\n", enable ? "enabled" : "disabled");
> > -out:
> > -       return ret;
> > -
> > +       dev_dbg(hba->dev, "%s WB-Buf Flush %s\n",
> > +                       __func__, enable ? "enabled" : "disabled");
> >  }
> > 
> >  static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,
> > diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> > index 18e56c1..eddc819 100644
> > --- a/drivers/scsi/ufs/ufshcd.h
> > +++ b/drivers/scsi/ufs/ufshcd.h
> > @@ -1099,7 +1099,7 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba
> > *hba,
> >                              u8 *desc_buff, int *buff_len,
> >                              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 */
> >  static inline const char *ufshcd_get_var_name(struct ufs_hba *hba)
> > --
> > 1.9.1  
> 


      reply	other threads:[~2021-03-18  1:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 11:44 Yue Hu
2021-03-17 14:02 ` Avri Altman
2021-03-18  1:33   ` Yue Hu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210318093313.000073ad.zbestahu@gmail.com \
    --to=zbestahu@gmail.com \
    --cc=Avri.Altman@wdc.com \
    --cc=alim.akhtar@samsung.com \
    --cc=huyue2@yulong.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=zbestahu@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®