3170c260580a4ef84ef70ec7b3fe8056340ce986
[openwrt/staging/981213.git] /
1 From e2f24cb1b5daf9a4f6f3ba574c1fa74aab9807a4 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 19 Apr 2023 23:07:40 +0200
4 Subject: [PATCH 2/5] leds: trigger: netdev: Drop NETDEV_LED_MODE_LINKUP from
5 mode
6
7 Putting NETDEV_LED_MODE_LINKUP in the same list of the netdev trigger
8 modes is wrong as it's used to set the link state of the device and not
9 to set a blink mode as it's done by NETDEV_LED_LINK, NETDEV_LED_TX and
10 NETDEV_LED_RX. It's also wrong to put this state in the same bitmap of the
11 netdev trigger mode and should be external to it.
12
13 Drop NETDEV_LED_MODE_LINKUP from mode list and convert to a simple bool
14 that will be true or false based on the carrier link. No functional
15 change intended.
16
17 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
18 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
19 Signed-off-by: Lee Jones <lee@kernel.org>
20 Link: https://lore.kernel.org/r/20230419210743.3594-3-ansuelsmth@gmail.com
21 ---
22 drivers/leds/trigger/ledtrig-netdev.c | 19 ++++++++-----------
23 1 file changed, 8 insertions(+), 11 deletions(-)
24
25 --- a/drivers/leds/trigger/ledtrig-netdev.c
26 +++ b/drivers/leds/trigger/ledtrig-netdev.c
27 @@ -50,10 +50,10 @@ struct led_netdev_data {
28 unsigned int last_activity;
29
30 unsigned long mode;
31 + bool carrier_link_up;
32 #define NETDEV_LED_LINK 0
33 #define NETDEV_LED_TX 1
34 #define NETDEV_LED_RX 2
35 -#define NETDEV_LED_MODE_LINKUP 3
36 };
37
38 enum netdev_led_attr {
39 @@ -73,9 +73,9 @@ static void set_baseline_state(struct le
40 if (!led_cdev->blink_brightness)
41 led_cdev->blink_brightness = led_cdev->max_brightness;
42
43 - if (!test_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode))
44 + if (!trigger_data->carrier_link_up) {
45 led_set_brightness(led_cdev, LED_OFF);
46 - else {
47 + } else {
48 if (test_bit(NETDEV_LED_LINK, &trigger_data->mode))
49 led_set_brightness(led_cdev,
50 led_cdev->blink_brightness);
51 @@ -131,10 +131,9 @@ static ssize_t device_name_store(struct
52 trigger_data->net_dev =
53 dev_get_by_name(&init_net, trigger_data->device_name);
54
55 - clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
56 + trigger_data->carrier_link_up = false;
57 if (trigger_data->net_dev != NULL)
58 - if (netif_carrier_ok(trigger_data->net_dev))
59 - set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
60 + trigger_data->carrier_link_up = netif_carrier_ok(trigger_data->net_dev);
61
62 trigger_data->last_activity = 0;
63
64 @@ -315,11 +314,10 @@ static int netdev_trig_notify(struct not
65
66 spin_lock_bh(&trigger_data->lock);
67
68 - clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
69 + trigger_data->carrier_link_up = false;
70 switch (evt) {
71 case NETDEV_CHANGENAME:
72 - if (netif_carrier_ok(dev))
73 - set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
74 + trigger_data->carrier_link_up = netif_carrier_ok(dev);
75 fallthrough;
76 case NETDEV_REGISTER:
77 if (trigger_data->net_dev)
78 @@ -333,8 +331,7 @@ static int netdev_trig_notify(struct not
79 break;
80 case NETDEV_UP:
81 case NETDEV_CHANGE:
82 - if (netif_carrier_ok(dev))
83 - set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
84 + trigger_data->carrier_link_up = netif_carrier_ok(dev);
85 break;
86 }
87