All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Avichal Rakesh <arakesh@google.com>,
	Greg KH <gregkh@linuxfoundation.org>,
	"dan.scally@ideasonboard.com" <dan.scally@ideasonboard.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	Jayant Chowdhary <jchowdhary@google.com>,
	"Eino-Ville Talvala (Eddy)" <etalvala@google.com>
Subject: Re: UVC Gadget Driver shows glitched frames with a Linux host
Date: Thu, 20 Apr 2023 20:05:46 +0300	[thread overview]
Message-ID: <20230420170546.GE21943@pendragon.ideasonboard.com> (raw)
In-Reply-To: <8c0da0fc-ac5d-42f4-9071-14fb78539f65@rowland.harvard.edu>

On Thu, Apr 20, 2023 at 10:31:24AM -0400, Alan Stern wrote:
> On Thu, Apr 20, 2023 at 02:31:25AM +0000, Thinh Nguyen wrote:
> > On Wed, Apr 19, 2023, Alan Stern wrote:
> > > On Wed, Apr 19, 2023 at 09:49:35PM +0000, Thinh Nguyen wrote:
> > > > By the usb spec, for IN direction, if there's no data available and the
> > > > host requests for data, then the device will send a zero-length data
> > > > packet.
> > > 
> > > I'm not aware of any such requirement in the USB-2 spec.  The closest I 
> > > can find is in section 5.6.4:
> > > 
> > > 	An isochronous IN endpoint must return a zero-length packet 
> > > 	whenever data is requested at a faster interval than the 
> > > 	specified interval and data is not available.
> > > 
> > > But this specifically refers only to situations where the host asks for 
> > > isochonous data more frequently than the endpoint descriptor's bInterval 
> > > describes.
> > 
> > This is from usb 3.2 section 4.4.8.2:
> > 
> > 	Note, if an endpoint has no isochronous data to transmit when
> > 	accessed by the host, it shall send a zero length packet in
> > 	response to the request for data.
> 
> Ah, but chapter 4 in the USB-3.2 spec describes only the SuperSpeed bus, 
> as mentioned in the first paragraph of section 4.1.  So the constraint 
> about sending 0-length isochronous packets when no data is available 
> applies only to SuperSpeed connections.  If a gadget is connected at 
> USB-2 speed, the constraint doesn't apply.
> 
> (And in fact, no matter what the connection speed is, there's always a 
> possibility that the first packet sent by the host to begin an 
> isochronous transfer might get lost or corrupted, in which case the 
> device would not send a reply in any case.)
> 
> > > >  This is what the dwc3 controller will do. So regardless whether
> > > > you prepare and queue a 0-length request or not, the host will receive
> > > > it.
> > > 
> > > Even so, whether the function driver submits these 0-length isochronous 
> > > requests makes a difference in terms of filling the slots in the 
> > > schedule and preventing later requests from becoming stale.
> > 
> > That's not my point. Avi concern was how the host may interpret 0-length
> > packet. My point was to note that it should behave the same as before.
> > Because even without sending 0-length requests, the controller would
> > already respond with 0-length packet already.
> 
> It would be good to confirm the reasoning by checking the source code 
> for the UVC host driver.  But I expect you are right.

The uvcvideo host driver should be fine. An isochronous frame descriptor
with actual_length set to 0 will cause the packet to be ignored. The
uvc_video_decode_isoc() function loops over all packets, and calls
uvc_video_decode_start() which starts with

	if (len < 2 || data[0] < 2 || data[0] > len) {
		stream->stats.frame.nb_invalid++;
		return -EINVAL;
	}

The -EINVAL return value causes the caller to ignore the packet.

We probably want to avoid increasing the counter of invalid packets
though, but the counter is used for debug purpose only, so it doesn't
affect operation negatively.

> > In fact, that's what the UVC driver should be doing, by maintaining the
> > request queue with dummy requests as suggested in the beginning.
> > 
> > Perhaps there was some misunderstanding. Sending 0-length request you
> > suggested is a perfectly good suggestion and UVC gadget driver should do
> > that instead of relying on the workaround in the dwc3 driver.
> 
> Agreed.

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2023-04-20 17:05 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-14 21:03 UVC Gadget Driver shows glitched frames with a Linux host Avichal Rakesh
2023-04-17 13:49 ` Greg KH
2023-04-18  1:34   ` Avichal Rakesh
2023-04-18  2:49     ` Thinh Nguyen
2023-04-18  6:56       ` Avichal Rakesh
2023-04-18 19:39         ` Thinh Nguyen
2023-04-18 22:45           ` Avichal Rakesh
2023-04-19  0:11             ` Thinh Nguyen
2023-04-19  0:19               ` Thinh Nguyen
2023-04-19  5:25                 ` Avichal Rakesh
2023-04-19 21:58                   ` Thinh Nguyen
2023-04-19 22:35                     ` Avichal Rakesh
2023-04-19  1:07             ` Alan Stern
2023-04-19  5:26               ` Avichal Rakesh
2023-04-19 21:49                 ` Thinh Nguyen
2023-04-19 22:26                   ` Avichal Rakesh
2023-04-19 22:38                     ` Thinh Nguyen
2023-04-19 23:12                       ` Avichal Rakesh
2023-04-20  1:20                   ` Alan Stern
2023-04-20  2:31                     ` Thinh Nguyen
2023-04-20 14:31                       ` Alan Stern
2023-04-20 17:05                         ` Laurent Pinchart [this message]
2023-04-20 20:22                         ` Thinh Nguyen
2023-04-20 17:20                 ` Laurent Pinchart
2023-05-05 22:39                   ` Avichal Rakesh
2023-05-05 22:41                     ` Avichal Rakesh
2023-05-05 23:58                       ` Thinh Nguyen
2023-05-06  2:49                     ` Thinh Nguyen
2023-05-06 12:53                     ` Laurent Pinchart
2023-05-08 23:49                       ` Avichal Rakesh
2023-05-09  0:21                         ` Thinh Nguyen
2023-05-09 18:33                           ` Avichal Rakesh
2023-05-09 22:35                             ` Thinh Nguyen
2023-05-09 22:42                               ` Thinh Nguyen
2023-05-16  0:29                                 ` Avichal Rakesh
2023-05-16  0:34                                   ` Avichal Rakesh
2023-05-17 23:36                                     ` Thinh Nguyen
2023-06-01  9:59                                       ` Dan Scally
2023-06-01 14:54                                   ` Dan Scally
2023-06-01 21:01                                     ` Avichal Rakesh

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=20230420170546.GE21943@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=arakesh@google.com \
    --cc=dan.scally@ideasonboard.com \
    --cc=etalvala@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jchowdhary@google.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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.