Skip to contentSkip to conversation

common: usb-hub: Reset hub port before scanning

PATCH In review Shantur Rathore 5 participants 21 messages Dec 9, 2023 – Feb 7, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 common: usb-hub: Reset hub port before scanning

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

---

Changes in v3:
- Split up patches as seperate series

Changes in v2:
- As requested, added fix for regulator-always-on in RockPro64

 common/usb_hub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
common/usb_hub.c +3 -1
index 70279f301d..3fb7e14d10 100644
@@ -174,8 +174,10 @@ static void usb_hub_power_on(struct usb_hub_device *hub)
 
 	debug("enabling power on all ports\n");
 	for (i = 0; i < dev->maxchild; i++) {
+		usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
+		debug("Reset : port %d returns %lX\n", i + 1, dev->status);
 		usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
-		debug("port %d returns %lX\n", i + 1, dev->status);
+		debug("PowerOn : port %d returns %lX\n", i + 1, dev->status);
 	}
 
 #ifdef CONFIG_SANDBOX
Signature · 1 line
2.40.1
#1 lore raw

Hi Marex,

Quoted 54 lines · Shantur Rathore

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

---

Changes in v3:
- Split up patches as seperate series

Changes in v2:
- As requested, added fix for regulator-always-on in RockPro64

 common/usb_hub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
common/usb_hub.c +3 -2
index 70279f301d..3fb7e14d10 100644
@@ -174,8 +174,10 @@ static void usb_hub_power_on(struct usb_hub_device *hub)
 
        debug("enabling power on all ports\n");
        for (i = 0; i < dev->maxchild; i++) {
+               usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
+               debug("Reset : port %d returns %lX\n", i + 1, dev->status);
                usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
-               debug("port %d returns %lX\n", i + 1, dev->status);
+               debug("PowerOn : port %d returns %lX\n", i + 1, dev->status);
        }
 
 #ifdef CONFIG_SANDBOX
--
Quoted 2 lines

2.40.1

Do you think it is the right time to get this in early so it can be tested for a longer time before the next release ?

Kind regards,
Shantur

#2 lore raw
Quoted 64 lines · Shantur Rathore

Hi Marex,

Quoted 54 lines · Shantur Rathore

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

---

Changes in v3:
- Split up patches as seperate series

Changes in v2:
- As requested, added fix for regulator-always-on in RockPro64

 common/usb_hub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
common/usb_hub.c +3 -2
index 70279f301d..3fb7e14d10 100644
@@ -174,8 +174,10 @@ static void usb_hub_power_on(struct usb_hub_device *hub)
 
        debug("enabling power on all ports\n");
        for (i = 0; i < dev->maxchild; i++) {
+               usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
+               debug("Reset : port %d returns %lX\n", i + 1, dev->status);
                usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
-               debug("port %d returns %lX\n", i + 1, dev->status);
+               debug("PowerOn : port %d returns %lX\n", i + 1, dev->status);
        }
 
 #ifdef CONFIG_SANDBOX
--
Quoted 2 lines

2.40.1

Do you think it is the right time to get this in early so it can be tested for a longer time before the next release ?

Quoted 2 lines

Kind regards,
Shantur

Ping.

#3 lore raw
In reply to Shantur Rathore
Quoted 55 lines · Shantur Rathore

Hi Marex,

Quoted 52 lines · Shantur Rathore

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

---

Changes in v3:
- Split up patches as seperate series

Changes in v2:
- As requested, added fix for regulator-always-on in RockPro64

  common/usb_hub.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
common/usb_hub.c +3 -1
index 70279f301d..3fb7e14d10 100644
@@ -174,8 +174,10 @@ static void usb_hub_power_on(struct usb_hub_device *hub)
 
         debug("enabling power on all ports\n");
         for (i = 0; i < dev->maxchild; i++) {
+               usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
+               debug("Reset : port %d returns %lX\n", i + 1, dev->status);
                 usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
-               debug("port %d returns %lX\n", i + 1, dev->status);
+               debug("PowerOn : port %d returns %lX\n", i + 1, dev->status);
         }
 
Quoted 7 lines
Quoted 4 lines
common/usb_hub.c +0 -1
  #ifdef CONFIG_SANDBOX
--

2.40.1

Do you think it is the right time to get this in early so it can be tested for a longer time before the next release ?

Yes, I think so, sorry for the delay.

I asked Tom to pick it directly and provided RB .

#4 lore raw
Quoted 65 lines · Marek Vasut
Quoted 55 lines · Shantur Rathore

Hi Marex,

Quoted 52 lines · Shantur Rathore

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

---

Changes in v3:
- Split up patches as seperate series

Changes in v2:
- As requested, added fix for regulator-always-on in RockPro64

  common/usb_hub.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
common/usb_hub.c +3 -1
index 70279f301d..3fb7e14d10 100644
@@ -174,8 +174,10 @@ static void usb_hub_power_on(struct usb_hub_device *hub)
 
         debug("enabling power on all ports\n");
         for (i = 0; i < dev->maxchild; i++) {
+               usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
+               debug("Reset : port %d returns %lX\n", i + 1, dev->status);
                 usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
-               debug("port %d returns %lX\n", i + 1, dev->status);
+               debug("PowerOn : port %d returns %lX\n", i + 1, dev->status);
         }
 
Quoted 7 lines
Quoted 4 lines
common/usb_hub.c +0 -1
  #ifdef CONFIG_SANDBOX
--

2.40.1

Do you think it is the right time to get this in early so it can be tested for a longer time before the next release ?

Quoted 3 lines

Yes, I think so, sorry for the delay.

I asked Tom to pick it directly and provided RB .

Thanks Marek,

Just realised Tom isn't included in this chain.

@Tom Rini - Can I request you to please merge this earlier in this release.

Kind regards,
Shantur

Reviewed-by on v3 1/1
#5 lore raw
In reply to Shantur Rathore
Quoted 16 lines · Shantur Rathore

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Quoted 8 lines

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

Tom, can you please pick this one up directly ?

#6 lore raw
In reply to Shantur Rathore
Quoted 9 lines · Shantur Rathore

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#7 lore raw
In reply to Shantur Rathore

On Sat, 9 Dec 2023 18:10:56 +0000
Shantur Rathore <[email protected]> wrote:

Hi,

Quoted 16 lines

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Quoted 6 lines

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

so this broke USB operation on some Allwinner boards. The ports still enumerate correctly, but no devices are detected. With mainline (containing this patch), and a USB stick connected:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 1 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

