Skip to content

Commit 24befa9

Browse files
scsi: ufs: core: Add support for qTimestamp attribute
The new qTimestamp attribute was added to UFS 4.0 spec, in order to synchronize timestamp between device logs and the host. The spec recommends 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 Link: https://lore.kernel.org/r/20230626103320.8737-1-arthur.simchaev@wdc.com Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 47699a2 commit 24befa9

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

drivers/ufs/core/ufshcd.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8520,6 +8520,41 @@ static int ufshcd_device_params_init(struct ufs_hba *hba)
85208520
return ret;
85218521
}
85228522

8523+
static void ufshcd_set_timestamp_attr(struct ufs_hba *hba)
8524+
{
8525+
int err;
8526+
struct ufs_query_req *request = NULL;
8527+
struct ufs_query_res *response = NULL;
8528+
struct ufs_dev_info *dev_info = &hba->dev_info;
8529+
struct utp_upiu_query_v4_0 *upiu_data;
8530+
8531+
if (dev_info->wspecversion < 0x400)
8532+
return;
8533+
8534+
ufshcd_hold(hba);
8535+
8536+
mutex_lock(&hba->dev_cmd.lock);
8537+
8538+
ufshcd_init_query(hba, &request, &response,
8539+
UPIU_QUERY_OPCODE_WRITE_ATTR,
8540+
QUERY_ATTR_IDN_TIMESTAMP, 0, 0);
8541+
8542+
request->query_func = UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST;
8543+
8544+
upiu_data = (struct utp_upiu_query_v4_0 *)&request->upiu_req;
8545+
8546+
put_unaligned_be64(ktime_get_real_ns(), &upiu_data->osf3);
8547+
8548+
err = ufshcd_exec_dev_cmd(hba, DEV_CMD_TYPE_QUERY, QUERY_REQ_TIMEOUT);
8549+
8550+
if (err)
8551+
dev_err(hba->dev, "%s: failed to set timestamp %d\n",
8552+
__func__, err);
8553+
8554+
mutex_unlock(&hba->dev_cmd.lock);
8555+
ufshcd_release(hba);
8556+
}
8557+
85238558
/**
85248559
* ufshcd_add_lus - probe and add UFS logical units
85258560
* @hba: per-adapter instance
@@ -8708,6 +8743,8 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)
87088743
ufshcd_set_ufs_dev_active(hba);
87098744
ufshcd_force_reset_auto_bkops(hba);
87108745

8746+
ufshcd_set_timestamp_attr(hba);
8747+
87118748
/* Gear up to HS gear if supported */
87128749
if (hba->max_pwr_info.is_valid) {
87138750
/*
@@ -9741,6 +9778,7 @@ static int __ufshcd_wl_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)
97419778
ret = ufshcd_set_dev_pwr_mode(hba, UFS_ACTIVE_PWR_MODE);
97429779
if (ret)
97439780
goto set_old_link_state;
9781+
ufshcd_set_timestamp_attr(hba);
97449782
}
97459783

97469784
if (ufshcd_keep_autobkops_enabled_except_suspend(hba))

include/uapi/scsi/scsi_bsg_ufs.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,31 @@ struct utp_upiu_query {
7070
__be32 reserved[2];
7171
};
7272

73+
/**
74+
* struct utp_upiu_query_v4_0 - upiu request buffer structure for
75+
* query request >= UFS 4.0 spec.
76+
* @opcode: command to perform B-0
77+
* @idn: a value that indicates the particular type of data B-1
78+
* @index: Index to further identify data B-2
79+
* @selector: Index to further identify data B-3
80+
* @osf4: spec field B-5
81+
* @osf5: spec field B 6,7
82+
* @osf6: spec field DW 8,9
83+
* @osf7: spec field DW 10,11
84+
*/
85+
struct utp_upiu_query_v4_0 {
86+
__u8 opcode;
87+
__u8 idn;
88+
__u8 index;
89+
__u8 selector;
90+
__u8 osf3;
91+
__u8 osf4;
92+
__be16 osf5;
93+
__be32 osf6;
94+
__be32 osf7;
95+
__be32 reserved;
96+
};
97+
7398
/**
7499
* struct utp_upiu_cmd - Command UPIU structure
75100
* @data_transfer_len: Data Transfer Length DW-3

include/ufs/ufs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ enum attr_idn {
170170
QUERY_ATTR_IDN_WB_BUFF_LIFE_TIME_EST = 0x1E,
171171
QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE = 0x1F,
172172
QUERY_ATTR_IDN_EXT_IID_EN = 0x2A,
173+
QUERY_ATTR_IDN_TIMESTAMP = 0x30
173174
};
174175

175176
/* Descriptor idn for Query requests */

0 commit comments

Comments
 (0)