From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 72E374A340F for ; Tue, 5 May 2026 18:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778005654; cv=none; b=T72FPdxvjrihAcdPqZr9yInWpJyH3PEWnG+wOHGDRpxtZiwMz4nv0AzPOytgkQAClbk5ehdroQ9jtApR2TIpKGZp6IimIpa7KbTbTNDtRcsn4bZ6TyG7ZZ4iBvFuLl9uYvRLR3wEtT6zyLG8XPoPEon7CbUTmuLtpqv+g2vVCLg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778005654; c=relaxed/simple; bh=PkLb8wZz3LN/U9OfvMiROxZgNCLmAY4Q33Wx8Bh9oLc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yf9bevDFcL0cwKfv2QIxB1S6yBGVJoHLxp0hz4xCur+wrDMPjUottWUjje1+vv7AHTtJzUjjHZgux9q/vNHMgjJP9F3RFl+Ojm4w4x8iip8pXdfEo9AN4YdINNyNdtlwroJX/XkKdmC3Ueq9oUXBrMA+dnDyY4G3Hg7P/ysXuzw= 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=F66qPCo1; arc=none smtp.client-ip=209.85.128.47 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="F66qPCo1" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4852b81c73aso42986105e9.3 for ; Tue, 05 May 2026 11:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778005651; x=1778610451; 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=qWs5na6Cu2X9woRa7xyM3F4TzvlhNiNJPEUsaW9Eszc=; b=F66qPCo15L0/Fj9y7Y2hMMkzKPpsV2ddOd3fXyuJEbDBcji/plsYmRmVQoBbt7bjVq eikjmocvaa9lRUJNovGyUEFaljbHHdzG+JVberjnlu19klW4GINh3AxH0NeRk7NB4ySU TegYExugjfQelXuD/GX2ExFSS9GLAU8Rn7wueWp2LfxYhZLDoM8jG+Nbgya8Yb7El49T BbZBu9eEg5NFDyG2G5iFwU4upZw+tJtOC4Yhhzvr4UPEpZ8AqIvyE8c8mSOJVX81BJQ8 OUTaoAiui5895g2JY1DT0NELo4bbETYo7StDdeCYcK0HlMfflZ5nHvOJ8JRnjbX61TaG fD/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778005651; x=1778610451; 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=qWs5na6Cu2X9woRa7xyM3F4TzvlhNiNJPEUsaW9Eszc=; b=IBeI8BQ34/DKtSRizFd/4a08qQVEmT1sy5yM5p+3Ykt4D7ZY0Doa5GZ0uujbMqMe5y W00NXV3LkfBPA0jZXwbcsBbJHU4cPNeLSgnGsMM2Ji5Zg1+u4629+WiZNsMQV4LF+3h6 Vx7jfsOKqH6lstj7cQc1FJ4OsrMGUrnyL/H+M0pte7XDszZVKcA3HUDjUhlCKMwtD1z5 Fu0MZzfBk3s9UXkrRVTDx/nLGxRBqdCcVUDHvc1HNUm17RzmOaa8xaJWoyMjxbNxnQKw CiyUU6Y/vTzgRW6AIOwanl8zkLcz6baJRHR8Y9TXtl6yMry36hgNP0TQD8Cu1rkWq1yI vshw== X-Forwarded-Encrypted: i=1; AFNElJ/EjcFRMR2BjjA4ltmzhNzBZrRTCY5IpDnUrSy5y5myUCedM4j/rurThymyRbms3lfZiGmvhWWklxZToQw=@vger.kernel.org X-Gm-Message-State: AOJu0YxlmLrjclN9lUFmIbdk8NB90AwSBBFeWOeocX8oH++xjLhiLzvv E7bZyuVeK2cAJF1WHW2Uln2X/3wFzFoLqqSNiId56jPreEt+6nOEtRuK X-Gm-Gg: AeBDietG5Icac1ctlZcTZlQa+kfAzJEW0NJFGulsiVLS+7x/nTT87GcXZ+PDc7TUh17 7A03RP+h4UQvCg/FabMLqVISqKZ7hNrB+2HtHvH0r1AOgDN5JGRp2UbADB+AIWi2Gsvvw0WKNey NCvQBlyTWzfA8XBUYg9xnyOE1X9jW9yLvtGu/LUTqtxhl8FGgfe4p95R83A3F1507iUoEGvlvlB KPgOV+1Dt5z6pb3TRB4FD5IHp2NQ8BPE4VHlXEydgQ6758jpqRymFrxNdFrR+4Bbve4gHZJVPvi bhzqf9eBoCULLCmuw4EOTGp2cgUQ2WauxyB85hUpMkZ+eJXNe5nZBYrAwkILYQhmUilzGBnIsjL Ix3wWWPdRNILK6Bx2V2H+8z7extPqauSpJmfBd/8K0976EZbJPQ9EwYpum+DQAD6pIpxEgOJEJs gLAL6VBhm4IRIsr6rC+nzAD/BS6V1xwmqUCWQkLsqNd4TwpZMDq3eEVtMH/8YGJeocdRTdyFkMW egt5A4= X-Received: by 2002:a05:600c:a110:b0:488:9e43:9690 with SMTP id 5b1f17b1804b1-48e51e17746mr5220405e9.10.1778005650787; Tue, 05 May 2026 11:27:30 -0700 (PDT) Received: from Ansuel-XPS24 (host-82-59-227-65.retail.telecomitalia.it. [82.59.227.65]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-48a820c865esm408208245e9.5.2026.05.05.11.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 11:27:30 -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 RFC PATCH v5 03/10] net: phylink: add phylink_release_pcs() to externally release a PCS Date: Tue, 5 May 2026 20:27:04 +0200 Message-ID: <20260505182713.27644-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260505182713.27644-1-ansuelsmth@gmail.com> References: <20260505182713.27644-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@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) 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 | 49 +++++++++++++++++++++++++++++++++++++++ include/linux/phylink.h | 2 ++ 2 files changed, 51 insertions(+) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 1a261060d78e..ca4f4f655a31 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -923,6 +923,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->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 9c5a43febde1..aef4a4fcf6e5 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -746,6 +746,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