Re: [RFT] usb: Fix TX errors on devices with unsupported LPM states.

2012-10-03 Thread Don Zickus
On Tue, Oct 02, 2012 at 02:42:41PM -0700, Sarah Sharp wrote:
   USB 3.0 devices are required to support Link PM.  However, some of
   them don't support U1, or don't support U2, or don't support either.
   There is no way in the USB 3.0 specification to say that a device
   doesn't support U1 or U2, so these devices set the U1 or U2 exit
   latency to the maximum possible values (10ms for U1, 2047ms for U2).
  
  It still failed for me. :-(
 
 Can you send me the `sudo lsusb -v` output for the device?  Also, please
 see if you can get a new cable and retest.

I attached the lsusb -v output (had to use another usb3 controller to
obtain it).  I can't really use another cable because it comes with its
own usb3 mini cable.  All the other usb3 cables I have are the normal
sized ones (with the fatter end).

Cheers,
Don


Bus 006 Device 002: ID 1058:0730 Western Digital Technologies, Inc. 
Device Descriptor:
  bLength18
  bDescriptorType 1
  bcdUSB   3.00
  bDeviceClass0 (Defined at Interface level)
  bDeviceSubClass 0 
  bDeviceProtocol 0 
  bMaxPacketSize0 9
  idVendor   0x1058 Western Digital Technologies, Inc.
  idProduct  0x0730 
  bcdDevice   10.16
  iManufacturer   1 Western Digital
  iProduct2 My Passport 0730
  iSerial 3 575837314132314434373235
  bNumConfigurations  1
  Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength   44
bNumInterfaces  1
bConfigurationValue 1
iConfiguration  0 
bmAttributes 0x80
  (Bus Powered)
MaxPower  224mA
Interface Descriptor:
  bLength 9
  bDescriptorType 4
  bInterfaceNumber0
  bAlternateSetting   0
  bNumEndpoints   2
  bInterfaceClass 8 Mass Storage
  bInterfaceSubClass  6 SCSI
  bInterfaceProtocol 80 Bulk-Only
  iInterface  0 
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x84  EP 4 IN
bmAttributes2
  Transfer TypeBulk
  Synch Type   None
  Usage Type   Data
wMaxPacketSize 0x0400  1x 1024 bytes
bInterval   0
bMaxBurst  15
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x03  EP 3 OUT
bmAttributes2
  Transfer TypeBulk
  Synch Type   None
  Usage Type   Data
wMaxPacketSize 0x0400  1x 1024 bytes
bInterval   0
bMaxBurst  15
Binary Object Store Descriptor:
  bLength 5
  bDescriptorType15
  wTotalLength   22
  bNumDeviceCaps  2
  SuperSpeed USB Device Capability:
bLength10
bDescriptorType16
bDevCapabilityType  3
bmAttributes 0x00
  Latency Tolerance Messages (LTM) Supported
wSpeedsSupported   0x000e
  Device can operate at Full Speed (12Mbps)
  Device can operate at High Speed (480Mbps)
  Device can operate at SuperSpeed (5Gbps)
bFunctionalitySupport   1
  Lowest fully-functional device speed is Full Speed (12Mbps)
bU1DevExitLat   0 micro seconds
bU2DevExitLat   0 micro seconds
  USB 2.0 Extension Device Capability:
bLength 7
bDescriptorType16
bDevCapabilityType  2
bmAttributes   0x0002
  Link Power Management (LPM) Supported
Device Status: 0x0002
  (Bus Powered)
  Remote Wakeup Enabled
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFT] usb: Fix TX errors on devices with unsupported LPM states.

2012-10-03 Thread Sarah Sharp
On Wed, Oct 03, 2012 at 09:34:43AM -0400, Don Zickus wrote:
 On Tue, Oct 02, 2012 at 02:42:41PM -0700, Sarah Sharp wrote:
USB 3.0 devices are required to support Link PM.  However, some of
them don't support U1, or don't support U2, or don't support either.
There is no way in the USB 3.0 specification to say that a device
doesn't support U1 or U2, so these devices set the U1 or U2 exit
latency to the maximum possible values (10ms for U1, 2047ms for U2).
   
   It still failed for me. :-(
  
  Can you send me the `sudo lsusb -v` output for the device?  Also, please
  see if you can get a new cable and retest.
 
 I attached the lsusb -v output (had to use another usb3 controller to
 obtain it).  I can't really use another cable because it comes with its
 own usb3 mini cable.  All the other usb3 cables I have are the normal
 sized ones (with the fatter end).

Hah, I think I see the issue:

   SuperSpeed USB Device Capability:
 bLength10
 bDescriptorType16
 bDevCapabilityType  3
 bmAttributes 0x00
   Latency Tolerance Messages (LTM) Supported
 wSpeedsSupported   0x000e
   Device can operate at Full Speed (12Mbps)
   Device can operate at High Speed (480Mbps)
   Device can operate at SuperSpeed (5Gbps)
 bFunctionalitySupport   1
   Lowest fully-functional device speed is Full Speed (12Mbps)
 bU1DevExitLat   0 micro seconds
 bU2DevExitLat   0 micro seconds

The device is claiming it won't experience *any* exit latency for U1 or
U2.  That probably means it doesn't support U1 or U2 at all.  So we need
to blacklist both the max values and the min values.  Patch shortly.

Sarah Sharp
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFT] usb: Fix TX errors on devices with unsupported LPM states.

2012-10-02 Thread Sarah Sharp
Hi Don,

The WD drive arrived today, but I can't reproduce your I/O errors on
3.6.  I didn't try with 3.5 yet.  However, I did notice that the device
really doesn't want to enter U1, but it will enter U2.

Can you test the following patch with your device and see if it helps?
If that doesn't work, I suggest getting a high-quality new cable and
seeing if that helps the transfer issues.

Gabor, this might fix your issues as well, and should allow your system
to consume less power than completely disabling LPM.

Sarah Sharp

8-8

USB 3.0 devices are required to support Link PM.  However, some of
them don't support U1, or don't support U2, or don't support either.
There is no way in the USB 3.0 specification to say that a device
doesn't support U1 or U2, so these devices set the U1 or U2 exit
latency to the maximum possible values (10ms for U1, 2047ms for U2).

With the old code, when we enabled hub-initiated U1 or U2 for a device
on the roothub, the host would send LGO_U1 and LGO_U2 every 10ms or
2047ms, respectively.  The device would always send refuse to go into
the lower power link state, and would send an LAUX back.

The constant U1/U2 refusals would fill an idle bus with link commands.
This caused transfer errors and timeouts with a Western Digital My
Passport Essential 500 GB USB 3.0 hard drive (PID:VID 1058:0740).  The
lsusb shows that device has the maximum possible device exit latency
for U1, but has a non-max U2 exit latency:

  SuperSpeed USB Device Capability:
bLength10
bDescriptorType16
bDevCapabilityType  3
bmAttributes 0x00
  Latency Tolerance Messages (LTM) Supported
wSpeedsSupported   0x000e
  Device can operate at Full Speed (12Mbps)
  Device can operate at High Speed (480Mbps)
  Device can operate at SuperSpeed (5Gbps)
bFunctionalitySupport   1
  Lowest fully-functional device speed is Full Speed (12Mbps)
bU1DevExitLat  10 micro seconds
bU2DevExitLat  32 micro seconds

Change the LPM enabling code to look for the maximum U1 and U2 exit
latencies.  If we find those magic values, don't enable hub-initiated
transitions to U1 or U2.  Instead, let the device initiate the lower
power link state.  That way, if a device does support U1 or U2 and it
truely needs the maximum exit latency, we can still save power.

With this patch, the roothub lsusb output shows the device is happy to
go into U2, just not U1:

 Hub Port Status:
   Port 1: .0243 5Gbps power U2 enable connect
   Port 2: .0263 5Gbps power suspend enable connect
   Port 3: .02a0 5Gbps power Rx.Detect
   Port 4: .02a0 5Gbps power Rx.Detect

This patch should be backported to stable kernels as old as 3.5, that
contain the commit 1ea7e0e8e3d0f50901d335ea4178ab2aa8c88201 USB: Add
support to enable/disable USB3 link states.

Signed-off-by: Sarah Sharp sarah.a.sh...@linux.intel.com
Cc: sta...@vger.kernel.org
---
 drivers/usb/core/hub.c  |   19 +++
 include/linux/usb/ch9.h |2 ++
 2 files changed, 21 insertions(+)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 128a804..e1065ed 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -3353,6 +3353,8 @@ static void usb_enable_link_state(struct usb_hcd *hcd, 
struct usb_device *udev,
enum usb3_link_state state)
 {
int timeout;
+   __u8 u1_mel;
+   __le16 u2_mel;
 
/* We allow the host controller to set the U1/U2 timeout internally
 * first, so that it can change its schedule to account for the
@@ -3372,6 +3374,23 @@ static void usb_enable_link_state(struct usb_hcd *hcd, 
struct usb_device *udev,
return;
}
 
+   /*
+* Magic maximum device exit latency values may mean the device doesn't
+* support U1 or U2.  If hub-initiated LPM is enabled, the device will
+* always refuse to go into U1 or U2, and will fill the bus with LAUX
+* link commands.  This can cause transfer errors, so only enable
+* device-initiated LPM.
+*/
+   u1_mel = udev-bos-ss_cap-bU1devExitLat;
+   u2_mel = udev-bos-ss_cap-bU2DevExitLat;
+   if ((state == USB3_LPM_U1  u1_mel == USB_U1_MAX_VALID_MEL) ||
+   (state == USB3_LPM_U2 
+le16_to_cpu(u2_mel) == USB_U2_MAX_VALID_MEL)) {
+   if (usb_set_device_initiated_lpm(udev, state, true))
+   hcd-driver-disable_usb3_lpm_timeout(hcd, udev, state);
+   return;
+   }
+
if (usb_set_lpm_timeout(udev, state, timeout))
/* If we can't set the parent hub U1/U2 timeout,
 * device-initiated LPM won't be allowed either, so let the xHCI
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index d1d732c..edf28ac 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -828,7 +828,9 @@ 

Re: [RFT] usb: Fix TX errors on devices with unsupported LPM states.

2012-10-02 Thread Alan Stern
On Tue, 2 Oct 2012, Sarah Sharp wrote:

 --- a/include/linux/usb/ch9.h
 +++ b/include/linux/usb/ch9.h
 @@ -828,7 +828,9 @@ struct usb_ss_cap_descriptor {/* Link Power 
 Management */
  #define USB_HIGH_SPEED_OPERATION (1  2) /* High speed operation */
  #define USB_5GBPS_OPERATION  (1  3) /* Operation at 5Gbps */
   __u8  bFunctionalitySupport;
 +#define  USB_U1_MAX_VALID_MEL0x0A/* U1 MEL is 10us, max 
 */
   __u8  bU1devExitLat;
 +#define  USB_U2_MAX_VALID_MEL0x7FF   /* U2 MEL is 2047us, 
 max */
   __le16 bU2DevExitLat;
  } __attribute__((packed));

Can these new values please be defined in decimal rather than hex?  
Then maybe the comments wouldn't be needed.

Alan Stern

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


Re: [RFT] usb: Fix TX errors on devices with unsupported LPM states.

2012-10-02 Thread Sarah Sharp
On Tue, Oct 02, 2012 at 03:50:45PM -0400, Alan Stern wrote:
 On Tue, 2 Oct 2012, Sarah Sharp wrote:
 
  --- a/include/linux/usb/ch9.h
  +++ b/include/linux/usb/ch9.h
  @@ -828,7 +828,9 @@ struct usb_ss_cap_descriptor {  /* Link Power 
  Management */
   #define USB_HIGH_SPEED_OPERATION   (1  2) /* High speed operation */
   #define USB_5GBPS_OPERATION(1  3) /* Operation at 5Gbps 
  */
  __u8  bFunctionalitySupport;
  +#defineUSB_U1_MAX_VALID_MEL0x0A/* U1 MEL is 10us, max 
  */
  __u8  bU1devExitLat;
  +#defineUSB_U2_MAX_VALID_MEL0x7FF   /* U2 MEL is 2047us, 
  max */
  __le16 bU2DevExitLat;
   } __attribute__((packed));
 
 Can these new values please be defined in decimal rather than hex?  
 Then maybe the comments wouldn't be needed.

Eh, sure. :)

Sarah Sharp
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFT] usb: Fix TX errors on devices with unsupported LPM states.

2012-10-02 Thread Don Zickus
On Tue, Oct 02, 2012 at 12:15:46PM -0700, Sarah Sharp wrote:
 Hi Don,
 
 The WD drive arrived today, but I can't reproduce your I/O errors on
 3.6.  I didn't try with 3.5 yet.  However, I did notice that the device
 really doesn't want to enter U1, but it will enter U2.

I did update the firmware but I think I had the problem before that
happened.  Also I don't use the VIA hub anymore.  I plugged the harddrive
directly into my mahobay system's usb3 port and see the problem.

 
 Can you test the following patch with your device and see if it helps?
 If that doesn't work, I suggest getting a high-quality new cable and
 seeing if that helps the transfer issues.
 
 Gabor, this might fix your issues as well, and should allow your system
 to consume less power than completely disabling LPM.
 
 Sarah Sharp
 
 8-8
 
 USB 3.0 devices are required to support Link PM.  However, some of
 them don't support U1, or don't support U2, or don't support either.
 There is no way in the USB 3.0 specification to say that a device
 doesn't support U1 or U2, so these devices set the U1 or U2 exit
 latency to the maximum possible values (10ms for U1, 2047ms for U2).

It still failed for me. :-(

Cheers,
Don
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFT] usb: Fix TX errors on devices with unsupported LPM states.

2012-10-02 Thread Sarah Sharp
On Tue, Oct 02, 2012 at 05:26:48PM -0400, Don Zickus wrote:
 On Tue, Oct 02, 2012 at 12:15:46PM -0700, Sarah Sharp wrote:
  Hi Don,
  
  The WD drive arrived today, but I can't reproduce your I/O errors on
  3.6.  I didn't try with 3.5 yet.  However, I did notice that the device
  really doesn't want to enter U1, but it will enter U2.
 
 I did update the firmware but I think I had the problem before that
 happened.  Also I don't use the VIA hub anymore.  I plugged the harddrive
 directly into my mahobay system's usb3 port and see the problem.
 
  
  Can you test the following patch with your device and see if it helps?
  If that doesn't work, I suggest getting a high-quality new cable and
  seeing if that helps the transfer issues.
  
  Gabor, this might fix your issues as well, and should allow your system
  to consume less power than completely disabling LPM.
  
  Sarah Sharp
  
  8-8
  
  USB 3.0 devices are required to support Link PM.  However, some of
  them don't support U1, or don't support U2, or don't support either.
  There is no way in the USB 3.0 specification to say that a device
  doesn't support U1 or U2, so these devices set the U1 or U2 exit
  latency to the maximum possible values (10ms for U1, 2047ms for U2).
 
 It still failed for me. :-(

Can you send me the `sudo lsusb -v` output for the device?  Also, please
see if you can get a new cable and retest.

If that still fails, the next step might be to add code to the USB core
to disable LPM for the device if too many URBs fail with transfer errors.

Sarah Sharp
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html