Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-usb-next-2012-05-18' of git://git.kernel.org/pub/scm/linux/kernel/git/sarah/xhci into usb-next

xhci: Link PM and bug fixes for 3.5.

Hi Greg,

Here's the final Link Power Management patches, along with a couple of bug
fixes that have been sitting in my queue. I've fixed all the comments that
Alan and Andiry had on the Link PM patches, so I think they're ready to go.

Sarah Sharp

+1512 -13
+1
drivers/bluetooth/ath3k.c
··· 439 439 .probe = ath3k_probe, 440 440 .disconnect = ath3k_disconnect, 441 441 .id_table = ath3k_table, 442 + .disable_hub_initiated_lpm = 1, 442 443 }; 443 444 444 445 module_usb_driver(ath3k_driver);
+1
drivers/bluetooth/bcm203x.c
··· 279 279 .probe = bcm203x_probe, 280 280 .disconnect = bcm203x_disconnect, 281 281 .id_table = bcm203x_table, 282 + .disable_hub_initiated_lpm = 1, 282 283 }; 283 284 284 285 module_usb_driver(bcm203x_driver);
+1
drivers/bluetooth/bfusb.c
··· 749 749 .probe = bfusb_probe, 750 750 .disconnect = bfusb_disconnect, 751 751 .id_table = bfusb_table, 752 + .disable_hub_initiated_lpm = 1, 752 753 }; 753 754 754 755 module_usb_driver(bfusb_driver);
+1
drivers/bluetooth/bpa10x.c
··· 508 508 .probe = bpa10x_probe, 509 509 .disconnect = bpa10x_disconnect, 510 510 .id_table = bpa10x_table, 511 + .disable_hub_initiated_lpm = 1, 511 512 }; 512 513 513 514 module_usb_driver(bpa10x_driver);
+1
drivers/bluetooth/btusb.c
··· 1218 1218 #endif 1219 1219 .id_table = btusb_table, 1220 1220 .supports_autosuspend = 1, 1221 + .disable_hub_initiated_lpm = 1, 1221 1222 }; 1222 1223 1223 1224 module_usb_driver(btusb_driver);
+1
drivers/isdn/gigaset/bas-gigaset.c
··· 148 148 .reset_resume = gigaset_post_reset, 149 149 .pre_reset = gigaset_pre_reset, 150 150 .post_reset = gigaset_post_reset, 151 + .disable_hub_initiated_lpm = 1, 151 152 }; 152 153 153 154 /* get message text for usb_submit_urb return code
+1
drivers/isdn/gigaset/usb-gigaset.c
··· 124 124 .reset_resume = gigaset_resume, 125 125 .pre_reset = gigaset_pre_reset, 126 126 .post_reset = gigaset_resume, 127 + .disable_hub_initiated_lpm = 1, 127 128 }; 128 129 129 130 struct usb_cardstate {
+1
drivers/isdn/hardware/mISDN/hfcsusb.c
··· 2151 2151 .id_table = hfcsusb_idtab, 2152 2152 .probe = hfcsusb_probe, 2153 2153 .disconnect = hfcsusb_disconnect, 2154 + .disable_hub_initiated_lpm = 1, 2154 2155 }; 2155 2156 2156 2157 module_usb_driver(hfcsusb_drv);
+1
drivers/isdn/hisax/hfc_usb.c
··· 1568 1568 .id_table = hfcusb_idtab, 1569 1569 .probe = hfc_usb_probe, 1570 1570 .disconnect = hfc_usb_disconnect, 1571 + .disable_hub_initiated_lpm = 1, 1571 1572 }; 1572 1573 1573 1574 static void __exit
+1
drivers/isdn/hisax/st5481_init.c
··· 182 182 .probe = probe_st5481, 183 183 .disconnect = disconnect_st5481, 184 184 .id_table = st5481_ids, 185 + .disable_hub_initiated_lpm = 1, 185 186 }; 186 187 187 188 static int __init st5481_usb_init(void)
+1
drivers/net/usb/asix.c
··· 1647 1647 .resume = usbnet_resume, 1648 1648 .disconnect = usbnet_disconnect, 1649 1649 .supports_autosuspend = 1, 1650 + .disable_hub_initiated_lpm = 1, 1650 1651 }; 1651 1652 1652 1653 module_usb_driver(asix_driver);
+1
drivers/net/usb/catc.c
··· 952 952 .probe = catc_probe, 953 953 .disconnect = catc_disconnect, 954 954 .id_table = catc_id_table, 955 + .disable_hub_initiated_lpm = 1, 955 956 }; 956 957 957 958 module_usb_driver(catc_driver);
+1
drivers/net/usb/cdc-phonet.c
··· 457 457 .probe = usbpn_probe, 458 458 .disconnect = usbpn_disconnect, 459 459 .id_table = usbpn_ids, 460 + .disable_hub_initiated_lpm = 1, 460 461 }; 461 462 462 463 module_usb_driver(usbpn_driver);
+1
drivers/net/usb/cdc_eem.c
··· 368 368 .disconnect = usbnet_disconnect, 369 369 .suspend = usbnet_suspend, 370 370 .resume = usbnet_resume, 371 + .disable_hub_initiated_lpm = 1, 371 372 }; 372 373 373 374 module_usb_driver(eem_driver);
+1
drivers/net/usb/cdc_ether.c
··· 633 633 .resume = usbnet_resume, 634 634 .reset_resume = usbnet_resume, 635 635 .supports_autosuspend = 1, 636 + .disable_hub_initiated_lpm = 1, 636 637 }; 637 638 638 639 module_usb_driver(cdc_driver);
+1
drivers/net/usb/cdc_ncm.c
··· 1212 1212 .resume = usbnet_resume, 1213 1213 .reset_resume = usbnet_resume, 1214 1214 .supports_autosuspend = 1, 1215 + .disable_hub_initiated_lpm = 1, 1215 1216 }; 1216 1217 1217 1218 static const struct ethtool_ops cdc_ncm_ethtool_ops = {
+1
drivers/net/usb/cdc_subset.c
··· 336 336 .resume = usbnet_resume, 337 337 .disconnect = usbnet_disconnect, 338 338 .id_table = products, 339 + .disable_hub_initiated_lpm = 1, 339 340 }; 340 341 341 342 module_usb_driver(cdc_subset_driver);
+1
drivers/net/usb/cx82310_eth.c
··· 327 327 .disconnect = usbnet_disconnect, 328 328 .suspend = usbnet_suspend, 329 329 .resume = usbnet_resume, 330 + .disable_hub_initiated_lpm = 1, 330 331 }; 331 332 332 333 module_usb_driver(cx82310_driver);
+1
drivers/net/usb/dm9601.c
··· 670 670 .disconnect = usbnet_disconnect, 671 671 .suspend = usbnet_suspend, 672 672 .resume = usbnet_resume, 673 + .disable_hub_initiated_lpm = 1, 673 674 }; 674 675 675 676 module_usb_driver(dm9601_driver);
+1
drivers/net/usb/gl620a.c
··· 225 225 .disconnect = usbnet_disconnect, 226 226 .suspend = usbnet_suspend, 227 227 .resume = usbnet_resume, 228 + .disable_hub_initiated_lpm = 1, 228 229 }; 229 230 230 231 module_usb_driver(gl620a_driver);
+1
drivers/net/usb/hso.c
··· 3291 3291 .resume = hso_resume, 3292 3292 .reset_resume = hso_resume, 3293 3293 .supports_autosuspend = 1, 3294 + .disable_hub_initiated_lpm = 1, 3294 3295 }; 3295 3296 3296 3297 static int __init hso_init(void)
+1
drivers/net/usb/int51x1.c
··· 236 236 .disconnect = usbnet_disconnect, 237 237 .suspend = usbnet_suspend, 238 238 .resume = usbnet_resume, 239 + .disable_hub_initiated_lpm = 1, 239 240 }; 240 241 241 242 module_usb_driver(int51x1_driver);
+1
drivers/net/usb/ipheth.c
··· 554 554 .probe = ipheth_probe, 555 555 .disconnect = ipheth_disconnect, 556 556 .id_table = ipheth_table, 557 + .disable_hub_initiated_lpm = 1, 557 558 }; 558 559 559 560 module_usb_driver(ipheth_driver);
+2 -1
drivers/net/usb/kalmia.c
··· 372 372 .probe = usbnet_probe, 373 373 .disconnect = usbnet_disconnect, 374 374 .suspend = usbnet_suspend, 375 - .resume = usbnet_resume 375 + .resume = usbnet_resume, 376 + .disable_hub_initiated_lpm = 1, 376 377 }; 377 378 378 379 module_usb_driver(kalmia_driver);
+1
drivers/net/usb/kaweth.c
··· 179 179 .resume = kaweth_resume, 180 180 .id_table = usb_klsi_table, 181 181 .supports_autosuspend = 1, 182 + .disable_hub_initiated_lpm = 1, 182 183 }; 183 184 184 185 typedef __u8 eth_addr_t[6];
+1
drivers/net/usb/lg-vl600.c
··· 344 344 .disconnect = usbnet_disconnect, 345 345 .suspend = usbnet_suspend, 346 346 .resume = usbnet_resume, 347 + .disable_hub_initiated_lpm = 1, 347 348 }; 348 349 349 350 module_usb_driver(lg_vl600_driver);
+1
drivers/net/usb/mcs7830.c
··· 690 690 .suspend = usbnet_suspend, 691 691 .resume = usbnet_resume, 692 692 .reset_resume = mcs7830_reset_resume, 693 + .disable_hub_initiated_lpm = 1, 693 694 }; 694 695 695 696 module_usb_driver(mcs7830_driver);
+1
drivers/net/usb/net1080.c
··· 587 587 .disconnect = usbnet_disconnect, 588 588 .suspend = usbnet_suspend, 589 589 .resume = usbnet_resume, 590 + .disable_hub_initiated_lpm = 1, 590 591 }; 591 592 592 593 module_usb_driver(net1080_driver);
+1
drivers/net/usb/pegasus.c
··· 1489 1489 .id_table = pegasus_ids, 1490 1490 .suspend = pegasus_suspend, 1491 1491 .resume = pegasus_resume, 1492 + .disable_hub_initiated_lpm = 1, 1492 1493 }; 1493 1494 1494 1495 static void __init parse_id(char *id)
+1
drivers/net/usb/plusb.c
··· 152 152 .disconnect = usbnet_disconnect, 153 153 .suspend = usbnet_suspend, 154 154 .resume = usbnet_resume, 155 + .disable_hub_initiated_lpm = 1, 155 156 }; 156 157 157 158 module_usb_driver(plusb_driver);
+1
drivers/net/usb/qmi_wwan.c
··· 525 525 .resume = qmi_wwan_resume, 526 526 .reset_resume = qmi_wwan_resume, 527 527 .supports_autosuspend = 1, 528 + .disable_hub_initiated_lpm = 1, 528 529 }; 529 530 530 531 static int __init qmi_wwan_init(void)
+1
drivers/net/usb/rndis_host.c
··· 633 633 .disconnect = usbnet_disconnect, 634 634 .suspend = usbnet_suspend, 635 635 .resume = usbnet_resume, 636 + .disable_hub_initiated_lpm = 1, 636 637 }; 637 638 638 639 module_usb_driver(rndis_driver);
+2 -1
drivers/net/usb/rtl8150.c
··· 948 948 .disconnect = rtl8150_disconnect, 949 949 .id_table = rtl8150_table, 950 950 .suspend = rtl8150_suspend, 951 - .resume = rtl8150_resume 951 + .resume = rtl8150_resume, 952 + .disable_hub_initiated_lpm = 1, 952 953 }; 953 954 954 955 module_usb_driver(rtl8150_driver);
+1
drivers/net/usb/sierra_net.c
··· 982 982 .suspend = usbnet_suspend, 983 983 .resume = usbnet_resume, 984 984 .no_dynamic_id = 1, 985 + .disable_hub_initiated_lpm = 1, 985 986 }; 986 987 987 988 module_usb_driver(sierra_net_driver);
+1
drivers/net/usb/smsc75xx.c
··· 1250 1250 .suspend = usbnet_suspend, 1251 1251 .resume = usbnet_resume, 1252 1252 .disconnect = usbnet_disconnect, 1253 + .disable_hub_initiated_lpm = 1, 1253 1254 }; 1254 1255 1255 1256 module_usb_driver(smsc75xx_driver);
+1
drivers/net/usb/smsc95xx.c
··· 1297 1297 .suspend = usbnet_suspend, 1298 1298 .resume = usbnet_resume, 1299 1299 .disconnect = usbnet_disconnect, 1300 + .disable_hub_initiated_lpm = 1, 1300 1301 }; 1301 1302 1302 1303 module_usb_driver(smsc95xx_driver);
+1
drivers/net/usb/zaurus.c
··· 377 377 .disconnect = usbnet_disconnect, 378 378 .suspend = usbnet_suspend, 379 379 .resume = usbnet_resume, 380 + .disable_hub_initiated_lpm = 1, 380 381 }; 381 382 382 383 module_usb_driver(zaurus_driver);
+1
drivers/net/wireless/at76c50x-usb.c
··· 2486 2486 .probe = at76_probe, 2487 2487 .disconnect = at76_disconnect, 2488 2488 .id_table = dev_table, 2489 + .disable_hub_initiated_lpm = 1, 2489 2490 }; 2490 2491 2491 2492 static int __init at76_mod_init(void)
+1
drivers/net/wireless/ath/ath6kl/usb.c
··· 405 405 .probe = ath6kl_usb_probe, 406 406 .disconnect = ath6kl_usb_remove, 407 407 .id_table = ath6kl_usb_ids, 408 + .disable_hub_initiated_lpm = 1, 408 409 }; 409 410 410 411 static int ath6kl_usb_init(void)
+1
drivers/net/wireless/ath/ath9k/hif_usb.c
··· 1356 1356 #endif 1357 1357 .id_table = ath9k_hif_usb_ids, 1358 1358 .soft_unbind = 1, 1359 + .disable_hub_initiated_lpm = 1, 1359 1360 }; 1360 1361 1361 1362 int ath9k_hif_usb_init(void)
+1
drivers/net/wireless/ath/carl9170/usb.c
··· 1159 1159 .resume = carl9170_usb_resume, 1160 1160 .reset_resume = carl9170_usb_resume, 1161 1161 #endif /* CONFIG_PM */ 1162 + .disable_hub_initiated_lpm = 1, 1162 1163 }; 1163 1164 1164 1165 module_usb_driver(carl9170_driver);
+1
drivers/net/wireless/brcm80211/brcmfmac/usb.c
··· 1605 1605 .suspend = brcmf_usb_suspend, 1606 1606 .resume = brcmf_usb_resume, 1607 1607 .supports_autosuspend = 1 1608 + .disable_hub_initiated_lpm = 1, 1608 1609 }; 1609 1610 1610 1611 void brcmf_usb_exit(void)
+1
drivers/net/wireless/libertas/if_usb.c
··· 1180 1180 .suspend = if_usb_suspend, 1181 1181 .resume = if_usb_resume, 1182 1182 .reset_resume = if_usb_resume, 1183 + .disable_hub_initiated_lpm = 1, 1183 1184 }; 1184 1185 1185 1186 module_usb_driver(if_usb_driver);
+1
drivers/net/wireless/libertas_tf/if_usb.c
··· 920 920 .id_table = if_usb_table, 921 921 .suspend = if_usb_suspend, 922 922 .resume = if_usb_resume, 923 + .disable_hub_initiated_lpm = 1, 923 924 }; 924 925 925 926 module_usb_driver(if_usb_driver);
+1
drivers/net/wireless/orinoco/orinoco_usb.c
··· 1752 1752 .probe = ezusb_probe, 1753 1753 .disconnect = ezusb_disconnect, 1754 1754 .id_table = ezusb_table, 1755 + .disable_hub_initiated_lpm = 1, 1755 1756 }; 1756 1757 1757 1758 module_usb_driver(orinoco_driver);
+1
drivers/net/wireless/p54/p54usb.c
··· 1081 1081 .reset_resume = p54u_resume, 1082 1082 #endif /* CONFIG_PM */ 1083 1083 .soft_unbind = 1, 1084 + .disable_hub_initiated_lpm = 1, 1084 1085 }; 1085 1086 1086 1087 module_usb_driver(p54u_driver);
+1
drivers/net/wireless/rndis_wlan.c
··· 3776 3776 .disconnect = usbnet_disconnect, 3777 3777 .suspend = usbnet_suspend, 3778 3778 .resume = usbnet_resume, 3779 + .disable_hub_initiated_lpm = 1, 3779 3780 }; 3780 3781 3781 3782 module_usb_driver(rndis_wlan_driver);
+1
drivers/net/wireless/rt2x00/rt2500usb.c
··· 1980 1980 .disconnect = rt2x00usb_disconnect, 1981 1981 .suspend = rt2x00usb_suspend, 1982 1982 .resume = rt2x00usb_resume, 1983 + .disable_hub_initiated_lpm = 1, 1983 1984 }; 1984 1985 1985 1986 module_usb_driver(rt2500usb_driver);
+1
drivers/net/wireless/rt2x00/rt2800usb.c
··· 1293 1293 .disconnect = rt2x00usb_disconnect, 1294 1294 .suspend = rt2x00usb_suspend, 1295 1295 .resume = rt2x00usb_resume, 1296 + .disable_hub_initiated_lpm = 1, 1296 1297 }; 1297 1298 1298 1299 module_usb_driver(rt2800usb_driver);
+1
drivers/net/wireless/rt2x00/rt73usb.c
··· 2526 2526 .disconnect = rt2x00usb_disconnect, 2527 2527 .suspend = rt2x00usb_suspend, 2528 2528 .resume = rt2x00usb_resume, 2529 + .disable_hub_initiated_lpm = 1, 2529 2530 }; 2530 2531 2531 2532 module_usb_driver(rt73usb_driver);
+1
drivers/net/wireless/rtl818x/rtl8187/dev.c
··· 1662 1662 .id_table = rtl8187_table, 1663 1663 .probe = rtl8187_probe, 1664 1664 .disconnect = __devexit_p(rtl8187_disconnect), 1665 + .disable_hub_initiated_lpm = 1, 1665 1666 }; 1666 1667 1667 1668 module_usb_driver(rtl8187_driver);
+1
drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
··· 372 372 #ifdef CONFIG_AUTOSUSPEND 373 373 .supports_autosuspend = 1, 374 374 #endif 375 + .disable_hub_initiated_lpm = 1, 375 376 }; 376 377 377 378 module_usb_driver(rtl8192cu_driver);
+1
drivers/net/wireless/zd1201.c
··· 1905 1905 .id_table = zd1201_table, 1906 1906 .suspend = zd1201_suspend, 1907 1907 .resume = zd1201_resume, 1908 + .disable_hub_initiated_lpm = 1, 1908 1909 }; 1909 1910 1910 1911 module_usb_driver(zd1201_usb);
+1
drivers/net/wireless/zd1211rw/zd_usb.c
··· 1542 1542 .disconnect = disconnect, 1543 1543 .pre_reset = pre_reset, 1544 1544 .post_reset = post_reset, 1545 + .disable_hub_initiated_lpm = 1, 1545 1546 }; 1546 1547 1547 1548 struct workqueue_struct *zd_workqueue;
+1
drivers/usb/class/cdc-acm.c
··· 1664 1664 #ifdef CONFIG_PM 1665 1665 .supports_autosuspend = 1, 1666 1666 #endif 1667 + .disable_hub_initiated_lpm = 1, 1667 1668 }; 1668 1669 1669 1670 /*
+1
drivers/usb/class/cdc-wdm.c
··· 1034 1034 .post_reset = wdm_post_reset, 1035 1035 .id_table = wdm_ids, 1036 1036 .supports_autosuspend = 1, 1037 + .disable_hub_initiated_lpm = 1, 1037 1038 }; 1038 1039 1039 1040 module_usb_driver(wdm_driver);
+53 -1
drivers/usb/core/driver.c
··· 288 288 struct usb_device *udev = interface_to_usbdev(intf); 289 289 const struct usb_device_id *id; 290 290 int error = -ENODEV; 291 + int lpm_disable_error; 291 292 292 293 dev_dbg(dev, "%s\n", __func__); 293 294 ··· 325 324 if (driver->supports_autosuspend) 326 325 pm_runtime_enable(dev); 327 326 327 + /* If the new driver doesn't allow hub-initiated LPM, and we can't 328 + * disable hub-initiated LPM, then fail the probe. 329 + * 330 + * Otherwise, leaving LPM enabled should be harmless, because the 331 + * endpoint intervals should remain the same, and the U1/U2 timeouts 332 + * should remain the same. 333 + * 334 + * If we need to install alt setting 0 before probe, or another alt 335 + * setting during probe, that should also be fine. usb_set_interface() 336 + * will attempt to disable LPM, and fail if it can't disable it. 337 + */ 338 + lpm_disable_error = usb_unlocked_disable_lpm(udev); 339 + if (lpm_disable_error && driver->disable_hub_initiated_lpm) { 340 + dev_err(&intf->dev, "%s Failed to disable LPM for driver %s\n.", 341 + __func__, driver->name); 342 + error = lpm_disable_error; 343 + goto err; 344 + } 345 + 328 346 /* Carry out a deferred switch to altsetting 0 */ 329 347 if (intf->needs_altsetting0) { 330 348 error = usb_set_interface(udev, intf->altsetting[0]. ··· 358 338 goto err; 359 339 360 340 intf->condition = USB_INTERFACE_BOUND; 341 + 342 + /* If the LPM disable succeeded, balance the ref counts. */ 343 + if (!lpm_disable_error) 344 + usb_unlocked_enable_lpm(udev); 345 + 361 346 usb_autosuspend_device(udev); 362 347 return error; 363 348 ··· 386 361 struct usb_driver *driver = to_usb_driver(dev->driver); 387 362 struct usb_interface *intf = to_usb_interface(dev); 388 363 struct usb_device *udev; 389 - int error, r; 364 + int error, r, lpm_disable_error; 390 365 391 366 intf->condition = USB_INTERFACE_UNBINDING; 392 367 393 368 /* Autoresume for set_interface call below */ 394 369 udev = interface_to_usbdev(intf); 395 370 error = usb_autoresume_device(udev); 371 + 372 + /* Hub-initiated LPM policy may change, so attempt to disable LPM until 373 + * the driver is unbound. If LPM isn't disabled, that's fine because it 374 + * wouldn't be enabled unless all the bound interfaces supported 375 + * hub-initiated LPM. 376 + */ 377 + lpm_disable_error = usb_unlocked_disable_lpm(udev); 396 378 397 379 /* Terminate all URBs for this interface unless the driver 398 380 * supports "soft" unbinding. ··· 433 401 434 402 intf->condition = USB_INTERFACE_UNBOUND; 435 403 intf->needs_remote_wakeup = 0; 404 + 405 + /* Attempt to re-enable USB3 LPM, if the disable succeeded. */ 406 + if (!lpm_disable_error) 407 + usb_unlocked_enable_lpm(udev); 436 408 437 409 /* Unbound interfaces are always runtime-PM-disabled and -suspended */ 438 410 if (driver->supports_autosuspend) ··· 478 442 struct usb_interface *iface, void *priv) 479 443 { 480 444 struct device *dev = &iface->dev; 445 + struct usb_device *udev; 481 446 int retval = 0; 447 + int lpm_disable_error; 482 448 483 449 if (dev->driver) 484 450 return -EBUSY; 451 + 452 + udev = interface_to_usbdev(iface); 485 453 486 454 dev->driver = &driver->drvwrap.driver; 487 455 usb_set_intfdata(iface, priv); 488 456 iface->needs_binding = 0; 489 457 490 458 iface->condition = USB_INTERFACE_BOUND; 459 + 460 + /* Disable LPM until this driver is bound. */ 461 + lpm_disable_error = usb_unlocked_disable_lpm(udev); 462 + if (lpm_disable_error && driver->disable_hub_initiated_lpm) { 463 + dev_err(&iface->dev, "%s Failed to disable LPM for driver %s\n.", 464 + __func__, driver->name); 465 + return -ENOMEM; 466 + } 491 467 492 468 /* Claimed interfaces are initially inactive (suspended) and 493 469 * runtime-PM-enabled, but only if the driver has autosuspend ··· 518 470 */ 519 471 if (device_is_registered(dev)) 520 472 retval = device_bind_driver(dev); 473 + 474 + /* Attempt to re-enable USB3 LPM, if the disable was successful. */ 475 + if (!lpm_disable_error) 476 + usb_unlocked_enable_lpm(udev); 521 477 522 478 return retval; 523 479 }
+9
drivers/usb/core/hcd.c
··· 997 997 dev_name(&usb_dev->dev), retval); 998 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 1010 retval = usb_new_device (usb_dev); 1002 1011 if (retval) {
+669 -3
drivers/usb/core/hub.c
··· 177 177 return usb_get_intfdata(hdev->actconfig->interface[0]); 178 178 } 179 179 180 + static 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 + */ 213 + static 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 + */ 258 + static 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 + */ 312 + static 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 + 335 + static 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 402 /* USB 2.0 spec Section 11.24.4.5 */ 181 403 static int get_hub_descriptor(struct usb_device *hdev, void *data) 182 404 { ··· 2702 2480 if (udev->usb2_hw_lpm_enabled == 1) 2703 2481 usb_set_usb2_hardware_lpm(udev, 0); 2704 2482 2483 + if (usb_unlocked_disable_lpm(udev)) { 2484 + dev_err(&udev->dev, "%s Failed to disable LPM before suspend\n.", 2485 + __func__); 2486 + return -ENOMEM; 2487 + } 2488 + 2705 2489 /* see 7.1.7.6 */ 2706 2490 if (hub_is_superspeed(hub->hdev)) 2707 2491 status = set_port_feature(hub->hdev, ··· 2726 2498 USB_DEVICE_REMOTE_WAKEUP, 0, 2727 2499 NULL, 0, 2728 2500 USB_CTRL_SET_TIMEOUT); 2501 + 2502 + /* Try to enable USB2 hardware LPM again */ 2503 + if (udev->usb2_hw_lpm_capable == 1) 2504 + usb_set_usb2_hardware_lpm(udev, 1); 2505 + 2506 + /* Try to enable USB3 LPM again */ 2507 + usb_unlocked_enable_lpm(udev); 2729 2508 2730 2509 /* System sleep transitions should never fail */ 2731 2510 if (!PMSG_IS_AUTO(msg)) ··· 2931 2696 /* Try to enable USB2 hardware LPM */ 2932 2697 if (udev->usb2_hw_lpm_capable == 1) 2933 2698 usb_set_usb2_hardware_lpm(udev, 1); 2699 + 2700 + /* Try to enable USB3 LPM */ 2701 + usb_unlocked_enable_lpm(udev); 2934 2702 } 2935 2703 2936 2704 return status; ··· 3062 2824 } 3063 2825 EXPORT_SYMBOL_GPL(usb_root_hub_lost_power); 3064 2826 2827 + static const char * const usb3_lpm_names[] = { 2828 + "U0", 2829 + "U1", 2830 + "U2", 2831 + "U3", 2832 + }; 2833 + 2834 + /* 2835 + * Send a Set SEL control transfer to the device, prior to enabling 2836 + * device-initiated U1 or U2. This lets the device know the exit latencies from 2837 + * the time the device initiates a U1 or U2 exit, to the time it will receive a 2838 + * packet from the host. 2839 + * 2840 + * This function will fail if the SEL or PEL values for udev are greater than 2841 + * the maximum allowed values for the link state to be enabled. 2842 + */ 2843 + static int usb_req_set_sel(struct usb_device *udev, enum usb3_link_state state) 2844 + { 2845 + struct usb_set_sel_req *sel_values; 2846 + unsigned long long u1_sel; 2847 + unsigned long long u1_pel; 2848 + unsigned long long u2_sel; 2849 + unsigned long long u2_pel; 2850 + int ret; 2851 + 2852 + /* Convert SEL and PEL stored in ns to us */ 2853 + u1_sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); 2854 + u1_pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); 2855 + u2_sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); 2856 + u2_pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); 2857 + 2858 + /* 2859 + * Make sure that the calculated SEL and PEL values for the link 2860 + * state we're enabling aren't bigger than the max SEL/PEL 2861 + * value that will fit in the SET SEL control transfer. 2862 + * Otherwise the device would get an incorrect idea of the exit 2863 + * latency for the link state, and could start a device-initiated 2864 + * U1/U2 when the exit latencies are too high. 2865 + */ 2866 + if ((state == USB3_LPM_U1 && 2867 + (u1_sel > USB3_LPM_MAX_U1_SEL_PEL || 2868 + u1_pel > USB3_LPM_MAX_U1_SEL_PEL)) || 2869 + (state == USB3_LPM_U2 && 2870 + (u2_sel > USB3_LPM_MAX_U2_SEL_PEL || 2871 + u2_pel > USB3_LPM_MAX_U2_SEL_PEL))) { 2872 + dev_dbg(&udev->dev, "Device-initiated %s disabled due " 2873 + "to long SEL %llu ms or PEL %llu ms\n", 2874 + usb3_lpm_names[state], u1_sel, u1_pel); 2875 + return -EINVAL; 2876 + } 2877 + 2878 + /* 2879 + * If we're enabling device-initiated LPM for one link state, 2880 + * but the other link state has a too high SEL or PEL value, 2881 + * just set those values to the max in the Set SEL request. 2882 + */ 2883 + if (u1_sel > USB3_LPM_MAX_U1_SEL_PEL) 2884 + u1_sel = USB3_LPM_MAX_U1_SEL_PEL; 2885 + 2886 + if (u1_pel > USB3_LPM_MAX_U1_SEL_PEL) 2887 + u1_pel = USB3_LPM_MAX_U1_SEL_PEL; 2888 + 2889 + if (u2_sel > USB3_LPM_MAX_U2_SEL_PEL) 2890 + u2_sel = USB3_LPM_MAX_U2_SEL_PEL; 2891 + 2892 + if (u2_pel > USB3_LPM_MAX_U2_SEL_PEL) 2893 + u2_pel = USB3_LPM_MAX_U2_SEL_PEL; 2894 + 2895 + /* 2896 + * usb_enable_lpm() can be called as part of a failed device reset, 2897 + * which may be initiated by an error path of a mass storage driver. 2898 + * Therefore, use GFP_NOIO. 2899 + */ 2900 + sel_values = kmalloc(sizeof *(sel_values), GFP_NOIO); 2901 + if (!sel_values) 2902 + return -ENOMEM; 2903 + 2904 + sel_values->u1_sel = u1_sel; 2905 + sel_values->u1_pel = u1_pel; 2906 + sel_values->u2_sel = cpu_to_le16(u2_sel); 2907 + sel_values->u2_pel = cpu_to_le16(u2_pel); 2908 + 2909 + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 2910 + USB_REQ_SET_SEL, 2911 + USB_RECIP_DEVICE, 2912 + 0, 0, 2913 + sel_values, sizeof *(sel_values), 2914 + USB_CTRL_SET_TIMEOUT); 2915 + kfree(sel_values); 2916 + return ret; 2917 + } 2918 + 2919 + /* 2920 + * Enable or disable device-initiated U1 or U2 transitions. 2921 + */ 2922 + static int usb_set_device_initiated_lpm(struct usb_device *udev, 2923 + enum usb3_link_state state, bool enable) 2924 + { 2925 + int ret; 2926 + int feature; 2927 + 2928 + switch (state) { 2929 + case USB3_LPM_U1: 2930 + feature = USB_DEVICE_U1_ENABLE; 2931 + break; 2932 + case USB3_LPM_U2: 2933 + feature = USB_DEVICE_U2_ENABLE; 2934 + break; 2935 + default: 2936 + dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n", 2937 + __func__, enable ? "enable" : "disable"); 2938 + return -EINVAL; 2939 + } 2940 + 2941 + if (udev->state != USB_STATE_CONFIGURED) { 2942 + dev_dbg(&udev->dev, "%s: Can't %s %s state " 2943 + "for unconfigured device.\n", 2944 + __func__, enable ? "enable" : "disable", 2945 + usb3_lpm_names[state]); 2946 + return 0; 2947 + } 2948 + 2949 + if (enable) { 2950 + /* 2951 + * First, let the device know about the exit latencies 2952 + * associated with the link state we're about to enable. 2953 + */ 2954 + ret = usb_req_set_sel(udev, state); 2955 + if (ret < 0) { 2956 + dev_warn(&udev->dev, "Set SEL for device-initiated " 2957 + "%s failed.\n", usb3_lpm_names[state]); 2958 + return -EBUSY; 2959 + } 2960 + /* 2961 + * Now send the control transfer to enable device-initiated LPM 2962 + * for either U1 or U2. 2963 + */ 2964 + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 2965 + USB_REQ_SET_FEATURE, 2966 + USB_RECIP_DEVICE, 2967 + feature, 2968 + 0, NULL, 0, 2969 + USB_CTRL_SET_TIMEOUT); 2970 + } else { 2971 + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 2972 + USB_REQ_CLEAR_FEATURE, 2973 + USB_RECIP_DEVICE, 2974 + feature, 2975 + 0, NULL, 0, 2976 + USB_CTRL_SET_TIMEOUT); 2977 + } 2978 + if (ret < 0) { 2979 + dev_warn(&udev->dev, "%s of device-initiated %s failed.\n", 2980 + enable ? "Enable" : "Disable", 2981 + usb3_lpm_names[state]); 2982 + return -EBUSY; 2983 + } 2984 + return 0; 2985 + } 2986 + 2987 + static int usb_set_lpm_timeout(struct usb_device *udev, 2988 + enum usb3_link_state state, int timeout) 2989 + { 2990 + int ret; 2991 + int feature; 2992 + 2993 + switch (state) { 2994 + case USB3_LPM_U1: 2995 + feature = USB_PORT_FEAT_U1_TIMEOUT; 2996 + break; 2997 + case USB3_LPM_U2: 2998 + feature = USB_PORT_FEAT_U2_TIMEOUT; 2999 + break; 3000 + default: 3001 + dev_warn(&udev->dev, "%s: Can't set timeout for non-U1 or U2 state.\n", 3002 + __func__); 3003 + return -EINVAL; 3004 + } 3005 + 3006 + if (state == USB3_LPM_U1 && timeout > USB3_LPM_U1_MAX_TIMEOUT && 3007 + timeout != USB3_LPM_DEVICE_INITIATED) { 3008 + dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x, " 3009 + "which is a reserved value.\n", 3010 + usb3_lpm_names[state], timeout); 3011 + return -EINVAL; 3012 + } 3013 + 3014 + ret = set_port_feature(udev->parent, 3015 + USB_PORT_LPM_TIMEOUT(timeout) | udev->portnum, 3016 + feature); 3017 + if (ret < 0) { 3018 + dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x," 3019 + "error code %i\n", usb3_lpm_names[state], 3020 + timeout, ret); 3021 + return -EBUSY; 3022 + } 3023 + if (state == USB3_LPM_U1) 3024 + udev->u1_params.timeout = timeout; 3025 + else 3026 + udev->u2_params.timeout = timeout; 3027 + return 0; 3028 + } 3029 + 3030 + /* 3031 + * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated 3032 + * U1/U2 entry. 3033 + * 3034 + * We will attempt to enable U1 or U2, but there are no guarantees that the 3035 + * control transfers to set the hub timeout or enable device-initiated U1/U2 3036 + * will be successful. 3037 + * 3038 + * If we cannot set the parent hub U1/U2 timeout, we attempt to let the xHCI 3039 + * driver know about it. If that call fails, it should be harmless, and just 3040 + * take up more slightly more bus bandwidth for unnecessary U1/U2 exit latency. 3041 + */ 3042 + static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, 3043 + enum usb3_link_state state) 3044 + { 3045 + int timeout; 3046 + 3047 + /* We allow the host controller to set the U1/U2 timeout internally 3048 + * first, so that it can change its schedule to account for the 3049 + * additional latency to send data to a device in a lower power 3050 + * link state. 3051 + */ 3052 + timeout = hcd->driver->enable_usb3_lpm_timeout(hcd, udev, state); 3053 + 3054 + /* xHCI host controller doesn't want to enable this LPM state. */ 3055 + if (timeout == 0) 3056 + return; 3057 + 3058 + if (timeout < 0) { 3059 + dev_warn(&udev->dev, "Could not enable %s link state, " 3060 + "xHCI error %i.\n", usb3_lpm_names[state], 3061 + timeout); 3062 + return; 3063 + } 3064 + 3065 + if (usb_set_lpm_timeout(udev, state, timeout)) 3066 + /* If we can't set the parent hub U1/U2 timeout, 3067 + * device-initiated LPM won't be allowed either, so let the xHCI 3068 + * host know that this link state won't be enabled. 3069 + */ 3070 + hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); 3071 + 3072 + /* Only a configured device will accept the Set Feature U1/U2_ENABLE */ 3073 + else if (udev->actconfig) 3074 + usb_set_device_initiated_lpm(udev, state, true); 3075 + 3076 + } 3077 + 3078 + /* 3079 + * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated 3080 + * U1/U2 entry. 3081 + * 3082 + * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry. 3083 + * If zero is returned, the parent will not allow the link to go into U1/U2. 3084 + * 3085 + * If zero is returned, device-initiated U1/U2 entry may still be enabled, but 3086 + * it won't have an effect on the bus link state because the parent hub will 3087 + * still disallow device-initiated U1/U2 entry. 3088 + * 3089 + * If zero is returned, the xHCI host controller may still think U1/U2 entry is 3090 + * possible. The result will be slightly more bus bandwidth will be taken up 3091 + * (to account for U1/U2 exit latency), but it should be harmless. 3092 + */ 3093 + static int usb_disable_link_state(struct usb_hcd *hcd, struct usb_device *udev, 3094 + enum usb3_link_state state) 3095 + { 3096 + int feature; 3097 + 3098 + switch (state) { 3099 + case USB3_LPM_U1: 3100 + feature = USB_PORT_FEAT_U1_TIMEOUT; 3101 + break; 3102 + case USB3_LPM_U2: 3103 + feature = USB_PORT_FEAT_U2_TIMEOUT; 3104 + break; 3105 + default: 3106 + dev_warn(&udev->dev, "%s: Can't disable non-U1 or U2 state.\n", 3107 + __func__); 3108 + return -EINVAL; 3109 + } 3110 + 3111 + if (usb_set_lpm_timeout(udev, state, 0)) 3112 + return -EBUSY; 3113 + 3114 + usb_set_device_initiated_lpm(udev, state, false); 3115 + 3116 + if (hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state)) 3117 + dev_warn(&udev->dev, "Could not disable xHCI %s timeout, " 3118 + "bus schedule bandwidth may be impacted.\n", 3119 + usb3_lpm_names[state]); 3120 + return 0; 3121 + } 3122 + 3123 + /* 3124 + * Disable hub-initiated and device-initiated U1 and U2 entry. 3125 + * Caller must own the bandwidth_mutex. 3126 + * 3127 + * This will call usb_enable_lpm() on failure, which will decrement 3128 + * lpm_disable_count, and will re-enable LPM if lpm_disable_count reaches zero. 3129 + */ 3130 + int usb_disable_lpm(struct usb_device *udev) 3131 + { 3132 + struct usb_hcd *hcd; 3133 + 3134 + if (!udev || !udev->parent || 3135 + udev->speed != USB_SPEED_SUPER || 3136 + !udev->lpm_capable) 3137 + return 0; 3138 + 3139 + hcd = bus_to_hcd(udev->bus); 3140 + if (!hcd || !hcd->driver->disable_usb3_lpm_timeout) 3141 + return 0; 3142 + 3143 + udev->lpm_disable_count++; 3144 + if ((udev->u1_params.timeout == 0 && udev->u1_params.timeout == 0)) 3145 + return 0; 3146 + 3147 + /* If LPM is enabled, attempt to disable it. */ 3148 + if (usb_disable_link_state(hcd, udev, USB3_LPM_U1)) 3149 + goto enable_lpm; 3150 + if (usb_disable_link_state(hcd, udev, USB3_LPM_U2)) 3151 + goto enable_lpm; 3152 + 3153 + return 0; 3154 + 3155 + enable_lpm: 3156 + usb_enable_lpm(udev); 3157 + return -EBUSY; 3158 + } 3159 + EXPORT_SYMBOL_GPL(usb_disable_lpm); 3160 + 3161 + /* Grab the bandwidth_mutex before calling usb_disable_lpm() */ 3162 + int usb_unlocked_disable_lpm(struct usb_device *udev) 3163 + { 3164 + struct usb_hcd *hcd = bus_to_hcd(udev->bus); 3165 + int ret; 3166 + 3167 + if (!hcd) 3168 + return -EINVAL; 3169 + 3170 + mutex_lock(hcd->bandwidth_mutex); 3171 + ret = usb_disable_lpm(udev); 3172 + mutex_unlock(hcd->bandwidth_mutex); 3173 + 3174 + return ret; 3175 + } 3176 + EXPORT_SYMBOL_GPL(usb_unlocked_disable_lpm); 3177 + 3178 + /* 3179 + * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The 3180 + * xHCI host policy may prevent U1 or U2 from being enabled. 3181 + * 3182 + * Other callers may have disabled link PM, so U1 and U2 entry will be disabled 3183 + * until the lpm_disable_count drops to zero. Caller must own the 3184 + * bandwidth_mutex. 3185 + */ 3186 + void usb_enable_lpm(struct usb_device *udev) 3187 + { 3188 + struct usb_hcd *hcd; 3189 + 3190 + if (!udev || !udev->parent || 3191 + udev->speed != USB_SPEED_SUPER || 3192 + !udev->lpm_capable) 3193 + return; 3194 + 3195 + udev->lpm_disable_count--; 3196 + hcd = bus_to_hcd(udev->bus); 3197 + /* Double check that we can both enable and disable LPM. 3198 + * Device must be configured to accept set feature U1/U2 timeout. 3199 + */ 3200 + if (!hcd || !hcd->driver->enable_usb3_lpm_timeout || 3201 + !hcd->driver->disable_usb3_lpm_timeout) 3202 + return; 3203 + 3204 + if (udev->lpm_disable_count > 0) 3205 + return; 3206 + 3207 + usb_enable_link_state(hcd, udev, USB3_LPM_U1); 3208 + usb_enable_link_state(hcd, udev, USB3_LPM_U2); 3209 + } 3210 + EXPORT_SYMBOL_GPL(usb_enable_lpm); 3211 + 3212 + /* Grab the bandwidth_mutex before calling usb_enable_lpm() */ 3213 + void usb_unlocked_enable_lpm(struct usb_device *udev) 3214 + { 3215 + struct usb_hcd *hcd = bus_to_hcd(udev->bus); 3216 + 3217 + if (!hcd) 3218 + return; 3219 + 3220 + mutex_lock(hcd->bandwidth_mutex); 3221 + usb_enable_lpm(udev); 3222 + mutex_unlock(hcd->bandwidth_mutex); 3223 + } 3224 + EXPORT_SYMBOL_GPL(usb_unlocked_enable_lpm); 3225 + 3226 + 3065 3227 #else /* CONFIG_PM */ 3066 3228 3067 3229 #define hub_suspend NULL 3068 3230 #define hub_resume NULL 3069 3231 #define hub_reset_resume NULL 3232 + 3233 + int usb_disable_lpm(struct usb_device *udev) 3234 + { 3235 + return 0; 3236 + } 3237 + 3238 + void usb_enable_lpm(struct usb_device *udev) { } 3239 + 3240 + int usb_unlocked_disable_lpm(struct usb_device *udev) 3241 + { 3242 + return 0; 3243 + } 3244 + 3245 + void usb_unlocked_enable_lpm(struct usb_device *udev) { } 3070 3246 #endif 3071 3247 3072 3248 ··· 3860 3208 if (udev->wusb == 0 && le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { 3861 3209 retval = usb_get_bos_descriptor(udev); 3862 3210 if (!retval) { 3863 - if (udev->bos->ext_cap && (USB_LPM_SUPPORT & 3864 - le32_to_cpu(udev->bos->ext_cap->bmAttributes))) 3865 - udev->lpm_capable = 1; 3211 + udev->lpm_capable = usb_device_supports_lpm(udev); 3212 + usb_set_lpm_parameters(udev); 3866 3213 } 3867 3214 } 3868 3215 ··· 4693 4042 goto done; 4694 4043 4695 4044 mutex_lock(hcd->bandwidth_mutex); 4045 + /* Disable LPM while we reset the device and reinstall the alt settings. 4046 + * Device-initiated LPM settings, and system exit latency settings are 4047 + * cleared when the device is reset, so we have to set them up again. 4048 + */ 4049 + ret = usb_disable_lpm(udev); 4050 + if (ret) { 4051 + dev_err(&udev->dev, "%s Failed to disable LPM\n.", __func__); 4052 + mutex_unlock(hcd->bandwidth_mutex); 4053 + goto done; 4054 + } 4696 4055 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); 4697 4056 if (ret < 0) { 4698 4057 dev_warn(&udev->dev, 4699 4058 "Busted HC? Not enough HCD resources for " 4700 4059 "old configuration.\n"); 4060 + usb_enable_lpm(udev); 4701 4061 mutex_unlock(hcd->bandwidth_mutex); 4702 4062 goto re_enumerate; 4703 4063 } ··· 4720 4058 dev_err(&udev->dev, 4721 4059 "can't restore configuration #%d (error=%d)\n", 4722 4060 udev->actconfig->desc.bConfigurationValue, ret); 4061 + usb_enable_lpm(udev); 4723 4062 mutex_unlock(hcd->bandwidth_mutex); 4724 4063 goto re_enumerate; 4725 4064 } ··· 4759 4096 desc->bInterfaceNumber, 4760 4097 desc->bAlternateSetting, 4761 4098 ret); 4099 + usb_unlocked_enable_lpm(udev); 4762 4100 goto re_enumerate; 4763 4101 } 4764 4102 } 4765 4103 4104 + /* Now that the alt settings are re-installed, enable LPM. */ 4105 + usb_unlocked_enable_lpm(udev); 4766 4106 done: 4767 4107 return 0; 4768 4108
+38
drivers/usb/core/message.c
··· 1308 1308 * Remove the current alt setting and add the new alt setting. 1309 1309 */ 1310 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 1319 ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt); 1312 1320 if (ret < 0) { 1313 1321 dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n", 1314 1322 alternate); 1323 + usb_enable_lpm(dev); 1315 1324 mutex_unlock(hcd->bandwidth_mutex); 1316 1325 return ret; 1317 1326 } ··· 1343 1334 } else if (ret < 0) { 1344 1335 /* Re-instate the old alt setting */ 1345 1336 usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting); 1337 + usb_enable_lpm(dev); 1346 1338 mutex_unlock(hcd->bandwidth_mutex); 1347 1339 return ret; 1348 1340 } ··· 1363 1353 usb_disable_interface(dev, iface, true); 1364 1354 1365 1355 iface->cur_altsetting = alt; 1356 + 1357 + /* Now that the interface is installed, re-enable LPM. */ 1358 + usb_unlocked_enable_lpm(dev); 1366 1359 1367 1360 /* If the interface only has one altsetting and the device didn't 1368 1361 * accept the request, we attempt to carry out the equivalent action ··· 1450 1437 config = dev->actconfig; 1451 1438 retval = 0; 1452 1439 mutex_lock(hcd->bandwidth_mutex); 1440 + /* Disable LPM, and re-enable it once the configuration is reset, so 1441 + * that the xHCI driver can recalculate the U1/U2 timeouts. 1442 + */ 1443 + if (usb_disable_lpm(dev)) { 1444 + dev_err(&dev->dev, "%s Failed to disable LPM\n.", __func__); 1445 + mutex_unlock(hcd->bandwidth_mutex); 1446 + return -ENOMEM; 1447 + } 1453 1448 /* Make sure we have enough bandwidth for each alternate setting 0 */ 1454 1449 for (i = 0; i < config->desc.bNumInterfaces; i++) { 1455 1450 struct usb_interface *intf = config->interface[i]; ··· 1486 1465 usb_hcd_alloc_bandwidth(dev, NULL, 1487 1466 alt, intf->cur_altsetting); 1488 1467 } 1468 + usb_enable_lpm(dev); 1489 1469 mutex_unlock(hcd->bandwidth_mutex); 1490 1470 return retval; 1491 1471 } ··· 1524 1502 create_intf_ep_devs(intf); 1525 1503 } 1526 1504 } 1505 + /* Now that the interfaces are installed, re-enable LPM. */ 1506 + usb_unlocked_enable_lpm(dev); 1527 1507 return 0; 1528 1508 } 1529 1509 EXPORT_SYMBOL_GPL(usb_reset_configuration); ··· 1787 1763 * this call fails, the device state is unchanged. 1788 1764 */ 1789 1765 mutex_lock(hcd->bandwidth_mutex); 1766 + /* Disable LPM, and re-enable it once the new configuration is 1767 + * installed, so that the xHCI driver can recalculate the U1/U2 1768 + * timeouts. 1769 + */ 1770 + if (usb_disable_lpm(dev)) { 1771 + dev_err(&dev->dev, "%s Failed to disable LPM\n.", __func__); 1772 + mutex_unlock(hcd->bandwidth_mutex); 1773 + return -ENOMEM; 1774 + } 1790 1775 ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); 1791 1776 if (ret < 0) { 1777 + usb_enable_lpm(dev); 1792 1778 mutex_unlock(hcd->bandwidth_mutex); 1793 1779 usb_autosuspend_device(dev); 1794 1780 goto free_interfaces; ··· 1818 1784 if (!cp) { 1819 1785 usb_set_device_state(dev, USB_STATE_ADDRESS); 1820 1786 usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); 1787 + usb_enable_lpm(dev); 1821 1788 mutex_unlock(hcd->bandwidth_mutex); 1822 1789 usb_autosuspend_device(dev); 1823 1790 goto free_interfaces; ··· 1872 1837 if (cp->string == NULL && 1873 1838 !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS)) 1874 1839 cp->string = usb_cache_string(dev, cp->desc.iConfiguration); 1840 + 1841 + /* Now that the interfaces are installed, re-enable LPM. */ 1842 + usb_unlocked_enable_lpm(dev); 1875 1843 1876 1844 /* Now that all the interfaces are set up, register them 1877 1845 * to trigger binding of drivers to interfaces. probe()
+19
drivers/usb/host/xhci-hub.c
··· 475 475 struct xhci_bus_state *bus_state; 476 476 u16 link_state = 0; 477 477 u16 wake_mask = 0; 478 + u16 timeout = 0; 478 479 479 480 max_ports = xhci_get_ports(hcd, &port_array); 480 481 bus_state = &xhci->bus_state[hcd_index(hcd)]; ··· 624 623 link_state = (wIndex & 0xff00) >> 3; 625 624 if (wValue == USB_PORT_FEAT_REMOTE_WAKE_MASK) 626 625 wake_mask = wIndex & 0xff00; 626 + /* The MSB of wIndex is the U1/U2 timeout */ 627 + timeout = (wIndex & 0xff00) >> 8; 627 628 wIndex &= 0xff; 628 629 if (!wIndex || wIndex > max_ports) 629 630 goto error; ··· 749 746 xhci_writel(xhci, temp, port_array[wIndex]); 750 747 751 748 temp = xhci_readl(xhci, port_array[wIndex]); 749 + break; 750 + case USB_PORT_FEAT_U1_TIMEOUT: 751 + if (hcd->speed != HCD_USB3) 752 + goto error; 753 + temp = xhci_readl(xhci, port_array[wIndex] + 1); 754 + temp &= ~PORT_U1_TIMEOUT_MASK; 755 + temp |= PORT_U1_TIMEOUT(timeout); 756 + xhci_writel(xhci, temp, port_array[wIndex] + 1); 757 + break; 758 + case USB_PORT_FEAT_U2_TIMEOUT: 759 + if (hcd->speed != HCD_USB3) 760 + goto error; 761 + temp = xhci_readl(xhci, port_array[wIndex] + 1); 762 + temp &= ~PORT_U2_TIMEOUT_MASK; 763 + temp |= PORT_U2_TIMEOUT(timeout); 764 + xhci_writel(xhci, temp, port_array[wIndex] + 1); 752 765 break; 753 766 default: 754 767 goto error;
+39
drivers/usb/host/xhci-mem.c
··· 1791 1791 { 1792 1792 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 1793 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 1802 unsigned long flags; 1795 1803 int size; 1796 1804 int i; ··· 1815 1807 xhci->event_ring = NULL; 1816 1808 xhci_dbg(xhci, "Freed event ring\n"); 1817 1809 1810 + if (xhci->lpm_command) 1811 + xhci_free_command(xhci, xhci->lpm_command); 1812 + xhci->cmd_ring_reserved_trbs = 0; 1818 1813 if (xhci->cmd_ring) 1819 1814 xhci_ring_free(xhci, xhci->cmd_ring); 1820 1815 xhci->cmd_ring = NULL; ··· 1860 1849 } 1861 1850 spin_unlock_irqrestore(&xhci->lock, flags); 1862 1851 1852 + bwt = &xhci->rh_bw->bw_table; 1853 + for (i = 0; i < XHCI_MAX_INTERVAL; i++) { 1854 + endpoints = &bwt->interval_bw[i].endpoints; 1855 + list_for_each_safe(ep, q, endpoints) { 1856 + virt_ep = list_entry(ep, struct xhci_virt_ep, bw_endpoint_list); 1857 + list_del(&virt_ep->bw_endpoint_list); 1858 + kfree(virt_ep); 1859 + } 1860 + } 1861 + 1862 + tt_list_head = &xhci->rh_bw->tts; 1863 + list_for_each_safe(tt, q, tt_list_head) { 1864 + tt_info = list_entry(tt, struct xhci_tt_bw_info, tt_list); 1865 + list_del(tt); 1866 + kfree(tt_info); 1867 + } 1868 + 1863 1869 xhci->num_usb2_ports = 0; 1864 1870 xhci->num_usb3_ports = 0; 1871 + xhci->num_active_eps = 0; 1865 1872 kfree(xhci->usb2_ports); 1866 1873 kfree(xhci->usb3_ports); 1867 1874 kfree(xhci->port_array); ··· 2378 2349 xhci_dbg(xhci, "// Setting command ring address to 0x%x\n", val); 2379 2350 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); 2380 2351 xhci_dbg_cmd_ptrs(xhci); 2352 + 2353 + xhci->lpm_command = xhci_alloc_command(xhci, true, true, flags); 2354 + if (!xhci->lpm_command) 2355 + goto fail; 2356 + 2357 + /* Reserve one command ring TRB for disabling LPM. 2358 + * Since the USB core grabs the shared usb_bus bandwidth mutex before 2359 + * disabling LPM, we only need to reserve one TRB for all devices. 2360 + */ 2361 + xhci->cmd_ring_reserved_trbs++; 2381 2362 2382 2363 val = xhci_readl(xhci, &xhci->cap_regs->db_off); 2383 2364 val &= DBOFF_MASK;
+14
drivers/usb/host/xhci-pci.c
··· 72 72 xhci_dbg(xhci, "QUIRK: Fresco Logic revision %u " 73 73 "has broken MSI implementation\n", 74 74 pdev->revision); 75 + xhci->quirks |= XHCI_TRUST_TX_LENGTH; 75 76 } 76 77 77 78 if (pdev->vendor == PCI_VENDOR_ID_NEC) ··· 84 83 /* AMD PLL quirk */ 85 84 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info()) 86 85 xhci->quirks |= XHCI_AMD_PLL_FIX; 86 + if (pdev->vendor == PCI_VENDOR_ID_INTEL) { 87 + xhci->quirks |= XHCI_LPM_SUPPORT; 88 + xhci->quirks |= XHCI_INTEL_HOST; 89 + } 87 90 if (pdev->vendor == PCI_VENDOR_ID_INTEL && 88 91 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) { 89 92 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; ··· 174 169 if (retval) 175 170 goto put_usb3_hcd; 176 171 /* Roothub already marked as USB 3.0 speed */ 172 + 173 + /* We know the LPM timeout algorithms for this host, let the USB core 174 + * enable and disable LPM for devices under the USB 3.0 roothub. 175 + */ 176 + if (xhci->quirks & XHCI_LPM_SUPPORT) 177 + hcd_to_bus(xhci->shared_hcd)->root_hub->lpm_capable = 1; 178 + 177 179 return 0; 178 180 179 181 put_usb3_hcd: ··· 304 292 */ 305 293 .update_device = xhci_update_device, 306 294 .set_usb2_hw_lpm = xhci_set_usb2_hardware_lpm, 295 + .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout, 296 + .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout, 307 297 }; 308 298 309 299 /*-------------------------------------------------------------------------*/
+19 -5
drivers/usb/host/xhci-ring.c
··· 1787 1787 /* handle completion code */ 1788 1788 switch (trb_comp_code) { 1789 1789 case COMP_SUCCESS: 1790 - frame->status = 0; 1791 - break; 1790 + if (TRB_LEN(le32_to_cpu(event->transfer_len)) == 0) { 1791 + frame->status = 0; 1792 + break; 1793 + } 1794 + if ((xhci->quirks & XHCI_TRUST_TX_LENGTH)) 1795 + trb_comp_code = COMP_SHORT_TX; 1792 1796 case COMP_SHORT_TX: 1793 1797 frame->status = td->urb->transfer_flags & URB_SHORT_NOT_OK ? 1794 1798 -EREMOTEIO : 0; ··· 1889 1885 switch (trb_comp_code) { 1890 1886 case COMP_SUCCESS: 1891 1887 /* Double check that the HW transferred everything. */ 1892 - if (event_trb != td->last_trb) { 1888 + if (event_trb != td->last_trb || 1889 + TRB_LEN(le32_to_cpu(event->transfer_len)) != 0) { 1893 1890 xhci_warn(xhci, "WARN Successful completion " 1894 1891 "on short TX\n"); 1895 1892 if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1896 1893 *status = -EREMOTEIO; 1897 1894 else 1898 1895 *status = 0; 1896 + if ((xhci->quirks & XHCI_TRUST_TX_LENGTH)) 1897 + trb_comp_code = COMP_SHORT_TX; 1899 1898 } else { 1900 1899 *status = 0; 1901 1900 } ··· 2057 2050 * transfer type 2058 2051 */ 2059 2052 case COMP_SUCCESS: 2053 + if (TRB_LEN(le32_to_cpu(event->transfer_len)) == 0) 2054 + break; 2055 + if (xhci->quirks & XHCI_TRUST_TX_LENGTH) 2056 + trb_comp_code = COMP_SHORT_TX; 2057 + else 2058 + xhci_warn(xhci, "WARN Successful completion on short TX: " 2059 + "needs XHCI_TRUST_TX_LENGTH quirk?\n"); 2060 2060 case COMP_SHORT_TX: 2061 2061 break; 2062 2062 case COMP_STOP: ··· 3609 3595 3610 3596 /* Queue an evaluate context command TRB */ 3611 3597 int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 3612 - u32 slot_id) 3598 + u32 slot_id, bool command_must_succeed) 3613 3599 { 3614 3600 return queue_command(xhci, lower_32_bits(in_ctx_ptr), 3615 3601 upper_32_bits(in_ctx_ptr), 0, 3616 3602 TRB_TYPE(TRB_EVAL_CONTEXT) | SLOT_ID_FOR_TRB(slot_id), 3617 - false); 3603 + command_must_succeed); 3618 3604 } 3619 3605 3620 3606 /*
+453 -1
drivers/usb/host/xhci.c
··· 2446 2446 udev->slot_id, must_succeed); 2447 2447 else 2448 2448 ret = xhci_queue_evaluate_context(xhci, in_ctx->dma, 2449 - udev->slot_id); 2449 + udev->slot_id, must_succeed); 2450 2450 if (ret < 0) { 2451 2451 if (command) 2452 2452 list_del(&command->cmd_list); ··· 3836 3836 spin_unlock_irqrestore(&xhci->lock, flags); 3837 3837 return 0; 3838 3838 } 3839 + 3840 + /*---------------------- USB 3.0 Link PM functions ------------------------*/ 3841 + 3842 + /* Service interval in nanoseconds = 2^(bInterval - 1) * 125us * 1000ns / 1us */ 3843 + static 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 + 3849 + static 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 + */ 3900 + static 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 + */ 3955 + static 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 + 3983 + static 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 + 4000 + static 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 + 4025 + static 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 + 4042 + static 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 + 4066 + static 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 + */ 4080 + static 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 + */ 4149 + static 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 + 4195 + static 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. */ 4241 + int 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 + 4272 + int 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 + /*-------------------------------------------------------------------------*/ 3839 4291 3840 4292 int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev) 3841 4293 {
+14 -1
drivers/usb/host/xhci.h
··· 362 362 * Timeout can be up to 127us. 0xFF means an infinite timeout. 363 363 */ 364 364 #define PORT_U1_TIMEOUT(p) ((p) & 0xff) 365 + #define PORT_U1_TIMEOUT_MASK 0xff 365 366 /* Inactivity timer value for transitions into U2 */ 366 367 #define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8) 368 + #define PORT_U2_TIMEOUT_MASK (0xff << 8) 367 369 /* Bits 24:31 for port testing */ 368 370 369 371 /* USB2 Protocol PORTSPMSC */ ··· 916 914 u8 real_port; 917 915 struct xhci_interval_bw_table *bw_table; 918 916 struct xhci_tt_bw_info *tt_info; 917 + /* The current max exit latency for the enabled USB3 link states. */ 918 + u16 current_mel; 919 919 }; 920 920 921 921 /* ··· 1428 1424 /* slot enabling and address device helpers */ 1429 1425 struct completion addr_dev; 1430 1426 int slot_id; 1427 + /* For USB 3.0 LPM enable/disable. */ 1428 + struct xhci_command *lpm_command; 1431 1429 /* Internal mirror of the HW's dcbaa */ 1432 1430 struct xhci_virt_device *devs[MAX_HC_SLOTS]; 1433 1431 /* For keeping track of bandwidth domains per roothub. */ ··· 1487 1481 #define XHCI_RESET_ON_RESUME (1 << 7) 1488 1482 #define XHCI_SW_BW_CHECKING (1 << 8) 1489 1483 #define XHCI_AMD_0x96_HOST (1 << 9) 1484 + #define XHCI_TRUST_TX_LENGTH (1 << 10) 1485 + #define XHCI_LPM_SUPPORT (1 << 11) 1486 + #define XHCI_INTEL_HOST (1 << 12) 1490 1487 unsigned int num_active_eps; 1491 1488 unsigned int limit_active_eps; 1492 1489 /* There are two roothubs to keep track of bus suspend info for */ ··· 1763 1754 int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1764 1755 u32 slot_id, bool command_must_succeed); 1765 1756 int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1766 - u32 slot_id); 1757 + u32 slot_id, bool command_must_succeed); 1767 1758 int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, 1768 1759 unsigned int ep_index); 1769 1760 int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id); ··· 1787 1778 /* xHCI roothub code */ 1788 1779 void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array, 1789 1780 int port_id, u32 link_state); 1781 + int xhci_enable_usb3_lpm_timeout(struct usb_hcd *hcd, 1782 + struct usb_device *udev, enum usb3_link_state state); 1783 + int xhci_disable_usb3_lpm_timeout(struct usb_hcd *hcd, 1784 + struct usb_device *udev, enum usb3_link_state state); 1790 1785 void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array, 1791 1786 int port_id, u32 port_bit); 1792 1787 int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
+60
include/linux/usb.h
··· 378 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 + */ 388 + struct 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 421 * struct usb_device - kernel's representation of a USB device 383 422 * @devnum: device number; address on a USB bus ··· 474 435 * specific data for the device. 475 436 * @slot_id: Slot ID assigned by xHCI 476 437 * @removable: Device can be physically removed from this port 438 + * @u1_params: exit latencies for USB3 U1 LPM state, and hub-initiated timeout. 439 + * @u2_params: exit latencies for USB3 U2 LPM state, and hub-initiated timeout. 440 + * @lpm_disable_count: Ref count used by usb_disable_lpm() and usb_enable_lpm() 441 + * to keep track of the number of functions that require USB 3.0 Link Power 442 + * Management to be disabled for this usb_device. This count should only 443 + * be manipulated by those functions, with the bandwidth_mutex is held. 477 444 * 478 445 * Notes: 479 446 * Usbcore drivers should not set usbdev->state directly. Instead use ··· 526 481 unsigned lpm_capable:1; 527 482 unsigned usb2_hw_lpm_capable:1; 528 483 unsigned usb2_hw_lpm_enabled:1; 484 + unsigned usb3_lpm_enabled:1; 529 485 int string_langid; 530 486 531 487 /* static strings from the device */ ··· 553 507 struct wusb_dev *wusb_dev; 554 508 int slot_id; 555 509 enum usb_device_removable removable; 510 + struct usb3_lpm_parameters u1_params; 511 + struct usb3_lpm_parameters u2_params; 512 + unsigned lpm_disable_count; 513 + unsigned hub_initiated_lpm_disable_count; 556 514 }; 557 515 #define to_usb_device(d) container_of(d, struct usb_device, dev) 558 516 ··· 591 541 extern void usb_autopm_put_interface_async(struct usb_interface *intf); 592 542 extern void usb_autopm_get_interface_no_resume(struct usb_interface *intf); 593 543 extern void usb_autopm_put_interface_no_suspend(struct usb_interface *intf); 544 + 545 + extern int usb_disable_lpm(struct usb_device *udev); 546 + extern void usb_enable_lpm(struct usb_device *udev); 547 + /* Same as above, but these functions lock/unlock the bandwidth_mutex. */ 548 + extern int usb_unlocked_disable_lpm(struct usb_device *udev); 549 + extern void usb_unlocked_enable_lpm(struct usb_device *udev); 594 550 595 551 static inline void usb_mark_last_busy(struct usb_device *udev) 596 552 { ··· 898 842 * for interfaces bound to this driver. 899 843 * @soft_unbind: if set to 1, the USB core will not kill URBs and disable 900 844 * endpoints before calling the driver's disconnect method. 845 + * @disable_hub_initiated_lpm: if set to 0, the USB core will not allow hubs 846 + * to initiate lower power link state transitions when an idle timeout 847 + * occurs. Device-initiated USB 3.0 link PM will still be allowed. 901 848 * 902 849 * USB interface drivers must provide a name, probe() and disconnect() 903 850 * methods, and an id_table. Other driver fields are optional. ··· 941 882 struct usbdrv_wrap drvwrap; 942 883 unsigned int no_dynamic_id:1; 943 884 unsigned int supports_autosuspend:1; 885 + unsigned int disable_hub_initiated_lpm:1; 944 886 unsigned int soft_unbind:1; 945 887 }; 946 888 #define to_usb_driver(d) container_of(d, struct usb_driver, drvwrap.driver)
+2
include/linux/usb/ch11.h
··· 76 76 #define USB_PORT_FEAT_C_BH_PORT_RESET 29 77 77 #define USB_PORT_FEAT_FORCE_LINKPM_ACCEPT 30 78 78 79 + #define USB_PORT_LPM_TIMEOUT(p) (((p) & 0xff) << 8) 80 + 79 81 /* USB 3.0 hub remote wake mask bits, see table 10-14 */ 80 82 #define USB_PORT_FEAT_REMOTE_WAKE_CONNECT (1 << 8) 81 83 #define USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT (1 << 9)
+56
include/linux/usb/ch9.h
··· 392 392 #define USB_ENDPOINT_XFER_INT 3 393 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 400 #define USB_ENDPOINT_SYNCTYPE 0x0c 396 401 #define USB_ENDPOINT_SYNC_NONE (0 << 2) 397 402 #define USB_ENDPOINT_SYNC_ASYNC (1 << 2) ··· 597 592 static inline int usb_endpoint_maxp(const struct usb_endpoint_descriptor *epd) 598 593 { 599 594 return __le16_to_cpu(epd->wMaxPacketSize); 595 + } 596 + 597 + static inline int usb_endpoint_interrupt_type( 598 + const struct usb_endpoint_descriptor *epd) 599 + { 600 + return epd->bmAttributes & USB_ENDPOINT_INTRTYPE; 600 601 } 601 602 602 603 /*-------------------------------------------------------------------------*/ ··· 945 934 * suspend states. (L2 being original USB 1.1 suspend.) 946 935 */ 947 936 }; 937 + 938 + enum usb3_link_state { 939 + USB3_LPM_U0 = 0, 940 + USB3_LPM_U1, 941 + USB3_LPM_U2, 942 + USB3_LPM_U3 943 + }; 944 + 945 + /* 946 + * A U1 timeout of 0x0 means the parent hub will reject any transitions to U1. 947 + * 0xff means the parent hub will accept transitions to U1, but will not 948 + * initiate a transition. 949 + * 950 + * A U1 timeout of 0x1 to 0x7F also causes the hub to initiate a transition to 951 + * U1 after that many microseconds. Timeouts of 0x80 to 0xFE are reserved 952 + * values. 953 + * 954 + * A U2 timeout of 0x0 means the parent hub will reject any transitions to U2. 955 + * 0xff means the parent hub will accept transitions to U2, but will not 956 + * initiate a transition. 957 + * 958 + * A U2 timeout of 0x1 to 0xFE also causes the hub to initiate a transition to 959 + * U2 after N*256 microseconds. Therefore a U2 timeout value of 0x1 means a U2 960 + * idle timer of 256 microseconds, 0x2 means 512 microseconds, 0xFE means 961 + * 65.024ms. 962 + */ 963 + #define USB3_LPM_DISABLED 0x0 964 + #define USB3_LPM_U1_MAX_TIMEOUT 0x7F 965 + #define USB3_LPM_U2_MAX_TIMEOUT 0xFE 966 + #define USB3_LPM_DEVICE_INITIATED 0xFF 967 + 968 + struct usb_set_sel_req { 969 + __u8 u1_sel; 970 + __u8 u1_pel; 971 + __le16 u2_sel; 972 + __le16 u2_pel; 973 + } __attribute__ ((packed)); 974 + 975 + /* 976 + * The Set System Exit Latency control transfer provides one byte each for 977 + * U1 SEL and U1 PEL, so the max exit latency is 0xFF. U2 SEL and U2 PEL each 978 + * are two bytes long. 979 + */ 980 + #define USB3_LPM_MAX_U1_SEL_PEL 0xFF 981 + #define USB3_LPM_MAX_U2_SEL_PEL 0xFFFF 948 982 949 983 /*-------------------------------------------------------------------------*/ 950 984
+9
include/linux/usb/hcd.h
··· 344 344 */ 345 345 int (*update_device)(struct usb_hcd *, struct usb_device *); 346 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 349 358 extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);