Convert mvneta to phylink
Subsystems (4)
Russell King - ARM Linux
reviewercover Convert mvneta to phylink
Hi,
This series converts mvneta to use phylink, which is necessary to support the SFP cages on SolidRun's Clearfog platform. This series just converts mvneta without adding the DT parts - having discussed with Andrew, we believe we're too close to the merge window to submit that patch.
I've split the "net: mvneta: convert to phylink" patch up to make it easier to review, and in doing so, spotted some minor corner cases that needed to be fixed along the way.
This series depends on the previously merged phylink patches in netdev, along with the recently reviewed 7 patch series "Resolve races in phy accessors" without which, the race described in patch 5 of that series is very evident when triggering a dummy hibernate cycle.
This series also illustrates how to convert mvpp2 to phylink.
mvneta is the only user of the fixed_phy_update_state() API, and this becomes redundant with the conversion.
It would be good to get this series not only reviewed, but also independently tested to ensure that I haven't missed anything - I only have the Clearfog platform to test on, and that doesn't support all the different interface modes that mvneta supports.
A particularly interesting side effect of this series is that DSA switches no longer need the "CPU" port and DSA facing MAC ethernet instance to be marked as a fixed link anymore with mvneta - we can use 1000BaseX mode, and the DSA to CPU link will use the 802.3z negotiation to determine the link properties without needing the link parameters to be explicitly stated in DT - that is a subject of a future patch.
drivers/net/ethernet/marvell/Kconfig | 2 +- drivers/net/ethernet/marvell/mvneta.c | 687 ++++++++++++++++++++-------------- drivers/net/phy/fixed_phy.c | 31 -- include/linux/phy_fixed.h | 9 - 4 files changed, 405 insertions(+), 324 deletions(-)
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up
PATCH 1/10 net: mvneta: ensure PM paths take the rtnl lock
The netdev core always ensures that the rtnl lock is held while calling the ndo_open() and ndo_stop() methods. However, the suspend/resume paths do not hold the rtnl lock. phylink will expect the rtnl lock to be held when the MAC driver calls it, so we end up with kernel warnings. Take the lock to ensure that these functions are called in a consistent manner.
--- drivers/net/ethernet/marvell/mvneta.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/marvell/mvneta.c +4 -0
@@ -4426,8 +4426,10 @@ static int mvneta_suspend(struct device *device)struct net_device *dev =dev_get_drvdata (device);struct mvneta_port *pp =netdev_priv (dev); +rtnl_lock ();if (netif_running (dev))mvneta_stop (dev); +rtnl_unlock ();netif_device_detach (dev);clk_disable_unprepare (pp->clk_bus);clk_disable_unprepare (pp->clk);
@@ -4464,10 +4466,12 @@ static int mvneta_resume(struct device *device)mvneta_fixed_link_update (pp, dev->phydev);netif_device_attach (dev); +rtnl_lock ();if (netif_running (dev)) {mvneta_open (dev);mvneta_set_rx_mode (dev); } +rtnl_unlock ();return 0 ; }
Signature · 1 line
2.7.4
PATCH 2/10 net: mvneta: prepare to convert to phylink
In reply to Russell King - ARM LinuxPrepare to convert mvneta to phylink by splitting the adjust_link function into its consituent parts.
--- drivers/net/ethernet/marvell/mvneta.c | 101 ++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 41 deletions(-)
drivers/net/ethernet/marvell/mvneta.c +60 -41
@@ -3251,37 +3251,73 @@ static int mvneta_set_mac_addr(struct net_device *dev, void *addr)return 0 ; } -static void mvneta_adjust_link (struct net_device *ndev) +static void mvneta_mac_config (struct net_device *ndev) {struct mvneta_port *pp =netdev_priv (ndev);struct phy_device *phydev = ndev->phydev; -int status_change =0 ; +u32 val; -if (phydev->link) { -if ((pp->speed != phydev->speed) || - (pp->duplex != phydev->duplex)) { -u32 val; +if ((pp->speed != phydev->speed) || + (pp->duplex != phydev->duplex)) { + val =mvreg_read (pp,MVNETA_GMAC_AUTONEG_CONFIG ); + val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED | +MVNETA_GMAC_CONFIG_GMII_SPEED | +MVNETA_GMAC_CONFIG_FULL_DUPLEX ); - val =mvreg_read (pp,MVNETA_GMAC_AUTONEG_CONFIG ); - val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED | -MVNETA_GMAC_CONFIG_GMII_SPEED | -MVNETA_GMAC_CONFIG_FULL_DUPLEX ); +if (phydev->duplex) + val |=MVNETA_GMAC_CONFIG_FULL_DUPLEX ; -if (phydev->duplex) - val |=MVNETA_GMAC_CONFIG_FULL_DUPLEX ; +if (phydev->speed ==SPEED_1000 ) + val |=MVNETA_GMAC_CONFIG_GMII_SPEED ; +else if (phydev->speed ==SPEED_100 ) + val |=MVNETA_GMAC_CONFIG_MII_SPEED ; -if (phydev->speed ==SPEED_1000 ) - val |=MVNETA_GMAC_CONFIG_GMII_SPEED ; -else if (phydev->speed ==SPEED_100 ) - val |=MVNETA_GMAC_CONFIG_MII_SPEED ; +mvreg_write (pp,MVNETA_GMAC_AUTONEG_CONFIG , val); -mvreg_write (pp,MVNETA_GMAC_AUTONEG_CONFIG , val); + pp->duplex = phydev->duplex; + pp->speed = phydev->speed; + } +} - pp->duplex = phydev->duplex; - pp->speed = phydev->speed; - } +static void mvneta_mac_link_down (struct net_device *ndev,bool autoneg) +{ +struct mvneta_port *pp =netdev_priv (ndev); +u32 val; + +if (!autoneg) { + val =mvreg_read (pp,MVNETA_GMAC_AUTONEG_CONFIG ); + val &= ~MVNETA_GMAC_FORCE_LINK_PASS ; + val |=MVNETA_GMAC_FORCE_LINK_DOWN ; +mvreg_write (pp,MVNETA_GMAC_AUTONEG_CONFIG , val); } +mvneta_port_down (pp); +} + +static void mvneta_mac_link_up (struct net_device *ndev,bool autoneg) +{ +struct mvneta_port *pp =netdev_priv (ndev); +u32 val; + +if (!autoneg) { + val =mvreg_read (pp,MVNETA_GMAC_AUTONEG_CONFIG ); + val &= ~MVNETA_GMAC_FORCE_LINK_DOWN ; + val |=MVNETA_GMAC_FORCE_LINK_PASS ; +mvreg_write (pp,MVNETA_GMAC_AUTONEG_CONFIG , val); + } + +mvneta_port_up (pp); +} + +static void mvneta_adjust_link (struct net_device *ndev) +{ +struct mvneta_port *pp =netdev_priv (ndev); +struct phy_device *phydev = ndev->phydev; +int status_change =0 ; + +if (phydev->link) +mvneta_mac_config (ndev); +if (phydev->link != pp->link) {if (!phydev->link) { pp->duplex =-1 ;
@@ -3293,27 +3329,10 @@ static void mvneta_adjust_link(struct net_device *ndev) }if (status_change) { -if (phydev->link) { -if (!pp->use_inband_status) { -u32 val =mvreg_read (pp, -MVNETA_GMAC_AUTONEG_CONFIG ); - val &= ~MVNETA_GMAC_FORCE_LINK_DOWN ; - val |=MVNETA_GMAC_FORCE_LINK_PASS ; -mvreg_write (pp,MVNETA_GMAC_AUTONEG_CONFIG , - val); - } -mvneta_port_up (pp); - }else { -if (!pp->use_inband_status) { -u32 val =mvreg_read (pp, -MVNETA_GMAC_AUTONEG_CONFIG ); - val &= ~MVNETA_GMAC_FORCE_LINK_PASS ; - val |=MVNETA_GMAC_FORCE_LINK_DOWN ; -mvreg_write (pp,MVNETA_GMAC_AUTONEG_CONFIG , - val); - } -mvneta_port_down (pp); - } +if (phydev->link) +mvneta_mac_link_down (ndev, pp->use_inband_status); +else +mvneta_mac_link_up (ndev, pp->use_inband_status);phy_print_status (phydev); } }
Signature · 1 line
2.7.4
PATCH 3/10 net: mvneta: convert to phylink
In reply to Russell King - ARM LinuxConvert mvneta to use phylink, which models the MAC to PHY link in a generic, reusable form.
- remove unused sync status
--- drivers/net/ethernet/marvell/Kconfig | 2 +- drivers/net/ethernet/marvell/mvneta.c | 417 ++++++++++++++-------------------- 2 files changed, 176 insertions(+), 243 deletions(-)
drivers/net/ethernet/marvell/Kconfig +1 -1
@@ -60,7 +60,7 @@ config MVNETA depends on ARCH_MVEBU || COMPILE_TEST depends on HAS_DMA select MVMDIO - select FIXED_PHY + select PHYLINK ---help--- This driver supports the network interface units in the Marvell ARMADA XP, ARMADA 370, ARMADA 38x and
drivers/net/ethernet/marvell/mvneta.c +175 -242
654 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 4/10 net: mvneta: move port configuration
In reply to Russell King - ARM LinuxMove the port configuration and release of reset to mvneta_mac_config() along side the rest of the port mode configuration.
--- drivers/net/ethernet/marvell/mvneta.c | 51 ++++++++++++++--------------------- 1 file changed, 20 insertions(+), 31 deletions(-)
drivers/net/ethernet/marvell/mvneta.c +20 -31
@@ -3251,7 +3251,8 @@ static void mvneta_mac_config(struct net_device *ndev, unsigned int mode,u32 new_clk, gmac_clk =mvreg_read (pp,MVNETA_GMAC_CLOCK_DIVIDER );u32 new_an, gmac_an =mvreg_read (pp,MVNETA_GMAC_AUTONEG_CONFIG ); - new_ctrl2 = gmac_ctrl2 & ~MVNETA_GMAC2_INBAND_AN_ENABLE ; + new_ctrl2 = gmac_ctrl2 & ~(MVNETA_GMAC2_INBAND_AN_ENABLE | +MVNETA_GMAC2_PORT_RESET ); new_clk = gmac_clk & ~MVNETA_GMAC_1MS_CLOCK_ENABLE ; new_an = gmac_an & ~(MVNETA_GMAC_INBAND_AN_ENABLE | MVNETA_GMAC_INBAND_RESTART_AN |
@@ -3262,6 +3263,15 @@ static void mvneta_mac_config(struct net_device *ndev, unsigned int mode,MVNETA_GMAC_CONFIG_FULL_DUPLEX | MVNETA_GMAC_AN_DUPLEX_EN); +/* Even though it might look weird, when we're configured in +* SGMII or QSGMII mode, the RGMII bit needs to be set. +*/ + new_ctrl2 |=MVNETA_GMAC2_PORT_RGMII ; + +if (state->interface ==PHY_INTERFACE_MODE_QSGMII || + state->interface ==PHY_INTERFACE_MODE_SGMII ) + new_ctrl2 |=MVNETA_GMAC2_PCS_ENABLE ; +if (!phylink_autoneg_inband (mode)) {/* Phy or fixed speed */ if (state->duplex)
@@ -3298,6 +3308,12 @@ static void mvneta_mac_config(struct net_device *ndev, unsigned int mode,mvreg_write (pp,MVNETA_GMAC_CLOCK_DIVIDER , new_clk);if (new_an != gmac_an)mvreg_write (pp,MVNETA_GMAC_AUTONEG_CONFIG , new_an); + +if (gmac_ctrl2 &MVNETA_GMAC2_PORT_RESET ) { +while ((mvreg_read (pp,MVNETA_GMAC_CTRL_2 ) & +MVNETA_GMAC2_PORT_RESET ) !=0 ) +continue ; + } }static void mvneta_mac_link_down (struct net_device *ndev,unsigned int mode)
@@ -4075,42 +4091,15 @@ static void mvneta_conf_mbus_windows(struct mvneta_port *pp,/* Power up the port */ static int mvneta_port_power_up (struct mvneta_port *pp,int phy_mode) { -u32 ctrl; -/* MAC Cause register should be cleared */ mvreg_write (pp,MVNETA_UNIT_INTR_CAUSE ,0 ); - ctrl =mvreg_read (pp,MVNETA_GMAC_CTRL_2 ); - -/* Even though it might look weird, when we're configured in -* SGMII or QSGMII mode, the RGMII bit needs to be set. -*/ -switch (phy_mode) { -case PHY_INTERFACE_MODE_QSGMII : +if (phy_mode ==PHY_INTERFACE_MODE_QSGMII )mvreg_write (pp,MVNETA_SERDES_CFG ,MVNETA_QSGMII_SERDES_PROTO ); - ctrl |=MVNETA_GMAC2_PCS_ENABLE |MVNETA_GMAC2_PORT_RGMII ; -break ; -case PHY_INTERFACE_MODE_SGMII : +else if (phy_mode ==PHY_INTERFACE_MODE_SGMII )mvreg_write (pp,MVNETA_SERDES_CFG ,MVNETA_SGMII_SERDES_PROTO ); - ctrl |=MVNETA_GMAC2_PCS_ENABLE |MVNETA_GMAC2_PORT_RGMII ; -break ; -case PHY_INTERFACE_MODE_RGMII : -case PHY_INTERFACE_MODE_RGMII_ID : -case PHY_INTERFACE_MODE_RGMII_RXID : -case PHY_INTERFACE_MODE_RGMII_TXID : - ctrl |=MVNETA_GMAC2_PORT_RGMII ; -break ; -default : +else if (!phy_interface_mode_is_rgmii (phy_mode))return -EINVAL ; - } - -/* Cancel Port Reset */ - ctrl &= ~MVNETA_GMAC2_PORT_RESET ; -mvreg_write (pp,MVNETA_GMAC_CTRL_2 , ctrl); - -while ((mvreg_read (pp,MVNETA_GMAC_CTRL_2 ) & -MVNETA_GMAC2_PORT_RESET ) !=0 ) -continue ;return 0 ; }
Signature · 1 line
2.7.4
PATCH 5/10 net: mvneta: add 1000BaseX support
In reply to Russell King - ARM LinuxAdd support for 1000BaseX link modes.
--- drivers/net/ethernet/marvell/mvneta.c | 59 +++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 9 deletions(-)
drivers/net/ethernet/marvell/mvneta.c +50 -9
@@ -189,6 +189,7 @@#define MVNETA_GMAC_CTRL_0 0x2c00#define MVNETA_GMAC_MAX_RX_SIZE_SHIFT 2#define MVNETA_GMAC_MAX_RX_SIZE_MASK 0x7ffc +#define MVNETA_GMAC0_PORT_1000BASE_X BIT(1)#define MVNETA_GMAC0_PORT_ENABLE BIT(0)#define MVNETA_GMAC_CTRL_2 0x2c08#define MVNETA_GMAC2_INBAND_AN_ENABLE BIT(0)
@@ -210,9 +211,13 @@#define MVNETA_GMAC_FORCE_LINK_DOWN BIT(0)#define MVNETA_GMAC_FORCE_LINK_PASS BIT(1)#define MVNETA_GMAC_INBAND_AN_ENABLE BIT(2) +#define MVNETA_GMAC_AN_BYPASS_ENABLE BIT(3) +#define MVNETA_GMAC_INBAND_RESTART_AN BIT(4)#define MVNETA_GMAC_CONFIG_MII_SPEED BIT(5)#define MVNETA_GMAC_CONFIG_GMII_SPEED BIT(6)#define MVNETA_GMAC_AN_SPEED_EN BIT(7) +#define MVNETA_GMAC_CONFIG_FLOW_CTRL BIT(8) +#define MVNETA_GMAC_ADVERT_SYM_FLOW_CTRL BIT(9)#define MVNETA_GMAC_AN_FLOW_CTRL_EN BIT(11)#define MVNETA_GMAC_CONFIG_FULL_DUPLEX BIT(12)#define MVNETA_GMAC_AN_DUPLEX_EN BIT(13)
@@ -3192,10 +3197,11 @@ static void mvneta_validate(struct net_device *ndev, unsigned long *supported, {__ETHTOOL_DECLARE_LINK_MODE_MASK (mask) = {0 , }; -/* We only support QSGMII, SGMII and RGMII modes */ +/* We only support QSGMII, SGMII, 802.3z and RGMII modes */ if (state->interface !=PHY_INTERFACE_MODE_NA && state->interface !=PHY_INTERFACE_MODE_QSGMII && state->interface !=PHY_INTERFACE_MODE_SGMII && + !phy_interface_mode_is_8023z (state->interface) && !phy_interface_mode_is_rgmii (state->interface)) {bitmap_zero (supported, __ETHTOOL_LINK_MODE_MASK_NBITS);return ;
@@ -3208,10 +3214,14 @@ static void mvneta_validate(struct net_device *ndev, unsigned long *supported,/* Half-duplex at speeds higher than 100Mbit is unsupported */ phylink_set(mask, 1000baseT_Full); phylink_set(mask, 1000baseX_Full); - phylink_set(mask, 10baseT_Half); - phylink_set(mask, 10baseT_Full); - phylink_set(mask, 100baseT_Half); - phylink_set(mask, 100baseT_Full); + +if (!phy_interface_mode_is_8023z (state->interface)) { +/* 10M and 100M are only supported in non-802.3z mode */ + phylink_set(mask, 10baseT_Half); + phylink_set(mask, 10baseT_Full); + phylink_set(mask, 100baseT_Half); + phylink_set(mask, 100baseT_Full); + }bitmap_and (supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
@@ -3243,14 +3253,27 @@ static int mvneta_mac_link_state(struct net_device *ndev,return 1 ; } +static void mvneta_mac_an_restart (struct net_device *ndev) +{ +struct mvneta_port *pp =netdev_priv (ndev); +u32 gmac_an =mvreg_read (pp,MVNETA_GMAC_AUTONEG_CONFIG ); + +mvreg_write (pp,MVNETA_GMAC_AUTONEG_CONFIG , + gmac_an |MVNETA_GMAC_INBAND_RESTART_AN ); +mvreg_write (pp,MVNETA_GMAC_AUTONEG_CONFIG , + gmac_an & ~MVNETA_GMAC_INBAND_RESTART_AN ); +} +static void mvneta_mac_config (struct net_device *ndev,unsigned int mode,const struct phylink_link_state *state) {struct mvneta_port *pp =netdev_priv (ndev); +u32 new_ctrl0, gmac_ctrl0 =mvreg_read (pp,MVNETA_GMAC_CTRL_0 );u32 new_ctrl2, gmac_ctrl2 =mvreg_read (pp,MVNETA_GMAC_CTRL_2 );u32 new_clk, gmac_clk =mvreg_read (pp,MVNETA_GMAC_CLOCK_DIVIDER );u32 new_an, gmac_an =mvreg_read (pp,MVNETA_GMAC_AUTONEG_CONFIG ); + new_ctrl0 = gmac_ctrl0 & ~MVNETA_GMAC0_PORT_1000BASE_X ; new_ctrl2 = gmac_ctrl2 & ~(MVNETA_GMAC2_INBAND_AN_ENABLE |MVNETA_GMAC2_PORT_RESET ); new_clk = gmac_clk & ~MVNETA_GMAC_1MS_CLOCK_ENABLE ;
@@ -3259,6 +3282,8 @@ static void mvneta_mac_config(struct net_device *ndev, unsigned int mode,MVNETA_GMAC_CONFIG_MII_SPEED |MVNETA_GMAC_CONFIG_GMII_SPEED |MVNETA_GMAC_AN_SPEED_EN | +MVNETA_GMAC_ADVERT_SYM_FLOW_CTRL | +MVNETA_GMAC_CONFIG_FLOW_CTRL |MVNETA_GMAC_AN_FLOW_CTRL_EN |MVNETA_GMAC_CONFIG_FULL_DUPLEX | MVNETA_GMAC_AN_DUPLEX_EN);
@@ -3269,7 +3294,8 @@ static void mvneta_mac_config(struct net_device *ndev, unsigned int mode, new_ctrl2 |=MVNETA_GMAC2_PORT_RGMII ;if (state->interface ==PHY_INTERFACE_MODE_QSGMII || - state->interface ==PHY_INTERFACE_MODE_SGMII ) + state->interface ==PHY_INTERFACE_MODE_SGMII || +phy_interface_mode_is_8023z (state->interface)) new_ctrl2 |=MVNETA_GMAC2_PCS_ENABLE ;if (!phylink_autoneg_inband (mode)) {
@@ -3281,7 +3307,7 @@ static void mvneta_mac_config(struct net_device *ndev, unsigned int mode, new_an |=MVNETA_GMAC_CONFIG_GMII_SPEED ; else if (state->speed == SPEED_100) new_an |= MVNETA_GMAC_CONFIG_MII_SPEED; - }else { + }else if (state->interface ==PHY_INTERFACE_MODE_SGMII ) {/* SGMII mode receives the state from the PHY */ new_ctrl2 |=MVNETA_GMAC2_INBAND_AN_ENABLE ; new_clk |=MVNETA_GMAC_1MS_CLOCK_ENABLE ;
@@ -3290,18 +3316,31 @@ static void mvneta_mac_config(struct net_device *ndev, unsigned int mode,MVNETA_GMAC_INBAND_AN_ENABLE |MVNETA_GMAC_AN_SPEED_EN |MVNETA_GMAC_AN_DUPLEX_EN ; + }else { +/* 802.3z negotiation - only 1000base-X */ + new_ctrl0 |=MVNETA_GMAC0_PORT_1000BASE_X ; + new_clk |=MVNETA_GMAC_1MS_CLOCK_ENABLE ; + new_an = (new_an & ~(MVNETA_GMAC_FORCE_LINK_DOWN | +MVNETA_GMAC_FORCE_LINK_PASS )) | +MVNETA_GMAC_INBAND_AN_ENABLE | +MVNETA_GMAC_CONFIG_GMII_SPEED | +/* The MAC only supports FD mode */ +MVNETA_GMAC_CONFIG_FULL_DUPLEX ; }/* Armada 370 documentation says we can only change the port mode * and in-band enable when the link is down, so force it down * while making these changes. We also do this for GMAC_CTRL2 */ -if ((new_ctrl2 ^ gmac_ctrl2) &MVNETA_GMAC2_INBAND_AN_ENABLE || +if ((new_ctrl0 ^ gmac_ctrl0) &MVNETA_GMAC0_PORT_1000BASE_X || + (new_ctrl2 ^ gmac_ctrl2) &MVNETA_GMAC2_INBAND_AN_ENABLE || (new_an ^ gmac_an) &MVNETA_GMAC_INBAND_AN_ENABLE ) {mvreg_write (pp,MVNETA_GMAC_AUTONEG_CONFIG , (gmac_an & ~MVNETA_GMAC_FORCE_LINK_PASS ) |MVNETA_GMAC_FORCE_LINK_DOWN ); } +if (new_ctrl0 != gmac_ctrl0) +mvreg_write (pp,MVNETA_GMAC_CTRL_0 , new_ctrl0);if (new_ctrl2 != gmac_ctrl2)mvreg_write (pp,MVNETA_GMAC_CTRL_2 , new_ctrl2);if (new_clk != gmac_clk)
@@ -3350,6 +3389,7 @@ static void mvneta_mac_link_up(struct net_device *ndev, unsigned int mode,static const struct phylink_mac_ops mvneta_phylink_ops = { .validate = mvneta_validate, .mac_link_state = mvneta_mac_link_state, + .mac_an_restart = mvneta_mac_an_restart, .mac_config = mvneta_mac_config, .mac_link_down = mvneta_mac_link_down, .mac_link_up = mvneta_mac_link_up,
@@ -4096,7 +4136,8 @@ static int mvneta_port_power_up(struct mvneta_port *pp, int phy_mode)if (phy_mode ==PHY_INTERFACE_MODE_QSGMII )mvreg_write (pp,MVNETA_SERDES_CFG ,MVNETA_QSGMII_SERDES_PROTO ); -else if (phy_mode ==PHY_INTERFACE_MODE_SGMII ) +else if (phy_mode ==PHY_INTERFACE_MODE_SGMII || + phy_mode ==PHY_INTERFACE_MODE_1000BASEX )mvreg_write (pp,MVNETA_SERDES_CFG ,MVNETA_SGMII_SERDES_PROTO );else if (!phy_interface_mode_is_rgmii (phy_mode))return -EINVAL ;
Signature · 1 line
2.7.4
PATCH 6/10 net: mvneta: add flow control support
In reply to Russell King - ARM LinuxAdd support for flow control to mvneta.
--- drivers/net/ethernet/marvell/mvneta.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/net/ethernet/marvell/mvneta.c +32 -0
@@ -3211,6 +3211,8 @@ static void mvneta_validate(struct net_device *ndev, unsigned long *supported,phylink_set (mask, Autoneg);phylink_set_port_modes (mask); +/* Asymmetric pause is unsupported */ +phylink_set (mask, Pause);/* Half-duplex at speeds higher than 100Mbit is unsupported */ phylink_set(mask, 1000baseT_Full); phylink_set(mask, 1000baseX_Full);
@@ -3249,6 +3251,10 @@ static int mvneta_mac_link_state(struct net_device *ndev, state->duplex = !!(gmac_stat &MVNETA_GMAC_FULL_DUPLEX ); state->pause =0 ; +if (gmac_stat &MVNETA_GMAC_RX_FLOW_CTRL_ENABLE ) + state->pause |=MLO_PAUSE_RX ; +if (gmac_stat &MVNETA_GMAC_TX_FLOW_CTRL_ENABLE ) + state->pause |=MLO_PAUSE_TX ;return 1 ; }
@@ -3298,6 +3304,11 @@ static void mvneta_mac_config(struct net_device *ndev, unsigned int mode, phy_interface_mode_is_8023z(state->interface)) new_ctrl2 |=MVNETA_GMAC2_PCS_ENABLE ; +if (phylink_test (state->advertising, Pause)) + new_an |=MVNETA_GMAC_ADVERT_SYM_FLOW_CTRL ; +if (state->pause &MLO_PAUSE_TXRX_MASK ) + new_an |=MVNETA_GMAC_CONFIG_FLOW_CTRL ; +if (!phylink_autoneg_inband (mode)) {/* Phy or fixed speed */ if (state->duplex)
@@ -3326,6 +3337,9 @@ static void mvneta_mac_config(struct net_device *ndev, unsigned int mode,MVNETA_GMAC_CONFIG_GMII_SPEED |/* The MAC only supports FD mode */ MVNETA_GMAC_CONFIG_FULL_DUPLEX ; + +if (state->pause &MLO_PAUSE_AN && state->an_enabled) + new_an |=MVNETA_GMAC_AN_FLOW_CTRL_EN ; }/* Armada 370 documentation says we can only change the port mode
@@ -3813,6 +3827,22 @@ static int mvneta_ethtool_set_ringparam(struct net_device *dev,return 0 ; } +static void mvneta_ethtool_get_pauseparam (struct net_device *dev, +struct ethtool_pauseparam *pause) +{ +struct mvneta_port *pp =netdev_priv (dev); + +phylink_ethtool_get_pauseparam (pp->phylink, pause); +} + +static int mvneta_ethtool_set_pauseparam (struct net_device *dev, +struct ethtool_pauseparam *pause) +{ +struct mvneta_port *pp =netdev_priv (dev); + +return phylink_ethtool_set_pauseparam (pp->phylink, pause); +} +static void mvneta_ethtool_get_strings (struct net_device *netdev,u32 sset,u8 *data) {
@@ -4021,6 +4051,8 @@ static const struct ethtool_ops mvneta_eth_tool_ops = { .get_drvinfo = mvneta_ethtool_get_drvinfo, .get_ringparam = mvneta_ethtool_get_ringparam, .set_ringparam = mvneta_ethtool_set_ringparam, + .get_pauseparam = mvneta_ethtool_get_pauseparam, + .set_pauseparam = mvneta_ethtool_set_pauseparam, .get_strings = mvneta_ethtool_get_strings, .get_ethtool_stats = mvneta_ethtool_get_stats, .get_sset_count = mvneta_ethtool_get_sset_count,
Signature · 1 line
2.7.4
PATCH 7/10 net: mvneta: add EEE support
In reply to Russell King - ARM LinuxAdd support for EEE to mvneta.
--- drivers/net/ethernet/marvell/mvneta.c | 99 +++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 5 deletions(-)
drivers/net/ethernet/marvell/mvneta.c +94 -5
@@ -244,6 +244,12 @@#define MVNETA_TXQ_TOKEN_SIZE_REG (q) (0x3e40 + ((q) << 2))#define MVNETA_TXQ_TOKEN_SIZE_MAX 0x7fffffff +#define MVNETA_LPI_CTRL_0 0x2cc0 +#define MVNETA_LPI_CTRL_1 0x2cc4 +#define MVNETA_LPI_REQUEST_ENABLE BIT(0) +#define MVNETA_LPI_CTRL_2 0x2cc8 +#define MVNETA_LPI_STATUS 0x2ccc +#define MVNETA_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff/* Descriptor ring Macros */
@@ -320,6 +326,11 @@#define MVNETA_RX_GET_BM_POOL_ID (rxd) \ (((rxd)->status & MVNETA_RXD_BM_POOL_MASK) >> MVNETA_RXD_BM_POOL_SHIFT) +enum { +ETHTOOL_STAT_EEE_WAKEUP , +ETHTOOL_MAX_STATS , +}; +struct mvneta_statistic {unsigned short offset;unsigned short type;
@@ -328,6 +339,7 @@ struct mvneta_statistic {#define T_REG_32 32#define T_REG_64 64 +#define T_SW 1static const struct mvneta_statistic mvneta_statistics[] = { {0x3000 ,T_REG_64 ,"good_octets_received" , },
@@ -362,6 +374,7 @@ static const struct mvneta_statistic mvneta_statistics[] = { { 0x304c, T_REG_32, "broadcast_frames_sent", }, { 0x3054, T_REG_32, "fc_sent", }, { 0x300c, T_REG_32, "internal_mac_transmit_err", }, + { ETHTOOL_STAT_EEE_WAKEUP, T_SW, "eee_wakeup_errors", }, }; struct mvneta_pcpu_stats {
@@ -424,6 +437,10 @@ struct mvneta_port {struct mvneta_bm_pool *pool_short;int bm_win_id; +bool eee_enabled; +bool eee_active; +bool tx_lpi_enabled; +u64 ethtool_stats[ARRAY_SIZE (mvneta_statistics)];u32 indir[MVNETA_RSS_LU_TABLE_SIZE ];
@@ -3369,6 +3386,18 @@ static void mvneta_mac_config(struct net_device *ndev, unsigned int mode, } } +static void mvneta_set_eee (struct mvneta_port *pp,bool enable) +{ +u32 lpi_ctl1; + + lpi_ctl1 =mvreg_read (pp,MVNETA_LPI_CTRL_1 ); +if (enable) + lpi_ctl1 |=MVNETA_LPI_REQUEST_ENABLE ; +else + lpi_ctl1 &= ~MVNETA_LPI_REQUEST_ENABLE ; +mvreg_write (pp,MVNETA_LPI_CTRL_1 , lpi_ctl1); +} +static void mvneta_mac_link_down (struct net_device *ndev,unsigned int mode) {struct mvneta_port *pp =netdev_priv (ndev);
@@ -3382,6 +3411,9 @@ static void mvneta_mac_link_down(struct net_device *ndev, unsigned int mode) val |=MVNETA_GMAC_FORCE_LINK_DOWN ;mvreg_write (pp,MVNETA_GMAC_AUTONEG_CONFIG , val); } + + pp->eee_active = false; +mvneta_set_eee (pp, false); } static void mvneta_mac_link_up(struct net_device *ndev, unsigned int mode,
@@ -3398,6 +3430,11 @@ static void mvneta_mac_link_up(struct net_device *ndev, unsigned int mode, }mvneta_port_up (pp); + +if (phy && pp->eee_enabled) { + pp->eee_active =phy_init_eee (phy,0 ) >=0 ; +mvneta_set_eee (pp, pp->eee_active && pp->tx_lpi_enabled); + } }static const struct phylink_mac_ops mvneta_phylink_ops = {
@@ -3859,26 +3896,35 @@ static void mvneta_ethtool_update_stats(struct mvneta_port *pp) {const struct mvneta_statistic *s;void __iomem *base = pp->base; -u32 high, low, val; -u64 val64; +u32 high, low; +u64 val;int i;for (i =0 , s = mvneta_statistics; s < mvneta_statistics +ARRAY_SIZE (mvneta_statistics); s++, i++) { + val =0 ; +switch (s->type) {case T_REG_32 : val =readl_relaxed (base + s->offset); - pp->ethtool_stats[i] += val;break ;case T_REG_64 :/* Docs say to read low 32-bit then high */ low =readl_relaxed (base + s->offset); high =readl_relaxed (base + s->offset +4 ); - val64 = (u64 )high <<32 | low; - pp->ethtool_stats[i] += val64; + val = (u64 )high <<32 | low; +break ; +case T_SW : +switch (s->offset) { +case ETHTOOL_STAT_EEE_WAKEUP : + val =phylink_get_eee_err (pp->phylink); +break ; + }break ; } + + pp->ethtool_stats[i] += val; } }
@@ -4031,6 +4077,47 @@ static int mvneta_ethtool_set_wol(struct net_device *dev,return ret; } +static int mvneta_ethtool_get_eee (struct net_device *dev, +struct ethtool_eee *eee) +{ +struct mvneta_port *pp =netdev_priv (dev); +u32 lpi_ctl0; + + lpi_ctl0 =mvreg_read (pp,MVNETA_LPI_CTRL_0 ); + + eee->eee_enabled = pp->eee_enabled; + eee->eee_active = pp->eee_active; + eee->tx_lpi_enabled = pp->tx_lpi_enabled; + eee->tx_lpi_timer = (lpi_ctl0) >>8 ;// * scale; + +return phylink_ethtool_get_eee (pp->phylink, eee); +} + +static int mvneta_ethtool_set_eee (struct net_device *dev, +struct ethtool_eee *eee) +{ +struct mvneta_port *pp =netdev_priv (dev); +u32 lpi_ctl0; + +/* The Armada 37x documents do not give limits for this other than +* it being an 8-bit register. */ +if (eee->tx_lpi_enabled && + (eee->tx_lpi_timer <0 || eee->tx_lpi_timer >255 )) +return -EINVAL ; + + lpi_ctl0 =mvreg_read (pp,MVNETA_LPI_CTRL_0 ); + lpi_ctl0 &= ~(0xff <<8 ); + lpi_ctl0 |= eee->tx_lpi_timer <<8 ; +mvreg_write (pp,MVNETA_LPI_CTRL_0 , lpi_ctl0); + + pp->eee_enabled = eee->eee_enabled; + pp->tx_lpi_enabled = eee->tx_lpi_enabled; + +mvneta_set_eee (pp, eee->tx_lpi_enabled && eee->eee_enabled); + +return phylink_ethtool_set_eee (pp->phylink, eee); +} +static const struct net_device_ops mvneta_netdev_ops = { .ndo_open = mvneta_open, .ndo_stop = mvneta_stop,
@@ -4064,6 +4151,8 @@ static const struct ethtool_ops mvneta_eth_tool_ops = { .set_link_ksettings = mvneta_ethtool_set_link_ksettings, .get_wol = mvneta_ethtool_get_wol, .set_wol = mvneta_ethtool_set_wol, + .get_eee = mvneta_ethtool_get_eee, + .set_eee = mvneta_ethtool_set_eee, };/* Initialize hw */
Signature · 1 line
2.7.4
PATCH 8/10 net: mvneta: disable MVNETA_CAUSE_PSC_SYNC_CHANGE interrupt
In reply to Russell King - ARM LinuxThe PSC sync change interrupt can fire multiple times while the link is down, which is caused by noise on the serdes lines. As this isn't information we make use of, it's pointless having the interrupt enabled.
--- drivers/net/ethernet/marvell/mvneta.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/net/ethernet/marvell/mvneta.c +4 -8
@@ -2704,8 +2704,7 @@ static int mvneta_poll(struct napi_struct *napi, int budget)mvreg_write (pp,MVNETA_INTR_MISC_CAUSE ,0 );if (cause_misc & (MVNETA_CAUSE_PHY_STATUS_CHANGE | -MVNETA_CAUSE_LINK_CHANGE | -MVNETA_CAUSE_PSC_SYNC_CHANGE )) +MVNETA_CAUSE_LINK_CHANGE ))mvneta_link_change (pp); }
@@ -3044,8 +3043,7 @@ static void mvneta_start_dev(struct mvneta_port *pp)mvreg_write (pp,MVNETA_INTR_MISC_MASK ,MVNETA_CAUSE_PHY_STATUS_CHANGE | -MVNETA_CAUSE_LINK_CHANGE | -MVNETA_CAUSE_PSC_SYNC_CHANGE ); +MVNETA_CAUSE_LINK_CHANGE );phylink_start (pp->phylink);netif_tx_start_all_queues (pp->dev);
@@ -3570,8 +3568,7 @@ static int mvneta_cpu_online(unsigned int cpu, struct hlist_node *node)on_each_cpu (mvneta_percpu_unmask_interrupt, pp, true);mvreg_write (pp,MVNETA_INTR_MISC_MASK ,MVNETA_CAUSE_PHY_STATUS_CHANGE | -MVNETA_CAUSE_LINK_CHANGE | -MVNETA_CAUSE_PSC_SYNC_CHANGE ); +MVNETA_CAUSE_LINK_CHANGE );netif_tx_start_all_queues (pp->dev);spin_unlock (&pp->lock);return 0 ;
@@ -3612,8 +3609,7 @@ static int mvneta_cpu_dead(unsigned int cpu, struct hlist_node *node)on_each_cpu (mvneta_percpu_unmask_interrupt, pp, true);mvreg_write (pp,MVNETA_INTR_MISC_MASK ,MVNETA_CAUSE_PHY_STATUS_CHANGE | -MVNETA_CAUSE_LINK_CHANGE | -MVNETA_CAUSE_PSC_SYNC_CHANGE ); +MVNETA_CAUSE_LINK_CHANGE );netif_tx_start_all_queues (pp->dev);return 0 ; }
Signature · 1 line
2.7.4
PATCH 9/10 net: mvneta: add module EEPROM reading support
In reply to Russell King - ARM LinuxAdd support for reading the SFF module's EEPROM via the ethtool API.
--- drivers/net/ethernet/marvell/mvneta.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/net/ethernet/marvell/mvneta.c +18 -0
@@ -4073,6 +4073,22 @@ static int mvneta_ethtool_set_wol(struct net_device *dev,return ret; } +static int mvneta_ethtool_get_module_info (struct net_device *dev, +struct ethtool_modinfo *modinfo) +{ +struct mvneta_port *pp =netdev_priv (dev); + +return phylink_ethtool_get_module_info (pp->phylink, modinfo); +} + +static int mvneta_ethtool_get_module_eeprom (struct net_device *dev, +struct ethtool_eeprom *ee,u8 *buf) +{ +struct mvneta_port *pp =netdev_priv (dev); + +return phylink_ethtool_get_module_eeprom (pp->phylink, ee, buf); +} +static int mvneta_ethtool_get_eee (struct net_device *dev,struct ethtool_eee *eee) {
@@ -4147,6 +4163,8 @@ static const struct ethtool_ops mvneta_eth_tool_ops = { .set_link_ksettings = mvneta_ethtool_set_link_ksettings, .get_wol = mvneta_ethtool_get_wol, .set_wol = mvneta_ethtool_set_wol, + .get_module_info = mvneta_ethtool_get_module_info, + .get_module_eeprom = mvneta_ethtool_get_module_eeprom, .get_eee = mvneta_ethtool_get_eee, .set_eee = mvneta_ethtool_set_eee, };
Signature · 1 line
2.7.4
PATCH 10/10 net: phy: fixed-phy: remove fixed_phy_update_state()
In reply to Russell King - ARM Linuxmvneta is the only user of fixed_phy_update_state(), which has been converted to use phylink instead. Remove fixed_phy_update_state().
--- drivers/net/phy/fixed_phy.c | 31 ------------------------------- include/linux/phy_fixed.h | 9 --------- 2 files changed, 40 deletions(-)
drivers/net/phy/fixed_phy.c +0 -31
@@ -115,37 +115,6 @@ int fixed_phy_set_link_update(struct phy_device *phydev, }EXPORT_SYMBOL_GPL (fixed_phy_set_link_update); -int fixed_phy_update_state (struct phy_device *phydev, -const struct fixed_phy_status *status, -const struct fixed_phy_status *changed) -{ -struct fixed_mdio_bus *fmb = &platform_fmb; -struct fixed_phy *fp; - -if (!phydev || phydev->mdio.bus != fmb->mii_bus) -return -EINVAL ; - -list_for_each_entry (fp, &fmb->phys, node) { -if (fp->addr == phydev->mdio.addr) { -write_seqcount_begin (&fp->seqcount); -#define _UPD (x) if (changed->x) \ - fp->status.x = status->x -_UPD (link); -_UPD (speed); -_UPD (duplex); -_UPD (pause); -_UPD (asym_pause); -#undef _UPD -fixed_phy_update (fp); -write_seqcount_end (&fp->seqcount); -return 0 ; - } - } - -return -ENOENT ; -} -EXPORT_SYMBOL (fixed_phy_update_state); -int fixed_phy_add (unsigned int irq,int phy_addr,struct fixed_phy_status *status,int link_gpio)
include/linux/phy_fixed.h +0 -9
@@ -24,9 +24,6 @@ extern void fixed_phy_unregister(struct phy_device *phydev);extern int fixed_phy_set_link_update (struct phy_device *phydev,int (*link_update)(struct net_device *,struct fixed_phy_status *)); -extern int fixed_phy_update_state (struct phy_device *phydev, -const struct fixed_phy_status *status, -const struct fixed_phy_status *changed);#else static inline int fixed_phy_add(unsigned int irq, int phy_id, struct fixed_phy_status *status,
@@ -50,12 +47,6 @@ static inline int fixed_phy_set_link_update(struct phy_device *phydev, {return -ENODEV ; } -static inline int fixed_phy_update_state (struct phy_device *phydev, -const struct fixed_phy_status *status, -const struct fixed_phy_status *changed) -{ -return -ENODEV ; -}#endif /* CONFIG_FIXED_PHY */ #endif /* __PHY_FIXED_H */
Signature · 1 line
2.7.4
Russell King - ARM Linux
reviewerQuoted 34 lines · Russell King - ARM Linux
Hi,
This series converts mvneta to use phylink, which is necessary to support the SFP cages on SolidRun's Clearfog platform. This series just converts mvneta without adding the DT parts - having discussed with Andrew, we believe we're too close to the merge window to submit that patch.
I've split the "net: mvneta: convert to phylink" patch up to make it easier to review, and in doing so, spotted some minor corner cases that needed to be fixed along the way.
This series depends on the previously merged phylink patches in netdev, along with the recently reviewed 7 patch series "Resolve races in phy accessors" without which, the race described in patch 5 of that series is very evident when triggering a dummy hibernate cycle.
This series also illustrates how to convert mvpp2 to phylink.
mvneta is the only user of the
fixed_phy_update_state()API, and this becomes redundant with the conversion.It would be good to get this series not only reviewed, but also independently tested to ensure that I haven't missed anything - I only have the Clearfog platform to test on, and that doesn't support all the different interface modes that mvneta supports.
A particularly interesting side effect of this series is that DSA switches no longer need the "CPU" port and DSA facing MAC ethernet instance to be marked as a fixed link anymore with mvneta - we can use 1000BaseX mode, and the DSA to CPU link will use the 802.3z negotiation to determine the link properties without needing the link parameters to be explicitly stated in DT - that is a subject of a future patch.
Quoted 5 lines
drivers/net/ethernet/marvell/Kconfig | 2 +- drivers/net/ethernet/marvell/mvneta.c | 687 ++++++++++++++++++++-------------- drivers/net/phy/fixed_phy.c | 31 -- include/linux/phy_fixed.h | 9 - 4 files changed, 405 insertions(+), 324 deletions(-)
Of course, this series is for net-next, not net... forgot to add that annotation, sorry.
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up
David Miller
maintainerFrom: Russell King - ARM Linux <[email protected]>
Date: Tue, 2 Jan 2018 17:22:42 +0000
Quoted 25 lines
This series converts mvneta to use phylink, which is necessary to support the SFP cages on SolidRun's Clearfog platform. This series just converts mvneta without adding the DT parts - having discussed with Andrew, we believe we're too close to the merge window to submit that patch.
I've split the "net: mvneta: convert to phylink" patch up to make it easier to review, and in doing so, spotted some minor corner cases that needed to be fixed along the way.
This series depends on the previously merged phylink patches in netdev, along with the recently reviewed 7 patch series "Resolve races in phy accessors" without which, the race described in patch 5 of that series is very evident when triggering a dummy hibernate cycle.
This series also illustrates how to convert mvpp2 to phylink.
mvneta is the only user of the
fixed_phy_update_state()API, and this becomes redundant with the conversion.It would be good to get this series not only reviewed, but also independently tested to ensure that I haven't missed anything - I only have the Clearfog platform to test on, and that doesn't support all the different interface modes that mvneta supports.
Quoted 6 lines
A particularly interesting side effect of this series is that DSA switches no longer need the "CPU" port and DSA facing MAC ethernet instance to be marked as a fixed link anymore with mvneta - we can use 1000BaseX mode, and the DSA to CPU link will use the 802.3z negotiation to determine the link properties without needing the link parameters to be explicitly stated in DT - that is a subject of a future patch.
This looks good to me, series applied, thanks Russell.