Commit 33615367 authored by Sebastian Reichel's avatar Sebastian Reichel Committed by David S. Miller

net: dsa: Support internal phy on 'cpu' port

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: default avatarSebastian Reichel <sebastian.reichel@collabora.co.uk>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5ca11440
......@@ -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) {
......
......@@ -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;
......
......@@ -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)
......
......@@ -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,7 +331,6 @@ 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,
......@@ -305,15 +353,22 @@ int dsa_port_fixed_link_register_of(struct dsa_port *dp)
ds->ops->adjust_link(ds, port, phydev);
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);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment