^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright 2006, Johannes Berg <johannes@sipsolutions.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) /* just for IFNAMSIZ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/if.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "led.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) void ieee80211_led_assoc(struct ieee80211_local *local, bool associated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) if (!atomic_read(&local->assoc_led_active))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) if (associated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) led_trigger_event(&local->assoc_led, LED_FULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) led_trigger_event(&local->assoc_led, LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) void ieee80211_led_radio(struct ieee80211_local *local, bool enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) if (!atomic_read(&local->radio_led_active))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) if (enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) led_trigger_event(&local->radio_led, LED_FULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) led_trigger_event(&local->radio_led, LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) void ieee80211_alloc_led_names(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) local->rx_led.name = kasprintf(GFP_KERNEL, "%srx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) wiphy_name(local->hw.wiphy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) local->tx_led.name = kasprintf(GFP_KERNEL, "%stx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) wiphy_name(local->hw.wiphy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) local->assoc_led.name = kasprintf(GFP_KERNEL, "%sassoc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) wiphy_name(local->hw.wiphy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) local->radio_led.name = kasprintf(GFP_KERNEL, "%sradio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) wiphy_name(local->hw.wiphy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void ieee80211_free_led_names(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) kfree(local->rx_led.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) kfree(local->tx_led.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) kfree(local->assoc_led.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) kfree(local->radio_led.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static int ieee80211_tx_led_activate(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct ieee80211_local *local = container_of(led_cdev->trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct ieee80211_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) tx_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) atomic_inc(&local->tx_led_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static void ieee80211_tx_led_deactivate(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct ieee80211_local *local = container_of(led_cdev->trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct ieee80211_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) tx_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) atomic_dec(&local->tx_led_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static int ieee80211_rx_led_activate(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct ieee80211_local *local = container_of(led_cdev->trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct ieee80211_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) rx_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) atomic_inc(&local->rx_led_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static void ieee80211_rx_led_deactivate(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct ieee80211_local *local = container_of(led_cdev->trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct ieee80211_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) rx_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) atomic_dec(&local->rx_led_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static int ieee80211_assoc_led_activate(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct ieee80211_local *local = container_of(led_cdev->trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct ieee80211_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) assoc_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) atomic_inc(&local->assoc_led_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static void ieee80211_assoc_led_deactivate(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct ieee80211_local *local = container_of(led_cdev->trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct ieee80211_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) assoc_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) atomic_dec(&local->assoc_led_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int ieee80211_radio_led_activate(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct ieee80211_local *local = container_of(led_cdev->trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct ieee80211_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) radio_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) atomic_inc(&local->radio_led_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static void ieee80211_radio_led_deactivate(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct ieee80211_local *local = container_of(led_cdev->trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct ieee80211_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) radio_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) atomic_dec(&local->radio_led_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int ieee80211_tpt_led_activate(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct ieee80211_local *local = container_of(led_cdev->trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct ieee80211_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) tpt_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) atomic_inc(&local->tpt_led_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static void ieee80211_tpt_led_deactivate(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct ieee80211_local *local = container_of(led_cdev->trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct ieee80211_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) tpt_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) atomic_dec(&local->tpt_led_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) void ieee80211_led_init(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) atomic_set(&local->rx_led_active, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) local->rx_led.activate = ieee80211_rx_led_activate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) local->rx_led.deactivate = ieee80211_rx_led_deactivate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (local->rx_led.name && led_trigger_register(&local->rx_led)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) kfree(local->rx_led.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) local->rx_led.name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) atomic_set(&local->tx_led_active, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) local->tx_led.activate = ieee80211_tx_led_activate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) local->tx_led.deactivate = ieee80211_tx_led_deactivate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (local->tx_led.name && led_trigger_register(&local->tx_led)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) kfree(local->tx_led.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) local->tx_led.name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) atomic_set(&local->assoc_led_active, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) local->assoc_led.activate = ieee80211_assoc_led_activate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) local->assoc_led.deactivate = ieee80211_assoc_led_deactivate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (local->assoc_led.name && led_trigger_register(&local->assoc_led)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) kfree(local->assoc_led.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) local->assoc_led.name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) atomic_set(&local->radio_led_active, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) local->radio_led.activate = ieee80211_radio_led_activate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) local->radio_led.deactivate = ieee80211_radio_led_deactivate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (local->radio_led.name && led_trigger_register(&local->radio_led)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) kfree(local->radio_led.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) local->radio_led.name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) atomic_set(&local->tpt_led_active, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (local->tpt_led_trigger) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) local->tpt_led.activate = ieee80211_tpt_led_activate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) local->tpt_led.deactivate = ieee80211_tpt_led_deactivate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (led_trigger_register(&local->tpt_led)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) kfree(local->tpt_led_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) local->tpt_led_trigger = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) void ieee80211_led_exit(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (local->radio_led.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) led_trigger_unregister(&local->radio_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (local->assoc_led.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) led_trigger_unregister(&local->assoc_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (local->tx_led.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) led_trigger_unregister(&local->tx_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (local->rx_led.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) led_trigger_unregister(&local->rx_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (local->tpt_led_trigger) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) led_trigger_unregister(&local->tpt_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) kfree(local->tpt_led_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) const char *__ieee80211_get_radio_led_name(struct ieee80211_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return local->radio_led.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) EXPORT_SYMBOL(__ieee80211_get_radio_led_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) const char *__ieee80211_get_assoc_led_name(struct ieee80211_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return local->assoc_led.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) EXPORT_SYMBOL(__ieee80211_get_assoc_led_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) const char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return local->tx_led.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) EXPORT_SYMBOL(__ieee80211_get_tx_led_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) const char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return local->rx_led.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) EXPORT_SYMBOL(__ieee80211_get_rx_led_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static unsigned long tpt_trig_traffic(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct tpt_led_trigger *tpt_trig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) unsigned long traffic, delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) traffic = tpt_trig->tx_bytes + tpt_trig->rx_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) delta = traffic - tpt_trig->prev_traffic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) tpt_trig->prev_traffic = traffic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return DIV_ROUND_UP(delta, 1024 / 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static void tpt_trig_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct tpt_led_trigger *tpt_trig = from_timer(tpt_trig, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct ieee80211_local *local = tpt_trig->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct led_classdev *led_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) unsigned long on, off, tpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (!tpt_trig->running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) mod_timer(&tpt_trig->timer, round_jiffies(jiffies + HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) tpt = tpt_trig_traffic(local, tpt_trig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* default to just solid on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) on = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) for (i = tpt_trig->blink_table_len - 1; i >= 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (tpt_trig->blink_table[i].throughput < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) tpt > tpt_trig->blink_table[i].throughput) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) off = tpt_trig->blink_table[i].blink_time / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) on = tpt_trig->blink_table[i].blink_time - off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) read_lock(&local->tpt_led.leddev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) list_for_each_entry(led_cdev, &local->tpt_led.led_cdevs, trig_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) led_blink_set(led_cdev, &on, &off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) read_unlock(&local->tpt_led.leddev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) const char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) __ieee80211_create_tpt_led_trigger(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) unsigned int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) const struct ieee80211_tpt_blink *blink_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) unsigned int blink_table_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct tpt_led_trigger *tpt_trig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (WARN_ON(local->tpt_led_trigger))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) tpt_trig = kzalloc(sizeof(struct tpt_led_trigger), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (!tpt_trig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) snprintf(tpt_trig->name, sizeof(tpt_trig->name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) "%stpt", wiphy_name(local->hw.wiphy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) local->tpt_led.name = tpt_trig->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) tpt_trig->blink_table = blink_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) tpt_trig->blink_table_len = blink_table_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) tpt_trig->want = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) tpt_trig->local = local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) timer_setup(&tpt_trig->timer, tpt_trig_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) local->tpt_led_trigger = tpt_trig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return tpt_trig->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) EXPORT_SYMBOL(__ieee80211_create_tpt_led_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static void ieee80211_start_tpt_led_trig(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct tpt_led_trigger *tpt_trig = local->tpt_led_trigger;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (tpt_trig->running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /* reset traffic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) tpt_trig_traffic(local, tpt_trig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) tpt_trig->running = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) tpt_trig_timer(&tpt_trig->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) mod_timer(&tpt_trig->timer, round_jiffies(jiffies + HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static void ieee80211_stop_tpt_led_trig(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct tpt_led_trigger *tpt_trig = local->tpt_led_trigger;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct led_classdev *led_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (!tpt_trig->running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) tpt_trig->running = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) del_timer_sync(&tpt_trig->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) read_lock(&local->tpt_led.leddev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) list_for_each_entry(led_cdev, &local->tpt_led.led_cdevs, trig_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) led_set_brightness(led_cdev, LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) read_unlock(&local->tpt_led.leddev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) void ieee80211_mod_tpt_led_trig(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) unsigned int types_on, unsigned int types_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) struct tpt_led_trigger *tpt_trig = local->tpt_led_trigger;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) bool allowed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) WARN_ON(types_on & types_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (!tpt_trig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) tpt_trig->active &= ~types_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) tpt_trig->active |= types_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * Regardless of wanted state, we shouldn't blink when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * the radio is disabled -- this can happen due to some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) * code ordering issues with __ieee80211_recalc_idle()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * being called before the radio is started.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) allowed = tpt_trig->active & IEEE80211_TPT_LEDTRIG_FL_RADIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (!allowed || !(tpt_trig->active & tpt_trig->want))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) ieee80211_stop_tpt_led_trig(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) ieee80211_start_tpt_led_trig(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }