Skip to contentSkip to conversation

Adds support for PHY LEDs with offload triggers

RFC PATCH Superseded Ansuel Smith 4 participants 21 messages Nov 11, 2021 – Nov 12, 2021

Subsystems (7)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Ansuel Smith

author maintainer
#0 lore raw

v4 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 3 API (hw_control_status/start/stop). They are used to put the LED in hardware mode and to configure the various trigger.
- We have hardware triggers that are used to expose to userspace the supported hardware mode and set the hardware mode on trigger activation.
- We can also have triggers that both support hardware and software mode.
- The LED driver will declare each supported hardware blink mode and communicate with the trigger all the supported blink modes that will be available by sysfs.
- A trigger will use blink_set to configure the blink mode to active in hardware mode.
- On hardware trigger activation, only the hardware mode is enabled but the blink modes are not configured. The LED driver should reset any link mode active by default.

Each LED driver will have to declare explicit support for the offload trigger (or return not supported error code) as we the trigger_data 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.

I also posted the netdev trigger expanded with the hardware support.

More polish is required but this is just to understand if I'm taking the correct path with this implementation hoping we find a correct implementation and we start working on the ""small details""

v4:
- Rework implementation and drop hw_configure logic.
We now expand blink_set.
- Address even more spelling mistake. (thx a lot Randy)
- Drop blink option and use blink_set delay.
- Rework phy-activity trigger to actually make the groups dynamic. v3:
- Rework start/stop as Andrew asked.
- Introduce more logic to permit a trigger to run in hardware mode.
- Add additional patch with netdev hardware support.
- Use test_bit API to check flag passed to hw_control_configure.
- Added a new cmd to hw_control_configure to reset any active blink_mode.
- Refactor all the patches to follow this new implementation. v2:
- Fix spelling mistake (sorry)
- Drop patch 02 "permit to declare supported offload triggers". Change the logic, now the LED driver declare support for them using the configure_offload with the cmd TRIGGER_SUPPORTED.
- Rework code to follow this new implementation.
- Update Documentation to better describe how this offload implementation work.

Ansuel Smith (8):
leds: add support for hardware driven LEDs
leds: document additional use of blink_set for hardware control
leds: trigger: netdev: drop NETDEV_LED_MODE_LINKUP from mode
leds: trigger: netdev: rename and expose NETDEV trigger enum and
struct
leds: trigger: netdev: add hardware control support
leds: trigger: add hardware-phy-activity trigger
net: dsa: qca8k: add LEDs support
dt-bindings: net: dsa: qca8k: add LEDs definition example

 .../devicetree/bindings/net/dsa/qca8k.yaml    |  20 +
 Documentation/leds/leds-class.rst             |  49 ++
 drivers/leds/Kconfig                          |  11 +
 drivers/leds/led-class.c                      |  40 ++
 drivers/leds/led-triggers.c                   |  22 +
 drivers/leds/trigger/Kconfig                  |  28 ++
 drivers/leds/trigger/Makefile                 |   1 +
 .../trigger/ledtrig-hardware-phy-activity.c   | 180 ++++++++
 drivers/leds/trigger/ledtrig-netdev.c         |  92 ++--
 drivers/net/dsa/Kconfig                       |   9 +
 drivers/net/dsa/Makefile                      |   1 +
 drivers/net/dsa/qca8k-leds.c                  | 423 ++++++++++++++++++
 drivers/net/dsa/qca8k.c                       |   8 +-
 drivers/net/dsa/qca8k.h                       |  65 +++
 include/linux/leds.h                          |  97 +++-
 15 files changed, 999 insertions(+), 47 deletions(-)
 create mode 100644 drivers/leds/trigger/ledtrig-hardware-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 v4 1/8 leds: add support for hardware driven LEDs

Some LEDs can be driven by 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 this and a supported trigger must be used.

LED driver should declare the correct control mode supported and should set the LED_SOFTWARE_CONTROLLED or LED_HARDWARE_CONTROLLED bit in the flags parameter.
The trigger will check these bit and fail to activate if the control mode is not supported. By default if a LED driver doesn't declare a control mode, bit LED_SOFTWARE_CONTROLLED is assumed and set by default.

The LED must implement 3 main API:
- hw_control_status(): This asks the LED driver if hardware mode is enabled or not.
- hw_control_start(): This will simply enable the hardware mode for the LED and the LED driver should reset any active blink_mode.
- hw_control_stop(): This will simply disable the hardware mode for the LED. It's advised for the driver to put the LED in the old state but this is not enforced and putting the LED off is also accepted.

If LED_HARDWARE_CONTROLLED bit is the only contro mode set (LED_SOFTWARE_CONTROLLED not set) set hw_control_status/start/stop is optional as the LED supports only hardware mode and any software only trigger will reject activation.

On init a LED driver that support a hardware mode should reset every blink mode set by default.

An additional config CONFIG_LEDS_HARDWARE_CONTROL is added to add support for LEDs that can be controlled by hardware.

---
 Documentation/leds/leds-class.rst | 32 +++++++++++++++++++++++++++++
 drivers/leds/Kconfig              | 11 ++++++++++
 drivers/leds/led-class.c          | 33 ++++++++++++++++++++++++++++++
 drivers/leds/led-triggers.c       | 22 ++++++++++++++++++++
 include/linux/leds.h              | 34 ++++++++++++++++++++++++++++++-
 5 files changed, 131 insertions(+), 1 deletion(-)
Documentation/leds/leds-class.rst +32 -0
index cd155ead8703..0175954717a3 100644
@@ -169,6 +169,38 @@ 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 driven LEDs
+===================================
+
+Some LEDs can be driven by 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 this and a supported trigger must
+be used.
+
+LED driver should declare the correct control mode supported and should set
+the LED_SOFTWARE_CONTROLLED or LED_HARDWARE_CONTROLLED bit in the flags
+parameter.
+The trigger will check these bit and fail to activate if the control mode
+is not supported. By default if a LED driver doesn't declare a control mode,
+bit LED_SOFTWARE_CONTROLLED is assumed and set by default.
+
+The LED must implement 3 main API:
+- hw_control_status(): This asks the LED driver if hardware mode is enabled
+    or not.
+- hw_control_start(): This will simply enable the hardware mode for the LED
+    and the LED driver should reset any active blink_mode.
+- hw_control_stop(): This will simply disable the hardware mode for the LED.
+    It's advised to the driver to put the LED in the old state but this is not
+    enforcerd and putting the LED off is also accepted.
+
+If LED_HARDWARE_CONTROLLED bit is the only contro mode set (LED_SOFTWARE_CONTROLLED
+not set) set hw_control_status/start/stop is optional as the LED supports only
+hardware mode and any software only trigger will reject activation.
+
+On init a LED driver that support a hardware mode should reset every blink mode
+set by default.
 
 Known Issues
 ============
drivers/leds/Kconfig +11 -0
index ed800f5da7d8..bd2b19cc77ec 100644
@@ -49,6 +49,17 @@ config LEDS_BRIGHTNESS_HW_CHANGED
 
 	  See Documentation/ABI/testing/sysfs-class-led for details.
 
+config LEDS_HARDWARE_CONTROL
+	bool "LED Hardware Control support"
+	help
+	  This option enabled Hardware control support used by leds that
+	  can be driven in hardware by using supported triggers.
+
+	  Hardware blink modes will be exposed by sysfs class in
+	  /sys/class/leds based on the trigger currently active.
+
+	  If unsure, say Y.
+
 comment "LED drivers"
 
 config LEDS_88PM860X
drivers/leds/led-class.c +33 -0
index f4bb02f6e042..98a4dc889344 100644
@@ -164,6 +164,26 @@ static void led_remove_brightness_hw_changed(struct led_classdev *led_cdev)
 }
 #endif
 
+#ifdef CONFIG_LEDS_HARDWARE_CONTROL
+static int led_classdev_check_hw_control_functions(struct led_classdev *led_cdev)
+{
+	if ((LED_SOFTWARE_CONTROLLED & led_cdev->flags) &&
+	    (LED_HARDWARE_CONTROLLED & led_cdev->flags) &&
+	    (!led_cdev->hw_control_status ||
+	    !led_cdev->hw_control_start ||
+	    !led_cdev->hw_control_stop))
+		return -EINVAL;
+
+	if ((LED_SOFTWARE_CONTROLLED & led_cdev->flags) &&
+	    (led_cdev->hw_control_status ||
+	    led_cdev->hw_control_start ||
+	    led_cdev->hw_control_stop))
+		return -EINVAL;
+
+	return 0;
+}
+#endif
+
 /**
  * led_classdev_suspend - suspend an led_classdev.
  * @led_cdev: the led_classdev to suspend.
@@ -367,6 +387,19 @@ int led_classdev_register_ext(struct device *parent,
 	if (ret < 0)
 		return ret;
 
+	/* Make sure a control mode is set.
+	 * With no control mode declared, set SOFTWARE_CONTROLLED by default.
+	 */
+	if (!(LED_SOFTWARE_CONTROLLED & led_cdev->flags) &&
+	    !(LED_HARDWARE_CONTROLLED & led_cdev->flags))
+		led_cdev->flags |= LED_SOFTWARE_CONTROLLED;
+
+#ifdef CONFIG_LEDS_HARDWARE_CONTROL
+	ret = led_classdev_check_hw_control_functions(led_cdev);
+	if (ret < 0)
+		return ret;
+#endif
+
 	mutex_init(&led_cdev->led_access);
 	mutex_lock(&led_cdev->led_access);
 	led_cdev->dev = device_create_with_groups(leds_class, parent, 0,
drivers/leds/led-triggers.c +22 -0
index 072491d3e17b..69dff5a29bea 100644
@@ -154,6 +154,20 @@ ssize_t led_trigger_read(struct file *filp, struct kobject *kobj,
 }
 EXPORT_SYMBOL_GPL(led_trigger_read);
 
+static bool led_trigger_is_supported(struct led_classdev *led_cdev,
+				     struct led_trigger *trigger)
+{
+	if (trigger->supported_blink_modes == SOFTWARE_ONLY &&
+	    !(LED_SOFTWARE_CONTROLLED & led_cdev->flags))
+		return 0;
+
+	if (trigger->supported_blink_modes == HARDWARE_ONLY &&
+	    !(LED_HARDWARE_CONTROLLED & led_cdev->flags))
+		return 0;
+
+	return 1;
+}
+
 /* Caller must ensure led_cdev->trigger_lock held */
 int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
 {
@@ -179,6 +193,10 @@ 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);
+		/* Disable hardware mode on trigger change if supported */
+		if ((led_cdev->flags & LED_HARDWARE_CONTROLLED) &&
+		    led_cdev->hw_control_status(led_cdev))
+			led_cdev->hw_control_stop(led_cdev);
 		if (led_cdev->trigger->deactivate)
 			led_cdev->trigger->deactivate(led_cdev);
 		device_remove_groups(led_cdev->dev, led_cdev->trigger->groups);
@@ -188,6 +206,10 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
 		led_set_brightness(led_cdev, LED_OFF);
 	}
 	if (trig) {
+		/* Make sure the trigger support the LED blink mode */
+		if (!led_trigger_is_supported(led_cdev, trig))
+			return -EINVAL;
+
 		spin_lock(&trig->leddev_list_lock);
 		list_add_tail_rcu(&led_cdev->trig_list, &trig->led_cdevs);
 		spin_unlock(&trig->leddev_list_lock);
include/linux/leds.h +33 -1
index ba4861ec73d3..d64e5768e7ab 100644
@@ -85,6 +85,11 @@ struct led_classdev {
 #define LED_BRIGHT_HW_CHANGED	BIT(21)
 #define LED_RETAIN_AT_SHUTDOWN	BIT(22)
 #define LED_INIT_DEFAULT_TRIGGER BIT(23)
+/* LED can be controlled by software. This is set by default
+ * if the LED driver doesn't report SOFTWARE or HARDWARE
+ */
+#define LED_SOFTWARE_CONTROLLED	BIT(24)
+#define LED_HARDWARE_CONTROLLED	BIT(25)
 
 	/* set_brightness_work / blink_timer flags, atomic, private. */
 	unsigned long		work_flags;
@@ -154,6 +159,20 @@ struct led_classdev {
 
 	/* LEDs that have private triggers have this set */
 	struct led_hw_trigger_type	*trigger_type;
+
+#ifdef CONFIG_LEDS_HARDWARE_CONTROL
+	/* Ask the LED driver if hardware mode is enabled or not.
+	 * Triggers will check if the hardware mode is active or not.
+	 */
+	bool			(*hw_control_status)(struct led_classdev *led_cdev);
+	/* Set LED in hardware mode and reset any blink mode active by default.
+	 */
+	int			(*hw_control_start)(struct led_classdev *led_cdev);
+	/* Disable hardware mode for LED. It's advised to the LED driver to put it to
+	 * the old status but that is not mandatory and also putting it off is accepted.
+	 */
+	int			(*hw_control_stop)(struct led_classdev *led_cdev);
+#endif
 #endif
 
 #ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED
@@ -215,7 +234,6 @@ extern struct led_classdev *of_led_get(struct device_node *np, int index);
 extern void led_put(struct led_classdev *led_cdev);
 struct led_classdev *__must_check devm_of_led_get(struct device *dev,
 						  int index);
-
 /**
  * led_blink_set - set blinking with software fallback
  * @led_cdev: the LED to start blinking
@@ -350,12 +368,26 @@ static inline bool led_sysfs_is_disabled(struct led_classdev *led_cdev)
 
 #define TRIG_NAME_MAX 50
 
+enum led_trigger_blink_supported_modes {
+	SOFTWARE_ONLY = BIT(0),
+	HARDWARE_ONLY = BIT(1),
+	SOFTWARE_HARDWARE = BIT(2),
+};
+
 struct led_trigger {
 	/* Trigger Properties */
 	const char	 *name;
 	int		(*activate)(struct led_classdev *led_cdev);
 	void		(*deactivate)(struct led_classdev *led_cdev);
 
+	/* Declare if the Trigger supports hardware control to
+	 * offload triggers or supports only software control.
+	 * A trigger can also declare support for hardware control
+	 * if is task is only configure LED blink modes and expose
+	 * them in sysfs.
+	 */
+	enum led_trigger_blink_supported_modes supported_blink_modes;
+
 	/* LED-private triggers have this set */
 	struct led_hw_trigger_type *trigger_type;
 
Signature · 1 line
2.32.0
author maintainer
#5 lore raw

RFC PATCH v4 2/8 leds: document additional use of blink_set for hardware control

In reply to Ansuel Smith

blink_set can now be used also to configure blink modes when hardware control is supported and active.
Trigger will try to use blink_set and a LED driver will use the trigger_data to configure the blink_modes once blink_set is called. Setting a brightness to LED_OFF will reset any blink mode and disable hardware control setting the LED off.

---
 Documentation/leds/leds-class.rst | 17 +++++++++++++++++
 drivers/leds/led-class.c          |  7 +++++++
 include/linux/leds.h              |  9 +++++++++
 3 files changed, 33 insertions(+)
Documentation/leds/leds-class.rst +17 -0
index 0175954717a3..c06a18b811de 100644
@@ -202,6 +202,23 @@ hardware mode and any software only trigger will reject activation.
 On init a LED driver that support a hardware mode should reset every blink mode
 set by default.
 
+Once a trigger has declared support for hardware-controller blinks, it will use
+blink_set() to try to offload his trigger on activation/configuration.
+blink_set() will return 0 if the requested modes set in trigger_data can be
+controlled by hardware or an error if both the mode bitmap is not supported by
+the hardware or there was a problem in the configuration.
+
+Following blink_set logic, setting brightness to LED_OFF with hardware control active
+will reset any active blink mode and disable hardware control setting the LED to off.
+
+It's in the LED driver's interest to know how to elaborate the trigger data and report support
+for a particular set of blink modes. For this exact reason explicit support for the specific
+trigger is mandatory or the driver returns -EOPNOTSUPP if asked to enter hardware mode
+with a not supported trigger.
+If the driver returns -EOPNOTSUPP on hw_control_configure(), the trigger activation will
+fail as the driver doesn't support that specific hardware blink modes or doesn't know
+how to handle the provided trigger data.
+
 Known Issues
 ============
 
drivers/leds/led-class.c +7 -0
index 98a4dc889344..de39e76a7c6e 100644
@@ -180,6 +180,13 @@ static int led_classdev_check_hw_control_functions(struct led_classdev *led_cdev
 	    led_cdev->hw_control_stop))
 		return -EINVAL;
 
+	/* blink_set is mandatory to configure the blink modes
+	 * in hardware control.
+	 */
+	if ((LED_HARDWARE_CONTROLLED & led_cdev->flags) &&
+	    !led_cdev->blink_set)
+		return -EINVAL;
+
 	return 0;
 }
 #endif
include/linux/leds.h +9 -0
index d64e5768e7ab..81d50269a446 100644
@@ -76,6 +76,7 @@ struct led_classdev {
 	/* Lower 16 bits reflect status */
 #define LED_SUSPENDED		BIT(0)
 #define LED_UNREGISTERING	BIT(1)
+#define LED_HARDWARE_CONTROL	BIT(2)
 	/* Upper 16 bits reflect control information */
 #define LED_CORE_SUSPENDRESUME	BIT(16)
 #define LED_SYSFS_DISABLE	BIT(17)
@@ -123,6 +124,12 @@ struct led_classdev {
 	 * match the values specified exactly.
 	 * Deactivate blinking again when the brightness is set to LED_OFF
 	 * via the brightness_set() callback.
+	 * With LED_HARDWARE_CONTROL set in LED flags blink_set will also
+	 * configure blink modes requested by the current trigger if
+	 * supported by the LED driver.
+	 * Setting brightness to LED_OFF with hardware control active will
+	 * reset any active blink mode and disable hardware control setting
+	 * the LED off.
 	 */
 	int		(*blink_set)(struct led_classdev *led_cdev,
 				     unsigned long *delay_on,
@@ -166,6 +173,8 @@ struct led_classdev {
 	 */
 	bool			(*hw_control_status)(struct led_classdev *led_cdev);
 	/* Set LED in hardware mode and reset any blink mode active by default.
+	 * A trigger supporting hardware mode will have to use blink_set to configure
+	 * the modes.
 	 */
 	int			(*hw_control_start)(struct led_classdev *led_cdev);
 	/* Disable hardware mode for LED. It's advised to the LED driver to put it to
Signature · 1 line
2.32.0
author maintainer
#7 lore raw

RFC PATCH v4 3/8 leds: trigger: netdev: drop NETDEV_LED_MODE_LINKUP from mode

In reply to Ansuel Smith

NETDEV_LED_MODE_LINKUP is not strictly a blink mode but really a status of the current situation of the carrier. It seems wrong to accomunate a link status to the blink mode list and would cause some confusion as someone would think that MODE_LINKUP is a separate mode that provide the netdev trigger with the other 3 LINK, RX and TX.

Drop NETDEV_LED_MODE_LINKUP from mode list and convert to a simple bool that will be true or false based on the carrier link. No functional change intended.

---
 drivers/leds/trigger/ledtrig-netdev.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/leds/trigger/ledtrig-netdev.c +7 -9
index d5e774d83021..66a81cc9b64d 100644
@@ -50,10 +50,10 @@ struct led_netdev_data {
 	unsigned int last_activity;
 
 	unsigned long mode;
+	bool carrier_link_up;
 #define NETDEV_LED_LINK	0
 #define NETDEV_LED_TX	1
 #define NETDEV_LED_RX	2
-#define NETDEV_LED_MODE_LINKUP	3
 };
 
 enum netdev_led_attr {
@@ -73,9 +73,9 @@ static void set_baseline_state(struct led_netdev_data *trigger_data)
 	if (!led_cdev->blink_brightness)
 		led_cdev->blink_brightness = led_cdev->max_brightness;
 
-	if (!test_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode))
+	if (!trigger_data->carrier_link_up) {
 		led_set_brightness(led_cdev, LED_OFF);
-	else {
+	} else {
 		if (test_bit(NETDEV_LED_LINK, &trigger_data->mode))
 			led_set_brightness(led_cdev,
 					   led_cdev->blink_brightness);
@@ -131,10 +131,9 @@ static ssize_t device_name_store(struct device *dev,
 		trigger_data->net_dev =
 		    dev_get_by_name(&init_net, trigger_data->device_name);
 
-	clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
+	trigger_data->carrier_link_up = false;
 	if (trigger_data->net_dev != NULL)
-		if (netif_carrier_ok(trigger_data->net_dev))
-			set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
+		trigger_data->carrier_link_up = netif_carrier_ok(trigger_data->net_dev);
 
 	trigger_data->last_activity = 0;
 
@@ -315,7 +314,7 @@ static int netdev_trig_notify(struct notifier_block *nb,
 
 	spin_lock_bh(&trigger_data->lock);
 
-	clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
+	trigger_data->carrier_link_up = false;
 	switch (evt) {
 	case NETDEV_CHANGENAME:
 	case NETDEV_REGISTER:
@@ -330,8 +329,7 @@ static int netdev_trig_notify(struct notifier_block *nb,
 		break;
 	case NETDEV_UP:
 	case NETDEV_CHANGE:
-		if (netif_carrier_ok(dev))
-			set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
+		trigger_data->carrier_link_up = netif_carrier_ok(dev);
 		break;
 	}
 
Signature · 1 line
2.32.0
author maintainer
#8 lore raw

RFC PATCH v4 4/8 leds: trigger: netdev: rename and expose NETDEV trigger enum and struct

In reply to Ansuel Smith

A LED driver, to support hardware control, requires to support a specific trigger and requires to elaborate his trigger_data struct. Move netdev trigger data struct to leds.h to make it accessible by any LED driver that wants to add support for hardware control for the specific netdev trigger.
Also rename NETDEV trigger enum modes to a more symbolic and descriptive name.

---
 drivers/leds/trigger/ledtrig-netdev.c | 48 ++++++++-------------------
 include/linux/leds.h                  | 27 +++++++++++++++
 2 files changed, 41 insertions(+), 34 deletions(-)
drivers/leds/trigger/ledtrig-netdev.c +14 -34
index 66a81cc9b64d..01e4544fa7b0 100644
@@ -36,26 +36,6 @@
  *
  */
 
-struct led_netdev_data {
-	spinlock_t lock;
-
-	struct delayed_work work;
-	struct notifier_block notifier;
-
-	struct led_classdev *led_cdev;
-	struct net_device *net_dev;
-
-	char device_name[IFNAMSIZ];
-	atomic_t interval;
-	unsigned int last_activity;
-
-	unsigned long mode;
-	bool carrier_link_up;
-#define NETDEV_LED_LINK	0
-#define NETDEV_LED_TX	1
-#define NETDEV_LED_RX	2
-};
-
 enum netdev_led_attr {
 	NETDEV_ATTR_LINK,
 	NETDEV_ATTR_TX,
@@ -76,7 +56,7 @@ static void set_baseline_state(struct led_netdev_data *trigger_data)
 	if (!trigger_data->carrier_link_up) {
 		led_set_brightness(led_cdev, LED_OFF);
 	} else {
-		if (test_bit(NETDEV_LED_LINK, &trigger_data->mode))
+		if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode))
 			led_set_brightness(led_cdev,
 					   led_cdev->blink_brightness);
 		else
@@ -85,8 +65,8 @@ static void set_baseline_state(struct led_netdev_data *trigger_data)
 		/* If we are looking for RX/TX start periodically
 		 * checking stats
 		 */
-		if (test_bit(NETDEV_LED_TX, &trigger_data->mode) ||
-		    test_bit(NETDEV_LED_RX, &trigger_data->mode))
+		if (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ||
+		    test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode))
 			schedule_delayed_work(&trigger_data->work, 0);
 	}
 }
@@ -153,13 +133,13 @@ static ssize_t netdev_led_attr_show(struct device *dev, char *buf,
 
 	switch (attr) {
 	case NETDEV_ATTR_LINK:
-		bit = NETDEV_LED_LINK;
+		bit = TRIGGER_NETDEV_LINK;
 		break;
 	case NETDEV_ATTR_TX:
-		bit = NETDEV_LED_TX;
+		bit = TRIGGER_NETDEV_TX;
 		break;
 	case NETDEV_ATTR_RX:
-		bit = NETDEV_LED_RX;
+		bit = TRIGGER_NETDEV_RX;
 		break;
 	default:
 		return -EINVAL;
@@ -182,13 +162,13 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf,
 
 	switch (attr) {
 	case NETDEV_ATTR_LINK:
-		bit = NETDEV_LED_LINK;
+		bit = TRIGGER_NETDEV_LINK;
 		break;
 	case NETDEV_ATTR_TX:
-		bit = NETDEV_LED_TX;
+		bit = TRIGGER_NETDEV_TX;
 		break;
 	case NETDEV_ATTR_RX:
-		bit = NETDEV_LED_RX;
+		bit = TRIGGER_NETDEV_RX;
 		break;
 	default:
 		return -EINVAL;
@@ -358,21 +338,21 @@ static void netdev_trig_work(struct work_struct *work)
 	}
 
 	/* If we are not looking for RX/TX then return  */
-	if (!test_bit(NETDEV_LED_TX, &trigger_data->mode) &&
-	    !test_bit(NETDEV_LED_RX, &trigger_data->mode))
+	if (!test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) &&
+	    !test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode))
 		return;
 
 	dev_stats = dev_get_stats(trigger_data->net_dev, &temp);
 	new_activity =
-	    (test_bit(NETDEV_LED_TX, &trigger_data->mode) ?
+	    (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ?
 		dev_stats->tx_packets : 0) +
-	    (test_bit(NETDEV_LED_RX, &trigger_data->mode) ?
+	    (test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode) ?
 		dev_stats->rx_packets : 0);
 
 	if (trigger_data->last_activity != new_activity) {
 		led_stop_software_blink(trigger_data->led_cdev);
 
-		invert = test_bit(NETDEV_LED_LINK, &trigger_data->mode);
+		invert = test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode);
 		interval = jiffies_to_msecs(
 				atomic_read(&trigger_data->interval));
 		/* base state is ON (link present) */
include/linux/leds.h +27 -0
index 81d50269a446..bc3c54eb269a 100644
@@ -505,6 +505,33 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
 
 #endif /* CONFIG_LEDS_TRIGGERS */
 
+/* Trigger specific trigger_data used by netdev trigger */
+#ifdef CONFIG_LEDS_TRIGGER_NETDEV
+struct led_netdev_data {
+	spinlock_t lock;
+
+	struct delayed_work work;
+	struct notifier_block notifier;
+
+	struct led_classdev *led_cdev;
+	struct net_device *net_dev;
+
+	char device_name[IFNAMSIZ];
+	atomic_t interval;
+	unsigned int last_activity;
+
+	unsigned long mode;
+	bool carrier_link_up;
+};
+
+/* Trigger specific bitmap blink mode used by netdev trigger */
+enum led_trigger_netdev_modes {
+	TRIGGER_NETDEV_LINK,
+	TRIGGER_NETDEV_TX,
+	TRIGGER_NETDEV_RX,
+};
+#endif
+
 /* Trigger specific functions */
 #ifdef CONFIG_LEDS_TRIGGER_DISK
 void ledtrig_disk_activity(bool write);
Signature · 1 line
2.32.0
author maintainer
#10 lore raw

RFC PATCH v4 5/8 leds: trigger: netdev: add hardware control support

In reply to Ansuel Smith

Add hardware control support for the Netdev trigger.
The trigger on config change will check if the requested trigger can set to blink mode using LED hardware mode and if every blink mode is supported, the trigger will enable hardware mode with the requested configuration. If there is at least one trigger that is not supported and can't run in hardware mode, then software mode will be used instead.

---
 drivers/leds/trigger/ledtrig-netdev.c | 30 +++++++++++++++++++++++++--
 include/linux/leds.h                  |  3 +++
 2 files changed, 31 insertions(+), 2 deletions(-)
drivers/leds/trigger/ledtrig-netdev.c +28 -2
index 01e4544fa7b0..74c9a6ecfbbf 100644
@@ -44,9 +44,31 @@ enum netdev_led_attr {
 
 static void set_baseline_state(struct led_netdev_data *trigger_data)
 {
-	int current_brightness;
+	int current_brightness, can_offload;
 	struct led_classdev *led_cdev = trigger_data->led_cdev;
 
+	if (LED_HARDWARE_CONTROLLED & led_cdev->flags) {
+		/* Check if blink mode can he set in hardware mode.
+		 * The LED driver will chose a interval based on the trigger_data
+		 * and its implementation.
+		 */
+		can_offload = led_cdev->blink_set(led_cdev, 0, 0);
+
+		/* If blink_set doesn't return error we can run in hardware mode
+		 * So actually activate it.
+		 */
+		if (!can_offload) {
+			led_cdev->hw_control_start(led_cdev);
+			return;
+		}
+	}
+
+	/* If LED supports only hardware mode and we reach this point,
+	 * then skip any software handling.
+	 */
+	if (!(LED_SOFTWARE_CONTROLLED & led_cdev->flags))
+		return;
+
 	current_brightness = led_cdev->brightness;
 	if (current_brightness)
 		led_cdev->blink_brightness = current_brightness;
@@ -395,8 +417,11 @@ static int netdev_trig_activate(struct led_classdev *led_cdev)
 
 	rc = register_netdevice_notifier(&trigger_data->notifier);
 	if (rc)
-		kfree(trigger_data);
+		goto err;
 
+	return 0;
+err:
+	kfree(trigger_data);
 	return rc;
 }
 
@@ -416,6 +441,7 @@ static void netdev_trig_deactivate(struct led_classdev *led_cdev)
 
 static struct led_trigger netdev_led_trigger = {
 	.name = "netdev",
+	.supported_blink_modes = SOFTWARE_HARDWARE,
 	.activate = netdev_trig_activate,
 	.deactivate = netdev_trig_deactivate,
 	.groups = netdev_trig_groups,
include/linux/leds.h +3 -0
index bc3c54eb269a..dd41acd564a3 100644
@@ -17,6 +17,9 @@
 #include <linux/spinlock.h>
 #include <linux/timer.h>
 #include <linux/workqueue.h>
+#ifdef CONFIG_LEDS_TRIGGER_NETDEV
+#include <linux/netdevice.h>
+#endif
 
 struct device;
 struct led_pattern;
Signature · 1 line
2.32.0
author maintainer
#13 lore raw

RFC PATCH v4 6/8 leds: trigger: add hardware-phy-activity trigger

In reply to Ansuel Smith

Add Hardware Only Trigger for PHY Activity. This special trigger is used to configure and expose the different HW trigger that are provided by the PHY. Each blink mode can be configured by sysfs and on trigger activation the hardware 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
- 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
- option_linkup_over: Ignore blink tx/rx with link keep not active
- option_power_on_reset: Keep LED on with switch reset

The trigger will check if the LED driver support the various blink modes and will expose the blink modes in sysfs.
It will finally enable hw mode for the LED without configuring any rule. It's in the led driver interest the detection and knowing how to elaborate the passed flags and should report -EOPNOTSUPP otherwise.

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

---
 drivers/leds/trigger/Kconfig                  |  28 +++
 drivers/leds/trigger/Makefile                 |   1 +
 .../trigger/ledtrig-hardware-phy-activity.c   | 180 ++++++++++++++++++
 include/linux/leds.h                          |  24 +++
 4 files changed, 233 insertions(+)
 create mode 100644 drivers/leds/trigger/ledtrig-hardware-phy-activity.c
drivers/leds/trigger/Kconfig +28 -0
index dc6816d36d06..737a8be533a3 100644
@@ -154,4 +154,32 @@ config LEDS_TRIGGER_TTY
 
 	  When build as a module this driver will be called ledtrig-tty.
 
+config LEDS_TRIGGER_HARDWARE_PHY_ACTIVITY
+	tristate "LED Trigger for PHY Activity for Hardware Controlled LED"
+	depends on LEDS_HARDWARE_CONTROL
+	help
+	  This allows LEDs to be configured to run by hardware and offloaded
+	  based on some rules. The LED will blink or be on based on the PHY
+	  activity for example on packet receive or based on the link speed.
+
+	  The current supported offload triggers are:
+	  - blink_tx: Blink LED on tx packet receive
+	  - blink_rx: Blink LED on rx packet receive
+	  - keep_link_10m: Keep LED on with 10m link speed
+	  - keep_link_100m: Keep LED on with 100m link speed
+	  - keep_link_1000m: Keep LED on with 1000m link speed
+	  - keep_half_duplex: Keep LED on with half duplex link
+	  - keep_full_duplex: Keep LED on with full duplex link
+	  - option_linkup_over: Blink rules are ignored with absent link
+	  - option_power_on_reset: Power ON Led on Switch/PHY reset
+	  - option_blink_2hz: Set blink speed at 2hz for every blink event
+	  - option_blink_4hz: Set blink speed at 4hz for every blink event
+	  - option_blink_8hz: Set blink speed at 8hz for every blink event
+
+	  These blink modes are present in the LED sysfs dir under
+	  hardware-phy-activity if supported by the LED driver.
+
+	  This trigger can be used only by LEDs that support Hardware mode.
+
+
 endif # LEDS_TRIGGERS
drivers/leds/trigger/Makefile +1 -0
index 25c4db97cdd4..f5d0d0057d2b 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_TRIGGER_HARDWARE_PHY_ACTIVITY) += ledtrig-hardware-phy-activity.o
drivers/leds/trigger/ledtrig-hardware-phy-activity.c new file +180 -0

180 lines not on this page · raw message

include/linux/leds.h +24 -0
index dd41acd564a3..1aeeb943290a 100644
@@ -535,6 +535,30 @@ enum led_trigger_netdev_modes {
 };
 #endif
 
+#ifdef CONFIG_LEDS_TRIGGER_HARDWARE_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 hardware_phy_activity {
+	TRIGGER_PHY_ACTIVITY_BLINK_TX, /* Blink on TX traffic */
+	TRIGGER_PHY_ACTIVITY_BLINK_RX, /* Blink on RX traffic */
+	TRIGGER_PHY_ACTIVITY_LINK_10M, /* LED on with 10M link */
+	TRIGGER_PHY_ACTIVITY_LINK_100M, /* LED on with 100M link */
+	TRIGGER_PHY_ACTIVITY_LINK_1000M, /* LED on with 1000M link */
+	TRIGGER_PHY_ACTIVITY_HALF_DUPLEX, /* LED on with Half-Duplex link */
+	TRIGGER_PHY_ACTIVITY_FULL_DUPLEX, /* LED on with Full-Duplex link */
+	TRIGGER_PHY_ACTIVITY_OPTION_LINKUP_OVER, /* LED will be on with KEEP blink mode and blink on BLINK traffic */
+	TRIGGER_PHY_ACTIVITY_OPTION_POWER_ON_RESET, /* LED will be on Switch reset */
+};
+
+struct hardware_phy_activity_data {
+	unsigned long mode;
+	struct attribute_group *group;
+};
+#endif
+
 /* Trigger specific functions */
 #ifdef CONFIG_LEDS_TRIGGER_DISK
 void ledtrig_disk_activity(bool write);
Signature · 1 line
2.32.0
author maintainer
#17 lore raw

RFC PATCH v4 8/8 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    | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/devicetree/bindings/net/dsa/qca8k.yaml +20 -0
index 48de0ace265d..106d95adc1e8 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,24 @@ 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";
+                        };
+
+                        led@1 {
+                            reg = <1>;
+                            color = <LED_COLOR_ID_AMBER>;
+                            function = LED_FUNCTION_LAN;
+                            function-enumerator = <1>;
+                            linux,default-trigger = "offload-phy-activity";
+                        };
+                    };
                 };
 
                 internal_phy_port2: ethernet-phy@1 {
Signature · 1 line
2.32.0
author maintainer
#15 lore raw

RFC PATCH v4 7/8 net: dsa: qca8k: add LEDs support

In reply to Ansuel Smith

Add LEDs support for qca8k Switch Family. This will provide the LEDs hardware API to permit the PHY LED to support hardware mode. Each port have at least 3 LEDs and they can HW blink, set on/off or follow blink modes configured with the LED in hardware mode.. This adds support for 2 hardware trigger netdev and hardware-phy-activity.

---
 drivers/net/dsa/Kconfig      |   9 +
 drivers/net/dsa/Makefile     |   1 +
 drivers/net/dsa/qca8k-leds.c | 423 +++++++++++++++++++++++++++++++++++
 drivers/net/dsa/qca8k.c      |   8 +-
 drivers/net/dsa/qca8k.h      |  65 ++++++
 5 files changed, 504 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/dsa/qca8k-leds.c
drivers/net/dsa/Kconfig +9 -0
index 7b1457a6e327..9f4bae5cc43d 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
+	  This enables 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 +423 -0

423 lines not on this page · raw message

drivers/net/dsa/qca8k.c +6 -2
index a429c9750add..10b2b47b2156 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;
@@ -1109,6 +1109,10 @@ qca8k_setup(struct dsa_switch *ds)
 	if (ret)
 		return ret;
 
+	ret = qca8k_setup_led_ctrl(priv);
+	if (ret)
+		return ret;
+
 	/* Make sure MAC06 is disabled */
 	ret = qca8k_reg_clear(priv, QCA8K_REG_PORT0_PAD_CTRL,
 			      QCA8K_PORT0_PAD_MAC06_EXCHANGE_EN);
drivers/net/dsa/qca8k.h +65 -0

93 lines not on this page · raw message

Signature · 1 line
2.32.0
#18 lore raw
In reply to Ansuel Smith
Quoted 36 lines · On Thu, 11 Nov 2021 02:34:52 +0100 Ansuel Smith <[email protected]> wrote:

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 3 API (hw_control_status/start/stop). They are used to put the LED in hardware mode and to configure the various trigger.
- We have hardware triggers that are used to expose to userspace the supported hardware mode and set the hardware mode on trigger activation.
- We can also have triggers that both support hardware and software mode.
- The LED driver will declare each supported hardware blink mode and communicate with the trigger all the supported blink modes that will be available by sysfs.
- A trigger will use blink_set to configure the blink mode to active in hardware mode.
- On hardware trigger activation, only the hardware mode is enabled but the blink modes are not configured. The LED driver should reset any link mode active by default.

Each LED driver will have to declare explicit support for the offload trigger (or return not supported error code) as we the trigger_data 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.

Quoted 5 lines

I also posted the netdev trigger expanded with the hardware support.

More polish is required but this is just to understand if I'm taking the correct path with this implementation hoping we find a correct implementation and we start working on the ""small details""

Hello Ansuel,

besides other things, I am still against the idea of the hardware-phy-activity trigger: I think that if the user wants the LED to indicate network device's link status or activity, it should always be done via the existing netdev trigger, and with that trigger only.

Yes, I know that netdev trigger does not currently support indicating different link modes, only whether the link is up (in any mode). That should be solved by extending the netdev trigger.

I am going to try to revive my last attempt and send my proposal again. Hope you don't mind.

Marek

reviewer
#14 lore raw

Re: [RFC PATCH v4 6/8] leds: trigger: add hardware-phy-activity trigger

In reply to Ansuel Smith

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

Quoted 13 lines · Ansuel Smith
drivers/leds/trigger/Kconfig +5 -0
index dc6816d36d06..737a8be533a3 100644
@@ -154,4 +154,32 @@ config LEDS_TRIGGER_TTY
 
  	  When build as a module this driver will be called ledtrig-tty.
 
+config LEDS_TRIGGER_HARDWARE_PHY_ACTIVITY
+	tristate "LED Trigger for PHY Activity for Hardware Controlled LED"
+	depends on LEDS_HARDWARE_CONTROL
+	help
+	  This allows LEDs to be configured to run by hardware and offloaded

to be run

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

Quoted 1 line
drivers/leds/trigger/Kconfig +1 -0
+	  based on some rules. The LED will blink or be on based on the PHY

or be "on" based on

Quoted 20 lines
drivers/leds/trigger/Kconfig +20 -0
+	  activity for example on packet receive or based on the link speed.
+
+	  The current supported offload triggers are:
+	  - blink_tx: Blink LED on tx packet receive
+	  - blink_rx: Blink LED on rx packet receive
+	  - keep_link_10m: Keep LED on with 10m link speed
+	  - keep_link_100m: Keep LED on with 100m link speed
+	  - keep_link_1000m: Keep LED on with 1000m link speed
+	  - keep_half_duplex: Keep LED on with half duplex link
+	  - keep_full_duplex: Keep LED on with full duplex link
+	  - option_linkup_over: Blink rules are ignored with absent link
+	  - option_power_on_reset: Power ON Led on Switch/PHY reset
+	  - option_blink_2hz: Set blink speed at 2hz for every blink event
+	  - option_blink_4hz: Set blink speed at 4hz for every blink event
+	  - option_blink_8hz: Set blink speed at 8hz for every blink event
+
+	  These blink modes are present in the LED sysfs dir under
+	  hardware-phy-activity if supported by the LED driver.
+
+	  This trigger can be used only by LEDs that support Hardware mode.
Signature · 1 line
~Randy
reviewer
#16 lore raw

Re: [RFC PATCH v4 7/8] net: dsa: qca8k: add LEDs support

In reply to Ansuel Smith
Quoted 5 lines · Ansuel Smith
drivers/net/dsa/Kconfig +0 -0
index 7b1457a6e327..9f4bae5cc43d 100644

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

Quoted 10 lines
drivers/net/dsa/Kconfig +7 -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
+	  This enables support for LEDs present on the Qualcomm Atheros
+	  QCA8K Ethernet switch chips. This require the LEDs offload

This requires

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

Re: [RFC PATCH v4 1/8] leds: add support for hardware driven LEDs

In reply to Ansuel Smith

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

Quoted 12 lines · Ansuel Smith
Documentation/leds/leds-class.rst +4 -0
index cd155ead8703..0175954717a3 100644
@@ -169,6 +169,38 @@ 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 driven LEDs
+===================================
+
+Some LEDs can be driven by hardware (for example a LED connected to

an LED

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

Quoted 10 lines
Documentation/leds/leds-class.rst +10 -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 this and a supported trigger must
+be used.
+
+LED driver should declare the correct control mode supported and should set
+the LED_SOFTWARE_CONTROLLED or LED_HARDWARE_CONTROLLED bit in the flags
+parameter.
+The trigger will check these bit and fail to activate if the control mode

bits

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

Quoted 2 lines
Documentation/leds/leds-class.rst +2 -0
+is not supported. By default if a LED driver doesn't declare a control mode,
+bit LED_SOFTWARE_CONTROLLED is assumed and set by default.

drop the second: by default

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

Quoted 2 lines
Documentation/leds/leds-class.rst +2 -0
+
+The LED must implement 3 main API:

APIs:

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

Quoted 7 lines
Documentation/leds/leds-class.rst +7 -0
+- hw_control_status(): This asks the LED driver if hardware mode is enabled
+    or not.
+- hw_control_start(): This will simply enable the hardware mode for the LED
+    and the LED driver should reset any active blink_mode.
+- hw_control_stop(): This will simply disable the hardware mode for the LED.
+    It's advised to the driver to put the LED in the old state but this is not
+    enforcerd and putting the LED off is also accepted.

enforced

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

Quoted 2 lines
Documentation/leds/leds-class.rst +2 -0
+
+If LED_HARDWARE_CONTROLLED bit is the only contro mode set (LED_SOFTWARE_CONTROLLED

control

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

Quoted 4 lines
Documentation/leds/leds-class.rst +4 -0
+not set) set hw_control_status/start/stop is optional as the LED supports only
+hardware mode and any software only trigger will reject activation.
+
+On init a LED driver that support a hardware mode should reset every blink mode

an LED

Quoted 9 lines
Documentation/leds/leds-class.rst +1 -0
+set by default.
 
  Known Issues
  ============
drivers/leds/Kconfig +0 -0
index ed800f5da7d8..bd2b19cc77ec 100644

drivers/leds/Kconfig config LEDS_BRIGHTNESS_HW_CHANGED · line 55

Quoted 7 lines
drivers/leds/Kconfig +4 -0
@@ -49,6 +49,17 @@ config LEDS_BRIGHTNESS_HW_CHANGED
 
  	  See Documentation/ABI/testing/sysfs-class-led for details.
 
+config LEDS_HARDWARE_CONTROL
+	bool "LED Hardware Control support"
+	help
+	  This option enabled Hardware control support used by leds that

enables LEDs

Quoted 6 lines
drivers/leds/Kconfig +6 -0
+	  can be driven in hardware by using supported triggers.
+
+	  Hardware blink modes will be exposed by sysfs class in
+	  /sys/class/leds based on the trigger currently active.
+
+	  If unsure, say Y.
Signature · 1 line
~Randy
reviewer
#6 lore raw

Re: [RFC PATCH v4 2/8] leds: document additional use of blink_set for hardware control

In reply to Ansuel Smith

Hi Ansuel,

Sorry -- I screwed this one up a little bit on the previous iteration.

Documentation/leds/leds-class.rst hardware mode and any software only trigger will reject activation. · line 205

Quoted 9 lines · Ansuel Smith
Documentation/leds/leds-class.rst +1 -0
index 0175954717a3..c06a18b811de 100644
@@ -202,6 +202,23 @@ hardware mode and any software only trigger will reject activation.
  On init a LED driver that support a hardware mode should reset every blink mode
  set by default.
 
+Once a trigger has declared support for hardware-controller blinks, it will use

hardware-controlled

Documentation/leds/leds-class.rst hardware mode and any software only trigger will reject activation. · line 208

Quoted 3 lines
Documentation/leds/leds-class.rst +3 -0
+blink_set() to try to offload his trigger on activation/configuration.
+blink_set() will return 0 if the requested modes set in trigger_data can be
+controlled by hardware or an error if both the mode bitmap is not supported by

maybe: if both of the bitmap modes are not supported by

Documentation/leds/leds-class.rst hardware mode and any software only trigger will reject activation. · line 219

Quoted 11 lines
Documentation/leds/leds-class.rst +11 -0
+the hardware or there was a problem in the configuration.
+
+Following blink_set logic, setting brightness to LED_OFF with hardware control active
+will reset any active blink mode and disable hardware control setting the LED to off.
+
+It's in the LED driver's interest to know how to elaborate the trigger data and report support
+for a particular set of blink modes. For this exact reason explicit support for the specific
+trigger is mandatory or the driver returns -EOPNOTSUPP if asked to enter hardware mode
+with a not supported trigger.
+If the driver returns -EOPNOTSUPP on hw_control_configure(), the trigger activation will
+fail as the driver doesn't support that specific hardware blink modes or doesn't know

mode

Documentation/leds/leds-class.rst hardware mode and any software only trigger will reject activation. · line 220

Quoted 1 line
Documentation/leds/leds-class.rst +1 -0
+how to handle the provided trigger data.

thanks.

Signature · 1 line
~Randy
#3 lore raw

Re: [RFC PATCH v4 1/8] leds: add support for hardware driven LEDs

In reply to Ansuel Smith
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Ansuel,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[also build test ERROR on linus/master next-20211110]
[cannot apply to pavel-leds/for-next robh/for-next net-next/master v5.15] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ansuel-Smith/Adds-support-for-PHY-LEDs-with-offload-triggers/20211111-093724
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git e5d5aadcf3cd59949316df49c27cb21788d7efe4
config: openrisc-buildonly-randconfig-r003-20211111 (attached as .config)
compiler: or1k-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/c56c3d000ada0de02ec9ecf03e93327733b91930
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ansuel-Smith/Adds-support-for-PHY-LEDs-with-offload-triggers/20211111-093724
git checkout c56c3d000ada0de02ec9ecf03e93327733b91930
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=openrisc SHELL=/bin/bash drivers/i2c/ drivers/leds/ kernel/bpf/

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/leds/led-triggers.c: In function 'led_trigger_set':

>> drivers/leds/led-triggers.c:198:29: error: 'struct led_classdev' has no member named 'hw_control_status'
     198 |                     led_cdev->hw_control_status(led_cdev))
         |                             ^~
>> drivers/leds/led-triggers.c:199:33: error: 'struct led_classdev' has no member named 'hw_control_stop'
     199 |                         led_cdev->hw_control_stop(led_cdev);
         |                                 ^~

vim +198 drivers/leds/led-triggers.c

170
171 /* Caller must ensure led_cdev->trigger_lock held */
172 int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
173 {
174 char *event = NULL;
175 char *envp[2];
176 const char *name;
177 int ret;
178
179 if (!led_cdev->trigger && !trig)
180 return 0;
181
182 name = trig ? trig->name : "none";
183 event = kasprintf(GFP_KERNEL, "TRIGGER=%s", name);
184
185 /* Remove any existing trigger */
186 if (led_cdev->trigger) {
187 spin_lock(&led_cdev->trigger->leddev_list_lock);
188 list_del_rcu(&led_cdev->trig_list);
189 spin_unlock(&led_cdev->trigger->leddev_list_lock);
190
191 /* ensure it's no longer visible on the led_cdevs list */
192 synchronize_rcu();
193
194 cancel_work_sync(&led_cdev->set_brightness_work);
195 led_stop_software_blink(led_cdev);
196 /* Disable hardware mode on trigger change if supported */
197 if ((led_cdev->flags & LED_HARDWARE_CONTROLLED) &&

 > 198			    led_cdev->hw_control_status(led_cdev))
 > 199				led_cdev->hw_control_stop(led_cdev);

200 if (led_cdev->trigger->deactivate)
201 led_cdev->trigger->deactivate(led_cdev);
202 device_remove_groups(led_cdev->dev, led_cdev->trigger->groups);
203 led_cdev->trigger = NULL;
204 led_cdev->trigger_data = NULL;
205 led_cdev->activated = false;
206 led_set_brightness(led_cdev, LED_OFF);
207 }
208 if (trig) {
209 /* Make sure the trigger support the LED blink mode */
210 if (!led_trigger_is_supported(led_cdev, trig))
211 return -EINVAL;
212
213 spin_lock(&trig->leddev_list_lock);
214 list_add_tail_rcu(&led_cdev->trig_list, &trig->led_cdevs);
215 spin_unlock(&trig->leddev_list_lock);
216 led_cdev->trigger = trig;
217
218 if (trig->activate)
219 ret = trig->activate(led_cdev);
220 else
221 ret = 0;
222
223 if (ret)
224 goto err_activate;
225
226 ret = device_add_groups(led_cdev->dev, trig->groups);
227 if (ret) {
228 dev_err(led_cdev->dev, "Failed to add trigger attributes\n");
229 goto err_add_groups;
230 }
231 }
232
233 if (event) {
234 envp[0] = event;
235 envp[1] = NULL;
236 if (kobject_uevent_env(&led_cdev->dev->kobj, KOBJ_CHANGE, envp))
237 dev_err(led_cdev->dev,
238 "%s: Error sending uevent\n", __func__);
239 kfree(event);
240 }
241
242 return 0;
243
244 err_add_groups:
245
246 if (trig->deactivate)
247 trig->deactivate(led_cdev);
248 err_activate:
249
250 spin_lock(&led_cdev->trigger->leddev_list_lock);
251 list_del_rcu(&led_cdev->trig_list);
252 spin_unlock(&led_cdev->trigger->leddev_list_lock);
253 synchronize_rcu();
254 led_cdev->trigger = NULL;
255 led_cdev->trigger_data = NULL;
256 led_set_brightness(led_cdev, LED_OFF);
257 kfree(event);
258
259 return ret;
260 }
261 EXPORT_SYMBOL_GPL(led_trigger_set);
262

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#11 lore raw

Re: [RFC PATCH v4 5/8] leds: trigger: netdev: add hardware control support

In reply to Ansuel Smith
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Ansuel,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[also build test ERROR on linus/master next-20211111]
[cannot apply to pavel-leds/for-next robh/for-next net-next/master v5.15] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ansuel-Smith/Adds-support-for-PHY-LEDs-with-offload-triggers/20211111-093724
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git e5d5aadcf3cd59949316df49c27cb21788d7efe4
config: openrisc-buildonly-randconfig-r003-20211111 (attached as .config)
compiler: or1k-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/9d84c5c79622ad5b17b116d01303f74a4ae94d10
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ansuel-Smith/Adds-support-for-PHY-LEDs-with-offload-triggers/20211111-093724
git checkout 9d84c5c79622ad5b17b116d01303f74a4ae94d10
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=openrisc SHELL=/bin/bash drivers/i2c/ drivers/leds/trigger/ kernel/bpf/

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/leds/trigger/ledtrig-netdev.c: In function 'set_baseline_state':

>> drivers/leds/trigger/ledtrig-netdev.c:61:33: error: 'struct led_classdev' has no member named 'hw_control_start'
      61 |                         led_cdev->hw_control_start(led_cdev);
         |                                 ^~

vim +61 drivers/leds/trigger/ledtrig-netdev.c

    44	
    45	static void set_baseline_state(struct led_netdev_data *trigger_data)
    46	{
    47		int current_brightness, can_offload;
    48		struct led_classdev *led_cdev = trigger_data->led_cdev;
    49	
    50		if (LED_HARDWARE_CONTROLLED & led_cdev->flags) {
    51			/* Check if blink mode can he set in hardware mode.
    52			 * The LED driver will chose a interval based on the trigger_data
    53			 * and its implementation.
    54			 */
    55			can_offload = led_cdev->blink_set(led_cdev, 0, 0);
    56	
    57			/* If blink_set doesn't return error we can run in hardware mode
    58			 * So actually activate it.
    59			 */
    60			if (!can_offload) {
  > 61				led_cdev->hw_control_start(led_cdev);
    62				return;
    63			}
    64		}
    65	
    66		/* If LED supports only hardware mode and we reach this point,
    67		 * then skip any software handling.
    68		 */
    69		if (!(LED_SOFTWARE_CONTROLLED & led_cdev->flags))
    70			return;
    71	
    72		current_brightness = led_cdev->brightness;
    73		if (current_brightness)
    74			led_cdev->blink_brightness = current_brightness;
    75		if (!led_cdev->blink_brightness)
    76			led_cdev->blink_brightness = led_cdev->max_brightness;
    77	
    78		if (!trigger_data->carrier_link_up) {
    79			led_set_brightness(led_cdev, LED_OFF);
    80		} else {
    81			if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode))
    82				led_set_brightness(led_cdev,
    83						   led_cdev->blink_brightness);
    84			else
    85				led_set_brightness(led_cdev, LED_OFF);
    86	
    87			/* If we are looking for RX/TX start periodically
    88			 * checking stats
    89			 */
    90			if (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ||
    91			    test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode))
    92				schedule_delayed_work(&trigger_data->work, 0);
    93		}
    94	}
    95	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#4 lore raw

