Skip to content

Commit c624f89

Browse files
ffainellidavem330
authored andcommitted
net: bcmgenet: Determine PHY type before scanning MDIO bus
Our internal GPHY might be powered off before we attempt scanning the MDIO bus and bind a driver to it. The way we are currently determining whether a PHY is internal or not is done *after* we have successfully matched its driver. If the PHY is powered down, it will not respond to the MDIO bus, so we will not be able to bind a driver to it. Our Device Tree for GENET interfaces specifies a "phy-mode" value: "internal" which tells if this internal uses an internal PHY or not. If of_get_phy_mode() fails to parse the 'phy-mode' property, do an additional manual lookup, and if we find "internal" set the corresponding internal variable accordingly. Replace all uses of phy_is_internal() with a check against priv->internal_phy to avoid having to rely on whether or not priv->phydev is set correctly. Fixes: 1c1008c ("net: bcmgenet: add main driver file") Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent bd4060a commit c624f89

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

drivers/net/ethernet/broadcom/genet/bcmgenet.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,7 @@ static int init_umac(struct bcmgenet_priv *priv)
17241724
int0_enable |= UMAC_IRQ_TXDMA_DONE;
17251725

17261726
/* Monitor cable plug/unplugged event for internal PHY */
1727-
if (phy_is_internal(priv->phydev)) {
1727+
if (priv->internal_phy) {
17281728
int0_enable |= UMAC_IRQ_LINK_EVENT;
17291729
} else if (priv->ext_phy) {
17301730
int0_enable |= UMAC_IRQ_LINK_EVENT;
@@ -2631,7 +2631,7 @@ static int bcmgenet_open(struct net_device *dev)
26312631
/* If this is an internal GPHY, power it back on now, before UniMAC is
26322632
* brought out of reset as absolutely no UniMAC activity is allowed
26332633
*/
2634-
if (phy_is_internal(priv->phydev))
2634+
if (priv->internal_phy)
26352635
bcmgenet_power_up(priv, GENET_POWER_PASSIVE);
26362636

26372637
/* take MAC out of reset */
@@ -2650,7 +2650,7 @@ static int bcmgenet_open(struct net_device *dev)
26502650

26512651
bcmgenet_set_hw_addr(priv, dev->dev_addr);
26522652

2653-
if (phy_is_internal(priv->phydev)) {
2653+
if (priv->internal_phy) {
26542654
reg = bcmgenet_ext_readl(priv, EXT_EXT_PWR_MGMT);
26552655
reg |= EXT_ENERGY_DET_MASK;
26562656
bcmgenet_ext_writel(priv, reg, EXT_EXT_PWR_MGMT);
@@ -2756,7 +2756,7 @@ static int bcmgenet_close(struct net_device *dev)
27562756
free_irq(priv->irq0, priv);
27572757
free_irq(priv->irq1, priv);
27582758

2759-
if (phy_is_internal(priv->phydev))
2759+
if (priv->internal_phy)
27602760
ret = bcmgenet_power_down(priv, GENET_POWER_PASSIVE);
27612761

27622762
if (!IS_ERR(priv->clk))
@@ -3318,7 +3318,7 @@ static int bcmgenet_suspend(struct device *d)
33183318
if (device_may_wakeup(d) && priv->wolopts) {
33193319
ret = bcmgenet_power_down(priv, GENET_POWER_WOL_MAGIC);
33203320
clk_prepare_enable(priv->clk_wol);
3321-
} else if (phy_is_internal(priv->phydev)) {
3321+
} else if (priv->internal_phy) {
33223322
ret = bcmgenet_power_down(priv, GENET_POWER_PASSIVE);
33233323
}
33243324

@@ -3347,7 +3347,7 @@ static int bcmgenet_resume(struct device *d)
33473347
/* If this is an internal GPHY, power it back on now, before UniMAC is
33483348
* brought out of reset as absolutely no UniMAC activity is allowed
33493349
*/
3350-
if (phy_is_internal(priv->phydev))
3350+
if (priv->internal_phy)
33513351
bcmgenet_power_up(priv, GENET_POWER_PASSIVE);
33523352

33533353
bcmgenet_umac_reset(priv);
@@ -3369,7 +3369,7 @@ static int bcmgenet_resume(struct device *d)
33693369

33703370
bcmgenet_set_hw_addr(priv, dev->dev_addr);
33713371

3372-
if (phy_is_internal(priv->phydev)) {
3372+
if (priv->internal_phy) {
33733373
reg = bcmgenet_ext_readl(priv, EXT_EXT_PWR_MGMT);
33743374
reg |= EXT_ENERGY_DET_MASK;
33753375
bcmgenet_ext_writel(priv, reg, EXT_EXT_PWR_MGMT);

drivers/net/ethernet/broadcom/genet/bcmgenet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ struct bcmgenet_priv {
593593
/* MDIO bus variables */
594594
wait_queue_head_t wq;
595595
struct phy_device *phydev;
596+
bool internal_phy;
596597
struct device_node *phy_dn;
597598
struct device_node *mdio_dn;
598599
struct mii_bus *mii_bus;

drivers/net/ethernet/broadcom/genet/bcmmii.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ int bcmgenet_mii_config(struct net_device *dev, bool init)
227227
u32 port_ctrl;
228228
u32 reg;
229229

230-
priv->ext_phy = !phy_is_internal(priv->phydev) &&
230+
priv->ext_phy = !priv->internal_phy &&
231231
(priv->phy_interface != PHY_INTERFACE_MODE_MOCA);
232232

233-
if (phy_is_internal(priv->phydev))
233+
if (priv->internal_phy)
234234
priv->phy_interface = PHY_INTERFACE_MODE_NA;
235235

236236
switch (priv->phy_interface) {
@@ -248,7 +248,7 @@ int bcmgenet_mii_config(struct net_device *dev, bool init)
248248

249249
bcmgenet_sys_writel(priv, port_ctrl, SYS_PORT_CTRL);
250250

251-
if (phy_is_internal(priv->phydev)) {
251+
if (priv->internal_phy) {
252252
phy_name = "internal PHY";
253253
bcmgenet_internal_phy_setup(dev);
254254
} else if (priv->phy_interface == PHY_INTERFACE_MODE_MOCA) {
@@ -386,7 +386,7 @@ static int bcmgenet_mii_probe(struct net_device *dev)
386386
/* The internal PHY has its link interrupts routed to the
387387
* Ethernet MAC ISRs
388388
*/
389-
if (phy_is_internal(priv->phydev))
389+
if (priv->internal_phy)
390390
priv->mii_bus->irq[phydev->addr] = PHY_IGNORE_INTERRUPT;
391391
else
392392
priv->mii_bus->irq[phydev->addr] = PHY_POLL;
@@ -479,7 +479,9 @@ static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv)
479479
{
480480
struct device_node *dn = priv->pdev->dev.of_node;
481481
struct device *kdev = &priv->pdev->dev;
482+
const char *phy_mode_str = NULL;
482483
char *compat;
484+
int phy_mode;
483485
int ret;
484486

485487
compat = kasprintf(GFP_KERNEL, "brcm,genet-mdio-v%d", priv->version);
@@ -503,7 +505,24 @@ static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv)
503505
priv->phy_dn = of_parse_phandle(dn, "phy-handle", 0);
504506

505507
/* Get the link mode */
506-
priv->phy_interface = of_get_phy_mode(dn);
508+
phy_mode = of_get_phy_mode(dn);
509+
priv->phy_interface = phy_mode;
510+
511+
/* We need to specifically look up whether this PHY interface is internal
512+
* or not *before* we even try to probe the PHY driver over MDIO as we
513+
* may have shut down the internal PHY for power saving purposes.
514+
*/
515+
if (phy_mode < 0) {
516+
ret = of_property_read_string(dn, "phy-mode", &phy_mode_str);
517+
if (ret < 0) {
518+
dev_err(kdev, "invalid PHY mode property\n");
519+
return ret;
520+
}
521+
522+
priv->phy_interface = PHY_INTERFACE_MODE_NA;
523+
if (!strcasecmp(phy_mode_str, "internal"))
524+
priv->internal_phy = true;
525+
}
507526

508527
return 0;
509528
}

0 commit comments

Comments
 (0)