[PATCH V2] usb: dwc3: Handle pending control data out correctly

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

 



If transfer not ready is received before ep queue is called for control
out transfer then pending flag is set. Handling of this case was not
correct.
TRB size must be max packet for all control out transfer.
dma sync function should also be called before start transfer.

Signed-off-by: Pratyush Anand <pratyush.anand@xxxxxx>
---
 drivers/usb/dwc3/ep0.c |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index c6c9b8a..ed1f728 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -142,6 +142,8 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,
 	 */
 	if (dep->flags & DWC3_EP_PENDING_REQUEST) {
 		unsigned	direction;
+		unsigned	transfer_size;
+		dma_addr_t	dma_addr;
 
 		direction = !!(dep->flags & DWC3_EP0_DIR_IN);
 
@@ -150,9 +152,35 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,
 			return 0;
 		}
 
+		transfer_size = req->request.length;
+
+		if (!direction && !IS_ALIGNED((u32)transfer_size,
+					dep->endpoint.maxpacket)) {
+			/*
+			 * REVISIT in case request length is bigger than EP0
+			 * wMaxPacketSize, we will need two chained TRBs to
+			 * handle the transfer.
+			 */
+			WARN_ON(transfer_size > dep->endpoint.maxpacket);
+
+			dwc->ep0_bounced = true;
+			transfer_size = roundup(transfer_size,
+					(u32)dep->endpoint.maxpacket);
+			dma_addr = dwc->ep0_bounce_addr;
+		} else {
+			dma_addr = req->request.dma;
+		}
+
+		ret = usb_gadget_map_request(&dwc->gadget, &req->request,
+				direction);
+		if (ret) {
+				dev_dbg(dwc->dev, "failed to map request\n");
+				return ret;
+		}
+
 		ret = dwc3_ep0_start_trans(dwc, direction,
-				req->request.dma, req->request.length,
-				DWC3_TRBCTL_CONTROL_DATA);
+					dma_addr, transfer_size,
+					DWC3_TRBCTL_CONTROL_DATA);
 		dep->flags &= ~(DWC3_EP_PENDING_REQUEST |
 				DWC3_EP0_DIR_IN);
 	} else if (dwc->delayed_status) {
-- 
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux