mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
To: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: barebox@lists.infradead.org
Subject: [PATCH v2] USB: xHCI: Sync non-coherent DMA buffers
Date: Mon, 13 Apr 2015 16:22:30 +0200	[thread overview]
Message-ID: <1428934950-6836-1-git-send-email-sebastian.hesselbarth@gmail.com> (raw)
In-Reply-To: <1428627714-17077-5-git-send-email-sebastian.hesselbarth@gmail.com>

When working with non-coherent transfer buffers, we have to sync
device and cpu for outgoing and incoming buffers. Fix the driver where
non-coherent buffers are used in device context.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Changelog:
v1->v2:
- balance dma_sync_single_foo() calls (Reported by Lucas Stach)

Cc: barebox@lists.infradead.org
Cc: Lucas Stach <dev@lynxeye.de>
---
 drivers/usb/host/xhci-hcd.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-hcd.c b/drivers/usb/host/xhci-hcd.c
index c3d623e91f51..a44a1a4dffa5 100644
--- a/drivers/usb/host/xhci-hcd.c
+++ b/drivers/usb/host/xhci-hcd.c
@@ -1024,6 +1024,11 @@ static int xhci_submit_normal(struct usb_device *udev, unsigned long pipe,
 		GET_SLOT_STATE(le32_to_cpu(vdev->out_ctx->slot.dev_state)), epi,
 		vdev->in_ctx, vdev->out_ctx);
 
+	/* pass ownership of data buffer to device */
+	dma_sync_single_for_device((unsigned long)buffer, length,
+				   usb_pipein(pipe) ?
+				   DMA_FROM_DEVICE : DMA_TO_DEVICE);
+
 	/* Normal TRB */
 	memset(&trb, 0, sizeof(union xhci_trb));
 	trb.event_cmd.cmd_trb = cpu_to_le64((dma_addr_t)buffer);
@@ -1037,6 +1042,11 @@ static int xhci_submit_normal(struct usb_device *udev, unsigned long pipe,
 	ret = xhci_wait_for_event(xhci, TRB_TRANSFER, &trb);
 	xhci_print_trb(xhci, &trb, "Response Normal");
 
+	/* Regain ownership of data buffer from device */
+	dma_sync_single_for_cpu((unsigned long)buffer, length,
+				usb_pipein(pipe) ?
+				DMA_FROM_DEVICE : DMA_TO_DEVICE);
+
 	switch (ret) {
 	case -COMP_SHORT_TX:
 		udev->status = 0;
@@ -1094,6 +1104,11 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe,
 			return ret;
 	}
 
+	/* Pass ownership of data buffer to device */
+	dma_sync_single_for_device((unsigned long)buffer, length,
+				   (req->requesttype & USB_DIR_IN) ?
+				   DMA_FROM_DEVICE : DMA_TO_DEVICE);
+
 	/* Setup TRB */
 	memset(&trb, 0, sizeof(union xhci_trb));
 	trb.generic.field[0] = le16_to_cpu(req->value) << 16 |
@@ -1141,11 +1156,17 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe,
 		if (ret == -COMP_SHORT_TX)
 			length -= EVENT_TRB_LEN(trb.event_cmd.status);
 		else if (ret < 0)
-			return ret;
+			goto dma_regain;
 	}
 
 	ret = xhci_wait_for_event(xhci, TRB_TRANSFER, &trb);
 	xhci_print_trb(xhci, &trb, "Response Status");
+
+dma_regain:
+	/* Regain ownership of data buffer from device */
+	dma_sync_single_for_cpu((unsigned long)buffer, length,
+				(req->requesttype & USB_DIR_IN) ?
+				DMA_FROM_DEVICE : DMA_TO_DEVICE);
 	if (ret < 0)
 		return ret;
 
-- 
2.1.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2015-04-13 14:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-10  1:01 [PATCH 0/4] Some fixes for PCI, mvneta, xHCI Sebastian Hesselbarth
2015-04-10  1:01 ` [PATCH 1/4] pci: fix device registration for directly attached devices Sebastian Hesselbarth
2015-04-10  7:15   ` Lucas Stach
2015-04-10  8:24     ` Sebastian Hesselbarth
2015-04-10  1:01 ` [PATCH 2/4] net: mvneta: Fix transmit errors due to dirty txdesc Sebastian Hesselbarth
2015-04-13  6:43   ` Sascha Hauer
2015-04-10  1:01 ` [PATCH 3/4] net: mvneta: Remove unnecessary DMA ops Sebastian Hesselbarth
2015-04-10  7:23   ` Lucas Stach
2015-04-10  8:18     ` Sebastian Hesselbarth
2015-04-10 16:09       ` Jan Lübbe
2015-04-10  1:01 ` [PATCH 4/4] USB: xHCI: Sync non-coherent DMA buffers Sebastian Hesselbarth
2015-04-10  7:25   ` Lucas Stach
2015-04-13 14:22   ` Sebastian Hesselbarth [this message]
2015-04-14 18:52     ` [PATCH v2] " Sascha Hauer
2015-04-14 19:29       ` Sebastian Hesselbarth
2015-04-15  9:11         ` Lucas Stach
2015-04-15  9:10     ` Lucas Stach
2015-04-15 12:06     ` 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=1428934950-6836-1-git-send-email-sebastian.hesselbarth@gmail.com \
    --to=sebastian.hesselbarth@gmail.com \
    --cc=barebox@lists.infradead.org \
    /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