Commit 7f854420 authored by Andrew Lunn's avatar Andrew Lunn Committed by David S. Miller
Browse files

phy: Add API for {un}registering an mdio device to a bus.



Rather than have drivers directly manipulate the mii_bus structure,
provide and API for registering and unregistering devices on an MDIO
bus, and performing lookups.

Signed-off-by: default avatarAndrew Lunn <andrew@lunn.ch>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 801a8ef5
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -502,7 +502,7 @@ static int au1000_mii_probe(struct net_device *dev)
		BUG_ON(aup->mac_id < 0 || aup->mac_id > 1);
		BUG_ON(aup->mac_id < 0 || aup->mac_id > 1);


		if (aup->phy_addr)
		if (aup->phy_addr)
			phydev = aup->mii_bus->phy_map[aup->phy_addr];
			phydev = mdiobus_get_phy(aup->mii_bus, aup->phy_addr);
		else
		else
			netdev_info(dev, "using PHY-less setup\n");
			netdev_info(dev, "using PHY-less setup\n");
		return 0;
		return 0;
@@ -512,8 +512,8 @@ static int au1000_mii_probe(struct net_device *dev)
	 * on the current MAC's MII bus
	 * on the current MAC's MII bus
	 */
	 */
	for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++)
	for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++)
		if (aup->mii_bus->phy_map[phy_addr]) {
		if (mdiobus_get_phy(aup->mii_bus, aup->phy_addr)) {
			phydev = aup->mii_bus->phy_map[phy_addr];
			phydev = mdiobus_get_phy(aup->mii_bus, aup->phy_addr);
			if (!aup->phy_search_highest_addr)
			if (!aup->phy_search_highest_addr)
				/* break out with first one found */
				/* break out with first one found */
				break;
				break;
@@ -531,7 +531,8 @@ static int au1000_mii_probe(struct net_device *dev)
			 */
			 */
			for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
			for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
				struct phy_device *const tmp_phydev =
				struct phy_device *const tmp_phydev =
					aup->mii_bus->phy_map[phy_addr];
					mdiobus_get_phy(aup->mii_bus,
							phy_addr);


				if (aup->mac_id == 1)
				if (aup->mac_id == 1)
					break;
					break;
+1 −1
Original line number Original line Diff line number Diff line
@@ -2272,7 +2272,7 @@ static int b44_register_phy_one(struct b44 *bp)
		goto err_out_mdiobus;
		goto err_out_mdiobus;
	}
	}


	if (!bp->mii_bus->phy_map[bp->phy_addr] &&
	if (!mdiobus_is_registered_device(bp->mii_bus, bp->phy_addr) &&
	    (sprom->boardflags_lo & (B44_BOARDFLAG_ROBO | B44_BOARDFLAG_ADM))) {
	    (sprom->boardflags_lo & (B44_BOARDFLAG_ROBO | B44_BOARDFLAG_ADM))) {


		dev_info(sdev->dev,
		dev_info(sdev->dev,
+1 −1
Original line number Original line Diff line number Diff line
@@ -573,7 +573,7 @@ static int bcmgenet_mii_pd_init(struct bcmgenet_priv *priv)
		}
		}


		if (pd->phy_address >= 0 && pd->phy_address < PHY_MAX_ADDR)
		if (pd->phy_address >= 0 && pd->phy_address < PHY_MAX_ADDR)
			phydev = mdio->phy_map[pd->phy_address];
			phydev = mdiobus_get_phy(mdio, pd->phy_address);
		else
		else
			phydev = phy_find_first(mdio);
			phydev = phy_find_first(mdio);


+15 −15
Original line number Original line Diff line number Diff line
@@ -1406,7 +1406,7 @@ static void tg3_mdio_config_5785(struct tg3 *tp)
	u32 val;
	u32 val;
	struct phy_device *phydev;
	struct phy_device *phydev;


	phydev = tp->mdio_bus->phy_map[tp->phy_addr];
	phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr);
	switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) {
	switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) {
	case PHY_ID_BCM50610:
	case PHY_ID_BCM50610:
	case PHY_ID_BCM50610M:
	case PHY_ID_BCM50610M:
@@ -1554,7 +1554,7 @@ static int tg3_mdio_init(struct tg3 *tp)
		return i;
		return i;
	}
	}


	phydev = tp->mdio_bus->phy_map[tp->phy_addr];
	phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr);


	if (!phydev || !phydev->drv) {
	if (!phydev || !phydev->drv) {
		dev_warn(&tp->pdev->dev, "No PHY devices\n");
		dev_warn(&tp->pdev->dev, "No PHY devices\n");
@@ -1964,7 +1964,7 @@ static void tg3_setup_flow_control(struct tg3 *tp, u32 lcladv, u32 rmtadv)
	u32 old_tx_mode = tp->tx_mode;
	u32 old_tx_mode = tp->tx_mode;


	if (tg3_flag(tp, USE_PHYLIB))
	if (tg3_flag(tp, USE_PHYLIB))
		autoneg = tp->mdio_bus->phy_map[tp->phy_addr]->autoneg;
		autoneg = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr)->autoneg;
	else
	else
		autoneg = tp->link_config.autoneg;
		autoneg = tp->link_config.autoneg;


@@ -2000,7 +2000,7 @@ static void tg3_adjust_link(struct net_device *dev)
	u8 oldflowctrl, linkmesg = 0;
	u8 oldflowctrl, linkmesg = 0;
	u32 mac_mode, lcl_adv, rmt_adv;
	u32 mac_mode, lcl_adv, rmt_adv;
	struct tg3 *tp = netdev_priv(dev);
	struct tg3 *tp = netdev_priv(dev);
	struct phy_device *phydev = tp->mdio_bus->phy_map[tp->phy_addr];
	struct phy_device *phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr);


	spin_lock_bh(&tp->lock);
	spin_lock_bh(&tp->lock);


@@ -2089,7 +2089,7 @@ static int tg3_phy_init(struct tg3 *tp)
	/* Bring the PHY back to a known state. */
	/* Bring the PHY back to a known state. */
	tg3_bmcr_reset(tp);
	tg3_bmcr_reset(tp);


	phydev = tp->mdio_bus->phy_map[tp->phy_addr];
	phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr);


	/* Attach the MAC to the PHY. */
	/* Attach the MAC to the PHY. */
	phydev = phy_connect(tp->dev, phydev_name(phydev),
	phydev = phy_connect(tp->dev, phydev_name(phydev),
@@ -2116,7 +2116,7 @@ static int tg3_phy_init(struct tg3 *tp)
				      SUPPORTED_Asym_Pause);
				      SUPPORTED_Asym_Pause);
		break;
		break;
	default:
	default:
		phy_disconnect(tp->mdio_bus->phy_map[tp->phy_addr]);
		phy_disconnect(mdiobus_get_phy(tp->mdio_bus, tp->phy_addr));
		return -EINVAL;
		return -EINVAL;
	}
	}


@@ -2136,7 +2136,7 @@ static void tg3_phy_start(struct tg3 *tp)
	if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
	if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
		return;
		return;


	phydev = tp->mdio_bus->phy_map[tp->phy_addr];
	phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr);


	if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) {
	if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) {
		tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER;
		tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER;
@@ -2156,13 +2156,13 @@ static void tg3_phy_stop(struct tg3 *tp)
	if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
	if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
		return;
		return;


	phy_stop(tp->mdio_bus->phy_map[tp->phy_addr]);
	phy_stop(mdiobus_get_phy(tp->mdio_bus, tp->phy_addr));
}
}


static void tg3_phy_fini(struct tg3 *tp)
static void tg3_phy_fini(struct tg3 *tp)
{
{
	if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) {
	if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) {
		phy_disconnect(tp->mdio_bus->phy_map[tp->phy_addr]);
		phy_disconnect(mdiobus_get_phy(tp->mdio_bus, tp->phy_addr));
		tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED;
		tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED;
	}
	}
}
}
@@ -4046,7 +4046,7 @@ static int tg3_power_down_prepare(struct tg3 *tp)
			struct phy_device *phydev;
			struct phy_device *phydev;
			u32 phyid, advertising;
			u32 phyid, advertising;


			phydev = tp->mdio_bus->phy_map[tp->phy_addr];
			phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr);


			tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER;
			tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER;


@@ -12074,7 +12074,7 @@ static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
		struct phy_device *phydev;
		struct phy_device *phydev;
		if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
		if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
			return -EAGAIN;
			return -EAGAIN;
		phydev = tp->mdio_bus->phy_map[tp->phy_addr];
		phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr);
		return phy_ethtool_gset(phydev, cmd);
		return phy_ethtool_gset(phydev, cmd);
	}
	}


@@ -12141,7 +12141,7 @@ static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
		struct phy_device *phydev;
		struct phy_device *phydev;
		if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
		if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
			return -EAGAIN;
			return -EAGAIN;
		phydev = tp->mdio_bus->phy_map[tp->phy_addr];
		phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr);
		return phy_ethtool_sset(phydev, cmd);
		return phy_ethtool_sset(phydev, cmd);
	}
	}


@@ -12296,7 +12296,7 @@ static int tg3_nway_reset(struct net_device *dev)
	if (tg3_flag(tp, USE_PHYLIB)) {
	if (tg3_flag(tp, USE_PHYLIB)) {
		if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
		if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
			return -EAGAIN;
			return -EAGAIN;
		r = phy_start_aneg(tp->mdio_bus->phy_map[tp->phy_addr]);
		r = phy_start_aneg(mdiobus_get_phy(tp->mdio_bus, tp->phy_addr));
	} else {
	} else {
		u32 bmcr;
		u32 bmcr;


@@ -12414,7 +12414,7 @@ static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam
		u32 newadv;
		u32 newadv;
		struct phy_device *phydev;
		struct phy_device *phydev;


		phydev = tp->mdio_bus->phy_map[tp->phy_addr];
		phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr);


		if (!(phydev->supported & SUPPORTED_Pause) ||
		if (!(phydev->supported & SUPPORTED_Pause) ||
		    (!(phydev->supported & SUPPORTED_Asym_Pause) &&
		    (!(phydev->supported & SUPPORTED_Asym_Pause) &&
@@ -13924,7 +13924,7 @@ static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
		struct phy_device *phydev;
		struct phy_device *phydev;
		if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
		if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
			return -EAGAIN;
			return -EAGAIN;
		phydev = tp->mdio_bus->phy_map[tp->phy_addr];
		phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr);
		return phy_mii_ioctl(phydev, ifr, cmd);
		return phy_mii_ioctl(phydev, ifr, cmd);
	}
	}


+2 −2
Original line number Original line Diff line number Diff line
@@ -678,7 +678,7 @@ static int ethoc_mdio_probe(struct net_device *dev)
	int err;
	int err;


	if (priv->phy_id != -1)
	if (priv->phy_id != -1)
		phy = priv->mdio->phy_map[priv->phy_id];
		phy = mdiobus_get_phy(priv->mdio, priv->phy_id);
	else
	else
		phy = phy_find_first(priv->mdio);
		phy = phy_find_first(priv->mdio);


@@ -766,7 +766,7 @@ static int ethoc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
		if (mdio->phy_id >= PHY_MAX_ADDR)
		if (mdio->phy_id >= PHY_MAX_ADDR)
			return -ERANGE;
			return -ERANGE;


		phy = priv->mdio->phy_map[mdio->phy_id];
		phy = mdiobus_get_phy(priv->mdio, mdio->phy_id);
		if (!phy)
		if (!phy)
			return -ENODEV;
			return -ENODEV;
	} else {
	} else {
Loading