Skip to contentSkip to conversation

net: pcs: Introduce support for fwnode PCS

PATCH Superseded Christian Marangi 3 participants 22 messages Aug 13 – Aug 19

Subsystems (8)

v14 of 23 Superseded Latest is v23 →

lore
Share & tools
lore
#0 lore raw

v14 cover net: pcs: Introduce support for fwnode PCS

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.

---

Changes v14:
- Fix deadlong 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 (12):
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: 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              |  234 ++
 Documentation/networking/sfp-phylink.rst      |   35 +-
 MAINTAINERS                                   |    9 +
 drivers/net/ethernet/airoha/Kconfig           |    2 +
 drivers/net/ethernet/airoha/airoha_eth.c      |  199 +-
 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                |   13 +
 drivers/net/pcs/airoha/Makefile               |    7 +
 drivers/net/pcs/airoha/pcs-airoha-common.c    | 1303 ++++++++++
 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/phylink.c                     |  419 +++-
 include/linux/pcs/pcs-provider.h              |   70 +
 include/linux/pcs/pcs.h                       |  174 ++
 include/linux/phylink.h                       |   28 +
 21 files changed, 6448 insertions(+), 60 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 include/linux/pcs/pcs-provider.h
 create mode 100644 include/linux/pcs/pcs.h
Signature · 1 line
2.53.0
#1 lore raw

PATCH v14 1/12 net: phylink: keep and use MAC supported_interfaces in phylink struct

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.

---
 drivers/net/phy/phylink.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/net/phy/phylink.c +15 -7
index b241768edbcb..e1e9f07f51bc 100644
@@ -60,6 +60,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;
 
@@ -628,7 +633,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,
@@ -1903,6 +1908,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);
@@ -2024,7 +2032,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");
@@ -2824,12 +2832,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;
 	}
 
@@ -3757,14 +3765,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");
@@ -3935,7 +3943,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);
 
 	/* Do the initial configuration */
 	return phylink_sfp_config_phy(pl, phy);
Signature · 1 line
2.53.0
#2 lore raw

PATCH v14 2/12 net: phylink: introduce internal phylink PCS handling

In reply to Christian Marangi

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.

---
 drivers/net/phy/phylink.c | 200 +++++++++++++++++++++++++++++++++-----
 include/linux/phylink.h   |  16 +++
 2 files changed, 194 insertions(+), 22 deletions(-)
drivers/net/phy/phylink.c +178 -22
index e1e9f07f51bc..6204e3bba16d 100644
@@ -60,6 +60,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.
 	 */
@@ -517,12 +520,29 @@ 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)
 {
-	struct phylink_pcs *pcs = NULL;
 	unsigned long capabilities;
+	struct phylink_pcs *pcs;
+	bool pcs_found = false;
 	int ret;
 
 	/* Get the PCS for this interface mode */
@@ -530,9 +550,24 @@ 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);
+
+		pcs_found = !!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)) {
+		list_for_each_entry(pcs, &pl->pcs_list, list) {
+			if (!phylink_validate_pcs_interface(pcs, state->interface)) {
+				pcs_found = true;
+				break;
+			}
+		}
 	}
 
-	if (pcs) {
+	if (pcs_found) {
 		/* The PCS, if present, must be setup before phylink_create()
 		 * has been called. If the ops is not initialised, print an
 		 * error and backtrace rather than oopsing the kernel.
@@ -544,13 +579,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;
 		}
@@ -964,12 +996,22 @@ static unsigned int phylink_inband_caps(struct phylink *pl,
 					 phy_interface_t interface)
 {
 	struct phylink_pcs *pcs;
+	bool pcs_found = false;
 
-	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);
+		pcs_found = !!pcs;
+	} else if (test_bit(interface, pl->config->pcs_interfaces)) {
+		list_for_each_entry(pcs, &pl->pcs_list, list) {
+			if (!phylink_validate_pcs_interface(pcs, interface)) {
+				pcs_found = true;
+				break;
+			}
+		}
+	}
 
-	pcs = pl->mac_ops->mac_select_pcs(pl->config, interface);
-	if (!pcs)
+	if (!pcs_found)
 		return 0;
 
 	return phylink_pcs_inband_caps(pcs, interface);
@@ -1264,10 +1306,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)) {
+		bool pcs_found = false;
+
+		list_for_each_entry(pcs, &pl->pcs_list, list) {
+			if (!phylink_validate_pcs_interface(pcs,
+							    state->interface)) {
+				pcs_found = true;
+				break;
+			}
+		}
 
-		pcs_changed = pl->pcs != pcs;
+		if (!pcs_found) {
+			phylink_err(pl,
+				    "couldn't find a PCS for %s\n",
+				    phy_modes(state->interface));
+
+			pl->major_config_failed = true;
+			return;
+		}
 	}
 
+	pcs_changed = pl->pcs != pcs;
+
 	phylink_pcs_neg_mode(pl, pcs, state->interface, state->advertising);
 
 	phylink_dbg(pl, "major config, active %s/%s/%s\n",
@@ -1294,13 +1362,15 @@ static void phylink_major_config(struct phylink *pl, bool restart,
 	if (pcs_changed) {
 		phylink_pcs_disable(pl->pcs);
 
-		if (pl->pcs)
-			pl->pcs->phylink = NULL;
+		if (pl->mac_ops->mac_select_pcs) {
+			if (pl->pcs)
+				pl->pcs->phylink = NULL;
 
-		if (pcs)
-			pcs->phylink = pl;
+			if (pcs)
+				pcs->phylink = pl;
+		}
 
-		pl->pcs = pcs;
+		WRITE_ONCE(pl->pcs, pcs);
 	}
 
 	if (pl->pcs)
@@ -1833,6 +1903,44 @@ 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;
+
+		list_add_tail(&pcs->list, &pl->pcs_list);
+	}
+
+out:
+	kfree(pcss);
+
+	return ret;
+}
+
 /**
  * phylink_create() - create a phylink instance
  * @config: a pointer to the target &struct phylink_config
@@ -1854,9 +1962,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,
@@ -1871,6 +1990,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) {
@@ -1908,16 +2028,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)
+		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);
@@ -1936,6 +2071,11 @@ 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_safe(pcs, tmp, &pl->pcs_list, list) {
+		list_del(&pcs->list);
+		pcs->phylink = NULL;
+	}
 free_pl:
 	kfree(pl);
 	return ERR_PTR(ret);
@@ -1953,11 +2093,20 @@ EXPORT_SYMBOL_GPL(phylink_create);
  */
 void phylink_destroy(struct phylink *pl)
 {
+	struct phylink_pcs *pcs, *tmp;
+
 	sfp_bus_del_upstream(pl->sfp_bus);
 	if (pl->link_gpio)
 		gpiod_put(pl->link_gpio);
 
 	cancel_work_sync(&pl->resolve);
+
+	/* Remove every PCS from phylink PCS list */
+	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
+		pcs->phylink = NULL;
+		list_del(&pcs->list);
+	}
+
 	kfree(pl);
 }
 EXPORT_SYMBOL_GPL(phylink_destroy);
@@ -2409,8 +2558,15 @@ void phylink_pcs_change(struct phylink_pcs *pcs, bool up)
 {
 	struct phylink *pl = pcs->phylink;
 
-	if (pl)
-		phylink_link_changed(pl, up, "pcs");
+	/*
+	 * Ignore PCS link state change if the PCS is not
+	 * attached to a phylink instance or the phylink
+	 * instance is not currently using this PCS.
+	 */
+	if (!pl || READ_ONCE(pl->pcs) != pcs)
+		return;
+
+	phylink_link_changed(pl, up, "pcs");
 }
 EXPORT_SYMBOL_GPL(phylink_pcs_change);
 
include/linux/phylink.h +16 -0
index 2bc0db3d52ac..ca9dfc142388 100644
@@ -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 *phylink;
 	bool poll;
 	bool rxc_always_on;
+
+	/* private: */
+	struct list_head list;
 };
 
 /**
Signature · 1 line
2.53.0
#4 lore raw

PATCH v14 3/12 net: pcs: implement Firmware node support for PCS driver

In reply to Christian Marangi

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.

---
 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
drivers/net/pcs/Kconfig +6 -0
index e417fd66f660..ba2caec866a5 100644
@@ -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
drivers/net/pcs/Makefile +1 -0
index 4f7920618b90..3005cdd89ab7 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 # Makefile for Linux PCS drivers
 
+obj-$(CONFIG_FWNODE_PCS)	+= pcs.o
 pcs_xpcs-$(CONFIG_PCS_XPCS)	:= pcs-xpcs.o pcs-xpcs-plat.o \
 				   pcs-xpcs-nxp.o pcs-xpcs-wx.o
 
drivers/net/pcs/pcs.c new file +245 -0

245 lines not on this page · raw message

include/linux/pcs/pcs-provider.h new file +70 -0

70 lines not on this page · raw message

include/linux/pcs/pcs.h new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
2.53.0
#6 lore raw

PATCH v14 4/12 net: phylink: save phylink instance fwnode on phylink_create

In reply to Christian Marangi

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().

---
 drivers/net/phy/phylink.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/phy/phylink.c +5 -0
index 6204e3bba16d..82eae20daed0 100644
@@ -44,6 +44,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;
 
@@ -1993,6 +1994,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);
@@ -2077,6 +2079,7 @@ struct phylink *phylink_create(struct phylink_config *config,
 		pcs->phylink = NULL;
 	}
 free_pl:
+	fwnode_handle_put(pl->fwnode);
 	kfree(pl);
 	return ERR_PTR(ret);
 }
@@ -2107,6 +2110,8 @@ void phylink_destroy(struct phylink *pl)
 		list_del(&pcs->list);
 	}
 
+	fwnode_handle_put(pl->fwnode);
+
 	kfree(pl);
 }
 EXPORT_SYMBOL_GPL(phylink_destroy);
Signature · 1 line
2.53.0
#7 lore raw

PATCH v14 5/12 net: phylink: support PCS provider release

In reply to Christian Marangi

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.

---
 drivers/net/pcs/pcs.c     |  47 +++++++++++++
 drivers/net/phy/phylink.c | 141 ++++++++++++++++++++++++++++++++++++--
 include/linux/pcs/pcs.h   |  69 +++++++++++++++++++
 3 files changed, 250 insertions(+), 7 deletions(-)
drivers/net/pcs/pcs.c +47 -0
index 39550d9a12a2..25b3248e8b93 100644
@@ -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;
drivers/net/phy/phylink.c +134 -7

270 lines not on this page · raw message

include/linux/pcs/pcs.h +69 -0

94 lines not on this page · raw message

Signature · 1 line
2.53.0
#9 lore raw

PATCH v14 6/12 net: phylink: support late PCS provider attach

In reply to Christian Marangi

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.

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.

---
 drivers/net/pcs/pcs.c     | 22 +++++++++++
 drivers/net/phy/phylink.c | 82 +++++++++++++++++++++++++++++++--------
 include/linux/pcs/pcs.h   | 31 +++++++++++++++
 3 files changed, 118 insertions(+), 17 deletions(-)
drivers/net/pcs/pcs.c +22 -0
index 25b3248e8b93..fef560eddf2a 100644
@@ -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)
drivers/net/phy/phylink.c +65 -17

122 lines not on this page · raw message

include/linux/pcs/pcs.h +31 -0
index 83e0a2ad4b09..00a636c82c65 100644
@@ -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 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) or
+ * can return -EINVAL if the PCS provider doesn't expose any PCS for the fwnode.
+ */
+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)
Signature · 1 line
2.53.0
#11 lore raw

PATCH v14 7/12 net: Document PCS subsystem

In reply to Christian Marangi

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

Also update the sfp-phylink migration guide.

---
 Documentation/networking/index.rst       |   1 +
 Documentation/networking/pcs.rst         | 234 +++++++++++++++++++++++
 Documentation/networking/sfp-phylink.rst |  35 ++--
 3 files changed, 246 insertions(+), 24 deletions(-)
 create mode 100644 Documentation/networking/pcs.rst
Documentation/networking/index.rst +1 -0
index 44a422ad3b05..3fce8f6ac089 100644
@@ -28,6 +28,7 @@ Contents:
    net_failover
    page_pool
    phy
+   pcs
    sfp-phylink
    alias
    bridge
Documentation/networking/pcs.rst new file +234 -0

234 lines not on this page · raw message

Documentation/networking/sfp-phylink.rst +11 -24
index 5bf285d73e8a..306505118eba 100644
@@ -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
Signature · 1 line
2.53.0
#12 lore raw

PATCH v14 8/12 MAINTAINERS: add myself as PCS subsystem maintainer

In reply to Christian Marangi

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

---
 MAINTAINERS | 9 +++++++++
 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
index e0e7fae5b92f..04db742696ac 100644
@@ -9690,6 +9690,15 @@ F:	include/uapi/linux/if_bridge.h
 F:	include/linux/netfilter_bridge/
 F:	net/bridge/
 
+ETHERNET PCS SUBSYSTEM
+M:	Christian Marangi <[email protected]>
+L:	[email protected]
+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 <[email protected]>
 M:	Heiner Kallweit <[email protected]>
Signature · 1 line
2.53.0
#13 lore raw

PATCH v14 9/12 net: phylink: add .pcs_link_down PCS OP

In reply to Christian Marangi

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.

---
 drivers/net/phy/phylink.c |  9 +++++++++
 include/linux/phylink.h   | 12 ++++++++++++
 2 files changed, 21 insertions(+)
drivers/net/phy/phylink.c +9 -0
index ba3efdb0a194..34dbe89328b1 100644
@@ -990,6 +990,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)
@@ -1701,6 +1707,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");
 }
 
include/linux/phylink.h +12 -0
index ca9dfc142388..ea554c0d41f8 100644
@@ -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
Signature · 1 line
2.53.0
#15 lore raw

PATCH v14 11/12 net: pcs: airoha: add PCS driver for Airoha AN7581 SoC

In reply to Christian Marangi

Add PCS driver for Airoha AN7581 SoC for Ethernet/PON/PCIe/USB SERDES and permit usage of external PHY or connected SFP cage. Supported modes are USXGMII, 10G-BASER, 2500BASE-X, 1000BASE-X and SGMII.

The driver probe and register the various needed registers and register as a PCS provider for fwnode usage.

---
 drivers/net/pcs/Kconfig                    |    2 +
 drivers/net/pcs/Makefile                   |    2 +
 drivers/net/pcs/airoha/Kconfig             |   13 +
 drivers/net/pcs/airoha/Makefile            |    7 +
 drivers/net/pcs/airoha/pcs-airoha-common.c | 1303 ++++++++++++
 drivers/net/pcs/airoha/pcs-airoha.h        | 1311 ++++++++++++
 drivers/net/pcs/airoha/pcs-an7581.c        | 2100 ++++++++++++++++++++
 7 files changed, 4738 insertions(+)
 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
drivers/net/pcs/Kconfig +2 -0
index ba2caec866a5..8fae619f2432 100644
@@ -41,4 +41,6 @@ config PCS_RZN1_MIIC
 	  Renesas RZ/N1, RZ/N2H, and RZ/T2H SoCs. This PCS converts MII to
 	  RMII/RGMII, or can be set in pass-through mode for MII.
 
+source "drivers/net/pcs/airoha/Kconfig"
+
 endmenu
drivers/net/pcs/Makefile +2 -0
index 3005cdd89ab7..91593aa8d926 100644
@@ -9,3 +9,5 @@ obj-$(CONFIG_PCS_XPCS)		+= pcs_xpcs.o
 obj-$(CONFIG_PCS_LYNX)		+= pcs-lynx.o
 obj-$(CONFIG_PCS_MTK_LYNXI)	+= pcs-mtk-lynxi.o
 obj-$(CONFIG_PCS_RZN1_MIIC)	+= pcs-rzn1-miic.o
+
+obj-$(CONFIG_PCS_AIROHA)	+= airoha/
drivers/net/pcs/airoha/Kconfig new file +13 -0
new file mode 100644
index 000000000000..1aa4c0d33b87
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config PCS_AIROHA
+	tristate
+	select FWNODE_PCS
+
+config PCS_AIROHA_AN7581
+	tristate "Airoha AN7581 PCS driver"
+	depends on ARCH_AIROHA || COMPILE_TEST
+	select PCS_AIROHA
+	help
+	  This module provides helper to phylink for managing the Airoha
+	  AN7581 PCS for SoC Ethernet and PON SERDES.
drivers/net/pcs/airoha/Makefile new file +7 -0
new file mode 100644
index 000000000000..c5201d5cc356
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_PCS_AIROHA)	:= pcs-airoha.o
+pcs-airoha-objs			:= pcs-airoha-common.o
+ifdef CONFIG_PCS_AIROHA_AN7581
+pcs-airoha-objs			+= pcs-an7581.o
+endif
drivers/net/pcs/airoha/pcs-airoha-common.c new file +1303 -0

1,303 lines not on this page · raw message

drivers/net/pcs/airoha/pcs-airoha.h new file +1311 -0

1,311 lines not on this page · raw message

drivers/net/pcs/airoha/pcs-an7581.c new file +2100 -0

355 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.53.0

Part of the diff is not shown here. View the raw message.

#17 lore raw

PATCH v14 12/12 net: airoha: add phylink support

In reply to Christian Marangi

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.

---
 drivers/net/ethernet/airoha/Kconfig       |   2 +
 drivers/net/ethernet/airoha/airoha_eth.c  | 199 +++++++++++++++++++++-
 drivers/net/ethernet/airoha/airoha_eth.h  |   5 +
 drivers/net/ethernet/airoha/airoha_regs.h |  12 ++
 4 files changed, 215 insertions(+), 3 deletions(-)
drivers/net/ethernet/airoha/Kconfig +2 -0
index 1f6640a15fc9..5c54a07d2a76 100644
@@ -20,6 +20,8 @@ config NET_AIROHA
 	depends on NET_DSA || !NET_DSA
 	select NET_AIROHA_NPU
 	select PAGE_POOL
+	select PCS_AIROHA
+	select PHYLINK
 	help
 	  This driver supports the gigabit ethernet MACs in the
 	  Airoha SoC family.
drivers/net/ethernet/airoha/airoha_eth.c +196 -3

274 lines not on this page · raw message

drivers/net/ethernet/airoha/airoha_eth.h +5 -0
index fa9a8edce22f..83daec003257 100644
@@ -595,6 +595,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 {
@@ -604,6 +607,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];
 };
drivers/net/ethernet/airoha/airoha_regs.h +12 -0
index 442b48c9b991..4ea89057b560 100644
@@ -357,6 +357,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)
 
Signature · 1 line
2.53.0
#14 lore raw

PATCH v14 10/12 dt-bindings: net: pcs: Document support for Airoha Ethernet PCS

In reply to Christian Marangi

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.

---
 .../bindings/net/pcs/airoha,pcs.yaml          | 261 ++++++++++++++++++
 1 file changed, 261 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml
Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml new file +261 -0
new file mode 100644
index 000000000000..9c1d116c1b01
@@ -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 <[email protected]>
+
+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>;
+    };
Signature · 1 line
2.53.0
#8 lore raw

Re: [PATCH v14 05/12] net: phylink: support PCS provider release

In reply to Christian Marangi
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Medium] Stale linkmode capabilities when a PCS provider is dynamically deleted.
- [Medium] Data race on the pcs->phylink pointer could lead to a NULL pointer dereference.

Pre-existing issues:
- [High] Unchecked error pointer dereference from mac_select_pcs in phylink_inband_caps. --

--- Patch [5]: [PATCH v14 05/12] net: phylink: support PCS provider release --- commit 33b352668c4f60d5ab772e19eb7823565b80a8ab
Author: Christian Marangi <[email protected]>

net: phylink: support PCS provider release

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.

[ ... ]

Quoted 4 lines
drivers/net/phy/phylink.c +0 -0
index 82eae20daed00..967cc919a3656 100644

[ ... ]

Quoted 11 lines
drivers/net/phy/phylink.c +3 -0
@@ -998,6 +1010,9 @@ static unsigned int phylink_inband_caps(struct phylink *pl,
 {
 	struct phylink_pcs *pcs;
 	bool pcs_found = false;
+	int ret = 0;
+
+	mutex_lock(&pl->state_mutex);
 
 	if (pl->mac_ops->mac_select_pcs) {
 		pcs = pl->mac_ops->mac_select_pcs(pl->config,

drivers/net/phy/phylink.c static unsigned int phylink_inband_caps(struct phylink *pl, · line 1033

Quoted 7 lines
drivers/net/phy/phylink.c +3 -1
@@ -1013,9 +1028,14 @@ static unsigned int phylink_inband_caps(struct phylink *pl,
 	}
 
 	if (!pcs_found)
-		return 0;
+		goto exit;
+
+	ret = phylink_pcs_inband_caps(pcs, interface);

[Severity: High]
This is a pre-existing issue, but can mac_select_pcs() return an error pointer here?

If so, the !!pcs check earlier in the function evaluates to true for error pointers. Is it possible that phylink_pcs_inband_caps() is then passed an error pointer, which it unconditionally dereferences?

Quoted 7 lines
drivers/net/phy/phylink.c +4 -1
+
+exit:
+	mutex_unlock(&pl->state_mutex);
 
-	return phylink_pcs_inband_caps(pcs, interface);
+	return ret;
 }

[ ... ]

Quoted 7 lines
drivers/net/phy/phylink.c +2 -0
@@ -1937,11 +1962,89 @@ static int phylink_fill_available_pcs(struct phylink *pl,
 	}
 
 out:
+	mutex_unlock(&pl->state_mutex);
+
 	kfree(pcss);

drivers/net/phy/phylink.c static int phylink_fill_available_pcs(struct phylink *pl, · line 1977

Quoted 10 lines
drivers/net/phy/phylink.c +6 -0
 
 	return ret;
 }
 
+static void phylink_del_pcs(struct phylink *pl, struct phylink_pcs *pcs)
+{
+	lockdep_assert_held(&pl->state_mutex);
+
+	list_del(&pcs->list);
+	pcs->phylink = NULL;

[Severity: Medium]
Is it possible for a lockless reader like phylink_pcs_change() to access pcs->phylink concurrently when a provider is removed?

If phylink_pcs_change() reads pcs->phylink without READ_ONCE(), and we do a plain store here without WRITE_ONCE(), could compiler optimizations lead to a NULL pointer dereference?

Quoted 5 lines
drivers/net/phy/phylink.c +5 -0
+
+	/*
+	 * 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

[ ... ]

Quoted 4 lines
drivers/net/phy/phylink.c +4 -0
+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);

[ ... ]

drivers/net/phy/phylink.c static int phylink_fill_available_pcs(struct phylink *pl, · line 2037

Quoted 7 lines
drivers/net/phy/phylink.c +7 -0
+	/* 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);

[Severity: Medium]
When a PCS provider is dynamically deleted and we update pl->supported_interfaces here, do we also need to recalculate the global pl->supported and pl->link_config.advertising linkmode masks?

Without calling phylink_validate() to update these masks, is it possible they retain the stale capabilities of the removed PCS, causing ethtool to report incorrect capabilities?

Quoted 9 lines
drivers/net/phy/phylink.c +9 -0
+
+	mutex_unlock(&pl->state_mutex);
+
+	rtnl_unlock();
+
+	phylink_run_resolve(pl);
+
+	return NOTIFY_OK;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#3 lore raw

Re: [PATCH v14 02/12] net: phylink: introduce internal phylink PCS handling

In reply to Christian Marangi
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] phylink_create() unconditionally expands the MAC's supported interfaces with all PCS-supported…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] phylink_create() unconditionally expands the MAC's supported interfaces with all PCS-supported interfaces, enabling unsupported MAC hardware modes.
- [Medium] phylink_validate_mac_and_pcs() fails to reject interfaces that require a dedicated PCS when no matching PCS is found. --

--- Patch [2]: [PATCH v14 02/12] net: phylink: introduce internal phylink PCS handling --- commit 6086d011ffb72e143c6102bee959c780b432bd7a
Author: Christian Marangi <[email protected]>

net: phylink: introduce internal phylink PCS handling

This commit introduces internal handling of PCS for phylink by allowing MACs to provide a list of available PCS via phylink_config. It parses this array and links the PCS list to the phylink instance. phylink validation and configuration functions are updated to use this PCS list instead of relying exclusively on .mac_select_pcs.

Quoted 4 lines
drivers/net/phy/phylink.c +0 -0
index e1e9f07f51bc6..6204e3bba16d7 100644

[ ... ]

Quoted 13 lines
drivers/net/phy/phylink.c +9 -0
@@ -530,9 +550,24 @@ 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);
+
+		pcs_found = !!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)) {

drivers/net/phy/phylink.c static int phylink_validate_mac_and_pcs(struct phylink *pl, · line 570

Quoted 10 lines
drivers/net/phy/phylink.c +7 -1
+		list_for_each_entry(pcs, &pl->pcs_list, list) {
+			if (!phylink_validate_pcs_interface(pcs, state->interface)) {
+				pcs_found = true;
+				break;
+			}
+		}
 	}
 
-	if (pcs) {
+	if (pcs_found) {

[Severity: Medium]
Should there be an explicit error return here if a dedicated PCS is required but none is found?

If pcs_found remains false after the loop in phylink_validate_mac_and_pcs(), the code skips the validation block without returning -EINVAL.

This allows the unsupported mode to pass MAC validation, which later fails during phylink_major_config().

[ ... ]

Quoted 12 lines
drivers/net/phy/phylink.c +8 -0
@@ -1908,16 +2028,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)
+		pcs->phylink = pl;

drivers/net/phy/phylink.c struct phylink *phylink_create(struct phylink_config *config, · line 2048

Quoted 10 lines
drivers/net/phy/phylink.c +7 -0
+
 	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: High]
Does this bitwise OR operation inadvertently expand the system's supported interfaces beyond the MAC's physical capabilities?

By injecting all PCS-supported interfaces into pl->supported_interfaces, generic PCS modules might expose high-speed modes that the attached MAC does not actually support. Could this lead to the MAC driver receiving configuration requests for unhandled interface types?

A similar capability expansion also appears to happen dynamically in pcs_provider_notify() when a PCS provider is added:

    /* 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);

Is this intended?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

Re: [PATCH v14 03/12] net: pcs: implement Firmware node support for PCS driver

In reply to Christian Marangi
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Lack of lifetime management between PCS consumer and provider allows Use-After-Free…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Lack of lifetime management between PCS consumer and provider allows Use-After-Free vulnerabilities.
- [High] Missing PCS providers are silently ignored instead of triggering probe deferral (-EPROBE_DEFER), breaking MAC linking and array indexing.
- [Medium] fwnode_pcs_get_from_pcsspec() drops error codes from the provider's xlate function and incorrectly continues searching the list. --

--- Patch [3]: [PATCH v14 03/12] net: pcs: implement Firmware node support for PCS driver --- commit 7bea9f15dae43881372af44cc139395687f3fc53

Author: Christian Marangi <[email protected]>
Date:   Thu Aug 13 08:35:08 2026 +0000

net: pcs: implement Firmware node support for PCS driver

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.

Quoted 4 lines
drivers/net/pcs/pcs.c new file +0 -0
new file mode 100644

[ ... ]

Quoted 8 lines
drivers/net/pcs/pcs.c new file +8 -0
+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;
+

drivers/net/pcs/pcs.c line 50

Quoted 10 lines
drivers/net/pcs/pcs.c new file +10 -0
+	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;

[Severity: High]
Should struct fwnode_pcs_provider track the module owner or device to allow reference counting? Without it, there doesn't seem to be a way to prevent the provider module from being unloaded while consumers hold a pointer.

Quoted 2 lines
drivers/net/pcs/pcs.c new file +2 -0
+
+	mutex_lock(&fwnode_pcs_mutex);

[ ... ]

Quoted 15 lines
drivers/net/pcs/pcs.c new file +15 -0
+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;

drivers/net/pcs/pcs.c line 157

Quoted 10 lines
drivers/net/pcs/pcs.c new file +10 -0
+
+	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;
+	}

[Severity: Medium]
The loop breaks only if !IS_ERR(pcs). If the fwnode matches but the provider's fwnode_xlate function returns a legitimate error (like -EINVAL for bad arguments), won't this loop just continue to the next provider instead of aborting and propagating the error?

After checking all other non-matching providers, it looks like it will unconditionally overwrite the actual error code with -ENODEV below.

drivers/net/pcs/pcs.c line 160

Quoted 3 lines
drivers/net/pcs/pcs.c new file +3 -0
+	mutex_unlock(&fwnode_pcs_mutex);
+
+	return !IS_ERR_OR_NULL(pcs) ? pcs : ERR_PTR(-ENODEV);

[Severity: High]
If a provider is not yet registered, this returns -ENODEV. Should this return -EPROBE_DEFER instead, so the consumer knows to retry when the PCS driver probes later?

Quoted 4 lines
drivers/net/pcs/pcs.c new file +4 -0
+}
+
+static struct phylink_pcs *__fwnode_pcs_get(const struct fwnode_handle *fwnode,
+					    unsigned int index, const char *con_id)

drivers/net/pcs/pcs.c line 174

Quoted 10 lines
drivers/net/pcs/pcs.c new file +10 -0
+{
+	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);

[Severity: High]
Does this return a raw pointer to the consumer without pinning the provider module in memory (e.g., via try_module_get)?

If the provider driver is unbound or unloaded via rmmod, could this leave the MAC driver with a dangling pointer and lead to a use-after-free during network operations?

Quoted 4 lines
drivers/net/pcs/pcs.c new file +4 -0
+	fwnode_handle_put(pcsspec.fwnode);
+
+	return pcs;
+}

[ ... ]

Quoted 17 lines
drivers/net/pcs/pcs.c new file +17 -0
+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)) {

drivers/net/pcs/pcs.c line 234

Quoted 10 lines
drivers/net/pcs/pcs.c new file +10 -0
+			/* 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;

[Severity: High]
By explicitly catching and ignoring -ENODEV, doesn't this break standard probe deferral, causing the MAC driver to initialize without its required PCS?

Also, since the loop variable i increments but found does not when a device is skipped, wouldn't subsequent valid PCS devices be shifted into earlier array indices in available_pcs, corrupting the expected hardware mapping?

Quoted 10 lines
drivers/net/pcs/pcs.c new file +10 -0
+
+			return PTR_ERR(pcs);
+		}
+
+		available_pcs[found] = pcs;
+		found++;
+	}
+
+	return found;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#16 lore raw

Re: [PATCH v14 11/12] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC

In reply to Christian Marangi
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [High] Unprotected re-initialization of shared resources (PLLs and global resets) during per-port bringup…

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Unprotected re-initialization of shared resources (PLLs and global resets) during per-port bringup disrupts active ports.
- [Medium] State retention across dynamic interface switching due to asymmetric register configuration.
- [Medium] Read-modify-write on write-1-to-clear (W1C) interrupt status registers inadvertently clears unintended pending interrupts.
- [Medium] Missing delay between asserting and deasserting reset controls.
- [Medium] Tight hardware polling loop for RX signal detection lacks a delay, risking false negatives.
- [Low] Unresolved FIXME comments and typographical errors indicate incomplete validation.
--

--- Patch [11]: [PATCH v14 11/12] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC --- commit 3d0ad7799a7613a55a29a2070766d339f6c58307
Author: Christian Marangi <[email protected]>

net: pcs: airoha: add PCS driver for Airoha AN7581 SoC

This commit adds a PCS driver for the Airoha AN7581 SoC for Ethernet, PON, PCIe, and USB SERDES. It registers the needed registers and acts as a PCS provider for phylink usage.

Quoted 6 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +0 -0
new file mode 100644
index 0000000000000..d9ec0e97b746a

drivers/net/pcs/airoha/pcs-airoha-common.c static int airoha_pcs_setup_scu(struct airoha_pcs_priv *priv, · line 140

Quoted 10 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +0 -0
@@ -131,10 +131,10 @@ static int airoha_pcs_setup_scu(struct airoha_pcs_priv *priv,
 		break;
 	}
 
 	ret = reset_control_bulk_assert(ARRAY_SIZE(priv->rsts),
 					priv->rsts);
 	if (ret)
 		return ret;
 
 	ret = reset_control_bulk_deassert(ARRAY_SIZE(priv->rsts),
 					  priv->rsts);

[Severity: High]
Since this function is called per-port during airoha_pcs_pre_config(), will asserting these global bulk resets disrupt an already active port (like the other port on the 2-port PCIe SerDes)?

[Severity: Medium]
Does this sequence need a delay between asserting and deasserting the reset controls?

Hardware blocks often require a minimum reset hold time to cleanly reset their state machines.

[ ... ]

drivers/net/pcs/airoha/pcs-airoha-common.c static void airoha_pcs_interrupt_init_usxgmii(struct airoha_pcs_priv *priv, · line 273

Quoted 3 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +0 -0
@@ -272,4 +272,4 @@ static void airoha_pcs_interrupt_init_usxgmii(struct airoha_pcs_priv *priv,
 	/* Interrupt saddly seems to be not weel supported for Link Down.
 	 * PCS Poll is a must to correctly read and react on Cable Deatch

[Severity: Low]
There are a few typos in this comment ("saddly", "weel", "Deatch"). Could they be fixed for clarity?

[ ... ]

drivers/net/pcs/airoha/pcs-airoha-common.c static void airoha_pcs_interrupt_init_usxgmii(struct airoha_pcs_priv *priv, · line 286

Quoted 10 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +0 -0
@@ -278,9 +278,9 @@ static void airoha_pcs_interrupt_init_usxgmii(struct airoha_pcs_priv *priv,
 	regmap_clear_bits(maps->usxgmii_pcs, AIROHA_PCS_USXGMII_PCS_CTRL_4,
 			  AIROHA_PCS_USXGMII_LINK_DOWN_ST_INT_EN);
 
 	/* Clear any pending interrupt */
 	regmap_set_bits(maps->usxgmii_pcs, AIROHA_PCS_USXGMII_PCS_INT_STA_2,
 			AIROHA_PCS_USXGMII_RPCS_FSM_DEC_ERR_INT |
 			AIROHA_PCS_USXGMII_R_TYPE_E_INT |
 			AIROHA_PCS_USXGMII_R_TYPE_T_INT |
 			AIROHA_PCS_USXGMII_R_TYPE_D_INT);

[Severity: Medium]
Are these interrupt status registers write-1-to-clear (W1C)?

If so, using regmap_set_bits() performs a read-modify-write. Any currently pending interrupts read as 1s will be written back as 1s, which could unintentionally clear all pending interrupts rather than just the ones specified in the mask.

[ ... ]

drivers/net/pcs/airoha/pcs-airoha-common.c

Quoted 9 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +0 -0
@@ -568,6 +568,6 @@ static int airoha_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
 	if (interface == PHY_INTERFACE_MODE_1000BASEX &&
 	    neg_mode != PHYLINK_PCS_NEG_INBAND_ENABLED) {
 		regmap_set_bits(maps->hsgmii_pcs, AIROHA_PCS_HSGMII_PCS_CTROL_1,
 				AIROHA_PCS_SGMII_SEND_AN_ERR_EN);
 
 		regmap_set_bits(maps->hsgmii_an, AIROHA_PCS_HSGMII_AN_SGMII_REG_AN_FORCE_CL37,
drivers/net/pcs/airoha/pcs-airoha-common.c new file +0 -0
 				AIROHA_PCS_HSGMII_AN_FORCE_AN_DONE);
 	}

[Severity: Medium]
Will these bits remain set if the port is later dynamically reconfigured to a different interface mode (e.g. switching to SGMII or 1000BASEX with inband negotiation enabled)?

It appears there is no logic to clear these bits if they were previously set, which could break the link upon changing modes.

Quoted 11 lines
drivers/net/pcs/airoha/pcs-an7581.c new file +0 -0
new file mode 100644
index 0000000000000..bba4a5164a4e2
@@ -255,5 +255,5 @@ static void an7581_pcs_jcpll_bringup(struct airoha_pcs_priv *priv,
 	/* This comment only apply to Serdes PCIe that expose
 	 * 2 PCS.
 	 *
 	 * The Serdes PCIe expose 2 PCS but always require
 	 * the PMA for the first PCS to be configured

drivers/net/pcs/airoha/pcs-an7581.c

Quoted 3 lines
drivers/net/pcs/airoha/pcs-an7581.c new file +0 -0
 	 * for correct functionality for JCPLL.
 	 */
 	pcs_pma = priv->pcs_pma[0];

[Severity: High]
Since pcs_pma[0] is hardcoded here and the JCPLL is shared, will bringing up a secondary port dynamically disable and restart the shared JCPLL, causing a disruption on the active first port?

[ ... ]

Quoted 4 lines
drivers/net/pcs/airoha/pcs-an7581.c new file +0 -0
@@ -643,2 +643,2 @@ static void an7581_pcs_rx_bringup(struct airoha_pcs_priv *priv,
 
 	/* FIXME: Warn and Ask Airoha about typo in air_eth_xsgmii.c line 1391 */

/* AIROHA_PCS_ANA_REV_1_FE_BUF1_BIAS_CTRL is set 0x0 in SDK but seems a typo */

[Severity: Low]
Is this FIXME intended to be resolved before merging?

It might be best to verify this hardware assumption with the vendor to ensure it won't hide any bugs.

[ ... ]

drivers/net/pcs/airoha/pcs-an7581.c

Quoted 11 lines
drivers/net/pcs/airoha/pcs-an7581.c new file +0 -0
@@ -2072,6 +2072,6 @@ static bool an7581_pcs_have_rx_signal(struct airoha_pcs_priv *priv, int index)
 	regmap_write(pcs_pma, AIROHA_PCS_PMA_DIG_RESERVE_0,
 		     AIROHA_PCS_TRIGGER_RX_SIDGET_SCAN);
 
 	/* Scan 6 times for RX sigdet module to detect RX signal */
 	for (i = 0; i < AIROHA_PCS_MAX_RX_SIGDET_TRY; i++) {
 		regmap_read(pcs_pma, AIROHA_PCS_PMA_DIG_RO_RESERVE_2,
drivers/net/pcs/airoha/pcs-an7581.c new file +0 -0
 			    &val);
 		if (val & AIROHA_PCS_RX_SIGDET)
 			count++;
 	}

[Severity: Medium]
Does this tight polling loop need a delay (such as usleep_range())?

Currently, the CPU will execute these reads across the MMIO bus very rapidly. Since analog circuitry typically requires settling time to assert signal detection, might this lead to false negatives?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
#10 lore raw

Re: [PATCH v14 06/12] net: phylink: support late PCS provider attach

In reply to Christian Marangi
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Missing `rtnl_lock()` during late PCS provider attachment causes a data race on…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Missing rtnl_lock() during late PCS provider attachment causes a data race on pl->supported_interfaces.
- [High] Late-attached PCS capabilities are not propagated to ethtool supported linkmodes (pl->supported).
- [High] If the PCS provider's fwnode_xlate callback returns NULL, it leads to a kernel panic in phylink_add_pcs(). --

--- Patch [6]: [PATCH v14 06/12] net: phylink: support late PCS provider attach --- commit b6137c0cfab8a7a646c6cbf7cf50ad62dca0f51b
Author: Christian Marangi <[email protected]>

net: phylink: support late PCS provider attach

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.

Quoted 4 lines
drivers/net/pcs/pcs.c +0 -0
index 25b3248e8b93b..fef560eddf2a9 100644

[ ... ]

Quoted 9 lines
drivers/net/pcs/pcs.c +5 -0
@@ -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;

drivers/net/pcs/pcs.c struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode, unsigned · line 222

Quoted 10 lines
drivers/net/pcs/pcs.c +10 -0
+	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;

[Severity: High]
If the provider's fwnode_xlate callback returns NULL, this function will return NULL.

Unlike fwnode_pcs_get_from_pcsspec(), which sanitizes NULL to ERR_PTR(-ENODEV), this function returns NULL directly.

Could this return value lead to a NULL pointer dereference in pcs_provider_notify() where IS_ERR() is checked instead of IS_ERR_OR_NULL()?

Quoted 3 lines
drivers/net/pcs/pcs.c +3 -0
+}
+EXPORT_SYMBOL_GPL(fwnode_pcs_get_from_provider);
+

[ ... ]

Quoted 4 lines
drivers/net/phy/phylink.c +0 -0
index 967cc919a3656..ba3efdb0a1948 100644

[ ... ]

Quoted 23 lines
drivers/net/phy/phylink.c +8 -7
@@ -2004,27 +2025,57 @@ static int pcs_provider_notify(struct notifier_block *self,
 	struct fwnode_pcs_provider *pp = data;
 	struct phylink_pcs *pcs, *tmp;
 	bool resolve = false;
+	int count, i;
 
-	rtnl_lock();
+	/*
+	 * On PCS provider deletion hold rtnl lock as one of
+	 * PCS can be currently in use by the phylink instance
+	 * and ethtool OPs can reference it.
+	 */
+	if (val == FWNODE_PCS_PROVIDER_DEL)
+		rtnl_lock();
 
 	mutex_lock(&pl->state_mutex);
 
-	/*
-	 * 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))

drivers/net/phy/phylink.c static int pcs_provider_notify(struct notifier_block *self, · line 2048

Quoted 10 lines
drivers/net/phy/phylink.c +9 -1
-			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(pcs))
+				continue;
+
+			phylink_add_pcs(pl, pcs);

[Severity: High]
If pcs is NULL here (because fwnode_pcs_get_from_provider() returned NULL), the IS_ERR() check will pass.

Would this cause a kernel panic when phylink_add_pcs() dereferences pcs to add it to the list via list_add_tail(&pcs->list, &pl->pcs_list)?

Quoted 10 lines
drivers/net/phy/phylink.c +7 -2
+			resolve = true;
+		}
+
+		/* Force an interface reconfig if major config fail */
+		if (resolve && pl->major_config_failed)
+			pl->force_major_config = true;
 
-		phylink_del_pcs(pl, pcs);
-		resolve = true;
+		break;

[ ... ]

drivers/net/phy/phylink.c static int pcs_provider_notify(struct notifier_block *self, · line 2091

Quoted 4 lines
drivers/net/phy/phylink.c +0 -0
@@ -2038,7 +2089,8 @@ static int pcs_provider_notify(struct notifier_block *self,
 
 	mutex_unlock(&pl->state_mutex);
 

[Severity: High]
Is it safe to update pl->supported_interfaces without holding rtnl_lock() during FWNODE_PCS_PROVIDER_ADD?

The FWNODE_PCS_PROVIDER_ADD path intentionally omits taking rtnl_lock() and modifies pl->supported_interfaces non-atomically via phy_interface_or() and phy_interface_copy() just above this.

Concurrently, phylink_sfp_config_optical() reads pl->supported_interfaces under rtnl_lock() but outside pl->state_mutex. Could this lead to a torn read of the bitmap, causing valid link modes to be spuriously rejected and SFP links failing to come up?

[Severity: High]
Does pl->supported (the ethtool linkmode mask) need to be recalculated when new PCS capabilities are added?

This code refreshes pl->supported_interfaces, but it doesn't appear to recalculate the ethtool capabilities mask pl->supported, which is normally done in phylink_create() via linkmode_fill(), linkmode_copy(), and phylink_validate().

If pl->supported is not updated here, will it remain permanently stale and prevent the use of new speeds or link modes introduced by the late-attached PCS?

Quoted 6 lines
drivers/net/phy/phylink.c +2 -1
-	rtnl_unlock();
+	if (val == FWNODE_PCS_PROVIDER_DEL)
+		rtnl_unlock();
 
 	phylink_run_resolve(pl);
 
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#18 lore raw

Re: [PATCH v14 12/12] net: airoha: add phylink support

In reply to Christian Marangi
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Missing `.nway_reset` callback in `ethtool_ops`, preventing users from restarting autonegotiation. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Missing .nway_reset callback in ethtool_ops, preventing users from restarting autonegotiation. --

--- Patch [12]: [PATCH v14 12/12] net: airoha: add phylink support --- commit 04ce17914816acfbcbe80f577754f5b7cd6c55ff
Author: Christian Marangi <[email protected]>

net: airoha: add phylink support

This commit adds phylink support for each GDM port, configuring internal interface modes for GDM1 and necessary PCS settings for external PHYs or SFP cages on GDM2/3/4. It also updates the ethtool get and set link ksettings functions to use phylink.

Quoted 4 lines
drivers/net/ethernet/airoha/airoha_eth.c +0 -0
index 64619e9a704dd..c3827bf9791b6 100644

[ ... ]

drivers/net/ethernet/airoha/airoha_eth.c static const struct ethtool_ops airoha_ethtool_ops = { · line 3398

Quoted 9 lines
drivers/net/ethernet/airoha/airoha_eth.c +2 -1
@@ -3353,7 +3392,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,
 };

[Severity: Low]
Since this patch fully supports phylink and implements set_link_ksettings, should airoha_ethtool_ops in drivers/net/ethernet/airoha/airoha_eth.c also include the .nway_reset callback?

Without this callback, userspace attempts to manually restart autonegotiation via "ethtool -r <interface>" will receive -EOPNOTSUPP. It is standard in phylink conversions to also provide an nway_reset wrapper that calls phylink_ethtool_nway_reset(dev->phylink) to allow administrators to trigger autonegotiation restarts.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
maintainer
#19 lore raw
In reply to Christian Marangi
Quoted 8 lines · On Thu, 13 Aug 2026 10:35:05 +0200 Christian Marangi wrote:

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.

Coccicheck says:

drivers/net/phy/phylink.c:1039:31-34:
ERROR: invalid reference to the index variable of the iterator on line 1028

drivers/net/phy/phylink.c:1364:26-29:
ERROR: invalid reference to the index variable of the iterator on line 1346

drivers/net/phy/phylink.c:582:7-10:
ERROR: invalid reference to the index variable of the iterator on line 569

I vaguely recall that you're supposed to make a copy of the pointer, not just add a "found" boolean. Dunno if it ever happened but Linus was trying to make the list iterators override the pointer on exit.

#20 lore raw
Quoted 18 lines · Jakub Kicinski
Quoted 8 lines · On Thu, 13 Aug 2026 10:35:05 +0200 Christian Marangi wrote:

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.

Coccicheck says:

drivers/net/phy/phylink.c:1039:31-34:
ERROR: invalid reference to the index variable of the iterator on line 1028

drivers/net/phy/phylink.c:1364:26-29:
ERROR: invalid reference to the index variable of the iterator on line 1346

Quoted 6 lines

drivers/net/phy/phylink.c:582:7-10:
ERROR: invalid reference to the index variable of the iterator on line 569

I vaguely recall that you're supposed to make a copy of the pointer, not just add a "found" boolean. Dunno if it ever happened but Linus was trying to make the list iterators override the pointer on exit.

Oh! I wasn't aware of this intention... I have seen lots of pattern where the last value of the iterator was directly used (if detected valid)

It's and easy fix... I can send a new revision right away if you want, I'm already on it fixing this in the meantime.

Signature · 1 line
	Ansuel
#21 lore raw

Il giorno lun 17 ago 2026 alle ore 23:02 Christian Marangi <[email protected]> ha scritto:

Quoted 27 lines · Jakub Kicinski
Quoted 18 lines · On Thu, 13 Aug 2026 10:35:05 +0200 Christian Marangi wrote:
Quoted 8 lines

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.

Coccicheck says:

drivers/net/phy/phylink.c:1039:31-34:
ERROR: invalid reference to the index variable of the iterator on line 1028

drivers/net/phy/phylink.c:1364:26-29:
ERROR: invalid reference to the index variable of the iterator on line 1346

Quoted 6 lines

drivers/net/phy/phylink.c:582:7-10:
ERROR: invalid reference to the index variable of the iterator on line 569

I vaguely recall that you're supposed to make a copy of the pointer, not just add a "found" boolean. Dunno if it ever happened but Linus was trying to make the list iterators override the pointer on exit.

Quoted 6 lines

Oh! I wasn't aware of this intention... I have seen lots of pattern where the last value of the iterator was directly used (if detected valid)

It's and easy fix... I can send a new revision right away if you want, I'm already on it fixing this in the meantime.

Sooo should I post a v15 with the fix? It would be great to have this for 7.3.