Skip to contentSkip to conversation

usb: dwc3: gadget: Return correct actual bytes written

PATCH New Felipe Balbi 1 participant 1 message Jul 30, 2018 USB

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 usb: dwc3: gadget: Return correct actual bytes written

Hi,

Quoted 3 lines · Thinh Nguyen

For OUT transfers, the total size (total TRB buffer allocation) must be a multiple of MaxPacketSize even if software is expecting a fixed non-multiple of MaxPacketSize transfer from the host.

this is the same for dwc3.0 and we already account for that.

Quoted 25 lines

(DWC_usb31 programming guide section 4.2.5)

So, to calculate the actual bytes written (OUT transfer), do:
actual = round_up(expected_length, MaxPacketSize) - remaining_length

Fixes e62c5bc57367 ("usb: dwc3: gadget: tracking per-TRB remaining bytes")
---
 drivers/usb/dwc3/gadget.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/usb/dwc3/gadget.c +2 -0
index a5b8387a37ba..9859ca9dff9a 100644
@@ -2319,6 +2319,8 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
 		const struct dwc3_event_depevt *event,
 		struct dwc3_request *req, int status)
 {
+	unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc);
+	unsigned int length = req->request.length;
 	int ret;
 
 	if (req->num_pending_sgs)

drivers/usb/dwc3/gadget.c static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, · line 2340

Quoted 5 lines
drivers/usb/dwc3/gadget.c +1 -1
@@ -2335,7 +2337,10 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
 		req->zero = false;
 	}
 
-	req->request.actual = req->request.length - req->remaining;
+	if (usb_endpoint_dir_out(dep->endpoint.desc))

dep->direction

drivers/usb/dwc3/gadget.c static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, · line 2343

Quoted 3 lines
drivers/usb/dwc3/gadget.c +3 -0
+		req->request.actual = round_up(length, maxp) - req->remaining;
+	else
+		req->request.actual = length - req->remaining;

this is completely unnecessary. What actual problem are you facing? Care to share some tracepoint data exposing the issue? How do you reproduce it? We added the chained TRB at the end to make dwc3 happy, why isn't that working for dwc31?