ath9k: fix handling of tx headroom for padding (fixes #20556)
[openwrt/svn-archive/archive.git] / package / kernel / mac80211 / patches / 530-ath9k_extra_leds.patch
1 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
2 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
3 @@ -806,6 +806,9 @@ static inline int ath9k_dump_btcoex(stru
4 void ath_init_leds(struct ath_softc *sc);
5 void ath_deinit_leds(struct ath_softc *sc);
6 void ath_fill_led_pin(struct ath_softc *sc);
7 +int ath_create_gpio_led(struct ath_softc *sc, int gpio, const char *name,
8 + const char *trigger, bool active_low);
9 +
10 #else
11 static inline void ath_init_leds(struct ath_softc *sc)
12 {
13 @@ -945,6 +948,13 @@ void ath_ant_comb_scan(struct ath_softc
14
15 #define ATH9K_NUM_CHANCTX 2 /* supports 2 operating channels */
16
17 +struct ath_led {
18 + struct list_head list;
19 + struct ath_softc *sc;
20 + const struct gpio_led *gpio;
21 + struct led_classdev cdev;
22 +};
23 +
24 struct ath_softc {
25 struct ieee80211_hw *hw;
26 struct device *dev;
27 @@ -996,9 +1006,8 @@ struct ath_softc {
28 spinlock_t chan_lock;
29
30 #ifdef CPTCFG_MAC80211_LEDS
31 - bool led_registered;
32 - char led_name[32];
33 - struct led_classdev led_cdev;
34 + const char *led_default_trigger;
35 + struct list_head leds;
36 #endif
37
38 #ifdef CPTCFG_ATH9K_DEBUGFS
39 --- a/drivers/net/wireless/ath/ath9k/gpio.c
40 +++ b/drivers/net/wireless/ath/ath9k/gpio.c
41 @@ -24,45 +24,102 @@
42 static void ath_led_brightness(struct led_classdev *led_cdev,
43 enum led_brightness brightness)
44 {
45 - struct ath_softc *sc = container_of(led_cdev, struct ath_softc, led_cdev);
46 - u32 val = (brightness == LED_OFF);
47 + struct ath_led *led = container_of(led_cdev, struct ath_led, cdev);
48 + struct ath_softc *sc = led->sc;
49
50 - if (sc->sc_ah->config.led_active_high)
51 - val = !val;
52 + ath9k_ps_wakeup(sc);
53 + ath9k_hw_set_gpio(sc->sc_ah, led->gpio->gpio,
54 + (brightness != LED_OFF) ^ led->gpio->active_low);
55 + ath9k_ps_restore(sc);
56 +}
57 +
58 +static int ath_add_led(struct ath_softc *sc, struct ath_led *led)
59 +{
60 + const struct gpio_led *gpio = led->gpio;
61 + int ret;
62 +
63 + led->cdev.name = gpio->name;
64 + led->cdev.default_trigger = gpio->default_trigger;
65 + led->cdev.brightness_set = ath_led_brightness;
66
67 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, val);
68 + ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->cdev);
69 + if (ret < 0)
70 + return ret;
71 +
72 + led->sc = sc;
73 + list_add(&led->list, &sc->leds);
74 +
75 + /* Configure gpio for output */
76 + ath9k_hw_cfg_output(sc->sc_ah, gpio->gpio,
77 + AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
78 +
79 + /* LED off */
80 + ath9k_hw_set_gpio(sc->sc_ah, gpio->gpio, gpio->active_low);
81 +
82 + return 0;
83 +}
84 +
85 +int ath_create_gpio_led(struct ath_softc *sc, int gpio_num, const char *name,
86 + const char *trigger, bool active_low)
87 +{
88 + struct ath_led *led;
89 + struct gpio_led *gpio;
90 + char *_name;
91 + int ret;
92 +
93 + led = kzalloc(sizeof(*led) + sizeof(*gpio) + strlen(name) + 1,
94 + GFP_KERNEL);
95 + if (!led)
96 + return -ENOMEM;
97 +
98 + led->gpio = gpio = (struct gpio_led *) (led + 1);
99 + _name = (char *) (led->gpio + 1);
100 +
101 + strcpy(_name, name);
102 + gpio->name = _name;
103 + gpio->gpio = gpio_num;
104 + gpio->active_low = active_low;
105 + gpio->default_trigger = trigger;
106 +
107 + ret = ath_add_led(sc, led);
108 + if (unlikely(ret < 0))
109 + kfree(led);
110 +
111 + return ret;
112 }
113
114 void ath_deinit_leds(struct ath_softc *sc)
115 {
116 - if (!sc->led_registered)
117 - return;
118 + struct ath_led *led;
119
120 - ath_led_brightness(&sc->led_cdev, LED_OFF);
121 - led_classdev_unregister(&sc->led_cdev);
122 + while (!list_empty(&sc->leds)) {
123 + led = list_first_entry(&sc->leds, struct ath_led, list);
124 + list_del(&led->list);
125 + ath_led_brightness(&led->cdev, LED_OFF);
126 + led_classdev_unregister(&led->cdev);
127 + kfree(led);
128 + }
129 }
130
131 void ath_init_leds(struct ath_softc *sc)
132 {
133 - int ret;
134 + char led_name[32];
135 + const char *trigger;
136 +
137 + INIT_LIST_HEAD(&sc->leds);
138
139 if (AR_SREV_9100(sc->sc_ah))
140 return;
141
142 - if (!ath9k_led_blink)
143 - sc->led_cdev.default_trigger =
144 - ieee80211_get_radio_led_name(sc->hw);
145 -
146 - snprintf(sc->led_name, sizeof(sc->led_name),
147 - "ath9k-%s", wiphy_name(sc->hw->wiphy));
148 - sc->led_cdev.name = sc->led_name;
149 - sc->led_cdev.brightness_set = ath_led_brightness;
150 + snprintf(led_name, sizeof(led_name), "ath9k-%s",
151 + wiphy_name(sc->hw->wiphy));
152
153 - ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
154 - if (ret < 0)
155 - return;
156 + if (ath9k_led_blink)
157 + trigger = sc->led_default_trigger;
158 + else
159 + trigger = ieee80211_get_radio_led_name(sc->hw);
160
161 - sc->led_registered = true;
162 + ath_create_gpio_led(sc, sc->sc_ah->led_pin, led_name, trigger, 1);
163 }
164
165 void ath_fill_led_pin(struct ath_softc *sc)
166 --- a/drivers/net/wireless/ath/ath9k/init.c
167 +++ b/drivers/net/wireless/ath/ath9k/init.c
168 @@ -944,7 +944,7 @@ int ath9k_init_device(u16 devid, struct
169
170 #ifdef CPTCFG_MAC80211_LEDS
171 /* must be initialized before ieee80211_register_hw */
172 - sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
173 + sc->led_default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
174 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
175 ARRAY_SIZE(ath9k_tpt_blink));
176 #endif
177 --- a/drivers/net/wireless/ath/ath9k/debug.c
178 +++ b/drivers/net/wireless/ath/ath9k/debug.c
179 @@ -1393,6 +1393,61 @@ static const struct file_operations fops
180 .llseek = default_llseek,
181 };
182
183 +#ifdef CONFIG_MAC80211_LEDS
184 +
185 +static ssize_t write_file_gpio_led(struct file *file, const char __user *ubuf,
186 + size_t count, loff_t *ppos)
187 +{
188 + struct ath_softc *sc = file->private_data;
189 + char buf[32], *str, *name, *c;
190 + ssize_t len;
191 + unsigned int gpio;
192 + bool active_low = false;
193 +
194 + len = min(count, sizeof(buf) - 1);
195 + if (copy_from_user(buf, ubuf, len))
196 + return -EFAULT;
197 +
198 + buf[len] = '\0';
199 + name = strchr(buf, ',');
200 + if (!name)
201 + return -EINVAL;
202 +
203 + *(name++) = 0;
204 + if (!*name)
205 + return -EINVAL;
206 +
207 + c = strchr(name, '\n');
208 + if (c)
209 + *c = 0;
210 +
211 + str = buf;
212 + if (*str == '!') {
213 + str++;
214 + active_low = true;
215 + }
216 +
217 + if (kstrtouint(str, 0, &gpio) < 0)
218 + return -EINVAL;
219 +
220 + if (gpio >= sc->sc_ah->caps.num_gpio_pins)
221 + return -EINVAL;
222 +
223 + if (ath_create_gpio_led(sc, gpio, name, NULL, active_low) < 0)
224 + return -EINVAL;
225 +
226 + return count;
227 +}
228 +
229 +static const struct file_operations fops_gpio_led = {
230 + .write = write_file_gpio_led,
231 + .open = simple_open,
232 + .owner = THIS_MODULE,
233 + .llseek = default_llseek,
234 +};
235 +
236 +#endif
237 +
238
239 int ath9k_init_debug(struct ath_hw *ah)
240 {
241 @@ -1417,6 +1472,10 @@ int ath9k_init_debug(struct ath_hw *ah)
242 &fops_eeprom);
243 debugfs_create_file("chanbw", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
244 sc, &fops_chanbw);
245 +#ifdef CONFIG_MAC80211_LEDS
246 + debugfs_create_file("gpio_led", S_IWUSR,
247 + sc->debug.debugfs_phy, sc, &fops_gpio_led);
248 +#endif
249 debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
250 read_file_dma);
251 debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,