Re: port power is on again after turning off by user space

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Peter Chen <peter.chen@xxxxxxx> 于2020年12月15日周二 上午11:33写道:
>
> Hi Alan,
>
> I use one HUB power control application (https://github.com/mvp/uhubctl) to investigate power switchable HUB, and
> find the kernel turns port power on again at drivers/usb/core/hub.c, after port power is turned off by user space.
>
> 5122                 if (hub_is_port_power_switchable(hub)
> 5123                                 && !port_is_power_on(hub, portstatus)
> 5124                                 && !port_dev->port_owner)
> 5125                         set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);
>
> The main sequence for testing turn port power off like below:
>
> - uhubctl sends command to turn specifc port (eg, 2-1.4) power off.
> - devio at kernel gets that command, and send to hub.
> - port power is off, the hub_event is triggered due to port status is changed.
> - usb_disconnect is called, but port power is on again by kernel at function hub_port_connect.
>
> I can't find the code history why the port power needs to turn on after device is disconnected, do you know why?
> Any sugguestions to fix it? Thanks.

Seems in this case the port need claimed by user app, I am seeing this commit

commit fbaecff06a7db4defa899a664fe2758e5161b39d
Author: Deepak Das <deepakdas.linux@xxxxxxxxx>
Date:   Wed Jan 21 23:39:58 2015 +0530

    usb: core: hub: modify hub reset logic in hub driver

    Currently if port power is turned off by user on hub port
    using USBDEVFS then port power is turned back ON
    by hub driver.
    This commit modifies hub reset logic in hub_port_connect() to prevent
    hub driver from turning back the port power ON if port is not owned
    by kernel.

    Signed-off-by: Deepak Das <deepakdas.linux@xxxxxxxxx>
    Acked-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index b4bfa3a..3e9c4d4 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -4655,9 +4655,13 @@ static void hub_port_connect(struct usb_hub
*hub, int port1, u16 portstatus,
        if (!(portstatus & USB_PORT_STAT_CONNECTION) ||
                        test_bit(port1, hub->removed_bits)) {

-               /* maybe switch power back on (e.g. root hub was reset) */
+               /*
+                * maybe switch power back on (e.g. root hub was reset)
+                * but only if the port isn't owned by someone else.
+                */
                if (hub_is_port_power_switchable(hub)
-                               && !port_is_power_on(hub, portstatus))
+                               && !port_is_power_on(hub, portstatus)
+                               && !port_dev->port_owner)
                        set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);

                if (portstatus & USB_PORT_STAT_ENABLE)

Li Jun
>
>
> Best regards,
> Peter Chen
>
>




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux