提交 4751d2aa 编写于 作者: V Vladimir Oltean 提交者: Jakub Kicinski

net: stmmac: the XPCS obscures a potential "PHY not found" error

stmmac_mdio_register() has logic to search for PHYs on the MDIO bus and
assign them IRQ lines, as well as to set priv->plat->phy_addr.

If no PHY is found, the "found" variable remains set to 0 and the
function errors out.

After the introduction of commit f213bbe8 ("net: stmmac: Integrate
it with DesignWare XPCS"), the "found" variable was immediately reused
for searching for a PCS on the same MDIO bus.

This can result in 2 types of potential problems (none of them seems to
be seen on the only Intel system that sets has_xpcs = true, otherwise it
would have been reported):

1. If a PCS is found but a PHY is not, then the code happily exits with
   no error. One might say "yes, but this is not possible, because
   of_mdiobus_register will probe a PHY for all MDIO addresses,
   including for the XPCS, so if an XPCS exists, then a PHY certainly
   exists too". Well, that is not true, see intel_mgbe_common_data():

	/* Ensure mdio bus scan skips intel serdes and pcs-xpcs */
	plat->mdio_bus_data->phy_mask = 1 << INTEL_MGBE_ADHOC_ADDR;
	plat->mdio_bus_data->phy_mask |= 1 << INTEL_MGBE_XPCS_ADDR;

2. A PHY is found but an MDIO device with the XPCS PHY ID isn't, and in
   that case, the error message will be "No PHY found". Confusing.
Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20210527155959.3270478-1-olteanv@gmail.comSigned-off-by: NJakub Kicinski <kuba@kernel.org>
上级 1ab4fe09
...@@ -503,6 +503,12 @@ int stmmac_mdio_register(struct net_device *ndev) ...@@ -503,6 +503,12 @@ int stmmac_mdio_register(struct net_device *ndev)
found = 1; found = 1;
} }
if (!found && !mdio_node) {
dev_warn(dev, "No PHY found\n");
err = -ENODEV;
goto no_phy_found;
}
/* Try to probe the XPCS by scanning all addresses. */ /* Try to probe the XPCS by scanning all addresses. */
if (priv->hw->xpcs) { if (priv->hw->xpcs) {
struct mdio_xpcs_args *xpcs = &priv->hw->xpcs_args; struct mdio_xpcs_args *xpcs = &priv->hw->xpcs_args;
...@@ -511,6 +517,7 @@ int stmmac_mdio_register(struct net_device *ndev) ...@@ -511,6 +517,7 @@ int stmmac_mdio_register(struct net_device *ndev)
xpcs->bus = new_bus; xpcs->bus = new_bus;
found = 0;
for (addr = 0; addr < max_addr; addr++) { for (addr = 0; addr < max_addr; addr++) {
xpcs->addr = addr; xpcs->addr = addr;
...@@ -520,13 +527,12 @@ int stmmac_mdio_register(struct net_device *ndev) ...@@ -520,13 +527,12 @@ int stmmac_mdio_register(struct net_device *ndev)
break; break;
} }
} }
}
if (!found && !mdio_node) { if (!found && !mdio_node) {
dev_warn(dev, "No PHY found\n"); dev_warn(dev, "No XPCS found\n");
mdiobus_unregister(new_bus); err = -ENODEV;
mdiobus_free(new_bus); goto no_xpcs_found;
return -ENODEV; }
} }
bus_register_done: bus_register_done:
...@@ -534,6 +540,9 @@ int stmmac_mdio_register(struct net_device *ndev) ...@@ -534,6 +540,9 @@ int stmmac_mdio_register(struct net_device *ndev)
return 0; return 0;
no_xpcs_found:
no_phy_found:
mdiobus_unregister(new_bus);
bus_register_fail: bus_register_fail:
mdiobus_free(new_bus); mdiobus_free(new_bus);
return err; return err;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部