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 08/15] net: phylink: support PCS provider release
Date: Mon, 30 Nov 2026 00:05:38 +0100 [thread overview]
Message-ID: <20261129230558.612526-9-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20261129230558.612526-1-ansuelsmth@gmail.com>
Add support for release of fwnode PCS from a PCS provider. Use a global
blocking notifier chain and subscribe each phylink instance that uses
internal PCS handling before populating its PCS list.
The PCS notifier emits FWNODE_PCS_PROVIDER_DEL after the provider is
removed from the global provider list. Phylink detaches the provider's PCS
synchronously and may call their operations during detach. Call
fwnode_pcs_del_provider() with RTNL unlocked and keep the PCS and its
hardware resources available until it returns.
Phylink uses fwnode_pcs_matches_provider() to check whether any PCS in its
list belongs to the provider being released. If so, refresh the PCS list
through fill_available_pcs() and detach PCS that are no longer available.
If the refresh fails, remove the provider's PCS directly. Track additions
and removals separately and wait for an RCU grace period after clearing
the removed PCS pointers to phylink.
When the list changes, rebuild supported_interfaces and recalculate the
link capabilities. Defer these updates until initialization finishes if the
notification arrives during phylink_create().
For optical SFPs, rebuild the usable interfaces from the module's
original interface mask and retain its EEPROM limits when recalculating
in-band capabilities. Clear stale supported modes and advertising if no
modes remain usable. If the current interface becomes unavailable,
retain supported modes for alternate interfaces. During major
configuration, check that the selected interface is usable and that
the selected PCS supports the requested in-band autonegotiation mode.
If the active PCS is removed, bring the link down if needed, stop in-band
polling, disable the PCS as needed and clear the active PCS pointer. Set
force_major_config when phylink is enabled so resolve can reconfigure the
link even if the interface mode is unchanged or the PHY link is down in
in-band mode. If an SFP link lost its PCS while the signal was down, force
reconfiguration when the signal returns.
Finally, trigger phylink resolve for an enabled instance after updating the
PCS list and capabilities.
Serialize PCS list updates and teardown with provider notifications
using pcs_list_mutex. Reuse the existing PCS ownership and state locking.
Unregister the notifier during phylink teardown and on creation failure.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/net/pcs/pcs.c | 31 +++
drivers/net/phy/phylink.c | 441 ++++++++++++++++++++++++++-----
include/linux/pcs/pcs-provider.h | 12 +
include/linux/pcs/pcs.h | 67 +++++
4 files changed, 487 insertions(+), 64 deletions(-)
diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c
index a0b3681db54b..f04888432a42 100644
--- a/drivers/net/pcs/pcs.c
+++ b/drivers/net/pcs/pcs.c
@@ -23,6 +23,19 @@ struct fwnode_pcs_provider {
static LIST_HEAD(fwnode_pcs_providers);
static DEFINE_MUTEX(fwnode_pcs_mutex);
+static BLOCKING_NOTIFIER_HEAD(fwnode_pcs_notify_list);
+
+int register_fwnode_pcs_notifier(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_register(&fwnode_pcs_notify_list, nb);
+}
+EXPORT_SYMBOL_GPL(register_fwnode_pcs_notifier);
+
+int unregister_fwnode_pcs_notifier(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_unregister(&fwnode_pcs_notify_list, nb);
+}
+EXPORT_SYMBOL_GPL(unregister_fwnode_pcs_notifier);
struct phylink_pcs *fwnode_pcs_simple_xlate(struct fwnode_reference_args *pcsspec,
void *data)
@@ -91,6 +104,11 @@ void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp)
mutex_unlock(&fwnode_pcs_mutex);
+ /* Signal phylink to release any PCS from this provider */
+ blocking_notifier_call_chain(&fwnode_pcs_notify_list,
+ FWNODE_PCS_PROVIDER_DEL,
+ pp);
+
fwnode_pcs_free_provider(pp);
}
EXPORT_SYMBOL_GPL(fwnode_pcs_del_provider);
@@ -220,6 +238,19 @@ struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode, unsigned
}
EXPORT_SYMBOL_GPL(fwnode_pcs_get);
+bool fwnode_pcs_matches_provider(struct fwnode_pcs_provider *provider,
+ const struct phylink_pcs *pcs)
+{
+ bool matches;
+
+ mutex_lock(&fwnode_pcs_mutex);
+ matches = pcs->provider == provider;
+ mutex_unlock(&fwnode_pcs_mutex);
+
+ return matches;
+}
+EXPORT_SYMBOL_GPL(fwnode_pcs_matches_provider);
+
unsigned int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode)
{
struct fwnode_reference_args out_args;
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 877a0a30ec22..6dde0eae0e73 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -11,8 +11,10 @@
#include <linux/gpio/consumer.h>
#include <linux/lockdep.h>
#include <linux/netdevice.h>
+#include <linux/notifier.h>
#include <linux/of.h>
#include <linux/of_mdio.h>
+#include <linux/pcs/pcs.h>
#include <linux/phy.h>
#include <linux/phy_fixed.h>
#include <linux/phy_link_topology.h>
@@ -41,6 +43,9 @@ enum {
PCS_STATE_DOWN = 0,
PCS_STATE_STARTING,
PCS_STATE_STARTED,
+ PCS_STATE_DETACHING,
+ PCS_STATE_INITIALIZING,
+ PCS_STATE_INIT_PENDING,
};
/**
@@ -72,6 +77,7 @@ struct phylink {
/* List of available PCS */
struct list_head pcs_list;
+ struct notifier_block fwnode_pcs_nb;
/*
* What interface are supported by the current link.
@@ -87,6 +93,8 @@ struct phylink {
struct timer_list link_poll;
struct mutex state_mutex;
+ /* Serialize PCS list updates with provider notifications */
+ struct mutex pcs_list_mutex;
/* Serialize updates to pl->phydev with phylink_resolve() */
struct mutex phydev_mutex;
struct phylink_link_state phy_state;
@@ -1084,6 +1092,24 @@ static unsigned int phylink_pcs_inband_caps(struct phylink_pcs *pcs,
return 0;
}
+static bool phylink_inband_autoneg_valid(unsigned int caps,
+ const unsigned long *adv)
+{
+ unsigned int mode;
+
+ /* If the PCS doesn't implement inband support, be permissive */
+ if (!caps)
+ return true;
+
+ if (linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, adv))
+ mode = LINK_INBAND_ENABLE;
+ else
+ mode = LINK_INBAND_DISABLE;
+
+ /* Check whether the PCS implements the required mode */
+ return caps & mode;
+}
+
static void phylink_pcs_pre_config(struct phylink_pcs *pcs,
phy_interface_t interface)
{
@@ -1504,6 +1530,19 @@ static void phylink_major_config(struct phylink *pl, bool restart,
}
}
+ /* A replacement PCS may require a different autonegotiation mode */
+ if (!pl->phydev && !phy_interface_empty(pl->sfp_module_interfaces)) {
+ unsigned int caps = phylink_pcs_inband_caps(pcs, state->interface);
+
+ if (!test_bit(state->interface, pl->sfp_interfaces) ||
+ !phylink_inband_autoneg_valid(caps, state->advertising)) {
+ phylink_err(pl, "incompatible SFP configuration for %s\n",
+ phy_modes(state->interface));
+ pl->major_config_failed = true;
+ return;
+ }
+ }
+
pcs_changed = pl->pcs != pcs;
phylink_pcs_neg_mode(pl, pcs, state->interface, state->advertising);
@@ -2183,32 +2222,6 @@ static bool phylink_add_pcs(struct phylink *pl, struct phylink_pcs *pcs)
return added;
}
-static int phylink_fill_available_pcs(struct phylink *pl,
- struct phylink_config *config)
-{
- struct phylink_pcs **pcss;
- int i, ret;
-
- if (!config->num_possible_pcs)
- return 0;
-
- pcss = kzalloc_objs(*pcss, config->num_possible_pcs);
- if (!pcss)
- return -ENOMEM;
-
- ret = config->fill_available_pcs(config, pcss, config->num_possible_pcs);
- if (ret < 0)
- goto out;
-
- for (i = 0; i < config->num_possible_pcs; i++)
- phylink_add_pcs(pl, pcss[i]);
-
-out:
- kfree(pcss);
-
- return ret;
-}
-
/**
* phylink_update_pause_state() - Update the phylink pause frame configuration
* @pl: a pointer to a &struct phylink instance
@@ -2385,35 +2398,46 @@ static void phylink_update_capabilities(struct phylink *pl,
}
/*
- * Revalidate SFP modes before generic in-band capabilities, so module
- * EEPROM limits are retained for in-band SFP configurations.
+ * Revalidate SFP modes against the current MAC and PCS interfaces
+ * before generic in-band capabilities to preserve the module's
+ * EEPROM limits. Keep the module's original interface mask so a
+ * later PCS addition can make an interface usable again.
*/
- if (pl->sfp_bus && config->interface != PHY_INTERFACE_MODE_NA &&
- !phy_interface_empty(pl->sfp_module_interfaces)) {
+ if (pl->sfp_bus && !phy_interface_empty(pl->sfp_module_interfaces)) {
__ETHTOOL_DECLARE_LINK_MODE_MASK(active_supported);
struct phylink_link_state sfp_config = *config;
__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
phy_interface_and(pl->sfp_interfaces, pl->sfp_module_interfaces,
pl->supported_interfaces);
+ linkmode_zero(pl->advertising);
+
linkmode_copy(supported, pl->sfp_support);
linkmode_copy(sfp_config.advertising, pl->sfp_support);
if (__phylink_validate_mask(pl, NULL, supported, &sfp_config,
- pl->sfp_interfaces))
- return;
-
- phylink_sfp_update_capabilities(pl, supported, &sfp_config,
- config->interface);
+ pl->sfp_interfaces)) {
+ /* No SFP modes remain usable with the current interfaces */
+ linkmode_zero(pl->supported);
+ phy_interface_zero(pl->sfp_interfaces);
+ goto exit;
+ }
/*
* Keep alternate modes available for interface selection, but
* only advertise modes that the current interface can use.
*/
+ linkmode_copy(pl->supported, supported);
+ if (!test_bit(config->interface, pl->sfp_interfaces))
+ goto exit;
+
linkmode_copy(active_supported, pl->sfp_support);
- if (__phylink_validate(pl, active_supported, &sfp_config))
- return;
+ if (__phylink_validate(pl, active_supported, &sfp_config)) {
+ __clear_bit(config->interface, pl->sfp_interfaces);
+ goto exit;
+ }
- linkmode_copy(pl->supported, supported);
+ phylink_sfp_update_capabilities(pl, pl->supported, &sfp_config,
+ config->interface);
linkmode_copy(pl->advertising, sfp_config.advertising);
goto exit;
}
@@ -2494,6 +2518,42 @@ void phylink_update_mac_pause_capabilities(struct phylink *pl, unsigned long mac
}
EXPORT_SYMBOL_GPL(phylink_update_mac_pause_capabilities);
+static void phylink_del_pcs(struct phylink *pl, struct phylink_pcs *pcs)
+{
+ ASSERT_RTNL();
+
+ lockdep_assert_held(&pl->state_mutex);
+
+ /*
+ * Check if we are removing the PCS currently
+ * in use by this phylink instance. 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) {
+ if (pl->old_link_state) {
+ phylink_link_down(pl);
+ pl->old_link_state = false;
+ }
+ if (pl->cfg_link_an_mode == MLO_AN_INBAND)
+ timer_delete_sync(&pl->link_poll);
+
+ if (pl->pcs_state != PCS_STATE_DOWN)
+ phylink_pcs_disable(pl->pcs);
+
+ if (!pl->phylink_disable_state)
+ pl->force_major_config = true;
+
+ WRITE_ONCE(pl->pcs, NULL);
+ }
+
+ mutex_lock(&phylink_pcs_ownership_mutex);
+ rcu_assign_pointer(pcs->phylink, NULL);
+ list_del(&pcs->list);
+ mutex_unlock(&phylink_pcs_ownership_mutex);
+}
+
static void phylink_parse_supported_interfaces(struct phylink *pl)
{
struct phylink_pcs *pcs;
@@ -2523,12 +2583,243 @@ static void phylink_parse_supported_interfaces(struct phylink *pl)
}
}
+static bool phylink_pcs_changed(struct phylink *pl)
+{
+ lockdep_assert_held(&pl->state_mutex);
+
+ /* Defer capability updates until creation finishes */
+ if (pl->pcs_state == PCS_STATE_INITIALIZING ||
+ pl->pcs_state == PCS_STATE_INIT_PENDING) {
+ pl->pcs_state = PCS_STATE_INIT_PENDING;
+ return false;
+ }
+
+ /* Skip forcing a major config if we are disabled */
+ if (!test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state) &&
+ (pl->force_major_config || pl->major_config_failed)) {
+ pl->force_major_config = true;
+ pl->link_failed = true;
+ }
+
+ return true;
+}
+
+static int phylink_update_pcs(struct phylink *pl, bool rescan)
+{
+ struct phylink_config *config = pl->config;
+ struct phy_device *phydev = NULL;
+ struct phylink_pcs *pcs, *tmp;
+ struct phylink_pcs **pcss;
+ unsigned int num_pcs, i;
+ bool removed = false;
+ bool added = false;
+ int ret;
+
+ lockdep_assert_held(&pl->pcs_list_mutex);
+
+ num_pcs = config->num_possible_pcs;
+ pcss = kzalloc_objs(*pcss, num_pcs);
+ if (!pcss)
+ return -ENOMEM;
+
+ ret = config->fill_available_pcs(config, pcss, num_pcs);
+ if (ret < 0) {
+ kfree(pcss);
+ return ret;
+ }
+
+ if (rescan) {
+ rtnl_lock();
+ mutex_lock(&pl->phydev_mutex);
+ phydev = pl->phydev;
+ if (phydev)
+ mutex_lock(&phydev->lock);
+ }
+ mutex_lock(&pl->state_mutex);
+
+ /* Detach unavailable PCS and clear retained PCS from the array */
+ list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
+ bool keep = false;
+
+ for (i = 0; i < num_pcs; i++) {
+ if (pcss[i] != pcs)
+ continue;
+
+ pcss[i] = NULL;
+ keep = true;
+ }
+ if (keep)
+ continue;
+
+ phylink_del_pcs(pl, pcs);
+ removed = true;
+ }
+
+ /* Wait for readers that obtained phylink through a removed PCS */
+ if (removed)
+ synchronize_rcu();
+
+ /* Attach the remaining PCS to this instance */
+ for (i = 0; i < num_pcs; i++)
+ if (phylink_add_pcs(pl, pcss[i]))
+ added = true;
+
+ if (rescan)
+ ret = (added || removed) && phylink_pcs_changed(pl);
+ if (!rescan || ret) {
+ phylink_parse_supported_interfaces(pl);
+ phylink_update_capabilities(pl, &pl->link_config);
+ }
+
+ mutex_unlock(&pl->state_mutex);
+ if (rescan) {
+ if (phydev)
+ mutex_unlock(&phydev->lock);
+ mutex_unlock(&pl->phydev_mutex);
+ rtnl_unlock();
+ }
+
+ kfree(pcss);
+
+ return ret;
+}
+
+static bool phylink_has_provider_pcs(struct phylink *pl,
+ struct fwnode_pcs_provider *provider)
+{
+ struct phylink_pcs *pcs;
+
+ lockdep_assert_held(&pl->state_mutex);
+
+ list_for_each_entry(pcs, &pl->pcs_list, list)
+ if (fwnode_pcs_matches_provider(provider, pcs))
+ return true;
+
+ return false;
+}
+
+/* Only used when refreshing the PCS list fails during provider removal */
+static bool phylink_remove_provider_pcs(struct phylink *pl,
+ struct fwnode_pcs_provider *provider)
+{
+ struct phylink_pcs *pcs, *tmp;
+ struct phy_device *phydev;
+ bool removed = false;
+ bool resolve = false;
+
+ lockdep_assert_held(&pl->pcs_list_mutex);
+
+ rtnl_lock();
+ mutex_lock(&pl->phydev_mutex);
+ phydev = pl->phydev;
+ if (phydev)
+ mutex_lock(&phydev->lock);
+ mutex_lock(&pl->state_mutex);
+
+ list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
+ if (!fwnode_pcs_matches_provider(provider, pcs))
+ continue;
+
+ phylink_del_pcs(pl, pcs);
+ removed = true;
+ }
+ if (removed) {
+ synchronize_rcu();
+ resolve = phylink_pcs_changed(pl);
+ }
+ if (resolve) {
+ phylink_parse_supported_interfaces(pl);
+ phylink_update_capabilities(pl, &pl->link_config);
+ }
+
+ mutex_unlock(&pl->state_mutex);
+ if (phydev)
+ mutex_unlock(&phydev->lock);
+ mutex_unlock(&pl->phydev_mutex);
+ rtnl_unlock();
+
+ return resolve;
+}
+
+static int pcs_provider_notify(struct notifier_block *self,
+ unsigned long val, void *data)
+{
+ struct phylink *pl = container_of(self, struct phylink, fwnode_pcs_nb);
+ struct fwnode_pcs_provider *provider = data;
+ bool resolve;
+ bool skip;
+ int ret;
+
+ if (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);
+ mutex_unlock(&pl->state_mutex);
+
+ if (skip) {
+ mutex_unlock(&pl->pcs_list_mutex);
+ return NOTIFY_DONE;
+ }
+
+ ret = phylink_update_pcs(pl, true);
+ resolve = ret > 0;
+ if (ret < 0) {
+ phylink_warn(pl, "failed to refresh available PCS: %pe\n",
+ ERR_PTR(ret));
+ /*
+ * Handle case where a PCS refresh failed and we still have to make
+ * 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);
+ }
+ mutex_unlock(&pl->pcs_list_mutex);
+
+ if (resolve)
+ phylink_run_resolve(pl);
+
+ return ret > 0 ? NOTIFY_OK : NOTIFY_DONE;
+}
+
+static void phylink_pcs_finish_init(struct phylink *pl)
+{
+ struct phy_device *phy;
+
+ /* SFP module callbacks can run once the upstream is registered */
+ if (pl->sfp_bus)
+ rtnl_lock();
+ mutex_lock(&pl->phydev_mutex);
+ phy = pl->phydev;
+ if (phy)
+ mutex_lock(&phy->lock);
+ mutex_lock(&pl->state_mutex);
+
+ if (pl->pcs_state == PCS_STATE_INIT_PENDING) {
+ phylink_parse_supported_interfaces(pl);
+ phylink_update_capabilities(pl, &pl->link_config);
+ }
+ pl->pcs_state = PCS_STATE_DOWN;
+
+ mutex_unlock(&pl->state_mutex);
+ if (phy)
+ mutex_unlock(&phy->lock);
+ mutex_unlock(&pl->phydev_mutex);
+ if (pl->sfp_bus)
+ rtnl_unlock();
+}
+
static void phylink_detach_pcss(struct phylink *pl)
{
struct phylink_pcs *pcs, *tmp;
+ mutex_lock(&pl->pcs_list_mutex);
mutex_lock(&pl->state_mutex);
+ pl->pcs_state = PCS_STATE_DETACHING;
+
mutex_lock(&phylink_pcs_ownership_mutex);
/* Remove every PCS from phylink PCS list */
list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
@@ -2550,6 +2841,11 @@ static void phylink_detach_pcss(struct phylink *pl)
synchronize_rcu();
mutex_unlock(&pl->state_mutex);
+ mutex_unlock(&pl->pcs_list_mutex);
+
+ /* Unregister notifier for late PCS attach */
+ if (pl->fwnode_pcs_nb.notifier_call)
+ unregister_fwnode_pcs_notifier(&pl->fwnode_pcs_nb);
}
/**
@@ -2604,6 +2900,7 @@ struct phylink *phylink_create(struct phylink_config *config,
return ERR_PTR(-ENOMEM);
mutex_init(&pl->phydev_mutex);
+ mutex_init(&pl->pcs_list_mutex);
mutex_init(&pl->state_mutex);
INIT_WORK(&pl->resolve, phylink_resolve);
INIT_LIST_HEAD(&pl->pcs_list);
@@ -2646,19 +2943,30 @@ struct phylink *phylink_create(struct phylink_config *config,
__set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
timer_setup(&pl->link_poll, phylink_fixed_poll, 0);
- /* Fill the PCS list with available PCS from phylink config */
- ret = phylink_fill_available_pcs(pl, config);
- if (ret < 0)
- goto free_pl;
-
- mutex_lock(&pl->state_mutex);
- phylink_parse_supported_interfaces(pl);
- phylink_update_capabilities(pl, &pl->link_config);
- mutex_unlock(&pl->state_mutex);
+ if (has_pcs_interfaces) {
+ /* Register the notifier before filling the PCS list */
+ pl->pcs_state = PCS_STATE_INITIALIZING;
+ pl->fwnode_pcs_nb.notifier_call = pcs_provider_notify;
+ register_fwnode_pcs_notifier(&pl->fwnode_pcs_nb);
+
+ mutex_lock(&pl->pcs_list_mutex);
+ ret = phylink_update_pcs(pl, false);
+ mutex_unlock(&pl->pcs_list_mutex);
+ if (ret < 0) {
+ phylink_err(pl, "failed to populate initial PCS list: %pe\n",
+ ERR_PTR(ret));
+ goto unregister_pcs_notify;
+ }
+ } else {
+ mutex_lock(&pl->state_mutex);
+ phylink_parse_supported_interfaces(pl);
+ phylink_update_capabilities(pl, &pl->link_config);
+ mutex_unlock(&pl->state_mutex);
+ }
ret = phylink_parse_mode(pl, fwnode);
if (ret < 0)
- goto unlink_pcs_list;
+ goto unregister_pcs_notify;
if (pl->cfg_link_an_mode == MLO_AN_FIXED) {
ret = phylink_parse_fixedlink(pl, fwnode);
@@ -2672,13 +2980,18 @@ struct phylink *phylink_create(struct phylink_config *config,
if (ret < 0)
goto release_link_gpio;
+ if (pl->fwnode_pcs_nb.notifier_call)
+ phylink_pcs_finish_init(pl);
+
return pl;
release_link_gpio:
if (pl->link_gpio)
gpiod_put(pl->link_gpio);
-unlink_pcs_list:
+unregister_pcs_notify:
phylink_detach_pcss(pl);
+ /* previous PCS notifier might have queued a resolve, cancel it */
+ cancel_work_sync(&pl->resolve);
free_pl:
kfree(pl);
return ERR_PTR(ret);
@@ -2702,6 +3015,7 @@ void phylink_destroy(struct phylink *pl)
gpiod_put(pl->link_gpio);
phylink_detach_pcss(pl);
+
cancel_work_sync(&pl->resolve);
kfree(pl);
@@ -3627,20 +3941,8 @@ static bool phylink_validate_pcs_inband_autoneg(struct phylink *pl,
phy_interface_t interface,
unsigned long *adv)
{
- unsigned int inband = phylink_inband_caps(pl, interface);
- unsigned int mask;
-
- /* If the PCS doesn't implement inband support, be permissive. */
- if (!inband)
- return true;
-
- if (linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, adv))
- mask = LINK_INBAND_ENABLE;
- else
- mask = LINK_INBAND_DISABLE;
-
- /* Check whether the PCS implements the required mode */
- return !!(inband & mask);
+ return phylink_inband_autoneg_valid(phylink_inband_caps(pl, interface),
+ adv);
}
/**
@@ -4632,7 +4934,18 @@ static void phylink_sfp_link_up(void *upstream)
ASSERT_RTNL();
- phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_LINK);
+ mutex_lock(&pl->state_mutex);
+ /* The PCS may have been removed while the signal was lost */
+ if (pl->phylink_disable_state == BIT(PHYLINK_DISABLE_LINK) &&
+ !pl->pcs && test_bit(pl->link_config.interface,
+ pl->config->pcs_interfaces)) {
+ pl->force_major_config = true;
+ pl->link_failed = true;
+ }
+ clear_bit(PHYLINK_DISABLE_LINK, &pl->phylink_disable_state);
+ mutex_unlock(&pl->state_mutex);
+
+ phylink_run_resolve(pl);
}
static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy)
diff --git a/include/linux/pcs/pcs-provider.h b/include/linux/pcs/pcs-provider.h
index 6b03a635f73c..2505c280946f 100644
--- a/include/linux/pcs/pcs-provider.h
+++ b/include/linux/pcs/pcs-provider.h
@@ -43,6 +43,12 @@ fwnode_pcs_add_provider(struct fwnode_handle *fwnode,
/**
* fwnode_pcs_del_provider - Removes a PCS provider
* @pp: PCS provider returned by fwnode_pcs_add_provider()
+ *
+ * Phylink detaches the provider's PCS instances synchronously and may call
+ * their operations during detach. Keep the PCS instances and the resources
+ * needed to access their hardware available until this function returns.
+ *
+ * Call without holding RTNL.
*/
void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp);
@@ -60,6 +66,12 @@ void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp);
* On driver detach, release function is invoked on the devres data,
* then, devres data is freed.
*
+ * Register the provider after acquiring all resources its PCS operations
+ * need, so devres unregisters it before releasing those resources. Devres
+ * cleanup runs after the driver's remove callback. If remove needs to make
+ * the PCS hardware inaccessible, use fwnode_pcs_add_provider() and call
+ * fwnode_pcs_del_provider() before shutting down the hardware.
+ *
* 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 b3bb158002d5..e7d1fcd65357 100644
--- a/include/linux/pcs/pcs.h
+++ b/include/linux/pcs/pcs.h
@@ -4,7 +4,42 @@
#include <linux/phylink.h>
+enum fwnode_pcs_notify_event {
+ FWNODE_PCS_PROVIDER_DEL,
+};
+
+struct fwnode_pcs_provider;
+
#if IS_ENABLED(CONFIG_FWNODE_PCS)
+/**
+ * register_fwnode_pcs_notifier - Register a notifier block for fwnode
+ * PCS events
+ * @nb: pointer to the notifier block
+ *
+ * Registers a notifier block to the fwnode_pcs_notify_list blocking
+ * notifier chain. This allows phylink instance to subscribe for
+ * PCS provider events.
+ *
+ * Call without holding RTNL.
+ *
+ * Returns: 0 or a negative error.
+ */
+int register_fwnode_pcs_notifier(struct notifier_block *nb);
+
+/**
+ * unregister_fwnode_pcs_notifier - Unregister a notifier block for fwnode
+ * PCS events
+ * @nb: pointer to the notifier block
+ *
+ * Unregisters a notifier block to the fwnode_pcs_notify_list blocking
+ * notifier chain.
+ *
+ * Call without holding RTNL.
+ *
+ * Returns: 0 or a negative error.
+ */
+int unregister_fwnode_pcs_notifier(struct notifier_block *nb);
+
/**
* fwnode_pcs_get - Retrieves a PCS from a firmware node
* @fwnode: firmware node
@@ -20,6 +55,22 @@
struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode,
unsigned int index);
+/**
+ * fwnode_pcs_matches_provider() - Check whether a PCS belongs to a provider
+ * @provider: PCS provider to check
+ * @pcs: PCS to check
+ *
+ * Check the provider recorded when the PCS was first looked up.
+ *
+ * This function is intended to be used when handling provider removal
+ * notifications, where the provider is already known and its PCS need to be
+ * identified among the PCS associated with a phylink instance.
+ *
+ * Returns: true if pcs belongs to provider, false otherwise.
+ */
+bool fwnode_pcs_matches_provider(struct fwnode_pcs_provider *provider,
+ const struct phylink_pcs *pcs);
+
/**
* fwnode_phylink_pcs_count - Count PCS entries described in firmware node
* @fwnode: firmware node
@@ -52,12 +103,28 @@ int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode,
struct phylink_pcs **available_pcs,
unsigned int num_pcs);
#else
+static inline int register_fwnode_pcs_notifier(struct notifier_block *nb)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline int unregister_fwnode_pcs_notifier(struct notifier_block *nb)
+{
+ return -EOPNOTSUPP;
+}
+
static inline struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode,
unsigned int index)
{
return ERR_PTR(-ENOENT);
}
+static inline bool fwnode_pcs_matches_provider(struct fwnode_pcs_provider *provider,
+ const struct phylink_pcs *pcs)
+{
+ return false;
+}
+
static inline unsigned int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode)
{
return 0;
--
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 ` Christian Marangi [this message]
2026-11-29 23:05 ` [PATCH net-next v23 09/15] net: phylink: support late PCS provider attach Christian Marangi
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-9-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