Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS
@ 2026-11-17 12:39 Christian Marangi
  2026-11-17 12:39 ` [PATCH net-next v22 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
                   ` (14 more replies)
  0 siblings, 15 replies; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

This series introduce a most awaited feature that is correctly
provide PCS with fwnode without having to use specific export symbol
and additional handling of PCS in phylink.

At times there were 2 different implementation (this and the one
from Sean) but Sean agreed that this can be picked and used in favor
of his implementation as long as his case with race condition is
correctly handled.

---
First the PCS fwnode:

The concept is to implement a producer-consumer API similar to other
subsystem like clock or PHY.

That seems to be the best solution to the problem as PCS driver needs
to be detached from phylink and implement a simple way to provide a
PCS while maintaining support for probe defer or driver removal.

To keep the implementation simple, the PCS driver devs needs some
collaboration to correctly implement this. This is O.K. as helper
to correctly implement this are provided hence it's really a matter
of following a pattern to correct follow removal of a PCS driver.

A PCS provider have to implement and call fwnode_pcs_add_provider() in
probe function and define an xlate function to define how the PCS
should be provided based on the requested interface and phandle spec
defined in fwnode (based on the #pcs-cells)

fwnode_pcs_get() is provided to provide a specific PCS declared in
fwnode at index.

A simple xlate function is provided for simple single PCS
implementation, fwnode_pcs_simple_xlate.

A PCS provider on driver removal must call fwnode_pcs_del_provider()
to delete itself as a provider.

---
Second PCS handling in phylink:

We have the PCS problem for the only reason that in initial
implementation, we permitted way too much flexibility to MAC driver
and things started to deviate. At times we couldn't think SoC
would start to put PCS outside the MAC hence it was OK to assume
they would live in the same driver. With the introduction of
10g in more consumer devices, we are observing a rapid growth
of this pattern with multiple PCS external to MAC.

To put a stop on this, the only solution is to give back to phylink
control on PCS handling and enforce more robust supported interface
definition from both MAC and PCS side.

It's suggested to read patch 0003 of this series for more info, here
a brief explaination of the idea:

This series introduce handling of PCS in phylink and try to deprecate
.mac_select_pcs.

Phylink now might contain a linked list of available PCS and
those will be used for PCS selection on phylink_major_config.

MAC driver needs to define pcs_interfaces mask in phylink_config
for every interface that needs a dedicated PCS.

These PCS needs to be provided to phylink at phylink_create time
by setting the .fill_available_pcs and .num_possible_pcs in phylink_config.
Helpers to parse PCS from fwnode are provided
fwnode_phylink_pcs_count() that will return the count of PCS entries
described in the firmware node and fwnode_phylink_pcs_parse() that will
fill a preallocated array of PCS pointer with the actual available PCS
(ignoring the one that still needs to be probed).

phylink_create() will fill the internal PCS list with the passed
array of PCS. phylink_major_config and other user of .mac_select_pcs
are adapted to make use of this new PCS list.

The supported interface value is also moved internally to phylink
struct. This is to handle late removal and addition of PCS.
(the bonus effect to this is giving phylink a clear idea of what
is actually supported by the MAC and his constraint with PCS)

The supported interface mask in phylink is done by OR the
supported_interfaces in phylink_config with every PCS in PCS list.

PCS removal is supported by forcing a mac_config, refresh the
supported interfaces and run a phy_resolve().

PCS late addition is supported by introducing a global notifier
for PCS provider. If a phylink have the pcs_interfaces mask not
zero, it's registered to this notifier.

PCS provider will emit a global PCS add event to signal any
interface that a new PCS might be available.

The function will then check if the PCS is related to the MAC
fwnode and add it accordingly.

A user for this new implementation is provided as an Airoha PCS
driver. This was also tested downstream with the IPQ95xx QCOM SoC
and with the help of Daniel also on the various Mediatek MT7988
SoC with both SFP cage implementation and DSA attached.

Lots of tests were done with driver unbind/bind and with interface
up/down also by adding print to make sure major_config_fail gets
correctly triggered and reset once the PCS comes back.

The dedicated commits have longer description on the implementation
so it's suggested to also check there for additional info.

It's worth to mention that OpenWrt is currently using this on
Mediatek SoC and QCOM ipq807x/ipq60xx/ipq50xx and Airoha are
already ported in staging tree for testing.

Also realtek is using this and proved to correctly work.

---
Due to the introduction of Sashiko and the introduction of
the notifier, a major reorg of the different scenario and capabilities
parsing was needed. This is to make the bot happy (in theory, but
it never is) and try to improve the state of the code by
moving the capabilitis parsing to a centralized place trying to
address all the scenario in one place.

---

Changes v22:
- Rebase on top of net-next (no idea why patchwork reported failed to apply...)
Changes v21:
- Add fixes tag for the RCU patch
- Preserve user-disabled ethtool advertising during capability
  updates and SFP interface selection.
- Add additional kconfig select for Airoha PCS and Airoha Ethernet
- Fix wrong rcu_assign_pointer NULL in RCU patch
- Use "pcs-handle-names" as already defined (instead of "pcs-names")
- Skip phylink_pcs_disable if already disabled
- Skip phylink_major_config if phylink disabled
- Better handle capabilites from phylink_parse_mode and phylink_parse_fixedlink
- Set link_failed on late attach so that resolve is triggered 2 times
- Improve description of fwnode_pcs_get_from_provider()
- Improve capabilities tracking for PHY and SFP scenario
- Add variant for __phy_get_rate_matching
Changes v20:
- Fix double declaration error in Documentation
- Drop mutex from patch 8 for validate_mac_and_pcs
- Correctly use non lock version in __phylink_validate
Changes v19:
- Rebase on top of net-next
- RCU protect phylink from pcs struct
- Fix dead-lock on phylink_validate
- Handle possible PCS provider returning NULL (protective coding)
- Improve capabilities handling refresh
Changes v18:
- Improve handling on late PCS addition
- Fix wrong comment on airoha PCS driver
- Rebase on top of net-next
Changes v17:
- Rebase on top of net-next
- Add Review tag for DT patch
- Recalculate capabilities on late removal/attach
Changes v16:
- Rebase on top of net-next
- Add Tested-by tag
- Add ACK for airoha ethernet patch + nit fix
Changes v15:
- Rebase on top of net-next
- Fix Coccicheck  warning
Changes v14:
- Fix deadlock when fill_available_pcs fails
- Move notifier and fill down after resolve disable bit is set
- Fix kconfig description
Changes v13:
- Fix regression in fwnode_pcs_get_from_pcsspec from v12
- Fix reverse lock for phy_lock and state_mutex
- Better handle lock in phylink_validate_mac_and_pcs and inband
- Fix wrong pointer to fwnode_pcs_add_provider notifier
- Fix compilation error for new C type in pcs_provider_notify
Changes v12:
- Fix kdoc for function
- Rework PCS provider add and delete to be provider driven (instead of
  relaying on scan of fwnode every time) (this also handle
  multi PCS scenario)
- Even further rework state mutex locking for concurrent pcs list
- Restore MAC supported_interfaces validation in phylink_create()
  wrongly dropped.
- Use get/put for fwnode reference
- Fix possible unment depndency for FWNODE_PCS
- Fix almost impossible problem for PCS calibration
- Hold rtnl with PCS deletion
Changes v11:
- Rework PCS release to notifier way (fix race as pointed out by bot)
- Add Ack from Lorenzo for Airoha Ethernet driver
- Introduce devm variant for pcs_provider_add
- Better support firmware node reference for PCS late attach
- Better protect list iteration with state mutex
- Minor fixup to airoha pcs driver (flow control fixup)
- Rebase on top of net-next
Changes v10:
- Minor code cleanup and fixes as suggested by bot
- Drop devlink patch
- Add reviewed by tag
- Configure old_link_state on PCS release
- Unlink PCS on error in phylink_create()
- Use list_add_tail
- Fix typo in Airoha PCS driver
- Update phylink migration guide
- Better handle late PCS attach (idempotent function and
  add unser state_mutex)
- Use dedicated lock in Airoha ethernet driver
Changes v9:
- Rebase on top of net-next/main
- Drop early verification of supported_interface
  (it can also be provided by get_capabilites MAC OP)
Changes v8:
- Back to RFC (net-next closed)
- Address additional bug reported by Sashiko bot
  - Better handle priv interface for Airoha PCS driver
  - Better handle locking for modifying the PCS list in
    phylink code
  - Improve fwnode_phylink_pcs_parse() parsing on -ENOENT
  - Better handle error condition in phylink_create()
  - Turn down the link when current PCS is released
- Fix compilation warning caused by copy paste error
Changes v7:
- Address all the bug from the Sashiko bot
- Rename .num_available_pcs to .num_possible_pcs
- Link PCS in phylink_create()
- Correctly unregister the notifier on phylink_destroy()
- Introduce fwnode_phylink_pcs_count()
- Better handle locking in phylink for PCS handling
- Better handle unavailable PCS at phylink_create() time
- Improve Documentation file
- Other minor fixes to address suggestion from bot
- Rebase on top of net-next
Changes v6:
- Rebase on top of net-next
- Add Documentation files
- Add fw_devlink patch
- Fix some comments typo
- Rework the airoha_eth.c implementation with new multi serdes code
- Extend PCS code with PCIe and USB support
- Align schema to new property
Changes v5:
- Rebase on top of net-next
- Use the new force_major_config
- Reword some comments and commit description
- Return -ENODEV instead of -EPROBE_DEFER to perevent race condition
- Drop phy_interface_copy patch (Russell pushed an equivalent version)
Changes v4:
- Move patch 0002 phy_interface_copy to 0002 (fix bisectability
  problem)
- Address review from Lorenzo for Airoha ethernet driver
- Fix kdoc error with missing Return (actually missing : before Return)
- Fix UNMET dependency reported error for CONFIG_FWNODE_PCS
- Revert to pcs.c instead of core.c (due to name conflict with other kmod)
- Fix clang compilation error for Airoha PCS driver
- Add missing inline function to pcs.h function
Changes v3:
- Out of RFC
- Fix various spelling mistake
- Drop circular dependency patch
- Complete Airoha Ethernet phylink integration
- Introduce .pcs_link_down PCS OP
Changes v2:
- Switch to fwnode
- Implement PCS provider notifier
- Better split changes
- Move supported_interfaces to phylink
- Add circular dependency patch
- Rework handling with indirect addition/removal and
  trigger of phylink_resolve()

Christian Marangi (15):
  net: phylink: make PCS phylink instance access RCU protected
  net: phylink: keep and use MAC supported_interfaces in phylink struct
  net: phylink: introduce internal phylink PCS handling
  net: pcs: implement Firmware node support for PCS driver
  net: phylink: save phylink instance fwnode on phylink_create
  net: phylink: make phylink_validate state locked
  net: phylink: add capabilities helpers and track modified advertising
  net: phylink: support PCS provider release
  net: phylink: support late PCS provider attach
  net: Document PCS subsystem
  MAINTAINERS: add myself as PCS subsystem maintainer
  net: phylink: add .pcs_link_down PCS OP
  dt-bindings: net: pcs: Document support for Airoha Ethernet PCS
  net: pcs: airoha: add PCS driver for Airoha AN7581 SoC
  net: airoha: add phylink support

 .../bindings/net/pcs/airoha,pcs.yaml          |  261 ++
 Documentation/networking/index.rst            |    1 +
 Documentation/networking/pcs.rst              |  231 ++
 Documentation/networking/sfp-phylink.rst      |   35 +-
 MAINTAINERS                                   |    9 +
 drivers/net/ethernet/airoha/Kconfig           |    2 +
 drivers/net/ethernet/airoha/airoha_eth.c      |  197 +-
 drivers/net/ethernet/airoha/airoha_eth.h      |    5 +
 drivers/net/ethernet/airoha/airoha_regs.h     |   12 +
 drivers/net/pcs/Kconfig                       |    8 +
 drivers/net/pcs/Makefile                      |    3 +
 drivers/net/pcs/airoha/Kconfig                |   17 +
 drivers/net/pcs/airoha/Makefile               |    7 +
 drivers/net/pcs/airoha/pcs-airoha-common.c    | 1309 ++++++++++
 drivers/net/pcs/airoha/pcs-airoha.h           | 1311 ++++++++++
 drivers/net/pcs/airoha/pcs-an7581.c           | 2100 +++++++++++++++++
 drivers/net/pcs/pcs.c                         |  314 +++
 drivers/net/phy/phy-internal.h                |   22 +
 drivers/net/phy/phy.c                         |   11 +-
 drivers/net/phy/phylink.c                     | 1168 ++++++---
 include/linux/pcs/pcs-provider.h              |   70 +
 include/linux/pcs/pcs.h                       |  174 ++
 include/linux/phylink.h                       |   30 +-
 23 files changed, 6994 insertions(+), 303 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml
 create mode 100644 Documentation/networking/pcs.rst
 create mode 100644 drivers/net/pcs/airoha/Kconfig
 create mode 100644 drivers/net/pcs/airoha/Makefile
 create mode 100644 drivers/net/pcs/airoha/pcs-airoha-common.c
 create mode 100644 drivers/net/pcs/airoha/pcs-airoha.h
 create mode 100644 drivers/net/pcs/airoha/pcs-an7581.c
 create mode 100644 drivers/net/pcs/pcs.c
 create mode 100644 drivers/net/phy/phy-internal.h
 create mode 100644 include/linux/pcs/pcs-provider.h
 create mode 100644 include/linux/pcs/pcs.h

-- 
2.55.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 01/15] net: phylink: make PCS phylink instance access RCU protected
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-21 23:26   ` Jakub Kicinski
  2026-11-17 12:39 ` [PATCH net-next v22 02/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
                   ` (13 subsequent siblings)
  14 siblings, 1 reply; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

In the context of phylink_pcs_change(), phylink instance is dereferenced
from the pcs pointer present in the phylink_pcs struct.

There is currently a fragility where this pcs pointer is never set NULL in
phylink_destroy() and would reference invalid memory after phylink instance
is freed.

In this scenario, if a PCS driver calls phylink_pcs_change(), invalid
memory can be dereferenced and phylink_link_changed() is called on freed
memory.

To address this, make the phylink instance saved in phylink_pcs struct RCU
protected and access it under RCU lock.

Also correctly reset the phylink instance pointer on phylink_destroy() and
syncronyze RCU to catch an execution of phylink_pcs_change().

Fixes: 24699cc1ff3e ("net: phylink: add support for PCS link change notifications")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/phy/phylink.c | 17 ++++++++++++++---
 include/linux/phylink.h   |  2 +-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index e7734e45376c..d9d0ace2042e 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -17,6 +17,7 @@
 #include <linux/phy_link_topology.h>
 #include <linux/phy_port.h>
 #include <linux/phylink.h>
+#include <linux/rcupdate.h>
 #include <linux/rtnetlink.h>
 #include <linux/spinlock.h>
 #include <linux/timer.h>
@@ -1295,10 +1296,10 @@ static void phylink_major_config(struct phylink *pl, bool restart,
 		phylink_pcs_disable(pl->pcs);
 
 		if (pl->pcs)
-			pl->pcs->phylink = NULL;
+			rcu_assign_pointer(pl->pcs->phylink, NULL);
 
 		if (pcs)
-			pcs->phylink = pl;
+			rcu_assign_pointer(pcs->phylink, pl);
 
 		pl->pcs = pcs;
 	}
@@ -2137,6 +2138,11 @@ void phylink_destroy(struct phylink *pl)
 	if (pl->link_gpio)
 		gpiod_put(pl->link_gpio);
 
+	if (pl->pcs) {
+		rcu_assign_pointer(pl->pcs->phylink, NULL);
+		synchronize_rcu();
+	}
+
 	cancel_work_sync(&pl->resolve);
 	kfree(pl);
 }
@@ -2601,10 +2607,15 @@ EXPORT_SYMBOL_GPL(phylink_mac_change);
  */
 void phylink_pcs_change(struct phylink_pcs *pcs, bool up)
 {
-	struct phylink *pl = pcs->phylink;
+	struct phylink *pl;
+
+	rcu_read_lock();
 
+	pl = rcu_dereference(pcs->phylink);
 	if (pl)
 		phylink_link_changed(pl, up, "pcs");
+
+	rcu_read_unlock();
 }
 EXPORT_SYMBOL_GPL(phylink_pcs_change);
 
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index 3a88a69882a6..4a0dc6fa8010 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -494,7 +494,7 @@ struct phylink_pcs_ops;
 struct phylink_pcs {
 	DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
 	const struct phylink_pcs_ops *ops;
-	struct phylink *phylink;
+	struct phylink __rcu *phylink;
 	bool poll;
 	bool rxc_always_on;
 };
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 02/15] net: phylink: keep and use MAC supported_interfaces in phylink struct
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
  2026-11-17 12:39 ` [PATCH net-next v22 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-17 12:39 ` [PATCH net-next v22 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

Add in phylink struct a copy of supported_interfaces from phylink_config
and make use of that instead of relying on phylink_config value.

This in preparation for support of PCS handling internally to phylink
where a PCS can be removed or added after the phylink is created and we
need both a reference of the supported_interfaces value from
phylink_config and an internal value that can be updated with the new
PCS info.

Tested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/phy/phylink.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index d9d0ace2042e..f482dc608810 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -63,6 +63,11 @@ struct phylink {
 	/* The link configuration settings */
 	struct phylink_link_state link_config;
 
+	/* What interface are supported by the current link.
+	 * Can change on removal or addition of new PCS.
+	 */
+	DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
+
 	/* The current settings */
 	phy_interface_t cur_interface;
 
@@ -633,7 +638,7 @@ static int phylink_validate_mask(struct phylink *pl, struct phy_device *phy,
 static int phylink_validate(struct phylink *pl, unsigned long *supported,
 			    struct phylink_link_state *state)
 {
-	const unsigned long *interfaces = pl->config->supported_interfaces;
+	const unsigned long *interfaces = pl->supported_interfaces;
 
 	if (state->interface == PHY_INTERFACE_MODE_NA)
 		return phylink_validate_mask(pl, NULL, supported, state,
@@ -1788,7 +1793,7 @@ static int phylink_create_sfp_cage_port(struct phylink *pl)
 	port->is_mii = true;
 	port->active = true;
 
-	phy_interface_and(port->interfaces, pl->config->supported_interfaces,
+	phy_interface_and(port->interfaces, pl->supported_interfaces,
 			  phylink_sfp_interfaces);
 	phy_port_update_supported(port);
 
@@ -2091,6 +2096,9 @@ 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);
 
+	phy_interface_copy(pl->supported_interfaces,
+			   pl->config->supported_interfaces);
+
 	linkmode_fill(pl->supported);
 	linkmode_copy(pl->link_config.advertising, pl->supported);
 	phylink_validate(pl, pl->supported, &pl->link_config);
@@ -2218,7 +2226,7 @@ static int phylink_validate_phy(struct phylink *pl, struct phy_device *phy,
 		 * those which the host supports.
 		 */
 		phy_interface_and(interfaces, phy->possible_interfaces,
-				  pl->config->supported_interfaces);
+				  pl->supported_interfaces);
 
 		if (phy_interface_empty(interfaces)) {
 			phylink_err(pl, "PHY has no common interfaces\n");
@@ -3037,12 +3045,12 @@ static phy_interface_t phylink_sfp_select_interface(struct phylink *pl,
 		return interface;
 	}
 
-	if (!test_bit(interface, pl->config->supported_interfaces)) {
+	if (!test_bit(interface, pl->supported_interfaces)) {
 		phylink_err(pl,
 			    "selection of interface failed, SFP selected %s (%u) but MAC supports %*pbl\n",
 			    phy_modes(interface), interface,
 			    (int)PHY_INTERFACE_MODE_MAX,
-			    pl->config->supported_interfaces);
+			    pl->supported_interfaces);
 		return PHY_INTERFACE_MODE_NA;
 	}
 
@@ -3921,14 +3929,14 @@ static int phylink_sfp_config_optical(struct phylink *pl)
 
 	phylink_dbg(pl, "optical SFP: interfaces=[mac=%*pbl, sfp=%*pbl]\n",
 		    (int)PHY_INTERFACE_MODE_MAX,
-		    pl->config->supported_interfaces,
+		    pl->supported_interfaces,
 		    (int)PHY_INTERFACE_MODE_MAX,
 		    pl->sfp_interfaces);
 
 	/* Find the union of the supported interfaces by the PCS/MAC and
 	 * the SFP module.
 	 */
-	phy_interface_and(pl->sfp_interfaces, pl->config->supported_interfaces,
+	phy_interface_and(pl->sfp_interfaces, pl->supported_interfaces,
 			  pl->sfp_interfaces);
 	if (phy_interface_empty(pl->sfp_interfaces)) {
 		phylink_err(pl, "unsupported SFP module: no common interface modes\n");
@@ -4166,7 +4174,7 @@ static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy)
 
 	/* Set the PHY's host supported interfaces */
 	phy_interface_and(phy->host_interfaces, phylink_sfp_interfaces,
-			  pl->config->supported_interfaces);
+			  pl->supported_interfaces);
 
 	phy_set_upstream_port(phy, pl->sfp_cage_port);
 
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 03/15] net: phylink: introduce internal phylink PCS handling
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
  2026-11-17 12:39 ` [PATCH net-next v22 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
  2026-11-17 12:39 ` [PATCH net-next v22 02/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-21 23:26   ` Jakub Kicinski
  2026-11-17 12:39 ` [PATCH net-next v22 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
                   ` (11 subsequent siblings)
  14 siblings, 1 reply; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

Introduce internal handling of PCS for phylink. This is an alternative
way to .mac_select_pcs that moves the selection logic of the PCS entirely
to phylink with the usage of the supported_interface value in the PCS
struct.

MAC should now provide a callback to fill the available PCS in
phylink_config in .fill_available_pcs and fill the .num_possible_pcs with
the number of elements in the array. MAC should also define a new bitmap,
pcs_interfaces, in phylink_config to define for what interface mode a
dedicated PCS is required.

On phylink_create(), an array of PCS pointer is allocated of size
.num_possible_pcs from phylink_config and .fill_available_pcs from
phylink_config is called passing as args the just allocated array and
the number of possible element in it.

MAC will fill this passed array with all the available PCS.

This array is then parsed and a linked list of PCS is created based on
the allocated PCS array filled by MAC via .fill_available_pcs().

Every PCS in phylink PCS list gets then linked to the phylink instance
by setting the phylink value in phylink_pcs struct to the phylink instance.
Also the supported_interface value in phylink struct is updated with
the new supported_interface from the provided PCS.

On phylink_destroy(), every PCS in phylink PCS list is unlinked from the
phylink instance by setting the phylink value in phylink_pcs struct to NULL
and removed from the PCS list.

phylink_validate_mac_and_pcs(), phylink_major_config() and
phylink_inband_caps() are updated to support this new implementation
with the PCS list stored in phylink.

They will make use of phylink_validate_pcs_interface() that will loop
for every PCS in the phylink PCS available list and find one that supports
the passed interface.

phylink_validate_pcs_interface() applies the same logic of .mac_select_pcs
where if a supported_interface value is not set for the PCS struct, then
it's assumed every interface is supported.

A MAC is required to implement either a .mac_select_pcs or make use of
the PCS list implementation. Implementing both will result in a fail
on phylink_create().

A MAC defining .num_possible_pcs in phylink_config MUST also define a
.fill_available_pcs or phylink_create() will fail with an negative error.

phylink value in phylink_pcs struct with this implementation is used to
track from PCS side when it's attached to a phylink instance. PCS driver
will make use of this information to correctly detach from a phylink
instance if needed.

phylink_pcs_change() is also changed to verify that the PCS that triggered
a link change is the one that is currently used by the phylink instance.

The .mac_select_pcs implementation is not changed but it's expected that
every MAC driver migrates to the new implementation to later deprecate
and remove .mac_select_pcs.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/phy/phylink.c | 201 ++++++++++++++++++++++++++++++++++----
 include/linux/phylink.h   |  16 +++
 2 files changed, 196 insertions(+), 21 deletions(-)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index f482dc608810..e8ba906cfba6 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -63,6 +63,9 @@ struct phylink {
 	/* The link configuration settings */
 	struct phylink_link_state link_config;
 
+	/* List of available PCS */
+	struct list_head pcs_list;
+
 	/* What interface are supported by the current link.
 	 * Can change on removal or addition of new PCS.
 	 */
@@ -522,6 +525,22 @@ static void phylink_validate_mask_caps(unsigned long *supported,
 	linkmode_and(state->advertising, state->advertising, mask);
 }
 
+static int phylink_validate_pcs_interface(struct phylink_pcs *pcs,
+					  phy_interface_t interface)
+{
+	/* If PCS define an empty supported_interfaces value, assume
+	 * all interface are supported.
+	 */
+	if (phy_interface_empty(pcs->supported_interfaces))
+		return 0;
+
+	/* Ensure that this PCS supports the interface mode */
+	if (!test_bit(interface, pcs->supported_interfaces))
+		return -EINVAL;
+
+	return 0;
+}
+
 static int phylink_validate_mac_and_pcs(struct phylink *pl,
 					unsigned long *supported,
 					struct phylink_link_state *state)
@@ -535,6 +554,21 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl,
 		pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
 		if (IS_ERR(pcs))
 			return PTR_ERR(pcs);
+	/*
+	 * Find a PCS in available PCS list for the requested interface.
+	 *
+	 * Skip searching if the MAC doesn't require a dedicated PCS for
+	 * the requested interface.
+	 */
+	} else if (test_bit(state->interface, pl->config->pcs_interfaces)) {
+		struct phylink_pcs *tmp;
+
+		list_for_each_entry(tmp, &pl->pcs_list, list) {
+			if (!phylink_validate_pcs_interface(tmp, state->interface)) {
+				pcs = tmp;
+				break;
+			}
+		}
 	}
 
 	if (pcs) {
@@ -549,13 +583,10 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl,
 			return -EINVAL;
 		}
 
-		/* Ensure that this PCS supports the interface which the MAC
-		 * returned it for. It is an error for the MAC to return a PCS
-		 * that does not support the interface mode.
-		 */
-		if (!phy_interface_empty(pcs->supported_interfaces) &&
-		    !test_bit(state->interface, pcs->supported_interfaces)) {
-			phylink_err(pl, "MAC returned PCS which does not support %s\n",
+		/* Recheck PCS to handle legacy way for .mac_select_pcs */
+		ret = phylink_validate_pcs_interface(pcs, state->interface);
+		if (ret) {
+			phylink_err(pl, "selected PCS does not support %s\n",
 				    phy_modes(state->interface));
 			return -EINVAL;
 		}
@@ -968,12 +999,22 @@ static void phylink_pcs_enable_eee(struct phylink_pcs *pcs)
 static unsigned int phylink_inband_caps(struct phylink *pl,
 					 phy_interface_t interface)
 {
-	struct phylink_pcs *pcs;
+	struct phylink_pcs *pcs = NULL;
 
-	if (!pl->mac_ops->mac_select_pcs)
-		return 0;
+	if (pl->mac_ops->mac_select_pcs) {
+		pcs = pl->mac_ops->mac_select_pcs(pl->config,
+						  interface);
+	} else if (test_bit(interface, pl->config->pcs_interfaces)) {
+		struct phylink_pcs *tmp;
+
+		list_for_each_entry(tmp, &pl->pcs_list, list) {
+			if (!phylink_validate_pcs_interface(tmp, interface)) {
+				pcs = tmp;
+				break;
+			}
+		}
+	}
 
-	pcs = pl->mac_ops->mac_select_pcs(pl->config, interface);
 	if (IS_ERR_OR_NULL(pcs))
 		return 0;
 
@@ -1270,10 +1311,36 @@ static void phylink_major_config(struct phylink *pl, bool restart,
 			pl->major_config_failed = true;
 			return;
 		}
+	/* Find a PCS in available PCS list for the requested interface.
+	 * This doesn't overwrite the previous .mac_select_pcs as either
+	 * .mac_select_pcs or PCS list implementation are permitted.
+	 *
+	 * Skip searching if the MAC doesn't require a dedicated PCS for
+	 * the requested interface.
+	 */
+	} else if (test_bit(state->interface, pl->config->pcs_interfaces)) {
+		struct phylink_pcs *tmp;
+
+		list_for_each_entry(tmp, &pl->pcs_list, list) {
+			if (!phylink_validate_pcs_interface(tmp,
+							    state->interface)) {
+				pcs = tmp;
+				break;
+			}
+		}
+
+		if (!pcs) {
+			phylink_err(pl,
+				    "couldn't find a PCS for %s\n",
+				    phy_modes(state->interface));
 
-		pcs_changed = pl->pcs != pcs;
+			pl->major_config_failed = true;
+			return;
+		}
 	}
 
+	pcs_changed = pl->pcs != pcs;
+
 	phylink_pcs_neg_mode(pl, pcs, state->interface, state->advertising);
 
 	phylink_dbg(pl, "major config, active %s/%s/%s\n",
@@ -1300,13 +1367,15 @@ static void phylink_major_config(struct phylink *pl, bool restart,
 	if (pcs_changed) {
 		phylink_pcs_disable(pl->pcs);
 
-		if (pl->pcs)
-			rcu_assign_pointer(pl->pcs->phylink, NULL);
+		if (pl->mac_ops->mac_select_pcs) {
+			if (pl->pcs)
+				rcu_assign_pointer(pl->pcs->phylink, NULL);
 
-		if (pcs)
-			rcu_assign_pointer(pcs->phylink, pl);
+			if (pcs)
+				rcu_assign_pointer(pcs->phylink, pl);
+		}
 
-		pl->pcs = pcs;
+		WRITE_ONCE(pl->pcs, pcs);
 	}
 
 	if (pl->pcs)
@@ -1901,6 +1970,49 @@ int phylink_set_fixed_link(struct phylink *pl,
 }
 EXPORT_SYMBOL_GPL(phylink_set_fixed_link);
 
+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;
+
+	if (!config->fill_available_pcs) {
+		dev_err(config->dev,
+			"phylink: error: num_possible_pcs defined but no fill_available_pcs\n");
+		return -EINVAL;
+	}
+
+	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++) {
+		struct phylink_pcs *pcs = pcss[i];
+
+		if (!pcs)
+			continue;
+
+		if (WARN(rcu_access_pointer(pcs->phylink),
+			 "%s: PCS already attached to a phylink instance\n",
+			 __func__))
+			continue;
+
+		list_add_tail(&pcs->list, &pl->pcs_list);
+	}
+
+out:
+	kfree(pcss);
+
+	return ret;
+}
+
 /**
  * phylink_update_pause_state() - Update the phylink pause frame configuration
  * @pl: a pointer to a &struct phylink instance
@@ -2042,9 +2154,20 @@ struct phylink *phylink_create(struct phylink_config *config,
 			       phy_interface_t iface,
 			       const struct phylink_mac_ops *mac_ops)
 {
+	struct phylink_pcs *tmp, *pcs;
 	struct phylink *pl;
 	int ret;
 
+	/*
+	 * Make sure either PCS internal validation or .mac_select_pcs
+	 * is used. Return error if both are defined.
+	 */
+	if (config->num_possible_pcs && mac_ops->mac_select_pcs) {
+		dev_err(config->dev,
+			"phylink: error: either phylink_config .num_possible_pcs or .mac_select_pcs must be used\n");
+		return ERR_PTR(-EINVAL);
+	}
+
 	/* Validate the supplied configuration */
 	if (phy_interface_empty(config->supported_interfaces)) {
 		dev_err(config->dev,
@@ -2059,6 +2182,7 @@ struct phylink *phylink_create(struct phylink_config *config,
 	mutex_init(&pl->phydev_mutex);
 	mutex_init(&pl->state_mutex);
 	INIT_WORK(&pl->resolve, phylink_resolve);
+	INIT_LIST_HEAD(&pl->pcs_list);
 
 	pl->config = config;
 	if (config->type == PHYLINK_NETDEV) {
@@ -2096,16 +2220,31 @@ 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;
+
+	/* Link available PCS to phylink */
+	list_for_each_entry(pcs, &pl->pcs_list, list)
+		rcu_assign_pointer(pcs->phylink, pl);
+
 	phy_interface_copy(pl->supported_interfaces,
 			   pl->config->supported_interfaces);
 
+	/* Update supported interfaces */
+	list_for_each_entry(pcs, &pl->pcs_list, list)
+		phy_interface_or(pl->supported_interfaces,
+				 pl->supported_interfaces,
+				 pcs->supported_interfaces);
+
 	linkmode_fill(pl->supported);
 	linkmode_copy(pl->link_config.advertising, pl->supported);
 	phylink_validate(pl, pl->supported, &pl->link_config);
 
 	ret = phylink_parse_mode(pl, fwnode);
 	if (ret < 0)
-		goto free_pl;
+		goto unlink_pcs_list;
 
 	if (pl->cfg_link_an_mode == MLO_AN_FIXED) {
 		ret = phylink_parse_fixedlink(pl, fwnode);
@@ -2124,6 +2263,14 @@ struct phylink *phylink_create(struct phylink_config *config,
 release_link_gpio:
 	if (pl->link_gpio)
 		gpiod_put(pl->link_gpio);
+unlink_pcs_list:
+	list_for_each_entry(pcs, &pl->pcs_list, list)
+		rcu_assign_pointer(pcs->phylink, NULL);
+
+	synchronize_rcu();
+
+	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list)
+		list_del(&pcs->list);
 free_pl:
 	kfree(pl);
 	return ERR_PTR(ret);
@@ -2141,17 +2288,29 @@ EXPORT_SYMBOL_GPL(phylink_create);
  */
 void phylink_destroy(struct phylink *pl)
 {
+	struct phylink_pcs *pcs, *tmp;
+
 	sfp_bus_del_upstream(pl->sfp_bus);
 	phylink_destroy_sfp_cage_port(pl);
 	if (pl->link_gpio)
 		gpiod_put(pl->link_gpio);
 
-	if (pl->pcs) {
+	/* Remove phylink instance from every PCS */
+	list_for_each_entry(pcs, &pl->pcs_list, list)
+		rcu_assign_pointer(pcs->phylink, NULL);
+
+	if (pl->pcs)
 		rcu_assign_pointer(pl->pcs->phylink, NULL);
+
+	if (pl->pcs || !list_empty(&pl->pcs_list))
 		synchronize_rcu();
-	}
 
 	cancel_work_sync(&pl->resolve);
+
+	/* Remove every PCS from phylink PCS list */
+	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list)
+		list_del(&pcs->list);
+
 	kfree(pl);
 }
 EXPORT_SYMBOL_GPL(phylink_destroy);
@@ -2620,7 +2779,7 @@ void phylink_pcs_change(struct phylink_pcs *pcs, bool up)
 	rcu_read_lock();
 
 	pl = rcu_dereference(pcs->phylink);
-	if (pl)
+	if (pl && READ_ONCE(pl->pcs) == pcs)
 		phylink_link_changed(pl, up, "pcs");
 
 	rcu_read_unlock();
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index 4a0dc6fa8010..418e8bec311d 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -12,6 +12,7 @@ struct ethtool_cmd;
 struct fwnode_handle;
 struct net_device;
 struct phylink;
+struct phylink_pcs;
 
 enum {
 	MLO_PAUSE_NONE,
@@ -151,6 +152,8 @@ enum phylink_op_type {
  *		     if MAC link is at %MLO_AN_FIXED mode.
  * @supported_interfaces: bitmap describing which PHY_INTERFACE_MODE_xxx
  *                        are supported by the MAC/PCS.
+ * @pcs_interfaces: bitmap describing for which PHY_INTERFACE_MODE_xxx a
+ *		    dedicated PCS is required.
  * @lpi_interfaces: bitmap describing which PHY interface modes can support
  *		    LPI signalling.
  * @mac_capabilities: MAC pause/speed/duplex capabilities.
@@ -160,6 +163,10 @@ enum phylink_op_type {
  * @wol_phy_legacy: Use Wake-on-Lan with PHY even if phy_can_wakeup() is false
  * @wol_phy_speed_ctrl: Use phy speed control on suspend/resume
  * @wol_mac_support: Bitmask of MAC supported %WAKE_* options
+ * @num_possible_pcs: num of possible phylink_pcs PCS
+ * @fill_available_pcs: callback to fill the available PCS in the passed
+ *			array struct of phylink_pcs PCS available_pcs up to
+ *			num_possible_pcs.
  */
 struct phylink_config {
 	struct device *dev;
@@ -172,6 +179,7 @@ struct phylink_config {
 	void (*get_fixed_state)(struct phylink_config *config,
 				struct phylink_link_state *state);
 	DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
+	DECLARE_PHY_INTERFACE_MASK(pcs_interfaces);
 	DECLARE_PHY_INTERFACE_MASK(lpi_interfaces);
 	unsigned long mac_capabilities;
 	unsigned long lpi_capabilities;
@@ -182,6 +190,11 @@ struct phylink_config {
 	bool wol_phy_legacy;
 	bool wol_phy_speed_ctrl;
 	u32 wol_mac_support;
+
+	unsigned int num_possible_pcs;
+	int (*fill_available_pcs)(struct phylink_config *config,
+				  struct phylink_pcs **available_pcs,
+				  unsigned int num_possible_pcs);
 };
 
 void phylink_limit_mac_speed(struct phylink_config *config, u32 max_speed);
@@ -497,6 +510,9 @@ struct phylink_pcs {
 	struct phylink __rcu *phylink;
 	bool poll;
 	bool rxc_always_on;
+
+	/* private: */
+	struct list_head list;
 };
 
 /**
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 04/15] net: pcs: implement Firmware node support for PCS driver
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
                   ` (2 preceding siblings ...)
  2026-11-17 12:39 ` [PATCH net-next v22 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-17 12:39 ` [PATCH net-next v22 05/15] net: phylink: save phylink instance fwnode on phylink_create Christian Marangi
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm
  Cc: Daniel Golle

Implement the foundation of Firmware node support for PCS driver.

To support this, implement a simple Provider API where a PCS driver can
expose multiple PCS with an xlate .fwnode_xlate function.

PCS driver will have to call fwnode_pcs_add_provider() and pass the
firmware node pointer and a xlate function to return the correct PCS for
the passed #pcs-cells.

This will register the PCS in a global list of providers so that
consumer can access it.

The consumer will then use fwnode_pcs_get() to get the actual PCS by
passing the firmware node pointer and the index for #pcs-cells.

For a simple implementation where #pcs-cells is 0 and the PCS driver
expose a single PCS, the xlate function fwnode_pcs_simple_xlate() is
provided.

For an advanced implementation a custom xlate function is required.

On removal the PCS driver must delete itself from the provider list
using fwnode_pcs_del_provider().

A devm variant devm_fwnode_pcs_add() is provided to automate the release
procedure.

Generic functions fwnode_phylink_pcs_count() and fwnode_phylink_pcs_parse()
are provided for MAC driver that will declare PCS in DT (or ACPI).

Function fwnode_phylink_pcs_count() will parse "pcs-handle" property and
will return the number of PCS entries described in the passed firmware
node.

Function fwnode_phylink_pcs_parse() will parse "pcs-handle" property and
fill the passed available_pcs array with the available PCS found up to
passed num_pcs value. It's worth to mention that this function will ignore
PCS that still needs to be probed (returning -ENODEV) and such PCS won't be
added to the available_pcs array.

Co-developed-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/pcs/Kconfig          |   6 +
 drivers/net/pcs/Makefile         |   1 +
 drivers/net/pcs/pcs.c            | 245 +++++++++++++++++++++++++++++++
 include/linux/pcs/pcs-provider.h |  70 +++++++++
 include/linux/pcs/pcs.h          |  74 ++++++++++
 5 files changed, 396 insertions(+)
 create mode 100644 drivers/net/pcs/pcs.c
 create mode 100644 include/linux/pcs/pcs-provider.h
 create mode 100644 include/linux/pcs/pcs.h

diff --git a/drivers/net/pcs/Kconfig b/drivers/net/pcs/Kconfig
index 108d47257bee..3d4d81c8e098 100644
--- a/drivers/net/pcs/Kconfig
+++ b/drivers/net/pcs/Kconfig
@@ -5,6 +5,12 @@
 
 menu "PCS device drivers"
 
+config FWNODE_PCS
+	bool "PCS Firmware Node"
+	depends on ACPI || OF || COMPILE_TEST
+	help
+	  Firmware node PCS accessors
+
 config PCS_XPCS
 	tristate "Synopsys DesignWare Ethernet XPCS"
 	select PHYLINK
diff --git a/drivers/net/pcs/Makefile b/drivers/net/pcs/Makefile
index f9f6cf2578d7..53ba1d560f69 100644
--- a/drivers/net/pcs/Makefile
+++ b/drivers/net/pcs/Makefile
@@ -3,6 +3,7 @@
 
 pcs_xpcs-$(CONFIG_PCS_XPCS)	:= pcs-xpcs.o pcs-xpcs-nxp.o pcs-xpcs-wx.o
 
+obj-$(CONFIG_FWNODE_PCS)	+= pcs.o
 obj-$(CONFIG_PCS_XPCS)		+= pcs_xpcs.o
 obj-$(CONFIG_PCS_XPCS_PLATFORM) += pcs-xpcs-plat.o
 obj-$(CONFIG_PCS_XPCS_ROCKCHIP) += pcs-xpcs-rk.o
diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c
new file mode 100644
index 000000000000..b1d48f6eee7f
--- /dev/null
+++ b/drivers/net/pcs/pcs.c
@@ -0,0 +1,245 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/mutex.h>
+#include <linux/property.h>
+#include <linux/phylink.h>
+#include <linux/pcs/pcs.h>
+#include <linux/pcs/pcs-provider.h>
+
+MODULE_DESCRIPTION("PCS library");
+MODULE_AUTHOR("Christian Marangi <ansuelsmth@gmail.com>");
+MODULE_LICENSE("GPL");
+
+struct fwnode_pcs_provider {
+	struct list_head link;
+
+	struct fwnode_handle *fwnode;
+	struct phylink_pcs *(*fwnode_xlate)(struct fwnode_reference_args *pcsspec,
+					    void *data);
+
+	void *data;
+};
+
+static LIST_HEAD(fwnode_pcs_providers);
+static DEFINE_MUTEX(fwnode_pcs_mutex);
+
+struct phylink_pcs *fwnode_pcs_simple_xlate(struct fwnode_reference_args *pcsspec,
+					    void *data)
+{
+	return data;
+}
+EXPORT_SYMBOL_GPL(fwnode_pcs_simple_xlate);
+
+struct fwnode_pcs_provider *
+fwnode_pcs_add_provider(struct fwnode_handle *fwnode,
+			struct phylink_pcs *(*fwnode_xlate)(struct fwnode_reference_args *pcsspec,
+							    void *data),
+			void *data)
+{
+	struct fwnode_pcs_provider *pp;
+
+	if (!fwnode)
+		return ERR_PTR(-EINVAL);
+
+	pp = kzalloc_obj(*pp);
+	if (!pp)
+		return ERR_PTR(-ENOMEM);
+
+	pp->fwnode = fwnode_handle_get(fwnode);
+	pp->data = data;
+	pp->fwnode_xlate = fwnode_xlate;
+
+	mutex_lock(&fwnode_pcs_mutex);
+
+	list_add(&pp->link, &fwnode_pcs_providers);
+	fwnode_dev_initialized(fwnode, true);
+
+	mutex_unlock(&fwnode_pcs_mutex);
+
+	pr_debug("Added pcs provider from %pfwf\n", fwnode);
+
+	return pp;
+}
+EXPORT_SYMBOL_GPL(fwnode_pcs_add_provider);
+
+void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp)
+{
+	if (IS_ERR_OR_NULL(pp))
+		return;
+
+	mutex_lock(&fwnode_pcs_mutex);
+
+	list_del(&pp->link);
+	fwnode_dev_initialized(pp->fwnode, false);
+
+	mutex_unlock(&fwnode_pcs_mutex);
+
+	fwnode_handle_put(pp->fwnode);
+	kfree(pp);
+}
+EXPORT_SYMBOL_GPL(fwnode_pcs_del_provider);
+
+static void devm_fwnode_pcs_del(struct device *dev, void *res)
+{
+	struct fwnode_pcs_provider *pp = *(struct fwnode_pcs_provider **)res;
+
+	fwnode_pcs_del_provider(pp);
+}
+
+struct fwnode_pcs_provider *
+devm_fwnode_pcs_add_provider(struct device *dev, struct fwnode_handle *fwnode,
+			     struct phylink_pcs *(*fwnode_xlate)(struct fwnode_reference_args *pcsspec,
+								 void *data),
+			     void *data)
+{
+	struct fwnode_pcs_provider **ptr, *pp;
+
+	ptr = devres_alloc(devm_fwnode_pcs_del, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return ERR_PTR(-ENOMEM);
+
+	pp = fwnode_pcs_add_provider(fwnode, fwnode_xlate, data);
+
+	if (!IS_ERR(pp)) {
+		*ptr = pp;
+		devres_add(dev, ptr);
+	} else {
+		devres_free(ptr);
+	}
+
+	return pp;
+}
+EXPORT_SYMBOL_GPL(devm_fwnode_pcs_add_provider);
+
+static int fwnode_parse_pcsspec(const struct fwnode_handle *fwnode,
+				int index, const char *name,
+				struct fwnode_reference_args *out_args)
+{
+	if (!fwnode)
+		return -EINVAL;
+
+	if (name) {
+		index = fwnode_property_match_string(fwnode, "pcs-handle-names",
+						     name);
+		if (index < 0)
+			return index;
+	}
+
+	return fwnode_property_get_reference_args(fwnode, "pcs-handle",
+						  "#pcs-cells", 0, index,
+						  out_args);
+}
+
+static struct phylink_pcs *
+__fwnode_pcs_get_from_pcsspec_provider(struct fwnode_reference_args *pcsspec,
+				       struct fwnode_pcs_provider *provider)
+{
+	if (provider->fwnode != pcsspec->fwnode)
+		return ERR_PTR(-EINVAL);
+
+	return provider->fwnode_xlate(pcsspec, provider->data);
+}
+
+static struct phylink_pcs *
+fwnode_pcs_get_from_pcsspec(struct fwnode_reference_args *pcsspec)
+{
+	struct fwnode_pcs_provider *provider;
+	struct phylink_pcs *pcs = NULL;
+
+	if (!pcsspec)
+		return ERR_PTR(-EINVAL);
+
+	mutex_lock(&fwnode_pcs_mutex);
+	list_for_each_entry(provider, &fwnode_pcs_providers, link) {
+		pcs = __fwnode_pcs_get_from_pcsspec_provider(pcsspec, provider);
+		if (!IS_ERR(pcs))
+			break;
+	}
+	mutex_unlock(&fwnode_pcs_mutex);
+
+	return !IS_ERR_OR_NULL(pcs) ? pcs : ERR_PTR(-ENODEV);
+}
+
+static struct phylink_pcs *__fwnode_pcs_get(const struct fwnode_handle *fwnode,
+					    unsigned int index, const char *con_id)
+{
+	struct fwnode_reference_args pcsspec;
+	struct phylink_pcs *pcs;
+	int ret;
+
+	ret = fwnode_parse_pcsspec(fwnode, index, con_id, &pcsspec);
+	if (ret)
+		return ERR_PTR(ret);
+
+	pcs = fwnode_pcs_get_from_pcsspec(&pcsspec);
+	fwnode_handle_put(pcsspec.fwnode);
+
+	return pcs;
+}
+
+struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode, unsigned int index)
+{
+	return __fwnode_pcs_get(fwnode, index, NULL);
+}
+EXPORT_SYMBOL_GPL(fwnode_pcs_get);
+
+unsigned int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode)
+{
+	struct fwnode_reference_args out_args;
+	int index = 0;
+	int ret;
+
+	while (true) {
+		ret = fwnode_property_get_reference_args(fwnode, "pcs-handle",
+							 "#pcs-cells", 0, index,
+							 &out_args);
+		/* We expect to reach an -ENOENT error while counting */
+		if (ret)
+			break;
+
+		fwnode_handle_put(out_args.fwnode);
+		index++;
+	}
+
+	return index;
+}
+EXPORT_SYMBOL_GPL(fwnode_phylink_pcs_count);
+
+int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode,
+			     struct phylink_pcs **available_pcs,
+			     unsigned int num_pcs)
+{
+	unsigned int i, found = 0;
+
+	if (!available_pcs)
+		return -EINVAL;
+
+	if (!fwnode_property_present(fwnode, "pcs-handle"))
+		return -ENODEV;
+
+	for (i = 0; i < num_pcs; i++) {
+		struct phylink_pcs *pcs;
+
+		pcs = fwnode_pcs_get(fwnode, i);
+		if (IS_ERR(pcs)) {
+			/* Exit early if no PCS remain.*/
+			if (PTR_ERR(pcs) == -ENOENT)
+				break;
+
+			/*
+			 * Ignore -ENODEV error for PCS that still
+			 * needs to probe.
+			 */
+			if (PTR_ERR(pcs) == -ENODEV)
+				continue;
+
+			return PTR_ERR(pcs);
+		}
+
+		available_pcs[found] = pcs;
+		found++;
+	}
+
+	return found;
+}
+EXPORT_SYMBOL_GPL(fwnode_phylink_pcs_parse);
diff --git a/include/linux/pcs/pcs-provider.h b/include/linux/pcs/pcs-provider.h
new file mode 100644
index 000000000000..15c198ffdd58
--- /dev/null
+++ b/include/linux/pcs/pcs-provider.h
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef __LINUX_PCS_PROVIDER_H
+#define __LINUX_PCS_PROVIDER_H
+
+struct fwnode_pcs_provider;
+
+/**
+ * fwnode_pcs_simple_xlate - Simple xlate function to retrieve PCS
+ * @pcsspec: reference arguments
+ * @data: Context data (assumed assigned to the single PCS)
+ *
+ * Returns: the PCS pointed by data.
+ */
+struct phylink_pcs *fwnode_pcs_simple_xlate(struct fwnode_reference_args *pcsspec,
+					    void *data);
+
+/**
+ * fwnode_pcs_add_provider - Registers a new PCS provider
+ * @fwnode: Firmware node
+ * @fwnode_xlate: xlate function to retrieve the PCS
+ * @data: Context data
+ *
+ * Register and add a new PCS provider to the global providers list
+ * for the firmware node. The relevant PCS from the PCS provider
+ * is retrieved from the passed fwnode_xlate function.
+ *
+ * The xlate function MUST return a pointer to an existing, already-allocated
+ * struct phylink_pcs and MUST NOT dynamically allocate a new PCS.
+ * The same PCS object must be returned for a given firmware reference and args,
+ * as PCS pointer identity is used to associate PCS objects with their provider.
+ *
+ * Returns: A pointer to the registered PCS provider on success, or
+ * an ERR_PTR() encoded error code on failure.
+ */
+struct fwnode_pcs_provider *
+fwnode_pcs_add_provider(struct fwnode_handle *fwnode,
+			struct phylink_pcs *(*fwnode_xlate)(struct fwnode_reference_args *pcsspec,
+							    void *data),
+			void *data);
+
+/**
+ * fwnode_pcs_del_provider - Removes a PCS provider
+ * @pp: PCS provider returned by fwnode_pcs_add_provider()
+ */
+void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp);
+
+/**
+ * devm_fwnode_pcs_add_provider - Registers a new PCS provider
+ * @dev: Device of the PCS provider
+ * @fwnode: Firmware node
+ * @fwnode_xlate: xlate function to retrieve the PCS
+ * @data: Context data
+ *
+ * Register and add a new PCS provider to the global providers list
+ * for the firmware node. The relevant PCS from the PCS provider
+ * is retrieved from the passed fwnode_xlate function. While at that, it
+ * also associates the device with the PCS provider using devres.
+ * On driver detach, release function is invoked on the devres data,
+ * then, devres data is freed.
+ *
+ * Returns: A pointer to the registered PCS provider on success, or
+ * an ERR_PTR() encoded error code on failure.
+ */
+struct fwnode_pcs_provider *
+devm_fwnode_pcs_add_provider(struct device *dev, struct fwnode_handle *fwnode,
+			     struct phylink_pcs *(*fwnode_xlate)(struct fwnode_reference_args *pcsspec,
+								 void *data),
+			     void *data);
+
+#endif /* __LINUX_PCS_PROVIDER_H */
diff --git a/include/linux/pcs/pcs.h b/include/linux/pcs/pcs.h
new file mode 100644
index 000000000000..ef2134c578c7
--- /dev/null
+++ b/include/linux/pcs/pcs.h
@@ -0,0 +1,74 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef __LINUX_PCS_H
+#define __LINUX_PCS_H
+
+#include <linux/phylink.h>
+
+#if IS_ENABLED(CONFIG_FWNODE_PCS)
+/**
+ * fwnode_pcs_get - Retrieves a PCS from a firmware node
+ * @fwnode: firmware node
+ * @index: index fwnode PCS handle in firmware node
+ *
+ * Get a PCS from the firmware node at index.
+ *
+ * Returns: a pointer to the phylink_pcs or a negative error pointer. Can
+ * return -ENODEV if the PCS is not present in global providers list (either
+ * due to driver still needs to be probed or it failed to probe/removed).
+ */
+struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode,
+				   unsigned int index);
+
+/**
+ * fwnode_phylink_pcs_count - Count PCS entries described in firmware node
+ * @fwnode: firmware node
+ *
+ * Helper function to count the number of PCS entries referenced by the
+ * "pcs-handle" property in a firmware node.
+ *
+ * Note that this function counts all PCS references in the firmware node,
+ * regardless of whether the corresponding PCS devices are already probed.
+ *
+ * Returns: number of PCS entries described in the firmware node.
+ */
+unsigned int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode);
+
+/**
+ * fwnode_phylink_pcs_parse - Parse available PCS from firmware node
+ * @fwnode: firmware node
+ * @available_pcs: pointer to preallocated array of PCS
+ * @num_pcs: maximum number of PCS entries to scan
+ *
+ * Helper function that parses PCS references from the "pcs-handle"
+ * property of a firmware node and fills @available_pcs with PCS that are
+ * currently available up to @num_pcs.
+ *
+ * Only PCS that are currently available are stored in @available_pcs.
+ * PCS that returns -ENODEV are skipped.
+ *
+ * Returns: number of PCS stored in @available_pcs, or negative error code.
+ */
+int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode,
+			     struct phylink_pcs **available_pcs,
+			     unsigned int num_pcs);
+#else
+static inline struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode,
+						 unsigned int index)
+{
+	return ERR_PTR(-ENOENT);
+}
+
+static inline unsigned int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode)
+{
+	return 0;
+}
+
+static inline int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode,
+					   struct phylink_pcs **available_pcs,
+					   unsigned int num_pcs)
+{
+	return -EOPNOTSUPP;
+}
+#endif
+
+#endif /* __LINUX_PCS_H */
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 05/15] net: phylink: save phylink instance fwnode on phylink_create
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
                   ` (3 preceding siblings ...)
  2026-11-17 12:39 ` [PATCH net-next v22 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-17 12:39 ` [PATCH net-next v22 06/15] net: phylink: make phylink_validate state locked Christian Marangi
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

The firmware node associated with the phylink instance might differ from
the device firmware node passed in phylink_config as such device can
reference the parent switch or other platform peripherals.

Some function might need to reference this firmware node after
phylink_create so add a dedicated fwnode entry in phylink internal struct
and save it on phylink_create().

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/phy/phylink.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index e8ba906cfba6..091c3a79c120 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -47,6 +47,7 @@ struct phylink {
 	const struct phylink_mac_ops *mac_ops;
 	struct phylink_config *config;
 	struct phylink_pcs *pcs;
+	struct fwnode_handle *fwnode;
 	struct device *dev;
 	unsigned int old_link_state:1;
 
@@ -2185,6 +2186,7 @@ struct phylink *phylink_create(struct phylink_config *config,
 	INIT_LIST_HEAD(&pl->pcs_list);
 
 	pl->config = config;
+	pl->fwnode = fwnode_handle_get((struct fwnode_handle *)fwnode);
 	if (config->type == PHYLINK_NETDEV) {
 		pl->netdev = to_net_dev(config->dev);
 		netif_carrier_off(pl->netdev);
@@ -2272,6 +2274,7 @@ struct phylink *phylink_create(struct phylink_config *config,
 	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list)
 		list_del(&pcs->list);
 free_pl:
+	fwnode_handle_put(pl->fwnode);
 	kfree(pl);
 	return ERR_PTR(ret);
 }
@@ -2311,6 +2314,8 @@ void phylink_destroy(struct phylink *pl)
 	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list)
 		list_del(&pcs->list);
 
+	fwnode_handle_put(pl->fwnode);
+
 	kfree(pl);
 }
 EXPORT_SYMBOL_GPL(phylink_destroy);
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 06/15] net: phylink: make phylink_validate state locked
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
                   ` (4 preceding siblings ...)
  2026-11-17 12:39 ` [PATCH net-next v22 05/15] net: phylink: save phylink instance fwnode on phylink_create Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-17 12:39 ` [PATCH net-next v22 07/15] net: phylink: add capabilities helpers and track modified advertising Christian Marangi
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

In preparation for support for PCS release/late attach, rework the
phylink_validate functions to be locked under the state mutex.

With the introduction of a notifier that can be called concurrently while a
phylink_create is called or an interface mode validation is being run, on
recalculating the supported interface and capabilities, an inconsistency
can be introduced with 2 validation run at the same time.

To handle this, make the phylink_validate lock under the phylink state
mutex, add lockless variant for phylink_validate_mask and phylink_validate
and add lockdep check to make sure the mutex is held in the inner
validate functions.

Function that already run phylink_validate under state mutex, are updated
to use the lockless variant.

Special care was needed for phy_get_rate_matching that required a lockless
variant. This is introduced by adding an internal phy header.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/phy/phy-internal.h | 22 ++++++++++++
 drivers/net/phy/phy.c          | 11 +++---
 drivers/net/phy/phylink.c      | 62 ++++++++++++++++++++++++++++------
 3 files changed, 79 insertions(+), 16 deletions(-)
 create mode 100644 drivers/net/phy/phy-internal.h

diff --git a/drivers/net/phy/phy-internal.h b/drivers/net/phy/phy-internal.h
new file mode 100644
index 000000000000..56d87495e1f0
--- /dev/null
+++ b/drivers/net/phy/phy-internal.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __PHY_INTERNAL_H
+#define __PHY_INTERNAL_H
+
+#include <linux/lockdep.h>
+#include <linux/phy.h>
+
+static inline int __phy_get_rate_matching(struct phy_device *phydev,
+					  phy_interface_t iface)
+{
+	int ret = RATE_MATCH_NONE;
+
+	lockdep_assert_held(&phydev->lock);
+
+	if (phydev->drv->get_rate_matching)
+		return phydev->drv->get_rate_matching(phydev, iface);
+
+	return ret;
+}
+
+#endif /* __PHY_INTERNAL_H */
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index fce9bc7be330..e305bbff16ad 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -38,6 +38,7 @@
 
 #include "phylib-internal.h"
 #include "phy-caps.h"
+#include "phy-internal.h"
 
 #define PHY_STATE_TIME	HZ
 
@@ -146,13 +147,11 @@ EXPORT_SYMBOL(phy_print_status);
 int phy_get_rate_matching(struct phy_device *phydev,
 			  phy_interface_t iface)
 {
-	int ret = RATE_MATCH_NONE;
+	int ret;
 
-	if (phydev->drv->get_rate_matching) {
-		mutex_lock(&phydev->lock);
-		ret = phydev->drv->get_rate_matching(phydev, iface);
-		mutex_unlock(&phydev->lock);
-	}
+	mutex_lock(&phydev->lock);
+	ret = __phy_get_rate_matching(phydev, iface);
+	mutex_unlock(&phydev->lock);
 
 	return ret;
 }
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 091c3a79c120..88280866c19a 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -9,6 +9,7 @@
 #include <linux/ethtool.h>
 #include <linux/export.h>
 #include <linux/gpio/consumer.h>
+#include <linux/lockdep.h>
 #include <linux/netdevice.h>
 #include <linux/of.h>
 #include <linux/of_mdio.h>
@@ -24,6 +25,7 @@
 #include <linux/workqueue.h>
 
 #include "phy-caps.h"
+#include "phy-internal.h"
 #include "sfp.h"
 #include "swphy.h"
 
@@ -550,6 +552,8 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl,
 	unsigned long capabilities;
 	int ret;
 
+	lockdep_assert_held(&pl->state_mutex);
+
 	/* Get the PCS for this interface mode */
 	if (pl->mac_ops->mac_select_pcs) {
 		pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
@@ -628,13 +632,15 @@ static void phylink_validate_one(struct phylink *pl, struct phy_device *phy,
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(tmp_supported);
 	struct phylink_link_state tmp_state;
 
+	lockdep_assert_held(&pl->state_mutex);
+
 	linkmode_copy(tmp_supported, supported);
 
 	tmp_state = *state;
 	tmp_state.interface = interface;
 
 	if (phy)
-		tmp_state.rate_matching = phy_get_rate_matching(phy, interface);
+		tmp_state.rate_matching = __phy_get_rate_matching(phy, interface);
 
 	if (!phylink_validate_mac_and_pcs(pl, tmp_supported, &tmp_state)) {
 		phylink_dbg(pl, " interface %u (%s) rate match %s supports %*pbl\n",
@@ -648,15 +654,17 @@ static void phylink_validate_one(struct phylink *pl, struct phy_device *phy,
 	}
 }
 
-static int phylink_validate_mask(struct phylink *pl, struct phy_device *phy,
-				 unsigned long *supported,
-				 struct phylink_link_state *state,
-				 const unsigned long *interfaces)
+static int __phylink_validate_mask(struct phylink *pl, struct phy_device *phy,
+				   unsigned long *supported,
+				   struct phylink_link_state *state,
+				   const unsigned long *interfaces)
 {
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(all_adv) = { 0, };
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(all_s) = { 0, };
 	int interface;
 
+	lockdep_assert_held(&pl->state_mutex);
+
 	for_each_set_bit(interface, interfaces, PHY_INTERFACE_MODE_MAX)
 		phylink_validate_one(pl, phy, supported, state, interface,
 				     all_s, all_adv);
@@ -667,14 +675,36 @@ static int phylink_validate_mask(struct phylink *pl, struct phy_device *phy,
 	return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
 }
 
-static int phylink_validate(struct phylink *pl, unsigned long *supported,
-			    struct phylink_link_state *state)
+static int phylink_validate_mask(struct phylink *pl, struct phy_device *phy,
+				 unsigned long *supported,
+				 struct phylink_link_state *state,
+				 const unsigned long *interfaces)
+{
+	int ret;
+
+	if (phy)
+		mutex_lock(&phy->lock);
+
+	mutex_lock(&pl->state_mutex);
+	ret = __phylink_validate_mask(pl, phy, supported, state, interfaces);
+	mutex_unlock(&pl->state_mutex);
+
+	if (phy)
+		mutex_unlock(&phy->lock);
+
+	return ret;
+}
+
+static int __phylink_validate(struct phylink *pl, unsigned long *supported,
+			      struct phylink_link_state *state)
 {
 	const unsigned long *interfaces = pl->supported_interfaces;
 
+	lockdep_assert_held(&pl->state_mutex);
+
 	if (state->interface == PHY_INTERFACE_MODE_NA)
-		return phylink_validate_mask(pl, NULL, supported, state,
-					     interfaces);
+		return __phylink_validate_mask(pl, NULL, supported, state,
+					       interfaces);
 
 	if (!test_bit(state->interface, interfaces))
 		return -EINVAL;
@@ -682,6 +712,18 @@ static int phylink_validate(struct phylink *pl, unsigned long *supported,
 	return phylink_validate_mac_and_pcs(pl, supported, state);
 }
 
+static int phylink_validate(struct phylink *pl, unsigned long *supported,
+			    struct phylink_link_state *state)
+{
+	int ret;
+
+	mutex_lock(&pl->state_mutex);
+	ret = __phylink_validate(pl, supported, state);
+	mutex_unlock(&pl->state_mutex);
+
+	return ret;
+}
+
 static void phylink_fill_fixedlink_supported(unsigned long *supported)
 {
 	linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, supported);
@@ -2117,7 +2159,7 @@ void phylink_update_mac_pause_capabilities(struct phylink *pl, unsigned long mac
 	else if (pl->sfp_bus)
 		linkmode_and(pl->supported, pl->supported, pl->sfp_support);
 
-	phylink_validate(pl, pl->supported, config);
+	__phylink_validate(pl, pl->supported, config);
 
 	pause_state = config->pause;
 
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 07/15] net: phylink: add capabilities helpers and track modified advertising
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
                   ` (5 preceding siblings ...)
  2026-11-17 12:39 ` [PATCH net-next v22 06/15] net: phylink: make phylink_validate state locked Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-21 23:26   ` Jakub Kicinski
  2026-11-17 12:39 ` [PATCH net-next v22 08/15] net: phylink: support PCS provider release Christian Marangi
                   ` (7 subsequent siblings)
  14 siblings, 1 reply; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

In preparation for PCS release/late attach, it's needed to introduce a
helpers to calculate the capabilities after a PCS is removed/added and it's
needed to track the advertising in link_config changed by the user compared
to the originally one calculated in phylink_create().

To archieve this, introduce dedicated advertising variables in phylink
struct and update it when the new phylink_update_capabilities() is called
or advertise is updated in link_config.

In phylink struct the new advertising will contain the full advertising
bits right after a phylink_validate and the new user_disabled_advertising
will be the mask of modes that were disabled from an ethtool ksettings
(with the parsing done in phylink_update_user_disabled_advertising()).

This double reference is needed to account case when a PCS gets removed and
attached again to preserve user-defined advertising rules.

phylink_update_capabilities() will calculate the new supported modes and
the new capabilities, update the full advertising in phylink and restore
the user-disabled modes.

phylink_create() is also updated to init the phylink advertising and
link_config advertising.

phylink_update_mac_pause_capabilities() is updated to use the new
phylink_update_capabilities() to account for user-disabled advertising
modes and update the full advertising in phylink.

Some rework were needed in the context of fixed-link, In-Band, PHY and SFP
to permit detaching the supported and link_config advertising parsing
outside the original config.

SFP logic is changed to not restrict the sfp_support mask in place but
instead propagate the restricted mask to phylink_sfp_set_config()
similar to how it's done for the PHY codepath.
This is needed to always have an unmodified source to reparse the
capabilities.

PHY advertising is changed to save the original advertising before
restricting it.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/phy/phylink.c | 607 +++++++++++++++++++++++++-------------
 1 file changed, 397 insertions(+), 210 deletions(-)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 88280866c19a..921c227a5b3c 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -62,6 +62,8 @@ struct phylink {
 	u8 link_port;			/* The current non-phy ethtool port */
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported_lpi);
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(user_disabled_advertising);
 
 	/* The link configuration settings */
 	struct phylink_link_state link_config;
@@ -85,6 +87,8 @@ struct phylink {
 	/* Serialize updates to pl->phydev with phylink_resolve() */
 	struct mutex phydev_mutex;
 	struct phylink_link_state phy_state;
+	/* PHY advertisement before restricting it to MAC/PCS capabilities */
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(phy_advertising);
 	unsigned int phy_ib_mode;
 	struct work_struct resolve;
 	unsigned int pcs_neg_mode;
@@ -724,6 +728,79 @@ static int phylink_validate(struct phylink *pl, unsigned long *supported,
 	return ret;
 }
 
+static int __phylink_validate_phy(struct phylink *pl, struct phy_device *phy,
+				  unsigned long *supported,
+				  struct phylink_link_state *state)
+{
+	DECLARE_PHY_INTERFACE_MASK(interfaces);
+
+	/* If the PHY provides a bitmap of the interfaces it will be using
+	 * depending on the negotiated media speeds, use this to validate
+	 * which ethtool link modes can be used.
+	 */
+	if (!phy_interface_empty(phy->possible_interfaces)) {
+		/* We only care about the union of the PHY's interfaces and
+		 * those which the host supports.
+		 */
+		phy_interface_and(interfaces, phy->possible_interfaces,
+				  pl->supported_interfaces);
+
+		if (phy_interface_empty(interfaces)) {
+			phylink_err(pl, "PHY has no common interfaces\n");
+			return -EINVAL;
+		}
+
+		if (phy_on_sfp(phy)) {
+			/* If the PHY is on a SFP, limit the interfaces to
+			 * those that can be used with a SFP module.
+			 */
+			phy_interface_and(interfaces, interfaces,
+					  phylink_sfp_interfaces);
+
+			if (phy_interface_empty(interfaces)) {
+				phylink_err(pl, "SFP PHY's possible interfaces becomes empty\n");
+				return -EINVAL;
+			}
+		}
+
+		phylink_dbg(pl, "PHY %s uses interfaces %*pbl, validating %*pbl\n",
+			    phydev_name(phy),
+			    (int)PHY_INTERFACE_MODE_MAX,
+			    phy->possible_interfaces,
+			    (int)PHY_INTERFACE_MODE_MAX, interfaces);
+
+		return __phylink_validate_mask(pl, phy, supported, state,
+					      interfaces);
+	}
+
+	phylink_dbg(pl, "PHY %s doesn't supply possible interfaces\n",
+		    phydev_name(phy));
+
+	/* Check whether we would use rate matching for the proposed interface
+	 * mode.
+	 */
+	state->rate_matching = __phy_get_rate_matching(phy, state->interface);
+
+	/* Clause 45 PHYs may switch their Serdes lane between, e.g. 10GBASE-R,
+	 * 5GBASE-R, 2500BASE-X and SGMII if they are not using rate matching.
+	 * For some interface modes (e.g. RXAUI, XAUI and USXGMII) switching
+	 * their Serdes is either unnecessary or not reasonable.
+	 *
+	 * For these which switch interface modes, we really need to know which
+	 * interface modes the PHY supports to properly work out which ethtool
+	 * linkmodes can be supported. For now, as a work-around, we validate
+	 * against all interface modes, which may lead to more ethtool link
+	 * modes being advertised than are actually supported.
+	 */
+	if (phy->is_c45 && state->rate_matching == RATE_MATCH_NONE &&
+	    state->interface != PHY_INTERFACE_MODE_RXAUI &&
+	    state->interface != PHY_INTERFACE_MODE_XAUI &&
+	    state->interface != PHY_INTERFACE_MODE_USXGMII)
+		state->interface = PHY_INTERFACE_MODE_NA;
+
+	return __phylink_validate(pl, supported, state);
+}
+
 static void phylink_fill_fixedlink_supported(unsigned long *supported)
 {
 	linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, supported);
@@ -740,12 +817,51 @@ static void phylink_fill_fixedlink_supported(unsigned long *supported)
 	linkmode_set_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, supported);
 }
 
-static int phylink_parse_fixedlink(struct phylink *pl,
-				   const struct fwnode_handle *fwnode)
+static int phylink_parse_fixedlink_capabilities(struct phylink *pl,
+						struct phylink_link_state *config)
 {
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(match) = { 0, };
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
 	const struct link_capabilities *c;
+
+	lockdep_assert_held(&pl->state_mutex);
+
+	linkmode_zero(pl->supported);
+	phylink_fill_fixedlink_supported(pl->supported);
+
+	linkmode_copy(config->advertising, pl->supported);
+	__phylink_validate(pl, pl->supported, config);
+
+	linkmode_copy(pl->advertising, config->advertising);
+
+	c = phy_caps_lookup(config->speed, config->duplex,
+			    pl->supported, true);
+	if (c)
+		linkmode_and(match, pl->supported, c->linkmodes);
+
+	linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, mask);
+	linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, mask);
+	linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, mask);
+	linkmode_and(pl->supported, pl->supported, mask);
+
+	phylink_set(pl->supported, MII);
+
+	if (c) {
+		linkmode_or(pl->supported, pl->supported, match);
+		linkmode_or(config->lp_advertising,
+			    config->lp_advertising, match);
+	}
+
+	linkmode_and(config->advertising, config->advertising,
+		     pl->supported);
+	linkmode_copy(pl->advertising, config->advertising);
+
+	return c ? 0 : -EINVAL;
+}
+
+static int phylink_parse_fixedlink(struct phylink *pl,
+				   const struct fwnode_handle *fwnode)
+{
 	struct fwnode_handle *fixed_node;
 	struct gpio_desc *desc;
 	u32 speed;
@@ -817,39 +933,77 @@ static int phylink_parse_fixedlink(struct phylink *pl,
 		phylink_warn(pl, "fixed link specifies half duplex for %dMbps link?\n",
 			     pl->link_config.speed);
 
-	linkmode_zero(pl->supported);
-	phylink_fill_fixedlink_supported(pl->supported);
+	mutex_lock(&pl->state_mutex);
+	ret = phylink_parse_fixedlink_capabilities(pl, &pl->link_config);
+	mutex_unlock(&pl->state_mutex);
+	if (ret)
+		phylink_warn(pl, "fixed link %s duplex %dMbps not recognised\n",
+			     pl->link_config.duplex == DUPLEX_FULL ? "full" : "half",
+			     pl->link_config.speed);
 
-	linkmode_copy(pl->link_config.advertising, pl->supported);
-	phylink_validate(pl, pl->supported, &pl->link_config);
+	pl->link_config.link = 1;
+	pl->link_config.an_complete = 1;
 
-	c = phy_caps_lookup(pl->link_config.speed, pl->link_config.duplex,
-			    pl->supported, true);
-	if (c)
-		linkmode_and(match, pl->supported, c->linkmodes);
+	return 0;
+}
 
-	linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, mask);
-	linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, mask);
-	linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, mask);
-	linkmode_and(pl->supported, pl->supported, mask);
+static int phylink_parse_inband_capabilities(struct phylink *pl,
+					     struct phylink_link_state *config)
+{
+	unsigned long caps;
+
+	lockdep_assert_held(&pl->state_mutex);
 
+	linkmode_zero(pl->supported);
 	phylink_set(pl->supported, MII);
+	phylink_set(pl->supported, Autoneg);
+	phylink_set(pl->supported, Asym_Pause);
+	phylink_set(pl->supported, Pause);
 
-	if (c) {
-		linkmode_or(pl->supported, pl->supported, match);
-		linkmode_or(pl->link_config.lp_advertising,
-			    pl->link_config.lp_advertising, match);
-	} else {
-		phylink_warn(pl, "fixed link %s duplex %dMbps not recognised\n",
-			     pl->link_config.duplex == DUPLEX_FULL ? "full" : "half",
-			     pl->link_config.speed);
+	switch (config->interface) {
+	case PHY_INTERFACE_MODE_SGMII:
+	case PHY_INTERFACE_MODE_PSGMII:
+	case PHY_INTERFACE_MODE_QSGMII:
+	case PHY_INTERFACE_MODE_QUSGMII:
+	case PHY_INTERFACE_MODE_RGMII:
+	case PHY_INTERFACE_MODE_RGMII_ID:
+	case PHY_INTERFACE_MODE_RGMII_RXID:
+	case PHY_INTERFACE_MODE_RGMII_TXID:
+	case PHY_INTERFACE_MODE_RTBI:
+	case PHY_INTERFACE_MODE_1000BASEX:
+	case PHY_INTERFACE_MODE_2500BASEX:
+	case PHY_INTERFACE_MODE_5GBASER:
+	case PHY_INTERFACE_MODE_25GBASER:
+	case PHY_INTERFACE_MODE_USXGMII:
+	case PHY_INTERFACE_MODE_10G_QXGMII:
+	case PHY_INTERFACE_MODE_10GKR:
+	case PHY_INTERFACE_MODE_10GBASER:
+	case PHY_INTERFACE_MODE_XLGMII:
+	case PHY_INTERFACE_MODE_50GBASER:
+	case PHY_INTERFACE_MODE_LAUI:
+	case PHY_INTERFACE_MODE_100GBASEP:
+		caps = ~(MAC_SYM_PAUSE | MAC_ASYM_PAUSE);
+		caps = phylink_get_capabilities(config->interface, caps,
+						RATE_MATCH_NONE);
+		phylink_caps_to_linkmodes(pl->supported, caps);
+		break;
+
+	default:
+		phylink_err(pl,
+			    "incorrect link mode %s for in-band status\n",
+			    phy_modes(config->interface));
+		return -EINVAL;
 	}
 
-	linkmode_and(pl->link_config.advertising, pl->link_config.advertising,
-		     pl->supported);
+	linkmode_copy(config->advertising, pl->supported);
 
-	pl->link_config.link = 1;
-	pl->link_config.an_complete = 1;
+	if (__phylink_validate(pl, pl->supported, config)) {
+		phylink_err(pl,
+			    "failed to validate link configuration for in-band status\n");
+		return -EINVAL;
+	}
+
+	linkmode_copy(pl->advertising, config->advertising);
 
 	return 0;
 }
@@ -859,7 +1013,7 @@ static int phylink_parse_mode(struct phylink *pl,
 {
 	struct fwnode_handle *dn;
 	const char *managed;
-	unsigned long caps;
+	int ret;
 
 	if (pl->config->default_an_inband)
 		pl->cfg_link_an_mode = MLO_AN_INBAND;
@@ -881,54 +1035,11 @@ static int phylink_parse_mode(struct phylink *pl,
 	}
 
 	if (pl->cfg_link_an_mode == MLO_AN_INBAND) {
-		linkmode_zero(pl->supported);
-		phylink_set(pl->supported, MII);
-		phylink_set(pl->supported, Autoneg);
-		phylink_set(pl->supported, Asym_Pause);
-		phylink_set(pl->supported, Pause);
-
-		switch (pl->link_config.interface) {
-		case PHY_INTERFACE_MODE_SGMII:
-		case PHY_INTERFACE_MODE_PSGMII:
-		case PHY_INTERFACE_MODE_QSGMII:
-		case PHY_INTERFACE_MODE_QUSGMII:
-		case PHY_INTERFACE_MODE_RGMII:
-		case PHY_INTERFACE_MODE_RGMII_ID:
-		case PHY_INTERFACE_MODE_RGMII_RXID:
-		case PHY_INTERFACE_MODE_RGMII_TXID:
-		case PHY_INTERFACE_MODE_RTBI:
-		case PHY_INTERFACE_MODE_1000BASEX:
-		case PHY_INTERFACE_MODE_2500BASEX:
-		case PHY_INTERFACE_MODE_5GBASER:
-		case PHY_INTERFACE_MODE_25GBASER:
-		case PHY_INTERFACE_MODE_USXGMII:
-		case PHY_INTERFACE_MODE_10G_QXGMII:
-		case PHY_INTERFACE_MODE_10GKR:
-		case PHY_INTERFACE_MODE_10GBASER:
-		case PHY_INTERFACE_MODE_XLGMII:
-		case PHY_INTERFACE_MODE_50GBASER:
-		case PHY_INTERFACE_MODE_LAUI:
-		case PHY_INTERFACE_MODE_100GBASEP:
-			caps = ~(MAC_SYM_PAUSE | MAC_ASYM_PAUSE);
-			caps = phylink_get_capabilities(pl->link_config.interface, caps,
-							RATE_MATCH_NONE);
-			phylink_caps_to_linkmodes(pl->supported, caps);
-			break;
-
-		default:
-			phylink_err(pl,
-				    "incorrect link mode %s for in-band status\n",
-				    phy_modes(pl->link_config.interface));
-			return -EINVAL;
-		}
-
-		linkmode_copy(pl->link_config.advertising, pl->supported);
-
-		if (phylink_validate(pl, pl->supported, &pl->link_config)) {
-			phylink_err(pl,
-				    "failed to validate link configuration for in-band status\n");
-			return -EINVAL;
-		}
+		mutex_lock(&pl->state_mutex);
+		ret = phylink_parse_inband_capabilities(pl, &pl->link_config);
+		mutex_unlock(&pl->state_mutex);
+		if (ret)
+			return ret;
 	}
 
 	return 0;
@@ -2087,6 +2198,8 @@ static void phylink_update_pause_state(struct phylink *pl, int pause_state)
 	 */
 	linkmode_set_pause(config->advertising, tx_pause,
 			   rx_pause);
+	if (pl->phydev)
+		linkmode_set_pause(pl->phy_advertising, tx_pause, rx_pause);
 
 	manual_changed = (config->pause ^ pause_state) & MLO_PAUSE_AN ||
 			 (!(pause_state & MLO_PAUSE_AN) &&
@@ -2120,6 +2233,142 @@ static void phylink_update_pause_state(struct phylink *pl, int pause_state)
 	}
 }
 
+static void phylink_update_user_disabled_advertising(struct phylink *pl,
+						     const unsigned long *advertising)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(disabled);
+
+	/* Preserve restrictions for modes absent from the current full mask. */
+	linkmode_andnot(disabled, pl->user_disabled_advertising,
+			pl->advertising);
+
+	/* Update restrictions for modes in the current full advertisement. */
+	linkmode_andnot(pl->user_disabled_advertising, pl->advertising,
+			advertising);
+
+	/* Combine the updated restrictions with those preserved above. */
+	linkmode_or(pl->user_disabled_advertising,
+		    pl->user_disabled_advertising, disabled);
+}
+
+static void phylink_sfp_update_capabilities(struct phylink *pl,
+					    unsigned long *supported,
+					    struct phylink_link_state *config,
+					    phy_interface_t interface)
+{
+	enum inband_type inband_type;
+
+	inband_type = phylink_get_inband_type(interface);
+	if (inband_type == INBAND_NONE) {
+		/* If this is the sole interface, and there is no inband
+		 * support, clear the advertising mask and Autoneg bit in
+		 * the support mask. Otherwise, just clear the Autoneg bit
+		 * in the advertising mask.
+		 */
+		if (phy_interface_weight(pl->sfp_interfaces) == 1) {
+			linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
+					   supported);
+			linkmode_zero(config->advertising);
+		} else {
+			linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
+					   config->advertising);
+		}
+	}
+}
+
+static int phylink_phy_update_capabilities(struct phylink *pl, struct phy_device *phy,
+					   phy_interface_t interface)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
+	struct phylink_link_state config;
+	int ret;
+
+	lockdep_assert_held(&pl->phydev_mutex);
+	lockdep_assert_held(&phy->lock);
+	lockdep_assert_held(&pl->state_mutex);
+
+	memset(&config, 0, sizeof(config));
+	linkmode_copy(supported, phy->supported);
+	linkmode_copy(config.advertising, pl->phy_advertising);
+	config.interface = interface;
+
+	ret = __phylink_validate_phy(pl, phy, supported, &config);
+	if (ret) {
+		phylink_warn(pl, "validation of %s with support %*pb and advertisement %*pb failed: %pe\n",
+			     phy_modes(config.interface),
+			     __ETHTOOL_LINK_MODE_MASK_NBITS, phy->supported,
+			     __ETHTOOL_LINK_MODE_MASK_NBITS, config.advertising,
+			     ERR_PTR(ret));
+		return ret;
+	}
+
+	linkmode_copy(pl->supported, supported);
+	linkmode_copy(pl->link_config.advertising, config.advertising);
+	linkmode_copy(pl->advertising, pl->link_config.advertising);
+
+	/* Restrict the phy advertisement according to the MAC support. */
+	linkmode_copy(phy->advertising, config.advertising);
+
+	return 0;
+}
+
+static void phylink_update_capabilities(struct phylink *pl,
+					struct phylink_link_state *config)
+{
+	if (pl->phydev) {
+		lockdep_assert_held(&pl->phydev_mutex);
+		lockdep_assert_held(&pl->phydev->lock);
+	}
+	lockdep_assert_held(&pl->state_mutex);
+
+	if (pl->phydev) {
+		phylink_phy_update_capabilities(pl, pl->phydev,
+						pl->phy_state.interface);
+		return;
+	}
+
+	if (pl->cfg_link_an_mode == MLO_AN_FIXED) {
+		phylink_parse_fixedlink_capabilities(pl, config);
+		goto exit;
+	}
+
+	if (pl->cfg_link_an_mode == MLO_AN_INBAND) {
+		phylink_parse_inband_capabilities(pl, config);
+		goto exit;
+	}
+
+	/* Revalidate the SFP module modes against every available interface. */
+	if (pl->sfp_bus && !pl->phydev && config->interface &&
+	    !phy_interface_empty(pl->sfp_interfaces)) {
+		__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
+
+		linkmode_copy(supported, pl->sfp_support);
+		linkmode_copy(config->advertising, pl->sfp_support);
+		if (!__phylink_validate_mask(pl, NULL, supported, config,
+					     pl->sfp_interfaces)) {
+			phylink_sfp_update_capabilities(pl, supported, config,
+							config->interface);
+			linkmode_copy(pl->supported, supported);
+			linkmode_copy(pl->advertising, config->advertising);
+		}
+
+		goto exit;
+	}
+
+	/* No media is attached yet. Recalculate the generic capabilities. */
+	linkmode_fill(pl->supported);
+	linkmode_copy(config->advertising, pl->supported);
+	__phylink_validate(pl, pl->supported, config);
+
+	/* Save the newly calculated full advertisement */
+	linkmode_copy(pl->advertising, config->advertising);
+
+exit:
+	/* Keep user-disabled modes out of the active advertisement. */
+	linkmode_andnot(config->advertising,
+			pl->advertising, pl->user_disabled_advertising);
+}
+
 /**
  * phylink_update_mac_pause_capabilities() - Dynamically update MAC pause
  * @pl: a pointer to a &struct phylink returned from phylink_create()
@@ -2132,6 +2381,7 @@ static void phylink_update_pause_state(struct phylink *pl, int pause_state)
 void phylink_update_mac_pause_capabilities(struct phylink *pl, unsigned long mac_pause)
 {
 	struct phylink_link_state *config = &pl->link_config;
+	struct phy_device *phydev;
 	unsigned long old_pause;
 	int pause_state;
 
@@ -2146,20 +2396,16 @@ void phylink_update_mac_pause_capabilities(struct phylink *pl, unsigned long mac
 	if (old_pause == mac_pause)
 		return;
 
+	mutex_lock(&pl->phydev_mutex);
+	phydev = pl->phydev;
+	if (phydev)
+		mutex_lock(&phydev->lock);
 	mutex_lock(&pl->state_mutex);
 
 	pl->config->mac_capabilities &= ~(MAC_SYM_PAUSE | MAC_ASYM_PAUSE);
 	pl->config->mac_capabilities |= mac_pause;
 
-	phylink_set(pl->supported, Pause);
-	phylink_set(pl->supported, Asym_Pause);
-
-	if (pl->phydev)
-		linkmode_and(pl->supported, pl->supported, pl->phydev->supported);
-	else if (pl->sfp_bus)
-		linkmode_and(pl->supported, pl->supported, pl->sfp_support);
-
-	__phylink_validate(pl, pl->supported, config);
+	phylink_update_capabilities(pl, config);
 
 	pause_state = config->pause;
 
@@ -2171,6 +2417,9 @@ void phylink_update_mac_pause_capabilities(struct phylink *pl, unsigned long mac
 	}
 
 	mutex_unlock(&pl->state_mutex);
+	if (phydev)
+		mutex_unlock(&phydev->lock);
+	mutex_unlock(&pl->phydev_mutex);
 
 	phylink_update_pause_state(pl, pause_state);
 }
@@ -2259,6 +2508,8 @@ struct phylink *phylink_create(struct phylink_config *config,
 	pl->link_config.pause = MLO_PAUSE_AN;
 	pl->link_config.speed = SPEED_UNKNOWN;
 	pl->link_config.duplex = DUPLEX_UNKNOWN;
+	linkmode_fill(pl->advertising);
+	linkmode_fill(pl->link_config.advertising);
 	pl->pcs_state = PCS_STATE_DOWN;
 	pl->mac_ops = mac_ops;
 	__set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
@@ -2282,9 +2533,9 @@ struct phylink *phylink_create(struct phylink_config *config,
 				 pl->supported_interfaces,
 				 pcs->supported_interfaces);
 
-	linkmode_fill(pl->supported);
-	linkmode_copy(pl->link_config.advertising, pl->supported);
-	phylink_validate(pl, pl->supported, &pl->link_config);
+	mutex_lock(&pl->state_mutex);
+	phylink_update_capabilities(pl, &pl->link_config);
+	mutex_unlock(&pl->state_mutex);
 
 	ret = phylink_parse_mode(pl, fwnode);
 	if (ret < 0)
@@ -2417,84 +2668,9 @@ static void phylink_phy_change(struct phy_device *phydev, bool up)
 		    phydev->enable_tx_lpi ? "" : "no");
 }
 
-static int phylink_validate_phy(struct phylink *pl, struct phy_device *phy,
-				unsigned long *supported,
-				struct phylink_link_state *state)
-{
-	DECLARE_PHY_INTERFACE_MASK(interfaces);
-
-	/* If the PHY provides a bitmap of the interfaces it will be using
-	 * depending on the negotiated media speeds, use this to validate
-	 * which ethtool link modes can be used.
-	 */
-	if (!phy_interface_empty(phy->possible_interfaces)) {
-		/* We only care about the union of the PHY's interfaces and
-		 * those which the host supports.
-		 */
-		phy_interface_and(interfaces, phy->possible_interfaces,
-				  pl->supported_interfaces);
-
-		if (phy_interface_empty(interfaces)) {
-			phylink_err(pl, "PHY has no common interfaces\n");
-			return -EINVAL;
-		}
-
-		if (phy_on_sfp(phy)) {
-			/* If the PHY is on a SFP, limit the interfaces to
-			 * those that can be used with a SFP module.
-			 */
-			phy_interface_and(interfaces, interfaces,
-					  phylink_sfp_interfaces);
-
-			if (phy_interface_empty(interfaces)) {
-				phylink_err(pl, "SFP PHY's possible interfaces becomes empty\n");
-				return -EINVAL;
-			}
-		}
-
-		phylink_dbg(pl, "PHY %s uses interfaces %*pbl, validating %*pbl\n",
-			    phydev_name(phy),
-			    (int)PHY_INTERFACE_MODE_MAX,
-			    phy->possible_interfaces,
-			    (int)PHY_INTERFACE_MODE_MAX, interfaces);
-
-		return phylink_validate_mask(pl, phy, supported, state,
-					     interfaces);
-	}
-
-	phylink_dbg(pl, "PHY %s doesn't supply possible interfaces\n",
-		    phydev_name(phy));
-
-	/* Check whether we would use rate matching for the proposed interface
-	 * mode.
-	 */
-	state->rate_matching = phy_get_rate_matching(phy, state->interface);
-
-	/* Clause 45 PHYs may switch their Serdes lane between, e.g. 10GBASE-R,
-	 * 5GBASE-R, 2500BASE-X and SGMII if they are not using rate matching.
-	 * For some interface modes (e.g. RXAUI, XAUI and USXGMII) switching
-	 * their Serdes is either unnecessary or not reasonable.
-	 *
-	 * For these which switch interface modes, we really need to know which
-	 * interface modes the PHY supports to properly work out which ethtool
-	 * linkmodes can be supported. For now, as a work-around, we validate
-	 * against all interface modes, which may lead to more ethtool link
-	 * modes being advertised than are actually supported.
-	 */
-	if (phy->is_c45 && state->rate_matching == RATE_MATCH_NONE &&
-	    state->interface != PHY_INTERFACE_MODE_RXAUI &&
-	    state->interface != PHY_INTERFACE_MODE_XAUI &&
-	    state->interface != PHY_INTERFACE_MODE_USXGMII)
-		state->interface = PHY_INTERFACE_MODE_NA;
-
-	return phylink_validate(pl, supported, state);
-}
-
 static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy,
 			       phy_interface_t interface)
 {
-	struct phylink_link_state config;
-	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
 	char *irq_str;
 	int ret;
 
@@ -2507,18 +2683,17 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy,
 	 */
 	phy_support_asym_pause(phy);
 
-	memset(&config, 0, sizeof(config));
-	linkmode_copy(supported, phy->supported);
-	linkmode_copy(config.advertising, phy->advertising);
-	config.interface = interface;
+	mutex_lock(&pl->phydev_mutex);
+	mutex_lock(&phy->lock);
+	mutex_lock(&pl->state_mutex);
+
+	linkmode_copy(pl->phy_advertising, phy->advertising);
 
-	ret = phylink_validate_phy(pl, phy, supported, &config);
+	ret = phylink_phy_update_capabilities(pl, phy, interface);
 	if (ret) {
-		phylink_warn(pl, "validation of %s with support %*pb and advertisement %*pb failed: %pe\n",
-			     phy_modes(config.interface),
-			     __ETHTOOL_LINK_MODE_MASK_NBITS, phy->supported,
-			     __ETHTOOL_LINK_MODE_MASK_NBITS, config.advertising,
-			     ERR_PTR(ret));
+		mutex_unlock(&pl->state_mutex);
+		mutex_unlock(&phy->lock);
+		mutex_unlock(&pl->phydev_mutex);
 		return ret;
 	}
 
@@ -2531,19 +2706,11 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy,
 		     dev_name(&phy->mdio.dev), phy->drv->name, irq_str);
 	kfree(irq_str);
 
-	mutex_lock(&pl->phydev_mutex);
-	mutex_lock(&phy->lock);
-	mutex_lock(&pl->state_mutex);
 	pl->phy_state.interface = interface;
 	pl->phy_state.pause = MLO_PAUSE_NONE;
 	pl->phy_state.speed = SPEED_UNKNOWN;
 	pl->phy_state.duplex = DUPLEX_UNKNOWN;
 	pl->phy_state.rate_matching = RATE_MATCH_NONE;
-	linkmode_copy(pl->supported, supported);
-	linkmode_copy(pl->link_config.advertising, config.advertising);
-
-	/* Restrict the phy advertisement according to the MAC support. */
-	linkmode_copy(phy->advertising, config.advertising);
 
 	/* If the MAC supports phylink managed EEE, restrict the EEE
 	 * advertisement according to the MAC's LPI capabilities.
@@ -3403,6 +3570,7 @@ static bool phylink_validate_pcs_inband_autoneg(struct phylink *pl,
 int phylink_ethtool_ksettings_set(struct phylink *pl,
 				  const struct ethtool_link_ksettings *kset)
 {
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(requested_advertising);
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(support);
 	const struct link_capabilities *c;
 	struct phylink_link_state config;
@@ -3411,6 +3579,7 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
 
 	if (pl->phydev) {
 		struct ethtool_link_ksettings phy_kset = *kset;
+		int ret;
 
 		linkmode_and(phy_kset.link_modes.advertising,
 			     phy_kset.link_modes.advertising,
@@ -3434,7 +3603,15 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
 		 *   the presence of a PHY, this should not be changed as that
 		 *   should be determined from the media side advertisement.
 		 */
-		return phy_ethtool_ksettings_set(pl->phydev, &phy_kset);
+		ret = phy_ethtool_ksettings_set(pl->phydev, &phy_kset);
+		if (!ret) {
+			mutex_lock(&pl->state_mutex);
+			linkmode_copy(pl->phy_advertising,
+				      phy_kset.link_modes.advertising);
+			mutex_unlock(&pl->state_mutex);
+		}
+
+		return ret;
 	}
 
 	config = pl->link_config;
@@ -3492,6 +3669,7 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
 	 */
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, config.advertising,
 			 kset->base.autoneg == AUTONEG_ENABLE);
+	linkmode_copy(requested_advertising, config.advertising);
 
 	/* If this link is with an SFP, ensure that changes to advertised modes
 	 * also cause the associated interface to be selected such that the
@@ -3539,6 +3717,7 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
 		return -EINVAL;
 
 	mutex_lock(&pl->state_mutex);
+	phylink_update_user_disabled_advertising(pl, requested_advertising);
 	pl->link_config.speed = config.speed;
 	pl->link_config.duplex = config.duplex;
 
@@ -4022,19 +4201,34 @@ static void phylink_sfp_detach(void *upstream, struct sfp_bus *bus)
 }
 
 static phy_interface_t phylink_choose_sfp_interface(struct phylink *pl,
-						    const unsigned long *intf)
+						    const unsigned long *intf,
+						    const unsigned long *supported,
+						    const struct phylink_link_state *state)
 {
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(tmp_supported);
+	struct phylink_link_state tmp_state;
 	phy_interface_t interface;
 	size_t i;
 
-	interface = PHY_INTERFACE_MODE_NA;
-	for (i = 0; i < ARRAY_SIZE(phylink_sfp_interface_preference); i++)
-		if (test_bit(phylink_sfp_interface_preference[i], intf)) {
-			interface = phylink_sfp_interface_preference[i];
-			break;
-		}
+	for (i = 0; i < ARRAY_SIZE(phylink_sfp_interface_preference); i++) {
+		interface = phylink_sfp_interface_preference[i];
+		if (!test_bit(interface, intf))
+			continue;
 
-	return interface;
+		tmp_state = *state;
+		tmp_state.interface = interface;
+		linkmode_copy(tmp_supported, supported);
+		if (phylink_validate(pl, tmp_supported, &tmp_state))
+			continue;
+
+		/* Skip this preferred interface if user-disabled in advertising */
+		linkmode_andnot(tmp_state.advertising, tmp_state.advertising,
+				pl->user_disabled_advertising);
+		if (!phylink_is_empty_linkmode(tmp_state.advertising))
+			return interface;
+	}
+
+	return PHY_INTERFACE_MODE_NA;
 }
 
 static void phylink_sfp_set_config(struct phylink *pl, unsigned long *supported,
@@ -4052,6 +4246,11 @@ static void phylink_sfp_set_config(struct phylink *pl, unsigned long *supported,
 		changed = true;
 	}
 
+	linkmode_copy(pl->advertising, state->advertising);
+	if (!pl->phydev)
+		linkmode_andnot(state->advertising, pl->advertising,
+				pl->user_disabled_advertising);
+
 	if (!linkmode_equal(pl->link_config.advertising, state->advertising)) {
 		linkmode_copy(pl->link_config.advertising, state->advertising);
 		changed = true;
@@ -4128,8 +4327,8 @@ static int phylink_sfp_config_phy(struct phylink *pl, struct phy_device *phy)
 static int phylink_sfp_config_optical(struct phylink *pl)
 {
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(support);
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_supported);
 	struct phylink_link_state config;
-	enum inband_type inband_type;
 	phy_interface_t interface;
 	int ret;
 
@@ -4151,15 +4350,16 @@ static int phylink_sfp_config_optical(struct phylink *pl)
 
 	memset(&config, 0, sizeof(config));
 	linkmode_copy(support, pl->sfp_support);
+	linkmode_copy(sfp_supported, support);
 	linkmode_copy(config.advertising, pl->sfp_support);
 	config.speed = SPEED_UNKNOWN;
 	config.duplex = DUPLEX_UNKNOWN;
 	config.pause = MLO_PAUSE_AN;
 
-	/* For all the interfaces that are supported, reduce the sfp_support
+	/* For all the interfaces that are supported, reduce the temporary
 	 * mask to only those link modes that can be supported.
 	 */
-	ret = phylink_validate_mask(pl, NULL, pl->sfp_support, &config,
+	ret = phylink_validate_mask(pl, NULL, sfp_supported, &config,
 				    pl->sfp_interfaces);
 	if (ret) {
 		phylink_err(pl, "unsupported SFP module: validation with support %*pb failed\n",
@@ -4167,7 +4367,8 @@ static int phylink_sfp_config_optical(struct phylink *pl)
 		return ret;
 	}
 
-	interface = phylink_choose_sfp_interface(pl, pl->sfp_interfaces);
+	interface = phylink_choose_sfp_interface(pl, pl->sfp_interfaces,
+						 sfp_supported, &config);
 	if (interface == PHY_INTERFACE_MODE_NA) {
 		phylink_err(pl, "failed to select SFP interface\n");
 		return -EINVAL;
@@ -4176,22 +4377,8 @@ static int phylink_sfp_config_optical(struct phylink *pl)
 	phylink_dbg(pl, "optical SFP: chosen %s interface\n",
 		    phy_modes(interface));
 
-	inband_type = phylink_get_inband_type(interface);
-	if (inband_type == INBAND_NONE) {
-		/* If this is the sole interface, and there is no inband
-		 * support, clear the advertising mask and Autoneg bit in
-		 * the support mask. Otherwise, just clear the Autoneg bit
-		 * in the advertising mask.
-		 */
-		if (phy_interface_weight(pl->sfp_interfaces) == 1) {
-			linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
-					   pl->sfp_support);
-			linkmode_zero(config.advertising);
-		} else {
-			linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
-					   config.advertising);
-		}
-	}
+	phylink_sfp_update_capabilities(pl, sfp_supported, &config,
+					interface);
 
 	if (!phylink_validate_pcs_inband_autoneg(pl, interface,
 						 config.advertising)) {
@@ -4212,7 +4399,7 @@ static int phylink_sfp_config_optical(struct phylink *pl)
 
 	pl->link_port = pl->sfp_port;
 
-	phylink_sfp_set_config(pl, pl->sfp_support, &config, false);
+	phylink_sfp_set_config(pl, sfp_supported, &config, false);
 
 	return 0;
 }
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 08/15] net: phylink: support PCS provider release
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
                   ` (6 preceding siblings ...)
  2026-11-17 12:39 ` [PATCH net-next v22 07/15] net: phylink: add capabilities helpers and track modified advertising Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-21 23:26   ` Jakub Kicinski
  2026-11-17 12:39 ` [PATCH net-next v22 09/15] net: phylink: support late PCS provider attach Christian Marangi
                   ` (6 subsequent siblings)
  14 siblings, 1 reply; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

Add support for release of fwnode PCS from a PCS provider.
This works by creating a global notifier for the PCS provider and
making each phylink instance that makes use of fwnode subscribe to
this notifier.

The PCS notifier will emit the event FWNODE_PCS_PROVIDER_DEL every time
a new PCS provider is released.

phylink will then react to this event and will call the new function
fwnode_pcs_matches_provider() on each PCS of the phylink instance and
will check if the PCS is provided by the PCS provider that is getting
released.

If a related PCS is found, then such PCS is removed from the phylink
instance PCS list and the supported_interfaces value is updated.

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.

Finally a phylink resolve is triggered to handle the PCS removal.

Protect every access of phylink pcs_list with state_mutex to handle async
PCS provider release and capabilities recalculation.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/pcs/pcs.c     |  47 +++++++++
 drivers/net/phy/phylink.c | 203 ++++++++++++++++++++++++++++++++------
 include/linux/pcs/pcs.h   |  69 +++++++++++++
 3 files changed, 289 insertions(+), 30 deletions(-)

diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c
index b1d48f6eee7f..f234a4635417 100644
--- a/drivers/net/pcs/pcs.c
+++ b/drivers/net/pcs/pcs.c
@@ -22,6 +22,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)
@@ -74,6 +87,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_handle_put(pp->fwnode);
 	kfree(pp);
 }
@@ -183,6 +201,35 @@ 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 fwnode_handle *fwnode,
+				 struct phylink_pcs *pl_pcs)
+{
+	struct fwnode_reference_args pcsspec;
+	int index = 0;
+	int ret;
+
+	while (true) {
+		struct phylink_pcs *pcs;
+
+		ret = fwnode_parse_pcsspec(fwnode, index, NULL, &pcsspec);
+		if (ret)
+			return false;
+
+		pcs = __fwnode_pcs_get_from_pcsspec_provider(&pcsspec, provider);
+		if (!IS_ERR(pcs) && pcs == pl_pcs) {
+			fwnode_handle_put(pcsspec.fwnode);
+			return true;
+		}
+
+		fwnode_handle_put(pcsspec.fwnode);
+		index++;
+	}
+
+	return false;
+}
+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 921c227a5b3c..094a15f3dbcd 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>
@@ -38,6 +40,7 @@ enum {
 	PCS_STATE_DOWN = 0,
 	PCS_STATE_STARTING,
 	PCS_STATE_STARTED,
+	PCS_STATE_DETACHING,
 };
 
 /**
@@ -70,6 +73,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.
 	 * Can change on removal or addition of new PCS.
@@ -934,13 +938,15 @@ static int phylink_parse_fixedlink(struct phylink *pl,
 			     pl->link_config.speed);
 
 	mutex_lock(&pl->state_mutex);
+
 	ret = phylink_parse_fixedlink_capabilities(pl, &pl->link_config);
-	mutex_unlock(&pl->state_mutex);
 	if (ret)
 		phylink_warn(pl, "fixed link %s duplex %dMbps not recognised\n",
 			     pl->link_config.duplex == DUPLEX_FULL ? "full" : "half",
 			     pl->link_config.speed);
 
+	mutex_unlock(&pl->state_mutex);
+
 	pl->link_config.link = 1;
 	pl->link_config.an_complete = 1;
 
@@ -1154,6 +1160,9 @@ static unsigned int phylink_inband_caps(struct phylink *pl,
 					 phy_interface_t interface)
 {
 	struct phylink_pcs *pcs = NULL;
+	int ret = 0;
+
+	mutex_lock(&pl->state_mutex);
 
 	if (pl->mac_ops->mac_select_pcs) {
 		pcs = pl->mac_ops->mac_select_pcs(pl->config,
@@ -1170,9 +1179,14 @@ static unsigned int phylink_inband_caps(struct phylink *pl,
 	}
 
 	if (IS_ERR_OR_NULL(pcs))
-		return 0;
+		goto exit;
 
-	return phylink_pcs_inband_caps(pcs, interface);
+	ret = phylink_pcs_inband_caps(pcs, interface);
+
+exit:
+	mutex_unlock(&pl->state_mutex);
+
+	return ret;
 }
 
 static void phylink_pcs_poll_stop(struct phylink *pl)
@@ -1713,7 +1727,9 @@ static void phylink_mac_initial_config(struct phylink *pl, bool force_restart)
 	phylink_apply_manual_flow(pl, &link_state);
 	if (phy)
 		mutex_lock(&phy->lock);
+	mutex_lock(&pl->state_mutex);
 	phylink_major_config(pl, force_restart, &link_state);
+	mutex_unlock(&pl->state_mutex);
 	if (phy)
 		mutex_unlock(&phy->lock);
 }
@@ -2143,6 +2159,9 @@ static int phylink_fill_available_pcs(struct phylink *pl,
 	if (!pcss)
 		return -ENOMEM;
 
+	/* Lock state_mutex while filling to handle PCS notify */
+	mutex_lock(&pl->state_mutex);
+
 	ret = config->fill_available_pcs(config, pcss, config->num_possible_pcs);
 	if (ret < 0)
 		goto out;
@@ -2162,6 +2181,8 @@ static int phylink_fill_available_pcs(struct phylink *pl,
 	}
 
 out:
+	mutex_unlock(&pl->state_mutex);
+
 	kfree(pcss);
 
 	return ret;
@@ -2350,6 +2371,11 @@ static void phylink_update_capabilities(struct phylink *pl,
 							config->interface);
 			linkmode_copy(pl->supported, supported);
 			linkmode_copy(pl->advertising, config->advertising);
+		} else {
+			/* No SFP modes remain usable with the current interfaces. */
+			linkmode_zero(pl->supported);
+			linkmode_zero(pl->advertising);
+			linkmode_zero(config->advertising);
 		}
 
 		goto exit;
@@ -2425,6 +2451,133 @@ 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);
+
+	rcu_assign_pointer(pcs->phylink, NULL);
+	synchronize_rcu();
+	list_del(&pcs->list);
+
+	/*
+	 * 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);
+	}
+}
+
+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 *pp = data;
+	struct phylink_pcs *pcs, *tmp;
+	struct phy_device *phydev;
+	bool resolve = false;
+
+	rtnl_lock();
+	mutex_lock(&pl->phydev_mutex);
+	phydev = pl->phydev;
+	if (phydev)
+		mutex_lock(&phydev->lock);
+	mutex_lock(&pl->state_mutex);
+
+	/* phylink instance is being destroyed, ignore any event */
+	if (pl->pcs_state == PCS_STATE_DETACHING)
+		goto exit;
+
+	/*
+	 * Loop all the PCS for phylink instance and check if
+	 * this notification is relevant for some of them.
+	 */
+	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
+		if (!fwnode_pcs_matches_provider(pp, pl->fwnode, pcs))
+			continue;
+
+		phylink_del_pcs(pl, pcs);
+		resolve = true;
+	}
+
+	/* Exit early if nothing has changed */
+	if (!resolve)
+		goto exit;
+
+	/* 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);
+
+	/* Recalculate capabilities */
+	phylink_update_capabilities(pl, &pl->link_config);
+
+exit:
+	mutex_unlock(&pl->state_mutex);
+	if (phydev)
+		mutex_unlock(&phydev->lock);
+	mutex_unlock(&pl->phydev_mutex);
+	rtnl_unlock();
+
+	if (resolve)
+		phylink_run_resolve(pl);
+
+	return resolve ? NOTIFY_OK : NOTIFY_DONE;
+}
+
+static void phylink_detach_pcss(struct phylink *pl)
+{
+	struct phylink_pcs *pcs, *tmp;
+	bool rcu_sync = false;
+
+	mutex_lock(&pl->state_mutex);
+
+	pl->pcs_state = PCS_STATE_DETACHING;
+
+	/* Remove every PCS from phylink PCS list */
+	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
+		rcu_assign_pointer(pcs->phylink, NULL);
+		list_del(&pcs->list);
+		rcu_sync = true;
+	}
+
+	if (pl->pcs) {
+		rcu_assign_pointer(pl->pcs->phylink, NULL);
+		WRITE_ONCE(pl->pcs, NULL);
+		rcu_sync = true;
+	}
+
+	if (rcu_sync)
+		synchronize_rcu();
+
+	mutex_unlock(&pl->state_mutex);
+
+	/* Unregister notifier for late PCS attach */
+	if (pl->fwnode_pcs_nb.notifier_call)
+		unregister_fwnode_pcs_notifier(&pl->fwnode_pcs_nb);
+}
+
 /**
  * phylink_create() - create a phylink instance
  * @config: a pointer to the target &struct phylink_config
@@ -2446,7 +2599,7 @@ struct phylink *phylink_create(struct phylink_config *config,
 			       phy_interface_t iface,
 			       const struct phylink_mac_ops *mac_ops)
 {
-	struct phylink_pcs *tmp, *pcs;
+	struct phylink_pcs *pcs;
 	struct phylink *pl;
 	int ret;
 
@@ -2515,10 +2668,18 @@ 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);
 
+	/* First register notifier for hotplug PCS events */
+	if (!phy_interface_empty(config->pcs_interfaces)) {
+		pl->fwnode_pcs_nb.notifier_call = pcs_provider_notify;
+		register_fwnode_pcs_notifier(&pl->fwnode_pcs_nb);
+	}
+
 	/* Fill the PCS list with available PCS from phylink config */
 	ret = phylink_fill_available_pcs(pl, config);
 	if (ret < 0)
-		goto free_pl;
+		goto unregister_pcs_notify;
+
+	mutex_lock(&pl->state_mutex);
 
 	/* Link available PCS to phylink */
 	list_for_each_entry(pcs, &pl->pcs_list, list)
@@ -2533,13 +2694,13 @@ struct phylink *phylink_create(struct phylink_config *config,
 				 pl->supported_interfaces,
 				 pcs->supported_interfaces);
 
-	mutex_lock(&pl->state_mutex);
 	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);
@@ -2558,14 +2719,10 @@ struct phylink *phylink_create(struct phylink_config *config,
 release_link_gpio:
 	if (pl->link_gpio)
 		gpiod_put(pl->link_gpio);
-unlink_pcs_list:
-	list_for_each_entry(pcs, &pl->pcs_list, list)
-		rcu_assign_pointer(pcs->phylink, NULL);
-
-	synchronize_rcu();
-
-	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list)
-		list_del(&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:
 	fwnode_handle_put(pl->fwnode);
 	kfree(pl);
@@ -2584,29 +2741,15 @@ EXPORT_SYMBOL_GPL(phylink_create);
  */
 void phylink_destroy(struct phylink *pl)
 {
-	struct phylink_pcs *pcs, *tmp;
-
 	sfp_bus_del_upstream(pl->sfp_bus);
 	phylink_destroy_sfp_cage_port(pl);
 	if (pl->link_gpio)
 		gpiod_put(pl->link_gpio);
 
-	/* Remove phylink instance from every PCS */
-	list_for_each_entry(pcs, &pl->pcs_list, list)
-		rcu_assign_pointer(pcs->phylink, NULL);
-
-	if (pl->pcs)
-		rcu_assign_pointer(pl->pcs->phylink, NULL);
-
-	if (pl->pcs || !list_empty(&pl->pcs_list))
-		synchronize_rcu();
+	phylink_detach_pcss(pl);
 
 	cancel_work_sync(&pl->resolve);
 
-	/* Remove every PCS from phylink PCS list */
-	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list)
-		list_del(&pcs->list);
-
 	fwnode_handle_put(pl->fwnode);
 
 	kfree(pl);
diff --git a/include/linux/pcs/pcs.h b/include/linux/pcs/pcs.h
index ef2134c578c7..83e0a2ad4b09 100644
--- a/include/linux/pcs/pcs.h
+++ b/include/linux/pcs/pcs.h
@@ -4,7 +4,38 @@
 
 #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.
+ *
+ * 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.
+ *
+ * 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
@@ -19,6 +50,27 @@
 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
+ * @fwnode: firmware node containing the PCS references
+ * @pl_pcs: PCS to check
+ *
+ * Parse the PCS references from the "pcs-handle" property of a firmware node
+ * and use provider to determine whether pl_pcs is one of the PCS provided by
+ * provider.
+ *
+ * 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 pl_pcs is provided by provider and referenced by fwnode,
+ * false otherwise.
+ */
+bool fwnode_pcs_matches_provider(struct fwnode_pcs_provider *provider,
+				 const struct fwnode_handle *fwnode,
+				 struct phylink_pcs *pl_pcs);
+
 /**
  * fwnode_phylink_pcs_count - Count PCS entries described in firmware node
  * @fwnode: firmware node
@@ -52,12 +104,29 @@ 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 fwnode_handle *fwnode,
+					       struct phylink_pcs *pl_pcs)
+{
+	return false;
+}
+
 static inline unsigned int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode)
 {
 	return 0;
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 09/15] net: phylink: support late PCS provider attach
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
                   ` (7 preceding siblings ...)
  2026-11-17 12:39 ` [PATCH net-next v22 08/15] net: phylink: support PCS provider release Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-21 23:26   ` Jakub Kicinski
  2026-11-17 12:39 ` [PATCH net-next v22 10/15] net: Document PCS subsystem Christian Marangi
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

Add support for late PCS provider attachment to a phylink instance.
Similar to FWNODE_PCS_PROVIDER_DEL, FWNODE_PCS_PROVIDER_ADD is added to
address the case where a PCS provider is added after a phylink instance is
created and started.

The PCS notifier will emit the event FWNODE_PCS_PROVIDER_ADD every time
a new PCS provider is added.

If a related PCS is found, then such PCS is added to the phylink
instance PCS list.

Such PCS is then linked to the phylink instance and the supported
interfaces of the phylink instance get refreshed.

If we are in a major_config_failed scenario an interface reconfiguration
is triggered in the next phylink resolve with a new phylink resolve right
after with the new AN mode reevaluated if a new PCS is selected.

In the example scenario where the link was previously torn down due to
removal of PCS, the link will be established again as the PCS came back
and is now available to phylink.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/pcs/pcs.c     |  22 ++++++++
 drivers/net/phy/phylink.c | 110 ++++++++++++++++++++++++++++++--------
 include/linux/pcs/pcs.h   |  31 +++++++++++
 3 files changed, 141 insertions(+), 22 deletions(-)

diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c
index f234a4635417..0a4853b756fb 100644
--- a/drivers/net/pcs/pcs.c
+++ b/drivers/net/pcs/pcs.c
@@ -69,6 +69,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;
@@ -201,6 +205,24 @@ struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode, unsigned
 }
 EXPORT_SYMBOL_GPL(fwnode_pcs_get);
 
+struct phylink_pcs *fwnode_pcs_get_from_provider(struct fwnode_pcs_provider *provider,
+						 const struct fwnode_handle *fwnode,
+						 int index)
+{
+	struct fwnode_reference_args pcsspec;
+	struct phylink_pcs *pcs;
+	int ret;
+
+	ret = fwnode_parse_pcsspec(fwnode, index, NULL, &pcsspec);
+	if (ret)
+		return ERR_PTR(ret);
+
+	pcs = __fwnode_pcs_get_from_pcsspec_provider(&pcsspec, provider);
+	fwnode_handle_put(pcsspec.fwnode);
+	return pcs;
+}
+EXPORT_SYMBOL_GPL(fwnode_pcs_get_from_provider);
+
 bool fwnode_pcs_matches_provider(struct fwnode_pcs_provider *provider,
 				 const struct fwnode_handle *fwnode,
 				 struct phylink_pcs *pl_pcs)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 094a15f3dbcd..8768d8220a13 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -112,6 +112,7 @@ struct phylink {
 
 	struct sfp_bus *sfp_bus;
 	bool sfp_may_have_phy;
+	DECLARE_PHY_INTERFACE_MASK(sfp_module_interfaces);
 	DECLARE_PHY_INTERFACE_MASK(sfp_interfaces);
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
 	u8 sfp_port;
@@ -2140,6 +2141,35 @@ int phylink_set_fixed_link(struct phylink *pl,
 }
 EXPORT_SYMBOL_GPL(phylink_set_fixed_link);
 
+static bool phylink_add_pcs(struct phylink *pl, struct phylink_pcs *pcs)
+{
+	struct phylink_pcs *tmp;
+
+	/*
+	 * Make sure state mutex is locked to protect concurrent
+	 * access to phylink instance PCS list from
+	 * initial fill_available_pcs and late PCS attach
+	 */
+	lockdep_assert_held(&pl->state_mutex);
+
+	/* Make sure PCS is not already in the list */
+	list_for_each_entry(tmp, &pl->pcs_list, list)
+		if (tmp == pcs)
+			return false;
+
+	if (WARN(rcu_access_pointer(pcs->phylink),
+		 "%s: PCS already attached to a phylink instance\n",
+		 __func__))
+		return false;
+
+	list_add_tail(&pcs->list, &pl->pcs_list);
+
+	/* Link PCS to phylink */
+	rcu_assign_pointer(pcs->phylink, pl);
+
+	return true;
+}
+
 static int phylink_fill_available_pcs(struct phylink *pl,
 				      struct phylink_config *config)
 {
@@ -2172,12 +2202,7 @@ static int phylink_fill_available_pcs(struct phylink *pl,
 		if (!pcs)
 			continue;
 
-		if (WARN(rcu_access_pointer(pcs->phylink),
-			 "%s: PCS already attached to a phylink instance\n",
-			 __func__))
-			continue;
-
-		list_add_tail(&pcs->list, &pl->pcs_list);
+		phylink_add_pcs(pl, pcs);
 	}
 
 out:
@@ -2358,11 +2383,24 @@ static void phylink_update_capabilities(struct phylink *pl,
 		goto exit;
 	}
 
-	/* Revalidate the SFP module modes against every available interface. */
+	/* Revalidate SFP modes against interfaces currently supported by the
+	 * MAC and PCS. Keep the module's interface list intact so a later PCS
+	 * addition can make an interface usable again.
+	 */
 	if (pl->sfp_bus && !pl->phydev && config->interface &&
-	    !phy_interface_empty(pl->sfp_interfaces)) {
+	    !phy_interface_empty(pl->sfp_module_interfaces)) {
 		__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
 
+		phy_interface_and(pl->sfp_interfaces,
+				  pl->sfp_module_interfaces,
+				  pl->supported_interfaces);
+		if (phy_interface_empty(pl->sfp_interfaces)) {
+			linkmode_zero(pl->supported);
+			linkmode_zero(pl->advertising);
+			linkmode_zero(config->advertising);
+			goto exit;
+		}
+
 		linkmode_copy(supported, pl->sfp_support);
 		linkmode_copy(config->advertising, pl->sfp_support);
 		if (!__phylink_validate_mask(pl, NULL, supported, config,
@@ -2494,6 +2532,7 @@ static int pcs_provider_notify(struct notifier_block *self,
 	struct phylink_pcs *pcs, *tmp;
 	struct phy_device *phydev;
 	bool resolve = false;
+	int count, i;
 
 	rtnl_lock();
 	mutex_lock(&pl->phydev_mutex);
@@ -2506,16 +2545,44 @@ static int pcs_provider_notify(struct notifier_block *self,
 	if (pl->pcs_state == PCS_STATE_DETACHING)
 		goto exit;
 
-	/*
-	 * Loop all the PCS for phylink instance and check if
-	 * this notification is relevant for some of them.
-	 */
-	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
-		if (!fwnode_pcs_matches_provider(pp, pl->fwnode, pcs))
-			continue;
+	switch (val) {
+	case FWNODE_PCS_PROVIDER_ADD:
+		count = fwnode_phylink_pcs_count(pl->fwnode);
+		for (i = 0; i < count; i++) {
+			pcs = fwnode_pcs_get_from_provider(pp, pl->fwnode, i);
+			if (IS_ERR_OR_NULL(pcs))
+				continue;
+
+			/* Trigger a resolve only if a PCS is actually added */
+			if (phylink_add_pcs(pl, pcs))
+				resolve = true;
+		}
+
+		/*
+		 * Force an interface reconfig if major config failed.
+		 * Configure link_failed to retrigger a resolve a
+		 * second time to reevaluate AN mode with the new
+		 * PCS if selected.
+		 */
+		if (resolve && pl->major_config_failed) {
+			pl->force_major_config = true;
+			pl->link_failed = true;
+		}
+
+		break;
+	case FWNODE_PCS_PROVIDER_DEL:
+		/*
+		 * Loop all the PCS for phylink instance and check if
+		 * this notification is relevant for some of them.
+		 */
+		list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
+			if (!fwnode_pcs_matches_provider(pp, pl->fwnode, pcs))
+				continue;
 
-		phylink_del_pcs(pl, pcs);
-		resolve = true;
+			phylink_del_pcs(pl, pcs);
+			resolve = true;
+		}
+		break;
 	}
 
 	/* Exit early if nothing has changed */
@@ -2681,10 +2748,6 @@ struct phylink *phylink_create(struct phylink_config *config,
 
 	mutex_lock(&pl->state_mutex);
 
-	/* Link available PCS to phylink */
-	list_for_each_entry(pcs, &pl->pcs_list, list)
-		rcu_assign_pointer(pcs->phylink, pl);
-
 	phy_interface_copy(pl->supported_interfaces,
 			   pl->config->supported_interfaces);
 
@@ -4424,6 +4487,7 @@ static int phylink_sfp_config_phy(struct phylink *pl, struct phy_device *phy)
 
 	/* We're not using pl->sfp_interfaces, so clear it. */
 	phy_interface_zero(pl->sfp_interfaces);
+	phy_interface_zero(pl->sfp_module_interfaces);
 	linkmode_copy(support, phy->supported);
 
 	memset(&config, 0, sizeof(config));
@@ -4485,7 +4549,7 @@ static int phylink_sfp_config_optical(struct phylink *pl)
 	 * the SFP module.
 	 */
 	phy_interface_and(pl->sfp_interfaces, pl->supported_interfaces,
-			  pl->sfp_interfaces);
+			  pl->sfp_module_interfaces);
 	if (phy_interface_empty(pl->sfp_interfaces)) {
 		phylink_err(pl, "unsupported SFP module: no common interface modes\n");
 		return -EINVAL;
@@ -4556,6 +4620,7 @@ static int phylink_sfp_module_insert(void *upstream,
 	ASSERT_RTNL();
 
 	caps = sfp_get_module_caps(pl->sfp_bus);
+	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);
 	pl->sfp_may_have_phy = caps->may_have_phy;
@@ -4573,6 +4638,7 @@ static void phylink_sfp_module_remove(void *upstream)
 	struct phylink *pl = upstream;
 
 	phy_interface_zero(pl->sfp_interfaces);
+	phy_interface_zero(pl->sfp_module_interfaces);
 }
 
 static int phylink_add_sfp_mod_port(struct phylink *pl)
diff --git a/include/linux/pcs/pcs.h b/include/linux/pcs/pcs.h
index 83e0a2ad4b09..a6fe9f71174a 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,
 };
 
@@ -50,6 +51,28 @@ int unregister_fwnode_pcs_notifier(struct notifier_block *nb);
 struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode,
 				   unsigned int index);
 
+/**
+ * fwnode_pcs_get_from_provider() - Retrieve a PCS from a specific provider
+ * @provider: PCS provider to use
+ * @fwnode: firmware node
+ * @index: index fwnode PCS handle in firmware node
+ *
+ * Get a PCS from the firmware node at index specifically provided by
+ * passed PCS provider.
+ *
+ * Unlike fwnode_pcs_get(), this function does not search the global list of
+ * PCS providers. The caller must provide the provider responsible for the
+ * referenced PCS.
+ *
+ * Returns: a pointer to the phylink_pcs, NULL or a negative error pointer. Can
+ * return -EINVAL if the PCS provider firmware node doesn't match the referenced
+ * firmware node or a negative error pointer (or NULL) from the PCS provider
+ * xlate function for the relevant firmware node and PCS handle index.
+ */
+struct phylink_pcs *fwnode_pcs_get_from_provider(struct fwnode_pcs_provider *provider,
+						 const struct fwnode_handle *fwnode,
+						 int index);
+
 /**
  * fwnode_pcs_matches_provider() - Check whether a PCS belongs to a provider
  * @provider: PCS provider to check
@@ -120,6 +143,14 @@ static inline struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwn
 	return ERR_PTR(-ENOENT);
 }
 
+static inline struct phylink_pcs *
+fwnode_pcs_get_from_provider(struct fwnode_pcs_provider *provider,
+			     const struct fwnode_handle *fwnode,
+			     int index)
+{
+	return ERR_PTR(-ENOENT);
+}
+
 static inline bool fwnode_pcs_matches_provider(struct fwnode_pcs_provider *provider,
 					       const struct fwnode_handle *fwnode,
 					       struct phylink_pcs *pl_pcs)
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 10/15] net: Document PCS subsystem
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
                   ` (8 preceding siblings ...)
  2026-11-17 12:39 ` [PATCH net-next v22 09/15] net: phylink: support late PCS provider attach Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-21 23:26   ` Jakub Kicinski
  2026-11-17 12:39 ` [PATCH net-next v22 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
                   ` (4 subsequent siblings)
  14 siblings, 1 reply; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

Add extensive documentation of the new PCS subsystem and the fwnode
implementation with producer/consumer API.

Also update the sfp-phylink migration guide.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 Documentation/networking/index.rst       |   1 +
 Documentation/networking/pcs.rst         | 231 +++++++++++++++++++++++
 Documentation/networking/sfp-phylink.rst |  35 ++--
 3 files changed, 243 insertions(+), 24 deletions(-)
 create mode 100644 Documentation/networking/pcs.rst

diff --git a/Documentation/networking/index.rst b/Documentation/networking/index.rst
index 44a422ad3b05..3fce8f6ac089 100644
--- a/Documentation/networking/index.rst
+++ b/Documentation/networking/index.rst
@@ -28,6 +28,7 @@ Contents:
    net_failover
    page_pool
    phy
+   pcs
    sfp-phylink
    alias
    bridge
diff --git a/Documentation/networking/pcs.rst b/Documentation/networking/pcs.rst
new file mode 100644
index 000000000000..71d1283a72cd
--- /dev/null
+++ b/Documentation/networking/pcs.rst
@@ -0,0 +1,231 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=============
+PCS Subsystem
+=============
+
+The PCS (Physical Coding Sublayer) subsystem handles the registration and lookup
+of PCS devices. These devices contain the upper sublayers of the Ethernet
+physical layer, generally handling framing, scrambling, and encoding tasks. PCS
+devices may also include PMA (Physical Medium Attachment) components. PCS
+devices transfer data between the Link-layer MAC device, and the rest of the
+physical layer, typically via a serdes. The output of the serdes may be
+connected more-or-less directly to the medium when using fiber-optic or
+backplane connections (1000BASE-SX, 1000BASE-KX, etc). It may also communicate
+with a separate PHY (such as over SGMII) which handles the connection to the
+medium (such as 1000BASE-T).
+
+Remark on usage of .mac_select_pcs and fw_node PCS
+--------------------------------------------------
+
+There are generally two ways to look up a PCS device.
+
+1. MAC OP struct .mac_select_pcs (considered deprecated)
+2. Internal PCS handling with ``num_possible_pcs`` and ``fill_available_pcs``
+
+Implementation 1 leaves the entire handling of the PCS to the MAC
+driver with the selection of the PCS driven by .mac_select_pcs.
+Custom implementations are required if the PCS is external to the MAC
+and needs to be handled by a separate driver.
+
+Implementation 2 makes the phylink core code to select the PCS
+provided by ``num_possible_pcs`` and ``fill_available_pcs`` either
+via internal MAC handling or firmware node (fwnode)
+
+Implementation 1 is considered deprecated and it's suggested to
+switch to implementation 2 and where possible switch to firmware
+node design.
+
+.. _pcs_fwnode:
+
+Looking up PCS Devices (fwnode implementation)
+-----------------------------------------------
+
+The lookup of a PCS device follows the common producer/consumer implementation
+used by similar subsystems with a ``#pcs-cells`` on the producer and a
+``pcs-handle`` property on the consumer::
+
+    pcs: pcs {
+        // ...
+        #pcs-cells = <0>;
+    };
+
+    ethernet-controller {
+        // ...
+        pcs-handle = <&pcs>;
+    };
+
+On :c:func:`phylink_create`, phylink will use the ``num_possible_pcs``
+value and ``fill_available_pcs`` helper function in
+:c:struct:`phylink_config` to compose the list of available PCS that can be
+used for the phylink instance.
+
+Phylink will then internally handle the selection of the correct PCS for
+the requested interface mode based on the interface modes configured in
+``pcs_interfaces`` in :c:struct:`phylink_config` struct and
+``supported_interfaces`` in :c:struct:`phylink_pcs` struct.
+
+A PCS is considered eligible when the requested interface mode is present
+in both ``pcs_interfaces`` in :c:struct:`phylink_config` struct and
+``supported_interfaces`` in :c:struct:`phylink_pcs` struct.
+
+``supported_interfaces`` describes all interface modes supported by the MAC,
+whereas ``pcs_interfaces`` identifies the subset that require PCS selection.
+
+For the special implementation where the PCS is internal or part of the MAC
+and a dedicated driver is not needed, it's possible to leave the implementation
+of the PCS to the MAC driver and just implement the ``num_possible_pcs``
+value and ``fill_available_pcs`` helper  function in
+:c:struct:`phylink_config` referencing the local :c:struct:`phylink_pcs`
+struct allocated from the MAC driver.
+
+.. _pcs_consumer:
+
+Using PCS Devices
+-----------------
+
+It's mandatory to either implement the ``mac_select_pcs`` callback
+of :c:struct:`phylink_mac_ops` or ``num_possible_pcs`` and ``fill_available_pcs``
+of :c:struct:`phylink_config` to use a PCS for a MAC.
+
+The fwnode implementation exposes simple helpers to parse the PCS from
+the fwnode :c:func:`fwnode_phylink_pcs_count` and
+:c:func:`fwnode_phylink_pcs_parse`. The :c:func:`fwnode_phylink_pcs_count` helper
+takes the fwnode where the ``pcs-handle`` should be parsed and return the
+number of PCS entries described in the fwnode.
+The :c:func:`fwnode_phylink_pcs_parse` helper takes three arguments,
+the fwnode where the ``pcs-handle`` should be parsed, an allocated array
+of :c:struct:`phylink_pcs` pointer where to put the parsed PCS from the fwnode
+and the maximum number of PCS to parse.
+Contrary to :c:func:`fwnode_phylink_pcs_count`, :c:func:`fwnode_phylink_pcs_parse`
+helper fills the allocated array with ONLY the available PCS and return the
+number of available PCS found. PCS that returns -ENODEV will be skipped and
+won't be inserted in the allocated array.
+
+A phylink instance may use multiple PCS devices. The maximum number is reported
+through ``num_possible_pcs``.
+
+It's mandatory to specify for what interface a PCS is needed. This can be done
+by filling the ``pcs_interfaces`` in :c:struct:`phylink_config` struct.
+If the requested interface mode is not present in this bitmask, phylink does
+not search for a PCS for  that specific mode. (example MAC doesn't need a PCS
+for SGMII but require one for USXGMII)
+
+With the use of the :c:func:`fwnode_phylink_pcs_parse` a common implementation
+is the following::
+
+   static int mac_fill_available_pcs(struct phylink_config *config,
+   				                      struct phylink_pcs **available_pcs,
+					                      unsigned int num_possible_pcs)
+   {
+   	struct device *dev = config->dev;
+
+   	return fwnode_phylink_pcs_parse(dev_fwnode(dev), available_pcs,
+						                    num_possible_pcs);
+   }
+
+   static int mac_setup_phylink(struct net_device *netdev)
+   {
+      struct phylink_config *config;
+
+      // ...
+
+      config->dev = &netdev->dev;
+
+      // ...
+
+      // Parse possible PCS and fill num_possible_pcs.
+      config->num_possible_pcs = fwnode_phylink_pcs_count(dev_fwnode(&netdev->dev));
+      config->fill_available_pcs = mac_fill_available_pcs;
+
+      __set_bit(PHY_INTERFACE_MODE_INTERNAL, config->supported_interfaces);
+      __set_bit(PHY_INTERFACE_MODE_SGMII, config->supported_interfaces);
+      __set_bit(PHY_INTERFACE_MODE_1000BASEX, config->supported_interfaces);
+      __set_bit(PHY_INTERFACE_MODE_USXGMII, config->supported_interfaces);
+
+      // PCS required only for USXGMII
+      __set_bit(PHY_INTERFACE_MODE_USXGMII, config->pcs_interfaces);
+
+      phylink = phylink_create(config, //...
+
+It's worth to mention that it's phylink code that takes care of allocating
+the array of :c:struct:`phylink_pcs` pointer for ``fill_available_pcs``
+callback based on the value set in ``num_possible_pcs`` for
+:c:struct:`phylink_config` struct.
+
+The ``fill_available_pcs`` callback must not write more than
+``num_possible_pcs`` entries. The third argument may be used to validate
+that there is enough space to fill all the available PCS in the passed array
+of :c:struct:`phylink_pcs` pointer.
+
+The ``fill_available_pcs`` callback is called only on :c:func:`phylink_create`
+and is used only to compose the initial available PCS list. Ownership of PCS
+is held by phylink.
+
+.. _pcs_producer:
+
+Writing PCS Drivers
+-------------------
+
+To write a PCS driver, first implement :c:struct:`phylink_pcs_ops`. Then,
+register your PCS in your probe function using :c:func:`fwnode_pcs_add_provider`.
+The :c:func:`fwnode_pcs_add_provider` takes three arguments, the fwnode where
+the PCS provider should be registered to, a xlate function to return the requested
+PCS based on ``#pcs-cells`` and a pointer to reference private data for the xlate
+function.
+
+The PCS will then be registered to a global list of PCS provider that the
+PCS fwnode implementation will use to parse it.
+
+For the simple case where the PCS driver expose a single PCS,
+:c:func:`fwnode_pcs_simple_xlate` can be used as the xlate function.
+
+You must call :c:func:`fwnode_pcs_del_provider` from your remove function
+on driver detach.
+
+A devm variant, :c:func:`devm_fwnode_pcs_add_provider`, is available to
+automatically release the PCS provider on driver detach.
+
+It's worth to mention that xlate function MUST reference already allocated
+:c:struct:`phylink_pcs` pointer and MUST NOT dynamically allocate new PCS.
+The returned pointer is used to identify the PCS across provider lookup and
+removal notifications.
+
+Late PCS registration handling
+------------------------------
+
+It's possible that a PCS becomes available after the MAC finished probing.
+Contrary to the usual producer/consumer implementation, when a PCS is not
+registered and can't be found, the fwnode parser helper returns ``-ENODEV``
+instead of ``-EPROBE_DEFER``.
+
+This is to prevent race condition with particular devices that register
+MAC and PCS with USB or PCIe and require the MAC to be registered before
+the PCS.
+
+The phylink logic correctly handle this special case and keep the phylink
+instance in a fail condition.
+
+The PCS fwnode implementation provides a notifier to which each phylink
+instance with a non-empty ``pcs_interfaces`` in :c:type:`phylink_config`
+registers. When a new PCS provider is registered, the notifier is called
+triggering the :c:func:`pcs_provider_notify` function.
+
+Function :c:func:`pcs_provider_notify` will check if the just added PCS
+should be used by the phylink instance. If it should be used then,
+it's added to the internal list of available PCS and a phylink major
+config is forced.
+
+If a phylink instance was in a failure state, with the just added PCS
+now part of the available PCS internal phylink list, provided all other
+conditions are satisfied, the configuration is retried and the failure
+condition is cleared.
+
+API Reference
+-------------
+
+.. kernel-doc:: include/linux/pcs/pcs.h
+   :internal:
+
+.. kernel-doc:: include/linux/pcs/pcs-provider.h
+   :internal:
diff --git a/Documentation/networking/sfp-phylink.rst b/Documentation/networking/sfp-phylink.rst
index 5bf285d73e8a..306505118eba 100644
--- a/Documentation/networking/sfp-phylink.rst
+++ b/Documentation/networking/sfp-phylink.rst
@@ -311,33 +311,20 @@ this documentation.
 
         priv->pcs = lynx_pcs_create_mdiodev(bus, 0);
 
-    Some PCS can be recovered based on firmware information:
+    PCS that should be recovered based on firmware information should implement
+    the external PCS as a :ref:`PCS provider <pcs_producer>` and reference it
+    with the use of PCS fwnode helper :ref:`PCS fwnode helper <pcs_fwnode>`.
 
-    .. code-block:: c
-
-        priv->pcs = lynx_pcs_create_fwnode(of_fwnode_handle(node));
-
-12. Populate the :c:func:`mac_select_pcs` callback and add it to your
-    :c:type:`struct phylink_mac_ops <phylink_mac_ops>` set of ops. This function
-    must return a pointer to the relevant :c:type:`struct phylink_pcs <phylink_pcs>`
-    that will be used for the requested link configuration:
-
-    .. code-block:: c
-
-        static struct phylink_pcs *foo_select_pcs(struct phylink_config *config,
-                                                  phy_interface_t interface)
-        {
-                struct foo_priv *priv = container_of(config, struct foo_priv,
-                                                     phylink_config);
-
-                if ( /* 'interface' needs a PCS to function */ )
-                        return priv->pcs;
+12. Populate the :c:var:`num_possible_pcs` value and
+    :c:func:`fill_available_pcs` callback and add it to your
+    :c:type:`struct phylink_config <phylink_config>`.
 
-                return NULL;
-        }
+    Refer to :ref:`Documentation/networking/pcs.rst <pcs_consumer>` for
+    further details and examples.
 
-    See :c:func:`mvpp2_select_pcs` for an example of a driver that has multiple
-    internal PCS.
+    Notice that the previous implementation of populating
+    :c:func:`mac_select_pcs` is considered deprecated in favor of the new
+    described above.
 
 13. Fill-in all the :c:type:`phy_interface_t <phy_interface_t>` (i.e. all MAC to
     PHY link modes) that your MAC can output. The following example shows a
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 11/15] MAINTAINERS: add myself as PCS subsystem maintainer
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
                   ` (9 preceding siblings ...)
  2026-11-17 12:39 ` [PATCH net-next v22 10/15] net: Document PCS subsystem Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-17 12:39 ` [PATCH net-next v22 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

List all the files of the Ethernet PCS subsystem and add myself as
maintainer.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 MAINTAINERS | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 32e218c0fe68..ccd2d04c5a07 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10034,6 +10034,15 @@ F:	include/uapi/linux/if_bridge.h
 F:	include/linux/netfilter_bridge/
 F:	net/bridge/
 
+ETHERNET PCS SUBSYSTEM
+M:	Christian Marangi <ansuelsmth@gmail.com>
+L:	netdev@vger.kernel.org
+S:	Maintained
+F:	Documentation/networking/pcs.rst
+F:	drivers/net/pcs/pcs.c
+F:	include/linux/pcs/pcs-provider.h
+F:	include/linux/pcs/pcs.h
+
 ETHERNET PHY LIBRARY
 M:	Andrew Lunn <andrew@lunn.ch>
 M:	Heiner Kallweit <hkallweit1@gmail.com>
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 12/15] net: phylink: add .pcs_link_down PCS OP
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
                   ` (10 preceding siblings ...)
  2026-11-17 12:39 ` [PATCH net-next v22 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-17 12:39 ` [PATCH net-next v22 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

Permit for PCS driver to define specific operation to tear down the link
between the MAC and the PCS.

This might be needed for some PCS that reset counter or require special
reset to correctly work if the link needs to be restored later.

On phylink_link_down() call, the additional phylink_pcs_link_down() will
be called after .mac_link_down to tear down the link.

PCS driver will need to define .pcs_link_down to make use of this.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/net/phy/phylink.c |  9 +++++++++
 include/linux/phylink.h   | 12 ++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 8768d8220a13..bf1c5188131f 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -1142,6 +1142,12 @@ static void phylink_pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
 		pcs->ops->pcs_link_up(pcs, neg_mode, interface, speed, duplex);
 }
 
+static void phylink_pcs_link_down(struct phylink_pcs *pcs)
+{
+	if (pcs && pcs->ops->pcs_link_down)
+		pcs->ops->pcs_link_down(pcs);
+}
+
 static void phylink_pcs_disable_eee(struct phylink_pcs *pcs)
 {
 	if (pcs && pcs->ops->pcs_disable_eee)
@@ -1854,6 +1860,9 @@ static void phylink_link_down(struct phylink *pl)
 
 	pl->mac_ops->mac_link_down(pl->config, pl->act_link_an_mode,
 				   pl->cur_interface);
+
+	phylink_pcs_link_down(pl->pcs);
+
 	phylink_info(pl, "Link is Down\n");
 }
 
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index 418e8bec311d..e8c3f693336a 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -528,6 +528,7 @@ struct phylink_pcs {
  * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
  * @pcs_link_up: program the PCS for the resolved link configuration
  *               (where necessary).
+ * @pcs_link_down: tear down link between MAC and PCS.
  * @pcs_disable_eee: optional notification to PCS that EEE has been disabled
  *		     at the MAC.
  * @pcs_enable_eee: optional notification to PCS that EEE will be enabled at
@@ -555,6 +556,7 @@ struct phylink_pcs_ops {
 	void (*pcs_an_restart)(struct phylink_pcs *pcs);
 	void (*pcs_link_up)(struct phylink_pcs *pcs, unsigned int neg_mode,
 			    phy_interface_t interface, int speed, int duplex);
+	void (*pcs_link_down)(struct phylink_pcs *pcs);
 	void (*pcs_disable_eee)(struct phylink_pcs *pcs);
 	void (*pcs_enable_eee)(struct phylink_pcs *pcs);
 	int (*pcs_pre_init)(struct phylink_pcs *pcs);
@@ -690,6 +692,16 @@ void pcs_an_restart(struct phylink_pcs *pcs);
 void pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
 		 phy_interface_t interface, int speed, int duplex);
 
+/**
+ * pcs_link_down() - tear down link between MAC and PCS
+ * @pcs: a pointer to a &struct phylink_pcs.
+ *
+ * This call will be made just after mac_link_down() to inform the PCS the
+ * link has gone down. PCS should be configured to stop processing packets
+ * for transmission and reception.
+ */
+void pcs_link_down(struct phylink_pcs *pcs);
+
 /**
  * pcs_disable_eee() - Disable EEE at the PCS
  * @pcs: a pointer to a &struct phylink_pcs
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
                   ` (11 preceding siblings ...)
  2026-11-17 12:39 ` [PATCH net-next v22 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-21 23:26   ` Jakub Kicinski
  2026-11-17 12:39 ` [PATCH net-next v22 15/15] net: airoha: add phylink support Christian Marangi
  2026-11-17 12:43 ` [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS netdev-bot+sinfo
  14 siblings, 1 reply; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

Document support for Airoha Ethernet PCS for AN7581 SoC.

Airoha AN7581 SoC expose multiple Physical Coding Sublayer (PCS) for
the various Serdes port supporting different Media Independent Interface
(10BASE-R, USXGMII, 2500BASE-X, 1000BASE-X, SGMII).

This follow the new PCS provider with the use of #pcs-cells property.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
---
 .../bindings/net/pcs/airoha,pcs.yaml          | 261 ++++++++++++++++++
 1 file changed, 261 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml

diff --git a/Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml b/Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml
new file mode 100644
index 000000000000..9c1d116c1b01
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml
@@ -0,0 +1,261 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/pcs/airoha,pcs.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Airoha Ethernet PCS and Serdes
+
+maintainers:
+  - Christian Marangi <ansuelsmth@gmail.com>
+
+description:
+  Airoha AN7581 SoC expose multiple Physical Coding Sublayer (PCS) for
+  the various Serdes port supporting different Media Independent Interface
+  (10BASE-R, USXGMII, 2500BASE-X, 1000BASE-X, SGMII).
+
+properties:
+  compatible:
+    enum:
+      - airoha,an7581-pcs-eth
+      - airoha,an7581-pcs-pon
+      - airoha,an7581-pcs-pcie
+      - airoha,an7581-pcs-usb
+
+  reg:
+    minItems: 6
+    maxItems: 15
+
+  reg-names:
+    minItems: 6
+    maxItems: 15
+
+  airoha,scu:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: phandle to the SCU node required to configure
+      the serdes line to the correct interface mode.
+
+  phys:
+    maxItems: 1
+
+  "#pcs-cells": true
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - "#pcs-cells"
+
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - airoha,an7581-pcs-eth
+              - airoha,an7581-pcs-pon
+
+    then:
+      properties:
+        reg:
+          items:
+            - description: PCS MAC reg
+            - description: HSGMII AN reg
+            - description: HSGMII PCS reg
+            - description: MULTI SGMII reg
+            - description: USXGMII reg
+            - description: HSGMII rate adaption reg
+            - description: PCS Analog register
+            - description: PCS PMA (Physical Medium Attachment) register
+
+        reg-names:
+          items:
+            - const: pcs_mac
+            - const: hsgmii_an
+            - const: hsgmii_pcs
+            - const: multi_sgmii
+            - const: usxgmii
+            - const: hsgmii_rate_adp
+            - const: pcs_ana
+            - const: pcs_pma
+
+        phys: false
+
+        "#pcs-cells":
+          const: 0
+
+      required:
+        - airoha,scu
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: airoha,an7581-pcs-pcie
+
+    then:
+      properties:
+        reg:
+          items:
+            - description: PCS MAC 0 reg
+            - description: HSGMII AN 0 reg
+            - description: HSGMII PCS 0 reg
+            - description: MULTI SGMII 0 reg
+            - description: USXGMII 0 reg
+            - description: HSGMII rate adaption 0 reg
+            - description: PCS MAC 1 reg
+            - description: HSGMII AN 1 reg
+            - description: HSGMII PCS 1 reg
+            - description: MULTI SGMII 1 reg
+            - description: USXGMII 1 reg
+            - description: HSGMII rate adaption 1 reg
+            - description: PCS Analog register
+            - description: PCS PMA (Physical Medium Attachment) 0 register
+            - description: PCS PMA (Physical Medium Attachment) 1 register
+
+        reg-names:
+          items:
+            - const: pcs_mac0
+            - const: hsgmii_an0
+            - const: hsgmii_pcs0
+            - const: multi_sgmii0
+            - const: usxgmii0
+            - const: hsgmii_rate_adp0
+            - const: pcs_mac1
+            - const: hsgmii_an1
+            - const: hsgmii_pcs1
+            - const: multi_sgmii1
+            - const: usxgmii1
+            - const: hsgmii_rate_adp1
+            - const: pcs_ana
+            - const: pcs_pma0
+            - const: pcs_pma1
+
+        phys: false
+
+        "#pcs-cells":
+          const: 1
+
+      required:
+        - airoha,scu
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: airoha,an7581-pcs-usb
+
+    then:
+      properties:
+        reg:
+          items:
+            - description: PCS MAC reg
+            - description: HSGMII AN reg
+            - description: HSGMII PCS reg
+            - description: MULTI SGMII reg
+            - description: HSGMII rate adaption reg
+            - description: PCS Analog register
+
+        reg-names:
+          items:
+            - const: pcs_mac
+            - const: hsgmii_an
+            - const: hsgmii_pcs
+            - const: multi_sgmii
+            - const: hsgmii_rate_adp
+            - const: pcs_ana
+
+        airoha,scu: false
+
+        "#pcs-cells":
+          const: 0
+
+      required:
+        - phys
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/phy/phy.h>
+
+    pcs@1fa08000 {
+      compatible = "airoha,an7581-pcs-pon";
+      reg = <0x1fa08000 0x1000>,
+            <0x1fa80000 0x60>,
+            <0x1fa80a00 0x164>,
+            <0x1fa84000 0x450>,
+            <0x1fa85900 0x338>,
+            <0x1fa86000 0x300>,
+            <0x1fa8a000 0x1000>,
+            <0x1fa8b000 0x1000>;
+      reg-names = "pcs_mac", "hsgmii_an", "hsgmii_pcs",
+                  "multi_sgmii", "usxgmii",
+                  "hsgmii_rate_adp", "pcs_ana", "pcs_pma";
+
+      airoha,scu = <&scuclk>;
+      #pcs-cells = <0>;
+    };
+
+    pcs@1fa09000 {
+      compatible = "airoha,an7581-pcs-eth";
+      reg = <0x1fa09000 0x1000>,
+            <0x1fa70000 0x60>,
+            <0x1fa70a00 0x164>,
+            <0x1fa74000 0x450>,
+            <0x1fa75900 0x338>,
+            <0x1fa76000 0x300>,
+            <0x1fa7a000 0x1000>,
+            <0x1fa7b000 0x1000>;
+      reg-names = "pcs_mac", "hsgmii_an", "hsgmii_pcs",
+                  "multi_sgmii", "usxgmii",
+                  "hsgmii_rate_adp", "pcs_ana", "pcs_pma";
+
+      airoha,scu = <&scuclk>;
+      #pcs-cells = <0>;
+    };
+
+    pcs@1fa04000 {
+      compatible = "airoha,an7581-pcs-pcie";
+      reg = <0x1fa04000 0x1000>,
+            <0x1fa50000 0x60>,
+            <0x1fa50a00 0x164>,
+            <0x1fa54000 0x450>,
+            <0x1fa55900 0x338>,
+            <0x1fa56000 0x300>,
+            <0x1fa05000 0x1000>,
+            <0x1fa60000 0x60>,
+            <0x1fa60a00 0x164>,
+            <0x1fa64000 0x450>,
+            <0x1fa65900 0x338>,
+            <0x1fa66000 0x300>,
+            <0x1fa5a000 0x1000>,
+            <0x1fa5b000 0x1000>,
+            <0x1fa5c000 0x1000>;
+      reg-names = "pcs_mac0", "hsgmii_an0", "hsgmii_pcs0",
+                  "multi_sgmii0", "usxgmii0",
+                  "hsgmii_rate_adp0",
+                  "pcs_mac1", "hsgmii_an1", "hsgmii_pcs1",
+                  "multi_sgmii1", "usxgmii1",
+                  "hsgmii_rate_adp1",
+                  "pcs_ana", "pcs_pma0", "pcs_pma1";
+
+      airoha,scu = <&scuclk>;
+      #pcs-cells = <1>;
+    };
+
+    pcs@1fa07000 {
+      compatible = "airoha,an7581-pcs-usb";
+      reg = <0x1fa07000 0x1000>,
+            <0x1fa90000 0x60>,
+            <0x1fa90a00 0x164>,
+            <0x1fa94000 0x450>,
+            <0x1fa96000 0x300>,
+            <0x1fa9a000 0x600>;
+      reg-names = "pcs_mac", "hsgmii_an", "hsgmii_pcs",
+                  "multi_sgmii", "hsgmii_rate_adp","pcs_ana";
+
+      phys = <&usb0_phy PHY_TYPE_USB3>;
+
+      #pcs-cells = <0>;
+    };
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v22 15/15] net: airoha: add phylink support
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
                   ` (12 preceding siblings ...)
  2026-11-17 12:39 ` [PATCH net-next v22 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
@ 2026-11-17 12:39 ` Christian Marangi
  2026-11-21 23:26   ` Jakub Kicinski
  2026-11-17 12:43 ` [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS netdev-bot+sinfo
  14 siblings, 1 reply; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:39 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Christian Marangi, Lorenzo Bianconi, Heiner Kallweit,
	Russell King, Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm
  Cc: Zhengping Zhang

Add phylink support for each GDM port. For GDM1 add the internal interface
mode as the only supported mode. For GDM2/3/4 add the required
configuration of the PCS to make the external PHY or attached SFP cage
work.

These needs to be defined in the GDM port node using the pcs-handle
property.

Update and provide a .get/set_link_ksettings function that use phylink
for ethtool OPs now that we fully support phylink.

Tested-by: Zhengping Zhang <zhengping.zhang@airoha.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/ethernet/airoha/Kconfig       |   2 +
 drivers/net/ethernet/airoha/airoha_eth.c  | 197 +++++++++++++++++++++-
 drivers/net/ethernet/airoha/airoha_eth.h  |   5 +
 drivers/net/ethernet/airoha/airoha_regs.h |  12 ++
 4 files changed, 213 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/airoha/Kconfig b/drivers/net/ethernet/airoha/Kconfig
index 1f6640a15fc9..3c7403870aa8 100644
--- a/drivers/net/ethernet/airoha/Kconfig
+++ b/drivers/net/ethernet/airoha/Kconfig
@@ -20,6 +20,8 @@ config NET_AIROHA
 	depends on NET_DSA || !NET_DSA
 	select NET_AIROHA_NPU
 	select PAGE_POOL
+	select FWNODE_PCS
+	select PHYLINK
 	help
 	  This driver supports the gigabit ethernet MACs in the
 	  Airoha SoC family.
diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
index 044ad0302ef3..e41dfad58b25 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.c
+++ b/drivers/net/ethernet/airoha/airoha_eth.c
@@ -6,6 +6,7 @@
 #include <linux/of.h>
 #include <linux/of_net.h>
 #include <linux/of_reserved_mem.h>
+#include <linux/pcs/pcs.h>
 #include <linux/platform_device.h>
 #include <linux/tcp.h>
 #include <linux/u64_stats_sync.h>
@@ -2194,10 +2195,18 @@ static int airoha_dev_open(struct net_device *netdev)
 		return -EBUSY;
 	}
 
+	err = phylink_of_phy_connect(dev->phylink, netdev->dev.of_node, 0);
+	if (err) {
+		netdev_err(netdev, "could not attach PHY: %d\n", err);
+		return err;
+	}
+
+	phylink_start(dev->phylink);
+
 	netif_tx_start_all_queues(netdev);
 	err = airoha_set_vip_for_gdm_port(dev, true);
 	if (err)
-		return err;
+		goto err_phy_stop;
 
 	if (netdev_uses_dsa(netdev))
 		airoha_fe_set(qdma->eth, REG_GDM_INGRESS_CFG(port->id),
@@ -2219,6 +2228,12 @@ static int airoha_dev_open(struct net_device *netdev)
 		airoha_dev_lro_enable(dev);
 
 	return 0;
+
+err_phy_stop:
+	phylink_stop(dev->phylink);
+	phylink_disconnect_phy(dev->phylink);
+
+	return err;
 }
 
 static int airoha_dev_stop(struct net_device *netdev)
@@ -2226,6 +2241,8 @@ static int airoha_dev_stop(struct net_device *netdev)
 	struct airoha_gdm_dev *dev = netdev_priv(netdev);
 	struct airoha_gdm_port *port = dev->port;
 
+	phylink_stop(dev->phylink);
+
 	netif_tx_disable(netdev);
 	airoha_set_vip_for_gdm_port(dev, false);
 
@@ -2239,6 +2256,8 @@ static int airoha_dev_stop(struct net_device *netdev)
 	if (netdev->features & NETIF_F_LRO)
 		airoha_dev_lro_disable(dev);
 
+	phylink_disconnect_phy(dev->phylink);
+
 	return 0;
 }
 
@@ -2829,6 +2848,24 @@ airoha_ethtool_get_rmon_stats(struct net_device *netdev,
 	} while (u64_stats_fetch_retry(&dev->stats.syncp, start));
 }
 
+static int
+airoha_ethtool_get_link_ksettings(struct net_device *netdev,
+				  struct ethtool_link_ksettings *cmd)
+{
+	struct airoha_gdm_dev *dev = netdev_priv(netdev);
+
+	return phylink_ethtool_ksettings_get(dev->phylink, cmd);
+}
+
+static int
+airoha_ethtool_set_link_ksettings(struct net_device *netdev,
+				  const struct ethtool_link_ksettings *cmd)
+{
+	struct airoha_gdm_dev *dev = netdev_priv(netdev);
+
+	return phylink_ethtool_ksettings_set(dev->phylink, cmd);
+}
+
 static int airoha_qdma_set_chan_tx_sched(struct net_device *netdev,
 					 int channel, enum tx_sched_mode mode,
 					 const u16 *weights, u8 n_weights)
@@ -3696,7 +3733,8 @@ static const struct ethtool_ops airoha_ethtool_ops = {
 	.get_drvinfo		= airoha_ethtool_get_drvinfo,
 	.get_eth_mac_stats      = airoha_ethtool_get_mac_stats,
 	.get_rmon_stats		= airoha_ethtool_get_rmon_stats,
-	.get_link_ksettings	= phy_ethtool_get_link_ksettings,
+	.get_link_ksettings	= airoha_ethtool_get_link_ksettings,
+	.set_link_ksettings	= airoha_ethtool_set_link_ksettings,
 	.get_link		= ethtool_op_get_link,
 };
 
@@ -3752,6 +3790,155 @@ bool airoha_is_valid_gdm_dev(struct airoha_eth *eth,
 	return false;
 }
 
+/* Nothing to do in MAC, everything is handled in PCS */
+static void airoha_mac_config(struct phylink_config *config, unsigned int mode,
+			      const struct phylink_link_state *state)
+{
+}
+
+static void airoha_mac_link_up(struct phylink_config *config, struct phy_device *phy,
+			       unsigned int mode, phy_interface_t interface,
+			       int speed, int duplex, bool tx_pause, bool rx_pause)
+{
+	struct airoha_gdm_dev *dev = container_of(config, struct airoha_gdm_dev,
+						  phylink_config);
+	struct airoha_gdm_port *port = dev->port;
+	struct airoha_eth *eth = dev->eth;
+	u32 frag_size_tx, frag_size_rx;
+
+	/* TX/RX frag is configured only for GDM4 */
+	if (port->id != AIROHA_GDM4_IDX)
+		return;
+
+	switch (speed) {
+	case SPEED_10000:
+	case SPEED_5000:
+		frag_size_tx = 8;
+		frag_size_rx = 8;
+		break;
+	case SPEED_2500:
+		frag_size_tx = 2;
+		frag_size_rx = 1;
+		break;
+	default:
+		frag_size_tx = 1;
+		frag_size_rx = 0;
+		break;
+	}
+
+	mutex_lock(&port->link_lock);
+
+	/* Configure TX/RX frag based on speed */
+	if (dev->nbq == 1) {
+		airoha_fe_rmw(eth, REG_FE_GDM4_TMBI_FRAG,
+			      GDM4_SGMII1_TX_FRAG_SIZE_MASK,
+			      FIELD_PREP(GDM4_SGMII1_TX_FRAG_SIZE_MASK,
+					 frag_size_tx));
+
+		airoha_fe_rmw(eth, REG_FE_GDM4_RMBI_FRAG,
+			      GDM4_SGMII1_RX_FRAG_SIZE_MASK,
+			      FIELD_PREP(GDM4_SGMII1_RX_FRAG_SIZE_MASK,
+					 frag_size_rx));
+	} else {
+		airoha_fe_rmw(eth, REG_FE_GDM4_TMBI_FRAG,
+			      GDM4_SGMII0_TX_FRAG_SIZE_MASK,
+			      FIELD_PREP(GDM4_SGMII0_TX_FRAG_SIZE_MASK,
+					 frag_size_tx));
+
+		airoha_fe_rmw(eth, REG_FE_GDM4_RMBI_FRAG,
+			      GDM4_SGMII0_RX_FRAG_SIZE_MASK,
+			      FIELD_PREP(GDM4_SGMII0_RX_FRAG_SIZE_MASK,
+					 frag_size_rx));
+	}
+
+	mutex_unlock(&port->link_lock);
+}
+
+/* Nothing to do in MAC, everything is handled in PCS */
+static void airoha_mac_link_down(struct phylink_config *config, unsigned int mode,
+				 phy_interface_t interface)
+{
+}
+
+static const struct phylink_mac_ops airoha_phylink_ops = {
+	.mac_config = airoha_mac_config,
+	.mac_link_up = airoha_mac_link_up,
+	.mac_link_down = airoha_mac_link_down,
+};
+
+static int airoha_fill_available_pcs(struct phylink_config *config,
+				     struct phylink_pcs **available_pcs,
+				     unsigned int num_possible_pcs)
+{
+	struct device *dev = config->dev;
+
+	return fwnode_phylink_pcs_parse(dev_fwnode(dev), available_pcs,
+					num_possible_pcs);
+}
+
+static int airoha_setup_phylink(struct net_device *netdev)
+{
+	struct airoha_gdm_dev *dev = netdev_priv(netdev);
+	struct device_node *np = netdev->dev.of_node;
+	struct airoha_gdm_port *port = dev->port;
+	struct phylink_config *config;
+	phy_interface_t phy_mode;
+	struct phylink *phylink;
+	int err;
+
+	err = of_get_phy_mode(np, &phy_mode);
+	if (err) {
+		dev_err(&netdev->dev, "incorrect phy-mode\n");
+		return err;
+	}
+
+	config = &dev->phylink_config;
+	config->dev = &netdev->dev;
+	config->type = PHYLINK_NETDEV;
+
+	/*
+	 * GDM1 only supports internal for Embedded Switch
+	 * and doesn't require a PCS.
+	 */
+	if (port->id == AIROHA_GDM1_IDX) {
+		config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
+					   MAC_10000FD;
+
+		__set_bit(PHY_INTERFACE_MODE_INTERNAL,
+			  config->supported_interfaces);
+	} else {
+		config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
+					   MAC_10 | MAC_100 | MAC_1000 |
+					   MAC_2500FD | MAC_5000FD | MAC_10000FD;
+
+		config->num_possible_pcs = fwnode_phylink_pcs_count(dev_fwnode(config->dev));
+		config->fill_available_pcs = airoha_fill_available_pcs;
+
+		__set_bit(PHY_INTERFACE_MODE_SGMII,
+			  config->supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_1000BASEX,
+			  config->supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_2500BASEX,
+			  config->supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_10GBASER,
+			  config->supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_USXGMII,
+			  config->supported_interfaces);
+
+		phy_interface_copy(config->pcs_interfaces,
+				   config->supported_interfaces);
+	}
+
+	phylink = phylink_create(config, of_fwnode_handle(np),
+				 phy_mode, &airoha_phylink_ops);
+	if (IS_ERR(phylink))
+		return PTR_ERR(phylink);
+
+	dev->phylink = phylink;
+
+	return 0;
+}
+
 static int airoha_alloc_gdm_device(struct airoha_eth *eth,
 				   struct airoha_gdm_port *port,
 				   int nbq, struct device_node *np)
@@ -3815,7 +4002,7 @@ static int airoha_alloc_gdm_device(struct airoha_eth *eth,
 	dev->nbq = nbq;
 	port->devs[index] = dev;
 
-	return 0;
+	return airoha_setup_phylink(netdev);
 }
 
 static int airoha_alloc_gdm_port(struct airoha_eth *eth,
@@ -3851,6 +4038,7 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth,
 
 	port->id = id;
 	spin_lock_init(&port->stats_lock);
+	mutex_init(&port->link_lock);
 	eth->ports[p] = port;
 
 	err = airoha_metadata_dst_alloc(port);
@@ -4046,6 +4234,8 @@ static int airoha_probe(struct platform_device *pdev)
 			netdev = netdev_from_priv(dev);
 			if (netdev->reg_state == NETREG_REGISTERED)
 				unregister_netdev(netdev);
+			if (dev->phylink)
+				phylink_destroy(dev->phylink);
 			of_node_put(netdev->dev.of_node);
 		}
 		airoha_metadata_dst_free(port);
@@ -4084,6 +4274,7 @@ static void airoha_remove(struct platform_device *pdev)
 
 			netdev = netdev_from_priv(dev);
 			unregister_netdev(netdev);
+			phylink_destroy(dev->phylink);
 			of_node_put(netdev->dev.of_node);
 		}
 		airoha_metadata_dst_free(port);
