From nobody Mon Jul 18 09:50:12 2022 X-Original-To: dev-commits-src-all@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 4Lmcdc2xmpz4WtCK; Mon, 18 Jul 2022 09:50:12 +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 4Lmcdc2Vcvz3D2k; Mon, 18 Jul 2022 09:50:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658137812; 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=kQSqgqTiKk7QuwT7oV35U014fml6A1WtwEOy6kZu3s0=; b=nPqm74pGw+L/2B/eqlL10KvZoENWVOBhx5cyhh1+Z29wX0abNMKJT5QmQM9Hn0kWxztf5r F0wZ393HqEDEWQ3SdDHtCp/fVQ9AW1VB/9a28ZAePWyPxVHa/7Lmik4+HRfGx6dnSavqha 6w41tB0jXbvVUsIr8z3khGI5lTP6Gsm0ka8j5KnyzddS6O9gcGwSqGq4pWvgnR4hMUzVTS 2TRYLKbedxYkTzRlc0qL9TE2MSeQkz+fhmlr8RHE7JP8KnocysrwUimAc0wNs4egGyGyXz HnM22yOv2zZKrTN/kUpnDMZS+DG9LQNEn2i6zKpTXt6qw7PWyC/8N13QZRsovA== 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 4Lmcdc1YCjzb2Q; Mon, 18 Jul 2022 09:50:12 +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 26I9oC1M034989; Mon, 18 Jul 2022 09:50:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26I9oCKZ034987; Mon, 18 Jul 2022 09:50:12 GMT (envelope-from git) Date: Mon, 18 Jul 2022 09:50:12 GMT Message-Id: <202207180950.26I9oCKZ034987@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: a7717dc610eb - stable/13 - dwc3: add more quirks and checks List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: a7717dc610ebe5ce9d1fa21ce84a8e6766b5e60b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658137812; 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=kQSqgqTiKk7QuwT7oV35U014fml6A1WtwEOy6kZu3s0=; b=dbvXOpRaiAwomi8ksFZAl2BkGgykrgHoz2zDtFIi5YMt/E/7MTN85zHXkE3mttMfY5rZnG WYuYJq5sJ74RH6NzC+xDSc4vpSFIpSd/FOHGvSVYapgQEoyjh1sMMjWG/KK/FyPDmySjHY /xwGNiemBv2vzXDYHHiZcp/jVr/jBWSccqIyH7oxijD3214fIeOdMvaNQ15DPfGrGXOeF7 Jsny0/EyvQr2R/KtbzL2T34Y6iygAS6y4r7xmeeorr89lTbrl9flLc3NanH2FMEgJste7b aOfsBJQCqJK9ejeKcrkYV+dTiGYR4/ZuCqdXmUkefHbuqG2tAP/1+9NhMGHCsA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1658137812; a=rsa-sha256; cv=none; b=dPWDOPBBnXD/o1XJ/H8uGZI7enFC4vWPmzSfojaWIQt8xOUnB9VRFB4Ewq7II+V5JfRuG7 rNM1Tld2GEKJhIVmd8qz8xjzHswm5b+S0w62XZfIa6SLOsxwzda9W7aiz+ZhZ2qd3XY36s JMRcCeCcwp4csOLV/320ayrUcfhilu8wWHYYa9fG5MpnZBM1S/uRlbHY2K7EbWw82n1MxJ ATclTR9U1eJdVhLFcNrnx9pfmGhNwU+decp/oDx30DigFXQcGMdM4Msz2z12+NbFZJTcGr m/YRpesmcdFjjvK6azuXKs9FPjJmjIR62Rnxmo0wZopzd3PcOWvk5JjFhf1wDQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=a7717dc610ebe5ce9d1fa21ce84a8e6766b5e60b commit a7717dc610ebe5ce9d1fa21ce84a8e6766b5e60b Author: Bjoern A. Zeeb AuthorDate: 2022-07-02 20:56:07 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-07-18 01:00:21 +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. Obtained from: an old debugging patch Reviewed by: mw (earlier version), mmel Differential Revision: https://reviews.freebsd.org/D35699 (cherry picked from commit 09cdf4878c621be4cd229fa88cdccdcdc8c101f7) (cherry picked from commit ec32fc2af52530e49d8a522ae29bf20b2e57603b) --- sys/dev/usb/controller/dwc3.c | 55 +++++++++++++++++++++++++++++++++++++++---- sys/dev/usb/controller/dwc3.h | 3 +++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/sys/dev/usb/controller/dwc3.c b/sys/dev/usb/controller/dwc3.c index b4156903874b..596fcb19ce1a 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,26 +166,54 @@ 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); if (sc->usb3_phy) phy_enable(sc->usb3_phy); + ghwp0 = DWC3_READ(sc, DWC3_GHWPARAMS0); + gctl = DWC3_READ(sc, DWC3_GCTL); gctl |= DWC3_GCTL_CORESOFTRESET; DWC3_WRITE(sc, DWC3_GCTL, gctl); 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 +278,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 +289,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 +308,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 +369,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))