Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp4838713imd; Tue, 30 Oct 2018 08:09:25 -0700 (PDT) X-Google-Smtp-Source: AJdET5dme3TJJykHnC1NhvxlaB2KqDFMc9jJU0GK6hENhuNSS5LJkIL9Asrgnzf+JYnLRGLp/kni X-Received: by 2002:a65:50c3:: with SMTP id s3-v6mr17997613pgp.355.1540912165183; Tue, 30 Oct 2018 08:09:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540912165; cv=none; d=google.com; s=arc-20160816; b=DpX/yHoGu0nyjg4ui72MZjop+gdRwOou1UDpr5L1DNElwlV8AmK1tpLEIpj2iCegFn GNHuEDR6VfNKUQqYABDcW9PGOGK4KNF5PMbzUIbiHDyE8YkYpErxuh57oalZjDV51bIK TQwmRvaHgF7bRIHxS9r4k1MH8w3tXACK5tz4/QQz80Dl0adrl4DWNSWDjGjtkQ7XzWkp EMkO1jbEaAR7WqDyVHIq8rTCY4zxxSn0Z+vfyH+eu1tcL/cMiLsRoG4fMEXrE+06Q5hN Mjn/sFUMKNzUVNCSxzMzkUzgTmhxkvpWCc2Lgf426zr5EZF4+u9p2rXHUmu0nWLMTuzc Nuaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=WcUSzyPF0/tRXpnLHspD8Dakk0gFyW6Rlw/BISOOyuY=; b=DvCObBHUJKeZAz2Y2X1nzPFJKWI6FZmPjcmBm/Iq/baJJtccQF661eTNz5qvsa+4pY kTU/2/Fr8m2vGNPEo1gl7ZJl2yErQZ6REH+tVApYxPONuDk/cRUPcnCqcitOctqvzMJO rjXZxMlqG8lwXtRJsb0r8JeRRIEBp9245zMjmpPre7TJr3nKrSf7OW6N1aOL5gKkdXtS 8Y+5tfHfffKgHDxszQG70vFw6td2X51dJrLm33ssUOu1X5tOWBmb3/UEm/MeUGMHNhpI WuR2b6KthhcR8Fsn2qctZlJBm75yGrotjLaqlQQ3J2CfYLl6hrMS20wjxDUS8LnhCSQk 4qhA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b4-v6si24038501plk.37.2018.10.30.08.09.00; Tue, 30 Oct 2018 08:09:25 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727520AbeJaABo convert rfc822-to-8bit (ORCPT + 99 others); Tue, 30 Oct 2018 20:01:44 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:53775 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726336AbeJaABo (ORCPT ); Tue, 30 Oct 2018 20:01:44 -0400 Received: from mail-pf1-f198.google.com ([209.85.210.198]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1gHVcW-0002Lz-Du for linux-kernel@vger.kernel.org; Tue, 30 Oct 2018 15:07:52 +0000 Received: by mail-pf1-f198.google.com with SMTP id g63-v6so10775621pfc.9 for ; Tue, 30 Oct 2018 08:07:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Ps8ixr9LtwFtMi6SbFiH2t0jlsGg0Zq5b5LNCeySn/M=; b=DjdAh4+GpmDYpIfOnzbkT9xgoEpOjOLCb08bf07Ua5mZoMOslAcsxvYF285B/WBMEV CWSn+a4UDxqAxGVr79zd9EFtms2XaB3oUiNz/eQQyfvb+Te8ddlqTZRyXmaLQTdLtJQa lvJxzTSx0BHhLarVI63oAT0OQf6edcUaIWjUbKEa64pLoABxsx+yuymAr7aLkhyPCqUd mNNYuzgenkQhJrkaNG/9LuKkWZScgr9HTbXfIBpcjAc3Fq/u/IlQeoPerXiRsalXowEx mOyKy7XUpPtAOiyS/gAZCS3XJpYDR7xZAcN96yz1Z03rK9ev4jwKoPJpKq0TnaAykjNY btjg== X-Gm-Message-State: AGRZ1gIPzDrzT8OI47JG+6P9uRi4w7z4i077aS+zKvA7tuBAgEWl0wez 7/35cBsbvqTg06Ms6HmdGUlWQINReeyg6CIA5IacgVlo/bA8IQZ0F4fLhESH2frhI6gPBTfqTnQ Ip7r43N/vuqbKs3PG6qN54+WypiJ1qI1yplx5wj2JZw== X-Received: by 2002:a63:fd09:: with SMTP id d9-v6mr18791549pgh.164.1540912070978; Tue, 30 Oct 2018 08:07:50 -0700 (PDT) X-Received: by 2002:a63:fd09:: with SMTP id d9-v6mr18791501pgh.164.1540912070492; Tue, 30 Oct 2018 08:07:50 -0700 (PDT) Received: from 2001-b011-380f-1f39-25e6-f27b-5378-368e.dynamic-ip6.hinet.net (2001-b011-380f-1f39-25e6-f27b-5378-368e.dynamic-ip6.hinet.net. [2001:b011:380f:1f39:25e6:f27b:5378:368e]) by smtp.gmail.com with ESMTPSA id x23-v6sm25347121pfh.56.2018.10.30.08.07.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Oct 2018 08:07:49 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.0 \(3445.100.39\)) Subject: Re: [PATCH] USB: Don't enable LPM if it's already enabled From: Kai Heng Feng In-Reply-To: Date: Tue, 30 Oct 2018 23:07:47 +0800 Cc: Mathias Nyman , gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8BIT Message-Id: References: To: Alan Stern X-Mailer: Apple Mail (2.3445.100.39) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Oct 30, 2018, at 23:00, Alan Stern wrote: > > On Tue, 30 Oct 2018, Mathias Nyman wrote: > >> On 30.10.2018 07:54, Kai-Heng Feng wrote: >>> 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(). >>> >>> So let's enable LPM for just once, as this solves the issue for the >>> device in question. >>> >>> Signed-off-by: Kai-Heng Feng >>> --- >>> drivers/usb/core/driver.c | 3 ++- >>> 1 file changed, 2 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c >>> index 53564386ed57..e11d2eac76b6 100644 >>> --- a/drivers/usb/core/driver.c >>> +++ b/drivers/usb/core/driver.c >>> @@ -1901,7 +1901,8 @@ int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable) >>> struct usb_hcd *hcd = bus_to_hcd(udev->bus); >>> int ret = -EPERM; >>> >>> - if (enable && !udev->usb2_hw_lpm_allowed) >>> + if (enable && !udev->usb2_hw_lpm_allowed || >>> + udev->usb2_hw_lpm_enabled == enable) >>> return 0; >>> >>> if (hcd->driver->set_usb2_hw_lpm) { >>> >> >> Something like that would probably work. >> >> Would it make sense to skip USB2 hw LPM enabling in usb_port_resume() if >> port was just reset (and thus LPM enabled)? >> >> something like this: >> >> --- a/drivers/usb/core/hub.c >> +++ b/drivers/usb/core/hub.c >> @@ -3520,7 +3520,7 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) >> hub_port_logical_disconnect(hub, port1); >> } else { >> /* Try to enable USB2 hardware LPM */ >> - if (udev->usb2_hw_lpm_capable == 1) >> + if (udev->usb2_hw_lpm_capable == 1 && !udev->reset_resume) >> usb_set_usb2_hardware_lpm(udev, 1); >> >> /* Try to enable USB3 LTM */ > > Why not simply test whether udev->usb2_hw_lpm_enabled is already true? > > if (udev->usb2_hw_lpm_capable == 1 && > !udev->usb2_hw_lpm_enabled) > > Or even put this extra test into usb_set_usb2_hardware_lpm(). I think it makes sense to merge all checks into usb_set_usb2_hardware_lpm(). I’ll resend one with this suggestion. Kai-Heng > > Alan Stern