From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv2-f12.google.com (mail-qv2-f12.google.com [74.125.230.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2B232BD59C for ; Sat, 12 Sep 2026 23:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.230.140 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789257094; cv=none; b=Db3TcPHz6gQukQwHt8bxwM7YmSFFja8tghmXt8pGjTxZYcPDDqe5ei/T+2BdSyyHwNbKACk+KGeEKiA36VCM6JxPle4j9x3jXCBYQ6omXhCU55MaaDTk+4hZmV6ZkIcqXzFh/KFUF8kI9rVPZnu+cwtY6aFQcE5KIxeetFHaMqo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789257094; c=relaxed/simple; bh=fD9xegSujnsT4NKnlfjWBz0getfDwxDziPE/OzXLPzU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=pNkO+x1GJ1B4OAb4va7CcPz8uyg0Z+QuGbNOPNLc2ce4qBBm+0dAecyMNsXLvnPe5YyPesb09OJPux8cqDpEtaVt/Z/y2K0dRkmPG1Wzgn83ZT0wdnOMddkuuBkMnC5mlqbedv/2C8YnHnR9WvG6pfHuov/id/zauN1Qt0tRIJk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=o3VAHv82; arc=none smtp.client-ip=74.125.230.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="o3VAHv82" Received: by mail-qv2-f12.google.com with SMTP id 6a1803df08f44-90cdfcbe207so11588226d6.3 for ; Sat, 12 Sep 2026 16:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789257090; x=1789861890; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=P9J6NG/MV7DU9c7t3z7uXv1DPj7gHWd/klA6eHMwHZo=; b=o3VAHv82RPTcsoGv+o/rwriT8Rva/nR2SAw4/upykMRGJPLF9EX7VKV/34/zJx6MzR u64cxRQM0MnVQZ0T5ACzOHRHPFQsfI9N6SOUj8jAn4Z1K7rxwqxF9OxHkERVcaXSzZaP jVOuM1pirXlmy+FE8ao4pcHQEeCyvrgfKOfMe/vtHRCbbpRooqUtEeRHBgpA9r7VQ+QP bwNqeQ1Er574ASxtAhyQ057IKCzUZm94Qmx8IleLYt6x94VG68ARPib4uo/jEIiKfUZ+ J5FzBs09TxNcnWAxZ9k9Q8Cu68x6aBnbXUYrp9jzWgjpYZOR4pdZlccQg56l5KBG1fAF vuEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789257090; x=1789861890; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=P9J6NG/MV7DU9c7t3z7uXv1DPj7gHWd/klA6eHMwHZo=; b=WH3xtFM7i+MPqtnI1TGdPyzhByLsNxJLH5E8O13C5Y42JVcaiMVDQVHDv6Ku0Z0vcW IW/lBiH5SCMtrNhMHUFVJ9SqWa5vN7dvGa+x+PXAimnTj7xOfNeJMvB04xwrTKDFxB/w ajLcdRw67QBwDHpq6h35t+WPgYpr4iGVenRXmmVztgCElZGFbFX2TuEQeFYK50vxxONW tE2W3qQDxVHiPF4hnbEXT8RHhwkkfxh0y8kK63IO1UIFIti484T8n38jDBXMpsRpM6d0 gRhEj1VpQt6+PcoStED7cXRQa6Nnta/q5+R0gSamWcswq7Z/HAOCadBxSciU4AzXbZXI q++A== X-Forwarded-Encrypted: i=1; AKwUvBz7zl5c6X9QWNFz4AKaS+6wXwEj3G3TDb/uzPJtgyrlK+QjUi2Z5K0D7xanLs9FneVk2kdq/QIqgMS5dzQ=@vger.kernel.org X-Gm-Message-State: AFuF++l9G32VTdQFWE9prniborrJMDW+1qkCx2pSCrOkCsIgHKKBscVN KsEu97VkRirVFJOJVMbH+dpTn4jfu7mp8G2s0SjdiPNF2Uyk52A3OXQfWFOnHg== X-Gm-Gg: AYBFou3Dr0y/PpkvmHGekXM50iWBBx432AnLI6DzzAXpZLCy3ae3ibzNrhjFs64tdNA UrJGll3WgGUiLZut/VegrO7aZTbhYbhXpjL9qBpIvRDCFf5hYv9tEfNttoF6VlianOLKvSkJ70n ci+JEb/LQuAUsyb9MQiIsy29KwQAbqkW1Wyba1UF8zAprTJuepl0StEOLuoZ6CtaxV8VGt1c522 TsbfBXSYv8SKWYHMF8yjgq3xOMy7DjNue7yBSa6njgtMz3Arocs1ALSrJKdBW3v6s9AIkt0AYc3 kkTR+YaNq8jbRPrWrtd7mEuXp5+JU4I1tO9HYOvhMIKXT3qTN+hRizaYtfMNllF6t2nAJubH5c0 /5/yPmdbDX13fU5Bo8AURmrkKj7L+9xaCsFbXCfnZjYwuypIRyTNedUT20Q8Tpa48w3VlmVVs/M hfqw7dnh1+Up76PwTZCtiFPTryvm/JUi2wpZygqspZGTqJ40+rCQRTn4HomROJg+Cd+5bN7K8ny saMN3h9JwcGgyKKaUSWl64AtlYK0YHa61+Uda5w0Xnv5iAPry5SDUFK6YW1g6k2Mw4H3qjghdna LVVbwmV863pPktgunD67Bd04K4TxfASRWf8YDedsz8HETe/c1yg1oWZi6xM= X-Received: by 2002:a05:622a:64a:b0:530:4310:53a3 with SMTP id d75a77b69052e-530e81d49c7mr71418151cf.48.1789257090557; Sat, 12 Sep 2026 16:51:30 -0700 (PDT) Received: from ryzen.lan ([2601:644:8000:7a86::e34]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-530cd3ab1d1sm54050791cf.17.2026.09.12.16.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2026 16:51:29 -0700 (PDT) From: Rosen Penev To: netdev@vger.kernel.org Cc: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next] net: phy: marvell: wake the system only from the WoL event Date: Sat, 12 Sep 2026 16:51:25 -0700 Message-ID: <20260912235125.151370-1-rosenp@gmail.com> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Enable waking the system from a WoL event on the 88E1318S/88E1510. When WoL is enabled, m88e1318_set_wol() now calls enable_irq_wake() on the PHY's IRQ and marks the MDIO device as a wakeup source so the underlying GPIO interrupt raises the system from suspend, and reverses both on disable. With WoL active the PHY must stay powered to detect a magic packet, but without masking, phy_suspend() would leave every interrupt enabled, so a link status change or any other PHY event would assert INTn and spuriously wake the system. Set PHY_ALWAYS_CALL_SUSPEND on the 88E1318S/88E1510 drivers so that phy_suspend() still calls their suspend callbacks with WoL enabled, and have those callbacks keep the PHY awake while writing the interrupt enable register (CSIER/IMASK) down to only the WoL event bit. marvell_config_intr() rewrites the whole CSIER register with MII_M1011_IMASK_INIT on resume, clearing the WoL enable bit. Re-arm WOL_EIE in the resume callbacks so the WoL interrupt stays active for the next sleep cycle. Assisted-by: LLM Signed-off-by: Rosen Penev --- drivers/net/phy/marvell.c | 145 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 138 insertions(+), 7 deletions(-) diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index f71cffa88406..70aaa09f2047 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include #include @@ -1902,6 +1904,61 @@ static int marvell_resume(struct phy_device *phydev) return err; } +/* marvell_wol_suspend_intrs + * + * With WoL enabled the PHY has to stay powered to keep detecting a WoL + * packet, so instead of entering low power mode, mask all interrupt + * sources except the WoL event. On the 88E1318S/88E1510 the interrupt + * mask (MII_M1011_IMASK) is the same register as the Copper Specific + * Interrupt Enable Register (MII_88E1318S_PHY_CSIER), so writing only + * the WoL event enable bit unmask just that event. + */ +static int marvell_wol_suspend_intrs(struct phy_device *phydev) +{ + int oldpage, ret; + + oldpage = phy_save_page(phydev); + if (oldpage < 0) + return oldpage; + + ret = marvell_write_page(phydev, MII_MARVELL_COPPER_PAGE); + if (ret < 0) + goto out; + + ret = __phy_write(phydev, MII_88E1318S_PHY_CSIER, + MII_88E1318S_PHY_CSIER_WOL_EIE); +out: + return phy_restore_page(phydev, oldpage, ret); +} + +/* marvell_wol_resume_intrs + * + * marvell_config_intr() rewrites the whole MII_M1011_IMASK register + * (which is MII_88E1318S_PHY_CSIER) with MII_M1011_IMASK_INIT on + * resume, clearing the WoL event interrupt enable bit. Re-arm it if + * WoL is still enabled so a later WoL event keeps waking the system. + */ +static int marvell_wol_resume_intrs(struct phy_device *phydev) +{ + int oldpage, ret; + + if (!phydev->wol_enabled) + return 0; + + oldpage = phy_save_page(phydev); + if (oldpage < 0) + return oldpage; + + ret = marvell_write_page(phydev, MII_MARVELL_COPPER_PAGE); + if (ret < 0) + goto out; + + ret = __phy_set_bits(phydev, MII_88E1318S_PHY_CSIER, + MII_88E1318S_PHY_CSIER_WOL_EIE); +out: + return phy_restore_page(phydev, oldpage, ret); +} + /* m88e1510_resume * * The 88e1510 PHY has an erratum where the phy downshift counter is not cleared @@ -1934,9 +1991,25 @@ static int m88e1510_resume(struct phy_device *phydev) /* downshift enabled, with previous counter value */ err = m88e1011_set_downshift(phydev, cnt); + if (err < 0) + return err; } - return err; + return marvell_wol_resume_intrs(phydev); +} + +/* m88e1510_suspend + * + * If WoL is enabled the PHY receiver has to keep running to detect a + * magic packet, so keep it awake and unmask only the WoL event at the + * PHY. Otherwise suspend both the fiber and copper interfaces as usual. + */ +static int m88e1510_suspend(struct phy_device *phydev) +{ + if (phydev->wol_enabled) + return marvell_wol_suspend_intrs(phydev); + + return marvell_suspend(phydev); } static int marvell_aneg_done(struct phy_device *phydev) @@ -1969,8 +2042,12 @@ static void m88e1318_get_wol(struct phy_device *phydev, static int m88e1318_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) { + struct device *dev = &phydev->mdio.dev; + bool wol_enable; int err = 0, oldpage; + wol_enable = !!(wol->wolopts & (WAKE_MAGIC | WAKE_PHY)); + oldpage = phy_save_page(phydev); if (oldpage < 0) goto error; @@ -2075,7 +2152,49 @@ static int m88e1318_set_wol(struct phy_device *phydev, } error: - return phy_restore_page(phydev, oldpage, err); + err = phy_restore_page(phydev, oldpage, err); + if (err < 0) + return err; + + if (device_can_wakeup(dev) && wol_enable != device_may_wakeup(dev)) { + err = device_set_wakeup_enable(dev, wol_enable); + if (err < 0) { + /* Roll back the PHY WoL config if the PM state update failed */ + struct ethtool_wolinfo wol_off = { .wolopts = 0 }; + int rollback_err = m88e1318_set_wol(phydev, &wol_off); + + if (rollback_err < 0) + phydev_err(phydev, + "Failed to disable WoL after wakeup enable error %d\n", + rollback_err); + } + } + + return err; +} + +/* m88e1318_suspend + * + * If WoL is enabled keep the PHY awake so it can detect a magic packet + * while the system is asleep, unmasking only the WoL event at the PHY. + * Otherwise suspend the PHY normally. + */ +static int m88e1318_suspend(struct phy_device *phydev) +{ + if (phydev->wol_enabled) + return marvell_wol_suspend_intrs(phydev); + + return genphy_suspend(phydev); +} + +static int m88e1318_resume(struct phy_device *phydev) +{ + int err = genphy_resume(phydev); + + if (err < 0) + return err; + + return marvell_wol_resume_intrs(phydev); } static int marvell_get_sset_count(struct phy_device *phydev) @@ -3587,14 +3706,25 @@ static int m88e1318_led_hw_control_get(struct phy_device *phydev, u8 index, static int marvell_probe(struct phy_device *phydev) { + struct device *dev = &phydev->mdio.dev; struct marvell_priv *priv; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; phydev->priv = priv; + if (device_property_present(dev, "wakeup-source") && + phy_interrupt_is_valid(phydev)) { + int ret = devm_pm_set_wake_irq(dev, phydev->irq); + + if (ret) + return ret; + + device_set_wakeup_capable(dev, true); + } + return marvell_hwmon_probe(phydev); } @@ -3813,6 +3943,7 @@ static struct phy_driver marvell_drivers[] = { .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E1318S", /* PHY_GBIT_FEATURES */ + .flags = PHY_ALWAYS_CALL_SUSPEND, .probe = marvell_probe, .config_init = m88e1318_config_init, .config_aneg = m88e1318_config_aneg, @@ -3821,8 +3952,8 @@ static struct phy_driver marvell_drivers[] = { .handle_interrupt = marvell_handle_interrupt, .get_wol = m88e1318_get_wol, .set_wol = m88e1318_set_wol, - .resume = genphy_resume, - .suspend = genphy_suspend, + .resume = m88e1318_resume, + .suspend = m88e1318_suspend, .read_page = marvell_read_page, .write_page = marvell_write_page, .get_sset_count = marvell_get_sset_count, @@ -3920,7 +4051,7 @@ static struct phy_driver marvell_drivers[] = { .name = "Marvell 88E1510", .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), .features = PHY_GBIT_FIBRE_FEATURES, - .flags = PHY_POLL_CABLE_TEST, + .flags = PHY_POLL_CABLE_TEST | PHY_ALWAYS_CALL_SUSPEND, .probe = marvell_probe, .config_init = m88e1510_config_init, .config_aneg = m88e1510_config_aneg, @@ -3930,7 +4061,7 @@ static struct phy_driver marvell_drivers[] = { .get_wol = m88e1318_get_wol, .set_wol = m88e1318_set_wol, .resume = m88e1510_resume, - .suspend = marvell_suspend, + .suspend = m88e1510_suspend, .read_page = marvell_read_page, .write_page = marvell_write_page, .get_sset_count = marvell_get_sset_count, -- 2.55.0