Skip to contentSkip to conversation

Adds support for PHY LEDs with offload triggers

RFC PATCH Superseded Ansuel Smith 4 participants 19 messages Nov 7, 2021 – Nov 8, 2021

Subsystems (7)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Ansuel Smith

author maintainer
#0 lore raw

cover Adds support for PHY LEDs with offload triggers

This is another attempt in adding support for PHY LEDs. Most of the times Switch/PHY have connected multiple LEDs that are controlled by HW based on some rules/event. Currently we lack any support for a generic way to control the HW part and normally we either never implement the feature or only add control for brightness or hw blink.

This is based on Marek idea of providing some API to cled but use a different implementation that in theory should be more generilized.

The current idea is:
- LED driver implement 2 API (trigger and configure). They are used to put the LED in offload mode and to configure the various trigger.
- We have offload triggers that are used to expose to userspace the supported offload triggers and set the offload mode on trigger activation.
- The PHY will declare the supported offload triggers using the linux,supported-offload-triggers binding in the dts.
- Only supported triggers from linux,supported-offload-triggers will be exposed by the offload trigger to userspace via sysfs. Other won't be configurable as they are not supported by the LED driver.
- The LED driver will set how the Offload mode is activated/disabled and will set a configure function to set each supported offload triggers. This function provide 3 different mode enable/disable/read that will enable or disable the offload trigger or read the current status.
- On offload trigger activation, only the offload mode is triggered but the offload triggers are not configured. This means that the LED will run in offload mode but will have the default rules/event set by the device by default. To change this the user will have to operate via userspace (or we can consider adding another binding in the dts to declare also a default trigger configuration)

Each LED driver will have to declare explicit support for the offload trigger (or return not supported error code) as we pass a u32 flag that the LED driver will elaborate and understand what is referring to (based on the current active trigger).

I posted a user for this new implementation that will benefit from this and will add a big feature to it. Currently qca8k can have up to 3 LEDs connected to each PHY port and we have some device that have only one of them connected and the default configuration won't work for that.

Ansuel Smith (5):
leds: permit to declare supported offload triggers
leds: add function to configure offload leds
leds: trigger: add offload-phy-activity trigger
net: dsa: qca8k: add LEDs support
dt-bindings: net: dsa: qca8k: add LEDs definition example

Marek Behún (1):
leds: trigger: add API for HW offloading of triggers

 .../devicetree/bindings/net/dsa/qca8k.yaml    |  30 ++
 Documentation/leds/leds-class.rst             |  38 ++
 drivers/leds/led-class.c                      |  15 +-
 drivers/leds/led-triggers.c                   |   1 +
 drivers/leds/trigger/Kconfig                  |  35 ++
 drivers/leds/trigger/Makefile                 |   1 +
 .../trigger/ledtrig-offload-phy-activity.c    | 151 ++++++++
 drivers/net/dsa/Kconfig                       |   9 +
 drivers/net/dsa/Makefile                      |   1 +
 drivers/net/dsa/qca8k-leds.c                  | 361 ++++++++++++++++++
 drivers/net/dsa/qca8k.c                       |   4 +-
 drivers/net/dsa/qca8k.h                       |  64 ++++
 include/linux/leds.h                          |  76 ++++
 13 files changed, 783 insertions(+), 3 deletions(-)
 create mode 100644 drivers/leds/trigger/ledtrig-offload-phy-activity.c
 create mode 100644 drivers/net/dsa/qca8k-leds.c
Signature · 1 line
2.32.0
author maintainer
#1 lore raw

RFC PATCH 1/6 leds: trigger: add API for HW offloading of triggers

From: Marek Behún <[email protected]>

Add method trigger_offload() and member variable offloaded to struct led_classdev. Add helper functions led_trigger_offload() and led_trigger_offload_stop().

The trigger_offload() method, when implemented by the LED driver, should be called (via led_trigger_offload() function) from trigger code wanting to be offloaded at the moment when configuration of the trigger changes.

If the trigger is successfully offloaded, this method returns 0 and the trigger does not have to blink the LED in software.

If the trigger with given configuration cannot be offloaded, the method should return -EOPNOTSUPP, in which case the trigger must blink the LED in SW.

The second argument to trigger_offload() being false means that the offloading is being disabled. In this case the function must return 0, errors are not permitted.

An additional config CONFIG_LEDS_OFFLOAD_TRIGGERS is added to add support for these special trigger offload driven.

---
 Documentation/leds/leds-class.rst | 22 +++++++++++++++++++++
 drivers/leds/led-triggers.c       |  1 +
 drivers/leds/trigger/Kconfig      | 10 ++++++++++
 include/linux/leds.h              | 33 +++++++++++++++++++++++++++++++
 4 files changed, 66 insertions(+)
Documentation/leds/leds-class.rst +22 -0
index cd155ead8703..035a738afc4a 100644
@@ -169,6 +169,28 @@ Setting the brightness to zero with brightness_set() callback function
 should completely turn off the LED and cancel the previously programmed
 hardware blinking function, if any.
 
+Hardware offloading of LED triggers
+===================================
+
+Some LEDs can offload SW triggers to hardware (for example a LED connected to
+an ethernet PHY or an ethernet switch can be configured to blink on activity on
+the network, which in software is done by the netdev trigger).
+
+To do such offloading, LED driver must support the this and a deficated offload
+trigger must be used. The LED must implement the trigger_offload() method and
+the trigger code must try to call this method (via led_trigger_offload()
+function) when configuration of the trigger (trigger_data) changes.
+
+The implementation of the trigger_offload() method by the LED driver must return
+0 if the offload is successful and -EOPNOTSUPP if the requested trigger
+configuration is not supported and the trigger should be executed in software.
+If trigger_offload() returns negative value, the triggering will be done in
+software, so any active offloading must also be disabled.
+
+If the second argument (enable) to the trigger_offload() method is false, any
+active HW offloading must be deactivated. In this case errors are not permitted
+in the trigger_offload() method.
+
 
 Known Issues
 ============
drivers/leds/led-triggers.c +1 -0
index 072491d3e17b..281c52914f42 100644
@@ -179,6 +179,7 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
 
 		cancel_work_sync(&led_cdev->set_brightness_work);
 		led_stop_software_blink(led_cdev);
+		led_trigger_offload_stop(led_cdev);
 		if (led_cdev->trigger->deactivate)
 			led_cdev->trigger->deactivate(led_cdev);
 		device_remove_groups(led_cdev->dev, led_cdev->trigger->groups);
drivers/leds/trigger/Kconfig +10 -0
index dc6816d36d06..c073e64e0a37 100644
@@ -9,6 +9,16 @@ menuconfig LEDS_TRIGGERS
 
 if LEDS_TRIGGERS
 
