🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23209

Re: [PATCH net-next v6 3/3] net: phy: dap8211r: add PHY LED control support

#23209
From: netdev-bot+sashiko
Date: Thu, 26 Nov 2026 18:39
173 lines
13978 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

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

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] dap8211r_led_hw_control_get() (drivers/net/phy/dap8211r.c:322)
  builds its rules only from LED_x_CON (0xA00C + index, read at line…
- [Medium] Speculative, because it depends on the reset scope of
  DAP8211R_PHY_CON (0xA001) bit 15, which the code cannot show.

--

net: phy: dap8211r: add PHY LED control support

This commit adds LED support for the three LEDs on the DAP8211R PHY. It
adds a dap8211r_write_ext() helper and implements the led_brightness_set,
led_hw_is_supported, led_hw_control_set and led_hw_control_get callbacks.

> diff --git a/drivers/net/phy/dap8211r.c b/drivers/net/phy/dap8211r.c
> index 1fe20efd394d7..b029b53dc7ba2 100644
> --- a/drivers/net/phy/dap8211r.c
> +++ b/drivers/net/phy/dap8211r.c

[ ... ]

> @@ -114,6 +190,189 @@ static int dap8211r_modify_ext(struct phy_device *phydev, u16 reg, u16 mask, u16
>  	return ret;
>  }
>  
> +/**
> + * dap8211r_led_brightness_set() - Modify the LEDs common control register
> + * @phydev: PHY device structure
> + * @index: LED index
> + * @value: ON/OFF value for force mode of the LED
> + *
> + * Enables force mode and sets the LED to ON/OFF state.
> + * It will be disabled when hardware LED control is requested.

[ ... ]

> +	if (value != LED_OFF)
> +		set |= DAP8211R_LED_FORCE_ON(index);
> +
> +	return dap8211r_modify_ext(phydev, DAP8211R_LED_COMCON, mask, set);
> +}

[ ... ]

> +static int dap8211r_led_hw_control_set(struct phy_device *phydev, u8 index, unsigned long rules)
> +{

[ ... ]

> +	ret = dap8211r_write_ext(phydev, led_reg, led_mode);
> +	if (ret)
> +		return ret;
> +
> +	return dap8211r_modify_ext(phydev, DAP8211R_LED_COMCON,
> +				   DAP8211R_LED_FORCE_EN(index), 0);
> +}

[Severity: Medium]
Will this LED setup survive the next call to dap8211r_config_init()? The
driver keeps no copy of LED_COMCON or LED0..2_CON. config_init does a chip
software reset and then reprograms only RGMII_CON:

drivers/net/phy/dap8211r.c:dap8211r_config_init() {
    ...
	ret = dap8211r_modify_ext(phydev, DAP8211R_PHY_CON, DAP8211R_PHY_SW_RST, 0);
    ...
	ret = dap8211r_modify_ext(phydev, DAP8211R_RGMII_CON, DAP8211R_RGMII_CONFIG_MASK, set);
    ...
}

config_init runs again from phy_init_hw(). phy_attach_direct() calls
phy_init_hw(), so for MAC drivers that connect the PHY in ndo_open this
happens on every ifup. mdio_bus_phy_resume() calls it too. The LED
classdevs are registered only once, at probe.

DAP8211R_PHY_SW_RST might also reset 0xA00B-0xA00E to their defaults. In
that case the LEDs would go back to power-on behaviour after an
ifdown/ifup or a suspend/resume. Meanwhile ledtrig-netdev would keep
hw_control=true and its cached mode, or the LED core would keep its cached
brightness.

This depends on the reset scope of PHY_CON bit 15, and the code doesn't
show it. If the LED registers survive the reset, this doesn't apply.

Can the reset scope be confirmed? If the LED registers are cleared, could
they be restored after the reset?

> +static int dap8211r_led_hw_control_get(struct phy_device *phydev, u8 index, unsigned long *rules)
> +{

[ ... ]

> +	led_mode = dap8211r_read_ext(phydev, led_reg);
> +	if (led_mode < 0)
> +		return led_mode;

[Severity: Medium]
Should this also check DAP8211R_LED_FORCE_EN(index) in DAP8211R_LED_COMCON?

dap8211r_led_brightness_set() sets that bit and leaves LED_x_CON alone.
The old rules stay in the register while the LED is forced on or off. Only
dap8211r_led_hw_control_set() clears FORCE_EN.

Consider switching the trigger from netdev to none:

echo none > trigger
  led_trigger_remove()
    led_trigger_set(led_cdev, NULL)
      __led_trigger_set()
        led_set_brightness(led_cdev, LED_OFF)
          ...
            dap8211r_led_brightness_set()   <- FORCE_EN set, forced off

In the same way, writing a non-zero value to brightness while no trigger
is set leaves the LED forced on.

Then switch back to netdev:

echo netdev > trigger
  __led_trigger_set()
    flush_work(&led_cdev->set_brightness_work);
    netdev_trig_activate()

When the PHY has an attached netdev, netdev_trig_activate() does:

    trigger_data->hw_control = true;
    set_device_name(trigger_data, name, strlen(name));

    rc = led_cdev->hw_control_get(led_cdev, &mode);
    if (!rc)
        trigger_data->mode = mode;

On this path, set_device_name() skips set_baseline_state():

    /* Skip if we're called from netdev_trig_activate() and hw_control is true */
    if (!trigger_data->hw_control || led_get_trigger_data(trigger_data->led_cdev))
        set_baseline_state(trigger_data);

hw_control_set() is never called, so FORCE_EN stays set. hw_control_get()
then returns 0 with the stale LED_x_CON rules.

Does the LED then stay forced off (or on) while sysfs shows netdev as
offloaded with link/rx/tx set? It looks like it only recovers when a mode
attribute or device_name is written again.

That doesn't match the kernel-doc above either, which says force mode
"will be disabled when hardware LED control is requested".

For comparison, gpy_led_brightness_set() in mxl-gpy.c clears the hardware
rule register on LED_OFF:

	if (value == LED_OFF)
		return phy_write_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_LED(index), 0);

