Skip to content

Commit 88e6804

Browse files
Bao D. Nguyenmartinkpetersen
authored andcommitted
scsi: ufs: core: Support Updating UIC Command Timeout
The default UIC command timeout still remains 500ms. Allow platform drivers to override the UIC command timeout if desired. In a real product, the 500ms timeout value is probably good enough. However, during the product development where there are a lot of logging and debug messages being printed to the UART console, interrupt starvations happen occasionally because the UART may print long debug messages from different modules in the system. While printing, the UART may have interrupts disabled for more than 500ms, causing UIC command timeout. The UIC command timeout would trigger more printing from the UFS driver, and eventually a watchdog timeout may occur unnecessarily. Add support for overriding the UIC command timeout value with the newly created uic_cmd_timeout kernel module parameter. Default value is 500ms. Supported values range from 500ms to 2 seconds. Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com> Link: https://lore.kernel.org/r/e4e1c87f3f867f270a3d4b5d57a00139ff0e9741.1721792309.git.quic_nguyenb@quicinc.com Suggested-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Reviewed-by: Peter Wang <peter.wang@mediatek.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 15f7b71 commit 88e6804

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

drivers/ufs/core/ufshcd.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151

5252

5353
/* UIC command timeout, unit: ms */
54-
#define UIC_CMD_TIMEOUT 500
55-
54+
enum {
55+
UIC_CMD_TIMEOUT_DEFAULT = 500,
56+
UIC_CMD_TIMEOUT_MAX = 2000,
57+
};
5658
/* NOP OUT retries waiting for NOP IN response */
5759
#define NOP_OUT_RETRIES 10
5860
/* Timeout after 50 msecs if NOP OUT hangs without response */
@@ -116,6 +118,23 @@ static bool is_mcq_supported(struct ufs_hba *hba)
116118
module_param(use_mcq_mode, bool, 0644);
117119
MODULE_PARM_DESC(use_mcq_mode, "Control MCQ mode for controllers starting from UFSHCI 4.0. 1 - enable MCQ, 0 - disable MCQ. MCQ is enabled by default");
118120

121+
static unsigned int uic_cmd_timeout = UIC_CMD_TIMEOUT_DEFAULT;
122+
123+
static int uic_cmd_timeout_set(const char *val, const struct kernel_param *kp)
124+
{
125+
return param_set_uint_minmax(val, kp, UIC_CMD_TIMEOUT_DEFAULT,
126+
UIC_CMD_TIMEOUT_MAX);
127+
}
128+
129+
static const struct kernel_param_ops uic_cmd_timeout_ops = {
130+
.set = uic_cmd_timeout_set,
131+
.get = param_get_uint,
132+
};
133+
134+
module_param_cb(uic_cmd_timeout, &uic_cmd_timeout_ops, &uic_cmd_timeout, 0644);
135+
MODULE_PARM_DESC(uic_cmd_timeout,
136+
"UFS UIC command timeout in milliseconds. Defaults to 500ms. Supported values range from 500ms to 2 seconds inclusively");
137+
119138
#define ufshcd_toggle_vreg(_dev, _vreg, _on) \
120139
({ \
121140
int _ret; \
@@ -2438,7 +2457,7 @@ static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba)
24382457
{
24392458
u32 val;
24402459
int ret = read_poll_timeout(ufshcd_readl, val, val & UIC_COMMAND_READY,
2441-
500, UIC_CMD_TIMEOUT * 1000, false, hba,
2460+
500, uic_cmd_timeout * 1000, false, hba,
24422461
REG_CONTROLLER_STATUS);
24432462
return ret == 0;
24442463
}
@@ -2498,7 +2517,7 @@ ufshcd_wait_for_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd)
24982517
lockdep_assert_held(&hba->uic_cmd_mutex);
24992518

25002519
if (wait_for_completion_timeout(&uic_cmd->done,
2501-
msecs_to_jiffies(UIC_CMD_TIMEOUT))) {
2520+
msecs_to_jiffies(uic_cmd_timeout))) {
25022521
ret = uic_cmd->argument2 & MASK_UIC_COMMAND_RESULT;
25032522
} else {
25042523
ret = -ETIMEDOUT;
@@ -4266,7 +4285,7 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd)
42664285
}
42674286

42684287
if (!wait_for_completion_timeout(hba->uic_async_done,
4269-
msecs_to_jiffies(UIC_CMD_TIMEOUT))) {
4288+
msecs_to_jiffies(uic_cmd_timeout))) {
42704289
dev_err(hba->dev,
42714290
"pwr ctrl cmd 0x%x with mode 0x%x completion timeout\n",
42724291
cmd->command, cmd->argument3);

0 commit comments

Comments
 (0)