net: dsa: Support internal phy on 'cpu' port
authorSebastian Reichel <sebastian.reichel@collabora.co.uk>
Tue, 23 Jan 2018 15:03:46 +0000 (16:03 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 24 Jan 2018 00:22:38 +0000 (19:22 -0500)
This adds support for enabling the internal PHY for a 'cpu' port.
It has been tested on GE B850v3,  B650v3 and B450v3, which have a
built-in MV88E6240 switch hardwired to a PCIe based network card.
On these machines the internal PHY of the i210 network card and
the Marvell switch are connected to each other and must be enabled
for properly using the switch. While the i210 PHY will be enabled
when the network interface is enabled, the switch's port is not
exposed as network interface. Additionally the mv88e6xxx driver
resets the chip during probe, so the PHY is disabled without this
patch.

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/dsa2.c
net/dsa/dsa_priv.h
net/dsa/legacy.c
net/dsa/port.c

index 21f9bed..adf50fb 100644 (file)
@@ -271,13 +271,12 @@ static int dsa_port_setup(struct dsa_port *dp)
                break;
        case DSA_PORT_TYPE_CPU:
        case DSA_PORT_TYPE_DSA:
-               err = dsa_port_fixed_link_register_of(dp);
+               err = dsa_port_link_register_of(dp);
                if (err) {
-                       dev_err(ds->dev, "failed to register fixed link for port %d.%d\n",
+                       dev_err(ds->dev, "failed to setup link for port %d.%d\n",
                                ds->index, dp->index);
                        return err;
                }
-
                break;
        case DSA_PORT_TYPE_USER:
                err = dsa_slave_create(dp);
@@ -301,7 +300,7 @@ static void dsa_port_teardown(struct dsa_port *dp)
                break;
        case DSA_PORT_TYPE_CPU:
        case DSA_PORT_TYPE_DSA:
-               dsa_port_fixed_link_unregister_of(dp);
+               dsa_port_link_unregister_of(dp);
                break;
        case DSA_PORT_TYPE_USER:
                if (dp->slave) {
index cefb0c3..70de789 100644 (file)
@@ -166,8 +166,8 @@ int dsa_port_vlan_add(struct dsa_port *dp,
                      struct switchdev_trans *trans);
 int dsa_port_vlan_del(struct dsa_port *dp,
                      const struct switchdev_obj_port_vlan *vlan);
-int dsa_port_fixed_link_register_of(struct dsa_port *dp);
-void dsa_port_fixed_link_unregister_of(struct dsa_port *dp);
+int dsa_port_link_register_of(struct dsa_port *dp);
+void dsa_port_link_unregister_of(struct dsa_port *dp);
 
 /* slave.c */
 extern const struct dsa_device_ops notag_netdev_ops;
index aa56d3f..cb54b81 100644 (file)
@@ -86,7 +86,7 @@ static int dsa_cpu_dsa_setups(struct dsa_switch *ds)
                if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
                        continue;
 
-               ret = dsa_port_fixed_link_register_of(&ds->ports[port]);
+               ret = dsa_port_link_register_of(&ds->ports[port]);
                if (ret)
                        return ret;
        }
@@ -275,7 +275,7 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
        for (port = 0; port < ds->num_ports; port++) {
                if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
                        continue;
-               dsa_port_fixed_link_unregister_of(&ds->ports[port]);
+               dsa_port_link_unregister_of(&ds->ports[port]);
        }
 
        if (ds->slave_mii_bus && ds->ops->phy_read)
index bb4be26..7acc116 100644 (file)
@@ -273,7 +273,56 @@ int dsa_port_vlan_del(struct dsa_port *dp,
        return 0;
 }
 
-int dsa_port_fixed_link_register_of(struct dsa_port *dp)
+static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable)
+{
+       struct device_node *port_dn = dp->dn;
+       struct device_node *phy_dn;
+       struct dsa_switch *ds = dp->ds;
+       struct phy_device *phydev;
+       int port = dp->index;
+       int err = 0;
+
+       phy_dn = of_parse_phandle(port_dn, "phy-handle", 0);
+       if (!phy_dn)
+               return 0;
+
+       phydev = of_phy_find_device(phy_dn);
+       if (!phydev) {
+               err = -EPROBE_DEFER;
+               goto err_put_of;
+       }
+
+       if (enable) {
+               err = genphy_config_init(phydev);
+               if (err < 0)
+                       goto err_put_dev;
+
+               err = genphy_resume(phydev);
+               if (err < 0)
+                       goto err_put_dev;
+
+               err = genphy_read_status(phydev);
+               if (err < 0)
+                       goto err_put_dev;
+       } else {
+               err = genphy_suspend(phydev);
+               if (err < 0)
+                       goto err_put_dev;
+       }
+
+       if (ds->ops->adjust_link)
+               ds->ops->adjust_link(ds, port, phydev);
+
+       dev_dbg(ds->dev, "enabled port's phy: %s", phydev_name(phydev));
+
+err_put_dev:
+       put_device(&phydev->mdio.dev);
+err_put_of:
+       of_node_put(phy_dn);
+       return err;
+}
+
+static int dsa_port_fixed_link_register_of(struct dsa_port *dp)
 {
        struct device_node *dn = dp->dn;
        struct dsa_switch *ds = dp->ds;
@@ -282,38 +331,44 @@ int dsa_port_fixed_link_register_of(struct dsa_port *dp)
        int mode;
        int err;
 
-       if (of_phy_is_fixed_link(dn)) {
-               err = of_phy_register_fixed_link(dn);
-               if (err) {
-                       dev_err(ds->dev,
-                               "failed to register the fixed PHY of port %d\n",
-                               port);
-                       return err;
-               }
+       err = of_phy_register_fixed_link(dn);
+       if (err) {
+               dev_err(ds->dev,
+                       "failed to register the fixed PHY of port %d\n",
+                       port);
+               return err;
+       }
 
-               phydev = of_phy_find_device(dn);
+       phydev = of_phy_find_device(dn);
 
-               mode = of_get_phy_mode(dn);
-               if (mode < 0)
-                       mode = PHY_INTERFACE_MODE_NA;
-               phydev->interface = mode;
+       mode = of_get_phy_mode(dn);
+       if (mode < 0)
+               mode = PHY_INTERFACE_MODE_NA;
+       phydev->interface = mode;
 
-               genphy_config_init(phydev);
-               genphy_read_status(phydev);
+       genphy_config_init(phydev);
+       genphy_read_status(phydev);
 
-               if (ds->ops->adjust_link)
-                       ds->ops->adjust_link(ds, port, phydev);
+       if (ds->ops->adjust_link)
+               ds->ops->adjust_link(ds, port, phydev);
 
-               put_device(&phydev->mdio.dev);
-       }
+       put_device(&phydev->mdio.dev);
 
        return 0;
 }
 
-void dsa_port_fixed_link_unregister_of(struct dsa_port *dp)
+int dsa_port_link_register_of(struct dsa_port *dp)
 {
-       struct device_node *dn = dp->dn;
+       if (of_phy_is_fixed_link(dp->dn))
+               return dsa_port_fixed_link_register_of(dp);
+       else
+               return dsa_port_setup_phy_of(dp, true);
+}
 
-       if (of_phy_is_fixed_link(dn))
-               of_phy_deregister_fixed_link(dn);
+void dsa_port_link_unregister_of(struct dsa_port *dp)
+{
+       if (of_phy_is_fixed_link(dp->dn))
+               of_phy_deregister_fixed_link(dp->dn);
+       else
+               dsa_port_setup_phy_of(dp, false);
 }