public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] usb: dwc2: fix aligned buffer usage
@ 2015-03-08  6:09 Stephen Warren
  2015-03-08  6:16 ` Stephen Warren
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Warren @ 2015-03-08  6:09 UTC (permalink / raw)
  To: u-boot

The original aligned_buffer usage:
a) Uselessly copied data into the aligned buffer even for IN
   transactions.
b) Needlessly split the memcpy() into separate calls per chunk, rather
   than doing it all at once, as it did for the post-transfer copy for
   IN transactions.
c) Always programmed the HW to transfer to/from the start of the aligned
   buffer, rather than the location of the start of the current chunk.
   This worked fine for OUT transactions since the memcpy copied the data
   to this location. However, for large IN transactions, it resulted in
   each transfer over-writing the data for the first transfer.

This patch assumes that the USB maxpacket is at least 8, so that each
chunk of the overall transfer is still aligned to the HW's 8-byte
alignment requirement.

Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
---
 drivers/usb/host/dwc2.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index 5a1c44a8fb75..5bb9df86735f 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -764,6 +764,9 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in,
 		return -EINVAL;
 	}
 
+	if (!in)
+		memcpy(aligned_buffer, (char *)buffer, len);
+
 	do {
 		/* Initialize channel */
 		dwc_otg_hc_init(regs, DWC2_HC_CHANNEL, devnum, ep, in, eptype,
@@ -795,8 +798,7 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in,
 		       (*pid << DWC2_HCTSIZ_PID_OFFSET),
 		       &hc_regs->hctsiz);
 
-		memcpy(aligned_buffer, (char *)buffer + done, len - done);
-		writel((uint32_t)aligned_buffer, &hc_regs->hcdma);
+		writel((uint32_t)&aligned_buffer[done], &hc_regs->hcdma);
 
 		/* Set host channel enable after all other setup is complete. */
 		clrsetbits_le32(&hc_regs->hcchar, DWC2_HCCHAR_MULTICNT_MASK |
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] usb: dwc2: fix aligned buffer usage
  2015-03-08  6:09 [U-Boot] [PATCH] usb: dwc2: fix aligned buffer usage Stephen Warren
@ 2015-03-08  6:16 ` Stephen Warren
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Warren @ 2015-03-08  6:16 UTC (permalink / raw)
  To: u-boot

On 03/07/2015 11:09 PM, Stephen Warren wrote:
> The original aligned_buffer usage:
> a) Uselessly copied data into the aligned buffer even for IN
>    transactions.
> b) Needlessly split the memcpy() into separate calls per chunk, rather
>    than doing it all at once, as it did for the post-transfer copy for
>    IN transactions.
> c) Always programmed the HW to transfer to/from the start of the aligned
>    buffer, rather than the location of the start of the current chunk.
>    This worked fine for OUT transactions since the memcpy copied the data
>    to this location. However, for large IN transactions, it resulted in
>    each transfer over-writing the data for the first transfer.
> 
> This patch assumes that the USB maxpacket is at least 8, so that each
> chunk of the overall transfer is still aligned to the HW's 8-byte
> alignment requirement.

Hmm. Further investigation shows the maxpacket isn't restricted to nice
aligned values. For some reason I thought it was. I'll need to adjust
this patch. Time for sleep!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-08  6:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-08  6:09 [U-Boot] [PATCH] usb: dwc2: fix aligned buffer usage Stephen Warren
2015-03-08  6:16 ` Stephen Warren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox