Skip to content

Commit

Permalink
net: dsa: fully divert PHY reads/writes if requested
Browse files Browse the repository at this point in the history
In case a PHY is found via Device Tree, and is also flagged by the
switch driver as needing indirect reads/writes using the switch driver
implemented MDIO bus, make sure that we bind this PHY to the slave MII
bus in order for this to happen.

Without this, we would succeed in having the PHY driver probe()'s
function to use slave MII bus read/write functions, because this is done
during dsa_slave_mii_init(), but past that point, the PHY driver would
not go through these diverted reads and writes.

Fixes: 0d8bcdd ("net: dsa: allow for more complex PHY setups")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Florian Fainelli authored and David S. Miller committed Mar 11, 2015
1 parent c305c16 commit cd28a1a
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions net/dsa/slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,12 @@ static int dsa_slave_fixed_link_update(struct net_device *dev,

/* slave device setup *******************************************************/
static int dsa_slave_phy_connect(struct dsa_slave_priv *p,
struct net_device *slave_dev)
struct net_device *slave_dev,
int addr)
{
struct dsa_switch *ds = p->parent;

p->phy = ds->slave_mii_bus->phy_map[p->port];
p->phy = ds->slave_mii_bus->phy_map[addr];
if (!p->phy)
return -ENODEV;

Expand Down Expand Up @@ -667,10 +668,24 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
if (ds->drv->get_phy_flags)
phy_flags = ds->drv->get_phy_flags(ds, p->port);

if (phy_dn)
p->phy = of_phy_connect(slave_dev, phy_dn,
dsa_slave_adjust_link, phy_flags,
p->phy_interface);
if (phy_dn) {
ret = of_mdio_parse_addr(&slave_dev->dev, phy_dn);
/* If this PHY address is part of phys_mii_mask, which means
* that we need to divert reads and writes to/from it, then we
* want to bind this device using the slave MII bus created by
* DSA to make that happen.
*/
if (ret >= 0 && (ds->phys_mii_mask & (1 << ret))) {
ret = dsa_slave_phy_connect(p, slave_dev, ret);
if (ret)
return ret;
} else {
p->phy = of_phy_connect(slave_dev, phy_dn,
dsa_slave_adjust_link,
phy_flags,
p->phy_interface);
}
}

if (p->phy && phy_is_fixed)
fixed_phy_set_link_update(p->phy, dsa_slave_fixed_link_update);
Expand All @@ -679,7 +694,7 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
* MDIO bus instead
*/
if (!p->phy) {
ret = dsa_slave_phy_connect(p, slave_dev);
ret = dsa_slave_phy_connect(p, slave_dev, p->port);
if (ret)
return ret;
} else {
Expand Down

0 comments on commit cd28a1a

Please sign in to comment.