Skip to contentSkip to conversation

USB: dwc: Add workaround for host mode VBUS glitch when boot

PATCH In review Frank Li 2 participants 6 messages Jan 24, 2024 – Jan 30, 2024

Subsystems (5)
lore
Share & tools
lore

Frank Li

author maintainer
#0 lore raw

v4 cover USB: dwc: Add workaround for host mode VBUS glitch when boot

Chagne from v2 to v3
- see notes at patch

Change from v1 to v2:
- splite xhci.h to xchi-port.h and xhci-caps.h to shared marco.
- add quirk subfix
- fixed checkpatch error with --strict.

left one warning to align existed code style.

CHECK: Alignment should match open parenthesis
+ dwc->host_vbus_glitches_quirk = device_property_read_bool(dev,
+ "snps,host-vbus-glitches-quirk");

Frank Li (1):
XHCI: Separate PORT and CAPs macros into dedicated file

Ran Wang (2):
dt-bindings: usb: dwc3: Add snps,host-vbus-glitches-quirk avoid vbus
glitch
usb: dwc3: Add workaround for host mode VBUS glitch when boot

 .../devicetree/bindings/usb/snps,dwc3.yaml    |   7 +
 drivers/usb/dwc3/core.c                       |   3 +
 drivers/usb/dwc3/core.h                       |   2 +
 drivers/usb/dwc3/host.c                       |  51 ++++
 drivers/usb/host/xhci-caps.h                  |  85 ++++++
 drivers/usb/host/xhci-port.h                  | 176 ++++++++++++
 drivers/usb/host/xhci.h                       | 262 +-----------------
 7 files changed, 327 insertions(+), 259 deletions(-)
 create mode 100644 drivers/usb/host/xhci-caps.h
 create mode 100644 drivers/usb/host/xhci-port.h
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v4 1/3 XHCI: Separate PORT and CAPs macros into dedicated file

Split the PORT and CAPs macro definitions into a separate file to facilitate sharing with other files without the need to include the entire xhci.h.

---
 drivers/usb/host/xhci-caps.h |  85 ++++++++++++
 drivers/usb/host/xhci-port.h | 176 +++++++++++++++++++++++
 drivers/usb/host/xhci.h      | 262 +----------------------------------
 3 files changed, 264 insertions(+), 259 deletions(-)
 create mode 100644 drivers/usb/host/xhci-caps.h
 create mode 100644 drivers/usb/host/xhci-port.h
drivers/usb/host/xhci-caps.h new file +85 -0
new file mode 100644
index 0000000000000..9e94cebf4a56d
@@ -0,0 +1,85 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/* hc_capbase bitmasks */
+/* bits 7:0 - how long is the Capabilities register */
+#define HC_LENGTH(p)		XHCI_HC_LENGTH(p)
+/* bits 31:16	*/
+#define HC_VERSION(p)		(((p) >> 16) & 0xffff)
+
+/* HCSPARAMS1 - hcs_params1 - bitmasks */
+/* bits 0:7, Max Device Slots */
+#define HCS_MAX_SLOTS(p)	(((p) >> 0) & 0xff)
+#define HCS_SLOTS_MASK		0xff
+/* bits 8:18, Max Interrupters */
+#define HCS_MAX_INTRS(p)	(((p) >> 8) & 0x7ff)
+/* bits 24:31, Max Ports - max value is 0x7F = 127 ports */
+#define HCS_MAX_PORTS(p)	(((p) >> 24) & 0x7f)
+
+/* HCSPARAMS2 - hcs_params2 - bitmasks */
+/* bits 0:3, frames or uframes that SW needs to queue transactions
+ * ahead of the HW to meet periodic deadlines */
+#define HCS_IST(p)		(((p) >> 0) & 0xf)
+/* bits 4:7, max number of Event Ring segments */
+#define HCS_ERST_MAX(p)		(((p) >> 4) & 0xf)
+/* bits 21:25 Hi 5 bits of Scratchpad buffers SW must allocate for the HW */
+/* bit 26 Scratchpad restore - for save/restore HW state - not used yet */
+/* bits 27:31 Lo 5 bits of Scratchpad buffers SW must allocate for the HW */
+#define HCS_MAX_SCRATCHPAD(p)   ((((p) >> 16) & 0x3e0) | (((p) >> 27) & 0x1f))
+
+/* HCSPARAMS3 - hcs_params3 - bitmasks */
+/* bits 0:7, Max U1 to U0 latency for the roothub ports */
+#define HCS_U1_LATENCY(p)	(((p) >> 0) & 0xff)
+/* bits 16:31, Max U2 to U0 latency for the roothub ports */
+#define HCS_U2_LATENCY(p)	(((p) >> 16) & 0xffff)
+
+/* HCCPARAMS - hcc_params - bitmasks */
+/* true: HC can use 64-bit address pointers */
+#define HCC_64BIT_ADDR(p)	((p) & (1 << 0))
+/* true: HC can do bandwidth negotiation */
+#define HCC_BANDWIDTH_NEG(p)	((p) & (1 << 1))
+/* true: HC uses 64-byte Device Context structures
+ * FIXME 64-byte context structures aren't supported yet.
+ */
+#define HCC_64BYTE_CONTEXT(p)	((p) & (1 << 2))
+/* true: HC has port power switches */
+#define HCC_PPC(p)		((p) & (1 << 3))
+/* true: HC has port indicators */
+#define HCS_INDICATOR(p)	((p) & (1 << 4))
+/* true: HC has Light HC Reset Capability */
+#define HCC_LIGHT_RESET(p)	((p) & (1 << 5))
+/* true: HC supports latency tolerance messaging */
+#define HCC_LTC(p)		((p) & (1 << 6))
+/* true: no secondary Stream ID Support */
+#define HCC_NSS(p)		((p) & (1 << 7))
+/* true: HC supports Stopped - Short Packet */
+#define HCC_SPC(p)		((p) & (1 << 9))
+/* true: HC has Contiguous Frame ID Capability */
+#define HCC_CFC(p)		((p) & (1 << 11))
+/* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15 */
+#define HCC_MAX_PSA(p)		(1 << ((((p) >> 12) & 0xf) + 1))
+/* Extended Capabilities pointer from PCI base - section 5.3.6 */
+#define HCC_EXT_CAPS(p)		XHCI_HCC_EXT_CAPS(p)
+
+#define CTX_SIZE(_hcc)		(HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32)
+
+/* db_off bitmask - bits 0:1 reserved */
+#define	DBOFF_MASK	(~0x3)
+
+/* run_regs_off bitmask - bits 0:4 reserved */
+#define	RTSOFF_MASK	(~0x1f)
+
+/* HCCPARAMS2 - hcc_params2 - bitmasks */
+/* true: HC supports U3 entry Capability */
+#define	HCC2_U3C(p)		((p) & (1 << 0))
+/* true: HC supports Configure endpoint command Max exit latency too large */
+#define	HCC2_CMC(p)		((p) & (1 << 1))
+/* true: HC supports Force Save context Capability */
+#define	HCC2_FSC(p)		((p) & (1 << 2))
+/* true: HC supports Compliance Transition Capability */
+#define	HCC2_CTC(p)		((p) & (1 << 3))
+/* true: HC support Large ESIT payload Capability > 48k */
+#define	HCC2_LEC(p)		((p) & (1 << 4))
+/* true: HC support Configuration Information Capability */
+#define	HCC2_CIC(p)		((p) & (1 << 5))
+/* true: HC support Extended TBC Capability, Isoc burst count > 65535 */
+#define	HCC2_ETC(p)		((p) & (1 << 6))
drivers/usb/host/xhci-port.h new file +176 -0

176 lines not on this page · raw message

drivers/usb/host/xhci.h +3 -259

280 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v4 2/3 dt-bindings: usb: dwc3: Add snps,host-vbus-glitches-quirk avoid vbus glitch

In reply to Frank Li

From: Ran Wang <[email protected]>

When DWC3 is set to host mode by programming register DWC3_GCTL, VBUS (or its control signal) will turn on immediately on related Root Hub ports. Then the VBUS will be de-asserted for a little while during xhci reset (conducted by xhci driver) for a little while and back to normal.

This VBUS glitch might cause some USB devices emuration fail if kernel boot with them connected. One SW workaround which can fix this is to program all PORTSC[PP] to 0 to turn off VBUS immediately after setting host mode in DWC3 driver(per signal measurement result, it will be too late to do it in xhci-plat.c or xhci.c).

---
 Documentation/devicetree/bindings/usb/snps,dwc3.yaml | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/usb/snps,dwc3.yaml +7 -0
index 203a1eb66691f..8f5d250070c78 100644
@@ -273,6 +273,13 @@ properties:
       with an external supply.
     type: boolean
 
+  snps,host-vbus-glitches-quirk:
+    description:
+      When set, power off all Root Hub ports immediately after
+      setting host mode to avoid vbus (negative) glitch happen in later
+      xhci reset. And the vbus will back to 5V automatically when reset done.
+    type: boolean
+
   snps,is-utmi-l1-suspend:
     description:
       True when DWC3 asserts output signal utmi_l1_suspend_n, false when
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v4 2/3] dt-bindings: usb: dwc3: Add snps,host-vbus-glitches-quirk avoid vbus glitch

Hey,

This version seems to be the lastest (v4) for this binding, but went out prior to discussion actually finishing on the v1!! of this patch, even ignoring Rob's comment today.
Please wait for conversations to resolve before sending new versions. I, at least, do not get paid for what I do here, so I often need well more than a day before I can get around to clearing my review queue.

Quoted 13 lines · Frank Li

From: Ran Wang <[email protected]>

When DWC3 is set to host mode by programming register DWC3_GCTL, VBUS (or its control signal) will turn on immediately on related Root Hub ports. Then the VBUS will be de-asserted for a little while during xhci reset (conducted by xhci driver) for a little while and back to normal.

This VBUS glitch might cause some USB devices emuration fail if kernel boot with them connected. One SW workaround which can fix this is to program all PORTSC[PP] to 0 to turn off VBUS immediately after setting host mode in DWC3 driver(per signal measurement result, it will be too late to do it in xhci-plat.c or xhci.c).

Quoted 4 lines

---

Where is your changelog?

Documentation/devicetree/bindings/usb/snps,dwc3.yaml properties: · line 276

Quoted 12 lines
 Documentation/devicetree/bindings/usb/snps,dwc3.yaml | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/usb/snps,dwc3.yaml +1 -0
index 203a1eb66691f..8f5d250070c78 100644
@@ -273,6 +273,13 @@ properties:
       with an external supply.
     type: boolean
 
+  snps,host-vbus-glitches-quirk:

I specifically recall saying no to adding "-quirk" here, but that might've been after this patch was sent.

Documentation/devicetree/bindings/usb/snps,dwc3.yaml properties: · line 281

Quoted 5 lines
Documentation/devicetree/bindings/usb/snps,dwc3.yaml +5 -0
+    description:
+      When set, power off all Root Hub ports immediately after
+      setting host mode to avoid vbus (negative) glitch happen in later
+      xhci reset. And the vbus will back to 5V automatically when reset done.
+    type: boolean

Rob commented today on the v1 conversation:
https://lore.kernel.org/all/[email protected]/

Please respond (there) to his comment.

Thanks,
Conor.

Quoted 6 lines
Documentation/devicetree/bindings/usb/snps,dwc3.yaml +0 -0
   snps,is-utmi-l1-suspend:
     description:
       True when DWC3 asserts output signal utmi_l1_suspend_n, false when
Signature · 1 line
2.34.1
author maintainer
#4 lore raw

Re: [PATCH v4 2/3] dt-bindings: usb: dwc3: Add snps,host-vbus-glitches-quirk avoid vbus glitch

Quoted 23 lines · Conor Dooley

Hey,

This version seems to be the lastest (v4) for this binding, but went out prior to discussion actually finishing on the v1!! of this patch, even ignoring Rob's comment today.
Please wait for conversations to resolve before sending new versions. I, at least, do not get paid for what I do here, so I often need well more than a day before I can get around to clearing my review queue.

Quoted 13 lines · Frank Li

From: Ran Wang <[email protected]>

When DWC3 is set to host mode by programming register DWC3_GCTL, VBUS (or its control signal) will turn on immediately on related Root Hub ports. Then the VBUS will be de-asserted for a little while during xhci reset (conducted by xhci driver) for a little while and back to normal.

This VBUS glitch might cause some USB devices emuration fail if kernel boot with them connected. One SW workaround which can fix this is to program all PORTSC[PP] to 0 to turn off VBUS immediately after setting host mode in DWC3 driver(per signal measurement result, it will be too late to do it in xhci-plat.c or xhci.c).

Quoted 6 lines
Quoted 4 lines

---

Where is your changelog?

Sorry forget add it this patch.

Quoted 12 lines
Quoted 12 lines
 Documentation/devicetree/bindings/usb/snps,dwc3.yaml | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/usb/snps,dwc3.yaml +0 -0
index 203a1eb66691f..8f5d250070c78 100644
@@ -273,6 +273,13 @@ properties:
       with an external supply.
     type: boolean
 
Quoted 4 lines

Documentation/devicetree/bindings/usb/snps,dwc3.yaml properties: · line 276

Quoted 1 line
Documentation/devicetree/bindings/usb/snps,dwc3.yaml +1 -0
+  snps,host-vbus-glitches-quirk:

I specifically recall saying no to adding "-quirk" here, but that might've been after this patch was sent.

Your comment is at v0 version. I told you there are v4.

Quoted 11 lines

Documentation/devicetree/bindings/usb/snps,dwc3.yaml properties: · line 281

Quoted 6 lines
Documentation/devicetree/bindings/usb/snps,dwc3.yaml +5 -0
+    description:
+      When set, power off all Root Hub ports immediately after
+      setting host mode to avoid vbus (negative) glitch happen in later
+      xhci reset. And the vbus will back to 5V automatically when reset done.
+    type: boolean

Rob commented today on the v1 conversation:
https://lore.kernel.org/all/[email protected]/

Please respond (there) to his comment.

Okay I will reply at v1 thread.

Quoted 10 lines

Thanks,
Conor.

Quoted 6 lines
Documentation/devicetree/bindings/usb/snps,dwc3.yaml +0 -0
   snps,is-utmi-l1-suspend:
     description:
       True when DWC3 asserts output signal utmi_l1_suspend_n, false when
Signature · 1 line
2.34.1
author maintainer
#5 lore raw

PATCH v4 3/3 usb: dwc3: Add workaround for host mode VBUS glitch when boot

In reply to Frank Li

From: Ran Wang <[email protected]>

When DWC3 is set to host mode by programming register DWC3_GCTL, VBUS (or its control signal) will be turned on immediately on related Root Hub ports. Then, the VBUS is turned off for a little while(15us) when do xhci reset (conducted by xhci driver) and back to normal finally, we can observe a negative glitch of related signal happen.

This VBUS glitch might cause some USB devices enumeration fail if kernel boot with them connected. Such as LS1012AFWRY/LS1043ARDB/LX2160AQDS /LS1088ARDB with Kingston 16GB USB2.0/Kingston USB3.0/JetFlash Transcend 4GB USB2.0 drives. The fail cases include enumerated as full-speed device or report wrong device descriptor, etc.

One SW workaround which can fix this is by programing all xhci PORTSC[PP] to 0 to turn off VBUS immediately after setting host mode in DWC3 driver (per signal measurement result, it will be too late to do it in xhci-plat.c or xhci.c). Then, after xhci reset complete in xhci driver, PORTSC[PP]s' value will back to 1 automatically and VBUS on at that time, no glitch happen and normal enumeration process has no impact.

---

Notes:
Chang from v3 to v4
- fix kernel-doc comments.
- fix ./script/kernel-doc check error.
- Add Thinh's ACK tag
Change from v2 to v3
- reversed christmas tree
- please move major change hunk to the top
- Reword "We have to ..." to "Some platforms need to ... "

Change from v1 to v2:
- split xhci.h
Last review at June 06, 2019. Fixed all review comments and sent again.

https://lore.kernel.org/linux-kernel/AM5PR0402MB2865979E26017BC5937DBBA5F1170@AM5PR0402MB2865.eurprd04.prod.outlook.com/

 drivers/usb/dwc3/core.c |  3 +++
 drivers/usb/dwc3/core.h |  2 ++
 drivers/usb/dwc3/host.c | 51 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+)
drivers/usb/dwc3/core.c +3 -0
index 3e55838c00014..3b68e8e45b8b9 100644
@@ -1626,6 +1626,9 @@ static void dwc3_get_properties(struct dwc3 *dwc)
 	dwc->dis_split_quirk = device_property_read_bool(dev,
 				"snps,dis-split-quirk");
 
+	dwc->host_vbus_glitches_quirk = device_property_read_bool(dev,
+				"snps,host-vbus-glitches-quirk");
+
 	dwc->lpm_nyet_threshold = lpm_nyet_threshold;
 	dwc->tx_de_emphasis = tx_de_emphasis;
 
drivers/usb/dwc3/core.h +2 -0
index e3eea965e57bf..df544ec730d22 100644
@@ -1132,6 +1132,7 @@ struct dwc3_scratchpad_array {
  *	2	- No de-emphasis
  *	3	- Reserved
  * @dis_metastability_quirk: set to disable metastability quirk.
+ * @host_vbus_glitches_quirk: set to avoid vbus glitch during xhci reset.
  * @dis_split_quirk: set to disable split boundary.
  * @wakeup_configured: set if the device is configured for remote wakeup.
  * @suspended: set to track suspend event due to U3/L2.
@@ -1353,6 +1354,7 @@ struct dwc3 {
 	unsigned		tx_de_emphasis:2;
 
 	unsigned		dis_metastability_quirk:1;
+	unsigned		host_vbus_glitches_quirk:1;
 
 	unsigned		dis_split_quirk:1;
 	unsigned		async_callbacks:1;
drivers/usb/dwc3/host.c +51 -0

65 lines not on this page · raw message

Signature · 1 line
2.34.1