From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 CB38C263F3D for ; Sun, 11 May 2025 20:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746994410; cv=none; b=Up5CYu0WGARzcgjPeK0kNpAz5GA1sR3lUHE6ZcteWAWZf+KDEIiNqQgHgw6yTlvYCa+8qBKhqn2NDejd/GKdkh9BK/hdmbhwW/o+TDjlMz6i+wjPFkzzFvki28z5yosmFdTI3iAtTat0m+StJ7kNZcpl5lVGoNicL0W9R9MazBo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746994410; c=relaxed/simple; bh=k2+jZG2fKDLcj1sNgat6nwbjyAPTOdXAGJj7hrPW7/M=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O33vXNzgoqPk+yR80Q/ttHDUg1OClG5xakIc/a4/k9FFUg9KT+Z0CyGa5JGI39xltyTkrpRi68mefU8vc6iArZU+iZfLOrbeTqlV57/3tbs2ZTndvNSMwaW+GcUxO6iJYcvSDvmUwGrK2uS37w/hO6HaRjXyohDC+UR00MqEPsI= 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=eFCrJtaY; arc=none smtp.client-ip=209.85.221.45 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="eFCrJtaY" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3a1fb18420aso1923815f8f.1 for ; Sun, 11 May 2025 13:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746994407; x=1747599207; darn=lists.linux.dev; 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=0mejOF2mYhTEXxWVOimbjN00Vr4yLk+E8aCpQ2xV2aM=; b=eFCrJtaY2hg594TL5JD6tQxwvrepzN6YsNP0E02V+5FJFwiNC5ICXs+ulyw9IhPJYm Dth4uPbXsOOOfVQOb+f52y/T7jHpFVay6aejQKifyzCCGDhHWEs1qDtLToAgBSpOmglx +VtIYiyjRsTQOls18ncMSWXVDof8n2QG7awecMKU8rsCPULLBAAJ2fKcrj3PNO+2F/WJ wOEPAu2lG8qqUegBaiQlOT9hdGy1RDltUh3xUOc7iAjvXFul5Jx0U5IaPfT3iOiDpFtk wZ8nuZE0HbFBXkFg6tb5sBnaP70M327Ru13mL7Uu2p1UCvBE9hxOBGti4y0EKllvdlUy N0tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746994407; x=1747599207; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0mejOF2mYhTEXxWVOimbjN00Vr4yLk+E8aCpQ2xV2aM=; b=PWXOw3SCruVGyMeoN+QLFFWTGqhtBsDZa+6lVWle/wczASzEvo2H2KuU2Nuuj7XbeR aHCBk/zq7kzcaCPnDUgm6ZucjUf7l2w240OrmdlpuPibVkxBCE39yUGMU7u0Z1ziawO2 3pv9LuXJX1gUYdnLMXJg7eBVqnEHRBeYizEEa7FRh0wfaLbH2F8e5ykcP3r/WMLH7gxd 7h97jid1Qp3wI6y++Hxml6faXpC3dyr84+0FcIb5I7am2Hasj5XhApBOg3yMacMjOTEE eZOfbDgz94XotxVidH1zDDEvS5TWmgKRkeaVU1nsRLSm5nEAdPgQ+DpL8VOu7vsXsTOo rVFw== X-Forwarded-Encrypted: i=1; AJvYcCXzssBK4JaGACuZu2haR/4KzVBRGgEOhFNtXOeRVzQIwUtNUDTTObIXWP6UlVTX/slmSgKg@lists.linux.dev X-Gm-Message-State: AOJu0YxPmGvKipWuzOF9QOZSuvq/60csVn+Invw0G3b/EELLHs7C9ZqF K/0iG1Pf7AwMlvSlsZaSyNRoVzVDU0rUGs9G9VWpF71Xt2+7Vcib X-Gm-Gg: ASbGncvgrkY3LX79cK3mB8L5+2m05bM7BaA+8dBEpgq8zxNd+wlVIXW7poCvJhWaPjy av9dBNG7Ql24GPM4bDB1826TVC5ZD880XKf8cs2yGGqAjWBOOgqrKspnRVHacH3Cif17EBkuPYe AyMSRKJmuRGVZqJMNYLa1pdwggOUL6vUR+fzLdhBuWzXtWHiR6kUy4vTfOf7Ikau6u4nyY+ldpd rZTRfby+aZPVU2XxmWSEV0Ai6g8Aau976YhMzM+/3iJcibtJSd4y3NPGzNy2Fy5LAuyELV4BC1t 3Uy12XU2k85XqgDweCglVmvQqS9htlM+61m+c1aYKjrgimCGyjX/wkcB/I7BtFo3+d3wEVhr7W+ WKL0d6cTa7VFGflQjamYvm6732/ylnb8= X-Google-Smtp-Source: AGHT+IFXCPvOH+Bl0GOCcZZfsHkVWH8TlBB8Wsfu39SLQaVZ3YE4Fzkrf4cNMCkqAZKJSKwW3S53LQ== X-Received: by 2002:a05:6000:18ae:b0:3a0:831d:267c with SMTP id ffacd0b85a97d-3a1f6433a0bmr9412917f8f.18.1746994406860; Sun, 11 May 2025 13:13:26 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-442d67ee275sm100615165e9.19.2025.05.11.13.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 May 2025 13:13:26 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lorenzo Bianconi , Heiner Kallweit , Russell King , Philipp Zabel , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Christian Marangi , Daniel Golle , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, llvm@lists.linux.dev Subject: [net-next PATCH v4 04/11] net: phylink: add phylink_release_pcs() to externally release a PCS Date: Sun, 11 May 2025 22:12:30 +0200 Message-ID: <20250511201250.3789083-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250511201250.3789083-1-ansuelsmth@gmail.com> References: <20250511201250.3789083-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev 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. A flag to make phylink resolve reconfigure the interface (even if it didn't change) is also added. 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 | 58 ++++++++++++++++++++++++++++++++++++++- include/linux/phylink.h | 2 ++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 95d7e06dee56..2f28c4c83062 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -84,6 +84,7 @@ struct phylink { bool link_failed; bool suspend_link_up; bool major_config_failed; + bool reconfig_interface; bool mac_supports_eee_ops; bool mac_supports_eee; bool phy_enable_tx_lpi; @@ -895,6 +896,55 @@ 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; + + list_del(&pcs->list); + pcs->phylink = NULL; + + /* Check if we are removing the PCS currently + * in use by phylink. If this is the case, + * force phylink resolve to reconfigure the interface + * mode and set the phylink PCS to NULL. + */ + if (pl->pcs == pcs) { + mutex_lock(&pl->state_mutex); + + pl->reconfig_interface = 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) { @@ -1688,6 +1738,10 @@ static void phylink_resolve(struct work_struct *w) if (pl->phydev) link_state.link &= pl->phy_state.link; + /* Force mac_config if we need to reconfig the interface */ + if (pl->reconfig_interface) + mac_config = true; + /* Only update if the PHY link is up */ if (pl->phydev && pl->phy_state.link) { /* If the interface has changed, force a link down @@ -1722,7 +1776,8 @@ static void phylink_resolve(struct work_struct *w) phylink_apply_manual_flow(pl, &link_state); if (mac_config) { - if (link_state.interface != pl->link_config.interface) { + if (link_state.interface != pl->link_config.interface || + pl->reconfig_interface) { /* The interface has changed, force the link down and * then reconfigure. */ @@ -1732,6 +1787,7 @@ static void phylink_resolve(struct work_struct *w) } phylink_major_config(pl, false, &link_state); pl->link_config.interface = link_state.interface; + pl->reconfig_interface = false; } } diff --git a/include/linux/phylink.h b/include/linux/phylink.h index ef0b5a0729c8..c5496c063b6a 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -717,6 +717,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.48.1