* [PATCH net v2 0/2] net: ibm: emac: fix the fixed-link PHY setup
@ 2026-11-23 9:31 Linkui Xiao
2026-11-23 9:32 ` [PATCH net v2 1/2] net: ibm: emac: attach the fixed-link PHY with of_phy_connect() Linkui Xiao
2026-11-23 9:32 ` [PATCH net v2 2/2] net: ibm: emac: read the fixed-link status before adjusting the link Linkui Xiao
0 siblings, 2 replies; 3+ messages in thread
From: Linkui Xiao @ 2026-11-23 9:31 UTC (permalink / raw)
To: andrew
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, rosenp,
jacob.e.keller, daniel.machon, chunkeey, kees+treewide, netdev,
linux-kernel, xiaolinkui
From: Linkui Xiao <xiaolinkui@kylinos.cn>
EMAC never attaches the fixed-link PHY, so it is missing from the netdev's
PHY link topology and ETHTOOL_MSG_PHY_GET crashes. Attaching it also
means it has to be detached again, and it exposes a second bug: since
commit d99b408ed8e5 nothing fills in the phy_device status, so the driver
has been programming the MAC as 10 Mbit/s half duplex for every fixed
link.
Both are fixed here, in the order that keeps the series bisectable.
Cross compiled for powerpc out of ppc44x_defconfig with W=1. No
hardware, so no runtime test.
Note per Documentation/process/generated-content.rst: the changes were
developed with an AI coding assistant; the analysis, build testing and
review are mine.
Linkui Xiao (2):
net: ibm: emac: attach the fixed-link PHY with of_phy_connect()
net: ibm: emac: read the fixed-link status before adjusting the link
drivers/net/ethernet/ibm/emac/core.c | 31 +++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
---
v2:
- rewrote the commit message by hand and kept it to the reasons for the
change (Andrew Lunn)
- explain why emac_adjust_link() is still called by hand (Andrew Lunn)
- disconnect the PHY in emac_remove() and on probe failure, and
deregister the fixed PHY when of_phy_connect() fails (Andrew Lunn,
Sashiko AI review)
- new 2/2: read the link status so emac_adjust_link() no longer copies
SPEED_UNKNOWN into dev->phy (Sashiko AI review)
- rebased: 4dd10fbbeb9c ("treewide: Convert devm_kmalloc() family to the
devm_kmalloc_obj() family") changed emac/core.c since v1
v1: https://lore.kernel.org/netdev/20261112075321.3903875-1-xiaolinkui@126.com/
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH net v2 1/2] net: ibm: emac: attach the fixed-link PHY with of_phy_connect()
2026-11-23 9:31 [PATCH net v2 0/2] net: ibm: emac: fix the fixed-link PHY setup Linkui Xiao
@ 2026-11-23 9:32 ` Linkui Xiao
2026-11-23 9:32 ` [PATCH net v2 2/2] net: ibm: emac: read the fixed-link status before adjusting the link Linkui Xiao
1 sibling, 0 replies; 3+ messages in thread
From: Linkui Xiao @ 2026-11-23 9:32 UTC (permalink / raw)
To: andrew
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, rosenp,
jacob.e.keller, daniel.machon, chunkeey, kees+treewide, netdev,
linux-kernel, xiaolinkui
From: Linkui Xiao <xiaolinkui@kylinos.cn>
emac_init_phy() sets ndev->phydev by hand for a fixed link, so
phy_attach_direct() never runs: the PHY stays out of the netdev's PHY
link topology, and ETHTOOL_MSG_PHY_GET then dereferences a NULL
link_topo in phy_prepare_data().
Use of_phy_connect(), as gianfar, fec, davinci_emac and nixge do, and as
this driver already does for the phy-handle case. It attaches the PHY
and drops the of_phy_find_device() reference, so put_device() goes away.
It only installs emac_adjust_link() as phydev->adjust_link though, and
the state machine is not started for a fixed link, so the explicit call
that copies the link parameters into dev->phy stays.
Attaching also means detaching. Without phy_disconnect(), unbind leaves
phydev->attached_dev pointing at a freed netdev and the next probe fails
with -EBUSY from phy_attach_direct(). This fixes the phy-handle path as
well, which calls phy_start() but never phy_stop().
Fixes: baab9de385a8 ("net: ibm: emac: use netdev's phydev directly")
Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
---
drivers/net/ethernet/ibm/emac/core.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 1b95b4d5deff..ba02cf878a12 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -2673,11 +2673,16 @@ static int emac_init_phy(struct emac_instance *dev)
return res;
res = of_phy_register_fixed_link(np);
- ndev->phydev = of_phy_find_device(np);
- if (res || !ndev->phydev)
- return res ? res : -EINVAL;
- emac_adjust_link(dev->ndev);
- put_device(&ndev->phydev->mdio.dev);
+ if (res)
+ return res;
+
+ if (!of_phy_connect(ndev, np, &emac_adjust_link, 0,
+ dev->phy_mode)) {
+ of_phy_deregister_fixed_link(np);
+ return -EINVAL;
+ }
+
+ emac_adjust_link(ndev);
}
return 0;
}
@@ -3190,6 +3195,10 @@ static int emac_probe(struct platform_device *ofdev)
/* I have a bad feeling about this ... */
err_detach_tah:
+ if (ndev->phydev)
+ phy_disconnect(ndev->phydev);
+ if (of_phy_is_fixed_link(np))
+ of_phy_deregister_fixed_link(np);
if (emac_has_feature(dev, EMAC_FTR_HAS_TAH))
tah_detach(dev->tah_dev, dev->tah_port);
err_detach_rgmii:
@@ -3223,6 +3232,11 @@ static void emac_remove(struct platform_device *ofdev)
cancel_work_sync(&dev->reset_work);
+ if (dev->ndev->phydev)
+ phy_disconnect(dev->ndev->phydev);
+ if (of_phy_is_fixed_link(ofdev->dev.of_node))
+ of_phy_deregister_fixed_link(ofdev->dev.of_node);
+
if (emac_has_feature(dev, EMAC_FTR_HAS_TAH))
tah_detach(dev->tah_dev, dev->tah_port);
if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII))
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH net v2 2/2] net: ibm: emac: read the fixed-link status before adjusting the link
2026-11-23 9:31 [PATCH net v2 0/2] net: ibm: emac: fix the fixed-link PHY setup Linkui Xiao
2026-11-23 9:32 ` [PATCH net v2 1/2] net: ibm: emac: attach the fixed-link PHY with of_phy_connect() Linkui Xiao
@ 2026-11-23 9:32 ` Linkui Xiao
1 sibling, 0 replies; 3+ messages in thread
From: Linkui Xiao @ 2026-11-23 9:32 UTC (permalink / raw)
To: andrew
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, rosenp,
jacob.e.keller, daniel.machon, chunkeey, kees+treewide, netdev,
linux-kernel, xiaolinkui
From: Linkui Xiao <xiaolinkui@kylinos.cn>
For a fixed link emac_init_phy() calls emac_adjust_link() once to copy
the link parameters from the phy_device into dev->phy, and never starts
the PHY state machine.
That worked while fixed_phy_register() copied the device tree status into
the phy_device itself. Commit d99b408ed8e5 ("net: phy: fixed_phy: remove
not needed initialization of phy_device members") dropped that, expecting
the state machine to fill the members in once the PHY is started. EMAC
does not start it, so emac_adjust_link() now copies SPEED_UNKNOWN and
DUPLEX_UNKNOWN, and emac_configure() programs the MAC for 10 Mbit/s half
duplex with flow control off, whatever the fixed-link property says.
Read the status once after attaching, as emac_mdio_read_link() already
does for the phy-handle path. The PHY is emulated, so genphy_read_status()
resolves speed, duplex and pause from the registers swphy generates out of
the device tree status.
Fixes: d99b408ed8e5 ("net: phy: fixed_phy: remove not needed initialization of phy_device members")
Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
---
drivers/net/ethernet/ibm/emac/core.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index ba02cf878a12..8b9ffbcd2ff4 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -2677,9 +2677,16 @@ static int emac_init_phy(struct emac_instance *dev)
return res;
if (!of_phy_connect(ndev, np, &emac_adjust_link, 0,
- dev->phy_mode)) {
+ dev->phy_mode))
+ res = -EINVAL;
+ else
+ res = phy_read_status(ndev->phydev);
+
+ if (res) {
+ if (ndev->phydev)
+ phy_disconnect(ndev->phydev);
of_phy_deregister_fixed_link(np);
- return -EINVAL;
+ return res;
}
emac_adjust_link(ndev);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-23 9:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 9:31 [PATCH net v2 0/2] net: ibm: emac: fix the fixed-link PHY setup Linkui Xiao
2026-11-23 9:32 ` [PATCH net v2 1/2] net: ibm: emac: attach the fixed-link PHY with of_phy_connect() Linkui Xiao
2026-11-23 9:32 ` [PATCH net v2 2/2] net: ibm: emac: read the fixed-link status before adjusting the link Linkui Xiao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).