With this patch here reverted:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found

I have no clue why this happens, there is no discrete hub anywhere in this setup, so I guess the code runs for the root hub here?
I am attaching a log with DEBUG enabled for common/usb_hub.c, for both cases.

Any clues, debug suggestions, or even a fix are warmly welcome.

Cheers,
Andre

Quoted 17 lines

---

Changes in v3:
- Split up patches as seperate series

Changes in v2:
- As requested, added fix for regulator-always-on in RockPro64

 common/usb_hub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
common/usb_hub.c +0 -0
index 70279f301d..3fb7e14d10 100644
@@ -174,8 +174,10 @@ static void usb_hub_power_on(struct usb_hub_device *hub)
 

common/usb_hub.c static void usb_hub_power_on(struct usb_hub_device *hub) · line 183

Quoted 10 lines
common/usb_hub.c +3 -1
 	debug("enabling power on all ports\n");
 	for (i = 0; i < dev->maxchild; i++) {
+		usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
+		debug("Reset : port %d returns %lX\n", i + 1, dev->status);
 		usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
-		debug("port %d returns %lX\n", i + 1, dev->status);
+		debug("PowerOn : port %d returns %lX\n", i + 1, dev->status);
 	}
 
 #ifdef CONFIG_SANDBOX

U-Boot 2024.04-rc1 (Jan 30 2024 - 13:32:13 +0000) Allwinner Technology

CPU:   Allwinner H616 (SUN50I)
Model: OrangePi Zero3
DRAM:  4 GiB
Core:  56 devices, 24 uclasses, devicetree: separate
WDT:   Not starting watchdog@30090a0
MMC:   mmc@4020000: 0
Loading Environment from FAT... Unable to read "uboot.env" from mmc0:1... 
In:    serial@5000000
Out:   serial@5000000
Err:   serial@5000000
Net:   eth0: ethernet@5020000

starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... usb_hub_post_probe 1 ports detected
ganged power switching
standalone hub
global over-current protection
Single TT
TT requires at most 8 FS bit times (666 ns)
power on to power good time: 20ms
hub controller current requirement: 0mA
port 1 is removable
get_hub_status returned status 1, change 1
local power source is lost (inactive)
no over-current condition exists
enabling power on all ports
port 1 returns 0
pgood_delay=20ms
devnum=1 poweron: query_delay=100 connect_timeout=1100 Port 1 Status 500 Change 0
<repeated 469 times>
Port 1 Status 100 Change 0
devnum=1 port=1: timeout
1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found
Hit any key to stop autoboot: 2

U-Boot 2024.04-rc1 (Jan 30 2024 - 13:24:42 +0000) Allwinner Technology

CPU:   Allwinner H616 (SUN50I)
Model: OrangePi Zero3
DRAM:  4 GiB
Core:  56 devices, 24 uclasses, devicetree: separate
WDT:   Not starting watchdog@30090a0
MMC:   mmc@4020000: 0
Loading Environment from FAT... Unable to read "uboot.env" from mmc0:1... 
In:    serial@5000000
Out:   serial@5000000
Err:   serial@5000000
Net:   eth0: ethernet@5020000

starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... usb_hub_post_probe 1 ports detected
ganged power switching
standalone hub
global over-current protection
Single TT
TT requires at most 8 FS bit times (666 ns)
power on to power good time: 20ms
hub controller current requirement: 0mA
port 1 is removable
get_hub_status returned status 1, change 1
local power source is lost (inactive)
no over-current condition exists
enabling power on all ports
Reset : port 1 returns 0
PowerOn : port 1 returns 0
pgood_delay=20ms
devnum=1 poweron: query_delay=100 connect_timeout=1100 Port 1 Status 500 Change 11
port 1 reset change
devnum=1 port=1: USB dev found
portstatus 500, change 1, 480 Mb/s usb_disconnect(&hub->children[port]);
1 USB Device(s) found
scanning bus usb@5200400 for devices... usb_hub_post_probe 1 ports detected
ganged power switching
standalone hub
no over-current protection
power on to power good time: 4ms
hub controller current requirement: 0mA
port 1 is removable
get_hub_status returned status 0, change 0
local power source is good
no over-current condition exists
enabling power on all ports
Reset : port 1 returns 0
PowerOn : port 1 returns 0
pgood_delay=4ms
devnum=1 poweron: query_delay=100 connect_timeout=1100 Port 1 Status 100 Change 0
<repeated 411 times>
Port 1 Status 100 Change 0
devnum=1 port=1: timeout
1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found
Hit any key to stop autoboot: 2

#8 lore raw

Hi Andre,

Quoted 47 lines · Andre Przywara

On Sat, 9 Dec 2023 18:10:56 +0000
Shantur Rathore <[email protected]> wrote:

Hi,

Quoted 16 lines

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Quoted 6 lines

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

so this broke USB operation on some Allwinner boards. The ports still enumerate correctly, but no devices are detected. With mainline (containing this patch), and a USB stick connected:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 1 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

With this patch here reverted:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found

Quoted 7 lines

I have no clue why this happens, there is no discrete hub anywhere in this setup, so I guess the code runs for the root hub here?
I am attaching a log with DEBUG enabled for common/usb_hub.c, for both cases.

Any clues, debug suggestions, or even a fix are warmly welcome.

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

Regards,
Shantur

#9 lore raw
Quoted 55 lines · Shantur Rathore

Hi Andre,

Quoted 52 lines · Andre Przywara

On Sat, 9 Dec 2023 18:10:56 +0000
Shantur Rathore <[email protected]> wrote:

Hi,

Quoted 16 lines

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Quoted 6 lines

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

so this broke USB operation on some Allwinner boards. The ports still enumerate correctly, but no devices are detected. With mainline (containing this patch), and a USB stick connected:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 1 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

With this patch here reverted:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found

I have no clue why this happens, there is no discrete hub anywhere in this setup, so I guess the code runs for the root hub here?
I am attaching a log with DEBUG enabled for common/usb_hub.c, for both cases.

Quoted 5 lines
Quoted 2 lines

Any clues, debug suggestions, or even a fix are warmly welcome.

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

I don't think this is device specific, see the logs. Hardware from Andre worked before this patch, does not work after this patch. There seem to be no connection event with this patch.

#10 lore raw
Quoted 60 lines · Marek Vasut
Quoted 58 lines · Shantur Rathore

Hi Andre,

Quoted 54 lines · Andre Przywara

On Sat, 9 Dec 2023 18:10:56 +0000
Shantur Rathore <[email protected]> wrote:

Hi,

Quoted 16 lines

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Quoted 6 lines

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

so this broke USB operation on some Allwinner boards. The ports still enumerate correctly, but no devices are detected. With mainline (containing this patch), and a USB stick connected:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 1 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

With this patch here reverted:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found

I have no clue why this happens, there is no discrete hub anywhere in this setup, so I guess the code runs for the root hub here?
I am attaching a log with DEBUG enabled for common/usb_hub.c, for both cases.

Any clues, debug suggestions, or even a fix are warmly welcome.

Quoted 6 lines
Quoted 2 lines

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

I don't think this is device specific, see the logs. Hardware from Andre worked before this patch, does not work after this patch. There seem to be no connection event with this patch.

I am trying to evaluate if this is happening due to a USB 2.0 device. I see that the host is USB 2.0. I have tested this on my RK3399 board on both USB 2.0 and USB 3.0 ports.
If this is not behaving on USB 2.0 ports then I can put a condition for this to happen
only on USB 3.0 ports.

#11 lore raw
Quoted 68 lines · Shantur Rathore
Quoted 60 lines · Marek Vasut
Quoted 58 lines · Shantur Rathore

Hi Andre,

Quoted 54 lines · Andre Przywara

On Sat, 9 Dec 2023 18:10:56 +0000
Shantur Rathore <[email protected]> wrote:

Hi,

Quoted 16 lines

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Quoted 6 lines

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

so this broke USB operation on some Allwinner boards. The ports still enumerate correctly, but no devices are detected. With mainline (containing this patch), and a USB stick connected:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 1 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

With this patch here reverted:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found

I have no clue why this happens, there is no discrete hub anywhere in this setup, so I guess the code runs for the root hub here?
I am attaching a log with DEBUG enabled for common/usb_hub.c, for both cases.

Any clues, debug suggestions, or even a fix are warmly welcome.

Quoted 6 lines
Quoted 2 lines

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

I don't think this is device specific, see the logs. Hardware from Andre worked before this patch, does not work after this patch. There seem to be no connection event with this patch.

Quoted 6 lines

I am trying to evaluate if this is happening due to a USB 2.0 device. I see that the host is USB 2.0. I have tested this on my RK3399 board on both USB 2.0 and USB 3.0 ports.
If this is not behaving on USB 2.0 ports then I can put a condition for this to happen
only on USB 3.0 ports.

Doesn't Linux perform this reset for all ports unconditionally ?

#12 lore raw
Quoted 70 lines · Marek Vasut
Quoted 68 lines · Shantur Rathore
Quoted 66 lines · Marek Vasut
Quoted 55 lines · Shantur Rathore

Hi Andre,

Quoted 52 lines · Andre Przywara

On Sat, 9 Dec 2023 18:10:56 +0000
Shantur Rathore <[email protected]> wrote:

Hi,

Quoted 16 lines

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Quoted 6 lines

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

so this broke USB operation on some Allwinner boards. The ports still enumerate correctly, but no devices are detected. With mainline (containing this patch), and a USB stick connected:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 1 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

With this patch here reverted:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found

I have no clue why this happens, there is no discrete hub anywhere in this setup, so I guess the code runs for the root hub here?
I am attaching a log with DEBUG enabled for common/usb_hub.c, for both cases.

Quoted 5 lines
Quoted 2 lines

Any clues, debug suggestions, or even a fix are warmly welcome.

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

I don't think this is device specific, see the logs. Hardware from Andre worked before this patch, does not work after this patch. There seem to be no connection event with this patch.

Quoted 8 lines
Quoted 6 lines

I am trying to evaluate if this is happening due to a USB 2.0 device. I see that the host is USB 2.0. I have tested this on my RK3399 board on both USB 2.0 and USB 3.0 ports.
If this is not behaving on USB 2.0 ports then I can put a condition for this to happen
only on USB 3.0 ports.

Doesn't Linux perform this reset for all ports unconditionally ?

Looks like it doesn't
https://github.com/torvalds/linux/blob/master/drivers/usb/core/hub.c#L2841

#13 lore raw
In reply to Shantur Rathore

On Thu, 1 Feb 2024 09:39:54 +0000
Shantur Rathore <[email protected]> wrote:

Hi Shantur,

Quoted 53 lines · Andre Przywara
Quoted 52 lines

On Sat, 9 Dec 2023 18:10:56 +0000
Shantur Rathore <[email protected]> wrote:

Hi,

Quoted 16 lines

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Quoted 6 lines

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

so this broke USB operation on some Allwinner boards. The ports still enumerate correctly, but no devices are detected. With mainline (containing this patch), and a USB stick connected:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 1 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

With this patch here reverted:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found

I have no clue why this happens, there is no discrete hub anywhere in this setup, so I guess the code runs for the root hub here?
I am attaching a log with DEBUG enabled for common/usb_hub.c, for both cases.

Quoted 5 lines
Quoted 2 lines

Any clues, debug suggestions, or even a fix are warmly welcome.

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

Yes, this was some USB 2.0 memory stick, on an USB 2.0 port. Most sunxi boards only have USB 2.0, but there is one SoC with USB 3.0, I will try some combinations later tonight.

Thanks,
Andre

#14 lore raw

Hi Andre,

Quoted 65 lines · Andre Przywara

On Thu, 1 Feb 2024 09:39:54 +0000
Shantur Rathore <[email protected]> wrote:

Hi Shantur,

Quoted 53 lines · Andre Przywara
Quoted 52 lines

On Sat, 9 Dec 2023 18:10:56 +0000
Shantur Rathore <[email protected]> wrote:

Hi,

Quoted 16 lines

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Quoted 6 lines

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

so this broke USB operation on some Allwinner boards. The ports still enumerate correctly, but no devices are detected. With mainline (containing this patch), and a USB stick connected:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 1 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

With this patch here reverted:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found

I have no clue why this happens, there is no discrete hub anywhere in this setup, so I guess the code runs for the root hub here?
I am attaching a log with DEBUG enabled for common/usb_hub.c, for both cases.

Quoted 5 lines
Quoted 2 lines

Any clues, debug suggestions, or even a fix are warmly welcome.

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

Quoted 6 lines

Yes, this was some USB 2.0 memory stick, on an USB 2.0 port. Most sunxi boards only have USB 2.0, but there is one SoC with USB 3.0, I will try some combinations later tonight.

Thanks,
Andre

That would be awesome.
We need to test

USB 3.0 and 2.0 ports with USB 3.0 and 2.0 drives.

Once you have tested it, can you please try the patch below

        debug("enabling power on all ports\n");
        for (i = 0; i < dev->maxchild; i++) {
-               usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
-               debug("Reset : port %d returns %lX\n", i + 1, dev->status);
+               if (usb_hub_is_superspeed(hub)) {

+ usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
+ debug("Reset : port %d returns %lX\n", i + 1,
dev->status);
+ }

                usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
                debug("PowerOn : port %d returns %lX\n", i + 1, dev->status);
        }

Thanks

Tested-by
#15 lore raw

On Thu, 1 Feb 2024 18:35:28 +0000
Shantur Rathore <[email protected]> wrote:

Hi Shantur,

Quoted 72 lines

Hi Andre,

Quoted 69 lines · Andre Przywara

On Thu, 1 Feb 2024 09:39:54 +0000
Shantur Rathore <[email protected]> wrote:

Hi Shantur,

Quoted 53 lines · Andre Przywara
Quoted 52 lines

On Sat, 9 Dec 2023 18:10:56 +0000
Shantur Rathore <[email protected]> wrote:

Hi,

Quoted 16 lines

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Quoted 6 lines

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

so this broke USB operation on some Allwinner boards. The ports still enumerate correctly, but no devices are detected. With mainline (containing this patch), and a USB stick connected:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 1 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

With this patch here reverted:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found

I have no clue why this happens, there is no discrete hub anywhere in this setup, so I guess the code runs for the root hub here?
I am attaching a log with DEBUG enabled for common/usb_hub.c, for both cases.

Quoted 5 lines
Quoted 2 lines

Any clues, debug suggestions, or even a fix are warmly welcome.

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

Yes, this was some USB 2.0 memory stick, on an USB 2.0 port. Most sunxi boards only have USB 2.0, but there is one SoC with USB 3.0, I will try some combinations later tonight.

Quoted 7 lines
Quoted 2 lines

Thanks,
Andre

That would be awesome.
We need to test

USB 3.0 and 2.0 ports with USB 3.0 and 2.0 drives.

So I had some mixed and apparently inconsistent results:
- On the Pine-H64 (H6 SoC with USB 3.0 + USB 2.0) it worked with mainline, but only after I applied some pending sunxi USB PHY regulator patches. This is an unrelated issue, those patches are needed to enable USB 3.0 support on that board (shared regulator conflict).
I tested a USB 2.0 and a USB 3.0 drive in both kind of slots, with and without the patch.
- On the OrangePi Zero 3 (H616 SoC with USB 2.0 only), the USB 3.0 drive would not work with mainline. A USB 2.0 drive was fine. Applying your patch below fixed that problem, now both drives worked.
- On the OrangePi Zero (H3 with USB 2.0 only), it worked with and without the patch below, with both the USB 2.0 and USB 3.0 drive.
- On the BananaPi M64 (A64 with USB 2.0 only and an onboard USB 2.0 hub) it also worked in all cases: with and without the patch, USB 2.0 and USB 3.0 drive.

So the good news is: with the patch below it worked in all cases, with all drives in all slots, on all boards. With current mainline some drives don't work at least on the board with the H616 SoC.

I cannot really say if that makes sense, and the results above maybe more per board than per SoC (different VBUS supply), but would pragmatically tend to use the patch, feel free to add my Tested-by:
when sending:

Just one tiny thing:

Review

Quoted 7 lines

Once you have tested it, can you please try the patch below

        debug("enabling power on all ports\n");
        for (i = 0; i < dev->maxchild; i++) {
(quoted diff) +1 -2
-               usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
-               debug("Reset : port %d returns %lX\n", i + 1, dev->status);
+               if (usb_hub_is_superspeed(hub)) {

this must be: usb_hub_is_superspeed(dev)

So many thanks for that patch, that seem to have fixed it for me - even though I don't understand why. But then again I only have superficial USB knowledge.

Cheers,
Andre

Quoted 10 lines
(quoted diff) +2 -0
+                       usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
+                       debug("Reset : port %d returns %lX\n", i + 1,

dev->status);
+ }

                usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
                debug("PowerOn : port %d returns %lX\n", i + 1, dev->status);
        }

Thanks

#16 lore raw

Hello Andre,

Quoted 66 lines · Andre Przywara
Quoted 56 lines · On Thu, 1 Feb 2024 18:35:28 +0000 Shantur Rathore <[email protected]> wrote:
Quoted 55 lines · Andre Przywara
Quoted 53 lines · On Thu, 1 Feb 2024 09:39:54 +0000 Shantur Rathore <[email protected]> wrote:
Quoted 42 lines · Andre Przywara
Quoted 16 lines · On Sat, 9 Dec 2023 18:10:56 +0000 Shantur Rathore <[email protected]> wrote:

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Quoted 6 lines

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

so this broke USB operation on some Allwinner boards. The ports still enumerate correctly, but no devices are detected. With mainline (containing this patch), and a USB stick connected:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 1 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

With this patch here reverted:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found

Quoted 7 lines

I have no clue why this happens, there is no discrete hub anywhere in this setup, so I guess the code runs for the root hub here?
I am attaching a log with DEBUG enabled for common/usb_hub.c, for both cases.

Any clues, debug suggestions, or even a fix are warmly welcome.

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

Quoted 8 lines
Quoted 3 lines

Yes, this was some USB 2.0 memory stick, on an USB 2.0 port. Most sunxi boards only have USB 2.0, but there is one SoC with USB 3.0, I will try some combinations later tonight.

That would be awesome.
We need to test

USB 3.0 and 2.0 ports with USB 3.0 and 2.0 drives.

Quoted 11 lines

So I had some mixed and apparently inconsistent results:
- On the Pine-H64 (H6 SoC with USB 3.0 + USB 2.0) it worked with mainline, but only after I applied some pending sunxi USB PHY regulator patches. This is an unrelated issue, those patches are needed to enable USB 3.0 support on that board (shared regulator conflict).
I tested a USB 2.0 and a USB 3.0 drive in both kind of slots, with and without the patch.
- On the OrangePi Zero 3 (H616 SoC with USB 2.0 only), the USB 3.0 drive would not work with mainline. A USB 2.0 drive was fine. Applying your patch below fixed that problem, now both drives worked.

Let me interject, please...

Huh, this (mih)behavior with the tested OrangePi Zero 3 is really strange. As we know, a USB 3.0 drive plugged into a USB 2.0 port should behave just like a USB 2.0 drive, using the separate set of pins inside the connector.

If possible, performing some additional testing with another USB 3.0 drive would be quite interesting. Could it be that something is wrong with the USB 2.0 receptacle on your OrangePi Zero 3, mechanically or electrically?

Quoted 43 lines

- On the OrangePi Zero (H3 with USB 2.0 only), it worked with and without the patch below, with both the USB 2.0 and USB 3.0 drive.
- On the BananaPi M64 (A64 with USB 2.0 only and an onboard USB 2.0 hub) it also worked in all cases: with and without the patch, USB 2.0 and USB 3.0 drive.

So the good news is: with the patch below it worked in all cases, with all drives in all slots, on all boards. With current mainline some drives don't work at least on the board with the H616 SoC.

I cannot really say if that makes sense, and the results above maybe more per board than per SoC (different VBUS supply), but would pragmatically tend to use the patch, feel free to add my Tested-by:
when sending:

Just one tiny thing:

Quoted 8 lines

Once you have tested it, can you please try the patch below

        debug("enabling power on all ports\n");
        for (i = 0; i < dev->maxchild; i++) {
(quoted diff) +0 -2
-               usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
-               debug("Reset : port %d returns %lX\n", i + 1, 

dev->status);
+ if (usb_hub_is_superspeed(hub)) {

this must be: usb_hub_is_superspeed(dev)

So many thanks for that patch, that seem to have fixed it for me - even though I don't understand why. But then again I only have superficial USB knowledge.

Quoted 9 lines

+ usb_set_port_feature(dev, i + 1,
USB_PORT_FEAT_RESET);
+ debug("Reset : port %d returns %lX\n", i + 1,
dev->status);
+ }
usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER); debug("PowerOn : port %d returns %lX\n", i + 1,

dev->status);
        }
#17 lore raw

On Fri, 02 Feb 2024 03:35:24 +0100
Dragan Simic <[email protected]> wrote:

Hi,

Quoted 83 lines

Hello Andre,

Quoted 68 lines · Andre Przywara
Quoted 57 lines · On Thu, 1 Feb 2024 18:35:28 +0000 Shantur Rathore <[email protected]> wrote:
Quoted 55 lines · Andre Przywara
Quoted 53 lines · On Thu, 1 Feb 2024 09:39:54 +0000 Shantur Rathore <[email protected]> wrote:
Quoted 42 lines · Andre Przywara
Quoted 16 lines · On Sat, 9 Dec 2023 18:10:56 +0000 Shantur Rathore <[email protected]> wrote:

Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control.

For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state.

With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off.

Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected.

Quoted 6 lines

Tested working after this patch:
1. AMicro AM8180 based NVME to USB Adapter
2. Kingston DataTraveler 3.0
3. GenesysLogic USB3.0 Hub

The drives were tested while connected directly and via the hub.

so this broke USB operation on some Allwinner boards. The ports still enumerate correctly, but no devices are detected. With mainline (containing this patch), and a USB stick connected:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 1 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

With this patch here reverted:
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found scanning bus usb@5200400 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found

Quoted 7 lines

I have no clue why this happens, there is no discrete hub anywhere in this setup, so I guess the code runs for the root hub here?
I am attaching a log with DEBUG enabled for common/usb_hub.c, for both cases.

Any clues, debug suggestions, or even a fix are warmly welcome.

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

Quoted 8 lines
Quoted 3 lines

Yes, this was some USB 2.0 memory stick, on an USB 2.0 port. Most sunxi boards only have USB 2.0, but there is one SoC with USB 3.0, I will try some combinations later tonight.

That would be awesome.
We need to test

USB 3.0 and 2.0 ports with USB 3.0 and 2.0 drives.

Quoted 11 lines

So I had some mixed and apparently inconsistent results:
- On the Pine-H64 (H6 SoC with USB 3.0 + USB 2.0) it worked with mainline, but only after I applied some pending sunxi USB PHY regulator patches. This is an unrelated issue, those patches are needed to enable USB 3.0 support on that board (shared regulator conflict).
I tested a USB 2.0 and a USB 3.0 drive in both kind of slots, with and without the patch.
- On the OrangePi Zero 3 (H616 SoC with USB 2.0 only), the USB 3.0 drive would not work with mainline. A USB 2.0 drive was fine. Applying your patch below fixed that problem, now both drives worked.

Quoted 6 lines

Let me interject, please...

Huh, this (mih)behavior with the tested OrangePi Zero 3 is really strange. As we know, a USB 3.0 drive plugged into a USB 2.0 port should behave just like a USB 2.0 drive, using the separate set of pins inside the connector.

Yes, I found this odd as well, hence saying inconsistent above.

Quoted 4 lines

If possible, performing some additional testing with another USB 3.0 drive would be quite interesting. Could it be that something is wrong with the USB 2.0 receptacle on your OrangePi Zero 3, mechanically or electrically?

The receptacle on the OPi Zero3 is a standard USB 2.0 Type-A socket, with clearly only 4 pins. The USB 3.0 stick in question has all 9 pins. So indeed there should be little difference to a USB 2.0 stick. And I just tested the same board with some other (cheap) USB 2.0 stick:
it's the same situation as with the USB 3.0 drive: it does not work with mainline, but works with the patch below. So the USB 3.0 device here might be a red herring, and it's actually more up to an individual device? Or maybe it's like: *Some* USB devices (in Hi-Speed mode?) do not like it when their port is reset before it's powered on? And the root hub implementation also plays a role, which is why we only got reports about Allwinner boards?
Also I think Marek said that Linux does the reset only when using SuperSpeed (hence the patch below), so maybe it's something in the USB 3.0 spec that changed the requirements?

Cheers,
Andre

Quoted 43 lines
Quoted 43 lines

- On the OrangePi Zero (H3 with USB 2.0 only), it worked with and without the patch below, with both the USB 2.0 and USB 3.0 drive.
- On the BananaPi M64 (A64 with USB 2.0 only and an onboard USB 2.0 hub) it also worked in all cases: with and without the patch, USB 2.0 and USB 3.0 drive.

So the good news is: with the patch below it worked in all cases, with all drives in all slots, on all boards. With current mainline some drives don't work at least on the board with the H616 SoC.

