2023-12-27 06:03:45

by Chunfeng Yun

[permalink] [raw]
Subject: [PATCH v4 1/3] dt-bindings: usb: mtk-xhci: add a property for Gen1 isoc-in transfer issue

For Gen1 isoc-in endpoint on controller before about SSUSB IPM v1.6.0, it
still send out unexpected ACK after receiving a short packet in burst
transfer, this will cause an exception on connected device, specially for
a 4k camera.
Add a quirk property "rx-fifo-depth" to work around this hardware issue,
prefer to use 3k bytes;
The side-effect is that may cause performance drop about 10%, including
bulk transfer.

Signed-off-by: Chunfeng Yun <[email protected]>
---
v4: change rx-fifo size in bytes
v3: add fifo depth unit, change the value range from 0-3 to 1-4
v2: change 'mediatek,rxfifo-depth' to 'rx-fifo-depth'
---
.../devicetree/bindings/usb/mediatek,mtk-xhci.yaml | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
index e9644e333d78..9f621f2209df 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
@@ -124,6 +124,17 @@ properties:
defined in the xHCI spec on MTK's controller.
default: 5000

+ rx-fifo-depth:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description:
+ It is a quirk used to work around Gen1 isoc-in endpoint transfer issue
+ that still send out unexpected ACK after device finish the burst transfer
+ with a short packet and cause an exception, specially on a 4K camera
+ device, it happens on controller before about IPM v1.6.0; the side-effect
+ is that may cause performance drop about 10%, include bulk transfer,
+ prefer to use 3k here. The size is in bytes.
+ enum: [1024, 2048, 3072, 4096]
+
# the following properties are only used for case 1
wakeup-source:
description: enable USB remote wakeup, see power/wakeup-source.txt
--
2.18.0



2023-12-27 06:03:47

by Chunfeng Yun

[permalink] [raw]
Subject: [PATCH v4 2/3] usb: xhci-mtk: fix a short packet issue of gen1 isoc-in transfer

For Gen1 isoc-in transfer, host still send out unexpected ACK after device
finish the burst with a short packet, this will cause an exception on the
connected device, such as, a usb 4k camera.
It can be fixed by setting rxfifo depth less than 4k bytes, prefer to use
3k here, the side-effect is that may cause performance drop about 10%,
including bulk transfer.

Fixes: 926d60ae64a6 ("usb: xhci-mtk: modify the SOF/ITP interval for mt8195")
Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Chunfeng Yun <[email protected]>
---
v4:
drop Cc stable
add reviewed-by Angelo
change rxfifo depth in bytes
v3:
add Cc stable
change @rxfifo_depth from int to u32, due to property's value range is changed
v2:
use 'rx-fifo-depth' property;
add header file 'linux/bitfield.h' to avoid building error on some ARCH;
---
drivers/usb/host/xhci-mtk.c | 40 +++++++++++++++++++++++++++++++++++--
drivers/usb/host/xhci-mtk.h | 2 ++
2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index bbdf1b0b7be1..3252e3d2d79c 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -7,6 +7,7 @@
* Chunfeng Yun <[email protected]>
*/

+#include <linux/bitfield.h>
#include <linux/dma-mapping.h>
#include <linux/iopoll.h>
#include <linux/kernel.h>
@@ -73,6 +74,9 @@
#define FRMCNT_LEV1_RANG (0x12b << 8)
#define FRMCNT_LEV1_RANG_MASK GENMASK(19, 8)

+#define HSCH_CFG1 0x960
+#define SCH3_RXFIFO_DEPTH_MASK GENMASK(21, 20)
+
#define SS_GEN2_EOF_CFG 0x990
#define SSG2EOF_OFFSET 0x3c

@@ -114,6 +118,8 @@
#define SSC_IP_SLEEP_EN BIT(4)
#define SSC_SPM_INT_EN BIT(1)

