🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21954

Re: [PATCH net-next v6 1/4] net: phy: Map C45 probe read errors to -ENODEV during bus scan

#21954
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 16:49
257 lines
17744 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The commit message describes the SFP impact wrongly.
- [Medium] get_phy_c45_devs_in_pkg() reads MDIO_DEVS2 and then
  MDIO_DEVS1, and returns the raw bus error from whichever read fails.
- [Low] The commit message says errors from the vendor MMD presence check
  in the identifier loop "are not mapped, so a PHY that fails midway is…
- [Low] When a devices-in-package read in the MMD search loop of
  get_phy_c45_ids() fails with -EIO/-ENODEV, the new code breaks out of…

--

net: phy: Map C45 probe read errors to -ENODEV during bus scan

This commit makes get_phy_c45_devs_in_pkg() return the raw bus error. It
then maps -EIO and -ENODEV to -ENODEV in the MMD search loop and in the
MMD 0 fallback of get_phy_c45_ids(), so C45 bus scans carry on past empty
addresses. When such an error happens in the MMD loop, the remaining MMDs
are skipped and only MMD 0 is probed.

> - sfp_sm_probe_phy(): a module whose PHY does not answer ends up with "no
>   PHY detected" after the usual retries, instead of going to SFP_S_FAIL.

[Severity: Medium]

Is this description of the SFP change accurate? On the mdio-i2c buses that
SFP uses, a PHY that does not answer does not seem to show up as a bus error
at all:

drivers/net/mdio/mdio-i2c.c:i2c_mii_read_default_c45() {
    ...
	ret = i2c_transfer(i2c, msgs, ARRAY_SIZE(msgs));
	if (ret != ARRAY_SIZE(msgs))
		return 0xffff;
    ...
}

drivers/net/mdio/mdio-i2c.c:i2c_mii_read_rollball() {
    ...
	ret = i2c_rollball_mii_poll(bus, bus_addr, res, sizeof(res));
	if (ret == -ETIMEDOUT)
		return 0xffff;
	else if (ret < 0)
		return ret;
    ...
}

So a module with an absent PHY already ended up with "no PHY detected"
before this patch.

>From an SFP bus, the only -EIO that seems able to reach
get_phy_c45_devs_in_pkg() is an I2C transport error on a RollBall module.
That error comes from i2c_rollball_mii_cmd() or i2c_rollball_mii_poll(),
for example a short transfer that __i2c_transfer_err() turns into -EIO.

With this patch, that transport fault becomes -ENODEV, and
sfp_sm_probe_phy() returns it without logging anything:

drivers/net/phy/sfp.c:sfp_sm_probe_phy() {
    ...
	phy = get_phy_device(sfp->i2c_mii, addr, is_c45);
	if (phy == ERR_PTR(-ENODEV))
		return PTR_ERR(phy);
	if (IS_ERR(phy)) {
		dev_err(sfp->dev, "mdiobus scan returned %pe\n", phy);
		return PTR_ERR(phy);
	}
    ...
}

The state machine then retries R_PHY_RETRY times and starts the module
without a PHY through sfp_module_start(). Before the patch it logged
"mdiobus scan returned -EIO" and went to SFP_S_FAIL.

This patch has a Fixes: tag and will likely be backported. Could the
sfp_sm_probe_phy() bullet describe this change instead?

> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index b39e945cebd73..2f17c9d4a2b9f 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c

[ ... ]

