Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4810248yba; Tue, 30 Apr 2019 04:53:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxBMCdQkmV6K8BtMMzzYWjtyaDjF0vUad0m2oH0yd4EeKYr9CJZo84UuMbG7bCgFLwUWDaI X-Received: by 2002:a63:dc50:: with SMTP id f16mr66102725pgj.396.1556625216655; Tue, 30 Apr 2019 04:53:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556625216; cv=none; d=google.com; s=arc-20160816; b=zmqDcj9dCz/TJvb/jLmXyYALXc3TFCCdLxkNaV+ugFDIqPEJ9FoJVTDiOOPaTTIR6U zzCc3VAsWJxr9uaCEFBfXU7dgVhQiYlDf35lqSlL90DVyKsGOClePty5fNGdgZ/uRb2u 9HbnqZ4qykwpwpL8RVYJd9KbgfZmJRu3lytZQLsgLAu7czqrW4NyTHlA+oq6pE27iNpf HOFZz98MNhX4IOtEqeysHdlkPxd+ytLoHkyH4MC2WE+seAmcryum/HvgHtlZiTTLxvtg PB2NV2+gp/4D04iv2C0xEBxOYcfGHd4zZRa9pFeHbBgmHH6eFmHJrbdl6gvlk7vyak1e Y/gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=g+exDqSaVTKf//1Tuut6sx+woIt47m566HhZ2RamuZA=; b=lf7UgJoXyd9sz5uxcpKtGHowT+Mw/kvRTe1ZhNf/uM0rESXYEaRZ4MCIxKHlpQeBNu d/04jdHX1CMKFFLVBdXa1+ypspvPN5wsDUjZ6Ry9NDQGdmvLxppavYhB2c2k8ZfXJlnG WdZDZVGdfdxEmZ8Do1JBKCCHwO4G+aNt9P4KChY6V2ajnlfMIWRTn2cYhx6/0Bjfa84T if9kVCeqhi0y9Iv/nSZ2l1xmB5cSmgHSBOu0EBnUgZuMHV+6pOe4XBIwSayznbOAqPOk CCRzffLcahh5VyU3T7tpgRPFpc+hfud/RF54zzj8DCFZGQC0M5NNroz5/sULPr8PQa7Z fzlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=La2yAyHA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r10si34058593pgp.30.2019.04.30.04.53.20; Tue, 30 Apr 2019 04:53:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=La2yAyHA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731459AbfD3Lvv (ORCPT + 99 others); Tue, 30 Apr 2019 07:51:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:39826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731448AbfD3Lvq (ORCPT ); Tue, 30 Apr 2019 07:51:46 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6419A21734; Tue, 30 Apr 2019 11:51:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556625105; bh=dRQmxGDorS+lESNzYyd3cJes+FHFTl2Vg09VzHfUl/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=La2yAyHA0NhoOYWvPHZA+/B1ZrF370G2x98JGbCwvoEbyZ1ZROR6PE2w/LUsbhiH9 6W957e9tQQPLhTLHRs0NaoG6MzJY6m/lgHE4E5ABWuEsKRO/6Pr7fpAeQrXbdgGZ9L 4zhITzN0N8qs6rY7LInFeUrjYL3XyA2YUaZObeu4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kai-Heng Feng Subject: [PATCH 5.0 47/89] USB: Consolidate LPM checks to avoid enabling LPM twice Date: Tue, 30 Apr 2019 13:38:38 +0200 Message-Id: <20190430113611.928229143@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430113609.741196396@linuxfoundation.org> References: <20190430113609.741196396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kai-Heng Feng commit d7a6c0ce8d26412903c7981503bad9e1cc7c45d2 upstream. USB Bluetooth controller QCA ROME (0cf3:e007) sometimes stops working after S3: [ 165.110742] Bluetooth: hci0: using NVM file: qca/nvm_usb_00000302.bin [ 168.432065] Bluetooth: hci0: Failed to send body at 4 of 1953 (-110) After some experiments, I found that disabling LPM can workaround the issue. On some platforms, the USB power is cut during S3, so the driver uses reset-resume to resume the device. During port resume, LPM gets enabled twice, by usb_reset_and_verify_device() and usb_port_resume(). Consolidate all checks into new LPM helpers to make sure LPM only gets enabled once. Fixes: de68bab4fa96 ("usb: Don't enable USB 2.0 Link PM by default.”) Signed-off-by: Kai-Heng Feng Cc: stable # after much soaking Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/driver.c | 11 ++++++++--- drivers/usb/core/hub.c | 12 ++++-------- drivers/usb/core/message.c | 3 +-- 3 files changed, 13 insertions(+), 13 deletions(-) --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1901,9 +1901,6 @@ static int usb_set_usb2_hardware_lpm(str struct usb_hcd *hcd = bus_to_hcd(udev->bus); int ret = -EPERM; - if (enable && !udev->usb2_hw_lpm_allowed) - return 0; - if (hcd->driver->set_usb2_hw_lpm) { ret = hcd->driver->set_usb2_hw_lpm(hcd, udev, enable); if (!ret) @@ -1915,11 +1912,19 @@ static int usb_set_usb2_hardware_lpm(str int usb_enable_usb2_hardware_lpm(struct usb_device *udev) { + if (!udev->usb2_hw_lpm_capable || + !udev->usb2_hw_lpm_allowed || + udev->usb2_hw_lpm_enabled) + return 0; + return usb_set_usb2_hardware_lpm(udev, 1); } int usb_disable_usb2_hardware_lpm(struct usb_device *udev) { + if (!udev->usb2_hw_lpm_enabled) + return 0; + return usb_set_usb2_hardware_lpm(udev, 0); } --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -3220,8 +3220,7 @@ int usb_port_suspend(struct usb_device * } /* disable USB2 hardware LPM */ - if (udev->usb2_hw_lpm_enabled == 1) - usb_disable_usb2_hardware_lpm(udev); + usb_disable_usb2_hardware_lpm(udev); if (usb_disable_ltm(udev)) { dev_err(&udev->dev, "Failed to disable LTM before suspend\n"); @@ -3259,8 +3258,7 @@ int usb_port_suspend(struct usb_device * usb_enable_ltm(udev); err_ltm: /* Try to enable USB2 hardware LPM again */ - if (udev->usb2_hw_lpm_capable == 1) - usb_enable_usb2_hardware_lpm(udev); + usb_enable_usb2_hardware_lpm(udev); if (udev->do_remote_wakeup) (void) usb_disable_remote_wakeup(udev); @@ -3543,8 +3541,7 @@ int usb_port_resume(struct usb_device *u hub_port_logical_disconnect(hub, port1); } else { /* Try to enable USB2 hardware LPM */ - if (udev->usb2_hw_lpm_capable == 1) - usb_enable_usb2_hardware_lpm(udev); + usb_enable_usb2_hardware_lpm(udev); /* Try to enable USB3 LTM */ usb_enable_ltm(udev); @@ -5649,8 +5646,7 @@ static int usb_reset_and_verify_device(s /* Disable USB2 hardware LPM. * It will be re-enabled by the enumeration process. */ - if (udev->usb2_hw_lpm_enabled == 1) - usb_disable_usb2_hardware_lpm(udev); + usb_disable_usb2_hardware_lpm(udev); /* Disable LPM while we reset the device and reinstall the alt settings. * Device-initiated LPM, and system exit latency settings are cleared --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c @@ -1243,8 +1243,7 @@ void usb_disable_device(struct usb_devic dev->actconfig->interface[i] = NULL; } - if (dev->usb2_hw_lpm_enabled == 1) - usb_disable_usb2_hardware_lpm(dev); + usb_disable_usb2_hardware_lpm(dev); usb_unlocked_disable_lpm(dev); usb_disable_ltm(dev);