Commit | Line | Data |
---|---|---|
fb9987d0 | 1 | /* |
5b68138e | 2 | * Copyright (c) 2010-2011 Atheros Communications Inc. |
fb9987d0 S |
3 | * |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
17 | #include "htc.h" | |
18 | ||
fb9987d0 S |
19 | /*************/ |
20 | /* Utilities */ | |
21 | /*************/ | |
22 | ||
fb9987d0 S |
23 | /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */ |
24 | static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv, | |
25 | struct ath9k_channel *ichan) | |
26 | { | |
27 | enum htc_phymode mode; | |
28 | ||
c75197a7 | 29 | mode = -EINVAL; |
fb9987d0 S |
30 | |
31 | switch (ichan->chanmode) { | |
32 | case CHANNEL_G: | |
33 | case CHANNEL_G_HT20: | |
34 | case CHANNEL_G_HT40PLUS: | |
35 | case CHANNEL_G_HT40MINUS: | |
36 | mode = HTC_MODE_11NG; | |
37 | break; | |
38 | case CHANNEL_A: | |
39 | case CHANNEL_A_HT20: | |
40 | case CHANNEL_A_HT40PLUS: | |
41 | case CHANNEL_A_HT40MINUS: | |
42 | mode = HTC_MODE_11NA; | |
43 | break; | |
44 | default: | |
45 | break; | |
46 | } | |
47 | ||
c75197a7 SM |
48 | WARN_ON(mode < 0); |
49 | ||
fb9987d0 S |
50 | return mode; |
51 | } | |
52 | ||
f933ebed SM |
53 | bool ath9k_htc_setpower(struct ath9k_htc_priv *priv, |
54 | enum ath9k_power_mode mode) | |
bde748a4 VN |
55 | { |
56 | bool ret; | |
57 | ||
58 | mutex_lock(&priv->htc_pm_lock); | |
59 | ret = ath9k_hw_setpower(priv->ah, mode); | |
60 | mutex_unlock(&priv->htc_pm_lock); | |
61 | ||
62 | return ret; | |
63 | } | |
64 | ||
65 | void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv) | |
66 | { | |
67 | mutex_lock(&priv->htc_pm_lock); | |
68 | if (++priv->ps_usecount != 1) | |
69 | goto unlock; | |
70 | ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE); | |
71 | ||
72 | unlock: | |
73 | mutex_unlock(&priv->htc_pm_lock); | |
74 | } | |
75 | ||
76 | void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv) | |
77 | { | |
78 | mutex_lock(&priv->htc_pm_lock); | |
79 | if (--priv->ps_usecount != 0) | |
80 | goto unlock; | |
81 | ||
8a8572a8 VN |
82 | if (priv->ps_idle) |
83 | ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP); | |
84 | else if (priv->ps_enabled) | |
bde748a4 | 85 | ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP); |
8a8572a8 | 86 | |
bde748a4 VN |
87 | unlock: |
88 | mutex_unlock(&priv->htc_pm_lock); | |
89 | } | |
90 | ||
91 | void ath9k_ps_work(struct work_struct *work) | |
92 | { | |
93 | struct ath9k_htc_priv *priv = | |
94 | container_of(work, struct ath9k_htc_priv, | |
95 | ps_work); | |
96 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); | |
97 | ||
98 | /* The chip wakes up after receiving the first beacon | |
99 | while network sleep is enabled. For the driver to | |
100 | be in sync with the hw, set the chip to awake and | |
101 | only then set it to sleep. | |
102 | */ | |
103 | ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP); | |
104 | } | |
105 | ||
7c277349 SM |
106 | static void ath9k_htc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
107 | { | |
108 | struct ath9k_htc_priv *priv = data; | |
109 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; | |
110 | ||
a5fae37d SM |
111 | if ((vif->type == NL80211_IFTYPE_AP) && bss_conf->enable_beacon) |
112 | priv->reconfig_beacon = true; | |
113 | ||
7c277349 SM |
114 | if (bss_conf->assoc) { |
115 | priv->rearm_ani = true; | |
116 | priv->reconfig_beacon = true; | |
117 | } | |
118 | } | |
119 | ||
120 | static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv) | |
121 | { | |
122 | priv->rearm_ani = false; | |
123 | priv->reconfig_beacon = false; | |
124 | ||
125 | ieee80211_iterate_active_interfaces_atomic(priv->hw, | |
126 | ath9k_htc_vif_iter, priv); | |
127 | if (priv->rearm_ani) | |
a236254c | 128 | ath9k_htc_start_ani(priv); |
7c277349 SM |
129 | |
130 | if (priv->reconfig_beacon) { | |
131 | ath9k_htc_ps_wakeup(priv); | |
132 | ath9k_htc_beacon_reconfig(priv); | |
133 | ath9k_htc_ps_restore(priv); | |
134 | } | |
135 | } | |
136 | ||
585895cd SM |
137 | static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
138 | { | |
139 | struct ath9k_vif_iter_data *iter_data = data; | |
140 | int i; | |
141 | ||
142 | for (i = 0; i < ETH_ALEN; i++) | |
143 | iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]); | |
144 | } | |
145 | ||
146 | static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv, | |
147 | struct ieee80211_vif *vif) | |
148 | { | |
149 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
150 | struct ath9k_vif_iter_data iter_data; | |
151 | ||
152 | /* | |
153 | * Use the hardware MAC address as reference, the hardware uses it | |
154 | * together with the BSSID mask when matching addresses. | |
155 | */ | |
156 | iter_data.hw_macaddr = common->macaddr; | |
157 | memset(&iter_data.mask, 0xff, ETH_ALEN); | |
158 | ||
159 | if (vif) | |
160 | ath9k_htc_bssid_iter(&iter_data, vif->addr, vif); | |
161 | ||
162 | /* Get list of all active MAC addresses */ | |
163 | ieee80211_iterate_active_interfaces_atomic(priv->hw, ath9k_htc_bssid_iter, | |
164 | &iter_data); | |
165 | ||
166 | memcpy(common->bssidmask, iter_data.mask, ETH_ALEN); | |
167 | ath_hw_setbssidmask(common); | |
168 | } | |
169 | ||
ffbe7c83 SM |
170 | static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv) |
171 | { | |
172 | if (priv->num_ibss_vif) | |
173 | priv->ah->opmode = NL80211_IFTYPE_ADHOC; | |
174 | else if (priv->num_ap_vif) | |
175 | priv->ah->opmode = NL80211_IFTYPE_AP; | |
176 | else | |
177 | priv->ah->opmode = NL80211_IFTYPE_STATION; | |
178 | ||
179 | ath9k_hw_setopmode(priv->ah); | |
180 | } | |
181 | ||
73908674 SM |
182 | void ath9k_htc_reset(struct ath9k_htc_priv *priv) |
183 | { | |
184 | struct ath_hw *ah = priv->ah; | |
185 | struct ath_common *common = ath9k_hw_common(ah); | |
186 | struct ieee80211_channel *channel = priv->hw->conf.channel; | |
4e3ae387 | 187 | struct ath9k_hw_cal_data *caldata = NULL; |
73908674 SM |
188 | enum htc_phymode mode; |
189 | __be16 htc_mode; | |
190 | u8 cmd_rsp; | |
191 | int ret; | |
192 | ||
193 | mutex_lock(&priv->mutex); | |
194 | ath9k_htc_ps_wakeup(priv); | |
195 | ||
a236254c | 196 | ath9k_htc_stop_ani(priv); |
73908674 | 197 | ieee80211_stop_queues(priv->hw); |
b587fc81 | 198 | |
859c3ca1 | 199 | del_timer_sync(&priv->tx.cleanup_timer); |
b587fc81 SM |
200 | ath9k_htc_tx_drain(priv); |
201 | ||
73908674 SM |
202 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
203 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); | |
204 | WMI_CMD(WMI_STOP_RECV_CMDID); | |
205 | ||
f4c88991 SM |
206 | ath9k_wmi_event_drain(priv); |
207 | ||
4e3ae387 | 208 | caldata = &priv->caldata; |
73908674 SM |
209 | ret = ath9k_hw_reset(ah, ah->curchan, caldata, false); |
210 | if (ret) { | |
211 | ath_err(common, | |
212 | "Unable to reset device (%u Mhz) reset status %d\n", | |
213 | channel->center_freq, ret); | |
214 | } | |
215 | ||
b2a5c3df RM |
216 | ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, |
217 | &priv->curtxpow); | |
73908674 SM |
218 | |
219 | WMI_CMD(WMI_START_RECV_CMDID); | |
220 | ath9k_host_rx_init(priv); | |
221 | ||
222 | mode = ath9k_htc_get_curmode(priv, ah->curchan); | |
223 | htc_mode = cpu_to_be16(mode); | |
224 | WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); | |
225 | ||
226 | WMI_CMD(WMI_ENABLE_INTR_CMDID); | |
227 | htc_start(priv->htc); | |
7c277349 | 228 | ath9k_htc_vif_reconfig(priv); |
73908674 SM |
229 | ieee80211_wake_queues(priv->hw); |
230 | ||
859c3ca1 SM |
231 | mod_timer(&priv->tx.cleanup_timer, |
232 | jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); | |
233 | ||
73908674 SM |
234 | ath9k_htc_ps_restore(priv); |
235 | mutex_unlock(&priv->mutex); | |
236 | } | |
237 | ||
fb9987d0 S |
238 | static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv, |
239 | struct ieee80211_hw *hw, | |
240 | struct ath9k_channel *hchan) | |
241 | { | |
242 | struct ath_hw *ah = priv->ah; | |
243 | struct ath_common *common = ath9k_hw_common(ah); | |
244 | struct ieee80211_conf *conf = &common->hw->conf; | |
039a0721 | 245 | bool fastcc; |
fb9987d0 | 246 | struct ieee80211_channel *channel = hw->conf.channel; |
8354dd3e | 247 | struct ath9k_hw_cal_data *caldata = NULL; |
fb9987d0 | 248 | enum htc_phymode mode; |
7f1f5a00 | 249 | __be16 htc_mode; |
fb9987d0 S |
250 | u8 cmd_rsp; |
251 | int ret; | |
252 | ||
253 | if (priv->op_flags & OP_INVALID) | |
254 | return -EIO; | |
255 | ||
039a0721 | 256 | fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL); |
fb9987d0 | 257 | |
bde748a4 | 258 | ath9k_htc_ps_wakeup(priv); |
b587fc81 | 259 | |
859c3ca1 | 260 | del_timer_sync(&priv->tx.cleanup_timer); |
b587fc81 SM |
261 | ath9k_htc_tx_drain(priv); |
262 | ||
fb9987d0 S |
263 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
264 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); | |
265 | WMI_CMD(WMI_STOP_RECV_CMDID); | |
266 | ||
f4c88991 SM |
267 | ath9k_wmi_event_drain(priv); |
268 | ||
d2182b69 | 269 | ath_dbg(common, CONFIG, |
226afe68 JP |
270 | "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n", |
271 | priv->ah->curchan->channel, | |
272 | channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf), | |
273 | fastcc); | |
fb9987d0 | 274 | |
4e3ae387 RM |
275 | if (!fastcc) |
276 | caldata = &priv->caldata; | |
b587fc81 | 277 | |
20bd2a09 | 278 | ret = ath9k_hw_reset(ah, hchan, caldata, fastcc); |
fb9987d0 | 279 | if (ret) { |
3800276a JP |
280 | ath_err(common, |
281 | "Unable to reset channel (%u Mhz) reset status %d\n", | |
282 | channel->center_freq, ret); | |
fb9987d0 S |
283 | goto err; |
284 | } | |
285 | ||
b2a5c3df RM |
286 | ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, |
287 | &priv->curtxpow); | |
fb9987d0 S |
288 | |
289 | WMI_CMD(WMI_START_RECV_CMDID); | |
290 | if (ret) | |
291 | goto err; | |
292 | ||
293 | ath9k_host_rx_init(priv); | |
294 | ||
295 | mode = ath9k_htc_get_curmode(priv, hchan); | |
296 | htc_mode = cpu_to_be16(mode); | |
297 | WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); | |
298 | if (ret) | |
299 | goto err; | |
300 | ||
301 | WMI_CMD(WMI_ENABLE_INTR_CMDID); | |
302 | if (ret) | |
303 | goto err; | |
304 | ||
305 | htc_start(priv->htc); | |
a5fae37d SM |
306 | |
307 | if (!(priv->op_flags & OP_SCANNING) && | |
308 | !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) | |
309 | ath9k_htc_vif_reconfig(priv); | |
310 | ||
859c3ca1 SM |
311 | mod_timer(&priv->tx.cleanup_timer, |
312 | jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); | |
313 | ||
fb9987d0 | 314 | err: |
bde748a4 | 315 | ath9k_htc_ps_restore(priv); |
fb9987d0 S |
316 | return ret; |
317 | } | |
318 | ||
a97b478c SM |
319 | /* |
320 | * Monitor mode handling is a tad complicated because the firmware requires | |
321 | * an interface to be created exclusively, while mac80211 doesn't associate | |
322 | * an interface with the mode. | |
323 | * | |
324 | * So, for now, only one monitor interface can be configured. | |
325 | */ | |
cc721287 SM |
326 | static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv) |
327 | { | |
328 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
329 | struct ath9k_htc_target_vif hvif; | |
330 | int ret = 0; | |
331 | u8 cmd_rsp; | |
332 | ||
333 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); | |
334 | memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN); | |
a97b478c | 335 | hvif.index = priv->mon_vif_idx; |
cc721287 | 336 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); |
0ff2b5c0 SM |
337 | if (ret) { |
338 | ath_err(common, "Unable to remove monitor interface at idx: %d\n", | |
339 | priv->mon_vif_idx); | |
340 | } | |
341 | ||
cc721287 | 342 | priv->nvifs--; |
a97b478c | 343 | priv->vif_slot &= ~(1 << priv->mon_vif_idx); |
cc721287 SM |
344 | } |
345 | ||
81fc2a33 RM |
346 | static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv) |
347 | { | |
348 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
349 | struct ath9k_htc_target_vif hvif; | |
cc721287 | 350 | struct ath9k_htc_target_sta tsta; |
a97b478c | 351 | int ret = 0, sta_idx; |
81fc2a33 RM |
352 | u8 cmd_rsp; |
353 | ||
a97b478c SM |
354 | if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) || |
355 | (priv->nstations >= ATH9K_HTC_MAX_STA)) { | |
356 | ret = -ENOBUFS; | |
357 | goto err_vif; | |
358 | } | |
81fc2a33 | 359 | |
a97b478c SM |
360 | sta_idx = ffz(priv->sta_slot); |
361 | if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) { | |
362 | ret = -ENOBUFS; | |
363 | goto err_vif; | |
364 | } | |
cc721287 SM |
365 | |
366 | /* | |
367 | * Add an interface. | |
368 | */ | |
81fc2a33 RM |
369 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
370 | memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN); | |
371 | ||
e4c62506 | 372 | hvif.opmode = HTC_M_MONITOR; |
a97b478c | 373 | hvif.index = ffz(priv->vif_slot); |
81fc2a33 RM |
374 | |
375 | WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif); | |
376 | if (ret) | |
a97b478c SM |
377 | goto err_vif; |
378 | ||
379 | /* | |
380 | * Assign the monitor interface index as a special case here. | |
381 | * This is needed when the interface is brought down. | |
382 | */ | |
383 | priv->mon_vif_idx = hvif.index; | |
384 | priv->vif_slot |= (1 << hvif.index); | |
385 | ||
386 | /* | |
387 | * Set the hardware mode to monitor only if there are no | |
388 | * other interfaces. | |
389 | */ | |
390 | if (!priv->nvifs) | |
391 | priv->ah->opmode = NL80211_IFTYPE_MONITOR; | |
81fc2a33 RM |
392 | |
393 | priv->nvifs++; | |
cc721287 SM |
394 | |
395 | /* | |
396 | * Associate a station with the interface for packet injection. | |
397 | */ | |
cc721287 SM |
398 | memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta)); |
399 | ||
400 | memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN); | |
401 | ||
402 | tsta.is_vif_sta = 1; | |
a97b478c | 403 | tsta.sta_index = sta_idx; |
cc721287 | 404 | tsta.vif_index = hvif.index; |
b97c57ff | 405 | tsta.maxampdu = cpu_to_be16(0xffff); |
cc721287 SM |
406 | |
407 | WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); | |
408 | if (ret) { | |
409 | ath_err(common, "Unable to add station entry for monitor mode\n"); | |
a97b478c | 410 | goto err_sta; |
cc721287 SM |
411 | } |
412 | ||
a97b478c | 413 | priv->sta_slot |= (1 << sta_idx); |
cc721287 | 414 | priv->nstations++; |
a97b478c | 415 | priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx; |
55de80d6 SM |
416 | priv->ah->is_monitoring = true; |
417 | ||
d2182b69 | 418 | ath_dbg(common, CONFIG, |
a97b478c SM |
419 | "Attached a monitor interface at idx: %d, sta idx: %d\n", |
420 | priv->mon_vif_idx, sta_idx); | |
421 | ||
81fc2a33 | 422 | return 0; |
cc721287 | 423 | |
a97b478c | 424 | err_sta: |
cc721287 SM |
425 | /* |
426 | * Remove the interface from the target. | |
427 | */ | |
428 | __ath9k_htc_remove_monitor_interface(priv); | |
a97b478c | 429 | err_vif: |
d2182b69 | 430 | ath_dbg(common, FATAL, "Unable to attach a monitor interface\n"); |
a97b478c | 431 | |
cc721287 | 432 | return ret; |
81fc2a33 RM |
433 | } |
434 | ||
435 | static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv) | |
436 | { | |
437 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
81fc2a33 | 438 | int ret = 0; |
cc721287 | 439 | u8 cmd_rsp, sta_idx; |
81fc2a33 | 440 | |
cc721287 | 441 | __ath9k_htc_remove_monitor_interface(priv); |
81fc2a33 | 442 | |
a97b478c | 443 | sta_idx = priv->vif_sta_pos[priv->mon_vif_idx]; |
cc721287 SM |
444 | |
445 | WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); | |
446 | if (ret) { | |
447 | ath_err(common, "Unable to remove station entry for monitor mode\n"); | |
448 | return ret; | |
449 | } | |
450 | ||
a97b478c | 451 | priv->sta_slot &= ~(1 << sta_idx); |
cc721287 | 452 | priv->nstations--; |
55de80d6 | 453 | priv->ah->is_monitoring = false; |
cc721287 | 454 | |
d2182b69 | 455 | ath_dbg(common, CONFIG, |
a97b478c SM |
456 | "Removed a monitor interface at idx: %d, sta idx: %d\n", |
457 | priv->mon_vif_idx, sta_idx); | |
458 | ||
cc721287 | 459 | return 0; |
81fc2a33 RM |
460 | } |
461 | ||
fb9987d0 S |
462 | static int ath9k_htc_add_station(struct ath9k_htc_priv *priv, |
463 | struct ieee80211_vif *vif, | |
464 | struct ieee80211_sta *sta) | |
465 | { | |
466 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
467 | struct ath9k_htc_target_sta tsta; | |
468 | struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; | |
469 | struct ath9k_htc_sta *ista; | |
a97b478c | 470 | int ret, sta_idx; |
fb9987d0 | 471 | u8 cmd_rsp; |
f0dd4980 | 472 | u16 maxampdu; |
fb9987d0 S |
473 | |
474 | if (priv->nstations >= ATH9K_HTC_MAX_STA) | |
475 | return -ENOBUFS; | |
476 | ||
a97b478c SM |
477 | sta_idx = ffz(priv->sta_slot); |
478 | if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) | |
479 | return -ENOBUFS; | |
480 | ||
fb9987d0 S |
481 | memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta)); |
482 | ||
483 | if (sta) { | |
484 | ista = (struct ath9k_htc_sta *) sta->drv_priv; | |
485 | memcpy(&tsta.macaddr, sta->addr, ETH_ALEN); | |
486 | memcpy(&tsta.bssid, common->curbssid, ETH_ALEN); | |
fb9987d0 | 487 | tsta.is_vif_sta = 0; |
a97b478c | 488 | ista->index = sta_idx; |
fb9987d0 S |
489 | } else { |
490 | memcpy(&tsta.macaddr, vif->addr, ETH_ALEN); | |
491 | tsta.is_vif_sta = 1; | |
492 | } | |
493 | ||
a97b478c | 494 | tsta.sta_index = sta_idx; |
fb9987d0 | 495 | tsta.vif_index = avp->index; |
f0dd4980 SM |
496 | |
497 | if (!sta) { | |
498 | tsta.maxampdu = cpu_to_be16(0xffff); | |
499 | } else { | |
500 | maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + | |
501 | sta->ht_cap.ampdu_factor); | |
502 | tsta.maxampdu = cpu_to_be16(maxampdu); | |
503 | } | |
504 | ||
fb9987d0 S |
505 | WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); |
506 | if (ret) { | |
507 | if (sta) | |
3800276a JP |
508 | ath_err(common, |
509 | "Unable to add station entry for: %pM\n", | |
510 | sta->addr); | |
fb9987d0 S |
511 | return ret; |
512 | } | |
513 | ||
a97b478c | 514 | if (sta) { |
d2182b69 | 515 | ath_dbg(common, CONFIG, |
226afe68 JP |
516 | "Added a station entry for: %pM (idx: %d)\n", |
517 | sta->addr, tsta.sta_index); | |
a97b478c | 518 | } else { |
d2182b69 | 519 | ath_dbg(common, CONFIG, |
a97b478c SM |
520 | "Added a station entry for VIF %d (idx: %d)\n", |
521 | avp->index, tsta.sta_index); | |
522 | } | |
fb9987d0 | 523 | |
a97b478c | 524 | priv->sta_slot |= (1 << sta_idx); |
fb9987d0 | 525 | priv->nstations++; |
a97b478c SM |
526 | if (!sta) |
527 | priv->vif_sta_pos[avp->index] = sta_idx; | |
528 | ||
fb9987d0 S |
529 | return 0; |
530 | } | |
531 | ||
532 | static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv, | |
533 | struct ieee80211_vif *vif, | |
534 | struct ieee80211_sta *sta) | |
535 | { | |
536 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
a97b478c | 537 | struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; |
fb9987d0 S |
538 | struct ath9k_htc_sta *ista; |
539 | int ret; | |
540 | u8 cmd_rsp, sta_idx; | |
541 | ||
542 | if (sta) { | |
543 | ista = (struct ath9k_htc_sta *) sta->drv_priv; | |
544 | sta_idx = ista->index; | |
545 | } else { | |
a97b478c | 546 | sta_idx = priv->vif_sta_pos[avp->index]; |
fb9987d0 S |
547 | } |
548 | ||
549 | WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); | |
550 | if (ret) { | |
551 | if (sta) | |
3800276a JP |
552 | ath_err(common, |
553 | "Unable to remove station entry for: %pM\n", | |
554 | sta->addr); | |
fb9987d0 S |
555 | return ret; |
556 | } | |
557 | ||
a97b478c | 558 | if (sta) { |
d2182b69 | 559 | ath_dbg(common, CONFIG, |
226afe68 JP |
560 | "Removed a station entry for: %pM (idx: %d)\n", |
561 | sta->addr, sta_idx); | |
a97b478c | 562 | } else { |
d2182b69 | 563 | ath_dbg(common, CONFIG, |
a97b478c SM |
564 | "Removed a station entry for VIF %d (idx: %d)\n", |
565 | avp->index, sta_idx); | |
566 | } | |
fb9987d0 | 567 | |
a97b478c | 568 | priv->sta_slot &= ~(1 << sta_idx); |
fb9987d0 | 569 | priv->nstations--; |
a97b478c | 570 | |
fb9987d0 S |
571 | return 0; |
572 | } | |
573 | ||
3a0593ef SM |
574 | int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv, |
575 | u8 enable_coex) | |
fb9987d0 S |
576 | { |
577 | struct ath9k_htc_cap_target tcap; | |
578 | int ret; | |
579 | u8 cmd_rsp; | |
580 | ||
581 | memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target)); | |
582 | ||
3a0593ef | 583 | tcap.ampdu_limit = cpu_to_be32(0xffff); |
bd548799 | 584 | tcap.ampdu_subframes = 0xff; |
3a0593ef | 585 | tcap.enable_coex = enable_coex; |
29d9075e | 586 | tcap.tx_chainmask = priv->ah->caps.tx_chainmask; |
fb9987d0 S |
587 | |
588 | WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap); | |
589 | ||
590 | return ret; | |
591 | } | |
592 | ||
0d425a7d S |
593 | static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv, |
594 | struct ieee80211_sta *sta, | |
595 | struct ath9k_htc_target_rate *trate) | |
fb9987d0 | 596 | { |
fb9987d0 S |
597 | struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv; |
598 | struct ieee80211_supported_band *sband; | |
fb9987d0 | 599 | u32 caps = 0; |
0d425a7d | 600 | int i, j; |
fb9987d0 | 601 | |
ea46e644 | 602 | sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band]; |
fb9987d0 S |
603 | |
604 | for (i = 0, j = 0; i < sband->n_bitrates; i++) { | |
605 | if (sta->supp_rates[sband->band] & BIT(i)) { | |
0d425a7d | 606 | trate->rates.legacy_rates.rs_rates[j] |
fb9987d0 S |
607 | = (sband->bitrates[i].bitrate * 2) / 10; |
608 | j++; | |
609 | } | |
610 | } | |
0d425a7d | 611 | trate->rates.legacy_rates.rs_nrates = j; |
fb9987d0 S |
612 | |
613 | if (sta->ht_cap.ht_supported) { | |
614 | for (i = 0, j = 0; i < 77; i++) { | |
615 | if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8))) | |
0d425a7d | 616 | trate->rates.ht_rates.rs_rates[j++] = i; |
fb9987d0 S |
617 | if (j == ATH_HTC_RATE_MAX) |
618 | break; | |
619 | } | |
0d425a7d | 620 | trate->rates.ht_rates.rs_nrates = j; |
fb9987d0 S |
621 | |
622 | caps = WLAN_RC_HT_FLAG; | |
3553727c FF |
623 | if (sta->ht_cap.mcs.rx_mask[1]) |
624 | caps |= WLAN_RC_DS_FLAG; | |
71ba186c VN |
625 | if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) && |
626 | (conf_is_ht40(&priv->hw->conf))) | |
fb9987d0 | 627 | caps |= WLAN_RC_40_FLAG; |
b4dec5e8 S |
628 | if (conf_is_ht40(&priv->hw->conf) && |
629 | (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) | |
630 | caps |= WLAN_RC_SGI_FLAG; | |
631 | else if (conf_is_ht20(&priv->hw->conf) && | |
632 | (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20)) | |
fb9987d0 | 633 | caps |= WLAN_RC_SGI_FLAG; |
fb9987d0 S |
634 | } |
635 | ||
0d425a7d S |
636 | trate->sta_index = ista->index; |
637 | trate->isnew = 1; | |
638 | trate->capflags = cpu_to_be32(caps); | |
639 | } | |
640 | ||
641 | static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv, | |
642 | struct ath9k_htc_target_rate *trate) | |
643 | { | |
644 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
645 | int ret; | |
646 | u8 cmd_rsp; | |
fb9987d0 | 647 | |
0d425a7d | 648 | WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate); |
fb9987d0 | 649 | if (ret) { |
3800276a JP |
650 | ath_err(common, |
651 | "Unable to initialize Rate information on target\n"); | |
fb9987d0 S |
652 | } |
653 | ||
0d425a7d | 654 | return ret; |
fb9987d0 S |
655 | } |
656 | ||
0d425a7d S |
657 | static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv, |
658 | struct ieee80211_sta *sta) | |
fb9987d0 | 659 | { |
fb9987d0 | 660 | struct ath_common *common = ath9k_hw_common(priv->ah); |
0d425a7d | 661 | struct ath9k_htc_target_rate trate; |
fb9987d0 | 662 | int ret; |
fb9987d0 | 663 | |
0d425a7d S |
664 | memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); |
665 | ath9k_htc_setup_rate(priv, sta, &trate); | |
666 | ret = ath9k_htc_send_rate_cmd(priv, &trate); | |
667 | if (!ret) | |
d2182b69 | 668 | ath_dbg(common, CONFIG, |
226afe68 JP |
669 | "Updated target sta: %pM, rate caps: 0x%X\n", |
670 | sta->addr, be32_to_cpu(trate.capflags)); | |
fb9987d0 S |
671 | } |
672 | ||
2c76ef89 S |
673 | static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv, |
674 | struct ieee80211_vif *vif, | |
675 | struct ieee80211_bss_conf *bss_conf) | |
676 | { | |
677 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
678 | struct ath9k_htc_target_rate trate; | |
679 | struct ieee80211_sta *sta; | |
680 | int ret; | |
681 | ||
682 | memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); | |
683 | ||
684 | rcu_read_lock(); | |
685 | sta = ieee80211_find_sta(vif, bss_conf->bssid); | |
686 | if (!sta) { | |
687 | rcu_read_unlock(); | |
688 | return; | |
689 | } | |
690 | ath9k_htc_setup_rate(priv, sta, &trate); | |
691 | rcu_read_unlock(); | |
692 | ||
693 | ret = ath9k_htc_send_rate_cmd(priv, &trate); | |
694 | if (!ret) | |
d2182b69 | 695 | ath_dbg(common, CONFIG, |
226afe68 JP |
696 | "Updated target sta: %pM, rate caps: 0x%X\n", |
697 | bss_conf->bssid, be32_to_cpu(trate.capflags)); | |
2c76ef89 S |
698 | } |
699 | ||
9edd9520 LR |
700 | static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv, |
701 | struct ieee80211_vif *vif, | |
702 | struct ieee80211_sta *sta, | |
703 | enum ieee80211_ampdu_mlme_action action, | |
704 | u16 tid) | |
fb9987d0 S |
705 | { |
706 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
707 | struct ath9k_htc_target_aggr aggr; | |
277a64d1 | 708 | struct ath9k_htc_sta *ista; |
fb9987d0 S |
709 | int ret = 0; |
710 | u8 cmd_rsp; | |
711 | ||
0730d114 | 712 | if (tid >= ATH9K_HTC_MAX_TID) |
fb9987d0 S |
713 | return -EINVAL; |
714 | ||
ef98c3cd | 715 | memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr)); |
ef98c3cd | 716 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
fb9987d0 | 717 | |
fb9987d0 | 718 | aggr.sta_index = ista->index; |
d7ca2139 S |
719 | aggr.tidno = tid & 0xf; |
720 | aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false; | |
fb9987d0 | 721 | |
fb9987d0 S |
722 | WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr); |
723 | if (ret) | |
d2182b69 | 724 | ath_dbg(common, CONFIG, |
226afe68 JP |
725 | "Unable to %s TX aggregation for (%pM, %d)\n", |
726 | (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid); | |
fb9987d0 | 727 | else |
d2182b69 | 728 | ath_dbg(common, CONFIG, |
226afe68 JP |
729 | "%s TX aggregation for (%pM, %d)\n", |
730 | (aggr.aggr_enable) ? "Starting" : "Stopping", | |
731 | sta->addr, tid); | |
fb9987d0 | 732 | |
658ef04f | 733 | spin_lock_bh(&priv->tx.tx_lock); |
d7ca2139 | 734 | ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP; |
658ef04f | 735 | spin_unlock_bh(&priv->tx.tx_lock); |
fb9987d0 | 736 | |
d7ca2139 | 737 | return ret; |
fb9987d0 S |
738 | } |
739 | ||
fb9987d0 S |
740 | /*******/ |
741 | /* ANI */ | |
742 | /*******/ | |
743 | ||
a236254c | 744 | void ath9k_htc_start_ani(struct ath9k_htc_priv *priv) |
fb9987d0 S |
745 | { |
746 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
747 | unsigned long timestamp = jiffies_to_msecs(jiffies); | |
748 | ||
749 | common->ani.longcal_timer = timestamp; | |
750 | common->ani.shortcal_timer = timestamp; | |
751 | common->ani.checkani_timer = timestamp; | |
752 | ||
a236254c SM |
753 | priv->op_flags |= OP_ANI_RUNNING; |
754 | ||
755 | ieee80211_queue_delayed_work(common->hw, &priv->ani_work, | |
fb9987d0 S |
756 | msecs_to_jiffies(ATH_ANI_POLLINTERVAL)); |
757 | } | |
758 | ||
a236254c SM |
759 | void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv) |
760 | { | |
761 | cancel_delayed_work_sync(&priv->ani_work); | |
762 | priv->op_flags &= ~OP_ANI_RUNNING; | |
763 | } | |
764 | ||
765 | void ath9k_htc_ani_work(struct work_struct *work) | |
fb9987d0 S |
766 | { |
767 | struct ath9k_htc_priv *priv = | |
a236254c | 768 | container_of(work, struct ath9k_htc_priv, ani_work.work); |
fb9987d0 S |
769 | struct ath_hw *ah = priv->ah; |
770 | struct ath_common *common = ath9k_hw_common(ah); | |
771 | bool longcal = false; | |
772 | bool shortcal = false; | |
773 | bool aniflag = false; | |
774 | unsigned int timestamp = jiffies_to_msecs(jiffies); | |
775 | u32 cal_interval, short_cal_interval; | |
776 | ||
a236254c SM |
777 | short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ? |
778 | ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL; | |
fb9987d0 | 779 | |
bde748a4 VN |
780 | /* Only calibrate if awake */ |
781 | if (ah->power_mode != ATH9K_PM_AWAKE) | |
782 | goto set_timer; | |
783 | ||
fb9987d0 S |
784 | /* Long calibration runs independently of short calibration. */ |
785 | if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) { | |
786 | longcal = true; | |
d2182b69 | 787 | ath_dbg(common, ANI, "longcal @%lu\n", jiffies); |
fb9987d0 S |
788 | common->ani.longcal_timer = timestamp; |
789 | } | |
790 | ||
791 | /* Short calibration applies only while caldone is false */ | |
792 | if (!common->ani.caldone) { | |
793 | if ((timestamp - common->ani.shortcal_timer) >= | |
794 | short_cal_interval) { | |
795 | shortcal = true; | |
d2182b69 | 796 | ath_dbg(common, ANI, "shortcal @%lu\n", jiffies); |
fb9987d0 S |
797 | common->ani.shortcal_timer = timestamp; |
798 | common->ani.resetcal_timer = timestamp; | |
799 | } | |
800 | } else { | |
801 | if ((timestamp - common->ani.resetcal_timer) >= | |
802 | ATH_RESTART_CALINTERVAL) { | |
803 | common->ani.caldone = ath9k_hw_reset_calvalid(ah); | |
804 | if (common->ani.caldone) | |
805 | common->ani.resetcal_timer = timestamp; | |
806 | } | |
807 | } | |
808 | ||
809 | /* Verify whether we must check ANI */ | |
4279425c NM |
810 | if (ah->config.enable_ani && |
811 | (timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) { | |
fb9987d0 S |
812 | aniflag = true; |
813 | common->ani.checkani_timer = timestamp; | |
814 | } | |
815 | ||
816 | /* Skip all processing if there's nothing to do. */ | |
817 | if (longcal || shortcal || aniflag) { | |
bde748a4 VN |
818 | |
819 | ath9k_htc_ps_wakeup(priv); | |
820 | ||
fb9987d0 S |
821 | /* Call ANI routine if necessary */ |
822 | if (aniflag) | |
823 | ath9k_hw_ani_monitor(ah, ah->curchan); | |
824 | ||
825 | /* Perform calibration if necessary */ | |
35ecfe03 | 826 | if (longcal || shortcal) |
fb9987d0 S |
827 | common->ani.caldone = |
828 | ath9k_hw_calibrate(ah, ah->curchan, | |
82b2d334 | 829 | ah->rxchainmask, longcal); |
fb9987d0 | 830 | |
bde748a4 | 831 | ath9k_htc_ps_restore(priv); |
fb9987d0 S |
832 | } |
833 | ||
bde748a4 | 834 | set_timer: |
fb9987d0 S |
835 | /* |
836 | * Set timer interval based on previous results. | |
837 | * The interval must be the shortest necessary to satisfy ANI, | |
838 | * short calibration and long calibration. | |
839 | */ | |
840 | cal_interval = ATH_LONG_CALINTERVAL; | |
4279425c | 841 | if (ah->config.enable_ani) |
fb9987d0 S |
842 | cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL); |
843 | if (!common->ani.caldone) | |
844 | cal_interval = min(cal_interval, (u32)short_cal_interval); | |
845 | ||
a236254c | 846 | ieee80211_queue_delayed_work(common->hw, &priv->ani_work, |
fb9987d0 S |
847 | msecs_to_jiffies(cal_interval)); |
848 | } | |
849 | ||
fb9987d0 S |
850 | /**********************/ |
851 | /* mac80211 Callbacks */ | |
852 | /**********************/ | |
853 | ||
7bb45683 | 854 | static void ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
fb9987d0 S |
855 | { |
856 | struct ieee80211_hdr *hdr; | |
857 | struct ath9k_htc_priv *priv = hw->priv; | |
8e86a547 | 858 | struct ath_common *common = ath9k_hw_common(priv->ah); |
2c5d57f0 | 859 | int padpos, padsize, ret, slot; |
fb9987d0 S |
860 | |
861 | hdr = (struct ieee80211_hdr *) skb->data; | |
862 | ||
863 | /* Add the padding after the header if this is not already done */ | |
864 | padpos = ath9k_cmn_padpos(hdr->frame_control); | |
865 | padsize = padpos & 3; | |
866 | if (padsize && skb->len > padpos) { | |
8e86a547 | 867 | if (skb_headroom(skb) < padsize) { |
d2182b69 | 868 | ath_dbg(common, XMIT, "No room for padding\n"); |
7bb45683 | 869 | goto fail_tx; |
8e86a547 | 870 | } |
fb9987d0 S |
871 | skb_push(skb, padsize); |
872 | memmove(skb->data, skb->data + padsize, padpos); | |
873 | } | |
874 | ||
2c5d57f0 SM |
875 | slot = ath9k_htc_tx_get_slot(priv); |
876 | if (slot < 0) { | |
d2182b69 | 877 | ath_dbg(common, XMIT, "No free TX slot\n"); |
2c5d57f0 SM |
878 | goto fail_tx; |
879 | } | |
880 | ||
881 | ret = ath9k_htc_tx_start(priv, skb, slot, false); | |
7757dfed | 882 | if (ret != 0) { |
d2182b69 | 883 | ath_dbg(common, XMIT, "Tx failed\n"); |
2c5d57f0 | 884 | goto clear_slot; |
fb9987d0 S |
885 | } |
886 | ||
8e86a547 SM |
887 | ath9k_htc_check_stop_queues(priv); |
888 | ||
7bb45683 | 889 | return; |
fb9987d0 | 890 | |
2c5d57f0 SM |
891 | clear_slot: |
892 | ath9k_htc_tx_clear_slot(priv, slot); | |
fb9987d0 S |
893 | fail_tx: |
894 | dev_kfree_skb_any(skb); | |
fb9987d0 S |
895 | } |
896 | ||
881ac6a5 | 897 | static int ath9k_htc_start(struct ieee80211_hw *hw) |
fb9987d0 S |
898 | { |
899 | struct ath9k_htc_priv *priv = hw->priv; | |
900 | struct ath_hw *ah = priv->ah; | |
901 | struct ath_common *common = ath9k_hw_common(ah); | |
902 | struct ieee80211_channel *curchan = hw->conf.channel; | |
903 | struct ath9k_channel *init_channel; | |
904 | int ret = 0; | |
905 | enum htc_phymode mode; | |
7f1f5a00 | 906 | __be16 htc_mode; |
fb9987d0 S |
907 | u8 cmd_rsp; |
908 | ||
881ac6a5 S |
909 | mutex_lock(&priv->mutex); |
910 | ||
d2182b69 | 911 | ath_dbg(common, CONFIG, |
226afe68 JP |
912 | "Starting driver with initial channel: %d MHz\n", |
913 | curchan->center_freq); | |
fb9987d0 | 914 | |
21d5130b S |
915 | /* Ensure that HW is awake before flushing RX */ |
916 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); | |
917 | WMI_CMD(WMI_FLUSH_RECV_CMDID); | |
918 | ||
fb9987d0 S |
919 | /* setup initial channel */ |
920 | init_channel = ath9k_cmn_get_curchannel(hw, ah); | |
921 | ||
20bd2a09 | 922 | ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false); |
fb9987d0 | 923 | if (ret) { |
3800276a JP |
924 | ath_err(common, |
925 | "Unable to reset hardware; reset status %d (freq %u MHz)\n", | |
926 | ret, curchan->center_freq); | |
881ac6a5 | 927 | mutex_unlock(&priv->mutex); |
8a8572a8 | 928 | return ret; |
fb9987d0 S |
929 | } |
930 | ||
b2a5c3df RM |
931 | ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, |
932 | &priv->curtxpow); | |
fb9987d0 S |
933 | |
934 | mode = ath9k_htc_get_curmode(priv, init_channel); | |
935 | htc_mode = cpu_to_be16(mode); | |
936 | WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); | |
fb9987d0 | 937 | WMI_CMD(WMI_ATH_INIT_CMDID); |
fb9987d0 | 938 | WMI_CMD(WMI_START_RECV_CMDID); |
fb9987d0 S |
939 | |
940 | ath9k_host_rx_init(priv); | |
941 | ||
3a0593ef | 942 | ret = ath9k_htc_update_cap_target(priv, 0); |
1057b750 | 943 | if (ret) |
d2182b69 | 944 | ath_dbg(common, CONFIG, |
1057b750 SM |
945 | "Failed to update capability in target\n"); |
946 | ||
fb9987d0 S |
947 | priv->op_flags &= ~OP_INVALID; |
948 | htc_start(priv->htc); | |
949 | ||
658ef04f | 950 | spin_lock_bh(&priv->tx.tx_lock); |
8e86a547 | 951 | priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP; |
658ef04f | 952 | spin_unlock_bh(&priv->tx.tx_lock); |
7757dfed S |
953 | |
954 | ieee80211_wake_queues(hw); | |
955 | ||
859c3ca1 SM |
956 | mod_timer(&priv->tx.cleanup_timer, |
957 | jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); | |
958 | ||
bf047fcd SM |
959 | ath9k_htc_start_btcoex(priv); |
960 | ||
fb9987d0 | 961 | mutex_unlock(&priv->mutex); |
8a8572a8 | 962 | |
fb9987d0 S |
963 | return ret; |
964 | } | |
965 | ||
881ac6a5 | 966 | static void ath9k_htc_stop(struct ieee80211_hw *hw) |
fb9987d0 S |
967 | { |
968 | struct ath9k_htc_priv *priv = hw->priv; | |
969 | struct ath_hw *ah = priv->ah; | |
970 | struct ath_common *common = ath9k_hw_common(ah); | |
0ff2b5c0 | 971 | int ret __attribute__ ((unused)); |
fb9987d0 S |
972 | u8 cmd_rsp; |
973 | ||
881ac6a5 S |
974 | mutex_lock(&priv->mutex); |
975 | ||
fb9987d0 | 976 | if (priv->op_flags & OP_INVALID) { |
d2182b69 | 977 | ath_dbg(common, ANY, "Device not present\n"); |
881ac6a5 | 978 | mutex_unlock(&priv->mutex); |
fb9987d0 S |
979 | return; |
980 | } | |
981 | ||
bde748a4 | 982 | ath9k_htc_ps_wakeup(priv); |
b587fc81 | 983 | |
fb9987d0 S |
984 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
985 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); | |
986 | WMI_CMD(WMI_STOP_RECV_CMDID); | |
ea888357 | 987 | |
ea888357 | 988 | tasklet_kill(&priv->rx_tasklet); |
fb9987d0 | 989 | |
859c3ca1 | 990 | del_timer_sync(&priv->tx.cleanup_timer); |
b587fc81 | 991 | ath9k_htc_tx_drain(priv); |
f4c88991 SM |
992 | ath9k_wmi_event_drain(priv); |
993 | ||
ea888357 SG |
994 | mutex_unlock(&priv->mutex); |
995 | ||
996 | /* Cancel all the running timers/work .. */ | |
997 | cancel_work_sync(&priv->fatal_work); | |
998 | cancel_work_sync(&priv->ps_work); | |
d244f21e SM |
999 | |
1000 | #ifdef CONFIG_MAC80211_LEDS | |
1001 | cancel_work_sync(&priv->led_work); | |
1002 | #endif | |
a236254c | 1003 | ath9k_htc_stop_ani(priv); |
ea888357 SG |
1004 | |
1005 | mutex_lock(&priv->mutex); | |
1006 | ||
bf047fcd | 1007 | ath9k_htc_stop_btcoex(priv); |
21cb9879 | 1008 | |
a97b478c SM |
1009 | /* Remove a monitor interface if it's present. */ |
1010 | if (priv->ah->is_monitoring) | |
1011 | ath9k_htc_remove_monitor_interface(priv); | |
1012 | ||
e9201f09 S |
1013 | ath9k_hw_phy_disable(ah); |
1014 | ath9k_hw_disable(ah); | |
e9201f09 S |
1015 | ath9k_htc_ps_restore(priv); |
1016 | ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP); | |
1017 | ||
fb9987d0 | 1018 | priv->op_flags |= OP_INVALID; |
fb9987d0 | 1019 | |
d2182b69 | 1020 | ath_dbg(common, CONFIG, "Driver halt\n"); |
8a8572a8 VN |
1021 | mutex_unlock(&priv->mutex); |
1022 | } | |
1023 | ||
fb9987d0 S |
1024 | static int ath9k_htc_add_interface(struct ieee80211_hw *hw, |
1025 | struct ieee80211_vif *vif) | |
1026 | { | |
1027 | struct ath9k_htc_priv *priv = hw->priv; | |
1028 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; | |
1029 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
1030 | struct ath9k_htc_target_vif hvif; | |
1031 | int ret = 0; | |
1032 | u8 cmd_rsp; | |
1033 | ||
1034 | mutex_lock(&priv->mutex); | |
1035 | ||
a97b478c | 1036 | if (priv->nvifs >= ATH9K_HTC_MAX_VIF) { |
ab77c70a | 1037 | mutex_unlock(&priv->mutex); |
0df8359a SM |
1038 | return -ENOBUFS; |
1039 | } | |
1040 | ||
1041 | if (priv->num_ibss_vif || | |
1042 | (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) { | |
1043 | ath_err(common, "IBSS coexistence with other modes is not allowed\n"); | |
1044 | mutex_unlock(&priv->mutex); | |
1045 | return -ENOBUFS; | |
fb9987d0 S |
1046 | } |
1047 | ||
da8d9d93 SM |
1048 | if (((vif->type == NL80211_IFTYPE_AP) || |
1049 | (vif->type == NL80211_IFTYPE_ADHOC)) && | |
1050 | ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) { | |
1051 | ath_err(common, "Max. number of beaconing interfaces reached\n"); | |
1052 | mutex_unlock(&priv->mutex); | |
1053 | return -ENOBUFS; | |
1054 | } | |
1055 | ||
bde748a4 | 1056 | ath9k_htc_ps_wakeup(priv); |
fb9987d0 S |
1057 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
1058 | memcpy(&hvif.myaddr, vif->addr, ETH_ALEN); | |
1059 | ||
1060 | switch (vif->type) { | |
1061 | case NL80211_IFTYPE_STATION: | |
e4c62506 | 1062 | hvif.opmode = HTC_M_STA; |
fb9987d0 S |
1063 | break; |
1064 | case NL80211_IFTYPE_ADHOC: | |
e4c62506 | 1065 | hvif.opmode = HTC_M_IBSS; |
fb9987d0 | 1066 | break; |
da8d9d93 | 1067 | case NL80211_IFTYPE_AP: |
e4c62506 | 1068 | hvif.opmode = HTC_M_HOSTAP; |
da8d9d93 | 1069 | break; |
fb9987d0 | 1070 | default: |
3800276a | 1071 | ath_err(common, |
fb9987d0 S |
1072 | "Interface type %d not yet supported\n", vif->type); |
1073 | ret = -EOPNOTSUPP; | |
1074 | goto out; | |
1075 | } | |
1076 | ||
fb9987d0 | 1077 | /* Index starts from zero on the target */ |
a97b478c | 1078 | avp->index = hvif.index = ffz(priv->vif_slot); |
fb9987d0 S |
1079 | hvif.rtsthreshold = cpu_to_be16(2304); |
1080 | WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif); | |
1081 | if (ret) | |
1082 | goto out; | |
1083 | ||
fb9987d0 S |
1084 | /* |
1085 | * We need a node in target to tx mgmt frames | |
1086 | * before association. | |
1087 | */ | |
1088 | ret = ath9k_htc_add_station(priv, vif, NULL); | |
ab77c70a SM |
1089 | if (ret) { |
1090 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); | |
fb9987d0 | 1091 | goto out; |
ab77c70a | 1092 | } |
fb9987d0 | 1093 | |
585895cd SM |
1094 | ath9k_htc_set_bssid_mask(priv, vif); |
1095 | ||
a97b478c | 1096 | priv->vif_slot |= (1 << avp->index); |
ab77c70a | 1097 | priv->nvifs++; |
a97b478c | 1098 | |
0df8359a | 1099 | INC_VIF(priv, vif->type); |
832f6a18 SM |
1100 | |
1101 | if ((vif->type == NL80211_IFTYPE_AP) || | |
1102 | (vif->type == NL80211_IFTYPE_ADHOC)) | |
1103 | ath9k_htc_assign_bslot(priv, vif); | |
1104 | ||
ffbe7c83 | 1105 | ath9k_htc_set_opmode(priv); |
0df8359a | 1106 | |
a236254c | 1107 | if ((priv->ah->opmode == NL80211_IFTYPE_AP) && |
9b674a02 SM |
1108 | !(priv->op_flags & OP_ANI_RUNNING)) { |
1109 | ath9k_hw_set_tsfadjust(priv->ah, 1); | |
a236254c | 1110 | ath9k_htc_start_ani(priv); |
9b674a02 | 1111 | } |
a236254c | 1112 | |
d2182b69 JP |
1113 | ath_dbg(common, CONFIG, "Attach a VIF of type: %d at idx: %d\n", |
1114 | vif->type, avp->index); | |
a97b478c | 1115 | |
fb9987d0 | 1116 | out: |
bde748a4 | 1117 | ath9k_htc_ps_restore(priv); |
fb9987d0 | 1118 | mutex_unlock(&priv->mutex); |
cb551df2 | 1119 | |
fb9987d0 S |
1120 | return ret; |
1121 | } | |
1122 | ||
1123 | static void ath9k_htc_remove_interface(struct ieee80211_hw *hw, | |
1124 | struct ieee80211_vif *vif) | |
1125 | { | |
1126 | struct ath9k_htc_priv *priv = hw->priv; | |
1127 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
1128 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; | |
1129 | struct ath9k_htc_target_vif hvif; | |
1130 | int ret = 0; | |
1131 | u8 cmd_rsp; | |
1132 | ||
fb9987d0 | 1133 | mutex_lock(&priv->mutex); |
cb551df2 | 1134 | ath9k_htc_ps_wakeup(priv); |
fb9987d0 S |
1135 | |
1136 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); | |
1137 | memcpy(&hvif.myaddr, vif->addr, ETH_ALEN); | |
1138 | hvif.index = avp->index; | |
1139 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); | |
0ff2b5c0 SM |
1140 | if (ret) { |
1141 | ath_err(common, "Unable to remove interface at idx: %d\n", | |
1142 | avp->index); | |
1143 | } | |
fb9987d0 | 1144 | priv->nvifs--; |
a97b478c | 1145 | priv->vif_slot &= ~(1 << avp->index); |
fb9987d0 S |
1146 | |
1147 | ath9k_htc_remove_station(priv, vif, NULL); | |
fb9987d0 | 1148 | |
0df8359a | 1149 | DEC_VIF(priv, vif->type); |
832f6a18 SM |
1150 | |
1151 | if ((vif->type == NL80211_IFTYPE_AP) || | |
1152 | (vif->type == NL80211_IFTYPE_ADHOC)) | |
1153 | ath9k_htc_remove_bslot(priv, vif); | |
1154 | ||
ffbe7c83 | 1155 | ath9k_htc_set_opmode(priv); |
0df8359a | 1156 | |
db32124a SM |
1157 | ath9k_htc_set_bssid_mask(priv, vif); |
1158 | ||
a236254c SM |
1159 | /* |
1160 | * Stop ANI only if there are no associated station interfaces. | |
1161 | */ | |
1162 | if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) { | |
1163 | priv->rearm_ani = false; | |
1164 | ieee80211_iterate_active_interfaces_atomic(priv->hw, | |
1165 | ath9k_htc_vif_iter, priv); | |
1166 | if (!priv->rearm_ani) | |
1167 | ath9k_htc_stop_ani(priv); | |
1168 | } | |
1169 | ||
d2182b69 | 1170 | ath_dbg(common, CONFIG, "Detach Interface at idx: %d\n", avp->index); |
a97b478c | 1171 | |
cb551df2 | 1172 | ath9k_htc_ps_restore(priv); |
fb9987d0 S |
1173 | mutex_unlock(&priv->mutex); |
1174 | } | |
1175 | ||
1176 | static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed) | |
1177 | { | |
1178 | struct ath9k_htc_priv *priv = hw->priv; | |
1179 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
1180 | struct ieee80211_conf *conf = &hw->conf; | |
1181 | ||
1182 | mutex_lock(&priv->mutex); | |
1183 | ||
8a8572a8 VN |
1184 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
1185 | bool enable_radio = false; | |
1186 | bool idle = !!(conf->flags & IEEE80211_CONF_IDLE); | |
1187 | ||
23367769 | 1188 | mutex_lock(&priv->htc_pm_lock); |
8a8572a8 VN |
1189 | if (!idle && priv->ps_idle) |
1190 | enable_radio = true; | |
8a8572a8 | 1191 | priv->ps_idle = idle; |
23367769 | 1192 | mutex_unlock(&priv->htc_pm_lock); |
8a8572a8 VN |
1193 | |
1194 | if (enable_radio) { | |
d2182b69 | 1195 | ath_dbg(common, CONFIG, "not-idle: enabling radio\n"); |
23367769 S |
1196 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
1197 | ath9k_htc_radio_enable(hw); | |
8a8572a8 VN |
1198 | } |
1199 | } | |
1200 | ||
55de80d6 SM |
1201 | /* |
1202 | * Monitor interface should be added before | |
1203 | * IEEE80211_CONF_CHANGE_CHANNEL is handled. | |
1204 | */ | |
1205 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { | |
a97b478c SM |
1206 | if ((conf->flags & IEEE80211_CONF_MONITOR) && |
1207 | !priv->ah->is_monitoring) | |
1208 | ath9k_htc_add_monitor_interface(priv); | |
1209 | else if (priv->ah->is_monitoring) | |
1210 | ath9k_htc_remove_monitor_interface(priv); | |
55de80d6 SM |
1211 | } |
1212 | ||
fb9987d0 S |
1213 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
1214 | struct ieee80211_channel *curchan = hw->conf.channel; | |
1215 | int pos = curchan->hw_value; | |
fb9987d0 | 1216 | |
d2182b69 | 1217 | ath_dbg(common, CONFIG, "Set channel: %d MHz\n", |
226afe68 | 1218 | curchan->center_freq); |
fb9987d0 | 1219 | |
babcbc29 FF |
1220 | ath9k_cmn_update_ichannel(&priv->ah->channels[pos], |
1221 | hw->conf.channel, | |
1222 | hw->conf.channel_type); | |
fb9987d0 S |
1223 | |
1224 | if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) { | |
3800276a | 1225 | ath_err(common, "Unable to set channel\n"); |
fb9987d0 S |
1226 | mutex_unlock(&priv->mutex); |
1227 | return -EINVAL; | |
1228 | } | |
1229 | ||
1230 | } | |
692d6b17 | 1231 | |
bde748a4 VN |
1232 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
1233 | if (conf->flags & IEEE80211_CONF_PS) { | |
1234 | ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP); | |
1235 | priv->ps_enabled = true; | |
1236 | } else { | |
1237 | priv->ps_enabled = false; | |
1238 | cancel_work_sync(&priv->ps_work); | |
1239 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); | |
1240 | } | |
1241 | } | |
fb9987d0 | 1242 | |
692d6b17 SM |
1243 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
1244 | priv->txpowlimit = 2 * conf->power_level; | |
b2a5c3df RM |
1245 | ath9k_cmn_update_txpow(priv->ah, priv->curtxpow, |
1246 | priv->txpowlimit, &priv->curtxpow); | |
692d6b17 SM |
1247 | } |
1248 | ||
23367769 S |
1249 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
1250 | mutex_lock(&priv->htc_pm_lock); | |
1251 | if (!priv->ps_idle) { | |
1252 | mutex_unlock(&priv->htc_pm_lock); | |
1253 | goto out; | |
1254 | } | |
1255 | mutex_unlock(&priv->htc_pm_lock); | |
1256 | ||
d2182b69 | 1257 | ath_dbg(common, CONFIG, "idle: disabling radio\n"); |
881ac6a5 | 1258 | ath9k_htc_radio_disable(hw); |
8a8572a8 VN |
1259 | } |
1260 | ||
23367769 | 1261 | out: |
fb9987d0 | 1262 | mutex_unlock(&priv->mutex); |
fb9987d0 S |
1263 | return 0; |
1264 | } | |
1265 | ||
1266 | #define SUPPORTED_FILTERS \ | |
1267 | (FIF_PROMISC_IN_BSS | \ | |
1268 | FIF_ALLMULTI | \ | |
1269 | FIF_CONTROL | \ | |
1270 | FIF_PSPOLL | \ | |
1271 | FIF_OTHER_BSS | \ | |
1272 | FIF_BCN_PRBRESP_PROMISC | \ | |
94a40c0c | 1273 | FIF_PROBE_REQ | \ |
fb9987d0 S |
1274 | FIF_FCSFAIL) |
1275 | ||
1276 | static void ath9k_htc_configure_filter(struct ieee80211_hw *hw, | |
1277 | unsigned int changed_flags, | |
1278 | unsigned int *total_flags, | |
1279 | u64 multicast) | |
1280 | { | |
1281 | struct ath9k_htc_priv *priv = hw->priv; | |
1282 | u32 rfilt; | |
1283 | ||
1284 | mutex_lock(&priv->mutex); | |
fb9987d0 S |
1285 | changed_flags &= SUPPORTED_FILTERS; |
1286 | *total_flags &= SUPPORTED_FILTERS; | |
1287 | ||
565dfefb | 1288 | if (priv->op_flags & OP_INVALID) { |
d2182b69 | 1289 | ath_dbg(ath9k_hw_common(priv->ah), ANY, |
565dfefb | 1290 | "Unable to configure filter on invalid state\n"); |
1ba45b9e | 1291 | mutex_unlock(&priv->mutex); |
565dfefb RM |
1292 | return; |
1293 | } | |
1294 | ath9k_htc_ps_wakeup(priv); | |
1295 | ||
fb9987d0 | 1296 | priv->rxfilter = *total_flags; |
0995d110 | 1297 | rfilt = ath9k_htc_calcrxfilter(priv); |
fb9987d0 S |
1298 | ath9k_hw_setrxfilter(priv->ah, rfilt); |
1299 | ||
d2182b69 JP |
1300 | ath_dbg(ath9k_hw_common(priv->ah), CONFIG, "Set HW RX filter: 0x%x\n", |
1301 | rfilt); | |
fb9987d0 | 1302 | |
bde748a4 | 1303 | ath9k_htc_ps_restore(priv); |
fb9987d0 S |
1304 | mutex_unlock(&priv->mutex); |
1305 | } | |
1306 | ||
abd984e6 S |
1307 | static int ath9k_htc_sta_add(struct ieee80211_hw *hw, |
1308 | struct ieee80211_vif *vif, | |
1309 | struct ieee80211_sta *sta) | |
fb9987d0 S |
1310 | { |
1311 | struct ath9k_htc_priv *priv = hw->priv; | |
1312 | int ret; | |
1313 | ||
05a30f9c | 1314 | mutex_lock(&priv->mutex); |
cb551df2 | 1315 | ath9k_htc_ps_wakeup(priv); |
abd984e6 S |
1316 | ret = ath9k_htc_add_station(priv, vif, sta); |
1317 | if (!ret) | |
1318 | ath9k_htc_init_rate(priv, sta); | |
1319 | ath9k_htc_ps_restore(priv); | |
1320 | mutex_unlock(&priv->mutex); | |
05a30f9c | 1321 | |
abd984e6 S |
1322 | return ret; |
1323 | } | |
1324 | ||
1325 | static int ath9k_htc_sta_remove(struct ieee80211_hw *hw, | |
1326 | struct ieee80211_vif *vif, | |
1327 | struct ieee80211_sta *sta) | |
1328 | { | |
1329 | struct ath9k_htc_priv *priv = hw->priv; | |
84c9e164 | 1330 | struct ath9k_htc_sta *ista; |
abd984e6 | 1331 | int ret; |
05a30f9c | 1332 | |
abd984e6 S |
1333 | mutex_lock(&priv->mutex); |
1334 | ath9k_htc_ps_wakeup(priv); | |
84c9e164 SM |
1335 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
1336 | htc_sta_drain(priv->htc, ista->index); | |
abd984e6 | 1337 | ret = ath9k_htc_remove_station(priv, vif, sta); |
cb551df2 | 1338 | ath9k_htc_ps_restore(priv); |
05a30f9c | 1339 | mutex_unlock(&priv->mutex); |
abd984e6 S |
1340 | |
1341 | return ret; | |
fb9987d0 S |
1342 | } |
1343 | ||
8a3a3c85 EP |
1344 | static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, |
1345 | struct ieee80211_vif *vif, u16 queue, | |
fb9987d0 S |
1346 | const struct ieee80211_tx_queue_params *params) |
1347 | { | |
1348 | struct ath9k_htc_priv *priv = hw->priv; | |
1349 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
1350 | struct ath9k_tx_queue_info qi; | |
1351 | int ret = 0, qnum; | |
1352 | ||
1353 | if (queue >= WME_NUM_AC) | |
1354 | return 0; | |
1355 | ||
1356 | mutex_lock(&priv->mutex); | |
cb551df2 | 1357 | ath9k_htc_ps_wakeup(priv); |
fb9987d0 S |
1358 | |
1359 | memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); | |
1360 | ||
1361 | qi.tqi_aifs = params->aifs; | |
1362 | qi.tqi_cwmin = params->cw_min; | |
1363 | qi.tqi_cwmax = params->cw_max; | |
1364 | qi.tqi_burstTime = params->txop; | |
1365 | ||
1366 | qnum = get_hw_qnum(queue, priv->hwq_map); | |
1367 | ||
d2182b69 | 1368 | ath_dbg(common, CONFIG, |
226afe68 JP |
1369 | "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", |
1370 | queue, qnum, params->aifs, params->cw_min, | |
1371 | params->cw_max, params->txop); | |
fb9987d0 | 1372 | |
e1572c5e | 1373 | ret = ath_htc_txq_update(priv, qnum, &qi); |
764580f5 | 1374 | if (ret) { |
3800276a | 1375 | ath_err(common, "TXQ Update failed\n"); |
764580f5 S |
1376 | goto out; |
1377 | } | |
fb9987d0 | 1378 | |
764580f5 | 1379 | if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) && |
e8c35a77 | 1380 | (qnum == priv->hwq_map[WME_AC_BE])) |
764580f5 S |
1381 | ath9k_htc_beaconq_config(priv); |
1382 | out: | |
cb551df2 | 1383 | ath9k_htc_ps_restore(priv); |
fb9987d0 S |
1384 | mutex_unlock(&priv->mutex); |
1385 | ||
1386 | return ret; | |
1387 | } | |
1388 | ||
1389 | static int ath9k_htc_set_key(struct ieee80211_hw *hw, | |
1390 | enum set_key_cmd cmd, | |
1391 | struct ieee80211_vif *vif, | |
1392 | struct ieee80211_sta *sta, | |
1393 | struct ieee80211_key_conf *key) | |
1394 | { | |
1395 | struct ath9k_htc_priv *priv = hw->priv; | |
1396 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
1397 | int ret = 0; | |
1398 | ||
e1572c5e | 1399 | if (htc_modparam_nohwcrypt) |
fb9987d0 S |
1400 | return -ENOSPC; |
1401 | ||
d7d312ca AQ |
1402 | if ((vif->type == NL80211_IFTYPE_ADHOC || |
1403 | vif->type == NL80211_IFTYPE_MESH_POINT) && | |
1404 | (key->cipher == WLAN_CIPHER_SUITE_TKIP || | |
1405 | key->cipher == WLAN_CIPHER_SUITE_CCMP) && | |
1406 | !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) { | |
1407 | /* | |
1408 | * For now, disable hw crypto for the RSN IBSS group keys. This | |
1409 | * could be optimized in the future to use a modified key cache | |
1410 | * design to support per-STA RX GTK, but until that gets | |
1411 | * implemented, use of software crypto for group addressed | |
1412 | * frames is a acceptable to allow RSN IBSS to be used. | |
1413 | */ | |
1414 | return -EOPNOTSUPP; | |
1415 | } | |
1416 | ||
fb9987d0 | 1417 | mutex_lock(&priv->mutex); |
d2182b69 | 1418 | ath_dbg(common, CONFIG, "Set HW Key\n"); |
bde748a4 | 1419 | ath9k_htc_ps_wakeup(priv); |
fb9987d0 S |
1420 | |
1421 | switch (cmd) { | |
1422 | case SET_KEY: | |
040e539e | 1423 | ret = ath_key_config(common, vif, sta, key); |
fb9987d0 S |
1424 | if (ret >= 0) { |
1425 | key->hw_key_idx = ret; | |
1426 | /* push IV and Michael MIC generation to stack */ | |
1427 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
97359d12 | 1428 | if (key->cipher == WLAN_CIPHER_SUITE_TKIP) |
fb9987d0 | 1429 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
97359d12 JB |
1430 | if (priv->ah->sw_mgmt_crypto && |
1431 | key->cipher == WLAN_CIPHER_SUITE_CCMP) | |
fb9987d0 S |
1432 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT; |
1433 | ret = 0; | |
1434 | } | |
1435 | break; | |
1436 | case DISABLE_KEY: | |
040e539e | 1437 | ath_key_delete(common, key); |
fb9987d0 S |
1438 | break; |
1439 | default: | |
1440 | ret = -EINVAL; | |
1441 | } | |
1442 | ||
bde748a4 | 1443 | ath9k_htc_ps_restore(priv); |
fb9987d0 S |
1444 | mutex_unlock(&priv->mutex); |
1445 | ||
1446 | return ret; | |
1447 | } | |
1448 | ||
0cd075d7 SM |
1449 | static void ath9k_htc_set_bssid(struct ath9k_htc_priv *priv) |
1450 | { | |
1451 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
1452 | ||
1453 | ath9k_hw_write_associd(priv->ah); | |
d2182b69 | 1454 | ath_dbg(common, CONFIG, "BSSID: %pM aid: 0x%x\n", |
0cd075d7 SM |
1455 | common->curbssid, common->curaid); |
1456 | } | |
1457 | ||
1458 | static void ath9k_htc_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif) | |
1459 | { | |
1460 | struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data; | |
1461 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
1462 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; | |
1463 | ||
1464 | if ((vif->type == NL80211_IFTYPE_STATION) && bss_conf->assoc) { | |
1465 | common->curaid = bss_conf->aid; | |
1466 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); | |
1467 | } | |
1468 | } | |
1469 | ||
1470 | static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv *priv) | |
1471 | { | |
1472 | if (priv->num_sta_assoc_vif == 1) { | |
1473 | ieee80211_iterate_active_interfaces_atomic(priv->hw, | |
1474 | ath9k_htc_bss_iter, priv); | |
1475 | ath9k_htc_set_bssid(priv); | |
1476 | } | |
1477 | } | |
1478 | ||
fb9987d0 S |
1479 | static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw, |
1480 | struct ieee80211_vif *vif, | |
1481 | struct ieee80211_bss_conf *bss_conf, | |
1482 | u32 changed) | |
1483 | { | |
1484 | struct ath9k_htc_priv *priv = hw->priv; | |
1485 | struct ath_hw *ah = priv->ah; | |
1486 | struct ath_common *common = ath9k_hw_common(ah); | |
1487 | ||
1488 | mutex_lock(&priv->mutex); | |
bde748a4 | 1489 | ath9k_htc_ps_wakeup(priv); |
fb9987d0 S |
1490 | |
1491 | if (changed & BSS_CHANGED_ASSOC) { | |
d2182b69 | 1492 | ath_dbg(common, CONFIG, "BSS Changed ASSOC %d\n", |
0cd075d7 | 1493 | bss_conf->assoc); |
e7a2a4f5 | 1494 | |
0cd075d7 SM |
1495 | bss_conf->assoc ? |
1496 | priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--; | |
e7a2a4f5 | 1497 | |
0cd075d7 SM |
1498 | if (priv->ah->opmode == NL80211_IFTYPE_STATION) { |
1499 | if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1)) | |
e7a2a4f5 | 1500 | ath9k_htc_start_ani(priv); |
0cd075d7 | 1501 | else if (priv->num_sta_assoc_vif == 0) |
e7a2a4f5 SM |
1502 | ath9k_htc_stop_ani(priv); |
1503 | } | |
fb9987d0 S |
1504 | } |
1505 | ||
1506 | if (changed & BSS_CHANGED_BSSID) { | |
0cd075d7 SM |
1507 | if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) { |
1508 | common->curaid = bss_conf->aid; | |
e7a2a4f5 | 1509 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); |
0cd075d7 SM |
1510 | ath9k_htc_set_bssid(priv); |
1511 | } else if (priv->ah->opmode == NL80211_IFTYPE_STATION) { | |
1512 | ath9k_htc_choose_set_bssid(priv); | |
e7a2a4f5 | 1513 | } |
fb9987d0 S |
1514 | } |
1515 | ||
a5fae37d | 1516 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) { |
d2182b69 JP |
1517 | ath_dbg(common, CONFIG, "Beacon enabled for BSS: %pM\n", |
1518 | bss_conf->bssid); | |
9b674a02 | 1519 | ath9k_htc_set_tsfadjust(priv, vif); |
fb9987d0 | 1520 | priv->op_flags |= OP_ENABLE_BEACON; |
1c3652a5 | 1521 | ath9k_htc_beacon_config(priv, vif); |
fb9987d0 S |
1522 | } |
1523 | ||
a5fae37d SM |
1524 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) { |
1525 | /* | |
1526 | * Disable SWBA interrupt only if there are no | |
1527 | * AP/IBSS interfaces. | |
1528 | */ | |
1529 | if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) { | |
d2182b69 | 1530 | ath_dbg(common, CONFIG, |
a5fae37d SM |
1531 | "Beacon disabled for BSS: %pM\n", |
1532 | bss_conf->bssid); | |
1533 | priv->op_flags &= ~OP_ENABLE_BEACON; | |
1534 | ath9k_htc_beacon_config(priv, vif); | |
1535 | } | |
1536 | } | |
1537 | ||
1538 | if (changed & BSS_CHANGED_BEACON_INT) { | |
1539 | /* | |
1540 | * Reset the HW TSF for the first AP interface. | |
1541 | */ | |
1542 | if ((priv->ah->opmode == NL80211_IFTYPE_AP) && | |
1543 | (priv->nvifs == 1) && | |
1544 | (priv->num_ap_vif == 1) && | |
1545 | (vif->type == NL80211_IFTYPE_AP)) { | |
1546 | priv->op_flags |= OP_TSF_RESET; | |
1547 | } | |
d2182b69 | 1548 | ath_dbg(common, CONFIG, |
a5fae37d SM |
1549 | "Beacon interval changed for BSS: %pM\n", |
1550 | bss_conf->bssid); | |
1c3652a5 | 1551 | ath9k_htc_beacon_config(priv, vif); |
fb9987d0 S |
1552 | } |
1553 | ||
fb9987d0 S |
1554 | if (changed & BSS_CHANGED_ERP_SLOT) { |
1555 | if (bss_conf->use_short_slot) | |
1556 | ah->slottime = 9; | |
1557 | else | |
1558 | ah->slottime = 20; | |
1559 | ||
1560 | ath9k_hw_init_global_settings(ah); | |
1561 | } | |
1562 | ||
2c76ef89 S |
1563 | if (changed & BSS_CHANGED_HT) |
1564 | ath9k_htc_update_rate(priv, vif, bss_conf); | |
1565 | ||
bde748a4 | 1566 | ath9k_htc_ps_restore(priv); |
fb9987d0 S |
1567 | mutex_unlock(&priv->mutex); |
1568 | } | |
1569 | ||
37a41b4a EP |
1570 | static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw, |
1571 | struct ieee80211_vif *vif) | |
fb9987d0 S |
1572 | { |
1573 | struct ath9k_htc_priv *priv = hw->priv; | |
1574 | u64 tsf; | |
1575 | ||
1576 | mutex_lock(&priv->mutex); | |
cb551df2 | 1577 | ath9k_htc_ps_wakeup(priv); |
fb9987d0 | 1578 | tsf = ath9k_hw_gettsf64(priv->ah); |
cb551df2 | 1579 | ath9k_htc_ps_restore(priv); |
fb9987d0 S |
1580 | mutex_unlock(&priv->mutex); |
1581 | ||
1582 | return tsf; | |
1583 | } | |
1584 | ||
37a41b4a EP |
1585 | static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, |
1586 | struct ieee80211_vif *vif, u64 tsf) | |
fb9987d0 S |
1587 | { |
1588 | struct ath9k_htc_priv *priv = hw->priv; | |
1589 | ||
1590 | mutex_lock(&priv->mutex); | |
cb551df2 | 1591 | ath9k_htc_ps_wakeup(priv); |
fb9987d0 | 1592 | ath9k_hw_settsf64(priv->ah, tsf); |
cb551df2 | 1593 | ath9k_htc_ps_restore(priv); |
fb9987d0 S |
1594 | mutex_unlock(&priv->mutex); |
1595 | } | |
1596 | ||
37a41b4a EP |
1597 | static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw, |
1598 | struct ieee80211_vif *vif) | |
fb9987d0 S |
1599 | { |
1600 | struct ath9k_htc_priv *priv = hw->priv; | |
1601 | ||
1602 | mutex_lock(&priv->mutex); | |
cb551df2 | 1603 | ath9k_htc_ps_wakeup(priv); |
fb9987d0 | 1604 | ath9k_hw_reset_tsf(priv->ah); |
bde748a4 | 1605 | ath9k_htc_ps_restore(priv); |
cb551df2 | 1606 | mutex_unlock(&priv->mutex); |
fb9987d0 S |
1607 | } |
1608 | ||
1609 | static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw, | |
1610 | struct ieee80211_vif *vif, | |
1611 | enum ieee80211_ampdu_mlme_action action, | |
1612 | struct ieee80211_sta *sta, | |
0b01f030 | 1613 | u16 tid, u16 *ssn, u8 buf_size) |
fb9987d0 S |
1614 | { |
1615 | struct ath9k_htc_priv *priv = hw->priv; | |
fb9987d0 | 1616 | struct ath9k_htc_sta *ista; |
d7ca2139 | 1617 | int ret = 0; |
fb9987d0 | 1618 | |
87df8957 | 1619 | mutex_lock(&priv->mutex); |
c58ca5b5 | 1620 | ath9k_htc_ps_wakeup(priv); |
87df8957 | 1621 | |
fb9987d0 S |
1622 | switch (action) { |
1623 | case IEEE80211_AMPDU_RX_START: | |
1624 | break; | |
1625 | case IEEE80211_AMPDU_RX_STOP: | |
1626 | break; | |
1627 | case IEEE80211_AMPDU_TX_START: | |
d7ca2139 S |
1628 | ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid); |
1629 | if (!ret) | |
1630 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
1631 | break; | |
fb9987d0 | 1632 | case IEEE80211_AMPDU_TX_STOP: |
d7ca2139 S |
1633 | ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid); |
1634 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
fb9987d0 S |
1635 | break; |
1636 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
1637 | ista = (struct ath9k_htc_sta *) sta->drv_priv; | |
658ef04f | 1638 | spin_lock_bh(&priv->tx.tx_lock); |
fb9987d0 | 1639 | ista->tid_state[tid] = AGGR_OPERATIONAL; |
658ef04f | 1640 | spin_unlock_bh(&priv->tx.tx_lock); |
fb9987d0 S |
1641 | break; |
1642 | default: | |
3800276a | 1643 | ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n"); |
fb9987d0 S |
1644 | } |
1645 | ||
c58ca5b5 | 1646 | ath9k_htc_ps_restore(priv); |
87df8957 SM |
1647 | mutex_unlock(&priv->mutex); |
1648 | ||
d7ca2139 | 1649 | return ret; |
fb9987d0 S |
1650 | } |
1651 | ||
1652 | static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw) | |
1653 | { | |
1654 | struct ath9k_htc_priv *priv = hw->priv; | |
1655 | ||
1656 | mutex_lock(&priv->mutex); | |
1657 | spin_lock_bh(&priv->beacon_lock); | |
1658 | priv->op_flags |= OP_SCANNING; | |
1659 | spin_unlock_bh(&priv->beacon_lock); | |
bde748a4 | 1660 | cancel_work_sync(&priv->ps_work); |
a236254c | 1661 | ath9k_htc_stop_ani(priv); |
fb9987d0 S |
1662 | mutex_unlock(&priv->mutex); |
1663 | } | |
1664 | ||
1665 | static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw) | |
1666 | { | |
1667 | struct ath9k_htc_priv *priv = hw->priv; | |
1668 | ||
1669 | mutex_lock(&priv->mutex); | |
1670 | spin_lock_bh(&priv->beacon_lock); | |
1671 | priv->op_flags &= ~OP_SCANNING; | |
1672 | spin_unlock_bh(&priv->beacon_lock); | |
7c277349 SM |
1673 | ath9k_htc_ps_wakeup(priv); |
1674 | ath9k_htc_vif_reconfig(priv); | |
bde748a4 | 1675 | ath9k_htc_ps_restore(priv); |
cb551df2 | 1676 | mutex_unlock(&priv->mutex); |
fb9987d0 S |
1677 | } |
1678 | ||
1679 | static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | |
1680 | { | |
1681 | return 0; | |
1682 | } | |
1683 | ||
1684 | static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw, | |
1685 | u8 coverage_class) | |
1686 | { | |
1687 | struct ath9k_htc_priv *priv = hw->priv; | |
1688 | ||
1689 | mutex_lock(&priv->mutex); | |
cb551df2 | 1690 | ath9k_htc_ps_wakeup(priv); |
fb9987d0 S |
1691 | priv->ah->coverage_class = coverage_class; |
1692 | ath9k_hw_init_global_settings(priv->ah); | |
cb551df2 | 1693 | ath9k_htc_ps_restore(priv); |
fb9987d0 S |
1694 | mutex_unlock(&priv->mutex); |
1695 | } | |
1696 | ||
e2186b7c SM |
1697 | /* |
1698 | * Currently, this is used only for selecting the minimum rate | |
1699 | * for management frames, rate selection for data frames remain | |
1700 | * unaffected. | |
1701 | */ | |
1702 | static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw *hw, | |
1703 | struct ieee80211_vif *vif, | |
1704 | const struct cfg80211_bitrate_mask *mask) | |
1705 | { | |
1706 | struct ath9k_htc_priv *priv = hw->priv; | |
1707 | struct ath_common *common = ath9k_hw_common(priv->ah); | |
1708 | struct ath9k_htc_target_rate_mask tmask; | |
1709 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; | |
1710 | int ret = 0; | |
1711 | u8 cmd_rsp; | |
1712 | ||
1713 | memset(&tmask, 0, sizeof(struct ath9k_htc_target_rate_mask)); | |
1714 | ||
1715 | tmask.vif_index = avp->index; | |
1716 | tmask.band = IEEE80211_BAND_2GHZ; | |
1717 | tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_2GHZ].legacy); | |
1718 | ||
1719 | WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask); | |
1720 | if (ret) { | |
1721 | ath_err(common, | |
1722 | "Unable to set 2G rate mask for " | |
1723 | "interface at idx: %d\n", avp->index); | |
1724 | goto out; | |
1725 | } | |
1726 | ||
1727 | tmask.band = IEEE80211_BAND_5GHZ; | |
1728 | tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_5GHZ].legacy); | |
1729 | ||
1730 | WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask); | |
1731 | if (ret) { | |
1732 | ath_err(common, | |
1733 | "Unable to set 5G rate mask for " | |
1734 | "interface at idx: %d\n", avp->index); | |
1735 | goto out; | |
1736 | } | |
1737 | ||
d2182b69 | 1738 | ath_dbg(common, CONFIG, "Set bitrate masks: 0x%x, 0x%x\n", |
e2186b7c SM |
1739 | mask->control[IEEE80211_BAND_2GHZ].legacy, |
1740 | mask->control[IEEE80211_BAND_5GHZ].legacy); | |
1741 | out: | |
1742 | return ret; | |
1743 | } | |
1744 | ||
5fa71984 MSS |
1745 | |
1746 | static int ath9k_htc_get_stats(struct ieee80211_hw *hw, | |
1747 | struct ieee80211_low_level_stats *stats) | |
1748 | { | |
1749 | struct ath9k_htc_priv *priv = hw->priv; | |
1750 | struct ath_hw *ah = priv->ah; | |
1751 | struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats; | |
1752 | ||
1753 | stats->dot11ACKFailureCount = mib_stats->ackrcv_bad; | |
1754 | stats->dot11RTSFailureCount = mib_stats->rts_bad; | |
1755 | stats->dot11FCSErrorCount = mib_stats->fcs_bad; | |
1756 | stats->dot11RTSSuccessCount = mib_stats->rts_good; | |
1757 | ||
1758 | return 0; | |
1759 | } | |
1760 | ||
fb9987d0 S |
1761 | struct ieee80211_ops ath9k_htc_ops = { |
1762 | .tx = ath9k_htc_tx, | |
1763 | .start = ath9k_htc_start, | |
1764 | .stop = ath9k_htc_stop, | |
1765 | .add_interface = ath9k_htc_add_interface, | |
1766 | .remove_interface = ath9k_htc_remove_interface, | |
1767 | .config = ath9k_htc_config, | |
1768 | .configure_filter = ath9k_htc_configure_filter, | |
abd984e6 S |
1769 | .sta_add = ath9k_htc_sta_add, |
1770 | .sta_remove = ath9k_htc_sta_remove, | |
fb9987d0 S |
1771 | .conf_tx = ath9k_htc_conf_tx, |
1772 | .bss_info_changed = ath9k_htc_bss_info_changed, | |
1773 | .set_key = ath9k_htc_set_key, | |
1774 | .get_tsf = ath9k_htc_get_tsf, | |
1775 | .set_tsf = ath9k_htc_set_tsf, | |
1776 | .reset_tsf = ath9k_htc_reset_tsf, | |
1777 | .ampdu_action = ath9k_htc_ampdu_action, | |
1778 | .sw_scan_start = ath9k_htc_sw_scan_start, | |
1779 | .sw_scan_complete = ath9k_htc_sw_scan_complete, | |
1780 | .set_rts_threshold = ath9k_htc_set_rts_threshold, | |
1781 | .rfkill_poll = ath9k_htc_rfkill_poll_state, | |
1782 | .set_coverage_class = ath9k_htc_set_coverage_class, | |
e2186b7c | 1783 | .set_bitrate_mask = ath9k_htc_set_bitrate_mask, |
5fa71984 | 1784 | .get_stats = ath9k_htc_get_stats, |
fb9987d0 | 1785 | }; |