From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: ske@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 2/2] usb: gadget: fsl_udc: dma_map buffers instead of using dma_sync
Date: Wed, 24 Jul 2024 11:47:32 +0200 [thread overview]
Message-ID: <20240724094732.886245-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240724094732.886245-1-a.fatoum@pengutronix.de>
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@pengutronix.de>
---
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
next prev parent reply other threads:[~2024-07-24 9:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-24 9:47 [PATCH master 1/2] dma: debug: fix compiler warning about pointer u64 cast Ahmad Fatoum
2024-07-24 9:47 ` Ahmad Fatoum [this message]
2024-07-30 8:13 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240724094732.886245-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=ske@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox