From bb6cd1d5aa80b373ebf183426d233d4c09692ed9 Mon Sep 17 00:00:00 2001 From: Wu Liang feng Date: Mon, 6 Jun 2016 11:30:35 +0800 Subject: [PATCH] usb: dwc3: gadget: fix OUT eps buffer size alignment issue Per dwc3 databook "Buffer Size Rules and Zero-Length Packets", dwc3 needs buffer size to be aligned to MaxPacketSize on ep out. Change-Id: Iff0e9c29c02c09b93bb34fed178051c02221ecc7 Signed-off-by: Wu Liang feng --- drivers/usb/dwc3/gadget.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 66cc37985b0b..e735b2a88a1a 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1010,6 +1010,17 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) trace_dwc3_ep_queue(req); + /* + * Per databook, the total size of buffer must be a multiple + * of MaxPacketSize for OUT endpoints. And MaxPacketSize is + * configed for endpoints in dwc3_gadget_set_ep_config(), + * set to usb_endpoint_descriptor->wMaxPacketSize. + */ + if (dep->direction == 0 && + req->request.length % dep->endpoint.desc->wMaxPacketSize) + req->request.length = roundup(req->request.length, + dep->endpoint.desc->wMaxPacketSize); + /* * We only add to our list of requests now and * start consuming the list once we get XferNotReady @@ -1156,7 +1167,7 @@ static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, * any other request. */ if (ret == 0 && request->zero && request->length && - (request->length % ep->maxpacket == 0)) + (request->length % ep->desc->wMaxPacketSize == 0)) ret = __dwc3_gadget_ep_queue_zlp(dwc, dep); spin_unlock_irqrestore(&dwc->lock, flags); -- 2.34.1