Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE054C433FE for ; Fri, 10 Dec 2021 09:28:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236458AbhLJJbn (ORCPT ); Fri, 10 Dec 2021 04:31:43 -0500 Received: from mail.loongson.cn ([114.242.206.163]:40784 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232385AbhLJJbl (ORCPT ); Fri, 10 Dec 2021 04:31:41 -0500 Received: from [10.180.13.84] (unknown [10.180.13.84]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxqsiDHbNhktAFAA--.12340S2; Fri, 10 Dec 2021 17:27:40 +0800 (CST) Subject: Re: [PATCH v1 2/2] usb: core: enable remote wakeup function for usb controller To: Alan Stern Cc: Jiri Kosina , benjamin.tissoires@redhat.com, gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com, mathias.nyman@linux.intel.com, rajatja@google.com, chris.chiu@canonical.com, linux-usb@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, zhuyinbo@loongson.cn, Greg Kroah-Hartman , Thinh Nguyen , Mathias Nyman , Rajat Jain , Chris Chiu , linux-usb@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org References: <1638956391-20149-1-git-send-email-zhuyinbo@loongson.cn> <1638956391-20149-2-git-send-email-zhuyinbo@loongson.cn> From: zhuyinbo Message-ID: Date: Fri, 10 Dec 2021 17:27:30 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=gbk; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf9AxqsiDHbNhkt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daVFxhVjvjDU0xZFpf9x0JUQvtAUUUUU= X-CM-SenderInfo: 52kx5xhqerqz5rrqw2lrqou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ?? 2021/12/9 ????6:04, Alan Stern ะด??: > On Wed, Dec 08, 2021 at 05:39:51PM +0800, Yinbo Zhu wrote: >> The remote wake up function is a regular function on usb device and >> I think keeping it enabled by default will make the usb application >> more convenient and usb device remote wake up function keep enabled >> that ask usb controller remote wake up was enabled at first. >> >> This patch only enable wake up on usb root hub device, among which, > > You say the patch only affects root hub devices, but this doesn't appear > to be true. > >> usb3.0 root hub doesn't be set wakeup node property but use command >> USB_INTRF_FUNC_SUSPEND to enable remote wake up function. >> >> Signed-off-by: Yinbo Zhu >> --- >> drivers/usb/core/hub.c | 20 ++++++++++++++++++-- >> include/linux/usb.h | 4 +++- >> 2 files changed, 21 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c >> index 86658a8..cb4b956 100644 >> --- a/drivers/usb/core/hub.c >> +++ b/drivers/usb/core/hub.c >> @@ -2509,6 +2509,8 @@ static void set_usb_port_removable(struct usb_device *udev) >> */ >> int usb_new_device(struct usb_device *udev) >> { >> + struct usb_host_config *config; >> + int ncfg; >> int err; >> >> if (udev->parent) { >> @@ -2540,6 +2542,18 @@ int usb_new_device(struct usb_device *udev) >> udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, >> (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); >> >> + for (ncfg = 0; ncfg < udev->descriptor.bNumConfigurations; ncfg++) { >> + config = &udev->config[ncfg]; >> + if ((config->desc.bmAttributes & (1 << 5)) == 0) >> + break; >> + if (ncfg + 1 == udev->descriptor.bNumConfigurations) { >> + err = usb_enable_remote_wakeup(udev); >> + if (err) >> + dev_dbg(&udev->dev, >> + "won't remote wakeup, err %d\n", err); >> + } >> + } > > I don't see anything in there which treats root hubs differently from > other devices. > Hi Alan Stern, You can find following code, non-root-hub had removed Wakeup sysfs attributes and disabled wakeup and root-hub had added wakeup sysfs attibutes before call usb_new_device, so this patch was only enabled remote wakeup for root-hub device. int usb_new_device(struct usb_device *udev) { if (udev->parent) { /* Initialize non-root-hub device wakeup to disabled; * device (un)configuration controls wakeup capable * sysfs power/wakeup controls wakeup enabled/disabled */ device_init_wakeup(&udev->dev, 0); } > Besides, enabling wakeup for root hubs is generally a bad idea. Suppose > you closed a laptop's lid and then unplugged a USB device -- with wakeup > enabled, the unplug would cause the laptop to wake up again without your > knowledge. > > Alan Stern when closed laptop's lid and then unplugged a non-hid usb device it doesn't cause laptop to wakeup. and if that usb device is hid type and cause laptop into wakeup state then system will continue into suspend state becuase system ask that need accepted a acpi lid open event. and for laptop usb wakeup that as general ask bios to enable usb wakeup then if need do more things to enable usb wakeup I think this usb wakeup function isn't friendly and inconveient, so enable it by default. after add this patch, if want to use usb wakeup function it only need enable bios configure it think it is appropriate. BRs, Yinbo. >