Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Oct 2023 01:44:16 GMT
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 05a0e28167d5 - stable/13 - xhci: Add support for 64-bit DMA in generic XHCI controller driver
Message-ID:  <202310040144.3941iGcU020567@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kevans:

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

commit 05a0e28167d5ab68762ad0a56d6dc9af4ed48d55
Author:     Stephen J. Kiernan <stevek@FreeBSD.org>
AuthorDate: 2023-08-11 16:06:02 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2023-10-04 01:42:34 +0000

    xhci: Add support for 64-bit DMA in generic XHCI controller driver
    
    The XHCI controller on 64-bit SoCs need to use 64-bit DMA.
    Add a quirk to tell the generic XHCI driver that 32-bit DMA needs
    to be used, if there are any that may need to use 32-bit DMA only.
    
    PR:             274237
    Reviewed by:    andrew
    Obtained from:  Juniper Networks, Inc.
    
    (cherry picked from commit 332af8c25dfc9857e997817281d7b7fa406783ef)
---
 sys/dev/usb/controller/generic_xhci.c     |  9 ++++++++-
 sys/dev/usb/controller/generic_xhci_fdt.c | 20 +++++++++++++++-----
 sys/dev/usb/controller/xhci.h             |  1 +
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/sys/dev/usb/controller/generic_xhci.c b/sys/dev/usb/controller/generic_xhci.c
index e0caf8f42af5..e89d1bc84497 100644
--- a/sys/dev/usb/controller/generic_xhci.c
+++ b/sys/dev/usb/controller/generic_xhci.c
@@ -61,7 +61,13 @@
 
 #include "generic_xhci.h"
 
+#if __SIZEOF_LONG__ == 8
+#define	IS_DMA_32B	0
+#elif __SIZEOF_LONG__ == 4
 #define	IS_DMA_32B	1
+#else
+#error unsupported long size
+#endif
 
 int
 generic_xhci_attach(device_t dev)
@@ -114,7 +120,8 @@ generic_xhci_attach(device_t dev)
 		return (err);
 	}
 
-	err = xhci_init(sc, dev, IS_DMA_32B);
+	err = xhci_init(sc, dev,
+	    (sc->sc_quirks & XHCI_QUIRK_DMA_32B) == 0 ? IS_DMA_32B : 1);
 	if (err != 0) {
 		device_printf(dev, "Failed to init XHCI, with error %d\n", err);
 		generic_xhci_detach(dev);
diff --git a/sys/dev/usb/controller/generic_xhci_fdt.c b/sys/dev/usb/controller/generic_xhci_fdt.c
index 8af9591a86b4..c850d2fb1314 100644
--- a/sys/dev/usb/controller/generic_xhci_fdt.c
+++ b/sys/dev/usb/controller/generic_xhci_fdt.c
@@ -55,12 +55,16 @@
 
 #include "generic_xhci.h"
 
+/* Flags for the OFW compat data table */
+#define	XHCI_FDT_MATCH		0x01
+#define	XHCI_FDT_32BIT_DMA	0x02	/* Controller needs 32-bit DMA */
+
 static struct ofw_compat_data compat_data[] = {
-	{"marvell,armada-380-xhci",	true},
-	{"marvell,armada3700-xhci",	true},
-	{"marvell,armada-8k-xhci",	true},
-	{"generic-xhci",		true},
-	{NULL,				false}
+	{"marvell,armada-380-xhci",	XHCI_FDT_MATCH},
+	{"marvell,armada3700-xhci",	XHCI_FDT_MATCH},
+	{"marvell,armada-8k-xhci",	XHCI_FDT_MATCH},
+	{"generic-xhci",		XHCI_FDT_MATCH},
+	{NULL,				0}
 };
 
 static int
@@ -81,14 +85,20 @@ generic_xhci_fdt_probe(device_t dev)
 static int
 generic_xhci_fdt_attach(device_t dev)
 {
+	struct xhci_softc *sc = device_get_softc(dev);
 	phandle_t node;
 	phy_t phy;
+	int flags;
 
 	node = ofw_bus_get_node(dev);
 	if (phy_get_by_ofw_property(dev, node, "usb-phy", &phy) == 0)
 		if (phy_enable(phy) != 0)
 			device_printf(dev, "Cannot enable phy\n");
 
+	flags = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
+	if ((flags & XHCI_FDT_32BIT_DMA) != 0)
+		sc->sc_quirks |= XHCI_QUIRK_DMA_32B;
+
 	return (generic_xhci_attach(dev));
 }
 
diff --git a/sys/dev/usb/controller/xhci.h b/sys/dev/usb/controller/xhci.h
index 0be0d185a869..3758815238ad 100644
--- a/sys/dev/usb/controller/xhci.h
+++ b/sys/dev/usb/controller/xhci.h
@@ -488,6 +488,7 @@ typedef int (xhci_port_route_t)(device_t, uint32_t, uint32_t);
 
 enum xhci_quirks {
 	XHCI_QUIRK_DISABLE_PORT_PED			= 0x00000001,
+	XHCI_QUIRK_DMA_32B				= 0x00000002,
 };
 
 struct xhci_softc {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202310040144.3941iGcU020567>