All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: gadget/legacy/ether: assume saner default power mode
@ 2021-09-16 14:56 Andreas Bauer
  2021-09-16 15:36 ` Greg KH
  2021-09-17  5:28 ` Felipe Balbi
  0 siblings, 2 replies; 6+ messages in thread
From: Andreas Bauer @ 2021-09-16 14:56 UTC (permalink / raw)
  To: linux-usb


I propose the included patch to the OTG USB ethernet gadget code:

  Report default of bus powered and 500mA bMaxPower consumption.

Reason:

  The USB spec requires all devices consuming more than 100mA from
  the bus to report in this manner. Devices such as Rpi Zero can operate
  in this mode and will then falsly report being self-powered when they
  are not.

  The more sane default is to report being 500mA bus-powered than being
  self-powered

This patch was born from an issue within the Raspberry Pi Zero ecosystem,
therefore I would invite comment regarding other usage of this OTG code.

Best regards,

Andreas

$ diff -u linux-5.14.2/drivers/usb/gadget/legacy/ether.c.orig linux-5.14.2/drivers/usb/gadget/legacy/ether.c
--- linux-5.14.2/drivers/usb/gadget/legacy/ether.c.orig	2021-09-08 13:52:41.000000000 +0700
+++ linux-5.14.2/drivers/usb/gadget/legacy/ether.c	2021-09-16 21:25:06.782958554 +0700
@@ -296,7 +296,8 @@
 	/* .label = f(hardware) */
 	.bConfigurationValue	= 1,
 	/* .iConfiguration = DYNAMIC */
-	.bmAttributes		= USB_CONFIG_ATT_SELFPOWER,
+	.bmAttributes		= 0,   /* bus powered implied */
+	.bMaxPower		= 250, /* 500mA in 2mA units */
 };
 
 /*-------------------------------------------------------------------------*/

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

* Re: [PATCH] usb: gadget/legacy/ether: assume saner default power mode
  2021-09-16 14:56 [PATCH] usb: gadget/legacy/ether: assume saner default power mode Andreas Bauer
@ 2021-09-16 15:36 ` Greg KH
  2021-09-17  5:28 ` Felipe Balbi
  1 sibling, 0 replies; 6+ messages in thread
From: Greg KH @ 2021-09-16 15:36 UTC (permalink / raw)
  To: Andreas Bauer; +Cc: linux-usb

On Thu, Sep 16, 2021 at 09:56:15PM +0700, Andreas Bauer wrote:
> 
> I propose the included patch to the OTG USB ethernet gadget code:
> 
>   Report default of bus powered and 500mA bMaxPower consumption.
> 
> Reason:
> 
>   The USB spec requires all devices consuming more than 100mA from
>   the bus to report in this manner. Devices such as Rpi Zero can operate
>   in this mode and will then falsly report being self-powered when they
>   are not.
> 
>   The more sane default is to report being 500mA bus-powered than being
>   self-powered
> 
> This patch was born from an issue within the Raspberry Pi Zero ecosystem,
> therefore I would invite comment regarding other usage of this OTG code.
> 
> Best regards,
> 
> Andreas
> 
> $ diff -u linux-5.14.2/drivers/usb/gadget/legacy/ether.c.orig linux-5.14.2/drivers/usb/gadget/legacy/ether.c
> --- linux-5.14.2/drivers/usb/gadget/legacy/ether.c.orig	2021-09-08 13:52:41.000000000 +0700
> +++ linux-5.14.2/drivers/usb/gadget/legacy/ether.c	2021-09-16 21:25:06.782958554 +0700
> @@ -296,7 +296,8 @@
>  	/* .label = f(hardware) */
>  	.bConfigurationValue	= 1,
>  	/* .iConfiguration = DYNAMIC */
> -	.bmAttributes		= USB_CONFIG_ATT_SELFPOWER,
> +	.bmAttributes		= 0,   /* bus powered implied */
> +	.bMaxPower		= 250, /* 500mA in 2mA units */
>  };
>  
>  /*-------------------------------------------------------------------------*/

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- Your patch does not have a Signed-off-by: line.  Please read the
  kernel file, Documentation/SubmittingPatches and resend it after
  adding that line.  Note, the line needs to be in the body of the
  email, before the patch, not at the bottom of the patch or in the
  email signature.

- You did not specify a description of why the patch is needed, or
  possibly, any description at all, in the email body.  Please read the
  section entitled "The canonical patch format" in the kernel file,
  Documentation/SubmittingPatches for what is needed in order to
  properly describe the change.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

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

* Re: [PATCH] usb: gadget/legacy/ether: assume saner default power mode
  2021-09-16 14:56 [PATCH] usb: gadget/legacy/ether: assume saner default power mode Andreas Bauer
  2021-09-16 15:36 ` Greg KH
@ 2021-09-17  5:28 ` Felipe Balbi
  2021-09-17  7:15   ` Andreas Bauer
  1 sibling, 1 reply; 6+ messages in thread
From: Felipe Balbi @ 2021-09-17  5:28 UTC (permalink / raw)
  To: Andreas Bauer; +Cc: linux-usb

Hi,

Andreas Bauer <andreas.bauer.nexus@gmail.com> writes:

> I propose the included patch to the OTG USB ethernet gadget code:
>
>   Report default of bus powered and 500mA bMaxPower consumption.
>
> Reason:
>
>   The USB spec requires all devices consuming more than 100mA from
>   the bus to report in this manner. Devices such as Rpi Zero can operate
>   in this mode and will then falsly report being self-powered when they
>   are not.
>
>   The more sane default is to report being 500mA bus-powered than being
>   self-powered
>
> This patch was born from an issue within the Raspberry Pi Zero ecosystem,
> therefore I would invite comment regarding other usage of this OTG code.

Have a look at other commits to get examples of how to write commits for
upstream. You're missing your Signed-off-by, adding extra unnecessary
spaces and making your signature show up in the commit log. All of
these are described in kernel documentation this
(https://www.kernel.org/doc/html/latest/process/submitting-patches.html)
is a good starting point.

> $ diff -u linux-5.14.2/drivers/usb/gadget/legacy/ether.c.orig linux-5.14.2/drivers/usb/gadget/legacy/ether.c
> --- linux-5.14.2/drivers/usb/gadget/legacy/ether.c.orig	2021-09-08 13:52:41.000000000 +0700
> +++ linux-5.14.2/drivers/usb/gadget/legacy/ether.c	2021-09-16 21:25:06.782958554 +0700
> @@ -296,7 +296,8 @@
>  	/* .label = f(hardware) */
>  	.bConfigurationValue	= 1,
>  	/* .iConfiguration = DYNAMIC */
> -	.bmAttributes		= USB_CONFIG_ATT_SELFPOWER,
> +	.bmAttributes		= 0,   /* bus powered implied */
> +	.bMaxPower		= 250, /* 500mA in 2mA units */

right, your "sane" default now prevents this gadget driver from working
behind bus powered hubs. Considering that a linux-based device is likely
to have its own battery, this is not really a sane default.

The default value of "self powered", seems much saner ;-)

-- 
balbi

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

* Re: [PATCH] usb: gadget/legacy/ether: assume saner default power mode
  2021-09-17  5:28 ` Felipe Balbi
@ 2021-09-17  7:15   ` Andreas Bauer
  2021-09-17  8:29     ` Felipe Balbi
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Bauer @ 2021-09-17  7:15 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: linux-usb

Am Fri, Sep 17, 2021 at 08:28:16AM +0300 schrieb Felipe Balbi:

> Have a look at other commits to get examples of how to write commits for
> upstream. You're missing your Signed-off-by, adding extra unnecessary
> spaces and making your signature show up in the commit log. All of
> these are described in kernel documentation this
> (https://www.kernel.org/doc/html/latest/process/submitting-patches.html)
> is a good starting point.

I apologize, this was my first try at contributing based on what I 
observed on this list. Will fix all mentioned points and consult the
documentation before trying again.

> > -	.bmAttributes		= USB_CONFIG_ATT_SELFPOWER,
> > +	.bmAttributes		= 0,	/* bus powered implied */
> > +	.bMaxPower		= 250,	/* 500mA in 2mA units */
> 
> right, your "sane" default now prevents this gadget driver from working
> behind bus powered hubs. Considering that a linux-based device is likely
> to have its own battery, this is not really a sane default.

The linux-based battery-powered device I have here (Android) charges its
battery and is thus bus-powered while in gadget mode.

Are there really a lot of devices that use gadget mode and do NOT draw 
power from the USB bus? Honest question, I don't know the answer.

> The default value of "self powered", seems much saner ;-)

It violates USB specification as is for most cases I reckon.  It also 
maximize functionality when the host does not enforce USB spec which
mostly seems to be the case.

