All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Andrey Konovalov <andreyknvl@google.com>
Cc: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	USB list <linux-usb@vger.kernel.org>,
	Dmitry Vyukov <dvyukov@google.com>
Subject: Re: Testing endpoint halt support for raw-gadget
Date: Tue, 28 Apr 2020 09:27:07 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.44L0.2004280920510.4958-100000@netrider.rowland.org> (raw)
In-Reply-To: <CAAeHK+z=z=e2pYQy3vtJO4rm+=Rb=av+4RidLCyp7Ae3shggqA@mail.gmail.com>

Better late than never...

On Tue, 28 Apr 2020, Andrey Konovalov wrote:

> On Tue, Apr 28, 2020 at 2:50 AM Andrey Konovalov <andreyknvl@google.com> wrote:
> >
> > On Mon, Apr 27, 2020 at 10:47 PM Andrey Konovalov <andreyknvl@google.com> wrote:
> > >
> > > On Mon, Apr 27, 2020 at 9:51 PM Andrey Konovalov <andreyknvl@google.com> wrote:

> > > > Another question, which actually seems to be a major problem.
> > > >
> > > > It looks like automatic endpoint selection based on required features
> > > > doesn't work in raw-gadget. The way it tries to do that is iterating
> > > > over the list of available endpoints and finding one that has the
> > > > right direction and transfer type. But it seems that the right way to
> > > > do that (like it's done in usb_ep_autoconfig()) is to also patch the
> > > > bEndpointAddress field of the endpoint descriptor.
> > > >
> > > > Currently with raw-gadget the endpoints are supposed to be enabled
> > > > after a set_configuration/set_interface request from the host, so it's
> > > > too late to patch the endpoint descriptor (the one that was sent to
> > > > the host during enumeration). I'm guessing that sending one endpoint
> > > > descriptor during enumeration and then using a different one (with
> > > > patched bEndpointAddress) to set ep->desc before doing usb_ep_enable()
> > > > won't work (as there's going to be mismatch in endpoint addresses
> > > > between the host and the UDC), right?

It certainly won't work.

> > > > I wonder what we can do about that. It seems that we actually need to
> > > > parse the descriptors and figure out the right endpoints before the
> > > > enumeration starts.

That's right.  In the case of raw-gadget, this would be done around the 
time the user tells the driver what the config descriptors are.

> > > Or maybe somehow expose all endpoints and their features (like
> > > GadgetFS) and let userspace put proper addresses into endpoint
> > > descriptors before enumeration starts.

And if the user messes up the assignment, his driver won't work.

> > I think this is the way to go, giving the userspace maximum control
> > over what's going on. Seems not too hard to implement too. The only
> > part that is not clear to me is how to figure out the endpoint address
> > that a particular UDC endpoint expects to have.
> >
> > Most of the time endpoints are named as something like "ep1in" or
> > "ep2out", and AFAIU the number in the endpoint name is the address.
> > However net2280 seems to have weird endpoint names "ep-a", "ep-b",
> > etc. Looking at usb_ep_autoconfig_ss(), those endpoints supposedly
> > have sequential addresses starting from 1 (for each in/out type). But
> > then in the GadgetFS example [1] e.g. "ep-a" corresponds to address 7,
> > which I don't understand. My guess is that this is done to handle both
> > dummy_udc and net2280 in a single if case, but I'm not sure.
> >
> > [1] http://www.linux-usb.org/gadget/usb.c
> 
> Oh, there's actually a comment that explains this [1] in dummy_hcd.c
> (exactly the place where one would look for it :). So "ep-a" and
> others are fully configurable and accept any endpoint address. OK, I
> think I've figured out what to do here, will send a patch.
> 
> [1] https://elixir.bootlin.com/linux/v5.7-rc3/source/drivers/usb/gadget/udc/dummy_hcd.c#L113

I know you want to provide maximum flexibility in terms of what the
user can do.  Still, there has to be some way for the kernel driver to
know what endpoints the user wants to expose and what their
characteristics should be.  You can't get this information just by
snooping Get-Descriptor responses because in theory the host doesn't
have to send any such requests.

Alan Stern


  reply	other threads:[~2020-04-28 13:27 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09 16:48 Testing endpoint halt support for raw-gadget Andrey Konovalov
2020-04-10  0:29 ` Alan Stern
2020-04-10 15:13   ` Andrey Konovalov
2020-04-10 15:53     ` Alan Stern
2020-04-27  1:26       ` Peter Chen
2020-04-27 14:29         ` Alan Stern
2020-04-29  2:20       ` Andrey Konovalov
2020-04-29 14:06         ` Alan Stern
2020-05-04 14:16           ` Andrey Konovalov
2020-05-04 14:24             ` Alan Stern
2020-05-04 15:11               ` Andrey Konovalov
2020-05-04 15:15                 ` Alan Stern
2020-05-05  6:34                   ` Felipe Balbi
2020-05-05 12:13                     ` Andrey Konovalov
2020-05-05 16:42                       ` Thinh Nguyen
2020-05-05  6:30               ` Felipe Balbi
2020-04-24 19:36   ` Andrey Konovalov
2020-04-24 19:56     ` Andrey Konovalov
2020-04-25  1:53       ` Alan Stern
2020-04-25 14:49         ` Andrey Konovalov
2020-04-25 15:02           ` Alan Stern
2020-04-27 19:51     ` Andrey Konovalov
2020-04-27 20:47       ` Andrey Konovalov
2020-04-28  0:50         ` Andrey Konovalov
2020-04-28  1:32           ` Andrey Konovalov
2020-04-28 13:27             ` Alan Stern [this message]
2020-05-13 17:07               ` Andrey Konovalov
2020-05-13 18:14                 ` Alan Stern
2020-05-13 18:31                   ` Andrey Konovalov
2020-05-13 19:09                     ` Alan Stern
2020-05-13 19:38                       ` Andrey Konovalov

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=Pine.LNX.4.44L0.2004280920510.4958-100000@netrider.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=andreyknvl@google.com \
    --cc=balbi@kernel.org \
    --cc=dvyukov@google.com \
    --cc=gregkh@linuxfoundation.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.