Re: [RFC PATCH v4 1/8] leds: add support for hardware driven LEDs

In reply to Ansuel Smith
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Ansuel,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[also build test ERROR on linus/master next-20211111]
[cannot apply to pavel-leds/for-next robh/for-next net-next/master v5.15] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ansuel-Smith/Adds-support-for-PHY-LEDs-with-offload-triggers/20211111-093724
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git e5d5aadcf3cd59949316df49c27cb21788d7efe4
config: riscv-buildonly-randconfig-r002-20211111 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 63ef0e17e28827eae53133b3467bdac7d9729318)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/c56c3d000ada0de02ec9ecf03e93327733b91930
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ansuel-Smith/Adds-support-for-PHY-LEDs-with-offload-triggers/20211111-093724
git checkout c56c3d000ada0de02ec9ecf03e93327733b91930
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash arch/riscv/kernel/ drivers/gpu/drm/ drivers/leds/ net/core/

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/leds/led-triggers.c:198:17: error: no member named 'hw_control_status' in 'struct led_classdev'
                       led_cdev->hw_control_status(led_cdev))
                       ~~~~~~~~  ^
>> drivers/leds/led-triggers.c:199:14: error: no member named 'hw_control_stop' in 'struct led_classdev'
                           led_cdev->hw_control_stop(led_cdev);
                           ~~~~~~~~  ^

2 errors generated.

vim +198 drivers/leds/led-triggers.c

170
171 /* Caller must ensure led_cdev->trigger_lock held */
172 int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
173 {
174 char *event = NULL;
175 char *envp[2];
176 const char *name;
177 int ret;
178
179 if (!led_cdev->trigger && !trig)
180 return 0;
181
182 name = trig ? trig->name : "none";
183 event = kasprintf(GFP_KERNEL, "TRIGGER=%s", name);
184
185 /* Remove any existing trigger */
186 if (led_cdev->trigger) {
187 spin_lock(&led_cdev->trigger->leddev_list_lock);
188 list_del_rcu(&led_cdev->trig_list);
189 spin_unlock(&led_cdev->trigger->leddev_list_lock);
190
191 /* ensure it's no longer visible on the led_cdevs list */
192 synchronize_rcu();
193
194 cancel_work_sync(&led_cdev->set_brightness_work);
195 led_stop_software_blink(led_cdev);
196 /* Disable hardware mode on trigger change if supported */
197 if ((led_cdev->flags & LED_HARDWARE_CONTROLLED) &&

 > 198			    led_cdev->hw_control_status(led_cdev))
 > 199				led_cdev->hw_control_stop(led_cdev);

200 if (led_cdev->trigger->deactivate)
201 led_cdev->trigger->deactivate(led_cdev);
202 device_remove_groups(led_cdev->dev, led_cdev->trigger->groups);
203 led_cdev->trigger = NULL;
204 led_cdev->trigger_data = NULL;
205 led_cdev->activated = false;
206 led_set_brightness(led_cdev, LED_OFF);
207 }
208 if (trig) {
209 /* Make sure the trigger support the LED blink mode */
210 if (!led_trigger_is_supported(led_cdev, trig))
211 return -EINVAL;
212
213 spin_lock(&trig->leddev_list_lock);
214 list_add_tail_rcu(&led_cdev->trig_list, &trig->led_cdevs);
215 spin_unlock(&trig->leddev_list_lock);
216 led_cdev->trigger = trig;
217
218 if (trig->activate)
219 ret = trig->activate(led_cdev);
220 else
221 ret = 0;
222
223 if (ret)
224 goto err_activate;
225
226 ret = device_add_groups(led_cdev->dev, trig->groups);
227 if (ret) {
228 dev_err(led_cdev->dev, "Failed to add trigger attributes\n");
229 goto err_add_groups;
230 }
231 }
232
233 if (event) {
234 envp[0] = event;
235 envp[1] = NULL;
236 if (kobject_uevent_env(&led_cdev->dev->kobj, KOBJ_CHANGE, envp))
237 dev_err(led_cdev->dev,
238 "%s: Error sending uevent\n", __func__);
239 kfree(event);
240 }
241
242 return 0;
243
244 err_add_groups:
245
246 if (trig->deactivate)
247 trig->deactivate(led_cdev);
248 err_activate:
249
250 spin_lock(&led_cdev->trigger->leddev_list_lock);
251 list_del_rcu(&led_cdev->trig_list);
252 spin_unlock(&led_cdev->trigger->leddev_list_lock);
253 synchronize_rcu();
254 led_cdev->trigger = NULL;
255 led_cdev->trigger_data = NULL;
256 led_set_brightness(led_cdev, LED_OFF);
257 kfree(event);
258
259 return ret;
260 }
261 EXPORT_SYMBOL_GPL(led_trigger_set);
262

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#12 lore raw

Re: [RFC PATCH v4 5/8] leds: trigger: netdev: add hardware control support

In reply to Ansuel Smith
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Ansuel,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[also build test ERROR on linus/master next-20211111]
[cannot apply to pavel-leds/for-next robh/for-next net-next/master v5.15] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ansuel-Smith/Adds-support-for-PHY-LEDs-with-offload-triggers/20211111-093724
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git e5d5aadcf3cd59949316df49c27cb21788d7efe4
config: riscv-buildonly-randconfig-r002-20211111 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 63ef0e17e28827eae53133b3467bdac7d9729318)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/9d84c5c79622ad5b17b116d01303f74a4ae94d10
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ansuel-Smith/Adds-support-for-PHY-LEDs-with-offload-triggers/20211111-093724
git checkout 9d84c5c79622ad5b17b116d01303f74a4ae94d10
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash arch/riscv/kernel/ drivers/gpu/drm/ drivers/leds/trigger/ net/core/

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/leds/trigger/ledtrig-netdev.c:61:14: error: no member named 'hw_control_start' in 'struct led_classdev'
                           led_cdev->hw_control_start(led_cdev);
                           ~~~~~~~~  ^

1 error generated.

vim +61 drivers/leds/trigger/ledtrig-netdev.c

    44	
    45	static void set_baseline_state(struct led_netdev_data *trigger_data)
    46	{
    47		int current_brightness, can_offload;
    48		struct led_classdev *led_cdev = trigger_data->led_cdev;
    49	
    50		if (LED_HARDWARE_CONTROLLED & led_cdev->flags) {
    51			/* Check if blink mode can he set in hardware mode.
    52			 * The LED driver will chose a interval based on the trigger_data
    53			 * and its implementation.
    54			 */
    55			can_offload = led_cdev->blink_set(led_cdev, 0, 0);
    56	
    57			/* If blink_set doesn't return error we can run in hardware mode
    58			 * So actually activate it.
    59			 */
    60			if (!can_offload) {
  > 61				led_cdev->hw_control_start(led_cdev);
    62				return;
    63			}
    64		}
    65	
    66		/* If LED supports only hardware mode and we reach this point,
    67		 * then skip any software handling.
    68		 */
    69		if (!(LED_SOFTWARE_CONTROLLED & led_cdev->flags))
    70			return;
    71	
    72		current_brightness = led_cdev->brightness;
    73		if (current_brightness)
    74			led_cdev->blink_brightness = current_brightness;
    75		if (!led_cdev->blink_brightness)
    76			led_cdev->blink_brightness = led_cdev->max_brightness;
    77	
    78		if (!trigger_data->carrier_link_up) {
    79			led_set_brightness(led_cdev, LED_OFF);
    80		} else {
    81			if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode))
    82				led_set_brightness(led_cdev,
    83						   led_cdev->blink_brightness);
    84			else
    85				led_set_brightness(led_cdev, LED_OFF);
    86	
    87			/* If we are looking for RX/TX start periodically
    88			 * checking stats
    89			 */
    90			if (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ||
    91			    test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode))
    92				schedule_delayed_work(&trigger_data->work, 0);
    93		}
    94	}
    95	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#9 lore raw

