usb: core: improve handling of hubs with no ports
Subsystems (2)
PATCH 1/1 usb: core: improve handling of hubs with no ports
I get the "hub doesn't have any ports" error message on a system with Amlogic S905W SoC. Seems the SoC has internal USB 3.0 supports but is crippled with regard to USB 3.0 ports.
Maybe we shouldn't consider this scenario an error. So let's change the message to info level, but otherwise keep the handling of the scenario as it is today. With the patch it looks like this on my system.
dwc2 c9100000.usb: supply vusb_d not found, using dummy regulator
dwc2 c9100000.usb: supply vusb_a not found, using dummy regulator
dwc2 c9100000.usb: EPs: 7, dedicated fifos, 712 entries in SPRAM
xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 1 xhci-hcd xhci-hcd.0.auto: hcc params 0x0228f664 hci version 0x100 quirks 0x0000000002010010 xhci-hcd xhci-hcd.0.auto: irq 49, io mem 0xc9000000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 2 xhci-hcd xhci-hcd.0.auto: Host supports USB 3.0 SuperSpeed
usb usb2: We don't know the algorithms for LPM for this host, disabling LPM. hub 2-0:1.0: USB hub found
hub 2-0:1.0: hub has no ports, exiting
--- drivers/usb/core/hub.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/usb/core/hub.c +2 -3
@@ -1423,9 +1423,8 @@ static int hub_configure(struct usb_hub *hub, ret = -ENODEV ; goto fail; }else if (hub->descriptor->bNbrPorts ==0 ) { - message ="hub doesn't have any ports!" ; - ret = -ENODEV ; - goto fail; +dev_info (hub_dev,"hub has no ports, exiting\n" ); +return -ENODEV ; }/*
Signature · 1 line
2.35.1
Quoted 35 lines · Heiner Kallweit
I get the "hub doesn't have any ports" error message on a system with Amlogic S905W SoC. Seems the SoC has internal USB 3.0 supports but is crippled with regard to USB 3.0 ports.
Maybe we shouldn't consider this scenario an error. So let's change the message to info level, but otherwise keep the handling of the scenario as it is today. With the patch it looks like this on my system.dwc2 c9100000.usb: supply
vusb_dnot found, using dummy regulator
dwc2 c9100000.usb: supplyvusb_anot found, using dummy regulator
dwc2 c9100000.usb: EPs: 7, dedicated fifos, 712 entries in SPRAM
xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 1 xhci-hcd xhci-hcd.0.auto: hcc params0x0228f664hci version0x100quirks0x0000000002010010xhci-hcd xhci-hcd.0.auto: irq 49, io mem0xc9000000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 2 xhci-hcd xhci-hcd.0.auto: Host supports USB 3.0 SuperSpeed
usb usb2: We don't know the algorithms for LPM for this host, disabling LPM. hub 2-0:1.0: USB hub found
hub 2-0:1.0: hub has no ports, exitingSigned-off-by Heiner Kallweit <[email protected]>--- drivers/usb/core/hub.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/usb/core/hub.c +0
-0@@ -1423,9 +1423,8 @@ static int hub_configure(struct usb_hub *hub, ret = -ENODEV ;
drivers/usb/core/hub.c static int hub_configure(struct usb_hub *hub, · line 1430
Quoted 10 lines
drivers/usb/core/hub.c +2
-3goto fail; }else if (hub->descriptor->bNbrPorts ==0 ) { - message ="hub doesn't have any ports!" ; - ret = -ENODEV ; - goto fail; +dev_info (hub_dev,"hub has no ports, exiting\n" ); +return -ENODEV ; }/*
How about instead changing xhci-hcd so that it doesn't try to register a USB-3 root hub if the controller doesn't have any USB-3 ports? I think that would make more sense.
Alan Stern
Quoted 45 lines · Alan Stern
Quoted 44 lines · Heiner Kallweit
I get the "hub doesn't have any ports" error message on a system with Amlogic S905W SoC. Seems the SoC has internal USB 3.0 supports but is crippled with regard to USB 3.0 ports.
Maybe we shouldn't consider this scenario an error. So let's change the message to info level, but otherwise keep the handling of the scenario as it is today. With the patch it looks like this on my system.dwc2 c9100000.usb: supply
vusb_dnot found, using dummy regulator
dwc2 c9100000.usb: supplyvusb_anot found, using dummy regulator
dwc2 c9100000.usb: EPs: 7, dedicated fifos, 712 entries in SPRAM
xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 1 xhci-hcd xhci-hcd.0.auto: hcc params0x0228f664hci version0x100quirks0x0000000002010010xhci-hcd xhci-hcd.0.auto: irq 49, io mem0xc9000000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 2 xhci-hcd xhci-hcd.0.auto: Host supports USB 3.0 SuperSpeed
usb usb2: We don't know the algorithms for LPM for this host, disabling LPM. hub 2-0:1.0: USB hub found
hub 2-0:1.0: hub has no ports, exitingSigned-off-by Heiner Kallweit <[email protected]>--- drivers/usb/core/hub.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/usb/core/hub.c +2
-3@@ -1423,9 +1423,8 @@ static int hub_configure(struct usb_hub *hub, ret = -ENODEV ; goto fail; }else if (hub->descriptor->bNbrPorts ==0 ) { - message ="hub doesn't have any ports!" ; - ret = -ENODEV ; - goto fail; +dev_info (hub_dev,"hub has no ports, exiting\n" ); +return -ENODEV ; }
Quoted 6 lines
drivers/usb/core/hub.c static int hub_configure(struct usb_hub *hub, · line 1430
Quoted 1 line
drivers/usb/core/hub.c +0
-0/* How about instead changing xhci-hcd so that it doesn't try to register a USB-3 root hub if the controller doesn't have any USB-3 ports? I think that would make more sense.
Right, this would be better. I checked and it seems to be a little bit bigger endeavor. If I let register_root_hub() fail, then this removes the USB3 bus/host (shared hcd), but also the USB2 bus/host. It took an additional change to xhci_plat_probe() to make it work on my system. Not sure what the impact could be on systems not using xhci_plat_probe(). Users may face the same issue like me, and having a USB3 hub with no ports may remove also the USB2 bus/host.
What I can do: submit my patches as RFC, then there's a better basis for a discussion.
Quoted 1 line
Alan Stern
Heiner
Quoted 24 lines · Heiner Kallweit
Quoted 17 lines · Alan Stern
Quoted 16 lines · Heiner Kallweit
drivers/usb/core/hub.c +2
-3@@ -1423,9 +1423,8 @@ static int hub_configure(struct usb_hub *hub, ret = -ENODEV ; goto fail; }else if (hub->descriptor->bNbrPorts ==0 ) { - message ="hub doesn't have any ports!" ; - ret = -ENODEV ; - goto fail; +dev_info (hub_dev,"hub has no ports, exiting\n" ); +return -ENODEV ; }Quoted 6 lines
drivers/usb/core/hub.c static int hub_configure(struct usb_hub *hub, · line 1430
Quoted 1 line
drivers/usb/core/hub.c +0
-0/* How about instead changing xhci-hcd so that it doesn't try to register a USB-3 root hub if the controller doesn't have any USB-3 ports? I think that would make more sense.
Quoted 7 lines
Right, this would be better. I checked and it seems to be a little bit bigger endeavor. If I let
register_root_hub()fail, then this removes the USB3 bus/host (shared hcd), but also the USB2 bus/host. It took an additional change toxhci_plat_probe()to make it work on my system. Not sure what the impact could be on systems not usingxhci_plat_probe(). Users may face the same issue like me, and having a USB3 hub with no ports may remove also the USB2 bus/host.
Don't change register_root_hub(). Just change xhci_plat_probe(); make it skip the second call to usb_add_hcd() if there are no USB-3 ports.
Alan Stern
Quoted 6 lines
What I can do: submit my patches as RFC, then there's a better basis for a discussion.
Quoted 1 line
Alan Stern
Heiner
Quoted 33 lines · Alan Stern
Quoted 24 lines · Heiner Kallweit
Quoted 17 lines · Alan Stern
Quoted 16 lines · Heiner Kallweit
drivers/usb/core/hub.c +2
-3@@ -1423,9 +1423,8 @@ static int hub_configure(struct usb_hub *hub, ret = -ENODEV ; goto fail; }else if (hub->descriptor->bNbrPorts ==0 ) { - message ="hub doesn't have any ports!" ; - ret = -ENODEV ; - goto fail; +dev_info (hub_dev,"hub has no ports, exiting\n" ); +return -ENODEV ; }Quoted 6 lines
drivers/usb/core/hub.c static int hub_configure(struct usb_hub *hub, · line 1430
Quoted 1 line
drivers/usb/core/hub.c +0
-0/* How about instead changing xhci-hcd so that it doesn't try to register a USB-3 root hub if the controller doesn't have any USB-3 ports? I think that would make more sense.
Quoted 7 lines
Right, this would be better. I checked and it seems to be a little bit bigger endeavor. If I let
register_root_hub()fail, then this removes the USB3 bus/host (shared hcd), but also the USB2 bus/host. It took an additional change toxhci_plat_probe()to make it work on my system. Not sure what the impact could be on systems not usingxhci_plat_probe(). Users may face the same issue like me, and having a USB3 hub with no ports may remove also the USB2 bus/host.
Quoted 3 lines
Don't change
register_root_hub(). Just changexhci_plat_probe(); make it skip the second call tousb_add_hcd()if there are no USB-3 ports.
How would I know the number of USB-3 ports before calling usb_add_hcd()? get_hub_descriptor() can be called only later in usb_add_hcd().
Quoted 8 lines
Alan Stern
Quoted 6 lines
What I can do: submit my patches as RFC, then there's a better basis for a discussion.
Quoted 1 line
Alan Stern
Heiner
Quoted 34 lines · Heiner Kallweit
Quoted 33 lines · Alan Stern
Quoted 31 lines · Heiner Kallweit
Quoted 17 lines · Alan Stern
Quoted 16 lines · Heiner Kallweit
drivers/usb/core/hub.c +2
-3@@ -1423,9 +1423,8 @@ static int hub_configure(struct usb_hub *hub, ret = -ENODEV ; goto fail; }else if (hub->descriptor->bNbrPorts ==0 ) { - message ="hub doesn't have any ports!" ; - ret = -ENODEV ; - goto fail; +dev_info (hub_dev,"hub has no ports, exiting\n" ); +return -ENODEV ; }Quoted 6 lines
drivers/usb/core/hub.c static int hub_configure(struct usb_hub *hub, · line 1430
Quoted 1 line
drivers/usb/core/hub.c +0
-0/* How about instead changing xhci-hcd so that it doesn't try to register a USB-3 root hub if the controller doesn't have any USB-3 ports? I think that would make more sense.
Right, this would be better. I checked and it seems to be a little bit bigger endeavor. If I let
register_root_hub()fail, then this removes the USB3 bus/host (shared hcd), but also the USB2 bus/host. It took an additional change toxhci_plat_probe()to make it work on my system. Not sure what the impact could be on systems not usingxhci_plat_probe(). Users may face the same issue like me, and having a USB3 hub with no ports may remove also the USB2 bus/host.
Quoted 5 lines
Quoted 3 lines
Don't change
register_root_hub(). Just changexhci_plat_probe(); make it skip the second call tousb_add_hcd()if there are no USB-3 ports.How would I know the number of USB-3 ports before calling
usb_add_hcd()?get_hub_descriptor()can be called only later inusb_add_hcd().
Where do you think get_hub_descriptor() gets that information from? It's stored in xhci->usb3_rhub.num_ports.
(Now, because I'm not very familiar with the xhci-hcd driver, I can't tell you whether xhci->usb3_rhub.num_ports gets initialized before or after the usb_add_hcd() call for the shared_hcd. You'll have to figure that out yourself.)
Alan Stern
Quoted 33 lines · Alan Stern
Quoted 24 lines · Heiner Kallweit
Quoted 17 lines · Alan Stern
Quoted 16 lines · Heiner Kallweit
drivers/usb/core/hub.c +2
-3@@ -1423,9 +1423,8 @@ static int hub_configure(struct usb_hub *hub, ret = -ENODEV ; goto fail; }else if (hub->descriptor->bNbrPorts ==0 ) { - message ="hub doesn't have any ports!" ; - ret = -ENODEV ; - goto fail; +dev_info (hub_dev,"hub has no ports, exiting\n" ); +return -ENODEV ; }Quoted 6 lines
drivers/usb/core/hub.c static int hub_configure(struct usb_hub *hub, · line 1430
Quoted 1 line
drivers/usb/core/hub.c +0
-0/* How about instead changing xhci-hcd so that it doesn't try to register a USB-3 root hub if the controller doesn't have any USB-3 ports? I think that would make more sense.
Quoted 7 lines
Right, this would be better. I checked and it seems to be a little bit bigger endeavor. If I let
register_root_hub()fail, then this removes the USB3 bus/host (shared hcd), but also the USB2 bus/host. It took an additional change toxhci_plat_probe()to make it work on my system. Not sure what the impact could be on systems not usingxhci_plat_probe(). Users may face the same issue like me, and having a USB3 hub with no ports may remove also the USB2 bus/host.
Quoted 3 lines
Don't change
register_root_hub(). Just changexhci_plat_probe(); make it skip the second call tousb_add_hcd()if there are no USB-3 ports.
This works on my system. However a consequence is that xhci->shared_hcd is NULL. There are a few places like the following in xhci.c where this may result in a NPE. Not knowing the USB subsystem in detail I can't say whether these places are in any relevant path.
static int xhci_run_finished(struct xhci_hcd *xhci)
{
if (xhci_start(xhci)) {
xhci_halt(xhci);
return -ENODEV;
}
xhci->shared_hcd->state = HC_STATE_RUNNING;Quoted 8 lines
Alan Stern
Quoted 6 lines
What I can do: submit my patches as RFC, then there's a better basis for a discussion.
Quoted 1 line
Alan Stern
Heiner
Heiner
Quoted 6 lines · Heiner Kallweit
Quoted 3 lines · Alan Stern
Don't change
register_root_hub(). Just changexhci_plat_probe(); make it skip the second call tousb_add_hcd()if there are no USB-3 ports.This works on my system. However a consequence is that
xhci->shared_hcdis NULL.
Why is that? xhci->shared_hcd doesn't get set in usb_add_hcd(), so skipping that call shouldn't cause it to be NULL.
Note: If you skip calling usb_add_hcd(), you will also have to skip the corresponding call to usb_remove_hcd(). There may be a few more subtleties involved as well; like I said before, I'm not an expert on this driver. You should ask the xhci-hcd maintainer for advice.
Alan Stern
Quoted 24 lines
There are a few places like the following in
xhci.cwhere
this may result in a NPE. Not knowing the USB subsystem in detail I can't say whether these places are in any relevant path.static int
xhci_run_finished(struct xhci_hcd *xhci){ if (xhci_start(xhci)) { xhci_halt(xhci); return -ENODEV; } xhci->shared_hcd->state = HC_STATE_RUNNING;Quoted 8 lines
Alan Stern
Quoted 6 lines
What I can do: submit my patches as RFC, then there's a better basis for a discussion.
Quoted 1 line
Alan Stern
Heiner
Heiner
Quoted 4 lines · Alan Stern
Quoted 3 lines · Heiner Kallweit
Quoted 2 lines · Alan Stern
Don't change
register_root_hub(). Just changexhci_plat_probe(); make it skip the second call tousb_add_hcd()if there are no USB-3 ports.
I believe this had been attempted in the past, but it does not appear that patch was ever accepted:
https://lore.kernel.org/linux-usb/[email protected]/
Jack
Quoted 37 lines
Quoted 2 lines
This works on my system. However a consequence is that
xhci->shared_hcdis NULL.Why is that?
xhci->shared_hcddoesn't get set inusb_add_hcd(), so skipping that call shouldn't cause it to be NULL.Note: If you skip calling
usb_add_hcd(), you will also have to skip the corresponding call tousb_remove_hcd(). There may be a few more subtleties involved as well; like I said before, I'm not an expert on this driver. You should ask the xhci-hcd maintainer for advice.Alan Stern
Quoted 24 lines
There are a few places like the following in
xhci.cwhere
this may result in a NPE. Not knowing the USB subsystem in detail I can't say whether these places are in any relevant path.static int
xhci_run_finished(struct xhci_hcd *xhci){ if (xhci_start(xhci)) { xhci_halt(xhci); return -ENODEV; } xhci->shared_hcd->state = HC_STATE_RUNNING;Quoted 8 lines
Alan Stern
Quoted 6 lines
What I can do: submit my patches as RFC, then there's a better basis for a discussion.
Quoted 1 line
Alan Stern
Heiner
Heiner
Quoted 11 lines · Jack Pham
Quoted 4 lines · Alan Stern
Quoted 3 lines · Heiner Kallweit
Quoted 2 lines · Alan Stern
Don't change
register_root_hub(). Just changexhci_plat_probe(); make it skip the second call tousb_add_hcd()if there are no USB-3 ports.I believe this had been attempted in the past, but it does not appear that patch was ever accepted:
I also found that xhci at several places relies on a proper shared_hcd, even if there are no USB3 ports. Therefore maybe go with the less invasive original version of my patch?
https://www.spinics.net/lists/linux-usb/msg222998.html
Quoted 39 lines
Jack
Quoted 37 lines
Quoted 2 lines
This works on my system. However a consequence is that
xhci->shared_hcdis NULL.Why is that?
xhci->shared_hcddoesn't get set inusb_add_hcd(), so skipping that call shouldn't cause it to be NULL.Note: If you skip calling
usb_add_hcd(), you will also have to skip the corresponding call tousb_remove_hcd(). There may be a few more subtleties involved as well; like I said before, I'm not an expert on this driver. You should ask the xhci-hcd maintainer for advice.Alan Stern
Quoted 24 lines
There are a few places like the following in
xhci.cwhere
this may result in a NPE. Not knowing the USB subsystem in detail I can't say whether these places are in any relevant path.static int
xhci_run_finished(struct xhci_hcd *xhci){ if (xhci_start(xhci)) { xhci_halt(xhci); return -ENODEV; } xhci->shared_hcd->state = HC_STATE_RUNNING;Quoted 8 lines
Alan Stern
Quoted 6 lines
What I can do: submit my patches as RFC, then there's a better basis for a discussion.
Quoted 1 line
Alan Stern
Heiner
Heiner
Quoted 10 lines · Heiner Kallweit
Quoted 9 lines · Jack Pham
Quoted 4 lines · Alan Stern
Quoted 3 lines · Heiner Kallweit
Quoted 2 lines · Alan Stern
Don't change
register_root_hub(). Just changexhci_plat_probe(); make it skip the second call tousb_add_hcd()if there are no USB-3 ports.I believe this had been attempted in the past, but it does not appear that patch was ever accepted:
Quoted 7 lines
Quoted 2 lines
I also found that xhci at several places relies on a proper
shared_hcd, even if there are no USB3 ports. Therefore maybe go with the less invasive original version of my patch?
The patch that Jack refers to, written by Tung Nguyen, does always create the shared_hcd. It simply avoids registering the shared_hcd when there are no USB-3 ports.
You should try that patch and see if it works on your system.
Alan Stern
Quoted 40 lines
Quoted 39 lines
Jack
Quoted 37 lines
Quoted 2 lines
This works on my system. However a consequence is that
xhci->shared_hcdis NULL.Why is that?
xhci->shared_hcddoesn't get set inusb_add_hcd(), so skipping that call shouldn't cause it to be NULL.Note: If you skip calling
usb_add_hcd(), you will also have to skip the corresponding call tousb_remove_hcd(). There may be a few more subtleties involved as well; like I said before, I'm not an expert on this driver. You should ask the xhci-hcd maintainer for advice.Alan Stern
Quoted 24 lines
There are a few places like the following in
xhci.cwhere
this may result in a NPE. Not knowing the USB subsystem in detail I can't say whether these places are in any relevant path.static int
xhci_run_finished(struct xhci_hcd *xhci){ if (xhci_start(xhci)) { xhci_halt(xhci); return -ENODEV; } xhci->shared_hcd->state = HC_STATE_RUNNING;Quoted 8 lines
Alan Stern
Quoted 6 lines
What I can do: submit my patches as RFC, then there's a better basis for a discussion.
Quoted 1 line
Alan Stern
Heiner
Heiner
Quoted 19 lines · Alan Stern
Quoted 10 lines · Heiner Kallweit
Quoted 9 lines · Jack Pham
Quoted 4 lines · Alan Stern
Quoted 3 lines · Heiner Kallweit
Quoted 2 lines · Alan Stern
Don't change
register_root_hub(). Just changexhci_plat_probe(); make it skip the second call tousb_add_hcd()if there are no USB-3 ports.I believe this had been attempted in the past, but it does not appear that patch was ever accepted:
Quoted 7 lines
Quoted 2 lines
I also found that xhci at several places relies on a proper
shared_hcd, even if there are no USB3 ports. Therefore maybe go with the less invasive original version of my patch?
Quoted 20 lines
The patch that Jack refers to, written by Tung Nguyen, does always create the
shared_hcd. It simply avoids registering theshared_hcdwhen there are no USB-3 ports.You should try that patch and see if it works on your system.
Alan Stern
Quoted 12 lines
Quoted 12 lines
Jack
Quoted 10 lines
Quoted 2 lines
This works on my system. However a consequence is that
xhci->shared_hcdis NULL.Why is that?
xhci->shared_hcddoesn't get set inusb_add_hcd(), so skipping that call shouldn't cause it to be NULL.Note: If you skip calling
usb_add_hcd(), you will also have to skip the corresponding call tousb_remove_hcd(). There may be a few more subtleties involved as well; like I said before, I'm not an expert on this driver. You should ask the xhci-hcd maintainer for advice.
I think we need to start supporting xHC conreollers with just one roothub. Only call usb_add_hcd() once in those cases.
Even prepare for special cases where xHCI only has usb3 ports (usb2 pins routed to a different host controller)
Currently driver reads port capabilities in:usb_add_hcd()
hcd->driver->reset ...-> xhci_gen_setup()
xhci_gen_setup()
xhci_init(hcd)
xhci_mem_init()
xhci_setup_port_arrays()Driver makes some assumptions based on if hcd is primary or not early in xhci_gen_setup(), and initializes values like hcd->speed = HCD_USB2;
Should be doable, changes needed in at least xhci_run(), xhci_stop(), xhci_resume(), xhci_suspend(), xhci_gen_setup() and probe.
-Mathias