Skip to content

Commit 8f9c938

Browse files
ptr324martinkpetersen
authored andcommitted
scsi: ufs: core: Support updating device command timeout
The default device command timeout remains 1.5 seconds, but platform drivers can override it if needed. Some UFS device commands may timeout due to being blocked by regular SCSI write commands. Therefore, the maximum timeout needs to be extended to 30 seconds, matching the SCSI write command timeout. And for error injection purposes, set the minimum value to 1 ms. Signed-off-by: Peter Wang <peter.wang@mediatek.com> Link: https://lore.kernel.org/r/20250510080345.595798-1-peter.wang@mediatek.com Suggested-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 8f6c52b commit 8f9c938

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

drivers/ufs/core/ufshcd.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ enum {
6363
/* Query request retries */
6464
#define QUERY_REQ_RETRIES 3
6565
/* Query request timeout */
66-
#define QUERY_REQ_TIMEOUT 1500 /* 1.5 seconds */
66+
enum {
67+
QUERY_REQ_TIMEOUT_MIN = 1,
68+
QUERY_REQ_TIMEOUT_DEFAULT = 1500,
69+
QUERY_REQ_TIMEOUT_MAX = 30000
70+
};
6771

6872
/* Advanced RPMB request timeout */
6973
#define ADVANCED_RPMB_REQ_TIMEOUT 3000 /* 3 seconds */
@@ -135,6 +139,23 @@ module_param_cb(uic_cmd_timeout, &uic_cmd_timeout_ops, &uic_cmd_timeout, 0644);
135139
MODULE_PARM_DESC(uic_cmd_timeout,
136140
"UFS UIC command timeout in milliseconds. Defaults to 500ms. Supported values range from 500ms to 5 seconds inclusively");
137141

142+
static unsigned int dev_cmd_timeout = QUERY_REQ_TIMEOUT_DEFAULT;
143+
144+
static int dev_cmd_timeout_set(const char *val, const struct kernel_param *kp)
145+
{
146+
return param_set_uint_minmax(val, kp, QUERY_REQ_TIMEOUT_MIN,
147+
QUERY_REQ_TIMEOUT_MAX);
148+
}
149+
150+
static const struct kernel_param_ops dev_cmd_timeout_ops = {
151+
.set = dev_cmd_timeout_set,
152+
.get = param_get_uint,
153+
};
154+
155+
module_param_cb(dev_cmd_timeout, &dev_cmd_timeout_ops, &dev_cmd_timeout, 0644);
156+
MODULE_PARM_DESC(dev_cmd_timeout,
157+
"UFS Device command timeout in milliseconds. Defaults to 1.5s. Supported values range from 1ms to 30 seconds inclusively");
158+
138159
#define ufshcd_toggle_vreg(_dev, _vreg, _on) \
139160
({ \
140161
int _ret; \
@@ -3362,7 +3383,7 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
33623383
struct ufs_query_req *request = NULL;
33633384
struct ufs_query_res *response = NULL;
33643385
int err, selector = 0;
3365-
int timeout = QUERY_REQ_TIMEOUT;
3386+
int timeout = dev_cmd_timeout;
33663387

33673388
BUG_ON(!hba);
33683389

@@ -3459,7 +3480,7 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
34593480
goto out_unlock;
34603481
}
34613482

3462-
err = ufshcd_exec_dev_cmd(hba, DEV_CMD_TYPE_QUERY, QUERY_REQ_TIMEOUT);
3483+
err = ufshcd_exec_dev_cmd(hba, DEV_CMD_TYPE_QUERY, dev_cmd_timeout);
34633484

34643485
if (err) {
34653486
dev_err(hba->dev, "%s: opcode 0x%.2x for idn %d failed, index %d, err = %d\n",
@@ -3555,7 +3576,7 @@ static int __ufshcd_query_descriptor(struct ufs_hba *hba,
35553576
goto out_unlock;
35563577
}
35573578

3558-
err = ufshcd_exec_dev_cmd(hba, DEV_CMD_TYPE_QUERY, QUERY_REQ_TIMEOUT);
3579+
err = ufshcd_exec_dev_cmd(hba, DEV_CMD_TYPE_QUERY, dev_cmd_timeout);
35593580

35603581
if (err) {
35613582
dev_err(hba->dev, "%s: opcode 0x%.2x for idn %d failed, index %d, err = %d\n",
@@ -6017,7 +6038,7 @@ int ufshcd_read_device_lvl_exception_id(struct ufs_hba *hba, u64 *exception_id)
60176038

60186039
request->query_func = UPIU_QUERY_FUNC_STANDARD_READ_REQUEST;
60196040

6020-
err = ufshcd_exec_dev_cmd(hba, DEV_CMD_TYPE_QUERY, QUERY_REQ_TIMEOUT);
6041+
err = ufshcd_exec_dev_cmd(hba, DEV_CMD_TYPE_QUERY, dev_cmd_timeout);
60216042

60226043
if (err) {
60236044
dev_err(hba->dev, "%s: failed to read device level exception %d\n",
@@ -7278,7 +7299,7 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba,
72787299
* bound to fail since dev_cmd.query and dev_cmd.type were left empty.
72797300
* read the response directly ignoring all errors.
72807301
*/
7281-
ufshcd_issue_dev_cmd(hba, lrbp, tag, QUERY_REQ_TIMEOUT);
7302+
ufshcd_issue_dev_cmd(hba, lrbp, tag, dev_cmd_timeout);
72827303

72837304
/* just copy the upiu response as it is */
72847305
memcpy(rsp_upiu, lrbp->ucd_rsp_ptr, sizeof(*rsp_upiu));
@@ -8716,7 +8737,7 @@ static void ufshcd_set_timestamp_attr(struct ufs_hba *hba)
87168737

87178738
put_unaligned_be64(ktime_get_real_ns(), &upiu_data->osf3);
87188739

8719-
err = ufshcd_exec_dev_cmd(hba, DEV_CMD_TYPE_QUERY, QUERY_REQ_TIMEOUT);
8740+
err = ufshcd_exec_dev_cmd(hba, DEV_CMD_TYPE_QUERY, dev_cmd_timeout);
87208741

87218742
if (err)
87228743
dev_err(hba->dev, "%s: failed to set timestamp %d\n",

0 commit comments

Comments
 (0)