Would a CONFIG option here make sense to differentiate between 
bus-powered devices and self-powered ones? This would probably affect
most OTG drivers...

regards,

Andreas

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

* Re: [PATCH] usb: gadget/legacy/ether: assume saner default power mode
  2021-09-17  7:15   ` Andreas Bauer
@ 2021-09-17  8:29     ` Felipe Balbi
  2021-09-17 17:12       ` Andreas Bauer
  0 siblings, 1 reply; 6+ messages in thread
From: Felipe Balbi @ 2021-09-17  8:29 UTC (permalink / raw)
  To: Andreas Bauer; +Cc: linux-usb


Hi,

Andreas Bauer <andreas.bauer.nexus@gmail.com> writes:
> Am Fri, Sep 17, 2021 at 08:28:16AM +0300 schrieb Felipe Balbi:
>
>> Have a look at other commits to get examples of how to write commits for
>> upstream. You're missing your Signed-off-by, adding extra unnecessary
>> spaces and making your signature show up in the commit log. All of
>> these are described in kernel documentation this
>> (https://www.kernel.org/doc/html/latest/process/submitting-patches.html)
>> is a good starting point.
>
> I apologize, this was my first try at contributing based on what I 
> observed on this list. Will fix all mentioned points and consult the
> documentation before trying again.

No worries :)

>> > -	.bmAttributes		= USB_CONFIG_ATT_SELFPOWER,
>> > +	.bmAttributes		= 0,	/* bus powered implied */
>> > +	.bMaxPower		= 250,	/* 500mA in 2mA units */
>> 
>> right, your "sane" default now prevents this gadget driver from working
>> behind bus powered hubs. Considering that a linux-based device is likely
>> to have its own battery, this is not really a sane default.
>
> The linux-based battery-powered device I have here (Android) charges its
> battery and is thus bus-powered while in gadget mode.

that's okay. It's because of this sort of thing that we've switched to a
configfs-based approach where we don't need to make assumptions about
the application. That's also why the pre-composed gadgets have been
moved to the "legacy" directory and we don't take changes to those
anymore, unless it's a bugfix, which $subject doesn't appear to be :)

> Are there really a lot of devices that use gadget mode and do NOT draw 
> power from the USB bus? Honest question, I don't know the answer.

Finding that out is going to be pretty hard, I'm afraid.

>> The default value of "self powered", seems much saner ;-)
>
> It violates USB specification as is for most cases I reckon.  It also 
> maximize functionality when the host does not enforce USB spec which
> mostly seems to be the case.
>
> Would a CONFIG option here make sense to differentiate between 
> bus-powered devices and self-powered ones? This would probably affect
> most OTG drivers...

We have configfs to cope with all of the possible variations, might want
to give that a shot?

https://www.kernel.org/doc/html/latest/usb/gadget_configfs.html

-- 
balbi

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

* Re: [PATCH] usb: gadget/legacy/ether: assume saner default power mode
  2021-09-17  8:29     ` Felipe Balbi
@ 2021-09-17 17:12       ` Andreas Bauer
  0 siblings, 0 replies; 6+ messages in thread
From: Andreas Bauer @ 2021-09-17 17:12 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: linux-usb

Am Fri, Sep 17, 2021 at 11:29:02AM +0300 schrieb Felipe Balbi:

> that's okay. It's because of this sort of thing that we've switched to a
> configfs-based approach where we don't need to make assumptions about
> the application. That's also why the pre-composed gadgets have been
> moved to the "legacy" directory and we don't take changes to those
> anymore, unless it's a bugfix, which $subject doesn't appear to be :)

Ok... my intention was to fix something which is wrong, but as always
in life, things are complicated. I will not pursue this further.

Thanks for your input.

> We have configfs to cope with all of the possible variations, might want
> to give that a shot?
> 
> https://www.kernel.org/doc/html/latest/usb/gadget_configfs.html

Never change a ru....

I will eventually give it a shot ;-)

best regards,

Andreas

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

end of thread, other threads:[~2021-09-17 17:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-16 14:56 [PATCH] usb: gadget/legacy/ether: assume saner default power mode Andreas Bauer
2021-09-16 15:36 ` Greg KH
2021-09-17  5:28 ` Felipe Balbi
2021-09-17  7:15   ` Andreas Bauer
2021-09-17  8:29     ` Felipe Balbi
2021-09-17 17:12       ` Andreas Bauer

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.