Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH v2 0/1] Allow platform drivers to update UIC command timeout
@ 2024-05-30 21:36 Bao D. Nguyen
  2024-05-30 21:36 ` [PATCH v2 1/1] scsi: ufs: core: Support Updating UIC Command Timeout Bao D. Nguyen
  0 siblings, 1 reply; 5+ messages in thread
From: Bao D. Nguyen @ 2024-05-30 21:36 UTC (permalink / raw)
  To: quic_cang, quic_nitirawa, bvanassche, avri.altman, beanhuo,
	adrian.hunter, martin.petersen
  Cc: linux-scsi, Bao D. Nguyen

The UIC command timeout default value remains as 500ms.

Allow platform drivers to change the UIC command timeout as they wish.
During product development where a lot of debug logging/printing can
occur, the uart may print from different modules with interrupt disabled
for more than 500ms, causing interrupt starvation and UIC command timeout
as a result. The UIC command timeout may eventually cause a watchdog
timeout unnecessarily. With this change, the platform drivers can set a
different UIC command timeout as desired. The supported values range
from 500ms to 2 seconds.

v1 -> v2: - Created kernel module parameter namely uic_cmd_timeout
            as recommended by Bart. Addressed some other comments.
          - Un-do the change in the include/ufs/ufshcd.h file
            which added the uic_cmd_timeout field to the hba struct.
	  - Removed the patch 2 in the series where the UIC command
	    timeout value was overridden by the platform driver.

Bao D. Nguyen (1):
  scsi: ufs: core: Support Updating UIC Command Timeout

 drivers/ufs/core/ufshcd.c | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

-- 
2.7.4


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

* [PATCH v2 1/1] scsi: ufs: core: Support Updating UIC Command Timeout
  2024-05-30 21:36 [PATCH v2 0/1] Allow platform drivers to update UIC command timeout Bao D. Nguyen
@ 2024-05-30 21:36 ` Bao D. Nguyen
  2024-06-12  1:43   ` Martin K. Petersen
  2024-06-12  3:24   ` Bart Van Assche
  0 siblings, 2 replies; 5+ messages in thread
From: Bao D. Nguyen @ 2024-05-30 21:36 UTC (permalink / raw)
  To: quic_cang, quic_nitirawa, bvanassche, avri.altman, beanhuo,
	adrian.hunter, martin.petersen
  Cc: linux-scsi, Bao D. Nguyen, Alim Akhtar, James E.J. Bottomley,
	Stanley Chu, Peter Wang, Manivannan Sadhasivam, open list

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>
Suggested-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/ufs/core/ufshcd.c | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 21429ee..92f1ed46 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -51,8 +51,10 @@
 
 
 /* UIC command timeout, unit: ms */
-#define UIC_CMD_TIMEOUT	500
-
+enum {
+	UIC_CMD_TIMEOUT		= 500,
+	UIC_CMD_TIMEOUT_MAX	= 2000,
+};
 /* NOP OUT retries waiting for NOP IN response */
 #define NOP_OUT_RETRIES    10
 /* Timeout after 50 msecs if NOP OUT hangs without response */
@@ -113,6 +115,29 @@ static bool is_mcq_supported(struct ufs_hba *hba)
 module_param(use_mcq_mode, bool, 0644);
 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");
 
