From patchwork Thu Jul 6 18:28:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Gagniuc X-Patchwork-Id: 116823 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2767437vqx; Thu, 6 Jul 2023 11:55:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlHx/GBVSw7khYBmGQdNu3Yc6ebNFFb8JtJhdo24JM6mdJrLpUiGSbZPnHu1JDkDBOFHhFLJ X-Received: by 2002:a05:6a21:339c:b0:11a:efaa:eb43 with SMTP id yy28-20020a056a21339c00b0011aefaaeb43mr2719853pzb.3.1688669717292; Thu, 06 Jul 2023 11:55:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688669717; cv=none; d=google.com; s=arc-20160816; b=K3VrkI+Soz04o2FmAQSvAeeJEKZxbHocioc2Ne9/db7sKZVmt1RLWSWIvjeqFoPJLb 7c7Bx5iA2LgQySYkhDC4R8bM8Z+StbIVTecss1Cw4CQhSU+I7T3xmM6HScsqBPUW3C8g NWh/UdYFC9impd61h7H53e2/y1mKZQrApO6rRXiV1J0naX8DFKWN+WzalcA1j9oF6dlu dmY77jreMsUvqKbBtEfB/Q0BB/4inPzAJtde5MgPRIU3vqlLsKMQIYI6TMoWEZs5ZyxJ KaF044S0yrgsWo/nnI9c0ybKBoJr/vr9o+bgFts1CEzEEeIXScA3xYc2Gb//DnXyZcdX 1F9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=i6byuPgD0BdV+edMY+7xoBI+stlHVgHroGrstvZaliE=; fh=OGVcpkow+bW0eya4lNVJeZuukVDqW1SjwDdUyZmIjkA=; b=VVHpli5T/2nNESMqDJuA6jZq7tnsYZy62THMtgkCxty15IvH6mMWySRfq6vcTyQbwi rcPqniYXtmZ9DU3iaP4HZtp0dWyPJKO5Jb5ryh13kcO38DtjxOLUcceAAkwLe1DBb068 zsnWky1nhCq9xPC5LD3O1RTGQj6NxMv5+99MipeqShR0OvZosrPjjQ1qdLwA0lUwzgKC 0sG5hqy9INuoHSY98KE/3BOZNdyS38jCuKfxBi7R3qEz5zB+VLjjE2W+A6IaN2LAOmfb QCTXrlgO+MzhU4A9kRTW4RgTthwT9G8Xbo+U/nLafTS4NmhgesmKrKv1q646woUX700X 4GgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hp.com header.s=mimecast20180716 header.b=NYNIXWBK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=hp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o11-20020a056a001bcb00b0067a5e89333esi1887400pfw.101.2023.07.06.11.54.59; Thu, 06 Jul 2023 11:55:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@hp.com header.s=mimecast20180716 header.b=NYNIXWBK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=hp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231280AbjGFSb5 (ORCPT + 99 others); Thu, 6 Jul 2023 14:31:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjGFSby (ORCPT ); Thu, 6 Jul 2023 14:31:54 -0400 X-Greylist: delayed 84 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 06 Jul 2023 11:31:02 PDT Received: from us-smtp-delivery-162.mimecast.com (us-smtp-delivery-162.mimecast.com [170.10.129.162]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8790D1BFF for ; Thu, 6 Jul 2023 11:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hp.com; s=mimecast20180716; t=1688668261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=i6byuPgD0BdV+edMY+7xoBI+stlHVgHroGrstvZaliE=; b=NYNIXWBKf74CNt9iQqkDQygusfeSVV6ed3w9/9TJQQU32OvJ6Oxa77utJQD8LTNDTbe1uK bgnRq4q4OloFLYdGWbV9Wv3iggYnh9JsWkSW3VZbPcRpyLg1Dw33OvcGSDD2CqDST5oizA kcZF5WOwsQu8WtP9RJd4rlDphYLYhqY= Received: from g1t6220.austin.hp.com (g1t6220.austin.hp.com [15.73.96.84]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-543-YG3C5vQoPEWLGQiUhrdSxA-1; Thu, 06 Jul 2023 14:29:35 -0400 X-MC-Unique: YG3C5vQoPEWLGQiUhrdSxA-1 Received: from g1t6217.austin.hpicorp.net (g1t6217.austin.hpicorp.net [15.67.1.144]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by g1t6220.austin.hp.com (Postfix) with ESMTPS id C072C23B; Thu, 6 Jul 2023 18:29:33 +0000 (UTC) Received: from jam-buntu.lan (unknown [15.74.50.248]) by g1t6217.austin.hpicorp.net (Postfix) with ESMTP id 516B189; Thu, 6 Jul 2023 18:29:32 +0000 (UTC) From: Alexandru Gagniuc To: linux-usb@vger.kernel.org, netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, hayeswang@realtek.com, jflf_kernel@gmx.com, bjorn@mork.no, svenva@chromium.org, linux-kernel@vger.kernel.org, eniac-xw.zhang@hp.com, Alexandru Gagniuc , stable@vger.kernel.org Subject: [PATCH] r8152: Suspend USB device before shutdown when WoL is enabled Date: Thu, 6 Jul 2023 18:28:58 +0000 Message-Id: <20230706182858.761311-1-alexandru.gagniuc@hp.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: hp.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770698537518637042?= X-GMAIL-MSGID: =?utf-8?q?1770698537518637042?= For Wake-on-LAN to work from S5 (shutdown), the USB link must be put in U3 state. If it is not, and the host "disappears", the chip will no longer respond to WoL triggers. To resolve this, add a notifier block and register it as a reboot notifier. When WoL is enabled, work through the usb_device struct to get to the suspend function. Calling this function puts the link in the correct state for WoL to function. Cc: stable@vger.kernel.org Signed-off-by: Alexandru Gagniuc --- drivers/net/usb/r8152.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 0999a58ca9d2..5623ca5c9142 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -875,6 +876,7 @@ struct r8152 { struct delayed_work schedule, hw_phy_work; struct mii_if_info mii; struct mutex control; /* use for hw setting */ + struct notifier_block reboot_notifier; #ifdef CONFIG_PM_SLEEP struct notifier_block pm_notifier; #endif @@ -9609,6 +9611,25 @@ static bool rtl8152_supports_lenovo_macpassthru(struct usb_device *udev) return 0; } +/* Suspend realtek chip before system shutdown + * + * For Wake-on-LAN to work from S5, the USB link must be put in U3 state. If + * the host otherwise "disappears", the chip will not respond to WoL triggers. + */ +static int rtl8152_notify(struct notifier_block *nb, unsigned long code, + void *unused) +{ + struct r8152 *tp = container_of(nb, struct r8152, reboot_notifier); + struct device *dev = &tp->udev->dev; + + if (code == SYS_POWER_OFF) { + if (tp->saved_wolopts && dev->type->pm->suspend) + dev->type->pm->suspend(dev); + } + + return NOTIFY_DONE; +} + static int rtl8152_probe(struct usb_interface *intf, const struct usb_device_id *id) { @@ -9791,6 +9812,9 @@ static int rtl8152_probe(struct usb_interface *intf, else device_set_wakeup_enable(&udev->dev, false); + tp->reboot_notifier.notifier_call = rtl8152_notify; + register_reboot_notifier(&tp->reboot_notifier); + netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION); return 0; @@ -9811,6 +9835,7 @@ static void rtl8152_disconnect(struct usb_interface *intf) if (tp) { rtl_set_unplug(tp); + unregister_reboot_notifier(&tp->reboot_notifier); unregister_netdev(tp->netdev); tasklet_kill(&tp->tx_tl); cancel_delayed_work_sync(&tp->hw_phy_work);