+config LEDS_OFFLOAD_TRIGGERS
+	bool "LED Offload Trigger support"
+	help
+	  This option enabled offload triggers support used by leds that
+	  can be driven in HW by declaring some specific triggers.
+	  A offload trigger will expose a sysfs dir to configure the
+	  different blinking trigger and the available hw trigger.
+
+	  If unsure, say Y.
+
 config LEDS_TRIGGER_TIMER
 	tristate "LED Timer Trigger"
 	help
include/linux/leds.h +33 -0
index ba4861ec73d3..949ab461287f 100644
@@ -154,6 +154,13 @@ struct led_classdev {
 
 	/* LEDs that have private triggers have this set */
 	struct led_hw_trigger_type	*trigger_type;
+
+#ifdef CONFIG_LEDS_OFFLOAD_TRIGGERS
+	int			offloaded;
+	/* some LEDs cne be driven by HW */
+	int			(*trigger_offload)(struct led_classdev *led_cdev,
+						   bool enable);
+#endif
 #endif
 
 #ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED
@@ -409,6 +416,32 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
 	return led_cdev->trigger_data;
 }
 
+#ifdef CONFIG_LEDS_OFFLOAD_TRIGGERS
+static inline int led_trigger_offload(struct led_classdev *led_cdev)
+{
+	int ret;
+
+	if (!led_cdev->trigger_offload)
+		return -EOPNOTSUPP;
+
+	ret = led_cdev->trigger_offload(led_cdev, true);
+	led_cdev->offloaded = !ret;
+
+	return ret;
+}
+
+static inline void led_trigger_offload_stop(struct led_classdev *led_cdev)
+{
+	if (!led_cdev->trigger_offload)
+		return;
+
+	if (led_cdev->offloaded) {
+		led_cdev->trigger_offload(led_cdev, false);
+		led_cdev->offloaded = false;
+	}
+}
+#endif
+
 /**
  * led_trigger_rename_static - rename a trigger
  * @name: the new trigger name
Signature · 1 line
2.32.0
reviewer
#2 lore raw

Re: [RFC PATCH 1/6] leds: trigger: add API for HW offloading of triggers

Hi,

Quoted 38 lines · Ansuel Smith

From: Marek Behún <[email protected]>

Add method trigger_offload() and member variable offloaded to struct led_classdev. Add helper functions led_trigger_offload() and led_trigger_offload_stop().

The trigger_offload() method, when implemented by the LED driver, should be called (via led_trigger_offload() function) from trigger code wanting to be offloaded at the moment when configuration of the trigger changes.

If the trigger is successfully offloaded, this method returns 0 and the trigger does not have to blink the LED in software.

If the trigger with given configuration cannot be offloaded, the method should return -EOPNOTSUPP, in which case the trigger must blink the LED in SW.

The second argument to trigger_offload() being false means that the offloading is being disabled. In this case the function must return 0, errors are not permitted.

An additional config CONFIG_LEDS_OFFLOAD_TRIGGERS is added to add support for these special trigger offload driven.

---
  Documentation/leds/leds-class.rst | 22 +++++++++++++++++++++
  drivers/leds/led-triggers.c       |  1 +
  drivers/leds/trigger/Kconfig      | 10 ++++++++++
  include/linux/leds.h              | 33 +++++++++++++++++++++++++++++++
  4 files changed, 66 insertions(+)
Documentation/leds/leds-class.rst +0 -0
index cd155ead8703..035a738afc4a 100644

Documentation/leds/leds-class.rst Setting the brightness to zero with brightness_set() callback function · line 175

Quoted 7 lines
Documentation/leds/leds-class.rst +4 -0
@@ -169,6 +169,28 @@ Setting the brightness to zero with brightness_set() callback function
  should completely turn off the LED and cancel the previously programmed
  hardware blinking function, if any.
 
+Hardware offloading of LED triggers
+===================================
+
+Some LEDs can offload SW triggers to hardware (for example a LED connected to

Better to s/SW/software/ and s/HW/hardware/ throughout the documentation file and Kconfig file(s).

Documentation/leds/leds-class.rst Setting the brightness to zero with brightness_set() callback function · line 179

Quoted 4 lines
Documentation/leds/leds-class.rst +4 -0
+an ethernet PHY or an ethernet switch can be configured to blink on activity on
+the network, which in software is done by the netdev trigger).
+
+To do such offloading, LED driver must support the this and a deficated offload

drop: the dedicated

Documentation/leds/leds-class.rst Setting the brightness to zero with brightness_set() callback function · line 180

Quoted 1 line
Documentation/leds/leds-class.rst +1 -0
+trigger must be used. The LED must implement the trigger_offload() method and

How does an LED implement the trigger_offload() method? They don't have very much logic in them AFAIK.

Quoted 19 lines
Documentation/leds/leds-class.rst +12 -0
+the trigger code must try to call this method (via led_trigger_offload()
+function) when configuration of the trigger (trigger_data) changes.
+
+The implementation of the trigger_offload() method by the LED driver must return
+0 if the offload is successful and -EOPNOTSUPP if the requested trigger
+configuration is not supported and the trigger should be executed in software.
+If trigger_offload() returns negative value, the triggering will be done in
+software, so any active offloading must also be disabled.
+
+If the second argument (enable) to the trigger_offload() method is false, any
+active HW offloading must be deactivated. In this case errors are not permitted
+in the trigger_offload() method.
 
 
drivers/leds/trigger/Kconfig +0 -0
index dc6816d36d06..c073e64e0a37 100644

drivers/leds/trigger/Kconfig menuconfig LEDS_TRIGGERS · line 15

Quoted 7 lines
drivers/leds/trigger/Kconfig +4 -0
@@ -9,6 +9,16 @@ menuconfig LEDS_TRIGGERS
 
  if LEDS_TRIGGERS
 
+config LEDS_OFFLOAD_TRIGGERS
+	bool "LED Offload Trigger support"
+	help
+	  This option enabled offload triggers support used by leds that

LEDs

drivers/leds/trigger/Kconfig menuconfig LEDS_TRIGGERS · line 18

Quoted 3 lines
drivers/leds/trigger/Kconfig +3 -0
+	  can be driven in HW by declaring some specific triggers.
+	  A offload trigger will expose a sysfs dir to configure the
+	  different blinking trigger and the available hw trigger.

Are the sysfs file values/meanings documented here? I seem to have missed them.

drivers/leds/trigger/Kconfig menuconfig LEDS_TRIGGERS · line 21

Quoted 3 lines
drivers/leds/trigger/Kconfig +3 -0
+
+	  If unsure, say Y.
+

thanks.

Signature · 1 line
~Randy
author maintainer
#3 lore raw

Re: [RFC PATCH 1/6] leds: trigger: add API for HW offloading of triggers

Quoted 58 lines · Randy Dunlap

Hi,

Quoted 38 lines · Ansuel Smith

From: Marek Behún <[email protected]>

Add method trigger_offload() and member variable offloaded to struct led_classdev. Add helper functions led_trigger_offload() and led_trigger_offload_stop().

The trigger_offload() method, when implemented by the LED driver, should be called (via led_trigger_offload() function) from trigger code wanting to be offloaded at the moment when configuration of the trigger changes.

If the trigger is successfully offloaded, this method returns 0 and the trigger does not have to blink the LED in software.

If the trigger with given configuration cannot be offloaded, the method should return -EOPNOTSUPP, in which case the trigger must blink the LED in SW.

The second argument to trigger_offload() being false means that the offloading is being disabled. In this case the function must return 0, errors are not permitted.

An additional config CONFIG_LEDS_OFFLOAD_TRIGGERS is added to add support for these special trigger offload driven.

---
  Documentation/leds/leds-class.rst | 22 +++++++++++++++++++++
  drivers/leds/led-triggers.c       |  1 +
  drivers/leds/trigger/Kconfig      | 10 ++++++++++
  include/linux/leds.h              | 33 +++++++++++++++++++++++++++++++
  4 files changed, 66 insertions(+)
Documentation/leds/leds-class.rst +0 -0
index cd155ead8703..035a738afc4a 100644

Documentation/leds/leds-class.rst Setting the brightness to zero with brightness_set() callback function · line 174

Quoted 6 lines
Documentation/leds/leds-class.rst +4 -0
@@ -169,6 +169,28 @@ Setting the brightness to zero with brightness_set() callback function
  should completely turn off the LED and cancel the previously programmed
  hardware blinking function, if any.
+Hardware offloading of LED triggers
+===================================
+
+Some LEDs can offload SW triggers to hardware (for example a LED connected to

Better to s/SW/software/ and s/HW/hardware/ throughout the documentation file and Kconfig file(s).

Documentation/leds/leds-class.rst Setting the brightness to zero with brightness_set() callback function · line 179

Quoted 4 lines
Documentation/leds/leds-class.rst +4 -0
+an ethernet PHY or an ethernet switch can be configured to blink on activity on
+the network, which in software is done by the netdev trigger).
+
+To do such offloading, LED driver must support the this and a deficated offload

drop: the dedicated

Quoted 5 lines

Documentation/leds/leds-class.rst Setting the brightness to zero with brightness_set() callback function · line 180

Quoted 1 line
Documentation/leds/leds-class.rst +1 -0
+trigger must be used. The LED must implement the trigger_offload() method and

How does an LED implement the trigger_offload() method? They don't have very much logic in them AFAIK.

With trigger_offload here I meand activating that mode. So the function will just do the required operation to set the LED in that specific mode. Nothing else.

Quoted 27 lines
Quoted 19 lines
Documentation/leds/leds-class.rst +12 -0
+the trigger code must try to call this method (via led_trigger_offload()
+function) when configuration of the trigger (trigger_data) changes.
+
+The implementation of the trigger_offload() method by the LED driver must return
+0 if the offload is successful and -EOPNOTSUPP if the requested trigger
+configuration is not supported and the trigger should be executed in software.
+If trigger_offload() returns negative value, the triggering will be done in
+software, so any active offloading must also be disabled.
+
+If the second argument (enable) to the trigger_offload() method is false, any
+active HW offloading must be deactivated. In this case errors are not permitted
+in the trigger_offload() method.
 
 
drivers/leds/trigger/Kconfig +0 -0
index dc6816d36d06..c073e64e0a37 100644

drivers/leds/trigger/Kconfig menuconfig LEDS_TRIGGERS · line 13

Quoted 5 lines
drivers/leds/trigger/Kconfig +4 -0
@@ -9,6 +9,16 @@ menuconfig LEDS_TRIGGERS
  if LEDS_TRIGGERS
+config LEDS_OFFLOAD_TRIGGERS
+	bool "LED Offload Trigger support"
+	help
+	  This option enabled offload triggers support used by leds that

LEDs

Quoted 7 lines

drivers/leds/trigger/Kconfig menuconfig LEDS_TRIGGERS · line 18

Quoted 3 lines
drivers/leds/trigger/Kconfig +3 -0
+	  can be driven in HW by declaring some specific triggers.
+	  A offload trigger will expose a sysfs dir to configure the
+	  different blinking trigger and the available hw trigger.

Are the sysfs file values/meanings documented here? I seem to have missed them.

The trigger should expose them and describe them. The idea is that the LED driver need to explicitly support the trigger and the LED driver will comunicate the trigger the supported offload trigger. And only then the trigger will make them available via sysfs and set them configurable. So all the sysfs stuff should be put in the trigger Kconfig help. This is just to add support for the entire offload part.

Quoted 7 lines

drivers/leds/trigger/Kconfig menuconfig LEDS_TRIGGERS · line 21

Quoted 3 lines
drivers/leds/trigger/Kconfig +3 -0
+
+	  If unsure, say Y.
+

thanks.

Signature · 1 line
~Randy
Signature · 1 line
	Ansuel
author maintainer
#4 lore raw

RFC PATCH 2/6 leds: permit to declare supported offload triggers

In reply to Ansuel Smith

With LEDs that can be offload driven, permit to declare supported triggers in the dts and add them to the cled struct to be used by the related offload trigger. This is particurally useful for phy that have support for HW blinking on tx/rx traffic or based on the speed link.

---
 Documentation/leds/leds-class.rst |  4 ++++
 drivers/leds/led-class.c          | 15 ++++++++++++++-
 include/linux/leds.h              |  5 ++++-
 3 files changed, 22 insertions(+), 2 deletions(-)
Documentation/leds/leds-class.rst +4 -0
index 035a738afc4a..ab50b58d6a21 100644
@@ -191,6 +191,10 @@ If the second argument (enable) to the trigger_offload() method is false, any
 active HW offloading must be deactivated. In this case errors are not permitted
 in the trigger_offload() method.
 
+LEDs can declare the supported offload trigger using linux,supported-offload-triggers
+binding in the dts. This is just an array of string that will be used by any
+offload trigger to check the supported triggers and configure the LED offload mode
+and bheaviour.
 
 Known Issues
 ============
drivers/leds/led-class.c +14 -1
index f4bb02f6e042..56f75e70b81e 100644
@@ -339,7 +339,7 @@ int led_classdev_register_ext(struct device *parent,
 	char composed_name[LED_MAX_NAME_SIZE];
 	char final_name[LED_MAX_NAME_SIZE];
 	const char *proposed_name = composed_name;
-	int ret;
+	int count, ret;
 
 	if (init_data) {
 		if (init_data->devname_mandatory && !init_data->devicename) {
@@ -358,6 +358,19 @@ int led_classdev_register_ext(struct device *parent,
 			if (fwnode_property_present(init_data->fwnode,
 						    "retain-state-shutdown"))
 				led_cdev->flags |= LED_RETAIN_AT_SHUTDOWN;
+
+			if (fwnode_property_present(init_data->fwnode,
+						    "linux,supported-offload-triggers")) {
+				count = fwnode_property_string_array_count(
+				    init_data->fwnode, "linux,supported-offload-triggers");
+
+				led_cdev->supported_offload_triggers =
+				    kcalloc(count, sizeof(char *), GFP_KERNEL);
+				fwnode_property_read_string_array(
+				    init_data->fwnode, "linux,supported-offload-triggers",
+				    led_cdev->supported_offload_triggers, count);
+				led_cdev->supported_offload_triggers_count = count;
+			}
 		}
 	} else {
 		proposed_name = led_cdev->name;
include/linux/leds.h +4 -1
index 949ab461287f..ff1f903f8079 100644
@@ -157,7 +157,10 @@ struct led_classdev {
 
 #ifdef CONFIG_LEDS_OFFLOAD_TRIGGERS
 	int			offloaded;
-	/* some LEDs cne be driven by HW */
+	/* LEDs can have multiple offload triggers */
+	int			supported_offload_triggers_count;
+	const char		**supported_offload_triggers;
+	/* some LEDs may be able to offload some SW triggers to HW */
 	int			(*trigger_offload)(struct led_classdev *led_cdev,
 						   bool enable);
 #endif
Signature · 1 line
2.32.0
#5 lore raw

Re: [RFC PATCH 2/6] leds: permit to declare supported offload triggers

Quoted 6 lines · On Sun, 7 Nov 2021 18:57:14 +0100 Ansuel Smith <[email protected]> wrote:

With LEDs that can be offload driven, permit to declare supported triggers in the dts and add them to the cled struct to be used by the related offload trigger. This is particurally useful for phy that have support for HW blinking on tx/rx traffic or based on the speed link.

NAK. The device-tree shouldn't define this, only the LED's function as designated by the manufacturer of the device.

Marek

author maintainer
#6 lore raw

Re: [RFC PATCH 2/6] leds: permit to declare supported offload triggers

Quoted 8 lines · Marek Behún
Quoted 5 lines · On Sun, 7 Nov 2021 18:57:14 +0100 Ansuel Smith <[email protected]> wrote:

With LEDs that can be offload driven, permit to declare supported triggers in the dts and add them to the cled struct to be used by the related offload trigger. This is particurally useful for phy that have support for HW blinking on tx/rx traffic or based on the speed link.

Quoted 6 lines
Quoted 1 line

NAK. The device-tree shouldn't define this, only the LED's function as designated by the manufacturer of the device.

Marek

Sure I will add a way to ask the led driver if the trigger is supported and report it.

