Skip to content

Commit 8fbc10b

Browse files
michaelsit-iotgkuba-moo
authored andcommitted
net: stmmac: check fwnode for phy device before scanning for phy
Some DT devices already have phy device configured in the DT/ACPI. Current implementation scans for a phy unconditionally even though there is a phy listed in the DT/ACPI and already attached. We should check the fwnode if there is any phy device listed in fwnode and decide whether to scan for a phy to attach to. Fixes: fe2cfbc ("net: stmmac: check if MAC needs to attach to a PHY") Reported-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com> Link: https://lore.kernel.org/lkml/20230403212434.296975-1-martin.blumenstingl@googlemail.com/ Tested-by: Guenter Roeck <linux@roeck-us.net> Tested-by: Shahab Vahedi <shahab@synopsys.com> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> Tested-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com> Suggested-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com> Link: https://lore.kernel.org/r/20230406024541.3556305-1-michael.wei.hong.sit@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 24e3fce commit 8fbc10b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,22 +1134,26 @@ static void stmmac_check_pcs_mode(struct stmmac_priv *priv)
11341134
static int stmmac_init_phy(struct net_device *dev)
11351135
{
11361136
struct stmmac_priv *priv = netdev_priv(dev);
1137+
struct fwnode_handle *phy_fwnode;
11371138
struct fwnode_handle *fwnode;
1138-
bool phy_needed;
11391139
int ret;
11401140

1141+
if (!phylink_expects_phy(priv->phylink))
1142+
return 0;
1143+
11411144
fwnode = of_fwnode_handle(priv->plat->phylink_node);
11421145
if (!fwnode)
11431146
fwnode = dev_fwnode(priv->device);
11441147

11451148
if (fwnode)
1146-
ret = phylink_fwnode_phy_connect(priv->phylink, fwnode, 0);
1149+
phy_fwnode = fwnode_get_phy_node(fwnode);
1150+
else
1151+
phy_fwnode = NULL;
11471152

1148-
phy_needed = phylink_expects_phy(priv->phylink);
11491153
/* Some DT bindings do not set-up the PHY handle. Let's try to
11501154
* manually parse it
11511155
*/
1152-
if (!fwnode || phy_needed || ret) {
1156+
if (!phy_fwnode || IS_ERR(phy_fwnode)) {
11531157
int addr = priv->plat->phy_addr;
11541158
struct phy_device *phydev;
11551159

@@ -1165,6 +1169,9 @@ static int stmmac_init_phy(struct net_device *dev)
11651169
}
11661170

11671171
ret = phylink_connect_phy(priv->phylink, phydev);
1172+
} else {
1173+
fwnode_handle_put(phy_fwnode);
1174+
ret = phylink_fwnode_phy_connect(priv->phylink, fwnode, 0);
11681175
}
11691176

11701177
if (!priv->plat->pmt) {

0 commit comments

Comments
 (0)