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

USB: Extend pci resume function to handle PM events

Currently, the pci_resume method has only a flag indicating whether the
system is resuming from hibernation. In order to handle all PM events like
AUTO_RESUME (runtime resume from device in D3), RESUME (system resume from
s2idle, S3 or S4 states) etc change the pci_resume method to handle all PM
events.

Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20230428140056.1318981-2-Basavaraj.Natikar@amd.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Basavaraj Natikar and committed by
Greg Kroah-Hartman
1f7d5520 986866c3

+36 -25
+13 -11
drivers/usb/core/hcd-pci.c
··· 415 415 return 0; 416 416 } 417 417 418 - static int suspend_common(struct device *dev, bool do_wakeup) 418 + static int suspend_common(struct device *dev, pm_message_t msg) 419 419 { 420 420 struct pci_dev *pci_dev = to_pci_dev(dev); 421 421 struct usb_hcd *hcd = pci_get_drvdata(pci_dev); 422 + bool do_wakeup; 422 423 int retval; 424 + 425 + do_wakeup = PMSG_IS_AUTO(msg) ? true : device_may_wakeup(dev); 423 426 424 427 /* Root hub suspend should have stopped all downstream traffic, 425 428 * and all bus master traffic. And done so for both the interface ··· 450 447 (retval == 0 && do_wakeup && hcd->shared_hcd && 451 448 HCD_WAKEUP_PENDING(hcd->shared_hcd))) { 452 449 if (hcd->driver->pci_resume) 453 - hcd->driver->pci_resume(hcd, false); 450 + hcd->driver->pci_resume(hcd, msg); 454 451 retval = -EBUSY; 455 452 } 456 453 if (retval) ··· 473 470 return retval; 474 471 } 475 472 476 - static int resume_common(struct device *dev, int event) 473 + static int resume_common(struct device *dev, pm_message_t msg) 477 474 { 478 475 struct pci_dev *pci_dev = to_pci_dev(dev); 479 476 struct usb_hcd *hcd = pci_get_drvdata(pci_dev); ··· 501 498 * No locking is needed because PCI controller drivers do not 502 499 * get unbound during system resume. 503 500 */ 504 - if (pci_dev->class == CL_EHCI && event != PM_EVENT_AUTO_RESUME) 501 + if (pci_dev->class == CL_EHCI && msg.event != PM_EVENT_AUTO_RESUME) 505 502 for_each_companion(pci_dev, hcd, 506 503 ehci_wait_for_companions); 507 504 508 - retval = hcd->driver->pci_resume(hcd, 509 - event == PM_EVENT_RESTORE); 505 + retval = hcd->driver->pci_resume(hcd, msg); 510 506 if (retval) { 511 507 dev_err(dev, "PCI post-resume error %d!\n", retval); 512 508 usb_hc_died(hcd); ··· 518 516 519 517 static int hcd_pci_suspend(struct device *dev) 520 518 { 521 - return suspend_common(dev, device_may_wakeup(dev)); 519 + return suspend_common(dev, PMSG_SUSPEND); 522 520 } 523 521 524 522 static int hcd_pci_suspend_noirq(struct device *dev) ··· 579 577 580 578 static int hcd_pci_resume(struct device *dev) 581 579 { 582 - return resume_common(dev, PM_EVENT_RESUME); 580 + return resume_common(dev, PMSG_RESUME); 583 581 } 584 582 585 583 static int hcd_pci_restore(struct device *dev) 586 584 { 587 - return resume_common(dev, PM_EVENT_RESTORE); 585 + return resume_common(dev, PMSG_RESTORE); 588 586 } 589 587 590 588 #else ··· 602 600 { 603 601 int retval; 604 602 605 - retval = suspend_common(dev, true); 603 + retval = suspend_common(dev, PMSG_AUTO_SUSPEND); 606 604 if (retval == 0) 607 605 powermac_set_asic(to_pci_dev(dev), 0); 608 606 dev_dbg(dev, "hcd_pci_runtime_suspend: %d\n", retval); ··· 614 612 int retval; 615 613 616 614 powermac_set_asic(to_pci_dev(dev), 1); 617 - retval = resume_common(dev, PM_EVENT_AUTO_RESUME); 615 + retval = resume_common(dev, PMSG_AUTO_RESUME); 618 616 dev_dbg(dev, "hcd_pci_runtime_resume: %d\n", retval); 619 617 return retval; 620 618 }
+2 -1
drivers/usb/host/ehci-pci.c
··· 354 354 * Also they depend on separate root hub suspend/resume. 355 355 */ 356 356 357 - static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated) 357 + static int ehci_pci_resume(struct usb_hcd *hcd, pm_message_t msg) 358 358 { 359 359 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 360 360 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 361 + bool hibernated = (msg.event == PM_EVENT_RESTORE); 361 362 362 363 if (ehci_resume(hcd, hibernated) != 0) 363 364 (void) ehci_pci_reinit(ehci, pdev);
+7 -1
drivers/usb/host/ohci-pci.c
··· 301 301 #endif 302 302 }; 303 303 304 + #ifdef CONFIG_PM 305 + static int ohci_pci_resume(struct usb_hcd *hcd, pm_message_t msg) 306 + { 307 + return ohci_resume(hcd, msg.event == PM_EVENT_RESTORE); 308 + } 309 + #endif 304 310 static int __init ohci_pci_init(void) 305 311 { 306 312 if (usb_disabled()) ··· 317 311 #ifdef CONFIG_PM 318 312 /* Entries for the PCI suspend/resume callbacks are special */ 319 313 ohci_pci_hc_driver.pci_suspend = ohci_suspend; 320 - ohci_pci_hc_driver.pci_resume = ohci_resume; 314 + ohci_pci_hc_driver.pci_resume = ohci_pci_resume; 321 315 #endif 322 316 323 317 return pci_register_driver(&ohci_pci_driver);
+4 -3
drivers/usb/host/uhci-pci.c
··· 167 167 168 168 #ifdef CONFIG_PM 169 169 170 - static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated); 170 + static int uhci_pci_resume(struct usb_hcd *hcd, pm_message_t state); 171 171 172 172 static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) 173 173 { ··· 202 202 203 203 /* Check for race with a wakeup request */ 204 204 if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) { 205 - uhci_pci_resume(hcd, false); 205 + uhci_pci_resume(hcd, PMSG_SUSPEND); 206 206 rc = -EBUSY; 207 207 } 208 208 return rc; 209 209 } 210 210 211 - static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated) 211 + static int uhci_pci_resume(struct usb_hcd *hcd, pm_message_t msg) 212 212 { 213 + bool hibernated = (msg.event == PM_EVENT_RESTORE); 213 214 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 214 215 215 216 dev_dbg(uhci_dev(uhci), "%s\n", __func__);
+1 -1
drivers/usb/host/xhci-histb.c
··· 367 367 if (!device_may_wakeup(dev)) 368 368 xhci_histb_host_enable(histb); 369 369 370 - return xhci_resume(xhci, 0); 370 + return xhci_resume(xhci, PMSG_RESUME); 371 371 } 372 372 373 373 static const struct dev_pm_ops xhci_histb_pm_ops = {
+2 -2
drivers/usb/host/xhci-pci.c
··· 824 824 return ret; 825 825 } 826 826 827 - static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated) 827 + static int xhci_pci_resume(struct usb_hcd *hcd, pm_message_t msg) 828 828 { 829 829 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 830 830 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); ··· 859 859 if (xhci->quirks & XHCI_PME_STUCK_QUIRK) 860 860 xhci_pme_quirk(hcd); 861 861 862 - retval = xhci_resume(xhci, hibernated); 862 + retval = xhci_resume(xhci, msg); 863 863 return retval; 864 864 } 865 865
+2 -2
drivers/usb/host/xhci-plat.c
··· 478 478 if (ret) 479 479 return ret; 480 480 481 - ret = xhci_resume(xhci, 0); 481 + ret = xhci_resume(xhci, PMSG_RESUME); 482 482 if (ret) 483 483 return ret; 484 484 ··· 507 507 struct usb_hcd *hcd = dev_get_drvdata(dev); 508 508 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 509 509 510 - return xhci_resume(xhci, 0); 510 + return xhci_resume(xhci, PMSG_AUTO_RESUME); 511 511 } 512 512 513 513 const struct dev_pm_ops xhci_plat_pm_ops = {
+1 -1
drivers/usb/host/xhci-tegra.c
··· 2272 2272 if (wakeup) 2273 2273 tegra_xhci_disable_phy_sleepwalk(tegra); 2274 2274 2275 - err = xhci_resume(xhci, 0); 2275 + err = xhci_resume(xhci, runtime ? PMSG_AUTO_RESUME : PMSG_RESUME); 2276 2276 if (err < 0) { 2277 2277 dev_err(tegra->dev, "failed to resume XHCI: %d\n", err); 2278 2278 goto disable_phy;
+2 -1
drivers/usb/host/xhci.c
··· 960 960 * This is called when the machine transition from S3/S4 mode. 961 961 * 962 962 */ 963 - int xhci_resume(struct xhci_hcd *xhci, bool hibernated) 963 + int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg) 964 964 { 965 + bool hibernated = (msg.event == PM_EVENT_RESTORE); 965 966 u32 command, temp = 0; 966 967 struct usb_hcd *hcd = xhci_to_hcd(xhci); 967 968 int retval = 0;
+1 -1
drivers/usb/host/xhci.h
··· 2140 2140 int xhci_ext_cap_init(struct xhci_hcd *xhci); 2141 2141 2142 2142 int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup); 2143 - int xhci_resume(struct xhci_hcd *xhci, bool hibernated); 2143 + int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg); 2144 2144 2145 2145 irqreturn_t xhci_irq(struct usb_hcd *hcd); 2146 2146 irqreturn_t xhci_msi_irq(int irq, void *hcd);
+1 -1
include/linux/usb/hcd.h
··· 267 267 int (*pci_suspend)(struct usb_hcd *hcd, bool do_wakeup); 268 268 269 269 /* called after entering D0 (etc), before resuming the hub */ 270 - int (*pci_resume)(struct usb_hcd *hcd, bool hibernated); 270 + int (*pci_resume)(struct usb_hcd *hcd, pm_message_t state); 271 271 272 272 /* called just before hibernate final D3 state, allows host to poweroff parts */ 273 273 int (*pci_poweroff_late)(struct usb_hcd *hcd, bool do_wakeup);