> @@ -810,8 +823,10 @@ static int get_phy_c45_devs_in_pkg(struct mii_bus *bus, int addr, int dev_addr,
>   * the PHY identifiers for each device. Return the "devices in package"
>   * and identifiers in @c45_ids.
>   *
> - * Returns zero on success, %-EIO on bus access error, or %-ENODEV if
> - * the "devices in package" is invalid or no device responds.
> + * Returns zero on success, %-ENODEV if the "devices in package" is invalid or
> + * if no MMD responds (including when the bus reports -EIO or -ENODEV for the
> + * reads that look for a device), or a negative error code from a failed bus
> + * access otherwise (usually %-EIO).
>   */
>  static int get_phy_c45_ids(struct mii_bus *bus, int addr,
>  			   struct phy_c45_device_ids *c45_ids)

[Severity: Low]

The commit message says:

    Errors from the vendor MMD presence check done while reading the
    identifiers and from the reads of the per-MMD identifiers themselves,
    which only happen once a device has answered, are not mapped, so a PHY
    that fails midway is not silently skipped.

Does the identifier loop in get_phy_c45_ids() keep that guarantee? The
VEND1/VEND2 branch returns the raw bus error from phy_c45_probe_present():

	/* Now probe Device Identifiers for each device present. */
	for (i = 1; i < num_ids; i++) {
		...
		if (i == MDIO_MMD_VEND1 || i == MDIO_MMD_VEND2) {
			...
			ret = phy_c45_probe_present(bus, addr, i);
			if (ret < 0)
				return ret;

Some read_c45 implementations return -ENODEV. One example is
orion_mdio_xsmi_read_c45() in drivers/net/ethernet/marvell/mvmdio.c:

	if (!(readl(dev->regs + MVMDIO_XSMI_MGNT_REG) &
	      MVMDIO_XSMI_READ_VALID)) {
		dev_err(bus->parent, "XSMI bus read not valid\n");
		return -ENODEV;
	}

Suppose a PHY has already answered the devices in package reads, and then
its STAT2 read on a vendor MMD fails this way. get_phy_c45_ids() returns
-ENODEV. mdiobus_scan_bus_c45(), __of_mdiobus_parse_phys() and
sfp_sm_probe_phy() all treat that as an empty address, so the PHY is
skipped without a message.

This code path is older than the patch. However, the new kernel-doc here
and for phy_get_c45_ids() links -ENODEV only to "no MMD responds". Should
this error be mapped to -EIO? Otherwise, should the commit message and
kernel-doc make a weaker claim?

> @@ -844,8 +859,20 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr,
>  				continue;
>  		}
>  		phy_reg = get_phy_c45_devs_in_pkg(bus, addr, i, &devs_in_pkg);
> -		if (phy_reg < 0)
> -			return -EIO;
> +		if (phy_reg < 0) {
> +			ret = get_phy_c45_probe_err(phy_reg);
> +			if (ret != -ENODEV)
> +				return ret;

[Severity: Medium]

Can this treat a PHY that has already answered as absent?
get_phy_c45_devs_in_pkg() reads MDIO_DEVS2 and then MDIO_DEVS1. It returns
the raw error from whichever read fails, so the caller cannot tell the two
cases apart:

	phy_reg = mdiobus_c45_read(bus, addr, dev_addr, MDIO_DEVS2);
	if (phy_reg < 0)
		return phy_reg;
	...
	phy_reg = mdiobus_c45_read(bus, addr, dev_addr, MDIO_DEVS1);
	if (phy_reg < 0)
		return phy_reg;

Suppose DEVS2 succeeds at MMD i, which on a controller that checks
turnaround means the device drove the bus. If only DEVS1 then fails with
-EIO or -ENODEV, this path sets devs_in_pkg to all Fs, breaks out of the
loop and leaves the decision to MMD 0 alone:

		phy_reg = get_phy_c45_devs_in_pkg(bus, addr, 0, &devs_in_pkg);
		if (phy_reg < 0)
			/* returning -ENODEV doesn't stop bus scanning */
			return get_phy_c45_probe_err(phy_reg);

Two outcomes seem possible:

- MMD 0 also fails with -EIO or -ENODEV. get_phy_c45_ids() returns -ENODEV,
  and mdiobus_scan_bus_c45(), __of_mdiobus_parse_phys() and
  sfp_sm_probe_phy() skip the PHY without a message.

- MMD 0 answers with a value that is not mostly Fs (some PHYs return 0
  there). The identifier loop finds no set bits, and the function returns 0
  with devices_in_package and mmds_present both 0. get_phy_device() would
  then create a phy_device with no MMDs. gpy_probe() would overwrite the
  live phydev->c45_ids with empty ids through phy_get_c45_ids() and keep
  probing.

Before this patch, the same condition returned -EIO and the failure was
visible.

Would it be better to map only a failure of the first (DEVS2) read, and to
return the error when DEVS1 fails after DEVS2 succeeded?

> +
> +			/* The MMD did not answer: treat it like a read of all
> +			 * Fs, which is what controllers that do not check the
> +			 * turnaround return, and go straight to the MMD 0
> +			 * probe below. Do not probe the remaining MMDs, each
> +			 * one costs two bus reads on a slow bus.
> +			 */
> +			devs_in_pkg = 0xffffffff;
> +			break;
> +		}
>  	}

[Severity: Low]

The comment says a failed MMD is treated like a read of all Fs. With the
break, can discovery give different results on the two kinds of
controller?

When the read returns all Fs, the loop condition moves on to the next MMD,
including the VEND1/VEND2 presence checks:

	for (i = 1; i < MDIO_MMD_NUM && (devs_in_pkg == 0 ||
	     (devs_in_pkg & 0x1fffffff) == 0x1fffffff); i++) {

After a mapped error, only MMD 0 is probed.

Take a package that does not implement MMD 1 but does implement later
MMDs, and that does not drive turnaround for an unimplemented DEVAD.

On a controller that does not check turnaround, it is found.

On a controller that does check turnaround, it gets -ENODEV unless it
answers on MMD 0, and it is skipped without a message. Examples are UniMAC
with the read_c45 from "net: mdio: mdio-bcm-unimac: Add Clause 45 support"
later in this series, or mvmdio XSMI. For an "ethernet-phy-ieee802.3-c45"
DT node it would be logged as missing, and the bus would register without
it.

The same applies when an earlier MMD already answered with devs_in_pkg ==
0 and a later MMD then fails turnaround.

These PHYs were not found on such controllers before the patch either,
because the scan failed with -EIO. The difference is that a visible failure
becomes a silent skip.

Would continuing the loop after a mapped error, as for 0xffff, give the
same results on both kinds of controller? The cost would be a bounded
number of extra reads.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123164835.1733304-1-florian.fainelli%40broadcom.com
Technical Details
Message-ID: <179553896595.3135.12489762291979495707@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370585-linux-kernel-netdev=dewy.ru
References: <20261123164835.1733304-2-florian.fainelli@broadcom.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370585-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v6 1/4] net: phy: Map C45 probe read errors to
 -ENODEV during bus scan
Date: Tue, 24 Nov 2026 16:49:25 +0000
Organization: Usenet Network
Message-ID: <179553896595.3135.12489762291979495707@kernel.org>
References: <20261123164835.1733304-2-florian.fainelli@broadcom.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4183384"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:aG9/zj6pXvRa8ObbG7LQXBc/bJA= sha256:6Y3Vjgkgch0go84AcIsCISpBB+5MulF4Ma2h4Iu6Ibo=
	sha1:LZsOW9ccX9hdi4q1OzzNQBjExu4= sha256:POqGWLAZ+eTrj3s2vVuU1c2wkNXu1EglnbSEJxQoLes=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id B4306125E2C; Tue, 24 Nov 2026 19:49:54 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ctiQOt2IYJKS;
	Tue, 24 Nov 2026 19:49:50 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-370585-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 189BC125E22; Tue, 24 Nov 2026 19:49:42 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 2E55040C78; Tue, 24 Nov 2026 16:49:29 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795538968;
	b=WdT+f6yPq/mv9rz2MiWxvFEeFiPax/mE1m6bIEJpBAJ22yEYgw+3GLEB2LTkGZtdpVbT
	 aR4sJbujvbmC/5BOafKl5GMSrg7Jk6tUKt/yN+oh/uzc7/GQzMpOyMfhvmY7K6oC4203u
	 rcIqbEEeZNYLWKQNCu1yA1VuJaK/NmYe7t33meFx7Y4L0cFGPqXWbtjgMjxMC86kM3u9o
	 hKQ3Ga0LfdepLOE2LJV1c5tFvMrbjv84YDMKoYzC03Cbk3wZxo43BbZ0fx0DHI6zXGrLd
	 vA8S2WhUxvGMNM0xSC9n8uUTf83NqEl83kfN7mrYgs6fW7NbXq1N5QIXoGJv/37aY/g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795538968;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=uTYBfpgEmNFEt26cRrwfLchBRDCus8OpqSq+AdE/ibE=;
	b=ny8ZfxxxEfN1w0o2dmfmMAWNv0okO0ZHt71PJMlIF7eCm2FKzU50bOlGqouCKS/E7Yun
	 8Y6NqGNuwwWPAGfSQn6dIZlwMhFo8V/djKZGzwLYTS3Jyk1NlafgaT3Jwca9amDN14N6B
	 BxuFftp4eaP27vN12k+nREkb/QSKVtO0U6MFHQAR4s+jqppDpte+N2CtVbCH5A1MO4idN
	 cys5tjwrryTLcBM6WEmExfMddTq9Z/VQovEEi4v4ZjedHCzWtkuf3wiLAqLzBZUeEMoNU
	 2upnMpJsToQ1n7mJSLi+xvnegfqehJQCrwsSxNb7PEoEP0//HxqXOZ3j8BUim98Re0g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QrZk390s;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 71599606A6B9;
	Tue, 24 Nov 2026 16:49:28 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QrZk390s
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795538967;
	b=B2+Aq2fpFft/9bcLyXWJnPbv1CosPOFYDHTmp1udKreA71cVOxthpFgux6BNVtAhjd0s
	 B3d9hRvyx/YEqthIi/N+CHtN/+7qqA+G93tXsY7oibFJSDGLJTgxc7PV4dZbu6UNvr/2u
	 +rY148354voaREh19u3Uj8LyMHTFW1baIgg/VLpph7sle0AlEBWIUm9yBnBst4xxRQvDS
	 BnAIbydFZ+kwZXMu1Vo6TqvBGBSYp9eMkq63lOrTzoD8dfDihX7hcgjyxeVAvlQx3M/+a
	 E0uj5Tw8xFh+QOZoVCRrpoZacVMQPdM1Z3OuKTvCWefUqqp2AApgPjqGgWoVEHHMnyg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795538967;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=uTYBfpgEmNFEt26cRrwfLchBRDCus8OpqSq+AdE/ibE=;
	b=0soOv+rsv5FN69tqOtJabatrw8r2ASopjZAw//lDbLCmJ6rIgfIHRqhN9hleyTdw6jWM
	 a30so1fGs4/wmQ7ObWIitDvh0EffWykdeYGvkav0H/qXKp/nynTG4/Lpzoya1PFuHEr3X
	 mRDURRrt2LWk1RD6uqCSGloxBxwWXSxCOv1KIal9SaHHXb8RUsXGdIydvq2++O2AxRhy4
	 PFsRJZ5gWiGZp6r1tvQu7BBSaUPrIUMtQS+FkbI3fCJWeVUkumjQvjlooXVdSdDGe1swJ
	 srHBFGUHml1ZT9l7knPArIdHwPcj5rrD2ocaA0J8WhNF1vXcifzVkPZ+O/tLSM2vbYg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QrZk390s;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87439606A33E;
	Tue, 24 Nov 2026 16:49:27 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 620001F000CA;
	Tue, 24 Nov 2026 16:49:26 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795538967;
	bh=uTYBfpgEmNFEt26cRrwfLchBRDCus8OpqSq+AdE/ibE=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=QrZk390sbgErIgN1mEeSQylLsXjdkG/49h0rsamx2y+4p4ftNrKePfnB4L4QEaQWf
	 cGQplUX53q+AayvD5v5merO1zsw1TIUGENnfijxrLZ51h6S/2+PUJg42hJkTPH5MVS
	 62eQE25B9E4m6VRxYMaa1ZvaijK8DX4alkSiitUNow1XULae6N8BvXbzmfJTYSZSH1
	 4LZuOeoOyBqlT3WCHh+yezQH4/UZ9E2FRkGr6tvhE6uR92XJawO/rRQ4V4JhF6Lk5i
	 YHRds4s7VhXecsvXEp/8Y4BR86vUi0V5ij6GTK9N7gC2FOY0jElY9ZsAxB9JSUrZZS
	 NyS5CKwl3FRpQ==
X-Cc: netdev@vger.kernel.org, nb@tipi-net.de, carlos.soto@broadcom.com,
 justin.chen@broadcom.com, opendmb@gmail.com,
 bcm-kernel-feedback-list@broadcom.com, andrew@lunn.ch, hkallweit1@gmail.com,
 linux@armlinux.org.uk, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org,
 kudzo51@gmail.com
X-In-Reply-To: <20261123164835.1733304-2-florian.fainelli@broadcom.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list