+static int uic_cmd_timeout_set(const char *val, const struct kernel_param *kp)
+{
+	unsigned int n;
+	int ret;
+
+	ret = kstrtou32(val, 0, &n);
+	if (ret != 0 || n < UIC_CMD_TIMEOUT || n > UIC_CMD_TIMEOUT_MAX)
+		return -EINVAL;
+
+	return param_set_int(val, kp);
+}
+
+static const struct kernel_param_ops uic_cmd_timeout_ops = {
+	.set = uic_cmd_timeout_set,
+	.get = param_get_uint,
+};
+
+static unsigned int uic_cmd_timeout = UIC_CMD_TIMEOUT;
+module_param_cb(uic_cmd_timeout, &uic_cmd_timeout_ops, &uic_cmd_timeout, 0644);
+MODULE_PARM_DESC(uic_cmd_timeout,
+		"UFS UIC command timeout in milliseconds. Default to 500ms. Supported values range from 500ms to 2 seconds inclusively");
+
+
 #define ufshcd_toggle_vreg(_dev, _vreg, _on)				\
 	({                                                              \
 		int _ret;                                               \
@@ -2460,7 +2485,7 @@ static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba)
 {
 	u32 val;
 	int ret = read_poll_timeout(ufshcd_readl, val, val & UIC_COMMAND_READY,
-				    500, UIC_CMD_TIMEOUT * 1000, false, hba,
+				    500, uic_cmd_timeout * 1000, false, hba,
 				    REG_CONTROLLER_STATUS);
 	return ret == 0;
 }
@@ -2520,7 +2545,7 @@ ufshcd_wait_for_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd)
 	lockdep_assert_held(&hba->uic_cmd_mutex);
 
 	if (wait_for_completion_timeout(&uic_cmd->done,
-					msecs_to_jiffies(UIC_CMD_TIMEOUT))) {
+					msecs_to_jiffies(uic_cmd_timeout))) {
 		ret = uic_cmd->argument2 & MASK_UIC_COMMAND_RESULT;
 	} else {
 		ret = -ETIMEDOUT;
@@ -4298,7 +4323,7 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd)
 	}
 
 	if (!wait_for_completion_timeout(hba->uic_async_done,
-					 msecs_to_jiffies(UIC_CMD_TIMEOUT))) {
+					 msecs_to_jiffies(uic_cmd_timeout))) {
 		dev_err(hba->dev,
 			"pwr ctrl cmd 0x%x with mode 0x%x completion timeout\n",
 			cmd->command, cmd->argument3);
-- 
2.7.4


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

* Re: [PATCH v2 1/1] scsi: ufs: core: Support Updating UIC Command Timeout
  2024-05-30 21:36 ` [PATCH v2 1/1] scsi: ufs: core: Support Updating UIC Command Timeout Bao D. Nguyen
@ 2024-06-12  1:43   ` Martin K. Petersen
  2024-06-12  3:25     ` Bart Van Assche
  2024-06-12  3:24   ` Bart Van Assche
  1 sibling, 1 reply; 5+ messages in thread
From: Martin K. Petersen @ 2024-06-12  1:43 UTC (permalink / raw)
  To: bvanassche
  Cc: Bao D. Nguyen, quic_cang, quic_nitirawa, avri.altman, beanhuo,
	adrian.hunter, martin.petersen, linux-scsi, Alim Akhtar,
	James E.J. Bottomley, Stanley Chu, Peter Wang,
	Manivannan Sadhasivam, open list


Hi Bart!

> 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>
> Suggested-by: Bart Van Assche <bvanassche@acm.org>

You requested changes which means you are on the hook for a review...

Thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH v2 1/1] scsi: ufs: core: Support Updating UIC Command Timeout
  2024-05-30 21:36 ` [PATCH v2 1/1] scsi: ufs: core: Support Updating UIC Command Timeout Bao D. Nguyen
  2024-06-12  1:43   ` Martin K. Petersen
@ 2024-06-12  3:24   ` Bart Van Assche
  1 sibling, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2024-06-12  3:24 UTC (permalink / raw)
  To: Bao D. Nguyen, quic_cang, quic_nitirawa, avri.altman, beanhuo,
	adrian.hunter, martin.petersen
  Cc: linux-scsi, Alim Akhtar, James E.J. Bottomley, Stanley Chu,
	Peter Wang, Manivannan Sadhasivam, open list

On 5/30/24 2:36 PM, Bao D. Nguyen wrote:
> +enum {
> +	UIC_CMD_TIMEOUT		= 500,
> +	UIC_CMD_TIMEOUT_MAX	= 2000,
> +};

Since UIC_CMD_TIMEOUT_MAX has been introduced, please rename 
UIC_CMD_TIMEOUT into UIC_CMD_TIMEOUT_DEFAULT or UIC_CMD_TIMEOUT_MIN to
make the role of that constant more clear.

> +static unsigned int uic_cmd_timeout = UIC_CMD_TIMEOUT;
> +module_param_cb(uic_cmd_timeout, &uic_cmd_timeout_ops, &uic_cmd_timeout, 0644);
> +MODULE_PARM_DESC(uic_cmd_timeout,
> +		"UFS UIC command timeout in milliseconds. Default to 500ms. Supported values range from 500ms to 2 seconds inclusively");

Default to -> Defaults to?

> +
> +

A single blank line should be sufficient.

Once these comments have been addressed, feel free to add:

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

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

* Re: [PATCH v2 1/1] scsi: ufs: core: Support Updating UIC Command Timeout
  2024-06-12  1:43   ` Martin K. Petersen
@ 2024-06-12  3:25     ` Bart Van Assche
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2024-06-12  3:25 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Bao D. Nguyen, quic_cang, quic_nitirawa, avri.altman, beanhuo,
	adrian.hunter, linux-scsi, Alim Akhtar, James E.J. Bottomley,
	Stanley Chu, Peter Wang, Manivannan Sadhasivam, open list

On 6/11/24 6:43 PM, Martin K. Petersen wrote:
> You requested changes which means you are on the hook for a review...

Thanks for the reminder - this patch got overlooked. I just posted a few
review comments.

Bart.


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

end of thread, other threads:[~2024-06-12  3:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-30 21:36 [PATCH v2 0/1] Allow platform drivers to update UIC command timeout Bao D. Nguyen
2024-05-30 21:36 ` [PATCH v2 1/1] scsi: ufs: core: Support Updating UIC Command Timeout Bao D. Nguyen
2024-06-12  1:43   ` Martin K. Petersen
2024-06-12  3:25     ` Bart Van Assche
2024-06-12  3:24   ` Bart Van Assche

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox