From patchwork Sun Sep 27 21:59:38 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 3517 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 19B661C308D for ; Mon, 28 Sep 2026 00:00:47 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-26352-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-26352-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id B328C2F097 for ; Sun, 27 Sep 2026 22:00:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3620B3DDAF6; Sun, 27 Sep 2026 22:00:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YXpslX6i" X-Original-To: linux-sunxi@lists.linux.dev Received: from mail-oo2-f38.google.com (mail-oo2-f38.google.com [74.125.231.166]) (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 3742F3D3CEF for ; Sun, 27 Sep 2026 21:59:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.231.166 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790546400; cv=none; b=JSRLS81Gd+MyW/yfSXLS449bZggiSQ9fzqT8/cIrZMcbn5QWcY6w+rJerjg1+pbbYRmcPCC4Qffyg9rkrVrKnd+mtEkAVy94IWExf9sw9xPhDSlQ9hKRSHH+JWE9thIBvuzIcoNBBSlsvGF1Yu/MCjMzdLbSDcjhRvj8M1H0HrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790546400; c=relaxed/simple; bh=rzqz19tdKiIDsU7aWYdQjxQohn7bMOmaxt0Fu4XDk60=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ae7NxM8m/zuMUhFBytlogXjsmC2V0i4bnXyvOA/utRlLZnkSHKRBNFxiD6KzmjhCajyRymSazim2GzmQoA6wmFUwCWSylU7FwgEkBaMdyJM7k+2XDwMYvrDJ7G0baWeQd9x0BQuWmZPN4s2NL2Lefq0988Nw/kCbRC5wZatxkr4= 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=YXpslX6i; arc=none smtp.client-ip=74.125.231.166 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 Received: by mail-oo2-f38.google.com with SMTP id 46e09a7af769-80a71781323so1412747a34.1 for ; Sun, 27 Sep 2026 14:59:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790546393; x=1791151193; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=sgAVUUxDB8OVhc+RGqtGQd2Cq3Rragg7xi0varaDwWI=; b=YXpslX6i+iHTYCKpjteUqdtVz9kXPpiv7AbrLBZjgDchQXn+jRvdVjqXsnI44xhELH pHsoAGjfEX+y95xswxd87fXcO1b1NaSEY/FIM7t5LM+xCfl4jx8t4MozhcMjkROIqxnI Xhkl7/lLifcqwIOmw8jdlDXyOtCcW7OstQFHVyedwdRUJrZVWvby0C+09M1FjRe2aQpD IZAbXQcvGh8QWgvQ/1+Ai8giBuC+bxiiWhqF9JITKucr2S6ArfQjJimQ7P0CUieUGWF9 ShH0Eq4ZDaqXqtWktRpKN+SFQ3/Q64tPh1M1wJR3UFJjhGOPwjrlGjXNpY1rdd0gzY9s AjIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790546393; x=1791151193; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=sgAVUUxDB8OVhc+RGqtGQd2Cq3Rragg7xi0varaDwWI=; b=wf+9TKM1Lu+sA5P06nl4ic1O9PSMwzocV3g1G3vzOtRxMRx7JGOuhJmkZQfcMzyUMT PN90no0YzFAZxbUl7NlNkL3SpPxHvt9X6/ohDpEM0oWZP4R4h9Lnuqu7Z2t7VZy1iXVY bS8Rgp3Mn469caoEsZoudrQ3KgLALU309zciw5Ab4o1Pq5wAP1jpgZj7M6q9uv9NN0Ey +meL3X3wdmPGtuKhgrZxh+/1ofqD7tgUsHqd3QZYtW+h5RtykFDj6sKYWiJo4b9uAU4N bgX9XtQtx2oohJ6KyIgGaIm+2ktmjasyh24BptL9KGYBrj69ItEzpK/PpDKNa7qsi0pr V/2w== X-Forwarded-Encrypted: i=1; AKwUvBxj2gI87dywhKUA2p0wQp8UsD2/eoZbJZ55WPWv6DHbZPy9aeg6mwQKEl1v8XHZt9HWAbyq4CCda6N75A==@lists.linux.dev X-Gm-Message-State: AFuF++k7zQv33X+skOZ+PPuyBuNmidB6tTKvh/jgxDM56BcRZjgZCxoU pdZ6FF0V9zjgnNqGg17+2d19JC3GMamCsE66cFIwsgOtxl19Cbb+8O1/ X-Gm-Gg: AYBFou0+XcreLIojI6Zh6sP/BLMWQOC8ZdYUojK4trOc88tfRH+jMamPW+XDU1SaB0k VA2zvBz+6ZjlIL5XFC7c2dez/RVN6Nz7uj8mc9+W68MvlJnjL56ls4ewmralBo7Q8Id0vcfc/KZ lHnoBrabv/gU3L2BI+75CcLE7SwI86iPzCZlijGFp+I6INstMsLu6/dtEFoaXND9PDDCqhzMFyX zki4obnSFFk6fjWRW3KKfvbmghuOdUkNIWCKRZ0J89ZNx0DId/xkz+xHQvzqjse+YM70nz2Ihb4 EGJzgGolYeXt+LjFYAiR0zrMHiBgqpkN7aHVx4WTsypBoPd6Ois8/QWlZ2u1gZP3x0zXwycb26/ RvbaBSmiaMecVJ+almiVo/c/pAu1cwO6rHvz7d5zcPIUcT7LtEdAi8kG1lnzsB1kRS1ARlUow/U xhqQA/oKaKNawb0qQrS8tzuNCslZk6EuZDHNROf72vrmdT6evIgqlLC2eqSd75wevl5+CJjxBka jzPxk0AYvTWTp4gV2cYltblbgC0X4uS0hF8N7QrGR1R+c0wLTXF7otLoS0CMK/Q+Zmg6Vc/HQ3M 1hXXooUm1+kGtQX9qnLrADcrecrQwEMXHSCqTph6p8xtpIcapYXNM9GHYotJxTYOpgJINBBQh2H 22x11Qs/3OD3rkDwurlLN X-Received: by 2002:a05:6820:4b97:b0:6b7:46e9:96f5 with SMTP id 006d021491bc7-6d43fe7118cmr10987249eaf.37.1790546393220; Sun, 27 Sep 2026 14:59:53 -0700 (PDT) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-81b3de6f7e1sm4874147a34.22.2026.09.27.14.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2026 14:59:52 -0700 (PDT) From: James Hilliard Date: Sun, 27 Sep 2026 15:59:38 -0600 Subject: [PATCH net-next v5 03/19] net: phylink: allow stopping a suspended instance Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20260927-submit-stmmac-reset-fixes-v1-v5-3-feec6c14dd06@gmail.com> References: <20260927-submit-stmmac-reset-fixes-v1-v5-0-feec6c14dd06@gmail.com> In-Reply-To: <20260927-submit-stmmac-reset-fixes-v1-v5-0-feec6c14dd06@gmail.com> To: Russell King , Andrew Lunn , Heiner Kallweit , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King (Oracle)" , Maxime Chevallier , Andrew Lunn , Maxime Coquelin , Alexandre Torgue , Christian Marangi , Tiezhu Yang , Huacai Chen , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , Serge Semin , Suraj Jaiswal , Richard Cochran , Joao Pinto , Vladimir Oltean , Ong Boon Leong , Voon Weifeng , "Song, Yoong Siang" , Linus Walleij , Martin Blumenstingl , Magnus Karlsson , Maciej Fijalkowski , Simon Horman , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Thierry Reding , Jonathan Hunter , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jose Abreu , Yao Zi , Philipp Zabel Cc: Richard Genoud , Alastair D'Silva , Maxime Ripard , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org, ZhaoJinming , Lorenzo Bianconi , Ding Hui , Linkui Xiao , Linkui Xiao , linux-tegra@vger.kernel.org, linux-sunxi@lists.linux.dev, James Hilliard X-Mailer: b4 0.15.2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= If a network driver's system resume fails before phylink_resume(), the network device can remain administratively up with phylink suspended. Closing the interface then needs to terminate that suspended instance. Calling phylink_resume() merely to make phylink_stop() work is not a safe substitute: resume reconfigures the MAC and restarts link resolution, although the driver has not successfully restored the MAC. This is a missing suspend-to-stop transition, independent of the reason hardware restoration failed. No MAC recovery policy belongs in phylink; the driver still decides whether to retry resume or wait for an ordinary administrative down/up cycle. Without MAC Wake-on-LAN, phylink_suspend() has already called phylink_stop(). Do not repeat PHY, SFP and PCS shutdown. However, phylink_prepare_resume() may have powered that stopped PHY back up to provide the receive clock for MAC reset. Suspend it again if WoL permits, without repeating phy_stop() on a PHY which is already halted. With MAC Wake-on-LAN, suspend deliberately defers mac_link_down() and sets PHYLINK_DISABLE_MAC_WOL. Finish that deferred link-down, drain resolution work and clear the WoL disable bit while retaining PHYLINK_DISABLE_STOPPED. Otherwise a subsequent start cannot resolve the link. Also undo PHY speed control performed by phylink_suspend(). As Andrew Lunn pointed out, phylink_start() does not restore the advertised speeds that phylink_resume() normally restores. Track suspend-owned speed control and restore the saved advertisement from either resume or suspended stop, including when PHY shutdown has already completed. An explicit driver speed-down request, such as stmmac's close-time power saving, must remain in effect until its matching speed-up. Restore any suspend-owned reduction before applying that request, so it cannot save the reduced advertisement over the original one. The following stop must not undo the driver's new reduction. Document that a suspended instance can be stopped directly. This neither resumes the PHY nor reconfigures or brings up the MAC. Fixes: f97493657c63 ("net: phylink: add suspend/resume support") Signed-off-by: James Hilliard --- drivers/net/phy/phylink.c | 51 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index a7d086cdc9b2..f97fee908df6 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -78,6 +78,7 @@ struct phylink { bool link_failed; bool suspend_link_up; + bool suspend_speed_down; bool force_major_config; bool major_config_failed; bool mac_supports_eee_ops; @@ -2618,6 +2619,14 @@ void phylink_start(struct phylink *pl) } EXPORT_SYMBOL_GPL(phylink_start); +static void phylink_restore_suspend_speed(struct phylink *pl) +{ + if (pl->suspend_speed_down) { + phylink_speed_up(pl); + pl->suspend_speed_down = false; + } +} + /** * phylink_stop() - stop a phylink instance * @pl: a pointer to a &struct phylink returned from phylink_create() @@ -2629,11 +2638,30 @@ EXPORT_SYMBOL_GPL(phylink_start); * * This will synchronously bring down the link if the link is not already * down (in other words, it will trigger a mac_link_down() method call.) + * A suspended instance may be stopped without first calling phylink_resume(). + * In particular, closing a device after a failed resume must not restart the + * link or reconfigure the MAC just to finish shutting it down. + * Any PHY advertisement reduced by phylink_suspend() is restored as part + * of this transition. + * If phylink_prepare_resume() powered up an already stopped PHY, suspend + * it again when Wake-on-LAN permits. */ void phylink_stop(struct phylink *pl) { ASSERT_RTNL(); + /* Also undo PHY speed control when terminating a suspended instance. */ + phylink_restore_suspend_speed(pl); + + if (test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state)) { + /* A failed MAC resume may have called phylink_prepare_resume() + * and powered the stopped PHY back up to supply its RX clock. + */ + if (pl->phydev) + phy_suspend(pl->phydev); + return; + } + if (pl->sfp_bus) sfp_upstream_stop(pl->sfp_bus); if (pl->phydev) @@ -2646,6 +2674,16 @@ void phylink_stop(struct phylink *pl) phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_STOPPED); + if (test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)) { + /* Finish the link-down deferred by MAC WoL, without restarting. */ + flush_work(&pl->resolve); + mutex_lock(&pl->state_mutex); + if (pl->suspend_link_up) + phylink_link_down(pl); + __clear_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state); + mutex_unlock(&pl->state_mutex); + } + pl->pcs_state = PCS_STATE_DOWN; phylink_pcs_disable(pl->pcs); @@ -2777,8 +2815,10 @@ void phylink_suspend(struct phylink *pl, bool mac_wol) phylink_stop(pl); } - if (phylink_phy_pm_speed_ctrl(pl)) + if (phylink_phy_pm_speed_ctrl(pl)) { phylink_speed_down(pl, false); + pl->suspend_speed_down = true; + } } EXPORT_SYMBOL_GPL(phylink_suspend); @@ -2818,8 +2858,7 @@ void phylink_resume(struct phylink *pl) { ASSERT_RTNL(); - if (phylink_phy_pm_speed_ctrl(pl)) - phylink_speed_up(pl); + phylink_restore_suspend_speed(pl); if (test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)) { /* Wake-on-Lan enabled, MAC handling */ @@ -3687,6 +3726,12 @@ int phylink_speed_down(struct phylink *pl, bool sync) ASSERT_RTNL(); + /* An explicit request takes over from suspend-time speed control. + * Restore the original advertisement before saving it again, so a + * repeated speed-down cannot replace it with the reduced advertisement. + */ + phylink_restore_suspend_speed(pl); + if (!pl->sfp_bus && pl->phydev) ret = phy_speed_down(pl->phydev, sync);