Skip to content

Commit

Permalink
net: dsa: Support internal phy on 'cpu' port
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Florian Fainelli <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
sre authored and davem330 committed Jan 24, 2018
1 parent 5ca1144 commit 3361536
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 32 deletions.
7 changes: 3 additions & 4 deletions net/dsa/dsa2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions net/dsa/dsa_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions net/dsa/legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down
103 changes: 79 additions & 24 deletions net/dsa/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

0 comments on commit 3361536

Please sign in to comment.