net: pcs: Introduce support for fwnode PCS
Subsystems (8)
v2 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.
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 should first call fwnode_pcs_del_provider() to delete itself as a provider and then release the PCS from phylink with phylink_release_pcs() under rtnl lock.
This series also 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 can be provided to phylink at phylink_create time by setting the available_pcs and num_available_pcs in phylink_config.
A helper to parse PCS from fwnode is provided fwnode_phylink_pcs_parse() that will fill a preallocated array of PCS.
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 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 avialable.
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.
While this was developed there was a different version that was proposed for the feature, this is posted with the hope of implementing a more streamlined implementation and as a continuation of v2 with the addressed request from Russell.
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 (11):
net: phylink: fix possible circular locking dep with config in-band
net: phylink: keep and use MAC supported_interfaces in phylink struct
net: phy: introduce phy_interface_copy helper
net: phylink: introduce internal phylink PCS handling
net: phylink: add phylink_release_pcs() to externally release a PCS
net: pcs: implement Firmware node support for PCS driver
net: phylink: support late PCS provider attach
dt-bindings: net: ethernet-controller: permit to define multiple PCS
net: pcs: airoha: add PCS driver for Airoha SoC
dt-bindings: net: pcs: Document support for Airoha Ethernet PCS
net: airoha: add phylink support for GDM2/3/4
.../bindings/net/ethernet-controller.yaml | 2 - .../bindings/net/pcs/airoha,pcs.yaml | 112 + drivers/net/ethernet/airoha/airoha_eth.c | 266 +- drivers/net/ethernet/airoha/airoha_eth.h | 4 + drivers/net/ethernet/airoha/airoha_regs.h | 12 + drivers/net/pcs/Kconfig | 14 + drivers/net/pcs/Makefile | 2 + drivers/net/pcs/pcs-airoha.c | 2855 +++++++++++++++++ drivers/net/pcs/pcs.c | 235 ++ drivers/net/phy/phylink.c | 283 +- include/linux/pcs/pcs-airoha.h | 26 + include/linux/pcs/pcs-provider.h | 41 + include/linux/pcs/pcs.h | 104 + include/linux/phy.h | 5 + include/linux/phylink.h | 12 + 15 files changed, 3942 insertions(+), 31 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml create mode 100644 drivers/net/pcs/pcs-airoha.c create mode 100644 drivers/net/pcs/pcs.c create mode 100644 include/linux/pcs/pcs-airoha.h create mode 100644 include/linux/pcs/pcs-provider.h create mode 100644 include/linux/pcs/pcs.h
Signature · 1 line
2.48.1
RFC PATCH v2 1/11 net: phylink: fix possible circular locking dep with config in-band
Debug lock detection revealed a possible circular locking dependency between phylink_major_config() and phylink_bringup_phy().
This was introduced by the addition of phy_config_inband(), which acquires the phydev lock. This made the locking order in phylink_bringup_phy() inconsistent, as it acquires the phydev lock before phylink's state_mutex.
A deadlock can occur when phylink_major_config() is called from phylink_resolve(), where the state_mutex is taken first and then the phydev lock. This is the reverse of the order used in phylink_bringup_phy().
To avoid this circular dependency, change the locking order in phylink_bringup_phy() to match the pattern used in phylink_resolve(): take state_mutex first, then the phydev lock.
A sample lockdep warning is included below for reference:
[ 147.749178]
[ 147.750682] ======================================================
[ 147.756850] WARNING: possible circular locking dependency detected
[ 147.763019] 6.14.0-next-20250404+ #0 Tainted: G O
[ 147.769189] ------------------------------------------------------
[ 147.775356] kworker/u16:0/12 is trying to acquire lock:
[ 147.780571] ffffff80ce9bcf08 (&dev->lock#2){+.+.}-{4:4}, at: phy_config_inband+0x44/0x90
[ 147.788672]
[ 147.788672] but task is already holding lock:
[ 147.794492] ffffff80c0dfbda0 (&pl->state_mutex){+.+.}-{4:4}, at: phylink_resolve+0x2c/0x6a8
[ 147.802840]
[ 147.802840] which lock already depends on the new lock.
[ 147.802840]
[ 147.811002]
[ 147.811002] the existing dependency chain (in reverse order) is:
[ 147.818472]
[ 147.818472] -> #1 (&pl->state_mutex){+.+.}-{4:4}:
[ 147.824647] __mutex_lock+0x90/0x924
[ 147.828738] mutex_lock_nested+0x20/0x28
[ 147.833173] phylink_bringup_phy+0x210/0x700
[ 147.837954] phylink_fwnode_phy_connect+0xe0/0x124
[ 147.843256] phylink_of_phy_connect+0x18/0x20
[ 147.848124] dsa_user_create+0x210/0x414
[ 147.852561] dsa_port_setup+0xd4/0x14c
[ 147.856823] dsa_register_switch+0xbb0/0xe40
[ 147.861605] mt7988_probe+0xf8/0x140
[ 147.865694] platform_probe+0x64/0xbc
[ 147.869869] really_probe+0xbc/0x388
[ 147.873955] __driver_probe_device+0x78/0x154
[ 147.878823] driver_probe_device+0x3c/0xd4
[ 147.883430] __device_attach_driver+0xb0/0x144
[ 147.888383] bus_for_each_drv+0x6c/0xb0
[ 147.892732] __device_attach+0x9c/0x19c
[ 147.897078] device_initial_probe+0x10/0x18
[ 147.901771] bus_probe_device+0xa8/0xac
[ 147.906118] deferred_probe_work_func+0xb8/0x118
[ 147.911245] process_one_work+0x224/0x610
[ 147.915769] worker_thread+0x1b8/0x35c
[ 147.920029] kthread+0x11c/0x1e8
[ 147.923769] ret_from_fork+0x10/0x20
[ 147.927857]
[ 147.927857] -> #0 (&dev->lock#2){+.+.}-{4:4}:
[ 147.933686] __lock_acquire+0x12b8/0x1ff0
[ 147.938209] lock_acquire+0xf4/0x2d8
[ 147.942295] __mutex_lock+0x90/0x924
[ 147.946383] mutex_lock_nested+0x20/0x28
[ 147.950817] phy_config_inband+0x44/0x90
[ 147.955252] phylink_major_config+0x684/0xa64
[ 147.960120] phylink_resolve+0x24c/0x6a8
[ 147.964554] process_one_work+0x224/0x610
[ 147.969075] worker_thread+0x1b8/0x35c
[ 147.973335] kthread+0x11c/0x1e8
[ 147.977075] ret_from_fork+0x10/0x20
[ 147.981162]
[ 147.981162] other info that might help us debug this:
[ 147.981162]
[ 147.989150] Possible unsafe locking scenario:
[ 147.989150]
[ 147.995056] CPU0 CPU1
[ 147.999575] ---- ----
[ 148.004094] lock(&pl->state_mutex);
[ 148.007748] lock(&dev->lock#2);
[ 148.013572] lock(&pl->state_mutex);
[ 148.019742] lock(&dev->lock#2);
[ 148.023051]
[ 148.023051] *** DEADLOCK ***
[ 148.023051]
[ 148.028958] 3 locks held by kworker/u16:0/12:
[ 148.033304] #0: ffffff80c0011d48 ((wq_completion)events_power_efficient){+.+.}-{0:0}, at: process_one_work+0x1a8/0x610
[ 148.044082] #1: ffffffc081ca3dd8 ((work_completion)(&pl->resolve)){+.+.}-{0:0}, at: process_one_work+0x1d0/0x610
[ 148.054338] #2: ffffff80c0dfbda0 (&pl->state_mutex){+.+.}-{4:4}, at: phylink_resolve+0x2c/0x6a8
[ 148.063119]
[ 148.063119] stack backtrace:
[ 148.067465] CPU: 3 UID: 0 PID: 12 Comm: kworker/u16:0 Tainted: G O 6.14.0-next-20250404+ #0 NONE
[ 148.067472] Tainted: [O]=OOT_MODULE
[ 148.067474] Hardware name: Bananapi BPI-R4 2.5GE PoE (DT)
[ 148.067476] Workqueue: events_power_efficient phylink_resolve
[ 148.067482] Call trace:
[ 148.067484] show_stack+0x14/0x1c (C)
[ 148.067492] dump_stack_lvl+0x84/0xc0
[ 148.067497] dump_stack+0x14/0x1c
[ 148.067500] print_circular_bug+0x330/0x43c
[ 148.067505] check_noncircular+0x124/0x134
[ 148.067508] __lock_acquire+0x12b8/0x1ff0
[ 148.067512] lock_acquire+0xf4/0x2d8
[ 148.067516] __mutex_lock+0x90/0x924
[ 148.067521] mutex_lock_nested+0x20/0x28
[ 148.067527] phy_config_inband+0x44/0x90
[ 148.067531] phylink_major_config+0x684/0xa64
[ 148.067535] phylink_resolve+0x24c/0x6a8
[ 148.067539] process_one_work+0x224/0x610
[ 148.067544] worker_thread+0x1b8/0x35c
[ 148.067548] kthread+0x11c/0x1e8
[ 148.067552] ret_from_fork+0x10/0x20--- drivers/net/phy/phylink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/phylink.c +2 -2
@@ -2072,8 +2072,8 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, dev_name(&phy->mdio.dev), phy->drv->name, irq_str);kfree (irq_str); -mutex_lock (&phy->lock);mutex_lock (&pl->state_mutex); +mutex_lock (&phy->lock); pl->phydev = phy; pl->phy_state.interface = interface; pl->phy_state.pause =MLO_PAUSE_NONE ;
@@ -2115,8 +2115,8 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy,phy_disable_eee (phy); } -mutex_unlock (&pl->state_mutex);mutex_unlock (&phy->lock); +mutex_unlock (&pl->state_mutex); phylink_dbg(pl, "phy: %s setting supported %*pb advertising %*pb\n",
Signature · 1 line
2.48.1
RFC PATCH v2 2/11 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 | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/net/phy/phylink.c +15 -7
@@ -66,6 +66,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;
@@ -616,7 +621,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,
@@ -1815,6 +1820,9 @@ struct phylink *phylink_create(struct phylink_config *config,mutex_init (&pl->state_mutex);INIT_WORK (&pl->resolve, phylink_resolve); +phy_interface_copy (pl->supported_interfaces, + config->supported_interfaces); + pl->config = config;if (config->type ==PHYLINK_NETDEV ) { pl->netdev =to_net_dev (config->dev);
@@ -1973,7 +1981,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" );
@@ -2685,12 +2693,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 ; }
@@ -3577,14 +3585,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 (interfaces, pl->config->supported_interfaces, +phy_interface_and (interfaces, pl->supported_interfaces, pl->sfp_interfaces);if (phy_interface_empty (interfaces)) {phylink_err (pl,"unsupported SFP module: no common interface modes\n" );
@@ -3730,7 +3738,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.48.1
RFC PATCH v2 3/11 net: phy: introduce phy_interface_copy helper
In reply to Christian MarangiIntroduce phy_interface_copy helper as a shorthand to copy the PHY interface bitmap to a different location.
This is useful if a PHY interface bitmap needs to be stored in a different variable and needs to be reset to an original value saved in a different bitmap.
--- include/linux/phy.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/phy.h +5 -0
@@ -173,6 +173,11 @@ static inline void phy_interface_or(unsigned long *dst, const unsigned long *a,bitmap_or (dst, a, b,PHY_INTERFACE_MODE_MAX ); } +static inline void phy_interface_copy (unsigned long *dst,const unsigned long *src) +{ +bitmap_copy (dst, src,PHY_INTERFACE_MODE_MAX ); +} +static inline void phy_interface_set_rgmii (unsigned long *intf) {__set_bit (PHY_INTERFACE_MODE_RGMII , intf);
Signature · 1 line
2.48.1
RFC PATCH v2 4/11 net: phylink: introduce internal phylink PCS handling
In reply to Christian MarangiIntroduce internal handling of PCS for phylink. This is an alternative to .mac_select_pcs that moves the selection logic of the PCS entirely to phylink with the usage of supported_interface value in the PCS struct.
MAC should now provide an array of available PCS in phylink_config in .available_pcs and fill the .num_available_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() this array is parsed and a linked list of PCS is created based on the PCS passed in phylink_config.
Also the supported_interface value in phylink struct is updated with the new supported_interface from the provided PCS.
On phylink_start() every PCS in phylink PCS list gets attached to the phylink instance. This is done by setting the phylink value in phylink_pcs struct to the phylink instance.
On phylink_stop(), every PCS in phylink PCS list is detached from the phylink instance. This is done by setting the phylink value in phylink_pcs struct to NULL.
On phylink_stop(), every PCS in phylink PCS list is removed from the 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() apply 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.
It's required for a MAC that implement either a .mac_select_pcs or make use of the PCS list implementation. Implementing both will result in a fail on MAC/PCS validation.
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.
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 | 147 +++++++++++++++++++++++++++++++++----- include/linux/phylink.h | 10 +++ 2 files changed, 139 insertions(+), 18 deletions(-)
drivers/net/phy/phylink.c +129 -18
@@ -66,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. */
@@ -150,6 +153,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
@@ -505,22 +510,59 @@ 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 */ if (pl->mac_ops->mac_select_pcs) { +/* Make sure either PCS internal validation or .mac_select_pcs +* is used. Return error if both are defined. +*/ +if (!list_empty (&pl->pcs_list)) { +phylink_err (pl,"either phylink_pcs_add() or .mac_select_pcs must be used\n" ); +return -EINVAL ; + } + pcs = pl->mac_ops->mac_select_pcs (pl->config, state->interface);if (IS_ERR (pcs))return PTR_ERR (pcs); + + pcs_found = !!pcs; + }else { +/* Check every assigned PCS and search for one that supports +* the interface. +*/ +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.
@@ -532,13 +574,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 ; }
@@ -943,12 +982,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 { +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);
@@ -1234,10 +1283,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 dedicaed 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 ; + } + } + +if (!pcs_found) { +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",
@@ -1264,10 +1339,12 @@ 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 ; - pcs->phylink = pl; + pcs->phylink = pl; + } pl->pcs = pcs; }
@@ -1803,8 +1880,9 @@ struct phylink *phylink_create(struct phylink_config *config,phy_interface_t iface, const struct phylink_mac_ops *mac_ops) { + struct phylink_pcs *pcs;struct phylink *pl; -int ret; +int i, ret;/* Validate the supplied configuration */ if (phy_interface_empty (config->supported_interfaces)) {
@@ -1819,9 +1897,21 @@ struct phylink *phylink_create(struct phylink_config *config,mutex_init (&pl->state_mutex);INIT_WORK (&pl->resolve, phylink_resolve); +INIT_LIST_HEAD (&pl->pcs_list); + +/* Fill the PCS list with available PCS from phylink config */ +for (i =0 ; i < config->num_available_pcs; i++) { + pcs = config->available_pcs[i]; + +list_add (&pcs->list, &pl->pcs_list); + }phy_interface_copy (pl->supported_interfaces, config->supported_interfaces); +list_for_each_entry (pcs, &pl->pcs_list, list) +phy_interface_or (pl->supported_interfaces, + pl->supported_interfaces, + pcs->supported_interfaces); pl->config = config;if (config->type ==PHYLINK_NETDEV ) {
@@ -1900,10 +1990,16 @@ 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); +/* Remove every PCS from phylink PCS list */ +list_for_each_entry_safe (pcs, tmp, &pl->pcs_list, list) +list_del (&pcs->list); +cancel_work_sync (&pl->resolve);kfree (pl); }
@@ -2380,6 +2476,7 @@ static irqreturn_t phylink_link_handler(int irq, void *data)*/ void phylink_start (struct phylink *pl) { +struct phylink_pcs *pcs;bool poll = false;ASSERT_RTNL ();
@@ -2406,6 +2503,10 @@ void phylink_start(struct phylink *pl) pl->pcs_state =PCS_STATE_STARTED ; +/* link available PCS to phylink struct */ +list_for_each_entry (pcs, &pl->pcs_list, list) + pcs->phylink = pl; +phylink_enable_and_run_resolve (pl,PHYLINK_DISABLE_STOPPED );if (pl->cfg_link_an_mode ==MLO_AN_FIXED && pl->link_gpio) {
@@ -2450,6 +2551,8 @@ EXPORT_SYMBOL_GPL(phylink_start);*/ void phylink_stop (struct phylink *pl) { +struct phylink_pcs *pcs; +ASSERT_RTNL ();if (pl->sfp_bus)
@@ -2467,6 +2570,14 @@ void phylink_stop(struct phylink *pl) pl->pcs_state =PCS_STATE_DOWN ;phylink_pcs_disable (pl->pcs); + +/* Drop link between phylink and PCS */ +list_for_each_entry (pcs, &pl->pcs_list, list) + pcs->phylink =NULL ; + +/* Restore original supported interfaces */ +phy_interface_copy (pl->supported_interfaces, + pl->config->supported_interfaces); }EXPORT_SYMBOL_GPL (phylink_stop);
include/linux/phylink.h +10 -0
@@ -150,12 +150,16 @@ 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. * @lpi_capabilities: MAC speeds which can support LPI signalling * @lpi_timer_default: Default EEE LPI timer setting. * @eee_enabled_default: If set, EEE will be enabled by phylink at creation time +* @available_pcs: array of available phylink_pcs PCS +* @num_available_pcs: num of available phylink_pcs PCS */ struct phylink_config {struct device *dev;
@@ -168,11 +172,14 @@ 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;u32 lpi_timer_default;bool eee_enabled_default; +struct phylink_pcs **available_pcs; +unsigned int num_available_pcs; };void phylink_limit_mac_speed (struct phylink_config *config,u32 max_speed);
@@ -460,6 +467,9 @@ struct phylink_pcs {struct phylink *phylink;bool poll;bool rxc_always_on; + +/* private: */ +struct list_head list; };/**
Signature · 1 line
2.48.1
RFC PATCH v2 5/11 net: phylink: add phylink_release_pcs() to externally release a PCS
In reply to Christian MarangiAdd phylink_release_pcs() to externally release a PCS from a phylink instance. This can be used to handle case when a single PCS needs to be removed and the phylink instance needs to be refreshed.
On calling phylink_release_pcs(), the PCS will be removed from the phylink internal PCS list and the phylink supported_interfaces value is reparsed with the remaining PCS interfaces.
Also a phylink resolve is triggered to handle the PCS removal.
It's also added to phylink a flag to make phylink resolve reconfigure the interface mode (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.
--- drivers/net/phy/phylink.c | 58 ++++++++++++++++++++++++++++++++++++++- include/linux/phylink.h | 2 ++ 2 files changed, 59 insertions(+), 1 deletion(-)
drivers/net/phy/phylink.c +57 -1
@@ -90,6 +90,7 @@ struct phylink {bool link_failed;bool major_config_failed; +bool reconfig_interface;bool mac_supports_eee_ops;bool mac_supports_eee;bool phy_enable_tx_lpi;
@@ -901,6 +902,55 @@ static void phylink_resolve_an_pause(struct phylink_link_state *state) } } +/** +* phylink_release_pcs - Removes a PCS from the phylink PCS available list +* @pcs: a pointer to the phylink_pcs struct to be released +* +* This function release a PCS from the phylink PCS available list if +* actually in use. It also refreshes the supported interfaces of the +* phylink instance by copying the supported interfaces from the phylink +* conf and merging the supported interfaces of the remaining available PCS +* in the list and trigger a resolve. +*/ +void phylink_release_pcs (struct phylink_pcs *pcs) +{ +struct phylink *pl; + +ASSERT_RTNL (); + + pl = pcs->phylink; +if (!pl) +return ; + +list_del (&pcs->list); + pcs->phylink =NULL ; + +/* Check if we are removing the PCS currently +* in use by phylink. If this is the case, +* force phylink resolve to reconfigure the interface +* mode and set the phylink PCS to NULL. +*/ +if (pl->pcs == pcs) { +mutex_lock (&pl->state_mutex); + + pl->reconfig_interface = true; + pl->pcs =NULL ; + +mutex_unlock (&pl->state_mutex); + } + +/* Refresh supported interfaces */ +phy_interface_copy (pl->supported_interfaces, + pl->config->supported_interfaces); +list_for_each_entry (pcs, &pl->pcs_list, list) +phy_interface_or (pl->supported_interfaces, + pl->supported_interfaces, + pcs->supported_interfaces); + +phylink_run_resolve (pl); +} +EXPORT_SYMBOL_GPL (phylink_release_pcs); +static unsigned int phylink_pcs_inband_caps (struct phylink_pcs *pcs,phy_interface_t interface) {
@@ -1694,6 +1744,10 @@ static void phylink_resolve(struct work_struct *w)if (pl->phydev) link_state.link &= pl->phy_state.link; +/* Force mac_config if we need to reconfig the interface */ +if (pl->reconfig_interface) + mac_config = true; +/* Only update if the PHY link is up */ if (pl->phydev && pl->phy_state.link) {/* If the interface has changed, force a link down
@@ -1728,7 +1782,8 @@ static void phylink_resolve(struct work_struct *w)phylink_apply_manual_flow (pl, &link_state);if (mac_config) { -if (link_state.interface != pl->link_config.interface) { +if (link_state.interface != pl->link_config.interface || + pl->reconfig_interface) {/* The interface has changed, force the link down and * then reconfigure. */
@@ -1738,6 +1793,7 @@ static void phylink_resolve(struct work_struct *w) }phylink_major_config (pl, false, &link_state); pl->link_config.interface = link_state.interface; + pl->reconfig_interface = false; } }
include/linux/phylink.h +2 -0
@@ -708,6 +708,8 @@ void phylink_disconnect_phy(struct phylink *);int phylink_set_fixed_link (struct phylink *,const struct phylink_link_state *); +void phylink_release_pcs (struct phylink_pcs *pcs); +void phylink_mac_change (struct phylink *,bool up);void phylink_pcs_change (struct phylink_pcs *,bool up);
Signature · 1 line
2.48.1
RFC PATCH v2 6/11 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.
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 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 advanced implementation a custom xlate function is required.
PCS driver on removal should first delete as a provider with the usage of fwnode_pcs_del_provider() and then call phylink_release_pcs() on every PCS the driver provides and
A generic function fwnode_phylink_pcs_parse() is provided for any MAC driver that will declare PCS in DT (or ACPI).
This function will parse "pcs-handle" property and fill the passed array with the parsed PCS in availabel_pcs up to the passed num_pcs value. It's also possible to pass NULL as array to only parse the PCS and update the num_pcs value with the count of scanned PCS.
--- drivers/net/pcs/Kconfig | 7 ++ drivers/net/pcs/Makefile | 1 + drivers/net/pcs/pcs.c | 201 +++++++++++++++++++++++++++++++ include/linux/pcs/pcs-provider.h | 41 +++++++ include/linux/pcs/pcs.h | 56 +++++++++ 5 files changed, 306 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 +7 -0
@@ -5,6 +5,13 @@ menu "PCS device drivers" +config FWNODE_PCS + tristate + depends on (ACPI || OF) + depends on PHYLINK + 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 +201 -0
201 lines not on this page · raw message
include/linux/pcs/pcs-provider.h new file +41 -0
41 lines not on this page · raw message
include/linux/pcs/pcs.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.48.1
RFC PATCH v2 7/11 net: phylink: support late PCS provider attach
In reply to Christian MarangiAdd support in phylink for late PCS provider attach to a phylink instance. 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_ADD every time a new PCS provider is added.
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 phy-handle property of the phylink instance.
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 if it's not disable 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.
If link was previously torn down due to removal of PCS, the link will be established again as the PCS came back and is not available to phylink.
--- drivers/net/pcs/pcs.c | 34 +++++++++++++++++++++++++ drivers/net/phy/phylink.c | 52 +++++++++++++++++++++++++++++++++++++++ include/linux/pcs/pcs.h | 48 ++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+)
drivers/net/pcs/pcs.c +34 -0
@@ -22,6 +22,13 @@ 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);struct phylink_pcs *fwnode_pcs_simple_get (struct fwnode_reference_args *pcsspec,void *data)
@@ -55,6 +62,10 @@ int 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 0 ; }EXPORT_SYMBOL_GPL (fwnode_pcs_add_provider);
@@ -147,6 +158,29 @@ struct phylink_pcs *fwnode_pcs_get(struct fwnode_handle *fwnode, int index) }EXPORT_SYMBOL_GPL (fwnode_pcs_get); +struct phylink_pcs * +fwnode_phylink_pcs_get_from_fwnode (struct fwnode_handle *fwnode, +struct fwnode_handle *pcs_fwnode) +{ +struct fwnode_reference_args pcsspec; +int i =0 ; +int ret; + +while (true) { + ret =fwnode_parse_pcsspec (fwnode, i,NULL , &pcsspec); +if (ret) +break ; + +if (pcsspec.fwnode == pcs_fwnode) +break ; + + i++; + } + +return fwnode_pcs_get (fwnode, i); +} +EXPORT_SYMBOL_GPL (fwnode_phylink_pcs_get_from_fwnode); +static int fwnode_phylink_pcs_count (struct fwnode_handle *fwnode,unsigned int *num_pcs) {
drivers/net/phy/phylink.c +52 -0
76 lines not on this page · raw message
include/linux/pcs/pcs.h +48 -0
73 lines not on this page · raw message
Signature · 1 line
2.48.1
RFC PATCH v2 8/11 dt-bindings: net: ethernet-controller: permit to define multiple PCS
In reply to Christian MarangiDrop the limitation of a single PCS in pcs-handle property. Multiple PCS can be defined for an ethrnet-controller node to support various PHY interface mode type.
It's very common for SoCs to have a dedicated PCS for SGMII mode and one for USXGMII mode.
---
(for Rob, I didn't ignore the comments, just want to
make sure the driver side is done, please ignore)
Documentation/devicetree/bindings/net/ethernet-controller.yaml | 2 -- 1 file changed, 2 deletions(-)
Documentation/devicetree/bindings/net/ethernet-controller.yaml +0 -2
@@ -110,8 +110,6 @@ properties: pcs-handle: $ref: /schemas/types.yaml#/definitions/phandle-array - items: - maxItems: 1 description: Specifies a reference to a node representing a PCS PHY device on a MDIO bus to link with an external PHY (phy-handle) if exists.
Signature · 1 line
2.48.1
RFC PATCH v2 9/11 net: pcs: airoha: add PCS driver for Airoha SoC
In reply to Christian MarangiAdd PCS driver for Airoha SoC for Ethernet Serdes and PCS and permit usage of external PHY or connected SFP cage. Supported modes are USXGMII, 10-BASER, 2500BASE-X, 1000BASE-X and SGMII.
The driver register as a PCS provider and supports poll mode to detect PCS port state. While interrupt is supported by the HW, there are some defect with the interrupt not fired on cable detach.
The PCS require complex calibration to correctly work and might require multiple try until the signal detection module "lock" on the signal level to correct work with the attached PHY.
--- drivers/net/pcs/Kconfig | 7 + drivers/net/pcs/Makefile | 1 + drivers/net/pcs/pcs-airoha.c | 2855 ++++++++++++++++++++++++++++++++ include/linux/pcs/pcs-airoha.h | 11 + 4 files changed, 2874 insertions(+) create mode 100644 drivers/net/pcs/pcs-airoha.c create mode 100644 include/linux/pcs/pcs-airoha.h
drivers/net/pcs/Kconfig +7 -0
@@ -12,6 +12,13 @@ config FWNODE_PCS help Firmware node PCS accessors +config PCS_AIROHA + select FWNODE_PCS + tristate "Airoha PCS driver" + help + This module provides helper to phylink for managing the Airoha + PCS for SoC Ethernet Serdes and PCS. + config PCS_XPCS tristate "Synopsys DesignWare Ethernet XPCS" select PHYLINK
drivers/net/pcs/Makefile +1 -0
@@ -2,6 +2,7 @@ # Makefile for Linux PCS drivers obj-$(CONFIG_FWNODE_PCS) += pcs.o +obj-$(CONFIG_PCS_AIROHA) += pcs-airoha.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-airoha.c new file +2855 -0
2,855 lines not on this page · raw message
include/linux/pcs/pcs-airoha.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LINUX_PCS_AIROHA_H +#define __LINUX_PCS_AIROHA_H + +/* XFI_MAC */ +#define AIROHA_PCS_XFI_MAC_XFI_GIB_CFG 0x0 +#define AIROHA_PCS_XFI_TX_FC_EN BIT(5) +#define AIROHA_PCS_XFI_RX_FC_EN BIT(4) + +#endif /* __LINUX_PCS_AIROHA_H */
Signature · 1 line
2.48.1
RFC PATCH v2 10/11 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.
---
(for Rob, I didn't ignore the comments, just want to
make sure the driver side is done, please ignore)
.../bindings/net/pcs/airoha,pcs.yaml | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml
Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml new file +112 -0
@@ -0,0 +1,112 @@ +# 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 + + reg: + items: + - description: XFI MAC reg + - description: HSGMII AN reg + - description: HSGMII PCS reg + - description: MULTI SGMII reg + - description: USXGMII reg + - description: HSGMII rate adaption reg + - description: XFI Analog register + - description: XFI PMA (Physical Medium Attachment) register + + reg-names: + items: + - const: xfi_mac + - const: hsgmii_an + - const: hsgmii_pcs + - const: multi_sgmii + - const: usxgmii + - const: hsgmii_rate_adp + - const: xfi_ana + - const: xfi_pma + + resets: + items: + - description: MAC reset + - description: PHY reset + + reset-names: + items: + - const: mac + - const: phy + + "#pcs-cells": + const: 0 + +required: + - compatible + - reg + - reg-names + - resets + - reset-names + - "#pcs-cells" + +additionalProperties: false + +examples: + - | + #include <dt-bindings/reset/airoha,en7581-reset.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 = "xfi_mac", "hsgmii_an", "hsgmii_pcs", + "multi_sgmii", "usxgmii", + "hsgmii_rate_adp", "xfi_ana", "xfi_pma"; + + resets = <&scuclk EN7581_XPON_MAC_RST>, + <&scuclk EN7581_XPON_PHY_RST>; + reset-names = "mac", "phy"; + + #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 = "xfi_mac", "hsgmii_an", "hsgmii_pcs", + "multi_sgmii", "usxgmii", + "hsgmii_rate_adp", "xfi_ana", "xfi_pma"; + + resets = <&scuclk EN7581_XSI_MAC_RST>, + <&scuclk EN7581_XSI_PHY_RST>; + reset-names = "mac", "phy"; + + #pcs-cells = <0>; + };
Signature · 1 line
2.48.1
RFC PATCH v2 11/11 net: airoha: add phylink support for GDM2/3/4
In reply to Christian MarangiAdd phylink support for GDM2/3/4 port that require 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.
--- drivers/net/ethernet/airoha/airoha_eth.c | 266 +++++++++++++++++++++- drivers/net/ethernet/airoha/airoha_eth.h | 4 + drivers/net/ethernet/airoha/airoha_regs.h | 12 + include/linux/pcs/pcs-airoha.h | 15 ++ 4 files changed, 296 insertions(+), 1 deletion(-)
drivers/net/ethernet/airoha/airoha_eth.c +265 -1
@@ -5,9 +5,13 @@*/ #include <linux/of.h> #include <linux/of_net.h> +#include <linux/of_platform.h> #include <linux/platform_device.h> #include <linux/tcp.h> +#include <linux/pcs/pcs.h> +#include <linux/pcs/pcs-airoha.h> #include <linux/u64_stats_sync.h> +#include <linux/regmap.h> #include <net/dst_metadata.h> #include <net/page_pool/helpers.h> #include <net/pkt_cls.h>
@@ -76,6 +80,11 @@ static bool airhoa_is_lan_gdm_port(struct airoha_gdm_port *port)return port->id ==1 ; } +static bool airhoa_is_phy_external (struct airoha_gdm_port *port) +{ +return port->id !=1 ; +} +static void airoha_set_macaddr (struct airoha_gdm_port *port,const u8 *addr) {struct airoha_eth *eth = port->qdma->eth;
@@ -1535,6 +1544,17 @@ static int airoha_dev_open(struct net_device *dev)struct airoha_gdm_port *port =netdev_priv (dev);struct airoha_qdma *qdma = port->qdma; +if (airhoa_is_phy_external (port)) { + err =phylink_of_phy_connect (port->phylink, dev->dev.of_node,0 ); +if (err) { +netdev_err (dev,"%s: could not attach PHY: %d\n" , __func__, + err); +return err; + } + +phylink_start (port->phylink); + } +netif_tx_start_all_queues (dev); err =airoha_set_vip_for_gdm_port (port, true);if (err)
@@ -1587,19 +1607,36 @@ static int airoha_dev_stop(struct net_device *dev) } } +if (airhoa_is_phy_external (port)) { +phylink_stop (port->phylink); +phylink_disconnect_phy (port->phylink); + } +return 0 ; }static int airoha_dev_set_macaddr (struct net_device *dev,void *p) {struct airoha_gdm_port *port =netdev_priv (dev); +const u8 *mac_addr = dev->dev_addr;int err; err =eth_mac_addr (dev, p);if (err)return err; -airoha_set_macaddr (port, dev->dev_addr); +airoha_set_macaddr (port, mac_addr); + +/* Update XFI mac address */ +if (airhoa_is_phy_external (port)) { +regmap_write (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_MACADDRL , +FIELD_PREP (AIROHA_PCS_XFI_MAC_MACADDRL , + mac_addr[0 ] <<24 | mac_addr[1 ] <<16 | + mac_addr[2 ] <<8 | mac_addr[3 ])); +regmap_write (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_MACADDRH , +FIELD_PREP (AIROHA_PCS_XFI_MAC_MACADDRH , + mac_addr[4 ] <<8 | mac_addr[5 ])); + }return 0 ; }
@@ -2454,6 +2491,210 @@ static void airoha_metadata_dst_free(struct airoha_gdm_port *port) } } +static void airoha_mac_config (struct phylink_config *config,unsigned int mode, +const struct phylink_link_state *state) +{ + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port, + phylink_config); + +/* Frag disable */ +regmap_update_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_RX_FRAG_LEN , +FIELD_PREP (AIROHA_PCS_XFI_RX_FRAG_LEN ,31 )); +regmap_update_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_TX_FRAG_LEN , +FIELD_PREP (AIROHA_PCS_XFI_TX_FRAG_LEN ,31 )); + +/* IPG NUM */ +regmap_update_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_IPG_NUM , +FIELD_PREP (AIROHA_PCS_XFI_IPG_NUM ,10 )); + +/* Enable TX/RX flow control */ +regmap_set_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_TX_FC_EN ); +regmap_set_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_RX_FC_EN ); +} + +static int airoha_mac_prepare (struct phylink_config *config,unsigned int mode, +phy_interface_t iface) +{ + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port, + phylink_config); + +/* MPI MBI disable */ +regmap_set_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_RXMPI_STOP | +AIROHA_PCS_XFI_RXMBI_STOP | +AIROHA_PCS_XFI_TXMPI_STOP | +AIROHA_PCS_XFI_TXMBI_STOP ); + +/* Write 1 to trigger reset and clear */ +regmap_clear_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_LOGIC_RST , +AIROHA_PCS_XFI_MAC_LOGIC_RST ); +regmap_set_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_LOGIC_RST , +AIROHA_PCS_XFI_MAC_LOGIC_RST ); + +usleep_range (1000 ,2000 ); + +/* Clear XFI MAC counter */ +regmap_set_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_CNT_CLR , +AIROHA_PCS_XFI_GLB_CNT_CLR ); + +return 0 ; +} + +static void airoha_mac_link_down (struct phylink_config *config,unsigned int mode, +phy_interface_t interface) +{ + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port, + phylink_config); + +/* MPI MBI disable */ +regmap_set_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_RXMPI_STOP | +AIROHA_PCS_XFI_RXMBI_STOP | +AIROHA_PCS_XFI_TXMPI_STOP | +AIROHA_PCS_XFI_TXMBI_STOP ); +} + +static void airoha_mac_link_up (struct phylink_config *config,struct phy_device *phy, +unsigned int mode,phy_interface_t interface, +int speed,int duplex,bool tx_pause,bool rx_pause) +{ + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port, + phylink_config); +struct airoha_qdma *qdma = port->qdma; +struct airoha_eth *eth = qdma->eth; +u32 frag_size_tx, frag_size_rx; + +switch (speed) { +case SPEED_10000 : +case SPEED_5000 : + frag_size_tx =8 ; + frag_size_rx =8 ; +break ; +case SPEED_2500 : + frag_size_tx =2 ; + frag_size_rx =1 ; +break ; +default : + frag_size_tx =1 ; + frag_size_rx =0 ; + } + +/* Configure TX/RX frag based on speed */ +if (port->id ==4 ) { +airoha_fe_rmw (eth,REG_GDMA4_TMBI_FRAG ,GDMA4_SGMII0_TX_FRAG_SIZE , +FIELD_PREP (GDMA4_SGMII0_TX_FRAG_SIZE , frag_size_tx)); + +airoha_fe_rmw (eth,REG_GDMA4_RMBI_FRAG ,GDMA4_SGMII0_RX_FRAG_SIZE , +FIELD_PREP (GDMA4_SGMII0_RX_FRAG_SIZE , frag_size_rx)); + } + +/* BPI BMI enable */ +regmap_clear_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_RXMPI_STOP | +AIROHA_PCS_XFI_RXMBI_STOP | +AIROHA_PCS_XFI_TXMPI_STOP | +AIROHA_PCS_XFI_TXMBI_STOP ); +} + +static const struct phylink_mac_ops airoha_phylink_ops = { + .mac_config = airoha_mac_config, + .mac_prepare = airoha_mac_prepare, + .mac_link_down = airoha_mac_link_down, + .mac_link_up = airoha_mac_link_up, +}; + +static int airoha_setup_phylink (struct net_device *dev) +{ +struct device_node *pcs_np, *np = dev->dev.of_node; +struct airoha_gdm_port *port =netdev_priv (dev); +struct phylink_pcs **available_pcs; +struct platform_device *pdev; +phy_interface_t phy_mode; +struct phylink *phylink; +unsigned int num_pcs; +int err; + + err =of_get_phy_mode (np, &phy_mode); +if (err) { +dev_err (&dev->dev,"incorrect phy-mode\n" ); +return err; + } + + pcs_np =of_parse_phandle (np,"pcs-handle" ,0 ); +if (!pcs_np) +return -ENODEV ; + +if (!of_device_is_available (pcs_np)) { +of_node_put (pcs_np); +return -ENODEV ; + } + + pdev =of_find_device_by_node (pcs_np); +of_node_put (pcs_np); +if (!pdev || !platform_get_drvdata (pdev)) { +if (pdev) +put_device (&pdev->dev); +return -EPROBE_DEFER ; + } + + port->xfi_mac =dev_get_regmap (&pdev->dev,"xfi_mac" ); +if (IS_ERR (port->xfi_mac)) +return PTR_ERR (port->xfi_mac); + + port->phylink_config.dev = &dev->dev; + port->phylink_config.type =PHYLINK_NETDEV ; + port->phylink_config.mac_capabilities =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 |MAC_1000 |MAC_2500FD | +MAC_5000FD |MAC_10000FD ; + + err =fwnode_phylink_pcs_parse (dev_fwnode (&dev->dev),NULL , &num_pcs); +if (err) +return err; + + available_pcs =kcalloc (num_pcs,sizeof (*available_pcs),GFP_KERNEL ); +if (!available_pcs) +return -ENOMEM ; + + err =fwnode_phylink_pcs_parse (dev_fwnode (&dev->dev), available_pcs, + &num_pcs); +if (err) + goto out; + + port->phylink_config.available_pcs = available_pcs; + port->phylink_config.num_available_pcs = num_pcs; + +__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); +__set_bit (PHY_INTERFACE_MODE_USXGMII , + port->phylink_config.supported_interfaces); + +phy_interface_copy (port->phylink_config.pcs_interfaces, + port->phylink_config.supported_interfaces); + + phylink =phylink_create (&port->phylink_config, +of_fwnode_handle (np), + phy_mode, &airoha_phylink_ops); +if (IS_ERR (phylink)) { + err =PTR_ERR (phylink); + goto out; + } + + port->phylink = phylink; +out: +kfree (available_pcs); + +return err; +} +static int airoha_alloc_gdm_port (struct airoha_eth *eth,struct device_node *np,int index) {
@@ -2532,6 +2773,23 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth,if (err)return err; +if (airhoa_is_phy_external (port)) { +const u8 *mac_addr = dev->dev_addr; + + err =airoha_setup_phylink (dev); +if (err) +return err; + +/* Setup XFI mac address */ +regmap_write (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_MACADDRL , +FIELD_PREP (AIROHA_PCS_XFI_MAC_MACADDRL , + mac_addr[0 ] <<24 | mac_addr[1 ] <<16 | + mac_addr[2 ] <<8 | mac_addr[3 ])); +regmap_write (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_MACADDRH , +FIELD_PREP (AIROHA_PCS_XFI_MAC_MACADDRH , + mac_addr[4 ] <<8 | mac_addr[5 ])); + } +return register_netdev (dev); }
@@ -2626,6 +2884,9 @@ static int airoha_probe(struct platform_device *pdev)struct airoha_gdm_port *port = eth->ports[i];if (port && port->dev->reg_state ==NETREG_REGISTERED ) { +if (airhoa_is_phy_external (port)) +phylink_destroy (port->phylink); +unregister_netdev (port->dev);airoha_metadata_dst_free (port); }
@@ -2653,6 +2914,9 @@ static void airoha_remove(struct platform_device *pdev)continue ;airoha_dev_stop (port->dev); +if (airhoa_is_phy_external (port)) +phylink_destroy (port->phylink); +unregister_netdev (port->dev);airoha_metadata_dst_free (port); }
drivers/net/ethernet/airoha/airoha_eth.h +4 -0
@@ -460,6 +460,10 @@ struct airoha_gdm_port {struct net_device *dev;int id; +struct phylink *phylink; +struct phylink_config phylink_config; +struct regmap *xfi_mac; +struct airoha_hw_stats stats;DECLARE_BITMAP (qos_sq_bmap,AIROHA_NUM_QOS_CHANNELS );
drivers/net/ethernet/airoha/airoha_regs.h +12 -0
@@ -356,6 +356,18 @@#define IP_FRAGMENT_PORT_MASK GENMASK(8, 5)#define IP_FRAGMENT_NBQ_MASK GENMASK(4, 0) +#define REG_GDMA4_TMBI_FRAG 0x2028 +#define GDMA4_SGMII1_TX_WEIGHT GENMASK(31, 26) +#define GDMA4_SGMII1_TX_FRAG_SIZE GENMASK(25, 16) +#define GDMA4_SGMII0_TX_WEIGHT GENMASK(15, 10) +#define GDMA4_SGMII0_TX_FRAG_SIZE GENMASK(9, 0) + +#define REG_GDMA4_RMBI_FRAG 0x202c +#define GDMA4_SGMII1_RX_WEIGHT GENMASK(31, 26) +#define GDMA4_SGMII1_RX_FRAG_SIZE GENMASK(25, 16) +#define GDMA4_SGMII0_RX_WEIGHT GENMASK(15, 10) +#define GDMA4_SGMII0_RX_FRAG_SIZE GENMASK(9, 0) +#define REG_MC_VLAN_EN 0x2100#define MC_VLAN_EN_MASK BIT(0)
include/linux/pcs/pcs-airoha.h +15 -0
@@ -5,7 +5,22 @@/* XFI_MAC */ #define AIROHA_PCS_XFI_MAC_XFI_GIB_CFG 0x0 +#define AIROHA_PCS_XFI_RX_FRAG_LEN GENMASK(26, 22) +#define AIROHA_PCS_XFI_TX_FRAG_LEN GENMASK(21, 17) +#define AIROHA_PCS_XFI_IPG_NUM GENMASK(15, 10)#define AIROHA_PCS_XFI_TX_FC_EN BIT(5)#define AIROHA_PCS_XFI_RX_FC_EN BIT(4) +#define AIROHA_PCS_XFI_RXMPI_STOP BIT(3) +#define AIROHA_PCS_XFI_RXMBI_STOP BIT(2) +#define AIROHA_PCS_XFI_TXMPI_STOP BIT(1) +#define AIROHA_PCS_XFI_TXMBI_STOP BIT(0) +#define AIROHA_PCS_XFI_MAC_XFI_LOGIC_RST 0x10 +#define AIROHA_PCS_XFI_MAC_LOGIC_RST BIT(0) +#define AIROHA_PCS_XFI_MAC_XFI_MACADDRH 0x60 +#define AIROHA_PCS_XFI_MAC_MACADDRH GENMASK(15, 0) +#define AIROHA_PCS_XFI_MAC_XFI_MACADDRL 0x64 +#define AIROHA_PCS_XFI_MAC_MACADDRL GENMASK(31, 0) +#define AIROHA_PCS_XFI_MAC_XFI_CNT_CLR 0x100 +#define AIROHA_PCS_XFI_GLB_CNT_CLR BIT(0)#endif /* __LINUX_PCS_AIROHA_H */
Signature · 1 line
2.48.1
Lorenzo Bianconi
maintainerRe: [RFC PATCH net-next v2 11/11] net: airoha: add phylink support for GDM2/3/4
Quoted 7 lines
Add phylink support for GDM2/3/4 port that require 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.
Signed-off-by Christian Marangi <[email protected]>
Hi Christian,
the patch looks fine to me, just few nits inline.
Regards,
Lorenzo
Quoted 12 lines
--- drivers/net/ethernet/airoha/airoha_eth.c | 266 +++++++++++++++++++++- drivers/net/ethernet/airoha/airoha_eth.h | 4 + drivers/net/ethernet/airoha/airoha_regs.h | 12 + include/linux/pcs/pcs-airoha.h | 15 ++ 4 files changed, 296 insertions(+), 1 deletion(-)drivers/net/ethernet/airoha/airoha_eth.c +0
-0
drivers/net/ethernet/airoha/airoha_eth.c line 12
Quoted 8 lines
drivers/net/ethernet/airoha/airoha_eth.c +3
-0@@ -5,9 +5,13 @@*/ #include <linux/of.h> #include <linux/of_net.h> +#include <linux/of_platform.h> #include <linux/platform_device.h> #include <linux/tcp.h> +#include <linux/pcs/pcs.h> +#include <linux/pcs/pcs-airoha.h>
can you please put includes in alphabetical order?
drivers/net/ethernet/airoha/airoha_eth.c static bool airhoa_is_lan_gdm_port(struct airoha_gdm_port *port) · line 84
Quoted 11 lines
drivers/net/ethernet/airoha/airoha_eth.c +3
-0#include <linux/u64_stats_sync.h> +#include <linux/regmap.h> #include <net/dst_metadata.h> #include <net/page_pool/helpers.h> #include <net/pkt_cls.h> @@ -76,6 +80,11 @@ static bool airhoa_is_lan_gdm_port(struct airoha_gdm_port *port)return port->id ==1 ; } +static bool airhoa_is_phy_external (struct airoha_gdm_port *port) +{
I guess you can add a comment here.
Quoted 38 lines
drivers/net/ethernet/airoha/airoha_eth.c +19
-0+return port->id !=1 ; +} +static void airoha_set_macaddr (struct airoha_gdm_port *port,const u8 *addr) {struct airoha_eth *eth = port->qdma->eth;@@ -1535,6 +1544,17 @@ static int airoha_dev_open(struct net_device *dev)struct airoha_gdm_port *port =netdev_priv (dev);struct airoha_qdma *qdma = port->qdma; +if (airhoa_is_phy_external (port)) { + err =phylink_of_phy_connect (port->phylink, dev->dev.of_node,0 ); +if (err) { +netdev_err (dev,"%s: could not attach PHY: %d\n" , __func__, + err); +return err; + } + +phylink_start (port->phylink); + } +netif_tx_start_all_queues (dev); err =airoha_set_vip_for_gdm_port (port, true);if (err)@@ -1587,19 +1607,36 @@ static int airoha_dev_stop(struct net_device *dev) } } +if (airhoa_is_phy_external (port)) { +phylink_stop (port->phylink); +phylink_disconnect_phy (port->phylink); + } +return 0 ; }static int airoha_dev_set_macaddr (struct net_device *dev,void *p) {
drivers/net/ethernet/airoha/airoha_eth.c static int airoha_dev_stop(struct net_device *dev) · line 1628
Quoted 10 lines
drivers/net/ethernet/airoha/airoha_eth.c +2
-1struct airoha_gdm_port *port =netdev_priv (dev); +const u8 *mac_addr = dev->dev_addr;int err; err =eth_mac_addr (dev, p);if (err)return err; -airoha_set_macaddr (port, dev->dev_addr); +airoha_set_macaddr (port, mac_addr);
this is not required.
Quoted 32 lines
drivers/net/ethernet/airoha/airoha_eth.c +25
-0+ +/* Update XFI mac address */ +if (airhoa_is_phy_external (port)) { +regmap_write (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_MACADDRL , +FIELD_PREP (AIROHA_PCS_XFI_MAC_MACADDRL , + mac_addr[0 ] <<24 | mac_addr[1 ] <<16 | + mac_addr[2 ] <<8 | mac_addr[3 ])); +regmap_write (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_MACADDRH , +FIELD_PREP (AIROHA_PCS_XFI_MAC_MACADDRH , + mac_addr[4 ] <<8 | mac_addr[5 ])); + }return 0 ; }@@ -2454,6 +2491,210 @@ static void airoha_metadata_dst_free(struct airoha_gdm_port *port) } } +static void airoha_mac_config (struct phylink_config *config,unsigned int mode, +const struct phylink_link_state *state) +{ + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port, + phylink_config); + +/* Frag disable */ +regmap_update_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_RX_FRAG_LEN , +FIELD_PREP (AIROHA_PCS_XFI_RX_FRAG_LEN ,31 )); +regmap_update_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_TX_FRAG_LEN , +FIELD_PREP (AIROHA_PCS_XFI_TX_FRAG_LEN ,31 )); +
drivers/net/ethernet/airoha/airoha_eth.c static void airoha_metadata_dst_free(struct airoha_gdm_port *port) · line 2517
Quoted 10 lines
drivers/net/ethernet/airoha/airoha_eth.c +10
-0+/* IPG NUM */ +regmap_update_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_IPG_NUM , +FIELD_PREP (AIROHA_PCS_XFI_IPG_NUM ,10 )); + +/* Enable TX/RX flow control */ +regmap_set_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_TX_FC_EN ); +regmap_set_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_RX_FC_EN );
I guess you can squash all the regmap_update_bits here.
Quoted 57 lines
drivers/net/ethernet/airoha/airoha_eth.c +57
-0+} + +static int airoha_mac_prepare (struct phylink_config *config,unsigned int mode, +phy_interface_t iface) +{ + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port, + phylink_config); + +/* MPI MBI disable */ +regmap_set_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_RXMPI_STOP | +AIROHA_PCS_XFI_RXMBI_STOP | +AIROHA_PCS_XFI_TXMPI_STOP | +AIROHA_PCS_XFI_TXMBI_STOP ); + +/* Write 1 to trigger reset and clear */ +regmap_clear_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_LOGIC_RST , +AIROHA_PCS_XFI_MAC_LOGIC_RST ); +regmap_set_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_LOGIC_RST , +AIROHA_PCS_XFI_MAC_LOGIC_RST ); + +usleep_range (1000 ,2000 ); + +/* Clear XFI MAC counter */ +regmap_set_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_CNT_CLR , +AIROHA_PCS_XFI_GLB_CNT_CLR ); + +return 0 ; +} + +static void airoha_mac_link_down (struct phylink_config *config,unsigned int mode, +phy_interface_t interface) +{ + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port, + phylink_config); + +/* MPI MBI disable */ +regmap_set_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_RXMPI_STOP | +AIROHA_PCS_XFI_RXMBI_STOP | +AIROHA_PCS_XFI_TXMPI_STOP | +AIROHA_PCS_XFI_TXMBI_STOP ); +} + +static void airoha_mac_link_up (struct phylink_config *config,struct phy_device *phy, +unsigned int mode,phy_interface_t interface, +int speed,int duplex,bool tx_pause,bool rx_pause) +{ + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port, + phylink_config); +struct airoha_qdma *qdma = port->qdma; +struct airoha_eth *eth = qdma->eth; +u32 frag_size_tx, frag_size_rx; + +switch (speed) { +case SPEED_10000 : +case SPEED_5000 :
drivers/net/ethernet/airoha/airoha_eth.c static void airoha_metadata_dst_free(struct airoha_gdm_port *port) · line 2584
Quoted 10 lines
drivers/net/ethernet/airoha/airoha_eth.c +10
-0+ frag_size_tx =8 ; + frag_size_rx =8 ; +break ; +case SPEED_2500 : + frag_size_tx =2 ; + frag_size_rx =1 ; +break ; +default : + frag_size_tx =1 ; + frag_size_rx =0 ;
missing break
Quoted 34 lines
drivers/net/ethernet/airoha/airoha_eth.c +34
-0+ } + +/* Configure TX/RX frag based on speed */ +if (port->id ==4 ) { +airoha_fe_rmw (eth,REG_GDMA4_TMBI_FRAG ,GDMA4_SGMII0_TX_FRAG_SIZE , +FIELD_PREP (GDMA4_SGMII0_TX_FRAG_SIZE , frag_size_tx)); + +airoha_fe_rmw (eth,REG_GDMA4_RMBI_FRAG ,GDMA4_SGMII0_RX_FRAG_SIZE , +FIELD_PREP (GDMA4_SGMII0_RX_FRAG_SIZE , frag_size_rx)); + } + +/* BPI BMI enable */ +regmap_clear_bits (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_GIB_CFG , +AIROHA_PCS_XFI_RXMPI_STOP | +AIROHA_PCS_XFI_RXMBI_STOP | +AIROHA_PCS_XFI_TXMPI_STOP | +AIROHA_PCS_XFI_TXMBI_STOP ); +} + +static const struct phylink_mac_ops airoha_phylink_ops = { + .mac_config = airoha_mac_config, + .mac_prepare = airoha_mac_prepare, + .mac_link_down = airoha_mac_link_down, + .mac_link_up = airoha_mac_link_up, +}; + +static int airoha_setup_phylink (struct net_device *dev) +{ +struct device_node *pcs_np, *np = dev->dev.of_node; +struct airoha_gdm_port *port =netdev_priv (dev); +struct phylink_pcs **available_pcs; +struct platform_device *pdev; +phy_interface_t phy_mode; +struct phylink *phylink;
drivers/net/ethernet/airoha/airoha_eth.c static void airoha_metadata_dst_free(struct airoha_gdm_port *port) · line 2628
Quoted 10 lines
drivers/net/ethernet/airoha/airoha_eth.c +10
-0+unsigned int num_pcs; +int err; + + err =of_get_phy_mode (np, &phy_mode); +if (err) { +dev_err (&dev->dev,"incorrect phy-mode\n" ); +return err; + } + + pcs_np =of_parse_phandle (np,"pcs-handle" ,0 );
I guess you need to update airoha,en7581-eth.yaml, don't you?
Quoted 21 lines
drivers/net/ethernet/airoha/airoha_eth.c +21
-0+if (!pcs_np) +return -ENODEV ; + +if (!of_device_is_available (pcs_np)) { +of_node_put (pcs_np); +return -ENODEV ; + } + + pdev =of_find_device_by_node (pcs_np); +of_node_put (pcs_np); +if (!pdev || !platform_get_drvdata (pdev)) { +if (pdev) +put_device (&pdev->dev); +return -EPROBE_DEFER ; + } + + port->xfi_mac =dev_get_regmap (&pdev->dev,"xfi_mac" ); +if (IS_ERR (port->xfi_mac)) +return PTR_ERR (port->xfi_mac); + + port->phylink_config.dev = &dev->dev;
drivers/net/ethernet/airoha/airoha_eth.c static void airoha_metadata_dst_free(struct airoha_gdm_port *port) · line 2659
Quoted 10 lines
drivers/net/ethernet/airoha/airoha_eth.c +10
-0+ port->phylink_config.type =PHYLINK_NETDEV ; + port->phylink_config.mac_capabilities =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 |MAC_1000 |MAC_2500FD | +MAC_5000FD |MAC_10000FD ; + + err =fwnode_phylink_pcs_parse (dev_fwnode (&dev->dev),NULL , &num_pcs); +if (err) +return err; + + available_pcs =kcalloc (num_pcs,sizeof (*available_pcs),GFP_KERNEL );
you can use devm_kcalloc() here.
Quoted 153 lines
drivers/net/ethernet/airoha/airoha_eth.c +61
-0+if (!available_pcs) +return -ENOMEM ; + + err =fwnode_phylink_pcs_parse (dev_fwnode (&dev->dev), available_pcs, + &num_pcs); +if (err) + goto out; + + port->phylink_config.available_pcs = available_pcs; + port->phylink_config.num_available_pcs = num_pcs; + +__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); +__set_bit (PHY_INTERFACE_MODE_USXGMII , + port->phylink_config.supported_interfaces); + +phy_interface_copy (port->phylink_config.pcs_interfaces, + port->phylink_config.supported_interfaces); + + phylink =phylink_create (&port->phylink_config, +of_fwnode_handle (np), + phy_mode, &airoha_phylink_ops); +if (IS_ERR (phylink)) { + err =PTR_ERR (phylink); + goto out; + } + + port->phylink = phylink; +out: +kfree (available_pcs); + +return err; +} +static int airoha_alloc_gdm_port (struct airoha_eth *eth,struct device_node *np,int index) {@@ -2532,6 +2773,23 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth,if (err)return err; +if (airhoa_is_phy_external (port)) { +const u8 *mac_addr = dev->dev_addr; + + err =airoha_setup_phylink (dev); +if (err) +return err; + +/* Setup XFI mac address */ +regmap_write (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_MACADDRL , +FIELD_PREP (AIROHA_PCS_XFI_MAC_MACADDRL , + mac_addr[0 ] <<24 | mac_addr[1 ] <<16 | + mac_addr[2 ] <<8 | mac_addr[3 ])); +regmap_write (port->xfi_mac,AIROHA_PCS_XFI_MAC_XFI_MACADDRH , +FIELD_PREP (AIROHA_PCS_XFI_MAC_MACADDRH , + mac_addr[4 ] <<8 | mac_addr[5 ])); + } +return register_netdev (dev); }@@ -2626,6 +2884,9 @@ static int airoha_probe(struct platform_device *pdev)struct airoha_gdm_port *port = eth->ports[i];if (port && port->dev->reg_state ==NETREG_REGISTERED ) { +if (airhoa_is_phy_external (port)) +phylink_destroy (port->phylink); +unregister_netdev (port->dev);airoha_metadata_dst_free (port); }@@ -2653,6 +2914,9 @@ static void airoha_remove(struct platform_device *pdev)continue ;airoha_dev_stop (port->dev); +if (airhoa_is_phy_external (port)) +phylink_destroy (port->phylink); +unregister_netdev (port->dev);airoha_metadata_dst_free (port); }drivers/net/ethernet/airoha/airoha_eth.h +4
-0@@ -460,6 +460,10 @@ struct airoha_gdm_port {struct net_device *dev;int id; +struct phylink *phylink; +struct phylink_config phylink_config; +struct regmap *xfi_mac; +struct airoha_hw_stats stats;DECLARE_BITMAP (qos_sq_bmap,AIROHA_NUM_QOS_CHANNELS );drivers/net/ethernet/airoha/airoha_regs.h +12
-0@@ -356,6 +356,18 @@#define IP_FRAGMENT_PORT_MASK GENMASK(8, 5)#define IP_FRAGMENT_NBQ_MASK GENMASK(4, 0) +#define REG_GDMA4_TMBI_FRAG 0x2028 +#define GDMA4_SGMII1_TX_WEIGHT GENMASK(31, 26) +#define GDMA4_SGMII1_TX_FRAG_SIZE GENMASK(25, 16) +#define GDMA4_SGMII0_TX_WEIGHT GENMASK(15, 10) +#define GDMA4_SGMII0_TX_FRAG_SIZE GENMASK(9, 0) + +#define REG_GDMA4_RMBI_FRAG 0x202c +#define GDMA4_SGMII1_RX_WEIGHT GENMASK(31, 26) +#define GDMA4_SGMII1_RX_FRAG_SIZE GENMASK(25, 16) +#define GDMA4_SGMII0_RX_WEIGHT GENMASK(15, 10) +#define GDMA4_SGMII0_RX_FRAG_SIZE GENMASK(9, 0) +#define REG_MC_VLAN_EN 0x2100#define MC_VLAN_EN_MASK BIT(0)include/linux/pcs/pcs-airoha.h +15
-0@@ -5,7 +5,22 @@/* XFI_MAC */ #define AIROHA_PCS_XFI_MAC_XFI_GIB_CFG 0x0 +#define AIROHA_PCS_XFI_RX_FRAG_LEN GENMASK(26, 22) +#define AIROHA_PCS_XFI_TX_FRAG_LEN GENMASK(21, 17) +#define AIROHA_PCS_XFI_IPG_NUM GENMASK(15, 10)#define AIROHA_PCS_XFI_TX_FC_EN BIT(5)#define AIROHA_PCS_XFI_RX_FC_EN BIT(4) +#define AIROHA_PCS_XFI_RXMPI_STOP BIT(3) +#define AIROHA_PCS_XFI_RXMBI_STOP BIT(2) +#define AIROHA_PCS_XFI_TXMPI_STOP BIT(1) +#define AIROHA_PCS_XFI_TXMBI_STOP BIT(0) +#define AIROHA_PCS_XFI_MAC_XFI_LOGIC_RST 0x10 +#define AIROHA_PCS_XFI_MAC_LOGIC_RST BIT(0) +#define AIROHA_PCS_XFI_MAC_XFI_MACADDRH 0x60 +#define AIROHA_PCS_XFI_MAC_MACADDRH GENMASK(15, 0) +#define AIROHA_PCS_XFI_MAC_XFI_MACADDRL 0x64 +#define AIROHA_PCS_XFI_MAC_MACADDRL GENMASK(31, 0) +#define AIROHA_PCS_XFI_MAC_XFI_CNT_CLR 0x100 +#define AIROHA_PCS_XFI_GLB_CNT_CLR BIT(0)#endif /* __LINUX_PCS_AIROHA_H */ Signature · 1 line
2.48.1