From nobody Sun Jul 03 22:19:39 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 1BE478A9EC7; Sun, 3 Jul 2022 22:19:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LbjzJ0G6Dz4Vj7; Sun, 3 Jul 2022 22:19:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656886780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yCDsaYffSdPnHz0VjrYR7XVSLxpyXMpvUQHVtdMTToc=; b=uxckl1JRq3aEnCaZDCu38Bj4ftqjctIphakW7xx1pfimB1dS+qHY/dryhmF/VD23RPa4be 0FClmtA0TCZYZaizXxParGtp/Eb8DCJZ9NM7l4tDItwj5gVV9KZ7omdGQ13NK38lQfHVkE fG1XbZjzDNF7L59k8rj5AWyGlXVZecahJqvuZh30ODAiOvoFMmf0kz2KIATuZ5HryoGqiN 8u8rX9FYW+8nr7WYirsz+n/AzGmHIfBfnj8JDT/V37SpCSZ5u9sL7GdqjVwNSyjOHeqfYD pw5kx5+B5HZ8O1Ink9kjFRYFYDSt+XW+k4r4qZd5gQSQKrNGdHPEiFaVAAheKA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D36EE2CC18; Sun, 3 Jul 2022 22:19:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 263MJdbU051041; Sun, 3 Jul 2022 22:19:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 263MJdDI051040; Sun, 3 Jul 2022 22:19:39 GMT (envelope-from git) Date: Sun, 3 Jul 2022 22:19:39 GMT Message-Id: <202207032219.263MJdDI051040@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 09cdf4878c62 - main - dwc3: add more quirks and checks List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 09cdf4878c621be4cd229fa88cdccdcdc8c101f7 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656886780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yCDsaYffSdPnHz0VjrYR7XVSLxpyXMpvUQHVtdMTToc=; b=eHMq/tsF8lwNLi5ZG13rU8wEFMBVVX1HaW2e3IF7YcRSp/ECcVua73igsd0aJPKid4cMTo nsa6itErYndWttmjIVvKYqp1AoSXrhlN4nuWRk5Jiv+Zx02DDQHiMk74oDkfpthzpXahKL ab97nVJxJwIII385lxl3rJK6sPRoKlSdT7hwnx2Ff7RJ2d4Us/cNcFN/gl68fbp+ytYm30 o1D37/1tE70ZnzmbCHhz03ADJBVp42Hq2OyjRkMFnEVVpxShad3jM4bGhHbuy3GzuTWqKD XXVc9HDJC8Q7dpcf6FpUbMTJTFiTnKCVfRvMWwT/SphIZ6x/J1vLhlQ6Ptt24w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656886780; a=rsa-sha256; cv=none; b=W3c6q7f6HKDT7Tv9QOfhmI2ocB8wsUYd0k5RXNiV9h3aYzScSttvB8V8swZ13eMNVMWsqh OMB4VPp6FTk8+wYB8fD1o9EaTs2U+zkncYAYy0mjyCOA9eGbawD85+TofLWPYJB6MTDrEl zMoimL8Uvcu+RddPT4VzMb+OsxKwEYFfP0QyD369yZ3EgkWB5HT0Rlub3xUGN5UI4hcPbu +kSjk8CURJbFHN0jvZuQypwUgbarmuJ30Aw8MqCYH4dmAt/DRmDiwNcjyOlSnsgA3dV6JG TeL3+mgold+P6hvp3Mj+9NUo9sr7IlhRPwqCZqcCqU7xZUXOdWOICcQ3mYyOtw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=09cdf4878c621be4cd229fa88cdccdcdc8c101f7 commit 09cdf4878c621be4cd229fa88cdccdcdc8c101f7 Author: Bjoern A. Zeeb AuthorDate: 2022-07-02 20:56:07 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-07-03 22:17:35 +0000 dwc3: add more quirks and checks Rather than just printing the Global SNPS ID Register store it as well so we can do a version check later. In addition, for debugging purposes, read the Global Hardware Parameters Registers and print them. Based on the snpsid disable an XHCI feature using a quirk prepared in 447c418da03454a2a00bc115a69c62055a6d5272. Add the "snps,dis_u3_susphy_quirk" quirk and handle Suspend USB3.0 SS PHY after power-on-reset/during core initialization (suggested to be cleared) based on the DWC3_GHWPARAMS0 register. MFC after: 2 weeks Obtained from: an old debugging patch Reviewed by: mw (earlier version), mmel Differential Revision: https://reviews.freebsd.org/D35699 --- sys/dev/usb/controller/dwc3.c | 54 +++++++++++++++++++++++++++++++++++++++---- sys/dev/usb/controller/dwc3.h | 3 +++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/sys/dev/usb/controller/dwc3.c b/sys/dev/usb/controller/dwc3.c index ac94a1327bcf..4b5109291cc4 100644 --- a/sys/dev/usb/controller/dwc3.c +++ b/sys/dev/usb/controller/dwc3.c @@ -79,6 +79,7 @@ struct snps_dwc3_softc { phandle_t node; phy_t usb2_phy; phy_t usb3_phy; + uint32_t snpsid; }; #define DWC3_WRITE(_sc, _off, _val) \ @@ -165,10 +166,30 @@ snsp_dwc3_dump_regs(struct snps_dwc3_softc *sc) } #endif +#ifdef DWC3_DEBUG +static void +snps_dwc3_dump_ctrlparams(struct snps_dwc3_softc *sc) +{ + const bus_size_t offs[] = { + DWC3_GHWPARAMS0, DWC3_GHWPARAMS1, DWC3_GHWPARAMS2, DWC3_GHWPARAMS3, + DWC3_GHWPARAMS4, DWC3_GHWPARAMS5, DWC3_GHWPARAMS6, DWC3_GHWPARAMS7, + DWC3_GHWPARAMS8, + }; + uint32_t reg; + int i; + + for (i = 0; i < nitems(offs); i++) { + reg = DWC3_READ(sc, offs[i]); + if (bootverbose) + device_printf(sc->dev, "hwparams[%d]: %#012x\n", i, reg); + } +} +#endif + static void snps_dwc3_reset(struct snps_dwc3_softc *sc) { - uint32_t gctl, phy2, phy3; + uint32_t gctl, ghwp0, phy2, phy3; if (sc->usb2_phy) phy_enable(sc->usb2_phy); @@ -179,12 +200,19 @@ snps_dwc3_reset(struct snps_dwc3_softc *sc) gctl |= DWC3_GCTL_CORESOFTRESET; DWC3_WRITE(sc, DWC3_GCTL, gctl); + ghwp0 = DWC3_READ(sc, DWC3_GHWPARAMS0); phy2 = DWC3_READ(sc, DWC3_GUSB2PHYCFG0); phy2 |= DWC3_GUSB2PHYCFG0_PHYSOFTRST; + if ((ghwp0 & DWC3_GHWPARAMS0_MODE_MASK) == + DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE) + phy2 &= ~DWC3_GUSB2PHYCFG0_SUSPENDUSB20; DWC3_WRITE(sc, DWC3_GUSB2PHYCFG0, phy2); phy3 = DWC3_READ(sc, DWC3_GUSB3PIPECTL0); phy3 |= DWC3_GUSB3PIPECTL0_PHYSOFTRST; + if ((ghwp0 & DWC3_GHWPARAMS0_MODE_MASK) == + DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE) + phy3 &= ~DWC3_GUSB3PIPECTL0_SUSPENDUSB3; DWC3_WRITE(sc, DWC3_GUSB3PIPECTL0, phy3); DELAY(1000); @@ -249,8 +277,10 @@ snps_dwc3_configure_phy(struct snps_dwc3_softc *sc) static void snps_dwc3_do_quirks(struct snps_dwc3_softc *sc) { - uint32_t reg; + struct xhci_softc *xsc; + uint32_t ghwp0, reg; + ghwp0 = DWC3_READ(sc, DWC3_GHWPARAMS0); reg = DWC3_READ(sc, DWC3_GUSB2PHYCFG0); if (device_has_property(sc->dev, "snps,dis-u2-freeclk-exists-quirk")) reg &= ~DWC3_GUSB2PHYCFG0_U2_FREECLK_EXISTS; @@ -258,7 +288,8 @@ snps_dwc3_do_quirks(struct snps_dwc3_softc *sc) reg |= DWC3_GUSB2PHYCFG0_U2_FREECLK_EXISTS; if (device_has_property(sc->dev, "snps,dis_u2_susphy_quirk")) reg &= ~DWC3_GUSB2PHYCFG0_SUSPENDUSB20; - else + else if ((ghwp0 & DWC3_GHWPARAMS0_MODE_MASK) == + DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE) reg |= DWC3_GUSB2PHYCFG0_SUSPENDUSB20; if (device_has_property(sc->dev, "snps,dis_enblslpm_quirk")) reg &= ~DWC3_GUSB2PHYCFG0_ENBLSLPM; @@ -276,7 +307,18 @@ snps_dwc3_do_quirks(struct snps_dwc3_softc *sc) reg &= ~DWC3_GUSB3PIPECTL0_DELAYP1TRANS; if (device_has_property(sc->dev, "snps,dis_rxdet_inp3_quirk")) reg |= DWC3_GUSB3PIPECTL0_DISRXDETINP3; + if (device_has_property(sc->dev, "snps,dis_u3_susphy_quirk")) + reg &= ~DWC3_GUSB3PIPECTL0_SUSPENDUSB3; + else if ((ghwp0 & DWC3_GHWPARAMS0_MODE_MASK) == + DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE) + reg |= DWC3_GUSB3PIPECTL0_SUSPENDUSB3; DWC3_WRITE(sc, DWC3_GUSB3PIPECTL0, reg); + + /* Port Disable does not work on <= 3.00a. Disable PORT_PED. */ + if ((sc->snpsid & 0xffff) <= 0x300a) { + xsc = &sc->sc; + xsc->sc_quirks |= XHCI_QUIRK_DISABLE_PORT_PED; + } } static int @@ -326,8 +368,12 @@ snps_dwc3_attach(device_t dev) sc->bst = rman_get_bustag(sc->mem_res); sc->bsh = rman_get_bushandle(sc->mem_res); + sc->snpsid = DWC3_READ(sc, DWC3_GSNPSID); if (bootverbose) - device_printf(dev, "snps id: %x\n", DWC3_READ(sc, DWC3_GSNPSID)); + device_printf(sc->dev, "snps id: %#012x\n", sc->snpsid); +#ifdef DWC3_DEBUG + snps_dwc3_dump_ctrlparams(sc); +#endif /* Get the phys */ sc->node = ofw_bus_get_node(dev); diff --git a/sys/dev/usb/controller/dwc3.h b/sys/dev/usb/controller/dwc3.h index 862e17b1bcd9..83951d327c8c 100644 --- a/sys/dev/usb/controller/dwc3.h +++ b/sys/dev/usb/controller/dwc3.h @@ -59,6 +59,8 @@ #define DWC3_GBUSERRADDRHI 0xc134 #define DWC3_GPRTBIMAPLO 0xc138 #define DWC3_GHWPARAMS0 0xc140 +#define DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE 0x2 +#define DWC3_GHWPARAMS0_MODE_MASK 0x3 #define DWC3_GHWPARAMS1 0xc144 #define DWC3_GHWPARAMS2 0xc148 #define DWC3_GHWPARAMS3 0xc14C @@ -93,6 +95,7 @@ #define DWC3_GUSB3PIPECTL0_PHYSOFTRST (1 << 31) #define DWC3_GUSB3PIPECTL0_DISRXDETINP3 (1 << 28) #define DWC3_GUSB3PIPECTL0_DELAYP1TRANS (1 << 18) +#define DWC3_GUSB3PIPECTL0_SUSPENDUSB3 (1 << 17) #define DWC3_GTXFIFOSIZ(x) (0xc300 + 0x4 * (x)) #define DWC3_GRXFIFOSIZ(x) (0xc380 + 0x4 * (x))