[PATCH master 2/2] usb: gadget: fsl_udc: dma_map buffers instead of using dma_sync

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



CONFIG_DMA_API_DEBUG depends on DMA buffers being mapped with
dma_map_single before ownership is switched with dma_sync_single.

As this is currently not done, CONFIG_DMA_API_DEBUG reports a lot of
false positives when the driver is enabled. Fix it by using
usb_gadget_map_request which internally calls dma_map_single.

This fixes the false positives, aligns us with what the Linux driver
is doing and reduces overhead when unmapping the buffer for an IN
target endpoint:

Previously with DMA_BIDIRECTIONAL, we always invalidated buffers
when taking back ownership for the CPU. This is unnecessary when
unmapping a buffer for an IN endpoint as the direction is DMA_TO_DEVICE
and we won't be reading back the result.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 drivers/usb/gadget/udc/fsl_udc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/udc/fsl_udc.c b/drivers/usb/gadget/udc/fsl_udc.c
index 41de44b30d12..e1d0d0b48272 100644
--- a/drivers/usb/gadget/udc/fsl_udc.c
+++ b/drivers/usb/gadget/udc/fsl_udc.c
@@ -197,8 +197,7 @@ static void done(struct fsl_ep *ep, struct fsl_req *req, int status)
 		dma_free_coherent(curr_td, 0, sizeof(struct ep_td_struct));
 	}
 
-	dma_sync_single_for_cpu(udc->gadget.dev.parent, (unsigned long)req->req.buf,
-				req->req.length, DMA_BIDIRECTIONAL);
+	usb_gadget_unmap_request(&udc->gadget, &req->req, ep_is_in(ep));
 
 	if (status && (status != -ESHUTDOWN))
 		VDBG("complete %s req %p stat %d len %u/%u",
@@ -861,7 +860,7 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req)
 	struct fsl_ep *ep = container_of(_ep, struct fsl_ep, ep);
 	struct fsl_req *req = container_of(_req, struct fsl_req, req);
 	struct fsl_udc *udc;
-	int is_iso = 0;
+	int ret, is_iso = 0;
 
 	/* catch various bogus parameters */
 	if (!_req || !req->req.complete || !req->req.buf
@@ -885,8 +884,9 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req)
 
 	req->ep = ep;
 
-	dma_sync_single_for_device(udc->gadget.dev.parent, (unsigned long)req->req.buf,
-				   req->req.length, DMA_BIDIRECTIONAL);
+	ret = usb_gadget_map_request(&ep->udc->gadget, &req->req, ep_is_in(ep));
+	if (ret)
+		return ret;
 
 	req->req.status = -EINPROGRESS;
 	req->req.actual = 0;
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux