linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/1] usb: core: lpm: set lpm_capable for root hub device
@ 2015-06-13  7:23 Lu Baolu
  2015-06-13 15:00 ` Alan Stern
  0 siblings, 1 reply; 3+ messages in thread
From: Lu Baolu @ 2015-06-13  7:23 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman, Alan Stern
  Cc: linux-usb, linux-kernel, 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.").

Cc: stable@vger.kernel.org # 3.15
Reported-by: Kevin Strasser <kevin.strasser@linux.intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/usb/core/hcd.c | 7 +++++--
 drivers/usb/core/hub.c | 2 +-
 drivers/usb/core/usb.h | 6 ++++++
 3 files changed, 12 insertions(+), 3 deletions(-)

 v1->v2 change log:
 1. two code blocks merged (Alan's feedback)
 2. fix build error when CONFIG_PM is not set (Alan's feedback)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 45a915c..1c1385e 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1022,9 +1022,12 @@ static int register_root_hub(struct usb_hcd *hcd)
 				dev_name(&usb_dev->dev), retval);
 		return (retval < 0) ? retval : -EMSGSIZE;
 	}
-	if (usb_dev->speed == USB_SPEED_SUPER) {
+
+	if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) {
 		retval = usb_get_bos_descriptor(usb_dev);
-		if (retval < 0) {
+		if (!retval) {
+			usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev);
+		} else if (usb_dev->speed == USB_SPEED_SUPER) {
 			mutex_unlock(&usb_bus_list_lock);
 			dev_dbg(parent_dev, "can't read %s bos descriptor %d\n",
 					dev_name(&usb_dev->dev), retval);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 3b71516..884d702 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -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.
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 7eb1e26..d54a669 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -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
 
@@ -106,6 +107,11 @@ static inline int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
 	return 0;
 }
 
+static inline int usb_device_supports_lpm(struct usb_device *udev)
+{
+	return 0;
+}
+
 #endif
 
 extern struct bus_type usb_bus_type;
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/1] usb: core: lpm: set lpm_capable for root hub device
  2015-06-13  7:23 [PATCH v2 1/1] usb: core: lpm: set lpm_capable for root hub device Lu Baolu
@ 2015-06-13 15:00 ` Alan Stern
  2015-06-15  2:52   ` Lu, Baolu
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Stern @ 2015-06-13 15:00 UTC (permalink / raw)
  To: Lu Baolu; +Cc: Mathias Nyman, Greg Kroah-Hartman, linux-usb, linux-kernel

On Sat, 13 Jun 2015, Lu Baolu wrote:

> 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.").
> 
> Cc: stable@vger.kernel.org # 3.15
> Reported-by: Kevin Strasser <kevin.strasser@linux.intel.com>
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> ---

> --- a/drivers/usb/core/usb.h
> +++ b/drivers/usb/core/usb.h
> @@ -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
>  
> @@ -106,6 +107,11 @@ static inline int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
>  	return 0;
>  }
>  
> +static inline int usb_device_supports_lpm(struct usb_device *udev)
> +{
> +	return 0;
> +}
> +
>  #endif
>  
>  extern struct bus_type usb_bus_type;

In fact, usb_device_supports_lpm() is compiled even when CONFIG_PM
isn't set.  Maybe this should be changed.  But if you don't want to
change it now, you need to put the declaration outside the "#ifdef
CONFIG_PM" region.  As it is, your patch is still broken (did you try 
building it with CONFIG_PM unset?).

Alan Stern


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/1] usb: core: lpm: set lpm_capable for root hub device
  2015-06-13 15:00 ` Alan Stern
@ 2015-06-15  2:52   ` Lu, Baolu
  0 siblings, 0 replies; 3+ messages in thread
From: Lu, Baolu @ 2015-06-15  2:52 UTC (permalink / raw)
  To: Alan Stern; +Cc: Mathias Nyman, Greg Kroah-Hartman, linux-usb, linux-kernel



On 06/13/2015 11:00 PM, Alan Stern wrote:
> On Sat, 13 Jun 2015, Lu Baolu wrote:
>
>> 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.").
>>
>> Cc: stable@vger.kernel.org # 3.15
>> Reported-by: Kevin Strasser <kevin.strasser@linux.intel.com>
>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>> ---
>> --- a/drivers/usb/core/usb.h
>> +++ b/drivers/usb/core/usb.h
>> @@ -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
>>   
>> @@ -106,6 +107,11 @@ static inline int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
>>   	return 0;
>>   }
>>   
>> +static inline int usb_device_supports_lpm(struct usb_device *udev)
>> +{
>> +	return 0;
>> +}
>> +
>>   #endif
>>   
>>   extern struct bus_type usb_bus_type;
> In fact, usb_device_supports_lpm() is compiled even when CONFIG_PM
> isn't set.  Maybe this should be changed.  But if you don't want to
> change it now, you need to put the declaration outside the "#ifdef
> CONFIG_PM" region.  As it is, your patch is still broken (did you try
> building it with CONFIG_PM unset?).

I am sorry for this silly mistake. I will move it out of CONFIG_PM region.

I tried building with CONFIG_PM unset. But it turns out that CONFIG_PM
was auto selected by some other items. I will test my next version of
patch with CONFIG_PM *really* unset before sending it out.

Thanks,
Baolu

>
> Alan Stern
>
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-15  2:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-13  7:23 [PATCH v2 1/1] usb: core: lpm: set lpm_capable for root hub device Lu Baolu
2015-06-13 15:00 ` Alan Stern
2015-06-15  2:52   ` Lu, Baolu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).