Commit ead2402c authored by Hauke Mehrtens's avatar Hauke Mehrtens Committed by David S. Miller

tg3: add support a phy at an address different than 01

When phylib was in use tg3 only searched at address 01 on the mdio
bus and did not work with any other address. On the BCM4705 SoCs the
switch is connected as a PHY behind the MAC driven by tg3 and it is at
PHY address 30 in most cases. This is a preparation patch to allow
support for such switches.

phy_addr is set to TG3_PHY_MII_ADDR for all devices, which are using
phylib, so this should not change any behavior.
Signed-off-by: default avatarHauke Mehrtens <hauke@hauke-m.de>
Acked-by: default avatarNithin Nayak Sujir <nsujir@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4fbef95a
...@@ -1375,7 +1375,7 @@ static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) ...@@ -1375,7 +1375,7 @@ static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg)
spin_lock_bh(&tp->lock); spin_lock_bh(&tp->lock);
if (tg3_readphy(tp, reg, &val)) if (__tg3_readphy(tp, mii_id, reg, &val))
val = -EIO; val = -EIO;
spin_unlock_bh(&tp->lock); spin_unlock_bh(&tp->lock);
...@@ -1390,7 +1390,7 @@ static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) ...@@ -1390,7 +1390,7 @@ static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val)
spin_lock_bh(&tp->lock); spin_lock_bh(&tp->lock);
if (tg3_writephy(tp, reg, val)) if (__tg3_writephy(tp, mii_id, reg, val))
ret = -EIO; ret = -EIO;
spin_unlock_bh(&tp->lock); spin_unlock_bh(&tp->lock);
...@@ -1408,7 +1408,7 @@ static void tg3_mdio_config_5785(struct tg3 *tp) ...@@ -1408,7 +1408,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[TG3_PHY_MII_ADDR]; phydev = tp->mdio_bus->phy_map[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:
...@@ -1533,7 +1533,7 @@ static int tg3_mdio_init(struct tg3 *tp) ...@@ -1533,7 +1533,7 @@ static int tg3_mdio_init(struct tg3 *tp)
tp->mdio_bus->read = &tg3_mdio_read; tp->mdio_bus->read = &tg3_mdio_read;
tp->mdio_bus->write = &tg3_mdio_write; tp->mdio_bus->write = &tg3_mdio_write;
tp->mdio_bus->reset = &tg3_mdio_reset; tp->mdio_bus->reset = &tg3_mdio_reset;
tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); tp->mdio_bus->phy_mask = ~(1 << tp->phy_addr);
tp->mdio_bus->irq = &tp->mdio_irq[0]; tp->mdio_bus->irq = &tp->mdio_irq[0];
for (i = 0; i < PHY_MAX_ADDR; i++) for (i = 0; i < PHY_MAX_ADDR; i++)
...@@ -1554,7 +1554,7 @@ static int tg3_mdio_init(struct tg3 *tp) ...@@ -1554,7 +1554,7 @@ static int tg3_mdio_init(struct tg3 *tp)
return i; return i;
} }
phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; phydev = tp->mdio_bus->phy_map[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) ...@@ -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[TG3_PHY_MII_ADDR]->autoneg; autoneg = tp->mdio_bus->phy_map[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) ...@@ -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[TG3_PHY_MII_ADDR]; struct phy_device *phydev = tp->mdio_bus->phy_map[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) ...@@ -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[TG3_PHY_MII_ADDR]; phydev = tp->mdio_bus->phy_map[tp->phy_addr];
/* Attach the MAC to the PHY. */ /* Attach the MAC to the PHY. */
phydev = phy_connect(tp->dev, dev_name(&phydev->dev), phydev = phy_connect(tp->dev, dev_name(&phydev->dev),
...@@ -2116,7 +2116,7 @@ static int tg3_phy_init(struct tg3 *tp) ...@@ -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[TG3_PHY_MII_ADDR]); phy_disconnect(tp->mdio_bus->phy_map[tp->phy_addr]);
return -EINVAL; return -EINVAL;
} }
...@@ -2134,7 +2134,7 @@ static void tg3_phy_start(struct tg3 *tp) ...@@ -2134,7 +2134,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[TG3_PHY_MII_ADDR]; phydev = tp->mdio_bus->phy_map[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;
...@@ -2154,13 +2154,13 @@ static void tg3_phy_stop(struct tg3 *tp) ...@@ -2154,13 +2154,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[TG3_PHY_MII_ADDR]); phy_stop(tp->mdio_bus->phy_map[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[TG3_PHY_MII_ADDR]); phy_disconnect(tp->mdio_bus->phy_map[tp->phy_addr]);
tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED;
} }
} }
...@@ -4034,7 +4034,7 @@ static int tg3_power_down_prepare(struct tg3 *tp) ...@@ -4034,7 +4034,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[TG3_PHY_MII_ADDR]; phydev = tp->mdio_bus->phy_map[tp->phy_addr];
tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER;
...@@ -11922,7 +11922,7 @@ static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) ...@@ -11922,7 +11922,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[TG3_PHY_MII_ADDR]; phydev = tp->mdio_bus->phy_map[tp->phy_addr];
return phy_ethtool_gset(phydev, cmd); return phy_ethtool_gset(phydev, cmd);
} }
...@@ -11989,7 +11989,7 @@ static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) ...@@ -11989,7 +11989,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[TG3_PHY_MII_ADDR]; phydev = tp->mdio_bus->phy_map[tp->phy_addr];
return phy_ethtool_sset(phydev, cmd); return phy_ethtool_sset(phydev, cmd);
} }
...@@ -12144,7 +12144,7 @@ static int tg3_nway_reset(struct net_device *dev) ...@@ -12144,7 +12144,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[TG3_PHY_MII_ADDR]); r = phy_start_aneg(tp->mdio_bus->phy_map[tp->phy_addr]);
} else { } else {
u32 bmcr; u32 bmcr;
...@@ -12260,7 +12260,7 @@ static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam ...@@ -12260,7 +12260,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[TG3_PHY_MII_ADDR]; phydev = tp->mdio_bus->phy_map[tp->phy_addr];
if (!(phydev->supported & SUPPORTED_Pause) || if (!(phydev->supported & SUPPORTED_Pause) ||
(!(phydev->supported & SUPPORTED_Asym_Pause) && (!(phydev->supported & SUPPORTED_Asym_Pause) &&
...@@ -13696,7 +13696,7 @@ static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) ...@@ -13696,7 +13696,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[TG3_PHY_MII_ADDR]; phydev = tp->mdio_bus->phy_map[tp->phy_addr];
return phy_mii_ioctl(phydev, ifr, cmd); return phy_mii_ioctl(phydev, ifr, cmd);
} }
...@@ -17635,7 +17635,7 @@ static int tg3_init_one(struct pci_dev *pdev, ...@@ -17635,7 +17635,7 @@ static int tg3_init_one(struct pci_dev *pdev,
if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) {
struct phy_device *phydev; struct phy_device *phydev;
phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; phydev = tp->mdio_bus->phy_map[tp->phy_addr];
netdev_info(dev, netdev_info(dev,
"attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n",
phydev->drv->name, dev_name(&phydev->dev)); phydev->drv->name, dev_name(&phydev->dev));
......
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