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

From: Artem Shimko

Date: Thu Nov 26 2026 - 14:47:47 EST


On Thu, Nov 26, 2026 at 9:39 PM <netdev-bot+sashiko@xxxxxxxxxx> wrote:
>
> 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.


> [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;

Confirmed on real hardware: asserting DAP8211R_PHY_SW_RST (bit 15 of
PHY_CON 0xA001) across ifdown/ifup cycles preserves the contents of
LED_COMCON (0xA00B) and LED0..2_CON (0xA00C..0xA00E). Therefore, no
saving or restoring of the LED registers in dap8211r_config_init() is
needed.

> [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?

agreed

pw-bot: cr