+#define SCH_FIFO_TO_KB(x) ((x) >> 10)
+
enum ssusb_uwk_vers {
SSUSB_UWK_V1 = 1,
SSUSB_UWK_V2,
@@ -165,6 +171,35 @@ static void xhci_mtk_set_frame_interval(struct xhci_hcd_mtk *mtk)
writel(value, hcd->regs + SS_GEN2_EOF_CFG);
}

+/*
+ * workaround: usb3.2 gen1 isoc rx hw issue
+ * host send out unexpected ACK afer device fininsh a burst transfer with
+ * a short packet.
+ */
+static void xhci_mtk_rxfifo_depth_set(struct xhci_hcd_mtk *mtk)
+{
+ struct usb_hcd *hcd = mtk->hcd;
+ u32 value;
+
+ if (!mtk->rxfifo_depth)
+ return;
+
+ value = readl(hcd->regs + HSCH_CFG1);
+ value &= ~SCH3_RXFIFO_DEPTH_MASK;
+ value |= FIELD_PREP(SCH3_RXFIFO_DEPTH_MASK,
+ SCH_FIFO_TO_KB(mtk->rxfifo_depth) - 1);
+ writel(value, hcd->regs + HSCH_CFG1);
+}
+
+static void xhci_mtk_init_quirk(struct xhci_hcd_mtk *mtk)
+{
+ /* workaround only for mt8195 */
+ xhci_mtk_set_frame_interval(mtk);
+
+ /* workaround for SoCs using SSUSB about before IPM v1.6.0 */
+ xhci_mtk_rxfifo_depth_set(mtk);
+}
+
static int xhci_mtk_host_enable(struct xhci_hcd_mtk *mtk)
{
struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs;
@@ -448,8 +483,7 @@ static int xhci_mtk_setup(struct usb_hcd *hcd)
if (ret)
return ret;

- /* workaround only for mt8195 */
- xhci_mtk_set_frame_interval(mtk);
+ xhci_mtk_init_quirk(mtk);
}

ret = xhci_gen_setup(hcd, xhci_mtk_quirks);
@@ -527,6 +561,8 @@ static int xhci_mtk_probe(struct platform_device *pdev)
of_property_read_u32(node, "mediatek,u2p-dis-msk",
&mtk->u2p_dis_msk);

+ of_property_read_u32(node, "rx-fifo-depth", &mtk->rxfifo_depth);
+
ret = usb_wakeup_of_property_parse(mtk, node);
if (ret) {
dev_err(dev, "failed to parse uwk property\n");
diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h
index 39f7ae7d3087..f5e2bd66bb1b 100644
--- a/drivers/usb/host/xhci-mtk.h
+++ b/drivers/usb/host/xhci-mtk.h
@@ -171,6 +171,8 @@ struct xhci_hcd_mtk {
struct regmap *uwk;
u32 uwk_reg_base;
u32 uwk_vers;
+ /* quirk */
+ u32 rxfifo_depth;
};

static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd)
--
2.18.0


2023-12-27 06:04:16

by Chunfeng Yun

[permalink] [raw]
Subject: [PATCH v4 3/3] arm64: dts: mediatek: mt8195: Add 'rx-fifo-depth' for cherry

Add the quirk property "rx-fifo-depth" to work around Gen1 isoc-in
transfer issue which send out unexpected ACK even after device
already finished the burst transfer with a short patcket, specially
for a 4K camera device.

Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Chunfeng Yun <[email protected]>
---
v4:
change property value, and put before supply
add reviewed-by Angelo
v3: change value according to binding
v2: use 'rx-fifo-depth' property
---
arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi b/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi
index dd5b89b73190..00fcde60300e 100644
--- a/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi
@@ -1183,6 +1183,7 @@
&xhci0 {
status = "okay";

+ rx-fifo-depth = <3072>;
vusb33-supply = <&mt6359_vusb_ldo_reg>;
vbus-supply = <&usb_vbus>;
};
@@ -1190,6 +1191,7 @@
&xhci1 {
status = "okay";

+ rx-fifo-depth = <3072>;
vusb33-supply = <&mt6359_vusb_ldo_reg>;
vbus-supply = <&usb_vbus>;
};
--
2.18.0


2023-12-27 09:20:27

by Sergey Shtylyov

[permalink] [raw]
Subject: Re: [PATCH v4 1/3] dt-bindings: usb: mtk-xhci: add a property for Gen1 isoc-in transfer issue

On 12/27/23 9:03 AM, Chunfeng Yun wrote:

> For Gen1 isoc-in endpoint on controller before about SSUSB IPM v1.6.0, it
> still send out unexpected ACK after receiving a short packet in burst
> transfer, this will cause an exception on connected device, specially for
> a 4k camera.
> Add a quirk property "rx-fifo-depth" to work around this hardware issue,
> prefer to use 3k bytes;
> The side-effect is that may cause performance drop about 10%, including

That it may cause?

> bulk transfer.
>
> Signed-off-by: Chunfeng Yun <[email protected]>
> ---
> v4: change rx-fifo size in bytes
> v3: add fifo depth unit, change the value range from 0-3 to 1-4
> v2: change 'mediatek,rxfifo-depth' to 'rx-fifo-depth'
> ---
> .../devicetree/bindings/usb/mediatek,mtk-xhci.yaml | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
> index e9644e333d78..9f621f2209df 100644
> --- a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
> +++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
> @@ -124,6 +124,17 @@ properties:
> defined in the xHCI spec on MTK's controller.
> default: 5000
>
> + rx-fifo-depth:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description:
> + It is a quirk used to work around Gen1 isoc-in endpoint transfer issue
> + that still send out unexpected ACK after device finish the burst transfer

Finishes.

> + with a short packet and cause an exception, specially on a 4K camera
> + device, it happens on controller before about IPM v1.6.0; the side-effect
> + is that may cause performance drop about 10%, include bulk transfer,

That it may cause? And including?

[...]

MBR, Sergey

2023-12-28 10:43:07

by Mathias Nyman

[permalink] [raw]
Subject: Re: [PATCH v4 1/3] dt-bindings: usb: mtk-xhci: add a property for Gen1 isoc-in transfer issue

Hi

On 27.12.2023 8.03, Chunfeng Yun wrote:
> For Gen1 isoc-in endpoint on controller before about SSUSB IPM v1.6.0, it
> still send out unexpected ACK after receiving a short packet in burst
> transfer, this will cause an exception on connected device, specially for
> a 4k camera.
> Add a quirk property "rx-fifo-depth" to work around this hardware issue,
> prefer to use 3k bytes;
> The side-effect is that may cause performance drop about 10%, including
> bulk transfer.

Is it be possible to detect those Mediatek xHC versions that need this
workaround in the xhci-mtk driver directly?

This way we could avoid passing a new "rx-fifo-depth" property to it.

Thanks
Mathias


Subject: Re: [PATCH v4 1/3] dt-bindings: usb: mtk-xhci: add a property for Gen1 isoc-in transfer issue

Il 27/12/23 07:03, Chunfeng Yun ha scritto:
> For Gen1 isoc-in endpoint on controller before about SSUSB IPM v1.6.0, it
> still send out unexpected ACK after receiving a short packet in burst
> transfer, this will cause an exception on connected device, specially for
> a 4k camera.
> Add a quirk property "rx-fifo-depth" to work around this hardware issue,
> prefer to use 3k bytes;
> The side-effect is that may cause performance drop about 10%, including
> bulk transfer.
>
> Signed-off-by: Chunfeng Yun <[email protected]>

Reviewed-by: AngeloGioacchino Del Regno <[email protected]>



2024-01-02 21:04:16

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH v4 1/3] dt-bindings: usb: mtk-xhci: add a property for Gen1 isoc-in transfer issue

On 27/12/2023 07:03, Chunfeng Yun wrote:
> For Gen1 isoc-in endpoint on controller before about SSUSB IPM v1.6.0, it
> still send out unexpected ACK after receiving a short packet in burst
> transfer, this will cause an exception on connected device, specially for
> a 4k camera.
> Add a quirk property "rx-fifo-depth" to work around this hardware issue,
> prefer to use 3k bytes;
> The side-effect is that may cause performance drop about 10%, including
> bulk transfer.
>
> Signed-off-by: Chunfeng Yun <[email protected]>
> ---
> v4: change rx-fifo size in bytes

Acked-by: Krzysztof Kozlowski <[email protected]>

Best regards,
Krzysztof


2024-01-04 06:12:52

by Chunfeng Yun

[permalink] [raw]
Subject: Re: [PATCH v4 1/3] dt-bindings: usb: mtk-xhci: add a property for Gen1 isoc-in transfer issue

On Thu, 2023-12-28 at 12:44 +0200, Mathias Nyman wrote:
>
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> Hi
>
> On 27.12.2023 8.03, Chunfeng Yun wrote:
> > For Gen1 isoc-in endpoint on controller before about SSUSB IPM
> v1.6.0, it
> > still send out unexpected ACK after receiving a short packet in
> burst
> > transfer, this will cause an exception on connected device,
> specially for
> > a 4k camera.
> > Add a quirk property "rx-fifo-depth" to work around this hardware
> issue,
> > prefer to use 3k bytes;
> > The side-effect is that may cause performance drop about 10%,
> including
> > bulk transfer.
>
> Is it be possible to detect those Mediatek xHC versions that need
> this
> workaround in the xhci-mtk driver directly?
the version info is saved in IPPC register, when support dual-role
mode, xhci-mtk driver can't access these register which are controlled
by dual-role controller mtu3 driver;
another reason is that some cases, e.g. connected a on-board fixed mass
storage device, do not use 4K camera, it's better to use the default
rx-fifo-depth;

Thanks
>
> This way we could avoid passing a new "rx-fifo-depth" property to it.
>
> Thanks
> Mathias
>
>

2024-01-04 07:27:50

by Chunfeng Yun

[permalink] [raw]
Subject: Re: [PATCH v4 1/3] dt-bindings: usb: mtk-xhci: add a property for Gen1 isoc-in transfer issue

On Wed, 2023-12-27 at 12:19 +0300, Sergey Shtylyov wrote:
>
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> On 12/27/23 9:03 AM, Chunfeng Yun wrote:
>
> > For Gen1 isoc-in endpoint on controller before about SSUSB IPM
> v1.6.0, it
> > still send out unexpected ACK after receiving a short packet in
> burst
> > transfer, this will cause an exception on connected device,
> specially for
> > a 4k camera.
> > Add a quirk property "rx-fifo-depth" to work around this hardware
> issue,
> > prefer to use 3k bytes;
> > The side-effect is that may cause performance drop about 10%,
> including
>
> That it may cause?
>
> > bulk transfer.
> >
> > Signed-off-by: Chunfeng Yun <[email protected]>
> > ---
> > v4: change rx-fifo size in bytes
> > v3: add fifo depth unit, change the value range from 0-3 to 1-4
> > v2: change 'mediatek,rxfifo-depth' to 'rx-fifo-depth'
> > ---
> > .../devicetree/bindings/usb/mediatek,mtk-xhci.yaml | 11
> +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtk-
> xhci.yaml b/Documentation/devicetree/bindings/usb/mediatek,mtk-
> xhci.yaml
> > index e9644e333d78..9f621f2209df 100644
> > --- a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
> > +++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
> > @@ -124,6 +124,17 @@ properties:
> > defined in the xHCI spec on MTK's controller.
> > default: 5000
> >
> > + rx-fifo-depth:
> > + $ref: /schemas/types.yaml#/definitions/uint32
> > + description:
> > + It is a quirk used to work around Gen1 isoc-in endpoint
> transfer issue
> > + that still send out unexpected ACK after device finish the
> burst transfer
>
> Finishes.
>
> > + with a short packet and cause an exception, specially on a
> 4K camera
> > + device, it happens on controller before about IPM v1.6.0;
> the side-effect
> > + is that may cause performance drop about 10%, include bulk
> transfer,
>
> That it may cause? And including?
Ok, I'll fix these typos,

Reply again, previous one contains HTML part;

Thanks
>


> [...]
>
> MBR, Sergey