Re: Remote wake up in gadget drivers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jun 28, 2024 at 05:39:45PM +0200, Andrey Konovalov wrote:
> (syzkaller to bcc)
> 
> Hi Alan,
> 
> I hope you could you clarify some things wrt the remote wake up
> support in gadget drivers.
> 
> Please see the Darrion's message first:
> 
> On Fri, Jun 28, 2024 at 5:34 AM Darrion Ramos <darrionramos@xxxxxxxxx> wrote:
> >
> > Additionally, we have been looking into the raw_gadget and have 
> > noticed that the keyboard example (both a physical instance on a 
> > raspberry pi and the virtual instance) do not wakeup the host device 
> > from suspend.

I don't understand the second part.  With a virtual instance, the gadget 
is physically on the host.  So if the host is suspended, how can the 
gadget do anything at all, let alone wake up the host?

> >  It seems that the emulated device does not communicate 
> > to the host that it is a wakeup capable device. The 
> > /sys/bus/devices/.../power directory for the respective udc is 
> > missing the wakeup files that would enable this.

What you wrote here is not what you meant; there is no /sys/bus/devices/ 
path.  Did you mean /sys/bus/usb/devices/... on the host, or did you 
mean /sys/bus/platform/... (or whatever) on the RPi?

> >  From my research on 
> > this I only found that the usb_gadget struct for the device needs to 
> > have the wakeup_capable flag set for the host to recognize the 
> > device as a remote wakeup source. I have printed the value during 
> > the gadget_bind and it seems to be set so I am not sure what else 
> > could be causing the host to not have the device recognized for 
> > remote wakeup. If anybody has any ideas on what needs to be modified 
> > in the raw_gadget or any resources for looking into it more it would 
> > be greatly appreciated, thanks!

The /sys/bus/usb/devices/.../power/wakeup file on the host will 
generally reflect the setting of the USB_CONFIG_ATT_WAKEUP bit in the 
gadget's configuration descriptor bmAttributes byte.  The code that 
sets wakeup_capable is in drivers/usb/core/hub.c, in the 
usb_set_device_state() function.  You can see that it uses the 
USB_CONFIG_ATT_WAKEUP bit.

> I assume that to take advantage of remote wake up, the device needs to
> first of all set the USB_DEVICE_REMOTE_WAKEUP bit in bmAttributes.

That bit gets set when the host tells the gadget to enable remote 
wakeup.  And generally the UDC driver handles this, not the gadget 
driver.

> But then, is the wake up supposed to be initiated through the gadget
> driver or through the UDC sysfs files as the ones that Darrion
> mentioned?

The wakeup request is initiated by the gadget driver calling 
usb_gadget_wakeup().

> For the former case, I assume that adding a new ioctl to Raw Gadget
> that calls usb_gadget_wakeup() would be a way to support this?

Yes.

> AFAICS, only the g_zero gadget driver calls usb_gadget_wakeup(). Do
> the other gadget drivers just have no support for remote wake up?

Grep shows that function/u_ether.c also calls usb_gadget_wakeup().  I 
don't know about most of the gadget drivers.  The f_mass_storage driver 
has no need for remote wakeup, for example, and the same is probably 
true for a lot of the others.  You'd think that the f_hid function would 
support remote wakeup, but maybe nobody ever implemented it.

Alan Stern




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux