From: Christian Marangi <ansuelsmth@gmail.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Christian Marangi <ansuelsmth@gmail.com>,
Lorenzo Bianconi <lorenzo@kernel.org>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>,
netdev@vger.kernel.org, devicetree@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, llvm@lists.linux.dev
Subject: [PATCH net-next v23 09/15] net: phylink: support late PCS provider attach
Date: Mon, 30 Nov 2026 00:05:39 +0100 [thread overview]
Message-ID: <20261129230558.612526-10-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20261129230558.612526-1-ansuelsmth@gmail.com>
Add support for late PCS provider attachment to a phylink instance. Add
FWNODE_PCS_PROVIDER_ADD to handle the case where a PCS provider becomes
available after a phylink instance has been created.
The PCS notifier emits FWNODE_PCS_PROVIDER_ADD after registering a provider
and releasing the provider mutex. Call fwnode_pcs_add_provider() and its
devm variant with RTNL unlocked since the notifier can take RTNL.
On the add event, refresh the phylink PCS list through
fill_available_pcs(). Attach newly available PCS to the phylink instance
and refresh supported_interfaces and link capabilities when the list
changes. If the PCS list changes during creation, finish any pending
capability updates and SFP retries at the end of phylink_create().
Defer optical SFP insertion with -EAGAIN when none of the module's
interfaces is currently usable and at least one requires a PCS. Retry
deferred insertion when a PCS is added to the phylink instance.
If major_config_failed is set on a running instance, the next phylink
resolve retries interface configuration and reevaluates the autonegotiation
mode for the selected PCS. A follow-up resolve checks the link state with
the new configuration, allowing a link torn down by PCS removal to come
back up.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/net/pcs/pcs.c | 4 +++
drivers/net/phy/phylink.c | 50 +++++++++++++++++++++++++++-----
include/linux/pcs/pcs-provider.h | 4 +++
include/linux/pcs/pcs.h | 1 +
4 files changed, 52 insertions(+), 7 deletions(-)
diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c
index f04888432a42..6e7df0c792d0 100644
--- a/drivers/net/pcs/pcs.c
+++ b/drivers/net/pcs/pcs.c
@@ -71,6 +71,10 @@ fwnode_pcs_add_provider(struct fwnode_handle *fwnode,
mutex_unlock(&fwnode_pcs_mutex);
+ blocking_notifier_call_chain(&fwnode_pcs_notify_list,
+ FWNODE_PCS_PROVIDER_ADD,
+ pp);
+
pr_debug("Added pcs provider from %pfwf\n", fwnode);
return pp;
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 6dde0eae0e73..3471ba8d5ba6 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -2604,6 +2604,21 @@ static bool phylink_pcs_changed(struct phylink *pl)
return true;
}
+static void phylink_sfp_retry_module(struct phylink *pl)
+{
+ struct sfp_bus *bus;
+
+ ASSERT_RTNL();
+
+ if (!pl->netdev)
+ return;
+
+ /* The SFP callbacks publish the attached bus under RTNL */
+ bus = pl->netdev->sfp_bus;
+ if (bus && bus == pl->sfp_bus)
+ sfp_upstream_retry_module(bus);
+}
+
static int phylink_update_pcs(struct phylink *pl, bool rescan)
{
struct phylink_config *config = pl->config;
@@ -2613,6 +2628,7 @@ static int phylink_update_pcs(struct phylink *pl, bool rescan)
unsigned int num_pcs, i;
bool removed = false;
bool added = false;
+ bool resolve;
int ret;
lockdep_assert_held(&pl->pcs_list_mutex);
@@ -2628,7 +2644,9 @@ static int phylink_update_pcs(struct phylink *pl, bool rescan)
return ret;
}
- if (rescan) {
+ /* An add notification can fill the PCS list before the initial update */
+ resolve = rescan || !list_empty(&pl->pcs_list);
+ if (resolve) {
rtnl_lock();
mutex_lock(&pl->phydev_mutex);
phydev = pl->phydev;
@@ -2672,10 +2690,12 @@ static int phylink_update_pcs(struct phylink *pl, bool rescan)
}
mutex_unlock(&pl->state_mutex);
- if (rescan) {
+ if (resolve) {
if (phydev)
mutex_unlock(&phydev->lock);
mutex_unlock(&pl->phydev_mutex);
+ if (rescan && added && ret > 0)
+ phylink_sfp_retry_module(pl);
rtnl_unlock();
}
@@ -2750,13 +2770,15 @@ static int pcs_provider_notify(struct notifier_block *self,
bool skip;
int ret;
- if (val != FWNODE_PCS_PROVIDER_DEL)
+ if (val != FWNODE_PCS_PROVIDER_ADD &&
+ val != FWNODE_PCS_PROVIDER_DEL)
return NOTIFY_DONE;
mutex_lock(&pl->pcs_list_mutex);
mutex_lock(&pl->state_mutex);
skip = pl->pcs_state == PCS_STATE_DETACHING ||
- !phylink_has_provider_pcs(pl, provider);
+ (val == FWNODE_PCS_PROVIDER_DEL &&
+ !phylink_has_provider_pcs(pl, provider));
mutex_unlock(&pl->state_mutex);
if (skip) {
@@ -2774,7 +2796,8 @@ static int pcs_provider_notify(struct notifier_block *self,
* sure to remove any PCS provided by the provider that is getting
* removed. Signal to user and forcefully remove them.
*/
- resolve = phylink_remove_provider_pcs(pl, provider);
+ if (val == FWNODE_PCS_PROVIDER_DEL)
+ resolve = phylink_remove_provider_pcs(pl, provider);
}
mutex_unlock(&pl->pcs_list_mutex);
@@ -2787,6 +2810,7 @@ static int pcs_provider_notify(struct notifier_block *self,
static void phylink_pcs_finish_init(struct phylink *pl)
{
struct phy_device *phy;
+ bool pending;
/* SFP module callbacks can run once the upstream is registered */
if (pl->sfp_bus)
@@ -2797,7 +2821,8 @@ static void phylink_pcs_finish_init(struct phylink *pl)
mutex_lock(&phy->lock);
mutex_lock(&pl->state_mutex);
- if (pl->pcs_state == PCS_STATE_INIT_PENDING) {
+ pending = pl->pcs_state == PCS_STATE_INIT_PENDING;
+ if (pending) {
phylink_parse_supported_interfaces(pl);
phylink_update_capabilities(pl, &pl->link_config);
}
@@ -2807,8 +2832,11 @@ static void phylink_pcs_finish_init(struct phylink *pl)
if (phy)
mutex_unlock(&phy->lock);
mutex_unlock(&pl->phydev_mutex);
- if (pl->sfp_bus)
+ if (pl->sfp_bus) {
+ if (pending)
+ phylink_sfp_retry_module(pl);
rtnl_unlock();
+ }
}
static void phylink_detach_pcss(struct phylink *pl)
@@ -4789,6 +4817,14 @@ static int phylink_sfp_module_insert(void *upstream,
ASSERT_RTNL();
caps = sfp_get_module_caps(pl->sfp_bus);
+ /* A late PCS may provide the module's only usable interface */
+ if (!caps->may_have_phy &&
+ !bitmap_intersects(caps->interfaces, pl->supported_interfaces,
+ PHY_INTERFACE_MODE_MAX) &&
+ bitmap_intersects(caps->interfaces, pl->config->pcs_interfaces,
+ PHY_INTERFACE_MODE_MAX))
+ return -EAGAIN;
+
phy_interface_copy(pl->sfp_module_interfaces, caps->interfaces);
phy_interface_copy(pl->sfp_interfaces, caps->interfaces);
linkmode_copy(pl->sfp_support, caps->link_modes);
diff --git a/include/linux/pcs/pcs-provider.h b/include/linux/pcs/pcs-provider.h
index 2505c280946f..afcb7b878130 100644
--- a/include/linux/pcs/pcs-provider.h
+++ b/include/linux/pcs/pcs-provider.h
@@ -31,6 +31,8 @@ struct phylink_pcs *fwnode_pcs_simple_xlate(struct fwnode_reference_args *pcsspe
* A PCS object belongs to one provider and must remain valid until that
* provider is removed.
*
+ * Call without holding RTNL.
+ *
* Returns: A pointer to the registered PCS provider on success, or
* an ERR_PTR() encoded error code on failure.
*/
@@ -72,6 +74,8 @@ void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp);
* the PCS hardware inaccessible, use fwnode_pcs_add_provider() and call
* fwnode_pcs_del_provider() before shutting down the hardware.
*
+ * Call without holding RTNL.
+ *
* Returns: A pointer to the registered PCS provider on success, or
* an ERR_PTR() encoded error code on failure.
*/
diff --git a/include/linux/pcs/pcs.h b/include/linux/pcs/pcs.h
index e7d1fcd65357..6a5f0b6858ab 100644
--- a/include/linux/pcs/pcs.h
+++ b/include/linux/pcs/pcs.h
@@ -5,6 +5,7 @@
#include <linux/phylink.h>
enum fwnode_pcs_notify_event {
+ FWNODE_PCS_PROVIDER_ADD,
FWNODE_PCS_PROVIDER_DEL,
};
--
2.55.0
next prev parent reply other threads:[~2026-11-29 23:06 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 23:05 [PATCH net-next v23 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 02/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 05/15] net: phylink: make phylink_validate state locked Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 06/15] net: phylink: add capabilities helpers and track modified advertising Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 07/15] net: sfp: support deferred module insertion Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 08/15] net: phylink: support PCS provider release Christian Marangi
2026-11-29 23:05 ` Christian Marangi [this message]
2026-11-29 23:05 ` [PATCH net-next v23 10/15] net: Document PCS subsystem Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 14/15] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 15/15] net: airoha: add phylink support Christian Marangi
2026-11-29 23:09 ` [PATCH net-next v23 00/15] net: pcs: Introduce support for fwnode PCS netdev-bot+sinfo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261129230558.612526-10-ansuelsmth@gmail.com \
--to=ansuelsmth@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=justinstitt@google.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=llvm@lists.linux.dev \
--cc=lorenzo@kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=netdev@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=rmk+kernel@armlinux.org.uk \
--cc=robh@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox