Skip to contentSkip to conversation

inherit dma configuration from parent dev

PATCH In review Sriram Dash 10 participants 25 messages Nov 17, 2016 – Jan 19, 2017

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

v5 cover inherit dma configuration from parent dev

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices.

The idea here is that you pass in the parent of_node along with the child device pointer, so it would behave exactly like the parent already does. The difference is that it also handles all the other attributes besides the mask.

Arnd Bergmann (6):
usb: separate out sysdev pointer from usb_bus
usb: chipidea: use bus->sysdev for DMA configuration
usb: ehci: fsl: use bus->sysdev for DMA configuration
usb: xhci: use bus->sysdev for DMA configuration
usb: dwc3: use bus->sysdev for DMA configuration
usb: dwc3: Do not set dma coherent mask

 drivers/usb/chipidea/core.c    |  3 ---
 drivers/usb/chipidea/host.c    |  3 ++-
 drivers/usb/chipidea/udc.c     | 10 +++++----
 drivers/usb/core/buffer.c      | 12 +++++------
 drivers/usb/core/hcd.c         | 48 +++++++++++++++++++++++++-----------------
 drivers/usb/core/usb.c         | 18 ++++++++--------
 drivers/usb/dwc3/core.c        | 27 ++++++++++++------------
 drivers/usb/dwc3/core.h        |  3 +++
 drivers/usb/dwc3/dwc3-exynos.c | 10 ---------
 drivers/usb/dwc3/dwc3-pci.c    | 10 +++++++++
 drivers/usb/dwc3/dwc3-st.c     |  1 -
 drivers/usb/dwc3/ep0.c         |  8 +++----
 drivers/usb/dwc3/gadget.c      | 33 +++++++++++++++--------------
 drivers/usb/dwc3/host.c        | 16 ++++++--------
 drivers/usb/host/ehci-fsl.c    |  4 ++--
 drivers/usb/host/xhci-mem.c    | 12 +++++------
 drivers/usb/host/xhci-plat.c   | 33 +++++++++++++++++++++++------
 drivers/usb/host/xhci.c        | 15 +++++++++----
 include/linux/usb.h            |  1 +
 include/linux/usb/hcd.h        |  3 +++
 20 files changed, 155 insertions(+), 115 deletions(-)
Signature · 1 line
2.1.0
#1 lore raw

PATCH v5 1/6 usb: separate out sysdev pointer from usb_bus

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices.

The idea here is that you pass in the parent of_node along with the child device pointer, so it would behave exactly like the parent already does. The difference is that it also handles all the other attributes besides the mask.

sysdev will represent the physical device, as seen from firmware or bus.Splitting the usb_bus->controller field into the Linux-internal device (used for the sysfs hierarchy, for printks and for power management) and a new pointer (used for DMA, DT enumeration and phy lookup) probably covers all that we really need.

Cc Felipe Balbi <[email protected]>
Cc Grygorii Strashko <[email protected]>
Cc Sinjan Kumar <[email protected]>
Cc David Fisher <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc "Thang Q. Nguyen" <[email protected]>
Cc Yoshihiro Shimoda <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Ming Lei <[email protected]>
Cc Jon Masters <[email protected]>
Cc Dann Frazier <[email protected]>
Cc Peter Chen <[email protected]>
Cc Leo Li <[email protected]>

---
Changes in v5:
- No update

Changes in v4:
- No update

Changes in v3:
- usb is_device_dma_capable instead of directly accessing dma props.

Changes in v2:
- Split the patch wrt driver

 drivers/usb/core/buffer.c | 12 ++++++------
 drivers/usb/core/hcd.c    | 48 ++++++++++++++++++++++++++++-------------------
 drivers/usb/core/usb.c    | 18 +++++++++---------
 include/linux/usb.h       |  1 +
 include/linux/usb/hcd.h   |  3 +++
 5 files changed, 48 insertions(+), 34 deletions(-)
