public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH V2 1/2] usb: dwc2: fix aligned buffer usage
@ 2015-03-08 17:08 Stephen Warren
  2015-03-08 17:08 ` [U-Boot] [PATCH V2 2/2] usb: dwc2: remove restriction on buffer length Stephen Warren
  2015-03-09 12:46 ` [U-Boot] [PATCH V2 1/2] usb: dwc2: fix aligned buffer usage Marek Vasut
  0 siblings, 2 replies; 4+ messages in thread
From: Stephen Warren @ 2015-03-08 17:08 UTC (permalink / raw)
  To: u-boot

The original aligned_buffer usage:
a) Uselessly copied data into the aligned buffer even for IN
   transactions. Fix this my making the copy conditional.
b) Always programmed the HW to transfer to/from the start of the aligned
   buffer. This worked fine for OUT transactions since the memcpy copied
   the OUT data to this location too. However, for large IN transactions,
   since the copy from the aligned buffer to the "client" buffer was
   deferred until after all chunks were transferred. it resulted in each
   chunk's transfer over-writing the data for the first transfer. Fix
   this by copying IN data as soon as it's received.

Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
---
v2: Move all memcpy()s back into the per-chunk loop; we can't rely on
maxpacket being a multiple of 8-bytes, so we need to copy each chunk to
the aligned_buffer not aligned_buffer+done; the HW requires 8-byte
alignment for the DMA buffer.

 drivers/usb/host/dwc2.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index 5a1c44a8fb75..05d21b7948f5 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -795,7 +795,9 @@ 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);
+		if (!in)
+			memcpy(aligned_buffer, (char *)buffer + done, len);
+
 		writel((uint32_t)aligned_buffer, &hc_regs->hcdma);
 
 		/* Set host channel enable after all other setup is complete. */
@@ -810,16 +812,16 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in,
 			break;
 		}
 
-		done += xfer_len;
 		if (in) {
-			done -= sub;
+			xfer_len -= sub;
+			memcpy(buffer + done, aligned_buffer, xfer_len);
 			if (sub)
 				stop_transfer = 1;
 		}
-	} while ((done < len) && !stop_transfer);
 
-	if (done && in)
-		memcpy(buffer, aligned_buffer, done);
+		done += xfer_len;
+
+	} while ((done < len) && !stop_transfer);
 
 	writel(0, &hc_regs->hcintmsk);
 	writel(0xFFFFFFFF, &hc_regs->hcint);
-- 
1.9.1

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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-08 17:08 [U-Boot] [PATCH V2 1/2] usb: dwc2: fix aligned buffer usage Stephen Warren
2015-03-08 17:08 ` [U-Boot] [PATCH V2 2/2] usb: dwc2: remove restriction on buffer length Stephen Warren
2015-03-09 12:46 ` [U-Boot] [PATCH V2 1/2] usb: dwc2: fix aligned buffer usage Marek Vasut
2015-03-09 16:33   ` Stephen Warren

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