Phylink integration improvements for Felix DSA driver
Subsystems (6)
Vladimir Oltean
maintainerv3 cover Phylink integration improvements for Felix DSA driver
From: Vladimir Oltean <[email protected]>
This is an overhaul of the Felix switch driver's phylink operations.
Patches 1, 3, 4 and 5 are cleanup, patch 2 is adding a new feature and and patch 6 is adaptation to the new format of an existing phylink API (mac_link_up).
Changes since v2:
- Replaced "PHYLINK" with "phylink".
- Rewrote commit message of patch 5/6.
Changes since v1:
- Now using phy_clear_bits and phy_set_bits instead of plain writes to MII_BMCR. This combines former patches 1/7 and 6/7 into a single new patch 1/6.
- Updated commit message of patch 5/6.
Vladimir Oltean (6):
net: dsa: felix: clarify the intention of writes to MII_BMCR
net: dsa: felix: support half-duplex link modes
net: dsa: felix: unconditionally configure MAC speed to 1000Mbps
net: dsa: felix: set proper pause frame timers based on link speed
net: dsa: felix: delete .phylink_mac_an_restart code
net: dsa: felix: use resolved link config in mac_link_up()
drivers/net/dsa/ocelot/felix.c | 108 +++++---- drivers/net/dsa/ocelot/felix.h | 11 +- drivers/net/dsa/ocelot/felix_vsc9959.c | 298 ++++++++++++------------- include/linux/fsl/enetc_mdio.h | 1 + 4 files changed, 213 insertions(+), 205 deletions(-)
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v3 1/6 net: dsa: felix: clarify the intention of writes to MII_BMCR
From: Vladimir Oltean <[email protected]>
The driver appears to write to BMCR_SPEED and BMCR_DUPLEX, fields which are read-only, since they are actually configured through the vendor-specific IF_MODE (0x14) register.
But the reason we're writing back the read-only values of MII_BMCR is to alter these writable fields:
BMCR_RESETBMCR_LOOPBACKBMCR_ANENABLEBMCR_PDOWNBMCR_ISOLATEBMCR_ANRESTART
In particular, the only field which is really relevant to this driver is BMCR_ANENABLE. Clarify that intention by spelling it out, using phy_set_bits and phy_clear_bits.
The driver also made a few writes to BMCR_RESET and BMCR_ANRESTART which are unnecessary and may temporarily disrupt the link to the PHY. Remove them.
---
Changes in v3:
None.
Changes in v2:
Patch is new.
drivers/net/dsa/ocelot/felix_vsc9959.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/net/dsa/ocelot/felix_vsc9959.c +3 -8
@@ -815,7 +815,7 @@ static void vsc9959_pcs_init_sgmii(struct phy_device *pcs,phy_write (pcs,ENETC_PCS_LINK_TIMER2 ,ENETC_PCS_LINK_TIMER2_VAL ); -phy_write (pcs,MII_BMCR ,BMCR_ANRESTART |BMCR_ANENABLE ); +phy_set_bits (pcs,MII_BMCR ,BMCR_ANENABLE ); }else {int speed;
@@ -845,10 +845,7 @@ static void vsc9959_pcs_init_sgmii(struct phy_device *pcs,ENETC_PCS_IF_MODE_SGMII_EN | ENETC_PCS_IF_MODE_SGMII_SPEED(speed)); -/* Yes, not a mistake: speed is given by IF_MODE. */ -phy_write (pcs,MII_BMCR ,BMCR_RESET | -BMCR_SPEED1000 | -BMCR_FULLDPLX ); +phy_clear_bits (pcs,MII_BMCR ,BMCR_ANENABLE ); } }
@@ -882,9 +879,7 @@ static void vsc9959_pcs_init_2500basex(struct phy_device *pcs,ENETC_PCS_IF_MODE_SGMII_EN | ENETC_PCS_IF_MODE_SGMII_SPEED(ENETC_PCS_SPEED_2500)); -phy_write (pcs,MII_BMCR ,BMCR_SPEED1000 | -BMCR_FULLDPLX | -BMCR_RESET ); +phy_clear_bits (pcs,MII_BMCR ,BMCR_ANENABLE ); } static void vsc9959_pcs_init_usxgmii(struct phy_device *pcs,
Signature · 1 line
2.25.1
Re: [PATCH v3 net-next 1/6] net: dsa: felix: clarify the intention of writes to MII_BMCR
Quoted 20 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
The driver appears to write to
BMCR_SPEEDandBMCR_DUPLEX, fields which are read-only, since they are actually configured through the vendor-specificIF_MODE(0x14) register.But the reason we're writing back the read-only values of
MII_BMCRis to alter these writable fields:
BMCR_RESETBMCR_LOOPBACKBMCR_ANENABLEBMCR_PDOWNBMCR_ISOLATEBMCR_ANRESTARTIn particular, the only field which is really relevant to this driver is
BMCR_ANENABLE. Clarify that intention by spelling it out, usingphy_set_bitsandphy_clear_bits.
Quoted 5 lines
The driver also made a few writes to
BMCR_RESETandBMCR_ANRESTARTwhich are unnecessary and may temporarily disrupt the link to the PHY. Remove them.Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v3 2/6 net: dsa: felix: support half-duplex link modes
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Ping tested:
[ 11.808455] mscc_felix 0000:00:00.5 swp0: Link is Up - 1Gbps/Full - flow control rx/tx [ 11.816497] IPv6: ADDRCONF(NETDEV_CHANGE): swp0: link becomes ready
[root@LS1028ARDB ~] # ethtool -s swp0 advertise 0x4
[ 18.844591] mscc_felix 0000:00:00.5 swp0: Link is Down [ 22.048337] mscc_felix 0000:00:00.5 swp0: Link is Up - 100Mbps/Half - flow control off
[root@LS1028ARDB ~] # ip addr add 192.168.1.1/24 dev swp0
[root@LS1028ARDB ~] # ping 192.168.1.2
PING 192.168.1.2 (192.168.1.2): 56 data bytes (...)
^C--- 192.168.1.2 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 0.383/0.611/1.051 ms
[root@LS1028ARDB ~] # ethtool -s swp0 advertise 0x10
[ 355.637747] mscc_felix 0000:00:00.5 swp0: Link is Down [ 358.788034] mscc_felix 0000:00:00.5 swp0: Link is Up - 1Gbps/Half - flow control off
[root@LS1028ARDB ~] # ping 192.168.1.2
PING 192.168.1.2 (192.168.1.2): 56 data bytes (...)
^C
--- 192.168.1.2 ping statistics ---
16 packets transmitted, 16 packets received, 0% packet loss round-trip min/avg/max = 0.301/0.384/1.138 ms
---
Changes in v3:
None.
Changes in v2:
None.
Note: this patch is still using state->duplex from mac_config(), although that will be changed in 6/6.
drivers/net/dsa/ocelot/felix.c | 4 +++- drivers/net/dsa/ocelot/felix_vsc9959.c | 23 +++++++++++++---------- include/linux/fsl/enetc_mdio.h | 1 + 3 files changed, 17 insertions(+), 11 deletions(-)
drivers/net/dsa/ocelot/felix.c +3 -1
@@ -194,13 +194,15 @@ static void felix_phylink_validate(struct dsa_switch *ds, int port,return ; } -/* No half-duplex. */ phylink_set_port_modes (mask);phylink_set (mask, Autoneg);phylink_set (mask, Pause);phylink_set (mask, Asym_Pause); + phylink_set(mask, 10baseT_Half); phylink_set(mask, 10baseT_Full); + phylink_set(mask, 100baseT_Half); phylink_set(mask, 100baseT_Full); + phylink_set(mask, 1000baseT_Half); phylink_set(mask, 1000baseT_Full); if (state->interface == PHY_INTERFACE_MODE_INTERNAL ||
drivers/net/dsa/ocelot/felix_vsc9959.c +13 -10
@@ -817,12 +817,9 @@ static void vsc9959_pcs_init_sgmii(struct phy_device *pcs,phy_set_bits (pcs,MII_BMCR ,BMCR_ANENABLE ); }else { +u16 if_mode =ENETC_PCS_IF_MODE_SGMII_EN ;int speed; -if (state->duplex ==DUPLEX_HALF ) { -phydev_err (pcs,"Half duplex not supported\n" ); -return ; - }switch (state->speed) {case SPEED_1000 : speed =ENETC_PCS_SPEED_1000 ;
@@ -841,9 +838,9 @@ static void vsc9959_pcs_init_sgmii(struct phy_device *pcs,return ; } -phy_write (pcs,ENETC_PCS_IF_MODE , -ENETC_PCS_IF_MODE_SGMII_EN | -ENETC_PCS_IF_MODE_SGMII_SPEED (speed)); + if_mode |=ENETC_PCS_IF_MODE_SGMII_SPEED (speed); +if (state->duplex ==DUPLEX_HALF ) + if_mode |=ENETC_PCS_IF_MODE_DUPLEX_HALF ;phy_clear_bits (pcs,MII_BMCR ,BMCR_ANENABLE ); }
@@ -870,15 +867,18 @@ static void vsc9959_pcs_init_2500basex(struct phy_device *pcs,unsigned int link_an_mode, const struct phylink_link_state *state) { + u16 if_mode = ENETC_PCS_IF_MODE_SGMII_SPEED(ENETC_PCS_SPEED_2500) | +ENETC_PCS_IF_MODE_SGMII_EN ; +if (link_an_mode ==MLO_AN_INBAND ) {phydev_err (pcs,"AN not supported on 3.125GHz SerDes lane\n" );return ; } -phy_write (pcs,ENETC_PCS_IF_MODE , -ENETC_PCS_IF_MODE_SGMII_EN | -ENETC_PCS_IF_MODE_SGMII_SPEED (ENETC_PCS_SPEED_2500 )); +if (state->duplex ==DUPLEX_HALF ) + if_mode |=ENETC_PCS_IF_MODE_DUPLEX_HALF ; +phy_write (pcs,ENETC_PCS_IF_MODE , if_mode);phy_clear_bits (pcs,MII_BMCR ,BMCR_ANENABLE ); }
@@ -919,8 +919,11 @@ static void vsc9959_pcs_init(struct ocelot *ocelot, int port,linkmode_set_bit_array (phy_basic_ports_array,ARRAY_SIZE (phy_basic_ports_array), pcs->supported); +linkmode_set_bit (ETHTOOL_LINK_MODE_10baseT_Half_BIT, pcs->supported);linkmode_set_bit (ETHTOOL_LINK_MODE_10baseT_Full_BIT, pcs->supported); +linkmode_set_bit (ETHTOOL_LINK_MODE_100baseT_Half_BIT, pcs->supported);linkmode_set_bit (ETHTOOL_LINK_MODE_100baseT_Full_BIT, pcs->supported); +linkmode_set_bit (ETHTOOL_LINK_MODE_1000baseT_Half_BIT, pcs->supported);linkmode_set_bit (ETHTOOL_LINK_MODE_1000baseT_Full_BIT, pcs->supported);if (pcs->interface ==PHY_INTERFACE_MODE_2500BASEX || pcs->interface ==PHY_INTERFACE_MODE_USXGMII )
include/linux/fsl/enetc_mdio.h +1 -0
@@ -15,6 +15,7 @@#define ENETC_PCS_IF_MODE_SGMII_EN BIT(0)#define ENETC_PCS_IF_MODE_USE_SGMII_AN BIT(1)#define ENETC_PCS_IF_MODE_SGMII_SPEED (x) (((x) << 2) & GENMASK(3, 2)) +#define ENETC_PCS_IF_MODE_DUPLEX_HALF BIT(3)/* Not a mistake, the SerDes PLL needs to be set at 3.125 GHz by Reset * Configuration Word (RCW, outside Linux control) for 2.5G SGMII mode. The PCS
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v3 3/6 net: dsa: felix: unconditionally configure MAC speed to 1000Mbps
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
In VSC9959, the PCS is the one who performs rate adaptation (symbol duplication) to the speed negotiated by the PHY. The MAC is unaware of that and must remain configured for gigabit. If it is configured at OCELOT_SPEED_10 or OCELOT_SPEED_100, it'll start transmitting PAUSE frames out of control and never recover, _even if_ we then reconfigure it at OCELOT_SPEED_1000 afterwards.
This patch fixes a bug that luckily did not have any functional impact. We were writing 10, 100, 1000 etc into this 2-bit field in DEV_CLOCK_CFG, but the hardware expects values in the range 0, 1, 2, 3. So all speed values were getting truncated to 0, which is OCELOT_SPEED_2500, and which also appears to be fine.
---
Changes in v3:
None.
Changes in v2:
None.
drivers/net/dsa/ocelot/felix.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/dsa/ocelot/felix.c +7 -2
@@ -240,9 +240,14 @@ static void felix_phylink_mac_config(struct dsa_switch *ds, int port,u32 mac_fc_cfg;/* Take port out of reset by clearing the MAC_TX_RST, MAC_RX_RST and -* PORT_RST bits in CLOCK_CFG +* PORT_RST bits in DEV_CLOCK_CFG. Note that the way this system is +* integrated is that the MAC speed is fixed and it's the PCS who is +* performing the rate adaptation, so we have to write "1000Mbps" into +* the LINK_SPEED field of DEV_CLOCK_CFG (which is also its default +* value). */ -ocelot_port_writel (ocelot_port,DEV_CLOCK_CFG_LINK_SPEED (state->speed), +ocelot_port_writel (ocelot_port, +DEV_CLOCK_CFG_LINK_SPEED (OCELOT_SPEED_1000 ),DEV_CLOCK_CFG );/* Flow control. Link speed is only used here to evaluate the time
Signature · 1 line
2.25.1
Re: [PATCH v3 net-next 3/6] net: dsa: felix: unconditionally configure MAC speed to 1000Mbps
Quoted 9 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
In VSC9959, the PCS is the one who performs rate adaptation (symbol duplication) to the speed negotiated by the PHY. The MAC is unaware of that and must remain configured for gigabit. If it is configured at
OCELOT_SPEED_10orOCELOT_SPEED_100, it'll start transmitting PAUSE frames out of control and never recover,_evenif_we then reconfigure it atOCELOT_SPEED_1000afterwards.
Quoted 7 lines
This patch fixes a bug that luckily did not have any functional impact. We were writing 10, 100, 1000 etc into this 2-bit field in
DEV_CLOCK_CFG, but the hardware expects values in the range 0, 1, 2, 3. So all speed values were getting truncated to 0, which isOCELOT_SPEED_2500, and which also appears to be fine.Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v3 4/6 net: dsa: felix: set proper pause frame timers based on link speed
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
state->speed holds a value of 10, 100, 1000 or 2500, but SYS_MAC_FC_CFG_FC_LINK_SPEED expects a value in the range 0, 1, 2 or 3.
So set the correct speed encoding into this register.
---
Changes in v3:
None.
Changes in v2:
None.
drivers/net/dsa/ocelot/felix.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/net/dsa/ocelot/felix.c +23 -4
@@ -250,10 +250,25 @@ static void felix_phylink_mac_config(struct dsa_switch *ds, int port,DEV_CLOCK_CFG_LINK_SPEED (OCELOT_SPEED_1000 ), DEV_CLOCK_CFG); -/* Flow control. Link speed is only used here to evaluate the time -* specification in incoming pause frames. -*/ - mac_fc_cfg =SYS_MAC_FC_CFG_FC_LINK_SPEED (state->speed); +switch (state->speed) { +case SPEED_10 : + mac_fc_cfg =SYS_MAC_FC_CFG_FC_LINK_SPEED (3 ); +break ; +case SPEED_100 : + mac_fc_cfg =SYS_MAC_FC_CFG_FC_LINK_SPEED (2 ); +break ; +case SPEED_1000 : +case SPEED_2500 : + mac_fc_cfg =SYS_MAC_FC_CFG_FC_LINK_SPEED (1 ); +break ; +case SPEED_UNKNOWN : + mac_fc_cfg =SYS_MAC_FC_CFG_FC_LINK_SPEED (0 ); +break ; +default : +dev_err (ocelot->dev,"Unsupported speed on port %d: %d\n" , + port, state->speed); +return ; + }/* handle Rx pause in all cases, with 2500base-X this is used for rate * adaptation.
@@ -265,6 +280,10 @@ static void felix_phylink_mac_config(struct dsa_switch *ds, int port,SYS_MAC_FC_CFG_PAUSE_VAL_CFG (0xffff ) |SYS_MAC_FC_CFG_FC_LATENCY_CFG (0x7 ) |SYS_MAC_FC_CFG_ZERO_PAUSE_ENA ; + +/* Flow control. Link speed is only used here to evaluate the time +* specification in incoming pause frames. +*/ ocelot_write_rix (ocelot, mac_fc_cfg,SYS_MAC_FC_CFG , port);ocelot_write_rix (ocelot,0 ,ANA_POL_FLOWC , port);
Signature · 1 line
2.25.1
Re: [PATCH v3 net-next 4/6] net: dsa: felix: set proper pause frame timers based on link speed
Quoted 8 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
state->speedholds a value of 10, 100, 1000 or 2500, butSYS_MAC_FC_CFG_FC_LINK_SPEEDexpects a value in the range 0, 1, 2 or 3.So set the correct speed encoding into this register.
Signed-off-by Vladimir Oltean <[email protected]>
Did you want to provide a Fixes: tag for this change?
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 4/6] net: dsa: felix: set proper pause frame timers based on link speed
Hi Florian,
Quoted 8 lines · Florian Fainelli
Quoted 5 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
state->speedholds a value of 10, 100, 1000 or 2500, butSYS_MAC_FC_CFG_FC_LINK_SPEEDexpects a value in the range 0, 1, 2 or 3.
Quoted 9 lines
Quoted 3 lines
So set the correct speed encoding into this register.
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>Did you want to provide a Fixes: tag for this change?
Signature · 1 line
Florian
I am not really sure how fine-grained this really is. Some testing with dedicated testing equipment was done even with the old values, and I don't remember that it raised any eyebrows at the time. I would prefer to not use the "Fixes:" tag here, just to be on the safe side.
Thanks,
-Vladimir
Vladimir Oltean
maintainerPATCH v3 5/6 net: dsa: felix: delete .phylink_mac_an_restart code
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Phylink uses the .mac_an_restart method to offer the user an implementation of the "ethtool -r" behavior, when the media-side auto negotiation can be restarted by the local MAC PCS. This is the case for fiber modes 1000Base-X and 2500Base-X (IEEE clause 37) that don't have an Ethernet PHY connected locally, and the media is connected to the MAC PCS directly.
On the other hand, the Cisco SGMII and USXGMII standards also have an auto negotiation mechanism based on IEEE 802.3 clause 37 (their respective specs require a MAC PCS and a PHY PCS to implement the same state machine, which is described in IEEE 802.3 "Auto-Negotiation Figure 37-6"), so the ability to restart auto-negotiation is intrinsically symmetrical (the MAC PCS can do it too).
However, it appears that not all SGMII/USXGMII PHYs have logic to restart the MDI-side auto-negotiation process when they detect a transition of the SGMII link from data mode to configuration mode. Some do (VSC8234) and some don't (AR8033, MV88E1111). IEEE and/or Cisco specification wordings to not help to prove whether propagating the "AN restart" event from MII side ("mr_restart_an") to MDI side ("mr_restart_negotiation") is required behavior - neither of them specifies any mandatory interaction between the clause 37 AN state machine from Figure 37-6 and the clause 28 AN state machine from Figure 28-18.
Therefore, even if a certain behavior could be proven as being required, real-life SGMII/USXGMII PHYs are inconsistent enough that a clause 37 AN restart cannot be used by phylink to reliably trigger a media-side renegotiation, when the user requests it via ethtool.
The only remaining use that the .mac_an_restart callback might possibly have, given what we know now, is to implement some silicon quirks, but so far that has proven to not be necessary.
So remove this code for now, since it never gets called and we don't foresee any circumstance in which it might be, either.
---
Changes in v3:
Update commit message to remove the lecturing tone, shorten the description, acknowledge what phylink is trying to achieve with the method and the fact that SGMII/USXGMII cannot achieve that.
Changes in v2:
Update commit message to be more clear.
drivers/net/dsa/ocelot/felix.c | 10 ------- drivers/net/dsa/ocelot/felix.h | 1 - drivers/net/dsa/ocelot/felix_vsc9959.c | 37 -------------------------- 3 files changed, 48 deletions(-)
drivers/net/dsa/ocelot/felix.c +0 -10
@@ -296,15 +296,6 @@ static void felix_phylink_mac_config(struct dsa_switch *ds, int port, state->speed); } -static void felix_phylink_mac_an_restart (struct dsa_switch *ds,int port) -{ -struct ocelot *ocelot = ds->priv; -struct felix *felix =ocelot_to_felix (ocelot); - -if (felix->info->pcs_an_restart) - felix->info->pcs_an_restart (ocelot, port); -} -static void felix_phylink_mac_link_down (struct dsa_switch *ds,int port,unsigned int link_an_mode,phy_interface_t interface)
@@ -810,7 +801,6 @@ static const struct dsa_switch_ops felix_switch_ops = { .phylink_validate = felix_phylink_validate, .phylink_mac_link_state = felix_phylink_mac_pcs_get_state, .phylink_mac_config = felix_phylink_mac_config, - .phylink_mac_an_restart = felix_phylink_mac_an_restart, .phylink_mac_link_down = felix_phylink_mac_link_down, .phylink_mac_link_up = felix_phylink_mac_link_up, .port_enable = felix_port_enable,
drivers/net/dsa/ocelot/felix.h +0 -1
@@ -31,7 +31,6 @@ struct felix_info {void (*pcs_init)(struct ocelot *ocelot,int port,unsigned int link_an_mode,const struct phylink_link_state *state); -void (*pcs_an_restart)(struct ocelot *ocelot,int port);void (*pcs_link_state)(struct ocelot *ocelot,int port,struct phylink_link_state *state); int (*prevalidate_phy_mode)(struct ocelot *ocelot, int port,
drivers/net/dsa/ocelot/felix_vsc9959.c +0 -37
@@ -728,42 +728,6 @@ static int vsc9959_reset(struct ocelot *ocelot)return 0 ; } -static void vsc9959_pcs_an_restart_sgmii (struct phy_device *pcs) -{ -phy_set_bits (pcs,MII_BMCR ,BMCR_ANRESTART ); -} - -static void vsc9959_pcs_an_restart_usxgmii (struct phy_device *pcs) -{ -phy_write_mmd (pcs,MDIO_MMD_VEND2 ,MII_BMCR , -USXGMII_BMCR_RESET | -USXGMII_BMCR_AN_EN | -USXGMII_BMCR_RST_AN ); -} - -static void vsc9959_pcs_an_restart (struct ocelot *ocelot,int port) -{ -struct felix *felix =ocelot_to_felix (ocelot); -struct phy_device *pcs = felix->pcs[port]; - -if (!pcs) -return ; - -switch (pcs->interface) { -case PHY_INTERFACE_MODE_SGMII : -case PHY_INTERFACE_MODE_QSGMII : -vsc9959_pcs_an_restart_sgmii (pcs); -break ; -case PHY_INTERFACE_MODE_USXGMII : -vsc9959_pcs_an_restart_usxgmii (pcs); -break ; -default : -dev_err (ocelot->dev,"Invalid PCS interface type %s\n" , -phy_modes (pcs->interface)); -break ; - } -} -/* We enable SGMII AN only when the PHY has managed = "in-band-status" in the * device tree. If we are in MLO_AN_PHY mode, we program directly state->speed * into the PCS, which is retrieved out-of-band over MDIO. This also has the
@@ -1411,7 +1375,6 @@ struct felix_info felix_info_vsc9959 = { .mdio_bus_alloc = vsc9959_mdio_bus_alloc, .mdio_bus_free = vsc9959_mdio_bus_free, .pcs_init = vsc9959_pcs_init, - .pcs_an_restart = vsc9959_pcs_an_restart, .pcs_link_state = vsc9959_pcs_link_state, .prevalidate_phy_mode = vsc9959_prevalidate_phy_mode, .port_setup_tc = vsc9959_port_setup_tc,
Signature · 1 line
2.25.1
Re: [PATCH v3 net-next 5/6] net: dsa: felix: delete .phylink_mac_an_restart code
Quoted 32 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Phylink uses the .mac_an_restart method to offer the user an implementation of the "ethtool -r" behavior, when the media-side auto negotiation can be restarted by the local MAC PCS. This is the case for fiber modes 1000Base-X and 2500Base-X (IEEE clause 37) that don't have an Ethernet PHY connected locally, and the media is connected to the MAC PCS directly.
On the other hand, the Cisco SGMII and USXGMII standards also have an auto negotiation mechanism based on IEEE 802.3 clause 37 (their respective specs require a MAC PCS and a PHY PCS to implement the same state machine, which is described in IEEE 802.3 "Auto-Negotiation Figure 37-6"), so the ability to restart auto-negotiation is intrinsically symmetrical (the MAC PCS can do it too).
However, it appears that not all SGMII/USXGMII PHYs have logic to restart the MDI-side auto-negotiation process when they detect a transition of the SGMII link from data mode to configuration mode. Some do (VSC8234) and some don't (AR8033, MV88E1111). IEEE and/or Cisco specification wordings to not help to prove whether propagating the "AN restart" event from MII side ("
mr_restart_an") to MDI side ("mr_restart_negotiation") is required behavior - neither of them specifies any mandatory interaction between the clause 37 AN state machine from Figure 37-6 and the clause 28 AN state machine from Figure 28-18.Therefore, even if a certain behavior could be proven as being required, real-life SGMII/USXGMII PHYs are inconsistent enough that a clause 37 AN restart cannot be used by phylink to reliably trigger a media-side renegotiation, when the user requests it via ethtool.
Quoted 8 lines
The only remaining use that the .mac_an_restart callback might possibly have, given what we know now, is to implement some silicon quirks, but so far that has proven to not be necessary.
So remove this code for now, since it never gets called and we don't foresee any circumstance in which it might be, either.
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v3 6/6 net: dsa: felix: use resolved link config in mac_link_up()
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Phylink now requires that parameters established through auto-negotiation be written into the MAC at the time of the mac_link_up() callback. In the case of felix, that means taking the port out of reset, setting the correct timers for PAUSE frames, and enabling/disabling TX flow control.
This patch also splits the inband and noinband configuration of the vsc9959 PCS (currently found in a function called "init") into 2 different functions, which have a nomenclature closer to phylink:
"config", for inband setup, and "link_up", for noinband (forced) setup.
This is necessary as a preparation step for giving up control of the PCS to phylink, which will be done in further patch series.
---
Changes in v3:
None.
Changes in v2:
Rebase on top of new patch 1/6.
drivers/net/dsa/ocelot/felix.c | 76 ++++---- drivers/net/dsa/ocelot/felix.h | 10 +- drivers/net/dsa/ocelot/felix_vsc9959.c | 257 ++++++++++++++----------- 3 files changed, 187 insertions(+), 156 deletions(-)
drivers/net/dsa/ocelot/felix.c +39 -37
@@ -233,6 +233,32 @@ static int felix_phylink_mac_pcs_get_state(struct dsa_switch *ds, int port,static void felix_phylink_mac_config (struct dsa_switch *ds,int port,unsigned int link_an_mode,const struct phylink_link_state *state) +{ +struct ocelot *ocelot = ds->priv; +struct felix *felix =ocelot_to_felix (ocelot); + +if (felix->info->pcs_config) + felix->info->pcs_config (ocelot, port, link_an_mode, state); +} + +static void felix_phylink_mac_link_down (struct dsa_switch *ds,int port, +unsigned int link_an_mode, +phy_interface_t interface) +{ +struct ocelot *ocelot = ds->priv; +struct ocelot_port *ocelot_port = ocelot->ports[port]; + +ocelot_port_writel (ocelot_port,0 ,DEV_MAC_ENA_CFG ); +ocelot_rmw_rix (ocelot,0 ,QSYS_SWITCH_PORT_MODE_PORT_ENA , +QSYS_SWITCH_PORT_MODE , port); +} + +static void felix_phylink_mac_link_up (struct dsa_switch *ds,int port, +unsigned int link_an_mode, +phy_interface_t interface, +struct phy_device *phydev, +int speed,int duplex, +bool tx_pause,bool rx_pause) {struct ocelot *ocelot = ds->priv;struct ocelot_port *ocelot_port = ocelot->ports[port];
@@ -250,7 +276,7 @@ static void felix_phylink_mac_config(struct dsa_switch *ds, int port,DEV_CLOCK_CFG_LINK_SPEED (OCELOT_SPEED_1000 ), DEV_CLOCK_CFG); -switch (state->speed) { +switch (speed) {case SPEED_10 : mac_fc_cfg =SYS_MAC_FC_CFG_FC_LINK_SPEED (3 );break ;
@@ -261,12 +287,9 @@ static void felix_phylink_mac_config(struct dsa_switch *ds, int port,case SPEED_2500 : mac_fc_cfg =SYS_MAC_FC_CFG_FC_LINK_SPEED (1 );break ; -case SPEED_UNKNOWN : - mac_fc_cfg =SYS_MAC_FC_CFG_FC_LINK_SPEED (0 ); -break ;default :dev_err (ocelot->dev,"Unsupported speed on port %d: %d\n" , - port, state->speed); + port, speed);return ; }
@@ -275,7 +298,7 @@ static void felix_phylink_mac_config(struct dsa_switch *ds, int port,*/ mac_fc_cfg |=SYS_MAC_FC_CFG_RX_FC_ENA ; -if (state->pause &MLO_PAUSE_TX ) +if (tx_pause) mac_fc_cfg |=SYS_MAC_FC_CFG_TX_FC_ENA |SYS_MAC_FC_CFG_PAUSE_VAL_CFG (0xffff ) | SYS_MAC_FC_CFG_FC_LATENCY_CFG(0x7) |
@@ -288,37 +311,9 @@ static void felix_phylink_mac_config(struct dsa_switch *ds, int port,ocelot_write_rix (ocelot,0 ,ANA_POL_FLOWC , port); -if (felix->info->pcs_init) - felix->info->pcs_init (ocelot, port, link_an_mode, state); - -if (felix->info->port_sched_speed_set) - felix->info->port_sched_speed_set (ocelot, port, - state->speed); -} - -static void felix_phylink_mac_link_down (struct dsa_switch *ds,int port, -unsigned int link_an_mode, -phy_interface_t interface) -{ -struct ocelot *ocelot = ds->priv; -struct ocelot_port *ocelot_port = ocelot->ports[port]; - -ocelot_port_writel (ocelot_port,0 ,DEV_MAC_ENA_CFG ); -ocelot_rmw_rix (ocelot,0 ,QSYS_SWITCH_PORT_MODE_PORT_ENA , -QSYS_SWITCH_PORT_MODE , port); -} - -static void felix_phylink_mac_link_up (struct dsa_switch *ds,int port, -unsigned int link_an_mode, -phy_interface_t interface, -struct phy_device *phydev, -int speed,int duplex, -bool tx_pause,bool rx_pause) -{ -struct ocelot *ocelot = ds->priv; -struct ocelot_port *ocelot_port = ocelot->ports[port]; - -/* Enable MAC module */ +/* Undo the effects of felix_phylink_mac_link_down: +* enable MAC module +*/ ocelot_port_writel (ocelot_port,DEV_MAC_ENA_CFG_RX_ENA |DEV_MAC_ENA_CFG_TX_ENA ,DEV_MAC_ENA_CFG );
@@ -335,6 +330,13 @@ static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port,QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG (1 ) |QSYS_SWITCH_PORT_MODE_PORT_ENA , QSYS_SWITCH_PORT_MODE, port); + +if (felix->info->pcs_link_up) + felix->info->pcs_link_up (ocelot, port, link_an_mode, interface, + speed, duplex); + +if (felix->info->port_sched_speed_set) + felix->info->port_sched_speed_set (ocelot, port, speed); }static void felix_port_qos_map_init (struct ocelot *ocelot,int port)
drivers/net/dsa/ocelot/felix.h +7 -3
@@ -28,9 +28,13 @@ struct felix_info {int imdio_pci_bar;int (*mdio_bus_alloc)(struct ocelot *ocelot);void (*mdio_bus_free)(struct ocelot *ocelot); -void (*pcs_init)(struct ocelot *ocelot,int port, -unsigned int link_an_mode, -const struct phylink_link_state *state); +void (*pcs_config)(struct ocelot *ocelot,int port, +unsigned int link_an_mode, +const struct phylink_link_state *state); +void (*pcs_link_up)(struct ocelot *ocelot,int port, +unsigned int link_an_mode, +phy_interface_t interface, +int speed,int duplex);void (*pcs_link_state)(struct ocelot *ocelot,int port,struct phylink_link_state *state); int (*prevalidate_phy_mode)(struct ocelot *ocelot, int port,
drivers/net/dsa/ocelot/felix_vsc9959.c +141 -116
297 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 net-next 6/6] net: dsa: felix: use resolved link config in mac_link_up()
Quoted 13 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Phylink now requires that parameters established through auto-negotiation be written into the MAC at the time of the
mac_link_up()callback. In the case of felix, that means taking the port out of reset, setting the correct timers for PAUSE frames, and enabling/disabling TX flow control.This patch also splits the inband and noinband configuration of the vsc9959 PCS (currently found in a function called "init") into 2 different functions, which have a nomenclature closer to phylink:
"config", for inband setup, and "link_up", for noinband (forced) setup.
Quoted 4 lines
This is necessary as a preparation step for giving up control of the PCS to phylink, which will be done in further patch series.
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian