The USB buffer allocation code is the only place in the usb core (and in fact the whole kernel) that uses is_device_dma_capable, while the URB mapping code uses the uses_dma flag in struct usb_bus. Switch the buffer allocation to use the uses_dma flag used by the rest of the USB code, and create a helper in hcd.h that checks this flag as well as the CONFIG_HAS_DMA to simplify the caller a bit.
Unified · Split
| @@ -66,9 +66,7 @@ int hcd_buffer_create(struct usb_hcd *hcd) · 65 unmodified lines | |||
| 66 | char name[16]; | 66 | char name[16]; |
| 67 | int i, size; | 67 | int i, size; |
| 68 | 68 | ||
| 69 | if (hcd->localmem_pool || | 69 | if (hcd->localmem_pool || !hcd_uses_dma(hcd)) |
| 70 | !IS_ENABLED(CONFIG_HAS_DMA) || | ||
| 71 | !is_device_dma_capable(hcd->self.sysdev)) | ||
| 72 | return 0; | 70 | return 0; |
| 73 | 71 | ||
| 74 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { | 72 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { |
| @@ -129,8 +127,7 @@ void *hcd_buffer_alloc( · 54 unmodified lines | |||
| 129 | return gen_pool_dma_alloc(hcd->localmem_pool, size, dma); | 127 | return gen_pool_dma_alloc(hcd->localmem_pool, size, dma); |
| 130 | 128 | ||
| 131 | /* some USB hosts just use PIO */ | 129 | /* some USB hosts just use PIO */ |
| 132 | if (!IS_ENABLED(CONFIG_HAS_DMA) || | 130 | if (!hcd_uses_dma(hcd)) { |
| 133 | !is_device_dma_capable(bus->sysdev)) { | ||
| 134 | *dma = ~(dma_addr_t) 0; | 131 | *dma = ~(dma_addr_t) 0; |
| 135 | return kmalloc(size, mem_flags); | 132 | return kmalloc(size, mem_flags); |
| 136 | } | 133 | } |
| @@ -160,8 +157,7 @@ void hcd_buffer_free( · 23 unmodified lines | |||
| 160 | return; | 157 | return; |
| 161 | } | 158 | } |
| 162 | 159 | ||
| 163 | if (!IS_ENABLED(CONFIG_HAS_DMA) || | 160 | if (!hcd_uses_dma(hcd)) { |
| 164 | !is_device_dma_capable(bus->sysdev)) { | ||
| 165 | kfree(addr); | 161 | kfree(addr); |
| 166 | return; | 162 | return; |
| 167 | } | 163 | } |
| @@ -1412,7 +1412,7 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, · 1411 unmodified lines | |||
| 1412 | if (usb_endpoint_xfer_control(&urb->ep->desc)) { | 1412 | if (usb_endpoint_xfer_control(&urb->ep->desc)) { |
| 1413 | if (hcd->self.uses_pio_for_control) | 1413 | if (hcd->self.uses_pio_for_control) |
| 1414 | return ret; | 1414 | return ret; |
| 1415 | if (IS_ENABLED(CONFIG_HAS_DMA) && hcd->self.uses_dma) { | 1415 | if (hcd_uses_dma(hcd)) { |
| 1416 | if (is_vmalloc_addr(urb->setup_packet)) { | 1416 | if (is_vmalloc_addr(urb->setup_packet)) { |
| 1417 | WARN_ONCE(1, "setup packet is not dma capable\n"); | 1417 | WARN_ONCE(1, "setup packet is not dma capable\n"); |
| 1418 | return -EAGAIN; | 1418 | return -EAGAIN; |
| @@ -1446,7 +1446,7 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, · 27 unmodified lines | |||
| 1446 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; | 1446 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; |
| 1447 | if (urb->transfer_buffer_length != 0 | 1447 | if (urb->transfer_buffer_length != 0 |
| 1448 | && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { | 1448 | && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { |
| 1449 | if (IS_ENABLED(CONFIG_HAS_DMA) && hcd->self.uses_dma) { | 1449 | if (hcd_uses_dma(hcd)) { |
| 1450 | if (urb->num_sgs) { | 1450 | if (urb->num_sgs) { |
| 1451 | int n; | 1451 | int n; |
| 1452 | 1452 | ||
| @@ -4608,7 +4608,7 @@ static int _dwc2_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, · 4607 unmodified lines | |||
| 4608 | 4608 | ||
| 4609 | buf = urb->transfer_buffer; | 4609 | buf = urb->transfer_buffer; |
| 4610 | 4610 | ||
| 4611 | if (hcd->self.uses_dma) { | 4611 | if (hcd_uses_dma(hcd)) { |
| 4612 | if (!buf && (urb->transfer_dma & 3)) { | 4612 | if (!buf && (urb->transfer_dma & 3)) { |
| 4613 | dev_err(hsotg->dev, | 4613 | dev_err(hsotg->dev, |
| 4614 | "%s: unaligned transfer with no transfer_buffer", | 4614 | "%s: unaligned transfer with no transfer_buffer", |
| @@ -1457,7 +1457,7 @@ typedef void (*usb_complete_t)(struct urb *); · 1456 unmodified lines | |||
| 1457 | * field rather than determining a dma address themselves. | 1457 | * field rather than determining a dma address themselves. |
| 1458 | * | 1458 | * |
| 1459 | * Note that transfer_buffer must still be set if the controller | 1459 | * Note that transfer_buffer must still be set if the controller |
| 1460 | * does not support DMA (as indicated by bus.uses_dma) and when talking | 1460 | * does not support DMA (as indicated by hcd_uses_dma()) and when talking |
| 1461 | * to root hub. If you have to trasfer between highmem zone and the device | 1461 | * to root hub. If you have to trasfer between highmem zone and the device |
| 1462 | * on such controller, create a bounce buffer or bail out with an error. | 1462 | * on such controller, create a bounce buffer or bail out with an error. |
| 1463 | * If transfer_buffer cannot be set (is in highmem) and the controller is DMA | 1463 | * If transfer_buffer cannot be set (is in highmem) and the controller is DMA |
| @@ -422,6 +422,9 @@ static inline bool hcd_periodic_completion_in_progress(struct usb_hcd *hcd, · 421 unmodified lines | |||
| 422 | return hcd->high_prio_bh.completing_ep == ep; | 422 | return hcd->high_prio_bh.completing_ep == ep; |
| 423 | } | 423 | } |
| 424 | 424 | ||
| 425 | #define hcd_uses_dma(hcd) \ | ||
| 426 | (IS_ENABLED(CONFIG_HAS_DMA) && (hcd)->self.uses_dma) | ||
| 427 | |||
| 425 | extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); | 428 | extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); |
| 426 | extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, | 429 | extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, |
| 427 | int status); | 430 | int status); |