Signature · 1 line
	Ansuel
maintainer
#7 lore raw

Re: [RFC PATCH 2/6] leds: permit to declare supported offload triggers

Quoted 11 lines · Ansuel Smith
Quoted 10 lines · Marek Behún
Quoted 6 lines · On Sun, 7 Nov 2021 18:57:14 +0100 Ansuel Smith <[email protected]> wrote:

With LEDs that can be offload driven, permit to declare supported triggers in the dts and add them to the cled struct to be used by the related offload trigger. This is particurally useful for phy that have support for HW blinking on tx/rx traffic or based on the speed link.

Quoted 7 lines
Quoted 4 lines

NAK. The device-tree shouldn't define this, only the LED's function as designated by the manufacturer of the device.

Marek

Sure I will add a way to ask the led driver if the trigger is supported and report it.

Yes, you need some way for the PHY/MAC driver to enumerate what it can do.

I've not looked at v2 yet...

Andrew

author maintainer
#8 lore raw

RFC PATCH 3/6 leds: add function to configure offload leds

In reply to Ansuel Smith

Add configure_offload helper to configure how the LED should work in offload mode. The function require to support the particular trigger and will use the passed offload_flags to elaborate the data and apply the correct configuration. This function will then be used by the offload trigger to request and update offload configuration.

---
 Documentation/leds/leds-class.rst | 12 ++++++++++++
 include/linux/leds.h              | 16 ++++++++++++++++
 2 files changed, 28 insertions(+)
Documentation/leds/leds-class.rst +12 -0
index ab50b58d6a21..af84cce09068 100644
@@ -191,6 +191,18 @@ If the second argument (enable) to the trigger_offload() method is false, any
 active HW offloading must be deactivated. In this case errors are not permitted
 in the trigger_offload() method.
 
+The offload trigger will use the function configure_offload() provided by the driver
+that will configure the offloaded mode for the LED.
+This function pass as the first argument (offload_flags) a u32 flag, it's in the LED
+driver interest how to elaborate this flags and to declare support for a particular
+offload trigger.
+The second argument (cmd) of the configure_offload() method can be used to do various
+operation for the specific trigger. We currently support ENABLE, DISABLE and READ to
+enable, disable and read the state of the offload trigger for the LED driver.
+If the driver return -ENOTSUPP on configure_offload, the trigger activation will
+fail as the driver doesn't support that specific offload trigger or don't know
+how to handle the provided flags.
+
 LEDs can declare the supported offload trigger using linux,supported-offload-triggers
 binding in the dts. This is just an array of string that will be used by any
 offload trigger to check the supported triggers and configure the LED offload mode
include/linux/leds.h +16 -0
index ff1f903f8079..eb06d812bc24 100644
@@ -67,6 +67,14 @@ struct led_hw_trigger_type {
 	int dummy;
 };
 
+#ifdef CONFIG_LEDS_OFFLOAD_TRIGGERS
+enum offload_trigger_cmd {
+	TRIGGER_ENABLE,
+	TRIGGER_DISABLE,
+	TRIGGER_READ
+};
+#endif
+
 struct led_classdev {
 	const char		*name;
 	unsigned int brightness;
@@ -163,6 +171,14 @@ struct led_classdev {
 	/* some LEDs may be able to offload some SW triggers to HW */
 	int			(*trigger_offload)(struct led_classdev *led_cdev,
 						   bool enable);
+	/* Function to configure how the LEDs should work in offload mode.
+	 * The function require to support the trigger and will use the
+	 * passed flags to elaborate the trigger requested and apply the
+	 * correct configuration.
+	 */
+	int			(*configure_offload)(struct led_classdev *led_cdev,
+						     u32 offload_flags,
+						     enum offload_trigger_cmd cmd);
 #endif
 #endif
 
Signature · 1 line
2.32.0
reviewer
#9 lore raw

Re: [RFC PATCH 3/6] leds: add function to configure offload leds

Documentation/leds/leds-class.rst If the second argument (enable) to the trigger_offload() method is false, any · line 196

Quoted 11 lines · Ansuel Smith
Documentation/leds/leds-class.rst +3 -0
index ab50b58d6a21..af84cce09068 100644
@@ -191,6 +191,18 @@ If the second argument (enable) to the trigger_offload() method is false, any
  active HW offloading must be deactivated. In this case errors are not permitted
  in the trigger_offload() method.
 
+The offload trigger will use the function configure_offload() provided by the driver
+that will configure the offloaded mode for the LED.
+This function pass as the first argument (offload_flags) a u32 flag, it's in the LED

passes flag. It's

Documentation/leds/leds-class.rst If the second argument (enable) to the trigger_offload() method is false, any · line 197

Quoted 1 line
Documentation/leds/leds-class.rst +1 -0
+driver interest how to elaborate this flags and to declare support for a particular

flag
although that sentence is not very clear.

Documentation/leds/leds-class.rst If the second argument (enable) to the trigger_offload() method is false, any · line 200

Quoted 3 lines
Documentation/leds/leds-class.rst +3 -0
+offload trigger.
+The second argument (cmd) of the configure_offload() method can be used to do various
+operation for the specific trigger. We currently support ENABLE, DISABLE and READ to

operations

Documentation/leds/leds-class.rst If the second argument (enable) to the trigger_offload() method is false, any · line 202

Quoted 2 lines
Documentation/leds/leds-class.rst +2 -0
+enable, disable and read the state of the offload trigger for the LED driver.
+If the driver return -ENOTSUPP on configure_offload, the trigger activation will

returns

Documentation/leds/leds-class.rst If the second argument (enable) to the trigger_offload() method is false, any · line 203

Quoted 1 line
Documentation/leds/leds-class.rst +1 -0
+fail as the driver doesn't support that specific offload trigger or don't know

doesn't know

Quoted 1 line
Documentation/leds/leds-class.rst +1 -0
+how to handle the provided flags.
Signature · 1 line
~Randy
author maintainer
#10 lore raw

RFC PATCH 4/6 leds: trigger: add offload-phy-activity trigger

In reply to Ansuel Smith

Add Offload Trigger for PHY Activity. This special trigger is used to configure and expose the different HW trigger that are provided by the PHY. Each offload trigger can be configured by sysfs and on trigger activation the offload mode is enabled.

This currently implement these hw triggers:
- blink_tx: Blink LED on tx packet receive
- blink_rx: Blink LED on rx packet receive
- blink_collision: Blink LED on collision detection
- link_10m: Keep LED on with 10m link speed
- link_100m: Keep LED on with 100m link speed
- link_1000m: Keep LED on with 1000m link speed
- half_duplex: Keep LED on with half duplex link
- full_duplex: Keep LED on with full duplex link
- linkup_over: Keep LED on with link speed and blink on rx/tx traffic
- power_on_reset: Keep LED on with switch reset
- blink_2hz: Set blink speed at 2hz for every blink event
- blink_4hz: Set blink speed at 4hz for every blink event
- blink_8hz: Set blink speed at 8hz for every blink event
- blink_auto: Set blink speed at 2hz for 10m link speed,

      4hz for 100m and 8hz for 1000m

The trigger will read the supported offload trigger in the led cdev and will expose the offload triggers in sysfs and then activate the offload mode for the led in offload mode has it configured by default. A flag is passed to configure_offload with the related rule from this trigger to active or disable.
It's in the led driver interest the detection and knowing how to elaborate the passed flags.

The different hw triggers are exposed in the led sysfs dir under the offload-phy-activity subdir.

---
 drivers/leds/trigger/Kconfig                  |  25 +++
 drivers/leds/trigger/Makefile                 |   1 +
 .../trigger/ledtrig-offload-phy-activity.c    | 151 ++++++++++++++++++
 include/linux/leds.h                          |  24 +++
 4 files changed, 201 insertions(+)
 create mode 100644 drivers/leds/trigger/ledtrig-offload-phy-activity.c
drivers/leds/trigger/Kconfig +25 -0
index c073e64e0a37..377a8bceb0b7 100644
@@ -164,4 +164,29 @@ config LEDS_TRIGGER_TTY
 
 	  When build as a module this driver will be called ledtrig-tty.
 
+config LEDS_OFFLOAD_TRIGGER_PHY_ACTIVITY
+	tristate "LED Offload Trigger for PHY Activity"
+	depends on LEDS_OFFLOAD_TRIGGERS
+	help
+	  This allows LEDs to be configured to run by HW and offloaded based
+	  on some rules. The LED will blink or be on based on the PHY Activity
+	  for example on packet receive of based on the link speed.
+	  The current rules are:
+	  - blink_tx: Blink LED on tx packet receive
+	  - blink_rx: Blink LED on rx packet receive
+	  - blink_collision: Blink LED on collision detection
+	  - link_10m: Keep LED on with 10m link speed
+	  - link_100m: Keep LED on with 100m link speed
+	  - link_1000m: Keep LED on with 1000m link speed
+	  - half_duplex: Keep LED on with half duplex link
+	  - full_duplex: Keep LED on with full duplex link
+	  - linkup_over: Keep LED on with link speed and blink on rx/tx traffic
+	  - power_on_reset: Keep LED on with switch reset
+	  - blink_2hz: Set blink speed at 2hz for every blink event
+	  - blink_4hz: Set blink speed at 4hz for every blink event
+	  - blink_8hz: Set blink speed at 8hz for every blink event
+	  - blink_auto: Set blink speed at 2hz for 10m link speed,
+	                4hz for 100m and 8hz for 1000m
+
+
 endif # LEDS_TRIGGERS
drivers/leds/trigger/Makefile +1 -0
index 25c4db97cdd4..392ca8568588 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_LEDS_TRIGGER_NETDEV)	+= ledtrig-netdev.o
 obj-$(CONFIG_LEDS_TRIGGER_PATTERN)	+= ledtrig-pattern.o
 obj-$(CONFIG_LEDS_TRIGGER_AUDIO)	+= ledtrig-audio.o
 obj-$(CONFIG_LEDS_TRIGGER_TTY)		+= ledtrig-tty.o
+obj-$(CONFIG_LEDS_OFFLOAD_TRIGGER_PHY_ACTIVITY) += ledtrig-offload-phy-activity.o
drivers/leds/trigger/ledtrig-offload-phy-activity.c new file +151 -0

151 lines not on this page · raw message

include/linux/leds.h +24 -0
index eb06d812bc24..1e8d1efcb44f 100644
@@ -537,6 +537,30 @@ static inline void ledtrig_flash_ctrl(bool on) {}
 static inline void ledtrig_torch_ctrl(bool on) {}
 #endif
 
+#ifdef CONFIG_LEDS_OFFLOAD_TRIGGER_PHY_ACTIVITY
+/* 3 main category for offload trigger:
+ * - blink: the led will blink on trigger
+ * - keep: the led will be kept on with condition
+ * - option: a configuration value internal to the led on how offload works
+ */
+enum offload_phy_activity {
+	BLINK_TX = BIT(0), /* Blink on TX traffic */
+	BLINK_RX = BIT(1), /* Blink on RX traffic */
+	BLINK_COLLISION = BIT(2), /* Blink on Collision packet */
+	KEEP_LINK_10M = BIT(3), /* LED on with 10M link */
+	KEEP_LINK_100M = BIT(4), /* LED on with 100M link */
+	KEEP_LINK_1000M = BIT(5), /* LED on with 1000M link */
+	KEEP_HALF_DUPLEX = BIT(6), /* LED on with Half-Duplex link */
+	KEEP_FULL_DUPLEX = BIT(7), /* LED on with Full-Duplex link */
+	OPTION_LINKUP_OVER = BIT(8), /* LED will be on with KEEP offload_triggers and blink on BLINK traffic */
+	OPTION_POWER_ON_RESET = BIT(9), /* LED will be on Switch reset */
+	OPTION_BLINK_2HZ = BIT(10), /* LED will blink with any offload_trigger at 2Hz */
+	OPTION_BLINK_4HZ = BIT(11), /* LED will blink with any offload_trigger at 4Hz */
+	OPTION_BLINK_8HZ = BIT(12), /* LED will blink with any offload_trigger at 8Hz */
+	OPTION_BLINK_AUTO = BIT(13), /* LED will blink differently based on the Link Speed */
+};
+#endif
+
 /*
  * Generic LED platform data for describing LED names and default triggers.
  */
Signature · 1 line
2.32.0
#11 lore raw

Re: [RFC PATCH 4/6] leds: trigger: add offload-phy-activity trigger

Quoted 30 lines · On Sun, 7 Nov 2021 18:57:16 +0100 Ansuel Smith <[email protected]> wrote:

Add Offload Trigger for PHY Activity. This special trigger is used to configure and expose the different HW trigger that are provided by the PHY. Each offload trigger can be configured by sysfs and on trigger activation the offload mode is enabled.

This currently implement these hw triggers:
- blink_tx: Blink LED on tx packet receive
- blink_rx: Blink LED on rx packet receive
- blink_collision: Blink LED on collision detection
- link_10m: Keep LED on with 10m link speed
- link_100m: Keep LED on with 100m link speed
- link_1000m: Keep LED on with 1000m link speed
- half_duplex: Keep LED on with half duplex link
- full_duplex: Keep LED on with full duplex link
- linkup_over: Keep LED on with link speed and blink on rx/tx traffic
- power_on_reset: Keep LED on with switch reset
- blink_2hz: Set blink speed at 2hz for every blink event
- blink_4hz: Set blink speed at 4hz for every blink event
- blink_8hz: Set blink speed at 8hz for every blink event
- blink_auto: Set blink speed at 2hz for 10m link speed,

      4hz for 100m and 8hz for 1000m

The trigger will read the supported offload trigger in the led cdev and will expose the offload triggers in sysfs and then activate the offload mode for the led in offload mode has it configured by default. A flag is passed to configure_offload with the related rule from this trigger to active or disable.
It's in the led driver interest the detection and knowing how to elaborate the passed flags.

Quoted 2 lines

The different hw triggers are exposed in the led sysfs dir under the offload-phy-activity subdir.

NAK. The current plan is to use netdev trigger, and if it can transparently offload the settings to HW, it will.

Yes, netdev trigger currently does not support all these settings. But it supports indicating link and blinking on activity.

So the plan is to start with offloading the blinking on activity, i.e. I the user does

  $ cd /sys/class/leds/<LED>
  $ echo netdev >trigger
  $ echo 1 >rx
  $ echo eth0 >device_name

this would, instead of doing blinking in software, do it in HW instead.

After this is implemented, we can start working on extending netdev trigger to support more complicated features.

Marek

author maintainer
#12 lore raw

Re: [RFC PATCH 4/6] leds: trigger: add offload-phy-activity trigger

Quoted 49 lines · Marek Behún
Quoted 30 lines · On Sun, 7 Nov 2021 18:57:16 +0100 Ansuel Smith <[email protected]> wrote:

Add Offload Trigger for PHY Activity. This special trigger is used to configure and expose the different HW trigger that are provided by the PHY. Each offload trigger can be configured by sysfs and on trigger activation the offload mode is enabled.

This currently implement these hw triggers:
- blink_tx: Blink LED on tx packet receive
- blink_rx: Blink LED on rx packet receive
- blink_collision: Blink LED on collision detection
- link_10m: Keep LED on with 10m link speed
- link_100m: Keep LED on with 100m link speed
- link_1000m: Keep LED on with 1000m link speed
- half_duplex: Keep LED on with half duplex link
- full_duplex: Keep LED on with full duplex link
- linkup_over: Keep LED on with link speed and blink on rx/tx traffic
- power_on_reset: Keep LED on with switch reset
- blink_2hz: Set blink speed at 2hz for every blink event
- blink_4hz: Set blink speed at 4hz for every blink event
- blink_8hz: Set blink speed at 8hz for every blink event
- blink_auto: Set blink speed at 2hz for 10m link speed,

      4hz for 100m and 8hz for 1000m

The trigger will read the supported offload trigger in the led cdev and will expose the offload triggers in sysfs and then activate the offload mode for the led in offload mode has it configured by default. A flag is passed to configure_offload with the related rule from this trigger to active or disable.
It's in the led driver interest the detection and knowing how to elaborate the passed flags.

Quoted 2 lines

The different hw triggers are exposed in the led sysfs dir under the offload-phy-activity subdir.

NAK. The current plan is to use netdev trigger, and if it can transparently offload the settings to HW, it will.

Yes, netdev trigger currently does not support all these settings. But it supports indicating link and blinking on activity.

So the plan is to start with offloading the blinking on activity, i.e. I the user does

  $ cd /sys/class/leds/<LED>
  $ echo netdev >trigger
  $ echo 1 >rx
  $ echo eth0 >device_name
Quoted 6 lines

this would, instead of doing blinking in software, do it in HW instead.

After this is implemented, we can start working on extending netdev trigger to support more complicated features.

Marek

Using the netdev trigger would cause some problem. Most of the switch can run in SW mode (with blink controlled by software of always on) or be put in HW mode and they will autonomously control blinking and how the LED will operate. So we just need to provide a way to trigger this mode and configure it. Why having something that gets triggered and then does nothing as it's offloaded?

The current way to configure this is very similar... Set the offload trigger and use the deidcated subdir to set how the led will blink/behave based on the supported trigger reported by the driver.

There is no reason to set a device_name as that would be hardcoded to the phy (and it should not change... again in HW we can't control that part, we can just tell the switch to blink on packet tx on that port)

So really the command is:

  $ cd /sys/class/leds/<LED>
  $ echo netdev > offload-phy-activity
  $ cd offload-phy-activity
  $ echo 1 > tx-blink

And the PHY will blink on tx packet.

I understand this should be an extension of netdev as they would do similar task but honestly polluting the netdev trigger of if and else to disable part of it if an offload mode can be supported seems bad and confusionary. At this point introduce a dedicated trigger so an user can switch between them. That way we can keep the flexibility of netdev trigger that will always work but also permit to support the HW mode with no load on the system.

Signature · 1 line
	Ansuel
#13 lore raw

Re: [RFC PATCH 4/6] leds: trigger: add offload-phy-activity trigger

Quoted 55 lines · On Sun, 7 Nov 2021 23:43:37 +0100 Ansuel Smith <[email protected]> wrote:
Quoted 54 lines · Marek Behún
Quoted 30 lines · On Sun, 7 Nov 2021 18:57:16 +0100 Ansuel Smith <[email protected]> wrote:

Add Offload Trigger for PHY Activity. This special trigger is used to configure and expose the different HW trigger that are provided by the PHY. Each offload trigger can be configured by sysfs and on trigger activation the offload mode is enabled.

This currently implement these hw triggers:
- blink_tx: Blink LED on tx packet receive
- blink_rx: Blink LED on rx packet receive
- blink_collision: Blink LED on collision detection
- link_10m: Keep LED on with 10m link speed
- link_100m: Keep LED on with 100m link speed
- link_1000m: Keep LED on with 1000m link speed
- half_duplex: Keep LED on with half duplex link
- full_duplex: Keep LED on with full duplex link
- linkup_over: Keep LED on with link speed and blink on rx/tx traffic
- power_on_reset: Keep LED on with switch reset
- blink_2hz: Set blink speed at 2hz for every blink event
- blink_4hz: Set blink speed at 4hz for every blink event
- blink_8hz: Set blink speed at 8hz for every blink event
- blink_auto: Set blink speed at 2hz for 10m link speed,

      4hz for 100m and 8hz for 1000m

The trigger will read the supported offload trigger in the led cdev and will expose the offload triggers in sysfs and then activate the offload mode for the led in offload mode has it configured by default. A flag is passed to configure_offload with the related rule from this trigger to active or disable.
It's in the led driver interest the detection and knowing how to elaborate the passed flags.

Quoted 2 lines

The different hw triggers are exposed in the led sysfs dir under the offload-phy-activity subdir.

NAK. The current plan is to use netdev trigger, and if it can transparently offload the settings to HW, it will.

Yes, netdev trigger currently does not support all these settings. But it supports indicating link and blinking on activity.

So the plan is to start with offloading the blinking on activity, i.e. I the user does

  $ cd /sys/class/leds/<LED>
  $ echo netdev >trigger
  $ echo 1 >rx
  $ echo eth0 >device_name

this would, instead of doing blinking in software, do it in HW instead.

After this is implemented, we can start working on extending netdev trigger to support more complicated features.

Quoted 8 lines
Quoted 1 line

Marek

Using the netdev trigger would cause some problem. Most of the switch can run in SW mode (with blink controlled by software of always on) or be put in HW mode and they will autonomously control blinking and how the LED will operate. So we just need to provide a way to trigger this mode and configure it. Why having something that gets triggered and then does nothing as it's offloaded?

Nothing gets triggered. In my last proposal, when the netdev trigger gets activated, it will first try to offload() itself to the LED controller. If the controller supports offloading, then netdev trigger won't be blinking the LEDs.

See my last proposal at
https://lore.kernel.org/linux-leds/[email protected]/

Quoted 8 lines

The current way to configure this is very similar... Set the offload trigger and use the deidcated subdir to set how the led will blink/behave based on the supported trigger reported by the driver.

There is no reason to set a device_name as that would be hardcoded to the phy (and it should not change... again in HW we can't control that part, we can just tell the switch to blink on packet tx on that port)

Quoted 7 lines

So really the command is:

  $ cd /sys/class/leds/<LED>
  $ echo netdev > offload-phy-activity
  $ cd offload-phy-activity
  $ echo 1 > tx-blink

And the PHY will blink on tx packet.

So there are now 2 different ways to set a LED to blink on tx activity:
the first one is via standard netdev trigger, the second one is this. That is wrong.

Quoted 7 lines

I understand this should be an extension of netdev as they would do similar task but honestly polluting the netdev trigger of if and else to disable part of it if an offload mode can be supported seems bad and confusionary. At this point introduce a dedicated trigger so an user can switch between them. That way we can keep the flexibility of netdev trigger that will always work but also permit to support the HW mode with no load on the system.

The rationale behind offloading netdev trigger is that it can use standard, existing sysfs ABI. If the driver finds out that it can offload the blinking to HW, it will.

This is similar to how other kernel APIs do this.

For example for an ethernet switch, we have DSA. So that we don't need a specific way to say to the switch which ports it should bridge. All ports are exported by the switch driver as standard network devices, and if we bridge them via standard API, the kernel, upon finding out that the bridging can be offloading to the switch chip, does that.

Marek

reviewer
#14 lore raw

Re: [RFC PATCH 4/6] leds: trigger: add offload-phy-activity trigger

In reply to Ansuel Smith

drivers/leds/trigger/Kconfig config LEDS_TRIGGER_TTY · line 173

Quoted 7 lines · Ansuel Smith
drivers/leds/trigger/Kconfig +7 -0
+config LEDS_OFFLOAD_TRIGGER_PHY_ACTIVITY
+	tristate "LED Offload Trigger for PHY Activity"
+	depends on LEDS_OFFLOAD_TRIGGERS
+	help
+	  This allows LEDs to be configured to run by HW and offloaded based
+	  on some rules. The LED will blink or be on based on the PHY Activity
+	  for example on packet receive of based on the link speed.

Cannot parse: of based on

Quoted 1 line
drivers/leds/trigger/Kconfig +1 -0
+	  The current rules are:
Signature · 1 line
~Randy
author maintainer
#15 lore raw

Re: [RFC PATCH 4/6] leds: trigger: add offload-phy-activity trigger

Quoted 11 lines · Randy Dunlap

drivers/leds/trigger/Kconfig config LEDS_TRIGGER_TTY · line 173

Quoted 7 lines · Ansuel Smith
drivers/leds/trigger/Kconfig +7 -0
+config LEDS_OFFLOAD_TRIGGER_PHY_ACTIVITY
+	tristate "LED Offload Trigger for PHY Activity"
+	depends on LEDS_OFFLOAD_TRIGGERS
+	help
+	  This allows LEDs to be configured to run by HW and offloaded based
+	  on some rules. The LED will blink or be on based on the PHY Activity
+	  for example on packet receive of based on the link speed.

Cannot parse: of based on

Typo. "on packet receive or based on the link speed" You can find right below all the modes.

Quoted 5 lines
Quoted 1 line
drivers/leds/trigger/Kconfig +1 -0
+	  The current rules are:
Signature · 1 line
~Randy
Signature · 1 line
	Ansuel
author maintainer
#16 lore raw

RFC PATCH 5/6 net: dsa: qca8k: add LEDs support

In reply to Ansuel Smith

Add LEDs support for qca8k Switch Family. This will provide the LEDs offload API to permit the PHY LED to be driven offloaded. Each port have at least 3 LEDs and they can HW blink, set on/off or set to be driven by some rules applied by the offload trigger.

---
 drivers/net/dsa/Kconfig      |   9 +
 drivers/net/dsa/Makefile     |   1 +
 drivers/net/dsa/qca8k-leds.c | 361 +++++++++++++++++++++++++++++++++++
 drivers/net/dsa/qca8k.c      |   4 +-
 drivers/net/dsa/qca8k.h      |  64 +++++++
 5 files changed, 437 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/dsa/qca8k-leds.c
drivers/net/dsa/Kconfig +9 -0
index 7b1457a6e327..89e36f3a8195 100644
@@ -67,6 +67,15 @@ config NET_DSA_QCA8K
 	  This enables support for the Qualcomm Atheros QCA8K Ethernet
 	  switch chips.
 
+config NET_DSA_QCA8K_LEDS_SUPPORT
+	tristate "Qualcomm Atheros QCA8K Ethernet switch family LEDs support"
+	select NET_DSA_QCA8K
+	select LEDS_OFFLOAD_TRIGGERS
+	help
+	  Thsi enabled support for LEDs present on the Qualcomm Atheros
+	  QCA8K Ethernet switch chips. This require the LEDs offload
+	  triggers support as it can run in offload mode.
+
 config NET_DSA_REALTEK_SMI
 	tristate "Realtek SMI Ethernet switch family support"
 	select NET_DSA_TAG_RTL4_A
drivers/net/dsa/Makefile +1 -0
index 8da1569a34e6..fb1e7d0cf126 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_NET_DSA_LANTIQ_GSWIP) += lantiq_gswip.o
 obj-$(CONFIG_NET_DSA_MT7530)	+= mt7530.o
 obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o
 obj-$(CONFIG_NET_DSA_QCA8K)	+= qca8k.o
+obj-$(CONFIG_NET_DSA_QCA8K_LEDS_SUPPORT) += qca8k-leds.o
 obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o
 realtek-smi-objs		:= realtek-smi-core.o rtl8366.o rtl8366rb.o rtl8365mb.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
drivers/net/dsa/qca8k-leds.c new file +361 -0

361 lines not on this page · raw message

drivers/net/dsa/qca8k.c +2 -2
index a429c9750add..b5c81e2d9f8a 100644
@@ -148,7 +148,7 @@ qca8k_set_page(struct mii_bus *bus, u16 page)
 	return 0;
 }
 
-static int
+int
 qca8k_read(struct qca8k_priv *priv, u32 reg, u32 *val)
 {
 	struct mii_bus *bus = priv->bus;
@@ -192,7 +192,7 @@ qca8k_write(struct qca8k_priv *priv, u32 reg, u32 val)
 	return ret;
 }
 
-static int
+int
 qca8k_rmw(struct qca8k_priv *priv, u32 reg, u32 mask, u32 write_val)
 {
 	struct mii_bus *bus = priv->bus;
drivers/net/dsa/qca8k.h +64 -0

92 lines not on this page · raw message

Signature · 1 line
2.32.0
reviewer
#17 lore raw

Re: [RFC PATCH 5/6] net: dsa: qca8k: add LEDs support

Quoted 5 lines · Ansuel Smith
drivers/net/dsa/Kconfig +0 -0
index 7b1457a6e327..89e36f3a8195 100644

drivers/net/dsa/Kconfig config NET_DSA_QCA8K · line 75

Quoted 9 lines
drivers/net/dsa/Kconfig +6 -0
@@ -67,6 +67,15 @@ config NET_DSA_QCA8K
  	  This enables support for the Qualcomm Atheros QCA8K Ethernet
  	  switch chips.
 
+config NET_DSA_QCA8K_LEDS_SUPPORT
+	tristate "Qualcomm Atheros QCA8K Ethernet switch family LEDs support"
+	select NET_DSA_QCA8K
+	select LEDS_OFFLOAD_TRIGGERS
+	help
+	  Thsi enabled support for LEDs present on the Qualcomm Atheros

This enables

drivers/net/dsa/Kconfig config NET_DSA_QCA8K · line 76

Quoted 1 line
drivers/net/dsa/Kconfig +1 -0
+	  QCA8K Ethernet switch chips. This require the LEDs offload

requires

Quoted 1 line
drivers/net/dsa/Kconfig +1 -0
+	  triggers support as it can run in offload mode.
Signature · 1 line
~Randy
author maintainer
#18 lore raw

RFC PATCH 6/6 dt-bindings: net: dsa: qca8k: add LEDs definition example

In reply to Ansuel Smith

Add LEDs definition example for qca8k using the offload trigger as the default trigger and add all the supported offload triggers by the switch.

---
 .../devicetree/bindings/net/dsa/qca8k.yaml    | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
Documentation/devicetree/bindings/net/dsa/qca8k.yaml +30 -0
index 48de0ace265d..d8394f625d03 100644
@@ -64,6 +64,8 @@ properties:
                  internal mdio access is used.
                  With the legacy mapping the reg corresponding to the internal
                  mdio is the switch reg with an offset of -1.
+                 Each phy have at least 3 LEDs connected and can be declared
+                 using the standard LEDs structure.
 
     properties:
       '#address-cells':
@@ -340,6 +342,34 @@ examples:
 
                 internal_phy_port1: ethernet-phy@0 {
                     reg = <0>;
+
+                    leds {
+                        led@0 {
+                            reg = <0>;
+                            color = <LED_COLOR_ID_WHITE>;
+                            function = LED_FUNCTION_LAN;
+                            function-enumerator = <1>;
+                            linux,default-trigger = "offload-phy-activity";
+                            linux,supported-offload-triggers = "rx-blink", "tx-blink", "ollision-blink",
+                                                        "link-10M", "link-100M", "link-1000M",
+                                                        "half-duplex", "full-duplex", "linkup-over",
+                                                        "power-on-reset", "blink-2hz", "blink-4hz",
+                                                        "blink-8hz", "blink-auto";
+                        };
+
+                        led@1 {
+                            reg = <1>;
+                            color = <LED_COLOR_ID_AMBER>;
+                            function = LED_FUNCTION_LAN;
+                            function-enumerator = <1>;
+                            linux,default-trigger = "offload-phy-activity";
+                            linux,supported-offload-triggers = "rx-blink", "tx-blink", "ollision-blink",
+                                                        "link-10M", "link-100M", "link-1000M",
+                                                        "half-duplex", "full-duplex", "linkup-over",
+                                                        "power-on-reset", "blink-2hz", "blink-4hz",
+                                                        "blink-8hz", "blink-auto";
+                        };
+                    };
                 };
 
                 internal_phy_port2: ethernet-phy@1 {
Signature · 1 line
2.32.0