@@ -1413,19 +1413,32 @@ static int usb_resume_interface(struct usb_device *udev,
*/
static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
{
- int status = 0;
- int i = 0, n = 0;
- struct usb_interface *intf;
+ int status = 0;
+ int i = 0, n = 0;
+ bool offload = false;
+ struct usb_interface *intf;
+ struct usb_host_endpoint *ep;
if (udev->state == USB_STATE_NOTATTACHED ||
udev->state == USB_STATE_SUSPENDED)
goto done;
+#ifdef CONFIG_USB_XHCI_SIDEBAND
+ if (msg.event == PM_EVENT_SUSPEND && usb_offload_check(udev)) {
+ dev_dbg(&udev->dev, "device offload active.\n");
+ offload = true;
+ }
+#endif
+
/* Suspend all the interfaces and then udev itself */
if (udev->actconfig) {
n = udev->actconfig->desc.bNumInterfaces;
for (i = n - 1; i >= 0; --i) {
intf = udev->actconfig->interface[i];
+ if (offload && intf->needs_remote_wakeup) {
+ dev_dbg(&intf->dev, "interface stays active on an offloaded device\n");
+ continue;
+ }
status = usb_suspend_interface(udev, intf, msg);
/* Ignore errors during system sleep transitions */
@@ -1436,7 +1449,8 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
}
}
if (status == 0) {
- status = usb_suspend_device(udev, msg);
+ if (!offload)
+ status = usb_suspend_device(udev, msg);
/*
* Ignore errors from non-root-hub devices during
@@ -1482,8 +1496,19 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
} else {
udev->can_submit = 0;
for (i = 0; i < 16; ++i) {
- usb_hcd_flush_endpoint(udev, udev->ep_out[i]);
- usb_hcd_flush_endpoint(udev, udev->ep_in[i]);
+ if (udev->ep_out[i]) {
+ ep = udev->ep_out[i];
+ intf = to_usb_interface(ep->ep_dev->dev.parent);
+ if (!(offload && intf->needs_remote_wakeup))
+ usb_hcd_flush_endpoint(udev, ep);
+ }
+
+ if (udev->ep_in[i]) {
+ ep = udev->ep_in[i];
+ intf = to_usb_interface(ep->ep_dev->dev.parent);
+ if (!(offload && intf->needs_remote_wakeup))
+ usb_hcd_flush_endpoint(udev, ep);
+ }
}
}
@@ -18,14 +18,6 @@
#include <linux/usb.h>
#include "usb.h"
-struct ep_device {
- struct usb_endpoint_descriptor *desc;
- struct usb_device *udev;
- struct device dev;
-};
-#define to_ep_device(_dev) \
- container_of(_dev, struct ep_device, dev)
-
struct ep_attribute {
struct attribute attr;
ssize_t (*show)(struct usb_device *,
@@ -2602,8 +2602,22 @@ static int dwc3_runtime_idle(struct device *dev)
static int dwc3_suspend(struct device *dev)
{
struct dwc3 *dwc = dev_get_drvdata(dev);
+#ifdef CONFIG_USB_XHCI_SIDEBAND
+ struct platform_device *xhci = dwc->xhci;
+ struct usb_hcd *hcd;
+#endif
int ret;
+#ifdef CONFIG_USB_XHCI_SIDEBAND
+ if (xhci) {
+ hcd = dev_get_drvdata(&xhci->dev);
+ if (xhci_sideband_check(hcd)) {
+ dev_dbg(dev, "sideband instance active.\n");
+ return 0;
+ }
+ }
+#endif
+
ret = dwc3_suspend_common(dwc, PMSG_SUSPEND);
if (ret)
return ret;
@@ -2616,8 +2630,22 @@ static int dwc3_suspend(struct device *dev)
static int dwc3_resume(struct device *dev)
{
struct dwc3 *dwc = dev_get_drvdata(dev);
+#ifdef CONFIG_USB_XHCI_SIDEBAND
+ struct platform_device *xhci = dwc->xhci;
+ struct usb_hcd *hcd;
+#endif
int ret = 0;
+#ifdef CONFIG_USB_XHCI_SIDEBAND
+ if (xhci) {
+ hcd = dev_get_drvdata(&xhci->dev);
+ if (xhci_sideband_check(hcd)) {
+ dev_dbg(dev, "sideband instance active.\n");
+ return 0;
+ }
+ }
+#endif
+
pinctrl_pm_select_default_state(dev);
pm_runtime_disable(dev);
@@ -26,6 +26,7 @@
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>
#include <linux/usb/otg.h>
+#include <linux/usb/hcd.h>
#include <linux/usb/role.h>
#include <linux/ulpi/interface.h>
@@ -456,6 +456,13 @@ static int xhci_plat_suspend_common(struct device *dev, struct pm_message pmsg)
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
int ret;
+#ifdef CONFIG_USB_XHCI_SIDEBAND
+ if (pmsg.event == PM_EVENT_SUSPEND && xhci_sideband_check(hcd)) {
+ dev_dbg(dev, "sideband instance active.\n");
+ return 0;
+ }
+#endif
+
if (pm_runtime_suspended(dev))
pm_runtime_resume(dev);
@@ -499,6 +506,13 @@ static int xhci_plat_resume_common(struct device *dev, struct pm_message pmsg)
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
int ret;
+#ifdef CONFIG_USB_XHCI_SIDEBAND
+ if (pmsg.event == PM_EVENT_RESUME && xhci_sideband_check(hcd)) {
+ dev_dbg(dev, "sideband instance active.\n");
+ return 0;
+ }
+#endif
+
if (!device_may_wakeup(dev) && (xhci->quirks & XHCI_SUSPEND_RESUME_CLKS)) {
ret = clk_prepare_enable(xhci->clk);
if (ret)
@@ -44,7 +44,13 @@ struct usb_driver;
* Devices may also have class-specific or vendor-specific descriptors.
*/
-struct ep_device;
+struct ep_device {
+ struct usb_endpoint_descriptor *desc;
+ struct usb_device *udev;
+ struct device dev;
+};
+#define to_ep_device(_dev) \
+ container_of(_dev, struct ep_device, dev)
/**
* struct usb_host_endpoint - host-side endpoint descriptor and queue
@@ -766,6 +766,13 @@ extern struct rw_semaphore ehci_cf_port_reset_rwsem;
#define USB_EHCI_LOADED 2
extern unsigned long usb_hcds_loaded;
+#if IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND)
+extern bool xhci_sideband_check(struct usb_hcd *hcd);
+#else
+static inline bool xhci_sideband_check(struct usb_hcd *hcd)
+{ return false; }
+#endif
+
#endif /* __KERNEL__ */
#endif /* __USB_CORE_HCD_H */
@@ -1619,8 +1619,11 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle,
mutex_lock(&chip->mutex);
subs->opened = 0;
mutex_unlock(&chip->mutex);
+ } else {
+ xhci_sideband_get(uadev[pcm_card_num].si);
}
} else {
+ xhci_sideband_put(uadev[pcm_card_num].si);
info = &uadev[pcm_card_num].info[info_idx];
if (info->data_ep_pipe) {
ep = usb_pipe_endpoint(uadev[pcm_card_num].udev,
Sharing a USB controller with another entity via xhci-sideband driver creates power management complexities. To prevent the USB controller from being inadvertently deactivated while in use by the other entity, a usage-count based mechanism is implemented. This allows the system to manage power effectively, ensuring the controller remains available whenever needed. In order to maintain full functionality of an offloaded USB devices, several changes are made within the suspend flow of such devices: - skip usb_suspend_device() so that the port/hub are still active for USB transfers via offloaded path. - not flushing the endpoints which are used by USB interfaces marked with needs_remote_wakeup. Namely, skip usb_suspend_interface() and usb_hcd_flush_endpoint() on associated USB interfaces. This reserves a pending interrupt urb during system suspend for handling the interrupt transfer, which is necessary since remote wakeup doesn't apply in the offloaded USB devices when controller is still active. Signed-off-by: Guan-Yu Lin <guanyulin@google.com> --- drivers/usb/core/driver.c | 37 ++++++++++++++++++++++++++----- drivers/usb/core/endpoint.c | 8 ------- drivers/usb/dwc3/core.c | 28 +++++++++++++++++++++++ drivers/usb/dwc3/core.h | 1 + drivers/usb/host/xhci-plat.c | 14 ++++++++++++ include/linux/usb.h | 8 ++++++- include/linux/usb/hcd.h | 7 ++++++ sound/usb/qcom/qc_audio_offload.c | 3 +++ 8 files changed, 91 insertions(+), 15 deletions(-)