linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND v2] ufs: core: Add support for qTimestamp attribute
@ 2023-06-26 10:33 Arthur Simchaev
  2023-06-26 12:36 ` Bean Huo
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Arthur Simchaev @ 2023-06-26 10:33 UTC (permalink / raw)
  To: martin.petersen
  Cc: avri.altman, Avi.Shchislowski, beanhuo, linux-scsi, linux-kernel,
	bvanassche, Arthur Simchaev

From: Arthur Simchaev <Arthur.Simchaev@wdc.com>

The new qTimestamp attribute was added to UFS 4.0 spec, in order to
synchronize timestamp between device logs and the host.The spec recommend
to send this attribute upon device power-on Reset/HW reset or when
switching to Active state (using SSU command). Due to this attribute,
the attribute's max value was extended to 8 bytes. As a result,
the new definition of struct utp_upiu_query_v4_0 was added.

Signed-off-by: Arthur Simchaev <Arthur.Simchaev@wdc.com>

-----------------
Changes to v2:
- Adressed Bart's comments
- Add missed response variable to ufshcd_set_timestamp_attr
---
 drivers/ufs/core/ufshcd.c        | 38 ++++++++++++++++++++++++++++++++
 include/uapi/scsi/scsi_bsg_ufs.h | 25 +++++++++++++++++++++
 include/ufs/ufs.h                |  1 +
 3 files changed, 64 insertions(+)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 358b3240b6c5..e2812911e462 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -8520,6 +8520,41 @@ 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;
+	struct utp_upiu_query_v4_0 *upiu_data;
+
+	if (dev_info->wspecversion < 0x400)
+		return;
+
+	ufshcd_hold(hba);
+
+	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;
+
+	upiu_data = (struct utp_upiu_query_v4_0 *)&request->upiu_req;
+
+	put_unaligned_be64(ktime_get_real_ns(), &upiu_data->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
@@ -8708,6 +8743,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) {
 		/*
@@ -9741,6 +9778,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/uapi/scsi/scsi_bsg_ufs.h b/include/uapi/scsi/scsi_bsg_ufs.h
index 2801b65299aa..fd3f9e5ee241 100644
--- a/include/uapi/scsi/scsi_bsg_ufs.h
+++ b/include/uapi/scsi/scsi_bsg_ufs.h
@@ -70,6 +70,31 @@ struct utp_upiu_query {
 	__be32 reserved[2];
 };
 
+/**
+ * struct utp_upiu_query_v4_0 - upiu request buffer structure for
+ * query request >= UFS 4.0 spec.
+ * @opcode: command to perform B-0
+ * @idn: a value that indicates the particular type of data B-1
+ * @index: Index to further identify data B-2
+ * @selector: Index to further identify data B-3
+ * @osf4: spec field B-5
+ * @osf5: spec field B 6,7
+ * @osf6: spec field DW 8,9
+ * @osf7: spec field DW 10,11
+ */
+struct utp_upiu_query_v4_0 {
+	__u8 opcode;
+	__u8 idn;
+	__u8 index;
+	__u8 selector;
+	__u8 osf3;
+	__u8 osf4;
+	__be16 osf5;
+	__be32 osf6;
+	__be32 osf7;
+	__be32 reserved;
+};
+
 /**
  * struct utp_upiu_cmd - Command UPIU structure
  * @data_transfer_len: Data Transfer Length DW-3
diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h
index 4e8d6240e589..198cb391f9db 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.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [RESEND v2] ufs: core: Add support for qTimestamp attribute
  2023-06-26 10:33 [RESEND v2] ufs: core: Add support for qTimestamp attribute Arthur Simchaev
@ 2023-06-26 12:36 ` Bean Huo
  2023-06-27 11:22   ` Arthur Simchaev
  2023-06-28 22:50 ` Bart Van Assche
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Bean Huo @ 2023-06-26 12:36 UTC (permalink / raw)
  To: Arthur Simchaev, martin.petersen
  Cc: avri.altman, Avi.Shchislowski, beanhuo, linux-scsi, linux-kernel,
	bvanassche

On Mon, 2023-06-26 at 13:33 +0300, Arthur Simchaev wrote:
>  
> +/**
> + * struct utp_upiu_query_v4_0 - upiu request buffer structure for
> + * query request >= UFS 4.0 spec.
> + * @opcode: command to perform B-0
> + * @idn: a value that indicates the particular type of data B-1
> + * @index: Index to further identify data B-2
> + * @selector: Index to further identify data B-3
> + * @osf4: spec field B-5
> + * @osf5: spec field B 6,7
> + * @osf6: spec field DW 8,9
> + * @osf7: spec field DW 10,11
> + */
> +struct utp_upiu_query_v4_0 {
> +       __u8 opcode;
> +       __u8 idn;
> +       __u8 index;
> +       __u8 selector;
> +       __u8 osf3;
> +       __u8 osf4;
> +       __be16 osf5;
> +       __be32 osf6;
> +       __be32 osf7;
> +       __be32 reserved;
> +};

