net: pcs: Introduce support for fwnode PCS
Subsystems (8)
v23 cover net: pcs: Introduce support for fwnode PCS
This series introduce a most awaited feature that is correctly provide PCS with fwnode without having to use specific export symbol and additional handling of PCS in phylink.
At times there were 2 different implementation (this and the one from Sean) but Sean agreed that this can be picked and used in favor of his implementation as long as his case with race condition is correctly handled.
---
First the PCS fwnode:
The concept is to implement a producer-consumer API similar to other subsystem like clock or PHY.
That seems to be the best solution to the problem as PCS driver needs to be detached from phylink and implement a simple way to provide a PCS while maintaining support for probe defer or driver removal.
To keep the implementation simple, the PCS driver devs needs some collaboration to correctly implement this. This is O.K. as helper to correctly implement this are provided hence it's really a matter of following a pattern to correct follow removal of a PCS driver.
A PCS provider have to implement and call fwnode_pcs_add_provider() in probe function and define an xlate function to define how the PCS should be provided based on the requested interface and phandle spec defined in fwnode (based on the #pcs-cells)
fwnode_pcs_get() is provided to provide a specific PCS declared in fwnode at index.
A simple xlate function is provided for simple single PCS implementation, fwnode_pcs_simple_xlate.
A PCS provider on driver removal must call fwnode_pcs_del_provider() to delete itself as a provider.
---
Second PCS handling in phylink:
We have the PCS problem for the only reason that in initial implementation, we permitted way too much flexibility to MAC driver and things started to deviate. At times we couldn't think SoC would start to put PCS outside the MAC hence it was OK to assume they would live in the same driver. With the introduction of 10g in more consumer devices, we are observing a rapid growth of this pattern with multiple PCS external to MAC.
To put a stop on this, the only solution is to give back to phylink control on PCS handling and enforce more robust supported interface definition from both MAC and PCS side.
This series introduce handling of PCS in phylink and try to deprecate .mac_select_pcs.
Phylink now might contain a linked list of available PCS and those will be used for PCS selection on phylink_major_config.
MAC driver needs to define pcs_interfaces mask in phylink_config for every interface that needs a dedicated PCS.
These PCS needs to be provided to phylink at phylink_create time by setting the .fill_available_pcs and .num_possible_pcs in phylink_config. Helpers to parse PCS from fwnode are provided fwnode_phylink_pcs_count() that will return the count of PCS entries described in the firmware node and fwnode_phylink_pcs_parse() that will fill a preallocated array of PCS pointer with the actual available PCS (ignoring the one that still needs to be probed).
phylink_create() will fill the internal PCS list with the passed array of PCS. phylink_major_config and other user of .mac_select_pcs are adapted to make use of this new PCS list.
The supported interface value is also moved internally to phylink struct. This is to handle late removal and addition of PCS. (the bonus effect to this is giving phylink a clear idea of what is actually supported by the MAC and his constraint with PCS)
The supported interface mask in phylink is done by OR the supported_interfaces in phylink_config with every PCS in PCS list.
PCS removal is supported by forcing a mac_config, refresh the supported interfaces and run a phy_resolve().
PCS late addition is supported by introducing a global notifier for PCS provider. If a phylink have the pcs_interfaces mask not zero, it's registered to this notifier.
PCS provider will emit a global PCS add event to signal any interface that a new PCS might be available.
The function will then check if the PCS is related to the MAC fwnode and add it accordingly.
A user for this new implementation is provided as an Airoha PCS driver. This was also tested downstream with the IPQ95xx QCOM SoC and with the help of Daniel also on the various Mediatek MT7988 SoC with both SFP cage implementation and DSA attached.
Lots of tests were done with driver unbind/bind and with interface up/down also by adding print to make sure major_config_fail gets correctly triggered and reset once the PCS comes back.
The dedicated commits have longer description on the implementation so it's suggested to also check there for additional info.
It's worth to mention that OpenWrt is currently using this on Mediatek SoC and QCOM ipq807x/ipq60xx/ipq50xx and Airoha are already ported in staging tree for testing.
Also realtek is using this and proved to correctly work.
---
Due to the introduction of Sashiko and the introduction of the notifier, a major reorg of the different scenario and capabilities parsing was needed. This is to make the bot happy (in theory, but it never is) and try to improve the state of the code by moving the capabilitis parsing to a centralized place trying to address all the scenario in one place.
---
---
Changes v23:
- Rebase onto net-next at 8b5aba6d328e.
- Wait for RCU readers on teardown even if the active PCS
was already cleared. Share PCS attachment and teardown helpers and serialize ownership changes across phylink instances.
- Validate pcs_interfaces, num_possible_pcs and fill_available_pcs together in phylink_create(). Limit PCS additions to the supported interface mask to modes selected by pcs_interfaces.
- Track provider ownership on first lookup, require stable PCS instances from the xlate callback, use unsigned reference indexes and document lookup errors, RTNL requirements and provider resource lifetime.
- Drop the saved phylink firmware node and fwnode_pcs_get_from_provider(). Rescan with fill_available_pcs() on provider add and remove. Serialize list updates with initialization and teardown, and detach departing PCS synchronously even when a rescan fails.
- Move PCS list and interface helpers into the initial PCS patch. Put in-band capability queries and initial major configuration under the state mutex, and validate an attached PHY with its mutex taken first.
- Add deferred SFP insertion and retry optical module insertion when a PCS becomes available.
- Retain raw SFP capabilities and EEPROM limits during recalculation. Clear cached capabilities after failed insertion, invalidate stale modes after PCS removal and check a replacement PCS's in-band autonegotiation mode. Reconfigure when the SFP signal returns after losing the PCS while the signal was down.
- Track user pause restrictions on links without a PHY. With a PHY, revalidate phylib's current advertisement, retain pause changes across PHY speed down and speed up, and complete EEE clock setup before publishing PHY-derived state.
- Update the PCS documentation for rescans, deferred insertion and advertisement ownership. Update commit descriptions, local variable ordering and networking comment formatting.
v22: https://lore.kernel.org/r/[email protected]/
Changes v22:
- Rebase on top of net-next (no idea why patchwork reported failed to apply...) Changes v21:
- Add fixes tag for the RCU patch
- Preserve user-disabled ethtool advertising during capability updates and SFP interface selection.
- Add additional kconfig select for Airoha PCS and Airoha Ethernet
- Fix wrong rcu_assign_pointer NULL in RCU patch
- Use "pcs-handle-names" as already defined (instead of "pcs-names")
- Skip phylink_pcs_disable if already disabled
- Skip phylink_major_config if phylink disabled
- Better handle capabilites from phylink_parse_mode and phylink_parse_fixedlink
- Set link_failed on late attach so that resolve is triggered 2 times
- Improve description of fwnode_pcs_get_from_provider()
- Improve capabilities tracking for PHY and SFP scenario
- Add variant for __phy_get_rate_matching
Changes v20:
- Fix double declaration error in Documentation
- Drop mutex from patch 8 for validate_mac_and_pcs
- Correctly use non lock version in __phylink_validate
Changes v19:
- Rebase on top of net-next
- RCU protect phylink from pcs struct
- Fix dead-lock on phylink_validate
- Handle possible PCS provider returning NULL (protective coding)
- Improve capabilities handling refresh
Changes v18:
- Improve handling on late PCS addition
- Fix wrong comment on airoha PCS driver
- Rebase on top of net-next
Changes v17:
- Rebase on top of net-next
- Add Review tag for DT patch
- Recalculate capabilities on late removal/attach
Changes v16:
- Rebase on top of net-next
- Add Tested-by tag
- Add ACK for airoha ethernet patch + nit fix
Changes v15:
- Rebase on top of net-next
- Fix Coccicheck warning
Changes v14:
- Fix deadlock when fill_available_pcs fails
- Move notifier and fill down after resolve disable bit is set
- Fix kconfig description
Changes v13:
- Fix regression in fwnode_pcs_get_from_pcsspec from v12
- Fix reverse lock for phy_lock and state_mutex
- Better handle lock in phylink_validate_mac_and_pcs and inband
- Fix wrong pointer to fwnode_pcs_add_provider notifier
- Fix compilation error for new C type in pcs_provider_notify Changes v12:
- Fix kdoc for function
- Rework PCS provider add and delete to be provider driven (instead of relaying on scan of fwnode every time) (this also handle
multi PCS scenario)
- Even further rework state mutex locking for concurrent pcs list
- Restore MAC supported_interfaces validation in phylink_create() wrongly dropped.
- Use get/put for fwnode reference
- Fix possible unment depndency for FWNODE_PCS
- Fix almost impossible problem for PCS calibration
- Hold rtnl with PCS deletion
Changes v11:
- Rework PCS release to notifier way (fix race as pointed out by bot)
- Add Ack from Lorenzo for Airoha Ethernet driver
- Introduce devm variant for pcs_provider_add
- Better support firmware node reference for PCS late attach
- Better protect list iteration with state mutex
- Minor fixup to airoha pcs driver (flow control fixup)
- Rebase on top of net-next
Changes v10:
- Minor code cleanup and fixes as suggested by bot
- Drop devlink patch
- Add reviewed by tag
- Configure old_link_state on PCS release
- Unlink PCS on error in phylink_create()
- Use list_add_tail
- Fix typo in Airoha PCS driver
- Update phylink migration guide
- Better handle late PCS attach (idempotent function and
add unser state_mutex)
- Use dedicated lock in Airoha ethernet driver
Changes v9:
- Rebase on top of net-next/main
- Drop early verification of supported_interface
(it can also be provided by get_capabilites MAC OP)
Changes v8:
- Back to RFC (net-next closed)
- Address additional bug reported by Sashiko bot
- Better handle priv interface for Airoha PCS driver
- Better handle locking for modifying the PCS list in
phylink code
- Improve fwnode_phylink_pcs_parse() parsing on -ENOENT
- Better handle error condition in phylink_create()
- Turn down the link when current PCS is released
- Fix compilation warning caused by copy paste error
Changes v7:
- Address all the bug from the Sashiko bot
- Rename .num_available_pcs to .num_possible_pcs
- Link PCS in phylink_create()
- Correctly unregister the notifier on phylink_destroy()
- Introduce fwnode_phylink_pcs_count()
- Better handle locking in phylink for PCS handling
- Better handle unavailable PCS at phylink_create() time
- Improve Documentation file
- Other minor fixes to address suggestion from bot
- Rebase on top of net-next
Changes v6:
- Rebase on top of net-next
- Add Documentation files
- Add fw_devlink patch
- Fix some comments typo
- Rework the airoha_eth.c implementation with new multi serdes code
- Extend PCS code with PCIe and USB support
- Align schema to new property
Changes v5:
- Rebase on top of net-next
- Use the new force_major_config
- Reword some comments and commit description
- Return -ENODEV instead of -EPROBE_DEFER to perevent race condition
- Drop phy_interface_copy patch (Russell pushed an equivalent version) Changes v4:
- Move patch 0002 phy_interface_copy to 0002 (fix bisectability problem)
- Address review from Lorenzo for Airoha ethernet driver
- Fix kdoc error with missing Return (actually missing : before Return)
- Fix UNMET dependency reported error for CONFIG_FWNODE_PCS
- Revert to pcs.c instead of core.c (due to name conflict with other kmod)
- Fix clang compilation error for Airoha PCS driver
- Add missing inline function to pcs.h function
Changes v3:
- Out of RFC
- Fix various spelling mistake
- Drop circular dependency patch
- Complete Airoha Ethernet phylink integration
- Introduce .pcs_link_down PCS OP
Changes v2:
- Switch to fwnode
- Implement PCS provider notifier
- Better split changes
- Move supported_interfaces to phylink
- Add circular dependency patch
- Rework handling with indirect addition/removal and
trigger of phylink_resolve()
Christian Marangi (15):
net: phylink: make PCS phylink instance access RCU protected
net: phylink: keep and use MAC supported_interfaces in phylink struct
net: phylink: introduce internal phylink PCS handling
net: pcs: implement Firmware node support for PCS driver
net: phylink: make phylink_validate state locked
net: phylink: add capabilities helpers and track modified advertising
net: sfp: support deferred module insertion
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 | 257 ++ Documentation/networking/sfp-phylink.rst | 35 +- MAINTAINERS | 9 + drivers/net/ethernet/airoha/Kconfig | 2 + drivers/net/ethernet/airoha/airoha_eth.c | 197 +- drivers/net/ethernet/airoha/airoha_eth.h | 5 + drivers/net/ethernet/airoha/airoha_regs.h | 12 + drivers/net/pcs/Kconfig | 8 + drivers/net/pcs/Makefile | 3 + drivers/net/pcs/airoha/Kconfig | 17 + drivers/net/pcs/airoha/Makefile | 7 + drivers/net/pcs/airoha/pcs-airoha-common.c | 1312 ++++++++++ drivers/net/pcs/airoha/pcs-airoha.h | 1311 ++++++++++ drivers/net/pcs/airoha/pcs-an7581.c | 2115 +++++++++++++++++ drivers/net/pcs/pcs.c | 314 +++ drivers/net/phy/phy-internal.h | 22 + drivers/net/phy/phy.c | 11 +- drivers/net/phy/phy_device.c | 8 +- drivers/net/phy/phylink.c | 1498 +++++++++--- drivers/net/phy/sfp-bus.c | 16 + drivers/net/phy/sfp.c | 17 + drivers/net/phy/sfp.h | 1 + include/linux/pcs/pcs-provider.h | 88 + include/linux/pcs/pcs.h | 142 ++ include/linux/phylink.h | 33 +- include/linux/sfp.h | 10 +- 28 files changed, 7346 insertions(+), 366 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml create mode 100644 Documentation/networking/pcs.rst create mode 100644 drivers/net/pcs/airoha/Kconfig create mode 100644 drivers/net/pcs/airoha/Makefile create mode 100644 drivers/net/pcs/airoha/pcs-airoha-common.c create mode 100644 drivers/net/pcs/airoha/pcs-airoha.h create mode 100644 drivers/net/pcs/airoha/pcs-an7581.c create mode 100644 drivers/net/pcs/pcs.c create mode 100644 drivers/net/phy/phy-internal.h create mode 100644 include/linux/pcs/pcs-provider.h create mode 100644 include/linux/pcs/pcs.h
Signature · 1 line
2.55.0
PATCH v23 1/15 net: phylink: make PCS phylink instance access RCU protected
In the context of phylink_pcs_change(), phylink instance is dereferenced from the pcs pointer present in the phylink_pcs struct.
There is currently a fragility where this pcs pointer is never set NULL in phylink_destroy() and would reference invalid memory after phylink instance is freed.
In this scenario, if a PCS driver calls phylink_pcs_change(), invalid memory can be dereferenced and phylink_link_changed() is called on freed memory.
To address this, make the phylink pointer saved in phylink_pcs struct RCU protected and access it under an RCU read lock. Use rcu_assign_pointer() to update the pointer in phylink_major_config().
Also correctly reset the phylink instance pointer on phylink_destroy() and unconditionally synchronize RCU to wait for any in-flight phylink_pcs_change() calls, even if phylink_major_config() already cleared the association.
--- drivers/net/phy/phylink.c | 22 +++++++++++++++++++--- include/linux/phylink.h | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-)
drivers/net/phy/phylink.c +19 -3
@@ -17,6 +17,7 @@#include <linux/phy_link_topology.h> #include <linux/phy_port.h> #include <linux/phylink.h> +#include <linux/rcupdate.h> #include <linux/rtnetlink.h> #include <linux/spinlock.h> #include <linux/timer.h>
@@ -1295,10 +1296,10 @@ static void phylink_major_config(struct phylink *pl, bool restart,phylink_pcs_disable (pl->pcs);if (pl->pcs) - pl->pcs->phylink =NULL ; +rcu_assign_pointer (pl->pcs->phylink,NULL );if (pcs) - pcs->phylink = pl; +rcu_assign_pointer (pcs->phylink, pl); pl->pcs = pcs; }
@@ -2157,6 +2158,16 @@ void phylink_destroy(struct phylink *pl)if (pl->link_gpio)gpiod_put (pl->link_gpio); +if (pl->pcs) +rcu_assign_pointer (pl->pcs->phylink,NULL ); + +/* +* Unconditionally wait for readers that may have obtained this +* phylink through a PCS while phylink_major_config() was clearing +* the association. +*/ +synchronize_rcu (); +cancel_work_sync (&pl->resolve);kfree (pl); }
@@ -2621,10 +2632,15 @@ EXPORT_SYMBOL_GPL(phylink_mac_change);*/ void phylink_pcs_change (struct phylink_pcs *pcs,bool up) { -struct phylink *pl = pcs->phylink; +struct phylink *pl; +rcu_read_lock (); + + pl =rcu_dereference (pcs->phylink);if (pl)phylink_link_changed (pl, up,"pcs" ); + +rcu_read_unlock (); }EXPORT_SYMBOL_GPL (phylink_pcs_change);
include/linux/phylink.h +1 -1
@@ -494,7 +494,7 @@ struct phylink_pcs_ops;struct phylink_pcs {DECLARE_PHY_INTERFACE_MASK (supported_interfaces);const struct phylink_pcs_ops *ops; -struct phylink *phylink; +struct phylink __rcu *phylink;bool poll;bool rxc_always_on; };
Signature · 1 line
2.55.0
PATCH v23 2/15 net: phylink: keep and use MAC supported_interfaces in phylink struct
In reply to Christian MarangiAdd 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 | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/net/phy/phylink.c +17 -8
@@ -63,6 +63,12 @@ struct phylink {/* The link configuration settings */ struct phylink_link_state link_config; +/* +* What interface are supported by the current link. +* Can change on removal or addition of new PCS. +*/ +DECLARE_PHY_INTERFACE_MASK (supported_interfaces); +/* The current settings */ phy_interface_t cur_interface;
@@ -633,7 +639,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,
@@ -1808,7 +1814,7 @@ static int phylink_create_sfp_cage_port(struct phylink *pl) port->is_mii = true; port->active = true; -phy_interface_and (port->interfaces, pl->config->supported_interfaces, +phy_interface_and (port->interfaces, pl->supported_interfaces, phylink_sfp_interfaces);phy_port_update_supported (port);
@@ -2111,6 +2117,9 @@ struct phylink *phylink_create(struct phylink_config *config,__set_bit (PHYLINK_DISABLE_STOPPED , &pl->phylink_disable_state);timer_setup (&pl->link_poll, phylink_fixed_poll,0 ); +phy_interface_copy (pl->supported_interfaces, + pl->config->supported_interfaces); +linkmode_fill (pl->supported);linkmode_copy (pl->link_config.advertising, pl->supported);phylink_validate (pl, pl->supported, &pl->link_config);
@@ -2243,7 +2252,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" );
@@ -3062,12 +3071,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 ; }
@@ -3946,14 +3955,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" );
@@ -4191,7 +4200,7 @@ static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy)/* Set the PHY's host supported interfaces */ phy_interface_and (phy->host_interfaces, phylink_sfp_interfaces, - pl->config->supported_interfaces); + pl->supported_interfaces);phy_set_upstream_port (phy, pl->sfp_cage_port);
Signature · 1 line
2.55.0
PATCH v23 3/15 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_interfaces bitmap in the PCS struct.
A MAC using internal PCS handling should provide a callback to fill the available PCS in .fill_available_pcs in phylink_config and set .num_possible_pcs to the number of elements in the array. The MAC should also define a new bitmap, pcs_interfaces, in phylink_config to define which interface modes require a dedicated PCS.
In phylink_create(), when .num_possible_pcs is nonzero, an array of PCS pointers is allocated with .num_possible_pcs entries and .fill_available_pcs is called with the phylink_config, the array and its size.
The MAC will fill this array with pointers to the available PCS.
This array is then parsed and a linked list of PCS is created based on the allocated PCS array filled by the MAC via .fill_available_pcs(), skipping empty entries and PCS instances that are already attached.
Link each PCS to its phylink instance with rcu_assign_pointer(). Use a global mutex to serialize the ownership check and updates across phylink instances. Rebuild phylink's supported_interfaces from the MAC bitmap and the PCS modes that are also set in pcs_interfaces.
Share PCS teardown between phylink_destroy() and the phylink_create() error path. Clear the PCS associations, unlink the list entries and wait for an RCU grace period before freeing phylink.
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.
For interface modes set in pcs_interfaces, they walk the list and use phylink_validate_pcs_interface() to find the first PCS that supports the requested interface. phylink_major_config() fails if it cannot find a PCS for that interface.
phylink_validate_pcs_interface() applies the same validation previously used for a PCS returned by .mac_select_pcs. An empty supported_interfaces bitmap in the PCS struct means that all interfaces are supported.
A MAC using the PCS list must set pcs_interfaces, .num_possible_pcs and .fill_available_pcs together. phylink_create() returns -EINVAL if the configuration is incomplete or if the PCS list is combined with .mac_select_pcs.
The phylink pointer in struct phylink_pcs tracks when a PCS is attached to a phylink instance. With internal PCS handling, the pointer stays set while the PCS is on the list, even when another PCS is selected.
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 | 259 +++++++++++++++++++++++++++++++++----- include/linux/phylink.h | 16 +++ 2 files changed, 244 insertions(+), 31 deletions(-)
drivers/net/phy/phylink.c +228 -31
@@ -27,6 +27,9 @@#include "sfp.h" #include "swphy.h" +/* Serializes changes to PCS list ownership across phylink instances */ +static DEFINE_MUTEX (phylink_pcs_ownership_mutex); +enum {PHYLINK_DISABLE_STOPPED ,PHYLINK_DISABLE_LINK ,
@@ -63,6 +66,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.
@@ -523,6 +529,23 @@ 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)
@@ -536,6 +559,21 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl, pcs = pl->mac_ops->mac_select_pcs (pl->config, state->interface);if (IS_ERR (pcs))return PTR_ERR (pcs); +/* +* Find a PCS in available PCS list for the requested interface. +* +* Skip searching if the MAC doesn't require a dedicated PCS for +* the requested interface. +*/ + }else if (test_bit (state->interface, pl->config->pcs_interfaces)) { +struct phylink_pcs *tmp; + +list_for_each_entry (tmp, &pl->pcs_list, list) { +if (!phylink_validate_pcs_interface (tmp, state->interface)) { + pcs = tmp; +break ; + } + } }if (pcs) {
@@ -550,13 +588,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 ; }
@@ -969,12 +1004,22 @@ static void phylink_pcs_enable_eee(struct phylink_pcs *pcs)static unsigned int phylink_inband_caps (struct phylink *pl,phy_interface_t interface) { -struct phylink_pcs *pcs; +struct phylink_pcs *pcs =NULL ; -if (!pl->mac_ops->mac_select_pcs) -return 0 ; +if (pl->mac_ops->mac_select_pcs) { + pcs = pl->mac_ops->mac_select_pcs (pl->config, + interface); + }else if (test_bit (interface, pl->config->pcs_interfaces)) { +struct phylink_pcs *tmp; + +list_for_each_entry (tmp, &pl->pcs_list, list) { +if (!phylink_validate_pcs_interface (tmp, interface)) { + pcs = tmp; +break ; + } + } + } - pcs = pl->mac_ops->mac_select_pcs (pl->config, interface);if (IS_ERR_OR_NULL (pcs))return 0 ;
@@ -1271,10 +1316,37 @@ static void phylink_major_config(struct phylink *pl, bool restart, pl->major_config_failed = true;return ; } +/* +* Find a PCS in available PCS list for the requested interface. +* This doesn't overwrite the previous .mac_select_pcs as either +* .mac_select_pcs or PCS list implementation are permitted. +* +* Skip searching if the MAC doesn't require a dedicated PCS for +* the requested interface. +*/ + }else if (test_bit (state->interface, pl->config->pcs_interfaces)) { +struct phylink_pcs *tmp; + +list_for_each_entry (tmp, &pl->pcs_list, list) { +if (!phylink_validate_pcs_interface (tmp, + state->interface)) { + pcs = tmp; +break ; + } + } + +if (!pcs) { +phylink_err (pl, +"couldn't find a PCS for %s\n" , +phy_modes (state->interface)); - pcs_changed = pl->pcs != pcs; + pl->major_config_failed = true; +return ; + } } + pcs_changed = pl->pcs != pcs; +phylink_pcs_neg_mode (pl, pcs, state->interface, state->advertising); phylink_dbg(pl, "major config, active %s/%s/%s\n",
@@ -1301,13 +1373,15 @@ static void phylink_major_config(struct phylink *pl, bool restart,if (pcs_changed) {phylink_pcs_disable (pl->pcs); -if (pl->pcs) -rcu_assign_pointer (pl->pcs->phylink,NULL ); +if (pl->mac_ops->mac_select_pcs) { +if (pl->pcs) +rcu_assign_pointer (pl->pcs->phylink,NULL ); -if (pcs) -rcu_assign_pointer (pcs->phylink, pl); +if (pcs) +rcu_assign_pointer (pcs->phylink, pl); + } - pl->pcs = pcs; +WRITE_ONCE (pl->pcs, pcs); }if (pl->pcs)
@@ -1922,6 +1996,58 @@ int phylink_set_fixed_link(struct phylink *pl, }EXPORT_SYMBOL_GPL (phylink_set_fixed_link); +static bool phylink_add_pcs (struct phylink *pl,struct phylink_pcs *pcs) +{ +struct phylink *owner; +bool added = false; + +if (!pcs) +return false; + +mutex_lock (&phylink_pcs_ownership_mutex); + owner =rcu_access_pointer (pcs->phylink); +if (owner == pl) + goto out; + +if (WARN (owner,"%s: PCS already attached to a phylink instance\n" , + __func__)) + goto out; + +list_add_tail (&pcs->list, &pl->pcs_list); +rcu_assign_pointer (pcs->phylink, pl); + added = true; + +out: +mutex_unlock (&phylink_pcs_ownership_mutex); +return added; +} + +static int phylink_fill_available_pcs (struct phylink *pl, +struct phylink_config *config) +{ +struct phylink_pcs **pcss; +int i, ret; + +if (!config->num_possible_pcs) +return 0 ; + + pcss =kzalloc_objs (*pcss, config->num_possible_pcs); +if (!pcss) +return -ENOMEM ; + + ret = config->fill_available_pcs (config, pcss, config->num_possible_pcs); +if (ret <0 ) + goto out; + +for (i =0 ; i < config->num_possible_pcs; i++) +phylink_add_pcs (pl, pcss[i]); + +out: +kfree (pcss); + +return ret; +} +/** * phylink_update_pause_state() - Update the phylink pause frame configuration * @pl: a pointer to a &struct phylink instance
@@ -2042,6 +2168,62 @@ void phylink_update_mac_pause_capabilities(struct phylink *pl, unsigned long mac }EXPORT_SYMBOL_GPL (phylink_update_mac_pause_capabilities); +static void phylink_parse_supported_interfaces (struct phylink *pl) +{ +struct phylink_pcs *pcs; + +phy_interface_copy (pl->supported_interfaces, + pl->config->supported_interfaces); + +/* +* Only add PCS-supported modes that phylink will select a PCS for. +* Otherwise, phylink may accept a PCS-only mode and configure it without +* a PCS. +*/ +list_for_each_entry (pcs, &pl->pcs_list, list) { +DECLARE_PHY_INTERFACE_MASK (pcs_interfaces); + +phy_interface_copy (pcs_interfaces, pl->config->pcs_interfaces); + +if (!phy_interface_empty (pcs->supported_interfaces)) +phy_interface_and (pcs_interfaces, pcs_interfaces, + pcs->supported_interfaces); + +phy_interface_or (pl->supported_interfaces, + pl->supported_interfaces, + pcs_interfaces); + } +} + +static void phylink_detach_pcss (struct phylink *pl) +{ +struct phylink_pcs *pcs, *tmp; + +mutex_lock (&pl->state_mutex); + +mutex_lock (&phylink_pcs_ownership_mutex); +/* Remove every PCS from phylink PCS list */ +list_for_each_entry_safe (pcs, tmp, &pl->pcs_list, list) { +rcu_assign_pointer (pcs->phylink,NULL ); +list_del (&pcs->list); + } + +if (pl->pcs) { +rcu_assign_pointer (pl->pcs->phylink,NULL ); +WRITE_ONCE (pl->pcs,NULL ); + } +mutex_unlock (&phylink_pcs_ownership_mutex); + +/* +* Unconditionally wait for readers that may have obtained this +* phylink through a PCS while phylink_major_config() was clearing +* the association. +*/ +synchronize_rcu (); + +mutex_unlock (&pl->state_mutex); +} +/** * phylink_create() - create a phylink instance * @config: a pointer to the target &struct phylink_config
@@ -2063,9 +2245,25 @@ struct phylink *phylink_create(struct phylink_config *config,phy_interface_t iface, const struct phylink_mac_ops *mac_ops) { + bool has_pcs_interfaces = !phy_interface_empty(config->pcs_interfaces); +bool has_pcs_callback = config->fill_available_pcs; +bool has_pcs_count = config->num_possible_pcs >0 ;struct phylink *pl;int ret; +if (has_pcs_interfaces != has_pcs_callback || + has_pcs_interfaces != has_pcs_count) { +dev_err (config->dev, +"phylink: error: pcs_interfaces, num_possible_pcs and fill_available_pcs must be set together\n" ); +return ERR_PTR (-EINVAL ); + } + +if (mac_ops->mac_select_pcs && has_pcs_interfaces) { +dev_err (config->dev, +"phylink: error: either phylink_config .mac_select_pcs or pcs_interfaces must be used\n" ); +return ERR_PTR (-EINVAL ); + } +/* Validate the supplied configuration */ if (phy_interface_empty (config->supported_interfaces)) { dev_err(config->dev,
@@ -2080,6 +2278,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 ) {
@@ -2117,8 +2316,12 @@ struct phylink *phylink_create(struct phylink_config *config,__set_bit (PHYLINK_DISABLE_STOPPED , &pl->phylink_disable_state);timer_setup (&pl->link_poll, phylink_fixed_poll,0 ); -phy_interface_copy (pl->supported_interfaces, - pl->config->supported_interfaces); +/* Fill the PCS list with available PCS from phylink config */ + ret =phylink_fill_available_pcs (pl, config); +if (ret <0 ) + goto free_pl; + +phylink_parse_supported_interfaces (pl);linkmode_fill (pl->supported);linkmode_copy (pl->link_config.advertising, pl->supported);
@@ -2126,7 +2329,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);
@@ -2145,6 +2348,8 @@ struct phylink *phylink_create(struct phylink_config *config, release_link_gpio:if (pl->link_gpio)gpiod_put (pl->link_gpio); +unlink_pcs_list: +phylink_detach_pcss (pl); free_pl:kfree (pl);return ERR_PTR (ret);
@@ -2167,17 +2372,9 @@ void phylink_destroy(struct phylink *pl)if (pl->link_gpio)gpiod_put (pl->link_gpio); -if (pl->pcs) -rcu_assign_pointer (pl->pcs->phylink,NULL ); - -/* -* Unconditionally wait for readers that may have obtained this -* phylink through a PCS while phylink_major_config() was clearing -* the association. -*/ -synchronize_rcu (); - +phylink_detach_pcss (pl);cancel_work_sync (&pl->resolve); +kfree (pl); }EXPORT_SYMBOL_GPL (phylink_destroy);
@@ -2646,7 +2843,7 @@ void phylink_pcs_change(struct phylink_pcs *pcs, bool up)rcu_read_lock (); pl =rcu_dereference (pcs->phylink); -if (pl) +if (pl &&READ_ONCE (pl->pcs) == pcs)phylink_link_changed (pl, up,"pcs" );rcu_read_unlock ();
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 __rcu *phylink;bool poll;bool rxc_always_on; + +/* private: */ +struct list_head list; };/**
Signature · 1 line
2.55.0
PATCH v23 4/15 net: pcs: implement Firmware node support for PCS driver
In reply to Christian MarangiImplement the foundation of firmware node support for PCS drivers.
To support this, implement a simple provider API where a PCS driver can expose multiple PCS with a fwnode_xlate callback.
The PCS driver calls fwnode_pcs_add_provider() and passes the firmware node pointer, an xlate function and context data. The xlate function returns the appropriate PCS for the firmware reference and its #pcs-cells arguments. It must return the same preallocated PCS for a given reference and arguments, and the PCS must remain valid until the provider is removed.
This registers the provider in a global list so that consumers can access its PCS. The first successful lookup associates the PCS with its provider.
The consumer uses fwnode_pcs_get() to get the actual PCS by passing the consumer's firmware node pointer and the index in the "pcs-handle" property. The lookup returns -ENODEV if no provider supplies a PCS for that reference.
For a simple implementation where #pcs-cells is 0 and the PCS driver exposes a single PCS, the xlate function fwnode_pcs_simple_xlate() is provided.
For an advanced implementation, a custom xlate function is required.
On removal, the PCS driver calls fwnode_pcs_del_provider() to remove an unmanaged provider from the provider list and clear its association with its PCS.
A devm variant, devm_fwnode_pcs_add_provider(), is provided to automate the release procedure.
Generic functions fwnode_phylink_pcs_count() and fwnode_phylink_pcs_parse() are provided for MAC drivers that declare PCS in DT or ACPI.
Function fwnode_phylink_pcs_count() parses the "pcs-handle" property and returns the number of PCS references in the passed firmware node, regardless of whether the corresponding PCS are available.
Function fwnode_phylink_pcs_parse() parses up to num_pcs entries in the "pcs-handle" property, fills the passed available_pcs array with the PCS it finds and returns the number stored. It skips lookups that return -ENODEV, stops at -ENOENT and propagates other lookup errors. It returns -ENODEV if the "pcs-handle" property is absent.
--- drivers/net/pcs/Kconfig | 6 + drivers/net/pcs/Makefile | 1 + drivers/net/pcs/pcs.c | 279 +++++++++++++++++++++++++++++++ include/linux/pcs/pcs-provider.h | 72 ++++++++ include/linux/pcs/pcs.h | 74 ++++++++ include/linux/phylink.h | 3 + 6 files changed, 435 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 || COMPILE_TEST + help + Firmware node PCS accessors + config PCS_XPCS tristate "Synopsys DesignWare Ethernet XPCS" select PHYLINK
drivers/net/pcs/Makefile +1 -0
@@ -3,6 +3,7 @@ pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-nxp.o pcs-xpcs-wx.o +obj-$(CONFIG_FWNODE_PCS) += pcs.o obj-$(CONFIG_PCS_XPCS) += pcs_xpcs.o obj-$(CONFIG_PCS_XPCS_PLATFORM) += pcs-xpcs-plat.o obj-$(CONFIG_PCS_XPCS_ROCKCHIP) += pcs-xpcs-rk.o
drivers/net/pcs/pcs.c new file +279 -0
279 lines not on this page · raw message
include/linux/pcs/pcs-provider.h new file +72 -0
72 lines not on this page · raw message
include/linux/pcs/pcs.h new file +74 -0
74 lines not on this page · raw message
include/linux/phylink.h +3 -0
@@ -10,6 +10,7 @@struct device_node ;struct ethtool_cmd ;struct fwnode_handle ; +struct fwnode_pcs_provider ;struct net_device ;struct phylink ;struct phylink_pcs ;
@@ -513,6 +514,8 @@ struct phylink_pcs {/* private: */ struct list_head list; +struct fwnode_pcs_provider *provider; +struct list_head provider_list; };/**
Signature · 1 line
2.55.0
PATCH v23 5/15 net: phylink: make phylink_validate state locked
In reply to Christian MarangiIn preparation for support for PCS release and late attach, rework the phylink validation functions to run under the state mutex.
The PCS notifier can recalculate supported interfaces and capabilities while phylink_create() or interface mode validation is running. Validation can then see inconsistent state.
To handle this, make phylink_validate() and phylink_validate_mask() take the phylink state mutex. Add __phylink_validate() and __phylink_validate_mask() for callers that already hold the mutex, and add lockdep assertions to the inner validation functions.
Update phylink_update_mac_pause_capabilities() to use __phylink_validate() since it already holds the state mutex.
Take the state mutex when querying PCS in-band capabilities and when applying the initial major configuration.
When validating an attached PHY, take the PHY mutex before the state mutex and call __phylink_validate_phy(). Add __phy_get_rate_matching() in phy-internal.h for callers that already hold the PHY mutex. phy_get_rate_matching() takes that mutex before calling the same helper.
--- drivers/net/phy/phy-internal.h | 22 +++ drivers/net/phy/phy.c | 11 +- drivers/net/phy/phylink.c | 238 ++++++++++++++++++++------------- 3 files changed, 175 insertions(+), 96 deletions(-) create mode 100644 drivers/net/phy/phy-internal.h
drivers/net/phy/phy-internal.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __PHY_INTERNAL_H +#define __PHY_INTERNAL_H + +#include <linux/lockdep.h> +#include <linux/phy.h> + +static inline int __phy_get_rate_matching (struct phy_device *phydev, +phy_interface_t iface) +{ +int ret =RATE_MATCH_NONE ; + +lockdep_assert_held (&phydev->lock); + +if (phydev->drv->get_rate_matching) +return phydev->drv->get_rate_matching (phydev, iface); + +return ret; +} + +#endif /* __PHY_INTERNAL_H */
drivers/net/phy/phy.c +5 -6
@@ -38,6 +38,7 @@#include "phylib-internal.h" #include "phy-caps.h" +#include "phy-internal.h" #define PHY_STATE_TIME HZ
@@ -146,13 +147,11 @@ EXPORT_SYMBOL(phy_print_status);int phy_get_rate_matching (struct phy_device *phydev,phy_interface_t iface) { -int ret =RATE_MATCH_NONE ; +int ret; -if (phydev->drv->get_rate_matching) { -mutex_lock (&phydev->lock); - ret = phydev->drv->get_rate_matching (phydev, iface); -mutex_unlock (&phydev->lock); - } +mutex_lock (&phydev->lock); + ret =__phy_get_rate_matching (phydev, iface); +mutex_unlock (&phydev->lock);return ret; }
drivers/net/phy/phylink.c +148 -90
363 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v23 6/15 net: phylink: add capabilities helpers and track modified advertising
In reply to Christian MarangiIn preparation for PCS release and late attach, introduce helpers to recalculate capabilities when a PCS is removed or added and track which advertising modes the user has disabled.
To achieve this, add advertising and user_disabled_advertising masks to struct phylink. The advertising mask holds the full validated advertisement before applying the phylink user restrictions. The user_disabled_advertising mask records the modes the user has disabled.
Without an attached PHY, phylink_update_user_disabled_advertising() uses the ethtool link settings request captured before interface-specific validation. It preserves restrictions for modes absent from the current full advertisement so they survive PCS removal and late attach. User-requested pause changes also update the Pause and Asym_Pause bits in the mask.
phylink_update_capabilities() recalculates the supported modes and the full advertisement. For links without a PHY, it applies the user-disabled mask when updating link_config.advertising.
phylink_create() initializes pl->advertising and link_config.advertising and uses phylink_update_capabilities() for initial validation.
phylink_update_mac_pause_capabilities() uses the same helper and keeps the user-disabled mask intact when updating the pause state.
Factor out the fixed-link, in-band, PHY and SFP capability calculations so they can be reused after the initial link configuration.
For optical SFPs, keep the module's original interface and link-mode masks. Derive sfp_interfaces from the module mask and current phylink support. Validate a copy of sfp_support and pass the restricted mask to phylink_sfp_set_config(). Clear cached module capabilities if insertion fails. Apply the user-disabled mask during interface selection and clear it when the SFP module is removed.
For PHYs, validate the advertisement currently applied by phylib. During PHY bringup, complete EEE clock setup before committing the PHY-derived link state and restrict the initial PHY advertisement to the validated modes.
Update phy_set_asym_pause() under the PHY mutex and apply the new pause settings to the advertisement saved by speed down so they are retained at speed up.
--- drivers/net/phy/phy_device.c | 8 +- drivers/net/phy/phylink.c | 590 +++++++++++++++++++++++------------ 2 files changed, 403 insertions(+), 195 deletions(-)
drivers/net/phy/phy_device.c +7 -1
@@ -3137,12 +3137,18 @@ void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx) {__ETHTOOL_DECLARE_LINK_MODE_MASK (oldadv); +mutex_lock (&phydev->lock);linkmode_copy (oldadv, phydev->advertising);linkmode_set_pause (phydev->advertising, tx, rx); +/* Keep the new pause settings in the advertisement saved by speed down */ +if (!linkmode_empty (phydev->adv_old)) +linkmode_set_pause (phydev->adv_old, tx, rx); +if (!linkmode_equal (oldadv, phydev->advertising) && phydev->autoneg) -phy_start_aneg (phydev); +_phy_start_aneg (phydev); +mutex_unlock (&phydev->lock); }EXPORT_SYMBOL (phy_set_asym_pause);
drivers/net/phy/phylink.c +396 -194
874 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v23 7/15 net: sfp: support deferred module insertion
In reply to Christian MarangiAdd support for deferring SFP module insertion when the upstream device needs a dependency that is not yet available. If module_insert() returns -EAGAIN, keep the module in SFP_MOD_WAITDEV with its transmitter disabled. Other insertion errors still move the module to SFP_MOD_ERROR.
Add sfp_upstream_retry_module() to let the upstream retry insertion once the dependency becomes available. A successful retry continues through the normal module power and link startup sequence.
This is needed by phylink when an optical SFP is inserted before the PCS provider for its host interface registers.
--- drivers/net/phy/sfp-bus.c | 16 ++++++++++++++++ drivers/net/phy/sfp.c | 17 +++++++++++++++++ drivers/net/phy/sfp.h | 1 + include/linux/sfp.h | 10 ++++++++-- 4 files changed, 42 insertions(+), 2 deletions(-)
drivers/net/phy/sfp-bus.c +16 -0
@@ -563,6 +563,22 @@ void sfp_upstream_stop(struct sfp_bus *bus) }EXPORT_SYMBOL_GPL (sfp_upstream_stop); +/** +* sfp_upstream_retry_module() - Retry deferred module insertion +* @bus: a pointer to the &struct sfp_bus for the module +* +* Ask the socket to retry insertion of a module whose upstream +* module_insert() callback returned -EAGAIN. Call with RTNL held. +*/ +void sfp_upstream_retry_module (struct sfp_bus *bus) +{ +ASSERT_RTNL (); + +if (bus->registered && bus->socket_ops->retry_module) + bus->socket_ops->retry_module (bus->sfp); +} +EXPORT_SYMBOL_GPL (sfp_upstream_retry_module); +static void sfp_upstream_clear (struct sfp_bus *bus) { bus->upstream_ops =NULL ;
drivers/net/phy/sfp.c +17 -0
@@ -43,6 +43,7 @@ enum {SFP_E_DEV_DETACH ,SFP_E_DEV_DOWN ,SFP_E_DEV_UP , +SFP_E_UPSTREAM_RETRY ,SFP_E_TX_FAULT ,SFP_E_TX_CLEAR , SFP_E_LOS_HIGH,
@@ -111,6 +112,7 @@ static const char * const event_strings[] = { [SFP_E_DEV_DETACH] = "dev_detach", [SFP_E_DEV_DOWN] = "dev_down", [SFP_E_DEV_UP] = "dev_up", + [SFP_E_UPSTREAM_RETRY] = "upstream_retry", [SFP_E_TX_FAULT] = "tx_fault", [SFP_E_TX_CLEAR] = "tx_clear", [SFP_E_LOS_HIGH] = "los_high",
@@ -2823,6 +2825,10 @@ static void sfp_sm_module(struct sfp *sfp, unsigned int event)sfp_sm_mod_next (sfp,SFP_MOD_WAITDEV ,0 ); fallthrough;case SFP_MOD_WAITDEV : +if (event !=SFP_E_TIMEOUT && event !=SFP_E_DEV_ATTACH && + event !=SFP_E_UPSTREAM_RETRY ) +break ; +/* Ensure that the device is attached before proceeding */ if (sfp->sm_dev_state <SFP_DEV_DOWN )break ;
@@ -2830,6 +2836,8 @@ static void sfp_sm_module(struct sfp *sfp, unsigned int event)/* Report the module insertion to the upstream device */ err =sfp_module_insert (sfp->sfp_bus, &sfp->id, sfp->quirk); +if (err == -EAGAIN ) +break ;if (err <0 ) {sfp_sm_mod_next (sfp,SFP_MOD_ERROR ,0 );break ;
@@ -3091,6 +3099,14 @@ static void sfp_stop(struct sfp *sfp)sfp_sm_event (sfp,SFP_E_DEV_DOWN ); } +static void sfp_retry_module (struct sfp *sfp) +{ +mutex_lock (&sfp->sm_mutex); +if (sfp->sm_mod_state ==SFP_MOD_WAITDEV ) +__sfp_sm_event (sfp,SFP_E_UPSTREAM_RETRY ); +mutex_unlock (&sfp->sm_mutex); +} +static void sfp_set_signal_rate (struct sfp *sfp,unsigned int rate_kbd) {unsigned int set;
@@ -3189,6 +3205,7 @@ static const struct sfp_socket_ops sfp_module_ops = { .detach = sfp_detach, .start = sfp_start, .stop = sfp_stop, + .retry_module = sfp_retry_module, .set_signal_rate = sfp_set_signal_rate, .module_info = sfp_module_info, .module_eeprom = sfp_module_eeprom,
drivers/net/phy/sfp.h +1 -0
@@ -20,6 +20,7 @@ struct sfp_socket_ops {void (*detach)(struct sfp *sfp);void (*start)(struct sfp *sfp);void (*stop)(struct sfp *sfp); +void (*retry_module)(struct sfp *sfp);void (*set_signal_rate)(struct sfp *sfp,unsigned int rate_kbd);int (*module_info)(struct sfp *sfp,struct ethtool_modinfo *modinfo); int (*module_eeprom)(struct sfp *sfp, struct ethtool_eeprom *ee,
include/linux/sfp.h +8 -2
@@ -550,8 +550,9 @@ struct sfp_module_caps {* @detach: called when the sfp socket driver is unbound from the upstream * (mandatory). * @module_insert: called after a module has been detected to determine -* whether the module is supported for the upstream device. -* @module_remove: called after the module has been removed. +* whether the module is supported for the upstream device. Return +* -EAGAIN to defer insertion until sfp_upstream_retry_module() is called. +* @module_remove: called after a successfully inserted module is removed. * @module_start: called after the PHY probe step * @module_stop: called before the PHY is removed * @link_down: called when the link is non-operational for whatever
@@ -588,6 +589,7 @@ int sfp_get_module_eeprom_by_page(struct sfp_bus *bus, struct netlink_ext_ack *extack);void sfp_upstream_start (struct sfp_bus *bus);void sfp_upstream_stop (struct sfp_bus *bus); +void sfp_upstream_retry_module (struct sfp_bus *bus);void sfp_upstream_set_signal_rate (struct sfp_bus *bus,unsigned int rate_kbd);void sfp_bus_put (struct sfp_bus *bus);struct sfp_bus *sfp_bus_find_fwnode (const struct fwnode_handle *fwnode);
@@ -635,6 +637,10 @@ static inline void sfp_upstream_stop(struct sfp_bus *bus) { } +static inline void sfp_upstream_retry_module (struct sfp_bus *bus) +{ +} +static inline void sfp_upstream_set_signal_rate (struct sfp_bus *bus,unsigned int rate_kbd) {
Signature · 1 line
2.55.0
PATCH v23 8/15 net: phylink: support PCS provider release
In reply to Christian MarangiAdd support for release of fwnode PCS from a PCS provider. Use a global blocking notifier chain and subscribe each phylink instance that uses internal PCS handling before populating its PCS list.
The PCS notifier emits FWNODE_PCS_PROVIDER_DEL after the provider is removed from the global provider list. Phylink detaches the provider's PCS synchronously and may call their operations during detach. Call fwnode_pcs_del_provider() with RTNL unlocked and keep the PCS and its hardware resources available until it returns.
Phylink uses fwnode_pcs_matches_provider() to check whether any PCS in its list belongs to the provider being released. If so, refresh the PCS list through fill_available_pcs() and detach PCS that are no longer available. If the refresh fails, remove the provider's PCS directly. Track additions and removals separately and wait for an RCU grace period after clearing the removed PCS pointers to phylink.
When the list changes, rebuild supported_interfaces and recalculate the link capabilities. Defer these updates until initialization finishes if the notification arrives during phylink_create().
For optical SFPs, rebuild the usable interfaces from the module's original interface mask and retain its EEPROM limits when recalculating in-band capabilities. Clear stale supported modes and advertising if no modes remain usable. If the current interface becomes unavailable, retain supported modes for alternate interfaces. During major configuration, check that the selected interface is usable and that the selected PCS supports the requested in-band autonegotiation mode.
If the active PCS is removed, bring the link down if needed, stop in-band polling, disable the PCS as needed and clear the active PCS pointer. Set force_major_config when phylink is enabled so resolve can reconfigure the link even if the interface mode is unchanged or the PHY link is down in in-band mode. If an SFP link lost its PCS while the signal was down, force reconfiguration when the signal returns.
Finally, trigger phylink resolve for an enabled instance after updating the PCS list and capabilities.
Serialize PCS list updates and teardown with provider notifications using pcs_list_mutex. Reuse the existing PCS ownership and state locking.
Unregister the notifier during phylink teardown and on creation failure.
--- drivers/net/pcs/pcs.c | 31 +++ drivers/net/phy/phylink.c | 441 ++++++++++++++++++++++++++----- include/linux/pcs/pcs-provider.h | 12 + include/linux/pcs/pcs.h | 67 +++++ 4 files changed, 487 insertions(+), 64 deletions(-)
drivers/net/pcs/pcs.c +31 -0
@@ -23,6 +23,19 @@ struct fwnode_pcs_provider {static LIST_HEAD (fwnode_pcs_providers);static DEFINE_MUTEX (fwnode_pcs_mutex); +static BLOCKING_NOTIFIER_HEAD (fwnode_pcs_notify_list); + +int register_fwnode_pcs_notifier (struct notifier_block *nb) +{ +return blocking_notifier_chain_register (&fwnode_pcs_notify_list, nb); +} +EXPORT_SYMBOL_GPL (register_fwnode_pcs_notifier); + +int unregister_fwnode_pcs_notifier (struct notifier_block *nb) +{ +return blocking_notifier_chain_unregister (&fwnode_pcs_notify_list, nb); +} +EXPORT_SYMBOL_GPL (unregister_fwnode_pcs_notifier);struct phylink_pcs *fwnode_pcs_simple_xlate (struct fwnode_reference_args *pcsspec,void *data)
@@ -91,6 +104,11 @@ void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp)mutex_unlock (&fwnode_pcs_mutex); +/* Signal phylink to release any PCS from this provider */ +blocking_notifier_call_chain (&fwnode_pcs_notify_list, +FWNODE_PCS_PROVIDER_DEL , + pp); +fwnode_pcs_free_provider (pp); }EXPORT_SYMBOL_GPL (fwnode_pcs_del_provider);
@@ -220,6 +238,19 @@ struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode, unsigned }EXPORT_SYMBOL_GPL (fwnode_pcs_get); +bool fwnode_pcs_matches_provider (struct fwnode_pcs_provider *provider, +const struct phylink_pcs *pcs) +{ +bool matches; + +mutex_lock (&fwnode_pcs_mutex); + matches = pcs->provider == provider; +mutex_unlock (&fwnode_pcs_mutex); + +return matches; +} +EXPORT_SYMBOL_GPL (fwnode_pcs_matches_provider); +unsigned int fwnode_phylink_pcs_count (struct fwnode_handle *fwnode) {struct fwnode_reference_args out_args;
drivers/net/phy/phylink.c +377 -64
577 lines not on this page · raw message
include/linux/pcs/pcs-provider.h +12 -0
@@ -43,6 +43,12 @@ fwnode_pcs_add_provider(struct fwnode_handle *fwnode,/** * fwnode_pcs_del_provider - Removes a PCS provider * @pp: PCS provider returned by fwnode_pcs_add_provider() +* +* Phylink detaches the provider's PCS instances synchronously and may call +* their operations during detach. Keep the PCS instances and the resources +* needed to access their hardware available until this function returns. +* +* Call without holding RTNL. */ void fwnode_pcs_del_provider (struct fwnode_pcs_provider *pp);
@@ -60,6 +66,12 @@ void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp);* On driver detach, release function is invoked on the devres data, * then, devres data is freed. * +* Register the provider after acquiring all resources its PCS operations +* need, so devres unregisters it before releasing those resources. Devres +* cleanup runs after the driver's remove callback. If remove needs to make +* the PCS hardware inaccessible, use fwnode_pcs_add_provider() and call +* fwnode_pcs_del_provider() before shutting down the hardware. +* * Returns: A pointer to the registered PCS provider on success, or * an ERR_PTR() encoded error code on failure. */
include/linux/pcs/pcs.h +67 -0
92 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v23 9/15 net: phylink: support late PCS provider attach
In reply to Christian MarangiAdd support for late PCS provider attachment to a phylink instance. Add FWNODE_PCS_PROVIDER_ADD to handle the case where a PCS provider becomes available after a phylink instance has been created.
The PCS notifier emits FWNODE_PCS_PROVIDER_ADD after registering a provider and releasing the provider mutex. Call fwnode_pcs_add_provider() and its devm variant with RTNL unlocked since the notifier can take RTNL.
On the add event, refresh the phylink PCS list through fill_available_pcs(). Attach newly available PCS to the phylink instance and refresh supported_interfaces and link capabilities when the list changes. If the PCS list changes during creation, finish any pending capability updates and SFP retries at the end of phylink_create().
Defer optical SFP insertion with -EAGAIN when none of the module's interfaces is currently usable and at least one requires a PCS. Retry deferred insertion when a PCS is added to the phylink instance.
If major_config_failed is set on a running instance, the next phylink resolve retries interface configuration and reevaluates the autonegotiation mode for the selected PCS. A follow-up resolve checks the link state with the new configuration, allowing a link torn down by PCS removal to come back up.
--- drivers/net/pcs/pcs.c | 4 +++ drivers/net/phy/phylink.c | 50 +++++++++++++++++++++++++++----- include/linux/pcs/pcs-provider.h | 4 +++ include/linux/pcs/pcs.h | 1 + 4 files changed, 52 insertions(+), 7 deletions(-)
drivers/net/pcs/pcs.c +4 -0
@@ -71,6 +71,10 @@ fwnode_pcs_add_provider(struct fwnode_handle *fwnode,mutex_unlock (&fwnode_pcs_mutex); +blocking_notifier_call_chain (&fwnode_pcs_notify_list, +FWNODE_PCS_PROVIDER_ADD , + pp); +pr_debug ("Added pcs provider from %pfwf\n" , fwnode);return pp;
drivers/net/phy/phylink.c +43 -7
119 lines not on this page · raw message
include/linux/pcs/pcs-provider.h +4 -0
@@ -31,6 +31,8 @@ struct phylink_pcs *fwnode_pcs_simple_xlate(struct fwnode_reference_args *pcsspe* A PCS object belongs to one provider and must remain valid until that * provider is removed. * +* Call without holding RTNL. +* * Returns: A pointer to the registered PCS provider on success, or * an ERR_PTR() encoded error code on failure. */
@@ -72,6 +74,8 @@ void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp);* the PCS hardware inaccessible, use fwnode_pcs_add_provider() and call * fwnode_pcs_del_provider() before shutting down the hardware. * +* Call without holding RTNL. +* * Returns: A pointer to the registered PCS provider on success, or * an ERR_PTR() encoded error code on failure. */
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.55.0
PATCH v23 10/15 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 | 257 +++++++++++++++++++++++ Documentation/networking/sfp-phylink.rst | 35 +-- 3 files changed, 269 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 +257 -0
257 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.55.0
PATCH v23 11/15 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
@@ -10036,6 +10036,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.55.0
PATCH v23 12/15 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
@@ -1163,6 +1163,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)
@@ -1889,6 +1895,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
@@ -531,6 +531,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
@@ -558,6 +559,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);
@@ -693,6 +695,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.55.0
PATCH v23 13/15 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.55.0
PATCH v23 14/15 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 | 17 + drivers/net/pcs/airoha/Makefile | 7 + drivers/net/pcs/airoha/pcs-airoha-common.c | 1312 ++++++++++++ drivers/net/pcs/airoha/pcs-airoha.h | 1311 ++++++++++++ drivers/net/pcs/airoha/pcs-an7581.c | 2115 ++++++++++++++++++++ 7 files changed, 4766 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
@@ -64,4 +64,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
@@ -10,3 +10,5 @@ obj-$(CONFIG_PCS_XPCS_ROCKCHIP) += pcs-xpcs-rk.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 +17 -0
@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config PCS_AIROHA + tristate + select PHYLINK + select FWNODE_PCS + select MFD_SYSCON + select REGMAP_MMIO + select GENERIC_PHY + +config PCS_AIROHA_AN7581 + tristate "Airoha AN7581 PCS driver" + depends on ARCH_AIROHA || COMPILE_TEST + select PCS_AIROHA + help + This module provides helper to phylink for managing the Airoha + AN7581 PCS for SoC Ethernet and PON SERDES.
drivers/net/pcs/airoha/Makefile new file +7 -0
@@ -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 +1312 -0
1,312 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 +2115 -0
342 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.55.0
Part of the diff is not shown here. View the raw message.
PATCH v23 15/15 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 | 197 +++++++++++++++++++++- drivers/net/ethernet/airoha/airoha_eth.h | 5 + drivers/net/ethernet/airoha/airoha_regs.h | 12 ++ 4 files changed, 213 insertions(+), 3 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 FWNODE_PCS + select PHYLINK help This driver supports the gigabit ethernet MACs in the Airoha SoC family.
drivers/net/ethernet/airoha/airoha_eth.c +194 -3
272 lines not on this page · raw message
drivers/net/ethernet/airoha/airoha_eth.h +5 -0
@@ -612,6 +612,9 @@ struct airoha_gdm_dev {* QDMA migration. */ spinlock_t txq_lock[AIROHA_NUM_NETDEV_TX_RINGS ]; + +struct phylink *phylink; +struct phylink_config phylink_config; };struct airoha_gdm_port {
@@ -621,6 +624,8 @@ struct airoha_gdm_port {/* protect concurrent hw_stats accesses */ spinlock_t stats_lock; +/* protect concurrent GDM4 register access */ +struct mutex link_lock;struct metadata_dst *dsa_meta[AIROHA_MAX_DSA_PORTS ]; };
drivers/net/ethernet/airoha/airoha_regs.h +12 -0
@@ -371,6 +371,18 @@#define IP_FRAGMENT_PORT_MASK GENMASK(8, 5)#define IP_FRAGMENT_NBQ_MASK GENMASK(4, 0) +#define REG_FE_GDM4_TMBI_FRAG 0x2028 +#define GDM4_SGMII1_TX_WEIGHT_MASK GENMASK(31, 26) +#define GDM4_SGMII1_TX_FRAG_SIZE_MASK GENMASK(25, 16) +#define GDM4_SGMII0_TX_WEIGHT_MASK GENMASK(15, 10) +#define GDM4_SGMII0_TX_FRAG_SIZE_MASK GENMASK(9, 0) + +#define REG_FE_GDM4_RMBI_FRAG 0x202c +#define GDM4_SGMII1_RX_WEIGHT_MASK GENMASK(31, 26) +#define GDM4_SGMII1_RX_FRAG_SIZE_MASK GENMASK(25, 16) +#define GDM4_SGMII0_RX_WEIGHT_MASK GENMASK(15, 10) +#define GDM4_SGMII0_RX_FRAG_SIZE_MASK GENMASK(9, 0) +#define REG_MC_VLAN_EN 0x2100#define MC_VLAN_EN_MASK BIT(0)
Signature · 1 line
2.55.0
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.