Skip to contentSkip to conversation

usb: gadget/legacy/ether: assume saner default power mode

PATCH In review Andreas Bauer 3 participants 6 messages Sep 16, 2021 – Sep 17, 2021 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget/legacy/ether: assume saner default power mode

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 */
 };

/*-------------------------------------------------------------------------*/

#1 lore raw
Quoted 26 lines · Andreas Bauer

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

drivers/usb/gadget/legacy/ether.c line 303

Quoted 9 lines
drivers/usb/gadget/legacy/ether.c renamed from drivers/usb/gadget/legacy/ether.c.orig +2 -1
@@ -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

#2 lore raw
In reply to Andreas Bauer

Hi,

Quoted 11 lines · Andreas Bauer

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.

Quoted 5 lines

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.

drivers/usb/gadget/legacy/ether.c line 300

Quoted 10 lines
$ diff -u linux-5.14.2/drivers/usb/gadget/legacy/ether.c.orig linux-5.14.2/drivers/usb/gadget/legacy/ether.c
drivers/usb/gadget/legacy/ether.c renamed from drivers/usb/gadget/legacy/ether.c.orig +2 -1
@@ -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 ;-)

Signature · 1 line
balbi
#3 lore raw

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

Quoted 6 lines

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.

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +2 -1
-	.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.

Quoted 1 line

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

#4 lore raw

Hi,

Quoted 9 lines · Andreas Bauer

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

Quoted 6 lines

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.

Quoted 3 lines

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 :)

Quoted 10 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +2 -1
-	.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 :)

Quoted 2 lines

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.

Quoted 9 lines
Quoted 1 line

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

Signature · 1 line
balbi
#5 lore raw

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

Quoted 5 lines

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.

Quoted 4 lines

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