usb: gadget: ether: Disable USB pullup in eth probe
PATCH 1/1 usb: gadget: ether: Disable USB pullup in eth probe
usb_gadget_register_driver() called by probe will initialize the USB controller which enters ready to connect state with pull-up resistor enabled.
From the host's point of view, a device is ready to be enumerated. However, since dm_usb_gadget_handle_interrupts() is only called when ethernet function is started, at this stage USB events are not managed, host's enumeration attempts will fail and resulting error like:
usb 1-1: new high-speed USB device number 50 using xhci_hcd usb 1-1: device descriptor read/64, error -110
usb 1-1: device descriptor read/64, error -110
usb usb1-port1: attempt power cycle
Disable USB pullup to prevent unwanted enumeration attempt.
--- drivers/usb/gadget/ether.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/usb/gadget/ether.c +10 -1
@@ -2459,6 +2459,8 @@ static int usb_eth_probe(struct udevice *dev) {struct ether_priv *priv =dev_get_priv (dev);struct eth_pdata *pdata =dev_get_plat (dev); +struct eth_dev *ethdev = &priv->ethdev; +int ret; priv->netdev = dev; l_priv = priv;
@@ -2499,7 +2501,14 @@ static int usb_eth_probe(struct udevice *dev) priv->eth_driver.disconnect = eth_disconnect; priv->eth_driver.suspend = eth_suspend; priv->eth_driver.resume = eth_resume; -return usb_gadget_register_driver (&priv->eth_driver); + + ret =usb_gadget_register_driver (&priv->eth_driver); +if (ret) +return ret; + +/* Keep pullup disabled until interrupt is available */ +usb_gadget_disconnect (ethdev->gadget); +return 0 ; }static int usb_eth_remove (struct udevice *dev)
--
2.45.2
Quoted 34 lines · Zixun LI
usb_gadget_register_driver()called by probe will initialize the USB controller which enters ready to connect state with pull-up resistor enabled.Quoted 1 line
From the host's point of view, a device is ready to be enumerated.
However, since
dm_usb_gadget_handle_interrupts()is only called when ethernet function is started, at this stage USB events are not managed, host's enumeration attempts will fail and resulting error like:
usb 1-1: new high-speed USB device number 50 usingxhci_hcdusb 1-1: device descriptor read/64, error -110
usb 1-1: device descriptor read/64, error -110
usb usb1-port1: attempt power cycleDisable USB pullup to prevent unwanted enumeration attempt.
Signed-off-by Zixun LI <[email protected]>--- drivers/usb/gadget/ether.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/usb/gadget/ether.c +2
-0@@ -2459,6 +2459,8 @@ static int usb_eth_probe(struct udevice *dev) {struct ether_priv *priv =dev_get_priv (dev);struct eth_pdata *pdata =dev_get_plat (dev); +struct eth_dev *ethdev = &priv->ethdev; +int ret; priv->netdev = dev; l_priv = priv;
drivers/usb/gadget/ether.c static int usb_eth_probe(struct udevice *dev) · line 2505
Quoted 6 lines
drivers/usb/gadget/ether.c +2
-1@@ -2499,7 +2501,14 @@ static int usb_eth_probe(struct udevice *dev) priv->eth_driver.disconnect = eth_disconnect; priv->eth_driver.suspend = eth_suspend; priv->eth_driver.resume = eth_resume; -return usb_gadget_register_driver (&priv->eth_driver); + + ret =usb_gadget_register_driver (&priv->eth_driver);
Wouldn't it be better if usb_gadget_register_driver() started in disconnected state right away ?
Hi Marek,
Quoted 3 lines · Marek Vasut
Wouldn't it be better if
usb_gadget_register_driver()started in disconnected state right away ?
That's what I did initially. But since g_dnl doesn't do connection after register (I explained in cover letter) doing so will keep g_dnl always in disconnected state.
Quoted 1 line · Zixun LI
Hi Marek,
Hi,
Quoted 8 lines · Marek Vasut
Quoted 3 lines
Wouldn't it be better if
usb_gadget_register_driver()started in disconnected state right away ?That's what I did initially. But since
g_dnldoesn't do connection after register (I explained in cover letter) doing so will keepg_dnlalways in disconnected state.
Would it be possible to fix up the g_dnl ?
Hi,
Quoted 2 lines · Marek Vasut
Would it be possible to fix up the
g_dnl?
g_dnl's interface is pretty different from usb_ether, I can't find a way to accessusb_gadget struct in g_dnl_register().
Meanwhile it can be fixed in udc core, by doing gadget_driver bind after udc start,
in addition to keeping the controller in disconnected state.
(quoted diff) +0 -0
b/drivers/usb/gadget/udc/udc-core.c
index 6bb419ae2a..b917a79892 100644
drivers/usb/gadget/udc/udc-core.c +0 -0
@@ -300,15 +300,17 @@ static int udc_bind_to_driver(struct usb_udc
*udc, struct usb_gadget_driver *dri
usb_gadget_udc_set_speed(udc, driver->speed);
- ret = driver->bind(udc->gadget);
- if (ret)
- goto err1;
ret = usb_gadget_udc_start(udc);
if (ret) {
- driver->unbind(udc->gadget);
goto err1;
}- usb_gadget_connect(udc->gadget);
+
+ /* Keep pullup disabled until interrupt is available */
+ usb_gadget_disconnect(udc->gadget);
+
+ ret = driver->bind(udc->gadget);
+ if (ret)
+ goto err1;
return 0;
err1:
Quoted 1 line · Zixun LI
Hi,
Hi,
Quoted 7 lines · Marek Vasut
Quoted 2 lines
Would it be possible to fix up the
g_dnl?g_dnl's interface is pretty different from
usb_ether, I can't find a way to accessusb_gadgetstruct ing_dnl_register().
Can you change the g_dnl_register() prototype and pass he structure in ? I suspect it should be available in the commands which register g_dnl ?
Quoted 16 lines
Meanwhile it can be fixed in udc core, by doing
gadget_driverbind after udc start,
in addition to keeping the controller in disconnected state.drivers/usb/gadget/udc/udc-core.c +0
-2@@ -300,15 +300,17 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driusb_gadget_udc_set_speed (udc, driver->speed); - ret = driver->bind (udc->gadget); -if (ret)
drivers/usb/gadget/udc/udc-core.c static int udc_bind_to_driver(struct usb_udc · line 310
Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +3
-3- goto err1; ret =usb_gadget_udc_start (udc);if (ret) { - driver->unbind (udc->gadget); goto err1; } -usb_gadget_connect (udc->gadget); + +/* Keep pullup disabled until interrupt is available */ +usb_gadget_disconnect (udc->gadget);
This is no good, this is a workaround, let's not do this.
Quoted 6 lines
drivers/usb/gadget/udc/udc-core.c +3
-0+ ret = driver->bind (udc->gadget); +if (ret) + goto err1;return 0 ; err1:
[...]
Quoted 4 lines · Marek Vasut
Can you change the
g_dnl_register()prototype and pass he structure in ? I suspect it should be available in the commands which registerg_dnl?
There are many places where g_dnl_register() is called, like fastboot, dfu, ums, etc, need to modify all of them ?
Quoted 3 lines
This is no good, this is a workaround, let's not do this.
You mean which part, order change or disconnect call ?
Is there a fixed order of udc_start (device init) and driver->bind ? In non-DM mode most device drivers do init first in their usb_gadget_register_driver(), except udc-core and DWC2 who does driver->bind first.
Call usb_gadget_disconnect here could avoid modifying all device driver's init.
Quoted 8 lines · Zixun LI
Quoted 4 lines · Marek Vasut
Can you change the
g_dnl_register()prototype and pass he structure in ? I suspect it should be available in the commands which registerg_dnl?There are many places where
g_dnl_register()is called, like fastboot, dfu, ums, etc, need to modify all of them ?
I think that should be possible with 'git grep' and 'sed' mechanically.
Quoted 4 lines
Quoted 2 lines
This is no good, this is a workaround, let's not do this.
You mean which part, order change or disconnect call ?
Yes
Quoted 4 lines
Is there a fixed order of
udc_start(device init) anddriver->bind? In non-DM mode most device drivers do init first in theirusb_gadget_register_driver(), except udc-core and DWC2 who doesdriver->bindfirst.
The driver .bind callback is called when the driver is instantiated (e.g. matching compatible string is found in DT, or some board file instantiates a driver and binds it to a DT node). This can happen very early.
The driver .probe callback initializes the controller hardware and is called only the first time the controller is used. U-Boot uses lazy hardware initialization to speed up the boot process, i.e. hardware is initialized the first time it is used, using the .probe callback.
The .udc_start callback in usb_gadget_ops must be called after the controller driver .bind and .probe were called.
The usb_composite_driver .bind has to be called after controller driver .bind (but it may be called before controller driver .probe).
I think udc_bind_to_driver() should not call usb_gadget_connect() , that connect should likely be called by at some later point. I also think that drivers/usb/gadget/udc/udc-core.c might have to be extended to provide some way to convert controller struct udevice to struct usb_gadget , so when e.g. run_usb_dnl_gadget() calls udc_device_get_by_index() and obtains struct udevice * , it can also get matching struct usb_gadget * , and call the usb_gadget_connect().
What do you think ?
Quoted 1 line
Call
usb_gadget_disconnecthere could avoid modifying all device driver's init.
[...]
Quoted 3 lines · Marek Vasut
I think
udc_bind_to_driver()should not callusb_gadget_connect(), that connect should likely be called by at some later point.
Yes it's more logical, to keep it in disconnected state you prefer modify controllers drivers init (I can do usba_udc and dwc2) or add a disconnect() call ?
Quoted 8 lines
I also think
thatdrivers/usb/gadget/udc/udc-core.cmight have to be extended to provide some way to convert controller struct udevice to structusb_gadget, so when e.g.run_usb_dnl_gadget()callsudc_device_get_by_index()and obtains struct udevice * , it can also get matching structusb_gadget* , and call theusb_gadget_connect().What do you think ?
I think it's a good idea.
If there are multiple gadget controllers (very rare), since usb_gadget_probe_driver() simply takes the first one from udc list, is there a chance that the one to be started is different from the one used by udc_device_get_by_index() ?
Quoted 8 lines · Zixun LI
Quoted 3 lines · Marek Vasut
I think
udc_bind_to_driver()should not callusb_gadget_connect(), that connect should likely be called by at some later point.Yes it's more logical, to keep it in disconnected state you prefer modify controllers drivers init (I can do
usba_udcand dwc2) or add adisconnect()call ?
I think modify the init is the best option.
Quoted 7 lines
Quoted 7 lines
I also think
thatdrivers/usb/gadget/udc/udc-core.cmight have to be extended to provide some way to convert controller struct udevice to structusb_gadget, so when e.g.run_usb_dnl_gadget()callsudc_device_get_by_index()and obtains struct udevice * , it can also get matching structusb_gadget* , and call theusb_gadget_connect().
Quoted 8 lines
Quoted 1 line
What do you think ?
I think it's a good idea.
If there are multiple gadget controllers (very rare), since
usb_gadget_probe_driver()simply takes the first one from udc list, is there a chance that the one to be started is different from the one used byudc_device_get_by_index()?
Yes, I think that chance exists.
I am looking at the usb_add_gadget_udc_release() and usb_gadget_probe_driver() and I am thinking, sigh, all that code is ready to be replaced by something cleaner which does not use this special struct usb_udc and udc_list, but instead only uses U-Boot DM udevices . But I am reluctant to ask you to do all that rework, because that is WAY out of scope of the problem you are trying to fix.
Quoted 23 lines · Marek Vasut
Quoted 8 lines · Zixun LI
Quoted 3 lines · Marek Vasut
I think
udc_bind_to_driver()should not callusb_gadget_connect(), that connect should likely be called by at some later point.Yes it's more logical, to keep it in disconnected state you prefer modify controllers drivers init (I can do
usba_udcand dwc2) or add adisconnect()call ?I think modify the init is the best option.
Quoted 11 lines
Quoted 8 lines
I also think
thatdrivers/usb/gadget/udc/udc-core.cmight have to be extended to provide some way to convert controller struct udevice to structusb_gadget, so when e.g.run_usb_dnl_gadget()callsudc_device_get_by_index()and obtains struct udevice * , it can also get matching structusb_gadget* , and call theusb_gadget_connect().What do you think ?
I think it's a good idea.
Quoted 8 lines
Quoted 4 lines
If there are multiple gadget controllers (very rare), since
usb_gadget_probe_driver()simply takes the first one from udc list, is there a chance that the one to be started is different from the one used byudc_device_get_by_index()?Yes, I think that chance exists.
I am looking at the
usb_add_gadget_udc_release()andusb_gadget_probe_driver()and I am thinking, sigh, all that code is ready to be replaced by something cleaner which does not use this special structusb_udcandudc_list, but instead only uses U-Boot DM udevices . But I am reluctant to ask you to do all that rework, because that is WAY out of scope of the problem you are trying to fix.
Maybe this could be a start (compile tested only):
https://source.denx.de/u-boot/custodians/u-boot-sh/-/commits/usb-udc-udevice
Quoted 9 lines · Marek Vasut
Quoted 8 lines
I am looking at the
usb_add_gadget_udc_release()andusb_gadget_probe_driver()and I am thinking, sigh, all that code is ready to be replaced by something cleaner which does not use this special structusb_udcandudc_list, but instead only uses U-Boot DM udevices . But I am reluctant to ask you to do all that rework, because that is WAY out of scope of the problem you are trying to fix.
Thank you for looking into this, refactor udc core could make things clear.
Quoted 3 lines
Maybe this could be a start (compile tested only):
https://source.denx.de/u-boot/custodians/u-boot-sh/-/commits/usb-udc-udevice
Tested no regression with usba_udc.
Quoted 11 lines · Zixun LI
Quoted 9 lines · Marek Vasut
Quoted 8 lines
I am looking at the
usb_add_gadget_udc_release()andusb_gadget_probe_driver()and I am thinking, sigh, all that code is ready to be replaced by something cleaner which does not use this special structusb_udcandudc_list, but instead only uses U-Boot DM udevices . But I am reluctant to ask you to do all that rework, because that is WAY out of scope of the problem you are trying to fix.
Quoted 1 line
Thank you for looking into this, refactor udc core could make things clear.
Sigh, yeah, I think you ran into part of the UDC code which is just ... not great ... sorry about that.
Quoted 5 lines
Quoted 3 lines
Maybe this could be a start (compile tested only):
https://source.denx.de/u-boot/custodians/u-boot-sh/-/commits/usb-udc-udevice
Tested no regression with
usba_udc.
Thanks for testing, patches posted.
Quoted 17 lines · Marek Vasut
Quoted 11 lines · Zixun LI
Quoted 9 lines · Marek Vasut
Quoted 8 lines
I am looking at the
usb_add_gadget_udc_release()andusb_gadget_probe_driver()and I am thinking, sigh, all that code is ready to be replaced by something cleaner which does not use this special structusb_udcandudc_list, but instead only uses U-Boot DM udevices . But I am reluctant to ask you to do all that rework, because that is WAY out of scope of the problem you are trying to fix.Quoted 1 line
Thank you for looking into this, refactor udc core could make things clear.
Sigh, yeah, I think you ran into part of the UDC code which is just ... not great ... sorry about that.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Maybe this could be a start (compile tested only):
https://source.denx.de/u-boot/custodians/u-boot-sh/-/commits/usb-udc-udevice
Tested no regression with
usba_udc.Thanks for testing, patches posted.
For reference, the series was posted here: