Subject: [PATCH leds v2 04/10] leds: trigger: netdev: support HW offloading

From: Marek Behún <[email-masked]>
Date: Tue, 1 Jun 2021 02:51:49 +0200

Add support for HW offloading of the netdev trigger.

We are only offloading if the link is up and rx/tx blinking is
requested.

Signed-off-by: Marek Behún <[email-masked]>
---
 drivers/leds/trigger/ledtrig-netdev.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index 9a98f9c5b8d0..1f1b63d5a78d 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -52,9 +52,17 @@ 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 (!test_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode)) {
+		led_trigger_offload_stop(led_cdev);
 		led_set_brightness(led_cdev, LED_OFF);
-	else {
+	} else {
+		bool blink = test_bit(NETDEV_LED_TX, &trigger_data->mode) ||
+			     test_bit(NETDEV_LED_RX, &trigger_data->mode);
+		/* Try offload to HW only if RX/TX blinking is requested */
+		if (blink)
+			if (!led_trigger_offload(led_cdev))
+				return;
+
 		if (test_bit(NETDEV_LED_LINK, &trigger_data->mode))
 			led_set_brightness(led_cdev,
 					   led_cdev->blink_brightness);
@@ -64,8 +72,7 @@ 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 (blink)
 			schedule_delayed_work(&trigger_data->work, 0);
 	}
 }
-- 
2.26.3