Hi Arthur,
In fact, this structure should be a "Transaction Specific Fields" in
Query UPIU for all query functions. By comparing 3.1 and 4.0, you can
use current utp_upiu_query{}, because you only want to pass 64bit TS.
Or you can change utp_upiu_query() to make it more uniform to meet
various query functions.

Kind regards,
Bean

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [RESEND v2] ufs: core: Add support for qTimestamp attribute
  2023-06-26 12:36 ` Bean Huo
@ 2023-06-27 11:22   ` Arthur Simchaev
  0 siblings, 0 replies; 9+ messages in thread
From: Arthur Simchaev @ 2023-06-27 11:22 UTC (permalink / raw)
  To: Bean Huo, martin.petersen
  Cc: Avri Altman, Avi Shchislowski, beanhuo, linux-scsi, linux-kernel,
	bvanassche

> 
> Hi Arthur,
> In fact, this structure should be a "Transaction Specific Fields" in
> Query UPIU for all query functions. By comparing 3.1 and 4.0, you can
> use current utp_upiu_query{}, because you only want to pass 64bit TS.
> Or you can change utp_upiu_query() to make it more uniform to meet
> various query functions.
>
Hi Bean

Actually, in the initial set of patches I changed utp_upiu_query , since the struct defined incorrectly
and I want to change it according to the spec, but according to Bart's comment,
the struct cannot be changed since the definition is in uapi . 
See the initial patch sets in the link below:

https://www.spinics.net/lists/linux-scsi/msg181985.html
https://www.spinics.net/lists/linux-scsi/msg182178.html
https://www.spinics.net/lists/linux-scsi/msg181987.html

Please let me know what you think.

Regards
Arthur


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RESEND v2] ufs: core: Add support for qTimestamp attribute
  2023-06-26 10:33 [RESEND v2] ufs: core: Add support for qTimestamp attribute Arthur Simchaev
  2023-06-26 12:36 ` Bean Huo
@ 2023-06-28 22:50 ` Bart Van Assche
  2023-06-29 13:58   ` Arthur Simchaev
  2023-07-05 21:13 ` Bart Van Assche
  2023-07-11 16:31 ` Martin K. Petersen
  3 siblings, 1 reply; 9+ messages in thread
From: Bart Van Assche @ 2023-06-28 22:50 UTC (permalink / raw)
  To: Arthur Simchaev, martin.petersen
  Cc: avri.altman, Avi.Shchislowski, beanhuo, linux-scsi, linux-kernel

On 6/26/23 03:33, Arthur Simchaev wrote:
> +/**
> + * struct utp_upiu_query_v4_0 - upiu request buffer structure for
> + * query request >= UFS 4.0 spec.
> + * @opcode: command to perform B-0
> + * @idn: a value that indicates the particular type of data B-1
> + * @index: Index to further identify data B-2
> + * @selector: Index to further identify data B-3
> + * @osf4: spec field B-5
> + * @osf5: spec field B 6,7
> + * @osf6: spec field DW 8,9
> + * @osf7: spec field DW 10,11
> + */
> +struct utp_upiu_query_v4_0 {
> +	__u8 opcode;
> +	__u8 idn;
> +	__u8 index;
> +	__u8 selector;
> +	__u8 osf3;
> +	__u8 osf4;
> +	__be16 osf5;
> +	__be32 osf6;
> +	__be32 osf7;
> +	__be32 reserved;
> +};

Is this structure useful for user space software? If not, please move it 
into another header file.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [RESEND v2] ufs: core: Add support for qTimestamp attribute
  2023-06-28 22:50 ` Bart Van Assche
@ 2023-06-29 13:58   ` Arthur Simchaev
  2023-07-05 10:02     ` Arthur Simchaev
  0 siblings, 1 reply; 9+ messages in thread
From: Arthur Simchaev @ 2023-06-29 13:58 UTC (permalink / raw)
  To: Bart Van Assche, martin.petersen
  Cc: Avri Altman, Avi Shchislowski, beanhuo, linux-scsi, linux-kernel

> Is this structure useful for user space software? If not, please move it
> into another header file.
Hi Bart

The struct is useful for user space software.
For example, the specific timestamp can be sent by ufs-utils utility to the device.

Regards
Arthur


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [RESEND v2] ufs: core: Add support for qTimestamp attribute
  2023-06-29 13:58   ` Arthur Simchaev
@ 2023-07-05 10:02     ` Arthur Simchaev
  0 siblings, 0 replies; 9+ messages in thread
From: Arthur Simchaev @ 2023-07-05 10:02 UTC (permalink / raw)
  To: Arthur Simchaev, Bart Van Assche, martin.petersen
  Cc: Avri Altman, Avi Shchislowski, beanhuo, linux-scsi, linux-kernel

Hi Bart

Is the patch, OK?
Or do you have additional comments?

Regards
Arthur

> -----Original Message-----
> From: Arthur Simchaev <Arthur.Simchaev@wdc.com>
> Sent: Thursday, June 29, 2023 4:59 PM
> To: Bart Van Assche <bvanassche@acm.org>; martin.petersen@oracle.com
> Cc: Avri Altman <Avri.Altman@wdc.com>; Avi Shchislowski
> <Avi.Shchislowski@wdc.com>; beanhuo@micron.com; linux-
> scsi@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: RE: [RESEND v2] ufs: core: Add support for qTimestamp attribute
> 
> CAUTION: This email originated from outside of Western Digital. Do not click
> on links or open attachments unless you recognize the sender and know that
> the content is safe.
> 
> 
> > Is this structure useful for user space software? If not, please move it
> > into another header file.
> Hi Bart
> 
> The struct is useful for user space software.
> For example, the specific timestamp can be sent by ufs-utils utility to the
> device.
> 
> Regards
> Arthur


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RESEND v2] ufs: core: Add support for qTimestamp attribute
  2023-06-26 10:33 [RESEND v2] ufs: core: Add support for qTimestamp attribute Arthur Simchaev
  2023-06-26 12:36 ` Bean Huo
  2023-06-28 22:50 ` Bart Van Assche
@ 2023-07-05 21:13 ` Bart Van Assche
  2023-07-06  1:44   ` Martin K. Petersen
  2023-07-11 16:31 ` Martin K. Petersen
  3 siblings, 1 reply; 9+ messages in thread
From: Bart Van Assche @ 2023-07-05 21:13 UTC (permalink / raw)
  To: Arthur Simchaev, martin.petersen
  Cc: avri.altman, Avi.Shchislowski, beanhuo, linux-scsi, linux-kernel

On 6/26/23 03:33, Arthur Simchaev wrote:
> The new qTimestamp attribute was added to UFS 4.0 spec, in order to
> synchronize timestamp between device logs and the host.The spec recommend
> to send this attribute upon device power-on Reset/HW reset or when
> switching to Active state (using SSU command). Due to this attribute,
> the attribute's max value was extended to 8 bytes. As a result,
> the new definition of struct utp_upiu_query_v4_0 was added.


Reviewed-by: Bart Van Assche <bvanassche@acm.org>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RESEND v2] ufs: core: Add support for qTimestamp attribute
  2023-07-05 21:13 ` Bart Van Assche
@ 2023-07-06  1:44   ` Martin K. Petersen
  0 siblings, 0 replies; 9+ messages in thread
From: Martin K. Petersen @ 2023-07-06  1:44 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Arthur Simchaev, martin.petersen, avri.altman, Avi.Shchislowski,
	beanhuo, linux-scsi, linux-kernel


Bart,

>> The new qTimestamp attribute was added to UFS 4.0 spec, in order to
>> synchronize timestamp between device logs and the host.The spec recommend
>> to send this attribute upon device power-on Reset/HW reset or when
>> switching to Active state (using SSU command). Due to this attribute,
>> the attribute's max value was extended to 8 bytes. As a result,
>> the new definition of struct utp_upiu_query_v4_0 was added.
>
> Reviewed-by: Bart Van Assche <bvanassche@acm.org>

Applied to 6.5/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RESEND v2] ufs: core: Add support for qTimestamp attribute
  2023-06-26 10:33 [RESEND v2] ufs: core: Add support for qTimestamp attribute Arthur Simchaev
                   ` (2 preceding siblings ...)
  2023-07-05 21:13 ` Bart Van Assche
@ 2023-07-11 16:31 ` Martin K. Petersen
  3 siblings, 0 replies; 9+ messages in thread
From: Martin K. Petersen @ 2023-07-11 16:31 UTC (permalink / raw)
  To: Arthur Simchaev
  Cc: Martin K . Petersen, avri.altman, Avi.Shchislowski, beanhuo,
	linux-scsi, linux-kernel, bvanassche, Arthur Simchaev

On Mon, 26 Jun 2023 13:33:19 +0300, Arthur Simchaev wrote:

> The new qTimestamp attribute was added to UFS 4.0 spec, in order to
> synchronize timestamp between device logs and the host.The spec recommend
> to send this attribute upon device power-on Reset/HW reset or when
> switching to Active state (using SSU command). Due to this attribute,
> the attribute's max value was extended to 8 bytes. As a result,
> the new definition of struct utp_upiu_query_v4_0 was added.
> 
> [...]

Applied to 6.5/scsi-fixes, thanks!

[1/1] ufs: core: Add support for qTimestamp attribute
      https://git.kernel.org/mkp/scsi/c/24befa92ed47

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-07-11 16:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-26 10:33 [RESEND v2] ufs: core: Add support for qTimestamp attribute Arthur Simchaev
2023-06-26 12:36 ` Bean Huo
2023-06-27 11:22   ` Arthur Simchaev
2023-06-28 22:50 ` Bart Van Assche
2023-06-29 13:58   ` Arthur Simchaev
2023-07-05 10:02     ` Arthur Simchaev
2023-07-05 21:13 ` Bart Van Assche
2023-07-06  1:44   ` Martin K. Petersen
2023-07-11 16:31 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).