UFS: Make TM command timeout configurable from host side
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): CGME20251106012702epcas1p28fdeed020ea44f18dcc751c283fbbcc2@epcas1p2.samsung.com
PATCH 1/1 UFS: Make TM command timeout configurable from host side
Currently, UFS driver uses hardcoded TM_CMD_TIMEOUT (100ms) for all Task Management commands, which may not be optimal for different UFS devices and use cases.
This patch adds a configurable tm_cmd_timeout field to ufs_hba structure and uses it instead of the hardcoded constant. The default value remains TM_CMD_TIMEOUT to maintain backward compatibility.
[ 90.372004] [1: kworker/u16:1: 10] ufshcd-qcom 1d84000.ufshc: ufshcd_abort: Device abort task at tag 9 [ 90.372025] [1: kworker/u16:1: 10] ufshcd-qcom 1d84000.ufshc: UPIU[9] - issue time 80324520 us [ 90.372037] [1: kworker/u16:1: 10] ufshcd-qcom 1d84000.ufshc: UPIU[9] - complete time 0 us [ 90.372049] [1: kworker/u16:1: 10] ufshcd-qcom 1d84000.ufshc: UPIU[9] - Transfer Request Descriptor phys@0x28120 [ 90.372085] [1: kworker/u16:1: 10] ufshcd-qcom 1d84000.ufshc: UPIU[9] - Request UPIU phys@0xb400 [ 90.372121] [1: kworker/u16:1: 10] ufshcd-qcom 1d84000.ufshc: UPIU[9] - Response UPIU phys@0xb600 [ 90.372180] [1: kworker/u16:1: 10] ufshcd-qcom 1d84000.ufshc: UPIU[9] - PRDT - 2 entries phys@0xb800 [ 90.372193] [1: kworker/u16:1: 10] ufshcd-qcom 1d84000.ufshc: ufshcd_abort: skipping abort [ 90.514494] [0: scsi_eh_0: 209] ufshcd-qcom 1d84000.ufshc: __ufshcd_issue_tm_cmd: task management cmd 0x08 timed-out
--- drivers/ufs/core/ufshcd.c | 3 ++- include/ufs/ufshcd.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +2 -1
@@ -7252,7 +7252,7 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba,/* wait until the task management command is completed */ err =wait_for_completion_io_timeout (&wait, -msecs_to_jiffies (TM_CMD_TIMEOUT )); +msecs_to_jiffies (hba->tm_cmd_timeout));if (!err) {ufshcd_add_tm_upiu_trace (hba, task_tag,UFS_TM_ERR ); dev_err(hba->dev, "%s: task management cmd 0x%.2x timed-out\n",
@@ -10565,6 +10565,7 @@ int ufshcd_alloc_host(struct device *dev, struct ufs_hba **hba_handle) hba->dev = dev; hba->dev_ref_clk_freq =REF_CLK_FREQ_INVAL ; hba->nop_out_timeout =NOP_OUT_TIMEOUT ; + hba->tm_cmd_timeout =TM_CMD_TIMEOUT ;ufshcd_set_sg_entry_size (hba,sizeof (struct ufshcd_sg_entry ));INIT_LIST_HEAD (&hba->clk_list_head);spin_lock_init (&hba->outstanding_lock);
include/ufs/ufshcd.h +2 -0
@@ -884,6 +884,7 @@ enum ufshcd_mcq_opr {* @dev_cmd: ufs device management command information * @last_dme_cmd_tstamp: time stamp of the last completed DME command * @nop_out_timeout: NOP OUT timeout value +* @tm_cmd_timeout: TM CMD timeout value * @dev_info: information about the UFS device * @auto_bkops_enabled: to track whether bkops is enabled in device * @vreg_info: UFS device voltage regulator information
@@ -1042,6 +1043,7 @@ struct ufs_hba {struct ufs_dev_cmd dev_cmd;ktime_t last_dme_cmd_tstamp;int nop_out_timeout; +int tm_cmd_timeout;/* Keeps information of the UFS device connected to this host */ struct ufs_dev_info dev_info;
Signature · 1 line
2.43.0
Quoted 9 lines · Seunghui Lee
Currently, UFS driver uses hardcoded
TM_CMD_TIMEOUT(100ms) for all Task Management commands, which may not be optimal for different UFS devices and use cases.This patch adds a configurable
tm_cmd_timeoutfield toufs_hbastructure
and uses it instead of the hardcoded constant. The default value remainsTM_CMD_TIMEOUTto maintain backward compatibility.
Hi Seunghui,
There should be another patch to add a device quirk that modifies the value of tm_cmd_timeout? Otherwise, this patch doesn’t actually change anything.
Thanks.
Peter
Quoted 19 lines
-----Original Message-----
From: Peter Wang (王信友) <[email protected]>
Sent: Tuesday, November 11, 2025 11:46 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] UFS: Make TM command timeout configurable from host sideQuoted 7 lines · Seunghui Lee
Currently, UFS driver uses hardcoded
TM_CMD_TIMEOUT(100ms) for all Task Management commands, which may not be optimal for different UFS devices and use cases.This patch adds a configurable
tm_cmd_timeoutfield toufs_hbastructure and uses it instead of the hardcoded constant. The default value remainsTM_CMD_TIMEOUTto maintain backward compatibility.
Quoted 9 lines
Hi Seunghui,
There should be another patch to add a device quirk that modifies the value of
tm_cmd_timeout?
Otherwise, this patch doesn’t actually change anything.Thanks.
Peter
Thank you for your kind opinion.
As you know, it's not easy to modify default value. Because it effects all devices.
Should I read the tm_cmd_timeout from dt property? What do you think?
* drivers/ufs/host/ufhcd-pltfrm.c
static void ufshcd_init_tm_cmd_timeout(struct ufs_hba *hba)
{
struct device *dev = hba->dev;
int ret;
ret = of_property_read_u32(dev->of_node, "tm_cmd_timeout",
&hba->tm_cmd_timeout);
if (ret) {
dev_dbg(hba->dev,
"%s: failed to read tm_cmd_timeout, ret=%d\n",
__func__, ret);
hba->tm_cmd_timeout = TM_CMD_TIMEOUT;
}
}Thanks,
Seunghui Lee.
Quoted 27 lines · Seunghui Lee
Thank you for your kind opinion.
As you know, it's not easy to modify default value. Because it effects all devices.Should I read the
tm_cmd_timeoutfrom dt property? What do you think?*
drivers/ufs/host/ufhcd-pltfrm.cstatic void
ufshcd_init_tm_cmd_timeout(struct ufs_hba *hba){
struct device *dev =hba->dev;
int ret;ret =
of_property_read_u32(dev->of_node, "tm_cmd_timeout", &hba->tm_cmd_timeout);
if (ret) {
dev_dbg(hba->dev,
"%s: failed to readtm_cmd_timeout, ret=%d\n",
__func__, ret);hba->tm_cmd_timeout=TM_CMD_TIMEOUT;
}
}
Quoted 3 lines
Thanks,
Seunghui Lee.
Hi Seunghui,
It seems that there is no node in the DTS to describe the UFS device. The UFS host node is not suitable, because the timeout value depends on the UFS device itself.
Since you found that some devices may have TM command times exceeding 100ms, why not add a device quirk and change the timeout value only for those devices?
Alternatively, you could consider using a module parameter, similar to uic_cmd_timeout and dev_cmd_timeout.
Thanks.
Peter
Bart Van Assche
reviewerQuoted 10 lines · Peter Wang (王信友)
It seems that there is no node in the DTS to describe the UFS device. The UFS host node is not suitable, because the timeout value depends on the UFS device itself.
Since you found that some devices may have TM command times exceeding 100ms, why not add a device quirk and change the timeout value only for those devices?
Alternatively, you could consider using a module parameter, similar to
uic_cmd_timeoutanddev_cmd_timeout.
Why a quirk? A quirk will select a single specific timeout. The approach of this patch lets the host driver set the timeout. This seems more flexible to me than introducing a new quirk. Additionally, I think this is a better solution than a new kernel module parameter.
Thanks,
Bart.
Quoted 11 lines · Bart Van Assche
Why a quirk? A quirk will select a single specific timeout. The approach
of this patch lets the host driver set the timeout. This seems more flexible to me than introducing a new quirk. Additionally, I think this
is a better solution than a new kernel module parameter.Thanks,
Bart.
Hi Bart,
It is not reasonable because the timeout value does not depend on the host, it depends on the device. It could set a large timoeut value for those devices.
By the way, this patch also doesn't change any host timeout value if you insist that the timeout value depends on the host.
Using a module parameter is a flexible method if the customer is using a device that may require an extended timeout value. Moreover, this approach would help maintain consistency. Otherwise, with so many different timeouts (uic/dev/tm), it would be quite chaotic if each is handled in a different way.
Thanks
Peter
Quoted 30 lines
-----Original Message-----
From: Peter Wang (王信友) <[email protected]>
Sent: Wednesday, November 12, 2025 11:58 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] UFS: Make TM command timeout configurable from host sideQuoted 9 lines · Bart Van Assche
Why a quirk? A quirk will select a single specific timeout. The approach of this patch lets the host driver set the timeout. This seems more flexible to me than introducing a new quirk. Additionally, I think this is a better solution than a new kernel module parameter.
Thanks,
Bart.
Hi Bart,
It is not reasonable because the timeout value does not depend on the host, it depends on the device. It could set a large timoeut value for those devices.
By the way, this patch also doesn't change any host timeout value if you insist that the timeout value depends on the host.
Quoted 8 lines
Using a module parameter is a flexible method if the customer is using a device that may require an extended timeout value.
Moreover, this approach would help maintain consistency. Otherwise, with so many different timeouts (uic/dev/tm), it would be quite chaotic if each is handled in a different way.Thanks
Peter
Hi Peter,
Currently, the modification is about changing it in the same way as nop_out_timeout.
The tm_cmd_timeout value is not read from the device.
Also, if the UFS can read the tm_cmd_timeout value and requires a longer timeout period than the specified value, dev quirks would also be acceptable.
However, for now, it seems fine to set it on the host.
When we checked on our side, it wasn't that the tm timeout value was insufficient for specific devices, but rather some vendors needed to increase it.
We plan to appropriately increase and use it. Also, since the current modification maintains the default value and allows an appropriate value to be adjusted according to each vendor, the current method also seems acceptable.
Thank you,
Seunghui Lee.
Quoted 19 lines · Seunghui Lee
Hi Peter,
Currently, the modification is about changing it in the same way as
nop_out_timeout.
Thetm_cmd_timeoutvalue is not read from the device. Also, if the UFS can read thetm_cmd_timeoutvalue and requires a longer timeout period than the specified value, dev quirks would also be acceptable.However, for now, it seems fine to set it on the host. When we checked on our side, it wasn't that the tm timeout value was insufficient for specific devices, but rather some vendors needed to increase it.
We plan to appropriately increase and use it. Also, since the current modification maintains the default value and allows an appropriate value to be adjusted according to each vendor, the current method also seems acceptable.
Quoted 3 lines
Thank you,
Seunghui Lee.
Hi Seunghui,
The nop_out_timeout value can be changed by the host, as shown here:
https://lore.kernel.org/all/[email protected]/
(hba->nop_out_timeout = 200;)
However, in this patch, no one sets tm_cmd_timeout, correct? So, I am saying that this patch doesn’t actually change anything, because the timeout is still 100ms for all hosts.
Thanks
Peter
Bart Van Assche
reviewerQuoted 2 lines · Peter Wang (王信友)
Using a module parameter is a flexible method if the customer is using a device that may require an extended timeout value.
Introducing a new kernel module parameter for a timeout that depends on the UFS device model doesn't sound ideal to me.
Can't we increase the default timeout (TM_CMD_TIMEOUT)? Increasing the default timeout shouldn't affect any configuration negatively, isn't it?
Thanks,
Bart.
Quoted 6 lines · Bart Van Assche
Can't we increase the default timeout (
TM_CMD_TIMEOUT)? Increasing the
default timeout shouldn't affect any configuration negatively, isn't it?
Hi Bart,
In the worst-case scenario (when the device is stuck), it may takes 1.1 seconds to abort a single task. When the queue is full (64), there will be noticeable lag. Aborting all tasks can take over a minute, which is unacceptable regardless of whether TM_CMD_TIMEOUT is increased or not. Under normal conditions, it’s very unlikely to exceed 100ms. So I think directly modifying TM_CMD_TIMEOUT is also acceptable, but I suggest keeping it within 500ms.
However, the optimal solution is for the vendor to update the firmware, ensuring that TM command priority is set appropriately to prevent situations where it exceeds 100ms.
Thanks
Peter
Quoted 27 lines
-----Original Message-----
From: Peter Wang (王信友) <[email protected]>
Sent: Thursday, November 13, 2025 7:09 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] UFS: Make TM command timeout configurable from host sideQuoted 5 lines · Bart Van Assche
Can't we increase the default timeout (
TM_CMD_TIMEOUT)? Increasing the default timeout shouldn't affect any configuration negatively, isn't it?Hi Bart,
In the worst-case scenario (when the device is stuck), it may takes 1.1 seconds to abort a single task. When the queue is full (64), there will be noticeable lag. Aborting all tasks can take over a minute, which is unacceptable regardless of whether
TM_CMD_TIMEOUTis increased or not. Under normal conditions, it’s very unlikely to exceed 100ms. So I think directly modifyingTM_CMD_TIMEOUTis also acceptable, but I suggest keeping it within 500ms.
Quoted 6 lines
However, the optimal solution is for the vendor to update the firmware, ensuring that TM command priority is set appropriately to prevent situations where it exceeds 100ms.
Thanks
Peter
Hi Mr.Wang,
I understand your concerns about considering the worst-case scenario. What about directly modifying TM_CMD_TIMEOUT (100ms -> 300ms) and reducing the TM retry count from 100 to 30?
Please let me know your opinion.
Thank you,
Seunghui Lee.
drivers/ufs/core/ufshcd.c +2 -2
@@ -68,7 +68,7 @@ enum {#define ADVANCED_RPMB_REQ_TIMEOUT 3000/* 3 seconds */ /* Task management command timeout */ -#define TM_CMD_TIMEOUT 100/* msecs */ +#define TM_CMD_TIMEOUT 300/* msecs */ /* maximum number of retries for a general UIC command */ #define UFS_UIC_COMMAND_RETRIES 3
@@ -7663,7 +7663,7 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)int poll_cnt;u8 resp =0xF ; -for (poll_cnt =100 ; poll_cnt; poll_cnt--) { +for (poll_cnt =30 ; poll_cnt; poll_cnt--) { err =ufshcd_issue_tm_cmd (hba, lrbp->lun, lrbp->task_tag,UFS_QUERY_TASK , &resp);if (!err && resp ==UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED ) {
Quoted 8 lines · Seunghui Lee
Hi Mr.Wang,
I understand your concerns about considering the worst-case scenario. What about directly modifying
TM_CMD_TIMEOUT(100ms -> 300ms) and reducing the TM retry count from 100 to 30?Please let me know your opinion.
Hi Seunghui,
Changing TM_CMD_TIMEOUT from 100ms to 300ms is okay for me. The adjustment of the TM retry count from 100 to 30 is not significant, so it does not matter whether this change is made or not. Overall, this patch looks good to me.
However, the other TM clear timeout of 1 second has a much greater impact:
ufshcd_wait_for_register(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL,
mask, ~mask, 1000, 1000);
Would you consider shortening this value as well?
Thanks
Peter
Quoted 29 lines
Thank you,
Seunghui Lee.drivers/ufs/core/ufshcd.c +2
-2@@ -68,7 +68,7 @@ enum { #define ADVANCED_RPMB_REQ_TIMEOUT 3000 /* 3 seconds */ /* Task management command timeout */ -#define TM_CMD_TIMEOUT 100/* msecs */ +#define TM_CMD_TIMEOUT 300/* msecs */ /* maximum number of retries for a general UIC command */ #define UFS_UIC_COMMAND_RETRIES 3@@ -7663,7 +7663,7 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag) int poll_cnt; u8 resp = 0xF; - for (poll_cnt = 100; poll_cnt; poll_cnt--) { + for (poll_cnt = 30; poll_cnt; poll_cnt--) {err = ufshcd_issue_tm_cmd(hba,
lrbp->lun, lrbp-Quoted 1 line
task_tag,
UFS_QUERY_TASK, &resp); if (!err && resp ==UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED) {
Quoted 11 lines · Seunghui Lee
Quoted 8 lines
Hi Mr.Wang,
I understand your concerns about considering the worst-case scenario. What about directly modifying
TM_CMD_TIMEOUT(100ms -> 300ms) and reducing the TM retry count from 100 to 30?Please let me know your opinion.
Quoted 7 lines
Hi Seunghui,
Changing
TM_CMD_TIMEOUTfrom 100ms to 300ms is okay for me. The adjustment of the TM retry count from 100 to 30 is not significant, so it does not matter whether this change is made or not. Overall, this patch looks good to me.
Thank you for your opinion.
I'll update the revision.
Quoted 8 lines
However, the other TM clear timeout of 1 second has a much greater impact:
ufshcd_wait_for_register(hba,REG_UTP_TRANSFER_REQ_DOOR_BELL,mask, ~mask, 1000, 1000);Would you consider shortening this value as well?
Thanks
Peter
Thank you for your additional comment.
By the way, in my humble opinion, it's not about tm cmd timeout, but about host register.
If it must be changed, how much time do you think for it? I think that it's handled by different modification.
Thanks,
Seunghui Lee.
Quoted 10 lines · Seunghui Lee
Thank you for your additional comment.
By the way, in my humble opinion, it's not about tm cmd timeout, but about host register.If it must be changed, how much time do you think for it? I think that it's handled by different modification.
Thanks,
Seunghui Lee.
Hi Seunghui,
Yes, it is about the host register. I don’t have any ideas about this for now, but a reasonable value should be at the millisecond level.
I agree that this is another topic, so let’s leave it as is for now.
Thanks
Peter
Bart Van Assche
reviewerdrivers/ufs/core/ufshcd.c int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag) · line 7669
Quoted 11 lines · Seunghui Lee
/* maximum number of retries for a general UIC command */ #define
UFS_UIC_COMMAND_RETRIES3drivers/ufs/core/ufshcd.c +1
-1@@ -7663,7 +7663,7 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)int poll_cnt;u8 resp =0xF ; -for (poll_cnt =100 ; poll_cnt; poll_cnt--) { +for (poll_cnt =30 ; poll_cnt; poll_cnt--) { err =ufshcd_issue_tm_cmd (hba, lrbp->lun, lrbp->task_tag,UFS_QUERY_TASK , &resp);if (!err && resp ==UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED ) {
There are no other SCSI drivers I know of that have a retry loop around the code that submits task management functions. I propose to reduce the retry count in this function from 100 to 1.
Thanks,
Bart.
Quoted 10 lines · Bart Van Assche
There are no other SCSI drivers I know of that have a retry loop around
the code that submits task management functions. I propose to reduce the
retry count in this function from 100 to 1.Thanks,
Bart.
Hi Bart and Seunghui,
Sorry, after thinking it through, under normal circumstances it usually only loops once, so changing it to 30 is fine. However, in extreme cases, it’s possible that after a 30-second timeout, the device just send a response, and at the same time, when the host receives the response, the IRQ is pending by system. (other irq is executing or spin_lock_irq, etc)
So I suggest not changing this value, since it doesn’t affect the normal execution time. But in extreme cases, it could indeed fix an error.
Thanks
Peter
Bart Van Assche
reviewerQuoted 4 lines · Peter Wang (王信友)
However, in extreme cases, it’s possible that after a 30-second timeout, the device just send a response, and at the same time, when the host receives the response, the IRQ is pending by system. (other irq is executing or
spin_lock_irq, etc)
It is not clear to me how this could happen? If a response is not received in time from the UFS device, an abort TMF is sent. If the device does not respond to the abort TMF, the UFS device is reset (ufshcd_device_reset() is called if ufshcd_abort_all() fails). This prevents that a response can be received after the error handler has finished, isn't it?
Thanks,
Bart.
Quoted 13 lines · Bart Van Assche
Quoted 4 lines · Peter Wang (王信友)
However, in extreme cases, it’s possible that after a 30-second timeout, the device just send a response, and at the same time, when the host receives the response, the IRQ is pending by system. (other irq is executing or
spin_lock_irq, etc)It is not clear to me how this could happen? If a response is not received in time from the UFS device, an abort TMF is sent. If the device does not respond to the abort TMF, the UFS device is reset (
ufshcd_device_reset()is called ifufshcd_abort_all()fails). This prevents that a response can be received after the error handler has finished, isn't it?
Quoted 3 lines
Thanks,
Bart.
Hi Bart,
The UFS device might take 30 seconds to send read/write response, and at the same time, the host sends a TM command to query this read/write task. In this case, host will receive the device’s TM response: UPIU_TASK_MANAGEMENT_FUNC_COMPL.
However, if the IRQ is disabled when the read/write response arrives, the host may not be able to process the response in time. Therefore, we need this loop to wait until the host IRQ is enabled and to clear the inflight command.
Thanks
Peter
Bart Van Assche
reviewerQuoted 8 lines · Peter Wang (王信友)
In the worst-case scenario (when the device is stuck), it may takes 1.1 seconds to abort a single task. When the queue is full (64), there will be noticeable lag. Aborting all tasks can take over a minute, which is unacceptable regardless of whether
TM_CMD_TIMEOUTis increased or not. Under normal conditions, it’s very unlikely to exceed 100ms. So I think directly modifyingTM_CMD_TIMEOUTis also acceptable, but I suggest keeping it within 500ms.
Hi Peter,
Aborting different commands should happen concurrently rather than sequentially. See also the queue_delayed_work() call in the SCSI core scsi_abort_command() function:
queue_delayed_work(shost->tmf_work_q, &scmd->abort_work, HZ / 100);
Unfortunately the max_active argument is set to 1 in the call that creates tmf_work_q:
shost->tmf_work_q = alloc_workqueue("scsi_tmf_%d",
WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_SYSFS, 1, shost->host_no);
Hannes, do you agree with increasing the max_active argument from 1 to INT_MAX? I think the above code was introduced 12 years ago by commit e494f6a72839 ("[SCSI] improved eh timeout handler").
Thanks,
Bart.
On Mon, 2025-11-17 at 08:40 -0800, Bart Van Assche wrote
Quoted 9 lines
Hannes, do you agree with increasing the
max_activeargument from 1 toINT_MAX? I think the above code was introduced 12 years ago by commite494f6a72839("[SCSI] improved eh timeout handler").Thanks,
Bart.
Hi Bart,
I think we can change max_active, but using the default value of 0 should be sufficient, according to workqueue.rst.
The maximum limit for ``@max_active`` is 2048 and the default value used
when 0 is specified is 1024. These values are chosen sufficiently high such that they are not the limiting factor while providing protection in
runaway cases.
Thanks
Peter
Quoted 3 lines · Seunghui Lee
Currently, UFS driver uses hardcoded
TM_CMD_TIMEOUT(100ms) for all Task Management commands, which may not be optimal for different UFS devices and use cases.