ath9k/ath9k_htc: remove redundand checks for dual-stream tx support
[pandora-kernel.git] / drivers / net / wireless / ath / ath9k / htc_drv_main.c
1 /*
2  * Copyright (c) 2010 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 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
20 static struct dentry *ath9k_debugfs_root;
21 #endif
22
23 /*************/
24 /* Utilities */
25 /*************/
26
27 static void ath_update_txpow(struct ath9k_htc_priv *priv)
28 {
29         struct ath_hw *ah = priv->ah;
30
31         if (priv->curtxpow != priv->txpowlimit) {
32                 ath9k_hw_set_txpowerlimit(ah, priv->txpowlimit);
33                 /* read back in case value is clamped */
34                 priv->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
35         }
36 }
37
38 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
39 static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv,
40                                               struct ath9k_channel *ichan)
41 {
42         enum htc_phymode mode;
43
44         mode = HTC_MODE_AUTO;
45
46         switch (ichan->chanmode) {
47         case CHANNEL_G:
48         case CHANNEL_G_HT20:
49         case CHANNEL_G_HT40PLUS:
50         case CHANNEL_G_HT40MINUS:
51                 mode = HTC_MODE_11NG;
52                 break;
53         case CHANNEL_A:
54         case CHANNEL_A_HT20:
55         case CHANNEL_A_HT40PLUS:
56         case CHANNEL_A_HT40MINUS:
57                 mode = HTC_MODE_11NA;
58                 break;
59         default:
60                 break;
61         }
62
63         return mode;
64 }
65
66 static bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
67                                enum ath9k_power_mode mode)
68 {
69         bool ret;
70
71         mutex_lock(&priv->htc_pm_lock);
72         ret = ath9k_hw_setpower(priv->ah, mode);
73         mutex_unlock(&priv->htc_pm_lock);
74
75         return ret;
76 }
77
78 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv)
79 {
80         mutex_lock(&priv->htc_pm_lock);
81         if (++priv->ps_usecount != 1)
82                 goto unlock;
83         ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE);
84
85 unlock:
86         mutex_unlock(&priv->htc_pm_lock);
87 }
88
89 void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv)
90 {
91         mutex_lock(&priv->htc_pm_lock);
92         if (--priv->ps_usecount != 0)
93                 goto unlock;
94
95         if (priv->ps_idle)
96                 ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP);
97         else if (priv->ps_enabled)
98                 ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP);
99
100 unlock:
101         mutex_unlock(&priv->htc_pm_lock);
102 }
103
104 void ath9k_ps_work(struct work_struct *work)
105 {
106         struct ath9k_htc_priv *priv =
107                 container_of(work, struct ath9k_htc_priv,
108                              ps_work);
109         ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
110
111         /* The chip wakes up after receiving the first beacon
112            while network sleep is enabled. For the driver to
113            be in sync with the hw, set the chip to awake and
114            only then set it to sleep.
115          */
116         ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
117 }
118
119 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
120                                  struct ieee80211_hw *hw,
121                                  struct ath9k_channel *hchan)
122 {
123         struct ath_hw *ah = priv->ah;
124         struct ath_common *common = ath9k_hw_common(ah);
125         struct ieee80211_conf *conf = &common->hw->conf;
126         bool fastcc = true;
127         struct ieee80211_channel *channel = hw->conf.channel;
128         enum htc_phymode mode;
129         __be16 htc_mode;
130         u8 cmd_rsp;
131         int ret;
132
133         if (priv->op_flags & OP_INVALID)
134                 return -EIO;
135
136         if (priv->op_flags & OP_FULL_RESET)
137                 fastcc = false;
138
139         /* Fiddle around with fastcc later on, for now just use full reset */
140         fastcc = false;
141         ath9k_htc_ps_wakeup(priv);
142         htc_stop(priv->htc);
143         WMI_CMD(WMI_DISABLE_INTR_CMDID);
144         WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
145         WMI_CMD(WMI_STOP_RECV_CMDID);
146
147         ath_print(common, ATH_DBG_CONFIG,
148                   "(%u MHz) -> (%u MHz), HT: %d, HT40: %d\n",
149                   priv->ah->curchan->channel,
150                   channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf));
151
152         ret = ath9k_hw_reset(ah, hchan, fastcc);
153         if (ret) {
154                 ath_print(common, ATH_DBG_FATAL,
155                           "Unable to reset channel (%u Mhz) "
156                           "reset status %d\n", channel->center_freq, ret);
157                 goto err;
158         }
159
160         ath_update_txpow(priv);
161
162         WMI_CMD(WMI_START_RECV_CMDID);
163         if (ret)
164                 goto err;
165
166         ath9k_host_rx_init(priv);
167
168         mode = ath9k_htc_get_curmode(priv, hchan);
169         htc_mode = cpu_to_be16(mode);
170         WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
171         if (ret)
172                 goto err;
173
174         WMI_CMD(WMI_ENABLE_INTR_CMDID);
175         if (ret)
176                 goto err;
177
178         htc_start(priv->htc);
179
180         priv->op_flags &= ~OP_FULL_RESET;
181 err:
182         ath9k_htc_ps_restore(priv);
183         return ret;
184 }
185
186 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
187 {
188         struct ath_common *common = ath9k_hw_common(priv->ah);
189         struct ath9k_htc_target_vif hvif;
190         int ret = 0;
191         u8 cmd_rsp;
192
193         if (priv->nvifs > 0)
194                 return -ENOBUFS;
195
196         memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
197         memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
198
199         hvif.opmode = cpu_to_be32(HTC_M_MONITOR);
200         priv->ah->opmode = NL80211_IFTYPE_MONITOR;
201         hvif.index = priv->nvifs;
202
203         WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
204         if (ret)
205                 return ret;
206
207         priv->nvifs++;
208         return 0;
209 }
210
211 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
212 {
213         struct ath_common *common = ath9k_hw_common(priv->ah);
214         struct ath9k_htc_target_vif hvif;
215         int ret = 0;
216         u8 cmd_rsp;
217
218         memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
219         memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
220         hvif.index = 0; /* Should do for now */
221         WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
222         priv->nvifs--;
223
224         return ret;
225 }
226
227 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
228                                  struct ieee80211_vif *vif,
229                                  struct ieee80211_sta *sta)
230 {
231         struct ath_common *common = ath9k_hw_common(priv->ah);
232         struct ath9k_htc_target_sta tsta;
233         struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
234         struct ath9k_htc_sta *ista;
235         int ret;
236         u8 cmd_rsp;
237
238         if (priv->nstations >= ATH9K_HTC_MAX_STA)
239                 return -ENOBUFS;
240
241         memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
242
243         if (sta) {
244                 ista = (struct ath9k_htc_sta *) sta->drv_priv;
245                 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
246                 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
247                 tsta.associd = common->curaid;
248                 tsta.is_vif_sta = 0;
249                 tsta.valid = true;
250                 ista->index = priv->nstations;
251         } else {
252                 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
253                 tsta.is_vif_sta = 1;
254         }
255
256         tsta.sta_index = priv->nstations;
257         tsta.vif_index = avp->index;
258         tsta.maxampdu = 0xffff;
259         if (sta && sta->ht_cap.ht_supported)
260                 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
261
262         WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
263         if (ret) {
264                 if (sta)
265                         ath_print(common, ATH_DBG_FATAL,
266                           "Unable to add station entry for: %pM\n", sta->addr);
267                 return ret;
268         }
269
270         if (sta)
271                 ath_print(common, ATH_DBG_CONFIG,
272                           "Added a station entry for: %pM (idx: %d)\n",
273                           sta->addr, tsta.sta_index);
274
275         priv->nstations++;
276         return 0;
277 }
278
279 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
280                                     struct ieee80211_vif *vif,
281                                     struct ieee80211_sta *sta)
282 {
283         struct ath_common *common = ath9k_hw_common(priv->ah);
284         struct ath9k_htc_sta *ista;
285         int ret;
286         u8 cmd_rsp, sta_idx;
287
288         if (sta) {
289                 ista = (struct ath9k_htc_sta *) sta->drv_priv;
290                 sta_idx = ista->index;
291         } else {
292                 sta_idx = 0;
293         }
294
295         WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
296         if (ret) {
297                 if (sta)
298                         ath_print(common, ATH_DBG_FATAL,
299                           "Unable to remove station entry for: %pM\n",
300                           sta->addr);
301                 return ret;
302         }
303
304         if (sta)
305                 ath_print(common, ATH_DBG_CONFIG,
306                           "Removed a station entry for: %pM (idx: %d)\n",
307                           sta->addr, sta_idx);
308
309         priv->nstations--;
310         return 0;
311 }
312
313 static int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
314 {
315         struct ath9k_htc_cap_target tcap;
316         int ret;
317         u8 cmd_rsp;
318
319         memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
320
321         /* FIXME: Values are hardcoded */
322         tcap.flags = 0x240c40;
323         tcap.flags_ext = 0x80601000;
324         tcap.ampdu_limit = 0xffff0000;
325         tcap.ampdu_subframes = 20;
326         tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
327         tcap.protmode = 1;
328         tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
329
330         WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
331
332         return ret;
333 }
334
335 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
336                                  struct ieee80211_sta *sta,
337                                  struct ath9k_htc_target_rate *trate)
338 {
339         struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
340         struct ieee80211_supported_band *sband;
341         u32 caps = 0;
342         int i, j;
343
344         sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
345
346         for (i = 0, j = 0; i < sband->n_bitrates; i++) {
347                 if (sta->supp_rates[sband->band] & BIT(i)) {
348                         trate->rates.legacy_rates.rs_rates[j]
349                                 = (sband->bitrates[i].bitrate * 2) / 10;
350                         j++;
351                 }
352         }
353         trate->rates.legacy_rates.rs_nrates = j;
354
355         if (sta->ht_cap.ht_supported) {
356                 for (i = 0, j = 0; i < 77; i++) {
357                         if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
358                                 trate->rates.ht_rates.rs_rates[j++] = i;
359                         if (j == ATH_HTC_RATE_MAX)
360                                 break;
361                 }
362                 trate->rates.ht_rates.rs_nrates = j;
363
364                 caps = WLAN_RC_HT_FLAG;
365                 if (sta->ht_cap.mcs.rx_mask[1])
366                         caps |= WLAN_RC_DS_FLAG;
367                 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
368                         caps |= WLAN_RC_40_FLAG;
369                 if (conf_is_ht40(&priv->hw->conf) &&
370                     (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
371                         caps |= WLAN_RC_SGI_FLAG;
372                 else if (conf_is_ht20(&priv->hw->conf) &&
373                          (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
374                         caps |= WLAN_RC_SGI_FLAG;
375         }
376
377         trate->sta_index = ista->index;
378         trate->isnew = 1;
379         trate->capflags = cpu_to_be32(caps);
380 }
381
382 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
383                                     struct ath9k_htc_target_rate *trate)
384 {
385         struct ath_common *common = ath9k_hw_common(priv->ah);
386         int ret;
387         u8 cmd_rsp;
388
389         WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
390         if (ret) {
391                 ath_print(common, ATH_DBG_FATAL,
392                           "Unable to initialize Rate information on target\n");
393         }
394
395         return ret;
396 }
397
398 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
399                                 struct ieee80211_sta *sta)
400 {
401         struct ath_common *common = ath9k_hw_common(priv->ah);
402         struct ath9k_htc_target_rate trate;
403         int ret;
404
405         memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
406         ath9k_htc_setup_rate(priv, sta, &trate);
407         ret = ath9k_htc_send_rate_cmd(priv, &trate);
408         if (!ret)
409                 ath_print(common, ATH_DBG_CONFIG,
410                           "Updated target sta: %pM, rate caps: 0x%X\n",
411                           sta->addr, be32_to_cpu(trate.capflags));
412 }
413
414 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
415                                   struct ieee80211_vif *vif,
416                                   struct ieee80211_bss_conf *bss_conf)
417 {
418         struct ath_common *common = ath9k_hw_common(priv->ah);
419         struct ath9k_htc_target_rate trate;
420         struct ieee80211_sta *sta;
421         int ret;
422
423         memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
424
425         rcu_read_lock();
426         sta = ieee80211_find_sta(vif, bss_conf->bssid);
427         if (!sta) {
428                 rcu_read_unlock();
429                 return;
430         }
431         ath9k_htc_setup_rate(priv, sta, &trate);
432         rcu_read_unlock();
433
434         ret = ath9k_htc_send_rate_cmd(priv, &trate);
435         if (!ret)
436                 ath_print(common, ATH_DBG_CONFIG,
437                           "Updated target sta: %pM, rate caps: 0x%X\n",
438                           bss_conf->bssid, be32_to_cpu(trate.capflags));
439 }
440
441 static int ath9k_htc_aggr_oper(struct ath9k_htc_priv *priv,
442                                struct ieee80211_vif *vif,
443                                u8 *sta_addr, u8 tid, bool oper)
444 {
445         struct ath_common *common = ath9k_hw_common(priv->ah);
446         struct ath9k_htc_target_aggr aggr;
447         struct ieee80211_sta *sta = NULL;
448         struct ath9k_htc_sta *ista;
449         int ret = 0;
450         u8 cmd_rsp;
451
452         if (tid >= ATH9K_HTC_MAX_TID)
453                 return -EINVAL;
454
455         memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
456
457         rcu_read_lock();
458
459         /* Check if we are able to retrieve the station */
460         sta = ieee80211_find_sta(vif, sta_addr);
461         if (!sta) {
462                 rcu_read_unlock();
463                 return -EINVAL;
464         }
465
466         ista = (struct ath9k_htc_sta *) sta->drv_priv;
467
468         if (oper)
469                 ista->tid_state[tid] = AGGR_START;
470         else
471                 ista->tid_state[tid] = AGGR_STOP;
472
473         aggr.sta_index = ista->index;
474
475         rcu_read_unlock();
476
477         aggr.tidno = tid;
478         aggr.aggr_enable = oper;
479
480         WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
481         if (ret)
482                 ath_print(common, ATH_DBG_CONFIG,
483                           "Unable to %s TX aggregation for (%pM, %d)\n",
484                           (oper) ? "start" : "stop", sta->addr, tid);
485         else
486                 ath_print(common, ATH_DBG_CONFIG,
487                           "%s aggregation for (%pM, %d)\n",
488                           (oper) ? "Starting" : "Stopping", sta->addr, tid);
489
490         return ret;
491 }
492
493 void ath9k_htc_aggr_work(struct work_struct *work)
494 {
495         int ret = 0;
496         struct ath9k_htc_priv *priv =
497                 container_of(work, struct ath9k_htc_priv,
498                              ath9k_aggr_work.work);
499         struct ath9k_htc_aggr_work *wk = &priv->aggr_work;
500
501         mutex_lock(&wk->mutex);
502
503         switch (wk->action) {
504         case IEEE80211_AMPDU_TX_START:
505                 ret = ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
506                                           wk->tid, true);
507                 if (!ret)
508                         ieee80211_start_tx_ba_cb_irqsafe(wk->vif, wk->sta_addr,
509                                                          wk->tid);
510                 break;
511         case IEEE80211_AMPDU_TX_STOP:
512                 ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
513                                     wk->tid, false);
514                 ieee80211_stop_tx_ba_cb_irqsafe(wk->vif, wk->sta_addr, wk->tid);
515                 break;
516         default:
517                 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
518                           "Unknown AMPDU action\n");
519         }
520
521         mutex_unlock(&wk->mutex);
522 }
523
524 /*********/
525 /* DEBUG */
526 /*********/
527
528 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
529
530 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
531 {
532         file->private_data = inode->i_private;
533         return 0;
534 }
535
536 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
537                                    size_t count, loff_t *ppos)
538 {
539         struct ath9k_htc_priv *priv =
540                 (struct ath9k_htc_priv *) file->private_data;
541         struct ath9k_htc_target_stats cmd_rsp;
542         char buf[512];
543         unsigned int len = 0;
544         int ret = 0;
545
546         memset(&cmd_rsp, 0, sizeof(cmd_rsp));
547
548         WMI_CMD(WMI_TGT_STATS_CMDID);
549         if (ret)
550                 return -EINVAL;
551
552
553         len += snprintf(buf + len, sizeof(buf) - len,
554                         "%19s : %10u\n", "TX Short Retries",
555                         be32_to_cpu(cmd_rsp.tx_shortretry));
556         len += snprintf(buf + len, sizeof(buf) - len,
557                         "%19s : %10u\n", "TX Long Retries",
558                         be32_to_cpu(cmd_rsp.tx_longretry));
559         len += snprintf(buf + len, sizeof(buf) - len,
560                         "%19s : %10u\n", "TX Xretries",
561                         be32_to_cpu(cmd_rsp.tx_xretries));
562         len += snprintf(buf + len, sizeof(buf) - len,
563                         "%19s : %10u\n", "TX Unaggr. Xretries",
564                         be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
565         len += snprintf(buf + len, sizeof(buf) - len,
566                         "%19s : %10u\n", "TX Xretries (HT)",
567                         be32_to_cpu(cmd_rsp.ht_tx_xretries));
568         len += snprintf(buf + len, sizeof(buf) - len,
569                         "%19s : %10u\n", "TX Rate", priv->debug.txrate);
570
571         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
572 }
573
574 static const struct file_operations fops_tgt_stats = {
575         .read = read_file_tgt_stats,
576         .open = ath9k_debugfs_open,
577         .owner = THIS_MODULE
578 };
579
580 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
581                               size_t count, loff_t *ppos)
582 {
583         struct ath9k_htc_priv *priv =
584                 (struct ath9k_htc_priv *) file->private_data;
585         char buf[512];
586         unsigned int len = 0;
587
588         len += snprintf(buf + len, sizeof(buf) - len,
589                         "%20s : %10u\n", "Buffers queued",
590                         priv->debug.tx_stats.buf_queued);
591         len += snprintf(buf + len, sizeof(buf) - len,
592                         "%20s : %10u\n", "Buffers completed",
593                         priv->debug.tx_stats.buf_completed);
594         len += snprintf(buf + len, sizeof(buf) - len,
595                         "%20s : %10u\n", "SKBs queued",
596                         priv->debug.tx_stats.skb_queued);
597         len += snprintf(buf + len, sizeof(buf) - len,
598                         "%20s : %10u\n", "SKBs completed",
599                         priv->debug.tx_stats.skb_completed);
600         len += snprintf(buf + len, sizeof(buf) - len,
601                         "%20s : %10u\n", "SKBs dropped",
602                         priv->debug.tx_stats.skb_dropped);
603
604         len += snprintf(buf + len, sizeof(buf) - len,
605                         "%20s : %10u\n", "BE queued",
606                         priv->debug.tx_stats.queue_stats[WME_AC_BE]);
607         len += snprintf(buf + len, sizeof(buf) - len,
608                         "%20s : %10u\n", "BK queued",
609                         priv->debug.tx_stats.queue_stats[WME_AC_BK]);
610         len += snprintf(buf + len, sizeof(buf) - len,
611                         "%20s : %10u\n", "VI queued",
612                         priv->debug.tx_stats.queue_stats[WME_AC_VI]);
613         len += snprintf(buf + len, sizeof(buf) - len,
614                         "%20s : %10u\n", "VO queued",
615                         priv->debug.tx_stats.queue_stats[WME_AC_VO]);
616
617         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
618 }
619
620 static const struct file_operations fops_xmit = {
621         .read = read_file_xmit,
622         .open = ath9k_debugfs_open,
623         .owner = THIS_MODULE
624 };
625
626 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
627                               size_t count, loff_t *ppos)
628 {
629         struct ath9k_htc_priv *priv =
630                 (struct ath9k_htc_priv *) file->private_data;
631         char buf[512];
632         unsigned int len = 0;
633
634         len += snprintf(buf + len, sizeof(buf) - len,
635                         "%20s : %10u\n", "SKBs allocated",
636                         priv->debug.rx_stats.skb_allocated);
637         len += snprintf(buf + len, sizeof(buf) - len,
638                         "%20s : %10u\n", "SKBs completed",
639                         priv->debug.rx_stats.skb_completed);
640         len += snprintf(buf + len, sizeof(buf) - len,
641                         "%20s : %10u\n", "SKBs Dropped",
642                         priv->debug.rx_stats.skb_dropped);
643
644         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
645 }
646
647 static const struct file_operations fops_recv = {
648         .read = read_file_recv,
649         .open = ath9k_debugfs_open,
650         .owner = THIS_MODULE
651 };
652
653 int ath9k_htc_init_debug(struct ath_hw *ah)
654 {
655         struct ath_common *common = ath9k_hw_common(ah);
656         struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
657
658         if (!ath9k_debugfs_root)
659                 return -ENOENT;
660
661         priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
662                                                      ath9k_debugfs_root);
663         if (!priv->debug.debugfs_phy)
664                 goto err;
665
666         priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
667                                                     priv->debug.debugfs_phy,
668                                                     priv, &fops_tgt_stats);
669         if (!priv->debug.debugfs_tgt_stats)
670                 goto err;
671
672
673         priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
674                                                        priv->debug.debugfs_phy,
675                                                        priv, &fops_xmit);
676         if (!priv->debug.debugfs_xmit)
677                 goto err;
678
679         priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
680                                                        priv->debug.debugfs_phy,
681                                                        priv, &fops_recv);
682         if (!priv->debug.debugfs_recv)
683                 goto err;
684
685         return 0;
686
687 err:
688         ath9k_htc_exit_debug(ah);
689         return -ENOMEM;
690 }
691
692 void ath9k_htc_exit_debug(struct ath_hw *ah)
693 {
694         struct ath_common *common = ath9k_hw_common(ah);
695         struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
696
697         debugfs_remove(priv->debug.debugfs_recv);
698         debugfs_remove(priv->debug.debugfs_xmit);
699         debugfs_remove(priv->debug.debugfs_tgt_stats);
700         debugfs_remove(priv->debug.debugfs_phy);
701 }
702
703 int ath9k_htc_debug_create_root(void)
704 {
705         ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
706         if (!ath9k_debugfs_root)
707                 return -ENOENT;
708
709         return 0;
710 }
711
712 void ath9k_htc_debug_remove_root(void)
713 {
714         debugfs_remove(ath9k_debugfs_root);
715         ath9k_debugfs_root = NULL;
716 }
717
718 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
719
720 /*******/
721 /* ANI */
722 /*******/
723
724 static void ath_start_ani(struct ath9k_htc_priv *priv)
725 {
726         struct ath_common *common = ath9k_hw_common(priv->ah);
727         unsigned long timestamp = jiffies_to_msecs(jiffies);
728
729         common->ani.longcal_timer = timestamp;
730         common->ani.shortcal_timer = timestamp;
731         common->ani.checkani_timer = timestamp;
732
733         ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
734                                      msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
735 }
736
737 void ath9k_ani_work(struct work_struct *work)
738 {
739         struct ath9k_htc_priv *priv =
740                 container_of(work, struct ath9k_htc_priv,
741                              ath9k_ani_work.work);
742         struct ath_hw *ah = priv->ah;
743         struct ath_common *common = ath9k_hw_common(ah);
744         bool longcal = false;
745         bool shortcal = false;
746         bool aniflag = false;
747         unsigned int timestamp = jiffies_to_msecs(jiffies);
748         u32 cal_interval, short_cal_interval;
749
750         short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
751
752         /* Only calibrate if awake */
753         if (ah->power_mode != ATH9K_PM_AWAKE)
754                 goto set_timer;
755
756         /* Long calibration runs independently of short calibration. */
757         if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
758                 longcal = true;
759                 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
760                 common->ani.longcal_timer = timestamp;
761         }
762
763         /* Short calibration applies only while caldone is false */
764         if (!common->ani.caldone) {
765                 if ((timestamp - common->ani.shortcal_timer) >=
766                     short_cal_interval) {
767                         shortcal = true;
768                         ath_print(common, ATH_DBG_ANI,
769                                   "shortcal @%lu\n", jiffies);
770                         common->ani.shortcal_timer = timestamp;
771                         common->ani.resetcal_timer = timestamp;
772                 }
773         } else {
774                 if ((timestamp - common->ani.resetcal_timer) >=
775                     ATH_RESTART_CALINTERVAL) {
776                         common->ani.caldone = ath9k_hw_reset_calvalid(ah);
777                         if (common->ani.caldone)
778                                 common->ani.resetcal_timer = timestamp;
779                 }
780         }
781
782         /* Verify whether we must check ANI */
783         if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
784                 aniflag = true;
785                 common->ani.checkani_timer = timestamp;
786         }
787
788         /* Skip all processing if there's nothing to do. */
789         if (longcal || shortcal || aniflag) {
790
791                 ath9k_htc_ps_wakeup(priv);
792
793                 /* Call ANI routine if necessary */
794                 if (aniflag)
795                         ath9k_hw_ani_monitor(ah, ah->curchan);
796
797                 /* Perform calibration if necessary */
798                 if (longcal || shortcal) {
799                         common->ani.caldone =
800                                 ath9k_hw_calibrate(ah, ah->curchan,
801                                                    common->rx_chainmask,
802                                                    longcal);
803
804                         if (longcal)
805                                 common->ani.noise_floor =
806                                         ath9k_hw_getchan_noise(ah, ah->curchan);
807
808                         ath_print(common, ATH_DBG_ANI,
809                                   " calibrate chan %u/%x nf: %d\n",
810                                   ah->curchan->channel,
811                                   ah->curchan->channelFlags,
812                                   common->ani.noise_floor);
813                 }
814
815                 ath9k_htc_ps_restore(priv);
816         }
817
818 set_timer:
819         /*
820         * Set timer interval based on previous results.
821         * The interval must be the shortest necessary to satisfy ANI,
822         * short calibration and long calibration.
823         */
824         cal_interval = ATH_LONG_CALINTERVAL;
825         if (priv->ah->config.enable_ani)
826                 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
827         if (!common->ani.caldone)
828                 cal_interval = min(cal_interval, (u32)short_cal_interval);
829
830         ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
831                                      msecs_to_jiffies(cal_interval));
832 }
833
834 /*******/
835 /* LED */
836 /*******/
837
838 static void ath9k_led_blink_work(struct work_struct *work)
839 {
840         struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
841                                                    ath9k_led_blink_work.work);
842
843         if (!(priv->op_flags & OP_LED_ASSOCIATED))
844                 return;
845
846         if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
847             (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
848                 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
849         else
850                 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
851                                   (priv->op_flags & OP_LED_ON) ? 1 : 0);
852
853         ieee80211_queue_delayed_work(priv->hw,
854                                      &priv->ath9k_led_blink_work,
855                                      (priv->op_flags & OP_LED_ON) ?
856                                      msecs_to_jiffies(priv->led_off_duration) :
857                                      msecs_to_jiffies(priv->led_on_duration));
858
859         priv->led_on_duration = priv->led_on_cnt ?
860                 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
861                 ATH_LED_ON_DURATION_IDLE;
862         priv->led_off_duration = priv->led_off_cnt ?
863                 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
864                 ATH_LED_OFF_DURATION_IDLE;
865         priv->led_on_cnt = priv->led_off_cnt = 0;
866
867         if (priv->op_flags & OP_LED_ON)
868                 priv->op_flags &= ~OP_LED_ON;
869         else
870                 priv->op_flags |= OP_LED_ON;
871 }
872
873 static void ath9k_led_brightness_work(struct work_struct *work)
874 {
875         struct ath_led *led = container_of(work, struct ath_led,
876                                            brightness_work.work);
877         struct ath9k_htc_priv *priv = led->priv;
878
879         switch (led->brightness) {
880         case LED_OFF:
881                 if (led->led_type == ATH_LED_ASSOC ||
882                     led->led_type == ATH_LED_RADIO) {
883                         ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
884                                           (led->led_type == ATH_LED_RADIO));
885                         priv->op_flags &= ~OP_LED_ASSOCIATED;
886                         if (led->led_type == ATH_LED_RADIO)
887                                 priv->op_flags &= ~OP_LED_ON;
888                 } else {
889                         priv->led_off_cnt++;
890                 }
891                 break;
892         case LED_FULL:
893                 if (led->led_type == ATH_LED_ASSOC) {
894                         priv->op_flags |= OP_LED_ASSOCIATED;
895                         ieee80211_queue_delayed_work(priv->hw,
896                                              &priv->ath9k_led_blink_work, 0);
897                 } else if (led->led_type == ATH_LED_RADIO) {
898                         ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
899                         priv->op_flags |= OP_LED_ON;
900                 } else {
901                         priv->led_on_cnt++;
902                 }
903                 break;
904         default:
905                 break;
906         }
907 }
908
909 static void ath9k_led_brightness(struct led_classdev *led_cdev,
910                                  enum led_brightness brightness)
911 {
912         struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
913         struct ath9k_htc_priv *priv = led->priv;
914
915         led->brightness = brightness;
916         if (!(priv->op_flags & OP_LED_DEINIT))
917                 ieee80211_queue_delayed_work(priv->hw,
918                                              &led->brightness_work, 0);
919 }
920
921 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
922 {
923         cancel_delayed_work_sync(&priv->radio_led.brightness_work);
924         cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
925         cancel_delayed_work_sync(&priv->tx_led.brightness_work);
926         cancel_delayed_work_sync(&priv->rx_led.brightness_work);
927 }
928
929 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
930                               char *trigger)
931 {
932         int ret;
933
934         led->priv = priv;
935         led->led_cdev.name = led->name;
936         led->led_cdev.default_trigger = trigger;
937         led->led_cdev.brightness_set = ath9k_led_brightness;
938
939         ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
940         if (ret)
941                 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
942                           "Failed to register led:%s", led->name);
943         else
944                 led->registered = 1;
945
946         INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
947
948         return ret;
949 }
950
951 static void ath9k_unregister_led(struct ath_led *led)
952 {
953         if (led->registered) {
954                 led_classdev_unregister(&led->led_cdev);
955                 led->registered = 0;
956         }
957 }
958
959 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
960 {
961         priv->op_flags |= OP_LED_DEINIT;
962         ath9k_unregister_led(&priv->assoc_led);
963         priv->op_flags &= ~OP_LED_ASSOCIATED;
964         ath9k_unregister_led(&priv->tx_led);
965         ath9k_unregister_led(&priv->rx_led);
966         ath9k_unregister_led(&priv->radio_led);
967 }
968
969 void ath9k_init_leds(struct ath9k_htc_priv *priv)
970 {
971         char *trigger;
972         int ret;
973
974         if (AR_SREV_9287(priv->ah))
975                 priv->ah->led_pin = ATH_LED_PIN_9287;
976         else if (AR_SREV_9271(priv->ah))
977                 priv->ah->led_pin = ATH_LED_PIN_9271;
978         else
979                 priv->ah->led_pin = ATH_LED_PIN_DEF;
980
981         /* Configure gpio 1 for output */
982         ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
983                             AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
984         /* LED off, active low */
985         ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
986
987         INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
988
989         trigger = ieee80211_get_radio_led_name(priv->hw);
990         snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
991                 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
992         ret = ath9k_register_led(priv, &priv->radio_led, trigger);
993         priv->radio_led.led_type = ATH_LED_RADIO;
994         if (ret)
995                 goto fail;
996
997         trigger = ieee80211_get_assoc_led_name(priv->hw);
998         snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
999                 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
1000         ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
1001         priv->assoc_led.led_type = ATH_LED_ASSOC;
1002         if (ret)
1003                 goto fail;
1004
1005         trigger = ieee80211_get_tx_led_name(priv->hw);
1006         snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
1007                 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
1008         ret = ath9k_register_led(priv, &priv->tx_led, trigger);
1009         priv->tx_led.led_type = ATH_LED_TX;
1010         if (ret)
1011                 goto fail;
1012
1013         trigger = ieee80211_get_rx_led_name(priv->hw);
1014         snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
1015                 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
1016         ret = ath9k_register_led(priv, &priv->rx_led, trigger);
1017         priv->rx_led.led_type = ATH_LED_RX;
1018         if (ret)
1019                 goto fail;
1020
1021         priv->op_flags &= ~OP_LED_DEINIT;
1022
1023         return;
1024
1025 fail:
1026         cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1027         ath9k_deinit_leds(priv);
1028 }
1029
1030 /*******************/
1031 /*      Rfkill     */
1032 /*******************/
1033
1034 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
1035 {
1036         return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
1037                 priv->ah->rfkill_polarity;
1038 }
1039
1040 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
1041 {
1042         struct ath9k_htc_priv *priv = hw->priv;
1043         bool blocked = !!ath_is_rfkill_set(priv);
1044
1045         wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1046 }
1047
1048 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1049 {
1050         if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1051                 wiphy_rfkill_start_polling(priv->hw->wiphy);
1052 }
1053
1054 static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1055 {
1056         struct ath9k_htc_priv *priv = hw->priv;
1057         struct ath_hw *ah = priv->ah;
1058         struct ath_common *common = ath9k_hw_common(ah);
1059         int ret;
1060         u8 cmd_rsp;
1061
1062         if (!ah->curchan)
1063                 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1064
1065         /* Reset the HW */
1066         ret = ath9k_hw_reset(ah, ah->curchan, false);
1067         if (ret) {
1068                 ath_print(common, ATH_DBG_FATAL,
1069                           "Unable to reset hardware; reset status %d "
1070                           "(freq %u MHz)\n", ret, ah->curchan->channel);
1071         }
1072
1073         ath_update_txpow(priv);
1074
1075         /* Start RX */
1076         WMI_CMD(WMI_START_RECV_CMDID);
1077         ath9k_host_rx_init(priv);
1078
1079         /* Start TX */
1080         htc_start(priv->htc);
1081         spin_lock_bh(&priv->tx_lock);
1082         priv->tx_queues_stop = false;
1083         spin_unlock_bh(&priv->tx_lock);
1084         ieee80211_wake_queues(hw);
1085
1086         WMI_CMD(WMI_ENABLE_INTR_CMDID);
1087
1088         /* Enable LED */
1089         ath9k_hw_cfg_output(ah, ah->led_pin,
1090                             AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1091         ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1092 }
1093
1094 static void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
1095 {
1096         struct ath9k_htc_priv *priv = hw->priv;
1097         struct ath_hw *ah = priv->ah;
1098         struct ath_common *common = ath9k_hw_common(ah);
1099         int ret;
1100         u8 cmd_rsp;
1101
1102         ath9k_htc_ps_wakeup(priv);
1103
1104         /* Disable LED */
1105         ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1106         ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1107
1108         WMI_CMD(WMI_DISABLE_INTR_CMDID);
1109
1110         /* Stop TX */
1111         ieee80211_stop_queues(hw);
1112         htc_stop(priv->htc);
1113         WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1114         skb_queue_purge(&priv->tx_queue);
1115
1116         /* Stop RX */
1117         WMI_CMD(WMI_STOP_RECV_CMDID);
1118
1119         /*
1120          * The MIB counters have to be disabled here,
1121          * since the target doesn't do it.
1122          */
1123         ath9k_hw_disable_mib_counters(ah);
1124
1125         if (!ah->curchan)
1126                 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1127
1128         /* Reset the HW */
1129         ret = ath9k_hw_reset(ah, ah->curchan, false);
1130         if (ret) {
1131                 ath_print(common, ATH_DBG_FATAL,
1132                           "Unable to reset hardware; reset status %d "
1133                           "(freq %u MHz)\n", ret, ah->curchan->channel);
1134         }
1135
1136         /* Disable the PHY */
1137         ath9k_hw_phy_disable(ah);
1138
1139         ath9k_htc_ps_restore(priv);
1140         ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1141 }
1142
1143 /**********************/
1144 /* mac80211 Callbacks */
1145 /**********************/
1146
1147 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1148 {
1149         struct ieee80211_hdr *hdr;
1150         struct ath9k_htc_priv *priv = hw->priv;
1151         int padpos, padsize, ret;
1152
1153         hdr = (struct ieee80211_hdr *) skb->data;
1154
1155         /* Add the padding after the header if this is not already done */
1156         padpos = ath9k_cmn_padpos(hdr->frame_control);
1157         padsize = padpos & 3;
1158         if (padsize && skb->len > padpos) {
1159                 if (skb_headroom(skb) < padsize)
1160                         return -1;
1161                 skb_push(skb, padsize);
1162                 memmove(skb->data, skb->data + padsize, padpos);
1163         }
1164
1165         ret = ath9k_htc_tx_start(priv, skb);
1166         if (ret != 0) {
1167                 if (ret == -ENOMEM) {
1168                         ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1169                                   "Stopping TX queues\n");
1170                         ieee80211_stop_queues(hw);
1171                         spin_lock_bh(&priv->tx_lock);
1172                         priv->tx_queues_stop = true;
1173                         spin_unlock_bh(&priv->tx_lock);
1174                 } else {
1175                         ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1176                                   "Tx failed");
1177                 }
1178                 goto fail_tx;
1179         }
1180
1181         return 0;
1182
1183 fail_tx:
1184         dev_kfree_skb_any(skb);
1185         return 0;
1186 }
1187
1188 static int ath9k_htc_start(struct ieee80211_hw *hw)
1189 {
1190         struct ath9k_htc_priv *priv = hw->priv;
1191         struct ath_hw *ah = priv->ah;
1192         struct ath_common *common = ath9k_hw_common(ah);
1193         struct ieee80211_channel *curchan = hw->conf.channel;
1194         struct ath9k_channel *init_channel;
1195         int ret = 0;
1196         enum htc_phymode mode;
1197         __be16 htc_mode;
1198         u8 cmd_rsp;
1199
1200         mutex_lock(&priv->mutex);
1201
1202         ath_print(common, ATH_DBG_CONFIG,
1203                   "Starting driver with initial channel: %d MHz\n",
1204                   curchan->center_freq);
1205
1206         /* Ensure that HW is awake before flushing RX */
1207         ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1208         WMI_CMD(WMI_FLUSH_RECV_CMDID);
1209
1210         /* setup initial channel */
1211         init_channel = ath9k_cmn_get_curchannel(hw, ah);
1212
1213         /* Reset SERDES registers */
1214         ath9k_hw_configpcipowersave(ah, 0, 0);
1215
1216         ath9k_hw_htc_resetinit(ah);
1217         ret = ath9k_hw_reset(ah, init_channel, false);
1218         if (ret) {
1219                 ath_print(common, ATH_DBG_FATAL,
1220                           "Unable to reset hardware; reset status %d "
1221                           "(freq %u MHz)\n", ret, curchan->center_freq);
1222                 mutex_unlock(&priv->mutex);
1223                 return ret;
1224         }
1225
1226         ath_update_txpow(priv);
1227
1228         mode = ath9k_htc_get_curmode(priv, init_channel);
1229         htc_mode = cpu_to_be16(mode);
1230         WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1231         WMI_CMD(WMI_ATH_INIT_CMDID);
1232         WMI_CMD(WMI_START_RECV_CMDID);
1233
1234         ath9k_host_rx_init(priv);
1235
1236         priv->op_flags &= ~OP_INVALID;
1237         htc_start(priv->htc);
1238
1239         spin_lock_bh(&priv->tx_lock);
1240         priv->tx_queues_stop = false;
1241         spin_unlock_bh(&priv->tx_lock);
1242
1243         ieee80211_wake_queues(hw);
1244
1245         mutex_unlock(&priv->mutex);
1246
1247         return ret;
1248 }
1249
1250 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1251 {
1252         struct ath9k_htc_priv *priv = hw->priv;
1253         struct ath_hw *ah = priv->ah;
1254         struct ath_common *common = ath9k_hw_common(ah);
1255         int ret = 0;
1256         u8 cmd_rsp;
1257
1258         mutex_lock(&priv->mutex);
1259
1260         if (priv->op_flags & OP_INVALID) {
1261                 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1262                 mutex_unlock(&priv->mutex);
1263                 return;
1264         }
1265
1266         /* Cancel all the running timers/work .. */
1267         cancel_work_sync(&priv->ps_work);
1268         cancel_delayed_work_sync(&priv->ath9k_ani_work);
1269         cancel_delayed_work_sync(&priv->ath9k_aggr_work);
1270         cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1271         ath9k_led_stop_brightness(priv);
1272
1273         ath9k_htc_ps_wakeup(priv);
1274         htc_stop(priv->htc);
1275         WMI_CMD(WMI_DISABLE_INTR_CMDID);
1276         WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1277         WMI_CMD(WMI_STOP_RECV_CMDID);
1278         skb_queue_purge(&priv->tx_queue);
1279
1280         /* Remove monitor interface here */
1281         if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1282                 if (ath9k_htc_remove_monitor_interface(priv))
1283                         ath_print(common, ATH_DBG_FATAL,
1284                                   "Unable to remove monitor interface\n");
1285                 else
1286                         ath_print(common, ATH_DBG_CONFIG,
1287                                   "Monitor interface removed\n");
1288         }
1289
1290         ath9k_hw_phy_disable(ah);
1291         ath9k_hw_disable(ah);
1292         ath9k_hw_configpcipowersave(ah, 1, 1);
1293         ath9k_htc_ps_restore(priv);
1294         ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1295
1296         priv->op_flags |= OP_INVALID;
1297
1298         ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1299         mutex_unlock(&priv->mutex);
1300 }
1301
1302 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1303                                    struct ieee80211_vif *vif)
1304 {
1305         struct ath9k_htc_priv *priv = hw->priv;
1306         struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1307         struct ath_common *common = ath9k_hw_common(priv->ah);
1308         struct ath9k_htc_target_vif hvif;
1309         int ret = 0;
1310         u8 cmd_rsp;
1311
1312         mutex_lock(&priv->mutex);
1313
1314         /* Only one interface for now */
1315         if (priv->nvifs > 0) {
1316                 ret = -ENOBUFS;
1317                 goto out;
1318         }
1319
1320         ath9k_htc_ps_wakeup(priv);
1321         memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1322         memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1323
1324         switch (vif->type) {
1325         case NL80211_IFTYPE_STATION:
1326                 hvif.opmode = cpu_to_be32(HTC_M_STA);
1327                 break;
1328         case NL80211_IFTYPE_ADHOC:
1329                 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1330                 break;
1331         default:
1332                 ath_print(common, ATH_DBG_FATAL,
1333                         "Interface type %d not yet supported\n", vif->type);
1334                 ret = -EOPNOTSUPP;
1335                 goto out;
1336         }
1337
1338         ath_print(common, ATH_DBG_CONFIG,
1339                   "Attach a VIF of type: %d\n", vif->type);
1340
1341         priv->ah->opmode = vif->type;
1342
1343         /* Index starts from zero on the target */
1344         avp->index = hvif.index = priv->nvifs;
1345         hvif.rtsthreshold = cpu_to_be16(2304);
1346         WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1347         if (ret)
1348                 goto out;
1349
1350         priv->nvifs++;
1351
1352         /*
1353          * We need a node in target to tx mgmt frames
1354          * before association.
1355          */
1356         ret = ath9k_htc_add_station(priv, vif, NULL);
1357         if (ret)
1358                 goto out;
1359
1360         ret = ath9k_htc_update_cap_target(priv);
1361         if (ret)
1362                 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1363                           " capability in target \n");
1364
1365         priv->vif = vif;
1366 out:
1367         ath9k_htc_ps_restore(priv);
1368         mutex_unlock(&priv->mutex);
1369
1370         return ret;
1371 }
1372
1373 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1374                                        struct ieee80211_vif *vif)
1375 {
1376         struct ath9k_htc_priv *priv = hw->priv;
1377         struct ath_common *common = ath9k_hw_common(priv->ah);
1378         struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1379         struct ath9k_htc_target_vif hvif;
1380         int ret = 0;
1381         u8 cmd_rsp;
1382
1383         ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1384
1385         mutex_lock(&priv->mutex);
1386         ath9k_htc_ps_wakeup(priv);
1387
1388         memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1389         memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1390         hvif.index = avp->index;
1391         WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1392         priv->nvifs--;
1393
1394         ath9k_htc_remove_station(priv, vif, NULL);
1395         priv->vif = NULL;
1396
1397         ath9k_htc_ps_restore(priv);
1398         mutex_unlock(&priv->mutex);
1399 }
1400
1401 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1402 {
1403         struct ath9k_htc_priv *priv = hw->priv;
1404         struct ath_common *common = ath9k_hw_common(priv->ah);
1405         struct ieee80211_conf *conf = &hw->conf;
1406
1407         mutex_lock(&priv->mutex);
1408
1409         if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1410                 bool enable_radio = false;
1411                 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1412
1413                 mutex_lock(&priv->htc_pm_lock);
1414                 if (!idle && priv->ps_idle)
1415                         enable_radio = true;
1416                 priv->ps_idle = idle;
1417                 mutex_unlock(&priv->htc_pm_lock);
1418
1419                 if (enable_radio) {
1420                         ath_print(common, ATH_DBG_CONFIG,
1421                                   "not-idle: enabling radio\n");
1422                         ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1423                         ath9k_htc_radio_enable(hw);
1424                 }
1425         }
1426
1427         if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1428                 struct ieee80211_channel *curchan = hw->conf.channel;
1429                 int pos = curchan->hw_value;
1430
1431                 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1432                           curchan->center_freq);
1433
1434                 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1435
1436                 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1437                         ath_print(common, ATH_DBG_FATAL,
1438                                   "Unable to set channel\n");
1439                         mutex_unlock(&priv->mutex);
1440                         return -EINVAL;
1441                 }
1442
1443         }
1444         if (changed & IEEE80211_CONF_CHANGE_PS) {
1445                 if (conf->flags & IEEE80211_CONF_PS) {
1446                         ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1447                         priv->ps_enabled = true;
1448                 } else {
1449                         priv->ps_enabled = false;
1450                         cancel_work_sync(&priv->ps_work);
1451                         ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1452                 }
1453         }
1454
1455         if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1456                 if (conf->flags & IEEE80211_CONF_MONITOR) {
1457                         if (ath9k_htc_add_monitor_interface(priv))
1458                                 ath_print(common, ATH_DBG_FATAL,
1459                                           "Failed to set monitor mode\n");
1460                         else
1461                                 ath_print(common, ATH_DBG_CONFIG,
1462                                           "HW opmode set to Monitor mode\n");
1463                 }
1464         }
1465
1466         if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1467                 mutex_lock(&priv->htc_pm_lock);
1468                 if (!priv->ps_idle) {
1469                         mutex_unlock(&priv->htc_pm_lock);
1470                         goto out;
1471                 }
1472                 mutex_unlock(&priv->htc_pm_lock);
1473
1474                 ath_print(common, ATH_DBG_CONFIG,
1475                           "idle: disabling radio\n");
1476                 ath9k_htc_radio_disable(hw);
1477         }
1478
1479 out:
1480         mutex_unlock(&priv->mutex);
1481         return 0;
1482 }
1483
1484 #define SUPPORTED_FILTERS                       \
1485         (FIF_PROMISC_IN_BSS |                   \
1486         FIF_ALLMULTI |                          \
1487         FIF_CONTROL |                           \
1488         FIF_PSPOLL |                            \
1489         FIF_OTHER_BSS |                         \
1490         FIF_BCN_PRBRESP_PROMISC |               \
1491         FIF_FCSFAIL)
1492
1493 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1494                                        unsigned int changed_flags,
1495                                        unsigned int *total_flags,
1496                                        u64 multicast)
1497 {
1498         struct ath9k_htc_priv *priv = hw->priv;
1499         u32 rfilt;
1500
1501         mutex_lock(&priv->mutex);
1502         ath9k_htc_ps_wakeup(priv);
1503
1504         changed_flags &= SUPPORTED_FILTERS;
1505         *total_flags &= SUPPORTED_FILTERS;
1506
1507         priv->rxfilter = *total_flags;
1508         rfilt = ath9k_htc_calcrxfilter(priv);
1509         ath9k_hw_setrxfilter(priv->ah, rfilt);
1510
1511         ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1512                   "Set HW RX filter: 0x%x\n", rfilt);
1513
1514         ath9k_htc_ps_restore(priv);
1515         mutex_unlock(&priv->mutex);
1516 }
1517
1518 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1519                              struct ieee80211_vif *vif,
1520                              struct ieee80211_sta *sta)
1521 {
1522         struct ath9k_htc_priv *priv = hw->priv;
1523         int ret;
1524
1525         mutex_lock(&priv->mutex);
1526         ath9k_htc_ps_wakeup(priv);
1527         ret = ath9k_htc_add_station(priv, vif, sta);
1528         if (!ret)
1529                 ath9k_htc_init_rate(priv, sta);
1530         ath9k_htc_ps_restore(priv);
1531         mutex_unlock(&priv->mutex);
1532
1533         return ret;
1534 }
1535
1536 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1537                                 struct ieee80211_vif *vif,
1538                                 struct ieee80211_sta *sta)
1539 {
1540         struct ath9k_htc_priv *priv = hw->priv;
1541         int ret;
1542
1543         mutex_lock(&priv->mutex);
1544         ath9k_htc_ps_wakeup(priv);
1545         ret = ath9k_htc_remove_station(priv, vif, sta);
1546         ath9k_htc_ps_restore(priv);
1547         mutex_unlock(&priv->mutex);
1548
1549         return ret;
1550 }
1551
1552 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1553                              const struct ieee80211_tx_queue_params *params)
1554 {
1555         struct ath9k_htc_priv *priv = hw->priv;
1556         struct ath_common *common = ath9k_hw_common(priv->ah);
1557         struct ath9k_tx_queue_info qi;
1558         int ret = 0, qnum;
1559
1560         if (queue >= WME_NUM_AC)
1561                 return 0;
1562
1563         mutex_lock(&priv->mutex);
1564         ath9k_htc_ps_wakeup(priv);
1565
1566         memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1567
1568         qi.tqi_aifs = params->aifs;
1569         qi.tqi_cwmin = params->cw_min;
1570         qi.tqi_cwmax = params->cw_max;
1571         qi.tqi_burstTime = params->txop;
1572
1573         qnum = get_hw_qnum(queue, priv->hwq_map);
1574
1575         ath_print(common, ATH_DBG_CONFIG,
1576                   "Configure tx [queue/hwq] [%d/%d],  "
1577                   "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1578                   queue, qnum, params->aifs, params->cw_min,
1579                   params->cw_max, params->txop);
1580
1581         ret = ath_htc_txq_update(priv, qnum, &qi);
1582         if (ret) {
1583                 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1584                 goto out;
1585         }
1586
1587         if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1588             (qnum == priv->hwq_map[WME_AC_BE]))
1589                     ath9k_htc_beaconq_config(priv);
1590 out:
1591         ath9k_htc_ps_restore(priv);
1592         mutex_unlock(&priv->mutex);
1593
1594         return ret;
1595 }
1596
1597 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1598                              enum set_key_cmd cmd,
1599                              struct ieee80211_vif *vif,
1600                              struct ieee80211_sta *sta,
1601                              struct ieee80211_key_conf *key)
1602 {
1603         struct ath9k_htc_priv *priv = hw->priv;
1604         struct ath_common *common = ath9k_hw_common(priv->ah);
1605         int ret = 0;
1606
1607         if (htc_modparam_nohwcrypt)
1608                 return -ENOSPC;
1609
1610         mutex_lock(&priv->mutex);
1611         ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1612         ath9k_htc_ps_wakeup(priv);
1613
1614         switch (cmd) {
1615         case SET_KEY:
1616                 ret = ath9k_cmn_key_config(common, vif, sta, key);
1617                 if (ret >= 0) {
1618                         key->hw_key_idx = ret;
1619                         /* push IV and Michael MIC generation to stack */
1620                         key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1621                         if (key->alg == ALG_TKIP)
1622                                 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1623                         if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1624                                 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1625                         ret = 0;
1626                 }
1627                 break;
1628         case DISABLE_KEY:
1629                 ath9k_cmn_key_delete(common, key);
1630                 break;
1631         default:
1632                 ret = -EINVAL;
1633         }
1634
1635         ath9k_htc_ps_restore(priv);
1636         mutex_unlock(&priv->mutex);
1637
1638         return ret;
1639 }
1640
1641 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1642                                        struct ieee80211_vif *vif,
1643                                        struct ieee80211_bss_conf *bss_conf,
1644                                        u32 changed)
1645 {
1646         struct ath9k_htc_priv *priv = hw->priv;
1647         struct ath_hw *ah = priv->ah;
1648         struct ath_common *common = ath9k_hw_common(ah);
1649
1650         mutex_lock(&priv->mutex);
1651         ath9k_htc_ps_wakeup(priv);
1652
1653         if (changed & BSS_CHANGED_ASSOC) {
1654                 common->curaid = bss_conf->assoc ?
1655                                  bss_conf->aid : 0;
1656                 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1657                         bss_conf->assoc);
1658
1659                 if (bss_conf->assoc) {
1660                         priv->op_flags |= OP_ASSOCIATED;
1661                         ath_start_ani(priv);
1662                 } else {
1663                         priv->op_flags &= ~OP_ASSOCIATED;
1664                         cancel_delayed_work_sync(&priv->ath9k_ani_work);
1665                 }
1666         }
1667
1668         if (changed & BSS_CHANGED_BSSID) {
1669                 /* Set BSSID */
1670                 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1671                 ath9k_hw_write_associd(ah);
1672
1673                 ath_print(common, ATH_DBG_CONFIG,
1674                           "BSSID: %pM aid: 0x%x\n",
1675                           common->curbssid, common->curaid);
1676         }
1677
1678         if ((changed & BSS_CHANGED_BEACON_INT) ||
1679             (changed & BSS_CHANGED_BEACON) ||
1680             ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1681             bss_conf->enable_beacon)) {
1682                 priv->op_flags |= OP_ENABLE_BEACON;
1683                 ath9k_htc_beacon_config(priv, vif);
1684         }
1685
1686         if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1687             !bss_conf->enable_beacon) {
1688                 priv->op_flags &= ~OP_ENABLE_BEACON;
1689                 ath9k_htc_beacon_config(priv, vif);
1690         }
1691
1692         if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1693                 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1694                           bss_conf->use_short_preamble);
1695                 if (bss_conf->use_short_preamble)
1696                         priv->op_flags |= OP_PREAMBLE_SHORT;
1697                 else
1698                         priv->op_flags &= ~OP_PREAMBLE_SHORT;
1699         }
1700
1701         if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1702                 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1703                           bss_conf->use_cts_prot);
1704                 if (bss_conf->use_cts_prot &&
1705                     hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1706                         priv->op_flags |= OP_PROTECT_ENABLE;
1707                 else
1708                         priv->op_flags &= ~OP_PROTECT_ENABLE;
1709         }
1710
1711         if (changed & BSS_CHANGED_ERP_SLOT) {
1712                 if (bss_conf->use_short_slot)
1713                         ah->slottime = 9;
1714                 else
1715                         ah->slottime = 20;
1716
1717                 ath9k_hw_init_global_settings(ah);
1718         }
1719
1720         if (changed & BSS_CHANGED_HT)
1721                 ath9k_htc_update_rate(priv, vif, bss_conf);
1722
1723         ath9k_htc_ps_restore(priv);
1724         mutex_unlock(&priv->mutex);
1725 }
1726
1727 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1728 {
1729         struct ath9k_htc_priv *priv = hw->priv;
1730         u64 tsf;
1731
1732         mutex_lock(&priv->mutex);
1733         ath9k_htc_ps_wakeup(priv);
1734         tsf = ath9k_hw_gettsf64(priv->ah);
1735         ath9k_htc_ps_restore(priv);
1736         mutex_unlock(&priv->mutex);
1737
1738         return tsf;
1739 }
1740
1741 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1742 {
1743         struct ath9k_htc_priv *priv = hw->priv;
1744
1745         mutex_lock(&priv->mutex);
1746         ath9k_htc_ps_wakeup(priv);
1747         ath9k_hw_settsf64(priv->ah, tsf);
1748         ath9k_htc_ps_restore(priv);
1749         mutex_unlock(&priv->mutex);
1750 }
1751
1752 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1753 {
1754         struct ath9k_htc_priv *priv = hw->priv;
1755
1756         mutex_lock(&priv->mutex);
1757         ath9k_htc_ps_wakeup(priv);
1758         ath9k_hw_reset_tsf(priv->ah);
1759         ath9k_htc_ps_restore(priv);
1760         mutex_unlock(&priv->mutex);
1761 }
1762
1763 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1764                                   struct ieee80211_vif *vif,
1765                                   enum ieee80211_ampdu_mlme_action action,
1766                                   struct ieee80211_sta *sta,
1767                                   u16 tid, u16 *ssn)
1768 {
1769         struct ath9k_htc_priv *priv = hw->priv;
1770         struct ath9k_htc_aggr_work *work = &priv->aggr_work;
1771         struct ath9k_htc_sta *ista;
1772
1773         switch (action) {
1774         case IEEE80211_AMPDU_RX_START:
1775                 break;
1776         case IEEE80211_AMPDU_RX_STOP:
1777                 break;
1778         case IEEE80211_AMPDU_TX_START:
1779         case IEEE80211_AMPDU_TX_STOP:
1780                 if (!(priv->op_flags & OP_TXAGGR))
1781                         return -ENOTSUPP;
1782                 memcpy(work->sta_addr, sta->addr, ETH_ALEN);
1783                 work->hw = hw;
1784                 work->vif = vif;
1785                 work->action = action;
1786                 work->tid = tid;
1787                 ieee80211_queue_delayed_work(hw, &priv->ath9k_aggr_work, 0);
1788                 break;
1789         case IEEE80211_AMPDU_TX_OPERATIONAL:
1790                 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1791                 ista->tid_state[tid] = AGGR_OPERATIONAL;
1792                 break;
1793         default:
1794                 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1795                           "Unknown AMPDU action\n");
1796         }
1797
1798         return 0;
1799 }
1800
1801 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1802 {
1803         struct ath9k_htc_priv *priv = hw->priv;
1804
1805         mutex_lock(&priv->mutex);
1806         spin_lock_bh(&priv->beacon_lock);
1807         priv->op_flags |= OP_SCANNING;
1808         spin_unlock_bh(&priv->beacon_lock);
1809         cancel_work_sync(&priv->ps_work);
1810         cancel_delayed_work_sync(&priv->ath9k_ani_work);
1811         mutex_unlock(&priv->mutex);
1812 }
1813
1814 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1815 {
1816         struct ath9k_htc_priv *priv = hw->priv;
1817
1818         mutex_lock(&priv->mutex);
1819         ath9k_htc_ps_wakeup(priv);
1820         spin_lock_bh(&priv->beacon_lock);
1821         priv->op_flags &= ~OP_SCANNING;
1822         spin_unlock_bh(&priv->beacon_lock);
1823         priv->op_flags |= OP_FULL_RESET;
1824         if (priv->op_flags & OP_ASSOCIATED)
1825                 ath9k_htc_beacon_config(priv, priv->vif);
1826         ath_start_ani(priv);
1827         ath9k_htc_ps_restore(priv);
1828         mutex_unlock(&priv->mutex);
1829 }
1830
1831 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1832 {
1833         return 0;
1834 }
1835
1836 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1837                                          u8 coverage_class)
1838 {
1839         struct ath9k_htc_priv *priv = hw->priv;
1840
1841         mutex_lock(&priv->mutex);
1842         ath9k_htc_ps_wakeup(priv);
1843         priv->ah->coverage_class = coverage_class;
1844         ath9k_hw_init_global_settings(priv->ah);
1845         ath9k_htc_ps_restore(priv);
1846         mutex_unlock(&priv->mutex);
1847 }
1848
1849 struct ieee80211_ops ath9k_htc_ops = {
1850         .tx                 = ath9k_htc_tx,
1851         .start              = ath9k_htc_start,
1852         .stop               = ath9k_htc_stop,
1853         .add_interface      = ath9k_htc_add_interface,
1854         .remove_interface   = ath9k_htc_remove_interface,
1855         .config             = ath9k_htc_config,
1856         .configure_filter   = ath9k_htc_configure_filter,
1857         .sta_add            = ath9k_htc_sta_add,
1858         .sta_remove         = ath9k_htc_sta_remove,
1859         .conf_tx            = ath9k_htc_conf_tx,
1860         .bss_info_changed   = ath9k_htc_bss_info_changed,
1861         .set_key            = ath9k_htc_set_key,
1862         .get_tsf            = ath9k_htc_get_tsf,
1863         .set_tsf            = ath9k_htc_set_tsf,
1864         .reset_tsf          = ath9k_htc_reset_tsf,
1865         .ampdu_action       = ath9k_htc_ampdu_action,
1866         .sw_scan_start      = ath9k_htc_sw_scan_start,
1867         .sw_scan_complete   = ath9k_htc_sw_scan_complete,
1868         .set_rts_threshold  = ath9k_htc_set_rts_threshold,
1869         .rfkill_poll        = ath9k_htc_rfkill_poll_state,
1870         .set_coverage_class = ath9k_htc_set_coverage_class,
1871 };