aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/bluetooth/ath3k.c1
-rw-r--r--drivers/bluetooth/bcm203x.c1
-rw-r--r--drivers/bluetooth/bfusb.c1
-rw-r--r--drivers/bluetooth/bpa10x.c1
-rw-r--r--drivers/bluetooth/btusb.c1
-rw-r--r--drivers/isdn/gigaset/bas-gigaset.c1
-rw-r--r--drivers/isdn/gigaset/usb-gigaset.c1
-rw-r--r--drivers/isdn/hardware/mISDN/hfcsusb.c1
-rw-r--r--drivers/isdn/hisax/hfc_usb.c1
-rw-r--r--drivers/isdn/hisax/st5481_init.c1
-rw-r--r--drivers/net/usb/asix.c1
-rw-r--r--drivers/net/usb/catc.c1
-rw-r--r--drivers/net/usb/cdc-phonet.c1
-rw-r--r--drivers/net/usb/cdc_eem.c1
-rw-r--r--drivers/net/usb/cdc_ether.c1
-rw-r--r--drivers/net/usb/cdc_ncm.c1
-rw-r--r--drivers/net/usb/cdc_subset.c1
-rw-r--r--drivers/net/usb/cx82310_eth.c1
-rw-r--r--drivers/net/usb/dm9601.c1
-rw-r--r--drivers/net/usb/gl620a.c1
-rw-r--r--drivers/net/usb/hso.c1
-rw-r--r--drivers/net/usb/int51x1.c1
-rw-r--r--drivers/net/usb/ipheth.c1
-rw-r--r--drivers/net/usb/kalmia.c3
-rw-r--r--drivers/net/usb/kaweth.c1
-rw-r--r--drivers/net/usb/lg-vl600.c1
-rw-r--r--drivers/net/usb/mcs7830.c1
-rw-r--r--drivers/net/usb/net1080.c1
-rw-r--r--drivers/net/usb/pegasus.c1
-rw-r--r--drivers/net/usb/plusb.c1
-rw-r--r--drivers/net/usb/qmi_wwan.c1
-rw-r--r--drivers/net/usb/rndis_host.c1
-rw-r--r--drivers/net/usb/rtl8150.c3
-rw-r--r--drivers/net/usb/sierra_net.c1
-rw-r--r--drivers/net/usb/smsc75xx.c1
-rw-r--r--drivers/net/usb/smsc95xx.c1
-rw-r--r--drivers/net/usb/zaurus.c1
-rw-r--r--drivers/net/wireless/at76c50x-usb.c1
-rw-r--r--drivers/net/wireless/ath/ath6kl/usb.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/hif_usb.c1
-rw-r--r--drivers/net/wireless/ath/carl9170/usb.c1
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/usb.c1
-rw-r--r--drivers/net/wireless/libertas/if_usb.c1
-rw-r--r--drivers/net/wireless/libertas_tf/if_usb.c1
-rw-r--r--drivers/net/wireless/orinoco/orinoco_usb.c1
-rw-r--r--drivers/net/wireless/p54/p54usb.c1
-rw-r--r--drivers/net/wireless/rndis_wlan.c1
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c1
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c1
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c1
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187/dev.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/sw.c1
-rw-r--r--drivers/net/wireless/zd1201.c1
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.c1
-rw-r--r--drivers/usb/class/cdc-acm.c1
-rw-r--r--drivers/usb/class/cdc-wdm.c1
-rw-r--r--drivers/usb/core/driver.c54
-rw-r--r--drivers/usb/core/hcd.c9
-rw-r--r--drivers/usb/core/hub.c672
-rw-r--r--drivers/usb/core/message.c38
-rw-r--r--drivers/usb/host/xhci-hub.c19
-rw-r--r--drivers/usb/host/xhci-mem.c39
-rw-r--r--drivers/usb/host/xhci-pci.c14
-rw-r--r--drivers/usb/host/xhci-ring.c24
-rw-r--r--drivers/usb/host/xhci.c454
-rw-r--r--drivers/usb/host/xhci.h15
-rw-r--r--include/linux/usb.h60
-rw-r--r--include/linux/usb/ch11.h2
-rw-r--r--include/linux/usb/ch9.h56
-rw-r--r--include/linux/usb/hcd.h9
70 files changed, 1512 insertions, 13 deletions
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index 57fd867553d7..2812b152d6e9 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -439,6 +439,7 @@ static struct usb_driver ath3k_driver = {
439 .probe = ath3k_probe, 439 .probe = ath3k_probe,
440 .disconnect = ath3k_disconnect, 440 .disconnect = ath3k_disconnect,
441 .id_table = ath3k_table, 441 .id_table = ath3k_table,
442 .disable_hub_initiated_lpm = 1,
442}; 443};
443 444
444module_usb_driver(ath3k_driver); 445module_usb_driver(ath3k_driver);
diff --git a/drivers/bluetooth/bcm203x.c b/drivers/bluetooth/bcm203x.c
index 1e742a50e2cd..37ae175162f3 100644
--- a/drivers/bluetooth/bcm203x.c
+++ b/drivers/bluetooth/bcm203x.c
@@ -279,6 +279,7 @@ static struct usb_driver bcm203x_driver = {
279 .probe = bcm203x_probe, 279 .probe = bcm203x_probe,
280 .disconnect = bcm203x_disconnect, 280 .disconnect = bcm203x_disconnect,
281 .id_table = bcm203x_table, 281 .id_table = bcm203x_table,
282 .disable_hub_initiated_lpm = 1,
282}; 283};
283 284
284module_usb_driver(bcm203x_driver); 285module_usb_driver(bcm203x_driver);
diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c
index b8ac1c549a1c..32e825144fe9 100644
--- a/drivers/bluetooth/bfusb.c
+++ b/drivers/bluetooth/bfusb.c
@@ -749,6 +749,7 @@ static struct usb_driver bfusb_driver = {
749 .probe = bfusb_probe, 749 .probe = bfusb_probe,
750 .disconnect = bfusb_disconnect, 750 .disconnect = bfusb_disconnect,
751 .id_table = bfusb_table, 751 .id_table = bfusb_table,
752 .disable_hub_initiated_lpm = 1,
752}; 753};
753 754
754module_usb_driver(bfusb_driver); 755module_usb_driver(bfusb_driver);
diff --git a/drivers/bluetooth/bpa10x.c b/drivers/bluetooth/bpa10x.c
index d894340a7601..609861a53c28 100644
--- a/drivers/bluetooth/bpa10x.c
+++ b/drivers/bluetooth/bpa10x.c
@@ -508,6 +508,7 @@ static struct usb_driver bpa10x_driver = {
508 .probe = bpa10x_probe, 508 .probe = bpa10x_probe,
509 .disconnect = bpa10x_disconnect, 509 .disconnect = bpa10x_disconnect,
510 .id_table = bpa10x_table, 510 .id_table = bpa10x_table,
511 .disable_hub_initiated_lpm = 1,
511}; 512};
512 513
513module_usb_driver(bpa10x_driver); 514module_usb_driver(bpa10x_driver);
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 9217121362e1..461c68bc4dd7 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -1218,6 +1218,7 @@ static struct usb_driver btusb_driver = {
1218#endif 1218#endif
1219 .id_table = btusb_table, 1219 .id_table = btusb_table,
1220 .supports_autosuspend = 1, 1220 .supports_autosuspend = 1,
1221 .disable_hub_initiated_lpm = 1,
1221}; 1222};
1222 1223
1223module_usb_driver(btusb_driver); 1224module_usb_driver(btusb_driver);
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
index afa080258bfa..17ea0177a529 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -148,6 +148,7 @@ static struct usb_driver gigaset_usb_driver = {
148 .reset_resume = gigaset_post_reset, 148 .reset_resume = gigaset_post_reset,
149 .pre_reset = gigaset_pre_reset, 149 .pre_reset = gigaset_pre_reset,
150 .post_reset = gigaset_post_reset, 150 .post_reset = gigaset_post_reset,
151 .disable_hub_initiated_lpm = 1,
151}; 152};
152 153
153/* get message text for usb_submit_urb return code 154/* get message text for usb_submit_urb return code
diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
index 049da67f6392..78f81e8a5be6 100644
--- a/drivers/isdn/gigaset/usb-gigaset.c
+++ b/drivers/isdn/gigaset/usb-gigaset.c
@@ -124,6 +124,7 @@ static struct usb_driver gigaset_usb_driver = {
124 .reset_resume = gigaset_resume, 124 .reset_resume = gigaset_resume,
125 .pre_reset = gigaset_pre_reset, 125 .pre_reset = gigaset_pre_reset,
126 .post_reset = gigaset_resume, 126 .post_reset = gigaset_resume,
127 .disable_hub_initiated_lpm = 1,
127}; 128};
128 129
129struct usb_cardstate { 130struct usb_cardstate {
diff --git a/drivers/isdn/hardware/mISDN/hfcsusb.c b/drivers/isdn/hardware/mISDN/hfcsusb.c
index 8cde2a0538ab..cddb769a8b12 100644
--- a/drivers/isdn/hardware/mISDN/hfcsusb.c
+++ b/drivers/isdn/hardware/mISDN/hfcsusb.c
@@ -2151,6 +2151,7 @@ static struct usb_driver hfcsusb_drv = {
2151 .id_table = hfcsusb_idtab, 2151 .id_table = hfcsusb_idtab,
2152 .probe = hfcsusb_probe, 2152 .probe = hfcsusb_probe,
2153 .disconnect = hfcsusb_disconnect, 2153 .disconnect = hfcsusb_disconnect,
2154 .disable_hub_initiated_lpm = 1,
2154}; 2155};
2155 2156
2156module_usb_driver(hfcsusb_drv); 2157module_usb_driver(hfcsusb_drv);
diff --git a/drivers/isdn/hisax/hfc_usb.c b/drivers/isdn/hisax/hfc_usb.c
index 62c65bdefd8a..84f9c8103078 100644
--- a/drivers/isdn/hisax/hfc_usb.c
+++ b/drivers/isdn/hisax/hfc_usb.c
@@ -1568,6 +1568,7 @@ static struct usb_driver hfc_drv = {
1568 .id_table = hfcusb_idtab, 1568 .id_table = hfcusb_idtab,
1569 .probe = hfc_usb_probe, 1569 .probe = hfc_usb_probe,
1570 .disconnect = hfc_usb_disconnect, 1570 .disconnect = hfc_usb_disconnect,
1571 .disable_hub_initiated_lpm = 1,
1571}; 1572};
1572 1573
1573static void __exit 1574static void __exit
diff --git a/drivers/isdn/hisax/st5481_init.c b/drivers/isdn/hisax/st5481_init.c
index 100296e20dc0..54ef9e4f8cbc 100644
--- a/drivers/isdn/hisax/st5481_init.c
+++ b/drivers/isdn/hisax/st5481_init.c
@@ -182,6 +182,7 @@ static struct usb_driver st5481_usb_driver = {
182 .probe = probe_st5481, 182 .probe = probe_st5481,
183 .disconnect = disconnect_st5481, 183 .disconnect = disconnect_st5481,
184 .id_table = st5481_ids, 184 .id_table = st5481_ids,
185 .disable_hub_initiated_lpm = 1,
185}; 186};
186 187
187static int __init st5481_usb_init(void) 188static int __init st5481_usb_init(void)
diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c
index 42b5151aa78a..71e2b0523bc2 100644
--- a/drivers/net/usb/asix.c
+++ b/drivers/net/usb/asix.c
@@ -1647,6 +1647,7 @@ static struct usb_driver asix_driver = {
1647 .resume = usbnet_resume, 1647 .resume = usbnet_resume,
1648 .disconnect = usbnet_disconnect, 1648 .disconnect = usbnet_disconnect,
1649 .supports_autosuspend = 1, 1649 .supports_autosuspend = 1,
1650 .disable_hub_initiated_lpm = 1,
1650}; 1651};
1651 1652
1652module_usb_driver(asix_driver); 1653module_usb_driver(asix_driver);
diff --git a/drivers/net/usb/catc.c b/drivers/net/usb/catc.c
index 5a73730b32eb..26c5bebd9eca 100644
--- a/drivers/net/usb/catc.c
+++ b/drivers/net/usb/catc.c
@@ -952,6 +952,7 @@ static struct usb_driver catc_driver = {
952 .probe = catc_probe, 952 .probe = catc_probe,
953 .disconnect = catc_disconnect, 953 .disconnect = catc_disconnect,
954 .id_table = catc_id_table, 954 .id_table = catc_id_table,
955 .disable_hub_initiated_lpm = 1,
955}; 956};
956 957
957module_usb_driver(catc_driver); 958module_usb_driver(catc_driver);
diff --git a/drivers/net/usb/cdc-phonet.c b/drivers/net/usb/cdc-phonet.c
index 3e41b00c6806..d848d4dd5754 100644
--- a/drivers/net/usb/cdc-phonet.c
+++ b/drivers/net/usb/cdc-phonet.c
@@ -457,6 +457,7 @@ static struct usb_driver usbpn_driver = {
457 .probe = usbpn_probe, 457 .probe = usbpn_probe,
458 .disconnect = usbpn_disconnect, 458 .disconnect = usbpn_disconnect,
459 .id_table = usbpn_ids, 459 .id_table = usbpn_ids,
460 .disable_hub_initiated_lpm = 1,
460}; 461};
461 462
462module_usb_driver(usbpn_driver); 463module_usb_driver(usbpn_driver);
diff --git a/drivers/net/usb/cdc_eem.c b/drivers/net/usb/cdc_eem.c
index 685a4e22c768..434d5af8e6fb 100644
--- a/drivers/net/usb/cdc_eem.c
+++ b/drivers/net/usb/cdc_eem.c
@@ -368,6 +368,7 @@ static struct usb_driver eem_driver = {
368 .disconnect = usbnet_disconnect, 368 .disconnect = usbnet_disconnect,
369 .suspend = usbnet_suspend, 369 .suspend = usbnet_suspend,
370 .resume = usbnet_resume, 370 .resume = usbnet_resume,
371 .disable_hub_initiated_lpm = 1,
371}; 372};
372 373
373module_usb_driver(eem_driver); 374module_usb_driver(eem_driver);
diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index 00880edba048..04997320862a 100644
--- a/drivers/net/usb/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
@@ -633,6 +633,7 @@ static struct usb_driver cdc_driver = {
633 .resume = usbnet_resume, 633 .resume = usbnet_resume,
634 .reset_resume = usbnet_resume, 634 .reset_resume = usbnet_resume,
635 .supports_autosuspend = 1, 635 .supports_autosuspend = 1,
636 .disable_hub_initiated_lpm = 1,
636}; 637};
637 638
638module_usb_driver(cdc_driver); 639module_usb_driver(cdc_driver);
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index 7adc9f6b0ea1..4b9513fcf275 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -1212,6 +1212,7 @@ static struct usb_driver cdc_ncm_driver = {
1212 .resume = usbnet_resume, 1212 .resume = usbnet_resume,
1213 .reset_resume = usbnet_resume, 1213 .reset_resume = usbnet_resume,
1214 .supports_autosuspend = 1, 1214 .supports_autosuspend = 1,
1215 .disable_hub_initiated_lpm = 1,
1215}; 1216};
1216 1217
1217static const struct ethtool_ops cdc_ncm_ethtool_ops = { 1218static const struct ethtool_ops cdc_ncm_ethtool_ops = {
diff --git a/drivers/net/usb/cdc_subset.c b/drivers/net/usb/cdc_subset.c
index b403d934e4e3..0d1fe89ae0bd 100644
--- a/drivers/net/usb/cdc_subset.c
+++ b/drivers/net/usb/cdc_subset.c
@@ -336,6 +336,7 @@ static struct usb_driver cdc_subset_driver = {
336 .resume = usbnet_resume, 336 .resume = usbnet_resume,
337 .disconnect = usbnet_disconnect, 337 .disconnect = usbnet_disconnect,
338 .id_table = products, 338 .id_table = products,
339 .disable_hub_initiated_lpm = 1,
339}; 340};
340 341
341module_usb_driver(cdc_subset_driver); 342module_usb_driver(cdc_subset_driver);
diff --git a/drivers/net/usb/cx82310_eth.c b/drivers/net/usb/cx82310_eth.c
index 0e0531356e62..49ab45e17fe8 100644
--- a/drivers/net/usb/cx82310_eth.c
+++ b/drivers/net/usb/cx82310_eth.c
@@ -327,6 +327,7 @@ static struct usb_driver cx82310_driver = {
327 .disconnect = usbnet_disconnect, 327 .disconnect = usbnet_disconnect,
328 .suspend = usbnet_suspend, 328 .suspend = usbnet_suspend,
329 .resume = usbnet_resume, 329 .resume = usbnet_resume,
330 .disable_hub_initiated_lpm = 1,
330}; 331};
331 332
332module_usb_driver(cx82310_driver); 333module_usb_driver(cx82310_driver);
diff --git a/drivers/net/usb/dm9601.c b/drivers/net/usb/dm9601.c
index b97226318ea5..e0433ce6ced7 100644
--- a/drivers/net/usb/dm9601.c
+++ b/drivers/net/usb/dm9601.c
@@ -670,6 +670,7 @@ static struct usb_driver dm9601_driver = {
670 .disconnect = usbnet_disconnect, 670 .disconnect = usbnet_disconnect,
671 .suspend = usbnet_suspend, 671 .suspend = usbnet_suspend,
672 .resume = usbnet_resume, 672 .resume = usbnet_resume,
673 .disable_hub_initiated_lpm = 1,
673}; 674};
674 675
675module_usb_driver(dm9601_driver); 676module_usb_driver(dm9601_driver);
diff --git a/drivers/net/usb/gl620a.c b/drivers/net/usb/gl620a.c
index 38266bdae26b..db3c8021f2a3 100644
--- a/drivers/net/usb/gl620a.c
+++ b/drivers/net/usb/gl620a.c
@@ -225,6 +225,7 @@ static struct usb_driver gl620a_driver = {
225 .disconnect = usbnet_disconnect, 225 .disconnect = usbnet_disconnect,
226 .suspend = usbnet_suspend, 226 .suspend = usbnet_suspend,
227 .resume = usbnet_resume, 227 .resume = usbnet_resume,
228 .disable_hub_initiated_lpm = 1,
228}; 229};
229 230
230module_usb_driver(gl620a_driver); 231module_usb_driver(gl620a_driver);
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 2d2a6882ba33..042c1a99520f 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -3291,6 +3291,7 @@ static struct usb_driver hso_driver = {
3291 .resume = hso_resume, 3291 .resume = hso_resume,
3292 .reset_resume = hso_resume, 3292 .reset_resume = hso_resume,
3293 .supports_autosuspend = 1, 3293 .supports_autosuspend = 1,
3294 .disable_hub_initiated_lpm = 1,
3294}; 3295};
3295 3296
3296static int __init hso_init(void) 3297static int __init hso_init(void)
diff --git a/drivers/net/usb/int51x1.c b/drivers/net/usb/int51x1.c
index 12a22a453ff1..8de641713d5f 100644
--- a/drivers/net/usb/int51x1.c
+++ b/drivers/net/usb/int51x1.c
@@ -236,6 +236,7 @@ static struct usb_driver int51x1_driver = {
236 .disconnect = usbnet_disconnect, 236 .disconnect = usbnet_disconnect,
237 .suspend = usbnet_suspend, 237 .suspend = usbnet_suspend,
238 .resume = usbnet_resume, 238 .resume = usbnet_resume,
239 .disable_hub_initiated_lpm = 1,
239}; 240};
240 241
241module_usb_driver(int51x1_driver); 242module_usb_driver(int51x1_driver);
diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c
index 32519e5a7b97..964031e3da87 100644
--- a/drivers/net/usb/ipheth.c
+++ b/drivers/net/usb/ipheth.c
@@ -554,6 +554,7 @@ static struct usb_driver ipheth_driver = {
554 .probe = ipheth_probe, 554 .probe = ipheth_probe,
555 .disconnect = ipheth_disconnect, 555 .disconnect = ipheth_disconnect,
556 .id_table = ipheth_table, 556 .id_table = ipheth_table,
557 .disable_hub_initiated_lpm = 1,
557}; 558};
558 559
559module_usb_driver(ipheth_driver); 560module_usb_driver(ipheth_driver);
diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
index 7562649b3d6b..92c49e0a59ec 100644
--- a/drivers/net/usb/kalmia.c
+++ b/drivers/net/usb/kalmia.c
@@ -372,7 +372,8 @@ static struct usb_driver kalmia_driver = {
372 .probe = usbnet_probe, 372 .probe = usbnet_probe,
373 .disconnect = usbnet_disconnect, 373 .disconnect = usbnet_disconnect,
374 .suspend = usbnet_suspend, 374 .suspend = usbnet_suspend,
375 .resume = usbnet_resume 375 .resume = usbnet_resume,
376 .disable_hub_initiated_lpm = 1,
376}; 377};
377 378
378module_usb_driver(kalmia_driver); 379module_usb_driver(kalmia_driver);
diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
index b8baf0858515..d8ad55284389 100644
--- a/drivers/net/usb/kaweth.c
+++ b/drivers/net/usb/kaweth.c
@@ -179,6 +179,7 @@ static struct usb_driver kaweth_driver = {
179 .resume = kaweth_resume, 179 .resume = kaweth_resume,
180 .id_table = usb_klsi_table, 180 .id_table = usb_klsi_table,
181 .supports_autosuspend = 1, 181 .supports_autosuspend = 1,
182 .disable_hub_initiated_lpm = 1,
182}; 183};
183 184
184typedef __u8 eth_addr_t[6]; 185typedef __u8 eth_addr_t[6];
diff --git a/drivers/net/usb/lg-vl600.c b/drivers/net/usb/lg-vl600.c
index 45a981fde43f..808d6506da41 100644
--- a/drivers/net/usb/lg-vl600.c
+++ b/drivers/net/usb/lg-vl600.c
@@ -344,6 +344,7 @@ static struct usb_driver lg_vl600_driver = {
344 .disconnect = usbnet_disconnect, 344 .disconnect = usbnet_disconnect,
345 .suspend = usbnet_suspend, 345 .suspend = usbnet_suspend,
346 .resume = usbnet_resume, 346 .resume = usbnet_resume,
347 .disable_hub_initiated_lpm = 1,
347}; 348};
348 349
349module_usb_driver(lg_vl600_driver); 350module_usb_driver(lg_vl600_driver);
diff --git a/drivers/net/usb/mcs7830.c b/drivers/net/usb/mcs7830.c
index c434b6ba0337..add1064f755d 100644
--- a/drivers/net/usb/mcs7830.c
+++ b/drivers/net/usb/mcs7830.c
@@ -690,6 +690,7 @@ static struct usb_driver mcs7830_driver = {
690 .suspend = usbnet_suspend, 690 .suspend = usbnet_suspend,
691 .resume = usbnet_resume, 691 .resume = usbnet_resume,
692 .reset_resume = mcs7830_reset_resume, 692 .reset_resume = mcs7830_reset_resume,
693 .disable_hub_initiated_lpm = 1,
693}; 694};
694 695
695module_usb_driver(mcs7830_driver); 696module_usb_driver(mcs7830_driver);
diff --git a/drivers/net/usb/net1080.c b/drivers/net/usb/net1080.c
index 83f965cb69e7..28c4d513ba85 100644
--- a/drivers/net/usb/net1080.c
+++ b/drivers/net/usb/net1080.c
@@ -587,6 +587,7 @@ static struct usb_driver net1080_driver = {
587 .disconnect = usbnet_disconnect, 587 .disconnect = usbnet_disconnect,
588 .suspend = usbnet_suspend, 588 .suspend = usbnet_suspend,
589 .resume = usbnet_resume, 589 .resume = usbnet_resume,
590 .disable_hub_initiated_lpm = 1,
590}; 591};
591 592
592module_usb_driver(net1080_driver); 593module_usb_driver(net1080_driver);
diff --git a/drivers/net/usb/pegasus.c b/drivers/net/usb/pegasus.c
index 752393092325..7023220456c5 100644
--- a/drivers/net/usb/pegasus.c
+++ b/drivers/net/usb/pegasus.c
@@ -1489,6 +1489,7 @@ static struct usb_driver pegasus_driver = {
1489 .id_table = pegasus_ids, 1489 .id_table = pegasus_ids,
1490 .suspend = pegasus_suspend, 1490 .suspend = pegasus_suspend,
1491 .resume = pegasus_resume, 1491 .resume = pegasus_resume,
1492 .disable_hub_initiated_lpm = 1,
1492}; 1493};
1493 1494
1494static void __init parse_id(char *id) 1495static void __init parse_id(char *id)
diff --git a/drivers/net/usb/plusb.c b/drivers/net/usb/plusb.c
index b2b035e29978..4584b9a805b3 100644
--- a/drivers/net/usb/plusb.c
+++ b/drivers/net/usb/plusb.c
@@ -152,6 +152,7 @@ static struct usb_driver plusb_driver = {
152 .disconnect = usbnet_disconnect, 152 .disconnect = usbnet_disconnect,
153 .suspend = usbnet_suspend, 153 .suspend = usbnet_suspend,
154 .resume = usbnet_resume, 154 .resume = usbnet_resume,
155 .disable_hub_initiated_lpm = 1,
155}; 156};
156 157
157module_usb_driver(plusb_driver); 158module_usb_driver(plusb_driver);
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index d316503b35d4..9048efed46db 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -525,6 +525,7 @@ static struct usb_driver qmi_wwan_driver = {
525 .resume = qmi_wwan_resume, 525 .resume = qmi_wwan_resume,
526 .reset_resume = qmi_wwan_resume, 526 .reset_resume = qmi_wwan_resume,
527 .supports_autosuspend = 1, 527 .supports_autosuspend = 1,
528 .disable_hub_initiated_lpm = 1,
528}; 529};
529 530
530static int __init qmi_wwan_init(void) 531static int __init qmi_wwan_init(void)
diff --git a/drivers/net/usb/rndis_host.c b/drivers/net/usb/rndis_host.c
index c8f1b5b3aff3..446d074ad7d0 100644
--- a/drivers/net/usb/rndis_host.c
+++ b/drivers/net/usb/rndis_host.c
@@ -633,6 +633,7 @@ static struct usb_driver rndis_driver = {
633 .disconnect = usbnet_disconnect, 633 .disconnect = usbnet_disconnect,
634 .suspend = usbnet_suspend, 634 .suspend = usbnet_suspend,
635 .resume = usbnet_resume, 635 .resume = usbnet_resume,
636 .disable_hub_initiated_lpm = 1,
636}; 637};
637 638
638module_usb_driver(rndis_driver); 639module_usb_driver(rndis_driver);
diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
index 65854cdcedc8..0e2c92e0e532 100644
--- a/drivers/net/usb/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
@@ -948,7 +948,8 @@ static struct usb_driver rtl8150_driver = {
948 .disconnect = rtl8150_disconnect, 948 .disconnect = rtl8150_disconnect,
949 .id_table = rtl8150_table, 949 .id_table = rtl8150_table,
950 .suspend = rtl8150_suspend, 950 .suspend = rtl8150_suspend,
951 .resume = rtl8150_resume 951 .resume = rtl8150_resume,
952 .disable_hub_initiated_lpm = 1,
952}; 953};
953 954
954module_usb_driver(rtl8150_driver); 955module_usb_driver(rtl8150_driver);
diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
index b59cf20c7817..3faef5670d1f 100644
--- a/drivers/net/usb/sierra_net.c
+++ b/drivers/net/usb/sierra_net.c
@@ -982,6 +982,7 @@ static struct usb_driver sierra_net_driver = {
982 .suspend = usbnet_suspend, 982 .suspend = usbnet_suspend,
983 .resume = usbnet_resume, 983 .resume = usbnet_resume,
984 .no_dynamic_id = 1, 984 .no_dynamic_id = 1,
985 .disable_hub_initiated_lpm = 1,
985}; 986};
986 987
987module_usb_driver(sierra_net_driver); 988module_usb_driver(sierra_net_driver);
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 00103a8c5e04..1fb4ddb2ccbf 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -1250,6 +1250,7 @@ static struct usb_driver smsc75xx_driver = {
1250 .suspend = usbnet_suspend, 1250 .suspend = usbnet_suspend,
1251 .resume = usbnet_resume, 1251 .resume = usbnet_resume,
1252 .disconnect = usbnet_disconnect, 1252 .disconnect = usbnet_disconnect,
1253 .disable_hub_initiated_lpm = 1,
1253}; 1254};
1254 1255
1255module_usb_driver(smsc75xx_driver); 1256module_usb_driver(smsc75xx_driver);
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 94ae66999f59..b1112e753859 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -1297,6 +1297,7 @@ static struct usb_driver smsc95xx_driver = {
1297 .suspend = usbnet_suspend, 1297 .suspend = usbnet_suspend,
1298 .resume = usbnet_resume, 1298 .resume = usbnet_resume,
1299 .disconnect = usbnet_disconnect, 1299 .disconnect = usbnet_disconnect,
1300 .disable_hub_initiated_lpm = 1,
1300}; 1301};
1301 1302
1302module_usb_driver(smsc95xx_driver); 1303module_usb_driver(smsc95xx_driver);
diff --git a/drivers/net/usb/zaurus.c b/drivers/net/usb/zaurus.c
index 34db195fb8b0..35c90307d473 100644
--- a/drivers/net/usb/zaurus.c
+++ b/drivers/net/usb/zaurus.c
@@ -377,6 +377,7 @@ static struct usb_driver zaurus_driver = {
377 .disconnect = usbnet_disconnect, 377 .disconnect = usbnet_disconnect,
378 .suspend = usbnet_suspend, 378 .suspend = usbnet_suspend,
379 .resume = usbnet_resume, 379 .resume = usbnet_resume,
380 .disable_hub_initiated_lpm = 1,
380}; 381};
381 382
382module_usb_driver(zaurus_driver); 383module_usb_driver(zaurus_driver);
diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
index cc741b3cc024..9dcd49cfab94 100644
--- a/drivers/net/wireless/at76c50x-usb.c
+++ b/drivers/net/wireless/at76c50x-usb.c
@@ -2486,6 +2486,7 @@ static struct usb_driver at76_driver = {
2486 .probe = at76_probe, 2486 .probe = at76_probe,
2487 .disconnect = at76_disconnect, 2487 .disconnect = at76_disconnect,
2488 .id_table = dev_table, 2488 .id_table = dev_table,
2489 .disable_hub_initiated_lpm = 1,
2489}; 2490};
2490 2491
2491static int __init at76_mod_init(void) 2492static int __init at76_mod_init(void)
diff --git a/drivers/net/wireless/ath/ath6kl/usb.c b/drivers/net/wireless/ath/ath6kl/usb.c
index 325b1224c2b1..f8a27db69c7f 100644
--- a/drivers/net/wireless/ath/ath6kl/usb.c
+++ b/drivers/net/wireless/ath/ath6kl/usb.c
@@ -405,6 +405,7 @@ static struct usb_driver ath6kl_usb_driver = {
405 .probe = ath6kl_usb_probe, 405 .probe = ath6kl_usb_probe,
406 .disconnect = ath6kl_usb_remove, 406 .disconnect = ath6kl_usb_remove,
407 .id_table = ath6kl_usb_ids, 407 .id_table = ath6kl_usb_ids,
408 .disable_hub_initiated_lpm = 1,
408}; 409};
409 410
410static int ath6kl_usb_init(void) 411static int ath6kl_usb_init(void)
diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c b/drivers/net/wireless/ath/ath9k/hif_usb.c
index 424aabb2c730..dea53dea9a53 100644
--- a/drivers/net/wireless/ath/ath9k/hif_usb.c
+++ b/drivers/net/wireless/ath/ath9k/hif_usb.c
@@ -1356,6 +1356,7 @@ static struct usb_driver ath9k_hif_usb_driver = {
1356#endif 1356#endif
1357 .id_table = ath9k_hif_usb_ids, 1357 .id_table = ath9k_hif_usb_ids,
1358 .soft_unbind = 1, 1358 .soft_unbind = 1,
1359 .disable_hub_initiated_lpm = 1,
1359}; 1360};
1360 1361
1361int ath9k_hif_usb_init(void) 1362int ath9k_hif_usb_init(void)
diff --git a/drivers/net/wireless/ath/carl9170/usb.c b/drivers/net/wireless/ath/carl9170/usb.c
index 89821e4835c7..888152ce3eca 100644
--- a/drivers/net/wireless/ath/carl9170/usb.c
+++ b/drivers/net/wireless/ath/carl9170/usb.c
@@ -1159,6 +1159,7 @@ static struct usb_driver carl9170_driver = {
1159 .resume = carl9170_usb_resume, 1159 .resume = carl9170_usb_resume,
1160 .reset_resume = carl9170_usb_resume, 1160 .reset_resume = carl9170_usb_resume,
1161#endif /* CONFIG_PM */ 1161#endif /* CONFIG_PM */
1162 .disable_hub_initiated_lpm = 1,
1162}; 1163};
1163 1164
1164module_usb_driver(carl9170_driver); 1165module_usb_driver(carl9170_driver);
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/usb.c b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
index 82364223e817..8852d23ef829 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/usb.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
@@ -1605,6 +1605,7 @@ static struct usb_driver brcmf_usbdrvr = {
1605 .suspend = brcmf_usb_suspend, 1605 .suspend = brcmf_usb_suspend,
1606 .resume = brcmf_usb_resume, 1606 .resume = brcmf_usb_resume,
1607 .supports_autosuspend = 1 1607 .supports_autosuspend = 1
1608 .disable_hub_initiated_lpm = 1,
1608}; 1609};
1609 1610
1610void brcmf_usb_exit(void) 1611void brcmf_usb_exit(void)
diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index 74da5f1ea243..76ea66d53b9c 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -1180,6 +1180,7 @@ static struct usb_driver if_usb_driver = {
1180 .suspend = if_usb_suspend, 1180 .suspend = if_usb_suspend,
1181 .resume = if_usb_resume, 1181 .resume = if_usb_resume,
1182 .reset_resume = if_usb_resume, 1182 .reset_resume = if_usb_resume,
1183 .disable_hub_initiated_lpm = 1,
1183}; 1184};
1184 1185
1185module_usb_driver(if_usb_driver); 1186module_usb_driver(if_usb_driver);
diff --git a/drivers/net/wireless/libertas_tf/if_usb.c b/drivers/net/wireless/libertas_tf/if_usb.c
index 7ced130f4f9e..19a5a92dd779 100644
--- a/drivers/net/wireless/libertas_tf/if_usb.c
+++ b/drivers/net/wireless/libertas_tf/if_usb.c
@@ -920,6 +920,7 @@ static struct usb_driver if_usb_driver = {
920 .id_table = if_usb_table, 920 .id_table = if_usb_table,
921 .suspend = if_usb_suspend, 921 .suspend = if_usb_suspend,
922 .resume = if_usb_resume, 922 .resume = if_usb_resume,
923 .disable_hub_initiated_lpm = 1,
923}; 924};
924 925
925module_usb_driver(if_usb_driver); 926module_usb_driver(if_usb_driver);
diff --git a/drivers/net/wireless/orinoco/orinoco_usb.c b/drivers/net/wireless/orinoco/orinoco_usb.c
index f634d4582bfe..7f53cea2f205 100644
--- a/drivers/net/wireless/orinoco/orinoco_usb.c
+++ b/drivers/net/wireless/orinoco/orinoco_usb.c
@@ -1752,6 +1752,7 @@ static struct usb_driver orinoco_driver = {
1752 .probe = ezusb_probe, 1752 .probe = ezusb_probe,
1753 .disconnect = ezusb_disconnect, 1753 .disconnect = ezusb_disconnect,
1754 .id_table = ezusb_table, 1754 .id_table = ezusb_table,
1755 .disable_hub_initiated_lpm = 1,
1755}; 1756};
1756 1757
1757module_usb_driver(orinoco_driver); 1758module_usb_driver(orinoco_driver);
diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
index f4d28c39aac7..d14dc81820e3 100644
--- a/drivers/net/wireless/p54/p54usb.c
+++ b/drivers/net/wireless/p54/p54usb.c
@@ -1081,6 +1081,7 @@ static struct usb_driver p54u_driver = {
1081 .reset_resume = p54u_resume, 1081 .reset_resume = p54u_resume,
1082#endif /* CONFIG_PM */ 1082#endif /* CONFIG_PM */
1083 .soft_unbind = 1, 1083 .soft_unbind = 1,
1084 .disable_hub_initiated_lpm = 1,
1084}; 1085};
1085 1086
1086module_usb_driver(p54u_driver); 1087module_usb_driver(p54u_driver);
diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
index d66e2980bc27..748a89de50d0 100644
--- a/drivers/net/wireless/rndis_wlan.c
+++ b/drivers/net/wireless/rndis_wlan.c
@@ -3776,6 +3776,7 @@ static struct usb_driver rndis_wlan_driver = {
3776 .disconnect = usbnet_disconnect, 3776 .disconnect = usbnet_disconnect,
3777 .suspend = usbnet_suspend, 3777 .suspend = usbnet_suspend,
3778 .resume = usbnet_resume, 3778 .resume = usbnet_resume,
3779 .disable_hub_initiated_lpm = 1,
3779}; 3780};
3780 3781
3781module_usb_driver(rndis_wlan_driver); 3782module_usb_driver(rndis_wlan_driver);
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index 1de9c752c88b..d432e49ed6cd 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -1980,6 +1980,7 @@ static struct usb_driver rt2500usb_driver = {
1980 .disconnect = rt2x00usb_disconnect, 1980 .disconnect = rt2x00usb_disconnect,
1981 .suspend = rt2x00usb_suspend, 1981 .suspend = rt2x00usb_suspend,
1982 .resume = rt2x00usb_resume, 1982 .resume = rt2x00usb_resume,
1983 .disable_hub_initiated_lpm = 1,
1983}; 1984};
1984 1985
1985module_usb_driver(rt2500usb_driver); 1986module_usb_driver(rt2500usb_driver);
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index 001735f7a661..d60d4e2772e6 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -1293,6 +1293,7 @@ static struct usb_driver rt2800usb_driver = {
1293 .disconnect = rt2x00usb_disconnect, 1293 .disconnect = rt2x00usb_disconnect,
1294 .suspend = rt2x00usb_suspend, 1294 .suspend = rt2x00usb_suspend,
1295 .resume = rt2x00usb_resume, 1295 .resume = rt2x00usb_resume,
1296 .disable_hub_initiated_lpm = 1,
1296}; 1297};
1297 1298
1298module_usb_driver(rt2800usb_driver); 1299module_usb_driver(rt2800usb_driver);
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index e477a964081d..f813de6cd1b7 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -2526,6 +2526,7 @@ static struct usb_driver rt73usb_driver = {
2526 .disconnect = rt2x00usb_disconnect, 2526 .disconnect = rt2x00usb_disconnect,
2527 .suspend = rt2x00usb_suspend, 2527 .suspend = rt2x00usb_suspend,
2528 .resume = rt2x00usb_resume, 2528 .resume = rt2x00usb_resume,
2529 .disable_hub_initiated_lpm = 1,
2529}; 2530};
2530 2531
2531module_usb_driver(rt73usb_driver); 2532module_usb_driver(rt73usb_driver);
diff --git a/drivers/net/wireless/rtl818x/rtl8187/dev.c b/drivers/net/wireless/rtl818x/rtl8187/dev.c
index cf53ac9d6f23..c2d2a21dd452 100644
--- a/drivers/net/wireless/rtl818x/rtl8187/dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8187/dev.c
@@ -1662,6 +1662,7 @@ static struct usb_driver rtl8187_driver = {
1662 .id_table = rtl8187_table, 1662 .id_table = rtl8187_table,
1663 .probe = rtl8187_probe, 1663 .probe = rtl8187_probe,
1664 .disconnect = __devexit_p(rtl8187_disconnect), 1664 .disconnect = __devexit_p(rtl8187_disconnect),
1665 .disable_hub_initiated_lpm = 1,
1665}; 1666};
1666 1667
1667module_usb_driver(rtl8187_driver); 1668module_usb_driver(rtl8187_driver);
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
index 82c85286ab2e..0face8b7e524 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
@@ -372,6 +372,7 @@ static struct usb_driver rtl8192cu_driver = {
372#ifdef CONFIG_AUTOSUSPEND 372#ifdef CONFIG_AUTOSUSPEND
373 .supports_autosuspend = 1, 373 .supports_autosuspend = 1,
374#endif 374#endif
375 .disable_hub_initiated_lpm = 1,
375}; 376};
376 377
377module_usb_driver(rtl8192cu_driver); 378module_usb_driver(rtl8192cu_driver);
diff --git a/drivers/net/wireless/zd1201.c b/drivers/net/wireless/zd1201.c
index a66b93b7ff9a..48273dd05b63 100644
--- a/drivers/net/wireless/zd1201.c
+++ b/drivers/net/wireless/zd1201.c
@@ -1905,6 +1905,7 @@ static struct usb_driver zd1201_usb = {
1905 .id_table = zd1201_table, 1905 .id_table = zd1201_table,
1906 .suspend = zd1201_suspend, 1906 .suspend = zd1201_suspend,
1907 .resume = zd1201_resume, 1907 .resume = zd1201_resume,
1908 .disable_hub_initiated_lpm = 1,
1908}; 1909};
1909 1910
1910module_usb_driver(zd1201_usb); 1911module_usb_driver(zd1201_usb);
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
index f766b3e67c6d..af83c43bcdb1 100644
--- a/drivers/net/wireless/zd1211rw/zd_usb.c
+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
@@ -1542,6 +1542,7 @@ static struct usb_driver driver = {
1542 .disconnect = disconnect, 1542 .disconnect = disconnect,
1543 .pre_reset = pre_reset, 1543 .pre_reset = pre_reset,
1544 .post_reset = post_reset, 1544 .post_reset = post_reset,
1545 .disable_hub_initiated_lpm = 1,
1545}; 1546};
1546 1547
1547struct workqueue_struct *zd_workqueue; 1548struct workqueue_struct *zd_workqueue;
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index b32ccb461019..f2a120eea9d4 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1664,6 +1664,7 @@ static struct usb_driver acm_driver = {
1664#ifdef CONFIG_PM 1664#ifdef CONFIG_PM
1665 .supports_autosuspend = 1, 1665 .supports_autosuspend = 1,
1666#endif 1666#endif
1667 .disable_hub_initiated_lpm = 1,
1667}; 1668};
1668 1669
1669/* 1670/*
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 631bb952d0f6..ea8b304f0e85 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -1034,6 +1034,7 @@ static struct usb_driver wdm_driver = {
1034 .post_reset = wdm_post_reset, 1034 .post_reset = wdm_post_reset,
1035 .id_table = wdm_ids, 1035 .id_table = wdm_ids,
1036 .supports_autosuspend = 1, 1036 .supports_autosuspend = 1,
1037 .disable_hub_initiated_lpm = 1,
1037}; 1038};
1038 1039
1039module_usb_driver(wdm_driver); 1040module_usb_driver(wdm_driver);
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index f6f81c85c5cf..f536aebc958e 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -288,6 +288,7 @@ static int usb_probe_interface(struct device *dev)
288 struct usb_device *udev = interface_to_usbdev(intf); 288 struct usb_device *udev = interface_to_usbdev(intf);
289 const struct usb_device_id *id; 289 const struct usb_device_id *id;
290 int error = -ENODEV; 290 int error = -ENODEV;
291 int lpm_disable_error;
291 292
292 dev_dbg(dev, "%s\n", __func__); 293 dev_dbg(dev, "%s\n", __func__);
293 294
@@ -324,6 +325,25 @@ static int usb_probe_interface(struct device *dev)
324 if (driver->supports_autosuspend) 325 if (driver->supports_autosuspend)
325 pm_runtime_enable(dev); 326 pm_runtime_enable(dev);
326 327
328 /* If the new driver doesn't allow hub-initiated LPM, and we can't
329 * disable hub-initiated LPM, then fail the probe.
330 *
331 * Otherwise, leaving LPM enabled should be harmless, because the
332 * endpoint intervals should remain the same, and the U1/U2 timeouts
333 * should remain the same.
334 *
335 * If we need to install alt setting 0 before probe, or another alt
336 * setting during probe, that should also be fine. usb_set_interface()
337 * will attempt to disable LPM, and fail if it can't disable it.
338 */
339 lpm_disable_error = usb_unlocked_disable_lpm(udev);
340 if (lpm_disable_error && driver->disable_hub_initiated_lpm) {
341 dev_err(&intf->dev, "%s Failed to disable LPM for driver %s\n.",
342 __func__, driver->name);
343 error = lpm_disable_error;
344 goto err;
345 }
346
327 /* Carry out a deferred switch to altsetting 0 */ 347 /* Carry out a deferred switch to altsetting 0 */
328 if (intf->needs_altsetting0) { 348 if (intf->needs_altsetting0) {
329 error = usb_set_interface(udev, intf->altsetting[0]. 349 error = usb_set_interface(udev, intf->altsetting[0].
@@ -338,6 +358,11 @@ static int usb_probe_interface(struct device *dev)
338 goto err; 358 goto err;
339 359
340 intf->condition = USB_INTERFACE_BOUND; 360 intf->condition = USB_INTERFACE_BOUND;
361
362 /* If the LPM disable succeeded, balance the ref counts. */
363 if (!lpm_disable_error)
364 usb_unlocked_enable_lpm(udev);
365
341 usb_autosuspend_device(udev); 366 usb_autosuspend_device(udev);
342 return error; 367 return error;
343 368
@@ -361,7 +386,7 @@ static int usb_unbind_interface(struct device *dev)
361 struct usb_driver *driver = to_usb_driver(dev->driver); 386 struct usb_driver *driver = to_usb_driver(dev->driver);
362 struct usb_interface *intf = to_usb_interface(dev); 387 struct usb_interface *intf = to_usb_interface(dev);
363 struct usb_device *udev; 388 struct usb_device *udev;
364 int error, r; 389 int error, r, lpm_disable_error;
365 390
366 intf->condition = USB_INTERFACE_UNBINDING; 391 intf->condition = USB_INTERFACE_UNBINDING;
367 392
@@ -369,6 +394,13 @@ static int usb_unbind_interface(struct device *dev)
369 udev = interface_to_usbdev(intf); 394 udev = interface_to_usbdev(intf);
370 error = usb_autoresume_device(udev); 395 error = usb_autoresume_device(udev);
371 396
397 /* Hub-initiated LPM policy may change, so attempt to disable LPM until
398 * the driver is unbound. If LPM isn't disabled, that's fine because it
399 * wouldn't be enabled unless all the bound interfaces supported
400 * hub-initiated LPM.
401 */
402 lpm_disable_error = usb_unlocked_disable_lpm(udev);
403
372 /* Terminate all URBs for this interface unless the driver 404 /* Terminate all URBs for this interface unless the driver
373 * supports "soft" unbinding. 405 * supports "soft" unbinding.
374 */ 406 */
@@ -402,6 +434,10 @@ static int usb_unbind_interface(struct device *dev)
402 intf->condition = USB_INTERFACE_UNBOUND; 434 intf->condition = USB_INTERFACE_UNBOUND;
403 intf->needs_remote_wakeup = 0; 435 intf->needs_remote_wakeup = 0;
404 436
437 /* Attempt to re-enable USB3 LPM, if the disable succeeded. */
438 if (!lpm_disable_error)
439 usb_unlocked_enable_lpm(udev);
440
405 /* Unbound interfaces are always runtime-PM-disabled and -suspended */ 441 /* Unbound interfaces are always runtime-PM-disabled and -suspended */
406 if (driver->supports_autosuspend) 442 if (driver->supports_autosuspend)
407 pm_runtime_disable(dev); 443 pm_runtime_disable(dev);
@@ -442,17 +478,29 @@ int usb_driver_claim_interface(struct usb_driver *driver,
442 struct usb_interface *iface, void *priv) 478 struct usb_interface *iface, void *priv)
443{ 479{
444 struct device *dev = &iface->dev; 480 struct device *dev = &iface->dev;
481 struct usb_device *udev;
445 int retval = 0; 482 int retval = 0;
483 int lpm_disable_error;
446 484
447 if (dev->driver) 485 if (dev->driver)
448 return -EBUSY; 486 return -EBUSY;
449 487
488 udev = interface_to_usbdev(iface);
489
450 dev->driver = &driver->drvwrap.driver; 490 dev->driver = &driver->drvwrap.driver;
451 usb_set_intfdata(iface, priv); 491 usb_set_intfdata(iface, priv);
452 iface->needs_binding = 0; 492 iface->needs_binding = 0;
453 493
454 iface->condition = USB_INTERFACE_BOUND; 494 iface->condition = USB_INTERFACE_BOUND;
455 495
496 /* Disable LPM until this driver is bound. */
497 lpm_disable_error = usb_unlocked_disable_lpm(udev);
498 if (lpm_disable_error && driver->disable_hub_initiated_lpm) {
499 dev_err(&iface->dev, "%s Failed to disable LPM for driver %s\n.",
500 __func__, driver->name);
501 return -ENOMEM;
502 }
503
456 /* Claimed interfaces are initially inactive (suspended) and 504 /* Claimed interfaces are initially inactive (suspended) and
457 * runtime-PM-enabled, but only if the driver has autosuspend 505 * runtime-PM-enabled, but only if the driver has autosuspend
458 * support. Otherwise they are marked active, to prevent the 506 * support. Otherwise they are marked active, to prevent the
@@ -471,6 +519,10 @@ int usb_driver_claim_interface(struct usb_driver *driver,
471 if (device_is_registered(dev)) 519 if (device_is_registered(dev))
472 retval = device_bind_driver(dev); 520 retval = device_bind_driver(dev);
473 521
522 /* Attempt to re-enable USB3 LPM, if the disable was successful. */
523 if (!lpm_disable_error)
524 usb_unlocked_enable_lpm(udev);
525
474 return retval; 526 return retval;
475} 527}
476EXPORT_SYMBOL_GPL(usb_driver_claim_interface); 528EXPORT_SYMBOL_GPL(usb_driver_claim_interface);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 0cd2daacacbe..190b1ec7bdcb 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -997,6 +997,15 @@ static int register_root_hub(struct usb_hcd *hcd)
997 dev_name(&usb_dev->dev), retval); 997 dev_name(&usb_dev->dev), retval);
998 return (retval < 0) ? retval : -EMSGSIZE; 998 return (retval < 0) ? retval : -EMSGSIZE;
999 } 999 }
1000 if (usb_dev->speed == USB_SPEED_SUPER) {
1001 retval = usb_get_bos_descriptor(usb_dev);
1002 if (retval < 0) {
1003 mutex_unlock(&usb_bus_list_lock);
1004 dev_dbg(parent_dev, "can't read %s bos descriptor %d\n",
1005 dev_name(&usb_dev->dev), retval);
1006 return retval;
1007 }
1008 }
1000 1009
1001 retval = usb_new_device (usb_dev); 1010 retval = usb_new_device (usb_dev);
1002 if (retval) { 1011 if (retval) {
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index ec6c97dadbe4..fcc244e9056f 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -177,6 +177,228 @@ static struct usb_hub *hdev_to_hub(struct usb_device *hdev)
177 return usb_get_intfdata(hdev->actconfig->interface[0]); 177 return usb_get_intfdata(hdev->actconfig->interface[0]);
178} 178}
179 179
180static int usb_device_supports_lpm(struct usb_device *udev)
181{
182 /* USB 2.1 (and greater) devices indicate LPM support through
183 * their USB 2.0 Extended Capabilities BOS descriptor.
184 */
185 if (udev->speed == USB_SPEED_HIGH) {
186 if (udev->bos->ext_cap &&
187 (USB_LPM_SUPPORT &
188 le32_to_cpu(udev->bos->ext_cap->bmAttributes)))
189 return 1;
190 return 0;
191 }
192
193 /* All USB 3.0 must support LPM, but we need their max exit latency
194 * information from the SuperSpeed Extended Capabilities BOS descriptor.
195 */
196 if (!udev->bos->ss_cap) {
197 dev_warn(&udev->dev, "No LPM exit latency info found. "
198 "Power management will be impacted.\n");
199 return 0;
200 }
201 if (udev->parent->lpm_capable)
202 return 1;
203
204 dev_warn(&udev->dev, "Parent hub missing LPM exit latency info. "
205 "Power management will be impacted.\n");
206 return 0;
207}
208
209/*
210 * Set the Maximum Exit Latency (MEL) for the host to initiate a transition from
211 * either U1 or U2.
212 */
213static void usb_set_lpm_mel(struct usb_device *udev,
214 struct usb3_lpm_parameters *udev_lpm_params,
215 unsigned int udev_exit_latency,
216 struct usb_hub *hub,
217 struct usb3_lpm_parameters *hub_lpm_params,
218 unsigned int hub_exit_latency)
219{
220 unsigned int total_mel;
221 unsigned int device_mel;
222 unsigned int hub_mel;
223
224 /*
225 * Calculate the time it takes to transition all links from the roothub
226 * to the parent hub into U0. The parent hub must then decode the
227 * packet (hub header decode latency) to figure out which port it was
228 * bound for.
229 *
230 * The Hub Header decode latency is expressed in 0.1us intervals (0x1
231 * means 0.1us). Multiply that by 100 to get nanoseconds.
232 */
233 total_mel = hub_lpm_params->mel +
234 (hub->descriptor->u.ss.bHubHdrDecLat * 100);
235
236 /*
237 * How long will it take to transition the downstream hub's port into
238 * U0? The greater of either the hub exit latency or the device exit
239 * latency.
240 *
241 * The BOS U1/U2 exit latencies are expressed in 1us intervals.
242 * Multiply that by 1000 to get nanoseconds.
243 */
244 device_mel = udev_exit_latency * 1000;
245 hub_mel = hub_exit_latency * 1000;
246 if (device_mel > hub_mel)
247 total_mel += device_mel;
248 else
249 total_mel += hub_mel;
250
251 udev_lpm_params->mel = total_mel;
252}
253
254/*
255 * Set the maximum Device to Host Exit Latency (PEL) for the device to initiate
256 * a transition from either U1 or U2.
257 */
258static void usb_set_lpm_pel(struct usb_device *udev,
259 struct usb3_lpm_parameters *udev_lpm_params,
260 unsigned int udev_exit_latency,
261 struct usb_hub *hub,
262 struct usb3_lpm_parameters *hub_lpm_params,
263 unsigned int hub_exit_latency,
264 unsigned int port_to_port_exit_latency)
265{
266 unsigned int first_link_pel;
267 unsigned int hub_pel;
268
269 /*
270 * First, the device sends an LFPS to transition the link between the
271 * device and the parent hub into U0. The exit latency is the bigger of
272 * the device exit latency or the hub exit latency.
273 */
274 if (udev_exit_latency > hub_exit_latency)
275 first_link_pel = udev_exit_latency * 1000;
276 else
277 first_link_pel = hub_exit_latency * 1000;
278
279 /*
280 * When the hub starts to receive the LFPS, there is a slight delay for
281 * it to figure out that one of the ports is sending an LFPS. Then it
282 * will forward the LFPS to its upstream link. The exit latency is the
283 * delay, plus the PEL that we calculated for this hub.
284 */
285 hub_pel = port_to_port_exit_latency * 1000 + hub_lpm_params->pel;
286
287 /*
288 * According to figure C-7 in the USB 3.0 spec, the PEL for this device
289 * is the greater of the two exit latencies.
290 */
291 if (first_link_pel > hub_pel)
292 udev_lpm_params->pel = first_link_pel;
293 else
294 udev_lpm_params->pel = hub_pel;
295}
296
297/*
298 * Set the System Exit Latency (SEL) to indicate the total worst-case time from
299 * when a device initiates a transition to U0, until when it will receive the
300 * first packet from the host controller.
301 *
302 * Section C.1.5.1 describes the four components to this:
303 * - t1: device PEL
304 * - t2: time for the ERDY to make it from the device to the host.
305 * - t3: a host-specific delay to process the ERDY.
306 * - t4: time for the packet to make it from the host to the device.
307 *
308 * t3 is specific to both the xHCI host and the platform the host is integrated
309 * into. The Intel HW folks have said it's negligible, FIXME if a different
310 * vendor says otherwise.
311 */
312static void usb_set_lpm_sel(struct usb_device *udev,
313 struct usb3_lpm_parameters *udev_lpm_params)
314{
315 struct usb_device *parent;
316 unsigned int num_hubs;
317 unsigned int total_sel;
318
319 /* t1 = device PEL */
320 total_sel = udev_lpm_params->pel;
321 /* How many external hubs are in between the device & the root port. */
322 for (parent = udev->parent, num_hubs = 0; parent->parent;
323 parent = parent->parent)
324 num_hubs++;
325 /* t2 = 2.1us + 250ns * (num_hubs - 1) */
326 if (num_hubs > 0)
327 total_sel += 2100 + 250 * (num_hubs - 1);
328
329 /* t4 = 250ns * num_hubs */
330 total_sel += 250 * num_hubs;
331
332 udev_lpm_params->sel = total_sel;
333}
334
335static void usb_set_lpm_parameters(struct usb_device *udev)
336{
337 struct usb_hub *hub;
338 unsigned int port_to_port_delay;
339 unsigned int udev_u1_del;
340 unsigned int udev_u2_del;
341 unsigned int hub_u1_del;
342 unsigned int hub_u2_del;
343
344 if (!udev->lpm_capable || udev->speed != USB_SPEED_SUPER)
345 return;
346
347 hub = hdev_to_hub(udev->parent);
348 /* It doesn't take time to transition the roothub into U0, since it
349 * doesn't have an upstream link.
350 */
351 if (!hub)
352 return;
353
354 udev_u1_del = udev->bos->ss_cap->bU1devExitLat;
355 udev_u2_del = udev->bos->ss_cap->bU2DevExitLat;
356 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat;
357 hub_u2_del = udev->parent->bos->ss_cap->bU2DevExitLat;
358
359 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del,
360 hub, &udev->parent->u1_params, hub_u1_del);
361
362 usb_set_lpm_mel(udev, &udev->u2_params, udev_u2_del,
363 hub, &udev->parent->u2_params, hub_u2_del);
364
365 /*
366 * Appendix C, section C.2.2.2, says that there is a slight delay from
367 * when the parent hub notices the downstream port is trying to
368 * transition to U0 to when the hub initiates a U0 transition on its
369 * upstream port. The section says the delays are tPort2PortU1EL and
370 * tPort2PortU2EL, but it doesn't define what they are.
371 *
372 * The hub chapter, sections 10.4.2.4 and 10.4.2.5 seem to be talking
373 * about the same delays. Use the maximum delay calculations from those
374 * sections. For U1, it's tHubPort2PortExitLat, which is 1us max. For
375 * U2, it's tHubPort2PortExitLat + U2DevExitLat - U1DevExitLat. I
376 * assume the device exit latencies they are talking about are the hub
377 * exit latencies.
378 *
379 * What do we do if the U2 exit latency is less than the U1 exit
380 * latency? It's possible, although not likely...
381 */
382 port_to_port_delay = 1;
383
384 usb_set_lpm_pel(udev, &udev->u1_params, udev_u1_del,
385 hub, &udev->parent->u1_params, hub_u1_del,
386 port_to_port_delay);
387
388 if (hub_u2_del > hub_u1_del)
389 port_to_port_delay = 1 + hub_u2_del - hub_u1_del;
390 else
391 port_to_port_delay = 1 + hub_u1_del;
392
393 usb_set_lpm_pel(udev, &udev->u2_params, udev_u2_del,
394 hub, &udev->parent->u2_params, hub_u2_del,
395 port_to_port_delay);
396
397 /* Now that we've got PEL, calculate SEL. */
398 usb_set_lpm_sel(udev, &udev->u1_params);
399 usb_set_lpm_sel(udev, &udev->u2_params);
400}
401
180/* USB 2.0 spec Section 11.24.4.5 */ 402/* USB 2.0 spec Section 11.24.4.5 */
181static int get_hub_descriptor(struct usb_device *hdev, void *data) 403static int get_hub_descriptor(struct usb_device *hdev, void *data)
182{ 404{
@@ -2480,6 +2702,12 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2480 if (udev->usb2_hw_lpm_enabled == 1) 2702 if (udev->usb2_hw_lpm_enabled == 1)
2481 usb_set_usb2_hardware_lpm(udev, 0); 2703 usb_set_usb2_hardware_lpm(udev, 0);
2482 2704
2705 if (usb_unlocked_disable_lpm(udev)) {
2706 dev_err(&udev->dev, "%s Failed to disable LPM before suspend\n.",
2707 __func__);
2708 return -ENOMEM;
2709 }
2710
2483 /* see 7.1.7.6 */ 2711 /* see 7.1.7.6 */
2484 if (hub_is_superspeed(hub->hdev)) 2712 if (hub_is_superspeed(hub->hdev))
2485 status = set_port_feature(hub->hdev, 2713 status = set_port_feature(hub->hdev,
@@ -2499,6 +2727,13 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2499 NULL, 0, 2727 NULL, 0,
2500 USB_CTRL_SET_TIMEOUT); 2728 USB_CTRL_SET_TIMEOUT);
2501 2729
2730 /* Try to enable USB2 hardware LPM again */
2731 if (udev->usb2_hw_lpm_capable == 1)
2732 usb_set_usb2_hardware_lpm(udev, 1);
2733
2734 /* Try to enable USB3 LPM again */
2735 usb_unlocked_enable_lpm(udev);
2736
2502 /* System sleep transitions should never fail */ 2737 /* System sleep transitions should never fail */
2503 if (!PMSG_IS_AUTO(msg)) 2738 if (!PMSG_IS_AUTO(msg))
2504 status = 0; 2739 status = 0;
@@ -2696,6 +2931,9 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
2696 /* Try to enable USB2 hardware LPM */ 2931 /* Try to enable USB2 hardware LPM */
2697 if (udev->usb2_hw_lpm_capable == 1) 2932 if (udev->usb2_hw_lpm_capable == 1)
2698 usb_set_usb2_hardware_lpm(udev, 1); 2933 usb_set_usb2_hardware_lpm(udev, 1);
2934
2935 /* Try to enable USB3 LPM */
2936 usb_unlocked_enable_lpm(udev);
2699 } 2937 }
2700 2938
2701 return status; 2939 return status;
@@ -2824,11 +3062,425 @@ void usb_root_hub_lost_power(struct usb_device *rhdev)
2824} 3062}
2825EXPORT_SYMBOL_GPL(usb_root_hub_lost_power); 3063EXPORT_SYMBOL_GPL(usb_root_hub_lost_power);
2826 3064
3065static const char * const usb3_lpm_names[] = {
3066 "U0",
3067 "U1",
3068 "U2",
3069 "U3",
3070};
3071
3072/*
3073 * Send a Set SEL control transfer to the device, prior to enabling
3074 * device-initiated U1 or U2. This lets the device know the exit latencies from
3075 * the time the device initiates a U1 or U2 exit, to the time it will receive a
3076 * packet from the host.
3077 *
3078 * This function will fail if the SEL or PEL values for udev are greater than
3079 * the maximum allowed values for the link state to be enabled.
3080 */
3081static int usb_req_set_sel(struct usb_device *udev, enum usb3_link_state state)
3082{
3083 struct usb_set_sel_req *sel_values;
3084 unsigned long long u1_sel;
3085 unsigned long long u1_pel;
3086 unsigned long long u2_sel;
3087 unsigned long long u2_pel;
3088 int ret;
3089
3090 /* Convert SEL and PEL stored in ns to us */
3091 u1_sel = DIV_ROUND_UP(udev->u1_params.sel, 1000);
3092 u1_pel = DIV_ROUND_UP(udev->u1_params.pel, 1000);
3093 u2_sel = DIV_ROUND_UP(udev->u2_params.sel, 1000);
3094 u2_pel = DIV_ROUND_UP(udev->u2_params.pel, 1000);
3095
3096 /*
3097 * Make sure that the calculated SEL and PEL values for the link
3098 * state we're enabling aren't bigger than the max SEL/PEL
3099 * value that will fit in the SET SEL control transfer.
3100 * Otherwise the device would get an incorrect idea of the exit
3101 * latency for the link state, and could start a device-initiated
3102 * U1/U2 when the exit latencies are too high.
3103 */
3104 if ((state == USB3_LPM_U1 &&
3105 (u1_sel > USB3_LPM_MAX_U1_SEL_PEL ||
3106 u1_pel > USB3_LPM_MAX_U1_SEL_PEL)) ||
3107 (state == USB3_LPM_U2 &&
3108 (u2_sel > USB3_LPM_MAX_U2_SEL_PEL ||
3109 u2_pel > USB3_LPM_MAX_U2_SEL_PEL))) {
3110 dev_dbg(&udev->dev, "Device-initiated %s disabled due "
3111 "to long SEL %llu ms or PEL %llu ms\n",
3112 usb3_lpm_names[state], u1_sel, u1_pel);
3113 return -EINVAL;
3114 }
3115
3116 /*
3117 * If we're enabling device-initiated LPM for one link state,
3118 * but the other link state has a too high SEL or PEL value,
3119 * just set those values to the max in the Set SEL request.
3120 */
3121 if (u1_sel > USB3_LPM_MAX_U1_SEL_PEL)
3122 u1_sel = USB3_LPM_MAX_U1_SEL_PEL;
3123
3124 if (u1_pel > USB3_LPM_MAX_U1_SEL_PEL)
3125 u1_pel = USB3_LPM_MAX_U1_SEL_PEL;
3126
3127 if (u2_sel > USB3_LPM_MAX_U2_SEL_PEL)
3128 u2_sel = USB3_LPM_MAX_U2_SEL_PEL;
3129
3130 if (u2_pel > USB3_LPM_MAX_U2_SEL_PEL)
3131 u2_pel = USB3_LPM_MAX_U2_SEL_PEL;
3132
3133 /*
3134 * usb_enable_lpm() can be called as part of a failed device reset,
3135 * which may be initiated by an error path of a mass storage driver.
3136 * Therefore, use GFP_NOIO.
3137 */
3138 sel_values = kmalloc(sizeof *(sel_values), GFP_NOIO);
3139 if (!sel_values)
3140 return -ENOMEM;
3141
3142 sel_values->u1_sel = u1_sel;
3143 sel_values->u1_pel = u1_pel;
3144 sel_values->u2_sel = cpu_to_le16(u2_sel);
3145 sel_values->u2_pel = cpu_to_le16(u2_pel);
3146
3147 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
3148 USB_REQ_SET_SEL,
3149 USB_RECIP_DEVICE,
3150 0, 0,
3151 sel_values, sizeof *(sel_values),
3152 USB_CTRL_SET_TIMEOUT);
3153 kfree(sel_values);
3154 return ret;
3155}
3156
3157/*
3158 * Enable or disable device-initiated U1 or U2 transitions.
3159 */
3160static int usb_set_device_initiated_lpm(struct usb_device *udev,
3161 enum usb3_link_state state, bool enable)
3162{
3163 int ret;
3164 int feature;
3165
3166 switch (state) {
3167 case USB3_LPM_U1:
3168 feature = USB_DEVICE_U1_ENABLE;
3169 break;
3170 case USB3_LPM_U2:
3171 feature = USB_DEVICE_U2_ENABLE;
3172 break;
3173 default:
3174 dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n",
3175 __func__, enable ? "enable" : "disable");
3176 return -EINVAL;
3177 }
3178
3179 if (udev->state != USB_STATE_CONFIGURED) {
3180 dev_dbg(&udev->dev, "%s: Can't %s %s state "
3181 "for unconfigured device.\n",
3182 __func__, enable ? "enable" : "disable",
3183 usb3_lpm_names[state]);
3184 return 0;
3185 }
3186
3187 if (enable) {
3188 /*
3189 * First, let the device know about the exit latencies
3190 * associated with the link state we're about to enable.
3191 */
3192 ret = usb_req_set_sel(udev, state);
3193 if (ret < 0) {
3194 dev_warn(&udev->dev, "Set SEL for device-initiated "
3195 "%s failed.\n", usb3_lpm_names[state]);
3196 return -EBUSY;
3197 }
3198 /*
3199 * Now send the control transfer to enable device-initiated LPM
3200 * for either U1 or U2.
3201 */
3202 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
3203 USB_REQ_SET_FEATURE,
3204 USB_RECIP_DEVICE,
3205 feature,
3206 0, NULL, 0,
3207 USB_CTRL_SET_TIMEOUT);
3208 } else {
3209 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
3210 USB_REQ_CLEAR_FEATURE,
3211 USB_RECIP_DEVICE,
3212 feature,
3213 0, NULL, 0,
3214 USB_CTRL_SET_TIMEOUT);
3215 }
3216 if (ret < 0) {
3217 dev_warn(&udev->dev, "%s of device-initiated %s failed.\n",
3218 enable ? "Enable" : "Disable",
3219 usb3_lpm_names[state]);
3220 return -EBUSY;
3221 }
3222 return 0;
3223}
3224
3225static int usb_set_lpm_timeout(struct usb_device *udev,
3226 enum usb3_link_state state, int timeout)
3227{
3228 int ret;
3229 int feature;
3230
3231 switch (state) {
3232 case USB3_LPM_U1:
3233 feature = USB_PORT_FEAT_U1_TIMEOUT;
3234 break;
3235 case USB3_LPM_U2:
3236 feature = USB_PORT_FEAT_U2_TIMEOUT;
3237 break;
3238 default:
3239 dev_warn(&udev->dev, "%s: Can't set timeout for non-U1 or U2 state.\n",
3240 __func__);
3241 return -EINVAL;
3242 }
3243
3244 if (state == USB3_LPM_U1 && timeout > USB3_LPM_U1_MAX_TIMEOUT &&
3245 timeout != USB3_LPM_DEVICE_INITIATED) {
3246 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x, "
3247 "which is a reserved value.\n",
3248 usb3_lpm_names[state], timeout);
3249 return -EINVAL;
3250 }
3251
3252 ret = set_port_feature(udev->parent,
3253 USB_PORT_LPM_TIMEOUT(timeout) | udev->portnum,
3254 feature);
3255 if (ret < 0) {
3256 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x,"
3257 "error code %i\n", usb3_lpm_names[state],
3258 timeout, ret);
3259 return -EBUSY;
3260 }
3261 if (state == USB3_LPM_U1)
3262 udev->u1_params.timeout = timeout;
3263 else
3264 udev->u2_params.timeout = timeout;
3265 return 0;
3266}
3267
3268/*
3269 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
3270 * U1/U2 entry.
3271 *
3272 * We will attempt to enable U1 or U2, but there are no guarantees that the
3273 * control transfers to set the hub timeout or enable device-initiated U1/U2
3274 * will be successful.
3275 *
3276 * If we cannot set the parent hub U1/U2 timeout, we attempt to let the xHCI
3277 * driver know about it. If that call fails, it should be harmless, and just
3278 * take up more slightly more bus bandwidth for unnecessary U1/U2 exit latency.
3279 */
3280static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev,
3281 enum usb3_link_state state)
3282{
3283 int timeout;
3284
3285 /* We allow the host controller to set the U1/U2 timeout internally
3286 * first, so that it can change its schedule to account for the
3287 * additional latency to send data to a device in a lower power
3288 * link state.
3289 */
3290 timeout = hcd->driver->enable_usb3_lpm_timeout(hcd, udev, state);
3291
3292 /* xHCI host controller doesn't want to enable this LPM state. */
3293 if (timeout == 0)
3294 return;
3295
3296 if (timeout < 0) {
3297 dev_warn(&udev->dev, "Could not enable %s link state, "
3298 "xHCI error %i.\n", usb3_lpm_names[state],
3299 timeout);
3300 return;
3301 }
3302
3303 if (usb_set_lpm_timeout(udev, state, timeout))
3304 /* If we can't set the parent hub U1/U2 timeout,
3305 * device-initiated LPM won't be allowed either, so let the xHCI
3306 * host know that this link state won't be enabled.
3307 */
3308 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state);
3309
3310 /* Only a configured device will accept the Set Feature U1/U2_ENABLE */
3311 else if (udev->actconfig)
3312 usb_set_device_initiated_lpm(udev, state, true);
3313
3314}
3315
3316/*
3317 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
3318 * U1/U2 entry.
3319 *
3320 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
3321 * If zero is returned, the parent will not allow the link to go into U1/U2.
3322 *
3323 * If zero is returned, device-initiated U1/U2 entry may still be enabled, but
3324 * it won't have an effect on the bus link state because the parent hub will
3325 * still disallow device-initiated U1/U2 entry.
3326 *
3327 * If zero is returned, the xHCI host controller may still think U1/U2 entry is
3328 * possible. The result will be slightly more bus bandwidth will be taken up
3329 * (to account for U1/U2 exit latency), but it should be harmless.
3330 */
3331static int usb_disable_link_state(struct usb_hcd *hcd, struct usb_device *udev,
3332 enum usb3_link_state state)
3333{
3334 int feature;
3335
3336 switch (state) {
3337 case USB3_LPM_U1:
3338 feature = USB_PORT_FEAT_U1_TIMEOUT;
3339 break;
3340 case USB3_LPM_U2:
3341 feature = USB_PORT_FEAT_U2_TIMEOUT;
3342 break;
3343 default:
3344 dev_warn(&udev->dev, "%s: Can't disable non-U1 or U2 state.\n",
3345 __func__);
3346 return -EINVAL;
3347 }
3348
3349 if (usb_set_lpm_timeout(udev, state, 0))
3350 return -EBUSY;
3351
3352 usb_set_device_initiated_lpm(udev, state, false);
3353
3354 if (hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state))
3355 dev_warn(&udev->dev, "Could not disable xHCI %s timeout, "
3356 "bus schedule bandwidth may be impacted.\n",
3357 usb3_lpm_names[state]);
3358 return 0;
3359}
3360
3361/*
3362 * Disable hub-initiated and device-initiated U1 and U2 entry.
3363 * Caller must own the bandwidth_mutex.
3364 *
3365 * This will call usb_enable_lpm() on failure, which will decrement
3366 * lpm_disable_count, and will re-enable LPM if lpm_disable_count reaches zero.
3367 */
3368int usb_disable_lpm(struct usb_device *udev)
3369{
3370 struct usb_hcd *hcd;
3371
3372 if (!udev || !udev->parent ||
3373 udev->speed != USB_SPEED_SUPER ||
3374 !udev->lpm_capable)
3375 return 0;
3376
3377 hcd = bus_to_hcd(udev->bus);
3378 if (!hcd || !hcd->driver->disable_usb3_lpm_timeout)
3379 return 0;
3380
3381 udev->lpm_disable_count++;
3382 if ((udev->u1_params.timeout == 0 && udev->u1_params.timeout == 0))
3383 return 0;
3384
3385 /* If LPM is enabled, attempt to disable it. */
3386 if (usb_disable_link_state(hcd, udev, USB3_LPM_U1))
3387 goto enable_lpm;
3388 if (usb_disable_link_state(hcd, udev, USB3_LPM_U2))
3389 goto enable_lpm;
3390
3391 return 0;
3392
3393enable_lpm:
3394 usb_enable_lpm(udev);
3395 return -EBUSY;
3396}
3397EXPORT_SYMBOL_GPL(usb_disable_lpm);
3398
3399/* Grab the bandwidth_mutex before calling usb_disable_lpm() */
3400int usb_unlocked_disable_lpm(struct usb_device *udev)
3401{
3402 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
3403 int ret;
3404
3405 if (!hcd)
3406 return -EINVAL;
3407
3408 mutex_lock(hcd->bandwidth_mutex);
3409 ret = usb_disable_lpm(udev);
3410 mutex_unlock(hcd->bandwidth_mutex);
3411
3412 return ret;
3413}
3414EXPORT_SYMBOL_GPL(usb_unlocked_disable_lpm);
3415
3416/*
3417 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
3418 * xHCI host policy may prevent U1 or U2 from being enabled.
3419 *
3420 * Other callers may have disabled link PM, so U1 and U2 entry will be disabled
3421 * until the lpm_disable_count drops to zero. Caller must own the
3422 * bandwidth_mutex.
3423 */
3424void usb_enable_lpm(struct usb_device *udev)
3425{
3426 struct usb_hcd *hcd;
3427
3428 if (!udev || !udev->parent ||
3429 udev->speed != USB_SPEED_SUPER ||
3430 !udev->lpm_capable)
3431 return;
3432
3433 udev->lpm_disable_count--;
3434 hcd = bus_to_hcd(udev->bus);
3435 /* Double check that we can both enable and disable LPM.
3436 * Device must be configured to accept set feature U1/U2 timeout.
3437 */
3438 if (!hcd || !hcd->driver->enable_usb3_lpm_timeout ||
3439 !hcd->driver->disable_usb3_lpm_timeout)
3440 return;
3441
3442 if (udev->lpm_disable_count > 0)
3443 return;
3444
3445 usb_enable_link_state(hcd, udev, USB3_LPM_U1);
3446 usb_enable_link_state(hcd, udev, USB3_LPM_U2);
3447}
3448EXPORT_SYMBOL_GPL(usb_enable_lpm);
3449
3450/* Grab the bandwidth_mutex before calling usb_enable_lpm() */
3451void usb_unlocked_enable_lpm(struct usb_device *udev)
3452{
3453 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
3454
3455 if (!hcd)
3456 return;
3457
3458 mutex_lock(hcd->bandwidth_mutex);
3459 usb_enable_lpm(udev);
3460 mutex_unlock(hcd->bandwidth_mutex);
3461}
3462EXPORT_SYMBOL_GPL(usb_unlocked_enable_lpm);
3463
3464
2827#else /* CONFIG_PM */ 3465#else /* CONFIG_PM */
2828 3466
2829#define hub_suspend NULL 3467#define hub_suspend NULL
2830#define hub_resume NULL 3468#define hub_resume NULL
2831#define hub_reset_resume NULL 3469#define hub_reset_resume NULL
3470
3471int usb_disable_lpm(struct usb_device *udev)
3472{
3473 return 0;
3474}
3475
3476void usb_enable_lpm(struct usb_device *udev) { }
3477
3478int usb_unlocked_disable_lpm(struct usb_device *udev)
3479{
3480 return 0;
3481}
3482
3483void usb_unlocked_enable_lpm(struct usb_device *udev) { }
2832#endif 3484#endif
2833 3485
2834 3486
@@ -3208,9 +3860,8 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
3208 if (udev->wusb == 0 && le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { 3860 if (udev->wusb == 0 && le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) {
3209 retval = usb_get_bos_descriptor(udev); 3861 retval = usb_get_bos_descriptor(udev);
3210 if (!retval) { 3862 if (!retval) {
3211 if (udev->bos->ext_cap && (USB_LPM_SUPPORT & 3863 udev->lpm_capable = usb_device_supports_lpm(udev);
3212 le32_to_cpu(udev->bos->ext_cap->bmAttributes))) 3864 usb_set_lpm_parameters(udev);
3213 udev->lpm_capable = 1;
3214 } 3865 }
3215 } 3866 }
3216 3867
@@ -4042,11 +4693,22 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
4042 goto done; 4693 goto done;
4043 4694
4044 mutex_lock(hcd->bandwidth_mutex); 4695 mutex_lock(hcd->bandwidth_mutex);
4696 /* Disable LPM while we reset the device and reinstall the alt settings.
4697 * Device-initiated LPM settings, and system exit latency settings are
4698 * cleared when the device is reset, so we have to set them up again.
4699 */
4700 ret = usb_disable_lpm(udev);
4701 if (ret) {
4702 dev_err(&udev->dev, "%s Failed to disable LPM\n.", __func__);
4703 mutex_unlock(hcd->bandwidth_mutex);
4704 goto done;
4705 }
4045 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); 4706 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL);
4046 if (ret < 0) { 4707 if (ret < 0) {
4047 dev_warn(&udev->dev, 4708 dev_warn(&udev->dev,
4048 "Busted HC? Not enough HCD resources for " 4709 "Busted HC? Not enough HCD resources for "
4049 "old configuration.\n"); 4710 "old configuration.\n");
4711 usb_enable_lpm(udev);
4050 mutex_unlock(hcd->bandwidth_mutex); 4712 mutex_unlock(hcd->bandwidth_mutex);
4051 goto re_enumerate; 4713 goto re_enumerate;
4052 } 4714 }
@@ -4058,6 +4720,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
4058 dev_err(&udev->dev, 4720 dev_err(&udev->dev,
4059 "can't restore configuration #%d (error=%d)\n", 4721 "can't restore configuration #%d (error=%d)\n",
4060 udev->actconfig->desc.bConfigurationValue, ret); 4722 udev->actconfig->desc.bConfigurationValue, ret);
4723 usb_enable_lpm(udev);
4061 mutex_unlock(hcd->bandwidth_mutex); 4724 mutex_unlock(hcd->bandwidth_mutex);
4062 goto re_enumerate; 4725 goto re_enumerate;
4063 } 4726 }
@@ -4096,10 +4759,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
4096 desc->bInterfaceNumber, 4759 desc->bInterfaceNumber,
4097 desc->bAlternateSetting, 4760 desc->bAlternateSetting,
4098 ret); 4761 ret);
4762 usb_unlocked_enable_lpm(udev);
4099 goto re_enumerate; 4763 goto re_enumerate;
4100 } 4764 }
4101 } 4765 }
4102 4766
4767 /* Now that the alt settings are re-installed, enable LPM. */
4768 usb_unlocked_enable_lpm(udev);
4103done: 4769done:
4104 return 0; 4770 return 0;
4105 4771
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index ca717da3be95..b548cf1dbc62 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1308,10 +1308,19 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1308 * Remove the current alt setting and add the new alt setting. 1308 * Remove the current alt setting and add the new alt setting.
1309 */ 1309 */
1310 mutex_lock(hcd->bandwidth_mutex); 1310 mutex_lock(hcd->bandwidth_mutex);
1311 /* Disable LPM, and re-enable it once the new alt setting is installed,
1312 * so that the xHCI driver can recalculate the U1/U2 timeouts.
1313 */
1314 if (usb_disable_lpm(dev)) {
1315 dev_err(&iface->dev, "%s Failed to disable LPM\n.", __func__);
1316 mutex_unlock(hcd->bandwidth_mutex);
1317 return -ENOMEM;
1318 }
1311 ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt); 1319 ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt);
1312 if (ret < 0) { 1320 if (ret < 0) {
1313 dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n", 1321 dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n",
1314 alternate); 1322 alternate);
1323 usb_enable_lpm(dev);
1315 mutex_unlock(hcd->bandwidth_mutex); 1324 mutex_unlock(hcd->bandwidth_mutex);
1316 return ret; 1325 return ret;
1317 } 1326 }
@@ -1334,6 +1343,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1334 } else if (ret < 0) { 1343 } else if (ret < 0) {
1335 /* Re-instate the old alt setting */ 1344 /* Re-instate the old alt setting */
1336 usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting); 1345 usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting);
1346 usb_enable_lpm(dev);
1337 mutex_unlock(hcd->bandwidth_mutex); 1347 mutex_unlock(hcd->bandwidth_mutex);
1338 return ret; 1348 return ret;
1339 } 1349 }
@@ -1354,6 +1364,9 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1354 1364
1355 iface->cur_altsetting = alt; 1365 iface->cur_altsetting = alt;
1356 1366
1367 /* Now that the interface is installed, re-enable LPM. */
1368 usb_unlocked_enable_lpm(dev);
1369
1357 /* If the interface only has one altsetting and the device didn't 1370 /* If the interface only has one altsetting and the device didn't
1358 * accept the request, we attempt to carry out the equivalent action 1371 * accept the request, we attempt to carry out the equivalent action
1359 * by manually clearing the HALT feature for each endpoint in the 1372 * by manually clearing the HALT feature for each endpoint in the
@@ -1437,6 +1450,14 @@ int usb_reset_configuration(struct usb_device *dev)
1437 config = dev->actconfig; 1450 config = dev->actconfig;
1438 retval = 0; 1451 retval = 0;
1439 mutex_lock(hcd->bandwidth_mutex); 1452 mutex_lock(hcd->bandwidth_mutex);
1453 /* Disable LPM, and re-enable it once the configuration is reset, so
1454 * that the xHCI driver can recalculate the U1/U2 timeouts.
1455 */
1456 if (usb_disable_lpm(dev)) {
1457 dev_err(&dev->dev, "%s Failed to disable LPM\n.", __func__);
1458 mutex_unlock(hcd->bandwidth_mutex);
1459 return -ENOMEM;
1460 }
1440 /* Make sure we have enough bandwidth for each alternate setting 0 */ 1461 /* Make sure we have enough bandwidth for each alternate setting 0 */
1441 for (i = 0; i < config->desc.bNumInterfaces; i++) { 1462 for (i = 0; i < config->desc.bNumInterfaces; i++) {
1442 struct usb_interface *intf = config->interface[i]; 1463 struct usb_interface *intf = config->interface[i];
@@ -1465,6 +1486,7 @@ reset_old_alts:
1465 usb_hcd_alloc_bandwidth(dev, NULL, 1486 usb_hcd_alloc_bandwidth(dev, NULL,
1466 alt, intf->cur_altsetting); 1487 alt, intf->cur_altsetting);
1467 } 1488 }
1489 usb_enable_lpm(dev);
1468 mutex_unlock(hcd->bandwidth_mutex); 1490 mutex_unlock(hcd->bandwidth_mutex);
1469 return retval; 1491 return retval;
1470 } 1492 }
@@ -1502,6 +1524,8 @@ reset_old_alts:
1502 create_intf_ep_devs(intf); 1524 create_intf_ep_devs(intf);
1503 } 1525 }
1504 } 1526 }
1527 /* Now that the interfaces are installed, re-enable LPM. */
1528 usb_unlocked_enable_lpm(dev);
1505 return 0; 1529 return 0;
1506} 1530}
1507EXPORT_SYMBOL_GPL(usb_reset_configuration); 1531EXPORT_SYMBOL_GPL(usb_reset_configuration);
@@ -1763,8 +1787,18 @@ free_interfaces:
1763 * this call fails, the device state is unchanged. 1787 * this call fails, the device state is unchanged.
1764 */ 1788 */
1765 mutex_lock(hcd->bandwidth_mutex); 1789 mutex_lock(hcd->bandwidth_mutex);
1790 /* Disable LPM, and re-enable it once the new configuration is
1791 * installed, so that the xHCI driver can recalculate the U1/U2
1792 * timeouts.
1793 */
1794 if (usb_disable_lpm(dev)) {
1795 dev_err(&dev->dev, "%s Failed to disable LPM\n.", __func__);
1796 mutex_unlock(hcd->bandwidth_mutex);
1797 return -ENOMEM;
1798 }
1766 ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); 1799 ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL);
1767 if (ret < 0) { 1800 if (ret < 0) {
1801 usb_enable_lpm(dev);
1768 mutex_unlock(hcd->bandwidth_mutex); 1802 mutex_unlock(hcd->bandwidth_mutex);
1769 usb_autosuspend_device(dev); 1803 usb_autosuspend_device(dev);
1770 goto free_interfaces; 1804 goto free_interfaces;
@@ -1784,6 +1818,7 @@ free_interfaces:
1784 if (!cp) { 1818 if (!cp) {
1785 usb_set_device_state(dev, USB_STATE_ADDRESS); 1819 usb_set_device_state(dev, USB_STATE_ADDRESS);
1786 usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); 1820 usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL);
1821 usb_enable_lpm(dev);
1787 mutex_unlock(hcd->bandwidth_mutex); 1822 mutex_unlock(hcd->bandwidth_mutex);
1788 usb_autosuspend_device(dev); 1823 usb_autosuspend_device(dev);
1789 goto free_interfaces; 1824 goto free_interfaces;
@@ -1838,6 +1873,9 @@ free_interfaces:
1838 !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS)) 1873 !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
1839 cp->string = usb_cache_string(dev, cp->desc.iConfiguration); 1874 cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
1840 1875
1876 /* Now that the interfaces are installed, re-enable LPM. */
1877 usb_unlocked_enable_lpm(dev);
1878
1841 /* Now that all the interfaces are set up, register them 1879 /* Now that all the interfaces are set up, register them
1842 * to trigger binding of drivers to interfaces. probe() 1880 * to trigger binding of drivers to interfaces. probe()
1843 * routines may install different altsettings and may 1881 * routines may install different altsettings and may
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 89850a82d51b..2732ef660c5c 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -475,6 +475,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
475 struct xhci_bus_state *bus_state; 475 struct xhci_bus_state *bus_state;
476 u16 link_state = 0; 476 u16 link_state = 0;
477 u16 wake_mask = 0; 477 u16 wake_mask = 0;
478 u16 timeout = 0;
478 479
479 max_ports = xhci_get_ports(hcd, &port_array); 480 max_ports = xhci_get_ports(hcd, &port_array);
480 bus_state = &xhci->bus_state[hcd_index(hcd)]; 481 bus_state = &xhci->bus_state[hcd_index(hcd)];
@@ -623,6 +624,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
623 link_state = (wIndex & 0xff00) >> 3; 624 link_state = (wIndex & 0xff00) >> 3;
624 if (wValue == USB_PORT_FEAT_REMOTE_WAKE_MASK) 625 if (wValue == USB_PORT_FEAT_REMOTE_WAKE_MASK)
625 wake_mask = wIndex & 0xff00; 626 wake_mask = wIndex & 0xff00;
627 /* The MSB of wIndex is the U1/U2 timeout */
628 timeout = (wIndex & 0xff00) >> 8;
626 wIndex &= 0xff; 629 wIndex &= 0xff;
627 if (!wIndex || wIndex > max_ports) 630 if (!wIndex || wIndex > max_ports)
628 goto error; 631 goto error;
@@ -747,6 +750,22 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
747 750
748 temp = xhci_readl(xhci, port_array[wIndex]); 751 temp = xhci_readl(xhci, port_array[wIndex]);
749 break; 752 break;
753 case USB_PORT_FEAT_U1_TIMEOUT:
754 if (hcd->speed != HCD_USB3)
755 goto error;
756 temp = xhci_readl(xhci, port_array[wIndex] + 1);
757 temp &= ~PORT_U1_TIMEOUT_MASK;
758 temp |= PORT_U1_TIMEOUT(timeout);
759 xhci_writel(xhci, temp, port_array[wIndex] + 1);
760 break;
761 case USB_PORT_FEAT_U2_TIMEOUT:
762 if (hcd->speed != HCD_USB3)
763 goto error;
764 temp = xhci_readl(xhci, port_array[wIndex] + 1);
765 temp &= ~PORT_U2_TIMEOUT_MASK;
766 temp |= PORT_U2_TIMEOUT(timeout);
767 xhci_writel(xhci, temp, port_array[wIndex] + 1);
768 break;
750 default: 769 default:
751 goto error; 770 goto error;
752 } 771 }
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 68eaa908ac8e..ec4338eec826 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1791,6 +1791,14 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1791{ 1791{
1792 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 1792 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
1793 struct dev_info *dev_info, *next; 1793 struct dev_info *dev_info, *next;
1794 struct list_head *tt_list_head;
1795 struct list_head *tt;
1796 struct list_head *endpoints;
1797 struct list_head *ep, *q;
1798 struct xhci_tt_bw_info *tt_info;
1799 struct xhci_interval_bw_table *bwt;
1800 struct xhci_virt_ep *virt_ep;
1801
1794 unsigned long flags; 1802 unsigned long flags;
1795 int size; 1803 int size;
1796 int i; 1804 int i;
@@ -1807,6 +1815,9 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1807 xhci->event_ring = NULL; 1815 xhci->event_ring = NULL;
1808 xhci_dbg(xhci, "Freed event ring\n"); 1816 xhci_dbg(xhci, "Freed event ring\n");
1809 1817
1818 if (xhci->lpm_command)
1819 xhci_free_command(xhci, xhci->lpm_command);
1820 xhci->cmd_ring_reserved_trbs = 0;
1810 if (xhci->cmd_ring) 1821 if (xhci->cmd_ring)
1811 xhci_ring_free(xhci, xhci->cmd_ring); 1822 xhci_ring_free(xhci, xhci->cmd_ring);
1812 xhci->cmd_ring = NULL; 1823 xhci->cmd_ring = NULL;
@@ -1849,8 +1860,26 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1849 } 1860 }
1850 spin_unlock_irqrestore(&xhci->lock, flags); 1861 spin_unlock_irqrestore(&xhci->lock, flags);
1851 1862
1863 bwt = &xhci->rh_bw->bw_table;
1864 for (i = 0; i < XHCI_MAX_INTERVAL; i++) {
1865 endpoints = &bwt->interval_bw[i].endpoints;
1866 list_for_each_safe(ep, q, endpoints) {
1867 virt_ep = list_entry(ep, struct xhci_virt_ep, bw_endpoint_list);
1868 list_del(&virt_ep->bw_endpoint_list);
1869 kfree(virt_ep);
1870 }
1871 }
1872
1873 tt_list_head = &xhci->rh_bw->tts;
1874 list_for_each_safe(tt, q, tt_list_head) {
1875 tt_info = list_entry(tt, struct xhci_tt_bw_info, tt_list);
1876 list_del(tt);
1877 kfree(tt_info);
1878 }
1879
1852 xhci->num_usb2_ports = 0; 1880 xhci->num_usb2_ports = 0;
1853 xhci->num_usb3_ports = 0; 1881 xhci->num_usb3_ports = 0;
1882 xhci->num_active_eps = 0;
1854 kfree(xhci->usb2_ports); 1883 kfree(xhci->usb2_ports);
1855 kfree(xhci->usb3_ports); 1884 kfree(xhci->usb3_ports);
1856 kfree(xhci->port_array); 1885 kfree(xhci->port_array);
@@ -2350,6 +2379,16 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2350 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); 2379 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
2351 xhci_dbg_cmd_ptrs(xhci); 2380 xhci_dbg_cmd_ptrs(xhci);
2352 2381
2382 xhci->lpm_command = xhci_alloc_command(xhci, true, true, flags);
2383 if (!xhci->lpm_command)
2384 goto fail;
2385
2386 /* Reserve one command ring TRB for disabling LPM.
2387 * Since the USB core grabs the shared usb_bus bandwidth mutex before
2388 * disabling LPM, we only need to reserve one TRB for all devices.
2389 */
2390 xhci->cmd_ring_reserved_trbs++;
2391
2353 val = xhci_readl(xhci, &xhci->cap_regs->db_off); 2392 val = xhci_readl(xhci, &xhci->cap_regs->db_off);
2354 val &= DBOFF_MASK; 2393 val &= DBOFF_MASK;
2355 xhci_dbg(xhci, "// Doorbell array is located at offset 0x%x" 2394 xhci_dbg(xhci, "// Doorbell array is located at offset 0x%x"
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 7a856a767e77..18b231b0c5d3 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -72,6 +72,7 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
72 xhci_dbg(xhci, "QUIRK: Fresco Logic revision %u " 72 xhci_dbg(xhci, "QUIRK: Fresco Logic revision %u "
73 "has broken MSI implementation\n", 73 "has broken MSI implementation\n",
74 pdev->revision); 74 pdev->revision);
75 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
75 } 76 }
76 77
77 if (pdev->vendor == PCI_VENDOR_ID_NEC) 78 if (pdev->vendor == PCI_VENDOR_ID_NEC)
@@ -83,6 +84,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
83 /* AMD PLL quirk */ 84 /* AMD PLL quirk */
84 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info()) 85 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info())
85 xhci->quirks |= XHCI_AMD_PLL_FIX; 86 xhci->quirks |= XHCI_AMD_PLL_FIX;
87 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
88 xhci->quirks |= XHCI_LPM_SUPPORT;
89 xhci->quirks |= XHCI_INTEL_HOST;
90 }
86 if (pdev->vendor == PCI_VENDOR_ID_INTEL && 91 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
87 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) { 92 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) {
88 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; 93 xhci->quirks |= XHCI_SPURIOUS_SUCCESS;
@@ -169,6 +174,13 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
169 if (retval) 174 if (retval)
170 goto put_usb3_hcd; 175 goto put_usb3_hcd;
171 /* Roothub already marked as USB 3.0 speed */ 176 /* Roothub already marked as USB 3.0 speed */
177
178 /* We know the LPM timeout algorithms for this host, let the USB core
179 * enable and disable LPM for devices under the USB 3.0 roothub.
180 */
181 if (xhci->quirks & XHCI_LPM_SUPPORT)
182 hcd_to_bus(xhci->shared_hcd)->root_hub->lpm_capable = 1;
183
172 return 0; 184 return 0;
173 185
174put_usb3_hcd: 186put_usb3_hcd:
@@ -292,6 +304,8 @@ static const struct hc_driver xhci_pci_hc_driver = {
292 */ 304 */
293 .update_device = xhci_update_device, 305 .update_device = xhci_update_device,
294 .set_usb2_hw_lpm = xhci_set_usb2_hardware_lpm, 306 .set_usb2_hw_lpm = xhci_set_usb2_hardware_lpm,
307 .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout,
308 .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout,
295}; 309};
296 310
297/*-------------------------------------------------------------------------*/ 311/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 329fd2a98dd6..23b4aefd1036 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1787,8 +1787,12 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
1787 /* handle completion code */ 1787 /* handle completion code */
1788 switch (trb_comp_code) { 1788 switch (trb_comp_code) {
1789 case COMP_SUCCESS: 1789 case COMP_SUCCESS:
1790 frame->status = 0; 1790 if (TRB_LEN(le32_to_cpu(event->transfer_len)) == 0) {
1791 break; 1791 frame->status = 0;
1792 break;
1793 }
1794 if ((xhci->quirks & XHCI_TRUST_TX_LENGTH))
1795 trb_comp_code = COMP_SHORT_TX;
1792 case COMP_SHORT_TX: 1796 case COMP_SHORT_TX:
1793 frame->status = td->urb->transfer_flags & URB_SHORT_NOT_OK ? 1797 frame->status = td->urb->transfer_flags & URB_SHORT_NOT_OK ?
1794 -EREMOTEIO : 0; 1798 -EREMOTEIO : 0;
@@ -1885,13 +1889,16 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
1885 switch (trb_comp_code) { 1889 switch (trb_comp_code) {
1886 case COMP_SUCCESS: 1890 case COMP_SUCCESS:
1887 /* Double check that the HW transferred everything. */ 1891 /* Double check that the HW transferred everything. */
1888 if (event_trb != td->last_trb) { 1892 if (event_trb != td->last_trb ||
1893 TRB_LEN(le32_to_cpu(event->transfer_len)) != 0) {
1889 xhci_warn(xhci, "WARN Successful completion " 1894 xhci_warn(xhci, "WARN Successful completion "
1890 "on short TX\n"); 1895 "on short TX\n");
1891 if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1896 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1892 *status = -EREMOTEIO; 1897 *status = -EREMOTEIO;
1893 else 1898 else
1894 *status = 0; 1899 *status = 0;
1900 if ((xhci->quirks & XHCI_TRUST_TX_LENGTH))
1901 trb_comp_code = COMP_SHORT_TX;
1895 } else { 1902 } else {
1896 *status = 0; 1903 *status = 0;
1897 } 1904 }
@@ -2050,6 +2057,13 @@ static int handle_tx_event(struct xhci_hcd *xhci,
2050 * transfer type 2057 * transfer type
2051 */ 2058 */
2052 case COMP_SUCCESS: 2059 case COMP_SUCCESS:
2060 if (TRB_LEN(le32_to_cpu(event->transfer_len)) == 0)
2061 break;
2062 if (xhci->quirks & XHCI_TRUST_TX_LENGTH)
2063 trb_comp_code = COMP_SHORT_TX;
2064 else
2065 xhci_warn(xhci, "WARN Successful completion on short TX: "
2066 "needs XHCI_TRUST_TX_LENGTH quirk?\n");
2053 case COMP_SHORT_TX: 2067 case COMP_SHORT_TX:
2054 break; 2068 break;
2055 case COMP_STOP: 2069 case COMP_STOP:
@@ -3595,12 +3609,12 @@ int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
3595 3609
3596/* Queue an evaluate context command TRB */ 3610/* Queue an evaluate context command TRB */
3597int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 3611int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
3598 u32 slot_id) 3612 u32 slot_id, bool command_must_succeed)
3599{ 3613{
3600 return queue_command(xhci, lower_32_bits(in_ctx_ptr), 3614 return queue_command(xhci, lower_32_bits(in_ctx_ptr),
3601 upper_32_bits(in_ctx_ptr), 0, 3615 upper_32_bits(in_ctx_ptr), 0,
3602 TRB_TYPE(TRB_EVAL_CONTEXT) | SLOT_ID_FOR_TRB(slot_id), 3616 TRB_TYPE(TRB_EVAL_CONTEXT) | SLOT_ID_FOR_TRB(slot_id),
3603 false); 3617 command_must_succeed);
3604} 3618}
3605 3619
3606/* 3620/*
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 16c05c6b5afa..4ceba145fa88 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -2446,7 +2446,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
2446 udev->slot_id, must_succeed); 2446 udev->slot_id, must_succeed);
2447 else 2447 else
2448 ret = xhci_queue_evaluate_context(xhci, in_ctx->dma, 2448 ret = xhci_queue_evaluate_context(xhci, in_ctx->dma,
2449 udev->slot_id); 2449 udev->slot_id, must_succeed);
2450 if (ret < 0) { 2450 if (ret < 0) {
2451 if (command) 2451 if (command)
2452 list_del(&command->cmd_list); 2452 list_del(&command->cmd_list);
@@ -3837,6 +3837,458 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
3837 return 0; 3837 return 0;
3838} 3838}
3839 3839
3840/*---------------------- USB 3.0 Link PM functions ------------------------*/
3841
3842/* Service interval in nanoseconds = 2^(bInterval - 1) * 125us * 1000ns / 1us */
3843static unsigned long long xhci_service_interval_to_ns(
3844 struct usb_endpoint_descriptor *desc)
3845{
3846 return (1 << (desc->bInterval - 1)) * 125 * 1000;
3847}
3848
3849static u16 xhci_get_timeout_no_hub_lpm(struct usb_device *udev,
3850 enum usb3_link_state state)
3851{
3852 unsigned long long sel;
3853 unsigned long long pel;
3854 unsigned int max_sel_pel;
3855 char *state_name;
3856
3857 switch (state) {
3858 case USB3_LPM_U1:
3859 /* Convert SEL and PEL stored in nanoseconds to microseconds */
3860 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000);
3861 pel = DIV_ROUND_UP(udev->u1_params.pel, 1000);
3862 max_sel_pel = USB3_LPM_MAX_U1_SEL_PEL;
3863 state_name = "U1";
3864 break;
3865 case USB3_LPM_U2:
3866 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000);
3867 pel = DIV_ROUND_UP(udev->u2_params.pel, 1000);
3868 max_sel_pel = USB3_LPM_MAX_U2_SEL_PEL;
3869 state_name = "U2";
3870 break;
3871 default:
3872 dev_warn(&udev->dev, "%s: Can't get timeout for non-U1 or U2 state.\n",
3873 __func__);
3874 return -EINVAL;
3875 }
3876
3877 if (sel <= max_sel_pel && pel <= max_sel_pel)
3878 return USB3_LPM_DEVICE_INITIATED;
3879
3880 if (sel > max_sel_pel)
3881 dev_dbg(&udev->dev, "Device-initiated %s disabled "
3882 "due to long SEL %llu ms\n",
3883 state_name, sel);
3884 else
3885 dev_dbg(&udev->dev, "Device-initiated %s disabled "
3886 "due to long PEL %llu\n ms",
3887 state_name, pel);
3888 return USB3_LPM_DISABLED;
3889}
3890
3891/* Returns the hub-encoded U1 timeout value.
3892 * The U1 timeout should be the maximum of the following values:
3893 * - For control endpoints, U1 system exit latency (SEL) * 3
3894 * - For bulk endpoints, U1 SEL * 5
3895 * - For interrupt endpoints:
3896 * - Notification EPs, U1 SEL * 3
3897 * - Periodic EPs, max(105% of bInterval, U1 SEL * 2)
3898 * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2)
3899 */
3900static u16 xhci_calculate_intel_u1_timeout(struct usb_device *udev,
3901 struct usb_endpoint_descriptor *desc)
3902{
3903 unsigned long long timeout_ns;
3904 int ep_type;
3905 int intr_type;
3906
3907 ep_type = usb_endpoint_type(desc);
3908 switch (ep_type) {
3909 case USB_ENDPOINT_XFER_CONTROL:
3910 timeout_ns = udev->u1_params.sel * 3;
3911 break;
3912 case USB_ENDPOINT_XFER_BULK:
3913 timeout_ns = udev->u1_params.sel * 5;
3914 break;
3915 case USB_ENDPOINT_XFER_INT:
3916 intr_type = usb_endpoint_interrupt_type(desc);
3917 if (intr_type == USB_ENDPOINT_INTR_NOTIFICATION) {
3918 timeout_ns = udev->u1_params.sel * 3;
3919 break;
3920 }
3921 /* Otherwise the calculation is the same as isoc eps */
3922 case USB_ENDPOINT_XFER_ISOC:
3923 timeout_ns = xhci_service_interval_to_ns(desc);
3924 timeout_ns = DIV_ROUND_UP(timeout_ns * 105, 100);
3925 if (timeout_ns < udev->u1_params.sel * 2)
3926 timeout_ns = udev->u1_params.sel * 2;
3927 break;
3928 default:
3929 return 0;
3930 }
3931
3932 /* The U1 timeout is encoded in 1us intervals. */
3933 timeout_ns = DIV_ROUND_UP(timeout_ns, 1000);
3934 /* Don't return a timeout of zero, because that's USB3_LPM_DISABLED. */
3935 if (timeout_ns == USB3_LPM_DISABLED)
3936 timeout_ns++;
3937
3938 /* If the necessary timeout value is bigger than what we can set in the
3939 * USB 3.0 hub, we have to disable hub-initiated U1.
3940 */
3941 if (timeout_ns <= USB3_LPM_U1_MAX_TIMEOUT)
3942 return timeout_ns;
3943 dev_dbg(&udev->dev, "Hub-initiated U1 disabled "
3944 "due to long timeout %llu ms\n", timeout_ns);
3945 return xhci_get_timeout_no_hub_lpm(udev, USB3_LPM_U1);
3946}
3947
3948/* Returns the hub-encoded U2 timeout value.
3949 * The U2 timeout should be the maximum of:
3950 * - 10 ms (to avoid the bandwidth impact on the scheduler)
3951 * - largest bInterval of any active periodic endpoint (to avoid going
3952 * into lower power link states between intervals).
3953 * - the U2 Exit Latency of the device
3954 */
3955static u16 xhci_calculate_intel_u2_timeout(struct usb_device *udev,
3956 struct usb_endpoint_descriptor *desc)
3957{
3958 unsigned long long timeout_ns;
3959 unsigned long long u2_del_ns;
3960
3961 timeout_ns = 10 * 1000 * 1000;
3962
3963 if ((usb_endpoint_xfer_int(desc) || usb_endpoint_xfer_isoc(desc)) &&
3964 (xhci_service_interval_to_ns(desc) > timeout_ns))
3965 timeout_ns = xhci_service_interval_to_ns(desc);
3966
3967 u2_del_ns = udev->bos->ss_cap->bU2DevExitLat * 1000;
3968 if (u2_del_ns > timeout_ns)
3969 timeout_ns = u2_del_ns;
3970
3971 /* The U2 timeout is encoded in 256us intervals */
3972 timeout_ns = DIV_ROUND_UP(timeout_ns, 256 * 1000);
3973 /* If the necessary timeout value is bigger than what we can set in the
3974 * USB 3.0 hub, we have to disable hub-initiated U2.
3975 */
3976 if (timeout_ns <= USB3_LPM_U2_MAX_TIMEOUT)
3977 return timeout_ns;
3978 dev_dbg(&udev->dev, "Hub-initiated U2 disabled "
3979 "due to long timeout %llu ms\n", timeout_ns);
3980 return xhci_get_timeout_no_hub_lpm(udev, USB3_LPM_U2);
3981}
3982
3983static u16 xhci_call_host_update_timeout_for_endpoint(struct xhci_hcd *xhci,
3984 struct usb_device *udev,
3985 struct usb_endpoint_descriptor *desc,
3986 enum usb3_link_state state,
3987 u16 *timeout)
3988{
3989 if (state == USB3_LPM_U1) {
3990 if (xhci->quirks & XHCI_INTEL_HOST)
3991 return xhci_calculate_intel_u1_timeout(udev, desc);
3992 } else {
3993 if (xhci->quirks & XHCI_INTEL_HOST)
3994 return xhci_calculate_intel_u2_timeout(udev, desc);
3995 }
3996
3997 return USB3_LPM_DISABLED;
3998}
3999
4000static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci,
4001 struct usb_device *udev,
4002 struct usb_endpoint_descriptor *desc,
4003 enum usb3_link_state state,
4004 u16 *timeout)
4005{
4006 u16 alt_timeout;
4007
4008 alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev,
4009 desc, state, timeout);
4010
4011 /* If we found we can't enable hub-initiated LPM, or
4012 * the U1 or U2 exit latency was too high to allow
4013 * device-initiated LPM as well, just stop searching.
4014 */
4015 if (alt_timeout == USB3_LPM_DISABLED ||
4016 alt_timeout == USB3_LPM_DEVICE_INITIATED) {
4017 *timeout = alt_timeout;
4018 return -E2BIG;
4019 }
4020 if (alt_timeout > *timeout)
4021 *timeout = alt_timeout;
4022 return 0;
4023}
4024
4025static int xhci_update_timeout_for_interface(struct xhci_hcd *xhci,
4026 struct usb_device *udev,
4027 struct usb_host_interface *alt,
4028 enum usb3_link_state state,
4029 u16 *timeout)
4030{
4031 int j;
4032
4033 for (j = 0; j < alt->desc.bNumEndpoints; j++) {
4034 if (xhci_update_timeout_for_endpoint(xhci, udev,
4035 &alt->endpoint[j].desc, state, timeout))
4036 return -E2BIG;
4037 continue;
4038 }
4039 return 0;
4040}
4041
4042static int xhci_check_intel_tier_policy(struct usb_device *udev,
4043 enum usb3_link_state state)
4044{
4045 struct usb_device *parent;
4046 unsigned int num_hubs;
4047
4048 if (state == USB3_LPM_U2)
4049 return 0;
4050
4051 /* Don't enable U1 if the device is on a 2nd tier hub or lower. */
4052 for (parent = udev->parent, num_hubs = 0; parent->parent;
4053 parent = parent->parent)
4054 num_hubs++;
4055
4056 if (num_hubs < 2)
4057 return 0;
4058
4059 dev_dbg(&udev->dev, "Disabling U1 link state for device"
4060 " below second-tier hub.\n");
4061 dev_dbg(&udev->dev, "Plug device into first-tier hub "
4062 "to decrease power consumption.\n");
4063 return -E2BIG;
4064}
4065
4066static int xhci_check_tier_policy(struct xhci_hcd *xhci,
4067 struct usb_device *udev,
4068 enum usb3_link_state state)
4069{
4070 if (xhci->quirks & XHCI_INTEL_HOST)
4071 return xhci_check_intel_tier_policy(udev, state);
4072 return -EINVAL;
4073}
4074
4075/* Returns the U1 or U2 timeout that should be enabled.
4076 * If the tier check or timeout setting functions return with a non-zero exit
4077 * code, that means the timeout value has been finalized and we shouldn't look
4078 * at any more endpoints.
4079 */
4080static u16 xhci_calculate_lpm_timeout(struct usb_hcd *hcd,
4081 struct usb_device *udev, enum usb3_link_state state)
4082{
4083 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
4084 struct usb_host_config *config;
4085 char *state_name;
4086 int i;
4087 u16 timeout = USB3_LPM_DISABLED;
4088
4089 if (state == USB3_LPM_U1)
4090 state_name = "U1";
4091 else if (state == USB3_LPM_U2)
4092 state_name = "U2";
4093 else {
4094 dev_warn(&udev->dev, "Can't enable unknown link state %i\n",
4095 state);
4096 return timeout;
4097 }
4098
4099 if (xhci_check_tier_policy(xhci, udev, state) < 0)
4100 return timeout;
4101
4102 /* Gather some information about the currently installed configuration
4103 * and alternate interface settings.
4104 */
4105 if (xhci_update_timeout_for_endpoint(xhci, udev, &udev->ep0.desc,
4106 state, &timeout))
4107 return timeout;
4108
4109 config = udev->actconfig;
4110 if (!config)
4111 return timeout;
4112
4113 for (i = 0; i < USB_MAXINTERFACES; i++) {
4114 struct usb_driver *driver;
4115 struct usb_interface *intf = config->interface[i];
4116
4117 if (!intf)
4118 continue;
4119
4120 /* Check if any currently bound drivers want hub-initiated LPM
4121 * disabled.
4122 */
4123 if (intf->dev.driver) {
4124 driver = to_usb_driver(intf->dev.driver);
4125 if (driver && driver->disable_hub_initiated_lpm) {
4126 dev_dbg(&udev->dev, "Hub-initiated %s disabled "
4127 "at request of driver %s\n",
4128 state_name, driver->name);
4129 return xhci_get_timeout_no_hub_lpm(udev, state);
4130 }
4131 }
4132
4133 /* Not sure how this could happen... */
4134 if (!intf->cur_altsetting)
4135 continue;
4136
4137 if (xhci_update_timeout_for_interface(xhci, udev,
4138 intf->cur_altsetting,
4139 state, &timeout))
4140 return timeout;
4141 }
4142 return timeout;
4143}
4144
4145/*
4146 * Issue an Evaluate Context command to change the Maximum Exit Latency in the
4147 * slot context. If that succeeds, store the new MEL in the xhci_virt_device.
4148 */
4149static int xhci_change_max_exit_latency(struct xhci_hcd *xhci,
4150 struct usb_device *udev, u16 max_exit_latency)
4151{
4152 struct xhci_virt_device *virt_dev;
4153 struct xhci_command *command;
4154 struct xhci_input_control_ctx *ctrl_ctx;
4155 struct xhci_slot_ctx *slot_ctx;
4156 unsigned long flags;
4157 int ret;
4158
4159 spin_lock_irqsave(&xhci->lock, flags);
4160 if (max_exit_latency == xhci->devs[udev->slot_id]->current_mel) {
4161 spin_unlock_irqrestore(&xhci->lock, flags);
4162 return 0;
4163 }
4164
4165 /* Attempt to issue an Evaluate Context command to change the MEL. */
4166 virt_dev = xhci->devs[udev->slot_id];
4167 command = xhci->lpm_command;
4168 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx);
4169 spin_unlock_irqrestore(&xhci->lock, flags);
4170
4171 ctrl_ctx = xhci_get_input_control_ctx(xhci, command->in_ctx);
4172 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG);
4173 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx);
4174 slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT));
4175 slot_ctx->dev_info2 |= cpu_to_le32(max_exit_latency);
4176
4177 xhci_dbg(xhci, "Set up evaluate context for LPM MEL change.\n");
4178 xhci_dbg(xhci, "Slot %u Input Context:\n", udev->slot_id);
4179 xhci_dbg_ctx(xhci, command->in_ctx, 0);
4180
4181 /* Issue and wait for the evaluate context command. */
4182 ret = xhci_configure_endpoint(xhci, udev, command,
4183 true, true);
4184 xhci_dbg(xhci, "Slot %u Output Context:\n", udev->slot_id);
4185 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 0);
4186
4187 if (!ret) {
4188 spin_lock_irqsave(&xhci->lock, flags);
4189 virt_dev->current_mel = max_exit_latency;
4190 spin_unlock_irqrestore(&xhci->lock, flags);
4191 }
4192 return ret;
4193}
4194
4195static int calculate_max_exit_latency(struct usb_device *udev,
4196 enum usb3_link_state state_changed,
4197 u16 hub_encoded_timeout)
4198{
4199 unsigned long long u1_mel_us = 0;
4200 unsigned long long u2_mel_us = 0;
4201 unsigned long long mel_us = 0;
4202 bool disabling_u1;
4203 bool disabling_u2;
4204 bool enabling_u1;
4205 bool enabling_u2;
4206
4207 disabling_u1 = (state_changed == USB3_LPM_U1 &&
4208 hub_encoded_timeout == USB3_LPM_DISABLED);
4209 disabling_u2 = (state_changed == USB3_LPM_U2 &&
4210 hub_encoded_timeout == USB3_LPM_DISABLED);
4211
4212 enabling_u1 = (state_changed == USB3_LPM_U1 &&
4213 hub_encoded_timeout != USB3_LPM_DISABLED);
4214 enabling_u2 = (state_changed == USB3_LPM_U2 &&
4215 hub_encoded_timeout != USB3_LPM_DISABLED);
4216
4217 /* If U1 was already enabled and we're not disabling it,
4218 * or we're going to enable U1, account for the U1 max exit latency.
4219 */
4220 if ((udev->u1_params.timeout != USB3_LPM_DISABLED && !disabling_u1) ||
4221 enabling_u1)
4222 u1_mel_us = DIV_ROUND_UP(udev->u1_params.mel, 1000);
4223 if ((udev->u2_params.timeout != USB3_LPM_DISABLED && !disabling_u2) ||
4224 enabling_u2)
4225 u2_mel_us = DIV_ROUND_UP(udev->u2_params.mel, 1000);
4226
4227 if (u1_mel_us > u2_mel_us)
4228 mel_us = u1_mel_us;
4229 else
4230 mel_us = u2_mel_us;
4231 /* xHCI host controller max exit latency field is only 16 bits wide. */
4232 if (mel_us > MAX_EXIT) {
4233 dev_warn(&udev->dev, "Link PM max exit latency of %lluus "
4234 "is too big.\n", mel_us);
4235 return -E2BIG;
4236 }
4237 return mel_us;
4238}
4239
4240/* Returns the USB3 hub-encoded value for the U1/U2 timeout. */
4241int xhci_enable_usb3_lpm_timeout(struct usb_hcd *hcd,
4242 struct usb_device *udev, enum usb3_link_state state)
4243{
4244 struct xhci_hcd *xhci;
4245 u16 hub_encoded_timeout;
4246 int mel;
4247 int ret;
4248
4249 xhci = hcd_to_xhci(hcd);
4250 /* The LPM timeout values are pretty host-controller specific, so don't
4251 * enable hub-initiated timeouts unless the vendor has provided
4252 * information about their timeout algorithm.
4253 */
4254 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) ||
4255 !xhci->devs[udev->slot_id])
4256 return USB3_LPM_DISABLED;
4257
4258 hub_encoded_timeout = xhci_calculate_lpm_timeout(hcd, udev, state);
4259 mel = calculate_max_exit_latency(udev, state, hub_encoded_timeout);
4260 if (mel < 0) {
4261 /* Max Exit Latency is too big, disable LPM. */
4262 hub_encoded_timeout = USB3_LPM_DISABLED;
4263 mel = 0;
4264 }
4265
4266 ret = xhci_change_max_exit_latency(xhci, udev, mel);
4267 if (ret)
4268 return ret;
4269 return hub_encoded_timeout;
4270}
4271
4272int xhci_disable_usb3_lpm_timeout(struct usb_hcd *hcd,
4273 struct usb_device *udev, enum usb3_link_state state)
4274{
4275 struct xhci_hcd *xhci;
4276 u16 mel;
4277 int ret;
4278
4279 xhci = hcd_to_xhci(hcd);
4280 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) ||
4281 !xhci->devs[udev->slot_id])
4282 return 0;
4283
4284 mel = calculate_max_exit_latency(udev, state, USB3_LPM_DISABLED);
4285 ret = xhci_change_max_exit_latency(xhci, udev, mel);
4286 if (ret)
4287 return ret;
4288 return 0;
4289}
4290/*-------------------------------------------------------------------------*/
4291
3840int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev) 4292int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
3841{ 4293{
3842 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 4294 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index ce1edd7246aa..de3d6e3e57be 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -362,8 +362,10 @@ struct xhci_op_regs {
362 * Timeout can be up to 127us. 0xFF means an infinite timeout. 362 * Timeout can be up to 127us. 0xFF means an infinite timeout.
363 */ 363 */
364#define PORT_U1_TIMEOUT(p) ((p) & 0xff) 364#define PORT_U1_TIMEOUT(p) ((p) & 0xff)
365#define PORT_U1_TIMEOUT_MASK 0xff
365/* Inactivity timer value for transitions into U2 */ 366/* Inactivity timer value for transitions into U2 */
366#define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8) 367#define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8)
368#define PORT_U2_TIMEOUT_MASK (0xff << 8)
367/* Bits 24:31 for port testing */ 369/* Bits 24:31 for port testing */
368 370
369/* USB2 Protocol PORTSPMSC */ 371/* USB2 Protocol PORTSPMSC */
@@ -914,6 +916,8 @@ struct xhci_virt_device {
914 u8 real_port; 916 u8 real_port;
915 struct xhci_interval_bw_table *bw_table; 917 struct xhci_interval_bw_table *bw_table;
916 struct xhci_tt_bw_info *tt_info; 918 struct xhci_tt_bw_info *tt_info;
919 /* The current max exit latency for the enabled USB3 link states. */
920 u16 current_mel;
917}; 921};
918 922
919/* 923/*
@@ -1424,6 +1428,8 @@ struct xhci_hcd {
1424 /* slot enabling and address device helpers */ 1428 /* slot enabling and address device helpers */
1425 struct completion addr_dev; 1429 struct completion addr_dev;
1426 int slot_id; 1430 int slot_id;
1431 /* For USB 3.0 LPM enable/disable. */
1432 struct xhci_command *lpm_command;
1427 /* Internal mirror of the HW's dcbaa */ 1433 /* Internal mirror of the HW's dcbaa */
1428 struct xhci_virt_device *devs[MAX_HC_SLOTS]; 1434 struct xhci_virt_device *devs[MAX_HC_SLOTS];
1429 /* For keeping track of bandwidth domains per roothub. */ 1435 /* For keeping track of bandwidth domains per roothub. */
@@ -1481,6 +1487,9 @@ struct xhci_hcd {
1481#define XHCI_RESET_ON_RESUME (1 << 7) 1487#define XHCI_RESET_ON_RESUME (1 << 7)
1482#define XHCI_SW_BW_CHECKING (1 << 8) 1488#define XHCI_SW_BW_CHECKING (1 << 8)
1483#define XHCI_AMD_0x96_HOST (1 << 9) 1489#define XHCI_AMD_0x96_HOST (1 << 9)
1490#define XHCI_TRUST_TX_LENGTH (1 << 10)
1491#define XHCI_LPM_SUPPORT (1 << 11)
1492#define XHCI_INTEL_HOST (1 << 12)
1484 unsigned int num_active_eps; 1493 unsigned int num_active_eps;
1485 unsigned int limit_active_eps; 1494 unsigned int limit_active_eps;
1486 /* There are two roothubs to keep track of bus suspend info for */ 1495 /* There are two roothubs to keep track of bus suspend info for */
@@ -1754,7 +1763,7 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
1754int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1763int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1755 u32 slot_id, bool command_must_succeed); 1764 u32 slot_id, bool command_must_succeed);
1756int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1765int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1757 u32 slot_id); 1766 u32 slot_id, bool command_must_succeed);
1758int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, 1767int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id,
1759 unsigned int ep_index); 1768 unsigned int ep_index);
1760int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id); 1769int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id);
@@ -1778,6 +1787,10 @@ void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id,
1778/* xHCI roothub code */ 1787/* xHCI roothub code */
1779void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array, 1788void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array,
1780 int port_id, u32 link_state); 1789 int port_id, u32 link_state);
1790int xhci_enable_usb3_lpm_timeout(struct usb_hcd *hcd,
1791 struct usb_device *udev, enum usb3_link_state state);
1792int xhci_disable_usb3_lpm_timeout(struct usb_hcd *hcd,
1793 struct usb_device *udev, enum usb3_link_state state);
1781void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array, 1794void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array,
1782 int port_id, u32 port_bit); 1795 int port_id, u32 port_bit);
1783int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, 1796int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 14933451d21d..c19297a8779c 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -378,6 +378,45 @@ enum usb_device_removable {
378 USB_DEVICE_FIXED, 378 USB_DEVICE_FIXED,
379}; 379};
380 380
381/*
382 * USB 3.0 Link Power Management (LPM) parameters.
383 *
384 * PEL and SEL are USB 3.0 Link PM latencies for device-initiated LPM exit.
385 * MEL is the USB 3.0 Link PM latency for host-initiated LPM exit.
386 * All three are stored in nanoseconds.
387 */
388struct usb3_lpm_parameters {
389 /*
390 * Maximum exit latency (MEL) for the host to send a packet to the
391 * device (either a Ping for isoc endpoints, or a data packet for
392 * interrupt endpoints), the hubs to decode the packet, and for all hubs
393 * in the path to transition the links to U0.
394 */
395 unsigned int mel;
396 /*
397 * Maximum exit latency for a device-initiated LPM transition to bring
398 * all links into U0. Abbreviated as "PEL" in section 9.4.12 of the USB
399 * 3.0 spec, with no explanation of what "P" stands for. "Path"?
400 */
401 unsigned int pel;
402
403 /*
404 * The System Exit Latency (SEL) includes PEL, and three other
405 * latencies. After a device initiates a U0 transition, it will take
406 * some time from when the device sends the ERDY to when it will finally
407 * receive the data packet. Basically, SEL should be the worse-case
408 * latency from when a device starts initiating a U0 transition to when
409 * it will get data.
410 */
411 unsigned int sel;
412 /*
413 * The idle timeout value that is currently programmed into the parent
414 * hub for this device. When the timer counts to zero, the parent hub
415 * will initiate an LPM transition to either U1 or U2.
416 */
417 int timeout;
418};
419
381/** 420/**
382 * struct usb_device - kernel's representation of a USB device 421 * struct usb_device - kernel's representation of a USB device
383 * @devnum: device number; address on a USB bus 422 * @devnum: device number; address on a USB bus
@@ -435,6 +474,12 @@ enum usb_device_removable {
435 * specific data for the device. 474 * specific data for the device.
436 * @slot_id: Slot ID assigned by xHCI 475 * @slot_id: Slot ID assigned by xHCI
437 * @removable: Device can be physically removed from this port 476 * @removable: Device can be physically removed from this port
477 * @u1_params: exit latencies for USB3 U1 LPM state, and hub-initiated timeout.
478 * @u2_params: exit latencies for USB3 U2 LPM state, and hub-initiated timeout.
479 * @lpm_disable_count: Ref count used by usb_disable_lpm() and usb_enable_lpm()
480 * to keep track of the number of functions that require USB 3.0 Link Power
481 * Management to be disabled for this usb_device. This count should only
482 * be manipulated by those functions, with the bandwidth_mutex is held.
438 * 483 *
439 * Notes: 484 * Notes:
440 * Usbcore drivers should not set usbdev->state directly. Instead use 485 * Usbcore drivers should not set usbdev->state directly. Instead use
@@ -481,6 +526,7 @@ struct usb_device {
481 unsigned lpm_capable:1; 526 unsigned lpm_capable:1;
482 unsigned usb2_hw_lpm_capable:1; 527 unsigned usb2_hw_lpm_capable:1;
483 unsigned usb2_hw_lpm_enabled:1; 528 unsigned usb2_hw_lpm_enabled:1;
529 unsigned usb3_lpm_enabled:1;
484 int string_langid; 530 int string_langid;
485 531
486 /* static strings from the device */ 532 /* static strings from the device */
@@ -507,6 +553,10 @@ struct usb_device {
507 struct wusb_dev *wusb_dev; 553 struct wusb_dev *wusb_dev;
508 int slot_id; 554 int slot_id;
509 enum usb_device_removable removable; 555 enum usb_device_removable removable;
556 struct usb3_lpm_parameters u1_params;
557 struct usb3_lpm_parameters u2_params;
558 unsigned lpm_disable_count;
559 unsigned hub_initiated_lpm_disable_count;
510}; 560};
511#define to_usb_device(d) container_of(d, struct usb_device, dev) 561#define to_usb_device(d) container_of(d, struct usb_device, dev)
512 562
@@ -542,6 +592,12 @@ extern void usb_autopm_put_interface_async(struct usb_interface *intf);
542extern void usb_autopm_get_interface_no_resume(struct usb_interface *intf); 592extern void usb_autopm_get_interface_no_resume(struct usb_interface *intf);
543extern void usb_autopm_put_interface_no_suspend(struct usb_interface *intf); 593extern void usb_autopm_put_interface_no_suspend(struct usb_interface *intf);
544 594
595extern int usb_disable_lpm(struct usb_device *udev);
596extern void usb_enable_lpm(struct usb_device *udev);
597/* Same as above, but these functions lock/unlock the bandwidth_mutex. */
598extern int usb_unlocked_disable_lpm(struct usb_device *udev);
599extern void usb_unlocked_enable_lpm(struct usb_device *udev);
600
545static inline void usb_mark_last_busy(struct usb_device *udev) 601static inline void usb_mark_last_busy(struct usb_device *udev)
546{ 602{
547 pm_runtime_mark_last_busy(&udev->dev); 603 pm_runtime_mark_last_busy(&udev->dev);
@@ -842,6 +898,9 @@ struct usbdrv_wrap {
842 * for interfaces bound to this driver. 898 * for interfaces bound to this driver.
843 * @soft_unbind: if set to 1, the USB core will not kill URBs and disable 899 * @soft_unbind: if set to 1, the USB core will not kill URBs and disable
844 * endpoints before calling the driver's disconnect method. 900 * endpoints before calling the driver's disconnect method.
901 * @disable_hub_initiated_lpm: if set to 0, the USB core will not allow hubs
902 * to initiate lower power link state transitions when an idle timeout
903 * occurs. Device-initiated USB 3.0 link PM will still be allowed.
845 * 904 *
846 * USB interface drivers must provide a name, probe() and disconnect() 905 * USB interface drivers must provide a name, probe() and disconnect()
847 * methods, and an id_table. Other driver fields are optional. 906 * methods, and an id_table. Other driver fields are optional.
@@ -882,6 +941,7 @@ struct usb_driver {
882 struct usbdrv_wrap drvwrap; 941 struct usbdrv_wrap drvwrap;
883 unsigned int no_dynamic_id:1; 942 unsigned int no_dynamic_id:1;
884 unsigned int supports_autosuspend:1; 943 unsigned int supports_autosuspend:1;
944 unsigned int disable_hub_initiated_lpm:1;
885 unsigned int soft_unbind:1; 945 unsigned int soft_unbind:1;
886}; 946};
887#define to_usb_driver(d) container_of(d, struct usb_driver, drvwrap.driver) 947#define to_usb_driver(d) container_of(d, struct usb_driver, drvwrap.driver)
diff --git a/include/linux/usb/ch11.h b/include/linux/usb/ch11.h
index f1d26b6067f1..b6c2863b2c94 100644
--- a/include/linux/usb/ch11.h
+++ b/include/linux/usb/ch11.h
@@ -76,6 +76,8 @@
76#define USB_PORT_FEAT_C_BH_PORT_RESET 29 76#define USB_PORT_FEAT_C_BH_PORT_RESET 29
77#define USB_PORT_FEAT_FORCE_LINKPM_ACCEPT 30 77#define USB_PORT_FEAT_FORCE_LINKPM_ACCEPT 30
78 78
79#define USB_PORT_LPM_TIMEOUT(p) (((p) & 0xff) << 8)
80
79/* USB 3.0 hub remote wake mask bits, see table 10-14 */ 81/* USB 3.0 hub remote wake mask bits, see table 10-14 */
80#define USB_PORT_FEAT_REMOTE_WAKE_CONNECT (1 << 8) 82#define USB_PORT_FEAT_REMOTE_WAKE_CONNECT (1 << 8)
81#define USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT (1 << 9) 83#define USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT (1 << 9)
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index e785d85b617f..d1d732c2838d 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -392,6 +392,11 @@ struct usb_endpoint_descriptor {
392#define USB_ENDPOINT_XFER_INT 3 392#define USB_ENDPOINT_XFER_INT 3
393#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80 393#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
394 394
395/* The USB 3.0 spec redefines bits 5:4 of bmAttributes as interrupt ep type. */
396#define USB_ENDPOINT_INTRTYPE 0x30
397#define USB_ENDPOINT_INTR_PERIODIC (0 << 4)
398#define USB_ENDPOINT_INTR_NOTIFICATION (1 << 4)
399
395#define USB_ENDPOINT_SYNCTYPE 0x0c 400#define USB_ENDPOINT_SYNCTYPE 0x0c
396#define USB_ENDPOINT_SYNC_NONE (0 << 2) 401#define USB_ENDPOINT_SYNC_NONE (0 << 2)
397#define USB_ENDPOINT_SYNC_ASYNC (1 << 2) 402#define USB_ENDPOINT_SYNC_ASYNC (1 << 2)
@@ -594,6 +599,12 @@ static inline int usb_endpoint_maxp(const struct usb_endpoint_descriptor *epd)
594 return __le16_to_cpu(epd->wMaxPacketSize); 599 return __le16_to_cpu(epd->wMaxPacketSize);
595} 600}
596 601
602static inline int usb_endpoint_interrupt_type(
603 const struct usb_endpoint_descriptor *epd)
604{
605 return epd->bmAttributes & USB_ENDPOINT_INTRTYPE;
606}
607
597/*-------------------------------------------------------------------------*/ 608/*-------------------------------------------------------------------------*/
598 609
599/* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */ 610/* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */
@@ -935,6 +946,51 @@ enum usb_device_state {
935 */ 946 */
936}; 947};
937 948
949enum usb3_link_state {
950 USB3_LPM_U0 = 0,
951 USB3_LPM_U1,
952 USB3_LPM_U2,
953 USB3_LPM_U3
954};
955
956/*
957 * A U1 timeout of 0x0 means the parent hub will reject any transitions to U1.
958 * 0xff means the parent hub will accept transitions to U1, but will not
959 * initiate a transition.
960 *
961 * A U1 timeout of 0x1 to 0x7F also causes the hub to initiate a transition to
962 * U1 after that many microseconds. Timeouts of 0x80 to 0xFE are reserved
963 * values.
964 *
965 * A U2 timeout of 0x0 means the parent hub will reject any transitions to U2.
966 * 0xff means the parent hub will accept transitions to U2, but will not
967 * initiate a transition.
968 *
969 * A U2 timeout of 0x1 to 0xFE also causes the hub to initiate a transition to
970 * U2 after N*256 microseconds. Therefore a U2 timeout value of 0x1 means a U2
971 * idle timer of 256 microseconds, 0x2 means 512 microseconds, 0xFE means
972 * 65.024ms.
973 */
974#define USB3_LPM_DISABLED 0x0
975#define USB3_LPM_U1_MAX_TIMEOUT 0x7F
976#define USB3_LPM_U2_MAX_TIMEOUT 0xFE
977#define USB3_LPM_DEVICE_INITIATED 0xFF
978
979struct usb_set_sel_req {
980 __u8 u1_sel;
981 __u8 u1_pel;
982 __le16 u2_sel;
983 __le16 u2_pel;
984} __attribute__ ((packed));
985
986/*
987 * The Set System Exit Latency control transfer provides one byte each for
988 * U1 SEL and U1 PEL, so the max exit latency is 0xFF. U2 SEL and U2 PEL each
989 * are two bytes long.
990 */
991#define USB3_LPM_MAX_U1_SEL_PEL 0xFF
992#define USB3_LPM_MAX_U2_SEL_PEL 0xFFFF
993
938/*-------------------------------------------------------------------------*/ 994/*-------------------------------------------------------------------------*/
939 995
940/* 996/*
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index bbb946437070..7f855d50cdf5 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -344,6 +344,15 @@ struct hc_driver {
344 */ 344 */
345 int (*update_device)(struct usb_hcd *, struct usb_device *); 345 int (*update_device)(struct usb_hcd *, struct usb_device *);
346 int (*set_usb2_hw_lpm)(struct usb_hcd *, struct usb_device *, int); 346 int (*set_usb2_hw_lpm)(struct usb_hcd *, struct usb_device *, int);
347 /* USB 3.0 Link Power Management */
348 /* Returns the USB3 hub-encoded value for the U1/U2 timeout. */
349 int (*enable_usb3_lpm_timeout)(struct usb_hcd *,
350 struct usb_device *, enum usb3_link_state state);
351 /* The xHCI host controller can still fail the command to
352 * disable the LPM timeouts, so this can return an error code.
353 */
354 int (*disable_usb3_lpm_timeout)(struct usb_hcd *,
355 struct usb_device *, enum usb3_link_state state);
347}; 356};
348 357
349extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); 358extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);