All of lore.kernel.org
 help / color / mirror / Atom feed
* [3/3] usb: dwc3: gadget: Return correct actual bytes written
@ 2018-07-30  6:07 Felipe Balbi
  0 siblings, 0 replies; 2+ messages in thread
From: Felipe Balbi @ 2018-07-30  6:07 UTC (permalink / raw)
  To: Thinh Nguyen, linux-usb; +Cc: John Youn

Hi,

Thinh Nguyen <Thinh.Nguyen@synopsys.com> writes:
> 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.

> (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")
> Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
> ---
>  drivers/usb/dwc3/gadget.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index a5b8387a37ba..9859ca9dff9a 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -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)
> @@ -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

> +		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?

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

* [3/3] usb: dwc3: gadget: Return correct actual bytes written
@ 2018-07-28  1:52 Thinh Nguyen
  0 siblings, 0 replies; 2+ messages in thread
From: Thinh Nguyen @ 2018-07-28  1:52 UTC (permalink / raw)
  To: Felipe Balbi, linux-usb; +Cc: John Youn

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.

(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")
Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
---
 drivers/usb/dwc3/gadget.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index a5b8387a37ba..9859ca9dff9a 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -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)
@@ -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))
+		req->request.actual = round_up(length, maxp) - req->remaining;
+	else
+		req->request.actual = length - req->remaining;
 
 	if (!dwc3_gadget_ep_request_completed(req) &&
 			req->num_pending_sgs) {

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

end of thread, other threads:[~2018-07-30  6:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-30  6:07 [3/3] usb: dwc3: gadget: Return correct actual bytes written Felipe Balbi
  -- strict thread matches above, loose matches on Subject: below --
2018-07-28  1:52 Thinh Nguyen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.