diff --git a/drivers/net/ethernet/airoha/airoha_eth.h b/drivers/net/ethernet/airoha/airoha_eth.h
index d270729e22ff..909e75fec279 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.h
+++ b/drivers/net/ethernet/airoha/airoha_eth.h
@@ -612,6 +612,9 @@ struct airoha_gdm_dev {
 	 * QDMA migration.
 	 */
 	spinlock_t txq_lock[AIROHA_NUM_NETDEV_TX_RINGS];
+
+	struct phylink *phylink;
+	struct phylink_config phylink_config;
 };
 
 struct airoha_gdm_port {
@@ -621,6 +624,8 @@ struct airoha_gdm_port {
 
 	/* protect concurrent hw_stats accesses */
 	spinlock_t stats_lock;
+	/* protect concurrent GDM4 register access */
+	struct mutex link_lock;
 
 	struct metadata_dst *dsa_meta[AIROHA_MAX_DSA_PORTS];
 };
diff --git a/drivers/net/ethernet/airoha/airoha_regs.h b/drivers/net/ethernet/airoha/airoha_regs.h
index 07dd04859fde..94d53d4c3ab7 100644
--- a/drivers/net/ethernet/airoha/airoha_regs.h
+++ b/drivers/net/ethernet/airoha/airoha_regs.h
@@ -371,6 +371,18 @@
 #define IP_FRAGMENT_PORT_MASK		GENMASK(8, 5)
 #define IP_FRAGMENT_NBQ_MASK		GENMASK(4, 0)
 
+#define REG_FE_GDM4_TMBI_FRAG		0x2028
+#define GDM4_SGMII1_TX_WEIGHT_MASK	GENMASK(31, 26)
+#define GDM4_SGMII1_TX_FRAG_SIZE_MASK	GENMASK(25, 16)
+#define GDM4_SGMII0_TX_WEIGHT_MASK	GENMASK(15, 10)
+#define GDM4_SGMII0_TX_FRAG_SIZE_MASK	GENMASK(9, 0)
+
+#define REG_FE_GDM4_RMBI_FRAG		0x202c
+#define GDM4_SGMII1_RX_WEIGHT_MASK	GENMASK(31, 26)
+#define GDM4_SGMII1_RX_FRAG_SIZE_MASK	GENMASK(25, 16)
+#define GDM4_SGMII0_RX_WEIGHT_MASK	GENMASK(15, 10)
+#define GDM4_SGMII0_RX_FRAG_SIZE_MASK	GENMASK(9, 0)
+
 #define REG_MC_VLAN_EN			0x2100
 #define MC_VLAN_EN_MASK			BIT(0)
 
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS
  2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
                   ` (13 preceding siblings ...)
  2026-11-17 12:39 ` [PATCH net-next v22 15/15] net: airoha: add phylink support Christian Marangi
@ 2026-11-17 12:43 ` netdev-bot+sinfo
  2026-11-17 12:47   ` Christian Marangi
  14 siblings, 1 reply; 25+ messages in thread
From: netdev-bot+sinfo @ 2026-11-17 12:43 UTC (permalink / raw)
  To: Christian Marangi
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Lorenzo Bianconi, Heiner Kallweit, Russell King,
	Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS
  2026-11-17 12:43 ` [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS netdev-bot+sinfo
@ 2026-11-17 12:47   ` Christian Marangi
  0 siblings, 0 replies; 25+ messages in thread
From: Christian Marangi @ 2026-11-17 12:47 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Lorenzo Bianconi, Heiner Kallweit, Russell King,
	Maxime Chevallier, Philipp Zabel, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Russell King (Oracle), netdev, devicetree, linux-kernel,
	linux-doc, linux-arm-kernel, linux-mediatek, llvm

On Tue, Nov 17, 2026 at 12:43:36PM +0000, netdev-bot+sinfo@kernel.org wrote:
> Hi!
> 
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
> 
>  - How the issue was discovered, e.g. hit in production, hit during
>    development, syzbot report, manual code inspection, LLM or static
>    analysis tool scan.
> 
>  - Whether the issue was actually triggered, or is only theoretical
>    (e.g. found by LLM and not proven at runtime). If it was triggered
>    please include the symptoms, like the stack trace or kernel messages.
> 
> Please do not repost the series just to address the above. Instead,
> reply to this email with the missing information, so that reviewers
> can take it into account.
> 
> *IMPORTANT*: If you do repost (for other reasons) - please include
> the relevant info in the cover letter or commit messages.
> -- 
> The evaluation is done by an LLM so it may be wrong, if you think
> that is the case please reply and explain.

The RCU """bug""" was found while evaluating the code. It's hardly possible
to have such bug on real world scenario since PCS and MAC are currently
tightly coupled. Nonetheless with VERY BAD PROGRAMMING it's still possible
to trigger it.

It's both a fix and a prerequisite for having standalone PCS support.

(hope I don't have to repeat this message for the next gozillion revision
of this series...)

-- 
	Ansuel


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v22 01/15] net: phylink: make PCS phylink instance access RCU protected
  2026-11-17 12:39 ` [PATCH net-next v22 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
@ 2026-11-21 23:26   ` Jakub Kicinski
  0 siblings, 0 replies; 25+ messages in thread
From: Jakub Kicinski @ 2026-11-21 23:26 UTC (permalink / raw)
  To: ansuelsmth
  Cc: Jakub Kicinski, andrew+netdev, davem, edumazet, pabeni, robh,
	krzk+dt, conor+dt, horms, corbet, skhan, rdunlap, lorenzo,
	hkallweit1, linux, maxime.chevallier, p.zabel, nathan,
	ndesaulniers, morbo, justinstitt, rmk+kernel, netdev, devicetree,
	linux-kernel, linux-doc, linux-arm-kernel, linux-mediatek, llvm,
	zhengping.zhang

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
net: phylink: make PCS phylink instance access RCU protected

This commit makes the phylink back-pointer in struct phylink_pcs RCU
protected and reads it under rcu_read_lock() in phylink_pcs_change().
phylink_destroy() now clears that pointer and calls synchronize_rcu(), so
a concurrent phylink_pcs_change() should not run on a freed phylink
instance.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index e7734e45376cd..d9d0ace2042e5 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c

[ ... ]

> @@ -1295,10 +1296,10 @@ static void phylink_major_config(struct phylink *pl, bool restart,
>  		phylink_pcs_disable(pl->pcs);
>  
>  		if (pl->pcs)
> -			pl->pcs->phylink = NULL;
> +			rcu_assign_pointer(pl->pcs->phylink, NULL);
>  
>  		if (pcs)
> -			pcs->phylink = pl;
> +			rcu_assign_pointer(pcs->phylink, pl);
>  
>  		pl->pcs = pcs;
>  	}

[ ... ]

> @@ -2137,6 +2138,11 @@ void phylink_destroy(struct phylink *pl)
>  	if (pl->link_gpio)
>  		gpiod_put(pl->link_gpio);
>  
> +	if (pl->pcs) {
> +		rcu_assign_pointer(pl->pcs->phylink, NULL);
> +		synchronize_rcu();
> +	}
> +
>  	cancel_work_sync(&pl->resolve);
>  	kfree(pl);
>  }

[Severity: High]
Can phylink_pcs_change() still use pl after kfree(pl) here?

phylink_destroy() only waits for a grace period when pl->pcs is non-NULL.
pl->pcs can be NULL at this point if an earlier phylink_major_config()
switched to a NULL PCS. That happens when mac_select_pcs() returns NULL
for the new interface, for example in the default case of
mv88e639x_pcs_select().

In that case phylink_major_config() cleared old_pcs->phylink and set
pl->pcs to NULL without waiting for a grace period. A sequence like this
looks possible:

PCS driver threaded IRQ handler:
phylink_pcs_change(old_pcs)
    rcu_read_lock();
    pl = rcu_dereference(pcs->phylink);
    <preempted>

Resolve worker:
phylink_major_config()
    rcu_assign_pointer(pl->pcs->phylink, NULL);
    pl->pcs = pcs;    /* pcs == NULL */

Driver teardown:
phylink_stop()
phylink_destroy()
    if (pl->pcs) { ... }    /* skipped, no synchronize_rcu() */
    cancel_work_sync(&pl->resolve);
    kfree(pl);

IRQ handler resumes:
    phylink_link_changed(pl, up, "pcs");
        /* writes pl->link_failed, may queue_work(&pl->resolve) */

phylink_stop() does not seem to close this window. It only handles
phylink's own link_poll timer, link_irq and resolve work, and the
phylink_pcs_disable(pl->pcs) call gets a NULL PCS here. The mv88e6xxx PCS
drivers use request_threaded_irq(), so with CONFIG_PREEMPT_RCU the reader
can be preempted inside its RCU section.

The commit message says the change will "syncronyze RCU to catch an
execution of phylink_pcs_change()". This case still seems to be open at
the end of the series. phylink_detach_pcss() only sets rcu_sync when
pcs_list is non-empty or pl->pcs is non-NULL, and pcs_list stays empty for
mac_select_pcs() drivers. The later READ_ONCE(pl->pcs) == pcs check in
phylink_pcs_change() also dereferences the possibly freed pl.

Would it make sense to call synchronize_rcu() unconditionally in
phylink_destroy() (and later in phylink_detach_pcss())? Another option is
to wait for a grace period whenever phylink_major_config() detaches the
old PCS.


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v22 03/15] net: phylink: introduce internal phylink PCS handling
  2026-11-17 12:39 ` [PATCH net-next v22 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
@ 2026-11-21 23:26   ` Jakub Kicinski
  0 siblings, 0 replies; 25+ messages in thread
From: Jakub Kicinski @ 2026-11-21 23:26 UTC (permalink / raw)
  To: ansuelsmth
  Cc: Jakub Kicinski, andrew+netdev, davem, edumazet, pabeni, robh,
	krzk+dt, conor+dt, horms, corbet, skhan, rdunlap, lorenzo,
	hkallweit1, linux, maxime.chevallier, p.zabel, nathan,
	ndesaulniers, morbo, justinstitt, rmk+kernel, netdev, devicetree,
	linux-kernel, linux-doc, linux-arm-kernel, linux-mediatek, llvm,
	zhengping.zhang

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
net: phylink: introduce internal phylink PCS handling

This adds an alternative to .mac_select_pcs. The MAC hands phylink a list
of PCS through .fill_available_pcs and .num_possible_pcs, and phylink
picks a PCS by matching the interface against each PCS's
supported_interfaces. A new pcs_interfaces mask in phylink_config marks
the modes that need a dedicated PCS, and phylink_create() widens
pl->supported_interfaces with the supported_interfaces of every listed
PCS.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index f482dc6088102..e8ba906cfba68 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c

[ ... ]

> @@ -2096,16 +2220,31 @@ 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;
> +
> +	/* Link available PCS to phylink */
> +	list_for_each_entry(pcs, &pl->pcs_list, list)
> +		rcu_assign_pointer(pcs->phylink, pl);
> +
>  	phy_interface_copy(pl->supported_interfaces,
>  			   pl->config->supported_interfaces);
>  
> +	/* Update supported interfaces */
> +	list_for_each_entry(pcs, &pl->pcs_list, list)
> +		phy_interface_or(pl->supported_interfaces,
> +				 pl->supported_interfaces,
> +				 pcs->supported_interfaces);
> +

[Severity: Medium]

Can this OR put modes into pl->supported_interfaces that phylink will
never select a PCS for?

The PCS modes are not masked with config->pcs_interfaces. However, the
PCS lookup this patch adds only runs when the interface is in
pcs_interfaces. The check in phylink_validate_mac_and_pcs(),
phylink_inband_caps() and phylink_major_config() is:

	} else if (test_bit(state->interface, pl->config->pcs_interfaces)) {

Suppose a listed PCS advertises a mode that is not in pcs_interfaces.
__phylink_validate() accepts that mode after checking only the MAC
capabilities.

SFP interface selection uses the same widened mask. It also ends up in
the SFP PHY's host_interfaces through phylink_sfp_connect_phy():

	phy_interface_and(phy->host_interfaces, phylink_sfp_interfaces,
			  pl->supported_interfaces);

If that mode is then picked, phylink_major_config() skips the PCS list
branch and pcs stays NULL:

	pcs_changed = pl->pcs != pcs;
	...
	if (pcs_changed) {
		phylink_pcs_disable(pl->pcs);
		...
		WRITE_ONCE(pl->pcs, pcs);
	}

So the active PCS is disabled and pl->pcs becomes NULL. mac_config() is
then called for a mode the MAC never listed in
config->supported_interfaces. No PCS is programmed for that mode.

The "couldn't find a PCS for %s" error is not printed either, because it
is only reached inside the pcs_interfaces branch.

The Documentation/networking/pcs.rst added later in the series describes
supported_interfaces as holding every MAC mode. It describes
pcs_interfaces as the subset that needs a PCS ("PCS required only for
USXGMII").

Under that model the OR either adds nothing new, or it adds modes outside
pcs_interfaces that never get a PCS. One example is a USXGMII PCS that
also supports 10GBASER, 2500BASEX and 1000BASEX, such as the Airoha PCS
added later in the series.

The airoha user in the series does not hit this, because it copies
supported_interfaces into pcs_interfaces. The final state of the series
still has the unmasked OR in both phylink_create() and
pcs_provider_notify().

Should the OR be limited to config->pcs_interfaces? Alternatively, should
phylink_create() reject a PCS mode that is not in pcs_interfaces?

phylink_create() also does not check that the new fields are consistent:

- It accepts num_possible_pcs with an empty pcs_interfaces. In that case
  the listed PCS are never selected.
- It accepts pcs_interfaces together with .mac_select_pcs. In that case
  pcs_interfaces is silently ignored.

Would it make sense to reject these combinations here?

Separately, the kernel-doc for @supported_interfaces ("supported by the
MAC/PCS") and @pcs_interfaces ("dedicated PCS is required") in
include/linux/phylink.h does not match how phylink combines the two
masks.


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v22 07/15] net: phylink: add capabilities helpers and track modified advertising
  2026-11-17 12:39 ` [PATCH net-next v22 07/15] net: phylink: add capabilities helpers and track modified advertising Christian Marangi
@ 2026-11-21 23:26   ` Jakub Kicinski
  0 siblings, 0 replies; 25+ messages in thread
From: Jakub Kicinski @ 2026-11-21 23:26 UTC (permalink / raw)
  To: ansuelsmth
  Cc: Jakub Kicinski, andrew+netdev, davem, edumazet, pabeni, robh,
	krzk+dt, conor+dt, horms, corbet, skhan, rdunlap, lorenzo,
	hkallweit1, linux, maxime.chevallier, p.zabel, nathan,
	ndesaulniers, morbo, justinstitt, rmk+kernel, netdev, devicetree,
	linux-kernel, linux-doc, linux-arm-kernel, linux-mediatek, llvm,
	zhengping.zhang

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
net: phylink: add capabilities helpers and track modified advertising

This prepares for PCS release and late attach. It adds
phylink_update_capabilities() to recompute the supported and advertised
link modes, and it tracks the full advertisement and a user-disabled mask
in struct phylink. It also saves the PHY advertisement before restricting
it, and stops the SFP path from modifying pl->sfp_support in place.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 88280866c19a2..921c227a5b3c0 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c

[ ... ]

> @@ -2120,6 +2233,142 @@ static void phylink_update_pause_state(struct phylink *pl, int pause_state)

[ ... ]

> +static void phylink_update_capabilities(struct phylink *pl,
> +					struct phylink_link_state *config)
> +{
> +	if (pl->phydev) {
> +		lockdep_assert_held(&pl->phydev_mutex);
> +		lockdep_assert_held(&pl->phydev->lock);
> +	}
> +	lockdep_assert_held(&pl->state_mutex);
> +
> +	if (pl->phydev) {
> +		phylink_phy_update_capabilities(pl, pl->phydev,
> +						pl->phy_state.interface);
> +		return;
> +	}
> +
> +	if (pl->cfg_link_an_mode == MLO_AN_FIXED) {
> +		phylink_parse_fixedlink_capabilities(pl, config);
> +		goto exit;
> +	}
> +
> +	if (pl->cfg_link_an_mode == MLO_AN_INBAND) {
> +		phylink_parse_inband_capabilities(pl, config);
> +		goto exit;
> +	}

[Severity: Medium]
Can the SFP branch below ever run for an SFP cage described with
managed = "in-band-status"?

phylink_sfp_set_config() only updates req_link_an_mode and
link_config.interface. cfg_link_an_mode therefore stays MLO_AN_INBAND
while an optical module is in use.

This check then sends the recompute to
phylink_parse_inband_capabilities(). That function zeroes pl->supported
and rebuilds it from the generic interface caps, not from pl->sfp_support.

For 10GBASE-R this gives every 10G link mode plus Autoneg instead of the
modes read from the module's EEPROM. It also brings back the Autoneg bit
that phylink_sfp_config_optical() removes when the only interface is
INBAND_NONE.

Some module interfaces are not in the in-band switch, for example
PHY_INTERFACE_MODE_100BASEX. For those, phylink_parse_inband_capabilities()
returns after pl->supported has already been cut down to MII, Autoneg,
Pause and Asym_Pause:

	default:
		phylink_err(pl,
			    "incorrect link mode %s for in-band status\n",
			    phy_modes(config->interface));
		return -EINVAL;

The return value is ignored here, so pl->supported is left with no speed
modes. The old code restricted the result with
linkmode_and(pl->supported, pl->supported, pl->sfp_support) whatever the
AN mode was.

At this commit, phylink_update_mac_pause_capabilities() reaches this path.
Later in the series pcs_provider_notify() does too, and the branch order
there is unchanged.

> +
> +	/* Revalidate the SFP module modes against every available interface. */
> +	if (pl->sfp_bus && !pl->phydev && config->interface &&
> +	    !phy_interface_empty(pl->sfp_interfaces)) {
> +		__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
> +
> +		linkmode_copy(supported, pl->sfp_support);
> +		linkmode_copy(config->advertising, pl->sfp_support);
> +		if (!__phylink_validate_mask(pl, NULL, supported, config,
> +					     pl->sfp_interfaces)) {
> +			phylink_sfp_update_capabilities(pl, supported, config,
> +							config->interface);
> +			linkmode_copy(pl->supported, supported);
> +			linkmode_copy(pl->advertising, config->advertising);
> +		}

[Severity: Medium]
Should this also narrow the result to the active link_config.interface?

__phylink_validate_mask() returns the union across all of
pl->sfp_interfaces. phylink_sfp_update_capabilities() only adjusts the
Autoneg bit.

Other paths do narrow. phylink_sfp_config_optical() validates against the
chosen interface before phylink_sfp_set_config() stores the
advertisement. The old phylink_update_mac_pause_capabilities() did the
same through __phylink_validate(pl, pl->supported, config).

After a recompute, pl->advertising and link_config.advertising can contain
both 1000baseX_Full and 10000baseSR_Full while the link runs 10GBASE-R.
phylink_ethtool_ksettings_get() then reports modes that the current
interface can't run. phylink_ethtool_ksettings_set() also computes
user_disabled_advertising against that wider mask.

> +
> +		goto exit;
> +	}

[ ... ]

> @@ -2146,20 +2396,16 @@ void phylink_update_mac_pause_capabilities(struct phylink *pl, unsigned long mac
>  	if (old_pause == mac_pause)
>  		return;
>  
> +	mutex_lock(&pl->phydev_mutex);
> +	phydev = pl->phydev;
> +	if (phydev)
> +		mutex_lock(&phydev->lock);
>  	mutex_lock(&pl->state_mutex);
>  
>  	pl->config->mac_capabilities &= ~(MAC_SYM_PAUSE | MAC_ASYM_PAUSE);
>  	pl->config->mac_capabilities |= mac_pause;
>  
> -	phylink_set(pl->supported, Pause);
> -	phylink_set(pl->supported, Asym_Pause);
> -
> -	if (pl->phydev)
> -		linkmode_and(pl->supported, pl->supported, pl->phydev->supported);
> -	else if (pl->sfp_bus)
> -		linkmode_and(pl->supported, pl->supported, pl->sfp_support);
> -
> -	__phylink_validate(pl, pl->supported, config);
> +	phylink_update_capabilities(pl, config);

[Severity: Medium]
Does the PHY still renegotiate when the MAC loses pause support?

With a PHY attached, this call goes through
phylink_phy_update_capabilities(). That function validates
pl->phy_advertising against MAC caps that no longer include pause, then
writes the result straight into the PHY:

	/* Restrict the phy advertisement according to the MAC support. */
	linkmode_copy(phy->advertising, config.advertising);

It does not call phy_config_aneg() or phy_start_aneg(). By the time
phylink_update_pause_state() calls phy_set_asym_pause(), the pause bits
are already clear:

drivers/net/phy/phy_device.c:phy_set_asym_pause() {
	linkmode_copy(oldadv, phydev->advertising);
	linkmode_set_pause(phydev->advertising, tx, rx);

	if (!linkmode_equal(oldadv, phydev->advertising) &&
	    phydev->autoneg)
		phy_start_aneg(phydev);
}

linkmode_equal() is therefore true, and aneg is not restarted. With AN
enabled, manual_changed is false, so no resolve is triggered either.

Before this patch, phydev->advertising still had the pause bits at this
point. phy_set_asym_pause() saw the difference and restarted aneg. The
kernel-doc still says the function "triggers renegotiation if needed".

The in-tree caller rtl8169_change_mtu() passes caps = 0 when switching to
a jumbo MTU. Won't the PHY keep advertising PAUSE_CAP/PAUSE_ASYM, and
flow control stay active in jumbo mode, until something else
renegotiates?

Writing phydev->advertising directly also skips phylib's own bookkeeping,
such as the adv_old mask used by phy_speed_up().

[ ... ]

> @@ -2507,18 +2683,17 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy,
>  	 */
>  	phy_support_asym_pause(phy);
>  
> -	memset(&config, 0, sizeof(config));
> -	linkmode_copy(supported, phy->supported);
> -	linkmode_copy(config.advertising, phy->advertising);
> -	config.interface = interface;
> +	mutex_lock(&pl->phydev_mutex);
> +	mutex_lock(&phy->lock);
> +	mutex_lock(&pl->state_mutex);
> +
> +	linkmode_copy(pl->phy_advertising, phy->advertising);
>  
> -	ret = phylink_validate_phy(pl, phy, supported, &config);
> +	ret = phylink_phy_update_capabilities(pl, phy, interface);

[Severity: Low]
The PHY-derived state is now written in this locked section:
pl->phy_advertising, pl->supported, pl->advertising,
link_config.advertising and phy->advertising. pl->phydev is published
only later, after all locks have been dropped and phy_eee_rx_clock_stop()
has run:

	mutex_lock(&pl->phydev_mutex);
	mutex_lock(&phy->lock);
	mutex_lock(&pl->state_mutex);
	pl->phydev = phy;

A phylink_update_capabilities() call that runs in that window sees
pl->phydev == NULL. In PHY mode without an SFP it takes the generic
branch:

	/* No media is attached yet. Recalculate the generic capabilities. */
	linkmode_fill(pl->supported);

Doesn't that throw away the PHY and MAC intersection that was just
computed? phylink_update_pause_state() also skips updating
pl->phy_advertising while pl->phydev is NULL.

The old mac-pause path only set the pause bits and revalidated the
existing pl->supported, so the PHY-derived mask mostly survived.

The in-tree drivers that trigger a recompute (r8169 and airoha) connect
the PHY under rtnl, so this doesn't look reachable in-tree today. It could
still happen for a driver that calls phylink_connect_phy() without rtnl
while the fwnode PCS notifier is registered.

>  	if (ret) {

[ ... ]

> @@ -3411,6 +3579,7 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
>  
>  	if (pl->phydev) {
>  		struct ethtool_link_ksettings phy_kset = *kset;
> +		int ret;
>  
>  		linkmode_and(phy_kset.link_modes.advertising,
>  			     phy_kset.link_modes.advertising,

[ ... ]

> @@ -3434,7 +3603,15 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
>  		 *   the presence of a PHY, this should not be changed as that
>  		 *   should be determined from the media side advertisement.
>  		 */
> -		return phy_ethtool_ksettings_set(pl->phydev, &phy_kset);
> +		ret = phy_ethtool_ksettings_set(pl->phydev, &phy_kset);
> +		if (!ret) {
> +			mutex_lock(&pl->state_mutex);
> +			linkmode_copy(pl->phy_advertising,
> +				      phy_kset.link_modes.advertising);
> +			mutex_unlock(&pl->state_mutex);
> +		}

[Severity: Medium]
Does this keep the meaning documented for the new field?

	/* PHY advertisement before restricting it to MAC/PCS capabilities */
	__ETHTOOL_DECLARE_LINK_MODE_MASK(phy_advertising);

phy_kset.link_modes.advertising has already been ANDed with pl->supported
above, and pl->supported is limited to MAC/PCS. It is also the raw
request, not what phylib applied. phy_ethtool_ksettings_set() ANDs it
with phydev->supported and sets the Autoneg bit from base.autoneg.

Later, phylink_phy_update_capabilities() replays this copy and writes the
result into phy->advertising:

	linkmode_copy(config.advertising, pl->phy_advertising);

Can that restore an Autoneg bit while phydev->autoneg is
AUTONEG_DISABLE?

Modes outside pl->supported at the time of the ethtool call are also lost
for good. After a PCS is re-attached they won't be advertised again. The
non-PHY path avoids this because it tracks user-disabled modes.

The copy also goes stale when phylib changes phydev->advertising itself,
for example in phy_speed_down(). The next recompute then silently
overwrites that change.

> +
> +		return ret;
>  	}

[ ... ]

> @@ -4022,19 +4201,34 @@ static void phylink_sfp_detach(void *upstream, struct sfp_bus *bus)

[ ... ]

> +	for (i = 0; i < ARRAY_SIZE(phylink_sfp_interface_preference); i++) {
> +		interface = phylink_sfp_interface_preference[i];
> +		if (!test_bit(interface, intf))
> +			continue;
>  
> -	return interface;
> +		tmp_state = *state;
> +		tmp_state.interface = interface;
> +		linkmode_copy(tmp_supported, supported);
> +		if (phylink_validate(pl, tmp_supported, &tmp_state))
> +			continue;
> +
> +		/* Skip this preferred interface if user-disabled in advertising */
> +		linkmode_andnot(tmp_state.advertising, tmp_state.advertising,
> +				pl->user_disabled_advertising);
> +		if (!phylink_is_empty_linkmode(tmp_state.advertising))
> +			return interface;
> +	}
> +
> +	return PHY_INTERFACE_MODE_NA;

[Severity: Medium]
Is pl->user_disabled_advertising ever cleared?

Its only writer is phylink_update_user_disabled_advertising(), which keeps
restrictions for modes that are absent from the current pl->advertising.
phylink_sfp_module_remove() only zeroes sfp_interfaces and
sfp_module_interfaces. An ethtool restriction made for one SFP module
therefore applies to every module inserted later.

For example, take a dual-rate 1G/10G module running 10GBASE-R. Running
"ethtool -s ... advertise 1000baseX/Full" records 10000baseSR_Full and the
pause bits as user-disabled.

Then a 10G-only module is inserted. This loop validates 10GBASE-R, masks
out the stale disabled modes, and is left with only Autoneg.
phylink_is_empty_linkmode() returns true and PHY_INTERFACE_MODE_NA is
returned. phylink_sfp_config_optical() then fails with "failed to select
SFP interface".

Before this patch, the interface was chosen by preference alone and the
module worked.

There is also a mismatch in phylink_sfp_set_config().
phylink_validate_pcs_inband_autoneg() checks the unmasked
config.advertising, but the masked one is what gets programmed, and it
may have Autoneg removed:

	linkmode_copy(pl->advertising, state->advertising);
	if (!pl->phydev)
		linkmode_andnot(state->advertising, pl->advertising,
				pl->user_disabled_advertising);

The commit message only mentions keeping user rules across PCS removal and
re-attach. Are these restrictions meant to persist across SFP module swaps
and change how the interface is selected?

[ ... ]


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v22 08/15] net: phylink: support PCS provider release
  2026-11-17 12:39 ` [PATCH net-next v22 08/15] net: phylink: support PCS provider release Christian Marangi
@ 2026-11-21 23:26   ` Jakub Kicinski
  0 siblings, 0 replies; 25+ messages in thread
From: Jakub Kicinski @ 2026-11-21 23:26 UTC (permalink / raw)
  To: ansuelsmth
  Cc: Jakub Kicinski, andrew+netdev, davem, edumazet, pabeni, robh,
	krzk+dt, conor+dt, horms, corbet, skhan, rdunlap, lorenzo,
	hkallweit1, linux, maxime.chevallier, p.zabel, nathan,
	ndesaulniers, morbo, justinstitt, rmk+kernel, netdev, devicetree,
	linux-kernel, linux-doc, linux-arm-kernel, linux-mediatek, llvm,
	zhengping.zhang

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
net: phylink: support PCS provider release

This adds a blocking notifier chain to the fwnode PCS layer.
fwnode_pcs_del_provider() uses it to emit FWNODE_PCS_PROVIDER_DEL. Each
phylink instance with pcs_interfaces subscribes, drops the matching PCS from
pl->pcs_list on that event, recalculates its capabilities, and accesses
pcs_list under state_mutex.

> diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c
> index b1d48f6eee7f1..f234a46354176 100644
> --- a/drivers/net/pcs/pcs.c
> +++ b/drivers/net/pcs/pcs.c

[ ... ]

> @@ -74,6 +87,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);
> +

[Severity: Medium]
Can this notifier call into PCS hardware that the provider has already
powered down?

pcs_provider_notify()->phylink_del_pcs() calls phylink_pcs_disable(), which
calls pcs->ops->pcs_disable(). If the link is up it also calls
phylink_link_down(), and later in the series that calls
pcs->ops->pcs_link_down() too.

With devm_fwnode_pcs_add_provider(), devm_fwnode_pcs_del() runs during devres
release. That happens after the driver's .remove(), and in reverse order of
registration.

A provider might gate clocks, drop runtime PM or assert reset in .remove().
It might also get devm clocks or resets after it registers the provider.
Either way, these PCS register accesses would hit unpowered hardware.

For example, pcs-rzn1-miic calls pm_runtime_put() in .remove(). If it were
converted to a devm fwnode provider, the del would run after that.

The airoha PCS in this series registers its devm provider last and has no
.remove(), so it is not affected.

Neither pcs-provider.h nor pcs.rst says the hardware must stay accessible
until fwnode_pcs_del_provider() returns. Should that be documented, or
should the notifier avoid touching the departing PCS hardware?

>  	fwnode_handle_put(pp->fwnode);
>  	kfree(pp);
>  }

[ ... ]

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 921c227a5b3c0..094a15f3dbcd0 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c

[ ... ]

> @@ -2425,6 +2451,133 @@ 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);
> +
> +	rcu_assign_pointer(pcs->phylink, NULL);
> +	synchronize_rcu();
> +	list_del(&pcs->list);

[Severity: Low]
Is a full grace period needed for every PCS while RTNL is held?

pcs_provider_notify() calls phylink_del_pcs() in a loop. It holds
rtnl_lock(), pl->phydev_mutex, phydev->lock and pl->state_mutex the whole
time, inside the notifier rwsem read section.

So each phylink subscribed to the departing provider holds RTNL for one
normal grace period per removed PCS. The instances run one after another.

phylink_detach_pcss() in this same patch clears all the pointers first and
then calls synchronize_rcu() once. Could pcs_provider_notify() do the same,
or use synchronize_net()?

> +
> +	/*
> +	 * Check if we are removing the PCS currently

[ ... ]

> +	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);
> +	}
> +}

[Severity: Medium]
Can the link stay down for good if the active PCS is removed while
PHYLINK_DISABLE_LINK is set?

On SFP loss of signal, phylink_sfp_link_down() sets PHYLINK_DISABLE_LINK
and pcs_state stays PCS_STATE_STARTED.

Suppose the active PCS's provider goes away during LOS.
phylink_pcs_disable() powers the PCS down and pl->pcs becomes NULL.
force_major_config is not set, because phylink_disable_state is non-zero.

When LOS clears:

phylink_sfp_link_up()
  phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_LINK)
    phylink_resolve()
        if ((mac_config && link_state.interface != pl->link_config.interface) ||
            pl->force_major_config) {

Neither condition holds, so phylink_major_config() is skipped and no PCS is
picked from pl->pcs_list again.

In in-band mode, phylink_mac_pcs_get_state() then sees pl->pcs == NULL and
reports link = 0.

That stays true even if another PCS in pcs_list supports the interface. It
also stays true after the provider is re-added, because the late attach
path only forces a major config when major_config_failed is set.

In MLO_AN_PHY mode, phylink_link_up() would call mac_link_up() and
netif_carrier_on() while the PCS is disabled.

The STOPPED, MAC_WOL and REPLAY bits each recover through
phylink_mac_initial_config() or force_major_config, but DISABLE_LINK does
not. Should force_major_config be set here whatever phylink_disable_state
is?

> +
> +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 *pp = data;
> +	struct phylink_pcs *pcs, *tmp;
> +	struct phy_device *phydev;
> +	bool resolve = false;
> +
> +	rtnl_lock();
> +	mutex_lock(&pl->phydev_mutex);
> +	phydev = pl->phydev;
> +	if (phydev)
> +		mutex_lock(&phydev->lock);
> +	mutex_lock(&pl->state_mutex);

[Severity: Medium]
Does this give fwnode_pcs_del_provider() a hidden "must not hold RTNL"
requirement?

fwnode_pcs_del_provider() used to take only fwnode_pcs_mutex. It now calls
blocking_notifier_call_chain(), which holds the chain rwsem for read. While
that is held, this callback takes rtnl_lock(), pl->phydev_mutex,
phydev->lock and pl->state_mutex.

A provider removed from a path that already holds RTNL, or any of those
locks, would deadlock here.

The rwsem-read -> rtnl ordering could also cause an ABBA deadlock with
register_fwnode_pcs_notifier() and unregister_fwnode_pcs_notifier(), which
take the same rwsem with down_write. That would happen if a MAC with
non-empty pcs_interfaces called phylink_create() or phylink_destroy() under
RTNL while another provider is being removed.

No current in-tree path does this. The airoha PCS deletes through devres at
unbind without RTNL, and airoha_eth creates and destroys phylink outside
RTNL.

But pcs-provider.h and pcs.rst do not mention this rule, and nothing
asserts it. Would a lockdep_assert_not_held() or a note in the API
documentation help?

> +
> +	/* phylink instance is being destroyed, ignore any event */
> +	if (pl->pcs_state == PCS_STATE_DETACHING)
> +		goto exit;
> +
> +	/*
> +	 * Loop all the PCS for phylink instance and check if
> +	 * this notification is relevant for some of them.
> +	 */
> +	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
> +		if (!fwnode_pcs_matches_provider(pp, pl->fwnode, pcs))
> +			continue;
> +
> +		phylink_del_pcs(pl, pcs);
> +		resolve = true;
> +	}

[Severity: Medium]
What happens when a PCS in pl->pcs_list did not come from the pcs-handle
property of pl->fwnode?

fwnode_pcs_matches_provider() works out ownership again at teardown. It
re-parses "pcs-handle" from the fwnode it is given and calls
provider->fwnode_xlate() again.

phylink does not record where each PCS came from when fill_available_pcs()
hands it over. The fill_available_pcs() contract in
include/linux/phylink.h does not require the PCS to come from the fwnode
passed to phylink_create().

The earlier patch "net: phylink: save phylink instance fwnode on
phylink_create" notes that pl->fwnode can differ from the fwnode of
config->dev. The pcs.rst example in "net: Document PCS subsystem" calls
fwnode_phylink_pcs_parse(dev_fwnode(config->dev), ...) from
fill_available_pcs.

For such a MAC, every check here returns false and phylink_del_pcs() is
never called. The PCS stays on pl->pcs_list, pcs->phylink stays set, and
the PCS may still be pl->pcs.

fwnode_pcs_del_provider() then returns, and the provider frees its
phylink_pcs (for example, a devm-allocated priv). After that,
phylink_resolve(), phylink_major_config() and phylink_mac_pcs_get_state()
would call pcs->ops through freed memory, and phylink_detach_pcss() would
write to it.

airoha_eth passes the same node to both, so it is not affected today. Would
it be more robust to record the provider, or the source fwnode, for each
PCS when it is added?

[ ... ]

> @@ -2515,10 +2668,18 @@ 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);
>  
> +	/* First register notifier for hotplug PCS events */
> +	if (!phy_interface_empty(config->pcs_interfaces)) {
> +		pl->fwnode_pcs_nb.notifier_call = pcs_provider_notify;
> +		register_fwnode_pcs_notifier(&pl->fwnode_pcs_nb);
> +	}

[Severity: Medium]
Can pcs_provider_notify() run against a partly initialized phylink here?

The notifier goes live, and pl->pcs_list is filled, before
phylink_parse_mode(), phylink_parse_fixedlink() and phylink_register_sfp()
run.

If a provider for one of the filled PCS is unbound at the same moment (for
example via sysfs), pcs_provider_notify() takes state_mutex and runs
phylink_update_capabilities(). That reads and writes pl->cfg_link_an_mode,
pl->sfp_bus, pl->link_config, pl->supported and pl->advertising.

Meanwhile phylink_create() writes the same fields without state_mutex.
phylink_parse_mode() sets pl->cfg_link_an_mode. phylink_parse_fixedlink()
sets link_config.speed and duplex, and does this before it takes
state_mutex:

	__set_bit(ETHTOOL_LINK_MODE_Pause_BIT,
		  pl->link_config.lp_advertising);

pl->req_link_an_mode and pl->sfp_bus are also written without the lock.

On a fixed-link port, once cfg_link_an_mode == MLO_AN_FIXED, the notifier
goes through phylink_parse_fixedlink_capabilities(). That function does a
read-modify-write linkmode_or() on config->lp_advertising, which could
overwrite the Pause bit phylink_parse_fixedlink() just set.

The later locked recalculation only ORs in match, so the link partner pause
ability from DT would be lost for good.

This also seems to conflict with the commit message:

  Protect every access of phylink pcs_list with state_mutex to handle async
  PCS provider release and capabilities recalculation.

Could the registration move to the end of phylink_create(), or could the
notifier ignore events until initialization is complete?

>  
>  	/* Fill the PCS list with available PCS from phylink config */
>  	ret = phylink_fill_available_pcs(pl, config);

[ ... ]


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v22 09/15] net: phylink: support late PCS provider attach
  2026-11-17 12:39 ` [PATCH net-next v22 09/15] net: phylink: support late PCS provider attach Christian Marangi
@ 2026-11-21 23:26   ` Jakub Kicinski
  0 siblings, 0 replies; 25+ messages in thread
From: Jakub Kicinski @ 2026-11-21 23:26 UTC (permalink / raw)
  To: ansuelsmth
  Cc: Jakub Kicinski, andrew+netdev, davem, edumazet, pabeni, robh,
	krzk+dt, conor+dt, horms, corbet, skhan, rdunlap, lorenzo,
	hkallweit1, linux, maxime.chevallier, p.zabel, nathan,
	ndesaulniers, morbo, justinstitt, rmk+kernel, netdev, devicetree,
	linux-kernel, linux-doc, linux-arm-kernel, linux-mediatek, llvm,
	zhengping.zhang

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
net: phylink: support late PCS provider attach

This adds a FWNODE_PCS_PROVIDER_ADD notifier event, emitted from
fwnode_pcs_add_provider(), so that a PCS provider registered after
phylink_create() can be attached to an existing phylink instance.
pcs_provider_notify() adds the matching PCSs through the new
phylink_add_pcs() and fwnode_pcs_get_from_provider() helpers, refreshes
supported interfaces and capabilities, and forces a major reconfig if the
previous one failed. The patch also adds pl->sfp_module_interfaces to keep
the SFP module's raw interface mask.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 094a15f3dbcd0..8768d8220a134 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
> @@ -112,6 +112,7 @@ struct phylink {
>  
>  	struct sfp_bus *sfp_bus;
>  	bool sfp_may_have_phy;
> +	DECLARE_PHY_INTERFACE_MASK(sfp_module_interfaces);
>  	DECLARE_PHY_INTERFACE_MASK(sfp_interfaces);
>  	__ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
>  	u8 sfp_port;

[Severity: Low]
The commit message only describes the FWNODE_PCS_PROVIDER_ADD event and
the late attach. The patch also reworks the generic SFP handling.

The new pl->sfp_module_interfaces is set in phylink_sfp_module_insert()
and cleared in phylink_sfp_module_remove() and phylink_sfp_config_phy().
phylink_sfp_config_optical() now intersects with sfp_module_interfaces
instead of narrowing pl->sfp_interfaces in place.

The SFP branch of phylink_update_capabilities() is now selected by
sfp_module_interfaces. It rebuilds pl->sfp_interfaces on every call, and
zeroes pl->supported, pl->advertising and config->advertising when the
intersection is empty.

The patch also moves rcu_assign_pointer(pcs->phylink, pl) out of
phylink_create() into the new phylink_add_pcs(), and adds a check that
skips a PCS already on pcs_list.

These changes also alter how the FWNODE_PCS_PROVIDER_DEL path from
"net: phylink: support PCS provider release" recomputes SFP capabilities.
They appear to be what makes that path restore them correctly.

Could the commit message describe these changes as well?

> @@ -2140,6 +2141,35 @@ int phylink_set_fixed_link(struct phylink *pl,
>  }
>  EXPORT_SYMBOL_GPL(phylink_set_fixed_link);
>  
> +static bool phylink_add_pcs(struct phylink *pl, struct phylink_pcs *pcs)
> +{
> +	struct phylink_pcs *tmp;
> +
> +	/*
> +	 * Make sure state mutex is locked to protect concurrent
> +	 * access to phylink instance PCS list from
> +	 * initial fill_available_pcs and late PCS attach
> +	 */
> +	lockdep_assert_held(&pl->state_mutex);
> +
> +	/* Make sure PCS is not already in the list */
> +	list_for_each_entry(tmp, &pl->pcs_list, list)
> +		if (tmp == pcs)
> +			return false;
> +
> +	if (WARN(rcu_access_pointer(pcs->phylink),
> +		 "%s: PCS already attached to a phylink instance\n",
> +		 __func__))
> +		return false;
> +
> +	list_add_tail(&pcs->list, &pl->pcs_list);
> +
> +	/* Link PCS to phylink */
> +	rcu_assign_pointer(pcs->phylink, pl);

[Severity: Low]
Is the pcs->phylink check plus list_add_tail() atomic across phylink
instances? The only lock held here is the per-instance pl->state_mutex.

With this patch, a new provider's PCS is offered to every registered
phylink instance:

instance A
fwnode_pcs_add_provider()
  blocking_notifier_call_chain()
    pcs_provider_notify()          /* holds A's state_mutex */
      phylink_add_pcs()

This can run at the same time as another instance is being created:

instance B
phylink_create()
  phylink_fill_available_pcs()     /* holds B's state_mutex */
    phylink_add_pcs()

B's fill_available_pcs callback can find the same provider through
fwnode_pcs_get(). The provider is already on fwnode_pcs_providers before
the notifier is called.

Suppose firmware describes two MACs whose pcs-handle entries resolve to
the same PCS, which is the case this WARN is meant to catch. Can both
threads pass the NULL check and link the single embedded pcs->list into
both pcs_list heads?

The comment above lockdep_assert_held() says state_mutex protects against
concurrent access from fill_available_pcs and late PCS attach. That only
seems to hold within one instance.

> +
> +	return true;
> +}

[ ... ]

> @@ -2358,11 +2383,24 @@ static void phylink_update_capabilities(struct phylink *pl,
>  		goto exit;
>  	}
>  
> -	/* Revalidate the SFP module modes against every available interface. */
> +	/* Revalidate SFP modes against interfaces currently supported by the
> +	 * MAC and PCS. Keep the module's interface list intact so a later PCS
> +	 * addition can make an interface usable again.
> +	 */

[Severity: Medium]
Does a later PCS addition actually make a rejected SFP module usable
again?

Suppose an optical module is inserted while the PCS provider is absent.
That can happen during phylink_create()->phylink_register_sfp(), or after
a FWNODE_PCS_PROVIDER_DEL. If the MAC driver leaves PCS-only interfaces
out of config->supported_interfaces, phylink_sfp_config_optical() fails:

	phy_interface_and(pl->sfp_interfaces, pl->supported_interfaces,
			  pl->sfp_module_interfaces);
	if (phy_interface_empty(pl->sfp_interfaces)) {
		phylink_err(pl, "unsupported SFP module: no common interface modes\n");
		return -EINVAL;
	}

sfp_sm_module() in drivers/net/phy/sfp.c then moves the module to
SFP_MOD_ERROR, which is a terminal state:

		err = sfp_module_insert(sfp->sfp_bus, &sfp->id,
					sfp->quirk);
		if (err < 0) {
			sfp_sm_mod_next(sfp, SFP_MOD_ERROR, 0);
			break;
		}

When the provider registers later, the FWNODE_PCS_PROVIDER_ADD branch of
pcs_provider_notify() only adds the PCS and refreshes
supported_interfaces. It then calls phylink_update_capabilities() with the
existing link_config.interface.

Nothing re-runs phylink_sfp_config_optical() or phylink_sfp_set_config(),
so req_link_an_mode and link_config.interface are never switched to the
module's interface. major_config_failed is not set either, because no
major config was attempted for the module.

Would the link stay down until the module is physically re-inserted?

[ ... ]

> @@ -2506,16 +2545,44 @@ static int pcs_provider_notify(struct notifier_block *self,
>  	if (pl->pcs_state == PCS_STATE_DETACHING)
>  		goto exit;
>  
> -	/*
> -	 * Loop all the PCS for phylink instance and check if
> -	 * this notification is relevant for some of them.
> -	 */
> -	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
> -		if (!fwnode_pcs_matches_provider(pp, pl->fwnode, pcs))
> -			continue;
> +	switch (val) {
> +	case FWNODE_PCS_PROVIDER_ADD:
> +		count = fwnode_phylink_pcs_count(pl->fwnode);
> +		for (i = 0; i < count; i++) {
> +			pcs = fwnode_pcs_get_from_provider(pp, pl->fwnode, i);
> +			if (IS_ERR_OR_NULL(pcs))
> +				continue;
> +
> +			/* Trigger a resolve only if a PCS is actually added */
> +			if (phylink_add_pcs(pl, pcs))
> +				resolve = true;
> +		}

[Severity: Low]
This fills pl->pcs_list differently from phylink_fill_available_pcs().

The phylink_config kernel-doc describes @fill_available_pcs as the MAC
driver's callback that fills the available PCS up to num_possible_pcs.
This path ignores config->fill_available_pcs and config->num_possible_pcs.
It parses pcs-handle on pl->fwnode directly instead.

A driver's callback might use a different fwnode, or filter or limit the
PCS set. Could such a driver end up with PCSs on pcs_list that its own
callback would never have returned?

Also, phylink_create() only rejects num_possible_pcs combined with
mac_select_pcs. It registers this notifier whenever
config->pcs_interfaces is non-empty.

For a mac_select_pcs driver that sets pcs_interfaces, this path would add
PCSs to pcs_list and OR their supported_interfaces into
pl->supported_interfaces. Meanwhile phylink_major_config() changes
pcs->phylink without touching pcs_list:

		if (pl->mac_ops->mac_select_pcs) {
			if (pl->pcs)
				rcu_assign_pointer(pl->pcs->phylink, NULL);

			if (pcs)
				rcu_assign_pointer(pcs->phylink, pl);
		}

Does that conflict with the list and back-pointer assumptions in
phylink_add_pcs()?

The only in-series user (airoha) parses the same fwnode, and no
mac_select_pcs driver currently sets pcs_interfaces. So this looks latent
for now.

> +
> +		/*
> +		 * Force an interface reconfig if major config failed.
> +		 * Configure link_failed to retrigger a resolve a
> +		 * second time to reevaluate AN mode with the new
> +		 * PCS if selected.
> +		 */
> +		if (resolve && pl->major_config_failed) {
> +			pl->force_major_config = true;
> +			pl->link_failed = true;
> +		}

[Severity: Low]
Should this be guarded by pl->phylink_disable_state, the way
phylink_del_pcs() is?

		if (!pl->phylink_disable_state)
			pl->force_major_config = true;

If the instance is stopped with major_config_failed left over from its
last run, phylink_run_resolve() won't queue any work. However,
force_major_config and link_failed stay set.

On the next phylink_start(), the call to
phylink_mac_initial_config()->phylink_major_config() clears
major_config_failed but not force_major_config. phylink_resolve() then
still sees the flag:

	if ((mac_config && link_state.interface != pl->link_config.interface) ||
	    pl->force_major_config) {

It runs a second mac_prepare/mac_config/pcs_config/mac_finish sequence,
followed by another resolve. Is that extra reconfiguration intended?

> +
> +		break;
> +	case FWNODE_PCS_PROVIDER_DEL:

[ ... ]

> +		break;
>  	}
>  
>  	/* Exit early if nothing has changed */

[Severity: Medium]
Suppose the ADD branch adds a PCS while the link is up and working
(major_config_failed is false). The code after this point still
recomputes the advertisement, but does not reconfigure the PCS:

	/* Recalculate capabilities */
	phylink_update_capabilities(pl, &pl->link_config);

For MLO_AN_INBAND without a PHY, phylink_parse_inband_capabilities() sets
Pause and Asym_Pause in pl->supported and copies that into
link_config.advertising. The SFP branch rebuilds it from pl->sfp_support.
The exit label only masks out pl->user_disabled_advertising.

A pause setting from ethtool -A is only recorded by
phylink_update_pause_state(), in config->pause and here:

	linkmode_set_pause(config->advertising, tx_pause,
			   rx_pause);

Can this silently re-enable a user-disabled pause advertisement in
link_config.advertising?

phylink_update_mac_pause_capabilities() re-applies the pause state with
phylink_update_pause_state() after phylink_update_capabilities().
pcs_provider_notify() does not.

No pcs_config() or phylink_change_inband_advert() call is made, so the
PCS hardware keeps advertising the old pause bits. Meanwhile ethtool and
phylink_mac_pcs_get_state() use the recomputed link_config.advertising.
The next pcs_config() would then program the re-enabled pause
advertisement.

[ ... ]

> @@ -4556,6 +4620,7 @@ static int phylink_sfp_module_insert(void *upstream,
>  	ASSERT_RTNL();
>  
>  	caps = sfp_get_module_caps(pl->sfp_bus);
> +	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);
>  	pl->sfp_may_have_phy = caps->may_have_phy;

[Severity: Medium]
Can pl->sfp_module_interfaces stay set after the module has been rejected
or removed?

It is copied here before phylink_sfp_config_optical() runs. Nothing clears
it when that call fails with "no common interface modes", which is what
happens while the needed PCS is still missing.

sfp.c then moves the module to SFP_MOD_ERROR. On physical removal,
sfp_sm_mod_remove() skips the upstream module_remove callback for that
state:

static void sfp_sm_mod_remove(struct sfp *sfp)
{
	if (sfp->sm_mod_state > SFP_MOD_WAITDEV)
		sfp_module_remove(sfp->sfp_bus);

SFP_MOD_ERROR is below SFP_MOD_WAITDEV. So phylink_sfp_module_remove() is
never called, and sfp_module_interfaces is never zeroed.

phylink_update_capabilities() now selects its SFP branch with
!phy_interface_empty(pl->sfp_module_interfaces). As a result, these calls
rebuild pl->supported, pl->advertising and pl->link_config.advertising
from the stale module data:

  every later PCS ADD or DEL notification
  every call to phylink_update_mac_pause_capabilities()

If there is no interface overlap, all three are zeroed. Otherwise the
stale module's link modes are installed.

Before this patch, the same failure left pl->sfp_interfaces empty. That
meant phylink_update_capabilities() fell through to the generic "no
media" path instead.

[ ... ]

> diff --git a/include/linux/pcs/pcs.h b/include/linux/pcs/pcs.h
> index 83e0a2ad4b099..a6fe9f71174ab 100644
> --- a/include/linux/pcs/pcs.h
> +++ b/include/linux/pcs/pcs.h

[ ... ]

> @@ -50,6 +51,28 @@ int unregister_fwnode_pcs_notifier(struct notifier_block *nb);

[ ... ]

> + * Returns: a pointer to the phylink_pcs, NULL or a negative error pointer. Can
> + * return -EINVAL if the PCS provider firmware node doesn't match the referenced
> + * firmware node or a negative error pointer (or NULL) from the PCS provider
> + * xlate function for the relevant firmware node and PCS handle index.
> + */
> +struct phylink_pcs *fwnode_pcs_get_from_provider(struct fwnode_pcs_provider *provider,
> +						 const struct fwnode_handle *fwnode,
> +						 int index);

[Severity: Low]
The Returns: section doesn't seem to cover every case. The implementation
also returns errors from fwnode_parse_pcsspec() before the provider match
is checked:

	ret = fwnode_parse_pcsspec(fwnode, index, NULL, &pcsspec);
	if (ret)
		return ERR_PTR(ret);

Examples are -ENOENT for an out-of-range index and -EINVAL for a NULL
fwnode. The stub used when PCS support is disabled returns
ERR_PTR(-ENOENT). Could these be documented as well?

This isn't a bug, but there is a type mismatch. The new helper takes an
int index, while fwnode_pcs_get() and fwnode_phylink_pcs_count() use
unsigned int. pcs_provider_notify() also stores the unsigned count in an
int.


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v22 10/15] net: Document PCS subsystem
  2026-11-17 12:39 ` [PATCH net-next v22 10/15] net: Document PCS subsystem Christian Marangi
@ 2026-11-21 23:26   ` Jakub Kicinski
  0 siblings, 0 replies; 25+ messages in thread
From: Jakub Kicinski @ 2026-11-21 23:26 UTC (permalink / raw)
  To: ansuelsmth
  Cc: Jakub Kicinski, andrew+netdev, davem, edumazet, pabeni, robh,
	krzk+dt, conor+dt, horms, corbet, skhan, rdunlap, lorenzo,
	hkallweit1, linux, maxime.chevallier, p.zabel, nathan,
	ndesaulniers, morbo, justinstitt, rmk+kernel, netdev, devicetree,
	linux-kernel, linux-doc, linux-arm-kernel, linux-mediatek, llvm,
	zhengping.zhang

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
net: Document PCS subsystem

This commit adds Documentation/networking/pcs.rst. The new file describes
the PCS subsystem, the fwnode producer/consumer API, late PCS registration
handling, and has an API reference section. It also updates the
sfp-phylink migration guide to point at num_possible_pcs and
fill_available_pcs, and marks mac_select_pcs as deprecated.

> diff --git a/Documentation/networking/pcs.rst b/Documentation/networking/pcs.rst
> new file mode 100644
> index 0000000000000..71d1283a72cd1
> --- /dev/null
> +++ b/Documentation/networking/pcs.rst
> @@ -0,0 +1,231 @@

[ ... ]

> +With the use of the :c:func:`fwnode_phylink_pcs_parse` a common implementation
> +is the following::
> +
> +   static int mac_fill_available_pcs(struct phylink_config *config,
> +   				                      struct phylink_pcs **available_pcs,
> +					                      unsigned int num_possible_pcs)
> +   {
> +   	struct device *dev = config->dev;
> +
> +   	return fwnode_phylink_pcs_parse(dev_fwnode(dev), available_pcs,
> +						                    num_possible_pcs);
> +   }
> +
> +   static int mac_setup_phylink(struct net_device *netdev)
> +   {
> +      struct phylink_config *config;
> +
> +      // ...
> +
> +      config->dev = &netdev->dev;
> +
> +      // ...
> +
> +      // Parse possible PCS and fill num_possible_pcs.
> +      config->num_possible_pcs = fwnode_phylink_pcs_count(dev_fwnode(&netdev->dev));
> +      config->fill_available_pcs = mac_fill_available_pcs;
> +

[ ... ]

> +      phylink = phylink_create(config, //...

[Severity: Medium]
The example parses pcs-handle from dev_fwnode(&netdev->dev) for both
num_possible_pcs and fill_available_pcs. The fwnode passed to
phylink_create() is cut off. Do these two have to be the same node?

The earlier text describes both helpers as taking "the fwnode where the
pcs-handle should be parsed", which reads as if the MAC driver can pick
any node.

However, pcs_provider_notify() in drivers/net/phy/phylink.c only ever uses
pl->fwnode, which is the node given to phylink_create():

	case FWNODE_PCS_PROVIDER_ADD:
		count = fwnode_phylink_pcs_count(pl->fwnode);
		for (i = 0; i < count; i++) {
			pcs = fwnode_pcs_get_from_provider(pp, pl->fwnode, i);
	...
	case FWNODE_PCS_PROVIDER_DEL:
		list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
			if (!fwnode_pcs_matches_provider(pp, pl->fwnode, pcs))
				continue;

If dev_fwnode(&netdev->dev) is NULL, fwnode_phylink_pcs_count() returns
0 and no PCS is filled at create time. A provider that was already
registered never sends ADD again, so the PCS is never attached and the
major config fails.

If a PCS is filled from node A while pl->fwnode is node B, the
PROVIDER_DEL check never matches it. The PCS stays on pl->pcs_list with
pcs->phylink still set after the provider has freed it. Later,
phylink_detach_pcss() writes to the freed memory:

	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
		rcu_assign_pointer(pcs->phylink, NULL);
		list_del(&pcs->list);

pl->pcs may also still point at it.

Could the example pass the same fwnode to phylink_create(), and could the
text state this requirement? The airoha_eth user later in the series only
works because it sets netdev->dev.of_node = np and passes
of_fwnode_handle(np) to phylink_create().

[ ... ]

> +The ``fill_available_pcs`` callback is called only on :c:func:`phylink_create`
> +and is used only to compose the initial available PCS list. Ownership of PCS
> +is held by phylink.

[Severity: Low]
Is "Ownership of PCS is held by phylink" accurate? phylink_add_pcs() links
the PCS in without taking any reference:

	list_add_tail(&pcs->list, &pl->pcs_list);

	/* Link PCS to phylink */
	rcu_assign_pointer(pcs->phylink, pl);

phylink never frees a struct phylink_pcs. phylink_fill_available_pcs()
frees only the temporary pointer array. The memory stays with the provider
driver, or with the MAC driver for an internal PCS. phylink drops its
borrowed pointer only in the FWNODE_PCS_PROVIDER_DEL notifier sent by
fwnode_pcs_del_provider(), or in phylink_detach_pcss().

On teardown ordering, the "Writing PCS Drivers" section only says "You
must call fwnode_pcs_del_provider from your remove function on driver
detach." Could it state the lifetime rule? A provider's phylink_pcs has to
stay valid until fwnode_pcs_del_provider(), or the devres release from
devm_fwnode_pcs_add_provider(), has returned. A MAC-internal PCS has to
outlive phylink_destroy().

Without that rule, a provider might free its PCS in .remove() while
relying on the devm variant, or kfree() it before calling
fwnode_pcs_del_provider(). In either case pcs_provider_notify() runs the
xlate, list_del(&pcs->list) and possibly phylink_pcs_disable() on freed
memory.

[ ... ]

> +It's worth to mention that xlate function MUST reference already allocated
> +:c:struct:`phylink_pcs` pointer and MUST NOT dynamically allocate new PCS.
> +The returned pointer is used to identify the PCS across provider lookup and
> +removal notifications.

[Severity: Low]
Should this section also say that a struct phylink_pcs can be attached to
only one phylink instance at a time? phylink_add_pcs() refuses a second
attach:

	if (WARN(rcu_access_pointer(pcs->phylink),
		 "%s: PCS already attached to a phylink instance\n",
		 __func__))
		return false;

phylink_fill_available_pcs() ignores that return value:

		phylink_add_pcs(pl, pcs);

If two MAC nodes have a pcs-handle that resolves to the same phylink_pcs,
the second MAC gets a WARN splat and runs without that PCS. Its major
config can then fail. The text requires an already allocated PCS but says
nothing about a single owner, so a provider author might share one PCS
object across several ports.

> +Late PCS registration handling
> +------------------------------
> +
> +It's possible that a PCS becomes available after the MAC finished probing.
> +Contrary to the usual producer/consumer implementation, when a PCS is not
> +registered and can't be found, the fwnode parser helper returns ``-ENODEV``
> +instead of ``-EPROBE_DEFER``.

[ ... ]

> +Function :c:func:`pcs_provider_notify` will check if the just added PCS
> +should be used by the phylink instance. If it should be used then,
> +it's added to the internal list of available PCS and a phylink major
> +config is forced.

[Severity: Low]
A few statements in pcs.rst don't seem to match the implementation.

Is a major config always forced here? pcs_provider_notify() forces one
only after an earlier major config failure:

		if (resolve && pl->major_config_failed) {
			pl->force_major_config = true;
			pl->link_failed = true;
		}

Otherwise it only refreshes supported_interfaces and the capabilities and
runs a resolve.

The text above says "the fwnode parser helper returns -ENODEV". But
fwnode_phylink_pcs_parse() skips per-entry -ENODEV. It returns -ENODEV
only when the pcs-handle property is missing:

	if (!fwnode_property_present(fwnode, "pcs-handle"))
		return -ENODEV;

The "Using PCS Devices" section says the helper returns the number of
available PCS found, and doesn't mention this case.
phylink_fill_available_pcs() treats any negative return as fatal:

	ret = config->fill_available_pcs(config, pcss, config->num_possible_pcs);
	if (ret < 0)
		goto out;

So a MAC with a fixed num_possible_pcs that calls the helper on a node
without pcs-handle would fail phylink_create(). Could this case be
documented?

In "Looking up PCS Devices", the two paragraphs before this sentence refer
to supported_interfaces in struct phylink_pcs:

  supported_interfaces describes all interface modes supported by the MAC,
  whereas pcs_interfaces identifies the subset that require PCS selection.

That sentence describes phylink_config.supported_interfaces instead.
Which one is meant? Also, phylink_create() and pcs_provider_notify() OR
every pcs->supported_interfaces into pl->supported_interfaces, so the
code doesn't enforce the subset relationship.

The docs present mac_select_pcs and num_possible_pcs as alternatives.
They don't mention that phylink_create() returns -EINVAL when both are
set. Should that be stated?

[ ... ]

> diff --git a/Documentation/networking/sfp-phylink.rst b/Documentation/networking/sfp-phylink.rst
> index 5bf285d73e8a1..306505118eba9 100644
> --- a/Documentation/networking/sfp-phylink.rst
> +++ b/Documentation/networking/sfp-phylink.rst
> @@ -311,33 +311,20 @@ this documentation.

[ ... ]

> +12. Populate the :c:var:`num_possible_pcs` value and
> +    :c:func:`fill_available_pcs` callback and add it to your
> +    :c:type:`struct phylink_config <phylink_config>`.
>  
> -                return NULL;
> -        }
> +    Refer to :ref:`Documentation/networking/pcs.rst <pcs_consumer>` for
> +    further details and examples.
>  
> -    See :c:func:`mvpp2_select_pcs` for an example of a driver that has multiple
> -    internal PCS.
> +    Notice that the previous implementation of populating
> +    :c:func:`mac_select_pcs` is considered deprecated in favor of the new
> +    described above.

[Severity: Low]
num_possible_pcs and fill_available_pcs are members of struct
phylink_config, not a global variable and a function. Will the :c:var:
and :c:func: references resolve? The plain literal markup used in pcs.rst
might be a better fit here.

pcs.rst also refers twice to :c:func: pcs_provider_notify. That is a
static function in drivers/net/phy/phylink.c with no kernel-doc, so the
reference can't resolve either. It also puts an internal symbol into the
user-facing documentation.

This step calls mac_select_pcs deprecated, but its kernel-doc in
include/linux/phylink.h is unchanged at the end of the series:

  * mac_select_pcs: Select a PCS for the interface mode.

That kernel-doc still presents mac_select_pcs as the normal mechanism.
Should it be updated so the API reference matches this guidance?


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v22 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS
  2026-11-17 12:39 ` [PATCH net-next v22 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
@ 2026-11-21 23:26   ` Jakub Kicinski
  0 siblings, 0 replies; 25+ messages in thread
From: Jakub Kicinski @ 2026-11-21 23:26 UTC (permalink / raw)
  To: ansuelsmth
  Cc: Jakub Kicinski, andrew+netdev, davem, edumazet, pabeni, robh,
	krzk+dt, conor+dt, horms, corbet, skhan, rdunlap, lorenzo,
	hkallweit1, linux, maxime.chevallier, p.zabel, nathan,
	ndesaulniers, morbo, justinstitt, rmk+kernel, netdev, devicetree,
	linux-kernel, linux-doc, linux-arm-kernel, linux-mediatek, llvm,
	zhengping.zhang

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
dt-bindings: net: pcs: Document support for Airoha Ethernet PCS

This adds a DT binding for the Airoha AN7581 PCS blocks on the Ethernet,
PON, PCIe and USB serdes ports. It follows the new PCS provider model,
where consumers reference the PCS through #pcs-cells.

> diff --git a/Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml b/Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml
> new file mode 100644
> index 0000000000000..9c1d116c1b016
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml

[ ... ]

> +description:
> +  Airoha AN7581 SoC expose multiple Physical Coding Sublayer (PCS) for
> +  the various Serdes port supporting different Media Independent Interface
> +  (10BASE-R, USXGMII, 2500BASE-X, 1000BASE-X, SGMII).

[Severity: Low]
This isn't a bug, but should 10BASE-R be 10GBASE-R here? The commit
message has the same typo:

  (10BASE-R, USXGMII, 2500BASE-X, 1000BASE-X, SGMII).

The driver later in the series sets PHY_INTERFACE_MODE_10GBASER in
airoha_pcs_probe().

[ ... ]

> +  airoha,scu:
> +    $ref: /schemas/types.yaml#/definitions/phandle
> +    description: phandle to the SCU node required to configure
> +      the serdes line to the correct interface mode.

[Severity: Medium]
Is a bare SCU phandle the right interface for selecting the serdes mode?

The SCU already offers this as a generic PHY provider. In
clock/airoha,en7523-scu.yaml:

  '#phy-cells':
    description:
      The first cell indicates the serdes phy number, see [2] for the
      available serdes port.
    const: 1

In drivers/clk/clk-en7523.c, en7581_serdes_phy_set_mode() handles
PHY_MODE_ETHERNET. It writes the REG_NP_SCU_SSTR XSI0/XSI1 select bits
while holding priv->lock.

The PCS driver later in the series writes the same bits through this
phandle, using its own regmap, in airoha_pcs_setup_scu_pcie():

    regmap_update_bits(priv->scu, AIROHA_SCU_SSTR,
                       AIROHA_SCU_PCIE_XSI0_SEL,
                       xsi_sel);

Doesn't that leave two unsynchronized read-modify-write paths on the
same SCU register?

Probing looks like a problem too. airoha_pcs_probe() does:

    priv->scu = syscon_regmap_lookup_by_phandle(dev->of_node,
                                                "airoha,scu");

The scuclk node in the example has only the compatible
"airoha,en7581-scu". It isn't a "syscon", and nothing registers it with
of_syscon_register_regmap().

Won't the lookup return -EPROBE_DEFER on every attempt? If so, the
eth/pon/pcie PCS never probes when the DT follows the example.

The phandle also has no cells. That means the dual-lane pcie node can't
say which SCU serdes port each PCS instance drives.

Could the binding use something like this instead of airoha,scu plus
phys: false?

    phys = <&scuclk AIROHA_SCU_SERDES_PCIE1>,
           <&scuclk AIROHA_SCU_SERDES_PCIE2>;

The usb variant already uses phys.

[ ... ]

> +  - if:
> +      properties:
> +        compatible:
> +          contains:
> +            const: airoha,an7581-pcs-pcie
> +
> +    then:
> +      properties:
> +        reg:

[ ... ]

> +        phys: false
> +
> +        "#pcs-cells":
> +          const: 1

[Severity: Medium]
With #pcs-cells set to 1, a MAC that uses one of the PCIe serdes PCS
instances has to write pcs-handle = <&pcs N>. Will the consumer schema
accept that?

ethernet-controller.yaml still has:

  pcs-handle:
    $ref: /schemas/types.yaml#/definitions/phandle-array
    items:
      maxItems: 1

That allows only the phandle in each entry. airoha,en7581-eth.yaml
references ethernet-controller.yaml# for its ethernet@N subnodes. A GMAC
node with pcs-handle = <&pcs_pcie 0> would then fail dtbs_check.

At runtime, fwnode_parse_pcsspec() in drivers/net/pcs/pcs.c parses the
"#pcs-cells" argument. airoha_pcs_xlate() rejects a PCIe specifier when
nargs != 1.

No patch in the series changes ethernet-controller.yaml. Its pcs-handle
description also still refers to a PCS PHY device on an MDIO bus.

[ ... ]

> +      required:
> +        - phys
> +
> +additionalProperties: false

[Severity: Medium]
Should resets and reset-names be documented here? The driver later in
the series requests them in airoha_pcs_probe():

    priv->rsts[0].id = "mac";
    priv->rsts[1].id = "phy";
    ret = devm_reset_control_bulk_get_optional_exclusive(dev,
                                    ARRAY_SIZE(priv->rsts),
                                    priv->rsts);

airoha_pcs_setup_scu() then asserts and deasserts these resets on every
interface setup.

The SCU reset controller has matching lines in
include/dt-bindings/reset/airoha,en7581-reset.h. Examples are
EN7581_XSI_PHY_RST, EN7581_XPON_PHY_RST and EN7581_XPON_MAC_RST.

Because of additionalProperties: false, a DT that provides these resets
fails validation. A DT that passes validation has no resets, so the reset
sequence in airoha_pcs_setup_scu() does nothing.

Wouldn't the PCS then stay in whatever state the bootloader or the
previous interface mode left it in?

[ ... ]

> +    pcs@1fa04000 {
> +      compatible = "airoha,an7581-pcs-pcie";
> +      reg = <0x1fa04000 0x1000>,

[ ... ]

> +            <0x1fa5a000 0x1000>,
> +            <0x1fa5b000 0x1000>,
> +            <0x1fa5c000 0x1000>;

[Severity: Medium]
Do these ranges overlap the existing PCIe PHY? In
arch/arm64/boot/dts/airoha/en7581.dtsi, the pciephy: phy@1fa5a000 node
is enabled and claims the same blocks:

    reg = <0x0 0x1fa5a000 0x0 0xfff>,
          <0x0 0x1fa5b000 0x0 0xfff>,
          <0x0 0x1fa5c000 0x0 0xfff>, ...
    reg-names = "csr-2l", "pma0", "pma1", ...

airoha_pcie_phy_probe() and airoha_pcs_init_named_regmap() both map these
ranges with devm_platform_ioremap_resource_byname(), which requests the
memory region.

Won't the driver that probes second fail with -EBUSY?

That would also rule out mixed setups, such as PCIe on one lane and
Ethernet on the other, because both need the shared csr-2l/pma blocks.

This variant also sets phys: false. The PCS therefore can't hand the
analog/PMA side to the PHY that owns it, the way the usb variant does.


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v22 15/15] net: airoha: add phylink support
  2026-11-17 12:39 ` [PATCH net-next v22 15/15] net: airoha: add phylink support Christian Marangi
@ 2026-11-21 23:26   ` Jakub Kicinski
  0 siblings, 0 replies; 25+ messages in thread
From: Jakub Kicinski @ 2026-11-21 23:26 UTC (permalink / raw)
  To: ansuelsmth
  Cc: Jakub Kicinski, andrew+netdev, davem, edumazet, pabeni, robh,
	krzk+dt, conor+dt, horms, corbet, skhan, rdunlap, lorenzo,
	hkallweit1, linux, maxime.chevallier, p.zabel, nathan,
	ndesaulniers, morbo, justinstitt, rmk+kernel, netdev, devicetree,
	linux-kernel, linux-doc, linux-arm-kernel, linux-mediatek, llvm,
	zhengping.zhang

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
net: airoha: add phylink support

This adds phylink support for each GDM port. GDM1 is limited to the
internal interface mode, and GDM2/3/4 use a PCS referenced through the
pcs-handle property. The ethtool link_ksettings ops now go through
phylink, and GDM4 TX/RX fragment sizes are set on link up.

> diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
> index 044ad0302ef35..e41dfad58b258 100644
> --- a/drivers/net/ethernet/airoha/airoha_eth.c
> +++ b/drivers/net/ethernet/airoha/airoha_eth.c

[ ... ]

> @@ -3752,6 +3790,155 @@ bool airoha_is_valid_gdm_dev(struct airoha_eth *eth,
>  	return false;
>  }
>  
> +/* Nothing to do in MAC, everything is handled in PCS */
> +static void airoha_mac_config(struct phylink_config *config, unsigned int mode,
> +			      const struct phylink_link_state *state)
> +{
> +}
> +
> +static void airoha_mac_link_up(struct phylink_config *config, struct phy_device *phy,
> +			       unsigned int mode, phy_interface_t interface,
> +			       int speed, int duplex, bool tx_pause, bool rx_pause)
> +{
> +	struct airoha_gdm_dev *dev = container_of(config, struct airoha_gdm_dev,
> +						  phylink_config);
> +	struct airoha_gdm_port *port = dev->port;
> +	struct airoha_eth *eth = dev->eth;
> +	u32 frag_size_tx, frag_size_rx;
> +
> +	/* TX/RX frag is configured only for GDM4 */
> +	if (port->id != AIROHA_GDM4_IDX)
> +		return;

[Severity: Medium]
Should tx_pause and rx_pause be applied somewhere in airoha_mac_link_up()?

airoha_setup_phylink() advertises MAC_ASYM_PAUSE | MAC_SYM_PAUSE on every
GDM port. However, airoha_mac_link_up() returns right away for GDM1-3 and
only writes fragment sizes for GDM4.

Nothing in drivers/net/ethernet/airoha uses tx_pause, rx_pause or
GDM_INGRESS_FC_EN_MASK.

The only flow control setup on this path is in airoha_pcs_config():

drivers/net/pcs/airoha/pcs-airoha-common.c:airoha_pcs_config() {
    ...
	/* Configure Flow Control on XFI */
	regmap_update_bits(maps->pcs_mac, AIROHA_PCS_XFI_MAC_XFI_GIB_CFG,
			   AIROHA_PCS_XFI_TX_FC_EN | AIROHA_PCS_XFI_RX_FC_EN,
			   permit_pause_to_mac ?
				AIROHA_PCS_XFI_TX_FC_EN | AIROHA_PCS_XFI_RX_FC_EN :
				0);
    ...
}

permit_pause_to_mac reflects whether pause autoneg is enabled. It is not
the result negotiated with the link partner.

With the default MLO_PAUSE_AN, XFI TX/RX flow control ends up enabled even
when the partner does not support pause. With pause forced on and autoneg
off, it ends up disabled while phylink reports pause as on.

Can the hardware flow control state differ from what phylink resolved and
reports?

Also, only get/set_link_ksettings were moved to phylink in
airoha_ethtool_ops. These are not wired up:

  get/set_pauseparam (phylink_ethtool_get/set_pauseparam())
  nway_reset (phylink_ethtool_nway_reset())
  ndo_eth_ioctl (phylink_mii_ioctl())

Is that intended, given the commit message says "now that we fully support
phylink"?

[ ... ]

> +static int airoha_setup_phylink(struct net_device *netdev)
> +{
> +	struct airoha_gdm_dev *dev = netdev_priv(netdev);
> +	struct device_node *np = netdev->dev.of_node;
> +	struct airoha_gdm_port *port = dev->port;
> +	struct phylink_config *config;
> +	phy_interface_t phy_mode;
> +	struct phylink *phylink;
> +	int err;
> +
> +	err = of_get_phy_mode(np, &phy_mode);
> +	if (err) {
> +		dev_err(&netdev->dev, "incorrect phy-mode\n");
> +		return err;
> +	}

[Severity: Medium]
Does this stop DTs that follow the current airoha,en7581-eth.yaml binding
from probing?

The binding's ^ethernet@[1-4]$ and ^ethernet@[0-5]$ patternProperties
only require reg and compatible. The binding example has no phy-mode,
fixed-link or pcs-handle. That example is ethernet@1, plus ethernet@4
with eth-port children @0 and @1.

With this patch, a missing phy-mode on any enabled GDM or eth-port node
propagates up:

airoha_probe()
  airoha_alloc_gdm_port()
    airoha_alloc_gdm_device()
      return airoha_setup_phylink(netdev);
        of_get_phy_mode() fails

airoha_probe() then runs the error_napi_stop teardown, so every port is
lost, GDM1 included. Before this patch the driver never called
of_get_phy_mode(), and such DTs probed fine.

A similar problem shows up in airoha_dev_open():

	err = phylink_of_phy_connect(dev->phylink, netdev->dev.of_node, 0);
	if (err) {
		netdev_err(netdev, "could not attach PHY: %d\n", err);
		return err;
	}

Suppose a node has phy-mode but no phy-handle, fixed-link, SFP or in-band
managed mode. Phylink is then in MLO_AN_PHY, and
phylink_fwnode_phy_connect() returns -ENODEV. Won't ndo_open now fail
where it used to succeed?

The commit message implies that GDM2/3/4 need pcs-handle. The code means
GDM1 needs phy-mode = "internal" plus fixed-link, because only
PHY_INTERFACE_MODE_INTERNAL is in supported_interfaces. The ethernet
binding describes neither. The series updates the PCS binding but not
this one.

Should airoha,en7581-eth.yaml be updated too? Alternatively, should the
driver fall back (for example to internal on GDM1) when phy-mode is
absent?

The in-tree en7581.dtsi gdm1 node already has phy-mode = "internal" and
fixed-link, so in-tree boards still work.

> +
> +	config = &dev->phylink_config;
> +	config->dev = &netdev->dev;
> +	config->type = PHYLINK_NETDEV;

[ ... ]

> +	} else {
> +		config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
> +					   MAC_10 | MAC_100 | MAC_1000 |
> +					   MAC_2500FD | MAC_5000FD | MAC_10000FD;

[Severity: Medium]
MAC_10, MAC_100 and MAC_1000 include MAC_10HD, MAC_100HD and MAC_1000HD.
That means phylink will advertise and accept half duplex. Is half duplex
actually supported on these ports?

Nothing seems to configure duplex:

  airoha_mac_link_up() ignores its duplex argument
  airoha_pcs_link_up() never reads duplex
  the Airoha PCS get_state helpers hard code DUPLEX_FULL
  airoha_pcs_ops has no .pcs_validate to strip half duplex modes

So a PHY that links half duplex with a half-duplex-only partner would
leave the GDM/PCS running full duplex.

Separately, USXGMII is in supported_interfaces and MAC_10 is advertised.
In the out-of-band branch of airoha_pcs_link_up(), the USXGMII/10GBASE-R
speed switch has no SPEED_10 case:

drivers/net/pcs/airoha/pcs-airoha-common.c:airoha_pcs_link_up() {
    ...
		if (interface == PHY_INTERFACE_MODE_USXGMII ||
		    interface == PHY_INTERFACE_MODE_10GBASER) {
			...
			case SPEED_100:
				rate_adapt = AIROHA_PCS_HSGMII_RATE_ADPT_FORCE_RATE_ADAPT_MODE_100;
				mode = AIROHA_PCS_USXGMII_MODE_100;
				break;
			default:
				/* Not supported */
				return;
			}
    ...
	if (data->link_up)
		data->link_up(priv, port->index);

	/* BPI BMI enable */
	regmap_clear_bits(maps->pcs_mac, AIROHA_PCS_XFI_MAC_XFI_GIB_CFG,
			  AIROHA_PCS_XFI_RXMPI_STOP |
			  AIROHA_PCS_XFI_RXMBI_STOP |
			  AIROHA_PCS_XFI_TXMPI_STOP |
			  AIROHA_PCS_XFI_TXMBI_STOP);
}

When a USXGMII PHY resolves to 10M, this returns before data->link_up().
It also returns before the MPI/MBI STOP bits set by pre_config/link_down
are cleared.

Would phylink then report carrier up while the XFI datapath stays stopped
and the USXGMII mode register keeps its old speed?

> +
> +		config->num_possible_pcs = fwnode_phylink_pcs_count(dev_fwnode(config->dev));
> +		config->fill_available_pcs = airoha_fill_available_pcs;

[Severity: Low]
The commit message says:

    These needs to be defined in the GDM port node using the pcs-handle
    property.

Is that accurate? fwnode_phylink_pcs_count() returns 0 when there is no
pcs-handle, and phylink_fill_available_pcs() then returns early:

	if (!config->num_possible_pcs)
		return 0;

phylink_create() then succeeds with SGMII, 1000BASE-X, 2500BASE-X,
10GBASE-R and USXGMII in supported_interfaces but no PCS at all. There is
no error or warning.

Can the port then report carrier up from the PHY while the SerDes is
never configured? Should a missing pcs-handle on GDM2/3/4 be rejected
here?

Also, config->dev is &netdev->dev. When sub-ports exist, its of_node is
the airoha,eth-port child. So pcs-handle is read from the child node, not
from "the GDM port node".

The commit message also leaves out the new GDM4 code in
airoha_mac_link_up():

  it writes speed-dependent TX/RX fragment sizes into
  REG_FE_GDM4_TMBI_FRAG and REG_FE_GDM4_RMBI_FRAG
  it picks the SGMII1 or SGMII0 fields based on dev->nbq == 1
  it serializes the writes with the new port->link_lock mutex

Could the commit message describe this as well?


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2026-11-21 23:28 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
2026-11-21 23:26   ` Jakub Kicinski
2026-11-17 12:39 ` [PATCH net-next v22 02/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-11-21 23:26   ` Jakub Kicinski
2026-11-17 12:39 ` [PATCH net-next v22 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 05/15] net: phylink: save phylink instance fwnode on phylink_create Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 06/15] net: phylink: make phylink_validate state locked Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 07/15] net: phylink: add capabilities helpers and track modified advertising Christian Marangi
2026-11-21 23:26   ` Jakub Kicinski
2026-11-17 12:39 ` [PATCH net-next v22 08/15] net: phylink: support PCS provider release Christian Marangi
2026-11-21 23:26   ` Jakub Kicinski
2026-11-17 12:39 ` [PATCH net-next v22 09/15] net: phylink: support late PCS provider attach Christian Marangi
2026-11-21 23:26   ` Jakub Kicinski
2026-11-17 12:39 ` [PATCH net-next v22 10/15] net: Document PCS subsystem Christian Marangi
2026-11-21 23:26   ` Jakub Kicinski
2026-11-17 12:39 ` [PATCH net-next v22 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-11-21 23:26   ` Jakub Kicinski
2026-11-17 12:39 ` [PATCH net-next v22 15/15] net: airoha: add phylink support Christian Marangi
2026-11-21 23:26   ` Jakub Kicinski
2026-11-17 12:43 ` [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS netdev-bot+sinfo
2026-11-17 12:47   ` Christian Marangi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox