[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJq09z6zGVb-TwYqWaT7BYvXGRz=0MEN+X0hy613V8a_CX5U5A@mail.gmail.com>
Date: Mon, 8 Jan 2024 02:47:22 -0300
From: Luiz Angelo Daros de Luca <luizluca@...il.com>
To: Christian Marangi <ansuelsmth@...il.com>
Cc: linus.walleij@...aro.org, alsi@...g-olufsen.dk, andrew@...n.ch,
f.fainelli@...il.com, olteanv@...il.com, davem@...emloft.net,
edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
arinc.unal@...nc9.com, netdev@...r.kernel.org
Subject: Re: [RFC net-next 0/2] net: dsa: realtek: fix LED support for rtl8366rb
> > Hi Christian,
> >
> > I tried to implement something close to your work with qca8k and LED
> > hw control. However, I couldn't find a solution that would work with
> > the existing API. The HW led configuration in realtek switches is
> > shared with all LEDs in a group. Before activating the hw control, all
> > LEDs in the same group must share the same netdev trigger config, use
> > the correct device and also use a compatible netdev trigger settings.
> > In order to check that, I would need to expose some internal netdev
> > trigger info that is only available through sysfs (and I believe sysfs
> > is not suitable to be used from the kernel). Even if I got all LEDs
> > with the correct settings, I would need to atomicly switch all LEDs to
> > use the hw control or, at least, I would need to stop all update jobs
> > because if the OS changes a LED brightness, it might be interpreted as
> > the OS disabling the hw control:
> >
>
> Saddly we still don't have the concept of LED groups, but from what I
> notice 99% of the time switch have limitation of HW control but single
> LED can still be controlled separately.
Individually, I can only turn them on/off. That is enough for software
control but not for hardware control. When you set a LED group to
blink on link activity, all LEDs will be affected.
> With this limitation you can use the is_supported function and some priv
> struct to enforce and reject unsupported configuration.
> netdev trigger will then fallback to software in this case. (I assume on
> real world scenario to have all the LED in the group to be set to the
> common rule set resulting in is_supported never rejecting it)
Maybe I wasn't clear enough about what the HW provides me. I have 4
16-bit registers:
REG1: a single blink rate used by all LEDs in all groups
REG2: configures the trigger for each group, 4-bit each, with one
special 4-bit value being "fixed", equivalent to "none" in Linux LED
trigger
REG3: bitmap to manually control LEDs in group 0 and 1 only when their
group trigger is configured as fixed.
REG3: bitmap to manually control LEDs in group 2 and 3 only when their
group trigger is configured as fixed.
And that's it.
I can keep track of the netdev trigger form calls to "is_supported
function". I can also check if all LEDs are still using the netdev
trigger. However, I cannot detect if the user changed the device to
something else not related to the corresponding port as the netdev
trigger will not check the compatibility if the device does not match.
I would still need to expose at least some of the netdev trigger
internal data.
> Also consider this situation, it's the first LED touched that enables HW
> control that drive everything. LED configuration are not enabled all at
> once. You can totally introduce a priv struct that cache the current
> modes and on the other LEDs make sure the requested mode match the cache
> one.
Considering that I can externally check that all LEDs have a netdev
trigger settings compatible with the HW control, once the last LED is
configured, I could return true for the hw_control_is_supported. When
hw_control_set is called, I could configure the hardware accordingly,
which would affect all LEDs in that group. However, the OS will still
use the software control for the other LEDs in that same group. That
way, once a netdev event turns off one LED, that message is the same
clue the LED driver receives to disable the hardware control. It will
undo the hardware change I just made. I could use
led_brightness_set(OFF) on those other LEDs during hw_control_set to
disable their software controlled triggers (actually changing the
trigger to "none"), but it might be a race condition of who stops the
other. And even then, the other LEDs will keep an inconsistent
configuration state, with "none" as their trigger.
I need:
1) expose the required info or allow an external caller to test a LED
configuration for compatibility (avoiding recursion).
2) something from hw_control_set() that stops the software triggers in
other LEDs without destroying their configuration.
3) something that could enable hw_control on those other LEDs
> And I guess this limitation should be printed and documented in DT.
>
> > /*
> > ...
> > * Deactivate hardware blink control by setting brightness to LED_OFF via
> > * the brightness_set() callback.
> > *
> > ...
> > */
> > int (*hw_control_set)(struct led_classdev *led_cdev,
> > unsigned long flags);
> >
> > Do you have any idea how to implement it?
> >
> > BTW, during my tests with a single LED, ignoring the LED group
> > situation, I noticed that the OS was sending a brightness_set(LED_OFF)
> > after I changed the trigger to netdev, a moment after hw_control_set
> > was called. It doesn't make sense to enable hw control just to disable
> > it afterwards. The call came from set_brightness_delayed(). Maybe it
> > is because my test device is pretty slow and the previous trigger
> > event always gets queued. Touching any settings after that worked as
> > expected without the spurious brightness_set(LED_OFF). Did you see
> > something like this?
> >
>
> Consider that brightness_set is called whatever a trigger is changed,
> the logic is in the generic LED handling. Setting OFF and then enabling
> hw control should not change a thing. In other driver tho I notice an
> extra measure is needed to reset any HW control rule already applied by
> default.
It would be OK to call brightness_set(LED_OFF) if that is guaranteed
to happen before hw_control_set(). The problem is that the
brightness_set(LED_OFF) happens *after* hw_control_set() was called.
It looks like a race condition.
Regards,
Luiz
Powered by blists - more mailing lists