linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN
@ 2025-04-21 13:51 Huan Tang
  2025-04-21 13:58 ` Huan Tang
  2025-04-22  2:55 ` Peter Wang (王信友)
  0 siblings, 2 replies; 11+ messages in thread
From: Huan Tang @ 2025-04-21 13:51 UTC (permalink / raw)
  To: alim.akhtar, avri.altman, bvanassche, James.Bottomley,
	martin.petersen, peter.wang, manivannan.sadhasivam, quic_nguyenb,
	ebiggers, minwoo.im, linux-scsi, linux-kernel
  Cc: opensource.kernel, Huan Tang

Add caps UFSHCD_CAP_MCQ_EN(default enable), then host driver to
control the on/off of MCQ; Sometimes, we don't want to enable
MCQ and want to disable it through the host driver, for example,
ufs-qcom.c .

Signed-off-by: Huan Tang <tanghuan@vivo.com>
---
 drivers/ufs/core/ufshcd.c | 3 ++-
 include/ufs/ufshcd.h      | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 44156041d88f..b8937f85d81a 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -112,7 +112,7 @@ static bool use_mcq_mode = true;
 
 static bool is_mcq_supported(struct ufs_hba *hba)
 {
-	return hba->mcq_sup && use_mcq_mode;
+	return hba->mcq_sup && use_mcq_mode && (hba->caps & UFSHCD_CAP_MCQ_EN);
 }
 
 module_param(use_mcq_mode, bool, 0644);
@@ -10389,6 +10389,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->caps |= UFSHCD_CAP_MCQ_EN;
 	ufshcd_set_sg_entry_size(hba, sizeof(struct ufshcd_sg_entry));
 	INIT_LIST_HEAD(&hba->clk_list_head);
 	spin_lock_init(&hba->outstanding_lock);
diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h
index e928ed0265ff..d8547bc6bf79 100644
--- a/include/ufs/ufshcd.h
+++ b/include/ufs/ufshcd.h
@@ -771,6 +771,12 @@ enum ufshcd_caps {
 	 * WriteBooster when scaling the clock down.
 	 */
 	UFSHCD_CAP_WB_WITH_CLK_SCALING			= 1 << 12,
+
+	/*
+	 * This capability allows the host controller driver to use the
+	 * multi-circular queue, if it is present
+	 */
+	UFSHCD_CAP_MCQ_EN				= 1 << 13,
 };
 
 struct ufs_hba_variant_params {
-- 
2.39.0


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

* [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN
  2025-04-21 13:51 [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN Huan Tang
@ 2025-04-21 13:58 ` Huan Tang
  2025-04-22  2:55 ` Peter Wang (王信友)
  1 sibling, 0 replies; 11+ messages in thread
From: Huan Tang @ 2025-04-21 13:58 UTC (permalink / raw)
  To: bvanassche
  Cc: James.Bottomley, alim.akhtar, avri.altman, ebiggers, linux-kernel,
	linux-scsi, manivannan.sadhasivam, martin.petersen, minwoo.im,
	opensource.kernel, peter.wang, quic_nguyenb

> Add caps UFSHCD_CAP_MCQ_EN(default enable), then host driver to
> control the on/off of MCQ; Sometimes, we don't want to enable
> MCQ and want to disable it through the host driver, for example,
> ufs-qcom.c .

Hi Bart sir,

Sorry to disturb you!
Some phones use the qcom SM7750 platform, but I don't want to use MCQ; currently, to turn it off, I have to break GKI, so I want to add a way to control MCQ on/off, so that I can turn it off in ufs-qcom.c

Thanks
Huan

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

* Re: [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN
  2025-04-21 13:51 [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN Huan Tang
  2025-04-21 13:58 ` Huan Tang
@ 2025-04-22  2:55 ` Peter Wang (王信友)
  2025-04-22  6:25   ` Huan Tang
  1 sibling, 1 reply; 11+ messages in thread
From: Peter Wang (王信友) @ 2025-04-22  2:55 UTC (permalink / raw)
  To: avri.altman@wdc.com, ebiggers@google.com, tanghuan@vivo.com,
	quic_nguyenb@quicinc.com, linux-scsi@vger.kernel.org,
	manivannan.sadhasivam@linaro.org, bvanassche@acm.org,
	alim.akhtar@samsung.com, minwoo.im@samsung.com,
	linux-kernel@vger.kernel.org, martin.petersen@oracle.com,
	James.Bottomley@HansenPartnership.com
  Cc: opensource.kernel@vivo.com

On Mon, 2025-04-21 at 21:51 +0800, Huan Tang wrote:
> 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> 
> 
> Add caps UFSHCD_CAP_MCQ_EN(default enable), then host driver to
> control the on/off of MCQ; Sometimes, we don't want to enable
> MCQ and want to disable it through the host driver, for example,
> ufs-qcom.c .
> 
> Signed-off-by: Huan Tang <tanghuan@vivo.com>
> ---


Hi Huan,

This patch of only add a flag and always enables this flag. 
In other words, it is a meaningless patch.
Suggest also uptream the flow of the disable flag patch 
as part of a patch series.

Thanks
Peter



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

* Re: [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN
  2025-04-22  2:55 ` Peter Wang (王信友)
@ 2025-04-22  6:25   ` Huan Tang
  2025-04-22  6:57     ` Bart Van Assche
                       ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Huan Tang @ 2025-04-22  6:25 UTC (permalink / raw)
  To: peter.wang
  Cc: James.Bottomley, alim.akhtar, avri.altman, bvanassche, ebiggers,
	linux-kernel, linux-scsi, manivannan.sadhasivam, martin.petersen,
	minwoo.im, opensource.kernel, quic_nguyenb, tanghuan

> This patch of only add a flag and always enables this flag. 
> In other words, it is a meaningless patch.
> Suggest also uptream the flow of the disable flag patch 
> as part of a patch series.

Hi Peter sir,

Thanks for you reply!
I found that using low-end UFS in SoCs that support MCQ may cause
device latency to reach extreme values.

My idea is that after having this patch, I can add hba->caps &=
~UFSHCD_CAP_MCQ_EN to disable mcq via ufs-qcom.c or ufs-mediatek.c. 

Do you mean to add a caps UFSHCD_CAP_MCQ_DISABLE? 
Or remove hba->caps |= UFSHCD_CAP_MCQ_EN in ufshcd_alloc_host, 
and then add hba->caps |= UFSHCD_CAP_MCQ_EN in ufs-xxx.c, such as ufs-mediatek.c?

Thanks
Huan

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

* Re: [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN
  2025-04-22  6:25   ` Huan Tang
@ 2025-04-22  6:57     ` Bart Van Assche
  2025-04-22  7:22       ` Huan Tang
  2025-04-22  6:57     ` Avri Altman
  2025-04-22  7:51     ` Peter Wang (王信友)
  2 siblings, 1 reply; 11+ messages in thread
From: Bart Van Assche @ 2025-04-22  6:57 UTC (permalink / raw)
  To: Huan Tang, peter.wang
  Cc: James.Bottomley, alim.akhtar, avri.altman, ebiggers, linux-kernel,
	linux-scsi, manivannan.sadhasivam, martin.petersen, minwoo.im,
	opensource.kernel, quic_nguyenb


On 4/21/25 11:25 PM, Huan Tang wrote:
> I found that using low-end UFS in SoCs that support MCQ may cause
> device latency to reach extreme values.

Hi Huan,

What is the root-cause of the high latency? If it is the time spent in
UFS interrupt handlers, please try to switch to threaded interrupt
handlers instead of disabling MCQ. See also
https://lore.kernel.org/linux-scsi/20250407-topic-ufs-use-threaded-irq-v3-0-08bee980f71e@linaro.org/

Bart.

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

* RE: [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN
  2025-04-22  6:25   ` Huan Tang
  2025-04-22  6:57     ` Bart Van Assche
@ 2025-04-22  6:57     ` Avri Altman
  2025-04-22  7:04       ` Huan Tang
  2025-04-22  7:06       ` Huan Tang
  2025-04-22  7:51     ` Peter Wang (王信友)
  2 siblings, 2 replies; 11+ messages in thread
From: Avri Altman @ 2025-04-22  6:57 UTC (permalink / raw)
  To: Huan Tang, peter.wang@mediatek.com
  Cc: James.Bottomley@HansenPartnership.com, alim.akhtar@samsung.com,
	avri.altman@wdc.com, bvanassche@acm.org, ebiggers@google.com,
	linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
	manivannan.sadhasivam@linaro.org, martin.petersen@oracle.com,
	minwoo.im@samsung.com, opensource.kernel@vivo.com,
	quic_nguyenb@quicinc.com

> 
> Thanks for you reply!
> 
> I found that using low-end UFS in SoCs that support MCQ may cause
> 
> device latency to reach extreme values.
Do you mean that the device reports wSpecVersion >= 400 but doesn't really work well with MCQ?

Thanks,
Avri


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

* RE: [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN
  2025-04-22  6:57     ` Avri Altman
@ 2025-04-22  7:04       ` Huan Tang
  2025-04-22  7:06       ` Huan Tang
  1 sibling, 0 replies; 11+ messages in thread
From: Huan Tang @ 2025-04-22  7:04 UTC (permalink / raw)
  To: avri.altman
  Cc: James.Bottomley, alim.akhtar, avri.altman, bvanassche, ebiggers,
	linux-kernel, linux-scsi, manivannan.sadhasivam, martin.petersen,
	minwoo.im, opensource.kernel, peter.wang, quic_nguyenb, tanghuan

Hi Arvi sir,

Thanks for your reply!

This means that the soc is UFSHCI 4.x, but the ufs device uses ufs2.x.

Thanks
Huan

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

* RE: [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN
  2025-04-22  6:57     ` Avri Altman
  2025-04-22  7:04       ` Huan Tang
@ 2025-04-22  7:06       ` Huan Tang
  2025-04-22  8:11         ` Avri Altman
  1 sibling, 1 reply; 11+ messages in thread
From: Huan Tang @ 2025-04-22  7:06 UTC (permalink / raw)
  To: avri.altman
  Cc: James.Bottomley, alim.akhtar, avri.altman, bvanassche, ebiggers,
	linux-kernel, linux-scsi, manivannan.sadhasivam, martin.petersen,
	minwoo.im, opensource.kernel, peter.wang, quic_nguyenb, tanghuan

> Do you mean that the device reports wSpecVersion >= 400 but doesn't really work well with MCQ?

Hi Arvi sir,

Thanks for your reply!

This means that the soc is UFSHCI 4.x, but the ufs device uses ufs2.x.

Thanks
Huan

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

* Re: [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN
  2025-04-22  6:57     ` Bart Van Assche
@ 2025-04-22  7:22       ` Huan Tang
  0 siblings, 0 replies; 11+ messages in thread
From: Huan Tang @ 2025-04-22  7:22 UTC (permalink / raw)
  To: bvanassche
  Cc: James.Bottomley, alim.akhtar, avri.altman, ebiggers, linux-kernel,
	linux-scsi, manivannan.sadhasivam, martin.petersen, minwoo.im,
	opensource.kernel, peter.wang, quic_nguyenb, tanghuan

> What is the root-cause of the high latency? If it is the time spent in
> UFS interrupt handlers, please try to switch to threaded interrupt
> handlers instead of disabling MCQ. See also
> https://lore.kernel.org/linux-scsi/20250407-topic-ufs-use-threaded-irq-v3-0-08bee980f71e@linaro.org/

Hi bart sir,

Thanks for your reply!

Thank you for your advice on the direction of interrupt handlers. 

The reason has not been found yet, but a comparative experiment was done, 
and the results are as follows:

The failure probability is 7/400 when MCQ is turned on, and 0/400
when MCQ is turned off; the definition of failure here is: the maximum
latency is greater than 5s.



Thanks
Huan

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

* Re: [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN
  2025-04-22  6:25   ` Huan Tang
  2025-04-22  6:57     ` Bart Van Assche
  2025-04-22  6:57     ` Avri Altman
@ 2025-04-22  7:51     ` Peter Wang (王信友)
  2 siblings, 0 replies; 11+ messages in thread
From: Peter Wang (王信友) @ 2025-04-22  7:51 UTC (permalink / raw)
  To: tanghuan@vivo.com
  Cc: avri.altman@wdc.com, ebiggers@google.com,
	quic_nguyenb@quicinc.com, linux-scsi@vger.kernel.org,
	manivannan.sadhasivam@linaro.org, linux-kernel@vger.kernel.org,
	alim.akhtar@samsung.com, bvanassche@acm.org,
	minwoo.im@samsung.com, opensource.kernel@vivo.com,
	James.Bottomley@HansenPartnership.com, martin.petersen@oracle.com

On Tue, 2025-04-22 at 14:25 +0800, Huan Tang wrote:
> 
> Hi Peter sir,
> 
> 
> 
> Thanks for you reply!
> 
> I found that using low-end UFS in SoCs that support MCQ may cause
> 
> device latency to reach extreme values.
> 
> 
> 
> My idea is that after having this patch, I can add hba->caps &=
> 
> ~UFSHCD_CAP_MCQ_EN to disable mcq via ufs-qcom.c or ufs-mediatek.c.
> 
> 
> 
> Do you mean to add a caps UFSHCD_CAP_MCQ_DISABLE?
> 
> Or remove hba->caps |= UFSHCD_CAP_MCQ_EN in ufshcd_alloc_host,
> 
> and then add hba->caps |= UFSHCD_CAP_MCQ_EN in ufs-xxx.c, such as
> ufs-mediatek.c?
> 
> 
> 
> Thanks
> 
> Huan

Hi Huan,

What I mean is that you need upstream code to disable this flag. 
hba->caps &= ~UFSHCD_CAP_MCQ_EN

But this seems a bit strange to me, as MCQ is a UFS host feature. 
It shouldn't be related to the old ufs2.x device. 
If it is ultimately confirmed to be an issue with the UFS device, 
you can add a device quirk to disable this flag.

Thanks.
Peter




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

* RE: [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN
  2025-04-22  7:06       ` Huan Tang
@ 2025-04-22  8:11         ` Avri Altman
  0 siblings, 0 replies; 11+ messages in thread
From: Avri Altman @ 2025-04-22  8:11 UTC (permalink / raw)
  To: Huan Tang
  Cc: James.Bottomley@HansenPartnership.com, alim.akhtar@samsung.com,
	avri.altman@wdc.com, bvanassche@acm.org, ebiggers@google.com,
	linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
	manivannan.sadhasivam@linaro.org, martin.petersen@oracle.com,
	minwoo.im@samsung.com, opensource.kernel@vivo.com,
	peter.wang@mediatek.com, quic_nguyenb@quicinc.com

> This means that the soc is UFSHCI 4.x, but the ufs device uses ufs2.x.
Ahha - ok.
One more thing you can try, is to wave the if (dev_info->wspecversion < 0x400) in ufshcd_set_rtt().
Originally it was designed for gear 5, but it would also help to maximize the device performance.

Thanks,
Avri

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

end of thread, other threads:[~2025-04-22  8:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-21 13:51 [PATCH] ufs: core: add caps UFSHCD_CAP_MCQ_EN Huan Tang
2025-04-21 13:58 ` Huan Tang
2025-04-22  2:55 ` Peter Wang (王信友)
2025-04-22  6:25   ` Huan Tang
2025-04-22  6:57     ` Bart Van Assche
2025-04-22  7:22       ` Huan Tang
2025-04-22  6:57     ` Avri Altman
2025-04-22  7:04       ` Huan Tang
2025-04-22  7:06       ` Huan Tang
2025-04-22  8:11         ` Avri Altman
2025-04-22  7:51     ` Peter Wang (王信友)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).