USB: Extend pci resume function to handle PM events
authorBasavaraj Natikar <Basavaraj.Natikar@amd.com>
Fri, 28 Apr 2023 14:00:55 +0000 (19:30 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 May 2023 08:33:18 +0000 (17:33 +0900)
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>
drivers/usb/core/hcd-pci.c
drivers/usb/host/ehci-pci.c
drivers/usb/host/ohci-pci.c
drivers/usb/host/uhci-pci.c
drivers/usb/host/xhci-histb.c
drivers/usb/host/xhci-pci.c
drivers/usb/host/xhci-plat.c
drivers/usb/host/xhci-tegra.c
drivers/usb/host/xhci.c
drivers/usb/host/xhci.h
include/linux/usb/hcd.h

index ab2f373..9902806 100644 (file)
@@ -415,12 +415,15 @@ static int check_root_hub_suspended(struct device *dev)
        return 0;
 }
 
-static int suspend_common(struct device *dev, bool do_wakeup)
+static int suspend_common(struct device *dev, pm_message_t msg)
 {
        struct pci_dev          *pci_dev = to_pci_dev(dev);
        struct usb_hcd          *hcd = pci_get_drvdata(pci_dev);
+       bool                    do_wakeup;
        int                     retval;
 
+       do_wakeup = PMSG_IS_AUTO(msg) ? true : device_may_wakeup(dev);
+
        /* Root hub suspend should have stopped all downstream traffic,
         * and all bus master traffic.  And done so for both the interface
         * and the stub usb_device (which we check here).  But maybe it
@@ -447,7 +450,7 @@ static int suspend_common(struct device *dev, bool do_wakeup)
                                (retval == 0 && do_wakeup && hcd->shared_hcd &&
                                 HCD_WAKEUP_PENDING(hcd->shared_hcd))) {
                        if (hcd->driver->pci_resume)
-                               hcd->driver->pci_resume(hcd, false);
+                               hcd->driver->pci_resume(hcd, msg);
                        retval = -EBUSY;
                }
                if (retval)
@@ -470,7 +473,7 @@ static int suspend_common(struct device *dev, bool do_wakeup)
        return retval;
 }
 
-static int resume_common(struct device *dev, int event)
+static int resume_common(struct device *dev, pm_message_t msg)
 {
        struct pci_dev          *pci_dev = to_pci_dev(dev);
        struct usb_hcd          *hcd = pci_get_drvdata(pci_dev);
@@ -498,12 +501,11 @@ static int resume_common(struct device *dev, int event)
                 * No locking is needed because PCI controller drivers do not
                 * get unbound during system resume.
                 */
-               if (pci_dev->class == CL_EHCI && event != PM_EVENT_AUTO_RESUME)
+               if (pci_dev->class == CL_EHCI && msg.event != PM_EVENT_AUTO_RESUME)
                        for_each_companion(pci_dev, hcd,
                                        ehci_wait_for_companions);
 
-               retval = hcd->driver->pci_resume(hcd,
-                               event == PM_EVENT_RESTORE);
+               retval = hcd->driver->pci_resume(hcd, msg);
                if (retval) {
                        dev_err(dev, "PCI post-resume error %d!\n", retval);
                        usb_hc_died(hcd);
@@ -516,7 +518,7 @@ static int resume_common(struct device *dev, int event)
 
 static int hcd_pci_suspend(struct device *dev)
 {
-       return suspend_common(dev, device_may_wakeup(dev));
+       return suspend_common(dev, PMSG_SUSPEND);
 }
 
 static int hcd_pci_suspend_noirq(struct device *dev)
@@ -577,12 +579,12 @@ static int hcd_pci_resume_noirq(struct device *dev)
 
 static int hcd_pci_resume(struct device *dev)
 {
-       return resume_common(dev, PM_EVENT_RESUME);
+       return resume_common(dev, PMSG_RESUME);
 }
 
 static int hcd_pci_restore(struct device *dev)
 {
-       return resume_common(dev, PM_EVENT_RESTORE);
+       return resume_common(dev, PMSG_RESTORE);
 }
 
 #else
@@ -600,7 +602,7 @@ static int hcd_pci_runtime_suspend(struct device *dev)
 {
        int     retval;
 
-       retval = suspend_common(dev, true);
+       retval = suspend_common(dev, PMSG_AUTO_SUSPEND);
        if (retval == 0)
                powermac_set_asic(to_pci_dev(dev), 0);
        dev_dbg(dev, "hcd_pci_runtime_suspend: %d\n", retval);
@@ -612,7 +614,7 @@ static int hcd_pci_runtime_resume(struct device *dev)
        int     retval;
 
        powermac_set_asic(to_pci_dev(dev), 1);
-       retval = resume_common(dev, PM_EVENT_AUTO_RESUME);
+       retval = resume_common(dev, PMSG_AUTO_RESUME);
        dev_dbg(dev, "hcd_pci_runtime_resume: %d\n", retval);
        return retval;
 }
index 4b148fe..889dc44 100644 (file)
@@ -354,10 +354,11 @@ done:
  * Also they depend on separate root hub suspend/resume.
  */
 
-static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
+static int ehci_pci_resume(struct usb_hcd *hcd, pm_message_t msg)
 {
        struct ehci_hcd         *ehci = hcd_to_ehci(hcd);
        struct pci_dev          *pdev = to_pci_dev(hcd->self.controller);
+       bool                    hibernated = (msg.event == PM_EVENT_RESTORE);
 
        if (ehci_resume(hcd, hibernated) != 0)
                (void) ehci_pci_reinit(ehci, pdev);
index d7b4f40..900ea0d 100644 (file)
@@ -301,6 +301,12 @@ static struct pci_driver ohci_pci_driver = {
 #endif
 };
 
+#ifdef CONFIG_PM
+static int ohci_pci_resume(struct usb_hcd *hcd, pm_message_t msg)
+{
+       return ohci_resume(hcd, msg.event == PM_EVENT_RESTORE);
+}
+#endif
 static int __init ohci_pci_init(void)
 {
        if (usb_disabled())
@@ -311,7 +317,7 @@ static int __init ohci_pci_init(void)
 #ifdef CONFIG_PM
        /* Entries for the PCI suspend/resume callbacks are special */
        ohci_pci_hc_driver.pci_suspend = ohci_suspend;
-       ohci_pci_hc_driver.pci_resume = ohci_resume;
+       ohci_pci_hc_driver.pci_resume = ohci_pci_resume;
 #endif
 
        return pci_register_driver(&ohci_pci_driver);
index 3592f75..5df4a18 100644 (file)
@@ -167,7 +167,7 @@ static void uhci_shutdown(struct pci_dev *pdev)
 
 #ifdef CONFIG_PM
 
-static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated);
+static int uhci_pci_resume(struct usb_hcd *hcd, pm_message_t state);
 
 static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
 {
@@ -202,14 +202,15 @@ done_okay:
 
        /* Check for race with a wakeup request */
        if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
-               uhci_pci_resume(hcd, false);
+               uhci_pci_resume(hcd, PMSG_SUSPEND);
                rc = -EBUSY;
        }
        return rc;
 }
 
-static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
+static int uhci_pci_resume(struct usb_hcd *hcd, pm_message_t msg)
 {
+       bool hibernated = (msg.event == PM_EVENT_RESTORE);
        struct uhci_hcd *uhci = hcd_to_uhci(hcd);
 
        dev_dbg(uhci_dev(uhci), "%s\n", __func__);
index 0836985..91ce978 100644 (file)
@@ -367,7 +367,7 @@ static int __maybe_unused xhci_histb_resume(struct device *dev)
        if (!device_may_wakeup(dev))
                xhci_histb_host_enable(histb);
 
-       return xhci_resume(xhci, 0);
+       return xhci_resume(xhci, PMSG_RESUME);
 }
 
 static const struct dev_pm_ops xhci_histb_pm_ops = {
index ddb79f2..e834c77 100644 (file)
@@ -824,7 +824,7 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
        return ret;
 }
 
-static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
+static int xhci_pci_resume(struct usb_hcd *hcd, pm_message_t msg)
 {
        struct xhci_hcd         *xhci = hcd_to_xhci(hcd);
        struct pci_dev          *pdev = to_pci_dev(hcd->self.controller);
@@ -859,7 +859,7 @@ static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
        if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
                xhci_pme_quirk(hcd);
 
-       retval = xhci_resume(xhci, hibernated);
+       retval = xhci_resume(xhci, msg);
        return retval;
 }
 
index b0c8e8e..f36633f 100644 (file)
@@ -478,7 +478,7 @@ static int __maybe_unused xhci_plat_resume(struct device *dev)
        if (ret)
                return ret;
 
-       ret = xhci_resume(xhci, 0);
+       ret = xhci_resume(xhci, PMSG_RESUME);
        if (ret)
                return ret;
 
@@ -507,7 +507,7 @@ static int __maybe_unused xhci_plat_runtime_resume(struct device *dev)
        struct usb_hcd  *hcd = dev_get_drvdata(dev);
        struct xhci_hcd *xhci = hcd_to_xhci(hcd);
 
-       return xhci_resume(xhci, 0);
+       return xhci_resume(xhci, PMSG_AUTO_RESUME);
 }
 
 const struct dev_pm_ops xhci_plat_pm_ops = {
index c75d932..8a9c7de 100644 (file)
@@ -2272,7 +2272,7 @@ static int tegra_xusb_exit_elpg(struct tegra_xusb *tegra, bool runtime)
        if (wakeup)
                tegra_xhci_disable_phy_sleepwalk(tegra);
 
-       err = xhci_resume(xhci, 0);
+       err = xhci_resume(xhci, runtime ? PMSG_AUTO_RESUME : PMSG_RESUME);
        if (err < 0) {
                dev_err(tegra->dev, "failed to resume XHCI: %d\n", err);
                goto disable_phy;
index 78790dc..65d54c8 100644 (file)
@@ -960,8 +960,9 @@ EXPORT_SYMBOL_GPL(xhci_suspend);
  * This is called when the machine transition from S3/S4 mode.
  *
  */
-int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
+int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg)
 {
+       bool                    hibernated = (msg.event == PM_EVENT_RESTORE);
        u32                     command, temp = 0;
        struct usb_hcd          *hcd = xhci_to_hcd(xhci);
        int                     retval = 0;
index 08d7219..047b290 100644 (file)
@@ -2140,7 +2140,7 @@ int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id);
 int xhci_ext_cap_init(struct xhci_hcd *xhci);
 
 int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup);
-int xhci_resume(struct xhci_hcd *xhci, bool hibernated);
+int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg);
 
 irqreturn_t xhci_irq(struct usb_hcd *hcd);
 irqreturn_t xhci_msi_irq(int irq, void *hcd);
index 094c77e..30ab899 100644 (file)
@@ -267,7 +267,7 @@ struct hc_driver {
        int     (*pci_suspend)(struct usb_hcd *hcd, bool do_wakeup);
 
        /* called after entering D0 (etc), before resuming the hub */
-       int     (*pci_resume)(struct usb_hcd *hcd, bool hibernated);
+       int     (*pci_resume)(struct usb_hcd *hcd, pm_message_t state);
 
        /* called just before hibernate final D3 state, allows host to poweroff parts */
        int     (*pci_poweroff_late)(struct usb_hcd *hcd, bool do_wakeup);