All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Felipe Balbi <balbi@kernel.org>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Cc: John Youn <John.Youn@synopsys.com>
Subject: [2/3] usb: dwc3: gadget: Don't skip updating remaining data
Date: Mon, 30 Jul 2018 22:23:46 +0000	[thread overview]
Message-ID: <30102591E157244384E984126FC3CB4F544A2E4D@us01wembx1.internal.synopsys.com> (raw)

Hi Felipe,

On 7/29/2018 11:08 PM, Felipe Balbi wrote:
> Thinh Nguyen <Thinh.Nguyen@synopsys.com> writes:
>> DWC3 must check for the BUFSIZ and update the req->remaining
>> regardless of transfer alignment. Returning early from transfer OUT
>> unalignment will skip updating the req->remaining.
>>
>> Fixes: c6267a51639b ("usb: dwc3: gadget: align transfers to wMaxPacketSize")
>> Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
>> ---
>>  drivers/usb/dwc3/gadget.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
>> index 032ea7d709ba..a5b8387a37ba 100644
>> --- a/drivers/usb/dwc3/gadget.c
>> +++ b/drivers/usb/dwc3/gadget.c
>> @@ -2246,6 +2246,9 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep,
>>  	if (chain && (trb->ctrl & DWC3_TRB_CTRL_HWO))
>>  		trb->ctrl &= ~DWC3_TRB_CTRL_HWO;
>>  
>> +	count = trb->size & DWC3_TRB_SIZE_MASK;
>> +	req->remaining += count;
>> +
>>  	/*
>>  	 * If we're dealing with unaligned size OUT transfer, we will be left
>>  	 * with one TRB pending in the ring. We need to manually clear HWO bit
>> @@ -2256,9 +2259,6 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep,
>>  		return 1;
>>  	}
>>  
>> -	count = trb->size & DWC3_TRB_SIZE_MASK;
>> -	req->remaining += count;
>> -
> this shouldn't be necessary, actually. The remaining TRB which was added
> to fix alignment issues, is simply because DWC3 doesn't like OUT
> transfers whose size are not aligned to wMaxPacketSize. We *know* we
> have e.g. 511 bytes to receive from host, but dwc3 wants me to write
> 1024 bytes on the TRB (for superspeed), so I need to add this chained
> TRB for the remaining 513 bytes.
>
> I don't expect host to send us more than 511 bytes, if it does, the host
> is faulty and I don't want to operate on those bytes anyway.
>

Right. But that's not the issue here. I realized that I did not describe
the issue fully...

The issue here is the reporting of the actual number of bytes
transferred. For isoc OUT transfers, the last TRB of the Buffer
Descriptor will be retired with HWO = 0 (dwc_usb3 and dwc_usb31
programming guide 4.3.7). So, the check for unaligned && HWO will be
false and will not return early. As a result, req->remaining will still
be updated with the BUFSIZ count, and the remaining will be 513+ in your
example. The 'actual' bytes written calculation will be wrong (e.g 511 -
513 = -2).

We can't rely on the current check to determine whether it's the last
TRB. My current solution is to update req->remaining for all TRB
completions. However, we have to also update the 'actual' bytes
calculation for OUT transfers.

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

             reply	other threads:[~2018-07-30 22:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-30 22:23 Thinh Nguyen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-08-03  7:54 [2/3] usb: dwc3: gadget: Don't skip updating remaining data Felipe Balbi
2018-08-03  3:20 Thinh Nguyen
2018-08-02  7:43 Felipe Balbi
2018-08-02  7:28 Felipe Balbi
2018-08-02  1:54 Thinh Nguyen
2018-08-02  1:26 Thinh Nguyen
2018-08-01  8:29 Felipe Balbi
2018-08-01  6:48 Felipe Balbi
2018-08-01  6:36 Felipe Balbi
2018-07-31  6:55 Felipe Balbi
2018-07-30  6:05 Felipe Balbi
2018-07-28  1:52 Thinh Nguyen

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=30102591E157244384E984126FC3CB4F544A2E4D@us01wembx1.internal.synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=John.Youn@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=linux-usb@vger.kernel.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 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.