Re: [RFC PATCH v4 4/8] leds: trigger: netdev: rename and expose NETDEV trigger enum and struct

In reply to Ansuel Smith
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Ansuel,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on net/master]
[also build test WARNING on linus/master next-20211111] [cannot apply to pavel-leds/for-next robh/for-next net-next/master v5.15] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ansuel-Smith/Adds-support-for-PHY-LEDs-with-offload-triggers/20211111-093724
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git e5d5aadcf3cd59949316df49c27cb21788d7efe4
config: microblaze-buildonly-randconfig-r001-20211111 (attached as .config)
compiler: microblaze-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/e8e8713b4128f4d9108d4326c95e2adc9b302971
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ansuel-Smith/Adds-support-for-PHY-LEDs-with-offload-triggers/20211111-093724
git checkout e8e8713b4128f4d9108d4326c95e2adc9b302971
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=microblaze SHELL=/bin/bash drivers/i2c/ drivers/leds/trigger/ kernel/bpf/

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/leds/trigger/ledtrig-netdev.c:45:39: warning: 'struct led_netdev_data' declared inside parameter list will not be visible outside of this definition or declaration
      45 | static void set_baseline_state(struct led_netdev_data *trigger_data)
         |                                       ^~~~~~~~~~~~~~~
   drivers/leds/trigger/ledtrig-netdev.c: In function 'set_baseline_state':
   drivers/leds/trigger/ledtrig-netdev.c:48:53: error: invalid use of undefined type 'struct led_netdev_data'
      48 |         struct led_classdev *led_cdev = trigger_data->led_cdev;
         |                                                     ^~
   drivers/leds/trigger/ledtrig-netdev.c:56:26: error: invalid use of undefined type 'struct led_netdev_data'
      56 |         if (!trigger_data->carrier_link_up) {
         |                          ^~
   drivers/leds/trigger/ledtrig-netdev.c:59:30: error: 'TRIGGER_NETDEV_LINK' undeclared (first use in this function)
      59 |                 if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode))
         |                              ^~~~~~~~~~~~~~~~~~~
   drivers/leds/trigger/ledtrig-netdev.c:59:30: note: each undeclared identifier is reported only once for each function it appears in
   drivers/leds/trigger/ledtrig-netdev.c:59:64: error: invalid use of undefined type 'struct led_netdev_data'
      59 |                 if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode))
         |                                                                ^~
   drivers/leds/trigger/ledtrig-netdev.c:68:30: error: 'TRIGGER_NETDEV_TX' undeclared (first use in this function)
      68 |                 if (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ||
         |                              ^~~~~~~~~~~~~~~~~
   drivers/leds/trigger/ledtrig-netdev.c:68:62: error: invalid use of undefined type 'struct led_netdev_data'
      68 |                 if (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ||
         |                                                              ^~
   drivers/leds/trigger/ledtrig-netdev.c:69:30: error: 'TRIGGER_NETDEV_RX' undeclared (first use in this function)
      69 |                     test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode))
         |                              ^~~~~~~~~~~~~~~~~
   drivers/leds/trigger/ledtrig-netdev.c:69:62: error: invalid use of undefined type 'struct led_netdev_data'
      69 |                     test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode))
         |                                                              ^~
   drivers/leds/trigger/ledtrig-netdev.c:70:60: error: invalid use of undefined type 'struct led_netdev_data'
      70 |                         schedule_delayed_work(&trigger_data->work, 0);
         |                                                            ^~
   drivers/leds/trigger/ledtrig-netdev.c: In function 'device_name_show':
   drivers/leds/trigger/ledtrig-netdev.c:80:35: error: invalid use of undefined type 'struct led_netdev_data'
      80 |         spin_lock_bh(&trigger_data->lock);
         |                                   ^~
   drivers/leds/trigger/ledtrig-netdev.c:81:48: error: invalid use of undefined type 'struct led_netdev_data'
      81 |         len = sprintf(buf, "%s\n", trigger_data->device_name);
         |                                                ^~
   drivers/leds/trigger/ledtrig-netdev.c:82:37: error: invalid use of undefined type 'struct led_netdev_data'
      82 |         spin_unlock_bh(&trigger_data->lock);
         |                                     ^~
   drivers/leds/trigger/ledtrig-netdev.c: In function 'device_name_store':
   drivers/leds/trigger/ledtrig-netdev.c:96:47: error: invalid use of undefined type 'struct led_netdev_data'
      96 |         cancel_delayed_work_sync(&trigger_data->work);
         |                                               ^~
   drivers/leds/trigger/ledtrig-netdev.c:98:35: error: invalid use of undefined type 'struct led_netdev_data'
      98 |         spin_lock_bh(&trigger_data->lock);
         |                                   ^~
   drivers/leds/trigger/ledtrig-netdev.c:100:25: error: invalid use of undefined type 'struct led_netdev_data'
     100 |         if (trigger_data->net_dev) {
         |                         ^~
   drivers/leds/trigger/ledtrig-netdev.c:101:37: error: invalid use of undefined type 'struct led_netdev_data'
     101 |                 dev_put(trigger_data->net_dev);
         |                                     ^~
   drivers/leds/trigger/ledtrig-netdev.c:102:29: error: invalid use of undefined type 'struct led_netdev_data'
     102 |                 trigger_data->net_dev = NULL;
         |                             ^~
   drivers/leds/trigger/ledtrig-netdev.c:105:28: error: invalid use of undefined type 'struct led_netdev_data'
     105 |         memcpy(trigger_data->device_name, buf, size);
         |                            ^~
   drivers/leds/trigger/ledtrig-netdev.c:106:21: error: invalid use of undefined type 'struct led_netdev_data'
     106 |         trigger_data->device_name[size] = 0;
         |                     ^~
   drivers/leds/trigger/ledtrig-netdev.c:107:37: error: invalid use of undefined type 'struct led_netdev_data'
     107 |         if (size > 0 && trigger_data->device_name[size - 1] == '\n')
         |                                     ^~
   drivers/leds/trigger/ledtrig-netdev.c:108:29: error: invalid use of undefined type 'struct led_netdev_data'
     108 |                 trigger_data->device_name[size - 1] = 0;
         |                             ^~
   drivers/leds/trigger/ledtrig-netdev.c:110:25: error: invalid use of undefined type 'struct led_netdev_data'
     110 |         if (trigger_data->device_name[0] != 0)
         |                         ^~
   drivers/leds/trigger/ledtrig-netdev.c:111:29: error: invalid use of undefined type 'struct led_netdev_data'
     111 |                 trigger_data->net_dev =
         |                             ^~
   drivers/leds/trigger/ledtrig-netdev.c:112:60: error: invalid use of undefined type 'struct led_netdev_data'
     112 |                     dev_get_by_name(&init_net, trigger_data->device_name);
         |                                                            ^~
   drivers/leds/trigger/ledtrig-netdev.c:114:21: error: invalid use of undefined type 'struct led_netdev_data'
     114 |         trigger_data->carrier_link_up = false;
         |                     ^~
   drivers/leds/trigger/ledtrig-netdev.c:115:25: error: invalid use of undefined type 'struct led_netdev_data'
     115 |         if (trigger_data->net_dev != NULL)
         |                         ^~
   drivers/leds/trigger/ledtrig-netdev.c:116:29: error: invalid use of undefined type 'struct led_netdev_data'
     116 |                 trigger_data->carrier_link_up = netif_carrier_ok(trigger_data->net_dev);
         |                             ^~
   drivers/leds/trigger/ledtrig-netdev.c:116:78: error: invalid use of undefined type 'struct led_netdev_data'
     116 |                 trigger_data->carrier_link_up = netif_carrier_ok(trigger_data->net_dev);
         |                                                                              ^~
   drivers/leds/trigger/ledtrig-netdev.c:118:21: error: invalid use of undefined type 'struct led_netdev_data'
     118 |         trigger_data->last_activity = 0;
         |                     ^~
   drivers/leds/trigger/ledtrig-netdev.c:120:28: error: passing argument 1 of 'set_baseline_state' from incompatible pointer type [-Werror=incompatible-pointer-types]
     120 |         set_baseline_state(trigger_data);
         |                            ^~~~~~~~~~~~
         |                            |
         |                            struct led_netdev_data *

drivers/leds/trigger/ledtrig-netdev.c:45:56: note: expected 'struct led_netdev_data *' but argument is of type 'struct led_netdev_data *'
45 | static void set_baseline_state(struct led_netdev_data *trigger_data)

vim +45 drivers/leds/trigger/ledtrig-netdev.c

06f502f57d0d77 Ben Whitten  2017-12-10  44  
06f502f57d0d77 Ben Whitten  2017-12-10 @45  static void set_baseline_state(struct led_netdev_data *trigger_data)
06f502f57d0d77 Ben Whitten  2017-12-10  46  {
06f502f57d0d77 Ben Whitten  2017-12-10  47  	int current_brightness;
06f502f57d0d77 Ben Whitten  2017-12-10  48  	struct led_classdev *led_cdev = trigger_data->led_cdev;
06f502f57d0d77 Ben Whitten  2017-12-10  49  
06f502f57d0d77 Ben Whitten  2017-12-10  50  	current_brightness = led_cdev->brightness;
06f502f57d0d77 Ben Whitten  2017-12-10  51  	if (current_brightness)
06f502f57d0d77 Ben Whitten  2017-12-10  52  		led_cdev->blink_brightness = current_brightness;
06f502f57d0d77 Ben Whitten  2017-12-10  53  	if (!led_cdev->blink_brightness)
06f502f57d0d77 Ben Whitten  2017-12-10  54  		led_cdev->blink_brightness = led_cdev->max_brightness;
06f502f57d0d77 Ben Whitten  2017-12-10  55  
a889cd6231ea62 Ansuel Smith 2021-11-11  56  	if (!trigger_data->carrier_link_up) {
06f502f57d0d77 Ben Whitten  2017-12-10  57  		led_set_brightness(led_cdev, LED_OFF);
a889cd6231ea62 Ansuel Smith 2021-11-11  58  	} else {
e8e8713b4128f4 Ansuel Smith 2021-11-11  59  		if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode))
06f502f57d0d77 Ben Whitten  2017-12-10  60  			led_set_brightness(led_cdev,
06f502f57d0d77 Ben Whitten  2017-12-10  61  					   led_cdev->blink_brightness);
06f502f57d0d77 Ben Whitten  2017-12-10  62  		else
06f502f57d0d77 Ben Whitten  2017-12-10  63  			led_set_brightness(led_cdev, LED_OFF);
06f502f57d0d77 Ben Whitten  2017-12-10  64  
06f502f57d0d77 Ben Whitten  2017-12-10  65  		/* If we are looking for RX/TX start periodically
06f502f57d0d77 Ben Whitten  2017-12-10  66  		 * checking stats
06f502f57d0d77 Ben Whitten  2017-12-10  67  		 */
e8e8713b4128f4 Ansuel Smith 2021-11-11  68  		if (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ||
e8e8713b4128f4 Ansuel Smith 2021-11-11  69  		    test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode))
06f502f57d0d77 Ben Whitten  2017-12-10  70  			schedule_delayed_work(&trigger_data->work, 0);
06f502f57d0d77 Ben Whitten  2017-12-10  71  	}
06f502f57d0d77 Ben Whitten  2017-12-10  72  }
06f502f57d0d77 Ben Whitten  2017-12-10  73  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author maintainer
#19 lore raw
In reply to Marek Behún
Quoted 52 lines · Marek Behún
Quoted 36 lines · On Thu, 11 Nov 2021 02:34:52 +0100 Ansuel Smith <[email protected]> wrote:

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 3 API (hw_control_status/start/stop). They are used to put the LED in hardware mode and to configure the various trigger.
- We have hardware triggers that are used to expose to userspace the supported hardware mode and set the hardware mode on trigger activation.
- We can also have triggers that both support hardware and software mode.
- The LED driver will declare each supported hardware blink mode and communicate with the trigger all the supported blink modes that will be available by sysfs.
- A trigger will use blink_set to configure the blink mode to active in hardware mode.
- On hardware trigger activation, only the hardware mode is enabled but the blink modes are not configured. The LED driver should reset any link mode active by default.

Each LED driver will have to declare explicit support for the offload trigger (or return not supported error code) as we the trigger_data 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.

Quoted 5 lines

I also posted the netdev trigger expanded with the hardware support.

More polish is required but this is just to understand if I'm taking the correct path with this implementation hoping we find a correct implementation and we start working on the ""small details""

Hello Ansuel,

besides other things, I am still against the idea of the hardware-phy-activity trigger: I think that if the user wants the LED to indicate network device's link status or activity, it should always be done via the existing netdev trigger, and with that trigger only.

Quoted 8 lines

Yes, I know that netdev trigger does not currently support indicating different link modes, only whether the link is up (in any mode). That should be solved by extending the netdev trigger.

I am going to try to revive my last attempt and send my proposal again. Hope you don't mind.

Marek

Honestly... It's a bit sad.
The netdev trigger have its limitation and I see introducing an additional trigger a practical way to correctly support some strange/specific PHY.
I implemented both idea: expand netdev and introduce a dedicated trigger and still this is problematic.
Is having an additional trigger for the specific task that bad?

I don't care as long as the feature is implemented but again pretty sad how this LEDs proposal went.

Signature · 1 line
	Ansuel
#20 lore raw
Quoted 70 lines · On Fri, 12 Nov 2021 16:35:21 +0100 Ansuel Smith <[email protected]> wrote:
Quoted 52 lines · Marek Behún
Quoted 36 lines · On Thu, 11 Nov 2021 02:34:52 +0100 Ansuel Smith <[email protected]> wrote:

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 3 API (hw_control_status/start/stop). They are used to put the LED in hardware mode and to configure the various trigger.
- We have hardware triggers that are used to expose to userspace the supported hardware mode and set the hardware mode on trigger activation.
- We can also have triggers that both support hardware and software mode.
- The LED driver will declare each supported hardware blink mode and communicate with the trigger all the supported blink modes that will be available by sysfs.
- A trigger will use blink_set to configure the blink mode to active in hardware mode.
- On hardware trigger activation, only the hardware mode is enabled but the blink modes are not configured. The LED driver should reset any link mode active by default.

Each LED driver will have to declare explicit support for the offload trigger (or return not supported error code) as we the trigger_data 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.

Quoted 5 lines

I also posted the netdev trigger expanded with the hardware support.

More polish is required but this is just to understand if I'm taking the correct path with this implementation hoping we find a correct implementation and we start working on the ""small details""

Hello Ansuel,

besides other things, I am still against the idea of the hardware-phy-activity trigger: I think that if the user wants the LED to indicate network device's link status or activity, it should always be done via the existing netdev trigger, and with that trigger only.

Quoted 8 lines

Yes, I know that netdev trigger does not currently support indicating different link modes, only whether the link is up (in any mode). That should be solved by extending the netdev trigger.

I am going to try to revive my last attempt and send my proposal again. Hope you don't mind.

Marek

Honestly... It's a bit sad.
The netdev trigger have its limitation and I see introducing an additional trigger a practical way to correctly support some strange/specific PHY.
I implemented both idea: expand netdev and introduce a dedicated trigger and still this is problematic.
Is having an additional trigger for the specific task that bad?

Quoted 2 lines

I don't care as long as the feature is implemented but again pretty sad how this LEDs proposal went.

Dear Ansuel,

Is having an additional trigger for the specific task that bad?

No, for a very specific thing it is not bad. By specific I mean something that an existing trigger does not support and can't support in a reasonable way. But netdev trigger already supports blinking on rx and tx, and even setting blinking frequency, and indicating link. And it can be reasonably extended to support indicating different link modes and even more complex things. For example what I would like to see is having support for indicating different links by different colors with RGB LEDs. I have ideas about how it can be implemented.

But a very specific thing can be implemented by a separate trigger. For an ethernet PHY chip this can be something like ethernet collision indication, or Energy Efficient Ethernet indication. But link and activity should be done via netdev.

Note that we even have an API for such specific triggers that can only work with some LEDs: the LED private triggers. Look at the member
struct led_hw_trigger_type *trigger_type;
of struct led_classdev and struct led_trigger.
With this member you can make a trigger to be only visible for some LEDs, so that when the user does
cd /sys/class/leds/<LED_WITH_PRIVATE_TRIGGER>
cat trigger
it will output
[none] netdev something something ... my-private-trigger
but for other LEDs (all those with different trigger_type) it will omit the my-private-trigger.

Your hardware-phy trigger should in fact use this private trigger API so that the user only sees the trigger for the LEDs that actually support it.

Anyway, Ansuel, if you are willing, we can have a call about this where I can explain my ideas to you and you to me and we can discuss it more and maybe come to an understanding? I am not opposed to working on this together.

Marek