* [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support
@ 2017-12-15 0:28 Florian Fainelli
2017-12-15 0:28 ` [RFT/RFC net-next 1/2] " Florian Fainelli
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Florian Fainelli @ 2017-12-15 0:28 UTC (permalink / raw)
To: netdev
Cc: rmk+kernel, sean.wang, john, kernel, privat, Woojung.Huh,
vivien.didelot, andrew, Florian Fainelli
Hi all,
This patch series replaces the existing PHYLIB integration with PHYLINK which
is a superior solution since we need to support a collection of fixed links,
integrated PHYs, SFP, non-pluggable SFPs etc.
I am expecting quite a lot of breakage, for a number of reasons:
- PHYLINK does not create a PHY device for fixed links (MLO_AN_FIXED), which
means that user-facing port (not DSA, not CPU) need to be explicitly handled
with phylink_mac_ops now
- only been able to test this on a limited number of platforms, and not the
ZII devel B/C boards yet
Please test and report!
Florian Fainelli (2):
net: dsa: Plug in PHYLINK support
net: dsa: bcm_sf2: Kick PHYLINK upon link interrupts
drivers/net/dsa/bcm_sf2.c | 29 +++--
include/net/dsa.h | 23 +++-
net/dsa/Kconfig | 1 +
net/dsa/dsa_priv.h | 9 --
net/dsa/slave.c | 294 +++++++++++++++++++++++++++-------------------
5 files changed, 210 insertions(+), 146 deletions(-)
--
2.14.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFT/RFC net-next 1/2] net: dsa: Plug in PHYLINK support
2017-12-15 0:28 [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support Florian Fainelli
@ 2017-12-15 0:28 ` Florian Fainelli
2017-12-15 0:28 ` [RFT/RFC net-next 2/2] net: dsa: bcm_sf2: Kick PHYLINK upon link interrupts Florian Fainelli
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2017-12-15 0:28 UTC (permalink / raw)
To: netdev
Cc: rmk+kernel, sean.wang, john, kernel, privat, Woojung.Huh,
vivien.didelot, andrew, Florian Fainelli
Add support for PHYLINK within the DSA subsystem in order to support more
complex devices such as pluggable and non-pluggable SFP modules, 10G PHYs, and
traditional PHYs. Using PHYLINK allows us to drop some amount of complexity we
had while dealing with 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() for most of these operations.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/net/dsa/bcm_sf2.c | 11 +-
include/net/dsa.h | 23 +++-
net/dsa/Kconfig | 1 +
net/dsa/dsa_priv.h | 9 --
net/dsa/slave.c | 294 +++++++++++++++++++++++++++-------------------
5 files changed, 198 insertions(+), 140 deletions(-)
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index 8ea0cd494ea0..a22a32a724b3 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -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>
@@ -563,7 +564,7 @@ static void bcm_sf2_sw_adjust_link(struct dsa_switch *ds, int port,
}
static void bcm_sf2_sw_fixed_link_update(struct dsa_switch *ds, int port,
- struct fixed_phy_status *status)
+ struct phylink_link_state *status)
{
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
u32 duplex, pause, offset;
@@ -611,13 +612,11 @@ static void bcm_sf2_sw_fixed_link_update(struct dsa_switch *ds, int port,
core_writel(priv, reg, offset);
if ((pause & (1 << port)) &&
- (pause & (1 << (port + PAUSESTS_TX_PAUSE_SHIFT)))) {
- status->asym_pause = 1;
- status->pause = 1;
- }
+ (pause & (1 << (port + PAUSESTS_TX_PAUSE_SHIFT))))
+ status->pause |= MLO_PAUSE_TXRX_MASK;
if (pause & (1 << port))
- status->pause = 1;
+ status->pause |= MLO_PAUSE_RX;
}
static void bcm_sf2_enable_acb(struct dsa_switch *ds)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index 6cb602dd970c..29d4a1b7a825 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -25,6 +25,7 @@
struct tc_action;
struct phy_device;
struct fixed_phy_status;
+struct phylink_link_state;
enum dsa_tag_protocol {
DSA_TAG_PROTO_NONE = 0,
@@ -197,6 +198,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
*/
@@ -348,8 +350,25 @@ struct dsa_switch_ops {
*/
void (*adjust_link)(struct dsa_switch *ds, int port,
struct phy_device *phydev);
+ /*
+ * 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);
+ void (*phylink_mac_link_up)(struct dsa_switch *ds, int port,
+ unsigned int mode,
+ struct phy_device *phydev);
void (*fixed_link_update)(struct dsa_switch *ds, int port,
- struct fixed_phy_status *st);
+ struct phylink_link_state *st);
/*
* ethtool hardware statistics.
@@ -568,4 +587,6 @@ static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev,
#define BRCM_TAG_GET_PORT(v) ((v) >> 8)
#define BRCM_TAG_GET_QUEUE(v) ((v) & 0xff)
+void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up);
+
#endif
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index bbf2c82cf7b2..8a6a8d1cc991 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -10,6 +10,7 @@ config NET_DSA
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.
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index b03665e8fb4e..690ed9877198 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -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
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 5d6475a6cc5d..6cf51f0a29aa 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -13,6 +13,7 @@
#include <linux/netdevice.h>
#include <linux/phy.h>
#include <linux/phy_fixed.h>
+#include <linux/phylink.h>
#include <linux/of_net.h>
#include <linux/of_mdio.h>
#include <linux/mdio.h>
@@ -97,8 +98,7 @@ static int dsa_slave_open(struct net_device *dev)
if (err)
goto clear_promisc;
- if (dev->phydev)
- phy_start(dev->phydev);
+ phylink_start(dp->pl);
return 0;
@@ -120,8 +120,7 @@ static int dsa_slave_close(struct net_device *dev)
struct net_device *master = dsa_slave_to_master(dev);
struct dsa_port *dp = dsa_slave_to_port(dev);
- if (dev->phydev)
- phy_stop(dev->phydev);
+ phylink_stop(dp->pl);
dsa_port_disable(dp, dev->phydev);
@@ -256,10 +255,9 @@ dsa_slave_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
- if (!dev->phydev)
- return -ENODEV;
+ struct dsa_port *dp = dsa_slave_to_port(dev);
- return phy_mii_ioctl(dev->phydev, ifr, cmd);
+ return phylink_mii_ioctl(dp->pl, ifr, cmd);
}
static int dsa_slave_port_attr_set(struct net_device *dev,
@@ -453,14 +451,11 @@ 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)
+static int dsa_slave_nway_reset(struct net_device *dev)
{
- if (!dev->phydev)
- return -ENODEV;
-
- genphy_update_link(dev->phydev);
+ struct dsa_port *dp = dsa_slave_to_port(dev);
- return dev->phydev->link;
+ return phylink_ethtool_nway_reset(dp->pl);
}
static int dsa_slave_get_eeprom_len(struct net_device *dev)
@@ -501,6 +496,22 @@ static int dsa_slave_set_eeprom(struct net_device *dev,
return -EOPNOTSUPP;
}
+static int dsa_slave_get_module_info(struct net_device *dev,
+ struct ethtool_modinfo *modinfo)
+{
+ struct dsa_port *dp = dsa_slave_to_port(dev);
+
+ return phylink_ethtool_get_module_info(dp->pl, modinfo);
+}
+
+static int dsa_slave_get_module_eeprom(struct net_device *dev,
+ struct ethtool_eeprom *ee, u8 *buf)
+{
+ struct dsa_port *dp = dsa_slave_to_port(dev);
+
+ return phylink_ethtool_get_module_eeprom(dp->pl, ee, buf);
+}
+
static void dsa_slave_get_strings(struct net_device *dev,
uint32_t stringset, uint8_t *data)
{
@@ -573,6 +584,8 @@ static void dsa_slave_get_wol(struct net_device *dev, struct ethtool_wolinfo *w)
struct dsa_port *dp = dsa_slave_to_port(dev);
struct dsa_switch *ds = dp->ds;
+ phylink_ethtool_get_wol(dp->pl, w);
+
if (ds->ops->get_wol)
ds->ops->get_wol(ds, dp->index, w);
}
@@ -583,6 +596,8 @@ static int dsa_slave_set_wol(struct net_device *dev, struct ethtool_wolinfo *w)
struct dsa_switch *ds = dp->ds;
int ret = -EOPNOTSUPP;
+ phylink_ethtool_set_wol(dp->pl, w);
+
if (ds->ops->set_wol)
ret = ds->ops->set_wol(ds, dp->index, w);
@@ -606,13 +621,7 @@ static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e)
if (ret)
return ret;
- if (e->eee_enabled) {
- ret = phy_init_eee(dev->phydev, 0);
- if (ret)
- return ret;
- }
-
- return phy_ethtool_set_eee(dev->phydev, e);
+ return phylink_ethtool_set_eee(dp->pl, e);
}
static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e)
@@ -632,7 +641,23 @@ static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e)
if (ret)
return ret;
- return phy_ethtool_get_eee(dev->phydev, e);
+ return phylink_ethtool_get_eee(dp->pl, e);
+}
+
+static int dsa_slave_get_link_ksettings(struct net_device *dev,
+ struct ethtool_link_ksettings *cmd)
+{
+ struct dsa_port *dp = dsa_slave_to_port(dev);
+
+ return phylink_ethtool_ksettings_get(dp->pl, cmd);
+}
+
+static int dsa_slave_set_link_ksettings(struct net_device *dev,
+ const struct ethtool_link_ksettings *cmd)
+{
+ struct dsa_port *dp = dsa_slave_to_port(dev);
+
+ return phylink_ethtool_ksettings_set(dp->pl, cmd);
}
#ifdef CONFIG_NET_POLL_CONTROLLER
@@ -923,11 +948,13 @@ static const struct ethtool_ops dsa_slave_ethtool_ops = {
.get_drvinfo = dsa_slave_get_drvinfo,
.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,
+ .nway_reset = dsa_slave_nway_reset,
+ .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,
+ .get_module_info = dsa_slave_get_module_info,
+ .get_module_eeprom = dsa_slave_get_module_eeprom,
.get_strings = dsa_slave_get_strings,
.get_ethtool_stats = dsa_slave_get_ethtool_stats,
.get_sset_count = dsa_slave_get_sset_count,
@@ -935,8 +962,8 @@ static const struct ethtool_ops dsa_slave_ethtool_ops = {
.get_wol = dsa_slave_get_wol,
.set_eee = dsa_slave_set_eee,
.get_eee = dsa_slave_get_eee,
- .get_link_ksettings = phy_ethtool_get_link_ksettings,
- .set_link_ksettings = phy_ethtool_set_link_ksettings,
+ .get_link_ksettings = dsa_slave_get_link_ksettings,
+ .set_link_ksettings = dsa_slave_set_link_ksettings,
.get_rxnfc = dsa_slave_get_rxnfc,
.set_rxnfc = dsa_slave_set_rxnfc,
};
@@ -994,56 +1021,118 @@ static struct device_type dsa_type = {
.name = "dsa",
};
-static void dsa_slave_adjust_link(struct net_device *dev)
+static void dsa_slave_phylink_validate(struct net_device *dev,
+ unsigned long *supported,
+ struct phylink_link_state *state)
{
struct dsa_port *dp = dsa_slave_to_port(dev);
- struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = dp->ds;
- unsigned int status_changed = 0;
- if (p->old_link != dev->phydev->link) {
- status_changed = 1;
- p->old_link = dev->phydev->link;
- }
+ if (!ds->ops->phylink_validate)
+ return;
- if (p->old_duplex != dev->phydev->duplex) {
- status_changed = 1;
- p->old_duplex = dev->phydev->duplex;
- }
+ ds->ops->phylink_validate(ds, dp->index, supported, state);
+}
- if (p->old_pause != dev->phydev->pause) {
- status_changed = 1;
- p->old_pause = dev->phydev->pause;
- }
+static int dsa_slave_phylink_mac_link_state(struct net_device *dev,
+ struct phylink_link_state *state)
+{
+ struct dsa_port *dp = dsa_slave_to_port(dev);
+ struct dsa_switch *ds = dp->ds;
+
+ /* Only called for SGMII and 802.3z */
+ if (!ds->ops->phylink_mac_link_state)
+ return -EOPNOTSUPP;
+
+ return ds->ops->phylink_mac_link_state(ds, dp->index, state);
+}
+
+static void dsa_slave_phylink_mac_config(struct net_device *dev,
+ unsigned int mode,
+ const struct phylink_link_state *state)
+{
+ struct dsa_port *dp = dsa_slave_to_port(dev);
+ struct dsa_switch *ds = dp->ds;
+
+ if (!ds->ops->phylink_mac_config)
+ return;
+
+ ds->ops->phylink_mac_config(ds, dp->index, mode, state);
+}
+
+static void dsa_slave_phylink_mac_an_restart(struct net_device *dev)
+{
+ struct dsa_port *dp = dsa_slave_to_port(dev);
+ struct dsa_switch *ds = dp->ds;
- if (ds->ops->adjust_link && status_changed)
- ds->ops->adjust_link(ds, dp->index, dev->phydev);
+ if (!ds->ops->phylink_mac_an_restart)
+ return;
- if (status_changed)
- phy_print_status(dev->phydev);
+ ds->ops->phylink_mac_an_restart(ds, dp->index);
}
-static int dsa_slave_fixed_link_update(struct net_device *dev,
- struct fixed_phy_status *status)
+static void dsa_slave_phylink_mac_link_down(struct net_device *dev,
+ unsigned int mode)
{
- struct dsa_switch *ds;
- struct dsa_port *dp;
+ struct dsa_port *dp = dsa_slave_to_port(dev);
+ struct dsa_switch *ds = dp->ds;
- if (dev) {
- dp = dsa_slave_to_port(dev);
- ds = dp->ds;
- if (ds->ops->fixed_link_update)
- ds->ops->fixed_link_update(ds, dp->index, status);
+ if (!ds->ops->phylink_mac_link_down) {
+ if (ds->ops->adjust_link && dev->phydev)
+ ds->ops->adjust_link(ds, dp->index, dev->phydev);
+ return;
}
- return 0;
+ ds->ops->phylink_mac_link_down(ds, dp->index, mode);
+}
+
+static void dsa_slave_phylink_mac_link_up(struct net_device *dev,
+ unsigned int mode,
+ struct phy_device *phydev)
+{
+ struct dsa_port *dp = dsa_slave_to_port(dev);
+ struct dsa_switch *ds = dp->ds;
+
+ if (!ds->ops->phylink_mac_link_up) {
+ if (ds->ops->adjust_link && dev->phydev)
+ ds->ops->adjust_link(ds, dp->index, dev->phydev);
+ return;
+ }
+
+ ds->ops->phylink_mac_link_up(ds, dp->index, mode, phydev);
+}
+
+static const struct phylink_mac_ops dsa_slave_phylink_mac_ops = {
+ .validate = dsa_slave_phylink_validate,
+ .mac_link_state = dsa_slave_phylink_mac_link_state,
+ .mac_config = dsa_slave_phylink_mac_config,
+ .mac_an_restart = dsa_slave_phylink_mac_an_restart,
+ .mac_link_down = dsa_slave_phylink_mac_link_down,
+ .mac_link_up = dsa_slave_phylink_mac_link_up,
+};
+
+void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up)
+{
+ const struct dsa_port *dp = dsa_to_port(ds, port);
+
+ phylink_mac_change(dp->pl, up);
+}
+EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_change);
+
+static void dsa_slave_phylink_fixed_state(struct net_device *dev,
+ struct phylink_link_state *state)
+{
+ struct dsa_port *dp = dsa_slave_to_port(dev);
+ struct dsa_switch *ds = dp->ds;
+
+ if (ds->ops->fixed_link_update)
+ ds->ops->fixed_link_update(ds, dp->index, state);
}
/* slave device setup *******************************************************/
static int dsa_slave_phy_connect(struct net_device *slave_dev, int addr)
{
struct dsa_port *dp = dsa_slave_to_port(slave_dev);
- struct dsa_slave_priv *p = netdev_priv(slave_dev);
struct dsa_switch *ds = dp->ds;
slave_dev->phydev = mdiobus_get_phy(ds->slave_mii_bus, addr);
@@ -1052,75 +1141,49 @@ static int dsa_slave_phy_connect(struct net_device *slave_dev, int addr)
return -ENODEV;
}
- /* Use already configured phy mode */
- if (p->phy_interface == PHY_INTERFACE_MODE_NA)
- p->phy_interface = slave_dev->phydev->interface;
-
- return phy_connect_direct(slave_dev, slave_dev->phydev,
- dsa_slave_adjust_link, p->phy_interface);
+ return phylink_connect_phy(dp->pl, slave_dev->phydev);
}
static int dsa_slave_phy_setup(struct net_device *slave_dev)
{
struct dsa_port *dp = dsa_slave_to_port(slave_dev);
- struct dsa_slave_priv *p = netdev_priv(slave_dev);
struct device_node *port_dn = dp->dn;
struct dsa_switch *ds = dp->ds;
- struct device_node *phy_dn;
- bool phy_is_fixed = false;
u32 phy_flags = 0;
int mode, ret;
mode = of_get_phy_mode(port_dn);
if (mode < 0)
mode = PHY_INTERFACE_MODE_NA;
- p->phy_interface = mode;
- phy_dn = of_parse_phandle(port_dn, "phy-handle", 0);
- if (!phy_dn && of_phy_is_fixed_link(port_dn)) {
- /* In the case of a fixed PHY, the DT node associated
- * to the fixed PHY is the Port DT node
- */
- ret = of_phy_register_fixed_link(port_dn);
- if (ret) {
- netdev_err(slave_dev, "failed to register fixed PHY: %d\n", ret);
- return ret;
- }
- phy_is_fixed = true;
- phy_dn = of_node_get(port_dn);
+ dp->pl = phylink_create(slave_dev, of_fwnode_handle(port_dn), mode,
+ &dsa_slave_phylink_mac_ops);
+ if (IS_ERR(dp->pl)) {
+ netdev_err(slave_dev,
+ "error creating PHYLINK: %ld\n", PTR_ERR(dp->pl));
+ return PTR_ERR(dp->pl);
}
+ phylink_fixed_state_cb(dp->pl, dsa_slave_phylink_fixed_state);
+
if (ds->ops->get_phy_flags)
phy_flags = ds->ops->get_phy_flags(ds, dp->index);
- if (phy_dn) {
- slave_dev->phydev = of_phy_connect(slave_dev, phy_dn,
- dsa_slave_adjust_link,
- phy_flags,
- p->phy_interface);
- of_node_put(phy_dn);
- }
-
- if (slave_dev->phydev && phy_is_fixed)
- fixed_phy_set_link_update(slave_dev->phydev,
- dsa_slave_fixed_link_update);
-
- /* We could not connect to a designated PHY, so use the switch internal
- * MDIO bus instead
- */
- if (!slave_dev->phydev) {
+ ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags);
+ if (ret == -ENODEV) {
+ /* We could not connect to a designated PHY or SFP, so use the
+ * switch internal MDIO bus instead
+ */
ret = dsa_slave_phy_connect(slave_dev, dp->index);
if (ret) {
- netdev_err(slave_dev, "failed to connect to port %d: %d\n",
+ netdev_err(slave_dev,
+ "failed to connect to port %d: %d\n",
dp->index, ret);
- if (phy_is_fixed)
- of_phy_deregister_fixed_link(port_dn);
+ phylink_destroy(dp->pl);
return ret;
}
}
- phy_attached_info(slave_dev->phydev);
-
return 0;
}
@@ -1135,29 +1198,22 @@ static void dsa_slave_set_lockdep_class_one(struct net_device *dev,
int dsa_slave_suspend(struct net_device *slave_dev)
{
- struct dsa_slave_priv *p = netdev_priv(slave_dev);
+ struct dsa_port *dp = dsa_slave_to_port(slave_dev);
netif_device_detach(slave_dev);
- if (slave_dev->phydev) {
- phy_stop(slave_dev->phydev);
- p->old_pause = -1;
- p->old_link = -1;
- p->old_duplex = -1;
- phy_suspend(slave_dev->phydev);
- }
+ phylink_stop(dp->pl);
return 0;
}
int dsa_slave_resume(struct net_device *slave_dev)
{
+ struct dsa_port *dp = dsa_slave_to_port(slave_dev);
+
netif_device_attach(slave_dev);
- if (slave_dev->phydev) {
- phy_resume(slave_dev->phydev);
- phy_start(slave_dev->phydev);
- }
+ phylink_start(dp->pl);
return 0;
}
@@ -1222,11 +1278,6 @@ int dsa_slave_create(struct dsa_port *port)
p->dp = port;
INIT_LIST_HEAD(&p->mall_tc_list);
p->xmit = cpu_dp->tag_ops->xmit;
-
- p->old_pause = -1;
- p->old_link = -1;
- p->old_duplex = -1;
-
port->slave = slave_dev;
netif_carrier_off(slave_dev);
@@ -1249,9 +1300,8 @@ int dsa_slave_create(struct dsa_port *port)
return 0;
out_phy:
- phy_disconnect(slave_dev->phydev);
- if (of_phy_is_fixed_link(port->dn))
- of_phy_deregister_fixed_link(port->dn);
+ phylink_disconnect_phy(p->dp->pl);
+ phylink_destroy(p->dp->pl);
out_free:
free_percpu(p->stats64);
free_netdev(slave_dev);
@@ -1263,15 +1313,11 @@ void dsa_slave_destroy(struct net_device *slave_dev)
{
struct dsa_port *dp = dsa_slave_to_port(slave_dev);
struct dsa_slave_priv *p = netdev_priv(slave_dev);
- struct device_node *port_dn = dp->dn;
netif_carrier_off(slave_dev);
- if (slave_dev->phydev) {
- phy_disconnect(slave_dev->phydev);
+ phylink_disconnect_phy(dp->pl);
+ phylink_destroy(dp->pl);
- if (of_phy_is_fixed_link(port_dn))
- of_phy_deregister_fixed_link(port_dn);
- }
dsa_slave_notify(slave_dev, DSA_PORT_UNREGISTER);
unregister_netdev(slave_dev);
free_percpu(p->stats64);
--
2.14.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [RFT/RFC net-next 2/2] net: dsa: bcm_sf2: Kick PHYLINK upon link interrupts
2017-12-15 0:28 [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support Florian Fainelli
2017-12-15 0:28 ` [RFT/RFC net-next 1/2] " Florian Fainelli
@ 2017-12-15 0:28 ` Florian Fainelli
2017-12-15 12:08 ` [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support Russell King - ARM Linux
2017-12-15 15:51 ` Egil Hjelmeland
3 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2017-12-15 0:28 UTC (permalink / raw)
To: netdev
Cc: rmk+kernel, sean.wang, john, kernel, privat, Woojung.Huh,
vivien.didelot, andrew, Florian Fainelli
In order to signal MoCA port link interrupts the same way we used to do
(through polling a fixed PHY and having an fixed_link_update callback
run), we just need to call phylink_mac_change() when that happens, and
have our custom fixed_link_update callback run to obtain the link state.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/net/dsa/bcm_sf2.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index a22a32a724b3..36e1cda0e0b2 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -307,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;
@@ -318,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))
+ 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))
+ dsa_port_phylink_mac_change(ds, 7, true);
+ }
+ if (priv->irq1_stat & P_LINK_DOWN_IRQ(P7_IRQ_OFF)) {
priv->port_sts[7].link = 0;
+ dsa_port_phylink_mac_change(ds, 7, false);
+ }
return IRQ_HANDLED;
}
@@ -1060,14 +1066,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;
--
2.14.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support
2017-12-15 0:28 [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support Florian Fainelli
2017-12-15 0:28 ` [RFT/RFC net-next 1/2] " Florian Fainelli
2017-12-15 0:28 ` [RFT/RFC net-next 2/2] net: dsa: bcm_sf2: Kick PHYLINK upon link interrupts Florian Fainelli
@ 2017-12-15 12:08 ` Russell King - ARM Linux
2017-12-15 12:48 ` Andrew Lunn
2017-12-15 15:51 ` Egil Hjelmeland
3 siblings, 1 reply; 6+ messages in thread
From: Russell King - ARM Linux @ 2017-12-15 12:08 UTC (permalink / raw)
To: Florian Fainelli
Cc: netdev, sean.wang, john, kernel, privat, Woojung.Huh,
vivien.didelot, andrew
On Thu, Dec 14, 2017 at 04:28:48PM -0800, Florian Fainelli wrote:
> Hi all,
>
> This patch series replaces the existing PHYLIB integration with PHYLINK which
> is a superior solution since we need to support a collection of fixed links,
> integrated PHYs, SFP, non-pluggable SFPs etc.
>
> I am expecting quite a lot of breakage, for a number of reasons:
>
> - PHYLINK does not create a PHY device for fixed links (MLO_AN_FIXED), which
> means that user-facing port (not DSA, not CPU) need to be explicitly handled
> with phylink_mac_ops now
>
> - only been able to test this on a limited number of platforms, and not the
> ZII devel B/C boards yet
>
> Please test and report!
The good news is that it almost works on the ZII Rev C with the SFF
modules, but there's a few issues that need solving:
1. s/WARN_ON(!lockdep_rtnl_is_held())/ASSERT_RTNL()/ in phylink.c -
probably wouldn't have been noticed if it wasn't for the lockdep
splat with DSA's interrupt handling during boot that's been there
since -rc1. (Andrew mentioned that it's known, so I haven't
reported that.)
2. ports without a phy but with sfp cause the "no phy at" and
"failed to connect to port" message - I think we need a way for
DSA to know whether it should be attempting to attach a PHY.
3. We need mv88e6xxx to implement at least phylink_mac_link_state()
so that SFPs report sane ethtool information. It also needs to
implement phylink_mac_config() so that the link can be appropriately
configured to the module's capabilities, and phylink_validate() to
do the jiggery for choosing between 1000base-X vs 2500base-X mode
if the DSA switches can't automatically select the appropriate one.
With a few hacks for the above, I can get TX_DISABLE on the SFF2 module
to follow the interface up/down status, but as I say more work is needed
so that mv88e6xxx works with the phylink callbacks for the SFF modules
to be properly supported.
--
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support
2017-12-15 12:08 ` [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support Russell King - ARM Linux
@ 2017-12-15 12:48 ` Andrew Lunn
0 siblings, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2017-12-15 12:48 UTC (permalink / raw)
To: Russell King - ARM Linux
Cc: Florian Fainelli, netdev, sean.wang, john, kernel, privat,
Woojung.Huh, vivien.didelot
> 1. s/WARN_ON(!lockdep_rtnl_is_held())/ASSERT_RTNL()/ in phylink.c -
> probably wouldn't have been noticed if it wasn't for the lockdep
> splat with DSA's interrupt handling during boot that's been there
> since -rc1. (Andrew mentioned that it's known, so I haven't
> reported that.)
Hi Russell
https://lkml.org/lkml/2017/12/2/260
This should fix that splat. I hope it will get picked up at some
point. It is probably getting on time to repost it.
Andrew
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support
2017-12-15 0:28 [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support Florian Fainelli
` (2 preceding siblings ...)
2017-12-15 12:08 ` [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support Russell King - ARM Linux
@ 2017-12-15 15:51 ` Egil Hjelmeland
3 siblings, 0 replies; 6+ messages in thread
From: Egil Hjelmeland @ 2017-12-15 15:51 UTC (permalink / raw)
To: Florian Fainelli, netdev
Cc: rmk+kernel, sean.wang, john, kernel, Woojung.Huh, vivien.didelot,
andrew
Hi
Den 15. des. 2017 01:28, skrev Florian Fainelli:
> Hi all,
>
> This patch series replaces the existing PHYLIB integration with PHYLINK which
> is a superior solution since we need to support a collection of fixed links,
> integrated PHYs, SFP, non-pluggable SFPs etc.
>
> I am expecting quite a lot of breakage, for a number of reasons:
>
> - PHYLINK does not create a PHY device for fixed links (MLO_AN_FIXED), which
> means that user-facing port (not DSA, not CPU) need to be explicitly handled
> with phylink_mac_ops now
>
FWIW: We (zenitel) does not use fixed-link on user-port. I gave the
patches a spin on our board with lan9303. As expected: no breakage.
Egil
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-12-15 15:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-15 0:28 [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support Florian Fainelli
2017-12-15 0:28 ` [RFT/RFC net-next 1/2] " Florian Fainelli
2017-12-15 0:28 ` [RFT/RFC net-next 2/2] net: dsa: bcm_sf2: Kick PHYLINK upon link interrupts Florian Fainelli
2017-12-15 12:08 ` [RFT/RFC net-next 0/2] net: dsa: Plug in PHYLINK support Russell King - ARM Linux
2017-12-15 12:48 ` Andrew Lunn
2017-12-15 15:51 ` Egil Hjelmeland
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).