git: ae33d74d47ef - stable/13 - dwc3: improve debugging

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Mon, 18 Jul 2022 09:50:13 UTC
The branch stable/13 has been updated by bz:

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

commit ae33d74d47ef014ebbd4f07d49b3bd81dfac2707
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-07-02 21:10:00 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-07-18 01:00:21 +0000

    dwc3: improve debugging
    
    Rather than hiding behind #if 0, hide the debugging behind DWC3_DEBUG
    so it can be turned on with a single define.  Require bootverbose
    to print anything so we can still avoid spamming the console if DWC3_DEBUG
    is on.
    Harmonize the format string in snsp_dwc3_dump_regs() to always print the
    full register and also print the XHCI quirks.
    Call snsp_dwc3_dump_regs() twice, before and after generic XHCI attachment
    and initialisation as this may have an effect on the confirgumation state.
    
    Obtained from:  an old debug patch
    Reviewed by:    mw
    Differential Revision: https://reviews.freebsd.org/D35700
    
    (cherry picked from commit 11a7d5e5d906f691558e06d4bb93b892de31b446)
---
 sys/dev/usb/controller/dwc3.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/sys/dev/usb/controller/dwc3.c b/sys/dev/usb/controller/dwc3.c
index 596fcb19ce1a..cf51de36f354 100644
--- a/sys/dev/usb/controller/dwc3.c
+++ b/sys/dev/usb/controller/dwc3.c
@@ -147,22 +147,33 @@ snps_dwc3_attach_xhci(device_t dev)
 	return (0);
 }
 
-#if 0
+#ifdef DWC3_DEBUG
 static void
-snsp_dwc3_dump_regs(struct snps_dwc3_softc *sc)
+snsp_dwc3_dump_regs(struct snps_dwc3_softc *sc, const char *msg)
 {
+	struct xhci_softc *xsc;
 	uint32_t reg;
 
+	if (!bootverbose)
+		return;
+
+	device_printf(sc->dev, "%s: %s:\n", __func__, msg ? msg : "");
+
 	reg = DWC3_READ(sc, DWC3_GCTL);
-	device_printf(sc->dev, "GCTL: %x\n", reg);
+	device_printf(sc->dev, "GCTL: %#012x\n", reg);
+	reg = DWC3_READ(sc, DWC3_GUCTL);
+	device_printf(sc->dev, "GUCTL: %#012x\n", reg);
 	reg = DWC3_READ(sc, DWC3_GUCTL1);
-	device_printf(sc->dev, "GUCTL1: %x\n", reg);
+	device_printf(sc->dev, "GUCTL1: %#012x\n", reg);
 	reg = DWC3_READ(sc, DWC3_GUSB2PHYCFG0);
-	device_printf(sc->dev, "GUSB2PHYCFG0: %x\n", reg);
+	device_printf(sc->dev, "GUSB2PHYCFG0: %#012x\n", reg);
 	reg = DWC3_READ(sc, DWC3_GUSB3PIPECTL0);
-	device_printf(sc->dev, "GUSB3PIPECTL0: %x\n", reg);
+	device_printf(sc->dev, "GUSB3PIPECTL0: %#012x\n", reg);
 	reg = DWC3_READ(sc, DWC3_DCFG);
-	device_printf(sc->dev, "DCFG: %x\n", reg);
+	device_printf(sc->dev, "DCFG: %#012x\n", reg);
+
+	xsc = &sc->sc;
+	device_printf(sc->dev, "xhci quirks: %#012x\n", xsc->sc_quirks);
 }
 #endif
 
@@ -385,10 +396,14 @@ snps_dwc3_attach(device_t dev)
 	snps_dwc3_configure_host(sc);
 	snps_dwc3_configure_phy(sc);
 	snps_dwc3_do_quirks(sc);
-#if 0
-	snsp_dwc3_dump_regs(sc);
+
+#ifdef DWC3_DEBUG
+	snsp_dwc3_dump_regs(sc, "Pre XHCI init");
 #endif
 	snps_dwc3_attach_xhci(dev);
+#ifdef DWC3_DEBUG
+	snsp_dwc3_dump_regs(sc, "Post XHCI init");
+#endif
 
 	return (0);
 }