One option is for hw_control_get() to return no rules or an error when
FORCE_EN(index) is set. Another is for brightness_set() to clear LED_x_CON.
Would either of those work here?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125183742.3039752-1-a.shimko.dev%40gmail.com
Technical Details
Message-ID: <179571839263.3135.10510245952431569206@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372284-linux-kernel-netdev=dewy.ru
References: <20261125183742.3039752-4-a.shimko.dev@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372284-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v6 3/3] net: phy: dap8211r: add PHY LED control support
Date: Thu, 26 Nov 2026 18:39:52 +0000
Organization: Usenet Network
Message-ID: <179571839263.3135.10510245952431569206@kernel.org>
References: <20261125183742.3039752-4-a.shimko.dev@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="534643"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Cm7iy9qdOqLq13Cc+xvFNaYJP+g= sha256:8SCF8+UlRftDHC60aEJHWII9p4xKPhNO3QQRS9bFeEw=
	sha1:NNF4Di1xZW+AvyMHCIUELxSY01M= sha256:OZXh992v4baVNwd886rn04IW1m02xYi9uaCWQxvsJBI=
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 22A84125EF3; Thu, 26 Nov 2026 21:40:17 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 yQaVjNssOd0N;
	Thu, 26 Nov 2026 21:40:12 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-372284-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 F3005125EF2; Thu, 26 Nov 2026 21:40:01 +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 6225A3A05D; Thu, 26 Nov 2026 18:39:56 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail;
	t=1795718395;
	b=Jp04t3d76jSvfBzSPrGYXHvP4oC5OYRTcAIeB/ZUDvl9YlCXLAGjaV9wl2eSGa3Y5s8V
	 JQ24RfZ6ob54OHwyEFoax651102qygIY88ZEj61oblNiwlAR4ZYbg55mxgOIsUd1Xj7hh
	 iOgQSHzHzdTC5N8FCfI98hOJoP6eaPaiiqRll5A341B2Rn/US1nJ8N45waIjVcBYPpTVO
	 Tw1jTJB0/hQdM6CyMatHUS7yg/fZphdGahjeRPkYuyrc+1013TJFm2M2rnL3rOQwYwN8I
	 rs4hCnYflNCfNuqhEcgHu2Ct4nSAtDQuoZSAdc9n1jaNFzeSUxCJVfVyY3hijuPw9UA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795718395;
	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=YSTzqRwhJELRsBttl0aXsnSnkGgl9o+9N6c89t9SOdc=;
	b=vOG8LbsrX/KYKYV2MUJFB1ck7f5mErmZB/p/aavF9g75kvSrCzjmsCIifH+enSDuG8Z6
	 Zs1oEmK7L0yFa5xzOjmqa/Cnyf0ji+XfeNcdQCfZ/pKh5u+mD4Rldn8m7E109zP6FFsPq
	 FBFmHJRboH7Tqa5tYgz1P0O+MX26ldhL0vK9cE8+p9BHgOlmur426Ha7cLktuDiRHRtzz
	 dWF1y+eHgtaY3AJUryUDYCralFJZOfnaFxynEdIemQBnuqyL8PYqlTZxqp3omCyJC8Po0
	 /C9M66A3Mb5RznuR1oTC6qqvuN/7O8kv9P81KVUQbKIZTBk60+of1bOVst9hWLKvBAA==
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=UdwaDnjP;
	arc=fail 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 EA02A606A335;
	Thu, 26 Nov 2026 18:39:54 +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=UdwaDnjP
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=1795718394;
	b=MSctGsE7UjU84/bnHdIJD6XrPJ7Ew6/gkZ6FhyvsS6IcSN/N03nlXjT1IuPXk3OPIESF
	 ze2EEiwX8GtDOtYbEECSVr1X4C9rDSW1yL5VGw3QCFPIaiWOeqFdWEyNxaZX7lACDtXW6
	 GCik/NCFA8y5AN0JNRteUd5XqVF2aXyVHiRYo40W5qxFrPvhSgr2dcaAIbFxWp3VCku3z
	 n8bIxEeRuhrdFk9dxWIQJx30dqoU9liBo+oUpimN2SxQdgVlkDXiLeCOLTYJqSwSN6LpU
	 OcOiNiwJkiVKyAF1tZei6JEOz7NVoXPaDDrxYU60VGIKQX3Vajyt1xy7V+YR7+E5/1w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795718394;
	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=YSTzqRwhJELRsBttl0aXsnSnkGgl9o+9N6c89t9SOdc=;
	b=eR8bjzs3CnQTepoAx5i9GfPgmWP4djP4qSSM7Ja4zituHBKjifD7cJUlMFdbwtUfJr8H
	 gI3W0Xogz3WuuNCNA1KyoAKkIQuwxqOP4py2cslo67Z497VBYBuPj0uGYj2UPKN1P3AzY
	 E6DKYxONyZEwnQTK0YS3mbjbHRsH5830tyz/x/uRKKHQxvh88pObBGRsorpqaTJTTJEPa
	 wp4Ta3WeCMhyM/0pDh2tKAntsF2df8IRqiC6wVMsw9NbaxT/sEiBvTfbSrSRxTozvMX+k
	 i0YpV4jw22BQ/VraWDDoHUn7xPv3jOZcN/QHxLWzLih1ZwjbmkeHSmYZ4tyNQX2g6DA==
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=UdwaDnjP;
	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 12AE7606A31C;
	Thu, 26 Nov 2026 18:39:54 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 174701F000C0;
	Thu, 26 Nov 2026 18:39:53 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795718393;
	bh=YSTzqRwhJELRsBttl0aXsnSnkGgl9o+9N6c89t9SOdc=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=UdwaDnjPGZvf8z73Rf0Dsyl1eO9t1u2CZq+QPxqNMz6P8icWAyxOcT3CgZt5DobFg
	 T0TJcK4TCh8QfpreXQHh3aOUmOEDq/LZZ8IrWd33hyxVRkOFHVRA8EySgwf3JWga8h
	 NiJNRBheXyUnpNThBwUuqShPUidg+Xg+f+OjAcJKCclS8yQp6oNZw5nhYpsfIBeOJM
	 839h33IXwnz8sB1GtEc8bXGPlxdpu01KamUHYxv0+VaPbos02oZEyMrzXwimnl9OJq
	 V3sJ6+1NbO7Z8zjvURLXbo3D2G6wwjC6/9YbJrexCyAydwSF8h0KvUZIolEkXruvj4
	 1HRx0zqE8ls2g==
X-Cc: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
 davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
 robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
 maxime.chevallier@bootlin.com, pavel@ucw.cz, linux-kernel@vger.kernel.org,
 devicetree@vger.kernel.org, linux-leds@vger.kernel.org,
 netdev@vger.kernel.org
X-In-Reply-To: <20261125183742.3039752-4-a.shimko.dev@gmail.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