From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 7BC6A3F5BC4 for ; Thu, 18 Jun 2026 12:58:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781787501; cv=none; b=NPXlwQ6Xtg3Q1o5WN48afApFc2j34EpqhAoLUxfT3/XOn0JoTeuYtTVVFM5EBY4GirT4K+RexNpGFiVS1r8/Hr+zkzqYzph6dXkZSJMlhu+zy0NoSJf3GI0R1gazlgBeKr3RpTmrVVdnYu73o/XO9ENQbAP4b+ZjqZ+liHYwimg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781787501; c=relaxed/simple; bh=4eefkNAfstnaWyC3I23kUkVKigZEIWwvbR5gE2d2aQo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ONh0UZwPZdczAxKZFKYx3Gv8ed9NgxJzAcj3GKzwVPheduBrMO+Du5m+7WSru0ErCCDGha6uL5LiHCY5d4qxSAQvfR81gxWHdT0vWWXTeqA4Q0uyC7Mv02Nyky0hWoG8ttxg8SWVQzRxwqQHObkRxYxZtjp89V4P/fSHCkIbkxs= 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=LBplTvyg; arc=none smtp.client-ip=209.85.128.53 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="LBplTvyg" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-490b12270b3so4771455e9.1 for ; Thu, 18 Jun 2026 05:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781787496; x=1782392296; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=puwAHt6DIGuC1Wf1TrT+M8/3nufhWyiZt6erLHCVM5o=; b=LBplTvyg1vgDp7Y25fVZCx27ZGsunvkSz4fiBZF+8Dn60rEOBm1jGNLyyxd/2RbB6f 7f5KtNvLs0rvquzLXxFmw3XhHjcHNO1O1+mLXm4bKpTF6A8Dmc4GuOpkOEQ9XThIRW7L ZhmxyH3IXa73w65We8WItzoKy/Hw6mlRu80ohu4QOAEeE6sE6EQacq/YR3sxyM519pmY QwcWODx8nvwnOAa2nx2ls4qJANA9FY7P5/P1gFxJmw13ny01/wqCTkIKcKX32Q0E12sq 2XP3HTbmN2iD1oXyf+R9v3yu+8w4VWq8ZoyoJHSshdB88IhN3cpO++tWGsEMgi05WUbN GJAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781787496; x=1782392296; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=puwAHt6DIGuC1Wf1TrT+M8/3nufhWyiZt6erLHCVM5o=; b=LgeAKk/Q0fps1P9egv5YWJlRsBAgX2ks+F+rtJ25uWJFe2oIyXMCRjiB9r19hE3R9T Vs4fnNnuqUTC48lgOAzoDqwf80soqAt/sj5ckH70U3IauZiUkXFJ9xiPNARU3uHItpx/ fir2Z0GZcSxa77O3W+Zfw55AZOVcMTX1paNJHvpjro2rtwy7gfCSKUuc536HJ4Mefp7y WtSBXPrJ1CXBVY6tVJCeaSfUVzua7GKe72LNfNmsYOoWr44mNi2HB2R7GfJq8thJ+2Ee He8rTp0aJdA8iSFNpB3JdKq+MGAepsolA++VdAnLAQwRLbCfsRGtM0PjUiNa227JgYp0 53KQ== X-Forwarded-Encrypted: i=1; AFNElJ/NZ0c1cIb32ZnbrF47EP88Uz2pmNFivFhEJFtmmnb/JnNVGG+679iQmHcr0LIxYNmWzjQBt78=@vger.kernel.org X-Gm-Message-State: AOJu0YzjHp3UDVMZ1eJ9pYQlu3a/tKasYsjtE5oPbTnfZXYVKRCWHveA prTqex1GUq+rGpGCvE2Ka8EIzXw7UOv2xUdQhoDXTCN5Vj/5kcwlwiLx84wT3g== X-Gm-Gg: AfdE7cnvKCHoFeEp0K0qFod/VZwM+MMeQWp9JDLxy5Zxc7/tWiPwgN7T2BEA2d9TG31 6hxYTSaxL9Ve29djYRkojFkWGbGyvFBnfqi/0/vpVxNiLXaHoW1/uZZfWXPU/4M6xFiTzn+SmiU MmtWaK+oz2DgI23ORt4uKUiKxYgQbhg2I0vPDaCRrOkIrBaUAlFcURfkYzlZCkIj4YTbLP0m7Zy p/NgyRgz13Z0Q4L95J3g0IERS3X1P+ok72ijrm8oauyRPuDQeXxTTBjxFIfoX0dSziknqDbmSv9 iiD1gOyCCXActdvVg6fE+d90JykparpDq0WSUJPusFTVHCeWLvWPqmo+5PTKQ0NXuuKxHf2gLf9 CrezmkhxvP5Zbw9OCGRwjpCmCTIrvk+m/1XU30xaEhqjtu3y2Xx2y7gHKxIxYrpoqAfN5pp4pI7 oE63yNHV0bn+7kZnEp2Tzmx1NJdG6Kcj7hpAe6D+k9ztXLfgTzJ3CNMHEi02HY2g== X-Received: by 2002:a05:600c:5644:b0:490:adb6:7957 with SMTP id 5b1f17b1804b1-49234141d98mr89030975e9.33.1781787495577; Thu, 18 Jun 2026 05:58:15 -0700 (PDT) Received: from Ansuel-XPS24.localdomain (93-34-88-103.ip49.fastwebnet.it. [93.34.88.103]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-49230a458f2sm241451585e9.3.2026.06.18.05.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2026 05:58:15 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Simon Horman , Jonathan Corbet , Shuah Khan , Christian Marangi , Lorenzo Bianconi , Heiner Kallweit , Russell King , Saravana Kannan , Philipp Zabel , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, llvm@lists.linux.dev, Maxime Chevallier Subject: [RFC PATCH net-next v8 03/12] net: phylink: add phylink_release_pcs() to externally release a PCS Date: Thu, 18 Jun 2026 14:57:11 +0200 Message-ID: <20260618125752.1223-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260618125752.1223-1-ansuelsmth@gmail.com> References: <20260618125752.1223-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add phylink_release_pcs() to externally release a PCS from a phylink instance. This can be used to handle case when a single PCS needs to be removed and the phylink instance needs to be refreshed. On calling phylink_release_pcs(), the PCS will be removed from the phylink internal PCS list and the phylink supported_interfaces value is reparsed with the remaining PCS interfaces. Also a phylink resolve is triggered to handle the PCS removal. The flag force_major_config is set to make phylink resolve reconfigure the interface (even if it didn't change). This is needed to handle the special case when the current PCS used by phylink is removed and a major_config is needed to propagae the configuration change. With this option enabled we also force mac_config even if the PHY link is not up for the in-band case. Signed-off-by: Christian Marangi --- drivers/net/phy/phylink.c | 56 +++++++++++++++++++++++++++++++++++++++ include/linux/phylink.h | 2 ++ 2 files changed, 58 insertions(+) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index c38bcd43b8c8..064d6f5a06da 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -158,6 +158,8 @@ static const phy_interface_t phylink_sfp_interface_preference[] = { static DECLARE_PHY_INTERFACE_MASK(phylink_sfp_interfaces); static void phylink_run_resolve(struct phylink *pl); +static void phylink_link_down(struct phylink *pl); +static void phylink_pcs_disable(struct phylink_pcs *pcs); /** * phylink_set_port_modes() - set the port type modes in the ethtool mask @@ -918,6 +920,60 @@ static void phylink_resolve_an_pause(struct phylink_link_state *state) } } +/** + * phylink_release_pcs - Removes a PCS from the phylink PCS available list + * @pcs: a pointer to the phylink_pcs struct to be released + * + * This function release a PCS from the phylink PCS available list if + * actually in use. It also refreshes the supported interfaces of the + * phylink instance by copying the supported interfaces from the phylink + * conf and merging the supported interfaces of the remaining available PCS + * in the list and trigger a resolve. + */ +void phylink_release_pcs(struct phylink_pcs *pcs) +{ + struct phylink *pl; + + ASSERT_RTNL(); + + pl = pcs->phylink; + if (!pl) + return; + + mutex_lock(&pl->state_mutex); + + list_del(&pcs->list); + pcs->phylink = NULL; + + /* + * Check if we are removing the PCS currently + * in use by phylink. If this is the case, tear down + * the link, force phylink resolve to reconfigure the + * interface mode, disable the current PCS and set the + * phylink PCS to NULL. + */ + if (pl->pcs == pcs) { + phylink_link_down(pl); + phylink_pcs_disable(pl->pcs); + + pl->force_major_config = true; + pl->pcs = NULL; + } + + mutex_unlock(&pl->state_mutex); + + /* Refresh supported interfaces */ + phy_interface_copy(pl->supported_interfaces, + pl->config->supported_interfaces); + list_for_each_entry(pcs, &pl->pcs_list, list) + phy_interface_or(pl->supported_interfaces, + pl->supported_interfaces, + pcs->supported_interfaces); + + phylink_run_resolve(pl); +} +EXPORT_SYMBOL_GPL(phylink_release_pcs); + static unsigned int phylink_pcs_inband_caps(struct phylink_pcs *pcs, phy_interface_t interface) { diff --git a/include/linux/phylink.h b/include/linux/phylink.h index ca9dfc142388..15e6b1a39dfe 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -751,6 +751,8 @@ void phylink_disconnect_phy(struct phylink *); int phylink_set_fixed_link(struct phylink *, const struct phylink_link_state *); +void phylink_release_pcs(struct phylink_pcs *pcs); + void phylink_mac_change(struct phylink *, bool up); void phylink_pcs_change(struct phylink_pcs *, bool up); -- 2.53.0