net: dsa: Plug in PHYLINK support
Subsystems (7)
v2 cover net: dsa: Plug in PHYLINK support
Hi all,
This patch series adds PHYLINK support to DSA which is necessary to support more complex PHY and pluggable modules setups.
Patch series can be found here:
https://github.com/ffainelli/linux/commits/dsa-phylink-v2
This was tested on:
- dsa-loop
- bcm_sf2
- mv88e6xxx
- b53
With a variety of test cases:
- internal & external MDIO PHYs
- MoCA with link notification through interrupt/MMIO register
- built-in PHYs
- ifconfig up/down for several cycles works
- bind/unbind of the drivers
Changes in v2:
- fixed link configuration for mv88e6xxx (Andrew) after introducing polling
This is technically v2 of what was posted back in March 2018, changes from last time:
- fixed probe/remove of drivers
- fixed missing gpiod_put() for link GPIOs
- fixed polling of link GPIOs (Russell I would need your SoB on the patch you provided offline initially, added some modifications to it)
- tested across a wider set of platforms
And everything should still work as expected. Please be aware of the following:
- switch drivers (like bcm_sf2) which may have user-facing network ports using fixed links would need to implement phylink_mac_ops to remain functional. PHYLINK does not create a phy_device for fixed links, therefore our call to adjust_link() from phylink_mac_link_{up,down} would not be calling into the driver. This *should not* affect CPU/DSA ports which are configured through adjust_link() but have no network devices
- support for SFP/SFF is now possible, but switch drivers will still need some modifications to properly support those, including, but not limited to using the correct binding information. This will be submitted on top of this series
Please do test on your respective platforms/switches and let me know if you find any issues, hopefully everything still works like before.
Thank you!
Florian Fainelli (7):
net: phy: phylink: Use gpiod_get_value_cansleep()
net: phy: phylink: Release link GPIO
net: dsa: Add PHYLINK switch operations
net: dsa: bcm_sf2: Implement phylink_mac_ops
net: dsa: Eliminate dsa_slave_get_link()
net: dsa: Plug in PHYLINK support
net: dsa: bcm_sf2: Get rid of PHYLIB functions
Russell King (2):
net: phy: phylink: Poll link GPIOs
net: dsa: mv88e6xxx: add PHYLINK support
drivers/net/dsa/bcm_sf2.c | 191 +++++++++++++++---------- drivers/net/dsa/mv88e6xxx/chip.c | 83 +++++++++++ drivers/net/dsa/mv88e6xxx/port.c | 39 ++++++ drivers/net/dsa/mv88e6xxx/port.h | 3 + drivers/net/phy/phylink.c | 20 ++- include/net/dsa.h | 25 ++++ net/dsa/Kconfig | 2 +- net/dsa/dsa_priv.h | 9 -- net/dsa/slave.c | 293 ++++++++++++++++++++++----------------- 9 files changed, 458 insertions(+), 207 deletions(-)
Signature · 1 line
2.14.1
PATCH v2 1/9 net: phy: phylink: Use gpiod_get_value_cansleep()
The GPIO provider for the link GPIO line might require the use of the _cansleep() API, utilize that. This is safe to do since we run in workqueue context.
--- drivers/net/phy/phylink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/phylink.c +1 -1
@@ -360,7 +360,7 @@ static void phylink_get_fixed_state(struct phylink *pl, struct phylink_link_statif (pl->get_fixed_state) pl->get_fixed_state (pl->netdev, state);else if (pl->link_gpio) - state->link = !!gpiod_get_value (pl->link_gpio); + state->link = !!gpiod_get_value_cansleep (pl->link_gpio); }/* Flow control is resolved according to our and the link partners
Signature · 1 line
2.14.1
PATCH v2 2/9 net: phy: phylink: Release link GPIO
In reply to Florian FainelliWe are not releasing the link GPIO descriptor with gpiod_put() which results in subsequent probing to get -EBUSY when calling fwnode_get_named_gpiod(). Fix this by doing the release in phylink_destroy().
--- drivers/net/phy/phylink.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/phy/phylink.c +2 -0
@@ -612,6 +612,8 @@ void phylink_destroy(struct phylink *pl) {if (pl->sfp_bus)sfp_unregister_upstream (pl->sfp_bus); +if (!IS_ERR (pl->link_gpio)) +gpiod_put (pl->link_gpio);cancel_work_sync (&pl->resolve);kfree (pl);
Signature · 1 line
2.14.1
PATCH v2 3/9 net: phy: phylink: Poll link GPIOs
In reply to Florian FainelliFrom: Russell King <[email protected]>
When using a fixed link with a link GPIO, we need to poll that GPIO to determine link state changes. This is consistent with what fixed_phy.c does.
--- drivers/net/phy/phylink.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/net/phy/phylink.c +16 -0
@@ -19,6 +19,7 @@#include <linux/phylink.h> #include <linux/rtnetlink.h> #include <linux/spinlock.h> +#include <linux/timer.h> #include <linux/workqueue.h> #include "sfp.h"
@@ -54,6 +55,7 @@ struct phylink {/* The link configuration settings */ struct phylink_link_state link_config;struct gpio_desc *link_gpio; +struct timer_list link_poll;void (*get_fixed_state)(struct net_device *dev,struct phylink_link_state *s);
@@ -500,6 +502,15 @@ static void phylink_run_resolve(struct phylink *pl)queue_work (system_power_efficient_wq, &pl->resolve); } +static void phylink_fixed_poll (struct timer_list *t) +{ + struct phylink *pl = container_of(t, struct phylink, link_poll); + +mod_timer (t, jiffies +HZ ); + +phylink_run_resolve (pl); +} +static const struct sfp_upstream_ops sfp_phylink_ops; static int phylink_register_sfp(struct phylink *pl,
@@ -572,6 +583,7 @@ struct phylink *phylink_create(struct net_device *ndev, pl->link_config.an_enabled = true; pl->ops = ops;__set_bit (PHYLINK_DISABLE_STOPPED , &pl->phylink_disable_state); +timer_setup (&pl->link_poll, phylink_fixed_poll,0 );bitmap_fill (pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS);linkmode_copy (pl->link_config.advertising, pl->supported);
@@ -905,6 +917,8 @@ void phylink_start(struct phylink *pl)clear_bit (PHYLINK_DISABLE_STOPPED , &pl->phylink_disable_state);phylink_run_resolve (pl); +if (pl->link_an_mode ==MLO_AN_FIXED && !IS_ERR (pl->link_gpio)) +mod_timer (&pl->link_poll, jiffies +HZ );if (pl->sfp_bus)sfp_upstream_start (pl->sfp_bus);if (pl->phydev)
@@ -929,6 +943,8 @@ void phylink_stop(struct phylink *pl)phy_stop (pl->phydev);if (pl->sfp_bus)sfp_upstream_stop (pl->sfp_bus); +if (pl->link_an_mode ==MLO_AN_FIXED && !IS_ERR (pl->link_gpio)) +del_timer_sync (&pl->link_poll);set_bit (PHYLINK_DISABLE_STOPPED , &pl->phylink_disable_state);queue_work (system_power_efficient_wq, &pl->resolve);
Signature · 1 line
2.14.1
PATCH v2 4/9 net: dsa: Add PHYLINK switch operations
In reply to Florian FainelliIn preparation for adding support for PHYLINK within DSA, define a number of operations that we will need and that switch drivers can start implementing. Proper integration with PHYLINK will follow in subsequent patches.
We start selecting PHYLINK (which implies PHYLIB) in net/dsa/Kconfig such that drivers can be guaranteed that this dependency is properly taken care of and can start referencing PHYLINK helper functions without requiring stubs or anything.
--- include/net/dsa.h | 24 ++++++++++++++++++++++++ net/dsa/Kconfig | 2 +- net/dsa/slave.c | 5 +++++ 3 files changed, 30 insertions(+), 1 deletion(-)
include/net/dsa.h +24 -0
@@ -20,12 +20,14 @@#include <linux/of.h> #include <linux/ethtool.h> #include <linux/net_tstamp.h> +#include <linux/phy.h> #include <net/devlink.h> #include <net/switchdev.h> struct tc_action ;struct phy_device ;struct fixed_phy_status ; +struct phylink_link_state ;enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =0 ,
@@ -353,6 +355,27 @@ struct dsa_switch_ops {void (*fixed_link_update)(struct dsa_switch *ds,int port,struct fixed_phy_status *st); +/* +* PHYLINK integration +*/ +void (*phylink_validate)(struct dsa_switch *ds,int port, +unsigned long *supported, +struct phylink_link_state *state); +int (*phylink_mac_link_state)(struct dsa_switch *ds,int port, +struct phylink_link_state *state); +void (*phylink_mac_config)(struct dsa_switch *ds,int port, +unsigned int mode, +const struct phylink_link_state *state); +void (*phylink_mac_an_restart)(struct dsa_switch *ds,int port); +void (*phylink_mac_link_down)(struct dsa_switch *ds,int port, +unsigned int mode, +phy_interface_t interface); +void (*phylink_mac_link_up)(struct dsa_switch *ds,int port, +unsigned int mode, +phy_interface_t interface, +struct phy_device *phydev); +void (*phylink_fixed_state)(struct dsa_switch *ds,int port, +struct phylink_link_state *state);/* * ethtool hardware statistics. */
@@ -595,5 +618,6 @@ static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev,int dsa_port_get_phy_strings (struct dsa_port *dp,uint8_t *data);int dsa_port_get_ethtool_phy_stats (struct dsa_port *dp,uint64_t *data);int dsa_port_get_phy_sset_count (struct dsa_port *dp); +void dsa_port_phylink_mac_change (struct dsa_switch *ds,int port,bool up);#endif
net/dsa/Kconfig +1 -1
@@ -9,7 +9,7 @@ config NET_DSA depends on HAVE_NET_DSA && MAY_USE_DEVLINK depends on BRIDGE || BRIDGE=n select NET_SWITCHDEV - select PHYLIB + select PHYLINK ---help--- Say Y if you want to enable support for the hardware switches supported by the Distributed Switch Architecture.
net/dsa/slave.c +5 -0
@@ -1119,6 +1119,11 @@ static int dsa_slave_phy_connect(struct net_device *slave_dev, int addr) dsa_slave_adjust_link, p->phy_interface); } +void dsa_port_phylink_mac_change (struct dsa_switch *ds,int port,bool up) +{ +} +EXPORT_SYMBOL_GPL (dsa_port_phylink_mac_change); +static int dsa_slave_phy_setup (struct net_device *slave_dev) {struct dsa_port *dp =dsa_slave_to_port (slave_dev);
Signature · 1 line
2.14.1
PATCH v2 5/9 net: dsa: bcm_sf2: Implement phylink_mac_ops
In reply to Florian FainelliMake the bcm_sf2 driver implement phylink_mac_ops since it needs to support a wide variety of network interfaces: internal & external MDIO PHYs, fixed PHYs, MoCA with MMIO link status.
A large amount of what needs to be done already exists under bcm_sf2_sw_adjust_link() so we are essentially breaking this down into the necessary operation for PHYLINK to work: mac_config, mac_link_up, mac_link_down and validate. We can now entirely get rid of most of what fixed_link_update() provided because only the link information is actually necessary. We still have to force DUPLEX_FULL for legacy Device Tree bindings that did not specify that before.
--- drivers/net/dsa/bcm_sf2.c | 214 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 206 insertions(+), 8 deletions(-)
drivers/net/dsa/bcm_sf2.c +206 -8
@@ -16,6 +16,7 @@#include <linux/platform_device.h> #include <linux/phy.h> #include <linux/phy_fixed.h> +#include <linux/phylink.h> #include <linux/mii.h> #include <linux/of.h> #include <linux/of_irq.h>
@@ -306,7 +307,8 @@ static int bcm_sf2_sw_mdio_write(struct mii_bus *bus, int addr, int regnum,static irqreturn_t bcm_sf2_switch_0_isr (int irq,void *dev_id) { -struct bcm_sf2_priv *priv = dev_id; +struct dsa_switch *ds = dev_id; +struct bcm_sf2_priv *priv =bcm_sf2_to_priv (ds); priv->irq0_stat =intrl2_0_readl (priv,INTRL2_CPU_STATUS ) & ~priv->irq0_mask;
@@ -317,16 +319,21 @@ static irqreturn_t bcm_sf2_switch_0_isr(int irq, void *dev_id)static irqreturn_t bcm_sf2_switch_1_isr (int irq,void *dev_id) { -struct bcm_sf2_priv *priv = dev_id; +struct dsa_switch *ds = dev_id; +struct bcm_sf2_priv *priv =bcm_sf2_to_priv (ds); priv->irq1_stat =intrl2_1_readl (priv,INTRL2_CPU_STATUS ) & ~priv->irq1_mask;intrl2_1_writel (priv, priv->irq1_stat,INTRL2_CPU_CLEAR ); -if (priv->irq1_stat &P_LINK_UP_IRQ (P7_IRQ_OFF )) - priv->port_sts[7 ].link =1 ; -if (priv->irq1_stat &P_LINK_DOWN_IRQ (P7_IRQ_OFF )) - priv->port_sts[7 ].link =0 ; +if (priv->irq1_stat &P_LINK_UP_IRQ (P7_IRQ_OFF )) { + priv->port_sts[7 ].link = true; +dsa_port_phylink_mac_change (ds,7 , true); + } +if (priv->irq1_stat &P_LINK_DOWN_IRQ (P7_IRQ_OFF )) { + priv->port_sts[7 ].link = false; +dsa_port_phylink_mac_change (ds,7 , false); + }return IRQ_HANDLED ; }
@@ -620,6 +627,192 @@ static void bcm_sf2_sw_fixed_link_update(struct dsa_switch *ds, int port, status->pause =1 ; } +static void bcm_sf2_sw_validate (struct dsa_switch *ds,int port, +unsigned long *supported, +struct phylink_link_state *state) +{ +__ETHTOOL_DECLARE_LINK_MODE_MASK (mask) = {0 , }; + +if (!phy_interface_mode_is_rgmii (state->interface) && + state->interface !=PHY_INTERFACE_MODE_MII && + state->interface !=PHY_INTERFACE_MODE_REVMII && + state->interface !=PHY_INTERFACE_MODE_GMII && + state->interface !=PHY_INTERFACE_MODE_INTERNAL && + state->interface !=PHY_INTERFACE_MODE_MOCA ) { +bitmap_zero (supported, __ETHTOOL_LINK_MODE_MASK_NBITS); +dev_err (ds->dev, +"Unsupported interface: %d\n" , state->interface); +return ; + } + +/* Allow all the expected bits */ +phylink_set (mask, Autoneg); +phylink_set_port_modes (mask); +phylink_set (mask, Pause); +phylink_set (mask, Asym_Pause); + +/* With the exclusion of MII and Reverse MII, we support Gigabit, +* including Half duplex +*/ +if (state->interface !=PHY_INTERFACE_MODE_MII && + state->interface !=PHY_INTERFACE_MODE_REVMII ) { + phylink_set(mask, 1000baseT_Full); + phylink_set(mask, 1000baseT_Half); + } + + 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); +bitmap_and (state->advertising, state->advertising, mask, + __ETHTOOL_LINK_MODE_MASK_NBITS); +} + +static void bcm_sf2_sw_mac_config (struct dsa_switch *ds,int port, +unsigned int mode, +const struct phylink_link_state *state) +{ +struct bcm_sf2_priv *priv =bcm_sf2_to_priv (ds); +u32 id_mode_dis =0 , port_mode; +u32 reg, offset; + +if (priv->type ==BCM7445_DEVICE_ID ) + offset =CORE_STS_OVERRIDE_GMIIP_PORT (port); +else + offset =CORE_STS_OVERRIDE_GMIIP2_PORT (port); + +switch (state->interface) { +case PHY_INTERFACE_MODE_RGMII : + id_mode_dis =1 ; +/* fallthrough */ +case PHY_INTERFACE_MODE_RGMII_TXID : + port_mode =EXT_GPHY ; +break ; +case PHY_INTERFACE_MODE_MII : + port_mode =EXT_EPHY ; +break ; +case PHY_INTERFACE_MODE_REVMII : + port_mode =EXT_REVMII ; +break ; +default : +/* all other PHYs: internal and MoCA */ + goto force_link; + } + +/* Clear id_mode_dis bit, and the existing port mode, let +* RGMII_MODE_EN bet set by mac_link_{up,down} +*/ + reg =reg_readl (priv,REG_RGMII_CNTRL_P (port)); + reg &= ~ID_MODE_DIS ; + reg &= ~(PORT_MODE_MASK <<PORT_MODE_SHIFT ); + reg &= ~(RX_PAUSE_EN |TX_PAUSE_EN ); + + reg |= port_mode; +if (id_mode_dis) + reg |=ID_MODE_DIS ; + +if (state->pause &MLO_PAUSE_TXRX_MASK ) { +if (state->pause &MLO_PAUSE_TX ) + reg |=TX_PAUSE_EN ; + reg |=RX_PAUSE_EN ; + } + +reg_writel (priv, reg,REG_RGMII_CNTRL_P (port)); + +force_link: +/* Force link settings detected from the PHY */ + reg =SW_OVERRIDE ; +switch (state->speed) { +case SPEED_1000 : + reg |=SPDSTS_1000 <<SPEED_SHIFT ; +break ; +case SPEED_100 : + reg |=SPDSTS_100 <<SPEED_SHIFT ; +break ; + } + +if (state->link) + reg |=LINK_STS ; +if (state->duplex ==DUPLEX_FULL ) + reg |=DUPLX_MODE ; + +core_writel (priv, reg, offset); +} + +static void bcm_sf2_sw_mac_link_set (struct dsa_switch *ds,int port, +phy_interface_t interface,bool link) +{ +struct bcm_sf2_priv *priv =bcm_sf2_to_priv (ds); +u32 reg; + +if (!phy_interface_mode_is_rgmii (interface) && + interface !=PHY_INTERFACE_MODE_MII && + interface !=PHY_INTERFACE_MODE_REVMII ) +return ; + +/* If the link is down, just disable the interface to conserve power */ + reg =reg_readl (priv,REG_RGMII_CNTRL_P (port)); +if (link) + reg |=RGMII_MODE_EN ; +else + reg &= ~RGMII_MODE_EN ; +reg_writel (priv, reg,REG_RGMII_CNTRL_P (port)); +} + +static void bcm_sf2_sw_mac_link_down (struct dsa_switch *ds,int port, +unsigned int mode, +phy_interface_t interface) +{ +bcm_sf2_sw_mac_link_set (ds, port, interface, false); +} + +static void bcm_sf2_sw_mac_link_up (struct dsa_switch *ds,int port, +unsigned int mode, +phy_interface_t interface, +struct phy_device *phydev) +{ +struct bcm_sf2_priv *priv =bcm_sf2_to_priv (ds); +struct ethtool_eee *p = &priv->dev->ports[port].eee; + +bcm_sf2_sw_mac_link_set (ds, port, interface, true); + +if (mode ==MLO_AN_PHY && phydev) + p->eee_enabled =b53_eee_init (ds, port, phydev); +} + +static void bcm_sf2_sw_fixed_state (struct dsa_switch *ds,int port, +struct phylink_link_state *status) +{ +struct bcm_sf2_priv *priv =bcm_sf2_to_priv (ds); + + status->link = false; + +/* MoCA port is special as we do not get link status from CORE_LNKSTS, +* which means that we need to force the link at the port override +* level to get the data to flow. We do use what the interrupt handler +* did determine before. +* +* For the other ports, we just force the link status, since this is +* a fixed PHY device. +*/ +if (port == priv->moca_port) { + status->link = priv->port_sts[port].link; +/* For MoCA interfaces, also force a link down notification +* since some version of the user-space daemon (mocad) use +* cmd->autoneg to force the link, which messes up the PHY +* state machine and make it go in PHY_FORCING state instead. +*/ +if (!status->link) +netif_carrier_off (ds->ports[port].slave); + status->duplex =DUPLEX_FULL ; + }else { + status->link = true; + } +} +static void bcm_sf2_enable_acb (struct dsa_switch *ds) {struct bcm_sf2_priv *priv =bcm_sf2_to_priv (ds);
@@ -863,6 +1056,11 @@ static const struct dsa_switch_ops bcm_sf2_ops = { .get_phy_flags = bcm_sf2_sw_get_phy_flags, .adjust_link = bcm_sf2_sw_adjust_link, .fixed_link_update = bcm_sf2_sw_fixed_link_update, + .phylink_validate = bcm_sf2_sw_validate, + .phylink_mac_config = bcm_sf2_sw_mac_config, + .phylink_mac_link_down = bcm_sf2_sw_mac_link_down, + .phylink_mac_link_up = bcm_sf2_sw_mac_link_up, + .phylink_fixed_state = bcm_sf2_sw_fixed_state, .suspend = bcm_sf2_sw_suspend, .resume = bcm_sf2_sw_resume, .get_wol = bcm_sf2_sw_get_wol,
@@ -1065,14 +1263,14 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev)bcm_sf2_intr_disable (priv); ret =devm_request_irq (&pdev->dev, priv->irq0, bcm_sf2_switch_0_isr,0 , -"switch_0" , priv); +"switch_0" , ds);if (ret <0 ) {pr_err ("failed to request switch_0 IRQ\n" ); goto out_mdio; } ret =devm_request_irq (&pdev->dev, priv->irq1, bcm_sf2_switch_1_isr,0 , -"switch_1" , priv); +"switch_1" , ds);if (ret <0 ) {pr_err ("failed to request switch_1 IRQ\n" ); goto out_mdio;
Signature · 1 line
2.14.1
PATCH v2 6/9 net: dsa: Eliminate dsa_slave_get_link()
In reply to Florian FainelliSince we use PHYLIB to manage the per-port link indication, this will also be reflected correctly in the network device's carrier state, so we can use ethtool_op_get_link() instead.
--- net/dsa/slave.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
net/dsa/slave.c +1 -11
@@ -498,16 +498,6 @@ dsa_slave_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p) ds->ops->get_regs (ds, dp->index, regs, _p); } -static u32 dsa_slave_get_link (struct net_device *dev) -{ -if (!dev->phydev) -return -ENODEV ; - -genphy_update_link (dev->phydev); - -return dev->phydev->link; -} -static int dsa_slave_get_eeprom_len (struct net_device *dev) {struct dsa_port *dp =dsa_slave_to_port (dev);
@@ -982,7 +972,7 @@ static const struct ethtool_ops dsa_slave_ethtool_ops = { .get_regs_len = dsa_slave_get_regs_len, .get_regs = dsa_slave_get_regs, .nway_reset = phy_ethtool_nway_reset, - .get_link = dsa_slave_get_link, + .get_link = ethtool_op_get_link, .get_eeprom_len = dsa_slave_get_eeprom_len, .get_eeprom = dsa_slave_get_eeprom, .set_eeprom = dsa_slave_set_eeprom,
Signature · 1 line
2.14.1
PATCH v2 7/9 net: dsa: mv88e6xxx: add PHYLINK support
In reply to Florian FainelliFrom: Russell King <[email protected]>
Add rudimentary phylink support to mv88e6xxx. This allows the driver using user ports with fixed links to keep operating normally. User ports with normal PHYs are not affected since the switch automatically manages their link parameters. User facing ports which use a SFP/SFF with a non-fixed link mode might require a call to phylink_mac_change() to operate properly.
--- drivers/net/dsa/mv88e6xxx/chip.c | 83 ++++++++++++++++++++++++++++++++++++++++ drivers/net/dsa/mv88e6xxx/port.c | 39 +++++++++++++++++++ drivers/net/dsa/mv88e6xxx/port.h | 3 ++ 3 files changed, 125 insertions(+)
drivers/net/dsa/mv88e6xxx/chip.c +83 -0
@@ -31,6 +31,7 @@#include <linux/netdevice.h> #include <linux/gpio/consumer.h> #include <linux/phy.h> +#include <linux/phylink.h> #include <net/dsa.h> #include "chip.h"
@@ -580,6 +581,83 @@ static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,dev_err (ds->dev,"p%d: failed to configure MAC\n" , port); } +static void mv88e6xxx_validate (struct dsa_switch *ds,int port, +unsigned long *supported, +struct phylink_link_state *state) +{ +} + +static int mv88e6xxx_link_state (struct dsa_switch *ds,int port, +struct phylink_link_state *state) +{ +struct mv88e6xxx_chip *chip = ds->priv; +int err; + +mutex_lock (&chip->reg_lock); + err =mv88e6xxx_port_link_state (chip, port, state); +mutex_unlock (&chip->reg_lock); + +return err; +} + +static void mv88e6xxx_mac_config (struct dsa_switch *ds,int port, +unsigned int mode, +const struct phylink_link_state *state) +{ +struct mv88e6xxx_chip *chip = ds->priv; +int speed, duplex, link, err; + +if (mode ==MLO_AN_PHY ) +return ; + +if (mode ==MLO_AN_FIXED ) { + link =LINK_FORCED_UP ; + speed = state->speed; + duplex = state->duplex; + }else { + speed =SPEED_UNFORCED ; + duplex =DUPLEX_UNFORCED ; + link =LINK_UNFORCED ; + } + +mutex_lock (&chip->reg_lock); + err =mv88e6xxx_port_setup_mac (chip, port, link, speed, duplex, + state->interface); +mutex_unlock (&chip->reg_lock); + +if (err && err != -EOPNOTSUPP ) +dev_err (ds->dev,"p%d: failed to configure MAC\n" , port); +} + +static void mv88e6xxx_mac_link_force (struct dsa_switch *ds,int port,int link) +{ +struct mv88e6xxx_chip *chip = ds->priv; +int err; + +mutex_lock (&chip->reg_lock); + err = chip->info->ops->port_set_link (chip, port, link); +mutex_unlock (&chip->reg_lock); + +if (err) +dev_err (chip->dev,"p%d: failed to force MAC link\n" , port); +} + +static void mv88e6xxx_mac_link_down (struct dsa_switch *ds,int port, +unsigned int mode, +phy_interface_t interface) +{ +if (mode ==MLO_AN_FIXED ) +mv88e6xxx_mac_link_force (ds, port,LINK_FORCED_DOWN ); +} + +static void mv88e6xxx_mac_link_up (struct dsa_switch *ds,int port, +unsigned int mode,phy_interface_t interface, +struct phy_device *phydev) +{ +if (mode ==MLO_AN_FIXED ) +mv88e6xxx_mac_link_force (ds, port,LINK_FORCED_UP ); +} +static int mv88e6xxx_stats_snapshot (struct mv88e6xxx_chip *chip,int port) {if (!chip->info->ops->stats_snapshot)
@@ -4140,6 +4218,11 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = { .get_tag_protocol = mv88e6xxx_get_tag_protocol, .setup = mv88e6xxx_setup, .adjust_link = mv88e6xxx_adjust_link, + .phylink_validate = mv88e6xxx_validate, + .phylink_mac_link_state = mv88e6xxx_link_state, + .phylink_mac_config = mv88e6xxx_mac_config, + .phylink_mac_link_down = mv88e6xxx_mac_link_down, + .phylink_mac_link_up = mv88e6xxx_mac_link_up, .get_strings = mv88e6xxx_get_strings, .get_ethtool_stats = mv88e6xxx_get_ethtool_stats, .get_sset_count = mv88e6xxx_get_sset_count,
drivers/net/dsa/mv88e6xxx/port.c +39 -0
@@ -15,6 +15,7 @@#include <linux/bitfield.h> #include <linux/if_bridge.h> #include <linux/phy.h> +#include <linux/phylink.h> #include "chip.h" #include "port.h"
@@ -378,6 +379,44 @@ int mv88e6xxx_port_get_cmode(struct mv88e6xxx_chip *chip, int port, u8 *cmode)return 0 ; } +int mv88e6xxx_port_link_state (struct mv88e6xxx_chip *chip,int port, +struct phylink_link_state *state) +{ +int err; +u16 reg; + + err =mv88e6xxx_port_read (chip, port,MV88E6XXX_PORT_STS , ®); +if (err) +return err; + +switch (reg &MV88E6XXX_PORT_STS_SPEED_MASK ) { +case MV88E6XXX_PORT_STS_SPEED_10 : + state->speed =SPEED_10 ; +break ; +case MV88E6XXX_PORT_STS_SPEED_100 : + state->speed =SPEED_100 ; +break ; +case MV88E6XXX_PORT_STS_SPEED_1000 : + state->speed =SPEED_1000 ; +break ; +case MV88E6XXX_PORT_STS_SPEED_10000 : +if ((reg &MV88E6XXX_PORT_STS_CMODE_MASK ) == +MV88E6XXX_PORT_STS_CMODE_2500BASEX ) + state->speed =SPEED_2500 ; +else + state->speed =SPEED_10000 ; +break ; + } + + state->duplex = reg &MV88E6XXX_PORT_STS_DUPLEX ? +DUPLEX_FULL :DUPLEX_HALF ; + state->link = !!(reg &MV88E6XXX_PORT_STS_LINK ); + state->an_enabled =1 ; + state->an_complete = state->link; + +return 0 ; +} +/* Offset 0x02: Jamming Control * * Do not limit the period of time that this port can be paused for by
drivers/net/dsa/mv88e6xxx/port.h +3 -0
@@ -29,6 +29,7 @@#define MV88E6XXX_PORT_STS_SPEED_10 0x0000#define MV88E6XXX_PORT_STS_SPEED_100 0x0100#define MV88E6XXX_PORT_STS_SPEED_1000 0x0200 +#define MV88E6XXX_PORT_STS_SPEED_10000 0x0300#define MV88E6352_PORT_STS_EEE 0x0040#define MV88E6165_PORT_STS_AM_DIS 0x0040#define MV88E6185_PORT_STS_MGMII 0x0040
@@ -295,6 +296,8 @@ int mv88e6390_port_pause_limit(struct mv88e6xxx_chip *chip, int port, u8 in,int mv88e6390x_port_set_cmode (struct mv88e6xxx_chip *chip,int port,phy_interface_t mode);int mv88e6xxx_port_get_cmode (struct mv88e6xxx_chip *chip,int port,u8 *cmode); +int mv88e6xxx_port_link_state (struct mv88e6xxx_chip *chip,int port, +struct phylink_link_state *state);int mv88e6xxx_port_set_map_da (struct mv88e6xxx_chip *chip,int port);int mv88e6095_port_set_upstream_port (struct mv88e6xxx_chip *chip,int port,int upstream_port);
Signature · 1 line
2.14.1
PATCH v2 8/9 net: dsa: Plug in PHYLINK support
In reply to Florian FainelliAdd support for PHYLINK within the DSA subsystem in order to support more complex devices such as pluggable (SFP) and non-pluggable (SFF) modules, 10G PHYs, and traditional PHYs. Using PHYLINK allows us to drop some amount of complexity we had while probing fixed and non-fixed PHYs using Device Tree.
Because PHYLINK separates the Ethernet MAC/port configuration into different stages, we let switch drivers implement those, and for now, we maintain functionality by calling dsa_slave_adjust_link() during phylink_mac_link_{up,down} which provides semantically equivalent steps.
Drivers willing to take advantage of PHYLINK should implement the phylink_mac_* operations that DSA wraps.
We cannot quite remove the adjust_link() callback just yet, because a number of drivers rely on that for configuring their "CPU" and "DSA" ports, this is done dsa_port_setup_phy_of() and dsa_port_fixed_link_register_of() still.
Drivers that utilize fixed links for user-facing ports (e.g: bcm_sf2) will need to implement phylink_mac_ops from now on to preserve functionality, since PHYLINK *does not* create a phy_device instance for fixed links.
--- include/net/dsa.h | 1 + net/dsa/dsa_priv.h | 9 -- net/dsa/slave.c | 294 +++++++++++++++++++++++++++++++---------------------- 3 files changed, 172 insertions(+), 132 deletions(-)
include/net/dsa.h +1 -0
@@ -201,6 +201,7 @@ struct dsa_port {u8 stp_state;struct net_device *bridge_dev;struct devlink_port devlink_port; +struct phylink *pl;/* * Original copy of the master netdev ethtool_ops */
net/dsa/dsa_priv.h +0 -9
@@ -75,15 +75,6 @@ struct dsa_slave_priv {/* DSA port data, such as switch, port index, etc. */ struct dsa_port *dp; -/* -* The phylib phy_device pointer for the PHY connected -* to this port. -*/ -phy_interface_t phy_interface; -int old_link; -int old_pause; -int old_duplex; -#ifdef CONFIG_NET_POLL_CONTROLLER struct netpoll *netpoll;#endif
net/dsa/slave.c +171 -123
458 lines not on this page · raw message
Signature · 1 line
2.14.1
PATCH v2 9/9 net: dsa: bcm_sf2: Get rid of PHYLIB functions
In reply to Florian FainelliNow that we have converted the bcm_sf2 driver to implement PHYLINK MAC operations, we can remove the PHYLIB callbacks: adjust_link() and fixed_link_update() which are no longer called by DSA.
--- drivers/net/dsa/bcm_sf2.c | 149 ---------------------------------------------- 1 file changed, 149 deletions(-)
drivers/net/dsa/bcm_sf2.c +0 -149
@@ -480,153 +480,6 @@ static u32 bcm_sf2_sw_get_phy_flags(struct dsa_switch *ds, int port)return priv->hw_params.gphy_rev; } -static void bcm_sf2_sw_adjust_link (struct dsa_switch *ds,int port, -struct phy_device *phydev) -{ -struct bcm_sf2_priv *priv =bcm_sf2_to_priv (ds); -struct ethtool_eee *p = &priv->dev->ports[port].eee; -u32 id_mode_dis =0 , port_mode; -const char *str =NULL ; -u32 reg, offset; - -if (priv->type ==BCM7445_DEVICE_ID ) - offset =CORE_STS_OVERRIDE_GMIIP_PORT (port); -else - offset =CORE_STS_OVERRIDE_GMIIP2_PORT (port); - -switch (phydev->interface) { -case PHY_INTERFACE_MODE_RGMII : - str ="RGMII (no delay)" ; - id_mode_dis =1 ; -case PHY_INTERFACE_MODE_RGMII_TXID : -if (!str) - str ="RGMII (TX delay)" ; - port_mode =EXT_GPHY ; -break ; -case PHY_INTERFACE_MODE_MII : - str ="MII" ; - port_mode =EXT_EPHY ; -break ; -case PHY_INTERFACE_MODE_REVMII : - str ="Reverse MII" ; - port_mode =EXT_REVMII ; -break ; -default : -/* All other PHYs: internal and MoCA */ - goto force_link; - } - -/* If the link is down, just disable the interface to conserve power */ -if (!phydev->link) { - reg =reg_readl (priv,REG_RGMII_CNTRL_P (port)); - reg &= ~RGMII_MODE_EN ; -reg_writel (priv, reg,REG_RGMII_CNTRL_P (port)); - goto force_link; - } - -/* Clear id_mode_dis bit, and the existing port mode, but -* make sure we enable the RGMII block for data to pass -*/ - reg =reg_readl (priv,REG_RGMII_CNTRL_P (port)); - reg &= ~ID_MODE_DIS ; - reg &= ~(PORT_MODE_MASK <<PORT_MODE_SHIFT ); - reg &= ~(RX_PAUSE_EN |TX_PAUSE_EN ); - - reg |= port_mode |RGMII_MODE_EN ; -if (id_mode_dis) - reg |=ID_MODE_DIS ; - -if (phydev->pause) { -if (phydev->asym_pause) - reg |=TX_PAUSE_EN ; - reg |=RX_PAUSE_EN ; - } - -reg_writel (priv, reg,REG_RGMII_CNTRL_P (port)); - -pr_info ("Port %d configured for %s\n" , port, str); - -force_link: -/* Force link settings detected from the PHY */ - reg =SW_OVERRIDE ; -switch (phydev->speed) { -case SPEED_1000 : - reg |=SPDSTS_1000 <<SPEED_SHIFT ; -break ; -case SPEED_100 : - reg |=SPDSTS_100 <<SPEED_SHIFT ; -break ; - } - -if (phydev->link) - reg |=LINK_STS ; -if (phydev->duplex ==DUPLEX_FULL ) - reg |=DUPLX_MODE ; - -core_writel (priv, reg, offset); - -if (!phydev->is_pseudo_fixed_link) - p->eee_enabled =b53_eee_init (ds, port, phydev); -} - -static void bcm_sf2_sw_fixed_link_update (struct dsa_switch *ds,int port, -struct fixed_phy_status *status) -{ -struct bcm_sf2_priv *priv =bcm_sf2_to_priv (ds); -u32 duplex, pause, offset; -u32 reg; - -if (priv->type ==BCM7445_DEVICE_ID ) - offset =CORE_STS_OVERRIDE_GMIIP_PORT (port); -else - offset =CORE_STS_OVERRIDE_GMIIP2_PORT (port); - - duplex =core_readl (priv,CORE_DUPSTS ); - pause =core_readl (priv,CORE_PAUSESTS ); - - status->link =0 ; - -/* MoCA port is special as we do not get link status from CORE_LNKSTS, -* which means that we need to force the link at the port override -* level to get the data to flow. We do use what the interrupt handler -* did determine before. -* -* For the other ports, we just force the link status, since this is -* a fixed PHY device. -*/ -if (port == priv->moca_port) { - status->link = priv->port_sts[port].link; -/* For MoCA interfaces, also force a link down notification -* since some version of the user-space daemon (mocad) use -* cmd->autoneg to force the link, which messes up the PHY -* state machine and make it go in PHY_FORCING state instead. -*/ -if (!status->link) -netif_carrier_off (ds->ports[port].slave); - status->duplex =1 ; - }else { - status->link =1 ; - status->duplex = !!(duplex & (1 << port)); - } - - reg =core_readl (priv, offset); - reg |=SW_OVERRIDE ; -if (status->link) - reg |=LINK_STS ; -else - reg &= ~LINK_STS ; -core_writel (priv, reg, offset); - -if ((pause & (1 << port)) && - (pause & (1 << (port +PAUSESTS_TX_PAUSE_SHIFT )))) { - status->asym_pause =1 ; - status->pause =1 ; - } - -if (pause & (1 << port)) - status->pause =1 ; -} -static void bcm_sf2_sw_validate (struct dsa_switch *ds,int port,unsigned long *supported,struct phylink_link_state *state)
@@ -1054,8 +907,6 @@ static const struct dsa_switch_ops bcm_sf2_ops = { .get_sset_count = b53_get_sset_count, .get_ethtool_phy_stats = b53_get_ethtool_phy_stats, .get_phy_flags = bcm_sf2_sw_get_phy_flags, - .adjust_link = bcm_sf2_sw_adjust_link, - .fixed_link_update = bcm_sf2_sw_fixed_link_update, .phylink_validate = bcm_sf2_sw_validate, .phylink_mac_config = bcm_sf2_sw_mac_config, .phylink_mac_link_down = bcm_sf2_sw_mac_link_down,
Signature · 1 line
2.14.1
Russell King - ARM Linux
maintainerRe: [PATCH net-next v2 3/9] net: phy: phylink: Poll link GPIOs
In reply to Florian FainelliQuoted 6 lines · Florian Fainelli
From: Russell King <[email protected]>
When using a fixed link with a link GPIO, we need to poll that GPIO to determine link state changes. This is consistent with what
fixed_phy.cdoes.Signed-off-by Florian Fainelli <[email protected]>
I'd like this to use the GPIO interrupt where available, only falling back to the timer approach when there's no interrupt. Unfortunately, I don't have much time to devote to this at the moment, having recently been away on vacation, and now having to work on ARM specific issues for probably all of the remainder of this kernel cycle.
That means I won't have time to test your series on any of the boards I have available to me.
Quoted 69 lines
--- drivers/net/phy/phylink.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)drivers/net/phy/phylink.c +16
-0@@ -19,6 +19,7 @@#include <linux/phylink.h> #include <linux/rtnetlink.h> #include <linux/spinlock.h> +#include <linux/timer.h> #include <linux/workqueue.h> #include "sfp.h" @@ -54,6 +55,7 @@ struct phylink {/* The link configuration settings */ struct phylink_link_state link_config;struct gpio_desc *link_gpio; +struct timer_list link_poll;void (*get_fixed_state)(struct net_device *dev,struct phylink_link_state *s);@@ -500,6 +502,15 @@ static void phylink_run_resolve(struct phylink *pl)queue_work (system_power_efficient_wq, &pl->resolve); } +static void phylink_fixed_poll (struct timer_list *t) +{ + struct phylink *pl = container_of(t, struct phylink, link_poll); + +mod_timer (t, jiffies +HZ ); + +phylink_run_resolve (pl); +} +static const struct sfp_upstream_ops sfp_phylink_ops; static int phylink_register_sfp(struct phylink *pl,@@ -572,6 +583,7 @@ struct phylink *phylink_create(struct net_device *ndev, pl->link_config.an_enabled = true; pl->ops = ops;__set_bit (PHYLINK_DISABLE_STOPPED , &pl->phylink_disable_state); +timer_setup (&pl->link_poll, phylink_fixed_poll,0 );bitmap_fill (pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS);linkmode_copy (pl->link_config.advertising, pl->supported);@@ -905,6 +917,8 @@ void phylink_start(struct phylink *pl)clear_bit (PHYLINK_DISABLE_STOPPED , &pl->phylink_disable_state);phylink_run_resolve (pl); +if (pl->link_an_mode ==MLO_AN_FIXED && !IS_ERR (pl->link_gpio)) +mod_timer (&pl->link_poll, jiffies +HZ );if (pl->sfp_bus)sfp_upstream_start (pl->sfp_bus);if (pl->phydev)@@ -929,6 +943,8 @@ void phylink_stop(struct phylink *pl)phy_stop (pl->phydev);if (pl->sfp_bus)sfp_upstream_stop (pl->sfp_bus); +if (pl->link_an_mode ==MLO_AN_FIXED && !IS_ERR (pl->link_gpio)) +del_timer_sync (&pl->link_poll);set_bit (PHYLINK_DISABLE_STOPPED , &pl->phylink_disable_state);queue_work (system_power_efficient_wq, &pl->resolve);Signature · 1 line
2.14.1
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
Re: [PATCH net-next v2 3/9] net: phy: phylink: Poll link GPIOs
Quoted 8 lines · Russell King - ARM Linux
Quoted 6 lines · Florian Fainelli
From: Russell King <[email protected]>
When using a fixed link with a link GPIO, we need to poll that GPIO to determine link state changes. This is consistent with what
fixed_phy.cdoes.Signed-off-by Florian Fainelli <[email protected]>
Quoted 8 lines
I'd like this to use the GPIO interrupt where available, only falling back to the timer approach when there's no interrupt. Unfortunately, I don't have much time to devote to this at the moment, having recently been away on vacation, and now having to work on ARM specific issues for probably all of the remainder of this kernel cycle.
That means I won't have time to test your series on any of the boards I have available to me.
No worries, thanks for looking at this. Andrew and I both tested this on the devel B and C boards where this is primarily useful. Can I still get your SoB for the portions you authored?
I will follow up with a change that uses GPIO interrupts when they are available.
Quoted 71 lines
Quoted 70 lines
--- drivers/net/phy/phylink.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)drivers/net/phy/phylink.c +16
-0@@ -19,6 +19,7 @@#include <linux/phylink.h> #include <linux/rtnetlink.h> #include <linux/spinlock.h> +#include <linux/timer.h> #include <linux/workqueue.h> #include "sfp.h" @@ -54,6 +55,7 @@ struct phylink {/* The link configuration settings */ struct phylink_link_state link_config;struct gpio_desc *link_gpio; +struct timer_list link_poll;void (*get_fixed_state)(struct net_device *dev,struct phylink_link_state *s);@@ -500,6 +502,15 @@ static void phylink_run_resolve(struct phylink *pl)queue_work (system_power_efficient_wq, &pl->resolve); } +static void phylink_fixed_poll (struct timer_list *t) +{ + struct phylink *pl = container_of(t, struct phylink, link_poll); + +mod_timer (t, jiffies +HZ ); + +phylink_run_resolve (pl); +} +static const struct sfp_upstream_ops sfp_phylink_ops; static int phylink_register_sfp(struct phylink *pl,@@ -572,6 +583,7 @@ struct phylink *phylink_create(struct net_device *ndev, pl->link_config.an_enabled = true; pl->ops = ops;__set_bit (PHYLINK_DISABLE_STOPPED , &pl->phylink_disable_state); +timer_setup (&pl->link_poll, phylink_fixed_poll,0 );bitmap_fill (pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS);linkmode_copy (pl->link_config.advertising, pl->supported);@@ -905,6 +917,8 @@ void phylink_start(struct phylink *pl)clear_bit (PHYLINK_DISABLE_STOPPED , &pl->phylink_disable_state);phylink_run_resolve (pl); +if (pl->link_an_mode ==MLO_AN_FIXED && !IS_ERR (pl->link_gpio)) +mod_timer (&pl->link_poll, jiffies +HZ );if (pl->sfp_bus)sfp_upstream_start (pl->sfp_bus);if (pl->phydev)@@ -929,6 +943,8 @@ void phylink_stop(struct phylink *pl)phy_stop (pl->phydev);if (pl->sfp_bus)sfp_upstream_stop (pl->sfp_bus); +if (pl->link_an_mode ==MLO_AN_FIXED && !IS_ERR (pl->link_gpio)) +del_timer_sync (&pl->link_poll);set_bit (PHYLINK_DISABLE_STOPPED , &pl->phylink_disable_state);queue_work (system_power_efficient_wq, &pl->resolve);Signature · 1 line
2.14.1
Signature · 1 line
Florian
David Miller
maintainerFrom: Florian Fainelli <[email protected]>
Date: Thu, 10 May 2018 13:17:28 -0700
Quoted 2 lines
This patch series adds PHYLINK support to DSA which is necessary to support more complex PHY and pluggable modules setups.
Series applied, thanks.