All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arthur Simchaev <Arthur.Simchaev@wdc.com>
To: martin.petersen@oracle.com
Cc: beanhuo@micron.com, bvanassche@acm.org,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Arthur Simchaev <Arthur.Simchaev@wdc.com>
Subject: [PATCH 2/2] ufs: core: Providing Timestamp information to the device
Date: Wed, 22 Feb 2023 17:12:50 +0200	[thread overview]
Message-ID: <1677078770-30994-3-git-send-email-Arthur.Simchaev@wdc.com> (raw)
In-Reply-To: <1677078770-30994-1-git-send-email-Arthur.Simchaev@wdc.com>

The new qTimestamp attribute was added to UFS 4.0 spec, in order to
synchronize the timestamp between the host and the ufs device.
The spec recommend to send this attribute upon device power-on Reset/HW
reset or when switching to Active state (using SSU command)

Signed-off-by: Arthur Simchaev <Arthur.Simchaev@wdc.com>
---
 drivers/ufs/core/ufshcd.c | 36 ++++++++++++++++++++++++++++++++++++
 include/ufs/ufs.h         |  1 +
 2 files changed, 37 insertions(+)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index b08760d..22c29ff 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -8378,6 +8378,39 @@ static int ufshcd_device_params_init(struct ufs_hba *hba)
 	return ret;
 }
 
+static void ufshcd_set_timestamp_attr(struct ufs_hba *hba)
+{
+	int err;
+	struct ufs_query_req *request = NULL;
+	struct ufs_query_res *response = NULL;
+	struct ufs_dev_info *dev_info = &hba->dev_info;
+
+	if (dev_info->wspecversion < 0x400)
+		return;
+
+	ufshcd_hold(hba, false);
+
+	mutex_lock(&hba->dev_cmd.lock);
+
+	ufshcd_init_query(hba, &request, &response,
+			  UPIU_QUERY_OPCODE_WRITE_ATTR,
+			  QUERY_ATTR_IDN_TIMESTAMP, 0, 0);
+
+	request->query_func = UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST;
+
+	put_unaligned_be64(ktime_get_real_ns(), &request->upiu_req.osf3);
+
+	err = ufshcd_exec_dev_cmd(hba, DEV_CMD_TYPE_QUERY, QUERY_REQ_TIMEOUT);
+
+	if (err)
+		dev_err(hba->dev, "%s: failed to set timestamp %d\n",
+			__func__, err);
+
+	mutex_unlock(&hba->dev_cmd.lock);
+
+	ufshcd_release(hba);
+}
+
 /**
  * ufshcd_add_lus - probe and add UFS logical units
  * @hba: per-adapter instance
@@ -8547,6 +8580,8 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)
 	ufshcd_set_ufs_dev_active(hba);
 	ufshcd_force_reset_auto_bkops(hba);
 
+	ufshcd_set_timestamp_attr(hba);
+
 	/* Gear up to HS gear if supported */
 	if (hba->max_pwr_info.is_valid) {
 		/*
@@ -9566,6 +9601,7 @@ static int __ufshcd_wl_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 		ret = ufshcd_set_dev_pwr_mode(hba, UFS_ACTIVE_PWR_MODE);
 		if (ret)
 			goto set_old_link_state;
+		ufshcd_set_timestamp_attr(hba);
 	}
 
 	if (ufshcd_keep_autobkops_enabled_except_suspend(hba))
diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h
index 4e8d624..198cb39 100644
--- a/include/ufs/ufs.h
+++ b/include/ufs/ufs.h
@@ -170,6 +170,7 @@ enum attr_idn {
 	QUERY_ATTR_IDN_WB_BUFF_LIFE_TIME_EST    = 0x1E,
 	QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE        = 0x1F,
 	QUERY_ATTR_IDN_EXT_IID_EN		= 0x2A,
+	QUERY_ATTR_IDN_TIMESTAMP		= 0x30
 };
 
 /* Descriptor idn for Query requests */
-- 
2.7.4


      parent reply	other threads:[~2023-02-22 15:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-22 15:12 [PATCH 0/2] ufs: core: Add support for qTimestamp attribute Arthur Simchaev
2023-02-22 15:12 ` [PATCH 1/2] include: uapi: scsi: Change utp_upiu_query struct Arthur Simchaev
2023-02-22 15:25   ` Bart Van Assche
2023-02-27 16:03     ` Arthur Simchaev
2023-02-27 16:59       ` Bart Van Assche
2023-03-01  9:46         ` Arthur Simchaev
2023-03-01 18:44           ` Bart Van Assche
2023-03-02  7:52             ` Arthur Simchaev
2023-02-23  2:23   ` kernel test robot
2023-02-22 15:12 ` Arthur Simchaev [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=1677078770-30994-3-git-send-email-Arthur.Simchaev@wdc.com \
    --to=arthur.simchaev@wdc.com \
    --cc=beanhuo@micron.com \
    --cc=bvanassche@acm.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.