drivers/usb/core/buffer.c +6 -6
index 98e39f9..a6cd44a 100644
@@ -63,7 +63,7 @@ int hcd_buffer_create(struct usb_hcd *hcd)
 	int		i, size;
 
 	if (!IS_ENABLED(CONFIG_HAS_DMA) ||
-	    (!hcd->self.controller->dma_mask &&
+	    (!is_device_dma_capable(hcd->self.sysdev) &&
 	     !(hcd->driver->flags & HCD_LOCAL_MEM)))
 		return 0;
 
@@ -72,7 +72,7 @@ int hcd_buffer_create(struct usb_hcd *hcd)
 		if (!size)
 			continue;
 		snprintf(name, sizeof(name), "buffer-%d", size);
-		hcd->pool[i] = dma_pool_create(name, hcd->self.controller,
+		hcd->pool[i] = dma_pool_create(name, hcd->self.sysdev,
 				size, size, 0);
 		if (!hcd->pool[i]) {
 			hcd_buffer_destroy(hcd);
@@ -127,7 +127,7 @@ void *hcd_buffer_alloc(
 
 	/* some USB hosts just use PIO */
 	if (!IS_ENABLED(CONFIG_HAS_DMA) ||
-	    (!bus->controller->dma_mask &&
+	    (!is_device_dma_capable(bus->sysdev) &&
 	     !(hcd->driver->flags & HCD_LOCAL_MEM))) {
 		*dma = ~(dma_addr_t) 0;
 		return kmalloc(size, mem_flags);
@@ -137,7 +137,7 @@ void *hcd_buffer_alloc(
 		if (size <= pool_max[i])
 			return dma_pool_alloc(hcd->pool[i], mem_flags, dma);
 	}
-	return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags);
+	return dma_alloc_coherent(hcd->self.sysdev, size, dma, mem_flags);
 }
 
 void hcd_buffer_free(
@@ -154,7 +154,7 @@ void hcd_buffer_free(
 		return;
 
 	if (!IS_ENABLED(CONFIG_HAS_DMA) ||
-	    (!bus->controller->dma_mask &&
+	    (!is_device_dma_capable(bus->sysdev) &&
 	     !(hcd->driver->flags & HCD_LOCAL_MEM))) {
 		kfree(addr);
 		return;
@@ -166,5 +166,5 @@ void hcd_buffer_free(
 			return;
 		}
 	}
-	dma_free_coherent(hcd->self.controller, size, addr, dma);
+	dma_free_coherent(hcd->self.sysdev, size, addr, dma);
 }
drivers/usb/core/hcd.c +29 -19

159 lines not on this page · raw message

drivers/usb/core/usb.c +9 -9
index 5921514..3abe83a 100644
@@ -450,9 +450,9 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
 	 * Note: calling dma_set_mask() on a USB device would set the
 	 * mask for the entire HCD, so don't do that.
 	 */
-	dev->dev.dma_mask = bus->controller->dma_mask;
-	dev->dev.dma_pfn_offset = bus->controller->dma_pfn_offset;
-	set_dev_node(&dev->dev, dev_to_node(bus->controller));
+	dev->dev.dma_mask = bus->sysdev->dma_mask;
+	dev->dev.dma_pfn_offset = bus->sysdev->dma_pfn_offset;
+	set_dev_node(&dev->dev, dev_to_node(bus->sysdev));
 	dev->state = USB_STATE_ATTACHED;
 	dev->lpm_disable_count = 1;
 	atomic_set(&dev->urbnum, 0);
@@ -800,7 +800,7 @@ struct urb *usb_buffer_map(struct urb *urb)
 	if (!urb
 			|| !urb->dev
 			|| !(bus = urb->dev->bus)
-			|| !(controller = bus->controller))
+			|| !(controller = bus->sysdev))
 		return NULL;
 
 	if (controller->dma_mask) {
@@ -838,7 +838,7 @@ void usb_buffer_dmasync(struct urb *urb)
 			|| !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
 			|| !urb->dev
 			|| !(bus = urb->dev->bus)
-			|| !(controller = bus->controller))
+			|| !(controller = bus->sysdev))
 		return;
 
 	if (controller->dma_mask) {
@@ -872,7 +872,7 @@ void usb_buffer_unmap(struct urb *urb)
 			|| !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
 			|| !urb->dev
 			|| !(bus = urb->dev->bus)
-			|| !(controller = bus->controller))
+			|| !(controller = bus->sysdev))
 		return;
 
 	if (controller->dma_mask) {
@@ -922,7 +922,7 @@ int usb_buffer_map_sg(const struct usb_device *dev, int is_in,
 
 	if (!dev
 			|| !(bus = dev->bus)
-			|| !(controller = bus->controller)
+			|| !(controller = bus->sysdev)
 			|| !controller->dma_mask)
 		return -EINVAL;
 
@@ -958,7 +958,7 @@ void usb_buffer_dmasync_sg(const struct usb_device *dev, int is_in,
 
 	if (!dev
 			|| !(bus = dev->bus)
-			|| !(controller = bus->controller)
+			|| !(controller = bus->sysdev)
 			|| !controller->dma_mask)
 		return;
 
@@ -986,7 +986,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
 
 	if (!dev
 			|| !(bus = dev->bus)
-			|| !(controller = bus->controller)
+			|| !(controller = bus->sysdev)
 			|| !controller->dma_mask)
 		return;
 
include/linux/usb.h +1 -0
index eba1f10..f3f5d8a 100644
@@ -354,6 +354,7 @@ struct usb_devmap {
  */
 struct usb_bus {
 	struct device *controller;	/* host/master side hardware */
+	struct device *sysdev;		/* as seen from firmware or bus */
 	int busnum;			/* Bus number (in order of reg) */
 	const char *bus_name;		/* stable id (PCI slot_name etc) */
 	u8 uses_dma;			/* Does the host controller use DMA? */
include/linux/usb/hcd.h +3 -0
index 66fc137..3860560 100644
@@ -437,6 +437,9 @@ extern int usb_hcd_alloc_bandwidth(struct usb_device *udev,
 		struct usb_host_interface *new_alt);
 extern int usb_hcd_get_frame_number(struct usb_device *udev);
 
+struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver,
+		struct device *sysdev, struct device *dev, const char *bus_name,
+		struct usb_hcd *primary_hcd);
 extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
 		struct device *dev, const char *bus_name);
 extern struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
Signature · 1 line
2.1.0
Tested-by on v5 1/6
#2 lore raw

Re: [PATCH v5 1/6] usb: separate out sysdev pointer from usb_bus

Hi all,

Quoted 41 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices.

The idea here is that you pass in the parent of_node along with the child device pointer, so it would behave exactly like the parent already does. The difference is that it also handles all the other attributes besides the mask.

sysdev will represent the physical device, as seen from firmware or bus.Splitting the usb_bus->controller field into the Linux-internal device (used for the sysfs hierarchy, for printks and for power management) and a new pointer (used for DMA, DT enumeration and phy lookup) probably covers all that we really need.

Cc Felipe Balbi <[email protected]>
Cc Grygorii Strashko <[email protected]>
Cc Sinjan Kumar <[email protected]>
Cc David Fisher <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc "Thang Q. Nguyen" <[email protected]>
Cc Yoshihiro Shimoda <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Ming Lei <[email protected]>
Cc Jon Masters <[email protected]>
Cc Dann Frazier <[email protected]>
Cc Peter Chen <[email protected]>
Cc Leo Li <[email protected]>

---
Changes in v5:
- No update

Changes in v4:
- No update

Quoted 6 lines

Changes in v3:
- usb is_device_dma_capable instead of directly accessing dma props.

Changes in v2:
- Split the patch wrt driver

I didn't notice this series had been reposted a few times. For some reason, this wasn't that easy to find in search engines... Anyway, when the whole series is applied, this fixes my XHCI probe issues for DWC3 host mode. Thanks!

But I noticed that Felipe has applied patches 5 and 6 in -next, while the rest are still outstanding. That means I hit the dma_mask WARN_ON() in xhci-plat.c, and it eventually fails to probe with -EIO still:

[    2.060272] ------------[ cut here ]------------
[    2.064908] WARNING: CPU: 5 PID: 1 at drivers/usb/host/xhci-plat.c:159 xhci_plat_probe+0x5c/0x444
...
[    2.288885] [<ffffff80084ed638>] xhci_plat_probe+0x5c/0x444
[    2.294456] [<ffffff800844519c>] platform_drv_probe+0x60/0xac
[    2.300200] [<ffffff8008443000>] driver_probe_device+0x12c/0x2a0
[    2.306204] [<ffffff80084431f8>] __driver_attach+0x84/0xb0
[    2.311687] [<ffffff8008441eb4>] bus_for_each_dev+0x9c/0xcc
[    2.317256] [<ffffff80084429fc>] driver_attach+0x2c/0x34
[    2.322566] [<ffffff800844255c>] bus_add_driver+0xf0/0x1f4
[    2.328049] [<ffffff8008443ebc>] driver_register+0x9c/0xe8
[    2.333530] [<ffffff80084450e0>] __platform_driver_register+0x60/0x6c
[    2.339968] [<ffffff8008c2f1ec>] xhci_plat_init+0x2c/0x34
[    2.345366] [<ffffff8008083208>] do_one_initcall+0xa4/0x13c
[    2.350936] [<ffffff8008c00d88>] kernel_init_freeable+0x1bc/0x274
[    2.357026] [<ffffff800874cce0>] kernel_init+0x18/0x104
[    2.362247] [<ffffff8008082e80>] ret_from_fork+0x10/0x50
[    2.374615] xhci-hcd: probe of xhci-hcd.1.auto failed with error -5
[    2.380962] ------------[ cut here ]------------
[    2.385588] WARNING: CPU: 4 PID: 1 at drivers/usb/host/xhci-plat.c:159 xhci_plat_probe+0x5c/0x444
...
[    2.637372] [<ffffff80084ed638>] xhci_plat_probe+0x5c/0x444
[    2.642941] [<ffffff800844519c>] platform_drv_probe+0x60/0xac
[    2.648685] [<ffffff8008443000>] driver_probe_device+0x12c/0x2a0
[    2.654688] [<ffffff80084431f8>] __driver_attach+0x84/0xb0
[    2.660170] [<ffffff8008441eb4>] bus_for_each_dev+0x9c/0xcc
[    2.665739] [<ffffff80084429fc>] driver_attach+0x2c/0x34
[    2.671048] [<ffffff800844255c>] bus_add_driver+0xf0/0x1f4
[    2.676532] [<ffffff8008443ebc>] driver_register+0x9c/0xe8
[    2.682012] [<ffffff80084450e0>] __platform_driver_register+0x60/0x6c
[    2.688450] [<ffffff8008c2f1ec>] xhci_plat_init+0x2c/0x34
[    2.693845] [<ffffff8008083208>] do_one_initcall+0xa4/0x13c
[    2.699415] [<ffffff8008c00d88>] kernel_init_freeable+0x1bc/0x274
[    2.705505] [<ffffff800874cce0>] kernel_init+0x18/0x104
[    2.710726] [<ffffff8008082e80>] ret_from_fork+0x10/0x50
[    2.716075] xhci-hcd: probe of xhci-hcd.2.auto failed with error -5

What's happening with patches 1-4?

Regards,
Brian

#3 lore raw

Re: [PATCH v5 1/6] usb: separate out sysdev pointer from usb_bus

Quoted 99 lines · Brian Norris

Hi all,

Quoted 41 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices.

The idea here is that you pass in the parent of_node along with the child device pointer, so it would behave exactly like the parent already does. The difference is that it also handles all the other attributes besides the mask.

sysdev will represent the physical device, as seen from firmware or bus.Splitting the usb_bus->controller field into the Linux-internal device (used for the sysfs hierarchy, for printks and for power management) and a new pointer (used for DMA, DT enumeration and phy lookup) probably covers all that we really need.

Cc Felipe Balbi <felipe.balbi-VuQAYsv1563Yd54FQh9/[email protected]>
Cc Grygorii Strashko <[email protected]>
Cc Sinjan Kumar <[email protected]>
Cc David Fisher <david.fisher1-HKixBCOQz3hWk0Htik3J/[email protected]>
Cc Catalin Marinas <[email protected]>
Cc "Thang Q. Nguyen" <[email protected]>
Cc Yoshihiro Shimoda <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Ming Lei <[email protected]>
Cc Jon Masters <[email protected]>
Cc Dann Frazier <[email protected]>
Cc Peter Chen <[email protected]>
Cc Leo Li <[email protected]>

---
Changes in v5:
- No update

Changes in v4:
- No update

Quoted 6 lines

Changes in v3:
- usb is_device_dma_capable instead of directly accessing dma props.

Changes in v2:
- Split the patch wrt driver

I didn't notice this series had been reposted a few times. For some reason, this wasn't that easy to find in search engines... Anyway, when the whole series is applied, this fixes my XHCI probe issues for DWC3 host mode. Thanks!

But I noticed that Felipe has applied patches 5 and 6 in -next, while the rest are still outstanding. That means I hit the dma_mask WARN_ON() in xhci-plat.c, and it eventually fails to probe with -EIO still:

[    2.060272] ------------[ cut here ]------------
[    2.064908] WARNING: CPU: 5 PID: 1 at drivers/usb/host/xhci-plat.c:159 xhci_plat_probe+0x5c/0x444
...
[    2.288885] [<ffffff80084ed638>] xhci_plat_probe+0x5c/0x444
[    2.294456] [<ffffff800844519c>] platform_drv_probe+0x60/0xac
[    2.300200] [<ffffff8008443000>] driver_probe_device+0x12c/0x2a0
[    2.306204] [<ffffff80084431f8>] __driver_attach+0x84/0xb0
[    2.311687] [<ffffff8008441eb4>] bus_for_each_dev+0x9c/0xcc
[    2.317256] [<ffffff80084429fc>] driver_attach+0x2c/0x34
[    2.322566] [<ffffff800844255c>] bus_add_driver+0xf0/0x1f4
[    2.328049] [<ffffff8008443ebc>] driver_register+0x9c/0xe8
[    2.333530] [<ffffff80084450e0>] __platform_driver_register+0x60/0x6c
[    2.339968] [<ffffff8008c2f1ec>] xhci_plat_init+0x2c/0x34
[    2.345366] [<ffffff8008083208>] do_one_initcall+0xa4/0x13c
[    2.350936] [<ffffff8008c00d88>] kernel_init_freeable+0x1bc/0x274
[    2.357026] [<ffffff800874cce0>] kernel_init+0x18/0x104
[    2.362247] [<ffffff8008082e80>] ret_from_fork+0x10/0x50
[    2.374615] xhci-hcd: probe of xhci-hcd.1.auto failed with error -5
[    2.380962] ------------[ cut here ]------------
[    2.385588] WARNING: CPU: 4 PID: 1 at drivers/usb/host/xhci-plat.c:159 xhci_plat_probe+0x5c/0x444
...
[    2.637372] [<ffffff80084ed638>] xhci_plat_probe+0x5c/0x444
[    2.642941] [<ffffff800844519c>] platform_drv_probe+0x60/0xac
[    2.648685] [<ffffff8008443000>] driver_probe_device+0x12c/0x2a0
[    2.654688] [<ffffff80084431f8>] __driver_attach+0x84/0xb0
[    2.660170] [<ffffff8008441eb4>] bus_for_each_dev+0x9c/0xcc
[    2.665739] [<ffffff80084429fc>] driver_attach+0x2c/0x34
[    2.671048] [<ffffff800844255c>] bus_add_driver+0xf0/0x1f4
[    2.676532] [<ffffff8008443ebc>] driver_register+0x9c/0xe8
[    2.682012] [<ffffff80084450e0>] __platform_driver_register+0x60/0x6c
[    2.688450] [<ffffff8008c2f1ec>] xhci_plat_init+0x2c/0x34
[    2.693845] [<ffffff8008083208>] do_one_initcall+0xa4/0x13c
[    2.699415] [<ffffff8008c00d88>] kernel_init_freeable+0x1bc/0x274
[    2.705505] [<ffffff800874cce0>] kernel_init+0x18/0x104
[    2.710726] [<ffffff8008082e80>] ret_from_fork+0x10/0x50
[    2.716075] xhci-hcd: probe of xhci-hcd.2.auto failed with error -5
Quoted 2 lines

What's happening with patches 1-4?

I can observe this warning also with 4.10-rc2

11.709204] ------------[ cut here ]------------

[   11.709218] WARNING: CPU: 0 PID: 163 at drivers/usb/host/xhci-plat.c:168 xhci_plat_probe+0x180/0x450 [xhci_plat_hcd]
[   11.709220] Modules linked in: xhci_plat_hcd(+) xhci_hcd usbcore dwc3 udc_core usb_common evdev snd_soc_simple_card snd_soc_simple_card_utils omapfb cfbfillrect cfbimgblt encoder_tpd12s015 connector_hdmi cfbcopyarea leds_gpi4
[   11.709308] CPU: 0 PID: 163 Comm: systemd-udevd Not tainted 4.10.0-rc2-00328-g0eeded4-dirty #124
[   11.709310] Hardware name: Generic DRA74X (Flattened Device Tree)
[   11.709326] [<c011013c>] (unwind_backtrace) from [<c010c300>] (show_stack+0x10/0x14)
[   11.709334] [<c010c300>] (show_stack) from [<c04a0038>] (dump_stack+0xac/0xe0)
[   11.709345] [<c04a0038>] (dump_stack) from [<c0137024>] (__warn+0xd8/0x104)
[   11.709354] [<c0137024>] (__warn) from [<c01370fc>] (warn_slowpath_null+0x20/0x28)
[   11.709365] [<c01370fc>] (warn_slowpath_null) from [<bf494280>] (xhci_plat_probe+0x180/0x450 [xhci_plat_hcd])
[   11.709401] [<bf494280>] (xhci_plat_probe [xhci_plat_hcd]) from [<c055f258>] (platform_drv_probe+0x4c/0xb0)
[   11.709409] [<c055f258>] (platform_drv_probe) from [<c055d2b4>] (driver_probe_device+0x200/0x2d4)
[   11.709418] [<c055d2b4>] (driver_probe_device) from [<c055d448>] (__driver_attach+0xc0/0xc4)
[   11.709426] [<c055d448>] (__driver_attach) from [<c055b730>] (bus_for_each_dev+0x6c/0xa0)
[   11.709434] [<c055b730>] (bus_for_each_dev) from [<c055c894>] (bus_add_driver+0x18c/0x214)
[   11.709441] [<c055c894>] (bus_add_driver) from [<c055e280>] (driver_register+0x78/0xf8)
[   11.709447] [<c055e280>] (driver_register) from [<c010188c>] (do_one_initcall+0x3c/0x174)
[   11.709454] [<c010188c>] (do_one_initcall) from [<c023c05c>] (do_init_module+0x5c/0x1d0)
[   11.709463] [<c023c05c>] (do_init_module) from [<c01da5c0>] (load_module+0x1d48/0x23a8)
[   11.709472] [<c01da5c0>] (load_module) from [<c01dae38>] (SyS_finit_module+0xa4/0xb8)
[   11.709481] [<c01dae38>] (SyS_finit_module) from [<c01079c8>] (__sys_trace_return+0x0/0x10)
[   11.709524] ---[ end trace 2744875bad6cd18f ]---
[   11.709757] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
Signature · 2 lines
regards,
-grygorii
Tested-by on v5 1/6
#4 lore raw

Re: [v5,1/6] usb: separate out sysdev pointer from usb_bus

In reply to Sriram Dash

Hi!

Quoted 17 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices.

The idea here is that you pass in the parent of_node along with the child device pointer, so it would behave exactly like the parent already does. The difference is that it also handles all the other attributes besides the mask.

sysdev will represent the physical device, as seen from firmware or bus.Splitting the usb_bus->controller field into the Linux-internal device (used for the sysfs hierarchy, for printks and for power management) and a new pointer (used for DMA, DT enumeration and phy lookup) probably covers all that we really need.

Quoted 3 lines

Successfully tested on arm64/axxia with DWC3 USB host, XHCIs properly inherit DMA configuration. Therefore:

Quoted 368 lines
Cc Felipe Balbi <[email protected]>
Cc Grygorii Strashko <[email protected]>
Cc Sinjan Kumar <[email protected]>
Cc David Fisher <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc "Thang Q. Nguyen" <[email protected]>
Cc Yoshihiro Shimoda <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Ming Lei <[email protected]>
Cc Jon Masters <[email protected]>
Cc Dann Frazier <[email protected]>
Cc Peter Chen <[email protected]>
Cc Leo Li <[email protected]>

---
Changes in v5:
- No update

Changes in v4:
- No update

Changes in v3:
- usb is_device_dma_capable instead of directly accessing dma props.

Changes in v2:
- Split the patch wrt driver

 drivers/usb/core/buffer.c | 12 ++++++------
 drivers/usb/core/hcd.c    | 48 ++++++++++++++++++++++++++++-------------------
 drivers/usb/core/usb.c    | 18 +++++++++---------
 include/linux/usb.h       |  1 +
 include/linux/usb/hcd.h   |  3 +++
 5 files changed, 48 insertions(+), 34 deletions(-)
drivers/usb/core/buffer.c +6 -6
index 98e39f9..a6cd44a 100644
@@ -63,7 +63,7 @@ int hcd_buffer_create(struct usb_hcd *hcd)
 	int		i, size;
 
 	if (!IS_ENABLED(CONFIG_HAS_DMA) ||
-	    (!hcd->self.controller->dma_mask &&
+	    (!is_device_dma_capable(hcd->self.sysdev) &&
 	     !(hcd->driver->flags & HCD_LOCAL_MEM)))
 		return 0;
 
@@ -72,7 +72,7 @@ int hcd_buffer_create(struct usb_hcd *hcd)
 		if (!size)
 			continue;
 		snprintf(name, sizeof(name), "buffer-%d", size);
-		hcd->pool[i] = dma_pool_create(name, hcd->self.controller,
+		hcd->pool[i] = dma_pool_create(name, hcd->self.sysdev,
 				size, size, 0);
 		if (!hcd->pool[i]) {
 			hcd_buffer_destroy(hcd);
@@ -127,7 +127,7 @@ void *hcd_buffer_alloc(
 
 	/* some USB hosts just use PIO */
 	if (!IS_ENABLED(CONFIG_HAS_DMA) ||
-	    (!bus->controller->dma_mask &&
+	    (!is_device_dma_capable(bus->sysdev) &&
 	     !(hcd->driver->flags & HCD_LOCAL_MEM))) {
 		*dma = ~(dma_addr_t) 0;
 		return kmalloc(size, mem_flags);
@@ -137,7 +137,7 @@ void *hcd_buffer_alloc(
 		if (size <= pool_max[i])
 			return dma_pool_alloc(hcd->pool[i], mem_flags, dma);
 	}
-	return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags);
+	return dma_alloc_coherent(hcd->self.sysdev, size, dma, mem_flags);
 }
 
 void hcd_buffer_free(
@@ -154,7 +154,7 @@ void hcd_buffer_free(
 		return;
 
 	if (!IS_ENABLED(CONFIG_HAS_DMA) ||
-	    (!bus->controller->dma_mask &&
+	    (!is_device_dma_capable(bus->sysdev) &&
 	     !(hcd->driver->flags & HCD_LOCAL_MEM))) {
 		kfree(addr);
 		return;
@@ -166,5 +166,5 @@ void hcd_buffer_free(
 			return;
 		}
 	}
-	dma_free_coherent(hcd->self.controller, size, addr, dma);
+	dma_free_coherent(hcd->self.sysdev, size, addr, dma);
 }
drivers/usb/core/hcd.c +29 -19
index 479e223..f8feb08 100644
@@ -1073,6 +1073,7 @@ static void usb_deregister_bus (struct usb_bus *bus)
 static int register_root_hub(struct usb_hcd *hcd)
 {
 	struct device *parent_dev = hcd->self.controller;
+	struct device *sysdev = hcd->self.sysdev;
 	struct usb_device *usb_dev = hcd->self.root_hub;
 	const int devnum = 1;
 	int retval;
@@ -1119,7 +1120,7 @@ static int register_root_hub(struct usb_hcd *hcd)
 		/* Did the HC die before the root hub was registered? */
 		if (HCD_DEAD(hcd))
 			usb_hc_died (hcd);	/* This time clean up */
-		usb_dev->dev.of_node = parent_dev->of_node;
+		usb_dev->dev.of_node = sysdev->of_node;
 	}
 	mutex_unlock(&usb_bus_idr_lock);
 
@@ -1465,19 +1466,19 @@ void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
 	dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
 	if (IS_ENABLED(CONFIG_HAS_DMA) &&
 	    (urb->transfer_flags & URB_DMA_MAP_SG))
-		dma_unmap_sg(hcd->self.controller,
+		dma_unmap_sg(hcd->self.sysdev,
 				urb->sg,
 				urb->num_sgs,
 				dir);
 	else if (IS_ENABLED(CONFIG_HAS_DMA) &&
 		 (urb->transfer_flags & URB_DMA_MAP_PAGE))
-		dma_unmap_page(hcd->self.controller,
+		dma_unmap_page(hcd->self.sysdev,
 				urb->transfer_dma,
 				urb->transfer_buffer_length,
 				dir);
 	else if (IS_ENABLED(CONFIG_HAS_DMA) &&
 		 (urb->transfer_flags & URB_DMA_MAP_SINGLE))
-		dma_unmap_single(hcd->self.controller,
+		dma_unmap_single(hcd->self.sysdev,
 				urb->transfer_dma,
 				urb->transfer_buffer_length,
 				dir);
@@ -1520,11 +1521,11 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
 			return ret;
 		if (IS_ENABLED(CONFIG_HAS_DMA) && hcd->self.uses_dma) {
 			urb->setup_dma = dma_map_single(
-					hcd->self.controller,
+					hcd->self.sysdev,
 					urb->setup_packet,
 					sizeof(struct usb_ctrlrequest),
 					DMA_TO_DEVICE);
-			if (dma_mapping_error(hcd->self.controller,
+			if (dma_mapping_error(hcd->self.sysdev,
 						urb->setup_dma))
 				return -EAGAIN;
 			urb->transfer_flags |= URB_SETUP_MAP_SINGLE;
@@ -1555,7 +1556,7 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
 				}
 
 				n = dma_map_sg(
-						hcd->self.controller,
+						hcd->self.sysdev,
 						urb->sg,
 						urb->num_sgs,
 						dir);
@@ -1570,12 +1571,12 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
 			} else if (urb->sg) {
 				struct scatterlist *sg = urb->sg;
 				urb->transfer_dma = dma_map_page(
-						hcd->self.controller,
+						hcd->self.sysdev,
 						sg_page(sg),
 						sg->offset,
 						urb->transfer_buffer_length,
 						dir);
-				if (dma_mapping_error(hcd->self.controller,
+				if (dma_mapping_error(hcd->self.sysdev,
 						urb->transfer_dma))
 					ret = -EAGAIN;
 				else
@@ -1585,11 +1586,11 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
 				ret = -EAGAIN;
 			} else {
 				urb->transfer_dma = dma_map_single(
-						hcd->self.controller,
+						hcd->self.sysdev,
 						urb->transfer_buffer,
 						urb->transfer_buffer_length,
 						dir);
-				if (dma_mapping_error(hcd->self.controller,
+				if (dma_mapping_error(hcd->self.sysdev,
 						urb->transfer_dma))
 					ret = -EAGAIN;
 				else
@@ -2511,8 +2512,8 @@ static void init_giveback_urb_bh(struct giveback_urb_bh *bh)
  * Return: On success, a pointer to the created and initialized HCD structure.
  * On failure (e.g. if memory is unavailable), %NULL.
  */
-struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
-		struct device *dev, const char *bus_name,
+struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver,
+		struct device *sysdev, struct device *dev, const char *bus_name,
 		struct usb_hcd *primary_hcd)
 {
 	struct usb_hcd *hcd;
@@ -2553,8 +2554,9 @@ struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
 
 	usb_bus_init(&hcd->self);
 	hcd->self.controller = dev;
+	hcd->self.sysdev = sysdev;
 	hcd->self.bus_name = bus_name;
-	hcd->self.uses_dma = (dev->dma_mask != NULL);
+	hcd->self.uses_dma = (sysdev->dma_mask != NULL);
 
 	init_timer(&hcd->rh_timer);
 	hcd->rh_timer.function = rh_timer_func;
@@ -2569,6 +2571,14 @@ struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
 			"USB Host Controller";
 	return hcd;
 }
+EXPORT_SYMBOL_GPL(__usb_create_hcd);
+
+struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
+		struct device *dev, const char *bus_name,
+		struct usb_hcd *primary_hcd)
+{
+	return __usb_create_hcd(driver, dev, dev, bus_name, primary_hcd);
+}
 EXPORT_SYMBOL_GPL(usb_create_shared_hcd);
 
 /**
@@ -2588,7 +2598,7 @@ EXPORT_SYMBOL_GPL(usb_create_shared_hcd);
 struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
 		struct device *dev, const char *bus_name)
 {
-	return usb_create_shared_hcd(driver, dev, bus_name, NULL);
+	return __usb_create_hcd(driver, dev, dev, bus_name, NULL);
 }
 EXPORT_SYMBOL_GPL(usb_create_hcd);
 
@@ -2715,7 +2725,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 	struct usb_device *rhdev;
 
 	if (IS_ENABLED(CONFIG_USB_PHY) && !hcd->usb_phy) {
-		struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller, 0);
+		struct usb_phy *phy = usb_get_phy_dev(hcd->self.sysdev, 0);
 
 		if (IS_ERR(phy)) {
 			retval = PTR_ERR(phy);
@@ -2733,7 +2743,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 	}
 
 	if (IS_ENABLED(CONFIG_GENERIC_PHY) && !hcd->phy) {
-		struct phy *phy = phy_get(hcd->self.controller, "usb");
+		struct phy *phy = phy_get(hcd->self.sysdev, "usb");
 
 		if (IS_ERR(phy)) {
 			retval = PTR_ERR(phy);
@@ -2781,7 +2791,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 	 */
 	retval = hcd_buffer_create(hcd);
 	if (retval != 0) {
-		dev_dbg(hcd->self.controller, "pool alloc failed\n");
+		dev_dbg(hcd->self.sysdev, "pool alloc failed\n");
 		goto err_create_buf;
 	}
 
@@ -2791,7 +2801,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 
 	rhdev = usb_alloc_dev(NULL, &hcd->self, 0);
 	if (rhdev == NULL) {
-		dev_err(hcd->self.controller, "unable to allocate root hub\n");
+		dev_err(hcd->self.sysdev, "unable to allocate root hub\n");
 		retval = -ENOMEM;
 		goto err_allocate_root_hub;
 	}
drivers/usb/core/usb.c +9 -9
index 5921514..3abe83a 100644
@@ -450,9 +450,9 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
 	 * Note: calling dma_set_mask() on a USB device would set the
 	 * mask for the entire HCD, so don't do that.
 	 */
-	dev->dev.dma_mask = bus->controller->dma_mask;
-	dev->dev.dma_pfn_offset = bus->controller->dma_pfn_offset;
-	set_dev_node(&dev->dev, dev_to_node(bus->controller));
+	dev->dev.dma_mask = bus->sysdev->dma_mask;
+	dev->dev.dma_pfn_offset = bus->sysdev->dma_pfn_offset;
+	set_dev_node(&dev->dev, dev_to_node(bus->sysdev));
 	dev->state = USB_STATE_ATTACHED;
 	dev->lpm_disable_count = 1;
 	atomic_set(&dev->urbnum, 0);
@@ -800,7 +800,7 @@ struct urb *usb_buffer_map(struct urb *urb)
 	if (!urb
 			|| !urb->dev
 			|| !(bus = urb->dev->bus)
-			|| !(controller = bus->controller))
+			|| !(controller = bus->sysdev))
 		return NULL;
 
 	if (controller->dma_mask) {
@@ -838,7 +838,7 @@ void usb_buffer_dmasync(struct urb *urb)
 			|| !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
 			|| !urb->dev
 			|| !(bus = urb->dev->bus)
-			|| !(controller = bus->controller))
+			|| !(controller = bus->sysdev))
 		return;
 
 	if (controller->dma_mask) {
@@ -872,7 +872,7 @@ void usb_buffer_unmap(struct urb *urb)
 			|| !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
 			|| !urb->dev
 			|| !(bus = urb->dev->bus)
-			|| !(controller = bus->controller))
+			|| !(controller = bus->sysdev))
 		return;
 
 	if (controller->dma_mask) {
@@ -922,7 +922,7 @@ int usb_buffer_map_sg(const struct usb_device *dev, int is_in,
 
 	if (!dev
 			|| !(bus = dev->bus)
-			|| !(controller = bus->controller)
+			|| !(controller = bus->sysdev)
 			|| !controller->dma_mask)
 		return -EINVAL;
 
@@ -958,7 +958,7 @@ void usb_buffer_dmasync_sg(const struct usb_device *dev, int is_in,
 
 	if (!dev
 			|| !(bus = dev->bus)
-			|| !(controller = bus->controller)
+			|| !(controller = bus->sysdev)
 			|| !controller->dma_mask)
 		return;
 
@@ -986,7 +986,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
 
 	if (!dev
 			|| !(bus = dev->bus)
-			|| !(controller = bus->controller)
+			|| !(controller = bus->sysdev)
 			|| !controller->dma_mask)
 		return;
 
include/linux/usb.h +1 -0
index eba1f10..f3f5d8a 100644
@@ -354,6 +354,7 @@ struct usb_devmap {
  */
 struct usb_bus {
 	struct device *controller;	/* host/master side hardware */
+	struct device *sysdev;		/* as seen from firmware or bus */
 	int busnum;			/* Bus number (in order of reg) */
 	const char *bus_name;		/* stable id (PCI slot_name etc) */
 	u8 uses_dma;			/* Does the host controller use DMA? */
include/linux/usb/hcd.h +3 -0
index 66fc137..3860560 100644
@@ -437,6 +437,9 @@ extern int usb_hcd_alloc_bandwidth(struct usb_device *udev,
 		struct usb_host_interface *new_alt);
 extern int usb_hcd_get_frame_number(struct usb_device *udev);
 
+struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver,
+		struct device *sysdev, struct device *dev, const char *bus_name,
+		struct usb_hcd *primary_hcd);
 extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
 		struct device *dev, const char *bus_name);
 extern struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
Signature · 2 lines
Best regards,
Alexander Sverdlin.
#5 lore raw

PATCH v5 2/6 usb: chipidea: use bus->sysdev for DMA configuration

In reply to Sriram Dash

From: Arnd Bergmann <[email protected]>

Set the dma for chipidea from sysdev. This is inherited from its parent node. Also, do not set dma mask for child as it is not required now.

---
Changes in v5:
- No update

Changes in v4:
- No update

Changes in v3:
- No update

Changes in v2:
- integrate chipidea driver changes together.

 drivers/usb/chipidea/core.c |  3 ---
 drivers/usb/chipidea/host.c |  3 ++-
 drivers/usb/chipidea/udc.c  | 10 ++++++----
 3 files changed, 8 insertions(+), 8 deletions(-)
drivers/usb/chipidea/core.c +0 -3
index 69426e6..8917a03 100644
@@ -833,9 +833,6 @@ struct platform_device *ci_hdrc_add_device(struct device *dev,
 	}
 
 	pdev->dev.parent = dev;
-	pdev->dev.dma_mask = dev->dma_mask;
-	pdev->dev.dma_parms = dev->dma_parms;
-	dma_set_coherent_mask(&pdev->dev, dev->coherent_dma_mask);
 
 	ret = platform_device_add_resources(pdev, res, nres);
 	if (ret)
drivers/usb/chipidea/host.c +2 -1
index 111b0e0b..3218b49 100644
@@ -116,7 +116,8 @@ static int host_start(struct ci_hdrc *ci)
 	if (usb_disabled())
 		return -ENODEV;
 
-	hcd = usb_create_hcd(&ci_ehci_hc_driver, ci->dev, dev_name(ci->dev));
+	hcd = __usb_create_hcd(&ci_ehci_hc_driver, ci->dev->parent,
+			       ci->dev, dev_name(ci->dev), NULL);
 	if (!hcd)
 		return -ENOMEM;
 
drivers/usb/chipidea/udc.c +6 -4
index a7b383d..891626a 100644
@@ -423,7 +423,8 @@ static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
 
 	hwreq->req.status = -EALREADY;
 
-	ret = usb_gadget_map_request(&ci->gadget, &hwreq->req, hwep->dir);
+	ret = usb_gadget_map_request_by_dev(ci->dev->parent,
+					    &hwreq->req, hwep->dir);
 	if (ret)
 		return ret;
 
@@ -603,7 +604,8 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
 		list_del_init(&node->td);
 	}
 
-	usb_gadget_unmap_request(&hwep->ci->gadget, &hwreq->req, hwep->dir);
+	usb_gadget_unmap_request_by_dev(hwep->ci->dev->parent,
+					&hwreq->req, hwep->dir);
 
 	hwreq->req.actual += actual;
 
@@ -1904,13 +1906,13 @@ static int udc_start(struct ci_hdrc *ci)
 	INIT_LIST_HEAD(&ci->gadget.ep_list);
 
 	/* alloc resources */
-	ci->qh_pool = dma_pool_create("ci_hw_qh", dev,
+	ci->qh_pool = dma_pool_create("ci_hw_qh", dev->parent,
 				       sizeof(struct ci_hw_qh),
 				       64, CI_HDRC_PAGE_SIZE);
 	if (ci->qh_pool == NULL)
 		return -ENOMEM;
 
-	ci->td_pool = dma_pool_create("ci_hw_td", dev,
+	ci->td_pool = dma_pool_create("ci_hw_td", dev->parent,
 				       sizeof(struct ci_hw_td),
 				       64, CI_HDRC_PAGE_SIZE);
 	if (ci->td_pool == NULL) {
Signature · 1 line
2.1.0
#6 lore raw

PATCH v5 3/6 usb: ehci: fsl: use bus->sysdev for DMA configuration

In reply to Sriram Dash

From: Arnd Bergmann <[email protected]>

For the dual role ehci fsl driver, sysdev will handle the dma config.

---
Changes in v5:
- No update

Changes in v4:
- No update
Changes in v3:
- fix compile errors
Changes in v2:
- fix compile warnings

 drivers/usb/host/ehci-fsl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-fsl.c +2 -2
index 9f5ffb6..4d4ab42 100644
@@ -96,8 +96,8 @@ static int fsl_ehci_drv_probe(struct platform_device *pdev)
 	}
 	irq = res->start;
 
-	hcd = usb_create_hcd(&fsl_ehci_hc_driver, &pdev->dev,
-				dev_name(&pdev->dev));
+	hcd = __usb_create_hcd(&fsl_ehci_hc_driver, pdev->dev.parent,
+			       &pdev->dev, dev_name(&pdev->dev), NULL);
 	if (!hcd) {
 		retval = -ENOMEM;
 		goto err1;
Signature · 1 line
2.1.0
#7 lore raw

PATCH v5 4/6 usb: xhci: use bus->sysdev for DMA configuration

In reply to Sriram Dash

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices. So, set the dma for xhci from sysdev. sysdev is pointing to device that is known to the system firmware or hardware.

---
Changes in v5:
- No update

Changes in v4:
- No update

Changes in v3:
- No update

Changes in v2:
- Separate out xhci driver changes apart

 drivers/usb/host/xhci-mem.c  | 12 ++++++------
 drivers/usb/host/xhci-plat.c | 33 ++++++++++++++++++++++++++-------
 drivers/usb/host/xhci.c      | 15 +++++++++++----
 3 files changed, 43 insertions(+), 17 deletions(-)
drivers/usb/host/xhci-mem.c +6 -6
index 48a26d378..eb32de9 100644
@@ -586,7 +586,7 @@ static void xhci_free_stream_ctx(struct xhci_hcd *xhci,
 		unsigned int num_stream_ctxs,
 		struct xhci_stream_ctx *stream_ctx, dma_addr_t dma)
 {
-	struct device *dev = xhci_to_hcd(xhci)->self.controller;
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 	size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
 
 	if (size > MEDIUM_STREAM_ARRAY_SIZE)
@@ -614,7 +614,7 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
 		unsigned int num_stream_ctxs, dma_addr_t *dma,
 		gfp_t mem_flags)
 {
-	struct device *dev = xhci_to_hcd(xhci)->self.controller;
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 	size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
 
 	if (size > MEDIUM_STREAM_ARRAY_SIZE)
@@ -1644,7 +1644,7 @@ void xhci_slot_copy(struct xhci_hcd *xhci,
 static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
 {
 	int i;
-	struct device *dev = xhci_to_hcd(xhci)->self.controller;
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 	int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2);
 
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
@@ -1716,7 +1716,7 @@ static void scratchpad_free(struct xhci_hcd *xhci)
 {
 	int num_sp;
 	int i;
-	struct device *dev = xhci_to_hcd(xhci)->self.controller;
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 
 	if (!xhci->scratchpad)
 		return;
@@ -1792,7 +1792,7 @@ void xhci_free_command(struct xhci_hcd *xhci,
 
 void xhci_mem_cleanup(struct xhci_hcd *xhci)
 {
-	struct device	*dev = xhci_to_hcd(xhci)->self.controller;
+	struct device	*dev = xhci_to_hcd(xhci)->self.sysdev;
 	int size;
 	int i, j, num_ports;
 
@@ -2334,7 +2334,7 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
 int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 {
 	dma_addr_t	dma;
-	struct device	*dev = xhci_to_hcd(xhci)->self.controller;
+	struct device	*dev = xhci_to_hcd(xhci)->self.sysdev;
 	unsigned int	val, val2;
 	u64		val_64;
 	struct xhci_segment	*seg;
drivers/usb/host/xhci-plat.c +26 -7
index ed56bf9..beb95c8 100644
@@ -14,6 +14,7 @@
 #include <linux/clk.h>
 #include <linux/dma-mapping.h>
 #include <linux/module.h>
+#include <linux/pci.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/usb/phy.h>
@@ -139,6 +140,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
 {
 	const struct of_device_id *match;
 	const struct hc_driver	*driver;
+	struct device		*sysdev;
 	struct xhci_hcd		*xhci;
 	struct resource         *res;
 	struct usb_hcd		*hcd;
@@ -155,22 +157,39 @@ static int xhci_plat_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return -ENODEV;
 
+	/*
+	 * sysdev must point to a device that is known to the system firmware
+	 * or PCI hardware. We handle these three cases here:
+	 * 1. xhci_plat comes from firmware
+	 * 2. xhci_plat is child of a device from firmware (dwc3-plat)
+	 * 3. xhci_plat is grandchild of a pci device (dwc3-pci)
+	 */
+	sysdev = &pdev->dev;
+	if (sysdev->parent && !sysdev->of_node && sysdev->parent->of_node)
+		sysdev = sysdev->parent;
+#ifdef CONFIG_PCI
+	else if (sysdev->parent && sysdev->parent->parent &&
+		 sysdev->parent->parent->bus == &pci_bus_type)
+		sysdev = sysdev->parent->parent;
+#endif
+
 	/* Try to set 64-bit DMA first */
-	if (WARN_ON(!pdev->dev.dma_mask))
+	if (WARN_ON(!sysdev->dma_mask))
 		/* Platform did not initialize dma_mask */
-		ret = dma_coerce_mask_and_coherent(&pdev->dev,
+		ret = dma_coerce_mask_and_coherent(sysdev,
 						   DMA_BIT_MASK(64));
 	else
-		ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
+		ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(64));
 
 	/* If seting 64-bit DMA mask fails, fall back to 32-bit DMA mask */
 	if (ret) {
-		ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+		ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(32));
 		if (ret)
 			return ret;
 	}
 
-	hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
+	hcd = __usb_create_hcd(driver, sysdev, &pdev->dev,
+			       dev_name(&pdev->dev), NULL);
 	if (!hcd)
 		return -ENOMEM;
 
@@ -220,13 +239,13 @@ static int xhci_plat_probe(struct platform_device *pdev)
 		goto disable_clk;
 	}
 
-	if (device_property_read_bool(&pdev->dev, "usb3-lpm-capable"))
+	if (device_property_read_bool(sysdev, "usb3-lpm-capable"))
 		xhci->quirks |= XHCI_LPM_SUPPORT;
 
 	if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
 		xhci->shared_hcd->can_do_streams = 1;
 
-	hcd->usb_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
+	hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev, "usb-phy", 0);
 	if (IS_ERR(hcd->usb_phy)) {
 		ret = PTR_ERR(hcd->usb_phy);
 		if (ret == -EPROBE_DEFER)
drivers/usb/host/xhci.c +11 -4
index cf30cb6..fc76671 100644
@@ -231,6 +231,9 @@ static int xhci_free_msi(struct xhci_hcd *xhci)
 static int xhci_setup_msi(struct xhci_hcd *xhci)
 {
 	int ret;
+	/*
+	 * TODO:Check with MSI Soc for sysdev
+	 */
 	struct pci_dev  *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
 
 	ret = pci_enable_msi(pdev);
@@ -257,7 +260,7 @@ static int xhci_setup_msi(struct xhci_hcd *xhci)
  */
 static void xhci_free_irq(struct xhci_hcd *xhci)
 {
-	struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
+	struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.sysdev);
 	int ret;
 
 	/* return if using legacy interrupt */
@@ -743,7 +746,7 @@ void xhci_shutdown(struct usb_hcd *hcd)
 	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
 
 	if (xhci->quirks & XHCI_SPURIOUS_REBOOT)
-		usb_disable_xhci_ports(to_pci_dev(hcd->self.controller));
+		usb_disable_xhci_ports(to_pci_dev(hcd->self.sysdev));
 
 	spin_lock_irq(&xhci->lock);
 	xhci_halt(xhci);
@@ -760,7 +763,7 @@ void xhci_shutdown(struct usb_hcd *hcd)
 
 	/* Yet another workaround for spurious wakeups at shutdown with HSW */
 	if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
-		pci_set_power_state(to_pci_dev(hcd->self.controller), PCI_D3hot);
+		pci_set_power_state(to_pci_dev(hcd->self.sysdev), PCI_D3hot);
 }
 
 #ifdef CONFIG_PM
@@ -4832,7 +4835,11 @@ int xhci_get_frame(struct usb_hcd *hcd)
 int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
 {
 	struct xhci_hcd		*xhci;
-	struct device		*dev = hcd->self.controller;
+	/*
+	 * TODO: Check with DWC3 clients for sysdev according to
+	 * quirks
+	 */
+	struct device		*dev = hcd->self.sysdev;
 	int			retval;
 
 	/* Accept arbitrarily long scatter-gather lists */
Signature · 1 line
2.1.0
#8 lore raw

Re: [PATCH v5 4/6] usb: xhci: use bus->sysdev for DMA configuration

Hi,

Quoted 138 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices. So, set the dma for xhci from sysdev. sysdev is pointing to device that is known to the system firmware or hardware.

---
Changes in v5:
- No update

Changes in v4:
- No update

Changes in v3:
- No update

Changes in v2:
- Separate out xhci driver changes apart

 drivers/usb/host/xhci-mem.c  | 12 ++++++------
 drivers/usb/host/xhci-plat.c | 33 ++++++++++++++++++++++++++-------
 drivers/usb/host/xhci.c      | 15 +++++++++++----
 3 files changed, 43 insertions(+), 17 deletions(-)
drivers/usb/host/xhci-mem.c +6 -6
index 48a26d378..eb32de9 100644
@@ -586,7 +586,7 @@ static void xhci_free_stream_ctx(struct xhci_hcd *xhci,
 		unsigned int num_stream_ctxs,
 		struct xhci_stream_ctx *stream_ctx, dma_addr_t dma)
 {
-	struct device *dev = xhci_to_hcd(xhci)->self.controller;
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 	size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
 
 	if (size > MEDIUM_STREAM_ARRAY_SIZE)
@@ -614,7 +614,7 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
 		unsigned int num_stream_ctxs, dma_addr_t *dma,
 		gfp_t mem_flags)
 {
-	struct device *dev = xhci_to_hcd(xhci)->self.controller;
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 	size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
 
 	if (size > MEDIUM_STREAM_ARRAY_SIZE)
@@ -1644,7 +1644,7 @@ void xhci_slot_copy(struct xhci_hcd *xhci,
 static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
 {
 	int i;
-	struct device *dev = xhci_to_hcd(xhci)->self.controller;
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 	int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2);
 
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
@@ -1716,7 +1716,7 @@ static void scratchpad_free(struct xhci_hcd *xhci)
 {
 	int num_sp;
 	int i;
-	struct device *dev = xhci_to_hcd(xhci)->self.controller;
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 
 	if (!xhci->scratchpad)
 		return;
@@ -1792,7 +1792,7 @@ void xhci_free_command(struct xhci_hcd *xhci,
 
 void xhci_mem_cleanup(struct xhci_hcd *xhci)
 {
-	struct device	*dev = xhci_to_hcd(xhci)->self.controller;
+	struct device	*dev = xhci_to_hcd(xhci)->self.sysdev;
 	int size;
 	int i, j, num_ports;
 
@@ -2334,7 +2334,7 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
 int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 {
 	dma_addr_t	dma;
-	struct device	*dev = xhci_to_hcd(xhci)->self.controller;
+	struct device	*dev = xhci_to_hcd(xhci)->self.sysdev;
 	unsigned int	val, val2;
 	u64		val_64;
 	struct xhci_segment	*seg;
drivers/usb/host/xhci-plat.c +21 -3
index ed56bf9..beb95c8 100644
@@ -14,6 +14,7 @@
 #include <linux/clk.h>
 #include <linux/dma-mapping.h>
 #include <linux/module.h>
+#include <linux/pci.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/usb/phy.h>
@@ -139,6 +140,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
 {
 	const struct of_device_id *match;
 	const struct hc_driver	*driver;
+	struct device		*sysdev;
 	struct xhci_hcd		*xhci;
 	struct resource         *res;
 	struct usb_hcd		*hcd;
@@ -155,22 +157,39 @@ static int xhci_plat_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return -ENODEV;
 
+	/*
+	 * sysdev must point to a device that is known to the system firmware
+	 * or PCI hardware. We handle these three cases here:
+	 * 1. xhci_plat comes from firmware
+	 * 2. xhci_plat is child of a device from firmware (dwc3-plat)
+	 * 3. xhci_plat is grandchild of a pci device (dwc3-pci)
+	 */
+	sysdev = &pdev->dev;
+	if (sysdev->parent && !sysdev->of_node && sysdev->parent->of_node)
+		sysdev = sysdev->parent;
+#ifdef CONFIG_PCI
+	else if (sysdev->parent && sysdev->parent->parent &&
+		 sysdev->parent->parent->bus == &pci_bus_type)
+		sysdev = sysdev->parent->parent;
+#endif
+
 	/* Try to set 64-bit DMA first */
-	if (WARN_ON(!pdev->dev.dma_mask))
+	if (WARN_ON(!sysdev->dma_mask))
 		/* Platform did not initialize dma_mask */
-		ret = dma_coerce_mask_and_coherent(&pdev->dev,
+		ret = dma_coerce_mask_and_coherent(sysdev,
 						   DMA_BIT_MASK(64));
 	else
-		ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
+		ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(64));
 
 	/* If seting 64-bit DMA mask fails, fall back to 32-bit DMA mask */

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 192

Quoted 10 lines
drivers/usb/host/xhci-plat.c +3 -2
 	if (ret) {
-		ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+		ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(32));
 		if (ret)
 			return ret;
 	}
 
-	hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
+	hcd = __usb_create_hcd(driver, sysdev, &pdev->dev,
+			       dev_name(&pdev->dev), NULL);

This is fine but we're forgetting to set sysdev while creating the shared HCD. This will lead to invalid dma parameters for the shared HCD.
So we would need,

- xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev,
+ xhci->shared_hcd = usb_create_shared_hcd(driver, sysdev,

                        dev_name(&pdev->dev), hcd);
        if (!xhci->shared_hcd) {
                ret = -ENOMEM;

Also, I noticed that Felipe has already picked up the dwc3 patches but the core and xhci patches are missing in linux-next leading to the following warning

[    4.648958] ------------[ cut here ]------------
[    4.653602] WARNING: CPU: 0 PID: 1 at drivers/usb/host/xhci-plat.c:159 xhci_plat_probe+0x1a0/0x474
[    4.662560] Modules linked in:
[    4.665612] CPU: 0 PID: 1 Comm: swapper/0 Tainted: G        W       4.9.0-rc3 #1028
[    4.673258] Hardware name: Keystone
[    4.676743] [<c020ed74>] (unwind_backtrace) from [<c020afac>] (show_stack+0x10/0x14)
[    4.684479] [<c020afac>] (show_stack) from [<c04c9160>] (dump_stack+0x78/0x8c)
[    4.691694] [<c04c9160>] (dump_stack) from [<c021c964>] (__warn+0xec/0x104)
[    4.698648] [<c021c964>] (__warn) from [<c021ca2c>] (warn_slowpath_null+0x20/0x28)
[    4.706210] [<c021ca2c>] (warn_slowpath_null) from [<c0604c40>] (xhci_plat_probe+0x1a0/0x474)
[    4.714729] [<c0604c40>] (xhci_plat_probe) from [<c05651c0>] (platform_drv_probe+0x4c/0xb0)
[    4.723073] [<c05651c0>] (platform_drv_probe) from [<c0563cb4>] (driver_probe_device+0x208/0x2b4)
[    4.731937] [<c0563cb4>] (driver_probe_device) from [<c0563e18>] (__driver_attach+0xb8/0xbc)
[    4.740365] [<c0563e18>] (__driver_attach) from [<c0562088>] (bus_for_each_dev+0x68/0x9c)
[    4.748535] [<c0562088>] (bus_for_each_dev) from [<c05631d8>] (bus_add_driver+0x1a4/0x21c)
[    4.756791] [<c05631d8>] (bus_add_driver) from [<c05642c8>] (driver_register+0x78/0xf8)
[    4.764786] [<c05642c8>] (driver_register) from [<c0201774>] (do_one_initcall+0x44/0x174)
[    4.772955] [<c0201774>] (do_one_initcall) from [<c0c00de8>] (kernel_init_freeable+0x154/0x1e4)
[    4.781645] [<c0c00de8>] (kernel_init_freeable) from [<c07b0a24>] (kernel_init+0x8/0x10c)
[    4.789815] [<c07b0a24>] (kernel_init) from [<c0207588>] (ret_from_fork+0x14/0x2c)
[    4.797573] ---[ end trace 0ec4c38d69780113 ]---

cheers,
-roger

Quoted 74 lines
drivers/usb/host/xhci-plat.c +2 -2
 	if (!hcd)
 		return -ENOMEM;
 
@@ -220,13 +239,13 @@ static int xhci_plat_probe(struct platform_device *pdev)
 		goto disable_clk;
 	}
 
-	if (device_property_read_bool(&pdev->dev, "usb3-lpm-capable"))
+	if (device_property_read_bool(sysdev, "usb3-lpm-capable"))
 		xhci->quirks |= XHCI_LPM_SUPPORT;
 
 	if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
 		xhci->shared_hcd->can_do_streams = 1;
 
-	hcd->usb_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
+	hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev, "usb-phy", 0);
 	if (IS_ERR(hcd->usb_phy)) {
 		ret = PTR_ERR(hcd->usb_phy);
 		if (ret == -EPROBE_DEFER)
drivers/usb/host/xhci.c +11 -4
index cf30cb6..fc76671 100644
@@ -231,6 +231,9 @@ static int xhci_free_msi(struct xhci_hcd *xhci)
 static int xhci_setup_msi(struct xhci_hcd *xhci)
 {
 	int ret;
+	/*
+	 * TODO:Check with MSI Soc for sysdev
+	 */
 	struct pci_dev  *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
 
 	ret = pci_enable_msi(pdev);
@@ -257,7 +260,7 @@ static int xhci_setup_msi(struct xhci_hcd *xhci)
  */
 static void xhci_free_irq(struct xhci_hcd *xhci)
 {
-	struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
+	struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.sysdev);
 	int ret;
 
 	/* return if using legacy interrupt */
@@ -743,7 +746,7 @@ void xhci_shutdown(struct usb_hcd *hcd)
 	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
 
 	if (xhci->quirks & XHCI_SPURIOUS_REBOOT)
-		usb_disable_xhci_ports(to_pci_dev(hcd->self.controller));
+		usb_disable_xhci_ports(to_pci_dev(hcd->self.sysdev));
 
 	spin_lock_irq(&xhci->lock);
 	xhci_halt(xhci);
@@ -760,7 +763,7 @@ void xhci_shutdown(struct usb_hcd *hcd)
 
 	/* Yet another workaround for spurious wakeups at shutdown with HSW */
 	if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
-		pci_set_power_state(to_pci_dev(hcd->self.controller), PCI_D3hot);
+		pci_set_power_state(to_pci_dev(hcd->self.sysdev), PCI_D3hot);
 }
 
 #ifdef CONFIG_PM
@@ -4832,7 +4835,11 @@ int xhci_get_frame(struct usb_hcd *hcd)
 int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
 {
 	struct xhci_hcd		*xhci;
-	struct device		*dev = hcd->self.controller;
+	/*
+	 * TODO: Check with DWC3 clients for sysdev according to
+	 * quirks
+	 */
+	struct device		*dev = hcd->self.sysdev;
 	int			retval;
 
 	/* Accept arbitrarily long scatter-gather lists */
Tested-by on v5 4/6
#9 lore raw

Re: [v5,4/6] usb: xhci: use bus->sysdev for DMA configuration

In reply to Sriram Dash

Hi!

Quoted 10 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices. So, set the dma for xhci from sysdev. sysdev is pointing to device that is known to the system firmware or hardware.

Successfully tested on arm64/axxia with DWC3 USB host, XHCIs properly inherit DMA configuration. Therefore:

Quoted 212 lines

---
Changes in v5:
- No update

Changes in v4:
- No update

Changes in v3:
- No update

Changes in v2:
- Separate out xhci driver changes apart

 drivers/usb/host/xhci-mem.c  | 12 ++++++------
 drivers/usb/host/xhci-plat.c | 33 ++++++++++++++++++++++++++-------
 drivers/usb/host/xhci.c      | 15 +++++++++++----
 3 files changed, 43 insertions(+), 17 deletions(-)
drivers/usb/host/xhci-mem.c +6 -6
index 48a26d378..eb32de9 100644
@@ -586,7 +586,7 @@ static void xhci_free_stream_ctx(struct xhci_hcd *xhci,
 		unsigned int num_stream_ctxs,
 		struct xhci_stream_ctx *stream_ctx, dma_addr_t dma)
 {
-	struct device *dev = xhci_to_hcd(xhci)->self.controller;
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 	size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
 
 	if (size > MEDIUM_STREAM_ARRAY_SIZE)
@@ -614,7 +614,7 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
 		unsigned int num_stream_ctxs, dma_addr_t *dma,
 		gfp_t mem_flags)
 {
-	struct device *dev = xhci_to_hcd(xhci)->self.controller;
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 	size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
 
 	if (size > MEDIUM_STREAM_ARRAY_SIZE)
@@ -1644,7 +1644,7 @@ void xhci_slot_copy(struct xhci_hcd *xhci,
 static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
 {
 	int i;
-	struct device *dev = xhci_to_hcd(xhci)->self.controller;
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 	int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2);
 
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
@@ -1716,7 +1716,7 @@ static void scratchpad_free(struct xhci_hcd *xhci)
 {
 	int num_sp;
 	int i;
-	struct device *dev = xhci_to_hcd(xhci)->self.controller;
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 
 	if (!xhci->scratchpad)
 		return;
@@ -1792,7 +1792,7 @@ void xhci_free_command(struct xhci_hcd *xhci,
 
 void xhci_mem_cleanup(struct xhci_hcd *xhci)
 {
-	struct device	*dev = xhci_to_hcd(xhci)->self.controller;
+	struct device	*dev = xhci_to_hcd(xhci)->self.sysdev;
 	int size;
 	int i, j, num_ports;
 
@@ -2334,7 +2334,7 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
 int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 {
 	dma_addr_t	dma;
-	struct device	*dev = xhci_to_hcd(xhci)->self.controller;
+	struct device	*dev = xhci_to_hcd(xhci)->self.sysdev;
 	unsigned int	val, val2;
 	u64		val_64;
 	struct xhci_segment	*seg;
drivers/usb/host/xhci-plat.c +26 -7
index ed56bf9..beb95c8 100644
@@ -14,6 +14,7 @@
 #include <linux/clk.h>
 #include <linux/dma-mapping.h>
 #include <linux/module.h>
+#include <linux/pci.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/usb/phy.h>
@@ -139,6 +140,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
 {
 	const struct of_device_id *match;
 	const struct hc_driver	*driver;
+	struct device		*sysdev;
 	struct xhci_hcd		*xhci;
 	struct resource         *res;
 	struct usb_hcd		*hcd;
@@ -155,22 +157,39 @@ static int xhci_plat_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return -ENODEV;
 
+	/*
+	 * sysdev must point to a device that is known to the system firmware
+	 * or PCI hardware. We handle these three cases here:
+	 * 1. xhci_plat comes from firmware
+	 * 2. xhci_plat is child of a device from firmware (dwc3-plat)
+	 * 3. xhci_plat is grandchild of a pci device (dwc3-pci)
+	 */
+	sysdev = &pdev->dev;
+	if (sysdev->parent && !sysdev->of_node && sysdev->parent->of_node)
+		sysdev = sysdev->parent;
+#ifdef CONFIG_PCI
+	else if (sysdev->parent && sysdev->parent->parent &&
+		 sysdev->parent->parent->bus == &pci_bus_type)
+		sysdev = sysdev->parent->parent;
+#endif
+
 	/* Try to set 64-bit DMA first */
-	if (WARN_ON(!pdev->dev.dma_mask))
+	if (WARN_ON(!sysdev->dma_mask))
 		/* Platform did not initialize dma_mask */
-		ret = dma_coerce_mask_and_coherent(&pdev->dev,
+		ret = dma_coerce_mask_and_coherent(sysdev,
 						   DMA_BIT_MASK(64));
 	else
-		ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
+		ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(64));
 
 	/* If seting 64-bit DMA mask fails, fall back to 32-bit DMA mask */
 	if (ret) {
-		ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+		ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(32));
 		if (ret)
 			return ret;
 	}
 
-	hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
+	hcd = __usb_create_hcd(driver, sysdev, &pdev->dev,
+			       dev_name(&pdev->dev), NULL);
 	if (!hcd)
 		return -ENOMEM;
 
@@ -220,13 +239,13 @@ static int xhci_plat_probe(struct platform_device *pdev)
 		goto disable_clk;
 	}
 
-	if (device_property_read_bool(&pdev->dev, "usb3-lpm-capable"))
+	if (device_property_read_bool(sysdev, "usb3-lpm-capable"))
 		xhci->quirks |= XHCI_LPM_SUPPORT;
 
 	if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
 		xhci->shared_hcd->can_do_streams = 1;
 
-	hcd->usb_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
+	hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev, "usb-phy", 0);
 	if (IS_ERR(hcd->usb_phy)) {
 		ret = PTR_ERR(hcd->usb_phy);
 		if (ret == -EPROBE_DEFER)
drivers/usb/host/xhci.c +11 -4
index cf30cb6..fc76671 100644
@@ -231,6 +231,9 @@ static int xhci_free_msi(struct xhci_hcd *xhci)
 static int xhci_setup_msi(struct xhci_hcd *xhci)
 {
 	int ret;
+	/*
+	 * TODO:Check with MSI Soc for sysdev
+	 */
 	struct pci_dev  *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
 
 	ret = pci_enable_msi(pdev);
@@ -257,7 +260,7 @@ static int xhci_setup_msi(struct xhci_hcd *xhci)
  */
 static void xhci_free_irq(struct xhci_hcd *xhci)
 {
-	struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
+	struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.sysdev);
 	int ret;
 
 	/* return if using legacy interrupt */
@@ -743,7 +746,7 @@ void xhci_shutdown(struct usb_hcd *hcd)
 	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
 
 	if (xhci->quirks & XHCI_SPURIOUS_REBOOT)
-		usb_disable_xhci_ports(to_pci_dev(hcd->self.controller));
+		usb_disable_xhci_ports(to_pci_dev(hcd->self.sysdev));
 
 	spin_lock_irq(&xhci->lock);
 	xhci_halt(xhci);
@@ -760,7 +763,7 @@ void xhci_shutdown(struct usb_hcd *hcd)
 
 	/* Yet another workaround for spurious wakeups at shutdown with HSW */
 	if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
-		pci_set_power_state(to_pci_dev(hcd->self.controller), PCI_D3hot);
+		pci_set_power_state(to_pci_dev(hcd->self.sysdev), PCI_D3hot);
 }
 
 #ifdef CONFIG_PM
@@ -4832,7 +4835,11 @@ int xhci_get_frame(struct usb_hcd *hcd)
 int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
 {
 	struct xhci_hcd		*xhci;
-	struct device		*dev = hcd->self.controller;
+	/*
+	 * TODO: Check with DWC3 clients for sysdev according to
+	 * quirks
+	 */
+	struct device		*dev = hcd->self.sysdev;
 	int			retval;
 
 	/* Accept arbitrarily long scatter-gather lists */
Signature · 2 lines
Best regards,
Alexander Sverdlin.
#10 lore raw

Re: [PATCH v5 4/6] usb: xhci: use bus->sysdev for DMA configuration

In reply to Sriram Dash
Quoted 11 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices. So, set the dma for xhci from sysdev. sysdev is pointing to device that is known to the system firmware or hardware.

---

...

Quoted 6 lines
drivers/usb/host/xhci-plat.c +6 -0
+	/*
+	 * sysdev must point to a device that is known to the system firmware
+	 * or PCI hardware. We handle these three cases here:
+	 * 1. xhci_plat comes from firmware
+	 * 2. xhci_plat is child of a device from firmware (dwc3-plat)
+	 * 3. xhci_plat is grandchild of a pci device (dwc3-pci)

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 175

Quoted 10 lines
drivers/usb/host/xhci-plat.c +10 -0
+	 */
+	sysdev = &pdev->dev;
+	if (sysdev->parent && !sysdev->of_node && sysdev->parent->of_node)
+		sysdev = sysdev->parent;
+#ifdef CONFIG_PCI
+	else if (sysdev->parent && sysdev->parent->parent &&
+		 sysdev->parent->parent->bus == &pci_bus_type)
+		sysdev = sysdev->parent->parent;
+#endif
+

Not maybe the the ideal situation here, and looks really tailored to make PCI dwc3 controllers with xhci support work.

Was there some reason child devices can't automatically inherit the dma mask from the parents, forcing us to dig it from grandparents?

Anyway, looks like the dwc3 part is already in 4.10-rc, If Greg and Alan want to take this series that's fine by me

I haven't tested that it won't break anything on PCI XHCI controllers though

-Mathias

maintainer
#11 lore raw

Re: [PATCH v5 4/6] usb: xhci: use bus->sysdev for DMA configuration

Quoted 35 lines · Mathias Nyman
Quoted 11 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices. So, set the dma for xhci from sysdev. sysdev is pointing to device that is known to the system firmware or hardware.

---

...

Quoted 6 lines
drivers/usb/host/xhci-plat.c +6 -0
+	/*
+	 * sysdev must point to a device that is known to the system firmware
+	 * or PCI hardware. We handle these three cases here:
+	 * 1. xhci_plat comes from firmware
+	 * 2. xhci_plat is child of a device from firmware (dwc3-plat)
+	 * 3. xhci_plat is grandchild of a pci device (dwc3-pci)

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 175

Quoted 10 lines
drivers/usb/host/xhci-plat.c +10 -0
+	 */
+	sysdev = &pdev->dev;
+	if (sysdev->parent && !sysdev->of_node && sysdev->parent->of_node)
+		sysdev = sysdev->parent;
+#ifdef CONFIG_PCI
+	else if (sysdev->parent && sysdev->parent->parent &&
+		 sysdev->parent->parent->bus == &pci_bus_type)
+		sysdev = sysdev->parent->parent;
+#endif
+

Not maybe the the ideal situation here, and looks really tailored to make PCI dwc3 controllers with xhci support work.

Quoted 5 lines

Was there some reason child devices can't automatically inherit the dma mask from the parents, forcing us to dig it from grandparents?

Anyway, looks like the dwc3 part is already in 4.10-rc, If Greg and Alan want to take this series that's fine by me

I have no objections.

Alan Stern

Quoted 3 lines

I haven't tested that it won't break anything on PCI XHCI controllers though

-Mathias

#12 lore raw

Re: [PATCH v5 4/6] usb: xhci: use bus->sysdev for DMA configuration

Mathias,

Quoted 40 lines · Alan Stern
Quoted 38 lines · Mathias Nyman
Quoted 11 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices. So, set the dma for xhci from sysdev. sysdev is pointing to device that is known to the system firmware or hardware.

---

...

Quoted 6 lines
drivers/usb/host/xhci-plat.c +6 -0
+	/*
+	 * sysdev must point to a device that is known to the system firmware
+	 * or PCI hardware. We handle these three cases here:
+	 * 1. xhci_plat comes from firmware
+	 * 2. xhci_plat is child of a device from firmware (dwc3-plat)
+	 * 3. xhci_plat is grandchild of a pci device (dwc3-pci)

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 175

Quoted 10 lines
drivers/usb/host/xhci-plat.c +10 -0
+	 */
+	sysdev = &pdev->dev;
+	if (sysdev->parent && !sysdev->of_node && sysdev->parent->of_node)
+		sysdev = sysdev->parent;
+#ifdef CONFIG_PCI
+	else if (sysdev->parent && sysdev->parent->parent &&
+		 sysdev->parent->parent->bus == &pci_bus_type)
+		sysdev = sysdev->parent->parent;
+#endif
+

Not maybe the the ideal situation here, and looks really tailored to make PCI dwc3 controllers with xhci support work.

Was there some reason child devices can't automatically inherit the dma mask from the parents, forcing us to dig it from grandparents?

Quoted 10 lines
Quoted 2 lines

Anyway, looks like the dwc3 part is already in 4.10-rc, If Greg and Alan want to take this series that's fine by me

I have no objections.

Alan Stern

Quoted 3 lines

I haven't tested that it won't break anything on PCI XHCI controllers though

-Mathias

Are you going to pick all the remaining patches from this series (i.e. 1 to 4)?

That should fix the warning that people are seeing on v4.10-rc.

cheers,
roger

Acked-by
#13 lore raw

Re: [PATCH v5 4/6] usb: xhci: use bus->sysdev for DMA configuration

Quoted 50 lines · Roger Quadros

Mathias,

Quoted 47 lines · Alan Stern
Quoted 35 lines · Mathias Nyman
Quoted 11 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices. So, set the dma for xhci from sysdev. sysdev is pointing to device that is known to the system firmware or hardware.

---

...

Quoted 6 lines
drivers/usb/host/xhci-plat.c +6 -0
+	/*
+	 * sysdev must point to a device that is known to the system firmware
+	 * or PCI hardware. We handle these three cases here:
+	 * 1. xhci_plat comes from firmware
+	 * 2. xhci_plat is child of a device from firmware (dwc3-plat)
+	 * 3. xhci_plat is grandchild of a pci device (dwc3-pci)

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 175

Quoted 10 lines
drivers/usb/host/xhci-plat.c +10 -0
+	 */
+	sysdev = &pdev->dev;
+	if (sysdev->parent && !sysdev->of_node && sysdev->parent->of_node)
+		sysdev = sysdev->parent;
+#ifdef CONFIG_PCI
+	else if (sysdev->parent && sysdev->parent->parent &&
+		 sysdev->parent->parent->bus == &pci_bus_type)
+		sysdev = sysdev->parent->parent;
+#endif
+

Not maybe the the ideal situation here, and looks really tailored to make PCI dwc3 controllers with xhci support work.

Quoted 5 lines

Was there some reason child devices can't automatically inherit the dma mask from the parents, forcing us to dig it from grandparents?

Anyway, looks like the dwc3 part is already in 4.10-rc, If Greg and Alan want to take this series that's fine by me

I have no objections.

Alan Stern

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

I haven't tested that it won't break anything on PCI XHCI controllers though

-Mathias

Are you going to pick all the remaining patches from this series (i.e. 1 to 4)?

That should fix the warning that people are seeing on v4.10-rc.

Let's check with Greg

Greg, 5/6 and 6/6 are in 4.10-rc already, causing additional warnings for people using dwc3 xhci.

First 3 patches change usb core, patch 4 xhci.

Compiles and boots, doesn't break pci xhci (non-dwc3) functionality

Would you like me to send first 4 patches for usb-linus to get a clean final 4.10 without warnings, or to send them for usb-next?

Or will you just pick the patches from here directly.

for patch 4/6:

-Mathias

maintainer
#14 lore raw

Re: [PATCH v5 4/6] usb: xhci: use bus->sysdev for DMA configuration

Quoted 65 lines · Mathias Nyman
Quoted 50 lines · Roger Quadros

Mathias,

Quoted 47 lines · Alan Stern
Quoted 35 lines · Mathias Nyman
Quoted 11 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices. So, set the dma for xhci from sysdev. sysdev is pointing to device that is known to the system firmware or hardware.

---

...

Quoted 6 lines
drivers/usb/host/xhci-plat.c +6 -0
+	/*
+	 * sysdev must point to a device that is known to the system firmware
+	 * or PCI hardware. We handle these three cases here:
+	 * 1. xhci_plat comes from firmware
+	 * 2. xhci_plat is child of a device from firmware (dwc3-plat)
+	 * 3. xhci_plat is grandchild of a pci device (dwc3-pci)

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 175

Quoted 10 lines
drivers/usb/host/xhci-plat.c +10 -0
+	 */
+	sysdev = &pdev->dev;
+	if (sysdev->parent && !sysdev->of_node && sysdev->parent->of_node)
+		sysdev = sysdev->parent;
+#ifdef CONFIG_PCI
+	else if (sysdev->parent && sysdev->parent->parent &&
+		 sysdev->parent->parent->bus == &pci_bus_type)
+		sysdev = sysdev->parent->parent;
+#endif
+

Not maybe the the ideal situation here, and looks really tailored to make PCI dwc3 controllers with xhci support work.

Quoted 5 lines

Was there some reason child devices can't automatically inherit the dma mask from the parents, forcing us to dig it from grandparents?

Anyway, looks like the dwc3 part is already in 4.10-rc, If Greg and Alan want to take this series that's fine by me

I have no objections.

Alan Stern

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

I haven't tested that it won't break anything on PCI XHCI controllers though

-Mathias

Are you going to pick all the remaining patches from this series (i.e. 1 to 4)?

That should fix the warning that people are seeing on v4.10-rc.

Let's check with Greg

Greg, 5/6 and 6/6 are in 4.10-rc already, causing additional warnings for people using dwc3 xhci.

Quoted 8 lines

First 3 patches change usb core, patch 4 xhci.

Compiles and boots, doesn't break pci xhci (non-dwc3) functionality

Would you like me to send first 4 patches for usb-linus to get a clean final 4.10 without warnings, or to send them for usb-next?

Or will you just pick the patches from here directly.

I don't have them "here" anymore, they are long-gone from my patch queue, sorry.

Can you resend them, I don't know what these patches contained, but if they fix an 4.10 issue, that would be good to have there, right?

thanks,

greg k-h

#15 lore raw

Re: [PATCH v5 4/6] usb: xhci: use bus->sysdev for DMA configuration

Quoted 73 lines · Greg KH
Quoted 72 lines · Mathias Nyman
Quoted 50 lines · Roger Quadros

Mathias,

Quoted 47 lines · Alan Stern
Quoted 35 lines · Mathias Nyman
Quoted 11 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices. So, set the dma for xhci from sysdev. sysdev is pointing to device that is known to the system firmware or hardware.

---

...

Quoted 6 lines
drivers/usb/host/xhci-plat.c +6 -0
+	/*
+	 * sysdev must point to a device that is known to the system firmware
+	 * or PCI hardware. We handle these three cases here:
+	 * 1. xhci_plat comes from firmware
+	 * 2. xhci_plat is child of a device from firmware (dwc3-plat)
+	 * 3. xhci_plat is grandchild of a pci device (dwc3-pci)

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 175

Quoted 10 lines
drivers/usb/host/xhci-plat.c +10 -0
+	 */
+	sysdev = &pdev->dev;
+	if (sysdev->parent && !sysdev->of_node && sysdev->parent->of_node)
+		sysdev = sysdev->parent;
+#ifdef CONFIG_PCI
+	else if (sysdev->parent && sysdev->parent->parent &&
+		 sysdev->parent->parent->bus == &pci_bus_type)
+		sysdev = sysdev->parent->parent;
+#endif
+

Not maybe the the ideal situation here, and looks really tailored to make PCI dwc3 controllers with xhci support work.

Quoted 5 lines

Was there some reason child devices can't automatically inherit the dma mask from the parents, forcing us to dig it from grandparents?

Anyway, looks like the dwc3 part is already in 4.10-rc, If Greg and Alan want to take this series that's fine by me

I have no objections.

Alan Stern

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

I haven't tested that it won't break anything on PCI XHCI controllers though

-Mathias

Are you going to pick all the remaining patches from this series (i.e. 1 to 4)?

That should fix the warning that people are seeing on v4.10-rc.

Let's check with Greg

Greg, 5/6 and 6/6 are in 4.10-rc already, causing additional warnings for people using dwc3 xhci.

First 3 patches change usb core, patch 4 xhci.

Compiles and boots, doesn't break pci xhci (non-dwc3) functionality

Would you like me to send first 4 patches for usb-linus to get a clean final 4.10 without warnings, or to send them for usb-next?

Quoted 8 lines
Quoted 1 line

Or will you just pick the patches from here directly.

I don't have them "here" anymore, they are long-gone from my patch queue, sorry.

Can you resend them, I don't know what these patches contained, but if they fix an 4.10 issue, that would be good to have there, right?

Right, I'll send them

-Mathias

#16 lore raw

PATCH v5 5/6 usb: dwc3: use bus->sysdev for DMA configuration

In reply to Sriram Dash

From: Arnd Bergmann <[email protected]>

The dma ops for dwc3 devices are not set properly. So, use a physical device sysdev, which will be inherited from parent, to set the hardware / firmware parameters like dma.

---
Changes in v5:
- rebase to usb testing/next

Changes in v4:
- removed the ifdefs for pci
- made the sysdev as a device property
- phy create lookup take up the correct device.

Changes in v3:
- No update

Changes in v2:
- integrate dwc3 driver changes together

 drivers/usb/dwc3/core.c     | 27 ++++++++++++++-------------
 drivers/usb/dwc3/core.h     |  3 +++
 drivers/usb/dwc3/dwc3-pci.c | 10 ++++++++++
 drivers/usb/dwc3/ep0.c      |  8 ++++----
 drivers/usb/dwc3/gadget.c   | 33 +++++++++++++++++----------------
 drivers/usb/dwc3/host.c     | 16 ++++++----------
 6 files changed, 54 insertions(+), 43 deletions(-)
drivers/usb/dwc3/core.c +14 -13
index e951448..e5fbab2 100644
@@ -202,7 +202,7 @@ static void dwc3_frame_length_adjustment(struct dwc3 *dwc)
 static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
 		struct dwc3_event_buffer *evt)
 {
-	dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma);
+	dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma);
 }
 
 /**
@@ -228,7 +228,7 @@ static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
 	if (!evt->cache)
 		return ERR_PTR(-ENOMEM);
 
-	evt->buf	= dma_alloc_coherent(dwc->dev, length,
+	evt->buf	= dma_alloc_coherent(dwc->sysdev, length,
 			&evt->dma, GFP_KERNEL);
 	if (!evt->buf)
 		return ERR_PTR(-ENOMEM);
@@ -341,11 +341,11 @@ static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
 	if (!WARN_ON(dwc->scratchbuf))
 		return 0;
 
-	scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf,
+	scratch_addr = dma_map_single(dwc->sysdev, dwc->scratchbuf,
 			dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
 			DMA_BIDIRECTIONAL);
-	if (dma_mapping_error(dwc->dev, scratch_addr)) {
-		dev_err(dwc->dev, "failed to map scratch buffer\n");
+	if (dma_mapping_error(dwc->sysdev, scratch_addr)) {
+		dev_err(dwc->sysdev, "failed to map scratch buffer\n");
 		ret = -EFAULT;
 		goto err0;
 	}
@@ -369,7 +369,7 @@ static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
 	return 0;
 
 err1:
-	dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
+	dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch *
 			DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
 
 err0:
@@ -388,7 +388,7 @@ static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
 	if (!WARN_ON(dwc->scratchbuf))
 		return;
 
-	dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
+	dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch *
 			DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
 	kfree(dwc->scratchbuf);
 }
@@ -927,6 +927,13 @@ static void dwc3_get_properties(struct dwc3 *dwc)
 	dwc->dr_mode = usb_get_dr_mode(dev);
 	dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node);
 
+	dwc->sysdev_is_parent = device_property_read_bool(dev,
+				"linux,sysdev_is_parent");
+	if (dwc->sysdev_is_parent)
+		dwc->sysdev = dwc->dev->parent;
+	else
+		dwc->sysdev = dwc->dev;
+
 	dwc->has_lpm_erratum = device_property_read_bool(dev,
 				"snps,has-lpm-erratum");
 	device_property_read_u8(dev, "snps,lpm-nyet-threshold",
@@ -1097,12 +1104,6 @@ static int dwc3_probe(struct platform_device *pdev)
 
 	spin_lock_init(&dwc->lock);
 
-	if (!dev->dma_mask) {
-		dev->dma_mask = dev->parent->dma_mask;
-		dev->dma_parms = dev->parent->dma_parms;
-		dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
-	}
-
 	pm_runtime_set_active(dev);
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY);
drivers/usb/dwc3/core.h +3 -0
index ef81fa5..de5a857 100644
@@ -819,6 +819,7 @@ struct dwc3_scratchpad_array {
  * @ep0_bounced: true when we used bounce buffer
  * @ep0_expect_in: true when we expect a DATA IN transfer
  * @has_hibernation: true when dwc3 was configured with Hibernation
+ * @sysdev_is_parent: true when dwc3 device has a parent driver
  * @has_lpm_erratum: true when core was configured with LPM Erratum. Note that
  *			there's now way for software to detect this in runtime.
  * @is_utmi_l1_suspend: the core asserts output signal
@@ -875,6 +876,7 @@ struct dwc3 {
 	spinlock_t		lock;
 
 	struct device		*dev;
+	struct device		*sysdev;
 
 	struct platform_device	*xhci;
 	struct resource		xhci_resources[DWC3_XHCI_RESOURCES_NUM];
@@ -976,6 +978,7 @@ struct dwc3 {
 	unsigned		ep0_bounced:1;
 	unsigned		ep0_expect_in:1;
 	unsigned		has_hibernation:1;
+	unsigned		sysdev_is_parent:1;
 	unsigned		has_lpm_erratum:1;
 	unsigned		is_utmi_l1_suspend:1;
 	unsigned		is_fpga:1;
drivers/usb/dwc3/dwc3-pci.c +10 -0
index 2b0e34d..2b73339 100644
@@ -73,6 +73,16 @@ static int dwc3_pci_quirks(struct dwc3_pci *dwc)
 {
 	struct platform_device		*dwc3 = dwc->dwc3;
 	struct pci_dev			*pdev = dwc->pci;
+	int				ret;
+
+	struct property_entry sysdev_property[] = {
+		PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
+		{ },
+	};
+
+	ret = platform_device_add_properties(dwc3, sysdev_property);
+	if (ret)
+		return ret;
 
 	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
 	    pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
drivers/usb/dwc3/ep0.c +4 -4
index 2b22ea7..2d7fb2d 100644
@@ -1000,8 +1000,8 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
 		u32	transfer_size = 0;
 		u32	maxpacket;
 
-		ret = usb_gadget_map_request(&dwc->gadget, &req->request,
-				dep->number);
+		ret = usb_gadget_map_request_by_dev(dwc->sysdev,
+				&req->request, dep->number);
 		if (ret)
 			return;
 
@@ -1026,8 +1026,8 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
 				dwc->ep0_bounce_addr, transfer_size,
 				DWC3_TRBCTL_CONTROL_DATA, false);
 	} else {
-		ret = usb_gadget_map_request(&dwc->gadget, &req->request,
-				dep->number);
+		ret = usb_gadget_map_request_by_dev(dwc->sysdev,
+				&req->request, dep->number);
 		if (ret)
 			return;
 
drivers/usb/dwc3/gadget.c +17 -16
index e2416de..6785595 100644
@@ -183,8 +183,8 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
 	if (dwc->ep0_bounced && dep->number == 0)
 		dwc->ep0_bounced = false;
 	else
-		usb_gadget_unmap_request(&dwc->gadget, &req->request,
-				req->direction);
+		usb_gadget_unmap_request_by_dev(dwc->sysdev,
+				&req->request, req->direction);
 
 	trace_dwc3_gadget_giveback(req);
 
@@ -399,7 +399,7 @@ static int dwc3_alloc_trb_pool(struct dwc3_ep *dep)
 	if (dep->trb_pool)
 		return 0;
 
-	dep->trb_pool = dma_alloc_coherent(dwc->dev,
+	dep->trb_pool = dma_alloc_coherent(dwc->sysdev,
 			sizeof(struct dwc3_trb) * DWC3_TRB_NUM,
 			&dep->trb_pool_dma, GFP_KERNEL);
 	if (!dep->trb_pool) {
@@ -415,7 +415,7 @@ static void dwc3_free_trb_pool(struct dwc3_ep *dep)
 {
 	struct dwc3		*dwc = dep->dwc;
 
-	dma_free_coherent(dwc->dev, sizeof(struct dwc3_trb) * DWC3_TRB_NUM,
+	dma_free_coherent(dwc->sysdev, sizeof(struct dwc3_trb) * DWC3_TRB_NUM,
 			dep->trb_pool, dep->trb_pool_dma);
 
 	dep->trb_pool = NULL;
@@ -1171,8 +1171,8 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
 
 	trace_dwc3_ep_queue(req);
 
-	ret = usb_gadget_map_request(&dwc->gadget, &req->request,
-			dep->direction);
+	ret = usb_gadget_map_request_by_dev(dwc->sysdev, &req->request,
+					    dep->direction);
 	if (ret)
 		return ret;
 
@@ -2977,7 +2977,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 
 	dwc->irq_gadget = irq;
 
-	dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
+	dwc->ctrl_req = dma_alloc_coherent(dwc->sysdev, sizeof(*dwc->ctrl_req),
 			&dwc->ctrl_req_addr, GFP_KERNEL);
 	if (!dwc->ctrl_req) {
 		dev_err(dwc->dev, "failed to allocate ctrl request\n");
@@ -2985,8 +2985,9 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 		goto err0;
 	}
 
-	dwc->ep0_trb = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ep0_trb) * 2,
-			&dwc->ep0_trb_addr, GFP_KERNEL);
+	dwc->ep0_trb = dma_alloc_coherent(dwc->sysdev,
+					  sizeof(*dwc->ep0_trb) * 2,
+					  &dwc->ep0_trb_addr, GFP_KERNEL);
 	if (!dwc->ep0_trb) {
 		dev_err(dwc->dev, "failed to allocate ep0 trb\n");
 		ret = -ENOMEM;
@@ -2999,7 +3000,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 		goto err2;
 	}
 
-	dwc->ep0_bounce = dma_alloc_coherent(dwc->dev,
+	dwc->ep0_bounce = dma_alloc_coherent(dwc->sysdev,
 			DWC3_EP0_BOUNCE_SIZE, &dwc->ep0_bounce_addr,
 			GFP_KERNEL);
 	if (!dwc->ep0_bounce) {
@@ -3072,18 +3073,18 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 
 err4:
 	dwc3_gadget_free_endpoints(dwc);
-	dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE,
+	dma_free_coherent(dwc->sysdev, DWC3_EP0_BOUNCE_SIZE,
 			dwc->ep0_bounce, dwc->ep0_bounce_addr);
 
 err3:
 	kfree(dwc->setup_buf);
 
 err2:
-	dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb) * 2,
+	dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2,
 			dwc->ep0_trb, dwc->ep0_trb_addr);
 
 err1:
-	dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
+	dma_free_coherent(dwc->sysdev, sizeof(*dwc->ctrl_req),
 			dwc->ctrl_req, dwc->ctrl_req_addr);
 
 err0:
@@ -3098,16 +3099,16 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
 
 	dwc3_gadget_free_endpoints(dwc);
 
-	dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE,
+	dma_free_coherent(dwc->sysdev, DWC3_EP0_BOUNCE_SIZE,
 			dwc->ep0_bounce, dwc->ep0_bounce_addr);
 
 	kfree(dwc->setup_buf);
 	kfree(dwc->zlp_buf);
 
-	dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb) * 2,
+	dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2,
 			dwc->ep0_trb, dwc->ep0_trb_addr);
 
-	dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
+	dma_free_coherent(dwc->sysdev, sizeof(*dwc->ctrl_req),
 			dwc->ctrl_req, dwc->ctrl_req_addr);
 }
 
drivers/usb/dwc3/host.c +6 -10
index 8c2679e..487f0ff 100644
@@ -84,11 +84,7 @@ int dwc3_host_init(struct dwc3 *dwc)
 		return -ENOMEM;
 	}
 
-	dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
-
 	xhci->dev.parent	= dwc->dev;
-	xhci->dev.dma_mask	= dwc->dev->dma_mask;
-	xhci->dev.dma_parms	= dwc->dev->dma_parms;
 
 	dwc->xhci = xhci;
 
@@ -111,9 +107,9 @@ int dwc3_host_init(struct dwc3 *dwc)
 	}
 
 	phy_create_lookup(dwc->usb2_generic_phy, "usb2-phy",
-			  dev_name(&xhci->dev));
+			  dev_name(dwc->dev));
 	phy_create_lookup(dwc->usb3_generic_phy, "usb3-phy",
-			  dev_name(&xhci->dev));
+			  dev_name(dwc->dev));
 
 	ret = platform_device_add(xhci);
 	if (ret) {
@@ -124,9 +120,9 @@ int dwc3_host_init(struct dwc3 *dwc)
 	return 0;
 err2:
 	phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
-			  dev_name(&xhci->dev));
+			  dev_name(dwc->dev));
 	phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
-			  dev_name(&xhci->dev));
+			  dev_name(dwc->dev));
 err1:
 	platform_device_put(xhci);
 	return ret;
@@ -135,8 +131,8 @@ int dwc3_host_init(struct dwc3 *dwc)
 void dwc3_host_exit(struct dwc3 *dwc)
 {
 	phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
-			  dev_name(&dwc->xhci->dev));
+			  dev_name(dwc->dev));
 	phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
-			  dev_name(&dwc->xhci->dev));
+			  dev_name(dwc->dev));
 	platform_device_unregister(dwc->xhci);
 }
Signature · 1 line
2.1.0
Tested-by on v5 5/6
#17 lore raw

Re: [v5,5/6] usb: dwc3: use bus->sysdev for DMA configuration

Hi!

Quoted 9 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

The dma ops for dwc3 devices are not set properly. So, use a physical device sysdev, which will be inherited from parent, to set the hardware / firmware parameters like dma.

Successfully tested on arm64/axxia with DWC3 USB host, XHCIs properly inherit DMA configuration. Therefore:

Quoted 348 lines

---
Changes in v5:
- rebase to usb testing/next

Changes in v4:
- removed the ifdefs for pci
- made the sysdev as a device property
- phy create lookup take up the correct device.

Changes in v3:
- No update

Changes in v2:
- integrate dwc3 driver changes together

 drivers/usb/dwc3/core.c     | 27 ++++++++++++++-------------
 drivers/usb/dwc3/core.h     |  3 +++
 drivers/usb/dwc3/dwc3-pci.c | 10 ++++++++++
 drivers/usb/dwc3/ep0.c      |  8 ++++----
 drivers/usb/dwc3/gadget.c   | 33 +++++++++++++++++----------------
 drivers/usb/dwc3/host.c     | 16 ++++++----------
 6 files changed, 54 insertions(+), 43 deletions(-)
drivers/usb/dwc3/core.c +14 -13
index e951448..e5fbab2 100644
@@ -202,7 +202,7 @@ static void dwc3_frame_length_adjustment(struct dwc3 *dwc)
 static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
 		struct dwc3_event_buffer *evt)
 {
-	dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma);
+	dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma);
 }
 
 /**
@@ -228,7 +228,7 @@ static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
 	if (!evt->cache)
 		return ERR_PTR(-ENOMEM);
 
-	evt->buf	= dma_alloc_coherent(dwc->dev, length,
+	evt->buf	= dma_alloc_coherent(dwc->sysdev, length,
 			&evt->dma, GFP_KERNEL);
 	if (!evt->buf)
 		return ERR_PTR(-ENOMEM);
@@ -341,11 +341,11 @@ static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
 	if (!WARN_ON(dwc->scratchbuf))
 		return 0;
 
-	scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf,
+	scratch_addr = dma_map_single(dwc->sysdev, dwc->scratchbuf,
 			dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
 			DMA_BIDIRECTIONAL);
-	if (dma_mapping_error(dwc->dev, scratch_addr)) {
-		dev_err(dwc->dev, "failed to map scratch buffer\n");
+	if (dma_mapping_error(dwc->sysdev, scratch_addr)) {
+		dev_err(dwc->sysdev, "failed to map scratch buffer\n");
 		ret = -EFAULT;
 		goto err0;
 	}
@@ -369,7 +369,7 @@ static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
 	return 0;
 
 err1:
-	dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
+	dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch *
 			DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
 
 err0:
@@ -388,7 +388,7 @@ static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
 	if (!WARN_ON(dwc->scratchbuf))
 		return;
 
-	dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
+	dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch *
 			DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
 	kfree(dwc->scratchbuf);
 }
@@ -927,6 +927,13 @@ static void dwc3_get_properties(struct dwc3 *dwc)
 	dwc->dr_mode = usb_get_dr_mode(dev);
 	dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node);
 
+	dwc->sysdev_is_parent = device_property_read_bool(dev,
+				"linux,sysdev_is_parent");
+	if (dwc->sysdev_is_parent)
+		dwc->sysdev = dwc->dev->parent;
+	else
+		dwc->sysdev = dwc->dev;
+
 	dwc->has_lpm_erratum = device_property_read_bool(dev,
 				"snps,has-lpm-erratum");
 	device_property_read_u8(dev, "snps,lpm-nyet-threshold",
@@ -1097,12 +1104,6 @@ static int dwc3_probe(struct platform_device *pdev)
 
 	spin_lock_init(&dwc->lock);
 
-	if (!dev->dma_mask) {
-		dev->dma_mask = dev->parent->dma_mask;
-		dev->dma_parms = dev->parent->dma_parms;
-		dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
-	}
-
 	pm_runtime_set_active(dev);
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY);
drivers/usb/dwc3/core.h +3 -0
index ef81fa5..de5a857 100644
@@ -819,6 +819,7 @@ struct dwc3_scratchpad_array {
  * @ep0_bounced: true when we used bounce buffer
  * @ep0_expect_in: true when we expect a DATA IN transfer
  * @has_hibernation: true when dwc3 was configured with Hibernation
+ * @sysdev_is_parent: true when dwc3 device has a parent driver
  * @has_lpm_erratum: true when core was configured with LPM Erratum. Note that
  *			there's now way for software to detect this in runtime.
  * @is_utmi_l1_suspend: the core asserts output signal
@@ -875,6 +876,7 @@ struct dwc3 {
 	spinlock_t		lock;
 
 	struct device		*dev;
+	struct device		*sysdev;
 
 	struct platform_device	*xhci;
 	struct resource		xhci_resources[DWC3_XHCI_RESOURCES_NUM];
@@ -976,6 +978,7 @@ struct dwc3 {
 	unsigned		ep0_bounced:1;
 	unsigned		ep0_expect_in:1;
 	unsigned		has_hibernation:1;
+	unsigned		sysdev_is_parent:1;
 	unsigned		has_lpm_erratum:1;
 	unsigned		is_utmi_l1_suspend:1;
 	unsigned		is_fpga:1;
drivers/usb/dwc3/dwc3-pci.c +10 -0
index 2b0e34d..2b73339 100644
@@ -73,6 +73,16 @@ static int dwc3_pci_quirks(struct dwc3_pci *dwc)
 {
 	struct platform_device		*dwc3 = dwc->dwc3;
 	struct pci_dev			*pdev = dwc->pci;
+	int				ret;
+
+	struct property_entry sysdev_property[] = {
+		PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
+		{ },
+	};
+
+	ret = platform_device_add_properties(dwc3, sysdev_property);
+	if (ret)
+		return ret;
 
 	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
 	    pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
drivers/usb/dwc3/ep0.c +4 -4
index 2b22ea7..2d7fb2d 100644
@@ -1000,8 +1000,8 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
 		u32	transfer_size = 0;
 		u32	maxpacket;
 
-		ret = usb_gadget_map_request(&dwc->gadget, &req->request,
-				dep->number);
+		ret = usb_gadget_map_request_by_dev(dwc->sysdev,
+				&req->request, dep->number);
 		if (ret)
 			return;
 
@@ -1026,8 +1026,8 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
 				dwc->ep0_bounce_addr, transfer_size,
 				DWC3_TRBCTL_CONTROL_DATA, false);
 	} else {
-		ret = usb_gadget_map_request(&dwc->gadget, &req->request,
-				dep->number);
+		ret = usb_gadget_map_request_by_dev(dwc->sysdev,
+				&req->request, dep->number);
 		if (ret)
 			return;
 
drivers/usb/dwc3/gadget.c +17 -16
index e2416de..6785595 100644
@@ -183,8 +183,8 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
 	if (dwc->ep0_bounced && dep->number == 0)
 		dwc->ep0_bounced = false;
 	else
-		usb_gadget_unmap_request(&dwc->gadget, &req->request,
-				req->direction);
+		usb_gadget_unmap_request_by_dev(dwc->sysdev,
+				&req->request, req->direction);
 
 	trace_dwc3_gadget_giveback(req);
 
@@ -399,7 +399,7 @@ static int dwc3_alloc_trb_pool(struct dwc3_ep *dep)
 	if (dep->trb_pool)
 		return 0;
 
-	dep->trb_pool = dma_alloc_coherent(dwc->dev,
+	dep->trb_pool = dma_alloc_coherent(dwc->sysdev,
 			sizeof(struct dwc3_trb) * DWC3_TRB_NUM,
 			&dep->trb_pool_dma, GFP_KERNEL);
 	if (!dep->trb_pool) {
@@ -415,7 +415,7 @@ static void dwc3_free_trb_pool(struct dwc3_ep *dep)
 {
 	struct dwc3		*dwc = dep->dwc;
 
-	dma_free_coherent(dwc->dev, sizeof(struct dwc3_trb) * DWC3_TRB_NUM,
+	dma_free_coherent(dwc->sysdev, sizeof(struct dwc3_trb) * DWC3_TRB_NUM,
 			dep->trb_pool, dep->trb_pool_dma);
 
 	dep->trb_pool = NULL;
@@ -1171,8 +1171,8 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
 
 	trace_dwc3_ep_queue(req);
 
-	ret = usb_gadget_map_request(&dwc->gadget, &req->request,
-			dep->direction);
+	ret = usb_gadget_map_request_by_dev(dwc->sysdev, &req->request,
+					    dep->direction);
 	if (ret)
 		return ret;
 
@@ -2977,7 +2977,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 
 	dwc->irq_gadget = irq;
 
-	dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
+	dwc->ctrl_req = dma_alloc_coherent(dwc->sysdev, sizeof(*dwc->ctrl_req),
 			&dwc->ctrl_req_addr, GFP_KERNEL);
 	if (!dwc->ctrl_req) {
 		dev_err(dwc->dev, "failed to allocate ctrl request\n");
@@ -2985,8 +2985,9 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 		goto err0;
 	}
 
-	dwc->ep0_trb = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ep0_trb) * 2,
-			&dwc->ep0_trb_addr, GFP_KERNEL);
+	dwc->ep0_trb = dma_alloc_coherent(dwc->sysdev,
+					  sizeof(*dwc->ep0_trb) * 2,
+					  &dwc->ep0_trb_addr, GFP_KERNEL);
 	if (!dwc->ep0_trb) {
 		dev_err(dwc->dev, "failed to allocate ep0 trb\n");
 		ret = -ENOMEM;
@@ -2999,7 +3000,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 		goto err2;
 	}
 
-	dwc->ep0_bounce = dma_alloc_coherent(dwc->dev,
+	dwc->ep0_bounce = dma_alloc_coherent(dwc->sysdev,
 			DWC3_EP0_BOUNCE_SIZE, &dwc->ep0_bounce_addr,
 			GFP_KERNEL);
 	if (!dwc->ep0_bounce) {
@@ -3072,18 +3073,18 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 
 err4:
 	dwc3_gadget_free_endpoints(dwc);
-	dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE,
+	dma_free_coherent(dwc->sysdev, DWC3_EP0_BOUNCE_SIZE,
 			dwc->ep0_bounce, dwc->ep0_bounce_addr);
 
 err3:
 	kfree(dwc->setup_buf);
 
 err2:
-	dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb) * 2,
+	dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2,
 			dwc->ep0_trb, dwc->ep0_trb_addr);
 
 err1:
-	dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
+	dma_free_coherent(dwc->sysdev, sizeof(*dwc->ctrl_req),
 			dwc->ctrl_req, dwc->ctrl_req_addr);
 
 err0:
@@ -3098,16 +3099,16 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
 
 	dwc3_gadget_free_endpoints(dwc);
 
-	dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE,
+	dma_free_coherent(dwc->sysdev, DWC3_EP0_BOUNCE_SIZE,
 			dwc->ep0_bounce, dwc->ep0_bounce_addr);
 
 	kfree(dwc->setup_buf);
 	kfree(dwc->zlp_buf);
 
-	dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb) * 2,
+	dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2,
 			dwc->ep0_trb, dwc->ep0_trb_addr);
 
-	dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
+	dma_free_coherent(dwc->sysdev, sizeof(*dwc->ctrl_req),
 			dwc->ctrl_req, dwc->ctrl_req_addr);
 }
 
drivers/usb/dwc3/host.c +6 -10
index 8c2679e..487f0ff 100644
@@ -84,11 +84,7 @@ int dwc3_host_init(struct dwc3 *dwc)
 		return -ENOMEM;
 	}
 
-	dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
-
 	xhci->dev.parent	= dwc->dev;
-	xhci->dev.dma_mask	= dwc->dev->dma_mask;
-	xhci->dev.dma_parms	= dwc->dev->dma_parms;
 
 	dwc->xhci = xhci;
 
@@ -111,9 +107,9 @@ int dwc3_host_init(struct dwc3 *dwc)
 	}
 
 	phy_create_lookup(dwc->usb2_generic_phy, "usb2-phy",
-			  dev_name(&xhci->dev));
+			  dev_name(dwc->dev));
 	phy_create_lookup(dwc->usb3_generic_phy, "usb3-phy",
-			  dev_name(&xhci->dev));
+			  dev_name(dwc->dev));
 
 	ret = platform_device_add(xhci);
 	if (ret) {
@@ -124,9 +120,9 @@ int dwc3_host_init(struct dwc3 *dwc)
 	return 0;
 err2:
 	phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
-			  dev_name(&xhci->dev));
+			  dev_name(dwc->dev));
 	phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
-			  dev_name(&xhci->dev));
+			  dev_name(dwc->dev));
 err1:
 	platform_device_put(xhci);
 	return ret;
@@ -135,8 +131,8 @@ int dwc3_host_init(struct dwc3 *dwc)
 void dwc3_host_exit(struct dwc3 *dwc)
 {
 	phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
-			  dev_name(&dwc->xhci->dev));
+			  dev_name(dwc->dev));
 	phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
-			  dev_name(&dwc->xhci->dev));
+			  dev_name(dwc->dev));
 	platform_device_unregister(dwc->xhci);
 }
Signature · 2 lines
Best regards,
Alexander Sverdlin.
#18 lore raw

PATCH v5 6/6 usb: dwc3: Do not set dma coherent mask

In reply to Sriram Dash

From: Arnd Bergmann <[email protected]>

The dma mask is correctly set up by the DT probe function, no need to override it any more.

---
Changes in v5:
- No update

Changes in v4:
- No update

Changes in v3:
- No update

Changes in v2:
- club the cleanup for dma coherent mask for device

 drivers/usb/dwc3/dwc3-exynos.c | 10 ----------
 drivers/usb/dwc3/dwc3-st.c     |  1 -
 2 files changed, 11 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +0 -10
index 2f1fb7e..e27899b 100644
@@ -20,7 +20,6 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/platform_device.h>
-#include <linux/dma-mapping.h>
 #include <linux/clk.h>
 #include <linux/usb/otg.h>
 #include <linux/usb/usb_phy_generic.h>
@@ -117,15 +116,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
 	if (!exynos)
 		return -ENOMEM;
 
-	/*
-	 * Right now device-tree probed devices don't get dma_mask set.
-	 * Since shared usb code relies on it, set it here for now.
-	 * Once we move to full device tree support this will vanish off.
-	 */
-	ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
-	if (ret)
-		return ret;
-
 	platform_set_drvdata(pdev, exynos);
 
 	exynos->dev	= dev;
drivers/usb/dwc3/dwc3-st.c +0 -1
index 89a2f71..4d7439c 100644
@@ -218,7 +218,6 @@ static int st_dwc3_probe(struct platform_device *pdev)
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
 
-	dma_set_coherent_mask(dev, dev->coherent_dma_mask);
 	dwc3_data->dev = dev;
 	dwc3_data->regmap = regmap;
 
Signature · 1 line
2.1.0
Tested-by on v5 6/6
#19 lore raw

Re: [v5,6/6] usb: dwc3: Do not set dma coherent mask

Hi!

Quoted 7 lines · Sriram Dash

From: Arnd Bergmann <[email protected]>

The dma mask is correctly set up by the DT probe function, no need to override it any more.

Successfully tested on arm64/axxia with DWC3 USB host, XHCIs properly inherit DMA configuration. Therefore:

Quoted 58 lines

---
Changes in v5:
- No update

Changes in v4:
- No update

Changes in v3:
- No update

Changes in v2:
- club the cleanup for dma coherent mask for device

 drivers/usb/dwc3/dwc3-exynos.c | 10 ----------
 drivers/usb/dwc3/dwc3-st.c     |  1 -
 2 files changed, 11 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +0 -10
index 2f1fb7e..e27899b 100644
@@ -20,7 +20,6 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/platform_device.h>
-#include <linux/dma-mapping.h>
 #include <linux/clk.h>
 #include <linux/usb/otg.h>
 #include <linux/usb/usb_phy_generic.h>
@@ -117,15 +116,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
 	if (!exynos)
 		return -ENOMEM;
 
-	/*
-	 * Right now device-tree probed devices don't get dma_mask set.
-	 * Since shared usb code relies on it, set it here for now.
-	 * Once we move to full device tree support this will vanish off.
-	 */
-	ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
-	if (ret)
-		return ret;
-
 	platform_set_drvdata(pdev, exynos);
 
 	exynos->dev	= dev;
drivers/usb/dwc3/dwc3-st.c +0 -1
index 89a2f71..4d7439c 100644
@@ -218,7 +218,6 @@ static int st_dwc3_probe(struct platform_device *pdev)
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
 
-	dma_set_coherent_mask(dev, dev->coherent_dma_mask);
 	dwc3_data->dev = dev;
 	dwc3_data->regmap = regmap;
 
Signature · 2 lines
Best regards,
Alexander Sverdlin.
Tested-by on the v5 series
#20 lore raw
In reply to Sriram Dash
Quoted 8 lines · Sriram Dash

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices.

The idea here is that you pass in the parent of_node along with the child device pointer, so it would behave exactly like the parent already does. The difference is that it also handles all the other attributes besides the mask.

Quoted 7 lines

Arnd Bergmann (6):
usb: separate out sysdev pointer from usb_bus
usb: chipidea: use bus->sysdev for DMA configuration
usb: ehci: fsl: use bus->sysdev for DMA configuration
usb: xhci: use bus->sysdev for DMA configuration
usb: dwc3: use bus->sysdev for DMA configuration
usb: dwc3: Do not set dma coherent mask

Tested patches 1, 4 & 5 on db820c platform with required set of patches [1] for phy.

for the above mentioned patches.

[1] https://lkml.org/lkml/2016/12/20/392

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#21 lore raw
In reply to Sriram Dash

Hi,

Quoted 8 lines · Sriram Dash

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices.

The idea here is that you pass in the parent of_node along with the child device pointer, so it would behave exactly like the parent already does. The difference is that it also handles all the other attributes besides the mask.

Quoted 7 lines

Arnd Bergmann (6):
usb: separate out sysdev pointer from usb_bus
usb: chipidea: use bus->sysdev for DMA configuration
usb: ehci: fsl: use bus->sysdev for DMA configuration
usb: xhci: use bus->sysdev for DMA configuration
usb: dwc3: use bus->sysdev for DMA configuration
usb: dwc3: Do not set dma coherent mask

Only the dwc3 patches have been picked up for v4.10 and the rest are still missing. Any plans to pick them in the rc cycle?

DMA configuration is still broken for XHCI on v4.10 and -next.

cheers,
-roger

Quoted 23 lines
 drivers/usb/chipidea/core.c    |  3 ---
 drivers/usb/chipidea/host.c    |  3 ++-
 drivers/usb/chipidea/udc.c     | 10 +++++----
 drivers/usb/core/buffer.c      | 12 +++++------
 drivers/usb/core/hcd.c         | 48 +++++++++++++++++++++++++-----------------
 drivers/usb/core/usb.c         | 18 ++++++++--------
 drivers/usb/dwc3/core.c        | 27 ++++++++++++------------
 drivers/usb/dwc3/core.h        |  3 +++
 drivers/usb/dwc3/dwc3-exynos.c | 10 ---------
 drivers/usb/dwc3/dwc3-pci.c    | 10 +++++++++
 drivers/usb/dwc3/dwc3-st.c     |  1 -
 drivers/usb/dwc3/ep0.c         |  8 +++----
 drivers/usb/dwc3/gadget.c      | 33 +++++++++++++++--------------
 drivers/usb/dwc3/host.c        | 16 ++++++--------
 drivers/usb/host/ehci-fsl.c    |  4 ++--
 drivers/usb/host/xhci-mem.c    | 12 +++++------
 drivers/usb/host/xhci-plat.c   | 33 +++++++++++++++++++++++------
 drivers/usb/host/xhci.c        | 15 +++++++++----
 include/linux/usb.h            |  1 +
 include/linux/usb/hcd.h        |  3 +++
 20 files changed, 155 insertions(+), 115 deletions(-)
maintainer
#22 lore raw
Quoted 19 lines · Roger Quadros

Hi,

Quoted 8 lines · Sriram Dash

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices.

The idea here is that you pass in the parent of_node along with the child device pointer, so it would behave exactly like the parent already does. The difference is that it also handles all the other attributes besides the mask.

Quoted 7 lines

Arnd Bergmann (6):
usb: separate out sysdev pointer from usb_bus
usb: chipidea: use bus->sysdev for DMA configuration
usb: ehci: fsl: use bus->sysdev for DMA configuration
usb: xhci: use bus->sysdev for DMA configuration
usb: dwc3: use bus->sysdev for DMA configuration
usb: dwc3: Do not set dma coherent mask

Quoted 4 lines

Only the dwc3 patches have been picked up for v4.10 and the rest are still missing. Any plans to pick them in the rc cycle?

DMA configuration is still broken for XHCI on v4.10 and -next.

It's always been broken, so it's not a big deal for 4.10 :)

#23 lore raw
Quoted 20 lines · Greg KH
Quoted 19 lines · Roger Quadros

Hi,

Quoted 15 lines · Sriram Dash

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices.

The idea here is that you pass in the parent of_node along with the child device pointer, so it would behave exactly like the parent already does. The difference is that it also handles all the other attributes besides the mask.

Arnd Bergmann (6):
usb: separate out sysdev pointer from usb_bus
usb: chipidea: use bus->sysdev for DMA configuration
usb: ehci: fsl: use bus->sysdev for DMA configuration
usb: xhci: use bus->sysdev for DMA configuration
usb: dwc3: use bus->sysdev for DMA configuration
usb: dwc3: Do not set dma coherent mask

Quoted 7 lines
Quoted 4 lines

Only the dwc3 patches have been picked up for v4.10 and the rest are still missing. Any plans to pick them in the rc cycle?

DMA configuration is still broken for XHCI on v4.10 and -next.

It's always been broken, so it's not a big deal for 4.10 :)

OK. But I do see the following warning on xhci probe on TI platforms that use dwc3 IP. This is new in v4.10.

[   11.664835] ------------[ cut here ]------------
[   11.669693] WARNING: CPU: 1 PID: 534 at drivers/usb/host/xhci-plat.c:168 xhci_plat_probe+0x180/0x450 [xhci_plat_hcd]
[   11.680765] Modules linked in: xhci_plat_hcd(+) xhci_hcd usbcore evdev dwc3 snd_soc_simple_card snd_soc_tlv320aic3x snd_soc_simple_card_utils udc_core m25p80 snd_soc_davinci_mcasp usb_common spi_nor snd_soc_e
[   11.726078] CPU: 1 PID: 534 Comm: modprobe Tainted: G        W       4.10.0-rc3 #1075
[   11.734293] Hardware name: Generic DRA74X (Flattened Device Tree)
[   11.740695] [<c011013c>] (unwind_backtrace) from [<c010c300>] (show_stack+0x10/0x14)
[   11.748829] [<c010c300>] (show_stack) from [<c04a0018>] (dump_stack+0xac/0xe0)
[   11.756413] [<c04a0018>] (dump_stack) from [<c013700c>] (__warn+0xd8/0x104)
[   11.763722] [<c013700c>] (__warn) from [<c01370e4>] (warn_slowpath_null+0x20/0x28)
[   11.771675] [<c01370e4>] (warn_slowpath_null) from [<bf317280>] (xhci_plat_probe+0x180/0x450 [xhci_plat_hcd])
[   11.782110] [<bf317280>] (xhci_plat_probe [xhci_plat_hcd]) from [<c055f390>] (platform_drv_probe+0x4c/0xb0)
[   11.792338] [<c055f390>] (platform_drv_probe) from [<c055d3ec>] (driver_probe_device+0x200/0x2d4)
[   11.801655] [<c055d3ec>] (driver_probe_device) from [<c055d580>] (__driver_attach+0xc0/0xc4)
[   11.810518] [<c055d580>] (__driver_attach) from [<c055b868>] (bus_for_each_dev+0x6c/0xa0)
[   11.819095] [<c055b868>] (bus_for_each_dev) from [<c055c9cc>] (bus_add_driver+0x18c/0x214)
[   11.827767] [<c055c9cc>] (bus_add_driver) from [<c055e3b8>] (driver_register+0x78/0xf8)
[   11.836167] [<c055e3b8>] (driver_register) from [<c010188c>] (do_one_initcall+0x3c/0x174)
[   11.844751] [<c010188c>] (do_one_initcall) from [<c023c084>] (do_init_module+0x5c/0x1d0)
[   11.853247] [<c023c084>] (do_init_module) from [<c01da5a8>] (load_module+0x1d48/0x23a8)
[   11.861649] [<c01da5a8>] (load_module) from [<c01dad58>] (SyS_init_module+0x150/0x174)
[   11.869961] [<c01dad58>] (SyS_init_module) from [<c0107860>] (ret_fast_syscall+0x0/0x1c)
[   11.878494] ---[ end trace a0ca4c6c0c9a9ee9 ]---
[   11.883400] xhci-hcd xhci-hcd.0.auto: xHCI Host Controller

cheers,
-roger

#24 lore raw

[adding Arnd Bergmann who wrote the patches and I noticed was not cc'ed]

Hello,

Quoted 24 lines · Roger Quadros
Quoted 23 lines · Greg KH
Quoted 22 lines · Roger Quadros

Hi,

Quoted 8 lines · Sriram Dash

For xhci-hcd platform device, all the DMA parameters are not configured properly, notably dma ops for dwc3 devices.

The idea here is that you pass in the parent of_node along with the child device pointer, so it would behave exactly like the parent already does. The difference is that it also handles all the other attributes besides the mask.

Quoted 7 lines

Arnd Bergmann (6):
usb: separate out sysdev pointer from usb_bus
usb: chipidea: use bus->sysdev for DMA configuration
usb: ehci: fsl: use bus->sysdev for DMA configuration
usb: xhci: use bus->sysdev for DMA configuration
usb: dwc3: use bus->sysdev for DMA configuration
usb: dwc3: Do not set dma coherent mask

Only the dwc3 patches have been picked up for v4.10 and the rest are still missing. Any plans to pick them in the rc cycle?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

DMA configuration is still broken for XHCI on v4.10 and -next.

It's always been broken, so it's not a big deal for 4.10 :)

OK. But I do see the following warning on xhci probe on TI platforms that use dwc3 IP. This is new in v4.10.

I see a similar warning on an Exynos5800 machine (Peach Pi). This is new starting from v4.10-rc1.

Quoted 15 lines
[   11.664835] ------------[ cut here ]------------
[   11.669693] WARNING: CPU: 1 PID: 534 at drivers/usb/host/xhci-plat.c:168 xhci_plat_probe+0x180/0x450 [xhci_plat_hcd]
[   11.680765] Modules linked in: xhci_plat_hcd(+) xhci_hcd usbcore evdev dwc3 snd_soc_simple_card snd_soc_tlv320aic3x snd_soc_simple_card_utils udc_core m25p80 snd_soc_davinci_mcasp usb_common spi_nor snd_soc_e
[   11.726078] CPU: 1 PID: 534 Comm: modprobe Tainted: G        W       4.10.0-rc3 #1075
[   11.734293] Hardware name: Generic DRA74X (Flattened Device Tree)
[   11.740695] [<c011013c>] (unwind_backtrace) from [<c010c300>] (show_stack+0x10/0x14)
[   11.748829] [<c010c300>] (show_stack) from [<c04a0018>] (dump_stack+0xac/0xe0)
[   11.756413] [<c04a0018>] (dump_stack) from [<c013700c>] (__warn+0xd8/0x104)
[   11.763722] [<c013700c>] (__warn) from [<c01370e4>] (warn_slowpath_null+0x20/0x28)
[   11.771675] [<c01370e4>] (warn_slowpath_null) from [<bf317280>] (xhci_plat_probe+0x180/0x450 [xhci_plat_hcd])
[   11.782110] [<bf317280>] (xhci_plat_probe [xhci_plat_hcd]) from [<c055f390>] (platform_drv_probe+0x4c/0xb0)
[   11.792338] [<c055f390>] (platform_drv_probe) from [<c055d3ec>] (driver_probe_device+0x200/0x2d4)
[   11.801655] [<c055d3ec>] (driver_probe_device) from [<c055d580>] (__driver_attach+0xc0/0xc4)
[   11.810518] [<c055d580>] (__driver_attach) from [<c055b868>] (bus_for_each_dev+0x6c/0xa0)
[   11.819095] [<c055b868>] (bus_for_each_dev) from [<c055c9cc>] (bus_add_driver+0x18c/0x214)
Quoted 9 lines
[   11.827767] [<c055c9cc>] (bus_add_driver) from [<c055e3b8>] (driver_register+0x78/0xf8)
[   11.836167] [<c055e3b8>] (driver_register) from [<c010188c>] (do_one_initcall+0x3c/0x174)
[   11.844751] [<c010188c>] (do_one_initcall) from [<c023c084>] (do_init_module+0x5c/0x1d0)
[   11.853247] [<c023c084>] (do_init_module) from [<c01da5a8>] (load_module+0x1d48/0x23a8)
[   11.861649] [<c01da5a8>] (load_module) from [<c01dad58>] (SyS_init_module+0x150/0x174)
[   11.869961] [<c01dad58>] (SyS_init_module) from [<c0107860>] (ret_fast_syscall+0x0/0x1c)
[   11.878494] ---[ end trace a0ca4c6c0c9a9ee9 ]---
[   11.883400] xhci-hcd xhci-hcd.0.auto: xHCI Host Controller

I tracked down to commit d64ff406e51e ("usb: dwc3: use bus->sysdev for DMA configuration") which is part of this series. If I revert that commit, the warning goes away.

Best regards,
Javier