I cannot really say if that makes sense, and the results above maybe more per board than per SoC (different VBUS supply), but would pragmatically tend to use the patch, feel free to add my Tested-by:
when sending:

Just one tiny thing:

Quoted 8 lines

Once you have tested it, can you please try the patch below

        debug("enabling power on all ports\n");
        for (i = 0; i < dev->maxchild; i++) {
(quoted diff) +0 -2
-               usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
-               debug("Reset : port %d returns %lX\n", i + 1, 

dev->status);
+ if (usb_hub_is_superspeed(hub)) {

this must be: usb_hub_is_superspeed(dev)

So many thanks for that patch, that seem to have fixed it for me - even though I don't understand why. But then again I only have superficial USB knowledge.

Quoted 9 lines

+ usb_set_port_feature(dev, i + 1,
USB_PORT_FEAT_RESET);
+ debug("Reset : port %d returns %lX\n", i + 1,
dev->status);
+ }
usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER); debug("PowerOn : port %d returns %lX\n", i + 1,

dev->status);
        }  
#18 lore raw

Hello Andre and Shantur,

Quoted 40 lines · Andre Przywara
Quoted 30 lines · On Fri, 02 Feb 2024 03:35:24 +0100 Dragan Simic <[email protected]> wrote:
Quoted 17 lines · Andre Przywara
Quoted 6 lines · On Thu, 1 Feb 2024 18:35:28 +0000 Shantur Rathore <[email protected]> wrote:
Quoted 4 lines · Andre Przywara
Quoted 2 lines · On Thu, 1 Feb 2024 09:39:54 +0000 Shantur Rathore <[email protected]> wrote:

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

Quoted 8 lines
Quoted 3 lines

Yes, this was some USB 2.0 memory stick, on an USB 2.0 port. Most sunxi boards only have USB 2.0, but there is one SoC with USB 3.0, I will try some combinations later tonight.

That would be awesome.
We need to test

USB 3.0 and 2.0 ports with USB 3.0 and 2.0 drives.

Quoted 11 lines

So I had some mixed and apparently inconsistent results:
- On the Pine-H64 (H6 SoC with USB 3.0 + USB 2.0) it worked with mainline, but only after I applied some pending sunxi USB PHY regulator patches. This is an unrelated issue, those patches are needed to enable USB 3.0 support on that board (shared regulator conflict).
I tested a USB 2.0 and a USB 3.0 drive in both kind of slots, with and without the patch.
- On the OrangePi Zero 3 (H616 SoC with USB 2.0 only), the USB 3.0 drive would not work with mainline. A USB 2.0 drive was fine. Applying your patch below fixed that problem, now both drives worked.

Quoted 6 lines

Let me interject, please...

Huh, this (mih)behavior with the tested OrangePi Zero 3 is really strange. As we know, a USB 3.0 drive plugged into a USB 2.0 port should behave just like a USB 2.0 drive, using the separate set of pins inside the connector.

Yes, I found this odd as well, hence saying inconsistent above.

Quoted 8 lines
Quoted 4 lines

If possible, performing some additional testing with another USB 3.0 drive would be quite interesting. Could it be that something is wrong with the USB 2.0 receptacle on your OrangePi Zero 3, mechanically or electrically?

The receptacle on the OPi Zero3 is a standard USB 2.0 Type-A socket, with clearly only 4 pins. The USB 3.0 stick in question has all 9 pins. So indeed there should be little difference to a USB 2.0 stick.

Ah, sorry, I wasn't clear enough... I actually had some possible damage to the Zero 3's USB 2.0 receptacle in mind, or some results of the regular wear and tear, which could've possibly caused some intermittent issues.

Quoted 8 lines

And I just tested the same board with some other (cheap) USB 2.0 stick:
it's the same situation as with the USB 3.0 drive: it does not work with mainline, but works with the patch below. So the USB 3.0 device here might be a red herring, and it's actually more up to an individual device? Or maybe it's like: *Some* USB devices (in Hi-Speed mode?) do not like it when their port is reset before it's powered on? And the root hub implementation also plays a role, which is why we only got reports about Allwinner boards?

Hmm, we've got quite a few unknowns there. Thank you for performing the additional testing!

Quoted 3 lines

Also I think Marek said that Linux does the reset only when using SuperSpeed (hence the patch below), so maybe it's something in the USB 3.0 spec that changed the requirements?

I just spent about an hour and a half going through the USB 2.0 and USB 3.0 specifications. From what I understood, resetting a USB 3.0 port should be required when a USB device transitions between different states, such as when it resumes from suspend, but maybe not necessarily upon the initial device attachment.

Though, the Linux kernel USB driver seems to be doing additional USB 3.0 port resets upon the initial USB device attachment, presumably to ensure proper state of the USB 3.0 hub port and proper USB mode negotiation.

Here are the links to a couple of screenshots from the USB 3.0 specification, for future reference: https://i.imgur.com/cMaBdq2.png
and https://i.imgur.com/PDciRjP.png .

Moreover, such USB port resets don't seem to exist for USB 2.0 hubs, or at least I didn't see them in the USB 2.0 specification. The resets seem to be added to the USB 3.0 specification as part of the port and device mode negotiation.

Thus, the additional fix that Shantur sent, available below, looks to be the right way to handle it. Thus, Shantur, AFAICT it's fine to submit this fix as a separate "Fixes" patch.

Quoted 43 lines
Quoted 43 lines
Quoted 43 lines

- On the OrangePi Zero (H3 with USB 2.0 only), it worked with and without the patch below, with both the USB 2.0 and USB 3.0 drive.
- On the BananaPi M64 (A64 with USB 2.0 only and an onboard USB 2.0 hub) it also worked in all cases: with and without the patch, USB 2.0 and USB 3.0 drive.

So the good news is: with the patch below it worked in all cases, with all drives in all slots, on all boards. With current mainline some drives don't work at least on the board with the H616 SoC.

I cannot really say if that makes sense, and the results above maybe more per board than per SoC (different VBUS supply), but would pragmatically tend to use the patch, feel free to add my Tested-by:
when sending:

Just one tiny thing:

Quoted 8 lines

Once you have tested it, can you please try the patch below

        debug("enabling power on all ports\n");
        for (i = 0; i < dev->maxchild; i++) {
(quoted diff) +0 -2
-               usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
-               debug("Reset : port %d returns %lX\n", i + 1,

dev->status);
+ if (usb_hub_is_superspeed(hub)) {

this must be: usb_hub_is_superspeed(dev)

So many thanks for that patch, that seem to have fixed it for me - even though I don't understand why. But then again I only have superficial USB knowledge.

Quoted 9 lines

+ usb_set_port_feature(dev, i + 1,
USB_PORT_FEAT_RESET);
+ debug("Reset : port %d returns %lX\n", i + 1,
dev->status);
+ }
usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER); debug("PowerOn : port %d returns %lX\n", i + 1,

dev->status);
        }
#19 lore raw

Hi Dragan and Andre,

Quoted 95 lines · Dragan Simic

Hello Andre and Shantur,

Quoted 41 lines · Andre Przywara
Quoted 30 lines · On Fri, 02 Feb 2024 03:35:24 +0100 Dragan Simic <[email protected]> wrote:
Quoted 17 lines · Andre Przywara
Quoted 6 lines · On Thu, 1 Feb 2024 18:35:28 +0000 Shantur Rathore <[email protected]> wrote:
Quoted 4 lines · Andre Przywara
Quoted 2 lines · On Thu, 1 Feb 2024 09:39:54 +0000 Shantur Rathore <[email protected]> wrote:

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

Quoted 8 lines
Quoted 3 lines

Yes, this was some USB 2.0 memory stick, on an USB 2.0 port. Most sunxi boards only have USB 2.0, but there is one SoC with USB 3.0, I will try some combinations later tonight.

That would be awesome.
We need to test

USB 3.0 and 2.0 ports with USB 3.0 and 2.0 drives.

Quoted 11 lines

So I had some mixed and apparently inconsistent results:
- On the Pine-H64 (H6 SoC with USB 3.0 + USB 2.0) it worked with mainline, but only after I applied some pending sunxi USB PHY regulator patches. This is an unrelated issue, those patches are needed to enable USB 3.0 support on that board (shared regulator conflict).
I tested a USB 2.0 and a USB 3.0 drive in both kind of slots, with and without the patch.
- On the OrangePi Zero 3 (H616 SoC with USB 2.0 only), the USB 3.0 drive would not work with mainline. A USB 2.0 drive was fine. Applying your patch below fixed that problem, now both drives worked.

Quoted 6 lines

Let me interject, please...

Huh, this (mih)behavior with the tested OrangePi Zero 3 is really strange. As we know, a USB 3.0 drive plugged into a USB 2.0 port should behave just like a USB 2.0 drive, using the separate set of pins inside the connector.

Yes, I found this odd as well, hence saying inconsistent above.

Quoted 8 lines
Quoted 4 lines

If possible, performing some additional testing with another USB 3.0 drive would be quite interesting. Could it be that something is wrong with the USB 2.0 receptacle on your OrangePi Zero 3, mechanically or electrically?

The receptacle on the OPi Zero3 is a standard USB 2.0 Type-A socket, with clearly only 4 pins. The USB 3.0 stick in question has all 9 pins. So indeed there should be little difference to a USB 2.0 stick.

Ah, sorry, I wasn't clear enough... I actually had some possible damage to the Zero 3's USB 2.0 receptacle in mind, or some results of the regular wear and tear, which could've possibly caused some intermittent issues.

Quoted 4 lines

And I just tested the same board with some other (cheap) USB 2.0 stick:
it's the same situation as with the USB 3.0 drive: it does not work with
mainline, but works with the patch below. So the USB 3.0 device here

Quoted 8 lines

might
be a red herring, and it's actually more up to an individual device? Or maybe it's like: *Some* USB devices (in Hi-Speed mode?) do not like it
when their port is reset before it's powered on? And the root hub implementation also plays a role, which is why we only got reports about
Allwinner boards?

Hmm, we've got quite a few unknowns there. Thank you for performing the additional testing!

Quoted 4 lines

Also I think Marek said that Linux does the reset only when using SuperSpeed (hence the patch below), so maybe it's something in the USB 3.0
spec that changed the requirements?

I just spent about an hour and a half going through the USB 2.0 and USB 3.0 specifications. From what I understood, resetting a USB 3.0 port should be required when a USB device transitions between different states, such as when it resumes from suspend, but maybe not necessarily upon the initial device attachment.

Though, the Linux kernel USB driver seems to be doing additional USB 3.0 port resets upon the initial USB device attachment, presumably to ensure proper state of the USB 3.0 hub port and proper USB mode negotiation.

Here are the links to a couple of screenshots from the USB 3.0 specification, for future reference: https://i.imgur.com/cMaBdq2.png
and https://i.imgur.com/PDciRjP.png .

Quoted 9 lines

Moreover, such USB port resets don't seem to exist for USB 2.0 hubs, or at least I didn't see them in the USB 2.0 specification. The resets seem to be added to the USB 3.0 specification as part of the port and device mode negotiation.

Thus, the additional fix that Shantur sent, available below, looks to be the right way to handle it. Thus, Shantur, AFAICT it's fine to submit this fix as a separate "Fixes" patch.

Thanks for confirmation.
I will submit a patch soon.

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines

- On the OrangePi Zero (H3 with USB 2.0 only), it worked with and without the patch below, with both the USB 2.0 and USB 3.0 drive.
- On the BananaPi M64 (A64 with USB 2.0 only and an onboard USB 2.0 hub) it also worked in all cases: with and without the patch, USB 2.0 and USB 3.0 drive.

So the good news is: with the patch below it worked in all cases, with all drives in all slots, on all boards. With current mainline some drives don't work at least on the board with the H616 SoC.

I cannot really say if that makes sense, and the results above maybe more per board than per SoC (different VBUS supply), but would pragmatically tend to use the patch, feel free to add my Tested-by:
when sending:

Just one tiny thing:

Quoted 2 lines

Once you have tested it, can you please try the patch below

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
        debug("enabling power on all ports\n");
        for (i = 0; i < dev->maxchild; i++) {
(quoted diff) +0 -2
-               usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
-               debug("Reset : port %d returns %lX\n", i + 1,

dev->status);
+ if (usb_hub_is_superspeed(hub)) {

this must be: usb_hub_is_superspeed(dev)

No, this is to check the hub. If the hub is USB 3.0 then we can try reset. The device isn't identified yet.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

So many thanks for that patch, that seem to have fixed it for me - even though I don't understand why. But then again I only have superficial USB knowledge.

Quoted 9 lines

+ usb_set_port_feature(dev, i + 1,
USB_PORT_FEAT_RESET);
+ debug("Reset : port %d returns %lX\n", i + 1,
dev->status);
+ }
usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER); debug("PowerOn : port %d returns %lX\n", i + 1,

dev->status);
        }
#20 lore raw
Quoted 140 lines · Shantur Rathore

Hi Dragan and Andre,

Quoted 95 lines · Dragan Simic

Hello Andre and Shantur,

Quoted 41 lines · Andre Przywara
Quoted 30 lines · On Fri, 02 Feb 2024 03:35:24 +0100 Dragan Simic <[email protected]> wrote:
Quoted 17 lines · Andre Przywara
Quoted 6 lines · On Thu, 1 Feb 2024 18:35:28 +0000 Shantur Rathore <[email protected]> wrote:
Quoted 4 lines · Andre Przywara
Quoted 2 lines · On Thu, 1 Feb 2024 09:39:54 +0000 Shantur Rathore <[email protected]> wrote:

Which USB disk are you using? Is it a USB 2.0 disk ? Can you try with any other USB disk to confirm?

Quoted 8 lines
Quoted 3 lines

Yes, this was some USB 2.0 memory stick, on an USB 2.0 port. Most sunxi boards only have USB 2.0, but there is one SoC with USB 3.0, I will try some combinations later tonight.

That would be awesome.
We need to test

USB 3.0 and 2.0 ports with USB 3.0 and 2.0 drives.

Quoted 11 lines

So I had some mixed and apparently inconsistent results:
- On the Pine-H64 (H6 SoC with USB 3.0 + USB 2.0) it worked with mainline, but only after I applied some pending sunxi USB PHY regulator patches. This is an unrelated issue, those patches are needed to enable USB 3.0 support on that board (shared regulator conflict).
I tested a USB 2.0 and a USB 3.0 drive in both kind of slots, with and without the patch.
- On the OrangePi Zero 3 (H616 SoC with USB 2.0 only), the USB 3.0 drive would not work with mainline. A USB 2.0 drive was fine. Applying your patch below fixed that problem, now both drives worked.

Quoted 6 lines

Let me interject, please...

Huh, this (mih)behavior with the tested OrangePi Zero 3 is really strange. As we know, a USB 3.0 drive plugged into a USB 2.0 port should behave just like a USB 2.0 drive, using the separate set of pins inside the connector.

Yes, I found this odd as well, hence saying inconsistent above.

Quoted 8 lines
Quoted 4 lines

If possible, performing some additional testing with another USB 3.0 drive would be quite interesting. Could it be that something is wrong with the USB 2.0 receptacle on your OrangePi Zero 3, mechanically or electrically?

The receptacle on the OPi Zero3 is a standard USB 2.0 Type-A socket, with clearly only 4 pins. The USB 3.0 stick in question has all 9 pins. So indeed there should be little difference to a USB 2.0 stick.

Ah, sorry, I wasn't clear enough... I actually had some possible damage to the Zero 3's USB 2.0 receptacle in mind, or some results of the regular wear and tear, which could've possibly caused some intermittent issues.

Quoted 4 lines

And I just tested the same board with some other (cheap) USB 2.0 stick:
it's the same situation as with the USB 3.0 drive: it does not work with
mainline, but works with the patch below. So the USB 3.0 device here

Quoted 8 lines

might
be a red herring, and it's actually more up to an individual device? Or maybe it's like: *Some* USB devices (in Hi-Speed mode?) do not like it
when their port is reset before it's powered on? And the root hub implementation also plays a role, which is why we only got reports about
Allwinner boards?

Hmm, we've got quite a few unknowns there. Thank you for performing the additional testing!

Quoted 4 lines

Also I think Marek said that Linux does the reset only when using SuperSpeed (hence the patch below), so maybe it's something in the USB 3.0
spec that changed the requirements?

I just spent about an hour and a half going through the USB 2.0 and USB 3.0 specifications. From what I understood, resetting a USB 3.0 port should be required when a USB device transitions between different states, such as when it resumes from suspend, but maybe not necessarily upon the initial device attachment.

Though, the Linux kernel USB driver seems to be doing additional USB 3.0 port resets upon the initial USB device attachment, presumably to ensure proper state of the USB 3.0 hub port and proper USB mode negotiation.

Here are the links to a couple of screenshots from the USB 3.0 specification, for future reference: https://i.imgur.com/cMaBdq2.png
and https://i.imgur.com/PDciRjP.png .

Quoted 9 lines

Moreover, such USB port resets don't seem to exist for USB 2.0 hubs, or at least I didn't see them in the USB 2.0 specification. The resets seem to be added to the USB 3.0 specification as part of the port and device mode negotiation.

Thus, the additional fix that Shantur sent, available below, looks to be the right way to handle it. Thus, Shantur, AFAICT it's fine to submit this fix as a separate "Fixes" patch.

Thanks for confirmation.
I will submit a patch soon.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines

- On the OrangePi Zero (H3 with USB 2.0 only), it worked with and without the patch below, with both the USB 2.0 and USB 3.0 drive.
- On the BananaPi M64 (A64 with USB 2.0 only and an onboard USB 2.0 hub) it also worked in all cases: with and without the patch, USB 2.0 and USB 3.0 drive.

So the good news is: with the patch below it worked in all cases, with all drives in all slots, on all boards. With current mainline some drives don't work at least on the board with the H616 SoC.

I cannot really say if that makes sense, and the results above maybe more per board than per SoC (different VBUS supply), but would pragmatically tend to use the patch, feel free to add my Tested-by:
when sending:

Just one tiny thing:

Quoted 8 lines

Once you have tested it, can you please try the patch below

        debug("enabling power on all ports\n");
        for (i = 0; i < dev->maxchild; i++) {
(quoted diff) +0 -2
-               usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
-               debug("Reset : port %d returns %lX\n", i + 1,

dev->status);
+ if (usb_hub_is_superspeed(hub)) {

Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

this must be: usb_hub_is_superspeed(dev)

No, this is to check the hub. If the hub is USB 3.0 then we can try reset. The device isn't identified yet.

Take my words back. Didn't realise the dev is a hub device.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

So many thanks for that patch, that seem to have fixed it for me - even though I don't understand why. But then again I only have superficial USB knowledge.

Quoted 9 lines

+ usb_set_port_feature(dev, i + 1,
USB_PORT_FEAT_RESET);
+ debug("Reset : port %d returns %lX\n", i + 1,
dev->status);
+ }
usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER); debug("PowerOn : port %d returns %lX\n", i + 1,

dev->status);
        }