Skip to contentSkip to conversation

usb: core: lpm: set lpm_capable for root hub device

PATCH Superseded Lu Baolu 3 participants 5 messages Jun 12, 2015 – Jun 13, 2015 USB

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Lu Baolu

author
#0 lore raw

PATCH 1/1 usb: core: lpm: set lpm_capable for root hub device

Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports Link PM.") removed the code to set lpm_capable for USB 3.0 super-speed root hub. The intention of that change was to avoid touching usb core internal field, a.k.a. lpm_capable, and let usb core to set it by checking U1 and U2 exit latency values in the descriptor.

Usb core checks and sets lpm_capable in hub_port_init(). Unfortunately, root hub is a special usb device as it has no parent. Hub_port_init() will never be called for a root hub device. That means lpm_capable will by no means be set for the root hub. As the result, lpm isn't functional at all in Linux kernel.

This patch add the code to check and set lpm_capable when registering a root hub device. It could be back-ported to kernels as old as v3.15, that contains the Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports Link PM.").

---
 drivers/usb/core/hcd.c | 6 ++++++
 drivers/usb/core/hub.c | 2 +-
 drivers/usb/core/usb.h | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
drivers/usb/core/hcd.c +6 -0
index 45a915c..48b208d 100644
@@ -1032,6 +1032,12 @@ static int register_root_hub(struct usb_hcd *hcd)
 		}
 	}
 
+	if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) {
+		retval = usb_get_bos_descriptor(usb_dev);
+		if (!retval)
+			usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev);
+	}
+
 	retval = usb_new_device (usb_dev);
 	if (retval) {
 		dev_err (parent_dev, "can't register root hub for %s, %d\n",
drivers/usb/core/hub.c +1 -1
index 3b71516..884d702 100644
@@ -122,7 +122,7 @@ struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev)
 	return usb_get_intfdata(hdev->actconfig->interface[0]);
 }
 
-static int usb_device_supports_lpm(struct usb_device *udev)
+int usb_device_supports_lpm(struct usb_device *udev)
 {
 	/* USB 2.1 (and greater) devices indicate LPM support through
 	 * their USB 2.0 Extended Capabilities BOS descriptor.
drivers/usb/core/usb.h +1 -0
index 7eb1e26..d5668c4 100644
@@ -82,6 +82,7 @@ extern int usb_runtime_suspend(struct device *dev);
 extern int usb_runtime_resume(struct device *dev);
 extern int usb_runtime_idle(struct device *dev);
 extern int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable);
+extern int usb_device_supports_lpm(struct usb_device *udev);
 
 #else
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 31 lines · Lu Baolu

Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports Link PM.") removed the code to set lpm_capable for USB 3.0 super-speed root hub. The intention of that change was to avoid touching usb core internal field, a.k.a. lpm_capable, and let usb core to set it by checking U1 and U2 exit latency values in the descriptor.

Usb core checks and sets lpm_capable in hub_port_init(). Unfortunately, root hub is a special usb device as it has no parent. Hub_port_init() will never be called for a root hub device. That means lpm_capable will by no means be set for the root hub. As the result, lpm isn't functional at all in Linux kernel.

This patch add the code to check and set lpm_capable when registering a root hub device. It could be back-ported to kernels as old as v3.15, that contains the Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports Link PM.").

---
 drivers/usb/core/hcd.c | 6 ++++++
 drivers/usb/core/hub.c | 2 +-
 drivers/usb/core/usb.h | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
drivers/usb/core/hcd.c +0 -0
index 45a915c..48b208d 100644

drivers/usb/core/hcd.c static int register_root_hub(struct usb_hcd *hcd) · line 1035

Quoted 4 lines
drivers/usb/core/hcd.c +1 -0
@@ -1032,6 +1032,12 @@ static int register_root_hub(struct usb_hcd *hcd)
 		}
 	}
 
+	if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) {

Why are you treating a binary coded value as a hex number to compare against?

author
#2 lore raw
Quoted 35 lines · Greg Kroah-Hartman
Quoted 34 lines · Lu Baolu

Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports Link PM.") removed the code to set lpm_capable for USB 3.0 super-speed root hub. The intention of that change was to avoid touching usb core internal field, a.k.a. lpm_capable, and let usb core to set it by checking U1 and U2 exit latency values in the descriptor.

Usb core checks and sets lpm_capable in hub_port_init(). Unfortunately, root hub is a special usb device as it has no parent. Hub_port_init() will never be called for a root hub device. That means lpm_capable will by no means be set for the root hub. As the result, lpm isn't functional at all in Linux kernel.

This patch add the code to check and set lpm_capable when registering a root hub device. It could be back-ported to kernels as old as v3.15, that contains the Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports Link PM.").

---
  drivers/usb/core/hcd.c | 6 ++++++
  drivers/usb/core/hub.c | 2 +-
  drivers/usb/core/usb.h | 1 +
  3 files changed, 8 insertions(+), 1 deletion(-)
drivers/usb/core/hcd.c +0 -0
index 45a915c..48b208d 100644
@@ -1032,6 +1032,12 @@ static int register_root_hub(struct usb_hcd *hcd)
  		}
  	}
 
Quoted 3 lines

drivers/usb/core/hcd.c static int register_root_hub(struct usb_hcd *hcd) · line 1035

Quoted 1 line
drivers/usb/core/hcd.c +1 -0
+	if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) {

Why are you treating a binary coded value as a hex number to compare against?

The value of the bcdUSB field is 0xJJMN for version JJ.M.N, where JJ – major version number,
M – minor version number,
N – sub-minor version number

I saw several places in usb core where it is treated as a hex and check the version requirement like this. Do you want me to separate it into three numbers and check major/minor/sub-minor versions separately?

Thanks,
Baolu

Quoted 7 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Lu Baolu
Quoted 31 lines · Lu Baolu

Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports Link PM.") removed the code to set lpm_capable for USB 3.0 super-speed root hub. The intention of that change was to avoid touching usb core internal field, a.k.a. lpm_capable, and let usb core to set it by checking U1 and U2 exit latency values in the descriptor.

Usb core checks and sets lpm_capable in hub_port_init(). Unfortunately, root hub is a special usb device as it has no parent. Hub_port_init() will never be called for a root hub device. That means lpm_capable will by no means be set for the root hub. As the result, lpm isn't functional at all in Linux kernel.

This patch add the code to check and set lpm_capable when registering a root hub device. It could be back-ported to kernels as old as v3.15, that contains the Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports Link PM.").

---
 drivers/usb/core/hcd.c | 6 ++++++
 drivers/usb/core/hub.c | 2 +-
 drivers/usb/core/usb.h | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
drivers/usb/core/hcd.c +0 -0
index 45a915c..48b208d 100644

drivers/usb/core/hcd.c static int register_root_hub(struct usb_hcd *hcd) · line 1040

Quoted 9 lines
drivers/usb/core/hcd.c +6 -0
@@ -1032,6 +1032,12 @@ static int register_root_hub(struct usb_hcd *hcd)
 		}
 	}
 
+	if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) {
+		retval = usb_get_bos_descriptor(usb_dev);
+		if (!retval)
+			usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev);
+	}
+

This should be integrated with the code immediately above it, which also calls usb_get_bos_descriptor(). In fact, maybe you should simply change the existing code to check bcdUSB >= 0x0201 instead of speed == USB_SPEED_SUPER.

Quoted 21 lines
drivers/usb/core/hcd.c +0 -0
 	retval = usb_new_device (usb_dev);
 	if (retval) {
 		dev_err (parent_dev, "can't register root hub for %s, %d\n",
drivers/usb/core/hub.c +1 -1
index 3b71516..884d702 100644
@@ -122,7 +122,7 @@ struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev)
 	return usb_get_intfdata(hdev->actconfig->interface[0]);
 }
 
-static int usb_device_supports_lpm(struct usb_device *udev)
+int usb_device_supports_lpm(struct usb_device *udev)
 {
 	/* USB 2.1 (and greater) devices indicate LPM support through
 	 * their USB 2.0 Extended Capabilities BOS descriptor.
drivers/usb/core/usb.h +0 -0
index 7eb1e26..d5668c4 100644

drivers/usb/core/usb.h extern int usb_runtime_suspend(struct device *dev); · line 87

Quoted 6 lines
drivers/usb/core/usb.h +1 -0
@@ -82,6 +82,7 @@ extern int usb_runtime_suspend(struct device *dev);
 extern int usb_runtime_resume(struct device *dev);
 extern int usb_runtime_idle(struct device *dev);
 extern int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable);
+extern int usb_device_supports_lpm(struct usb_device *udev);
 
 #else

This will break if you build it with CONFIG_PM disabled.

Alan Stern

author
#4 lore raw
Quoted 36 lines · Alan Stern
Quoted 34 lines · Lu Baolu

Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports Link PM.") removed the code to set lpm_capable for USB 3.0 super-speed root hub. The intention of that change was to avoid touching usb core internal field, a.k.a. lpm_capable, and let usb core to set it by checking U1 and U2 exit latency values in the descriptor.

Usb core checks and sets lpm_capable in hub_port_init(). Unfortunately, root hub is a special usb device as it has no parent. Hub_port_init() will never be called for a root hub device. That means lpm_capable will by no means be set for the root hub. As the result, lpm isn't functional at all in Linux kernel.

This patch add the code to check and set lpm_capable when registering a root hub device. It could be back-ported to kernels as old as v3.15, that contains the Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports Link PM.").

---
  drivers/usb/core/hcd.c | 6 ++++++
  drivers/usb/core/hub.c | 2 +-
  drivers/usb/core/usb.h | 1 +
  3 files changed, 8 insertions(+), 1 deletion(-)
drivers/usb/core/hcd.c +0 -0
index 45a915c..48b208d 100644
@@ -1032,6 +1032,12 @@ static int register_root_hub(struct usb_hcd *hcd)
  		}
  	}
 
Quoted 10 lines

drivers/usb/core/hcd.c static int register_root_hub(struct usb_hcd *hcd) · line 1040

Quoted 6 lines
drivers/usb/core/hcd.c +6 -0
+	if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) {
+		retval = usb_get_bos_descriptor(usb_dev);
+		if (!retval)
+			usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev);
+	}
+

This should be integrated with the code immediately above it, which also calls usb_get_bos_descriptor(). In fact, maybe you should simply change the existing code to check bcdUSB >= 0x0201 instead of speed == USB_SPEED_SUPER.

I agree with you and will change it in v2 patch.

Quoted 27 lines
Quoted 27 lines
drivers/usb/core/hcd.c +0 -0
  	retval = usb_new_device (usb_dev);
  	if (retval) {
  		dev_err (parent_dev, "can't register root hub for %s, %d\n",
drivers/usb/core/hub.c +1 -1
index 3b71516..884d702 100644
@@ -122,7 +122,7 @@ struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev)
  	return usb_get_intfdata(hdev->actconfig->interface[0]);
  }
 
-static int usb_device_supports_lpm(struct usb_device *udev)
+int usb_device_supports_lpm(struct usb_device *udev)
  {
  	/* USB 2.1 (and greater) devices indicate LPM support through
  	 * their USB 2.0 Extended Capabilities BOS descriptor.
drivers/usb/core/usb.h +1 -0
index 7eb1e26..d5668c4 100644
@@ -82,6 +82,7 @@ extern int usb_runtime_suspend(struct device *dev);
  extern int usb_runtime_resume(struct device *dev);
  extern int usb_runtime_idle(struct device *dev);
  extern int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable);
+extern int usb_device_supports_lpm(struct usb_device *udev);
 
Quoted 2 lines

drivers/usb/core/usb.h extern int usb_runtime_suspend(struct device *dev); · line 87

Quoted 1 line
drivers/usb/core/usb.h +0 -0
  #else

This will break if you build it with CONFIG_PM disabled.

Yes. Will fix it in v2 patch.

Quoted 2 lines

Alan Stern

Thank you,
Baolu

Quoted 8 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/