[PATCH 3/6] usb: add a HCD_DMA flag instead of guestimating DMA capabilities

2019-08-16 Thread Christoph Hellwig
The usb core is the only major place in the kernel that checks for
a non-NULL device dma_mask to see if a device is DMA capable.  This
is generally a bad idea, as all major busses always set up a DMA mask,
even if the device is not DMA capable - in fact bus layers like PCI
can't even know if a device is DMA capable at enumeration time.  This
leads to lots of workaround in HCD drivers, and also prevented us from
setting up a DMA mask for platform devices by default last time we
tried.

Replace this guess with an explicit HCD_DMA that is set by drivers that
appear to have DMA support.

Signed-off-by: Christoph Hellwig 
---
 drivers/staging/octeon-usb/octeon-hcd.c | 2 +-
 drivers/usb/core/hcd.c  | 1 -
 drivers/usb/dwc2/hcd.c  | 6 +++---
 drivers/usb/host/ehci-grlib.c   | 2 +-
 drivers/usb/host/ehci-hcd.c | 2 +-
 drivers/usb/host/ehci-pmcmsp.c  | 2 +-
 drivers/usb/host/ehci-ppc-of.c  | 2 +-
 drivers/usb/host/ehci-ps3.c | 2 +-
 drivers/usb/host/ehci-sh.c  | 2 +-
 drivers/usb/host/ehci-xilinx-of.c   | 2 +-
 drivers/usb/host/fhci-hcd.c | 2 +-
 drivers/usb/host/fotg210-hcd.c  | 2 +-
 drivers/usb/host/imx21-hcd.c| 2 +-
 drivers/usb/host/isp116x-hcd.c  | 6 --
 drivers/usb/host/isp1362-hcd.c  | 5 -
 drivers/usb/host/ohci-hcd.c | 2 +-
 drivers/usb/host/ohci-ppc-of.c  | 2 +-
 drivers/usb/host/ohci-ps3.c | 2 +-
 drivers/usb/host/ohci-sa.c  | 2 +-
 drivers/usb/host/ohci-sm501.c   | 2 +-
 drivers/usb/host/ohci-tmio.c| 2 +-
 drivers/usb/host/oxu210hp-hcd.c | 3 ---
 drivers/usb/host/r8a66597-hcd.c | 6 --
 drivers/usb/host/sl811-hcd.c| 6 --
 drivers/usb/host/u132-hcd.c | 2 --
 drivers/usb/host/uhci-grlib.c   | 2 +-
 drivers/usb/host/uhci-pci.c | 2 +-
 drivers/usb/host/uhci-platform.c| 2 +-
 drivers/usb/host/xhci.c | 2 +-
 drivers/usb/isp1760/isp1760-core.c  | 3 ---
 drivers/usb/isp1760/isp1760-if.c| 1 -
 drivers/usb/musb/musb_host.c| 2 +-
 drivers/usb/renesas_usbhs/mod_host.c| 2 +-
 include/linux/usb.h | 1 -
 include/linux/usb/hcd.h | 7 +--
 35 files changed, 31 insertions(+), 62 deletions(-)

diff --git a/drivers/staging/octeon-usb/octeon-hcd.c 
b/drivers/staging/octeon-usb/octeon-hcd.c
index cd2b777073c4..a5321cc692c5 100644
--- a/drivers/staging/octeon-usb/octeon-hcd.c
+++ b/drivers/staging/octeon-usb/octeon-hcd.c
@@ -3512,7 +3512,7 @@ static const struct hc_driver octeon_hc_driver = {
.product_desc   = "Octeon Host Controller",
.hcd_priv_size  = sizeof(struct octeon_hcd),
.irq= octeon_usb_irq,
-   .flags  = HCD_MEMORY | HCD_USB2,
+   .flags  = HCD_MEMORY | HCD_DMA | HCD_USB2,
.start  = octeon_usb_start,
.stop   = octeon_usb_stop,
.urb_enqueue= octeon_usb_urb_enqueue,
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 8592c0344fe8..add2af4af766 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2454,7 +2454,6 @@ struct usb_hcd *__usb_create_hcd(const struct hc_driver 
*driver,
hcd->self.controller = dev;
hcd->self.sysdev = sysdev;
hcd->self.bus_name = bus_name;
-   hcd->self.uses_dma = (sysdev->dma_mask != NULL);
 
timer_setup(>rh_timer, rh_timer_func, 0);
 #ifdef CONFIG_PM
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 111787a137ee..81afe553aa66 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -5062,13 +5062,13 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg)
dwc2_hc_driver.reset_device = dwc2_reset_device;
}
 
+   if (hsotg->params.host_dma)
+   dwc2_hc_driver.flags |= HCD_DMA;
+
hcd = usb_create_hcd(_hc_driver, hsotg->dev, dev_name(hsotg->dev));
if (!hcd)
goto error1;
 
-   if (!hsotg->params.host_dma)
-   hcd->self.uses_dma = 0;
-
hcd->has_tt = 1;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/usb/host/ehci-grlib.c b/drivers/usb/host/ehci-grlib.c
index 656b8c08efc8..a2c3b4ec8a8b 100644
--- a/drivers/usb/host/ehci-grlib.c
+++ b/drivers/usb/host/ehci-grlib.c
@@ -30,7 +30,7 @@ static const struct hc_driver ehci_grlib_hc_driver = {
 * generic hardware linkage
 */
.irq= ehci_irq,
-   .flags  = HCD_MEMORY | HCD_USB2 | HCD_BH,
+   .flags  = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH,
 
/*
 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 9da7e22848c9..cf2b7ae93b7e 100644
--- 

Re: [PATCH 3/6] usb: add a HCD_DMA flag instead of guestimating DMA capabilities

2019-08-12 Thread Christoph Hellwig
> diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
> index 576f7d79ad4e..9d17e0695e35 100644
> --- a/drivers/usb/host/ehci-ppc-of.c
> +++ b/drivers/usb/host/ehci-ppc-of.c
> @@ -31,7 +31,7 @@ static const struct hc_driver ehci_ppc_of_hc_driver = {
>* generic hardware linkage
>*/
>   .irq= ehci_irq,
> - .flags  = HCD_MEMORY | HCD_USB2 | HCD_BH,
> + .flags  = HCD_MEMORY | HC_DMA | HCD_USB2 | HCD_BH,

FYI, the kbuild bot found a little typo here, so even for the unlikely
case that the series is otherwise perfect I'll have to resend it at
least once.
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[PATCH 3/6] usb: add a HCD_DMA flag instead of guestimating DMA capabilities

2019-08-11 Thread Christoph Hellwig
The usb core is the only major place in the kernel that checks for
a non-NULL device dma_mask to see if a device is DMA capable.  This
is generally a bad idea, as all major busses always set up a DMA mask,
even if the device is not DMA capable - in fact bus layers like PCI
can't even know if a device is DMA capable at enumeration time.  This
leads to lots of workaround in HCD drivers, and also prevented us from
setting up a DMA mask for platform devices by default last time we
tried.

Replace this guess with an explicit HCD_DMA that is set by drivers that
appear to have DMA support.

Signed-off-by: Christoph Hellwig 
---
 drivers/staging/octeon-usb/octeon-hcd.c | 2 +-
 drivers/usb/core/hcd.c  | 1 -
 drivers/usb/dwc2/hcd.c  | 6 +++---
 drivers/usb/host/ehci-grlib.c   | 2 +-
 drivers/usb/host/ehci-hcd.c | 2 +-
 drivers/usb/host/ehci-pmcmsp.c  | 2 +-
 drivers/usb/host/ehci-ppc-of.c  | 2 +-
 drivers/usb/host/ehci-ps3.c | 2 +-
 drivers/usb/host/ehci-sh.c  | 2 +-
 drivers/usb/host/ehci-xilinx-of.c   | 2 +-
 drivers/usb/host/fhci-hcd.c | 2 +-
 drivers/usb/host/fotg210-hcd.c  | 2 +-
 drivers/usb/host/imx21-hcd.c| 2 +-
 drivers/usb/host/isp116x-hcd.c  | 6 --
 drivers/usb/host/isp1362-hcd.c  | 5 -
 drivers/usb/host/ohci-hcd.c | 2 +-
 drivers/usb/host/ohci-ppc-of.c  | 2 +-
 drivers/usb/host/ohci-ps3.c | 2 +-
 drivers/usb/host/ohci-sa.c  | 2 +-
 drivers/usb/host/ohci-sm501.c   | 2 +-
 drivers/usb/host/ohci-tmio.c| 2 +-
 drivers/usb/host/oxu210hp-hcd.c | 3 ---
 drivers/usb/host/r8a66597-hcd.c | 6 --
 drivers/usb/host/sl811-hcd.c| 6 --
 drivers/usb/host/u132-hcd.c | 2 --
 drivers/usb/host/uhci-grlib.c   | 2 +-
 drivers/usb/host/uhci-pci.c | 2 +-
 drivers/usb/host/uhci-platform.c| 2 +-
 drivers/usb/host/xhci.c | 2 +-
 drivers/usb/isp1760/isp1760-core.c  | 3 ---
 drivers/usb/isp1760/isp1760-if.c| 1 -
 drivers/usb/musb/musb_host.c| 2 +-
 drivers/usb/renesas_usbhs/mod_host.c| 2 +-
 include/linux/usb.h | 1 -
 include/linux/usb/hcd.h | 7 +--
 35 files changed, 31 insertions(+), 62 deletions(-)

diff --git a/drivers/staging/octeon-usb/octeon-hcd.c 
b/drivers/staging/octeon-usb/octeon-hcd.c
index cd2b777073c4..a5321cc692c5 100644
--- a/drivers/staging/octeon-usb/octeon-hcd.c
+++ b/drivers/staging/octeon-usb/octeon-hcd.c
@@ -3512,7 +3512,7 @@ static const struct hc_driver octeon_hc_driver = {
.product_desc   = "Octeon Host Controller",
.hcd_priv_size  = sizeof(struct octeon_hcd),
.irq= octeon_usb_irq,
-   .flags  = HCD_MEMORY | HCD_USB2,
+   .flags  = HCD_MEMORY | HCD_DMA | HCD_USB2,
.start  = octeon_usb_start,
.stop   = octeon_usb_stop,
.urb_enqueue= octeon_usb_urb_enqueue,
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 8592c0344fe8..add2af4af766 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2454,7 +2454,6 @@ struct usb_hcd *__usb_create_hcd(const struct hc_driver 
*driver,
hcd->self.controller = dev;
hcd->self.sysdev = sysdev;
hcd->self.bus_name = bus_name;
-   hcd->self.uses_dma = (sysdev->dma_mask != NULL);
 
timer_setup(>rh_timer, rh_timer_func, 0);
 #ifdef CONFIG_PM
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 111787a137ee..81afe553aa66 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -5062,13 +5062,13 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg)
dwc2_hc_driver.reset_device = dwc2_reset_device;
}
 
+   if (hsotg->params.host_dma)
+   dwc2_hc_driver.flags |= HCD_DMA;
+
hcd = usb_create_hcd(_hc_driver, hsotg->dev, dev_name(hsotg->dev));
if (!hcd)
goto error1;
 
-   if (!hsotg->params.host_dma)
-   hcd->self.uses_dma = 0;
-
hcd->has_tt = 1;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/usb/host/ehci-grlib.c b/drivers/usb/host/ehci-grlib.c
index 656b8c08efc8..a2c3b4ec8a8b 100644
--- a/drivers/usb/host/ehci-grlib.c
+++ b/drivers/usb/host/ehci-grlib.c
@@ -30,7 +30,7 @@ static const struct hc_driver ehci_grlib_hc_driver = {
 * generic hardware linkage
 */
.irq= ehci_irq,
-   .flags  = HCD_MEMORY | HCD_USB2 | HCD_BH,
+   .flags  = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH,
 
/*
 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 9da7e22848c9..cf2b7ae93b7e 100644
---