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