19cc1d7c9edc169f874ba3c4ea4ada60156168d2
[openwrt/staging/thess.git] /
1 From bdec9cb83936e0ac4cb87fed5b49fad0175f7dec Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 19 Apr 2023 23:07:41 +0200
4 Subject: [PATCH 3/5] leds: trigger: netdev: Rename add namespace to netdev
5 trigger enum modes
6
7 Rename NETDEV trigger enum modes to a more symbolic name and add a
8 namespace to them.
9
10 Also add __TRIGGER_NETDEV_MAX to identify the max modes of the netdev
11 trigger.
12
13 This is a cleanup to drop the define and no behaviour change are
14 intended.
15
16 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
17 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
18 Signed-off-by: Lee Jones <lee@kernel.org>
19 Link: https://lore.kernel.org/r/20230419210743.3594-4-ansuelsmth@gmail.com
20 ---
21 drivers/leds/trigger/ledtrig-netdev.c | 58 ++++++++++++---------------
22 1 file changed, 25 insertions(+), 33 deletions(-)
23
24 --- a/drivers/leds/trigger/ledtrig-netdev.c
25 +++ b/drivers/leds/trigger/ledtrig-netdev.c
26 @@ -51,15 +51,15 @@ struct led_netdev_data {
27
28 unsigned long mode;
29 bool carrier_link_up;
30 -#define NETDEV_LED_LINK 0
31 -#define NETDEV_LED_TX 1
32 -#define NETDEV_LED_RX 2
33 };
34
35 -enum netdev_led_attr {
36 - NETDEV_ATTR_LINK,
37 - NETDEV_ATTR_TX,
38 - NETDEV_ATTR_RX
39 +enum led_trigger_netdev_modes {
40 + TRIGGER_NETDEV_LINK = 0,
41 + TRIGGER_NETDEV_TX,
42 + TRIGGER_NETDEV_RX,
43 +
44 + /* Keep last */
45 + __TRIGGER_NETDEV_MAX,
46 };
47
48 static void set_baseline_state(struct led_netdev_data *trigger_data)
49 @@ -76,7 +76,7 @@ static void set_baseline_state(struct le
50 if (!trigger_data->carrier_link_up) {
51 led_set_brightness(led_cdev, LED_OFF);
52 } else {
53 - if (test_bit(NETDEV_LED_LINK, &trigger_data->mode))
54 + if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode))
55 led_set_brightness(led_cdev,
56 led_cdev->blink_brightness);
57 else
58 @@ -85,8 +85,8 @@ static void set_baseline_state(struct le
59 /* If we are looking for RX/TX start periodically
60 * checking stats
61 */
62 - if (test_bit(NETDEV_LED_TX, &trigger_data->mode) ||
63 - test_bit(NETDEV_LED_RX, &trigger_data->mode))
64 + if (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ||
65 + test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode))
66 schedule_delayed_work(&trigger_data->work, 0);
67 }
68 }
69 @@ -146,20 +146,16 @@ static ssize_t device_name_store(struct
70 static DEVICE_ATTR_RW(device_name);
71
72 static ssize_t netdev_led_attr_show(struct device *dev, char *buf,
73 - enum netdev_led_attr attr)
74 + enum led_trigger_netdev_modes attr)
75 {
76 struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
77 int bit;
78
79 switch (attr) {
80 - case NETDEV_ATTR_LINK:
81 - bit = NETDEV_LED_LINK;
82 - break;
83 - case NETDEV_ATTR_TX:
84 - bit = NETDEV_LED_TX;
85 - break;
86 - case NETDEV_ATTR_RX:
87 - bit = NETDEV_LED_RX;
88 + case TRIGGER_NETDEV_LINK:
89 + case TRIGGER_NETDEV_TX:
90 + case TRIGGER_NETDEV_RX:
91 + bit = attr;
92 break;
93 default:
94 return -EINVAL;
95 @@ -169,7 +165,7 @@ static ssize_t netdev_led_attr_show(stru
96 }
97
98 static ssize_t netdev_led_attr_store(struct device *dev, const char *buf,
99 - size_t size, enum netdev_led_attr attr)
100 + size_t size, enum led_trigger_netdev_modes attr)
101 {
102 struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
103 unsigned long state;
104 @@ -181,14 +177,10 @@ static ssize_t netdev_led_attr_store(str
105 return ret;
106
107 switch (attr) {
108 - case NETDEV_ATTR_LINK:
109 - bit = NETDEV_LED_LINK;
110 - break;
111 - case NETDEV_ATTR_TX:
112 - bit = NETDEV_LED_TX;
113 - break;
114 - case NETDEV_ATTR_RX:
115 - bit = NETDEV_LED_RX;
116 + case TRIGGER_NETDEV_LINK:
117 + case TRIGGER_NETDEV_TX:
118 + case TRIGGER_NETDEV_RX:
119 + bit = attr;
120 break;
121 default:
122 return -EINVAL;
123 @@ -360,21 +352,21 @@ static void netdev_trig_work(struct work
124 }
125
126 /* If we are not looking for RX/TX then return */
127 - if (!test_bit(NETDEV_LED_TX, &trigger_data->mode) &&
128 - !test_bit(NETDEV_LED_RX, &trigger_data->mode))
129 + if (!test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) &&
130 + !test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode))
131 return;
132
133 dev_stats = dev_get_stats(trigger_data->net_dev, &temp);
134 new_activity =
135 - (test_bit(NETDEV_LED_TX, &trigger_data->mode) ?
136 + (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ?
137 dev_stats->tx_packets : 0) +
138 - (test_bit(NETDEV_LED_RX, &trigger_data->mode) ?
139 + (test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode) ?
140 dev_stats->rx_packets : 0);
141
142 if (trigger_data->last_activity != new_activity) {
143 led_stop_software_blink(trigger_data->led_cdev);
144
145 - invert = test_bit(NETDEV_LED_LINK, &trigger_data->mode);
146 + invert = test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode);
147 interval = jiffies_to_msecs(
148 atomic_read(&trigger_data->interval));
149 /* base state is ON (link present) */