11 #include <linux/slab.h>
12 #include <linux/export.h>
19 if (local->rx_led_counter++ % 2 == 0)
31 local->tx_led_counter += 2*q-1;
32 if (local->tx_led_counter % 2 == 0)
60 snprintf(local->rx_led_name,
sizeof(local->rx_led_name),
61 "%srx", wiphy_name(local->
hw.wiphy));
62 snprintf(local->tx_led_name,
sizeof(local->tx_led_name),
63 "%stx", wiphy_name(local->
hw.wiphy));
64 snprintf(local->assoc_led_name,
sizeof(local->assoc_led_name),
65 "%sassoc", wiphy_name(local->
hw.wiphy));
66 snprintf(local->radio_led_name,
sizeof(local->radio_led_name),
67 "%sradio", wiphy_name(local->
hw.wiphy));
72 local->rx_led = kzalloc(
sizeof(
struct led_trigger),
GFP_KERNEL);
74 local->rx_led->name = local->rx_led_name;
81 local->tx_led = kzalloc(
sizeof(
struct led_trigger),
GFP_KERNEL);
83 local->tx_led->name = local->tx_led_name;
90 local->assoc_led = kzalloc(
sizeof(
struct led_trigger),
GFP_KERNEL);
91 if (local->assoc_led) {
92 local->assoc_led->name = local->assoc_led_name;
94 kfree(local->assoc_led);
95 local->assoc_led =
NULL;
99 local->radio_led = kzalloc(
sizeof(
struct led_trigger),
GFP_KERNEL);
100 if (local->radio_led) {
101 local->radio_led->name = local->radio_led_name;
103 kfree(local->radio_led);
104 local->radio_led =
NULL;
108 if (local->tpt_led_trigger) {
110 kfree(local->tpt_led_trigger);
111 local->tpt_led_trigger =
NULL;
118 if (local->radio_led) {
120 kfree(local->radio_led);
122 if (local->assoc_led) {
124 kfree(local->assoc_led);
128 kfree(local->tx_led);
132 kfree(local->rx_led);
135 if (local->tpt_led_trigger) {
137 kfree(local->tpt_led_trigger);
145 return local->radio_led_name;
153 return local->assoc_led_name;
161 return local->tx_led_name;
169 return local->rx_led_name;
174 struct tpt_led_trigger *tpt_trig)
176 unsigned long traffic,
delta;
178 traffic = tpt_trig->tx_bytes + tpt_trig->rx_bytes;
180 delta = traffic - tpt_trig->prev_traffic;
181 tpt_trig->prev_traffic = traffic;
185 static void tpt_trig_timer(
unsigned long data)
188 struct tpt_led_trigger *tpt_trig = local->tpt_led_trigger;
190 unsigned long on, off, tpt;
193 if (!tpt_trig->running)
198 tpt = tpt_trig_traffic(local, tpt_trig);
204 for (i = tpt_trig->blink_table_len - 1; i >= 0; i--) {
205 if (tpt_trig->blink_table[i].throughput < 0 ||
206 tpt > tpt_trig->blink_table[i].throughput) {
207 off = tpt_trig->blink_table[
i].blink_time / 2;
208 on = tpt_trig->blink_table[
i].blink_time - off;
213 read_lock(&tpt_trig->trig.leddev_list_lock);
222 unsigned int blink_table_len)
225 struct tpt_led_trigger *tpt_trig;
227 if (
WARN_ON(local->tpt_led_trigger))
230 tpt_trig = kzalloc(
sizeof(
struct tpt_led_trigger),
GFP_KERNEL);
234 snprintf(tpt_trig->name,
sizeof(tpt_trig->name),
235 "%stpt", wiphy_name(local->
hw.wiphy));
237 tpt_trig->trig.name = tpt_trig->name;
239 tpt_trig->blink_table = blink_table;
240 tpt_trig->blink_table_len = blink_table_len;
241 tpt_trig->want =
flags;
243 setup_timer(&tpt_trig->timer, tpt_trig_timer, (
unsigned long)local);
245 local->tpt_led_trigger = tpt_trig;
247 return tpt_trig->name;
251 static void ieee80211_start_tpt_led_trig(
struct ieee80211_local *local)
253 struct tpt_led_trigger *tpt_trig = local->tpt_led_trigger;
255 if (tpt_trig->running)
259 tpt_trig_traffic(local, tpt_trig);
260 tpt_trig->running =
true;
262 tpt_trig_timer((
unsigned long)local);
268 struct tpt_led_trigger *tpt_trig = local->tpt_led_trigger;
271 if (!tpt_trig->running)
274 tpt_trig->running =
false;
277 read_lock(&tpt_trig->trig.leddev_list_lock);
284 unsigned int types_on,
unsigned int types_off)
286 struct tpt_led_trigger *tpt_trig = local->tpt_led_trigger;
294 tpt_trig->active &= ~types_off;
295 tpt_trig->active |= types_on;
305 if (!allowed || !(tpt_trig->active & tpt_trig->want))
306 ieee80211_stop_tpt_led_trig(local);
308 ieee80211_start_tpt_led_trig(local);