net: pcs: Introduce support for fwnode PCS
Subsystems (9)
v11 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_get.
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 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 | 229 ++ Documentation/networking/sfp-phylink.rst | 35 +- MAINTAINERS | 9 + drivers/net/ethernet/airoha/Kconfig | 2 + drivers/net/ethernet/airoha/airoha_eth.c | 190 +- 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 | 12 + 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 | 2093 +++++++++++++++++ drivers/net/pcs/pcs.c | 294 +++ drivers/net/phy/phylink.c | 347 ++- include/linux/pcs/pcs-provider.h | 65 + include/linux/pcs/pcs.h | 141 ++ include/linux/phylink.h | 28 + 21 files changed, 6298 insertions(+), 58 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
PATCH v11 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
@@ -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,
@@ -1878,6 +1883,9 @@ struct phylink *phylink_create(struct phylink_config *config, goto free_pl; } +phy_interface_copy (pl->supported_interfaces, + pl->config->supported_interfaces); + pl->mac_supports_eee_ops =phylink_mac_implements_lpi (mac_ops); pl->mac_supports_eee = pl->mac_supports_eee_ops && pl->config->lpi_capabilities &&
@@ -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
PATCH v11 2/12 net: phylink: introduce internal phylink PCS handling
In reply to Christian MarangiIntroduce 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 | 205 +++++++++++++++++++++++++++++++++----- include/linux/phylink.h | 16 +++ 2 files changed, 196 insertions(+), 25 deletions(-)
drivers/net/phy/phylink.c +180 -25
@@ -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. */
@@ -154,6 +157,8 @@ static const phy_interface_t phylink_sfp_interface_preference[] = {static DECLARE_PHY_INTERFACE_MASK (phylink_sfp_interfaces); +static void phylink_run_resolve (struct phylink *pl); +/** * phylink_set_port_modes() - set the port type modes in the ethtool mask * @mask: ethtool link mode mask
@@ -517,12 +522,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 +552,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 +581,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 +998,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 +1308,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 +1364,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 +1905,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,13 +1964,17 @@ 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; -/* Validate the supplied configuration */ -if (phy_interface_empty (config->supported_interfaces)) { +/* +* 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: empty supported_interfaces\n" ); +"phylink: error: either phylink_config .num_possible_pcs or .mac_select_pcs must be used\n" );return ERR_PTR (-EINVAL ); }
@@ -1871,6 +1985,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 ) {
@@ -1883,9 +1998,24 @@ struct phylink *phylink_create(struct phylink_config *config, goto free_pl; } +/* 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); + pl->mac_supports_eee_ops =phylink_mac_implements_lpi (mac_ops); pl->mac_supports_eee = pl->mac_supports_eee_ops && pl->config->lpi_capabilities &&
@@ -1917,7 +2047,7 @@ struct phylink *phylink_create(struct phylink_config *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 +2066,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 +2088,24 @@ 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); + +mutex_lock (&pl->state_mutex); + +/* 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); + } + +mutex_unlock (&pl->state_mutex); +kfree (pl); }EXPORT_SYMBOL_GPL (phylink_destroy);
@@ -2409,8 +2557,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
@@ -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
PATCH v11 3/12 net: pcs: implement Firmware node support for PCS driver
In reply to Christian MarangiImplement 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 .get 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_get() 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 | 240 +++++++++++++++++++++++++++++++ include/linux/pcs/pcs-provider.h | 65 +++++++++ include/linux/pcs/pcs.h | 75 ++++++++++ 5 files changed, 387 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
@@ -5,6 +5,12 @@ menu "PCS device drivers" +config FWNODE_PCS + bool "PCS Firmware Node" + depends on (ACPI || OF) + help + Firmware node PCS accessors + config PCS_XPCS tristate "Synopsys DesignWare Ethernet XPCS" select PHYLINK
drivers/net/pcs/Makefile +1 -0
@@ -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 +240 -0
240 lines not on this page · raw message
include/linux/pcs/pcs-provider.h new file +65 -0
65 lines not on this page · raw message
include/linux/pcs/pcs.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v11 4/12 net: phylink: save phylink instance fwnode on phylink_create
In reply to Christian MarangiThe 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 | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/phy/phylink.c +2 -0
@@ -44,6 +44,7 @@ struct phylink {const struct phylink_mac_ops *mac_ops;struct phylink_config *config;struct phylink_pcs *pcs; +const struct fwnode_handle *fwnode;struct device *dev; unsigned int old_link_state:1;
@@ -1988,6 +1989,7 @@ struct phylink *phylink_create(struct phylink_config *config,INIT_LIST_HEAD (&pl->pcs_list); pl->config = config; + pl->fwnode = fwnode;if (config->type ==PHYLINK_NETDEV ) { pl->netdev =to_net_dev (config->dev);netif_carrier_off (pl->netdev);
Signature · 1 line
2.53.0
PATCH v11 5/12 net: phylink: support PCS provider release
In reply to Christian MarangiAdd 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_phylink_pcs_get_from_fwnode() that will check if the PCS fwnode provided by the event is present in the pcs-handle property of the phylink instance.
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.
--- drivers/net/pcs/pcs.c | 50 ++++++++++++++++++++++++ drivers/net/phy/phylink.c | 82 ++++++++++++++++++++++++++++++++++++++- include/linux/pcs/pcs.h | 65 +++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+), 1 deletion(-)
drivers/net/pcs/pcs.c +50 -0
@@ -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_get (struct fwnode_reference_args *pcsspec,void *data)
@@ -67,6 +80,11 @@ void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp)mutex_lock (&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); +list_del (&pp->link);fwnode_dev_initialized (pp->fwnode, false);fwnode_handle_put (pp->fwnode);
@@ -178,6 +196,38 @@ struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode, unsigned }EXPORT_SYMBOL_GPL (fwnode_pcs_get); +struct phylink_pcs * +fwnode_phylink_pcs_get_from_fwnode (const struct fwnode_handle *fwnode, +struct fwnode_handle *pcs_fwnode) +{ +struct fwnode_reference_args pcsspec; +int index =0 ; +int ret; + +/* Loop until we find a matching PCS node or +* fwnode_parse_pcsspec() returns error +* if we don't have any other PCS reference to check. +*/ +while (true) { + ret =fwnode_parse_pcsspec (fwnode, index,NULL , &pcsspec); +if (ret) +return ERR_PTR (ret); + +/* Exit loop if we found the matching PCS node */ +if (pcsspec.fwnode == pcs_fwnode) { +fwnode_handle_put (pcsspec.fwnode); +break ; + } + +/* Check the next PCS reference */ +fwnode_handle_put (pcsspec.fwnode); + index++; + } + +return fwnode_pcs_get (fwnode, index); +} +EXPORT_SYMBOL_GPL (fwnode_phylink_pcs_get_from_fwnode); +unsigned int fwnode_phylink_pcs_count (struct fwnode_handle *fwnode) {struct fwnode_reference_args out_args;
drivers/net/phy/phylink.c +81 -1
139 lines not on this page · raw message
include/linux/pcs/pcs.h +65 -0
90 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v11 6/12 net: phylink: support late PCS provider attach
In reply to Christian MarangiAdd 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.
Then we link the PCS to the phylink instance and we refresh the supported interfaces of the phylink instance.
Finally we check if we are in a major_config_failed scenario and trigger an interface reconfiguration 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 | 4 ++++ drivers/net/phy/phylink.c | 41 +++++++++++++++++++++++++++++++++------ include/linux/pcs/pcs.h | 1 + 3 files changed, 40 insertions(+), 6 deletions(-)
drivers/net/pcs/pcs.c +4 -0
@@ -69,6 +69,10 @@ fwnode_pcs_add_provider(struct fwnode_handle *fwnode,fwnode_dev_initialized (fwnode, true); +blocking_notifier_call_chain (&fwnode_pcs_notify_list, +FWNODE_PCS_PROVIDER_ADD , + fwnode); +return pp; }EXPORT_SYMBOL_GPL (fwnode_pcs_add_provider);
drivers/net/phy/phylink.c +35 -6
65 lines not on this page · raw message
include/linux/pcs/pcs.h +1 -0
@@ -5,6 +5,7 @@#include <linux/phylink.h> enum fwnode_pcs_notify_event { +FWNODE_PCS_PROVIDER_ADD ,FWNODE_PCS_PROVIDER_DEL , };
Signature · 1 line
2.53.0
PATCH v11 7/12 net: Document PCS subsystem
In reply to Christian MarangiAdd 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 | 229 +++++++++++++++++++++++ Documentation/networking/sfp-phylink.rst | 35 ++-- 3 files changed, 241 insertions(+), 24 deletions(-) create mode 100644 Documentation/networking/pcs.rst
Documentation/networking/index.rst +1 -0
@@ -28,6 +28,7 @@ Contents: net_failover page_pool phy + pcs sfp-phylink alias bridge
Documentation/networking/pcs.rst new file +229 -0
229 lines not on this page · raw message
Documentation/networking/sfp-phylink.rst +11 -24
@@ -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
PATCH v11 8/12 MAINTAINERS: add myself as PCS subsystem maintainer
In reply to Christian MarangiList all the files of the Ethernet PCS subsystem and add myself as maintainer.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -9688,6 +9688,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
PATCH v11 9/12 net: phylink: add .pcs_link_down PCS OP
In reply to Christian MarangiPermit 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
@@ -982,6 +982,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)
@@ -1683,6 +1689,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
@@ -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
PATCH v11 10/12 dt-bindings: net: pcs: Document support for Airoha Ethernet PCS
In reply to Christian MarangiDocument 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
@@ -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
PATCH v11 12/12 net: airoha: add phylink support
In reply to Christian MarangiAdd 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 | 190 +++++++++++++++++++++- drivers/net/ethernet/airoha/airoha_eth.h | 5 + drivers/net/ethernet/airoha/airoha_regs.h | 12 ++ 4 files changed, 207 insertions(+), 2 deletions(-)
drivers/net/ethernet/airoha/Kconfig +2 -0
@@ -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 +188 -2
256 lines not on this page · raw message
drivers/net/ethernet/airoha/airoha_eth.h +5 -0
@@ -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
@@ -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
PATCH v11 11/12 net: pcs: airoha: add PCS driver for Airoha AN7581 SoC
In reply to Christian MarangiAdd 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 | 12 + 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 | 2093 ++++++++++++++++++++ 7 files changed, 4730 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
@@ -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
@@ -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 +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config PCS_AIROHA + tristate + select FWNODE_PCS + +config PCS_AIROHA_AN7581 + tristate "Airoha AN7581 PCS driver" + 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
@@ -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 +2093 -0
356 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.
Randy Dunlap
reviewerRe: [PATCH net-next v11 03/12] net: pcs: implement Firmware node support for PCS driver
In reply to Christian MarangiHi--
Quoted 7 lines · Christian Marangi
Implement the foundation of Firmware node support for PCS driver.
Co-developed-by Daniel Golle <[email protected]>Signed-off-by Daniel Golle <[email protected]>Signed-off-by Christian Marangi <[email protected]>
Quoted 11 lines
--- drivers/net/pcs/Kconfig | 6 + drivers/net/pcs/Makefile | 1 + drivers/net/pcs/pcs.c | 240 +++++++++++++++++++++++++++++++ include/linux/pcs/pcs-provider.h | 65 +++++++++ include/linux/pcs/pcs.h | 75 ++++++++++ 5 files changed, 387 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
Please address these warnings:
WARNING: ../include/linux/pcs/pcs-provider.h:39 function parameter 'pp' not described in 'fwnode_pcs_del_provider' WARNING: ../include/linux/pcs/pcs-provider.h:39 Excess function parameter 'fwnode' description in 'fwnode_pcs_del_provider' WARNING: ../include/linux/pcs/pcs-provider.h:62 expecting prototype for fwnode_pcs_add_provider(). Prototype was for devm_fwnode_pcs_add_provider() instead
Quoted 61 lines
include/linux/pcs/pcs-provider.h new file +55
-0@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef __LINUX_PCS_PROVIDER_H +#define __LINUX_PCS_PROVIDER_H + +struct fwnode_pcs_provider ; + +/** +* fwnode_pcs_simple_get - Simple xlate function to retrieve PCS +* @pcsspec: reference arguments +* @data: Context data (assumed assigned to the single PCS) +* +* Returns: the PCS pointed by data. +*/ +struct phylink_pcs *fwnode_pcs_simple_get (struct fwnode_reference_args *pcsspec, +void *data); + +/** +* fwnode_pcs_add_provider - Registers a new PCS provider +* @fwnode: Firmware node +* @get: xlate function to retrieve the PCS +* @data: Context data +* +* Register and add a new PCS provider to the global providers list +* for the firmware node. The relevant PCS from the PCS provider +* is retrieved from the passed xlate function. +* +* Returns: A pointer to the registered PCS provider on success, or +* an ERR_PTR() encoded error code on failure. +*/ +struct fwnode_pcs_provider * +fwnode_pcs_add_provider (struct fwnode_handle *fwnode, +struct phylink_pcs *(*get)(struct fwnode_reference_args *pcsspec, +void *data), +void *data); + +/** +* fwnode_pcs_del_provider - Removes a PCS provider +* @fwnode: Firmware node +*/ +void fwnode_pcs_del_provider (struct fwnode_pcs_provider *pp); + +/** +* fwnode_pcs_add_provider - Registers a new PCS provider +* @dev: Device of the PCS provider +* @fwnode: Firmware node +* @get: xlate function to retrieve the PCS +* @data: Context data +* +* Register and add a new PCS provider to the global providers list +* for the firmware node. The relevant PCS from the PCS provider +* is retrieved from the passed xlate function. While at that, it +* also associates the device with the PCS provider using devres. +* On driver detach, release function is invoked on the devres data, +* then, devres data is freed. +*
include/linux/pcs/pcs-provider.h line 65
Quoted 10 lines
include/linux/pcs/pcs-provider.h new file +10
-0+* Returns: A pointer to the registered PCS provider on success, or +* an ERR_PTR() encoded error code on failure. +*/ +struct fwnode_pcs_provider * +devm_fwnode_pcs_add_provider (struct device *dev,struct fwnode_handle *fwnode, +struct phylink_pcs *(*get)(struct fwnode_reference_args *pcsspec, +void *data), +void *data); + +#endif /* __LINUX_PCS_PROVIDER_H */
thanks.
Signature · 1 line
~Randy
Re: [PATCH net-next v11 03/12] net: pcs: implement Firmware node support for PCS driver
Quoted 23 lines · Randy Dunlap
Hi--
Quoted 7 lines · Christian Marangi
Implement the foundation of Firmware node support for PCS driver.
Co-developed-by Daniel Golle <[email protected]>Signed-off-by Daniel Golle <[email protected]>Signed-off-by Christian Marangi <[email protected]>Quoted 11 lines
--- drivers/net/pcs/Kconfig | 6 + drivers/net/pcs/Makefile | 1 + drivers/net/pcs/pcs.c | 240 +++++++++++++++++++++++++++++++ include/linux/pcs/pcs-provider.h | 65 +++++++++ include/linux/pcs/pcs.h | 75 ++++++++++ 5 files changed, 387 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
Quoted 6 lines
Please address these warnings:
WARNING: ../include/linux/pcs/pcs-provider.h:39 function parameter 'pp' not described in 'fwnode_pcs_del_provider' WARNING: ../include/linux/pcs/pcs-provider.h:39 Excess function parameter 'fwnode' description in 'fwnode_pcs_del_provider' WARNING: ../include/linux/pcs/pcs-provider.h:62 expecting prototype for fwnode_pcs_add_provider(). Prototype was for devm_fwnode_pcs_add_provider() instead
Yep, they slipped in the rework. I already fixed these, just waiting the usual 24h.
Quoted 77 lines
Quoted 61 lines
include/linux/pcs/pcs-provider.h new file +55
-0@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef __LINUX_PCS_PROVIDER_H +#define __LINUX_PCS_PROVIDER_H + +struct fwnode_pcs_provider ; + +/** +* fwnode_pcs_simple_get - Simple xlate function to retrieve PCS +* @pcsspec: reference arguments +* @data: Context data (assumed assigned to the single PCS) +* +* Returns: the PCS pointed by data. +*/ +struct phylink_pcs *fwnode_pcs_simple_get (struct fwnode_reference_args *pcsspec, +void *data); + +/** +* fwnode_pcs_add_provider - Registers a new PCS provider +* @fwnode: Firmware node +* @get: xlate function to retrieve the PCS +* @data: Context data +* +* Register and add a new PCS provider to the global providers list +* for the firmware node. The relevant PCS from the PCS provider +* is retrieved from the passed xlate function. +* +* Returns: A pointer to the registered PCS provider on success, or +* an ERR_PTR() encoded error code on failure. +*/ +struct fwnode_pcs_provider * +fwnode_pcs_add_provider (struct fwnode_handle *fwnode, +struct phylink_pcs *(*get)(struct fwnode_reference_args *pcsspec, +void *data), +void *data); + +/** +* fwnode_pcs_del_provider - Removes a PCS provider +* @fwnode: Firmware node +*/ +void fwnode_pcs_del_provider (struct fwnode_pcs_provider *pp); + +/** +* fwnode_pcs_add_provider - Registers a new PCS provider +* @dev: Device of the PCS provider +* @fwnode: Firmware node +* @get: xlate function to retrieve the PCS +* @data: Context data +* +* Register and add a new PCS provider to the global providers list +* for the firmware node. The relevant PCS from the PCS provider +* is retrieved from the passed xlate function. While at that, it +* also associates the device with the PCS provider using devres. +* On driver detach, release function is invoked on the devres data, +* then, devres data is freed. +* include/linux/pcs/pcs-provider.h line 65
Quoted 10 lines
include/linux/pcs/pcs-provider.h new file +10
-0+* Returns: A pointer to the registered PCS provider on success, or +* an ERR_PTR() encoded error code on failure. +*/ +struct fwnode_pcs_provider * +devm_fwnode_pcs_add_provider (struct device *dev,struct fwnode_handle *fwnode, +struct phylink_pcs *(*get)(struct fwnode_reference_args *pcsspec, +void *data), +void *data); + +#endif /* __LINUX_PCS_PROVIDER_H */ thanks.
Signature · 1 line
~Randy
Signature · 1 line
Ansuel
[email protected]
AI reviewRe: [PATCH net-next v11 02/12] net: phylink: introduce internal phylink PCS handling
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] phylink_validate_mac_and_pcs() fails to return an error when a required PCS is missing, leading to…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] phylink_validate_mac_and_pcs() fails to return an error when a required PCS is missing, leading to subsequent fatal errors.
- [Medium] Accidental deletion of MAC supported_interfaces validation in phylink_create().
--
--- Patch [2]: [PATCH net-next v11 02/12] net: phylink: introduce internal phylink PCS handling --- commit 73e85e119d9228a55571bdc2d1bafc5c5ee4b1fa
Author: Christian Marangi <[email protected]>
net: phylink: introduce internal phylink PCS handling
This commit introduces internal handling of PCS for phylink using a linked list of available PCS instead of relying solely on the .mac_select_pcs callback. It updates major configuration and validation paths to search the available PCS list when the MAC requires a dedicated PCS.
Quoted 4 lines
drivers/net/phy/phylink.c +0
-0
[ ... ]
Quoted 13 lines
drivers/net/phy/phylink.c +9
-0@@ -530,9 +552,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 572
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: High]
If a required PCS is not found in the list, pcs_found remains false, but doesn't phylink_validate_mac_and_pcs() then fall through and continue to validate MAC capabilities instead of immediately returning an error like -EINVAL?
Later in phylink_major_config(), trying to apply this configuration could fail fatally and leave the link in a broken state.
[ ... ]
Quoted 10 lines
drivers/net/phy/phylink.c +1
-2@@ -1854,13 +1964,17 @@ 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; -/* Validate the supplied configuration */ -if (phy_interface_empty (config->supported_interfaces)) {
drivers/net/phy/phylink.c struct phylink *phylink_create(struct phylink_config *config, · line 1979
Quoted 10 lines
drivers/net/phy/phylink.c +6
-1+/* +* 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: empty supported_interfaces\n" ); +"phylink: error: either phylink_config .num_possible_pcs or .mac_select_pcs must be used\n" );return ERR_PTR (-EINVAL ); }
[Severity: Medium]
Was the validation check for an empty supported_interfaces mask intentionally removed here?
Without it, it looks like misconfigured MAC drivers might initialize successfully but fail silently later.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH net-next v11 03/12] net: pcs: implement Firmware node support for PCS driver
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Provider module unload causes use-after-free due to missing module and device lifecycle references…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Provider module unload causes use-after-free due to missing module and device lifecycle references in fwnode_pcs_get().
- [High] Returning -ENODEV and compacting the available_pcs array breaks probe deferral and destroys hardware port mappings.
- [Low] devm_fwnode_pcs_add_provider() unnecessarily allocates devres memory for NULL fwnodes.
- [Low] Redundant condition in fwnode_parse_pcsspec() leads to dead code.
--
--- Patch [3]: [PATCH net-next v11 03/12] net: pcs: implement Firmware node support for PCS driver --- commit 9eb9adef70448b865a27066bb2a6ee2e49d74279
Author: Christian Marangi <[email protected]>
net: pcs: implement Firmware node support for PCS driver
Implement the foundation of Firmware node support for PCS driver. This adds a Provider API where a PCS driver can expose multiple PCS with an xlate function, and consumers can request them.
Quoted 6 lines
drivers/net/pcs/pcs.c new file +0
-0@@ -0,0 +1,240 @@
[ ... ]
Quoted 5 lines
drivers/net/pcs/pcs.c new file +5
-0+struct fwnode_pcs_provider * +devm_fwnode_pcs_add_provider (struct device *dev,struct fwnode_handle *fwnode, +struct phylink_pcs *(*get)(struct fwnode_reference_args *pcsspec, +void *data), +void *data)
drivers/net/pcs/pcs.c line 100
Quoted 10 lines
drivers/net/pcs/pcs.c new file +10
-0+{ +struct fwnode_pcs_provider **ptr, *pp; + + ptr =devres_alloc (devm_fwnode_pcs_del,sizeof (*ptr),GFP_KERNEL ); +if (!ptr) +return ERR_PTR (-ENOMEM ); + + pp =fwnode_pcs_add_provider (fwnode, get, data); + +if (!IS_ERR (pp)) {
[Severity: Low]
Does this unintentionally allocate devres memory for NULL fwnodes?
If a driver calls this with a NULL fwnode, fwnode_pcs_add_provider() returns 0 (NULL). Since IS_ERR() does not catch NULL pointers, !IS_ERR(pp) evaluates to true, resulting in a devres entry tracking a NULL provider.
Quoted 20 lines
drivers/net/pcs/pcs.c new file +20
-0+ *ptr = pp; +devres_add (dev, ptr); + }else { +devres_free (ptr); + } + +return pp; +} +EXPORT_SYMBOL_GPL (devm_fwnode_pcs_add_provider); + +static int fwnode_parse_pcsspec (const struct fwnode_handle *fwnode, +int index,const char *name, +struct fwnode_reference_args *out_args) +{ +int ret; + +if (!fwnode) +return -EINVAL ; + +if (name) {
drivers/net/pcs/pcs.c line 130
Quoted 10 lines
drivers/net/pcs/pcs.c new file +10
-0+ index =fwnode_property_match_string (fwnode,"pcs-names" , + name); +if (index <0 ) +return index; + } + + ret =fwnode_property_get_reference_args (fwnode,"pcs-handle" , +"#pcs-cells" ,0 , index, + out_args); +if (ret || (name && index <0 ))
[Severity: Low]
Is this (name && index < 0) check unreachable?
Since the earlier block already returns if index < 0 when name is provided:
if (name) {
index = fwnode_property_match_string(fwnode, "pcs-names",
name);
if (index < 0)
return index;
}Could this redundant check be safely removed?
Quoted 15 lines
drivers/net/pcs/pcs.c new file +15
-0+return ret; + +return 0 ; +} + +static struct phylink_pcs * +fwnode_pcs_get_from_pcsspec (struct fwnode_reference_args *pcsspec) +{ +struct fwnode_pcs_provider *provider; +struct phylink_pcs *pcs =ERR_PTR (-ENODEV ); + +if (!pcsspec) +return ERR_PTR (-EINVAL ); + +mutex_lock (&fwnode_pcs_mutex);
drivers/net/pcs/pcs.c line 155
Quoted 10 lines
drivers/net/pcs/pcs.c new file +10
-0+list_for_each_entry (provider, &fwnode_pcs_providers, link) { +if (provider->fwnode == pcsspec->fwnode) { + pcs = provider->get (pcsspec, provider->data); +if (!IS_ERR (pcs)) +break ; + } + } +mutex_unlock (&fwnode_pcs_mutex); + +return pcs;
[Severity: High]
Does this allow a use-after-free if the provider module is unloaded?
The phylink_pcs pointer is returned to the consumer here without acquiring a module reference (like try_module_get) or establishing a device link (like device_link_add).
If the administrator unbinds the PCS provider driver, it looks like fwnode_pcs_del_provider() tears down the provider without revoking consumers' dangling pointers, which could lead to a crash during subsequent phylink operations.
Quoted 1 line
+}
[ ... ]
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 229
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]
Does continuing on -ENODEV break probe deferral and misalign the array?
If a MAC driver requests multiple PCS nodes and one has not yet probed, fwnode_pcs_get() returns -ENODEV. By continuing without returning -EPROBE_DEFER, the loop skips the unprobed PCS without incrementing the found counter.
Could this cause subsequent valid PCS entries to be stored at the wrong indices in available_pcs, leading to hardware being configured incorrectly?
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
[email protected]
AI reviewRe: [PATCH net-next v11 04/12] net: phylink: save phylink instance fwnode on phylink_create
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch saves a pointer to a reference-counted `fwnode_handle` in `struct phylink` without…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch saves a pointer to a reference-counted fwnode_handle in struct phylink without acquiring a reference, creating a dormant use-after-free vulnerability. --
--- Patch [4]: [PATCH net-next v11 04/12] net: phylink: save phylink instance fwnode on phylink_create --- commit 45a3120238ef47d0743c1bd3fbcd3cc41505b72f
Author: Christian Marangi <[email protected]>
net: phylink: save phylink instance fwnode on phylink_create
This commit adds a new fwnode field to the internal struct phylink and stores the passed fwnode_handle pointer during phylink_create(). This allows future functions to reference the firmware node after creation, as it might differ from the device firmware node.
Quoted 13 lines
drivers/net/phy/phylink.c +1
-0@@ -44,6 +44,7 @@ struct phylink {const struct phylink_mac_ops *mac_ops;struct phylink_config *config;struct phylink_pcs *pcs; +const struct fwnode_handle *fwnode;struct device *dev; unsigned int old_link_state:1;
drivers/net/phy/phylink.c struct phylink *phylink_create(struct phylink_config *config, · line 1992
Quoted 4 lines
drivers/net/phy/phylink.c +1
-0@@ -1988,6 +1989,7 @@ struct phylink *phylink_create(struct phylink_config *config,INIT_LIST_HEAD (&pl->pcs_list); pl->config = config; + pl->fwnode = fwnode;
[Severity: Medium]
Will this lead to a use-after-free when callers drop their fwnode reference?
If a caller retrieves the fwnode via iterators like fwnode_for_each_available_child_node(), the iterator drops the reference to the node when the loop proceeds. Because phylink_create() assigns the pointer without taking its own reference via fwnode_handle_get(), the stored pointer could become dangling immediately after the caller's loop iteration finishes.
Should this use fwnode_handle_get(fwnode) to ensure the node remains valid for the future code paths mentioned in the commit message?
Quoted 3 lines
drivers/net/phy/phylink.c +0
-0if (config->type ==PHYLINK_NETDEV ) { pl->netdev =to_net_dev (config->dev);netif_carrier_off (pl->netdev);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH net-next v11 05/12] net: phylink: support PCS provider release
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] A self-deadlock (AA deadlock) occurs on `fwnode_pcs_mutex` when a PCS provider is deleted.…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] A self-deadlock (AA deadlock) occurs on fwnode_pcs_mutex when a PCS provider is deleted.
- [High] Unconditional list_del() in phylink_del_pcs() leads to a NULL pointer dereference or list corruption if the PCS was never added to the phylink's PCS list.
- [High] Lockless iterations of pl->pcs_list race with concurrent dynamic deletion via phylink_del_pcs(), causing LIST_POISON dereferences.
- [High] Lockless access to pl->pcs in ethtool callbacks races with runtime PCS deletion, leading to Use-After-Free.
--
--- Patch [5]: [PATCH net-next v11 05/12] net: phylink: support PCS provider release --- commit a1d43d116ac4a79cbb3a27b395cf89f68d773799
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.
Quoted 3 lines
drivers/net/pcs/pcs.c +0
-0
[ ... ]
drivers/net/pcs/pcs.c void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp) · line 87
Quoted 9 lines
drivers/net/pcs/pcs.c +5
-0@@ -67,6 +80,11 @@ void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp)mutex_lock (&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); +
[Severity: High]
Does this sequence cause a self-deadlock? fwnode_pcs_del_provider() acquires the global fwnode_pcs_mutex and then broadcasts the FWNODE_PCS_PROVIDER_DEL event via blocking_notifier_call_chain().
This synchronously invokes the phylink callback pcs_provider_notify(), which calls fwnode_phylink_pcs_get_from_fwnode(). That delegates to fwnode_pcs_get() -> __fwnode_pcs_get() -> fwnode_pcs_get_from_pcsspec().
Inside fwnode_pcs_get_from_pcsspec(), the code attempts to re-acquire the exact same fwnode_pcs_mutex. Since it is a non-recursive mutex already held by this thread, could this hang the system?
Quoted 3 lines
drivers/net/pcs/pcs.c +0
-0list_del (&pp->link);fwnode_dev_initialized (pp->fwnode, false);fwnode_handle_put (pp->fwnode);
[ ... ]
Quoted 3 lines
drivers/net/phy/phylink.c +0
-0
[ ... ]
drivers/net/phy/phylink.c static int phylink_fill_available_pcs(struct phylink *pl, · line 1955
Quoted 3 lines
drivers/net/phy/phylink.c +3
-0+static void phylink_del_pcs (struct phylink *pl,struct phylink_pcs *pcs) +{ +list_del (&pcs->list);
[Severity: High]
Can this lead to a NULL pointer dereference or list corruption?
In phylink_create(), the PCS notifier is registered before the initial PCS list is populated. If a FWNODE_PCS_PROVIDER_DEL event fires concurrently during this window, pcs_provider_notify() will look up the relevant PCS and unconditionally call phylink_del_pcs().
Because the PCS has not yet been linked into pl->pcs_list, its list_head would be uninitialized or zero-initialized. Executing list_del(&pcs->list) on an unlinked node dereferences NULL pointers.
Quoted 10 lines
drivers/net/phy/phylink.c +10
-0+ pcs->phylink =NULL ; + +/* +* Check if we are removing the PCS currently +* in use by this phylink instance. If this is the case, +* tear down the link, force phylink resolve to reconfigure the +* interface mode, disable the current PCS and set the +* phylink PCS to NULL. +*/ +if (pl->pcs == pcs) {
drivers/net/phy/phylink.c static int phylink_fill_available_pcs(struct phylink *pl, · line 1975
Quoted 10 lines
drivers/net/phy/phylink.c +10
-0+if (pl->old_link_state) { +phylink_link_down (pl); + pl->old_link_state = false; + } +if (pl->cfg_link_an_mode ==MLO_AN_INBAND ) +timer_delete_sync (&pl->link_poll); +phylink_pcs_disable (pl->pcs); + + pl->force_major_config = true; +WRITE_ONCE (pl->pcs,NULL );
[Severity: High]
Does clearing pl->pcs here race with ethtool callbacks, leading to a use-after-free?
Functions triggered by ethtool, such as phylink_ethtool_nway_reset(), operate with only the RTNL lock held and do not acquire pl->state_mutex. They call phylink_pcs_an_restart(), which reads pl->pcs and dereferences its operations pointer locklessly:
if (pl->pcs && ... )
pl->pcs->ops->pcs_an_restart(pl->pcs);
Concurrently, this teardown path takes pl->state_mutex (but not RTNL), detaches the PCS, and returns. The underlying memory can then be freed by the provider driver. Could the ethtool path read a valid pl->pcs pointer just before detachment, and dereference it after it is freed?
Quoted 9 lines
drivers/net/phy/phylink.c +9
-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); +const struct fwnode_handle *pl_fwnode = pl->fwnode; +struct fwnode_handle *pcs_fwnode = data;
drivers/net/phy/phylink.c static int phylink_fill_available_pcs(struct phylink *pl, · line 1994
Quoted 10 lines
drivers/net/phy/phylink.c +10
-0+struct phylink_pcs *pcs; + +/* Check if the PCS provider is relevant for this phylink instance */ + pcs =fwnode_phylink_pcs_get_from_fwnode (pl_fwnode, pcs_fwnode); +if (IS_ERR (pcs)) +return NOTIFY_DONE ; + +mutex_lock (&pl->state_mutex); + +phylink_del_pcs (pl, pcs);
[Severity: High]
Does dynamically modifying the list here race with existing lockless iterations of pl->pcs_list?
Before this patch, pl->pcs_list was populated in phylink_create() and treated as read-only. Existing readers like phylink_validate_mac_and_pcs() and phylink_inband_caps() iterate over pl->pcs_list locklessly while holding only the RTNL lock.
If a PCS provider is removed concurrently under pl->state_mutex, could these RTNL-only readers follow poisoned list pointers resulting from list_del(), crashing the kernel?
Additionally, the error path in phylink_create() iterates and unlinks the list locklessly before unregistering the global notifier:
unlink_pcs_list:
list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
list_del(&pcs->list);
...
}Could this error path race with the notifier callback?
Quoted 4 lines
drivers/net/phy/phylink.c +4
-0+ +/* Refresh supported interfaces */ +phy_interface_copy (pl->supported_interfaces, + pl->config->supported_interfaces);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH net-next v11 06/12] net: phylink: support late PCS provider attach
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [Critical] Self-deadlock in fwnode_pcs_del_provider via FWNODE_PCS_PROVIDER_DEL notification. - [High]…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] Self-deadlock in fwnode_pcs_del_provider via FWNODE_PCS_PROVIDER_DEL notification.
- [High] Error paths in phylink_create skip necessary cleanup, leading to Use-After-Free of the phylink instance and dangling PCS pointers.
- [High] phylink_del_pcs unconditionally calls list_del, crashing on PCS structures not tracked in the phylink list.
- [High] Missing reference counting on struct phylink_pcs pointers allows a TOCTOU Use-After-Free during asynchronous provider removal. --
--- Patch [6]: [PATCH net-next v11 06/12] net: phylink: support late PCS provider attach --- commit d404b5bc48ec98384e8bad4f7b0b1af967121eee
Author: Christian Marangi <[email protected]>
net: phylink: support late PCS provider attach
This patch adds support for attaching a PCS provider to a phylink instance after the instance has been created and started. It introduces FWNODE_PCS_PROVIDER_ADD to notify phylink when a new PCS provider becomes available, linking it and triggering a resolve step to recover links.
Quoted 4 lines
drivers/net/phy/phylink.c +0
-0
[ ... ]
drivers/net/phy/phylink.c static int phylink_fill_available_pcs(struct phylink *pl, · line 1963
Quoted 6 lines
drivers/net/phy/phylink.c +1
-1@@ -1939,7 +1960,7 @@ static int phylink_fill_available_pcs(struct phylink *pl,if (!pcs)continue ; -list_add_tail (&pcs->list, &pl->pcs_list); +phylink_add_pcs (pl, pcs);
[Severity: High]
Could the lack of reference counting on the returned phylink_pcs pointers lead to a use-after-free here?
fwnode_pcs_get() and its underlying provider callbacks return a pointer without taking a reference. If a concurrent provider unbind occurs right before pl->state_mutex is acquired, the provider could be removed and the memory freed.
When the lock is finally acquired in phylink_fill_available_pcs(), could this add a freed pointer to the list?
Quoted 9 lines
drivers/net/phy/phylink.c +1
-1}mutex_unlock (&pl->state_mutex);@@ -1991,7 +2012,19 @@ static int pcs_provider_notify(struct notifier_block *self,mutex_lock (&pl->state_mutex); -phylink_del_pcs (pl, pcs); +switch (val) {
drivers/net/phy/phylink.c static int pcs_provider_notify(struct notifier_block *self, · line 2025
Quoted 10 lines
drivers/net/phy/phylink.c +10
-0+case FWNODE_PCS_PROVIDER_ADD : +phylink_add_pcs (pl, pcs); + +/* Force an interface reconfig if major config fail */ +if (pl->major_config_failed) + pl->force_major_config = true; + +break ; +case FWNODE_PCS_PROVIDER_DEL : +phylink_del_pcs (pl, pcs);
[Severity: High]
Will this cause a crash if the PCS being removed was never actually added to the list?
When handling a provider removal, phylink_del_pcs() is called unconditionally based purely on its presence in the device tree. If the driver's fill_available_pcs() omitted it, or if phylink_create() failed before it could be added, the pcs->list remains uninitialized.
Would this lead to list_del(&pcs->list) dereferencing a NULL pointer?
[Severity: Critical]
Could this notifier chain lead to a self-deadlock when removing a provider?
When fwnode_pcs_del_provider() is called, it acquires fwnode_pcs_mutex and fires the FWNODE_PCS_PROVIDER_DEL notification.
This notifier callback, pcs_provider_notify(), responds by calling fwnode_phylink_pcs_get_from_fwnode():
pcs_provider_notify()
pcs = fwnode_phylink_pcs_get_from_fwnode(pl_fwnode, pcs_fwnode);
This subsequently calls fwnode_pcs_get_from_pcsspec(), which attempts to acquire the exact same fwnode_pcs_mutex lock.
Since the lock is not recursive, will this result in a deadlock on the thread removing the provider?
drivers/net/phy/phylink.c struct phylink *phylink_create(struct phylink_config *config, · line 2083
Quoted 13 lines
drivers/net/phy/phylink.c +2
-4+break ; + }/* Refresh supported interfaces */ phy_interface_copy(pl->supported_interfaces,@@ -2077,10 +2110,6 @@ struct phylink *phylink_create(struct phylink_config *config,mutex_lock (&pl->state_mutex); -/* Link available PCS to phylink */ -list_for_each_entry (pcs, &pl->pcs_list, list) - pcs->phylink = pl; -
[Severity: High]
Does the error handling in phylink_create() leak dangling pointers and use freed memory if a failure occurs after the notifier is registered?
The PCS notifier is registered early in phylink_create(). If an asynchronous FWNODE_PCS_PROVIDER_ADD event fires concurrently, pcs_provider_notify() can queue the pl->resolve work item.
If phylink_create() subsequently fails (for example, in phylink_fill_available_pcs()), the error path jumps to unregister_pcs_notify and frees the phylink structure:
unregister_pcs_notify:
unregister_fwnode_pcs_notifier(&pl->fwnode_pcs_nb);
free_pl:
kfree(pl);This path does not call cancel_work_sync(&pl->resolve), leaving the queued work to execute on freed memory.
Additionally, because the error path skips unlinking the PCS list, any PCS dynamically added by the notifier will be left with a dangling pcs->phylink pointer.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH net-next v11 07/12] net: Document PCS subsystem
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Mutex deadlock during fwnode_pcs_del_provider() due to notifier callback re-acquiring…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Mutex deadlock during fwnode_pcs_del_provider() due to notifier callback re-acquiring fwnode_pcs_mutex.
- [High] Concurrent list modification in phylink_create() error path due to missing mutex and incorrect cleanup ordering. --
--- Patch [7]: [PATCH net-next v11 07/12] net: Document PCS subsystem --- commit 0d23601c1b08a3129af4d3f510928e8e13e5be2d
Author: Christian Marangi <[email protected]>
net: Document PCS subsystem
Add extensive documentation of the new PCS subsystem and the fwnode implementation with producer/consumer API.
Also update the sfp-phylink migration guide.
Quoted 7 lines
drivers/net/pcs/pcs.c new file +1
-0@@ -0,0 +1,294 @@ +// SPDX-License-Identifier: GPL-2.0-or-later
[ ... ]
drivers/net/pcs/pcs.c
Quoted 11 lines
drivers/net/pcs/pcs.c new file +11
-0+void fwnode_pcs_del_provider (struct fwnode_pcs_provider *pp) +{ +if (IS_ERR_OR_NULL (pp)) +return ; + +mutex_lock (&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);
[Severity: High]
Does this code cause a mutex deadlock?
When fwnode_pcs_del_provider() is called, it acquires fwnode_pcs_mutex to protect the providers list before triggering the blocking notifier.
The registered notifier pcs_provider_notify() runs in the same thread context. It handles the event by calling fwnode_phylink_pcs_get_from_fwnode(), which cascades down to fwnode_pcs_get_from_pcsspec():
pcs_provider_notify()
fwnode_phylink_pcs_get_from_fwnode()
fwnode_pcs_get()
__fwnode_pcs_get()
fwnode_pcs_get_from_pcsspec()
mutex_lock(&fwnode_pcs_mutex);Since fwnode_pcs_mutex is a standard (non-recursive) mutex, attempting to lock it twice would result in a deterministic deadlock during normal teardown paths.
Quoted 9 lines
drivers/net/pcs/pcs.c new file +9
-0+ +list_del (&pp->link); +fwnode_dev_initialized (pp->fwnode, false); +fwnode_handle_put (pp->fwnode); +kfree (pp); + +mutex_unlock (&fwnode_pcs_mutex); +} +EXPORT_SYMBOL_GPL (fwnode_pcs_del_provider);
[ ... ]
Quoted 4 lines
drivers/net/phy/phylink.c +0
-0
[ ... ]
drivers/net/phy/phylink.c struct phylink *phylink_create(struct phylink_config *config, · line 2180
Quoted 11 lines
drivers/net/phy/phylink.c +7
-0@@ -1928,6 +2171,13 @@ 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 ; + } +unregister_pcs_notify: +unregister_fwnode_pcs_notifier (&pl->fwnode_pcs_nb);
[Severity: High]
Can this error path lead to concurrent list modification?
In this error path, pl->pcs_list is manipulated without holding pl->state_mutex, and this occurs before the PCS notifier (pl->fwnode_pcs_nb) is unregistered.
If a provider addition or deletion event fires concurrently, pcs_provider_notify() will be invoked. The notifier safely acquires pl->state_mutex to modify pl->pcs_list, but because this teardown path does not hold the mutex while executing list_del(&pcs->list), it creates an unsafe data race.
To safely fix this, could the teardown unregister the notifier first and then hold pl->state_mutex while iterating the list, similar to how it is handled in phylink_destroy()?
Quoted 3 lines
drivers/net/phy/phylink.c +0
-0free_pl:kfree (pl);return ERR_PTR (ret);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [PATCH net-next v11 09/12] net: phylink: add .pcs_link_down PCS OP
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Lockless traversal of `pl->pcs_list` and unprotected modification of `pl->pcs` in…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Lockless traversal of pl->pcs_list and unprotected modification of pl->pcs in phylink_start() and phylink_resume(). --
--- Patch [9]: [PATCH net-next v11 09/12] net: phylink: add .pcs_link_down PCS OP --- commit 7a2f38b91902153c2c82a86f0b98d881f66246ff
Author: Christian Marangi <[email protected]>
net: phylink: add .pcs_link_down PCS OP
This commit adds a .pcs_link_down operation to permit a PCS driver to define specific actions to tear down the link between the MAC and the PCS. It hooks into phylink_link_down() to call this new operation when tearing down the link.
Quoted 4 lines
drivers/net/phy/phylink.c +0
-0
[ ... ]
drivers/net/phy/phylink.c static void phylink_link_down(struct phylink *pl) · line 1696
Quoted 9 lines
drivers/net/phy/phylink.c +3
-0@@ -1683,6 +1689,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" ); }
[Severity: High]
Does this sequence permit concurrent list traversal and modification of pl->pcs_list?
Looking at phylink_start(), it initiates the configuration path without acquiring pl->state_mutex:
phylink_start()
phylink_mac_initial_config(pl, true)
phylink_major_config()
list_for_each_entry(pcs, &pl->pcs_list, list) {
...
}Concurrently, pcs_provider_notify() modifies the list under pl->state_mutex but without rtnl_lock:
pcs_provider_notify()
mutex_lock(&pl->state_mutex);
...
phylink_add_pcs(pl, pcs);
list_add_tail(&pcs->list, &pl->pcs_list);Can this lead to list corruption if a PCS provider probe races with a network interface startup?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
[email protected]
AI reviewRe: [PATCH net-next v11 10/12] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Missing `minItems` and `maxItems` constraints in `if-then` blocks for `reg` and `reg-names`…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing minItems and maxItems constraints in if-then blocks for reg and reg-names allow incomplete device tree nodes to silently pass validation. --
--- Patch [10]: [PATCH net-next v11 10/12] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS --- commit d59fd3ae8fb2709a26756c96f02e5d3905143b5a
Author: Christian Marangi <[email protected]>
dt-bindings: net: pcs: Document support for Airoha Ethernet PCS
This patch documents support for Airoha Ethernet PCS for AN7581 SoC. It adds a new physical coding sublayer provider binding for the various Serdes ports (10BASE-R, USXGMII, 2500BASE-X, 1000BASE-X, SGMII).
Quoted 4 lines
Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml new file +0
-0
[ ... ]
Quoted 11 lines
Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml new file +11
-0+allOf: + - if: + properties: + compatible: + contains: + enum: + - airoha,an7581-pcs-eth + - airoha,an7581-pcs-pon + + then: + properties:
Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml line 69
Quoted 10 lines
Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml new file +10
-0+ 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
[Severity: Medium]
Should this allOf conditional block for eth/pon also specify minItems: 8 and
maxItems: 8 for the reg and reg-names arrays?
Because the top-level schema defines minItems: 6 and maxItems: 15, defining an items list here without explicit length constraints means a device tree providing only 6 registers will silently pass validation for this variant.
[ ... ]
Quoted 15 lines
Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml new file +15
-0+ - 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
Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml line 114
Quoted 10 lines
Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml new file +10
-0+ - 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
[Severity: Medium]
Similarly, does this pcie allOf conditional block need a minItems: 15 constraint to ensure all required registers are present?
Without minItems constraints on reg and reg-names, any array length between the top-level 6 and 15 will pass validation, allowing incomplete device tree nodes to be accepted.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
[email protected]
AI reviewRe: [PATCH net-next v11 11/12] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] Unconditional global reset and shared PLL reconfiguration disrupts active multi-port setups.…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Unconditional global reset and shared PLL reconfiguration disrupts active multi-port setups.
- [High] NULL pointer dereference when instantiated without OF match data.
- [High] Unintentional clearing of unhandled interrupts due to RMW on W1C registers.
- [High] Uninitialized stack variables written to hardware registers.
- [Medium] Hardware calibration degradation due to infinite continuation on perfect match. --
--- Patch [11]: [PATCH net-next v11 11/12] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC --- commit aec569f759beda361ff885957891c7c73a20bfd6
Author: Christian Marangi <[email protected]>
Subject: net: pcs: airoha: add PCS driver for Airoha AN7581 SoC
This commit introduces a new PCS driver for the Airoha AN7581 SoC, supporting Ethernet, PON, PCIe, and USB SERDES. It supports multiple interface modes including USXGMII, 10G-BASER, 2500BASE-X, 1000BASE-X, and SGMII.
Quoted 5 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +0
-0@@ -0,0 +1,1303 @@
[ ... ]
Quoted 12 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +12
-0+static int airoha_pcs_setup_scu (struct airoha_pcs_priv *priv, +int index,phy_interface_t interface) +{ +const struct airoha_pcs_match_data *data = priv->data; +int ret; + +switch (data->port_type) { +case AIROHA_PCS_ETH : +airoha_pcs_setup_scu_eth (priv, interface); +break ; +case AIROHA_PCS_PON : +airoha_pcs_setup_scu_pon (priv, interface);
drivers/net/pcs/airoha/pcs-airoha-common.c line 135
Quoted 10 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +10
-0+break ; +case AIROHA_PCS_PCIE : +airoha_pcs_setup_scu_pcie (priv, index, interface); +break ; +case AIROHA_PCS_USB : +break ; + } + + ret =reset_control_bulk_assert (ARRAY_SIZE (priv->rsts), + priv->rsts);
[Severity: High]
Does this unconditional global reset disrupt active multi-port setups?
In airoha_pcs_setup_scu(), asserting and deasserting the shared bulk resets for the entire PCS block will affect all ports. If the driver manages a multi-port instance, bringing up a secondary port might dynamically crash the link on an already-active primary port.
Quoted 2 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +2
-0+if (ret) +return ret;
[ ... ]
Quoted 6 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +6
-0+static void airoha_pcs_interrupt_init_sgmii (struct airoha_pcs_priv *priv, +int index) +{ +struct airoha_pcs_maps *maps = &priv->maps[index]; + +/* Disable every interrupt */
drivers/net/pcs/airoha/pcs-airoha-common.c line 229
Quoted 10 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +10
-0+regmap_clear_bits (maps->hsgmii_pcs,AIROHA_PCS_HSGMII_PCS_HSGMII_MODE_INTERRUPT , +AIROHA_PCS_HSGMII_MODE2_REMOVE_FAULT_OCCUR_INT | +AIROHA_PCS_HSGMII_MODE2_AN_CL37_TIMERDONE_INT | +AIROHA_PCS_HSGMII_MODE2_AN_MIS_INT | +AIROHA_PCS_HSGMII_MODE2_RX_SYN_DONE_INT | +AIROHA_PCS_HSGMII_MODE2_AN_DONE_INT ); + +/* Clear interrupt */ + regmap_set_bits(maps->hsgmii_pcs, AIROHA_PCS_HSGMII_PCS_HSGMII_MODE_INTERRUPT, + AIROHA_PCS_HSGMII_MODE2_REMOVE_FAULT_OCCUR_INT_CLEAR |
[Severity: High]
Can using regmap_set_bits() here cause unrelated pending interrupts to be lost?
regmap_set_bits() performs a read-modify-write. On Write-1-to-Clear registers, reading the active status bits and writing them back writes 1 to all currently active interrupts, which would silently acknowledge and drop any interrupts that fired before the write.
Quoted 1 line
drivers/net/pcs/airoha/pcs-airoha-common.c new file +1
-0+ AIROHA_PCS_HSGMII_MODE2_AN_CL37_TIMERDONE_INT_CLEAR |
[ ... ]
Quoted 3 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +3
-0+static void airoha_pcs_interrupt_init_usxgmii (struct airoha_pcs_priv *priv, +int index) +{
[ ... ]
drivers/net/pcs/airoha/pcs-airoha-common.c line 278
Quoted 3 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +3
-0+/* 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 |
[Severity: High]
Could this read-modify-write on a W1C register lead to missed interrupts here as well?
Similar to the sgmii interrupt initialization above, regmap_set_bits() will write back any already-set status bits and potentially clear unhandled interrupts silently.
Quoted 1 line
drivers/net/pcs/airoha/pcs-airoha-common.c new file +1
-0+ AIROHA_PCS_USXGMII_R_TYPE_E_INT |
[ ... ]
Quoted 3 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +3
-0+static void airoha_pcs_link_up (struct phylink_pcs *pcs,unsigned int neg_mode, +phy_interface_t interface,int speed,int duplex) +{
[ ... ]
Quoted 33 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +33
-0+if (interface ==PHY_INTERFACE_MODE_SGMII || + interface ==PHY_INTERFACE_MODE_2500BASEX ) { +u32 ck_gen_mode; +u32 speed_reg; +u32 if_mode; + +switch (speed) { +case SPEED_2500 : + speed_reg =AIROHA_PCS_LINK_MODE_P0_2_5G ; +break ; +case SPEED_1000 : + speed_reg =AIROHA_PCS_LINK_MODE_P0_1G ; + if_mode =AIROHA_PCS_HSGMII_AN_SPEED_FORCE_MODE_1000 ; + ck_gen_mode =AIROHA_PCS_HSGMII_PCS_FORCE_CUR_SGMII_MODE_1000 ; +break ; +case SPEED_100 : + speed_reg =AIROHA_PCS_LINK_MODE_P0_100M ; + if_mode =AIROHA_PCS_HSGMII_AN_SPEED_FORCE_MODE_100 ; + ck_gen_mode =AIROHA_PCS_HSGMII_PCS_FORCE_CUR_SGMII_MODE_100 ; +break ; +case SPEED_10 : + speed_reg =AIROHA_PCS_LINK_MODE_P0_10M ; + if_mode =AIROHA_PCS_HSGMII_AN_SPEED_FORCE_MODE_10 ; + ck_gen_mode =AIROHA_PCS_HSGMII_PCS_FORCE_CUR_SGMII_MODE_10 ; +break ; + } + +if (interface ==PHY_INTERFACE_MODE_SGMII ) { +regmap_update_bits (maps->hsgmii_an,AIROHA_PCS_HSGMII_AN_SGMII_REG_AN_13 , +AIROHA_PCS_HSGMII_AN_SPEED_FORCE_MODE , + if_mode); + + regmap_update_bits(maps->hsgmii_pcs, AIROHA_PCS_HSGMII_PCS_AN_SGMII_MODE_FORCE,
drivers/net/pcs/airoha/pcs-airoha-common.c line 831
Quoted 10 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +10
-0+AIROHA_PCS_HSGMII_PCS_FORCE_CUR_SGMII_MODE | +AIROHA_PCS_HSGMII_PCS_FORCE_CUR_SGMII_MODE_SEL , + ck_gen_mode | + AIROHA_PCS_HSGMII_PCS_FORCE_CUR_SGMII_MODE_SEL); + } + + regmap_update_bits(maps->multi_sgmii, AIROHA_PCS_MULTI_SGMII_SGMII_STS_CTRL_0, + AIROHA_PCS_LINK_MODE_P0 | + AIROHA_PCS_FORCE_SPD_MODE_P0, + speed_reg |
[Severity: High]
Are we certain speed matches one of the expected cases here?
If speed is unknown or unhandled, the switch statement falls through without initializing speed_reg, if_mode, or ck_gen_mode. This would result in garbage values from the stack being written to the PCS control registers.
Quoted 3 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +3
-0+ AIROHA_PCS_FORCE_SPD_MODE_P0); + } + }
[ ... ]
Quoted 5 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +5
-0+static int airoha_pcs_probe (struct platform_device *pdev) +{ +const struct airoha_pcs_match_data *data; +struct fwnode_pcs_provider *pcs_provider; +struct device *dev = &pdev->dev;
drivers/net/pcs/airoha/pcs-airoha-common.c line 1139
Quoted 10 lines
drivers/net/pcs/airoha/pcs-airoha-common.c new file +10
-0+struct airoha_pcs_priv *priv; +int index, ret; + + data =of_device_get_match_data (dev); + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->ports = devm_kcalloc(dev, data->num_port,
[Severity: High]
Will this crash if the driver is bound without an OF match?
If the device is instantiated via platform mechanisms matching by name rather than through an OF node, of_device_get_match_data() will return NULL, causing a NULL pointer dereference here when accessing data->num_port.
Quoted 1 line
drivers/net/pcs/airoha/pcs-airoha-common.c new file +1
-0+ sizeof(*priv->ports), GFP_KERNEL);
[ ... ]
Quoted 5 lines
drivers/net/pcs/airoha/pcs-an7581.c new file +0
-0@@ -0,0 +1,2093 @@
[ ... ]
Quoted 19 lines
drivers/net/pcs/airoha/pcs-an7581.c new file +19
-0+static void an7581_pcs_jcpll_bringup (struct airoha_pcs_priv *priv, +int index,phy_interface_t interface) +{ +struct regmap_field **pcs_ana_fields = priv->pcs_ana_fields[index]; +struct regmap *pcs_pma; +u32 kband_vref; + +switch (interface) { +case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_1000BASEX : +case PHY_INTERFACE_MODE_2500BASEX : + kband_vref =0x10 ; +break ; +case PHY_INTERFACE_MODE_USXGMII : +case PHY_INTERFACE_MODE_10GBASER : + kband_vref =0xf ; +break ; +default : +return ;
drivers/net/pcs/airoha/pcs-an7581.c line 702
Quoted 10 lines
drivers/net/pcs/airoha/pcs-an7581.c new file +10
-0+ } + +/* 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 +* for correct functionality for JCPLL. +*/ + pcs_pma = priv->pcs_pma[0 ];
[Severity: High]
Does hardcoding pcs_pma[0] disrupt port 1 when it is brought up?
In a multi-port scenario, an7581_pcs_jcpll_bringup() and an7581_pcs_txpll_bringup() will unconditionally reconfigure the shared PLL via pcs_pma[0]. This could dynamically crash or reset the link on an already-active primary port when the secondary port is configured.
Quoted 2 lines
drivers/net/pcs/airoha/pcs-an7581.c new file +2
-0+ +/* Setup LDO */
[ ... ]
Quoted 3 lines
drivers/net/pcs/airoha/pcs-an7581.c new file +3
-0+static u32 an7581_pcs_rx_prcal_idac_minor (struct airoha_pcs_priv *priv,int index, +u32 target_fl_out,u32 cdr_pr_idac_major) +{
[ ... ]
drivers/net/pcs/airoha/pcs-an7581.c line 1578
Quoted 11 lines
drivers/net/pcs/airoha/pcs-an7581.c new file +11
-0+/* Assume we found the deadline when the new absolue signal difference +* from target is greater than the previous and the difference is at +* least 10% greater between the old and new value. +* This is to account for signal detection level tollerance making +* sure we are actually over a deadline (AKA we are getting farther +* from target) +*/ +dev_dbg (priv->dev,"Tested CDR Pr Idac: %x Fl Out: %x Diff: %u\n" , + cdr_pr_idac_tmp, fl_out, fl_out_diff_new); +if (fl_out_diff && fl_out_diff_new > fl_out_diff && + (abs_diff (fl_out_diff_new, fl_out_diff) *100 ) / fl_out_diff >10 ) {
[Severity: Medium]
What happens if the previous iteration achieved a perfect match?
If fl_out_diff becomes 0 because of an exact match with target_fl_out, this condition evaluates to false. The loop will then fall through to the else branch, continuing to add bits and moving away from the perfect calibration, resulting in hardware calibration degradation.
Quoted 1 line
drivers/net/pcs/airoha/pcs-an7581.c new file +1
-0+/* Exit early if we are already at the deadline */
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
[email protected]
AI reviewRe: [PATCH net-next v11 12/12] net: airoha: add phylink support
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] NET_AIROHA unconditionally selects PCS_AIROHA, which leads to an unmet dependency warning on…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] NET_AIROHA unconditionally selects PCS_AIROHA, which leads to an unmet dependency warning on COMPILE_TEST when ACPI and OF are disabled. --
--- Patch [12]: [PATCH net-next v11 12/12] net: airoha: add phylink support --- commit 60178eed84d4f34367e6ce74cdedc61c17f52abb
Author: Christian Marangi <[email protected]>
net: airoha: add phylink support
This commit adds phylink support for GDM ports in the Airoha ethernet driver, configuring GDM1 for internal interface mode and GDM2/3/4 for external PHY or SFP cage operation via PCS. It also updates ethtool link ksettings to use phylink.
drivers/net/ethernet/airoha/Kconfig config NET_AIROHA · line 23
Quoted 9 lines
drivers/net/ethernet/airoha/Kconfig +1
-0@@ -20,6 +20,8 @@ config NET_AIROHA depends on NET_DSA || !NET_DSA select NET_AIROHA_NPU select PAGE_POOL + select PCS_AIROHA
[Severity: Medium]
Does selecting PCS_AIROHA here create an unmet dependency warning under COMPILE_TEST? PCS_AIROHA selects FWNODE_PCS, which depends on ACPI || OF. Since NET_AIROHA unconditionally selects PCS_AIROHA without inheriting the ACPI || OF dependency, can this cause a Kconfig warning and potential build failures when both are disabled?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Andrew Lunn
maintainerRe: [PATCH net-next v11 02/12] net: phylink: introduce internal phylink PCS handling
In reply to Christian MarangiQuoted 12 lines
+++
b/drivers/net/phy/phylink.cdrivers/net/phy/phylink.c +3
-0@@ -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. */
drivers/net/phy/phylink.c static const phy_interface_t phylink_sfp_interface_preference[] = { · line 160
Quoted 4 lines
drivers/net/phy/phylink.c +1
-0@@ -154,6 +157,8 @@ static const phy_interface_t phylink_sfp_interface_preference[] = {static DECLARE_PHY_INTERFACE_MASK (phylink_sfp_interfaces); +static void phylink_run_resolve (struct phylink *pl);
forward definitions are not liked. Please add a patch which moves it earlier.
Andrew
Re: [PATCH net-next v11 04/12] net: phylink: save phylink instance fwnode on phylink_create
In reply to Christian MarangiQuoted 9 lines · Christian Marangi
The firmware node associated with the phylink instance might differ from the device firmware node passed in
phylink_configas such device can reference the parent switch or other platform peripherals.Some function might need to reference this firmware node after
phylink_createso add a dedicated fwnode entry in phylink internal struct and save it onphylink_create().Signed-off-by Christian Marangi <[email protected]>
Andrew
Re: [PATCH net-next v11 06/12] net: phylink: support late PCS provider attach
In reply to Christian MarangiQuoted 14 lines · Christian Marangi
Add support for late PCS provider attachment to a phylink instance. Similar to
FWNODE_PCS_PROVIDER_DEL,FWNODE_PCS_PROVIDER_ADDis 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_ADDevery time a new PCS provider is added.If a related PCS is found, then such PCS is added to the phylink instance PCS list.
Then we link the PCS to the phylink instance and we refresh the supported interfaces of the phylink instance.
Quoted 8 lines
Finally we check if we are in a
major_config_failedscenario and trigger an interface reconfiguration 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.
Signed-off-by Christian Marangi <[email protected]>
Andrew
Andrew Lunn
maintainerQuoted 3 lines · Christian Marangi
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.
One of Russells complaints was the phylink has too many bits of code for ideas which did not work out and were replaced by new ways of doing things.
We want .mac_select_pcs to go away, this framework should replace it. Please could you convert one of the exist users of .mac_select_pcs, so we get an idea of what that involved. If that conversion is pretty mechanical, i think we should have a second patchset which converts all the current users, and then remove support for .mac_select_pcs.
Overall i think the direction of this patchset is good.
Andrew
Quoted 9 lines · Andrew Lunn
Quoted 3 lines · Christian Marangi
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.
One of Russells complaints was the phylink has too many bits of code for ideas which did not work out and were replaced by new ways of doing things.
Quoted 8 lines
We want .mac_select_pcs to go away, this framework should replace it. Please could you convert one of the exist users of .mac_select_pcs, so we get an idea of what that involved. If that conversion is pretty mechanical, i think we should have a second patchset which converts all the current users, and then remove support for .mac_select_pcs.
Overall i think the direction of this patchset is good.
Thanks for the initial check.
Maxime converted one device with this and the patch delta was small... let me copy those patch here. (it was referenced in v9)
I think the most annoying one will be stmmac with the 3 different PCS implementation but we already handled that in a upcoming ipq50xx driver currently present in OpenWrt mainline.
Maybe if Maxime is O.K. I can include his patch in this series.
From 38ad94b1e62bf3523097983dfb515f59b1634477 Mon Sep 17 00:00:00 2001
From: Maxime Chevallier <[email protected]>
Date: Tue, 21 Jul 2026 13:52:57 +0200
Subject: [PATCH] net: marvell: mvpp2: Convert to the new PCS API
Following the introduction of the PCS framework, port mvpp2 to the new PCS API.
--- .../net/ethernet/marvell/mvpp2/mvpp2_main.c | 161 +++++++++++------- 1 file changed, 95 insertions(+), 66 deletions(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +95 -66
@@ -6499,21 +6499,6 @@ static void mvpp2_gmac_config(struct mvpp2_port *port, unsigned int mode,writel (ctrl4, port->base +MVPP22_GMAC_CTRL_4_REG ); } -static struct phylink_pcs *mvpp2_select_pcs (struct phylink_config *config, -phy_interface_t interface) -{ -struct mvpp2_port *port =mvpp2_phylink_to_port (config); - -/* Select the appropriate PCS operations depending on the -* configured interface mode. We will only switch to a mode -* that the validate() checks have already passed. -*/ -if (mvpp2_is_xlg (interface)) -return &port->pcs_xlg; -else -return &port->pcs_gmac; -} -static int mvpp2_mac_prepare (struct phylink_config *config,unsigned int mode,phy_interface_t interface) {
@@ -6786,7 +6771,6 @@ static int mvpp2_mac_enable_tx_lpi(struct phylink_config *config, u32 timer, }static const struct phylink_mac_ops mvpp2_phylink_ops = { - .mac_select_pcs = mvpp2_select_pcs, .mac_prepare = mvpp2_mac_prepare, .mac_config = mvpp2_mac_config, .mac_finish = mvpp2_mac_finish,
@@ -6808,7 +6792,10 @@ static void mvpp2_acpi_start(struct mvpp2_port *port) };struct phylink_pcs *pcs; - pcs =mvpp2_select_pcs (&port->phylink_config, port->phy_interface); +if (mvpp2_is_xlg (port->phy_interface)) + pcs = &port->pcs_xlg; +else + pcs = &port->pcs_gmac;mvpp2_mac_prepare (&port->phylink_config,MLO_AN_INBAND , port->phy_interface);
@@ -6823,6 +6810,78 @@ static void mvpp2_acpi_start(struct mvpp2_port *port) SPEED_UNKNOWN, DUPLEX_UNKNOWN, false, false); } +static int mvpp2_port_fill_pcs (struct phylink_config *config, +struct phylink_pcs **available_pcs, +unsigned int num_possible_pcs) +{ +struct mvpp2_port *port =mvpp2_phylink_to_port (config); + + available_pcs[0 ] = &port->pcs_gmac; + +if (mvpp2_port_supports_xlg (port)) { +if (num_possible_pcs <2 ) +return -EINVAL ; + + available_pcs[1 ] = &port->pcs_xlg; + } + +return 0 ; +} + +static void mvpp2_port_init_pcs_xlg (struct phylink_pcs *pcs,bool has_comphy, +phy_interface_t phy_mode) +{ +if (has_comphy) { +__set_bit (PHY_INTERFACE_MODE_5GBASER , + pcs->supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_10GBASER , + pcs->supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_XAUI , + pcs->supported_interfaces); + }else if (phy_mode ==PHY_INTERFACE_MODE_5GBASER ) { +__set_bit (PHY_INTERFACE_MODE_5GBASER , + pcs->supported_interfaces); + }else if (phy_mode ==PHY_INTERFACE_MODE_10GBASER ) { +__set_bit (PHY_INTERFACE_MODE_10GBASER , + pcs->supported_interfaces); + }else if (phy_mode ==PHY_INTERFACE_MODE_XAUI ) { +__set_bit (PHY_INTERFACE_MODE_XAUI , + pcs->supported_interfaces); + } +} + +static void mvpp2_port_init_pcs_gmac (struct phylink_pcs *pcs,bool has_comphy, +phy_interface_t phy_mode) +{ +if (has_comphy) { +/* If a COMPHY is present, we can support any of the +* serdes modes and switch between them. +*/ +__set_bit (PHY_INTERFACE_MODE_SGMII , + pcs->supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_1000BASEX , + pcs->supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_2500BASEX , + pcs->supported_interfaces); + }else if (phy_mode ==PHY_INTERFACE_MODE_2500BASEX ) { +/* No COMPHY, with only 2500BASE-X mode supported */ +__set_bit (PHY_INTERFACE_MODE_2500BASEX , + pcs->supported_interfaces); + }else if (phy_mode ==PHY_INTERFACE_MODE_1000BASEX || + phy_mode ==PHY_INTERFACE_MODE_SGMII ) { +/* No COMPHY, we can switch between 1000BASE-X and SGMII +*/ +__set_bit (PHY_INTERFACE_MODE_1000BASEX , + pcs->supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_SGMII , + pcs->supported_interfaces); + } + +/* RGMII and MII are still routed through the gmac PCS */ +phy_interface_set_rgmii (pcs->supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_MII , pcs->supported_interfaces); +} +/* In order to ensure backward compatibility for ACPI, check if the port * firmware node comprises the necessary description allowing to use phylink. */
@@ -7082,28 +7141,17 @@ static int mvpp2_port_probe(struct platform_device *pdev, port->phylink_config.mac_capabilities |=MAC_SYM_PAUSE |MAC_ASYM_PAUSE ; -if (mvpp2_port_supports_xlg (port)) { -/* If a COMPHY is present, we can support any of -* the serdes modes and switch between them. -*/ -if (comphy) { -__set_bit (PHY_INTERFACE_MODE_5GBASER , - port->phylink_config.supported_interfaces); -__set_bit (PHY_INTERFACE_MODE_10GBASER , - port->phylink_config.supported_interfaces); -__set_bit (PHY_INTERFACE_MODE_XAUI , - port->phylink_config.supported_interfaces); - }else if (phy_mode ==PHY_INTERFACE_MODE_5GBASER ) { -__set_bit (PHY_INTERFACE_MODE_5GBASER , - port->phylink_config.supported_interfaces); - }else if (phy_mode ==PHY_INTERFACE_MODE_10GBASER ) { -__set_bit (PHY_INTERFACE_MODE_10GBASER , - port->phylink_config.supported_interfaces); - }else if (phy_mode ==PHY_INTERFACE_MODE_XAUI ) { -__set_bit (PHY_INTERFACE_MODE_XAUI , - port->phylink_config.supported_interfaces); - } +if (!mvpp2_port_supports_xlg (port)) + port->phylink_config.num_possible_pcs =1 ; +else + port->phylink_config.num_possible_pcs =2 ; + + port->phylink_config.fill_available_pcs = mvpp2_port_fill_pcs; +mvpp2_port_init_pcs_xlg (&port->pcs_xlg, comphy, phy_mode); +mvpp2_port_init_pcs_gmac (&port->pcs_gmac, comphy, phy_mode); + +if (mvpp2_port_supports_xlg (port)) {if (comphy) port->phylink_config.mac_capabilities |=MAC_10000FD |MAC_5000FD ;
@@ -7115,35 +7163,16 @@ static int mvpp2_port_probe(struct platform_device *pdev,MAC_10000FD ; } -if (mvpp2_port_supports_rgmii (port)) { -phy_interface_set_rgmii (port->phylink_config.supported_interfaces); -__set_bit (PHY_INTERFACE_MODE_MII , - port->phylink_config.supported_interfaces); - } +phy_interface_copy (port->phylink_config.pcs_interfaces, + port->pcs_gmac.supported_interfaces); -if (comphy) { -/* If a COMPHY is present, we can support any of the -* serdes modes and switch between them. -*/ -__set_bit (PHY_INTERFACE_MODE_SGMII , - port->phylink_config.supported_interfaces); -__set_bit (PHY_INTERFACE_MODE_1000BASEX , - port->phylink_config.supported_interfaces); -__set_bit (PHY_INTERFACE_MODE_2500BASEX , - port->phylink_config.supported_interfaces); - }else if (phy_mode ==PHY_INTERFACE_MODE_2500BASEX ) { -/* No COMPHY, with only 2500BASE-X mode supported */ -__set_bit (PHY_INTERFACE_MODE_2500BASEX , - port->phylink_config.supported_interfaces); - }else if (phy_mode ==PHY_INTERFACE_MODE_1000BASEX || - phy_mode ==PHY_INTERFACE_MODE_SGMII ) { -/* No COMPHY, we can switch between 1000BASE-X and SGMII -*/ -__set_bit (PHY_INTERFACE_MODE_1000BASEX , - port->phylink_config.supported_interfaces); -__set_bit (PHY_INTERFACE_MODE_SGMII , - port->phylink_config.supported_interfaces); - } +if (mvpp2_port_supports_xlg (port)) +phy_interface_or (port->phylink_config.pcs_interfaces, + port->phylink_config.pcs_interfaces, + port->pcs_xlg.supported_interfaces); + +phy_interface_copy (port->phylink_config.supported_interfaces, + port->phylink_config.pcs_interfaces); phylink =phylink_create (&port->phylink_config, port_fwnode, phy_mode, &mvpp2_phylink_ops);
--
2.55.0
Signature · 1 line
Ansuel
Andrew Lunn
maintainerQuoted 3 lines
I think the most annoying one will be stmmac with the 3 different PCS implementation but we already handled that in a upcoming ipq50xx driver currently present in OpenWrt mainline.
stmmac is always annoying :-(
If this can make it more uniform, make internal and external PCS look the same, that would be great.
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c static void mvpp2_acpi_start(struct mvpp2_port *port) · line 6798
Quoted 9 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +4
-1@@ -6808,7 +6792,10 @@ static void mvpp2_acpi_start(struct mvpp2_port *port) };struct phylink_pcs *pcs; - pcs =mvpp2_select_pcs (&port->phylink_config, port->phy_interface); +if (mvpp2_is_xlg (port->phy_interface)) + pcs = &port->pcs_xlg; +else + pcs = &port->pcs_gmac;
I thought the point of new API was that phylink picked the PCS. Why this if? Why not register both and let phylink pick?
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c static void mvpp2_acpi_start(struct mvpp2_port *port) · line 6823
Quoted 11 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +11
-0+static int mvpp2_port_fill_pcs (struct phylink_config *config, +struct phylink_pcs **available_pcs, +unsigned int num_possible_pcs) +{ +struct mvpp2_port *port =mvpp2_phylink_to_port (config); + + available_pcs[0 ] = &port->pcs_gmac; + +if (mvpp2_port_supports_xlg (port)) { +if (num_possible_pcs <2 ) +return -EINVAL ;
This seems like defensive programming. If we said there was two, we should assume available_pcs has room for two. I would not even pass int num_possible_pcs as a parameter.
Andrew
Quoted 10 lines · Andrew Lunn
Quoted 3 lines
I think the most annoying one will be stmmac with the 3 different PCS implementation but we already handled that in a upcoming ipq50xx driver currently present in OpenWrt mainline.
stmmac is always annoying :-(
If this can make it more uniform, make internal and external PCS look the same, that would be great.
I posted v12 that should smooth stuff even more. I think I found a good way with the notifier approach.
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +0
-0@@ -6808,7 +6792,10 @@ static void mvpp2_acpi_start(struct mvpp2_port *port) };struct phylink_pcs *pcs;
Quoted 9 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c static void mvpp2_acpi_start(struct mvpp2_port *port) · line 6798
Quoted 5 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +4
-1- pcs =mvpp2_select_pcs (&port->phylink_config, port->phy_interface); +if (mvpp2_is_xlg (port->phy_interface)) + pcs = &port->pcs_xlg; +else + pcs = &port->pcs_gmac;I thought the point of new API was that phylink picked the PCS. Why this if? Why not register both and let phylink pick?
Yep I'm not sure of this... If they expose different interface mode then both can be provided at the same time. I think it was done to reduce the logic difference and patch delta to the minimum.
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +7
-0+static int mvpp2_port_fill_pcs (struct phylink_config *config, +struct phylink_pcs **available_pcs, +unsigned int num_possible_pcs) +{ +struct mvpp2_port *port =mvpp2_phylink_to_port (config); + + available_pcs[0 ] = &port->pcs_gmac;
Quoted 9 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c static void mvpp2_acpi_start(struct mvpp2_port *port) · line 6823
Quoted 4 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +4
-0+ +if (mvpp2_port_supports_xlg (port)) { +if (num_possible_pcs <2 ) +return -EINVAL ;This seems like defensive programming. If we said there was two, we should assume
available_pcshas room for two. I would not even pass intnum_possible_pcsas a parameter.
Yes the if is redundant. The phylink core code ALWAYS allocate based on the phylink_config value. The num_possible is just as a validation value of what the space allocated in available_pcs.
If everyone is ok I can change and include this in the series.
Signature · 1 line
Ansuel