git: 447c418da034 - main - USB: add quirks to XHCI

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Wed, 15 Jun 2022 21:10:15 UTC
The branch main has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=447c418da03454a2a00bc115a69c62055a6d5272

commit 447c418da03454a2a00bc115a69c62055a6d5272
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-06-14 16:39:31 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-06-15 21:08:58 +0000

    USB: add quirks to XHCI
    
    While XHCI is very generic some revisions of chipsets have problems.
    On dwc3 <= 3.00a Port Disable does not seem to work so we need to not
    enable it.
    For that introduce quirks to xhci so that controllers can steer
    certain features.  I would hope that this is and remains the only one.
    
    Obtained from:  an old patch mainly debugging other problems
    MFC after:      2 weeks
    Reviewed by:    hselasky
    Differential Revision: https://reviews.freebsd.org/D35482
---
 sys/dev/usb/controller/xhci.c | 3 ++-
 sys/dev/usb/controller/xhci.h | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/sys/dev/usb/controller/xhci.c b/sys/dev/usb/controller/xhci.c
index 15835d0a641b..039750cb0874 100644
--- a/sys/dev/usb/controller/xhci.c
+++ b/sys/dev/usb/controller/xhci.c
@@ -3392,7 +3392,8 @@ xhci_roothub_exec(struct usb_device *udev,
 			XWRITE4(sc, oper, port, v | XHCI_PS_PRC);
 			break;
 		case UHF_PORT_ENABLE:
-			XWRITE4(sc, oper, port, v | XHCI_PS_PED);
+			if ((sc->sc_quirks & XHCI_QUIRK_DISABLE_PORT_PED) == 0)
+				XWRITE4(sc, oper, port, v | XHCI_PS_PED);
 			break;
 		case UHF_PORT_POWER:
 			XWRITE4(sc, oper, port, v & ~XHCI_PS_PP);
diff --git a/sys/dev/usb/controller/xhci.h b/sys/dev/usb/controller/xhci.h
index e5c189697067..4701e62ba3e5 100644
--- a/sys/dev/usb/controller/xhci.h
+++ b/sys/dev/usb/controller/xhci.h
@@ -487,6 +487,10 @@ union xhci_hub_desc {
 
 typedef int (xhci_port_route_t)(device_t, uint32_t, uint32_t);
 
+enum xhci_quirks {
+	XHCI_QUIRK_DISABLE_PORT_PED			= 0x00000001,
+};
+
 struct xhci_softc {
 	struct xhci_hw_softc	sc_hw;
 	/* base device */
@@ -563,6 +567,9 @@ struct xhci_softc {
 
 	/* vendor string for root HUB */
 	char			sc_vendor[16];
+
+	/* XHCI quirks. */
+	uint32_t		sc_quirks;
 };
 
 #define	XHCI_CMD_LOCK(sc)	sx_xlock(&(sc)->sc_cmd_sx)