Received: by 10.192.165.156 with SMTP id m28csp899456imm; Thu, 19 Apr 2018 09:19:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/NFuc/BZxq/YgVUq9Gc/BYU6lSqpzn9XhjpsIZ+7qiVvQfBc23oa2uEim/2w0ZOw694v5o X-Received: by 2002:a17:902:bd8e:: with SMTP id q14-v6mr6878678pls.322.1524154794939; Thu, 19 Apr 2018 09:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524154794; cv=none; d=google.com; s=arc-20160816; b=S9JUJnpx9zr+d1/zu3fIJQyTPdpsQ4vVjcuwn5Y/rBdGCF2B7vqTmpqpLZ8Rf4HTON FcBqT3nqj4LPoKZQkWbx6+aPKQMOXh+F4xihGQlHoF+c6QSOCOFRTFlHbaAqy32qEwHA sz2OJQz/HdPBCBFXNmklEtDJ5D0rOwvl86wvP/nKb0M3eqHyBuHp19rEaic1YAPy8RC2 Tjh4hONIEFkelpUIuPpODuKgVO8lQgliLnAus0dO2t1skQG7AtLU8u1Vmy7pBG3sExJ/ sxuzd0/5KPF7vq9PQu6Boz/xM766OrQRPAIsYnb2/ila8hc/hcYZsGz0bc8WqIGzshv5 71UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=rQLkGJyJe6cZv7UuHSqKAXYuHZUAisY0INMyW51bBQU=; b=PBUk53iI2g7av9nrLVQN1Ku9ceE3km0GcEUicmZMJXbEEzDkfr/kppZ7PonMV5hCzb 3cLTiPnyK+fo5CSrO/xc+0EshRr52XPMVPmWMNG6tJIU+ZoJbj2mxiJYM/cyuLg3/J12 GtQa+B0f6J/Ha1Hwljdfu2jEd8FFNvTZoTdFkGCPFrk9smUhC4fvr0J3FPLXRPzrtbLd 3j1elIUk8QyT7Io8GYy1w7bjSskYVZ9zHoPXBMPFEU3EDWPhlpEda1xtzYsvnnB/vRlu ILDV1iaeAJ2IYCBWTBGzVHD/cmK5ty41/6uagHnFMlEcL1hqGFjKk3IqJCbzCsonOd3d s9SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TLePZXnR; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9si3179550pge.641.2018.04.19.09.19.39; Thu, 19 Apr 2018 09:19:54 -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=@google.com header.s=20161025 header.b=TLePZXnR; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753774AbeDSQSY (ORCPT + 99 others); Thu, 19 Apr 2018 12:18:24 -0400 Received: from mail-ot0-f196.google.com ([74.125.82.196]:36131 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753555AbeDSQSW (ORCPT ); Thu, 19 Apr 2018 12:18:22 -0400 Received: by mail-ot0-f196.google.com with SMTP id p2-v6so6463402otf.3 for ; Thu, 19 Apr 2018 09:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=rQLkGJyJe6cZv7UuHSqKAXYuHZUAisY0INMyW51bBQU=; b=TLePZXnRKs2us94F4swf5FsSTG6dsgVT7Re/UVii+JjORsxGb1lSU2Dbrc1U8cbY5B FV7DTz2TkraLX5Y4uwQI5Krd86jJ0te1gmkyKfztf4rA7/NKixk2u72AK4CJ4LD3Opq+ v3eAiawip6Ie4nAngqNTqLg88a0G5vLW9KkTZ+mkJ7b8j0y4n7aRPVhjHouLhRl8VAZh cb3nga+Cjg+qH5g741uSj8T55kOJisJJPUEC2glYSvH+KYYi8cD/0hsMIvxJra/qWL+l UB9t+NpUBMYqHI5u8HN2oA5rI3wx2DPeGekm8msLdFYEZyAfN/8tdAjP1//hYZoaKW7E BatQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=rQLkGJyJe6cZv7UuHSqKAXYuHZUAisY0INMyW51bBQU=; b=XaDTRyH3LWKGRJPXFTMLH0uRo07HTjeml7tiRBSM6opCjInsbefLNsWtZBPjmAQ0Jj TjwKkLeUstig4ZfRPOjOUA7nwqEbTGdpKnAdHxUYnuLQ3nhfdrouUeSOqa7jysvs9fuy WM7LvHEjHHEQb9p4epi+vtzEDhmR9jST//h9W/Xdi7PcWDhDvk19VVVYmIqxDPQvBaOB mFNMMCrAzw3JoWO5QnkZYFiNzE40j9ppxT/QJin7lXyN4SCI/f26+Ot608VE0gRBBX6L cVZi1ksMvxFKG0Q2yHPPP4LO1UDcejy7rzOmpp9TqLtarh17ci6v3Hp0tVUXYZ82jCiY c+jA== X-Gm-Message-State: ALQs6tC1eeCD+ONa+z+s2CJgtmNGO06mskeA1hgSWiF6ZqCGl5Iz5hmc V0ZdJpmLJGMvwisWkQNYMUHd9VWeArgpp0LhNfDBLw== X-Received: by 2002:a9d:1eea:: with SMTP id n97-v6mr4193089otn.73.1524154701310; Thu, 19 Apr 2018 09:18:21 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.11.71 with HTTP; Thu, 19 Apr 2018 09:17:40 -0700 (PDT) In-Reply-To: References: <20180419001850.133110-1-ravisadineni@chromium.org> From: Rajat Jain Date: Thu, 19 Apr 2018 09:17:40 -0700 Message-ID: Subject: Re: [PATCH] USB: Increment wakeup count on remote wakeup. To: Alan Stern Cc: Ravi Chandra Sadineni , Greg Kroah-Hartman , martin.blumenstingl@googlemail.com, Ravi Chandra Sadineni , chunfeng.yun@mediatek.com, johan@kernel.org, arvind.yadav.cs@gmail.com, Dmitry Torokhov , anton.bondarenko.sama@gmail.com, f.fainelli@gmail.com, keescook@chromium.org, mathias.nyman@linux.intel.com, felipe.balbi@linux.intel.com, ekorenevsky@gmail.com, peter.chen@nxp.com, joe@perches.com, Todd Broch , linux-usb@vger.kernel.org, Linux Kernel Mailing List , Benson Leung Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 19, 2018 at 8:01 AM, Alan Stern wrote: > On Wed, 18 Apr 2018, Ravi Chandra Sadineni wrote: > >> On chromebooks we depend on wakeup count to identify the wakeup source. >> But currently USB devices do not increment the wakeup count when they >> trigger the remote wake. This patch addresses the same. >> >> Resume condition is reported differently on USB 2.0 and USB 3.0 devices. >> >> On USB 2.0 devices, a wake capable device, if wake enabled, drives >> resume signal to indicate a remote wake (USB 2.0 spec section 7.1.7.7). >> The upstream facing port then sets C_PORT_SUSPEND bit and reports a >> port change event (USB 2.0 spec section 11.24.2.7.2.3). Thus if a port >> has resumed before driving the resume signal from the host and >> C_PORT_SUSPEND is set, then the device attached to the given port might >> be the reason for the last system wakeup. Increment the wakeup count for >> the same. >> >> On USB 3.0 devices, a function may signal that it wants to exit from device >> suspend by sending a Function Wake Device Notification to the host (USB3.0 >> spec section 8.5.6.4) Thus on receiving the Function Wake, increment the >> wakeup count. >> >> Signed-off-by: ravisadineni@chromium.org >> --- >> drivers/usb/core/hcd.c | 1 + >> drivers/usb/core/hub.c | 12 ++++++++++-- >> 2 files changed, 11 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c >> index 777036ae63674..79f95a878fb6e 100644 >> --- a/drivers/usb/core/hcd.c >> +++ b/drivers/usb/core/hcd.c >> @@ -2375,6 +2375,7 @@ void usb_hcd_resume_root_hub (struct usb_hcd *hcd) >> { >> unsigned long flags; >> >> + pm_wakeup_event(dev, 0); > > Instead of dev, you probably want to use hcd->self.sysdev. Or maybe > hcd->self.controller, although the difference probably doesn't matter > for your purposes. > > On the other hand, this wakeup event may already have been counted by > the host controller's bus subsystem. Does it matter if the same wakeup > event gets counted twice? No. The context is that we're interested in making user space behave differently if the wake up source was a user input device (e.g. USB keyboard) v/s some other kind of USB device. So all that matters is that the USB device wakeup count gets incremented. > > (This is inevitable with USB devices, in any case. If a device sends a > wakeup request, it will be counted for that device, for all the > intermediate hubs, and for the host controller.) > >> @@ -3432,10 +3437,13 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) >> >> usb_lock_port(port_dev); >> >> - /* Skip the initial Clear-Suspend step for a remote wakeup */ >> status = hub_port_status(hub, port1, &portstatus, &portchange); >> - if (status == 0 && !port_is_suspended(hub, portstatus)) >> + /* Skip the initial Clear-Suspend step for a remote wakeup */ > > What is the reason for moving the comment line down after the > hub_port_status() call? > > Alan Stern > >> + if (status == 0 && !port_is_suspended(hub, portstatus)) { >> + if (portchange & USB_PORT_STAT_C_SUSPEND) >> + pm_wakeup_event(&udev->dev, 0); >> goto SuspendCleared; >> + } >> >> /* see 7.1.7.7; affects power usage, but not budgeting */ >> if (hub_is_superspeed(hub->hdev)) >> >