mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linkui Xiao <xiaolinkui@126.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>, netdev@vger.kernel.org
Cc: Andrew Lunn <andrew@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Rosen Penev <rosenp@gmail.com>,
	Christian Lamparter <chunkeey@gmail.com>,
	Jacob Keller <jacob.e.keller@intel.com>,
	Kees Cook <kees+treewide@kernel.org>,
	Daniel Machon <daniel.machon@microchip.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	linux-kernel@vger.kernel.org, Linkui Xiao <xiaolinkui@kylinos.cn>
Subject: [PATCH net v3] net: ibm: emac: attach and start the fixed-link PHY
Date: Tue, 24 Nov 2026 16:39:41 +0800	[thread overview]
Message-ID: <20261124083941.2480237-1-xiaolinkui@126.com> (raw)

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 is missing from the netdev's PHY
link topology and ETHTOOL_MSG_PHY_GET dereferences the NULL link_topo in
phy_prepare_data().

Attach it with of_phy_connect(), as this driver already does for the
phy-handle case and as gianfar, fec, davinci_emac and nixge do, and start
it with phy_start(). phylib then resolves the link and calls
emac_adjust_link(), the same as for a real PHY. That callback fills in the
dev->phy speed, duplex and pause that emac_configure() reads to build MR1.
Nothing else fills those in since commit d99b408ed8e5 ("net: phy:
fixed_phy: remove not needed initialization of phy_device members"), so
today a fixed link is programmed as 10 Mbit/s half duplex with flow
control off, whatever the fixed-link property says.

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(). The disconnect also stops the
phy-handle path, which calls phy_start() but never phy_stop(). The fixed
PHY is deregistered on the same paths.

Fixes: baab9de385a8 ("net: ibm: emac: use netdev's phydev directly")
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 | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

v3:
  - dropped 2/2: no phy_read_status() and no hand called
    emac_adjust_link(); the fixed link is started with phy_start() and
    phylib calls the adjust link callback like it does for a real PHY
    (Andrew Lunn)
  - back to a single patch, so no cover letter
  - the of_phy_connect() failure branch no longer deregisters the
    fixed PHY itself: the new err_detach_tah cleanup covers every
    probe failure, so the call was redundant
v2: https://lore.kernel.org/netdev/20261123093201.770552-1-xiaolinkui@126.com/
  - 1/2: rewrote the commit message by hand (Andrew Lunn)
  - 1/2: 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)
  - 2/2: new, read the link status so emac_adjust_link() no longer copies
    SPEED_UNKNOWN into dev->phy (Sashiko AI review)
v1: https://lore.kernel.org/netdev/20261112075321.3903875-1-xiaolinkui@126.com/

Cross compiled for powerpc out of ppc44x_defconfig with W=1, clean. No
hardware here, so no runtime test.

Per Documentation/process/generated-content.rst: the change and the commit
message were developed with an AI coding assistant; the analysis, the build
testing and the review are mine.

diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 1b95b4d5deff..ddf33c029334 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -2673,11 +2673,14 @@ 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))
+				return -EINVAL;
+
+			phy_start(ndev->phydev);
 		}
 		return 0;
 	}
@@ -3190,6 +3193,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 +3230,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


             reply	other threads:[~2026-11-24  8:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  8:39 Linkui Xiao [this message]
2026-11-24  8:44 ` netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124083941.2480237-1-xiaolinkui@126.com \
    --to=xiaolinkui@126.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=chunkeey@gmail.com \
    --cc=daniel.machon@microchip.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=jacob.e.keller@intel.com \
    --cc=kees+treewide@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rosenp@gmail.com \
    --cc=xiaolinkui@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®