Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: add a HCD_DMA flag instead of guestimating DMA capabilities

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>

authored by

Christoph Hellwig and committed by
Greg Kroah-Hartman
7b81cb6b 0709831a

+31 -62
+1 -1
drivers/staging/octeon-usb/octeon-hcd.c
··· 3512 3512 .product_desc = "Octeon Host Controller", 3513 3513 .hcd_priv_size = sizeof(struct octeon_hcd), 3514 3514 .irq = octeon_usb_irq, 3515 - .flags = HCD_MEMORY | HCD_USB2, 3515 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB2, 3516 3516 .start = octeon_usb_start, 3517 3517 .stop = octeon_usb_stop, 3518 3518 .urb_enqueue = octeon_usb_urb_enqueue,
-1
drivers/usb/core/hcd.c
··· 2454 2454 hcd->self.controller = dev; 2455 2455 hcd->self.sysdev = sysdev; 2456 2456 hcd->self.bus_name = bus_name; 2457 - hcd->self.uses_dma = (sysdev->dma_mask != NULL); 2458 2457 2459 2458 timer_setup(&hcd->rh_timer, rh_timer_func, 0); 2460 2459 #ifdef CONFIG_PM
+3 -3
drivers/usb/dwc2/hcd.c
··· 5062 5062 dwc2_hc_driver.reset_device = dwc2_reset_device; 5063 5063 } 5064 5064 5065 + if (hsotg->params.host_dma) 5066 + dwc2_hc_driver.flags |= HCD_DMA; 5067 + 5065 5068 hcd = usb_create_hcd(&dwc2_hc_driver, hsotg->dev, dev_name(hsotg->dev)); 5066 5069 if (!hcd) 5067 5070 goto error1; 5068 - 5069 - if (!hsotg->params.host_dma) 5070 - hcd->self.uses_dma = 0; 5071 5071 5072 5072 hcd->has_tt = 1; 5073 5073
+1 -1
drivers/usb/host/ehci-grlib.c
··· 30 30 * generic hardware linkage 31 31 */ 32 32 .irq = ehci_irq, 33 - .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, 33 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH, 34 34 35 35 /* 36 36 * basic lifecycle operations
+1 -1
drivers/usb/host/ehci-hcd.c
··· 1193 1193 * generic hardware linkage 1194 1194 */ 1195 1195 .irq = ehci_irq, 1196 - .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, 1196 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH, 1197 1197 1198 1198 /* 1199 1199 * basic lifecycle operations
+1 -1
drivers/usb/host/ehci-pmcmsp.c
··· 250 250 * generic hardware linkage 251 251 */ 252 252 .irq = ehci_irq, 253 - .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, 253 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH, 254 254 255 255 /* 256 256 * basic lifecycle operations
+1 -1
drivers/usb/host/ehci-ppc-of.c
··· 31 31 * generic hardware linkage 32 32 */ 33 33 .irq = ehci_irq, 34 - .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, 34 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH, 35 35 36 36 /* 37 37 * basic lifecycle operations
+1 -1
drivers/usb/host/ehci-ps3.c
··· 59 59 .product_desc = "PS3 EHCI Host Controller", 60 60 .hcd_priv_size = sizeof(struct ehci_hcd), 61 61 .irq = ehci_irq, 62 - .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, 62 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH, 63 63 .reset = ps3_ehci_hc_reset, 64 64 .start = ehci_run, 65 65 .stop = ehci_stop,
+1 -1
drivers/usb/host/ehci-sh.c
··· 33 33 * generic hardware linkage 34 34 */ 35 35 .irq = ehci_irq, 36 - .flags = HCD_USB2 | HCD_MEMORY | HCD_BH, 36 + .flags = HCD_USB2 | HCD_DMA | HCD_MEMORY | HCD_BH, 37 37 38 38 /* 39 39 * basic lifecycle operations
+1 -1
drivers/usb/host/ehci-xilinx-of.c
··· 66 66 * generic hardware linkage 67 67 */ 68 68 .irq = ehci_irq, 69 - .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, 69 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH, 70 70 71 71 /* 72 72 * basic lifecycle operations
+1 -1
drivers/usb/host/fhci-hcd.c
··· 538 538 539 539 /* generic hardware linkage */ 540 540 .irq = fhci_irq, 541 - .flags = HCD_USB11 | HCD_MEMORY, 541 + .flags = HCD_DMA | HCD_USB11 | HCD_MEMORY, 542 542 543 543 /* basic lifecycle operation */ 544 544 .start = fhci_start,
+1 -1
drivers/usb/host/fotg210-hcd.c
··· 5508 5508 * generic hardware linkage 5509 5509 */ 5510 5510 .irq = fotg210_irq, 5511 - .flags = HCD_MEMORY | HCD_USB2, 5511 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB2, 5512 5512 5513 5513 /* 5514 5514 * basic lifecycle operations
+1 -1
drivers/usb/host/imx21-hcd.c
··· 1771 1771 .product_desc = "IMX21 USB Host Controller", 1772 1772 .hcd_priv_size = sizeof(struct imx21), 1773 1773 1774 - .flags = HCD_USB11, 1774 + .flags = HCD_DMA | HCD_USB11, 1775 1775 .irq = imx21_irq, 1776 1776 1777 1777 .reset = imx21_hc_reset,
-6
drivers/usb/host/isp116x-hcd.c
··· 1581 1581 irq = ires->start; 1582 1582 irqflags = ires->flags & IRQF_TRIGGER_MASK; 1583 1583 1584 - if (pdev->dev.dma_mask) { 1585 - DBG("DMA not supported\n"); 1586 - ret = -EINVAL; 1587 - goto err1; 1588 - } 1589 - 1590 1584 if (!request_mem_region(addr->start, 2, hcd_name)) { 1591 1585 ret = -EBUSY; 1592 1586 goto err1;
-5
drivers/usb/host/isp1362-hcd.c
··· 2645 2645 if (pdev->num_resources < 3) 2646 2646 return -ENODEV; 2647 2647 2648 - if (pdev->dev.dma_mask) { 2649 - DBG(1, "won't do DMA"); 2650 - return -ENODEV; 2651 - } 2652 - 2653 2648 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 2654 2649 if (!irq_res) 2655 2650 return -ENODEV;
+1 -1
drivers/usb/host/ohci-hcd.c
··· 1178 1178 * generic hardware linkage 1179 1179 */ 1180 1180 .irq = ohci_irq, 1181 - .flags = HCD_MEMORY | HCD_USB11, 1181 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB11, 1182 1182 1183 1183 /* 1184 1184 * basic lifecycle operations
+1 -1
drivers/usb/host/ohci-ppc-of.c
··· 50 50 * generic hardware linkage 51 51 */ 52 52 .irq = ohci_irq, 53 - .flags = HCD_USB11 | HCD_MEMORY, 53 + .flags = HCD_USB11 | HCD_DMA | HCD_MEMORY, 54 54 55 55 /* 56 56 * basic lifecycle operations
+1 -1
drivers/usb/host/ohci-ps3.c
··· 46 46 .product_desc = "PS3 OHCI Host Controller", 47 47 .hcd_priv_size = sizeof(struct ohci_hcd), 48 48 .irq = ohci_irq, 49 - .flags = HCD_MEMORY | HCD_USB11, 49 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB11, 50 50 .reset = ps3_ohci_hc_reset, 51 51 .start = ps3_ohci_hc_start, 52 52 .stop = ohci_stop,
+1 -1
drivers/usb/host/ohci-sa1111.c
··· 84 84 * generic hardware linkage 85 85 */ 86 86 .irq = ohci_irq, 87 - .flags = HCD_USB11 | HCD_MEMORY, 87 + .flags = HCD_USB11 | HCD_DMA | HCD_MEMORY, 88 88 89 89 /* 90 90 * basic lifecycle operations
+1 -1
drivers/usb/host/ohci-sm501.c
··· 49 49 * generic hardware linkage 50 50 */ 51 51 .irq = ohci_irq, 52 - .flags = HCD_USB11 | HCD_MEMORY, 52 + .flags = HCD_USB11 | HCD_DMA | HCD_MEMORY, 53 53 54 54 /* 55 55 * basic lifecycle operations
+1 -1
drivers/usb/host/ohci-tmio.c
··· 156 156 157 157 /* generic hardware linkage */ 158 158 .irq = ohci_irq, 159 - .flags = HCD_USB11 | HCD_MEMORY, 159 + .flags = HCD_USB11 | HCD_DMA | HCD_MEMORY, 160 160 161 161 /* basic lifecycle operations */ 162 162 .start = ohci_tmio_start,
-3
drivers/usb/host/oxu210hp-hcd.c
··· 3088 3088 INIT_LIST_HEAD(&oxu->urb_list); 3089 3089 oxu->urb_len = 0; 3090 3090 3091 - /* FIMXE */ 3092 - hcd->self.controller->dma_mask = NULL; 3093 - 3094 3091 if (oxu->is_otg) { 3095 3092 oxu->caps = hcd->regs + OXU_OTG_CAP_OFFSET; 3096 3093 oxu->regs = hcd->regs + OXU_OTG_CAP_OFFSET + \
-6
drivers/usb/host/r8a66597-hcd.c
··· 2411 2411 if (usb_disabled()) 2412 2412 return -ENODEV; 2413 2413 2414 - if (pdev->dev.dma_mask) { 2415 - ret = -EINVAL; 2416 - dev_err(&pdev->dev, "dma not supported\n"); 2417 - goto clean_up; 2418 - } 2419 - 2420 2414 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2421 2415 if (!res) { 2422 2416 ret = -ENODEV;
-6
drivers/usb/host/sl811-hcd.c
··· 1632 1632 irq = ires->start; 1633 1633 irqflags = ires->flags & IRQF_TRIGGER_MASK; 1634 1634 1635 - /* refuse to confuse usbcore */ 1636 - if (dev->dev.dma_mask) { 1637 - dev_dbg(&dev->dev, "no we won't dma\n"); 1638 - return -EINVAL; 1639 - } 1640 - 1641 1635 /* the chip may be wired for either kind of addressing */ 1642 1636 addr = platform_get_resource(dev, IORESOURCE_MEM, 0); 1643 1637 data = platform_get_resource(dev, IORESOURCE_MEM, 1);
-2
drivers/usb/host/u132-hcd.c
··· 3077 3077 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a); 3078 3078 if (retval) 3079 3079 return retval; 3080 - if (pdev->dev.dma_mask) 3081 - return -EINVAL; 3082 3080 3083 3081 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, dev_name(&pdev->dev)); 3084 3082 if (!hcd) {
+1 -1
drivers/usb/host/uhci-grlib.c
··· 63 63 64 64 /* Generic hardware linkage */ 65 65 .irq = uhci_irq, 66 - .flags = HCD_MEMORY | HCD_USB11, 66 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB11, 67 67 68 68 /* Basic lifecycle operations */ 69 69 .reset = uhci_grlib_init,
+1 -1
drivers/usb/host/uhci-pci.c
··· 261 261 262 262 /* Generic hardware linkage */ 263 263 .irq = uhci_irq, 264 - .flags = HCD_USB11, 264 + .flags = HCD_DMA | HCD_USB11, 265 265 266 266 /* Basic lifecycle operations */ 267 267 .reset = uhci_pci_init,
+1 -1
drivers/usb/host/uhci-platform.c
··· 41 41 42 42 /* Generic hardware linkage */ 43 43 .irq = uhci_irq, 44 - .flags = HCD_MEMORY | HCD_USB11, 44 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB11, 45 45 46 46 /* Basic lifecycle operations */ 47 47 .reset = uhci_platform_init,
+1 -1
drivers/usb/host/xhci.c
··· 5217 5217 * generic hardware linkage 5218 5218 */ 5219 5219 .irq = xhci_irq, 5220 - .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED, 5220 + .flags = HCD_MEMORY | HCD_DMA | HCD_USB3 | HCD_SHARED, 5221 5221 5222 5222 /* 5223 5223 * basic lifecycle operations
-3
drivers/usb/isp1760/isp1760-core.c
··· 120 120 (!IS_ENABLED(CONFIG_USB_ISP1761_UDC) || udc_disabled)) 121 121 return -ENODEV; 122 122 123 - /* prevent usb-core allocating DMA pages */ 124 - dev->dma_mask = NULL; 125 - 126 123 isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL); 127 124 if (!isp) 128 125 return -ENOMEM;
-1
drivers/usb/isp1760/isp1760-if.c
··· 139 139 140 140 pci_set_master(dev); 141 141 142 - dev->dev.dma_mask = NULL; 143 142 ret = isp1760_register(&dev->resource[3], dev->irq, 0, &dev->dev, 144 143 devflags); 145 144 if (ret < 0)
+1 -1
drivers/usb/musb/musb_host.c
··· 2689 2689 .description = "musb-hcd", 2690 2690 .product_desc = "MUSB HDRC host driver", 2691 2691 .hcd_priv_size = sizeof(struct musb *), 2692 - .flags = HCD_USB2 | HCD_MEMORY, 2692 + .flags = HCD_USB2 | HCD_DMA | HCD_MEMORY, 2693 2693 2694 2694 /* not using irq handler or reset hooks from usbcore, since 2695 2695 * those must be shared with peripheral code for OTG configs
+1 -1
drivers/usb/renesas_usbhs/mod_host.c
··· 1283 1283 /* 1284 1284 * generic hardware linkage 1285 1285 */ 1286 - .flags = HCD_USB2, 1286 + .flags = HCD_DMA | HCD_USB2, 1287 1287 1288 1288 .start = usbhsh_host_start, 1289 1289 .stop = usbhsh_host_stop,
-1
include/linux/usb.h
··· 426 426 struct device *sysdev; /* as seen from firmware or bus */ 427 427 int busnum; /* Bus number (in order of reg) */ 428 428 const char *bus_name; /* stable id (PCI slot_name etc) */ 429 - u8 uses_dma; /* Does the host controller use DMA? */ 430 429 u8 uses_pio_for_control; /* 431 430 * Does the host controller use PIO 432 431 * for control transfers?
+5 -2
include/linux/usb/hcd.h
··· 256 256 257 257 int flags; 258 258 #define HCD_MEMORY 0x0001 /* HC regs use memory (else I/O) */ 259 + #define HCD_DMA 0x0002 /* HC uses DMA */ 259 260 #define HCD_SHARED 0x0004 /* Two (or more) usb_hcds share HW */ 260 261 #define HCD_USB11 0x0010 /* USB 1.1 */ 261 262 #define HCD_USB2 0x0020 /* USB 2.0 */ ··· 423 422 return hcd->high_prio_bh.completing_ep == ep; 424 423 } 425 424 426 - #define hcd_uses_dma(hcd) \ 427 - (IS_ENABLED(CONFIG_HAS_DMA) && (hcd)->self.uses_dma) 425 + static inline bool hcd_uses_dma(struct usb_hcd *hcd) 426 + { 427 + return IS_ENABLED(CONFIG_HAS_DMA) && (hcd->driver->flags & HCD_DMA); 428 + } 428 429 429 430 extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); 430 431 extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,