public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] r8152: Suspend USB device before shutdown when WoL is enabled
@ 2023-07-06 18:28 Alexandru Gagniuc
  2023-07-08  0:12 ` Jakub Kicinski
  0 siblings, 1 reply; 12+ messages in thread
From: Alexandru Gagniuc @ 2023-07-06 18:28 UTC (permalink / raw)
  To: linux-usb, netdev
  Cc: davem, edumazet, kuba, pabeni, hayeswang, jflf_kernel, bjorn,
	svenva, linux-kernel, eniac-xw.zhang, Alexandru Gagniuc, stable

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 <alexandru.gagniuc@hp.com>
---
 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 <net/ip6_checksum.h>
 #include <uapi/linux/mdio.h>
 #include <linux/mdio.h>
+#include <linux/reboot.h>
 #include <linux/usb/cdc.h>
 #include <linux/suspend.h>
 #include <linux/atomic.h>
@@ -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);
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-08-11  1:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-06 18:28 [PATCH] r8152: Suspend USB device before shutdown when WoL is enabled Alexandru Gagniuc
2023-07-08  0:12 ` Jakub Kicinski
2023-07-08  1:51   ` Alan Stern
2023-07-19 17:37     ` [PATCH v2] " Alexandru Gagniuc
2023-07-19 18:36       ` Alan Stern
2023-08-02 14:56         ` Gagniuc, Alexandru
2023-08-02 15:23           ` Alan Stern
2023-08-10 16:22         ` Alexandru Gagniuc
2023-08-10 17:34           ` Alan Stern
2023-08-10 22:51             ` Alexandru Gagniuc
2023-08-11  1:51               ` Alan Stern
2023-07-20  8:39       ` Oliver Neukum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox