]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
usb: add a HCD_DMA flag instead of guestimating DMA capabilities
authorChristoph Hellwig <hch@lst.de>
Fri, 16 Aug 2019 06:24:32 +0000 (08:24 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Aug 2019 17:03:35 +0000 (10:03 -0700)
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 <hch@lst.de>
Link: https://lore.kernel.org/r/20190816062435.881-4-hch@lst.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
35 files changed:
drivers/staging/octeon-usb/octeon-hcd.c
drivers/usb/core/hcd.c
drivers/usb/dwc2/hcd.c
drivers/usb/host/ehci-grlib.c
drivers/usb/host/ehci-hcd.c
drivers/usb/host/ehci-pmcmsp.c
drivers/usb/host/ehci-ppc-of.c
drivers/usb/host/ehci-ps3.c
drivers/usb/host/ehci-sh.c
drivers/usb/host/ehci-xilinx-of.c
drivers/usb/host/fhci-hcd.c
drivers/usb/host/fotg210-hcd.c
drivers/usb/host/imx21-hcd.c
drivers/usb/host/isp116x-hcd.c
drivers/usb/host/isp1362-hcd.c
drivers/usb/host/ohci-hcd.c
drivers/usb/host/ohci-ppc-of.c
drivers/usb/host/ohci-ps3.c
drivers/usb/host/ohci-sa1111.c
drivers/usb/host/ohci-sm501.c
drivers/usb/host/ohci-tmio.c
drivers/usb/host/oxu210hp-hcd.c
drivers/usb/host/r8a66597-hcd.c
drivers/usb/host/sl811-hcd.c
drivers/usb/host/u132-hcd.c
drivers/usb/host/uhci-grlib.c
drivers/usb/host/uhci-pci.c
drivers/usb/host/uhci-platform.c
drivers/usb/host/xhci.c
drivers/usb/isp1760/isp1760-core.c
drivers/usb/isp1760/isp1760-if.c
drivers/usb/musb/musb_host.c
drivers/usb/renesas_usbhs/mod_host.c
include/linux/usb.h
include/linux/usb/hcd.h

index cd2b777073c42bfbd7cd63df3013426e0d32750c..a5321cc692c5029d05eabeed4516d38948f6cde4 100644 (file)
@@ -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,
index 8592c0344fe81f1458cacf1eaf55bfa516049121..add2af4af766da7bdd657cbfbce71b19818da6ba 100644 (file)
@@ -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(&hcd->rh_timer, rh_timer_func, 0);
 #ifdef CONFIG_PM
index 111787a137eead0bd65e554bc2a9705ad39dbcc9..81afe553aa666973b6174e501b899055d05c943f 100644 (file)
@@ -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(&dwc2_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);
index 656b8c08efc86cce6887acb1c98a680c52959007..a2c3b4ec8a8b5ff1183a9456a77b72cec8d1a4db 100644 (file)
@@ -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
index 9da7e22848c98827c43863a19c7da8259c4f6aeb..cf2b7ae93b7e907efb339c0f9bcd962259ce1ba1 100644 (file)
@@ -1193,7 +1193,7 @@ static const struct hc_driver ehci_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
index 46e160370d6e450c8368971516b6c61d58e958bc..a2b610dbedfc60911dd6b8be40ef0ecde561fed1 100644 (file)
@@ -250,7 +250,7 @@ static const struct hc_driver ehci_msp_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
index 576f7d79ad4eff122ef9a0c8690671ac51aa1c0e..6bbaee74f7e7dc7c07fc6110945ef68b2f524893 100644 (file)
@@ -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 | HCD_DMA | HCD_USB2 | HCD_BH,
 
        /*
         * basic lifecycle operations
index 454d8c624a3f5a8bcbef964be25c4819c5eb0a40..fb52133c3557fa40019bfe0efa07b3c3d275413f 100644 (file)
@@ -59,7 +59,7 @@ static const struct hc_driver ps3_ehci_hc_driver = {
        .product_desc           = "PS3 EHCI Host Controller",
        .hcd_priv_size          = sizeof(struct ehci_hcd),
        .irq                    = ehci_irq,
-       .flags                  = HCD_MEMORY | HCD_USB2 | HCD_BH,
+       .flags                  = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH,
        .reset                  = ps3_ehci_hc_reset,
        .start                  = ehci_run,
        .stop                   = ehci_stop,
index ef75b9d70eb4e4bf90a37c83b0458f62e73267e1..2afde14dc425c261ff0b0a235dde664ae80f975e 100644 (file)
@@ -33,7 +33,7 @@ static const struct hc_driver ehci_sh_hc_driver = {
         * generic hardware linkage
         */
        .irq                            = ehci_irq,
-       .flags                          = HCD_USB2 | HCD_MEMORY | HCD_BH,
+       .flags                          = HCD_USB2 | HCD_DMA | HCD_MEMORY | HCD_BH,
 
        /*
         * basic lifecycle operations
index d2a27578e44078457bec272c10f6491d3388f9f0..67a6ee8cb5d8058e5948afe2c32233c59860a949 100644 (file)
@@ -66,7 +66,7 @@ static const struct hc_driver ehci_xilinx_of_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
index 48fe9e6c24655513a1a1be6668d760e22d445662..04733876c9c6d0d47c37fa15f28251eb627abaa0 100644 (file)
@@ -538,7 +538,7 @@ static const struct hc_driver fhci_driver = {
 
        /* generic hardware linkage */
        .irq = fhci_irq,
-       .flags = HCD_USB11 | HCD_MEMORY,
+       .flags = HCD_DMA | HCD_USB11 | HCD_MEMORY,
 
        /* basic lifecycle operation */
        .start = fhci_start,
index 0dbfa5c107035df3e0158a1af07a271c600a2df6..9e0c98d6bdb09fc56a470b30b4416a6cc8a89834 100644 (file)
@@ -5508,7 +5508,7 @@ static const struct hc_driver fotg210_fotg210_hc_driver = {
         * generic hardware linkage
         */
        .irq                    = fotg210_irq,
-       .flags                  = HCD_MEMORY | HCD_USB2,
+       .flags                  = HCD_MEMORY | HCD_DMA | HCD_USB2,
 
        /*
         * basic lifecycle operations
index e406c5459a973ce29a1e48d3eefcdf8fd09af18d..5835f9966204626fbf5f29c769c233249a7b96bf 100644 (file)
@@ -1771,7 +1771,7 @@ static const struct hc_driver imx21_hc_driver = {
        .product_desc = "IMX21 USB Host Controller",
        .hcd_priv_size = sizeof(struct imx21),
 
-       .flags = HCD_USB11,
+       .flags = HCD_DMA | HCD_USB11,
        .irq = imx21_irq,
 
        .reset = imx21_hc_reset,
index 74da136d322ac93aba9e8ab7b6352e51bb5f86c0..a87c0b26279e71e4492ae377f7652b60dc0df40d 100644 (file)
@@ -1581,12 +1581,6 @@ static int isp116x_probe(struct platform_device *pdev)
        irq = ires->start;
        irqflags = ires->flags & IRQF_TRIGGER_MASK;
 
-       if (pdev->dev.dma_mask) {
-               DBG("DMA not supported\n");
-               ret = -EINVAL;
-               goto err1;
-       }
-
        if (!request_mem_region(addr->start, 2, hcd_name)) {
                ret = -EBUSY;
                goto err1;
index 28bf8bfb091e6bcd531982033d9f95e4e8641513..96f8daa11f2556260b22c5967b70eb40fa915aa4 100644 (file)
@@ -2645,11 +2645,6 @@ static int isp1362_probe(struct platform_device *pdev)
        if (pdev->num_resources < 3)
                return -ENODEV;
 
-       if (pdev->dev.dma_mask) {
-               DBG(1, "won't do DMA");
-               return -ENODEV;
-       }
-
        irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
        if (!irq_res)
                return -ENODEV;
index b457fdaff29746a0e70794b06308289290b2baf9..1eb8d17e19dbfa130ae358a5743730d5d3e5bd13 100644 (file)
@@ -1178,7 +1178,7 @@ static const struct hc_driver ohci_hc_driver = {
         * generic hardware linkage
        */
        .irq =                  ohci_irq,
-       .flags =                HCD_MEMORY | HCD_USB11,
+       .flags =                HCD_MEMORY | HCD_DMA | HCD_USB11,
 
        /*
        * basic lifecycle operations
index 76a9b40b08f1559719570914f13280ee99fc8e6b..45f7cceb6df31474a2a6e5c8e413cb23f8b9e4af 100644 (file)
@@ -50,7 +50,7 @@ static const struct hc_driver ohci_ppc_of_hc_driver = {
         * generic hardware linkage
         */
        .irq =                  ohci_irq,
-       .flags =                HCD_USB11 | HCD_MEMORY,
+       .flags =                HCD_USB11 | HCD_DMA | HCD_MEMORY,
 
        /*
         * basic lifecycle operations
index 395f9d3bc849f3d35cf0cd01cd2de43e38c5f6b3..f77cd6af0ccfc9335bab8d2379b05b6c390ae149 100644 (file)
@@ -46,7 +46,7 @@ static const struct hc_driver ps3_ohci_hc_driver = {
        .product_desc           = "PS3 OHCI Host Controller",
        .hcd_priv_size          = sizeof(struct ohci_hcd),
        .irq                    = ohci_irq,
-       .flags                  = HCD_MEMORY | HCD_USB11,
+       .flags                  = HCD_MEMORY | HCD_DMA | HCD_USB11,
        .reset                  = ps3_ohci_hc_reset,
        .start                  = ps3_ohci_hc_start,
        .stop                   = ohci_stop,
index ebec9a7699e34767ffbe1de5115c8226c475f92f..8e19a5eb5b629ae31356b985425dcdc84b0b1ea7 100644 (file)
@@ -84,7 +84,7 @@ static const struct hc_driver ohci_sa1111_hc_driver = {
         * generic hardware linkage
         */
        .irq =                  ohci_irq,
-       .flags =                HCD_USB11 | HCD_MEMORY,
+       .flags =                HCD_USB11 | HCD_DMA | HCD_MEMORY,
 
        /*
         * basic lifecycle operations
index c158cda9e4b9bc509d8e7fdf63fc6846fe8e07b9..0b2aea6e28d46bac785cceea52f7ffab3517d97f 100644 (file)
@@ -49,7 +49,7 @@ static const struct hc_driver ohci_sm501_hc_driver = {
         * generic hardware linkage
         */
        .irq =                  ohci_irq,
-       .flags =                HCD_USB11 | HCD_MEMORY,
+       .flags =                HCD_USB11 | HCD_DMA | HCD_MEMORY,
 
        /*
         * basic lifecycle operations
index fb6f5e9ae5c620e54aa85c2542339314f634d10e..221593d75556117ed51b3481411106125b5e5d4a 100644 (file)
@@ -156,7 +156,7 @@ static const struct hc_driver ohci_tmio_hc_driver = {
 
        /* generic hardware linkage */
        .irq =                  ohci_irq,
-       .flags =                HCD_USB11 | HCD_MEMORY,
+       .flags =                HCD_USB11 | HCD_DMA | HCD_MEMORY,
 
        /* basic lifecycle operations */
        .start =                ohci_tmio_start,
index 09cc19df798e440c4207b71033b2880d2c539c40..e67242e437edceb643e4f421b7b8d05d3587ae73 100644 (file)
@@ -3088,9 +3088,6 @@ static int oxu_reset(struct usb_hcd *hcd)
        INIT_LIST_HEAD(&oxu->urb_list);
        oxu->urb_len = 0;
 
-       /* FIMXE */
-       hcd->self.controller->dma_mask = NULL;
-
        if (oxu->is_otg) {
                oxu->caps = hcd->regs + OXU_OTG_CAP_OFFSET;
                oxu->regs = hcd->regs + OXU_OTG_CAP_OFFSET + \
index 42668aeca57c8a96a9a42fce95ceab4bd1b18bd4..0c03ac6b021379b1a076eed75360759aba28526c 100644 (file)
@@ -2411,12 +2411,6 @@ static int r8a66597_probe(struct platform_device *pdev)
        if (usb_disabled())
                return -ENODEV;
 
-       if (pdev->dev.dma_mask) {
-               ret = -EINVAL;
-               dev_err(&pdev->dev, "dma not supported\n");
-               goto clean_up;
-       }
-
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
                ret = -ENODEV;
index 5b061e59994899a2868718ece1aa133842b1d445..72a34a1eb6189c4ab0fa055e3d339ab297cab72e 100644 (file)
@@ -1632,12 +1632,6 @@ sl811h_probe(struct platform_device *dev)
        irq = ires->start;
        irqflags = ires->flags & IRQF_TRIGGER_MASK;
 
-       /* refuse to confuse usbcore */
-       if (dev->dev.dma_mask) {
-               dev_dbg(&dev->dev, "no we won't dma\n");
-               return -EINVAL;
-       }
-
        /* the chip may be wired for either kind of addressing */
        addr = platform_get_resource(dev, IORESOURCE_MEM, 0);
        data = platform_get_resource(dev, IORESOURCE_MEM, 1);
index 400c40bc43a6fb676c21249a4e84965a1b16e38e..4efee34f154fcb772b72856f34bd3df4f092c73b 100644 (file)
@@ -3077,8 +3077,6 @@ static int u132_probe(struct platform_device *pdev)
        retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
        if (retval)
                return retval;
-       if (pdev->dev.dma_mask)
-               return -EINVAL;
 
        hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, dev_name(&pdev->dev));
        if (!hcd) {
index 2103b1ed0f8ff132ce571ce11de68c53396d7d0d..0a201a73b196352d4cfdb34749aabc0ae918b915 100644 (file)
@@ -63,7 +63,7 @@ static const struct hc_driver uhci_grlib_hc_driver = {
 
        /* Generic hardware linkage */
        .irq =                  uhci_irq,
-       .flags =                HCD_MEMORY | HCD_USB11,
+       .flags =                HCD_MEMORY | HCD_DMA | HCD_USB11,
 
        /* Basic lifecycle operations */
        .reset =                uhci_grlib_init,
index 0dd944277c99b04f9575281641d1587d60bc7310..0fa3d72bae261a517e2f1bf45cf04c9e5086640b 100644 (file)
@@ -261,7 +261,7 @@ static const struct hc_driver uhci_driver = {
 
        /* Generic hardware linkage */
        .irq =                  uhci_irq,
-       .flags =                HCD_USB11,
+       .flags =                HCD_DMA | HCD_USB11,
 
        /* Basic lifecycle operations */
        .reset =                uhci_pci_init,
index 89700e26fb296bc97c478580d9e1418dd781e663..70dbd95c3f063a43db2035df59b152e66ea45984 100644 (file)
@@ -41,7 +41,7 @@ static const struct hc_driver uhci_platform_hc_driver = {
 
        /* Generic hardware linkage */
        .irq =                  uhci_irq,
-       .flags =                HCD_MEMORY | HCD_USB11,
+       .flags =                HCD_MEMORY | HCD_DMA | HCD_USB11,
 
        /* Basic lifecycle operations */
        .reset =                uhci_platform_init,
index 03d1e552769bf9d1a7471e8c17d36765eb0225f6..e315c0158e90a50e264179c1a5b89853b0c99b21 100644 (file)
@@ -5217,7 +5217,7 @@ static const struct hc_driver xhci_hc_driver = {
         * generic hardware linkage
         */
        .irq =                  xhci_irq,
-       .flags =                HCD_MEMORY | HCD_USB3 | HCD_SHARED,
+       .flags =                HCD_MEMORY | HCD_DMA | HCD_USB3 | HCD_SHARED,
 
        /*
         * basic lifecycle operations
index 55b94fd10331b1888d9a928fffe55c676233b2f8..fdeb4cf97cc56130922f65104be558760590d24a 100644 (file)
@@ -120,9 +120,6 @@ int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
            (!IS_ENABLED(CONFIG_USB_ISP1761_UDC) || udc_disabled))
                return -ENODEV;
 
-       /* prevent usb-core allocating DMA pages */
-       dev->dma_mask = NULL;
-
        isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL);
        if (!isp)
                return -ENOMEM;
index 241a00d7502729190590a4b9f899ebb0cb25c411..07cc82ff327c986b045e413f5f268a4663a2a8d4 100644 (file)
@@ -139,7 +139,6 @@ static int isp1761_pci_probe(struct pci_dev *dev,
 
        pci_set_master(dev);
 
-       dev->dev.dma_mask = NULL;
        ret = isp1760_register(&dev->resource[3], dev->irq, 0, &dev->dev,
                               devflags);
        if (ret < 0)
index eb308ec35c66207908ad5cdb0c5faf0ffabe09e4..5a44b70372d922576f98ccb2d41f891627d3e3f3 100644 (file)
@@ -2689,7 +2689,7 @@ static const struct hc_driver musb_hc_driver = {
        .description            = "musb-hcd",
        .product_desc           = "MUSB HDRC host driver",
        .hcd_priv_size          = sizeof(struct musb *),
-       .flags                  = HCD_USB2 | HCD_MEMORY,
+       .flags                  = HCD_USB2 | HCD_DMA | HCD_MEMORY,
 
        /* not using irq handler or reset hooks from usbcore, since
         * those must be shared with peripheral code for OTG configs
index ddd3be48f948472cb1c884f551ad13e858c53a01..ae54221011c3ad899b738dd8a94ef161104a0e32 100644 (file)
@@ -1283,7 +1283,7 @@ static const struct hc_driver usbhsh_driver = {
        /*
         * generic hardware linkage
         */
-       .flags =                HCD_USB2,
+       .flags =                HCD_DMA | HCD_USB2,
 
        .start =                usbhsh_host_start,
        .stop =                 usbhsh_host_stop,
index b548c530f988a43fd2d49b4c081e23fe2eafa816..e656e7b4b1e44cea5047477cf238c066559af92d 100644 (file)
@@ -426,7 +426,6 @@ struct usb_bus {
        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? */
        u8 uses_pio_for_control;        /*
                                         * Does the host controller use PIO
                                         * for control transfers?
index a20e7815d814cb1fd6f84c91730d8584f8381fe4..8d3869c7de854680ff840802faa6dd1edbd911cd 100644 (file)
@@ -256,6 +256,7 @@ struct hc_driver {
 
        int     flags;
 #define        HCD_MEMORY      0x0001          /* HC regs use memory (else I/O) */
+#define        HCD_DMA         0x0002          /* HC uses DMA */
 #define        HCD_SHARED      0x0004          /* Two (or more) usb_hcds share HW */
 #define        HCD_USB11       0x0010          /* USB 1.1 */
 #define        HCD_USB2        0x0020          /* USB 2.0 */
@@ -422,8 +423,10 @@ static inline bool hcd_periodic_completion_in_progress(struct usb_hcd *hcd,
        return hcd->high_prio_bh.completing_ep == ep;
 }
 
-#define hcd_uses_dma(hcd) \
-       (IS_ENABLED(CONFIG_HAS_DMA) && (hcd)->self.uses_dma)
+static inline bool hcd_uses_dma(struct usb_hcd *hcd)
+{
+       return IS_ENABLED(CONFIG_HAS_DMA) && (hcd->driver->flags & HCD_DMA);
+}
 
 extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);
 extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,