mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Avri Altman <Avri.Altman@wdc.com>
To: Bean Huo <beanhuo@iokpp.de>,
	"bvanassche@acm.org" <bvanassche@acm.org>,
	"alim.akhtar@samsung.com" <alim.akhtar@samsung.com>,
	"jejb@linux.ibm.com" <jejb@linux.ibm.com>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
	"mani@kernel.org" <mani@kernel.org>,
	"quic_cang@quicinc.com" <quic_cang@quicinc.com>,
	"quic_asutoshd@quicinc.com" <quic_asutoshd@quicinc.com>,
	"beanhuo@micron.com" <beanhuo@micron.com>,
	"thomas@t-8ch.de" <thomas@t-8ch.de>
Cc: "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"mikebi@micron.com" <mikebi@micron.com>,
	"lporzio@micron.com" <lporzio@micron.com>
Subject: RE: [PATCH v3 2/3] scsi: ufs: core: Add UFS RTC support
Date: Mon, 4 Dec 2023 12:13:45 +0000	[thread overview]
Message-ID: <DM6PR04MB657594BADE76428806210D3AFC86A@DM6PR04MB6575.namprd04.prod.outlook.com> (raw)
In-Reply-To: <20231202160227.766529-3-beanhuo@iokpp.de>

> +static void  ufs_init_rtc(struct ufs_hba *hba, u8 *desc_buf) {
> +       struct ufs_dev_info *dev_info = &hba->dev_info;
> +       u16 periodic_rtc_update =
> +get_unaligned_be16(&desc_buf[DEVICE_DESC_PARAM_FRQ_RTC]);
> +
> +       if (periodic_rtc_update & UFS_RTC_TIME_BASELINE) {
Is it allowed to ignore the update period as depicted by wPeriodicRTCUpdate?
And choose a different update period, e.g. 10 seconds instead?
If yes - then It deserve a comment IMO.

Thanks,
Avri

> +               dev_info->rtc_type = UFS_RTC_ABSOLUTE;
> +               /*
> +                * The concept of measuring time in Linux as the number of seconds
> elapsed since
> +                * 00:00:00 UTC on January 1, 1970, and UFS ABS RTC is elapsed
> from January 1st
> +                * 2010 00:00, here we need to adjust ABS baseline.
> +                */
> +               dev_info->rtc_time_baseline = mktime64(2010, 1, 1, 0, 0, 0) -
> +                                                       mktime64(1970, 1, 1, 0, 0, 0);
> +       } else {
> +               dev_info->rtc_type = UFS_RTC_RELATIVE;
> +               dev_info->rtc_time_baseline = 0;
> +       }
> +
> +       INIT_DELAYED_WORK(&hba->ufs_rtc_update_work, ufshcd_rtc_work);
> }
> +
>  static int ufs_get_device_desc(struct ufs_hba *hba)  {
>         int err;
> @@ -8241,6 +8310,8 @@ static int ufs_get_device_desc(struct ufs_hba
> *hba)
> 
>         ufshcd_temp_notif_probe(hba, desc_buf);
> 
> +       ufs_init_rtc(hba, desc_buf);
> +
>         if (hba->ext_iid_sup)
>                 ufshcd_ext_iid_probe(hba, desc_buf);
> 
> @@ -8794,6 +8865,8 @@ static int ufshcd_device_init(struct ufs_hba *hba,
> bool init_dev_params)
>         ufshcd_force_reset_auto_bkops(hba);
> 
>         ufshcd_set_timestamp_attr(hba);
> +       schedule_delayed_work(&hba->ufs_rtc_update_work,
> +
> + msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS));
> 
>         /* Gear up to HS gear if supported */
>         if (hba->max_pwr_info.is_valid) { @@ -9750,6 +9823,8 @@ static int
> __ufshcd_wl_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
>         ret = ufshcd_vops_suspend(hba, pm_op, POST_CHANGE);
>         if (ret)
>                 goto set_link_active;
> +
> +       cancel_delayed_work_sync(&hba->ufs_rtc_update_work);
>         goto out;
> 
>  set_link_active:
> @@ -9844,6 +9919,8 @@ static int __ufshcd_wl_resume(struct ufs_hba
> *hba, enum ufs_pm_op pm_op)
>                 if (ret)
>                         goto set_old_link_state;
>                 ufshcd_set_timestamp_attr(hba);
> +               schedule_delayed_work(&hba->ufs_rtc_update_work,
> +
> + msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS));
>         }
> 
>         if (ufshcd_keep_autobkops_enabled_except_suspend(hba))
> diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h index
> e77ab1786856..8022d267fe8a 100644
> --- a/include/ufs/ufs.h
> +++ b/include/ufs/ufs.h
> @@ -14,6 +14,7 @@
>  #include <linux/bitops.h>
>  #include <linux/types.h>
>  #include <uapi/scsi/scsi_bsg_ufs.h>
> +#include <linux/time64.h>
> 
>  /*
>   * Using static_assert() is not allowed in UAPI header files. Hence the check
> @@ -551,6 +552,15 @@ struct ufs_vreg_info {
>         struct ufs_vreg *vdd_hba;
>  };
> 
> +/*
> + * UFS device descriptor wPeriodicRTCUpdate bit9 defines RTC time
> baseline.
> + */
> +#define UFS_RTC_TIME_BASELINE BIT(9)
> +enum ufs_rtc_time {
> +       UFS_RTC_RELATIVE,
> +       UFS_RTC_ABSOLUTE
> +};
> +
>  struct ufs_dev_info {
>         bool    f_power_on_wp_en;
>         /* Keeps information if any of the LU is power on write protected */ @@
> -578,6 +588,10 @@ struct ufs_dev_info {
> 
>         /* UFS EXT_IID Enable */
>         bool    b_ext_iid_en;
> +
> +       /* UFS RTC */
> +       enum ufs_rtc_time rtc_type;
> +       time64_t rtc_time_baseline;
>  };
> 
>  /*
> diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index
> 7f0b2c5599cd..7bdda92fcb1c 100644
> --- a/include/ufs/ufshcd.h
> +++ b/include/ufs/ufshcd.h
> @@ -911,6 +911,8 @@ enum ufshcd_mcq_opr {
>   * @mcq_base: Multi circular queue registers base address
>   * @uhq: array of supported hardware queues
>   * @dev_cmd_queue: Queue for issuing device management commands
> + * @mcq_opr: MCQ operation and runtime registers
> + * @ufs_rtc_update_work: A work for UFS RTC periodic update
>   */
>  struct ufs_hba {
>         void __iomem *mmio_base;
> @@ -1071,6 +1073,8 @@ struct ufs_hba {
>         struct ufs_hw_queue *uhq;
>         struct ufs_hw_queue *dev_cmd_queue;
>         struct ufshcd_mcq_opr_info_t mcq_opr[OPR_MAX];
> +
> +       struct delayed_work ufs_rtc_update_work;
>  };
> 
>  /**
> --
> 2.34.1
> 


  reply	other threads:[~2023-12-04 12:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-02 16:02 [PATCH v3 0/3] " Bean Huo
2023-12-02 16:02 ` [PATCH v3 1/3] scsi: ufs: core: Add ufshcd_is_ufs_dev_busy() Bean Huo
2023-12-06 19:36   ` Avri Altman
2023-12-02 16:02 ` [PATCH v3 2/3] scsi: ufs: core: Add UFS RTC support Bean Huo
2023-12-04 12:13   ` Avri Altman [this message]
2023-12-04 12:23     ` Avri Altman
2023-12-06 19:38   ` Avri Altman
2023-12-07  0:59   ` Bart Van Assche
2023-12-07 23:02     ` Bean Huo
2023-12-02 16:02 ` [PATCH v3 3/3] scsi: ufs: core: Add sysfs node for UFS RTC update Bean Huo
2023-12-06 19:39   ` Avri Altman
2023-12-06 17:08 ` [PATCH v3 0/3] Add UFS RTC support Bean Huo

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=DM6PR04MB657594BADE76428806210D3AFC86A@DM6PR04MB6575.namprd04.prod.outlook.com \
    --to=avri.altman@wdc.com \
    --cc=alim.akhtar@samsung.com \
    --cc=beanhuo@iokpp.de \
    --cc=beanhuo@micron.com \
    --cc=bvanassche@acm.org \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=lporzio@micron.com \
    --cc=mani@kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mikebi@micron.com \
    --cc=quic_asutoshd@quicinc.com \
    --cc=quic_cang@quicinc.com \
    --cc=thomas@t-8ch.de \
    /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®